1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017-2018 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>
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->ctx_ndlp = 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
->ctx_buf
;
539 ndlp
= (struct lpfc_nodelist
*)mboxq
->ctx_ndlp
;
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 spin_lock_irq(shost
->host_lock
);
840 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
841 spin_unlock_irq(shost
->host_lock
);
845 if (!(vport
->fc_flag
& FC_PT2PT
)) {
846 /* Check config parameter use-adisc or FCP-2 */
847 if ((vport
->cfg_use_adisc
&& (vport
->fc_flag
& FC_RSCN_MODE
)) ||
848 ((ndlp
->nlp_fcp_info
& NLP_FCP_2_DEVICE
) &&
849 (ndlp
->nlp_type
& NLP_FCP_TARGET
))) {
850 spin_lock_irq(shost
->host_lock
);
851 ndlp
->nlp_flag
|= NLP_NPR_ADISC
;
852 spin_unlock_irq(shost
->host_lock
);
857 spin_lock_irq(shost
->host_lock
);
858 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
859 spin_unlock_irq(shost
->host_lock
);
860 lpfc_unreg_rpi(vport
, ndlp
);
865 * lpfc_release_rpi - Release a RPI by issuing unreg_login mailbox cmd.
866 * @phba : Pointer to lpfc_hba structure.
867 * @vport: Pointer to lpfc_vport structure.
868 * @rpi : rpi to be release.
870 * This function will send a unreg_login mailbox command to the firmware
874 lpfc_release_rpi(struct lpfc_hba
*phba
, struct lpfc_vport
*vport
,
875 struct lpfc_nodelist
*ndlp
, uint16_t rpi
)
880 /* If there is already an UNREG in progress for this ndlp,
881 * no need to queue up another one.
883 if (ndlp
->nlp_flag
& NLP_UNREG_INP
) {
884 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
885 "1435 release_rpi SKIP UNREG x%x on "
886 "NPort x%x deferred x%x flg x%x "
888 ndlp
->nlp_rpi
, ndlp
->nlp_DID
,
890 ndlp
->nlp_flag
, ndlp
);
894 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
,
897 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
898 "2796 mailbox memory allocation failed \n");
900 lpfc_unreg_login(phba
, vport
->vpi
, rpi
, pmb
);
901 pmb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
903 pmb
->ctx_ndlp
= ndlp
;
905 if (((ndlp
->nlp_DID
& Fabric_DID_MASK
) != Fabric_DID_MASK
) &&
906 (!(vport
->fc_flag
& FC_OFFLINE_MODE
)))
907 ndlp
->nlp_flag
|= NLP_UNREG_INP
;
909 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
910 "1437 release_rpi UNREG x%x "
911 "on NPort x%x flg x%x\n",
912 ndlp
->nlp_rpi
, ndlp
->nlp_DID
, ndlp
->nlp_flag
);
914 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
915 if (rc
== MBX_NOT_FINISHED
)
916 mempool_free(pmb
, phba
->mbox_mem_pool
);
921 lpfc_disc_illegal(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
922 void *arg
, uint32_t evt
)
924 struct lpfc_hba
*phba
;
925 LPFC_MBOXQ_t
*pmb
= (LPFC_MBOXQ_t
*) arg
;
929 /* Release the RPI if reglogin completing */
930 if (!(phba
->pport
->load_flag
& FC_UNLOADING
) &&
931 (evt
== NLP_EVT_CMPL_REG_LOGIN
) &&
932 (!pmb
->u
.mb
.mbxStatus
)) {
933 rpi
= pmb
->u
.mb
.un
.varWords
[0];
934 lpfc_release_rpi(phba
, vport
, ndlp
, rpi
);
936 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
937 "0271 Illegal State Transition: node x%x "
938 "event x%x, state x%x Data: x%x x%x\n",
939 ndlp
->nlp_DID
, evt
, ndlp
->nlp_state
, ndlp
->nlp_rpi
,
941 return ndlp
->nlp_state
;
945 lpfc_cmpl_plogi_illegal(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
946 void *arg
, uint32_t evt
)
948 /* This transition is only legal if we previously
949 * rcv'ed a PLOGI. Since we don't want 2 discovery threads
950 * working on the same NPortID, do nothing for this thread
953 if (!(ndlp
->nlp_flag
& NLP_RCV_PLOGI
)) {
954 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
955 "0272 Illegal State Transition: node x%x "
956 "event x%x, state x%x Data: x%x x%x\n",
957 ndlp
->nlp_DID
, evt
, ndlp
->nlp_state
, ndlp
->nlp_rpi
,
960 return ndlp
->nlp_state
;
963 /* Start of Discovery State Machine routines */
966 lpfc_rcv_plogi_unused_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
967 void *arg
, uint32_t evt
)
969 struct lpfc_iocbq
*cmdiocb
;
971 cmdiocb
= (struct lpfc_iocbq
*) arg
;
973 if (lpfc_rcv_plogi(vport
, ndlp
, cmdiocb
)) {
974 return ndlp
->nlp_state
;
976 return NLP_STE_FREED_NODE
;
980 lpfc_rcv_els_unused_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
981 void *arg
, uint32_t evt
)
983 lpfc_issue_els_logo(vport
, ndlp
, 0);
984 return ndlp
->nlp_state
;
988 lpfc_rcv_logo_unused_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
989 void *arg
, uint32_t evt
)
991 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
992 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
994 spin_lock_irq(shost
->host_lock
);
995 ndlp
->nlp_flag
|= NLP_LOGO_ACC
;
996 spin_unlock_irq(shost
->host_lock
);
997 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
999 return ndlp
->nlp_state
;
1003 lpfc_cmpl_logo_unused_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1004 void *arg
, uint32_t evt
)
1006 return NLP_STE_FREED_NODE
;
1010 lpfc_device_rm_unused_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1011 void *arg
, uint32_t evt
)
1013 return NLP_STE_FREED_NODE
;
1017 lpfc_device_recov_unused_node(struct lpfc_vport
*vport
,
1018 struct lpfc_nodelist
*ndlp
,
1019 void *arg
, uint32_t evt
)
1021 return ndlp
->nlp_state
;
1025 lpfc_rcv_plogi_plogi_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1026 void *arg
, uint32_t evt
)
1028 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1029 struct lpfc_hba
*phba
= vport
->phba
;
1030 struct lpfc_iocbq
*cmdiocb
= arg
;
1031 struct lpfc_dmabuf
*pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
1032 uint32_t *lp
= (uint32_t *) pcmd
->virt
;
1033 struct serv_parm
*sp
= (struct serv_parm
*) (lp
+ 1);
1037 memset(&stat
, 0, sizeof (struct ls_rjt
));
1039 /* For a PLOGI, we only accept if our portname is less
1040 * than the remote portname.
1042 phba
->fc_stat
.elsLogiCol
++;
1043 port_cmp
= memcmp(&vport
->fc_portname
, &sp
->portName
,
1044 sizeof(struct lpfc_name
));
1046 if (port_cmp
>= 0) {
1047 /* Reject this request because the remote node will accept
1049 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
1050 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CMD_IN_PROGRESS
;
1051 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
,
1054 if (lpfc_rcv_plogi(vport
, ndlp
, cmdiocb
) &&
1055 (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) &&
1056 (vport
->num_disc_nodes
)) {
1057 spin_lock_irq(shost
->host_lock
);
1058 ndlp
->nlp_flag
&= ~NLP_NPR_2B_DISC
;
1059 spin_unlock_irq(shost
->host_lock
);
1060 /* Check if there are more PLOGIs to be sent */
1061 lpfc_more_plogi(vport
);
1062 if (vport
->num_disc_nodes
== 0) {
1063 spin_lock_irq(shost
->host_lock
);
1064 vport
->fc_flag
&= ~FC_NDISC_ACTIVE
;
1065 spin_unlock_irq(shost
->host_lock
);
1066 lpfc_can_disctmo(vport
);
1067 lpfc_end_rscn(vport
);
1070 } /* If our portname was less */
1072 return ndlp
->nlp_state
;
1076 lpfc_rcv_prli_plogi_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1077 void *arg
, uint32_t evt
)
1079 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1082 memset(&stat
, 0, sizeof (struct ls_rjt
));
1083 stat
.un
.b
.lsRjtRsnCode
= LSRJT_LOGICAL_BSY
;
1084 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_NOTHING_MORE
;
1085 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
1086 return ndlp
->nlp_state
;
1090 lpfc_rcv_logo_plogi_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1091 void *arg
, uint32_t evt
)
1093 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1095 /* Retrieve RPI from LOGO IOCB. RPI is used for CMD_ABORT_XRI_CN */
1096 if (vport
->phba
->sli_rev
== LPFC_SLI_REV3
)
1097 ndlp
->nlp_rpi
= cmdiocb
->iocb
.ulpIoTag
;
1098 /* software abort outstanding PLOGI */
1099 lpfc_els_abort(vport
->phba
, ndlp
);
1101 lpfc_rcv_logo(vport
, ndlp
, cmdiocb
, ELS_CMD_LOGO
);
1102 return ndlp
->nlp_state
;
1106 lpfc_rcv_els_plogi_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1107 void *arg
, uint32_t evt
)
1109 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1110 struct lpfc_hba
*phba
= vport
->phba
;
1111 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1113 /* software abort outstanding PLOGI */
1114 lpfc_els_abort(phba
, ndlp
);
1116 if (evt
== NLP_EVT_RCV_LOGO
) {
1117 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
1119 lpfc_issue_els_logo(vport
, ndlp
, 0);
1122 /* Put ndlp in npr state set plogi timer for 1 sec */
1123 mod_timer(&ndlp
->nlp_delayfunc
, jiffies
+ msecs_to_jiffies(1000 * 1));
1124 spin_lock_irq(shost
->host_lock
);
1125 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
1126 spin_unlock_irq(shost
->host_lock
);
1127 ndlp
->nlp_last_elscmd
= ELS_CMD_PLOGI
;
1128 ndlp
->nlp_prev_state
= NLP_STE_PLOGI_ISSUE
;
1129 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1131 return ndlp
->nlp_state
;
1135 lpfc_cmpl_plogi_plogi_issue(struct lpfc_vport
*vport
,
1136 struct lpfc_nodelist
*ndlp
,
1140 struct lpfc_hba
*phba
= vport
->phba
;
1141 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1142 struct lpfc_iocbq
*cmdiocb
, *rspiocb
;
1143 struct lpfc_dmabuf
*pcmd
, *prsp
, *mp
;
1147 struct serv_parm
*sp
;
1152 cmdiocb
= (struct lpfc_iocbq
*) arg
;
1153 rspiocb
= cmdiocb
->context_un
.rsp_iocb
;
1155 if (ndlp
->nlp_flag
& NLP_ACC_REGLOGIN
) {
1156 /* Recovery from PLOGI collision logic */
1157 return ndlp
->nlp_state
;
1160 irsp
= &rspiocb
->iocb
;
1162 if (irsp
->ulpStatus
)
1165 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
1167 prsp
= list_get_first(&pcmd
->list
, struct lpfc_dmabuf
, list
);
1171 lp
= (uint32_t *) prsp
->virt
;
1172 sp
= (struct serv_parm
*) ((uint8_t *) lp
+ sizeof (uint32_t));
1174 /* Some switches have FDMI servers returning 0 for WWN */
1175 if ((ndlp
->nlp_DID
!= FDMI_DID
) &&
1176 (wwn_to_u64(sp
->portName
.u
.wwn
) == 0 ||
1177 wwn_to_u64(sp
->nodeName
.u
.wwn
) == 0)) {
1178 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1179 "0142 PLOGI RSP: Invalid WWN.\n");
1182 if (!lpfc_check_sparm(vport
, ndlp
, sp
, CLASS3
, 0))
1184 /* PLOGI chkparm OK */
1185 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
1186 "0121 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
1187 ndlp
->nlp_DID
, ndlp
->nlp_state
,
1188 ndlp
->nlp_flag
, ndlp
->nlp_rpi
);
1189 if (vport
->cfg_fcp_class
== 2 && (sp
->cls2
.classValid
))
1190 ndlp
->nlp_fcp_info
|= CLASS2
;
1192 ndlp
->nlp_fcp_info
|= CLASS3
;
1194 ndlp
->nlp_class_sup
= 0;
1195 if (sp
->cls1
.classValid
)
1196 ndlp
->nlp_class_sup
|= FC_COS_CLASS1
;
1197 if (sp
->cls2
.classValid
)
1198 ndlp
->nlp_class_sup
|= FC_COS_CLASS2
;
1199 if (sp
->cls3
.classValid
)
1200 ndlp
->nlp_class_sup
|= FC_COS_CLASS3
;
1201 if (sp
->cls4
.classValid
)
1202 ndlp
->nlp_class_sup
|= FC_COS_CLASS4
;
1203 ndlp
->nlp_maxframe
=
1204 ((sp
->cmn
.bbRcvSizeMsb
& 0x0F) << 8) | sp
->cmn
.bbRcvSizeLsb
;
1206 if ((vport
->fc_flag
& FC_PT2PT
) &&
1207 (vport
->fc_flag
& FC_PT2PT_PLOGI
)) {
1208 ed_tov
= be32_to_cpu(sp
->cmn
.e_d_tov
);
1209 if (sp
->cmn
.edtovResolution
) {
1210 /* E_D_TOV ticks are in nanoseconds */
1211 ed_tov
= (phba
->fc_edtov
+ 999999) / 1000000;
1214 ndlp
->nlp_flag
&= ~NLP_SUPPRESS_RSP
;
1215 if ((phba
->sli
.sli_flag
& LPFC_SLI_SUPPRESS_RSP
) &&
1216 sp
->cmn
.valid_vendor_ver_level
) {
1217 vid
= be32_to_cpu(sp
->un
.vv
.vid
);
1218 flag
= be32_to_cpu(sp
->un
.vv
.flags
);
1219 if ((vid
== LPFC_VV_EMLX_ID
) &&
1220 (flag
& LPFC_VV_SUPPRESS_RSP
))
1221 ndlp
->nlp_flag
|= NLP_SUPPRESS_RSP
;
1225 * Use the larger EDTOV
1226 * RATOV = 2 * EDTOV for pt-to-pt
1228 if (ed_tov
> phba
->fc_edtov
)
1229 phba
->fc_edtov
= ed_tov
;
1230 phba
->fc_ratov
= (2 * phba
->fc_edtov
) / 1000;
1232 memcpy(&phba
->fc_fabparam
, sp
, sizeof(struct serv_parm
));
1234 /* Issue config_link / reg_vfi to account for updated TOV's */
1235 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
1236 lpfc_issue_reg_vfi(vport
);
1238 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1240 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1241 "0133 PLOGI: no memory "
1243 "Data: x%x x%x x%x x%x\n",
1244 ndlp
->nlp_DID
, ndlp
->nlp_state
,
1245 ndlp
->nlp_flag
, ndlp
->nlp_rpi
);
1249 lpfc_config_link(phba
, mbox
);
1251 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
1252 mbox
->vport
= vport
;
1253 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
1254 if (rc
== MBX_NOT_FINISHED
) {
1255 mempool_free(mbox
, phba
->mbox_mem_pool
);
1261 lpfc_unreg_rpi(vport
, ndlp
);
1263 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1265 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1266 "0018 PLOGI: no memory for reg_login "
1267 "Data: x%x x%x x%x x%x\n",
1268 ndlp
->nlp_DID
, ndlp
->nlp_state
,
1269 ndlp
->nlp_flag
, ndlp
->nlp_rpi
);
1273 if (lpfc_reg_rpi(phba
, vport
->vpi
, irsp
->un
.elsreq64
.remoteID
,
1274 (uint8_t *) sp
, mbox
, ndlp
->nlp_rpi
) == 0) {
1275 switch (ndlp
->nlp_DID
) {
1276 case NameServer_DID
:
1277 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_ns_reg_login
;
1280 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_fdmi_reg_login
;
1283 ndlp
->nlp_flag
|= NLP_REG_LOGIN_SEND
;
1284 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_reg_login
;
1286 mbox
->ctx_ndlp
= lpfc_nlp_get(ndlp
);
1287 mbox
->vport
= vport
;
1288 if (lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
)
1289 != MBX_NOT_FINISHED
) {
1290 lpfc_nlp_set_state(vport
, ndlp
,
1291 NLP_STE_REG_LOGIN_ISSUE
);
1292 return ndlp
->nlp_state
;
1294 if (ndlp
->nlp_flag
& NLP_REG_LOGIN_SEND
)
1295 ndlp
->nlp_flag
&= ~NLP_REG_LOGIN_SEND
;
1296 /* decrement node reference count to the failed mbox
1300 mp
= (struct lpfc_dmabuf
*)mbox
->ctx_buf
;
1301 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
1303 mempool_free(mbox
, phba
->mbox_mem_pool
);
1305 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1306 "0134 PLOGI: cannot issue reg_login "
1307 "Data: x%x x%x x%x x%x\n",
1308 ndlp
->nlp_DID
, ndlp
->nlp_state
,
1309 ndlp
->nlp_flag
, ndlp
->nlp_rpi
);
1311 mempool_free(mbox
, phba
->mbox_mem_pool
);
1313 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1314 "0135 PLOGI: cannot format reg_login "
1315 "Data: x%x x%x x%x x%x\n",
1316 ndlp
->nlp_DID
, ndlp
->nlp_state
,
1317 ndlp
->nlp_flag
, ndlp
->nlp_rpi
);
1322 if (ndlp
->nlp_DID
== NameServer_DID
) {
1323 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
1324 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1325 "0261 Cannot Register NameServer login\n");
1329 ** In case the node reference counter does not go to zero, ensure that
1330 ** the stale state for the node is not processed.
1333 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
1334 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1335 spin_lock_irq(shost
->host_lock
);
1336 ndlp
->nlp_flag
|= NLP_DEFER_RM
;
1337 spin_unlock_irq(shost
->host_lock
);
1338 return NLP_STE_FREED_NODE
;
1342 lpfc_cmpl_logo_plogi_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1343 void *arg
, uint32_t evt
)
1345 return ndlp
->nlp_state
;
1349 lpfc_cmpl_reglogin_plogi_issue(struct lpfc_vport
*vport
,
1350 struct lpfc_nodelist
*ndlp
, void *arg
, uint32_t evt
)
1352 struct lpfc_hba
*phba
;
1353 LPFC_MBOXQ_t
*pmb
= (LPFC_MBOXQ_t
*) arg
;
1354 MAILBOX_t
*mb
= &pmb
->u
.mb
;
1358 /* Release the RPI */
1359 if (!(phba
->pport
->load_flag
& FC_UNLOADING
) &&
1361 rpi
= pmb
->u
.mb
.un
.varWords
[0];
1362 lpfc_release_rpi(phba
, vport
, ndlp
, rpi
);
1364 return ndlp
->nlp_state
;
1368 lpfc_device_rm_plogi_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1369 void *arg
, uint32_t evt
)
1371 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1373 if (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) {
1374 spin_lock_irq(shost
->host_lock
);
1375 ndlp
->nlp_flag
|= NLP_NODEV_REMOVE
;
1376 spin_unlock_irq(shost
->host_lock
);
1377 return ndlp
->nlp_state
;
1379 /* software abort outstanding PLOGI */
1380 lpfc_els_abort(vport
->phba
, ndlp
);
1382 lpfc_drop_node(vport
, ndlp
);
1383 return NLP_STE_FREED_NODE
;
1388 lpfc_device_recov_plogi_issue(struct lpfc_vport
*vport
,
1389 struct lpfc_nodelist
*ndlp
,
1393 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1394 struct lpfc_hba
*phba
= vport
->phba
;
1396 /* Don't do anything that will mess up processing of the
1399 if (vport
->fc_flag
& FC_RSCN_DEFERRED
)
1400 return ndlp
->nlp_state
;
1402 /* software abort outstanding PLOGI */
1403 lpfc_els_abort(phba
, ndlp
);
1405 ndlp
->nlp_prev_state
= NLP_STE_PLOGI_ISSUE
;
1406 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1407 spin_lock_irq(shost
->host_lock
);
1408 ndlp
->nlp_flag
&= ~(NLP_NODEV_REMOVE
| NLP_NPR_2B_DISC
);
1409 spin_unlock_irq(shost
->host_lock
);
1411 return ndlp
->nlp_state
;
1415 lpfc_rcv_plogi_adisc_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1416 void *arg
, uint32_t evt
)
1418 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1419 struct lpfc_hba
*phba
= vport
->phba
;
1420 struct lpfc_iocbq
*cmdiocb
;
1422 /* software abort outstanding ADISC */
1423 lpfc_els_abort(phba
, ndlp
);
1425 cmdiocb
= (struct lpfc_iocbq
*) arg
;
1427 if (lpfc_rcv_plogi(vport
, ndlp
, cmdiocb
)) {
1428 if (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) {
1429 spin_lock_irq(shost
->host_lock
);
1430 ndlp
->nlp_flag
&= ~NLP_NPR_2B_DISC
;
1431 spin_unlock_irq(shost
->host_lock
);
1432 if (vport
->num_disc_nodes
)
1433 lpfc_more_adisc(vport
);
1435 return ndlp
->nlp_state
;
1437 ndlp
->nlp_prev_state
= NLP_STE_ADISC_ISSUE
;
1438 lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0);
1439 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
1441 return ndlp
->nlp_state
;
1445 lpfc_rcv_prli_adisc_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1446 void *arg
, uint32_t evt
)
1448 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1450 if (lpfc_rcv_prli_support_check(vport
, ndlp
, cmdiocb
))
1451 lpfc_els_rsp_prli_acc(vport
, cmdiocb
, ndlp
);
1452 return ndlp
->nlp_state
;
1456 lpfc_rcv_logo_adisc_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1457 void *arg
, uint32_t evt
)
1459 struct lpfc_hba
*phba
= vport
->phba
;
1460 struct lpfc_iocbq
*cmdiocb
;
1462 cmdiocb
= (struct lpfc_iocbq
*) arg
;
1464 /* software abort outstanding ADISC */
1465 lpfc_els_abort(phba
, ndlp
);
1467 lpfc_rcv_logo(vport
, ndlp
, cmdiocb
, ELS_CMD_LOGO
);
1468 return ndlp
->nlp_state
;
1472 lpfc_rcv_padisc_adisc_issue(struct lpfc_vport
*vport
,
1473 struct lpfc_nodelist
*ndlp
,
1474 void *arg
, uint32_t evt
)
1476 struct lpfc_iocbq
*cmdiocb
;
1478 cmdiocb
= (struct lpfc_iocbq
*) arg
;
1480 lpfc_rcv_padisc(vport
, ndlp
, cmdiocb
);
1481 return ndlp
->nlp_state
;
1485 lpfc_rcv_prlo_adisc_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1486 void *arg
, uint32_t evt
)
1488 struct lpfc_iocbq
*cmdiocb
;
1490 cmdiocb
= (struct lpfc_iocbq
*) arg
;
1492 /* Treat like rcv logo */
1493 lpfc_rcv_logo(vport
, ndlp
, cmdiocb
, ELS_CMD_PRLO
);
1494 return ndlp
->nlp_state
;
1498 lpfc_cmpl_adisc_adisc_issue(struct lpfc_vport
*vport
,
1499 struct lpfc_nodelist
*ndlp
,
1500 void *arg
, uint32_t evt
)
1502 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1503 struct lpfc_hba
*phba
= vport
->phba
;
1504 struct lpfc_iocbq
*cmdiocb
, *rspiocb
;
1509 cmdiocb
= (struct lpfc_iocbq
*) arg
;
1510 rspiocb
= cmdiocb
->context_un
.rsp_iocb
;
1512 ap
= (ADISC
*)lpfc_check_elscmpl_iocb(phba
, cmdiocb
, rspiocb
);
1513 irsp
= &rspiocb
->iocb
;
1515 if ((irsp
->ulpStatus
) ||
1516 (!lpfc_check_adisc(vport
, ndlp
, &ap
->nodeName
, &ap
->portName
))) {
1518 mod_timer(&ndlp
->nlp_delayfunc
,
1519 jiffies
+ msecs_to_jiffies(1000));
1520 spin_lock_irq(shost
->host_lock
);
1521 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
1522 spin_unlock_irq(shost
->host_lock
);
1523 ndlp
->nlp_last_elscmd
= ELS_CMD_PLOGI
;
1525 memset(&ndlp
->nlp_nodename
, 0, sizeof(struct lpfc_name
));
1526 memset(&ndlp
->nlp_portname
, 0, sizeof(struct lpfc_name
));
1528 ndlp
->nlp_prev_state
= NLP_STE_ADISC_ISSUE
;
1529 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1530 lpfc_unreg_rpi(vport
, ndlp
);
1531 return ndlp
->nlp_state
;
1534 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
1535 rc
= lpfc_sli4_resume_rpi(ndlp
, NULL
, NULL
);
1537 /* Stay in state and retry. */
1538 ndlp
->nlp_prev_state
= NLP_STE_ADISC_ISSUE
;
1539 return ndlp
->nlp_state
;
1543 if (ndlp
->nlp_type
& NLP_FCP_TARGET
) {
1544 ndlp
->nlp_prev_state
= NLP_STE_ADISC_ISSUE
;
1545 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_MAPPED_NODE
);
1547 ndlp
->nlp_prev_state
= NLP_STE_ADISC_ISSUE
;
1548 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
1551 return ndlp
->nlp_state
;
1555 lpfc_device_rm_adisc_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1556 void *arg
, uint32_t evt
)
1558 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1560 if (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) {
1561 spin_lock_irq(shost
->host_lock
);
1562 ndlp
->nlp_flag
|= NLP_NODEV_REMOVE
;
1563 spin_unlock_irq(shost
->host_lock
);
1564 return ndlp
->nlp_state
;
1566 /* software abort outstanding ADISC */
1567 lpfc_els_abort(vport
->phba
, ndlp
);
1569 lpfc_drop_node(vport
, ndlp
);
1570 return NLP_STE_FREED_NODE
;
1575 lpfc_device_recov_adisc_issue(struct lpfc_vport
*vport
,
1576 struct lpfc_nodelist
*ndlp
,
1580 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1581 struct lpfc_hba
*phba
= vport
->phba
;
1583 /* Don't do anything that will mess up processing of the
1586 if (vport
->fc_flag
& FC_RSCN_DEFERRED
)
1587 return ndlp
->nlp_state
;
1589 /* software abort outstanding ADISC */
1590 lpfc_els_abort(phba
, ndlp
);
1592 ndlp
->nlp_prev_state
= NLP_STE_ADISC_ISSUE
;
1593 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1594 spin_lock_irq(shost
->host_lock
);
1595 ndlp
->nlp_flag
&= ~(NLP_NODEV_REMOVE
| NLP_NPR_2B_DISC
);
1596 spin_unlock_irq(shost
->host_lock
);
1597 lpfc_disc_set_adisc(vport
, ndlp
);
1598 return ndlp
->nlp_state
;
1602 lpfc_rcv_plogi_reglogin_issue(struct lpfc_vport
*vport
,
1603 struct lpfc_nodelist
*ndlp
,
1607 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1609 lpfc_rcv_plogi(vport
, ndlp
, cmdiocb
);
1610 return ndlp
->nlp_state
;
1614 lpfc_rcv_prli_reglogin_issue(struct lpfc_vport
*vport
,
1615 struct lpfc_nodelist
*ndlp
,
1619 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1622 if (!lpfc_rcv_prli_support_check(vport
, ndlp
, cmdiocb
)) {
1623 return ndlp
->nlp_state
;
1625 if (vport
->phba
->nvmet_support
) {
1626 /* NVME Target mode. Handle and respond to the PRLI and
1627 * transition to UNMAPPED provided the RPI has completed
1630 if (ndlp
->nlp_flag
& NLP_RPI_REGISTERED
) {
1631 lpfc_rcv_prli(vport
, ndlp
, cmdiocb
);
1632 lpfc_els_rsp_prli_acc(vport
, cmdiocb
, ndlp
);
1634 /* RPI registration has not completed. Reject the PRLI
1635 * to prevent an illegal state transition when the
1636 * rpi registration does complete.
1638 memset(&stat
, 0, sizeof(struct ls_rjt
));
1639 stat
.un
.b
.lsRjtRsnCode
= LSRJT_LOGICAL_BSY
;
1640 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_NOTHING_MORE
;
1641 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
,
1643 return ndlp
->nlp_state
;
1646 /* Initiator mode. */
1647 lpfc_els_rsp_prli_acc(vport
, cmdiocb
, ndlp
);
1649 return ndlp
->nlp_state
;
1653 lpfc_rcv_logo_reglogin_issue(struct lpfc_vport
*vport
,
1654 struct lpfc_nodelist
*ndlp
,
1658 struct lpfc_hba
*phba
= vport
->phba
;
1659 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1661 LPFC_MBOXQ_t
*nextmb
;
1662 struct lpfc_dmabuf
*mp
;
1664 cmdiocb
= (struct lpfc_iocbq
*) arg
;
1666 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
1667 if ((mb
= phba
->sli
.mbox_active
)) {
1668 if ((mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) &&
1669 (ndlp
== (struct lpfc_nodelist
*)mb
->ctx_ndlp
)) {
1670 ndlp
->nlp_flag
&= ~NLP_REG_LOGIN_SEND
;
1672 mb
->ctx_ndlp
= NULL
;
1673 mb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
1677 spin_lock_irq(&phba
->hbalock
);
1678 list_for_each_entry_safe(mb
, nextmb
, &phba
->sli
.mboxq
, list
) {
1679 if ((mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) &&
1680 (ndlp
== (struct lpfc_nodelist
*)mb
->ctx_ndlp
)) {
1681 mp
= (struct lpfc_dmabuf
*)(mb
->ctx_buf
);
1683 __lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
1686 ndlp
->nlp_flag
&= ~NLP_REG_LOGIN_SEND
;
1688 list_del(&mb
->list
);
1689 phba
->sli
.mboxq_cnt
--;
1690 mempool_free(mb
, phba
->mbox_mem_pool
);
1693 spin_unlock_irq(&phba
->hbalock
);
1695 lpfc_rcv_logo(vport
, ndlp
, cmdiocb
, ELS_CMD_LOGO
);
1696 return ndlp
->nlp_state
;
1700 lpfc_rcv_padisc_reglogin_issue(struct lpfc_vport
*vport
,
1701 struct lpfc_nodelist
*ndlp
,
1705 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1707 lpfc_rcv_padisc(vport
, ndlp
, cmdiocb
);
1708 return ndlp
->nlp_state
;
1712 lpfc_rcv_prlo_reglogin_issue(struct lpfc_vport
*vport
,
1713 struct lpfc_nodelist
*ndlp
,
1717 struct lpfc_iocbq
*cmdiocb
;
1719 cmdiocb
= (struct lpfc_iocbq
*) arg
;
1720 lpfc_els_rsp_acc(vport
, ELS_CMD_PRLO
, cmdiocb
, ndlp
, NULL
);
1721 return ndlp
->nlp_state
;
1725 lpfc_cmpl_reglogin_reglogin_issue(struct lpfc_vport
*vport
,
1726 struct lpfc_nodelist
*ndlp
,
1730 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1731 struct lpfc_hba
*phba
= vport
->phba
;
1732 LPFC_MBOXQ_t
*pmb
= (LPFC_MBOXQ_t
*) arg
;
1733 MAILBOX_t
*mb
= &pmb
->u
.mb
;
1734 uint32_t did
= mb
->un
.varWords
[1];
1737 if (mb
->mbxStatus
) {
1738 /* RegLogin failed */
1739 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
1740 "0246 RegLogin failed Data: x%x x%x x%x x%x "
1742 did
, mb
->mbxStatus
, vport
->port_state
,
1743 mb
->un
.varRegLogin
.vpi
,
1744 mb
->un
.varRegLogin
.rpi
);
1746 * If RegLogin failed due to lack of HBA resources do not
1749 if (mb
->mbxStatus
== MBXERR_RPI_FULL
) {
1750 ndlp
->nlp_prev_state
= NLP_STE_REG_LOGIN_ISSUE
;
1751 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1752 return ndlp
->nlp_state
;
1755 /* Put ndlp in npr state set plogi timer for 1 sec */
1756 mod_timer(&ndlp
->nlp_delayfunc
,
1757 jiffies
+ msecs_to_jiffies(1000 * 1));
1758 spin_lock_irq(shost
->host_lock
);
1759 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
1760 spin_unlock_irq(shost
->host_lock
);
1761 ndlp
->nlp_last_elscmd
= ELS_CMD_PLOGI
;
1763 lpfc_issue_els_logo(vport
, ndlp
, 0);
1764 ndlp
->nlp_prev_state
= NLP_STE_REG_LOGIN_ISSUE
;
1765 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1766 return ndlp
->nlp_state
;
1769 /* SLI4 ports have preallocated logical rpis. */
1770 if (phba
->sli_rev
< LPFC_SLI_REV4
)
1771 ndlp
->nlp_rpi
= mb
->un
.varWords
[0];
1773 ndlp
->nlp_flag
|= NLP_RPI_REGISTERED
;
1775 /* Only if we are not a fabric nport do we issue PRLI */
1776 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
1777 "3066 RegLogin Complete on x%x x%x x%x\n",
1778 did
, ndlp
->nlp_type
, ndlp
->nlp_fc4_type
);
1779 if (!(ndlp
->nlp_type
& NLP_FABRIC
) &&
1780 (phba
->nvmet_support
== 0)) {
1781 /* The driver supports FCP and NVME concurrently. If the
1782 * ndlp's nlp_fc4_type is still zero, the driver doesn't
1783 * know what PRLI to send yet. Figure that out now and
1784 * call PRLI depending on the outcome.
1786 if (vport
->fc_flag
& FC_PT2PT
) {
1787 /* If we are pt2pt, there is no Fabric to determine
1788 * the FC4 type of the remote nport. So if NVME
1789 * is configured try it.
1791 ndlp
->nlp_fc4_type
|= NLP_FC4_FCP
;
1792 if ((phba
->cfg_enable_fc4_type
== LPFC_ENABLE_BOTH
) ||
1793 (phba
->cfg_enable_fc4_type
== LPFC_ENABLE_NVME
)) {
1794 ndlp
->nlp_fc4_type
|= NLP_FC4_NVME
;
1795 /* We need to update the localport also */
1796 lpfc_nvme_update_localport(vport
);
1799 } else if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) {
1800 ndlp
->nlp_fc4_type
|= NLP_FC4_FCP
;
1802 } else if (ndlp
->nlp_fc4_type
== 0) {
1803 /* If we are only configured for FCP, the driver
1804 * should just issue PRLI for FCP. Otherwise issue
1805 * GFT_ID to determine if remote port supports NVME.
1807 if (phba
->cfg_enable_fc4_type
!= LPFC_ENABLE_FCP
) {
1808 rc
= lpfc_ns_cmd(vport
, SLI_CTNS_GFT_ID
,
1810 return ndlp
->nlp_state
;
1812 ndlp
->nlp_fc4_type
= NLP_FC4_FCP
;
1815 ndlp
->nlp_prev_state
= NLP_STE_REG_LOGIN_ISSUE
;
1816 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PRLI_ISSUE
);
1817 lpfc_issue_els_prli(vport
, ndlp
, 0);
1819 if ((vport
->fc_flag
& FC_PT2PT
) && phba
->nvmet_support
)
1820 phba
->targetport
->port_id
= vport
->fc_myDID
;
1822 /* Only Fabric ports should transition. NVME target
1823 * must complete PRLI.
1825 if (ndlp
->nlp_type
& NLP_FABRIC
) {
1826 ndlp
->nlp_prev_state
= NLP_STE_REG_LOGIN_ISSUE
;
1827 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
1830 return ndlp
->nlp_state
;
1834 lpfc_device_rm_reglogin_issue(struct lpfc_vport
*vport
,
1835 struct lpfc_nodelist
*ndlp
,
1839 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1841 if (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) {
1842 spin_lock_irq(shost
->host_lock
);
1843 ndlp
->nlp_flag
|= NLP_NODEV_REMOVE
;
1844 spin_unlock_irq(shost
->host_lock
);
1845 return ndlp
->nlp_state
;
1847 lpfc_drop_node(vport
, ndlp
);
1848 return NLP_STE_FREED_NODE
;
1853 lpfc_device_recov_reglogin_issue(struct lpfc_vport
*vport
,
1854 struct lpfc_nodelist
*ndlp
,
1858 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1860 /* Don't do anything that will mess up processing of the
1863 if (vport
->fc_flag
& FC_RSCN_DEFERRED
)
1864 return ndlp
->nlp_state
;
1866 ndlp
->nlp_prev_state
= NLP_STE_REG_LOGIN_ISSUE
;
1867 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1868 spin_lock_irq(shost
->host_lock
);
1870 /* If we are a target we won't immediately transition into PRLI,
1871 * so if REG_LOGIN already completed we don't need to ignore it.
1873 if (!(ndlp
->nlp_flag
& NLP_RPI_REGISTERED
) ||
1874 !vport
->phba
->nvmet_support
)
1875 ndlp
->nlp_flag
|= NLP_IGNR_REG_CMPL
;
1877 ndlp
->nlp_flag
&= ~(NLP_NODEV_REMOVE
| NLP_NPR_2B_DISC
);
1878 spin_unlock_irq(shost
->host_lock
);
1879 lpfc_disc_set_adisc(vport
, ndlp
);
1880 return ndlp
->nlp_state
;
1884 lpfc_rcv_plogi_prli_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1885 void *arg
, uint32_t evt
)
1887 struct lpfc_iocbq
*cmdiocb
;
1889 cmdiocb
= (struct lpfc_iocbq
*) arg
;
1891 lpfc_rcv_plogi(vport
, ndlp
, cmdiocb
);
1892 return ndlp
->nlp_state
;
1896 lpfc_rcv_prli_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 if (!lpfc_rcv_prli_support_check(vport
, ndlp
, cmdiocb
))
1902 return ndlp
->nlp_state
;
1903 lpfc_els_rsp_prli_acc(vport
, cmdiocb
, ndlp
);
1904 return ndlp
->nlp_state
;
1908 lpfc_rcv_logo_prli_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1909 void *arg
, uint32_t evt
)
1911 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1913 /* Software abort outstanding PRLI before sending acc */
1914 lpfc_els_abort(vport
->phba
, ndlp
);
1916 lpfc_rcv_logo(vport
, ndlp
, cmdiocb
, ELS_CMD_LOGO
);
1917 return ndlp
->nlp_state
;
1921 lpfc_rcv_padisc_prli_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1922 void *arg
, uint32_t evt
)
1924 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1926 lpfc_rcv_padisc(vport
, ndlp
, cmdiocb
);
1927 return ndlp
->nlp_state
;
1930 /* This routine is envoked when we rcv a PRLO request from a nport
1931 * we are logged into. We should send back a PRLO rsp setting the
1933 * NEXT STATE = PRLI_ISSUE
1936 lpfc_rcv_prlo_prli_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1937 void *arg
, uint32_t evt
)
1939 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1941 lpfc_els_rsp_acc(vport
, ELS_CMD_PRLO
, cmdiocb
, ndlp
, NULL
);
1942 return ndlp
->nlp_state
;
1946 lpfc_cmpl_prli_prli_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1947 void *arg
, uint32_t evt
)
1949 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1950 struct lpfc_iocbq
*cmdiocb
, *rspiocb
;
1951 struct lpfc_hba
*phba
= vport
->phba
;
1954 struct lpfc_nvme_prli
*nvpr
;
1957 cmdiocb
= (struct lpfc_iocbq
*) arg
;
1958 rspiocb
= cmdiocb
->context_un
.rsp_iocb
;
1960 /* A solicited PRLI is either FCP or NVME. The PRLI cmd/rsp
1961 * format is different so NULL the two PRLI types so that the
1962 * driver correctly gets the correct context.
1966 temp_ptr
= lpfc_check_elscmpl_iocb(phba
, cmdiocb
, rspiocb
);
1967 if (cmdiocb
->iocb_flag
& LPFC_PRLI_FCP_REQ
)
1968 npr
= (PRLI
*) temp_ptr
;
1969 else if (cmdiocb
->iocb_flag
& LPFC_PRLI_NVME_REQ
)
1970 nvpr
= (struct lpfc_nvme_prli
*) temp_ptr
;
1972 irsp
= &rspiocb
->iocb
;
1973 if (irsp
->ulpStatus
) {
1974 if ((vport
->port_type
== LPFC_NPIV_PORT
) &&
1975 vport
->cfg_restrict_login
) {
1979 /* Adjust the nlp_type accordingly if the PRLI failed */
1981 ndlp
->nlp_fc4_type
&= ~NLP_FC4_FCP
;
1983 ndlp
->nlp_fc4_type
&= ~NLP_FC4_NVME
;
1985 /* We can't set the DSM state till BOTH PRLIs complete */
1989 if (npr
&& (npr
->acceptRspCode
== PRLI_REQ_EXECUTED
) &&
1990 (npr
->prliType
== PRLI_FCP_TYPE
)) {
1991 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NVME_DISC
,
1992 "6028 FCP NPR PRLI Cmpl Init %d Target %d\n",
1995 if (npr
->initiatorFunc
)
1996 ndlp
->nlp_type
|= NLP_FCP_INITIATOR
;
1997 if (npr
->targetFunc
) {
1998 ndlp
->nlp_type
|= NLP_FCP_TARGET
;
1999 if (npr
->writeXferRdyDis
)
2000 ndlp
->nlp_flag
|= NLP_FIRSTBURST
;
2003 ndlp
->nlp_fcp_info
|= NLP_FCP_2_DEVICE
;
2006 (bf_get_be32(prli_acc_rsp_code
, nvpr
) ==
2007 PRLI_REQ_EXECUTED
) &&
2008 (bf_get_be32(prli_type_code
, nvpr
) ==
2011 /* Complete setting up the remote ndlp personality. */
2012 if (bf_get_be32(prli_init
, nvpr
))
2013 ndlp
->nlp_type
|= NLP_NVME_INITIATOR
;
2015 /* Target driver cannot solicit NVME FB. */
2016 if (bf_get_be32(prli_tgt
, nvpr
)) {
2017 /* Complete the nvme target roles. The transport
2018 * needs to know if the rport is capable of
2019 * discovery in addition to its role.
2021 ndlp
->nlp_type
|= NLP_NVME_TARGET
;
2022 if (bf_get_be32(prli_disc
, nvpr
))
2023 ndlp
->nlp_type
|= NLP_NVME_DISCOVERY
;
2026 * If prli_fba is set, the Target supports FirstBurst.
2027 * If prli_fb_sz is 0, the FirstBurst size is unlimited,
2028 * otherwise it defines the actual size supported by
2031 if ((bf_get_be32(prli_fba
, nvpr
) == 1) &&
2032 (phba
->cfg_nvme_enable_fb
) &&
2033 (!phba
->nvmet_support
)) {
2034 /* Both sides support FB. The target's first
2035 * burst size is a 512 byte encoded value.
2037 ndlp
->nlp_flag
|= NLP_FIRSTBURST
;
2038 ndlp
->nvme_fb_size
= bf_get_be32(prli_fb_sz
,
2041 /* Expressed in units of 512 bytes */
2042 if (ndlp
->nvme_fb_size
)
2043 ndlp
->nvme_fb_size
<<=
2046 ndlp
->nvme_fb_size
= LPFC_NVME_MAX_FB
;
2050 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NVME_DISC
,
2051 "6029 NVME PRLI Cmpl w1 x%08x "
2052 "w4 x%08x w5 x%08x flag x%x, "
2053 "fcp_info x%x nlp_type x%x\n",
2054 be32_to_cpu(nvpr
->word1
),
2055 be32_to_cpu(nvpr
->word4
),
2056 be32_to_cpu(nvpr
->word5
),
2057 ndlp
->nlp_flag
, ndlp
->nlp_fcp_info
,
2060 if (!(ndlp
->nlp_type
& NLP_FCP_TARGET
) &&
2061 (vport
->port_type
== LPFC_NPIV_PORT
) &&
2062 vport
->cfg_restrict_login
) {
2064 spin_lock_irq(shost
->host_lock
);
2065 ndlp
->nlp_flag
|= NLP_TARGET_REMOVE
;
2066 spin_unlock_irq(shost
->host_lock
);
2067 lpfc_issue_els_logo(vport
, ndlp
, 0);
2069 ndlp
->nlp_prev_state
= NLP_STE_PRLI_ISSUE
;
2070 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
2071 return ndlp
->nlp_state
;
2075 /* The ndlp state cannot move to MAPPED or UNMAPPED before all PRLIs
2078 if (ndlp
->fc4_prli_sent
== 0) {
2079 ndlp
->nlp_prev_state
= NLP_STE_PRLI_ISSUE
;
2080 if (ndlp
->nlp_type
& (NLP_FCP_TARGET
| NLP_NVME_TARGET
))
2081 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_MAPPED_NODE
);
2082 else if (ndlp
->nlp_type
&
2083 (NLP_FCP_INITIATOR
| NLP_NVME_INITIATOR
))
2084 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
2086 lpfc_printf_vlog(vport
,
2088 "3067 PRLI's still outstanding "
2089 "on x%06x - count %d, Pend Node Mode "
2091 ndlp
->nlp_DID
, ndlp
->fc4_prli_sent
);
2093 return ndlp
->nlp_state
;
2096 /*! lpfc_device_rm_prli_issue
2107 * This routine is envoked when we a request to remove a nport we are in the
2108 * process of PRLIing. We should software abort outstanding prli, unreg
2109 * login, send a logout. We will change node state to UNUSED_NODE, put it
2110 * on plogi list so it can be freed when LOGO completes.
2115 lpfc_device_rm_prli_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2116 void *arg
, uint32_t evt
)
2118 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2120 if (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) {
2121 spin_lock_irq(shost
->host_lock
);
2122 ndlp
->nlp_flag
|= NLP_NODEV_REMOVE
;
2123 spin_unlock_irq(shost
->host_lock
);
2124 return ndlp
->nlp_state
;
2126 /* software abort outstanding PLOGI */
2127 lpfc_els_abort(vport
->phba
, ndlp
);
2129 lpfc_drop_node(vport
, ndlp
);
2130 return NLP_STE_FREED_NODE
;
2135 /*! lpfc_device_recov_prli_issue
2146 * The routine is envoked when the state of a device is unknown, like
2147 * during a link down. We should remove the nodelist entry from the
2148 * unmapped list, issue a UNREG_LOGIN, do a software abort of the
2149 * outstanding PRLI command, then free the node entry.
2152 lpfc_device_recov_prli_issue(struct lpfc_vport
*vport
,
2153 struct lpfc_nodelist
*ndlp
,
2157 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2158 struct lpfc_hba
*phba
= vport
->phba
;
2160 /* Don't do anything that will mess up processing of the
2163 if (vport
->fc_flag
& FC_RSCN_DEFERRED
)
2164 return ndlp
->nlp_state
;
2166 /* software abort outstanding PRLI */
2167 lpfc_els_abort(phba
, ndlp
);
2169 ndlp
->nlp_prev_state
= NLP_STE_PRLI_ISSUE
;
2170 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
2171 spin_lock_irq(shost
->host_lock
);
2172 ndlp
->nlp_flag
&= ~(NLP_NODEV_REMOVE
| NLP_NPR_2B_DISC
);
2173 spin_unlock_irq(shost
->host_lock
);
2174 lpfc_disc_set_adisc(vport
, ndlp
);
2175 return ndlp
->nlp_state
;
2179 lpfc_rcv_plogi_logo_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2180 void *arg
, uint32_t evt
)
2182 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*)arg
;
2185 memset(&stat
, 0, sizeof(struct ls_rjt
));
2186 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
2187 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_NOTHING_MORE
;
2188 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
2189 return ndlp
->nlp_state
;
2193 lpfc_rcv_prli_logo_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2194 void *arg
, uint32_t evt
)
2196 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*)arg
;
2199 memset(&stat
, 0, sizeof(struct ls_rjt
));
2200 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
2201 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_NOTHING_MORE
;
2202 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
2203 return ndlp
->nlp_state
;
2207 lpfc_rcv_logo_logo_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2208 void *arg
, uint32_t evt
)
2210 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2211 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*)arg
;
2213 spin_lock_irq(shost
->host_lock
);
2214 ndlp
->nlp_flag
|= NLP_LOGO_ACC
;
2215 spin_unlock_irq(shost
->host_lock
);
2216 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
2217 return ndlp
->nlp_state
;
2221 lpfc_rcv_padisc_logo_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2222 void *arg
, uint32_t evt
)
2224 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*)arg
;
2227 memset(&stat
, 0, sizeof(struct ls_rjt
));
2228 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
2229 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_NOTHING_MORE
;
2230 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
2231 return ndlp
->nlp_state
;
2235 lpfc_rcv_prlo_logo_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2236 void *arg
, uint32_t evt
)
2238 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*)arg
;
2241 memset(&stat
, 0, sizeof(struct ls_rjt
));
2242 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
2243 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_NOTHING_MORE
;
2244 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
2245 return ndlp
->nlp_state
;
2249 lpfc_cmpl_logo_logo_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2250 void *arg
, uint32_t evt
)
2252 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2254 ndlp
->nlp_prev_state
= NLP_STE_LOGO_ISSUE
;
2255 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
2256 spin_lock_irq(shost
->host_lock
);
2257 ndlp
->nlp_flag
&= ~(NLP_NODEV_REMOVE
| NLP_NPR_2B_DISC
);
2258 spin_unlock_irq(shost
->host_lock
);
2259 lpfc_disc_set_adisc(vport
, ndlp
);
2260 return ndlp
->nlp_state
;
2264 lpfc_device_rm_logo_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2265 void *arg
, uint32_t evt
)
2268 * DevLoss has timed out and is calling for Device Remove.
2269 * In this case, abort the LOGO and cleanup the ndlp
2272 lpfc_unreg_rpi(vport
, ndlp
);
2273 /* software abort outstanding PLOGI */
2274 lpfc_els_abort(vport
->phba
, ndlp
);
2275 lpfc_drop_node(vport
, ndlp
);
2276 return NLP_STE_FREED_NODE
;
2280 lpfc_device_recov_logo_issue(struct lpfc_vport
*vport
,
2281 struct lpfc_nodelist
*ndlp
,
2282 void *arg
, uint32_t evt
)
2285 * Device Recovery events have no meaning for a node with a LOGO
2286 * outstanding. The LOGO has to complete first and handle the
2287 * node from that point.
2289 return ndlp
->nlp_state
;
2293 lpfc_rcv_plogi_unmap_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2294 void *arg
, uint32_t evt
)
2296 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2298 lpfc_rcv_plogi(vport
, ndlp
, cmdiocb
);
2299 return ndlp
->nlp_state
;
2303 lpfc_rcv_prli_unmap_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2304 void *arg
, uint32_t evt
)
2306 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2308 if (!lpfc_rcv_prli_support_check(vport
, ndlp
, cmdiocb
))
2309 return ndlp
->nlp_state
;
2311 lpfc_rcv_prli(vport
, ndlp
, cmdiocb
);
2312 lpfc_els_rsp_prli_acc(vport
, cmdiocb
, ndlp
);
2313 return ndlp
->nlp_state
;
2317 lpfc_rcv_logo_unmap_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2318 void *arg
, uint32_t evt
)
2320 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2322 lpfc_rcv_logo(vport
, ndlp
, cmdiocb
, ELS_CMD_LOGO
);
2323 return ndlp
->nlp_state
;
2327 lpfc_rcv_padisc_unmap_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2328 void *arg
, uint32_t evt
)
2330 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2332 lpfc_rcv_padisc(vport
, ndlp
, cmdiocb
);
2333 return ndlp
->nlp_state
;
2337 lpfc_rcv_prlo_unmap_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2338 void *arg
, uint32_t evt
)
2340 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2342 lpfc_els_rsp_acc(vport
, ELS_CMD_PRLO
, cmdiocb
, ndlp
, NULL
);
2343 return ndlp
->nlp_state
;
2347 lpfc_device_recov_unmap_node(struct lpfc_vport
*vport
,
2348 struct lpfc_nodelist
*ndlp
,
2352 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2354 ndlp
->nlp_prev_state
= NLP_STE_UNMAPPED_NODE
;
2355 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
2356 spin_lock_irq(shost
->host_lock
);
2357 ndlp
->nlp_flag
&= ~(NLP_NODEV_REMOVE
| NLP_NPR_2B_DISC
);
2358 ndlp
->nlp_fc4_type
&= ~(NLP_FC4_FCP
| NLP_FC4_NVME
);
2359 spin_unlock_irq(shost
->host_lock
);
2360 lpfc_disc_set_adisc(vport
, ndlp
);
2362 return ndlp
->nlp_state
;
2366 lpfc_rcv_plogi_mapped_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2367 void *arg
, uint32_t evt
)
2369 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2371 lpfc_rcv_plogi(vport
, ndlp
, cmdiocb
);
2372 return ndlp
->nlp_state
;
2376 lpfc_rcv_prli_mapped_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2377 void *arg
, uint32_t evt
)
2379 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2381 if (!lpfc_rcv_prli_support_check(vport
, ndlp
, cmdiocb
))
2382 return ndlp
->nlp_state
;
2383 lpfc_els_rsp_prli_acc(vport
, cmdiocb
, ndlp
);
2384 return ndlp
->nlp_state
;
2388 lpfc_rcv_logo_mapped_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2389 void *arg
, uint32_t evt
)
2391 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2393 lpfc_rcv_logo(vport
, ndlp
, cmdiocb
, ELS_CMD_LOGO
);
2394 return ndlp
->nlp_state
;
2398 lpfc_rcv_padisc_mapped_node(struct lpfc_vport
*vport
,
2399 struct lpfc_nodelist
*ndlp
,
2400 void *arg
, uint32_t evt
)
2402 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2404 lpfc_rcv_padisc(vport
, ndlp
, cmdiocb
);
2405 return ndlp
->nlp_state
;
2409 lpfc_rcv_prlo_mapped_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2410 void *arg
, uint32_t evt
)
2412 struct lpfc_hba
*phba
= vport
->phba
;
2413 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2415 /* flush the target */
2416 lpfc_sli_abort_iocb(vport
, &phba
->sli
.sli3_ring
[LPFC_FCP_RING
],
2417 ndlp
->nlp_sid
, 0, LPFC_CTX_TGT
);
2419 /* Treat like rcv logo */
2420 lpfc_rcv_logo(vport
, ndlp
, cmdiocb
, ELS_CMD_PRLO
);
2421 return ndlp
->nlp_state
;
2425 lpfc_device_recov_mapped_node(struct lpfc_vport
*vport
,
2426 struct lpfc_nodelist
*ndlp
,
2430 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2432 ndlp
->nlp_prev_state
= NLP_STE_MAPPED_NODE
;
2433 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
2434 spin_lock_irq(shost
->host_lock
);
2435 ndlp
->nlp_flag
&= ~(NLP_NODEV_REMOVE
| NLP_NPR_2B_DISC
);
2436 ndlp
->nlp_fc4_type
&= ~(NLP_FC4_FCP
| NLP_FC4_NVME
);
2437 spin_unlock_irq(shost
->host_lock
);
2438 lpfc_disc_set_adisc(vport
, ndlp
);
2439 return ndlp
->nlp_state
;
2443 lpfc_rcv_plogi_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2444 void *arg
, uint32_t evt
)
2446 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2447 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2449 /* Ignore PLOGI if we have an outstanding LOGO */
2450 if (ndlp
->nlp_flag
& (NLP_LOGO_SND
| NLP_LOGO_ACC
))
2451 return ndlp
->nlp_state
;
2452 if (lpfc_rcv_plogi(vport
, ndlp
, cmdiocb
)) {
2453 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
2454 spin_lock_irq(shost
->host_lock
);
2455 ndlp
->nlp_flag
&= ~(NLP_NPR_ADISC
| NLP_NPR_2B_DISC
);
2456 spin_unlock_irq(shost
->host_lock
);
2457 } else if (!(ndlp
->nlp_flag
& NLP_NPR_2B_DISC
)) {
2458 /* send PLOGI immediately, move to PLOGI issue state */
2459 if (!(ndlp
->nlp_flag
& NLP_DELAY_TMO
)) {
2460 ndlp
->nlp_prev_state
= NLP_STE_NPR_NODE
;
2461 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
2462 lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0);
2465 return ndlp
->nlp_state
;
2469 lpfc_rcv_prli_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2470 void *arg
, uint32_t evt
)
2472 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2473 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2476 memset(&stat
, 0, sizeof (struct ls_rjt
));
2477 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
2478 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_NOTHING_MORE
;
2479 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
2481 if (!(ndlp
->nlp_flag
& NLP_DELAY_TMO
)) {
2482 if (ndlp
->nlp_flag
& NLP_NPR_ADISC
) {
2483 spin_lock_irq(shost
->host_lock
);
2484 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
2485 ndlp
->nlp_prev_state
= NLP_STE_NPR_NODE
;
2486 spin_unlock_irq(shost
->host_lock
);
2487 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_ADISC_ISSUE
);
2488 lpfc_issue_els_adisc(vport
, ndlp
, 0);
2490 ndlp
->nlp_prev_state
= NLP_STE_NPR_NODE
;
2491 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
2492 lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0);
2495 return ndlp
->nlp_state
;
2499 lpfc_rcv_logo_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2500 void *arg
, uint32_t evt
)
2502 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2504 lpfc_rcv_logo(vport
, ndlp
, cmdiocb
, ELS_CMD_LOGO
);
2505 return ndlp
->nlp_state
;
2509 lpfc_rcv_padisc_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2510 void *arg
, uint32_t evt
)
2512 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2514 lpfc_rcv_padisc(vport
, ndlp
, cmdiocb
);
2516 * Do not start discovery if discovery is about to start
2517 * or discovery in progress for this node. Starting discovery
2518 * here will affect the counting of discovery threads.
2520 if (!(ndlp
->nlp_flag
& NLP_DELAY_TMO
) &&
2521 !(ndlp
->nlp_flag
& NLP_NPR_2B_DISC
)) {
2522 if (ndlp
->nlp_flag
& NLP_NPR_ADISC
) {
2523 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
2524 ndlp
->nlp_prev_state
= NLP_STE_NPR_NODE
;
2525 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_ADISC_ISSUE
);
2526 lpfc_issue_els_adisc(vport
, ndlp
, 0);
2528 ndlp
->nlp_prev_state
= NLP_STE_NPR_NODE
;
2529 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
2530 lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0);
2533 return ndlp
->nlp_state
;
2537 lpfc_rcv_prlo_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2538 void *arg
, uint32_t evt
)
2540 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2541 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2543 spin_lock_irq(shost
->host_lock
);
2544 ndlp
->nlp_flag
|= NLP_LOGO_ACC
;
2545 spin_unlock_irq(shost
->host_lock
);
2547 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
2549 if ((ndlp
->nlp_flag
& NLP_DELAY_TMO
) == 0) {
2550 mod_timer(&ndlp
->nlp_delayfunc
,
2551 jiffies
+ msecs_to_jiffies(1000 * 1));
2552 spin_lock_irq(shost
->host_lock
);
2553 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
2554 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
2555 spin_unlock_irq(shost
->host_lock
);
2556 ndlp
->nlp_last_elscmd
= ELS_CMD_PLOGI
;
2558 spin_lock_irq(shost
->host_lock
);
2559 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
2560 spin_unlock_irq(shost
->host_lock
);
2562 return ndlp
->nlp_state
;
2566 lpfc_cmpl_plogi_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2567 void *arg
, uint32_t evt
)
2569 struct lpfc_iocbq
*cmdiocb
, *rspiocb
;
2571 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2573 cmdiocb
= (struct lpfc_iocbq
*) arg
;
2574 rspiocb
= cmdiocb
->context_un
.rsp_iocb
;
2576 irsp
= &rspiocb
->iocb
;
2577 if (irsp
->ulpStatus
) {
2578 spin_lock_irq(shost
->host_lock
);
2579 ndlp
->nlp_flag
|= NLP_DEFER_RM
;
2580 spin_unlock_irq(shost
->host_lock
);
2581 return NLP_STE_FREED_NODE
;
2583 return ndlp
->nlp_state
;
2587 lpfc_cmpl_prli_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2588 void *arg
, uint32_t evt
)
2590 struct lpfc_iocbq
*cmdiocb
, *rspiocb
;
2593 cmdiocb
= (struct lpfc_iocbq
*) arg
;
2594 rspiocb
= cmdiocb
->context_un
.rsp_iocb
;
2596 irsp
= &rspiocb
->iocb
;
2597 if (irsp
->ulpStatus
&& (ndlp
->nlp_flag
& NLP_NODEV_REMOVE
)) {
2598 lpfc_drop_node(vport
, ndlp
);
2599 return NLP_STE_FREED_NODE
;
2601 return ndlp
->nlp_state
;
2605 lpfc_cmpl_logo_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2606 void *arg
, uint32_t evt
)
2608 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2610 /* For the fabric port just clear the fc flags. */
2611 if (ndlp
->nlp_DID
== Fabric_DID
) {
2612 spin_lock_irq(shost
->host_lock
);
2613 vport
->fc_flag
&= ~(FC_FABRIC
| FC_PUBLIC_LOOP
);
2614 spin_unlock_irq(shost
->host_lock
);
2616 lpfc_unreg_rpi(vport
, ndlp
);
2617 return ndlp
->nlp_state
;
2621 lpfc_cmpl_adisc_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2622 void *arg
, uint32_t evt
)
2624 struct lpfc_iocbq
*cmdiocb
, *rspiocb
;
2627 cmdiocb
= (struct lpfc_iocbq
*) arg
;
2628 rspiocb
= cmdiocb
->context_un
.rsp_iocb
;
2630 irsp
= &rspiocb
->iocb
;
2631 if (irsp
->ulpStatus
&& (ndlp
->nlp_flag
& NLP_NODEV_REMOVE
)) {
2632 lpfc_drop_node(vport
, ndlp
);
2633 return NLP_STE_FREED_NODE
;
2635 return ndlp
->nlp_state
;
2639 lpfc_cmpl_reglogin_npr_node(struct lpfc_vport
*vport
,
2640 struct lpfc_nodelist
*ndlp
,
2641 void *arg
, uint32_t evt
)
2643 LPFC_MBOXQ_t
*pmb
= (LPFC_MBOXQ_t
*) arg
;
2644 MAILBOX_t
*mb
= &pmb
->u
.mb
;
2646 if (!mb
->mbxStatus
) {
2647 /* SLI4 ports have preallocated logical rpis. */
2648 if (vport
->phba
->sli_rev
< LPFC_SLI_REV4
)
2649 ndlp
->nlp_rpi
= mb
->un
.varWords
[0];
2650 ndlp
->nlp_flag
|= NLP_RPI_REGISTERED
;
2651 if (ndlp
->nlp_flag
& NLP_LOGO_ACC
) {
2652 lpfc_unreg_rpi(vport
, ndlp
);
2655 if (ndlp
->nlp_flag
& NLP_NODEV_REMOVE
) {
2656 lpfc_drop_node(vport
, ndlp
);
2657 return NLP_STE_FREED_NODE
;
2660 return ndlp
->nlp_state
;
2664 lpfc_device_rm_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2665 void *arg
, uint32_t evt
)
2667 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2669 if (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) {
2670 spin_lock_irq(shost
->host_lock
);
2671 ndlp
->nlp_flag
|= NLP_NODEV_REMOVE
;
2672 spin_unlock_irq(shost
->host_lock
);
2673 return ndlp
->nlp_state
;
2675 lpfc_drop_node(vport
, ndlp
);
2676 return NLP_STE_FREED_NODE
;
2680 lpfc_device_recov_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2681 void *arg
, uint32_t evt
)
2683 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2685 /* Don't do anything that will mess up processing of the
2688 if (vport
->fc_flag
& FC_RSCN_DEFERRED
)
2689 return ndlp
->nlp_state
;
2691 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
2692 spin_lock_irq(shost
->host_lock
);
2693 ndlp
->nlp_flag
&= ~(NLP_NODEV_REMOVE
| NLP_NPR_2B_DISC
);
2694 ndlp
->nlp_fc4_type
&= ~(NLP_FC4_FCP
| NLP_FC4_NVME
);
2695 spin_unlock_irq(shost
->host_lock
);
2696 return ndlp
->nlp_state
;
2700 /* This next section defines the NPort Discovery State Machine */
2702 /* There are 4 different double linked lists nodelist entries can reside on.
2703 * The plogi list and adisc list are used when Link Up discovery or RSCN
2704 * processing is needed. Each list holds the nodes that we will send PLOGI
2705 * or ADISC on. These lists will keep track of what nodes will be effected
2706 * by an RSCN, or a Link Up (Typically, all nodes are effected on Link Up).
2707 * The unmapped_list will contain all nodes that we have successfully logged
2708 * into at the Fibre Channel level. The mapped_list will contain all nodes
2709 * that are mapped FCP targets.
2712 * The bind list is a list of undiscovered (potentially non-existent) nodes
2713 * that we have saved binding information on. This information is used when
2714 * nodes transition from the unmapped to the mapped list.
2716 /* For UNUSED_NODE state, the node has just been allocated .
2717 * For PLOGI_ISSUE and REG_LOGIN_ISSUE, the node is on
2718 * the PLOGI list. For REG_LOGIN_COMPL, the node is taken off the PLOGI list
2719 * and put on the unmapped list. For ADISC processing, the node is taken off
2720 * the ADISC list and placed on either the mapped or unmapped list (depending
2721 * on its previous state). Once on the unmapped list, a PRLI is issued and the
2722 * state changed to PRLI_ISSUE. When the PRLI completion occurs, the state is
2723 * changed to UNMAPPED_NODE. If the completion indicates a mapped
2724 * node, the node is taken off the unmapped list. The binding list is checked
2725 * for a valid binding, or a binding is automatically assigned. If binding
2726 * assignment is unsuccessful, the node is left on the unmapped list. If
2727 * binding assignment is successful, the associated binding list entry (if
2728 * any) is removed, and the node is placed on the mapped list.
2731 * For a Link Down, all nodes on the ADISC, PLOGI, unmapped or mapped
2732 * lists will receive a DEVICE_RECOVERY event. If the linkdown or devloss timers
2733 * expire, all effected nodes will receive a DEVICE_RM event.
2736 * For a Link Up or RSCN, all nodes will move from the mapped / unmapped lists
2737 * to either the ADISC or PLOGI list. After a Nameserver query or ALPA loopmap
2738 * check, additional nodes may be added or removed (via DEVICE_RM) to / from
2739 * the PLOGI or ADISC lists. Once the PLOGI and ADISC lists are populated,
2740 * we will first process the ADISC list. 32 entries are processed initially and
2741 * ADISC is initited for each one. Completions / Events for each node are
2742 * funnelled thru the state machine. As each node finishes ADISC processing, it
2743 * starts ADISC for any nodes waiting for ADISC processing. If no nodes are
2744 * waiting, and the ADISC list count is identically 0, then we are done. For
2745 * Link Up discovery, since all nodes on the PLOGI list are UNREG_LOGIN'ed, we
2746 * can issue a CLEAR_LA and reenable Link Events. Next we will process the PLOGI
2747 * list. 32 entries are processed initially and PLOGI is initited for each one.
2748 * Completions / Events for each node are funnelled thru the state machine. As
2749 * each node finishes PLOGI processing, it starts PLOGI for any nodes waiting
2750 * for PLOGI processing. If no nodes are waiting, and the PLOGI list count is
2751 * indentically 0, then we are done. We have now completed discovery / RSCN
2752 * handling. Upon completion, ALL nodes should be on either the mapped or
2756 static uint32_t (*lpfc_disc_action
[NLP_STE_MAX_STATE
* NLP_EVT_MAX_EVENT
])
2757 (struct lpfc_vport
*, struct lpfc_nodelist
*, void *, uint32_t) = {
2758 /* Action routine Event Current State */
2759 lpfc_rcv_plogi_unused_node
, /* RCV_PLOGI UNUSED_NODE */
2760 lpfc_rcv_els_unused_node
, /* RCV_PRLI */
2761 lpfc_rcv_logo_unused_node
, /* RCV_LOGO */
2762 lpfc_rcv_els_unused_node
, /* RCV_ADISC */
2763 lpfc_rcv_els_unused_node
, /* RCV_PDISC */
2764 lpfc_rcv_els_unused_node
, /* RCV_PRLO */
2765 lpfc_disc_illegal
, /* CMPL_PLOGI */
2766 lpfc_disc_illegal
, /* CMPL_PRLI */
2767 lpfc_cmpl_logo_unused_node
, /* CMPL_LOGO */
2768 lpfc_disc_illegal
, /* CMPL_ADISC */
2769 lpfc_disc_illegal
, /* CMPL_REG_LOGIN */
2770 lpfc_device_rm_unused_node
, /* DEVICE_RM */
2771 lpfc_device_recov_unused_node
, /* DEVICE_RECOVERY */
2773 lpfc_rcv_plogi_plogi_issue
, /* RCV_PLOGI PLOGI_ISSUE */
2774 lpfc_rcv_prli_plogi_issue
, /* RCV_PRLI */
2775 lpfc_rcv_logo_plogi_issue
, /* RCV_LOGO */
2776 lpfc_rcv_els_plogi_issue
, /* RCV_ADISC */
2777 lpfc_rcv_els_plogi_issue
, /* RCV_PDISC */
2778 lpfc_rcv_els_plogi_issue
, /* RCV_PRLO */
2779 lpfc_cmpl_plogi_plogi_issue
, /* CMPL_PLOGI */
2780 lpfc_disc_illegal
, /* CMPL_PRLI */
2781 lpfc_cmpl_logo_plogi_issue
, /* CMPL_LOGO */
2782 lpfc_disc_illegal
, /* CMPL_ADISC */
2783 lpfc_cmpl_reglogin_plogi_issue
,/* CMPL_REG_LOGIN */
2784 lpfc_device_rm_plogi_issue
, /* DEVICE_RM */
2785 lpfc_device_recov_plogi_issue
, /* DEVICE_RECOVERY */
2787 lpfc_rcv_plogi_adisc_issue
, /* RCV_PLOGI ADISC_ISSUE */
2788 lpfc_rcv_prli_adisc_issue
, /* RCV_PRLI */
2789 lpfc_rcv_logo_adisc_issue
, /* RCV_LOGO */
2790 lpfc_rcv_padisc_adisc_issue
, /* RCV_ADISC */
2791 lpfc_rcv_padisc_adisc_issue
, /* RCV_PDISC */
2792 lpfc_rcv_prlo_adisc_issue
, /* RCV_PRLO */
2793 lpfc_disc_illegal
, /* CMPL_PLOGI */
2794 lpfc_disc_illegal
, /* CMPL_PRLI */
2795 lpfc_disc_illegal
, /* CMPL_LOGO */
2796 lpfc_cmpl_adisc_adisc_issue
, /* CMPL_ADISC */
2797 lpfc_disc_illegal
, /* CMPL_REG_LOGIN */
2798 lpfc_device_rm_adisc_issue
, /* DEVICE_RM */
2799 lpfc_device_recov_adisc_issue
, /* DEVICE_RECOVERY */
2801 lpfc_rcv_plogi_reglogin_issue
, /* RCV_PLOGI REG_LOGIN_ISSUE */
2802 lpfc_rcv_prli_reglogin_issue
, /* RCV_PLOGI */
2803 lpfc_rcv_logo_reglogin_issue
, /* RCV_LOGO */
2804 lpfc_rcv_padisc_reglogin_issue
, /* RCV_ADISC */
2805 lpfc_rcv_padisc_reglogin_issue
, /* RCV_PDISC */
2806 lpfc_rcv_prlo_reglogin_issue
, /* RCV_PRLO */
2807 lpfc_cmpl_plogi_illegal
, /* CMPL_PLOGI */
2808 lpfc_disc_illegal
, /* CMPL_PRLI */
2809 lpfc_disc_illegal
, /* CMPL_LOGO */
2810 lpfc_disc_illegal
, /* CMPL_ADISC */
2811 lpfc_cmpl_reglogin_reglogin_issue
,/* CMPL_REG_LOGIN */
2812 lpfc_device_rm_reglogin_issue
, /* DEVICE_RM */
2813 lpfc_device_recov_reglogin_issue
,/* DEVICE_RECOVERY */
2815 lpfc_rcv_plogi_prli_issue
, /* RCV_PLOGI PRLI_ISSUE */
2816 lpfc_rcv_prli_prli_issue
, /* RCV_PRLI */
2817 lpfc_rcv_logo_prli_issue
, /* RCV_LOGO */
2818 lpfc_rcv_padisc_prli_issue
, /* RCV_ADISC */
2819 lpfc_rcv_padisc_prli_issue
, /* RCV_PDISC */
2820 lpfc_rcv_prlo_prli_issue
, /* RCV_PRLO */
2821 lpfc_cmpl_plogi_illegal
, /* CMPL_PLOGI */
2822 lpfc_cmpl_prli_prli_issue
, /* CMPL_PRLI */
2823 lpfc_disc_illegal
, /* CMPL_LOGO */
2824 lpfc_disc_illegal
, /* CMPL_ADISC */
2825 lpfc_disc_illegal
, /* CMPL_REG_LOGIN */
2826 lpfc_device_rm_prli_issue
, /* DEVICE_RM */
2827 lpfc_device_recov_prli_issue
, /* DEVICE_RECOVERY */
2829 lpfc_rcv_plogi_logo_issue
, /* RCV_PLOGI LOGO_ISSUE */
2830 lpfc_rcv_prli_logo_issue
, /* RCV_PRLI */
2831 lpfc_rcv_logo_logo_issue
, /* RCV_LOGO */
2832 lpfc_rcv_padisc_logo_issue
, /* RCV_ADISC */
2833 lpfc_rcv_padisc_logo_issue
, /* RCV_PDISC */
2834 lpfc_rcv_prlo_logo_issue
, /* RCV_PRLO */
2835 lpfc_cmpl_plogi_illegal
, /* CMPL_PLOGI */
2836 lpfc_disc_illegal
, /* CMPL_PRLI */
2837 lpfc_cmpl_logo_logo_issue
, /* CMPL_LOGO */
2838 lpfc_disc_illegal
, /* CMPL_ADISC */
2839 lpfc_disc_illegal
, /* CMPL_REG_LOGIN */
2840 lpfc_device_rm_logo_issue
, /* DEVICE_RM */
2841 lpfc_device_recov_logo_issue
, /* DEVICE_RECOVERY */
2843 lpfc_rcv_plogi_unmap_node
, /* RCV_PLOGI UNMAPPED_NODE */
2844 lpfc_rcv_prli_unmap_node
, /* RCV_PRLI */
2845 lpfc_rcv_logo_unmap_node
, /* RCV_LOGO */
2846 lpfc_rcv_padisc_unmap_node
, /* RCV_ADISC */
2847 lpfc_rcv_padisc_unmap_node
, /* RCV_PDISC */
2848 lpfc_rcv_prlo_unmap_node
, /* RCV_PRLO */
2849 lpfc_disc_illegal
, /* CMPL_PLOGI */
2850 lpfc_disc_illegal
, /* CMPL_PRLI */
2851 lpfc_disc_illegal
, /* CMPL_LOGO */
2852 lpfc_disc_illegal
, /* CMPL_ADISC */
2853 lpfc_disc_illegal
, /* CMPL_REG_LOGIN */
2854 lpfc_disc_illegal
, /* DEVICE_RM */
2855 lpfc_device_recov_unmap_node
, /* DEVICE_RECOVERY */
2857 lpfc_rcv_plogi_mapped_node
, /* RCV_PLOGI MAPPED_NODE */
2858 lpfc_rcv_prli_mapped_node
, /* RCV_PRLI */
2859 lpfc_rcv_logo_mapped_node
, /* RCV_LOGO */
2860 lpfc_rcv_padisc_mapped_node
, /* RCV_ADISC */
2861 lpfc_rcv_padisc_mapped_node
, /* RCV_PDISC */
2862 lpfc_rcv_prlo_mapped_node
, /* RCV_PRLO */
2863 lpfc_disc_illegal
, /* CMPL_PLOGI */
2864 lpfc_disc_illegal
, /* CMPL_PRLI */
2865 lpfc_disc_illegal
, /* CMPL_LOGO */
2866 lpfc_disc_illegal
, /* CMPL_ADISC */
2867 lpfc_disc_illegal
, /* CMPL_REG_LOGIN */
2868 lpfc_disc_illegal
, /* DEVICE_RM */
2869 lpfc_device_recov_mapped_node
, /* DEVICE_RECOVERY */
2871 lpfc_rcv_plogi_npr_node
, /* RCV_PLOGI NPR_NODE */
2872 lpfc_rcv_prli_npr_node
, /* RCV_PRLI */
2873 lpfc_rcv_logo_npr_node
, /* RCV_LOGO */
2874 lpfc_rcv_padisc_npr_node
, /* RCV_ADISC */
2875 lpfc_rcv_padisc_npr_node
, /* RCV_PDISC */
2876 lpfc_rcv_prlo_npr_node
, /* RCV_PRLO */
2877 lpfc_cmpl_plogi_npr_node
, /* CMPL_PLOGI */
2878 lpfc_cmpl_prli_npr_node
, /* CMPL_PRLI */
2879 lpfc_cmpl_logo_npr_node
, /* CMPL_LOGO */
2880 lpfc_cmpl_adisc_npr_node
, /* CMPL_ADISC */
2881 lpfc_cmpl_reglogin_npr_node
, /* CMPL_REG_LOGIN */
2882 lpfc_device_rm_npr_node
, /* DEVICE_RM */
2883 lpfc_device_recov_npr_node
, /* DEVICE_RECOVERY */
2887 lpfc_disc_state_machine(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2888 void *arg
, uint32_t evt
)
2890 uint32_t cur_state
, rc
;
2891 uint32_t(*func
) (struct lpfc_vport
*, struct lpfc_nodelist
*, void *,
2893 uint32_t got_ndlp
= 0;
2895 if (lpfc_nlp_get(ndlp
))
2898 cur_state
= ndlp
->nlp_state
;
2900 /* DSM in event <evt> on NPort <nlp_DID> in state <cur_state> */
2901 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
2902 "0211 DSM in event x%x on NPort x%x in "
2903 "state %d rpi x%x Data: x%x x%x\n",
2904 evt
, ndlp
->nlp_DID
, cur_state
, ndlp
->nlp_rpi
,
2905 ndlp
->nlp_flag
, ndlp
->nlp_fc4_type
);
2907 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_DSM
,
2908 "DSM in: evt:%d ste:%d did:x%x",
2909 evt
, cur_state
, ndlp
->nlp_DID
);
2911 func
= lpfc_disc_action
[(cur_state
* NLP_EVT_MAX_EVENT
) + evt
];
2912 rc
= (func
) (vport
, ndlp
, arg
, evt
);
2914 /* DSM out state <rc> on NPort <nlp_DID> */
2916 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
2917 "0212 DSM out state %d on NPort x%x "
2918 "rpi x%x Data: x%x\n",
2919 rc
, ndlp
->nlp_DID
, ndlp
->nlp_rpi
, ndlp
->nlp_flag
);
2921 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_DSM
,
2922 "DSM out: ste:%d did:x%x flg:x%x",
2923 rc
, ndlp
->nlp_DID
, ndlp
->nlp_flag
);
2924 /* Decrement the ndlp reference count held for this function */
2927 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
2928 "0213 DSM out state %d on NPort free\n", rc
);
2930 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_DSM
,
2931 "DSM out: ste:%d did:x%x flg:x%x",