1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017-2022 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
;
174 u32 ulp_status
= get_job_ulpstatus(phba
, rspiocb
);
176 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
178 /* For lpfc_els_abort, context2 could be zero'ed to delay
179 * freeing associated memory till after ABTS completes.
182 prsp
= list_get_first(&pcmd
->list
, struct lpfc_dmabuf
,
185 lp
= (uint32_t *) prsp
->virt
;
186 ptr
= (void *)((uint8_t *)lp
+ sizeof(uint32_t));
189 /* Force ulp_status error since we are returning NULL ptr */
191 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
192 bf_set(lpfc_wcqe_c_status
, &rspiocb
->wcqe_cmpl
,
193 IOSTAT_LOCAL_REJECT
);
194 rspiocb
->wcqe_cmpl
.parameter
= IOERR_SLI_ABORTED
;
196 rspiocb
->iocb
.ulpStatus
= IOSTAT_LOCAL_REJECT
;
197 rspiocb
->iocb
.un
.ulpWord
[4] = IOERR_SLI_ABORTED
;
208 * Free resources / clean up outstanding I/Os
209 * associated with a LPFC_NODELIST entry. This
210 * routine effectively results in a "software abort".
213 lpfc_els_abort(struct lpfc_hba
*phba
, struct lpfc_nodelist
*ndlp
)
215 LIST_HEAD(abort_list
);
216 struct lpfc_sli_ring
*pring
;
217 struct lpfc_iocbq
*iocb
, *next_iocb
;
219 pring
= lpfc_phba_elsring(phba
);
221 /* In case of error recovery path, we might have a NULL pring here */
222 if (unlikely(!pring
))
225 /* Abort outstanding I/O on NPort <nlp_DID> */
226 lpfc_printf_vlog(ndlp
->vport
, KERN_INFO
, LOG_DISCOVERY
,
227 "2819 Abort outstanding I/O on NPort x%x "
228 "Data: x%x x%x x%x\n",
229 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
231 /* Clean up all fabric IOs first.*/
232 lpfc_fabric_abort_nport(ndlp
);
235 * Lock the ELS ring txcmplq for SLI3/SLI4 and build a local list
236 * of all ELS IOs that need an ABTS. The IOs need to stay on the
237 * txcmplq so that the abort operation completes them successfully.
239 spin_lock_irq(&phba
->hbalock
);
240 if (phba
->sli_rev
== LPFC_SLI_REV4
)
241 spin_lock(&pring
->ring_lock
);
242 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
, list
) {
243 /* Add to abort_list on on NDLP match. */
244 if (lpfc_check_sli_ndlp(phba
, pring
, iocb
, ndlp
))
245 list_add_tail(&iocb
->dlist
, &abort_list
);
247 if (phba
->sli_rev
== LPFC_SLI_REV4
)
248 spin_unlock(&pring
->ring_lock
);
249 spin_unlock_irq(&phba
->hbalock
);
251 /* Abort the targeted IOs and remove them from the abort list. */
252 list_for_each_entry_safe(iocb
, next_iocb
, &abort_list
, dlist
) {
253 spin_lock_irq(&phba
->hbalock
);
254 list_del_init(&iocb
->dlist
);
255 lpfc_sli_issue_abort_iotag(phba
, pring
, iocb
, NULL
);
256 spin_unlock_irq(&phba
->hbalock
);
258 /* Make sure HBA is alive */
259 lpfc_issue_hb_tmo(phba
);
261 INIT_LIST_HEAD(&abort_list
);
263 /* Now process the txq */
264 spin_lock_irq(&phba
->hbalock
);
265 if (phba
->sli_rev
== LPFC_SLI_REV4
)
266 spin_lock(&pring
->ring_lock
);
268 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txq
, list
) {
269 /* Check to see if iocb matches the nport we are looking for */
270 if (lpfc_check_sli_ndlp(phba
, pring
, iocb
, ndlp
)) {
271 list_del_init(&iocb
->list
);
272 list_add_tail(&iocb
->list
, &abort_list
);
276 if (phba
->sli_rev
== LPFC_SLI_REV4
)
277 spin_unlock(&pring
->ring_lock
);
278 spin_unlock_irq(&phba
->hbalock
);
280 /* Cancel all the IOCBs from the completions list */
281 lpfc_sli_cancel_iocbs(phba
, &abort_list
,
282 IOSTAT_LOCAL_REJECT
, IOERR_SLI_ABORTED
);
284 lpfc_cancel_retry_delay_tmo(phba
->pport
, ndlp
);
287 /* lpfc_defer_plogi_acc - Issue PLOGI ACC after reg_login completes
288 * @phba: pointer to lpfc hba data structure.
289 * @login_mbox: pointer to REG_RPI mailbox object
291 * The ACC for a rcv'ed PLOGI is deferred until AFTER the REG_RPI completes
294 lpfc_defer_plogi_acc(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*login_mbox
)
296 struct lpfc_iocbq
*save_iocb
;
297 struct lpfc_nodelist
*ndlp
;
298 MAILBOX_t
*mb
= &login_mbox
->u
.mb
;
302 ndlp
= login_mbox
->ctx_ndlp
;
303 save_iocb
= login_mbox
->context3
;
305 if (mb
->mbxStatus
== MBX_SUCCESS
) {
306 /* Now that REG_RPI completed successfully,
307 * we can now proceed with sending the PLOGI ACC.
309 rc
= lpfc_els_rsp_acc(login_mbox
->vport
, ELS_CMD_PLOGI
,
310 save_iocb
, ndlp
, NULL
);
312 lpfc_printf_log(phba
, KERN_ERR
, LOG_TRACE_EVENT
,
313 "4576 PLOGI ACC fails pt2pt discovery: "
314 "DID %x Data: %x\n", ndlp
->nlp_DID
, rc
);
318 /* Now process the REG_RPI cmpl */
319 lpfc_mbx_cmpl_reg_login(phba
, login_mbox
);
320 ndlp
->nlp_flag
&= ~NLP_ACC_REGLOGIN
;
325 lpfc_rcv_plogi(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
326 struct lpfc_iocbq
*cmdiocb
)
328 struct lpfc_hba
*phba
= vport
->phba
;
329 struct lpfc_dmabuf
*pcmd
;
330 struct lpfc_dmabuf
*mp
;
331 uint64_t nlp_portwwn
= 0;
333 union lpfc_wqe128
*wqe
;
335 struct serv_parm
*sp
;
337 LPFC_MBOXQ_t
*link_mbox
;
338 LPFC_MBOXQ_t
*login_mbox
;
339 struct lpfc_iocbq
*save_iocb
;
345 memset(&stat
, 0, sizeof (struct ls_rjt
));
346 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
347 lp
= (uint32_t *) pcmd
->virt
;
348 sp
= (struct serv_parm
*) ((uint8_t *) lp
+ sizeof (uint32_t));
349 if (wwn_to_u64(sp
->portName
.u
.wwn
) == 0) {
350 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
351 "0140 PLOGI Reject: invalid pname\n");
352 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
353 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_INVALID_PNAME
;
354 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
,
358 if (wwn_to_u64(sp
->nodeName
.u
.wwn
) == 0) {
359 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
360 "0141 PLOGI Reject: invalid nname\n");
361 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
362 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_INVALID_NNAME
;
363 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
,
368 nlp_portwwn
= wwn_to_u64(ndlp
->nlp_portname
.u
.wwn
);
369 if ((lpfc_check_sparm(vport
, ndlp
, sp
, CLASS3
, 0) == 0)) {
370 /* Reject this request because invalid parameters */
371 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
372 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_SPARM_OPTIONS
;
373 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
,
378 if (phba
->sli_rev
== LPFC_SLI_REV4
)
381 icmd
= &cmdiocb
->iocb
;
383 /* PLOGI chkparm OK */
384 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
385 "0114 PLOGI chkparm OK Data: x%x x%x x%x "
387 ndlp
->nlp_DID
, ndlp
->nlp_state
, ndlp
->nlp_flag
,
388 ndlp
->nlp_rpi
, vport
->port_state
,
391 if (vport
->cfg_fcp_class
== 2 && sp
->cls2
.classValid
)
392 ndlp
->nlp_fcp_info
|= CLASS2
;
394 ndlp
->nlp_fcp_info
|= CLASS3
;
396 ndlp
->nlp_class_sup
= 0;
397 if (sp
->cls1
.classValid
)
398 ndlp
->nlp_class_sup
|= FC_COS_CLASS1
;
399 if (sp
->cls2
.classValid
)
400 ndlp
->nlp_class_sup
|= FC_COS_CLASS2
;
401 if (sp
->cls3
.classValid
)
402 ndlp
->nlp_class_sup
|= FC_COS_CLASS3
;
403 if (sp
->cls4
.classValid
)
404 ndlp
->nlp_class_sup
|= FC_COS_CLASS4
;
406 ((sp
->cmn
.bbRcvSizeMsb
& 0x0F) << 8) | sp
->cmn
.bbRcvSizeLsb
;
407 /* if already logged in, do implicit logout */
408 switch (ndlp
->nlp_state
) {
409 case NLP_STE_NPR_NODE
:
410 if (!(ndlp
->nlp_flag
& NLP_NPR_ADISC
))
413 case NLP_STE_REG_LOGIN_ISSUE
:
414 case NLP_STE_PRLI_ISSUE
:
415 case NLP_STE_UNMAPPED_NODE
:
416 case NLP_STE_MAPPED_NODE
:
417 /* For initiators, lpfc_plogi_confirm_nport skips fabric did.
418 * For target mode, execute implicit logo.
419 * Fabric nodes go into NPR.
421 if (!(ndlp
->nlp_type
& NLP_FABRIC
) &&
422 !(phba
->nvmet_support
)) {
423 /* Clear ndlp info, since follow up PRLI may have
424 * updated ndlp information
426 ndlp
->nlp_type
&= ~(NLP_FCP_TARGET
| NLP_FCP_INITIATOR
);
427 ndlp
->nlp_type
&= ~(NLP_NVME_TARGET
| NLP_NVME_INITIATOR
);
428 ndlp
->nlp_fcp_info
&= ~NLP_FCP_2_DEVICE
;
429 ndlp
->nlp_nvme_info
&= ~NLP_NVME_NSLER
;
430 ndlp
->nlp_flag
&= ~NLP_FIRSTBURST
;
432 lpfc_els_rsp_acc(vport
, ELS_CMD_PLOGI
, cmdiocb
,
436 if (nlp_portwwn
!= 0 &&
437 nlp_portwwn
!= wwn_to_u64(sp
->portName
.u
.wwn
))
438 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
439 "0143 PLOGI recv'd from DID: x%x "
440 "WWPN changed: old %llx new %llx\n",
442 (unsigned long long)nlp_portwwn
,
444 wwn_to_u64(sp
->portName
.u
.wwn
));
446 /* Notify transport of connectivity loss to trigger cleanup. */
447 if (phba
->nvmet_support
&&
448 ndlp
->nlp_state
== NLP_STE_UNMAPPED_NODE
)
449 lpfc_nvmet_invalidate_host(phba
, ndlp
);
451 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
452 /* rport needs to be unregistered first */
453 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
457 ndlp
->nlp_type
&= ~(NLP_FCP_TARGET
| NLP_FCP_INITIATOR
);
458 ndlp
->nlp_type
&= ~(NLP_NVME_TARGET
| NLP_NVME_INITIATOR
);
459 ndlp
->nlp_fcp_info
&= ~NLP_FCP_2_DEVICE
;
460 ndlp
->nlp_nvme_info
&= ~NLP_NVME_NSLER
;
461 ndlp
->nlp_flag
&= ~NLP_FIRSTBURST
;
467 /* Check for Nport to NPort pt2pt protocol */
468 if ((vport
->fc_flag
& FC_PT2PT
) &&
469 !(vport
->fc_flag
& FC_PT2PT_PLOGI
)) {
470 /* rcv'ed PLOGI decides what our NPortId will be */
471 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
472 vport
->fc_myDID
= bf_get(els_rsp64_sid
,
473 &cmdiocb
->wqe
.xmit_els_rsp
);
475 vport
->fc_myDID
= icmd
->un
.rcvels
.parmRo
;
478 /* If there is an outstanding FLOGI, abort it now.
479 * The remote NPort is not going to ACC our FLOGI
480 * if its already issuing a PLOGI for pt2pt mode.
481 * This indicates our FLOGI was dropped; however, we
482 * must have ACCed the remote NPorts FLOGI to us
485 if (phba
->hba_flag
& HBA_FLOGI_OUTSTANDING
)
486 lpfc_els_abort_flogi(phba
);
488 ed_tov
= be32_to_cpu(sp
->cmn
.e_d_tov
);
489 if (sp
->cmn
.edtovResolution
) {
490 /* E_D_TOV ticks are in nanoseconds */
491 ed_tov
= (phba
->fc_edtov
+ 999999) / 1000000;
495 * For pt-to-pt, use the larger EDTOV
498 if (ed_tov
> phba
->fc_edtov
)
499 phba
->fc_edtov
= ed_tov
;
500 phba
->fc_ratov
= (2 * phba
->fc_edtov
) / 1000;
502 memcpy(&phba
->fc_fabparam
, sp
, sizeof(struct serv_parm
));
504 /* Issue CONFIG_LINK for SLI3 or REG_VFI for SLI4,
505 * to account for updated TOV's / parameters
507 if (phba
->sli_rev
== LPFC_SLI_REV4
)
508 lpfc_issue_reg_vfi(vport
);
510 link_mbox
= mempool_alloc(phba
->mbox_mem_pool
,
514 lpfc_config_link(phba
, link_mbox
);
515 link_mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
516 link_mbox
->vport
= vport
;
517 link_mbox
->ctx_ndlp
= ndlp
;
519 rc
= lpfc_sli_issue_mbox(phba
, link_mbox
, MBX_NOWAIT
);
520 if (rc
== MBX_NOT_FINISHED
) {
521 mempool_free(link_mbox
, phba
->mbox_mem_pool
);
526 lpfc_can_disctmo(vport
);
529 ndlp
->nlp_flag
&= ~NLP_SUPPRESS_RSP
;
530 if ((phba
->sli
.sli_flag
& LPFC_SLI_SUPPRESS_RSP
) &&
531 sp
->cmn
.valid_vendor_ver_level
) {
532 vid
= be32_to_cpu(sp
->un
.vv
.vid
);
533 flag
= be32_to_cpu(sp
->un
.vv
.flags
);
534 if ((vid
== LPFC_VV_EMLX_ID
) && (flag
& LPFC_VV_SUPPRESS_RSP
))
535 ndlp
->nlp_flag
|= NLP_SUPPRESS_RSP
;
538 login_mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
542 save_iocb
= kzalloc(sizeof(*save_iocb
), GFP_KERNEL
);
546 /* Save info from cmd IOCB to be used in rsp after all mbox completes */
547 memcpy((uint8_t *)save_iocb
, (uint8_t *)cmdiocb
,
548 sizeof(struct lpfc_iocbq
));
550 /* Registering an existing RPI behaves differently for SLI3 vs SLI4 */
551 if (phba
->sli_rev
== LPFC_SLI_REV4
)
552 lpfc_unreg_rpi(vport
, ndlp
);
554 /* Issue REG_LOGIN first, before ACCing the PLOGI, thus we will
555 * always be deferring the ACC.
557 if (phba
->sli_rev
== LPFC_SLI_REV4
)
558 remote_did
= bf_get(wqe_els_did
, &wqe
->xmit_els_rsp
.wqe_dest
);
560 remote_did
= icmd
->un
.rcvels
.remoteID
;
561 rc
= lpfc_reg_rpi(phba
, vport
->vpi
, remote_did
,
562 (uint8_t *)sp
, login_mbox
, ndlp
->nlp_rpi
);
566 login_mbox
->mbox_cmpl
= lpfc_mbx_cmpl_reg_login
;
567 login_mbox
->vport
= vport
;
570 * If there is an outstanding PLOGI issued, abort it before
571 * sending ACC rsp for received PLOGI. If pending plogi
572 * is not canceled here, the plogi will be rejected by
573 * remote port and will be retried. On a configuration with
574 * single discovery thread, this will cause a huge delay in
575 * discovery. Also this will cause multiple state machines
576 * running in parallel for this node.
577 * This only applies to a fabric environment.
579 if ((ndlp
->nlp_state
== NLP_STE_PLOGI_ISSUE
) &&
580 (vport
->fc_flag
& FC_FABRIC
)) {
581 /* software abort outstanding PLOGI */
582 lpfc_els_abort(phba
, ndlp
);
585 if ((vport
->port_type
== LPFC_NPIV_PORT
&&
586 vport
->cfg_restrict_login
)) {
588 /* no deferred ACC */
591 /* This is an NPIV SLI4 instance that does not need to register
594 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
595 mp
= (struct lpfc_dmabuf
*)login_mbox
->ctx_buf
;
597 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
600 mempool_free(login_mbox
, phba
->mbox_mem_pool
);
603 /* In order to preserve RPIs, we want to cleanup
604 * the default RPI the firmware created to rcv
605 * this ELS request. The only way to do this is
606 * to register, then unregister the RPI.
608 spin_lock_irq(&ndlp
->lock
);
609 ndlp
->nlp_flag
|= (NLP_RM_DFLT_RPI
| NLP_ACC_REGLOGIN
|
611 spin_unlock_irq(&ndlp
->lock
);
614 stat
.un
.b
.lsRjtRsnCode
= LSRJT_INVALID_CMD
;
615 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_NOTHING_MORE
;
616 rc
= lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
,
619 mempool_free(login_mbox
, phba
->mbox_mem_pool
);
623 /* So the order here should be:
625 * Issue CONFIG_LINK mbox
631 * Issue UNREG RPI mbx
638 login_mbox
->mbox_cmpl
= lpfc_defer_plogi_acc
;
639 login_mbox
->ctx_ndlp
= lpfc_nlp_get(ndlp
);
640 login_mbox
->context3
= save_iocb
; /* For PLOGI ACC */
642 spin_lock_irq(&ndlp
->lock
);
643 ndlp
->nlp_flag
|= (NLP_ACC_REGLOGIN
| NLP_RCV_PLOGI
);
644 spin_unlock_irq(&ndlp
->lock
);
646 /* Start the ball rolling by issuing REG_LOGIN here */
647 rc
= lpfc_sli_issue_mbox(phba
, login_mbox
, MBX_NOWAIT
);
648 if (rc
== MBX_NOT_FINISHED
)
650 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_REG_LOGIN_ISSUE
);
656 mempool_free(login_mbox
, phba
->mbox_mem_pool
);
658 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
659 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_OUT_OF_RESOURCE
;
660 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
665 * lpfc_mbx_cmpl_resume_rpi - Resume RPI completion routine
666 * @phba: pointer to lpfc hba data structure.
667 * @mboxq: pointer to mailbox object
669 * This routine is invoked to issue a completion to a rcv'ed
670 * ADISC or PDISC after the paused RPI has been resumed.
673 lpfc_mbx_cmpl_resume_rpi(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
675 struct lpfc_vport
*vport
;
676 struct lpfc_iocbq
*elsiocb
;
677 struct lpfc_nodelist
*ndlp
;
680 elsiocb
= (struct lpfc_iocbq
*)mboxq
->ctx_buf
;
681 ndlp
= (struct lpfc_nodelist
*)mboxq
->ctx_ndlp
;
682 vport
= mboxq
->vport
;
683 cmd
= elsiocb
->drvrTimeout
;
685 if (cmd
== ELS_CMD_ADISC
) {
686 lpfc_els_rsp_adisc_acc(vport
, elsiocb
, ndlp
);
688 lpfc_els_rsp_acc(vport
, ELS_CMD_PLOGI
, elsiocb
,
692 /* This nlp_put pairs with lpfc_sli4_resume_rpi */
696 mempool_free(mboxq
, phba
->mbox_mem_pool
);
700 lpfc_rcv_padisc(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
701 struct lpfc_iocbq
*cmdiocb
)
703 struct lpfc_hba
*phba
= vport
->phba
;
704 struct lpfc_iocbq
*elsiocb
;
705 struct lpfc_dmabuf
*pcmd
;
706 struct serv_parm
*sp
;
707 struct lpfc_name
*pnn
, *ppn
;
713 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
714 lp
= (uint32_t *) pcmd
->virt
;
717 if (cmd
== ELS_CMD_ADISC
) {
719 pnn
= (struct lpfc_name
*) & ap
->nodeName
;
720 ppn
= (struct lpfc_name
*) & ap
->portName
;
722 sp
= (struct serv_parm
*) lp
;
723 pnn
= (struct lpfc_name
*) & sp
->nodeName
;
724 ppn
= (struct lpfc_name
*) & sp
->portName
;
727 if (get_job_ulpstatus(phba
, cmdiocb
) == 0 &&
728 lpfc_check_adisc(vport
, ndlp
, pnn
, ppn
)) {
731 * As soon as we send ACC, the remote NPort can
732 * start sending us data. Thus, for SLI4 we must
733 * resume the RPI before the ACC goes out.
735 if (vport
->phba
->sli_rev
== LPFC_SLI_REV4
) {
736 elsiocb
= kmalloc(sizeof(struct lpfc_iocbq
),
739 /* Save info from cmd IOCB used in rsp */
740 memcpy((uint8_t *)elsiocb
, (uint8_t *)cmdiocb
,
741 sizeof(struct lpfc_iocbq
));
743 /* Save the ELS cmd */
744 elsiocb
->drvrTimeout
= cmd
;
746 lpfc_sli4_resume_rpi(ndlp
,
747 lpfc_mbx_cmpl_resume_rpi
, elsiocb
);
752 if (cmd
== ELS_CMD_ADISC
) {
753 lpfc_els_rsp_adisc_acc(vport
, cmdiocb
, ndlp
);
755 lpfc_els_rsp_acc(vport
, ELS_CMD_PLOGI
, cmdiocb
,
759 /* If we are authenticated, move to the proper state.
760 * It is possible an ADISC arrived and the remote nport
761 * is already in MAPPED or UNMAPPED state. Catch this
762 * condition and don't set the nlp_state again because
763 * it causes an unnecessary transport unregister/register.
765 * Nodes marked for ADISC will move MAPPED or UNMAPPED state
766 * after issuing ADISC
768 if (ndlp
->nlp_type
& (NLP_FCP_TARGET
| NLP_NVME_TARGET
)) {
769 if ((ndlp
->nlp_state
!= NLP_STE_MAPPED_NODE
) &&
770 !(ndlp
->nlp_flag
& NLP_NPR_ADISC
))
771 lpfc_nlp_set_state(vport
, ndlp
,
772 NLP_STE_MAPPED_NODE
);
777 /* Reject this request because invalid parameters */
778 stat
.un
.b
.lsRjtRsvd0
= 0;
779 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
780 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_SPARM_OPTIONS
;
781 stat
.un
.b
.vendorUnique
= 0;
782 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
785 mod_timer(&ndlp
->nlp_delayfunc
, jiffies
+ msecs_to_jiffies(1000));
787 spin_lock_irq(&ndlp
->lock
);
788 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
789 spin_unlock_irq(&ndlp
->lock
);
790 ndlp
->nlp_last_elscmd
= ELS_CMD_PLOGI
;
791 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
792 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
797 lpfc_rcv_logo(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
798 struct lpfc_iocbq
*cmdiocb
, uint32_t els_cmd
)
800 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
801 struct lpfc_hba
*phba
= vport
->phba
;
802 struct lpfc_vport
**vports
;
803 int i
, active_vlink_present
= 0 ;
805 /* Put ndlp in NPR state with 1 sec timeout for plogi, ACC logo */
806 /* Only call LOGO ACC for first LOGO, this avoids sending unnecessary
807 * PLOGIs during LOGO storms from a device.
809 spin_lock_irq(&ndlp
->lock
);
810 ndlp
->nlp_flag
|= NLP_LOGO_ACC
;
811 spin_unlock_irq(&ndlp
->lock
);
812 if (els_cmd
== ELS_CMD_PRLO
)
813 lpfc_els_rsp_acc(vport
, ELS_CMD_PRLO
, cmdiocb
, ndlp
, NULL
);
815 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
817 /* This clause allows the initiator to ACC the LOGO back to the
818 * Fabric Domain Controller. It does deliberately skip all other
819 * steps because some fabrics send RDP requests after logging out
820 * from the initiator.
822 if (ndlp
->nlp_type
& NLP_FABRIC
&&
823 ((ndlp
->nlp_DID
& WELL_KNOWN_DID_MASK
) != WELL_KNOWN_DID_MASK
))
826 /* Notify transport of connectivity loss to trigger cleanup. */
827 if (phba
->nvmet_support
&&
828 ndlp
->nlp_state
== NLP_STE_UNMAPPED_NODE
)
829 lpfc_nvmet_invalidate_host(phba
, ndlp
);
831 if (ndlp
->nlp_DID
== Fabric_DID
) {
832 if (vport
->port_state
<= LPFC_FDISC
)
834 lpfc_linkdown_port(vport
);
835 spin_lock_irq(shost
->host_lock
);
836 vport
->fc_flag
|= FC_VPORT_LOGO_RCVD
;
837 spin_unlock_irq(shost
->host_lock
);
838 vports
= lpfc_create_vport_work_array(phba
);
840 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
;
842 if ((!(vports
[i
]->fc_flag
&
843 FC_VPORT_LOGO_RCVD
)) &&
844 (vports
[i
]->port_state
> LPFC_FDISC
)) {
845 active_vlink_present
= 1;
849 lpfc_destroy_vport_work_array(phba
, vports
);
853 * Don't re-instantiate if vport is marked for deletion.
854 * If we are here first then vport_delete is going to wait
855 * for discovery to complete.
857 if (!(vport
->load_flag
& FC_UNLOADING
) &&
858 active_vlink_present
) {
860 * If there are other active VLinks present,
861 * re-instantiate the Vlink using FDISC.
863 mod_timer(&ndlp
->nlp_delayfunc
,
864 jiffies
+ msecs_to_jiffies(1000));
865 spin_lock_irq(&ndlp
->lock
);
866 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
867 spin_unlock_irq(&ndlp
->lock
);
868 ndlp
->nlp_last_elscmd
= ELS_CMD_FDISC
;
869 vport
->port_state
= LPFC_FDISC
;
871 spin_lock_irq(shost
->host_lock
);
872 phba
->pport
->fc_flag
&= ~FC_LOGO_RCVD_DID_CHNG
;
873 spin_unlock_irq(shost
->host_lock
);
874 lpfc_retry_pport_discovery(phba
);
876 } else if ((!(ndlp
->nlp_type
& NLP_FABRIC
) &&
877 ((ndlp
->nlp_type
& NLP_FCP_TARGET
) ||
878 (ndlp
->nlp_type
& NLP_NVME_TARGET
) ||
879 (vport
->fc_flag
& FC_PT2PT
))) ||
880 (ndlp
->nlp_state
== NLP_STE_ADISC_ISSUE
)) {
881 /* Only try to re-login if this is NOT a Fabric Node
882 * AND the remote NPORT is a FCP/NVME Target or we
883 * are in pt2pt mode. NLP_STE_ADISC_ISSUE is a special
884 * case for LOGO as a response to ADISC behavior.
886 mod_timer(&ndlp
->nlp_delayfunc
,
887 jiffies
+ msecs_to_jiffies(1000 * 1));
888 spin_lock_irq(&ndlp
->lock
);
889 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
890 spin_unlock_irq(&ndlp
->lock
);
892 ndlp
->nlp_last_elscmd
= ELS_CMD_PLOGI
;
895 /* Unregister from backend, could have been skipped due to ADISC */
896 lpfc_nlp_unreg_node(vport
, ndlp
);
898 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
899 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
901 spin_lock_irq(&ndlp
->lock
);
902 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
903 spin_unlock_irq(&ndlp
->lock
);
904 /* The driver has to wait until the ACC completes before it continues
905 * processing the LOGO. The action will resume in
906 * lpfc_cmpl_els_logo_acc routine. Since part of processing includes an
907 * unreg_login, the driver waits so the ACC does not get aborted.
913 lpfc_rcv_prli_support_check(struct lpfc_vport
*vport
,
914 struct lpfc_nodelist
*ndlp
,
915 struct lpfc_iocbq
*cmdiocb
)
921 payload
= ((struct lpfc_dmabuf
*)cmdiocb
->context2
)->virt
;
923 if (vport
->phba
->nvmet_support
) {
924 /* Must be a NVME PRLI */
925 if (cmd
== ELS_CMD_PRLI
)
928 /* Initiator mode. */
929 if (!vport
->nvmei_support
&& (cmd
== ELS_CMD_NVMEPRLI
))
934 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_NVME_DISC
,
935 "6115 Rcv PRLI (%x) check failed: ndlp rpi %d "
936 "state x%x flags x%x\n",
937 cmd
, ndlp
->nlp_rpi
, ndlp
->nlp_state
,
939 memset(&stat
, 0, sizeof(struct ls_rjt
));
940 stat
.un
.b
.lsRjtRsnCode
= LSRJT_CMD_UNSUPPORTED
;
941 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_REQ_UNSUPPORTED
;
942 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
,
948 lpfc_rcv_prli(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
949 struct lpfc_iocbq
*cmdiocb
)
951 struct lpfc_hba
*phba
= vport
->phba
;
952 struct lpfc_dmabuf
*pcmd
;
955 struct fc_rport
*rport
= ndlp
->rport
;
958 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
959 lp
= (uint32_t *) pcmd
->virt
;
960 npr
= (PRLI
*) ((uint8_t *) lp
+ sizeof (uint32_t));
962 if ((npr
->prliType
== PRLI_FCP_TYPE
) ||
963 (npr
->prliType
== PRLI_NVME_TYPE
)) {
964 if (npr
->initiatorFunc
) {
965 if (npr
->prliType
== PRLI_FCP_TYPE
)
966 ndlp
->nlp_type
|= NLP_FCP_INITIATOR
;
967 if (npr
->prliType
== PRLI_NVME_TYPE
)
968 ndlp
->nlp_type
|= NLP_NVME_INITIATOR
;
970 if (npr
->targetFunc
) {
971 if (npr
->prliType
== PRLI_FCP_TYPE
)
972 ndlp
->nlp_type
|= NLP_FCP_TARGET
;
973 if (npr
->prliType
== PRLI_NVME_TYPE
)
974 ndlp
->nlp_type
|= NLP_NVME_TARGET
;
975 if (npr
->writeXferRdyDis
)
976 ndlp
->nlp_flag
|= NLP_FIRSTBURST
;
978 if (npr
->Retry
&& ndlp
->nlp_type
&
979 (NLP_FCP_INITIATOR
| NLP_FCP_TARGET
))
980 ndlp
->nlp_fcp_info
|= NLP_FCP_2_DEVICE
;
982 if (npr
->Retry
&& phba
->nsler
&&
983 ndlp
->nlp_type
& (NLP_NVME_INITIATOR
| NLP_NVME_TARGET
))
984 ndlp
->nlp_nvme_info
|= NLP_NVME_NSLER
;
987 /* If this driver is in nvme target mode, set the ndlp's fc4
988 * type to NVME provided the PRLI response claims NVME FC4
989 * type. Target mode does not issue gft_id so doesn't get
990 * the fc4 type set until now.
992 if (phba
->nvmet_support
&& (npr
->prliType
== PRLI_NVME_TYPE
)) {
993 ndlp
->nlp_fc4_type
|= NLP_FC4_NVME
;
994 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
997 /* Fabric Controllers send FCP PRLI as an initiator but should
998 * not get recognized as FCP type and registered with transport.
1000 if (npr
->prliType
== PRLI_FCP_TYPE
&&
1001 !(ndlp
->nlp_type
& NLP_FABRIC
))
1002 ndlp
->nlp_fc4_type
|= NLP_FC4_FCP
;
1005 /* We need to update the rport role values */
1006 roles
= FC_RPORT_ROLE_UNKNOWN
;
1007 if (ndlp
->nlp_type
& NLP_FCP_INITIATOR
)
1008 roles
|= FC_RPORT_ROLE_FCP_INITIATOR
;
1009 if (ndlp
->nlp_type
& NLP_FCP_TARGET
)
1010 roles
|= FC_RPORT_ROLE_FCP_TARGET
;
1012 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_RPORT
,
1013 "rport rolechg: role:x%x did:x%x flg:x%x",
1014 roles
, ndlp
->nlp_DID
, ndlp
->nlp_flag
);
1016 if (vport
->cfg_enable_fc4_type
!= LPFC_ENABLE_NVME
)
1017 fc_remote_port_rolechg(rport
, roles
);
1022 lpfc_disc_set_adisc(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
1024 if (!(ndlp
->nlp_flag
& NLP_RPI_REGISTERED
)) {
1025 spin_lock_irq(&ndlp
->lock
);
1026 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
1027 spin_unlock_irq(&ndlp
->lock
);
1031 if (!(vport
->fc_flag
& FC_PT2PT
)) {
1032 /* Check config parameter use-adisc or FCP-2 */
1033 if (vport
->cfg_use_adisc
&& ((vport
->fc_flag
& FC_RSCN_MODE
) ||
1034 ((ndlp
->nlp_fcp_info
& NLP_FCP_2_DEVICE
) &&
1035 (ndlp
->nlp_type
& NLP_FCP_TARGET
)))) {
1036 spin_lock_irq(&ndlp
->lock
);
1037 ndlp
->nlp_flag
|= NLP_NPR_ADISC
;
1038 spin_unlock_irq(&ndlp
->lock
);
1043 spin_lock_irq(&ndlp
->lock
);
1044 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
1045 spin_unlock_irq(&ndlp
->lock
);
1046 lpfc_unreg_rpi(vport
, ndlp
);
1051 * lpfc_release_rpi - Release a RPI by issuing unreg_login mailbox cmd.
1052 * @phba : Pointer to lpfc_hba structure.
1053 * @vport: Pointer to lpfc_vport structure.
1054 * @ndlp: Pointer to lpfc_nodelist structure.
1055 * @rpi : rpi to be release.
1057 * This function will send a unreg_login mailbox command to the firmware
1061 lpfc_release_rpi(struct lpfc_hba
*phba
, struct lpfc_vport
*vport
,
1062 struct lpfc_nodelist
*ndlp
, uint16_t rpi
)
1067 /* If there is already an UNREG in progress for this ndlp,
1068 * no need to queue up another one.
1070 if (ndlp
->nlp_flag
& NLP_UNREG_INP
) {
1071 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
1072 "1435 release_rpi SKIP UNREG x%x on "
1073 "NPort x%x deferred x%x flg x%x "
1075 ndlp
->nlp_rpi
, ndlp
->nlp_DID
,
1076 ndlp
->nlp_defer_did
,
1077 ndlp
->nlp_flag
, ndlp
);
1081 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
,
1084 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
1085 "2796 mailbox memory allocation failed \n");
1087 lpfc_unreg_login(phba
, vport
->vpi
, rpi
, pmb
);
1088 pmb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
1090 pmb
->ctx_ndlp
= lpfc_nlp_get(ndlp
);
1091 if (!pmb
->ctx_ndlp
) {
1092 mempool_free(pmb
, phba
->mbox_mem_pool
);
1096 if (((ndlp
->nlp_DID
& Fabric_DID_MASK
) != Fabric_DID_MASK
) &&
1097 (!(vport
->fc_flag
& FC_OFFLINE_MODE
)))
1098 ndlp
->nlp_flag
|= NLP_UNREG_INP
;
1100 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
1101 "1437 release_rpi UNREG x%x "
1102 "on NPort x%x flg x%x\n",
1103 ndlp
->nlp_rpi
, ndlp
->nlp_DID
, ndlp
->nlp_flag
);
1105 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
1106 if (rc
== MBX_NOT_FINISHED
)
1107 mempool_free(pmb
, phba
->mbox_mem_pool
);
1112 lpfc_disc_illegal(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1113 void *arg
, uint32_t evt
)
1115 struct lpfc_hba
*phba
;
1116 LPFC_MBOXQ_t
*pmb
= (LPFC_MBOXQ_t
*) arg
;
1120 /* Release the RPI if reglogin completing */
1121 if (!(phba
->pport
->load_flag
& FC_UNLOADING
) &&
1122 (evt
== NLP_EVT_CMPL_REG_LOGIN
) &&
1123 (!pmb
->u
.mb
.mbxStatus
)) {
1124 rpi
= pmb
->u
.mb
.un
.varWords
[0];
1125 lpfc_release_rpi(phba
, vport
, ndlp
, rpi
);
1127 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
1128 "0271 Illegal State Transition: node x%x "
1129 "event x%x, state x%x Data: x%x x%x\n",
1130 ndlp
->nlp_DID
, evt
, ndlp
->nlp_state
, ndlp
->nlp_rpi
,
1132 return ndlp
->nlp_state
;
1136 lpfc_cmpl_plogi_illegal(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1137 void *arg
, uint32_t evt
)
1139 /* This transition is only legal if we previously
1140 * rcv'ed a PLOGI. Since we don't want 2 discovery threads
1141 * working on the same NPortID, do nothing for this thread
1144 if (!(ndlp
->nlp_flag
& NLP_RCV_PLOGI
)) {
1145 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
1146 "0272 Illegal State Transition: node x%x "
1147 "event x%x, state x%x Data: x%x x%x\n",
1148 ndlp
->nlp_DID
, evt
, ndlp
->nlp_state
,
1149 ndlp
->nlp_rpi
, ndlp
->nlp_flag
);
1151 return ndlp
->nlp_state
;
1154 /* Start of Discovery State Machine routines */
1157 lpfc_rcv_plogi_unused_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1158 void *arg
, uint32_t evt
)
1160 struct lpfc_iocbq
*cmdiocb
;
1162 cmdiocb
= (struct lpfc_iocbq
*) arg
;
1164 if (lpfc_rcv_plogi(vport
, ndlp
, cmdiocb
)) {
1165 return ndlp
->nlp_state
;
1167 return NLP_STE_FREED_NODE
;
1171 lpfc_rcv_els_unused_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1172 void *arg
, uint32_t evt
)
1174 lpfc_issue_els_logo(vport
, ndlp
, 0);
1175 return ndlp
->nlp_state
;
1179 lpfc_rcv_logo_unused_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1180 void *arg
, uint32_t evt
)
1182 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1184 spin_lock_irq(&ndlp
->lock
);
1185 ndlp
->nlp_flag
|= NLP_LOGO_ACC
;
1186 spin_unlock_irq(&ndlp
->lock
);
1187 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
1189 return ndlp
->nlp_state
;
1193 lpfc_cmpl_logo_unused_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1194 void *arg
, uint32_t evt
)
1196 return NLP_STE_FREED_NODE
;
1200 lpfc_device_rm_unused_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1201 void *arg
, uint32_t evt
)
1203 return NLP_STE_FREED_NODE
;
1207 lpfc_device_recov_unused_node(struct lpfc_vport
*vport
,
1208 struct lpfc_nodelist
*ndlp
,
1209 void *arg
, uint32_t evt
)
1211 return ndlp
->nlp_state
;
1215 lpfc_rcv_plogi_plogi_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1216 void *arg
, uint32_t evt
)
1218 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1219 struct lpfc_hba
*phba
= vport
->phba
;
1220 struct lpfc_iocbq
*cmdiocb
= arg
;
1221 struct lpfc_dmabuf
*pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
1222 uint32_t *lp
= (uint32_t *) pcmd
->virt
;
1223 struct serv_parm
*sp
= (struct serv_parm
*) (lp
+ 1);
1227 memset(&stat
, 0, sizeof (struct ls_rjt
));
1229 /* For a PLOGI, we only accept if our portname is less
1230 * than the remote portname.
1232 phba
->fc_stat
.elsLogiCol
++;
1233 port_cmp
= memcmp(&vport
->fc_portname
, &sp
->portName
,
1234 sizeof(struct lpfc_name
));
1236 if (port_cmp
>= 0) {
1237 /* Reject this request because the remote node will accept
1239 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
1240 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CMD_IN_PROGRESS
;
1241 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
,
1244 if (lpfc_rcv_plogi(vport
, ndlp
, cmdiocb
) &&
1245 (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) &&
1246 (vport
->num_disc_nodes
)) {
1247 spin_lock_irq(&ndlp
->lock
);
1248 ndlp
->nlp_flag
&= ~NLP_NPR_2B_DISC
;
1249 spin_unlock_irq(&ndlp
->lock
);
1250 /* Check if there are more PLOGIs to be sent */
1251 lpfc_more_plogi(vport
);
1252 if (vport
->num_disc_nodes
== 0) {
1253 spin_lock_irq(shost
->host_lock
);
1254 vport
->fc_flag
&= ~FC_NDISC_ACTIVE
;
1255 spin_unlock_irq(shost
->host_lock
);
1256 lpfc_can_disctmo(vport
);
1257 lpfc_end_rscn(vport
);
1260 } /* If our portname was less */
1262 return ndlp
->nlp_state
;
1266 lpfc_rcv_prli_plogi_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1267 void *arg
, uint32_t evt
)
1269 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1272 memset(&stat
, 0, sizeof (struct ls_rjt
));
1273 stat
.un
.b
.lsRjtRsnCode
= LSRJT_LOGICAL_BSY
;
1274 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_NOTHING_MORE
;
1275 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
1276 return ndlp
->nlp_state
;
1280 lpfc_rcv_logo_plogi_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1281 void *arg
, uint32_t evt
)
1283 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1285 /* Retrieve RPI from LOGO IOCB. RPI is used for CMD_ABORT_XRI_CN */
1286 if (vport
->phba
->sli_rev
== LPFC_SLI_REV3
)
1287 ndlp
->nlp_rpi
= cmdiocb
->iocb
.ulpIoTag
;
1288 /* software abort outstanding PLOGI */
1289 lpfc_els_abort(vport
->phba
, ndlp
);
1291 lpfc_rcv_logo(vport
, ndlp
, cmdiocb
, ELS_CMD_LOGO
);
1292 return ndlp
->nlp_state
;
1296 lpfc_rcv_els_plogi_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1297 void *arg
, uint32_t evt
)
1299 struct lpfc_hba
*phba
= vport
->phba
;
1300 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1302 /* software abort outstanding PLOGI */
1303 lpfc_els_abort(phba
, ndlp
);
1305 if (evt
== NLP_EVT_RCV_LOGO
) {
1306 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
1308 lpfc_issue_els_logo(vport
, ndlp
, 0);
1311 /* Put ndlp in npr state set plogi timer for 1 sec */
1312 mod_timer(&ndlp
->nlp_delayfunc
, jiffies
+ msecs_to_jiffies(1000 * 1));
1313 spin_lock_irq(&ndlp
->lock
);
1314 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
1315 spin_unlock_irq(&ndlp
->lock
);
1316 ndlp
->nlp_last_elscmd
= ELS_CMD_PLOGI
;
1317 ndlp
->nlp_prev_state
= NLP_STE_PLOGI_ISSUE
;
1318 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1320 return ndlp
->nlp_state
;
1324 lpfc_cmpl_plogi_plogi_issue(struct lpfc_vport
*vport
,
1325 struct lpfc_nodelist
*ndlp
,
1329 struct lpfc_hba
*phba
= vport
->phba
;
1330 struct lpfc_iocbq
*cmdiocb
, *rspiocb
;
1331 struct lpfc_dmabuf
*pcmd
, *prsp
, *mp
;
1334 struct serv_parm
*sp
;
1341 cmdiocb
= (struct lpfc_iocbq
*) arg
;
1342 rspiocb
= cmdiocb
->context_un
.rsp_iocb
;
1344 ulp_status
= get_job_ulpstatus(phba
, rspiocb
);
1346 if (ndlp
->nlp_flag
& NLP_ACC_REGLOGIN
) {
1347 /* Recovery from PLOGI collision logic */
1348 return ndlp
->nlp_state
;
1354 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
1356 prsp
= list_get_first(&pcmd
->list
, struct lpfc_dmabuf
, list
);
1360 lp
= (uint32_t *) prsp
->virt
;
1361 sp
= (struct serv_parm
*) ((uint8_t *) lp
+ sizeof (uint32_t));
1363 /* Some switches have FDMI servers returning 0 for WWN */
1364 if ((ndlp
->nlp_DID
!= FDMI_DID
) &&
1365 (wwn_to_u64(sp
->portName
.u
.wwn
) == 0 ||
1366 wwn_to_u64(sp
->nodeName
.u
.wwn
) == 0)) {
1367 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
1368 "0142 PLOGI RSP: Invalid WWN.\n");
1371 if (!lpfc_check_sparm(vport
, ndlp
, sp
, CLASS3
, 0))
1373 /* PLOGI chkparm OK */
1374 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
1375 "0121 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
1376 ndlp
->nlp_DID
, ndlp
->nlp_state
,
1377 ndlp
->nlp_flag
, ndlp
->nlp_rpi
);
1378 if (vport
->cfg_fcp_class
== 2 && (sp
->cls2
.classValid
))
1379 ndlp
->nlp_fcp_info
|= CLASS2
;
1381 ndlp
->nlp_fcp_info
|= CLASS3
;
1383 ndlp
->nlp_class_sup
= 0;
1384 if (sp
->cls1
.classValid
)
1385 ndlp
->nlp_class_sup
|= FC_COS_CLASS1
;
1386 if (sp
->cls2
.classValid
)
1387 ndlp
->nlp_class_sup
|= FC_COS_CLASS2
;
1388 if (sp
->cls3
.classValid
)
1389 ndlp
->nlp_class_sup
|= FC_COS_CLASS3
;
1390 if (sp
->cls4
.classValid
)
1391 ndlp
->nlp_class_sup
|= FC_COS_CLASS4
;
1392 ndlp
->nlp_maxframe
=
1393 ((sp
->cmn
.bbRcvSizeMsb
& 0x0F) << 8) | sp
->cmn
.bbRcvSizeLsb
;
1395 if ((vport
->fc_flag
& FC_PT2PT
) &&
1396 (vport
->fc_flag
& FC_PT2PT_PLOGI
)) {
1397 ed_tov
= be32_to_cpu(sp
->cmn
.e_d_tov
);
1398 if (sp
->cmn
.edtovResolution
) {
1399 /* E_D_TOV ticks are in nanoseconds */
1400 ed_tov
= (phba
->fc_edtov
+ 999999) / 1000000;
1403 ndlp
->nlp_flag
&= ~NLP_SUPPRESS_RSP
;
1404 if ((phba
->sli
.sli_flag
& LPFC_SLI_SUPPRESS_RSP
) &&
1405 sp
->cmn
.valid_vendor_ver_level
) {
1406 vid
= be32_to_cpu(sp
->un
.vv
.vid
);
1407 flag
= be32_to_cpu(sp
->un
.vv
.flags
);
1408 if ((vid
== LPFC_VV_EMLX_ID
) &&
1409 (flag
& LPFC_VV_SUPPRESS_RSP
))
1410 ndlp
->nlp_flag
|= NLP_SUPPRESS_RSP
;
1414 * Use the larger EDTOV
1415 * RATOV = 2 * EDTOV for pt-to-pt
1417 if (ed_tov
> phba
->fc_edtov
)
1418 phba
->fc_edtov
= ed_tov
;
1419 phba
->fc_ratov
= (2 * phba
->fc_edtov
) / 1000;
1421 memcpy(&phba
->fc_fabparam
, sp
, sizeof(struct serv_parm
));
1423 /* Issue config_link / reg_vfi to account for updated TOV's */
1424 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
1425 lpfc_issue_reg_vfi(vport
);
1427 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1429 lpfc_printf_vlog(vport
, KERN_ERR
,
1431 "0133 PLOGI: no memory "
1433 "Data: x%x x%x x%x x%x\n",
1434 ndlp
->nlp_DID
, ndlp
->nlp_state
,
1435 ndlp
->nlp_flag
, ndlp
->nlp_rpi
);
1439 lpfc_config_link(phba
, mbox
);
1441 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
1442 mbox
->vport
= vport
;
1443 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
1444 if (rc
== MBX_NOT_FINISHED
) {
1445 mempool_free(mbox
, phba
->mbox_mem_pool
);
1451 lpfc_unreg_rpi(vport
, ndlp
);
1453 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1455 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
1456 "0018 PLOGI: no memory for reg_login "
1457 "Data: x%x x%x x%x x%x\n",
1458 ndlp
->nlp_DID
, ndlp
->nlp_state
,
1459 ndlp
->nlp_flag
, ndlp
->nlp_rpi
);
1463 did
= get_job_els_rsp64_did(phba
, cmdiocb
);
1465 if (lpfc_reg_rpi(phba
, vport
->vpi
, did
,
1466 (uint8_t *) sp
, mbox
, ndlp
->nlp_rpi
) == 0) {
1467 switch (ndlp
->nlp_DID
) {
1468 case NameServer_DID
:
1469 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_ns_reg_login
;
1470 /* Fabric Controller Node needs these parameters. */
1471 memcpy(&ndlp
->fc_sparam
, sp
, sizeof(struct serv_parm
));
1474 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_fdmi_reg_login
;
1477 ndlp
->nlp_flag
|= NLP_REG_LOGIN_SEND
;
1478 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_reg_login
;
1481 mbox
->ctx_ndlp
= lpfc_nlp_get(ndlp
);
1482 if (!mbox
->ctx_ndlp
)
1485 mbox
->vport
= vport
;
1486 if (lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
)
1487 != MBX_NOT_FINISHED
) {
1488 lpfc_nlp_set_state(vport
, ndlp
,
1489 NLP_STE_REG_LOGIN_ISSUE
);
1490 return ndlp
->nlp_state
;
1492 if (ndlp
->nlp_flag
& NLP_REG_LOGIN_SEND
)
1493 ndlp
->nlp_flag
&= ~NLP_REG_LOGIN_SEND
;
1494 /* decrement node reference count to the failed mbox
1498 mp
= (struct lpfc_dmabuf
*)mbox
->ctx_buf
;
1499 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
1501 mempool_free(mbox
, phba
->mbox_mem_pool
);
1503 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
1504 "0134 PLOGI: cannot issue reg_login "
1505 "Data: x%x x%x x%x x%x\n",
1506 ndlp
->nlp_DID
, ndlp
->nlp_state
,
1507 ndlp
->nlp_flag
, ndlp
->nlp_rpi
);
1509 mempool_free(mbox
, phba
->mbox_mem_pool
);
1511 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
1512 "0135 PLOGI: cannot format 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
);
1520 if (ndlp
->nlp_DID
== NameServer_DID
) {
1521 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
1522 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
1523 "0261 Cannot Register NameServer login\n");
1527 ** In case the node reference counter does not go to zero, ensure that
1528 ** the stale state for the node is not processed.
1531 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
1532 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1533 return NLP_STE_FREED_NODE
;
1537 lpfc_cmpl_logo_plogi_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1538 void *arg
, uint32_t evt
)
1540 return ndlp
->nlp_state
;
1544 lpfc_cmpl_reglogin_plogi_issue(struct lpfc_vport
*vport
,
1545 struct lpfc_nodelist
*ndlp
, void *arg
, uint32_t evt
)
1547 struct lpfc_hba
*phba
;
1548 LPFC_MBOXQ_t
*pmb
= (LPFC_MBOXQ_t
*) arg
;
1549 MAILBOX_t
*mb
= &pmb
->u
.mb
;
1553 /* Release the RPI */
1554 if (!(phba
->pport
->load_flag
& FC_UNLOADING
) &&
1556 rpi
= pmb
->u
.mb
.un
.varWords
[0];
1557 lpfc_release_rpi(phba
, vport
, ndlp
, rpi
);
1559 return ndlp
->nlp_state
;
1563 lpfc_device_rm_plogi_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1564 void *arg
, uint32_t evt
)
1566 if (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) {
1567 spin_lock_irq(&ndlp
->lock
);
1568 ndlp
->nlp_flag
|= NLP_NODEV_REMOVE
;
1569 spin_unlock_irq(&ndlp
->lock
);
1570 return ndlp
->nlp_state
;
1572 /* software abort outstanding PLOGI */
1573 lpfc_els_abort(vport
->phba
, ndlp
);
1575 lpfc_drop_node(vport
, ndlp
);
1576 return NLP_STE_FREED_NODE
;
1581 lpfc_device_recov_plogi_issue(struct lpfc_vport
*vport
,
1582 struct lpfc_nodelist
*ndlp
,
1586 struct lpfc_hba
*phba
= vport
->phba
;
1588 /* Don't do anything that will mess up processing of the
1591 if (vport
->fc_flag
& FC_RSCN_DEFERRED
)
1592 return ndlp
->nlp_state
;
1594 /* software abort outstanding PLOGI */
1595 lpfc_els_abort(phba
, ndlp
);
1597 ndlp
->nlp_prev_state
= NLP_STE_PLOGI_ISSUE
;
1598 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1599 spin_lock_irq(&ndlp
->lock
);
1600 ndlp
->nlp_flag
&= ~(NLP_NODEV_REMOVE
| NLP_NPR_2B_DISC
);
1601 spin_unlock_irq(&ndlp
->lock
);
1603 return ndlp
->nlp_state
;
1607 lpfc_rcv_plogi_adisc_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1608 void *arg
, uint32_t evt
)
1610 struct lpfc_hba
*phba
= vport
->phba
;
1611 struct lpfc_iocbq
*cmdiocb
;
1613 /* software abort outstanding ADISC */
1614 lpfc_els_abort(phba
, ndlp
);
1616 cmdiocb
= (struct lpfc_iocbq
*) arg
;
1618 if (lpfc_rcv_plogi(vport
, ndlp
, cmdiocb
)) {
1619 if (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) {
1620 spin_lock_irq(&ndlp
->lock
);
1621 ndlp
->nlp_flag
&= ~NLP_NPR_2B_DISC
;
1622 spin_unlock_irq(&ndlp
->lock
);
1623 if (vport
->num_disc_nodes
)
1624 lpfc_more_adisc(vport
);
1626 return ndlp
->nlp_state
;
1628 ndlp
->nlp_prev_state
= NLP_STE_ADISC_ISSUE
;
1629 lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0);
1630 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
1632 return ndlp
->nlp_state
;
1636 lpfc_rcv_prli_adisc_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1637 void *arg
, uint32_t evt
)
1639 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1641 if (lpfc_rcv_prli_support_check(vport
, ndlp
, cmdiocb
))
1642 lpfc_els_rsp_prli_acc(vport
, cmdiocb
, ndlp
);
1643 return ndlp
->nlp_state
;
1647 lpfc_rcv_logo_adisc_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1648 void *arg
, uint32_t evt
)
1650 struct lpfc_hba
*phba
= vport
->phba
;
1651 struct lpfc_iocbq
*cmdiocb
;
1653 cmdiocb
= (struct lpfc_iocbq
*) arg
;
1655 /* software abort outstanding ADISC */
1656 lpfc_els_abort(phba
, ndlp
);
1658 lpfc_rcv_logo(vport
, ndlp
, cmdiocb
, ELS_CMD_LOGO
);
1659 return ndlp
->nlp_state
;
1663 lpfc_rcv_padisc_adisc_issue(struct lpfc_vport
*vport
,
1664 struct lpfc_nodelist
*ndlp
,
1665 void *arg
, uint32_t evt
)
1667 struct lpfc_iocbq
*cmdiocb
;
1669 cmdiocb
= (struct lpfc_iocbq
*) arg
;
1671 lpfc_rcv_padisc(vport
, ndlp
, cmdiocb
);
1672 return ndlp
->nlp_state
;
1676 lpfc_rcv_prlo_adisc_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1677 void *arg
, uint32_t evt
)
1679 struct lpfc_iocbq
*cmdiocb
;
1681 cmdiocb
= (struct lpfc_iocbq
*) arg
;
1683 /* Treat like rcv logo */
1684 lpfc_rcv_logo(vport
, ndlp
, cmdiocb
, ELS_CMD_PRLO
);
1685 return ndlp
->nlp_state
;
1689 lpfc_cmpl_adisc_adisc_issue(struct lpfc_vport
*vport
,
1690 struct lpfc_nodelist
*ndlp
,
1691 void *arg
, uint32_t evt
)
1693 struct lpfc_hba
*phba
= vport
->phba
;
1694 struct lpfc_iocbq
*cmdiocb
, *rspiocb
;
1699 cmdiocb
= (struct lpfc_iocbq
*) arg
;
1700 rspiocb
= cmdiocb
->context_un
.rsp_iocb
;
1702 ulp_status
= get_job_ulpstatus(phba
, rspiocb
);
1704 ap
= (ADISC
*)lpfc_check_elscmpl_iocb(phba
, cmdiocb
, rspiocb
);
1707 (!lpfc_check_adisc(vport
, ndlp
, &ap
->nodeName
, &ap
->portName
))) {
1709 mod_timer(&ndlp
->nlp_delayfunc
,
1710 jiffies
+ msecs_to_jiffies(1000));
1711 spin_lock_irq(&ndlp
->lock
);
1712 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
1713 spin_unlock_irq(&ndlp
->lock
);
1714 ndlp
->nlp_last_elscmd
= ELS_CMD_PLOGI
;
1716 ndlp
->nlp_prev_state
= NLP_STE_ADISC_ISSUE
;
1717 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1718 lpfc_unreg_rpi(vport
, ndlp
);
1719 return ndlp
->nlp_state
;
1722 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
1723 rc
= lpfc_sli4_resume_rpi(ndlp
, NULL
, NULL
);
1725 /* Stay in state and retry. */
1726 ndlp
->nlp_prev_state
= NLP_STE_ADISC_ISSUE
;
1727 return ndlp
->nlp_state
;
1731 if (ndlp
->nlp_type
& NLP_FCP_TARGET
)
1732 ndlp
->nlp_fc4_type
|= NLP_FC4_FCP
;
1734 if (ndlp
->nlp_type
& NLP_NVME_TARGET
)
1735 ndlp
->nlp_fc4_type
|= NLP_FC4_NVME
;
1737 if (ndlp
->nlp_type
& (NLP_FCP_TARGET
| NLP_NVME_TARGET
)) {
1738 ndlp
->nlp_prev_state
= NLP_STE_ADISC_ISSUE
;
1739 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_MAPPED_NODE
);
1741 ndlp
->nlp_prev_state
= NLP_STE_ADISC_ISSUE
;
1742 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
1745 return ndlp
->nlp_state
;
1749 lpfc_device_rm_adisc_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1750 void *arg
, uint32_t evt
)
1752 if (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) {
1753 spin_lock_irq(&ndlp
->lock
);
1754 ndlp
->nlp_flag
|= NLP_NODEV_REMOVE
;
1755 spin_unlock_irq(&ndlp
->lock
);
1756 return ndlp
->nlp_state
;
1758 /* software abort outstanding ADISC */
1759 lpfc_els_abort(vport
->phba
, ndlp
);
1761 lpfc_drop_node(vport
, ndlp
);
1762 return NLP_STE_FREED_NODE
;
1767 lpfc_device_recov_adisc_issue(struct lpfc_vport
*vport
,
1768 struct lpfc_nodelist
*ndlp
,
1772 struct lpfc_hba
*phba
= vport
->phba
;
1774 /* Don't do anything that will mess up processing of the
1777 if (vport
->fc_flag
& FC_RSCN_DEFERRED
)
1778 return ndlp
->nlp_state
;
1780 /* software abort outstanding ADISC */
1781 lpfc_els_abort(phba
, ndlp
);
1783 ndlp
->nlp_prev_state
= NLP_STE_ADISC_ISSUE
;
1784 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1785 spin_lock_irq(&ndlp
->lock
);
1786 ndlp
->nlp_flag
&= ~(NLP_NODEV_REMOVE
| NLP_NPR_2B_DISC
);
1787 spin_unlock_irq(&ndlp
->lock
);
1788 lpfc_disc_set_adisc(vport
, ndlp
);
1789 return ndlp
->nlp_state
;
1793 lpfc_rcv_plogi_reglogin_issue(struct lpfc_vport
*vport
,
1794 struct lpfc_nodelist
*ndlp
,
1798 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1800 lpfc_rcv_plogi(vport
, ndlp
, cmdiocb
);
1801 return ndlp
->nlp_state
;
1805 lpfc_rcv_prli_reglogin_issue(struct lpfc_vport
*vport
,
1806 struct lpfc_nodelist
*ndlp
,
1810 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1813 if (!lpfc_rcv_prli_support_check(vport
, ndlp
, cmdiocb
)) {
1814 return ndlp
->nlp_state
;
1816 if (vport
->phba
->nvmet_support
) {
1817 /* NVME Target mode. Handle and respond to the PRLI and
1818 * transition to UNMAPPED provided the RPI has completed
1821 if (ndlp
->nlp_flag
& NLP_RPI_REGISTERED
) {
1822 lpfc_rcv_prli(vport
, ndlp
, cmdiocb
);
1823 lpfc_els_rsp_prli_acc(vport
, cmdiocb
, ndlp
);
1825 /* RPI registration has not completed. Reject the PRLI
1826 * to prevent an illegal state transition when the
1827 * rpi registration does complete.
1829 memset(&stat
, 0, sizeof(struct ls_rjt
));
1830 stat
.un
.b
.lsRjtRsnCode
= LSRJT_LOGICAL_BSY
;
1831 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_NOTHING_MORE
;
1832 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
,
1834 return ndlp
->nlp_state
;
1837 /* Initiator mode. */
1838 lpfc_els_rsp_prli_acc(vport
, cmdiocb
, ndlp
);
1840 return ndlp
->nlp_state
;
1844 lpfc_rcv_logo_reglogin_issue(struct lpfc_vport
*vport
,
1845 struct lpfc_nodelist
*ndlp
,
1849 struct lpfc_hba
*phba
= vport
->phba
;
1850 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1852 LPFC_MBOXQ_t
*nextmb
;
1853 struct lpfc_dmabuf
*mp
;
1854 struct lpfc_nodelist
*ns_ndlp
;
1856 cmdiocb
= (struct lpfc_iocbq
*) arg
;
1858 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
1859 if ((mb
= phba
->sli
.mbox_active
)) {
1860 if ((mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) &&
1861 (ndlp
== (struct lpfc_nodelist
*)mb
->ctx_ndlp
)) {
1862 ndlp
->nlp_flag
&= ~NLP_REG_LOGIN_SEND
;
1864 mb
->ctx_ndlp
= NULL
;
1865 mb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
1869 spin_lock_irq(&phba
->hbalock
);
1870 list_for_each_entry_safe(mb
, nextmb
, &phba
->sli
.mboxq
, list
) {
1871 if ((mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) &&
1872 (ndlp
== (struct lpfc_nodelist
*)mb
->ctx_ndlp
)) {
1873 mp
= (struct lpfc_dmabuf
*)(mb
->ctx_buf
);
1875 __lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
1878 ndlp
->nlp_flag
&= ~NLP_REG_LOGIN_SEND
;
1880 list_del(&mb
->list
);
1881 phba
->sli
.mboxq_cnt
--;
1882 mempool_free(mb
, phba
->mbox_mem_pool
);
1885 spin_unlock_irq(&phba
->hbalock
);
1887 /* software abort if any GID_FT is outstanding */
1888 if (vport
->cfg_enable_fc4_type
!= LPFC_ENABLE_FCP
) {
1889 ns_ndlp
= lpfc_findnode_did(vport
, NameServer_DID
);
1891 lpfc_els_abort(phba
, ns_ndlp
);
1894 lpfc_rcv_logo(vport
, ndlp
, cmdiocb
, ELS_CMD_LOGO
);
1895 return ndlp
->nlp_state
;
1899 lpfc_rcv_padisc_reglogin_issue(struct lpfc_vport
*vport
,
1900 struct lpfc_nodelist
*ndlp
,
1904 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1906 lpfc_rcv_padisc(vport
, ndlp
, cmdiocb
);
1907 return ndlp
->nlp_state
;
1911 lpfc_rcv_prlo_reglogin_issue(struct lpfc_vport
*vport
,
1912 struct lpfc_nodelist
*ndlp
,
1916 struct lpfc_iocbq
*cmdiocb
;
1918 cmdiocb
= (struct lpfc_iocbq
*) arg
;
1919 lpfc_els_rsp_acc(vport
, ELS_CMD_PRLO
, cmdiocb
, ndlp
, NULL
);
1920 return ndlp
->nlp_state
;
1924 lpfc_cmpl_reglogin_reglogin_issue(struct lpfc_vport
*vport
,
1925 struct lpfc_nodelist
*ndlp
,
1929 struct lpfc_hba
*phba
= vport
->phba
;
1930 LPFC_MBOXQ_t
*pmb
= (LPFC_MBOXQ_t
*) arg
;
1931 MAILBOX_t
*mb
= &pmb
->u
.mb
;
1932 uint32_t did
= mb
->un
.varWords
[1];
1934 if (mb
->mbxStatus
) {
1935 /* RegLogin failed */
1936 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_TRACE_EVENT
,
1937 "0246 RegLogin failed Data: x%x x%x x%x x%x "
1939 did
, mb
->mbxStatus
, vport
->port_state
,
1940 mb
->un
.varRegLogin
.vpi
,
1941 mb
->un
.varRegLogin
.rpi
);
1943 * If RegLogin failed due to lack of HBA resources do not
1946 if (mb
->mbxStatus
== MBXERR_RPI_FULL
) {
1947 ndlp
->nlp_prev_state
= NLP_STE_REG_LOGIN_ISSUE
;
1948 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1949 return ndlp
->nlp_state
;
1952 /* Put ndlp in npr state set plogi timer for 1 sec */
1953 mod_timer(&ndlp
->nlp_delayfunc
,
1954 jiffies
+ msecs_to_jiffies(1000 * 1));
1955 spin_lock_irq(&ndlp
->lock
);
1956 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
1957 spin_unlock_irq(&ndlp
->lock
);
1958 ndlp
->nlp_last_elscmd
= ELS_CMD_PLOGI
;
1960 lpfc_issue_els_logo(vport
, ndlp
, 0);
1961 return ndlp
->nlp_state
;
1964 /* SLI4 ports have preallocated logical rpis. */
1965 if (phba
->sli_rev
< LPFC_SLI_REV4
)
1966 ndlp
->nlp_rpi
= mb
->un
.varWords
[0];
1968 ndlp
->nlp_flag
|= NLP_RPI_REGISTERED
;
1970 /* Only if we are not a fabric nport do we issue PRLI */
1971 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
1972 "3066 RegLogin Complete on x%x x%x x%x\n",
1973 did
, ndlp
->nlp_type
, ndlp
->nlp_fc4_type
);
1974 if (!(ndlp
->nlp_type
& NLP_FABRIC
) &&
1975 (phba
->nvmet_support
== 0)) {
1976 /* The driver supports FCP and NVME concurrently. If the
1977 * ndlp's nlp_fc4_type is still zero, the driver doesn't
1978 * know what PRLI to send yet. Figure that out now and
1979 * call PRLI depending on the outcome.
1981 if (vport
->fc_flag
& FC_PT2PT
) {
1982 /* If we are pt2pt, there is no Fabric to determine
1983 * the FC4 type of the remote nport. So if NVME
1984 * is configured try it.
1986 ndlp
->nlp_fc4_type
|= NLP_FC4_FCP
;
1987 if ((!(vport
->fc_flag
& FC_PT2PT_NO_NVME
)) &&
1988 (vport
->cfg_enable_fc4_type
== LPFC_ENABLE_BOTH
||
1989 vport
->cfg_enable_fc4_type
== LPFC_ENABLE_NVME
)) {
1990 ndlp
->nlp_fc4_type
|= NLP_FC4_NVME
;
1991 /* We need to update the localport also */
1992 lpfc_nvme_update_localport(vport
);
1995 } else if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) {
1996 ndlp
->nlp_fc4_type
|= NLP_FC4_FCP
;
1998 } else if (ndlp
->nlp_fc4_type
== 0) {
1999 /* If we are only configured for FCP, the driver
2000 * should just issue PRLI for FCP. Otherwise issue
2001 * GFT_ID to determine if remote port supports NVME.
2003 if (vport
->cfg_enable_fc4_type
!= LPFC_ENABLE_FCP
) {
2004 lpfc_ns_cmd(vport
, SLI_CTNS_GFT_ID
, 0,
2006 return ndlp
->nlp_state
;
2008 ndlp
->nlp_fc4_type
= NLP_FC4_FCP
;
2011 ndlp
->nlp_prev_state
= NLP_STE_REG_LOGIN_ISSUE
;
2012 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PRLI_ISSUE
);
2013 if (lpfc_issue_els_prli(vport
, ndlp
, 0)) {
2014 lpfc_issue_els_logo(vport
, ndlp
, 0);
2015 ndlp
->nlp_prev_state
= NLP_STE_REG_LOGIN_ISSUE
;
2016 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
2019 if ((vport
->fc_flag
& FC_PT2PT
) && phba
->nvmet_support
)
2020 phba
->targetport
->port_id
= vport
->fc_myDID
;
2022 /* Only Fabric ports should transition. NVME target
2023 * must complete PRLI.
2025 if (ndlp
->nlp_type
& NLP_FABRIC
) {
2026 ndlp
->nlp_fc4_type
&= ~NLP_FC4_FCP
;
2027 ndlp
->nlp_prev_state
= NLP_STE_REG_LOGIN_ISSUE
;
2028 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
2031 return ndlp
->nlp_state
;
2035 lpfc_device_rm_reglogin_issue(struct lpfc_vport
*vport
,
2036 struct lpfc_nodelist
*ndlp
,
2040 if (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) {
2041 spin_lock_irq(&ndlp
->lock
);
2042 ndlp
->nlp_flag
|= NLP_NODEV_REMOVE
;
2043 spin_unlock_irq(&ndlp
->lock
);
2044 return ndlp
->nlp_state
;
2046 lpfc_drop_node(vport
, ndlp
);
2047 return NLP_STE_FREED_NODE
;
2052 lpfc_device_recov_reglogin_issue(struct lpfc_vport
*vport
,
2053 struct lpfc_nodelist
*ndlp
,
2057 /* Don't do anything that will mess up processing of the
2060 if (vport
->fc_flag
& FC_RSCN_DEFERRED
)
2061 return ndlp
->nlp_state
;
2063 ndlp
->nlp_prev_state
= NLP_STE_REG_LOGIN_ISSUE
;
2064 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
2065 spin_lock_irq(&ndlp
->lock
);
2067 /* If we are a target we won't immediately transition into PRLI,
2068 * so if REG_LOGIN already completed we don't need to ignore it.
2070 if (!(ndlp
->nlp_flag
& NLP_RPI_REGISTERED
) ||
2071 !vport
->phba
->nvmet_support
)
2072 ndlp
->nlp_flag
|= NLP_IGNR_REG_CMPL
;
2074 ndlp
->nlp_flag
&= ~(NLP_NODEV_REMOVE
| NLP_NPR_2B_DISC
);
2075 spin_unlock_irq(&ndlp
->lock
);
2076 lpfc_disc_set_adisc(vport
, ndlp
);
2077 return ndlp
->nlp_state
;
2081 lpfc_rcv_plogi_prli_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2082 void *arg
, uint32_t evt
)
2084 struct lpfc_iocbq
*cmdiocb
;
2086 cmdiocb
= (struct lpfc_iocbq
*) arg
;
2088 lpfc_rcv_plogi(vport
, ndlp
, cmdiocb
);
2089 return ndlp
->nlp_state
;
2093 lpfc_rcv_prli_prli_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2094 void *arg
, uint32_t evt
)
2096 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2098 if (!lpfc_rcv_prli_support_check(vport
, ndlp
, cmdiocb
))
2099 return ndlp
->nlp_state
;
2100 lpfc_rcv_prli(vport
, ndlp
, cmdiocb
);
2101 lpfc_els_rsp_prli_acc(vport
, cmdiocb
, ndlp
);
2102 return ndlp
->nlp_state
;
2106 lpfc_rcv_logo_prli_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2107 void *arg
, uint32_t evt
)
2109 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2111 /* Software abort outstanding PRLI before sending acc */
2112 lpfc_els_abort(vport
->phba
, ndlp
);
2114 lpfc_rcv_logo(vport
, ndlp
, cmdiocb
, ELS_CMD_LOGO
);
2115 return ndlp
->nlp_state
;
2119 lpfc_rcv_padisc_prli_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2120 void *arg
, uint32_t evt
)
2122 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2124 lpfc_rcv_padisc(vport
, ndlp
, cmdiocb
);
2125 return ndlp
->nlp_state
;
2128 /* This routine is envoked when we rcv a PRLO request from a nport
2129 * we are logged into. We should send back a PRLO rsp setting the
2131 * NEXT STATE = PRLI_ISSUE
2134 lpfc_rcv_prlo_prli_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2135 void *arg
, uint32_t evt
)
2137 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2139 lpfc_els_rsp_acc(vport
, ELS_CMD_PRLO
, cmdiocb
, ndlp
, NULL
);
2140 return ndlp
->nlp_state
;
2144 lpfc_cmpl_prli_prli_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2145 void *arg
, uint32_t evt
)
2147 struct lpfc_iocbq
*cmdiocb
, *rspiocb
;
2148 struct lpfc_hba
*phba
= vport
->phba
;
2150 struct lpfc_nvme_prli
*nvpr
;
2154 cmdiocb
= (struct lpfc_iocbq
*) arg
;
2155 rspiocb
= cmdiocb
->context_un
.rsp_iocb
;
2157 ulp_status
= get_job_ulpstatus(phba
, rspiocb
);
2159 /* A solicited PRLI is either FCP or NVME. The PRLI cmd/rsp
2160 * format is different so NULL the two PRLI types so that the
2161 * driver correctly gets the correct context.
2165 temp_ptr
= lpfc_check_elscmpl_iocb(phba
, cmdiocb
, rspiocb
);
2166 if (cmdiocb
->cmd_flag
& LPFC_PRLI_FCP_REQ
)
2167 npr
= (PRLI
*) temp_ptr
;
2168 else if (cmdiocb
->cmd_flag
& LPFC_PRLI_NVME_REQ
)
2169 nvpr
= (struct lpfc_nvme_prli
*) temp_ptr
;
2172 if ((vport
->port_type
== LPFC_NPIV_PORT
) &&
2173 vport
->cfg_restrict_login
) {
2177 /* Adjust the nlp_type accordingly if the PRLI failed */
2179 ndlp
->nlp_fc4_type
&= ~NLP_FC4_FCP
;
2181 ndlp
->nlp_fc4_type
&= ~NLP_FC4_NVME
;
2183 /* We can't set the DSM state till BOTH PRLIs complete */
2187 if (npr
&& (npr
->acceptRspCode
== PRLI_REQ_EXECUTED
) &&
2188 (npr
->prliType
== PRLI_FCP_TYPE
)) {
2189 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NVME_DISC
,
2190 "6028 FCP NPR PRLI Cmpl Init %d Target %d\n",
2193 if (npr
->initiatorFunc
)
2194 ndlp
->nlp_type
|= NLP_FCP_INITIATOR
;
2195 if (npr
->targetFunc
) {
2196 ndlp
->nlp_type
|= NLP_FCP_TARGET
;
2197 if (npr
->writeXferRdyDis
)
2198 ndlp
->nlp_flag
|= NLP_FIRSTBURST
;
2201 ndlp
->nlp_fcp_info
|= NLP_FCP_2_DEVICE
;
2204 (bf_get_be32(prli_acc_rsp_code
, nvpr
) ==
2205 PRLI_REQ_EXECUTED
) &&
2206 (bf_get_be32(prli_type_code
, nvpr
) ==
2209 /* Complete setting up the remote ndlp personality. */
2210 if (bf_get_be32(prli_init
, nvpr
))
2211 ndlp
->nlp_type
|= NLP_NVME_INITIATOR
;
2213 if (phba
->nsler
&& bf_get_be32(prli_nsler
, nvpr
) &&
2214 bf_get_be32(prli_conf
, nvpr
))
2216 ndlp
->nlp_nvme_info
|= NLP_NVME_NSLER
;
2218 ndlp
->nlp_nvme_info
&= ~NLP_NVME_NSLER
;
2220 /* Target driver cannot solicit NVME FB. */
2221 if (bf_get_be32(prli_tgt
, nvpr
)) {
2222 /* Complete the nvme target roles. The transport
2223 * needs to know if the rport is capable of
2224 * discovery in addition to its role.
2226 ndlp
->nlp_type
|= NLP_NVME_TARGET
;
2227 if (bf_get_be32(prli_disc
, nvpr
))
2228 ndlp
->nlp_type
|= NLP_NVME_DISCOVERY
;
2231 * If prli_fba is set, the Target supports FirstBurst.
2232 * If prli_fb_sz is 0, the FirstBurst size is unlimited,
2233 * otherwise it defines the actual size supported by
2236 if ((bf_get_be32(prli_fba
, nvpr
) == 1) &&
2237 (phba
->cfg_nvme_enable_fb
) &&
2238 (!phba
->nvmet_support
)) {
2239 /* Both sides support FB. The target's first
2240 * burst size is a 512 byte encoded value.
2242 ndlp
->nlp_flag
|= NLP_FIRSTBURST
;
2243 ndlp
->nvme_fb_size
= bf_get_be32(prli_fb_sz
,
2246 /* Expressed in units of 512 bytes */
2247 if (ndlp
->nvme_fb_size
)
2248 ndlp
->nvme_fb_size
<<=
2251 ndlp
->nvme_fb_size
= LPFC_NVME_MAX_FB
;
2255 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NVME_DISC
,
2256 "6029 NVME PRLI Cmpl w1 x%08x "
2257 "w4 x%08x w5 x%08x flag x%x, "
2258 "fcp_info x%x nlp_type x%x\n",
2259 be32_to_cpu(nvpr
->word1
),
2260 be32_to_cpu(nvpr
->word4
),
2261 be32_to_cpu(nvpr
->word5
),
2262 ndlp
->nlp_flag
, ndlp
->nlp_fcp_info
,
2265 if (!(ndlp
->nlp_type
& NLP_FCP_TARGET
) &&
2266 (vport
->port_type
== LPFC_NPIV_PORT
) &&
2267 vport
->cfg_restrict_login
) {
2269 spin_lock_irq(&ndlp
->lock
);
2270 ndlp
->nlp_flag
|= NLP_TARGET_REMOVE
;
2271 spin_unlock_irq(&ndlp
->lock
);
2272 lpfc_issue_els_logo(vport
, ndlp
, 0);
2274 ndlp
->nlp_prev_state
= NLP_STE_PRLI_ISSUE
;
2275 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
2276 return ndlp
->nlp_state
;
2280 /* The ndlp state cannot move to MAPPED or UNMAPPED before all PRLIs
2283 if (ndlp
->fc4_prli_sent
== 0) {
2284 ndlp
->nlp_prev_state
= NLP_STE_PRLI_ISSUE
;
2285 if (ndlp
->nlp_type
& (NLP_FCP_TARGET
| NLP_NVME_TARGET
))
2286 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_MAPPED_NODE
);
2287 else if (ndlp
->nlp_type
&
2288 (NLP_FCP_INITIATOR
| NLP_NVME_INITIATOR
))
2289 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
2291 lpfc_printf_vlog(vport
,
2293 "3067 PRLI's still outstanding "
2294 "on x%06x - count %d, Pend Node Mode "
2296 ndlp
->nlp_DID
, ndlp
->fc4_prli_sent
);
2298 return ndlp
->nlp_state
;
2301 /*! lpfc_device_rm_prli_issue
2312 * This routine is envoked when we a request to remove a nport we are in the
2313 * process of PRLIing. We should software abort outstanding prli, unreg
2314 * login, send a logout. We will change node state to UNUSED_NODE, put it
2315 * on plogi list so it can be freed when LOGO completes.
2320 lpfc_device_rm_prli_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2321 void *arg
, uint32_t evt
)
2323 if (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) {
2324 spin_lock_irq(&ndlp
->lock
);
2325 ndlp
->nlp_flag
|= NLP_NODEV_REMOVE
;
2326 spin_unlock_irq(&ndlp
->lock
);
2327 return ndlp
->nlp_state
;
2329 /* software abort outstanding PLOGI */
2330 lpfc_els_abort(vport
->phba
, ndlp
);
2332 lpfc_drop_node(vport
, ndlp
);
2333 return NLP_STE_FREED_NODE
;
2338 /*! lpfc_device_recov_prli_issue
2349 * The routine is envoked when the state of a device is unknown, like
2350 * during a link down. We should remove the nodelist entry from the
2351 * unmapped list, issue a UNREG_LOGIN, do a software abort of the
2352 * outstanding PRLI command, then free the node entry.
2355 lpfc_device_recov_prli_issue(struct lpfc_vport
*vport
,
2356 struct lpfc_nodelist
*ndlp
,
2360 struct lpfc_hba
*phba
= vport
->phba
;
2362 /* Don't do anything that will mess up processing of the
2365 if (vport
->fc_flag
& FC_RSCN_DEFERRED
)
2366 return ndlp
->nlp_state
;
2368 /* software abort outstanding PRLI */
2369 lpfc_els_abort(phba
, ndlp
);
2371 ndlp
->nlp_prev_state
= NLP_STE_PRLI_ISSUE
;
2372 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
2373 spin_lock_irq(&ndlp
->lock
);
2374 ndlp
->nlp_flag
&= ~(NLP_NODEV_REMOVE
| NLP_NPR_2B_DISC
);
2375 spin_unlock_irq(&ndlp
->lock
);
2376 lpfc_disc_set_adisc(vport
, ndlp
);
2377 return ndlp
->nlp_state
;
2381 lpfc_rcv_plogi_logo_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2382 void *arg
, uint32_t evt
)
2384 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*)arg
;
2387 memset(&stat
, 0, sizeof(struct ls_rjt
));
2388 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
2389 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_NOTHING_MORE
;
2390 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
2391 return ndlp
->nlp_state
;
2395 lpfc_rcv_prli_logo_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2396 void *arg
, uint32_t evt
)
2398 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*)arg
;
2401 memset(&stat
, 0, sizeof(struct ls_rjt
));
2402 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
2403 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_NOTHING_MORE
;
2404 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
2405 return ndlp
->nlp_state
;
2409 lpfc_rcv_logo_logo_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2410 void *arg
, uint32_t evt
)
2412 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*)arg
;
2414 spin_lock_irq(&ndlp
->lock
);
2415 ndlp
->nlp_flag
|= NLP_LOGO_ACC
;
2416 spin_unlock_irq(&ndlp
->lock
);
2417 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
2418 return ndlp
->nlp_state
;
2422 lpfc_rcv_padisc_logo_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2423 void *arg
, uint32_t evt
)
2425 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*)arg
;
2428 memset(&stat
, 0, sizeof(struct ls_rjt
));
2429 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
2430 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_NOTHING_MORE
;
2431 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
2432 return ndlp
->nlp_state
;
2436 lpfc_rcv_prlo_logo_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2437 void *arg
, uint32_t evt
)
2439 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*)arg
;
2442 memset(&stat
, 0, sizeof(struct ls_rjt
));
2443 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
2444 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_NOTHING_MORE
;
2445 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
2446 return ndlp
->nlp_state
;
2450 lpfc_cmpl_logo_logo_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2451 void *arg
, uint32_t evt
)
2453 ndlp
->nlp_prev_state
= NLP_STE_LOGO_ISSUE
;
2454 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
2455 spin_lock_irq(&ndlp
->lock
);
2456 ndlp
->nlp_flag
&= ~(NLP_NODEV_REMOVE
| NLP_NPR_2B_DISC
);
2457 spin_unlock_irq(&ndlp
->lock
);
2458 lpfc_disc_set_adisc(vport
, ndlp
);
2459 return ndlp
->nlp_state
;
2463 lpfc_device_rm_logo_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2464 void *arg
, uint32_t evt
)
2467 * DevLoss has timed out and is calling for Device Remove.
2468 * In this case, abort the LOGO and cleanup the ndlp
2471 lpfc_unreg_rpi(vport
, ndlp
);
2472 /* software abort outstanding PLOGI */
2473 lpfc_els_abort(vport
->phba
, ndlp
);
2474 lpfc_drop_node(vport
, ndlp
);
2475 return NLP_STE_FREED_NODE
;
2479 lpfc_device_recov_logo_issue(struct lpfc_vport
*vport
,
2480 struct lpfc_nodelist
*ndlp
,
2481 void *arg
, uint32_t evt
)
2484 * Device Recovery events have no meaning for a node with a LOGO
2485 * outstanding. The LOGO has to complete first and handle the
2486 * node from that point.
2488 return ndlp
->nlp_state
;
2492 lpfc_rcv_plogi_unmap_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2493 void *arg
, uint32_t evt
)
2495 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2497 lpfc_rcv_plogi(vport
, ndlp
, cmdiocb
);
2498 return ndlp
->nlp_state
;
2502 lpfc_rcv_prli_unmap_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2503 void *arg
, uint32_t evt
)
2505 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2507 if (!lpfc_rcv_prli_support_check(vport
, ndlp
, cmdiocb
))
2508 return ndlp
->nlp_state
;
2510 lpfc_rcv_prli(vport
, ndlp
, cmdiocb
);
2511 lpfc_els_rsp_prli_acc(vport
, cmdiocb
, ndlp
);
2512 return ndlp
->nlp_state
;
2516 lpfc_rcv_logo_unmap_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2517 void *arg
, uint32_t evt
)
2519 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2521 lpfc_rcv_logo(vport
, ndlp
, cmdiocb
, ELS_CMD_LOGO
);
2522 return ndlp
->nlp_state
;
2526 lpfc_rcv_padisc_unmap_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2527 void *arg
, uint32_t evt
)
2529 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2531 lpfc_rcv_padisc(vport
, ndlp
, cmdiocb
);
2532 return ndlp
->nlp_state
;
2536 lpfc_rcv_prlo_unmap_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2537 void *arg
, uint32_t evt
)
2539 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2541 lpfc_els_rsp_acc(vport
, ELS_CMD_PRLO
, cmdiocb
, ndlp
, NULL
);
2542 return ndlp
->nlp_state
;
2546 lpfc_device_rm_unmap_node(struct lpfc_vport
*vport
,
2547 struct lpfc_nodelist
*ndlp
,
2551 lpfc_drop_node(vport
, ndlp
);
2552 return NLP_STE_FREED_NODE
;
2556 lpfc_device_recov_unmap_node(struct lpfc_vport
*vport
,
2557 struct lpfc_nodelist
*ndlp
,
2561 ndlp
->nlp_prev_state
= NLP_STE_UNMAPPED_NODE
;
2562 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
2563 spin_lock_irq(&ndlp
->lock
);
2564 ndlp
->nlp_flag
&= ~(NLP_NODEV_REMOVE
| NLP_NPR_2B_DISC
);
2565 ndlp
->nlp_fc4_type
&= ~(NLP_FC4_FCP
| NLP_FC4_NVME
);
2566 spin_unlock_irq(&ndlp
->lock
);
2567 lpfc_disc_set_adisc(vport
, ndlp
);
2569 return ndlp
->nlp_state
;
2573 lpfc_rcv_plogi_mapped_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2574 void *arg
, uint32_t evt
)
2576 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2578 lpfc_rcv_plogi(vport
, ndlp
, cmdiocb
);
2579 return ndlp
->nlp_state
;
2583 lpfc_rcv_prli_mapped_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2584 void *arg
, uint32_t evt
)
2586 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2588 if (!lpfc_rcv_prli_support_check(vport
, ndlp
, cmdiocb
))
2589 return ndlp
->nlp_state
;
2590 lpfc_els_rsp_prli_acc(vport
, cmdiocb
, ndlp
);
2591 return ndlp
->nlp_state
;
2595 lpfc_rcv_logo_mapped_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2596 void *arg
, uint32_t evt
)
2598 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2600 lpfc_rcv_logo(vport
, ndlp
, cmdiocb
, ELS_CMD_LOGO
);
2601 return ndlp
->nlp_state
;
2605 lpfc_rcv_padisc_mapped_node(struct lpfc_vport
*vport
,
2606 struct lpfc_nodelist
*ndlp
,
2607 void *arg
, uint32_t evt
)
2609 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2611 lpfc_rcv_padisc(vport
, ndlp
, cmdiocb
);
2612 return ndlp
->nlp_state
;
2616 lpfc_rcv_prlo_mapped_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2617 void *arg
, uint32_t evt
)
2619 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2621 /* flush the target */
2622 lpfc_sli_abort_iocb(vport
, 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 lpfc_disc_set_adisc(vport
, ndlp
);
2637 ndlp
->nlp_prev_state
= NLP_STE_MAPPED_NODE
;
2638 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
2639 spin_lock_irq(&ndlp
->lock
);
2640 ndlp
->nlp_flag
&= ~(NLP_NODEV_REMOVE
| NLP_NPR_2B_DISC
);
2641 ndlp
->nlp_fc4_type
&= ~(NLP_FC4_FCP
| NLP_FC4_NVME
);
2642 spin_unlock_irq(&ndlp
->lock
);
2643 return ndlp
->nlp_state
;
2647 lpfc_rcv_plogi_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2648 void *arg
, uint32_t evt
)
2650 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2652 /* Ignore PLOGI if we have an outstanding LOGO */
2653 if (ndlp
->nlp_flag
& (NLP_LOGO_SND
| NLP_LOGO_ACC
))
2654 return ndlp
->nlp_state
;
2655 if (lpfc_rcv_plogi(vport
, ndlp
, cmdiocb
)) {
2656 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
2657 spin_lock_irq(&ndlp
->lock
);
2658 ndlp
->nlp_flag
&= ~(NLP_NPR_ADISC
| NLP_NPR_2B_DISC
);
2659 spin_unlock_irq(&ndlp
->lock
);
2660 } else if (!(ndlp
->nlp_flag
& NLP_NPR_2B_DISC
)) {
2661 /* send PLOGI immediately, move to PLOGI issue state */
2662 if (!(ndlp
->nlp_flag
& NLP_DELAY_TMO
)) {
2663 ndlp
->nlp_prev_state
= NLP_STE_NPR_NODE
;
2664 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
2665 lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0);
2668 return ndlp
->nlp_state
;
2672 lpfc_rcv_prli_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2673 void *arg
, uint32_t evt
)
2675 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2678 memset(&stat
, 0, sizeof (struct ls_rjt
));
2679 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
2680 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_NOTHING_MORE
;
2681 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
2683 if (!(ndlp
->nlp_flag
& NLP_DELAY_TMO
)) {
2685 * ADISC nodes will be handled in regular discovery path after
2686 * receiving response from NS.
2688 * For other nodes, Send PLOGI to trigger an implicit LOGO.
2690 if (!(ndlp
->nlp_flag
& NLP_NPR_ADISC
)) {
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
)) {
2724 * ADISC nodes will be handled in regular discovery path after
2725 * receiving response from NS.
2727 * For other nodes, Send PLOGI to trigger an implicit LOGO.
2729 if (!(ndlp
->nlp_flag
& NLP_NPR_ADISC
)) {
2730 ndlp
->nlp_prev_state
= NLP_STE_NPR_NODE
;
2731 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
2732 lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0);
2735 return ndlp
->nlp_state
;
2739 lpfc_rcv_prlo_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2740 void *arg
, uint32_t evt
)
2742 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2744 spin_lock_irq(&ndlp
->lock
);
2745 ndlp
->nlp_flag
|= NLP_LOGO_ACC
;
2746 spin_unlock_irq(&ndlp
->lock
);
2748 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
2750 if ((ndlp
->nlp_flag
& NLP_DELAY_TMO
) == 0) {
2751 mod_timer(&ndlp
->nlp_delayfunc
,
2752 jiffies
+ msecs_to_jiffies(1000 * 1));
2753 spin_lock_irq(&ndlp
->lock
);
2754 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
2755 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
2756 spin_unlock_irq(&ndlp
->lock
);
2757 ndlp
->nlp_last_elscmd
= ELS_CMD_PLOGI
;
2759 spin_lock_irq(&ndlp
->lock
);
2760 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
2761 spin_unlock_irq(&ndlp
->lock
);
2763 return ndlp
->nlp_state
;
2767 lpfc_cmpl_plogi_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2768 void *arg
, uint32_t evt
)
2770 struct lpfc_hba
*phba
= vport
->phba
;
2771 struct lpfc_iocbq
*cmdiocb
, *rspiocb
;
2774 cmdiocb
= (struct lpfc_iocbq
*) arg
;
2775 rspiocb
= cmdiocb
->context_un
.rsp_iocb
;
2777 ulp_status
= get_job_ulpstatus(phba
, rspiocb
);
2780 return NLP_STE_FREED_NODE
;
2782 return ndlp
->nlp_state
;
2786 lpfc_cmpl_prli_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2787 void *arg
, uint32_t evt
)
2789 struct lpfc_hba
*phba
= vport
->phba
;
2790 struct lpfc_iocbq
*cmdiocb
, *rspiocb
;
2793 cmdiocb
= (struct lpfc_iocbq
*) arg
;
2794 rspiocb
= cmdiocb
->context_un
.rsp_iocb
;
2796 ulp_status
= get_job_ulpstatus(phba
, rspiocb
);
2798 if (ulp_status
&& (ndlp
->nlp_flag
& NLP_NODEV_REMOVE
)) {
2799 lpfc_drop_node(vport
, ndlp
);
2800 return NLP_STE_FREED_NODE
;
2802 return ndlp
->nlp_state
;
2806 lpfc_cmpl_logo_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2807 void *arg
, uint32_t evt
)
2809 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2811 /* For the fabric port just clear the fc flags. */
2812 if (ndlp
->nlp_DID
== Fabric_DID
) {
2813 spin_lock_irq(shost
->host_lock
);
2814 vport
->fc_flag
&= ~(FC_FABRIC
| FC_PUBLIC_LOOP
);
2815 spin_unlock_irq(shost
->host_lock
);
2817 lpfc_unreg_rpi(vport
, ndlp
);
2818 return ndlp
->nlp_state
;
2822 lpfc_cmpl_adisc_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2823 void *arg
, uint32_t evt
)
2825 struct lpfc_hba
*phba
= vport
->phba
;
2826 struct lpfc_iocbq
*cmdiocb
, *rspiocb
;
2829 cmdiocb
= (struct lpfc_iocbq
*) arg
;
2830 rspiocb
= cmdiocb
->context_un
.rsp_iocb
;
2832 ulp_status
= get_job_ulpstatus(phba
, rspiocb
);
2834 if (ulp_status
&& (ndlp
->nlp_flag
& NLP_NODEV_REMOVE
)) {
2835 lpfc_drop_node(vport
, ndlp
);
2836 return NLP_STE_FREED_NODE
;
2838 return ndlp
->nlp_state
;
2842 lpfc_cmpl_reglogin_npr_node(struct lpfc_vport
*vport
,
2843 struct lpfc_nodelist
*ndlp
,
2844 void *arg
, uint32_t evt
)
2846 LPFC_MBOXQ_t
*pmb
= (LPFC_MBOXQ_t
*) arg
;
2847 MAILBOX_t
*mb
= &pmb
->u
.mb
;
2849 if (!mb
->mbxStatus
) {
2850 /* SLI4 ports have preallocated logical rpis. */
2851 if (vport
->phba
->sli_rev
< LPFC_SLI_REV4
)
2852 ndlp
->nlp_rpi
= mb
->un
.varWords
[0];
2853 ndlp
->nlp_flag
|= NLP_RPI_REGISTERED
;
2854 if (ndlp
->nlp_flag
& NLP_LOGO_ACC
) {
2855 lpfc_unreg_rpi(vport
, ndlp
);
2858 if (ndlp
->nlp_flag
& NLP_NODEV_REMOVE
) {
2859 lpfc_drop_node(vport
, ndlp
);
2860 return NLP_STE_FREED_NODE
;
2863 return ndlp
->nlp_state
;
2867 lpfc_device_rm_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2868 void *arg
, uint32_t evt
)
2870 if (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) {
2871 spin_lock_irq(&ndlp
->lock
);
2872 ndlp
->nlp_flag
|= NLP_NODEV_REMOVE
;
2873 spin_unlock_irq(&ndlp
->lock
);
2874 return ndlp
->nlp_state
;
2876 lpfc_drop_node(vport
, ndlp
);
2877 return NLP_STE_FREED_NODE
;
2881 lpfc_device_recov_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2882 void *arg
, uint32_t evt
)
2884 /* Don't do anything that will mess up processing of the
2887 if (vport
->fc_flag
& FC_RSCN_DEFERRED
)
2888 return ndlp
->nlp_state
;
2890 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
2891 spin_lock_irq(&ndlp
->lock
);
2892 ndlp
->nlp_flag
&= ~(NLP_NODEV_REMOVE
| NLP_NPR_2B_DISC
);
2893 ndlp
->nlp_fc4_type
&= ~(NLP_FC4_FCP
| NLP_FC4_NVME
);
2894 spin_unlock_irq(&ndlp
->lock
);
2895 return ndlp
->nlp_state
;
2899 /* This next section defines the NPort Discovery State Machine */
2901 /* There are 4 different double linked lists nodelist entries can reside on.
2902 * The plogi list and adisc list are used when Link Up discovery or RSCN
2903 * processing is needed. Each list holds the nodes that we will send PLOGI
2904 * or ADISC on. These lists will keep track of what nodes will be effected
2905 * by an RSCN, or a Link Up (Typically, all nodes are effected on Link Up).
2906 * The unmapped_list will contain all nodes that we have successfully logged
2907 * into at the Fibre Channel level. The mapped_list will contain all nodes
2908 * that are mapped FCP targets.
2911 * The bind list is a list of undiscovered (potentially non-existent) nodes
2912 * that we have saved binding information on. This information is used when
2913 * nodes transition from the unmapped to the mapped list.
2915 /* For UNUSED_NODE state, the node has just been allocated .
2916 * For PLOGI_ISSUE and REG_LOGIN_ISSUE, the node is on
2917 * the PLOGI list. For REG_LOGIN_COMPL, the node is taken off the PLOGI list
2918 * and put on the unmapped list. For ADISC processing, the node is taken off
2919 * the ADISC list and placed on either the mapped or unmapped list (depending
2920 * on its previous state). Once on the unmapped list, a PRLI is issued and the
2921 * state changed to PRLI_ISSUE. When the PRLI completion occurs, the state is
2922 * changed to UNMAPPED_NODE. If the completion indicates a mapped
2923 * node, the node is taken off the unmapped list. The binding list is checked
2924 * for a valid binding, or a binding is automatically assigned. If binding
2925 * assignment is unsuccessful, the node is left on the unmapped list. If
2926 * binding assignment is successful, the associated binding list entry (if
2927 * any) is removed, and the node is placed on the mapped list.
2930 * For a Link Down, all nodes on the ADISC, PLOGI, unmapped or mapped
2931 * lists will receive a DEVICE_RECOVERY event. If the linkdown or devloss timers
2932 * expire, all effected nodes will receive a DEVICE_RM event.
2935 * For a Link Up or RSCN, all nodes will move from the mapped / unmapped lists
2936 * to either the ADISC or PLOGI list. After a Nameserver query or ALPA loopmap
2937 * check, additional nodes may be added or removed (via DEVICE_RM) to / from
2938 * the PLOGI or ADISC lists. Once the PLOGI and ADISC lists are populated,
2939 * we will first process the ADISC list. 32 entries are processed initially and
2940 * ADISC is initited for each one. Completions / Events for each node are
2941 * funnelled thru the state machine. As each node finishes ADISC processing, it
2942 * starts ADISC for any nodes waiting for ADISC processing. If no nodes are
2943 * waiting, and the ADISC list count is identically 0, then we are done. For
2944 * Link Up discovery, since all nodes on the PLOGI list are UNREG_LOGIN'ed, we
2945 * can issue a CLEAR_LA and reenable Link Events. Next we will process the PLOGI
2946 * list. 32 entries are processed initially and PLOGI is initited for each one.
2947 * Completions / Events for each node are funnelled thru the state machine. As
2948 * each node finishes PLOGI processing, it starts PLOGI for any nodes waiting
2949 * for PLOGI processing. If no nodes are waiting, and the PLOGI list count is
2950 * indentically 0, then we are done. We have now completed discovery / RSCN
2951 * handling. Upon completion, ALL nodes should be on either the mapped or
2955 static uint32_t (*lpfc_disc_action
[NLP_STE_MAX_STATE
* NLP_EVT_MAX_EVENT
])
2956 (struct lpfc_vport
*, struct lpfc_nodelist
*, void *, uint32_t) = {
2957 /* Action routine Event Current State */
2958 lpfc_rcv_plogi_unused_node
, /* RCV_PLOGI UNUSED_NODE */
2959 lpfc_rcv_els_unused_node
, /* RCV_PRLI */
2960 lpfc_rcv_logo_unused_node
, /* RCV_LOGO */
2961 lpfc_rcv_els_unused_node
, /* RCV_ADISC */
2962 lpfc_rcv_els_unused_node
, /* RCV_PDISC */
2963 lpfc_rcv_els_unused_node
, /* RCV_PRLO */
2964 lpfc_disc_illegal
, /* CMPL_PLOGI */
2965 lpfc_disc_illegal
, /* CMPL_PRLI */
2966 lpfc_cmpl_logo_unused_node
, /* CMPL_LOGO */
2967 lpfc_disc_illegal
, /* CMPL_ADISC */
2968 lpfc_disc_illegal
, /* CMPL_REG_LOGIN */
2969 lpfc_device_rm_unused_node
, /* DEVICE_RM */
2970 lpfc_device_recov_unused_node
, /* DEVICE_RECOVERY */
2972 lpfc_rcv_plogi_plogi_issue
, /* RCV_PLOGI PLOGI_ISSUE */
2973 lpfc_rcv_prli_plogi_issue
, /* RCV_PRLI */
2974 lpfc_rcv_logo_plogi_issue
, /* RCV_LOGO */
2975 lpfc_rcv_els_plogi_issue
, /* RCV_ADISC */
2976 lpfc_rcv_els_plogi_issue
, /* RCV_PDISC */
2977 lpfc_rcv_els_plogi_issue
, /* RCV_PRLO */
2978 lpfc_cmpl_plogi_plogi_issue
, /* CMPL_PLOGI */
2979 lpfc_disc_illegal
, /* CMPL_PRLI */
2980 lpfc_cmpl_logo_plogi_issue
, /* CMPL_LOGO */
2981 lpfc_disc_illegal
, /* CMPL_ADISC */
2982 lpfc_cmpl_reglogin_plogi_issue
,/* CMPL_REG_LOGIN */
2983 lpfc_device_rm_plogi_issue
, /* DEVICE_RM */
2984 lpfc_device_recov_plogi_issue
, /* DEVICE_RECOVERY */
2986 lpfc_rcv_plogi_adisc_issue
, /* RCV_PLOGI ADISC_ISSUE */
2987 lpfc_rcv_prli_adisc_issue
, /* RCV_PRLI */
2988 lpfc_rcv_logo_adisc_issue
, /* RCV_LOGO */
2989 lpfc_rcv_padisc_adisc_issue
, /* RCV_ADISC */
2990 lpfc_rcv_padisc_adisc_issue
, /* RCV_PDISC */
2991 lpfc_rcv_prlo_adisc_issue
, /* RCV_PRLO */
2992 lpfc_disc_illegal
, /* CMPL_PLOGI */
2993 lpfc_disc_illegal
, /* CMPL_PRLI */
2994 lpfc_disc_illegal
, /* CMPL_LOGO */
2995 lpfc_cmpl_adisc_adisc_issue
, /* CMPL_ADISC */
2996 lpfc_disc_illegal
, /* CMPL_REG_LOGIN */
2997 lpfc_device_rm_adisc_issue
, /* DEVICE_RM */
2998 lpfc_device_recov_adisc_issue
, /* DEVICE_RECOVERY */
3000 lpfc_rcv_plogi_reglogin_issue
, /* RCV_PLOGI REG_LOGIN_ISSUE */
3001 lpfc_rcv_prli_reglogin_issue
, /* RCV_PLOGI */
3002 lpfc_rcv_logo_reglogin_issue
, /* RCV_LOGO */
3003 lpfc_rcv_padisc_reglogin_issue
, /* RCV_ADISC */
3004 lpfc_rcv_padisc_reglogin_issue
, /* RCV_PDISC */
3005 lpfc_rcv_prlo_reglogin_issue
, /* RCV_PRLO */
3006 lpfc_cmpl_plogi_illegal
, /* CMPL_PLOGI */
3007 lpfc_disc_illegal
, /* CMPL_PRLI */
3008 lpfc_disc_illegal
, /* CMPL_LOGO */
3009 lpfc_disc_illegal
, /* CMPL_ADISC */
3010 lpfc_cmpl_reglogin_reglogin_issue
,/* CMPL_REG_LOGIN */
3011 lpfc_device_rm_reglogin_issue
, /* DEVICE_RM */
3012 lpfc_device_recov_reglogin_issue
,/* DEVICE_RECOVERY */
3014 lpfc_rcv_plogi_prli_issue
, /* RCV_PLOGI PRLI_ISSUE */
3015 lpfc_rcv_prli_prli_issue
, /* RCV_PRLI */
3016 lpfc_rcv_logo_prli_issue
, /* RCV_LOGO */
3017 lpfc_rcv_padisc_prli_issue
, /* RCV_ADISC */
3018 lpfc_rcv_padisc_prli_issue
, /* RCV_PDISC */
3019 lpfc_rcv_prlo_prli_issue
, /* RCV_PRLO */
3020 lpfc_cmpl_plogi_illegal
, /* CMPL_PLOGI */
3021 lpfc_cmpl_prli_prli_issue
, /* CMPL_PRLI */
3022 lpfc_disc_illegal
, /* CMPL_LOGO */
3023 lpfc_disc_illegal
, /* CMPL_ADISC */
3024 lpfc_disc_illegal
, /* CMPL_REG_LOGIN */
3025 lpfc_device_rm_prli_issue
, /* DEVICE_RM */
3026 lpfc_device_recov_prli_issue
, /* DEVICE_RECOVERY */
3028 lpfc_rcv_plogi_logo_issue
, /* RCV_PLOGI LOGO_ISSUE */
3029 lpfc_rcv_prli_logo_issue
, /* RCV_PRLI */
3030 lpfc_rcv_logo_logo_issue
, /* RCV_LOGO */
3031 lpfc_rcv_padisc_logo_issue
, /* RCV_ADISC */
3032 lpfc_rcv_padisc_logo_issue
, /* RCV_PDISC */
3033 lpfc_rcv_prlo_logo_issue
, /* RCV_PRLO */
3034 lpfc_cmpl_plogi_illegal
, /* CMPL_PLOGI */
3035 lpfc_disc_illegal
, /* CMPL_PRLI */
3036 lpfc_cmpl_logo_logo_issue
, /* CMPL_LOGO */
3037 lpfc_disc_illegal
, /* CMPL_ADISC */
3038 lpfc_disc_illegal
, /* CMPL_REG_LOGIN */
3039 lpfc_device_rm_logo_issue
, /* DEVICE_RM */
3040 lpfc_device_recov_logo_issue
, /* DEVICE_RECOVERY */
3042 lpfc_rcv_plogi_unmap_node
, /* RCV_PLOGI UNMAPPED_NODE */
3043 lpfc_rcv_prli_unmap_node
, /* RCV_PRLI */
3044 lpfc_rcv_logo_unmap_node
, /* RCV_LOGO */
3045 lpfc_rcv_padisc_unmap_node
, /* RCV_ADISC */
3046 lpfc_rcv_padisc_unmap_node
, /* RCV_PDISC */
3047 lpfc_rcv_prlo_unmap_node
, /* RCV_PRLO */
3048 lpfc_disc_illegal
, /* CMPL_PLOGI */
3049 lpfc_disc_illegal
, /* CMPL_PRLI */
3050 lpfc_disc_illegal
, /* CMPL_LOGO */
3051 lpfc_disc_illegal
, /* CMPL_ADISC */
3052 lpfc_disc_illegal
, /* CMPL_REG_LOGIN */
3053 lpfc_device_rm_unmap_node
, /* DEVICE_RM */
3054 lpfc_device_recov_unmap_node
, /* DEVICE_RECOVERY */
3056 lpfc_rcv_plogi_mapped_node
, /* RCV_PLOGI MAPPED_NODE */
3057 lpfc_rcv_prli_mapped_node
, /* RCV_PRLI */
3058 lpfc_rcv_logo_mapped_node
, /* RCV_LOGO */
3059 lpfc_rcv_padisc_mapped_node
, /* RCV_ADISC */
3060 lpfc_rcv_padisc_mapped_node
, /* RCV_PDISC */
3061 lpfc_rcv_prlo_mapped_node
, /* RCV_PRLO */
3062 lpfc_disc_illegal
, /* CMPL_PLOGI */
3063 lpfc_disc_illegal
, /* CMPL_PRLI */
3064 lpfc_disc_illegal
, /* CMPL_LOGO */
3065 lpfc_disc_illegal
, /* CMPL_ADISC */
3066 lpfc_disc_illegal
, /* CMPL_REG_LOGIN */
3067 lpfc_disc_illegal
, /* DEVICE_RM */
3068 lpfc_device_recov_mapped_node
, /* DEVICE_RECOVERY */
3070 lpfc_rcv_plogi_npr_node
, /* RCV_PLOGI NPR_NODE */
3071 lpfc_rcv_prli_npr_node
, /* RCV_PRLI */
3072 lpfc_rcv_logo_npr_node
, /* RCV_LOGO */
3073 lpfc_rcv_padisc_npr_node
, /* RCV_ADISC */
3074 lpfc_rcv_padisc_npr_node
, /* RCV_PDISC */
3075 lpfc_rcv_prlo_npr_node
, /* RCV_PRLO */
3076 lpfc_cmpl_plogi_npr_node
, /* CMPL_PLOGI */
3077 lpfc_cmpl_prli_npr_node
, /* CMPL_PRLI */
3078 lpfc_cmpl_logo_npr_node
, /* CMPL_LOGO */
3079 lpfc_cmpl_adisc_npr_node
, /* CMPL_ADISC */
3080 lpfc_cmpl_reglogin_npr_node
, /* CMPL_REG_LOGIN */
3081 lpfc_device_rm_npr_node
, /* DEVICE_RM */
3082 lpfc_device_recov_npr_node
, /* DEVICE_RECOVERY */
3086 lpfc_disc_state_machine(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
3087 void *arg
, uint32_t evt
)
3089 uint32_t cur_state
, rc
;
3090 uint32_t(*func
) (struct lpfc_vport
*, struct lpfc_nodelist
*, void *,
3092 uint32_t got_ndlp
= 0;
3095 if (lpfc_nlp_get(ndlp
))
3098 cur_state
= ndlp
->nlp_state
;
3100 data1
= (((uint32_t)ndlp
->nlp_fc4_type
<< 16) |
3101 ((uint32_t)ndlp
->nlp_type
));
3102 /* DSM in event <evt> on NPort <nlp_DID> in state <cur_state> */
3103 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
3104 "0211 DSM in event x%x on NPort x%x in "
3105 "state %d rpi x%x Data: x%x x%x\n",
3106 evt
, ndlp
->nlp_DID
, cur_state
, ndlp
->nlp_rpi
,
3107 ndlp
->nlp_flag
, data1
);
3109 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_DSM
,
3110 "DSM in: evt:%d ste:%d did:x%x",
3111 evt
, cur_state
, ndlp
->nlp_DID
);
3113 func
= lpfc_disc_action
[(cur_state
* NLP_EVT_MAX_EVENT
) + evt
];
3114 rc
= (func
) (vport
, ndlp
, arg
, evt
);
3116 /* DSM out state <rc> on NPort <nlp_DID> */
3118 data1
= (((uint32_t)ndlp
->nlp_fc4_type
<< 16) |
3119 ((uint32_t)ndlp
->nlp_type
));
3120 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
3121 "0212 DSM out state %d on NPort x%x "
3122 "rpi x%x Data: x%x x%x\n",
3123 rc
, ndlp
->nlp_DID
, ndlp
->nlp_rpi
, ndlp
->nlp_flag
,
3126 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_DSM
,
3127 "DSM out: ste:%d did:x%x flg:x%x",
3128 rc
, ndlp
->nlp_DID
, ndlp
->nlp_flag
);
3129 /* Decrement the ndlp reference count held for this function */
3132 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
3133 "0213 DSM out state %d on NPort free\n", rc
);
3135 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_DSM
,
3136 "DSM out: ste:%d did:x%x flg:x%x",