1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2007 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"
38 #include "lpfc_vport.h"
39 #include "lpfc_debugfs.h"
41 static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *,
43 static void lpfc_cmpl_fabric_iocb(struct lpfc_hba *, struct lpfc_iocbq *,
46 static int lpfc_max_els_tries = 3;
49 lpfc_els_chk_latt(struct lpfc_vport *vport)
51 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
52 struct lpfc_hba *phba = vport->phba;
55 if (vport->port_state >= LPFC_VPORT_READY ||
56 phba->link_state == LPFC_LINK_DOWN)
59 /* Read the HBA Host Attention Register */
60 ha_copy = readl(phba->HAregaddr);
62 if (!(ha_copy & HA_LATT))
65 /* Pending Link Event during Discovery */
66 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
67 "0237 Pending Link Event during "
68 "Discovery: State x%x\n",
69 phba->pport->port_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(shost->host_lock);
78 vport->fc_flag |= FC_ABORT_DISCOVERY;
79 spin_unlock_irq(shost->host_lock);
81 if (phba->link_state != LPFC_CLEAR_LA)
82 lpfc_issue_clear_la(phba, vport);
87 static struct lpfc_iocbq *
88 lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp,
89 uint16_t cmdSize, uint8_t retry,
90 struct lpfc_nodelist *ndlp, uint32_t did,
93 struct lpfc_hba *phba = vport->phba;
94 struct lpfc_iocbq *elsiocb;
95 struct lpfc_dmabuf *pcmd, *prsp, *pbuflist;
96 struct ulp_bde64 *bpl;
100 if (!lpfc_is_link_up(phba))
103 /* Allocate buffer for command iocb */
104 elsiocb = lpfc_sli_get_iocbq(phba);
108 icmd = &elsiocb->iocb;
110 /* fill in BDEs for command */
111 /* Allocate buffer for command payload */
112 pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
114 pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys);
115 if (!pcmd || !pcmd->virt) {
118 lpfc_sli_release_iocbq(phba, elsiocb);
122 INIT_LIST_HEAD(&pcmd->list);
124 /* Allocate buffer for response payload */
126 prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
128 prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
130 if (!prsp || !prsp->virt) {
132 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
134 lpfc_sli_release_iocbq(phba, elsiocb);
137 INIT_LIST_HEAD(&prsp->list);
142 /* Allocate buffer for Buffer ptr list */
143 pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
145 pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
147 if (!pbuflist || !pbuflist->virt) {
148 lpfc_sli_release_iocbq(phba, elsiocb);
149 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
150 lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
157 INIT_LIST_HEAD(&pbuflist->list);
159 icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
160 icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
161 icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BDL;
162 icmd->un.elsreq64.remoteID = did; /* DID */
164 icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
165 icmd->ulpCommand = CMD_ELS_REQUEST64_CR;
166 icmd->ulpTimeout = phba->fc_ratov * 2;
168 icmd->un.elsreq64.bdl.bdeSize = sizeof(struct ulp_bde64);
169 icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
171 icmd->ulpBdeCount = 1;
173 icmd->ulpClass = CLASS3;
175 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
176 icmd->un.elsreq64.myID = vport->fc_myDID;
178 /* For ELS_REQUEST64_CR, use the VPI by default */
179 icmd->ulpContext = vport->vpi;
184 bpl = (struct ulp_bde64 *) pbuflist->virt;
185 bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys));
186 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys));
187 bpl->tus.f.bdeSize = cmdSize;
188 bpl->tus.f.bdeFlags = 0;
189 bpl->tus.w = le32_to_cpu(bpl->tus.w);
193 bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys));
194 bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys));
195 bpl->tus.f.bdeSize = FCELSSIZE;
196 bpl->tus.f.bdeFlags = BUFF_USE_RCV;
197 bpl->tus.w = le32_to_cpu(bpl->tus.w);
200 elsiocb->context1 = lpfc_nlp_get(ndlp);
201 elsiocb->context2 = pcmd;
202 elsiocb->context3 = pbuflist;
203 elsiocb->retry = retry;
204 elsiocb->vport = vport;
205 elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
208 list_add(&prsp->list, &pcmd->list);
211 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
212 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
213 "0116 Xmit ELS command x%x to remote "
214 "NPORT x%x I/O tag: x%x, port state: x%x\n",
215 elscmd, did, elsiocb->iotag,
218 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
219 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
220 "0117 Xmit ELS response x%x to remote "
221 "NPORT x%x I/O tag: x%x, size: x%x\n",
222 elscmd, ndlp->nlp_DID, elsiocb->iotag,
230 lpfc_issue_fabric_reglogin(struct lpfc_vport *vport)
232 struct lpfc_hba *phba = vport->phba;
234 struct lpfc_dmabuf *mp;
235 struct lpfc_nodelist *ndlp;
236 struct serv_parm *sp;
240 sp = &phba->fc_fabparam;
241 ndlp = lpfc_findnode_did(vport, Fabric_DID);
247 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
253 vport->port_state = LPFC_FABRIC_CFG_LINK;
254 lpfc_config_link(phba, mbox);
255 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
258 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
259 if (rc == MBX_NOT_FINISHED) {
264 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
269 rc = lpfc_reg_login(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox,
276 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
278 mbox->context2 = lpfc_nlp_get(ndlp);
280 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
281 if (rc == MBX_NOT_FINISHED) {
283 goto fail_issue_reg_login;
288 fail_issue_reg_login:
290 mp = (struct lpfc_dmabuf *) mbox->context1;
291 lpfc_mbuf_free(phba, mp->virt, mp->phys);
294 mempool_free(mbox, phba->mbox_mem_pool);
297 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
298 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
299 "0249 Cannot issue Register Fabric login: Err %d\n", err);
304 lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
305 struct serv_parm *sp, IOCB_t *irsp)
307 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
308 struct lpfc_hba *phba = vport->phba;
309 struct lpfc_nodelist *np;
310 struct lpfc_nodelist *next_np;
312 spin_lock_irq(shost->host_lock);
313 vport->fc_flag |= FC_FABRIC;
314 spin_unlock_irq(shost->host_lock);
316 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
317 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
318 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
320 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
322 if (phba->fc_topology == TOPOLOGY_LOOP) {
323 spin_lock_irq(shost->host_lock);
324 vport->fc_flag |= FC_PUBLIC_LOOP;
325 spin_unlock_irq(shost->host_lock);
328 * If we are a N-port connected to a Fabric, fixup sparam's so
329 * logins to devices on remote loops work.
331 vport->fc_sparam.cmn.altBbCredit = 1;
334 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
335 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
336 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
337 ndlp->nlp_class_sup = 0;
338 if (sp->cls1.classValid)
339 ndlp->nlp_class_sup |= FC_COS_CLASS1;
340 if (sp->cls2.classValid)
341 ndlp->nlp_class_sup |= FC_COS_CLASS2;
342 if (sp->cls3.classValid)
343 ndlp->nlp_class_sup |= FC_COS_CLASS3;
344 if (sp->cls4.classValid)
345 ndlp->nlp_class_sup |= FC_COS_CLASS4;
346 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
347 sp->cmn.bbRcvSizeLsb;
348 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
350 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
351 if (sp->cmn.response_multiple_NPort) {
352 lpfc_printf_vlog(vport, KERN_WARNING,
354 "1816 FLOGI NPIV supported, "
355 "response data 0x%x\n",
356 sp->cmn.response_multiple_NPort);
357 phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
359 /* Because we asked f/w for NPIV it still expects us
360 to call reg_vnpid atleast for the physcial host */
361 lpfc_printf_vlog(vport, KERN_WARNING,
363 "1817 Fabric does not support NPIV "
364 "- configuring single port mode.\n");
365 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
369 if ((vport->fc_prevDID != vport->fc_myDID) &&
370 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
372 /* If our NportID changed, we need to ensure all
373 * remaining NPORTs get unreg_login'ed.
375 list_for_each_entry_safe(np, next_np,
376 &vport->fc_nodes, nlp_listp) {
377 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
378 !(np->nlp_flag & NLP_NPR_ADISC))
380 spin_lock_irq(shost->host_lock);
381 np->nlp_flag &= ~NLP_NPR_ADISC;
382 spin_unlock_irq(shost->host_lock);
383 lpfc_unreg_rpi(vport, np);
385 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
386 lpfc_mbx_unreg_vpi(vport);
387 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
391 ndlp->nlp_sid = irsp->un.ulpWord[4] & Mask_DID;
392 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
394 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
395 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) {
396 lpfc_register_new_vport(phba, vport, ndlp);
399 lpfc_issue_fabric_reglogin(vport);
404 * We FLOGIed into an NPort, initiate pt2pt protocol
407 lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
408 struct serv_parm *sp)
410 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
411 struct lpfc_hba *phba = vport->phba;
415 spin_lock_irq(shost->host_lock);
416 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
417 spin_unlock_irq(shost->host_lock);
419 phba->fc_edtov = FF_DEF_EDTOV;
420 phba->fc_ratov = FF_DEF_RATOV;
421 rc = memcmp(&vport->fc_portname, &sp->portName,
422 sizeof(vport->fc_portname));
424 /* This side will initiate the PLOGI */
425 spin_lock_irq(shost->host_lock);
426 vport->fc_flag |= FC_PT2PT_PLOGI;
427 spin_unlock_irq(shost->host_lock);
430 * N_Port ID cannot be 0, set our to LocalID the other
431 * side will be RemoteID.
436 vport->fc_myDID = PT2PT_LocalID;
438 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
442 lpfc_config_link(phba, mbox);
444 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
446 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
447 if (rc == MBX_NOT_FINISHED) {
448 mempool_free(mbox, phba->mbox_mem_pool);
453 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
456 * Cannot find existing Fabric ndlp, so allocate a
459 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
463 lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID);
466 memcpy(&ndlp->nlp_portname, &sp->portName,
467 sizeof(struct lpfc_name));
468 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
469 sizeof(struct lpfc_name));
470 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
471 spin_lock_irq(shost->host_lock);
472 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
473 spin_unlock_irq(shost->host_lock);
475 /* This side will wait for the PLOGI */
479 spin_lock_irq(shost->host_lock);
480 vport->fc_flag |= FC_PT2PT;
481 spin_unlock_irq(shost->host_lock);
483 /* Start discovery - this should just do CLEAR_LA */
484 lpfc_disc_start(vport);
491 lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
492 struct lpfc_iocbq *rspiocb)
494 struct lpfc_vport *vport = cmdiocb->vport;
495 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
496 IOCB_t *irsp = &rspiocb->iocb;
497 struct lpfc_nodelist *ndlp = cmdiocb->context1;
498 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
499 struct serv_parm *sp;
502 /* Check to see if link went down during discovery */
503 if (lpfc_els_chk_latt(vport)) {
508 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
509 "FLOGI cmpl: status:x%x/x%x state:x%x",
510 irsp->ulpStatus, irsp->un.ulpWord[4],
513 if (irsp->ulpStatus) {
514 /* Check for retry */
515 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
518 /* FLOGI failed, so there is no fabric */
519 spin_lock_irq(shost->host_lock);
520 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
521 spin_unlock_irq(shost->host_lock);
523 /* If private loop, then allow max outstanding els to be
524 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
525 * alpa map would take too long otherwise.
527 if (phba->alpa_map[0] == 0) {
528 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
532 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
533 "0100 FLOGI failure Data: x%x x%x "
535 irsp->ulpStatus, irsp->un.ulpWord[4],
541 * The FLogI succeeded. Sync the data for the CPU before
544 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
546 sp = prsp->virt + sizeof(uint32_t);
548 /* FLOGI completes successfully */
549 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
550 "0101 FLOGI completes sucessfully "
551 "Data: x%x x%x x%x x%x\n",
552 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
553 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution);
555 if (vport->port_state == LPFC_FLOGI) {
557 * If Common Service Parameters indicate Nport
558 * we are point to point, if Fport we are Fabric.
561 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
563 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
572 if (!lpfc_error_lost_link(irsp)) {
573 /* FLOGI failed, so just use loop map to make discovery list */
574 lpfc_disc_list_loopmap(vport);
576 /* Start discovery */
577 lpfc_disc_start(vport);
578 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
579 ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) &&
580 (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) &&
581 (phba->link_state != LPFC_CLEAR_LA)) {
582 /* If FLOGI failed enable link interrupt. */
583 lpfc_issue_clear_la(phba, vport);
586 lpfc_els_free_iocb(phba, cmdiocb);
590 lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
593 struct lpfc_hba *phba = vport->phba;
594 struct serv_parm *sp;
596 struct lpfc_iocbq *elsiocb;
597 struct lpfc_sli_ring *pring;
603 pring = &phba->sli.ring[LPFC_ELS_RING];
605 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
606 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
607 ndlp->nlp_DID, ELS_CMD_FLOGI);
612 icmd = &elsiocb->iocb;
613 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
615 /* For FLOGI request, remainder of payload is service parameters */
616 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
617 pcmd += sizeof(uint32_t);
618 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
619 sp = (struct serv_parm *) pcmd;
621 /* Setup CSPs accordingly for Fabric */
623 sp->cmn.w2.r_a_tov = 0;
624 sp->cls1.classValid = 0;
625 sp->cls2.seqDelivery = 1;
626 sp->cls3.seqDelivery = 1;
627 if (sp->cmn.fcphLow < FC_PH3)
628 sp->cmn.fcphLow = FC_PH3;
629 if (sp->cmn.fcphHigh < FC_PH3)
630 sp->cmn.fcphHigh = FC_PH3;
632 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
633 sp->cmn.request_multiple_Nport = 1;
635 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
640 if (phba->fc_topology != TOPOLOGY_LOOP) {
641 icmd->un.elsreq64.myID = 0;
642 icmd->un.elsreq64.fl = 1;
645 tmo = phba->fc_ratov;
646 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
647 lpfc_set_disctmo(vport);
648 phba->fc_ratov = tmo;
650 phba->fc_stat.elsXmitFLOGI++;
651 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
653 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
654 "Issue FLOGI: opt:x%x",
655 phba->sli3_options, 0, 0);
657 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
658 if (rc == IOCB_ERROR) {
659 lpfc_els_free_iocb(phba, elsiocb);
666 lpfc_els_abort_flogi(struct lpfc_hba *phba)
668 struct lpfc_sli_ring *pring;
669 struct lpfc_iocbq *iocb, *next_iocb;
670 struct lpfc_nodelist *ndlp;
673 /* Abort outstanding I/O on NPort <nlp_DID> */
674 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
675 "0201 Abort outstanding I/O on NPort x%x\n",
678 pring = &phba->sli.ring[LPFC_ELS_RING];
681 * Check the txcmplq for an iocb that matches the nport the driver is
684 spin_lock_irq(&phba->hbalock);
685 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
687 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR &&
688 icmd->un.elsreq64.bdl.ulpIoTag32) {
689 ndlp = (struct lpfc_nodelist *)(iocb->context1);
690 if (ndlp && (ndlp->nlp_DID == Fabric_DID)) {
691 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
695 spin_unlock_irq(&phba->hbalock);
701 lpfc_initial_flogi(struct lpfc_vport *vport)
703 struct lpfc_hba *phba = vport->phba;
704 struct lpfc_nodelist *ndlp;
706 vport->port_state = LPFC_FLOGI;
707 lpfc_set_disctmo(vport);
709 /* First look for the Fabric ndlp */
710 ndlp = lpfc_findnode_did(vport, Fabric_DID);
712 /* Cannot find existing Fabric ndlp, so allocate a new one */
713 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
716 lpfc_nlp_init(vport, ndlp, Fabric_DID);
718 lpfc_dequeue_node(vport, ndlp);
721 if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
728 lpfc_initial_fdisc(struct lpfc_vport *vport)
730 struct lpfc_hba *phba = vport->phba;
731 struct lpfc_nodelist *ndlp;
733 /* First look for the Fabric ndlp */
734 ndlp = lpfc_findnode_did(vport, Fabric_DID);
736 /* Cannot find existing Fabric ndlp, so allocate a new one */
737 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
740 lpfc_nlp_init(vport, ndlp, Fabric_DID);
742 lpfc_dequeue_node(vport, ndlp);
744 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
751 lpfc_more_plogi(struct lpfc_vport *vport)
755 if (vport->num_disc_nodes)
756 vport->num_disc_nodes--;
758 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
759 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
760 "0232 Continue discovery with %d PLOGIs to go "
761 "Data: x%x x%x x%x\n",
762 vport->num_disc_nodes, vport->fc_plogi_cnt,
763 vport->fc_flag, vport->port_state);
764 /* Check to see if there are more PLOGIs to be sent */
765 if (vport->fc_flag & FC_NLP_MORE)
766 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
767 sentplogi = lpfc_els_disc_plogi(vport);
772 static struct lpfc_nodelist *
773 lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
774 struct lpfc_nodelist *ndlp)
776 struct lpfc_vport *vport = ndlp->vport;
777 struct lpfc_nodelist *new_ndlp;
778 struct serv_parm *sp;
779 uint8_t name[sizeof(struct lpfc_name)];
782 /* Fabric nodes can have the same WWPN so we don't bother searching
783 * by WWPN. Just return the ndlp that was given to us.
785 if (ndlp->nlp_type & NLP_FABRIC)
788 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
789 memset(name, 0, sizeof(struct lpfc_name));
791 /* Now we find out if the NPort we are logging into, matches the WWPN
792 * we have for that ndlp. If not, we have some work to do.
794 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
796 if (new_ndlp == ndlp)
800 rc = memcmp(&ndlp->nlp_portname, name,
801 sizeof(struct lpfc_name));
804 new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
808 lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID);
811 lpfc_unreg_rpi(vport, new_ndlp);
812 new_ndlp->nlp_DID = ndlp->nlp_DID;
813 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
814 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
816 /* Move this back to NPR state */
817 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
818 /* The new_ndlp is replacing ndlp totally, so we need
819 * to put ndlp on UNUSED list and try to free it.
821 lpfc_drop_node(vport, ndlp);
824 lpfc_unreg_rpi(vport, ndlp);
825 ndlp->nlp_DID = 0; /* Two ndlps cannot have the same did */
826 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
832 lpfc_end_rscn(struct lpfc_vport *vport)
834 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
836 if (vport->fc_flag & FC_RSCN_MODE) {
838 * Check to see if more RSCNs came in while we were
839 * processing this one.
841 if (vport->fc_rscn_id_cnt ||
842 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
843 lpfc_els_handle_rscn(vport);
845 spin_lock_irq(shost->host_lock);
846 vport->fc_flag &= ~FC_RSCN_MODE;
847 spin_unlock_irq(shost->host_lock);
853 lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
854 struct lpfc_iocbq *rspiocb)
856 struct lpfc_vport *vport = cmdiocb->vport;
857 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
859 struct lpfc_nodelist *ndlp;
860 struct lpfc_dmabuf *prsp;
861 int disc, rc, did, type;
863 /* we pass cmdiocb to state machine which needs rspiocb as well */
864 cmdiocb->context_un.rsp_iocb = rspiocb;
866 irsp = &rspiocb->iocb;
867 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
868 "PLOGI cmpl: status:x%x/x%x did:x%x",
869 irsp->ulpStatus, irsp->un.ulpWord[4],
870 irsp->un.elsreq64.remoteID);
872 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
874 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
875 "0136 PLOGI completes to NPort x%x "
876 "with no ndlp. Data: x%x x%x x%x\n",
877 irsp->un.elsreq64.remoteID,
878 irsp->ulpStatus, irsp->un.ulpWord[4],
883 /* Since ndlp can be freed in the disc state machine, note if this node
884 * is being used during discovery.
886 spin_lock_irq(shost->host_lock);
887 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
888 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
889 spin_unlock_irq(shost->host_lock);
892 /* PLOGI completes to NPort <nlp_DID> */
893 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
894 "0102 PLOGI completes to NPort x%x "
895 "Data: x%x x%x x%x x%x x%x\n",
896 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
897 irsp->ulpTimeout, disc, vport->num_disc_nodes);
898 /* Check to see if link went down during discovery */
899 if (lpfc_els_chk_latt(vport)) {
900 spin_lock_irq(shost->host_lock);
901 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
902 spin_unlock_irq(shost->host_lock);
906 /* ndlp could be freed in DSM, save these values now */
907 type = ndlp->nlp_type;
910 if (irsp->ulpStatus) {
911 /* Check for retry */
912 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
913 /* ELS command is being retried */
915 spin_lock_irq(shost->host_lock);
916 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
917 spin_unlock_irq(shost->host_lock);
922 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
923 if (lpfc_error_lost_link(irsp)) {
924 rc = NLP_STE_FREED_NODE;
926 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
930 /* Good status, call state machine */
931 prsp = list_entry(((struct lpfc_dmabuf *)
932 cmdiocb->context2)->list.next,
933 struct lpfc_dmabuf, list);
934 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
935 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
939 if (disc && vport->num_disc_nodes) {
940 /* Check to see if there are more PLOGIs to be sent */
941 lpfc_more_plogi(vport);
943 if (vport->num_disc_nodes == 0) {
944 spin_lock_irq(shost->host_lock);
945 vport->fc_flag &= ~FC_NDISC_ACTIVE;
946 spin_unlock_irq(shost->host_lock);
948 lpfc_can_disctmo(vport);
949 lpfc_end_rscn(vport);
954 lpfc_els_free_iocb(phba, cmdiocb);
959 lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
961 struct lpfc_hba *phba = vport->phba;
962 struct serv_parm *sp;
964 struct lpfc_nodelist *ndlp;
965 struct lpfc_iocbq *elsiocb;
966 struct lpfc_sli_ring *pring;
967 struct lpfc_sli *psli;
973 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
975 ndlp = lpfc_findnode_did(vport, did);
976 /* If ndlp if not NULL, we will bump the reference count on it */
978 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
979 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
984 icmd = &elsiocb->iocb;
985 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
987 /* For PLOGI request, remainder of payload is service parameters */
988 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
989 pcmd += sizeof(uint32_t);
990 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
991 sp = (struct serv_parm *) pcmd;
993 if (sp->cmn.fcphLow < FC_PH_4_3)
994 sp->cmn.fcphLow = FC_PH_4_3;
996 if (sp->cmn.fcphHigh < FC_PH3)
997 sp->cmn.fcphHigh = FC_PH3;
999 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1000 "Issue PLOGI: did:x%x",
1003 phba->fc_stat.elsXmitPLOGI++;
1004 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
1005 ret = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
1007 if (ret == IOCB_ERROR) {
1008 lpfc_els_free_iocb(phba, elsiocb);
1015 lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1016 struct lpfc_iocbq *rspiocb)
1018 struct lpfc_vport *vport = cmdiocb->vport;
1019 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1021 struct lpfc_sli *psli;
1022 struct lpfc_nodelist *ndlp;
1025 /* we pass cmdiocb to state machine which needs rspiocb as well */
1026 cmdiocb->context_un.rsp_iocb = rspiocb;
1028 irsp = &(rspiocb->iocb);
1029 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1030 spin_lock_irq(shost->host_lock);
1031 ndlp->nlp_flag &= ~NLP_PRLI_SND;
1032 spin_unlock_irq(shost->host_lock);
1034 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1035 "PRLI cmpl: status:x%x/x%x did:x%x",
1036 irsp->ulpStatus, irsp->un.ulpWord[4],
1038 /* PRLI completes to NPort <nlp_DID> */
1039 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1040 "0103 PRLI completes to NPort x%x "
1041 "Data: x%x x%x x%x x%x\n",
1042 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1043 irsp->ulpTimeout, vport->num_disc_nodes);
1045 vport->fc_prli_sent--;
1046 /* Check to see if link went down during discovery */
1047 if (lpfc_els_chk_latt(vport))
1050 if (irsp->ulpStatus) {
1051 /* Check for retry */
1052 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1053 /* ELS command is being retried */
1057 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1058 if (lpfc_error_lost_link(irsp)) {
1061 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1065 /* Good status, call state machine */
1066 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1071 lpfc_els_free_iocb(phba, cmdiocb);
1076 lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1079 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1080 struct lpfc_hba *phba = vport->phba;
1083 struct lpfc_iocbq *elsiocb;
1084 struct lpfc_sli_ring *pring;
1085 struct lpfc_sli *psli;
1090 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1092 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
1093 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1094 ndlp->nlp_DID, ELS_CMD_PRLI);
1098 icmd = &elsiocb->iocb;
1099 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1101 /* For PRLI request, remainder of payload is service parameters */
1102 memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t)));
1103 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
1104 pcmd += sizeof(uint32_t);
1106 /* For PRLI, remainder of payload is PRLI parameter page */
1107 npr = (PRLI *) pcmd;
1109 * If our firmware version is 3.20 or later,
1110 * set the following bits for FC-TAPE support.
1112 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
1113 npr->ConfmComplAllowed = 1;
1115 npr->TaskRetryIdReq = 1;
1117 npr->estabImagePair = 1;
1118 npr->readXferRdyDis = 1;
1120 /* For FCP support */
1121 npr->prliType = PRLI_FCP_TYPE;
1122 npr->initiatorFunc = 1;
1124 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1125 "Issue PRLI: did:x%x",
1126 ndlp->nlp_DID, 0, 0);
1128 phba->fc_stat.elsXmitPRLI++;
1129 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
1130 spin_lock_irq(shost->host_lock);
1131 ndlp->nlp_flag |= NLP_PRLI_SND;
1132 spin_unlock_irq(shost->host_lock);
1133 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
1134 spin_lock_irq(shost->host_lock);
1135 ndlp->nlp_flag &= ~NLP_PRLI_SND;
1136 spin_unlock_irq(shost->host_lock);
1137 lpfc_els_free_iocb(phba, elsiocb);
1140 vport->fc_prli_sent++;
1145 lpfc_more_adisc(struct lpfc_vport *vport)
1149 if (vport->num_disc_nodes)
1150 vport->num_disc_nodes--;
1151 /* Continue discovery with <num_disc_nodes> ADISCs to go */
1152 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1153 "0210 Continue discovery with %d ADISCs to go "
1154 "Data: x%x x%x x%x\n",
1155 vport->num_disc_nodes, vport->fc_adisc_cnt,
1156 vport->fc_flag, vport->port_state);
1157 /* Check to see if there are more ADISCs to be sent */
1158 if (vport->fc_flag & FC_NLP_MORE) {
1159 lpfc_set_disctmo(vport);
1160 /* go thru NPR nodes and issue any remaining ELS ADISCs */
1161 sentadisc = lpfc_els_disc_adisc(vport);
1167 lpfc_rscn_disc(struct lpfc_vport *vport)
1169 lpfc_can_disctmo(vport);
1171 /* RSCN discovery */
1172 /* go thru NPR nodes and issue ELS PLOGIs */
1173 if (vport->fc_npr_cnt)
1174 if (lpfc_els_disc_plogi(vport))
1177 lpfc_end_rscn(vport);
1181 lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1182 struct lpfc_iocbq *rspiocb)
1184 struct lpfc_vport *vport = cmdiocb->vport;
1185 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1187 struct lpfc_nodelist *ndlp;
1190 /* we pass cmdiocb to state machine which needs rspiocb as well */
1191 cmdiocb->context_un.rsp_iocb = rspiocb;
1193 irsp = &(rspiocb->iocb);
1194 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1196 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1197 "ADISC cmpl: status:x%x/x%x did:x%x",
1198 irsp->ulpStatus, irsp->un.ulpWord[4],
1201 /* Since ndlp can be freed in the disc state machine, note if this node
1202 * is being used during discovery.
1204 spin_lock_irq(shost->host_lock);
1205 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
1206 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
1207 spin_unlock_irq(shost->host_lock);
1208 /* ADISC completes to NPort <nlp_DID> */
1209 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1210 "0104 ADISC completes to NPort x%x "
1211 "Data: x%x x%x x%x x%x x%x\n",
1212 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1213 irsp->ulpTimeout, disc, vport->num_disc_nodes);
1214 /* Check to see if link went down during discovery */
1215 if (lpfc_els_chk_latt(vport)) {
1216 spin_lock_irq(shost->host_lock);
1217 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1218 spin_unlock_irq(shost->host_lock);
1222 if (irsp->ulpStatus) {
1223 /* Check for retry */
1224 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1225 /* ELS command is being retried */
1227 spin_lock_irq(shost->host_lock);
1228 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1229 spin_unlock_irq(shost->host_lock);
1230 lpfc_set_disctmo(vport);
1235 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1236 if (!lpfc_error_lost_link(irsp)) {
1237 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1238 NLP_EVT_CMPL_ADISC);
1241 /* Good status, call state machine */
1242 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1243 NLP_EVT_CMPL_ADISC);
1246 if (disc && vport->num_disc_nodes) {
1247 /* Check to see if there are more ADISCs to be sent */
1248 lpfc_more_adisc(vport);
1250 /* Check to see if we are done with ADISC authentication */
1251 if (vport->num_disc_nodes == 0) {
1252 /* If we get here, there is nothing left to ADISC */
1254 * For NPIV, cmpl_reg_vpi will set port_state to READY,
1255 * and continue discovery.
1257 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
1258 !(vport->fc_flag & FC_RSCN_MODE)) {
1259 lpfc_issue_reg_vpi(phba, vport);
1263 * For SLI2, we need to set port_state to READY
1264 * and continue discovery.
1266 if (vport->port_state < LPFC_VPORT_READY) {
1267 /* If we get here, there is nothing to ADISC */
1268 if (vport->port_type == LPFC_PHYSICAL_PORT)
1269 lpfc_issue_clear_la(phba, vport);
1271 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
1272 vport->num_disc_nodes = 0;
1273 /* go thru NPR list, issue ELS PLOGIs */
1274 if (vport->fc_npr_cnt)
1275 lpfc_els_disc_plogi(vport);
1277 if (!vport->num_disc_nodes) {
1278 spin_lock_irq(shost->host_lock);
1283 lpfc_can_disctmo(vport);
1286 vport->port_state = LPFC_VPORT_READY;
1288 lpfc_rscn_disc(vport);
1293 lpfc_els_free_iocb(phba, cmdiocb);
1298 lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1301 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1302 struct lpfc_hba *phba = vport->phba;
1305 struct lpfc_iocbq *elsiocb;
1306 struct lpfc_sli *psli = &phba->sli;
1307 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
1311 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
1312 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1313 ndlp->nlp_DID, ELS_CMD_ADISC);
1317 icmd = &elsiocb->iocb;
1318 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1320 /* For ADISC request, remainder of payload is service parameters */
1321 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
1322 pcmd += sizeof(uint32_t);
1324 /* Fill in ADISC payload */
1325 ap = (ADISC *) pcmd;
1326 ap->hardAL_PA = phba->fc_pref_ALPA;
1327 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
1328 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
1329 ap->DID = be32_to_cpu(vport->fc_myDID);
1331 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1332 "Issue ADISC: did:x%x",
1333 ndlp->nlp_DID, 0, 0);
1335 phba->fc_stat.elsXmitADISC++;
1336 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
1337 spin_lock_irq(shost->host_lock);
1338 ndlp->nlp_flag |= NLP_ADISC_SND;
1339 spin_unlock_irq(shost->host_lock);
1340 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
1341 spin_lock_irq(shost->host_lock);
1342 ndlp->nlp_flag &= ~NLP_ADISC_SND;
1343 spin_unlock_irq(shost->host_lock);
1344 lpfc_els_free_iocb(phba, elsiocb);
1351 lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1352 struct lpfc_iocbq *rspiocb)
1354 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1355 struct lpfc_vport *vport = ndlp->vport;
1356 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1358 struct lpfc_sli *psli;
1361 /* we pass cmdiocb to state machine which needs rspiocb as well */
1362 cmdiocb->context_un.rsp_iocb = rspiocb;
1364 irsp = &(rspiocb->iocb);
1365 spin_lock_irq(shost->host_lock);
1366 ndlp->nlp_flag &= ~NLP_LOGO_SND;
1367 spin_unlock_irq(shost->host_lock);
1369 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1370 "LOGO cmpl: status:x%x/x%x did:x%x",
1371 irsp->ulpStatus, irsp->un.ulpWord[4],
1373 /* LOGO completes to NPort <nlp_DID> */
1374 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1375 "0105 LOGO completes to NPort x%x "
1376 "Data: x%x x%x x%x x%x\n",
1377 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1378 irsp->ulpTimeout, vport->num_disc_nodes);
1379 /* Check to see if link went down during discovery */
1380 if (lpfc_els_chk_latt(vport))
1383 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
1384 /* NLP_EVT_DEVICE_RM should unregister the RPI
1385 * which should abort all outstanding IOs.
1387 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1392 if (irsp->ulpStatus) {
1393 /* Check for retry */
1394 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
1395 /* ELS command is being retried */
1398 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1399 if (lpfc_error_lost_link(irsp))
1402 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1405 /* Good status, call state machine.
1406 * This will unregister the rpi if needed.
1408 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1413 lpfc_els_free_iocb(phba, cmdiocb);
1418 lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1421 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1422 struct lpfc_hba *phba = vport->phba;
1424 struct lpfc_iocbq *elsiocb;
1425 struct lpfc_sli_ring *pring;
1426 struct lpfc_sli *psli;
1432 pring = &psli->ring[LPFC_ELS_RING];
1434 spin_lock_irq(shost->host_lock);
1435 if (ndlp->nlp_flag & NLP_LOGO_SND) {
1436 spin_unlock_irq(shost->host_lock);
1439 spin_unlock_irq(shost->host_lock);
1441 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
1442 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1443 ndlp->nlp_DID, ELS_CMD_LOGO);
1447 icmd = &elsiocb->iocb;
1448 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1449 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
1450 pcmd += sizeof(uint32_t);
1452 /* Fill in LOGO payload */
1453 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
1454 pcmd += sizeof(uint32_t);
1455 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
1457 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1458 "Issue LOGO: did:x%x",
1459 ndlp->nlp_DID, 0, 0);
1461 phba->fc_stat.elsXmitLOGO++;
1462 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
1463 spin_lock_irq(shost->host_lock);
1464 ndlp->nlp_flag |= NLP_LOGO_SND;
1465 spin_unlock_irq(shost->host_lock);
1466 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
1468 if (rc == IOCB_ERROR) {
1469 spin_lock_irq(shost->host_lock);
1470 ndlp->nlp_flag &= ~NLP_LOGO_SND;
1471 spin_unlock_irq(shost->host_lock);
1472 lpfc_els_free_iocb(phba, elsiocb);
1479 lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1480 struct lpfc_iocbq *rspiocb)
1482 struct lpfc_vport *vport = cmdiocb->vport;
1485 irsp = &rspiocb->iocb;
1487 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1488 "ELS cmd cmpl: status:x%x/x%x did:x%x",
1489 irsp->ulpStatus, irsp->un.ulpWord[4],
1490 irsp->un.elsreq64.remoteID);
1491 /* ELS cmd tag <ulpIoTag> completes */
1492 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1493 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
1494 irsp->ulpIoTag, irsp->ulpStatus,
1495 irsp->un.ulpWord[4], irsp->ulpTimeout);
1496 /* Check to see if link went down during discovery */
1497 lpfc_els_chk_latt(vport);
1498 lpfc_els_free_iocb(phba, cmdiocb);
1503 lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
1505 struct lpfc_hba *phba = vport->phba;
1507 struct lpfc_iocbq *elsiocb;
1508 struct lpfc_sli_ring *pring;
1509 struct lpfc_sli *psli;
1512 struct lpfc_nodelist *ndlp;
1515 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1516 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
1517 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1521 lpfc_nlp_init(vport, ndlp, nportid);
1523 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1524 ndlp->nlp_DID, ELS_CMD_SCR);
1531 icmd = &elsiocb->iocb;
1532 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1534 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
1535 pcmd += sizeof(uint32_t);
1537 /* For SCR, remainder of payload is SCR parameter page */
1538 memset(pcmd, 0, sizeof(SCR));
1539 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
1541 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1542 "Issue SCR: did:x%x",
1543 ndlp->nlp_DID, 0, 0);
1545 phba->fc_stat.elsXmitSCR++;
1546 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
1547 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
1549 lpfc_els_free_iocb(phba, elsiocb);
1557 lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
1559 struct lpfc_hba *phba = vport->phba;
1561 struct lpfc_iocbq *elsiocb;
1562 struct lpfc_sli_ring *pring;
1563 struct lpfc_sli *psli;
1568 struct lpfc_nodelist *ondlp;
1569 struct lpfc_nodelist *ndlp;
1572 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1573 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
1574 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1578 lpfc_nlp_init(vport, ndlp, nportid);
1580 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1581 ndlp->nlp_DID, ELS_CMD_RNID);
1587 icmd = &elsiocb->iocb;
1588 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1590 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
1591 pcmd += sizeof(uint32_t);
1593 /* Fill in FARPR payload */
1594 fp = (FARP *) (pcmd);
1595 memset(fp, 0, sizeof(FARP));
1596 lp = (uint32_t *) pcmd;
1597 *lp++ = be32_to_cpu(nportid);
1598 *lp++ = be32_to_cpu(vport->fc_myDID);
1600 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
1602 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
1603 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
1604 ondlp = lpfc_findnode_did(vport, nportid);
1606 memcpy(&fp->OportName, &ondlp->nlp_portname,
1607 sizeof(struct lpfc_name));
1608 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
1609 sizeof(struct lpfc_name));
1612 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1613 "Issue FARPR: did:x%x",
1614 ndlp->nlp_DID, 0, 0);
1616 phba->fc_stat.elsXmitFARPR++;
1617 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
1618 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
1620 lpfc_els_free_iocb(phba, elsiocb);
1628 lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
1630 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1632 spin_lock_irq(shost->host_lock);
1633 nlp->nlp_flag &= ~NLP_DELAY_TMO;
1634 spin_unlock_irq(shost->host_lock);
1635 del_timer_sync(&nlp->nlp_delayfunc);
1636 nlp->nlp_last_elscmd = 0;
1638 if (!list_empty(&nlp->els_retry_evt.evt_listp))
1639 list_del_init(&nlp->els_retry_evt.evt_listp);
1641 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
1642 spin_lock_irq(shost->host_lock);
1643 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1644 spin_unlock_irq(shost->host_lock);
1645 if (vport->num_disc_nodes) {
1646 /* Check to see if there are more
1649 lpfc_more_plogi(vport);
1651 if (vport->num_disc_nodes == 0) {
1652 spin_lock_irq(shost->host_lock);
1653 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1654 spin_unlock_irq(shost->host_lock);
1655 lpfc_can_disctmo(vport);
1656 lpfc_end_rscn(vport);
1664 lpfc_els_retry_delay(unsigned long ptr)
1666 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
1667 struct lpfc_vport *vport = ndlp->vport;
1668 struct lpfc_hba *phba = vport->phba;
1669 unsigned long flags;
1670 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
1672 ndlp = (struct lpfc_nodelist *) ptr;
1673 phba = ndlp->vport->phba;
1674 evtp = &ndlp->els_retry_evt;
1676 spin_lock_irqsave(&phba->hbalock, flags);
1677 if (!list_empty(&evtp->evt_listp)) {
1678 spin_unlock_irqrestore(&phba->hbalock, flags);
1682 evtp->evt_arg1 = ndlp;
1683 evtp->evt = LPFC_EVT_ELS_RETRY;
1684 list_add_tail(&evtp->evt_listp, &phba->work_list);
1685 if (phba->work_wait)
1686 lpfc_worker_wake_up(phba);
1688 spin_unlock_irqrestore(&phba->hbalock, flags);
1693 lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
1695 struct lpfc_vport *vport = ndlp->vport;
1696 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1697 uint32_t cmd, did, retry;
1699 spin_lock_irq(shost->host_lock);
1700 did = ndlp->nlp_DID;
1701 cmd = ndlp->nlp_last_elscmd;
1702 ndlp->nlp_last_elscmd = 0;
1704 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
1705 spin_unlock_irq(shost->host_lock);
1709 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
1710 spin_unlock_irq(shost->host_lock);
1712 * If a discovery event readded nlp_delayfunc after timer
1713 * firing and before processing the timer, cancel the
1716 del_timer_sync(&ndlp->nlp_delayfunc);
1717 retry = ndlp->nlp_retry;
1721 lpfc_issue_els_flogi(vport, ndlp, retry);
1724 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
1725 ndlp->nlp_prev_state = ndlp->nlp_state;
1726 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1730 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
1731 ndlp->nlp_prev_state = ndlp->nlp_state;
1732 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
1736 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
1737 ndlp->nlp_prev_state = ndlp->nlp_state;
1738 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
1742 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
1743 ndlp->nlp_prev_state = ndlp->nlp_state;
1744 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1748 lpfc_issue_els_fdisc(vport, ndlp, retry);
1755 lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1756 struct lpfc_iocbq *rspiocb)
1758 struct lpfc_vport *vport = cmdiocb->vport;
1759 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1760 IOCB_t *irsp = &rspiocb->iocb;
1761 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1762 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
1765 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
1771 /* Note: context2 may be 0 for internal driver abort
1772 * of delays ELS command.
1775 if (pcmd && pcmd->virt) {
1776 elscmd = (uint32_t *) (pcmd->virt);
1781 did = ndlp->nlp_DID;
1783 /* We should only hit this case for retrying PLOGI */
1784 did = irsp->un.elsreq64.remoteID;
1785 ndlp = lpfc_findnode_did(vport, did);
1786 if (!ndlp && (cmd != ELS_CMD_PLOGI))
1790 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1791 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
1792 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
1794 switch (irsp->ulpStatus) {
1795 case IOSTAT_FCP_RSP_ERROR:
1796 case IOSTAT_REMOTE_STOP:
1799 case IOSTAT_LOCAL_REJECT:
1800 switch ((irsp->un.ulpWord[4] & 0xff)) {
1801 case IOERR_LOOP_OPEN_FAILURE:
1802 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
1807 case IOERR_ILLEGAL_COMMAND:
1808 if ((phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) &&
1809 (cmd == ELS_CMD_FDISC)) {
1810 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1811 "0124 FDISC failed (3/6) "
1813 lpfc_mbx_unreg_vpi(vport);
1815 /* FDISC retry policy */
1817 if (cmdiocb->retry >= 32)
1822 case IOERR_NO_RESOURCES:
1823 logerr = 1; /* HBA out of resources */
1825 if (cmdiocb->retry > 100)
1830 case IOERR_ILLEGAL_FRAME:
1835 case IOERR_SEQUENCE_TIMEOUT:
1836 case IOERR_INVALID_RPI:
1842 case IOSTAT_NPORT_RJT:
1843 case IOSTAT_FABRIC_RJT:
1844 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
1850 case IOSTAT_NPORT_BSY:
1851 case IOSTAT_FABRIC_BSY:
1852 logerr = 1; /* Fabric / Remote NPort out of resources */
1857 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
1858 /* Added for Vendor specifc support
1859 * Just keep retrying for these Rsn / Exp codes
1861 switch (stat.un.b.lsRjtRsnCode) {
1862 case LSRJT_UNABLE_TPC:
1863 if (stat.un.b.lsRjtRsnCodeExp ==
1864 LSEXP_CMD_IN_PROGRESS) {
1865 if (cmd == ELS_CMD_PLOGI) {
1872 if (cmd == ELS_CMD_PLOGI) {
1874 maxretry = lpfc_max_els_tries + 1;
1878 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
1879 (cmd == ELS_CMD_FDISC) &&
1880 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
1881 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1882 "0125 FDISC Failed (x%x). "
1883 "Fabric out of resources\n",
1884 stat.un.lsRjtError);
1885 lpfc_vport_set_state(vport,
1886 FC_VPORT_NO_FABRIC_RSCS);
1890 case LSRJT_LOGICAL_BSY:
1891 if ((cmd == ELS_CMD_PLOGI) ||
1892 (cmd == ELS_CMD_PRLI)) {
1895 } else if (cmd == ELS_CMD_FDISC) {
1896 /* FDISC retry policy */
1898 if (cmdiocb->retry >= 32)
1904 case LSRJT_LOGICAL_ERR:
1905 case LSRJT_PROTOCOL_ERR:
1906 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
1907 (cmd == ELS_CMD_FDISC) &&
1908 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
1909 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
1911 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1912 "0123 FDISC Failed (x%x). "
1913 "Fabric Detected Bad WWN\n",
1914 stat.un.lsRjtError);
1915 lpfc_vport_set_state(vport,
1916 FC_VPORT_FABRIC_REJ_WWN);
1922 case IOSTAT_INTERMED_RSP:
1930 if (did == FDMI_DID)
1933 if ((cmd == ELS_CMD_FLOGI) &&
1934 (phba->fc_topology != TOPOLOGY_LOOP)) {
1935 /* FLOGI retry policy */
1938 if (cmdiocb->retry >= 32)
1942 if ((++cmdiocb->retry) >= maxretry) {
1943 phba->fc_stat.elsRetryExceeded++;
1947 if ((vport->load_flag & FC_UNLOADING) != 0)
1952 /* Retry ELS command <elsCmd> to remote NPORT <did> */
1953 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1954 "0107 Retry ELS command x%x to remote "
1955 "NPORT x%x Data: x%x x%x\n",
1956 cmd, did, cmdiocb->retry, delay);
1958 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
1959 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
1960 ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) {
1961 /* Don't reset timer for no resources */
1963 /* If discovery / RSCN timer is running, reset it */
1964 if (timer_pending(&vport->fc_disctmo) ||
1965 (vport->fc_flag & FC_RSCN_MODE))
1966 lpfc_set_disctmo(vport);
1969 phba->fc_stat.elsXmitRetry++;
1970 if (ndlp && delay) {
1971 phba->fc_stat.elsDelayRetry++;
1972 ndlp->nlp_retry = cmdiocb->retry;
1974 /* delay is specified in milliseconds */
1975 mod_timer(&ndlp->nlp_delayfunc,
1976 jiffies + msecs_to_jiffies(delay));
1977 spin_lock_irq(shost->host_lock);
1978 ndlp->nlp_flag |= NLP_DELAY_TMO;
1979 spin_unlock_irq(shost->host_lock);
1981 ndlp->nlp_prev_state = ndlp->nlp_state;
1982 if (cmd == ELS_CMD_PRLI)
1983 lpfc_nlp_set_state(vport, ndlp,
1984 NLP_STE_REG_LOGIN_ISSUE);
1986 lpfc_nlp_set_state(vport, ndlp,
1988 ndlp->nlp_last_elscmd = cmd;
1994 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
1997 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
2001 ndlp->nlp_prev_state = ndlp->nlp_state;
2002 lpfc_nlp_set_state(vport, ndlp,
2003 NLP_STE_PLOGI_ISSUE);
2005 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
2008 ndlp->nlp_prev_state = ndlp->nlp_state;
2009 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2010 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
2013 ndlp->nlp_prev_state = ndlp->nlp_state;
2014 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
2015 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
2018 ndlp->nlp_prev_state = ndlp->nlp_state;
2019 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2020 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
2024 /* No retry ELS command <elsCmd> to remote NPORT <did> */
2026 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2027 "0137 No retry ELS command x%x to remote "
2028 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
2029 cmd, did, irsp->ulpStatus,
2030 irsp->un.ulpWord[4]);
2033 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2034 "0108 No retry ELS command x%x to remote "
2035 "NPORT x%x Retried:%d Error:x%x/%x\n",
2036 cmd, did, cmdiocb->retry, irsp->ulpStatus,
2037 irsp->un.ulpWord[4]);
2043 lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
2045 struct lpfc_dmabuf *buf_ptr;
2047 /* Free the response before processing the command. */
2048 if (!list_empty(&buf_ptr1->list)) {
2049 list_remove_head(&buf_ptr1->list, buf_ptr,
2052 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
2055 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
2061 lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
2063 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
2069 lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
2071 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
2073 if (elsiocb->context1) {
2074 lpfc_nlp_put(elsiocb->context1);
2075 elsiocb->context1 = NULL;
2077 /* context2 = cmd, context2->next = rsp, context3 = bpl */
2078 if (elsiocb->context2) {
2079 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
2080 lpfc_els_free_data(phba, buf_ptr1);
2083 if (elsiocb->context3) {
2084 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
2085 lpfc_els_free_bpl(phba, buf_ptr);
2087 lpfc_sli_release_iocbq(phba, elsiocb);
2092 lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2093 struct lpfc_iocbq *rspiocb)
2095 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2096 struct lpfc_vport *vport = cmdiocb->vport;
2099 irsp = &rspiocb->iocb;
2100 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2101 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
2102 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
2103 /* ACC to LOGO completes to NPort <nlp_DID> */
2104 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2105 "0109 ACC to LOGO completes to NPort x%x "
2106 "Data: x%x x%x x%x\n",
2107 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2110 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
2111 /* NPort Recovery mode or node is just allocated */
2112 if (!lpfc_nlp_not_used(ndlp)) {
2113 /* If the ndlp is being used by another discovery
2114 * thread, just unregister the RPI.
2116 lpfc_unreg_rpi(vport, ndlp);
2119 lpfc_els_free_iocb(phba, cmdiocb);
2124 lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
2126 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
2127 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
2129 pmb->context1 = NULL;
2130 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2132 mempool_free(pmb, phba->mbox_mem_pool);
2135 /* This is the end of the default RPI cleanup logic for this
2136 * ndlp. If no other discovery threads are using this ndlp.
2137 * we should free all resources associated with it.
2139 lpfc_nlp_not_used(ndlp);
2144 lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2145 struct lpfc_iocbq *rspiocb)
2147 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2148 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
2149 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
2152 LPFC_MBOXQ_t *mbox = NULL;
2153 struct lpfc_dmabuf *mp = NULL;
2154 uint32_t ls_rjt = 0;
2156 irsp = &rspiocb->iocb;
2158 if (cmdiocb->context_un.mbox)
2159 mbox = cmdiocb->context_un.mbox;
2161 /* First determine if this is a LS_RJT cmpl */
2162 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
2163 if (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT) {
2164 /* A LS_RJT associated with Default RPI cleanup
2165 * has its own seperate code path.
2167 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
2171 /* Check to see if link went down during discovery */
2172 if (!ndlp || lpfc_els_chk_latt(vport)) {
2174 mp = (struct lpfc_dmabuf *) mbox->context1;
2176 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2179 mempool_free(mbox, phba->mbox_mem_pool);
2181 if (ndlp && (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
2182 if (lpfc_nlp_not_used(ndlp))
2187 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2188 "ELS rsp cmpl: status:x%x/x%x did:x%x",
2189 irsp->ulpStatus, irsp->un.ulpWord[4],
2190 cmdiocb->iocb.un.elsreq64.remoteID);
2191 /* ELS response tag <ulpIoTag> completes */
2192 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2193 "0110 ELS response tag x%x completes "
2194 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
2195 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
2196 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
2197 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2200 if ((rspiocb->iocb.ulpStatus == 0)
2201 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
2202 lpfc_unreg_rpi(vport, ndlp);
2203 mbox->context2 = lpfc_nlp_get(ndlp);
2204 mbox->vport = vport;
2205 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
2206 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
2207 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
2210 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
2211 ndlp->nlp_prev_state = ndlp->nlp_state;
2212 lpfc_nlp_set_state(vport, ndlp,
2213 NLP_STE_REG_LOGIN_ISSUE);
2215 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
2216 != MBX_NOT_FINISHED) {
2220 /* ELS rsp: Cannot issue reg_login for <NPortid> */
2221 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2222 "0138 ELS rsp: Cannot issue reg_login for x%x "
2223 "Data: x%x x%x x%x\n",
2224 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2227 if (lpfc_nlp_not_used(ndlp))
2230 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
2231 if (!lpfc_error_lost_link(irsp) &&
2232 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
2233 if (lpfc_nlp_not_used(ndlp))
2237 mp = (struct lpfc_dmabuf *) mbox->context1;
2239 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2242 mempool_free(mbox, phba->mbox_mem_pool);
2246 spin_lock_irq(shost->host_lock);
2247 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
2248 spin_unlock_irq(shost->host_lock);
2250 /* If the node is not being used by another discovery thread,
2251 * and we are sending a reject, we are done with it.
2252 * Release driver reference count here and free associated
2256 lpfc_nlp_not_used(ndlp);
2259 lpfc_els_free_iocb(phba, cmdiocb);
2264 lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
2265 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
2268 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2269 struct lpfc_hba *phba = vport->phba;
2272 struct lpfc_iocbq *elsiocb;
2273 struct lpfc_sli_ring *pring;
2274 struct lpfc_sli *psli;
2278 ELS_PKT *els_pkt_ptr;
2281 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2282 oldcmd = &oldiocb->iocb;
2286 cmdsize = sizeof(uint32_t);
2287 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
2288 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
2290 spin_lock_irq(shost->host_lock);
2291 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
2292 spin_unlock_irq(shost->host_lock);
2296 icmd = &elsiocb->iocb;
2297 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2298 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2299 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
2300 pcmd += sizeof(uint32_t);
2302 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2303 "Issue ACC: did:x%x flg:x%x",
2304 ndlp->nlp_DID, ndlp->nlp_flag, 0);
2307 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
2308 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
2309 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
2313 icmd = &elsiocb->iocb;
2314 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2315 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2318 elsiocb->context_un.mbox = mbox;
2320 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
2321 pcmd += sizeof(uint32_t);
2322 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
2324 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2325 "Issue ACC PLOGI: did:x%x flg:x%x",
2326 ndlp->nlp_DID, ndlp->nlp_flag, 0);
2329 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
2330 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
2331 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
2335 icmd = &elsiocb->iocb;
2336 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2337 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2339 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
2340 sizeof(uint32_t) + sizeof(PRLO));
2341 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
2342 els_pkt_ptr = (ELS_PKT *) pcmd;
2343 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
2345 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2346 "Issue ACC PRLO: did:x%x flg:x%x",
2347 ndlp->nlp_DID, ndlp->nlp_flag, 0);
2352 /* Xmit ELS ACC response tag <ulpIoTag> */
2353 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2354 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
2355 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n",
2356 elsiocb->iotag, elsiocb->iocb.ulpContext,
2357 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2359 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
2360 spin_lock_irq(shost->host_lock);
2361 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
2362 spin_unlock_irq(shost->host_lock);
2363 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
2365 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
2368 phba->fc_stat.elsXmitACC++;
2369 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
2370 if (rc == IOCB_ERROR) {
2371 lpfc_els_free_iocb(phba, elsiocb);
2378 lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
2379 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
2382 struct lpfc_hba *phba = vport->phba;
2385 struct lpfc_iocbq *elsiocb;
2386 struct lpfc_sli_ring *pring;
2387 struct lpfc_sli *psli;
2393 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2395 cmdsize = 2 * sizeof(uint32_t);
2396 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
2397 ndlp->nlp_DID, ELS_CMD_LS_RJT);
2401 icmd = &elsiocb->iocb;
2402 oldcmd = &oldiocb->iocb;
2403 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2404 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2406 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
2407 pcmd += sizeof(uint32_t);
2408 *((uint32_t *) (pcmd)) = rejectError;
2411 elsiocb->context_un.mbox = mbox;
2413 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
2414 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2415 "0129 Xmit ELS RJT x%x response tag x%x "
2416 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
2418 rejectError, elsiocb->iotag,
2419 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
2420 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
2421 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2422 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
2423 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
2425 phba->fc_stat.elsXmitLSRJT++;
2426 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
2427 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
2429 if (rc == IOCB_ERROR) {
2430 lpfc_els_free_iocb(phba, elsiocb);
2437 lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
2438 struct lpfc_nodelist *ndlp)
2440 struct lpfc_hba *phba = vport->phba;
2441 struct lpfc_sli *psli = &phba->sli;
2442 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
2444 IOCB_t *icmd, *oldcmd;
2445 struct lpfc_iocbq *elsiocb;
2450 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
2451 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
2452 ndlp->nlp_DID, ELS_CMD_ACC);
2456 icmd = &elsiocb->iocb;
2457 oldcmd = &oldiocb->iocb;
2458 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2460 /* Xmit ADISC ACC response tag <ulpIoTag> */
2461 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2462 "0130 Xmit ADISC ACC response iotag x%x xri: "
2463 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
2464 elsiocb->iotag, elsiocb->iocb.ulpContext,
2465 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2467 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2469 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
2470 pcmd += sizeof(uint32_t);
2472 ap = (ADISC *) (pcmd);
2473 ap->hardAL_PA = phba->fc_pref_ALPA;
2474 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2475 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
2476 ap->DID = be32_to_cpu(vport->fc_myDID);
2478 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2479 "Issue ACC ADISC: did:x%x flg:x%x",
2480 ndlp->nlp_DID, ndlp->nlp_flag, 0);
2482 phba->fc_stat.elsXmitACC++;
2483 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
2484 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
2485 if (rc == IOCB_ERROR) {
2486 lpfc_els_free_iocb(phba, elsiocb);
2493 lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
2494 struct lpfc_nodelist *ndlp)
2496 struct lpfc_hba *phba = vport->phba;
2501 struct lpfc_iocbq *elsiocb;
2502 struct lpfc_sli_ring *pring;
2503 struct lpfc_sli *psli;
2509 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2511 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
2512 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
2513 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
2517 icmd = &elsiocb->iocb;
2518 oldcmd = &oldiocb->iocb;
2519 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2520 /* Xmit PRLI ACC response tag <ulpIoTag> */
2521 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2522 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
2523 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
2524 elsiocb->iotag, elsiocb->iocb.ulpContext,
2525 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2527 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2529 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
2530 pcmd += sizeof(uint32_t);
2532 /* For PRLI, remainder of payload is PRLI parameter page */
2533 memset(pcmd, 0, sizeof(PRLI));
2535 npr = (PRLI *) pcmd;
2538 * If our firmware version is 3.20 or later,
2539 * set the following bits for FC-TAPE support.
2541 if (vpd->rev.feaLevelHigh >= 0x02) {
2542 npr->ConfmComplAllowed = 1;
2544 npr->TaskRetryIdReq = 1;
2547 npr->acceptRspCode = PRLI_REQ_EXECUTED;
2548 npr->estabImagePair = 1;
2549 npr->readXferRdyDis = 1;
2550 npr->ConfmComplAllowed = 1;
2552 npr->prliType = PRLI_FCP_TYPE;
2553 npr->initiatorFunc = 1;
2555 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2556 "Issue ACC PRLI: did:x%x flg:x%x",
2557 ndlp->nlp_DID, ndlp->nlp_flag, 0);
2559 phba->fc_stat.elsXmitACC++;
2560 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
2562 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
2563 if (rc == IOCB_ERROR) {
2564 lpfc_els_free_iocb(phba, elsiocb);
2571 lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
2572 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
2574 struct lpfc_hba *phba = vport->phba;
2576 IOCB_t *icmd, *oldcmd;
2577 struct lpfc_iocbq *elsiocb;
2578 struct lpfc_sli_ring *pring;
2579 struct lpfc_sli *psli;
2585 pring = &psli->ring[LPFC_ELS_RING];
2587 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
2588 + (2 * sizeof(struct lpfc_name));
2590 cmdsize += sizeof(RNID_TOP_DISC);
2592 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
2593 ndlp->nlp_DID, ELS_CMD_ACC);
2597 icmd = &elsiocb->iocb;
2598 oldcmd = &oldiocb->iocb;
2599 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2600 /* Xmit RNID ACC response tag <ulpIoTag> */
2601 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2602 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
2603 elsiocb->iotag, elsiocb->iocb.ulpContext);
2604 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2605 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
2606 pcmd += sizeof(uint32_t);
2608 memset(pcmd, 0, sizeof(RNID));
2609 rn = (RNID *) (pcmd);
2610 rn->Format = format;
2611 rn->CommonLen = (2 * sizeof(struct lpfc_name));
2612 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2613 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
2616 rn->SpecificLen = 0;
2618 case RNID_TOPOLOGY_DISC:
2619 rn->SpecificLen = sizeof(RNID_TOP_DISC);
2620 memcpy(&rn->un.topologyDisc.portName,
2621 &vport->fc_portname, sizeof(struct lpfc_name));
2622 rn->un.topologyDisc.unitType = RNID_HBA;
2623 rn->un.topologyDisc.physPort = 0;
2624 rn->un.topologyDisc.attachedNodes = 0;
2628 rn->SpecificLen = 0;
2632 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2633 "Issue ACC RNID: did:x%x flg:x%x",
2634 ndlp->nlp_DID, ndlp->nlp_flag, 0);
2636 phba->fc_stat.elsXmitACC++;
2637 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
2639 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
2640 * it could be freed */
2642 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
2643 if (rc == IOCB_ERROR) {
2644 lpfc_els_free_iocb(phba, elsiocb);
2651 lpfc_els_disc_adisc(struct lpfc_vport *vport)
2653 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2654 struct lpfc_nodelist *ndlp, *next_ndlp;
2657 /* go thru NPR nodes and issue any remaining ELS ADISCs */
2658 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
2659 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
2660 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
2661 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
2662 spin_lock_irq(shost->host_lock);
2663 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2664 spin_unlock_irq(shost->host_lock);
2665 ndlp->nlp_prev_state = ndlp->nlp_state;
2666 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2667 lpfc_issue_els_adisc(vport, ndlp, 0);
2669 vport->num_disc_nodes++;
2670 if (vport->num_disc_nodes >=
2671 vport->cfg_discovery_threads) {
2672 spin_lock_irq(shost->host_lock);
2673 vport->fc_flag |= FC_NLP_MORE;
2674 spin_unlock_irq(shost->host_lock);
2679 if (sentadisc == 0) {
2680 spin_lock_irq(shost->host_lock);
2681 vport->fc_flag &= ~FC_NLP_MORE;
2682 spin_unlock_irq(shost->host_lock);
2688 lpfc_els_disc_plogi(struct lpfc_vport *vport)
2690 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2691 struct lpfc_nodelist *ndlp, *next_ndlp;
2694 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
2695 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
2696 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
2697 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
2698 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
2699 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
2700 ndlp->nlp_prev_state = ndlp->nlp_state;
2701 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2702 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
2704 vport->num_disc_nodes++;
2705 if (vport->num_disc_nodes >=
2706 vport->cfg_discovery_threads) {
2707 spin_lock_irq(shost->host_lock);
2708 vport->fc_flag |= FC_NLP_MORE;
2709 spin_unlock_irq(shost->host_lock);
2715 lpfc_set_disctmo(vport);
2718 spin_lock_irq(shost->host_lock);
2719 vport->fc_flag &= ~FC_NLP_MORE;
2720 spin_unlock_irq(shost->host_lock);
2726 lpfc_els_flush_rscn(struct lpfc_vport *vport)
2728 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2729 struct lpfc_hba *phba = vport->phba;
2732 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
2733 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
2734 vport->fc_rscn_id_list[i] = NULL;
2736 spin_lock_irq(shost->host_lock);
2737 vport->fc_rscn_id_cnt = 0;
2738 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
2739 spin_unlock_irq(shost->host_lock);
2740 lpfc_can_disctmo(vport);
2744 lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
2749 uint32_t payload_len, i;
2751 ns_did.un.word = did;
2753 /* Never match fabric nodes for RSCNs */
2754 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
2757 /* If we are doing a FULL RSCN rediscovery, match everything */
2758 if (vport->fc_flag & FC_RSCN_DISCOVERY)
2761 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
2762 lp = vport->fc_rscn_id_list[i]->virt;
2763 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
2764 payload_len -= sizeof(uint32_t); /* take off word 0 */
2765 while (payload_len) {
2766 rscn_did.un.word = be32_to_cpu(*lp++);
2767 payload_len -= sizeof(uint32_t);
2768 switch (rscn_did.un.b.resv) {
2769 case 0: /* Single N_Port ID effected */
2770 if (ns_did.un.word == rscn_did.un.word)
2773 case 1: /* Whole N_Port Area effected */
2774 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
2775 && (ns_did.un.b.area == rscn_did.un.b.area))
2778 case 2: /* Whole N_Port Domain effected */
2779 if (ns_did.un.b.domain == rscn_did.un.b.domain)
2783 /* Unknown Identifier in RSCN node */
2784 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
2785 "0217 Unknown Identifier in "
2786 "RSCN payload Data: x%x\n",
2788 case 3: /* Whole Fabric effected */
2797 lpfc_rscn_recovery_check(struct lpfc_vport *vport)
2799 struct lpfc_nodelist *ndlp = NULL;
2801 /* Look at all nodes effected by pending RSCNs and move
2802 * them to NPR state.
2805 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
2806 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE ||
2807 lpfc_rscn_payload_check(vport, ndlp->nlp_DID) == 0)
2810 lpfc_disc_state_machine(vport, ndlp, NULL,
2811 NLP_EVT_DEVICE_RECOVERY);
2814 * Make sure NLP_DELAY_TMO is NOT running after a device
2817 if (ndlp->nlp_flag & NLP_DELAY_TMO)
2818 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2825 lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
2826 struct lpfc_nodelist *ndlp)
2828 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2829 struct lpfc_hba *phba = vport->phba;
2830 struct lpfc_dmabuf *pcmd;
2831 uint32_t *lp, *datap;
2833 uint32_t payload_len, length, nportid, *cmd;
2834 int rscn_cnt = vport->fc_rscn_id_cnt;
2835 int rscn_id = 0, hba_id = 0;
2838 icmd = &cmdiocb->iocb;
2839 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2840 lp = (uint32_t *) pcmd->virt;
2842 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
2843 payload_len -= sizeof(uint32_t); /* take off word 0 */
2845 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2846 "0214 RSCN received Data: x%x x%x x%x x%x\n",
2847 vport->fc_flag, payload_len, *lp, rscn_cnt);
2848 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
2849 fc_host_post_event(shost, fc_get_event_number(),
2850 FCH_EVT_RSCN, lp[i]);
2852 /* If we are about to begin discovery, just ACC the RSCN.
2853 * Discovery processing will satisfy it.
2855 if (vport->port_state <= LPFC_NS_QRY) {
2856 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
2857 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
2858 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
2860 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
2864 /* If this RSCN just contains NPortIDs for other vports on this HBA,
2865 * just ACC and ignore it.
2867 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2868 !(vport->cfg_peer_port_login)) {
2873 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
2874 i -= sizeof(uint32_t);
2876 if (lpfc_find_vport_by_did(phba, nportid))
2879 if (rscn_id == hba_id) {
2880 /* ALL NPortIDs in RSCN are on HBA */
2881 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2883 "Data: x%x x%x x%x x%x\n",
2884 vport->fc_flag, payload_len,
2886 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
2887 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
2888 ndlp->nlp_DID, vport->port_state,
2891 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
2897 /* If we are already processing an RSCN, save the received
2898 * RSCN payload buffer, cmdiocb->context2 to process later.
2900 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
2901 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
2902 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
2903 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
2905 vport->fc_flag |= FC_RSCN_DEFERRED;
2906 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
2907 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
2908 spin_lock_irq(shost->host_lock);
2909 vport->fc_flag |= FC_RSCN_MODE;
2910 spin_unlock_irq(shost->host_lock);
2912 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
2913 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
2916 (payload_len + length <= LPFC_BPL_SIZE)) {
2917 *cmd &= ELS_CMD_MASK;
2918 *cmd |= be32_to_cpu(payload_len + length);
2919 memcpy(((uint8_t *)cmd) + length, lp,
2922 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
2923 vport->fc_rscn_id_cnt++;
2924 /* If we zero, cmdiocb->context2, the calling
2925 * routine will not try to free it.
2927 cmdiocb->context2 = NULL;
2931 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2932 "0235 Deferred RSCN "
2933 "Data: x%x x%x x%x\n",
2934 vport->fc_rscn_id_cnt, vport->fc_flag,
2937 spin_lock_irq(shost->host_lock);
2938 vport->fc_flag |= FC_RSCN_DISCOVERY;
2939 spin_unlock_irq(shost->host_lock);
2940 /* ReDiscovery RSCN */
2941 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2942 "0234 ReDiscovery RSCN "
2943 "Data: x%x x%x x%x\n",
2944 vport->fc_rscn_id_cnt, vport->fc_flag,
2948 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
2950 /* send RECOVERY event for ALL nodes that match RSCN payload */
2951 lpfc_rscn_recovery_check(vport);
2952 vport->fc_flag &= ~FC_RSCN_DEFERRED;
2956 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
2957 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
2958 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
2960 spin_lock_irq(shost->host_lock);
2961 vport->fc_flag |= FC_RSCN_MODE;
2962 spin_unlock_irq(shost->host_lock);
2963 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
2965 * If we zero, cmdiocb->context2, the calling routine will
2966 * not try to free it.
2968 cmdiocb->context2 = NULL;
2970 lpfc_set_disctmo(vport);
2973 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
2975 /* send RECOVERY event for ALL nodes that match RSCN payload */
2976 lpfc_rscn_recovery_check(vport);
2978 return lpfc_els_handle_rscn(vport);
2982 lpfc_els_handle_rscn(struct lpfc_vport *vport)
2984 struct lpfc_nodelist *ndlp;
2985 struct lpfc_hba *phba = vport->phba;
2987 /* Ignore RSCN if the port is being torn down. */
2988 if (vport->load_flag & FC_UNLOADING) {
2989 lpfc_els_flush_rscn(vport);
2993 /* Start timer for RSCN processing */
2994 lpfc_set_disctmo(vport);
2996 /* RSCN processed */
2997 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2998 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
2999 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
3002 /* To process RSCN, first compare RSCN data with NameServer */
3003 vport->fc_ns_retry = 0;
3004 ndlp = lpfc_findnode_did(vport, NameServer_DID);
3005 if (ndlp && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
3006 /* Good ndlp, issue CT Request to NameServer */
3007 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
3008 /* Wait for NameServer query cmpl before we can
3012 /* If login to NameServer does not exist, issue one */
3013 /* Good status, issue PLOGI to NameServer */
3014 ndlp = lpfc_findnode_did(vport, NameServer_DID);
3016 /* Wait for NameServer login cmpl before we can
3020 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
3022 lpfc_els_flush_rscn(vport);
3025 lpfc_nlp_init(vport, ndlp, NameServer_DID);
3026 ndlp->nlp_type |= NLP_FABRIC;
3027 ndlp->nlp_prev_state = ndlp->nlp_state;
3028 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
3029 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
3030 /* Wait for NameServer login cmpl before we can
3036 lpfc_els_flush_rscn(vport);
3041 lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3042 struct lpfc_nodelist *ndlp)
3044 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3045 struct lpfc_hba *phba = vport->phba;
3046 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3047 uint32_t *lp = (uint32_t *) pcmd->virt;
3048 IOCB_t *icmd = &cmdiocb->iocb;
3049 struct serv_parm *sp;
3056 sp = (struct serv_parm *) lp;
3058 /* FLOGI received */
3060 lpfc_set_disctmo(vport);
3062 if (phba->fc_topology == TOPOLOGY_LOOP) {
3063 /* We should never receive a FLOGI in loop mode, ignore it */
3064 did = icmd->un.elsreq64.remoteID;
3066 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
3068 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3069 "0113 An FLOGI ELS command x%x was "
3070 "received from DID x%x in Loop Mode\n",
3077 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3))) {
3078 /* For a FLOGI we accept, then if our portname is greater
3079 * then the remote portname we initiate Nport login.
3082 rc = memcmp(&vport->fc_portname, &sp->portName,
3083 sizeof(struct lpfc_name));
3086 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3090 lpfc_linkdown(phba);
3091 lpfc_init_link(phba, mbox,
3093 phba->cfg_link_speed);
3094 mbox->mb.un.varInitLnk.lipsr_AL_PA = 0;
3095 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
3096 mbox->vport = vport;
3097 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
3098 lpfc_set_loopback_flag(phba);
3099 if (rc == MBX_NOT_FINISHED) {
3100 mempool_free(mbox, phba->mbox_mem_pool);
3103 } else if (rc > 0) { /* greater than */
3104 spin_lock_irq(shost->host_lock);
3105 vport->fc_flag |= FC_PT2PT_PLOGI;
3106 spin_unlock_irq(shost->host_lock);
3108 spin_lock_irq(shost->host_lock);
3109 vport->fc_flag |= FC_PT2PT;
3110 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
3111 spin_unlock_irq(shost->host_lock);
3113 /* Reject this request because invalid parameters */
3114 stat.un.b.lsRjtRsvd0 = 0;
3115 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3116 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
3117 stat.un.b.vendorUnique = 0;
3118 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
3124 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
3130 lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3131 struct lpfc_nodelist *ndlp)
3133 struct lpfc_dmabuf *pcmd;
3140 icmd = &cmdiocb->iocb;
3141 did = icmd->un.elsreq64.remoteID;
3142 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3143 lp = (uint32_t *) pcmd->virt;
3150 switch (rn->Format) {
3152 case RNID_TOPOLOGY_DISC:
3154 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
3157 /* Reject this request because format not supported */
3158 stat.un.b.lsRjtRsvd0 = 0;
3159 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3160 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
3161 stat.un.b.vendorUnique = 0;
3162 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
3169 lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3170 struct lpfc_nodelist *ndlp)
3174 /* For now, unconditionally reject this command */
3175 stat.un.b.lsRjtRsvd0 = 0;
3176 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3177 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
3178 stat.un.b.vendorUnique = 0;
3179 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
3184 lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3186 struct lpfc_sli *psli = &phba->sli;
3187 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
3192 struct lpfc_iocbq *elsiocb;
3193 struct lpfc_nodelist *ndlp;
3194 uint16_t xri, status;
3199 ndlp = (struct lpfc_nodelist *) pmb->context2;
3200 xri = (uint16_t) ((unsigned long)(pmb->context1));
3201 pmb->context1 = NULL;
3202 pmb->context2 = NULL;
3204 if (mb->mbxStatus) {
3205 mempool_free(pmb, phba->mbox_mem_pool);
3209 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
3210 mempool_free(pmb, phba->mbox_mem_pool);
3211 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
3212 lpfc_max_els_tries, ndlp,
3213 ndlp->nlp_DID, ELS_CMD_ACC);
3218 icmd = &elsiocb->iocb;
3219 icmd->ulpContext = xri;
3221 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3222 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
3223 pcmd += sizeof(uint32_t); /* Skip past command */
3224 rps_rsp = (RPS_RSP *)pcmd;
3226 if (phba->fc_topology != TOPOLOGY_LOOP)
3230 if (phba->pport->fc_flag & FC_FABRIC)
3234 rps_rsp->portStatus = be16_to_cpu(status);
3235 rps_rsp->linkFailureCnt = be32_to_cpu(mb->un.varRdLnk.linkFailureCnt);
3236 rps_rsp->lossSyncCnt = be32_to_cpu(mb->un.varRdLnk.lossSyncCnt);
3237 rps_rsp->lossSignalCnt = be32_to_cpu(mb->un.varRdLnk.lossSignalCnt);
3238 rps_rsp->primSeqErrCnt = be32_to_cpu(mb->un.varRdLnk.primSeqErrCnt);
3239 rps_rsp->invalidXmitWord = be32_to_cpu(mb->un.varRdLnk.invalidXmitWord);
3240 rps_rsp->crcCnt = be32_to_cpu(mb->un.varRdLnk.crcCnt);
3241 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
3242 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
3243 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
3244 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
3245 elsiocb->iotag, elsiocb->iocb.ulpContext,
3246 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3248 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
3249 phba->fc_stat.elsXmitACC++;
3250 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR)
3251 lpfc_els_free_iocb(phba, elsiocb);
3256 lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3257 struct lpfc_nodelist *ndlp)
3259 struct lpfc_hba *phba = vport->phba;
3263 struct lpfc_dmabuf *pcmd;
3267 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
3268 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
3269 stat.un.b.lsRjtRsvd0 = 0;
3270 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3271 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
3272 stat.un.b.vendorUnique = 0;
3273 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
3277 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3278 lp = (uint32_t *) pcmd->virt;
3279 flag = (be32_to_cpu(*lp++) & 0xf);
3283 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
3284 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
3285 sizeof(struct lpfc_name)) == 0))) {
3287 printk("Fix me....\n");
3289 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
3291 lpfc_read_lnk_stat(phba, mbox);
3293 (void *)((unsigned long) cmdiocb->iocb.ulpContext);
3294 mbox->context2 = lpfc_nlp_get(ndlp);
3295 mbox->vport = vport;
3296 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
3297 if (lpfc_sli_issue_mbox (phba, mbox, MBX_NOWAIT)
3298 != MBX_NOT_FINISHED)
3299 /* Mbox completion will send ELS Response */
3303 mempool_free(mbox, phba->mbox_mem_pool);
3306 stat.un.b.lsRjtRsvd0 = 0;
3307 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3308 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
3309 stat.un.b.vendorUnique = 0;
3310 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
3315 lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
3316 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
3318 struct lpfc_hba *phba = vport->phba;
3319 IOCB_t *icmd, *oldcmd;
3321 struct lpfc_iocbq *elsiocb;
3322 struct lpfc_sli *psli = &phba->sli;
3323 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
3326 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3327 ndlp->nlp_DID, ELS_CMD_ACC);
3332 icmd = &elsiocb->iocb;
3333 oldcmd = &oldiocb->iocb;
3334 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3336 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3337 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
3338 pcmd += sizeof(uint16_t);
3339 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
3340 pcmd += sizeof(uint16_t);
3342 /* Setup the RPL ACC payload */
3343 rpl_rsp.listLen = be32_to_cpu(1);
3345 rpl_rsp.port_num_blk.portNum = 0;
3346 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
3347 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
3348 sizeof(struct lpfc_name));
3349 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
3350 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
3351 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3352 "0120 Xmit ELS RPL ACC response tag x%x "
3353 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
3355 elsiocb->iotag, elsiocb->iocb.ulpContext,
3356 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3358 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
3359 phba->fc_stat.elsXmitACC++;
3360 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
3361 lpfc_els_free_iocb(phba, elsiocb);
3368 lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3369 struct lpfc_nodelist *ndlp)
3371 struct lpfc_dmabuf *pcmd;
3378 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
3379 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
3380 stat.un.b.lsRjtRsvd0 = 0;
3381 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3382 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
3383 stat.un.b.vendorUnique = 0;
3384 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
3388 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3389 lp = (uint32_t *) pcmd->virt;
3390 rpl = (RPL *) (lp + 1);
3392 maxsize = be32_to_cpu(rpl->maxsize);
3394 /* We support only one port */
3395 if ((rpl->index == 0) &&
3397 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
3398 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
3400 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
3402 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
3408 lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3409 struct lpfc_nodelist *ndlp)
3411 struct lpfc_dmabuf *pcmd;
3415 uint32_t cmd, cnt, did;
3417 icmd = &cmdiocb->iocb;
3418 did = icmd->un.elsreq64.remoteID;
3419 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3420 lp = (uint32_t *) pcmd->virt;
3424 /* FARP-REQ received from DID <did> */
3425 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3426 "0601 FARP-REQ received from DID x%x\n", did);
3427 /* We will only support match on WWPN or WWNN */
3428 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
3433 /* If this FARP command is searching for my portname */
3434 if (fp->Mflags & FARP_MATCH_PORT) {
3435 if (memcmp(&fp->RportName, &vport->fc_portname,
3436 sizeof(struct lpfc_name)) == 0)
3440 /* If this FARP command is searching for my nodename */
3441 if (fp->Mflags & FARP_MATCH_NODE) {
3442 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
3443 sizeof(struct lpfc_name)) == 0)
3448 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
3449 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
3450 /* Log back into the node before sending the FARP. */
3451 if (fp->Rflags & FARP_REQUEST_PLOGI) {
3452 ndlp->nlp_prev_state = ndlp->nlp_state;
3453 lpfc_nlp_set_state(vport, ndlp,
3454 NLP_STE_PLOGI_ISSUE);
3455 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
3458 /* Send a FARP response to that node */
3459 if (fp->Rflags & FARP_REQUEST_FARPR)
3460 lpfc_issue_els_farpr(vport, did, 0);
3467 lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3468 struct lpfc_nodelist *ndlp)
3470 struct lpfc_dmabuf *pcmd;
3475 icmd = &cmdiocb->iocb;
3476 did = icmd->un.elsreq64.remoteID;
3477 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3478 lp = (uint32_t *) pcmd->virt;
3481 /* FARP-RSP received from DID <did> */
3482 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3483 "0600 FARP-RSP received from DID x%x\n", did);
3484 /* ACCEPT the Farp resp request */
3485 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
3491 lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3492 struct lpfc_nodelist *fan_ndlp)
3494 struct lpfc_dmabuf *pcmd;
3499 struct lpfc_nodelist *ndlp, *next_ndlp;
3500 struct lpfc_hba *phba = vport->phba;
3503 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3504 "0265 FAN received\n");
3505 icmd = &cmdiocb->iocb;
3506 did = icmd->un.elsreq64.remoteID;
3507 pcmd = (struct lpfc_dmabuf *)cmdiocb->context2;
3508 lp = (uint32_t *)pcmd->virt;
3513 /* FAN received; Fan does not have a reply sequence */
3515 if (phba->pport->port_state == LPFC_LOCAL_CFG_LINK) {
3516 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
3517 sizeof(struct lpfc_name)) != 0) ||
3518 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
3519 sizeof(struct lpfc_name)) != 0)) {
3521 * This node has switched fabrics. FLOGI is required
3522 * Clean up the old rpi's
3525 list_for_each_entry_safe(ndlp, next_ndlp,
3526 &vport->fc_nodes, nlp_listp) {
3527 if (ndlp->nlp_state != NLP_STE_NPR_NODE)
3529 if (ndlp->nlp_type & NLP_FABRIC) {
3531 * Clean up old Fabric, Nameserver and
3532 * other NLP_FABRIC logins
3534 lpfc_drop_node(vport, ndlp);
3536 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
3537 /* Fail outstanding I/O now since this
3538 * device is marked for PLOGI
3540 lpfc_unreg_rpi(vport, ndlp);
3544 lpfc_initial_flogi(vport);
3547 /* Discovery not needed,
3548 * move the nodes to their original state.
3550 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
3552 if (ndlp->nlp_state != NLP_STE_NPR_NODE)
3555 switch (ndlp->nlp_prev_state) {
3556 case NLP_STE_UNMAPPED_NODE:
3557 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
3558 lpfc_nlp_set_state(vport, ndlp,
3559 NLP_STE_UNMAPPED_NODE);
3562 case NLP_STE_MAPPED_NODE:
3563 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
3564 lpfc_nlp_set_state(vport, ndlp,
3565 NLP_STE_MAPPED_NODE);
3573 /* Start discovery - this should just do CLEAR_LA */
3574 lpfc_disc_start(vport);
3580 lpfc_els_timeout(unsigned long ptr)
3582 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
3583 struct lpfc_hba *phba = vport->phba;
3584 unsigned long iflag;
3586 spin_lock_irqsave(&vport->work_port_lock, iflag);
3587 if ((vport->work_port_events & WORKER_ELS_TMO) == 0) {
3588 vport->work_port_events |= WORKER_ELS_TMO;
3589 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
3591 spin_lock_irqsave(&phba->hbalock, iflag);
3592 if (phba->work_wait)
3593 lpfc_worker_wake_up(phba);
3594 spin_unlock_irqrestore(&phba->hbalock, iflag);
3597 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
3602 lpfc_els_timeout_handler(struct lpfc_vport *vport)
3604 struct lpfc_hba *phba = vport->phba;
3605 struct lpfc_sli_ring *pring;
3606 struct lpfc_iocbq *tmp_iocb, *piocb;
3608 struct lpfc_dmabuf *pcmd;
3609 uint32_t els_command = 0;
3611 uint32_t remote_ID = 0xffffffff;
3613 /* If the timer is already canceled do nothing */
3614 if ((vport->work_port_events & WORKER_ELS_TMO) == 0) {
3617 spin_lock_irq(&phba->hbalock);
3618 timeout = (uint32_t)(phba->fc_ratov << 1);
3620 pring = &phba->sli.ring[LPFC_ELS_RING];
3622 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
3625 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
3626 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
3627 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
3630 if (piocb->vport != vport)
3633 pcmd = (struct lpfc_dmabuf *) piocb->context2;
3635 els_command = *(uint32_t *) (pcmd->virt);
3637 if (els_command == ELS_CMD_FARP ||
3638 els_command == ELS_CMD_FARPR ||
3639 els_command == ELS_CMD_FDISC)
3642 if (vport != piocb->vport)
3645 if (piocb->drvrTimeout > 0) {
3646 if (piocb->drvrTimeout >= timeout)
3647 piocb->drvrTimeout -= timeout;
3649 piocb->drvrTimeout = 0;
3653 remote_ID = 0xffffffff;
3654 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
3655 remote_ID = cmd->un.elsreq64.remoteID;
3657 struct lpfc_nodelist *ndlp;
3658 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
3660 remote_ID = ndlp->nlp_DID;
3662 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3663 "0127 ELS timeout Data: x%x x%x x%x "
3664 "x%x\n", els_command,
3665 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
3666 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
3668 spin_unlock_irq(&phba->hbalock);
3670 if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt)
3671 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
3675 lpfc_els_flush_cmd(struct lpfc_vport *vport)
3677 LIST_HEAD(completions);
3678 struct lpfc_hba *phba = vport->phba;
3679 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
3680 struct lpfc_iocbq *tmp_iocb, *piocb;
3683 lpfc_fabric_abort_vport(vport);
3685 spin_lock_irq(&phba->hbalock);
3686 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
3689 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
3693 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
3694 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
3695 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
3696 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
3697 cmd->ulpCommand == CMD_ABORT_XRI_CN)
3700 if (piocb->vport != vport)
3703 list_move_tail(&piocb->list, &completions);
3707 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
3708 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
3712 if (piocb->vport != vport)
3715 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
3717 spin_unlock_irq(&phba->hbalock);
3719 while (!list_empty(&completions)) {
3720 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
3722 list_del_init(&piocb->list);
3724 if (!piocb->iocb_cmpl)
3725 lpfc_sli_release_iocbq(phba, piocb);
3727 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
3728 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
3729 (piocb->iocb_cmpl) (phba, piocb, piocb);
3737 lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
3739 LIST_HEAD(completions);
3740 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
3741 struct lpfc_iocbq *tmp_iocb, *piocb;
3744 lpfc_fabric_abort_hba(phba);
3745 spin_lock_irq(&phba->hbalock);
3746 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
3748 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
3750 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
3751 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
3752 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
3753 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
3754 cmd->ulpCommand == CMD_ABORT_XRI_CN)
3756 list_move_tail(&piocb->list, &completions);
3759 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
3760 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
3762 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
3764 spin_unlock_irq(&phba->hbalock);
3765 while (!list_empty(&completions)) {
3766 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
3768 list_del_init(&piocb->list);
3769 if (!piocb->iocb_cmpl)
3770 lpfc_sli_release_iocbq(phba, piocb);
3772 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
3773 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
3774 (piocb->iocb_cmpl) (phba, piocb, piocb);
3781 lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3782 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
3784 struct Scsi_Host *shost;
3785 struct lpfc_nodelist *ndlp;
3788 uint32_t cmd, did, newnode, rjt_err = 0;
3789 IOCB_t *icmd = &elsiocb->iocb;
3791 if (vport == NULL || elsiocb->context2 == NULL)
3795 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
3797 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
3798 lpfc_post_buffer(phba, pring, 1, 1);
3800 did = icmd->un.rcvels.remoteID;
3801 if (icmd->ulpStatus) {
3802 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3803 "RCV Unsol ELS: status:x%x/x%x did:x%x",
3804 icmd->ulpStatus, icmd->un.ulpWord[4], did);
3808 /* Check to see if link went down during discovery */
3809 if (lpfc_els_chk_latt(vport))
3812 /* Ignore traffic recevied during vport shutdown. */
3813 if (vport->load_flag & FC_UNLOADING)
3816 ndlp = lpfc_findnode_did(vport, did);
3818 /* Cannot find existing Fabric ndlp, so allocate a new one */
3819 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
3823 lpfc_nlp_init(vport, ndlp, did);
3824 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
3826 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) {
3827 ndlp->nlp_type |= NLP_FABRIC;
3831 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
3832 /* This is simular to the new node path */
3834 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
3839 phba->fc_stat.elsRcvFrame++;
3840 if (elsiocb->context1)
3841 lpfc_nlp_put(elsiocb->context1);
3842 elsiocb->context1 = lpfc_nlp_get(ndlp);
3843 elsiocb->vport = vport;
3845 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
3846 cmd &= ELS_CMD_MASK;
3848 /* ELS command <elsCmd> received from NPORT <did> */
3849 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3850 "0112 ELS command x%x received from NPORT x%x "
3851 "Data: x%x\n", cmd, did, vport->port_state);
3854 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3855 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
3856 did, vport->port_state, ndlp->nlp_flag);
3858 phba->fc_stat.elsRcvPLOGI++;
3859 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
3861 if (vport->port_state < LPFC_DISC_AUTH) {
3862 rjt_err = LSRJT_UNABLE_TPC;
3866 shost = lpfc_shost_from_vport(vport);
3867 spin_lock_irq(shost->host_lock);
3868 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
3869 spin_unlock_irq(shost->host_lock);
3871 lpfc_disc_state_machine(vport, ndlp, elsiocb,
3876 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3877 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
3878 did, vport->port_state, ndlp->nlp_flag);
3880 phba->fc_stat.elsRcvFLOGI++;
3881 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
3886 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3887 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
3888 did, vport->port_state, ndlp->nlp_flag);
3890 phba->fc_stat.elsRcvLOGO++;
3891 if (vport->port_state < LPFC_DISC_AUTH) {
3892 rjt_err = LSRJT_UNABLE_TPC;
3895 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
3898 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3899 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
3900 did, vport->port_state, ndlp->nlp_flag);
3902 phba->fc_stat.elsRcvPRLO++;
3903 if (vport->port_state < LPFC_DISC_AUTH) {
3904 rjt_err = LSRJT_UNABLE_TPC;
3907 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
3910 phba->fc_stat.elsRcvRSCN++;
3911 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
3916 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3917 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
3918 did, vport->port_state, ndlp->nlp_flag);
3920 phba->fc_stat.elsRcvADISC++;
3921 if (vport->port_state < LPFC_DISC_AUTH) {
3922 rjt_err = LSRJT_UNABLE_TPC;
3925 lpfc_disc_state_machine(vport, ndlp, elsiocb,
3929 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3930 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
3931 did, vport->port_state, ndlp->nlp_flag);
3933 phba->fc_stat.elsRcvPDISC++;
3934 if (vport->port_state < LPFC_DISC_AUTH) {
3935 rjt_err = LSRJT_UNABLE_TPC;
3938 lpfc_disc_state_machine(vport, ndlp, elsiocb,
3942 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3943 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
3944 did, vport->port_state, ndlp->nlp_flag);
3946 phba->fc_stat.elsRcvFARPR++;
3947 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
3950 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3951 "RCV FARP: did:x%x/ste:x%x flg:x%x",
3952 did, vport->port_state, ndlp->nlp_flag);
3954 phba->fc_stat.elsRcvFARP++;
3955 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
3958 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3959 "RCV FAN: did:x%x/ste:x%x flg:x%x",
3960 did, vport->port_state, ndlp->nlp_flag);
3962 phba->fc_stat.elsRcvFAN++;
3963 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
3966 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3967 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
3968 did, vport->port_state, ndlp->nlp_flag);
3970 phba->fc_stat.elsRcvPRLI++;
3971 if (vport->port_state < LPFC_DISC_AUTH) {
3972 rjt_err = LSRJT_UNABLE_TPC;
3975 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
3978 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3979 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
3980 did, vport->port_state, ndlp->nlp_flag);
3982 phba->fc_stat.elsRcvLIRR++;
3983 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
3988 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3989 "RCV RPS: did:x%x/ste:x%x flg:x%x",
3990 did, vport->port_state, ndlp->nlp_flag);
3992 phba->fc_stat.elsRcvRPS++;
3993 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
3998 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3999 "RCV RPL: did:x%x/ste:x%x flg:x%x",
4000 did, vport->port_state, ndlp->nlp_flag);
4002 phba->fc_stat.elsRcvRPL++;
4003 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
4008 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4009 "RCV RNID: did:x%x/ste:x%x flg:x%x",
4010 did, vport->port_state, ndlp->nlp_flag);
4012 phba->fc_stat.elsRcvRNID++;
4013 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
4018 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4019 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
4020 cmd, did, vport->port_state);
4022 /* Unsupported ELS command, reject */
4023 rjt_err = LSRJT_INVALID_CMD;
4025 /* Unknown ELS command <elsCmd> received from NPORT <did> */
4026 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4027 "0115 Unknown ELS command x%x "
4028 "received from NPORT x%x\n", cmd, did);
4034 /* check if need to LS_RJT received ELS cmd */
4036 memset(&stat, 0, sizeof(stat));
4037 stat.un.b.lsRjtRsnCode = rjt_err;
4038 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
4039 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
4046 if (vport && !(vport->load_flag & FC_UNLOADING))
4047 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
4048 "(%d):0111 Dropping received ELS cmd "
4049 "Data: x%x x%x x%x\n",
4050 vport->vpi, icmd->ulpStatus,
4051 icmd->un.ulpWord[4], icmd->ulpTimeout);
4052 phba->fc_stat.elsRcvDrop++;
4055 static struct lpfc_vport *
4056 lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
4058 struct lpfc_vport *vport;
4059 unsigned long flags;
4061 spin_lock_irqsave(&phba->hbalock, flags);
4062 list_for_each_entry(vport, &phba->port_list, listentry) {
4063 if (vport->vpi == vpi) {
4064 spin_unlock_irqrestore(&phba->hbalock, flags);
4068 spin_unlock_irqrestore(&phba->hbalock, flags);
4073 lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
4074 struct lpfc_iocbq *elsiocb)
4076 struct lpfc_vport *vport = phba->pport;
4077 IOCB_t *icmd = &elsiocb->iocb;
4079 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
4080 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
4082 elsiocb->context2 = NULL;
4083 elsiocb->context3 = NULL;
4085 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
4086 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
4087 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
4088 (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) {
4089 phba->fc_stat.NoRcvBuf++;
4090 /* Not enough posted buffers; Try posting more buffers */
4091 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
4092 lpfc_post_buffer(phba, pring, 0, 1);
4096 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
4097 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
4098 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
4099 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
4100 vport = phba->pport;
4102 uint16_t vpi = icmd->unsli3.rcvsli3.vpi;
4103 vport = lpfc_find_vport_by_vpid(phba, vpi);
4106 /* If there are no BDEs associated
4107 * with this IOCB, there is nothing to do.
4109 if (icmd->ulpBdeCount == 0)
4112 /* type of ELS cmd is first 32bit word
4115 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
4116 elsiocb->context2 = bdeBuf1;
4118 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
4119 icmd->un.cont64[0].addrLow);
4120 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
4124 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
4126 * The different unsolicited event handlers would tell us
4127 * if they are done with "mp" by setting context2 to NULL.
4129 lpfc_nlp_put(elsiocb->context1);
4130 elsiocb->context1 = NULL;
4131 if (elsiocb->context2) {
4132 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
4133 elsiocb->context2 = NULL;
4136 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
4137 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
4138 icmd->ulpBdeCount == 2) {
4139 elsiocb->context2 = bdeBuf2;
4140 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
4141 /* free mp if we are done with it */
4142 if (elsiocb->context2) {
4143 lpfc_in_buf_free(phba, elsiocb->context2);
4144 elsiocb->context2 = NULL;
4150 lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
4152 struct lpfc_nodelist *ndlp, *ndlp_fdmi;
4154 ndlp = lpfc_findnode_did(vport, NameServer_DID);
4156 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
4158 if (phba->fc_topology == TOPOLOGY_LOOP) {
4159 lpfc_disc_start(vport);
4162 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4163 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4164 "0251 NameServer login: no memory\n");
4167 lpfc_nlp_init(vport, ndlp, NameServer_DID);
4168 ndlp->nlp_type |= NLP_FABRIC;
4171 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
4173 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
4174 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4175 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4176 "0252 Cannot issue NameServer login\n");
4180 if (vport->cfg_fdmi_on) {
4181 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
4184 lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
4185 ndlp_fdmi->nlp_type |= NLP_FABRIC;
4186 ndlp_fdmi->nlp_state =
4187 NLP_STE_PLOGI_ISSUE;
4188 lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID,
4196 lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4198 struct lpfc_vport *vport = pmb->vport;
4199 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4200 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
4201 MAILBOX_t *mb = &pmb->mb;
4203 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
4206 if (mb->mbxStatus) {
4207 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
4208 "0915 Register VPI failed: 0x%x\n",
4211 switch (mb->mbxStatus) {
4212 case 0x11: /* unsupported feature */
4213 case 0x9603: /* max_vpi exceeded */
4214 /* giving up on vport registration */
4215 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4216 spin_lock_irq(shost->host_lock);
4217 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
4218 spin_unlock_irq(shost->host_lock);
4219 lpfc_can_disctmo(vport);
4222 /* Try to recover from this error */
4223 lpfc_mbx_unreg_vpi(vport);
4224 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
4225 lpfc_initial_fdisc(vport);
4230 if (vport == phba->pport)
4231 lpfc_issue_fabric_reglogin(vport);
4233 lpfc_do_scr_ns_plogi(phba, vport);
4235 mempool_free(pmb, phba->mbox_mem_pool);
4240 lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
4241 struct lpfc_nodelist *ndlp)
4245 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4247 lpfc_reg_vpi(phba, vport->vpi, vport->fc_myDID, mbox);
4248 mbox->vport = vport;
4249 mbox->context2 = lpfc_nlp_get(ndlp);
4250 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
4251 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
4252 == MBX_NOT_FINISHED) {
4253 mempool_free(mbox, phba->mbox_mem_pool);
4254 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
4256 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4257 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
4258 "0253 Register VPI: Can't send mbox\n");
4261 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4263 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
4264 "0254 Register VPI: no memory\n");
4266 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
4272 lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4273 struct lpfc_iocbq *rspiocb)
4275 struct lpfc_vport *vport = cmdiocb->vport;
4276 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4277 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
4278 struct lpfc_nodelist *np;
4279 struct lpfc_nodelist *next_np;
4280 IOCB_t *irsp = &rspiocb->iocb;
4281 struct lpfc_iocbq *piocb;
4283 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4284 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
4285 irsp->ulpStatus, irsp->un.ulpWord[4],
4287 /* Since all FDISCs are being single threaded, we
4288 * must reset the discovery timer for ALL vports
4289 * waiting to send FDISC when one completes.
4291 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
4292 lpfc_set_disctmo(piocb->vport);
4295 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4296 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
4297 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
4299 if (irsp->ulpStatus) {
4300 /* Check for retry */
4301 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
4304 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4305 "0124 FDISC failed. (%d/%d)\n",
4306 irsp->ulpStatus, irsp->un.ulpWord[4]);
4307 if (vport->fc_vport->vport_state == FC_VPORT_INITIALIZING)
4308 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4311 /* giving up on FDISC. Cancel discovery timer */
4312 lpfc_can_disctmo(vport);
4314 spin_lock_irq(shost->host_lock);
4315 vport->fc_flag |= FC_FABRIC;
4316 if (vport->phba->fc_topology == TOPOLOGY_LOOP)
4317 vport->fc_flag |= FC_PUBLIC_LOOP;
4318 spin_unlock_irq(shost->host_lock);
4320 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
4321 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
4322 if ((vport->fc_prevDID != vport->fc_myDID) &&
4323 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
4324 /* If our NportID changed, we need to ensure all
4325 * remaining NPORTs get unreg_login'ed so we can
4328 list_for_each_entry_safe(np, next_np,
4329 &vport->fc_nodes, nlp_listp) {
4330 if (np->nlp_state != NLP_STE_NPR_NODE
4331 || !(np->nlp_flag & NLP_NPR_ADISC))
4333 spin_lock_irq(shost->host_lock);
4334 np->nlp_flag &= ~NLP_NPR_ADISC;
4335 spin_unlock_irq(shost->host_lock);
4336 lpfc_unreg_rpi(vport, np);
4338 lpfc_mbx_unreg_vpi(vport);
4339 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
4342 if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
4343 lpfc_register_new_vport(phba, vport, ndlp);
4345 lpfc_do_scr_ns_plogi(phba, vport);
4347 lpfc_nlp_put(ndlp); /* Free Fabric ndlp for vports */
4351 lpfc_els_free_iocb(phba, cmdiocb);
4355 lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4358 struct lpfc_hba *phba = vport->phba;
4360 struct lpfc_iocbq *elsiocb;
4361 struct serv_parm *sp;
4364 int did = ndlp->nlp_DID;
4367 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
4368 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
4371 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4372 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4373 "0255 Issue FDISC: no IOCB\n");
4377 icmd = &elsiocb->iocb;
4378 icmd->un.elsreq64.myID = 0;
4379 icmd->un.elsreq64.fl = 1;
4381 /* For FDISC, Let FDISC rsp set the NPortID for this VPI */
4385 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4386 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
4387 pcmd += sizeof(uint32_t); /* CSP Word 1 */
4388 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
4389 sp = (struct serv_parm *) pcmd;
4390 /* Setup CSPs accordingly for Fabric */
4391 sp->cmn.e_d_tov = 0;
4392 sp->cmn.w2.r_a_tov = 0;
4393 sp->cls1.classValid = 0;
4394 sp->cls2.seqDelivery = 1;
4395 sp->cls3.seqDelivery = 1;
4397 pcmd += sizeof(uint32_t); /* CSP Word 2 */
4398 pcmd += sizeof(uint32_t); /* CSP Word 3 */
4399 pcmd += sizeof(uint32_t); /* CSP Word 4 */
4400 pcmd += sizeof(uint32_t); /* Port Name */
4401 memcpy(pcmd, &vport->fc_portname, 8);
4402 pcmd += sizeof(uint32_t); /* Node Name */
4403 pcmd += sizeof(uint32_t); /* Node Name */
4404 memcpy(pcmd, &vport->fc_nodename, 8);
4406 lpfc_set_disctmo(vport);
4408 phba->fc_stat.elsXmitFDISC++;
4409 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
4411 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4412 "Issue FDISC: did:x%x",
4415 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
4416 if (rc == IOCB_ERROR) {
4417 lpfc_els_free_iocb(phba, elsiocb);
4418 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4419 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4420 "0256 Issue FDISC: Cannot send IOCB\n");
4423 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
4424 vport->port_state = LPFC_FDISC;
4429 lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4430 struct lpfc_iocbq *rspiocb)
4432 struct lpfc_vport *vport = cmdiocb->vport;
4435 irsp = &rspiocb->iocb;
4436 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4437 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
4438 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
4440 lpfc_els_free_iocb(phba, cmdiocb);
4441 vport->unreg_vpi_cmpl = VPORT_ERROR;
4445 lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4447 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4448 struct lpfc_hba *phba = vport->phba;
4449 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
4451 struct lpfc_iocbq *elsiocb;
4455 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
4456 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
4461 icmd = &elsiocb->iocb;
4462 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4463 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
4464 pcmd += sizeof(uint32_t);
4466 /* Fill in LOGO payload */
4467 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
4468 pcmd += sizeof(uint32_t);
4469 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
4471 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4472 "Issue LOGO npiv did:x%x flg:x%x",
4473 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4475 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
4476 spin_lock_irq(shost->host_lock);
4477 ndlp->nlp_flag |= NLP_LOGO_SND;
4478 spin_unlock_irq(shost->host_lock);
4479 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
4480 spin_lock_irq(shost->host_lock);
4481 ndlp->nlp_flag &= ~NLP_LOGO_SND;
4482 spin_unlock_irq(shost->host_lock);
4483 lpfc_els_free_iocb(phba, elsiocb);
4490 lpfc_fabric_block_timeout(unsigned long ptr)
4492 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
4493 unsigned long iflags;
4494 uint32_t tmo_posted;
4495 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
4496 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
4498 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
4499 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
4502 spin_lock_irqsave(&phba->hbalock, iflags);
4503 if (phba->work_wait)
4504 lpfc_worker_wake_up(phba);
4505 spin_unlock_irqrestore(&phba->hbalock, iflags);
4510 lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
4512 struct lpfc_iocbq *iocb;
4513 unsigned long iflags;
4515 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
4520 spin_lock_irqsave(&phba->hbalock, iflags);
4521 /* Post any pending iocb to the SLI layer */
4522 if (atomic_read(&phba->fabric_iocb_count) == 0) {
4523 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
4526 atomic_inc(&phba->fabric_iocb_count);
4528 spin_unlock_irqrestore(&phba->hbalock, iflags);
4530 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
4531 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
4532 iocb->iocb_flag |= LPFC_IO_FABRIC;
4534 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
4535 "Fabric sched1: ste:x%x",
4536 iocb->vport->port_state, 0, 0);
4538 ret = lpfc_sli_issue_iocb(phba, pring, iocb, 0);
4540 if (ret == IOCB_ERROR) {
4541 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
4542 iocb->fabric_iocb_cmpl = NULL;
4543 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
4545 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
4546 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
4547 iocb->iocb_cmpl(phba, iocb, iocb);
4549 atomic_dec(&phba->fabric_iocb_count);
4558 lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
4560 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
4562 lpfc_resume_fabric_iocbs(phba);
4567 lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
4571 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
4572 /* Start a timer to unblock fabric
4576 mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 );
4582 lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4583 struct lpfc_iocbq *rspiocb)
4587 if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
4590 switch (rspiocb->iocb.ulpStatus) {
4591 case IOSTAT_NPORT_RJT:
4592 case IOSTAT_FABRIC_RJT:
4593 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
4594 lpfc_block_fabric_iocbs(phba);
4598 case IOSTAT_NPORT_BSY:
4599 case IOSTAT_FABRIC_BSY:
4600 lpfc_block_fabric_iocbs(phba);
4604 stat.un.lsRjtError =
4605 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
4606 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
4607 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
4608 lpfc_block_fabric_iocbs(phba);
4612 if (atomic_read(&phba->fabric_iocb_count) == 0)
4615 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
4616 cmdiocb->fabric_iocb_cmpl = NULL;
4617 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
4618 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
4620 atomic_dec(&phba->fabric_iocb_count);
4621 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
4622 /* Post any pending iocbs to HBA */
4623 lpfc_resume_fabric_iocbs(phba);
4628 lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
4630 unsigned long iflags;
4631 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
4635 if (atomic_read(&phba->fabric_iocb_count) > 1)
4638 spin_lock_irqsave(&phba->hbalock, iflags);
4639 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
4640 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
4642 spin_unlock_irqrestore(&phba->hbalock, iflags);
4644 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
4645 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
4646 iocb->iocb_flag |= LPFC_IO_FABRIC;
4648 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
4649 "Fabric sched2: ste:x%x",
4650 iocb->vport->port_state, 0, 0);
4652 atomic_inc(&phba->fabric_iocb_count);
4653 ret = lpfc_sli_issue_iocb(phba, pring, iocb, 0);
4655 if (ret == IOCB_ERROR) {
4656 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
4657 iocb->fabric_iocb_cmpl = NULL;
4658 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
4659 atomic_dec(&phba->fabric_iocb_count);
4662 spin_lock_irqsave(&phba->hbalock, iflags);
4663 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
4664 spin_unlock_irqrestore(&phba->hbalock, iflags);
4671 void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
4673 LIST_HEAD(completions);
4674 struct lpfc_hba *phba = vport->phba;
4675 struct lpfc_iocbq *tmp_iocb, *piocb;
4678 spin_lock_irq(&phba->hbalock);
4679 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
4682 if (piocb->vport != vport)
4685 list_move_tail(&piocb->list, &completions);
4687 spin_unlock_irq(&phba->hbalock);
4689 while (!list_empty(&completions)) {
4690 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
4691 list_del_init(&piocb->list);
4694 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
4695 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
4696 (piocb->iocb_cmpl) (phba, piocb, piocb);
4700 void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
4702 LIST_HEAD(completions);
4703 struct lpfc_hba *phba = ndlp->vport->phba;
4704 struct lpfc_iocbq *tmp_iocb, *piocb;
4705 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
4708 spin_lock_irq(&phba->hbalock);
4709 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
4711 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
4713 list_move_tail(&piocb->list, &completions);
4716 spin_unlock_irq(&phba->hbalock);
4718 while (!list_empty(&completions)) {
4719 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
4720 list_del_init(&piocb->list);
4723 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
4724 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
4725 (piocb->iocb_cmpl) (phba, piocb, piocb);
4729 void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
4731 LIST_HEAD(completions);
4732 struct lpfc_iocbq *piocb;
4735 spin_lock_irq(&phba->hbalock);
4736 list_splice_init(&phba->fabric_iocb_list, &completions);
4737 spin_unlock_irq(&phba->hbalock);
4739 while (!list_empty(&completions)) {
4740 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
4741 list_del_init(&piocb->list);
4744 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
4745 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
4746 (piocb->iocb_cmpl) (phba, piocb, piocb);
4751 void lpfc_fabric_abort_flogi(struct lpfc_hba *phba)
4753 LIST_HEAD(completions);
4754 struct lpfc_iocbq *tmp_iocb, *piocb;
4756 struct lpfc_nodelist *ndlp;
4758 spin_lock_irq(&phba->hbalock);
4759 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
4763 ndlp = (struct lpfc_nodelist *) piocb->context1;
4764 if (cmd->ulpCommand == CMD_ELS_REQUEST64_CR &&
4766 ndlp->nlp_DID == Fabric_DID)
4767 list_move_tail(&piocb->list, &completions);
4769 spin_unlock_irq(&phba->hbalock);
4771 while (!list_empty(&completions)) {
4772 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
4773 list_del_init(&piocb->list);
4776 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
4777 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
4778 (piocb->iocb_cmpl) (phba, piocb, piocb);