1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2008 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 *******************************************************************/
21 /* See Fibre Channel protocol T11 FC-LS for details */
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
);
117 icmd
= &elsiocb
->iocb
;
119 /* fill in BDEs for command */
120 /* Allocate buffer for command payload */
121 pcmd
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
123 pcmd
->virt
= lpfc_mbuf_alloc(phba
, MEM_PRI
, &pcmd
->phys
);
124 if (!pcmd
|| !pcmd
->virt
)
125 goto els_iocb_free_pcmb_exit
;
127 INIT_LIST_HEAD(&pcmd
->list
);
129 /* Allocate buffer for response payload */
131 prsp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
133 prsp
->virt
= lpfc_mbuf_alloc(phba
, MEM_PRI
,
135 if (!prsp
|| !prsp
->virt
)
136 goto els_iocb_free_prsp_exit
;
137 INIT_LIST_HEAD(&prsp
->list
);
141 /* Allocate buffer for Buffer ptr list */
142 pbuflist
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
144 pbuflist
->virt
= lpfc_mbuf_alloc(phba
, MEM_PRI
,
146 if (!pbuflist
|| !pbuflist
->virt
)
147 goto els_iocb_free_pbuf_exit
;
149 INIT_LIST_HEAD(&pbuflist
->list
);
151 icmd
->un
.elsreq64
.bdl
.addrHigh
= putPaddrHigh(pbuflist
->phys
);
152 icmd
->un
.elsreq64
.bdl
.addrLow
= putPaddrLow(pbuflist
->phys
);
153 icmd
->un
.elsreq64
.bdl
.bdeFlags
= BUFF_TYPE_BDL
;
154 icmd
->un
.elsreq64
.remoteID
= did
; /* DID */
156 icmd
->un
.elsreq64
.bdl
.bdeSize
= (2 * sizeof(struct ulp_bde64
));
157 icmd
->ulpCommand
= CMD_ELS_REQUEST64_CR
;
158 icmd
->ulpTimeout
= phba
->fc_ratov
* 2;
160 icmd
->un
.elsreq64
.bdl
.bdeSize
= sizeof(struct ulp_bde64
);
161 icmd
->ulpCommand
= CMD_XMIT_ELS_RSP64_CX
;
163 icmd
->ulpBdeCount
= 1;
165 icmd
->ulpClass
= CLASS3
;
167 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) {
168 icmd
->un
.elsreq64
.myID
= vport
->fc_myDID
;
170 /* For ELS_REQUEST64_CR, use the VPI by default */
171 icmd
->ulpContext
= vport
->vpi
;
176 bpl
= (struct ulp_bde64
*) pbuflist
->virt
;
177 bpl
->addrLow
= le32_to_cpu(putPaddrLow(pcmd
->phys
));
178 bpl
->addrHigh
= le32_to_cpu(putPaddrHigh(pcmd
->phys
));
179 bpl
->tus
.f
.bdeSize
= cmdSize
;
180 bpl
->tus
.f
.bdeFlags
= 0;
181 bpl
->tus
.w
= le32_to_cpu(bpl
->tus
.w
);
185 bpl
->addrLow
= le32_to_cpu(putPaddrLow(prsp
->phys
));
186 bpl
->addrHigh
= le32_to_cpu(putPaddrHigh(prsp
->phys
));
187 bpl
->tus
.f
.bdeSize
= FCELSSIZE
;
188 bpl
->tus
.f
.bdeFlags
= BUFF_USE_RCV
;
189 bpl
->tus
.w
= le32_to_cpu(bpl
->tus
.w
);
192 /* prevent preparing iocb with NULL ndlp reference */
193 elsiocb
->context1
= lpfc_nlp_get(ndlp
);
194 if (!elsiocb
->context1
)
195 goto els_iocb_free_pbuf_exit
;
196 elsiocb
->context2
= pcmd
;
197 elsiocb
->context3
= pbuflist
;
198 elsiocb
->retry
= retry
;
199 elsiocb
->vport
= vport
;
200 elsiocb
->drvrTimeout
= (phba
->fc_ratov
<< 1) + LPFC_DRVR_TIMEOUT
;
203 list_add(&prsp
->list
, &pcmd
->list
);
206 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
207 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
208 "0116 Xmit ELS command x%x to remote "
209 "NPORT x%x I/O tag: x%x, port state: x%x\n",
210 elscmd
, did
, elsiocb
->iotag
,
213 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
214 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
215 "0117 Xmit ELS response x%x to remote "
216 "NPORT x%x I/O tag: x%x, size: x%x\n",
217 elscmd
, ndlp
->nlp_DID
, elsiocb
->iotag
,
222 els_iocb_free_pbuf_exit
:
223 lpfc_mbuf_free(phba
, prsp
->virt
, prsp
->phys
);
226 els_iocb_free_prsp_exit
:
227 lpfc_mbuf_free(phba
, pcmd
->virt
, pcmd
->phys
);
230 els_iocb_free_pcmb_exit
:
232 lpfc_sli_release_iocbq(phba
, elsiocb
);
237 lpfc_issue_fabric_reglogin(struct lpfc_vport
*vport
)
239 struct lpfc_hba
*phba
= vport
->phba
;
241 struct lpfc_dmabuf
*mp
;
242 struct lpfc_nodelist
*ndlp
;
243 struct serv_parm
*sp
;
247 sp
= &phba
->fc_fabparam
;
248 ndlp
= lpfc_findnode_did(vport
, Fabric_DID
);
249 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
)) {
254 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
260 vport
->port_state
= LPFC_FABRIC_CFG_LINK
;
261 lpfc_config_link(phba
, mbox
);
262 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
265 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
266 if (rc
== MBX_NOT_FINISHED
) {
271 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
276 rc
= lpfc_reg_login(phba
, vport
->vpi
, Fabric_DID
, (uint8_t *)sp
, mbox
,
283 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_fabric_reg_login
;
285 /* increment the reference count on ndlp to hold reference
286 * for the callback routine.
288 mbox
->context2
= lpfc_nlp_get(ndlp
);
290 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
291 if (rc
== MBX_NOT_FINISHED
) {
293 goto fail_issue_reg_login
;
298 fail_issue_reg_login
:
299 /* decrement the reference count on ndlp just incremented
300 * for the failed mbox command.
303 mp
= (struct lpfc_dmabuf
*) mbox
->context1
;
304 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
307 mempool_free(mbox
, phba
->mbox_mem_pool
);
310 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
311 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
312 "0249 Cannot issue Register Fabric login: Err %d\n", err
);
317 lpfc_cmpl_els_flogi_fabric(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
318 struct serv_parm
*sp
, IOCB_t
*irsp
)
320 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
321 struct lpfc_hba
*phba
= vport
->phba
;
322 struct lpfc_nodelist
*np
;
323 struct lpfc_nodelist
*next_np
;
325 spin_lock_irq(shost
->host_lock
);
326 vport
->fc_flag
|= FC_FABRIC
;
327 spin_unlock_irq(shost
->host_lock
);
329 phba
->fc_edtov
= be32_to_cpu(sp
->cmn
.e_d_tov
);
330 if (sp
->cmn
.edtovResolution
) /* E_D_TOV ticks are in nanoseconds */
331 phba
->fc_edtov
= (phba
->fc_edtov
+ 999999) / 1000000;
333 phba
->fc_ratov
= (be32_to_cpu(sp
->cmn
.w2
.r_a_tov
) + 999) / 1000;
335 if (phba
->fc_topology
== TOPOLOGY_LOOP
) {
336 spin_lock_irq(shost
->host_lock
);
337 vport
->fc_flag
|= FC_PUBLIC_LOOP
;
338 spin_unlock_irq(shost
->host_lock
);
341 * If we are a N-port connected to a Fabric, fixup sparam's so
342 * logins to devices on remote loops work.
344 vport
->fc_sparam
.cmn
.altBbCredit
= 1;
347 vport
->fc_myDID
= irsp
->un
.ulpWord
[4] & Mask_DID
;
348 memcpy(&ndlp
->nlp_portname
, &sp
->portName
, sizeof(struct lpfc_name
));
349 memcpy(&ndlp
->nlp_nodename
, &sp
->nodeName
, sizeof(struct lpfc_name
));
350 ndlp
->nlp_class_sup
= 0;
351 if (sp
->cls1
.classValid
)
352 ndlp
->nlp_class_sup
|= FC_COS_CLASS1
;
353 if (sp
->cls2
.classValid
)
354 ndlp
->nlp_class_sup
|= FC_COS_CLASS2
;
355 if (sp
->cls3
.classValid
)
356 ndlp
->nlp_class_sup
|= FC_COS_CLASS3
;
357 if (sp
->cls4
.classValid
)
358 ndlp
->nlp_class_sup
|= FC_COS_CLASS4
;
359 ndlp
->nlp_maxframe
= ((sp
->cmn
.bbRcvSizeMsb
& 0x0F) << 8) |
360 sp
->cmn
.bbRcvSizeLsb
;
361 memcpy(&phba
->fc_fabparam
, sp
, sizeof(struct serv_parm
));
363 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) {
364 if (sp
->cmn
.response_multiple_NPort
) {
365 lpfc_printf_vlog(vport
, KERN_WARNING
,
367 "1816 FLOGI NPIV supported, "
368 "response data 0x%x\n",
369 sp
->cmn
.response_multiple_NPort
);
370 phba
->link_flag
|= LS_NPIV_FAB_SUPPORTED
;
372 /* Because we asked f/w for NPIV it still expects us
373 to call reg_vnpid atleast for the physcial host */
374 lpfc_printf_vlog(vport
, KERN_WARNING
,
376 "1817 Fabric does not support NPIV "
377 "- configuring single port mode.\n");
378 phba
->link_flag
&= ~LS_NPIV_FAB_SUPPORTED
;
382 if ((vport
->fc_prevDID
!= vport
->fc_myDID
) &&
383 !(vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
)) {
385 /* If our NportID changed, we need to ensure all
386 * remaining NPORTs get unreg_login'ed.
388 list_for_each_entry_safe(np
, next_np
,
389 &vport
->fc_nodes
, nlp_listp
) {
390 if (!NLP_CHK_NODE_ACT(ndlp
))
392 if ((np
->nlp_state
!= NLP_STE_NPR_NODE
) ||
393 !(np
->nlp_flag
& NLP_NPR_ADISC
))
395 spin_lock_irq(shost
->host_lock
);
396 np
->nlp_flag
&= ~NLP_NPR_ADISC
;
397 spin_unlock_irq(shost
->host_lock
);
398 lpfc_unreg_rpi(vport
, np
);
400 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) {
401 lpfc_mbx_unreg_vpi(vport
);
402 spin_lock_irq(shost
->host_lock
);
403 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
404 spin_unlock_irq(shost
->host_lock
);
408 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_REG_LOGIN_ISSUE
);
410 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
&&
411 vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
) {
412 lpfc_register_new_vport(phba
, vport
, ndlp
);
415 lpfc_issue_fabric_reglogin(vport
);
420 * We FLOGIed into an NPort, initiate pt2pt protocol
423 lpfc_cmpl_els_flogi_nport(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
424 struct serv_parm
*sp
)
426 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
427 struct lpfc_hba
*phba
= vport
->phba
;
431 spin_lock_irq(shost
->host_lock
);
432 vport
->fc_flag
&= ~(FC_FABRIC
| FC_PUBLIC_LOOP
);
433 spin_unlock_irq(shost
->host_lock
);
435 phba
->fc_edtov
= FF_DEF_EDTOV
;
436 phba
->fc_ratov
= FF_DEF_RATOV
;
437 rc
= memcmp(&vport
->fc_portname
, &sp
->portName
,
438 sizeof(vport
->fc_portname
));
440 /* This side will initiate the PLOGI */
441 spin_lock_irq(shost
->host_lock
);
442 vport
->fc_flag
|= FC_PT2PT_PLOGI
;
443 spin_unlock_irq(shost
->host_lock
);
446 * N_Port ID cannot be 0, set our to LocalID the other
447 * side will be RemoteID.
452 vport
->fc_myDID
= PT2PT_LocalID
;
454 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
458 lpfc_config_link(phba
, mbox
);
460 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
462 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
463 if (rc
== MBX_NOT_FINISHED
) {
464 mempool_free(mbox
, phba
->mbox_mem_pool
);
467 /* Decrement ndlp reference count indicating that ndlp can be
468 * safely released when other references to it are done.
472 ndlp
= lpfc_findnode_did(vport
, PT2PT_RemoteID
);
475 * Cannot find existing Fabric ndlp, so allocate a
478 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
481 lpfc_nlp_init(vport
, ndlp
, PT2PT_RemoteID
);
482 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
483 ndlp
= lpfc_enable_node(vport
, ndlp
,
484 NLP_STE_UNUSED_NODE
);
489 memcpy(&ndlp
->nlp_portname
, &sp
->portName
,
490 sizeof(struct lpfc_name
));
491 memcpy(&ndlp
->nlp_nodename
, &sp
->nodeName
,
492 sizeof(struct lpfc_name
));
493 /* Set state will put ndlp onto node list if not already done */
494 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
495 spin_lock_irq(shost
->host_lock
);
496 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
497 spin_unlock_irq(shost
->host_lock
);
499 /* This side will wait for the PLOGI, decrement ndlp reference
500 * count indicating that ndlp can be released when other
501 * references to it are done.
505 /* If we are pt2pt with another NPort, force NPIV off! */
506 phba
->sli3_options
&= ~LPFC_SLI3_NPIV_ENABLED
;
508 spin_lock_irq(shost
->host_lock
);
509 vport
->fc_flag
|= FC_PT2PT
;
510 spin_unlock_irq(shost
->host_lock
);
512 /* Start discovery - this should just do CLEAR_LA */
513 lpfc_disc_start(vport
);
520 lpfc_cmpl_els_flogi(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
521 struct lpfc_iocbq
*rspiocb
)
523 struct lpfc_vport
*vport
= cmdiocb
->vport
;
524 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
525 IOCB_t
*irsp
= &rspiocb
->iocb
;
526 struct lpfc_nodelist
*ndlp
= cmdiocb
->context1
;
527 struct lpfc_dmabuf
*pcmd
= cmdiocb
->context2
, *prsp
;
528 struct serv_parm
*sp
;
531 /* Check to see if link went down during discovery */
532 if (lpfc_els_chk_latt(vport
)) {
533 /* One additional decrement on node reference count to
534 * trigger the release of the node
540 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
541 "FLOGI cmpl: status:x%x/x%x state:x%x",
542 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
545 if (irsp
->ulpStatus
) {
546 /* Check for retry */
547 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
))
550 /* FLOGI failed, so there is no fabric */
551 spin_lock_irq(shost
->host_lock
);
552 vport
->fc_flag
&= ~(FC_FABRIC
| FC_PUBLIC_LOOP
);
553 spin_unlock_irq(shost
->host_lock
);
555 /* If private loop, then allow max outstanding els to be
556 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
557 * alpa map would take too long otherwise.
559 if (phba
->alpa_map
[0] == 0) {
560 vport
->cfg_discovery_threads
= LPFC_MAX_DISC_THREADS
;
564 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
565 "0100 FLOGI failure Data: x%x x%x "
567 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
573 * The FLogI succeeded. Sync the data for the CPU before
576 prsp
= list_get_first(&pcmd
->list
, struct lpfc_dmabuf
, list
);
578 sp
= prsp
->virt
+ sizeof(uint32_t);
580 /* FLOGI completes successfully */
581 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
582 "0101 FLOGI completes sucessfully "
583 "Data: x%x x%x x%x x%x\n",
584 irsp
->un
.ulpWord
[4], sp
->cmn
.e_d_tov
,
585 sp
->cmn
.w2
.r_a_tov
, sp
->cmn
.edtovResolution
);
587 if (vport
->port_state
== LPFC_FLOGI
) {
589 * If Common Service Parameters indicate Nport
590 * we are point to point, if Fport we are Fabric.
593 rc
= lpfc_cmpl_els_flogi_fabric(vport
, ndlp
, sp
, irsp
);
595 rc
= lpfc_cmpl_els_flogi_nport(vport
, ndlp
, sp
);
604 if (!lpfc_error_lost_link(irsp
)) {
605 /* FLOGI failed, so just use loop map to make discovery list */
606 lpfc_disc_list_loopmap(vport
);
608 /* Start discovery */
609 lpfc_disc_start(vport
);
610 } else if (((irsp
->ulpStatus
!= IOSTAT_LOCAL_REJECT
) ||
611 ((irsp
->un
.ulpWord
[4] != IOERR_SLI_ABORTED
) &&
612 (irsp
->un
.ulpWord
[4] != IOERR_SLI_DOWN
))) &&
613 (phba
->link_state
!= LPFC_CLEAR_LA
)) {
614 /* If FLOGI failed enable link interrupt. */
615 lpfc_issue_clear_la(phba
, vport
);
618 lpfc_els_free_iocb(phba
, cmdiocb
);
622 lpfc_issue_els_flogi(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
625 struct lpfc_hba
*phba
= vport
->phba
;
626 struct serv_parm
*sp
;
628 struct lpfc_iocbq
*elsiocb
;
629 struct lpfc_sli_ring
*pring
;
635 pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
637 cmdsize
= (sizeof(uint32_t) + sizeof(struct serv_parm
));
638 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
639 ndlp
->nlp_DID
, ELS_CMD_FLOGI
);
644 icmd
= &elsiocb
->iocb
;
645 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
647 /* For FLOGI request, remainder of payload is service parameters */
648 *((uint32_t *) (pcmd
)) = ELS_CMD_FLOGI
;
649 pcmd
+= sizeof(uint32_t);
650 memcpy(pcmd
, &vport
->fc_sparam
, sizeof(struct serv_parm
));
651 sp
= (struct serv_parm
*) pcmd
;
653 /* Setup CSPs accordingly for Fabric */
655 sp
->cmn
.w2
.r_a_tov
= 0;
656 sp
->cls1
.classValid
= 0;
657 sp
->cls2
.seqDelivery
= 1;
658 sp
->cls3
.seqDelivery
= 1;
659 if (sp
->cmn
.fcphLow
< FC_PH3
)
660 sp
->cmn
.fcphLow
= FC_PH3
;
661 if (sp
->cmn
.fcphHigh
< FC_PH3
)
662 sp
->cmn
.fcphHigh
= FC_PH3
;
664 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) {
665 sp
->cmn
.request_multiple_Nport
= 1;
667 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
672 if (phba
->fc_topology
!= TOPOLOGY_LOOP
) {
673 icmd
->un
.elsreq64
.myID
= 0;
674 icmd
->un
.elsreq64
.fl
= 1;
677 tmo
= phba
->fc_ratov
;
678 phba
->fc_ratov
= LPFC_DISC_FLOGI_TMO
;
679 lpfc_set_disctmo(vport
);
680 phba
->fc_ratov
= tmo
;
682 phba
->fc_stat
.elsXmitFLOGI
++;
683 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_flogi
;
685 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
686 "Issue FLOGI: opt:x%x",
687 phba
->sli3_options
, 0, 0);
689 rc
= lpfc_issue_fabric_iocb(phba
, elsiocb
);
690 if (rc
== IOCB_ERROR
) {
691 lpfc_els_free_iocb(phba
, elsiocb
);
698 lpfc_els_abort_flogi(struct lpfc_hba
*phba
)
700 struct lpfc_sli_ring
*pring
;
701 struct lpfc_iocbq
*iocb
, *next_iocb
;
702 struct lpfc_nodelist
*ndlp
;
705 /* Abort outstanding I/O on NPort <nlp_DID> */
706 lpfc_printf_log(phba
, KERN_INFO
, LOG_DISCOVERY
,
707 "0201 Abort outstanding I/O on NPort x%x\n",
710 pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
713 * Check the txcmplq for an iocb that matches the nport the driver is
716 spin_lock_irq(&phba
->hbalock
);
717 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
, list
) {
719 if (icmd
->ulpCommand
== CMD_ELS_REQUEST64_CR
&&
720 icmd
->un
.elsreq64
.bdl
.ulpIoTag32
) {
721 ndlp
= (struct lpfc_nodelist
*)(iocb
->context1
);
722 if (ndlp
&& (ndlp
->nlp_DID
== Fabric_DID
)) {
723 lpfc_sli_issue_abort_iotag(phba
, pring
, iocb
);
727 spin_unlock_irq(&phba
->hbalock
);
733 lpfc_initial_flogi(struct lpfc_vport
*vport
)
735 struct lpfc_hba
*phba
= vport
->phba
;
736 struct lpfc_nodelist
*ndlp
;
738 vport
->port_state
= LPFC_FLOGI
;
739 lpfc_set_disctmo(vport
);
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
);
749 /* Put ndlp onto node list */
750 lpfc_enqueue_node(vport
, ndlp
);
751 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
752 /* re-setup ndlp without removing from node list */
753 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
758 if (lpfc_issue_els_flogi(vport
, ndlp
, 0))
759 /* This decrement of reference count to node shall kick off
760 * the release of the node.
768 lpfc_initial_fdisc(struct lpfc_vport
*vport
)
770 struct lpfc_hba
*phba
= vport
->phba
;
771 struct lpfc_nodelist
*ndlp
;
773 /* First look for the Fabric ndlp */
774 ndlp
= lpfc_findnode_did(vport
, Fabric_DID
);
776 /* Cannot find existing Fabric ndlp, so allocate a new one */
777 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
780 lpfc_nlp_init(vport
, ndlp
, Fabric_DID
);
781 /* Put ndlp onto node list */
782 lpfc_enqueue_node(vport
, ndlp
);
783 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
784 /* re-setup ndlp without removing from node list */
785 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
790 if (lpfc_issue_els_fdisc(vport
, ndlp
, 0)) {
791 /* decrement node reference count to trigger the release of
801 lpfc_more_plogi(struct lpfc_vport
*vport
)
805 if (vport
->num_disc_nodes
)
806 vport
->num_disc_nodes
--;
808 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
809 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
810 "0232 Continue discovery with %d PLOGIs to go "
811 "Data: x%x x%x x%x\n",
812 vport
->num_disc_nodes
, vport
->fc_plogi_cnt
,
813 vport
->fc_flag
, vport
->port_state
);
814 /* Check to see if there are more PLOGIs to be sent */
815 if (vport
->fc_flag
& FC_NLP_MORE
)
816 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
817 sentplogi
= lpfc_els_disc_plogi(vport
);
822 static struct lpfc_nodelist
*
823 lpfc_plogi_confirm_nport(struct lpfc_hba
*phba
, uint32_t *prsp
,
824 struct lpfc_nodelist
*ndlp
)
826 struct lpfc_vport
*vport
= ndlp
->vport
;
827 struct lpfc_nodelist
*new_ndlp
;
828 struct lpfc_rport_data
*rdata
;
829 struct fc_rport
*rport
;
830 struct serv_parm
*sp
;
831 uint8_t name
[sizeof(struct lpfc_name
)];
834 /* Fabric nodes can have the same WWPN so we don't bother searching
835 * by WWPN. Just return the ndlp that was given to us.
837 if (ndlp
->nlp_type
& NLP_FABRIC
)
840 sp
= (struct serv_parm
*) ((uint8_t *) prsp
+ sizeof(uint32_t));
841 memset(name
, 0, sizeof(struct lpfc_name
));
843 /* Now we find out if the NPort we are logging into, matches the WWPN
844 * we have for that ndlp. If not, we have some work to do.
846 new_ndlp
= lpfc_findnode_wwpn(vport
, &sp
->portName
);
848 if (new_ndlp
== ndlp
&& NLP_CHK_NODE_ACT(new_ndlp
))
852 rc
= memcmp(&ndlp
->nlp_portname
, name
,
853 sizeof(struct lpfc_name
));
856 new_ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_ATOMIC
);
859 lpfc_nlp_init(vport
, new_ndlp
, ndlp
->nlp_DID
);
860 } else if (!NLP_CHK_NODE_ACT(new_ndlp
)) {
861 new_ndlp
= lpfc_enable_node(vport
, new_ndlp
,
862 NLP_STE_UNUSED_NODE
);
867 lpfc_unreg_rpi(vport
, new_ndlp
);
868 new_ndlp
->nlp_DID
= ndlp
->nlp_DID
;
869 new_ndlp
->nlp_prev_state
= ndlp
->nlp_prev_state
;
871 if (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
)
872 new_ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
873 ndlp
->nlp_flag
&= ~NLP_NPR_2B_DISC
;
875 /* Set state will put new_ndlp on to node list if not already done */
876 lpfc_nlp_set_state(vport
, new_ndlp
, ndlp
->nlp_state
);
878 /* Move this back to NPR state */
879 if (memcmp(&ndlp
->nlp_portname
, name
, sizeof(struct lpfc_name
)) == 0) {
880 /* The new_ndlp is replacing ndlp totally, so we need
881 * to put ndlp on UNUSED list and try to free it.
884 /* Fix up the rport accordingly */
887 rdata
= rport
->dd_data
;
888 if (rdata
->pnode
== ndlp
) {
891 rdata
->pnode
= lpfc_nlp_get(new_ndlp
);
892 new_ndlp
->rport
= rport
;
894 new_ndlp
->nlp_type
= ndlp
->nlp_type
;
897 lpfc_drop_node(vport
, ndlp
);
900 lpfc_unreg_rpi(vport
, ndlp
);
901 ndlp
->nlp_DID
= 0; /* Two ndlps cannot have the same did */
902 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
908 lpfc_end_rscn(struct lpfc_vport
*vport
)
910 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
912 if (vport
->fc_flag
& FC_RSCN_MODE
) {
914 * Check to see if more RSCNs came in while we were
915 * processing this one.
917 if (vport
->fc_rscn_id_cnt
||
918 (vport
->fc_flag
& FC_RSCN_DISCOVERY
) != 0)
919 lpfc_els_handle_rscn(vport
);
921 spin_lock_irq(shost
->host_lock
);
922 vport
->fc_flag
&= ~FC_RSCN_MODE
;
923 spin_unlock_irq(shost
->host_lock
);
929 lpfc_cmpl_els_plogi(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
930 struct lpfc_iocbq
*rspiocb
)
932 struct lpfc_vport
*vport
= cmdiocb
->vport
;
933 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
935 struct lpfc_nodelist
*ndlp
;
936 struct lpfc_dmabuf
*prsp
;
937 int disc
, rc
, did
, type
;
939 /* we pass cmdiocb to state machine which needs rspiocb as well */
940 cmdiocb
->context_un
.rsp_iocb
= rspiocb
;
942 irsp
= &rspiocb
->iocb
;
943 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
944 "PLOGI cmpl: status:x%x/x%x did:x%x",
945 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
946 irsp
->un
.elsreq64
.remoteID
);
948 ndlp
= lpfc_findnode_did(vport
, irsp
->un
.elsreq64
.remoteID
);
949 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
)) {
950 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
951 "0136 PLOGI completes to NPort x%x "
952 "with no ndlp. Data: x%x x%x x%x\n",
953 irsp
->un
.elsreq64
.remoteID
,
954 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
959 /* Since ndlp can be freed in the disc state machine, note if this node
960 * is being used during discovery.
962 spin_lock_irq(shost
->host_lock
);
963 disc
= (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
);
964 ndlp
->nlp_flag
&= ~NLP_NPR_2B_DISC
;
965 spin_unlock_irq(shost
->host_lock
);
968 /* PLOGI completes to NPort <nlp_DID> */
969 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
970 "0102 PLOGI completes to NPort x%x "
971 "Data: x%x x%x x%x x%x x%x\n",
972 ndlp
->nlp_DID
, irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
973 irsp
->ulpTimeout
, disc
, vport
->num_disc_nodes
);
974 /* Check to see if link went down during discovery */
975 if (lpfc_els_chk_latt(vport
)) {
976 spin_lock_irq(shost
->host_lock
);
977 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
978 spin_unlock_irq(shost
->host_lock
);
982 /* ndlp could be freed in DSM, save these values now */
983 type
= ndlp
->nlp_type
;
986 if (irsp
->ulpStatus
) {
987 /* Check for retry */
988 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
)) {
989 /* ELS command is being retried */
991 spin_lock_irq(shost
->host_lock
);
992 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
993 spin_unlock_irq(shost
->host_lock
);
998 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
999 if (lpfc_error_lost_link(irsp
))
1000 rc
= NLP_STE_FREED_NODE
;
1002 rc
= lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
1003 NLP_EVT_CMPL_PLOGI
);
1005 /* Good status, call state machine */
1006 prsp
= list_entry(((struct lpfc_dmabuf
*)
1007 cmdiocb
->context2
)->list
.next
,
1008 struct lpfc_dmabuf
, list
);
1009 ndlp
= lpfc_plogi_confirm_nport(phba
, prsp
->virt
, ndlp
);
1010 rc
= lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
1011 NLP_EVT_CMPL_PLOGI
);
1014 if (disc
&& vport
->num_disc_nodes
) {
1015 /* Check to see if there are more PLOGIs to be sent */
1016 lpfc_more_plogi(vport
);
1018 if (vport
->num_disc_nodes
== 0) {
1019 spin_lock_irq(shost
->host_lock
);
1020 vport
->fc_flag
&= ~FC_NDISC_ACTIVE
;
1021 spin_unlock_irq(shost
->host_lock
);
1023 lpfc_can_disctmo(vport
);
1024 lpfc_end_rscn(vport
);
1029 lpfc_els_free_iocb(phba
, cmdiocb
);
1034 lpfc_issue_els_plogi(struct lpfc_vport
*vport
, uint32_t did
, uint8_t retry
)
1036 struct lpfc_hba
*phba
= vport
->phba
;
1037 struct serv_parm
*sp
;
1039 struct lpfc_nodelist
*ndlp
;
1040 struct lpfc_iocbq
*elsiocb
;
1041 struct lpfc_sli_ring
*pring
;
1042 struct lpfc_sli
*psli
;
1048 pring
= &psli
->ring
[LPFC_ELS_RING
]; /* ELS ring */
1050 ndlp
= lpfc_findnode_did(vport
, did
);
1051 if (ndlp
&& !NLP_CHK_NODE_ACT(ndlp
))
1054 /* If ndlp is not NULL, we will bump the reference count on it */
1055 cmdsize
= (sizeof(uint32_t) + sizeof(struct serv_parm
));
1056 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
, did
,
1061 icmd
= &elsiocb
->iocb
;
1062 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
1064 /* For PLOGI request, remainder of payload is service parameters */
1065 *((uint32_t *) (pcmd
)) = ELS_CMD_PLOGI
;
1066 pcmd
+= sizeof(uint32_t);
1067 memcpy(pcmd
, &vport
->fc_sparam
, sizeof(struct serv_parm
));
1068 sp
= (struct serv_parm
*) pcmd
;
1070 if (sp
->cmn
.fcphLow
< FC_PH_4_3
)
1071 sp
->cmn
.fcphLow
= FC_PH_4_3
;
1073 if (sp
->cmn
.fcphHigh
< FC_PH3
)
1074 sp
->cmn
.fcphHigh
= FC_PH3
;
1076 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1077 "Issue PLOGI: did:x%x",
1080 phba
->fc_stat
.elsXmitPLOGI
++;
1081 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_plogi
;
1082 ret
= lpfc_sli_issue_iocb(phba
, pring
, elsiocb
, 0);
1084 if (ret
== IOCB_ERROR
) {
1085 lpfc_els_free_iocb(phba
, elsiocb
);
1092 lpfc_cmpl_els_prli(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
1093 struct lpfc_iocbq
*rspiocb
)
1095 struct lpfc_vport
*vport
= cmdiocb
->vport
;
1096 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1098 struct lpfc_sli
*psli
;
1099 struct lpfc_nodelist
*ndlp
;
1102 /* we pass cmdiocb to state machine which needs rspiocb as well */
1103 cmdiocb
->context_un
.rsp_iocb
= rspiocb
;
1105 irsp
= &(rspiocb
->iocb
);
1106 ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
1107 spin_lock_irq(shost
->host_lock
);
1108 ndlp
->nlp_flag
&= ~NLP_PRLI_SND
;
1109 spin_unlock_irq(shost
->host_lock
);
1111 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1112 "PRLI cmpl: status:x%x/x%x did:x%x",
1113 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1115 /* PRLI completes to NPort <nlp_DID> */
1116 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
1117 "0103 PRLI completes to NPort x%x "
1118 "Data: x%x x%x x%x x%x\n",
1119 ndlp
->nlp_DID
, irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1120 irsp
->ulpTimeout
, vport
->num_disc_nodes
);
1122 vport
->fc_prli_sent
--;
1123 /* Check to see if link went down during discovery */
1124 if (lpfc_els_chk_latt(vport
))
1127 if (irsp
->ulpStatus
) {
1128 /* Check for retry */
1129 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
)) {
1130 /* ELS command is being retried */
1134 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1135 if (lpfc_error_lost_link(irsp
))
1138 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
1141 /* Good status, call state machine */
1142 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
1145 lpfc_els_free_iocb(phba
, cmdiocb
);
1150 lpfc_issue_els_prli(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1153 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1154 struct lpfc_hba
*phba
= vport
->phba
;
1157 struct lpfc_iocbq
*elsiocb
;
1158 struct lpfc_sli_ring
*pring
;
1159 struct lpfc_sli
*psli
;
1164 pring
= &psli
->ring
[LPFC_ELS_RING
]; /* ELS ring */
1166 cmdsize
= (sizeof(uint32_t) + sizeof(PRLI
));
1167 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
1168 ndlp
->nlp_DID
, ELS_CMD_PRLI
);
1172 icmd
= &elsiocb
->iocb
;
1173 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
1175 /* For PRLI request, remainder of payload is service parameters */
1176 memset(pcmd
, 0, (sizeof(PRLI
) + sizeof(uint32_t)));
1177 *((uint32_t *) (pcmd
)) = ELS_CMD_PRLI
;
1178 pcmd
+= sizeof(uint32_t);
1180 /* For PRLI, remainder of payload is PRLI parameter page */
1181 npr
= (PRLI
*) pcmd
;
1183 * If our firmware version is 3.20 or later,
1184 * set the following bits for FC-TAPE support.
1186 if (phba
->vpd
.rev
.feaLevelHigh
>= 0x02) {
1187 npr
->ConfmComplAllowed
= 1;
1189 npr
->TaskRetryIdReq
= 1;
1191 npr
->estabImagePair
= 1;
1192 npr
->readXferRdyDis
= 1;
1194 /* For FCP support */
1195 npr
->prliType
= PRLI_FCP_TYPE
;
1196 npr
->initiatorFunc
= 1;
1198 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1199 "Issue PRLI: did:x%x",
1200 ndlp
->nlp_DID
, 0, 0);
1202 phba
->fc_stat
.elsXmitPRLI
++;
1203 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_prli
;
1204 spin_lock_irq(shost
->host_lock
);
1205 ndlp
->nlp_flag
|= NLP_PRLI_SND
;
1206 spin_unlock_irq(shost
->host_lock
);
1207 if (lpfc_sli_issue_iocb(phba
, pring
, elsiocb
, 0) == IOCB_ERROR
) {
1208 spin_lock_irq(shost
->host_lock
);
1209 ndlp
->nlp_flag
&= ~NLP_PRLI_SND
;
1210 spin_unlock_irq(shost
->host_lock
);
1211 lpfc_els_free_iocb(phba
, elsiocb
);
1214 vport
->fc_prli_sent
++;
1219 lpfc_more_adisc(struct lpfc_vport
*vport
)
1223 if (vport
->num_disc_nodes
)
1224 vport
->num_disc_nodes
--;
1225 /* Continue discovery with <num_disc_nodes> ADISCs to go */
1226 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
1227 "0210 Continue discovery with %d ADISCs to go "
1228 "Data: x%x x%x x%x\n",
1229 vport
->num_disc_nodes
, vport
->fc_adisc_cnt
,
1230 vport
->fc_flag
, vport
->port_state
);
1231 /* Check to see if there are more ADISCs to be sent */
1232 if (vport
->fc_flag
& FC_NLP_MORE
) {
1233 lpfc_set_disctmo(vport
);
1234 /* go thru NPR nodes and issue any remaining ELS ADISCs */
1235 sentadisc
= lpfc_els_disc_adisc(vport
);
1241 lpfc_rscn_disc(struct lpfc_vport
*vport
)
1243 lpfc_can_disctmo(vport
);
1245 /* RSCN discovery */
1246 /* go thru NPR nodes and issue ELS PLOGIs */
1247 if (vport
->fc_npr_cnt
)
1248 if (lpfc_els_disc_plogi(vport
))
1251 lpfc_end_rscn(vport
);
1255 lpfc_cmpl_els_adisc(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
1256 struct lpfc_iocbq
*rspiocb
)
1258 struct lpfc_vport
*vport
= cmdiocb
->vport
;
1259 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1261 struct lpfc_nodelist
*ndlp
;
1264 /* we pass cmdiocb to state machine which needs rspiocb as well */
1265 cmdiocb
->context_un
.rsp_iocb
= rspiocb
;
1267 irsp
= &(rspiocb
->iocb
);
1268 ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
1270 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1271 "ADISC cmpl: status:x%x/x%x did:x%x",
1272 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1275 /* Since ndlp can be freed in the disc state machine, note if this node
1276 * is being used during discovery.
1278 spin_lock_irq(shost
->host_lock
);
1279 disc
= (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
);
1280 ndlp
->nlp_flag
&= ~(NLP_ADISC_SND
| NLP_NPR_2B_DISC
);
1281 spin_unlock_irq(shost
->host_lock
);
1282 /* ADISC completes to NPort <nlp_DID> */
1283 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
1284 "0104 ADISC completes to NPort x%x "
1285 "Data: x%x x%x x%x x%x x%x\n",
1286 ndlp
->nlp_DID
, irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1287 irsp
->ulpTimeout
, disc
, vport
->num_disc_nodes
);
1288 /* Check to see if link went down during discovery */
1289 if (lpfc_els_chk_latt(vport
)) {
1290 spin_lock_irq(shost
->host_lock
);
1291 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
1292 spin_unlock_irq(shost
->host_lock
);
1296 if (irsp
->ulpStatus
) {
1297 /* Check for retry */
1298 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
)) {
1299 /* ELS command is being retried */
1301 spin_lock_irq(shost
->host_lock
);
1302 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
1303 spin_unlock_irq(shost
->host_lock
);
1304 lpfc_set_disctmo(vport
);
1309 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1310 if (!lpfc_error_lost_link(irsp
))
1311 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
1312 NLP_EVT_CMPL_ADISC
);
1314 /* Good status, call state machine */
1315 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
1316 NLP_EVT_CMPL_ADISC
);
1318 if (disc
&& vport
->num_disc_nodes
) {
1319 /* Check to see if there are more ADISCs to be sent */
1320 lpfc_more_adisc(vport
);
1322 /* Check to see if we are done with ADISC authentication */
1323 if (vport
->num_disc_nodes
== 0) {
1324 /* If we get here, there is nothing left to ADISC */
1326 * For NPIV, cmpl_reg_vpi will set port_state to READY,
1327 * and continue discovery.
1329 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
1330 !(vport
->fc_flag
& FC_RSCN_MODE
)) {
1331 lpfc_issue_reg_vpi(phba
, vport
);
1335 * For SLI2, we need to set port_state to READY
1336 * and continue discovery.
1338 if (vport
->port_state
< LPFC_VPORT_READY
) {
1339 /* If we get here, there is nothing to ADISC */
1340 if (vport
->port_type
== LPFC_PHYSICAL_PORT
)
1341 lpfc_issue_clear_la(phba
, vport
);
1343 if (!(vport
->fc_flag
& FC_ABORT_DISCOVERY
)) {
1344 vport
->num_disc_nodes
= 0;
1345 /* go thru NPR list, issue ELS PLOGIs */
1346 if (vport
->fc_npr_cnt
)
1347 lpfc_els_disc_plogi(vport
);
1349 if (!vport
->num_disc_nodes
) {
1350 spin_lock_irq(shost
->host_lock
);
1355 lpfc_can_disctmo(vport
);
1358 vport
->port_state
= LPFC_VPORT_READY
;
1360 lpfc_rscn_disc(vport
);
1365 lpfc_els_free_iocb(phba
, cmdiocb
);
1370 lpfc_issue_els_adisc(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1373 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1374 struct lpfc_hba
*phba
= vport
->phba
;
1377 struct lpfc_iocbq
*elsiocb
;
1378 struct lpfc_sli
*psli
= &phba
->sli
;
1379 struct lpfc_sli_ring
*pring
= &psli
->ring
[LPFC_ELS_RING
];
1383 cmdsize
= (sizeof(uint32_t) + sizeof(ADISC
));
1384 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
1385 ndlp
->nlp_DID
, ELS_CMD_ADISC
);
1389 icmd
= &elsiocb
->iocb
;
1390 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
1392 /* For ADISC request, remainder of payload is service parameters */
1393 *((uint32_t *) (pcmd
)) = ELS_CMD_ADISC
;
1394 pcmd
+= sizeof(uint32_t);
1396 /* Fill in ADISC payload */
1397 ap
= (ADISC
*) pcmd
;
1398 ap
->hardAL_PA
= phba
->fc_pref_ALPA
;
1399 memcpy(&ap
->portName
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
1400 memcpy(&ap
->nodeName
, &vport
->fc_nodename
, sizeof(struct lpfc_name
));
1401 ap
->DID
= be32_to_cpu(vport
->fc_myDID
);
1403 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1404 "Issue ADISC: did:x%x",
1405 ndlp
->nlp_DID
, 0, 0);
1407 phba
->fc_stat
.elsXmitADISC
++;
1408 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_adisc
;
1409 spin_lock_irq(shost
->host_lock
);
1410 ndlp
->nlp_flag
|= NLP_ADISC_SND
;
1411 spin_unlock_irq(shost
->host_lock
);
1412 if (lpfc_sli_issue_iocb(phba
, pring
, elsiocb
, 0) == IOCB_ERROR
) {
1413 spin_lock_irq(shost
->host_lock
);
1414 ndlp
->nlp_flag
&= ~NLP_ADISC_SND
;
1415 spin_unlock_irq(shost
->host_lock
);
1416 lpfc_els_free_iocb(phba
, elsiocb
);
1423 lpfc_cmpl_els_logo(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
1424 struct lpfc_iocbq
*rspiocb
)
1426 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
1427 struct lpfc_vport
*vport
= ndlp
->vport
;
1428 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1430 struct lpfc_sli
*psli
;
1433 /* we pass cmdiocb to state machine which needs rspiocb as well */
1434 cmdiocb
->context_un
.rsp_iocb
= rspiocb
;
1436 irsp
= &(rspiocb
->iocb
);
1437 spin_lock_irq(shost
->host_lock
);
1438 ndlp
->nlp_flag
&= ~NLP_LOGO_SND
;
1439 spin_unlock_irq(shost
->host_lock
);
1441 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1442 "LOGO cmpl: status:x%x/x%x did:x%x",
1443 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1445 /* LOGO completes to NPort <nlp_DID> */
1446 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
1447 "0105 LOGO completes to NPort x%x "
1448 "Data: x%x x%x x%x x%x\n",
1449 ndlp
->nlp_DID
, irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1450 irsp
->ulpTimeout
, vport
->num_disc_nodes
);
1451 /* Check to see if link went down during discovery */
1452 if (lpfc_els_chk_latt(vport
))
1455 if (ndlp
->nlp_flag
& NLP_TARGET_REMOVE
) {
1456 /* NLP_EVT_DEVICE_RM should unregister the RPI
1457 * which should abort all outstanding IOs.
1459 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
1464 if (irsp
->ulpStatus
) {
1465 /* Check for retry */
1466 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
))
1467 /* ELS command is being retried */
1470 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1471 if (lpfc_error_lost_link(irsp
))
1474 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
1477 /* Good status, call state machine.
1478 * This will unregister the rpi if needed.
1480 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
1483 lpfc_els_free_iocb(phba
, cmdiocb
);
1488 lpfc_issue_els_logo(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1491 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1492 struct lpfc_hba
*phba
= vport
->phba
;
1494 struct lpfc_iocbq
*elsiocb
;
1495 struct lpfc_sli_ring
*pring
;
1496 struct lpfc_sli
*psli
;
1502 pring
= &psli
->ring
[LPFC_ELS_RING
];
1504 spin_lock_irq(shost
->host_lock
);
1505 if (ndlp
->nlp_flag
& NLP_LOGO_SND
) {
1506 spin_unlock_irq(shost
->host_lock
);
1509 spin_unlock_irq(shost
->host_lock
);
1511 cmdsize
= (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name
);
1512 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
1513 ndlp
->nlp_DID
, ELS_CMD_LOGO
);
1517 icmd
= &elsiocb
->iocb
;
1518 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
1519 *((uint32_t *) (pcmd
)) = ELS_CMD_LOGO
;
1520 pcmd
+= sizeof(uint32_t);
1522 /* Fill in LOGO payload */
1523 *((uint32_t *) (pcmd
)) = be32_to_cpu(vport
->fc_myDID
);
1524 pcmd
+= sizeof(uint32_t);
1525 memcpy(pcmd
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
1527 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1528 "Issue LOGO: did:x%x",
1529 ndlp
->nlp_DID
, 0, 0);
1531 phba
->fc_stat
.elsXmitLOGO
++;
1532 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_logo
;
1533 spin_lock_irq(shost
->host_lock
);
1534 ndlp
->nlp_flag
|= NLP_LOGO_SND
;
1535 spin_unlock_irq(shost
->host_lock
);
1536 rc
= lpfc_sli_issue_iocb(phba
, pring
, elsiocb
, 0);
1538 if (rc
== IOCB_ERROR
) {
1539 spin_lock_irq(shost
->host_lock
);
1540 ndlp
->nlp_flag
&= ~NLP_LOGO_SND
;
1541 spin_unlock_irq(shost
->host_lock
);
1542 lpfc_els_free_iocb(phba
, elsiocb
);
1549 lpfc_cmpl_els_cmd(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
1550 struct lpfc_iocbq
*rspiocb
)
1552 struct lpfc_vport
*vport
= cmdiocb
->vport
;
1555 irsp
= &rspiocb
->iocb
;
1557 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1558 "ELS cmd cmpl: status:x%x/x%x did:x%x",
1559 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1560 irsp
->un
.elsreq64
.remoteID
);
1561 /* ELS cmd tag <ulpIoTag> completes */
1562 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
1563 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
1564 irsp
->ulpIoTag
, irsp
->ulpStatus
,
1565 irsp
->un
.ulpWord
[4], irsp
->ulpTimeout
);
1566 /* Check to see if link went down during discovery */
1567 lpfc_els_chk_latt(vport
);
1568 lpfc_els_free_iocb(phba
, cmdiocb
);
1573 lpfc_issue_els_scr(struct lpfc_vport
*vport
, uint32_t nportid
, uint8_t retry
)
1575 struct lpfc_hba
*phba
= vport
->phba
;
1577 struct lpfc_iocbq
*elsiocb
;
1578 struct lpfc_sli_ring
*pring
;
1579 struct lpfc_sli
*psli
;
1582 struct lpfc_nodelist
*ndlp
;
1585 pring
= &psli
->ring
[LPFC_ELS_RING
]; /* ELS ring */
1586 cmdsize
= (sizeof(uint32_t) + sizeof(SCR
));
1588 ndlp
= lpfc_findnode_did(vport
, nportid
);
1590 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
1593 lpfc_nlp_init(vport
, ndlp
, nportid
);
1594 lpfc_enqueue_node(vport
, ndlp
);
1595 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
1596 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
1601 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
1602 ndlp
->nlp_DID
, ELS_CMD_SCR
);
1605 /* This will trigger the release of the node just
1612 icmd
= &elsiocb
->iocb
;
1613 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
1615 *((uint32_t *) (pcmd
)) = ELS_CMD_SCR
;
1616 pcmd
+= sizeof(uint32_t);
1618 /* For SCR, remainder of payload is SCR parameter page */
1619 memset(pcmd
, 0, sizeof(SCR
));
1620 ((SCR
*) pcmd
)->Function
= SCR_FUNC_FULL
;
1622 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1623 "Issue SCR: did:x%x",
1624 ndlp
->nlp_DID
, 0, 0);
1626 phba
->fc_stat
.elsXmitSCR
++;
1627 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_cmd
;
1628 if (lpfc_sli_issue_iocb(phba
, pring
, elsiocb
, 0) == IOCB_ERROR
) {
1629 /* The additional lpfc_nlp_put will cause the following
1630 * lpfc_els_free_iocb routine to trigger the rlease of
1634 lpfc_els_free_iocb(phba
, elsiocb
);
1637 /* This will cause the callback-function lpfc_cmpl_els_cmd to
1638 * trigger the release of node.
1645 lpfc_issue_els_farpr(struct lpfc_vport
*vport
, uint32_t nportid
, uint8_t retry
)
1647 struct lpfc_hba
*phba
= vport
->phba
;
1649 struct lpfc_iocbq
*elsiocb
;
1650 struct lpfc_sli_ring
*pring
;
1651 struct lpfc_sli
*psli
;
1656 struct lpfc_nodelist
*ondlp
;
1657 struct lpfc_nodelist
*ndlp
;
1660 pring
= &psli
->ring
[LPFC_ELS_RING
]; /* ELS ring */
1661 cmdsize
= (sizeof(uint32_t) + sizeof(FARP
));
1663 ndlp
= lpfc_findnode_did(vport
, nportid
);
1665 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
1668 lpfc_nlp_init(vport
, ndlp
, nportid
);
1669 lpfc_enqueue_node(vport
, ndlp
);
1670 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
1671 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
1676 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
1677 ndlp
->nlp_DID
, ELS_CMD_RNID
);
1679 /* This will trigger the release of the node just
1686 icmd
= &elsiocb
->iocb
;
1687 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
1689 *((uint32_t *) (pcmd
)) = ELS_CMD_FARPR
;
1690 pcmd
+= sizeof(uint32_t);
1692 /* Fill in FARPR payload */
1693 fp
= (FARP
*) (pcmd
);
1694 memset(fp
, 0, sizeof(FARP
));
1695 lp
= (uint32_t *) pcmd
;
1696 *lp
++ = be32_to_cpu(nportid
);
1697 *lp
++ = be32_to_cpu(vport
->fc_myDID
);
1699 fp
->Mflags
= (FARP_MATCH_PORT
| FARP_MATCH_NODE
);
1701 memcpy(&fp
->RportName
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
1702 memcpy(&fp
->RnodeName
, &vport
->fc_nodename
, sizeof(struct lpfc_name
));
1703 ondlp
= lpfc_findnode_did(vport
, nportid
);
1704 if (ondlp
&& NLP_CHK_NODE_ACT(ondlp
)) {
1705 memcpy(&fp
->OportName
, &ondlp
->nlp_portname
,
1706 sizeof(struct lpfc_name
));
1707 memcpy(&fp
->OnodeName
, &ondlp
->nlp_nodename
,
1708 sizeof(struct lpfc_name
));
1711 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1712 "Issue FARPR: did:x%x",
1713 ndlp
->nlp_DID
, 0, 0);
1715 phba
->fc_stat
.elsXmitFARPR
++;
1716 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_cmd
;
1717 if (lpfc_sli_issue_iocb(phba
, pring
, elsiocb
, 0) == IOCB_ERROR
) {
1718 /* The additional lpfc_nlp_put will cause the following
1719 * lpfc_els_free_iocb routine to trigger the release of
1723 lpfc_els_free_iocb(phba
, elsiocb
);
1726 /* This will cause the callback-function lpfc_cmpl_els_cmd to
1727 * trigger the release of the node.
1734 lpfc_cancel_retry_delay_tmo(struct lpfc_vport
*vport
, struct lpfc_nodelist
*nlp
)
1736 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1737 struct lpfc_work_evt
*evtp
;
1739 spin_lock_irq(shost
->host_lock
);
1740 nlp
->nlp_flag
&= ~NLP_DELAY_TMO
;
1741 spin_unlock_irq(shost
->host_lock
);
1742 del_timer_sync(&nlp
->nlp_delayfunc
);
1743 nlp
->nlp_last_elscmd
= 0;
1745 if (!list_empty(&nlp
->els_retry_evt
.evt_listp
)) {
1746 list_del_init(&nlp
->els_retry_evt
.evt_listp
);
1747 /* Decrement nlp reference count held for the delayed retry */
1748 evtp
= &nlp
->els_retry_evt
;
1749 lpfc_nlp_put((struct lpfc_nodelist
*)evtp
->evt_arg1
);
1752 if (nlp
->nlp_flag
& NLP_NPR_2B_DISC
) {
1753 spin_lock_irq(shost
->host_lock
);
1754 nlp
->nlp_flag
&= ~NLP_NPR_2B_DISC
;
1755 spin_unlock_irq(shost
->host_lock
);
1756 if (vport
->num_disc_nodes
) {
1757 /* Check to see if there are more
1760 lpfc_more_plogi(vport
);
1762 if (vport
->num_disc_nodes
== 0) {
1763 spin_lock_irq(shost
->host_lock
);
1764 vport
->fc_flag
&= ~FC_NDISC_ACTIVE
;
1765 spin_unlock_irq(shost
->host_lock
);
1766 lpfc_can_disctmo(vport
);
1767 lpfc_end_rscn(vport
);
1775 lpfc_els_retry_delay(unsigned long ptr
)
1777 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) ptr
;
1778 struct lpfc_vport
*vport
= ndlp
->vport
;
1779 struct lpfc_hba
*phba
= vport
->phba
;
1780 unsigned long flags
;
1781 struct lpfc_work_evt
*evtp
= &ndlp
->els_retry_evt
;
1783 ndlp
= (struct lpfc_nodelist
*) ptr
;
1784 phba
= ndlp
->vport
->phba
;
1785 evtp
= &ndlp
->els_retry_evt
;
1787 spin_lock_irqsave(&phba
->hbalock
, flags
);
1788 if (!list_empty(&evtp
->evt_listp
)) {
1789 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1793 /* We need to hold the node by incrementing the reference
1794 * count until the queued work is done
1796 evtp
->evt_arg1
= lpfc_nlp_get(ndlp
);
1797 evtp
->evt
= LPFC_EVT_ELS_RETRY
;
1798 list_add_tail(&evtp
->evt_listp
, &phba
->work_list
);
1799 if (phba
->work_wait
)
1800 lpfc_worker_wake_up(phba
);
1802 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1807 lpfc_els_retry_delay_handler(struct lpfc_nodelist
*ndlp
)
1809 struct lpfc_vport
*vport
= ndlp
->vport
;
1810 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1811 uint32_t cmd
, did
, retry
;
1813 spin_lock_irq(shost
->host_lock
);
1814 did
= ndlp
->nlp_DID
;
1815 cmd
= ndlp
->nlp_last_elscmd
;
1816 ndlp
->nlp_last_elscmd
= 0;
1818 if (!(ndlp
->nlp_flag
& NLP_DELAY_TMO
)) {
1819 spin_unlock_irq(shost
->host_lock
);
1823 ndlp
->nlp_flag
&= ~NLP_DELAY_TMO
;
1824 spin_unlock_irq(shost
->host_lock
);
1826 * If a discovery event readded nlp_delayfunc after timer
1827 * firing and before processing the timer, cancel the
1830 del_timer_sync(&ndlp
->nlp_delayfunc
);
1831 retry
= ndlp
->nlp_retry
;
1835 lpfc_issue_els_flogi(vport
, ndlp
, retry
);
1838 if (!lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, retry
)) {
1839 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
1840 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
1844 if (!lpfc_issue_els_adisc(vport
, ndlp
, retry
)) {
1845 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
1846 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_ADISC_ISSUE
);
1850 if (!lpfc_issue_els_prli(vport
, ndlp
, retry
)) {
1851 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
1852 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PRLI_ISSUE
);
1856 if (!lpfc_issue_els_logo(vport
, ndlp
, retry
)) {
1857 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
1858 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1862 lpfc_issue_els_fdisc(vport
, ndlp
, retry
);
1869 lpfc_els_retry(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
1870 struct lpfc_iocbq
*rspiocb
)
1872 struct lpfc_vport
*vport
= cmdiocb
->vport
;
1873 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1874 IOCB_t
*irsp
= &rspiocb
->iocb
;
1875 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
1876 struct lpfc_dmabuf
*pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
1879 int retry
= 0, maxretry
= lpfc_max_els_tries
, delay
= 0;
1885 /* Note: context2 may be 0 for internal driver abort
1886 * of delays ELS command.
1889 if (pcmd
&& pcmd
->virt
) {
1890 elscmd
= (uint32_t *) (pcmd
->virt
);
1894 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
))
1895 did
= ndlp
->nlp_DID
;
1897 /* We should only hit this case for retrying PLOGI */
1898 did
= irsp
->un
.elsreq64
.remoteID
;
1899 ndlp
= lpfc_findnode_did(vport
, did
);
1900 if ((!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
))
1901 && (cmd
!= ELS_CMD_PLOGI
))
1905 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1906 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
1907 *(((uint32_t *) irsp
) + 7), irsp
->un
.ulpWord
[4], ndlp
->nlp_DID
);
1909 switch (irsp
->ulpStatus
) {
1910 case IOSTAT_FCP_RSP_ERROR
:
1911 case IOSTAT_REMOTE_STOP
:
1914 case IOSTAT_LOCAL_REJECT
:
1915 switch ((irsp
->un
.ulpWord
[4] & 0xff)) {
1916 case IOERR_LOOP_OPEN_FAILURE
:
1917 if (cmd
== ELS_CMD_PLOGI
&& cmdiocb
->retry
== 0)
1922 case IOERR_ILLEGAL_COMMAND
:
1923 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1924 "0124 Retry illegal cmd x%x "
1925 "retry:x%x delay:x%x\n",
1926 cmd
, cmdiocb
->retry
, delay
);
1928 /* All command's retry policy */
1930 if (cmdiocb
->retry
> 2)
1934 case IOERR_NO_RESOURCES
:
1935 logerr
= 1; /* HBA out of resources */
1937 if (cmdiocb
->retry
> 100)
1942 case IOERR_ILLEGAL_FRAME
:
1947 case IOERR_SEQUENCE_TIMEOUT
:
1948 case IOERR_INVALID_RPI
:
1954 case IOSTAT_NPORT_RJT
:
1955 case IOSTAT_FABRIC_RJT
:
1956 if (irsp
->un
.ulpWord
[4] & RJT_UNAVAIL_TEMP
) {
1962 case IOSTAT_NPORT_BSY
:
1963 case IOSTAT_FABRIC_BSY
:
1964 logerr
= 1; /* Fabric / Remote NPort out of resources */
1969 stat
.un
.lsRjtError
= be32_to_cpu(irsp
->un
.ulpWord
[4]);
1970 /* Added for Vendor specifc support
1971 * Just keep retrying for these Rsn / Exp codes
1973 switch (stat
.un
.b
.lsRjtRsnCode
) {
1974 case LSRJT_UNABLE_TPC
:
1975 if (stat
.un
.b
.lsRjtRsnCodeExp
==
1976 LSEXP_CMD_IN_PROGRESS
) {
1977 if (cmd
== ELS_CMD_PLOGI
) {
1984 if (cmd
== ELS_CMD_PLOGI
) {
1986 maxretry
= lpfc_max_els_tries
+ 1;
1990 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
1991 (cmd
== ELS_CMD_FDISC
) &&
1992 (stat
.un
.b
.lsRjtRsnCodeExp
== LSEXP_OUT_OF_RESOURCE
)){
1993 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1994 "0125 FDISC Failed (x%x). "
1995 "Fabric out of resources\n",
1996 stat
.un
.lsRjtError
);
1997 lpfc_vport_set_state(vport
,
1998 FC_VPORT_NO_FABRIC_RSCS
);
2002 case LSRJT_LOGICAL_BSY
:
2003 if ((cmd
== ELS_CMD_PLOGI
) ||
2004 (cmd
== ELS_CMD_PRLI
)) {
2007 } else if (cmd
== ELS_CMD_FDISC
) {
2008 /* FDISC retry policy */
2010 if (cmdiocb
->retry
>= 32)
2016 case LSRJT_LOGICAL_ERR
:
2017 /* There are some cases where switches return this
2018 * error when they are not ready and should be returning
2019 * Logical Busy. We should delay every time.
2021 if (cmd
== ELS_CMD_FDISC
&&
2022 stat
.un
.b
.lsRjtRsnCodeExp
== LSEXP_PORT_LOGIN_REQ
) {
2028 case LSRJT_PROTOCOL_ERR
:
2029 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
2030 (cmd
== ELS_CMD_FDISC
) &&
2031 ((stat
.un
.b
.lsRjtRsnCodeExp
== LSEXP_INVALID_PNAME
) ||
2032 (stat
.un
.b
.lsRjtRsnCodeExp
== LSEXP_INVALID_NPORT_ID
))
2034 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
2035 "0123 FDISC Failed (x%x). "
2036 "Fabric Detected Bad WWN\n",
2037 stat
.un
.lsRjtError
);
2038 lpfc_vport_set_state(vport
,
2039 FC_VPORT_FABRIC_REJ_WWN
);
2045 case IOSTAT_INTERMED_RSP
:
2053 if (did
== FDMI_DID
)
2056 if ((cmd
== ELS_CMD_FLOGI
) &&
2057 (phba
->fc_topology
!= TOPOLOGY_LOOP
) &&
2058 !lpfc_error_lost_link(irsp
)) {
2059 /* FLOGI retry policy */
2062 if (cmdiocb
->retry
>= 32)
2066 if ((++cmdiocb
->retry
) >= maxretry
) {
2067 phba
->fc_stat
.elsRetryExceeded
++;
2071 if ((vport
->load_flag
& FC_UNLOADING
) != 0)
2076 /* Retry ELS command <elsCmd> to remote NPORT <did> */
2077 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
2078 "0107 Retry ELS command x%x to remote "
2079 "NPORT x%x Data: x%x x%x\n",
2080 cmd
, did
, cmdiocb
->retry
, delay
);
2082 if (((cmd
== ELS_CMD_PLOGI
) || (cmd
== ELS_CMD_ADISC
)) &&
2083 ((irsp
->ulpStatus
!= IOSTAT_LOCAL_REJECT
) ||
2084 ((irsp
->un
.ulpWord
[4] & 0xff) != IOERR_NO_RESOURCES
))) {
2085 /* Don't reset timer for no resources */
2087 /* If discovery / RSCN timer is running, reset it */
2088 if (timer_pending(&vport
->fc_disctmo
) ||
2089 (vport
->fc_flag
& FC_RSCN_MODE
))
2090 lpfc_set_disctmo(vport
);
2093 phba
->fc_stat
.elsXmitRetry
++;
2094 if (ndlp
&& delay
) {
2095 phba
->fc_stat
.elsDelayRetry
++;
2096 ndlp
->nlp_retry
= cmdiocb
->retry
;
2098 /* delay is specified in milliseconds */
2099 mod_timer(&ndlp
->nlp_delayfunc
,
2100 jiffies
+ msecs_to_jiffies(delay
));
2101 spin_lock_irq(shost
->host_lock
);
2102 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
2103 spin_unlock_irq(shost
->host_lock
);
2105 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
2106 if (cmd
== ELS_CMD_PRLI
)
2107 lpfc_nlp_set_state(vport
, ndlp
,
2108 NLP_STE_REG_LOGIN_ISSUE
);
2110 lpfc_nlp_set_state(vport
, ndlp
,
2112 ndlp
->nlp_last_elscmd
= cmd
;
2118 lpfc_issue_els_flogi(vport
, ndlp
, cmdiocb
->retry
);
2121 lpfc_issue_els_fdisc(vport
, ndlp
, cmdiocb
->retry
);
2125 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
2126 lpfc_nlp_set_state(vport
, ndlp
,
2127 NLP_STE_PLOGI_ISSUE
);
2129 lpfc_issue_els_plogi(vport
, did
, cmdiocb
->retry
);
2132 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
2133 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_ADISC_ISSUE
);
2134 lpfc_issue_els_adisc(vport
, ndlp
, cmdiocb
->retry
);
2137 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
2138 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PRLI_ISSUE
);
2139 lpfc_issue_els_prli(vport
, ndlp
, cmdiocb
->retry
);
2142 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
2143 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
2144 lpfc_issue_els_logo(vport
, ndlp
, cmdiocb
->retry
);
2148 /* No retry ELS command <elsCmd> to remote NPORT <did> */
2150 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
2151 "0137 No retry ELS command x%x to remote "
2152 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
2153 cmd
, did
, irsp
->ulpStatus
,
2154 irsp
->un
.ulpWord
[4]);
2157 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
2158 "0108 No retry ELS command x%x to remote "
2159 "NPORT x%x Retried:%d Error:x%x/%x\n",
2160 cmd
, did
, cmdiocb
->retry
, irsp
->ulpStatus
,
2161 irsp
->un
.ulpWord
[4]);
2167 lpfc_els_free_data(struct lpfc_hba
*phba
, struct lpfc_dmabuf
*buf_ptr1
)
2169 struct lpfc_dmabuf
*buf_ptr
;
2171 /* Free the response before processing the command. */
2172 if (!list_empty(&buf_ptr1
->list
)) {
2173 list_remove_head(&buf_ptr1
->list
, buf_ptr
,
2176 lpfc_mbuf_free(phba
, buf_ptr
->virt
, buf_ptr
->phys
);
2179 lpfc_mbuf_free(phba
, buf_ptr1
->virt
, buf_ptr1
->phys
);
2185 lpfc_els_free_bpl(struct lpfc_hba
*phba
, struct lpfc_dmabuf
*buf_ptr
)
2187 lpfc_mbuf_free(phba
, buf_ptr
->virt
, buf_ptr
->phys
);
2193 lpfc_els_free_iocb(struct lpfc_hba
*phba
, struct lpfc_iocbq
*elsiocb
)
2195 struct lpfc_dmabuf
*buf_ptr
, *buf_ptr1
;
2196 struct lpfc_nodelist
*ndlp
;
2198 ndlp
= (struct lpfc_nodelist
*)elsiocb
->context1
;
2200 if (ndlp
->nlp_flag
& NLP_DEFER_RM
) {
2203 /* If the ndlp is not being used by another discovery
2206 if (!lpfc_nlp_not_used(ndlp
)) {
2207 /* If ndlp is being used by another discovery
2208 * thread, just clear NLP_DEFER_RM
2210 ndlp
->nlp_flag
&= ~NLP_DEFER_RM
;
2215 elsiocb
->context1
= NULL
;
2217 /* context2 = cmd, context2->next = rsp, context3 = bpl */
2218 if (elsiocb
->context2
) {
2219 if (elsiocb
->iocb_flag
& LPFC_DELAY_MEM_FREE
) {
2220 /* Firmware could still be in progress of DMAing
2221 * payload, so don't free data buffer till after
2224 elsiocb
->iocb_flag
&= ~LPFC_DELAY_MEM_FREE
;
2225 buf_ptr
= elsiocb
->context2
;
2226 elsiocb
->context2
= NULL
;
2229 spin_lock_irq(&phba
->hbalock
);
2230 if (!list_empty(&buf_ptr
->list
)) {
2231 list_remove_head(&buf_ptr
->list
,
2232 buf_ptr1
, struct lpfc_dmabuf
,
2234 INIT_LIST_HEAD(&buf_ptr1
->list
);
2235 list_add_tail(&buf_ptr1
->list
,
2239 INIT_LIST_HEAD(&buf_ptr
->list
);
2240 list_add_tail(&buf_ptr
->list
, &phba
->elsbuf
);
2242 spin_unlock_irq(&phba
->hbalock
);
2245 buf_ptr1
= (struct lpfc_dmabuf
*) elsiocb
->context2
;
2246 lpfc_els_free_data(phba
, buf_ptr1
);
2250 if (elsiocb
->context3
) {
2251 buf_ptr
= (struct lpfc_dmabuf
*) elsiocb
->context3
;
2252 lpfc_els_free_bpl(phba
, buf_ptr
);
2254 lpfc_sli_release_iocbq(phba
, elsiocb
);
2259 lpfc_cmpl_els_logo_acc(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
2260 struct lpfc_iocbq
*rspiocb
)
2262 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
2263 struct lpfc_vport
*vport
= cmdiocb
->vport
;
2266 irsp
= &rspiocb
->iocb
;
2267 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
2268 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
2269 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4], ndlp
->nlp_DID
);
2270 /* ACC to LOGO completes to NPort <nlp_DID> */
2271 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
2272 "0109 ACC to LOGO completes to NPort x%x "
2273 "Data: x%x x%x x%x\n",
2274 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
2277 if (ndlp
->nlp_state
== NLP_STE_NPR_NODE
) {
2278 /* NPort Recovery mode or node is just allocated */
2279 if (!lpfc_nlp_not_used(ndlp
)) {
2280 /* If the ndlp is being used by another discovery
2281 * thread, just unregister the RPI.
2283 lpfc_unreg_rpi(vport
, ndlp
);
2285 /* Indicate the node has already released, should
2286 * not reference to it from within lpfc_els_free_iocb.
2288 cmdiocb
->context1
= NULL
;
2291 lpfc_els_free_iocb(phba
, cmdiocb
);
2296 lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
2298 struct lpfc_dmabuf
*mp
= (struct lpfc_dmabuf
*) (pmb
->context1
);
2299 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
2301 pmb
->context1
= NULL
;
2302 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
2304 mempool_free(pmb
, phba
->mbox_mem_pool
);
2307 /* This is the end of the default RPI cleanup logic for this
2308 * ndlp. If no other discovery threads are using this ndlp.
2309 * we should free all resources associated with it.
2311 lpfc_nlp_not_used(ndlp
);
2317 lpfc_cmpl_els_rsp(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
2318 struct lpfc_iocbq
*rspiocb
)
2320 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
2321 struct lpfc_vport
*vport
= ndlp
? ndlp
->vport
: NULL
;
2322 struct Scsi_Host
*shost
= vport
? lpfc_shost_from_vport(vport
) : NULL
;
2325 LPFC_MBOXQ_t
*mbox
= NULL
;
2326 struct lpfc_dmabuf
*mp
= NULL
;
2327 uint32_t ls_rjt
= 0;
2329 irsp
= &rspiocb
->iocb
;
2331 if (cmdiocb
->context_un
.mbox
)
2332 mbox
= cmdiocb
->context_un
.mbox
;
2334 /* First determine if this is a LS_RJT cmpl. Note, this callback
2335 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
2337 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) cmdiocb
->context2
)->virt
);
2338 if (ndlp
&& (*((uint32_t *) (pcmd
)) == ELS_CMD_LS_RJT
)) {
2339 /* A LS_RJT associated with Default RPI cleanup has its own
2340 * seperate code path.
2342 if (!(ndlp
->nlp_flag
& NLP_RM_DFLT_RPI
))
2346 /* Check to see if link went down during discovery */
2347 if (!ndlp
|| lpfc_els_chk_latt(vport
)) {
2349 mp
= (struct lpfc_dmabuf
*) mbox
->context1
;
2351 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
2354 mempool_free(mbox
, phba
->mbox_mem_pool
);
2356 if (ndlp
&& (ndlp
->nlp_flag
& NLP_RM_DFLT_RPI
))
2357 if (lpfc_nlp_not_used(ndlp
)) {
2359 /* Indicate the node has already released,
2360 * should not reference to it from within
2361 * the routine lpfc_els_free_iocb.
2363 cmdiocb
->context1
= NULL
;
2368 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
2369 "ELS rsp cmpl: status:x%x/x%x did:x%x",
2370 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
2371 cmdiocb
->iocb
.un
.elsreq64
.remoteID
);
2372 /* ELS response tag <ulpIoTag> completes */
2373 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
2374 "0110 ELS response tag x%x completes "
2375 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
2376 cmdiocb
->iocb
.ulpIoTag
, rspiocb
->iocb
.ulpStatus
,
2377 rspiocb
->iocb
.un
.ulpWord
[4], rspiocb
->iocb
.ulpTimeout
,
2378 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
2381 if ((rspiocb
->iocb
.ulpStatus
== 0)
2382 && (ndlp
->nlp_flag
& NLP_ACC_REGLOGIN
)) {
2383 lpfc_unreg_rpi(vport
, ndlp
);
2384 /* Increment reference count to ndlp to hold the
2385 * reference to ndlp for the callback function.
2387 mbox
->context2
= lpfc_nlp_get(ndlp
);
2388 mbox
->vport
= vport
;
2389 if (ndlp
->nlp_flag
& NLP_RM_DFLT_RPI
) {
2390 mbox
->mbox_flag
|= LPFC_MBX_IMED_UNREG
;
2391 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_dflt_rpi
;
2394 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_reg_login
;
2395 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
2396 lpfc_nlp_set_state(vport
, ndlp
,
2397 NLP_STE_REG_LOGIN_ISSUE
);
2399 if (lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
)
2400 != MBX_NOT_FINISHED
)
2403 /* Decrement the ndlp reference count we
2404 * set for this failed mailbox command.
2408 /* ELS rsp: Cannot issue reg_login for <NPortid> */
2409 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
2410 "0138 ELS rsp: Cannot issue reg_login for x%x "
2411 "Data: x%x x%x x%x\n",
2412 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
2415 if (lpfc_nlp_not_used(ndlp
)) {
2417 /* Indicate node has already been released,
2418 * should not reference to it from within
2419 * the routine lpfc_els_free_iocb.
2421 cmdiocb
->context1
= NULL
;
2424 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
2425 if (!lpfc_error_lost_link(irsp
) &&
2426 ndlp
->nlp_flag
& NLP_ACC_REGLOGIN
) {
2427 if (lpfc_nlp_not_used(ndlp
)) {
2429 /* Indicate node has already been
2430 * released, should not reference
2431 * to it from within the routine
2432 * lpfc_els_free_iocb.
2434 cmdiocb
->context1
= NULL
;
2438 mp
= (struct lpfc_dmabuf
*) mbox
->context1
;
2440 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
2443 mempool_free(mbox
, phba
->mbox_mem_pool
);
2447 spin_lock_irq(shost
->host_lock
);
2448 ndlp
->nlp_flag
&= ~(NLP_ACC_REGLOGIN
| NLP_RM_DFLT_RPI
);
2449 spin_unlock_irq(shost
->host_lock
);
2451 /* If the node is not being used by another discovery thread,
2452 * and we are sending a reject, we are done with it.
2453 * Release driver reference count here and free associated
2457 if (lpfc_nlp_not_used(ndlp
))
2458 /* Indicate node has already been released,
2459 * should not reference to it from within
2460 * the routine lpfc_els_free_iocb.
2462 cmdiocb
->context1
= NULL
;
2465 lpfc_els_free_iocb(phba
, cmdiocb
);
2470 lpfc_els_rsp_acc(struct lpfc_vport
*vport
, uint32_t flag
,
2471 struct lpfc_iocbq
*oldiocb
, struct lpfc_nodelist
*ndlp
,
2474 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2475 struct lpfc_hba
*phba
= vport
->phba
;
2478 struct lpfc_iocbq
*elsiocb
;
2479 struct lpfc_sli_ring
*pring
;
2480 struct lpfc_sli
*psli
;
2484 ELS_PKT
*els_pkt_ptr
;
2487 pring
= &psli
->ring
[LPFC_ELS_RING
]; /* ELS ring */
2488 oldcmd
= &oldiocb
->iocb
;
2492 cmdsize
= sizeof(uint32_t);
2493 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
,
2494 ndlp
, ndlp
->nlp_DID
, ELS_CMD_ACC
);
2496 spin_lock_irq(shost
->host_lock
);
2497 ndlp
->nlp_flag
&= ~NLP_LOGO_ACC
;
2498 spin_unlock_irq(shost
->host_lock
);
2502 icmd
= &elsiocb
->iocb
;
2503 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri */
2504 pcmd
= (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
2505 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
2506 pcmd
+= sizeof(uint32_t);
2508 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
2509 "Issue ACC: did:x%x flg:x%x",
2510 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
2513 cmdsize
= (sizeof(struct serv_parm
) + sizeof(uint32_t));
2514 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
,
2515 ndlp
, ndlp
->nlp_DID
, ELS_CMD_ACC
);
2519 icmd
= &elsiocb
->iocb
;
2520 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri */
2521 pcmd
= (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
2524 elsiocb
->context_un
.mbox
= mbox
;
2526 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
2527 pcmd
+= sizeof(uint32_t);
2528 memcpy(pcmd
, &vport
->fc_sparam
, sizeof(struct serv_parm
));
2530 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
2531 "Issue ACC PLOGI: did:x%x flg:x%x",
2532 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
2535 cmdsize
= sizeof(uint32_t) + sizeof(PRLO
);
2536 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
,
2537 ndlp
, ndlp
->nlp_DID
, ELS_CMD_PRLO
);
2541 icmd
= &elsiocb
->iocb
;
2542 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri */
2543 pcmd
= (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
2545 memcpy(pcmd
, ((struct lpfc_dmabuf
*) oldiocb
->context2
)->virt
,
2546 sizeof(uint32_t) + sizeof(PRLO
));
2547 *((uint32_t *) (pcmd
)) = ELS_CMD_PRLO_ACC
;
2548 els_pkt_ptr
= (ELS_PKT
*) pcmd
;
2549 els_pkt_ptr
->un
.prlo
.acceptRspCode
= PRLO_REQ_EXECUTED
;
2551 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
2552 "Issue ACC PRLO: did:x%x flg:x%x",
2553 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
2558 /* Xmit ELS ACC response tag <ulpIoTag> */
2559 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
2560 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
2561 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n",
2562 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
2563 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
2565 if (ndlp
->nlp_flag
& NLP_LOGO_ACC
) {
2566 spin_lock_irq(shost
->host_lock
);
2567 ndlp
->nlp_flag
&= ~NLP_LOGO_ACC
;
2568 spin_unlock_irq(shost
->host_lock
);
2569 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_logo_acc
;
2571 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
2574 phba
->fc_stat
.elsXmitACC
++;
2575 rc
= lpfc_sli_issue_iocb(phba
, pring
, elsiocb
, 0);
2576 if (rc
== IOCB_ERROR
) {
2577 lpfc_els_free_iocb(phba
, elsiocb
);
2584 lpfc_els_rsp_reject(struct lpfc_vport
*vport
, uint32_t rejectError
,
2585 struct lpfc_iocbq
*oldiocb
, struct lpfc_nodelist
*ndlp
,
2588 struct lpfc_hba
*phba
= vport
->phba
;
2591 struct lpfc_iocbq
*elsiocb
;
2592 struct lpfc_sli_ring
*pring
;
2593 struct lpfc_sli
*psli
;
2599 pring
= &psli
->ring
[LPFC_ELS_RING
]; /* ELS ring */
2601 cmdsize
= 2 * sizeof(uint32_t);
2602 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
2603 ndlp
->nlp_DID
, ELS_CMD_LS_RJT
);
2607 icmd
= &elsiocb
->iocb
;
2608 oldcmd
= &oldiocb
->iocb
;
2609 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri */
2610 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
2612 *((uint32_t *) (pcmd
)) = ELS_CMD_LS_RJT
;
2613 pcmd
+= sizeof(uint32_t);
2614 *((uint32_t *) (pcmd
)) = rejectError
;
2617 elsiocb
->context_un
.mbox
= mbox
;
2619 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
2620 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
2621 "0129 Xmit ELS RJT x%x response tag x%x "
2622 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
2624 rejectError
, elsiocb
->iotag
,
2625 elsiocb
->iocb
.ulpContext
, ndlp
->nlp_DID
,
2626 ndlp
->nlp_flag
, ndlp
->nlp_state
, ndlp
->nlp_rpi
);
2627 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
2628 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
2629 ndlp
->nlp_DID
, ndlp
->nlp_flag
, rejectError
);
2631 phba
->fc_stat
.elsXmitLSRJT
++;
2632 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
2633 rc
= lpfc_sli_issue_iocb(phba
, pring
, elsiocb
, 0);
2635 if (rc
== IOCB_ERROR
) {
2636 lpfc_els_free_iocb(phba
, elsiocb
);
2643 lpfc_els_rsp_adisc_acc(struct lpfc_vport
*vport
, struct lpfc_iocbq
*oldiocb
,
2644 struct lpfc_nodelist
*ndlp
)
2646 struct lpfc_hba
*phba
= vport
->phba
;
2647 struct lpfc_sli
*psli
= &phba
->sli
;
2648 struct lpfc_sli_ring
*pring
= &psli
->ring
[LPFC_ELS_RING
];
2650 IOCB_t
*icmd
, *oldcmd
;
2651 struct lpfc_iocbq
*elsiocb
;
2656 cmdsize
= sizeof(uint32_t) + sizeof(ADISC
);
2657 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
2658 ndlp
->nlp_DID
, ELS_CMD_ACC
);
2662 icmd
= &elsiocb
->iocb
;
2663 oldcmd
= &oldiocb
->iocb
;
2664 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri */
2666 /* Xmit ADISC ACC response tag <ulpIoTag> */
2667 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
2668 "0130 Xmit ADISC ACC response iotag x%x xri: "
2669 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
2670 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
2671 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
2673 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
2675 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
2676 pcmd
+= sizeof(uint32_t);
2678 ap
= (ADISC
*) (pcmd
);
2679 ap
->hardAL_PA
= phba
->fc_pref_ALPA
;
2680 memcpy(&ap
->portName
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
2681 memcpy(&ap
->nodeName
, &vport
->fc_nodename
, sizeof(struct lpfc_name
));
2682 ap
->DID
= be32_to_cpu(vport
->fc_myDID
);
2684 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
2685 "Issue ACC ADISC: did:x%x flg:x%x",
2686 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
2688 phba
->fc_stat
.elsXmitACC
++;
2689 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
2690 rc
= lpfc_sli_issue_iocb(phba
, pring
, elsiocb
, 0);
2691 if (rc
== IOCB_ERROR
) {
2692 lpfc_els_free_iocb(phba
, elsiocb
);
2699 lpfc_els_rsp_prli_acc(struct lpfc_vport
*vport
, struct lpfc_iocbq
*oldiocb
,
2700 struct lpfc_nodelist
*ndlp
)
2702 struct lpfc_hba
*phba
= vport
->phba
;
2707 struct lpfc_iocbq
*elsiocb
;
2708 struct lpfc_sli_ring
*pring
;
2709 struct lpfc_sli
*psli
;
2715 pring
= &psli
->ring
[LPFC_ELS_RING
]; /* ELS ring */
2717 cmdsize
= sizeof(uint32_t) + sizeof(PRLI
);
2718 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
2719 ndlp
->nlp_DID
, (ELS_CMD_ACC
| (ELS_CMD_PRLI
& ~ELS_RSP_MASK
)));
2723 icmd
= &elsiocb
->iocb
;
2724 oldcmd
= &oldiocb
->iocb
;
2725 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri */
2726 /* Xmit PRLI ACC response tag <ulpIoTag> */
2727 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
2728 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
2729 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
2730 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
2731 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
2733 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
2735 *((uint32_t *) (pcmd
)) = (ELS_CMD_ACC
| (ELS_CMD_PRLI
& ~ELS_RSP_MASK
));
2736 pcmd
+= sizeof(uint32_t);
2738 /* For PRLI, remainder of payload is PRLI parameter page */
2739 memset(pcmd
, 0, sizeof(PRLI
));
2741 npr
= (PRLI
*) pcmd
;
2744 * If our firmware version is 3.20 or later,
2745 * set the following bits for FC-TAPE support.
2747 if (vpd
->rev
.feaLevelHigh
>= 0x02) {
2748 npr
->ConfmComplAllowed
= 1;
2750 npr
->TaskRetryIdReq
= 1;
2753 npr
->acceptRspCode
= PRLI_REQ_EXECUTED
;
2754 npr
->estabImagePair
= 1;
2755 npr
->readXferRdyDis
= 1;
2756 npr
->ConfmComplAllowed
= 1;
2758 npr
->prliType
= PRLI_FCP_TYPE
;
2759 npr
->initiatorFunc
= 1;
2761 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
2762 "Issue ACC PRLI: did:x%x flg:x%x",
2763 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
2765 phba
->fc_stat
.elsXmitACC
++;
2766 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
2768 rc
= lpfc_sli_issue_iocb(phba
, pring
, elsiocb
, 0);
2769 if (rc
== IOCB_ERROR
) {
2770 lpfc_els_free_iocb(phba
, elsiocb
);
2777 lpfc_els_rsp_rnid_acc(struct lpfc_vport
*vport
, uint8_t format
,
2778 struct lpfc_iocbq
*oldiocb
, struct lpfc_nodelist
*ndlp
)
2780 struct lpfc_hba
*phba
= vport
->phba
;
2782 IOCB_t
*icmd
, *oldcmd
;
2783 struct lpfc_iocbq
*elsiocb
;
2784 struct lpfc_sli_ring
*pring
;
2785 struct lpfc_sli
*psli
;
2791 pring
= &psli
->ring
[LPFC_ELS_RING
];
2793 cmdsize
= sizeof(uint32_t) + sizeof(uint32_t)
2794 + (2 * sizeof(struct lpfc_name
));
2796 cmdsize
+= sizeof(RNID_TOP_DISC
);
2798 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
2799 ndlp
->nlp_DID
, ELS_CMD_ACC
);
2803 icmd
= &elsiocb
->iocb
;
2804 oldcmd
= &oldiocb
->iocb
;
2805 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri */
2806 /* Xmit RNID ACC response tag <ulpIoTag> */
2807 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
2808 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
2809 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
);
2810 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
2811 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
2812 pcmd
+= sizeof(uint32_t);
2814 memset(pcmd
, 0, sizeof(RNID
));
2815 rn
= (RNID
*) (pcmd
);
2816 rn
->Format
= format
;
2817 rn
->CommonLen
= (2 * sizeof(struct lpfc_name
));
2818 memcpy(&rn
->portName
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
2819 memcpy(&rn
->nodeName
, &vport
->fc_nodename
, sizeof(struct lpfc_name
));
2822 rn
->SpecificLen
= 0;
2824 case RNID_TOPOLOGY_DISC
:
2825 rn
->SpecificLen
= sizeof(RNID_TOP_DISC
);
2826 memcpy(&rn
->un
.topologyDisc
.portName
,
2827 &vport
->fc_portname
, sizeof(struct lpfc_name
));
2828 rn
->un
.topologyDisc
.unitType
= RNID_HBA
;
2829 rn
->un
.topologyDisc
.physPort
= 0;
2830 rn
->un
.topologyDisc
.attachedNodes
= 0;
2834 rn
->SpecificLen
= 0;
2838 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
2839 "Issue ACC RNID: did:x%x flg:x%x",
2840 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
2842 phba
->fc_stat
.elsXmitACC
++;
2843 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
2845 elsiocb
->context1
= NULL
; /* Don't need ndlp for cmpl,
2846 * it could be freed */
2848 rc
= lpfc_sli_issue_iocb(phba
, pring
, elsiocb
, 0);
2849 if (rc
== IOCB_ERROR
) {
2850 lpfc_els_free_iocb(phba
, elsiocb
);
2857 lpfc_els_disc_adisc(struct lpfc_vport
*vport
)
2859 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2860 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
2863 /* go thru NPR nodes and issue any remaining ELS ADISCs */
2864 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
, nlp_listp
) {
2865 if (!NLP_CHK_NODE_ACT(ndlp
))
2867 if (ndlp
->nlp_state
== NLP_STE_NPR_NODE
&&
2868 (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) != 0 &&
2869 (ndlp
->nlp_flag
& NLP_NPR_ADISC
) != 0) {
2870 spin_lock_irq(shost
->host_lock
);
2871 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
2872 spin_unlock_irq(shost
->host_lock
);
2873 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
2874 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_ADISC_ISSUE
);
2875 lpfc_issue_els_adisc(vport
, ndlp
, 0);
2877 vport
->num_disc_nodes
++;
2878 if (vport
->num_disc_nodes
>=
2879 vport
->cfg_discovery_threads
) {
2880 spin_lock_irq(shost
->host_lock
);
2881 vport
->fc_flag
|= FC_NLP_MORE
;
2882 spin_unlock_irq(shost
->host_lock
);
2887 if (sentadisc
== 0) {
2888 spin_lock_irq(shost
->host_lock
);
2889 vport
->fc_flag
&= ~FC_NLP_MORE
;
2890 spin_unlock_irq(shost
->host_lock
);
2896 lpfc_els_disc_plogi(struct lpfc_vport
*vport
)
2898 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2899 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
2902 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
2903 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
, nlp_listp
) {
2904 if (!NLP_CHK_NODE_ACT(ndlp
))
2906 if (ndlp
->nlp_state
== NLP_STE_NPR_NODE
&&
2907 (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) != 0 &&
2908 (ndlp
->nlp_flag
& NLP_DELAY_TMO
) == 0 &&
2909 (ndlp
->nlp_flag
& NLP_NPR_ADISC
) == 0) {
2910 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
2911 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
2912 lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0);
2914 vport
->num_disc_nodes
++;
2915 if (vport
->num_disc_nodes
>=
2916 vport
->cfg_discovery_threads
) {
2917 spin_lock_irq(shost
->host_lock
);
2918 vport
->fc_flag
|= FC_NLP_MORE
;
2919 spin_unlock_irq(shost
->host_lock
);
2925 lpfc_set_disctmo(vport
);
2928 spin_lock_irq(shost
->host_lock
);
2929 vport
->fc_flag
&= ~FC_NLP_MORE
;
2930 spin_unlock_irq(shost
->host_lock
);
2936 lpfc_els_flush_rscn(struct lpfc_vport
*vport
)
2938 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2939 struct lpfc_hba
*phba
= vport
->phba
;
2942 spin_lock_irq(shost
->host_lock
);
2943 if (vport
->fc_rscn_flush
) {
2944 /* Another thread is walking fc_rscn_id_list on this vport */
2945 spin_unlock_irq(shost
->host_lock
);
2948 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
2949 vport
->fc_rscn_flush
= 1;
2950 spin_unlock_irq(shost
->host_lock
);
2952 for (i
= 0; i
< vport
->fc_rscn_id_cnt
; i
++) {
2953 lpfc_in_buf_free(phba
, vport
->fc_rscn_id_list
[i
]);
2954 vport
->fc_rscn_id_list
[i
] = NULL
;
2956 spin_lock_irq(shost
->host_lock
);
2957 vport
->fc_rscn_id_cnt
= 0;
2958 vport
->fc_flag
&= ~(FC_RSCN_MODE
| FC_RSCN_DISCOVERY
);
2959 spin_unlock_irq(shost
->host_lock
);
2960 lpfc_can_disctmo(vport
);
2961 /* Indicate we are done walking this fc_rscn_id_list */
2962 vport
->fc_rscn_flush
= 0;
2966 lpfc_rscn_payload_check(struct lpfc_vport
*vport
, uint32_t did
)
2971 uint32_t payload_len
, i
;
2972 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2974 ns_did
.un
.word
= did
;
2976 /* Never match fabric nodes for RSCNs */
2977 if ((did
& Fabric_DID_MASK
) == Fabric_DID_MASK
)
2980 /* If we are doing a FULL RSCN rediscovery, match everything */
2981 if (vport
->fc_flag
& FC_RSCN_DISCOVERY
)
2984 spin_lock_irq(shost
->host_lock
);
2985 if (vport
->fc_rscn_flush
) {
2986 /* Another thread is walking fc_rscn_id_list on this vport */
2987 spin_unlock_irq(shost
->host_lock
);
2990 /* Indicate we are walking fc_rscn_id_list on this vport */
2991 vport
->fc_rscn_flush
= 1;
2992 spin_unlock_irq(shost
->host_lock
);
2993 for (i
= 0; i
< vport
->fc_rscn_id_cnt
; i
++) {
2994 lp
= vport
->fc_rscn_id_list
[i
]->virt
;
2995 payload_len
= be32_to_cpu(*lp
++ & ~ELS_CMD_MASK
);
2996 payload_len
-= sizeof(uint32_t); /* take off word 0 */
2997 while (payload_len
) {
2998 rscn_did
.un
.word
= be32_to_cpu(*lp
++);
2999 payload_len
-= sizeof(uint32_t);
3000 switch (rscn_did
.un
.b
.resv
) {
3001 case 0: /* Single N_Port ID effected */
3002 if (ns_did
.un
.word
== rscn_did
.un
.word
)
3003 goto return_did_out
;
3005 case 1: /* Whole N_Port Area effected */
3006 if ((ns_did
.un
.b
.domain
== rscn_did
.un
.b
.domain
)
3007 && (ns_did
.un
.b
.area
== rscn_did
.un
.b
.area
))
3008 goto return_did_out
;
3010 case 2: /* Whole N_Port Domain effected */
3011 if (ns_did
.un
.b
.domain
== rscn_did
.un
.b
.domain
)
3012 goto return_did_out
;
3015 /* Unknown Identifier in RSCN node */
3016 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
3017 "0217 Unknown Identifier in "
3018 "RSCN payload Data: x%x\n",
3020 case 3: /* Whole Fabric effected */
3021 goto return_did_out
;
3025 /* Indicate we are done with walking fc_rscn_id_list on this vport */
3026 vport
->fc_rscn_flush
= 0;
3029 /* Indicate we are done with walking fc_rscn_id_list on this vport */
3030 vport
->fc_rscn_flush
= 0;
3035 lpfc_rscn_recovery_check(struct lpfc_vport
*vport
)
3037 struct lpfc_nodelist
*ndlp
= NULL
;
3039 /* Look at all nodes effected by pending RSCNs and move
3040 * them to NPR state.
3043 list_for_each_entry(ndlp
, &vport
->fc_nodes
, nlp_listp
) {
3044 if (!NLP_CHK_NODE_ACT(ndlp
) ||
3045 ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
||
3046 lpfc_rscn_payload_check(vport
, ndlp
->nlp_DID
) == 0)
3049 lpfc_disc_state_machine(vport
, ndlp
, NULL
,
3050 NLP_EVT_DEVICE_RECOVERY
);
3053 * Make sure NLP_DELAY_TMO is NOT running after a device
3056 if (ndlp
->nlp_flag
& NLP_DELAY_TMO
)
3057 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
3064 lpfc_els_rcv_rscn(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
3065 struct lpfc_nodelist
*ndlp
)
3067 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3068 struct lpfc_hba
*phba
= vport
->phba
;
3069 struct lpfc_dmabuf
*pcmd
;
3070 uint32_t *lp
, *datap
;
3072 uint32_t payload_len
, length
, nportid
, *cmd
;
3074 int rscn_id
= 0, hba_id
= 0;
3077 icmd
= &cmdiocb
->iocb
;
3078 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
3079 lp
= (uint32_t *) pcmd
->virt
;
3081 payload_len
= be32_to_cpu(*lp
++ & ~ELS_CMD_MASK
);
3082 payload_len
-= sizeof(uint32_t); /* take off word 0 */
3084 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
3085 "0214 RSCN received Data: x%x x%x x%x x%x\n",
3086 vport
->fc_flag
, payload_len
, *lp
,
3087 vport
->fc_rscn_id_cnt
);
3088 for (i
= 0; i
< payload_len
/sizeof(uint32_t); i
++)
3089 fc_host_post_event(shost
, fc_get_event_number(),
3090 FCH_EVT_RSCN
, lp
[i
]);
3092 /* If we are about to begin discovery, just ACC the RSCN.
3093 * Discovery processing will satisfy it.
3095 if (vport
->port_state
<= LPFC_NS_QRY
) {
3096 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
3097 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
3098 ndlp
->nlp_DID
, vport
->port_state
, ndlp
->nlp_flag
);
3100 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
3104 /* If this RSCN just contains NPortIDs for other vports on this HBA,
3105 * just ACC and ignore it.
3107 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
3108 !(vport
->cfg_peer_port_login
)) {
3113 nportid
= ((be32_to_cpu(nportid
)) & Mask_DID
);
3114 i
-= sizeof(uint32_t);
3116 if (lpfc_find_vport_by_did(phba
, nportid
))
3119 if (rscn_id
== hba_id
) {
3120 /* ALL NPortIDs in RSCN are on HBA */
3121 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
3123 "Data: x%x x%x x%x x%x\n",
3124 vport
->fc_flag
, payload_len
,
3125 *lp
, vport
->fc_rscn_id_cnt
);
3126 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
3127 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
3128 ndlp
->nlp_DID
, vport
->port_state
,
3131 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
,
3137 spin_lock_irq(shost
->host_lock
);
3138 if (vport
->fc_rscn_flush
) {
3139 /* Another thread is walking fc_rscn_id_list on this vport */
3140 spin_unlock_irq(shost
->host_lock
);
3141 vport
->fc_flag
|= FC_RSCN_DISCOVERY
;
3144 /* Indicate we are walking fc_rscn_id_list on this vport */
3145 vport
->fc_rscn_flush
= 1;
3146 spin_unlock_irq(shost
->host_lock
);
3147 /* Get the array count after sucessfully have the token */
3148 rscn_cnt
= vport
->fc_rscn_id_cnt
;
3149 /* If we are already processing an RSCN, save the received
3150 * RSCN payload buffer, cmdiocb->context2 to process later.
3152 if (vport
->fc_flag
& (FC_RSCN_MODE
| FC_NDISC_ACTIVE
)) {
3153 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
3154 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
3155 ndlp
->nlp_DID
, vport
->port_state
, ndlp
->nlp_flag
);
3157 spin_lock_irq(shost
->host_lock
);
3158 vport
->fc_flag
|= FC_RSCN_DEFERRED
;
3159 if ((rscn_cnt
< FC_MAX_HOLD_RSCN
) &&
3160 !(vport
->fc_flag
& FC_RSCN_DISCOVERY
)) {
3161 vport
->fc_flag
|= FC_RSCN_MODE
;
3162 spin_unlock_irq(shost
->host_lock
);
3164 cmd
= vport
->fc_rscn_id_list
[rscn_cnt
-1]->virt
;
3165 length
= be32_to_cpu(*cmd
& ~ELS_CMD_MASK
);
3168 (payload_len
+ length
<= LPFC_BPL_SIZE
)) {
3169 *cmd
&= ELS_CMD_MASK
;
3170 *cmd
|= cpu_to_be32(payload_len
+ length
);
3171 memcpy(((uint8_t *)cmd
) + length
, lp
,
3174 vport
->fc_rscn_id_list
[rscn_cnt
] = pcmd
;
3175 vport
->fc_rscn_id_cnt
++;
3176 /* If we zero, cmdiocb->context2, the calling
3177 * routine will not try to free it.
3179 cmdiocb
->context2
= NULL
;
3182 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
3183 "0235 Deferred RSCN "
3184 "Data: x%x x%x x%x\n",
3185 vport
->fc_rscn_id_cnt
, vport
->fc_flag
,
3188 vport
->fc_flag
|= FC_RSCN_DISCOVERY
;
3189 spin_unlock_irq(shost
->host_lock
);
3190 /* ReDiscovery RSCN */
3191 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
3192 "0234 ReDiscovery RSCN "
3193 "Data: x%x x%x x%x\n",
3194 vport
->fc_rscn_id_cnt
, vport
->fc_flag
,
3197 /* Indicate we are done walking fc_rscn_id_list on this vport */
3198 vport
->fc_rscn_flush
= 0;
3200 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
3201 /* send RECOVERY event for ALL nodes that match RSCN payload */
3202 lpfc_rscn_recovery_check(vport
);
3203 spin_lock_irq(shost
->host_lock
);
3204 vport
->fc_flag
&= ~FC_RSCN_DEFERRED
;
3205 spin_unlock_irq(shost
->host_lock
);
3208 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
3209 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
3210 ndlp
->nlp_DID
, vport
->port_state
, ndlp
->nlp_flag
);
3212 spin_lock_irq(shost
->host_lock
);
3213 vport
->fc_flag
|= FC_RSCN_MODE
;
3214 spin_unlock_irq(shost
->host_lock
);
3215 vport
->fc_rscn_id_list
[vport
->fc_rscn_id_cnt
++] = pcmd
;
3216 /* Indicate we are done walking fc_rscn_id_list on this vport */
3217 vport
->fc_rscn_flush
= 0;
3219 * If we zero, cmdiocb->context2, the calling routine will
3220 * not try to free it.
3222 cmdiocb
->context2
= NULL
;
3223 lpfc_set_disctmo(vport
);
3225 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
3226 /* send RECOVERY event for ALL nodes that match RSCN payload */
3227 lpfc_rscn_recovery_check(vport
);
3228 return lpfc_els_handle_rscn(vport
);
3232 lpfc_els_handle_rscn(struct lpfc_vport
*vport
)
3234 struct lpfc_nodelist
*ndlp
;
3235 struct lpfc_hba
*phba
= vport
->phba
;
3237 /* Ignore RSCN if the port is being torn down. */
3238 if (vport
->load_flag
& FC_UNLOADING
) {
3239 lpfc_els_flush_rscn(vport
);
3243 /* Start timer for RSCN processing */
3244 lpfc_set_disctmo(vport
);
3246 /* RSCN processed */
3247 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
3248 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
3249 vport
->fc_flag
, 0, vport
->fc_rscn_id_cnt
,
3252 /* To process RSCN, first compare RSCN data with NameServer */
3253 vport
->fc_ns_retry
= 0;
3254 vport
->num_disc_nodes
= 0;
3256 ndlp
= lpfc_findnode_did(vport
, NameServer_DID
);
3257 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
)
3258 && ndlp
->nlp_state
== NLP_STE_UNMAPPED_NODE
) {
3259 /* Good ndlp, issue CT Request to NameServer */
3260 if (lpfc_ns_cmd(vport
, SLI_CTNS_GID_FT
, 0, 0) == 0)
3261 /* Wait for NameServer query cmpl before we can
3265 /* If login to NameServer does not exist, issue one */
3266 /* Good status, issue PLOGI to NameServer */
3267 ndlp
= lpfc_findnode_did(vport
, NameServer_DID
);
3268 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
))
3269 /* Wait for NameServer login cmpl before we can
3274 ndlp
= lpfc_enable_node(vport
, ndlp
,
3275 NLP_STE_PLOGI_ISSUE
);
3277 lpfc_els_flush_rscn(vport
);
3280 ndlp
->nlp_prev_state
= NLP_STE_UNUSED_NODE
;
3282 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
3284 lpfc_els_flush_rscn(vport
);
3287 lpfc_nlp_init(vport
, ndlp
, NameServer_DID
);
3288 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
3289 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
3291 ndlp
->nlp_type
|= NLP_FABRIC
;
3292 lpfc_issue_els_plogi(vport
, NameServer_DID
, 0);
3293 /* Wait for NameServer login cmpl before we can
3299 lpfc_els_flush_rscn(vport
);
3304 lpfc_els_rcv_flogi(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
3305 struct lpfc_nodelist
*ndlp
)
3307 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3308 struct lpfc_hba
*phba
= vport
->phba
;
3309 struct lpfc_dmabuf
*pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
3310 uint32_t *lp
= (uint32_t *) pcmd
->virt
;
3311 IOCB_t
*icmd
= &cmdiocb
->iocb
;
3312 struct serv_parm
*sp
;
3319 sp
= (struct serv_parm
*) lp
;
3321 /* FLOGI received */
3323 lpfc_set_disctmo(vport
);
3325 if (phba
->fc_topology
== TOPOLOGY_LOOP
) {
3326 /* We should never receive a FLOGI in loop mode, ignore it */
3327 did
= icmd
->un
.elsreq64
.remoteID
;
3329 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
3331 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
3332 "0113 An FLOGI ELS command x%x was "
3333 "received from DID x%x in Loop Mode\n",
3340 if ((lpfc_check_sparm(vport
, ndlp
, sp
, CLASS3
))) {
3341 /* For a FLOGI we accept, then if our portname is greater
3342 * then the remote portname we initiate Nport login.
3345 rc
= memcmp(&vport
->fc_portname
, &sp
->portName
,
3346 sizeof(struct lpfc_name
));
3349 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
3353 lpfc_linkdown(phba
);
3354 lpfc_init_link(phba
, mbox
,
3356 phba
->cfg_link_speed
);
3357 mbox
->mb
.un
.varInitLnk
.lipsr_AL_PA
= 0;
3358 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
3359 mbox
->vport
= vport
;
3360 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
3361 lpfc_set_loopback_flag(phba
);
3362 if (rc
== MBX_NOT_FINISHED
) {
3363 mempool_free(mbox
, phba
->mbox_mem_pool
);
3366 } else if (rc
> 0) { /* greater than */
3367 spin_lock_irq(shost
->host_lock
);
3368 vport
->fc_flag
|= FC_PT2PT_PLOGI
;
3369 spin_unlock_irq(shost
->host_lock
);
3371 spin_lock_irq(shost
->host_lock
);
3372 vport
->fc_flag
|= FC_PT2PT
;
3373 vport
->fc_flag
&= ~(FC_FABRIC
| FC_PUBLIC_LOOP
);
3374 spin_unlock_irq(shost
->host_lock
);
3376 /* Reject this request because invalid parameters */
3377 stat
.un
.b
.lsRjtRsvd0
= 0;
3378 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
3379 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_SPARM_OPTIONS
;
3380 stat
.un
.b
.vendorUnique
= 0;
3381 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
,
3387 lpfc_els_rsp_acc(vport
, ELS_CMD_PLOGI
, cmdiocb
, ndlp
, NULL
);
3393 lpfc_els_rcv_rnid(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
3394 struct lpfc_nodelist
*ndlp
)
3396 struct lpfc_dmabuf
*pcmd
;
3403 icmd
= &cmdiocb
->iocb
;
3404 did
= icmd
->un
.elsreq64
.remoteID
;
3405 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
3406 lp
= (uint32_t *) pcmd
->virt
;
3413 switch (rn
->Format
) {
3415 case RNID_TOPOLOGY_DISC
:
3417 lpfc_els_rsp_rnid_acc(vport
, rn
->Format
, cmdiocb
, ndlp
);
3420 /* Reject this request because format not supported */
3421 stat
.un
.b
.lsRjtRsvd0
= 0;
3422 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
3423 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CANT_GIVE_DATA
;
3424 stat
.un
.b
.vendorUnique
= 0;
3425 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
,
3432 lpfc_els_rcv_lirr(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
3433 struct lpfc_nodelist
*ndlp
)
3437 /* For now, unconditionally reject this command */
3438 stat
.un
.b
.lsRjtRsvd0
= 0;
3439 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
3440 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CANT_GIVE_DATA
;
3441 stat
.un
.b
.vendorUnique
= 0;
3442 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
3447 lpfc_els_rsp_rps_acc(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
3449 struct lpfc_sli
*psli
= &phba
->sli
;
3450 struct lpfc_sli_ring
*pring
= &psli
->ring
[LPFC_ELS_RING
];
3455 struct lpfc_iocbq
*elsiocb
;
3456 struct lpfc_nodelist
*ndlp
;
3457 uint16_t xri
, status
;
3462 ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
3463 xri
= (uint16_t) ((unsigned long)(pmb
->context1
));
3464 pmb
->context1
= NULL
;
3465 pmb
->context2
= NULL
;
3467 if (mb
->mbxStatus
) {
3468 mempool_free(pmb
, phba
->mbox_mem_pool
);
3472 cmdsize
= sizeof(RPS_RSP
) + sizeof(uint32_t);
3473 mempool_free(pmb
, phba
->mbox_mem_pool
);
3474 elsiocb
= lpfc_prep_els_iocb(phba
->pport
, 0, cmdsize
,
3475 lpfc_max_els_tries
, ndlp
,
3476 ndlp
->nlp_DID
, ELS_CMD_ACC
);
3478 /* Decrement the ndlp reference count from previous mbox command */
3484 icmd
= &elsiocb
->iocb
;
3485 icmd
->ulpContext
= xri
;
3487 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
3488 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
3489 pcmd
+= sizeof(uint32_t); /* Skip past command */
3490 rps_rsp
= (RPS_RSP
*)pcmd
;
3492 if (phba
->fc_topology
!= TOPOLOGY_LOOP
)
3496 if (phba
->pport
->fc_flag
& FC_FABRIC
)
3500 rps_rsp
->portStatus
= cpu_to_be16(status
);
3501 rps_rsp
->linkFailureCnt
= cpu_to_be32(mb
->un
.varRdLnk
.linkFailureCnt
);
3502 rps_rsp
->lossSyncCnt
= cpu_to_be32(mb
->un
.varRdLnk
.lossSyncCnt
);
3503 rps_rsp
->lossSignalCnt
= cpu_to_be32(mb
->un
.varRdLnk
.lossSignalCnt
);
3504 rps_rsp
->primSeqErrCnt
= cpu_to_be32(mb
->un
.varRdLnk
.primSeqErrCnt
);
3505 rps_rsp
->invalidXmitWord
= cpu_to_be32(mb
->un
.varRdLnk
.invalidXmitWord
);
3506 rps_rsp
->crcCnt
= cpu_to_be32(mb
->un
.varRdLnk
.crcCnt
);
3507 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
3508 lpfc_printf_vlog(ndlp
->vport
, KERN_INFO
, LOG_ELS
,
3509 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
3510 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
3511 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
3512 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
3514 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
3515 phba
->fc_stat
.elsXmitACC
++;
3516 if (lpfc_sli_issue_iocb(phba
, pring
, elsiocb
, 0) == IOCB_ERROR
)
3517 lpfc_els_free_iocb(phba
, elsiocb
);
3522 lpfc_els_rcv_rps(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
3523 struct lpfc_nodelist
*ndlp
)
3525 struct lpfc_hba
*phba
= vport
->phba
;
3529 struct lpfc_dmabuf
*pcmd
;
3533 if ((ndlp
->nlp_state
!= NLP_STE_UNMAPPED_NODE
) &&
3534 (ndlp
->nlp_state
!= NLP_STE_MAPPED_NODE
)) {
3535 stat
.un
.b
.lsRjtRsvd0
= 0;
3536 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
3537 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CANT_GIVE_DATA
;
3538 stat
.un
.b
.vendorUnique
= 0;
3539 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
,
3543 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
3544 lp
= (uint32_t *) pcmd
->virt
;
3545 flag
= (be32_to_cpu(*lp
++) & 0xf);
3549 ((flag
== 1) && (be32_to_cpu(rps
->un
.portNum
) == 0)) ||
3550 ((flag
== 2) && (memcmp(&rps
->un
.portName
, &vport
->fc_portname
,
3551 sizeof(struct lpfc_name
)) == 0))) {
3553 printk("Fix me....\n");
3555 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_ATOMIC
);
3557 lpfc_read_lnk_stat(phba
, mbox
);
3559 (void *)((unsigned long) cmdiocb
->iocb
.ulpContext
);
3560 mbox
->context2
= lpfc_nlp_get(ndlp
);
3561 mbox
->vport
= vport
;
3562 mbox
->mbox_cmpl
= lpfc_els_rsp_rps_acc
;
3563 if (lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
)
3564 != MBX_NOT_FINISHED
)
3565 /* Mbox completion will send ELS Response */
3567 /* Decrement reference count used for the failed mbox
3571 mempool_free(mbox
, phba
->mbox_mem_pool
);
3574 stat
.un
.b
.lsRjtRsvd0
= 0;
3575 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
3576 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CANT_GIVE_DATA
;
3577 stat
.un
.b
.vendorUnique
= 0;
3578 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
3583 lpfc_els_rsp_rpl_acc(struct lpfc_vport
*vport
, uint16_t cmdsize
,
3584 struct lpfc_iocbq
*oldiocb
, struct lpfc_nodelist
*ndlp
)
3586 struct lpfc_hba
*phba
= vport
->phba
;
3587 IOCB_t
*icmd
, *oldcmd
;
3589 struct lpfc_iocbq
*elsiocb
;
3590 struct lpfc_sli
*psli
= &phba
->sli
;
3591 struct lpfc_sli_ring
*pring
= &psli
->ring
[LPFC_ELS_RING
];
3594 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
3595 ndlp
->nlp_DID
, ELS_CMD_ACC
);
3600 icmd
= &elsiocb
->iocb
;
3601 oldcmd
= &oldiocb
->iocb
;
3602 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri */
3604 pcmd
= (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
3605 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
3606 pcmd
+= sizeof(uint16_t);
3607 *((uint16_t *)(pcmd
)) = be16_to_cpu(cmdsize
);
3608 pcmd
+= sizeof(uint16_t);
3610 /* Setup the RPL ACC payload */
3611 rpl_rsp
.listLen
= be32_to_cpu(1);
3613 rpl_rsp
.port_num_blk
.portNum
= 0;
3614 rpl_rsp
.port_num_blk
.portID
= be32_to_cpu(vport
->fc_myDID
);
3615 memcpy(&rpl_rsp
.port_num_blk
.portName
, &vport
->fc_portname
,
3616 sizeof(struct lpfc_name
));
3617 memcpy(pcmd
, &rpl_rsp
, cmdsize
- sizeof(uint32_t));
3618 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
3619 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3620 "0120 Xmit ELS RPL ACC response tag x%x "
3621 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
3623 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
3624 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
3626 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
3627 phba
->fc_stat
.elsXmitACC
++;
3628 if (lpfc_sli_issue_iocb(phba
, pring
, elsiocb
, 0) == IOCB_ERROR
) {
3629 lpfc_els_free_iocb(phba
, elsiocb
);
3636 lpfc_els_rcv_rpl(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
3637 struct lpfc_nodelist
*ndlp
)
3639 struct lpfc_dmabuf
*pcmd
;
3646 if ((ndlp
->nlp_state
!= NLP_STE_UNMAPPED_NODE
) &&
3647 (ndlp
->nlp_state
!= NLP_STE_MAPPED_NODE
)) {
3648 stat
.un
.b
.lsRjtRsvd0
= 0;
3649 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
3650 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CANT_GIVE_DATA
;
3651 stat
.un
.b
.vendorUnique
= 0;
3652 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
,
3656 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
3657 lp
= (uint32_t *) pcmd
->virt
;
3658 rpl
= (RPL
*) (lp
+ 1);
3660 maxsize
= be32_to_cpu(rpl
->maxsize
);
3662 /* We support only one port */
3663 if ((rpl
->index
== 0) &&
3665 ((maxsize
* sizeof(uint32_t)) >= sizeof(RPL_RSP
)))) {
3666 cmdsize
= sizeof(uint32_t) + sizeof(RPL_RSP
);
3668 cmdsize
= sizeof(uint32_t) + maxsize
* sizeof(uint32_t);
3670 lpfc_els_rsp_rpl_acc(vport
, cmdsize
, cmdiocb
, ndlp
);
3676 lpfc_els_rcv_farp(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
3677 struct lpfc_nodelist
*ndlp
)
3679 struct lpfc_dmabuf
*pcmd
;
3683 uint32_t cmd
, cnt
, did
;
3685 icmd
= &cmdiocb
->iocb
;
3686 did
= icmd
->un
.elsreq64
.remoteID
;
3687 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
3688 lp
= (uint32_t *) pcmd
->virt
;
3692 /* FARP-REQ received from DID <did> */
3693 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3694 "0601 FARP-REQ received from DID x%x\n", did
);
3695 /* We will only support match on WWPN or WWNN */
3696 if (fp
->Mflags
& ~(FARP_MATCH_NODE
| FARP_MATCH_PORT
)) {
3701 /* If this FARP command is searching for my portname */
3702 if (fp
->Mflags
& FARP_MATCH_PORT
) {
3703 if (memcmp(&fp
->RportName
, &vport
->fc_portname
,
3704 sizeof(struct lpfc_name
)) == 0)
3708 /* If this FARP command is searching for my nodename */
3709 if (fp
->Mflags
& FARP_MATCH_NODE
) {
3710 if (memcmp(&fp
->RnodeName
, &vport
->fc_nodename
,
3711 sizeof(struct lpfc_name
)) == 0)
3716 if ((ndlp
->nlp_state
== NLP_STE_UNMAPPED_NODE
) ||
3717 (ndlp
->nlp_state
== NLP_STE_MAPPED_NODE
)) {
3718 /* Log back into the node before sending the FARP. */
3719 if (fp
->Rflags
& FARP_REQUEST_PLOGI
) {
3720 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
3721 lpfc_nlp_set_state(vport
, ndlp
,
3722 NLP_STE_PLOGI_ISSUE
);
3723 lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0);
3726 /* Send a FARP response to that node */
3727 if (fp
->Rflags
& FARP_REQUEST_FARPR
)
3728 lpfc_issue_els_farpr(vport
, did
, 0);
3735 lpfc_els_rcv_farpr(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
3736 struct lpfc_nodelist
*ndlp
)
3738 struct lpfc_dmabuf
*pcmd
;
3743 icmd
= &cmdiocb
->iocb
;
3744 did
= icmd
->un
.elsreq64
.remoteID
;
3745 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
3746 lp
= (uint32_t *) pcmd
->virt
;
3749 /* FARP-RSP received from DID <did> */
3750 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3751 "0600 FARP-RSP received from DID x%x\n", did
);
3752 /* ACCEPT the Farp resp request */
3753 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
3759 lpfc_els_rcv_fan(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
3760 struct lpfc_nodelist
*fan_ndlp
)
3762 struct lpfc_dmabuf
*pcmd
;
3767 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
3768 struct lpfc_hba
*phba
= vport
->phba
;
3771 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3772 "0265 FAN received\n");
3773 icmd
= &cmdiocb
->iocb
;
3774 did
= icmd
->un
.elsreq64
.remoteID
;
3775 pcmd
= (struct lpfc_dmabuf
*)cmdiocb
->context2
;
3776 lp
= (uint32_t *)pcmd
->virt
;
3781 /* FAN received; Fan does not have a reply sequence */
3783 if (phba
->pport
->port_state
== LPFC_LOCAL_CFG_LINK
) {
3784 if ((memcmp(&phba
->fc_fabparam
.nodeName
, &fp
->FnodeName
,
3785 sizeof(struct lpfc_name
)) != 0) ||
3786 (memcmp(&phba
->fc_fabparam
.portName
, &fp
->FportName
,
3787 sizeof(struct lpfc_name
)) != 0)) {
3789 * This node has switched fabrics. FLOGI is required
3790 * Clean up the old rpi's
3793 list_for_each_entry_safe(ndlp
, next_ndlp
,
3794 &vport
->fc_nodes
, nlp_listp
) {
3795 if (!NLP_CHK_NODE_ACT(ndlp
))
3797 if (ndlp
->nlp_state
!= NLP_STE_NPR_NODE
)
3799 if (ndlp
->nlp_type
& NLP_FABRIC
) {
3801 * Clean up old Fabric, Nameserver and
3802 * other NLP_FABRIC logins
3804 lpfc_drop_node(vport
, ndlp
);
3806 } else if (!(ndlp
->nlp_flag
& NLP_NPR_ADISC
)) {
3807 /* Fail outstanding I/O now since this
3808 * device is marked for PLOGI
3810 lpfc_unreg_rpi(vport
, ndlp
);
3814 lpfc_initial_flogi(vport
);
3817 /* Discovery not needed,
3818 * move the nodes to their original state.
3820 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
,
3822 if (!NLP_CHK_NODE_ACT(ndlp
))
3824 if (ndlp
->nlp_state
!= NLP_STE_NPR_NODE
)
3827 switch (ndlp
->nlp_prev_state
) {
3828 case NLP_STE_UNMAPPED_NODE
:
3829 ndlp
->nlp_prev_state
= NLP_STE_NPR_NODE
;
3830 lpfc_nlp_set_state(vport
, ndlp
,
3831 NLP_STE_UNMAPPED_NODE
);
3834 case NLP_STE_MAPPED_NODE
:
3835 ndlp
->nlp_prev_state
= NLP_STE_NPR_NODE
;
3836 lpfc_nlp_set_state(vport
, ndlp
,
3837 NLP_STE_MAPPED_NODE
);
3845 /* Start discovery - this should just do CLEAR_LA */
3846 lpfc_disc_start(vport
);
3852 lpfc_els_timeout(unsigned long ptr
)
3854 struct lpfc_vport
*vport
= (struct lpfc_vport
*) ptr
;
3855 struct lpfc_hba
*phba
= vport
->phba
;
3856 unsigned long iflag
;
3858 spin_lock_irqsave(&vport
->work_port_lock
, iflag
);
3859 if ((vport
->work_port_events
& WORKER_ELS_TMO
) == 0) {
3860 vport
->work_port_events
|= WORKER_ELS_TMO
;
3861 spin_unlock_irqrestore(&vport
->work_port_lock
, iflag
);
3863 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3864 if (phba
->work_wait
)
3865 lpfc_worker_wake_up(phba
);
3866 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3869 spin_unlock_irqrestore(&vport
->work_port_lock
, iflag
);
3874 lpfc_els_timeout_handler(struct lpfc_vport
*vport
)
3876 struct lpfc_hba
*phba
= vport
->phba
;
3877 struct lpfc_sli_ring
*pring
;
3878 struct lpfc_iocbq
*tmp_iocb
, *piocb
;
3880 struct lpfc_dmabuf
*pcmd
;
3881 uint32_t els_command
= 0;
3883 uint32_t remote_ID
= 0xffffffff;
3885 /* If the timer is already canceled do nothing */
3886 if ((vport
->work_port_events
& WORKER_ELS_TMO
) == 0) {
3889 spin_lock_irq(&phba
->hbalock
);
3890 timeout
= (uint32_t)(phba
->fc_ratov
<< 1);
3892 pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
3894 list_for_each_entry_safe(piocb
, tmp_iocb
, &pring
->txcmplq
, list
) {
3897 if ((piocb
->iocb_flag
& LPFC_IO_LIBDFC
) != 0 ||
3898 piocb
->iocb
.ulpCommand
== CMD_ABORT_XRI_CN
||
3899 piocb
->iocb
.ulpCommand
== CMD_CLOSE_XRI_CN
)
3902 if (piocb
->vport
!= vport
)
3905 pcmd
= (struct lpfc_dmabuf
*) piocb
->context2
;
3907 els_command
= *(uint32_t *) (pcmd
->virt
);
3909 if (els_command
== ELS_CMD_FARP
||
3910 els_command
== ELS_CMD_FARPR
||
3911 els_command
== ELS_CMD_FDISC
)
3914 if (vport
!= piocb
->vport
)
3917 if (piocb
->drvrTimeout
> 0) {
3918 if (piocb
->drvrTimeout
>= timeout
)
3919 piocb
->drvrTimeout
-= timeout
;
3921 piocb
->drvrTimeout
= 0;
3925 remote_ID
= 0xffffffff;
3926 if (cmd
->ulpCommand
!= CMD_GEN_REQUEST64_CR
)
3927 remote_ID
= cmd
->un
.elsreq64
.remoteID
;
3929 struct lpfc_nodelist
*ndlp
;
3930 ndlp
= __lpfc_findnode_rpi(vport
, cmd
->ulpContext
);
3932 remote_ID
= ndlp
->nlp_DID
;
3934 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
3935 "0127 ELS timeout Data: x%x x%x x%x "
3936 "x%x\n", els_command
,
3937 remote_ID
, cmd
->ulpCommand
, cmd
->ulpIoTag
);
3938 lpfc_sli_issue_abort_iotag(phba
, pring
, piocb
);
3940 spin_unlock_irq(&phba
->hbalock
);
3942 if (phba
->sli
.ring
[LPFC_ELS_RING
].txcmplq_cnt
)
3943 mod_timer(&vport
->els_tmofunc
, jiffies
+ HZ
* timeout
);
3947 lpfc_els_flush_cmd(struct lpfc_vport
*vport
)
3949 LIST_HEAD(completions
);
3950 struct lpfc_hba
*phba
= vport
->phba
;
3951 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
3952 struct lpfc_iocbq
*tmp_iocb
, *piocb
;
3955 lpfc_fabric_abort_vport(vport
);
3957 spin_lock_irq(&phba
->hbalock
);
3958 list_for_each_entry_safe(piocb
, tmp_iocb
, &pring
->txq
, list
) {
3961 if (piocb
->iocb_flag
& LPFC_IO_LIBDFC
) {
3965 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
3966 if (cmd
->ulpCommand
== CMD_QUE_RING_BUF_CN
||
3967 cmd
->ulpCommand
== CMD_QUE_RING_BUF64_CN
||
3968 cmd
->ulpCommand
== CMD_CLOSE_XRI_CN
||
3969 cmd
->ulpCommand
== CMD_ABORT_XRI_CN
)
3972 if (piocb
->vport
!= vport
)
3975 list_move_tail(&piocb
->list
, &completions
);
3979 list_for_each_entry_safe(piocb
, tmp_iocb
, &pring
->txcmplq
, list
) {
3980 if (piocb
->iocb_flag
& LPFC_IO_LIBDFC
) {
3984 if (piocb
->vport
!= vport
)
3987 lpfc_sli_issue_abort_iotag(phba
, pring
, piocb
);
3989 spin_unlock_irq(&phba
->hbalock
);
3991 while (!list_empty(&completions
)) {
3992 piocb
= list_get_first(&completions
, struct lpfc_iocbq
, list
);
3994 list_del_init(&piocb
->list
);
3996 if (!piocb
->iocb_cmpl
)
3997 lpfc_sli_release_iocbq(phba
, piocb
);
3999 cmd
->ulpStatus
= IOSTAT_LOCAL_REJECT
;
4000 cmd
->un
.ulpWord
[4] = IOERR_SLI_ABORTED
;
4001 (piocb
->iocb_cmpl
) (phba
, piocb
, piocb
);
4009 lpfc_els_flush_all_cmd(struct lpfc_hba
*phba
)
4011 LIST_HEAD(completions
);
4012 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
4013 struct lpfc_iocbq
*tmp_iocb
, *piocb
;
4016 lpfc_fabric_abort_hba(phba
);
4017 spin_lock_irq(&phba
->hbalock
);
4018 list_for_each_entry_safe(piocb
, tmp_iocb
, &pring
->txq
, list
) {
4020 if (piocb
->iocb_flag
& LPFC_IO_LIBDFC
)
4022 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
4023 if (cmd
->ulpCommand
== CMD_QUE_RING_BUF_CN
||
4024 cmd
->ulpCommand
== CMD_QUE_RING_BUF64_CN
||
4025 cmd
->ulpCommand
== CMD_CLOSE_XRI_CN
||
4026 cmd
->ulpCommand
== CMD_ABORT_XRI_CN
)
4028 list_move_tail(&piocb
->list
, &completions
);
4031 list_for_each_entry_safe(piocb
, tmp_iocb
, &pring
->txcmplq
, list
) {
4032 if (piocb
->iocb_flag
& LPFC_IO_LIBDFC
)
4034 lpfc_sli_issue_abort_iotag(phba
, pring
, piocb
);
4036 spin_unlock_irq(&phba
->hbalock
);
4037 while (!list_empty(&completions
)) {
4038 piocb
= list_get_first(&completions
, struct lpfc_iocbq
, list
);
4040 list_del_init(&piocb
->list
);
4041 if (!piocb
->iocb_cmpl
)
4042 lpfc_sli_release_iocbq(phba
, piocb
);
4044 cmd
->ulpStatus
= IOSTAT_LOCAL_REJECT
;
4045 cmd
->un
.ulpWord
[4] = IOERR_SLI_ABORTED
;
4046 (piocb
->iocb_cmpl
) (phba
, piocb
, piocb
);
4053 lpfc_els_unsol_buffer(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
4054 struct lpfc_vport
*vport
, struct lpfc_iocbq
*elsiocb
)
4056 struct Scsi_Host
*shost
;
4057 struct lpfc_nodelist
*ndlp
;
4060 uint32_t cmd
, did
, newnode
, rjt_err
= 0;
4061 IOCB_t
*icmd
= &elsiocb
->iocb
;
4063 if (!vport
|| !(elsiocb
->context2
))
4067 payload
= ((struct lpfc_dmabuf
*)elsiocb
->context2
)->virt
;
4069 if ((phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) == 0)
4070 lpfc_post_buffer(phba
, pring
, 1, 1);
4072 did
= icmd
->un
.rcvels
.remoteID
;
4073 if (icmd
->ulpStatus
) {
4074 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
4075 "RCV Unsol ELS: status:x%x/x%x did:x%x",
4076 icmd
->ulpStatus
, icmd
->un
.ulpWord
[4], did
);
4080 /* Check to see if link went down during discovery */
4081 if (lpfc_els_chk_latt(vport
))
4084 /* Ignore traffic recevied during vport shutdown. */
4085 if (vport
->load_flag
& FC_UNLOADING
)
4088 ndlp
= lpfc_findnode_did(vport
, did
);
4090 /* Cannot find existing Fabric ndlp, so allocate a new one */
4091 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
4095 lpfc_nlp_init(vport
, ndlp
, did
);
4096 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
4098 if ((did
& Fabric_DID_MASK
) == Fabric_DID_MASK
)
4099 ndlp
->nlp_type
|= NLP_FABRIC
;
4101 if (!NLP_CHK_NODE_ACT(ndlp
)) {
4102 ndlp
= lpfc_enable_node(vport
, ndlp
,
4103 NLP_STE_UNUSED_NODE
);
4107 if (ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
) {
4108 /* This is simular to the new node path */
4109 ndlp
= lpfc_nlp_get(ndlp
);
4112 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
4117 phba
->fc_stat
.elsRcvFrame
++;
4118 if (elsiocb
->context1
)
4119 lpfc_nlp_put(elsiocb
->context1
);
4121 elsiocb
->context1
= lpfc_nlp_get(ndlp
);
4122 elsiocb
->vport
= vport
;
4124 if ((cmd
& ELS_CMD_MASK
) == ELS_CMD_RSCN
) {
4125 cmd
&= ELS_CMD_MASK
;
4127 /* ELS command <elsCmd> received from NPORT <did> */
4128 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
4129 "0112 ELS command x%x received from NPORT x%x "
4130 "Data: x%x\n", cmd
, did
, vport
->port_state
);
4133 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
4134 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
4135 did
, vport
->port_state
, ndlp
->nlp_flag
);
4137 phba
->fc_stat
.elsRcvPLOGI
++;
4138 ndlp
= lpfc_plogi_confirm_nport(phba
, payload
, ndlp
);
4140 if (vport
->port_state
< LPFC_DISC_AUTH
) {
4141 if (!(phba
->pport
->fc_flag
& FC_PT2PT
) ||
4142 (phba
->pport
->fc_flag
& FC_PT2PT_PLOGI
)) {
4143 rjt_err
= LSRJT_UNABLE_TPC
;
4146 /* We get here, and drop thru, if we are PT2PT with
4147 * another NPort and the other side has initiated
4148 * the PLOGI before responding to our FLOGI.
4152 shost
= lpfc_shost_from_vport(vport
);
4153 spin_lock_irq(shost
->host_lock
);
4154 ndlp
->nlp_flag
&= ~NLP_TARGET_REMOVE
;
4155 spin_unlock_irq(shost
->host_lock
);
4157 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
,
4162 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
4163 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
4164 did
, vport
->port_state
, ndlp
->nlp_flag
);
4166 phba
->fc_stat
.elsRcvFLOGI
++;
4167 lpfc_els_rcv_flogi(vport
, elsiocb
, ndlp
);
4172 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
4173 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
4174 did
, vport
->port_state
, ndlp
->nlp_flag
);
4176 phba
->fc_stat
.elsRcvLOGO
++;
4177 if (vport
->port_state
< LPFC_DISC_AUTH
) {
4178 rjt_err
= LSRJT_UNABLE_TPC
;
4181 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
, NLP_EVT_RCV_LOGO
);
4184 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
4185 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
4186 did
, vport
->port_state
, ndlp
->nlp_flag
);
4188 phba
->fc_stat
.elsRcvPRLO
++;
4189 if (vport
->port_state
< LPFC_DISC_AUTH
) {
4190 rjt_err
= LSRJT_UNABLE_TPC
;
4193 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
, NLP_EVT_RCV_PRLO
);
4196 phba
->fc_stat
.elsRcvRSCN
++;
4197 lpfc_els_rcv_rscn(vport
, elsiocb
, ndlp
);
4202 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
4203 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
4204 did
, vport
->port_state
, ndlp
->nlp_flag
);
4206 phba
->fc_stat
.elsRcvADISC
++;
4207 if (vport
->port_state
< LPFC_DISC_AUTH
) {
4208 rjt_err
= LSRJT_UNABLE_TPC
;
4211 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
,
4215 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
4216 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
4217 did
, vport
->port_state
, ndlp
->nlp_flag
);
4219 phba
->fc_stat
.elsRcvPDISC
++;
4220 if (vport
->port_state
< LPFC_DISC_AUTH
) {
4221 rjt_err
= LSRJT_UNABLE_TPC
;
4224 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
,
4228 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
4229 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
4230 did
, vport
->port_state
, ndlp
->nlp_flag
);
4232 phba
->fc_stat
.elsRcvFARPR
++;
4233 lpfc_els_rcv_farpr(vport
, elsiocb
, ndlp
);
4236 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
4237 "RCV FARP: did:x%x/ste:x%x flg:x%x",
4238 did
, vport
->port_state
, ndlp
->nlp_flag
);
4240 phba
->fc_stat
.elsRcvFARP
++;
4241 lpfc_els_rcv_farp(vport
, elsiocb
, ndlp
);
4244 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
4245 "RCV FAN: did:x%x/ste:x%x flg:x%x",
4246 did
, vport
->port_state
, ndlp
->nlp_flag
);
4248 phba
->fc_stat
.elsRcvFAN
++;
4249 lpfc_els_rcv_fan(vport
, elsiocb
, ndlp
);
4252 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
4253 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
4254 did
, vport
->port_state
, ndlp
->nlp_flag
);
4256 phba
->fc_stat
.elsRcvPRLI
++;
4257 if (vport
->port_state
< LPFC_DISC_AUTH
) {
4258 rjt_err
= LSRJT_UNABLE_TPC
;
4261 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
, NLP_EVT_RCV_PRLI
);
4264 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
4265 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
4266 did
, vport
->port_state
, ndlp
->nlp_flag
);
4268 phba
->fc_stat
.elsRcvLIRR
++;
4269 lpfc_els_rcv_lirr(vport
, elsiocb
, ndlp
);
4274 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
4275 "RCV RPS: did:x%x/ste:x%x flg:x%x",
4276 did
, vport
->port_state
, ndlp
->nlp_flag
);
4278 phba
->fc_stat
.elsRcvRPS
++;
4279 lpfc_els_rcv_rps(vport
, elsiocb
, ndlp
);
4284 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
4285 "RCV RPL: did:x%x/ste:x%x flg:x%x",
4286 did
, vport
->port_state
, ndlp
->nlp_flag
);
4288 phba
->fc_stat
.elsRcvRPL
++;
4289 lpfc_els_rcv_rpl(vport
, elsiocb
, ndlp
);
4294 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
4295 "RCV RNID: did:x%x/ste:x%x flg:x%x",
4296 did
, vport
->port_state
, ndlp
->nlp_flag
);
4298 phba
->fc_stat
.elsRcvRNID
++;
4299 lpfc_els_rcv_rnid(vport
, elsiocb
, ndlp
);
4304 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
4305 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
4306 cmd
, did
, vport
->port_state
);
4308 /* Unsupported ELS command, reject */
4309 rjt_err
= LSRJT_INVALID_CMD
;
4311 /* Unknown ELS command <elsCmd> received from NPORT <did> */
4312 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
4313 "0115 Unknown ELS command x%x "
4314 "received from NPORT x%x\n", cmd
, did
);
4320 /* check if need to LS_RJT received ELS cmd */
4322 memset(&stat
, 0, sizeof(stat
));
4323 stat
.un
.b
.lsRjtRsnCode
= rjt_err
;
4324 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_NOTHING_MORE
;
4325 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, elsiocb
, ndlp
,
4332 if (vport
&& !(vport
->load_flag
& FC_UNLOADING
))
4333 lpfc_printf_log(phba
, KERN_ERR
, LOG_ELS
,
4334 "(%d):0111 Dropping received ELS cmd "
4335 "Data: x%x x%x x%x\n",
4336 vport
->vpi
, icmd
->ulpStatus
,
4337 icmd
->un
.ulpWord
[4], icmd
->ulpTimeout
);
4338 phba
->fc_stat
.elsRcvDrop
++;
4341 static struct lpfc_vport
*
4342 lpfc_find_vport_by_vpid(struct lpfc_hba
*phba
, uint16_t vpi
)
4344 struct lpfc_vport
*vport
;
4345 unsigned long flags
;
4347 spin_lock_irqsave(&phba
->hbalock
, flags
);
4348 list_for_each_entry(vport
, &phba
->port_list
, listentry
) {
4349 if (vport
->vpi
== vpi
) {
4350 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
4354 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
4359 lpfc_els_unsol_event(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
4360 struct lpfc_iocbq
*elsiocb
)
4362 struct lpfc_vport
*vport
= phba
->pport
;
4363 IOCB_t
*icmd
= &elsiocb
->iocb
;
4365 struct lpfc_dmabuf
*bdeBuf1
= elsiocb
->context2
;
4366 struct lpfc_dmabuf
*bdeBuf2
= elsiocb
->context3
;
4368 elsiocb
->context2
= NULL
;
4369 elsiocb
->context3
= NULL
;
4371 if (icmd
->ulpStatus
== IOSTAT_NEED_BUFFER
) {
4372 lpfc_sli_hbqbuf_add_hbqs(phba
, LPFC_ELS_HBQ
);
4373 } else if (icmd
->ulpStatus
== IOSTAT_LOCAL_REJECT
&&
4374 (icmd
->un
.ulpWord
[4] & 0xff) == IOERR_RCV_BUFFER_WAITING
) {
4375 phba
->fc_stat
.NoRcvBuf
++;
4376 /* Not enough posted buffers; Try posting more buffers */
4377 if (!(phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
))
4378 lpfc_post_buffer(phba
, pring
, 0, 1);
4382 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
4383 (icmd
->ulpCommand
== CMD_IOCB_RCV_ELS64_CX
||
4384 icmd
->ulpCommand
== CMD_IOCB_RCV_SEQ64_CX
)) {
4385 if (icmd
->unsli3
.rcvsli3
.vpi
== 0xffff)
4386 vport
= phba
->pport
;
4388 uint16_t vpi
= icmd
->unsli3
.rcvsli3
.vpi
;
4389 vport
= lpfc_find_vport_by_vpid(phba
, vpi
);
4392 /* If there are no BDEs associated
4393 * with this IOCB, there is nothing to do.
4395 if (icmd
->ulpBdeCount
== 0)
4398 /* type of ELS cmd is first 32bit word
4401 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) {
4402 elsiocb
->context2
= bdeBuf1
;
4404 paddr
= getPaddr(icmd
->un
.cont64
[0].addrHigh
,
4405 icmd
->un
.cont64
[0].addrLow
);
4406 elsiocb
->context2
= lpfc_sli_ringpostbuf_get(phba
, pring
,
4410 lpfc_els_unsol_buffer(phba
, pring
, vport
, elsiocb
);
4412 * The different unsolicited event handlers would tell us
4413 * if they are done with "mp" by setting context2 to NULL.
4415 lpfc_nlp_put(elsiocb
->context1
);
4416 elsiocb
->context1
= NULL
;
4417 if (elsiocb
->context2
) {
4418 lpfc_in_buf_free(phba
, (struct lpfc_dmabuf
*)elsiocb
->context2
);
4419 elsiocb
->context2
= NULL
;
4422 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
4423 if ((phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) &&
4424 icmd
->ulpBdeCount
== 2) {
4425 elsiocb
->context2
= bdeBuf2
;
4426 lpfc_els_unsol_buffer(phba
, pring
, vport
, elsiocb
);
4427 /* free mp if we are done with it */
4428 if (elsiocb
->context2
) {
4429 lpfc_in_buf_free(phba
, elsiocb
->context2
);
4430 elsiocb
->context2
= NULL
;
4436 lpfc_do_scr_ns_plogi(struct lpfc_hba
*phba
, struct lpfc_vport
*vport
)
4438 struct lpfc_nodelist
*ndlp
, *ndlp_fdmi
;
4440 ndlp
= lpfc_findnode_did(vport
, NameServer_DID
);
4442 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
4444 if (phba
->fc_topology
== TOPOLOGY_LOOP
) {
4445 lpfc_disc_start(vport
);
4448 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
4449 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
4450 "0251 NameServer login: no memory\n");
4453 lpfc_nlp_init(vport
, ndlp
, NameServer_DID
);
4454 ndlp
->nlp_type
|= NLP_FABRIC
;
4455 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
4456 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
4458 if (phba
->fc_topology
== TOPOLOGY_LOOP
) {
4459 lpfc_disc_start(vport
);
4462 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
4463 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
4464 "0348 NameServer login: node freed\n");
4469 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
4471 if (lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0)) {
4472 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
4473 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
4474 "0252 Cannot issue NameServer login\n");
4478 if (vport
->cfg_fdmi_on
) {
4479 ndlp_fdmi
= mempool_alloc(phba
->nlp_mem_pool
,
4482 lpfc_nlp_init(vport
, ndlp_fdmi
, FDMI_DID
);
4483 ndlp_fdmi
->nlp_type
|= NLP_FABRIC
;
4484 ndlp_fdmi
->nlp_state
=
4485 NLP_STE_PLOGI_ISSUE
;
4486 lpfc_issue_els_plogi(vport
, ndlp_fdmi
->nlp_DID
,
4494 lpfc_cmpl_reg_new_vport(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
4496 struct lpfc_vport
*vport
= pmb
->vport
;
4497 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4498 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
4499 MAILBOX_t
*mb
= &pmb
->mb
;
4501 spin_lock_irq(shost
->host_lock
);
4502 vport
->fc_flag
&= ~FC_VPORT_NEEDS_REG_VPI
;
4503 spin_unlock_irq(shost
->host_lock
);
4505 if (mb
->mbxStatus
) {
4506 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
4507 "0915 Register VPI failed: 0x%x\n",
4510 switch (mb
->mbxStatus
) {
4511 case 0x11: /* unsupported feature */
4512 case 0x9603: /* max_vpi exceeded */
4513 case 0x9602: /* Link event since CLEAR_LA */
4514 /* giving up on vport registration */
4515 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
4516 spin_lock_irq(shost
->host_lock
);
4517 vport
->fc_flag
&= ~(FC_FABRIC
| FC_PUBLIC_LOOP
);
4518 spin_unlock_irq(shost
->host_lock
);
4519 lpfc_can_disctmo(vport
);
4522 /* Try to recover from this error */
4523 lpfc_mbx_unreg_vpi(vport
);
4524 spin_lock_irq(shost
->host_lock
);
4525 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
4526 spin_unlock_irq(shost
->host_lock
);
4527 if (vport
->port_type
== LPFC_PHYSICAL_PORT
)
4528 lpfc_initial_flogi(vport
);
4530 lpfc_initial_fdisc(vport
);
4535 if (vport
== phba
->pport
)
4536 lpfc_issue_fabric_reglogin(vport
);
4538 lpfc_do_scr_ns_plogi(phba
, vport
);
4541 /* Now, we decrement the ndlp reference count held for this
4546 mempool_free(pmb
, phba
->mbox_mem_pool
);
4551 lpfc_register_new_vport(struct lpfc_hba
*phba
, struct lpfc_vport
*vport
,
4552 struct lpfc_nodelist
*ndlp
)
4554 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4557 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4559 lpfc_reg_vpi(phba
, vport
->vpi
, vport
->fc_myDID
, mbox
);
4560 mbox
->vport
= vport
;
4561 mbox
->context2
= lpfc_nlp_get(ndlp
);
4562 mbox
->mbox_cmpl
= lpfc_cmpl_reg_new_vport
;
4563 if (lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
)
4564 == MBX_NOT_FINISHED
) {
4565 /* mailbox command not success, decrement ndlp
4566 * reference count for this command
4569 mempool_free(mbox
, phba
->mbox_mem_pool
);
4571 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
4572 "0253 Register VPI: Can't send mbox\n");
4576 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
4577 "0254 Register VPI: no memory\n");
4583 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
4584 spin_lock_irq(shost
->host_lock
);
4585 vport
->fc_flag
&= ~FC_VPORT_NEEDS_REG_VPI
;
4586 spin_unlock_irq(shost
->host_lock
);
4591 lpfc_cmpl_els_fdisc(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
4592 struct lpfc_iocbq
*rspiocb
)
4594 struct lpfc_vport
*vport
= cmdiocb
->vport
;
4595 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4596 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
4597 struct lpfc_nodelist
*np
;
4598 struct lpfc_nodelist
*next_np
;
4599 IOCB_t
*irsp
= &rspiocb
->iocb
;
4600 struct lpfc_iocbq
*piocb
;
4602 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
4603 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
4604 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
4606 /* Since all FDISCs are being single threaded, we
4607 * must reset the discovery timer for ALL vports
4608 * waiting to send FDISC when one completes.
4610 list_for_each_entry(piocb
, &phba
->fabric_iocb_list
, list
) {
4611 lpfc_set_disctmo(piocb
->vport
);
4614 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
4615 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
4616 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4], vport
->fc_prevDID
);
4618 if (irsp
->ulpStatus
) {
4619 /* Check for retry */
4620 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
))
4623 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
4624 "0124 FDISC failed. (%d/%d)\n",
4625 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4]);
4626 if (vport
->fc_vport
->vport_state
== FC_VPORT_INITIALIZING
)
4627 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
4629 /* giving up on FDISC. Cancel discovery timer */
4630 lpfc_can_disctmo(vport
);
4632 spin_lock_irq(shost
->host_lock
);
4633 vport
->fc_flag
|= FC_FABRIC
;
4634 if (vport
->phba
->fc_topology
== TOPOLOGY_LOOP
)
4635 vport
->fc_flag
|= FC_PUBLIC_LOOP
;
4636 spin_unlock_irq(shost
->host_lock
);
4638 vport
->fc_myDID
= irsp
->un
.ulpWord
[4] & Mask_DID
;
4639 lpfc_vport_set_state(vport
, FC_VPORT_ACTIVE
);
4640 if ((vport
->fc_prevDID
!= vport
->fc_myDID
) &&
4641 !(vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
)) {
4642 /* If our NportID changed, we need to ensure all
4643 * remaining NPORTs get unreg_login'ed so we can
4646 list_for_each_entry_safe(np
, next_np
,
4647 &vport
->fc_nodes
, nlp_listp
) {
4648 if (!NLP_CHK_NODE_ACT(ndlp
) ||
4649 (np
->nlp_state
!= NLP_STE_NPR_NODE
) ||
4650 !(np
->nlp_flag
& NLP_NPR_ADISC
))
4652 spin_lock_irq(shost
->host_lock
);
4653 np
->nlp_flag
&= ~NLP_NPR_ADISC
;
4654 spin_unlock_irq(shost
->host_lock
);
4655 lpfc_unreg_rpi(vport
, np
);
4657 lpfc_mbx_unreg_vpi(vport
);
4658 spin_lock_irq(shost
->host_lock
);
4659 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
4660 spin_unlock_irq(shost
->host_lock
);
4663 if (vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
)
4664 lpfc_register_new_vport(phba
, vport
, ndlp
);
4666 lpfc_do_scr_ns_plogi(phba
, vport
);
4668 /* Unconditionaly kick off releasing fabric node for vports */
4673 lpfc_els_free_iocb(phba
, cmdiocb
);
4677 lpfc_issue_els_fdisc(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
4680 struct lpfc_hba
*phba
= vport
->phba
;
4682 struct lpfc_iocbq
*elsiocb
;
4683 struct serv_parm
*sp
;
4686 int did
= ndlp
->nlp_DID
;
4689 cmdsize
= (sizeof(uint32_t) + sizeof(struct serv_parm
));
4690 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
, did
,
4693 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
4694 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
4695 "0255 Issue FDISC: no IOCB\n");
4699 icmd
= &elsiocb
->iocb
;
4700 icmd
->un
.elsreq64
.myID
= 0;
4701 icmd
->un
.elsreq64
.fl
= 1;
4703 /* For FDISC, Let FDISC rsp set the NPortID for this VPI */
4707 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
4708 *((uint32_t *) (pcmd
)) = ELS_CMD_FDISC
;
4709 pcmd
+= sizeof(uint32_t); /* CSP Word 1 */
4710 memcpy(pcmd
, &vport
->phba
->pport
->fc_sparam
, sizeof(struct serv_parm
));
4711 sp
= (struct serv_parm
*) pcmd
;
4712 /* Setup CSPs accordingly for Fabric */
4713 sp
->cmn
.e_d_tov
= 0;
4714 sp
->cmn
.w2
.r_a_tov
= 0;
4715 sp
->cls1
.classValid
= 0;
4716 sp
->cls2
.seqDelivery
= 1;
4717 sp
->cls3
.seqDelivery
= 1;
4719 pcmd
+= sizeof(uint32_t); /* CSP Word 2 */
4720 pcmd
+= sizeof(uint32_t); /* CSP Word 3 */
4721 pcmd
+= sizeof(uint32_t); /* CSP Word 4 */
4722 pcmd
+= sizeof(uint32_t); /* Port Name */
4723 memcpy(pcmd
, &vport
->fc_portname
, 8);
4724 pcmd
+= sizeof(uint32_t); /* Node Name */
4725 pcmd
+= sizeof(uint32_t); /* Node Name */
4726 memcpy(pcmd
, &vport
->fc_nodename
, 8);
4728 lpfc_set_disctmo(vport
);
4730 phba
->fc_stat
.elsXmitFDISC
++;
4731 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_fdisc
;
4733 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
4734 "Issue FDISC: did:x%x",
4737 rc
= lpfc_issue_fabric_iocb(phba
, elsiocb
);
4738 if (rc
== IOCB_ERROR
) {
4739 lpfc_els_free_iocb(phba
, elsiocb
);
4740 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
4741 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
4742 "0256 Issue FDISC: Cannot send IOCB\n");
4745 lpfc_vport_set_state(vport
, FC_VPORT_INITIALIZING
);
4746 vport
->port_state
= LPFC_FDISC
;
4751 lpfc_cmpl_els_npiv_logo(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
4752 struct lpfc_iocbq
*rspiocb
)
4754 struct lpfc_vport
*vport
= cmdiocb
->vport
;
4756 struct lpfc_nodelist
*ndlp
;
4757 ndlp
= (struct lpfc_nodelist
*)cmdiocb
->context1
;
4759 irsp
= &rspiocb
->iocb
;
4760 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
4761 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
4762 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4], irsp
->un
.rcvels
.remoteID
);
4764 lpfc_els_free_iocb(phba
, cmdiocb
);
4765 vport
->unreg_vpi_cmpl
= VPORT_ERROR
;
4767 /* Trigger the release of the ndlp after logo */
4772 lpfc_issue_els_npiv_logo(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
4774 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4775 struct lpfc_hba
*phba
= vport
->phba
;
4776 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
4778 struct lpfc_iocbq
*elsiocb
;
4782 cmdsize
= 2 * sizeof(uint32_t) + sizeof(struct lpfc_name
);
4783 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, 0, ndlp
, ndlp
->nlp_DID
,
4788 icmd
= &elsiocb
->iocb
;
4789 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
4790 *((uint32_t *) (pcmd
)) = ELS_CMD_LOGO
;
4791 pcmd
+= sizeof(uint32_t);
4793 /* Fill in LOGO payload */
4794 *((uint32_t *) (pcmd
)) = be32_to_cpu(vport
->fc_myDID
);
4795 pcmd
+= sizeof(uint32_t);
4796 memcpy(pcmd
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
4798 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
4799 "Issue LOGO npiv did:x%x flg:x%x",
4800 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
4802 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_npiv_logo
;
4803 spin_lock_irq(shost
->host_lock
);
4804 ndlp
->nlp_flag
|= NLP_LOGO_SND
;
4805 spin_unlock_irq(shost
->host_lock
);
4806 if (lpfc_sli_issue_iocb(phba
, pring
, elsiocb
, 0) == IOCB_ERROR
) {
4807 spin_lock_irq(shost
->host_lock
);
4808 ndlp
->nlp_flag
&= ~NLP_LOGO_SND
;
4809 spin_unlock_irq(shost
->host_lock
);
4810 lpfc_els_free_iocb(phba
, elsiocb
);
4817 lpfc_fabric_block_timeout(unsigned long ptr
)
4819 struct lpfc_hba
*phba
= (struct lpfc_hba
*) ptr
;
4820 unsigned long iflags
;
4821 uint32_t tmo_posted
;
4822 spin_lock_irqsave(&phba
->pport
->work_port_lock
, iflags
);
4823 tmo_posted
= phba
->pport
->work_port_events
& WORKER_FABRIC_BLOCK_TMO
;
4825 phba
->pport
->work_port_events
|= WORKER_FABRIC_BLOCK_TMO
;
4826 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, iflags
);
4829 spin_lock_irqsave(&phba
->hbalock
, iflags
);
4830 if (phba
->work_wait
)
4831 lpfc_worker_wake_up(phba
);
4832 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
4837 lpfc_resume_fabric_iocbs(struct lpfc_hba
*phba
)
4839 struct lpfc_iocbq
*iocb
;
4840 unsigned long iflags
;
4842 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
4847 spin_lock_irqsave(&phba
->hbalock
, iflags
);
4848 /* Post any pending iocb to the SLI layer */
4849 if (atomic_read(&phba
->fabric_iocb_count
) == 0) {
4850 list_remove_head(&phba
->fabric_iocb_list
, iocb
, typeof(*iocb
),
4853 /* Increment fabric iocb count to hold the position */
4854 atomic_inc(&phba
->fabric_iocb_count
);
4856 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
4858 iocb
->fabric_iocb_cmpl
= iocb
->iocb_cmpl
;
4859 iocb
->iocb_cmpl
= lpfc_cmpl_fabric_iocb
;
4860 iocb
->iocb_flag
|= LPFC_IO_FABRIC
;
4862 lpfc_debugfs_disc_trc(iocb
->vport
, LPFC_DISC_TRC_ELS_CMD
,
4863 "Fabric sched1: ste:x%x",
4864 iocb
->vport
->port_state
, 0, 0);
4866 ret
= lpfc_sli_issue_iocb(phba
, pring
, iocb
, 0);
4868 if (ret
== IOCB_ERROR
) {
4869 iocb
->iocb_cmpl
= iocb
->fabric_iocb_cmpl
;
4870 iocb
->fabric_iocb_cmpl
= NULL
;
4871 iocb
->iocb_flag
&= ~LPFC_IO_FABRIC
;
4873 cmd
->ulpStatus
= IOSTAT_LOCAL_REJECT
;
4874 cmd
->un
.ulpWord
[4] = IOERR_SLI_ABORTED
;
4875 iocb
->iocb_cmpl(phba
, iocb
, iocb
);
4877 atomic_dec(&phba
->fabric_iocb_count
);
4886 lpfc_unblock_fabric_iocbs(struct lpfc_hba
*phba
)
4888 clear_bit(FABRIC_COMANDS_BLOCKED
, &phba
->bit_flags
);
4890 lpfc_resume_fabric_iocbs(phba
);
4895 lpfc_block_fabric_iocbs(struct lpfc_hba
*phba
)
4899 blocked
= test_and_set_bit(FABRIC_COMANDS_BLOCKED
, &phba
->bit_flags
);
4900 /* Start a timer to unblock fabric iocbs after 100ms */
4902 mod_timer(&phba
->fabric_block_timer
, jiffies
+ HZ
/10 );
4908 lpfc_cmpl_fabric_iocb(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
4909 struct lpfc_iocbq
*rspiocb
)
4913 if ((cmdiocb
->iocb_flag
& LPFC_IO_FABRIC
) != LPFC_IO_FABRIC
)
4916 switch (rspiocb
->iocb
.ulpStatus
) {
4917 case IOSTAT_NPORT_RJT
:
4918 case IOSTAT_FABRIC_RJT
:
4919 if (rspiocb
->iocb
.un
.ulpWord
[4] & RJT_UNAVAIL_TEMP
) {
4920 lpfc_block_fabric_iocbs(phba
);
4924 case IOSTAT_NPORT_BSY
:
4925 case IOSTAT_FABRIC_BSY
:
4926 lpfc_block_fabric_iocbs(phba
);
4930 stat
.un
.lsRjtError
=
4931 be32_to_cpu(rspiocb
->iocb
.un
.ulpWord
[4]);
4932 if ((stat
.un
.b
.lsRjtRsnCode
== LSRJT_UNABLE_TPC
) ||
4933 (stat
.un
.b
.lsRjtRsnCode
== LSRJT_LOGICAL_BSY
))
4934 lpfc_block_fabric_iocbs(phba
);
4938 if (atomic_read(&phba
->fabric_iocb_count
) == 0)
4941 cmdiocb
->iocb_cmpl
= cmdiocb
->fabric_iocb_cmpl
;
4942 cmdiocb
->fabric_iocb_cmpl
= NULL
;
4943 cmdiocb
->iocb_flag
&= ~LPFC_IO_FABRIC
;
4944 cmdiocb
->iocb_cmpl(phba
, cmdiocb
, rspiocb
);
4946 atomic_dec(&phba
->fabric_iocb_count
);
4947 if (!test_bit(FABRIC_COMANDS_BLOCKED
, &phba
->bit_flags
)) {
4948 /* Post any pending iocbs to HBA */
4949 lpfc_resume_fabric_iocbs(phba
);
4954 lpfc_issue_fabric_iocb(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocb
)
4956 unsigned long iflags
;
4957 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
4961 if (atomic_read(&phba
->fabric_iocb_count
) > 1)
4964 spin_lock_irqsave(&phba
->hbalock
, iflags
);
4965 ready
= atomic_read(&phba
->fabric_iocb_count
) == 0 &&
4966 !test_bit(FABRIC_COMANDS_BLOCKED
, &phba
->bit_flags
);
4969 /* Increment fabric iocb count to hold the position */
4970 atomic_inc(&phba
->fabric_iocb_count
);
4971 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
4973 iocb
->fabric_iocb_cmpl
= iocb
->iocb_cmpl
;
4974 iocb
->iocb_cmpl
= lpfc_cmpl_fabric_iocb
;
4975 iocb
->iocb_flag
|= LPFC_IO_FABRIC
;
4977 lpfc_debugfs_disc_trc(iocb
->vport
, LPFC_DISC_TRC_ELS_CMD
,
4978 "Fabric sched2: ste:x%x",
4979 iocb
->vport
->port_state
, 0, 0);
4981 ret
= lpfc_sli_issue_iocb(phba
, pring
, iocb
, 0);
4983 if (ret
== IOCB_ERROR
) {
4984 iocb
->iocb_cmpl
= iocb
->fabric_iocb_cmpl
;
4985 iocb
->fabric_iocb_cmpl
= NULL
;
4986 iocb
->iocb_flag
&= ~LPFC_IO_FABRIC
;
4987 atomic_dec(&phba
->fabric_iocb_count
);
4990 spin_lock_irqsave(&phba
->hbalock
, iflags
);
4991 list_add_tail(&iocb
->list
, &phba
->fabric_iocb_list
);
4992 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
4999 static void lpfc_fabric_abort_vport(struct lpfc_vport
*vport
)
5001 LIST_HEAD(completions
);
5002 struct lpfc_hba
*phba
= vport
->phba
;
5003 struct lpfc_iocbq
*tmp_iocb
, *piocb
;
5006 spin_lock_irq(&phba
->hbalock
);
5007 list_for_each_entry_safe(piocb
, tmp_iocb
, &phba
->fabric_iocb_list
,
5010 if (piocb
->vport
!= vport
)
5013 list_move_tail(&piocb
->list
, &completions
);
5015 spin_unlock_irq(&phba
->hbalock
);
5017 while (!list_empty(&completions
)) {
5018 piocb
= list_get_first(&completions
, struct lpfc_iocbq
, list
);
5019 list_del_init(&piocb
->list
);
5022 cmd
->ulpStatus
= IOSTAT_LOCAL_REJECT
;
5023 cmd
->un
.ulpWord
[4] = IOERR_SLI_ABORTED
;
5024 (piocb
->iocb_cmpl
) (phba
, piocb
, piocb
);
5028 void lpfc_fabric_abort_nport(struct lpfc_nodelist
*ndlp
)
5030 LIST_HEAD(completions
);
5031 struct lpfc_hba
*phba
= ndlp
->vport
->phba
;
5032 struct lpfc_iocbq
*tmp_iocb
, *piocb
;
5033 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
5036 spin_lock_irq(&phba
->hbalock
);
5037 list_for_each_entry_safe(piocb
, tmp_iocb
, &phba
->fabric_iocb_list
,
5039 if ((lpfc_check_sli_ndlp(phba
, pring
, piocb
, ndlp
))) {
5041 list_move_tail(&piocb
->list
, &completions
);
5044 spin_unlock_irq(&phba
->hbalock
);
5046 while (!list_empty(&completions
)) {
5047 piocb
= list_get_first(&completions
, struct lpfc_iocbq
, list
);
5048 list_del_init(&piocb
->list
);
5051 cmd
->ulpStatus
= IOSTAT_LOCAL_REJECT
;
5052 cmd
->un
.ulpWord
[4] = IOERR_SLI_ABORTED
;
5053 (piocb
->iocb_cmpl
) (phba
, piocb
, piocb
);
5057 void lpfc_fabric_abort_hba(struct lpfc_hba
*phba
)
5059 LIST_HEAD(completions
);
5060 struct lpfc_iocbq
*piocb
;
5063 spin_lock_irq(&phba
->hbalock
);
5064 list_splice_init(&phba
->fabric_iocb_list
, &completions
);
5065 spin_unlock_irq(&phba
->hbalock
);
5067 while (!list_empty(&completions
)) {
5068 piocb
= list_get_first(&completions
, struct lpfc_iocbq
, list
);
5069 list_del_init(&piocb
->list
);
5072 cmd
->ulpStatus
= IOSTAT_LOCAL_REJECT
;
5073 cmd
->un
.ulpWord
[4] = IOERR_SLI_ABORTED
;
5074 (piocb
->iocb_cmpl
) (phba
, piocb
, piocb
);
5080 void lpfc_fabric_abort_flogi(struct lpfc_hba
*phba
)
5082 LIST_HEAD(completions
);
5083 struct lpfc_iocbq
*tmp_iocb
, *piocb
;
5085 struct lpfc_nodelist
*ndlp
;
5087 spin_lock_irq(&phba
->hbalock
);
5088 list_for_each_entry_safe(piocb
, tmp_iocb
, &phba
->fabric_iocb_list
,
5092 ndlp
= (struct lpfc_nodelist
*) piocb
->context1
;
5093 if (cmd
->ulpCommand
== CMD_ELS_REQUEST64_CR
&&
5095 ndlp
->nlp_DID
== Fabric_DID
)
5096 list_move_tail(&piocb
->list
, &completions
);
5098 spin_unlock_irq(&phba
->hbalock
);
5100 while (!list_empty(&completions
)) {
5101 piocb
= list_get_first(&completions
, struct lpfc_iocbq
, list
);
5102 list_del_init(&piocb
->list
);
5105 cmd
->ulpStatus
= IOSTAT_LOCAL_REJECT
;
5106 cmd
->un
.ulpWord
[4] = IOERR_SLI_ABORTED
;
5107 (piocb
->iocb_cmpl
) (phba
, piocb
, piocb
);