1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2008 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/interrupt.h>
26 #include <scsi/scsi.h>
27 #include <scsi/scsi_device.h>
28 #include <scsi/scsi_host.h>
29 #include <scsi/scsi_transport_fc.h>
33 #include "lpfc_disc.h"
34 #include "lpfc_scsi.h"
36 #include "lpfc_logmsg.h"
37 #include "lpfc_crtn.h"
38 #include "lpfc_vport.h"
39 #include "lpfc_debugfs.h"
42 /* Called to verify a rcv'ed ADISC was intended for us. */
44 lpfc_check_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
45 struct lpfc_name *nn, struct lpfc_name *pn)
47 /* Compare the ADISC rsp WWNN / WWPN matches our internal node
48 * table entry for that node.
50 if (memcmp(nn, &ndlp->nlp_nodename, sizeof (struct lpfc_name)))
53 if (memcmp(pn, &ndlp->nlp_portname, sizeof (struct lpfc_name)))
56 /* we match, return success */
61 lpfc_check_sparm(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
62 struct serv_parm * sp, uint32_t class)
64 volatile struct serv_parm *hsp = &vport->fc_sparam;
65 uint16_t hsp_value, ssp_value = 0;
68 * The receive data field size and buffer-to-buffer receive data field
69 * size entries are 16 bits but are represented as two 8-bit fields in
70 * the driver data structure to account for rsvd bits and other control
71 * bits. Reconstruct and compare the fields as a 16-bit values before
72 * correcting the byte values.
74 if (sp->cls1.classValid) {
75 hsp_value = (hsp->cls1.rcvDataSizeMsb << 8) |
76 hsp->cls1.rcvDataSizeLsb;
77 ssp_value = (sp->cls1.rcvDataSizeMsb << 8) |
78 sp->cls1.rcvDataSizeLsb;
80 goto bad_service_param;
81 if (ssp_value > hsp_value) {
82 sp->cls1.rcvDataSizeLsb = hsp->cls1.rcvDataSizeLsb;
83 sp->cls1.rcvDataSizeMsb = hsp->cls1.rcvDataSizeMsb;
85 } else if (class == CLASS1) {
86 goto bad_service_param;
89 if (sp->cls2.classValid) {
90 hsp_value = (hsp->cls2.rcvDataSizeMsb << 8) |
91 hsp->cls2.rcvDataSizeLsb;
92 ssp_value = (sp->cls2.rcvDataSizeMsb << 8) |
93 sp->cls2.rcvDataSizeLsb;
95 goto bad_service_param;
96 if (ssp_value > hsp_value) {
97 sp->cls2.rcvDataSizeLsb = hsp->cls2.rcvDataSizeLsb;
98 sp->cls2.rcvDataSizeMsb = hsp->cls2.rcvDataSizeMsb;
100 } else if (class == CLASS2) {
101 goto bad_service_param;
104 if (sp->cls3.classValid) {
105 hsp_value = (hsp->cls3.rcvDataSizeMsb << 8) |
106 hsp->cls3.rcvDataSizeLsb;
107 ssp_value = (sp->cls3.rcvDataSizeMsb << 8) |
108 sp->cls3.rcvDataSizeLsb;
110 goto bad_service_param;
111 if (ssp_value > hsp_value) {
112 sp->cls3.rcvDataSizeLsb = hsp->cls3.rcvDataSizeLsb;
113 sp->cls3.rcvDataSizeMsb = hsp->cls3.rcvDataSizeMsb;
115 } else if (class == CLASS3) {
116 goto bad_service_param;
120 * Preserve the upper four bits of the MSB from the PLOGI response.
121 * These bits contain the Buffer-to-Buffer State Change Number
122 * from the target and need to be passed to the FW.
124 hsp_value = (hsp->cmn.bbRcvSizeMsb << 8) | hsp->cmn.bbRcvSizeLsb;
125 ssp_value = (sp->cmn.bbRcvSizeMsb << 8) | sp->cmn.bbRcvSizeLsb;
126 if (ssp_value > hsp_value) {
127 sp->cmn.bbRcvSizeLsb = hsp->cmn.bbRcvSizeLsb;
128 sp->cmn.bbRcvSizeMsb = (sp->cmn.bbRcvSizeMsb & 0xF0) |
129 (hsp->cmn.bbRcvSizeMsb & 0x0F);
132 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof (struct lpfc_name));
133 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof (struct lpfc_name));
136 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
138 "(%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x) sent "
139 "invalid service parameters. Ignoring device.\n",
141 sp->nodeName.u.wwn[0], sp->nodeName.u.wwn[1],
142 sp->nodeName.u.wwn[2], sp->nodeName.u.wwn[3],
143 sp->nodeName.u.wwn[4], sp->nodeName.u.wwn[5],
144 sp->nodeName.u.wwn[6], sp->nodeName.u.wwn[7]);
149 lpfc_check_elscmpl_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
150 struct lpfc_iocbq *rspiocb)
152 struct lpfc_dmabuf *pcmd, *prsp;
157 irsp = &rspiocb->iocb;
158 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
160 /* For lpfc_els_abort, context2 could be zero'ed to delay
161 * freeing associated memory till after ABTS completes.
164 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf,
167 lp = (uint32_t *) prsp->virt;
168 ptr = (void *)((uint8_t *)lp + sizeof(uint32_t));
171 /* Force ulpStatus error since we are returning NULL ptr */
172 if (!(irsp->ulpStatus)) {
173 irsp->ulpStatus = IOSTAT_LOCAL_REJECT;
174 irsp->un.ulpWord[4] = IOERR_SLI_ABORTED;
183 * Free resources / clean up outstanding I/Os
184 * associated with a LPFC_NODELIST entry. This
185 * routine effectively results in a "software abort".
188 lpfc_els_abort(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
190 LIST_HEAD(completions);
191 struct lpfc_sli *psli = &phba->sli;
192 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
193 struct lpfc_iocbq *iocb, *next_iocb;
196 /* Abort outstanding I/O on NPort <nlp_DID> */
197 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_DISCOVERY,
198 "0205 Abort outstanding I/O on NPort x%x "
199 "Data: x%x x%x x%x\n",
200 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
203 lpfc_fabric_abort_nport(ndlp);
205 /* First check the txq */
206 spin_lock_irq(&phba->hbalock);
207 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
208 /* Check to see if iocb matches the nport we are looking for */
209 if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp)) {
210 /* It matches, so deque and call compl with anp error */
211 list_move_tail(&iocb->list, &completions);
216 /* Next check the txcmplq */
217 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
218 /* Check to see if iocb matches the nport we are looking for */
219 if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp)) {
220 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
223 spin_unlock_irq(&phba->hbalock);
225 while (!list_empty(&completions)) {
226 iocb = list_get_first(&completions, struct lpfc_iocbq, list);
228 list_del_init(&iocb->list);
230 if (!iocb->iocb_cmpl)
231 lpfc_sli_release_iocbq(phba, iocb);
233 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
234 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
235 (iocb->iocb_cmpl) (phba, iocb, iocb);
238 lpfc_cancel_retry_delay_tmo(phba->pport, ndlp);
243 lpfc_rcv_plogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
244 struct lpfc_iocbq *cmdiocb)
246 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
247 struct lpfc_hba *phba = vport->phba;
248 struct lpfc_dmabuf *pcmd;
251 struct serv_parm *sp;
256 memset(&stat, 0, sizeof (struct ls_rjt));
257 if (vport->port_state <= LPFC_FLOGI) {
258 /* Before responding to PLOGI, check for pt2pt mode.
259 * If we are pt2pt, with an outstanding FLOGI, abort
260 * the FLOGI and resend it first.
262 if (vport->fc_flag & FC_PT2PT) {
263 lpfc_els_abort_flogi(phba);
264 if (!(vport->fc_flag & FC_PT2PT_PLOGI)) {
265 /* If the other side is supposed to initiate
266 * the PLOGI anyway, just ACC it now and
267 * move on with discovery.
269 phba->fc_edtov = FF_DEF_EDTOV;
270 phba->fc_ratov = FF_DEF_RATOV;
271 /* Start discovery - this should just do
273 lpfc_disc_start(vport);
275 lpfc_initial_flogi(vport);
277 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
278 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
279 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
284 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
285 lp = (uint32_t *) pcmd->virt;
286 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
287 if (wwn_to_u64(sp->portName.u.wwn) == 0) {
288 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
289 "0140 PLOGI Reject: invalid nname\n");
290 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
291 stat.un.b.lsRjtRsnCodeExp = LSEXP_INVALID_PNAME;
292 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
296 if (wwn_to_u64(sp->nodeName.u.wwn) == 0) {
297 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
298 "0141 PLOGI Reject: invalid pname\n");
299 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
300 stat.un.b.lsRjtRsnCodeExp = LSEXP_INVALID_NNAME;
301 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
305 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3) == 0)) {
306 /* Reject this request because invalid parameters */
307 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
308 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
309 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
313 icmd = &cmdiocb->iocb;
315 /* PLOGI chkparm OK */
316 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
317 "0114 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
318 ndlp->nlp_DID, ndlp->nlp_state, ndlp->nlp_flag,
321 if (vport->cfg_fcp_class == 2 && sp->cls2.classValid)
322 ndlp->nlp_fcp_info |= CLASS2;
324 ndlp->nlp_fcp_info |= CLASS3;
326 ndlp->nlp_class_sup = 0;
327 if (sp->cls1.classValid)
328 ndlp->nlp_class_sup |= FC_COS_CLASS1;
329 if (sp->cls2.classValid)
330 ndlp->nlp_class_sup |= FC_COS_CLASS2;
331 if (sp->cls3.classValid)
332 ndlp->nlp_class_sup |= FC_COS_CLASS3;
333 if (sp->cls4.classValid)
334 ndlp->nlp_class_sup |= FC_COS_CLASS4;
336 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
338 /* no need to reg_login if we are already in one of these states */
339 switch (ndlp->nlp_state) {
340 case NLP_STE_NPR_NODE:
341 if (!(ndlp->nlp_flag & NLP_NPR_ADISC))
343 case NLP_STE_REG_LOGIN_ISSUE:
344 case NLP_STE_PRLI_ISSUE:
345 case NLP_STE_UNMAPPED_NODE:
346 case NLP_STE_MAPPED_NODE:
347 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
351 if ((vport->fc_flag & FC_PT2PT) &&
352 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
353 /* rcv'ed PLOGI decides what our NPortId will be */
354 vport->fc_myDID = icmd->un.rcvels.parmRo;
355 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
358 lpfc_config_link(phba, mbox);
359 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
361 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
362 if (rc == MBX_NOT_FINISHED) {
363 mempool_free(mbox, phba->mbox_mem_pool);
367 lpfc_can_disctmo(vport);
369 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
373 rc = lpfc_reg_login(phba, vport->vpi, icmd->un.rcvels.remoteID,
374 (uint8_t *) sp, mbox, 0);
376 mempool_free(mbox, phba->mbox_mem_pool);
380 /* ACC PLOGI rsp command needs to execute first,
381 * queue this mbox command to be processed later.
383 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
385 * mbox->context2 = lpfc_nlp_get(ndlp) deferred until mailbox
386 * command issued in lpfc_cmpl_els_acc().
389 spin_lock_irq(shost->host_lock);
390 ndlp->nlp_flag |= (NLP_ACC_REGLOGIN | NLP_RCV_PLOGI);
391 spin_unlock_irq(shost->host_lock);
394 * If there is an outstanding PLOGI issued, abort it before
395 * sending ACC rsp for received PLOGI. If pending plogi
396 * is not canceled here, the plogi will be rejected by
397 * remote port and will be retried. On a configuration with
398 * single discovery thread, this will cause a huge delay in
399 * discovery. Also this will cause multiple state machines
400 * running in parallel for this node.
402 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE) {
403 /* software abort outstanding PLOGI */
404 lpfc_els_abort(phba, ndlp);
407 if ((vport->port_type == LPFC_NPIV_PORT &&
408 vport->cfg_restrict_login)) {
410 /* In order to preserve RPIs, we want to cleanup
411 * the default RPI the firmware created to rcv
412 * this ELS request. The only way to do this is
413 * to register, then unregister the RPI.
415 spin_lock_irq(shost->host_lock);
416 ndlp->nlp_flag |= NLP_RM_DFLT_RPI;
417 spin_unlock_irq(shost->host_lock);
418 stat.un.b.lsRjtRsnCode = LSRJT_INVALID_CMD;
419 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
420 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
424 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, mbox);
427 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
428 stat.un.b.lsRjtRsnCodeExp = LSEXP_OUT_OF_RESOURCE;
429 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
434 lpfc_rcv_padisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
435 struct lpfc_iocbq *cmdiocb)
437 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
438 struct lpfc_dmabuf *pcmd;
439 struct serv_parm *sp;
440 struct lpfc_name *pnn, *ppn;
447 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
448 lp = (uint32_t *) pcmd->virt;
451 if (cmd == ELS_CMD_ADISC) {
453 pnn = (struct lpfc_name *) & ap->nodeName;
454 ppn = (struct lpfc_name *) & ap->portName;
456 sp = (struct serv_parm *) lp;
457 pnn = (struct lpfc_name *) & sp->nodeName;
458 ppn = (struct lpfc_name *) & sp->portName;
461 icmd = &cmdiocb->iocb;
462 if (icmd->ulpStatus == 0 && lpfc_check_adisc(vport, ndlp, pnn, ppn)) {
463 if (cmd == ELS_CMD_ADISC) {
464 lpfc_els_rsp_adisc_acc(vport, cmdiocb, ndlp);
466 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp,
471 /* Reject this request because invalid parameters */
472 stat.un.b.lsRjtRsvd0 = 0;
473 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
474 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
475 stat.un.b.vendorUnique = 0;
476 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
479 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
481 spin_lock_irq(shost->host_lock);
482 ndlp->nlp_flag |= NLP_DELAY_TMO;
483 spin_unlock_irq(shost->host_lock);
484 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
485 ndlp->nlp_prev_state = ndlp->nlp_state;
486 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
491 lpfc_rcv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
492 struct lpfc_iocbq *cmdiocb, uint32_t els_cmd)
494 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
496 /* Put ndlp in NPR state with 1 sec timeout for plogi, ACC logo */
497 /* Only call LOGO ACC for first LOGO, this avoids sending unnecessary
498 * PLOGIs during LOGO storms from a device.
500 spin_lock_irq(shost->host_lock);
501 ndlp->nlp_flag |= NLP_LOGO_ACC;
502 spin_unlock_irq(shost->host_lock);
503 if (els_cmd == ELS_CMD_PRLO)
504 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
506 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
508 if ((!(ndlp->nlp_type & NLP_FABRIC) &&
509 ((ndlp->nlp_type & NLP_FCP_TARGET) ||
510 !(ndlp->nlp_type & NLP_FCP_INITIATOR))) ||
511 (ndlp->nlp_state == NLP_STE_ADISC_ISSUE)) {
512 /* Only try to re-login if this is NOT a Fabric Node */
513 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
514 spin_lock_irq(shost->host_lock);
515 ndlp->nlp_flag |= NLP_DELAY_TMO;
516 spin_unlock_irq(shost->host_lock);
518 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
520 ndlp->nlp_prev_state = ndlp->nlp_state;
521 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
523 spin_lock_irq(shost->host_lock);
524 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
525 spin_unlock_irq(shost->host_lock);
526 /* The driver has to wait until the ACC completes before it continues
527 * processing the LOGO. The action will resume in
528 * lpfc_cmpl_els_logo_acc routine. Since part of processing includes an
529 * unreg_login, the driver waits so the ACC does not get aborted.
535 lpfc_rcv_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
536 struct lpfc_iocbq *cmdiocb)
538 struct lpfc_dmabuf *pcmd;
541 struct fc_rport *rport = ndlp->rport;
544 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
545 lp = (uint32_t *) pcmd->virt;
546 npr = (PRLI *) ((uint8_t *) lp + sizeof (uint32_t));
548 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
549 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
550 if (npr->prliType == PRLI_FCP_TYPE) {
551 if (npr->initiatorFunc)
552 ndlp->nlp_type |= NLP_FCP_INITIATOR;
554 ndlp->nlp_type |= NLP_FCP_TARGET;
556 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
559 /* We need to update the rport role values */
560 roles = FC_RPORT_ROLE_UNKNOWN;
561 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
562 roles |= FC_RPORT_ROLE_FCP_INITIATOR;
563 if (ndlp->nlp_type & NLP_FCP_TARGET)
564 roles |= FC_RPORT_ROLE_FCP_TARGET;
566 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
567 "rport rolechg: role:x%x did:x%x flg:x%x",
568 roles, ndlp->nlp_DID, ndlp->nlp_flag);
570 fc_remote_port_rolechg(rport, roles);
575 lpfc_disc_set_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
577 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
579 if (!ndlp->nlp_rpi) {
580 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
584 if (!(vport->fc_flag & FC_PT2PT)) {
585 /* Check config parameter use-adisc or FCP-2 */
586 if ((vport->cfg_use_adisc && (vport->fc_flag & FC_RSCN_MODE)) ||
587 ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) {
588 spin_lock_irq(shost->host_lock);
589 ndlp->nlp_flag |= NLP_NPR_ADISC;
590 spin_unlock_irq(shost->host_lock);
594 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
595 lpfc_unreg_rpi(vport, ndlp);
600 lpfc_disc_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
601 void *arg, uint32_t evt)
603 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
604 "0271 Illegal State Transition: node x%x "
605 "event x%x, state x%x Data: x%x x%x\n",
606 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
608 return ndlp->nlp_state;
612 lpfc_cmpl_plogi_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
613 void *arg, uint32_t evt)
615 /* This transition is only legal if we previously
616 * rcv'ed a PLOGI. Since we don't want 2 discovery threads
617 * working on the same NPortID, do nothing for this thread
620 if (!(ndlp->nlp_flag & NLP_RCV_PLOGI)) {
621 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
622 "0272 Illegal State Transition: node x%x "
623 "event x%x, state x%x Data: x%x x%x\n",
624 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
627 return ndlp->nlp_state;
630 /* Start of Discovery State Machine routines */
633 lpfc_rcv_plogi_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
634 void *arg, uint32_t evt)
636 struct lpfc_iocbq *cmdiocb;
638 cmdiocb = (struct lpfc_iocbq *) arg;
640 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
641 return ndlp->nlp_state;
643 return NLP_STE_FREED_NODE;
647 lpfc_rcv_els_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
648 void *arg, uint32_t evt)
650 lpfc_issue_els_logo(vport, ndlp, 0);
651 return ndlp->nlp_state;
655 lpfc_rcv_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
656 void *arg, uint32_t evt)
658 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
659 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
661 spin_lock_irq(shost->host_lock);
662 ndlp->nlp_flag |= NLP_LOGO_ACC;
663 spin_unlock_irq(shost->host_lock);
664 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
666 return ndlp->nlp_state;
670 lpfc_cmpl_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
671 void *arg, uint32_t evt)
673 return NLP_STE_FREED_NODE;
677 lpfc_device_rm_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
678 void *arg, uint32_t evt)
680 return NLP_STE_FREED_NODE;
684 lpfc_rcv_plogi_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
685 void *arg, uint32_t evt)
687 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
688 struct lpfc_hba *phba = vport->phba;
689 struct lpfc_iocbq *cmdiocb = arg;
690 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
691 uint32_t *lp = (uint32_t *) pcmd->virt;
692 struct serv_parm *sp = (struct serv_parm *) (lp + 1);
696 memset(&stat, 0, sizeof (struct ls_rjt));
698 /* For a PLOGI, we only accept if our portname is less
699 * than the remote portname.
701 phba->fc_stat.elsLogiCol++;
702 port_cmp = memcmp(&vport->fc_portname, &sp->portName,
703 sizeof(struct lpfc_name));
706 /* Reject this request because the remote node will accept
708 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
709 stat.un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
710 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
713 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb) &&
714 (ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
715 (vport->num_disc_nodes)) {
716 spin_lock_irq(shost->host_lock);
717 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
718 spin_unlock_irq(shost->host_lock);
719 /* Check if there are more PLOGIs to be sent */
720 lpfc_more_plogi(vport);
721 if (vport->num_disc_nodes == 0) {
722 spin_lock_irq(shost->host_lock);
723 vport->fc_flag &= ~FC_NDISC_ACTIVE;
724 spin_unlock_irq(shost->host_lock);
725 lpfc_can_disctmo(vport);
726 lpfc_end_rscn(vport);
729 } /* If our portname was less */
731 return ndlp->nlp_state;
735 lpfc_rcv_prli_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
736 void *arg, uint32_t evt)
738 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
741 memset(&stat, 0, sizeof (struct ls_rjt));
742 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
743 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
744 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
745 return ndlp->nlp_state;
749 lpfc_rcv_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
750 void *arg, uint32_t evt)
752 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
754 /* software abort outstanding PLOGI */
755 lpfc_els_abort(vport->phba, ndlp);
757 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
758 return ndlp->nlp_state;
762 lpfc_rcv_els_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
763 void *arg, uint32_t evt)
765 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
766 struct lpfc_hba *phba = vport->phba;
767 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
769 /* software abort outstanding PLOGI */
770 lpfc_els_abort(phba, ndlp);
772 if (evt == NLP_EVT_RCV_LOGO) {
773 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
775 lpfc_issue_els_logo(vport, ndlp, 0);
778 /* Put ndlp in npr state set plogi timer for 1 sec */
779 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
780 spin_lock_irq(shost->host_lock);
781 ndlp->nlp_flag |= NLP_DELAY_TMO;
782 spin_unlock_irq(shost->host_lock);
783 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
784 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
785 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
787 return ndlp->nlp_state;
791 lpfc_cmpl_plogi_plogi_issue(struct lpfc_vport *vport,
792 struct lpfc_nodelist *ndlp,
796 struct lpfc_hba *phba = vport->phba;
797 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
798 struct lpfc_iocbq *cmdiocb, *rspiocb;
799 struct lpfc_dmabuf *pcmd, *prsp, *mp;
802 struct serv_parm *sp;
805 cmdiocb = (struct lpfc_iocbq *) arg;
806 rspiocb = cmdiocb->context_un.rsp_iocb;
808 if (ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
809 /* Recovery from PLOGI collision logic */
810 return ndlp->nlp_state;
813 irsp = &rspiocb->iocb;
818 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
820 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
822 lp = (uint32_t *) prsp->virt;
823 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
825 /* Some switches have FDMI servers returning 0 for WWN */
826 if ((ndlp->nlp_DID != FDMI_DID) &&
827 (wwn_to_u64(sp->portName.u.wwn) == 0 ||
828 wwn_to_u64(sp->nodeName.u.wwn) == 0)) {
829 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
830 "0142 PLOGI RSP: Invalid WWN.\n");
833 if (!lpfc_check_sparm(vport, ndlp, sp, CLASS3))
835 /* PLOGI chkparm OK */
836 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
837 "0121 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
838 ndlp->nlp_DID, ndlp->nlp_state,
839 ndlp->nlp_flag, ndlp->nlp_rpi);
840 if (vport->cfg_fcp_class == 2 && (sp->cls2.classValid))
841 ndlp->nlp_fcp_info |= CLASS2;
843 ndlp->nlp_fcp_info |= CLASS3;
845 ndlp->nlp_class_sup = 0;
846 if (sp->cls1.classValid)
847 ndlp->nlp_class_sup |= FC_COS_CLASS1;
848 if (sp->cls2.classValid)
849 ndlp->nlp_class_sup |= FC_COS_CLASS2;
850 if (sp->cls3.classValid)
851 ndlp->nlp_class_sup |= FC_COS_CLASS3;
852 if (sp->cls4.classValid)
853 ndlp->nlp_class_sup |= FC_COS_CLASS4;
855 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
857 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
859 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
860 "0133 PLOGI: no memory for reg_login "
861 "Data: x%x x%x x%x x%x\n",
862 ndlp->nlp_DID, ndlp->nlp_state,
863 ndlp->nlp_flag, ndlp->nlp_rpi);
867 lpfc_unreg_rpi(vport, ndlp);
869 if (lpfc_reg_login(phba, vport->vpi, irsp->un.elsreq64.remoteID,
870 (uint8_t *) sp, mbox, 0) == 0) {
871 switch (ndlp->nlp_DID) {
873 mbox->mbox_cmpl = lpfc_mbx_cmpl_ns_reg_login;
876 mbox->mbox_cmpl = lpfc_mbx_cmpl_fdmi_reg_login;
879 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
881 mbox->context2 = lpfc_nlp_get(ndlp);
883 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
884 != MBX_NOT_FINISHED) {
885 lpfc_nlp_set_state(vport, ndlp,
886 NLP_STE_REG_LOGIN_ISSUE);
887 return ndlp->nlp_state;
889 /* decrement node reference count to the failed mbox
893 mp = (struct lpfc_dmabuf *) mbox->context1;
894 lpfc_mbuf_free(phba, mp->virt, mp->phys);
896 mempool_free(mbox, phba->mbox_mem_pool);
898 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
899 "0134 PLOGI: cannot issue reg_login "
900 "Data: x%x x%x x%x x%x\n",
901 ndlp->nlp_DID, ndlp->nlp_state,
902 ndlp->nlp_flag, ndlp->nlp_rpi);
904 mempool_free(mbox, phba->mbox_mem_pool);
906 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
907 "0135 PLOGI: cannot format reg_login "
908 "Data: x%x x%x x%x x%x\n",
909 ndlp->nlp_DID, ndlp->nlp_state,
910 ndlp->nlp_flag, ndlp->nlp_rpi);
915 if (ndlp->nlp_DID == NameServer_DID) {
916 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
917 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
918 "0261 Cannot Register NameServer login\n");
921 spin_lock_irq(shost->host_lock);
922 ndlp->nlp_flag |= NLP_DEFER_RM;
923 spin_unlock_irq(shost->host_lock);
924 return NLP_STE_FREED_NODE;
928 lpfc_cmpl_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
929 void *arg, uint32_t evt)
931 return ndlp->nlp_state;
935 lpfc_cmpl_reglogin_plogi_issue(struct lpfc_vport *vport,
936 struct lpfc_nodelist *ndlp, void *arg, uint32_t evt)
938 return ndlp->nlp_state;
942 lpfc_device_rm_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
943 void *arg, uint32_t evt)
945 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
947 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
948 spin_lock_irq(shost->host_lock);
949 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
950 spin_unlock_irq(shost->host_lock);
951 return ndlp->nlp_state;
953 /* software abort outstanding PLOGI */
954 lpfc_els_abort(vport->phba, ndlp);
956 lpfc_drop_node(vport, ndlp);
957 return NLP_STE_FREED_NODE;
962 lpfc_device_recov_plogi_issue(struct lpfc_vport *vport,
963 struct lpfc_nodelist *ndlp,
967 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
968 struct lpfc_hba *phba = vport->phba;
970 /* Don't do anything that will mess up processing of the
973 if (vport->fc_flag & FC_RSCN_DEFERRED)
974 return ndlp->nlp_state;
976 /* software abort outstanding PLOGI */
977 lpfc_els_abort(phba, ndlp);
979 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
980 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
981 spin_lock_irq(shost->host_lock);
982 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
983 spin_unlock_irq(shost->host_lock);
985 return ndlp->nlp_state;
989 lpfc_rcv_plogi_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
990 void *arg, uint32_t evt)
992 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
993 struct lpfc_hba *phba = vport->phba;
994 struct lpfc_iocbq *cmdiocb;
996 /* software abort outstanding ADISC */
997 lpfc_els_abort(phba, ndlp);
999 cmdiocb = (struct lpfc_iocbq *) arg;
1001 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
1002 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1003 spin_lock_irq(shost->host_lock);
1004 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1005 spin_unlock_irq(shost->host_lock);
1006 if (vport->num_disc_nodes)
1007 lpfc_more_adisc(vport);
1009 return ndlp->nlp_state;
1011 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1012 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
1013 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1015 return ndlp->nlp_state;
1019 lpfc_rcv_prli_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1020 void *arg, uint32_t evt)
1022 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1024 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1025 return ndlp->nlp_state;
1029 lpfc_rcv_logo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1030 void *arg, uint32_t evt)
1032 struct lpfc_hba *phba = vport->phba;
1033 struct lpfc_iocbq *cmdiocb;
1035 cmdiocb = (struct lpfc_iocbq *) arg;
1037 /* software abort outstanding ADISC */
1038 lpfc_els_abort(phba, ndlp);
1040 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1041 return ndlp->nlp_state;
1045 lpfc_rcv_padisc_adisc_issue(struct lpfc_vport *vport,
1046 struct lpfc_nodelist *ndlp,
1047 void *arg, uint32_t evt)
1049 struct lpfc_iocbq *cmdiocb;
1051 cmdiocb = (struct lpfc_iocbq *) arg;
1053 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1054 return ndlp->nlp_state;
1058 lpfc_rcv_prlo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1059 void *arg, uint32_t evt)
1061 struct lpfc_iocbq *cmdiocb;
1063 cmdiocb = (struct lpfc_iocbq *) arg;
1065 /* Treat like rcv logo */
1066 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
1067 return ndlp->nlp_state;
1071 lpfc_cmpl_adisc_adisc_issue(struct lpfc_vport *vport,
1072 struct lpfc_nodelist *ndlp,
1073 void *arg, uint32_t evt)
1075 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1076 struct lpfc_hba *phba = vport->phba;
1077 struct lpfc_iocbq *cmdiocb, *rspiocb;
1081 cmdiocb = (struct lpfc_iocbq *) arg;
1082 rspiocb = cmdiocb->context_un.rsp_iocb;
1084 ap = (ADISC *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1085 irsp = &rspiocb->iocb;
1087 if ((irsp->ulpStatus) ||
1088 (!lpfc_check_adisc(vport, ndlp, &ap->nodeName, &ap->portName))) {
1090 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
1091 spin_lock_irq(shost->host_lock);
1092 ndlp->nlp_flag |= NLP_DELAY_TMO;
1093 spin_unlock_irq(shost->host_lock);
1094 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1096 memset(&ndlp->nlp_nodename, 0, sizeof(struct lpfc_name));
1097 memset(&ndlp->nlp_portname, 0, sizeof(struct lpfc_name));
1099 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1100 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1101 lpfc_unreg_rpi(vport, ndlp);
1102 return ndlp->nlp_state;
1105 if (ndlp->nlp_type & NLP_FCP_TARGET) {
1106 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1107 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
1109 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1110 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1112 return ndlp->nlp_state;
1116 lpfc_device_rm_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1117 void *arg, uint32_t evt)
1119 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1121 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1122 spin_lock_irq(shost->host_lock);
1123 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1124 spin_unlock_irq(shost->host_lock);
1125 return ndlp->nlp_state;
1127 /* software abort outstanding ADISC */
1128 lpfc_els_abort(vport->phba, ndlp);
1130 lpfc_drop_node(vport, ndlp);
1131 return NLP_STE_FREED_NODE;
1136 lpfc_device_recov_adisc_issue(struct lpfc_vport *vport,
1137 struct lpfc_nodelist *ndlp,
1141 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1142 struct lpfc_hba *phba = vport->phba;
1144 /* Don't do anything that will mess up processing of the
1147 if (vport->fc_flag & FC_RSCN_DEFERRED)
1148 return ndlp->nlp_state;
1150 /* software abort outstanding ADISC */
1151 lpfc_els_abort(phba, ndlp);
1153 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1154 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1155 spin_lock_irq(shost->host_lock);
1156 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1157 spin_unlock_irq(shost->host_lock);
1158 lpfc_disc_set_adisc(vport, ndlp);
1159 return ndlp->nlp_state;
1163 lpfc_rcv_plogi_reglogin_issue(struct lpfc_vport *vport,
1164 struct lpfc_nodelist *ndlp,
1168 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1170 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
1171 return ndlp->nlp_state;
1175 lpfc_rcv_prli_reglogin_issue(struct lpfc_vport *vport,
1176 struct lpfc_nodelist *ndlp,
1180 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1182 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1183 return ndlp->nlp_state;
1187 lpfc_rcv_logo_reglogin_issue(struct lpfc_vport *vport,
1188 struct lpfc_nodelist *ndlp,
1192 struct lpfc_hba *phba = vport->phba;
1193 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1195 LPFC_MBOXQ_t *nextmb;
1196 struct lpfc_dmabuf *mp;
1198 cmdiocb = (struct lpfc_iocbq *) arg;
1200 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
1201 if ((mb = phba->sli.mbox_active)) {
1202 if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
1203 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1205 mb->context2 = NULL;
1206 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1210 spin_lock_irq(&phba->hbalock);
1211 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
1212 if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
1213 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1214 mp = (struct lpfc_dmabuf *) (mb->context1);
1216 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
1220 list_del(&mb->list);
1221 mempool_free(mb, phba->mbox_mem_pool);
1224 spin_unlock_irq(&phba->hbalock);
1226 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1227 return ndlp->nlp_state;
1231 lpfc_rcv_padisc_reglogin_issue(struct lpfc_vport *vport,
1232 struct lpfc_nodelist *ndlp,
1236 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1238 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1239 return ndlp->nlp_state;
1243 lpfc_rcv_prlo_reglogin_issue(struct lpfc_vport *vport,
1244 struct lpfc_nodelist *ndlp,
1248 struct lpfc_iocbq *cmdiocb;
1250 cmdiocb = (struct lpfc_iocbq *) arg;
1251 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
1252 return ndlp->nlp_state;
1256 lpfc_cmpl_reglogin_reglogin_issue(struct lpfc_vport *vport,
1257 struct lpfc_nodelist *ndlp,
1261 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1262 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1263 MAILBOX_t *mb = &pmb->mb;
1264 uint32_t did = mb->un.varWords[1];
1266 if (mb->mbxStatus) {
1267 /* RegLogin failed */
1268 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1269 "0246 RegLogin failed Data: x%x x%x x%x\n",
1270 did, mb->mbxStatus, vport->port_state);
1272 * If RegLogin failed due to lack of HBA resources do not
1275 if (mb->mbxStatus == MBXERR_RPI_FULL) {
1276 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1277 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1278 return ndlp->nlp_state;
1281 /* Put ndlp in npr state set plogi timer for 1 sec */
1282 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
1283 spin_lock_irq(shost->host_lock);
1284 ndlp->nlp_flag |= NLP_DELAY_TMO;
1285 spin_unlock_irq(shost->host_lock);
1286 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1288 lpfc_issue_els_logo(vport, ndlp, 0);
1289 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1290 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1291 return ndlp->nlp_state;
1294 ndlp->nlp_rpi = mb->un.varWords[0];
1296 /* Only if we are not a fabric nport do we issue PRLI */
1297 if (!(ndlp->nlp_type & NLP_FABRIC)) {
1298 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1299 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
1300 lpfc_issue_els_prli(vport, ndlp, 0);
1302 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1303 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1305 return ndlp->nlp_state;
1309 lpfc_device_rm_reglogin_issue(struct lpfc_vport *vport,
1310 struct lpfc_nodelist *ndlp,
1314 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1316 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1317 spin_lock_irq(shost->host_lock);
1318 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1319 spin_unlock_irq(shost->host_lock);
1320 return ndlp->nlp_state;
1322 lpfc_drop_node(vport, ndlp);
1323 return NLP_STE_FREED_NODE;
1328 lpfc_device_recov_reglogin_issue(struct lpfc_vport *vport,
1329 struct lpfc_nodelist *ndlp,
1333 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1335 /* Don't do anything that will mess up processing of the
1338 if (vport->fc_flag & FC_RSCN_DEFERRED)
1339 return ndlp->nlp_state;
1341 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1342 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1343 spin_lock_irq(shost->host_lock);
1344 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1345 spin_unlock_irq(shost->host_lock);
1346 lpfc_disc_set_adisc(vport, ndlp);
1347 return ndlp->nlp_state;
1351 lpfc_rcv_plogi_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1352 void *arg, uint32_t evt)
1354 struct lpfc_iocbq *cmdiocb;
1356 cmdiocb = (struct lpfc_iocbq *) arg;
1358 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
1359 return ndlp->nlp_state;
1363 lpfc_rcv_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1364 void *arg, uint32_t evt)
1366 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1368 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1369 return ndlp->nlp_state;
1373 lpfc_rcv_logo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1374 void *arg, uint32_t evt)
1376 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1378 /* Software abort outstanding PRLI before sending acc */
1379 lpfc_els_abort(vport->phba, ndlp);
1381 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1382 return ndlp->nlp_state;
1386 lpfc_rcv_padisc_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1387 void *arg, uint32_t evt)
1389 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1391 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1392 return ndlp->nlp_state;
1395 /* This routine is envoked when we rcv a PRLO request from a nport
1396 * we are logged into. We should send back a PRLO rsp setting the
1398 * NEXT STATE = PRLI_ISSUE
1401 lpfc_rcv_prlo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1402 void *arg, uint32_t evt)
1404 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1406 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
1407 return ndlp->nlp_state;
1411 lpfc_cmpl_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1412 void *arg, uint32_t evt)
1414 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1415 struct lpfc_iocbq *cmdiocb, *rspiocb;
1416 struct lpfc_hba *phba = vport->phba;
1420 cmdiocb = (struct lpfc_iocbq *) arg;
1421 rspiocb = cmdiocb->context_un.rsp_iocb;
1422 npr = (PRLI *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1424 irsp = &rspiocb->iocb;
1425 if (irsp->ulpStatus) {
1426 if ((vport->port_type == LPFC_NPIV_PORT) &&
1427 vport->cfg_restrict_login) {
1430 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
1431 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1432 return ndlp->nlp_state;
1435 /* Check out PRLI rsp */
1436 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
1437 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
1438 if ((npr->acceptRspCode == PRLI_REQ_EXECUTED) &&
1439 (npr->prliType == PRLI_FCP_TYPE)) {
1440 if (npr->initiatorFunc)
1441 ndlp->nlp_type |= NLP_FCP_INITIATOR;
1442 if (npr->targetFunc)
1443 ndlp->nlp_type |= NLP_FCP_TARGET;
1445 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
1447 if (!(ndlp->nlp_type & NLP_FCP_TARGET) &&
1448 (vport->port_type == LPFC_NPIV_PORT) &&
1449 vport->cfg_restrict_login) {
1451 spin_lock_irq(shost->host_lock);
1452 ndlp->nlp_flag |= NLP_TARGET_REMOVE;
1453 spin_unlock_irq(shost->host_lock);
1454 lpfc_issue_els_logo(vport, ndlp, 0);
1456 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
1457 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1458 return ndlp->nlp_state;
1461 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
1462 if (ndlp->nlp_type & NLP_FCP_TARGET)
1463 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
1465 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1466 return ndlp->nlp_state;
1469 /*! lpfc_device_rm_prli_issue
1480 * This routine is envoked when we a request to remove a nport we are in the
1481 * process of PRLIing. We should software abort outstanding prli, unreg
1482 * login, send a logout. We will change node state to UNUSED_NODE, put it
1483 * on plogi list so it can be freed when LOGO completes.
1488 lpfc_device_rm_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1489 void *arg, uint32_t evt)
1491 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1493 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1494 spin_lock_irq(shost->host_lock);
1495 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1496 spin_unlock_irq(shost->host_lock);
1497 return ndlp->nlp_state;
1499 /* software abort outstanding PLOGI */
1500 lpfc_els_abort(vport->phba, ndlp);
1502 lpfc_drop_node(vport, ndlp);
1503 return NLP_STE_FREED_NODE;
1508 /*! lpfc_device_recov_prli_issue
1519 * The routine is envoked when the state of a device is unknown, like
1520 * during a link down. We should remove the nodelist entry from the
1521 * unmapped list, issue a UNREG_LOGIN, do a software abort of the
1522 * outstanding PRLI command, then free the node entry.
1525 lpfc_device_recov_prli_issue(struct lpfc_vport *vport,
1526 struct lpfc_nodelist *ndlp,
1530 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1531 struct lpfc_hba *phba = vport->phba;
1533 /* Don't do anything that will mess up processing of the
1536 if (vport->fc_flag & FC_RSCN_DEFERRED)
1537 return ndlp->nlp_state;
1539 /* software abort outstanding PRLI */
1540 lpfc_els_abort(phba, ndlp);
1542 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
1543 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1544 spin_lock_irq(shost->host_lock);
1545 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1546 spin_unlock_irq(shost->host_lock);
1547 lpfc_disc_set_adisc(vport, ndlp);
1548 return ndlp->nlp_state;
1552 lpfc_rcv_plogi_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1553 void *arg, uint32_t evt)
1555 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1557 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
1558 return ndlp->nlp_state;
1562 lpfc_rcv_prli_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1563 void *arg, uint32_t evt)
1565 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1567 lpfc_rcv_prli(vport, ndlp, cmdiocb);
1568 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1569 return ndlp->nlp_state;
1573 lpfc_rcv_logo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1574 void *arg, uint32_t evt)
1576 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1578 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1579 return ndlp->nlp_state;
1583 lpfc_rcv_padisc_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1584 void *arg, uint32_t evt)
1586 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1588 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1589 return ndlp->nlp_state;
1593 lpfc_rcv_prlo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1594 void *arg, uint32_t evt)
1596 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1598 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
1599 return ndlp->nlp_state;
1603 lpfc_device_recov_unmap_node(struct lpfc_vport *vport,
1604 struct lpfc_nodelist *ndlp,
1608 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1610 ndlp->nlp_prev_state = NLP_STE_UNMAPPED_NODE;
1611 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1612 spin_lock_irq(shost->host_lock);
1613 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1614 spin_unlock_irq(shost->host_lock);
1615 lpfc_disc_set_adisc(vport, ndlp);
1617 return ndlp->nlp_state;
1621 lpfc_rcv_plogi_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1622 void *arg, uint32_t evt)
1624 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1626 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
1627 return ndlp->nlp_state;
1631 lpfc_rcv_prli_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1632 void *arg, uint32_t evt)
1634 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1636 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1637 return ndlp->nlp_state;
1641 lpfc_rcv_logo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1642 void *arg, uint32_t evt)
1644 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1646 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1647 return ndlp->nlp_state;
1651 lpfc_rcv_padisc_mapped_node(struct lpfc_vport *vport,
1652 struct lpfc_nodelist *ndlp,
1653 void *arg, uint32_t evt)
1655 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1657 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1658 return ndlp->nlp_state;
1662 lpfc_rcv_prlo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1663 void *arg, uint32_t evt)
1665 struct lpfc_hba *phba = vport->phba;
1666 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1668 /* flush the target */
1669 lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring],
1670 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
1672 /* Treat like rcv logo */
1673 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
1674 return ndlp->nlp_state;
1678 lpfc_device_recov_mapped_node(struct lpfc_vport *vport,
1679 struct lpfc_nodelist *ndlp,
1683 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1685 ndlp->nlp_prev_state = NLP_STE_MAPPED_NODE;
1686 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1687 spin_lock_irq(shost->host_lock);
1688 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1689 spin_unlock_irq(shost->host_lock);
1690 lpfc_disc_set_adisc(vport, ndlp);
1691 return ndlp->nlp_state;
1695 lpfc_rcv_plogi_npr_node(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 = (struct lpfc_iocbq *) arg;
1701 /* Ignore PLOGI if we have an outstanding LOGO */
1702 if (ndlp->nlp_flag & (NLP_LOGO_SND | NLP_LOGO_ACC))
1703 return ndlp->nlp_state;
1704 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
1705 lpfc_cancel_retry_delay_tmo(vport, ndlp);
1706 spin_lock_irq(shost->host_lock);
1707 ndlp->nlp_flag &= ~(NLP_NPR_ADISC | NLP_NPR_2B_DISC);
1708 spin_unlock_irq(shost->host_lock);
1709 } else if (!(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
1710 /* send PLOGI immediately, move to PLOGI issue state */
1711 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
1712 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
1713 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1714 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
1717 return ndlp->nlp_state;
1721 lpfc_rcv_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1722 void *arg, uint32_t evt)
1724 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1725 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1728 memset(&stat, 0, sizeof (struct ls_rjt));
1729 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
1730 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
1731 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
1733 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
1734 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
1735 spin_lock_irq(shost->host_lock);
1736 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1737 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
1738 spin_unlock_irq(shost->host_lock);
1739 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
1740 lpfc_issue_els_adisc(vport, ndlp, 0);
1742 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
1743 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1744 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
1747 return ndlp->nlp_state;
1751 lpfc_rcv_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1752 void *arg, uint32_t evt)
1754 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1756 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1757 return ndlp->nlp_state;
1761 lpfc_rcv_padisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1762 void *arg, uint32_t evt)
1764 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1766 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1768 * Do not start discovery if discovery is about to start
1769 * or discovery in progress for this node. Starting discovery
1770 * here will affect the counting of discovery threads.
1772 if (!(ndlp->nlp_flag & NLP_DELAY_TMO) &&
1773 !(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
1774 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
1775 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1776 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
1777 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
1778 lpfc_issue_els_adisc(vport, ndlp, 0);
1780 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
1781 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1782 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
1785 return ndlp->nlp_state;
1789 lpfc_rcv_prlo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1790 void *arg, uint32_t evt)
1792 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1793 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1795 spin_lock_irq(shost->host_lock);
1796 ndlp->nlp_flag |= NLP_LOGO_ACC;
1797 spin_unlock_irq(shost->host_lock);
1799 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
1801 if ((ndlp->nlp_flag & NLP_DELAY_TMO) == 0) {
1802 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
1803 spin_lock_irq(shost->host_lock);
1804 ndlp->nlp_flag |= NLP_DELAY_TMO;
1805 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1806 spin_unlock_irq(shost->host_lock);
1807 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1809 spin_lock_irq(shost->host_lock);
1810 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1811 spin_unlock_irq(shost->host_lock);
1813 return ndlp->nlp_state;
1817 lpfc_cmpl_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1818 void *arg, uint32_t evt)
1820 struct lpfc_iocbq *cmdiocb, *rspiocb;
1823 cmdiocb = (struct lpfc_iocbq *) arg;
1824 rspiocb = cmdiocb->context_un.rsp_iocb;
1826 irsp = &rspiocb->iocb;
1827 if (irsp->ulpStatus) {
1828 ndlp->nlp_flag |= NLP_DEFER_RM;
1829 return NLP_STE_FREED_NODE;
1831 return ndlp->nlp_state;
1835 lpfc_cmpl_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1836 void *arg, uint32_t evt)
1838 struct lpfc_iocbq *cmdiocb, *rspiocb;
1841 cmdiocb = (struct lpfc_iocbq *) arg;
1842 rspiocb = cmdiocb->context_un.rsp_iocb;
1844 irsp = &rspiocb->iocb;
1845 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
1846 lpfc_drop_node(vport, ndlp);
1847 return NLP_STE_FREED_NODE;
1849 return ndlp->nlp_state;
1853 lpfc_cmpl_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1854 void *arg, uint32_t evt)
1856 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1857 if (ndlp->nlp_DID == Fabric_DID) {
1858 spin_lock_irq(shost->host_lock);
1859 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
1860 spin_unlock_irq(shost->host_lock);
1862 lpfc_unreg_rpi(vport, ndlp);
1863 return ndlp->nlp_state;
1867 lpfc_cmpl_adisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1868 void *arg, uint32_t evt)
1870 struct lpfc_iocbq *cmdiocb, *rspiocb;
1873 cmdiocb = (struct lpfc_iocbq *) arg;
1874 rspiocb = cmdiocb->context_un.rsp_iocb;
1876 irsp = &rspiocb->iocb;
1877 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
1878 lpfc_drop_node(vport, ndlp);
1879 return NLP_STE_FREED_NODE;
1881 return ndlp->nlp_state;
1885 lpfc_cmpl_reglogin_npr_node(struct lpfc_vport *vport,
1886 struct lpfc_nodelist *ndlp,
1887 void *arg, uint32_t evt)
1889 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1890 MAILBOX_t *mb = &pmb->mb;
1893 ndlp->nlp_rpi = mb->un.varWords[0];
1895 if (ndlp->nlp_flag & NLP_NODEV_REMOVE) {
1896 lpfc_drop_node(vport, ndlp);
1897 return NLP_STE_FREED_NODE;
1900 return ndlp->nlp_state;
1904 lpfc_device_rm_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1905 void *arg, uint32_t evt)
1907 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1909 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1910 spin_lock_irq(shost->host_lock);
1911 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1912 spin_unlock_irq(shost->host_lock);
1913 return ndlp->nlp_state;
1915 lpfc_drop_node(vport, ndlp);
1916 return NLP_STE_FREED_NODE;
1920 lpfc_device_recov_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1921 void *arg, uint32_t evt)
1923 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1925 /* Don't do anything that will mess up processing of the
1928 if (vport->fc_flag & FC_RSCN_DEFERRED)
1929 return ndlp->nlp_state;
1931 spin_lock_irq(shost->host_lock);
1932 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1933 spin_unlock_irq(shost->host_lock);
1934 lpfc_cancel_retry_delay_tmo(vport, ndlp);
1935 return ndlp->nlp_state;
1939 /* This next section defines the NPort Discovery State Machine */
1941 /* There are 4 different double linked lists nodelist entries can reside on.
1942 * The plogi list and adisc list are used when Link Up discovery or RSCN
1943 * processing is needed. Each list holds the nodes that we will send PLOGI
1944 * or ADISC on. These lists will keep track of what nodes will be effected
1945 * by an RSCN, or a Link Up (Typically, all nodes are effected on Link Up).
1946 * The unmapped_list will contain all nodes that we have successfully logged
1947 * into at the Fibre Channel level. The mapped_list will contain all nodes
1948 * that are mapped FCP targets.
1951 * The bind list is a list of undiscovered (potentially non-existent) nodes
1952 * that we have saved binding information on. This information is used when
1953 * nodes transition from the unmapped to the mapped list.
1955 /* For UNUSED_NODE state, the node has just been allocated .
1956 * For PLOGI_ISSUE and REG_LOGIN_ISSUE, the node is on
1957 * the PLOGI list. For REG_LOGIN_COMPL, the node is taken off the PLOGI list
1958 * and put on the unmapped list. For ADISC processing, the node is taken off
1959 * the ADISC list and placed on either the mapped or unmapped list (depending
1960 * on its previous state). Once on the unmapped list, a PRLI is issued and the
1961 * state changed to PRLI_ISSUE. When the PRLI completion occurs, the state is
1962 * changed to UNMAPPED_NODE. If the completion indicates a mapped
1963 * node, the node is taken off the unmapped list. The binding list is checked
1964 * for a valid binding, or a binding is automatically assigned. If binding
1965 * assignment is unsuccessful, the node is left on the unmapped list. If
1966 * binding assignment is successful, the associated binding list entry (if
1967 * any) is removed, and the node is placed on the mapped list.
1970 * For a Link Down, all nodes on the ADISC, PLOGI, unmapped or mapped
1971 * lists will receive a DEVICE_RECOVERY event. If the linkdown or devloss timers
1972 * expire, all effected nodes will receive a DEVICE_RM event.
1975 * For a Link Up or RSCN, all nodes will move from the mapped / unmapped lists
1976 * to either the ADISC or PLOGI list. After a Nameserver query or ALPA loopmap
1977 * check, additional nodes may be added or removed (via DEVICE_RM) to / from
1978 * the PLOGI or ADISC lists. Once the PLOGI and ADISC lists are populated,
1979 * we will first process the ADISC list. 32 entries are processed initially and
1980 * ADISC is initited for each one. Completions / Events for each node are
1981 * funnelled thru the state machine. As each node finishes ADISC processing, it
1982 * starts ADISC for any nodes waiting for ADISC processing. If no nodes are
1983 * waiting, and the ADISC list count is identically 0, then we are done. For
1984 * Link Up discovery, since all nodes on the PLOGI list are UNREG_LOGIN'ed, we
1985 * can issue a CLEAR_LA and reenable Link Events. Next we will process the PLOGI
1986 * list. 32 entries are processed initially and PLOGI is initited for each one.
1987 * Completions / Events for each node are funnelled thru the state machine. As
1988 * each node finishes PLOGI processing, it starts PLOGI for any nodes waiting
1989 * for PLOGI processing. If no nodes are waiting, and the PLOGI list count is
1990 * indentically 0, then we are done. We have now completed discovery / RSCN
1991 * handling. Upon completion, ALL nodes should be on either the mapped or
1995 static uint32_t (*lpfc_disc_action[NLP_STE_MAX_STATE * NLP_EVT_MAX_EVENT])
1996 (struct lpfc_vport *, struct lpfc_nodelist *, void *, uint32_t) = {
1997 /* Action routine Event Current State */
1998 lpfc_rcv_plogi_unused_node, /* RCV_PLOGI UNUSED_NODE */
1999 lpfc_rcv_els_unused_node, /* RCV_PRLI */
2000 lpfc_rcv_logo_unused_node, /* RCV_LOGO */
2001 lpfc_rcv_els_unused_node, /* RCV_ADISC */
2002 lpfc_rcv_els_unused_node, /* RCV_PDISC */
2003 lpfc_rcv_els_unused_node, /* RCV_PRLO */
2004 lpfc_disc_illegal, /* CMPL_PLOGI */
2005 lpfc_disc_illegal, /* CMPL_PRLI */
2006 lpfc_cmpl_logo_unused_node, /* CMPL_LOGO */
2007 lpfc_disc_illegal, /* CMPL_ADISC */
2008 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2009 lpfc_device_rm_unused_node, /* DEVICE_RM */
2010 lpfc_disc_illegal, /* DEVICE_RECOVERY */
2012 lpfc_rcv_plogi_plogi_issue, /* RCV_PLOGI PLOGI_ISSUE */
2013 lpfc_rcv_prli_plogi_issue, /* RCV_PRLI */
2014 lpfc_rcv_logo_plogi_issue, /* RCV_LOGO */
2015 lpfc_rcv_els_plogi_issue, /* RCV_ADISC */
2016 lpfc_rcv_els_plogi_issue, /* RCV_PDISC */
2017 lpfc_rcv_els_plogi_issue, /* RCV_PRLO */
2018 lpfc_cmpl_plogi_plogi_issue, /* CMPL_PLOGI */
2019 lpfc_disc_illegal, /* CMPL_PRLI */
2020 lpfc_cmpl_logo_plogi_issue, /* CMPL_LOGO */
2021 lpfc_disc_illegal, /* CMPL_ADISC */
2022 lpfc_cmpl_reglogin_plogi_issue,/* CMPL_REG_LOGIN */
2023 lpfc_device_rm_plogi_issue, /* DEVICE_RM */
2024 lpfc_device_recov_plogi_issue, /* DEVICE_RECOVERY */
2026 lpfc_rcv_plogi_adisc_issue, /* RCV_PLOGI ADISC_ISSUE */
2027 lpfc_rcv_prli_adisc_issue, /* RCV_PRLI */
2028 lpfc_rcv_logo_adisc_issue, /* RCV_LOGO */
2029 lpfc_rcv_padisc_adisc_issue, /* RCV_ADISC */
2030 lpfc_rcv_padisc_adisc_issue, /* RCV_PDISC */
2031 lpfc_rcv_prlo_adisc_issue, /* RCV_PRLO */
2032 lpfc_disc_illegal, /* CMPL_PLOGI */
2033 lpfc_disc_illegal, /* CMPL_PRLI */
2034 lpfc_disc_illegal, /* CMPL_LOGO */
2035 lpfc_cmpl_adisc_adisc_issue, /* CMPL_ADISC */
2036 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2037 lpfc_device_rm_adisc_issue, /* DEVICE_RM */
2038 lpfc_device_recov_adisc_issue, /* DEVICE_RECOVERY */
2040 lpfc_rcv_plogi_reglogin_issue, /* RCV_PLOGI REG_LOGIN_ISSUE */
2041 lpfc_rcv_prli_reglogin_issue, /* RCV_PLOGI */
2042 lpfc_rcv_logo_reglogin_issue, /* RCV_LOGO */
2043 lpfc_rcv_padisc_reglogin_issue, /* RCV_ADISC */
2044 lpfc_rcv_padisc_reglogin_issue, /* RCV_PDISC */
2045 lpfc_rcv_prlo_reglogin_issue, /* RCV_PRLO */
2046 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
2047 lpfc_disc_illegal, /* CMPL_PRLI */
2048 lpfc_disc_illegal, /* CMPL_LOGO */
2049 lpfc_disc_illegal, /* CMPL_ADISC */
2050 lpfc_cmpl_reglogin_reglogin_issue,/* CMPL_REG_LOGIN */
2051 lpfc_device_rm_reglogin_issue, /* DEVICE_RM */
2052 lpfc_device_recov_reglogin_issue,/* DEVICE_RECOVERY */
2054 lpfc_rcv_plogi_prli_issue, /* RCV_PLOGI PRLI_ISSUE */
2055 lpfc_rcv_prli_prli_issue, /* RCV_PRLI */
2056 lpfc_rcv_logo_prli_issue, /* RCV_LOGO */
2057 lpfc_rcv_padisc_prli_issue, /* RCV_ADISC */
2058 lpfc_rcv_padisc_prli_issue, /* RCV_PDISC */
2059 lpfc_rcv_prlo_prli_issue, /* RCV_PRLO */
2060 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
2061 lpfc_cmpl_prli_prli_issue, /* CMPL_PRLI */
2062 lpfc_disc_illegal, /* CMPL_LOGO */
2063 lpfc_disc_illegal, /* CMPL_ADISC */
2064 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2065 lpfc_device_rm_prli_issue, /* DEVICE_RM */
2066 lpfc_device_recov_prli_issue, /* DEVICE_RECOVERY */
2068 lpfc_rcv_plogi_unmap_node, /* RCV_PLOGI UNMAPPED_NODE */
2069 lpfc_rcv_prli_unmap_node, /* RCV_PRLI */
2070 lpfc_rcv_logo_unmap_node, /* RCV_LOGO */
2071 lpfc_rcv_padisc_unmap_node, /* RCV_ADISC */
2072 lpfc_rcv_padisc_unmap_node, /* RCV_PDISC */
2073 lpfc_rcv_prlo_unmap_node, /* RCV_PRLO */
2074 lpfc_disc_illegal, /* CMPL_PLOGI */
2075 lpfc_disc_illegal, /* CMPL_PRLI */
2076 lpfc_disc_illegal, /* CMPL_LOGO */
2077 lpfc_disc_illegal, /* CMPL_ADISC */
2078 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2079 lpfc_disc_illegal, /* DEVICE_RM */
2080 lpfc_device_recov_unmap_node, /* DEVICE_RECOVERY */
2082 lpfc_rcv_plogi_mapped_node, /* RCV_PLOGI MAPPED_NODE */
2083 lpfc_rcv_prli_mapped_node, /* RCV_PRLI */
2084 lpfc_rcv_logo_mapped_node, /* RCV_LOGO */
2085 lpfc_rcv_padisc_mapped_node, /* RCV_ADISC */
2086 lpfc_rcv_padisc_mapped_node, /* RCV_PDISC */
2087 lpfc_rcv_prlo_mapped_node, /* RCV_PRLO */
2088 lpfc_disc_illegal, /* CMPL_PLOGI */
2089 lpfc_disc_illegal, /* CMPL_PRLI */
2090 lpfc_disc_illegal, /* CMPL_LOGO */
2091 lpfc_disc_illegal, /* CMPL_ADISC */
2092 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2093 lpfc_disc_illegal, /* DEVICE_RM */
2094 lpfc_device_recov_mapped_node, /* DEVICE_RECOVERY */
2096 lpfc_rcv_plogi_npr_node, /* RCV_PLOGI NPR_NODE */
2097 lpfc_rcv_prli_npr_node, /* RCV_PRLI */
2098 lpfc_rcv_logo_npr_node, /* RCV_LOGO */
2099 lpfc_rcv_padisc_npr_node, /* RCV_ADISC */
2100 lpfc_rcv_padisc_npr_node, /* RCV_PDISC */
2101 lpfc_rcv_prlo_npr_node, /* RCV_PRLO */
2102 lpfc_cmpl_plogi_npr_node, /* CMPL_PLOGI */
2103 lpfc_cmpl_prli_npr_node, /* CMPL_PRLI */
2104 lpfc_cmpl_logo_npr_node, /* CMPL_LOGO */
2105 lpfc_cmpl_adisc_npr_node, /* CMPL_ADISC */
2106 lpfc_cmpl_reglogin_npr_node, /* CMPL_REG_LOGIN */
2107 lpfc_device_rm_npr_node, /* DEVICE_RM */
2108 lpfc_device_recov_npr_node, /* DEVICE_RECOVERY */
2112 lpfc_disc_state_machine(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2113 void *arg, uint32_t evt)
2115 uint32_t cur_state, rc;
2116 uint32_t(*func) (struct lpfc_vport *, struct lpfc_nodelist *, void *,
2118 uint32_t got_ndlp = 0;
2120 if (lpfc_nlp_get(ndlp))
2123 cur_state = ndlp->nlp_state;
2125 /* DSM in event <evt> on NPort <nlp_DID> in state <cur_state> */
2126 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2127 "0211 DSM in event x%x on NPort x%x in "
2128 "state %d Data: x%x\n",
2129 evt, ndlp->nlp_DID, cur_state, ndlp->nlp_flag);
2131 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2132 "DSM in: evt:%d ste:%d did:x%x",
2133 evt, cur_state, ndlp->nlp_DID);
2135 func = lpfc_disc_action[(cur_state * NLP_EVT_MAX_EVENT) + evt];
2136 rc = (func) (vport, ndlp, arg, evt);
2138 /* DSM out state <rc> on NPort <nlp_DID> */
2140 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2141 "0212 DSM out state %d on NPort x%x Data: x%x\n",
2142 rc, ndlp->nlp_DID, ndlp->nlp_flag);
2144 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2145 "DSM out: ste:%d did:x%x flg:x%x",
2146 rc, ndlp->nlp_DID, ndlp->nlp_flag);
2147 /* Decrement the ndlp reference count held for this function */
2150 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2151 "0213 DSM out state %d on NPort free\n", rc);
2153 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2154 "DSM out: ste:%d did:x%x flg:x%x",