1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2013 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. *
7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
9 * This program is free software; you can redistribute it and/or *
10 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
20 *******************************************************************/
22 #include <linux/blkdev.h>
23 #include <linux/pci.h>
24 #include <linux/slab.h>
25 #include <linux/interrupt.h>
27 #include <scsi/scsi.h>
28 #include <scsi/scsi_device.h>
29 #include <scsi/scsi_host.h>
30 #include <scsi/scsi_transport_fc.h>
35 #include "lpfc_sli4.h"
37 #include "lpfc_disc.h"
38 #include "lpfc_scsi.h"
40 #include "lpfc_logmsg.h"
41 #include "lpfc_crtn.h"
42 #include "lpfc_vport.h"
43 #include "lpfc_debugfs.h"
46 /* Called to verify a rcv'ed ADISC was intended for us. */
48 lpfc_check_adisc(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
49 struct lpfc_name
*nn
, struct lpfc_name
*pn
)
51 /* First, we MUST have a RPI registered */
52 if (!(ndlp
->nlp_flag
& NLP_RPI_REGISTERED
))
55 /* Compare the ADISC rsp WWNN / WWPN matches our internal node
56 * table entry for that node.
58 if (memcmp(nn
, &ndlp
->nlp_nodename
, sizeof (struct lpfc_name
)))
61 if (memcmp(pn
, &ndlp
->nlp_portname
, sizeof (struct lpfc_name
)))
64 /* we match, return success */
69 lpfc_check_sparm(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
70 struct serv_parm
*sp
, uint32_t class, int flogi
)
72 volatile struct serv_parm
*hsp
= &vport
->fc_sparam
;
73 uint16_t hsp_value
, ssp_value
= 0;
76 * The receive data field size and buffer-to-buffer receive data field
77 * size entries are 16 bits but are represented as two 8-bit fields in
78 * the driver data structure to account for rsvd bits and other control
79 * bits. Reconstruct and compare the fields as a 16-bit values before
80 * correcting the byte values.
82 if (sp
->cls1
.classValid
) {
84 hsp_value
= ((hsp
->cls1
.rcvDataSizeMsb
<< 8) |
85 hsp
->cls1
.rcvDataSizeLsb
);
86 ssp_value
= ((sp
->cls1
.rcvDataSizeMsb
<< 8) |
87 sp
->cls1
.rcvDataSizeLsb
);
89 goto bad_service_param
;
90 if (ssp_value
> hsp_value
) {
91 sp
->cls1
.rcvDataSizeLsb
=
92 hsp
->cls1
.rcvDataSizeLsb
;
93 sp
->cls1
.rcvDataSizeMsb
=
94 hsp
->cls1
.rcvDataSizeMsb
;
97 } else if (class == CLASS1
)
98 goto bad_service_param
;
99 if (sp
->cls2
.classValid
) {
101 hsp_value
= ((hsp
->cls2
.rcvDataSizeMsb
<< 8) |
102 hsp
->cls2
.rcvDataSizeLsb
);
103 ssp_value
= ((sp
->cls2
.rcvDataSizeMsb
<< 8) |
104 sp
->cls2
.rcvDataSizeLsb
);
106 goto bad_service_param
;
107 if (ssp_value
> hsp_value
) {
108 sp
->cls2
.rcvDataSizeLsb
=
109 hsp
->cls2
.rcvDataSizeLsb
;
110 sp
->cls2
.rcvDataSizeMsb
=
111 hsp
->cls2
.rcvDataSizeMsb
;
114 } else if (class == CLASS2
)
115 goto bad_service_param
;
116 if (sp
->cls3
.classValid
) {
118 hsp_value
= ((hsp
->cls3
.rcvDataSizeMsb
<< 8) |
119 hsp
->cls3
.rcvDataSizeLsb
);
120 ssp_value
= ((sp
->cls3
.rcvDataSizeMsb
<< 8) |
121 sp
->cls3
.rcvDataSizeLsb
);
123 goto bad_service_param
;
124 if (ssp_value
> hsp_value
) {
125 sp
->cls3
.rcvDataSizeLsb
=
126 hsp
->cls3
.rcvDataSizeLsb
;
127 sp
->cls3
.rcvDataSizeMsb
=
128 hsp
->cls3
.rcvDataSizeMsb
;
131 } else if (class == CLASS3
)
132 goto bad_service_param
;
135 * Preserve the upper four bits of the MSB from the PLOGI response.
136 * These bits contain the Buffer-to-Buffer State Change Number
137 * from the target and need to be passed to the FW.
139 hsp_value
= (hsp
->cmn
.bbRcvSizeMsb
<< 8) | hsp
->cmn
.bbRcvSizeLsb
;
140 ssp_value
= (sp
->cmn
.bbRcvSizeMsb
<< 8) | sp
->cmn
.bbRcvSizeLsb
;
141 if (ssp_value
> hsp_value
) {
142 sp
->cmn
.bbRcvSizeLsb
= hsp
->cmn
.bbRcvSizeLsb
;
143 sp
->cmn
.bbRcvSizeMsb
= (sp
->cmn
.bbRcvSizeMsb
& 0xF0) |
144 (hsp
->cmn
.bbRcvSizeMsb
& 0x0F);
147 memcpy(&ndlp
->nlp_nodename
, &sp
->nodeName
, sizeof (struct lpfc_name
));
148 memcpy(&ndlp
->nlp_portname
, &sp
->portName
, sizeof (struct lpfc_name
));
151 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
153 "(%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x) sent "
154 "invalid service parameters. Ignoring device.\n",
156 sp
->nodeName
.u
.wwn
[0], sp
->nodeName
.u
.wwn
[1],
157 sp
->nodeName
.u
.wwn
[2], sp
->nodeName
.u
.wwn
[3],
158 sp
->nodeName
.u
.wwn
[4], sp
->nodeName
.u
.wwn
[5],
159 sp
->nodeName
.u
.wwn
[6], sp
->nodeName
.u
.wwn
[7]);
164 lpfc_check_elscmpl_iocb(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
165 struct lpfc_iocbq
*rspiocb
)
167 struct lpfc_dmabuf
*pcmd
, *prsp
;
172 irsp
= &rspiocb
->iocb
;
173 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
175 /* For lpfc_els_abort, context2 could be zero'ed to delay
176 * freeing associated memory till after ABTS completes.
179 prsp
= list_get_first(&pcmd
->list
, struct lpfc_dmabuf
,
182 lp
= (uint32_t *) prsp
->virt
;
183 ptr
= (void *)((uint8_t *)lp
+ sizeof(uint32_t));
186 /* Force ulpStatus error since we are returning NULL ptr */
187 if (!(irsp
->ulpStatus
)) {
188 irsp
->ulpStatus
= IOSTAT_LOCAL_REJECT
;
189 irsp
->un
.ulpWord
[4] = IOERR_SLI_ABORTED
;
199 * Free resources / clean up outstanding I/Os
200 * associated with a LPFC_NODELIST entry. This
201 * routine effectively results in a "software abort".
204 lpfc_els_abort(struct lpfc_hba
*phba
, struct lpfc_nodelist
*ndlp
)
206 LIST_HEAD(abort_list
);
207 struct lpfc_sli
*psli
= &phba
->sli
;
208 struct lpfc_sli_ring
*pring
= &psli
->ring
[LPFC_ELS_RING
];
209 struct lpfc_iocbq
*iocb
, *next_iocb
;
211 /* Abort outstanding I/O on NPort <nlp_DID> */
212 lpfc_printf_vlog(ndlp
->vport
, KERN_INFO
, LOG_DISCOVERY
,
213 "2819 Abort outstanding I/O on NPort x%x "
214 "Data: x%x x%x x%x\n",
215 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
217 /* Clean up all fabric IOs first.*/
218 lpfc_fabric_abort_nport(ndlp
);
221 * Lock the ELS ring txcmplq for SLI3/SLI4 and build a local list
222 * of all ELS IOs that need an ABTS. The IOs need to stay on the
223 * txcmplq so that the abort operation completes them successfully.
225 spin_lock_irq(&phba
->hbalock
);
226 if (phba
->sli_rev
== LPFC_SLI_REV4
)
227 spin_lock(&pring
->ring_lock
);
228 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
, list
) {
229 /* Add to abort_list on on NDLP match. */
230 if (lpfc_check_sli_ndlp(phba
, pring
, iocb
, ndlp
))
231 list_add_tail(&iocb
->dlist
, &abort_list
);
233 if (phba
->sli_rev
== LPFC_SLI_REV4
)
234 spin_unlock(&pring
->ring_lock
);
235 spin_unlock_irq(&phba
->hbalock
);
237 /* Abort the targeted IOs and remove them from the abort list. */
238 list_for_each_entry_safe(iocb
, next_iocb
, &abort_list
, dlist
) {
239 spin_lock_irq(&phba
->hbalock
);
240 list_del_init(&iocb
->dlist
);
241 lpfc_sli_issue_abort_iotag(phba
, pring
, iocb
);
242 spin_unlock_irq(&phba
->hbalock
);
245 INIT_LIST_HEAD(&abort_list
);
247 /* Now process the txq */
248 spin_lock_irq(&phba
->hbalock
);
249 if (phba
->sli_rev
== LPFC_SLI_REV4
)
250 spin_lock(&pring
->ring_lock
);
252 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txq
, list
) {
253 /* Check to see if iocb matches the nport we are looking for */
254 if (lpfc_check_sli_ndlp(phba
, pring
, iocb
, ndlp
)) {
255 list_del_init(&iocb
->list
);
256 list_add_tail(&iocb
->list
, &abort_list
);
260 if (phba
->sli_rev
== LPFC_SLI_REV4
)
261 spin_unlock(&pring
->ring_lock
);
262 spin_unlock_irq(&phba
->hbalock
);
264 /* Cancel all the IOCBs from the completions list */
265 lpfc_sli_cancel_iocbs(phba
, &abort_list
,
266 IOSTAT_LOCAL_REJECT
, IOERR_SLI_ABORTED
);
268 lpfc_cancel_retry_delay_tmo(phba
->pport
, ndlp
);
273 lpfc_rcv_plogi(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
274 struct lpfc_iocbq
*cmdiocb
)
276 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
277 struct lpfc_hba
*phba
= vport
->phba
;
278 struct lpfc_dmabuf
*pcmd
;
281 struct serv_parm
*sp
;
286 memset(&stat
, 0, sizeof (struct ls_rjt
));
287 if (vport
->port_state
<= LPFC_FDISC
) {
288 /* Before responding to PLOGI, check for pt2pt mode.
289 * If we are pt2pt, with an outstanding FLOGI, abort
290 * the FLOGI and resend it first.
292 if (vport
->fc_flag
& FC_PT2PT
) {
293 lpfc_els_abort_flogi(phba
);
294 if (!(vport
->fc_flag
& FC_PT2PT_PLOGI
)) {
295 /* If the other side is supposed to initiate
296 * the PLOGI anyway, just ACC it now and
297 * move on with discovery.
299 phba
->fc_edtov
= FF_DEF_EDTOV
;
300 phba
->fc_ratov
= FF_DEF_RATOV
;
301 /* Start discovery - this should just do
303 lpfc_disc_start(vport
);
305 lpfc_initial_flogi(vport
);
307 stat
.un
.b
.lsRjtRsnCode
= LSRJT_LOGICAL_BSY
;
308 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_NOTHING_MORE
;
309 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
,
314 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
315 lp
= (uint32_t *) pcmd
->virt
;
316 sp
= (struct serv_parm
*) ((uint8_t *) lp
+ sizeof (uint32_t));
317 if (wwn_to_u64(sp
->portName
.u
.wwn
) == 0) {
318 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
319 "0140 PLOGI Reject: invalid nname\n");
320 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
321 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_INVALID_PNAME
;
322 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
,
326 if (wwn_to_u64(sp
->nodeName
.u
.wwn
) == 0) {
327 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
328 "0141 PLOGI Reject: invalid pname\n");
329 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
330 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_INVALID_NNAME
;
331 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
,
335 if ((lpfc_check_sparm(vport
, ndlp
, sp
, CLASS3
, 0) == 0)) {
336 /* Reject this request because invalid parameters */
337 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
338 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_SPARM_OPTIONS
;
339 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
,
343 icmd
= &cmdiocb
->iocb
;
345 /* PLOGI chkparm OK */
346 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
347 "0114 PLOGI chkparm OK Data: x%x x%x x%x "
349 ndlp
->nlp_DID
, ndlp
->nlp_state
, ndlp
->nlp_flag
,
350 ndlp
->nlp_rpi
, vport
->port_state
,
353 if (vport
->cfg_fcp_class
== 2 && sp
->cls2
.classValid
)
354 ndlp
->nlp_fcp_info
|= CLASS2
;
356 ndlp
->nlp_fcp_info
|= CLASS3
;
358 ndlp
->nlp_class_sup
= 0;
359 if (sp
->cls1
.classValid
)
360 ndlp
->nlp_class_sup
|= FC_COS_CLASS1
;
361 if (sp
->cls2
.classValid
)
362 ndlp
->nlp_class_sup
|= FC_COS_CLASS2
;
363 if (sp
->cls3
.classValid
)
364 ndlp
->nlp_class_sup
|= FC_COS_CLASS3
;
365 if (sp
->cls4
.classValid
)
366 ndlp
->nlp_class_sup
|= FC_COS_CLASS4
;
368 ((sp
->cmn
.bbRcvSizeMsb
& 0x0F) << 8) | sp
->cmn
.bbRcvSizeLsb
;
370 /* no need to reg_login if we are already in one of these states */
371 switch (ndlp
->nlp_state
) {
372 case NLP_STE_NPR_NODE
:
373 if (!(ndlp
->nlp_flag
& NLP_NPR_ADISC
))
375 case NLP_STE_REG_LOGIN_ISSUE
:
376 case NLP_STE_PRLI_ISSUE
:
377 case NLP_STE_UNMAPPED_NODE
:
378 case NLP_STE_MAPPED_NODE
:
379 lpfc_els_rsp_acc(vport
, ELS_CMD_PLOGI
, cmdiocb
, ndlp
, NULL
);
383 /* Check for Nport to NPort pt2pt protocol */
384 if ((vport
->fc_flag
& FC_PT2PT
) &&
385 !(vport
->fc_flag
& FC_PT2PT_PLOGI
)) {
387 /* rcv'ed PLOGI decides what our NPortId will be */
388 vport
->fc_myDID
= icmd
->un
.rcvels
.parmRo
;
389 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
392 lpfc_config_link(phba
, mbox
);
393 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
395 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
396 if (rc
== MBX_NOT_FINISHED
) {
397 mempool_free(mbox
, phba
->mbox_mem_pool
);
401 * For SLI4, the VFI/VPI are registered AFTER the
402 * Nport with the higher WWPN sends us a PLOGI with
403 * our assigned NPortId.
405 if (phba
->sli_rev
== LPFC_SLI_REV4
)
406 lpfc_issue_reg_vfi(vport
);
408 lpfc_can_disctmo(vport
);
410 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
414 /* Registering an existing RPI behaves differently for SLI3 vs SLI4 */
415 if (phba
->sli_rev
== LPFC_SLI_REV4
)
416 lpfc_unreg_rpi(vport
, ndlp
);
418 rc
= lpfc_reg_rpi(phba
, vport
->vpi
, icmd
->un
.rcvels
.remoteID
,
419 (uint8_t *) sp
, mbox
, ndlp
->nlp_rpi
);
421 mempool_free(mbox
, phba
->mbox_mem_pool
);
425 /* ACC PLOGI rsp command needs to execute first,
426 * queue this mbox command to be processed later.
428 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_reg_login
;
430 * mbox->context2 = lpfc_nlp_get(ndlp) deferred until mailbox
431 * command issued in lpfc_cmpl_els_acc().
434 spin_lock_irq(shost
->host_lock
);
435 ndlp
->nlp_flag
|= (NLP_ACC_REGLOGIN
| NLP_RCV_PLOGI
);
436 spin_unlock_irq(shost
->host_lock
);
439 * If there is an outstanding PLOGI issued, abort it before
440 * sending ACC rsp for received PLOGI. If pending plogi
441 * is not canceled here, the plogi will be rejected by
442 * remote port and will be retried. On a configuration with
443 * single discovery thread, this will cause a huge delay in
444 * discovery. Also this will cause multiple state machines
445 * running in parallel for this node.
447 if (ndlp
->nlp_state
== NLP_STE_PLOGI_ISSUE
) {
448 /* software abort outstanding PLOGI */
449 lpfc_els_abort(phba
, ndlp
);
452 if ((vport
->port_type
== LPFC_NPIV_PORT
&&
453 vport
->cfg_restrict_login
)) {
455 /* In order to preserve RPIs, we want to cleanup
456 * the default RPI the firmware created to rcv
457 * this ELS request. The only way to do this is
458 * to register, then unregister the RPI.
460 spin_lock_irq(shost
->host_lock
);
461 ndlp
->nlp_flag
|= NLP_RM_DFLT_RPI
;
462 spin_unlock_irq(shost
->host_lock
);
463 stat
.un
.b
.lsRjtRsnCode
= LSRJT_INVALID_CMD
;
464 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_NOTHING_MORE
;
465 rc
= lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
,
468 mempool_free(mbox
, phba
->mbox_mem_pool
);
471 rc
= lpfc_els_rsp_acc(vport
, ELS_CMD_PLOGI
, cmdiocb
, ndlp
, mbox
);
473 mempool_free(mbox
, phba
->mbox_mem_pool
);
476 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
477 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_OUT_OF_RESOURCE
;
478 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
483 * lpfc_mbx_cmpl_resume_rpi - Resume RPI completion routine
484 * @phba: pointer to lpfc hba data structure.
485 * @mboxq: pointer to mailbox object
487 * This routine is invoked to issue a completion to a rcv'ed
488 * ADISC or PDISC after the paused RPI has been resumed.
491 lpfc_mbx_cmpl_resume_rpi(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
493 struct lpfc_vport
*vport
;
494 struct lpfc_iocbq
*elsiocb
;
495 struct lpfc_nodelist
*ndlp
;
498 elsiocb
= (struct lpfc_iocbq
*)mboxq
->context1
;
499 ndlp
= (struct lpfc_nodelist
*) mboxq
->context2
;
500 vport
= mboxq
->vport
;
501 cmd
= elsiocb
->drvrTimeout
;
503 if (cmd
== ELS_CMD_ADISC
) {
504 lpfc_els_rsp_adisc_acc(vport
, elsiocb
, ndlp
);
506 lpfc_els_rsp_acc(vport
, ELS_CMD_PLOGI
, elsiocb
,
510 mempool_free(mboxq
, phba
->mbox_mem_pool
);
514 lpfc_rcv_padisc(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
515 struct lpfc_iocbq
*cmdiocb
)
517 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
518 struct lpfc_iocbq
*elsiocb
;
519 struct lpfc_dmabuf
*pcmd
;
520 struct serv_parm
*sp
;
521 struct lpfc_name
*pnn
, *ppn
;
528 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
529 lp
= (uint32_t *) pcmd
->virt
;
532 if (cmd
== ELS_CMD_ADISC
) {
534 pnn
= (struct lpfc_name
*) & ap
->nodeName
;
535 ppn
= (struct lpfc_name
*) & ap
->portName
;
537 sp
= (struct serv_parm
*) lp
;
538 pnn
= (struct lpfc_name
*) & sp
->nodeName
;
539 ppn
= (struct lpfc_name
*) & sp
->portName
;
542 icmd
= &cmdiocb
->iocb
;
543 if (icmd
->ulpStatus
== 0 && lpfc_check_adisc(vport
, ndlp
, pnn
, ppn
)) {
546 * As soon as we send ACC, the remote NPort can
547 * start sending us data. Thus, for SLI4 we must
548 * resume the RPI before the ACC goes out.
550 if (vport
->phba
->sli_rev
== LPFC_SLI_REV4
) {
551 elsiocb
= kmalloc(sizeof(struct lpfc_iocbq
),
555 /* Save info from cmd IOCB used in rsp */
556 memcpy((uint8_t *)elsiocb
, (uint8_t *)cmdiocb
,
557 sizeof(struct lpfc_iocbq
));
559 /* Save the ELS cmd */
560 elsiocb
->drvrTimeout
= cmd
;
562 lpfc_sli4_resume_rpi(ndlp
,
563 lpfc_mbx_cmpl_resume_rpi
, elsiocb
);
568 if (cmd
== ELS_CMD_ADISC
) {
569 lpfc_els_rsp_adisc_acc(vport
, cmdiocb
, ndlp
);
571 lpfc_els_rsp_acc(vport
, ELS_CMD_PLOGI
, cmdiocb
,
575 /* If we are authenticated, move to the proper state */
576 if (ndlp
->nlp_type
& NLP_FCP_TARGET
)
577 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_MAPPED_NODE
);
579 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
583 /* Reject this request because invalid parameters */
584 stat
.un
.b
.lsRjtRsvd0
= 0;
585 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
586 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_SPARM_OPTIONS
;
587 stat
.un
.b
.vendorUnique
= 0;
588 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
591 mod_timer(&ndlp
->nlp_delayfunc
, jiffies
+ msecs_to_jiffies(1000));
593 spin_lock_irq(shost
->host_lock
);
594 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
595 spin_unlock_irq(shost
->host_lock
);
596 ndlp
->nlp_last_elscmd
= ELS_CMD_PLOGI
;
597 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
598 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
603 lpfc_rcv_logo(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
604 struct lpfc_iocbq
*cmdiocb
, uint32_t els_cmd
)
606 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
607 struct lpfc_hba
*phba
= vport
->phba
;
608 struct lpfc_vport
**vports
;
609 int i
, active_vlink_present
= 0 ;
611 /* Put ndlp in NPR state with 1 sec timeout for plogi, ACC logo */
612 /* Only call LOGO ACC for first LOGO, this avoids sending unnecessary
613 * PLOGIs during LOGO storms from a device.
615 spin_lock_irq(shost
->host_lock
);
616 ndlp
->nlp_flag
|= NLP_LOGO_ACC
;
617 spin_unlock_irq(shost
->host_lock
);
618 if (els_cmd
== ELS_CMD_PRLO
)
619 lpfc_els_rsp_acc(vport
, ELS_CMD_PRLO
, cmdiocb
, ndlp
, NULL
);
621 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
622 if (ndlp
->nlp_DID
== Fabric_DID
) {
623 if (vport
->port_state
<= LPFC_FDISC
)
625 lpfc_linkdown_port(vport
);
626 spin_lock_irq(shost
->host_lock
);
627 vport
->fc_flag
|= FC_VPORT_LOGO_RCVD
;
628 spin_unlock_irq(shost
->host_lock
);
629 vports
= lpfc_create_vport_work_array(phba
);
631 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
;
633 if ((!(vports
[i
]->fc_flag
&
634 FC_VPORT_LOGO_RCVD
)) &&
635 (vports
[i
]->port_state
> LPFC_FDISC
)) {
636 active_vlink_present
= 1;
640 lpfc_destroy_vport_work_array(phba
, vports
);
643 if (active_vlink_present
) {
645 * If there are other active VLinks present,
646 * re-instantiate the Vlink using FDISC.
648 mod_timer(&ndlp
->nlp_delayfunc
,
649 jiffies
+ msecs_to_jiffies(1000));
650 spin_lock_irq(shost
->host_lock
);
651 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
652 spin_unlock_irq(shost
->host_lock
);
653 ndlp
->nlp_last_elscmd
= ELS_CMD_FDISC
;
654 vport
->port_state
= LPFC_FDISC
;
656 spin_lock_irq(shost
->host_lock
);
657 phba
->pport
->fc_flag
&= ~FC_LOGO_RCVD_DID_CHNG
;
658 spin_unlock_irq(shost
->host_lock
);
659 lpfc_retry_pport_discovery(phba
);
661 } else if ((!(ndlp
->nlp_type
& NLP_FABRIC
) &&
662 ((ndlp
->nlp_type
& NLP_FCP_TARGET
) ||
663 !(ndlp
->nlp_type
& NLP_FCP_INITIATOR
))) ||
664 (ndlp
->nlp_state
== NLP_STE_ADISC_ISSUE
)) {
665 /* Only try to re-login if this is NOT a Fabric Node */
666 mod_timer(&ndlp
->nlp_delayfunc
,
667 jiffies
+ msecs_to_jiffies(1000 * 1));
668 spin_lock_irq(shost
->host_lock
);
669 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
670 spin_unlock_irq(shost
->host_lock
);
672 ndlp
->nlp_last_elscmd
= ELS_CMD_PLOGI
;
675 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
676 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
678 spin_lock_irq(shost
->host_lock
);
679 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
680 spin_unlock_irq(shost
->host_lock
);
681 /* The driver has to wait until the ACC completes before it continues
682 * processing the LOGO. The action will resume in
683 * lpfc_cmpl_els_logo_acc routine. Since part of processing includes an
684 * unreg_login, the driver waits so the ACC does not get aborted.
690 lpfc_rcv_prli(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
691 struct lpfc_iocbq
*cmdiocb
)
693 struct lpfc_dmabuf
*pcmd
;
696 struct fc_rport
*rport
= ndlp
->rport
;
699 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
700 lp
= (uint32_t *) pcmd
->virt
;
701 npr
= (PRLI
*) ((uint8_t *) lp
+ sizeof (uint32_t));
703 ndlp
->nlp_type
&= ~(NLP_FCP_TARGET
| NLP_FCP_INITIATOR
);
704 ndlp
->nlp_fcp_info
&= ~NLP_FCP_2_DEVICE
;
705 ndlp
->nlp_flag
&= ~NLP_FIRSTBURST
;
706 if (npr
->prliType
== PRLI_FCP_TYPE
) {
707 if (npr
->initiatorFunc
)
708 ndlp
->nlp_type
|= NLP_FCP_INITIATOR
;
709 if (npr
->targetFunc
) {
710 ndlp
->nlp_type
|= NLP_FCP_TARGET
;
711 if (npr
->writeXferRdyDis
)
712 ndlp
->nlp_flag
|= NLP_FIRSTBURST
;
715 ndlp
->nlp_fcp_info
|= NLP_FCP_2_DEVICE
;
718 /* We need to update the rport role values */
719 roles
= FC_RPORT_ROLE_UNKNOWN
;
720 if (ndlp
->nlp_type
& NLP_FCP_INITIATOR
)
721 roles
|= FC_RPORT_ROLE_FCP_INITIATOR
;
722 if (ndlp
->nlp_type
& NLP_FCP_TARGET
)
723 roles
|= FC_RPORT_ROLE_FCP_TARGET
;
725 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_RPORT
,
726 "rport rolechg: role:x%x did:x%x flg:x%x",
727 roles
, ndlp
->nlp_DID
, ndlp
->nlp_flag
);
729 fc_remote_port_rolechg(rport
, roles
);
734 lpfc_disc_set_adisc(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
736 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
738 if (!(ndlp
->nlp_flag
& NLP_RPI_REGISTERED
)) {
739 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
743 if (!(vport
->fc_flag
& FC_PT2PT
)) {
744 /* Check config parameter use-adisc or FCP-2 */
745 if ((vport
->cfg_use_adisc
&& (vport
->fc_flag
& FC_RSCN_MODE
)) ||
746 ((ndlp
->nlp_fcp_info
& NLP_FCP_2_DEVICE
) &&
747 (ndlp
->nlp_type
& NLP_FCP_TARGET
))) {
748 spin_lock_irq(shost
->host_lock
);
749 ndlp
->nlp_flag
|= NLP_NPR_ADISC
;
750 spin_unlock_irq(shost
->host_lock
);
754 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
755 lpfc_unreg_rpi(vport
, ndlp
);
760 * lpfc_release_rpi - Release a RPI by issuing unreg_login mailbox cmd.
761 * @phba : Pointer to lpfc_hba structure.
762 * @vport: Pointer to lpfc_vport structure.
763 * @rpi : rpi to be release.
765 * This function will send a unreg_login mailbox command to the firmware
769 lpfc_release_rpi(struct lpfc_hba
*phba
,
770 struct lpfc_vport
*vport
,
776 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
,
779 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
780 "2796 mailbox memory allocation failed \n");
782 lpfc_unreg_login(phba
, vport
->vpi
, rpi
, pmb
);
783 pmb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
784 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
785 if (rc
== MBX_NOT_FINISHED
)
786 mempool_free(pmb
, phba
->mbox_mem_pool
);
791 lpfc_disc_illegal(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
792 void *arg
, uint32_t evt
)
794 struct lpfc_hba
*phba
;
795 LPFC_MBOXQ_t
*pmb
= (LPFC_MBOXQ_t
*) arg
;
800 /* Release the RPI if reglogin completing */
801 if (!(phba
->pport
->load_flag
& FC_UNLOADING
) &&
802 (evt
== NLP_EVT_CMPL_REG_LOGIN
) &&
803 (!pmb
->u
.mb
.mbxStatus
)) {
805 rpi
= pmb
->u
.mb
.un
.varWords
[0];
806 lpfc_release_rpi(phba
, vport
, rpi
);
808 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
809 "0271 Illegal State Transition: node x%x "
810 "event x%x, state x%x Data: x%x x%x\n",
811 ndlp
->nlp_DID
, evt
, ndlp
->nlp_state
, ndlp
->nlp_rpi
,
813 return ndlp
->nlp_state
;
817 lpfc_cmpl_plogi_illegal(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
818 void *arg
, uint32_t evt
)
820 /* This transition is only legal if we previously
821 * rcv'ed a PLOGI. Since we don't want 2 discovery threads
822 * working on the same NPortID, do nothing for this thread
825 if (!(ndlp
->nlp_flag
& NLP_RCV_PLOGI
)) {
826 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
827 "0272 Illegal State Transition: node x%x "
828 "event x%x, state x%x Data: x%x x%x\n",
829 ndlp
->nlp_DID
, evt
, ndlp
->nlp_state
, ndlp
->nlp_rpi
,
832 return ndlp
->nlp_state
;
835 /* Start of Discovery State Machine routines */
838 lpfc_rcv_plogi_unused_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
839 void *arg
, uint32_t evt
)
841 struct lpfc_iocbq
*cmdiocb
;
843 cmdiocb
= (struct lpfc_iocbq
*) arg
;
845 if (lpfc_rcv_plogi(vport
, ndlp
, cmdiocb
)) {
846 return ndlp
->nlp_state
;
848 return NLP_STE_FREED_NODE
;
852 lpfc_rcv_els_unused_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
853 void *arg
, uint32_t evt
)
855 lpfc_issue_els_logo(vport
, ndlp
, 0);
856 return ndlp
->nlp_state
;
860 lpfc_rcv_logo_unused_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
861 void *arg
, uint32_t evt
)
863 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
864 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
866 spin_lock_irq(shost
->host_lock
);
867 ndlp
->nlp_flag
|= NLP_LOGO_ACC
;
868 spin_unlock_irq(shost
->host_lock
);
869 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
871 return ndlp
->nlp_state
;
875 lpfc_cmpl_logo_unused_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
876 void *arg
, uint32_t evt
)
878 return NLP_STE_FREED_NODE
;
882 lpfc_device_rm_unused_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
883 void *arg
, uint32_t evt
)
885 return NLP_STE_FREED_NODE
;
889 lpfc_device_recov_unused_node(struct lpfc_vport
*vport
,
890 struct lpfc_nodelist
*ndlp
,
891 void *arg
, uint32_t evt
)
893 return ndlp
->nlp_state
;
897 lpfc_rcv_plogi_plogi_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
898 void *arg
, uint32_t evt
)
900 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
901 struct lpfc_hba
*phba
= vport
->phba
;
902 struct lpfc_iocbq
*cmdiocb
= arg
;
903 struct lpfc_dmabuf
*pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
904 uint32_t *lp
= (uint32_t *) pcmd
->virt
;
905 struct serv_parm
*sp
= (struct serv_parm
*) (lp
+ 1);
909 memset(&stat
, 0, sizeof (struct ls_rjt
));
911 /* For a PLOGI, we only accept if our portname is less
912 * than the remote portname.
914 phba
->fc_stat
.elsLogiCol
++;
915 port_cmp
= memcmp(&vport
->fc_portname
, &sp
->portName
,
916 sizeof(struct lpfc_name
));
919 /* Reject this request because the remote node will accept
921 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
922 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CMD_IN_PROGRESS
;
923 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
,
926 if (lpfc_rcv_plogi(vport
, ndlp
, cmdiocb
) &&
927 (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) &&
928 (vport
->num_disc_nodes
)) {
929 spin_lock_irq(shost
->host_lock
);
930 ndlp
->nlp_flag
&= ~NLP_NPR_2B_DISC
;
931 spin_unlock_irq(shost
->host_lock
);
932 /* Check if there are more PLOGIs to be sent */
933 lpfc_more_plogi(vport
);
934 if (vport
->num_disc_nodes
== 0) {
935 spin_lock_irq(shost
->host_lock
);
936 vport
->fc_flag
&= ~FC_NDISC_ACTIVE
;
937 spin_unlock_irq(shost
->host_lock
);
938 lpfc_can_disctmo(vport
);
939 lpfc_end_rscn(vport
);
942 } /* If our portname was less */
944 return ndlp
->nlp_state
;
948 lpfc_rcv_prli_plogi_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
949 void *arg
, uint32_t evt
)
951 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
954 memset(&stat
, 0, sizeof (struct ls_rjt
));
955 stat
.un
.b
.lsRjtRsnCode
= LSRJT_LOGICAL_BSY
;
956 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_NOTHING_MORE
;
957 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
958 return ndlp
->nlp_state
;
962 lpfc_rcv_logo_plogi_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
963 void *arg
, uint32_t evt
)
965 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
967 /* software abort outstanding PLOGI */
968 lpfc_els_abort(vport
->phba
, ndlp
);
970 lpfc_rcv_logo(vport
, ndlp
, cmdiocb
, ELS_CMD_LOGO
);
971 return ndlp
->nlp_state
;
975 lpfc_rcv_els_plogi_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
976 void *arg
, uint32_t evt
)
978 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
979 struct lpfc_hba
*phba
= vport
->phba
;
980 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
982 /* software abort outstanding PLOGI */
983 lpfc_els_abort(phba
, ndlp
);
985 if (evt
== NLP_EVT_RCV_LOGO
) {
986 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
988 lpfc_issue_els_logo(vport
, ndlp
, 0);
991 /* Put ndlp in npr state set plogi timer for 1 sec */
992 mod_timer(&ndlp
->nlp_delayfunc
, jiffies
+ msecs_to_jiffies(1000 * 1));
993 spin_lock_irq(shost
->host_lock
);
994 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
995 spin_unlock_irq(shost
->host_lock
);
996 ndlp
->nlp_last_elscmd
= ELS_CMD_PLOGI
;
997 ndlp
->nlp_prev_state
= NLP_STE_PLOGI_ISSUE
;
998 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1000 return ndlp
->nlp_state
;
1004 lpfc_cmpl_plogi_plogi_issue(struct lpfc_vport
*vport
,
1005 struct lpfc_nodelist
*ndlp
,
1009 struct lpfc_hba
*phba
= vport
->phba
;
1010 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1011 struct lpfc_iocbq
*cmdiocb
, *rspiocb
;
1012 struct lpfc_dmabuf
*pcmd
, *prsp
, *mp
;
1015 struct serv_parm
*sp
;
1018 cmdiocb
= (struct lpfc_iocbq
*) arg
;
1019 rspiocb
= cmdiocb
->context_un
.rsp_iocb
;
1021 if (ndlp
->nlp_flag
& NLP_ACC_REGLOGIN
) {
1022 /* Recovery from PLOGI collision logic */
1023 return ndlp
->nlp_state
;
1026 irsp
= &rspiocb
->iocb
;
1028 if (irsp
->ulpStatus
)
1031 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
1033 prsp
= list_get_first(&pcmd
->list
, struct lpfc_dmabuf
, list
);
1037 lp
= (uint32_t *) prsp
->virt
;
1038 sp
= (struct serv_parm
*) ((uint8_t *) lp
+ sizeof (uint32_t));
1040 /* Some switches have FDMI servers returning 0 for WWN */
1041 if ((ndlp
->nlp_DID
!= FDMI_DID
) &&
1042 (wwn_to_u64(sp
->portName
.u
.wwn
) == 0 ||
1043 wwn_to_u64(sp
->nodeName
.u
.wwn
) == 0)) {
1044 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1045 "0142 PLOGI RSP: Invalid WWN.\n");
1048 if (!lpfc_check_sparm(vport
, ndlp
, sp
, CLASS3
, 0))
1050 /* PLOGI chkparm OK */
1051 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
1052 "0121 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
1053 ndlp
->nlp_DID
, ndlp
->nlp_state
,
1054 ndlp
->nlp_flag
, ndlp
->nlp_rpi
);
1055 if (vport
->cfg_fcp_class
== 2 && (sp
->cls2
.classValid
))
1056 ndlp
->nlp_fcp_info
|= CLASS2
;
1058 ndlp
->nlp_fcp_info
|= CLASS3
;
1060 ndlp
->nlp_class_sup
= 0;
1061 if (sp
->cls1
.classValid
)
1062 ndlp
->nlp_class_sup
|= FC_COS_CLASS1
;
1063 if (sp
->cls2
.classValid
)
1064 ndlp
->nlp_class_sup
|= FC_COS_CLASS2
;
1065 if (sp
->cls3
.classValid
)
1066 ndlp
->nlp_class_sup
|= FC_COS_CLASS3
;
1067 if (sp
->cls4
.classValid
)
1068 ndlp
->nlp_class_sup
|= FC_COS_CLASS4
;
1069 ndlp
->nlp_maxframe
=
1070 ((sp
->cmn
.bbRcvSizeMsb
& 0x0F) << 8) | sp
->cmn
.bbRcvSizeLsb
;
1072 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1074 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1075 "0133 PLOGI: no memory for reg_login "
1076 "Data: x%x x%x x%x x%x\n",
1077 ndlp
->nlp_DID
, ndlp
->nlp_state
,
1078 ndlp
->nlp_flag
, ndlp
->nlp_rpi
);
1082 lpfc_unreg_rpi(vport
, ndlp
);
1084 if (lpfc_reg_rpi(phba
, vport
->vpi
, irsp
->un
.elsreq64
.remoteID
,
1085 (uint8_t *) sp
, mbox
, ndlp
->nlp_rpi
) == 0) {
1086 switch (ndlp
->nlp_DID
) {
1087 case NameServer_DID
:
1088 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_ns_reg_login
;
1091 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_fdmi_reg_login
;
1094 ndlp
->nlp_flag
|= NLP_REG_LOGIN_SEND
;
1095 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_reg_login
;
1097 mbox
->context2
= lpfc_nlp_get(ndlp
);
1098 mbox
->vport
= vport
;
1099 if (lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
)
1100 != MBX_NOT_FINISHED
) {
1101 lpfc_nlp_set_state(vport
, ndlp
,
1102 NLP_STE_REG_LOGIN_ISSUE
);
1103 return ndlp
->nlp_state
;
1105 if (ndlp
->nlp_flag
& NLP_REG_LOGIN_SEND
)
1106 ndlp
->nlp_flag
&= ~NLP_REG_LOGIN_SEND
;
1107 /* decrement node reference count to the failed mbox
1111 mp
= (struct lpfc_dmabuf
*) mbox
->context1
;
1112 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
1114 mempool_free(mbox
, phba
->mbox_mem_pool
);
1116 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1117 "0134 PLOGI: cannot issue reg_login "
1118 "Data: x%x x%x x%x x%x\n",
1119 ndlp
->nlp_DID
, ndlp
->nlp_state
,
1120 ndlp
->nlp_flag
, ndlp
->nlp_rpi
);
1122 mempool_free(mbox
, phba
->mbox_mem_pool
);
1124 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1125 "0135 PLOGI: cannot format reg_login "
1126 "Data: x%x x%x x%x x%x\n",
1127 ndlp
->nlp_DID
, ndlp
->nlp_state
,
1128 ndlp
->nlp_flag
, ndlp
->nlp_rpi
);
1133 if (ndlp
->nlp_DID
== NameServer_DID
) {
1134 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
1135 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1136 "0261 Cannot Register NameServer login\n");
1140 ** In case the node reference counter does not go to zero, ensure that
1141 ** the stale state for the node is not processed.
1144 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
1145 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1146 spin_lock_irq(shost
->host_lock
);
1147 ndlp
->nlp_flag
|= NLP_DEFER_RM
;
1148 spin_unlock_irq(shost
->host_lock
);
1149 return NLP_STE_FREED_NODE
;
1153 lpfc_cmpl_logo_plogi_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1154 void *arg
, uint32_t evt
)
1156 return ndlp
->nlp_state
;
1160 lpfc_cmpl_reglogin_plogi_issue(struct lpfc_vport
*vport
,
1161 struct lpfc_nodelist
*ndlp
, void *arg
, uint32_t evt
)
1163 struct lpfc_hba
*phba
;
1164 LPFC_MBOXQ_t
*pmb
= (LPFC_MBOXQ_t
*) arg
;
1165 MAILBOX_t
*mb
= &pmb
->u
.mb
;
1169 /* Release the RPI */
1170 if (!(phba
->pport
->load_flag
& FC_UNLOADING
) &&
1172 rpi
= pmb
->u
.mb
.un
.varWords
[0];
1173 lpfc_release_rpi(phba
, vport
, rpi
);
1175 return ndlp
->nlp_state
;
1179 lpfc_device_rm_plogi_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1180 void *arg
, uint32_t evt
)
1182 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1184 if (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) {
1185 spin_lock_irq(shost
->host_lock
);
1186 ndlp
->nlp_flag
|= NLP_NODEV_REMOVE
;
1187 spin_unlock_irq(shost
->host_lock
);
1188 return ndlp
->nlp_state
;
1190 /* software abort outstanding PLOGI */
1191 lpfc_els_abort(vport
->phba
, ndlp
);
1193 lpfc_drop_node(vport
, ndlp
);
1194 return NLP_STE_FREED_NODE
;
1199 lpfc_device_recov_plogi_issue(struct lpfc_vport
*vport
,
1200 struct lpfc_nodelist
*ndlp
,
1204 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1205 struct lpfc_hba
*phba
= vport
->phba
;
1207 /* Don't do anything that will mess up processing of the
1210 if (vport
->fc_flag
& FC_RSCN_DEFERRED
)
1211 return ndlp
->nlp_state
;
1213 /* software abort outstanding PLOGI */
1214 lpfc_els_abort(phba
, ndlp
);
1216 ndlp
->nlp_prev_state
= NLP_STE_PLOGI_ISSUE
;
1217 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1218 spin_lock_irq(shost
->host_lock
);
1219 ndlp
->nlp_flag
&= ~(NLP_NODEV_REMOVE
| NLP_NPR_2B_DISC
);
1220 spin_unlock_irq(shost
->host_lock
);
1222 return ndlp
->nlp_state
;
1226 lpfc_rcv_plogi_adisc_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1227 void *arg
, uint32_t evt
)
1229 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1230 struct lpfc_hba
*phba
= vport
->phba
;
1231 struct lpfc_iocbq
*cmdiocb
;
1233 /* software abort outstanding ADISC */
1234 lpfc_els_abort(phba
, ndlp
);
1236 cmdiocb
= (struct lpfc_iocbq
*) arg
;
1238 if (lpfc_rcv_plogi(vport
, ndlp
, cmdiocb
)) {
1239 if (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) {
1240 spin_lock_irq(shost
->host_lock
);
1241 ndlp
->nlp_flag
&= ~NLP_NPR_2B_DISC
;
1242 spin_unlock_irq(shost
->host_lock
);
1243 if (vport
->num_disc_nodes
)
1244 lpfc_more_adisc(vport
);
1246 return ndlp
->nlp_state
;
1248 ndlp
->nlp_prev_state
= NLP_STE_ADISC_ISSUE
;
1249 lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0);
1250 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
1252 return ndlp
->nlp_state
;
1256 lpfc_rcv_prli_adisc_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1257 void *arg
, uint32_t evt
)
1259 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1261 lpfc_els_rsp_prli_acc(vport
, cmdiocb
, ndlp
);
1262 return ndlp
->nlp_state
;
1266 lpfc_rcv_logo_adisc_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1267 void *arg
, uint32_t evt
)
1269 struct lpfc_hba
*phba
= vport
->phba
;
1270 struct lpfc_iocbq
*cmdiocb
;
1272 cmdiocb
= (struct lpfc_iocbq
*) arg
;
1274 /* software abort outstanding ADISC */
1275 lpfc_els_abort(phba
, ndlp
);
1277 lpfc_rcv_logo(vport
, ndlp
, cmdiocb
, ELS_CMD_LOGO
);
1278 return ndlp
->nlp_state
;
1282 lpfc_rcv_padisc_adisc_issue(struct lpfc_vport
*vport
,
1283 struct lpfc_nodelist
*ndlp
,
1284 void *arg
, uint32_t evt
)
1286 struct lpfc_iocbq
*cmdiocb
;
1288 cmdiocb
= (struct lpfc_iocbq
*) arg
;
1290 lpfc_rcv_padisc(vport
, ndlp
, cmdiocb
);
1291 return ndlp
->nlp_state
;
1295 lpfc_rcv_prlo_adisc_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1296 void *arg
, uint32_t evt
)
1298 struct lpfc_iocbq
*cmdiocb
;
1300 cmdiocb
= (struct lpfc_iocbq
*) arg
;
1302 /* Treat like rcv logo */
1303 lpfc_rcv_logo(vport
, ndlp
, cmdiocb
, ELS_CMD_PRLO
);
1304 return ndlp
->nlp_state
;
1308 lpfc_cmpl_adisc_adisc_issue(struct lpfc_vport
*vport
,
1309 struct lpfc_nodelist
*ndlp
,
1310 void *arg
, uint32_t evt
)
1312 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1313 struct lpfc_hba
*phba
= vport
->phba
;
1314 struct lpfc_iocbq
*cmdiocb
, *rspiocb
;
1319 cmdiocb
= (struct lpfc_iocbq
*) arg
;
1320 rspiocb
= cmdiocb
->context_un
.rsp_iocb
;
1322 ap
= (ADISC
*)lpfc_check_elscmpl_iocb(phba
, cmdiocb
, rspiocb
);
1323 irsp
= &rspiocb
->iocb
;
1325 if ((irsp
->ulpStatus
) ||
1326 (!lpfc_check_adisc(vport
, ndlp
, &ap
->nodeName
, &ap
->portName
))) {
1328 mod_timer(&ndlp
->nlp_delayfunc
,
1329 jiffies
+ msecs_to_jiffies(1000));
1330 spin_lock_irq(shost
->host_lock
);
1331 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
1332 spin_unlock_irq(shost
->host_lock
);
1333 ndlp
->nlp_last_elscmd
= ELS_CMD_PLOGI
;
1335 memset(&ndlp
->nlp_nodename
, 0, sizeof(struct lpfc_name
));
1336 memset(&ndlp
->nlp_portname
, 0, sizeof(struct lpfc_name
));
1338 ndlp
->nlp_prev_state
= NLP_STE_ADISC_ISSUE
;
1339 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1340 lpfc_unreg_rpi(vport
, ndlp
);
1341 return ndlp
->nlp_state
;
1344 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
1345 rc
= lpfc_sli4_resume_rpi(ndlp
, NULL
, NULL
);
1347 /* Stay in state and retry. */
1348 ndlp
->nlp_prev_state
= NLP_STE_ADISC_ISSUE
;
1349 return ndlp
->nlp_state
;
1353 if (ndlp
->nlp_type
& NLP_FCP_TARGET
) {
1354 ndlp
->nlp_prev_state
= NLP_STE_ADISC_ISSUE
;
1355 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_MAPPED_NODE
);
1357 ndlp
->nlp_prev_state
= NLP_STE_ADISC_ISSUE
;
1358 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
1361 return ndlp
->nlp_state
;
1365 lpfc_device_rm_adisc_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1366 void *arg
, uint32_t evt
)
1368 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1370 if (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) {
1371 spin_lock_irq(shost
->host_lock
);
1372 ndlp
->nlp_flag
|= NLP_NODEV_REMOVE
;
1373 spin_unlock_irq(shost
->host_lock
);
1374 return ndlp
->nlp_state
;
1376 /* software abort outstanding ADISC */
1377 lpfc_els_abort(vport
->phba
, ndlp
);
1379 lpfc_drop_node(vport
, ndlp
);
1380 return NLP_STE_FREED_NODE
;
1385 lpfc_device_recov_adisc_issue(struct lpfc_vport
*vport
,
1386 struct lpfc_nodelist
*ndlp
,
1390 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1391 struct lpfc_hba
*phba
= vport
->phba
;
1393 /* Don't do anything that will mess up processing of the
1396 if (vport
->fc_flag
& FC_RSCN_DEFERRED
)
1397 return ndlp
->nlp_state
;
1399 /* software abort outstanding ADISC */
1400 lpfc_els_abort(phba
, ndlp
);
1402 ndlp
->nlp_prev_state
= NLP_STE_ADISC_ISSUE
;
1403 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1404 spin_lock_irq(shost
->host_lock
);
1405 ndlp
->nlp_flag
&= ~(NLP_NODEV_REMOVE
| NLP_NPR_2B_DISC
);
1406 spin_unlock_irq(shost
->host_lock
);
1407 lpfc_disc_set_adisc(vport
, ndlp
);
1408 return ndlp
->nlp_state
;
1412 lpfc_rcv_plogi_reglogin_issue(struct lpfc_vport
*vport
,
1413 struct lpfc_nodelist
*ndlp
,
1417 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1419 lpfc_rcv_plogi(vport
, ndlp
, cmdiocb
);
1420 return ndlp
->nlp_state
;
1424 lpfc_rcv_prli_reglogin_issue(struct lpfc_vport
*vport
,
1425 struct lpfc_nodelist
*ndlp
,
1429 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1431 lpfc_els_rsp_prli_acc(vport
, cmdiocb
, ndlp
);
1432 return ndlp
->nlp_state
;
1436 lpfc_rcv_logo_reglogin_issue(struct lpfc_vport
*vport
,
1437 struct lpfc_nodelist
*ndlp
,
1441 struct lpfc_hba
*phba
= vport
->phba
;
1442 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1444 LPFC_MBOXQ_t
*nextmb
;
1445 struct lpfc_dmabuf
*mp
;
1447 cmdiocb
= (struct lpfc_iocbq
*) arg
;
1449 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
1450 if ((mb
= phba
->sli
.mbox_active
)) {
1451 if ((mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) &&
1452 (ndlp
== (struct lpfc_nodelist
*) mb
->context2
)) {
1454 mb
->context2
= NULL
;
1455 mb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
1459 spin_lock_irq(&phba
->hbalock
);
1460 list_for_each_entry_safe(mb
, nextmb
, &phba
->sli
.mboxq
, list
) {
1461 if ((mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) &&
1462 (ndlp
== (struct lpfc_nodelist
*) mb
->context2
)) {
1463 mp
= (struct lpfc_dmabuf
*) (mb
->context1
);
1465 __lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
1469 list_del(&mb
->list
);
1470 phba
->sli
.mboxq_cnt
--;
1471 mempool_free(mb
, phba
->mbox_mem_pool
);
1474 spin_unlock_irq(&phba
->hbalock
);
1476 lpfc_rcv_logo(vport
, ndlp
, cmdiocb
, ELS_CMD_LOGO
);
1477 return ndlp
->nlp_state
;
1481 lpfc_rcv_padisc_reglogin_issue(struct lpfc_vport
*vport
,
1482 struct lpfc_nodelist
*ndlp
,
1486 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1488 lpfc_rcv_padisc(vport
, ndlp
, cmdiocb
);
1489 return ndlp
->nlp_state
;
1493 lpfc_rcv_prlo_reglogin_issue(struct lpfc_vport
*vport
,
1494 struct lpfc_nodelist
*ndlp
,
1498 struct lpfc_iocbq
*cmdiocb
;
1500 cmdiocb
= (struct lpfc_iocbq
*) arg
;
1501 lpfc_els_rsp_acc(vport
, ELS_CMD_PRLO
, cmdiocb
, ndlp
, NULL
);
1502 return ndlp
->nlp_state
;
1506 lpfc_cmpl_reglogin_reglogin_issue(struct lpfc_vport
*vport
,
1507 struct lpfc_nodelist
*ndlp
,
1511 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1512 LPFC_MBOXQ_t
*pmb
= (LPFC_MBOXQ_t
*) arg
;
1513 MAILBOX_t
*mb
= &pmb
->u
.mb
;
1514 uint32_t did
= mb
->un
.varWords
[1];
1516 if (mb
->mbxStatus
) {
1517 /* RegLogin failed */
1518 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
1519 "0246 RegLogin failed Data: x%x x%x x%x x%x "
1521 did
, mb
->mbxStatus
, vport
->port_state
,
1522 mb
->un
.varRegLogin
.vpi
,
1523 mb
->un
.varRegLogin
.rpi
);
1525 * If RegLogin failed due to lack of HBA resources do not
1528 if (mb
->mbxStatus
== MBXERR_RPI_FULL
) {
1529 ndlp
->nlp_prev_state
= NLP_STE_REG_LOGIN_ISSUE
;
1530 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1531 return ndlp
->nlp_state
;
1534 /* Put ndlp in npr state set plogi timer for 1 sec */
1535 mod_timer(&ndlp
->nlp_delayfunc
,
1536 jiffies
+ msecs_to_jiffies(1000 * 1));
1537 spin_lock_irq(shost
->host_lock
);
1538 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
1539 spin_unlock_irq(shost
->host_lock
);
1540 ndlp
->nlp_last_elscmd
= ELS_CMD_PLOGI
;
1542 lpfc_issue_els_logo(vport
, ndlp
, 0);
1543 ndlp
->nlp_prev_state
= NLP_STE_REG_LOGIN_ISSUE
;
1544 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1545 return ndlp
->nlp_state
;
1548 /* SLI4 ports have preallocated logical rpis. */
1549 if (vport
->phba
->sli_rev
< LPFC_SLI_REV4
)
1550 ndlp
->nlp_rpi
= mb
->un
.varWords
[0];
1552 ndlp
->nlp_flag
|= NLP_RPI_REGISTERED
;
1554 /* Only if we are not a fabric nport do we issue PRLI */
1555 if (!(ndlp
->nlp_type
& NLP_FABRIC
)) {
1556 ndlp
->nlp_prev_state
= NLP_STE_REG_LOGIN_ISSUE
;
1557 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PRLI_ISSUE
);
1558 lpfc_issue_els_prli(vport
, ndlp
, 0);
1560 ndlp
->nlp_prev_state
= NLP_STE_REG_LOGIN_ISSUE
;
1561 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
1563 return ndlp
->nlp_state
;
1567 lpfc_device_rm_reglogin_issue(struct lpfc_vport
*vport
,
1568 struct lpfc_nodelist
*ndlp
,
1572 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1574 if (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) {
1575 spin_lock_irq(shost
->host_lock
);
1576 ndlp
->nlp_flag
|= NLP_NODEV_REMOVE
;
1577 spin_unlock_irq(shost
->host_lock
);
1578 return ndlp
->nlp_state
;
1580 lpfc_drop_node(vport
, ndlp
);
1581 return NLP_STE_FREED_NODE
;
1586 lpfc_device_recov_reglogin_issue(struct lpfc_vport
*vport
,
1587 struct lpfc_nodelist
*ndlp
,
1591 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1593 /* Don't do anything that will mess up processing of the
1596 if (vport
->fc_flag
& FC_RSCN_DEFERRED
)
1597 return ndlp
->nlp_state
;
1599 ndlp
->nlp_prev_state
= NLP_STE_REG_LOGIN_ISSUE
;
1600 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1601 spin_lock_irq(shost
->host_lock
);
1602 ndlp
->nlp_flag
|= NLP_IGNR_REG_CMPL
;
1603 ndlp
->nlp_flag
&= ~(NLP_NODEV_REMOVE
| NLP_NPR_2B_DISC
);
1604 spin_unlock_irq(shost
->host_lock
);
1605 lpfc_disc_set_adisc(vport
, ndlp
);
1606 return ndlp
->nlp_state
;
1610 lpfc_rcv_plogi_prli_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1611 void *arg
, uint32_t evt
)
1613 struct lpfc_iocbq
*cmdiocb
;
1615 cmdiocb
= (struct lpfc_iocbq
*) arg
;
1617 lpfc_rcv_plogi(vport
, ndlp
, cmdiocb
);
1618 return ndlp
->nlp_state
;
1622 lpfc_rcv_prli_prli_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1623 void *arg
, uint32_t evt
)
1625 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1627 lpfc_els_rsp_prli_acc(vport
, cmdiocb
, ndlp
);
1628 return ndlp
->nlp_state
;
1632 lpfc_rcv_logo_prli_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1633 void *arg
, uint32_t evt
)
1635 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1637 /* Software abort outstanding PRLI before sending acc */
1638 lpfc_els_abort(vport
->phba
, ndlp
);
1640 lpfc_rcv_logo(vport
, ndlp
, cmdiocb
, ELS_CMD_LOGO
);
1641 return ndlp
->nlp_state
;
1645 lpfc_rcv_padisc_prli_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1646 void *arg
, uint32_t evt
)
1648 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1650 lpfc_rcv_padisc(vport
, ndlp
, cmdiocb
);
1651 return ndlp
->nlp_state
;
1654 /* This routine is envoked when we rcv a PRLO request from a nport
1655 * we are logged into. We should send back a PRLO rsp setting the
1657 * NEXT STATE = PRLI_ISSUE
1660 lpfc_rcv_prlo_prli_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1661 void *arg
, uint32_t evt
)
1663 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1665 lpfc_els_rsp_acc(vport
, ELS_CMD_PRLO
, cmdiocb
, ndlp
, NULL
);
1666 return ndlp
->nlp_state
;
1670 lpfc_cmpl_prli_prli_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1671 void *arg
, uint32_t evt
)
1673 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1674 struct lpfc_iocbq
*cmdiocb
, *rspiocb
;
1675 struct lpfc_hba
*phba
= vport
->phba
;
1679 cmdiocb
= (struct lpfc_iocbq
*) arg
;
1680 rspiocb
= cmdiocb
->context_un
.rsp_iocb
;
1681 npr
= (PRLI
*)lpfc_check_elscmpl_iocb(phba
, cmdiocb
, rspiocb
);
1683 irsp
= &rspiocb
->iocb
;
1684 if (irsp
->ulpStatus
) {
1685 if ((vport
->port_type
== LPFC_NPIV_PORT
) &&
1686 vport
->cfg_restrict_login
) {
1689 ndlp
->nlp_prev_state
= NLP_STE_PRLI_ISSUE
;
1690 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
1691 return ndlp
->nlp_state
;
1694 /* Check out PRLI rsp */
1695 ndlp
->nlp_type
&= ~(NLP_FCP_TARGET
| NLP_FCP_INITIATOR
);
1696 ndlp
->nlp_fcp_info
&= ~NLP_FCP_2_DEVICE
;
1697 ndlp
->nlp_flag
&= ~NLP_FIRSTBURST
;
1698 if ((npr
->acceptRspCode
== PRLI_REQ_EXECUTED
) &&
1699 (npr
->prliType
== PRLI_FCP_TYPE
)) {
1700 if (npr
->initiatorFunc
)
1701 ndlp
->nlp_type
|= NLP_FCP_INITIATOR
;
1702 if (npr
->targetFunc
) {
1703 ndlp
->nlp_type
|= NLP_FCP_TARGET
;
1704 if (npr
->writeXferRdyDis
)
1705 ndlp
->nlp_flag
|= NLP_FIRSTBURST
;
1708 ndlp
->nlp_fcp_info
|= NLP_FCP_2_DEVICE
;
1710 if (!(ndlp
->nlp_type
& NLP_FCP_TARGET
) &&
1711 (vport
->port_type
== LPFC_NPIV_PORT
) &&
1712 vport
->cfg_restrict_login
) {
1714 spin_lock_irq(shost
->host_lock
);
1715 ndlp
->nlp_flag
|= NLP_TARGET_REMOVE
;
1716 spin_unlock_irq(shost
->host_lock
);
1717 lpfc_issue_els_logo(vport
, ndlp
, 0);
1719 ndlp
->nlp_prev_state
= NLP_STE_PRLI_ISSUE
;
1720 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1721 return ndlp
->nlp_state
;
1724 ndlp
->nlp_prev_state
= NLP_STE_PRLI_ISSUE
;
1725 if (ndlp
->nlp_type
& NLP_FCP_TARGET
)
1726 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_MAPPED_NODE
);
1728 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
1729 return ndlp
->nlp_state
;
1732 /*! lpfc_device_rm_prli_issue
1743 * This routine is envoked when we a request to remove a nport we are in the
1744 * process of PRLIing. We should software abort outstanding prli, unreg
1745 * login, send a logout. We will change node state to UNUSED_NODE, put it
1746 * on plogi list so it can be freed when LOGO completes.
1751 lpfc_device_rm_prli_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1752 void *arg
, uint32_t evt
)
1754 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1756 if (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) {
1757 spin_lock_irq(shost
->host_lock
);
1758 ndlp
->nlp_flag
|= NLP_NODEV_REMOVE
;
1759 spin_unlock_irq(shost
->host_lock
);
1760 return ndlp
->nlp_state
;
1762 /* software abort outstanding PLOGI */
1763 lpfc_els_abort(vport
->phba
, ndlp
);
1765 lpfc_drop_node(vport
, ndlp
);
1766 return NLP_STE_FREED_NODE
;
1771 /*! lpfc_device_recov_prli_issue
1782 * The routine is envoked when the state of a device is unknown, like
1783 * during a link down. We should remove the nodelist entry from the
1784 * unmapped list, issue a UNREG_LOGIN, do a software abort of the
1785 * outstanding PRLI command, then free the node entry.
1788 lpfc_device_recov_prli_issue(struct lpfc_vport
*vport
,
1789 struct lpfc_nodelist
*ndlp
,
1793 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1794 struct lpfc_hba
*phba
= vport
->phba
;
1796 /* Don't do anything that will mess up processing of the
1799 if (vport
->fc_flag
& FC_RSCN_DEFERRED
)
1800 return ndlp
->nlp_state
;
1802 /* software abort outstanding PRLI */
1803 lpfc_els_abort(phba
, ndlp
);
1805 ndlp
->nlp_prev_state
= NLP_STE_PRLI_ISSUE
;
1806 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1807 spin_lock_irq(shost
->host_lock
);
1808 ndlp
->nlp_flag
&= ~(NLP_NODEV_REMOVE
| NLP_NPR_2B_DISC
);
1809 spin_unlock_irq(shost
->host_lock
);
1810 lpfc_disc_set_adisc(vport
, ndlp
);
1811 return ndlp
->nlp_state
;
1815 lpfc_rcv_plogi_logo_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1816 void *arg
, uint32_t evt
)
1818 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*)arg
;
1821 memset(&stat
, 0, sizeof(struct ls_rjt
));
1822 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
1823 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_NOTHING_MORE
;
1824 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
1825 return ndlp
->nlp_state
;
1829 lpfc_rcv_prli_logo_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1830 void *arg
, uint32_t evt
)
1832 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*)arg
;
1835 memset(&stat
, 0, sizeof(struct ls_rjt
));
1836 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
1837 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_NOTHING_MORE
;
1838 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
1839 return ndlp
->nlp_state
;
1843 lpfc_rcv_logo_logo_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1844 void *arg
, uint32_t evt
)
1846 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1847 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*)arg
;
1849 spin_lock_irq(shost
->host_lock
);
1850 ndlp
->nlp_flag
&= NLP_LOGO_ACC
;
1851 spin_unlock_irq(shost
->host_lock
);
1852 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
1853 return ndlp
->nlp_state
;
1857 lpfc_rcv_padisc_logo_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1858 void *arg
, uint32_t evt
)
1860 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*)arg
;
1863 memset(&stat
, 0, sizeof(struct ls_rjt
));
1864 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
1865 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_NOTHING_MORE
;
1866 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
1867 return ndlp
->nlp_state
;
1871 lpfc_rcv_prlo_logo_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1872 void *arg
, uint32_t evt
)
1874 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*)arg
;
1877 memset(&stat
, 0, sizeof(struct ls_rjt
));
1878 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
1879 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_NOTHING_MORE
;
1880 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
1881 return ndlp
->nlp_state
;
1885 lpfc_cmpl_logo_logo_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1886 void *arg
, uint32_t evt
)
1888 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1890 ndlp
->nlp_prev_state
= NLP_STE_LOGO_ISSUE
;
1891 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1892 spin_lock_irq(shost
->host_lock
);
1893 ndlp
->nlp_flag
&= ~(NLP_NODEV_REMOVE
| NLP_NPR_2B_DISC
);
1894 spin_unlock_irq(shost
->host_lock
);
1895 lpfc_disc_set_adisc(vport
, ndlp
);
1896 return ndlp
->nlp_state
;
1900 lpfc_device_rm_logo_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1901 void *arg
, uint32_t evt
)
1904 * Take no action. If a LOGO is outstanding, then possibly DevLoss has
1905 * timed out and is calling for Device Remove. In this case, the LOGO
1906 * must be allowed to complete in state LOGO_ISSUE so that the rpi
1907 * and other NLP flags are correctly cleaned up.
1909 return ndlp
->nlp_state
;
1913 lpfc_device_recov_logo_issue(struct lpfc_vport
*vport
,
1914 struct lpfc_nodelist
*ndlp
,
1915 void *arg
, uint32_t evt
)
1918 * Device Recovery events have no meaning for a node with a LOGO
1919 * outstanding. The LOGO has to complete first and handle the
1920 * node from that point.
1922 return ndlp
->nlp_state
;
1926 lpfc_rcv_plogi_unmap_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1927 void *arg
, uint32_t evt
)
1929 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1931 lpfc_rcv_plogi(vport
, ndlp
, cmdiocb
);
1932 return ndlp
->nlp_state
;
1936 lpfc_rcv_prli_unmap_node(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_rcv_prli(vport
, ndlp
, cmdiocb
);
1942 lpfc_els_rsp_prli_acc(vport
, cmdiocb
, ndlp
);
1943 return ndlp
->nlp_state
;
1947 lpfc_rcv_logo_unmap_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1948 void *arg
, uint32_t evt
)
1950 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1952 lpfc_rcv_logo(vport
, ndlp
, cmdiocb
, ELS_CMD_LOGO
);
1953 return ndlp
->nlp_state
;
1957 lpfc_rcv_padisc_unmap_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1958 void *arg
, uint32_t evt
)
1960 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1962 lpfc_rcv_padisc(vport
, ndlp
, cmdiocb
);
1963 return ndlp
->nlp_state
;
1967 lpfc_rcv_prlo_unmap_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1968 void *arg
, uint32_t evt
)
1970 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1972 lpfc_els_rsp_acc(vport
, ELS_CMD_PRLO
, cmdiocb
, ndlp
, NULL
);
1973 return ndlp
->nlp_state
;
1977 lpfc_device_recov_unmap_node(struct lpfc_vport
*vport
,
1978 struct lpfc_nodelist
*ndlp
,
1982 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1984 ndlp
->nlp_prev_state
= NLP_STE_UNMAPPED_NODE
;
1985 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1986 spin_lock_irq(shost
->host_lock
);
1987 ndlp
->nlp_flag
&= ~(NLP_NODEV_REMOVE
| NLP_NPR_2B_DISC
);
1988 spin_unlock_irq(shost
->host_lock
);
1989 lpfc_disc_set_adisc(vport
, ndlp
);
1991 return ndlp
->nlp_state
;
1995 lpfc_rcv_plogi_mapped_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1996 void *arg
, uint32_t evt
)
1998 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2000 lpfc_rcv_plogi(vport
, ndlp
, cmdiocb
);
2001 return ndlp
->nlp_state
;
2005 lpfc_rcv_prli_mapped_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2006 void *arg
, uint32_t evt
)
2008 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2010 lpfc_els_rsp_prli_acc(vport
, cmdiocb
, ndlp
);
2011 return ndlp
->nlp_state
;
2015 lpfc_rcv_logo_mapped_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2016 void *arg
, uint32_t evt
)
2018 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2020 lpfc_rcv_logo(vport
, ndlp
, cmdiocb
, ELS_CMD_LOGO
);
2021 return ndlp
->nlp_state
;
2025 lpfc_rcv_padisc_mapped_node(struct lpfc_vport
*vport
,
2026 struct lpfc_nodelist
*ndlp
,
2027 void *arg
, uint32_t evt
)
2029 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2031 lpfc_rcv_padisc(vport
, ndlp
, cmdiocb
);
2032 return ndlp
->nlp_state
;
2036 lpfc_rcv_prlo_mapped_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2037 void *arg
, uint32_t evt
)
2039 struct lpfc_hba
*phba
= vport
->phba
;
2040 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2042 /* flush the target */
2043 lpfc_sli_abort_iocb(vport
, &phba
->sli
.ring
[phba
->sli
.fcp_ring
],
2044 ndlp
->nlp_sid
, 0, LPFC_CTX_TGT
);
2046 /* Treat like rcv logo */
2047 lpfc_rcv_logo(vport
, ndlp
, cmdiocb
, ELS_CMD_PRLO
);
2048 return ndlp
->nlp_state
;
2052 lpfc_device_recov_mapped_node(struct lpfc_vport
*vport
,
2053 struct lpfc_nodelist
*ndlp
,
2057 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2059 ndlp
->nlp_prev_state
= NLP_STE_MAPPED_NODE
;
2060 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
2061 spin_lock_irq(shost
->host_lock
);
2062 ndlp
->nlp_flag
&= ~(NLP_NODEV_REMOVE
| NLP_NPR_2B_DISC
);
2063 spin_unlock_irq(shost
->host_lock
);
2064 lpfc_disc_set_adisc(vport
, ndlp
);
2065 return ndlp
->nlp_state
;
2069 lpfc_rcv_plogi_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2070 void *arg
, uint32_t evt
)
2072 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2073 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2075 /* Ignore PLOGI if we have an outstanding LOGO */
2076 if (ndlp
->nlp_flag
& (NLP_LOGO_SND
| NLP_LOGO_ACC
))
2077 return ndlp
->nlp_state
;
2078 if (lpfc_rcv_plogi(vport
, ndlp
, cmdiocb
)) {
2079 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
2080 spin_lock_irq(shost
->host_lock
);
2081 ndlp
->nlp_flag
&= ~(NLP_NPR_ADISC
| NLP_NPR_2B_DISC
);
2082 spin_unlock_irq(shost
->host_lock
);
2083 } else if (!(ndlp
->nlp_flag
& NLP_NPR_2B_DISC
)) {
2084 /* send PLOGI immediately, move to PLOGI issue state */
2085 if (!(ndlp
->nlp_flag
& NLP_DELAY_TMO
)) {
2086 ndlp
->nlp_prev_state
= NLP_STE_NPR_NODE
;
2087 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
2088 lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0);
2091 return ndlp
->nlp_state
;
2095 lpfc_rcv_prli_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2096 void *arg
, uint32_t evt
)
2098 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2099 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2102 memset(&stat
, 0, sizeof (struct ls_rjt
));
2103 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
2104 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_NOTHING_MORE
;
2105 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
2107 if (!(ndlp
->nlp_flag
& NLP_DELAY_TMO
)) {
2108 if (ndlp
->nlp_flag
& NLP_NPR_ADISC
) {
2109 spin_lock_irq(shost
->host_lock
);
2110 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
2111 ndlp
->nlp_prev_state
= NLP_STE_NPR_NODE
;
2112 spin_unlock_irq(shost
->host_lock
);
2113 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_ADISC_ISSUE
);
2114 lpfc_issue_els_adisc(vport
, ndlp
, 0);
2116 ndlp
->nlp_prev_state
= NLP_STE_NPR_NODE
;
2117 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
2118 lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0);
2121 return ndlp
->nlp_state
;
2125 lpfc_rcv_logo_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2126 void *arg
, uint32_t evt
)
2128 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2130 lpfc_rcv_logo(vport
, ndlp
, cmdiocb
, ELS_CMD_LOGO
);
2131 return ndlp
->nlp_state
;
2135 lpfc_rcv_padisc_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2136 void *arg
, uint32_t evt
)
2138 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2140 lpfc_rcv_padisc(vport
, ndlp
, cmdiocb
);
2142 * Do not start discovery if discovery is about to start
2143 * or discovery in progress for this node. Starting discovery
2144 * here will affect the counting of discovery threads.
2146 if (!(ndlp
->nlp_flag
& NLP_DELAY_TMO
) &&
2147 !(ndlp
->nlp_flag
& NLP_NPR_2B_DISC
)) {
2148 if (ndlp
->nlp_flag
& NLP_NPR_ADISC
) {
2149 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
2150 ndlp
->nlp_prev_state
= NLP_STE_NPR_NODE
;
2151 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_ADISC_ISSUE
);
2152 lpfc_issue_els_adisc(vport
, ndlp
, 0);
2154 ndlp
->nlp_prev_state
= NLP_STE_NPR_NODE
;
2155 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
2156 lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0);
2159 return ndlp
->nlp_state
;
2163 lpfc_rcv_prlo_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2164 void *arg
, uint32_t evt
)
2166 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2167 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2169 spin_lock_irq(shost
->host_lock
);
2170 ndlp
->nlp_flag
|= NLP_LOGO_ACC
;
2171 spin_unlock_irq(shost
->host_lock
);
2173 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
2175 if ((ndlp
->nlp_flag
& NLP_DELAY_TMO
) == 0) {
2176 mod_timer(&ndlp
->nlp_delayfunc
,
2177 jiffies
+ msecs_to_jiffies(1000 * 1));
2178 spin_lock_irq(shost
->host_lock
);
2179 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
2180 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
2181 spin_unlock_irq(shost
->host_lock
);
2182 ndlp
->nlp_last_elscmd
= ELS_CMD_PLOGI
;
2184 spin_lock_irq(shost
->host_lock
);
2185 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
2186 spin_unlock_irq(shost
->host_lock
);
2188 return ndlp
->nlp_state
;
2192 lpfc_cmpl_plogi_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2193 void *arg
, uint32_t evt
)
2195 struct lpfc_iocbq
*cmdiocb
, *rspiocb
;
2197 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2199 cmdiocb
= (struct lpfc_iocbq
*) arg
;
2200 rspiocb
= cmdiocb
->context_un
.rsp_iocb
;
2202 irsp
= &rspiocb
->iocb
;
2203 if (irsp
->ulpStatus
) {
2204 spin_lock_irq(shost
->host_lock
);
2205 ndlp
->nlp_flag
|= NLP_DEFER_RM
;
2206 spin_unlock_irq(shost
->host_lock
);
2207 return NLP_STE_FREED_NODE
;
2209 return ndlp
->nlp_state
;
2213 lpfc_cmpl_prli_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2214 void *arg
, uint32_t evt
)
2216 struct lpfc_iocbq
*cmdiocb
, *rspiocb
;
2219 cmdiocb
= (struct lpfc_iocbq
*) arg
;
2220 rspiocb
= cmdiocb
->context_un
.rsp_iocb
;
2222 irsp
= &rspiocb
->iocb
;
2223 if (irsp
->ulpStatus
&& (ndlp
->nlp_flag
& NLP_NODEV_REMOVE
)) {
2224 lpfc_drop_node(vport
, ndlp
);
2225 return NLP_STE_FREED_NODE
;
2227 return ndlp
->nlp_state
;
2231 lpfc_cmpl_logo_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2232 void *arg
, uint32_t evt
)
2234 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2236 /* For the fabric port just clear the fc flags. */
2237 if (ndlp
->nlp_DID
== Fabric_DID
) {
2238 spin_lock_irq(shost
->host_lock
);
2239 vport
->fc_flag
&= ~(FC_FABRIC
| FC_PUBLIC_LOOP
);
2240 spin_unlock_irq(shost
->host_lock
);
2242 lpfc_unreg_rpi(vport
, ndlp
);
2243 return ndlp
->nlp_state
;
2247 lpfc_cmpl_adisc_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2248 void *arg
, uint32_t evt
)
2250 struct lpfc_iocbq
*cmdiocb
, *rspiocb
;
2253 cmdiocb
= (struct lpfc_iocbq
*) arg
;
2254 rspiocb
= cmdiocb
->context_un
.rsp_iocb
;
2256 irsp
= &rspiocb
->iocb
;
2257 if (irsp
->ulpStatus
&& (ndlp
->nlp_flag
& NLP_NODEV_REMOVE
)) {
2258 lpfc_drop_node(vport
, ndlp
);
2259 return NLP_STE_FREED_NODE
;
2261 return ndlp
->nlp_state
;
2265 lpfc_cmpl_reglogin_npr_node(struct lpfc_vport
*vport
,
2266 struct lpfc_nodelist
*ndlp
,
2267 void *arg
, uint32_t evt
)
2269 LPFC_MBOXQ_t
*pmb
= (LPFC_MBOXQ_t
*) arg
;
2270 MAILBOX_t
*mb
= &pmb
->u
.mb
;
2272 if (!mb
->mbxStatus
) {
2273 /* SLI4 ports have preallocated logical rpis. */
2274 if (vport
->phba
->sli_rev
< LPFC_SLI_REV4
)
2275 ndlp
->nlp_rpi
= mb
->un
.varWords
[0];
2276 ndlp
->nlp_flag
|= NLP_RPI_REGISTERED
;
2278 if (ndlp
->nlp_flag
& NLP_NODEV_REMOVE
) {
2279 lpfc_drop_node(vport
, ndlp
);
2280 return NLP_STE_FREED_NODE
;
2283 return ndlp
->nlp_state
;
2287 lpfc_device_rm_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2288 void *arg
, uint32_t evt
)
2290 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2292 if (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) {
2293 spin_lock_irq(shost
->host_lock
);
2294 ndlp
->nlp_flag
|= NLP_NODEV_REMOVE
;
2295 spin_unlock_irq(shost
->host_lock
);
2296 return ndlp
->nlp_state
;
2298 lpfc_drop_node(vport
, ndlp
);
2299 return NLP_STE_FREED_NODE
;
2303 lpfc_device_recov_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2304 void *arg
, uint32_t evt
)
2306 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2308 /* Don't do anything that will mess up processing of the
2311 if (vport
->fc_flag
& FC_RSCN_DEFERRED
)
2312 return ndlp
->nlp_state
;
2314 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
2315 spin_lock_irq(shost
->host_lock
);
2316 ndlp
->nlp_flag
&= ~(NLP_NODEV_REMOVE
| NLP_NPR_2B_DISC
);
2317 spin_unlock_irq(shost
->host_lock
);
2318 return ndlp
->nlp_state
;
2322 /* This next section defines the NPort Discovery State Machine */
2324 /* There are 4 different double linked lists nodelist entries can reside on.
2325 * The plogi list and adisc list are used when Link Up discovery or RSCN
2326 * processing is needed. Each list holds the nodes that we will send PLOGI
2327 * or ADISC on. These lists will keep track of what nodes will be effected
2328 * by an RSCN, or a Link Up (Typically, all nodes are effected on Link Up).
2329 * The unmapped_list will contain all nodes that we have successfully logged
2330 * into at the Fibre Channel level. The mapped_list will contain all nodes
2331 * that are mapped FCP targets.
2334 * The bind list is a list of undiscovered (potentially non-existent) nodes
2335 * that we have saved binding information on. This information is used when
2336 * nodes transition from the unmapped to the mapped list.
2338 /* For UNUSED_NODE state, the node has just been allocated .
2339 * For PLOGI_ISSUE and REG_LOGIN_ISSUE, the node is on
2340 * the PLOGI list. For REG_LOGIN_COMPL, the node is taken off the PLOGI list
2341 * and put on the unmapped list. For ADISC processing, the node is taken off
2342 * the ADISC list and placed on either the mapped or unmapped list (depending
2343 * on its previous state). Once on the unmapped list, a PRLI is issued and the
2344 * state changed to PRLI_ISSUE. When the PRLI completion occurs, the state is
2345 * changed to UNMAPPED_NODE. If the completion indicates a mapped
2346 * node, the node is taken off the unmapped list. The binding list is checked
2347 * for a valid binding, or a binding is automatically assigned. If binding
2348 * assignment is unsuccessful, the node is left on the unmapped list. If
2349 * binding assignment is successful, the associated binding list entry (if
2350 * any) is removed, and the node is placed on the mapped list.
2353 * For a Link Down, all nodes on the ADISC, PLOGI, unmapped or mapped
2354 * lists will receive a DEVICE_RECOVERY event. If the linkdown or devloss timers
2355 * expire, all effected nodes will receive a DEVICE_RM event.
2358 * For a Link Up or RSCN, all nodes will move from the mapped / unmapped lists
2359 * to either the ADISC or PLOGI list. After a Nameserver query or ALPA loopmap
2360 * check, additional nodes may be added or removed (via DEVICE_RM) to / from
2361 * the PLOGI or ADISC lists. Once the PLOGI and ADISC lists are populated,
2362 * we will first process the ADISC list. 32 entries are processed initially and
2363 * ADISC is initited for each one. Completions / Events for each node are
2364 * funnelled thru the state machine. As each node finishes ADISC processing, it
2365 * starts ADISC for any nodes waiting for ADISC processing. If no nodes are
2366 * waiting, and the ADISC list count is identically 0, then we are done. For
2367 * Link Up discovery, since all nodes on the PLOGI list are UNREG_LOGIN'ed, we
2368 * can issue a CLEAR_LA and reenable Link Events. Next we will process the PLOGI
2369 * list. 32 entries are processed initially and PLOGI is initited for each one.
2370 * Completions / Events for each node are funnelled thru the state machine. As
2371 * each node finishes PLOGI processing, it starts PLOGI for any nodes waiting
2372 * for PLOGI processing. If no nodes are waiting, and the PLOGI list count is
2373 * indentically 0, then we are done. We have now completed discovery / RSCN
2374 * handling. Upon completion, ALL nodes should be on either the mapped or
2378 static uint32_t (*lpfc_disc_action
[NLP_STE_MAX_STATE
* NLP_EVT_MAX_EVENT
])
2379 (struct lpfc_vport
*, struct lpfc_nodelist
*, void *, uint32_t) = {
2380 /* Action routine Event Current State */
2381 lpfc_rcv_plogi_unused_node
, /* RCV_PLOGI UNUSED_NODE */
2382 lpfc_rcv_els_unused_node
, /* RCV_PRLI */
2383 lpfc_rcv_logo_unused_node
, /* RCV_LOGO */
2384 lpfc_rcv_els_unused_node
, /* RCV_ADISC */
2385 lpfc_rcv_els_unused_node
, /* RCV_PDISC */
2386 lpfc_rcv_els_unused_node
, /* RCV_PRLO */
2387 lpfc_disc_illegal
, /* CMPL_PLOGI */
2388 lpfc_disc_illegal
, /* CMPL_PRLI */
2389 lpfc_cmpl_logo_unused_node
, /* CMPL_LOGO */
2390 lpfc_disc_illegal
, /* CMPL_ADISC */
2391 lpfc_disc_illegal
, /* CMPL_REG_LOGIN */
2392 lpfc_device_rm_unused_node
, /* DEVICE_RM */
2393 lpfc_device_recov_unused_node
, /* DEVICE_RECOVERY */
2395 lpfc_rcv_plogi_plogi_issue
, /* RCV_PLOGI PLOGI_ISSUE */
2396 lpfc_rcv_prli_plogi_issue
, /* RCV_PRLI */
2397 lpfc_rcv_logo_plogi_issue
, /* RCV_LOGO */
2398 lpfc_rcv_els_plogi_issue
, /* RCV_ADISC */
2399 lpfc_rcv_els_plogi_issue
, /* RCV_PDISC */
2400 lpfc_rcv_els_plogi_issue
, /* RCV_PRLO */
2401 lpfc_cmpl_plogi_plogi_issue
, /* CMPL_PLOGI */
2402 lpfc_disc_illegal
, /* CMPL_PRLI */
2403 lpfc_cmpl_logo_plogi_issue
, /* CMPL_LOGO */
2404 lpfc_disc_illegal
, /* CMPL_ADISC */
2405 lpfc_cmpl_reglogin_plogi_issue
,/* CMPL_REG_LOGIN */
2406 lpfc_device_rm_plogi_issue
, /* DEVICE_RM */
2407 lpfc_device_recov_plogi_issue
, /* DEVICE_RECOVERY */
2409 lpfc_rcv_plogi_adisc_issue
, /* RCV_PLOGI ADISC_ISSUE */
2410 lpfc_rcv_prli_adisc_issue
, /* RCV_PRLI */
2411 lpfc_rcv_logo_adisc_issue
, /* RCV_LOGO */
2412 lpfc_rcv_padisc_adisc_issue
, /* RCV_ADISC */
2413 lpfc_rcv_padisc_adisc_issue
, /* RCV_PDISC */
2414 lpfc_rcv_prlo_adisc_issue
, /* RCV_PRLO */
2415 lpfc_disc_illegal
, /* CMPL_PLOGI */
2416 lpfc_disc_illegal
, /* CMPL_PRLI */
2417 lpfc_disc_illegal
, /* CMPL_LOGO */
2418 lpfc_cmpl_adisc_adisc_issue
, /* CMPL_ADISC */
2419 lpfc_disc_illegal
, /* CMPL_REG_LOGIN */
2420 lpfc_device_rm_adisc_issue
, /* DEVICE_RM */
2421 lpfc_device_recov_adisc_issue
, /* DEVICE_RECOVERY */
2423 lpfc_rcv_plogi_reglogin_issue
, /* RCV_PLOGI REG_LOGIN_ISSUE */
2424 lpfc_rcv_prli_reglogin_issue
, /* RCV_PLOGI */
2425 lpfc_rcv_logo_reglogin_issue
, /* RCV_LOGO */
2426 lpfc_rcv_padisc_reglogin_issue
, /* RCV_ADISC */
2427 lpfc_rcv_padisc_reglogin_issue
, /* RCV_PDISC */
2428 lpfc_rcv_prlo_reglogin_issue
, /* RCV_PRLO */
2429 lpfc_cmpl_plogi_illegal
, /* CMPL_PLOGI */
2430 lpfc_disc_illegal
, /* CMPL_PRLI */
2431 lpfc_disc_illegal
, /* CMPL_LOGO */
2432 lpfc_disc_illegal
, /* CMPL_ADISC */
2433 lpfc_cmpl_reglogin_reglogin_issue
,/* CMPL_REG_LOGIN */
2434 lpfc_device_rm_reglogin_issue
, /* DEVICE_RM */
2435 lpfc_device_recov_reglogin_issue
,/* DEVICE_RECOVERY */
2437 lpfc_rcv_plogi_prli_issue
, /* RCV_PLOGI PRLI_ISSUE */
2438 lpfc_rcv_prli_prli_issue
, /* RCV_PRLI */
2439 lpfc_rcv_logo_prli_issue
, /* RCV_LOGO */
2440 lpfc_rcv_padisc_prli_issue
, /* RCV_ADISC */
2441 lpfc_rcv_padisc_prli_issue
, /* RCV_PDISC */
2442 lpfc_rcv_prlo_prli_issue
, /* RCV_PRLO */
2443 lpfc_cmpl_plogi_illegal
, /* CMPL_PLOGI */
2444 lpfc_cmpl_prli_prli_issue
, /* CMPL_PRLI */
2445 lpfc_disc_illegal
, /* CMPL_LOGO */
2446 lpfc_disc_illegal
, /* CMPL_ADISC */
2447 lpfc_disc_illegal
, /* CMPL_REG_LOGIN */
2448 lpfc_device_rm_prli_issue
, /* DEVICE_RM */
2449 lpfc_device_recov_prli_issue
, /* DEVICE_RECOVERY */
2451 lpfc_rcv_plogi_logo_issue
, /* RCV_PLOGI LOGO_ISSUE */
2452 lpfc_rcv_prli_logo_issue
, /* RCV_PRLI */
2453 lpfc_rcv_logo_logo_issue
, /* RCV_LOGO */
2454 lpfc_rcv_padisc_logo_issue
, /* RCV_ADISC */
2455 lpfc_rcv_padisc_logo_issue
, /* RCV_PDISC */
2456 lpfc_rcv_prlo_logo_issue
, /* RCV_PRLO */
2457 lpfc_cmpl_plogi_illegal
, /* CMPL_PLOGI */
2458 lpfc_disc_illegal
, /* CMPL_PRLI */
2459 lpfc_cmpl_logo_logo_issue
, /* CMPL_LOGO */
2460 lpfc_disc_illegal
, /* CMPL_ADISC */
2461 lpfc_disc_illegal
, /* CMPL_REG_LOGIN */
2462 lpfc_device_rm_logo_issue
, /* DEVICE_RM */
2463 lpfc_device_recov_logo_issue
, /* DEVICE_RECOVERY */
2465 lpfc_rcv_plogi_unmap_node
, /* RCV_PLOGI UNMAPPED_NODE */
2466 lpfc_rcv_prli_unmap_node
, /* RCV_PRLI */
2467 lpfc_rcv_logo_unmap_node
, /* RCV_LOGO */
2468 lpfc_rcv_padisc_unmap_node
, /* RCV_ADISC */
2469 lpfc_rcv_padisc_unmap_node
, /* RCV_PDISC */
2470 lpfc_rcv_prlo_unmap_node
, /* RCV_PRLO */
2471 lpfc_disc_illegal
, /* CMPL_PLOGI */
2472 lpfc_disc_illegal
, /* CMPL_PRLI */
2473 lpfc_disc_illegal
, /* CMPL_LOGO */
2474 lpfc_disc_illegal
, /* CMPL_ADISC */
2475 lpfc_disc_illegal
, /* CMPL_REG_LOGIN */
2476 lpfc_disc_illegal
, /* DEVICE_RM */
2477 lpfc_device_recov_unmap_node
, /* DEVICE_RECOVERY */
2479 lpfc_rcv_plogi_mapped_node
, /* RCV_PLOGI MAPPED_NODE */
2480 lpfc_rcv_prli_mapped_node
, /* RCV_PRLI */
2481 lpfc_rcv_logo_mapped_node
, /* RCV_LOGO */
2482 lpfc_rcv_padisc_mapped_node
, /* RCV_ADISC */
2483 lpfc_rcv_padisc_mapped_node
, /* RCV_PDISC */
2484 lpfc_rcv_prlo_mapped_node
, /* RCV_PRLO */
2485 lpfc_disc_illegal
, /* CMPL_PLOGI */
2486 lpfc_disc_illegal
, /* CMPL_PRLI */
2487 lpfc_disc_illegal
, /* CMPL_LOGO */
2488 lpfc_disc_illegal
, /* CMPL_ADISC */
2489 lpfc_disc_illegal
, /* CMPL_REG_LOGIN */
2490 lpfc_disc_illegal
, /* DEVICE_RM */
2491 lpfc_device_recov_mapped_node
, /* DEVICE_RECOVERY */
2493 lpfc_rcv_plogi_npr_node
, /* RCV_PLOGI NPR_NODE */
2494 lpfc_rcv_prli_npr_node
, /* RCV_PRLI */
2495 lpfc_rcv_logo_npr_node
, /* RCV_LOGO */
2496 lpfc_rcv_padisc_npr_node
, /* RCV_ADISC */
2497 lpfc_rcv_padisc_npr_node
, /* RCV_PDISC */
2498 lpfc_rcv_prlo_npr_node
, /* RCV_PRLO */
2499 lpfc_cmpl_plogi_npr_node
, /* CMPL_PLOGI */
2500 lpfc_cmpl_prli_npr_node
, /* CMPL_PRLI */
2501 lpfc_cmpl_logo_npr_node
, /* CMPL_LOGO */
2502 lpfc_cmpl_adisc_npr_node
, /* CMPL_ADISC */
2503 lpfc_cmpl_reglogin_npr_node
, /* CMPL_REG_LOGIN */
2504 lpfc_device_rm_npr_node
, /* DEVICE_RM */
2505 lpfc_device_recov_npr_node
, /* DEVICE_RECOVERY */
2509 lpfc_disc_state_machine(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2510 void *arg
, uint32_t evt
)
2512 uint32_t cur_state
, rc
;
2513 uint32_t(*func
) (struct lpfc_vport
*, struct lpfc_nodelist
*, void *,
2515 uint32_t got_ndlp
= 0;
2517 if (lpfc_nlp_get(ndlp
))
2520 cur_state
= ndlp
->nlp_state
;
2522 /* DSM in event <evt> on NPort <nlp_DID> in state <cur_state> */
2523 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
2524 "0211 DSM in event x%x on NPort x%x in "
2525 "state %d Data: x%x\n",
2526 evt
, ndlp
->nlp_DID
, cur_state
, ndlp
->nlp_flag
);
2528 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_DSM
,
2529 "DSM in: evt:%d ste:%d did:x%x",
2530 evt
, cur_state
, ndlp
->nlp_DID
);
2532 func
= lpfc_disc_action
[(cur_state
* NLP_EVT_MAX_EVENT
) + evt
];
2533 rc
= (func
) (vport
, ndlp
, arg
, evt
);
2535 /* DSM out state <rc> on NPort <nlp_DID> */
2537 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
2538 "0212 DSM out state %d on NPort x%x Data: x%x\n",
2539 rc
, ndlp
->nlp_DID
, ndlp
->nlp_flag
);
2541 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_DSM
,
2542 "DSM out: ste:%d did:x%x flg:x%x",
2543 rc
, ndlp
->nlp_DID
, ndlp
->nlp_flag
);
2544 /* Decrement the ndlp reference count held for this function */
2547 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
2548 "0213 DSM out state %d on NPort free\n", rc
);
2550 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_DSM
,
2551 "DSM out: ste:%d did:x%x flg:x%x",