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 /* Check for Nport to NPort pt2pt protocol */
394 if ((vport
->fc_flag
& FC_PT2PT
) &&
395 !(vport
->fc_flag
& FC_PT2PT_PLOGI
)) {
396 /* rcv'ed PLOGI decides what our NPortId will be */
397 vport
->fc_myDID
= icmd
->un
.rcvels
.parmRo
;
399 ed_tov
= be32_to_cpu(sp
->cmn
.e_d_tov
);
400 if (sp
->cmn
.edtovResolution
) {
401 /* E_D_TOV ticks are in nanoseconds */
402 ed_tov
= (phba
->fc_edtov
+ 999999) / 1000000;
406 * For pt-to-pt, use the larger EDTOV
409 if (ed_tov
> phba
->fc_edtov
)
410 phba
->fc_edtov
= ed_tov
;
411 phba
->fc_ratov
= (2 * phba
->fc_edtov
) / 1000;
413 memcpy(&phba
->fc_fabparam
, sp
, sizeof(struct serv_parm
));
415 /* Issue config_link / reg_vfi to account for updated TOV's */
417 if (phba
->sli_rev
== LPFC_SLI_REV4
)
418 lpfc_issue_reg_vfi(vport
);
420 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
423 lpfc_config_link(phba
, mbox
);
424 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
426 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
427 if (rc
== MBX_NOT_FINISHED
) {
428 mempool_free(mbox
, phba
->mbox_mem_pool
);
433 lpfc_can_disctmo(vport
);
436 ndlp
->nlp_flag
&= ~NLP_SUPPRESS_RSP
;
437 if ((phba
->sli
.sli_flag
& LPFC_SLI_SUPPRESS_RSP
) &&
438 sp
->cmn
.valid_vendor_ver_level
) {
439 vid
= be32_to_cpu(sp
->un
.vv
.vid
);
440 flag
= be32_to_cpu(sp
->un
.vv
.flags
);
441 if ((vid
== LPFC_VV_EMLX_ID
) && (flag
& LPFC_VV_SUPPRESS_RSP
))
442 ndlp
->nlp_flag
|= NLP_SUPPRESS_RSP
;
445 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
449 /* Registering an existing RPI behaves differently for SLI3 vs SLI4 */
450 if (phba
->sli_rev
== LPFC_SLI_REV4
)
451 lpfc_unreg_rpi(vport
, ndlp
);
453 rc
= lpfc_reg_rpi(phba
, vport
->vpi
, icmd
->un
.rcvels
.remoteID
,
454 (uint8_t *) sp
, mbox
, ndlp
->nlp_rpi
);
456 mempool_free(mbox
, phba
->mbox_mem_pool
);
460 /* ACC PLOGI rsp command needs to execute first,
461 * queue this mbox command to be processed later.
463 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_reg_login
;
465 * mbox->context2 = lpfc_nlp_get(ndlp) deferred until mailbox
466 * command issued in lpfc_cmpl_els_acc().
469 spin_lock_irq(shost
->host_lock
);
470 ndlp
->nlp_flag
|= (NLP_ACC_REGLOGIN
| NLP_RCV_PLOGI
);
471 spin_unlock_irq(shost
->host_lock
);
474 * If there is an outstanding PLOGI issued, abort it before
475 * sending ACC rsp for received PLOGI. If pending plogi
476 * is not canceled here, the plogi will be rejected by
477 * remote port and will be retried. On a configuration with
478 * single discovery thread, this will cause a huge delay in
479 * discovery. Also this will cause multiple state machines
480 * running in parallel for this node.
482 if (ndlp
->nlp_state
== NLP_STE_PLOGI_ISSUE
) {
483 /* software abort outstanding PLOGI */
484 lpfc_els_abort(phba
, ndlp
);
487 if ((vport
->port_type
== LPFC_NPIV_PORT
&&
488 vport
->cfg_restrict_login
)) {
490 /* In order to preserve RPIs, we want to cleanup
491 * the default RPI the firmware created to rcv
492 * this ELS request. The only way to do this is
493 * to register, then unregister the RPI.
495 spin_lock_irq(shost
->host_lock
);
496 ndlp
->nlp_flag
|= NLP_RM_DFLT_RPI
;
497 spin_unlock_irq(shost
->host_lock
);
498 stat
.un
.b
.lsRjtRsnCode
= LSRJT_INVALID_CMD
;
499 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_NOTHING_MORE
;
500 rc
= lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
,
503 mempool_free(mbox
, phba
->mbox_mem_pool
);
506 rc
= lpfc_els_rsp_acc(vport
, ELS_CMD_PLOGI
, cmdiocb
, ndlp
, mbox
);
508 mempool_free(mbox
, phba
->mbox_mem_pool
);
511 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
512 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_OUT_OF_RESOURCE
;
513 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
518 * lpfc_mbx_cmpl_resume_rpi - Resume RPI completion routine
519 * @phba: pointer to lpfc hba data structure.
520 * @mboxq: pointer to mailbox object
522 * This routine is invoked to issue a completion to a rcv'ed
523 * ADISC or PDISC after the paused RPI has been resumed.
526 lpfc_mbx_cmpl_resume_rpi(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
528 struct lpfc_vport
*vport
;
529 struct lpfc_iocbq
*elsiocb
;
530 struct lpfc_nodelist
*ndlp
;
533 elsiocb
= (struct lpfc_iocbq
*)mboxq
->context1
;
534 ndlp
= (struct lpfc_nodelist
*) mboxq
->context2
;
535 vport
= mboxq
->vport
;
536 cmd
= elsiocb
->drvrTimeout
;
538 if (cmd
== ELS_CMD_ADISC
) {
539 lpfc_els_rsp_adisc_acc(vport
, elsiocb
, ndlp
);
541 lpfc_els_rsp_acc(vport
, ELS_CMD_PLOGI
, elsiocb
,
545 mempool_free(mboxq
, phba
->mbox_mem_pool
);
549 lpfc_rcv_padisc(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
550 struct lpfc_iocbq
*cmdiocb
)
552 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
553 struct lpfc_iocbq
*elsiocb
;
554 struct lpfc_dmabuf
*pcmd
;
555 struct serv_parm
*sp
;
556 struct lpfc_name
*pnn
, *ppn
;
563 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
564 lp
= (uint32_t *) pcmd
->virt
;
567 if (cmd
== ELS_CMD_ADISC
) {
569 pnn
= (struct lpfc_name
*) & ap
->nodeName
;
570 ppn
= (struct lpfc_name
*) & ap
->portName
;
572 sp
= (struct serv_parm
*) lp
;
573 pnn
= (struct lpfc_name
*) & sp
->nodeName
;
574 ppn
= (struct lpfc_name
*) & sp
->portName
;
577 icmd
= &cmdiocb
->iocb
;
578 if (icmd
->ulpStatus
== 0 && lpfc_check_adisc(vport
, ndlp
, pnn
, ppn
)) {
581 * As soon as we send ACC, the remote NPort can
582 * start sending us data. Thus, for SLI4 we must
583 * resume the RPI before the ACC goes out.
585 if (vport
->phba
->sli_rev
== LPFC_SLI_REV4
) {
586 elsiocb
= kmalloc(sizeof(struct lpfc_iocbq
),
590 /* Save info from cmd IOCB used in rsp */
591 memcpy((uint8_t *)elsiocb
, (uint8_t *)cmdiocb
,
592 sizeof(struct lpfc_iocbq
));
594 /* Save the ELS cmd */
595 elsiocb
->drvrTimeout
= cmd
;
597 lpfc_sli4_resume_rpi(ndlp
,
598 lpfc_mbx_cmpl_resume_rpi
, elsiocb
);
603 if (cmd
== ELS_CMD_ADISC
) {
604 lpfc_els_rsp_adisc_acc(vport
, cmdiocb
, ndlp
);
606 lpfc_els_rsp_acc(vport
, ELS_CMD_PLOGI
, cmdiocb
,
610 /* If we are authenticated, move to the proper state */
611 if (ndlp
->nlp_type
& NLP_FCP_TARGET
)
612 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_MAPPED_NODE
);
614 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
618 /* Reject this request because invalid parameters */
619 stat
.un
.b
.lsRjtRsvd0
= 0;
620 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
621 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_SPARM_OPTIONS
;
622 stat
.un
.b
.vendorUnique
= 0;
623 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
626 mod_timer(&ndlp
->nlp_delayfunc
, jiffies
+ msecs_to_jiffies(1000));
628 spin_lock_irq(shost
->host_lock
);
629 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
630 spin_unlock_irq(shost
->host_lock
);
631 ndlp
->nlp_last_elscmd
= ELS_CMD_PLOGI
;
632 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
633 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
638 lpfc_rcv_logo(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
639 struct lpfc_iocbq
*cmdiocb
, uint32_t els_cmd
)
641 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
642 struct lpfc_hba
*phba
= vport
->phba
;
643 struct lpfc_vport
**vports
;
644 int i
, active_vlink_present
= 0 ;
646 /* Put ndlp in NPR state with 1 sec timeout for plogi, ACC logo */
647 /* Only call LOGO ACC for first LOGO, this avoids sending unnecessary
648 * PLOGIs during LOGO storms from a device.
650 spin_lock_irq(shost
->host_lock
);
651 ndlp
->nlp_flag
|= NLP_LOGO_ACC
;
652 spin_unlock_irq(shost
->host_lock
);
653 if (els_cmd
== ELS_CMD_PRLO
)
654 lpfc_els_rsp_acc(vport
, ELS_CMD_PRLO
, cmdiocb
, ndlp
, NULL
);
656 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
657 if (ndlp
->nlp_DID
== Fabric_DID
) {
658 if (vport
->port_state
<= LPFC_FDISC
)
660 lpfc_linkdown_port(vport
);
661 spin_lock_irq(shost
->host_lock
);
662 vport
->fc_flag
|= FC_VPORT_LOGO_RCVD
;
663 spin_unlock_irq(shost
->host_lock
);
664 vports
= lpfc_create_vport_work_array(phba
);
666 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
;
668 if ((!(vports
[i
]->fc_flag
&
669 FC_VPORT_LOGO_RCVD
)) &&
670 (vports
[i
]->port_state
> LPFC_FDISC
)) {
671 active_vlink_present
= 1;
675 lpfc_destroy_vport_work_array(phba
, vports
);
679 * Don't re-instantiate if vport is marked for deletion.
680 * If we are here first then vport_delete is going to wait
681 * for discovery to complete.
683 if (!(vport
->load_flag
& FC_UNLOADING
) &&
684 active_vlink_present
) {
686 * If there are other active VLinks present,
687 * re-instantiate the Vlink using FDISC.
689 mod_timer(&ndlp
->nlp_delayfunc
,
690 jiffies
+ msecs_to_jiffies(1000));
691 spin_lock_irq(shost
->host_lock
);
692 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
693 spin_unlock_irq(shost
->host_lock
);
694 ndlp
->nlp_last_elscmd
= ELS_CMD_FDISC
;
695 vport
->port_state
= LPFC_FDISC
;
697 spin_lock_irq(shost
->host_lock
);
698 phba
->pport
->fc_flag
&= ~FC_LOGO_RCVD_DID_CHNG
;
699 spin_unlock_irq(shost
->host_lock
);
700 lpfc_retry_pport_discovery(phba
);
702 } else if ((!(ndlp
->nlp_type
& NLP_FABRIC
) &&
703 ((ndlp
->nlp_type
& NLP_FCP_TARGET
) ||
704 !(ndlp
->nlp_type
& NLP_FCP_INITIATOR
))) ||
705 (ndlp
->nlp_state
== NLP_STE_ADISC_ISSUE
)) {
706 /* Only try to re-login if this is NOT a Fabric Node */
707 mod_timer(&ndlp
->nlp_delayfunc
,
708 jiffies
+ msecs_to_jiffies(1000 * 1));
709 spin_lock_irq(shost
->host_lock
);
710 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
711 spin_unlock_irq(shost
->host_lock
);
713 ndlp
->nlp_last_elscmd
= ELS_CMD_PLOGI
;
716 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
717 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
719 spin_lock_irq(shost
->host_lock
);
720 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
721 spin_unlock_irq(shost
->host_lock
);
722 /* The driver has to wait until the ACC completes before it continues
723 * processing the LOGO. The action will resume in
724 * lpfc_cmpl_els_logo_acc routine. Since part of processing includes an
725 * unreg_login, the driver waits so the ACC does not get aborted.
731 lpfc_rcv_prli(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
732 struct lpfc_iocbq
*cmdiocb
)
734 struct lpfc_hba
*phba
= vport
->phba
;
735 struct lpfc_dmabuf
*pcmd
;
738 struct fc_rport
*rport
= ndlp
->rport
;
741 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
742 lp
= (uint32_t *) pcmd
->virt
;
743 npr
= (PRLI
*) ((uint8_t *) lp
+ sizeof (uint32_t));
745 ndlp
->nlp_type
&= ~(NLP_FCP_TARGET
| NLP_FCP_INITIATOR
);
746 ndlp
->nlp_fcp_info
&= ~NLP_FCP_2_DEVICE
;
747 ndlp
->nlp_flag
&= ~NLP_FIRSTBURST
;
748 if ((npr
->prliType
== PRLI_FCP_TYPE
) ||
749 (npr
->prliType
== PRLI_NVME_TYPE
)) {
750 if (npr
->initiatorFunc
) {
751 if (npr
->prliType
== PRLI_FCP_TYPE
)
752 ndlp
->nlp_type
|= NLP_FCP_INITIATOR
;
753 if (npr
->prliType
== PRLI_NVME_TYPE
)
754 ndlp
->nlp_type
|= NLP_NVME_INITIATOR
;
756 if (npr
->targetFunc
) {
757 if (npr
->prliType
== PRLI_FCP_TYPE
)
758 ndlp
->nlp_type
|= NLP_FCP_TARGET
;
759 if (npr
->prliType
== PRLI_NVME_TYPE
)
760 ndlp
->nlp_type
|= NLP_NVME_TARGET
;
761 if (npr
->writeXferRdyDis
)
762 ndlp
->nlp_flag
|= NLP_FIRSTBURST
;
765 ndlp
->nlp_fcp_info
|= NLP_FCP_2_DEVICE
;
767 /* If this driver is in nvme target mode, set the ndlp's fc4
768 * type to NVME provided the PRLI response claims NVME FC4
769 * type. Target mode does not issue gft_id so doesn't get
770 * the fc4 type set until now.
772 if ((phba
->nvmet_support
) && (npr
->prliType
== PRLI_NVME_TYPE
))
773 ndlp
->nlp_fc4_type
|= NLP_FC4_NVME
;
776 /* We need to update the rport role values */
777 roles
= FC_RPORT_ROLE_UNKNOWN
;
778 if (ndlp
->nlp_type
& NLP_FCP_INITIATOR
)
779 roles
|= FC_RPORT_ROLE_FCP_INITIATOR
;
780 if (ndlp
->nlp_type
& NLP_FCP_TARGET
)
781 roles
|= FC_RPORT_ROLE_FCP_TARGET
;
783 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_RPORT
,
784 "rport rolechg: role:x%x did:x%x flg:x%x",
785 roles
, ndlp
->nlp_DID
, ndlp
->nlp_flag
);
787 if (phba
->cfg_enable_fc4_type
!= LPFC_ENABLE_NVME
)
788 fc_remote_port_rolechg(rport
, roles
);
793 lpfc_disc_set_adisc(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
795 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
797 if (!(ndlp
->nlp_flag
& NLP_RPI_REGISTERED
)) {
798 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
802 if (!(vport
->fc_flag
& FC_PT2PT
)) {
803 /* Check config parameter use-adisc or FCP-2 */
804 if ((vport
->cfg_use_adisc
&& (vport
->fc_flag
& FC_RSCN_MODE
)) ||
805 ((ndlp
->nlp_fcp_info
& NLP_FCP_2_DEVICE
) &&
806 (ndlp
->nlp_type
& NLP_FCP_TARGET
))) {
807 spin_lock_irq(shost
->host_lock
);
808 ndlp
->nlp_flag
|= NLP_NPR_ADISC
;
809 spin_unlock_irq(shost
->host_lock
);
813 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
814 lpfc_unreg_rpi(vport
, ndlp
);
819 * lpfc_release_rpi - Release a RPI by issuing unreg_login mailbox cmd.
820 * @phba : Pointer to lpfc_hba structure.
821 * @vport: Pointer to lpfc_vport structure.
822 * @rpi : rpi to be release.
824 * This function will send a unreg_login mailbox command to the firmware
828 lpfc_release_rpi(struct lpfc_hba
*phba
,
829 struct lpfc_vport
*vport
,
835 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
,
838 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
839 "2796 mailbox memory allocation failed \n");
841 lpfc_unreg_login(phba
, vport
->vpi
, rpi
, pmb
);
842 pmb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
843 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
844 if (rc
== MBX_NOT_FINISHED
)
845 mempool_free(pmb
, phba
->mbox_mem_pool
);
850 lpfc_disc_illegal(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
851 void *arg
, uint32_t evt
)
853 struct lpfc_hba
*phba
;
854 LPFC_MBOXQ_t
*pmb
= (LPFC_MBOXQ_t
*) arg
;
858 /* Release the RPI if reglogin completing */
859 if (!(phba
->pport
->load_flag
& FC_UNLOADING
) &&
860 (evt
== NLP_EVT_CMPL_REG_LOGIN
) &&
861 (!pmb
->u
.mb
.mbxStatus
)) {
862 rpi
= pmb
->u
.mb
.un
.varWords
[0];
863 lpfc_release_rpi(phba
, vport
, rpi
);
865 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
866 "0271 Illegal State Transition: node x%x "
867 "event x%x, state x%x Data: x%x x%x\n",
868 ndlp
->nlp_DID
, evt
, ndlp
->nlp_state
, ndlp
->nlp_rpi
,
870 return ndlp
->nlp_state
;
874 lpfc_cmpl_plogi_illegal(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
875 void *arg
, uint32_t evt
)
877 /* This transition is only legal if we previously
878 * rcv'ed a PLOGI. Since we don't want 2 discovery threads
879 * working on the same NPortID, do nothing for this thread
882 if (!(ndlp
->nlp_flag
& NLP_RCV_PLOGI
)) {
883 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
884 "0272 Illegal State Transition: node x%x "
885 "event x%x, state x%x Data: x%x x%x\n",
886 ndlp
->nlp_DID
, evt
, ndlp
->nlp_state
, ndlp
->nlp_rpi
,
889 return ndlp
->nlp_state
;
892 /* Start of Discovery State Machine routines */
895 lpfc_rcv_plogi_unused_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
896 void *arg
, uint32_t evt
)
898 struct lpfc_iocbq
*cmdiocb
;
900 cmdiocb
= (struct lpfc_iocbq
*) arg
;
902 if (lpfc_rcv_plogi(vport
, ndlp
, cmdiocb
)) {
903 return ndlp
->nlp_state
;
905 return NLP_STE_FREED_NODE
;
909 lpfc_rcv_els_unused_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
910 void *arg
, uint32_t evt
)
912 lpfc_issue_els_logo(vport
, ndlp
, 0);
913 return ndlp
->nlp_state
;
917 lpfc_rcv_logo_unused_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
918 void *arg
, uint32_t evt
)
920 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
921 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
923 spin_lock_irq(shost
->host_lock
);
924 ndlp
->nlp_flag
|= NLP_LOGO_ACC
;
925 spin_unlock_irq(shost
->host_lock
);
926 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
928 return ndlp
->nlp_state
;
932 lpfc_cmpl_logo_unused_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
933 void *arg
, uint32_t evt
)
935 return NLP_STE_FREED_NODE
;
939 lpfc_device_rm_unused_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
940 void *arg
, uint32_t evt
)
942 return NLP_STE_FREED_NODE
;
946 lpfc_device_recov_unused_node(struct lpfc_vport
*vport
,
947 struct lpfc_nodelist
*ndlp
,
948 void *arg
, uint32_t evt
)
950 return ndlp
->nlp_state
;
954 lpfc_rcv_plogi_plogi_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
955 void *arg
, uint32_t evt
)
957 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
958 struct lpfc_hba
*phba
= vport
->phba
;
959 struct lpfc_iocbq
*cmdiocb
= arg
;
960 struct lpfc_dmabuf
*pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
961 uint32_t *lp
= (uint32_t *) pcmd
->virt
;
962 struct serv_parm
*sp
= (struct serv_parm
*) (lp
+ 1);
966 memset(&stat
, 0, sizeof (struct ls_rjt
));
968 /* For a PLOGI, we only accept if our portname is less
969 * than the remote portname.
971 phba
->fc_stat
.elsLogiCol
++;
972 port_cmp
= memcmp(&vport
->fc_portname
, &sp
->portName
,
973 sizeof(struct lpfc_name
));
976 /* Reject this request because the remote node will accept
978 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
979 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CMD_IN_PROGRESS
;
980 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
,
983 if (lpfc_rcv_plogi(vport
, ndlp
, cmdiocb
) &&
984 (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) &&
985 (vport
->num_disc_nodes
)) {
986 spin_lock_irq(shost
->host_lock
);
987 ndlp
->nlp_flag
&= ~NLP_NPR_2B_DISC
;
988 spin_unlock_irq(shost
->host_lock
);
989 /* Check if there are more PLOGIs to be sent */
990 lpfc_more_plogi(vport
);
991 if (vport
->num_disc_nodes
== 0) {
992 spin_lock_irq(shost
->host_lock
);
993 vport
->fc_flag
&= ~FC_NDISC_ACTIVE
;
994 spin_unlock_irq(shost
->host_lock
);
995 lpfc_can_disctmo(vport
);
996 lpfc_end_rscn(vport
);
999 } /* If our portname was less */
1001 return ndlp
->nlp_state
;
1005 lpfc_rcv_prli_plogi_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1006 void *arg
, uint32_t evt
)
1008 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1011 memset(&stat
, 0, sizeof (struct ls_rjt
));
1012 stat
.un
.b
.lsRjtRsnCode
= LSRJT_LOGICAL_BSY
;
1013 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_NOTHING_MORE
;
1014 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
1015 return ndlp
->nlp_state
;
1019 lpfc_rcv_logo_plogi_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1020 void *arg
, uint32_t evt
)
1022 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1024 /* software abort outstanding PLOGI */
1025 lpfc_els_abort(vport
->phba
, ndlp
);
1027 lpfc_rcv_logo(vport
, ndlp
, cmdiocb
, ELS_CMD_LOGO
);
1028 return ndlp
->nlp_state
;
1032 lpfc_rcv_els_plogi_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1033 void *arg
, uint32_t evt
)
1035 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1036 struct lpfc_hba
*phba
= vport
->phba
;
1037 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1039 /* software abort outstanding PLOGI */
1040 lpfc_els_abort(phba
, ndlp
);
1042 if (evt
== NLP_EVT_RCV_LOGO
) {
1043 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
1045 lpfc_issue_els_logo(vport
, ndlp
, 0);
1048 /* Put ndlp in npr state set plogi timer for 1 sec */
1049 mod_timer(&ndlp
->nlp_delayfunc
, jiffies
+ msecs_to_jiffies(1000 * 1));
1050 spin_lock_irq(shost
->host_lock
);
1051 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
1052 spin_unlock_irq(shost
->host_lock
);
1053 ndlp
->nlp_last_elscmd
= ELS_CMD_PLOGI
;
1054 ndlp
->nlp_prev_state
= NLP_STE_PLOGI_ISSUE
;
1055 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1057 return ndlp
->nlp_state
;
1061 lpfc_cmpl_plogi_plogi_issue(struct lpfc_vport
*vport
,
1062 struct lpfc_nodelist
*ndlp
,
1066 struct lpfc_hba
*phba
= vport
->phba
;
1067 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1068 struct lpfc_iocbq
*cmdiocb
, *rspiocb
;
1069 struct lpfc_dmabuf
*pcmd
, *prsp
, *mp
;
1073 struct serv_parm
*sp
;
1078 cmdiocb
= (struct lpfc_iocbq
*) arg
;
1079 rspiocb
= cmdiocb
->context_un
.rsp_iocb
;
1081 if (ndlp
->nlp_flag
& NLP_ACC_REGLOGIN
) {
1082 /* Recovery from PLOGI collision logic */
1083 return ndlp
->nlp_state
;
1086 irsp
= &rspiocb
->iocb
;
1088 if (irsp
->ulpStatus
)
1091 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
1093 prsp
= list_get_first(&pcmd
->list
, struct lpfc_dmabuf
, list
);
1097 lp
= (uint32_t *) prsp
->virt
;
1098 sp
= (struct serv_parm
*) ((uint8_t *) lp
+ sizeof (uint32_t));
1100 /* Some switches have FDMI servers returning 0 for WWN */
1101 if ((ndlp
->nlp_DID
!= FDMI_DID
) &&
1102 (wwn_to_u64(sp
->portName
.u
.wwn
) == 0 ||
1103 wwn_to_u64(sp
->nodeName
.u
.wwn
) == 0)) {
1104 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1105 "0142 PLOGI RSP: Invalid WWN.\n");
1108 if (!lpfc_check_sparm(vport
, ndlp
, sp
, CLASS3
, 0))
1110 /* PLOGI chkparm OK */
1111 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
1112 "0121 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
1113 ndlp
->nlp_DID
, ndlp
->nlp_state
,
1114 ndlp
->nlp_flag
, ndlp
->nlp_rpi
);
1115 if (vport
->cfg_fcp_class
== 2 && (sp
->cls2
.classValid
))
1116 ndlp
->nlp_fcp_info
|= CLASS2
;
1118 ndlp
->nlp_fcp_info
|= CLASS3
;
1120 ndlp
->nlp_class_sup
= 0;
1121 if (sp
->cls1
.classValid
)
1122 ndlp
->nlp_class_sup
|= FC_COS_CLASS1
;
1123 if (sp
->cls2
.classValid
)
1124 ndlp
->nlp_class_sup
|= FC_COS_CLASS2
;
1125 if (sp
->cls3
.classValid
)
1126 ndlp
->nlp_class_sup
|= FC_COS_CLASS3
;
1127 if (sp
->cls4
.classValid
)
1128 ndlp
->nlp_class_sup
|= FC_COS_CLASS4
;
1129 ndlp
->nlp_maxframe
=
1130 ((sp
->cmn
.bbRcvSizeMsb
& 0x0F) << 8) | sp
->cmn
.bbRcvSizeLsb
;
1132 if ((vport
->fc_flag
& FC_PT2PT
) &&
1133 (vport
->fc_flag
& FC_PT2PT_PLOGI
)) {
1134 ed_tov
= be32_to_cpu(sp
->cmn
.e_d_tov
);
1135 if (sp
->cmn
.edtovResolution
) {
1136 /* E_D_TOV ticks are in nanoseconds */
1137 ed_tov
= (phba
->fc_edtov
+ 999999) / 1000000;
1140 ndlp
->nlp_flag
&= ~NLP_SUPPRESS_RSP
;
1141 if ((phba
->sli
.sli_flag
& LPFC_SLI_SUPPRESS_RSP
) &&
1142 sp
->cmn
.valid_vendor_ver_level
) {
1143 vid
= be32_to_cpu(sp
->un
.vv
.vid
);
1144 flag
= be32_to_cpu(sp
->un
.vv
.flags
);
1145 if ((vid
== LPFC_VV_EMLX_ID
) &&
1146 (flag
& LPFC_VV_SUPPRESS_RSP
))
1147 ndlp
->nlp_flag
|= NLP_SUPPRESS_RSP
;
1151 * Use the larger EDTOV
1152 * RATOV = 2 * EDTOV for pt-to-pt
1154 if (ed_tov
> phba
->fc_edtov
)
1155 phba
->fc_edtov
= ed_tov
;
1156 phba
->fc_ratov
= (2 * phba
->fc_edtov
) / 1000;
1158 memcpy(&phba
->fc_fabparam
, sp
, sizeof(struct serv_parm
));
1160 /* Issue config_link / reg_vfi to account for updated TOV's */
1161 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
1162 lpfc_issue_reg_vfi(vport
);
1164 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1166 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1167 "0133 PLOGI: no memory "
1169 "Data: x%x x%x x%x x%x\n",
1170 ndlp
->nlp_DID
, ndlp
->nlp_state
,
1171 ndlp
->nlp_flag
, ndlp
->nlp_rpi
);
1175 lpfc_config_link(phba
, mbox
);
1177 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
1178 mbox
->vport
= vport
;
1179 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
1180 if (rc
== MBX_NOT_FINISHED
) {
1181 mempool_free(mbox
, phba
->mbox_mem_pool
);
1187 lpfc_unreg_rpi(vport
, ndlp
);
1189 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1191 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1192 "0018 PLOGI: no memory for reg_login "
1193 "Data: x%x x%x x%x x%x\n",
1194 ndlp
->nlp_DID
, ndlp
->nlp_state
,
1195 ndlp
->nlp_flag
, ndlp
->nlp_rpi
);
1199 if (lpfc_reg_rpi(phba
, vport
->vpi
, irsp
->un
.elsreq64
.remoteID
,
1200 (uint8_t *) sp
, mbox
, ndlp
->nlp_rpi
) == 0) {
1201 switch (ndlp
->nlp_DID
) {
1202 case NameServer_DID
:
1203 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_ns_reg_login
;
1206 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_fdmi_reg_login
;
1209 ndlp
->nlp_flag
|= NLP_REG_LOGIN_SEND
;
1210 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_reg_login
;
1212 mbox
->context2
= lpfc_nlp_get(ndlp
);
1213 mbox
->vport
= vport
;
1214 if (lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
)
1215 != MBX_NOT_FINISHED
) {
1216 lpfc_nlp_set_state(vport
, ndlp
,
1217 NLP_STE_REG_LOGIN_ISSUE
);
1218 return ndlp
->nlp_state
;
1220 if (ndlp
->nlp_flag
& NLP_REG_LOGIN_SEND
)
1221 ndlp
->nlp_flag
&= ~NLP_REG_LOGIN_SEND
;
1222 /* decrement node reference count to the failed mbox
1226 mp
= (struct lpfc_dmabuf
*) mbox
->context1
;
1227 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
1229 mempool_free(mbox
, phba
->mbox_mem_pool
);
1231 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1232 "0134 PLOGI: cannot issue reg_login "
1233 "Data: x%x x%x x%x x%x\n",
1234 ndlp
->nlp_DID
, ndlp
->nlp_state
,
1235 ndlp
->nlp_flag
, ndlp
->nlp_rpi
);
1237 mempool_free(mbox
, phba
->mbox_mem_pool
);
1239 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1240 "0135 PLOGI: cannot format reg_login "
1241 "Data: x%x x%x x%x x%x\n",
1242 ndlp
->nlp_DID
, ndlp
->nlp_state
,
1243 ndlp
->nlp_flag
, ndlp
->nlp_rpi
);
1248 if (ndlp
->nlp_DID
== NameServer_DID
) {
1249 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
1250 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1251 "0261 Cannot Register NameServer login\n");
1255 ** In case the node reference counter does not go to zero, ensure that
1256 ** the stale state for the node is not processed.
1259 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
1260 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1261 spin_lock_irq(shost
->host_lock
);
1262 ndlp
->nlp_flag
|= NLP_DEFER_RM
;
1263 spin_unlock_irq(shost
->host_lock
);
1264 return NLP_STE_FREED_NODE
;
1268 lpfc_cmpl_logo_plogi_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1269 void *arg
, uint32_t evt
)
1271 return ndlp
->nlp_state
;
1275 lpfc_cmpl_reglogin_plogi_issue(struct lpfc_vport
*vport
,
1276 struct lpfc_nodelist
*ndlp
, void *arg
, uint32_t evt
)
1278 struct lpfc_hba
*phba
;
1279 LPFC_MBOXQ_t
*pmb
= (LPFC_MBOXQ_t
*) arg
;
1280 MAILBOX_t
*mb
= &pmb
->u
.mb
;
1284 /* Release the RPI */
1285 if (!(phba
->pport
->load_flag
& FC_UNLOADING
) &&
1287 rpi
= pmb
->u
.mb
.un
.varWords
[0];
1288 lpfc_release_rpi(phba
, vport
, rpi
);
1290 return ndlp
->nlp_state
;
1294 lpfc_device_rm_plogi_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1295 void *arg
, uint32_t evt
)
1297 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1299 if (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) {
1300 spin_lock_irq(shost
->host_lock
);
1301 ndlp
->nlp_flag
|= NLP_NODEV_REMOVE
;
1302 spin_unlock_irq(shost
->host_lock
);
1303 return ndlp
->nlp_state
;
1305 /* software abort outstanding PLOGI */
1306 lpfc_els_abort(vport
->phba
, ndlp
);
1308 lpfc_drop_node(vport
, ndlp
);
1309 return NLP_STE_FREED_NODE
;
1314 lpfc_device_recov_plogi_issue(struct lpfc_vport
*vport
,
1315 struct lpfc_nodelist
*ndlp
,
1319 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1320 struct lpfc_hba
*phba
= vport
->phba
;
1322 /* Don't do anything that will mess up processing of the
1325 if (vport
->fc_flag
& FC_RSCN_DEFERRED
)
1326 return ndlp
->nlp_state
;
1328 /* software abort outstanding PLOGI */
1329 lpfc_els_abort(phba
, ndlp
);
1331 ndlp
->nlp_prev_state
= NLP_STE_PLOGI_ISSUE
;
1332 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1333 spin_lock_irq(shost
->host_lock
);
1334 ndlp
->nlp_flag
&= ~(NLP_NODEV_REMOVE
| NLP_NPR_2B_DISC
);
1335 spin_unlock_irq(shost
->host_lock
);
1337 return ndlp
->nlp_state
;
1341 lpfc_rcv_plogi_adisc_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1342 void *arg
, uint32_t evt
)
1344 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1345 struct lpfc_hba
*phba
= vport
->phba
;
1346 struct lpfc_iocbq
*cmdiocb
;
1348 /* software abort outstanding ADISC */
1349 lpfc_els_abort(phba
, ndlp
);
1351 cmdiocb
= (struct lpfc_iocbq
*) arg
;
1353 if (lpfc_rcv_plogi(vport
, ndlp
, cmdiocb
)) {
1354 if (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) {
1355 spin_lock_irq(shost
->host_lock
);
1356 ndlp
->nlp_flag
&= ~NLP_NPR_2B_DISC
;
1357 spin_unlock_irq(shost
->host_lock
);
1358 if (vport
->num_disc_nodes
)
1359 lpfc_more_adisc(vport
);
1361 return ndlp
->nlp_state
;
1363 ndlp
->nlp_prev_state
= NLP_STE_ADISC_ISSUE
;
1364 lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0);
1365 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
1367 return ndlp
->nlp_state
;
1371 lpfc_rcv_prli_adisc_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1372 void *arg
, uint32_t evt
)
1374 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1376 lpfc_els_rsp_prli_acc(vport
, cmdiocb
, ndlp
);
1377 return ndlp
->nlp_state
;
1381 lpfc_rcv_logo_adisc_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1382 void *arg
, uint32_t evt
)
1384 struct lpfc_hba
*phba
= vport
->phba
;
1385 struct lpfc_iocbq
*cmdiocb
;
1387 cmdiocb
= (struct lpfc_iocbq
*) arg
;
1389 /* software abort outstanding ADISC */
1390 lpfc_els_abort(phba
, ndlp
);
1392 lpfc_rcv_logo(vport
, ndlp
, cmdiocb
, ELS_CMD_LOGO
);
1393 return ndlp
->nlp_state
;
1397 lpfc_rcv_padisc_adisc_issue(struct lpfc_vport
*vport
,
1398 struct lpfc_nodelist
*ndlp
,
1399 void *arg
, uint32_t evt
)
1401 struct lpfc_iocbq
*cmdiocb
;
1403 cmdiocb
= (struct lpfc_iocbq
*) arg
;
1405 lpfc_rcv_padisc(vport
, ndlp
, cmdiocb
);
1406 return ndlp
->nlp_state
;
1410 lpfc_rcv_prlo_adisc_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1411 void *arg
, uint32_t evt
)
1413 struct lpfc_iocbq
*cmdiocb
;
1415 cmdiocb
= (struct lpfc_iocbq
*) arg
;
1417 /* Treat like rcv logo */
1418 lpfc_rcv_logo(vport
, ndlp
, cmdiocb
, ELS_CMD_PRLO
);
1419 return ndlp
->nlp_state
;
1423 lpfc_cmpl_adisc_adisc_issue(struct lpfc_vport
*vport
,
1424 struct lpfc_nodelist
*ndlp
,
1425 void *arg
, uint32_t evt
)
1427 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1428 struct lpfc_hba
*phba
= vport
->phba
;
1429 struct lpfc_iocbq
*cmdiocb
, *rspiocb
;
1434 cmdiocb
= (struct lpfc_iocbq
*) arg
;
1435 rspiocb
= cmdiocb
->context_un
.rsp_iocb
;
1437 ap
= (ADISC
*)lpfc_check_elscmpl_iocb(phba
, cmdiocb
, rspiocb
);
1438 irsp
= &rspiocb
->iocb
;
1440 if ((irsp
->ulpStatus
) ||
1441 (!lpfc_check_adisc(vport
, ndlp
, &ap
->nodeName
, &ap
->portName
))) {
1443 mod_timer(&ndlp
->nlp_delayfunc
,
1444 jiffies
+ msecs_to_jiffies(1000));
1445 spin_lock_irq(shost
->host_lock
);
1446 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
1447 spin_unlock_irq(shost
->host_lock
);
1448 ndlp
->nlp_last_elscmd
= ELS_CMD_PLOGI
;
1450 memset(&ndlp
->nlp_nodename
, 0, sizeof(struct lpfc_name
));
1451 memset(&ndlp
->nlp_portname
, 0, sizeof(struct lpfc_name
));
1453 ndlp
->nlp_prev_state
= NLP_STE_ADISC_ISSUE
;
1454 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1455 lpfc_unreg_rpi(vport
, ndlp
);
1456 return ndlp
->nlp_state
;
1459 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
1460 rc
= lpfc_sli4_resume_rpi(ndlp
, NULL
, NULL
);
1462 /* Stay in state and retry. */
1463 ndlp
->nlp_prev_state
= NLP_STE_ADISC_ISSUE
;
1464 return ndlp
->nlp_state
;
1468 if (ndlp
->nlp_type
& NLP_FCP_TARGET
) {
1469 ndlp
->nlp_prev_state
= NLP_STE_ADISC_ISSUE
;
1470 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_MAPPED_NODE
);
1472 ndlp
->nlp_prev_state
= NLP_STE_ADISC_ISSUE
;
1473 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
1476 return ndlp
->nlp_state
;
1480 lpfc_device_rm_adisc_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1481 void *arg
, uint32_t evt
)
1483 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1485 if (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) {
1486 spin_lock_irq(shost
->host_lock
);
1487 ndlp
->nlp_flag
|= NLP_NODEV_REMOVE
;
1488 spin_unlock_irq(shost
->host_lock
);
1489 return ndlp
->nlp_state
;
1491 /* software abort outstanding ADISC */
1492 lpfc_els_abort(vport
->phba
, ndlp
);
1494 lpfc_drop_node(vport
, ndlp
);
1495 return NLP_STE_FREED_NODE
;
1500 lpfc_device_recov_adisc_issue(struct lpfc_vport
*vport
,
1501 struct lpfc_nodelist
*ndlp
,
1505 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1506 struct lpfc_hba
*phba
= vport
->phba
;
1508 /* Don't do anything that will mess up processing of the
1511 if (vport
->fc_flag
& FC_RSCN_DEFERRED
)
1512 return ndlp
->nlp_state
;
1514 /* software abort outstanding ADISC */
1515 lpfc_els_abort(phba
, ndlp
);
1517 ndlp
->nlp_prev_state
= NLP_STE_ADISC_ISSUE
;
1518 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1519 spin_lock_irq(shost
->host_lock
);
1520 ndlp
->nlp_flag
&= ~(NLP_NODEV_REMOVE
| NLP_NPR_2B_DISC
);
1521 spin_unlock_irq(shost
->host_lock
);
1522 lpfc_disc_set_adisc(vport
, ndlp
);
1523 return ndlp
->nlp_state
;
1527 lpfc_rcv_plogi_reglogin_issue(struct lpfc_vport
*vport
,
1528 struct lpfc_nodelist
*ndlp
,
1532 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1534 lpfc_rcv_plogi(vport
, ndlp
, cmdiocb
);
1535 return ndlp
->nlp_state
;
1539 lpfc_rcv_prli_reglogin_issue(struct lpfc_vport
*vport
,
1540 struct lpfc_nodelist
*ndlp
,
1544 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1547 if (vport
->phba
->nvmet_support
) {
1548 /* NVME Target mode. Handle and respond to the PRLI and
1549 * transition to UNMAPPED provided the RPI has completed
1552 if (ndlp
->nlp_flag
& NLP_RPI_REGISTERED
) {
1553 lpfc_rcv_prli(vport
, ndlp
, cmdiocb
);
1554 lpfc_els_rsp_prli_acc(vport
, cmdiocb
, ndlp
);
1555 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
1557 /* RPI registration has not completed. Reject the PRLI
1558 * to prevent an illegal state transition when the
1559 * rpi registration does complete.
1561 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_NVME_DISC
,
1562 "6115 NVMET ndlp rpi %d state "
1563 "unknown, state x%x flags x%08x\n",
1564 ndlp
->nlp_rpi
, ndlp
->nlp_state
,
1566 memset(&stat
, 0, sizeof(struct ls_rjt
));
1567 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
1568 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CMD_IN_PROGRESS
;
1569 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
,
1573 /* Initiator mode. */
1574 lpfc_els_rsp_prli_acc(vport
, cmdiocb
, ndlp
);
1577 return ndlp
->nlp_state
;
1581 lpfc_rcv_logo_reglogin_issue(struct lpfc_vport
*vport
,
1582 struct lpfc_nodelist
*ndlp
,
1586 struct lpfc_hba
*phba
= vport
->phba
;
1587 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1589 LPFC_MBOXQ_t
*nextmb
;
1590 struct lpfc_dmabuf
*mp
;
1592 cmdiocb
= (struct lpfc_iocbq
*) arg
;
1594 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
1595 if ((mb
= phba
->sli
.mbox_active
)) {
1596 if ((mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) &&
1597 (ndlp
== (struct lpfc_nodelist
*) mb
->context2
)) {
1598 ndlp
->nlp_flag
&= ~NLP_REG_LOGIN_SEND
;
1600 mb
->context2
= NULL
;
1601 mb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
1605 spin_lock_irq(&phba
->hbalock
);
1606 list_for_each_entry_safe(mb
, nextmb
, &phba
->sli
.mboxq
, list
) {
1607 if ((mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) &&
1608 (ndlp
== (struct lpfc_nodelist
*) mb
->context2
)) {
1609 mp
= (struct lpfc_dmabuf
*) (mb
->context1
);
1611 __lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
1614 ndlp
->nlp_flag
&= ~NLP_REG_LOGIN_SEND
;
1616 list_del(&mb
->list
);
1617 phba
->sli
.mboxq_cnt
--;
1618 mempool_free(mb
, phba
->mbox_mem_pool
);
1621 spin_unlock_irq(&phba
->hbalock
);
1623 lpfc_rcv_logo(vport
, ndlp
, cmdiocb
, ELS_CMD_LOGO
);
1624 return ndlp
->nlp_state
;
1628 lpfc_rcv_padisc_reglogin_issue(struct lpfc_vport
*vport
,
1629 struct lpfc_nodelist
*ndlp
,
1633 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1635 lpfc_rcv_padisc(vport
, ndlp
, cmdiocb
);
1636 return ndlp
->nlp_state
;
1640 lpfc_rcv_prlo_reglogin_issue(struct lpfc_vport
*vport
,
1641 struct lpfc_nodelist
*ndlp
,
1645 struct lpfc_iocbq
*cmdiocb
;
1647 cmdiocb
= (struct lpfc_iocbq
*) arg
;
1648 lpfc_els_rsp_acc(vport
, ELS_CMD_PRLO
, cmdiocb
, ndlp
, NULL
);
1649 return ndlp
->nlp_state
;
1653 lpfc_cmpl_reglogin_reglogin_issue(struct lpfc_vport
*vport
,
1654 struct lpfc_nodelist
*ndlp
,
1658 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1659 struct lpfc_hba
*phba
= vport
->phba
;
1660 LPFC_MBOXQ_t
*pmb
= (LPFC_MBOXQ_t
*) arg
;
1661 MAILBOX_t
*mb
= &pmb
->u
.mb
;
1662 uint32_t did
= mb
->un
.varWords
[1];
1665 if (mb
->mbxStatus
) {
1666 /* RegLogin failed */
1667 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
1668 "0246 RegLogin failed Data: x%x x%x x%x x%x "
1670 did
, mb
->mbxStatus
, vport
->port_state
,
1671 mb
->un
.varRegLogin
.vpi
,
1672 mb
->un
.varRegLogin
.rpi
);
1674 * If RegLogin failed due to lack of HBA resources do not
1677 if (mb
->mbxStatus
== MBXERR_RPI_FULL
) {
1678 ndlp
->nlp_prev_state
= NLP_STE_REG_LOGIN_ISSUE
;
1679 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1680 return ndlp
->nlp_state
;
1683 /* Put ndlp in npr state set plogi timer for 1 sec */
1684 mod_timer(&ndlp
->nlp_delayfunc
,
1685 jiffies
+ msecs_to_jiffies(1000 * 1));
1686 spin_lock_irq(shost
->host_lock
);
1687 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
1688 spin_unlock_irq(shost
->host_lock
);
1689 ndlp
->nlp_last_elscmd
= ELS_CMD_PLOGI
;
1691 lpfc_issue_els_logo(vport
, ndlp
, 0);
1692 ndlp
->nlp_prev_state
= NLP_STE_REG_LOGIN_ISSUE
;
1693 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1694 return ndlp
->nlp_state
;
1697 /* SLI4 ports have preallocated logical rpis. */
1698 if (phba
->sli_rev
< LPFC_SLI_REV4
)
1699 ndlp
->nlp_rpi
= mb
->un
.varWords
[0];
1701 ndlp
->nlp_flag
|= NLP_RPI_REGISTERED
;
1703 /* Only if we are not a fabric nport do we issue PRLI */
1704 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
1705 "3066 RegLogin Complete on x%x x%x x%x\n",
1706 did
, ndlp
->nlp_type
, ndlp
->nlp_fc4_type
);
1707 if (!(ndlp
->nlp_type
& NLP_FABRIC
) &&
1708 (phba
->nvmet_support
== 0)) {
1709 /* The driver supports FCP and NVME concurrently. If the
1710 * ndlp's nlp_fc4_type is still zero, the driver doesn't
1711 * know what PRLI to send yet. Figure that out now and
1712 * call PRLI depending on the outcome.
1714 if (vport
->fc_flag
& FC_PT2PT
) {
1715 /* If we are pt2pt, there is no Fabric to determine
1716 * the FC4 type of the remote nport. So if NVME
1717 * is configured try it.
1719 ndlp
->nlp_fc4_type
|= NLP_FC4_FCP
;
1720 if ((phba
->cfg_enable_fc4_type
== LPFC_ENABLE_BOTH
) ||
1721 (phba
->cfg_enable_fc4_type
== LPFC_ENABLE_NVME
)) {
1722 ndlp
->nlp_fc4_type
|= NLP_FC4_NVME
;
1723 /* We need to update the localport also */
1724 lpfc_nvme_update_localport(vport
);
1727 } else if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) {
1728 ndlp
->nlp_fc4_type
|= NLP_FC4_FCP
;
1730 } else if (ndlp
->nlp_fc4_type
== 0) {
1731 rc
= lpfc_ns_cmd(vport
, SLI_CTNS_GFT_ID
,
1733 return ndlp
->nlp_state
;
1736 ndlp
->nlp_prev_state
= NLP_STE_REG_LOGIN_ISSUE
;
1737 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PRLI_ISSUE
);
1738 lpfc_issue_els_prli(vport
, ndlp
, 0);
1740 if ((vport
->fc_flag
& FC_PT2PT
) && phba
->nvmet_support
)
1741 phba
->targetport
->port_id
= vport
->fc_myDID
;
1743 /* Only Fabric ports should transition. NVME target
1744 * must complete PRLI.
1746 if (ndlp
->nlp_type
& NLP_FABRIC
) {
1747 ndlp
->nlp_prev_state
= NLP_STE_REG_LOGIN_ISSUE
;
1748 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
1751 return ndlp
->nlp_state
;
1755 lpfc_device_rm_reglogin_issue(struct lpfc_vport
*vport
,
1756 struct lpfc_nodelist
*ndlp
,
1760 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1762 if (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) {
1763 spin_lock_irq(shost
->host_lock
);
1764 ndlp
->nlp_flag
|= NLP_NODEV_REMOVE
;
1765 spin_unlock_irq(shost
->host_lock
);
1766 return ndlp
->nlp_state
;
1768 lpfc_drop_node(vport
, ndlp
);
1769 return NLP_STE_FREED_NODE
;
1774 lpfc_device_recov_reglogin_issue(struct lpfc_vport
*vport
,
1775 struct lpfc_nodelist
*ndlp
,
1779 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1781 /* Don't do anything that will mess up processing of the
1784 if (vport
->fc_flag
& FC_RSCN_DEFERRED
)
1785 return ndlp
->nlp_state
;
1787 ndlp
->nlp_prev_state
= NLP_STE_REG_LOGIN_ISSUE
;
1788 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1789 spin_lock_irq(shost
->host_lock
);
1791 /* If we are a target we won't immediately transition into PRLI,
1792 * so if REG_LOGIN already completed we don't need to ignore it.
1794 if (!(ndlp
->nlp_flag
& NLP_RPI_REGISTERED
) ||
1795 !vport
->phba
->nvmet_support
)
1796 ndlp
->nlp_flag
|= NLP_IGNR_REG_CMPL
;
1798 ndlp
->nlp_flag
&= ~(NLP_NODEV_REMOVE
| NLP_NPR_2B_DISC
);
1799 spin_unlock_irq(shost
->host_lock
);
1800 lpfc_disc_set_adisc(vport
, ndlp
);
1801 return ndlp
->nlp_state
;
1805 lpfc_rcv_plogi_prli_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1806 void *arg
, uint32_t evt
)
1808 struct lpfc_iocbq
*cmdiocb
;
1810 cmdiocb
= (struct lpfc_iocbq
*) arg
;
1812 lpfc_rcv_plogi(vport
, ndlp
, cmdiocb
);
1813 return ndlp
->nlp_state
;
1817 lpfc_rcv_prli_prli_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1818 void *arg
, uint32_t evt
)
1820 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1822 lpfc_els_rsp_prli_acc(vport
, cmdiocb
, ndlp
);
1823 return ndlp
->nlp_state
;
1827 lpfc_rcv_logo_prli_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1828 void *arg
, uint32_t evt
)
1830 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1832 /* Software abort outstanding PRLI before sending acc */
1833 lpfc_els_abort(vport
->phba
, ndlp
);
1835 lpfc_rcv_logo(vport
, ndlp
, cmdiocb
, ELS_CMD_LOGO
);
1836 return ndlp
->nlp_state
;
1840 lpfc_rcv_padisc_prli_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1841 void *arg
, uint32_t evt
)
1843 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1845 lpfc_rcv_padisc(vport
, ndlp
, cmdiocb
);
1846 return ndlp
->nlp_state
;
1849 /* This routine is envoked when we rcv a PRLO request from a nport
1850 * we are logged into. We should send back a PRLO rsp setting the
1852 * NEXT STATE = PRLI_ISSUE
1855 lpfc_rcv_prlo_prli_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1856 void *arg
, uint32_t evt
)
1858 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1860 lpfc_els_rsp_acc(vport
, ELS_CMD_PRLO
, cmdiocb
, ndlp
, NULL
);
1861 return ndlp
->nlp_state
;
1865 lpfc_cmpl_prli_prli_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1866 void *arg
, uint32_t evt
)
1868 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1869 struct lpfc_iocbq
*cmdiocb
, *rspiocb
;
1870 struct lpfc_hba
*phba
= vport
->phba
;
1873 struct lpfc_nvme_prli
*nvpr
;
1876 cmdiocb
= (struct lpfc_iocbq
*) arg
;
1877 rspiocb
= cmdiocb
->context_un
.rsp_iocb
;
1879 /* A solicited PRLI is either FCP or NVME. The PRLI cmd/rsp
1880 * format is different so NULL the two PRLI types so that the
1881 * driver correctly gets the correct context.
1885 temp_ptr
= lpfc_check_elscmpl_iocb(phba
, cmdiocb
, rspiocb
);
1886 if (cmdiocb
->iocb_flag
& LPFC_PRLI_FCP_REQ
)
1887 npr
= (PRLI
*) temp_ptr
;
1888 else if (cmdiocb
->iocb_flag
& LPFC_PRLI_NVME_REQ
)
1889 nvpr
= (struct lpfc_nvme_prli
*) temp_ptr
;
1891 irsp
= &rspiocb
->iocb
;
1892 if (irsp
->ulpStatus
) {
1893 if ((vport
->port_type
== LPFC_NPIV_PORT
) &&
1894 vport
->cfg_restrict_login
) {
1898 /* When the rport rejected the FCP PRLI as unsupported.
1899 * This should only happen in Pt2Pt so an NVME PRLI
1900 * should be outstanding still.
1902 if (npr
&& ndlp
->nlp_flag
& NLP_FCP_PRLI_RJT
) {
1903 ndlp
->nlp_fc4_type
&= ~NLP_FC4_FCP
;
1907 /* The LS Req had some error. Don't let this be a
1910 if ((ndlp
->fc4_prli_sent
== 1) &&
1911 (ndlp
->nlp_state
== NLP_STE_PRLI_ISSUE
) &&
1912 (ndlp
->nlp_type
& (NLP_FCP_TARGET
| NLP_FCP_INITIATOR
)))
1913 /* The FCP PRLI completed successfully but
1914 * the NVME PRLI failed. Since they are sent in
1915 * succession, allow the FCP to complete.
1919 ndlp
->nlp_prev_state
= NLP_STE_PRLI_ISSUE
;
1920 ndlp
->nlp_type
|= NLP_FCP_INITIATOR
;
1921 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
1922 return ndlp
->nlp_state
;
1925 /* Check out PRLI rsp */
1926 ndlp
->nlp_type
&= ~(NLP_FCP_TARGET
| NLP_FCP_INITIATOR
);
1927 ndlp
->nlp_fcp_info
&= ~NLP_FCP_2_DEVICE
;
1929 /* NVME or FCP first burst must be negotiated for each PRLI. */
1930 ndlp
->nlp_flag
&= ~NLP_FIRSTBURST
;
1931 ndlp
->nvme_fb_size
= 0;
1932 if (npr
&& (npr
->acceptRspCode
== PRLI_REQ_EXECUTED
) &&
1933 (npr
->prliType
== PRLI_FCP_TYPE
)) {
1934 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NVME_DISC
,
1935 "6028 FCP NPR PRLI Cmpl Init %d Target %d\n",
1938 if (npr
->initiatorFunc
)
1939 ndlp
->nlp_type
|= NLP_FCP_INITIATOR
;
1940 if (npr
->targetFunc
) {
1941 ndlp
->nlp_type
|= NLP_FCP_TARGET
;
1942 if (npr
->writeXferRdyDis
)
1943 ndlp
->nlp_flag
|= NLP_FIRSTBURST
;
1946 ndlp
->nlp_fcp_info
|= NLP_FCP_2_DEVICE
;
1948 /* PRLI completed. Decrement count. */
1949 ndlp
->fc4_prli_sent
--;
1951 (bf_get_be32(prli_acc_rsp_code
, nvpr
) ==
1952 PRLI_REQ_EXECUTED
) &&
1953 (bf_get_be32(prli_type_code
, nvpr
) ==
1956 /* Complete setting up the remote ndlp personality. */
1957 if (bf_get_be32(prli_init
, nvpr
))
1958 ndlp
->nlp_type
|= NLP_NVME_INITIATOR
;
1960 /* Target driver cannot solicit NVME FB. */
1961 if (bf_get_be32(prli_tgt
, nvpr
)) {
1962 /* Complete the nvme target roles. The transport
1963 * needs to know if the rport is capable of
1964 * discovery in addition to its role.
1966 ndlp
->nlp_type
|= NLP_NVME_TARGET
;
1967 if (bf_get_be32(prli_disc
, nvpr
))
1968 ndlp
->nlp_type
|= NLP_NVME_DISCOVERY
;
1969 if ((bf_get_be32(prli_fba
, nvpr
) == 1) &&
1970 (bf_get_be32(prli_fb_sz
, nvpr
) > 0) &&
1971 (phba
->cfg_nvme_enable_fb
) &&
1972 (!phba
->nvmet_support
)) {
1973 /* Both sides support FB. The target's first
1974 * burst size is a 512 byte encoded value.
1976 ndlp
->nlp_flag
|= NLP_FIRSTBURST
;
1977 ndlp
->nvme_fb_size
= bf_get_be32(prli_fb_sz
,
1982 if (bf_get_be32(prli_recov
, nvpr
))
1983 ndlp
->nlp_fcp_info
|= NLP_FCP_2_DEVICE
;
1985 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NVME_DISC
,
1986 "6029 NVME PRLI Cmpl w1 x%08x "
1987 "w4 x%08x w5 x%08x flag x%x, "
1988 "fcp_info x%x nlp_type x%x\n",
1989 be32_to_cpu(nvpr
->word1
),
1990 be32_to_cpu(nvpr
->word4
),
1991 be32_to_cpu(nvpr
->word5
),
1992 ndlp
->nlp_flag
, ndlp
->nlp_fcp_info
,
1994 /* PRLI completed. Decrement count. */
1995 ndlp
->fc4_prli_sent
--;
1997 if (!(ndlp
->nlp_type
& NLP_FCP_TARGET
) &&
1998 (vport
->port_type
== LPFC_NPIV_PORT
) &&
1999 vport
->cfg_restrict_login
) {
2001 spin_lock_irq(shost
->host_lock
);
2002 ndlp
->nlp_flag
|= NLP_TARGET_REMOVE
;
2003 spin_unlock_irq(shost
->host_lock
);
2004 lpfc_issue_els_logo(vport
, ndlp
, 0);
2006 ndlp
->nlp_prev_state
= NLP_STE_PRLI_ISSUE
;
2007 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
2008 return ndlp
->nlp_state
;
2012 /* The ndlp state cannot move to MAPPED or UNMAPPED before all PRLIs
2015 if (ndlp
->fc4_prli_sent
== 0) {
2016 ndlp
->nlp_prev_state
= NLP_STE_PRLI_ISSUE
;
2017 if (ndlp
->nlp_type
& (NLP_FCP_TARGET
| NLP_NVME_TARGET
))
2018 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_MAPPED_NODE
);
2020 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
2022 lpfc_printf_vlog(vport
,
2024 "3067 PRLI's still outstanding "
2025 "on x%06x - count %d, Pend Node Mode "
2027 ndlp
->nlp_DID
, ndlp
->fc4_prli_sent
);
2029 return ndlp
->nlp_state
;
2032 /*! lpfc_device_rm_prli_issue
2043 * This routine is envoked when we a request to remove a nport we are in the
2044 * process of PRLIing. We should software abort outstanding prli, unreg
2045 * login, send a logout. We will change node state to UNUSED_NODE, put it
2046 * on plogi list so it can be freed when LOGO completes.
2051 lpfc_device_rm_prli_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2052 void *arg
, uint32_t evt
)
2054 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2056 if (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) {
2057 spin_lock_irq(shost
->host_lock
);
2058 ndlp
->nlp_flag
|= NLP_NODEV_REMOVE
;
2059 spin_unlock_irq(shost
->host_lock
);
2060 return ndlp
->nlp_state
;
2062 /* software abort outstanding PLOGI */
2063 lpfc_els_abort(vport
->phba
, ndlp
);
2065 lpfc_drop_node(vport
, ndlp
);
2066 return NLP_STE_FREED_NODE
;
2071 /*! lpfc_device_recov_prli_issue
2082 * The routine is envoked when the state of a device is unknown, like
2083 * during a link down. We should remove the nodelist entry from the
2084 * unmapped list, issue a UNREG_LOGIN, do a software abort of the
2085 * outstanding PRLI command, then free the node entry.
2088 lpfc_device_recov_prli_issue(struct lpfc_vport
*vport
,
2089 struct lpfc_nodelist
*ndlp
,
2093 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2094 struct lpfc_hba
*phba
= vport
->phba
;
2096 /* Don't do anything that will mess up processing of the
2099 if (vport
->fc_flag
& FC_RSCN_DEFERRED
)
2100 return ndlp
->nlp_state
;
2102 /* software abort outstanding PRLI */
2103 lpfc_els_abort(phba
, ndlp
);
2105 ndlp
->nlp_prev_state
= NLP_STE_PRLI_ISSUE
;
2106 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
2107 spin_lock_irq(shost
->host_lock
);
2108 ndlp
->nlp_flag
&= ~(NLP_NODEV_REMOVE
| NLP_NPR_2B_DISC
);
2109 spin_unlock_irq(shost
->host_lock
);
2110 lpfc_disc_set_adisc(vport
, ndlp
);
2111 return ndlp
->nlp_state
;
2115 lpfc_rcv_plogi_logo_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2116 void *arg
, uint32_t evt
)
2118 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*)arg
;
2121 memset(&stat
, 0, sizeof(struct ls_rjt
));
2122 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
2123 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_NOTHING_MORE
;
2124 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
2125 return ndlp
->nlp_state
;
2129 lpfc_rcv_prli_logo_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2130 void *arg
, uint32_t evt
)
2132 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*)arg
;
2135 memset(&stat
, 0, sizeof(struct ls_rjt
));
2136 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
2137 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_NOTHING_MORE
;
2138 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
2139 return ndlp
->nlp_state
;
2143 lpfc_rcv_logo_logo_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2144 void *arg
, uint32_t evt
)
2146 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2147 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*)arg
;
2149 spin_lock_irq(shost
->host_lock
);
2150 ndlp
->nlp_flag
|= NLP_LOGO_ACC
;
2151 spin_unlock_irq(shost
->host_lock
);
2152 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
2153 return ndlp
->nlp_state
;
2157 lpfc_rcv_padisc_logo_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2158 void *arg
, uint32_t evt
)
2160 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*)arg
;
2163 memset(&stat
, 0, sizeof(struct ls_rjt
));
2164 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
2165 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_NOTHING_MORE
;
2166 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
2167 return ndlp
->nlp_state
;
2171 lpfc_rcv_prlo_logo_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2172 void *arg
, uint32_t evt
)
2174 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*)arg
;
2177 memset(&stat
, 0, sizeof(struct ls_rjt
));
2178 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
2179 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_NOTHING_MORE
;
2180 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
2181 return ndlp
->nlp_state
;
2185 lpfc_cmpl_logo_logo_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2186 void *arg
, uint32_t evt
)
2188 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2190 ndlp
->nlp_prev_state
= NLP_STE_LOGO_ISSUE
;
2191 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
2192 spin_lock_irq(shost
->host_lock
);
2193 ndlp
->nlp_flag
&= ~(NLP_NODEV_REMOVE
| NLP_NPR_2B_DISC
);
2194 spin_unlock_irq(shost
->host_lock
);
2195 lpfc_disc_set_adisc(vport
, ndlp
);
2196 return ndlp
->nlp_state
;
2200 lpfc_device_rm_logo_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2201 void *arg
, uint32_t evt
)
2204 * DevLoss has timed out and is calling for Device Remove.
2205 * In this case, abort the LOGO and cleanup the ndlp
2208 lpfc_unreg_rpi(vport
, ndlp
);
2209 /* software abort outstanding PLOGI */
2210 lpfc_els_abort(vport
->phba
, ndlp
);
2211 lpfc_drop_node(vport
, ndlp
);
2212 return NLP_STE_FREED_NODE
;
2216 lpfc_device_recov_logo_issue(struct lpfc_vport
*vport
,
2217 struct lpfc_nodelist
*ndlp
,
2218 void *arg
, uint32_t evt
)
2221 * Device Recovery events have no meaning for a node with a LOGO
2222 * outstanding. The LOGO has to complete first and handle the
2223 * node from that point.
2225 return ndlp
->nlp_state
;
2229 lpfc_rcv_plogi_unmap_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2230 void *arg
, uint32_t evt
)
2232 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2234 lpfc_rcv_plogi(vport
, ndlp
, cmdiocb
);
2235 return ndlp
->nlp_state
;
2239 lpfc_rcv_prli_unmap_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2240 void *arg
, uint32_t evt
)
2242 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2244 lpfc_rcv_prli(vport
, ndlp
, cmdiocb
);
2245 lpfc_els_rsp_prli_acc(vport
, cmdiocb
, ndlp
);
2246 return ndlp
->nlp_state
;
2250 lpfc_rcv_logo_unmap_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2251 void *arg
, uint32_t evt
)
2253 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2255 lpfc_rcv_logo(vport
, ndlp
, cmdiocb
, ELS_CMD_LOGO
);
2256 return ndlp
->nlp_state
;
2260 lpfc_rcv_padisc_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_padisc(vport
, ndlp
, cmdiocb
);
2266 return ndlp
->nlp_state
;
2270 lpfc_rcv_prlo_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 lpfc_els_rsp_acc(vport
, ELS_CMD_PRLO
, cmdiocb
, ndlp
, NULL
);
2276 return ndlp
->nlp_state
;
2280 lpfc_device_recov_unmap_node(struct lpfc_vport
*vport
,
2281 struct lpfc_nodelist
*ndlp
,
2285 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2287 ndlp
->nlp_prev_state
= NLP_STE_UNMAPPED_NODE
;
2288 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
2289 spin_lock_irq(shost
->host_lock
);
2290 ndlp
->nlp_flag
&= ~(NLP_NODEV_REMOVE
| NLP_NPR_2B_DISC
);
2291 spin_unlock_irq(shost
->host_lock
);
2292 lpfc_disc_set_adisc(vport
, ndlp
);
2294 return ndlp
->nlp_state
;
2298 lpfc_rcv_plogi_mapped_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2299 void *arg
, uint32_t evt
)
2301 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2303 lpfc_rcv_plogi(vport
, ndlp
, cmdiocb
);
2304 return ndlp
->nlp_state
;
2308 lpfc_rcv_prli_mapped_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2309 void *arg
, uint32_t evt
)
2311 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2313 lpfc_els_rsp_prli_acc(vport
, cmdiocb
, ndlp
);
2314 return ndlp
->nlp_state
;
2318 lpfc_rcv_logo_mapped_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2319 void *arg
, uint32_t evt
)
2321 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2323 lpfc_rcv_logo(vport
, ndlp
, cmdiocb
, ELS_CMD_LOGO
);
2324 return ndlp
->nlp_state
;
2328 lpfc_rcv_padisc_mapped_node(struct lpfc_vport
*vport
,
2329 struct lpfc_nodelist
*ndlp
,
2330 void *arg
, uint32_t evt
)
2332 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2334 lpfc_rcv_padisc(vport
, ndlp
, cmdiocb
);
2335 return ndlp
->nlp_state
;
2339 lpfc_rcv_prlo_mapped_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2340 void *arg
, uint32_t evt
)
2342 struct lpfc_hba
*phba
= vport
->phba
;
2343 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2345 /* flush the target */
2346 lpfc_sli_abort_iocb(vport
, &phba
->sli
.sli3_ring
[LPFC_FCP_RING
],
2347 ndlp
->nlp_sid
, 0, LPFC_CTX_TGT
);
2349 /* Treat like rcv logo */
2350 lpfc_rcv_logo(vport
, ndlp
, cmdiocb
, ELS_CMD_PRLO
);
2351 return ndlp
->nlp_state
;
2355 lpfc_device_recov_mapped_node(struct lpfc_vport
*vport
,
2356 struct lpfc_nodelist
*ndlp
,
2360 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2362 ndlp
->nlp_prev_state
= NLP_STE_MAPPED_NODE
;
2363 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
2364 spin_lock_irq(shost
->host_lock
);
2365 ndlp
->nlp_flag
&= ~(NLP_NODEV_REMOVE
| NLP_NPR_2B_DISC
);
2366 spin_unlock_irq(shost
->host_lock
);
2367 lpfc_disc_set_adisc(vport
, ndlp
);
2368 return ndlp
->nlp_state
;
2372 lpfc_rcv_plogi_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2373 void *arg
, uint32_t evt
)
2375 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2376 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2378 /* Ignore PLOGI if we have an outstanding LOGO */
2379 if (ndlp
->nlp_flag
& (NLP_LOGO_SND
| NLP_LOGO_ACC
))
2380 return ndlp
->nlp_state
;
2381 if (lpfc_rcv_plogi(vport
, ndlp
, cmdiocb
)) {
2382 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
2383 spin_lock_irq(shost
->host_lock
);
2384 ndlp
->nlp_flag
&= ~(NLP_NPR_ADISC
| NLP_NPR_2B_DISC
);
2385 spin_unlock_irq(shost
->host_lock
);
2386 } else if (!(ndlp
->nlp_flag
& NLP_NPR_2B_DISC
)) {
2387 /* send PLOGI immediately, move to PLOGI issue state */
2388 if (!(ndlp
->nlp_flag
& NLP_DELAY_TMO
)) {
2389 ndlp
->nlp_prev_state
= NLP_STE_NPR_NODE
;
2390 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
2391 lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0);
2394 return ndlp
->nlp_state
;
2398 lpfc_rcv_prli_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2399 void *arg
, uint32_t evt
)
2401 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2402 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2405 memset(&stat
, 0, sizeof (struct ls_rjt
));
2406 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
2407 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_NOTHING_MORE
;
2408 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
2410 if (!(ndlp
->nlp_flag
& NLP_DELAY_TMO
)) {
2411 if (ndlp
->nlp_flag
& NLP_NPR_ADISC
) {
2412 spin_lock_irq(shost
->host_lock
);
2413 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
2414 ndlp
->nlp_prev_state
= NLP_STE_NPR_NODE
;
2415 spin_unlock_irq(shost
->host_lock
);
2416 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_ADISC_ISSUE
);
2417 lpfc_issue_els_adisc(vport
, ndlp
, 0);
2419 ndlp
->nlp_prev_state
= NLP_STE_NPR_NODE
;
2420 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
2421 lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0);
2424 return ndlp
->nlp_state
;
2428 lpfc_rcv_logo_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2429 void *arg
, uint32_t evt
)
2431 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2433 lpfc_rcv_logo(vport
, ndlp
, cmdiocb
, ELS_CMD_LOGO
);
2434 return ndlp
->nlp_state
;
2438 lpfc_rcv_padisc_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2439 void *arg
, uint32_t evt
)
2441 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2443 lpfc_rcv_padisc(vport
, ndlp
, cmdiocb
);
2445 * Do not start discovery if discovery is about to start
2446 * or discovery in progress for this node. Starting discovery
2447 * here will affect the counting of discovery threads.
2449 if (!(ndlp
->nlp_flag
& NLP_DELAY_TMO
) &&
2450 !(ndlp
->nlp_flag
& NLP_NPR_2B_DISC
)) {
2451 if (ndlp
->nlp_flag
& NLP_NPR_ADISC
) {
2452 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
2453 ndlp
->nlp_prev_state
= NLP_STE_NPR_NODE
;
2454 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_ADISC_ISSUE
);
2455 lpfc_issue_els_adisc(vport
, ndlp
, 0);
2457 ndlp
->nlp_prev_state
= NLP_STE_NPR_NODE
;
2458 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
2459 lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0);
2462 return ndlp
->nlp_state
;
2466 lpfc_rcv_prlo_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2467 void *arg
, uint32_t evt
)
2469 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2470 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2472 spin_lock_irq(shost
->host_lock
);
2473 ndlp
->nlp_flag
|= NLP_LOGO_ACC
;
2474 spin_unlock_irq(shost
->host_lock
);
2476 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
2478 if ((ndlp
->nlp_flag
& NLP_DELAY_TMO
) == 0) {
2479 mod_timer(&ndlp
->nlp_delayfunc
,
2480 jiffies
+ msecs_to_jiffies(1000 * 1));
2481 spin_lock_irq(shost
->host_lock
);
2482 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
2483 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
2484 spin_unlock_irq(shost
->host_lock
);
2485 ndlp
->nlp_last_elscmd
= ELS_CMD_PLOGI
;
2487 spin_lock_irq(shost
->host_lock
);
2488 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
2489 spin_unlock_irq(shost
->host_lock
);
2491 return ndlp
->nlp_state
;
2495 lpfc_cmpl_plogi_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2496 void *arg
, uint32_t evt
)
2498 struct lpfc_iocbq
*cmdiocb
, *rspiocb
;
2500 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2502 cmdiocb
= (struct lpfc_iocbq
*) arg
;
2503 rspiocb
= cmdiocb
->context_un
.rsp_iocb
;
2505 irsp
= &rspiocb
->iocb
;
2506 if (irsp
->ulpStatus
) {
2507 spin_lock_irq(shost
->host_lock
);
2508 ndlp
->nlp_flag
|= NLP_DEFER_RM
;
2509 spin_unlock_irq(shost
->host_lock
);
2510 return NLP_STE_FREED_NODE
;
2512 return ndlp
->nlp_state
;
2516 lpfc_cmpl_prli_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2517 void *arg
, uint32_t evt
)
2519 struct lpfc_iocbq
*cmdiocb
, *rspiocb
;
2522 cmdiocb
= (struct lpfc_iocbq
*) arg
;
2523 rspiocb
= cmdiocb
->context_un
.rsp_iocb
;
2525 irsp
= &rspiocb
->iocb
;
2526 if (irsp
->ulpStatus
&& (ndlp
->nlp_flag
& NLP_NODEV_REMOVE
)) {
2527 lpfc_drop_node(vport
, ndlp
);
2528 return NLP_STE_FREED_NODE
;
2530 return ndlp
->nlp_state
;
2534 lpfc_cmpl_logo_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2535 void *arg
, uint32_t evt
)
2537 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2539 /* For the fabric port just clear the fc flags. */
2540 if (ndlp
->nlp_DID
== Fabric_DID
) {
2541 spin_lock_irq(shost
->host_lock
);
2542 vport
->fc_flag
&= ~(FC_FABRIC
| FC_PUBLIC_LOOP
);
2543 spin_unlock_irq(shost
->host_lock
);
2545 lpfc_unreg_rpi(vport
, ndlp
);
2546 return ndlp
->nlp_state
;
2550 lpfc_cmpl_adisc_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2551 void *arg
, uint32_t evt
)
2553 struct lpfc_iocbq
*cmdiocb
, *rspiocb
;
2556 cmdiocb
= (struct lpfc_iocbq
*) arg
;
2557 rspiocb
= cmdiocb
->context_un
.rsp_iocb
;
2559 irsp
= &rspiocb
->iocb
;
2560 if (irsp
->ulpStatus
&& (ndlp
->nlp_flag
& NLP_NODEV_REMOVE
)) {
2561 lpfc_drop_node(vport
, ndlp
);
2562 return NLP_STE_FREED_NODE
;
2564 return ndlp
->nlp_state
;
2568 lpfc_cmpl_reglogin_npr_node(struct lpfc_vport
*vport
,
2569 struct lpfc_nodelist
*ndlp
,
2570 void *arg
, uint32_t evt
)
2572 LPFC_MBOXQ_t
*pmb
= (LPFC_MBOXQ_t
*) arg
;
2573 MAILBOX_t
*mb
= &pmb
->u
.mb
;
2575 if (!mb
->mbxStatus
) {
2576 /* SLI4 ports have preallocated logical rpis. */
2577 if (vport
->phba
->sli_rev
< LPFC_SLI_REV4
)
2578 ndlp
->nlp_rpi
= mb
->un
.varWords
[0];
2579 ndlp
->nlp_flag
|= NLP_RPI_REGISTERED
;
2580 if (ndlp
->nlp_flag
& NLP_LOGO_ACC
) {
2581 lpfc_unreg_rpi(vport
, ndlp
);
2584 if (ndlp
->nlp_flag
& NLP_NODEV_REMOVE
) {
2585 lpfc_drop_node(vport
, ndlp
);
2586 return NLP_STE_FREED_NODE
;
2589 return ndlp
->nlp_state
;
2593 lpfc_device_rm_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2594 void *arg
, uint32_t evt
)
2596 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2598 if (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) {
2599 spin_lock_irq(shost
->host_lock
);
2600 ndlp
->nlp_flag
|= NLP_NODEV_REMOVE
;
2601 spin_unlock_irq(shost
->host_lock
);
2602 return ndlp
->nlp_state
;
2604 lpfc_drop_node(vport
, ndlp
);
2605 return NLP_STE_FREED_NODE
;
2609 lpfc_device_recov_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2610 void *arg
, uint32_t evt
)
2612 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2614 /* Don't do anything that will mess up processing of the
2617 if (vport
->fc_flag
& FC_RSCN_DEFERRED
)
2618 return ndlp
->nlp_state
;
2620 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
2621 spin_lock_irq(shost
->host_lock
);
2622 ndlp
->nlp_flag
&= ~(NLP_NODEV_REMOVE
| NLP_NPR_2B_DISC
);
2623 spin_unlock_irq(shost
->host_lock
);
2624 return ndlp
->nlp_state
;
2628 /* This next section defines the NPort Discovery State Machine */
2630 /* There are 4 different double linked lists nodelist entries can reside on.
2631 * The plogi list and adisc list are used when Link Up discovery or RSCN
2632 * processing is needed. Each list holds the nodes that we will send PLOGI
2633 * or ADISC on. These lists will keep track of what nodes will be effected
2634 * by an RSCN, or a Link Up (Typically, all nodes are effected on Link Up).
2635 * The unmapped_list will contain all nodes that we have successfully logged
2636 * into at the Fibre Channel level. The mapped_list will contain all nodes
2637 * that are mapped FCP targets.
2640 * The bind list is a list of undiscovered (potentially non-existent) nodes
2641 * that we have saved binding information on. This information is used when
2642 * nodes transition from the unmapped to the mapped list.
2644 /* For UNUSED_NODE state, the node has just been allocated .
2645 * For PLOGI_ISSUE and REG_LOGIN_ISSUE, the node is on
2646 * the PLOGI list. For REG_LOGIN_COMPL, the node is taken off the PLOGI list
2647 * and put on the unmapped list. For ADISC processing, the node is taken off
2648 * the ADISC list and placed on either the mapped or unmapped list (depending
2649 * on its previous state). Once on the unmapped list, a PRLI is issued and the
2650 * state changed to PRLI_ISSUE. When the PRLI completion occurs, the state is
2651 * changed to UNMAPPED_NODE. If the completion indicates a mapped
2652 * node, the node is taken off the unmapped list. The binding list is checked
2653 * for a valid binding, or a binding is automatically assigned. If binding
2654 * assignment is unsuccessful, the node is left on the unmapped list. If
2655 * binding assignment is successful, the associated binding list entry (if
2656 * any) is removed, and the node is placed on the mapped list.
2659 * For a Link Down, all nodes on the ADISC, PLOGI, unmapped or mapped
2660 * lists will receive a DEVICE_RECOVERY event. If the linkdown or devloss timers
2661 * expire, all effected nodes will receive a DEVICE_RM event.
2664 * For a Link Up or RSCN, all nodes will move from the mapped / unmapped lists
2665 * to either the ADISC or PLOGI list. After a Nameserver query or ALPA loopmap
2666 * check, additional nodes may be added or removed (via DEVICE_RM) to / from
2667 * the PLOGI or ADISC lists. Once the PLOGI and ADISC lists are populated,
2668 * we will first process the ADISC list. 32 entries are processed initially and
2669 * ADISC is initited for each one. Completions / Events for each node are
2670 * funnelled thru the state machine. As each node finishes ADISC processing, it
2671 * starts ADISC for any nodes waiting for ADISC processing. If no nodes are
2672 * waiting, and the ADISC list count is identically 0, then we are done. For
2673 * Link Up discovery, since all nodes on the PLOGI list are UNREG_LOGIN'ed, we
2674 * can issue a CLEAR_LA and reenable Link Events. Next we will process the PLOGI
2675 * list. 32 entries are processed initially and PLOGI is initited for each one.
2676 * Completions / Events for each node are funnelled thru the state machine. As
2677 * each node finishes PLOGI processing, it starts PLOGI for any nodes waiting
2678 * for PLOGI processing. If no nodes are waiting, and the PLOGI list count is
2679 * indentically 0, then we are done. We have now completed discovery / RSCN
2680 * handling. Upon completion, ALL nodes should be on either the mapped or
2684 static uint32_t (*lpfc_disc_action
[NLP_STE_MAX_STATE
* NLP_EVT_MAX_EVENT
])
2685 (struct lpfc_vport
*, struct lpfc_nodelist
*, void *, uint32_t) = {
2686 /* Action routine Event Current State */
2687 lpfc_rcv_plogi_unused_node
, /* RCV_PLOGI UNUSED_NODE */
2688 lpfc_rcv_els_unused_node
, /* RCV_PRLI */
2689 lpfc_rcv_logo_unused_node
, /* RCV_LOGO */
2690 lpfc_rcv_els_unused_node
, /* RCV_ADISC */
2691 lpfc_rcv_els_unused_node
, /* RCV_PDISC */
2692 lpfc_rcv_els_unused_node
, /* RCV_PRLO */
2693 lpfc_disc_illegal
, /* CMPL_PLOGI */
2694 lpfc_disc_illegal
, /* CMPL_PRLI */
2695 lpfc_cmpl_logo_unused_node
, /* CMPL_LOGO */
2696 lpfc_disc_illegal
, /* CMPL_ADISC */
2697 lpfc_disc_illegal
, /* CMPL_REG_LOGIN */
2698 lpfc_device_rm_unused_node
, /* DEVICE_RM */
2699 lpfc_device_recov_unused_node
, /* DEVICE_RECOVERY */
2701 lpfc_rcv_plogi_plogi_issue
, /* RCV_PLOGI PLOGI_ISSUE */
2702 lpfc_rcv_prli_plogi_issue
, /* RCV_PRLI */
2703 lpfc_rcv_logo_plogi_issue
, /* RCV_LOGO */
2704 lpfc_rcv_els_plogi_issue
, /* RCV_ADISC */
2705 lpfc_rcv_els_plogi_issue
, /* RCV_PDISC */
2706 lpfc_rcv_els_plogi_issue
, /* RCV_PRLO */
2707 lpfc_cmpl_plogi_plogi_issue
, /* CMPL_PLOGI */
2708 lpfc_disc_illegal
, /* CMPL_PRLI */
2709 lpfc_cmpl_logo_plogi_issue
, /* CMPL_LOGO */
2710 lpfc_disc_illegal
, /* CMPL_ADISC */
2711 lpfc_cmpl_reglogin_plogi_issue
,/* CMPL_REG_LOGIN */
2712 lpfc_device_rm_plogi_issue
, /* DEVICE_RM */
2713 lpfc_device_recov_plogi_issue
, /* DEVICE_RECOVERY */
2715 lpfc_rcv_plogi_adisc_issue
, /* RCV_PLOGI ADISC_ISSUE */
2716 lpfc_rcv_prli_adisc_issue
, /* RCV_PRLI */
2717 lpfc_rcv_logo_adisc_issue
, /* RCV_LOGO */
2718 lpfc_rcv_padisc_adisc_issue
, /* RCV_ADISC */
2719 lpfc_rcv_padisc_adisc_issue
, /* RCV_PDISC */
2720 lpfc_rcv_prlo_adisc_issue
, /* RCV_PRLO */
2721 lpfc_disc_illegal
, /* CMPL_PLOGI */
2722 lpfc_disc_illegal
, /* CMPL_PRLI */
2723 lpfc_disc_illegal
, /* CMPL_LOGO */
2724 lpfc_cmpl_adisc_adisc_issue
, /* CMPL_ADISC */
2725 lpfc_disc_illegal
, /* CMPL_REG_LOGIN */
2726 lpfc_device_rm_adisc_issue
, /* DEVICE_RM */
2727 lpfc_device_recov_adisc_issue
, /* DEVICE_RECOVERY */
2729 lpfc_rcv_plogi_reglogin_issue
, /* RCV_PLOGI REG_LOGIN_ISSUE */
2730 lpfc_rcv_prli_reglogin_issue
, /* RCV_PLOGI */
2731 lpfc_rcv_logo_reglogin_issue
, /* RCV_LOGO */
2732 lpfc_rcv_padisc_reglogin_issue
, /* RCV_ADISC */
2733 lpfc_rcv_padisc_reglogin_issue
, /* RCV_PDISC */
2734 lpfc_rcv_prlo_reglogin_issue
, /* RCV_PRLO */
2735 lpfc_cmpl_plogi_illegal
, /* CMPL_PLOGI */
2736 lpfc_disc_illegal
, /* CMPL_PRLI */
2737 lpfc_disc_illegal
, /* CMPL_LOGO */
2738 lpfc_disc_illegal
, /* CMPL_ADISC */
2739 lpfc_cmpl_reglogin_reglogin_issue
,/* CMPL_REG_LOGIN */
2740 lpfc_device_rm_reglogin_issue
, /* DEVICE_RM */
2741 lpfc_device_recov_reglogin_issue
,/* DEVICE_RECOVERY */
2743 lpfc_rcv_plogi_prli_issue
, /* RCV_PLOGI PRLI_ISSUE */
2744 lpfc_rcv_prli_prli_issue
, /* RCV_PRLI */
2745 lpfc_rcv_logo_prli_issue
, /* RCV_LOGO */
2746 lpfc_rcv_padisc_prli_issue
, /* RCV_ADISC */
2747 lpfc_rcv_padisc_prli_issue
, /* RCV_PDISC */
2748 lpfc_rcv_prlo_prli_issue
, /* RCV_PRLO */
2749 lpfc_cmpl_plogi_illegal
, /* CMPL_PLOGI */
2750 lpfc_cmpl_prli_prli_issue
, /* CMPL_PRLI */
2751 lpfc_disc_illegal
, /* CMPL_LOGO */
2752 lpfc_disc_illegal
, /* CMPL_ADISC */
2753 lpfc_disc_illegal
, /* CMPL_REG_LOGIN */
2754 lpfc_device_rm_prli_issue
, /* DEVICE_RM */
2755 lpfc_device_recov_prli_issue
, /* DEVICE_RECOVERY */
2757 lpfc_rcv_plogi_logo_issue
, /* RCV_PLOGI LOGO_ISSUE */
2758 lpfc_rcv_prli_logo_issue
, /* RCV_PRLI */
2759 lpfc_rcv_logo_logo_issue
, /* RCV_LOGO */
2760 lpfc_rcv_padisc_logo_issue
, /* RCV_ADISC */
2761 lpfc_rcv_padisc_logo_issue
, /* RCV_PDISC */
2762 lpfc_rcv_prlo_logo_issue
, /* RCV_PRLO */
2763 lpfc_cmpl_plogi_illegal
, /* CMPL_PLOGI */
2764 lpfc_disc_illegal
, /* CMPL_PRLI */
2765 lpfc_cmpl_logo_logo_issue
, /* CMPL_LOGO */
2766 lpfc_disc_illegal
, /* CMPL_ADISC */
2767 lpfc_disc_illegal
, /* CMPL_REG_LOGIN */
2768 lpfc_device_rm_logo_issue
, /* DEVICE_RM */
2769 lpfc_device_recov_logo_issue
, /* DEVICE_RECOVERY */
2771 lpfc_rcv_plogi_unmap_node
, /* RCV_PLOGI UNMAPPED_NODE */
2772 lpfc_rcv_prli_unmap_node
, /* RCV_PRLI */
2773 lpfc_rcv_logo_unmap_node
, /* RCV_LOGO */
2774 lpfc_rcv_padisc_unmap_node
, /* RCV_ADISC */
2775 lpfc_rcv_padisc_unmap_node
, /* RCV_PDISC */
2776 lpfc_rcv_prlo_unmap_node
, /* RCV_PRLO */
2777 lpfc_disc_illegal
, /* CMPL_PLOGI */
2778 lpfc_disc_illegal
, /* CMPL_PRLI */
2779 lpfc_disc_illegal
, /* CMPL_LOGO */
2780 lpfc_disc_illegal
, /* CMPL_ADISC */
2781 lpfc_disc_illegal
, /* CMPL_REG_LOGIN */
2782 lpfc_disc_illegal
, /* DEVICE_RM */
2783 lpfc_device_recov_unmap_node
, /* DEVICE_RECOVERY */
2785 lpfc_rcv_plogi_mapped_node
, /* RCV_PLOGI MAPPED_NODE */
2786 lpfc_rcv_prli_mapped_node
, /* RCV_PRLI */
2787 lpfc_rcv_logo_mapped_node
, /* RCV_LOGO */
2788 lpfc_rcv_padisc_mapped_node
, /* RCV_ADISC */
2789 lpfc_rcv_padisc_mapped_node
, /* RCV_PDISC */
2790 lpfc_rcv_prlo_mapped_node
, /* RCV_PRLO */
2791 lpfc_disc_illegal
, /* CMPL_PLOGI */
2792 lpfc_disc_illegal
, /* CMPL_PRLI */
2793 lpfc_disc_illegal
, /* CMPL_LOGO */
2794 lpfc_disc_illegal
, /* CMPL_ADISC */
2795 lpfc_disc_illegal
, /* CMPL_REG_LOGIN */
2796 lpfc_disc_illegal
, /* DEVICE_RM */
2797 lpfc_device_recov_mapped_node
, /* DEVICE_RECOVERY */
2799 lpfc_rcv_plogi_npr_node
, /* RCV_PLOGI NPR_NODE */
2800 lpfc_rcv_prli_npr_node
, /* RCV_PRLI */
2801 lpfc_rcv_logo_npr_node
, /* RCV_LOGO */
2802 lpfc_rcv_padisc_npr_node
, /* RCV_ADISC */
2803 lpfc_rcv_padisc_npr_node
, /* RCV_PDISC */
2804 lpfc_rcv_prlo_npr_node
, /* RCV_PRLO */
2805 lpfc_cmpl_plogi_npr_node
, /* CMPL_PLOGI */
2806 lpfc_cmpl_prli_npr_node
, /* CMPL_PRLI */
2807 lpfc_cmpl_logo_npr_node
, /* CMPL_LOGO */
2808 lpfc_cmpl_adisc_npr_node
, /* CMPL_ADISC */
2809 lpfc_cmpl_reglogin_npr_node
, /* CMPL_REG_LOGIN */
2810 lpfc_device_rm_npr_node
, /* DEVICE_RM */
2811 lpfc_device_recov_npr_node
, /* DEVICE_RECOVERY */
2815 lpfc_disc_state_machine(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2816 void *arg
, uint32_t evt
)
2818 uint32_t cur_state
, rc
;
2819 uint32_t(*func
) (struct lpfc_vport
*, struct lpfc_nodelist
*, void *,
2821 uint32_t got_ndlp
= 0;
2823 if (lpfc_nlp_get(ndlp
))
2826 cur_state
= ndlp
->nlp_state
;
2828 /* DSM in event <evt> on NPort <nlp_DID> in state <cur_state> */
2829 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
2830 "0211 DSM in event x%x on NPort x%x in "
2831 "state %d Data: x%x\n",
2832 evt
, ndlp
->nlp_DID
, cur_state
, ndlp
->nlp_flag
);
2834 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_DSM
,
2835 "DSM in: evt:%d ste:%d did:x%x",
2836 evt
, cur_state
, ndlp
->nlp_DID
);
2838 func
= lpfc_disc_action
[(cur_state
* NLP_EVT_MAX_EVENT
) + evt
];
2839 rc
= (func
) (vport
, ndlp
, arg
, evt
);
2841 /* DSM out state <rc> on NPort <nlp_DID> */
2843 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
2844 "0212 DSM out state %d on NPort x%x Data: x%x\n",
2845 rc
, ndlp
->nlp_DID
, ndlp
->nlp_flag
);
2847 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_DSM
,
2848 "DSM out: ste:%d did:x%x flg:x%x",
2849 rc
, ndlp
->nlp_DID
, ndlp
->nlp_flag
);
2850 /* Decrement the ndlp reference count held for this function */
2853 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
2854 "0213 DSM out state %d on NPort free\n", rc
);
2856 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_DSM
,
2857 "DSM out: ste:%d did:x%x flg:x%x",