1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017-2020 Broadcom. All Rights Reserved. The term *
5 * “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. *
6 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
7 * EMULEX and SLI are trademarks of Emulex. *
9 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
11 * This program is free software; you can redistribute it and/or *
12 * modify it under the terms of version 2 of the GNU General *
13 * Public License as published by the Free Software Foundation. *
14 * This program is distributed in the hope that it will be useful. *
15 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
16 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
17 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
18 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
19 * TO BE LEGALLY INVALID. See the GNU General Public License for *
20 * more details, a copy of which can be found in the file COPYING *
21 * included with this package. *
22 *******************************************************************/
24 #include <linux/blkdev.h>
25 #include <linux/pci.h>
26 #include <linux/slab.h>
27 #include <linux/interrupt.h>
29 #include <scsi/scsi.h>
30 #include <scsi/scsi_device.h>
31 #include <scsi/scsi_host.h>
32 #include <scsi/scsi_transport_fc.h>
33 #include <scsi/fc/fc_fs.h>
38 #include "lpfc_sli4.h"
40 #include "lpfc_disc.h"
42 #include "lpfc_scsi.h"
43 #include "lpfc_nvme.h"
44 #include "lpfc_logmsg.h"
45 #include "lpfc_crtn.h"
46 #include "lpfc_vport.h"
47 #include "lpfc_debugfs.h"
50 /* Called to verify a rcv'ed ADISC was intended for us. */
52 lpfc_check_adisc(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
53 struct lpfc_name
*nn
, struct lpfc_name
*pn
)
55 /* First, we MUST have a RPI registered */
56 if (!(ndlp
->nlp_flag
& NLP_RPI_REGISTERED
))
59 /* Compare the ADISC rsp WWNN / WWPN matches our internal node
60 * table entry for that node.
62 if (memcmp(nn
, &ndlp
->nlp_nodename
, sizeof (struct lpfc_name
)))
65 if (memcmp(pn
, &ndlp
->nlp_portname
, sizeof (struct lpfc_name
)))
68 /* we match, return success */
73 lpfc_check_sparm(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
74 struct serv_parm
*sp
, uint32_t class, int flogi
)
76 volatile struct serv_parm
*hsp
= &vport
->fc_sparam
;
77 uint16_t hsp_value
, ssp_value
= 0;
80 * The receive data field size and buffer-to-buffer receive data field
81 * size entries are 16 bits but are represented as two 8-bit fields in
82 * the driver data structure to account for rsvd bits and other control
83 * bits. Reconstruct and compare the fields as a 16-bit values before
84 * correcting the byte values.
86 if (sp
->cls1
.classValid
) {
88 hsp_value
= ((hsp
->cls1
.rcvDataSizeMsb
<< 8) |
89 hsp
->cls1
.rcvDataSizeLsb
);
90 ssp_value
= ((sp
->cls1
.rcvDataSizeMsb
<< 8) |
91 sp
->cls1
.rcvDataSizeLsb
);
93 goto bad_service_param
;
94 if (ssp_value
> hsp_value
) {
95 sp
->cls1
.rcvDataSizeLsb
=
96 hsp
->cls1
.rcvDataSizeLsb
;
97 sp
->cls1
.rcvDataSizeMsb
=
98 hsp
->cls1
.rcvDataSizeMsb
;
101 } else if (class == CLASS1
)
102 goto bad_service_param
;
103 if (sp
->cls2
.classValid
) {
105 hsp_value
= ((hsp
->cls2
.rcvDataSizeMsb
<< 8) |
106 hsp
->cls2
.rcvDataSizeLsb
);
107 ssp_value
= ((sp
->cls2
.rcvDataSizeMsb
<< 8) |
108 sp
->cls2
.rcvDataSizeLsb
);
110 goto bad_service_param
;
111 if (ssp_value
> hsp_value
) {
112 sp
->cls2
.rcvDataSizeLsb
=
113 hsp
->cls2
.rcvDataSizeLsb
;
114 sp
->cls2
.rcvDataSizeMsb
=
115 hsp
->cls2
.rcvDataSizeMsb
;
118 } else if (class == CLASS2
)
119 goto bad_service_param
;
120 if (sp
->cls3
.classValid
) {
122 hsp_value
= ((hsp
->cls3
.rcvDataSizeMsb
<< 8) |
123 hsp
->cls3
.rcvDataSizeLsb
);
124 ssp_value
= ((sp
->cls3
.rcvDataSizeMsb
<< 8) |
125 sp
->cls3
.rcvDataSizeLsb
);
127 goto bad_service_param
;
128 if (ssp_value
> hsp_value
) {
129 sp
->cls3
.rcvDataSizeLsb
=
130 hsp
->cls3
.rcvDataSizeLsb
;
131 sp
->cls3
.rcvDataSizeMsb
=
132 hsp
->cls3
.rcvDataSizeMsb
;
135 } else if (class == CLASS3
)
136 goto bad_service_param
;
139 * Preserve the upper four bits of the MSB from the PLOGI response.
140 * These bits contain the Buffer-to-Buffer State Change Number
141 * from the target and need to be passed to the FW.
143 hsp_value
= (hsp
->cmn
.bbRcvSizeMsb
<< 8) | hsp
->cmn
.bbRcvSizeLsb
;
144 ssp_value
= (sp
->cmn
.bbRcvSizeMsb
<< 8) | sp
->cmn
.bbRcvSizeLsb
;
145 if (ssp_value
> hsp_value
) {
146 sp
->cmn
.bbRcvSizeLsb
= hsp
->cmn
.bbRcvSizeLsb
;
147 sp
->cmn
.bbRcvSizeMsb
= (sp
->cmn
.bbRcvSizeMsb
& 0xF0) |
148 (hsp
->cmn
.bbRcvSizeMsb
& 0x0F);
151 memcpy(&ndlp
->nlp_nodename
, &sp
->nodeName
, sizeof (struct lpfc_name
));
152 memcpy(&ndlp
->nlp_portname
, &sp
->portName
, sizeof (struct lpfc_name
));
155 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
157 "(%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x) sent "
158 "invalid service parameters. Ignoring device.\n",
160 sp
->nodeName
.u
.wwn
[0], sp
->nodeName
.u
.wwn
[1],
161 sp
->nodeName
.u
.wwn
[2], sp
->nodeName
.u
.wwn
[3],
162 sp
->nodeName
.u
.wwn
[4], sp
->nodeName
.u
.wwn
[5],
163 sp
->nodeName
.u
.wwn
[6], sp
->nodeName
.u
.wwn
[7]);
168 lpfc_check_elscmpl_iocb(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
169 struct lpfc_iocbq
*rspiocb
)
171 struct lpfc_dmabuf
*pcmd
, *prsp
;
176 irsp
= &rspiocb
->iocb
;
177 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
179 /* For lpfc_els_abort, context2 could be zero'ed to delay
180 * freeing associated memory till after ABTS completes.
183 prsp
= list_get_first(&pcmd
->list
, struct lpfc_dmabuf
,
186 lp
= (uint32_t *) prsp
->virt
;
187 ptr
= (void *)((uint8_t *)lp
+ sizeof(uint32_t));
190 /* Force ulpStatus error since we are returning NULL ptr */
191 if (!(irsp
->ulpStatus
)) {
192 irsp
->ulpStatus
= IOSTAT_LOCAL_REJECT
;
193 irsp
->un
.ulpWord
[4] = IOERR_SLI_ABORTED
;
203 * Free resources / clean up outstanding I/Os
204 * associated with a LPFC_NODELIST entry. This
205 * routine effectively results in a "software abort".
208 lpfc_els_abort(struct lpfc_hba
*phba
, struct lpfc_nodelist
*ndlp
)
210 LIST_HEAD(abort_list
);
211 struct lpfc_sli_ring
*pring
;
212 struct lpfc_iocbq
*iocb
, *next_iocb
;
214 pring
= lpfc_phba_elsring(phba
);
216 /* In case of error recovery path, we might have a NULL pring here */
217 if (unlikely(!pring
))
220 /* Abort outstanding I/O on NPort <nlp_DID> */
221 lpfc_printf_vlog(ndlp
->vport
, KERN_INFO
, LOG_DISCOVERY
,
222 "2819 Abort outstanding I/O on NPort x%x "
223 "Data: x%x x%x x%x\n",
224 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
226 /* Clean up all fabric IOs first.*/
227 lpfc_fabric_abort_nport(ndlp
);
230 * Lock the ELS ring txcmplq for SLI3/SLI4 and build a local list
231 * of all ELS IOs that need an ABTS. The IOs need to stay on the
232 * txcmplq so that the abort operation completes them successfully.
234 spin_lock_irq(&phba
->hbalock
);
235 if (phba
->sli_rev
== LPFC_SLI_REV4
)
236 spin_lock(&pring
->ring_lock
);
237 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
, list
) {
238 /* Add to abort_list on on NDLP match. */
239 if (lpfc_check_sli_ndlp(phba
, pring
, iocb
, ndlp
))
240 list_add_tail(&iocb
->dlist
, &abort_list
);
242 if (phba
->sli_rev
== LPFC_SLI_REV4
)
243 spin_unlock(&pring
->ring_lock
);
244 spin_unlock_irq(&phba
->hbalock
);
246 /* Abort the targeted IOs and remove them from the abort list. */
247 list_for_each_entry_safe(iocb
, next_iocb
, &abort_list
, dlist
) {
248 spin_lock_irq(&phba
->hbalock
);
249 list_del_init(&iocb
->dlist
);
250 lpfc_sli_issue_abort_iotag(phba
, pring
, iocb
, NULL
);
251 spin_unlock_irq(&phba
->hbalock
);
254 INIT_LIST_HEAD(&abort_list
);
256 /* Now process the txq */
257 spin_lock_irq(&phba
->hbalock
);
258 if (phba
->sli_rev
== LPFC_SLI_REV4
)
259 spin_lock(&pring
->ring_lock
);
261 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txq
, list
) {
262 /* Check to see if iocb matches the nport we are looking for */
263 if (lpfc_check_sli_ndlp(phba
, pring
, iocb
, ndlp
)) {
264 list_del_init(&iocb
->list
);
265 list_add_tail(&iocb
->list
, &abort_list
);
269 if (phba
->sli_rev
== LPFC_SLI_REV4
)
270 spin_unlock(&pring
->ring_lock
);
271 spin_unlock_irq(&phba
->hbalock
);
273 /* Cancel all the IOCBs from the completions list */
274 lpfc_sli_cancel_iocbs(phba
, &abort_list
,
275 IOSTAT_LOCAL_REJECT
, IOERR_SLI_ABORTED
);
277 lpfc_cancel_retry_delay_tmo(phba
->pport
, ndlp
);
280 /* lpfc_defer_pt2pt_acc - Complete SLI3 pt2pt processing on link up
281 * @phba: pointer to lpfc hba data structure.
282 * @link_mbox: pointer to CONFIG_LINK mailbox object
284 * This routine is only called if we are SLI3, direct connect pt2pt
285 * mode and the remote NPort issues the PLOGI after link up.
288 lpfc_defer_pt2pt_acc(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*link_mbox
)
290 LPFC_MBOXQ_t
*login_mbox
;
291 MAILBOX_t
*mb
= &link_mbox
->u
.mb
;
292 struct lpfc_iocbq
*save_iocb
;
293 struct lpfc_nodelist
*ndlp
;
296 ndlp
= link_mbox
->ctx_ndlp
;
297 login_mbox
= link_mbox
->context3
;
298 save_iocb
= login_mbox
->context3
;
299 link_mbox
->context3
= NULL
;
300 login_mbox
->context3
= NULL
;
302 /* Check for CONFIG_LINK error */
304 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
305 "4575 CONFIG_LINK fails pt2pt discovery: %x\n",
307 mempool_free(login_mbox
, phba
->mbox_mem_pool
);
308 mempool_free(link_mbox
, phba
->mbox_mem_pool
);
313 /* Now that CONFIG_LINK completed, and our SID is configured,
314 * we can now proceed with sending the PLOGI ACC.
316 rc
= lpfc_els_rsp_acc(link_mbox
->vport
, ELS_CMD_PLOGI
,
317 save_iocb
, ndlp
, login_mbox
);
319 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
320 "4576 PLOGI ACC fails pt2pt discovery: %x\n",
322 mempool_free(login_mbox
, phba
->mbox_mem_pool
);
325 mempool_free(link_mbox
, phba
->mbox_mem_pool
);
330 * lpfc_defer_tgt_acc - Progress SLI4 target rcv PLOGI handler
331 * @phba: Pointer to HBA context object.
332 * @pmb: Pointer to mailbox object.
334 * This function provides the unreg rpi mailbox completion handler for a tgt.
335 * The routine frees the memory resources associated with the completed
336 * mailbox command and transmits the ELS ACC.
338 * This routine is only called if we are SLI4, acting in target
339 * mode and the remote NPort issues the PLOGI after link up.
342 lpfc_defer_acc_rsp(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
344 struct lpfc_vport
*vport
= pmb
->vport
;
345 struct lpfc_nodelist
*ndlp
= pmb
->ctx_ndlp
;
346 LPFC_MBOXQ_t
*mbox
= pmb
->context3
;
347 struct lpfc_iocbq
*piocb
= NULL
;
351 pmb
->context3
= NULL
;
352 piocb
= mbox
->context3
;
353 mbox
->context3
= NULL
;
357 * Complete the unreg rpi mbx request, and update flags.
358 * This will also restart any deferred events.
360 lpfc_sli4_unreg_rpi_cmpl_clr(phba
, pmb
);
363 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
364 "4578 PLOGI ACC fail\n");
366 mempool_free(mbox
, phba
->mbox_mem_pool
);
370 rc
= lpfc_els_rsp_acc(vport
, ELS_CMD_PLOGI
, piocb
, ndlp
, mbox
);
372 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
373 "4579 PLOGI ACC fail %x\n", rc
);
375 mempool_free(mbox
, phba
->mbox_mem_pool
);
381 lpfc_rcv_plogi(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
382 struct lpfc_iocbq
*cmdiocb
)
384 struct lpfc_hba
*phba
= vport
->phba
;
385 struct lpfc_dmabuf
*pcmd
;
386 uint64_t nlp_portwwn
= 0;
389 struct serv_parm
*sp
;
391 LPFC_MBOXQ_t
*link_mbox
;
392 LPFC_MBOXQ_t
*login_mbox
;
393 struct lpfc_iocbq
*save_iocb
;
399 memset(&stat
, 0, sizeof (struct ls_rjt
));
400 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
401 lp
= (uint32_t *) pcmd
->virt
;
402 sp
= (struct serv_parm
*) ((uint8_t *) lp
+ sizeof (uint32_t));
403 if (wwn_to_u64(sp
->portName
.u
.wwn
) == 0) {
404 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
405 "0140 PLOGI Reject: invalid nname\n");
406 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
407 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_INVALID_PNAME
;
408 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
,
412 if (wwn_to_u64(sp
->nodeName
.u
.wwn
) == 0) {
413 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
414 "0141 PLOGI Reject: invalid pname\n");
415 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
416 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_INVALID_NNAME
;
417 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
,
422 nlp_portwwn
= wwn_to_u64(ndlp
->nlp_portname
.u
.wwn
);
423 if ((lpfc_check_sparm(vport
, ndlp
, sp
, CLASS3
, 0) == 0)) {
424 /* Reject this request because invalid parameters */
425 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
426 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_SPARM_OPTIONS
;
427 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
,
431 icmd
= &cmdiocb
->iocb
;
433 /* PLOGI chkparm OK */
434 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
435 "0114 PLOGI chkparm OK Data: x%x x%x x%x "
437 ndlp
->nlp_DID
, ndlp
->nlp_state
, ndlp
->nlp_flag
,
438 ndlp
->nlp_rpi
, vport
->port_state
,
441 if (vport
->cfg_fcp_class
== 2 && sp
->cls2
.classValid
)
442 ndlp
->nlp_fcp_info
|= CLASS2
;
444 ndlp
->nlp_fcp_info
|= CLASS3
;
447 ndlp
->nlp_class_sup
= 0;
448 if (sp
->cls1
.classValid
)
449 ndlp
->nlp_class_sup
|= FC_COS_CLASS1
;
450 if (sp
->cls2
.classValid
)
451 ndlp
->nlp_class_sup
|= FC_COS_CLASS2
;
452 if (sp
->cls3
.classValid
)
453 ndlp
->nlp_class_sup
|= FC_COS_CLASS3
;
454 if (sp
->cls4
.classValid
)
455 ndlp
->nlp_class_sup
|= FC_COS_CLASS4
;
457 ((sp
->cmn
.bbRcvSizeMsb
& 0x0F) << 8) | sp
->cmn
.bbRcvSizeLsb
;
458 /* if already logged in, do implicit logout */
459 switch (ndlp
->nlp_state
) {
460 case NLP_STE_NPR_NODE
:
461 if (!(ndlp
->nlp_flag
& NLP_NPR_ADISC
))
464 case NLP_STE_REG_LOGIN_ISSUE
:
465 case NLP_STE_PRLI_ISSUE
:
466 case NLP_STE_UNMAPPED_NODE
:
467 case NLP_STE_MAPPED_NODE
:
468 /* For initiators, lpfc_plogi_confirm_nport skips fabric did.
469 * For target mode, execute implicit logo.
470 * Fabric nodes go into NPR.
472 if (!(ndlp
->nlp_type
& NLP_FABRIC
) &&
473 !(phba
->nvmet_support
)) {
474 lpfc_els_rsp_acc(vport
, ELS_CMD_PLOGI
, cmdiocb
,
478 if (nlp_portwwn
!= 0 &&
479 nlp_portwwn
!= wwn_to_u64(sp
->portName
.u
.wwn
))
480 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
481 "0143 PLOGI recv'd from DID: x%x "
482 "WWPN changed: old %llx new %llx\n",
484 (unsigned long long)nlp_portwwn
,
486 wwn_to_u64(sp
->portName
.u
.wwn
));
488 /* Notify transport of connectivity loss to trigger cleanup. */
489 if (phba
->nvmet_support
&&
490 ndlp
->nlp_state
== NLP_STE_UNMAPPED_NODE
)
491 lpfc_nvmet_invalidate_host(phba
, ndlp
);
493 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
494 /* rport needs to be unregistered first */
495 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
499 ndlp
->nlp_type
&= ~(NLP_FCP_TARGET
| NLP_FCP_INITIATOR
);
500 ndlp
->nlp_type
&= ~(NLP_NVME_TARGET
| NLP_NVME_INITIATOR
);
501 ndlp
->nlp_fcp_info
&= ~NLP_FCP_2_DEVICE
;
502 ndlp
->nlp_flag
&= ~NLP_FIRSTBURST
;
508 /* Check for Nport to NPort pt2pt protocol */
509 if ((vport
->fc_flag
& FC_PT2PT
) &&
510 !(vport
->fc_flag
& FC_PT2PT_PLOGI
)) {
511 /* rcv'ed PLOGI decides what our NPortId will be */
512 vport
->fc_myDID
= icmd
->un
.rcvels
.parmRo
;
514 ed_tov
= be32_to_cpu(sp
->cmn
.e_d_tov
);
515 if (sp
->cmn
.edtovResolution
) {
516 /* E_D_TOV ticks are in nanoseconds */
517 ed_tov
= (phba
->fc_edtov
+ 999999) / 1000000;
521 * For pt-to-pt, use the larger EDTOV
524 if (ed_tov
> phba
->fc_edtov
)
525 phba
->fc_edtov
= ed_tov
;
526 phba
->fc_ratov
= (2 * phba
->fc_edtov
) / 1000;
528 memcpy(&phba
->fc_fabparam
, sp
, sizeof(struct serv_parm
));
530 /* Issue config_link / reg_vfi to account for updated TOV's */
532 if (phba
->sli_rev
== LPFC_SLI_REV4
)
533 lpfc_issue_reg_vfi(vport
);
536 link_mbox
= mempool_alloc(phba
->mbox_mem_pool
,
540 lpfc_config_link(phba
, link_mbox
);
541 link_mbox
->mbox_cmpl
= lpfc_defer_pt2pt_acc
;
542 link_mbox
->vport
= vport
;
543 link_mbox
->ctx_ndlp
= ndlp
;
545 save_iocb
= kzalloc(sizeof(*save_iocb
), GFP_KERNEL
);
548 /* Save info from cmd IOCB used in rsp */
549 memcpy((uint8_t *)save_iocb
, (uint8_t *)cmdiocb
,
550 sizeof(struct lpfc_iocbq
));
553 lpfc_can_disctmo(vport
);
556 ndlp
->nlp_flag
&= ~NLP_SUPPRESS_RSP
;
557 if ((phba
->sli
.sli_flag
& LPFC_SLI_SUPPRESS_RSP
) &&
558 sp
->cmn
.valid_vendor_ver_level
) {
559 vid
= be32_to_cpu(sp
->un
.vv
.vid
);
560 flag
= be32_to_cpu(sp
->un
.vv
.flags
);
561 if ((vid
== LPFC_VV_EMLX_ID
) && (flag
& LPFC_VV_SUPPRESS_RSP
))
562 ndlp
->nlp_flag
|= NLP_SUPPRESS_RSP
;
565 login_mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
569 /* Registering an existing RPI behaves differently for SLI3 vs SLI4 */
570 if (phba
->nvmet_support
&& !defer_acc
) {
571 link_mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
575 /* As unique identifiers such as iotag would be overwritten
576 * with those from the cmdiocb, allocate separate temporary
577 * storage for the copy.
579 save_iocb
= kzalloc(sizeof(*save_iocb
), GFP_KERNEL
);
583 /* Unreg RPI is required for SLI4. */
584 rpi
= phba
->sli4_hba
.rpi_ids
[ndlp
->nlp_rpi
];
585 lpfc_unreg_login(phba
, vport
->vpi
, rpi
, link_mbox
);
586 link_mbox
->vport
= vport
;
587 link_mbox
->ctx_ndlp
= lpfc_nlp_get(ndlp
);
588 if (!link_mbox
->ctx_ndlp
)
591 link_mbox
->mbox_cmpl
= lpfc_defer_acc_rsp
;
593 if (((ndlp
->nlp_DID
& Fabric_DID_MASK
) != Fabric_DID_MASK
) &&
594 (!(vport
->fc_flag
& FC_OFFLINE_MODE
)))
595 ndlp
->nlp_flag
|= NLP_UNREG_INP
;
597 /* Save info from cmd IOCB used in rsp */
598 memcpy(save_iocb
, cmdiocb
, sizeof(*save_iocb
));
600 /* Delay sending ACC till unreg RPI completes. */
602 } else if (phba
->sli_rev
== LPFC_SLI_REV4
)
603 lpfc_unreg_rpi(vport
, ndlp
);
605 rc
= lpfc_reg_rpi(phba
, vport
->vpi
, icmd
->un
.rcvels
.remoteID
,
606 (uint8_t *)sp
, login_mbox
, ndlp
->nlp_rpi
);
610 /* ACC PLOGI rsp command needs to execute first,
611 * queue this login_mbox command to be processed later.
613 login_mbox
->mbox_cmpl
= lpfc_mbx_cmpl_reg_login
;
615 * login_mbox->ctx_ndlp = lpfc_nlp_get(ndlp) deferred until mailbox
616 * command issued in lpfc_cmpl_els_acc().
618 login_mbox
->vport
= vport
;
619 spin_lock_irq(&ndlp
->lock
);
620 ndlp
->nlp_flag
|= (NLP_ACC_REGLOGIN
| NLP_RCV_PLOGI
);
621 spin_unlock_irq(&ndlp
->lock
);
624 * If there is an outstanding PLOGI issued, abort it before
625 * sending ACC rsp for received PLOGI. If pending plogi
626 * is not canceled here, the plogi will be rejected by
627 * remote port and will be retried. On a configuration with
628 * single discovery thread, this will cause a huge delay in
629 * discovery. Also this will cause multiple state machines
630 * running in parallel for this node.
631 * This only applies to a fabric environment.
633 if ((ndlp
->nlp_state
== NLP_STE_PLOGI_ISSUE
) &&
634 (vport
->fc_flag
& FC_FABRIC
)) {
635 /* software abort outstanding PLOGI */
636 lpfc_els_abort(phba
, ndlp
);
639 if ((vport
->port_type
== LPFC_NPIV_PORT
&&
640 vport
->cfg_restrict_login
)) {
642 /* no deferred ACC */
645 /* In order to preserve RPIs, we want to cleanup
646 * the default RPI the firmware created to rcv
647 * this ELS request. The only way to do this is
648 * to register, then unregister the RPI.
650 spin_lock_irq(&ndlp
->lock
);
651 ndlp
->nlp_flag
|= NLP_RM_DFLT_RPI
;
652 spin_unlock_irq(&ndlp
->lock
);
653 stat
.un
.b
.lsRjtRsnCode
= LSRJT_INVALID_CMD
;
654 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_NOTHING_MORE
;
655 rc
= lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
,
658 mempool_free(login_mbox
, phba
->mbox_mem_pool
);
662 /* So the order here should be:
664 * Issue CONFIG_LINK mbox
667 * Issue UNREG RPI mbx
671 * Issue REG_LOGIN mbox
674 /* Save the REG_LOGIN mbox for and rcv IOCB copy later */
675 link_mbox
->context3
= login_mbox
;
676 login_mbox
->context3
= save_iocb
;
678 /* Start the ball rolling by issuing CONFIG_LINK here */
679 rc
= lpfc_sli_issue_mbox(phba
, link_mbox
, MBX_NOWAIT
);
680 if (rc
== MBX_NOT_FINISHED
)
685 rc
= lpfc_els_rsp_acc(vport
, ELS_CMD_PLOGI
, cmdiocb
, ndlp
, login_mbox
);
687 mempool_free(login_mbox
, phba
->mbox_mem_pool
);
691 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
692 "4577 discovery failure: %p %p %p\n",
693 save_iocb
, link_mbox
, login_mbox
);
696 mempool_free(link_mbox
, phba
->mbox_mem_pool
);
698 mempool_free(login_mbox
, phba
->mbox_mem_pool
);
700 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
701 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_OUT_OF_RESOURCE
;
702 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
707 * lpfc_mbx_cmpl_resume_rpi - Resume RPI completion routine
708 * @phba: pointer to lpfc hba data structure.
709 * @mboxq: pointer to mailbox object
711 * This routine is invoked to issue a completion to a rcv'ed
712 * ADISC or PDISC after the paused RPI has been resumed.
715 lpfc_mbx_cmpl_resume_rpi(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
717 struct lpfc_vport
*vport
;
718 struct lpfc_iocbq
*elsiocb
;
719 struct lpfc_nodelist
*ndlp
;
722 elsiocb
= (struct lpfc_iocbq
*)mboxq
->ctx_buf
;
723 ndlp
= (struct lpfc_nodelist
*)mboxq
->ctx_ndlp
;
724 vport
= mboxq
->vport
;
725 cmd
= elsiocb
->drvrTimeout
;
727 if (cmd
== ELS_CMD_ADISC
) {
728 lpfc_els_rsp_adisc_acc(vport
, elsiocb
, ndlp
);
730 lpfc_els_rsp_acc(vport
, ELS_CMD_PLOGI
, elsiocb
,
734 mempool_free(mboxq
, phba
->mbox_mem_pool
);
738 lpfc_rcv_padisc(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
739 struct lpfc_iocbq
*cmdiocb
)
741 struct lpfc_iocbq
*elsiocb
;
742 struct lpfc_dmabuf
*pcmd
;
743 struct serv_parm
*sp
;
744 struct lpfc_name
*pnn
, *ppn
;
751 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
752 lp
= (uint32_t *) pcmd
->virt
;
755 if (cmd
== ELS_CMD_ADISC
) {
757 pnn
= (struct lpfc_name
*) & ap
->nodeName
;
758 ppn
= (struct lpfc_name
*) & ap
->portName
;
760 sp
= (struct serv_parm
*) lp
;
761 pnn
= (struct lpfc_name
*) & sp
->nodeName
;
762 ppn
= (struct lpfc_name
*) & sp
->portName
;
765 icmd
= &cmdiocb
->iocb
;
766 if (icmd
->ulpStatus
== 0 && lpfc_check_adisc(vport
, ndlp
, pnn
, ppn
)) {
769 * As soon as we send ACC, the remote NPort can
770 * start sending us data. Thus, for SLI4 we must
771 * resume the RPI before the ACC goes out.
773 if (vport
->phba
->sli_rev
== LPFC_SLI_REV4
) {
774 elsiocb
= kmalloc(sizeof(struct lpfc_iocbq
),
778 /* Save info from cmd IOCB used in rsp */
779 memcpy((uint8_t *)elsiocb
, (uint8_t *)cmdiocb
,
780 sizeof(struct lpfc_iocbq
));
782 /* Save the ELS cmd */
783 elsiocb
->drvrTimeout
= cmd
;
785 lpfc_sli4_resume_rpi(ndlp
,
786 lpfc_mbx_cmpl_resume_rpi
, elsiocb
);
791 if (cmd
== ELS_CMD_ADISC
) {
792 lpfc_els_rsp_adisc_acc(vport
, cmdiocb
, ndlp
);
794 lpfc_els_rsp_acc(vport
, ELS_CMD_PLOGI
, cmdiocb
,
798 /* If we are authenticated, move to the proper state.
799 * It is possible an ADISC arrived and the remote nport
800 * is already in MAPPED or UNMAPPED state. Catch this
801 * condition and don't set the nlp_state again because
802 * it causes an unnecessary transport unregister/register.
804 if (ndlp
->nlp_type
& (NLP_FCP_TARGET
| NLP_NVME_TARGET
)) {
805 if (ndlp
->nlp_state
!= NLP_STE_MAPPED_NODE
)
806 lpfc_nlp_set_state(vport
, ndlp
,
807 NLP_STE_MAPPED_NODE
);
812 /* Reject this request because invalid parameters */
813 stat
.un
.b
.lsRjtRsvd0
= 0;
814 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
815 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_SPARM_OPTIONS
;
816 stat
.un
.b
.vendorUnique
= 0;
817 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
820 mod_timer(&ndlp
->nlp_delayfunc
, jiffies
+ msecs_to_jiffies(1000));
822 spin_lock_irq(&ndlp
->lock
);
823 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
824 spin_unlock_irq(&ndlp
->lock
);
825 ndlp
->nlp_last_elscmd
= ELS_CMD_PLOGI
;
826 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
827 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
832 lpfc_rcv_logo(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
833 struct lpfc_iocbq
*cmdiocb
, uint32_t els_cmd
)
835 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
836 struct lpfc_hba
*phba
= vport
->phba
;
837 struct lpfc_vport
**vports
;
838 int i
, active_vlink_present
= 0 ;
840 /* Put ndlp in NPR state with 1 sec timeout for plogi, ACC logo */
841 /* Only call LOGO ACC for first LOGO, this avoids sending unnecessary
842 * PLOGIs during LOGO storms from a device.
844 spin_lock_irq(&ndlp
->lock
);
845 ndlp
->nlp_flag
|= NLP_LOGO_ACC
;
846 spin_unlock_irq(&ndlp
->lock
);
847 if (els_cmd
== ELS_CMD_PRLO
)
848 lpfc_els_rsp_acc(vport
, ELS_CMD_PRLO
, cmdiocb
, ndlp
, NULL
);
850 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
852 /* Notify transport of connectivity loss to trigger cleanup. */
853 if (phba
->nvmet_support
&&
854 ndlp
->nlp_state
== NLP_STE_UNMAPPED_NODE
)
855 lpfc_nvmet_invalidate_host(phba
, ndlp
);
857 if (ndlp
->nlp_DID
== Fabric_DID
) {
858 if (vport
->port_state
<= LPFC_FDISC
)
860 lpfc_linkdown_port(vport
);
861 spin_lock_irq(shost
->host_lock
);
862 vport
->fc_flag
|= FC_VPORT_LOGO_RCVD
;
863 spin_unlock_irq(shost
->host_lock
);
864 vports
= lpfc_create_vport_work_array(phba
);
866 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
;
868 if ((!(vports
[i
]->fc_flag
&
869 FC_VPORT_LOGO_RCVD
)) &&
870 (vports
[i
]->port_state
> LPFC_FDISC
)) {
871 active_vlink_present
= 1;
875 lpfc_destroy_vport_work_array(phba
, vports
);
879 * Don't re-instantiate if vport is marked for deletion.
880 * If we are here first then vport_delete is going to wait
881 * for discovery to complete.
883 if (!(vport
->load_flag
& FC_UNLOADING
) &&
884 active_vlink_present
) {
886 * If there are other active VLinks present,
887 * re-instantiate the Vlink using FDISC.
889 mod_timer(&ndlp
->nlp_delayfunc
,
890 jiffies
+ msecs_to_jiffies(1000));
891 spin_lock_irq(&ndlp
->lock
);
892 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
893 spin_unlock_irq(&ndlp
->lock
);
894 ndlp
->nlp_last_elscmd
= ELS_CMD_FDISC
;
895 vport
->port_state
= LPFC_FDISC
;
897 spin_lock_irq(shost
->host_lock
);
898 phba
->pport
->fc_flag
&= ~FC_LOGO_RCVD_DID_CHNG
;
899 spin_unlock_irq(shost
->host_lock
);
900 lpfc_retry_pport_discovery(phba
);
902 } else if ((!(ndlp
->nlp_type
& NLP_FABRIC
) &&
903 ((ndlp
->nlp_type
& NLP_FCP_TARGET
) ||
904 !(ndlp
->nlp_type
& NLP_FCP_INITIATOR
))) ||
905 (ndlp
->nlp_state
== NLP_STE_ADISC_ISSUE
)) {
906 /* Only try to re-login if this is NOT a Fabric Node */
907 mod_timer(&ndlp
->nlp_delayfunc
,
908 jiffies
+ msecs_to_jiffies(1000 * 1));
909 spin_lock_irq(&ndlp
->lock
);
910 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
911 spin_unlock_irq(&ndlp
->lock
);
913 ndlp
->nlp_last_elscmd
= ELS_CMD_PLOGI
;
916 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
917 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
919 spin_lock_irq(&ndlp
->lock
);
920 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
921 spin_unlock_irq(&ndlp
->lock
);
922 /* The driver has to wait until the ACC completes before it continues
923 * processing the LOGO. The action will resume in
924 * lpfc_cmpl_els_logo_acc routine. Since part of processing includes an
925 * unreg_login, the driver waits so the ACC does not get aborted.
931 lpfc_rcv_prli_support_check(struct lpfc_vport
*vport
,
932 struct lpfc_nodelist
*ndlp
,
933 struct lpfc_iocbq
*cmdiocb
)
939 payload
= ((struct lpfc_dmabuf
*)cmdiocb
->context2
)->virt
;
941 if (vport
->phba
->nvmet_support
) {
942 /* Must be a NVME PRLI */
943 if (cmd
== ELS_CMD_PRLI
)
946 /* Initiator mode. */
947 if (!vport
->nvmei_support
&& (cmd
== ELS_CMD_NVMEPRLI
))
952 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_NVME_DISC
,
953 "6115 Rcv PRLI (%x) check failed: ndlp rpi %d "
954 "state x%x flags x%x\n",
955 cmd
, ndlp
->nlp_rpi
, ndlp
->nlp_state
,
957 memset(&stat
, 0, sizeof(struct ls_rjt
));
958 stat
.un
.b
.lsRjtRsnCode
= LSRJT_CMD_UNSUPPORTED
;
959 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_REQ_UNSUPPORTED
;
960 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
,
966 lpfc_rcv_prli(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
967 struct lpfc_iocbq
*cmdiocb
)
969 struct lpfc_hba
*phba
= vport
->phba
;
970 struct lpfc_dmabuf
*pcmd
;
973 struct fc_rport
*rport
= ndlp
->rport
;
976 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
977 lp
= (uint32_t *) pcmd
->virt
;
978 npr
= (PRLI
*) ((uint8_t *) lp
+ sizeof (uint32_t));
980 if ((npr
->prliType
== PRLI_FCP_TYPE
) ||
981 (npr
->prliType
== PRLI_NVME_TYPE
)) {
982 if (npr
->initiatorFunc
) {
983 if (npr
->prliType
== PRLI_FCP_TYPE
)
984 ndlp
->nlp_type
|= NLP_FCP_INITIATOR
;
985 if (npr
->prliType
== PRLI_NVME_TYPE
)
986 ndlp
->nlp_type
|= NLP_NVME_INITIATOR
;
988 if (npr
->targetFunc
) {
989 if (npr
->prliType
== PRLI_FCP_TYPE
)
990 ndlp
->nlp_type
|= NLP_FCP_TARGET
;
991 if (npr
->prliType
== PRLI_NVME_TYPE
)
992 ndlp
->nlp_type
|= NLP_NVME_TARGET
;
993 if (npr
->writeXferRdyDis
)
994 ndlp
->nlp_flag
|= NLP_FIRSTBURST
;
996 if (npr
->Retry
&& ndlp
->nlp_type
&
997 (NLP_FCP_INITIATOR
| NLP_FCP_TARGET
))
998 ndlp
->nlp_fcp_info
|= NLP_FCP_2_DEVICE
;
1000 if (npr
->Retry
&& phba
->nsler
&&
1001 ndlp
->nlp_type
& (NLP_NVME_INITIATOR
| NLP_NVME_TARGET
))
1002 ndlp
->nlp_nvme_info
|= NLP_NVME_NSLER
;
1005 /* If this driver is in nvme target mode, set the ndlp's fc4
1006 * type to NVME provided the PRLI response claims NVME FC4
1007 * type. Target mode does not issue gft_id so doesn't get
1008 * the fc4 type set until now.
1010 if (phba
->nvmet_support
&& (npr
->prliType
== PRLI_NVME_TYPE
)) {
1011 ndlp
->nlp_fc4_type
|= NLP_FC4_NVME
;
1012 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
1014 if (npr
->prliType
== PRLI_FCP_TYPE
)
1015 ndlp
->nlp_fc4_type
|= NLP_FC4_FCP
;
1018 /* We need to update the rport role values */
1019 roles
= FC_RPORT_ROLE_UNKNOWN
;
1020 if (ndlp
->nlp_type
& NLP_FCP_INITIATOR
)
1021 roles
|= FC_RPORT_ROLE_FCP_INITIATOR
;
1022 if (ndlp
->nlp_type
& NLP_FCP_TARGET
)
1023 roles
|= FC_RPORT_ROLE_FCP_TARGET
;
1025 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_RPORT
,
1026 "rport rolechg: role:x%x did:x%x flg:x%x",
1027 roles
, ndlp
->nlp_DID
, ndlp
->nlp_flag
);
1029 if (vport
->cfg_enable_fc4_type
!= LPFC_ENABLE_NVME
)
1030 fc_remote_port_rolechg(rport
, roles
);
1035 lpfc_disc_set_adisc(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
1037 if (!(ndlp
->nlp_flag
& NLP_RPI_REGISTERED
)) {
1038 spin_lock_irq(&ndlp
->lock
);
1039 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
1040 spin_unlock_irq(&ndlp
->lock
);
1044 if (!(vport
->fc_flag
& FC_PT2PT
)) {
1045 /* Check config parameter use-adisc or FCP-2 */
1046 if (vport
->cfg_use_adisc
&& ((vport
->fc_flag
& FC_RSCN_MODE
) ||
1047 ((ndlp
->nlp_fcp_info
& NLP_FCP_2_DEVICE
) &&
1048 (ndlp
->nlp_type
& NLP_FCP_TARGET
)))) {
1049 spin_lock_irq(&ndlp
->lock
);
1050 ndlp
->nlp_flag
|= NLP_NPR_ADISC
;
1051 spin_unlock_irq(&ndlp
->lock
);
1056 spin_lock_irq(&ndlp
->lock
);
1057 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
1058 spin_unlock_irq(&ndlp
->lock
);
1059 lpfc_unreg_rpi(vport
, ndlp
);
1064 * lpfc_release_rpi - Release a RPI by issuing unreg_login mailbox cmd.
1065 * @phba : Pointer to lpfc_hba structure.
1066 * @vport: Pointer to lpfc_vport structure.
1067 * @ndlp: Pointer to lpfc_nodelist structure.
1068 * @rpi : rpi to be release.
1070 * This function will send a unreg_login mailbox command to the firmware
1074 lpfc_release_rpi(struct lpfc_hba
*phba
, struct lpfc_vport
*vport
,
1075 struct lpfc_nodelist
*ndlp
, uint16_t rpi
)
1080 /* If there is already an UNREG in progress for this ndlp,
1081 * no need to queue up another one.
1083 if (ndlp
->nlp_flag
& NLP_UNREG_INP
) {
1084 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
1085 "1435 release_rpi SKIP UNREG x%x on "
1086 "NPort x%x deferred x%x flg x%x "
1088 ndlp
->nlp_rpi
, ndlp
->nlp_DID
,
1089 ndlp
->nlp_defer_did
,
1090 ndlp
->nlp_flag
, ndlp
);
1094 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
,
1097 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
1098 "2796 mailbox memory allocation failed \n");
1100 lpfc_unreg_login(phba
, vport
->vpi
, rpi
, pmb
);
1101 pmb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
1103 pmb
->ctx_ndlp
= lpfc_nlp_get(ndlp
);
1104 if (!pmb
->ctx_ndlp
) {
1105 mempool_free(pmb
, phba
->mbox_mem_pool
);
1109 if (((ndlp
->nlp_DID
& Fabric_DID_MASK
) != Fabric_DID_MASK
) &&
1110 (!(vport
->fc_flag
& FC_OFFLINE_MODE
)))
1111 ndlp
->nlp_flag
|= NLP_UNREG_INP
;
1113 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
1114 "1437 release_rpi UNREG x%x "
1115 "on NPort x%x flg x%x\n",
1116 ndlp
->nlp_rpi
, ndlp
->nlp_DID
, ndlp
->nlp_flag
);
1118 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
1119 if (rc
== MBX_NOT_FINISHED
)
1120 mempool_free(pmb
, phba
->mbox_mem_pool
);
1125 lpfc_disc_illegal(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1126 void *arg
, uint32_t evt
)
1128 struct lpfc_hba
*phba
;
1129 LPFC_MBOXQ_t
*pmb
= (LPFC_MBOXQ_t
*) arg
;
1133 /* Release the RPI if reglogin completing */
1134 if (!(phba
->pport
->load_flag
& FC_UNLOADING
) &&
1135 (evt
== NLP_EVT_CMPL_REG_LOGIN
) &&
1136 (!pmb
->u
.mb
.mbxStatus
)) {
1137 rpi
= pmb
->u
.mb
.un
.varWords
[0];
1138 lpfc_release_rpi(phba
, vport
, ndlp
, rpi
);
1140 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
1141 "0271 Illegal State Transition: node x%x "
1142 "event x%x, state x%x Data: x%x x%x\n",
1143 ndlp
->nlp_DID
, evt
, ndlp
->nlp_state
, ndlp
->nlp_rpi
,
1145 return ndlp
->nlp_state
;
1149 lpfc_cmpl_plogi_illegal(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1150 void *arg
, uint32_t evt
)
1152 /* This transition is only legal if we previously
1153 * rcv'ed a PLOGI. Since we don't want 2 discovery threads
1154 * working on the same NPortID, do nothing for this thread
1157 if (!(ndlp
->nlp_flag
& NLP_RCV_PLOGI
)) {
1158 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
1159 "0272 Illegal State Transition: node x%x "
1160 "event x%x, state x%x Data: x%x x%x\n",
1161 ndlp
->nlp_DID
, evt
, ndlp
->nlp_state
,
1162 ndlp
->nlp_rpi
, ndlp
->nlp_flag
);
1164 return ndlp
->nlp_state
;
1167 /* Start of Discovery State Machine routines */
1170 lpfc_rcv_plogi_unused_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1171 void *arg
, uint32_t evt
)
1173 struct lpfc_iocbq
*cmdiocb
;
1175 cmdiocb
= (struct lpfc_iocbq
*) arg
;
1177 if (lpfc_rcv_plogi(vport
, ndlp
, cmdiocb
)) {
1178 return ndlp
->nlp_state
;
1180 return NLP_STE_FREED_NODE
;
1184 lpfc_rcv_els_unused_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1185 void *arg
, uint32_t evt
)
1187 lpfc_issue_els_logo(vport
, ndlp
, 0);
1188 return ndlp
->nlp_state
;
1192 lpfc_rcv_logo_unused_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1193 void *arg
, uint32_t evt
)
1195 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1197 spin_lock_irq(&ndlp
->lock
);
1198 ndlp
->nlp_flag
|= NLP_LOGO_ACC
;
1199 spin_unlock_irq(&ndlp
->lock
);
1200 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
1202 return ndlp
->nlp_state
;
1206 lpfc_cmpl_logo_unused_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1207 void *arg
, uint32_t evt
)
1209 return NLP_STE_FREED_NODE
;
1213 lpfc_device_rm_unused_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1214 void *arg
, uint32_t evt
)
1216 return NLP_STE_FREED_NODE
;
1220 lpfc_device_recov_unused_node(struct lpfc_vport
*vport
,
1221 struct lpfc_nodelist
*ndlp
,
1222 void *arg
, uint32_t evt
)
1224 return ndlp
->nlp_state
;
1228 lpfc_rcv_plogi_plogi_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1229 void *arg
, uint32_t evt
)
1231 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1232 struct lpfc_hba
*phba
= vport
->phba
;
1233 struct lpfc_iocbq
*cmdiocb
= arg
;
1234 struct lpfc_dmabuf
*pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
1235 uint32_t *lp
= (uint32_t *) pcmd
->virt
;
1236 struct serv_parm
*sp
= (struct serv_parm
*) (lp
+ 1);
1240 memset(&stat
, 0, sizeof (struct ls_rjt
));
1242 /* For a PLOGI, we only accept if our portname is less
1243 * than the remote portname.
1245 phba
->fc_stat
.elsLogiCol
++;
1246 port_cmp
= memcmp(&vport
->fc_portname
, &sp
->portName
,
1247 sizeof(struct lpfc_name
));
1249 if (port_cmp
>= 0) {
1250 /* Reject this request because the remote node will accept
1252 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
1253 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CMD_IN_PROGRESS
;
1254 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
,
1257 if (lpfc_rcv_plogi(vport
, ndlp
, cmdiocb
) &&
1258 (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) &&
1259 (vport
->num_disc_nodes
)) {
1260 spin_lock_irq(&ndlp
->lock
);
1261 ndlp
->nlp_flag
&= ~NLP_NPR_2B_DISC
;
1262 spin_unlock_irq(&ndlp
->lock
);
1263 /* Check if there are more PLOGIs to be sent */
1264 lpfc_more_plogi(vport
);
1265 if (vport
->num_disc_nodes
== 0) {
1266 spin_lock_irq(shost
->host_lock
);
1267 vport
->fc_flag
&= ~FC_NDISC_ACTIVE
;
1268 spin_unlock_irq(shost
->host_lock
);
1269 lpfc_can_disctmo(vport
);
1270 lpfc_end_rscn(vport
);
1273 } /* If our portname was less */
1275 return ndlp
->nlp_state
;
1279 lpfc_rcv_prli_plogi_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1280 void *arg
, uint32_t evt
)
1282 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1285 memset(&stat
, 0, sizeof (struct ls_rjt
));
1286 stat
.un
.b
.lsRjtRsnCode
= LSRJT_LOGICAL_BSY
;
1287 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_NOTHING_MORE
;
1288 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
1289 return ndlp
->nlp_state
;
1293 lpfc_rcv_logo_plogi_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1294 void *arg
, uint32_t evt
)
1296 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1298 /* Retrieve RPI from LOGO IOCB. RPI is used for CMD_ABORT_XRI_CN */
1299 if (vport
->phba
->sli_rev
== LPFC_SLI_REV3
)
1300 ndlp
->nlp_rpi
= cmdiocb
->iocb
.ulpIoTag
;
1301 /* software abort outstanding PLOGI */
1302 lpfc_els_abort(vport
->phba
, ndlp
);
1304 lpfc_rcv_logo(vport
, ndlp
, cmdiocb
, ELS_CMD_LOGO
);
1305 return ndlp
->nlp_state
;
1309 lpfc_rcv_els_plogi_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1310 void *arg
, uint32_t evt
)
1312 struct lpfc_hba
*phba
= vport
->phba
;
1313 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1315 /* software abort outstanding PLOGI */
1316 lpfc_els_abort(phba
, ndlp
);
1318 if (evt
== NLP_EVT_RCV_LOGO
) {
1319 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
1321 lpfc_issue_els_logo(vport
, ndlp
, 0);
1324 /* Put ndlp in npr state set plogi timer for 1 sec */
1325 mod_timer(&ndlp
->nlp_delayfunc
, jiffies
+ msecs_to_jiffies(1000 * 1));
1326 spin_lock_irq(&ndlp
->lock
);
1327 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
1328 spin_unlock_irq(&ndlp
->lock
);
1329 ndlp
->nlp_last_elscmd
= ELS_CMD_PLOGI
;
1330 ndlp
->nlp_prev_state
= NLP_STE_PLOGI_ISSUE
;
1331 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1333 return ndlp
->nlp_state
;
1337 lpfc_cmpl_plogi_plogi_issue(struct lpfc_vport
*vport
,
1338 struct lpfc_nodelist
*ndlp
,
1342 struct lpfc_hba
*phba
= vport
->phba
;
1343 struct lpfc_iocbq
*cmdiocb
, *rspiocb
;
1344 struct lpfc_dmabuf
*pcmd
, *prsp
, *mp
;
1348 struct serv_parm
*sp
;
1353 cmdiocb
= (struct lpfc_iocbq
*) arg
;
1354 rspiocb
= cmdiocb
->context_un
.rsp_iocb
;
1356 if (ndlp
->nlp_flag
& NLP_ACC_REGLOGIN
) {
1357 /* Recovery from PLOGI collision logic */
1358 return ndlp
->nlp_state
;
1361 irsp
= &rspiocb
->iocb
;
1363 if (irsp
->ulpStatus
)
1366 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
1368 prsp
= list_get_first(&pcmd
->list
, struct lpfc_dmabuf
, list
);
1372 lp
= (uint32_t *) prsp
->virt
;
1373 sp
= (struct serv_parm
*) ((uint8_t *) lp
+ sizeof (uint32_t));
1375 /* Some switches have FDMI servers returning 0 for WWN */
1376 if ((ndlp
->nlp_DID
!= FDMI_DID
) &&
1377 (wwn_to_u64(sp
->portName
.u
.wwn
) == 0 ||
1378 wwn_to_u64(sp
->nodeName
.u
.wwn
) == 0)) {
1379 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
1380 "0142 PLOGI RSP: Invalid WWN.\n");
1383 if (!lpfc_check_sparm(vport
, ndlp
, sp
, CLASS3
, 0))
1385 /* PLOGI chkparm OK */
1386 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
1387 "0121 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
1388 ndlp
->nlp_DID
, ndlp
->nlp_state
,
1389 ndlp
->nlp_flag
, ndlp
->nlp_rpi
);
1390 if (vport
->cfg_fcp_class
== 2 && (sp
->cls2
.classValid
))
1391 ndlp
->nlp_fcp_info
|= CLASS2
;
1393 ndlp
->nlp_fcp_info
|= CLASS3
;
1395 ndlp
->nlp_class_sup
= 0;
1396 if (sp
->cls1
.classValid
)
1397 ndlp
->nlp_class_sup
|= FC_COS_CLASS1
;
1398 if (sp
->cls2
.classValid
)
1399 ndlp
->nlp_class_sup
|= FC_COS_CLASS2
;
1400 if (sp
->cls3
.classValid
)
1401 ndlp
->nlp_class_sup
|= FC_COS_CLASS3
;
1402 if (sp
->cls4
.classValid
)
1403 ndlp
->nlp_class_sup
|= FC_COS_CLASS4
;
1404 ndlp
->nlp_maxframe
=
1405 ((sp
->cmn
.bbRcvSizeMsb
& 0x0F) << 8) | sp
->cmn
.bbRcvSizeLsb
;
1407 if ((vport
->fc_flag
& FC_PT2PT
) &&
1408 (vport
->fc_flag
& FC_PT2PT_PLOGI
)) {
1409 ed_tov
= be32_to_cpu(sp
->cmn
.e_d_tov
);
1410 if (sp
->cmn
.edtovResolution
) {
1411 /* E_D_TOV ticks are in nanoseconds */
1412 ed_tov
= (phba
->fc_edtov
+ 999999) / 1000000;
1415 ndlp
->nlp_flag
&= ~NLP_SUPPRESS_RSP
;
1416 if ((phba
->sli
.sli_flag
& LPFC_SLI_SUPPRESS_RSP
) &&
1417 sp
->cmn
.valid_vendor_ver_level
) {
1418 vid
= be32_to_cpu(sp
->un
.vv
.vid
);
1419 flag
= be32_to_cpu(sp
->un
.vv
.flags
);
1420 if ((vid
== LPFC_VV_EMLX_ID
) &&
1421 (flag
& LPFC_VV_SUPPRESS_RSP
))
1422 ndlp
->nlp_flag
|= NLP_SUPPRESS_RSP
;
1426 * Use the larger EDTOV
1427 * RATOV = 2 * EDTOV for pt-to-pt
1429 if (ed_tov
> phba
->fc_edtov
)
1430 phba
->fc_edtov
= ed_tov
;
1431 phba
->fc_ratov
= (2 * phba
->fc_edtov
) / 1000;
1433 memcpy(&phba
->fc_fabparam
, sp
, sizeof(struct serv_parm
));
1435 /* Issue config_link / reg_vfi to account for updated TOV's */
1436 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
1437 lpfc_issue_reg_vfi(vport
);
1439 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1441 lpfc_printf_vlog(vport
, KERN_ERR
,
1443 "0133 PLOGI: no memory "
1445 "Data: x%x x%x x%x x%x\n",
1446 ndlp
->nlp_DID
, ndlp
->nlp_state
,
1447 ndlp
->nlp_flag
, ndlp
->nlp_rpi
);
1451 lpfc_config_link(phba
, mbox
);
1453 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
1454 mbox
->vport
= vport
;
1455 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
1456 if (rc
== MBX_NOT_FINISHED
) {
1457 mempool_free(mbox
, phba
->mbox_mem_pool
);
1463 lpfc_unreg_rpi(vport
, ndlp
);
1465 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1467 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
1468 "0018 PLOGI: no memory for reg_login "
1469 "Data: x%x x%x x%x x%x\n",
1470 ndlp
->nlp_DID
, ndlp
->nlp_state
,
1471 ndlp
->nlp_flag
, ndlp
->nlp_rpi
);
1475 if (lpfc_reg_rpi(phba
, vport
->vpi
, irsp
->un
.elsreq64
.remoteID
,
1476 (uint8_t *) sp
, mbox
, ndlp
->nlp_rpi
) == 0) {
1477 switch (ndlp
->nlp_DID
) {
1478 case NameServer_DID
:
1479 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_ns_reg_login
;
1482 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_fdmi_reg_login
;
1485 ndlp
->nlp_flag
|= NLP_REG_LOGIN_SEND
;
1486 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_reg_login
;
1489 mbox
->ctx_ndlp
= lpfc_nlp_get(ndlp
);
1490 if (!mbox
->ctx_ndlp
)
1493 mbox
->vport
= vport
;
1494 if (lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
)
1495 != MBX_NOT_FINISHED
) {
1496 lpfc_nlp_set_state(vport
, ndlp
,
1497 NLP_STE_REG_LOGIN_ISSUE
);
1498 return ndlp
->nlp_state
;
1500 if (ndlp
->nlp_flag
& NLP_REG_LOGIN_SEND
)
1501 ndlp
->nlp_flag
&= ~NLP_REG_LOGIN_SEND
;
1502 /* decrement node reference count to the failed mbox
1506 mp
= (struct lpfc_dmabuf
*)mbox
->ctx_buf
;
1507 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
1509 mempool_free(mbox
, phba
->mbox_mem_pool
);
1511 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
1512 "0134 PLOGI: cannot issue reg_login "
1513 "Data: x%x x%x x%x x%x\n",
1514 ndlp
->nlp_DID
, ndlp
->nlp_state
,
1515 ndlp
->nlp_flag
, ndlp
->nlp_rpi
);
1517 mempool_free(mbox
, phba
->mbox_mem_pool
);
1519 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
1520 "0135 PLOGI: cannot format reg_login "
1521 "Data: x%x x%x x%x x%x\n",
1522 ndlp
->nlp_DID
, ndlp
->nlp_state
,
1523 ndlp
->nlp_flag
, ndlp
->nlp_rpi
);
1528 if (ndlp
->nlp_DID
== NameServer_DID
) {
1529 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
1530 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
1531 "0261 Cannot Register NameServer login\n");
1535 ** In case the node reference counter does not go to zero, ensure that
1536 ** the stale state for the node is not processed.
1539 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
1540 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1541 return NLP_STE_FREED_NODE
;
1545 lpfc_cmpl_logo_plogi_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1546 void *arg
, uint32_t evt
)
1548 return ndlp
->nlp_state
;
1552 lpfc_cmpl_reglogin_plogi_issue(struct lpfc_vport
*vport
,
1553 struct lpfc_nodelist
*ndlp
, void *arg
, uint32_t evt
)
1555 struct lpfc_hba
*phba
;
1556 LPFC_MBOXQ_t
*pmb
= (LPFC_MBOXQ_t
*) arg
;
1557 MAILBOX_t
*mb
= &pmb
->u
.mb
;
1561 /* Release the RPI */
1562 if (!(phba
->pport
->load_flag
& FC_UNLOADING
) &&
1564 rpi
= pmb
->u
.mb
.un
.varWords
[0];
1565 lpfc_release_rpi(phba
, vport
, ndlp
, rpi
);
1567 return ndlp
->nlp_state
;
1571 lpfc_device_rm_plogi_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1572 void *arg
, uint32_t evt
)
1574 if (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) {
1575 spin_lock_irq(&ndlp
->lock
);
1576 ndlp
->nlp_flag
|= NLP_NODEV_REMOVE
;
1577 spin_unlock_irq(&ndlp
->lock
);
1578 return ndlp
->nlp_state
;
1580 /* software abort outstanding PLOGI */
1581 lpfc_els_abort(vport
->phba
, ndlp
);
1583 lpfc_drop_node(vport
, ndlp
);
1584 return NLP_STE_FREED_NODE
;
1589 lpfc_device_recov_plogi_issue(struct lpfc_vport
*vport
,
1590 struct lpfc_nodelist
*ndlp
,
1594 struct lpfc_hba
*phba
= vport
->phba
;
1596 /* Don't do anything that will mess up processing of the
1599 if (vport
->fc_flag
& FC_RSCN_DEFERRED
)
1600 return ndlp
->nlp_state
;
1602 /* software abort outstanding PLOGI */
1603 lpfc_els_abort(phba
, ndlp
);
1605 ndlp
->nlp_prev_state
= NLP_STE_PLOGI_ISSUE
;
1606 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1607 spin_lock_irq(&ndlp
->lock
);
1608 ndlp
->nlp_flag
&= ~(NLP_NODEV_REMOVE
| NLP_NPR_2B_DISC
);
1609 spin_unlock_irq(&ndlp
->lock
);
1611 return ndlp
->nlp_state
;
1615 lpfc_rcv_plogi_adisc_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1616 void *arg
, uint32_t evt
)
1618 struct lpfc_hba
*phba
= vport
->phba
;
1619 struct lpfc_iocbq
*cmdiocb
;
1621 /* software abort outstanding ADISC */
1622 lpfc_els_abort(phba
, ndlp
);
1624 cmdiocb
= (struct lpfc_iocbq
*) arg
;
1626 if (lpfc_rcv_plogi(vport
, ndlp
, cmdiocb
)) {
1627 if (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) {
1628 spin_lock_irq(&ndlp
->lock
);
1629 ndlp
->nlp_flag
&= ~NLP_NPR_2B_DISC
;
1630 spin_unlock_irq(&ndlp
->lock
);
1631 if (vport
->num_disc_nodes
)
1632 lpfc_more_adisc(vport
);
1634 return ndlp
->nlp_state
;
1636 ndlp
->nlp_prev_state
= NLP_STE_ADISC_ISSUE
;
1637 lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0);
1638 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
1640 return ndlp
->nlp_state
;
1644 lpfc_rcv_prli_adisc_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1645 void *arg
, uint32_t evt
)
1647 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1649 if (lpfc_rcv_prli_support_check(vport
, ndlp
, cmdiocb
))
1650 lpfc_els_rsp_prli_acc(vport
, cmdiocb
, ndlp
);
1651 return ndlp
->nlp_state
;
1655 lpfc_rcv_logo_adisc_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1656 void *arg
, uint32_t evt
)
1658 struct lpfc_hba
*phba
= vport
->phba
;
1659 struct lpfc_iocbq
*cmdiocb
;
1661 cmdiocb
= (struct lpfc_iocbq
*) arg
;
1663 /* software abort outstanding ADISC */
1664 lpfc_els_abort(phba
, ndlp
);
1666 lpfc_rcv_logo(vport
, ndlp
, cmdiocb
, ELS_CMD_LOGO
);
1667 return ndlp
->nlp_state
;
1671 lpfc_rcv_padisc_adisc_issue(struct lpfc_vport
*vport
,
1672 struct lpfc_nodelist
*ndlp
,
1673 void *arg
, uint32_t evt
)
1675 struct lpfc_iocbq
*cmdiocb
;
1677 cmdiocb
= (struct lpfc_iocbq
*) arg
;
1679 lpfc_rcv_padisc(vport
, ndlp
, cmdiocb
);
1680 return ndlp
->nlp_state
;
1684 lpfc_rcv_prlo_adisc_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1685 void *arg
, uint32_t evt
)
1687 struct lpfc_iocbq
*cmdiocb
;
1689 cmdiocb
= (struct lpfc_iocbq
*) arg
;
1691 /* Treat like rcv logo */
1692 lpfc_rcv_logo(vport
, ndlp
, cmdiocb
, ELS_CMD_PRLO
);
1693 return ndlp
->nlp_state
;
1697 lpfc_cmpl_adisc_adisc_issue(struct lpfc_vport
*vport
,
1698 struct lpfc_nodelist
*ndlp
,
1699 void *arg
, uint32_t evt
)
1701 struct lpfc_hba
*phba
= vport
->phba
;
1702 struct lpfc_iocbq
*cmdiocb
, *rspiocb
;
1707 cmdiocb
= (struct lpfc_iocbq
*) arg
;
1708 rspiocb
= cmdiocb
->context_un
.rsp_iocb
;
1710 ap
= (ADISC
*)lpfc_check_elscmpl_iocb(phba
, cmdiocb
, rspiocb
);
1711 irsp
= &rspiocb
->iocb
;
1713 if ((irsp
->ulpStatus
) ||
1714 (!lpfc_check_adisc(vport
, ndlp
, &ap
->nodeName
, &ap
->portName
))) {
1716 mod_timer(&ndlp
->nlp_delayfunc
,
1717 jiffies
+ msecs_to_jiffies(1000));
1718 spin_lock_irq(&ndlp
->lock
);
1719 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
1720 spin_unlock_irq(&ndlp
->lock
);
1721 ndlp
->nlp_last_elscmd
= ELS_CMD_PLOGI
;
1723 memset(&ndlp
->nlp_nodename
, 0, sizeof(struct lpfc_name
));
1724 memset(&ndlp
->nlp_portname
, 0, sizeof(struct lpfc_name
));
1726 ndlp
->nlp_prev_state
= NLP_STE_ADISC_ISSUE
;
1727 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1728 lpfc_unreg_rpi(vport
, ndlp
);
1729 return ndlp
->nlp_state
;
1732 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
1733 rc
= lpfc_sli4_resume_rpi(ndlp
, NULL
, NULL
);
1735 /* Stay in state and retry. */
1736 ndlp
->nlp_prev_state
= NLP_STE_ADISC_ISSUE
;
1737 return ndlp
->nlp_state
;
1741 if (ndlp
->nlp_type
& NLP_FCP_TARGET
)
1742 ndlp
->nlp_fc4_type
|= NLP_FC4_FCP
;
1744 if (ndlp
->nlp_type
& NLP_NVME_TARGET
)
1745 ndlp
->nlp_fc4_type
|= NLP_FC4_NVME
;
1747 if (ndlp
->nlp_type
& (NLP_FCP_TARGET
| NLP_NVME_TARGET
)) {
1748 ndlp
->nlp_prev_state
= NLP_STE_ADISC_ISSUE
;
1749 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_MAPPED_NODE
);
1751 ndlp
->nlp_prev_state
= NLP_STE_ADISC_ISSUE
;
1752 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
1755 return ndlp
->nlp_state
;
1759 lpfc_device_rm_adisc_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1760 void *arg
, uint32_t evt
)
1762 if (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) {
1763 spin_lock_irq(&ndlp
->lock
);
1764 ndlp
->nlp_flag
|= NLP_NODEV_REMOVE
;
1765 spin_unlock_irq(&ndlp
->lock
);
1766 return ndlp
->nlp_state
;
1768 /* software abort outstanding ADISC */
1769 lpfc_els_abort(vport
->phba
, ndlp
);
1771 lpfc_drop_node(vport
, ndlp
);
1772 return NLP_STE_FREED_NODE
;
1777 lpfc_device_recov_adisc_issue(struct lpfc_vport
*vport
,
1778 struct lpfc_nodelist
*ndlp
,
1782 struct lpfc_hba
*phba
= vport
->phba
;
1784 /* Don't do anything that will mess up processing of the
1787 if (vport
->fc_flag
& FC_RSCN_DEFERRED
)
1788 return ndlp
->nlp_state
;
1790 /* software abort outstanding ADISC */
1791 lpfc_els_abort(phba
, ndlp
);
1793 ndlp
->nlp_prev_state
= NLP_STE_ADISC_ISSUE
;
1794 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1795 spin_lock_irq(&ndlp
->lock
);
1796 ndlp
->nlp_flag
&= ~(NLP_NODEV_REMOVE
| NLP_NPR_2B_DISC
);
1797 spin_unlock_irq(&ndlp
->lock
);
1798 lpfc_disc_set_adisc(vport
, ndlp
);
1799 return ndlp
->nlp_state
;
1803 lpfc_rcv_plogi_reglogin_issue(struct lpfc_vport
*vport
,
1804 struct lpfc_nodelist
*ndlp
,
1808 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1810 lpfc_rcv_plogi(vport
, ndlp
, cmdiocb
);
1811 return ndlp
->nlp_state
;
1815 lpfc_rcv_prli_reglogin_issue(struct lpfc_vport
*vport
,
1816 struct lpfc_nodelist
*ndlp
,
1820 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1823 if (!lpfc_rcv_prli_support_check(vport
, ndlp
, cmdiocb
)) {
1824 return ndlp
->nlp_state
;
1826 if (vport
->phba
->nvmet_support
) {
1827 /* NVME Target mode. Handle and respond to the PRLI and
1828 * transition to UNMAPPED provided the RPI has completed
1831 if (ndlp
->nlp_flag
& NLP_RPI_REGISTERED
) {
1832 lpfc_rcv_prli(vport
, ndlp
, cmdiocb
);
1833 lpfc_els_rsp_prli_acc(vport
, cmdiocb
, ndlp
);
1835 /* RPI registration has not completed. Reject the PRLI
1836 * to prevent an illegal state transition when the
1837 * rpi registration does complete.
1839 memset(&stat
, 0, sizeof(struct ls_rjt
));
1840 stat
.un
.b
.lsRjtRsnCode
= LSRJT_LOGICAL_BSY
;
1841 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_NOTHING_MORE
;
1842 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
,
1844 return ndlp
->nlp_state
;
1847 /* Initiator mode. */
1848 lpfc_els_rsp_prli_acc(vport
, cmdiocb
, ndlp
);
1850 return ndlp
->nlp_state
;
1854 lpfc_rcv_logo_reglogin_issue(struct lpfc_vport
*vport
,
1855 struct lpfc_nodelist
*ndlp
,
1859 struct lpfc_hba
*phba
= vport
->phba
;
1860 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1862 LPFC_MBOXQ_t
*nextmb
;
1863 struct lpfc_dmabuf
*mp
;
1864 struct lpfc_nodelist
*ns_ndlp
;
1866 cmdiocb
= (struct lpfc_iocbq
*) arg
;
1868 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
1869 if ((mb
= phba
->sli
.mbox_active
)) {
1870 if ((mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) &&
1871 (ndlp
== (struct lpfc_nodelist
*)mb
->ctx_ndlp
)) {
1872 ndlp
->nlp_flag
&= ~NLP_REG_LOGIN_SEND
;
1874 mb
->ctx_ndlp
= NULL
;
1875 mb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
1879 spin_lock_irq(&phba
->hbalock
);
1880 list_for_each_entry_safe(mb
, nextmb
, &phba
->sli
.mboxq
, list
) {
1881 if ((mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) &&
1882 (ndlp
== (struct lpfc_nodelist
*)mb
->ctx_ndlp
)) {
1883 mp
= (struct lpfc_dmabuf
*)(mb
->ctx_buf
);
1885 __lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
1888 ndlp
->nlp_flag
&= ~NLP_REG_LOGIN_SEND
;
1890 list_del(&mb
->list
);
1891 phba
->sli
.mboxq_cnt
--;
1892 mempool_free(mb
, phba
->mbox_mem_pool
);
1895 spin_unlock_irq(&phba
->hbalock
);
1897 /* software abort if any GID_FT is outstanding */
1898 if (vport
->cfg_enable_fc4_type
!= LPFC_ENABLE_FCP
) {
1899 ns_ndlp
= lpfc_findnode_did(vport
, NameServer_DID
);
1901 lpfc_els_abort(phba
, ns_ndlp
);
1904 lpfc_rcv_logo(vport
, ndlp
, cmdiocb
, ELS_CMD_LOGO
);
1905 return ndlp
->nlp_state
;
1909 lpfc_rcv_padisc_reglogin_issue(struct lpfc_vport
*vport
,
1910 struct lpfc_nodelist
*ndlp
,
1914 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1916 lpfc_rcv_padisc(vport
, ndlp
, cmdiocb
);
1917 return ndlp
->nlp_state
;
1921 lpfc_rcv_prlo_reglogin_issue(struct lpfc_vport
*vport
,
1922 struct lpfc_nodelist
*ndlp
,
1926 struct lpfc_iocbq
*cmdiocb
;
1928 cmdiocb
= (struct lpfc_iocbq
*) arg
;
1929 lpfc_els_rsp_acc(vport
, ELS_CMD_PRLO
, cmdiocb
, ndlp
, NULL
);
1930 return ndlp
->nlp_state
;
1934 lpfc_cmpl_reglogin_reglogin_issue(struct lpfc_vport
*vport
,
1935 struct lpfc_nodelist
*ndlp
,
1939 struct lpfc_hba
*phba
= vport
->phba
;
1940 LPFC_MBOXQ_t
*pmb
= (LPFC_MBOXQ_t
*) arg
;
1941 MAILBOX_t
*mb
= &pmb
->u
.mb
;
1942 uint32_t did
= mb
->un
.varWords
[1];
1944 if (mb
->mbxStatus
) {
1945 /* RegLogin failed */
1946 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
1947 "0246 RegLogin failed Data: x%x x%x x%x x%x "
1949 did
, mb
->mbxStatus
, vport
->port_state
,
1950 mb
->un
.varRegLogin
.vpi
,
1951 mb
->un
.varRegLogin
.rpi
);
1953 * If RegLogin failed due to lack of HBA resources do not
1956 if (mb
->mbxStatus
== MBXERR_RPI_FULL
) {
1957 ndlp
->nlp_prev_state
= NLP_STE_REG_LOGIN_ISSUE
;
1958 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1959 return ndlp
->nlp_state
;
1962 /* Put ndlp in npr state set plogi timer for 1 sec */
1963 mod_timer(&ndlp
->nlp_delayfunc
,
1964 jiffies
+ msecs_to_jiffies(1000 * 1));
1965 spin_lock_irq(&ndlp
->lock
);
1966 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
1967 spin_unlock_irq(&ndlp
->lock
);
1968 ndlp
->nlp_last_elscmd
= ELS_CMD_PLOGI
;
1970 lpfc_issue_els_logo(vport
, ndlp
, 0);
1971 ndlp
->nlp_prev_state
= NLP_STE_REG_LOGIN_ISSUE
;
1972 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1973 return ndlp
->nlp_state
;
1976 /* SLI4 ports have preallocated logical rpis. */
1977 if (phba
->sli_rev
< LPFC_SLI_REV4
)
1978 ndlp
->nlp_rpi
= mb
->un
.varWords
[0];
1980 ndlp
->nlp_flag
|= NLP_RPI_REGISTERED
;
1982 /* Only if we are not a fabric nport do we issue PRLI */
1983 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
1984 "3066 RegLogin Complete on x%x x%x x%x\n",
1985 did
, ndlp
->nlp_type
, ndlp
->nlp_fc4_type
);
1986 if (!(ndlp
->nlp_type
& NLP_FABRIC
) &&
1987 (phba
->nvmet_support
== 0)) {
1988 /* The driver supports FCP and NVME concurrently. If the
1989 * ndlp's nlp_fc4_type is still zero, the driver doesn't
1990 * know what PRLI to send yet. Figure that out now and
1991 * call PRLI depending on the outcome.
1993 if (vport
->fc_flag
& FC_PT2PT
) {
1994 /* If we are pt2pt, there is no Fabric to determine
1995 * the FC4 type of the remote nport. So if NVME
1996 * is configured try it.
1998 ndlp
->nlp_fc4_type
|= NLP_FC4_FCP
;
1999 if ((vport
->cfg_enable_fc4_type
== LPFC_ENABLE_BOTH
) ||
2000 (vport
->cfg_enable_fc4_type
== LPFC_ENABLE_NVME
)) {
2001 ndlp
->nlp_fc4_type
|= NLP_FC4_NVME
;
2002 /* We need to update the localport also */
2003 lpfc_nvme_update_localport(vport
);
2006 } else if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) {
2007 ndlp
->nlp_fc4_type
|= NLP_FC4_FCP
;
2009 } else if (ndlp
->nlp_fc4_type
== 0) {
2010 /* If we are only configured for FCP, the driver
2011 * should just issue PRLI for FCP. Otherwise issue
2012 * GFT_ID to determine if remote port supports NVME.
2014 if (vport
->cfg_enable_fc4_type
!= LPFC_ENABLE_FCP
) {
2015 lpfc_ns_cmd(vport
, SLI_CTNS_GFT_ID
, 0,
2017 return ndlp
->nlp_state
;
2019 ndlp
->nlp_fc4_type
= NLP_FC4_FCP
;
2022 ndlp
->nlp_prev_state
= NLP_STE_REG_LOGIN_ISSUE
;
2023 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PRLI_ISSUE
);
2024 if (lpfc_issue_els_prli(vport
, ndlp
, 0)) {
2025 lpfc_issue_els_logo(vport
, ndlp
, 0);
2026 ndlp
->nlp_prev_state
= NLP_STE_REG_LOGIN_ISSUE
;
2027 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
2030 if ((vport
->fc_flag
& FC_PT2PT
) && phba
->nvmet_support
)
2031 phba
->targetport
->port_id
= vport
->fc_myDID
;
2033 /* Only Fabric ports should transition. NVME target
2034 * must complete PRLI.
2036 if (ndlp
->nlp_type
& NLP_FABRIC
) {
2037 ndlp
->nlp_prev_state
= NLP_STE_REG_LOGIN_ISSUE
;
2038 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
2041 return ndlp
->nlp_state
;
2045 lpfc_device_rm_reglogin_issue(struct lpfc_vport
*vport
,
2046 struct lpfc_nodelist
*ndlp
,
2050 if (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) {
2051 spin_lock_irq(&ndlp
->lock
);
2052 ndlp
->nlp_flag
|= NLP_NODEV_REMOVE
;
2053 spin_unlock_irq(&ndlp
->lock
);
2054 return ndlp
->nlp_state
;
2056 lpfc_drop_node(vport
, ndlp
);
2057 return NLP_STE_FREED_NODE
;
2062 lpfc_device_recov_reglogin_issue(struct lpfc_vport
*vport
,
2063 struct lpfc_nodelist
*ndlp
,
2067 /* Don't do anything that will mess up processing of the
2070 if (vport
->fc_flag
& FC_RSCN_DEFERRED
)
2071 return ndlp
->nlp_state
;
2073 ndlp
->nlp_prev_state
= NLP_STE_REG_LOGIN_ISSUE
;
2074 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
2075 spin_lock_irq(&ndlp
->lock
);
2077 /* If we are a target we won't immediately transition into PRLI,
2078 * so if REG_LOGIN already completed we don't need to ignore it.
2080 if (!(ndlp
->nlp_flag
& NLP_RPI_REGISTERED
) ||
2081 !vport
->phba
->nvmet_support
)
2082 ndlp
->nlp_flag
|= NLP_IGNR_REG_CMPL
;
2084 ndlp
->nlp_flag
&= ~(NLP_NODEV_REMOVE
| NLP_NPR_2B_DISC
);
2085 spin_unlock_irq(&ndlp
->lock
);
2086 lpfc_disc_set_adisc(vport
, ndlp
);
2087 return ndlp
->nlp_state
;
2091 lpfc_rcv_plogi_prli_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2092 void *arg
, uint32_t evt
)
2094 struct lpfc_iocbq
*cmdiocb
;
2096 cmdiocb
= (struct lpfc_iocbq
*) arg
;
2098 lpfc_rcv_plogi(vport
, ndlp
, cmdiocb
);
2099 return ndlp
->nlp_state
;
2103 lpfc_rcv_prli_prli_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2104 void *arg
, uint32_t evt
)
2106 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2108 if (!lpfc_rcv_prli_support_check(vport
, ndlp
, cmdiocb
))
2109 return ndlp
->nlp_state
;
2110 lpfc_els_rsp_prli_acc(vport
, cmdiocb
, ndlp
);
2111 return ndlp
->nlp_state
;
2115 lpfc_rcv_logo_prli_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2116 void *arg
, uint32_t evt
)
2118 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2120 /* Software abort outstanding PRLI before sending acc */
2121 lpfc_els_abort(vport
->phba
, ndlp
);
2123 lpfc_rcv_logo(vport
, ndlp
, cmdiocb
, ELS_CMD_LOGO
);
2124 return ndlp
->nlp_state
;
2128 lpfc_rcv_padisc_prli_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2129 void *arg
, uint32_t evt
)
2131 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2133 lpfc_rcv_padisc(vport
, ndlp
, cmdiocb
);
2134 return ndlp
->nlp_state
;
2137 /* This routine is envoked when we rcv a PRLO request from a nport
2138 * we are logged into. We should send back a PRLO rsp setting the
2140 * NEXT STATE = PRLI_ISSUE
2143 lpfc_rcv_prlo_prli_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2144 void *arg
, uint32_t evt
)
2146 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2148 lpfc_els_rsp_acc(vport
, ELS_CMD_PRLO
, cmdiocb
, ndlp
, NULL
);
2149 return ndlp
->nlp_state
;
2153 lpfc_cmpl_prli_prli_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2154 void *arg
, uint32_t evt
)
2156 struct lpfc_iocbq
*cmdiocb
, *rspiocb
;
2157 struct lpfc_hba
*phba
= vport
->phba
;
2160 struct lpfc_nvme_prli
*nvpr
;
2163 cmdiocb
= (struct lpfc_iocbq
*) arg
;
2164 rspiocb
= cmdiocb
->context_un
.rsp_iocb
;
2166 /* A solicited PRLI is either FCP or NVME. The PRLI cmd/rsp
2167 * format is different so NULL the two PRLI types so that the
2168 * driver correctly gets the correct context.
2172 temp_ptr
= lpfc_check_elscmpl_iocb(phba
, cmdiocb
, rspiocb
);
2173 if (cmdiocb
->iocb_flag
& LPFC_PRLI_FCP_REQ
)
2174 npr
= (PRLI
*) temp_ptr
;
2175 else if (cmdiocb
->iocb_flag
& LPFC_PRLI_NVME_REQ
)
2176 nvpr
= (struct lpfc_nvme_prli
*) temp_ptr
;
2178 irsp
= &rspiocb
->iocb
;
2179 if (irsp
->ulpStatus
) {
2180 if ((vport
->port_type
== LPFC_NPIV_PORT
) &&
2181 vport
->cfg_restrict_login
) {
2185 /* Adjust the nlp_type accordingly if the PRLI failed */
2187 ndlp
->nlp_fc4_type
&= ~NLP_FC4_FCP
;
2189 ndlp
->nlp_fc4_type
&= ~NLP_FC4_NVME
;
2191 /* We can't set the DSM state till BOTH PRLIs complete */
2195 if (npr
&& (npr
->acceptRspCode
== PRLI_REQ_EXECUTED
) &&
2196 (npr
->prliType
== PRLI_FCP_TYPE
)) {
2197 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NVME_DISC
,
2198 "6028 FCP NPR PRLI Cmpl Init %d Target %d\n",
2201 if (npr
->initiatorFunc
)
2202 ndlp
->nlp_type
|= NLP_FCP_INITIATOR
;
2203 if (npr
->targetFunc
) {
2204 ndlp
->nlp_type
|= NLP_FCP_TARGET
;
2205 if (npr
->writeXferRdyDis
)
2206 ndlp
->nlp_flag
|= NLP_FIRSTBURST
;
2209 ndlp
->nlp_fcp_info
|= NLP_FCP_2_DEVICE
;
2212 (bf_get_be32(prli_acc_rsp_code
, nvpr
) ==
2213 PRLI_REQ_EXECUTED
) &&
2214 (bf_get_be32(prli_type_code
, nvpr
) ==
2217 /* Complete setting up the remote ndlp personality. */
2218 if (bf_get_be32(prli_init
, nvpr
))
2219 ndlp
->nlp_type
|= NLP_NVME_INITIATOR
;
2221 if (phba
->nsler
&& bf_get_be32(prli_nsler
, nvpr
) &&
2222 bf_get_be32(prli_conf
, nvpr
))
2224 ndlp
->nlp_nvme_info
|= NLP_NVME_NSLER
;
2226 ndlp
->nlp_nvme_info
&= ~NLP_NVME_NSLER
;
2228 /* Target driver cannot solicit NVME FB. */
2229 if (bf_get_be32(prli_tgt
, nvpr
)) {
2230 /* Complete the nvme target roles. The transport
2231 * needs to know if the rport is capable of
2232 * discovery in addition to its role.
2234 ndlp
->nlp_type
|= NLP_NVME_TARGET
;
2235 if (bf_get_be32(prli_disc
, nvpr
))
2236 ndlp
->nlp_type
|= NLP_NVME_DISCOVERY
;
2239 * If prli_fba is set, the Target supports FirstBurst.
2240 * If prli_fb_sz is 0, the FirstBurst size is unlimited,
2241 * otherwise it defines the actual size supported by
2244 if ((bf_get_be32(prli_fba
, nvpr
) == 1) &&
2245 (phba
->cfg_nvme_enable_fb
) &&
2246 (!phba
->nvmet_support
)) {
2247 /* Both sides support FB. The target's first
2248 * burst size is a 512 byte encoded value.
2250 ndlp
->nlp_flag
|= NLP_FIRSTBURST
;
2251 ndlp
->nvme_fb_size
= bf_get_be32(prli_fb_sz
,
2254 /* Expressed in units of 512 bytes */
2255 if (ndlp
->nvme_fb_size
)
2256 ndlp
->nvme_fb_size
<<=
2259 ndlp
->nvme_fb_size
= LPFC_NVME_MAX_FB
;
2263 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NVME_DISC
,
2264 "6029 NVME PRLI Cmpl w1 x%08x "
2265 "w4 x%08x w5 x%08x flag x%x, "
2266 "fcp_info x%x nlp_type x%x\n",
2267 be32_to_cpu(nvpr
->word1
),
2268 be32_to_cpu(nvpr
->word4
),
2269 be32_to_cpu(nvpr
->word5
),
2270 ndlp
->nlp_flag
, ndlp
->nlp_fcp_info
,
2273 if (!(ndlp
->nlp_type
& NLP_FCP_TARGET
) &&
2274 (vport
->port_type
== LPFC_NPIV_PORT
) &&
2275 vport
->cfg_restrict_login
) {
2277 spin_lock_irq(&ndlp
->lock
);
2278 ndlp
->nlp_flag
|= NLP_TARGET_REMOVE
;
2279 spin_unlock_irq(&ndlp
->lock
);
2280 lpfc_issue_els_logo(vport
, ndlp
, 0);
2282 ndlp
->nlp_prev_state
= NLP_STE_PRLI_ISSUE
;
2283 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
2284 return ndlp
->nlp_state
;
2288 /* The ndlp state cannot move to MAPPED or UNMAPPED before all PRLIs
2291 if (ndlp
->fc4_prli_sent
== 0) {
2292 ndlp
->nlp_prev_state
= NLP_STE_PRLI_ISSUE
;
2293 if (ndlp
->nlp_type
& (NLP_FCP_TARGET
| NLP_NVME_TARGET
))
2294 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_MAPPED_NODE
);
2295 else if (ndlp
->nlp_type
&
2296 (NLP_FCP_INITIATOR
| NLP_NVME_INITIATOR
))
2297 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
2299 lpfc_printf_vlog(vport
,
2301 "3067 PRLI's still outstanding "
2302 "on x%06x - count %d, Pend Node Mode "
2304 ndlp
->nlp_DID
, ndlp
->fc4_prli_sent
);
2306 return ndlp
->nlp_state
;
2309 /*! lpfc_device_rm_prli_issue
2320 * This routine is envoked when we a request to remove a nport we are in the
2321 * process of PRLIing. We should software abort outstanding prli, unreg
2322 * login, send a logout. We will change node state to UNUSED_NODE, put it
2323 * on plogi list so it can be freed when LOGO completes.
2328 lpfc_device_rm_prli_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2329 void *arg
, uint32_t evt
)
2331 if (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) {
2332 spin_lock_irq(&ndlp
->lock
);
2333 ndlp
->nlp_flag
|= NLP_NODEV_REMOVE
;
2334 spin_unlock_irq(&ndlp
->lock
);
2335 return ndlp
->nlp_state
;
2337 /* software abort outstanding PLOGI */
2338 lpfc_els_abort(vport
->phba
, ndlp
);
2340 lpfc_drop_node(vport
, ndlp
);
2341 return NLP_STE_FREED_NODE
;
2346 /*! lpfc_device_recov_prli_issue
2357 * The routine is envoked when the state of a device is unknown, like
2358 * during a link down. We should remove the nodelist entry from the
2359 * unmapped list, issue a UNREG_LOGIN, do a software abort of the
2360 * outstanding PRLI command, then free the node entry.
2363 lpfc_device_recov_prli_issue(struct lpfc_vport
*vport
,
2364 struct lpfc_nodelist
*ndlp
,
2368 struct lpfc_hba
*phba
= vport
->phba
;
2370 /* Don't do anything that will mess up processing of the
2373 if (vport
->fc_flag
& FC_RSCN_DEFERRED
)
2374 return ndlp
->nlp_state
;
2376 /* software abort outstanding PRLI */
2377 lpfc_els_abort(phba
, ndlp
);
2379 ndlp
->nlp_prev_state
= NLP_STE_PRLI_ISSUE
;
2380 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
2381 spin_lock_irq(&ndlp
->lock
);
2382 ndlp
->nlp_flag
&= ~(NLP_NODEV_REMOVE
| NLP_NPR_2B_DISC
);
2383 spin_unlock_irq(&ndlp
->lock
);
2384 lpfc_disc_set_adisc(vport
, ndlp
);
2385 return ndlp
->nlp_state
;
2389 lpfc_rcv_plogi_logo_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2390 void *arg
, uint32_t evt
)
2392 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*)arg
;
2395 memset(&stat
, 0, sizeof(struct ls_rjt
));
2396 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
2397 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_NOTHING_MORE
;
2398 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
2399 return ndlp
->nlp_state
;
2403 lpfc_rcv_prli_logo_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2404 void *arg
, uint32_t evt
)
2406 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*)arg
;
2409 memset(&stat
, 0, sizeof(struct ls_rjt
));
2410 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
2411 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_NOTHING_MORE
;
2412 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
2413 return ndlp
->nlp_state
;
2417 lpfc_rcv_logo_logo_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2418 void *arg
, uint32_t evt
)
2420 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*)arg
;
2422 spin_lock_irq(&ndlp
->lock
);
2423 ndlp
->nlp_flag
|= NLP_LOGO_ACC
;
2424 spin_unlock_irq(&ndlp
->lock
);
2425 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
2426 return ndlp
->nlp_state
;
2430 lpfc_rcv_padisc_logo_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2431 void *arg
, uint32_t evt
)
2433 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*)arg
;
2436 memset(&stat
, 0, sizeof(struct ls_rjt
));
2437 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
2438 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_NOTHING_MORE
;
2439 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
2440 return ndlp
->nlp_state
;
2444 lpfc_rcv_prlo_logo_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2445 void *arg
, uint32_t evt
)
2447 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*)arg
;
2450 memset(&stat
, 0, sizeof(struct ls_rjt
));
2451 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
2452 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_NOTHING_MORE
;
2453 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
2454 return ndlp
->nlp_state
;
2458 lpfc_cmpl_logo_logo_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2459 void *arg
, uint32_t evt
)
2461 ndlp
->nlp_prev_state
= NLP_STE_LOGO_ISSUE
;
2462 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
2463 spin_lock_irq(&ndlp
->lock
);
2464 ndlp
->nlp_flag
&= ~(NLP_NODEV_REMOVE
| NLP_NPR_2B_DISC
);
2465 spin_unlock_irq(&ndlp
->lock
);
2466 lpfc_disc_set_adisc(vport
, ndlp
);
2467 return ndlp
->nlp_state
;
2471 lpfc_device_rm_logo_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2472 void *arg
, uint32_t evt
)
2475 * DevLoss has timed out and is calling for Device Remove.
2476 * In this case, abort the LOGO and cleanup the ndlp
2479 lpfc_unreg_rpi(vport
, ndlp
);
2480 /* software abort outstanding PLOGI */
2481 lpfc_els_abort(vport
->phba
, ndlp
);
2482 lpfc_drop_node(vport
, ndlp
);
2483 return NLP_STE_FREED_NODE
;
2487 lpfc_device_recov_logo_issue(struct lpfc_vport
*vport
,
2488 struct lpfc_nodelist
*ndlp
,
2489 void *arg
, uint32_t evt
)
2492 * Device Recovery events have no meaning for a node with a LOGO
2493 * outstanding. The LOGO has to complete first and handle the
2494 * node from that point.
2496 return ndlp
->nlp_state
;
2500 lpfc_rcv_plogi_unmap_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2501 void *arg
, uint32_t evt
)
2503 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2505 lpfc_rcv_plogi(vport
, ndlp
, cmdiocb
);
2506 return ndlp
->nlp_state
;
2510 lpfc_rcv_prli_unmap_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2511 void *arg
, uint32_t evt
)
2513 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2515 if (!lpfc_rcv_prli_support_check(vport
, ndlp
, cmdiocb
))
2516 return ndlp
->nlp_state
;
2518 lpfc_rcv_prli(vport
, ndlp
, cmdiocb
);
2519 lpfc_els_rsp_prli_acc(vport
, cmdiocb
, ndlp
);
2520 return ndlp
->nlp_state
;
2524 lpfc_rcv_logo_unmap_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2525 void *arg
, uint32_t evt
)
2527 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2529 lpfc_rcv_logo(vport
, ndlp
, cmdiocb
, ELS_CMD_LOGO
);
2530 return ndlp
->nlp_state
;
2534 lpfc_rcv_padisc_unmap_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2535 void *arg
, uint32_t evt
)
2537 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2539 lpfc_rcv_padisc(vport
, ndlp
, cmdiocb
);
2540 return ndlp
->nlp_state
;
2544 lpfc_rcv_prlo_unmap_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2545 void *arg
, uint32_t evt
)
2547 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2549 lpfc_els_rsp_acc(vport
, ELS_CMD_PRLO
, cmdiocb
, ndlp
, NULL
);
2550 return ndlp
->nlp_state
;
2554 lpfc_device_recov_unmap_node(struct lpfc_vport
*vport
,
2555 struct lpfc_nodelist
*ndlp
,
2559 ndlp
->nlp_prev_state
= NLP_STE_UNMAPPED_NODE
;
2560 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
2561 spin_lock_irq(&ndlp
->lock
);
2562 ndlp
->nlp_flag
&= ~(NLP_NODEV_REMOVE
| NLP_NPR_2B_DISC
);
2563 ndlp
->nlp_fc4_type
&= ~(NLP_FC4_FCP
| NLP_FC4_NVME
);
2564 spin_unlock_irq(&ndlp
->lock
);
2565 lpfc_disc_set_adisc(vport
, ndlp
);
2567 return ndlp
->nlp_state
;
2571 lpfc_rcv_plogi_mapped_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2572 void *arg
, uint32_t evt
)
2574 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2576 lpfc_rcv_plogi(vport
, ndlp
, cmdiocb
);
2577 return ndlp
->nlp_state
;
2581 lpfc_rcv_prli_mapped_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2582 void *arg
, uint32_t evt
)
2584 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2586 if (!lpfc_rcv_prli_support_check(vport
, ndlp
, cmdiocb
))
2587 return ndlp
->nlp_state
;
2588 lpfc_els_rsp_prli_acc(vport
, cmdiocb
, ndlp
);
2589 return ndlp
->nlp_state
;
2593 lpfc_rcv_logo_mapped_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2594 void *arg
, uint32_t evt
)
2596 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2598 lpfc_rcv_logo(vport
, ndlp
, cmdiocb
, ELS_CMD_LOGO
);
2599 return ndlp
->nlp_state
;
2603 lpfc_rcv_padisc_mapped_node(struct lpfc_vport
*vport
,
2604 struct lpfc_nodelist
*ndlp
,
2605 void *arg
, uint32_t evt
)
2607 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2609 lpfc_rcv_padisc(vport
, ndlp
, cmdiocb
);
2610 return ndlp
->nlp_state
;
2614 lpfc_rcv_prlo_mapped_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2615 void *arg
, uint32_t evt
)
2617 struct lpfc_hba
*phba
= vport
->phba
;
2618 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2620 /* flush the target */
2621 lpfc_sli_abort_iocb(vport
, &phba
->sli
.sli3_ring
[LPFC_FCP_RING
],
2622 ndlp
->nlp_sid
, 0, LPFC_CTX_TGT
);
2624 /* Treat like rcv logo */
2625 lpfc_rcv_logo(vport
, ndlp
, cmdiocb
, ELS_CMD_PRLO
);
2626 return ndlp
->nlp_state
;
2630 lpfc_device_recov_mapped_node(struct lpfc_vport
*vport
,
2631 struct lpfc_nodelist
*ndlp
,
2635 ndlp
->nlp_prev_state
= NLP_STE_MAPPED_NODE
;
2636 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
2637 spin_lock_irq(&ndlp
->lock
);
2638 ndlp
->nlp_flag
&= ~(NLP_NODEV_REMOVE
| NLP_NPR_2B_DISC
);
2639 ndlp
->nlp_fc4_type
&= ~(NLP_FC4_FCP
| NLP_FC4_NVME
);
2640 spin_unlock_irq(&ndlp
->lock
);
2641 lpfc_disc_set_adisc(vport
, ndlp
);
2642 return ndlp
->nlp_state
;
2646 lpfc_rcv_plogi_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2647 void *arg
, uint32_t evt
)
2649 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2651 /* Ignore PLOGI if we have an outstanding LOGO */
2652 if (ndlp
->nlp_flag
& (NLP_LOGO_SND
| NLP_LOGO_ACC
))
2653 return ndlp
->nlp_state
;
2654 if (lpfc_rcv_plogi(vport
, ndlp
, cmdiocb
)) {
2655 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
2656 spin_lock_irq(&ndlp
->lock
);
2657 ndlp
->nlp_flag
&= ~(NLP_NPR_ADISC
| NLP_NPR_2B_DISC
);
2658 spin_unlock_irq(&ndlp
->lock
);
2659 } else if (!(ndlp
->nlp_flag
& NLP_NPR_2B_DISC
)) {
2660 /* send PLOGI immediately, move to PLOGI issue state */
2661 if (!(ndlp
->nlp_flag
& NLP_DELAY_TMO
)) {
2662 ndlp
->nlp_prev_state
= NLP_STE_NPR_NODE
;
2663 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
2664 lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0);
2667 return ndlp
->nlp_state
;
2671 lpfc_rcv_prli_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2672 void *arg
, uint32_t evt
)
2674 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2677 memset(&stat
, 0, sizeof (struct ls_rjt
));
2678 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
2679 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_NOTHING_MORE
;
2680 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
2682 if (!(ndlp
->nlp_flag
& NLP_DELAY_TMO
)) {
2683 if (ndlp
->nlp_flag
& NLP_NPR_ADISC
) {
2684 spin_lock_irq(&ndlp
->lock
);
2685 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
2686 ndlp
->nlp_prev_state
= NLP_STE_NPR_NODE
;
2687 spin_unlock_irq(&ndlp
->lock
);
2688 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_ADISC_ISSUE
);
2689 lpfc_issue_els_adisc(vport
, ndlp
, 0);
2691 ndlp
->nlp_prev_state
= NLP_STE_NPR_NODE
;
2692 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
2693 lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0);
2696 return ndlp
->nlp_state
;
2700 lpfc_rcv_logo_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2701 void *arg
, uint32_t evt
)
2703 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2705 lpfc_rcv_logo(vport
, ndlp
, cmdiocb
, ELS_CMD_LOGO
);
2706 return ndlp
->nlp_state
;
2710 lpfc_rcv_padisc_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2711 void *arg
, uint32_t evt
)
2713 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2715 lpfc_rcv_padisc(vport
, ndlp
, cmdiocb
);
2717 * Do not start discovery if discovery is about to start
2718 * or discovery in progress for this node. Starting discovery
2719 * here will affect the counting of discovery threads.
2721 if (!(ndlp
->nlp_flag
& NLP_DELAY_TMO
) &&
2722 !(ndlp
->nlp_flag
& NLP_NPR_2B_DISC
)) {
2723 if (ndlp
->nlp_flag
& NLP_NPR_ADISC
) {
2724 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
2725 ndlp
->nlp_prev_state
= NLP_STE_NPR_NODE
;
2726 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_ADISC_ISSUE
);
2727 lpfc_issue_els_adisc(vport
, ndlp
, 0);
2729 ndlp
->nlp_prev_state
= NLP_STE_NPR_NODE
;
2730 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
2731 lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0);
2734 return ndlp
->nlp_state
;
2738 lpfc_rcv_prlo_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2739 void *arg
, uint32_t evt
)
2741 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2743 spin_lock_irq(&ndlp
->lock
);
2744 ndlp
->nlp_flag
|= NLP_LOGO_ACC
;
2745 spin_unlock_irq(&ndlp
->lock
);
2747 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
2749 if ((ndlp
->nlp_flag
& NLP_DELAY_TMO
) == 0) {
2750 mod_timer(&ndlp
->nlp_delayfunc
,
2751 jiffies
+ msecs_to_jiffies(1000 * 1));
2752 spin_lock_irq(&ndlp
->lock
);
2753 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
2754 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
2755 spin_unlock_irq(&ndlp
->lock
);
2756 ndlp
->nlp_last_elscmd
= ELS_CMD_PLOGI
;
2758 spin_lock_irq(&ndlp
->lock
);
2759 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
2760 spin_unlock_irq(&ndlp
->lock
);
2762 return ndlp
->nlp_state
;
2766 lpfc_cmpl_plogi_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2767 void *arg
, uint32_t evt
)
2769 struct lpfc_iocbq
*cmdiocb
, *rspiocb
;
2772 cmdiocb
= (struct lpfc_iocbq
*) arg
;
2773 rspiocb
= cmdiocb
->context_un
.rsp_iocb
;
2775 irsp
= &rspiocb
->iocb
;
2776 if (irsp
->ulpStatus
) {
2777 return NLP_STE_FREED_NODE
;
2779 return ndlp
->nlp_state
;
2783 lpfc_cmpl_prli_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2784 void *arg
, uint32_t evt
)
2786 struct lpfc_iocbq
*cmdiocb
, *rspiocb
;
2789 cmdiocb
= (struct lpfc_iocbq
*) arg
;
2790 rspiocb
= cmdiocb
->context_un
.rsp_iocb
;
2792 irsp
= &rspiocb
->iocb
;
2793 if (irsp
->ulpStatus
&& (ndlp
->nlp_flag
& NLP_NODEV_REMOVE
)) {
2794 lpfc_drop_node(vport
, ndlp
);
2795 return NLP_STE_FREED_NODE
;
2797 return ndlp
->nlp_state
;
2801 lpfc_cmpl_logo_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2802 void *arg
, uint32_t evt
)
2804 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2806 /* For the fabric port just clear the fc flags. */
2807 if (ndlp
->nlp_DID
== Fabric_DID
) {
2808 spin_lock_irq(shost
->host_lock
);
2809 vport
->fc_flag
&= ~(FC_FABRIC
| FC_PUBLIC_LOOP
);
2810 spin_unlock_irq(shost
->host_lock
);
2812 lpfc_unreg_rpi(vport
, ndlp
);
2813 return ndlp
->nlp_state
;
2817 lpfc_cmpl_adisc_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2818 void *arg
, uint32_t evt
)
2820 struct lpfc_iocbq
*cmdiocb
, *rspiocb
;
2823 cmdiocb
= (struct lpfc_iocbq
*) arg
;
2824 rspiocb
= cmdiocb
->context_un
.rsp_iocb
;
2826 irsp
= &rspiocb
->iocb
;
2827 if (irsp
->ulpStatus
&& (ndlp
->nlp_flag
& NLP_NODEV_REMOVE
)) {
2828 lpfc_drop_node(vport
, ndlp
);
2829 return NLP_STE_FREED_NODE
;
2831 return ndlp
->nlp_state
;
2835 lpfc_cmpl_reglogin_npr_node(struct lpfc_vport
*vport
,
2836 struct lpfc_nodelist
*ndlp
,
2837 void *arg
, uint32_t evt
)
2839 LPFC_MBOXQ_t
*pmb
= (LPFC_MBOXQ_t
*) arg
;
2840 MAILBOX_t
*mb
= &pmb
->u
.mb
;
2842 if (!mb
->mbxStatus
) {
2843 /* SLI4 ports have preallocated logical rpis. */
2844 if (vport
->phba
->sli_rev
< LPFC_SLI_REV4
)
2845 ndlp
->nlp_rpi
= mb
->un
.varWords
[0];
2846 ndlp
->nlp_flag
|= NLP_RPI_REGISTERED
;
2847 if (ndlp
->nlp_flag
& NLP_LOGO_ACC
) {
2848 lpfc_unreg_rpi(vport
, ndlp
);
2851 if (ndlp
->nlp_flag
& NLP_NODEV_REMOVE
) {
2852 lpfc_drop_node(vport
, ndlp
);
2853 return NLP_STE_FREED_NODE
;
2856 return ndlp
->nlp_state
;
2860 lpfc_device_rm_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2861 void *arg
, uint32_t evt
)
2863 if (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) {
2864 spin_lock_irq(&ndlp
->lock
);
2865 ndlp
->nlp_flag
|= NLP_NODEV_REMOVE
;
2866 spin_unlock_irq(&ndlp
->lock
);
2867 return ndlp
->nlp_state
;
2869 lpfc_drop_node(vport
, ndlp
);
2870 return NLP_STE_FREED_NODE
;
2874 lpfc_device_recov_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2875 void *arg
, uint32_t evt
)
2877 /* Don't do anything that will mess up processing of the
2880 if (vport
->fc_flag
& FC_RSCN_DEFERRED
)
2881 return ndlp
->nlp_state
;
2883 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
2884 spin_lock_irq(&ndlp
->lock
);
2885 ndlp
->nlp_flag
&= ~(NLP_NODEV_REMOVE
| NLP_NPR_2B_DISC
);
2886 ndlp
->nlp_fc4_type
&= ~(NLP_FC4_FCP
| NLP_FC4_NVME
);
2887 spin_unlock_irq(&ndlp
->lock
);
2888 return ndlp
->nlp_state
;
2892 /* This next section defines the NPort Discovery State Machine */
2894 /* There are 4 different double linked lists nodelist entries can reside on.
2895 * The plogi list and adisc list are used when Link Up discovery or RSCN
2896 * processing is needed. Each list holds the nodes that we will send PLOGI
2897 * or ADISC on. These lists will keep track of what nodes will be effected
2898 * by an RSCN, or a Link Up (Typically, all nodes are effected on Link Up).
2899 * The unmapped_list will contain all nodes that we have successfully logged
2900 * into at the Fibre Channel level. The mapped_list will contain all nodes
2901 * that are mapped FCP targets.
2904 * The bind list is a list of undiscovered (potentially non-existent) nodes
2905 * that we have saved binding information on. This information is used when
2906 * nodes transition from the unmapped to the mapped list.
2908 /* For UNUSED_NODE state, the node has just been allocated .
2909 * For PLOGI_ISSUE and REG_LOGIN_ISSUE, the node is on
2910 * the PLOGI list. For REG_LOGIN_COMPL, the node is taken off the PLOGI list
2911 * and put on the unmapped list. For ADISC processing, the node is taken off
2912 * the ADISC list and placed on either the mapped or unmapped list (depending
2913 * on its previous state). Once on the unmapped list, a PRLI is issued and the
2914 * state changed to PRLI_ISSUE. When the PRLI completion occurs, the state is
2915 * changed to UNMAPPED_NODE. If the completion indicates a mapped
2916 * node, the node is taken off the unmapped list. The binding list is checked
2917 * for a valid binding, or a binding is automatically assigned. If binding
2918 * assignment is unsuccessful, the node is left on the unmapped list. If
2919 * binding assignment is successful, the associated binding list entry (if
2920 * any) is removed, and the node is placed on the mapped list.
2923 * For a Link Down, all nodes on the ADISC, PLOGI, unmapped or mapped
2924 * lists will receive a DEVICE_RECOVERY event. If the linkdown or devloss timers
2925 * expire, all effected nodes will receive a DEVICE_RM event.
2928 * For a Link Up or RSCN, all nodes will move from the mapped / unmapped lists
2929 * to either the ADISC or PLOGI list. After a Nameserver query or ALPA loopmap
2930 * check, additional nodes may be added or removed (via DEVICE_RM) to / from
2931 * the PLOGI or ADISC lists. Once the PLOGI and ADISC lists are populated,
2932 * we will first process the ADISC list. 32 entries are processed initially and
2933 * ADISC is initited for each one. Completions / Events for each node are
2934 * funnelled thru the state machine. As each node finishes ADISC processing, it
2935 * starts ADISC for any nodes waiting for ADISC processing. If no nodes are
2936 * waiting, and the ADISC list count is identically 0, then we are done. For
2937 * Link Up discovery, since all nodes on the PLOGI list are UNREG_LOGIN'ed, we
2938 * can issue a CLEAR_LA and reenable Link Events. Next we will process the PLOGI
2939 * list. 32 entries are processed initially and PLOGI is initited for each one.
2940 * Completions / Events for each node are funnelled thru the state machine. As
2941 * each node finishes PLOGI processing, it starts PLOGI for any nodes waiting
2942 * for PLOGI processing. If no nodes are waiting, and the PLOGI list count is
2943 * indentically 0, then we are done. We have now completed discovery / RSCN
2944 * handling. Upon completion, ALL nodes should be on either the mapped or
2948 static uint32_t (*lpfc_disc_action
[NLP_STE_MAX_STATE
* NLP_EVT_MAX_EVENT
])
2949 (struct lpfc_vport
*, struct lpfc_nodelist
*, void *, uint32_t) = {
2950 /* Action routine Event Current State */
2951 lpfc_rcv_plogi_unused_node
, /* RCV_PLOGI UNUSED_NODE */
2952 lpfc_rcv_els_unused_node
, /* RCV_PRLI */
2953 lpfc_rcv_logo_unused_node
, /* RCV_LOGO */
2954 lpfc_rcv_els_unused_node
, /* RCV_ADISC */
2955 lpfc_rcv_els_unused_node
, /* RCV_PDISC */
2956 lpfc_rcv_els_unused_node
, /* RCV_PRLO */
2957 lpfc_disc_illegal
, /* CMPL_PLOGI */
2958 lpfc_disc_illegal
, /* CMPL_PRLI */
2959 lpfc_cmpl_logo_unused_node
, /* CMPL_LOGO */
2960 lpfc_disc_illegal
, /* CMPL_ADISC */
2961 lpfc_disc_illegal
, /* CMPL_REG_LOGIN */
2962 lpfc_device_rm_unused_node
, /* DEVICE_RM */
2963 lpfc_device_recov_unused_node
, /* DEVICE_RECOVERY */
2965 lpfc_rcv_plogi_plogi_issue
, /* RCV_PLOGI PLOGI_ISSUE */
2966 lpfc_rcv_prli_plogi_issue
, /* RCV_PRLI */
2967 lpfc_rcv_logo_plogi_issue
, /* RCV_LOGO */
2968 lpfc_rcv_els_plogi_issue
, /* RCV_ADISC */
2969 lpfc_rcv_els_plogi_issue
, /* RCV_PDISC */
2970 lpfc_rcv_els_plogi_issue
, /* RCV_PRLO */
2971 lpfc_cmpl_plogi_plogi_issue
, /* CMPL_PLOGI */
2972 lpfc_disc_illegal
, /* CMPL_PRLI */
2973 lpfc_cmpl_logo_plogi_issue
, /* CMPL_LOGO */
2974 lpfc_disc_illegal
, /* CMPL_ADISC */
2975 lpfc_cmpl_reglogin_plogi_issue
,/* CMPL_REG_LOGIN */
2976 lpfc_device_rm_plogi_issue
, /* DEVICE_RM */
2977 lpfc_device_recov_plogi_issue
, /* DEVICE_RECOVERY */
2979 lpfc_rcv_plogi_adisc_issue
, /* RCV_PLOGI ADISC_ISSUE */
2980 lpfc_rcv_prli_adisc_issue
, /* RCV_PRLI */
2981 lpfc_rcv_logo_adisc_issue
, /* RCV_LOGO */
2982 lpfc_rcv_padisc_adisc_issue
, /* RCV_ADISC */
2983 lpfc_rcv_padisc_adisc_issue
, /* RCV_PDISC */
2984 lpfc_rcv_prlo_adisc_issue
, /* RCV_PRLO */
2985 lpfc_disc_illegal
, /* CMPL_PLOGI */
2986 lpfc_disc_illegal
, /* CMPL_PRLI */
2987 lpfc_disc_illegal
, /* CMPL_LOGO */
2988 lpfc_cmpl_adisc_adisc_issue
, /* CMPL_ADISC */
2989 lpfc_disc_illegal
, /* CMPL_REG_LOGIN */
2990 lpfc_device_rm_adisc_issue
, /* DEVICE_RM */
2991 lpfc_device_recov_adisc_issue
, /* DEVICE_RECOVERY */
2993 lpfc_rcv_plogi_reglogin_issue
, /* RCV_PLOGI REG_LOGIN_ISSUE */
2994 lpfc_rcv_prli_reglogin_issue
, /* RCV_PLOGI */
2995 lpfc_rcv_logo_reglogin_issue
, /* RCV_LOGO */
2996 lpfc_rcv_padisc_reglogin_issue
, /* RCV_ADISC */
2997 lpfc_rcv_padisc_reglogin_issue
, /* RCV_PDISC */
2998 lpfc_rcv_prlo_reglogin_issue
, /* RCV_PRLO */
2999 lpfc_cmpl_plogi_illegal
, /* CMPL_PLOGI */
3000 lpfc_disc_illegal
, /* CMPL_PRLI */
3001 lpfc_disc_illegal
, /* CMPL_LOGO */
3002 lpfc_disc_illegal
, /* CMPL_ADISC */
3003 lpfc_cmpl_reglogin_reglogin_issue
,/* CMPL_REG_LOGIN */
3004 lpfc_device_rm_reglogin_issue
, /* DEVICE_RM */
3005 lpfc_device_recov_reglogin_issue
,/* DEVICE_RECOVERY */
3007 lpfc_rcv_plogi_prli_issue
, /* RCV_PLOGI PRLI_ISSUE */
3008 lpfc_rcv_prli_prli_issue
, /* RCV_PRLI */
3009 lpfc_rcv_logo_prli_issue
, /* RCV_LOGO */
3010 lpfc_rcv_padisc_prli_issue
, /* RCV_ADISC */
3011 lpfc_rcv_padisc_prli_issue
, /* RCV_PDISC */
3012 lpfc_rcv_prlo_prli_issue
, /* RCV_PRLO */
3013 lpfc_cmpl_plogi_illegal
, /* CMPL_PLOGI */
3014 lpfc_cmpl_prli_prli_issue
, /* CMPL_PRLI */
3015 lpfc_disc_illegal
, /* CMPL_LOGO */
3016 lpfc_disc_illegal
, /* CMPL_ADISC */
3017 lpfc_disc_illegal
, /* CMPL_REG_LOGIN */
3018 lpfc_device_rm_prli_issue
, /* DEVICE_RM */
3019 lpfc_device_recov_prli_issue
, /* DEVICE_RECOVERY */
3021 lpfc_rcv_plogi_logo_issue
, /* RCV_PLOGI LOGO_ISSUE */
3022 lpfc_rcv_prli_logo_issue
, /* RCV_PRLI */
3023 lpfc_rcv_logo_logo_issue
, /* RCV_LOGO */
3024 lpfc_rcv_padisc_logo_issue
, /* RCV_ADISC */
3025 lpfc_rcv_padisc_logo_issue
, /* RCV_PDISC */
3026 lpfc_rcv_prlo_logo_issue
, /* RCV_PRLO */
3027 lpfc_cmpl_plogi_illegal
, /* CMPL_PLOGI */
3028 lpfc_disc_illegal
, /* CMPL_PRLI */
3029 lpfc_cmpl_logo_logo_issue
, /* CMPL_LOGO */
3030 lpfc_disc_illegal
, /* CMPL_ADISC */
3031 lpfc_disc_illegal
, /* CMPL_REG_LOGIN */
3032 lpfc_device_rm_logo_issue
, /* DEVICE_RM */
3033 lpfc_device_recov_logo_issue
, /* DEVICE_RECOVERY */
3035 lpfc_rcv_plogi_unmap_node
, /* RCV_PLOGI UNMAPPED_NODE */
3036 lpfc_rcv_prli_unmap_node
, /* RCV_PRLI */
3037 lpfc_rcv_logo_unmap_node
, /* RCV_LOGO */
3038 lpfc_rcv_padisc_unmap_node
, /* RCV_ADISC */
3039 lpfc_rcv_padisc_unmap_node
, /* RCV_PDISC */
3040 lpfc_rcv_prlo_unmap_node
, /* RCV_PRLO */
3041 lpfc_disc_illegal
, /* CMPL_PLOGI */
3042 lpfc_disc_illegal
, /* CMPL_PRLI */
3043 lpfc_disc_illegal
, /* CMPL_LOGO */
3044 lpfc_disc_illegal
, /* CMPL_ADISC */
3045 lpfc_disc_illegal
, /* CMPL_REG_LOGIN */
3046 lpfc_disc_illegal
, /* DEVICE_RM */
3047 lpfc_device_recov_unmap_node
, /* DEVICE_RECOVERY */
3049 lpfc_rcv_plogi_mapped_node
, /* RCV_PLOGI MAPPED_NODE */
3050 lpfc_rcv_prli_mapped_node
, /* RCV_PRLI */
3051 lpfc_rcv_logo_mapped_node
, /* RCV_LOGO */
3052 lpfc_rcv_padisc_mapped_node
, /* RCV_ADISC */
3053 lpfc_rcv_padisc_mapped_node
, /* RCV_PDISC */
3054 lpfc_rcv_prlo_mapped_node
, /* RCV_PRLO */
3055 lpfc_disc_illegal
, /* CMPL_PLOGI */
3056 lpfc_disc_illegal
, /* CMPL_PRLI */
3057 lpfc_disc_illegal
, /* CMPL_LOGO */
3058 lpfc_disc_illegal
, /* CMPL_ADISC */
3059 lpfc_disc_illegal
, /* CMPL_REG_LOGIN */
3060 lpfc_disc_illegal
, /* DEVICE_RM */
3061 lpfc_device_recov_mapped_node
, /* DEVICE_RECOVERY */
3063 lpfc_rcv_plogi_npr_node
, /* RCV_PLOGI NPR_NODE */
3064 lpfc_rcv_prli_npr_node
, /* RCV_PRLI */
3065 lpfc_rcv_logo_npr_node
, /* RCV_LOGO */
3066 lpfc_rcv_padisc_npr_node
, /* RCV_ADISC */
3067 lpfc_rcv_padisc_npr_node
, /* RCV_PDISC */
3068 lpfc_rcv_prlo_npr_node
, /* RCV_PRLO */
3069 lpfc_cmpl_plogi_npr_node
, /* CMPL_PLOGI */
3070 lpfc_cmpl_prli_npr_node
, /* CMPL_PRLI */
3071 lpfc_cmpl_logo_npr_node
, /* CMPL_LOGO */
3072 lpfc_cmpl_adisc_npr_node
, /* CMPL_ADISC */
3073 lpfc_cmpl_reglogin_npr_node
, /* CMPL_REG_LOGIN */
3074 lpfc_device_rm_npr_node
, /* DEVICE_RM */
3075 lpfc_device_recov_npr_node
, /* DEVICE_RECOVERY */
3079 lpfc_disc_state_machine(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
3080 void *arg
, uint32_t evt
)
3082 uint32_t cur_state
, rc
;
3083 uint32_t(*func
) (struct lpfc_vport
*, struct lpfc_nodelist
*, void *,
3085 uint32_t got_ndlp
= 0;
3088 if (lpfc_nlp_get(ndlp
))
3091 cur_state
= ndlp
->nlp_state
;
3093 data1
= (((uint32_t)ndlp
->nlp_fc4_type
<< 16) |
3094 ((uint32_t)ndlp
->nlp_type
));
3095 /* DSM in event <evt> on NPort <nlp_DID> in state <cur_state> */
3096 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
3097 "0211 DSM in event x%x on NPort x%x in "
3098 "state %d rpi x%x Data: x%x x%x\n",
3099 evt
, ndlp
->nlp_DID
, cur_state
, ndlp
->nlp_rpi
,
3100 ndlp
->nlp_flag
, data1
);
3102 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_DSM
,
3103 "DSM in: evt:%d ste:%d did:x%x",
3104 evt
, cur_state
, ndlp
->nlp_DID
);
3106 func
= lpfc_disc_action
[(cur_state
* NLP_EVT_MAX_EVENT
) + evt
];
3107 rc
= (func
) (vport
, ndlp
, arg
, evt
);
3109 /* DSM out state <rc> on NPort <nlp_DID> */
3111 data1
= (((uint32_t)ndlp
->nlp_fc4_type
<< 16) |
3112 ((uint32_t)ndlp
->nlp_type
));
3113 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
3114 "0212 DSM out state %d on NPort x%x "
3115 "rpi x%x Data: x%x x%x\n",
3116 rc
, ndlp
->nlp_DID
, ndlp
->nlp_rpi
, ndlp
->nlp_flag
,
3119 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_DSM
,
3120 "DSM out: ste:%d did:x%x flg:x%x",
3121 rc
, ndlp
->nlp_DID
, ndlp
->nlp_flag
);
3122 /* Decrement the ndlp reference count held for this function */
3125 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
3126 "0213 DSM out state %d on NPort free\n", rc
);
3128 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_DSM
,
3129 "DSM out: ste:%d did:x%x flg:x%x",