1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2007 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. *
7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
9 * This program is free software; you can redistribute it and/or *
10 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
20 *******************************************************************/
22 #include <linux/blkdev.h>
23 #include <linux/pci.h>
24 #include <linux/interrupt.h>
26 #include <scsi/scsi.h>
27 #include <scsi/scsi_device.h>
28 #include <scsi/scsi_host.h>
29 #include <scsi/scsi_transport_fc.h>
33 #include "lpfc_disc.h"
34 #include "lpfc_scsi.h"
36 #include "lpfc_logmsg.h"
37 #include "lpfc_crtn.h"
38 #include "lpfc_vport.h"
39 #include "lpfc_debugfs.h"
41 static int lpfc_els_retry(struct lpfc_hba
*, struct lpfc_iocbq
*,
43 static void lpfc_cmpl_fabric_iocb(struct lpfc_hba
*, struct lpfc_iocbq
*,
46 static int lpfc_max_els_tries
= 3;
49 lpfc_els_chk_latt(struct lpfc_vport
*vport
)
51 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
52 struct lpfc_hba
*phba
= vport
->phba
;
55 if (vport
->port_state
>= LPFC_VPORT_READY
||
56 phba
->link_state
== LPFC_LINK_DOWN
)
59 /* Read the HBA Host Attention Register */
60 ha_copy
= readl(phba
->HAregaddr
);
62 if (!(ha_copy
& HA_LATT
))
65 /* Pending Link Event during Discovery */
66 lpfc_printf_log(phba
, KERN_ERR
, LOG_DISCOVERY
,
67 "%d (%d):0237 Pending Link Event during "
68 "Discovery: State x%x\n",
69 phba
->brd_no
, vport
->vpi
, phba
->pport
->port_state
);
71 /* CLEAR_LA should re-enable link attention events and
72 * we should then imediately take a LATT event. The
73 * LATT processing should call lpfc_linkdown() which
74 * will cleanup any left over in-progress discovery
77 spin_lock_irq(shost
->host_lock
);
78 vport
->fc_flag
|= FC_ABORT_DISCOVERY
;
79 spin_unlock_irq(shost
->host_lock
);
81 if (phba
->link_state
!= LPFC_CLEAR_LA
)
82 lpfc_issue_clear_la(phba
, vport
);
87 static struct lpfc_iocbq
*
88 lpfc_prep_els_iocb(struct lpfc_vport
*vport
, uint8_t expectRsp
,
89 uint16_t cmdSize
, uint8_t retry
,
90 struct lpfc_nodelist
*ndlp
, uint32_t did
,
93 struct lpfc_hba
*phba
= vport
->phba
;
94 struct lpfc_iocbq
*elsiocb
;
95 struct lpfc_dmabuf
*pcmd
, *prsp
, *pbuflist
;
96 struct ulp_bde64
*bpl
;
100 if (!lpfc_is_link_up(phba
))
103 /* Allocate buffer for command iocb */
104 elsiocb
= lpfc_sli_get_iocbq(phba
);
108 icmd
= &elsiocb
->iocb
;
110 /* fill in BDEs for command */
111 /* Allocate buffer for command payload */
112 if (((pcmd
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
)) == 0) ||
113 ((pcmd
->virt
= lpfc_mbuf_alloc(phba
,
114 MEM_PRI
, &(pcmd
->phys
))) == 0)) {
117 lpfc_sli_release_iocbq(phba
, elsiocb
);
121 INIT_LIST_HEAD(&pcmd
->list
);
123 /* Allocate buffer for response payload */
125 prsp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
127 prsp
->virt
= lpfc_mbuf_alloc(phba
, MEM_PRI
,
129 if (prsp
== 0 || prsp
->virt
== 0) {
131 lpfc_mbuf_free(phba
, pcmd
->virt
, pcmd
->phys
);
133 lpfc_sli_release_iocbq(phba
, elsiocb
);
136 INIT_LIST_HEAD(&prsp
->list
);
141 /* Allocate buffer for Buffer ptr list */
142 pbuflist
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
144 pbuflist
->virt
= lpfc_mbuf_alloc(phba
, MEM_PRI
,
146 if (pbuflist
== 0 || pbuflist
->virt
== 0) {
147 lpfc_sli_release_iocbq(phba
, elsiocb
);
148 lpfc_mbuf_free(phba
, pcmd
->virt
, pcmd
->phys
);
149 lpfc_mbuf_free(phba
, prsp
->virt
, prsp
->phys
);
156 INIT_LIST_HEAD(&pbuflist
->list
);
158 icmd
->un
.elsreq64
.bdl
.addrHigh
= putPaddrHigh(pbuflist
->phys
);
159 icmd
->un
.elsreq64
.bdl
.addrLow
= putPaddrLow(pbuflist
->phys
);
160 icmd
->un
.elsreq64
.bdl
.bdeFlags
= BUFF_TYPE_BDL
;
161 icmd
->un
.elsreq64
.remoteID
= did
; /* DID */
163 icmd
->un
.elsreq64
.bdl
.bdeSize
= (2 * sizeof(struct ulp_bde64
));
164 icmd
->ulpCommand
= CMD_ELS_REQUEST64_CR
;
165 icmd
->ulpTimeout
= phba
->fc_ratov
* 2;
167 icmd
->un
.elsreq64
.bdl
.bdeSize
= sizeof(struct ulp_bde64
);
168 icmd
->ulpCommand
= CMD_XMIT_ELS_RSP64_CX
;
170 icmd
->ulpBdeCount
= 1;
172 icmd
->ulpClass
= CLASS3
;
174 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) {
175 icmd
->un
.elsreq64
.myID
= vport
->fc_myDID
;
177 /* For ELS_REQUEST64_CR, use the VPI by default */
178 icmd
->ulpContext
= vport
->vpi
;
183 bpl
= (struct ulp_bde64
*) pbuflist
->virt
;
184 bpl
->addrLow
= le32_to_cpu(putPaddrLow(pcmd
->phys
));
185 bpl
->addrHigh
= le32_to_cpu(putPaddrHigh(pcmd
->phys
));
186 bpl
->tus
.f
.bdeSize
= cmdSize
;
187 bpl
->tus
.f
.bdeFlags
= 0;
188 bpl
->tus
.w
= le32_to_cpu(bpl
->tus
.w
);
192 bpl
->addrLow
= le32_to_cpu(putPaddrLow(prsp
->phys
));
193 bpl
->addrHigh
= le32_to_cpu(putPaddrHigh(prsp
->phys
));
194 bpl
->tus
.f
.bdeSize
= FCELSSIZE
;
195 bpl
->tus
.f
.bdeFlags
= BUFF_USE_RCV
;
196 bpl
->tus
.w
= le32_to_cpu(bpl
->tus
.w
);
199 /* Save for completion so we can release these resources */
200 if (elscmd
!= ELS_CMD_LS_RJT
)
201 elsiocb
->context1
= lpfc_nlp_get(ndlp
);
202 elsiocb
->context2
= pcmd
;
203 elsiocb
->context3
= pbuflist
;
204 elsiocb
->retry
= retry
;
205 elsiocb
->vport
= vport
;
206 elsiocb
->drvrTimeout
= (phba
->fc_ratov
<< 1) + LPFC_DRVR_TIMEOUT
;
209 list_add(&prsp
->list
, &pcmd
->list
);
213 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
214 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
215 "%d (%d):0116 Xmit ELS command x%x to remote "
216 "NPORT x%x I/O tag: x%x, port state: x%x\n",
217 phba
->brd_no
, vport
->vpi
, elscmd
, did
,
218 elsiocb
->iotag
, vport
->port_state
);
220 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
221 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
222 "%d (%d):0117 Xmit ELS response x%x to remote "
223 "NPORT x%x I/O tag: x%x, size: x%x\n",
224 phba
->brd_no
, vport
->vpi
, elscmd
,
225 ndlp
->nlp_DID
, elsiocb
->iotag
, cmdSize
);
233 lpfc_issue_fabric_reglogin(struct lpfc_vport
*vport
)
235 struct lpfc_hba
*phba
= vport
->phba
;
237 struct lpfc_dmabuf
*mp
;
238 struct lpfc_nodelist
*ndlp
;
239 struct serv_parm
*sp
;
242 sp
= &phba
->fc_fabparam
;
243 ndlp
= lpfc_findnode_did(vport
, Fabric_DID
);
247 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
251 vport
->port_state
= LPFC_FABRIC_CFG_LINK
;
252 lpfc_config_link(phba
, mbox
);
253 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
256 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
| MBX_STOP_IOCB
);
257 if (rc
== MBX_NOT_FINISHED
)
260 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
263 rc
= lpfc_reg_login(phba
, vport
->vpi
, Fabric_DID
, (uint8_t *)sp
, mbox
,
268 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_fabric_reg_login
;
270 mbox
->context2
= lpfc_nlp_get(ndlp
);
272 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
| MBX_STOP_IOCB
);
273 if (rc
== MBX_NOT_FINISHED
)
274 goto fail_issue_reg_login
;
278 fail_issue_reg_login
:
280 mp
= (struct lpfc_dmabuf
*) mbox
->context1
;
281 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
284 mempool_free(mbox
, phba
->mbox_mem_pool
);
287 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
288 lpfc_printf_log(phba
, KERN_ERR
, LOG_ELS
,
289 "%d (%d):0249 Cannot issue Register Fabric login\n",
290 phba
->brd_no
, vport
->vpi
);
295 lpfc_cmpl_els_flogi_fabric(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
296 struct serv_parm
*sp
, IOCB_t
*irsp
)
298 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
299 struct lpfc_hba
*phba
= vport
->phba
;
300 struct lpfc_nodelist
*np
;
301 struct lpfc_nodelist
*next_np
;
303 spin_lock_irq(shost
->host_lock
);
304 vport
->fc_flag
|= FC_FABRIC
;
305 spin_unlock_irq(shost
->host_lock
);
307 phba
->fc_edtov
= be32_to_cpu(sp
->cmn
.e_d_tov
);
308 if (sp
->cmn
.edtovResolution
) /* E_D_TOV ticks are in nanoseconds */
309 phba
->fc_edtov
= (phba
->fc_edtov
+ 999999) / 1000000;
311 phba
->fc_ratov
= (be32_to_cpu(sp
->cmn
.w2
.r_a_tov
) + 999) / 1000;
313 if (phba
->fc_topology
== TOPOLOGY_LOOP
) {
314 spin_lock_irq(shost
->host_lock
);
315 vport
->fc_flag
|= FC_PUBLIC_LOOP
;
316 spin_unlock_irq(shost
->host_lock
);
319 * If we are a N-port connected to a Fabric, fixup sparam's so
320 * logins to devices on remote loops work.
322 vport
->fc_sparam
.cmn
.altBbCredit
= 1;
325 vport
->fc_myDID
= irsp
->un
.ulpWord
[4] & Mask_DID
;
326 memcpy(&ndlp
->nlp_portname
, &sp
->portName
, sizeof(struct lpfc_name
));
327 memcpy(&ndlp
->nlp_nodename
, &sp
->nodeName
, sizeof(struct lpfc_name
));
328 ndlp
->nlp_class_sup
= 0;
329 if (sp
->cls1
.classValid
)
330 ndlp
->nlp_class_sup
|= FC_COS_CLASS1
;
331 if (sp
->cls2
.classValid
)
332 ndlp
->nlp_class_sup
|= FC_COS_CLASS2
;
333 if (sp
->cls3
.classValid
)
334 ndlp
->nlp_class_sup
|= FC_COS_CLASS3
;
335 if (sp
->cls4
.classValid
)
336 ndlp
->nlp_class_sup
|= FC_COS_CLASS4
;
337 ndlp
->nlp_maxframe
= ((sp
->cmn
.bbRcvSizeMsb
& 0x0F) << 8) |
338 sp
->cmn
.bbRcvSizeLsb
;
339 memcpy(&phba
->fc_fabparam
, sp
, sizeof(struct serv_parm
));
341 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) {
342 if (sp
->cmn
.response_multiple_NPort
) {
343 lpfc_printf_log(phba
, KERN_WARNING
, LOG_ELS
| LOG_VPORT
,
344 "%d:1816 FLOGI NPIV supported, "
345 "response data 0x%x\n",
347 sp
->cmn
.response_multiple_NPort
);
348 phba
->link_flag
|= LS_NPIV_FAB_SUPPORTED
;
351 /* Because we asked f/w for NPIV it still expects us
352 to call reg_vnpid atleast for the physcial host */
353 lpfc_printf_log(phba
, KERN_WARNING
, LOG_ELS
| LOG_VPORT
,
354 "%d:1817 Fabric does not support NPIV "
355 "- configuring single port mode.\n",
357 phba
->link_flag
&= ~LS_NPIV_FAB_SUPPORTED
;
361 if ((vport
->fc_prevDID
!= vport
->fc_myDID
) &&
362 !(vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
)) {
364 /* If our NportID changed, we need to ensure all
365 * remaining NPORTs get unreg_login'ed.
367 list_for_each_entry_safe(np
, next_np
,
368 &vport
->fc_nodes
, nlp_listp
) {
369 if ((np
->nlp_state
!= NLP_STE_NPR_NODE
) ||
370 !(np
->nlp_flag
& NLP_NPR_ADISC
))
372 spin_lock_irq(shost
->host_lock
);
373 np
->nlp_flag
&= ~NLP_NPR_ADISC
;
374 spin_unlock_irq(shost
->host_lock
);
375 lpfc_unreg_rpi(vport
, np
);
377 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) {
378 lpfc_mbx_unreg_vpi(vport
);
379 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
383 ndlp
->nlp_sid
= irsp
->un
.ulpWord
[4] & Mask_DID
;
384 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_REG_LOGIN_ISSUE
);
386 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
&&
387 vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
) {
388 lpfc_register_new_vport(phba
, vport
, ndlp
);
391 lpfc_issue_fabric_reglogin(vport
);
396 * We FLOGIed into an NPort, initiate pt2pt protocol
399 lpfc_cmpl_els_flogi_nport(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
400 struct serv_parm
*sp
)
402 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
403 struct lpfc_hba
*phba
= vport
->phba
;
407 spin_lock_irq(shost
->host_lock
);
408 vport
->fc_flag
&= ~(FC_FABRIC
| FC_PUBLIC_LOOP
);
409 spin_unlock_irq(shost
->host_lock
);
411 phba
->fc_edtov
= FF_DEF_EDTOV
;
412 phba
->fc_ratov
= FF_DEF_RATOV
;
413 rc
= memcmp(&vport
->fc_portname
, &sp
->portName
,
414 sizeof(vport
->fc_portname
));
416 /* This side will initiate the PLOGI */
417 spin_lock_irq(shost
->host_lock
);
418 vport
->fc_flag
|= FC_PT2PT_PLOGI
;
419 spin_unlock_irq(shost
->host_lock
);
422 * N_Port ID cannot be 0, set our to LocalID the other
423 * side will be RemoteID.
428 vport
->fc_myDID
= PT2PT_LocalID
;
430 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
434 lpfc_config_link(phba
, mbox
);
436 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
438 rc
= lpfc_sli_issue_mbox(phba
, mbox
,
439 MBX_NOWAIT
| MBX_STOP_IOCB
);
440 if (rc
== MBX_NOT_FINISHED
) {
441 mempool_free(mbox
, phba
->mbox_mem_pool
);
446 ndlp
= lpfc_findnode_did(vport
, PT2PT_RemoteID
);
449 * Cannot find existing Fabric ndlp, so allocate a
452 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
456 lpfc_nlp_init(vport
, ndlp
, PT2PT_RemoteID
);
459 memcpy(&ndlp
->nlp_portname
, &sp
->portName
,
460 sizeof(struct lpfc_name
));
461 memcpy(&ndlp
->nlp_nodename
, &sp
->nodeName
,
462 sizeof(struct lpfc_name
));
463 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
464 spin_lock_irq(shost
->host_lock
);
465 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
466 spin_unlock_irq(shost
->host_lock
);
468 /* This side will wait for the PLOGI */
472 spin_lock_irq(shost
->host_lock
);
473 vport
->fc_flag
|= FC_PT2PT
;
474 spin_unlock_irq(shost
->host_lock
);
476 /* Start discovery - this should just do CLEAR_LA */
477 lpfc_disc_start(vport
);
484 lpfc_cmpl_els_flogi(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
485 struct lpfc_iocbq
*rspiocb
)
487 struct lpfc_vport
*vport
= cmdiocb
->vport
;
488 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
489 IOCB_t
*irsp
= &rspiocb
->iocb
;
490 struct lpfc_nodelist
*ndlp
= cmdiocb
->context1
;
491 struct lpfc_dmabuf
*pcmd
= cmdiocb
->context2
, *prsp
;
492 struct serv_parm
*sp
;
495 /* Check to see if link went down during discovery */
496 if (lpfc_els_chk_latt(vport
)) {
501 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
502 "FLOGI cmpl: status:x%x/x%x state:x%x",
503 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
506 if (irsp
->ulpStatus
) {
507 /* Check for retry */
508 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
))
511 /* FLOGI failed, so there is no fabric */
512 spin_lock_irq(shost
->host_lock
);
513 vport
->fc_flag
&= ~(FC_FABRIC
| FC_PUBLIC_LOOP
);
514 spin_unlock_irq(shost
->host_lock
);
516 /* If private loop, then allow max outstanding els to be
517 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
518 * alpa map would take too long otherwise.
520 if (phba
->alpa_map
[0] == 0) {
521 phba
->cfg_discovery_threads
= LPFC_MAX_DISC_THREADS
;
525 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
526 "%d (%d):0100 FLOGI failure Data: x%x x%x "
528 phba
->brd_no
, vport
->vpi
,
529 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
535 * The FLogI succeeded. Sync the data for the CPU before
538 prsp
= list_get_first(&pcmd
->list
, struct lpfc_dmabuf
, list
);
540 sp
= prsp
->virt
+ sizeof(uint32_t);
542 /* FLOGI completes successfully */
543 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
544 "%d (%d):0101 FLOGI completes sucessfully "
545 "Data: x%x x%x x%x x%x\n",
546 phba
->brd_no
, vport
->vpi
,
547 irsp
->un
.ulpWord
[4], sp
->cmn
.e_d_tov
,
548 sp
->cmn
.w2
.r_a_tov
, sp
->cmn
.edtovResolution
);
550 if (vport
->port_state
== LPFC_FLOGI
) {
552 * If Common Service Parameters indicate Nport
553 * we are point to point, if Fport we are Fabric.
556 rc
= lpfc_cmpl_els_flogi_fabric(vport
, ndlp
, sp
, irsp
);
558 rc
= lpfc_cmpl_els_flogi_nport(vport
, ndlp
, sp
);
567 if (!lpfc_error_lost_link(irsp
)) {
568 /* FLOGI failed, so just use loop map to make discovery list */
569 lpfc_disc_list_loopmap(vport
);
571 /* Start discovery */
572 lpfc_disc_start(vport
);
576 lpfc_els_free_iocb(phba
, cmdiocb
);
580 lpfc_issue_els_flogi(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
583 struct lpfc_hba
*phba
= vport
->phba
;
584 struct serv_parm
*sp
;
586 struct lpfc_iocbq
*elsiocb
;
587 struct lpfc_sli_ring
*pring
;
593 pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
595 cmdsize
= (sizeof(uint32_t) + sizeof(struct serv_parm
));
596 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
597 ndlp
->nlp_DID
, ELS_CMD_FLOGI
);
602 icmd
= &elsiocb
->iocb
;
603 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
605 /* For FLOGI request, remainder of payload is service parameters */
606 *((uint32_t *) (pcmd
)) = ELS_CMD_FLOGI
;
607 pcmd
+= sizeof(uint32_t);
608 memcpy(pcmd
, &vport
->fc_sparam
, sizeof(struct serv_parm
));
609 sp
= (struct serv_parm
*) pcmd
;
611 /* Setup CSPs accordingly for Fabric */
613 sp
->cmn
.w2
.r_a_tov
= 0;
614 sp
->cls1
.classValid
= 0;
615 sp
->cls2
.seqDelivery
= 1;
616 sp
->cls3
.seqDelivery
= 1;
617 if (sp
->cmn
.fcphLow
< FC_PH3
)
618 sp
->cmn
.fcphLow
= FC_PH3
;
619 if (sp
->cmn
.fcphHigh
< FC_PH3
)
620 sp
->cmn
.fcphHigh
= FC_PH3
;
622 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) {
623 sp
->cmn
.request_multiple_Nport
= 1;
625 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
630 if (phba
->fc_topology
!= TOPOLOGY_LOOP
) {
631 icmd
->un
.elsreq64
.myID
= 0;
632 icmd
->un
.elsreq64
.fl
= 1;
635 tmo
= phba
->fc_ratov
;
636 phba
->fc_ratov
= LPFC_DISC_FLOGI_TMO
;
637 lpfc_set_disctmo(vport
);
638 phba
->fc_ratov
= tmo
;
640 phba
->fc_stat
.elsXmitFLOGI
++;
641 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_flogi
;
643 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
644 "Issue FLOGI: opt:x%x",
645 phba
->sli3_options
, 0, 0);
647 rc
= lpfc_issue_fabric_iocb(phba
, elsiocb
);
648 if (rc
== IOCB_ERROR
) {
649 lpfc_els_free_iocb(phba
, elsiocb
);
656 lpfc_els_abort_flogi(struct lpfc_hba
*phba
)
658 struct lpfc_sli_ring
*pring
;
659 struct lpfc_iocbq
*iocb
, *next_iocb
;
660 struct lpfc_nodelist
*ndlp
;
663 /* Abort outstanding I/O on NPort <nlp_DID> */
664 lpfc_printf_log(phba
, KERN_INFO
, LOG_DISCOVERY
,
665 "%d:0201 Abort outstanding I/O on NPort x%x\n",
666 phba
->brd_no
, Fabric_DID
);
668 pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
671 * Check the txcmplq for an iocb that matches the nport the driver is
674 spin_lock_irq(&phba
->hbalock
);
675 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
, list
) {
677 if (icmd
->ulpCommand
== CMD_ELS_REQUEST64_CR
&&
678 icmd
->un
.elsreq64
.bdl
.ulpIoTag32
) {
679 ndlp
= (struct lpfc_nodelist
*)(iocb
->context1
);
680 if (ndlp
&& (ndlp
->nlp_DID
== Fabric_DID
)) {
681 lpfc_sli_issue_abort_iotag(phba
, pring
, iocb
);
685 spin_unlock_irq(&phba
->hbalock
);
691 lpfc_initial_flogi(struct lpfc_vport
*vport
)
693 struct lpfc_hba
*phba
= vport
->phba
;
694 struct lpfc_nodelist
*ndlp
;
696 /* First look for the Fabric ndlp */
697 ndlp
= lpfc_findnode_did(vport
, Fabric_DID
);
699 /* Cannot find existing Fabric ndlp, so allocate a new one */
700 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
703 lpfc_nlp_init(vport
, ndlp
, Fabric_DID
);
705 lpfc_dequeue_node(vport
, ndlp
);
707 if (lpfc_issue_els_flogi(vport
, ndlp
, 0)) {
714 lpfc_initial_fdisc(struct lpfc_vport
*vport
)
716 struct lpfc_hba
*phba
= vport
->phba
;
717 struct lpfc_nodelist
*ndlp
;
719 /* First look for the Fabric ndlp */
720 ndlp
= lpfc_findnode_did(vport
, Fabric_DID
);
722 /* Cannot find existing Fabric ndlp, so allocate a new one */
723 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
726 lpfc_nlp_init(vport
, ndlp
, Fabric_DID
);
728 lpfc_dequeue_node(vport
, ndlp
);
730 if (lpfc_issue_els_fdisc(vport
, ndlp
, 0)) {
736 lpfc_more_plogi(struct lpfc_vport
*vport
)
739 struct lpfc_hba
*phba
= vport
->phba
;
741 if (vport
->num_disc_nodes
)
742 vport
->num_disc_nodes
--;
744 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
745 lpfc_printf_log(phba
, KERN_INFO
, LOG_DISCOVERY
,
746 "%d (%d):0232 Continue discovery with %d PLOGIs to go "
747 "Data: x%x x%x x%x\n",
748 phba
->brd_no
, vport
->vpi
, vport
->num_disc_nodes
,
749 vport
->fc_plogi_cnt
, vport
->fc_flag
, vport
->port_state
);
751 /* Check to see if there are more PLOGIs to be sent */
752 if (vport
->fc_flag
& FC_NLP_MORE
)
753 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
754 sentplogi
= lpfc_els_disc_plogi(vport
);
759 static struct lpfc_nodelist
*
760 lpfc_plogi_confirm_nport(struct lpfc_hba
*phba
, uint32_t *prsp
,
761 struct lpfc_nodelist
*ndlp
)
763 struct lpfc_vport
*vport
= ndlp
->vport
;
764 struct lpfc_nodelist
*new_ndlp
;
765 struct serv_parm
*sp
;
766 uint8_t name
[sizeof(struct lpfc_name
)];
769 /* Fabric nodes can have the same WWPN so we don't bother searching
770 * by WWPN. Just return the ndlp that was given to us.
772 if (ndlp
->nlp_type
& NLP_FABRIC
)
775 sp
= (struct serv_parm
*) ((uint8_t *) prsp
+ sizeof(uint32_t));
776 memset(name
, 0, sizeof(struct lpfc_name
));
778 /* Now we find out if the NPort we are logging into, matches the WWPN
779 * we have for that ndlp. If not, we have some work to do.
781 new_ndlp
= lpfc_findnode_wwpn(vport
, &sp
->portName
);
783 if (new_ndlp
== ndlp
)
787 rc
= memcmp(&ndlp
->nlp_portname
, name
,
788 sizeof(struct lpfc_name
));
791 new_ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_ATOMIC
);
795 lpfc_nlp_init(vport
, new_ndlp
, ndlp
->nlp_DID
);
798 lpfc_unreg_rpi(vport
, new_ndlp
);
799 new_ndlp
->nlp_DID
= ndlp
->nlp_DID
;
800 new_ndlp
->nlp_prev_state
= ndlp
->nlp_prev_state
;
801 lpfc_nlp_set_state(vport
, new_ndlp
, ndlp
->nlp_state
);
803 /* Move this back to NPR state */
804 if (memcmp(&ndlp
->nlp_portname
, name
, sizeof(struct lpfc_name
)) == 0)
805 lpfc_drop_node(vport
, ndlp
);
807 lpfc_unreg_rpi(vport
, ndlp
);
808 ndlp
->nlp_DID
= 0; /* Two ndlps cannot have the same did */
809 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
815 lpfc_cmpl_els_plogi(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
816 struct lpfc_iocbq
*rspiocb
)
818 struct lpfc_vport
*vport
= cmdiocb
->vport
;
819 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
821 struct lpfc_nodelist
*ndlp
;
822 struct lpfc_dmabuf
*prsp
;
823 int disc
, rc
, did
, type
;
825 /* we pass cmdiocb to state machine which needs rspiocb as well */
826 cmdiocb
->context_un
.rsp_iocb
= rspiocb
;
828 irsp
= &rspiocb
->iocb
;
829 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
830 "PLOGI cmpl: status:x%x/x%x did:x%x",
831 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
832 irsp
->un
.elsreq64
.remoteID
);
834 ndlp
= lpfc_findnode_did(vport
, irsp
->un
.elsreq64
.remoteID
);
836 lpfc_printf_log(phba
, KERN_ERR
, LOG_ELS
,
837 "%d (%d):0136 PLOGI completes to NPort x%x "
838 "with no ndlp. Data: x%x x%x x%x\n",
839 phba
->brd_no
, vport
->vpi
, irsp
->un
.elsreq64
.remoteID
,
840 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4], irsp
->ulpIoTag
);
844 /* Since ndlp can be freed in the disc state machine, note if this node
845 * is being used during discovery.
847 spin_lock_irq(shost
->host_lock
);
848 disc
= (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
);
849 ndlp
->nlp_flag
&= ~NLP_NPR_2B_DISC
;
850 spin_unlock_irq(shost
->host_lock
);
853 /* PLOGI completes to NPort <nlp_DID> */
854 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
855 "%d (%d):0102 PLOGI completes to NPort x%x "
856 "Data: x%x x%x x%x x%x x%x\n",
857 phba
->brd_no
, vport
->vpi
, ndlp
->nlp_DID
,
858 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
859 irsp
->ulpTimeout
, disc
, vport
->num_disc_nodes
);
861 /* Check to see if link went down during discovery */
862 if (lpfc_els_chk_latt(vport
)) {
863 spin_lock_irq(shost
->host_lock
);
864 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
865 spin_unlock_irq(shost
->host_lock
);
869 /* ndlp could be freed in DSM, save these values now */
870 type
= ndlp
->nlp_type
;
873 if (irsp
->ulpStatus
) {
874 /* Check for retry */
875 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
)) {
876 /* ELS command is being retried */
878 spin_lock_irq(shost
->host_lock
);
879 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
880 spin_unlock_irq(shost
->host_lock
);
886 if (ndlp
->nlp_DID
== NameServer_DID
) {
887 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
888 lpfc_printf_log(phba
, KERN_ERR
, LOG_ELS
,
889 "%d (%d):0250 Nameserver login error: "
891 phba
->brd_no
, vport
->vpi
,
892 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4]);
895 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
896 if (lpfc_error_lost_link(irsp
)) {
897 rc
= NLP_STE_FREED_NODE
;
899 rc
= lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
903 /* Good status, call state machine */
904 prsp
= list_entry(((struct lpfc_dmabuf
*)
905 cmdiocb
->context2
)->list
.next
,
906 struct lpfc_dmabuf
, list
);
907 ndlp
= lpfc_plogi_confirm_nport(phba
, prsp
->virt
, ndlp
);
908 rc
= lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
912 if (disc
&& vport
->num_disc_nodes
) {
913 /* Check to see if there are more PLOGIs to be sent */
914 lpfc_more_plogi(vport
);
916 if (vport
->num_disc_nodes
== 0) {
917 spin_lock_irq(shost
->host_lock
);
918 vport
->fc_flag
&= ~FC_NDISC_ACTIVE
;
919 spin_unlock_irq(shost
->host_lock
);
921 lpfc_can_disctmo(vport
);
922 if (vport
->fc_flag
& FC_RSCN_MODE
) {
924 * Check to see if more RSCNs came in while
925 * we were processing this one.
927 if ((vport
->fc_rscn_id_cnt
== 0) &&
928 (!(vport
->fc_flag
& FC_RSCN_DISCOVERY
))) {
929 spin_lock_irq(shost
->host_lock
);
930 vport
->fc_flag
&= ~FC_RSCN_MODE
;
931 spin_unlock_irq(shost
->host_lock
);
933 lpfc_els_handle_rscn(vport
);
940 lpfc_els_free_iocb(phba
, cmdiocb
);
945 lpfc_issue_els_plogi(struct lpfc_vport
*vport
, uint32_t did
, uint8_t retry
)
947 struct lpfc_hba
*phba
= vport
->phba
;
948 struct serv_parm
*sp
;
950 struct lpfc_iocbq
*elsiocb
;
951 struct lpfc_sli_ring
*pring
;
952 struct lpfc_sli
*psli
;
958 pring
= &psli
->ring
[LPFC_ELS_RING
]; /* ELS ring */
960 cmdsize
= (sizeof(uint32_t) + sizeof(struct serv_parm
));
961 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, NULL
, did
,
966 icmd
= &elsiocb
->iocb
;
967 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
969 /* For PLOGI request, remainder of payload is service parameters */
970 *((uint32_t *) (pcmd
)) = ELS_CMD_PLOGI
;
971 pcmd
+= sizeof(uint32_t);
972 memcpy(pcmd
, &vport
->fc_sparam
, sizeof(struct serv_parm
));
973 sp
= (struct serv_parm
*) pcmd
;
975 if (sp
->cmn
.fcphLow
< FC_PH_4_3
)
976 sp
->cmn
.fcphLow
= FC_PH_4_3
;
978 if (sp
->cmn
.fcphHigh
< FC_PH3
)
979 sp
->cmn
.fcphHigh
= FC_PH3
;
981 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
982 "Issue PLOGI: did:x%x",
985 phba
->fc_stat
.elsXmitPLOGI
++;
986 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_plogi
;
987 ret
= lpfc_sli_issue_iocb(phba
, pring
, elsiocb
, 0);
989 if (ret
== IOCB_ERROR
) {
990 lpfc_els_free_iocb(phba
, elsiocb
);
997 lpfc_cmpl_els_prli(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
998 struct lpfc_iocbq
*rspiocb
)
1000 struct lpfc_vport
*vport
= cmdiocb
->vport
;
1001 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1003 struct lpfc_sli
*psli
;
1004 struct lpfc_nodelist
*ndlp
;
1007 /* we pass cmdiocb to state machine which needs rspiocb as well */
1008 cmdiocb
->context_un
.rsp_iocb
= rspiocb
;
1010 irsp
= &(rspiocb
->iocb
);
1011 ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
1012 spin_lock_irq(shost
->host_lock
);
1013 ndlp
->nlp_flag
&= ~NLP_PRLI_SND
;
1014 spin_unlock_irq(shost
->host_lock
);
1016 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1017 "PRLI cmpl: status:x%x/x%x did:x%x",
1018 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1021 /* PRLI completes to NPort <nlp_DID> */
1022 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
1023 "%d (%d):0103 PRLI completes to NPort x%x "
1024 "Data: x%x x%x x%x x%x\n",
1025 phba
->brd_no
, vport
->vpi
, ndlp
->nlp_DID
,
1026 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4], irsp
->ulpTimeout
,
1027 vport
->num_disc_nodes
);
1029 vport
->fc_prli_sent
--;
1030 /* Check to see if link went down during discovery */
1031 if (lpfc_els_chk_latt(vport
))
1034 if (irsp
->ulpStatus
) {
1035 /* Check for retry */
1036 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
)) {
1037 /* ELS command is being retried */
1041 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1042 if (lpfc_error_lost_link(irsp
)) {
1045 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
1049 /* Good status, call state machine */
1050 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
1055 lpfc_els_free_iocb(phba
, cmdiocb
);
1060 lpfc_issue_els_prli(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1063 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1064 struct lpfc_hba
*phba
= vport
->phba
;
1067 struct lpfc_iocbq
*elsiocb
;
1068 struct lpfc_sli_ring
*pring
;
1069 struct lpfc_sli
*psli
;
1074 pring
= &psli
->ring
[LPFC_ELS_RING
]; /* ELS ring */
1076 cmdsize
= (sizeof(uint32_t) + sizeof(PRLI
));
1077 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
1078 ndlp
->nlp_DID
, ELS_CMD_PRLI
);
1082 icmd
= &elsiocb
->iocb
;
1083 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
1085 /* For PRLI request, remainder of payload is service parameters */
1086 memset(pcmd
, 0, (sizeof(PRLI
) + sizeof(uint32_t)));
1087 *((uint32_t *) (pcmd
)) = ELS_CMD_PRLI
;
1088 pcmd
+= sizeof(uint32_t);
1090 /* For PRLI, remainder of payload is PRLI parameter page */
1091 npr
= (PRLI
*) pcmd
;
1093 * If our firmware version is 3.20 or later,
1094 * set the following bits for FC-TAPE support.
1096 if (phba
->vpd
.rev
.feaLevelHigh
>= 0x02) {
1097 npr
->ConfmComplAllowed
= 1;
1099 npr
->TaskRetryIdReq
= 1;
1101 npr
->estabImagePair
= 1;
1102 npr
->readXferRdyDis
= 1;
1104 /* For FCP support */
1105 npr
->prliType
= PRLI_FCP_TYPE
;
1106 npr
->initiatorFunc
= 1;
1108 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1109 "Issue PRLI: did:x%x",
1110 ndlp
->nlp_DID
, 0, 0);
1112 phba
->fc_stat
.elsXmitPRLI
++;
1113 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_prli
;
1114 spin_lock_irq(shost
->host_lock
);
1115 ndlp
->nlp_flag
|= NLP_PRLI_SND
;
1116 spin_unlock_irq(shost
->host_lock
);
1117 if (lpfc_sli_issue_iocb(phba
, pring
, elsiocb
, 0) == IOCB_ERROR
) {
1118 spin_lock_irq(shost
->host_lock
);
1119 ndlp
->nlp_flag
&= ~NLP_PRLI_SND
;
1120 spin_unlock_irq(shost
->host_lock
);
1121 lpfc_els_free_iocb(phba
, elsiocb
);
1124 vport
->fc_prli_sent
++;
1129 lpfc_more_adisc(struct lpfc_vport
*vport
)
1132 struct lpfc_hba
*phba
= vport
->phba
;
1134 if (vport
->num_disc_nodes
)
1135 vport
->num_disc_nodes
--;
1137 /* Continue discovery with <num_disc_nodes> ADISCs to go */
1138 lpfc_printf_log(phba
, KERN_INFO
, LOG_DISCOVERY
,
1139 "%d (%d):0210 Continue discovery with %d ADISCs to go "
1140 "Data: x%x x%x x%x\n",
1141 phba
->brd_no
, vport
->vpi
, vport
->num_disc_nodes
,
1142 vport
->fc_adisc_cnt
, vport
->fc_flag
, vport
->port_state
);
1144 /* Check to see if there are more ADISCs to be sent */
1145 if (vport
->fc_flag
& FC_NLP_MORE
) {
1146 lpfc_set_disctmo(vport
);
1147 /* go thru NPR nodes and issue any remaining ELS ADISCs */
1148 sentadisc
= lpfc_els_disc_adisc(vport
);
1154 lpfc_rscn_disc(struct lpfc_vport
*vport
)
1156 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1158 lpfc_can_disctmo(vport
);
1160 /* RSCN discovery */
1161 /* go thru NPR nodes and issue ELS PLOGIs */
1162 if (vport
->fc_npr_cnt
)
1163 if (lpfc_els_disc_plogi(vport
))
1166 if (vport
->fc_flag
& FC_RSCN_MODE
) {
1167 /* Check to see if more RSCNs came in while we were
1168 * processing this one.
1170 if ((vport
->fc_rscn_id_cnt
== 0) &&
1171 (!(vport
->fc_flag
& FC_RSCN_DISCOVERY
))) {
1172 spin_lock_irq(shost
->host_lock
);
1173 vport
->fc_flag
&= ~FC_RSCN_MODE
;
1174 spin_unlock_irq(shost
->host_lock
);
1176 lpfc_els_handle_rscn(vport
);
1182 lpfc_cmpl_els_adisc(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
1183 struct lpfc_iocbq
*rspiocb
)
1185 struct lpfc_vport
*vport
= cmdiocb
->vport
;
1186 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1188 struct lpfc_nodelist
*ndlp
;
1191 /* we pass cmdiocb to state machine which needs rspiocb as well */
1192 cmdiocb
->context_un
.rsp_iocb
= rspiocb
;
1194 irsp
= &(rspiocb
->iocb
);
1195 ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
1197 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1198 "ADISC cmpl: status:x%x/x%x did:x%x",
1199 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1202 /* Since ndlp can be freed in the disc state machine, note if this node
1203 * is being used during discovery.
1205 spin_lock_irq(shost
->host_lock
);
1206 disc
= (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
);
1207 ndlp
->nlp_flag
&= ~(NLP_ADISC_SND
| NLP_NPR_2B_DISC
);
1208 spin_unlock_irq(shost
->host_lock
);
1210 /* ADISC completes to NPort <nlp_DID> */
1211 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
1212 "%d (%d):0104 ADISC completes to NPort x%x "
1213 "Data: x%x x%x x%x x%x x%x\n",
1214 phba
->brd_no
, vport
->vpi
, ndlp
->nlp_DID
,
1215 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4], irsp
->ulpTimeout
,
1216 disc
, vport
->num_disc_nodes
);
1218 /* Check to see if link went down during discovery */
1219 if (lpfc_els_chk_latt(vport
)) {
1220 spin_lock_irq(shost
->host_lock
);
1221 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
1222 spin_unlock_irq(shost
->host_lock
);
1226 if (irsp
->ulpStatus
) {
1227 /* Check for retry */
1228 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
)) {
1229 /* ELS command is being retried */
1231 spin_lock_irq(shost
->host_lock
);
1232 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
1233 spin_unlock_irq(shost
->host_lock
);
1234 lpfc_set_disctmo(vport
);
1239 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1240 if (!lpfc_error_lost_link(irsp
)) {
1241 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
1242 NLP_EVT_CMPL_ADISC
);
1245 /* Good status, call state machine */
1246 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
1247 NLP_EVT_CMPL_ADISC
);
1250 if (disc
&& vport
->num_disc_nodes
) {
1251 /* Check to see if there are more ADISCs to be sent */
1252 lpfc_more_adisc(vport
);
1254 /* Check to see if we are done with ADISC authentication */
1255 if (vport
->num_disc_nodes
== 0) {
1256 /* If we get here, there is nothing left to ADISC */
1258 * For NPIV, cmpl_reg_vpi will set port_state to READY,
1259 * and continue discovery.
1261 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
1262 !(vport
->fc_flag
& FC_RSCN_MODE
)) {
1263 lpfc_issue_reg_vpi(phba
, vport
);
1267 * For SLI2, we need to set port_state to READY
1268 * and continue discovery.
1270 if (vport
->port_state
< LPFC_VPORT_READY
) {
1271 /* If we get here, there is nothing to ADISC */
1272 if (vport
->port_type
== LPFC_PHYSICAL_PORT
)
1273 lpfc_issue_clear_la(phba
, vport
);
1275 if (!(vport
->fc_flag
& FC_ABORT_DISCOVERY
)) {
1276 vport
->num_disc_nodes
= 0;
1277 /* go thru NPR list, issue ELS PLOGIs */
1278 if (vport
->fc_npr_cnt
)
1279 lpfc_els_disc_plogi(vport
);
1281 if (!vport
->num_disc_nodes
) {
1282 spin_lock_irq(shost
->host_lock
);
1287 lpfc_can_disctmo(vport
);
1290 vport
->port_state
= LPFC_VPORT_READY
;
1292 lpfc_rscn_disc(vport
);
1297 lpfc_els_free_iocb(phba
, cmdiocb
);
1302 lpfc_issue_els_adisc(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1305 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1306 struct lpfc_hba
*phba
= vport
->phba
;
1309 struct lpfc_iocbq
*elsiocb
;
1310 struct lpfc_sli
*psli
= &phba
->sli
;
1311 struct lpfc_sli_ring
*pring
= &psli
->ring
[LPFC_ELS_RING
];
1315 cmdsize
= (sizeof(uint32_t) + sizeof(ADISC
));
1316 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
1317 ndlp
->nlp_DID
, ELS_CMD_ADISC
);
1321 icmd
= &elsiocb
->iocb
;
1322 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
1324 /* For ADISC request, remainder of payload is service parameters */
1325 *((uint32_t *) (pcmd
)) = ELS_CMD_ADISC
;
1326 pcmd
+= sizeof(uint32_t);
1328 /* Fill in ADISC payload */
1329 ap
= (ADISC
*) pcmd
;
1330 ap
->hardAL_PA
= phba
->fc_pref_ALPA
;
1331 memcpy(&ap
->portName
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
1332 memcpy(&ap
->nodeName
, &vport
->fc_nodename
, sizeof(struct lpfc_name
));
1333 ap
->DID
= be32_to_cpu(vport
->fc_myDID
);
1335 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1336 "Issue ADISC: did:x%x",
1337 ndlp
->nlp_DID
, 0, 0);
1339 phba
->fc_stat
.elsXmitADISC
++;
1340 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_adisc
;
1341 spin_lock_irq(shost
->host_lock
);
1342 ndlp
->nlp_flag
|= NLP_ADISC_SND
;
1343 spin_unlock_irq(shost
->host_lock
);
1344 if (lpfc_sli_issue_iocb(phba
, pring
, elsiocb
, 0) == IOCB_ERROR
) {
1345 spin_lock_irq(shost
->host_lock
);
1346 ndlp
->nlp_flag
&= ~NLP_ADISC_SND
;
1347 spin_unlock_irq(shost
->host_lock
);
1348 lpfc_els_free_iocb(phba
, elsiocb
);
1355 lpfc_cmpl_els_logo(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
1356 struct lpfc_iocbq
*rspiocb
)
1358 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
1359 struct lpfc_vport
*vport
= ndlp
->vport
;
1360 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1362 struct lpfc_sli
*psli
;
1365 /* we pass cmdiocb to state machine which needs rspiocb as well */
1366 cmdiocb
->context_un
.rsp_iocb
= rspiocb
;
1368 irsp
= &(rspiocb
->iocb
);
1369 spin_lock_irq(shost
->host_lock
);
1370 ndlp
->nlp_flag
&= ~NLP_LOGO_SND
;
1371 spin_unlock_irq(shost
->host_lock
);
1373 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1374 "LOGO cmpl: status:x%x/x%x did:x%x",
1375 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1378 /* LOGO completes to NPort <nlp_DID> */
1379 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
1380 "%d (%d):0105 LOGO completes to NPort x%x "
1381 "Data: x%x x%x x%x x%x\n",
1382 phba
->brd_no
, vport
->vpi
, ndlp
->nlp_DID
,
1383 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4], irsp
->ulpTimeout
,
1384 vport
->num_disc_nodes
);
1386 /* Check to see if link went down during discovery */
1387 if (lpfc_els_chk_latt(vport
))
1390 if (ndlp
->nlp_flag
& NLP_TARGET_REMOVE
) {
1391 /* NLP_EVT_DEVICE_RM should unregister the RPI
1392 * which should abort all outstanding IOs.
1394 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
1399 if (irsp
->ulpStatus
) {
1400 /* Check for retry */
1401 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
))
1402 /* ELS command is being retried */
1405 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1406 if (lpfc_error_lost_link(irsp
))
1409 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
1412 /* Good status, call state machine.
1413 * This will unregister the rpi if needed.
1415 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
1420 lpfc_els_free_iocb(phba
, cmdiocb
);
1425 lpfc_issue_els_logo(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1428 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1429 struct lpfc_hba
*phba
= vport
->phba
;
1431 struct lpfc_iocbq
*elsiocb
;
1432 struct lpfc_sli_ring
*pring
;
1433 struct lpfc_sli
*psli
;
1439 pring
= &psli
->ring
[LPFC_ELS_RING
];
1441 cmdsize
= (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name
);
1442 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
1443 ndlp
->nlp_DID
, ELS_CMD_LOGO
);
1447 icmd
= &elsiocb
->iocb
;
1448 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
1449 *((uint32_t *) (pcmd
)) = ELS_CMD_LOGO
;
1450 pcmd
+= sizeof(uint32_t);
1452 /* Fill in LOGO payload */
1453 *((uint32_t *) (pcmd
)) = be32_to_cpu(vport
->fc_myDID
);
1454 pcmd
+= sizeof(uint32_t);
1455 memcpy(pcmd
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
1457 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1458 "Issue LOGO: did:x%x",
1459 ndlp
->nlp_DID
, 0, 0);
1461 phba
->fc_stat
.elsXmitLOGO
++;
1462 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_logo
;
1463 spin_lock_irq(shost
->host_lock
);
1464 ndlp
->nlp_flag
|= NLP_LOGO_SND
;
1465 spin_unlock_irq(shost
->host_lock
);
1466 rc
= lpfc_sli_issue_iocb(phba
, pring
, elsiocb
, 0);
1468 if (rc
== IOCB_ERROR
) {
1469 spin_lock_irq(shost
->host_lock
);
1470 ndlp
->nlp_flag
&= ~NLP_LOGO_SND
;
1471 spin_unlock_irq(shost
->host_lock
);
1472 lpfc_els_free_iocb(phba
, elsiocb
);
1479 lpfc_cmpl_els_cmd(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
1480 struct lpfc_iocbq
*rspiocb
)
1482 struct lpfc_vport
*vport
= cmdiocb
->vport
;
1485 irsp
= &rspiocb
->iocb
;
1487 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1488 "ELS cmd cmpl: status:x%x/x%x did:x%x",
1489 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1490 irsp
->un
.elsreq64
.remoteID
);
1492 /* ELS cmd tag <ulpIoTag> completes */
1493 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
1494 "%d (%d):0106 ELS cmd tag x%x completes Data: x%x x%x "
1496 phba
->brd_no
, vport
->vpi
,
1497 irsp
->ulpIoTag
, irsp
->ulpStatus
,
1498 irsp
->un
.ulpWord
[4], irsp
->ulpTimeout
);
1500 /* Check to see if link went down during discovery */
1501 lpfc_els_chk_latt(vport
);
1502 lpfc_els_free_iocb(phba
, cmdiocb
);
1507 lpfc_issue_els_scr(struct lpfc_vport
*vport
, uint32_t nportid
, uint8_t retry
)
1509 struct lpfc_hba
*phba
= vport
->phba
;
1511 struct lpfc_iocbq
*elsiocb
;
1512 struct lpfc_sli_ring
*pring
;
1513 struct lpfc_sli
*psli
;
1516 struct lpfc_nodelist
*ndlp
;
1519 pring
= &psli
->ring
[LPFC_ELS_RING
]; /* ELS ring */
1520 cmdsize
= (sizeof(uint32_t) + sizeof(SCR
));
1521 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
1525 lpfc_nlp_init(vport
, ndlp
, nportid
);
1527 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
1528 ndlp
->nlp_DID
, ELS_CMD_SCR
);
1535 icmd
= &elsiocb
->iocb
;
1536 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
1538 *((uint32_t *) (pcmd
)) = ELS_CMD_SCR
;
1539 pcmd
+= sizeof(uint32_t);
1541 /* For SCR, remainder of payload is SCR parameter page */
1542 memset(pcmd
, 0, sizeof(SCR
));
1543 ((SCR
*) pcmd
)->Function
= SCR_FUNC_FULL
;
1545 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1546 "Issue SCR: did:x%x",
1547 ndlp
->nlp_DID
, 0, 0);
1549 phba
->fc_stat
.elsXmitSCR
++;
1550 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_cmd
;
1551 if (lpfc_sli_issue_iocb(phba
, pring
, elsiocb
, 0) == IOCB_ERROR
) {
1553 lpfc_els_free_iocb(phba
, elsiocb
);
1561 lpfc_issue_els_farpr(struct lpfc_vport
*vport
, uint32_t nportid
, uint8_t retry
)
1563 struct lpfc_hba
*phba
= vport
->phba
;
1565 struct lpfc_iocbq
*elsiocb
;
1566 struct lpfc_sli_ring
*pring
;
1567 struct lpfc_sli
*psli
;
1572 struct lpfc_nodelist
*ondlp
;
1573 struct lpfc_nodelist
*ndlp
;
1576 pring
= &psli
->ring
[LPFC_ELS_RING
]; /* ELS ring */
1577 cmdsize
= (sizeof(uint32_t) + sizeof(FARP
));
1578 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
1582 lpfc_nlp_init(vport
, ndlp
, nportid
);
1584 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
1585 ndlp
->nlp_DID
, ELS_CMD_RNID
);
1591 icmd
= &elsiocb
->iocb
;
1592 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
1594 *((uint32_t *) (pcmd
)) = ELS_CMD_FARPR
;
1595 pcmd
+= sizeof(uint32_t);
1597 /* Fill in FARPR payload */
1598 fp
= (FARP
*) (pcmd
);
1599 memset(fp
, 0, sizeof(FARP
));
1600 lp
= (uint32_t *) pcmd
;
1601 *lp
++ = be32_to_cpu(nportid
);
1602 *lp
++ = be32_to_cpu(vport
->fc_myDID
);
1604 fp
->Mflags
= (FARP_MATCH_PORT
| FARP_MATCH_NODE
);
1606 memcpy(&fp
->RportName
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
1607 memcpy(&fp
->RnodeName
, &vport
->fc_nodename
, sizeof(struct lpfc_name
));
1608 ondlp
= lpfc_findnode_did(vport
, nportid
);
1610 memcpy(&fp
->OportName
, &ondlp
->nlp_portname
,
1611 sizeof(struct lpfc_name
));
1612 memcpy(&fp
->OnodeName
, &ondlp
->nlp_nodename
,
1613 sizeof(struct lpfc_name
));
1616 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1617 "Issue FARPR: did:x%x",
1618 ndlp
->nlp_DID
, 0, 0);
1620 phba
->fc_stat
.elsXmitFARPR
++;
1621 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_cmd
;
1622 if (lpfc_sli_issue_iocb(phba
, pring
, elsiocb
, 0) == IOCB_ERROR
) {
1624 lpfc_els_free_iocb(phba
, elsiocb
);
1632 lpfc_end_rscn(struct lpfc_vport
*vport
)
1634 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1636 if (vport
->fc_flag
& FC_RSCN_MODE
) {
1638 * Check to see if more RSCNs came in while we were
1639 * processing this one.
1641 if (vport
->fc_rscn_id_cnt
||
1642 (vport
->fc_flag
& FC_RSCN_DISCOVERY
) != 0)
1643 lpfc_els_handle_rscn(vport
);
1645 spin_lock_irq(shost
->host_lock
);
1646 vport
->fc_flag
&= ~FC_RSCN_MODE
;
1647 spin_unlock_irq(shost
->host_lock
);
1653 lpfc_cancel_retry_delay_tmo(struct lpfc_vport
*vport
, struct lpfc_nodelist
*nlp
)
1655 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1657 spin_lock_irq(shost
->host_lock
);
1658 nlp
->nlp_flag
&= ~NLP_DELAY_TMO
;
1659 spin_unlock_irq(shost
->host_lock
);
1660 del_timer_sync(&nlp
->nlp_delayfunc
);
1661 nlp
->nlp_last_elscmd
= 0;
1663 if (!list_empty(&nlp
->els_retry_evt
.evt_listp
))
1664 list_del_init(&nlp
->els_retry_evt
.evt_listp
);
1666 if (nlp
->nlp_flag
& NLP_NPR_2B_DISC
) {
1667 spin_lock_irq(shost
->host_lock
);
1668 nlp
->nlp_flag
&= ~NLP_NPR_2B_DISC
;
1669 spin_unlock_irq(shost
->host_lock
);
1670 if (vport
->num_disc_nodes
) {
1671 /* Check to see if there are more
1674 lpfc_more_plogi(vport
);
1676 if (vport
->num_disc_nodes
== 0) {
1677 spin_lock_irq(shost
->host_lock
);
1678 vport
->fc_flag
&= ~FC_NDISC_ACTIVE
;
1679 spin_unlock_irq(shost
->host_lock
);
1680 lpfc_can_disctmo(vport
);
1681 lpfc_end_rscn(vport
);
1689 lpfc_els_retry_delay(unsigned long ptr
)
1691 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) ptr
;
1692 struct lpfc_vport
*vport
= ndlp
->vport
;
1693 struct lpfc_hba
*phba
= vport
->phba
;
1694 unsigned long flags
;
1695 struct lpfc_work_evt
*evtp
= &ndlp
->els_retry_evt
;
1697 ndlp
= (struct lpfc_nodelist
*) ptr
;
1698 phba
= ndlp
->vport
->phba
;
1699 evtp
= &ndlp
->els_retry_evt
;
1701 spin_lock_irqsave(&phba
->hbalock
, flags
);
1702 if (!list_empty(&evtp
->evt_listp
)) {
1703 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1707 evtp
->evt_arg1
= ndlp
;
1708 evtp
->evt
= LPFC_EVT_ELS_RETRY
;
1709 list_add_tail(&evtp
->evt_listp
, &phba
->work_list
);
1710 if (phba
->work_wait
)
1711 lpfc_worker_wake_up(phba
);
1713 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1718 lpfc_els_retry_delay_handler(struct lpfc_nodelist
*ndlp
)
1720 struct lpfc_vport
*vport
= ndlp
->vport
;
1721 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1722 uint32_t cmd
, did
, retry
;
1724 spin_lock_irq(shost
->host_lock
);
1725 did
= ndlp
->nlp_DID
;
1726 cmd
= ndlp
->nlp_last_elscmd
;
1727 ndlp
->nlp_last_elscmd
= 0;
1729 if (!(ndlp
->nlp_flag
& NLP_DELAY_TMO
)) {
1730 spin_unlock_irq(shost
->host_lock
);
1734 ndlp
->nlp_flag
&= ~NLP_DELAY_TMO
;
1735 spin_unlock_irq(shost
->host_lock
);
1737 * If a discovery event readded nlp_delayfunc after timer
1738 * firing and before processing the timer, cancel the
1741 del_timer_sync(&ndlp
->nlp_delayfunc
);
1742 retry
= ndlp
->nlp_retry
;
1746 lpfc_issue_els_flogi(vport
, ndlp
, retry
);
1749 if (!lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, retry
)) {
1750 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
1751 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
1755 if (!lpfc_issue_els_adisc(vport
, ndlp
, retry
)) {
1756 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
1757 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_ADISC_ISSUE
);
1761 if (!lpfc_issue_els_prli(vport
, ndlp
, retry
)) {
1762 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
1763 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PRLI_ISSUE
);
1767 if (!lpfc_issue_els_logo(vport
, ndlp
, retry
)) {
1768 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
1769 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1773 lpfc_issue_els_fdisc(vport
, ndlp
, retry
);
1780 lpfc_els_retry(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
1781 struct lpfc_iocbq
*rspiocb
)
1783 struct lpfc_vport
*vport
= cmdiocb
->vport
;
1784 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1785 IOCB_t
*irsp
= &rspiocb
->iocb
;
1786 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
1787 struct lpfc_dmabuf
*pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
1790 int retry
= 0, maxretry
= lpfc_max_els_tries
, delay
= 0;
1795 /* Note: context2 may be 0 for internal driver abort
1796 * of delays ELS command.
1799 if (pcmd
&& pcmd
->virt
) {
1800 elscmd
= (uint32_t *) (pcmd
->virt
);
1805 did
= ndlp
->nlp_DID
;
1807 /* We should only hit this case for retrying PLOGI */
1808 did
= irsp
->un
.elsreq64
.remoteID
;
1809 ndlp
= lpfc_findnode_did(vport
, did
);
1810 if (!ndlp
&& (cmd
!= ELS_CMD_PLOGI
))
1814 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1815 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
1816 *(((uint32_t *) irsp
) + 7), irsp
->un
.ulpWord
[4], ndlp
->nlp_DID
);
1818 switch (irsp
->ulpStatus
) {
1819 case IOSTAT_FCP_RSP_ERROR
:
1820 case IOSTAT_REMOTE_STOP
:
1823 case IOSTAT_LOCAL_REJECT
:
1824 switch ((irsp
->un
.ulpWord
[4] & 0xff)) {
1825 case IOERR_LOOP_OPEN_FAILURE
:
1826 if (cmd
== ELS_CMD_PLOGI
&& cmdiocb
->retry
== 0)
1831 case IOERR_ILLEGAL_COMMAND
:
1832 if ((phba
->sli3_options
& LPFC_SLI3_VPORT_TEARDOWN
) &&
1833 (cmd
== ELS_CMD_FDISC
)) {
1834 lpfc_printf_log(phba
, KERN_ERR
, LOG_ELS
,
1835 "%d (%d):0124 FDISC failed (3/6) retrying...\n",
1836 phba
->brd_no
, vport
->vpi
);
1837 lpfc_mbx_unreg_vpi(vport
);
1839 /* Always retry for this case */
1844 case IOERR_NO_RESOURCES
:
1846 if (cmdiocb
->retry
> 100)
1851 case IOERR_ILLEGAL_FRAME
:
1856 case IOERR_SEQUENCE_TIMEOUT
:
1857 case IOERR_INVALID_RPI
:
1863 case IOSTAT_NPORT_RJT
:
1864 case IOSTAT_FABRIC_RJT
:
1865 if (irsp
->un
.ulpWord
[4] & RJT_UNAVAIL_TEMP
) {
1871 case IOSTAT_NPORT_BSY
:
1872 case IOSTAT_FABRIC_BSY
:
1877 stat
.un
.lsRjtError
= be32_to_cpu(irsp
->un
.ulpWord
[4]);
1878 /* Added for Vendor specifc support
1879 * Just keep retrying for these Rsn / Exp codes
1881 switch (stat
.un
.b
.lsRjtRsnCode
) {
1882 case LSRJT_UNABLE_TPC
:
1883 if (stat
.un
.b
.lsRjtRsnCodeExp
==
1884 LSEXP_CMD_IN_PROGRESS
) {
1885 if (cmd
== ELS_CMD_PLOGI
) {
1892 if (cmd
== ELS_CMD_PLOGI
) {
1894 maxretry
= lpfc_max_els_tries
+ 1;
1898 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
1899 (cmd
== ELS_CMD_FDISC
) &&
1900 (stat
.un
.b
.lsRjtRsnCodeExp
== LSEXP_OUT_OF_RESOURCE
)){
1901 lpfc_printf_log(phba
, KERN_ERR
, LOG_ELS
,
1902 "%d (%d):0125 FDISC Failed (x%x)."
1903 " Fabric out of resources\n",
1904 phba
->brd_no
, vport
->vpi
, stat
.un
.lsRjtError
);
1905 lpfc_vport_set_state(vport
,
1906 FC_VPORT_NO_FABRIC_RSCS
);
1910 case LSRJT_LOGICAL_BSY
:
1911 if ((cmd
== ELS_CMD_PLOGI
) ||
1912 (cmd
== ELS_CMD_PRLI
)) {
1915 } else if (cmd
== ELS_CMD_FDISC
) {
1916 /* Always retry for this case */
1922 case LSRJT_LOGICAL_ERR
:
1923 case LSRJT_PROTOCOL_ERR
:
1924 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
1925 (cmd
== ELS_CMD_FDISC
) &&
1926 ((stat
.un
.b
.lsRjtRsnCodeExp
== LSEXP_INVALID_PNAME
) ||
1927 (stat
.un
.b
.lsRjtRsnCodeExp
== LSEXP_INVALID_NPORT_ID
))
1929 lpfc_printf_log(phba
, KERN_ERR
, LOG_ELS
,
1930 "%d (%d):0123 FDISC Failed (x%x)."
1931 " Fabric Detected Bad WWN\n",
1932 phba
->brd_no
, vport
->vpi
, stat
.un
.lsRjtError
);
1933 lpfc_vport_set_state(vport
,
1934 FC_VPORT_FABRIC_REJ_WWN
);
1940 case IOSTAT_INTERMED_RSP
:
1948 if (did
== FDMI_DID
)
1951 if ((++cmdiocb
->retry
) >= maxretry
) {
1952 phba
->fc_stat
.elsRetryExceeded
++;
1956 if ((vport
->load_flag
& FC_UNLOADING
) != 0)
1961 /* Retry ELS command <elsCmd> to remote NPORT <did> */
1962 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
1963 "%d (%d):0107 Retry ELS command x%x to remote "
1964 "NPORT x%x Data: x%x x%x\n",
1965 phba
->brd_no
, vport
->vpi
,
1966 cmd
, did
, cmdiocb
->retry
, delay
);
1968 if (((cmd
== ELS_CMD_PLOGI
) || (cmd
== ELS_CMD_ADISC
)) &&
1969 ((irsp
->ulpStatus
!= IOSTAT_LOCAL_REJECT
) ||
1970 ((irsp
->un
.ulpWord
[4] & 0xff) != IOERR_NO_RESOURCES
))) {
1971 /* Don't reset timer for no resources */
1973 /* If discovery / RSCN timer is running, reset it */
1974 if (timer_pending(&vport
->fc_disctmo
) ||
1975 (vport
->fc_flag
& FC_RSCN_MODE
))
1976 lpfc_set_disctmo(vport
);
1979 phba
->fc_stat
.elsXmitRetry
++;
1980 if (ndlp
&& delay
) {
1981 phba
->fc_stat
.elsDelayRetry
++;
1982 ndlp
->nlp_retry
= cmdiocb
->retry
;
1984 /* delay is specified in milliseconds */
1985 mod_timer(&ndlp
->nlp_delayfunc
,
1986 jiffies
+ msecs_to_jiffies(delay
));
1987 spin_lock_irq(shost
->host_lock
);
1988 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
1989 spin_unlock_irq(shost
->host_lock
);
1991 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
1992 if (cmd
== ELS_CMD_PRLI
)
1993 lpfc_nlp_set_state(vport
, ndlp
,
1994 NLP_STE_REG_LOGIN_ISSUE
);
1996 lpfc_nlp_set_state(vport
, ndlp
,
1998 ndlp
->nlp_last_elscmd
= cmd
;
2004 lpfc_issue_els_flogi(vport
, ndlp
, cmdiocb
->retry
);
2007 lpfc_issue_els_fdisc(vport
, ndlp
, cmdiocb
->retry
);
2011 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
2012 lpfc_nlp_set_state(vport
, ndlp
,
2013 NLP_STE_PLOGI_ISSUE
);
2015 lpfc_issue_els_plogi(vport
, did
, cmdiocb
->retry
);
2018 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
2019 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_ADISC_ISSUE
);
2020 lpfc_issue_els_adisc(vport
, ndlp
, cmdiocb
->retry
);
2023 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
2024 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PRLI_ISSUE
);
2025 lpfc_issue_els_prli(vport
, ndlp
, cmdiocb
->retry
);
2028 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
2029 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
2030 lpfc_issue_els_logo(vport
, ndlp
, cmdiocb
->retry
);
2035 /* No retry ELS command <elsCmd> to remote NPORT <did> */
2036 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
2037 "0108 No retry ELS command x%x to remote "
2038 "NPORT x%x Retried:%d Error:x%x/%x\n",
2039 cmd
, did
, cmdiocb
->retry
, irsp
->ulpStatus
,
2040 irsp
->un
.ulpWord
[4]);
2045 lpfc_els_free_iocb(struct lpfc_hba
*phba
, struct lpfc_iocbq
*elsiocb
)
2047 struct lpfc_dmabuf
*buf_ptr
, *buf_ptr1
;
2049 if (elsiocb
->context1
) {
2050 lpfc_nlp_put(elsiocb
->context1
);
2051 elsiocb
->context1
= NULL
;
2053 /* context2 = cmd, context2->next = rsp, context3 = bpl */
2054 if (elsiocb
->context2
) {
2055 buf_ptr1
= (struct lpfc_dmabuf
*) elsiocb
->context2
;
2056 /* Free the response before processing the command. */
2057 if (!list_empty(&buf_ptr1
->list
)) {
2058 list_remove_head(&buf_ptr1
->list
, buf_ptr
,
2061 lpfc_mbuf_free(phba
, buf_ptr
->virt
, buf_ptr
->phys
);
2064 lpfc_mbuf_free(phba
, buf_ptr1
->virt
, buf_ptr1
->phys
);
2068 if (elsiocb
->context3
) {
2069 buf_ptr
= (struct lpfc_dmabuf
*) elsiocb
->context3
;
2070 lpfc_mbuf_free(phba
, buf_ptr
->virt
, buf_ptr
->phys
);
2073 lpfc_sli_release_iocbq(phba
, elsiocb
);
2078 lpfc_cmpl_els_logo_acc(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
2079 struct lpfc_iocbq
*rspiocb
)
2081 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
2082 struct lpfc_vport
*vport
= cmdiocb
->vport
;
2085 irsp
= &rspiocb
->iocb
;
2086 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
2087 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
2088 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4], ndlp
->nlp_DID
);
2090 /* ACC to LOGO completes to NPort <nlp_DID> */
2091 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
2092 "%d (%d):0109 ACC to LOGO completes to NPort x%x "
2093 "Data: x%x x%x x%x\n",
2094 phba
->brd_no
, vport
->vpi
, ndlp
->nlp_DID
,
2095 ndlp
->nlp_flag
, ndlp
->nlp_state
, ndlp
->nlp_rpi
);
2097 switch (ndlp
->nlp_state
) {
2098 case NLP_STE_UNUSED_NODE
: /* node is just allocated */
2099 lpfc_drop_node(vport
, ndlp
);
2101 case NLP_STE_NPR_NODE
: /* NPort Recovery mode */
2102 lpfc_unreg_rpi(vport
, ndlp
);
2107 lpfc_els_free_iocb(phba
, cmdiocb
);
2112 lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
2114 struct lpfc_dmabuf
*mp
= (struct lpfc_dmabuf
*) (pmb
->context1
);
2115 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
2117 pmb
->context1
= NULL
;
2118 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
2120 mempool_free(pmb
, phba
->mbox_mem_pool
);
2126 lpfc_cmpl_els_rsp(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
2127 struct lpfc_iocbq
*rspiocb
)
2129 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
2130 struct lpfc_vport
*vport
= ndlp
? ndlp
->vport
: NULL
;
2131 struct Scsi_Host
*shost
= vport
? lpfc_shost_from_vport(vport
) : NULL
;
2133 LPFC_MBOXQ_t
*mbox
= NULL
;
2134 struct lpfc_dmabuf
*mp
= NULL
;
2136 irsp
= &rspiocb
->iocb
;
2138 if (cmdiocb
->context_un
.mbox
)
2139 mbox
= cmdiocb
->context_un
.mbox
;
2141 /* Check to see if link went down during discovery */
2142 if (!ndlp
|| lpfc_els_chk_latt(vport
)) {
2144 mp
= (struct lpfc_dmabuf
*) mbox
->context1
;
2146 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
2149 mempool_free(mbox
, phba
->mbox_mem_pool
);
2154 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
2155 "ACC cmpl: status:x%x/x%x did:x%x",
2156 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
2157 irsp
->un
.rcvels
.remoteID
);
2159 /* ELS response tag <ulpIoTag> completes */
2160 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
2161 "%d (%d):0110 ELS response tag x%x completes "
2162 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
2163 phba
->brd_no
, vport
->vpi
,
2164 cmdiocb
->iocb
.ulpIoTag
, rspiocb
->iocb
.ulpStatus
,
2165 rspiocb
->iocb
.un
.ulpWord
[4], rspiocb
->iocb
.ulpTimeout
,
2166 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
2170 if ((rspiocb
->iocb
.ulpStatus
== 0)
2171 && (ndlp
->nlp_flag
& NLP_ACC_REGLOGIN
)) {
2172 lpfc_unreg_rpi(vport
, ndlp
);
2173 mbox
->context2
= lpfc_nlp_get(ndlp
);
2174 mbox
->vport
= vport
;
2175 if (ndlp
->nlp_flag
& NLP_RM_DFLT_RPI
) {
2176 mbox
->mbox_flag
|= LPFC_MBX_IMED_UNREG
;
2177 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_dflt_rpi
;
2180 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_reg_login
;
2181 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
2182 lpfc_nlp_set_state(vport
, ndlp
,
2183 NLP_STE_REG_LOGIN_ISSUE
);
2185 if (lpfc_sli_issue_mbox(phba
, mbox
,
2186 (MBX_NOWAIT
| MBX_STOP_IOCB
))
2187 != MBX_NOT_FINISHED
) {
2191 /* NOTE: we should have messages for unsuccessful
2194 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
2195 if (!lpfc_error_lost_link(irsp
) &&
2196 ndlp
->nlp_flag
& NLP_ACC_REGLOGIN
) {
2197 lpfc_drop_node(vport
, ndlp
);
2201 mp
= (struct lpfc_dmabuf
*) mbox
->context1
;
2203 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
2206 mempool_free(mbox
, phba
->mbox_mem_pool
);
2210 spin_lock_irq(shost
->host_lock
);
2211 ndlp
->nlp_flag
&= ~(NLP_ACC_REGLOGIN
| NLP_RM_DFLT_RPI
);
2212 spin_unlock_irq(shost
->host_lock
);
2214 lpfc_els_free_iocb(phba
, cmdiocb
);
2219 lpfc_els_rsp_acc(struct lpfc_vport
*vport
, uint32_t flag
,
2220 struct lpfc_iocbq
*oldiocb
, struct lpfc_nodelist
*ndlp
,
2221 LPFC_MBOXQ_t
*mbox
, uint8_t newnode
)
2223 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2224 struct lpfc_hba
*phba
= vport
->phba
;
2227 struct lpfc_iocbq
*elsiocb
;
2228 struct lpfc_sli_ring
*pring
;
2229 struct lpfc_sli
*psli
;
2233 ELS_PKT
*els_pkt_ptr
;
2236 pring
= &psli
->ring
[LPFC_ELS_RING
]; /* ELS ring */
2237 oldcmd
= &oldiocb
->iocb
;
2241 cmdsize
= sizeof(uint32_t);
2242 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
,
2243 ndlp
, ndlp
->nlp_DID
, ELS_CMD_ACC
);
2245 spin_lock_irq(shost
->host_lock
);
2246 ndlp
->nlp_flag
&= ~NLP_LOGO_ACC
;
2247 spin_unlock_irq(shost
->host_lock
);
2251 icmd
= &elsiocb
->iocb
;
2252 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri */
2253 pcmd
= (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
2254 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
2255 pcmd
+= sizeof(uint32_t);
2257 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
2258 "Issue ACC: did:x%x flg:x%x",
2259 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
2262 cmdsize
= (sizeof(struct serv_parm
) + sizeof(uint32_t));
2263 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
,
2264 ndlp
, ndlp
->nlp_DID
, ELS_CMD_ACC
);
2268 icmd
= &elsiocb
->iocb
;
2269 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri */
2270 pcmd
= (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
2273 elsiocb
->context_un
.mbox
= mbox
;
2275 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
2276 pcmd
+= sizeof(uint32_t);
2277 memcpy(pcmd
, &vport
->fc_sparam
, sizeof(struct serv_parm
));
2279 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
2280 "Issue ACC PLOGI: did:x%x flg:x%x",
2281 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
2284 cmdsize
= sizeof(uint32_t) + sizeof(PRLO
);
2285 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
,
2286 ndlp
, ndlp
->nlp_DID
, ELS_CMD_PRLO
);
2290 icmd
= &elsiocb
->iocb
;
2291 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri */
2292 pcmd
= (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
2294 memcpy(pcmd
, ((struct lpfc_dmabuf
*) oldiocb
->context2
)->virt
,
2295 sizeof(uint32_t) + sizeof(PRLO
));
2296 *((uint32_t *) (pcmd
)) = ELS_CMD_PRLO_ACC
;
2297 els_pkt_ptr
= (ELS_PKT
*) pcmd
;
2298 els_pkt_ptr
->un
.prlo
.acceptRspCode
= PRLO_REQ_EXECUTED
;
2300 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
2301 "Issue ACC PRLO: did:x%x flg:x%x",
2302 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
2310 elsiocb
->context1
= NULL
;
2313 /* Xmit ELS ACC response tag <ulpIoTag> */
2314 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
2315 "%d (%d):0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
2316 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n",
2317 phba
->brd_no
, vport
->vpi
, elsiocb
->iotag
,
2318 elsiocb
->iocb
.ulpContext
, ndlp
->nlp_DID
,
2319 ndlp
->nlp_flag
, ndlp
->nlp_state
, ndlp
->nlp_rpi
);
2321 if (ndlp
->nlp_flag
& NLP_LOGO_ACC
) {
2322 spin_lock_irq(shost
->host_lock
);
2323 ndlp
->nlp_flag
&= ~NLP_LOGO_ACC
;
2324 spin_unlock_irq(shost
->host_lock
);
2325 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_logo_acc
;
2327 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
2330 phba
->fc_stat
.elsXmitACC
++;
2331 rc
= lpfc_sli_issue_iocb(phba
, pring
, elsiocb
, 0);
2332 if (rc
== IOCB_ERROR
) {
2333 lpfc_els_free_iocb(phba
, elsiocb
);
2340 lpfc_els_rsp_reject(struct lpfc_vport
*vport
, uint32_t rejectError
,
2341 struct lpfc_iocbq
*oldiocb
, struct lpfc_nodelist
*ndlp
,
2344 struct lpfc_hba
*phba
= vport
->phba
;
2347 struct lpfc_iocbq
*elsiocb
;
2348 struct lpfc_sli_ring
*pring
;
2349 struct lpfc_sli
*psli
;
2355 pring
= &psli
->ring
[LPFC_ELS_RING
]; /* ELS ring */
2357 cmdsize
= 2 * sizeof(uint32_t);
2358 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
2359 ndlp
->nlp_DID
, ELS_CMD_LS_RJT
);
2363 icmd
= &elsiocb
->iocb
;
2364 oldcmd
= &oldiocb
->iocb
;
2365 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri */
2366 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
2368 *((uint32_t *) (pcmd
)) = ELS_CMD_LS_RJT
;
2369 pcmd
+= sizeof(uint32_t);
2370 *((uint32_t *) (pcmd
)) = rejectError
;
2373 elsiocb
->context_un
.mbox
= mbox
;
2374 elsiocb
->context1
= lpfc_nlp_get(ndlp
);
2377 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
2378 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
2379 "%d (%d):0129 Xmit ELS RJT x%x response tag x%x "
2380 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
2382 phba
->brd_no
, vport
->vpi
, rejectError
, elsiocb
->iotag
,
2383 elsiocb
->iocb
.ulpContext
, ndlp
->nlp_DID
,
2384 ndlp
->nlp_flag
, ndlp
->nlp_state
, ndlp
->nlp_rpi
);
2386 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
2387 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
2388 ndlp
->nlp_DID
, ndlp
->nlp_flag
, rejectError
);
2390 phba
->fc_stat
.elsXmitLSRJT
++;
2391 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
2392 rc
= lpfc_sli_issue_iocb(phba
, pring
, elsiocb
, 0);
2393 if (rc
== IOCB_ERROR
) {
2394 lpfc_els_free_iocb(phba
, elsiocb
);
2401 lpfc_els_rsp_adisc_acc(struct lpfc_vport
*vport
, struct lpfc_iocbq
*oldiocb
,
2402 struct lpfc_nodelist
*ndlp
)
2404 struct lpfc_hba
*phba
= vport
->phba
;
2405 struct lpfc_sli
*psli
= &phba
->sli
;
2406 struct lpfc_sli_ring
*pring
= &psli
->ring
[LPFC_ELS_RING
];
2408 IOCB_t
*icmd
, *oldcmd
;
2409 struct lpfc_iocbq
*elsiocb
;
2414 cmdsize
= sizeof(uint32_t) + sizeof(ADISC
);
2415 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
2416 ndlp
->nlp_DID
, ELS_CMD_ACC
);
2420 icmd
= &elsiocb
->iocb
;
2421 oldcmd
= &oldiocb
->iocb
;
2422 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri */
2424 /* Xmit ADISC ACC response tag <ulpIoTag> */
2425 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
2426 "%d (%d):0130 Xmit ADISC ACC response iotag x%x xri: "
2427 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
2428 phba
->brd_no
, vport
->vpi
, elsiocb
->iotag
,
2429 elsiocb
->iocb
.ulpContext
, ndlp
->nlp_DID
,
2430 ndlp
->nlp_flag
, ndlp
->nlp_state
, ndlp
->nlp_rpi
);
2432 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
2434 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
2435 pcmd
+= sizeof(uint32_t);
2437 ap
= (ADISC
*) (pcmd
);
2438 ap
->hardAL_PA
= phba
->fc_pref_ALPA
;
2439 memcpy(&ap
->portName
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
2440 memcpy(&ap
->nodeName
, &vport
->fc_nodename
, sizeof(struct lpfc_name
));
2441 ap
->DID
= be32_to_cpu(vport
->fc_myDID
);
2443 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
2444 "Issue ACC ADISC: did:x%x flg:x%x",
2445 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
2447 phba
->fc_stat
.elsXmitACC
++;
2448 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
2449 rc
= lpfc_sli_issue_iocb(phba
, pring
, elsiocb
, 0);
2450 if (rc
== IOCB_ERROR
) {
2451 lpfc_els_free_iocb(phba
, elsiocb
);
2458 lpfc_els_rsp_prli_acc(struct lpfc_vport
*vport
, struct lpfc_iocbq
*oldiocb
,
2459 struct lpfc_nodelist
*ndlp
)
2461 struct lpfc_hba
*phba
= vport
->phba
;
2466 struct lpfc_iocbq
*elsiocb
;
2467 struct lpfc_sli_ring
*pring
;
2468 struct lpfc_sli
*psli
;
2474 pring
= &psli
->ring
[LPFC_ELS_RING
]; /* ELS ring */
2476 cmdsize
= sizeof(uint32_t) + sizeof(PRLI
);
2477 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
2478 ndlp
->nlp_DID
, (ELS_CMD_ACC
| (ELS_CMD_PRLI
& ~ELS_RSP_MASK
)));
2482 icmd
= &elsiocb
->iocb
;
2483 oldcmd
= &oldiocb
->iocb
;
2484 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri */
2486 /* Xmit PRLI ACC response tag <ulpIoTag> */
2487 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
2488 "%d (%d):0131 Xmit PRLI ACC response tag x%x xri x%x, "
2489 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
2490 phba
->brd_no
, vport
->vpi
, elsiocb
->iotag
,
2491 elsiocb
->iocb
.ulpContext
, ndlp
->nlp_DID
,
2492 ndlp
->nlp_flag
, ndlp
->nlp_state
, ndlp
->nlp_rpi
);
2494 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
2496 *((uint32_t *) (pcmd
)) = (ELS_CMD_ACC
| (ELS_CMD_PRLI
& ~ELS_RSP_MASK
));
2497 pcmd
+= sizeof(uint32_t);
2499 /* For PRLI, remainder of payload is PRLI parameter page */
2500 memset(pcmd
, 0, sizeof(PRLI
));
2502 npr
= (PRLI
*) pcmd
;
2505 * If our firmware version is 3.20 or later,
2506 * set the following bits for FC-TAPE support.
2508 if (vpd
->rev
.feaLevelHigh
>= 0x02) {
2509 npr
->ConfmComplAllowed
= 1;
2511 npr
->TaskRetryIdReq
= 1;
2514 npr
->acceptRspCode
= PRLI_REQ_EXECUTED
;
2515 npr
->estabImagePair
= 1;
2516 npr
->readXferRdyDis
= 1;
2517 npr
->ConfmComplAllowed
= 1;
2519 npr
->prliType
= PRLI_FCP_TYPE
;
2520 npr
->initiatorFunc
= 1;
2522 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
2523 "Issue ACC PRLI: did:x%x flg:x%x",
2524 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
2526 phba
->fc_stat
.elsXmitACC
++;
2527 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
2529 rc
= lpfc_sli_issue_iocb(phba
, pring
, elsiocb
, 0);
2530 if (rc
== IOCB_ERROR
) {
2531 lpfc_els_free_iocb(phba
, elsiocb
);
2538 lpfc_els_rsp_rnid_acc(struct lpfc_vport
*vport
, uint8_t format
,
2539 struct lpfc_iocbq
*oldiocb
, struct lpfc_nodelist
*ndlp
)
2541 struct lpfc_hba
*phba
= vport
->phba
;
2543 IOCB_t
*icmd
, *oldcmd
;
2544 struct lpfc_iocbq
*elsiocb
;
2545 struct lpfc_sli_ring
*pring
;
2546 struct lpfc_sli
*psli
;
2552 pring
= &psli
->ring
[LPFC_ELS_RING
];
2554 cmdsize
= sizeof(uint32_t) + sizeof(uint32_t)
2555 + (2 * sizeof(struct lpfc_name
));
2557 cmdsize
+= sizeof(RNID_TOP_DISC
);
2559 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
2560 ndlp
->nlp_DID
, ELS_CMD_ACC
);
2564 icmd
= &elsiocb
->iocb
;
2565 oldcmd
= &oldiocb
->iocb
;
2566 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri */
2568 /* Xmit RNID ACC response tag <ulpIoTag> */
2569 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
2570 "%d (%d):0132 Xmit RNID ACC response tag x%x "
2572 phba
->brd_no
, vport
->vpi
, elsiocb
->iotag
,
2573 elsiocb
->iocb
.ulpContext
);
2575 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
2577 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
2578 pcmd
+= sizeof(uint32_t);
2580 memset(pcmd
, 0, sizeof(RNID
));
2581 rn
= (RNID
*) (pcmd
);
2582 rn
->Format
= format
;
2583 rn
->CommonLen
= (2 * sizeof(struct lpfc_name
));
2584 memcpy(&rn
->portName
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
2585 memcpy(&rn
->nodeName
, &vport
->fc_nodename
, sizeof(struct lpfc_name
));
2588 rn
->SpecificLen
= 0;
2590 case RNID_TOPOLOGY_DISC
:
2591 rn
->SpecificLen
= sizeof(RNID_TOP_DISC
);
2592 memcpy(&rn
->un
.topologyDisc
.portName
,
2593 &vport
->fc_portname
, sizeof(struct lpfc_name
));
2594 rn
->un
.topologyDisc
.unitType
= RNID_HBA
;
2595 rn
->un
.topologyDisc
.physPort
= 0;
2596 rn
->un
.topologyDisc
.attachedNodes
= 0;
2600 rn
->SpecificLen
= 0;
2604 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
2605 "Issue ACC RNID: did:x%x flg:x%x",
2606 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
2608 phba
->fc_stat
.elsXmitACC
++;
2609 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
2611 elsiocb
->context1
= NULL
; /* Don't need ndlp for cmpl,
2612 * it could be freed */
2614 rc
= lpfc_sli_issue_iocb(phba
, pring
, elsiocb
, 0);
2615 if (rc
== IOCB_ERROR
) {
2616 lpfc_els_free_iocb(phba
, elsiocb
);
2623 lpfc_els_disc_adisc(struct lpfc_vport
*vport
)
2625 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2626 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
2629 /* go thru NPR nodes and issue any remaining ELS ADISCs */
2630 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
, nlp_listp
) {
2631 if (ndlp
->nlp_state
== NLP_STE_NPR_NODE
&&
2632 (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) != 0 &&
2633 (ndlp
->nlp_flag
& NLP_NPR_ADISC
) != 0) {
2634 spin_lock_irq(shost
->host_lock
);
2635 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
2636 spin_unlock_irq(shost
->host_lock
);
2637 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
2638 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_ADISC_ISSUE
);
2639 lpfc_issue_els_adisc(vport
, ndlp
, 0);
2641 vport
->num_disc_nodes
++;
2642 if (vport
->num_disc_nodes
>=
2643 vport
->phba
->cfg_discovery_threads
) {
2644 spin_lock_irq(shost
->host_lock
);
2645 vport
->fc_flag
|= FC_NLP_MORE
;
2646 spin_unlock_irq(shost
->host_lock
);
2651 if (sentadisc
== 0) {
2652 spin_lock_irq(shost
->host_lock
);
2653 vport
->fc_flag
&= ~FC_NLP_MORE
;
2654 spin_unlock_irq(shost
->host_lock
);
2660 lpfc_els_disc_plogi(struct lpfc_vport
*vport
)
2662 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2663 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
2666 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
2667 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
, nlp_listp
) {
2668 if (ndlp
->nlp_state
== NLP_STE_NPR_NODE
&&
2669 (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) != 0 &&
2670 (ndlp
->nlp_flag
& NLP_DELAY_TMO
) == 0 &&
2671 (ndlp
->nlp_flag
& NLP_NPR_ADISC
) == 0) {
2672 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
2673 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
2674 lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0);
2676 vport
->num_disc_nodes
++;
2677 if (vport
->num_disc_nodes
>=
2678 vport
->phba
->cfg_discovery_threads
) {
2679 spin_lock_irq(shost
->host_lock
);
2680 vport
->fc_flag
|= FC_NLP_MORE
;
2681 spin_unlock_irq(shost
->host_lock
);
2686 if (sentplogi
== 0) {
2687 spin_lock_irq(shost
->host_lock
);
2688 vport
->fc_flag
&= ~FC_NLP_MORE
;
2689 spin_unlock_irq(shost
->host_lock
);
2695 lpfc_els_flush_rscn(struct lpfc_vport
*vport
)
2697 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2698 struct lpfc_hba
*phba
= vport
->phba
;
2701 for (i
= 0; i
< vport
->fc_rscn_id_cnt
; i
++) {
2702 lpfc_in_buf_free(phba
, vport
->fc_rscn_id_list
[i
]);
2703 vport
->fc_rscn_id_list
[i
] = NULL
;
2705 spin_lock_irq(shost
->host_lock
);
2706 vport
->fc_rscn_id_cnt
= 0;
2707 vport
->fc_flag
&= ~(FC_RSCN_MODE
| FC_RSCN_DISCOVERY
);
2708 spin_unlock_irq(shost
->host_lock
);
2709 lpfc_can_disctmo(vport
);
2713 lpfc_rscn_payload_check(struct lpfc_vport
*vport
, uint32_t did
)
2718 uint32_t payload_len
, i
;
2719 struct lpfc_hba
*phba
= vport
->phba
;
2721 ns_did
.un
.word
= did
;
2723 /* Never match fabric nodes for RSCNs */
2724 if ((did
& Fabric_DID_MASK
) == Fabric_DID_MASK
)
2727 /* If we are doing a FULL RSCN rediscovery, match everything */
2728 if (vport
->fc_flag
& FC_RSCN_DISCOVERY
)
2731 for (i
= 0; i
< vport
->fc_rscn_id_cnt
; i
++) {
2732 lp
= vport
->fc_rscn_id_list
[i
]->virt
;
2733 payload_len
= be32_to_cpu(*lp
++ & ~ELS_CMD_MASK
);
2734 payload_len
-= sizeof(uint32_t); /* take off word 0 */
2735 while (payload_len
) {
2736 rscn_did
.un
.word
= be32_to_cpu(*lp
++);
2737 payload_len
-= sizeof(uint32_t);
2738 switch (rscn_did
.un
.b
.resv
) {
2739 case 0: /* Single N_Port ID effected */
2740 if (ns_did
.un
.word
== rscn_did
.un
.word
)
2743 case 1: /* Whole N_Port Area effected */
2744 if ((ns_did
.un
.b
.domain
== rscn_did
.un
.b
.domain
)
2745 && (ns_did
.un
.b
.area
== rscn_did
.un
.b
.area
))
2748 case 2: /* Whole N_Port Domain effected */
2749 if (ns_did
.un
.b
.domain
== rscn_did
.un
.b
.domain
)
2753 /* Unknown Identifier in RSCN node */
2754 lpfc_printf_log(phba
, KERN_ERR
, LOG_DISCOVERY
,
2755 "%d (%d):0217 Unknown "
2756 "Identifier in RSCN payload "
2758 phba
->brd_no
, vport
->vpi
,
2760 case 3: /* Whole Fabric effected */
2769 lpfc_rscn_recovery_check(struct lpfc_vport
*vport
)
2771 struct lpfc_nodelist
*ndlp
= NULL
;
2773 /* Look at all nodes effected by pending RSCNs and move
2774 * them to NPR state.
2777 list_for_each_entry(ndlp
, &vport
->fc_nodes
, nlp_listp
) {
2778 if (ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
||
2779 lpfc_rscn_payload_check(vport
, ndlp
->nlp_DID
) == 0)
2782 lpfc_disc_state_machine(vport
, ndlp
, NULL
,
2783 NLP_EVT_DEVICE_RECOVERY
);
2786 * Make sure NLP_DELAY_TMO is NOT running after a device
2789 if (ndlp
->nlp_flag
& NLP_DELAY_TMO
)
2790 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
2797 lpfc_els_rcv_rscn(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
2798 struct lpfc_nodelist
*ndlp
, uint8_t newnode
)
2800 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2801 struct lpfc_hba
*phba
= vport
->phba
;
2802 struct lpfc_dmabuf
*pcmd
;
2803 uint32_t *lp
, *datap
;
2805 uint32_t payload_len
, length
, nportid
, *cmd
;
2806 int rscn_cnt
= vport
->fc_rscn_id_cnt
;
2807 int rscn_id
= 0, hba_id
= 0;
2810 icmd
= &cmdiocb
->iocb
;
2811 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
2812 lp
= (uint32_t *) pcmd
->virt
;
2814 payload_len
= be32_to_cpu(*lp
++ & ~ELS_CMD_MASK
);
2815 payload_len
-= sizeof(uint32_t); /* take off word 0 */
2818 lpfc_printf_log(phba
, KERN_INFO
, LOG_DISCOVERY
,
2819 "%d (%d):0214 RSCN received Data: x%x x%x x%x x%x\n",
2820 phba
->brd_no
, vport
->vpi
, vport
->fc_flag
, payload_len
,
2823 for (i
= 0; i
< payload_len
/sizeof(uint32_t); i
++)
2824 fc_host_post_event(shost
, fc_get_event_number(),
2825 FCH_EVT_RSCN
, lp
[i
]);
2827 /* If we are about to begin discovery, just ACC the RSCN.
2828 * Discovery processing will satisfy it.
2830 if (vport
->port_state
<= LPFC_NS_QRY
) {
2831 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
2832 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
2833 ndlp
->nlp_DID
, vport
->port_state
, ndlp
->nlp_flag
);
2835 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
,
2840 /* If this RSCN just contains NPortIDs for other vports on this HBA,
2841 * just ACC and ignore it.
2843 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
2844 !(phba
->cfg_peer_port_login
)) {
2849 nportid
= ((be32_to_cpu(nportid
)) & Mask_DID
);
2850 i
-= sizeof(uint32_t);
2852 if (lpfc_find_vport_by_did(phba
, nportid
))
2855 if (rscn_id
== hba_id
) {
2856 /* ALL NPortIDs in RSCN are on HBA */
2857 lpfc_printf_log(phba
, KERN_INFO
, LOG_DISCOVERY
,
2858 "%d (%d):0214 Ignore RSCN Data: x%x x%x x%x x%x\n",
2859 phba
->brd_no
, vport
->vpi
, vport
->fc_flag
, payload_len
,
2862 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
2863 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
2864 ndlp
->nlp_DID
, vport
->port_state
,
2867 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
,
2868 ndlp
, NULL
, newnode
);
2873 /* If we are already processing an RSCN, save the received
2874 * RSCN payload buffer, cmdiocb->context2 to process later.
2876 if (vport
->fc_flag
& (FC_RSCN_MODE
| FC_NDISC_ACTIVE
)) {
2877 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
2878 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
2879 ndlp
->nlp_DID
, vport
->port_state
, ndlp
->nlp_flag
);
2881 vport
->fc_flag
|= FC_RSCN_DEFERRED
;
2882 if ((rscn_cnt
< FC_MAX_HOLD_RSCN
) &&
2883 !(vport
->fc_flag
& FC_RSCN_DISCOVERY
)) {
2884 spin_lock_irq(shost
->host_lock
);
2885 vport
->fc_flag
|= FC_RSCN_MODE
;
2886 spin_unlock_irq(shost
->host_lock
);
2888 cmd
= vport
->fc_rscn_id_list
[rscn_cnt
-1]->virt
;
2889 length
= be32_to_cpu(*cmd
& ~ELS_CMD_MASK
);
2892 (payload_len
+ length
<= LPFC_BPL_SIZE
)) {
2893 *cmd
&= ELS_CMD_MASK
;
2894 *cmd
|= be32_to_cpu(payload_len
+ length
);
2895 memcpy(((uint8_t *)cmd
) + length
, lp
,
2898 vport
->fc_rscn_id_list
[rscn_cnt
] = pcmd
;
2899 vport
->fc_rscn_id_cnt
++;
2900 /* If we zero, cmdiocb->context2, the calling
2901 * routine will not try to free it.
2903 cmdiocb
->context2
= NULL
;
2907 lpfc_printf_log(phba
, KERN_INFO
, LOG_DISCOVERY
,
2908 "%d (%d):0235 Deferred RSCN "
2909 "Data: x%x x%x x%x\n",
2910 phba
->brd_no
, vport
->vpi
,
2911 vport
->fc_rscn_id_cnt
, vport
->fc_flag
,
2914 spin_lock_irq(shost
->host_lock
);
2915 vport
->fc_flag
|= FC_RSCN_DISCOVERY
;
2916 spin_unlock_irq(shost
->host_lock
);
2917 /* ReDiscovery RSCN */
2918 lpfc_printf_log(phba
, KERN_INFO
, LOG_DISCOVERY
,
2919 "%d (%d):0234 ReDiscovery RSCN "
2920 "Data: x%x x%x x%x\n",
2921 phba
->brd_no
, vport
->vpi
,
2922 vport
->fc_rscn_id_cnt
, vport
->fc_flag
,
2926 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
,
2929 /* send RECOVERY event for ALL nodes that match RSCN payload */
2930 lpfc_rscn_recovery_check(vport
);
2931 vport
->fc_flag
&= ~FC_RSCN_DEFERRED
;
2935 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
2936 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
2937 ndlp
->nlp_DID
, vport
->port_state
, ndlp
->nlp_flag
);
2939 spin_lock_irq(shost
->host_lock
);
2940 vport
->fc_flag
|= FC_RSCN_MODE
;
2941 spin_unlock_irq(shost
->host_lock
);
2942 vport
->fc_rscn_id_list
[vport
->fc_rscn_id_cnt
++] = pcmd
;
2944 * If we zero, cmdiocb->context2, the calling routine will
2945 * not try to free it.
2947 cmdiocb
->context2
= NULL
;
2949 lpfc_set_disctmo(vport
);
2952 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
, newnode
);
2954 /* send RECOVERY event for ALL nodes that match RSCN payload */
2955 lpfc_rscn_recovery_check(vport
);
2957 return lpfc_els_handle_rscn(vport
);
2961 lpfc_els_handle_rscn(struct lpfc_vport
*vport
)
2963 struct lpfc_nodelist
*ndlp
;
2964 struct lpfc_hba
*phba
= vport
->phba
;
2966 /* Ignore RSCN if the port is being torn down. */
2967 if (vport
->load_flag
& FC_UNLOADING
) {
2968 lpfc_els_flush_rscn(vport
);
2972 /* Start timer for RSCN processing */
2973 lpfc_set_disctmo(vport
);
2975 /* RSCN processed */
2976 lpfc_printf_log(phba
, KERN_INFO
, LOG_DISCOVERY
,
2977 "%d (%d):0215 RSCN processed Data: x%x x%x x%x x%x\n",
2978 phba
->brd_no
, vport
->vpi
,
2979 vport
->fc_flag
, 0, vport
->fc_rscn_id_cnt
,
2982 /* To process RSCN, first compare RSCN data with NameServer */
2983 vport
->fc_ns_retry
= 0;
2984 ndlp
= lpfc_findnode_did(vport
, NameServer_DID
);
2985 if (ndlp
&& ndlp
->nlp_state
== NLP_STE_UNMAPPED_NODE
) {
2986 /* Good ndlp, issue CT Request to NameServer */
2987 if (lpfc_ns_cmd(vport
, SLI_CTNS_GID_FT
, 0, 0) == 0)
2988 /* Wait for NameServer query cmpl before we can
2992 /* If login to NameServer does not exist, issue one */
2993 /* Good status, issue PLOGI to NameServer */
2994 ndlp
= lpfc_findnode_did(vport
, NameServer_DID
);
2996 /* Wait for NameServer login cmpl before we can
3000 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
3002 lpfc_els_flush_rscn(vport
);
3005 lpfc_nlp_init(vport
, ndlp
, NameServer_DID
);
3006 ndlp
->nlp_type
|= NLP_FABRIC
;
3007 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
3008 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
3009 lpfc_issue_els_plogi(vport
, NameServer_DID
, 0);
3010 /* Wait for NameServer login cmpl before we can
3016 lpfc_els_flush_rscn(vport
);
3021 lpfc_els_rcv_flogi(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
3022 struct lpfc_nodelist
*ndlp
, uint8_t newnode
)
3024 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3025 struct lpfc_hba
*phba
= vport
->phba
;
3026 struct lpfc_dmabuf
*pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
3027 uint32_t *lp
= (uint32_t *) pcmd
->virt
;
3028 IOCB_t
*icmd
= &cmdiocb
->iocb
;
3029 struct serv_parm
*sp
;
3036 sp
= (struct serv_parm
*) lp
;
3038 /* FLOGI received */
3040 lpfc_set_disctmo(vport
);
3042 if (phba
->fc_topology
== TOPOLOGY_LOOP
) {
3043 /* We should never receive a FLOGI in loop mode, ignore it */
3044 did
= icmd
->un
.elsreq64
.remoteID
;
3046 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
3048 lpfc_printf_log(phba
, KERN_ERR
, LOG_ELS
,
3049 "%d (%d):0113 An FLOGI ELS command x%x was "
3050 "received from DID x%x in Loop Mode\n",
3051 phba
->brd_no
, vport
->vpi
, cmd
, did
);
3057 if ((lpfc_check_sparm(vport
, ndlp
, sp
, CLASS3
))) {
3058 /* For a FLOGI we accept, then if our portname is greater
3059 * then the remote portname we initiate Nport login.
3062 rc
= memcmp(&vport
->fc_portname
, &sp
->portName
,
3063 sizeof(struct lpfc_name
));
3066 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
3070 lpfc_linkdown(phba
);
3071 lpfc_init_link(phba
, mbox
,
3073 phba
->cfg_link_speed
);
3074 mbox
->mb
.un
.varInitLnk
.lipsr_AL_PA
= 0;
3075 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
3076 mbox
->vport
= vport
;
3077 rc
= lpfc_sli_issue_mbox
3078 (phba
, mbox
, (MBX_NOWAIT
| MBX_STOP_IOCB
));
3079 lpfc_set_loopback_flag(phba
);
3080 if (rc
== MBX_NOT_FINISHED
) {
3081 mempool_free(mbox
, phba
->mbox_mem_pool
);
3084 } else if (rc
> 0) { /* greater than */
3085 spin_lock_irq(shost
->host_lock
);
3086 vport
->fc_flag
|= FC_PT2PT_PLOGI
;
3087 spin_unlock_irq(shost
->host_lock
);
3089 spin_lock_irq(shost
->host_lock
);
3090 vport
->fc_flag
|= FC_PT2PT
;
3091 vport
->fc_flag
&= ~(FC_FABRIC
| FC_PUBLIC_LOOP
);
3092 spin_unlock_irq(shost
->host_lock
);
3094 /* Reject this request because invalid parameters */
3095 stat
.un
.b
.lsRjtRsvd0
= 0;
3096 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
3097 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_SPARM_OPTIONS
;
3098 stat
.un
.b
.vendorUnique
= 0;
3099 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
,
3105 lpfc_els_rsp_acc(vport
, ELS_CMD_PLOGI
, cmdiocb
, ndlp
, NULL
, newnode
);
3111 lpfc_els_rcv_rnid(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
3112 struct lpfc_nodelist
*ndlp
)
3114 struct lpfc_dmabuf
*pcmd
;
3121 icmd
= &cmdiocb
->iocb
;
3122 did
= icmd
->un
.elsreq64
.remoteID
;
3123 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
3124 lp
= (uint32_t *) pcmd
->virt
;
3131 switch (rn
->Format
) {
3133 case RNID_TOPOLOGY_DISC
:
3135 lpfc_els_rsp_rnid_acc(vport
, rn
->Format
, cmdiocb
, ndlp
);
3138 /* Reject this request because format not supported */
3139 stat
.un
.b
.lsRjtRsvd0
= 0;
3140 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
3141 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CANT_GIVE_DATA
;
3142 stat
.un
.b
.vendorUnique
= 0;
3143 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
,
3150 lpfc_els_rcv_lirr(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
3151 struct lpfc_nodelist
*ndlp
)
3155 /* For now, unconditionally reject this command */
3156 stat
.un
.b
.lsRjtRsvd0
= 0;
3157 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
3158 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CANT_GIVE_DATA
;
3159 stat
.un
.b
.vendorUnique
= 0;
3160 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
3165 lpfc_els_rsp_rps_acc(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
3167 struct lpfc_sli
*psli
= &phba
->sli
;
3168 struct lpfc_sli_ring
*pring
= &psli
->ring
[LPFC_ELS_RING
];
3173 struct lpfc_iocbq
*elsiocb
;
3174 struct lpfc_nodelist
*ndlp
;
3175 uint16_t xri
, status
;
3180 ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
3181 xri
= (uint16_t) ((unsigned long)(pmb
->context1
));
3182 pmb
->context1
= NULL
;
3183 pmb
->context2
= NULL
;
3185 if (mb
->mbxStatus
) {
3186 mempool_free(pmb
, phba
->mbox_mem_pool
);
3190 cmdsize
= sizeof(RPS_RSP
) + sizeof(uint32_t);
3191 mempool_free(pmb
, phba
->mbox_mem_pool
);
3192 elsiocb
= lpfc_prep_els_iocb(phba
->pport
, 0, cmdsize
,
3193 lpfc_max_els_tries
, ndlp
,
3194 ndlp
->nlp_DID
, ELS_CMD_ACC
);
3199 icmd
= &elsiocb
->iocb
;
3200 icmd
->ulpContext
= xri
;
3202 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
3203 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
3204 pcmd
+= sizeof(uint32_t); /* Skip past command */
3205 rps_rsp
= (RPS_RSP
*)pcmd
;
3207 if (phba
->fc_topology
!= TOPOLOGY_LOOP
)
3211 if (phba
->pport
->fc_flag
& FC_FABRIC
)
3215 rps_rsp
->portStatus
= be16_to_cpu(status
);
3216 rps_rsp
->linkFailureCnt
= be32_to_cpu(mb
->un
.varRdLnk
.linkFailureCnt
);
3217 rps_rsp
->lossSyncCnt
= be32_to_cpu(mb
->un
.varRdLnk
.lossSyncCnt
);
3218 rps_rsp
->lossSignalCnt
= be32_to_cpu(mb
->un
.varRdLnk
.lossSignalCnt
);
3219 rps_rsp
->primSeqErrCnt
= be32_to_cpu(mb
->un
.varRdLnk
.primSeqErrCnt
);
3220 rps_rsp
->invalidXmitWord
= be32_to_cpu(mb
->un
.varRdLnk
.invalidXmitWord
);
3221 rps_rsp
->crcCnt
= be32_to_cpu(mb
->un
.varRdLnk
.crcCnt
);
3223 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
3224 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
3225 "%d (%d):0118 Xmit ELS RPS ACC response tag x%x "
3226 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
3228 phba
->brd_no
, ndlp
->vport
->vpi
, elsiocb
->iotag
,
3229 elsiocb
->iocb
.ulpContext
, ndlp
->nlp_DID
,
3230 ndlp
->nlp_flag
, ndlp
->nlp_state
, ndlp
->nlp_rpi
);
3232 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
3233 phba
->fc_stat
.elsXmitACC
++;
3234 if (lpfc_sli_issue_iocb(phba
, pring
, elsiocb
, 0) == IOCB_ERROR
)
3235 lpfc_els_free_iocb(phba
, elsiocb
);
3240 lpfc_els_rcv_rps(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
3241 struct lpfc_nodelist
*ndlp
)
3243 struct lpfc_hba
*phba
= vport
->phba
;
3247 struct lpfc_dmabuf
*pcmd
;
3251 if ((ndlp
->nlp_state
!= NLP_STE_UNMAPPED_NODE
) &&
3252 (ndlp
->nlp_state
!= NLP_STE_MAPPED_NODE
)) {
3253 stat
.un
.b
.lsRjtRsvd0
= 0;
3254 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
3255 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CANT_GIVE_DATA
;
3256 stat
.un
.b
.vendorUnique
= 0;
3257 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
,
3261 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
3262 lp
= (uint32_t *) pcmd
->virt
;
3263 flag
= (be32_to_cpu(*lp
++) & 0xf);
3267 ((flag
== 1) && (be32_to_cpu(rps
->un
.portNum
) == 0)) ||
3268 ((flag
== 2) && (memcmp(&rps
->un
.portName
, &vport
->fc_portname
,
3269 sizeof(struct lpfc_name
)) == 0))) {
3271 printk("Fix me....\n");
3273 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_ATOMIC
);
3275 lpfc_read_lnk_stat(phba
, mbox
);
3277 (void *)((unsigned long) cmdiocb
->iocb
.ulpContext
);
3278 mbox
->context2
= lpfc_nlp_get(ndlp
);
3279 mbox
->vport
= vport
;
3280 mbox
->mbox_cmpl
= lpfc_els_rsp_rps_acc
;
3281 if (lpfc_sli_issue_mbox (phba
, mbox
,
3282 (MBX_NOWAIT
| MBX_STOP_IOCB
)) != MBX_NOT_FINISHED
)
3283 /* Mbox completion will send ELS Response */
3287 mempool_free(mbox
, phba
->mbox_mem_pool
);
3290 stat
.un
.b
.lsRjtRsvd0
= 0;
3291 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
3292 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CANT_GIVE_DATA
;
3293 stat
.un
.b
.vendorUnique
= 0;
3294 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
3299 lpfc_els_rsp_rpl_acc(struct lpfc_vport
*vport
, uint16_t cmdsize
,
3300 struct lpfc_iocbq
*oldiocb
, struct lpfc_nodelist
*ndlp
)
3302 struct lpfc_hba
*phba
= vport
->phba
;
3303 IOCB_t
*icmd
, *oldcmd
;
3305 struct lpfc_iocbq
*elsiocb
;
3306 struct lpfc_sli
*psli
= &phba
->sli
;
3307 struct lpfc_sli_ring
*pring
= &psli
->ring
[LPFC_ELS_RING
];
3310 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
3311 ndlp
->nlp_DID
, ELS_CMD_ACC
);
3316 icmd
= &elsiocb
->iocb
;
3317 oldcmd
= &oldiocb
->iocb
;
3318 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri */
3320 pcmd
= (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
3321 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
3322 pcmd
+= sizeof(uint16_t);
3323 *((uint16_t *)(pcmd
)) = be16_to_cpu(cmdsize
);
3324 pcmd
+= sizeof(uint16_t);
3326 /* Setup the RPL ACC payload */
3327 rpl_rsp
.listLen
= be32_to_cpu(1);
3329 rpl_rsp
.port_num_blk
.portNum
= 0;
3330 rpl_rsp
.port_num_blk
.portID
= be32_to_cpu(vport
->fc_myDID
);
3331 memcpy(&rpl_rsp
.port_num_blk
.portName
, &vport
->fc_portname
,
3332 sizeof(struct lpfc_name
));
3334 memcpy(pcmd
, &rpl_rsp
, cmdsize
- sizeof(uint32_t));
3337 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
3338 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
3339 "%d (%d):0120 Xmit ELS RPL ACC response tag x%x "
3340 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
3342 phba
->brd_no
, vport
->vpi
, elsiocb
->iotag
,
3343 elsiocb
->iocb
.ulpContext
, ndlp
->nlp_DID
,
3344 ndlp
->nlp_flag
, ndlp
->nlp_state
, ndlp
->nlp_rpi
);
3346 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
3348 phba
->fc_stat
.elsXmitACC
++;
3349 if (lpfc_sli_issue_iocb(phba
, pring
, elsiocb
, 0) == IOCB_ERROR
) {
3350 lpfc_els_free_iocb(phba
, elsiocb
);
3357 lpfc_els_rcv_rpl(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
3358 struct lpfc_nodelist
*ndlp
)
3360 struct lpfc_dmabuf
*pcmd
;
3367 if ((ndlp
->nlp_state
!= NLP_STE_UNMAPPED_NODE
) &&
3368 (ndlp
->nlp_state
!= NLP_STE_MAPPED_NODE
)) {
3369 stat
.un
.b
.lsRjtRsvd0
= 0;
3370 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
3371 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CANT_GIVE_DATA
;
3372 stat
.un
.b
.vendorUnique
= 0;
3373 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
,
3377 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
3378 lp
= (uint32_t *) pcmd
->virt
;
3379 rpl
= (RPL
*) (lp
+ 1);
3381 maxsize
= be32_to_cpu(rpl
->maxsize
);
3383 /* We support only one port */
3384 if ((rpl
->index
== 0) &&
3386 ((maxsize
* sizeof(uint32_t)) >= sizeof(RPL_RSP
)))) {
3387 cmdsize
= sizeof(uint32_t) + sizeof(RPL_RSP
);
3389 cmdsize
= sizeof(uint32_t) + maxsize
* sizeof(uint32_t);
3391 lpfc_els_rsp_rpl_acc(vport
, cmdsize
, cmdiocb
, ndlp
);
3397 lpfc_els_rcv_farp(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
3398 struct lpfc_nodelist
*ndlp
)
3400 struct lpfc_hba
*phba
= vport
->phba
;
3401 struct lpfc_dmabuf
*pcmd
;
3405 uint32_t cmd
, cnt
, did
;
3407 icmd
= &cmdiocb
->iocb
;
3408 did
= icmd
->un
.elsreq64
.remoteID
;
3409 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
3410 lp
= (uint32_t *) pcmd
->virt
;
3415 /* FARP-REQ received from DID <did> */
3416 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
3417 "%d (%d):0601 FARP-REQ received from DID x%x\n",
3418 phba
->brd_no
, vport
->vpi
, did
);
3420 /* We will only support match on WWPN or WWNN */
3421 if (fp
->Mflags
& ~(FARP_MATCH_NODE
| FARP_MATCH_PORT
)) {
3426 /* If this FARP command is searching for my portname */
3427 if (fp
->Mflags
& FARP_MATCH_PORT
) {
3428 if (memcmp(&fp
->RportName
, &vport
->fc_portname
,
3429 sizeof(struct lpfc_name
)) == 0)
3433 /* If this FARP command is searching for my nodename */
3434 if (fp
->Mflags
& FARP_MATCH_NODE
) {
3435 if (memcmp(&fp
->RnodeName
, &vport
->fc_nodename
,
3436 sizeof(struct lpfc_name
)) == 0)
3441 if ((ndlp
->nlp_state
== NLP_STE_UNMAPPED_NODE
) ||
3442 (ndlp
->nlp_state
== NLP_STE_MAPPED_NODE
)) {
3443 /* Log back into the node before sending the FARP. */
3444 if (fp
->Rflags
& FARP_REQUEST_PLOGI
) {
3445 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
3446 lpfc_nlp_set_state(vport
, ndlp
,
3447 NLP_STE_PLOGI_ISSUE
);
3448 lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0);
3451 /* Send a FARP response to that node */
3452 if (fp
->Rflags
& FARP_REQUEST_FARPR
)
3453 lpfc_issue_els_farpr(vport
, did
, 0);
3460 lpfc_els_rcv_farpr(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
3461 struct lpfc_nodelist
*ndlp
)
3463 struct lpfc_dmabuf
*pcmd
;
3467 struct lpfc_hba
*phba
= vport
->phba
;
3469 icmd
= &cmdiocb
->iocb
;
3470 did
= icmd
->un
.elsreq64
.remoteID
;
3471 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
3472 lp
= (uint32_t *) pcmd
->virt
;
3475 /* FARP-RSP received from DID <did> */
3476 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
3477 "%d (%d):0600 FARP-RSP received from DID x%x\n",
3478 phba
->brd_no
, vport
->vpi
, did
);
3479 /* ACCEPT the Farp resp request */
3480 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
, 0);
3486 lpfc_els_rcv_fan(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
3487 struct lpfc_nodelist
*fan_ndlp
)
3489 struct lpfc_dmabuf
*pcmd
;
3494 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
3495 struct lpfc_hba
*phba
= vport
->phba
;
3498 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
3499 "%d (%d):0265 FAN received\n",
3500 phba
->brd_no
, vport
->vpi
);
3502 icmd
= &cmdiocb
->iocb
;
3503 did
= icmd
->un
.elsreq64
.remoteID
;
3504 pcmd
= (struct lpfc_dmabuf
*)cmdiocb
->context2
;
3505 lp
= (uint32_t *)pcmd
->virt
;
3510 /* FAN received; Fan does not have a reply sequence */
3512 if (phba
->pport
->port_state
== LPFC_LOCAL_CFG_LINK
) {
3513 if ((memcmp(&phba
->fc_fabparam
.nodeName
, &fp
->FnodeName
,
3514 sizeof(struct lpfc_name
)) != 0) ||
3515 (memcmp(&phba
->fc_fabparam
.portName
, &fp
->FportName
,
3516 sizeof(struct lpfc_name
)) != 0)) {
3518 * This node has switched fabrics. FLOGI is required
3519 * Clean up the old rpi's
3522 list_for_each_entry_safe(ndlp
, next_ndlp
,
3523 &vport
->fc_nodes
, nlp_listp
) {
3524 if (ndlp
->nlp_state
!= NLP_STE_NPR_NODE
)
3526 if (ndlp
->nlp_type
& NLP_FABRIC
) {
3528 * Clean up old Fabric, Nameserver and
3529 * other NLP_FABRIC logins
3531 lpfc_drop_node(vport
, ndlp
);
3532 } else if (!(ndlp
->nlp_flag
& NLP_NPR_ADISC
)) {
3533 /* Fail outstanding I/O now since this
3534 * device is marked for PLOGI
3536 lpfc_unreg_rpi(vport
, ndlp
);
3540 vport
->port_state
= LPFC_FLOGI
;
3541 lpfc_set_disctmo(vport
);
3542 lpfc_initial_flogi(vport
);
3545 /* Discovery not needed,
3546 * move the nodes to their original state.
3548 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
,
3550 if (ndlp
->nlp_state
!= NLP_STE_NPR_NODE
)
3553 switch (ndlp
->nlp_prev_state
) {
3554 case NLP_STE_UNMAPPED_NODE
:
3555 ndlp
->nlp_prev_state
= NLP_STE_NPR_NODE
;
3556 lpfc_nlp_set_state(vport
, ndlp
,
3557 NLP_STE_UNMAPPED_NODE
);
3560 case NLP_STE_MAPPED_NODE
:
3561 ndlp
->nlp_prev_state
= NLP_STE_NPR_NODE
;
3562 lpfc_nlp_set_state(vport
, ndlp
,
3563 NLP_STE_MAPPED_NODE
);
3571 /* Start discovery - this should just do CLEAR_LA */
3572 lpfc_disc_start(vport
);
3578 lpfc_els_timeout(unsigned long ptr
)
3580 struct lpfc_vport
*vport
= (struct lpfc_vport
*) ptr
;
3581 struct lpfc_hba
*phba
= vport
->phba
;
3582 unsigned long iflag
;
3584 spin_lock_irqsave(&vport
->work_port_lock
, iflag
);
3585 if ((vport
->work_port_events
& WORKER_ELS_TMO
) == 0) {
3586 vport
->work_port_events
|= WORKER_ELS_TMO
;
3587 spin_unlock_irqrestore(&vport
->work_port_lock
, iflag
);
3589 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3590 if (phba
->work_wait
)
3591 lpfc_worker_wake_up(phba
);
3592 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3595 spin_unlock_irqrestore(&vport
->work_port_lock
, iflag
);
3600 lpfc_els_timeout_handler(struct lpfc_vport
*vport
)
3602 struct lpfc_hba
*phba
= vport
->phba
;
3603 struct lpfc_sli_ring
*pring
;
3604 struct lpfc_iocbq
*tmp_iocb
, *piocb
;
3606 struct lpfc_dmabuf
*pcmd
;
3607 uint32_t els_command
= 0;
3609 uint32_t remote_ID
= 0xffffffff;
3611 /* If the timer is already canceled do nothing */
3612 if ((vport
->work_port_events
& WORKER_ELS_TMO
) == 0) {
3615 spin_lock_irq(&phba
->hbalock
);
3616 timeout
= (uint32_t)(phba
->fc_ratov
<< 1);
3618 pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
3620 list_for_each_entry_safe(piocb
, tmp_iocb
, &pring
->txcmplq
, list
) {
3623 if ((piocb
->iocb_flag
& LPFC_IO_LIBDFC
) != 0 ||
3624 piocb
->iocb
.ulpCommand
== CMD_ABORT_XRI_CN
||
3625 piocb
->iocb
.ulpCommand
== CMD_CLOSE_XRI_CN
)
3628 if (piocb
->vport
!= vport
)
3631 pcmd
= (struct lpfc_dmabuf
*) piocb
->context2
;
3633 els_command
= *(uint32_t *) (pcmd
->virt
);
3635 if (els_command
== ELS_CMD_FARP
||
3636 els_command
== ELS_CMD_FARPR
||
3637 els_command
== ELS_CMD_FDISC
)
3640 if (vport
!= piocb
->vport
)
3643 if (piocb
->drvrTimeout
> 0) {
3644 if (piocb
->drvrTimeout
>= timeout
)
3645 piocb
->drvrTimeout
-= timeout
;
3647 piocb
->drvrTimeout
= 0;
3651 remote_ID
= 0xffffffff;
3652 if (cmd
->ulpCommand
!= CMD_GEN_REQUEST64_CR
)
3653 remote_ID
= cmd
->un
.elsreq64
.remoteID
;
3655 struct lpfc_nodelist
*ndlp
;
3656 ndlp
= __lpfc_findnode_rpi(vport
, cmd
->ulpContext
);
3658 remote_ID
= ndlp
->nlp_DID
;
3661 lpfc_printf_log(phba
, KERN_ERR
, LOG_ELS
,
3662 "%d (%d):0127 ELS timeout Data: x%x x%x x%x "
3664 phba
->brd_no
, vport
->vpi
, els_command
,
3665 remote_ID
, cmd
->ulpCommand
, cmd
->ulpIoTag
);
3667 lpfc_sli_issue_abort_iotag(phba
, pring
, piocb
);
3669 spin_unlock_irq(&phba
->hbalock
);
3671 if (phba
->sli
.ring
[LPFC_ELS_RING
].txcmplq_cnt
)
3672 mod_timer(&vport
->els_tmofunc
, jiffies
+ HZ
* timeout
);
3676 lpfc_els_flush_cmd(struct lpfc_vport
*vport
)
3678 LIST_HEAD(completions
);
3679 struct lpfc_hba
*phba
= vport
->phba
;
3680 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
3681 struct lpfc_iocbq
*tmp_iocb
, *piocb
;
3684 lpfc_fabric_abort_vport(vport
);
3686 spin_lock_irq(&phba
->hbalock
);
3687 list_for_each_entry_safe(piocb
, tmp_iocb
, &pring
->txq
, list
) {
3690 if (piocb
->iocb_flag
& LPFC_IO_LIBDFC
) {
3694 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
3695 if (cmd
->ulpCommand
== CMD_QUE_RING_BUF_CN
||
3696 cmd
->ulpCommand
== CMD_QUE_RING_BUF64_CN
||
3697 cmd
->ulpCommand
== CMD_CLOSE_XRI_CN
||
3698 cmd
->ulpCommand
== CMD_ABORT_XRI_CN
)
3701 if (piocb
->vport
!= vport
)
3704 list_move_tail(&piocb
->list
, &completions
);
3708 list_for_each_entry_safe(piocb
, tmp_iocb
, &pring
->txcmplq
, list
) {
3709 if (piocb
->iocb_flag
& LPFC_IO_LIBDFC
) {
3713 if (piocb
->vport
!= vport
)
3716 lpfc_sli_issue_abort_iotag(phba
, pring
, piocb
);
3718 spin_unlock_irq(&phba
->hbalock
);
3720 while (!list_empty(&completions
)) {
3721 piocb
= list_get_first(&completions
, struct lpfc_iocbq
, list
);
3723 list_del_init(&piocb
->list
);
3725 if (!piocb
->iocb_cmpl
)
3726 lpfc_sli_release_iocbq(phba
, piocb
);
3728 cmd
->ulpStatus
= IOSTAT_LOCAL_REJECT
;
3729 cmd
->un
.ulpWord
[4] = IOERR_SLI_ABORTED
;
3730 (piocb
->iocb_cmpl
) (phba
, piocb
, piocb
);
3738 lpfc_els_flush_all_cmd(struct lpfc_hba
*phba
)
3740 LIST_HEAD(completions
);
3741 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
3742 struct lpfc_iocbq
*tmp_iocb
, *piocb
;
3745 lpfc_fabric_abort_hba(phba
);
3746 spin_lock_irq(&phba
->hbalock
);
3747 list_for_each_entry_safe(piocb
, tmp_iocb
, &pring
->txq
, list
) {
3749 if (piocb
->iocb_flag
& LPFC_IO_LIBDFC
)
3751 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
3752 if (cmd
->ulpCommand
== CMD_QUE_RING_BUF_CN
||
3753 cmd
->ulpCommand
== CMD_QUE_RING_BUF64_CN
||
3754 cmd
->ulpCommand
== CMD_CLOSE_XRI_CN
||
3755 cmd
->ulpCommand
== CMD_ABORT_XRI_CN
)
3757 list_move_tail(&piocb
->list
, &completions
);
3760 list_for_each_entry_safe(piocb
, tmp_iocb
, &pring
->txcmplq
, list
) {
3761 if (piocb
->iocb_flag
& LPFC_IO_LIBDFC
)
3763 lpfc_sli_issue_abort_iotag(phba
, pring
, piocb
);
3765 spin_unlock_irq(&phba
->hbalock
);
3766 while (!list_empty(&completions
)) {
3767 piocb
= list_get_first(&completions
, struct lpfc_iocbq
, list
);
3769 list_del_init(&piocb
->list
);
3770 if (!piocb
->iocb_cmpl
)
3771 lpfc_sli_release_iocbq(phba
, piocb
);
3773 cmd
->ulpStatus
= IOSTAT_LOCAL_REJECT
;
3774 cmd
->un
.ulpWord
[4] = IOERR_SLI_ABORTED
;
3775 (piocb
->iocb_cmpl
) (phba
, piocb
, piocb
);
3782 lpfc_els_unsol_buffer(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
3783 struct lpfc_vport
*vport
, struct lpfc_iocbq
*elsiocb
)
3785 struct lpfc_nodelist
*ndlp
;
3788 uint32_t cmd
, did
, newnode
, rjt_err
= 0;
3789 IOCB_t
*icmd
= &elsiocb
->iocb
;
3791 if (vport
== NULL
|| elsiocb
->context2
== NULL
)
3795 payload
= ((struct lpfc_dmabuf
*)elsiocb
->context2
)->virt
;
3797 if ((phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) == 0)
3798 lpfc_post_buffer(phba
, pring
, 1, 1);
3800 did
= icmd
->un
.rcvels
.remoteID
;
3801 if (icmd
->ulpStatus
) {
3802 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
3803 "RCV Unsol ELS: status:x%x/x%x did:x%x",
3804 icmd
->ulpStatus
, icmd
->un
.ulpWord
[4], did
);
3808 /* Check to see if link went down during discovery */
3809 if (lpfc_els_chk_latt(vport
))
3812 /* Ignore traffic recevied during vport shutdown. */
3813 if (vport
->load_flag
& FC_UNLOADING
)
3816 ndlp
= lpfc_findnode_did(vport
, did
);
3818 /* Cannot find existing Fabric ndlp, so allocate a new one */
3819 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
3823 lpfc_nlp_init(vport
, ndlp
, did
);
3825 if ((did
& Fabric_DID_MASK
) == Fabric_DID_MASK
) {
3826 ndlp
->nlp_type
|= NLP_FABRIC
;
3828 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
3831 phba
->fc_stat
.elsRcvFrame
++;
3832 if (elsiocb
->context1
)
3833 lpfc_nlp_put(elsiocb
->context1
);
3834 elsiocb
->context1
= lpfc_nlp_get(ndlp
);
3835 elsiocb
->vport
= vport
;
3837 if ((cmd
& ELS_CMD_MASK
) == ELS_CMD_RSCN
) {
3838 cmd
&= ELS_CMD_MASK
;
3840 /* ELS command <elsCmd> received from NPORT <did> */
3841 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
3842 "%d (%d):0112 ELS command x%x received from NPORT x%x "
3843 "Data: x%x\n", phba
->brd_no
, vport
->vpi
, cmd
, did
,
3848 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
3849 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
3850 did
, vport
->port_state
, ndlp
->nlp_flag
);
3852 phba
->fc_stat
.elsRcvPLOGI
++;
3853 ndlp
= lpfc_plogi_confirm_nport(phba
, payload
, ndlp
);
3855 if (vport
->port_state
< LPFC_DISC_AUTH
) {
3856 rjt_err
= LSRJT_UNABLE_TPC
;
3859 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
,
3864 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
3865 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
3866 did
, vport
->port_state
, ndlp
->nlp_flag
);
3868 phba
->fc_stat
.elsRcvFLOGI
++;
3869 lpfc_els_rcv_flogi(vport
, elsiocb
, ndlp
, newnode
);
3871 lpfc_drop_node(vport
, ndlp
);
3874 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
3875 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
3876 did
, vport
->port_state
, ndlp
->nlp_flag
);
3878 phba
->fc_stat
.elsRcvLOGO
++;
3879 if (vport
->port_state
< LPFC_DISC_AUTH
) {
3880 rjt_err
= LSRJT_UNABLE_TPC
;
3883 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
, NLP_EVT_RCV_LOGO
);
3886 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
3887 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
3888 did
, vport
->port_state
, ndlp
->nlp_flag
);
3890 phba
->fc_stat
.elsRcvPRLO
++;
3891 if (vport
->port_state
< LPFC_DISC_AUTH
) {
3892 rjt_err
= LSRJT_UNABLE_TPC
;
3895 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
, NLP_EVT_RCV_PRLO
);
3898 phba
->fc_stat
.elsRcvRSCN
++;
3899 lpfc_els_rcv_rscn(vport
, elsiocb
, ndlp
, newnode
);
3901 lpfc_drop_node(vport
, ndlp
);
3904 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
3905 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
3906 did
, vport
->port_state
, ndlp
->nlp_flag
);
3908 phba
->fc_stat
.elsRcvADISC
++;
3909 if (vport
->port_state
< LPFC_DISC_AUTH
) {
3910 rjt_err
= LSRJT_UNABLE_TPC
;
3913 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
,
3917 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
3918 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
3919 did
, vport
->port_state
, ndlp
->nlp_flag
);
3921 phba
->fc_stat
.elsRcvPDISC
++;
3922 if (vport
->port_state
< LPFC_DISC_AUTH
) {
3923 rjt_err
= LSRJT_UNABLE_TPC
;
3926 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
,
3930 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
3931 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
3932 did
, vport
->port_state
, ndlp
->nlp_flag
);
3934 phba
->fc_stat
.elsRcvFARPR
++;
3935 lpfc_els_rcv_farpr(vport
, elsiocb
, ndlp
);
3938 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
3939 "RCV FARP: did:x%x/ste:x%x flg:x%x",
3940 did
, vport
->port_state
, ndlp
->nlp_flag
);
3942 phba
->fc_stat
.elsRcvFARP
++;
3943 lpfc_els_rcv_farp(vport
, elsiocb
, ndlp
);
3946 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
3947 "RCV FAN: did:x%x/ste:x%x flg:x%x",
3948 did
, vport
->port_state
, ndlp
->nlp_flag
);
3950 phba
->fc_stat
.elsRcvFAN
++;
3951 lpfc_els_rcv_fan(vport
, elsiocb
, ndlp
);
3954 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
3955 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
3956 did
, vport
->port_state
, ndlp
->nlp_flag
);
3958 phba
->fc_stat
.elsRcvPRLI
++;
3959 if (vport
->port_state
< LPFC_DISC_AUTH
) {
3960 rjt_err
= LSRJT_UNABLE_TPC
;
3963 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
, NLP_EVT_RCV_PRLI
);
3966 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
3967 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
3968 did
, vport
->port_state
, ndlp
->nlp_flag
);
3970 phba
->fc_stat
.elsRcvLIRR
++;
3971 lpfc_els_rcv_lirr(vport
, elsiocb
, ndlp
);
3973 lpfc_drop_node(vport
, ndlp
);
3976 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
3977 "RCV RPS: did:x%x/ste:x%x flg:x%x",
3978 did
, vport
->port_state
, ndlp
->nlp_flag
);
3980 phba
->fc_stat
.elsRcvRPS
++;
3981 lpfc_els_rcv_rps(vport
, elsiocb
, ndlp
);
3983 lpfc_drop_node(vport
, ndlp
);
3986 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
3987 "RCV RPL: did:x%x/ste:x%x flg:x%x",
3988 did
, vport
->port_state
, ndlp
->nlp_flag
);
3990 phba
->fc_stat
.elsRcvRPL
++;
3991 lpfc_els_rcv_rpl(vport
, elsiocb
, ndlp
);
3993 lpfc_drop_node(vport
, ndlp
);
3996 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
3997 "RCV RNID: did:x%x/ste:x%x flg:x%x",
3998 did
, vport
->port_state
, ndlp
->nlp_flag
);
4000 phba
->fc_stat
.elsRcvRNID
++;
4001 lpfc_els_rcv_rnid(vport
, elsiocb
, ndlp
);
4003 lpfc_drop_node(vport
, ndlp
);
4006 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
4007 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
4008 cmd
, did
, vport
->port_state
);
4010 /* Unsupported ELS command, reject */
4011 rjt_err
= LSRJT_INVALID_CMD
;
4013 /* Unknown ELS command <elsCmd> received from NPORT <did> */
4014 lpfc_printf_log(phba
, KERN_ERR
, LOG_ELS
,
4015 "%d (%d):0115 Unknown ELS command x%x "
4016 "received from NPORT x%x\n",
4017 phba
->brd_no
, vport
->vpi
, cmd
, did
);
4019 lpfc_drop_node(vport
, ndlp
);
4023 /* check if need to LS_RJT received ELS cmd */
4025 memset(&stat
, 0, sizeof(stat
));
4026 stat
.un
.b
.lsRjtRsnCode
= rjt_err
;
4027 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_NOTHING_MORE
;
4028 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, elsiocb
, ndlp
,
4031 lpfc_drop_node(vport
, ndlp
);
4037 lpfc_printf_log(phba
, KERN_ERR
, LOG_ELS
,
4038 "%d (%d):0111 Dropping received ELS cmd "
4039 "Data: x%x x%x x%x\n",
4040 phba
->brd_no
, vport
? vport
->vpi
: 0xffff,
4041 icmd
->ulpStatus
, icmd
->un
.ulpWord
[4],
4043 phba
->fc_stat
.elsRcvDrop
++;
4046 static struct lpfc_vport
*
4047 lpfc_find_vport_by_vpid(struct lpfc_hba
*phba
, uint16_t vpi
)
4049 struct lpfc_vport
*vport
;
4050 unsigned long flags
;
4052 spin_lock_irqsave(&phba
->hbalock
, flags
);
4053 list_for_each_entry(vport
, &phba
->port_list
, listentry
) {
4054 if (vport
->vpi
== vpi
) {
4055 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
4059 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
4064 lpfc_els_unsol_event(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
4065 struct lpfc_iocbq
*elsiocb
)
4067 struct lpfc_vport
*vport
= phba
->pport
;
4068 IOCB_t
*icmd
= &elsiocb
->iocb
;
4070 struct lpfc_dmabuf
*bdeBuf1
= elsiocb
->context2
;
4071 struct lpfc_dmabuf
*bdeBuf2
= elsiocb
->context3
;
4073 elsiocb
->context2
= NULL
;
4074 elsiocb
->context3
= NULL
;
4076 if (icmd
->ulpStatus
== IOSTAT_NEED_BUFFER
) {
4077 lpfc_sli_hbqbuf_add_hbqs(phba
, LPFC_ELS_HBQ
);
4078 } else if (icmd
->ulpStatus
== IOSTAT_LOCAL_REJECT
&&
4079 (icmd
->un
.ulpWord
[4] & 0xff) == IOERR_RCV_BUFFER_WAITING
) {
4080 phba
->fc_stat
.NoRcvBuf
++;
4081 /* Not enough posted buffers; Try posting more buffers */
4082 if (!(phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
))
4083 lpfc_post_buffer(phba
, pring
, 0, 1);
4087 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
4088 (icmd
->ulpCommand
== CMD_IOCB_RCV_ELS64_CX
||
4089 icmd
->ulpCommand
== CMD_IOCB_RCV_SEQ64_CX
)) {
4090 if (icmd
->unsli3
.rcvsli3
.vpi
== 0xffff)
4091 vport
= phba
->pport
;
4093 uint16_t vpi
= icmd
->unsli3
.rcvsli3
.vpi
;
4094 vport
= lpfc_find_vport_by_vpid(phba
, vpi
);
4097 /* If there are no BDEs associated
4098 * with this IOCB, there is nothing to do.
4100 if (icmd
->ulpBdeCount
== 0)
4103 /* type of ELS cmd is first 32bit word
4106 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) {
4107 elsiocb
->context2
= bdeBuf1
;
4109 paddr
= getPaddr(icmd
->un
.cont64
[0].addrHigh
,
4110 icmd
->un
.cont64
[0].addrLow
);
4111 elsiocb
->context2
= lpfc_sli_ringpostbuf_get(phba
, pring
,
4115 lpfc_els_unsol_buffer(phba
, pring
, vport
, elsiocb
);
4117 * The different unsolicited event handlers would tell us
4118 * if they are done with "mp" by setting context2 to NULL.
4120 lpfc_nlp_put(elsiocb
->context1
);
4121 elsiocb
->context1
= NULL
;
4122 if (elsiocb
->context2
) {
4123 lpfc_in_buf_free(phba
, (struct lpfc_dmabuf
*)elsiocb
->context2
);
4124 elsiocb
->context2
= NULL
;
4127 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
4128 if ((phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) &&
4129 icmd
->ulpBdeCount
== 2) {
4130 elsiocb
->context2
= bdeBuf2
;
4131 lpfc_els_unsol_buffer(phba
, pring
, vport
, elsiocb
);
4132 /* free mp if we are done with it */
4133 if (elsiocb
->context2
) {
4134 lpfc_in_buf_free(phba
, elsiocb
->context2
);
4135 elsiocb
->context2
= NULL
;
4141 lpfc_do_scr_ns_plogi(struct lpfc_hba
*phba
, struct lpfc_vport
*vport
)
4143 struct lpfc_nodelist
*ndlp
, *ndlp_fdmi
;
4145 ndlp
= lpfc_findnode_did(vport
, NameServer_DID
);
4147 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
4149 if (phba
->fc_topology
== TOPOLOGY_LOOP
) {
4150 lpfc_disc_start(vport
);
4153 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
4154 lpfc_printf_log(phba
, KERN_ERR
, LOG_ELS
,
4155 "%d (%d):0251 NameServer login: no memory\n",
4156 phba
->brd_no
, vport
->vpi
);
4159 lpfc_nlp_init(vport
, ndlp
, NameServer_DID
);
4160 ndlp
->nlp_type
|= NLP_FABRIC
;
4163 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
4165 if (lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0)) {
4166 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
4167 lpfc_printf_log(phba
, KERN_ERR
, LOG_ELS
,
4168 "%d (%d):0252 Cannot issue NameServer login\n",
4169 phba
->brd_no
, vport
->vpi
);
4173 if (phba
->cfg_fdmi_on
) {
4174 ndlp_fdmi
= mempool_alloc(phba
->nlp_mem_pool
,
4177 lpfc_nlp_init(vport
, ndlp_fdmi
, FDMI_DID
);
4178 ndlp_fdmi
->nlp_type
|= NLP_FABRIC
;
4179 ndlp_fdmi
->nlp_state
=
4180 NLP_STE_PLOGI_ISSUE
;
4181 lpfc_issue_els_plogi(vport
, ndlp_fdmi
->nlp_DID
,
4189 lpfc_cmpl_reg_new_vport(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
4191 struct lpfc_vport
*vport
= pmb
->vport
;
4192 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4193 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
4194 MAILBOX_t
*mb
= &pmb
->mb
;
4196 vport
->fc_flag
&= ~FC_VPORT_NEEDS_REG_VPI
;
4199 if (mb
->mbxStatus
) {
4200 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
,
4201 "%d (%d):0915 Register VPI failed: 0x%x\n",
4202 phba
->brd_no
, vport
->vpi
, mb
->mbxStatus
);
4204 switch (mb
->mbxStatus
) {
4205 case 0x11: /* unsupported feature */
4206 case 0x9603: /* max_vpi exceeded */
4207 /* giving up on vport registration */
4208 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
4209 spin_lock_irq(shost
->host_lock
);
4210 vport
->fc_flag
&= ~(FC_FABRIC
| FC_PUBLIC_LOOP
);
4211 spin_unlock_irq(shost
->host_lock
);
4212 lpfc_can_disctmo(vport
);
4215 /* Try to recover from this error */
4216 lpfc_mbx_unreg_vpi(vport
);
4217 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
4218 lpfc_initial_fdisc(vport
);
4223 if (vport
== phba
->pport
)
4224 lpfc_issue_fabric_reglogin(vport
);
4226 lpfc_do_scr_ns_plogi(phba
, vport
);
4228 mempool_free(pmb
, phba
->mbox_mem_pool
);
4233 lpfc_register_new_vport(struct lpfc_hba
*phba
, struct lpfc_vport
*vport
,
4234 struct lpfc_nodelist
*ndlp
)
4238 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4240 lpfc_reg_vpi(phba
, vport
->vpi
, vport
->fc_myDID
, mbox
);
4241 mbox
->vport
= vport
;
4242 mbox
->context2
= lpfc_nlp_get(ndlp
);
4243 mbox
->mbox_cmpl
= lpfc_cmpl_reg_new_vport
;
4244 if (lpfc_sli_issue_mbox(phba
, mbox
,
4245 MBX_NOWAIT
| MBX_STOP_IOCB
)
4246 == MBX_NOT_FINISHED
) {
4247 mempool_free(mbox
, phba
->mbox_mem_pool
);
4248 vport
->fc_flag
&= ~FC_VPORT_NEEDS_REG_VPI
;
4250 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
4252 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
,
4253 "%d (%d):0253 Register VPI: Cannot send mbox\n",
4254 phba
->brd_no
, vport
->vpi
);
4257 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
4259 lpfc_printf_log(phba
, KERN_ERR
, LOG_MBOX
,
4260 "%d (%d):0254 Register VPI: no memory\n",
4261 phba
->brd_no
, vport
->vpi
);
4263 vport
->fc_flag
&= ~FC_VPORT_NEEDS_REG_VPI
;
4269 lpfc_cmpl_els_fdisc(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
4270 struct lpfc_iocbq
*rspiocb
)
4272 struct lpfc_vport
*vport
= cmdiocb
->vport
;
4273 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4274 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
4275 struct lpfc_nodelist
*np
;
4276 struct lpfc_nodelist
*next_np
;
4277 IOCB_t
*irsp
= &rspiocb
->iocb
;
4278 struct lpfc_iocbq
*piocb
;
4280 lpfc_printf_log(phba
, KERN_INFO
, LOG_ELS
,
4281 "%d (%d):0123 FDISC completes. x%x/x%x prevDID: x%x\n",
4282 phba
->brd_no
, vport
->vpi
,
4283 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4], vport
->fc_prevDID
);
4285 /* Since all FDISCs are being single threaded, we
4286 * must reset the discovery timer for ALL vports
4287 * waiting to send FDISC when one completes.
4289 list_for_each_entry(piocb
, &phba
->fabric_iocb_list
, list
) {
4290 lpfc_set_disctmo(piocb
->vport
);
4293 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
4294 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
4295 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4], vport
->fc_prevDID
);
4297 if (irsp
->ulpStatus
) {
4298 /* Check for retry */
4299 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
))
4303 lpfc_printf_log(phba
, KERN_ERR
, LOG_ELS
,
4304 "%d (%d):0124 FDISC failed. (%d/%d)\n",
4305 phba
->brd_no
, vport
->vpi
,
4306 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4]);
4308 if (vport
->fc_vport
->vport_state
== FC_VPORT_INITIALIZING
)
4309 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
4312 /* giving up on FDISC. Cancel discovery timer */
4313 lpfc_can_disctmo(vport
);
4315 spin_lock_irq(shost
->host_lock
);
4316 vport
->fc_flag
|= FC_FABRIC
;
4317 if (vport
->phba
->fc_topology
== TOPOLOGY_LOOP
)
4318 vport
->fc_flag
|= FC_PUBLIC_LOOP
;
4319 spin_unlock_irq(shost
->host_lock
);
4321 vport
->fc_myDID
= irsp
->un
.ulpWord
[4] & Mask_DID
;
4322 lpfc_vport_set_state(vport
, FC_VPORT_ACTIVE
);
4323 if ((vport
->fc_prevDID
!= vport
->fc_myDID
) &&
4324 !(vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
)) {
4325 /* If our NportID changed, we need to ensure all
4326 * remaining NPORTs get unreg_login'ed so we can
4329 list_for_each_entry_safe(np
, next_np
,
4330 &vport
->fc_nodes
, nlp_listp
) {
4331 if (np
->nlp_state
!= NLP_STE_NPR_NODE
4332 || !(np
->nlp_flag
& NLP_NPR_ADISC
))
4334 spin_lock_irq(shost
->host_lock
);
4335 np
->nlp_flag
&= ~NLP_NPR_ADISC
;
4336 spin_unlock_irq(shost
->host_lock
);
4337 lpfc_unreg_rpi(vport
, np
);
4339 lpfc_mbx_unreg_vpi(vport
);
4340 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
4343 if (vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
)
4344 lpfc_register_new_vport(phba
, vport
, ndlp
);
4346 lpfc_do_scr_ns_plogi(phba
, vport
);
4348 lpfc_nlp_put(ndlp
); /* Free Fabric ndlp for vports */
4352 lpfc_els_free_iocb(phba
, cmdiocb
);
4356 lpfc_issue_els_fdisc(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
4359 struct lpfc_hba
*phba
= vport
->phba
;
4361 struct lpfc_iocbq
*elsiocb
;
4362 struct serv_parm
*sp
;
4365 int did
= ndlp
->nlp_DID
;
4368 cmdsize
= (sizeof(uint32_t) + sizeof(struct serv_parm
));
4369 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
, did
,
4372 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
4374 lpfc_printf_log(phba
, KERN_ERR
, LOG_ELS
,
4375 "%d (%d):0255 Issue FDISC: no IOCB\n",
4376 phba
->brd_no
, vport
->vpi
);
4380 icmd
= &elsiocb
->iocb
;
4381 icmd
->un
.elsreq64
.myID
= 0;
4382 icmd
->un
.elsreq64
.fl
= 1;
4384 /* For FDISC, Let FDISC rsp set the NPortID for this VPI */
4388 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
4389 *((uint32_t *) (pcmd
)) = ELS_CMD_FDISC
;
4390 pcmd
+= sizeof(uint32_t); /* CSP Word 1 */
4391 memcpy(pcmd
, &vport
->phba
->pport
->fc_sparam
, sizeof(struct serv_parm
));
4392 sp
= (struct serv_parm
*) pcmd
;
4393 /* Setup CSPs accordingly for Fabric */
4394 sp
->cmn
.e_d_tov
= 0;
4395 sp
->cmn
.w2
.r_a_tov
= 0;
4396 sp
->cls1
.classValid
= 0;
4397 sp
->cls2
.seqDelivery
= 1;
4398 sp
->cls3
.seqDelivery
= 1;
4400 pcmd
+= sizeof(uint32_t); /* CSP Word 2 */
4401 pcmd
+= sizeof(uint32_t); /* CSP Word 3 */
4402 pcmd
+= sizeof(uint32_t); /* CSP Word 4 */
4403 pcmd
+= sizeof(uint32_t); /* Port Name */
4404 memcpy(pcmd
, &vport
->fc_portname
, 8);
4405 pcmd
+= sizeof(uint32_t); /* Node Name */
4406 pcmd
+= sizeof(uint32_t); /* Node Name */
4407 memcpy(pcmd
, &vport
->fc_nodename
, 8);
4409 lpfc_set_disctmo(vport
);
4411 phba
->fc_stat
.elsXmitFDISC
++;
4412 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_fdisc
;
4414 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
4415 "Issue FDISC: did:x%x",
4418 rc
= lpfc_issue_fabric_iocb(phba
, elsiocb
);
4419 if (rc
== IOCB_ERROR
) {
4420 lpfc_els_free_iocb(phba
, elsiocb
);
4421 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
4423 lpfc_printf_log(phba
, KERN_ERR
, LOG_ELS
,
4424 "%d (%d):0256 Issue FDISC: Cannot send IOCB\n",
4425 phba
->brd_no
, vport
->vpi
);
4429 lpfc_vport_set_state(vport
, FC_VPORT_INITIALIZING
);
4430 vport
->port_state
= LPFC_FDISC
;
4435 lpfc_cmpl_els_npiv_logo(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
4436 struct lpfc_iocbq
*rspiocb
)
4438 struct lpfc_vport
*vport
= cmdiocb
->vport
;
4441 irsp
= &rspiocb
->iocb
;
4442 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
4443 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
4444 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4], irsp
->un
.rcvels
.remoteID
);
4446 lpfc_els_free_iocb(phba
, cmdiocb
);
4447 vport
->unreg_vpi_cmpl
= VPORT_ERROR
;
4451 lpfc_issue_els_npiv_logo(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
4453 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4454 struct lpfc_hba
*phba
= vport
->phba
;
4455 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
4457 struct lpfc_iocbq
*elsiocb
;
4461 cmdsize
= 2 * sizeof(uint32_t) + sizeof(struct lpfc_name
);
4462 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, 0, ndlp
, ndlp
->nlp_DID
,
4467 icmd
= &elsiocb
->iocb
;
4468 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
4469 *((uint32_t *) (pcmd
)) = ELS_CMD_LOGO
;
4470 pcmd
+= sizeof(uint32_t);
4472 /* Fill in LOGO payload */
4473 *((uint32_t *) (pcmd
)) = be32_to_cpu(vport
->fc_myDID
);
4474 pcmd
+= sizeof(uint32_t);
4475 memcpy(pcmd
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
4477 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
4478 "Issue LOGO npiv did:x%x flg:x%x",
4479 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
4481 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_npiv_logo
;
4482 spin_lock_irq(shost
->host_lock
);
4483 ndlp
->nlp_flag
|= NLP_LOGO_SND
;
4484 spin_unlock_irq(shost
->host_lock
);
4485 if (lpfc_sli_issue_iocb(phba
, pring
, elsiocb
, 0) == IOCB_ERROR
) {
4486 spin_lock_irq(shost
->host_lock
);
4487 ndlp
->nlp_flag
&= ~NLP_LOGO_SND
;
4488 spin_unlock_irq(shost
->host_lock
);
4489 lpfc_els_free_iocb(phba
, elsiocb
);
4496 lpfc_fabric_block_timeout(unsigned long ptr
)
4498 struct lpfc_hba
*phba
= (struct lpfc_hba
*) ptr
;
4499 unsigned long iflags
;
4500 uint32_t tmo_posted
;
4501 spin_lock_irqsave(&phba
->pport
->work_port_lock
, iflags
);
4502 tmo_posted
= phba
->pport
->work_port_events
& WORKER_FABRIC_BLOCK_TMO
;
4504 phba
->pport
->work_port_events
|= WORKER_FABRIC_BLOCK_TMO
;
4505 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, iflags
);
4508 spin_lock_irqsave(&phba
->hbalock
, iflags
);
4509 if (phba
->work_wait
)
4510 lpfc_worker_wake_up(phba
);
4511 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
4516 lpfc_resume_fabric_iocbs(struct lpfc_hba
*phba
)
4518 struct lpfc_iocbq
*iocb
;
4519 unsigned long iflags
;
4521 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
4526 spin_lock_irqsave(&phba
->hbalock
, iflags
);
4527 /* Post any pending iocb to the SLI layer */
4528 if (atomic_read(&phba
->fabric_iocb_count
) == 0) {
4529 list_remove_head(&phba
->fabric_iocb_list
, iocb
, typeof(*iocb
),
4532 atomic_inc(&phba
->fabric_iocb_count
);
4534 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
4536 iocb
->fabric_iocb_cmpl
= iocb
->iocb_cmpl
;
4537 iocb
->iocb_cmpl
= lpfc_cmpl_fabric_iocb
;
4538 iocb
->iocb_flag
|= LPFC_IO_FABRIC
;
4540 lpfc_debugfs_disc_trc(iocb
->vport
, LPFC_DISC_TRC_ELS_CMD
,
4541 "Fabric sched1: ste:x%x",
4542 iocb
->vport
->port_state
, 0, 0);
4544 ret
= lpfc_sli_issue_iocb(phba
, pring
, iocb
, 0);
4546 if (ret
== IOCB_ERROR
) {
4547 iocb
->iocb_cmpl
= iocb
->fabric_iocb_cmpl
;
4548 iocb
->fabric_iocb_cmpl
= NULL
;
4549 iocb
->iocb_flag
&= ~LPFC_IO_FABRIC
;
4551 cmd
->ulpStatus
= IOSTAT_LOCAL_REJECT
;
4552 cmd
->un
.ulpWord
[4] = IOERR_SLI_ABORTED
;
4553 iocb
->iocb_cmpl(phba
, iocb
, iocb
);
4555 atomic_dec(&phba
->fabric_iocb_count
);
4564 lpfc_unblock_fabric_iocbs(struct lpfc_hba
*phba
)
4566 clear_bit(FABRIC_COMANDS_BLOCKED
, &phba
->bit_flags
);
4568 lpfc_resume_fabric_iocbs(phba
);
4573 lpfc_block_fabric_iocbs(struct lpfc_hba
*phba
)
4577 blocked
= test_and_set_bit(FABRIC_COMANDS_BLOCKED
, &phba
->bit_flags
);
4578 /* Start a timer to unblock fabric
4582 mod_timer(&phba
->fabric_block_timer
, jiffies
+ HZ
/10 );
4588 lpfc_cmpl_fabric_iocb(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
4589 struct lpfc_iocbq
*rspiocb
)
4593 if ((cmdiocb
->iocb_flag
& LPFC_IO_FABRIC
) != LPFC_IO_FABRIC
)
4596 switch (rspiocb
->iocb
.ulpStatus
) {
4597 case IOSTAT_NPORT_RJT
:
4598 case IOSTAT_FABRIC_RJT
:
4599 if (rspiocb
->iocb
.un
.ulpWord
[4] & RJT_UNAVAIL_TEMP
) {
4600 lpfc_block_fabric_iocbs(phba
);
4604 case IOSTAT_NPORT_BSY
:
4605 case IOSTAT_FABRIC_BSY
:
4606 lpfc_block_fabric_iocbs(phba
);
4610 stat
.un
.lsRjtError
=
4611 be32_to_cpu(rspiocb
->iocb
.un
.ulpWord
[4]);
4612 if ((stat
.un
.b
.lsRjtRsnCode
== LSRJT_UNABLE_TPC
) ||
4613 (stat
.un
.b
.lsRjtRsnCode
== LSRJT_LOGICAL_BSY
))
4614 lpfc_block_fabric_iocbs(phba
);
4618 if (atomic_read(&phba
->fabric_iocb_count
) == 0)
4621 cmdiocb
->iocb_cmpl
= cmdiocb
->fabric_iocb_cmpl
;
4622 cmdiocb
->fabric_iocb_cmpl
= NULL
;
4623 cmdiocb
->iocb_flag
&= ~LPFC_IO_FABRIC
;
4624 cmdiocb
->iocb_cmpl(phba
, cmdiocb
, rspiocb
);
4626 atomic_dec(&phba
->fabric_iocb_count
);
4627 if (!test_bit(FABRIC_COMANDS_BLOCKED
, &phba
->bit_flags
)) {
4628 /* Post any pending iocbs to HBA */
4629 lpfc_resume_fabric_iocbs(phba
);
4634 lpfc_issue_fabric_iocb(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocb
)
4636 unsigned long iflags
;
4637 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
4641 if (atomic_read(&phba
->fabric_iocb_count
) > 1)
4644 spin_lock_irqsave(&phba
->hbalock
, iflags
);
4645 ready
= atomic_read(&phba
->fabric_iocb_count
) == 0 &&
4646 !test_bit(FABRIC_COMANDS_BLOCKED
, &phba
->bit_flags
);
4648 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
4650 iocb
->fabric_iocb_cmpl
= iocb
->iocb_cmpl
;
4651 iocb
->iocb_cmpl
= lpfc_cmpl_fabric_iocb
;
4652 iocb
->iocb_flag
|= LPFC_IO_FABRIC
;
4654 lpfc_debugfs_disc_trc(iocb
->vport
, LPFC_DISC_TRC_ELS_CMD
,
4655 "Fabric sched2: ste:x%x",
4656 iocb
->vport
->port_state
, 0, 0);
4658 atomic_inc(&phba
->fabric_iocb_count
);
4659 ret
= lpfc_sli_issue_iocb(phba
, pring
, iocb
, 0);
4661 if (ret
== IOCB_ERROR
) {
4662 iocb
->iocb_cmpl
= iocb
->fabric_iocb_cmpl
;
4663 iocb
->fabric_iocb_cmpl
= NULL
;
4664 iocb
->iocb_flag
&= ~LPFC_IO_FABRIC
;
4665 atomic_dec(&phba
->fabric_iocb_count
);
4668 spin_lock_irqsave(&phba
->hbalock
, iflags
);
4669 list_add_tail(&iocb
->list
, &phba
->fabric_iocb_list
);
4670 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
4677 void lpfc_fabric_abort_vport(struct lpfc_vport
*vport
)
4679 LIST_HEAD(completions
);
4680 struct lpfc_hba
*phba
= vport
->phba
;
4681 struct lpfc_iocbq
*tmp_iocb
, *piocb
;
4684 spin_lock_irq(&phba
->hbalock
);
4685 list_for_each_entry_safe(piocb
, tmp_iocb
, &phba
->fabric_iocb_list
,
4688 if (piocb
->vport
!= vport
)
4691 list_move_tail(&piocb
->list
, &completions
);
4693 spin_unlock_irq(&phba
->hbalock
);
4695 while (!list_empty(&completions
)) {
4696 piocb
= list_get_first(&completions
, struct lpfc_iocbq
, list
);
4697 list_del_init(&piocb
->list
);
4700 cmd
->ulpStatus
= IOSTAT_LOCAL_REJECT
;
4701 cmd
->un
.ulpWord
[4] = IOERR_SLI_ABORTED
;
4702 (piocb
->iocb_cmpl
) (phba
, piocb
, piocb
);
4706 void lpfc_fabric_abort_nport(struct lpfc_nodelist
*ndlp
)
4708 LIST_HEAD(completions
);
4709 struct lpfc_hba
*phba
= ndlp
->vport
->phba
;
4710 struct lpfc_iocbq
*tmp_iocb
, *piocb
;
4711 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
4714 spin_lock_irq(&phba
->hbalock
);
4715 list_for_each_entry_safe(piocb
, tmp_iocb
, &phba
->fabric_iocb_list
,
4717 if ((lpfc_check_sli_ndlp(phba
, pring
, piocb
, ndlp
))) {
4719 list_move_tail(&piocb
->list
, &completions
);
4722 spin_unlock_irq(&phba
->hbalock
);
4724 while (!list_empty(&completions
)) {
4725 piocb
= list_get_first(&completions
, struct lpfc_iocbq
, list
);
4726 list_del_init(&piocb
->list
);
4729 cmd
->ulpStatus
= IOSTAT_LOCAL_REJECT
;
4730 cmd
->un
.ulpWord
[4] = IOERR_SLI_ABORTED
;
4731 (piocb
->iocb_cmpl
) (phba
, piocb
, piocb
);
4735 void lpfc_fabric_abort_hba(struct lpfc_hba
*phba
)
4737 LIST_HEAD(completions
);
4738 struct lpfc_iocbq
*piocb
;
4741 spin_lock_irq(&phba
->hbalock
);
4742 list_splice_init(&phba
->fabric_iocb_list
, &completions
);
4743 spin_unlock_irq(&phba
->hbalock
);
4745 while (!list_empty(&completions
)) {
4746 piocb
= list_get_first(&completions
, struct lpfc_iocbq
, list
);
4747 list_del_init(&piocb
->list
);
4750 cmd
->ulpStatus
= IOSTAT_LOCAL_REJECT
;
4751 cmd
->un
.ulpWord
[4] = IOERR_SLI_ABORTED
;
4752 (piocb
->iocb_cmpl
) (phba
, piocb
, piocb
);
4757 void lpfc_fabric_abort_flogi(struct lpfc_hba
*phba
)
4759 LIST_HEAD(completions
);
4760 struct lpfc_iocbq
*tmp_iocb
, *piocb
;
4762 struct lpfc_nodelist
*ndlp
;
4764 spin_lock_irq(&phba
->hbalock
);
4765 list_for_each_entry_safe(piocb
, tmp_iocb
, &phba
->fabric_iocb_list
,
4769 ndlp
= (struct lpfc_nodelist
*) piocb
->context1
;
4770 if (cmd
->ulpCommand
== CMD_ELS_REQUEST64_CR
&&
4772 ndlp
->nlp_DID
== Fabric_DID
)
4773 list_move_tail(&piocb
->list
, &completions
);
4775 spin_unlock_irq(&phba
->hbalock
);
4777 while (!list_empty(&completions
)) {
4778 piocb
= list_get_first(&completions
, struct lpfc_iocbq
, list
);
4779 list_del_init(&piocb
->list
);
4782 cmd
->ulpStatus
= IOSTAT_LOCAL_REJECT
;
4783 cmd
->un
.ulpWord
[4] = IOERR_SLI_ABORTED
;
4784 (piocb
->iocb_cmpl
) (phba
, piocb
, piocb
);