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
;
827 /* Release the RPI if reglogin completing */
828 if (!(phba
->pport
->load_flag
& FC_UNLOADING
) &&
829 (evt
== NLP_EVT_CMPL_REG_LOGIN
) &&
830 (!pmb
->u
.mb
.mbxStatus
)) {
832 rpi
= pmb
->u
.mb
.un
.varWords
[0];
833 lpfc_release_rpi(phba
, vport
, rpi
);
835 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
836 "0271 Illegal State Transition: node x%x "
837 "event x%x, state x%x Data: x%x x%x\n",
838 ndlp
->nlp_DID
, evt
, ndlp
->nlp_state
, ndlp
->nlp_rpi
,
840 return ndlp
->nlp_state
;
844 lpfc_cmpl_plogi_illegal(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
845 void *arg
, uint32_t evt
)
847 /* This transition is only legal if we previously
848 * rcv'ed a PLOGI. Since we don't want 2 discovery threads
849 * working on the same NPortID, do nothing for this thread
852 if (!(ndlp
->nlp_flag
& NLP_RCV_PLOGI
)) {
853 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
854 "0272 Illegal State Transition: node x%x "
855 "event x%x, state x%x Data: x%x x%x\n",
856 ndlp
->nlp_DID
, evt
, ndlp
->nlp_state
, ndlp
->nlp_rpi
,
859 return ndlp
->nlp_state
;
862 /* Start of Discovery State Machine routines */
865 lpfc_rcv_plogi_unused_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
866 void *arg
, uint32_t evt
)
868 struct lpfc_iocbq
*cmdiocb
;
870 cmdiocb
= (struct lpfc_iocbq
*) arg
;
872 if (lpfc_rcv_plogi(vport
, ndlp
, cmdiocb
)) {
873 return ndlp
->nlp_state
;
875 return NLP_STE_FREED_NODE
;
879 lpfc_rcv_els_unused_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
880 void *arg
, uint32_t evt
)
882 lpfc_issue_els_logo(vport
, ndlp
, 0);
883 return ndlp
->nlp_state
;
887 lpfc_rcv_logo_unused_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
888 void *arg
, uint32_t evt
)
890 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
891 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
893 spin_lock_irq(shost
->host_lock
);
894 ndlp
->nlp_flag
|= NLP_LOGO_ACC
;
895 spin_unlock_irq(shost
->host_lock
);
896 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
898 return ndlp
->nlp_state
;
902 lpfc_cmpl_logo_unused_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
903 void *arg
, uint32_t evt
)
905 return NLP_STE_FREED_NODE
;
909 lpfc_device_rm_unused_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
910 void *arg
, uint32_t evt
)
912 return NLP_STE_FREED_NODE
;
916 lpfc_device_recov_unused_node(struct lpfc_vport
*vport
,
917 struct lpfc_nodelist
*ndlp
,
918 void *arg
, uint32_t evt
)
920 return ndlp
->nlp_state
;
924 lpfc_rcv_plogi_plogi_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
925 void *arg
, uint32_t evt
)
927 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
928 struct lpfc_hba
*phba
= vport
->phba
;
929 struct lpfc_iocbq
*cmdiocb
= arg
;
930 struct lpfc_dmabuf
*pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
931 uint32_t *lp
= (uint32_t *) pcmd
->virt
;
932 struct serv_parm
*sp
= (struct serv_parm
*) (lp
+ 1);
936 memset(&stat
, 0, sizeof (struct ls_rjt
));
938 /* For a PLOGI, we only accept if our portname is less
939 * than the remote portname.
941 phba
->fc_stat
.elsLogiCol
++;
942 port_cmp
= memcmp(&vport
->fc_portname
, &sp
->portName
,
943 sizeof(struct lpfc_name
));
946 /* Reject this request because the remote node will accept
948 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
949 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CMD_IN_PROGRESS
;
950 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
,
953 if (lpfc_rcv_plogi(vport
, ndlp
, cmdiocb
) &&
954 (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) &&
955 (vport
->num_disc_nodes
)) {
956 spin_lock_irq(shost
->host_lock
);
957 ndlp
->nlp_flag
&= ~NLP_NPR_2B_DISC
;
958 spin_unlock_irq(shost
->host_lock
);
959 /* Check if there are more PLOGIs to be sent */
960 lpfc_more_plogi(vport
);
961 if (vport
->num_disc_nodes
== 0) {
962 spin_lock_irq(shost
->host_lock
);
963 vport
->fc_flag
&= ~FC_NDISC_ACTIVE
;
964 spin_unlock_irq(shost
->host_lock
);
965 lpfc_can_disctmo(vport
);
966 lpfc_end_rscn(vport
);
969 } /* If our portname was less */
971 return ndlp
->nlp_state
;
975 lpfc_rcv_prli_plogi_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
976 void *arg
, uint32_t evt
)
978 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
981 memset(&stat
, 0, sizeof (struct ls_rjt
));
982 stat
.un
.b
.lsRjtRsnCode
= LSRJT_LOGICAL_BSY
;
983 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_NOTHING_MORE
;
984 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
985 return ndlp
->nlp_state
;
989 lpfc_rcv_logo_plogi_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
990 void *arg
, uint32_t evt
)
992 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
994 /* software abort outstanding PLOGI */
995 lpfc_els_abort(vport
->phba
, ndlp
);
997 lpfc_rcv_logo(vport
, ndlp
, cmdiocb
, ELS_CMD_LOGO
);
998 return ndlp
->nlp_state
;
1002 lpfc_rcv_els_plogi_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1003 void *arg
, uint32_t evt
)
1005 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1006 struct lpfc_hba
*phba
= vport
->phba
;
1007 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1009 /* software abort outstanding PLOGI */
1010 lpfc_els_abort(phba
, ndlp
);
1012 if (evt
== NLP_EVT_RCV_LOGO
) {
1013 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
1015 lpfc_issue_els_logo(vport
, ndlp
, 0);
1018 /* Put ndlp in npr state set plogi timer for 1 sec */
1019 mod_timer(&ndlp
->nlp_delayfunc
, jiffies
+ msecs_to_jiffies(1000 * 1));
1020 spin_lock_irq(shost
->host_lock
);
1021 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
1022 spin_unlock_irq(shost
->host_lock
);
1023 ndlp
->nlp_last_elscmd
= ELS_CMD_PLOGI
;
1024 ndlp
->nlp_prev_state
= NLP_STE_PLOGI_ISSUE
;
1025 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1027 return ndlp
->nlp_state
;
1031 lpfc_cmpl_plogi_plogi_issue(struct lpfc_vport
*vport
,
1032 struct lpfc_nodelist
*ndlp
,
1036 struct lpfc_hba
*phba
= vport
->phba
;
1037 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1038 struct lpfc_iocbq
*cmdiocb
, *rspiocb
;
1039 struct lpfc_dmabuf
*pcmd
, *prsp
, *mp
;
1042 struct serv_parm
*sp
;
1045 cmdiocb
= (struct lpfc_iocbq
*) arg
;
1046 rspiocb
= cmdiocb
->context_un
.rsp_iocb
;
1048 if (ndlp
->nlp_flag
& NLP_ACC_REGLOGIN
) {
1049 /* Recovery from PLOGI collision logic */
1050 return ndlp
->nlp_state
;
1053 irsp
= &rspiocb
->iocb
;
1055 if (irsp
->ulpStatus
)
1058 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
1060 prsp
= list_get_first(&pcmd
->list
, struct lpfc_dmabuf
, list
);
1064 lp
= (uint32_t *) prsp
->virt
;
1065 sp
= (struct serv_parm
*) ((uint8_t *) lp
+ sizeof (uint32_t));
1067 /* Some switches have FDMI servers returning 0 for WWN */
1068 if ((ndlp
->nlp_DID
!= FDMI_DID
) &&
1069 (wwn_to_u64(sp
->portName
.u
.wwn
) == 0 ||
1070 wwn_to_u64(sp
->nodeName
.u
.wwn
) == 0)) {
1071 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1072 "0142 PLOGI RSP: Invalid WWN.\n");
1075 if (!lpfc_check_sparm(vport
, ndlp
, sp
, CLASS3
, 0))
1077 /* PLOGI chkparm OK */
1078 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
1079 "0121 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
1080 ndlp
->nlp_DID
, ndlp
->nlp_state
,
1081 ndlp
->nlp_flag
, ndlp
->nlp_rpi
);
1082 if (vport
->cfg_fcp_class
== 2 && (sp
->cls2
.classValid
))
1083 ndlp
->nlp_fcp_info
|= CLASS2
;
1085 ndlp
->nlp_fcp_info
|= CLASS3
;
1087 ndlp
->nlp_class_sup
= 0;
1088 if (sp
->cls1
.classValid
)
1089 ndlp
->nlp_class_sup
|= FC_COS_CLASS1
;
1090 if (sp
->cls2
.classValid
)
1091 ndlp
->nlp_class_sup
|= FC_COS_CLASS2
;
1092 if (sp
->cls3
.classValid
)
1093 ndlp
->nlp_class_sup
|= FC_COS_CLASS3
;
1094 if (sp
->cls4
.classValid
)
1095 ndlp
->nlp_class_sup
|= FC_COS_CLASS4
;
1096 ndlp
->nlp_maxframe
=
1097 ((sp
->cmn
.bbRcvSizeMsb
& 0x0F) << 8) | sp
->cmn
.bbRcvSizeLsb
;
1099 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1101 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1102 "0133 PLOGI: no memory for reg_login "
1103 "Data: x%x x%x x%x x%x\n",
1104 ndlp
->nlp_DID
, ndlp
->nlp_state
,
1105 ndlp
->nlp_flag
, ndlp
->nlp_rpi
);
1109 lpfc_unreg_rpi(vport
, ndlp
);
1111 if (lpfc_reg_rpi(phba
, vport
->vpi
, irsp
->un
.elsreq64
.remoteID
,
1112 (uint8_t *) sp
, mbox
, ndlp
->nlp_rpi
) == 0) {
1113 switch (ndlp
->nlp_DID
) {
1114 case NameServer_DID
:
1115 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_ns_reg_login
;
1118 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_fdmi_reg_login
;
1121 ndlp
->nlp_flag
|= NLP_REG_LOGIN_SEND
;
1122 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_reg_login
;
1124 mbox
->context2
= lpfc_nlp_get(ndlp
);
1125 mbox
->vport
= vport
;
1126 if (lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
)
1127 != MBX_NOT_FINISHED
) {
1128 lpfc_nlp_set_state(vport
, ndlp
,
1129 NLP_STE_REG_LOGIN_ISSUE
);
1130 return ndlp
->nlp_state
;
1132 if (ndlp
->nlp_flag
& NLP_REG_LOGIN_SEND
)
1133 ndlp
->nlp_flag
&= ~NLP_REG_LOGIN_SEND
;
1134 /* decrement node reference count to the failed mbox
1138 mp
= (struct lpfc_dmabuf
*) mbox
->context1
;
1139 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
1141 mempool_free(mbox
, phba
->mbox_mem_pool
);
1143 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1144 "0134 PLOGI: cannot issue reg_login "
1145 "Data: x%x x%x x%x x%x\n",
1146 ndlp
->nlp_DID
, ndlp
->nlp_state
,
1147 ndlp
->nlp_flag
, ndlp
->nlp_rpi
);
1149 mempool_free(mbox
, phba
->mbox_mem_pool
);
1151 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1152 "0135 PLOGI: cannot format reg_login "
1153 "Data: x%x x%x x%x x%x\n",
1154 ndlp
->nlp_DID
, ndlp
->nlp_state
,
1155 ndlp
->nlp_flag
, ndlp
->nlp_rpi
);
1160 if (ndlp
->nlp_DID
== NameServer_DID
) {
1161 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
1162 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1163 "0261 Cannot Register NameServer login\n");
1167 ** In case the node reference counter does not go to zero, ensure that
1168 ** the stale state for the node is not processed.
1171 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
1172 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1173 spin_lock_irq(shost
->host_lock
);
1174 ndlp
->nlp_flag
|= NLP_DEFER_RM
;
1175 spin_unlock_irq(shost
->host_lock
);
1176 return NLP_STE_FREED_NODE
;
1180 lpfc_cmpl_logo_plogi_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1181 void *arg
, uint32_t evt
)
1183 return ndlp
->nlp_state
;
1187 lpfc_cmpl_reglogin_plogi_issue(struct lpfc_vport
*vport
,
1188 struct lpfc_nodelist
*ndlp
, void *arg
, uint32_t evt
)
1190 struct lpfc_hba
*phba
;
1191 LPFC_MBOXQ_t
*pmb
= (LPFC_MBOXQ_t
*) arg
;
1192 MAILBOX_t
*mb
= &pmb
->u
.mb
;
1196 /* Release the RPI */
1197 if (!(phba
->pport
->load_flag
& FC_UNLOADING
) &&
1199 rpi
= pmb
->u
.mb
.un
.varWords
[0];
1200 lpfc_release_rpi(phba
, vport
, rpi
);
1202 return ndlp
->nlp_state
;
1206 lpfc_device_rm_plogi_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1207 void *arg
, uint32_t evt
)
1209 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1211 if (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) {
1212 spin_lock_irq(shost
->host_lock
);
1213 ndlp
->nlp_flag
|= NLP_NODEV_REMOVE
;
1214 spin_unlock_irq(shost
->host_lock
);
1215 return ndlp
->nlp_state
;
1217 /* software abort outstanding PLOGI */
1218 lpfc_els_abort(vport
->phba
, ndlp
);
1220 lpfc_drop_node(vport
, ndlp
);
1221 return NLP_STE_FREED_NODE
;
1226 lpfc_device_recov_plogi_issue(struct lpfc_vport
*vport
,
1227 struct lpfc_nodelist
*ndlp
,
1231 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1232 struct lpfc_hba
*phba
= vport
->phba
;
1234 /* Don't do anything that will mess up processing of the
1237 if (vport
->fc_flag
& FC_RSCN_DEFERRED
)
1238 return ndlp
->nlp_state
;
1240 /* software abort outstanding PLOGI */
1241 lpfc_els_abort(phba
, ndlp
);
1243 ndlp
->nlp_prev_state
= NLP_STE_PLOGI_ISSUE
;
1244 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1245 spin_lock_irq(shost
->host_lock
);
1246 ndlp
->nlp_flag
&= ~(NLP_NODEV_REMOVE
| NLP_NPR_2B_DISC
);
1247 spin_unlock_irq(shost
->host_lock
);
1249 return ndlp
->nlp_state
;
1253 lpfc_rcv_plogi_adisc_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1254 void *arg
, uint32_t evt
)
1256 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1257 struct lpfc_hba
*phba
= vport
->phba
;
1258 struct lpfc_iocbq
*cmdiocb
;
1260 /* software abort outstanding ADISC */
1261 lpfc_els_abort(phba
, ndlp
);
1263 cmdiocb
= (struct lpfc_iocbq
*) arg
;
1265 if (lpfc_rcv_plogi(vport
, ndlp
, cmdiocb
)) {
1266 if (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) {
1267 spin_lock_irq(shost
->host_lock
);
1268 ndlp
->nlp_flag
&= ~NLP_NPR_2B_DISC
;
1269 spin_unlock_irq(shost
->host_lock
);
1270 if (vport
->num_disc_nodes
)
1271 lpfc_more_adisc(vport
);
1273 return ndlp
->nlp_state
;
1275 ndlp
->nlp_prev_state
= NLP_STE_ADISC_ISSUE
;
1276 lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0);
1277 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
1279 return ndlp
->nlp_state
;
1283 lpfc_rcv_prli_adisc_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1284 void *arg
, uint32_t evt
)
1286 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1288 lpfc_els_rsp_prli_acc(vport
, cmdiocb
, ndlp
);
1289 return ndlp
->nlp_state
;
1293 lpfc_rcv_logo_adisc_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1294 void *arg
, uint32_t evt
)
1296 struct lpfc_hba
*phba
= vport
->phba
;
1297 struct lpfc_iocbq
*cmdiocb
;
1299 cmdiocb
= (struct lpfc_iocbq
*) arg
;
1301 /* software abort outstanding ADISC */
1302 lpfc_els_abort(phba
, ndlp
);
1304 lpfc_rcv_logo(vport
, ndlp
, cmdiocb
, ELS_CMD_LOGO
);
1305 return ndlp
->nlp_state
;
1309 lpfc_rcv_padisc_adisc_issue(struct lpfc_vport
*vport
,
1310 struct lpfc_nodelist
*ndlp
,
1311 void *arg
, uint32_t evt
)
1313 struct lpfc_iocbq
*cmdiocb
;
1315 cmdiocb
= (struct lpfc_iocbq
*) arg
;
1317 lpfc_rcv_padisc(vport
, ndlp
, cmdiocb
);
1318 return ndlp
->nlp_state
;
1322 lpfc_rcv_prlo_adisc_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1323 void *arg
, uint32_t evt
)
1325 struct lpfc_iocbq
*cmdiocb
;
1327 cmdiocb
= (struct lpfc_iocbq
*) arg
;
1329 /* Treat like rcv logo */
1330 lpfc_rcv_logo(vport
, ndlp
, cmdiocb
, ELS_CMD_PRLO
);
1331 return ndlp
->nlp_state
;
1335 lpfc_cmpl_adisc_adisc_issue(struct lpfc_vport
*vport
,
1336 struct lpfc_nodelist
*ndlp
,
1337 void *arg
, uint32_t evt
)
1339 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1340 struct lpfc_hba
*phba
= vport
->phba
;
1341 struct lpfc_iocbq
*cmdiocb
, *rspiocb
;
1346 cmdiocb
= (struct lpfc_iocbq
*) arg
;
1347 rspiocb
= cmdiocb
->context_un
.rsp_iocb
;
1349 ap
= (ADISC
*)lpfc_check_elscmpl_iocb(phba
, cmdiocb
, rspiocb
);
1350 irsp
= &rspiocb
->iocb
;
1352 if ((irsp
->ulpStatus
) ||
1353 (!lpfc_check_adisc(vport
, ndlp
, &ap
->nodeName
, &ap
->portName
))) {
1355 mod_timer(&ndlp
->nlp_delayfunc
,
1356 jiffies
+ msecs_to_jiffies(1000));
1357 spin_lock_irq(shost
->host_lock
);
1358 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
1359 spin_unlock_irq(shost
->host_lock
);
1360 ndlp
->nlp_last_elscmd
= ELS_CMD_PLOGI
;
1362 memset(&ndlp
->nlp_nodename
, 0, sizeof(struct lpfc_name
));
1363 memset(&ndlp
->nlp_portname
, 0, sizeof(struct lpfc_name
));
1365 ndlp
->nlp_prev_state
= NLP_STE_ADISC_ISSUE
;
1366 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1367 lpfc_unreg_rpi(vport
, ndlp
);
1368 return ndlp
->nlp_state
;
1371 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
1372 rc
= lpfc_sli4_resume_rpi(ndlp
, NULL
, NULL
);
1374 /* Stay in state and retry. */
1375 ndlp
->nlp_prev_state
= NLP_STE_ADISC_ISSUE
;
1376 return ndlp
->nlp_state
;
1380 if (ndlp
->nlp_type
& NLP_FCP_TARGET
) {
1381 ndlp
->nlp_prev_state
= NLP_STE_ADISC_ISSUE
;
1382 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_MAPPED_NODE
);
1384 ndlp
->nlp_prev_state
= NLP_STE_ADISC_ISSUE
;
1385 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
1388 return ndlp
->nlp_state
;
1392 lpfc_device_rm_adisc_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1393 void *arg
, uint32_t evt
)
1395 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1397 if (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) {
1398 spin_lock_irq(shost
->host_lock
);
1399 ndlp
->nlp_flag
|= NLP_NODEV_REMOVE
;
1400 spin_unlock_irq(shost
->host_lock
);
1401 return ndlp
->nlp_state
;
1403 /* software abort outstanding ADISC */
1404 lpfc_els_abort(vport
->phba
, ndlp
);
1406 lpfc_drop_node(vport
, ndlp
);
1407 return NLP_STE_FREED_NODE
;
1412 lpfc_device_recov_adisc_issue(struct lpfc_vport
*vport
,
1413 struct lpfc_nodelist
*ndlp
,
1417 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1418 struct lpfc_hba
*phba
= vport
->phba
;
1420 /* Don't do anything that will mess up processing of the
1423 if (vport
->fc_flag
& FC_RSCN_DEFERRED
)
1424 return ndlp
->nlp_state
;
1426 /* software abort outstanding ADISC */
1427 lpfc_els_abort(phba
, ndlp
);
1429 ndlp
->nlp_prev_state
= NLP_STE_ADISC_ISSUE
;
1430 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1431 spin_lock_irq(shost
->host_lock
);
1432 ndlp
->nlp_flag
&= ~(NLP_NODEV_REMOVE
| NLP_NPR_2B_DISC
);
1433 spin_unlock_irq(shost
->host_lock
);
1434 lpfc_disc_set_adisc(vport
, ndlp
);
1435 return ndlp
->nlp_state
;
1439 lpfc_rcv_plogi_reglogin_issue(struct lpfc_vport
*vport
,
1440 struct lpfc_nodelist
*ndlp
,
1444 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1446 lpfc_rcv_plogi(vport
, ndlp
, cmdiocb
);
1447 return ndlp
->nlp_state
;
1451 lpfc_rcv_prli_reglogin_issue(struct lpfc_vport
*vport
,
1452 struct lpfc_nodelist
*ndlp
,
1456 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1458 lpfc_els_rsp_prli_acc(vport
, cmdiocb
, ndlp
);
1459 return ndlp
->nlp_state
;
1463 lpfc_rcv_logo_reglogin_issue(struct lpfc_vport
*vport
,
1464 struct lpfc_nodelist
*ndlp
,
1468 struct lpfc_hba
*phba
= vport
->phba
;
1469 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1471 LPFC_MBOXQ_t
*nextmb
;
1472 struct lpfc_dmabuf
*mp
;
1474 cmdiocb
= (struct lpfc_iocbq
*) arg
;
1476 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
1477 if ((mb
= phba
->sli
.mbox_active
)) {
1478 if ((mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) &&
1479 (ndlp
== (struct lpfc_nodelist
*) mb
->context2
)) {
1481 mb
->context2
= NULL
;
1482 mb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
1486 spin_lock_irq(&phba
->hbalock
);
1487 list_for_each_entry_safe(mb
, nextmb
, &phba
->sli
.mboxq
, list
) {
1488 if ((mb
->u
.mb
.mbxCommand
== MBX_REG_LOGIN64
) &&
1489 (ndlp
== (struct lpfc_nodelist
*) mb
->context2
)) {
1490 mp
= (struct lpfc_dmabuf
*) (mb
->context1
);
1492 __lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
1496 list_del(&mb
->list
);
1497 phba
->sli
.mboxq_cnt
--;
1498 mempool_free(mb
, phba
->mbox_mem_pool
);
1501 spin_unlock_irq(&phba
->hbalock
);
1503 lpfc_rcv_logo(vport
, ndlp
, cmdiocb
, ELS_CMD_LOGO
);
1504 return ndlp
->nlp_state
;
1508 lpfc_rcv_padisc_reglogin_issue(struct lpfc_vport
*vport
,
1509 struct lpfc_nodelist
*ndlp
,
1513 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1515 lpfc_rcv_padisc(vport
, ndlp
, cmdiocb
);
1516 return ndlp
->nlp_state
;
1520 lpfc_rcv_prlo_reglogin_issue(struct lpfc_vport
*vport
,
1521 struct lpfc_nodelist
*ndlp
,
1525 struct lpfc_iocbq
*cmdiocb
;
1527 cmdiocb
= (struct lpfc_iocbq
*) arg
;
1528 lpfc_els_rsp_acc(vport
, ELS_CMD_PRLO
, cmdiocb
, ndlp
, NULL
);
1529 return ndlp
->nlp_state
;
1533 lpfc_cmpl_reglogin_reglogin_issue(struct lpfc_vport
*vport
,
1534 struct lpfc_nodelist
*ndlp
,
1538 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1539 LPFC_MBOXQ_t
*pmb
= (LPFC_MBOXQ_t
*) arg
;
1540 MAILBOX_t
*mb
= &pmb
->u
.mb
;
1541 uint32_t did
= mb
->un
.varWords
[1];
1543 if (mb
->mbxStatus
) {
1544 /* RegLogin failed */
1545 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
1546 "0246 RegLogin failed Data: x%x x%x x%x x%x "
1548 did
, mb
->mbxStatus
, vport
->port_state
,
1549 mb
->un
.varRegLogin
.vpi
,
1550 mb
->un
.varRegLogin
.rpi
);
1552 * If RegLogin failed due to lack of HBA resources do not
1555 if (mb
->mbxStatus
== MBXERR_RPI_FULL
) {
1556 ndlp
->nlp_prev_state
= NLP_STE_REG_LOGIN_ISSUE
;
1557 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1558 return ndlp
->nlp_state
;
1561 /* Put ndlp in npr state set plogi timer for 1 sec */
1562 mod_timer(&ndlp
->nlp_delayfunc
,
1563 jiffies
+ msecs_to_jiffies(1000 * 1));
1564 spin_lock_irq(shost
->host_lock
);
1565 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
1566 spin_unlock_irq(shost
->host_lock
);
1567 ndlp
->nlp_last_elscmd
= ELS_CMD_PLOGI
;
1569 lpfc_issue_els_logo(vport
, ndlp
, 0);
1570 ndlp
->nlp_prev_state
= NLP_STE_REG_LOGIN_ISSUE
;
1571 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1572 return ndlp
->nlp_state
;
1575 /* SLI4 ports have preallocated logical rpis. */
1576 if (vport
->phba
->sli_rev
< LPFC_SLI_REV4
)
1577 ndlp
->nlp_rpi
= mb
->un
.varWords
[0];
1579 ndlp
->nlp_flag
|= NLP_RPI_REGISTERED
;
1581 /* Only if we are not a fabric nport do we issue PRLI */
1582 if (!(ndlp
->nlp_type
& NLP_FABRIC
)) {
1583 ndlp
->nlp_prev_state
= NLP_STE_REG_LOGIN_ISSUE
;
1584 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PRLI_ISSUE
);
1585 lpfc_issue_els_prli(vport
, ndlp
, 0);
1587 ndlp
->nlp_prev_state
= NLP_STE_REG_LOGIN_ISSUE
;
1588 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
1590 return ndlp
->nlp_state
;
1594 lpfc_device_rm_reglogin_issue(struct lpfc_vport
*vport
,
1595 struct lpfc_nodelist
*ndlp
,
1599 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1601 if (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) {
1602 spin_lock_irq(shost
->host_lock
);
1603 ndlp
->nlp_flag
|= NLP_NODEV_REMOVE
;
1604 spin_unlock_irq(shost
->host_lock
);
1605 return ndlp
->nlp_state
;
1607 lpfc_drop_node(vport
, ndlp
);
1608 return NLP_STE_FREED_NODE
;
1613 lpfc_device_recov_reglogin_issue(struct lpfc_vport
*vport
,
1614 struct lpfc_nodelist
*ndlp
,
1618 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1620 /* Don't do anything that will mess up processing of the
1623 if (vport
->fc_flag
& FC_RSCN_DEFERRED
)
1624 return ndlp
->nlp_state
;
1626 ndlp
->nlp_prev_state
= NLP_STE_REG_LOGIN_ISSUE
;
1627 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1628 spin_lock_irq(shost
->host_lock
);
1629 ndlp
->nlp_flag
|= NLP_IGNR_REG_CMPL
;
1630 ndlp
->nlp_flag
&= ~(NLP_NODEV_REMOVE
| NLP_NPR_2B_DISC
);
1631 spin_unlock_irq(shost
->host_lock
);
1632 lpfc_disc_set_adisc(vport
, ndlp
);
1633 return ndlp
->nlp_state
;
1637 lpfc_rcv_plogi_prli_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1638 void *arg
, uint32_t evt
)
1640 struct lpfc_iocbq
*cmdiocb
;
1642 cmdiocb
= (struct lpfc_iocbq
*) arg
;
1644 lpfc_rcv_plogi(vport
, ndlp
, cmdiocb
);
1645 return ndlp
->nlp_state
;
1649 lpfc_rcv_prli_prli_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1650 void *arg
, uint32_t evt
)
1652 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1654 lpfc_els_rsp_prli_acc(vport
, cmdiocb
, ndlp
);
1655 return ndlp
->nlp_state
;
1659 lpfc_rcv_logo_prli_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1660 void *arg
, uint32_t evt
)
1662 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1664 /* Software abort outstanding PRLI before sending acc */
1665 lpfc_els_abort(vport
->phba
, ndlp
);
1667 lpfc_rcv_logo(vport
, ndlp
, cmdiocb
, ELS_CMD_LOGO
);
1668 return ndlp
->nlp_state
;
1672 lpfc_rcv_padisc_prli_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1673 void *arg
, uint32_t evt
)
1675 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1677 lpfc_rcv_padisc(vport
, ndlp
, cmdiocb
);
1678 return ndlp
->nlp_state
;
1681 /* This routine is envoked when we rcv a PRLO request from a nport
1682 * we are logged into. We should send back a PRLO rsp setting the
1684 * NEXT STATE = PRLI_ISSUE
1687 lpfc_rcv_prlo_prli_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1688 void *arg
, uint32_t evt
)
1690 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1692 lpfc_els_rsp_acc(vport
, ELS_CMD_PRLO
, cmdiocb
, ndlp
, NULL
);
1693 return ndlp
->nlp_state
;
1697 lpfc_cmpl_prli_prli_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1698 void *arg
, uint32_t evt
)
1700 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1701 struct lpfc_iocbq
*cmdiocb
, *rspiocb
;
1702 struct lpfc_hba
*phba
= vport
->phba
;
1706 cmdiocb
= (struct lpfc_iocbq
*) arg
;
1707 rspiocb
= cmdiocb
->context_un
.rsp_iocb
;
1708 npr
= (PRLI
*)lpfc_check_elscmpl_iocb(phba
, cmdiocb
, rspiocb
);
1710 irsp
= &rspiocb
->iocb
;
1711 if (irsp
->ulpStatus
) {
1712 if ((vport
->port_type
== LPFC_NPIV_PORT
) &&
1713 vport
->cfg_restrict_login
) {
1716 ndlp
->nlp_prev_state
= NLP_STE_PRLI_ISSUE
;
1717 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
1718 return ndlp
->nlp_state
;
1721 /* Check out PRLI rsp */
1722 ndlp
->nlp_type
&= ~(NLP_FCP_TARGET
| NLP_FCP_INITIATOR
);
1723 ndlp
->nlp_fcp_info
&= ~NLP_FCP_2_DEVICE
;
1724 ndlp
->nlp_flag
&= ~NLP_FIRSTBURST
;
1725 if ((npr
->acceptRspCode
== PRLI_REQ_EXECUTED
) &&
1726 (npr
->prliType
== PRLI_FCP_TYPE
)) {
1727 if (npr
->initiatorFunc
)
1728 ndlp
->nlp_type
|= NLP_FCP_INITIATOR
;
1729 if (npr
->targetFunc
) {
1730 ndlp
->nlp_type
|= NLP_FCP_TARGET
;
1731 if (npr
->writeXferRdyDis
)
1732 ndlp
->nlp_flag
|= NLP_FIRSTBURST
;
1735 ndlp
->nlp_fcp_info
|= NLP_FCP_2_DEVICE
;
1737 if (!(ndlp
->nlp_type
& NLP_FCP_TARGET
) &&
1738 (vport
->port_type
== LPFC_NPIV_PORT
) &&
1739 vport
->cfg_restrict_login
) {
1741 spin_lock_irq(shost
->host_lock
);
1742 ndlp
->nlp_flag
|= NLP_TARGET_REMOVE
;
1743 spin_unlock_irq(shost
->host_lock
);
1744 lpfc_issue_els_logo(vport
, ndlp
, 0);
1746 ndlp
->nlp_prev_state
= NLP_STE_PRLI_ISSUE
;
1747 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1748 return ndlp
->nlp_state
;
1751 ndlp
->nlp_prev_state
= NLP_STE_PRLI_ISSUE
;
1752 if (ndlp
->nlp_type
& NLP_FCP_TARGET
)
1753 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_MAPPED_NODE
);
1755 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
1756 return ndlp
->nlp_state
;
1759 /*! lpfc_device_rm_prli_issue
1770 * This routine is envoked when we a request to remove a nport we are in the
1771 * process of PRLIing. We should software abort outstanding prli, unreg
1772 * login, send a logout. We will change node state to UNUSED_NODE, put it
1773 * on plogi list so it can be freed when LOGO completes.
1778 lpfc_device_rm_prli_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1779 void *arg
, uint32_t evt
)
1781 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1783 if (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) {
1784 spin_lock_irq(shost
->host_lock
);
1785 ndlp
->nlp_flag
|= NLP_NODEV_REMOVE
;
1786 spin_unlock_irq(shost
->host_lock
);
1787 return ndlp
->nlp_state
;
1789 /* software abort outstanding PLOGI */
1790 lpfc_els_abort(vport
->phba
, ndlp
);
1792 lpfc_drop_node(vport
, ndlp
);
1793 return NLP_STE_FREED_NODE
;
1798 /*! lpfc_device_recov_prli_issue
1809 * The routine is envoked when the state of a device is unknown, like
1810 * during a link down. We should remove the nodelist entry from the
1811 * unmapped list, issue a UNREG_LOGIN, do a software abort of the
1812 * outstanding PRLI command, then free the node entry.
1815 lpfc_device_recov_prli_issue(struct lpfc_vport
*vport
,
1816 struct lpfc_nodelist
*ndlp
,
1820 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1821 struct lpfc_hba
*phba
= vport
->phba
;
1823 /* Don't do anything that will mess up processing of the
1826 if (vport
->fc_flag
& FC_RSCN_DEFERRED
)
1827 return ndlp
->nlp_state
;
1829 /* software abort outstanding PRLI */
1830 lpfc_els_abort(phba
, ndlp
);
1832 ndlp
->nlp_prev_state
= NLP_STE_PRLI_ISSUE
;
1833 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1834 spin_lock_irq(shost
->host_lock
);
1835 ndlp
->nlp_flag
&= ~(NLP_NODEV_REMOVE
| NLP_NPR_2B_DISC
);
1836 spin_unlock_irq(shost
->host_lock
);
1837 lpfc_disc_set_adisc(vport
, ndlp
);
1838 return ndlp
->nlp_state
;
1842 lpfc_rcv_plogi_logo_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1843 void *arg
, uint32_t evt
)
1845 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*)arg
;
1848 memset(&stat
, 0, sizeof(struct ls_rjt
));
1849 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
1850 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_NOTHING_MORE
;
1851 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
1852 return ndlp
->nlp_state
;
1856 lpfc_rcv_prli_logo_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1857 void *arg
, uint32_t evt
)
1859 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*)arg
;
1862 memset(&stat
, 0, sizeof(struct ls_rjt
));
1863 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
1864 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_NOTHING_MORE
;
1865 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
1866 return ndlp
->nlp_state
;
1870 lpfc_rcv_logo_logo_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1871 void *arg
, uint32_t evt
)
1873 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1874 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*)arg
;
1876 spin_lock_irq(shost
->host_lock
);
1877 ndlp
->nlp_flag
|= NLP_LOGO_ACC
;
1878 spin_unlock_irq(shost
->host_lock
);
1879 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
1880 return ndlp
->nlp_state
;
1884 lpfc_rcv_padisc_logo_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1885 void *arg
, uint32_t evt
)
1887 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*)arg
;
1890 memset(&stat
, 0, sizeof(struct ls_rjt
));
1891 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
1892 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_NOTHING_MORE
;
1893 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
1894 return ndlp
->nlp_state
;
1898 lpfc_rcv_prlo_logo_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1899 void *arg
, uint32_t evt
)
1901 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*)arg
;
1904 memset(&stat
, 0, sizeof(struct ls_rjt
));
1905 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
1906 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_NOTHING_MORE
;
1907 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
1908 return ndlp
->nlp_state
;
1912 lpfc_cmpl_logo_logo_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1913 void *arg
, uint32_t evt
)
1915 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1917 ndlp
->nlp_prev_state
= NLP_STE_LOGO_ISSUE
;
1918 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1919 spin_lock_irq(shost
->host_lock
);
1920 ndlp
->nlp_flag
&= ~(NLP_NODEV_REMOVE
| NLP_NPR_2B_DISC
);
1921 spin_unlock_irq(shost
->host_lock
);
1922 lpfc_disc_set_adisc(vport
, ndlp
);
1923 return ndlp
->nlp_state
;
1927 lpfc_device_rm_logo_issue(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1928 void *arg
, uint32_t evt
)
1931 * Take no action. If a LOGO is outstanding, then possibly DevLoss has
1932 * timed out and is calling for Device Remove. In this case, the LOGO
1933 * must be allowed to complete in state LOGO_ISSUE so that the rpi
1934 * and other NLP flags are correctly cleaned up.
1936 return ndlp
->nlp_state
;
1940 lpfc_device_recov_logo_issue(struct lpfc_vport
*vport
,
1941 struct lpfc_nodelist
*ndlp
,
1942 void *arg
, uint32_t evt
)
1945 * Device Recovery events have no meaning for a node with a LOGO
1946 * outstanding. The LOGO has to complete first and handle the
1947 * node from that point.
1949 return ndlp
->nlp_state
;
1953 lpfc_rcv_plogi_unmap_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1954 void *arg
, uint32_t evt
)
1956 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1958 lpfc_rcv_plogi(vport
, ndlp
, cmdiocb
);
1959 return ndlp
->nlp_state
;
1963 lpfc_rcv_prli_unmap_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1964 void *arg
, uint32_t evt
)
1966 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1968 lpfc_rcv_prli(vport
, ndlp
, cmdiocb
);
1969 lpfc_els_rsp_prli_acc(vport
, cmdiocb
, ndlp
);
1970 return ndlp
->nlp_state
;
1974 lpfc_rcv_logo_unmap_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1975 void *arg
, uint32_t evt
)
1977 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1979 lpfc_rcv_logo(vport
, ndlp
, cmdiocb
, ELS_CMD_LOGO
);
1980 return ndlp
->nlp_state
;
1984 lpfc_rcv_padisc_unmap_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1985 void *arg
, uint32_t evt
)
1987 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1989 lpfc_rcv_padisc(vport
, ndlp
, cmdiocb
);
1990 return ndlp
->nlp_state
;
1994 lpfc_rcv_prlo_unmap_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1995 void *arg
, uint32_t evt
)
1997 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
1999 lpfc_els_rsp_acc(vport
, ELS_CMD_PRLO
, cmdiocb
, ndlp
, NULL
);
2000 return ndlp
->nlp_state
;
2004 lpfc_device_recov_unmap_node(struct lpfc_vport
*vport
,
2005 struct lpfc_nodelist
*ndlp
,
2009 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2011 ndlp
->nlp_prev_state
= NLP_STE_UNMAPPED_NODE
;
2012 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
2013 spin_lock_irq(shost
->host_lock
);
2014 ndlp
->nlp_flag
&= ~(NLP_NODEV_REMOVE
| NLP_NPR_2B_DISC
);
2015 spin_unlock_irq(shost
->host_lock
);
2016 lpfc_disc_set_adisc(vport
, ndlp
);
2018 return ndlp
->nlp_state
;
2022 lpfc_rcv_plogi_mapped_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2023 void *arg
, uint32_t evt
)
2025 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2027 lpfc_rcv_plogi(vport
, ndlp
, cmdiocb
);
2028 return ndlp
->nlp_state
;
2032 lpfc_rcv_prli_mapped_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2033 void *arg
, uint32_t evt
)
2035 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2037 lpfc_els_rsp_prli_acc(vport
, cmdiocb
, ndlp
);
2038 return ndlp
->nlp_state
;
2042 lpfc_rcv_logo_mapped_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2043 void *arg
, uint32_t evt
)
2045 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2047 lpfc_rcv_logo(vport
, ndlp
, cmdiocb
, ELS_CMD_LOGO
);
2048 return ndlp
->nlp_state
;
2052 lpfc_rcv_padisc_mapped_node(struct lpfc_vport
*vport
,
2053 struct lpfc_nodelist
*ndlp
,
2054 void *arg
, uint32_t evt
)
2056 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2058 lpfc_rcv_padisc(vport
, ndlp
, cmdiocb
);
2059 return ndlp
->nlp_state
;
2063 lpfc_rcv_prlo_mapped_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2064 void *arg
, uint32_t evt
)
2066 struct lpfc_hba
*phba
= vport
->phba
;
2067 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2069 /* flush the target */
2070 lpfc_sli_abort_iocb(vport
, &phba
->sli
.ring
[phba
->sli
.fcp_ring
],
2071 ndlp
->nlp_sid
, 0, LPFC_CTX_TGT
);
2073 /* Treat like rcv logo */
2074 lpfc_rcv_logo(vport
, ndlp
, cmdiocb
, ELS_CMD_PRLO
);
2075 return ndlp
->nlp_state
;
2079 lpfc_device_recov_mapped_node(struct lpfc_vport
*vport
,
2080 struct lpfc_nodelist
*ndlp
,
2084 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2086 ndlp
->nlp_prev_state
= NLP_STE_MAPPED_NODE
;
2087 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
2088 spin_lock_irq(shost
->host_lock
);
2089 ndlp
->nlp_flag
&= ~(NLP_NODEV_REMOVE
| NLP_NPR_2B_DISC
);
2090 spin_unlock_irq(shost
->host_lock
);
2091 lpfc_disc_set_adisc(vport
, ndlp
);
2092 return ndlp
->nlp_state
;
2096 lpfc_rcv_plogi_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2097 void *arg
, uint32_t evt
)
2099 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2100 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2102 /* Ignore PLOGI if we have an outstanding LOGO */
2103 if (ndlp
->nlp_flag
& (NLP_LOGO_SND
| NLP_LOGO_ACC
))
2104 return ndlp
->nlp_state
;
2105 if (lpfc_rcv_plogi(vport
, ndlp
, cmdiocb
)) {
2106 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
2107 spin_lock_irq(shost
->host_lock
);
2108 ndlp
->nlp_flag
&= ~(NLP_NPR_ADISC
| NLP_NPR_2B_DISC
);
2109 spin_unlock_irq(shost
->host_lock
);
2110 } else if (!(ndlp
->nlp_flag
& NLP_NPR_2B_DISC
)) {
2111 /* send PLOGI immediately, move to PLOGI issue state */
2112 if (!(ndlp
->nlp_flag
& NLP_DELAY_TMO
)) {
2113 ndlp
->nlp_prev_state
= NLP_STE_NPR_NODE
;
2114 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
2115 lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0);
2118 return ndlp
->nlp_state
;
2122 lpfc_rcv_prli_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2123 void *arg
, uint32_t evt
)
2125 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2126 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2129 memset(&stat
, 0, sizeof (struct ls_rjt
));
2130 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
2131 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_NOTHING_MORE
;
2132 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
2134 if (!(ndlp
->nlp_flag
& NLP_DELAY_TMO
)) {
2135 if (ndlp
->nlp_flag
& NLP_NPR_ADISC
) {
2136 spin_lock_irq(shost
->host_lock
);
2137 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
2138 ndlp
->nlp_prev_state
= NLP_STE_NPR_NODE
;
2139 spin_unlock_irq(shost
->host_lock
);
2140 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_ADISC_ISSUE
);
2141 lpfc_issue_els_adisc(vport
, ndlp
, 0);
2143 ndlp
->nlp_prev_state
= NLP_STE_NPR_NODE
;
2144 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
2145 lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0);
2148 return ndlp
->nlp_state
;
2152 lpfc_rcv_logo_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2153 void *arg
, uint32_t evt
)
2155 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2157 lpfc_rcv_logo(vport
, ndlp
, cmdiocb
, ELS_CMD_LOGO
);
2158 return ndlp
->nlp_state
;
2162 lpfc_rcv_padisc_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2163 void *arg
, uint32_t evt
)
2165 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2167 lpfc_rcv_padisc(vport
, ndlp
, cmdiocb
);
2169 * Do not start discovery if discovery is about to start
2170 * or discovery in progress for this node. Starting discovery
2171 * here will affect the counting of discovery threads.
2173 if (!(ndlp
->nlp_flag
& NLP_DELAY_TMO
) &&
2174 !(ndlp
->nlp_flag
& NLP_NPR_2B_DISC
)) {
2175 if (ndlp
->nlp_flag
& NLP_NPR_ADISC
) {
2176 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
2177 ndlp
->nlp_prev_state
= NLP_STE_NPR_NODE
;
2178 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_ADISC_ISSUE
);
2179 lpfc_issue_els_adisc(vport
, ndlp
, 0);
2181 ndlp
->nlp_prev_state
= NLP_STE_NPR_NODE
;
2182 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
2183 lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0);
2186 return ndlp
->nlp_state
;
2190 lpfc_rcv_prlo_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2191 void *arg
, uint32_t evt
)
2193 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2194 struct lpfc_iocbq
*cmdiocb
= (struct lpfc_iocbq
*) arg
;
2196 spin_lock_irq(shost
->host_lock
);
2197 ndlp
->nlp_flag
|= NLP_LOGO_ACC
;
2198 spin_unlock_irq(shost
->host_lock
);
2200 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
2202 if ((ndlp
->nlp_flag
& NLP_DELAY_TMO
) == 0) {
2203 mod_timer(&ndlp
->nlp_delayfunc
,
2204 jiffies
+ msecs_to_jiffies(1000 * 1));
2205 spin_lock_irq(shost
->host_lock
);
2206 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
2207 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
2208 spin_unlock_irq(shost
->host_lock
);
2209 ndlp
->nlp_last_elscmd
= ELS_CMD_PLOGI
;
2211 spin_lock_irq(shost
->host_lock
);
2212 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
2213 spin_unlock_irq(shost
->host_lock
);
2215 return ndlp
->nlp_state
;
2219 lpfc_cmpl_plogi_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2220 void *arg
, uint32_t evt
)
2222 struct lpfc_iocbq
*cmdiocb
, *rspiocb
;
2224 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2226 cmdiocb
= (struct lpfc_iocbq
*) arg
;
2227 rspiocb
= cmdiocb
->context_un
.rsp_iocb
;
2229 irsp
= &rspiocb
->iocb
;
2230 if (irsp
->ulpStatus
) {
2231 spin_lock_irq(shost
->host_lock
);
2232 ndlp
->nlp_flag
|= NLP_DEFER_RM
;
2233 spin_unlock_irq(shost
->host_lock
);
2234 return NLP_STE_FREED_NODE
;
2236 return ndlp
->nlp_state
;
2240 lpfc_cmpl_prli_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2241 void *arg
, uint32_t evt
)
2243 struct lpfc_iocbq
*cmdiocb
, *rspiocb
;
2246 cmdiocb
= (struct lpfc_iocbq
*) arg
;
2247 rspiocb
= cmdiocb
->context_un
.rsp_iocb
;
2249 irsp
= &rspiocb
->iocb
;
2250 if (irsp
->ulpStatus
&& (ndlp
->nlp_flag
& NLP_NODEV_REMOVE
)) {
2251 lpfc_drop_node(vport
, ndlp
);
2252 return NLP_STE_FREED_NODE
;
2254 return ndlp
->nlp_state
;
2258 lpfc_cmpl_logo_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2259 void *arg
, uint32_t evt
)
2261 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2263 /* For the fabric port just clear the fc flags. */
2264 if (ndlp
->nlp_DID
== Fabric_DID
) {
2265 spin_lock_irq(shost
->host_lock
);
2266 vport
->fc_flag
&= ~(FC_FABRIC
| FC_PUBLIC_LOOP
);
2267 spin_unlock_irq(shost
->host_lock
);
2269 lpfc_unreg_rpi(vport
, ndlp
);
2270 return ndlp
->nlp_state
;
2274 lpfc_cmpl_adisc_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2275 void *arg
, uint32_t evt
)
2277 struct lpfc_iocbq
*cmdiocb
, *rspiocb
;
2280 cmdiocb
= (struct lpfc_iocbq
*) arg
;
2281 rspiocb
= cmdiocb
->context_un
.rsp_iocb
;
2283 irsp
= &rspiocb
->iocb
;
2284 if (irsp
->ulpStatus
&& (ndlp
->nlp_flag
& NLP_NODEV_REMOVE
)) {
2285 lpfc_drop_node(vport
, ndlp
);
2286 return NLP_STE_FREED_NODE
;
2288 return ndlp
->nlp_state
;
2292 lpfc_cmpl_reglogin_npr_node(struct lpfc_vport
*vport
,
2293 struct lpfc_nodelist
*ndlp
,
2294 void *arg
, uint32_t evt
)
2296 LPFC_MBOXQ_t
*pmb
= (LPFC_MBOXQ_t
*) arg
;
2297 MAILBOX_t
*mb
= &pmb
->u
.mb
;
2299 if (!mb
->mbxStatus
) {
2300 /* SLI4 ports have preallocated logical rpis. */
2301 if (vport
->phba
->sli_rev
< LPFC_SLI_REV4
)
2302 ndlp
->nlp_rpi
= mb
->un
.varWords
[0];
2303 ndlp
->nlp_flag
|= NLP_RPI_REGISTERED
;
2305 if (ndlp
->nlp_flag
& NLP_NODEV_REMOVE
) {
2306 lpfc_drop_node(vport
, ndlp
);
2307 return NLP_STE_FREED_NODE
;
2310 return ndlp
->nlp_state
;
2314 lpfc_device_rm_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2315 void *arg
, uint32_t evt
)
2317 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2319 if (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) {
2320 spin_lock_irq(shost
->host_lock
);
2321 ndlp
->nlp_flag
|= NLP_NODEV_REMOVE
;
2322 spin_unlock_irq(shost
->host_lock
);
2323 return ndlp
->nlp_state
;
2325 lpfc_drop_node(vport
, ndlp
);
2326 return NLP_STE_FREED_NODE
;
2330 lpfc_device_recov_npr_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2331 void *arg
, uint32_t evt
)
2333 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2335 /* Don't do anything that will mess up processing of the
2338 if (vport
->fc_flag
& FC_RSCN_DEFERRED
)
2339 return ndlp
->nlp_state
;
2341 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
2342 spin_lock_irq(shost
->host_lock
);
2343 ndlp
->nlp_flag
&= ~(NLP_NODEV_REMOVE
| NLP_NPR_2B_DISC
);
2344 spin_unlock_irq(shost
->host_lock
);
2345 return ndlp
->nlp_state
;
2349 /* This next section defines the NPort Discovery State Machine */
2351 /* There are 4 different double linked lists nodelist entries can reside on.
2352 * The plogi list and adisc list are used when Link Up discovery or RSCN
2353 * processing is needed. Each list holds the nodes that we will send PLOGI
2354 * or ADISC on. These lists will keep track of what nodes will be effected
2355 * by an RSCN, or a Link Up (Typically, all nodes are effected on Link Up).
2356 * The unmapped_list will contain all nodes that we have successfully logged
2357 * into at the Fibre Channel level. The mapped_list will contain all nodes
2358 * that are mapped FCP targets.
2361 * The bind list is a list of undiscovered (potentially non-existent) nodes
2362 * that we have saved binding information on. This information is used when
2363 * nodes transition from the unmapped to the mapped list.
2365 /* For UNUSED_NODE state, the node has just been allocated .
2366 * For PLOGI_ISSUE and REG_LOGIN_ISSUE, the node is on
2367 * the PLOGI list. For REG_LOGIN_COMPL, the node is taken off the PLOGI list
2368 * and put on the unmapped list. For ADISC processing, the node is taken off
2369 * the ADISC list and placed on either the mapped or unmapped list (depending
2370 * on its previous state). Once on the unmapped list, a PRLI is issued and the
2371 * state changed to PRLI_ISSUE. When the PRLI completion occurs, the state is
2372 * changed to UNMAPPED_NODE. If the completion indicates a mapped
2373 * node, the node is taken off the unmapped list. The binding list is checked
2374 * for a valid binding, or a binding is automatically assigned. If binding
2375 * assignment is unsuccessful, the node is left on the unmapped list. If
2376 * binding assignment is successful, the associated binding list entry (if
2377 * any) is removed, and the node is placed on the mapped list.
2380 * For a Link Down, all nodes on the ADISC, PLOGI, unmapped or mapped
2381 * lists will receive a DEVICE_RECOVERY event. If the linkdown or devloss timers
2382 * expire, all effected nodes will receive a DEVICE_RM event.
2385 * For a Link Up or RSCN, all nodes will move from the mapped / unmapped lists
2386 * to either the ADISC or PLOGI list. After a Nameserver query or ALPA loopmap
2387 * check, additional nodes may be added or removed (via DEVICE_RM) to / from
2388 * the PLOGI or ADISC lists. Once the PLOGI and ADISC lists are populated,
2389 * we will first process the ADISC list. 32 entries are processed initially and
2390 * ADISC is initited for each one. Completions / Events for each node are
2391 * funnelled thru the state machine. As each node finishes ADISC processing, it
2392 * starts ADISC for any nodes waiting for ADISC processing. If no nodes are
2393 * waiting, and the ADISC list count is identically 0, then we are done. For
2394 * Link Up discovery, since all nodes on the PLOGI list are UNREG_LOGIN'ed, we
2395 * can issue a CLEAR_LA and reenable Link Events. Next we will process the PLOGI
2396 * list. 32 entries are processed initially and PLOGI is initited for each one.
2397 * Completions / Events for each node are funnelled thru the state machine. As
2398 * each node finishes PLOGI processing, it starts PLOGI for any nodes waiting
2399 * for PLOGI processing. If no nodes are waiting, and the PLOGI list count is
2400 * indentically 0, then we are done. We have now completed discovery / RSCN
2401 * handling. Upon completion, ALL nodes should be on either the mapped or
2405 static uint32_t (*lpfc_disc_action
[NLP_STE_MAX_STATE
* NLP_EVT_MAX_EVENT
])
2406 (struct lpfc_vport
*, struct lpfc_nodelist
*, void *, uint32_t) = {
2407 /* Action routine Event Current State */
2408 lpfc_rcv_plogi_unused_node
, /* RCV_PLOGI UNUSED_NODE */
2409 lpfc_rcv_els_unused_node
, /* RCV_PRLI */
2410 lpfc_rcv_logo_unused_node
, /* RCV_LOGO */
2411 lpfc_rcv_els_unused_node
, /* RCV_ADISC */
2412 lpfc_rcv_els_unused_node
, /* RCV_PDISC */
2413 lpfc_rcv_els_unused_node
, /* RCV_PRLO */
2414 lpfc_disc_illegal
, /* CMPL_PLOGI */
2415 lpfc_disc_illegal
, /* CMPL_PRLI */
2416 lpfc_cmpl_logo_unused_node
, /* CMPL_LOGO */
2417 lpfc_disc_illegal
, /* CMPL_ADISC */
2418 lpfc_disc_illegal
, /* CMPL_REG_LOGIN */
2419 lpfc_device_rm_unused_node
, /* DEVICE_RM */
2420 lpfc_device_recov_unused_node
, /* DEVICE_RECOVERY */
2422 lpfc_rcv_plogi_plogi_issue
, /* RCV_PLOGI PLOGI_ISSUE */
2423 lpfc_rcv_prli_plogi_issue
, /* RCV_PRLI */
2424 lpfc_rcv_logo_plogi_issue
, /* RCV_LOGO */
2425 lpfc_rcv_els_plogi_issue
, /* RCV_ADISC */
2426 lpfc_rcv_els_plogi_issue
, /* RCV_PDISC */
2427 lpfc_rcv_els_plogi_issue
, /* RCV_PRLO */
2428 lpfc_cmpl_plogi_plogi_issue
, /* CMPL_PLOGI */
2429 lpfc_disc_illegal
, /* CMPL_PRLI */
2430 lpfc_cmpl_logo_plogi_issue
, /* CMPL_LOGO */
2431 lpfc_disc_illegal
, /* CMPL_ADISC */
2432 lpfc_cmpl_reglogin_plogi_issue
,/* CMPL_REG_LOGIN */
2433 lpfc_device_rm_plogi_issue
, /* DEVICE_RM */
2434 lpfc_device_recov_plogi_issue
, /* DEVICE_RECOVERY */
2436 lpfc_rcv_plogi_adisc_issue
, /* RCV_PLOGI ADISC_ISSUE */
2437 lpfc_rcv_prli_adisc_issue
, /* RCV_PRLI */
2438 lpfc_rcv_logo_adisc_issue
, /* RCV_LOGO */
2439 lpfc_rcv_padisc_adisc_issue
, /* RCV_ADISC */
2440 lpfc_rcv_padisc_adisc_issue
, /* RCV_PDISC */
2441 lpfc_rcv_prlo_adisc_issue
, /* RCV_PRLO */
2442 lpfc_disc_illegal
, /* CMPL_PLOGI */
2443 lpfc_disc_illegal
, /* CMPL_PRLI */
2444 lpfc_disc_illegal
, /* CMPL_LOGO */
2445 lpfc_cmpl_adisc_adisc_issue
, /* CMPL_ADISC */
2446 lpfc_disc_illegal
, /* CMPL_REG_LOGIN */
2447 lpfc_device_rm_adisc_issue
, /* DEVICE_RM */
2448 lpfc_device_recov_adisc_issue
, /* DEVICE_RECOVERY */
2450 lpfc_rcv_plogi_reglogin_issue
, /* RCV_PLOGI REG_LOGIN_ISSUE */
2451 lpfc_rcv_prli_reglogin_issue
, /* RCV_PLOGI */
2452 lpfc_rcv_logo_reglogin_issue
, /* RCV_LOGO */
2453 lpfc_rcv_padisc_reglogin_issue
, /* RCV_ADISC */
2454 lpfc_rcv_padisc_reglogin_issue
, /* RCV_PDISC */
2455 lpfc_rcv_prlo_reglogin_issue
, /* RCV_PRLO */
2456 lpfc_cmpl_plogi_illegal
, /* CMPL_PLOGI */
2457 lpfc_disc_illegal
, /* CMPL_PRLI */
2458 lpfc_disc_illegal
, /* CMPL_LOGO */
2459 lpfc_disc_illegal
, /* CMPL_ADISC */
2460 lpfc_cmpl_reglogin_reglogin_issue
,/* CMPL_REG_LOGIN */
2461 lpfc_device_rm_reglogin_issue
, /* DEVICE_RM */
2462 lpfc_device_recov_reglogin_issue
,/* DEVICE_RECOVERY */
2464 lpfc_rcv_plogi_prli_issue
, /* RCV_PLOGI PRLI_ISSUE */
2465 lpfc_rcv_prli_prli_issue
, /* RCV_PRLI */
2466 lpfc_rcv_logo_prli_issue
, /* RCV_LOGO */
2467 lpfc_rcv_padisc_prli_issue
, /* RCV_ADISC */
2468 lpfc_rcv_padisc_prli_issue
, /* RCV_PDISC */
2469 lpfc_rcv_prlo_prli_issue
, /* RCV_PRLO */
2470 lpfc_cmpl_plogi_illegal
, /* CMPL_PLOGI */
2471 lpfc_cmpl_prli_prli_issue
, /* CMPL_PRLI */
2472 lpfc_disc_illegal
, /* CMPL_LOGO */
2473 lpfc_disc_illegal
, /* CMPL_ADISC */
2474 lpfc_disc_illegal
, /* CMPL_REG_LOGIN */
2475 lpfc_device_rm_prli_issue
, /* DEVICE_RM */
2476 lpfc_device_recov_prli_issue
, /* DEVICE_RECOVERY */
2478 lpfc_rcv_plogi_logo_issue
, /* RCV_PLOGI LOGO_ISSUE */
2479 lpfc_rcv_prli_logo_issue
, /* RCV_PRLI */
2480 lpfc_rcv_logo_logo_issue
, /* RCV_LOGO */
2481 lpfc_rcv_padisc_logo_issue
, /* RCV_ADISC */
2482 lpfc_rcv_padisc_logo_issue
, /* RCV_PDISC */
2483 lpfc_rcv_prlo_logo_issue
, /* RCV_PRLO */
2484 lpfc_cmpl_plogi_illegal
, /* CMPL_PLOGI */
2485 lpfc_disc_illegal
, /* CMPL_PRLI */
2486 lpfc_cmpl_logo_logo_issue
, /* CMPL_LOGO */
2487 lpfc_disc_illegal
, /* CMPL_ADISC */
2488 lpfc_disc_illegal
, /* CMPL_REG_LOGIN */
2489 lpfc_device_rm_logo_issue
, /* DEVICE_RM */
2490 lpfc_device_recov_logo_issue
, /* DEVICE_RECOVERY */
2492 lpfc_rcv_plogi_unmap_node
, /* RCV_PLOGI UNMAPPED_NODE */
2493 lpfc_rcv_prli_unmap_node
, /* RCV_PRLI */
2494 lpfc_rcv_logo_unmap_node
, /* RCV_LOGO */
2495 lpfc_rcv_padisc_unmap_node
, /* RCV_ADISC */
2496 lpfc_rcv_padisc_unmap_node
, /* RCV_PDISC */
2497 lpfc_rcv_prlo_unmap_node
, /* RCV_PRLO */
2498 lpfc_disc_illegal
, /* CMPL_PLOGI */
2499 lpfc_disc_illegal
, /* CMPL_PRLI */
2500 lpfc_disc_illegal
, /* CMPL_LOGO */
2501 lpfc_disc_illegal
, /* CMPL_ADISC */
2502 lpfc_disc_illegal
, /* CMPL_REG_LOGIN */
2503 lpfc_disc_illegal
, /* DEVICE_RM */
2504 lpfc_device_recov_unmap_node
, /* DEVICE_RECOVERY */
2506 lpfc_rcv_plogi_mapped_node
, /* RCV_PLOGI MAPPED_NODE */
2507 lpfc_rcv_prli_mapped_node
, /* RCV_PRLI */
2508 lpfc_rcv_logo_mapped_node
, /* RCV_LOGO */
2509 lpfc_rcv_padisc_mapped_node
, /* RCV_ADISC */
2510 lpfc_rcv_padisc_mapped_node
, /* RCV_PDISC */
2511 lpfc_rcv_prlo_mapped_node
, /* RCV_PRLO */
2512 lpfc_disc_illegal
, /* CMPL_PLOGI */
2513 lpfc_disc_illegal
, /* CMPL_PRLI */
2514 lpfc_disc_illegal
, /* CMPL_LOGO */
2515 lpfc_disc_illegal
, /* CMPL_ADISC */
2516 lpfc_disc_illegal
, /* CMPL_REG_LOGIN */
2517 lpfc_disc_illegal
, /* DEVICE_RM */
2518 lpfc_device_recov_mapped_node
, /* DEVICE_RECOVERY */
2520 lpfc_rcv_plogi_npr_node
, /* RCV_PLOGI NPR_NODE */
2521 lpfc_rcv_prli_npr_node
, /* RCV_PRLI */
2522 lpfc_rcv_logo_npr_node
, /* RCV_LOGO */
2523 lpfc_rcv_padisc_npr_node
, /* RCV_ADISC */
2524 lpfc_rcv_padisc_npr_node
, /* RCV_PDISC */
2525 lpfc_rcv_prlo_npr_node
, /* RCV_PRLO */
2526 lpfc_cmpl_plogi_npr_node
, /* CMPL_PLOGI */
2527 lpfc_cmpl_prli_npr_node
, /* CMPL_PRLI */
2528 lpfc_cmpl_logo_npr_node
, /* CMPL_LOGO */
2529 lpfc_cmpl_adisc_npr_node
, /* CMPL_ADISC */
2530 lpfc_cmpl_reglogin_npr_node
, /* CMPL_REG_LOGIN */
2531 lpfc_device_rm_npr_node
, /* DEVICE_RM */
2532 lpfc_device_recov_npr_node
, /* DEVICE_RECOVERY */
2536 lpfc_disc_state_machine(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2537 void *arg
, uint32_t evt
)
2539 uint32_t cur_state
, rc
;
2540 uint32_t(*func
) (struct lpfc_vport
*, struct lpfc_nodelist
*, void *,
2542 uint32_t got_ndlp
= 0;
2544 if (lpfc_nlp_get(ndlp
))
2547 cur_state
= ndlp
->nlp_state
;
2549 /* DSM in event <evt> on NPort <nlp_DID> in state <cur_state> */
2550 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
2551 "0211 DSM in event x%x on NPort x%x in "
2552 "state %d Data: x%x\n",
2553 evt
, ndlp
->nlp_DID
, cur_state
, ndlp
->nlp_flag
);
2555 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_DSM
,
2556 "DSM in: evt:%d ste:%d did:x%x",
2557 evt
, cur_state
, ndlp
->nlp_DID
);
2559 func
= lpfc_disc_action
[(cur_state
* NLP_EVT_MAX_EVENT
) + evt
];
2560 rc
= (func
) (vport
, ndlp
, arg
, evt
);
2562 /* DSM out state <rc> on NPort <nlp_DID> */
2564 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
2565 "0212 DSM out state %d on NPort x%x Data: x%x\n",
2566 rc
, ndlp
->nlp_DID
, ndlp
->nlp_flag
);
2568 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_DSM
,
2569 "DSM out: ste:%d did:x%x flg:x%x",
2570 rc
, ndlp
->nlp_DID
, ndlp
->nlp_flag
);
2571 /* Decrement the ndlp reference count held for this function */
2574 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
2575 "0213 DSM out state %d on NPort free\n", rc
);
2577 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_DSM
,
2578 "DSM out: ste:%d did:x%x flg:x%x",