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 *,
45 static void lpfc_fabric_abort_vport(struct lpfc_vport *vport);
46 static int lpfc_issue_els_fdisc(struct lpfc_vport *vport,
47 struct lpfc_nodelist *ndlp, uint8_t retry);
48 static int lpfc_issue_fabric_iocb(struct lpfc_hba *phba,
49 struct lpfc_iocbq *iocb);
50 static void lpfc_register_new_vport(struct lpfc_hba *phba,
51 struct lpfc_vport *vport,
52 struct lpfc_nodelist *ndlp);
54 static int lpfc_max_els_tries = 3;
57 lpfc_els_chk_latt(struct lpfc_vport *vport)
59 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
60 struct lpfc_hba *phba = vport->phba;
63 if (vport->port_state >= LPFC_VPORT_READY ||
64 phba->link_state == LPFC_LINK_DOWN)
67 /* Read the HBA Host Attention Register */
68 ha_copy = readl(phba->HAregaddr);
70 if (!(ha_copy & HA_LATT))
73 /* Pending Link Event during Discovery */
74 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
75 "0237 Pending Link Event during "
76 "Discovery: State x%x\n",
77 phba->pport->port_state);
79 /* CLEAR_LA should re-enable link attention events and
80 * we should then imediately take a LATT event. The
81 * LATT processing should call lpfc_linkdown() which
82 * will cleanup any left over in-progress discovery
85 spin_lock_irq(shost->host_lock);
86 vport->fc_flag |= FC_ABORT_DISCOVERY;
87 spin_unlock_irq(shost->host_lock);
89 if (phba->link_state != LPFC_CLEAR_LA)
90 lpfc_issue_clear_la(phba, vport);
95 static struct lpfc_iocbq *
96 lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp,
97 uint16_t cmdSize, uint8_t retry,
98 struct lpfc_nodelist *ndlp, uint32_t did,
101 struct lpfc_hba *phba = vport->phba;
102 struct lpfc_iocbq *elsiocb;
103 struct lpfc_dmabuf *pcmd, *prsp, *pbuflist;
104 struct ulp_bde64 *bpl;
108 if (!lpfc_is_link_up(phba))
111 /* Allocate buffer for command iocb */
112 elsiocb = lpfc_sli_get_iocbq(phba);
116 icmd = &elsiocb->iocb;
118 /* fill in BDEs for command */
119 /* Allocate buffer for command payload */
120 pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
122 pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys);
123 if (!pcmd || !pcmd->virt) {
126 lpfc_sli_release_iocbq(phba, elsiocb);
130 INIT_LIST_HEAD(&pcmd->list);
132 /* Allocate buffer for response payload */
134 prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
136 prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
138 if (!prsp || !prsp->virt) {
140 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
142 lpfc_sli_release_iocbq(phba, elsiocb);
145 INIT_LIST_HEAD(&prsp->list);
150 /* Allocate buffer for Buffer ptr list */
151 pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
153 pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
155 if (!pbuflist || !pbuflist->virt) {
156 lpfc_sli_release_iocbq(phba, elsiocb);
157 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
158 lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
165 INIT_LIST_HEAD(&pbuflist->list);
167 icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
168 icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
169 icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BDL;
170 icmd->un.elsreq64.remoteID = did; /* DID */
172 icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
173 icmd->ulpCommand = CMD_ELS_REQUEST64_CR;
174 icmd->ulpTimeout = phba->fc_ratov * 2;
176 icmd->un.elsreq64.bdl.bdeSize = sizeof(struct ulp_bde64);
177 icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
179 icmd->ulpBdeCount = 1;
181 icmd->ulpClass = CLASS3;
183 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
184 icmd->un.elsreq64.myID = vport->fc_myDID;
186 /* For ELS_REQUEST64_CR, use the VPI by default */
187 icmd->ulpContext = vport->vpi;
192 bpl = (struct ulp_bde64 *) pbuflist->virt;
193 bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys));
194 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys));
195 bpl->tus.f.bdeSize = cmdSize;
196 bpl->tus.f.bdeFlags = 0;
197 bpl->tus.w = le32_to_cpu(bpl->tus.w);
201 bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys));
202 bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys));
203 bpl->tus.f.bdeSize = FCELSSIZE;
204 bpl->tus.f.bdeFlags = BUFF_USE_RCV;
205 bpl->tus.w = le32_to_cpu(bpl->tus.w);
208 elsiocb->context1 = lpfc_nlp_get(ndlp);
209 elsiocb->context2 = pcmd;
210 elsiocb->context3 = pbuflist;
211 elsiocb->retry = retry;
212 elsiocb->vport = vport;
213 elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
216 list_add(&prsp->list, &pcmd->list);
219 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
220 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
221 "0116 Xmit ELS command x%x to remote "
222 "NPORT x%x I/O tag: x%x, port state: x%x\n",
223 elscmd, did, elsiocb->iotag,
226 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
227 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
228 "0117 Xmit ELS response x%x to remote "
229 "NPORT x%x I/O tag: x%x, size: x%x\n",
230 elscmd, ndlp->nlp_DID, elsiocb->iotag,
238 lpfc_issue_fabric_reglogin(struct lpfc_vport *vport)
240 struct lpfc_hba *phba = vport->phba;
242 struct lpfc_dmabuf *mp;
243 struct lpfc_nodelist *ndlp;
244 struct serv_parm *sp;
248 sp = &phba->fc_fabparam;
249 ndlp = lpfc_findnode_did(vport, Fabric_DID);
255 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
261 vport->port_state = LPFC_FABRIC_CFG_LINK;
262 lpfc_config_link(phba, mbox);
263 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
266 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
267 if (rc == MBX_NOT_FINISHED) {
272 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
277 rc = lpfc_reg_login(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox,
284 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
286 mbox->context2 = lpfc_nlp_get(ndlp);
288 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
289 if (rc == MBX_NOT_FINISHED) {
291 goto fail_issue_reg_login;
296 fail_issue_reg_login:
298 mp = (struct lpfc_dmabuf *) mbox->context1;
299 lpfc_mbuf_free(phba, mp->virt, mp->phys);
302 mempool_free(mbox, phba->mbox_mem_pool);
305 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
306 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
307 "0249 Cannot issue Register Fabric login: Err %d\n", err);
312 lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
313 struct serv_parm *sp, IOCB_t *irsp)
315 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
316 struct lpfc_hba *phba = vport->phba;
317 struct lpfc_nodelist *np;
318 struct lpfc_nodelist *next_np;
320 spin_lock_irq(shost->host_lock);
321 vport->fc_flag |= FC_FABRIC;
322 spin_unlock_irq(shost->host_lock);
324 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
325 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
326 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
328 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
330 if (phba->fc_topology == TOPOLOGY_LOOP) {
331 spin_lock_irq(shost->host_lock);
332 vport->fc_flag |= FC_PUBLIC_LOOP;
333 spin_unlock_irq(shost->host_lock);
336 * If we are a N-port connected to a Fabric, fixup sparam's so
337 * logins to devices on remote loops work.
339 vport->fc_sparam.cmn.altBbCredit = 1;
342 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
343 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
344 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
345 ndlp->nlp_class_sup = 0;
346 if (sp->cls1.classValid)
347 ndlp->nlp_class_sup |= FC_COS_CLASS1;
348 if (sp->cls2.classValid)
349 ndlp->nlp_class_sup |= FC_COS_CLASS2;
350 if (sp->cls3.classValid)
351 ndlp->nlp_class_sup |= FC_COS_CLASS3;
352 if (sp->cls4.classValid)
353 ndlp->nlp_class_sup |= FC_COS_CLASS4;
354 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
355 sp->cmn.bbRcvSizeLsb;
356 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
358 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
359 if (sp->cmn.response_multiple_NPort) {
360 lpfc_printf_vlog(vport, KERN_WARNING,
362 "1816 FLOGI NPIV supported, "
363 "response data 0x%x\n",
364 sp->cmn.response_multiple_NPort);
365 phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
367 /* Because we asked f/w for NPIV it still expects us
368 to call reg_vnpid atleast for the physcial host */
369 lpfc_printf_vlog(vport, KERN_WARNING,
371 "1817 Fabric does not support NPIV "
372 "- configuring single port mode.\n");
373 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
377 if ((vport->fc_prevDID != vport->fc_myDID) &&
378 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
380 /* If our NportID changed, we need to ensure all
381 * remaining NPORTs get unreg_login'ed.
383 list_for_each_entry_safe(np, next_np,
384 &vport->fc_nodes, nlp_listp) {
385 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
386 !(np->nlp_flag & NLP_NPR_ADISC))
388 spin_lock_irq(shost->host_lock);
389 np->nlp_flag &= ~NLP_NPR_ADISC;
390 spin_unlock_irq(shost->host_lock);
391 lpfc_unreg_rpi(vport, np);
393 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
394 lpfc_mbx_unreg_vpi(vport);
395 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
399 ndlp->nlp_sid = irsp->un.ulpWord[4] & Mask_DID;
400 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
402 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
403 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) {
404 lpfc_register_new_vport(phba, vport, ndlp);
407 lpfc_issue_fabric_reglogin(vport);
412 * We FLOGIed into an NPort, initiate pt2pt protocol
415 lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
416 struct serv_parm *sp)
418 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
419 struct lpfc_hba *phba = vport->phba;
423 spin_lock_irq(shost->host_lock);
424 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
425 spin_unlock_irq(shost->host_lock);
427 phba->fc_edtov = FF_DEF_EDTOV;
428 phba->fc_ratov = FF_DEF_RATOV;
429 rc = memcmp(&vport->fc_portname, &sp->portName,
430 sizeof(vport->fc_portname));
432 /* This side will initiate the PLOGI */
433 spin_lock_irq(shost->host_lock);
434 vport->fc_flag |= FC_PT2PT_PLOGI;
435 spin_unlock_irq(shost->host_lock);
438 * N_Port ID cannot be 0, set our to LocalID the other
439 * side will be RemoteID.
444 vport->fc_myDID = PT2PT_LocalID;
446 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
450 lpfc_config_link(phba, mbox);
452 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
454 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
455 if (rc == MBX_NOT_FINISHED) {
456 mempool_free(mbox, phba->mbox_mem_pool);
461 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
464 * Cannot find existing Fabric ndlp, so allocate a
467 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
471 lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID);
474 memcpy(&ndlp->nlp_portname, &sp->portName,
475 sizeof(struct lpfc_name));
476 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
477 sizeof(struct lpfc_name));
478 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
479 spin_lock_irq(shost->host_lock);
480 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
481 spin_unlock_irq(shost->host_lock);
483 /* This side will wait for the PLOGI */
487 spin_lock_irq(shost->host_lock);
488 vport->fc_flag |= FC_PT2PT;
489 spin_unlock_irq(shost->host_lock);
491 /* Start discovery - this should just do CLEAR_LA */
492 lpfc_disc_start(vport);
499 lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
500 struct lpfc_iocbq *rspiocb)
502 struct lpfc_vport *vport = cmdiocb->vport;
503 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
504 IOCB_t *irsp = &rspiocb->iocb;
505 struct lpfc_nodelist *ndlp = cmdiocb->context1;
506 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
507 struct serv_parm *sp;
510 /* Check to see if link went down during discovery */
511 if (lpfc_els_chk_latt(vport)) {
516 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
517 "FLOGI cmpl: status:x%x/x%x state:x%x",
518 irsp->ulpStatus, irsp->un.ulpWord[4],
521 if (irsp->ulpStatus) {
522 /* Check for retry */
523 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
526 /* FLOGI failed, so there is no fabric */
527 spin_lock_irq(shost->host_lock);
528 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
529 spin_unlock_irq(shost->host_lock);
531 /* If private loop, then allow max outstanding els to be
532 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
533 * alpa map would take too long otherwise.
535 if (phba->alpa_map[0] == 0) {
536 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
540 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
541 "0100 FLOGI failure Data: x%x x%x "
543 irsp->ulpStatus, irsp->un.ulpWord[4],
549 * The FLogI succeeded. Sync the data for the CPU before
552 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
554 sp = prsp->virt + sizeof(uint32_t);
556 /* FLOGI completes successfully */
557 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
558 "0101 FLOGI completes sucessfully "
559 "Data: x%x x%x x%x x%x\n",
560 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
561 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution);
563 if (vport->port_state == LPFC_FLOGI) {
565 * If Common Service Parameters indicate Nport
566 * we are point to point, if Fport we are Fabric.
569 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
571 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
580 if (!lpfc_error_lost_link(irsp)) {
581 /* FLOGI failed, so just use loop map to make discovery list */
582 lpfc_disc_list_loopmap(vport);
584 /* Start discovery */
585 lpfc_disc_start(vport);
586 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
587 ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) &&
588 (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) &&
589 (phba->link_state != LPFC_CLEAR_LA)) {
590 /* If FLOGI failed enable link interrupt. */
591 lpfc_issue_clear_la(phba, vport);
594 lpfc_els_free_iocb(phba, cmdiocb);
598 lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
601 struct lpfc_hba *phba = vport->phba;
602 struct serv_parm *sp;
604 struct lpfc_iocbq *elsiocb;
605 struct lpfc_sli_ring *pring;
611 pring = &phba->sli.ring[LPFC_ELS_RING];
613 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
614 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
615 ndlp->nlp_DID, ELS_CMD_FLOGI);
620 icmd = &elsiocb->iocb;
621 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
623 /* For FLOGI request, remainder of payload is service parameters */
624 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
625 pcmd += sizeof(uint32_t);
626 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
627 sp = (struct serv_parm *) pcmd;
629 /* Setup CSPs accordingly for Fabric */
631 sp->cmn.w2.r_a_tov = 0;
632 sp->cls1.classValid = 0;
633 sp->cls2.seqDelivery = 1;
634 sp->cls3.seqDelivery = 1;
635 if (sp->cmn.fcphLow < FC_PH3)
636 sp->cmn.fcphLow = FC_PH3;
637 if (sp->cmn.fcphHigh < FC_PH3)
638 sp->cmn.fcphHigh = FC_PH3;
640 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
641 sp->cmn.request_multiple_Nport = 1;
643 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
648 if (phba->fc_topology != TOPOLOGY_LOOP) {
649 icmd->un.elsreq64.myID = 0;
650 icmd->un.elsreq64.fl = 1;
653 tmo = phba->fc_ratov;
654 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
655 lpfc_set_disctmo(vport);
656 phba->fc_ratov = tmo;
658 phba->fc_stat.elsXmitFLOGI++;
659 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
661 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
662 "Issue FLOGI: opt:x%x",
663 phba->sli3_options, 0, 0);
665 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
666 if (rc == IOCB_ERROR) {
667 lpfc_els_free_iocb(phba, elsiocb);
674 lpfc_els_abort_flogi(struct lpfc_hba *phba)
676 struct lpfc_sli_ring *pring;
677 struct lpfc_iocbq *iocb, *next_iocb;
678 struct lpfc_nodelist *ndlp;
681 /* Abort outstanding I/O on NPort <nlp_DID> */
682 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
683 "0201 Abort outstanding I/O on NPort x%x\n",
686 pring = &phba->sli.ring[LPFC_ELS_RING];
689 * Check the txcmplq for an iocb that matches the nport the driver is
692 spin_lock_irq(&phba->hbalock);
693 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
695 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR &&
696 icmd->un.elsreq64.bdl.ulpIoTag32) {
697 ndlp = (struct lpfc_nodelist *)(iocb->context1);
698 if (ndlp && (ndlp->nlp_DID == Fabric_DID)) {
699 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
703 spin_unlock_irq(&phba->hbalock);
709 lpfc_initial_flogi(struct lpfc_vport *vport)
711 struct lpfc_hba *phba = vport->phba;
712 struct lpfc_nodelist *ndlp;
714 vport->port_state = LPFC_FLOGI;
715 lpfc_set_disctmo(vport);
717 /* First look for the Fabric ndlp */
718 ndlp = lpfc_findnode_did(vport, Fabric_DID);
720 /* Cannot find existing Fabric ndlp, so allocate a new one */
721 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
724 lpfc_nlp_init(vport, ndlp, Fabric_DID);
726 lpfc_dequeue_node(vport, ndlp);
729 if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
736 lpfc_initial_fdisc(struct lpfc_vport *vport)
738 struct lpfc_hba *phba = vport->phba;
739 struct lpfc_nodelist *ndlp;
741 /* First look for the Fabric ndlp */
742 ndlp = lpfc_findnode_did(vport, Fabric_DID);
744 /* Cannot find existing Fabric ndlp, so allocate a new one */
745 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
748 lpfc_nlp_init(vport, ndlp, Fabric_DID);
750 lpfc_dequeue_node(vport, ndlp);
752 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
759 lpfc_more_plogi(struct lpfc_vport *vport)
763 if (vport->num_disc_nodes)
764 vport->num_disc_nodes--;
766 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
767 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
768 "0232 Continue discovery with %d PLOGIs to go "
769 "Data: x%x x%x x%x\n",
770 vport->num_disc_nodes, vport->fc_plogi_cnt,
771 vport->fc_flag, vport->port_state);
772 /* Check to see if there are more PLOGIs to be sent */
773 if (vport->fc_flag & FC_NLP_MORE)
774 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
775 sentplogi = lpfc_els_disc_plogi(vport);
780 static struct lpfc_nodelist *
781 lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
782 struct lpfc_nodelist *ndlp)
784 struct lpfc_vport *vport = ndlp->vport;
785 struct lpfc_nodelist *new_ndlp;
786 struct serv_parm *sp;
787 uint8_t name[sizeof(struct lpfc_name)];
790 /* Fabric nodes can have the same WWPN so we don't bother searching
791 * by WWPN. Just return the ndlp that was given to us.
793 if (ndlp->nlp_type & NLP_FABRIC)
796 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
797 memset(name, 0, sizeof(struct lpfc_name));
799 /* Now we find out if the NPort we are logging into, matches the WWPN
800 * we have for that ndlp. If not, we have some work to do.
802 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
804 if (new_ndlp == ndlp)
808 rc = memcmp(&ndlp->nlp_portname, name,
809 sizeof(struct lpfc_name));
812 new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
816 lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID);
819 lpfc_unreg_rpi(vport, new_ndlp);
820 new_ndlp->nlp_DID = ndlp->nlp_DID;
821 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
822 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
824 /* Move this back to NPR state */
825 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
826 /* The new_ndlp is replacing ndlp totally, so we need
827 * to put ndlp on UNUSED list and try to free it.
829 lpfc_drop_node(vport, ndlp);
832 lpfc_unreg_rpi(vport, ndlp);
833 ndlp->nlp_DID = 0; /* Two ndlps cannot have the same did */
834 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
840 lpfc_end_rscn(struct lpfc_vport *vport)
842 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
844 if (vport->fc_flag & FC_RSCN_MODE) {
846 * Check to see if more RSCNs came in while we were
847 * processing this one.
849 if (vport->fc_rscn_id_cnt ||
850 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
851 lpfc_els_handle_rscn(vport);
853 spin_lock_irq(shost->host_lock);
854 vport->fc_flag &= ~FC_RSCN_MODE;
855 spin_unlock_irq(shost->host_lock);
861 lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
862 struct lpfc_iocbq *rspiocb)
864 struct lpfc_vport *vport = cmdiocb->vport;
865 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
867 struct lpfc_nodelist *ndlp;
868 struct lpfc_dmabuf *prsp;
869 int disc, rc, did, type;
871 /* we pass cmdiocb to state machine which needs rspiocb as well */
872 cmdiocb->context_un.rsp_iocb = rspiocb;
874 irsp = &rspiocb->iocb;
875 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
876 "PLOGI cmpl: status:x%x/x%x did:x%x",
877 irsp->ulpStatus, irsp->un.ulpWord[4],
878 irsp->un.elsreq64.remoteID);
880 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
882 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
883 "0136 PLOGI completes to NPort x%x "
884 "with no ndlp. Data: x%x x%x x%x\n",
885 irsp->un.elsreq64.remoteID,
886 irsp->ulpStatus, irsp->un.ulpWord[4],
891 /* Since ndlp can be freed in the disc state machine, note if this node
892 * is being used during discovery.
894 spin_lock_irq(shost->host_lock);
895 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
896 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
897 spin_unlock_irq(shost->host_lock);
900 /* PLOGI completes to NPort <nlp_DID> */
901 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
902 "0102 PLOGI completes to NPort x%x "
903 "Data: x%x x%x x%x x%x x%x\n",
904 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
905 irsp->ulpTimeout, disc, vport->num_disc_nodes);
906 /* Check to see if link went down during discovery */
907 if (lpfc_els_chk_latt(vport)) {
908 spin_lock_irq(shost->host_lock);
909 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
910 spin_unlock_irq(shost->host_lock);
914 /* ndlp could be freed in DSM, save these values now */
915 type = ndlp->nlp_type;
918 if (irsp->ulpStatus) {
919 /* Check for retry */
920 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
921 /* ELS command is being retried */
923 spin_lock_irq(shost->host_lock);
924 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
925 spin_unlock_irq(shost->host_lock);
930 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
931 if (lpfc_error_lost_link(irsp)) {
932 rc = NLP_STE_FREED_NODE;
934 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
938 /* Good status, call state machine */
939 prsp = list_entry(((struct lpfc_dmabuf *)
940 cmdiocb->context2)->list.next,
941 struct lpfc_dmabuf, list);
942 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
943 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
947 if (disc && vport->num_disc_nodes) {
948 /* Check to see if there are more PLOGIs to be sent */
949 lpfc_more_plogi(vport);
951 if (vport->num_disc_nodes == 0) {
952 spin_lock_irq(shost->host_lock);
953 vport->fc_flag &= ~FC_NDISC_ACTIVE;
954 spin_unlock_irq(shost->host_lock);
956 lpfc_can_disctmo(vport);
957 lpfc_end_rscn(vport);
962 lpfc_els_free_iocb(phba, cmdiocb);
967 lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
969 struct lpfc_hba *phba = vport->phba;
970 struct serv_parm *sp;
972 struct lpfc_nodelist *ndlp;
973 struct lpfc_iocbq *elsiocb;
974 struct lpfc_sli_ring *pring;
975 struct lpfc_sli *psli;
981 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
983 ndlp = lpfc_findnode_did(vport, did);
984 /* If ndlp if not NULL, we will bump the reference count on it */
986 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
987 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
992 icmd = &elsiocb->iocb;
993 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
995 /* For PLOGI request, remainder of payload is service parameters */
996 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
997 pcmd += sizeof(uint32_t);
998 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
999 sp = (struct serv_parm *) pcmd;
1001 if (sp->cmn.fcphLow < FC_PH_4_3)
1002 sp->cmn.fcphLow = FC_PH_4_3;
1004 if (sp->cmn.fcphHigh < FC_PH3)
1005 sp->cmn.fcphHigh = FC_PH3;
1007 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1008 "Issue PLOGI: did:x%x",
1011 phba->fc_stat.elsXmitPLOGI++;
1012 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
1013 ret = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
1015 if (ret == IOCB_ERROR) {
1016 lpfc_els_free_iocb(phba, elsiocb);
1023 lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1024 struct lpfc_iocbq *rspiocb)
1026 struct lpfc_vport *vport = cmdiocb->vport;
1027 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1029 struct lpfc_sli *psli;
1030 struct lpfc_nodelist *ndlp;
1033 /* we pass cmdiocb to state machine which needs rspiocb as well */
1034 cmdiocb->context_un.rsp_iocb = rspiocb;
1036 irsp = &(rspiocb->iocb);
1037 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1038 spin_lock_irq(shost->host_lock);
1039 ndlp->nlp_flag &= ~NLP_PRLI_SND;
1040 spin_unlock_irq(shost->host_lock);
1042 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1043 "PRLI cmpl: status:x%x/x%x did:x%x",
1044 irsp->ulpStatus, irsp->un.ulpWord[4],
1046 /* PRLI completes to NPort <nlp_DID> */
1047 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1048 "0103 PRLI completes to NPort x%x "
1049 "Data: x%x x%x x%x x%x\n",
1050 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1051 irsp->ulpTimeout, vport->num_disc_nodes);
1053 vport->fc_prli_sent--;
1054 /* Check to see if link went down during discovery */
1055 if (lpfc_els_chk_latt(vport))
1058 if (irsp->ulpStatus) {
1059 /* Check for retry */
1060 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1061 /* ELS command is being retried */
1065 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1066 if (lpfc_error_lost_link(irsp)) {
1069 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1073 /* Good status, call state machine */
1074 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1079 lpfc_els_free_iocb(phba, cmdiocb);
1084 lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1087 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1088 struct lpfc_hba *phba = vport->phba;
1091 struct lpfc_iocbq *elsiocb;
1092 struct lpfc_sli_ring *pring;
1093 struct lpfc_sli *psli;
1098 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1100 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
1101 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1102 ndlp->nlp_DID, ELS_CMD_PRLI);
1106 icmd = &elsiocb->iocb;
1107 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1109 /* For PRLI request, remainder of payload is service parameters */
1110 memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t)));
1111 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
1112 pcmd += sizeof(uint32_t);
1114 /* For PRLI, remainder of payload is PRLI parameter page */
1115 npr = (PRLI *) pcmd;
1117 * If our firmware version is 3.20 or later,
1118 * set the following bits for FC-TAPE support.
1120 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
1121 npr->ConfmComplAllowed = 1;
1123 npr->TaskRetryIdReq = 1;
1125 npr->estabImagePair = 1;
1126 npr->readXferRdyDis = 1;
1128 /* For FCP support */
1129 npr->prliType = PRLI_FCP_TYPE;
1130 npr->initiatorFunc = 1;
1132 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1133 "Issue PRLI: did:x%x",
1134 ndlp->nlp_DID, 0, 0);
1136 phba->fc_stat.elsXmitPRLI++;
1137 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
1138 spin_lock_irq(shost->host_lock);
1139 ndlp->nlp_flag |= NLP_PRLI_SND;
1140 spin_unlock_irq(shost->host_lock);
1141 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
1142 spin_lock_irq(shost->host_lock);
1143 ndlp->nlp_flag &= ~NLP_PRLI_SND;
1144 spin_unlock_irq(shost->host_lock);
1145 lpfc_els_free_iocb(phba, elsiocb);
1148 vport->fc_prli_sent++;
1153 lpfc_more_adisc(struct lpfc_vport *vport)
1157 if (vport->num_disc_nodes)
1158 vport->num_disc_nodes--;
1159 /* Continue discovery with <num_disc_nodes> ADISCs to go */
1160 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1161 "0210 Continue discovery with %d ADISCs to go "
1162 "Data: x%x x%x x%x\n",
1163 vport->num_disc_nodes, vport->fc_adisc_cnt,
1164 vport->fc_flag, vport->port_state);
1165 /* Check to see if there are more ADISCs to be sent */
1166 if (vport->fc_flag & FC_NLP_MORE) {
1167 lpfc_set_disctmo(vport);
1168 /* go thru NPR nodes and issue any remaining ELS ADISCs */
1169 sentadisc = lpfc_els_disc_adisc(vport);
1175 lpfc_rscn_disc(struct lpfc_vport *vport)
1177 lpfc_can_disctmo(vport);
1179 /* RSCN discovery */
1180 /* go thru NPR nodes and issue ELS PLOGIs */
1181 if (vport->fc_npr_cnt)
1182 if (lpfc_els_disc_plogi(vport))
1185 lpfc_end_rscn(vport);
1189 lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1190 struct lpfc_iocbq *rspiocb)
1192 struct lpfc_vport *vport = cmdiocb->vport;
1193 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1195 struct lpfc_nodelist *ndlp;
1198 /* we pass cmdiocb to state machine which needs rspiocb as well */
1199 cmdiocb->context_un.rsp_iocb = rspiocb;
1201 irsp = &(rspiocb->iocb);
1202 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1204 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1205 "ADISC cmpl: status:x%x/x%x did:x%x",
1206 irsp->ulpStatus, irsp->un.ulpWord[4],
1209 /* Since ndlp can be freed in the disc state machine, note if this node
1210 * is being used during discovery.
1212 spin_lock_irq(shost->host_lock);
1213 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
1214 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
1215 spin_unlock_irq(shost->host_lock);
1216 /* ADISC completes to NPort <nlp_DID> */
1217 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1218 "0104 ADISC completes to NPort x%x "
1219 "Data: x%x x%x x%x x%x x%x\n",
1220 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1221 irsp->ulpTimeout, disc, vport->num_disc_nodes);
1222 /* Check to see if link went down during discovery */
1223 if (lpfc_els_chk_latt(vport)) {
1224 spin_lock_irq(shost->host_lock);
1225 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1226 spin_unlock_irq(shost->host_lock);
1230 if (irsp->ulpStatus) {
1231 /* Check for retry */
1232 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1233 /* ELS command is being retried */
1235 spin_lock_irq(shost->host_lock);
1236 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1237 spin_unlock_irq(shost->host_lock);
1238 lpfc_set_disctmo(vport);
1243 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1244 if (!lpfc_error_lost_link(irsp)) {
1245 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1246 NLP_EVT_CMPL_ADISC);
1249 /* Good status, call state machine */
1250 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1251 NLP_EVT_CMPL_ADISC);
1254 if (disc && vport->num_disc_nodes) {
1255 /* Check to see if there are more ADISCs to be sent */
1256 lpfc_more_adisc(vport);
1258 /* Check to see if we are done with ADISC authentication */
1259 if (vport->num_disc_nodes == 0) {
1260 /* If we get here, there is nothing left to ADISC */
1262 * For NPIV, cmpl_reg_vpi will set port_state to READY,
1263 * and continue discovery.
1265 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
1266 !(vport->fc_flag & FC_RSCN_MODE)) {
1267 lpfc_issue_reg_vpi(phba, vport);
1271 * For SLI2, we need to set port_state to READY
1272 * and continue discovery.
1274 if (vport->port_state < LPFC_VPORT_READY) {
1275 /* If we get here, there is nothing to ADISC */
1276 if (vport->port_type == LPFC_PHYSICAL_PORT)
1277 lpfc_issue_clear_la(phba, vport);
1279 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
1280 vport->num_disc_nodes = 0;
1281 /* go thru NPR list, issue ELS PLOGIs */
1282 if (vport->fc_npr_cnt)
1283 lpfc_els_disc_plogi(vport);
1285 if (!vport->num_disc_nodes) {
1286 spin_lock_irq(shost->host_lock);
1291 lpfc_can_disctmo(vport);
1294 vport->port_state = LPFC_VPORT_READY;
1296 lpfc_rscn_disc(vport);
1301 lpfc_els_free_iocb(phba, cmdiocb);
1306 lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1309 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1310 struct lpfc_hba *phba = vport->phba;
1313 struct lpfc_iocbq *elsiocb;
1314 struct lpfc_sli *psli = &phba->sli;
1315 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
1319 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
1320 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1321 ndlp->nlp_DID, ELS_CMD_ADISC);
1325 icmd = &elsiocb->iocb;
1326 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1328 /* For ADISC request, remainder of payload is service parameters */
1329 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
1330 pcmd += sizeof(uint32_t);
1332 /* Fill in ADISC payload */
1333 ap = (ADISC *) pcmd;
1334 ap->hardAL_PA = phba->fc_pref_ALPA;
1335 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
1336 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
1337 ap->DID = be32_to_cpu(vport->fc_myDID);
1339 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1340 "Issue ADISC: did:x%x",
1341 ndlp->nlp_DID, 0, 0);
1343 phba->fc_stat.elsXmitADISC++;
1344 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
1345 spin_lock_irq(shost->host_lock);
1346 ndlp->nlp_flag |= NLP_ADISC_SND;
1347 spin_unlock_irq(shost->host_lock);
1348 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
1349 spin_lock_irq(shost->host_lock);
1350 ndlp->nlp_flag &= ~NLP_ADISC_SND;
1351 spin_unlock_irq(shost->host_lock);
1352 lpfc_els_free_iocb(phba, elsiocb);
1359 lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1360 struct lpfc_iocbq *rspiocb)
1362 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1363 struct lpfc_vport *vport = ndlp->vport;
1364 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1366 struct lpfc_sli *psli;
1369 /* we pass cmdiocb to state machine which needs rspiocb as well */
1370 cmdiocb->context_un.rsp_iocb = rspiocb;
1372 irsp = &(rspiocb->iocb);
1373 spin_lock_irq(shost->host_lock);
1374 ndlp->nlp_flag &= ~NLP_LOGO_SND;
1375 spin_unlock_irq(shost->host_lock);
1377 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1378 "LOGO cmpl: status:x%x/x%x did:x%x",
1379 irsp->ulpStatus, irsp->un.ulpWord[4],
1381 /* LOGO completes to NPort <nlp_DID> */
1382 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1383 "0105 LOGO completes to NPort x%x "
1384 "Data: x%x x%x x%x x%x\n",
1385 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1386 irsp->ulpTimeout, vport->num_disc_nodes);
1387 /* Check to see if link went down during discovery */
1388 if (lpfc_els_chk_latt(vport))
1391 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
1392 /* NLP_EVT_DEVICE_RM should unregister the RPI
1393 * which should abort all outstanding IOs.
1395 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1400 if (irsp->ulpStatus) {
1401 /* Check for retry */
1402 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
1403 /* ELS command is being retried */
1406 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1407 if (lpfc_error_lost_link(irsp))
1410 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1413 /* Good status, call state machine.
1414 * This will unregister the rpi if needed.
1416 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1421 lpfc_els_free_iocb(phba, cmdiocb);
1426 lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1429 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1430 struct lpfc_hba *phba = vport->phba;
1432 struct lpfc_iocbq *elsiocb;
1433 struct lpfc_sli_ring *pring;
1434 struct lpfc_sli *psli;
1440 pring = &psli->ring[LPFC_ELS_RING];
1442 spin_lock_irq(shost->host_lock);
1443 if (ndlp->nlp_flag & NLP_LOGO_SND) {
1444 spin_unlock_irq(shost->host_lock);
1447 spin_unlock_irq(shost->host_lock);
1449 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
1450 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1451 ndlp->nlp_DID, ELS_CMD_LOGO);
1455 icmd = &elsiocb->iocb;
1456 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1457 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
1458 pcmd += sizeof(uint32_t);
1460 /* Fill in LOGO payload */
1461 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
1462 pcmd += sizeof(uint32_t);
1463 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
1465 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1466 "Issue LOGO: did:x%x",
1467 ndlp->nlp_DID, 0, 0);
1469 phba->fc_stat.elsXmitLOGO++;
1470 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
1471 spin_lock_irq(shost->host_lock);
1472 ndlp->nlp_flag |= NLP_LOGO_SND;
1473 spin_unlock_irq(shost->host_lock);
1474 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
1476 if (rc == IOCB_ERROR) {
1477 spin_lock_irq(shost->host_lock);
1478 ndlp->nlp_flag &= ~NLP_LOGO_SND;
1479 spin_unlock_irq(shost->host_lock);
1480 lpfc_els_free_iocb(phba, elsiocb);
1487 lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1488 struct lpfc_iocbq *rspiocb)
1490 struct lpfc_vport *vport = cmdiocb->vport;
1493 irsp = &rspiocb->iocb;
1495 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1496 "ELS cmd cmpl: status:x%x/x%x did:x%x",
1497 irsp->ulpStatus, irsp->un.ulpWord[4],
1498 irsp->un.elsreq64.remoteID);
1499 /* ELS cmd tag <ulpIoTag> completes */
1500 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1501 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
1502 irsp->ulpIoTag, irsp->ulpStatus,
1503 irsp->un.ulpWord[4], irsp->ulpTimeout);
1504 /* Check to see if link went down during discovery */
1505 lpfc_els_chk_latt(vport);
1506 lpfc_els_free_iocb(phba, cmdiocb);
1511 lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
1513 struct lpfc_hba *phba = vport->phba;
1515 struct lpfc_iocbq *elsiocb;
1516 struct lpfc_sli_ring *pring;
1517 struct lpfc_sli *psli;
1520 struct lpfc_nodelist *ndlp;
1523 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1524 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
1525 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1529 lpfc_nlp_init(vport, ndlp, nportid);
1531 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1532 ndlp->nlp_DID, ELS_CMD_SCR);
1539 icmd = &elsiocb->iocb;
1540 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1542 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
1543 pcmd += sizeof(uint32_t);
1545 /* For SCR, remainder of payload is SCR parameter page */
1546 memset(pcmd, 0, sizeof(SCR));
1547 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
1549 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1550 "Issue SCR: did:x%x",
1551 ndlp->nlp_DID, 0, 0);
1553 phba->fc_stat.elsXmitSCR++;
1554 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
1555 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
1557 lpfc_els_free_iocb(phba, elsiocb);
1565 lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
1567 struct lpfc_hba *phba = vport->phba;
1569 struct lpfc_iocbq *elsiocb;
1570 struct lpfc_sli_ring *pring;
1571 struct lpfc_sli *psli;
1576 struct lpfc_nodelist *ondlp;
1577 struct lpfc_nodelist *ndlp;
1580 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1581 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
1582 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1586 lpfc_nlp_init(vport, ndlp, nportid);
1588 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1589 ndlp->nlp_DID, ELS_CMD_RNID);
1595 icmd = &elsiocb->iocb;
1596 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1598 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
1599 pcmd += sizeof(uint32_t);
1601 /* Fill in FARPR payload */
1602 fp = (FARP *) (pcmd);
1603 memset(fp, 0, sizeof(FARP));
1604 lp = (uint32_t *) pcmd;
1605 *lp++ = be32_to_cpu(nportid);
1606 *lp++ = be32_to_cpu(vport->fc_myDID);
1608 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
1610 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
1611 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
1612 ondlp = lpfc_findnode_did(vport, nportid);
1614 memcpy(&fp->OportName, &ondlp->nlp_portname,
1615 sizeof(struct lpfc_name));
1616 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
1617 sizeof(struct lpfc_name));
1620 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1621 "Issue FARPR: did:x%x",
1622 ndlp->nlp_DID, 0, 0);
1624 phba->fc_stat.elsXmitFARPR++;
1625 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
1626 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
1628 lpfc_els_free_iocb(phba, elsiocb);
1636 lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
1638 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1640 spin_lock_irq(shost->host_lock);
1641 nlp->nlp_flag &= ~NLP_DELAY_TMO;
1642 spin_unlock_irq(shost->host_lock);
1643 del_timer_sync(&nlp->nlp_delayfunc);
1644 nlp->nlp_last_elscmd = 0;
1646 if (!list_empty(&nlp->els_retry_evt.evt_listp))
1647 list_del_init(&nlp->els_retry_evt.evt_listp);
1649 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
1650 spin_lock_irq(shost->host_lock);
1651 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1652 spin_unlock_irq(shost->host_lock);
1653 if (vport->num_disc_nodes) {
1654 /* Check to see if there are more
1657 lpfc_more_plogi(vport);
1659 if (vport->num_disc_nodes == 0) {
1660 spin_lock_irq(shost->host_lock);
1661 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1662 spin_unlock_irq(shost->host_lock);
1663 lpfc_can_disctmo(vport);
1664 lpfc_end_rscn(vport);
1672 lpfc_els_retry_delay(unsigned long ptr)
1674 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
1675 struct lpfc_vport *vport = ndlp->vport;
1676 struct lpfc_hba *phba = vport->phba;
1677 unsigned long flags;
1678 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
1680 ndlp = (struct lpfc_nodelist *) ptr;
1681 phba = ndlp->vport->phba;
1682 evtp = &ndlp->els_retry_evt;
1684 spin_lock_irqsave(&phba->hbalock, flags);
1685 if (!list_empty(&evtp->evt_listp)) {
1686 spin_unlock_irqrestore(&phba->hbalock, flags);
1690 evtp->evt_arg1 = ndlp;
1691 evtp->evt = LPFC_EVT_ELS_RETRY;
1692 list_add_tail(&evtp->evt_listp, &phba->work_list);
1693 if (phba->work_wait)
1694 lpfc_worker_wake_up(phba);
1696 spin_unlock_irqrestore(&phba->hbalock, flags);
1701 lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
1703 struct lpfc_vport *vport = ndlp->vport;
1704 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1705 uint32_t cmd, did, retry;
1707 spin_lock_irq(shost->host_lock);
1708 did = ndlp->nlp_DID;
1709 cmd = ndlp->nlp_last_elscmd;
1710 ndlp->nlp_last_elscmd = 0;
1712 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
1713 spin_unlock_irq(shost->host_lock);
1717 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
1718 spin_unlock_irq(shost->host_lock);
1720 * If a discovery event readded nlp_delayfunc after timer
1721 * firing and before processing the timer, cancel the
1724 del_timer_sync(&ndlp->nlp_delayfunc);
1725 retry = ndlp->nlp_retry;
1729 lpfc_issue_els_flogi(vport, ndlp, retry);
1732 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
1733 ndlp->nlp_prev_state = ndlp->nlp_state;
1734 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1738 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
1739 ndlp->nlp_prev_state = ndlp->nlp_state;
1740 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
1744 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
1745 ndlp->nlp_prev_state = ndlp->nlp_state;
1746 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
1750 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
1751 ndlp->nlp_prev_state = ndlp->nlp_state;
1752 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1756 lpfc_issue_els_fdisc(vport, ndlp, retry);
1763 lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1764 struct lpfc_iocbq *rspiocb)
1766 struct lpfc_vport *vport = cmdiocb->vport;
1767 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1768 IOCB_t *irsp = &rspiocb->iocb;
1769 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1770 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
1773 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
1779 /* Note: context2 may be 0 for internal driver abort
1780 * of delays ELS command.
1783 if (pcmd && pcmd->virt) {
1784 elscmd = (uint32_t *) (pcmd->virt);
1789 did = ndlp->nlp_DID;
1791 /* We should only hit this case for retrying PLOGI */
1792 did = irsp->un.elsreq64.remoteID;
1793 ndlp = lpfc_findnode_did(vport, did);
1794 if (!ndlp && (cmd != ELS_CMD_PLOGI))
1798 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1799 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
1800 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
1802 switch (irsp->ulpStatus) {
1803 case IOSTAT_FCP_RSP_ERROR:
1804 case IOSTAT_REMOTE_STOP:
1807 case IOSTAT_LOCAL_REJECT:
1808 switch ((irsp->un.ulpWord[4] & 0xff)) {
1809 case IOERR_LOOP_OPEN_FAILURE:
1810 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
1815 case IOERR_ILLEGAL_COMMAND:
1816 if ((phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) &&
1817 (cmd == ELS_CMD_FDISC)) {
1818 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1819 "0124 FDISC failed (3/6) "
1821 lpfc_mbx_unreg_vpi(vport);
1823 /* FDISC retry policy */
1825 if (cmdiocb->retry >= 32)
1830 case IOERR_NO_RESOURCES:
1831 logerr = 1; /* HBA out of resources */
1833 if (cmdiocb->retry > 100)
1838 case IOERR_ILLEGAL_FRAME:
1843 case IOERR_SEQUENCE_TIMEOUT:
1844 case IOERR_INVALID_RPI:
1850 case IOSTAT_NPORT_RJT:
1851 case IOSTAT_FABRIC_RJT:
1852 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
1858 case IOSTAT_NPORT_BSY:
1859 case IOSTAT_FABRIC_BSY:
1860 logerr = 1; /* Fabric / Remote NPort out of resources */
1865 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
1866 /* Added for Vendor specifc support
1867 * Just keep retrying for these Rsn / Exp codes
1869 switch (stat.un.b.lsRjtRsnCode) {
1870 case LSRJT_UNABLE_TPC:
1871 if (stat.un.b.lsRjtRsnCodeExp ==
1872 LSEXP_CMD_IN_PROGRESS) {
1873 if (cmd == ELS_CMD_PLOGI) {
1880 if (cmd == ELS_CMD_PLOGI) {
1882 maxretry = lpfc_max_els_tries + 1;
1886 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
1887 (cmd == ELS_CMD_FDISC) &&
1888 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
1889 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1890 "0125 FDISC Failed (x%x). "
1891 "Fabric out of resources\n",
1892 stat.un.lsRjtError);
1893 lpfc_vport_set_state(vport,
1894 FC_VPORT_NO_FABRIC_RSCS);
1898 case LSRJT_LOGICAL_BSY:
1899 if ((cmd == ELS_CMD_PLOGI) ||
1900 (cmd == ELS_CMD_PRLI)) {
1903 } else if (cmd == ELS_CMD_FDISC) {
1904 /* FDISC retry policy */
1906 if (cmdiocb->retry >= 32)
1912 case LSRJT_LOGICAL_ERR:
1913 case LSRJT_PROTOCOL_ERR:
1914 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
1915 (cmd == ELS_CMD_FDISC) &&
1916 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
1917 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
1919 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1920 "0123 FDISC Failed (x%x). "
1921 "Fabric Detected Bad WWN\n",
1922 stat.un.lsRjtError);
1923 lpfc_vport_set_state(vport,
1924 FC_VPORT_FABRIC_REJ_WWN);
1930 case IOSTAT_INTERMED_RSP:
1938 if (did == FDMI_DID)
1941 if ((cmd == ELS_CMD_FLOGI) &&
1942 (phba->fc_topology != TOPOLOGY_LOOP)) {
1943 /* FLOGI retry policy */
1946 if (cmdiocb->retry >= 32)
1950 if ((++cmdiocb->retry) >= maxretry) {
1951 phba->fc_stat.elsRetryExceeded++;
1955 if ((vport->load_flag & FC_UNLOADING) != 0)
1960 /* Retry ELS command <elsCmd> to remote NPORT <did> */
1961 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1962 "0107 Retry ELS command x%x to remote "
1963 "NPORT x%x Data: x%x x%x\n",
1964 cmd, did, cmdiocb->retry, delay);
1966 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
1967 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
1968 ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) {
1969 /* Don't reset timer for no resources */
1971 /* If discovery / RSCN timer is running, reset it */
1972 if (timer_pending(&vport->fc_disctmo) ||
1973 (vport->fc_flag & FC_RSCN_MODE))
1974 lpfc_set_disctmo(vport);
1977 phba->fc_stat.elsXmitRetry++;
1978 if (ndlp && delay) {
1979 phba->fc_stat.elsDelayRetry++;
1980 ndlp->nlp_retry = cmdiocb->retry;
1982 /* delay is specified in milliseconds */
1983 mod_timer(&ndlp->nlp_delayfunc,
1984 jiffies + msecs_to_jiffies(delay));
1985 spin_lock_irq(shost->host_lock);
1986 ndlp->nlp_flag |= NLP_DELAY_TMO;
1987 spin_unlock_irq(shost->host_lock);
1989 ndlp->nlp_prev_state = ndlp->nlp_state;
1990 if (cmd == ELS_CMD_PRLI)
1991 lpfc_nlp_set_state(vport, ndlp,
1992 NLP_STE_REG_LOGIN_ISSUE);
1994 lpfc_nlp_set_state(vport, ndlp,
1996 ndlp->nlp_last_elscmd = cmd;
2002 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
2005 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
2009 ndlp->nlp_prev_state = ndlp->nlp_state;
2010 lpfc_nlp_set_state(vport, ndlp,
2011 NLP_STE_PLOGI_ISSUE);
2013 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
2016 ndlp->nlp_prev_state = ndlp->nlp_state;
2017 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2018 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
2021 ndlp->nlp_prev_state = ndlp->nlp_state;
2022 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
2023 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
2026 ndlp->nlp_prev_state = ndlp->nlp_state;
2027 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2028 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
2032 /* No retry ELS command <elsCmd> to remote NPORT <did> */
2034 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2035 "0137 No retry ELS command x%x to remote "
2036 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
2037 cmd, did, irsp->ulpStatus,
2038 irsp->un.ulpWord[4]);
2041 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2042 "0108 No retry ELS command x%x to remote "
2043 "NPORT x%x Retried:%d Error:x%x/%x\n",
2044 cmd, did, cmdiocb->retry, irsp->ulpStatus,
2045 irsp->un.ulpWord[4]);
2051 lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
2053 struct lpfc_dmabuf *buf_ptr;
2055 /* Free the response before processing the command. */
2056 if (!list_empty(&buf_ptr1->list)) {
2057 list_remove_head(&buf_ptr1->list, buf_ptr,
2060 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
2063 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
2069 lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
2071 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
2077 lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
2079 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
2080 struct lpfc_nodelist *ndlp;
2082 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
2084 if (ndlp->nlp_flag & NLP_DEFER_RM) {
2087 /* If the ndlp is not being used by another discovery
2090 if (!lpfc_nlp_not_used(ndlp)) {
2091 /* If ndlp is being used by another discovery
2092 * thread, just clear NLP_DEFER_RM
2094 ndlp->nlp_flag &= ~NLP_DEFER_RM;
2099 elsiocb->context1 = NULL;
2101 /* context2 = cmd, context2->next = rsp, context3 = bpl */
2102 if (elsiocb->context2) {
2103 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
2104 lpfc_els_free_data(phba, buf_ptr1);
2107 if (elsiocb->context3) {
2108 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
2109 lpfc_els_free_bpl(phba, buf_ptr);
2111 lpfc_sli_release_iocbq(phba, elsiocb);
2116 lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2117 struct lpfc_iocbq *rspiocb)
2119 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2120 struct lpfc_vport *vport = cmdiocb->vport;
2123 irsp = &rspiocb->iocb;
2124 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2125 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
2126 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
2127 /* ACC to LOGO completes to NPort <nlp_DID> */
2128 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2129 "0109 ACC to LOGO completes to NPort x%x "
2130 "Data: x%x x%x x%x\n",
2131 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2134 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
2135 /* NPort Recovery mode or node is just allocated */
2136 if (!lpfc_nlp_not_used(ndlp)) {
2137 /* If the ndlp is being used by another discovery
2138 * thread, just unregister the RPI.
2140 lpfc_unreg_rpi(vport, ndlp);
2143 lpfc_els_free_iocb(phba, cmdiocb);
2148 lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
2150 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
2151 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
2153 pmb->context1 = NULL;
2154 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2156 mempool_free(pmb, phba->mbox_mem_pool);
2160 /* This is the end of the default RPI cleanup logic for this
2161 * ndlp. If no other discovery threads are using this ndlp.
2162 * we should free all resources associated with it.
2164 lpfc_nlp_not_used(ndlp);
2170 lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2171 struct lpfc_iocbq *rspiocb)
2173 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2174 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
2175 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
2178 LPFC_MBOXQ_t *mbox = NULL;
2179 struct lpfc_dmabuf *mp = NULL;
2180 uint32_t ls_rjt = 0;
2182 irsp = &rspiocb->iocb;
2184 if (cmdiocb->context_un.mbox)
2185 mbox = cmdiocb->context_un.mbox;
2187 /* First determine if this is a LS_RJT cmpl */
2188 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
2189 if (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT) {
2190 /* A LS_RJT associated with Default RPI cleanup
2191 * has its own seperate code path.
2193 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
2197 /* Check to see if link went down during discovery */
2198 if (!ndlp || lpfc_els_chk_latt(vport)) {
2200 mp = (struct lpfc_dmabuf *) mbox->context1;
2202 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2205 mempool_free(mbox, phba->mbox_mem_pool);
2207 if (ndlp && (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
2208 if (lpfc_nlp_not_used(ndlp))
2213 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2214 "ELS rsp cmpl: status:x%x/x%x did:x%x",
2215 irsp->ulpStatus, irsp->un.ulpWord[4],
2216 cmdiocb->iocb.un.elsreq64.remoteID);
2217 /* ELS response tag <ulpIoTag> completes */
2218 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2219 "0110 ELS response tag x%x completes "
2220 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
2221 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
2222 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
2223 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2226 if ((rspiocb->iocb.ulpStatus == 0)
2227 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
2228 lpfc_unreg_rpi(vport, ndlp);
2229 mbox->context2 = lpfc_nlp_get(ndlp);
2230 mbox->vport = vport;
2231 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
2232 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
2233 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
2236 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
2237 ndlp->nlp_prev_state = ndlp->nlp_state;
2238 lpfc_nlp_set_state(vport, ndlp,
2239 NLP_STE_REG_LOGIN_ISSUE);
2241 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
2242 != MBX_NOT_FINISHED) {
2246 /* ELS rsp: Cannot issue reg_login for <NPortid> */
2247 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2248 "0138 ELS rsp: Cannot issue reg_login for x%x "
2249 "Data: x%x x%x x%x\n",
2250 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2253 if (lpfc_nlp_not_used(ndlp))
2256 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
2257 if (!lpfc_error_lost_link(irsp) &&
2258 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
2259 if (lpfc_nlp_not_used(ndlp))
2263 mp = (struct lpfc_dmabuf *) mbox->context1;
2265 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2268 mempool_free(mbox, phba->mbox_mem_pool);
2272 spin_lock_irq(shost->host_lock);
2273 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
2274 spin_unlock_irq(shost->host_lock);
2276 /* If the node is not being used by another discovery thread,
2277 * and we are sending a reject, we are done with it.
2278 * Release driver reference count here and free associated
2282 lpfc_nlp_not_used(ndlp);
2285 lpfc_els_free_iocb(phba, cmdiocb);
2290 lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
2291 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
2294 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2295 struct lpfc_hba *phba = vport->phba;
2298 struct lpfc_iocbq *elsiocb;
2299 struct lpfc_sli_ring *pring;
2300 struct lpfc_sli *psli;
2304 ELS_PKT *els_pkt_ptr;
2307 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2308 oldcmd = &oldiocb->iocb;
2312 cmdsize = sizeof(uint32_t);
2313 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
2314 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
2316 spin_lock_irq(shost->host_lock);
2317 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
2318 spin_unlock_irq(shost->host_lock);
2322 icmd = &elsiocb->iocb;
2323 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2324 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2325 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
2326 pcmd += sizeof(uint32_t);
2328 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2329 "Issue ACC: did:x%x flg:x%x",
2330 ndlp->nlp_DID, ndlp->nlp_flag, 0);
2333 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
2334 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
2335 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
2339 icmd = &elsiocb->iocb;
2340 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2341 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2344 elsiocb->context_un.mbox = mbox;
2346 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
2347 pcmd += sizeof(uint32_t);
2348 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
2350 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2351 "Issue ACC PLOGI: did:x%x flg:x%x",
2352 ndlp->nlp_DID, ndlp->nlp_flag, 0);
2355 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
2356 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
2357 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
2361 icmd = &elsiocb->iocb;
2362 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2363 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2365 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
2366 sizeof(uint32_t) + sizeof(PRLO));
2367 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
2368 els_pkt_ptr = (ELS_PKT *) pcmd;
2369 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
2371 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2372 "Issue ACC PRLO: did:x%x flg:x%x",
2373 ndlp->nlp_DID, ndlp->nlp_flag, 0);
2378 /* Xmit ELS ACC response tag <ulpIoTag> */
2379 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2380 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
2381 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n",
2382 elsiocb->iotag, elsiocb->iocb.ulpContext,
2383 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2385 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
2386 spin_lock_irq(shost->host_lock);
2387 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
2388 spin_unlock_irq(shost->host_lock);
2389 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
2391 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
2394 phba->fc_stat.elsXmitACC++;
2395 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
2396 if (rc == IOCB_ERROR) {
2397 lpfc_els_free_iocb(phba, elsiocb);
2404 lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
2405 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
2408 struct lpfc_hba *phba = vport->phba;
2411 struct lpfc_iocbq *elsiocb;
2412 struct lpfc_sli_ring *pring;
2413 struct lpfc_sli *psli;
2419 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2421 cmdsize = 2 * sizeof(uint32_t);
2422 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
2423 ndlp->nlp_DID, ELS_CMD_LS_RJT);
2427 icmd = &elsiocb->iocb;
2428 oldcmd = &oldiocb->iocb;
2429 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2430 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2432 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
2433 pcmd += sizeof(uint32_t);
2434 *((uint32_t *) (pcmd)) = rejectError;
2437 elsiocb->context_un.mbox = mbox;
2439 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
2440 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2441 "0129 Xmit ELS RJT x%x response tag x%x "
2442 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
2444 rejectError, elsiocb->iotag,
2445 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
2446 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
2447 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2448 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
2449 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
2451 phba->fc_stat.elsXmitLSRJT++;
2452 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
2453 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
2455 if (rc == IOCB_ERROR) {
2456 lpfc_els_free_iocb(phba, elsiocb);
2463 lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
2464 struct lpfc_nodelist *ndlp)
2466 struct lpfc_hba *phba = vport->phba;
2467 struct lpfc_sli *psli = &phba->sli;
2468 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
2470 IOCB_t *icmd, *oldcmd;
2471 struct lpfc_iocbq *elsiocb;
2476 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
2477 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
2478 ndlp->nlp_DID, ELS_CMD_ACC);
2482 icmd = &elsiocb->iocb;
2483 oldcmd = &oldiocb->iocb;
2484 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2486 /* Xmit ADISC ACC response tag <ulpIoTag> */
2487 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2488 "0130 Xmit ADISC ACC response iotag x%x xri: "
2489 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
2490 elsiocb->iotag, elsiocb->iocb.ulpContext,
2491 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2493 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2495 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
2496 pcmd += sizeof(uint32_t);
2498 ap = (ADISC *) (pcmd);
2499 ap->hardAL_PA = phba->fc_pref_ALPA;
2500 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2501 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
2502 ap->DID = be32_to_cpu(vport->fc_myDID);
2504 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2505 "Issue ACC ADISC: did:x%x flg:x%x",
2506 ndlp->nlp_DID, ndlp->nlp_flag, 0);
2508 phba->fc_stat.elsXmitACC++;
2509 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
2510 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
2511 if (rc == IOCB_ERROR) {
2512 lpfc_els_free_iocb(phba, elsiocb);
2519 lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
2520 struct lpfc_nodelist *ndlp)
2522 struct lpfc_hba *phba = vport->phba;
2527 struct lpfc_iocbq *elsiocb;
2528 struct lpfc_sli_ring *pring;
2529 struct lpfc_sli *psli;
2535 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2537 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
2538 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
2539 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
2543 icmd = &elsiocb->iocb;
2544 oldcmd = &oldiocb->iocb;
2545 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2546 /* Xmit PRLI ACC response tag <ulpIoTag> */
2547 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2548 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
2549 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
2550 elsiocb->iotag, elsiocb->iocb.ulpContext,
2551 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2553 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2555 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
2556 pcmd += sizeof(uint32_t);
2558 /* For PRLI, remainder of payload is PRLI parameter page */
2559 memset(pcmd, 0, sizeof(PRLI));
2561 npr = (PRLI *) pcmd;
2564 * If our firmware version is 3.20 or later,
2565 * set the following bits for FC-TAPE support.
2567 if (vpd->rev.feaLevelHigh >= 0x02) {
2568 npr->ConfmComplAllowed = 1;
2570 npr->TaskRetryIdReq = 1;
2573 npr->acceptRspCode = PRLI_REQ_EXECUTED;
2574 npr->estabImagePair = 1;
2575 npr->readXferRdyDis = 1;
2576 npr->ConfmComplAllowed = 1;
2578 npr->prliType = PRLI_FCP_TYPE;
2579 npr->initiatorFunc = 1;
2581 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2582 "Issue ACC PRLI: did:x%x flg:x%x",
2583 ndlp->nlp_DID, ndlp->nlp_flag, 0);
2585 phba->fc_stat.elsXmitACC++;
2586 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
2588 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
2589 if (rc == IOCB_ERROR) {
2590 lpfc_els_free_iocb(phba, elsiocb);
2597 lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
2598 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
2600 struct lpfc_hba *phba = vport->phba;
2602 IOCB_t *icmd, *oldcmd;
2603 struct lpfc_iocbq *elsiocb;
2604 struct lpfc_sli_ring *pring;
2605 struct lpfc_sli *psli;
2611 pring = &psli->ring[LPFC_ELS_RING];
2613 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
2614 + (2 * sizeof(struct lpfc_name));
2616 cmdsize += sizeof(RNID_TOP_DISC);
2618 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
2619 ndlp->nlp_DID, ELS_CMD_ACC);
2623 icmd = &elsiocb->iocb;
2624 oldcmd = &oldiocb->iocb;
2625 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2626 /* Xmit RNID ACC response tag <ulpIoTag> */
2627 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2628 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
2629 elsiocb->iotag, elsiocb->iocb.ulpContext);
2630 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2631 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
2632 pcmd += sizeof(uint32_t);
2634 memset(pcmd, 0, sizeof(RNID));
2635 rn = (RNID *) (pcmd);
2636 rn->Format = format;
2637 rn->CommonLen = (2 * sizeof(struct lpfc_name));
2638 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2639 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
2642 rn->SpecificLen = 0;
2644 case RNID_TOPOLOGY_DISC:
2645 rn->SpecificLen = sizeof(RNID_TOP_DISC);
2646 memcpy(&rn->un.topologyDisc.portName,
2647 &vport->fc_portname, sizeof(struct lpfc_name));
2648 rn->un.topologyDisc.unitType = RNID_HBA;
2649 rn->un.topologyDisc.physPort = 0;
2650 rn->un.topologyDisc.attachedNodes = 0;
2654 rn->SpecificLen = 0;
2658 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2659 "Issue ACC RNID: did:x%x flg:x%x",
2660 ndlp->nlp_DID, ndlp->nlp_flag, 0);
2662 phba->fc_stat.elsXmitACC++;
2663 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
2665 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
2666 * it could be freed */
2668 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
2669 if (rc == IOCB_ERROR) {
2670 lpfc_els_free_iocb(phba, elsiocb);
2677 lpfc_els_disc_adisc(struct lpfc_vport *vport)
2679 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2680 struct lpfc_nodelist *ndlp, *next_ndlp;
2683 /* go thru NPR nodes and issue any remaining ELS ADISCs */
2684 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
2685 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
2686 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
2687 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
2688 spin_lock_irq(shost->host_lock);
2689 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2690 spin_unlock_irq(shost->host_lock);
2691 ndlp->nlp_prev_state = ndlp->nlp_state;
2692 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2693 lpfc_issue_els_adisc(vport, ndlp, 0);
2695 vport->num_disc_nodes++;
2696 if (vport->num_disc_nodes >=
2697 vport->cfg_discovery_threads) {
2698 spin_lock_irq(shost->host_lock);
2699 vport->fc_flag |= FC_NLP_MORE;
2700 spin_unlock_irq(shost->host_lock);
2705 if (sentadisc == 0) {
2706 spin_lock_irq(shost->host_lock);
2707 vport->fc_flag &= ~FC_NLP_MORE;
2708 spin_unlock_irq(shost->host_lock);
2714 lpfc_els_disc_plogi(struct lpfc_vport *vport)
2716 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2717 struct lpfc_nodelist *ndlp, *next_ndlp;
2720 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
2721 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
2722 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
2723 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
2724 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
2725 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
2726 ndlp->nlp_prev_state = ndlp->nlp_state;
2727 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2728 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
2730 vport->num_disc_nodes++;
2731 if (vport->num_disc_nodes >=
2732 vport->cfg_discovery_threads) {
2733 spin_lock_irq(shost->host_lock);
2734 vport->fc_flag |= FC_NLP_MORE;
2735 spin_unlock_irq(shost->host_lock);
2741 lpfc_set_disctmo(vport);
2744 spin_lock_irq(shost->host_lock);
2745 vport->fc_flag &= ~FC_NLP_MORE;
2746 spin_unlock_irq(shost->host_lock);
2752 lpfc_els_flush_rscn(struct lpfc_vport *vport)
2754 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2755 struct lpfc_hba *phba = vport->phba;
2758 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
2759 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
2760 vport->fc_rscn_id_list[i] = NULL;
2762 spin_lock_irq(shost->host_lock);
2763 vport->fc_rscn_id_cnt = 0;
2764 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
2765 spin_unlock_irq(shost->host_lock);
2766 lpfc_can_disctmo(vport);
2770 lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
2775 uint32_t payload_len, i;
2777 ns_did.un.word = did;
2779 /* Never match fabric nodes for RSCNs */
2780 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
2783 /* If we are doing a FULL RSCN rediscovery, match everything */
2784 if (vport->fc_flag & FC_RSCN_DISCOVERY)
2787 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
2788 lp = vport->fc_rscn_id_list[i]->virt;
2789 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
2790 payload_len -= sizeof(uint32_t); /* take off word 0 */
2791 while (payload_len) {
2792 rscn_did.un.word = be32_to_cpu(*lp++);
2793 payload_len -= sizeof(uint32_t);
2794 switch (rscn_did.un.b.resv) {
2795 case 0: /* Single N_Port ID effected */
2796 if (ns_did.un.word == rscn_did.un.word)
2799 case 1: /* Whole N_Port Area effected */
2800 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
2801 && (ns_did.un.b.area == rscn_did.un.b.area))
2804 case 2: /* Whole N_Port Domain effected */
2805 if (ns_did.un.b.domain == rscn_did.un.b.domain)
2809 /* Unknown Identifier in RSCN node */
2810 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
2811 "0217 Unknown Identifier in "
2812 "RSCN payload Data: x%x\n",
2814 case 3: /* Whole Fabric effected */
2823 lpfc_rscn_recovery_check(struct lpfc_vport *vport)
2825 struct lpfc_nodelist *ndlp = NULL;
2827 /* Look at all nodes effected by pending RSCNs and move
2828 * them to NPR state.
2831 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
2832 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE ||
2833 lpfc_rscn_payload_check(vport, ndlp->nlp_DID) == 0)
2836 lpfc_disc_state_machine(vport, ndlp, NULL,
2837 NLP_EVT_DEVICE_RECOVERY);
2840 * Make sure NLP_DELAY_TMO is NOT running after a device
2843 if (ndlp->nlp_flag & NLP_DELAY_TMO)
2844 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2851 lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
2852 struct lpfc_nodelist *ndlp)
2854 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2855 struct lpfc_hba *phba = vport->phba;
2856 struct lpfc_dmabuf *pcmd;
2857 uint32_t *lp, *datap;
2859 uint32_t payload_len, length, nportid, *cmd;
2860 int rscn_cnt = vport->fc_rscn_id_cnt;
2861 int rscn_id = 0, hba_id = 0;
2864 icmd = &cmdiocb->iocb;
2865 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2866 lp = (uint32_t *) pcmd->virt;
2868 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
2869 payload_len -= sizeof(uint32_t); /* take off word 0 */
2871 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2872 "0214 RSCN received Data: x%x x%x x%x x%x\n",
2873 vport->fc_flag, payload_len, *lp, rscn_cnt);
2874 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
2875 fc_host_post_event(shost, fc_get_event_number(),
2876 FCH_EVT_RSCN, lp[i]);
2878 /* If we are about to begin discovery, just ACC the RSCN.
2879 * Discovery processing will satisfy it.
2881 if (vport->port_state <= LPFC_NS_QRY) {
2882 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
2883 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
2884 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
2886 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
2890 /* If this RSCN just contains NPortIDs for other vports on this HBA,
2891 * just ACC and ignore it.
2893 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2894 !(vport->cfg_peer_port_login)) {
2899 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
2900 i -= sizeof(uint32_t);
2902 if (lpfc_find_vport_by_did(phba, nportid))
2905 if (rscn_id == hba_id) {
2906 /* ALL NPortIDs in RSCN are on HBA */
2907 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2909 "Data: x%x x%x x%x x%x\n",
2910 vport->fc_flag, payload_len,
2912 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
2913 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
2914 ndlp->nlp_DID, vport->port_state,
2917 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
2923 /* If we are already processing an RSCN, save the received
2924 * RSCN payload buffer, cmdiocb->context2 to process later.
2926 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
2927 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
2928 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
2929 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
2931 vport->fc_flag |= FC_RSCN_DEFERRED;
2932 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
2933 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
2934 spin_lock_irq(shost->host_lock);
2935 vport->fc_flag |= FC_RSCN_MODE;
2936 spin_unlock_irq(shost->host_lock);
2938 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
2939 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
2942 (payload_len + length <= LPFC_BPL_SIZE)) {
2943 *cmd &= ELS_CMD_MASK;
2944 *cmd |= be32_to_cpu(payload_len + length);
2945 memcpy(((uint8_t *)cmd) + length, lp,
2948 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
2949 vport->fc_rscn_id_cnt++;
2950 /* If we zero, cmdiocb->context2, the calling
2951 * routine will not try to free it.
2953 cmdiocb->context2 = NULL;
2957 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2958 "0235 Deferred RSCN "
2959 "Data: x%x x%x x%x\n",
2960 vport->fc_rscn_id_cnt, vport->fc_flag,
2963 spin_lock_irq(shost->host_lock);
2964 vport->fc_flag |= FC_RSCN_DISCOVERY;
2965 spin_unlock_irq(shost->host_lock);
2966 /* ReDiscovery RSCN */
2967 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2968 "0234 ReDiscovery RSCN "
2969 "Data: x%x x%x x%x\n",
2970 vport->fc_rscn_id_cnt, vport->fc_flag,
2974 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
2976 /* send RECOVERY event for ALL nodes that match RSCN payload */
2977 lpfc_rscn_recovery_check(vport);
2978 vport->fc_flag &= ~FC_RSCN_DEFERRED;
2982 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
2983 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
2984 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
2986 spin_lock_irq(shost->host_lock);
2987 vport->fc_flag |= FC_RSCN_MODE;
2988 spin_unlock_irq(shost->host_lock);
2989 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
2991 * If we zero, cmdiocb->context2, the calling routine will
2992 * not try to free it.
2994 cmdiocb->context2 = NULL;
2996 lpfc_set_disctmo(vport);
2999 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
3001 /* send RECOVERY event for ALL nodes that match RSCN payload */
3002 lpfc_rscn_recovery_check(vport);
3004 return lpfc_els_handle_rscn(vport);
3008 lpfc_els_handle_rscn(struct lpfc_vport *vport)
3010 struct lpfc_nodelist *ndlp;
3011 struct lpfc_hba *phba = vport->phba;
3013 /* Ignore RSCN if the port is being torn down. */
3014 if (vport->load_flag & FC_UNLOADING) {
3015 lpfc_els_flush_rscn(vport);
3019 /* Start timer for RSCN processing */
3020 lpfc_set_disctmo(vport);
3022 /* RSCN processed */
3023 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3024 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
3025 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
3028 /* To process RSCN, first compare RSCN data with NameServer */
3029 vport->fc_ns_retry = 0;
3030 ndlp = lpfc_findnode_did(vport, NameServer_DID);
3031 if (ndlp && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
3032 /* Good ndlp, issue CT Request to NameServer */
3033 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
3034 /* Wait for NameServer query cmpl before we can
3038 /* If login to NameServer does not exist, issue one */
3039 /* Good status, issue PLOGI to NameServer */
3040 ndlp = lpfc_findnode_did(vport, NameServer_DID);
3042 /* Wait for NameServer login cmpl before we can
3046 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
3048 lpfc_els_flush_rscn(vport);
3051 lpfc_nlp_init(vport, ndlp, NameServer_DID);
3052 ndlp->nlp_type |= NLP_FABRIC;
3053 ndlp->nlp_prev_state = ndlp->nlp_state;
3054 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
3055 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
3056 /* Wait for NameServer login cmpl before we can
3062 lpfc_els_flush_rscn(vport);
3067 lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3068 struct lpfc_nodelist *ndlp)
3070 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3071 struct lpfc_hba *phba = vport->phba;
3072 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3073 uint32_t *lp = (uint32_t *) pcmd->virt;
3074 IOCB_t *icmd = &cmdiocb->iocb;
3075 struct serv_parm *sp;
3082 sp = (struct serv_parm *) lp;
3084 /* FLOGI received */
3086 lpfc_set_disctmo(vport);
3088 if (phba->fc_topology == TOPOLOGY_LOOP) {
3089 /* We should never receive a FLOGI in loop mode, ignore it */
3090 did = icmd->un.elsreq64.remoteID;
3092 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
3094 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3095 "0113 An FLOGI ELS command x%x was "
3096 "received from DID x%x in Loop Mode\n",
3103 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3))) {
3104 /* For a FLOGI we accept, then if our portname is greater
3105 * then the remote portname we initiate Nport login.
3108 rc = memcmp(&vport->fc_portname, &sp->portName,
3109 sizeof(struct lpfc_name));
3112 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3116 lpfc_linkdown(phba);
3117 lpfc_init_link(phba, mbox,
3119 phba->cfg_link_speed);
3120 mbox->mb.un.varInitLnk.lipsr_AL_PA = 0;
3121 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
3122 mbox->vport = vport;
3123 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
3124 lpfc_set_loopback_flag(phba);
3125 if (rc == MBX_NOT_FINISHED) {
3126 mempool_free(mbox, phba->mbox_mem_pool);
3129 } else if (rc > 0) { /* greater than */
3130 spin_lock_irq(shost->host_lock);
3131 vport->fc_flag |= FC_PT2PT_PLOGI;
3132 spin_unlock_irq(shost->host_lock);
3134 spin_lock_irq(shost->host_lock);
3135 vport->fc_flag |= FC_PT2PT;
3136 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
3137 spin_unlock_irq(shost->host_lock);
3139 /* Reject this request because invalid parameters */
3140 stat.un.b.lsRjtRsvd0 = 0;
3141 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3142 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
3143 stat.un.b.vendorUnique = 0;
3144 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
3150 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
3156 lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3157 struct lpfc_nodelist *ndlp)
3159 struct lpfc_dmabuf *pcmd;
3166 icmd = &cmdiocb->iocb;
3167 did = icmd->un.elsreq64.remoteID;
3168 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3169 lp = (uint32_t *) pcmd->virt;
3176 switch (rn->Format) {
3178 case RNID_TOPOLOGY_DISC:
3180 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
3183 /* Reject this request because format not supported */
3184 stat.un.b.lsRjtRsvd0 = 0;
3185 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3186 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
3187 stat.un.b.vendorUnique = 0;
3188 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
3195 lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3196 struct lpfc_nodelist *ndlp)
3200 /* For now, unconditionally reject this command */
3201 stat.un.b.lsRjtRsvd0 = 0;
3202 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3203 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
3204 stat.un.b.vendorUnique = 0;
3205 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
3210 lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3212 struct lpfc_sli *psli = &phba->sli;
3213 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
3218 struct lpfc_iocbq *elsiocb;
3219 struct lpfc_nodelist *ndlp;
3220 uint16_t xri, status;
3225 ndlp = (struct lpfc_nodelist *) pmb->context2;
3226 xri = (uint16_t) ((unsigned long)(pmb->context1));
3227 pmb->context1 = NULL;
3228 pmb->context2 = NULL;
3230 if (mb->mbxStatus) {
3231 mempool_free(pmb, phba->mbox_mem_pool);
3235 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
3236 mempool_free(pmb, phba->mbox_mem_pool);
3237 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
3238 lpfc_max_els_tries, ndlp,
3239 ndlp->nlp_DID, ELS_CMD_ACC);
3244 icmd = &elsiocb->iocb;
3245 icmd->ulpContext = xri;
3247 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3248 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
3249 pcmd += sizeof(uint32_t); /* Skip past command */
3250 rps_rsp = (RPS_RSP *)pcmd;
3252 if (phba->fc_topology != TOPOLOGY_LOOP)
3256 if (phba->pport->fc_flag & FC_FABRIC)
3260 rps_rsp->portStatus = be16_to_cpu(status);
3261 rps_rsp->linkFailureCnt = be32_to_cpu(mb->un.varRdLnk.linkFailureCnt);
3262 rps_rsp->lossSyncCnt = be32_to_cpu(mb->un.varRdLnk.lossSyncCnt);
3263 rps_rsp->lossSignalCnt = be32_to_cpu(mb->un.varRdLnk.lossSignalCnt);
3264 rps_rsp->primSeqErrCnt = be32_to_cpu(mb->un.varRdLnk.primSeqErrCnt);
3265 rps_rsp->invalidXmitWord = be32_to_cpu(mb->un.varRdLnk.invalidXmitWord);
3266 rps_rsp->crcCnt = be32_to_cpu(mb->un.varRdLnk.crcCnt);
3267 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
3268 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
3269 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
3270 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
3271 elsiocb->iotag, elsiocb->iocb.ulpContext,
3272 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3274 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
3275 phba->fc_stat.elsXmitACC++;
3276 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR)
3277 lpfc_els_free_iocb(phba, elsiocb);
3282 lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3283 struct lpfc_nodelist *ndlp)
3285 struct lpfc_hba *phba = vport->phba;
3289 struct lpfc_dmabuf *pcmd;
3293 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
3294 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
3295 stat.un.b.lsRjtRsvd0 = 0;
3296 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3297 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
3298 stat.un.b.vendorUnique = 0;
3299 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
3303 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3304 lp = (uint32_t *) pcmd->virt;
3305 flag = (be32_to_cpu(*lp++) & 0xf);
3309 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
3310 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
3311 sizeof(struct lpfc_name)) == 0))) {
3313 printk("Fix me....\n");
3315 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
3317 lpfc_read_lnk_stat(phba, mbox);
3319 (void *)((unsigned long) cmdiocb->iocb.ulpContext);
3320 mbox->context2 = lpfc_nlp_get(ndlp);
3321 mbox->vport = vport;
3322 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
3323 if (lpfc_sli_issue_mbox (phba, mbox, MBX_NOWAIT)
3324 != MBX_NOT_FINISHED)
3325 /* Mbox completion will send ELS Response */
3329 mempool_free(mbox, phba->mbox_mem_pool);
3332 stat.un.b.lsRjtRsvd0 = 0;
3333 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3334 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
3335 stat.un.b.vendorUnique = 0;
3336 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
3341 lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
3342 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
3344 struct lpfc_hba *phba = vport->phba;
3345 IOCB_t *icmd, *oldcmd;
3347 struct lpfc_iocbq *elsiocb;
3348 struct lpfc_sli *psli = &phba->sli;
3349 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
3352 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3353 ndlp->nlp_DID, ELS_CMD_ACC);
3358 icmd = &elsiocb->iocb;
3359 oldcmd = &oldiocb->iocb;
3360 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3362 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3363 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
3364 pcmd += sizeof(uint16_t);
3365 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
3366 pcmd += sizeof(uint16_t);
3368 /* Setup the RPL ACC payload */
3369 rpl_rsp.listLen = be32_to_cpu(1);
3371 rpl_rsp.port_num_blk.portNum = 0;
3372 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
3373 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
3374 sizeof(struct lpfc_name));
3375 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
3376 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
3377 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3378 "0120 Xmit ELS RPL ACC response tag x%x "
3379 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
3381 elsiocb->iotag, elsiocb->iocb.ulpContext,
3382 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3384 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
3385 phba->fc_stat.elsXmitACC++;
3386 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
3387 lpfc_els_free_iocb(phba, elsiocb);
3394 lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3395 struct lpfc_nodelist *ndlp)
3397 struct lpfc_dmabuf *pcmd;
3404 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
3405 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
3406 stat.un.b.lsRjtRsvd0 = 0;
3407 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3408 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
3409 stat.un.b.vendorUnique = 0;
3410 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
3414 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3415 lp = (uint32_t *) pcmd->virt;
3416 rpl = (RPL *) (lp + 1);
3418 maxsize = be32_to_cpu(rpl->maxsize);
3420 /* We support only one port */
3421 if ((rpl->index == 0) &&
3423 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
3424 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
3426 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
3428 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
3434 lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3435 struct lpfc_nodelist *ndlp)
3437 struct lpfc_dmabuf *pcmd;
3441 uint32_t cmd, cnt, did;
3443 icmd = &cmdiocb->iocb;
3444 did = icmd->un.elsreq64.remoteID;
3445 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3446 lp = (uint32_t *) pcmd->virt;
3450 /* FARP-REQ received from DID <did> */
3451 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3452 "0601 FARP-REQ received from DID x%x\n", did);
3453 /* We will only support match on WWPN or WWNN */
3454 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
3459 /* If this FARP command is searching for my portname */
3460 if (fp->Mflags & FARP_MATCH_PORT) {
3461 if (memcmp(&fp->RportName, &vport->fc_portname,
3462 sizeof(struct lpfc_name)) == 0)
3466 /* If this FARP command is searching for my nodename */
3467 if (fp->Mflags & FARP_MATCH_NODE) {
3468 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
3469 sizeof(struct lpfc_name)) == 0)
3474 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
3475 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
3476 /* Log back into the node before sending the FARP. */
3477 if (fp->Rflags & FARP_REQUEST_PLOGI) {
3478 ndlp->nlp_prev_state = ndlp->nlp_state;
3479 lpfc_nlp_set_state(vport, ndlp,
3480 NLP_STE_PLOGI_ISSUE);
3481 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
3484 /* Send a FARP response to that node */
3485 if (fp->Rflags & FARP_REQUEST_FARPR)
3486 lpfc_issue_els_farpr(vport, did, 0);
3493 lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3494 struct lpfc_nodelist *ndlp)
3496 struct lpfc_dmabuf *pcmd;
3501 icmd = &cmdiocb->iocb;
3502 did = icmd->un.elsreq64.remoteID;
3503 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3504 lp = (uint32_t *) pcmd->virt;
3507 /* FARP-RSP received from DID <did> */
3508 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3509 "0600 FARP-RSP received from DID x%x\n", did);
3510 /* ACCEPT the Farp resp request */
3511 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
3517 lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3518 struct lpfc_nodelist *fan_ndlp)
3520 struct lpfc_dmabuf *pcmd;
3525 struct lpfc_nodelist *ndlp, *next_ndlp;
3526 struct lpfc_hba *phba = vport->phba;
3529 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3530 "0265 FAN received\n");
3531 icmd = &cmdiocb->iocb;
3532 did = icmd->un.elsreq64.remoteID;
3533 pcmd = (struct lpfc_dmabuf *)cmdiocb->context2;
3534 lp = (uint32_t *)pcmd->virt;
3539 /* FAN received; Fan does not have a reply sequence */
3541 if (phba->pport->port_state == LPFC_LOCAL_CFG_LINK) {
3542 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
3543 sizeof(struct lpfc_name)) != 0) ||
3544 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
3545 sizeof(struct lpfc_name)) != 0)) {
3547 * This node has switched fabrics. FLOGI is required
3548 * Clean up the old rpi's
3551 list_for_each_entry_safe(ndlp, next_ndlp,
3552 &vport->fc_nodes, nlp_listp) {
3553 if (ndlp->nlp_state != NLP_STE_NPR_NODE)
3555 if (ndlp->nlp_type & NLP_FABRIC) {
3557 * Clean up old Fabric, Nameserver and
3558 * other NLP_FABRIC logins
3560 lpfc_drop_node(vport, ndlp);
3562 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
3563 /* Fail outstanding I/O now since this
3564 * device is marked for PLOGI
3566 lpfc_unreg_rpi(vport, ndlp);
3570 lpfc_initial_flogi(vport);
3573 /* Discovery not needed,
3574 * move the nodes to their original state.
3576 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
3578 if (ndlp->nlp_state != NLP_STE_NPR_NODE)
3581 switch (ndlp->nlp_prev_state) {
3582 case NLP_STE_UNMAPPED_NODE:
3583 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
3584 lpfc_nlp_set_state(vport, ndlp,
3585 NLP_STE_UNMAPPED_NODE);
3588 case NLP_STE_MAPPED_NODE:
3589 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
3590 lpfc_nlp_set_state(vport, ndlp,
3591 NLP_STE_MAPPED_NODE);
3599 /* Start discovery - this should just do CLEAR_LA */
3600 lpfc_disc_start(vport);
3606 lpfc_els_timeout(unsigned long ptr)
3608 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
3609 struct lpfc_hba *phba = vport->phba;
3610 unsigned long iflag;
3612 spin_lock_irqsave(&vport->work_port_lock, iflag);
3613 if ((vport->work_port_events & WORKER_ELS_TMO) == 0) {
3614 vport->work_port_events |= WORKER_ELS_TMO;
3615 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
3617 spin_lock_irqsave(&phba->hbalock, iflag);
3618 if (phba->work_wait)
3619 lpfc_worker_wake_up(phba);
3620 spin_unlock_irqrestore(&phba->hbalock, iflag);
3623 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
3628 lpfc_els_timeout_handler(struct lpfc_vport *vport)
3630 struct lpfc_hba *phba = vport->phba;
3631 struct lpfc_sli_ring *pring;
3632 struct lpfc_iocbq *tmp_iocb, *piocb;
3634 struct lpfc_dmabuf *pcmd;
3635 uint32_t els_command = 0;
3637 uint32_t remote_ID = 0xffffffff;
3639 /* If the timer is already canceled do nothing */
3640 if ((vport->work_port_events & WORKER_ELS_TMO) == 0) {
3643 spin_lock_irq(&phba->hbalock);
3644 timeout = (uint32_t)(phba->fc_ratov << 1);
3646 pring = &phba->sli.ring[LPFC_ELS_RING];
3648 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
3651 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
3652 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
3653 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
3656 if (piocb->vport != vport)
3659 pcmd = (struct lpfc_dmabuf *) piocb->context2;
3661 els_command = *(uint32_t *) (pcmd->virt);
3663 if (els_command == ELS_CMD_FARP ||
3664 els_command == ELS_CMD_FARPR ||
3665 els_command == ELS_CMD_FDISC)
3668 if (vport != piocb->vport)
3671 if (piocb->drvrTimeout > 0) {
3672 if (piocb->drvrTimeout >= timeout)
3673 piocb->drvrTimeout -= timeout;
3675 piocb->drvrTimeout = 0;
3679 remote_ID = 0xffffffff;
3680 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
3681 remote_ID = cmd->un.elsreq64.remoteID;
3683 struct lpfc_nodelist *ndlp;
3684 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
3686 remote_ID = ndlp->nlp_DID;
3688 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3689 "0127 ELS timeout Data: x%x x%x x%x "
3690 "x%x\n", els_command,
3691 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
3692 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
3694 spin_unlock_irq(&phba->hbalock);
3696 if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt)
3697 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
3701 lpfc_els_flush_cmd(struct lpfc_vport *vport)
3703 LIST_HEAD(completions);
3704 struct lpfc_hba *phba = vport->phba;
3705 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
3706 struct lpfc_iocbq *tmp_iocb, *piocb;
3709 lpfc_fabric_abort_vport(vport);
3711 spin_lock_irq(&phba->hbalock);
3712 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
3715 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
3719 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
3720 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
3721 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
3722 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
3723 cmd->ulpCommand == CMD_ABORT_XRI_CN)
3726 if (piocb->vport != vport)
3729 list_move_tail(&piocb->list, &completions);
3733 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
3734 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
3738 if (piocb->vport != vport)
3741 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
3743 spin_unlock_irq(&phba->hbalock);
3745 while (!list_empty(&completions)) {
3746 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
3748 list_del_init(&piocb->list);
3750 if (!piocb->iocb_cmpl)
3751 lpfc_sli_release_iocbq(phba, piocb);
3753 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
3754 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
3755 (piocb->iocb_cmpl) (phba, piocb, piocb);
3763 lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
3765 LIST_HEAD(completions);
3766 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
3767 struct lpfc_iocbq *tmp_iocb, *piocb;
3770 lpfc_fabric_abort_hba(phba);
3771 spin_lock_irq(&phba->hbalock);
3772 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
3774 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
3776 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
3777 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
3778 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
3779 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
3780 cmd->ulpCommand == CMD_ABORT_XRI_CN)
3782 list_move_tail(&piocb->list, &completions);
3785 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
3786 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
3788 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
3790 spin_unlock_irq(&phba->hbalock);
3791 while (!list_empty(&completions)) {
3792 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
3794 list_del_init(&piocb->list);
3795 if (!piocb->iocb_cmpl)
3796 lpfc_sli_release_iocbq(phba, piocb);
3798 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
3799 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
3800 (piocb->iocb_cmpl) (phba, piocb, piocb);
3807 lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3808 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
3810 struct Scsi_Host *shost;
3811 struct lpfc_nodelist *ndlp;
3814 uint32_t cmd, did, newnode, rjt_err = 0;
3815 IOCB_t *icmd = &elsiocb->iocb;
3817 if (vport == NULL || elsiocb->context2 == NULL)
3821 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
3823 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
3824 lpfc_post_buffer(phba, pring, 1, 1);
3826 did = icmd->un.rcvels.remoteID;
3827 if (icmd->ulpStatus) {
3828 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3829 "RCV Unsol ELS: status:x%x/x%x did:x%x",
3830 icmd->ulpStatus, icmd->un.ulpWord[4], did);
3834 /* Check to see if link went down during discovery */
3835 if (lpfc_els_chk_latt(vport))
3838 /* Ignore traffic recevied during vport shutdown. */
3839 if (vport->load_flag & FC_UNLOADING)
3842 ndlp = lpfc_findnode_did(vport, did);
3844 /* Cannot find existing Fabric ndlp, so allocate a new one */
3845 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
3849 lpfc_nlp_init(vport, ndlp, did);
3850 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
3852 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) {
3853 ndlp->nlp_type |= NLP_FABRIC;
3857 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
3858 /* This is simular to the new node path */
3860 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
3865 phba->fc_stat.elsRcvFrame++;
3866 if (elsiocb->context1)
3867 lpfc_nlp_put(elsiocb->context1);
3868 elsiocb->context1 = lpfc_nlp_get(ndlp);
3869 elsiocb->vport = vport;
3871 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
3872 cmd &= ELS_CMD_MASK;
3874 /* ELS command <elsCmd> received from NPORT <did> */
3875 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3876 "0112 ELS command x%x received from NPORT x%x "
3877 "Data: x%x\n", cmd, did, vport->port_state);
3880 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3881 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
3882 did, vport->port_state, ndlp->nlp_flag);
3884 phba->fc_stat.elsRcvPLOGI++;
3885 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
3887 if (vport->port_state < LPFC_DISC_AUTH) {
3888 rjt_err = LSRJT_UNABLE_TPC;
3892 shost = lpfc_shost_from_vport(vport);
3893 spin_lock_irq(shost->host_lock);
3894 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
3895 spin_unlock_irq(shost->host_lock);
3897 lpfc_disc_state_machine(vport, ndlp, elsiocb,
3902 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3903 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
3904 did, vport->port_state, ndlp->nlp_flag);
3906 phba->fc_stat.elsRcvFLOGI++;
3907 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
3912 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3913 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
3914 did, vport->port_state, ndlp->nlp_flag);
3916 phba->fc_stat.elsRcvLOGO++;
3917 if (vport->port_state < LPFC_DISC_AUTH) {
3918 rjt_err = LSRJT_UNABLE_TPC;
3921 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
3924 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3925 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
3926 did, vport->port_state, ndlp->nlp_flag);
3928 phba->fc_stat.elsRcvPRLO++;
3929 if (vport->port_state < LPFC_DISC_AUTH) {
3930 rjt_err = LSRJT_UNABLE_TPC;
3933 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
3936 phba->fc_stat.elsRcvRSCN++;
3937 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
3942 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3943 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
3944 did, vport->port_state, ndlp->nlp_flag);
3946 phba->fc_stat.elsRcvADISC++;
3947 if (vport->port_state < LPFC_DISC_AUTH) {
3948 rjt_err = LSRJT_UNABLE_TPC;
3951 lpfc_disc_state_machine(vport, ndlp, elsiocb,
3955 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3956 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
3957 did, vport->port_state, ndlp->nlp_flag);
3959 phba->fc_stat.elsRcvPDISC++;
3960 if (vport->port_state < LPFC_DISC_AUTH) {
3961 rjt_err = LSRJT_UNABLE_TPC;
3964 lpfc_disc_state_machine(vport, ndlp, elsiocb,
3968 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3969 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
3970 did, vport->port_state, ndlp->nlp_flag);
3972 phba->fc_stat.elsRcvFARPR++;
3973 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
3976 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3977 "RCV FARP: did:x%x/ste:x%x flg:x%x",
3978 did, vport->port_state, ndlp->nlp_flag);
3980 phba->fc_stat.elsRcvFARP++;
3981 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
3984 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3985 "RCV FAN: did:x%x/ste:x%x flg:x%x",
3986 did, vport->port_state, ndlp->nlp_flag);
3988 phba->fc_stat.elsRcvFAN++;
3989 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
3992 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3993 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
3994 did, vport->port_state, ndlp->nlp_flag);
3996 phba->fc_stat.elsRcvPRLI++;
3997 if (vport->port_state < LPFC_DISC_AUTH) {
3998 rjt_err = LSRJT_UNABLE_TPC;
4001 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
4004 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4005 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
4006 did, vport->port_state, ndlp->nlp_flag);
4008 phba->fc_stat.elsRcvLIRR++;
4009 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
4014 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4015 "RCV RPS: did:x%x/ste:x%x flg:x%x",
4016 did, vport->port_state, ndlp->nlp_flag);
4018 phba->fc_stat.elsRcvRPS++;
4019 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
4024 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4025 "RCV RPL: did:x%x/ste:x%x flg:x%x",
4026 did, vport->port_state, ndlp->nlp_flag);
4028 phba->fc_stat.elsRcvRPL++;
4029 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
4034 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4035 "RCV RNID: did:x%x/ste:x%x flg:x%x",
4036 did, vport->port_state, ndlp->nlp_flag);
4038 phba->fc_stat.elsRcvRNID++;
4039 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
4044 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4045 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
4046 cmd, did, vport->port_state);
4048 /* Unsupported ELS command, reject */
4049 rjt_err = LSRJT_INVALID_CMD;
4051 /* Unknown ELS command <elsCmd> received from NPORT <did> */
4052 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4053 "0115 Unknown ELS command x%x "
4054 "received from NPORT x%x\n", cmd, did);
4060 /* check if need to LS_RJT received ELS cmd */
4062 memset(&stat, 0, sizeof(stat));
4063 stat.un.b.lsRjtRsnCode = rjt_err;
4064 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
4065 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
4072 if (vport && !(vport->load_flag & FC_UNLOADING))
4073 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
4074 "(%d):0111 Dropping received ELS cmd "
4075 "Data: x%x x%x x%x\n",
4076 vport->vpi, icmd->ulpStatus,
4077 icmd->un.ulpWord[4], icmd->ulpTimeout);
4078 phba->fc_stat.elsRcvDrop++;
4081 static struct lpfc_vport *
4082 lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
4084 struct lpfc_vport *vport;
4085 unsigned long flags;
4087 spin_lock_irqsave(&phba->hbalock, flags);
4088 list_for_each_entry(vport, &phba->port_list, listentry) {
4089 if (vport->vpi == vpi) {
4090 spin_unlock_irqrestore(&phba->hbalock, flags);
4094 spin_unlock_irqrestore(&phba->hbalock, flags);
4099 lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
4100 struct lpfc_iocbq *elsiocb)
4102 struct lpfc_vport *vport = phba->pport;
4103 IOCB_t *icmd = &elsiocb->iocb;
4105 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
4106 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
4108 elsiocb->context2 = NULL;
4109 elsiocb->context3 = NULL;
4111 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
4112 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
4113 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
4114 (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) {
4115 phba->fc_stat.NoRcvBuf++;
4116 /* Not enough posted buffers; Try posting more buffers */
4117 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
4118 lpfc_post_buffer(phba, pring, 0, 1);
4122 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
4123 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
4124 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
4125 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
4126 vport = phba->pport;
4128 uint16_t vpi = icmd->unsli3.rcvsli3.vpi;
4129 vport = lpfc_find_vport_by_vpid(phba, vpi);
4132 /* If there are no BDEs associated
4133 * with this IOCB, there is nothing to do.
4135 if (icmd->ulpBdeCount == 0)
4138 /* type of ELS cmd is first 32bit word
4141 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
4142 elsiocb->context2 = bdeBuf1;
4144 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
4145 icmd->un.cont64[0].addrLow);
4146 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
4150 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
4152 * The different unsolicited event handlers would tell us
4153 * if they are done with "mp" by setting context2 to NULL.
4155 lpfc_nlp_put(elsiocb->context1);
4156 elsiocb->context1 = NULL;
4157 if (elsiocb->context2) {
4158 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
4159 elsiocb->context2 = NULL;
4162 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
4163 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
4164 icmd->ulpBdeCount == 2) {
4165 elsiocb->context2 = bdeBuf2;
4166 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
4167 /* free mp if we are done with it */
4168 if (elsiocb->context2) {
4169 lpfc_in_buf_free(phba, elsiocb->context2);
4170 elsiocb->context2 = NULL;
4176 lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
4178 struct lpfc_nodelist *ndlp, *ndlp_fdmi;
4180 ndlp = lpfc_findnode_did(vport, NameServer_DID);
4182 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
4184 if (phba->fc_topology == TOPOLOGY_LOOP) {
4185 lpfc_disc_start(vport);
4188 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4189 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4190 "0251 NameServer login: no memory\n");
4193 lpfc_nlp_init(vport, ndlp, NameServer_DID);
4194 ndlp->nlp_type |= NLP_FABRIC;
4197 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
4199 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
4200 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4201 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4202 "0252 Cannot issue NameServer login\n");
4206 if (vport->cfg_fdmi_on) {
4207 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
4210 lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
4211 ndlp_fdmi->nlp_type |= NLP_FABRIC;
4212 ndlp_fdmi->nlp_state =
4213 NLP_STE_PLOGI_ISSUE;
4214 lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID,
4222 lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4224 struct lpfc_vport *vport = pmb->vport;
4225 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4226 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
4227 MAILBOX_t *mb = &pmb->mb;
4229 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
4232 if (mb->mbxStatus) {
4233 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
4234 "0915 Register VPI failed: 0x%x\n",
4237 switch (mb->mbxStatus) {
4238 case 0x11: /* unsupported feature */
4239 case 0x9603: /* max_vpi exceeded */
4240 /* giving up on vport registration */
4241 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4242 spin_lock_irq(shost->host_lock);
4243 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
4244 spin_unlock_irq(shost->host_lock);
4245 lpfc_can_disctmo(vport);
4248 /* Try to recover from this error */
4249 lpfc_mbx_unreg_vpi(vport);
4250 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
4251 lpfc_initial_fdisc(vport);
4256 if (vport == phba->pport)
4257 lpfc_issue_fabric_reglogin(vport);
4259 lpfc_do_scr_ns_plogi(phba, vport);
4261 mempool_free(pmb, phba->mbox_mem_pool);
4266 lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
4267 struct lpfc_nodelist *ndlp)
4271 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4273 lpfc_reg_vpi(phba, vport->vpi, vport->fc_myDID, mbox);
4274 mbox->vport = vport;
4275 mbox->context2 = lpfc_nlp_get(ndlp);
4276 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
4277 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
4278 == MBX_NOT_FINISHED) {
4279 mempool_free(mbox, phba->mbox_mem_pool);
4280 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
4282 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4283 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
4284 "0253 Register VPI: Can't send mbox\n");
4287 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4289 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
4290 "0254 Register VPI: no memory\n");
4292 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
4298 lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4299 struct lpfc_iocbq *rspiocb)
4301 struct lpfc_vport *vport = cmdiocb->vport;
4302 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4303 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
4304 struct lpfc_nodelist *np;
4305 struct lpfc_nodelist *next_np;
4306 IOCB_t *irsp = &rspiocb->iocb;
4307 struct lpfc_iocbq *piocb;
4309 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4310 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
4311 irsp->ulpStatus, irsp->un.ulpWord[4],
4313 /* Since all FDISCs are being single threaded, we
4314 * must reset the discovery timer for ALL vports
4315 * waiting to send FDISC when one completes.
4317 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
4318 lpfc_set_disctmo(piocb->vport);
4321 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4322 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
4323 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
4325 if (irsp->ulpStatus) {
4326 /* Check for retry */
4327 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
4330 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4331 "0124 FDISC failed. (%d/%d)\n",
4332 irsp->ulpStatus, irsp->un.ulpWord[4]);
4333 if (vport->fc_vport->vport_state == FC_VPORT_INITIALIZING)
4334 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4337 /* giving up on FDISC. Cancel discovery timer */
4338 lpfc_can_disctmo(vport);
4340 spin_lock_irq(shost->host_lock);
4341 vport->fc_flag |= FC_FABRIC;
4342 if (vport->phba->fc_topology == TOPOLOGY_LOOP)
4343 vport->fc_flag |= FC_PUBLIC_LOOP;
4344 spin_unlock_irq(shost->host_lock);
4346 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
4347 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
4348 if ((vport->fc_prevDID != vport->fc_myDID) &&
4349 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
4350 /* If our NportID changed, we need to ensure all
4351 * remaining NPORTs get unreg_login'ed so we can
4354 list_for_each_entry_safe(np, next_np,
4355 &vport->fc_nodes, nlp_listp) {
4356 if (np->nlp_state != NLP_STE_NPR_NODE
4357 || !(np->nlp_flag & NLP_NPR_ADISC))
4359 spin_lock_irq(shost->host_lock);
4360 np->nlp_flag &= ~NLP_NPR_ADISC;
4361 spin_unlock_irq(shost->host_lock);
4362 lpfc_unreg_rpi(vport, np);
4364 lpfc_mbx_unreg_vpi(vport);
4365 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
4368 if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
4369 lpfc_register_new_vport(phba, vport, ndlp);
4371 lpfc_do_scr_ns_plogi(phba, vport);
4373 lpfc_nlp_put(ndlp); /* Free Fabric ndlp for vports */
4377 lpfc_els_free_iocb(phba, cmdiocb);
4381 lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4384 struct lpfc_hba *phba = vport->phba;
4386 struct lpfc_iocbq *elsiocb;
4387 struct serv_parm *sp;
4390 int did = ndlp->nlp_DID;
4393 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
4394 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
4397 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4398 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4399 "0255 Issue FDISC: no IOCB\n");
4403 icmd = &elsiocb->iocb;
4404 icmd->un.elsreq64.myID = 0;
4405 icmd->un.elsreq64.fl = 1;
4407 /* For FDISC, Let FDISC rsp set the NPortID for this VPI */
4411 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4412 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
4413 pcmd += sizeof(uint32_t); /* CSP Word 1 */
4414 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
4415 sp = (struct serv_parm *) pcmd;
4416 /* Setup CSPs accordingly for Fabric */
4417 sp->cmn.e_d_tov = 0;
4418 sp->cmn.w2.r_a_tov = 0;
4419 sp->cls1.classValid = 0;
4420 sp->cls2.seqDelivery = 1;
4421 sp->cls3.seqDelivery = 1;
4423 pcmd += sizeof(uint32_t); /* CSP Word 2 */
4424 pcmd += sizeof(uint32_t); /* CSP Word 3 */
4425 pcmd += sizeof(uint32_t); /* CSP Word 4 */
4426 pcmd += sizeof(uint32_t); /* Port Name */
4427 memcpy(pcmd, &vport->fc_portname, 8);
4428 pcmd += sizeof(uint32_t); /* Node Name */
4429 pcmd += sizeof(uint32_t); /* Node Name */
4430 memcpy(pcmd, &vport->fc_nodename, 8);
4432 lpfc_set_disctmo(vport);
4434 phba->fc_stat.elsXmitFDISC++;
4435 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
4437 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4438 "Issue FDISC: did:x%x",
4441 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
4442 if (rc == IOCB_ERROR) {
4443 lpfc_els_free_iocb(phba, elsiocb);
4444 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4445 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4446 "0256 Issue FDISC: Cannot send IOCB\n");
4449 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
4450 vport->port_state = LPFC_FDISC;
4455 lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4456 struct lpfc_iocbq *rspiocb)
4458 struct lpfc_vport *vport = cmdiocb->vport;
4461 irsp = &rspiocb->iocb;
4462 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4463 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
4464 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
4466 lpfc_els_free_iocb(phba, cmdiocb);
4467 vport->unreg_vpi_cmpl = VPORT_ERROR;
4471 lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4473 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4474 struct lpfc_hba *phba = vport->phba;
4475 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
4477 struct lpfc_iocbq *elsiocb;
4481 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
4482 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
4487 icmd = &elsiocb->iocb;
4488 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4489 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
4490 pcmd += sizeof(uint32_t);
4492 /* Fill in LOGO payload */
4493 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
4494 pcmd += sizeof(uint32_t);
4495 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
4497 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4498 "Issue LOGO npiv did:x%x flg:x%x",
4499 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4501 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
4502 spin_lock_irq(shost->host_lock);
4503 ndlp->nlp_flag |= NLP_LOGO_SND;
4504 spin_unlock_irq(shost->host_lock);
4505 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
4506 spin_lock_irq(shost->host_lock);
4507 ndlp->nlp_flag &= ~NLP_LOGO_SND;
4508 spin_unlock_irq(shost->host_lock);
4509 lpfc_els_free_iocb(phba, elsiocb);
4516 lpfc_fabric_block_timeout(unsigned long ptr)
4518 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
4519 unsigned long iflags;
4520 uint32_t tmo_posted;
4521 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
4522 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
4524 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
4525 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
4528 spin_lock_irqsave(&phba->hbalock, iflags);
4529 if (phba->work_wait)
4530 lpfc_worker_wake_up(phba);
4531 spin_unlock_irqrestore(&phba->hbalock, iflags);
4536 lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
4538 struct lpfc_iocbq *iocb;
4539 unsigned long iflags;
4541 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
4546 spin_lock_irqsave(&phba->hbalock, iflags);
4547 /* Post any pending iocb to the SLI layer */
4548 if (atomic_read(&phba->fabric_iocb_count) == 0) {
4549 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
4552 atomic_inc(&phba->fabric_iocb_count);
4554 spin_unlock_irqrestore(&phba->hbalock, iflags);
4556 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
4557 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
4558 iocb->iocb_flag |= LPFC_IO_FABRIC;
4560 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
4561 "Fabric sched1: ste:x%x",
4562 iocb->vport->port_state, 0, 0);
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;
4571 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
4572 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
4573 iocb->iocb_cmpl(phba, iocb, iocb);
4575 atomic_dec(&phba->fabric_iocb_count);
4584 lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
4586 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
4588 lpfc_resume_fabric_iocbs(phba);
4593 lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
4597 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
4598 /* Start a timer to unblock fabric
4602 mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 );
4608 lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4609 struct lpfc_iocbq *rspiocb)
4613 if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
4616 switch (rspiocb->iocb.ulpStatus) {
4617 case IOSTAT_NPORT_RJT:
4618 case IOSTAT_FABRIC_RJT:
4619 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
4620 lpfc_block_fabric_iocbs(phba);
4624 case IOSTAT_NPORT_BSY:
4625 case IOSTAT_FABRIC_BSY:
4626 lpfc_block_fabric_iocbs(phba);
4630 stat.un.lsRjtError =
4631 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
4632 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
4633 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
4634 lpfc_block_fabric_iocbs(phba);
4638 if (atomic_read(&phba->fabric_iocb_count) == 0)
4641 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
4642 cmdiocb->fabric_iocb_cmpl = NULL;
4643 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
4644 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
4646 atomic_dec(&phba->fabric_iocb_count);
4647 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
4648 /* Post any pending iocbs to HBA */
4649 lpfc_resume_fabric_iocbs(phba);
4654 lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
4656 unsigned long iflags;
4657 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
4661 if (atomic_read(&phba->fabric_iocb_count) > 1)
4664 spin_lock_irqsave(&phba->hbalock, iflags);
4665 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
4666 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
4668 spin_unlock_irqrestore(&phba->hbalock, iflags);
4670 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
4671 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
4672 iocb->iocb_flag |= LPFC_IO_FABRIC;
4674 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
4675 "Fabric sched2: ste:x%x",
4676 iocb->vport->port_state, 0, 0);
4678 atomic_inc(&phba->fabric_iocb_count);
4679 ret = lpfc_sli_issue_iocb(phba, pring, iocb, 0);
4681 if (ret == IOCB_ERROR) {
4682 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
4683 iocb->fabric_iocb_cmpl = NULL;
4684 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
4685 atomic_dec(&phba->fabric_iocb_count);
4688 spin_lock_irqsave(&phba->hbalock, iflags);
4689 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
4690 spin_unlock_irqrestore(&phba->hbalock, iflags);
4697 static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
4699 LIST_HEAD(completions);
4700 struct lpfc_hba *phba = vport->phba;
4701 struct lpfc_iocbq *tmp_iocb, *piocb;
4704 spin_lock_irq(&phba->hbalock);
4705 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
4708 if (piocb->vport != vport)
4711 list_move_tail(&piocb->list, &completions);
4713 spin_unlock_irq(&phba->hbalock);
4715 while (!list_empty(&completions)) {
4716 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
4717 list_del_init(&piocb->list);
4720 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
4721 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
4722 (piocb->iocb_cmpl) (phba, piocb, piocb);
4726 void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
4728 LIST_HEAD(completions);
4729 struct lpfc_hba *phba = ndlp->vport->phba;
4730 struct lpfc_iocbq *tmp_iocb, *piocb;
4731 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
4734 spin_lock_irq(&phba->hbalock);
4735 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
4737 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
4739 list_move_tail(&piocb->list, &completions);
4742 spin_unlock_irq(&phba->hbalock);
4744 while (!list_empty(&completions)) {
4745 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
4746 list_del_init(&piocb->list);
4749 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
4750 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
4751 (piocb->iocb_cmpl) (phba, piocb, piocb);
4755 void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
4757 LIST_HEAD(completions);
4758 struct lpfc_iocbq *piocb;
4761 spin_lock_irq(&phba->hbalock);
4762 list_splice_init(&phba->fabric_iocb_list, &completions);
4763 spin_unlock_irq(&phba->hbalock);
4765 while (!list_empty(&completions)) {
4766 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
4767 list_del_init(&piocb->list);
4770 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
4771 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
4772 (piocb->iocb_cmpl) (phba, piocb, piocb);
4778 void lpfc_fabric_abort_flogi(struct lpfc_hba *phba)
4780 LIST_HEAD(completions);
4781 struct lpfc_iocbq *tmp_iocb, *piocb;
4783 struct lpfc_nodelist *ndlp;
4785 spin_lock_irq(&phba->hbalock);
4786 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
4790 ndlp = (struct lpfc_nodelist *) piocb->context1;
4791 if (cmd->ulpCommand == CMD_ELS_REQUEST64_CR &&
4793 ndlp->nlp_DID == Fabric_DID)
4794 list_move_tail(&piocb->list, &completions);
4796 spin_unlock_irq(&phba->hbalock);
4798 while (!list_empty(&completions)) {
4799 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
4800 list_del_init(&piocb->list);
4803 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
4804 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
4805 (piocb->iocb_cmpl) (phba, piocb, piocb);