1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2015 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
;
279 uint64_t nlp_portwwn
= 0;
282 struct serv_parm
*sp
;
287 memset(&stat
, 0, sizeof (struct ls_rjt
));
288 if (vport
->port_state
<= LPFC_FDISC
) {
289 /* Before responding to PLOGI, check for pt2pt mode.
290 * If we are pt2pt, with an outstanding FLOGI, abort
291 * the FLOGI and resend it first.
293 if (vport
->fc_flag
& FC_PT2PT
) {
294 lpfc_els_abort_flogi(phba
);
295 if (!(vport
->fc_flag
& FC_PT2PT_PLOGI
)) {
296 /* If the other side is supposed to initiate
297 * the PLOGI anyway, just ACC it now and
298 * move on with discovery.
300 phba
->fc_edtov
= FF_DEF_EDTOV
;
301 phba
->fc_ratov
= FF_DEF_RATOV
;
302 /* Start discovery - this should just do
304 lpfc_disc_start(vport
);
306 lpfc_initial_flogi(vport
);
308 stat
.un
.b
.lsRjtRsnCode
= LSRJT_LOGICAL_BSY
;
309 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_NOTHING_MORE
;
310 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
,
315 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
316 lp
= (uint32_t *) pcmd
->virt
;
317 sp
= (struct serv_parm
*) ((uint8_t *) lp
+ sizeof (uint32_t));
318 if (wwn_to_u64(sp
->portName
.u
.wwn
) == 0) {
319 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
320 "0140 PLOGI Reject: invalid nname\n");
321 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
322 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_INVALID_PNAME
;
323 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
,
327 if (wwn_to_u64(sp
->nodeName
.u
.wwn
) == 0) {
328 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
329 "0141 PLOGI Reject: invalid pname\n");
330 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
331 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_INVALID_NNAME
;
332 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
,
337 nlp_portwwn
= wwn_to_u64(ndlp
->nlp_portname
.u
.wwn
);
338 if ((lpfc_check_sparm(vport
, ndlp
, sp
, CLASS3
, 0) == 0)) {
339 /* Reject this request because invalid parameters */
340 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
341 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_SPARM_OPTIONS
;
342 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
,
346 icmd
= &cmdiocb
->iocb
;
348 /* PLOGI chkparm OK */
349 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
350 "0114 PLOGI chkparm OK Data: x%x x%x x%x "
352 ndlp
->nlp_DID
, ndlp
->nlp_state
, ndlp
->nlp_flag
,
353 ndlp
->nlp_rpi
, vport
->port_state
,
356 if (vport
->cfg_fcp_class
== 2 && sp
->cls2
.classValid
)
357 ndlp
->nlp_fcp_info
|= CLASS2
;
359 ndlp
->nlp_fcp_info
|= CLASS3
;
361 ndlp
->nlp_class_sup
= 0;
362 if (sp
->cls1
.classValid
)
363 ndlp
->nlp_class_sup
|= FC_COS_CLASS1
;
364 if (sp
->cls2
.classValid
)
365 ndlp
->nlp_class_sup
|= FC_COS_CLASS2
;
366 if (sp
->cls3
.classValid
)
367 ndlp
->nlp_class_sup
|= FC_COS_CLASS3
;
368 if (sp
->cls4
.classValid
)
369 ndlp
->nlp_class_sup
|= FC_COS_CLASS4
;
371 ((sp
->cmn
.bbRcvSizeMsb
& 0x0F) << 8) | sp
->cmn
.bbRcvSizeLsb
;
373 /* if already logged in, do implicit logout */
374 switch (ndlp
->nlp_state
) {
375 case NLP_STE_NPR_NODE
:
376 if (!(ndlp
->nlp_flag
& NLP_NPR_ADISC
))
378 case NLP_STE_REG_LOGIN_ISSUE
:
379 case NLP_STE_PRLI_ISSUE
:
380 case NLP_STE_UNMAPPED_NODE
:
381 case NLP_STE_MAPPED_NODE
:
382 /* lpfc_plogi_confirm_nport skips fabric did, handle it here */
383 if (!(ndlp
->nlp_type
& NLP_FABRIC
)) {
384 lpfc_els_rsp_acc(vport
, ELS_CMD_PLOGI
, cmdiocb
,
388 if (nlp_portwwn
!= 0 &&
389 nlp_portwwn
!= wwn_to_u64(sp
->portName
.u
.wwn
))
390 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
391 "0143 PLOGI recv'd from DID: x%x "
392 "WWPN changed: old %llx new %llx\n",
394 (unsigned long long)nlp_portwwn
,
396 wwn_to_u64(sp
->portName
.u
.wwn
));
398 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
399 /* rport needs to be unregistered first */
400 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
404 /* Check for Nport to NPort pt2pt protocol */
405 if ((vport
->fc_flag
& FC_PT2PT
) &&
406 !(vport
->fc_flag
& FC_PT2PT_PLOGI
)) {
408 /* rcv'ed PLOGI decides what our NPortId will be */
409 vport
->fc_myDID
= icmd
->un
.rcvels
.parmRo
;
410 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
413 lpfc_config_link(phba
, mbox
);
414 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
416 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
417 if (rc
== MBX_NOT_FINISHED
) {
418 mempool_free(mbox
, phba
->mbox_mem_pool
);
422 * For SLI4, the VFI/VPI are registered AFTER the
423 * Nport with the higher WWPN sends us a PLOGI with
424 * our assigned NPortId.
426 if (phba
->sli_rev
== LPFC_SLI_REV4
)
427 lpfc_issue_reg_vfi(vport
);
429 lpfc_can_disctmo(vport
);
431 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
435 /* Registering an existing RPI behaves differently for SLI3 vs SLI4 */
436 if (phba
->sli_rev
== LPFC_SLI_REV4
)
437 lpfc_unreg_rpi(vport
, ndlp
);
439 rc
= lpfc_reg_rpi(phba
, vport
->vpi
, icmd
->un
.rcvels
.remoteID
,
440 (uint8_t *) sp
, mbox
, ndlp
->nlp_rpi
);
442 mempool_free(mbox
, phba
->mbox_mem_pool
);
446 /* ACC PLOGI rsp command needs to execute first,
447 * queue this mbox command to be processed later.
449 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_reg_login
;
451 * mbox->context2 = lpfc_nlp_get(ndlp) deferred until mailbox
452 * command issued in lpfc_cmpl_els_acc().
455 spin_lock_irq(shost
->host_lock
);
456 ndlp
->nlp_flag
|= (NLP_ACC_REGLOGIN
| NLP_RCV_PLOGI
);
457 spin_unlock_irq(shost
->host_lock
);
460 * If there is an outstanding PLOGI issued, abort it before
461 * sending ACC rsp for received PLOGI. If pending plogi
462 * is not canceled here, the plogi will be rejected by
463 * remote port and will be retried. On a configuration with
464 * single discovery thread, this will cause a huge delay in
465 * discovery. Also this will cause multiple state machines
466 * running in parallel for this node.
468 if (ndlp
->nlp_state
== NLP_STE_PLOGI_ISSUE
) {
469 /* software abort outstanding PLOGI */
470 lpfc_els_abort(phba
, ndlp
);
473 if ((vport
->port_type
== LPFC_NPIV_PORT
&&
474 vport
->cfg_restrict_login
)) {
476 /* In order to preserve RPIs, we want to cleanup
477 * the default RPI the firmware created to rcv
478 * this ELS request. The only way to do this is
479 * to register, then unregister the RPI.
481 spin_lock_irq(shost
->host_lock
);
482 ndlp
->nlp_flag
|= NLP_RM_DFLT_RPI
;
483 spin_unlock_irq(shost
->host_lock
);
484 stat
.un
.b
.lsRjtRsnCode
= LSRJT_INVALID_CMD
;
485 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_NOTHING_MORE
;
486 rc
= lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
,
489 mempool_free(mbox
, phba
->mbox_mem_pool
);
492 rc
= lpfc_els_rsp_acc(vport
, ELS_CMD_PLOGI
, cmdiocb
, ndlp
, mbox
);
494 mempool_free(mbox
, phba
->mbox_mem_pool
);
497 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
498 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_OUT_OF_RESOURCE
;
499 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
504 * lpfc_mbx_cmpl_resume_rpi - Resume RPI completion routine
505 * @phba: pointer to lpfc hba data structure.
506 * @mboxq: pointer to mailbox object
508 * This routine is invoked to issue a completion to a rcv'ed
509 * ADISC or PDISC after the paused RPI has been resumed.
512 lpfc_mbx_cmpl_resume_rpi(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*mboxq
)
514 struct lpfc_vport
*vport
;
515 struct lpfc_iocbq
*elsiocb
;
516 struct lpfc_nodelist
*ndlp
;
519 elsiocb
= (struct lpfc_iocbq
*)mboxq
->context1
;
520 ndlp
= (struct lpfc_nodelist
*) mboxq
->context2
;
521 vport
= mboxq
->vport
;
522 cmd
= elsiocb
->drvrTimeout
;
524 if (cmd
== ELS_CMD_ADISC
) {
525 lpfc_els_rsp_adisc_acc(vport
, elsiocb
, ndlp
);
527 lpfc_els_rsp_acc(vport
, ELS_CMD_PLOGI
, elsiocb
,
531 mempool_free(mboxq
, phba
->mbox_mem_pool
);
535 lpfc_rcv_padisc(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
536 struct lpfc_iocbq
*cmdiocb
)
538 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
539 struct lpfc_iocbq
*elsiocb
;
540 struct lpfc_dmabuf
*pcmd
;
541 struct serv_parm
*sp
;
542 struct lpfc_name
*pnn
, *ppn
;
549 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
550 lp
= (uint32_t *) pcmd
->virt
;
553 if (cmd
== ELS_CMD_ADISC
) {
555 pnn
= (struct lpfc_name
*) & ap
->nodeName
;
556 ppn
= (struct lpfc_name
*) & ap
->portName
;
558 sp
= (struct serv_parm
*) lp
;
559 pnn
= (struct lpfc_name
*) & sp
->nodeName
;
560 ppn
= (struct lpfc_name
*) & sp
->portName
;
563 icmd
= &cmdiocb
->iocb
;
564 if (icmd
->ulpStatus
== 0 && lpfc_check_adisc(vport
, ndlp
, pnn
, ppn
)) {
567 * As soon as we send ACC, the remote NPort can
568 * start sending us data. Thus, for SLI4 we must
569 * resume the RPI before the ACC goes out.
571 if (vport
->phba
->sli_rev
== LPFC_SLI_REV4
) {
572 elsiocb
= kmalloc(sizeof(struct lpfc_iocbq
),
576 /* Save info from cmd IOCB used in rsp */
577 memcpy((uint8_t *)elsiocb
, (uint8_t *)cmdiocb
,
578 sizeof(struct lpfc_iocbq
));
580 /* Save the ELS cmd */
581 elsiocb
->drvrTimeout
= cmd
;
583 lpfc_sli4_resume_rpi(ndlp
,
584 lpfc_mbx_cmpl_resume_rpi
, elsiocb
);
589 if (cmd
== ELS_CMD_ADISC
) {
590 lpfc_els_rsp_adisc_acc(vport
, cmdiocb
, ndlp
);
592 lpfc_els_rsp_acc(vport
, ELS_CMD_PLOGI
, cmdiocb
,
596 /* If we are authenticated, move to the proper state */
597 if (ndlp
->nlp_type
& NLP_FCP_TARGET
)
598 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_MAPPED_NODE
);
600 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
604 /* Reject this request because invalid parameters */
605 stat
.un
.b
.lsRjtRsvd0
= 0;
606 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
607 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_SPARM_OPTIONS
;
608 stat
.un
.b
.vendorUnique
= 0;
609 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
612 mod_timer(&ndlp
->nlp_delayfunc
, jiffies
+ msecs_to_jiffies(1000));
614 spin_lock_irq(shost
->host_lock
);
615 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
616 spin_unlock_irq(shost
->host_lock
);
617 ndlp
->nlp_last_elscmd
= ELS_CMD_PLOGI
;
618 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
619 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
624 lpfc_rcv_logo(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
625 struct lpfc_iocbq
*cmdiocb
, uint32_t els_cmd
)
627 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
628 struct lpfc_hba
*phba
= vport
->phba
;
629 struct lpfc_vport
**vports
;
630 int i
, active_vlink_present
= 0 ;
632 /* Put ndlp in NPR state with 1 sec timeout for plogi, ACC logo */
633 /* Only call LOGO ACC for first LOGO, this avoids sending unnecessary
634 * PLOGIs during LOGO storms from a device.
636 spin_lock_irq(shost
->host_lock
);
637 ndlp
->nlp_flag
|= NLP_LOGO_ACC
;
638 spin_unlock_irq(shost
->host_lock
);
639 if (els_cmd
== ELS_CMD_PRLO
)
640 lpfc_els_rsp_acc(vport
, ELS_CMD_PRLO
, cmdiocb
, ndlp
, NULL
);
642 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
643 if (ndlp
->nlp_DID
== Fabric_DID
) {
644 if (vport
->port_state
<= LPFC_FDISC
)
646 lpfc_linkdown_port(vport
);
647 spin_lock_irq(shost
->host_lock
);
648 vport
->fc_flag
|= FC_VPORT_LOGO_RCVD
;
649 spin_unlock_irq(shost
->host_lock
);
650 vports
= lpfc_create_vport_work_array(phba
);
652 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
;
654 if ((!(vports
[i
]->fc_flag
&
655 FC_VPORT_LOGO_RCVD
)) &&
656 (vports
[i
]->port_state
> LPFC_FDISC
)) {
657 active_vlink_present
= 1;
661 lpfc_destroy_vport_work_array(phba
, vports
);
665 * Don't re-instantiate if vport is marked for deletion.
666 * If we are here first then vport_delete is going to wait
667 * for discovery to complete.
669 if (!(vport
->load_flag
& FC_UNLOADING
) &&
670 active_vlink_present
) {
672 * If there are other active VLinks present,
673 * re-instantiate the Vlink using FDISC.
675 mod_timer(&ndlp
->nlp_delayfunc
,
676 jiffies
+ msecs_to_jiffies(1000));
677 spin_lock_irq(shost
->host_lock
);
678 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
679 spin_unlock_irq(shost
->host_lock
);
680 ndlp
->nlp_last_elscmd
= ELS_CMD_FDISC
;
681 vport
->port_state
= LPFC_FDISC
;
683 spin_lock_irq(shost
->host_lock
);
684 phba
->pport
->fc_flag
&= ~FC_LOGO_RCVD_DID_CHNG
;
685 spin_unlock_irq(shost
->host_lock
);
686 lpfc_retry_pport_discovery(phba
);
688 } else if ((!(ndlp
->nlp_type
& NLP_FABRIC
) &&
689 ((ndlp
->nlp_type
& NLP_FCP_TARGET
) ||
690 !(ndlp
->nlp_type
& NLP_FCP_INITIATOR
))) ||
691 (ndlp
->nlp_state
== NLP_STE_ADISC_ISSUE
)) {
692 /* Only try to re-login if this is NOT a Fabric Node */
693 mod_timer(&ndlp
->nlp_delayfunc
,
694 jiffies
+ msecs_to_jiffies(1000 * 1));
695 spin_lock_irq(shost
->host_lock
);
696 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
697 spin_unlock_irq(shost
->host_lock
);
699 ndlp
->nlp_last_elscmd
= ELS_CMD_PLOGI
;
702 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
703 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
705 spin_lock_irq(shost
->host_lock
);
706 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
707 spin_unlock_irq(shost
->host_lock
);
708 /* The driver has to wait until the ACC completes before it continues
709 * processing the LOGO. The action will resume in
710 * lpfc_cmpl_els_logo_acc routine. Since part of processing includes an
711 * unreg_login, the driver waits so the ACC does not get aborted.
717 lpfc_rcv_prli(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
718 struct lpfc_iocbq
*cmdiocb
)
720 struct lpfc_dmabuf
*pcmd
;
723 struct fc_rport
*rport
= ndlp
->rport
;
726 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
727 lp
= (uint32_t *) pcmd
->virt
;
728 npr
= (PRLI
*) ((uint8_t *) lp
+ sizeof (uint32_t));
730 ndlp
->nlp_type
&= ~(NLP_FCP_TARGET
| NLP_FCP_INITIATOR
);
731 ndlp
->nlp_fcp_info
&= ~NLP_FCP_2_DEVICE
;
732 ndlp
->nlp_flag
&= ~NLP_FIRSTBURST
;
733 if (npr
->prliType
== PRLI_FCP_TYPE
) {
734 if (npr
->initiatorFunc
)
735 ndlp
->nlp_type
|= NLP_FCP_INITIATOR
;
736 if (npr
->targetFunc
) {
737 ndlp
->nlp_type
|= NLP_FCP_TARGET
;
738 if (npr
->writeXferRdyDis
)
739 ndlp
->nlp_flag
|= NLP_FIRSTBURST
;
742 ndlp
->nlp_fcp_info
|= NLP_FCP_2_DEVICE
;
745 /* We need to update the rport role values */
746 roles
= FC_RPORT_ROLE_UNKNOWN
;
747 if (ndlp
->nlp_type
& NLP_FCP_INITIATOR
)
748 roles
|= FC_RPORT_ROLE_FCP_INITIATOR
;
749 if (ndlp
->nlp_type
& NLP_FCP_TARGET
)
750 roles
|= FC_RPORT_ROLE_FCP_TARGET
;
752 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_RPORT
,
753 "rport rolechg: role:x%x did:x%x flg:x%x",
754 roles
, ndlp
->nlp_DID
, ndlp
->nlp_flag
);
756 fc_remote_port_rolechg(rport
, roles
);
761 lpfc_disc_set_adisc(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
763 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
765 if (!(ndlp
->nlp_flag
& NLP_RPI_REGISTERED
)) {
766 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
770 if (!(vport
->fc_flag
& FC_PT2PT
)) {
771 /* Check config parameter use-adisc or FCP-2 */
772 if ((vport
->cfg_use_adisc
&& (vport
->fc_flag
& FC_RSCN_MODE
)) ||
773 ((ndlp
->nlp_fcp_info
& NLP_FCP_2_DEVICE
) &&
774 (ndlp
->nlp_type
& NLP_FCP_TARGET
))) {
775 spin_lock_irq(shost
->host_lock
);
776 ndlp
->nlp_flag
|= NLP_NPR_ADISC
;
777 spin_unlock_irq(shost
->host_lock
);
781 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
782 lpfc_unreg_rpi(vport
, ndlp
);
787 * lpfc_release_rpi - Release a RPI by issuing unreg_login mailbox cmd.
788 * @phba : Pointer to lpfc_hba structure.
789 * @vport: Pointer to lpfc_vport structure.
790 * @rpi : rpi to be release.
792 * This function will send a unreg_login mailbox command to the firmware
796 lpfc_release_rpi(struct lpfc_hba
*phba
,
797 struct lpfc_vport
*vport
,
803 pmb
= (LPFC_MBOXQ_t
*) mempool_alloc(phba
->mbox_mem_pool
,
806 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
807 "2796 mailbox memory allocation failed \n");
809 lpfc_unreg_login(phba
, vport
->vpi
, rpi
, pmb
);
810 pmb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
811 rc
= lpfc_sli_issue_mbox(phba
, pmb
, MBX_NOWAIT
);
812 if (rc
== MBX_NOT_FINISHED
)
813 mempool_free(pmb
, phba
->mbox_mem_pool
);
818 lpfc_disc_illegal(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
819 void *arg
, uint32_t evt
)
821 struct lpfc_hba
*phba
;
822 LPFC_MBOXQ_t
*pmb
= (LPFC_MBOXQ_t
*) arg
;
826 /* Release the RPI if reglogin completing */
827 if (!(phba
->pport
->load_flag
& FC_UNLOADING
) &&
828 (evt
== NLP_EVT_CMPL_REG_LOGIN
) &&
829 (!pmb
->u
.mb
.mbxStatus
)) {
830 rpi
= pmb
->u
.mb
.un
.varWords
[0];
831 lpfc_release_rpi(phba
, vport
, rpi
);
833 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
834 "0271 Illegal State Transition: node x%x "
835 "event x%x, state x%x Data: x%x x%x\n",
836 ndlp
->nlp_DID
, evt
, ndlp
->nlp_state
, ndlp
->nlp_rpi
,
838 return ndlp
->nlp_state
;
842 lpfc_cmpl_plogi_illegal(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
843 void *arg
, uint32_t evt
)
845 /* This transition is only legal if we previously
846 * rcv'ed a PLOGI. Since we don't want 2 discovery threads
847 * working on the same NPortID, do nothing for this thread
850 if (!(ndlp
->nlp_flag
& NLP_RCV_PLOGI
)) {
851 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
852 "0272 Illegal State Transition: node x%x "
853 "event x%x, state x%x Data: x%x x%x\n",
854 ndlp
->nlp_DID
, evt
, ndlp
->nlp_state
, ndlp
->nlp_rpi
,
857 return ndlp
->nlp_state
;
860 /* Start of Discovery State Machine routines */
863 lpfc_rcv_plogi_unused_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
864 void *arg
, uint32_t evt
)
866 struct lpfc_iocbq
*cmdiocb
;
868 cmdiocb
= (struct lpfc_iocbq
*) arg
;
870 if (lpfc_rcv_plogi(vport
, ndlp
, cmdiocb
)) {
871 return ndlp
->nlp_state
;
873 return NLP_STE_FREED_NODE
;
877 lpfc_rcv_els_unused_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
878 void *arg
, uint32_t evt
)
880 lpfc_issue_els_logo(vport
, ndlp
, 0);
881 return ndlp
->nlp_state
;
885 lpfc_rcv_logo_unused_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
886 void *arg
, uint32_t evt
)
888 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
889 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
891 spin_lock_irq(shost
->host_lock
);
892 ndlp
->nlp_flag
|= NLP_LOGO_ACC
;
893 spin_unlock_irq(shost
->host_lock
);
894 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
896 return ndlp
->nlp_state
;
900 lpfc_cmpl_logo_unused_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
901 void *arg
, uint32_t evt
)
903 return NLP_STE_FREED_NODE
;
907 lpfc_device_rm_unused_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
908 void *arg
, uint32_t evt
)
910 return NLP_STE_FREED_NODE
;
914 lpfc_device_recov_unused_node(struct lpfc_vport
*vport
,
915 struct lpfc_nodelist
*ndlp
,
916 void *arg
, uint32_t evt
)
918 return ndlp
->nlp_state
;
922 lpfc_rcv_plogi_plogi_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
923 void *arg
, uint32_t evt
)
925 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
926 struct lpfc_hba
*phba
= vport
->phba
;
927 struct lpfc_iocbq
*cmdiocb
= arg
;
928 struct lpfc_dmabuf
*pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
929 uint32_t *lp
= (uint32_t *) pcmd
->virt
;
930 struct serv_parm
*sp
= (struct serv_parm
*) (lp
+ 1);
934 memset(&stat
, 0, sizeof (struct ls_rjt
));
936 /* For a PLOGI, we only accept if our portname is less
937 * than the remote portname.
939 phba
->fc_stat
.elsLogiCol
++;
940 port_cmp
= memcmp(&vport
->fc_portname
, &sp
->portName
,
941 sizeof(struct lpfc_name
));
944 /* Reject this request because the remote node will accept
946 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
947 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CMD_IN_PROGRESS
;
948 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
,
951 if (lpfc_rcv_plogi(vport
, ndlp
, cmdiocb
) &&
952 (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) &&
953 (vport
->num_disc_nodes
)) {
954 spin_lock_irq(shost
->host_lock
);
955 ndlp
->nlp_flag
&= ~NLP_NPR_2B_DISC
;
956 spin_unlock_irq(shost
->host_lock
);
957 /* Check if there are more PLOGIs to be sent */
958 lpfc_more_plogi(vport
);
959 if (vport
->num_disc_nodes
== 0) {
960 spin_lock_irq(shost
->host_lock
);
961 vport
->fc_flag
&= ~FC_NDISC_ACTIVE
;
962 spin_unlock_irq(shost
->host_lock
);
963 lpfc_can_disctmo(vport
);
964 lpfc_end_rscn(vport
);
967 } /* If our portname was less */
969 return ndlp
->nlp_state
;
973 lpfc_rcv_prli_plogi_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
974 void *arg
, uint32_t evt
)
976 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
979 memset(&stat
, 0, sizeof (struct ls_rjt
));
980 stat
.un
.b
.lsRjtRsnCode
= LSRJT_LOGICAL_BSY
;
981 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_NOTHING_MORE
;
982 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
983 return ndlp
->nlp_state
;
987 lpfc_rcv_logo_plogi_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
988 void *arg
, uint32_t evt
)
990 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
992 /* software abort outstanding PLOGI */
993 lpfc_els_abort(vport
->phba
, ndlp
);
995 lpfc_rcv_logo(vport
, ndlp
, cmdiocb
, ELS_CMD_LOGO
);
996 return ndlp
->nlp_state
;
1000 lpfc_rcv_els_plogi_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1001 void *arg
, uint32_t evt
)
1003 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1004 struct lpfc_hba
*phba
= vport
->phba
;
1005 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1007 /* software abort outstanding PLOGI */
1008 lpfc_els_abort(phba
, ndlp
);
1010 if (evt
== NLP_EVT_RCV_LOGO
) {
1011 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
1013 lpfc_issue_els_logo(vport
, ndlp
, 0);
1016 /* Put ndlp in npr state set plogi timer for 1 sec */
1017 mod_timer(&ndlp
->nlp_delayfunc
, jiffies
+ msecs_to_jiffies(1000 * 1));
1018 spin_lock_irq(shost
->host_lock
);
1019 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
1020 spin_unlock_irq(shost
->host_lock
);
1021 ndlp
->nlp_last_elscmd
= ELS_CMD_PLOGI
;
1022 ndlp
->nlp_prev_state
= NLP_STE_PLOGI_ISSUE
;
1023 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1025 return ndlp
->nlp_state
;
1029 lpfc_cmpl_plogi_plogi_issue(struct lpfc_vport
*vport
,
1030 struct lpfc_nodelist
*ndlp
,
1034 struct lpfc_hba
*phba
= vport
->phba
;
1035 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1036 struct lpfc_iocbq
*cmdiocb
, *rspiocb
;
1037 struct lpfc_dmabuf
*pcmd
, *prsp
, *mp
;
1040 struct serv_parm
*sp
;
1043 cmdiocb
= (struct lpfc_iocbq
*) arg
;
1044 rspiocb
= cmdiocb
->context_un
.rsp_iocb
;
1046 if (ndlp
->nlp_flag
& NLP_ACC_REGLOGIN
) {
1047 /* Recovery from PLOGI collision logic */
1048 return ndlp
->nlp_state
;
1051 irsp
= &rspiocb
->iocb
;
1053 if (irsp
->ulpStatus
)
1056 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
1058 prsp
= list_get_first(&pcmd
->list
, struct lpfc_dmabuf
, list
);
1062 lp
= (uint32_t *) prsp
->virt
;
1063 sp
= (struct serv_parm
*) ((uint8_t *) lp
+ sizeof (uint32_t));
1065 /* Some switches have FDMI servers returning 0 for WWN */
1066 if ((ndlp
->nlp_DID
!= FDMI_DID
) &&
1067 (wwn_to_u64(sp
->portName
.u
.wwn
) == 0 ||
1068 wwn_to_u64(sp
->nodeName
.u
.wwn
) == 0)) {
1069 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1070 "0142 PLOGI RSP: Invalid WWN.\n");
1073 if (!lpfc_check_sparm(vport
, ndlp
, sp
, CLASS3
, 0))
1075 /* PLOGI chkparm OK */
1076 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
1077 "0121 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
1078 ndlp
->nlp_DID
, ndlp
->nlp_state
,
1079 ndlp
->nlp_flag
, ndlp
->nlp_rpi
);
1080 if (vport
->cfg_fcp_class
== 2 && (sp
->cls2
.classValid
))
1081 ndlp
->nlp_fcp_info
|= CLASS2
;
1083 ndlp
->nlp_fcp_info
|= CLASS3
;
1085 ndlp
->nlp_class_sup
= 0;
1086 if (sp
->cls1
.classValid
)
1087 ndlp
->nlp_class_sup
|= FC_COS_CLASS1
;
1088 if (sp
->cls2
.classValid
)
1089 ndlp
->nlp_class_sup
|= FC_COS_CLASS2
;
1090 if (sp
->cls3
.classValid
)
1091 ndlp
->nlp_class_sup
|= FC_COS_CLASS3
;
1092 if (sp
->cls4
.classValid
)
1093 ndlp
->nlp_class_sup
|= FC_COS_CLASS4
;
1094 ndlp
->nlp_maxframe
=
1095 ((sp
->cmn
.bbRcvSizeMsb
& 0x0F) << 8) | sp
->cmn
.bbRcvSizeLsb
;
1097 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1099 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1100 "0133 PLOGI: no memory for reg_login "
1101 "Data: x%x x%x x%x x%x\n",
1102 ndlp
->nlp_DID
, ndlp
->nlp_state
,
1103 ndlp
->nlp_flag
, ndlp
->nlp_rpi
);
1107 lpfc_unreg_rpi(vport
, ndlp
);
1109 if (lpfc_reg_rpi(phba
, vport
->vpi
, irsp
->un
.elsreq64
.remoteID
,
1110 (uint8_t *) sp
, mbox
, ndlp
->nlp_rpi
) == 0) {
1111 switch (ndlp
->nlp_DID
) {
1112 case NameServer_DID
:
1113 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_ns_reg_login
;
1116 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_fdmi_reg_login
;
1119 ndlp
->nlp_flag
|= NLP_REG_LOGIN_SEND
;
1120 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_reg_login
;
1122 mbox
->context2
= lpfc_nlp_get(ndlp
);
1123 mbox
->vport
= vport
;
1124 if (lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
)
1125 != MBX_NOT_FINISHED
) {
1126 lpfc_nlp_set_state(vport
, ndlp
,
1127 NLP_STE_REG_LOGIN_ISSUE
);
1128 return ndlp
->nlp_state
;
1130 if (ndlp
->nlp_flag
& NLP_REG_LOGIN_SEND
)
1131 ndlp
->nlp_flag
&= ~NLP_REG_LOGIN_SEND
;
1132 /* decrement node reference count to the failed mbox
1136 mp
= (struct lpfc_dmabuf
*) mbox
->context1
;
1137 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
1139 mempool_free(mbox
, phba
->mbox_mem_pool
);
1141 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1142 "0134 PLOGI: cannot issue reg_login "
1143 "Data: x%x x%x x%x x%x\n",
1144 ndlp
->nlp_DID
, ndlp
->nlp_state
,
1145 ndlp
->nlp_flag
, ndlp
->nlp_rpi
);
1147 mempool_free(mbox
, phba
->mbox_mem_pool
);
1149 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1150 "0135 PLOGI: cannot format reg_login "
1151 "Data: x%x x%x x%x x%x\n",
1152 ndlp
->nlp_DID
, ndlp
->nlp_state
,
1153 ndlp
->nlp_flag
, ndlp
->nlp_rpi
);
1158 if (ndlp
->nlp_DID
== NameServer_DID
) {
1159 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
1160 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1161 "0261 Cannot Register NameServer login\n");
1165 ** In case the node reference counter does not go to zero, ensure that
1166 ** the stale state for the node is not processed.
1169 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
1170 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1171 spin_lock_irq(shost
->host_lock
);
1172 ndlp
->nlp_flag
|= NLP_DEFER_RM
;
1173 spin_unlock_irq(shost
->host_lock
);
1174 return NLP_STE_FREED_NODE
;
1178 lpfc_cmpl_logo_plogi_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1179 void *arg
, uint32_t evt
)
1181 return ndlp
->nlp_state
;
1185 lpfc_cmpl_reglogin_plogi_issue(struct lpfc_vport
*vport
,
1186 struct lpfc_nodelist
*ndlp
, void *arg
, uint32_t evt
)
1188 struct lpfc_hba
*phba
;
1189 LPFC_MBOXQ_t
*pmb
= (LPFC_MBOXQ_t
*) arg
;
1190 MAILBOX_t
*mb
= &pmb
->u
.mb
;
1194 /* Release the RPI */
1195 if (!(phba
->pport
->load_flag
& FC_UNLOADING
) &&
1197 rpi
= pmb
->u
.mb
.un
.varWords
[0];
1198 lpfc_release_rpi(phba
, vport
, rpi
);
1200 return ndlp
->nlp_state
;
1204 lpfc_device_rm_plogi_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1205 void *arg
, uint32_t evt
)
1207 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1209 if (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) {
1210 spin_lock_irq(shost
->host_lock
);
1211 ndlp
->nlp_flag
|= NLP_NODEV_REMOVE
;
1212 spin_unlock_irq(shost
->host_lock
);
1213 return ndlp
->nlp_state
;
1215 /* software abort outstanding PLOGI */
1216 lpfc_els_abort(vport
->phba
, ndlp
);
1218 lpfc_drop_node(vport
, ndlp
);
1219 return NLP_STE_FREED_NODE
;
1224 lpfc_device_recov_plogi_issue(struct lpfc_vport
*vport
,
1225 struct lpfc_nodelist
*ndlp
,
1229 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1230 struct lpfc_hba
*phba
= vport
->phba
;
1232 /* Don't do anything that will mess up processing of the
1235 if (vport
->fc_flag
& FC_RSCN_DEFERRED
)
1236 return ndlp
->nlp_state
;
1238 /* software abort outstanding PLOGI */
1239 lpfc_els_abort(phba
, ndlp
);
1241 ndlp
->nlp_prev_state
= NLP_STE_PLOGI_ISSUE
;
1242 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1243 spin_lock_irq(shost
->host_lock
);
1244 ndlp
->nlp_flag
&= ~(NLP_NODEV_REMOVE
| NLP_NPR_2B_DISC
);
1245 spin_unlock_irq(shost
->host_lock
);
1247 return ndlp
->nlp_state
;
1251 lpfc_rcv_plogi_adisc_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1252 void *arg
, uint32_t evt
)
1254 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1255 struct lpfc_hba
*phba
= vport
->phba
;
1256 struct lpfc_iocbq
*cmdiocb
;
1258 /* software abort outstanding ADISC */
1259 lpfc_els_abort(phba
, ndlp
);
1261 cmdiocb
= (struct lpfc_iocbq
*) arg
;
1263 if (lpfc_rcv_plogi(vport
, ndlp
, cmdiocb
)) {
1264 if (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) {
1265 spin_lock_irq(shost
->host_lock
);
1266 ndlp
->nlp_flag
&= ~NLP_NPR_2B_DISC
;
1267 spin_unlock_irq(shost
->host_lock
);
1268 if (vport
->num_disc_nodes
)
1269 lpfc_more_adisc(vport
);
1271 return ndlp
->nlp_state
;
1273 ndlp
->nlp_prev_state
= NLP_STE_ADISC_ISSUE
;
1274 lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0);
1275 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
1277 return ndlp
->nlp_state
;
1281 lpfc_rcv_prli_adisc_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1282 void *arg
, uint32_t evt
)
1284 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1286 lpfc_els_rsp_prli_acc(vport
, cmdiocb
, ndlp
);
1287 return ndlp
->nlp_state
;
1291 lpfc_rcv_logo_adisc_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1292 void *arg
, uint32_t evt
)
1294 struct lpfc_hba
*phba
= vport
->phba
;
1295 struct lpfc_iocbq
*cmdiocb
;
1297 cmdiocb
= (struct lpfc_iocbq
*) arg
;
1299 /* software abort outstanding ADISC */
1300 lpfc_els_abort(phba
, ndlp
);
1302 lpfc_rcv_logo(vport
, ndlp
, cmdiocb
, ELS_CMD_LOGO
);
1303 return ndlp
->nlp_state
;
1307 lpfc_rcv_padisc_adisc_issue(struct lpfc_vport
*vport
,
1308 struct lpfc_nodelist
*ndlp
,
1309 void *arg
, uint32_t evt
)
1311 struct lpfc_iocbq
*cmdiocb
;
1313 cmdiocb
= (struct lpfc_iocbq
*) arg
;
1315 lpfc_rcv_padisc(vport
, ndlp
, cmdiocb
);
1316 return ndlp
->nlp_state
;
1320 lpfc_rcv_prlo_adisc_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1321 void *arg
, uint32_t evt
)
1323 struct lpfc_iocbq
*cmdiocb
;
1325 cmdiocb
= (struct lpfc_iocbq
*) arg
;
1327 /* Treat like rcv logo */
1328 lpfc_rcv_logo(vport
, ndlp
, cmdiocb
, ELS_CMD_PRLO
);
1329 return ndlp
->nlp_state
;
1333 lpfc_cmpl_adisc_adisc_issue(struct lpfc_vport
*vport
,
1334 struct lpfc_nodelist
*ndlp
,
1335 void *arg
, uint32_t evt
)
1337 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1338 struct lpfc_hba
*phba
= vport
->phba
;
1339 struct lpfc_iocbq
*cmdiocb
, *rspiocb
;
1344 cmdiocb
= (struct lpfc_iocbq
*) arg
;
1345 rspiocb
= cmdiocb
->context_un
.rsp_iocb
;
1347 ap
= (ADISC
*)lpfc_check_elscmpl_iocb(phba
, cmdiocb
, rspiocb
);
1348 irsp
= &rspiocb
->iocb
;
1350 if ((irsp
->ulpStatus
) ||
1351 (!lpfc_check_adisc(vport
, ndlp
, &ap
->nodeName
, &ap
->portName
))) {
1353 mod_timer(&ndlp
->nlp_delayfunc
,
1354 jiffies
+ msecs_to_jiffies(1000));
1355 spin_lock_irq(shost
->host_lock
);
1356 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
1357 spin_unlock_irq(shost
->host_lock
);
1358 ndlp
->nlp_last_elscmd
= ELS_CMD_PLOGI
;
1360 memset(&ndlp
->nlp_nodename
, 0, sizeof(struct lpfc_name
));
1361 memset(&ndlp
->nlp_portname
, 0, sizeof(struct lpfc_name
));
1363 ndlp
->nlp_prev_state
= NLP_STE_ADISC_ISSUE
;
1364 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1365 lpfc_unreg_rpi(vport
, ndlp
);
1366 return ndlp
->nlp_state
;
1369 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
1370 rc
= lpfc_sli4_resume_rpi(ndlp
, NULL
, NULL
);
1372 /* Stay in state and retry. */
1373 ndlp
->nlp_prev_state
= NLP_STE_ADISC_ISSUE
;
1374 return ndlp
->nlp_state
;
1378 if (ndlp
->nlp_type
& NLP_FCP_TARGET
) {
1379 ndlp
->nlp_prev_state
= NLP_STE_ADISC_ISSUE
;
1380 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_MAPPED_NODE
);
1382 ndlp
->nlp_prev_state
= NLP_STE_ADISC_ISSUE
;
1383 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
1386 return ndlp
->nlp_state
;
1390 lpfc_device_rm_adisc_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1391 void *arg
, uint32_t evt
)
1393 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1395 if (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) {
1396 spin_lock_irq(shost
->host_lock
);
1397 ndlp
->nlp_flag
|= NLP_NODEV_REMOVE
;
1398 spin_unlock_irq(shost
->host_lock
);
1399 return ndlp
->nlp_state
;
1401 /* software abort outstanding ADISC */
1402 lpfc_els_abort(vport
->phba
, ndlp
);
1404 lpfc_drop_node(vport
, ndlp
);
1405 return NLP_STE_FREED_NODE
;
1410 lpfc_device_recov_adisc_issue(struct lpfc_vport
*vport
,
1411 struct lpfc_nodelist
*ndlp
,
1415 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1416 struct lpfc_hba
*phba
= vport
->phba
;
1418 /* Don't do anything that will mess up processing of the
1421 if (vport
->fc_flag
& FC_RSCN_DEFERRED
)
1422 return ndlp
->nlp_state
;
1424 /* software abort outstanding ADISC */
1425 lpfc_els_abort(phba
, ndlp
);
1427 ndlp
->nlp_prev_state
= NLP_STE_ADISC_ISSUE
;
1428 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1429 spin_lock_irq(shost
->host_lock
);
1430 ndlp
->nlp_flag
&= ~(NLP_NODEV_REMOVE
| NLP_NPR_2B_DISC
);
1431 spin_unlock_irq(shost
->host_lock
);
1432 lpfc_disc_set_adisc(vport
, ndlp
);
1433 return ndlp
->nlp_state
;
1437 lpfc_rcv_plogi_reglogin_issue(struct lpfc_vport
*vport
,
1438 struct lpfc_nodelist
*ndlp
,
1442 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1444 lpfc_rcv_plogi(vport
, ndlp
, cmdiocb
);
1445 return ndlp
->nlp_state
;
1449 lpfc_rcv_prli_reglogin_issue(struct lpfc_vport
*vport
,
1450 struct lpfc_nodelist
*ndlp
,
1454 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1456 lpfc_els_rsp_prli_acc(vport
, cmdiocb
, ndlp
);
1457 return ndlp
->nlp_state
;
1461 lpfc_rcv_logo_reglogin_issue(struct lpfc_vport
*vport
,
1462 struct lpfc_nodelist
*ndlp
,
1466 struct lpfc_hba
*phba
= vport
->phba
;
1467 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1469 LPFC_MBOXQ_t
*nextmb
;
1470 struct lpfc_dmabuf
*mp
;
1472 cmdiocb
= (struct lpfc_iocbq
*) arg
;
1474 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
1475 if ((mb
= phba
->sli
.mbox_active
)) {
1476 if ((mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) &&
1477 (ndlp
== (struct lpfc_nodelist
*) mb
->context2
)) {
1479 mb
->context2
= NULL
;
1480 mb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
1484 spin_lock_irq(&phba
->hbalock
);
1485 list_for_each_entry_safe(mb
, nextmb
, &phba
->sli
.mboxq
, list
) {
1486 if ((mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) &&
1487 (ndlp
== (struct lpfc_nodelist
*) mb
->context2
)) {
1488 mp
= (struct lpfc_dmabuf
*) (mb
->context1
);
1490 __lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
1494 list_del(&mb
->list
);
1495 phba
->sli
.mboxq_cnt
--;
1496 mempool_free(mb
, phba
->mbox_mem_pool
);
1499 spin_unlock_irq(&phba
->hbalock
);
1501 lpfc_rcv_logo(vport
, ndlp
, cmdiocb
, ELS_CMD_LOGO
);
1502 return ndlp
->nlp_state
;
1506 lpfc_rcv_padisc_reglogin_issue(struct lpfc_vport
*vport
,
1507 struct lpfc_nodelist
*ndlp
,
1511 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1513 lpfc_rcv_padisc(vport
, ndlp
, cmdiocb
);
1514 return ndlp
->nlp_state
;
1518 lpfc_rcv_prlo_reglogin_issue(struct lpfc_vport
*vport
,
1519 struct lpfc_nodelist
*ndlp
,
1523 struct lpfc_iocbq
*cmdiocb
;
1525 cmdiocb
= (struct lpfc_iocbq
*) arg
;
1526 lpfc_els_rsp_acc(vport
, ELS_CMD_PRLO
, cmdiocb
, ndlp
, NULL
);
1527 return ndlp
->nlp_state
;
1531 lpfc_cmpl_reglogin_reglogin_issue(struct lpfc_vport
*vport
,
1532 struct lpfc_nodelist
*ndlp
,
1536 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1537 LPFC_MBOXQ_t
*pmb
= (LPFC_MBOXQ_t
*) arg
;
1538 MAILBOX_t
*mb
= &pmb
->u
.mb
;
1539 uint32_t did
= mb
->un
.varWords
[1];
1541 if (mb
->mbxStatus
) {
1542 /* RegLogin failed */
1543 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
1544 "0246 RegLogin failed Data: x%x x%x x%x x%x "
1546 did
, mb
->mbxStatus
, vport
->port_state
,
1547 mb
->un
.varRegLogin
.vpi
,
1548 mb
->un
.varRegLogin
.rpi
);
1550 * If RegLogin failed due to lack of HBA resources do not
1553 if (mb
->mbxStatus
== MBXERR_RPI_FULL
) {
1554 ndlp
->nlp_prev_state
= NLP_STE_REG_LOGIN_ISSUE
;
1555 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1556 return ndlp
->nlp_state
;
1559 /* Put ndlp in npr state set plogi timer for 1 sec */
1560 mod_timer(&ndlp
->nlp_delayfunc
,
1561 jiffies
+ msecs_to_jiffies(1000 * 1));
1562 spin_lock_irq(shost
->host_lock
);
1563 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
1564 spin_unlock_irq(shost
->host_lock
);
1565 ndlp
->nlp_last_elscmd
= ELS_CMD_PLOGI
;
1567 lpfc_issue_els_logo(vport
, ndlp
, 0);
1568 ndlp
->nlp_prev_state
= NLP_STE_REG_LOGIN_ISSUE
;
1569 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1570 return ndlp
->nlp_state
;
1573 /* SLI4 ports have preallocated logical rpis. */
1574 if (vport
->phba
->sli_rev
< LPFC_SLI_REV4
)
1575 ndlp
->nlp_rpi
= mb
->un
.varWords
[0];
1577 ndlp
->nlp_flag
|= NLP_RPI_REGISTERED
;
1579 /* Only if we are not a fabric nport do we issue PRLI */
1580 if (!(ndlp
->nlp_type
& NLP_FABRIC
)) {
1581 ndlp
->nlp_prev_state
= NLP_STE_REG_LOGIN_ISSUE
;
1582 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PRLI_ISSUE
);
1583 lpfc_issue_els_prli(vport
, ndlp
, 0);
1585 ndlp
->nlp_prev_state
= NLP_STE_REG_LOGIN_ISSUE
;
1586 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
1588 return ndlp
->nlp_state
;
1592 lpfc_device_rm_reglogin_issue(struct lpfc_vport
*vport
,
1593 struct lpfc_nodelist
*ndlp
,
1597 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1599 if (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) {
1600 spin_lock_irq(shost
->host_lock
);
1601 ndlp
->nlp_flag
|= NLP_NODEV_REMOVE
;
1602 spin_unlock_irq(shost
->host_lock
);
1603 return ndlp
->nlp_state
;
1605 lpfc_drop_node(vport
, ndlp
);
1606 return NLP_STE_FREED_NODE
;
1611 lpfc_device_recov_reglogin_issue(struct lpfc_vport
*vport
,
1612 struct lpfc_nodelist
*ndlp
,
1616 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1618 /* Don't do anything that will mess up processing of the
1621 if (vport
->fc_flag
& FC_RSCN_DEFERRED
)
1622 return ndlp
->nlp_state
;
1624 ndlp
->nlp_prev_state
= NLP_STE_REG_LOGIN_ISSUE
;
1625 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1626 spin_lock_irq(shost
->host_lock
);
1627 ndlp
->nlp_flag
|= NLP_IGNR_REG_CMPL
;
1628 ndlp
->nlp_flag
&= ~(NLP_NODEV_REMOVE
| NLP_NPR_2B_DISC
);
1629 spin_unlock_irq(shost
->host_lock
);
1630 lpfc_disc_set_adisc(vport
, ndlp
);
1631 return ndlp
->nlp_state
;
1635 lpfc_rcv_plogi_prli_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1636 void *arg
, uint32_t evt
)
1638 struct lpfc_iocbq
*cmdiocb
;
1640 cmdiocb
= (struct lpfc_iocbq
*) arg
;
1642 lpfc_rcv_plogi(vport
, ndlp
, cmdiocb
);
1643 return ndlp
->nlp_state
;
1647 lpfc_rcv_prli_prli_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1648 void *arg
, uint32_t evt
)
1650 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1652 lpfc_els_rsp_prli_acc(vport
, cmdiocb
, ndlp
);
1653 return ndlp
->nlp_state
;
1657 lpfc_rcv_logo_prli_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1658 void *arg
, uint32_t evt
)
1660 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1662 /* Software abort outstanding PRLI before sending acc */
1663 lpfc_els_abort(vport
->phba
, ndlp
);
1665 lpfc_rcv_logo(vport
, ndlp
, cmdiocb
, ELS_CMD_LOGO
);
1666 return ndlp
->nlp_state
;
1670 lpfc_rcv_padisc_prli_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1671 void *arg
, uint32_t evt
)
1673 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1675 lpfc_rcv_padisc(vport
, ndlp
, cmdiocb
);
1676 return ndlp
->nlp_state
;
1679 /* This routine is envoked when we rcv a PRLO request from a nport
1680 * we are logged into. We should send back a PRLO rsp setting the
1682 * NEXT STATE = PRLI_ISSUE
1685 lpfc_rcv_prlo_prli_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1686 void *arg
, uint32_t evt
)
1688 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1690 lpfc_els_rsp_acc(vport
, ELS_CMD_PRLO
, cmdiocb
, ndlp
, NULL
);
1691 return ndlp
->nlp_state
;
1695 lpfc_cmpl_prli_prli_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1696 void *arg
, uint32_t evt
)
1698 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1699 struct lpfc_iocbq
*cmdiocb
, *rspiocb
;
1700 struct lpfc_hba
*phba
= vport
->phba
;
1704 cmdiocb
= (struct lpfc_iocbq
*) arg
;
1705 rspiocb
= cmdiocb
->context_un
.rsp_iocb
;
1706 npr
= (PRLI
*)lpfc_check_elscmpl_iocb(phba
, cmdiocb
, rspiocb
);
1708 irsp
= &rspiocb
->iocb
;
1709 if (irsp
->ulpStatus
) {
1710 if ((vport
->port_type
== LPFC_NPIV_PORT
) &&
1711 vport
->cfg_restrict_login
) {
1714 ndlp
->nlp_prev_state
= NLP_STE_PRLI_ISSUE
;
1715 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
1716 return ndlp
->nlp_state
;
1719 /* Check out PRLI rsp */
1720 ndlp
->nlp_type
&= ~(NLP_FCP_TARGET
| NLP_FCP_INITIATOR
);
1721 ndlp
->nlp_fcp_info
&= ~NLP_FCP_2_DEVICE
;
1722 ndlp
->nlp_flag
&= ~NLP_FIRSTBURST
;
1723 if ((npr
->acceptRspCode
== PRLI_REQ_EXECUTED
) &&
1724 (npr
->prliType
== PRLI_FCP_TYPE
)) {
1725 if (npr
->initiatorFunc
)
1726 ndlp
->nlp_type
|= NLP_FCP_INITIATOR
;
1727 if (npr
->targetFunc
) {
1728 ndlp
->nlp_type
|= NLP_FCP_TARGET
;
1729 if (npr
->writeXferRdyDis
)
1730 ndlp
->nlp_flag
|= NLP_FIRSTBURST
;
1733 ndlp
->nlp_fcp_info
|= NLP_FCP_2_DEVICE
;
1735 if (!(ndlp
->nlp_type
& NLP_FCP_TARGET
) &&
1736 (vport
->port_type
== LPFC_NPIV_PORT
) &&
1737 vport
->cfg_restrict_login
) {
1739 spin_lock_irq(shost
->host_lock
);
1740 ndlp
->nlp_flag
|= NLP_TARGET_REMOVE
;
1741 spin_unlock_irq(shost
->host_lock
);
1742 lpfc_issue_els_logo(vport
, ndlp
, 0);
1744 ndlp
->nlp_prev_state
= NLP_STE_PRLI_ISSUE
;
1745 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1746 return ndlp
->nlp_state
;
1749 ndlp
->nlp_prev_state
= NLP_STE_PRLI_ISSUE
;
1750 if (ndlp
->nlp_type
& NLP_FCP_TARGET
)
1751 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_MAPPED_NODE
);
1753 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
1754 return ndlp
->nlp_state
;
1757 /*! lpfc_device_rm_prli_issue
1768 * This routine is envoked when we a request to remove a nport we are in the
1769 * process of PRLIing. We should software abort outstanding prli, unreg
1770 * login, send a logout. We will change node state to UNUSED_NODE, put it
1771 * on plogi list so it can be freed when LOGO completes.
1776 lpfc_device_rm_prli_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1777 void *arg
, uint32_t evt
)
1779 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1781 if (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) {
1782 spin_lock_irq(shost
->host_lock
);
1783 ndlp
->nlp_flag
|= NLP_NODEV_REMOVE
;
1784 spin_unlock_irq(shost
->host_lock
);
1785 return ndlp
->nlp_state
;
1787 /* software abort outstanding PLOGI */
1788 lpfc_els_abort(vport
->phba
, ndlp
);
1790 lpfc_drop_node(vport
, ndlp
);
1791 return NLP_STE_FREED_NODE
;
1796 /*! lpfc_device_recov_prli_issue
1807 * The routine is envoked when the state of a device is unknown, like
1808 * during a link down. We should remove the nodelist entry from the
1809 * unmapped list, issue a UNREG_LOGIN, do a software abort of the
1810 * outstanding PRLI command, then free the node entry.
1813 lpfc_device_recov_prli_issue(struct lpfc_vport
*vport
,
1814 struct lpfc_nodelist
*ndlp
,
1818 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1819 struct lpfc_hba
*phba
= vport
->phba
;
1821 /* Don't do anything that will mess up processing of the
1824 if (vport
->fc_flag
& FC_RSCN_DEFERRED
)
1825 return ndlp
->nlp_state
;
1827 /* software abort outstanding PRLI */
1828 lpfc_els_abort(phba
, ndlp
);
1830 ndlp
->nlp_prev_state
= NLP_STE_PRLI_ISSUE
;
1831 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1832 spin_lock_irq(shost
->host_lock
);
1833 ndlp
->nlp_flag
&= ~(NLP_NODEV_REMOVE
| NLP_NPR_2B_DISC
);
1834 spin_unlock_irq(shost
->host_lock
);
1835 lpfc_disc_set_adisc(vport
, ndlp
);
1836 return ndlp
->nlp_state
;
1840 lpfc_rcv_plogi_logo_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1841 void *arg
, uint32_t evt
)
1843 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*)arg
;
1846 memset(&stat
, 0, sizeof(struct ls_rjt
));
1847 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
1848 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_NOTHING_MORE
;
1849 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
1850 return ndlp
->nlp_state
;
1854 lpfc_rcv_prli_logo_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1855 void *arg
, uint32_t evt
)
1857 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*)arg
;
1860 memset(&stat
, 0, sizeof(struct ls_rjt
));
1861 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
1862 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_NOTHING_MORE
;
1863 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
1864 return ndlp
->nlp_state
;
1868 lpfc_rcv_logo_logo_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1869 void *arg
, uint32_t evt
)
1871 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1872 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*)arg
;
1874 spin_lock_irq(shost
->host_lock
);
1875 ndlp
->nlp_flag
|= NLP_LOGO_ACC
;
1876 spin_unlock_irq(shost
->host_lock
);
1877 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
1878 return ndlp
->nlp_state
;
1882 lpfc_rcv_padisc_logo_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1883 void *arg
, uint32_t evt
)
1885 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*)arg
;
1888 memset(&stat
, 0, sizeof(struct ls_rjt
));
1889 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
1890 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_NOTHING_MORE
;
1891 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
1892 return ndlp
->nlp_state
;
1896 lpfc_rcv_prlo_logo_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1897 void *arg
, uint32_t evt
)
1899 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*)arg
;
1902 memset(&stat
, 0, sizeof(struct ls_rjt
));
1903 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
1904 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_NOTHING_MORE
;
1905 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
1906 return ndlp
->nlp_state
;
1910 lpfc_cmpl_logo_logo_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1911 void *arg
, uint32_t evt
)
1913 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1915 ndlp
->nlp_prev_state
= NLP_STE_LOGO_ISSUE
;
1916 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1917 spin_lock_irq(shost
->host_lock
);
1918 ndlp
->nlp_flag
&= ~(NLP_NODEV_REMOVE
| NLP_NPR_2B_DISC
);
1919 spin_unlock_irq(shost
->host_lock
);
1920 lpfc_disc_set_adisc(vport
, ndlp
);
1921 return ndlp
->nlp_state
;
1925 lpfc_device_rm_logo_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1926 void *arg
, uint32_t evt
)
1929 * Take no action. If a LOGO is outstanding, then possibly DevLoss has
1930 * timed out and is calling for Device Remove. In this case, the LOGO
1931 * must be allowed to complete in state LOGO_ISSUE so that the rpi
1932 * and other NLP flags are correctly cleaned up.
1934 return ndlp
->nlp_state
;
1938 lpfc_device_recov_logo_issue(struct lpfc_vport
*vport
,
1939 struct lpfc_nodelist
*ndlp
,
1940 void *arg
, uint32_t evt
)
1943 * Device Recovery events have no meaning for a node with a LOGO
1944 * outstanding. The LOGO has to complete first and handle the
1945 * node from that point.
1947 return ndlp
->nlp_state
;
1951 lpfc_rcv_plogi_unmap_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1952 void *arg
, uint32_t evt
)
1954 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1956 lpfc_rcv_plogi(vport
, ndlp
, cmdiocb
);
1957 return ndlp
->nlp_state
;
1961 lpfc_rcv_prli_unmap_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1962 void *arg
, uint32_t evt
)
1964 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1966 lpfc_rcv_prli(vport
, ndlp
, cmdiocb
);
1967 lpfc_els_rsp_prli_acc(vport
, cmdiocb
, ndlp
);
1968 return ndlp
->nlp_state
;
1972 lpfc_rcv_logo_unmap_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1973 void *arg
, uint32_t evt
)
1975 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1977 lpfc_rcv_logo(vport
, ndlp
, cmdiocb
, ELS_CMD_LOGO
);
1978 return ndlp
->nlp_state
;
1982 lpfc_rcv_padisc_unmap_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1983 void *arg
, uint32_t evt
)
1985 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1987 lpfc_rcv_padisc(vport
, ndlp
, cmdiocb
);
1988 return ndlp
->nlp_state
;
1992 lpfc_rcv_prlo_unmap_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1993 void *arg
, uint32_t evt
)
1995 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1997 lpfc_els_rsp_acc(vport
, ELS_CMD_PRLO
, cmdiocb
, ndlp
, NULL
);
1998 return ndlp
->nlp_state
;
2002 lpfc_device_recov_unmap_node(struct lpfc_vport
*vport
,
2003 struct lpfc_nodelist
*ndlp
,
2007 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2009 ndlp
->nlp_prev_state
= NLP_STE_UNMAPPED_NODE
;
2010 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
2011 spin_lock_irq(shost
->host_lock
);
2012 ndlp
->nlp_flag
&= ~(NLP_NODEV_REMOVE
| NLP_NPR_2B_DISC
);
2013 spin_unlock_irq(shost
->host_lock
);
2014 lpfc_disc_set_adisc(vport
, ndlp
);
2016 return ndlp
->nlp_state
;
2020 lpfc_rcv_plogi_mapped_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2021 void *arg
, uint32_t evt
)
2023 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2025 lpfc_rcv_plogi(vport
, ndlp
, cmdiocb
);
2026 return ndlp
->nlp_state
;
2030 lpfc_rcv_prli_mapped_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2031 void *arg
, uint32_t evt
)
2033 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2035 lpfc_els_rsp_prli_acc(vport
, cmdiocb
, ndlp
);
2036 return ndlp
->nlp_state
;
2040 lpfc_rcv_logo_mapped_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2041 void *arg
, uint32_t evt
)
2043 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2045 lpfc_rcv_logo(vport
, ndlp
, cmdiocb
, ELS_CMD_LOGO
);
2046 return ndlp
->nlp_state
;
2050 lpfc_rcv_padisc_mapped_node(struct lpfc_vport
*vport
,
2051 struct lpfc_nodelist
*ndlp
,
2052 void *arg
, uint32_t evt
)
2054 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2056 lpfc_rcv_padisc(vport
, ndlp
, cmdiocb
);
2057 return ndlp
->nlp_state
;
2061 lpfc_rcv_prlo_mapped_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2062 void *arg
, uint32_t evt
)
2064 struct lpfc_hba
*phba
= vport
->phba
;
2065 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2067 /* flush the target */
2068 lpfc_sli_abort_iocb(vport
, &phba
->sli
.ring
[phba
->sli
.fcp_ring
],
2069 ndlp
->nlp_sid
, 0, LPFC_CTX_TGT
);
2071 /* Treat like rcv logo */
2072 lpfc_rcv_logo(vport
, ndlp
, cmdiocb
, ELS_CMD_PRLO
);
2073 return ndlp
->nlp_state
;
2077 lpfc_device_recov_mapped_node(struct lpfc_vport
*vport
,
2078 struct lpfc_nodelist
*ndlp
,
2082 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2084 ndlp
->nlp_prev_state
= NLP_STE_MAPPED_NODE
;
2085 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
2086 spin_lock_irq(shost
->host_lock
);
2087 ndlp
->nlp_flag
&= ~(NLP_NODEV_REMOVE
| NLP_NPR_2B_DISC
);
2088 spin_unlock_irq(shost
->host_lock
);
2089 lpfc_disc_set_adisc(vport
, ndlp
);
2090 return ndlp
->nlp_state
;
2094 lpfc_rcv_plogi_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2095 void *arg
, uint32_t evt
)
2097 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2098 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2100 /* Ignore PLOGI if we have an outstanding LOGO */
2101 if (ndlp
->nlp_flag
& (NLP_LOGO_SND
| NLP_LOGO_ACC
))
2102 return ndlp
->nlp_state
;
2103 if (lpfc_rcv_plogi(vport
, ndlp
, cmdiocb
)) {
2104 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
2105 spin_lock_irq(shost
->host_lock
);
2106 ndlp
->nlp_flag
&= ~(NLP_NPR_ADISC
| NLP_NPR_2B_DISC
);
2107 spin_unlock_irq(shost
->host_lock
);
2108 } else if (!(ndlp
->nlp_flag
& NLP_NPR_2B_DISC
)) {
2109 /* send PLOGI immediately, move to PLOGI issue state */
2110 if (!(ndlp
->nlp_flag
& NLP_DELAY_TMO
)) {
2111 ndlp
->nlp_prev_state
= NLP_STE_NPR_NODE
;
2112 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
2113 lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0);
2116 return ndlp
->nlp_state
;
2120 lpfc_rcv_prli_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2121 void *arg
, uint32_t evt
)
2123 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2124 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2127 memset(&stat
, 0, sizeof (struct ls_rjt
));
2128 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
2129 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_NOTHING_MORE
;
2130 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
2132 if (!(ndlp
->nlp_flag
& NLP_DELAY_TMO
)) {
2133 if (ndlp
->nlp_flag
& NLP_NPR_ADISC
) {
2134 spin_lock_irq(shost
->host_lock
);
2135 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
2136 ndlp
->nlp_prev_state
= NLP_STE_NPR_NODE
;
2137 spin_unlock_irq(shost
->host_lock
);
2138 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_ADISC_ISSUE
);
2139 lpfc_issue_els_adisc(vport
, ndlp
, 0);
2141 ndlp
->nlp_prev_state
= NLP_STE_NPR_NODE
;
2142 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
2143 lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0);
2146 return ndlp
->nlp_state
;
2150 lpfc_rcv_logo_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2151 void *arg
, uint32_t evt
)
2153 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2155 lpfc_rcv_logo(vport
, ndlp
, cmdiocb
, ELS_CMD_LOGO
);
2156 return ndlp
->nlp_state
;
2160 lpfc_rcv_padisc_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2161 void *arg
, uint32_t evt
)
2163 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2165 lpfc_rcv_padisc(vport
, ndlp
, cmdiocb
);
2167 * Do not start discovery if discovery is about to start
2168 * or discovery in progress for this node. Starting discovery
2169 * here will affect the counting of discovery threads.
2171 if (!(ndlp
->nlp_flag
& NLP_DELAY_TMO
) &&
2172 !(ndlp
->nlp_flag
& NLP_NPR_2B_DISC
)) {
2173 if (ndlp
->nlp_flag
& NLP_NPR_ADISC
) {
2174 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
2175 ndlp
->nlp_prev_state
= NLP_STE_NPR_NODE
;
2176 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_ADISC_ISSUE
);
2177 lpfc_issue_els_adisc(vport
, ndlp
, 0);
2179 ndlp
->nlp_prev_state
= NLP_STE_NPR_NODE
;
2180 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
2181 lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0);
2184 return ndlp
->nlp_state
;
2188 lpfc_rcv_prlo_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2189 void *arg
, uint32_t evt
)
2191 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2192 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2194 spin_lock_irq(shost
->host_lock
);
2195 ndlp
->nlp_flag
|= NLP_LOGO_ACC
;
2196 spin_unlock_irq(shost
->host_lock
);
2198 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
2200 if ((ndlp
->nlp_flag
& NLP_DELAY_TMO
) == 0) {
2201 mod_timer(&ndlp
->nlp_delayfunc
,
2202 jiffies
+ msecs_to_jiffies(1000 * 1));
2203 spin_lock_irq(shost
->host_lock
);
2204 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
2205 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
2206 spin_unlock_irq(shost
->host_lock
);
2207 ndlp
->nlp_last_elscmd
= ELS_CMD_PLOGI
;
2209 spin_lock_irq(shost
->host_lock
);
2210 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
2211 spin_unlock_irq(shost
->host_lock
);
2213 return ndlp
->nlp_state
;
2217 lpfc_cmpl_plogi_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2218 void *arg
, uint32_t evt
)
2220 struct lpfc_iocbq
*cmdiocb
, *rspiocb
;
2222 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2224 cmdiocb
= (struct lpfc_iocbq
*) arg
;
2225 rspiocb
= cmdiocb
->context_un
.rsp_iocb
;
2227 irsp
= &rspiocb
->iocb
;
2228 if (irsp
->ulpStatus
) {
2229 spin_lock_irq(shost
->host_lock
);
2230 ndlp
->nlp_flag
|= NLP_DEFER_RM
;
2231 spin_unlock_irq(shost
->host_lock
);
2232 return NLP_STE_FREED_NODE
;
2234 return ndlp
->nlp_state
;
2238 lpfc_cmpl_prli_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2239 void *arg
, uint32_t evt
)
2241 struct lpfc_iocbq
*cmdiocb
, *rspiocb
;
2244 cmdiocb
= (struct lpfc_iocbq
*) arg
;
2245 rspiocb
= cmdiocb
->context_un
.rsp_iocb
;
2247 irsp
= &rspiocb
->iocb
;
2248 if (irsp
->ulpStatus
&& (ndlp
->nlp_flag
& NLP_NODEV_REMOVE
)) {
2249 lpfc_drop_node(vport
, ndlp
);
2250 return NLP_STE_FREED_NODE
;
2252 return ndlp
->nlp_state
;
2256 lpfc_cmpl_logo_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2257 void *arg
, uint32_t evt
)
2259 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2261 /* For the fabric port just clear the fc flags. */
2262 if (ndlp
->nlp_DID
== Fabric_DID
) {
2263 spin_lock_irq(shost
->host_lock
);
2264 vport
->fc_flag
&= ~(FC_FABRIC
| FC_PUBLIC_LOOP
);
2265 spin_unlock_irq(shost
->host_lock
);
2267 lpfc_unreg_rpi(vport
, ndlp
);
2268 return ndlp
->nlp_state
;
2272 lpfc_cmpl_adisc_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2273 void *arg
, uint32_t evt
)
2275 struct lpfc_iocbq
*cmdiocb
, *rspiocb
;
2278 cmdiocb
= (struct lpfc_iocbq
*) arg
;
2279 rspiocb
= cmdiocb
->context_un
.rsp_iocb
;
2281 irsp
= &rspiocb
->iocb
;
2282 if (irsp
->ulpStatus
&& (ndlp
->nlp_flag
& NLP_NODEV_REMOVE
)) {
2283 lpfc_drop_node(vport
, ndlp
);
2284 return NLP_STE_FREED_NODE
;
2286 return ndlp
->nlp_state
;
2290 lpfc_cmpl_reglogin_npr_node(struct lpfc_vport
*vport
,
2291 struct lpfc_nodelist
*ndlp
,
2292 void *arg
, uint32_t evt
)
2294 LPFC_MBOXQ_t
*pmb
= (LPFC_MBOXQ_t
*) arg
;
2295 MAILBOX_t
*mb
= &pmb
->u
.mb
;
2297 if (!mb
->mbxStatus
) {
2298 /* SLI4 ports have preallocated logical rpis. */
2299 if (vport
->phba
->sli_rev
< LPFC_SLI_REV4
)
2300 ndlp
->nlp_rpi
= mb
->un
.varWords
[0];
2301 ndlp
->nlp_flag
|= NLP_RPI_REGISTERED
;
2303 if (ndlp
->nlp_flag
& NLP_NODEV_REMOVE
) {
2304 lpfc_drop_node(vport
, ndlp
);
2305 return NLP_STE_FREED_NODE
;
2308 return ndlp
->nlp_state
;
2312 lpfc_device_rm_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2313 void *arg
, uint32_t evt
)
2315 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2317 if (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) {
2318 spin_lock_irq(shost
->host_lock
);
2319 ndlp
->nlp_flag
|= NLP_NODEV_REMOVE
;
2320 spin_unlock_irq(shost
->host_lock
);
2321 return ndlp
->nlp_state
;
2323 lpfc_drop_node(vport
, ndlp
);
2324 return NLP_STE_FREED_NODE
;
2328 lpfc_device_recov_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2329 void *arg
, uint32_t evt
)
2331 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2333 /* Don't do anything that will mess up processing of the
2336 if (vport
->fc_flag
& FC_RSCN_DEFERRED
)
2337 return ndlp
->nlp_state
;
2339 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
2340 spin_lock_irq(shost
->host_lock
);
2341 ndlp
->nlp_flag
&= ~(NLP_NODEV_REMOVE
| NLP_NPR_2B_DISC
);
2342 spin_unlock_irq(shost
->host_lock
);
2343 return ndlp
->nlp_state
;
2347 /* This next section defines the NPort Discovery State Machine */
2349 /* There are 4 different double linked lists nodelist entries can reside on.
2350 * The plogi list and adisc list are used when Link Up discovery or RSCN
2351 * processing is needed. Each list holds the nodes that we will send PLOGI
2352 * or ADISC on. These lists will keep track of what nodes will be effected
2353 * by an RSCN, or a Link Up (Typically, all nodes are effected on Link Up).
2354 * The unmapped_list will contain all nodes that we have successfully logged
2355 * into at the Fibre Channel level. The mapped_list will contain all nodes
2356 * that are mapped FCP targets.
2359 * The bind list is a list of undiscovered (potentially non-existent) nodes
2360 * that we have saved binding information on. This information is used when
2361 * nodes transition from the unmapped to the mapped list.
2363 /* For UNUSED_NODE state, the node has just been allocated .
2364 * For PLOGI_ISSUE and REG_LOGIN_ISSUE, the node is on
2365 * the PLOGI list. For REG_LOGIN_COMPL, the node is taken off the PLOGI list
2366 * and put on the unmapped list. For ADISC processing, the node is taken off
2367 * the ADISC list and placed on either the mapped or unmapped list (depending
2368 * on its previous state). Once on the unmapped list, a PRLI is issued and the
2369 * state changed to PRLI_ISSUE. When the PRLI completion occurs, the state is
2370 * changed to UNMAPPED_NODE. If the completion indicates a mapped
2371 * node, the node is taken off the unmapped list. The binding list is checked
2372 * for a valid binding, or a binding is automatically assigned. If binding
2373 * assignment is unsuccessful, the node is left on the unmapped list. If
2374 * binding assignment is successful, the associated binding list entry (if
2375 * any) is removed, and the node is placed on the mapped list.
2378 * For a Link Down, all nodes on the ADISC, PLOGI, unmapped or mapped
2379 * lists will receive a DEVICE_RECOVERY event. If the linkdown or devloss timers
2380 * expire, all effected nodes will receive a DEVICE_RM event.
2383 * For a Link Up or RSCN, all nodes will move from the mapped / unmapped lists
2384 * to either the ADISC or PLOGI list. After a Nameserver query or ALPA loopmap
2385 * check, additional nodes may be added or removed (via DEVICE_RM) to / from
2386 * the PLOGI or ADISC lists. Once the PLOGI and ADISC lists are populated,
2387 * we will first process the ADISC list. 32 entries are processed initially and
2388 * ADISC is initited for each one. Completions / Events for each node are
2389 * funnelled thru the state machine. As each node finishes ADISC processing, it
2390 * starts ADISC for any nodes waiting for ADISC processing. If no nodes are
2391 * waiting, and the ADISC list count is identically 0, then we are done. For
2392 * Link Up discovery, since all nodes on the PLOGI list are UNREG_LOGIN'ed, we
2393 * can issue a CLEAR_LA and reenable Link Events. Next we will process the PLOGI
2394 * list. 32 entries are processed initially and PLOGI is initited for each one.
2395 * Completions / Events for each node are funnelled thru the state machine. As
2396 * each node finishes PLOGI processing, it starts PLOGI for any nodes waiting
2397 * for PLOGI processing. If no nodes are waiting, and the PLOGI list count is
2398 * indentically 0, then we are done. We have now completed discovery / RSCN
2399 * handling. Upon completion, ALL nodes should be on either the mapped or
2403 static uint32_t (*lpfc_disc_action
[NLP_STE_MAX_STATE
* NLP_EVT_MAX_EVENT
])
2404 (struct lpfc_vport
*, struct lpfc_nodelist
*, void *, uint32_t) = {
2405 /* Action routine Event Current State */
2406 lpfc_rcv_plogi_unused_node
, /* RCV_PLOGI UNUSED_NODE */
2407 lpfc_rcv_els_unused_node
, /* RCV_PRLI */
2408 lpfc_rcv_logo_unused_node
, /* RCV_LOGO */
2409 lpfc_rcv_els_unused_node
, /* RCV_ADISC */
2410 lpfc_rcv_els_unused_node
, /* RCV_PDISC */
2411 lpfc_rcv_els_unused_node
, /* RCV_PRLO */
2412 lpfc_disc_illegal
, /* CMPL_PLOGI */
2413 lpfc_disc_illegal
, /* CMPL_PRLI */
2414 lpfc_cmpl_logo_unused_node
, /* CMPL_LOGO */
2415 lpfc_disc_illegal
, /* CMPL_ADISC */
2416 lpfc_disc_illegal
, /* CMPL_REG_LOGIN */
2417 lpfc_device_rm_unused_node
, /* DEVICE_RM */
2418 lpfc_device_recov_unused_node
, /* DEVICE_RECOVERY */
2420 lpfc_rcv_plogi_plogi_issue
, /* RCV_PLOGI PLOGI_ISSUE */
2421 lpfc_rcv_prli_plogi_issue
, /* RCV_PRLI */
2422 lpfc_rcv_logo_plogi_issue
, /* RCV_LOGO */
2423 lpfc_rcv_els_plogi_issue
, /* RCV_ADISC */
2424 lpfc_rcv_els_plogi_issue
, /* RCV_PDISC */
2425 lpfc_rcv_els_plogi_issue
, /* RCV_PRLO */
2426 lpfc_cmpl_plogi_plogi_issue
, /* CMPL_PLOGI */
2427 lpfc_disc_illegal
, /* CMPL_PRLI */
2428 lpfc_cmpl_logo_plogi_issue
, /* CMPL_LOGO */
2429 lpfc_disc_illegal
, /* CMPL_ADISC */
2430 lpfc_cmpl_reglogin_plogi_issue
,/* CMPL_REG_LOGIN */
2431 lpfc_device_rm_plogi_issue
, /* DEVICE_RM */
2432 lpfc_device_recov_plogi_issue
, /* DEVICE_RECOVERY */
2434 lpfc_rcv_plogi_adisc_issue
, /* RCV_PLOGI ADISC_ISSUE */
2435 lpfc_rcv_prli_adisc_issue
, /* RCV_PRLI */
2436 lpfc_rcv_logo_adisc_issue
, /* RCV_LOGO */
2437 lpfc_rcv_padisc_adisc_issue
, /* RCV_ADISC */
2438 lpfc_rcv_padisc_adisc_issue
, /* RCV_PDISC */
2439 lpfc_rcv_prlo_adisc_issue
, /* RCV_PRLO */
2440 lpfc_disc_illegal
, /* CMPL_PLOGI */
2441 lpfc_disc_illegal
, /* CMPL_PRLI */
2442 lpfc_disc_illegal
, /* CMPL_LOGO */
2443 lpfc_cmpl_adisc_adisc_issue
, /* CMPL_ADISC */
2444 lpfc_disc_illegal
, /* CMPL_REG_LOGIN */
2445 lpfc_device_rm_adisc_issue
, /* DEVICE_RM */
2446 lpfc_device_recov_adisc_issue
, /* DEVICE_RECOVERY */
2448 lpfc_rcv_plogi_reglogin_issue
, /* RCV_PLOGI REG_LOGIN_ISSUE */
2449 lpfc_rcv_prli_reglogin_issue
, /* RCV_PLOGI */
2450 lpfc_rcv_logo_reglogin_issue
, /* RCV_LOGO */
2451 lpfc_rcv_padisc_reglogin_issue
, /* RCV_ADISC */
2452 lpfc_rcv_padisc_reglogin_issue
, /* RCV_PDISC */
2453 lpfc_rcv_prlo_reglogin_issue
, /* RCV_PRLO */
2454 lpfc_cmpl_plogi_illegal
, /* CMPL_PLOGI */
2455 lpfc_disc_illegal
, /* CMPL_PRLI */
2456 lpfc_disc_illegal
, /* CMPL_LOGO */
2457 lpfc_disc_illegal
, /* CMPL_ADISC */
2458 lpfc_cmpl_reglogin_reglogin_issue
,/* CMPL_REG_LOGIN */
2459 lpfc_device_rm_reglogin_issue
, /* DEVICE_RM */
2460 lpfc_device_recov_reglogin_issue
,/* DEVICE_RECOVERY */
2462 lpfc_rcv_plogi_prli_issue
, /* RCV_PLOGI PRLI_ISSUE */
2463 lpfc_rcv_prli_prli_issue
, /* RCV_PRLI */
2464 lpfc_rcv_logo_prli_issue
, /* RCV_LOGO */
2465 lpfc_rcv_padisc_prli_issue
, /* RCV_ADISC */
2466 lpfc_rcv_padisc_prli_issue
, /* RCV_PDISC */
2467 lpfc_rcv_prlo_prli_issue
, /* RCV_PRLO */
2468 lpfc_cmpl_plogi_illegal
, /* CMPL_PLOGI */
2469 lpfc_cmpl_prli_prli_issue
, /* CMPL_PRLI */
2470 lpfc_disc_illegal
, /* CMPL_LOGO */
2471 lpfc_disc_illegal
, /* CMPL_ADISC */
2472 lpfc_disc_illegal
, /* CMPL_REG_LOGIN */
2473 lpfc_device_rm_prli_issue
, /* DEVICE_RM */
2474 lpfc_device_recov_prli_issue
, /* DEVICE_RECOVERY */
2476 lpfc_rcv_plogi_logo_issue
, /* RCV_PLOGI LOGO_ISSUE */
2477 lpfc_rcv_prli_logo_issue
, /* RCV_PRLI */
2478 lpfc_rcv_logo_logo_issue
, /* RCV_LOGO */
2479 lpfc_rcv_padisc_logo_issue
, /* RCV_ADISC */
2480 lpfc_rcv_padisc_logo_issue
, /* RCV_PDISC */
2481 lpfc_rcv_prlo_logo_issue
, /* RCV_PRLO */
2482 lpfc_cmpl_plogi_illegal
, /* CMPL_PLOGI */
2483 lpfc_disc_illegal
, /* CMPL_PRLI */
2484 lpfc_cmpl_logo_logo_issue
, /* CMPL_LOGO */
2485 lpfc_disc_illegal
, /* CMPL_ADISC */
2486 lpfc_disc_illegal
, /* CMPL_REG_LOGIN */
2487 lpfc_device_rm_logo_issue
, /* DEVICE_RM */
2488 lpfc_device_recov_logo_issue
, /* DEVICE_RECOVERY */
2490 lpfc_rcv_plogi_unmap_node
, /* RCV_PLOGI UNMAPPED_NODE */
2491 lpfc_rcv_prli_unmap_node
, /* RCV_PRLI */
2492 lpfc_rcv_logo_unmap_node
, /* RCV_LOGO */
2493 lpfc_rcv_padisc_unmap_node
, /* RCV_ADISC */
2494 lpfc_rcv_padisc_unmap_node
, /* RCV_PDISC */
2495 lpfc_rcv_prlo_unmap_node
, /* RCV_PRLO */
2496 lpfc_disc_illegal
, /* CMPL_PLOGI */
2497 lpfc_disc_illegal
, /* CMPL_PRLI */
2498 lpfc_disc_illegal
, /* CMPL_LOGO */
2499 lpfc_disc_illegal
, /* CMPL_ADISC */
2500 lpfc_disc_illegal
, /* CMPL_REG_LOGIN */
2501 lpfc_disc_illegal
, /* DEVICE_RM */
2502 lpfc_device_recov_unmap_node
, /* DEVICE_RECOVERY */
2504 lpfc_rcv_plogi_mapped_node
, /* RCV_PLOGI MAPPED_NODE */
2505 lpfc_rcv_prli_mapped_node
, /* RCV_PRLI */
2506 lpfc_rcv_logo_mapped_node
, /* RCV_LOGO */
2507 lpfc_rcv_padisc_mapped_node
, /* RCV_ADISC */
2508 lpfc_rcv_padisc_mapped_node
, /* RCV_PDISC */
2509 lpfc_rcv_prlo_mapped_node
, /* RCV_PRLO */
2510 lpfc_disc_illegal
, /* CMPL_PLOGI */
2511 lpfc_disc_illegal
, /* CMPL_PRLI */
2512 lpfc_disc_illegal
, /* CMPL_LOGO */
2513 lpfc_disc_illegal
, /* CMPL_ADISC */
2514 lpfc_disc_illegal
, /* CMPL_REG_LOGIN */
2515 lpfc_disc_illegal
, /* DEVICE_RM */
2516 lpfc_device_recov_mapped_node
, /* DEVICE_RECOVERY */
2518 lpfc_rcv_plogi_npr_node
, /* RCV_PLOGI NPR_NODE */
2519 lpfc_rcv_prli_npr_node
, /* RCV_PRLI */
2520 lpfc_rcv_logo_npr_node
, /* RCV_LOGO */
2521 lpfc_rcv_padisc_npr_node
, /* RCV_ADISC */
2522 lpfc_rcv_padisc_npr_node
, /* RCV_PDISC */
2523 lpfc_rcv_prlo_npr_node
, /* RCV_PRLO */
2524 lpfc_cmpl_plogi_npr_node
, /* CMPL_PLOGI */
2525 lpfc_cmpl_prli_npr_node
, /* CMPL_PRLI */
2526 lpfc_cmpl_logo_npr_node
, /* CMPL_LOGO */
2527 lpfc_cmpl_adisc_npr_node
, /* CMPL_ADISC */
2528 lpfc_cmpl_reglogin_npr_node
, /* CMPL_REG_LOGIN */
2529 lpfc_device_rm_npr_node
, /* DEVICE_RM */
2530 lpfc_device_recov_npr_node
, /* DEVICE_RECOVERY */
2534 lpfc_disc_state_machine(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2535 void *arg
, uint32_t evt
)
2537 uint32_t cur_state
, rc
;
2538 uint32_t(*func
) (struct lpfc_vport
*, struct lpfc_nodelist
*, void *,
2540 uint32_t got_ndlp
= 0;
2542 if (lpfc_nlp_get(ndlp
))
2545 cur_state
= ndlp
->nlp_state
;
2547 /* DSM in event <evt> on NPort <nlp_DID> in state <cur_state> */
2548 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
2549 "0211 DSM in event x%x on NPort x%x in "
2550 "state %d Data: x%x\n",
2551 evt
, ndlp
->nlp_DID
, cur_state
, ndlp
->nlp_flag
);
2553 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_DSM
,
2554 "DSM in: evt:%d ste:%d did:x%x",
2555 evt
, cur_state
, ndlp
->nlp_DID
);
2557 func
= lpfc_disc_action
[(cur_state
* NLP_EVT_MAX_EVENT
) + evt
];
2558 rc
= (func
) (vport
, ndlp
, arg
, evt
);
2560 /* DSM out state <rc> on NPort <nlp_DID> */
2562 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
2563 "0212 DSM out state %d on NPort x%x Data: x%x\n",
2564 rc
, ndlp
->nlp_DID
, ndlp
->nlp_flag
);
2566 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_DSM
,
2567 "DSM out: ste:%d did:x%x flg:x%x",
2568 rc
, ndlp
->nlp_DID
, ndlp
->nlp_flag
);
2569 /* Decrement the ndlp reference count held for this function */
2572 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
2573 "0213 DSM out state %d on NPort free\n", rc
);
2575 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_DSM
,
2576 "DSM out: ste:%d did:x%x flg:x%x",