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 if (((pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL)) == 0) ||
113 ((pcmd->virt = lpfc_mbuf_alloc(phba,
114 MEM_PRI, &(pcmd->phys))) == 0)) {
117 lpfc_sli_release_iocbq(phba, elsiocb);
121 INIT_LIST_HEAD(&pcmd->list);
123 /* Allocate buffer for response payload */
125 prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
127 prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
129 if (prsp == 0 || prsp->virt == 0) {
131 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
133 lpfc_sli_release_iocbq(phba, elsiocb);
136 INIT_LIST_HEAD(&prsp->list);
141 /* Allocate buffer for Buffer ptr list */
142 pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
144 pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
146 if (pbuflist == 0 || pbuflist->virt == 0) {
147 lpfc_sli_release_iocbq(phba, elsiocb);
148 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
149 lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
156 INIT_LIST_HEAD(&pbuflist->list);
158 icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
159 icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
160 icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BDL;
161 icmd->un.elsreq64.remoteID = did; /* DID */
163 icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
164 icmd->ulpCommand = CMD_ELS_REQUEST64_CR;
165 icmd->ulpTimeout = phba->fc_ratov * 2;
167 icmd->un.elsreq64.bdl.bdeSize = sizeof(struct ulp_bde64);
168 icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
170 icmd->ulpBdeCount = 1;
172 icmd->ulpClass = CLASS3;
174 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
175 icmd->un.elsreq64.myID = vport->fc_myDID;
177 /* For ELS_REQUEST64_CR, use the VPI by default */
178 icmd->ulpContext = vport->vpi;
183 bpl = (struct ulp_bde64 *) pbuflist->virt;
184 bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys));
185 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys));
186 bpl->tus.f.bdeSize = cmdSize;
187 bpl->tus.f.bdeFlags = 0;
188 bpl->tus.w = le32_to_cpu(bpl->tus.w);
192 bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys));
193 bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys));
194 bpl->tus.f.bdeSize = FCELSSIZE;
195 bpl->tus.f.bdeFlags = BUFF_USE_RCV;
196 bpl->tus.w = le32_to_cpu(bpl->tus.w);
199 elsiocb->context1 = lpfc_nlp_get(ndlp);
200 elsiocb->context2 = pcmd;
201 elsiocb->context3 = pbuflist;
202 elsiocb->retry = retry;
203 elsiocb->vport = vport;
204 elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
207 list_add(&prsp->list, &pcmd->list);
210 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
211 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
212 "0116 Xmit ELS command x%x to remote "
213 "NPORT x%x I/O tag: x%x, port state: x%x\n",
214 elscmd, did, elsiocb->iotag,
217 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
218 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
219 "0117 Xmit ELS response x%x to remote "
220 "NPORT x%x I/O tag: x%x, size: x%x\n",
221 elscmd, ndlp->nlp_DID, elsiocb->iotag,
229 lpfc_issue_fabric_reglogin(struct lpfc_vport *vport)
231 struct lpfc_hba *phba = vport->phba;
233 struct lpfc_dmabuf *mp;
234 struct lpfc_nodelist *ndlp;
235 struct serv_parm *sp;
238 sp = &phba->fc_fabparam;
239 ndlp = lpfc_findnode_did(vport, Fabric_DID);
243 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
247 vport->port_state = LPFC_FABRIC_CFG_LINK;
248 lpfc_config_link(phba, mbox);
249 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
252 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
253 if (rc == MBX_NOT_FINISHED)
256 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
259 rc = lpfc_reg_login(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox,
264 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
266 mbox->context2 = lpfc_nlp_get(ndlp);
268 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
269 if (rc == MBX_NOT_FINISHED)
270 goto fail_issue_reg_login;
274 fail_issue_reg_login:
276 mp = (struct lpfc_dmabuf *) mbox->context1;
277 lpfc_mbuf_free(phba, mp->virt, mp->phys);
280 mempool_free(mbox, phba->mbox_mem_pool);
283 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
284 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
285 "0249 Cannot issue Register Fabric login\n");
290 lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
291 struct serv_parm *sp, IOCB_t *irsp)
293 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
294 struct lpfc_hba *phba = vport->phba;
295 struct lpfc_nodelist *np;
296 struct lpfc_nodelist *next_np;
298 spin_lock_irq(shost->host_lock);
299 vport->fc_flag |= FC_FABRIC;
300 spin_unlock_irq(shost->host_lock);
302 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
303 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
304 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
306 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
308 if (phba->fc_topology == TOPOLOGY_LOOP) {
309 spin_lock_irq(shost->host_lock);
310 vport->fc_flag |= FC_PUBLIC_LOOP;
311 spin_unlock_irq(shost->host_lock);
314 * If we are a N-port connected to a Fabric, fixup sparam's so
315 * logins to devices on remote loops work.
317 vport->fc_sparam.cmn.altBbCredit = 1;
320 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
321 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
322 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
323 ndlp->nlp_class_sup = 0;
324 if (sp->cls1.classValid)
325 ndlp->nlp_class_sup |= FC_COS_CLASS1;
326 if (sp->cls2.classValid)
327 ndlp->nlp_class_sup |= FC_COS_CLASS2;
328 if (sp->cls3.classValid)
329 ndlp->nlp_class_sup |= FC_COS_CLASS3;
330 if (sp->cls4.classValid)
331 ndlp->nlp_class_sup |= FC_COS_CLASS4;
332 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
333 sp->cmn.bbRcvSizeLsb;
334 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
336 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
337 if (sp->cmn.response_multiple_NPort) {
338 lpfc_printf_vlog(vport, KERN_WARNING,
340 "1816 FLOGI NPIV supported, "
341 "response data 0x%x\n",
342 sp->cmn.response_multiple_NPort);
343 phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
345 /* Because we asked f/w for NPIV it still expects us
346 to call reg_vnpid atleast for the physcial host */
347 lpfc_printf_vlog(vport, KERN_WARNING,
349 "1817 Fabric does not support NPIV "
350 "- configuring single port mode.\n");
351 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
355 if ((vport->fc_prevDID != vport->fc_myDID) &&
356 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
358 /* If our NportID changed, we need to ensure all
359 * remaining NPORTs get unreg_login'ed.
361 list_for_each_entry_safe(np, next_np,
362 &vport->fc_nodes, nlp_listp) {
363 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
364 !(np->nlp_flag & NLP_NPR_ADISC))
366 spin_lock_irq(shost->host_lock);
367 np->nlp_flag &= ~NLP_NPR_ADISC;
368 spin_unlock_irq(shost->host_lock);
369 lpfc_unreg_rpi(vport, np);
371 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
372 lpfc_mbx_unreg_vpi(vport);
373 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
377 ndlp->nlp_sid = irsp->un.ulpWord[4] & Mask_DID;
378 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
380 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
381 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) {
382 lpfc_register_new_vport(phba, vport, ndlp);
385 lpfc_issue_fabric_reglogin(vport);
390 * We FLOGIed into an NPort, initiate pt2pt protocol
393 lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
394 struct serv_parm *sp)
396 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
397 struct lpfc_hba *phba = vport->phba;
401 spin_lock_irq(shost->host_lock);
402 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
403 spin_unlock_irq(shost->host_lock);
405 phba->fc_edtov = FF_DEF_EDTOV;
406 phba->fc_ratov = FF_DEF_RATOV;
407 rc = memcmp(&vport->fc_portname, &sp->portName,
408 sizeof(vport->fc_portname));
410 /* This side will initiate the PLOGI */
411 spin_lock_irq(shost->host_lock);
412 vport->fc_flag |= FC_PT2PT_PLOGI;
413 spin_unlock_irq(shost->host_lock);
416 * N_Port ID cannot be 0, set our to LocalID the other
417 * side will be RemoteID.
422 vport->fc_myDID = PT2PT_LocalID;
424 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
428 lpfc_config_link(phba, mbox);
430 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
432 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
433 if (rc == MBX_NOT_FINISHED) {
434 mempool_free(mbox, phba->mbox_mem_pool);
439 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
442 * Cannot find existing Fabric ndlp, so allocate a
445 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
449 lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID);
452 memcpy(&ndlp->nlp_portname, &sp->portName,
453 sizeof(struct lpfc_name));
454 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
455 sizeof(struct lpfc_name));
456 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
457 spin_lock_irq(shost->host_lock);
458 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
459 spin_unlock_irq(shost->host_lock);
461 /* This side will wait for the PLOGI */
465 spin_lock_irq(shost->host_lock);
466 vport->fc_flag |= FC_PT2PT;
467 spin_unlock_irq(shost->host_lock);
469 /* Start discovery - this should just do CLEAR_LA */
470 lpfc_disc_start(vport);
477 lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
478 struct lpfc_iocbq *rspiocb)
480 struct lpfc_vport *vport = cmdiocb->vport;
481 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
482 IOCB_t *irsp = &rspiocb->iocb;
483 struct lpfc_nodelist *ndlp = cmdiocb->context1;
484 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
485 struct serv_parm *sp;
488 /* Check to see if link went down during discovery */
489 if (lpfc_els_chk_latt(vport)) {
494 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
495 "FLOGI cmpl: status:x%x/x%x state:x%x",
496 irsp->ulpStatus, irsp->un.ulpWord[4],
499 if (irsp->ulpStatus) {
500 /* Check for retry */
501 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
504 /* FLOGI failed, so there is no fabric */
505 spin_lock_irq(shost->host_lock);
506 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
507 spin_unlock_irq(shost->host_lock);
509 /* If private loop, then allow max outstanding els to be
510 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
511 * alpa map would take too long otherwise.
513 if (phba->alpa_map[0] == 0) {
514 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
518 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
519 "0100 FLOGI failure Data: x%x x%x "
521 irsp->ulpStatus, irsp->un.ulpWord[4],
527 * The FLogI succeeded. Sync the data for the CPU before
530 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
532 sp = prsp->virt + sizeof(uint32_t);
534 /* FLOGI completes successfully */
535 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
536 "0101 FLOGI completes sucessfully "
537 "Data: x%x x%x x%x x%x\n",
538 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
539 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution);
541 if (vport->port_state == LPFC_FLOGI) {
543 * If Common Service Parameters indicate Nport
544 * we are point to point, if Fport we are Fabric.
547 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
549 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
558 if (!lpfc_error_lost_link(irsp)) {
559 /* FLOGI failed, so just use loop map to make discovery list */
560 lpfc_disc_list_loopmap(vport);
562 /* Start discovery */
563 lpfc_disc_start(vport);
567 lpfc_els_free_iocb(phba, cmdiocb);
571 lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
574 struct lpfc_hba *phba = vport->phba;
575 struct serv_parm *sp;
577 struct lpfc_iocbq *elsiocb;
578 struct lpfc_sli_ring *pring;
584 pring = &phba->sli.ring[LPFC_ELS_RING];
586 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
587 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
588 ndlp->nlp_DID, ELS_CMD_FLOGI);
593 icmd = &elsiocb->iocb;
594 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
596 /* For FLOGI request, remainder of payload is service parameters */
597 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
598 pcmd += sizeof(uint32_t);
599 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
600 sp = (struct serv_parm *) pcmd;
602 /* Setup CSPs accordingly for Fabric */
604 sp->cmn.w2.r_a_tov = 0;
605 sp->cls1.classValid = 0;
606 sp->cls2.seqDelivery = 1;
607 sp->cls3.seqDelivery = 1;
608 if (sp->cmn.fcphLow < FC_PH3)
609 sp->cmn.fcphLow = FC_PH3;
610 if (sp->cmn.fcphHigh < FC_PH3)
611 sp->cmn.fcphHigh = FC_PH3;
613 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
614 sp->cmn.request_multiple_Nport = 1;
616 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
621 if (phba->fc_topology != TOPOLOGY_LOOP) {
622 icmd->un.elsreq64.myID = 0;
623 icmd->un.elsreq64.fl = 1;
626 tmo = phba->fc_ratov;
627 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
628 lpfc_set_disctmo(vport);
629 phba->fc_ratov = tmo;
631 phba->fc_stat.elsXmitFLOGI++;
632 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
634 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
635 "Issue FLOGI: opt:x%x",
636 phba->sli3_options, 0, 0);
638 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
639 if (rc == IOCB_ERROR) {
640 lpfc_els_free_iocb(phba, elsiocb);
647 lpfc_els_abort_flogi(struct lpfc_hba *phba)
649 struct lpfc_sli_ring *pring;
650 struct lpfc_iocbq *iocb, *next_iocb;
651 struct lpfc_nodelist *ndlp;
654 /* Abort outstanding I/O on NPort <nlp_DID> */
655 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
656 "0201 Abort outstanding I/O on NPort x%x\n",
659 pring = &phba->sli.ring[LPFC_ELS_RING];
662 * Check the txcmplq for an iocb that matches the nport the driver is
665 spin_lock_irq(&phba->hbalock);
666 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
668 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR &&
669 icmd->un.elsreq64.bdl.ulpIoTag32) {
670 ndlp = (struct lpfc_nodelist *)(iocb->context1);
671 if (ndlp && (ndlp->nlp_DID == Fabric_DID)) {
672 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
676 spin_unlock_irq(&phba->hbalock);
682 lpfc_initial_flogi(struct lpfc_vport *vport)
684 struct lpfc_hba *phba = vport->phba;
685 struct lpfc_nodelist *ndlp;
687 /* First look for the Fabric ndlp */
688 ndlp = lpfc_findnode_did(vport, Fabric_DID);
690 /* Cannot find existing Fabric ndlp, so allocate a new one */
691 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
694 lpfc_nlp_init(vport, ndlp, Fabric_DID);
696 lpfc_dequeue_node(vport, ndlp);
698 if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
705 lpfc_initial_fdisc(struct lpfc_vport *vport)
707 struct lpfc_hba *phba = vport->phba;
708 struct lpfc_nodelist *ndlp;
710 /* First look for the Fabric ndlp */
711 ndlp = lpfc_findnode_did(vport, Fabric_DID);
713 /* Cannot find existing Fabric ndlp, so allocate a new one */
714 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
717 lpfc_nlp_init(vport, ndlp, Fabric_DID);
719 lpfc_dequeue_node(vport, ndlp);
721 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
727 lpfc_more_plogi(struct lpfc_vport *vport)
731 if (vport->num_disc_nodes)
732 vport->num_disc_nodes--;
734 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
735 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
736 "0232 Continue discovery with %d PLOGIs to go "
737 "Data: x%x x%x x%x\n",
738 vport->num_disc_nodes, vport->fc_plogi_cnt,
739 vport->fc_flag, vport->port_state);
740 /* Check to see if there are more PLOGIs to be sent */
741 if (vport->fc_flag & FC_NLP_MORE)
742 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
743 sentplogi = lpfc_els_disc_plogi(vport);
748 static struct lpfc_nodelist *
749 lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
750 struct lpfc_nodelist *ndlp)
752 struct lpfc_vport *vport = ndlp->vport;
753 struct lpfc_nodelist *new_ndlp;
754 struct serv_parm *sp;
755 uint8_t name[sizeof(struct lpfc_name)];
758 /* Fabric nodes can have the same WWPN so we don't bother searching
759 * by WWPN. Just return the ndlp that was given to us.
761 if (ndlp->nlp_type & NLP_FABRIC)
764 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
765 memset(name, 0, sizeof(struct lpfc_name));
767 /* Now we find out if the NPort we are logging into, matches the WWPN
768 * we have for that ndlp. If not, we have some work to do.
770 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
772 if (new_ndlp == ndlp)
776 rc = memcmp(&ndlp->nlp_portname, name,
777 sizeof(struct lpfc_name));
780 new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
784 lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID);
787 lpfc_unreg_rpi(vport, new_ndlp);
788 new_ndlp->nlp_DID = ndlp->nlp_DID;
789 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
790 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
792 /* Move this back to NPR state */
793 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0)
794 lpfc_drop_node(vport, ndlp);
796 lpfc_unreg_rpi(vport, ndlp);
797 ndlp->nlp_DID = 0; /* Two ndlps cannot have the same did */
798 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
804 lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
805 struct lpfc_iocbq *rspiocb)
807 struct lpfc_vport *vport = cmdiocb->vport;
808 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
810 struct lpfc_nodelist *ndlp;
811 struct lpfc_dmabuf *prsp;
812 int disc, rc, did, type;
814 /* we pass cmdiocb to state machine which needs rspiocb as well */
815 cmdiocb->context_un.rsp_iocb = rspiocb;
817 irsp = &rspiocb->iocb;
818 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
819 "PLOGI cmpl: status:x%x/x%x did:x%x",
820 irsp->ulpStatus, irsp->un.ulpWord[4],
821 irsp->un.elsreq64.remoteID);
823 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
825 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
826 "0136 PLOGI completes to NPort x%x "
827 "with no ndlp. Data: x%x x%x x%x\n",
828 irsp->un.elsreq64.remoteID,
829 irsp->ulpStatus, irsp->un.ulpWord[4],
834 /* Since ndlp can be freed in the disc state machine, note if this node
835 * is being used during discovery.
837 spin_lock_irq(shost->host_lock);
838 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
839 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
840 spin_unlock_irq(shost->host_lock);
843 /* PLOGI completes to NPort <nlp_DID> */
844 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
845 "0102 PLOGI completes to NPort x%x "
846 "Data: x%x x%x x%x x%x x%x\n",
847 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
848 irsp->ulpTimeout, disc, vport->num_disc_nodes);
849 /* Check to see if link went down during discovery */
850 if (lpfc_els_chk_latt(vport)) {
851 spin_lock_irq(shost->host_lock);
852 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
853 spin_unlock_irq(shost->host_lock);
857 /* ndlp could be freed in DSM, save these values now */
858 type = ndlp->nlp_type;
861 if (irsp->ulpStatus) {
862 /* Check for retry */
863 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
864 /* ELS command is being retried */
866 spin_lock_irq(shost->host_lock);
867 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
868 spin_unlock_irq(shost->host_lock);
873 if (ndlp->nlp_DID == NameServer_DID) {
874 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
875 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
876 "0250 Nameserver login error: "
878 irsp->ulpStatus, irsp->un.ulpWord[4]);
880 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
881 if (lpfc_error_lost_link(irsp)) {
882 rc = NLP_STE_FREED_NODE;
884 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
888 /* Good status, call state machine */
889 prsp = list_entry(((struct lpfc_dmabuf *)
890 cmdiocb->context2)->list.next,
891 struct lpfc_dmabuf, list);
892 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
893 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
897 if (disc && vport->num_disc_nodes) {
898 /* Check to see if there are more PLOGIs to be sent */
899 lpfc_more_plogi(vport);
901 if (vport->num_disc_nodes == 0) {
902 spin_lock_irq(shost->host_lock);
903 vport->fc_flag &= ~FC_NDISC_ACTIVE;
904 spin_unlock_irq(shost->host_lock);
906 lpfc_can_disctmo(vport);
907 if (vport->fc_flag & FC_RSCN_MODE) {
909 * Check to see if more RSCNs came in while
910 * we were processing this one.
912 if ((vport->fc_rscn_id_cnt == 0) &&
913 (!(vport->fc_flag & FC_RSCN_DISCOVERY))) {
914 spin_lock_irq(shost->host_lock);
915 vport->fc_flag &= ~FC_RSCN_MODE;
916 spin_unlock_irq(shost->host_lock);
918 lpfc_els_handle_rscn(vport);
925 lpfc_els_free_iocb(phba, cmdiocb);
930 lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
932 struct lpfc_hba *phba = vport->phba;
933 struct serv_parm *sp;
935 struct lpfc_iocbq *elsiocb;
936 struct lpfc_sli_ring *pring;
937 struct lpfc_sli *psli;
943 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
945 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
946 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, NULL, did,
951 icmd = &elsiocb->iocb;
952 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
954 /* For PLOGI request, remainder of payload is service parameters */
955 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
956 pcmd += sizeof(uint32_t);
957 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
958 sp = (struct serv_parm *) pcmd;
960 if (sp->cmn.fcphLow < FC_PH_4_3)
961 sp->cmn.fcphLow = FC_PH_4_3;
963 if (sp->cmn.fcphHigh < FC_PH3)
964 sp->cmn.fcphHigh = FC_PH3;
966 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
967 "Issue PLOGI: did:x%x",
970 phba->fc_stat.elsXmitPLOGI++;
971 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
972 ret = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
974 if (ret == IOCB_ERROR) {
975 lpfc_els_free_iocb(phba, elsiocb);
982 lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
983 struct lpfc_iocbq *rspiocb)
985 struct lpfc_vport *vport = cmdiocb->vport;
986 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
988 struct lpfc_sli *psli;
989 struct lpfc_nodelist *ndlp;
992 /* we pass cmdiocb to state machine which needs rspiocb as well */
993 cmdiocb->context_un.rsp_iocb = rspiocb;
995 irsp = &(rspiocb->iocb);
996 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
997 spin_lock_irq(shost->host_lock);
998 ndlp->nlp_flag &= ~NLP_PRLI_SND;
999 spin_unlock_irq(shost->host_lock);
1001 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1002 "PRLI cmpl: status:x%x/x%x did:x%x",
1003 irsp->ulpStatus, irsp->un.ulpWord[4],
1005 /* PRLI completes to NPort <nlp_DID> */
1006 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1007 "0103 PRLI completes to NPort x%x "
1008 "Data: x%x x%x x%x x%x\n",
1009 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1010 irsp->ulpTimeout, vport->num_disc_nodes);
1012 vport->fc_prli_sent--;
1013 /* Check to see if link went down during discovery */
1014 if (lpfc_els_chk_latt(vport))
1017 if (irsp->ulpStatus) {
1018 /* Check for retry */
1019 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1020 /* ELS command is being retried */
1024 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1025 if (lpfc_error_lost_link(irsp)) {
1028 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1032 /* Good status, call state machine */
1033 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1038 lpfc_els_free_iocb(phba, cmdiocb);
1043 lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1046 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1047 struct lpfc_hba *phba = vport->phba;
1050 struct lpfc_iocbq *elsiocb;
1051 struct lpfc_sli_ring *pring;
1052 struct lpfc_sli *psli;
1057 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1059 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
1060 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1061 ndlp->nlp_DID, ELS_CMD_PRLI);
1065 icmd = &elsiocb->iocb;
1066 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1068 /* For PRLI request, remainder of payload is service parameters */
1069 memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t)));
1070 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
1071 pcmd += sizeof(uint32_t);
1073 /* For PRLI, remainder of payload is PRLI parameter page */
1074 npr = (PRLI *) pcmd;
1076 * If our firmware version is 3.20 or later,
1077 * set the following bits for FC-TAPE support.
1079 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
1080 npr->ConfmComplAllowed = 1;
1082 npr->TaskRetryIdReq = 1;
1084 npr->estabImagePair = 1;
1085 npr->readXferRdyDis = 1;
1087 /* For FCP support */
1088 npr->prliType = PRLI_FCP_TYPE;
1089 npr->initiatorFunc = 1;
1091 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1092 "Issue PRLI: did:x%x",
1093 ndlp->nlp_DID, 0, 0);
1095 phba->fc_stat.elsXmitPRLI++;
1096 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
1097 spin_lock_irq(shost->host_lock);
1098 ndlp->nlp_flag |= NLP_PRLI_SND;
1099 spin_unlock_irq(shost->host_lock);
1100 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
1101 spin_lock_irq(shost->host_lock);
1102 ndlp->nlp_flag &= ~NLP_PRLI_SND;
1103 spin_unlock_irq(shost->host_lock);
1104 lpfc_els_free_iocb(phba, elsiocb);
1107 vport->fc_prli_sent++;
1112 lpfc_more_adisc(struct lpfc_vport *vport)
1116 if (vport->num_disc_nodes)
1117 vport->num_disc_nodes--;
1118 /* Continue discovery with <num_disc_nodes> ADISCs to go */
1119 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1120 "0210 Continue discovery with %d ADISCs to go "
1121 "Data: x%x x%x x%x\n",
1122 vport->num_disc_nodes, vport->fc_adisc_cnt,
1123 vport->fc_flag, vport->port_state);
1124 /* Check to see if there are more ADISCs to be sent */
1125 if (vport->fc_flag & FC_NLP_MORE) {
1126 lpfc_set_disctmo(vport);
1127 /* go thru NPR nodes and issue any remaining ELS ADISCs */
1128 sentadisc = lpfc_els_disc_adisc(vport);
1134 lpfc_rscn_disc(struct lpfc_vport *vport)
1136 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1138 lpfc_can_disctmo(vport);
1140 /* RSCN discovery */
1141 /* go thru NPR nodes and issue ELS PLOGIs */
1142 if (vport->fc_npr_cnt)
1143 if (lpfc_els_disc_plogi(vport))
1146 if (vport->fc_flag & FC_RSCN_MODE) {
1147 /* Check to see if more RSCNs came in while we were
1148 * processing this one.
1150 if ((vport->fc_rscn_id_cnt == 0) &&
1151 (!(vport->fc_flag & FC_RSCN_DISCOVERY))) {
1152 spin_lock_irq(shost->host_lock);
1153 vport->fc_flag &= ~FC_RSCN_MODE;
1154 spin_unlock_irq(shost->host_lock);
1156 lpfc_els_handle_rscn(vport);
1162 lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1163 struct lpfc_iocbq *rspiocb)
1165 struct lpfc_vport *vport = cmdiocb->vport;
1166 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1168 struct lpfc_nodelist *ndlp;
1171 /* we pass cmdiocb to state machine which needs rspiocb as well */
1172 cmdiocb->context_un.rsp_iocb = rspiocb;
1174 irsp = &(rspiocb->iocb);
1175 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1177 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1178 "ADISC cmpl: status:x%x/x%x did:x%x",
1179 irsp->ulpStatus, irsp->un.ulpWord[4],
1182 /* Since ndlp can be freed in the disc state machine, note if this node
1183 * is being used during discovery.
1185 spin_lock_irq(shost->host_lock);
1186 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
1187 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
1188 spin_unlock_irq(shost->host_lock);
1189 /* ADISC completes to NPort <nlp_DID> */
1190 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1191 "0104 ADISC completes to NPort x%x "
1192 "Data: x%x x%x x%x x%x x%x\n",
1193 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1194 irsp->ulpTimeout, disc, vport->num_disc_nodes);
1195 /* Check to see if link went down during discovery */
1196 if (lpfc_els_chk_latt(vport)) {
1197 spin_lock_irq(shost->host_lock);
1198 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1199 spin_unlock_irq(shost->host_lock);
1203 if (irsp->ulpStatus) {
1204 /* Check for retry */
1205 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1206 /* ELS command is being retried */
1208 spin_lock_irq(shost->host_lock);
1209 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1210 spin_unlock_irq(shost->host_lock);
1211 lpfc_set_disctmo(vport);
1216 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1217 if (!lpfc_error_lost_link(irsp)) {
1218 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1219 NLP_EVT_CMPL_ADISC);
1222 /* Good status, call state machine */
1223 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1224 NLP_EVT_CMPL_ADISC);
1227 if (disc && vport->num_disc_nodes) {
1228 /* Check to see if there are more ADISCs to be sent */
1229 lpfc_more_adisc(vport);
1231 /* Check to see if we are done with ADISC authentication */
1232 if (vport->num_disc_nodes == 0) {
1233 /* If we get here, there is nothing left to ADISC */
1235 * For NPIV, cmpl_reg_vpi will set port_state to READY,
1236 * and continue discovery.
1238 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
1239 !(vport->fc_flag & FC_RSCN_MODE)) {
1240 lpfc_issue_reg_vpi(phba, vport);
1244 * For SLI2, we need to set port_state to READY
1245 * and continue discovery.
1247 if (vport->port_state < LPFC_VPORT_READY) {
1248 /* If we get here, there is nothing to ADISC */
1249 if (vport->port_type == LPFC_PHYSICAL_PORT)
1250 lpfc_issue_clear_la(phba, vport);
1252 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
1253 vport->num_disc_nodes = 0;
1254 /* go thru NPR list, issue ELS PLOGIs */
1255 if (vport->fc_npr_cnt)
1256 lpfc_els_disc_plogi(vport);
1258 if (!vport->num_disc_nodes) {
1259 spin_lock_irq(shost->host_lock);
1264 lpfc_can_disctmo(vport);
1267 vport->port_state = LPFC_VPORT_READY;
1269 lpfc_rscn_disc(vport);
1274 lpfc_els_free_iocb(phba, cmdiocb);
1279 lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1282 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1283 struct lpfc_hba *phba = vport->phba;
1286 struct lpfc_iocbq *elsiocb;
1287 struct lpfc_sli *psli = &phba->sli;
1288 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
1292 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
1293 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1294 ndlp->nlp_DID, ELS_CMD_ADISC);
1298 icmd = &elsiocb->iocb;
1299 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1301 /* For ADISC request, remainder of payload is service parameters */
1302 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
1303 pcmd += sizeof(uint32_t);
1305 /* Fill in ADISC payload */
1306 ap = (ADISC *) pcmd;
1307 ap->hardAL_PA = phba->fc_pref_ALPA;
1308 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
1309 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
1310 ap->DID = be32_to_cpu(vport->fc_myDID);
1312 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1313 "Issue ADISC: did:x%x",
1314 ndlp->nlp_DID, 0, 0);
1316 phba->fc_stat.elsXmitADISC++;
1317 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
1318 spin_lock_irq(shost->host_lock);
1319 ndlp->nlp_flag |= NLP_ADISC_SND;
1320 spin_unlock_irq(shost->host_lock);
1321 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
1322 spin_lock_irq(shost->host_lock);
1323 ndlp->nlp_flag &= ~NLP_ADISC_SND;
1324 spin_unlock_irq(shost->host_lock);
1325 lpfc_els_free_iocb(phba, elsiocb);
1332 lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1333 struct lpfc_iocbq *rspiocb)
1335 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1336 struct lpfc_vport *vport = ndlp->vport;
1337 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1339 struct lpfc_sli *psli;
1342 /* we pass cmdiocb to state machine which needs rspiocb as well */
1343 cmdiocb->context_un.rsp_iocb = rspiocb;
1345 irsp = &(rspiocb->iocb);
1346 spin_lock_irq(shost->host_lock);
1347 ndlp->nlp_flag &= ~NLP_LOGO_SND;
1348 spin_unlock_irq(shost->host_lock);
1350 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1351 "LOGO cmpl: status:x%x/x%x did:x%x",
1352 irsp->ulpStatus, irsp->un.ulpWord[4],
1354 /* LOGO completes to NPort <nlp_DID> */
1355 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1356 "0105 LOGO completes to NPort x%x "
1357 "Data: x%x x%x x%x x%x\n",
1358 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1359 irsp->ulpTimeout, vport->num_disc_nodes);
1360 /* Check to see if link went down during discovery */
1361 if (lpfc_els_chk_latt(vport))
1364 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
1365 /* NLP_EVT_DEVICE_RM should unregister the RPI
1366 * which should abort all outstanding IOs.
1368 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1373 if (irsp->ulpStatus) {
1374 /* Check for retry */
1375 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
1376 /* ELS command is being retried */
1379 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1380 if (lpfc_error_lost_link(irsp))
1383 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1386 /* Good status, call state machine.
1387 * This will unregister the rpi if needed.
1389 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1394 lpfc_els_free_iocb(phba, cmdiocb);
1399 lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1402 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1403 struct lpfc_hba *phba = vport->phba;
1405 struct lpfc_iocbq *elsiocb;
1406 struct lpfc_sli_ring *pring;
1407 struct lpfc_sli *psli;
1413 pring = &psli->ring[LPFC_ELS_RING];
1415 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
1416 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1417 ndlp->nlp_DID, ELS_CMD_LOGO);
1421 icmd = &elsiocb->iocb;
1422 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1423 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
1424 pcmd += sizeof(uint32_t);
1426 /* Fill in LOGO payload */
1427 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
1428 pcmd += sizeof(uint32_t);
1429 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
1431 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1432 "Issue LOGO: did:x%x",
1433 ndlp->nlp_DID, 0, 0);
1435 phba->fc_stat.elsXmitLOGO++;
1436 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
1437 spin_lock_irq(shost->host_lock);
1438 ndlp->nlp_flag |= NLP_LOGO_SND;
1439 spin_unlock_irq(shost->host_lock);
1440 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
1442 if (rc == IOCB_ERROR) {
1443 spin_lock_irq(shost->host_lock);
1444 ndlp->nlp_flag &= ~NLP_LOGO_SND;
1445 spin_unlock_irq(shost->host_lock);
1446 lpfc_els_free_iocb(phba, elsiocb);
1453 lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1454 struct lpfc_iocbq *rspiocb)
1456 struct lpfc_vport *vport = cmdiocb->vport;
1459 irsp = &rspiocb->iocb;
1461 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1462 "ELS cmd cmpl: status:x%x/x%x did:x%x",
1463 irsp->ulpStatus, irsp->un.ulpWord[4],
1464 irsp->un.elsreq64.remoteID);
1465 /* ELS cmd tag <ulpIoTag> completes */
1466 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1467 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
1468 irsp->ulpIoTag, irsp->ulpStatus,
1469 irsp->un.ulpWord[4], irsp->ulpTimeout);
1470 /* Check to see if link went down during discovery */
1471 lpfc_els_chk_latt(vport);
1472 lpfc_els_free_iocb(phba, cmdiocb);
1477 lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
1479 struct lpfc_hba *phba = vport->phba;
1481 struct lpfc_iocbq *elsiocb;
1482 struct lpfc_sli_ring *pring;
1483 struct lpfc_sli *psli;
1486 struct lpfc_nodelist *ndlp;
1489 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1490 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
1491 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1495 lpfc_nlp_init(vport, ndlp, nportid);
1497 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1498 ndlp->nlp_DID, ELS_CMD_SCR);
1505 icmd = &elsiocb->iocb;
1506 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1508 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
1509 pcmd += sizeof(uint32_t);
1511 /* For SCR, remainder of payload is SCR parameter page */
1512 memset(pcmd, 0, sizeof(SCR));
1513 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
1515 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1516 "Issue SCR: did:x%x",
1517 ndlp->nlp_DID, 0, 0);
1519 phba->fc_stat.elsXmitSCR++;
1520 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
1521 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
1523 lpfc_els_free_iocb(phba, elsiocb);
1531 lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
1533 struct lpfc_hba *phba = vport->phba;
1535 struct lpfc_iocbq *elsiocb;
1536 struct lpfc_sli_ring *pring;
1537 struct lpfc_sli *psli;
1542 struct lpfc_nodelist *ondlp;
1543 struct lpfc_nodelist *ndlp;
1546 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1547 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
1548 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1552 lpfc_nlp_init(vport, ndlp, nportid);
1554 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1555 ndlp->nlp_DID, ELS_CMD_RNID);
1561 icmd = &elsiocb->iocb;
1562 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1564 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
1565 pcmd += sizeof(uint32_t);
1567 /* Fill in FARPR payload */
1568 fp = (FARP *) (pcmd);
1569 memset(fp, 0, sizeof(FARP));
1570 lp = (uint32_t *) pcmd;
1571 *lp++ = be32_to_cpu(nportid);
1572 *lp++ = be32_to_cpu(vport->fc_myDID);
1574 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
1576 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
1577 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
1578 ondlp = lpfc_findnode_did(vport, nportid);
1580 memcpy(&fp->OportName, &ondlp->nlp_portname,
1581 sizeof(struct lpfc_name));
1582 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
1583 sizeof(struct lpfc_name));
1586 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1587 "Issue FARPR: did:x%x",
1588 ndlp->nlp_DID, 0, 0);
1590 phba->fc_stat.elsXmitFARPR++;
1591 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
1592 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
1594 lpfc_els_free_iocb(phba, elsiocb);
1602 lpfc_end_rscn(struct lpfc_vport *vport)
1604 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1606 if (vport->fc_flag & FC_RSCN_MODE) {
1608 * Check to see if more RSCNs came in while we were
1609 * processing this one.
1611 if (vport->fc_rscn_id_cnt ||
1612 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1613 lpfc_els_handle_rscn(vport);
1615 spin_lock_irq(shost->host_lock);
1616 vport->fc_flag &= ~FC_RSCN_MODE;
1617 spin_unlock_irq(shost->host_lock);
1623 lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
1625 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1627 spin_lock_irq(shost->host_lock);
1628 nlp->nlp_flag &= ~NLP_DELAY_TMO;
1629 spin_unlock_irq(shost->host_lock);
1630 del_timer_sync(&nlp->nlp_delayfunc);
1631 nlp->nlp_last_elscmd = 0;
1633 if (!list_empty(&nlp->els_retry_evt.evt_listp))
1634 list_del_init(&nlp->els_retry_evt.evt_listp);
1636 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
1637 spin_lock_irq(shost->host_lock);
1638 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1639 spin_unlock_irq(shost->host_lock);
1640 if (vport->num_disc_nodes) {
1641 /* Check to see if there are more
1644 lpfc_more_plogi(vport);
1646 if (vport->num_disc_nodes == 0) {
1647 spin_lock_irq(shost->host_lock);
1648 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1649 spin_unlock_irq(shost->host_lock);
1650 lpfc_can_disctmo(vport);
1651 lpfc_end_rscn(vport);
1659 lpfc_els_retry_delay(unsigned long ptr)
1661 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
1662 struct lpfc_vport *vport = ndlp->vport;
1663 struct lpfc_hba *phba = vport->phba;
1664 unsigned long flags;
1665 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
1667 ndlp = (struct lpfc_nodelist *) ptr;
1668 phba = ndlp->vport->phba;
1669 evtp = &ndlp->els_retry_evt;
1671 spin_lock_irqsave(&phba->hbalock, flags);
1672 if (!list_empty(&evtp->evt_listp)) {
1673 spin_unlock_irqrestore(&phba->hbalock, flags);
1677 evtp->evt_arg1 = ndlp;
1678 evtp->evt = LPFC_EVT_ELS_RETRY;
1679 list_add_tail(&evtp->evt_listp, &phba->work_list);
1680 if (phba->work_wait)
1681 lpfc_worker_wake_up(phba);
1683 spin_unlock_irqrestore(&phba->hbalock, flags);
1688 lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
1690 struct lpfc_vport *vport = ndlp->vport;
1691 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1692 uint32_t cmd, did, retry;
1694 spin_lock_irq(shost->host_lock);
1695 did = ndlp->nlp_DID;
1696 cmd = ndlp->nlp_last_elscmd;
1697 ndlp->nlp_last_elscmd = 0;
1699 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
1700 spin_unlock_irq(shost->host_lock);
1704 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
1705 spin_unlock_irq(shost->host_lock);
1707 * If a discovery event readded nlp_delayfunc after timer
1708 * firing and before processing the timer, cancel the
1711 del_timer_sync(&ndlp->nlp_delayfunc);
1712 retry = ndlp->nlp_retry;
1716 lpfc_issue_els_flogi(vport, ndlp, retry);
1719 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
1720 ndlp->nlp_prev_state = ndlp->nlp_state;
1721 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1725 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
1726 ndlp->nlp_prev_state = ndlp->nlp_state;
1727 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
1731 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
1732 ndlp->nlp_prev_state = ndlp->nlp_state;
1733 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
1737 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
1738 ndlp->nlp_prev_state = ndlp->nlp_state;
1739 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1743 lpfc_issue_els_fdisc(vport, ndlp, retry);
1750 lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1751 struct lpfc_iocbq *rspiocb)
1753 struct lpfc_vport *vport = cmdiocb->vport;
1754 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1755 IOCB_t *irsp = &rspiocb->iocb;
1756 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1757 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
1760 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
1765 /* Note: context2 may be 0 for internal driver abort
1766 * of delays ELS command.
1769 if (pcmd && pcmd->virt) {
1770 elscmd = (uint32_t *) (pcmd->virt);
1775 did = ndlp->nlp_DID;
1777 /* We should only hit this case for retrying PLOGI */
1778 did = irsp->un.elsreq64.remoteID;
1779 ndlp = lpfc_findnode_did(vport, did);
1780 if (!ndlp && (cmd != ELS_CMD_PLOGI))
1784 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1785 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
1786 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
1788 switch (irsp->ulpStatus) {
1789 case IOSTAT_FCP_RSP_ERROR:
1790 case IOSTAT_REMOTE_STOP:
1793 case IOSTAT_LOCAL_REJECT:
1794 switch ((irsp->un.ulpWord[4] & 0xff)) {
1795 case IOERR_LOOP_OPEN_FAILURE:
1796 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
1801 case IOERR_ILLEGAL_COMMAND:
1802 if ((phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) &&
1803 (cmd == ELS_CMD_FDISC)) {
1804 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1805 "0124 FDISC failed (3/6) "
1807 lpfc_mbx_unreg_vpi(vport);
1809 /* FDISC retry policy */
1811 if (cmdiocb->retry >= 32)
1816 case IOERR_NO_RESOURCES:
1818 if (cmdiocb->retry > 100)
1823 case IOERR_ILLEGAL_FRAME:
1828 case IOERR_SEQUENCE_TIMEOUT:
1829 case IOERR_INVALID_RPI:
1835 case IOSTAT_NPORT_RJT:
1836 case IOSTAT_FABRIC_RJT:
1837 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
1843 case IOSTAT_NPORT_BSY:
1844 case IOSTAT_FABRIC_BSY:
1849 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
1850 /* Added for Vendor specifc support
1851 * Just keep retrying for these Rsn / Exp codes
1853 switch (stat.un.b.lsRjtRsnCode) {
1854 case LSRJT_UNABLE_TPC:
1855 if (stat.un.b.lsRjtRsnCodeExp ==
1856 LSEXP_CMD_IN_PROGRESS) {
1857 if (cmd == ELS_CMD_PLOGI) {
1864 if (cmd == ELS_CMD_PLOGI) {
1866 maxretry = lpfc_max_els_tries + 1;
1870 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
1871 (cmd == ELS_CMD_FDISC) &&
1872 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
1873 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1874 "0125 FDISC Failed (x%x). "
1875 "Fabric out of resources\n",
1876 stat.un.lsRjtError);
1877 lpfc_vport_set_state(vport,
1878 FC_VPORT_NO_FABRIC_RSCS);
1882 case LSRJT_LOGICAL_BSY:
1883 if ((cmd == ELS_CMD_PLOGI) ||
1884 (cmd == ELS_CMD_PRLI)) {
1887 } else if (cmd == ELS_CMD_FDISC) {
1888 /* FDISC retry policy */
1890 if (cmdiocb->retry >= 32)
1896 case LSRJT_LOGICAL_ERR:
1897 case LSRJT_PROTOCOL_ERR:
1898 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
1899 (cmd == ELS_CMD_FDISC) &&
1900 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
1901 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
1903 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1904 "0123 FDISC Failed (x%x). "
1905 "Fabric Detected Bad WWN\n",
1906 stat.un.lsRjtError);
1907 lpfc_vport_set_state(vport,
1908 FC_VPORT_FABRIC_REJ_WWN);
1914 case IOSTAT_INTERMED_RSP:
1922 if (did == FDMI_DID)
1925 if ((++cmdiocb->retry) >= maxretry) {
1926 phba->fc_stat.elsRetryExceeded++;
1930 if ((vport->load_flag & FC_UNLOADING) != 0)
1935 /* Retry ELS command <elsCmd> to remote NPORT <did> */
1936 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1937 "0107 Retry ELS command x%x to remote "
1938 "NPORT x%x Data: x%x x%x\n",
1939 cmd, did, cmdiocb->retry, delay);
1941 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
1942 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
1943 ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) {
1944 /* Don't reset timer for no resources */
1946 /* If discovery / RSCN timer is running, reset it */
1947 if (timer_pending(&vport->fc_disctmo) ||
1948 (vport->fc_flag & FC_RSCN_MODE))
1949 lpfc_set_disctmo(vport);
1952 phba->fc_stat.elsXmitRetry++;
1953 if (ndlp && delay) {
1954 phba->fc_stat.elsDelayRetry++;
1955 ndlp->nlp_retry = cmdiocb->retry;
1957 /* delay is specified in milliseconds */
1958 mod_timer(&ndlp->nlp_delayfunc,
1959 jiffies + msecs_to_jiffies(delay));
1960 spin_lock_irq(shost->host_lock);
1961 ndlp->nlp_flag |= NLP_DELAY_TMO;
1962 spin_unlock_irq(shost->host_lock);
1964 ndlp->nlp_prev_state = ndlp->nlp_state;
1965 if (cmd == ELS_CMD_PRLI)
1966 lpfc_nlp_set_state(vport, ndlp,
1967 NLP_STE_REG_LOGIN_ISSUE);
1969 lpfc_nlp_set_state(vport, ndlp,
1971 ndlp->nlp_last_elscmd = cmd;
1977 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
1980 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
1984 ndlp->nlp_prev_state = ndlp->nlp_state;
1985 lpfc_nlp_set_state(vport, ndlp,
1986 NLP_STE_PLOGI_ISSUE);
1988 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
1991 ndlp->nlp_prev_state = ndlp->nlp_state;
1992 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
1993 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
1996 ndlp->nlp_prev_state = ndlp->nlp_state;
1997 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
1998 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
2001 ndlp->nlp_prev_state = ndlp->nlp_state;
2002 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2003 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
2007 /* No retry ELS command <elsCmd> to remote NPORT <did> */
2008 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2009 "0108 No retry ELS command x%x to remote "
2010 "NPORT x%x Retried:%d Error:x%x/%x\n",
2011 cmd, did, cmdiocb->retry, irsp->ulpStatus,
2012 irsp->un.ulpWord[4]);
2017 lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
2019 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
2021 if (elsiocb->context1) {
2022 lpfc_nlp_put(elsiocb->context1);
2023 elsiocb->context1 = NULL;
2025 /* context2 = cmd, context2->next = rsp, context3 = bpl */
2026 if (elsiocb->context2) {
2027 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
2028 /* Free the response before processing the command. */
2029 if (!list_empty(&buf_ptr1->list)) {
2030 list_remove_head(&buf_ptr1->list, buf_ptr,
2033 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
2036 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
2040 if (elsiocb->context3) {
2041 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
2042 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
2045 lpfc_sli_release_iocbq(phba, elsiocb);
2050 lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2051 struct lpfc_iocbq *rspiocb)
2053 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2054 struct lpfc_vport *vport = cmdiocb->vport;
2057 irsp = &rspiocb->iocb;
2058 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2059 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
2060 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
2061 /* ACC to LOGO completes to NPort <nlp_DID> */
2062 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2063 "0109 ACC to LOGO completes to NPort x%x "
2064 "Data: x%x x%x x%x\n",
2065 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2067 switch (ndlp->nlp_state) {
2068 case NLP_STE_UNUSED_NODE: /* node is just allocated */
2069 lpfc_drop_node(vport, ndlp);
2071 case NLP_STE_NPR_NODE: /* NPort Recovery mode */
2072 lpfc_unreg_rpi(vport, ndlp);
2077 lpfc_els_free_iocb(phba, cmdiocb);
2082 lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
2084 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
2085 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
2087 pmb->context1 = NULL;
2088 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2090 mempool_free(pmb, phba->mbox_mem_pool);
2096 lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2097 struct lpfc_iocbq *rspiocb)
2099 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2100 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
2101 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
2103 LPFC_MBOXQ_t *mbox = NULL;
2104 struct lpfc_dmabuf *mp = NULL;
2106 irsp = &rspiocb->iocb;
2108 if (cmdiocb->context_un.mbox)
2109 mbox = cmdiocb->context_un.mbox;
2111 /* Check to see if link went down during discovery */
2112 if (!ndlp || lpfc_els_chk_latt(vport)) {
2114 mp = (struct lpfc_dmabuf *) mbox->context1;
2116 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2119 mempool_free(mbox, phba->mbox_mem_pool);
2124 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2125 "ELS rsp cmpl: status:x%x/x%x did:x%x",
2126 irsp->ulpStatus, irsp->un.ulpWord[4],
2127 cmdiocb->iocb.un.elsreq64.remoteID);
2128 /* ELS response tag <ulpIoTag> completes */
2129 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2130 "0110 ELS response tag x%x completes "
2131 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
2132 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
2133 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
2134 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2137 if ((rspiocb->iocb.ulpStatus == 0)
2138 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
2139 lpfc_unreg_rpi(vport, ndlp);
2140 mbox->context2 = lpfc_nlp_get(ndlp);
2141 mbox->vport = vport;
2142 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
2143 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
2144 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
2147 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
2148 ndlp->nlp_prev_state = ndlp->nlp_state;
2149 lpfc_nlp_set_state(vport, ndlp,
2150 NLP_STE_REG_LOGIN_ISSUE);
2152 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
2153 != MBX_NOT_FINISHED) {
2157 /* NOTE: we should have messages for unsuccessful
2160 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
2161 if (!lpfc_error_lost_link(irsp) &&
2162 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
2163 lpfc_drop_node(vport, ndlp);
2167 mp = (struct lpfc_dmabuf *) mbox->context1;
2169 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2172 mempool_free(mbox, phba->mbox_mem_pool);
2176 spin_lock_irq(shost->host_lock);
2177 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
2178 spin_unlock_irq(shost->host_lock);
2180 lpfc_els_free_iocb(phba, cmdiocb);
2185 lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
2186 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
2189 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2190 struct lpfc_hba *phba = vport->phba;
2193 struct lpfc_iocbq *elsiocb;
2194 struct lpfc_sli_ring *pring;
2195 struct lpfc_sli *psli;
2199 ELS_PKT *els_pkt_ptr;
2202 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2203 oldcmd = &oldiocb->iocb;
2207 cmdsize = sizeof(uint32_t);
2208 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
2209 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
2211 spin_lock_irq(shost->host_lock);
2212 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
2213 spin_unlock_irq(shost->host_lock);
2217 icmd = &elsiocb->iocb;
2218 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2219 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2220 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
2221 pcmd += sizeof(uint32_t);
2223 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2224 "Issue ACC: did:x%x flg:x%x",
2225 ndlp->nlp_DID, ndlp->nlp_flag, 0);
2228 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
2229 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
2230 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
2234 icmd = &elsiocb->iocb;
2235 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2236 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2239 elsiocb->context_un.mbox = mbox;
2241 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
2242 pcmd += sizeof(uint32_t);
2243 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
2245 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2246 "Issue ACC PLOGI: did:x%x flg:x%x",
2247 ndlp->nlp_DID, ndlp->nlp_flag, 0);
2250 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
2251 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
2252 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
2256 icmd = &elsiocb->iocb;
2257 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2258 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2260 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
2261 sizeof(uint32_t) + sizeof(PRLO));
2262 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
2263 els_pkt_ptr = (ELS_PKT *) pcmd;
2264 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
2266 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2267 "Issue ACC PRLO: did:x%x flg:x%x",
2268 ndlp->nlp_DID, ndlp->nlp_flag, 0);
2273 /* Xmit ELS ACC response tag <ulpIoTag> */
2274 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2275 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
2276 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n",
2277 elsiocb->iotag, elsiocb->iocb.ulpContext,
2278 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2280 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
2281 spin_lock_irq(shost->host_lock);
2282 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
2283 spin_unlock_irq(shost->host_lock);
2284 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
2286 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
2289 phba->fc_stat.elsXmitACC++;
2290 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
2291 if (rc == IOCB_ERROR) {
2292 lpfc_els_free_iocb(phba, elsiocb);
2299 lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
2300 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
2303 struct lpfc_hba *phba = vport->phba;
2306 struct lpfc_iocbq *elsiocb;
2307 struct lpfc_sli_ring *pring;
2308 struct lpfc_sli *psli;
2314 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2316 cmdsize = 2 * sizeof(uint32_t);
2317 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
2318 ndlp->nlp_DID, ELS_CMD_LS_RJT);
2322 icmd = &elsiocb->iocb;
2323 oldcmd = &oldiocb->iocb;
2324 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2325 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2327 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
2328 pcmd += sizeof(uint32_t);
2329 *((uint32_t *) (pcmd)) = rejectError;
2332 elsiocb->context_un.mbox = mbox;
2334 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
2335 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2336 "0129 Xmit ELS RJT x%x response tag x%x "
2337 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
2339 rejectError, elsiocb->iotag,
2340 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
2341 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
2342 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2343 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
2344 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
2346 phba->fc_stat.elsXmitLSRJT++;
2347 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
2348 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
2350 /* If the node is in the UNUSED state, and we are sending
2351 * a reject, we are done with it. Release driver reference
2352 * count here. The outstanding els will release its reference on
2353 * completion and the node can be freed then.
2355 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
2358 if (rc == IOCB_ERROR) {
2359 lpfc_els_free_iocb(phba, elsiocb);
2366 lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
2367 struct lpfc_nodelist *ndlp)
2369 struct lpfc_hba *phba = vport->phba;
2370 struct lpfc_sli *psli = &phba->sli;
2371 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
2373 IOCB_t *icmd, *oldcmd;
2374 struct lpfc_iocbq *elsiocb;
2379 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
2380 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
2381 ndlp->nlp_DID, ELS_CMD_ACC);
2385 icmd = &elsiocb->iocb;
2386 oldcmd = &oldiocb->iocb;
2387 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2389 /* Xmit ADISC ACC response tag <ulpIoTag> */
2390 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2391 "0130 Xmit ADISC ACC response iotag x%x xri: "
2392 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
2393 elsiocb->iotag, elsiocb->iocb.ulpContext,
2394 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2396 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2398 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
2399 pcmd += sizeof(uint32_t);
2401 ap = (ADISC *) (pcmd);
2402 ap->hardAL_PA = phba->fc_pref_ALPA;
2403 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2404 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
2405 ap->DID = be32_to_cpu(vport->fc_myDID);
2407 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2408 "Issue ACC ADISC: did:x%x flg:x%x",
2409 ndlp->nlp_DID, ndlp->nlp_flag, 0);
2411 phba->fc_stat.elsXmitACC++;
2412 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
2413 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
2414 if (rc == IOCB_ERROR) {
2415 lpfc_els_free_iocb(phba, elsiocb);
2422 lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
2423 struct lpfc_nodelist *ndlp)
2425 struct lpfc_hba *phba = vport->phba;
2430 struct lpfc_iocbq *elsiocb;
2431 struct lpfc_sli_ring *pring;
2432 struct lpfc_sli *psli;
2438 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2440 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
2441 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
2442 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
2446 icmd = &elsiocb->iocb;
2447 oldcmd = &oldiocb->iocb;
2448 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2449 /* Xmit PRLI ACC response tag <ulpIoTag> */
2450 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2451 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
2452 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
2453 elsiocb->iotag, elsiocb->iocb.ulpContext,
2454 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2456 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2458 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
2459 pcmd += sizeof(uint32_t);
2461 /* For PRLI, remainder of payload is PRLI parameter page */
2462 memset(pcmd, 0, sizeof(PRLI));
2464 npr = (PRLI *) pcmd;
2467 * If our firmware version is 3.20 or later,
2468 * set the following bits for FC-TAPE support.
2470 if (vpd->rev.feaLevelHigh >= 0x02) {
2471 npr->ConfmComplAllowed = 1;
2473 npr->TaskRetryIdReq = 1;
2476 npr->acceptRspCode = PRLI_REQ_EXECUTED;
2477 npr->estabImagePair = 1;
2478 npr->readXferRdyDis = 1;
2479 npr->ConfmComplAllowed = 1;
2481 npr->prliType = PRLI_FCP_TYPE;
2482 npr->initiatorFunc = 1;
2484 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2485 "Issue ACC PRLI: did:x%x flg:x%x",
2486 ndlp->nlp_DID, ndlp->nlp_flag, 0);
2488 phba->fc_stat.elsXmitACC++;
2489 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
2491 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
2492 if (rc == IOCB_ERROR) {
2493 lpfc_els_free_iocb(phba, elsiocb);
2500 lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
2501 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
2503 struct lpfc_hba *phba = vport->phba;
2505 IOCB_t *icmd, *oldcmd;
2506 struct lpfc_iocbq *elsiocb;
2507 struct lpfc_sli_ring *pring;
2508 struct lpfc_sli *psli;
2514 pring = &psli->ring[LPFC_ELS_RING];
2516 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
2517 + (2 * sizeof(struct lpfc_name));
2519 cmdsize += sizeof(RNID_TOP_DISC);
2521 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
2522 ndlp->nlp_DID, ELS_CMD_ACC);
2526 icmd = &elsiocb->iocb;
2527 oldcmd = &oldiocb->iocb;
2528 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2529 /* Xmit RNID ACC response tag <ulpIoTag> */
2530 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2531 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
2532 elsiocb->iotag, elsiocb->iocb.ulpContext);
2533 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2534 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
2535 pcmd += sizeof(uint32_t);
2537 memset(pcmd, 0, sizeof(RNID));
2538 rn = (RNID *) (pcmd);
2539 rn->Format = format;
2540 rn->CommonLen = (2 * sizeof(struct lpfc_name));
2541 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2542 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
2545 rn->SpecificLen = 0;
2547 case RNID_TOPOLOGY_DISC:
2548 rn->SpecificLen = sizeof(RNID_TOP_DISC);
2549 memcpy(&rn->un.topologyDisc.portName,
2550 &vport->fc_portname, sizeof(struct lpfc_name));
2551 rn->un.topologyDisc.unitType = RNID_HBA;
2552 rn->un.topologyDisc.physPort = 0;
2553 rn->un.topologyDisc.attachedNodes = 0;
2557 rn->SpecificLen = 0;
2561 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2562 "Issue ACC RNID: did:x%x flg:x%x",
2563 ndlp->nlp_DID, ndlp->nlp_flag, 0);
2565 phba->fc_stat.elsXmitACC++;
2566 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
2568 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
2569 * it could be freed */
2571 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
2572 if (rc == IOCB_ERROR) {
2573 lpfc_els_free_iocb(phba, elsiocb);
2580 lpfc_els_disc_adisc(struct lpfc_vport *vport)
2582 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2583 struct lpfc_nodelist *ndlp, *next_ndlp;
2586 /* go thru NPR nodes and issue any remaining ELS ADISCs */
2587 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
2588 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
2589 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
2590 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
2591 spin_lock_irq(shost->host_lock);
2592 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2593 spin_unlock_irq(shost->host_lock);
2594 ndlp->nlp_prev_state = ndlp->nlp_state;
2595 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2596 lpfc_issue_els_adisc(vport, ndlp, 0);
2598 vport->num_disc_nodes++;
2599 if (vport->num_disc_nodes >=
2600 vport->cfg_discovery_threads) {
2601 spin_lock_irq(shost->host_lock);
2602 vport->fc_flag |= FC_NLP_MORE;
2603 spin_unlock_irq(shost->host_lock);
2608 if (sentadisc == 0) {
2609 spin_lock_irq(shost->host_lock);
2610 vport->fc_flag &= ~FC_NLP_MORE;
2611 spin_unlock_irq(shost->host_lock);
2617 lpfc_els_disc_plogi(struct lpfc_vport *vport)
2619 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2620 struct lpfc_nodelist *ndlp, *next_ndlp;
2623 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
2624 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
2625 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
2626 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
2627 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
2628 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
2629 ndlp->nlp_prev_state = ndlp->nlp_state;
2630 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2631 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
2633 vport->num_disc_nodes++;
2634 if (vport->num_disc_nodes >=
2635 vport->cfg_discovery_threads) {
2636 spin_lock_irq(shost->host_lock);
2637 vport->fc_flag |= FC_NLP_MORE;
2638 spin_unlock_irq(shost->host_lock);
2643 if (sentplogi == 0) {
2644 spin_lock_irq(shost->host_lock);
2645 vport->fc_flag &= ~FC_NLP_MORE;
2646 spin_unlock_irq(shost->host_lock);
2652 lpfc_els_flush_rscn(struct lpfc_vport *vport)
2654 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2655 struct lpfc_hba *phba = vport->phba;
2658 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
2659 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
2660 vport->fc_rscn_id_list[i] = NULL;
2662 spin_lock_irq(shost->host_lock);
2663 vport->fc_rscn_id_cnt = 0;
2664 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
2665 spin_unlock_irq(shost->host_lock);
2666 lpfc_can_disctmo(vport);
2670 lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
2675 uint32_t payload_len, i;
2677 ns_did.un.word = did;
2679 /* Never match fabric nodes for RSCNs */
2680 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
2683 /* If we are doing a FULL RSCN rediscovery, match everything */
2684 if (vport->fc_flag & FC_RSCN_DISCOVERY)
2687 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
2688 lp = vport->fc_rscn_id_list[i]->virt;
2689 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
2690 payload_len -= sizeof(uint32_t); /* take off word 0 */
2691 while (payload_len) {
2692 rscn_did.un.word = be32_to_cpu(*lp++);
2693 payload_len -= sizeof(uint32_t);
2694 switch (rscn_did.un.b.resv) {
2695 case 0: /* Single N_Port ID effected */
2696 if (ns_did.un.word == rscn_did.un.word)
2699 case 1: /* Whole N_Port Area effected */
2700 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
2701 && (ns_did.un.b.area == rscn_did.un.b.area))
2704 case 2: /* Whole N_Port Domain effected */
2705 if (ns_did.un.b.domain == rscn_did.un.b.domain)
2709 /* Unknown Identifier in RSCN node */
2710 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
2711 "0217 Unknown Identifier in "
2712 "RSCN payload Data: x%x\n",
2714 case 3: /* Whole Fabric effected */
2723 lpfc_rscn_recovery_check(struct lpfc_vport *vport)
2725 struct lpfc_nodelist *ndlp = NULL;
2727 /* Look at all nodes effected by pending RSCNs and move
2728 * them to NPR state.
2731 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
2732 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE ||
2733 lpfc_rscn_payload_check(vport, ndlp->nlp_DID) == 0)
2736 lpfc_disc_state_machine(vport, ndlp, NULL,
2737 NLP_EVT_DEVICE_RECOVERY);
2740 * Make sure NLP_DELAY_TMO is NOT running after a device
2743 if (ndlp->nlp_flag & NLP_DELAY_TMO)
2744 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2751 lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
2752 struct lpfc_nodelist *ndlp)
2754 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2755 struct lpfc_hba *phba = vport->phba;
2756 struct lpfc_dmabuf *pcmd;
2757 uint32_t *lp, *datap;
2759 uint32_t payload_len, length, nportid, *cmd;
2760 int rscn_cnt = vport->fc_rscn_id_cnt;
2761 int rscn_id = 0, hba_id = 0;
2764 icmd = &cmdiocb->iocb;
2765 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2766 lp = (uint32_t *) pcmd->virt;
2768 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
2769 payload_len -= sizeof(uint32_t); /* take off word 0 */
2771 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2772 "0214 RSCN received Data: x%x x%x x%x x%x\n",
2773 vport->fc_flag, payload_len, *lp, rscn_cnt);
2774 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
2775 fc_host_post_event(shost, fc_get_event_number(),
2776 FCH_EVT_RSCN, lp[i]);
2778 /* If we are about to begin discovery, just ACC the RSCN.
2779 * Discovery processing will satisfy it.
2781 if (vport->port_state <= LPFC_NS_QRY) {
2782 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
2783 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
2784 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
2786 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
2790 /* If this RSCN just contains NPortIDs for other vports on this HBA,
2791 * just ACC and ignore it.
2793 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2794 !(vport->cfg_peer_port_login)) {
2799 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
2800 i -= sizeof(uint32_t);
2802 if (lpfc_find_vport_by_did(phba, nportid))
2805 if (rscn_id == hba_id) {
2806 /* ALL NPortIDs in RSCN are on HBA */
2807 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2809 "Data: x%x x%x x%x x%x\n",
2810 vport->fc_flag, payload_len,
2812 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
2813 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
2814 ndlp->nlp_DID, vport->port_state,
2817 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
2823 /* If we are already processing an RSCN, save the received
2824 * RSCN payload buffer, cmdiocb->context2 to process later.
2826 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
2827 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
2828 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
2829 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
2831 vport->fc_flag |= FC_RSCN_DEFERRED;
2832 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
2833 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
2834 spin_lock_irq(shost->host_lock);
2835 vport->fc_flag |= FC_RSCN_MODE;
2836 spin_unlock_irq(shost->host_lock);
2838 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
2839 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
2842 (payload_len + length <= LPFC_BPL_SIZE)) {
2843 *cmd &= ELS_CMD_MASK;
2844 *cmd |= be32_to_cpu(payload_len + length);
2845 memcpy(((uint8_t *)cmd) + length, lp,
2848 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
2849 vport->fc_rscn_id_cnt++;
2850 /* If we zero, cmdiocb->context2, the calling
2851 * routine will not try to free it.
2853 cmdiocb->context2 = NULL;
2857 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2858 "0235 Deferred RSCN "
2859 "Data: x%x x%x x%x\n",
2860 vport->fc_rscn_id_cnt, vport->fc_flag,
2863 spin_lock_irq(shost->host_lock);
2864 vport->fc_flag |= FC_RSCN_DISCOVERY;
2865 spin_unlock_irq(shost->host_lock);
2866 /* ReDiscovery RSCN */
2867 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2868 "0234 ReDiscovery RSCN "
2869 "Data: x%x x%x x%x\n",
2870 vport->fc_rscn_id_cnt, vport->fc_flag,
2874 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
2876 /* send RECOVERY event for ALL nodes that match RSCN payload */
2877 lpfc_rscn_recovery_check(vport);
2878 vport->fc_flag &= ~FC_RSCN_DEFERRED;
2882 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
2883 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
2884 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
2886 spin_lock_irq(shost->host_lock);
2887 vport->fc_flag |= FC_RSCN_MODE;
2888 spin_unlock_irq(shost->host_lock);
2889 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
2891 * If we zero, cmdiocb->context2, the calling routine will
2892 * not try to free it.
2894 cmdiocb->context2 = NULL;
2896 lpfc_set_disctmo(vport);
2899 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
2901 /* send RECOVERY event for ALL nodes that match RSCN payload */
2902 lpfc_rscn_recovery_check(vport);
2904 return lpfc_els_handle_rscn(vport);
2908 lpfc_els_handle_rscn(struct lpfc_vport *vport)
2910 struct lpfc_nodelist *ndlp;
2911 struct lpfc_hba *phba = vport->phba;
2913 /* Ignore RSCN if the port is being torn down. */
2914 if (vport->load_flag & FC_UNLOADING) {
2915 lpfc_els_flush_rscn(vport);
2919 /* Start timer for RSCN processing */
2920 lpfc_set_disctmo(vport);
2922 /* RSCN processed */
2923 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2924 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
2925 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
2928 /* To process RSCN, first compare RSCN data with NameServer */
2929 vport->fc_ns_retry = 0;
2930 ndlp = lpfc_findnode_did(vport, NameServer_DID);
2931 if (ndlp && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
2932 /* Good ndlp, issue CT Request to NameServer */
2933 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
2934 /* Wait for NameServer query cmpl before we can
2938 /* If login to NameServer does not exist, issue one */
2939 /* Good status, issue PLOGI to NameServer */
2940 ndlp = lpfc_findnode_did(vport, NameServer_DID);
2942 /* Wait for NameServer login cmpl before we can
2946 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2948 lpfc_els_flush_rscn(vport);
2951 lpfc_nlp_init(vport, ndlp, NameServer_DID);
2952 ndlp->nlp_type |= NLP_FABRIC;
2953 ndlp->nlp_prev_state = ndlp->nlp_state;
2954 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2955 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
2956 /* Wait for NameServer login cmpl before we can
2962 lpfc_els_flush_rscn(vport);
2967 lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
2968 struct lpfc_nodelist *ndlp)
2970 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2971 struct lpfc_hba *phba = vport->phba;
2972 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2973 uint32_t *lp = (uint32_t *) pcmd->virt;
2974 IOCB_t *icmd = &cmdiocb->iocb;
2975 struct serv_parm *sp;
2982 sp = (struct serv_parm *) lp;
2984 /* FLOGI received */
2986 lpfc_set_disctmo(vport);
2988 if (phba->fc_topology == TOPOLOGY_LOOP) {
2989 /* We should never receive a FLOGI in loop mode, ignore it */
2990 did = icmd->un.elsreq64.remoteID;
2992 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
2994 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2995 "0113 An FLOGI ELS command x%x was "
2996 "received from DID x%x in Loop Mode\n",
3003 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3))) {
3004 /* For a FLOGI we accept, then if our portname is greater
3005 * then the remote portname we initiate Nport login.
3008 rc = memcmp(&vport->fc_portname, &sp->portName,
3009 sizeof(struct lpfc_name));
3012 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3016 lpfc_linkdown(phba);
3017 lpfc_init_link(phba, mbox,
3019 phba->cfg_link_speed);
3020 mbox->mb.un.varInitLnk.lipsr_AL_PA = 0;
3021 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
3022 mbox->vport = vport;
3023 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
3024 lpfc_set_loopback_flag(phba);
3025 if (rc == MBX_NOT_FINISHED) {
3026 mempool_free(mbox, phba->mbox_mem_pool);
3029 } else if (rc > 0) { /* greater than */
3030 spin_lock_irq(shost->host_lock);
3031 vport->fc_flag |= FC_PT2PT_PLOGI;
3032 spin_unlock_irq(shost->host_lock);
3034 spin_lock_irq(shost->host_lock);
3035 vport->fc_flag |= FC_PT2PT;
3036 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
3037 spin_unlock_irq(shost->host_lock);
3039 /* Reject this request because invalid parameters */
3040 stat.un.b.lsRjtRsvd0 = 0;
3041 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3042 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
3043 stat.un.b.vendorUnique = 0;
3044 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
3050 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
3056 lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3057 struct lpfc_nodelist *ndlp)
3059 struct lpfc_dmabuf *pcmd;
3066 icmd = &cmdiocb->iocb;
3067 did = icmd->un.elsreq64.remoteID;
3068 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3069 lp = (uint32_t *) pcmd->virt;
3076 switch (rn->Format) {
3078 case RNID_TOPOLOGY_DISC:
3080 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
3083 /* Reject this request because format not supported */
3084 stat.un.b.lsRjtRsvd0 = 0;
3085 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3086 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
3087 stat.un.b.vendorUnique = 0;
3088 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
3095 lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3096 struct lpfc_nodelist *ndlp)
3100 /* For now, unconditionally reject this command */
3101 stat.un.b.lsRjtRsvd0 = 0;
3102 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3103 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
3104 stat.un.b.vendorUnique = 0;
3105 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
3110 lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3112 struct lpfc_sli *psli = &phba->sli;
3113 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
3118 struct lpfc_iocbq *elsiocb;
3119 struct lpfc_nodelist *ndlp;
3120 uint16_t xri, status;
3125 ndlp = (struct lpfc_nodelist *) pmb->context2;
3126 xri = (uint16_t) ((unsigned long)(pmb->context1));
3127 pmb->context1 = NULL;
3128 pmb->context2 = NULL;
3130 if (mb->mbxStatus) {
3131 mempool_free(pmb, phba->mbox_mem_pool);
3135 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
3136 mempool_free(pmb, phba->mbox_mem_pool);
3137 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
3138 lpfc_max_els_tries, ndlp,
3139 ndlp->nlp_DID, ELS_CMD_ACC);
3144 icmd = &elsiocb->iocb;
3145 icmd->ulpContext = xri;
3147 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3148 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
3149 pcmd += sizeof(uint32_t); /* Skip past command */
3150 rps_rsp = (RPS_RSP *)pcmd;
3152 if (phba->fc_topology != TOPOLOGY_LOOP)
3156 if (phba->pport->fc_flag & FC_FABRIC)
3160 rps_rsp->portStatus = be16_to_cpu(status);
3161 rps_rsp->linkFailureCnt = be32_to_cpu(mb->un.varRdLnk.linkFailureCnt);
3162 rps_rsp->lossSyncCnt = be32_to_cpu(mb->un.varRdLnk.lossSyncCnt);
3163 rps_rsp->lossSignalCnt = be32_to_cpu(mb->un.varRdLnk.lossSignalCnt);
3164 rps_rsp->primSeqErrCnt = be32_to_cpu(mb->un.varRdLnk.primSeqErrCnt);
3165 rps_rsp->invalidXmitWord = be32_to_cpu(mb->un.varRdLnk.invalidXmitWord);
3166 rps_rsp->crcCnt = be32_to_cpu(mb->un.varRdLnk.crcCnt);
3167 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
3168 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
3169 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
3170 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
3171 elsiocb->iotag, elsiocb->iocb.ulpContext,
3172 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3174 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
3175 phba->fc_stat.elsXmitACC++;
3176 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR)
3177 lpfc_els_free_iocb(phba, elsiocb);
3182 lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3183 struct lpfc_nodelist *ndlp)
3185 struct lpfc_hba *phba = vport->phba;
3189 struct lpfc_dmabuf *pcmd;
3193 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
3194 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
3195 stat.un.b.lsRjtRsvd0 = 0;
3196 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3197 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
3198 stat.un.b.vendorUnique = 0;
3199 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
3203 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3204 lp = (uint32_t *) pcmd->virt;
3205 flag = (be32_to_cpu(*lp++) & 0xf);
3209 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
3210 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
3211 sizeof(struct lpfc_name)) == 0))) {
3213 printk("Fix me....\n");
3215 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
3217 lpfc_read_lnk_stat(phba, mbox);
3219 (void *)((unsigned long) cmdiocb->iocb.ulpContext);
3220 mbox->context2 = lpfc_nlp_get(ndlp);
3221 mbox->vport = vport;
3222 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
3223 if (lpfc_sli_issue_mbox (phba, mbox, MBX_NOWAIT)
3224 != MBX_NOT_FINISHED)
3225 /* Mbox completion will send ELS Response */
3229 mempool_free(mbox, phba->mbox_mem_pool);
3232 stat.un.b.lsRjtRsvd0 = 0;
3233 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3234 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
3235 stat.un.b.vendorUnique = 0;
3236 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
3241 lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
3242 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
3244 struct lpfc_hba *phba = vport->phba;
3245 IOCB_t *icmd, *oldcmd;
3247 struct lpfc_iocbq *elsiocb;
3248 struct lpfc_sli *psli = &phba->sli;
3249 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
3252 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3253 ndlp->nlp_DID, ELS_CMD_ACC);
3258 icmd = &elsiocb->iocb;
3259 oldcmd = &oldiocb->iocb;
3260 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3262 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3263 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
3264 pcmd += sizeof(uint16_t);
3265 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
3266 pcmd += sizeof(uint16_t);
3268 /* Setup the RPL ACC payload */
3269 rpl_rsp.listLen = be32_to_cpu(1);
3271 rpl_rsp.port_num_blk.portNum = 0;
3272 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
3273 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
3274 sizeof(struct lpfc_name));
3275 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
3276 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
3277 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3278 "0120 Xmit ELS RPL ACC response tag x%x "
3279 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
3281 elsiocb->iotag, elsiocb->iocb.ulpContext,
3282 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3284 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
3285 phba->fc_stat.elsXmitACC++;
3286 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
3287 lpfc_els_free_iocb(phba, elsiocb);
3294 lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3295 struct lpfc_nodelist *ndlp)
3297 struct lpfc_dmabuf *pcmd;
3304 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
3305 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
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,
3314 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3315 lp = (uint32_t *) pcmd->virt;
3316 rpl = (RPL *) (lp + 1);
3318 maxsize = be32_to_cpu(rpl->maxsize);
3320 /* We support only one port */
3321 if ((rpl->index == 0) &&
3323 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
3324 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
3326 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
3328 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
3334 lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3335 struct lpfc_nodelist *ndlp)
3337 struct lpfc_dmabuf *pcmd;
3341 uint32_t cmd, cnt, did;
3343 icmd = &cmdiocb->iocb;
3344 did = icmd->un.elsreq64.remoteID;
3345 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3346 lp = (uint32_t *) pcmd->virt;
3350 /* FARP-REQ received from DID <did> */
3351 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3352 "0601 FARP-REQ received from DID x%x\n", did);
3353 /* We will only support match on WWPN or WWNN */
3354 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
3359 /* If this FARP command is searching for my portname */
3360 if (fp->Mflags & FARP_MATCH_PORT) {
3361 if (memcmp(&fp->RportName, &vport->fc_portname,
3362 sizeof(struct lpfc_name)) == 0)
3366 /* If this FARP command is searching for my nodename */
3367 if (fp->Mflags & FARP_MATCH_NODE) {
3368 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
3369 sizeof(struct lpfc_name)) == 0)
3374 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
3375 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
3376 /* Log back into the node before sending the FARP. */
3377 if (fp->Rflags & FARP_REQUEST_PLOGI) {
3378 ndlp->nlp_prev_state = ndlp->nlp_state;
3379 lpfc_nlp_set_state(vport, ndlp,
3380 NLP_STE_PLOGI_ISSUE);
3381 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
3384 /* Send a FARP response to that node */
3385 if (fp->Rflags & FARP_REQUEST_FARPR)
3386 lpfc_issue_els_farpr(vport, did, 0);
3393 lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3394 struct lpfc_nodelist *ndlp)
3396 struct lpfc_dmabuf *pcmd;
3401 icmd = &cmdiocb->iocb;
3402 did = icmd->un.elsreq64.remoteID;
3403 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3404 lp = (uint32_t *) pcmd->virt;
3407 /* FARP-RSP received from DID <did> */
3408 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3409 "0600 FARP-RSP received from DID x%x\n", did);
3410 /* ACCEPT the Farp resp request */
3411 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
3417 lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3418 struct lpfc_nodelist *fan_ndlp)
3420 struct lpfc_dmabuf *pcmd;
3425 struct lpfc_nodelist *ndlp, *next_ndlp;
3426 struct lpfc_hba *phba = vport->phba;
3429 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3430 "0265 FAN received\n");
3431 icmd = &cmdiocb->iocb;
3432 did = icmd->un.elsreq64.remoteID;
3433 pcmd = (struct lpfc_dmabuf *)cmdiocb->context2;
3434 lp = (uint32_t *)pcmd->virt;
3439 /* FAN received; Fan does not have a reply sequence */
3441 if (phba->pport->port_state == LPFC_LOCAL_CFG_LINK) {
3442 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
3443 sizeof(struct lpfc_name)) != 0) ||
3444 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
3445 sizeof(struct lpfc_name)) != 0)) {
3447 * This node has switched fabrics. FLOGI is required
3448 * Clean up the old rpi's
3451 list_for_each_entry_safe(ndlp, next_ndlp,
3452 &vport->fc_nodes, nlp_listp) {
3453 if (ndlp->nlp_state != NLP_STE_NPR_NODE)
3455 if (ndlp->nlp_type & NLP_FABRIC) {
3457 * Clean up old Fabric, Nameserver and
3458 * other NLP_FABRIC logins
3460 lpfc_drop_node(vport, ndlp);
3461 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
3462 /* Fail outstanding I/O now since this
3463 * device is marked for PLOGI
3465 lpfc_unreg_rpi(vport, ndlp);
3469 vport->port_state = LPFC_FLOGI;
3470 lpfc_set_disctmo(vport);
3471 lpfc_initial_flogi(vport);
3474 /* Discovery not needed,
3475 * move the nodes to their original state.
3477 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
3479 if (ndlp->nlp_state != NLP_STE_NPR_NODE)
3482 switch (ndlp->nlp_prev_state) {
3483 case NLP_STE_UNMAPPED_NODE:
3484 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
3485 lpfc_nlp_set_state(vport, ndlp,
3486 NLP_STE_UNMAPPED_NODE);
3489 case NLP_STE_MAPPED_NODE:
3490 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
3491 lpfc_nlp_set_state(vport, ndlp,
3492 NLP_STE_MAPPED_NODE);
3500 /* Start discovery - this should just do CLEAR_LA */
3501 lpfc_disc_start(vport);
3507 lpfc_els_timeout(unsigned long ptr)
3509 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
3510 struct lpfc_hba *phba = vport->phba;
3511 unsigned long iflag;
3513 spin_lock_irqsave(&vport->work_port_lock, iflag);
3514 if ((vport->work_port_events & WORKER_ELS_TMO) == 0) {
3515 vport->work_port_events |= WORKER_ELS_TMO;
3516 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
3518 spin_lock_irqsave(&phba->hbalock, iflag);
3519 if (phba->work_wait)
3520 lpfc_worker_wake_up(phba);
3521 spin_unlock_irqrestore(&phba->hbalock, iflag);
3524 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
3529 lpfc_els_timeout_handler(struct lpfc_vport *vport)
3531 struct lpfc_hba *phba = vport->phba;
3532 struct lpfc_sli_ring *pring;
3533 struct lpfc_iocbq *tmp_iocb, *piocb;
3535 struct lpfc_dmabuf *pcmd;
3536 uint32_t els_command = 0;
3538 uint32_t remote_ID = 0xffffffff;
3540 /* If the timer is already canceled do nothing */
3541 if ((vport->work_port_events & WORKER_ELS_TMO) == 0) {
3544 spin_lock_irq(&phba->hbalock);
3545 timeout = (uint32_t)(phba->fc_ratov << 1);
3547 pring = &phba->sli.ring[LPFC_ELS_RING];
3549 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
3552 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
3553 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
3554 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
3557 if (piocb->vport != vport)
3560 pcmd = (struct lpfc_dmabuf *) piocb->context2;
3562 els_command = *(uint32_t *) (pcmd->virt);
3564 if (els_command == ELS_CMD_FARP ||
3565 els_command == ELS_CMD_FARPR ||
3566 els_command == ELS_CMD_FDISC)
3569 if (vport != piocb->vport)
3572 if (piocb->drvrTimeout > 0) {
3573 if (piocb->drvrTimeout >= timeout)
3574 piocb->drvrTimeout -= timeout;
3576 piocb->drvrTimeout = 0;
3580 remote_ID = 0xffffffff;
3581 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
3582 remote_ID = cmd->un.elsreq64.remoteID;
3584 struct lpfc_nodelist *ndlp;
3585 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
3587 remote_ID = ndlp->nlp_DID;
3589 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3590 "0127 ELS timeout Data: x%x x%x x%x "
3591 "x%x\n", els_command,
3592 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
3593 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
3595 spin_unlock_irq(&phba->hbalock);
3597 if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt)
3598 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
3602 lpfc_els_flush_cmd(struct lpfc_vport *vport)
3604 LIST_HEAD(completions);
3605 struct lpfc_hba *phba = vport->phba;
3606 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
3607 struct lpfc_iocbq *tmp_iocb, *piocb;
3610 lpfc_fabric_abort_vport(vport);
3612 spin_lock_irq(&phba->hbalock);
3613 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
3616 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
3620 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
3621 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
3622 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
3623 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
3624 cmd->ulpCommand == CMD_ABORT_XRI_CN)
3627 if (piocb->vport != vport)
3630 list_move_tail(&piocb->list, &completions);
3634 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
3635 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
3639 if (piocb->vport != vport)
3642 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
3644 spin_unlock_irq(&phba->hbalock);
3646 while (!list_empty(&completions)) {
3647 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
3649 list_del_init(&piocb->list);
3651 if (!piocb->iocb_cmpl)
3652 lpfc_sli_release_iocbq(phba, piocb);
3654 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
3655 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
3656 (piocb->iocb_cmpl) (phba, piocb, piocb);
3664 lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
3666 LIST_HEAD(completions);
3667 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
3668 struct lpfc_iocbq *tmp_iocb, *piocb;
3671 lpfc_fabric_abort_hba(phba);
3672 spin_lock_irq(&phba->hbalock);
3673 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
3675 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
3677 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
3678 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
3679 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
3680 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
3681 cmd->ulpCommand == CMD_ABORT_XRI_CN)
3683 list_move_tail(&piocb->list, &completions);
3686 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
3687 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
3689 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
3691 spin_unlock_irq(&phba->hbalock);
3692 while (!list_empty(&completions)) {
3693 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
3695 list_del_init(&piocb->list);
3696 if (!piocb->iocb_cmpl)
3697 lpfc_sli_release_iocbq(phba, piocb);
3699 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
3700 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
3701 (piocb->iocb_cmpl) (phba, piocb, piocb);
3708 lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3709 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
3711 struct lpfc_nodelist *ndlp;
3714 uint32_t cmd, did, newnode, rjt_err = 0;
3715 IOCB_t *icmd = &elsiocb->iocb;
3717 if (vport == NULL || elsiocb->context2 == NULL)
3721 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
3723 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
3724 lpfc_post_buffer(phba, pring, 1, 1);
3726 did = icmd->un.rcvels.remoteID;
3727 if (icmd->ulpStatus) {
3728 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3729 "RCV Unsol ELS: status:x%x/x%x did:x%x",
3730 icmd->ulpStatus, icmd->un.ulpWord[4], did);
3734 /* Check to see if link went down during discovery */
3735 if (lpfc_els_chk_latt(vport))
3738 /* Ignore traffic recevied during vport shutdown. */
3739 if (vport->load_flag & FC_UNLOADING)
3742 ndlp = lpfc_findnode_did(vport, did);
3744 /* Cannot find existing Fabric ndlp, so allocate a new one */
3745 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
3749 lpfc_nlp_init(vport, ndlp, did);
3751 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) {
3752 ndlp->nlp_type |= NLP_FABRIC;
3754 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE);
3757 phba->fc_stat.elsRcvFrame++;
3758 if (elsiocb->context1)
3759 lpfc_nlp_put(elsiocb->context1);
3760 elsiocb->context1 = lpfc_nlp_get(ndlp);
3761 elsiocb->vport = vport;
3763 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
3764 cmd &= ELS_CMD_MASK;
3766 /* ELS command <elsCmd> received from NPORT <did> */
3767 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3768 "0112 ELS command x%x received from NPORT x%x "
3769 "Data: x%x\n", cmd, did, vport->port_state);
3772 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3773 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
3774 did, vport->port_state, ndlp->nlp_flag);
3776 phba->fc_stat.elsRcvPLOGI++;
3777 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
3779 if (vport->port_state < LPFC_DISC_AUTH) {
3780 rjt_err = LSRJT_UNABLE_TPC;
3783 lpfc_disc_state_machine(vport, ndlp, elsiocb,
3788 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3789 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
3790 did, vport->port_state, ndlp->nlp_flag);
3792 phba->fc_stat.elsRcvFLOGI++;
3793 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
3795 lpfc_drop_node(vport, ndlp);
3798 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3799 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
3800 did, vport->port_state, ndlp->nlp_flag);
3802 phba->fc_stat.elsRcvLOGO++;
3803 if (vport->port_state < LPFC_DISC_AUTH) {
3804 rjt_err = LSRJT_UNABLE_TPC;
3807 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
3810 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3811 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
3812 did, vport->port_state, ndlp->nlp_flag);
3814 phba->fc_stat.elsRcvPRLO++;
3815 if (vport->port_state < LPFC_DISC_AUTH) {
3816 rjt_err = LSRJT_UNABLE_TPC;
3819 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
3822 phba->fc_stat.elsRcvRSCN++;
3823 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
3825 lpfc_drop_node(vport, ndlp);
3828 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3829 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
3830 did, vport->port_state, ndlp->nlp_flag);
3832 phba->fc_stat.elsRcvADISC++;
3833 if (vport->port_state < LPFC_DISC_AUTH) {
3834 rjt_err = LSRJT_UNABLE_TPC;
3837 lpfc_disc_state_machine(vport, ndlp, elsiocb,
3841 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3842 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
3843 did, vport->port_state, ndlp->nlp_flag);
3845 phba->fc_stat.elsRcvPDISC++;
3846 if (vport->port_state < LPFC_DISC_AUTH) {
3847 rjt_err = LSRJT_UNABLE_TPC;
3850 lpfc_disc_state_machine(vport, ndlp, elsiocb,
3854 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3855 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
3856 did, vport->port_state, ndlp->nlp_flag);
3858 phba->fc_stat.elsRcvFARPR++;
3859 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
3862 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3863 "RCV FARP: did:x%x/ste:x%x flg:x%x",
3864 did, vport->port_state, ndlp->nlp_flag);
3866 phba->fc_stat.elsRcvFARP++;
3867 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
3870 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3871 "RCV FAN: did:x%x/ste:x%x flg:x%x",
3872 did, vport->port_state, ndlp->nlp_flag);
3874 phba->fc_stat.elsRcvFAN++;
3875 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
3878 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3879 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
3880 did, vport->port_state, ndlp->nlp_flag);
3882 phba->fc_stat.elsRcvPRLI++;
3883 if (vport->port_state < LPFC_DISC_AUTH) {
3884 rjt_err = LSRJT_UNABLE_TPC;
3887 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
3890 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3891 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
3892 did, vport->port_state, ndlp->nlp_flag);
3894 phba->fc_stat.elsRcvLIRR++;
3895 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
3897 lpfc_drop_node(vport, ndlp);
3900 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3901 "RCV RPS: did:x%x/ste:x%x flg:x%x",
3902 did, vport->port_state, ndlp->nlp_flag);
3904 phba->fc_stat.elsRcvRPS++;
3905 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
3907 lpfc_drop_node(vport, ndlp);
3910 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3911 "RCV RPL: did:x%x/ste:x%x flg:x%x",
3912 did, vport->port_state, ndlp->nlp_flag);
3914 phba->fc_stat.elsRcvRPL++;
3915 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
3917 lpfc_drop_node(vport, ndlp);
3920 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3921 "RCV RNID: did:x%x/ste:x%x flg:x%x",
3922 did, vport->port_state, ndlp->nlp_flag);
3924 phba->fc_stat.elsRcvRNID++;
3925 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
3927 lpfc_drop_node(vport, ndlp);
3930 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3931 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
3932 cmd, did, vport->port_state);
3934 /* Unsupported ELS command, reject */
3935 rjt_err = LSRJT_INVALID_CMD;
3937 /* Unknown ELS command <elsCmd> received from NPORT <did> */
3938 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3939 "0115 Unknown ELS command x%x "
3940 "received from NPORT x%x\n", cmd, did);
3942 lpfc_drop_node(vport, ndlp);
3946 /* check if need to LS_RJT received ELS cmd */
3948 memset(&stat, 0, sizeof(stat));
3949 stat.un.b.lsRjtRsnCode = rjt_err;
3950 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
3951 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
3958 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
3959 "(%d):0111 Dropping received ELS cmd "
3960 "Data: x%x x%x x%x\n",
3961 vport ? vport->vpi : 0xffff, icmd->ulpStatus,
3962 icmd->un.ulpWord[4], icmd->ulpTimeout);
3963 phba->fc_stat.elsRcvDrop++;
3966 static struct lpfc_vport *
3967 lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
3969 struct lpfc_vport *vport;
3970 unsigned long flags;
3972 spin_lock_irqsave(&phba->hbalock, flags);
3973 list_for_each_entry(vport, &phba->port_list, listentry) {
3974 if (vport->vpi == vpi) {
3975 spin_unlock_irqrestore(&phba->hbalock, flags);
3979 spin_unlock_irqrestore(&phba->hbalock, flags);
3984 lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3985 struct lpfc_iocbq *elsiocb)
3987 struct lpfc_vport *vport = phba->pport;
3988 IOCB_t *icmd = &elsiocb->iocb;
3990 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
3991 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
3993 elsiocb->context2 = NULL;
3994 elsiocb->context3 = NULL;
3996 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
3997 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
3998 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
3999 (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) {
4000 phba->fc_stat.NoRcvBuf++;
4001 /* Not enough posted buffers; Try posting more buffers */
4002 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
4003 lpfc_post_buffer(phba, pring, 0, 1);
4007 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
4008 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
4009 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
4010 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
4011 vport = phba->pport;
4013 uint16_t vpi = icmd->unsli3.rcvsli3.vpi;
4014 vport = lpfc_find_vport_by_vpid(phba, vpi);
4017 /* If there are no BDEs associated
4018 * with this IOCB, there is nothing to do.
4020 if (icmd->ulpBdeCount == 0)
4023 /* type of ELS cmd is first 32bit word
4026 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
4027 elsiocb->context2 = bdeBuf1;
4029 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
4030 icmd->un.cont64[0].addrLow);
4031 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
4035 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
4037 * The different unsolicited event handlers would tell us
4038 * if they are done with "mp" by setting context2 to NULL.
4040 lpfc_nlp_put(elsiocb->context1);
4041 elsiocb->context1 = NULL;
4042 if (elsiocb->context2) {
4043 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
4044 elsiocb->context2 = NULL;
4047 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
4048 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
4049 icmd->ulpBdeCount == 2) {
4050 elsiocb->context2 = bdeBuf2;
4051 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
4052 /* free mp if we are done with it */
4053 if (elsiocb->context2) {
4054 lpfc_in_buf_free(phba, elsiocb->context2);
4055 elsiocb->context2 = NULL;
4061 lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
4063 struct lpfc_nodelist *ndlp, *ndlp_fdmi;
4065 ndlp = lpfc_findnode_did(vport, NameServer_DID);
4067 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
4069 if (phba->fc_topology == TOPOLOGY_LOOP) {
4070 lpfc_disc_start(vport);
4073 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4074 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4075 "0251 NameServer login: no memory\n");
4078 lpfc_nlp_init(vport, ndlp, NameServer_DID);
4079 ndlp->nlp_type |= NLP_FABRIC;
4082 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
4084 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
4085 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4086 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4087 "0252 Cannot issue NameServer login\n");
4091 if (vport->cfg_fdmi_on) {
4092 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
4095 lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
4096 ndlp_fdmi->nlp_type |= NLP_FABRIC;
4097 ndlp_fdmi->nlp_state =
4098 NLP_STE_PLOGI_ISSUE;
4099 lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID,
4107 lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4109 struct lpfc_vport *vport = pmb->vport;
4110 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4111 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
4112 MAILBOX_t *mb = &pmb->mb;
4114 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
4117 if (mb->mbxStatus) {
4118 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
4119 "0915 Register VPI failed: 0x%x\n",
4122 switch (mb->mbxStatus) {
4123 case 0x11: /* unsupported feature */
4124 case 0x9603: /* max_vpi exceeded */
4125 /* giving up on vport registration */
4126 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4127 spin_lock_irq(shost->host_lock);
4128 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
4129 spin_unlock_irq(shost->host_lock);
4130 lpfc_can_disctmo(vport);
4133 /* Try to recover from this error */
4134 lpfc_mbx_unreg_vpi(vport);
4135 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
4136 lpfc_initial_fdisc(vport);
4141 if (vport == phba->pport)
4142 lpfc_issue_fabric_reglogin(vport);
4144 lpfc_do_scr_ns_plogi(phba, vport);
4146 mempool_free(pmb, phba->mbox_mem_pool);
4151 lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
4152 struct lpfc_nodelist *ndlp)
4156 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4158 lpfc_reg_vpi(phba, vport->vpi, vport->fc_myDID, mbox);
4159 mbox->vport = vport;
4160 mbox->context2 = lpfc_nlp_get(ndlp);
4161 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
4162 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
4163 == MBX_NOT_FINISHED) {
4164 mempool_free(mbox, phba->mbox_mem_pool);
4165 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
4167 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4168 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
4169 "0253 Register VPI: Can't send mbox\n");
4172 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4174 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
4175 "0254 Register VPI: no memory\n");
4177 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
4183 lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4184 struct lpfc_iocbq *rspiocb)
4186 struct lpfc_vport *vport = cmdiocb->vport;
4187 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4188 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
4189 struct lpfc_nodelist *np;
4190 struct lpfc_nodelist *next_np;
4191 IOCB_t *irsp = &rspiocb->iocb;
4192 struct lpfc_iocbq *piocb;
4194 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4195 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
4196 irsp->ulpStatus, irsp->un.ulpWord[4],
4198 /* Since all FDISCs are being single threaded, we
4199 * must reset the discovery timer for ALL vports
4200 * waiting to send FDISC when one completes.
4202 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
4203 lpfc_set_disctmo(piocb->vport);
4206 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4207 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
4208 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
4210 if (irsp->ulpStatus) {
4211 /* Check for retry */
4212 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
4215 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4216 "0124 FDISC failed. (%d/%d)\n",
4217 irsp->ulpStatus, irsp->un.ulpWord[4]);
4218 if (vport->fc_vport->vport_state == FC_VPORT_INITIALIZING)
4219 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4222 /* giving up on FDISC. Cancel discovery timer */
4223 lpfc_can_disctmo(vport);
4225 spin_lock_irq(shost->host_lock);
4226 vport->fc_flag |= FC_FABRIC;
4227 if (vport->phba->fc_topology == TOPOLOGY_LOOP)
4228 vport->fc_flag |= FC_PUBLIC_LOOP;
4229 spin_unlock_irq(shost->host_lock);
4231 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
4232 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
4233 if ((vport->fc_prevDID != vport->fc_myDID) &&
4234 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
4235 /* If our NportID changed, we need to ensure all
4236 * remaining NPORTs get unreg_login'ed so we can
4239 list_for_each_entry_safe(np, next_np,
4240 &vport->fc_nodes, nlp_listp) {
4241 if (np->nlp_state != NLP_STE_NPR_NODE
4242 || !(np->nlp_flag & NLP_NPR_ADISC))
4244 spin_lock_irq(shost->host_lock);
4245 np->nlp_flag &= ~NLP_NPR_ADISC;
4246 spin_unlock_irq(shost->host_lock);
4247 lpfc_unreg_rpi(vport, np);
4249 lpfc_mbx_unreg_vpi(vport);
4250 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
4253 if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
4254 lpfc_register_new_vport(phba, vport, ndlp);
4256 lpfc_do_scr_ns_plogi(phba, vport);
4258 lpfc_nlp_put(ndlp); /* Free Fabric ndlp for vports */
4262 lpfc_els_free_iocb(phba, cmdiocb);
4266 lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4269 struct lpfc_hba *phba = vport->phba;
4271 struct lpfc_iocbq *elsiocb;
4272 struct serv_parm *sp;
4275 int did = ndlp->nlp_DID;
4278 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
4279 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
4282 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4283 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4284 "0255 Issue FDISC: no IOCB\n");
4288 icmd = &elsiocb->iocb;
4289 icmd->un.elsreq64.myID = 0;
4290 icmd->un.elsreq64.fl = 1;
4292 /* For FDISC, Let FDISC rsp set the NPortID for this VPI */
4296 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4297 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
4298 pcmd += sizeof(uint32_t); /* CSP Word 1 */
4299 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
4300 sp = (struct serv_parm *) pcmd;
4301 /* Setup CSPs accordingly for Fabric */
4302 sp->cmn.e_d_tov = 0;
4303 sp->cmn.w2.r_a_tov = 0;
4304 sp->cls1.classValid = 0;
4305 sp->cls2.seqDelivery = 1;
4306 sp->cls3.seqDelivery = 1;
4308 pcmd += sizeof(uint32_t); /* CSP Word 2 */
4309 pcmd += sizeof(uint32_t); /* CSP Word 3 */
4310 pcmd += sizeof(uint32_t); /* CSP Word 4 */
4311 pcmd += sizeof(uint32_t); /* Port Name */
4312 memcpy(pcmd, &vport->fc_portname, 8);
4313 pcmd += sizeof(uint32_t); /* Node Name */
4314 pcmd += sizeof(uint32_t); /* Node Name */
4315 memcpy(pcmd, &vport->fc_nodename, 8);
4317 lpfc_set_disctmo(vport);
4319 phba->fc_stat.elsXmitFDISC++;
4320 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
4322 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4323 "Issue FDISC: did:x%x",
4326 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
4327 if (rc == IOCB_ERROR) {
4328 lpfc_els_free_iocb(phba, elsiocb);
4329 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4330 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4331 "0256 Issue FDISC: Cannot send IOCB\n");
4334 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
4335 vport->port_state = LPFC_FDISC;
4340 lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4341 struct lpfc_iocbq *rspiocb)
4343 struct lpfc_vport *vport = cmdiocb->vport;
4346 irsp = &rspiocb->iocb;
4347 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4348 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
4349 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
4351 lpfc_els_free_iocb(phba, cmdiocb);
4352 vport->unreg_vpi_cmpl = VPORT_ERROR;
4356 lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4358 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4359 struct lpfc_hba *phba = vport->phba;
4360 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
4362 struct lpfc_iocbq *elsiocb;
4366 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
4367 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
4372 icmd = &elsiocb->iocb;
4373 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4374 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
4375 pcmd += sizeof(uint32_t);
4377 /* Fill in LOGO payload */
4378 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
4379 pcmd += sizeof(uint32_t);
4380 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
4382 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4383 "Issue LOGO npiv did:x%x flg:x%x",
4384 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4386 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
4387 spin_lock_irq(shost->host_lock);
4388 ndlp->nlp_flag |= NLP_LOGO_SND;
4389 spin_unlock_irq(shost->host_lock);
4390 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
4391 spin_lock_irq(shost->host_lock);
4392 ndlp->nlp_flag &= ~NLP_LOGO_SND;
4393 spin_unlock_irq(shost->host_lock);
4394 lpfc_els_free_iocb(phba, elsiocb);
4401 lpfc_fabric_block_timeout(unsigned long ptr)
4403 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
4404 unsigned long iflags;
4405 uint32_t tmo_posted;
4406 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
4407 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
4409 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
4410 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
4413 spin_lock_irqsave(&phba->hbalock, iflags);
4414 if (phba->work_wait)
4415 lpfc_worker_wake_up(phba);
4416 spin_unlock_irqrestore(&phba->hbalock, iflags);
4421 lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
4423 struct lpfc_iocbq *iocb;
4424 unsigned long iflags;
4426 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
4431 spin_lock_irqsave(&phba->hbalock, iflags);
4432 /* Post any pending iocb to the SLI layer */
4433 if (atomic_read(&phba->fabric_iocb_count) == 0) {
4434 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
4437 atomic_inc(&phba->fabric_iocb_count);
4439 spin_unlock_irqrestore(&phba->hbalock, iflags);
4441 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
4442 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
4443 iocb->iocb_flag |= LPFC_IO_FABRIC;
4445 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
4446 "Fabric sched1: ste:x%x",
4447 iocb->vport->port_state, 0, 0);
4449 ret = lpfc_sli_issue_iocb(phba, pring, iocb, 0);
4451 if (ret == IOCB_ERROR) {
4452 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
4453 iocb->fabric_iocb_cmpl = NULL;
4454 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
4456 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
4457 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
4458 iocb->iocb_cmpl(phba, iocb, iocb);
4460 atomic_dec(&phba->fabric_iocb_count);
4469 lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
4471 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
4473 lpfc_resume_fabric_iocbs(phba);
4478 lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
4482 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
4483 /* Start a timer to unblock fabric
4487 mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 );
4493 lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4494 struct lpfc_iocbq *rspiocb)
4498 if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
4501 switch (rspiocb->iocb.ulpStatus) {
4502 case IOSTAT_NPORT_RJT:
4503 case IOSTAT_FABRIC_RJT:
4504 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
4505 lpfc_block_fabric_iocbs(phba);
4509 case IOSTAT_NPORT_BSY:
4510 case IOSTAT_FABRIC_BSY:
4511 lpfc_block_fabric_iocbs(phba);
4515 stat.un.lsRjtError =
4516 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
4517 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
4518 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
4519 lpfc_block_fabric_iocbs(phba);
4523 if (atomic_read(&phba->fabric_iocb_count) == 0)
4526 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
4527 cmdiocb->fabric_iocb_cmpl = NULL;
4528 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
4529 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
4531 atomic_dec(&phba->fabric_iocb_count);
4532 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
4533 /* Post any pending iocbs to HBA */
4534 lpfc_resume_fabric_iocbs(phba);
4539 lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
4541 unsigned long iflags;
4542 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
4546 if (atomic_read(&phba->fabric_iocb_count) > 1)
4549 spin_lock_irqsave(&phba->hbalock, iflags);
4550 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
4551 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
4553 spin_unlock_irqrestore(&phba->hbalock, iflags);
4555 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
4556 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
4557 iocb->iocb_flag |= LPFC_IO_FABRIC;
4559 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
4560 "Fabric sched2: ste:x%x",
4561 iocb->vport->port_state, 0, 0);
4563 atomic_inc(&phba->fabric_iocb_count);
4564 ret = lpfc_sli_issue_iocb(phba, pring, iocb, 0);
4566 if (ret == IOCB_ERROR) {
4567 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
4568 iocb->fabric_iocb_cmpl = NULL;
4569 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
4570 atomic_dec(&phba->fabric_iocb_count);
4573 spin_lock_irqsave(&phba->hbalock, iflags);
4574 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
4575 spin_unlock_irqrestore(&phba->hbalock, iflags);
4582 void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
4584 LIST_HEAD(completions);
4585 struct lpfc_hba *phba = vport->phba;
4586 struct lpfc_iocbq *tmp_iocb, *piocb;
4589 spin_lock_irq(&phba->hbalock);
4590 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
4593 if (piocb->vport != vport)
4596 list_move_tail(&piocb->list, &completions);
4598 spin_unlock_irq(&phba->hbalock);
4600 while (!list_empty(&completions)) {
4601 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
4602 list_del_init(&piocb->list);
4605 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
4606 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
4607 (piocb->iocb_cmpl) (phba, piocb, piocb);
4611 void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
4613 LIST_HEAD(completions);
4614 struct lpfc_hba *phba = ndlp->vport->phba;
4615 struct lpfc_iocbq *tmp_iocb, *piocb;
4616 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
4619 spin_lock_irq(&phba->hbalock);
4620 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
4622 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
4624 list_move_tail(&piocb->list, &completions);
4627 spin_unlock_irq(&phba->hbalock);
4629 while (!list_empty(&completions)) {
4630 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
4631 list_del_init(&piocb->list);
4634 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
4635 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
4636 (piocb->iocb_cmpl) (phba, piocb, piocb);
4640 void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
4642 LIST_HEAD(completions);
4643 struct lpfc_iocbq *piocb;
4646 spin_lock_irq(&phba->hbalock);
4647 list_splice_init(&phba->fabric_iocb_list, &completions);
4648 spin_unlock_irq(&phba->hbalock);
4650 while (!list_empty(&completions)) {
4651 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
4652 list_del_init(&piocb->list);
4655 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
4656 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
4657 (piocb->iocb_cmpl) (phba, piocb, piocb);
4662 void lpfc_fabric_abort_flogi(struct lpfc_hba *phba)
4664 LIST_HEAD(completions);
4665 struct lpfc_iocbq *tmp_iocb, *piocb;
4667 struct lpfc_nodelist *ndlp;
4669 spin_lock_irq(&phba->hbalock);
4670 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
4674 ndlp = (struct lpfc_nodelist *) piocb->context1;
4675 if (cmd->ulpCommand == CMD_ELS_REQUEST64_CR &&
4677 ndlp->nlp_DID == Fabric_DID)
4678 list_move_tail(&piocb->list, &completions);
4680 spin_unlock_irq(&phba->hbalock);
4682 while (!list_empty(&completions)) {
4683 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
4684 list_del_init(&piocb->list);
4687 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
4688 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
4689 (piocb->iocb_cmpl) (phba, piocb, piocb);