1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017 Broadcom. All Rights Reserved. The term *
5 * “Broadcom” refers to Broadcom Limited 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>
35 #include <linux/nvme-fc-driver.h>
40 #include "lpfc_sli4.h"
42 #include "lpfc_disc.h"
44 #include "lpfc_scsi.h"
45 #include "lpfc_nvme.h"
46 #include "lpfc_logmsg.h"
47 #include "lpfc_crtn.h"
48 #include "lpfc_vport.h"
49 #include "lpfc_debugfs.h"
52 /* Called to verify a rcv'ed ADISC was intended for us. */
54 lpfc_check_adisc(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
55 struct lpfc_name
*nn
, struct lpfc_name
*pn
)
57 /* First, we MUST have a RPI registered */
58 if (!(ndlp
->nlp_flag
& NLP_RPI_REGISTERED
))
61 /* Compare the ADISC rsp WWNN / WWPN matches our internal node
62 * table entry for that node.
64 if (memcmp(nn
, &ndlp
->nlp_nodename
, sizeof (struct lpfc_name
)))
67 if (memcmp(pn
, &ndlp
->nlp_portname
, sizeof (struct lpfc_name
)))
70 /* we match, return success */
75 lpfc_check_sparm(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
76 struct serv_parm
*sp
, uint32_t class, int flogi
)
78 volatile struct serv_parm
*hsp
= &vport
->fc_sparam
;
79 uint16_t hsp_value
, ssp_value
= 0;
82 * The receive data field size and buffer-to-buffer receive data field
83 * size entries are 16 bits but are represented as two 8-bit fields in
84 * the driver data structure to account for rsvd bits and other control
85 * bits. Reconstruct and compare the fields as a 16-bit values before
86 * correcting the byte values.
88 if (sp
->cls1
.classValid
) {
90 hsp_value
= ((hsp
->cls1
.rcvDataSizeMsb
<< 8) |
91 hsp
->cls1
.rcvDataSizeLsb
);
92 ssp_value
= ((sp
->cls1
.rcvDataSizeMsb
<< 8) |
93 sp
->cls1
.rcvDataSizeLsb
);
95 goto bad_service_param
;
96 if (ssp_value
> hsp_value
) {
97 sp
->cls1
.rcvDataSizeLsb
=
98 hsp
->cls1
.rcvDataSizeLsb
;
99 sp
->cls1
.rcvDataSizeMsb
=
100 hsp
->cls1
.rcvDataSizeMsb
;
103 } else if (class == CLASS1
)
104 goto bad_service_param
;
105 if (sp
->cls2
.classValid
) {
107 hsp_value
= ((hsp
->cls2
.rcvDataSizeMsb
<< 8) |
108 hsp
->cls2
.rcvDataSizeLsb
);
109 ssp_value
= ((sp
->cls2
.rcvDataSizeMsb
<< 8) |
110 sp
->cls2
.rcvDataSizeLsb
);
112 goto bad_service_param
;
113 if (ssp_value
> hsp_value
) {
114 sp
->cls2
.rcvDataSizeLsb
=
115 hsp
->cls2
.rcvDataSizeLsb
;
116 sp
->cls2
.rcvDataSizeMsb
=
117 hsp
->cls2
.rcvDataSizeMsb
;
120 } else if (class == CLASS2
)
121 goto bad_service_param
;
122 if (sp
->cls3
.classValid
) {
124 hsp_value
= ((hsp
->cls3
.rcvDataSizeMsb
<< 8) |
125 hsp
->cls3
.rcvDataSizeLsb
);
126 ssp_value
= ((sp
->cls3
.rcvDataSizeMsb
<< 8) |
127 sp
->cls3
.rcvDataSizeLsb
);
129 goto bad_service_param
;
130 if (ssp_value
> hsp_value
) {
131 sp
->cls3
.rcvDataSizeLsb
=
132 hsp
->cls3
.rcvDataSizeLsb
;
133 sp
->cls3
.rcvDataSizeMsb
=
134 hsp
->cls3
.rcvDataSizeMsb
;
137 } else if (class == CLASS3
)
138 goto bad_service_param
;
141 * Preserve the upper four bits of the MSB from the PLOGI response.
142 * These bits contain the Buffer-to-Buffer State Change Number
143 * from the target and need to be passed to the FW.
145 hsp_value
= (hsp
->cmn
.bbRcvSizeMsb
<< 8) | hsp
->cmn
.bbRcvSizeLsb
;
146 ssp_value
= (sp
->cmn
.bbRcvSizeMsb
<< 8) | sp
->cmn
.bbRcvSizeLsb
;
147 if (ssp_value
> hsp_value
) {
148 sp
->cmn
.bbRcvSizeLsb
= hsp
->cmn
.bbRcvSizeLsb
;
149 sp
->cmn
.bbRcvSizeMsb
= (sp
->cmn
.bbRcvSizeMsb
& 0xF0) |
150 (hsp
->cmn
.bbRcvSizeMsb
& 0x0F);
153 memcpy(&ndlp
->nlp_nodename
, &sp
->nodeName
, sizeof (struct lpfc_name
));
154 memcpy(&ndlp
->nlp_portname
, &sp
->portName
, sizeof (struct lpfc_name
));
157 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
159 "(%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x) sent "
160 "invalid service parameters. Ignoring device.\n",
162 sp
->nodeName
.u
.wwn
[0], sp
->nodeName
.u
.wwn
[1],
163 sp
->nodeName
.u
.wwn
[2], sp
->nodeName
.u
.wwn
[3],
164 sp
->nodeName
.u
.wwn
[4], sp
->nodeName
.u
.wwn
[5],
165 sp
->nodeName
.u
.wwn
[6], sp
->nodeName
.u
.wwn
[7]);
170 lpfc_check_elscmpl_iocb(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
171 struct lpfc_iocbq
*rspiocb
)
173 struct lpfc_dmabuf
*pcmd
, *prsp
;
178 irsp
= &rspiocb
->iocb
;
179 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
181 /* For lpfc_els_abort, context2 could be zero'ed to delay
182 * freeing associated memory till after ABTS completes.
185 prsp
= list_get_first(&pcmd
->list
, struct lpfc_dmabuf
,
188 lp
= (uint32_t *) prsp
->virt
;
189 ptr
= (void *)((uint8_t *)lp
+ sizeof(uint32_t));
192 /* Force ulpStatus error since we are returning NULL ptr */
193 if (!(irsp
->ulpStatus
)) {
194 irsp
->ulpStatus
= IOSTAT_LOCAL_REJECT
;
195 irsp
->un
.ulpWord
[4] = IOERR_SLI_ABORTED
;
205 * Free resources / clean up outstanding I/Os
206 * associated with a LPFC_NODELIST entry. This
207 * routine effectively results in a "software abort".
210 lpfc_els_abort(struct lpfc_hba
*phba
, struct lpfc_nodelist
*ndlp
)
212 LIST_HEAD(abort_list
);
213 struct lpfc_sli_ring
*pring
;
214 struct lpfc_iocbq
*iocb
, *next_iocb
;
216 pring
= lpfc_phba_elsring(phba
);
218 /* In case of error recovery path, we might have a NULL pring here */
219 if (unlikely(!pring
))
222 /* Abort outstanding I/O on NPort <nlp_DID> */
223 lpfc_printf_vlog(ndlp
->vport
, KERN_INFO
, LOG_DISCOVERY
,
224 "2819 Abort outstanding I/O on NPort x%x "
225 "Data: x%x x%x x%x\n",
226 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
228 /* Clean up all fabric IOs first.*/
229 lpfc_fabric_abort_nport(ndlp
);
232 * Lock the ELS ring txcmplq for SLI3/SLI4 and build a local list
233 * of all ELS IOs that need an ABTS. The IOs need to stay on the
234 * txcmplq so that the abort operation completes them successfully.
236 spin_lock_irq(&phba
->hbalock
);
237 if (phba
->sli_rev
== LPFC_SLI_REV4
)
238 spin_lock(&pring
->ring_lock
);
239 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
, list
) {
240 /* Add to abort_list on on NDLP match. */
241 if (lpfc_check_sli_ndlp(phba
, pring
, iocb
, ndlp
))
242 list_add_tail(&iocb
->dlist
, &abort_list
);
244 if (phba
->sli_rev
== LPFC_SLI_REV4
)
245 spin_unlock(&pring
->ring_lock
);
246 spin_unlock_irq(&phba
->hbalock
);
248 /* Abort the targeted IOs and remove them from the abort list. */
249 list_for_each_entry_safe(iocb
, next_iocb
, &abort_list
, dlist
) {
250 spin_lock_irq(&phba
->hbalock
);
251 list_del_init(&iocb
->dlist
);
252 lpfc_sli_issue_abort_iotag(phba
, pring
, iocb
);
253 spin_unlock_irq(&phba
->hbalock
);
256 INIT_LIST_HEAD(&abort_list
);
258 /* Now process the txq */
259 spin_lock_irq(&phba
->hbalock
);
260 if (phba
->sli_rev
== LPFC_SLI_REV4
)
261 spin_lock(&pring
->ring_lock
);
263 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txq
, list
) {
264 /* Check to see if iocb matches the nport we are looking for */
265 if (lpfc_check_sli_ndlp(phba
, pring
, iocb
, ndlp
)) {
266 list_del_init(&iocb
->list
);
267 list_add_tail(&iocb
->list
, &abort_list
);
271 if (phba
->sli_rev
== LPFC_SLI_REV4
)
272 spin_unlock(&pring
->ring_lock
);
273 spin_unlock_irq(&phba
->hbalock
);
275 /* Cancel all the IOCBs from the completions list */
276 lpfc_sli_cancel_iocbs(phba
, &abort_list
,
277 IOSTAT_LOCAL_REJECT
, IOERR_SLI_ABORTED
);
279 lpfc_cancel_retry_delay_tmo(phba
->pport
, ndlp
);
283 lpfc_rcv_plogi(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
284 struct lpfc_iocbq
*cmdiocb
)
286 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
287 struct lpfc_hba
*phba
= vport
->phba
;
288 struct lpfc_dmabuf
*pcmd
;
289 uint64_t nlp_portwwn
= 0;
292 struct serv_parm
*sp
;
299 memset(&stat
, 0, sizeof (struct ls_rjt
));
300 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
301 lp
= (uint32_t *) pcmd
->virt
;
302 sp
= (struct serv_parm
*) ((uint8_t *) lp
+ sizeof (uint32_t));
303 if (wwn_to_u64(sp
->portName
.u
.wwn
) == 0) {
304 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
305 "0140 PLOGI Reject: invalid nname\n");
306 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
307 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_INVALID_PNAME
;
308 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
,
312 if (wwn_to_u64(sp
->nodeName
.u
.wwn
) == 0) {
313 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
314 "0141 PLOGI Reject: invalid pname\n");
315 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
316 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_INVALID_NNAME
;
317 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
,
322 nlp_portwwn
= wwn_to_u64(ndlp
->nlp_portname
.u
.wwn
);
323 if ((lpfc_check_sparm(vport
, ndlp
, sp
, CLASS3
, 0) == 0)) {
324 /* Reject this request because invalid parameters */
325 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
326 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_SPARM_OPTIONS
;
327 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
,
331 icmd
= &cmdiocb
->iocb
;
333 /* PLOGI chkparm OK */
334 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
335 "0114 PLOGI chkparm OK Data: x%x x%x x%x "
337 ndlp
->nlp_DID
, ndlp
->nlp_state
, ndlp
->nlp_flag
,
338 ndlp
->nlp_rpi
, vport
->port_state
,
341 if (vport
->cfg_fcp_class
== 2 && sp
->cls2
.classValid
)
342 ndlp
->nlp_fcp_info
|= CLASS2
;
344 ndlp
->nlp_fcp_info
|= CLASS3
;
346 ndlp
->nlp_class_sup
= 0;
347 if (sp
->cls1
.classValid
)
348 ndlp
->nlp_class_sup
|= FC_COS_CLASS1
;
349 if (sp
->cls2
.classValid
)
350 ndlp
->nlp_class_sup
|= FC_COS_CLASS2
;
351 if (sp
->cls3
.classValid
)
352 ndlp
->nlp_class_sup
|= FC_COS_CLASS3
;
353 if (sp
->cls4
.classValid
)
354 ndlp
->nlp_class_sup
|= FC_COS_CLASS4
;
356 ((sp
->cmn
.bbRcvSizeMsb
& 0x0F) << 8) | sp
->cmn
.bbRcvSizeLsb
;
358 /* if already logged in, do implicit logout */
359 switch (ndlp
->nlp_state
) {
360 case NLP_STE_NPR_NODE
:
361 if (!(ndlp
->nlp_flag
& NLP_NPR_ADISC
))
363 case NLP_STE_REG_LOGIN_ISSUE
:
364 case NLP_STE_PRLI_ISSUE
:
365 case NLP_STE_UNMAPPED_NODE
:
366 case NLP_STE_MAPPED_NODE
:
367 /* For initiators, lpfc_plogi_confirm_nport skips fabric did.
368 * For target mode, execute implicit logo.
369 * Fabric nodes go into NPR.
371 if (!(ndlp
->nlp_type
& NLP_FABRIC
) &&
372 !(phba
->nvmet_support
)) {
373 lpfc_els_rsp_acc(vport
, ELS_CMD_PLOGI
, cmdiocb
,
377 if (nlp_portwwn
!= 0 &&
378 nlp_portwwn
!= wwn_to_u64(sp
->portName
.u
.wwn
))
379 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
380 "0143 PLOGI recv'd from DID: x%x "
381 "WWPN changed: old %llx new %llx\n",
383 (unsigned long long)nlp_portwwn
,
385 wwn_to_u64(sp
->portName
.u
.wwn
));
387 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
388 /* rport needs to be unregistered first */
389 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
393 ndlp
->nlp_type
&= ~(NLP_FCP_TARGET
| NLP_FCP_INITIATOR
);
394 ndlp
->nlp_type
&= ~(NLP_NVME_TARGET
| NLP_NVME_INITIATOR
);
395 ndlp
->nlp_fcp_info
&= ~NLP_FCP_2_DEVICE
;
396 ndlp
->nlp_flag
&= ~NLP_FIRSTBURST
;
398 /* Check for Nport to NPort pt2pt protocol */
399 if ((vport
->fc_flag
& FC_PT2PT
) &&
400 !(vport
->fc_flag
& FC_PT2PT_PLOGI
)) {
401 /* rcv'ed PLOGI decides what our NPortId will be */
402 vport
->fc_myDID
= icmd
->un
.rcvels
.parmRo
;
404 ed_tov
= be32_to_cpu(sp
->cmn
.e_d_tov
);
405 if (sp
->cmn
.edtovResolution
) {
406 /* E_D_TOV ticks are in nanoseconds */
407 ed_tov
= (phba
->fc_edtov
+ 999999) / 1000000;
411 * For pt-to-pt, use the larger EDTOV
414 if (ed_tov
> phba
->fc_edtov
)
415 phba
->fc_edtov
= ed_tov
;
416 phba
->fc_ratov
= (2 * phba
->fc_edtov
) / 1000;
418 memcpy(&phba
->fc_fabparam
, sp
, sizeof(struct serv_parm
));
420 /* Issue config_link / reg_vfi to account for updated TOV's */
422 if (phba
->sli_rev
== LPFC_SLI_REV4
)
423 lpfc_issue_reg_vfi(vport
);
425 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
428 lpfc_config_link(phba
, mbox
);
429 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
431 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
432 if (rc
== MBX_NOT_FINISHED
) {
433 mempool_free(mbox
, phba
->mbox_mem_pool
);
438 lpfc_can_disctmo(vport
);
441 ndlp
->nlp_flag
&= ~NLP_SUPPRESS_RSP
;
442 if ((phba
->sli
.sli_flag
& LPFC_SLI_SUPPRESS_RSP
) &&
443 sp
->cmn
.valid_vendor_ver_level
) {
444 vid
= be32_to_cpu(sp
->un
.vv
.vid
);
445 flag
= be32_to_cpu(sp
->un
.vv
.flags
);
446 if ((vid
== LPFC_VV_EMLX_ID
) && (flag
& LPFC_VV_SUPPRESS_RSP
))
447 ndlp
->nlp_flag
|= NLP_SUPPRESS_RSP
;
450 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
454 /* Registering an existing RPI behaves differently for SLI3 vs SLI4 */
455 if (phba
->sli_rev
== LPFC_SLI_REV4
)
456 lpfc_unreg_rpi(vport
, ndlp
);
458 rc
= lpfc_reg_rpi(phba
, vport
->vpi
, icmd
->un
.rcvels
.remoteID
,
459 (uint8_t *) sp
, mbox
, ndlp
->nlp_rpi
);
461 mempool_free(mbox
, phba
->mbox_mem_pool
);
465 /* ACC PLOGI rsp command needs to execute first,
466 * queue this mbox command to be processed later.
468 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_reg_login
;
470 * mbox->context2 = lpfc_nlp_get(ndlp) deferred until mailbox
471 * command issued in lpfc_cmpl_els_acc().
474 spin_lock_irq(shost
->host_lock
);
475 ndlp
->nlp_flag
|= (NLP_ACC_REGLOGIN
| NLP_RCV_PLOGI
);
476 spin_unlock_irq(shost
->host_lock
);
479 * If there is an outstanding PLOGI issued, abort it before
480 * sending ACC rsp for received PLOGI. If pending plogi
481 * is not canceled here, the plogi will be rejected by
482 * remote port and will be retried. On a configuration with
483 * single discovery thread, this will cause a huge delay in
484 * discovery. Also this will cause multiple state machines
485 * running in parallel for this node.
487 if (ndlp
->nlp_state
== NLP_STE_PLOGI_ISSUE
) {
488 /* software abort outstanding PLOGI */
489 lpfc_els_abort(phba
, ndlp
);
492 if ((vport
->port_type
== LPFC_NPIV_PORT
&&
493 vport
->cfg_restrict_login
)) {
495 /* In order to preserve RPIs, we want to cleanup
496 * the default RPI the firmware created to rcv
497 * this ELS request. The only way to do this is
498 * to register, then unregister the RPI.
500 spin_lock_irq(shost
->host_lock
);
501 ndlp
->nlp_flag
|= NLP_RM_DFLT_RPI
;
502 spin_unlock_irq(shost
->host_lock
);
503 stat
.un
.b
.lsRjtRsnCode
= LSRJT_INVALID_CMD
;
504 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_NOTHING_MORE
;
505 rc
= lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
,
508 mempool_free(mbox
, phba
->mbox_mem_pool
);
511 rc
= lpfc_els_rsp_acc(vport
, ELS_CMD_PLOGI
, cmdiocb
, ndlp
, mbox
);
513 mempool_free(mbox
, phba
->mbox_mem_pool
);
516 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
517 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_OUT_OF_RESOURCE
;
518 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
523 * lpfc_mbx_cmpl_resume_rpi - Resume RPI completion routine
524 * @phba: pointer to lpfc hba data structure.
525 * @mboxq: pointer to mailbox object
527 * This routine is invoked to issue a completion to a rcv'ed
528 * ADISC or PDISC after the paused RPI has been resumed.
531 lpfc_mbx_cmpl_resume_rpi(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
533 struct lpfc_vport
*vport
;
534 struct lpfc_iocbq
*elsiocb
;
535 struct lpfc_nodelist
*ndlp
;
538 elsiocb
= (struct lpfc_iocbq
*)mboxq
->context1
;
539 ndlp
= (struct lpfc_nodelist
*) mboxq
->context2
;
540 vport
= mboxq
->vport
;
541 cmd
= elsiocb
->drvrTimeout
;
543 if (cmd
== ELS_CMD_ADISC
) {
544 lpfc_els_rsp_adisc_acc(vport
, elsiocb
, ndlp
);
546 lpfc_els_rsp_acc(vport
, ELS_CMD_PLOGI
, elsiocb
,
550 mempool_free(mboxq
, phba
->mbox_mem_pool
);
554 lpfc_rcv_padisc(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
555 struct lpfc_iocbq
*cmdiocb
)
557 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
558 struct lpfc_iocbq
*elsiocb
;
559 struct lpfc_dmabuf
*pcmd
;
560 struct serv_parm
*sp
;
561 struct lpfc_name
*pnn
, *ppn
;
568 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
569 lp
= (uint32_t *) pcmd
->virt
;
572 if (cmd
== ELS_CMD_ADISC
) {
574 pnn
= (struct lpfc_name
*) & ap
->nodeName
;
575 ppn
= (struct lpfc_name
*) & ap
->portName
;
577 sp
= (struct serv_parm
*) lp
;
578 pnn
= (struct lpfc_name
*) & sp
->nodeName
;
579 ppn
= (struct lpfc_name
*) & sp
->portName
;
582 icmd
= &cmdiocb
->iocb
;
583 if (icmd
->ulpStatus
== 0 && lpfc_check_adisc(vport
, ndlp
, pnn
, ppn
)) {
586 * As soon as we send ACC, the remote NPort can
587 * start sending us data. Thus, for SLI4 we must
588 * resume the RPI before the ACC goes out.
590 if (vport
->phba
->sli_rev
== LPFC_SLI_REV4
) {
591 elsiocb
= kmalloc(sizeof(struct lpfc_iocbq
),
595 /* Save info from cmd IOCB used in rsp */
596 memcpy((uint8_t *)elsiocb
, (uint8_t *)cmdiocb
,
597 sizeof(struct lpfc_iocbq
));
599 /* Save the ELS cmd */
600 elsiocb
->drvrTimeout
= cmd
;
602 lpfc_sli4_resume_rpi(ndlp
,
603 lpfc_mbx_cmpl_resume_rpi
, elsiocb
);
608 if (cmd
== ELS_CMD_ADISC
) {
609 lpfc_els_rsp_adisc_acc(vport
, cmdiocb
, ndlp
);
611 lpfc_els_rsp_acc(vport
, ELS_CMD_PLOGI
, cmdiocb
,
615 /* If we are authenticated, move to the proper state */
616 if (ndlp
->nlp_type
& NLP_FCP_TARGET
)
617 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_MAPPED_NODE
);
619 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
623 /* Reject this request because invalid parameters */
624 stat
.un
.b
.lsRjtRsvd0
= 0;
625 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
626 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_SPARM_OPTIONS
;
627 stat
.un
.b
.vendorUnique
= 0;
628 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
631 mod_timer(&ndlp
->nlp_delayfunc
, jiffies
+ msecs_to_jiffies(1000));
633 spin_lock_irq(shost
->host_lock
);
634 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
635 spin_unlock_irq(shost
->host_lock
);
636 ndlp
->nlp_last_elscmd
= ELS_CMD_PLOGI
;
637 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
638 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
643 lpfc_rcv_logo(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
644 struct lpfc_iocbq
*cmdiocb
, uint32_t els_cmd
)
646 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
647 struct lpfc_hba
*phba
= vport
->phba
;
648 struct lpfc_vport
**vports
;
649 int i
, active_vlink_present
= 0 ;
651 /* Put ndlp in NPR state with 1 sec timeout for plogi, ACC logo */
652 /* Only call LOGO ACC for first LOGO, this avoids sending unnecessary
653 * PLOGIs during LOGO storms from a device.
655 spin_lock_irq(shost
->host_lock
);
656 ndlp
->nlp_flag
|= NLP_LOGO_ACC
;
657 spin_unlock_irq(shost
->host_lock
);
658 if (els_cmd
== ELS_CMD_PRLO
)
659 lpfc_els_rsp_acc(vport
, ELS_CMD_PRLO
, cmdiocb
, ndlp
, NULL
);
661 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
662 if (ndlp
->nlp_DID
== Fabric_DID
) {
663 if (vport
->port_state
<= LPFC_FDISC
)
665 lpfc_linkdown_port(vport
);
666 spin_lock_irq(shost
->host_lock
);
667 vport
->fc_flag
|= FC_VPORT_LOGO_RCVD
;
668 spin_unlock_irq(shost
->host_lock
);
669 vports
= lpfc_create_vport_work_array(phba
);
671 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
;
673 if ((!(vports
[i
]->fc_flag
&
674 FC_VPORT_LOGO_RCVD
)) &&
675 (vports
[i
]->port_state
> LPFC_FDISC
)) {
676 active_vlink_present
= 1;
680 lpfc_destroy_vport_work_array(phba
, vports
);
684 * Don't re-instantiate if vport is marked for deletion.
685 * If we are here first then vport_delete is going to wait
686 * for discovery to complete.
688 if (!(vport
->load_flag
& FC_UNLOADING
) &&
689 active_vlink_present
) {
691 * If there are other active VLinks present,
692 * re-instantiate the Vlink using FDISC.
694 mod_timer(&ndlp
->nlp_delayfunc
,
695 jiffies
+ msecs_to_jiffies(1000));
696 spin_lock_irq(shost
->host_lock
);
697 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
698 spin_unlock_irq(shost
->host_lock
);
699 ndlp
->nlp_last_elscmd
= ELS_CMD_FDISC
;
700 vport
->port_state
= LPFC_FDISC
;
702 spin_lock_irq(shost
->host_lock
);
703 phba
->pport
->fc_flag
&= ~FC_LOGO_RCVD_DID_CHNG
;
704 spin_unlock_irq(shost
->host_lock
);
705 lpfc_retry_pport_discovery(phba
);
707 } else if ((!(ndlp
->nlp_type
& NLP_FABRIC
) &&
708 ((ndlp
->nlp_type
& NLP_FCP_TARGET
) ||
709 !(ndlp
->nlp_type
& NLP_FCP_INITIATOR
))) ||
710 (ndlp
->nlp_state
== NLP_STE_ADISC_ISSUE
)) {
711 /* Only try to re-login if this is NOT a Fabric Node */
712 mod_timer(&ndlp
->nlp_delayfunc
,
713 jiffies
+ msecs_to_jiffies(1000 * 1));
714 spin_lock_irq(shost
->host_lock
);
715 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
716 spin_unlock_irq(shost
->host_lock
);
718 ndlp
->nlp_last_elscmd
= ELS_CMD_PLOGI
;
721 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
722 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
724 spin_lock_irq(shost
->host_lock
);
725 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
726 spin_unlock_irq(shost
->host_lock
);
727 /* The driver has to wait until the ACC completes before it continues
728 * processing the LOGO. The action will resume in
729 * lpfc_cmpl_els_logo_acc routine. Since part of processing includes an
730 * unreg_login, the driver waits so the ACC does not get aborted.
736 lpfc_rcv_prli_support_check(struct lpfc_vport
*vport
,
737 struct lpfc_nodelist
*ndlp
,
738 struct lpfc_iocbq
*cmdiocb
)
744 payload
= ((struct lpfc_dmabuf
*)cmdiocb
->context2
)->virt
;
746 if (vport
->phba
->nvmet_support
) {
747 /* Must be a NVME PRLI */
748 if (cmd
== ELS_CMD_PRLI
)
751 /* Initiator mode. */
752 if (!vport
->nvmei_support
&& (cmd
== ELS_CMD_NVMEPRLI
))
757 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_NVME_DISC
,
758 "6115 Rcv PRLI (%x) check failed: ndlp rpi %d "
759 "state x%x flags x%x\n",
760 cmd
, ndlp
->nlp_rpi
, ndlp
->nlp_state
,
762 memset(&stat
, 0, sizeof(struct ls_rjt
));
763 stat
.un
.b
.lsRjtRsnCode
= LSRJT_CMD_UNSUPPORTED
;
764 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_REQ_UNSUPPORTED
;
765 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
,
771 lpfc_rcv_prli(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
772 struct lpfc_iocbq
*cmdiocb
)
774 struct lpfc_hba
*phba
= vport
->phba
;
775 struct lpfc_dmabuf
*pcmd
;
778 struct fc_rport
*rport
= ndlp
->rport
;
781 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
782 lp
= (uint32_t *) pcmd
->virt
;
783 npr
= (PRLI
*) ((uint8_t *) lp
+ sizeof (uint32_t));
785 if ((npr
->prliType
== PRLI_FCP_TYPE
) ||
786 (npr
->prliType
== PRLI_NVME_TYPE
)) {
787 if (npr
->initiatorFunc
) {
788 if (npr
->prliType
== PRLI_FCP_TYPE
)
789 ndlp
->nlp_type
|= NLP_FCP_INITIATOR
;
790 if (npr
->prliType
== PRLI_NVME_TYPE
)
791 ndlp
->nlp_type
|= NLP_NVME_INITIATOR
;
793 if (npr
->targetFunc
) {
794 if (npr
->prliType
== PRLI_FCP_TYPE
)
795 ndlp
->nlp_type
|= NLP_FCP_TARGET
;
796 if (npr
->prliType
== PRLI_NVME_TYPE
)
797 ndlp
->nlp_type
|= NLP_NVME_TARGET
;
798 if (npr
->writeXferRdyDis
)
799 ndlp
->nlp_flag
|= NLP_FIRSTBURST
;
802 ndlp
->nlp_fcp_info
|= NLP_FCP_2_DEVICE
;
804 /* If this driver is in nvme target mode, set the ndlp's fc4
805 * type to NVME provided the PRLI response claims NVME FC4
806 * type. Target mode does not issue gft_id so doesn't get
807 * the fc4 type set until now.
809 if (phba
->nvmet_support
&& (npr
->prliType
== PRLI_NVME_TYPE
)) {
810 ndlp
->nlp_fc4_type
|= NLP_FC4_NVME
;
811 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
813 if (npr
->prliType
== PRLI_FCP_TYPE
)
814 ndlp
->nlp_fc4_type
|= NLP_FC4_FCP
;
817 /* We need to update the rport role values */
818 roles
= FC_RPORT_ROLE_UNKNOWN
;
819 if (ndlp
->nlp_type
& NLP_FCP_INITIATOR
)
820 roles
|= FC_RPORT_ROLE_FCP_INITIATOR
;
821 if (ndlp
->nlp_type
& NLP_FCP_TARGET
)
822 roles
|= FC_RPORT_ROLE_FCP_TARGET
;
824 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_RPORT
,
825 "rport rolechg: role:x%x did:x%x flg:x%x",
826 roles
, ndlp
->nlp_DID
, ndlp
->nlp_flag
);
828 if (phba
->cfg_enable_fc4_type
!= LPFC_ENABLE_NVME
)
829 fc_remote_port_rolechg(rport
, roles
);
834 lpfc_disc_set_adisc(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
836 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
838 if (!(ndlp
->nlp_flag
& NLP_RPI_REGISTERED
)) {
839 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
843 if (!(vport
->fc_flag
& FC_PT2PT
)) {
844 /* Check config parameter use-adisc or FCP-2 */
845 if ((vport
->cfg_use_adisc
&& (vport
->fc_flag
& FC_RSCN_MODE
)) ||
846 ((ndlp
->nlp_fcp_info
& NLP_FCP_2_DEVICE
) &&
847 (ndlp
->nlp_type
& NLP_FCP_TARGET
))) {
848 spin_lock_irq(shost
->host_lock
);
849 ndlp
->nlp_flag
|= NLP_NPR_ADISC
;
850 spin_unlock_irq(shost
->host_lock
);
854 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
855 lpfc_unreg_rpi(vport
, ndlp
);
860 * lpfc_release_rpi - Release a RPI by issuing unreg_login mailbox cmd.
861 * @phba : Pointer to lpfc_hba structure.
862 * @vport: Pointer to lpfc_vport structure.
863 * @rpi : rpi to be release.
865 * This function will send a unreg_login mailbox command to the firmware
869 lpfc_release_rpi(struct lpfc_hba
*phba
,
870 struct lpfc_vport
*vport
,
876 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
,
879 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
880 "2796 mailbox memory allocation failed \n");
882 lpfc_unreg_login(phba
, vport
->vpi
, rpi
, pmb
);
883 pmb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
884 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
885 if (rc
== MBX_NOT_FINISHED
)
886 mempool_free(pmb
, phba
->mbox_mem_pool
);
891 lpfc_disc_illegal(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
892 void *arg
, uint32_t evt
)
894 struct lpfc_hba
*phba
;
895 LPFC_MBOXQ_t
*pmb
= (LPFC_MBOXQ_t
*) arg
;
899 /* Release the RPI if reglogin completing */
900 if (!(phba
->pport
->load_flag
& FC_UNLOADING
) &&
901 (evt
== NLP_EVT_CMPL_REG_LOGIN
) &&
902 (!pmb
->u
.mb
.mbxStatus
)) {
903 rpi
= pmb
->u
.mb
.un
.varWords
[0];
904 lpfc_release_rpi(phba
, vport
, rpi
);
906 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
907 "0271 Illegal State Transition: node x%x "
908 "event x%x, state x%x Data: x%x x%x\n",
909 ndlp
->nlp_DID
, evt
, ndlp
->nlp_state
, ndlp
->nlp_rpi
,
911 return ndlp
->nlp_state
;
915 lpfc_cmpl_plogi_illegal(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
916 void *arg
, uint32_t evt
)
918 /* This transition is only legal if we previously
919 * rcv'ed a PLOGI. Since we don't want 2 discovery threads
920 * working on the same NPortID, do nothing for this thread
923 if (!(ndlp
->nlp_flag
& NLP_RCV_PLOGI
)) {
924 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
925 "0272 Illegal State Transition: node x%x "
926 "event x%x, state x%x Data: x%x x%x\n",
927 ndlp
->nlp_DID
, evt
, ndlp
->nlp_state
, ndlp
->nlp_rpi
,
930 return ndlp
->nlp_state
;
933 /* Start of Discovery State Machine routines */
936 lpfc_rcv_plogi_unused_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
937 void *arg
, uint32_t evt
)
939 struct lpfc_iocbq
*cmdiocb
;
941 cmdiocb
= (struct lpfc_iocbq
*) arg
;
943 if (lpfc_rcv_plogi(vport
, ndlp
, cmdiocb
)) {
944 return ndlp
->nlp_state
;
946 return NLP_STE_FREED_NODE
;
950 lpfc_rcv_els_unused_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
951 void *arg
, uint32_t evt
)
953 lpfc_issue_els_logo(vport
, ndlp
, 0);
954 return ndlp
->nlp_state
;
958 lpfc_rcv_logo_unused_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
959 void *arg
, uint32_t evt
)
961 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
962 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
964 spin_lock_irq(shost
->host_lock
);
965 ndlp
->nlp_flag
|= NLP_LOGO_ACC
;
966 spin_unlock_irq(shost
->host_lock
);
967 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
969 return ndlp
->nlp_state
;
973 lpfc_cmpl_logo_unused_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
974 void *arg
, uint32_t evt
)
976 return NLP_STE_FREED_NODE
;
980 lpfc_device_rm_unused_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
981 void *arg
, uint32_t evt
)
983 return NLP_STE_FREED_NODE
;
987 lpfc_device_recov_unused_node(struct lpfc_vport
*vport
,
988 struct lpfc_nodelist
*ndlp
,
989 void *arg
, uint32_t evt
)
991 return ndlp
->nlp_state
;
995 lpfc_rcv_plogi_plogi_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
996 void *arg
, uint32_t evt
)
998 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
999 struct lpfc_hba
*phba
= vport
->phba
;
1000 struct lpfc_iocbq
*cmdiocb
= arg
;
1001 struct lpfc_dmabuf
*pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
1002 uint32_t *lp
= (uint32_t *) pcmd
->virt
;
1003 struct serv_parm
*sp
= (struct serv_parm
*) (lp
+ 1);
1007 memset(&stat
, 0, sizeof (struct ls_rjt
));
1009 /* For a PLOGI, we only accept if our portname is less
1010 * than the remote portname.
1012 phba
->fc_stat
.elsLogiCol
++;
1013 port_cmp
= memcmp(&vport
->fc_portname
, &sp
->portName
,
1014 sizeof(struct lpfc_name
));
1016 if (port_cmp
>= 0) {
1017 /* Reject this request because the remote node will accept
1019 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
1020 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CMD_IN_PROGRESS
;
1021 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
,
1024 if (lpfc_rcv_plogi(vport
, ndlp
, cmdiocb
) &&
1025 (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) &&
1026 (vport
->num_disc_nodes
)) {
1027 spin_lock_irq(shost
->host_lock
);
1028 ndlp
->nlp_flag
&= ~NLP_NPR_2B_DISC
;
1029 spin_unlock_irq(shost
->host_lock
);
1030 /* Check if there are more PLOGIs to be sent */
1031 lpfc_more_plogi(vport
);
1032 if (vport
->num_disc_nodes
== 0) {
1033 spin_lock_irq(shost
->host_lock
);
1034 vport
->fc_flag
&= ~FC_NDISC_ACTIVE
;
1035 spin_unlock_irq(shost
->host_lock
);
1036 lpfc_can_disctmo(vport
);
1037 lpfc_end_rscn(vport
);
1040 } /* If our portname was less */
1042 return ndlp
->nlp_state
;
1046 lpfc_rcv_prli_plogi_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1047 void *arg
, uint32_t evt
)
1049 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1052 memset(&stat
, 0, sizeof (struct ls_rjt
));
1053 stat
.un
.b
.lsRjtRsnCode
= LSRJT_LOGICAL_BSY
;
1054 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_NOTHING_MORE
;
1055 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
1056 return ndlp
->nlp_state
;
1060 lpfc_rcv_logo_plogi_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1061 void *arg
, uint32_t evt
)
1063 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1065 /* software abort outstanding PLOGI */
1066 lpfc_els_abort(vport
->phba
, ndlp
);
1068 lpfc_rcv_logo(vport
, ndlp
, cmdiocb
, ELS_CMD_LOGO
);
1069 return ndlp
->nlp_state
;
1073 lpfc_rcv_els_plogi_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1074 void *arg
, uint32_t evt
)
1076 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1077 struct lpfc_hba
*phba
= vport
->phba
;
1078 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1080 /* software abort outstanding PLOGI */
1081 lpfc_els_abort(phba
, ndlp
);
1083 if (evt
== NLP_EVT_RCV_LOGO
) {
1084 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
1086 lpfc_issue_els_logo(vport
, ndlp
, 0);
1089 /* Put ndlp in npr state set plogi timer for 1 sec */
1090 mod_timer(&ndlp
->nlp_delayfunc
, jiffies
+ msecs_to_jiffies(1000 * 1));
1091 spin_lock_irq(shost
->host_lock
);
1092 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
1093 spin_unlock_irq(shost
->host_lock
);
1094 ndlp
->nlp_last_elscmd
= ELS_CMD_PLOGI
;
1095 ndlp
->nlp_prev_state
= NLP_STE_PLOGI_ISSUE
;
1096 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1098 return ndlp
->nlp_state
;
1102 lpfc_cmpl_plogi_plogi_issue(struct lpfc_vport
*vport
,
1103 struct lpfc_nodelist
*ndlp
,
1107 struct lpfc_hba
*phba
= vport
->phba
;
1108 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1109 struct lpfc_iocbq
*cmdiocb
, *rspiocb
;
1110 struct lpfc_dmabuf
*pcmd
, *prsp
, *mp
;
1114 struct serv_parm
*sp
;
1119 cmdiocb
= (struct lpfc_iocbq
*) arg
;
1120 rspiocb
= cmdiocb
->context_un
.rsp_iocb
;
1122 if (ndlp
->nlp_flag
& NLP_ACC_REGLOGIN
) {
1123 /* Recovery from PLOGI collision logic */
1124 return ndlp
->nlp_state
;
1127 irsp
= &rspiocb
->iocb
;
1129 if (irsp
->ulpStatus
)
1132 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
1134 prsp
= list_get_first(&pcmd
->list
, struct lpfc_dmabuf
, list
);
1138 lp
= (uint32_t *) prsp
->virt
;
1139 sp
= (struct serv_parm
*) ((uint8_t *) lp
+ sizeof (uint32_t));
1141 /* Some switches have FDMI servers returning 0 for WWN */
1142 if ((ndlp
->nlp_DID
!= FDMI_DID
) &&
1143 (wwn_to_u64(sp
->portName
.u
.wwn
) == 0 ||
1144 wwn_to_u64(sp
->nodeName
.u
.wwn
) == 0)) {
1145 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1146 "0142 PLOGI RSP: Invalid WWN.\n");
1149 if (!lpfc_check_sparm(vport
, ndlp
, sp
, CLASS3
, 0))
1151 /* PLOGI chkparm OK */
1152 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
1153 "0121 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
1154 ndlp
->nlp_DID
, ndlp
->nlp_state
,
1155 ndlp
->nlp_flag
, ndlp
->nlp_rpi
);
1156 if (vport
->cfg_fcp_class
== 2 && (sp
->cls2
.classValid
))
1157 ndlp
->nlp_fcp_info
|= CLASS2
;
1159 ndlp
->nlp_fcp_info
|= CLASS3
;
1161 ndlp
->nlp_class_sup
= 0;
1162 if (sp
->cls1
.classValid
)
1163 ndlp
->nlp_class_sup
|= FC_COS_CLASS1
;
1164 if (sp
->cls2
.classValid
)
1165 ndlp
->nlp_class_sup
|= FC_COS_CLASS2
;
1166 if (sp
->cls3
.classValid
)
1167 ndlp
->nlp_class_sup
|= FC_COS_CLASS3
;
1168 if (sp
->cls4
.classValid
)
1169 ndlp
->nlp_class_sup
|= FC_COS_CLASS4
;
1170 ndlp
->nlp_maxframe
=
1171 ((sp
->cmn
.bbRcvSizeMsb
& 0x0F) << 8) | sp
->cmn
.bbRcvSizeLsb
;
1173 if ((vport
->fc_flag
& FC_PT2PT
) &&
1174 (vport
->fc_flag
& FC_PT2PT_PLOGI
)) {
1175 ed_tov
= be32_to_cpu(sp
->cmn
.e_d_tov
);
1176 if (sp
->cmn
.edtovResolution
) {
1177 /* E_D_TOV ticks are in nanoseconds */
1178 ed_tov
= (phba
->fc_edtov
+ 999999) / 1000000;
1181 ndlp
->nlp_flag
&= ~NLP_SUPPRESS_RSP
;
1182 if ((phba
->sli
.sli_flag
& LPFC_SLI_SUPPRESS_RSP
) &&
1183 sp
->cmn
.valid_vendor_ver_level
) {
1184 vid
= be32_to_cpu(sp
->un
.vv
.vid
);
1185 flag
= be32_to_cpu(sp
->un
.vv
.flags
);
1186 if ((vid
== LPFC_VV_EMLX_ID
) &&
1187 (flag
& LPFC_VV_SUPPRESS_RSP
))
1188 ndlp
->nlp_flag
|= NLP_SUPPRESS_RSP
;
1192 * Use the larger EDTOV
1193 * RATOV = 2 * EDTOV for pt-to-pt
1195 if (ed_tov
> phba
->fc_edtov
)
1196 phba
->fc_edtov
= ed_tov
;
1197 phba
->fc_ratov
= (2 * phba
->fc_edtov
) / 1000;
1199 memcpy(&phba
->fc_fabparam
, sp
, sizeof(struct serv_parm
));
1201 /* Issue config_link / reg_vfi to account for updated TOV's */
1202 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
1203 lpfc_issue_reg_vfi(vport
);
1205 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1207 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1208 "0133 PLOGI: no memory "
1210 "Data: x%x x%x x%x x%x\n",
1211 ndlp
->nlp_DID
, ndlp
->nlp_state
,
1212 ndlp
->nlp_flag
, ndlp
->nlp_rpi
);
1216 lpfc_config_link(phba
, mbox
);
1218 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
1219 mbox
->vport
= vport
;
1220 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
1221 if (rc
== MBX_NOT_FINISHED
) {
1222 mempool_free(mbox
, phba
->mbox_mem_pool
);
1228 lpfc_unreg_rpi(vport
, ndlp
);
1230 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1232 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1233 "0018 PLOGI: no memory for reg_login "
1234 "Data: x%x x%x x%x x%x\n",
1235 ndlp
->nlp_DID
, ndlp
->nlp_state
,
1236 ndlp
->nlp_flag
, ndlp
->nlp_rpi
);
1240 if (lpfc_reg_rpi(phba
, vport
->vpi
, irsp
->un
.elsreq64
.remoteID
,
1241 (uint8_t *) sp
, mbox
, ndlp
->nlp_rpi
) == 0) {
1242 switch (ndlp
->nlp_DID
) {
1243 case NameServer_DID
:
1244 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_ns_reg_login
;
1247 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_fdmi_reg_login
;
1250 ndlp
->nlp_flag
|= NLP_REG_LOGIN_SEND
;
1251 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_reg_login
;
1253 mbox
->context2
= lpfc_nlp_get(ndlp
);
1254 mbox
->vport
= vport
;
1255 if (lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
)
1256 != MBX_NOT_FINISHED
) {
1257 lpfc_nlp_set_state(vport
, ndlp
,
1258 NLP_STE_REG_LOGIN_ISSUE
);
1259 return ndlp
->nlp_state
;
1261 if (ndlp
->nlp_flag
& NLP_REG_LOGIN_SEND
)
1262 ndlp
->nlp_flag
&= ~NLP_REG_LOGIN_SEND
;
1263 /* decrement node reference count to the failed mbox
1267 mp
= (struct lpfc_dmabuf
*) mbox
->context1
;
1268 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
1270 mempool_free(mbox
, phba
->mbox_mem_pool
);
1272 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1273 "0134 PLOGI: cannot issue reg_login "
1274 "Data: x%x x%x x%x x%x\n",
1275 ndlp
->nlp_DID
, ndlp
->nlp_state
,
1276 ndlp
->nlp_flag
, ndlp
->nlp_rpi
);
1278 mempool_free(mbox
, phba
->mbox_mem_pool
);
1280 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1281 "0135 PLOGI: cannot format reg_login "
1282 "Data: x%x x%x x%x x%x\n",
1283 ndlp
->nlp_DID
, ndlp
->nlp_state
,
1284 ndlp
->nlp_flag
, ndlp
->nlp_rpi
);
1289 if (ndlp
->nlp_DID
== NameServer_DID
) {
1290 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
1291 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1292 "0261 Cannot Register NameServer login\n");
1296 ** In case the node reference counter does not go to zero, ensure that
1297 ** the stale state for the node is not processed.
1300 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
1301 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1302 spin_lock_irq(shost
->host_lock
);
1303 ndlp
->nlp_flag
|= NLP_DEFER_RM
;
1304 spin_unlock_irq(shost
->host_lock
);
1305 return NLP_STE_FREED_NODE
;
1309 lpfc_cmpl_logo_plogi_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1310 void *arg
, uint32_t evt
)
1312 return ndlp
->nlp_state
;
1316 lpfc_cmpl_reglogin_plogi_issue(struct lpfc_vport
*vport
,
1317 struct lpfc_nodelist
*ndlp
, void *arg
, uint32_t evt
)
1319 struct lpfc_hba
*phba
;
1320 LPFC_MBOXQ_t
*pmb
= (LPFC_MBOXQ_t
*) arg
;
1321 MAILBOX_t
*mb
= &pmb
->u
.mb
;
1325 /* Release the RPI */
1326 if (!(phba
->pport
->load_flag
& FC_UNLOADING
) &&
1328 rpi
= pmb
->u
.mb
.un
.varWords
[0];
1329 lpfc_release_rpi(phba
, vport
, rpi
);
1331 return ndlp
->nlp_state
;
1335 lpfc_device_rm_plogi_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1336 void *arg
, uint32_t evt
)
1338 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1340 if (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) {
1341 spin_lock_irq(shost
->host_lock
);
1342 ndlp
->nlp_flag
|= NLP_NODEV_REMOVE
;
1343 spin_unlock_irq(shost
->host_lock
);
1344 return ndlp
->nlp_state
;
1346 /* software abort outstanding PLOGI */
1347 lpfc_els_abort(vport
->phba
, ndlp
);
1349 lpfc_drop_node(vport
, ndlp
);
1350 return NLP_STE_FREED_NODE
;
1355 lpfc_device_recov_plogi_issue(struct lpfc_vport
*vport
,
1356 struct lpfc_nodelist
*ndlp
,
1360 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1361 struct lpfc_hba
*phba
= vport
->phba
;
1363 /* Don't do anything that will mess up processing of the
1366 if (vport
->fc_flag
& FC_RSCN_DEFERRED
)
1367 return ndlp
->nlp_state
;
1369 /* software abort outstanding PLOGI */
1370 lpfc_els_abort(phba
, ndlp
);
1372 ndlp
->nlp_prev_state
= NLP_STE_PLOGI_ISSUE
;
1373 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1374 spin_lock_irq(shost
->host_lock
);
1375 ndlp
->nlp_flag
&= ~(NLP_NODEV_REMOVE
| NLP_NPR_2B_DISC
);
1376 spin_unlock_irq(shost
->host_lock
);
1378 return ndlp
->nlp_state
;
1382 lpfc_rcv_plogi_adisc_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1383 void *arg
, uint32_t evt
)
1385 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1386 struct lpfc_hba
*phba
= vport
->phba
;
1387 struct lpfc_iocbq
*cmdiocb
;
1389 /* software abort outstanding ADISC */
1390 lpfc_els_abort(phba
, ndlp
);
1392 cmdiocb
= (struct lpfc_iocbq
*) arg
;
1394 if (lpfc_rcv_plogi(vport
, ndlp
, cmdiocb
)) {
1395 if (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) {
1396 spin_lock_irq(shost
->host_lock
);
1397 ndlp
->nlp_flag
&= ~NLP_NPR_2B_DISC
;
1398 spin_unlock_irq(shost
->host_lock
);
1399 if (vport
->num_disc_nodes
)
1400 lpfc_more_adisc(vport
);
1402 return ndlp
->nlp_state
;
1404 ndlp
->nlp_prev_state
= NLP_STE_ADISC_ISSUE
;
1405 lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0);
1406 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
1408 return ndlp
->nlp_state
;
1412 lpfc_rcv_prli_adisc_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1413 void *arg
, uint32_t evt
)
1415 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1417 if (lpfc_rcv_prli_support_check(vport
, ndlp
, cmdiocb
))
1418 lpfc_els_rsp_prli_acc(vport
, cmdiocb
, ndlp
);
1419 return ndlp
->nlp_state
;
1423 lpfc_rcv_logo_adisc_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1424 void *arg
, uint32_t evt
)
1426 struct lpfc_hba
*phba
= vport
->phba
;
1427 struct lpfc_iocbq
*cmdiocb
;
1429 cmdiocb
= (struct lpfc_iocbq
*) arg
;
1431 /* software abort outstanding ADISC */
1432 lpfc_els_abort(phba
, ndlp
);
1434 lpfc_rcv_logo(vport
, ndlp
, cmdiocb
, ELS_CMD_LOGO
);
1435 return ndlp
->nlp_state
;
1439 lpfc_rcv_padisc_adisc_issue(struct lpfc_vport
*vport
,
1440 struct lpfc_nodelist
*ndlp
,
1441 void *arg
, uint32_t evt
)
1443 struct lpfc_iocbq
*cmdiocb
;
1445 cmdiocb
= (struct lpfc_iocbq
*) arg
;
1447 lpfc_rcv_padisc(vport
, ndlp
, cmdiocb
);
1448 return ndlp
->nlp_state
;
1452 lpfc_rcv_prlo_adisc_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1453 void *arg
, uint32_t evt
)
1455 struct lpfc_iocbq
*cmdiocb
;
1457 cmdiocb
= (struct lpfc_iocbq
*) arg
;
1459 /* Treat like rcv logo */
1460 lpfc_rcv_logo(vport
, ndlp
, cmdiocb
, ELS_CMD_PRLO
);
1461 return ndlp
->nlp_state
;
1465 lpfc_cmpl_adisc_adisc_issue(struct lpfc_vport
*vport
,
1466 struct lpfc_nodelist
*ndlp
,
1467 void *arg
, uint32_t evt
)
1469 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1470 struct lpfc_hba
*phba
= vport
->phba
;
1471 struct lpfc_iocbq
*cmdiocb
, *rspiocb
;
1476 cmdiocb
= (struct lpfc_iocbq
*) arg
;
1477 rspiocb
= cmdiocb
->context_un
.rsp_iocb
;
1479 ap
= (ADISC
*)lpfc_check_elscmpl_iocb(phba
, cmdiocb
, rspiocb
);
1480 irsp
= &rspiocb
->iocb
;
1482 if ((irsp
->ulpStatus
) ||
1483 (!lpfc_check_adisc(vport
, ndlp
, &ap
->nodeName
, &ap
->portName
))) {
1485 mod_timer(&ndlp
->nlp_delayfunc
,
1486 jiffies
+ msecs_to_jiffies(1000));
1487 spin_lock_irq(shost
->host_lock
);
1488 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
1489 spin_unlock_irq(shost
->host_lock
);
1490 ndlp
->nlp_last_elscmd
= ELS_CMD_PLOGI
;
1492 memset(&ndlp
->nlp_nodename
, 0, sizeof(struct lpfc_name
));
1493 memset(&ndlp
->nlp_portname
, 0, sizeof(struct lpfc_name
));
1495 ndlp
->nlp_prev_state
= NLP_STE_ADISC_ISSUE
;
1496 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1497 lpfc_unreg_rpi(vport
, ndlp
);
1498 return ndlp
->nlp_state
;
1501 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
1502 rc
= lpfc_sli4_resume_rpi(ndlp
, NULL
, NULL
);
1504 /* Stay in state and retry. */
1505 ndlp
->nlp_prev_state
= NLP_STE_ADISC_ISSUE
;
1506 return ndlp
->nlp_state
;
1510 if (ndlp
->nlp_type
& NLP_FCP_TARGET
) {
1511 ndlp
->nlp_prev_state
= NLP_STE_ADISC_ISSUE
;
1512 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_MAPPED_NODE
);
1514 ndlp
->nlp_prev_state
= NLP_STE_ADISC_ISSUE
;
1515 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
1518 return ndlp
->nlp_state
;
1522 lpfc_device_rm_adisc_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1523 void *arg
, uint32_t evt
)
1525 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1527 if (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) {
1528 spin_lock_irq(shost
->host_lock
);
1529 ndlp
->nlp_flag
|= NLP_NODEV_REMOVE
;
1530 spin_unlock_irq(shost
->host_lock
);
1531 return ndlp
->nlp_state
;
1533 /* software abort outstanding ADISC */
1534 lpfc_els_abort(vport
->phba
, ndlp
);
1536 lpfc_drop_node(vport
, ndlp
);
1537 return NLP_STE_FREED_NODE
;
1542 lpfc_device_recov_adisc_issue(struct lpfc_vport
*vport
,
1543 struct lpfc_nodelist
*ndlp
,
1547 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1548 struct lpfc_hba
*phba
= vport
->phba
;
1550 /* Don't do anything that will mess up processing of the
1553 if (vport
->fc_flag
& FC_RSCN_DEFERRED
)
1554 return ndlp
->nlp_state
;
1556 /* software abort outstanding ADISC */
1557 lpfc_els_abort(phba
, ndlp
);
1559 ndlp
->nlp_prev_state
= NLP_STE_ADISC_ISSUE
;
1560 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1561 spin_lock_irq(shost
->host_lock
);
1562 ndlp
->nlp_flag
&= ~(NLP_NODEV_REMOVE
| NLP_NPR_2B_DISC
);
1563 spin_unlock_irq(shost
->host_lock
);
1564 lpfc_disc_set_adisc(vport
, ndlp
);
1565 return ndlp
->nlp_state
;
1569 lpfc_rcv_plogi_reglogin_issue(struct lpfc_vport
*vport
,
1570 struct lpfc_nodelist
*ndlp
,
1574 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1576 lpfc_rcv_plogi(vport
, ndlp
, cmdiocb
);
1577 return ndlp
->nlp_state
;
1581 lpfc_rcv_prli_reglogin_issue(struct lpfc_vport
*vport
,
1582 struct lpfc_nodelist
*ndlp
,
1586 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1589 if (!lpfc_rcv_prli_support_check(vport
, ndlp
, cmdiocb
)) {
1590 return ndlp
->nlp_state
;
1592 if (vport
->phba
->nvmet_support
) {
1593 /* NVME Target mode. Handle and respond to the PRLI and
1594 * transition to UNMAPPED provided the RPI has completed
1597 if (ndlp
->nlp_flag
& NLP_RPI_REGISTERED
) {
1598 lpfc_rcv_prli(vport
, ndlp
, cmdiocb
);
1599 lpfc_els_rsp_prli_acc(vport
, cmdiocb
, ndlp
);
1601 /* RPI registration has not completed. Reject the PRLI
1602 * to prevent an illegal state transition when the
1603 * rpi registration does complete.
1605 memset(&stat
, 0, sizeof(struct ls_rjt
));
1606 stat
.un
.b
.lsRjtRsnCode
= LSRJT_LOGICAL_BSY
;
1607 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_NOTHING_MORE
;
1608 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
,
1610 return ndlp
->nlp_state
;
1613 /* Initiator mode. */
1614 lpfc_els_rsp_prli_acc(vport
, cmdiocb
, ndlp
);
1616 return ndlp
->nlp_state
;
1620 lpfc_rcv_logo_reglogin_issue(struct lpfc_vport
*vport
,
1621 struct lpfc_nodelist
*ndlp
,
1625 struct lpfc_hba
*phba
= vport
->phba
;
1626 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1628 LPFC_MBOXQ_t
*nextmb
;
1629 struct lpfc_dmabuf
*mp
;
1631 cmdiocb
= (struct lpfc_iocbq
*) arg
;
1633 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
1634 if ((mb
= phba
->sli
.mbox_active
)) {
1635 if ((mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) &&
1636 (ndlp
== (struct lpfc_nodelist
*) mb
->context2
)) {
1637 ndlp
->nlp_flag
&= ~NLP_REG_LOGIN_SEND
;
1639 mb
->context2
= NULL
;
1640 mb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
1644 spin_lock_irq(&phba
->hbalock
);
1645 list_for_each_entry_safe(mb
, nextmb
, &phba
->sli
.mboxq
, list
) {
1646 if ((mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) &&
1647 (ndlp
== (struct lpfc_nodelist
*) mb
->context2
)) {
1648 mp
= (struct lpfc_dmabuf
*) (mb
->context1
);
1650 __lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
1653 ndlp
->nlp_flag
&= ~NLP_REG_LOGIN_SEND
;
1655 list_del(&mb
->list
);
1656 phba
->sli
.mboxq_cnt
--;
1657 mempool_free(mb
, phba
->mbox_mem_pool
);
1660 spin_unlock_irq(&phba
->hbalock
);
1662 lpfc_rcv_logo(vport
, ndlp
, cmdiocb
, ELS_CMD_LOGO
);
1663 return ndlp
->nlp_state
;
1667 lpfc_rcv_padisc_reglogin_issue(struct lpfc_vport
*vport
,
1668 struct lpfc_nodelist
*ndlp
,
1672 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1674 lpfc_rcv_padisc(vport
, ndlp
, cmdiocb
);
1675 return ndlp
->nlp_state
;
1679 lpfc_rcv_prlo_reglogin_issue(struct lpfc_vport
*vport
,
1680 struct lpfc_nodelist
*ndlp
,
1684 struct lpfc_iocbq
*cmdiocb
;
1686 cmdiocb
= (struct lpfc_iocbq
*) arg
;
1687 lpfc_els_rsp_acc(vport
, ELS_CMD_PRLO
, cmdiocb
, ndlp
, NULL
);
1688 return ndlp
->nlp_state
;
1692 lpfc_cmpl_reglogin_reglogin_issue(struct lpfc_vport
*vport
,
1693 struct lpfc_nodelist
*ndlp
,
1697 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1698 struct lpfc_hba
*phba
= vport
->phba
;
1699 LPFC_MBOXQ_t
*pmb
= (LPFC_MBOXQ_t
*) arg
;
1700 MAILBOX_t
*mb
= &pmb
->u
.mb
;
1701 uint32_t did
= mb
->un
.varWords
[1];
1704 if (mb
->mbxStatus
) {
1705 /* RegLogin failed */
1706 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
1707 "0246 RegLogin failed Data: x%x x%x x%x x%x "
1709 did
, mb
->mbxStatus
, vport
->port_state
,
1710 mb
->un
.varRegLogin
.vpi
,
1711 mb
->un
.varRegLogin
.rpi
);
1713 * If RegLogin failed due to lack of HBA resources do not
1716 if (mb
->mbxStatus
== MBXERR_RPI_FULL
) {
1717 ndlp
->nlp_prev_state
= NLP_STE_REG_LOGIN_ISSUE
;
1718 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1719 return ndlp
->nlp_state
;
1722 /* Put ndlp in npr state set plogi timer for 1 sec */
1723 mod_timer(&ndlp
->nlp_delayfunc
,
1724 jiffies
+ msecs_to_jiffies(1000 * 1));
1725 spin_lock_irq(shost
->host_lock
);
1726 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
1727 spin_unlock_irq(shost
->host_lock
);
1728 ndlp
->nlp_last_elscmd
= ELS_CMD_PLOGI
;
1730 lpfc_issue_els_logo(vport
, ndlp
, 0);
1731 ndlp
->nlp_prev_state
= NLP_STE_REG_LOGIN_ISSUE
;
1732 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1733 return ndlp
->nlp_state
;
1736 /* SLI4 ports have preallocated logical rpis. */
1737 if (phba
->sli_rev
< LPFC_SLI_REV4
)
1738 ndlp
->nlp_rpi
= mb
->un
.varWords
[0];
1740 ndlp
->nlp_flag
|= NLP_RPI_REGISTERED
;
1742 /* Only if we are not a fabric nport do we issue PRLI */
1743 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
1744 "3066 RegLogin Complete on x%x x%x x%x\n",
1745 did
, ndlp
->nlp_type
, ndlp
->nlp_fc4_type
);
1746 if (!(ndlp
->nlp_type
& NLP_FABRIC
) &&
1747 (phba
->nvmet_support
== 0)) {
1748 /* The driver supports FCP and NVME concurrently. If the
1749 * ndlp's nlp_fc4_type is still zero, the driver doesn't
1750 * know what PRLI to send yet. Figure that out now and
1751 * call PRLI depending on the outcome.
1753 if (vport
->fc_flag
& FC_PT2PT
) {
1754 /* If we are pt2pt, there is no Fabric to determine
1755 * the FC4 type of the remote nport. So if NVME
1756 * is configured try it.
1758 ndlp
->nlp_fc4_type
|= NLP_FC4_FCP
;
1759 if ((phba
->cfg_enable_fc4_type
== LPFC_ENABLE_BOTH
) ||
1760 (phba
->cfg_enable_fc4_type
== LPFC_ENABLE_NVME
)) {
1761 ndlp
->nlp_fc4_type
|= NLP_FC4_NVME
;
1762 /* We need to update the localport also */
1763 lpfc_nvme_update_localport(vport
);
1766 } else if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) {
1767 ndlp
->nlp_fc4_type
|= NLP_FC4_FCP
;
1769 } else if (ndlp
->nlp_fc4_type
== 0) {
1770 rc
= lpfc_ns_cmd(vport
, SLI_CTNS_GFT_ID
,
1772 return ndlp
->nlp_state
;
1775 ndlp
->nlp_prev_state
= NLP_STE_REG_LOGIN_ISSUE
;
1776 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PRLI_ISSUE
);
1777 lpfc_issue_els_prli(vport
, ndlp
, 0);
1779 if ((vport
->fc_flag
& FC_PT2PT
) && phba
->nvmet_support
)
1780 phba
->targetport
->port_id
= vport
->fc_myDID
;
1782 /* Only Fabric ports should transition. NVME target
1783 * must complete PRLI.
1785 if (ndlp
->nlp_type
& NLP_FABRIC
) {
1786 ndlp
->nlp_prev_state
= NLP_STE_REG_LOGIN_ISSUE
;
1787 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
1790 return ndlp
->nlp_state
;
1794 lpfc_device_rm_reglogin_issue(struct lpfc_vport
*vport
,
1795 struct lpfc_nodelist
*ndlp
,
1799 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1801 if (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) {
1802 spin_lock_irq(shost
->host_lock
);
1803 ndlp
->nlp_flag
|= NLP_NODEV_REMOVE
;
1804 spin_unlock_irq(shost
->host_lock
);
1805 return ndlp
->nlp_state
;
1807 lpfc_drop_node(vport
, ndlp
);
1808 return NLP_STE_FREED_NODE
;
1813 lpfc_device_recov_reglogin_issue(struct lpfc_vport
*vport
,
1814 struct lpfc_nodelist
*ndlp
,
1818 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1820 /* Don't do anything that will mess up processing of the
1823 if (vport
->fc_flag
& FC_RSCN_DEFERRED
)
1824 return ndlp
->nlp_state
;
1826 ndlp
->nlp_prev_state
= NLP_STE_REG_LOGIN_ISSUE
;
1827 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1828 spin_lock_irq(shost
->host_lock
);
1830 /* If we are a target we won't immediately transition into PRLI,
1831 * so if REG_LOGIN already completed we don't need to ignore it.
1833 if (!(ndlp
->nlp_flag
& NLP_RPI_REGISTERED
) ||
1834 !vport
->phba
->nvmet_support
)
1835 ndlp
->nlp_flag
|= NLP_IGNR_REG_CMPL
;
1837 ndlp
->nlp_flag
&= ~(NLP_NODEV_REMOVE
| NLP_NPR_2B_DISC
);
1838 spin_unlock_irq(shost
->host_lock
);
1839 lpfc_disc_set_adisc(vport
, ndlp
);
1840 return ndlp
->nlp_state
;
1844 lpfc_rcv_plogi_prli_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1845 void *arg
, uint32_t evt
)
1847 struct lpfc_iocbq
*cmdiocb
;
1849 cmdiocb
= (struct lpfc_iocbq
*) arg
;
1851 lpfc_rcv_plogi(vport
, ndlp
, cmdiocb
);
1852 return ndlp
->nlp_state
;
1856 lpfc_rcv_prli_prli_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1857 void *arg
, uint32_t evt
)
1859 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1861 if (!lpfc_rcv_prli_support_check(vport
, ndlp
, cmdiocb
))
1862 return ndlp
->nlp_state
;
1863 lpfc_els_rsp_prli_acc(vport
, cmdiocb
, ndlp
);
1864 return ndlp
->nlp_state
;
1868 lpfc_rcv_logo_prli_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1869 void *arg
, uint32_t evt
)
1871 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1873 /* Software abort outstanding PRLI before sending acc */
1874 lpfc_els_abort(vport
->phba
, ndlp
);
1876 lpfc_rcv_logo(vport
, ndlp
, cmdiocb
, ELS_CMD_LOGO
);
1877 return ndlp
->nlp_state
;
1881 lpfc_rcv_padisc_prli_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1882 void *arg
, uint32_t evt
)
1884 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1886 lpfc_rcv_padisc(vport
, ndlp
, cmdiocb
);
1887 return ndlp
->nlp_state
;
1890 /* This routine is envoked when we rcv a PRLO request from a nport
1891 * we are logged into. We should send back a PRLO rsp setting the
1893 * NEXT STATE = PRLI_ISSUE
1896 lpfc_rcv_prlo_prli_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1897 void *arg
, uint32_t evt
)
1899 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1901 lpfc_els_rsp_acc(vport
, ELS_CMD_PRLO
, cmdiocb
, ndlp
, NULL
);
1902 return ndlp
->nlp_state
;
1906 lpfc_cmpl_prli_prli_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1907 void *arg
, uint32_t evt
)
1909 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1910 struct lpfc_iocbq
*cmdiocb
, *rspiocb
;
1911 struct lpfc_hba
*phba
= vport
->phba
;
1914 struct lpfc_nvme_prli
*nvpr
;
1917 cmdiocb
= (struct lpfc_iocbq
*) arg
;
1918 rspiocb
= cmdiocb
->context_un
.rsp_iocb
;
1920 /* A solicited PRLI is either FCP or NVME. The PRLI cmd/rsp
1921 * format is different so NULL the two PRLI types so that the
1922 * driver correctly gets the correct context.
1926 temp_ptr
= lpfc_check_elscmpl_iocb(phba
, cmdiocb
, rspiocb
);
1927 if (cmdiocb
->iocb_flag
& LPFC_PRLI_FCP_REQ
)
1928 npr
= (PRLI
*) temp_ptr
;
1929 else if (cmdiocb
->iocb_flag
& LPFC_PRLI_NVME_REQ
)
1930 nvpr
= (struct lpfc_nvme_prli
*) temp_ptr
;
1932 irsp
= &rspiocb
->iocb
;
1933 if (irsp
->ulpStatus
) {
1934 if ((vport
->port_type
== LPFC_NPIV_PORT
) &&
1935 vport
->cfg_restrict_login
) {
1939 /* When the rport rejected the FCP PRLI as unsupported.
1940 * This should only happen in Pt2Pt so an NVME PRLI
1941 * should be outstanding still.
1943 if (npr
&& ndlp
->nlp_flag
& NLP_FCP_PRLI_RJT
) {
1944 ndlp
->nlp_fc4_type
&= ~NLP_FC4_FCP
;
1948 /* The LS Req had some error. Don't let this be a
1951 if ((ndlp
->fc4_prli_sent
== 1) &&
1952 (ndlp
->nlp_state
== NLP_STE_PRLI_ISSUE
) &&
1953 (ndlp
->nlp_type
& (NLP_FCP_TARGET
| NLP_FCP_INITIATOR
)))
1954 /* The FCP PRLI completed successfully but
1955 * the NVME PRLI failed. Since they are sent in
1956 * succession, allow the FCP to complete.
1960 ndlp
->nlp_prev_state
= NLP_STE_PRLI_ISSUE
;
1961 ndlp
->nlp_type
|= NLP_FCP_INITIATOR
;
1962 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
1963 return ndlp
->nlp_state
;
1966 if (npr
&& (npr
->acceptRspCode
== PRLI_REQ_EXECUTED
) &&
1967 (npr
->prliType
== PRLI_FCP_TYPE
)) {
1968 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NVME_DISC
,
1969 "6028 FCP NPR PRLI Cmpl Init %d Target %d\n",
1972 if (npr
->initiatorFunc
)
1973 ndlp
->nlp_type
|= NLP_FCP_INITIATOR
;
1974 if (npr
->targetFunc
) {
1975 ndlp
->nlp_type
|= NLP_FCP_TARGET
;
1976 if (npr
->writeXferRdyDis
)
1977 ndlp
->nlp_flag
|= NLP_FIRSTBURST
;
1980 ndlp
->nlp_fcp_info
|= NLP_FCP_2_DEVICE
;
1983 (bf_get_be32(prli_acc_rsp_code
, nvpr
) ==
1984 PRLI_REQ_EXECUTED
) &&
1985 (bf_get_be32(prli_type_code
, nvpr
) ==
1988 /* Complete setting up the remote ndlp personality. */
1989 if (bf_get_be32(prli_init
, nvpr
))
1990 ndlp
->nlp_type
|= NLP_NVME_INITIATOR
;
1992 /* Target driver cannot solicit NVME FB. */
1993 if (bf_get_be32(prli_tgt
, nvpr
)) {
1994 /* Complete the nvme target roles. The transport
1995 * needs to know if the rport is capable of
1996 * discovery in addition to its role.
1998 ndlp
->nlp_type
|= NLP_NVME_TARGET
;
1999 if (bf_get_be32(prli_disc
, nvpr
))
2000 ndlp
->nlp_type
|= NLP_NVME_DISCOVERY
;
2001 if ((bf_get_be32(prli_fba
, nvpr
) == 1) &&
2002 (bf_get_be32(prli_fb_sz
, nvpr
) > 0) &&
2003 (phba
->cfg_nvme_enable_fb
) &&
2004 (!phba
->nvmet_support
)) {
2005 /* Both sides support FB. The target's first
2006 * burst size is a 512 byte encoded value.
2008 ndlp
->nlp_flag
|= NLP_FIRSTBURST
;
2009 ndlp
->nvme_fb_size
= bf_get_be32(prli_fb_sz
,
2014 if (bf_get_be32(prli_recov
, nvpr
))
2015 ndlp
->nlp_fcp_info
|= NLP_FCP_2_DEVICE
;
2017 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NVME_DISC
,
2018 "6029 NVME PRLI Cmpl w1 x%08x "
2019 "w4 x%08x w5 x%08x flag x%x, "
2020 "fcp_info x%x nlp_type x%x\n",
2021 be32_to_cpu(nvpr
->word1
),
2022 be32_to_cpu(nvpr
->word4
),
2023 be32_to_cpu(nvpr
->word5
),
2024 ndlp
->nlp_flag
, ndlp
->nlp_fcp_info
,
2027 if (!(ndlp
->nlp_type
& NLP_FCP_TARGET
) &&
2028 (vport
->port_type
== LPFC_NPIV_PORT
) &&
2029 vport
->cfg_restrict_login
) {
2031 spin_lock_irq(shost
->host_lock
);
2032 ndlp
->nlp_flag
|= NLP_TARGET_REMOVE
;
2033 spin_unlock_irq(shost
->host_lock
);
2034 lpfc_issue_els_logo(vport
, ndlp
, 0);
2036 ndlp
->nlp_prev_state
= NLP_STE_PRLI_ISSUE
;
2037 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
2038 return ndlp
->nlp_state
;
2042 /* The ndlp state cannot move to MAPPED or UNMAPPED before all PRLIs
2045 if (ndlp
->fc4_prli_sent
== 0) {
2046 ndlp
->nlp_prev_state
= NLP_STE_PRLI_ISSUE
;
2047 if (ndlp
->nlp_type
& (NLP_FCP_TARGET
| NLP_NVME_TARGET
))
2048 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_MAPPED_NODE
);
2049 else if (ndlp
->nlp_type
&
2050 (NLP_FCP_INITIATOR
| NLP_NVME_INITIATOR
))
2051 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
2053 lpfc_printf_vlog(vport
,
2055 "3067 PRLI's still outstanding "
2056 "on x%06x - count %d, Pend Node Mode "
2058 ndlp
->nlp_DID
, ndlp
->fc4_prli_sent
);
2060 return ndlp
->nlp_state
;
2063 /*! lpfc_device_rm_prli_issue
2074 * This routine is envoked when we a request to remove a nport we are in the
2075 * process of PRLIing. We should software abort outstanding prli, unreg
2076 * login, send a logout. We will change node state to UNUSED_NODE, put it
2077 * on plogi list so it can be freed when LOGO completes.
2082 lpfc_device_rm_prli_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2083 void *arg
, uint32_t evt
)
2085 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2087 if (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) {
2088 spin_lock_irq(shost
->host_lock
);
2089 ndlp
->nlp_flag
|= NLP_NODEV_REMOVE
;
2090 spin_unlock_irq(shost
->host_lock
);
2091 return ndlp
->nlp_state
;
2093 /* software abort outstanding PLOGI */
2094 lpfc_els_abort(vport
->phba
, ndlp
);
2096 lpfc_drop_node(vport
, ndlp
);
2097 return NLP_STE_FREED_NODE
;
2102 /*! lpfc_device_recov_prli_issue
2113 * The routine is envoked when the state of a device is unknown, like
2114 * during a link down. We should remove the nodelist entry from the
2115 * unmapped list, issue a UNREG_LOGIN, do a software abort of the
2116 * outstanding PRLI command, then free the node entry.
2119 lpfc_device_recov_prli_issue(struct lpfc_vport
*vport
,
2120 struct lpfc_nodelist
*ndlp
,
2124 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2125 struct lpfc_hba
*phba
= vport
->phba
;
2127 /* Don't do anything that will mess up processing of the
2130 if (vport
->fc_flag
& FC_RSCN_DEFERRED
)
2131 return ndlp
->nlp_state
;
2133 /* software abort outstanding PRLI */
2134 lpfc_els_abort(phba
, ndlp
);
2136 ndlp
->nlp_prev_state
= NLP_STE_PRLI_ISSUE
;
2137 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
2138 spin_lock_irq(shost
->host_lock
);
2139 ndlp
->nlp_flag
&= ~(NLP_NODEV_REMOVE
| NLP_NPR_2B_DISC
);
2140 spin_unlock_irq(shost
->host_lock
);
2141 lpfc_disc_set_adisc(vport
, ndlp
);
2142 return ndlp
->nlp_state
;
2146 lpfc_rcv_plogi_logo_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2147 void *arg
, uint32_t evt
)
2149 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*)arg
;
2152 memset(&stat
, 0, sizeof(struct ls_rjt
));
2153 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
2154 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_NOTHING_MORE
;
2155 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
2156 return ndlp
->nlp_state
;
2160 lpfc_rcv_prli_logo_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2161 void *arg
, uint32_t evt
)
2163 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*)arg
;
2166 memset(&stat
, 0, sizeof(struct ls_rjt
));
2167 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
2168 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_NOTHING_MORE
;
2169 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
2170 return ndlp
->nlp_state
;
2174 lpfc_rcv_logo_logo_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2175 void *arg
, uint32_t evt
)
2177 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2178 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*)arg
;
2180 spin_lock_irq(shost
->host_lock
);
2181 ndlp
->nlp_flag
|= NLP_LOGO_ACC
;
2182 spin_unlock_irq(shost
->host_lock
);
2183 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
2184 return ndlp
->nlp_state
;
2188 lpfc_rcv_padisc_logo_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2189 void *arg
, uint32_t evt
)
2191 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*)arg
;
2194 memset(&stat
, 0, sizeof(struct ls_rjt
));
2195 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
2196 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_NOTHING_MORE
;
2197 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
2198 return ndlp
->nlp_state
;
2202 lpfc_rcv_prlo_logo_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2203 void *arg
, uint32_t evt
)
2205 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*)arg
;
2208 memset(&stat
, 0, sizeof(struct ls_rjt
));
2209 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
2210 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_NOTHING_MORE
;
2211 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
2212 return ndlp
->nlp_state
;
2216 lpfc_cmpl_logo_logo_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2217 void *arg
, uint32_t evt
)
2219 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2221 ndlp
->nlp_prev_state
= NLP_STE_LOGO_ISSUE
;
2222 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
2223 spin_lock_irq(shost
->host_lock
);
2224 ndlp
->nlp_flag
&= ~(NLP_NODEV_REMOVE
| NLP_NPR_2B_DISC
);
2225 spin_unlock_irq(shost
->host_lock
);
2226 lpfc_disc_set_adisc(vport
, ndlp
);
2227 return ndlp
->nlp_state
;
2231 lpfc_device_rm_logo_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2232 void *arg
, uint32_t evt
)
2235 * DevLoss has timed out and is calling for Device Remove.
2236 * In this case, abort the LOGO and cleanup the ndlp
2239 lpfc_unreg_rpi(vport
, ndlp
);
2240 /* software abort outstanding PLOGI */
2241 lpfc_els_abort(vport
->phba
, ndlp
);
2242 lpfc_drop_node(vport
, ndlp
);
2243 return NLP_STE_FREED_NODE
;
2247 lpfc_device_recov_logo_issue(struct lpfc_vport
*vport
,
2248 struct lpfc_nodelist
*ndlp
,
2249 void *arg
, uint32_t evt
)
2252 * Device Recovery events have no meaning for a node with a LOGO
2253 * outstanding. The LOGO has to complete first and handle the
2254 * node from that point.
2256 return ndlp
->nlp_state
;
2260 lpfc_rcv_plogi_unmap_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2261 void *arg
, uint32_t evt
)
2263 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2265 lpfc_rcv_plogi(vport
, ndlp
, cmdiocb
);
2266 return ndlp
->nlp_state
;
2270 lpfc_rcv_prli_unmap_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2271 void *arg
, uint32_t evt
)
2273 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2275 if (!lpfc_rcv_prli_support_check(vport
, ndlp
, cmdiocb
))
2276 return ndlp
->nlp_state
;
2278 lpfc_rcv_prli(vport
, ndlp
, cmdiocb
);
2279 lpfc_els_rsp_prli_acc(vport
, cmdiocb
, ndlp
);
2280 return ndlp
->nlp_state
;
2284 lpfc_rcv_logo_unmap_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2285 void *arg
, uint32_t evt
)
2287 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2289 lpfc_rcv_logo(vport
, ndlp
, cmdiocb
, ELS_CMD_LOGO
);
2290 return ndlp
->nlp_state
;
2294 lpfc_rcv_padisc_unmap_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2295 void *arg
, uint32_t evt
)
2297 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2299 lpfc_rcv_padisc(vport
, ndlp
, cmdiocb
);
2300 return ndlp
->nlp_state
;
2304 lpfc_rcv_prlo_unmap_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2305 void *arg
, uint32_t evt
)
2307 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2309 lpfc_els_rsp_acc(vport
, ELS_CMD_PRLO
, cmdiocb
, ndlp
, NULL
);
2310 return ndlp
->nlp_state
;
2314 lpfc_device_recov_unmap_node(struct lpfc_vport
*vport
,
2315 struct lpfc_nodelist
*ndlp
,
2319 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2321 ndlp
->nlp_prev_state
= NLP_STE_UNMAPPED_NODE
;
2322 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
2323 spin_lock_irq(shost
->host_lock
);
2324 ndlp
->nlp_flag
&= ~(NLP_NODEV_REMOVE
| NLP_NPR_2B_DISC
);
2325 spin_unlock_irq(shost
->host_lock
);
2326 lpfc_disc_set_adisc(vport
, ndlp
);
2328 return ndlp
->nlp_state
;
2332 lpfc_rcv_plogi_mapped_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2333 void *arg
, uint32_t evt
)
2335 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2337 lpfc_rcv_plogi(vport
, ndlp
, cmdiocb
);
2338 return ndlp
->nlp_state
;
2342 lpfc_rcv_prli_mapped_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2343 void *arg
, uint32_t evt
)
2345 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2347 if (!lpfc_rcv_prli_support_check(vport
, ndlp
, cmdiocb
))
2348 return ndlp
->nlp_state
;
2349 lpfc_els_rsp_prli_acc(vport
, cmdiocb
, ndlp
);
2350 return ndlp
->nlp_state
;
2354 lpfc_rcv_logo_mapped_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2355 void *arg
, uint32_t evt
)
2357 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2359 lpfc_rcv_logo(vport
, ndlp
, cmdiocb
, ELS_CMD_LOGO
);
2360 return ndlp
->nlp_state
;
2364 lpfc_rcv_padisc_mapped_node(struct lpfc_vport
*vport
,
2365 struct lpfc_nodelist
*ndlp
,
2366 void *arg
, uint32_t evt
)
2368 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2370 lpfc_rcv_padisc(vport
, ndlp
, cmdiocb
);
2371 return ndlp
->nlp_state
;
2375 lpfc_rcv_prlo_mapped_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2376 void *arg
, uint32_t evt
)
2378 struct lpfc_hba
*phba
= vport
->phba
;
2379 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2381 /* flush the target */
2382 lpfc_sli_abort_iocb(vport
, &phba
->sli
.sli3_ring
[LPFC_FCP_RING
],
2383 ndlp
->nlp_sid
, 0, LPFC_CTX_TGT
);
2385 /* Treat like rcv logo */
2386 lpfc_rcv_logo(vport
, ndlp
, cmdiocb
, ELS_CMD_PRLO
);
2387 return ndlp
->nlp_state
;
2391 lpfc_device_recov_mapped_node(struct lpfc_vport
*vport
,
2392 struct lpfc_nodelist
*ndlp
,
2396 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2398 ndlp
->nlp_prev_state
= NLP_STE_MAPPED_NODE
;
2399 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
2400 spin_lock_irq(shost
->host_lock
);
2401 ndlp
->nlp_flag
&= ~(NLP_NODEV_REMOVE
| NLP_NPR_2B_DISC
);
2402 spin_unlock_irq(shost
->host_lock
);
2403 lpfc_disc_set_adisc(vport
, ndlp
);
2404 return ndlp
->nlp_state
;
2408 lpfc_rcv_plogi_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2409 void *arg
, uint32_t evt
)
2411 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2412 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2414 /* Ignore PLOGI if we have an outstanding LOGO */
2415 if (ndlp
->nlp_flag
& (NLP_LOGO_SND
| NLP_LOGO_ACC
))
2416 return ndlp
->nlp_state
;
2417 if (lpfc_rcv_plogi(vport
, ndlp
, cmdiocb
)) {
2418 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
2419 spin_lock_irq(shost
->host_lock
);
2420 ndlp
->nlp_flag
&= ~(NLP_NPR_ADISC
| NLP_NPR_2B_DISC
);
2421 spin_unlock_irq(shost
->host_lock
);
2422 } else if (!(ndlp
->nlp_flag
& NLP_NPR_2B_DISC
)) {
2423 /* send PLOGI immediately, move to PLOGI issue state */
2424 if (!(ndlp
->nlp_flag
& NLP_DELAY_TMO
)) {
2425 ndlp
->nlp_prev_state
= NLP_STE_NPR_NODE
;
2426 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
2427 lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0);
2430 return ndlp
->nlp_state
;
2434 lpfc_rcv_prli_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2435 void *arg
, uint32_t evt
)
2437 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2438 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2441 memset(&stat
, 0, sizeof (struct ls_rjt
));
2442 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
2443 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_NOTHING_MORE
;
2444 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
2446 if (!(ndlp
->nlp_flag
& NLP_DELAY_TMO
)) {
2447 if (ndlp
->nlp_flag
& NLP_NPR_ADISC
) {
2448 spin_lock_irq(shost
->host_lock
);
2449 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
2450 ndlp
->nlp_prev_state
= NLP_STE_NPR_NODE
;
2451 spin_unlock_irq(shost
->host_lock
);
2452 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_ADISC_ISSUE
);
2453 lpfc_issue_els_adisc(vport
, ndlp
, 0);
2455 ndlp
->nlp_prev_state
= NLP_STE_NPR_NODE
;
2456 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
2457 lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0);
2460 return ndlp
->nlp_state
;
2464 lpfc_rcv_logo_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2465 void *arg
, uint32_t evt
)
2467 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2469 lpfc_rcv_logo(vport
, ndlp
, cmdiocb
, ELS_CMD_LOGO
);
2470 return ndlp
->nlp_state
;
2474 lpfc_rcv_padisc_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2475 void *arg
, uint32_t evt
)
2477 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2479 lpfc_rcv_padisc(vport
, ndlp
, cmdiocb
);
2481 * Do not start discovery if discovery is about to start
2482 * or discovery in progress for this node. Starting discovery
2483 * here will affect the counting of discovery threads.
2485 if (!(ndlp
->nlp_flag
& NLP_DELAY_TMO
) &&
2486 !(ndlp
->nlp_flag
& NLP_NPR_2B_DISC
)) {
2487 if (ndlp
->nlp_flag
& NLP_NPR_ADISC
) {
2488 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
2489 ndlp
->nlp_prev_state
= NLP_STE_NPR_NODE
;
2490 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_ADISC_ISSUE
);
2491 lpfc_issue_els_adisc(vport
, ndlp
, 0);
2493 ndlp
->nlp_prev_state
= NLP_STE_NPR_NODE
;
2494 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
2495 lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0);
2498 return ndlp
->nlp_state
;
2502 lpfc_rcv_prlo_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2503 void *arg
, uint32_t evt
)
2505 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2506 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2508 spin_lock_irq(shost
->host_lock
);
2509 ndlp
->nlp_flag
|= NLP_LOGO_ACC
;
2510 spin_unlock_irq(shost
->host_lock
);
2512 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
2514 if ((ndlp
->nlp_flag
& NLP_DELAY_TMO
) == 0) {
2515 mod_timer(&ndlp
->nlp_delayfunc
,
2516 jiffies
+ msecs_to_jiffies(1000 * 1));
2517 spin_lock_irq(shost
->host_lock
);
2518 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
2519 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
2520 spin_unlock_irq(shost
->host_lock
);
2521 ndlp
->nlp_last_elscmd
= ELS_CMD_PLOGI
;
2523 spin_lock_irq(shost
->host_lock
);
2524 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
2525 spin_unlock_irq(shost
->host_lock
);
2527 return ndlp
->nlp_state
;
2531 lpfc_cmpl_plogi_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2532 void *arg
, uint32_t evt
)
2534 struct lpfc_iocbq
*cmdiocb
, *rspiocb
;
2536 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2538 cmdiocb
= (struct lpfc_iocbq
*) arg
;
2539 rspiocb
= cmdiocb
->context_un
.rsp_iocb
;
2541 irsp
= &rspiocb
->iocb
;
2542 if (irsp
->ulpStatus
) {
2543 spin_lock_irq(shost
->host_lock
);
2544 ndlp
->nlp_flag
|= NLP_DEFER_RM
;
2545 spin_unlock_irq(shost
->host_lock
);
2546 return NLP_STE_FREED_NODE
;
2548 return ndlp
->nlp_state
;
2552 lpfc_cmpl_prli_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2553 void *arg
, uint32_t evt
)
2555 struct lpfc_iocbq
*cmdiocb
, *rspiocb
;
2558 cmdiocb
= (struct lpfc_iocbq
*) arg
;
2559 rspiocb
= cmdiocb
->context_un
.rsp_iocb
;
2561 irsp
= &rspiocb
->iocb
;
2562 if (irsp
->ulpStatus
&& (ndlp
->nlp_flag
& NLP_NODEV_REMOVE
)) {
2563 lpfc_drop_node(vport
, ndlp
);
2564 return NLP_STE_FREED_NODE
;
2566 return ndlp
->nlp_state
;
2570 lpfc_cmpl_logo_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2571 void *arg
, uint32_t evt
)
2573 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2575 /* For the fabric port just clear the fc flags. */
2576 if (ndlp
->nlp_DID
== Fabric_DID
) {
2577 spin_lock_irq(shost
->host_lock
);
2578 vport
->fc_flag
&= ~(FC_FABRIC
| FC_PUBLIC_LOOP
);
2579 spin_unlock_irq(shost
->host_lock
);
2581 lpfc_unreg_rpi(vport
, ndlp
);
2582 return ndlp
->nlp_state
;
2586 lpfc_cmpl_adisc_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2587 void *arg
, uint32_t evt
)
2589 struct lpfc_iocbq
*cmdiocb
, *rspiocb
;
2592 cmdiocb
= (struct lpfc_iocbq
*) arg
;
2593 rspiocb
= cmdiocb
->context_un
.rsp_iocb
;
2595 irsp
= &rspiocb
->iocb
;
2596 if (irsp
->ulpStatus
&& (ndlp
->nlp_flag
& NLP_NODEV_REMOVE
)) {
2597 lpfc_drop_node(vport
, ndlp
);
2598 return NLP_STE_FREED_NODE
;
2600 return ndlp
->nlp_state
;
2604 lpfc_cmpl_reglogin_npr_node(struct lpfc_vport
*vport
,
2605 struct lpfc_nodelist
*ndlp
,
2606 void *arg
, uint32_t evt
)
2608 LPFC_MBOXQ_t
*pmb
= (LPFC_MBOXQ_t
*) arg
;
2609 MAILBOX_t
*mb
= &pmb
->u
.mb
;
2611 if (!mb
->mbxStatus
) {
2612 /* SLI4 ports have preallocated logical rpis. */
2613 if (vport
->phba
->sli_rev
< LPFC_SLI_REV4
)
2614 ndlp
->nlp_rpi
= mb
->un
.varWords
[0];
2615 ndlp
->nlp_flag
|= NLP_RPI_REGISTERED
;
2616 if (ndlp
->nlp_flag
& NLP_LOGO_ACC
) {
2617 lpfc_unreg_rpi(vport
, ndlp
);
2620 if (ndlp
->nlp_flag
& NLP_NODEV_REMOVE
) {
2621 lpfc_drop_node(vport
, ndlp
);
2622 return NLP_STE_FREED_NODE
;
2625 return ndlp
->nlp_state
;
2629 lpfc_device_rm_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2630 void *arg
, uint32_t evt
)
2632 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2634 if (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) {
2635 spin_lock_irq(shost
->host_lock
);
2636 ndlp
->nlp_flag
|= NLP_NODEV_REMOVE
;
2637 spin_unlock_irq(shost
->host_lock
);
2638 return ndlp
->nlp_state
;
2640 lpfc_drop_node(vport
, ndlp
);
2641 return NLP_STE_FREED_NODE
;
2645 lpfc_device_recov_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2646 void *arg
, uint32_t evt
)
2648 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2650 /* Don't do anything that will mess up processing of the
2653 if (vport
->fc_flag
& FC_RSCN_DEFERRED
)
2654 return ndlp
->nlp_state
;
2656 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
2657 spin_lock_irq(shost
->host_lock
);
2658 ndlp
->nlp_flag
&= ~(NLP_NODEV_REMOVE
| NLP_NPR_2B_DISC
);
2659 spin_unlock_irq(shost
->host_lock
);
2660 return ndlp
->nlp_state
;
2664 /* This next section defines the NPort Discovery State Machine */
2666 /* There are 4 different double linked lists nodelist entries can reside on.
2667 * The plogi list and adisc list are used when Link Up discovery or RSCN
2668 * processing is needed. Each list holds the nodes that we will send PLOGI
2669 * or ADISC on. These lists will keep track of what nodes will be effected
2670 * by an RSCN, or a Link Up (Typically, all nodes are effected on Link Up).
2671 * The unmapped_list will contain all nodes that we have successfully logged
2672 * into at the Fibre Channel level. The mapped_list will contain all nodes
2673 * that are mapped FCP targets.
2676 * The bind list is a list of undiscovered (potentially non-existent) nodes
2677 * that we have saved binding information on. This information is used when
2678 * nodes transition from the unmapped to the mapped list.
2680 /* For UNUSED_NODE state, the node has just been allocated .
2681 * For PLOGI_ISSUE and REG_LOGIN_ISSUE, the node is on
2682 * the PLOGI list. For REG_LOGIN_COMPL, the node is taken off the PLOGI list
2683 * and put on the unmapped list. For ADISC processing, the node is taken off
2684 * the ADISC list and placed on either the mapped or unmapped list (depending
2685 * on its previous state). Once on the unmapped list, a PRLI is issued and the
2686 * state changed to PRLI_ISSUE. When the PRLI completion occurs, the state is
2687 * changed to UNMAPPED_NODE. If the completion indicates a mapped
2688 * node, the node is taken off the unmapped list. The binding list is checked
2689 * for a valid binding, or a binding is automatically assigned. If binding
2690 * assignment is unsuccessful, the node is left on the unmapped list. If
2691 * binding assignment is successful, the associated binding list entry (if
2692 * any) is removed, and the node is placed on the mapped list.
2695 * For a Link Down, all nodes on the ADISC, PLOGI, unmapped or mapped
2696 * lists will receive a DEVICE_RECOVERY event. If the linkdown or devloss timers
2697 * expire, all effected nodes will receive a DEVICE_RM event.
2700 * For a Link Up or RSCN, all nodes will move from the mapped / unmapped lists
2701 * to either the ADISC or PLOGI list. After a Nameserver query or ALPA loopmap
2702 * check, additional nodes may be added or removed (via DEVICE_RM) to / from
2703 * the PLOGI or ADISC lists. Once the PLOGI and ADISC lists are populated,
2704 * we will first process the ADISC list. 32 entries are processed initially and
2705 * ADISC is initited for each one. Completions / Events for each node are
2706 * funnelled thru the state machine. As each node finishes ADISC processing, it
2707 * starts ADISC for any nodes waiting for ADISC processing. If no nodes are
2708 * waiting, and the ADISC list count is identically 0, then we are done. For
2709 * Link Up discovery, since all nodes on the PLOGI list are UNREG_LOGIN'ed, we
2710 * can issue a CLEAR_LA and reenable Link Events. Next we will process the PLOGI
2711 * list. 32 entries are processed initially and PLOGI is initited for each one.
2712 * Completions / Events for each node are funnelled thru the state machine. As
2713 * each node finishes PLOGI processing, it starts PLOGI for any nodes waiting
2714 * for PLOGI processing. If no nodes are waiting, and the PLOGI list count is
2715 * indentically 0, then we are done. We have now completed discovery / RSCN
2716 * handling. Upon completion, ALL nodes should be on either the mapped or
2720 static uint32_t (*lpfc_disc_action
[NLP_STE_MAX_STATE
* NLP_EVT_MAX_EVENT
])
2721 (struct lpfc_vport
*, struct lpfc_nodelist
*, void *, uint32_t) = {
2722 /* Action routine Event Current State */
2723 lpfc_rcv_plogi_unused_node
, /* RCV_PLOGI UNUSED_NODE */
2724 lpfc_rcv_els_unused_node
, /* RCV_PRLI */
2725 lpfc_rcv_logo_unused_node
, /* RCV_LOGO */
2726 lpfc_rcv_els_unused_node
, /* RCV_ADISC */
2727 lpfc_rcv_els_unused_node
, /* RCV_PDISC */
2728 lpfc_rcv_els_unused_node
, /* RCV_PRLO */
2729 lpfc_disc_illegal
, /* CMPL_PLOGI */
2730 lpfc_disc_illegal
, /* CMPL_PRLI */
2731 lpfc_cmpl_logo_unused_node
, /* CMPL_LOGO */
2732 lpfc_disc_illegal
, /* CMPL_ADISC */
2733 lpfc_disc_illegal
, /* CMPL_REG_LOGIN */
2734 lpfc_device_rm_unused_node
, /* DEVICE_RM */
2735 lpfc_device_recov_unused_node
, /* DEVICE_RECOVERY */
2737 lpfc_rcv_plogi_plogi_issue
, /* RCV_PLOGI PLOGI_ISSUE */
2738 lpfc_rcv_prli_plogi_issue
, /* RCV_PRLI */
2739 lpfc_rcv_logo_plogi_issue
, /* RCV_LOGO */
2740 lpfc_rcv_els_plogi_issue
, /* RCV_ADISC */
2741 lpfc_rcv_els_plogi_issue
, /* RCV_PDISC */
2742 lpfc_rcv_els_plogi_issue
, /* RCV_PRLO */
2743 lpfc_cmpl_plogi_plogi_issue
, /* CMPL_PLOGI */
2744 lpfc_disc_illegal
, /* CMPL_PRLI */
2745 lpfc_cmpl_logo_plogi_issue
, /* CMPL_LOGO */
2746 lpfc_disc_illegal
, /* CMPL_ADISC */
2747 lpfc_cmpl_reglogin_plogi_issue
,/* CMPL_REG_LOGIN */
2748 lpfc_device_rm_plogi_issue
, /* DEVICE_RM */
2749 lpfc_device_recov_plogi_issue
, /* DEVICE_RECOVERY */
2751 lpfc_rcv_plogi_adisc_issue
, /* RCV_PLOGI ADISC_ISSUE */
2752 lpfc_rcv_prli_adisc_issue
, /* RCV_PRLI */
2753 lpfc_rcv_logo_adisc_issue
, /* RCV_LOGO */
2754 lpfc_rcv_padisc_adisc_issue
, /* RCV_ADISC */
2755 lpfc_rcv_padisc_adisc_issue
, /* RCV_PDISC */
2756 lpfc_rcv_prlo_adisc_issue
, /* RCV_PRLO */
2757 lpfc_disc_illegal
, /* CMPL_PLOGI */
2758 lpfc_disc_illegal
, /* CMPL_PRLI */
2759 lpfc_disc_illegal
, /* CMPL_LOGO */
2760 lpfc_cmpl_adisc_adisc_issue
, /* CMPL_ADISC */
2761 lpfc_disc_illegal
, /* CMPL_REG_LOGIN */
2762 lpfc_device_rm_adisc_issue
, /* DEVICE_RM */
2763 lpfc_device_recov_adisc_issue
, /* DEVICE_RECOVERY */
2765 lpfc_rcv_plogi_reglogin_issue
, /* RCV_PLOGI REG_LOGIN_ISSUE */
2766 lpfc_rcv_prli_reglogin_issue
, /* RCV_PLOGI */
2767 lpfc_rcv_logo_reglogin_issue
, /* RCV_LOGO */
2768 lpfc_rcv_padisc_reglogin_issue
, /* RCV_ADISC */
2769 lpfc_rcv_padisc_reglogin_issue
, /* RCV_PDISC */
2770 lpfc_rcv_prlo_reglogin_issue
, /* RCV_PRLO */
2771 lpfc_cmpl_plogi_illegal
, /* CMPL_PLOGI */
2772 lpfc_disc_illegal
, /* CMPL_PRLI */
2773 lpfc_disc_illegal
, /* CMPL_LOGO */
2774 lpfc_disc_illegal
, /* CMPL_ADISC */
2775 lpfc_cmpl_reglogin_reglogin_issue
,/* CMPL_REG_LOGIN */
2776 lpfc_device_rm_reglogin_issue
, /* DEVICE_RM */
2777 lpfc_device_recov_reglogin_issue
,/* DEVICE_RECOVERY */
2779 lpfc_rcv_plogi_prli_issue
, /* RCV_PLOGI PRLI_ISSUE */
2780 lpfc_rcv_prli_prli_issue
, /* RCV_PRLI */
2781 lpfc_rcv_logo_prli_issue
, /* RCV_LOGO */
2782 lpfc_rcv_padisc_prli_issue
, /* RCV_ADISC */
2783 lpfc_rcv_padisc_prli_issue
, /* RCV_PDISC */
2784 lpfc_rcv_prlo_prli_issue
, /* RCV_PRLO */
2785 lpfc_cmpl_plogi_illegal
, /* CMPL_PLOGI */
2786 lpfc_cmpl_prli_prli_issue
, /* CMPL_PRLI */
2787 lpfc_disc_illegal
, /* CMPL_LOGO */
2788 lpfc_disc_illegal
, /* CMPL_ADISC */
2789 lpfc_disc_illegal
, /* CMPL_REG_LOGIN */
2790 lpfc_device_rm_prli_issue
, /* DEVICE_RM */
2791 lpfc_device_recov_prli_issue
, /* DEVICE_RECOVERY */
2793 lpfc_rcv_plogi_logo_issue
, /* RCV_PLOGI LOGO_ISSUE */
2794 lpfc_rcv_prli_logo_issue
, /* RCV_PRLI */
2795 lpfc_rcv_logo_logo_issue
, /* RCV_LOGO */
2796 lpfc_rcv_padisc_logo_issue
, /* RCV_ADISC */
2797 lpfc_rcv_padisc_logo_issue
, /* RCV_PDISC */
2798 lpfc_rcv_prlo_logo_issue
, /* RCV_PRLO */
2799 lpfc_cmpl_plogi_illegal
, /* CMPL_PLOGI */
2800 lpfc_disc_illegal
, /* CMPL_PRLI */
2801 lpfc_cmpl_logo_logo_issue
, /* CMPL_LOGO */
2802 lpfc_disc_illegal
, /* CMPL_ADISC */
2803 lpfc_disc_illegal
, /* CMPL_REG_LOGIN */
2804 lpfc_device_rm_logo_issue
, /* DEVICE_RM */
2805 lpfc_device_recov_logo_issue
, /* DEVICE_RECOVERY */
2807 lpfc_rcv_plogi_unmap_node
, /* RCV_PLOGI UNMAPPED_NODE */
2808 lpfc_rcv_prli_unmap_node
, /* RCV_PRLI */
2809 lpfc_rcv_logo_unmap_node
, /* RCV_LOGO */
2810 lpfc_rcv_padisc_unmap_node
, /* RCV_ADISC */
2811 lpfc_rcv_padisc_unmap_node
, /* RCV_PDISC */
2812 lpfc_rcv_prlo_unmap_node
, /* RCV_PRLO */
2813 lpfc_disc_illegal
, /* CMPL_PLOGI */
2814 lpfc_disc_illegal
, /* CMPL_PRLI */
2815 lpfc_disc_illegal
, /* CMPL_LOGO */
2816 lpfc_disc_illegal
, /* CMPL_ADISC */
2817 lpfc_disc_illegal
, /* CMPL_REG_LOGIN */
2818 lpfc_disc_illegal
, /* DEVICE_RM */
2819 lpfc_device_recov_unmap_node
, /* DEVICE_RECOVERY */
2821 lpfc_rcv_plogi_mapped_node
, /* RCV_PLOGI MAPPED_NODE */
2822 lpfc_rcv_prli_mapped_node
, /* RCV_PRLI */
2823 lpfc_rcv_logo_mapped_node
, /* RCV_LOGO */
2824 lpfc_rcv_padisc_mapped_node
, /* RCV_ADISC */
2825 lpfc_rcv_padisc_mapped_node
, /* RCV_PDISC */
2826 lpfc_rcv_prlo_mapped_node
, /* RCV_PRLO */
2827 lpfc_disc_illegal
, /* CMPL_PLOGI */
2828 lpfc_disc_illegal
, /* CMPL_PRLI */
2829 lpfc_disc_illegal
, /* CMPL_LOGO */
2830 lpfc_disc_illegal
, /* CMPL_ADISC */
2831 lpfc_disc_illegal
, /* CMPL_REG_LOGIN */
2832 lpfc_disc_illegal
, /* DEVICE_RM */
2833 lpfc_device_recov_mapped_node
, /* DEVICE_RECOVERY */
2835 lpfc_rcv_plogi_npr_node
, /* RCV_PLOGI NPR_NODE */
2836 lpfc_rcv_prli_npr_node
, /* RCV_PRLI */
2837 lpfc_rcv_logo_npr_node
, /* RCV_LOGO */
2838 lpfc_rcv_padisc_npr_node
, /* RCV_ADISC */
2839 lpfc_rcv_padisc_npr_node
, /* RCV_PDISC */
2840 lpfc_rcv_prlo_npr_node
, /* RCV_PRLO */
2841 lpfc_cmpl_plogi_npr_node
, /* CMPL_PLOGI */
2842 lpfc_cmpl_prli_npr_node
, /* CMPL_PRLI */
2843 lpfc_cmpl_logo_npr_node
, /* CMPL_LOGO */
2844 lpfc_cmpl_adisc_npr_node
, /* CMPL_ADISC */
2845 lpfc_cmpl_reglogin_npr_node
, /* CMPL_REG_LOGIN */
2846 lpfc_device_rm_npr_node
, /* DEVICE_RM */
2847 lpfc_device_recov_npr_node
, /* DEVICE_RECOVERY */
2851 lpfc_disc_state_machine(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2852 void *arg
, uint32_t evt
)
2854 uint32_t cur_state
, rc
;
2855 uint32_t(*func
) (struct lpfc_vport
*, struct lpfc_nodelist
*, void *,
2857 uint32_t got_ndlp
= 0;
2859 if (lpfc_nlp_get(ndlp
))
2862 cur_state
= ndlp
->nlp_state
;
2864 /* DSM in event <evt> on NPort <nlp_DID> in state <cur_state> */
2865 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
2866 "0211 DSM in event x%x on NPort x%x in "
2867 "state %d Data: x%x\n",
2868 evt
, ndlp
->nlp_DID
, cur_state
, ndlp
->nlp_flag
);
2870 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_DSM
,
2871 "DSM in: evt:%d ste:%d did:x%x",
2872 evt
, cur_state
, ndlp
->nlp_DID
);
2874 func
= lpfc_disc_action
[(cur_state
* NLP_EVT_MAX_EVENT
) + evt
];
2875 rc
= (func
) (vport
, ndlp
, arg
, evt
);
2877 /* DSM out state <rc> on NPort <nlp_DID> */
2879 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
2880 "0212 DSM out state %d on NPort x%x Data: x%x\n",
2881 rc
, ndlp
->nlp_DID
, ndlp
->nlp_flag
);
2883 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_DSM
,
2884 "DSM out: ste:%d did:x%x flg:x%x",
2885 rc
, ndlp
->nlp_DID
, ndlp
->nlp_flag
);
2886 /* Decrement the ndlp reference count held for this function */
2889 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
2890 "0213 DSM out state %d on NPort free\n", rc
);
2892 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_DSM
,
2893 "DSM out: ste:%d did:x%x flg:x%x",