1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2007 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);
239 /* If we are delaying issuing an ELS command, cancel it */
240 if (ndlp->nlp_flag & NLP_DELAY_TMO)
241 lpfc_cancel_retry_delay_tmo(phba->pport, ndlp);
246 lpfc_rcv_plogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
247 struct lpfc_iocbq *cmdiocb)
249 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
250 struct lpfc_hba *phba = vport->phba;
251 struct lpfc_dmabuf *pcmd;
254 struct serv_parm *sp;
259 memset(&stat, 0, sizeof (struct ls_rjt));
260 if (vport->port_state <= LPFC_FLOGI) {
261 /* Before responding to PLOGI, check for pt2pt mode.
262 * If we are pt2pt, with an outstanding FLOGI, abort
263 * the FLOGI and resend it first.
265 if (vport->fc_flag & FC_PT2PT) {
266 lpfc_els_abort_flogi(phba);
267 if (!(vport->fc_flag & FC_PT2PT_PLOGI)) {
268 /* If the other side is supposed to initiate
269 * the PLOGI anyway, just ACC it now and
270 * move on with discovery.
272 phba->fc_edtov = FF_DEF_EDTOV;
273 phba->fc_ratov = FF_DEF_RATOV;
274 /* Start discovery - this should just do
276 lpfc_disc_start(vport);
278 lpfc_initial_flogi(vport);
280 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
281 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
282 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
287 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
288 lp = (uint32_t *) pcmd->virt;
289 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
290 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3) == 0)) {
291 /* Reject this request because invalid parameters */
292 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
293 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
294 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
298 icmd = &cmdiocb->iocb;
300 /* PLOGI chkparm OK */
301 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
302 "0114 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
303 ndlp->nlp_DID, ndlp->nlp_state, ndlp->nlp_flag,
306 if (vport->cfg_fcp_class == 2 && sp->cls2.classValid)
307 ndlp->nlp_fcp_info |= CLASS2;
309 ndlp->nlp_fcp_info |= CLASS3;
311 ndlp->nlp_class_sup = 0;
312 if (sp->cls1.classValid)
313 ndlp->nlp_class_sup |= FC_COS_CLASS1;
314 if (sp->cls2.classValid)
315 ndlp->nlp_class_sup |= FC_COS_CLASS2;
316 if (sp->cls3.classValid)
317 ndlp->nlp_class_sup |= FC_COS_CLASS3;
318 if (sp->cls4.classValid)
319 ndlp->nlp_class_sup |= FC_COS_CLASS4;
321 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
323 /* no need to reg_login if we are already in one of these states */
324 switch (ndlp->nlp_state) {
325 case NLP_STE_NPR_NODE:
326 if (!(ndlp->nlp_flag & NLP_NPR_ADISC))
328 case NLP_STE_REG_LOGIN_ISSUE:
329 case NLP_STE_PRLI_ISSUE:
330 case NLP_STE_UNMAPPED_NODE:
331 case NLP_STE_MAPPED_NODE:
332 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
336 if ((vport->fc_flag & FC_PT2PT) &&
337 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
338 /* rcv'ed PLOGI decides what our NPortId will be */
339 vport->fc_myDID = icmd->un.rcvels.parmRo;
340 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
343 lpfc_config_link(phba, mbox);
344 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
346 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
347 if (rc == MBX_NOT_FINISHED) {
348 mempool_free(mbox, phba->mbox_mem_pool);
352 lpfc_can_disctmo(vport);
354 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
358 rc = lpfc_reg_login(phba, vport->vpi, icmd->un.rcvels.remoteID,
359 (uint8_t *) sp, mbox, 0);
361 mempool_free(mbox, phba->mbox_mem_pool);
365 /* ACC PLOGI rsp command needs to execute first,
366 * queue this mbox command to be processed later.
368 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
370 * mbox->context2 = lpfc_nlp_get(ndlp) deferred until mailbox
371 * command issued in lpfc_cmpl_els_acc().
374 spin_lock_irq(shost->host_lock);
375 ndlp->nlp_flag |= (NLP_ACC_REGLOGIN | NLP_RCV_PLOGI);
376 spin_unlock_irq(shost->host_lock);
379 * If there is an outstanding PLOGI issued, abort it before
380 * sending ACC rsp for received PLOGI. If pending plogi
381 * is not canceled here, the plogi will be rejected by
382 * remote port and will be retried. On a configuration with
383 * single discovery thread, this will cause a huge delay in
384 * discovery. Also this will cause multiple state machines
385 * running in parallel for this node.
387 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE) {
388 /* software abort outstanding PLOGI */
389 lpfc_els_abort(phba, ndlp);
392 if ((vport->port_type == LPFC_NPIV_PORT &&
393 vport->cfg_restrict_login)) {
395 /* In order to preserve RPIs, we want to cleanup
396 * the default RPI the firmware created to rcv
397 * this ELS request. The only way to do this is
398 * to register, then unregister the RPI.
400 spin_lock_irq(shost->host_lock);
401 ndlp->nlp_flag |= NLP_RM_DFLT_RPI;
402 spin_unlock_irq(shost->host_lock);
403 stat.un.b.lsRjtRsnCode = LSRJT_INVALID_CMD;
404 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
405 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
410 /* If the remote NPort logs into us, before we can initiate
411 * discovery to them, cleanup the NPort from discovery accordingly.
413 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
414 spin_lock_irq(shost->host_lock);
415 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
416 spin_unlock_irq(shost->host_lock);
417 del_timer_sync(&ndlp->nlp_delayfunc);
418 ndlp->nlp_last_elscmd = 0;
420 if (!list_empty(&ndlp->els_retry_evt.evt_listp))
421 list_del_init(&ndlp->els_retry_evt.evt_listp);
423 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
424 spin_lock_irq(shost->host_lock);
425 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
426 spin_unlock_irq(shost->host_lock);
427 if (vport->num_disc_nodes) {
428 /* Check to see if there are more
431 lpfc_more_plogi(vport);
433 if (vport->num_disc_nodes == 0) {
434 spin_lock_irq(shost->host_lock);
435 vport->fc_flag &= ~FC_NDISC_ACTIVE;
436 spin_unlock_irq(shost->host_lock);
437 lpfc_can_disctmo(vport);
438 lpfc_end_rscn(vport);
444 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, mbox);
448 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
449 stat.un.b.lsRjtRsnCodeExp = LSEXP_OUT_OF_RESOURCE;
450 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
455 lpfc_rcv_padisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
456 struct lpfc_iocbq *cmdiocb)
458 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
459 struct lpfc_dmabuf *pcmd;
460 struct serv_parm *sp;
461 struct lpfc_name *pnn, *ppn;
468 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
469 lp = (uint32_t *) pcmd->virt;
472 if (cmd == ELS_CMD_ADISC) {
474 pnn = (struct lpfc_name *) & ap->nodeName;
475 ppn = (struct lpfc_name *) & ap->portName;
477 sp = (struct serv_parm *) lp;
478 pnn = (struct lpfc_name *) & sp->nodeName;
479 ppn = (struct lpfc_name *) & sp->portName;
482 icmd = &cmdiocb->iocb;
483 if (icmd->ulpStatus == 0 && lpfc_check_adisc(vport, ndlp, pnn, ppn)) {
484 if (cmd == ELS_CMD_ADISC) {
485 lpfc_els_rsp_adisc_acc(vport, cmdiocb, ndlp);
487 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp,
492 /* Reject this request because invalid parameters */
493 stat.un.b.lsRjtRsvd0 = 0;
494 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
495 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
496 stat.un.b.vendorUnique = 0;
497 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
500 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
502 spin_lock_irq(shost->host_lock);
503 ndlp->nlp_flag |= NLP_DELAY_TMO;
504 spin_unlock_irq(shost->host_lock);
505 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
506 ndlp->nlp_prev_state = ndlp->nlp_state;
507 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
512 lpfc_rcv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
513 struct lpfc_iocbq *cmdiocb, uint32_t els_cmd)
515 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
517 /* Put ndlp in NPR state with 1 sec timeout for plogi, ACC logo */
518 /* Only call LOGO ACC for first LOGO, this avoids sending unnecessary
519 * PLOGIs during LOGO storms from a device.
521 spin_lock_irq(shost->host_lock);
522 ndlp->nlp_flag |= NLP_LOGO_ACC;
523 spin_unlock_irq(shost->host_lock);
524 if (els_cmd == ELS_CMD_PRLO)
525 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
527 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
529 if (!(ndlp->nlp_type & NLP_FABRIC) ||
530 (ndlp->nlp_state == NLP_STE_ADISC_ISSUE)) {
531 /* Only try to re-login if this is NOT a Fabric Node */
532 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
533 spin_lock_irq(shost->host_lock);
534 ndlp->nlp_flag |= NLP_DELAY_TMO;
535 spin_unlock_irq(shost->host_lock);
537 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
539 ndlp->nlp_prev_state = ndlp->nlp_state;
540 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
542 spin_lock_irq(shost->host_lock);
543 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
544 spin_unlock_irq(shost->host_lock);
545 /* The driver has to wait until the ACC completes before it continues
546 * processing the LOGO. The action will resume in
547 * lpfc_cmpl_els_logo_acc routine. Since part of processing includes an
548 * unreg_login, the driver waits so the ACC does not get aborted.
554 lpfc_rcv_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
555 struct lpfc_iocbq *cmdiocb)
557 struct lpfc_dmabuf *pcmd;
560 struct fc_rport *rport = ndlp->rport;
563 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
564 lp = (uint32_t *) pcmd->virt;
565 npr = (PRLI *) ((uint8_t *) lp + sizeof (uint32_t));
567 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
568 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
569 if (npr->prliType == PRLI_FCP_TYPE) {
570 if (npr->initiatorFunc)
571 ndlp->nlp_type |= NLP_FCP_INITIATOR;
573 ndlp->nlp_type |= NLP_FCP_TARGET;
575 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
578 /* We need to update the rport role values */
579 roles = FC_RPORT_ROLE_UNKNOWN;
580 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
581 roles |= FC_RPORT_ROLE_FCP_INITIATOR;
582 if (ndlp->nlp_type & NLP_FCP_TARGET)
583 roles |= FC_RPORT_ROLE_FCP_TARGET;
585 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
586 "rport rolechg: role:x%x did:x%x flg:x%x",
587 roles, ndlp->nlp_DID, ndlp->nlp_flag);
589 fc_remote_port_rolechg(rport, roles);
594 lpfc_disc_set_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
596 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
598 if (!ndlp->nlp_rpi) {
599 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
603 /* Check config parameter use-adisc or FCP-2 */
604 if ((vport->cfg_use_adisc && (vport->fc_flag & FC_RSCN_MODE)) ||
605 ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) {
606 spin_lock_irq(shost->host_lock);
607 ndlp->nlp_flag |= NLP_NPR_ADISC;
608 spin_unlock_irq(shost->host_lock);
611 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
612 lpfc_unreg_rpi(vport, ndlp);
617 lpfc_disc_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
618 void *arg, uint32_t evt)
620 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
621 "0253 Illegal State Transition: node x%x "
622 "event x%x, state x%x Data: x%x x%x\n",
623 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
625 return ndlp->nlp_state;
629 lpfc_cmpl_plogi_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
630 void *arg, uint32_t evt)
632 /* This transition is only legal if we previously
633 * rcv'ed a PLOGI. Since we don't want 2 discovery threads
634 * working on the same NPortID, do nothing for this thread
637 if (!(ndlp->nlp_flag & NLP_RCV_PLOGI)) {
638 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
639 "0253 Illegal State Transition: node x%x "
640 "event x%x, state x%x Data: x%x x%x\n",
641 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
644 return ndlp->nlp_state;
647 /* Start of Discovery State Machine routines */
650 lpfc_rcv_plogi_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
651 void *arg, uint32_t evt)
653 struct lpfc_iocbq *cmdiocb;
655 cmdiocb = (struct lpfc_iocbq *) arg;
657 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
658 return ndlp->nlp_state;
660 return NLP_STE_FREED_NODE;
664 lpfc_rcv_els_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
665 void *arg, uint32_t evt)
667 lpfc_issue_els_logo(vport, ndlp, 0);
668 return ndlp->nlp_state;
672 lpfc_rcv_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
673 void *arg, uint32_t evt)
675 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
676 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
678 spin_lock_irq(shost->host_lock);
679 ndlp->nlp_flag |= NLP_LOGO_ACC;
680 spin_unlock_irq(shost->host_lock);
681 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
683 return ndlp->nlp_state;
687 lpfc_cmpl_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
688 void *arg, uint32_t evt)
690 return NLP_STE_FREED_NODE;
694 lpfc_device_rm_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
695 void *arg, uint32_t evt)
697 return NLP_STE_FREED_NODE;
701 lpfc_rcv_plogi_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
702 void *arg, uint32_t evt)
704 struct lpfc_hba *phba = vport->phba;
705 struct lpfc_iocbq *cmdiocb = arg;
706 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
707 uint32_t *lp = (uint32_t *) pcmd->virt;
708 struct serv_parm *sp = (struct serv_parm *) (lp + 1);
712 memset(&stat, 0, sizeof (struct ls_rjt));
714 /* For a PLOGI, we only accept if our portname is less
715 * than the remote portname.
717 phba->fc_stat.elsLogiCol++;
718 port_cmp = memcmp(&vport->fc_portname, &sp->portName,
719 sizeof(struct lpfc_name));
722 /* Reject this request because the remote node will accept
724 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
725 stat.un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
726 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
729 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
730 } /* If our portname was less */
732 return ndlp->nlp_state;
736 lpfc_rcv_prli_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
737 void *arg, uint32_t evt)
739 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
742 memset(&stat, 0, sizeof (struct ls_rjt));
743 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
744 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
745 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
746 return ndlp->nlp_state;
750 lpfc_rcv_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
751 void *arg, uint32_t evt)
753 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
755 /* software abort outstanding PLOGI */
756 lpfc_els_abort(vport->phba, ndlp);
758 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
759 return ndlp->nlp_state;
763 lpfc_rcv_els_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
764 void *arg, uint32_t evt)
766 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
767 struct lpfc_hba *phba = vport->phba;
768 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
770 /* software abort outstanding PLOGI */
771 lpfc_els_abort(phba, ndlp);
773 if (evt == NLP_EVT_RCV_LOGO) {
774 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
776 lpfc_issue_els_logo(vport, ndlp, 0);
779 /* Put ndlp in npr state set plogi timer for 1 sec */
780 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
781 spin_lock_irq(shost->host_lock);
782 ndlp->nlp_flag |= NLP_DELAY_TMO;
783 spin_unlock_irq(shost->host_lock);
784 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
785 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
786 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
788 return ndlp->nlp_state;
792 lpfc_cmpl_plogi_plogi_issue(struct lpfc_vport *vport,
793 struct lpfc_nodelist *ndlp,
797 struct lpfc_hba *phba = vport->phba;
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));
824 if (!lpfc_check_sparm(vport, ndlp, sp, CLASS3))
826 /* PLOGI chkparm OK */
827 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
828 "0121 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
829 ndlp->nlp_DID, ndlp->nlp_state,
830 ndlp->nlp_flag, ndlp->nlp_rpi);
831 if (vport->cfg_fcp_class == 2 && (sp->cls2.classValid))
832 ndlp->nlp_fcp_info |= CLASS2;
834 ndlp->nlp_fcp_info |= CLASS3;
836 ndlp->nlp_class_sup = 0;
837 if (sp->cls1.classValid)
838 ndlp->nlp_class_sup |= FC_COS_CLASS1;
839 if (sp->cls2.classValid)
840 ndlp->nlp_class_sup |= FC_COS_CLASS2;
841 if (sp->cls3.classValid)
842 ndlp->nlp_class_sup |= FC_COS_CLASS3;
843 if (sp->cls4.classValid)
844 ndlp->nlp_class_sup |= FC_COS_CLASS4;
846 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
848 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
850 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
851 "0133 PLOGI: no memory for reg_login "
852 "Data: x%x x%x x%x x%x\n",
853 ndlp->nlp_DID, ndlp->nlp_state,
854 ndlp->nlp_flag, ndlp->nlp_rpi);
858 lpfc_unreg_rpi(vport, ndlp);
860 if (lpfc_reg_login(phba, vport->vpi, irsp->un.elsreq64.remoteID,
861 (uint8_t *) sp, mbox, 0) == 0) {
862 switch (ndlp->nlp_DID) {
864 mbox->mbox_cmpl = lpfc_mbx_cmpl_ns_reg_login;
867 mbox->mbox_cmpl = lpfc_mbx_cmpl_fdmi_reg_login;
870 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
872 mbox->context2 = lpfc_nlp_get(ndlp);
874 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
875 != MBX_NOT_FINISHED) {
876 lpfc_nlp_set_state(vport, ndlp,
877 NLP_STE_REG_LOGIN_ISSUE);
878 return ndlp->nlp_state;
881 mp = (struct lpfc_dmabuf *) mbox->context1;
882 lpfc_mbuf_free(phba, mp->virt, mp->phys);
884 mempool_free(mbox, phba->mbox_mem_pool);
886 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
887 "0134 PLOGI: cannot issue reg_login "
888 "Data: x%x x%x x%x x%x\n",
889 ndlp->nlp_DID, ndlp->nlp_state,
890 ndlp->nlp_flag, ndlp->nlp_rpi);
892 mempool_free(mbox, phba->mbox_mem_pool);
894 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
895 "0135 PLOGI: cannot format reg_login "
896 "Data: x%x x%x x%x x%x\n",
897 ndlp->nlp_DID, ndlp->nlp_state,
898 ndlp->nlp_flag, ndlp->nlp_rpi);
903 if (ndlp->nlp_DID == NameServer_DID) {
904 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
905 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
906 "0261 Cannot Register NameServer login\n");
909 /* Free this node since the driver cannot login or has the wrong
911 lpfc_nlp_not_used(ndlp);
912 return NLP_STE_FREED_NODE;
916 lpfc_device_rm_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
917 void *arg, uint32_t evt)
919 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
921 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
922 spin_lock_irq(shost->host_lock);
923 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
924 spin_unlock_irq(shost->host_lock);
925 return ndlp->nlp_state;
927 /* software abort outstanding PLOGI */
928 lpfc_els_abort(vport->phba, ndlp);
930 lpfc_drop_node(vport, ndlp);
931 return NLP_STE_FREED_NODE;
936 lpfc_device_recov_plogi_issue(struct lpfc_vport *vport,
937 struct lpfc_nodelist *ndlp,
941 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
942 struct lpfc_hba *phba = vport->phba;
944 /* Don't do anything that will mess up processing of the
947 if (vport->fc_flag & FC_RSCN_DEFERRED)
948 return ndlp->nlp_state;
950 /* software abort outstanding PLOGI */
951 lpfc_els_abort(phba, ndlp);
953 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
954 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
955 spin_lock_irq(shost->host_lock);
956 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
957 spin_unlock_irq(shost->host_lock);
959 return ndlp->nlp_state;
963 lpfc_rcv_plogi_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
964 void *arg, uint32_t evt)
966 struct lpfc_hba *phba = vport->phba;
967 struct lpfc_iocbq *cmdiocb;
969 /* software abort outstanding ADISC */
970 lpfc_els_abort(phba, ndlp);
972 cmdiocb = (struct lpfc_iocbq *) arg;
974 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb))
975 return ndlp->nlp_state;
977 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
978 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
979 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
981 return ndlp->nlp_state;
985 lpfc_rcv_prli_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
986 void *arg, uint32_t evt)
988 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
990 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
991 return ndlp->nlp_state;
995 lpfc_rcv_logo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
996 void *arg, uint32_t evt)
998 struct lpfc_hba *phba = vport->phba;
999 struct lpfc_iocbq *cmdiocb;
1001 cmdiocb = (struct lpfc_iocbq *) arg;
1003 /* software abort outstanding ADISC */
1004 lpfc_els_abort(phba, ndlp);
1006 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1007 return ndlp->nlp_state;
1011 lpfc_rcv_padisc_adisc_issue(struct lpfc_vport *vport,
1012 struct lpfc_nodelist *ndlp,
1013 void *arg, uint32_t evt)
1015 struct lpfc_iocbq *cmdiocb;
1017 cmdiocb = (struct lpfc_iocbq *) arg;
1019 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1020 return ndlp->nlp_state;
1024 lpfc_rcv_prlo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1025 void *arg, uint32_t evt)
1027 struct lpfc_iocbq *cmdiocb;
1029 cmdiocb = (struct lpfc_iocbq *) arg;
1031 /* Treat like rcv logo */
1032 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
1033 return ndlp->nlp_state;
1037 lpfc_cmpl_adisc_adisc_issue(struct lpfc_vport *vport,
1038 struct lpfc_nodelist *ndlp,
1039 void *arg, uint32_t evt)
1041 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1042 struct lpfc_hba *phba = vport->phba;
1043 struct lpfc_iocbq *cmdiocb, *rspiocb;
1047 cmdiocb = (struct lpfc_iocbq *) arg;
1048 rspiocb = cmdiocb->context_un.rsp_iocb;
1050 ap = (ADISC *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1051 irsp = &rspiocb->iocb;
1053 if ((irsp->ulpStatus) ||
1054 (!lpfc_check_adisc(vport, ndlp, &ap->nodeName, &ap->portName))) {
1056 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
1057 spin_lock_irq(shost->host_lock);
1058 ndlp->nlp_flag |= NLP_DELAY_TMO;
1059 spin_unlock_irq(shost->host_lock);
1060 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1062 memset(&ndlp->nlp_nodename, 0, sizeof(struct lpfc_name));
1063 memset(&ndlp->nlp_portname, 0, sizeof(struct lpfc_name));
1065 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1066 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1067 lpfc_unreg_rpi(vport, ndlp);
1068 return ndlp->nlp_state;
1071 if (ndlp->nlp_type & NLP_FCP_TARGET) {
1072 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1073 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
1075 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1076 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1078 return ndlp->nlp_state;
1082 lpfc_device_rm_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1083 void *arg, uint32_t evt)
1085 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1087 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1088 spin_lock_irq(shost->host_lock);
1089 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1090 spin_unlock_irq(shost->host_lock);
1091 return ndlp->nlp_state;
1093 /* software abort outstanding ADISC */
1094 lpfc_els_abort(vport->phba, ndlp);
1096 lpfc_drop_node(vport, ndlp);
1097 return NLP_STE_FREED_NODE;
1102 lpfc_device_recov_adisc_issue(struct lpfc_vport *vport,
1103 struct lpfc_nodelist *ndlp,
1107 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1108 struct lpfc_hba *phba = vport->phba;
1110 /* Don't do anything that will mess up processing of the
1113 if (vport->fc_flag & FC_RSCN_DEFERRED)
1114 return ndlp->nlp_state;
1116 /* software abort outstanding ADISC */
1117 lpfc_els_abort(phba, ndlp);
1119 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1120 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1121 spin_lock_irq(shost->host_lock);
1122 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1123 spin_unlock_irq(shost->host_lock);
1124 lpfc_disc_set_adisc(vport, ndlp);
1125 return ndlp->nlp_state;
1129 lpfc_rcv_plogi_reglogin_issue(struct lpfc_vport *vport,
1130 struct lpfc_nodelist *ndlp,
1134 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1136 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
1137 return ndlp->nlp_state;
1141 lpfc_rcv_prli_reglogin_issue(struct lpfc_vport *vport,
1142 struct lpfc_nodelist *ndlp,
1146 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1148 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1149 return ndlp->nlp_state;
1153 lpfc_rcv_logo_reglogin_issue(struct lpfc_vport *vport,
1154 struct lpfc_nodelist *ndlp,
1158 struct lpfc_hba *phba = vport->phba;
1159 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1161 LPFC_MBOXQ_t *nextmb;
1162 struct lpfc_dmabuf *mp;
1164 cmdiocb = (struct lpfc_iocbq *) arg;
1166 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
1167 if ((mb = phba->sli.mbox_active)) {
1168 if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
1169 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1171 mb->context2 = NULL;
1172 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1176 spin_lock_irq(&phba->hbalock);
1177 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
1178 if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
1179 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1180 mp = (struct lpfc_dmabuf *) (mb->context1);
1182 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
1186 list_del(&mb->list);
1187 mempool_free(mb, phba->mbox_mem_pool);
1190 spin_unlock_irq(&phba->hbalock);
1192 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1193 return ndlp->nlp_state;
1197 lpfc_rcv_padisc_reglogin_issue(struct lpfc_vport *vport,
1198 struct lpfc_nodelist *ndlp,
1202 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1204 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1205 return ndlp->nlp_state;
1209 lpfc_rcv_prlo_reglogin_issue(struct lpfc_vport *vport,
1210 struct lpfc_nodelist *ndlp,
1214 struct lpfc_iocbq *cmdiocb;
1216 cmdiocb = (struct lpfc_iocbq *) arg;
1217 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
1218 return ndlp->nlp_state;
1222 lpfc_cmpl_reglogin_reglogin_issue(struct lpfc_vport *vport,
1223 struct lpfc_nodelist *ndlp,
1227 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1228 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1229 MAILBOX_t *mb = &pmb->mb;
1230 uint32_t did = mb->un.varWords[1];
1232 if (mb->mbxStatus) {
1233 /* RegLogin failed */
1234 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1235 "0246 RegLogin failed Data: x%x x%x x%x\n",
1236 did, mb->mbxStatus, vport->port_state);
1238 * If RegLogin failed due to lack of HBA resources do not
1241 if (mb->mbxStatus == MBXERR_RPI_FULL) {
1242 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1243 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1244 return ndlp->nlp_state;
1247 /* Put ndlp in npr state set plogi timer for 1 sec */
1248 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
1249 spin_lock_irq(shost->host_lock);
1250 ndlp->nlp_flag |= NLP_DELAY_TMO;
1251 spin_unlock_irq(shost->host_lock);
1252 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1254 lpfc_issue_els_logo(vport, ndlp, 0);
1255 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1256 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1257 return ndlp->nlp_state;
1260 ndlp->nlp_rpi = mb->un.varWords[0];
1262 /* Only if we are not a fabric nport do we issue PRLI */
1263 if (!(ndlp->nlp_type & NLP_FABRIC)) {
1264 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1265 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
1266 lpfc_issue_els_prli(vport, ndlp, 0);
1268 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1269 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1271 return ndlp->nlp_state;
1275 lpfc_device_rm_reglogin_issue(struct lpfc_vport *vport,
1276 struct lpfc_nodelist *ndlp,
1280 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1282 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1283 spin_lock_irq(shost->host_lock);
1284 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1285 spin_unlock_irq(shost->host_lock);
1286 return ndlp->nlp_state;
1288 lpfc_drop_node(vport, ndlp);
1289 return NLP_STE_FREED_NODE;
1294 lpfc_device_recov_reglogin_issue(struct lpfc_vport *vport,
1295 struct lpfc_nodelist *ndlp,
1299 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1301 /* Don't do anything that will mess up processing of the
1304 if (vport->fc_flag & FC_RSCN_DEFERRED)
1305 return ndlp->nlp_state;
1307 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1308 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1309 spin_lock_irq(shost->host_lock);
1310 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1311 spin_unlock_irq(shost->host_lock);
1312 lpfc_disc_set_adisc(vport, ndlp);
1313 return ndlp->nlp_state;
1317 lpfc_rcv_plogi_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1318 void *arg, uint32_t evt)
1320 struct lpfc_iocbq *cmdiocb;
1322 cmdiocb = (struct lpfc_iocbq *) arg;
1324 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
1325 return ndlp->nlp_state;
1329 lpfc_rcv_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1330 void *arg, uint32_t evt)
1332 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1334 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1335 return ndlp->nlp_state;
1339 lpfc_rcv_logo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1340 void *arg, uint32_t evt)
1342 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1344 /* Software abort outstanding PRLI before sending acc */
1345 lpfc_els_abort(vport->phba, ndlp);
1347 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1348 return ndlp->nlp_state;
1352 lpfc_rcv_padisc_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1353 void *arg, uint32_t evt)
1355 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1357 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1358 return ndlp->nlp_state;
1361 /* This routine is envoked when we rcv a PRLO request from a nport
1362 * we are logged into. We should send back a PRLO rsp setting the
1364 * NEXT STATE = PRLI_ISSUE
1367 lpfc_rcv_prlo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1368 void *arg, uint32_t evt)
1370 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1372 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
1373 return ndlp->nlp_state;
1377 lpfc_cmpl_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1378 void *arg, uint32_t evt)
1380 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1381 struct lpfc_iocbq *cmdiocb, *rspiocb;
1382 struct lpfc_hba *phba = vport->phba;
1386 cmdiocb = (struct lpfc_iocbq *) arg;
1387 rspiocb = cmdiocb->context_un.rsp_iocb;
1388 npr = (PRLI *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1390 irsp = &rspiocb->iocb;
1391 if (irsp->ulpStatus) {
1392 if ((vport->port_type == LPFC_NPIV_PORT) &&
1393 vport->cfg_restrict_login) {
1396 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
1397 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1398 return ndlp->nlp_state;
1401 /* Check out PRLI rsp */
1402 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
1403 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
1404 if ((npr->acceptRspCode == PRLI_REQ_EXECUTED) &&
1405 (npr->prliType == PRLI_FCP_TYPE)) {
1406 if (npr->initiatorFunc)
1407 ndlp->nlp_type |= NLP_FCP_INITIATOR;
1408 if (npr->targetFunc)
1409 ndlp->nlp_type |= NLP_FCP_TARGET;
1411 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
1413 if (!(ndlp->nlp_type & NLP_FCP_TARGET) &&
1414 (vport->port_type == LPFC_NPIV_PORT) &&
1415 vport->cfg_restrict_login) {
1417 spin_lock_irq(shost->host_lock);
1418 ndlp->nlp_flag |= NLP_TARGET_REMOVE;
1419 spin_unlock_irq(shost->host_lock);
1420 lpfc_issue_els_logo(vport, ndlp, 0);
1422 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
1423 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1424 return ndlp->nlp_state;
1427 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
1428 if (ndlp->nlp_type & NLP_FCP_TARGET)
1429 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
1431 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1432 return ndlp->nlp_state;
1435 /*! lpfc_device_rm_prli_issue
1446 * This routine is envoked when we a request to remove a nport we are in the
1447 * process of PRLIing. We should software abort outstanding prli, unreg
1448 * login, send a logout. We will change node state to UNUSED_NODE, put it
1449 * on plogi list so it can be freed when LOGO completes.
1454 lpfc_device_rm_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1455 void *arg, uint32_t evt)
1457 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1459 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1460 spin_lock_irq(shost->host_lock);
1461 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1462 spin_unlock_irq(shost->host_lock);
1463 return ndlp->nlp_state;
1465 /* software abort outstanding PLOGI */
1466 lpfc_els_abort(vport->phba, ndlp);
1468 lpfc_drop_node(vport, ndlp);
1469 return NLP_STE_FREED_NODE;
1474 /*! lpfc_device_recov_prli_issue
1485 * The routine is envoked when the state of a device is unknown, like
1486 * during a link down. We should remove the nodelist entry from the
1487 * unmapped list, issue a UNREG_LOGIN, do a software abort of the
1488 * outstanding PRLI command, then free the node entry.
1491 lpfc_device_recov_prli_issue(struct lpfc_vport *vport,
1492 struct lpfc_nodelist *ndlp,
1496 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1497 struct lpfc_hba *phba = vport->phba;
1499 /* Don't do anything that will mess up processing of the
1502 if (vport->fc_flag & FC_RSCN_DEFERRED)
1503 return ndlp->nlp_state;
1505 /* software abort outstanding PRLI */
1506 lpfc_els_abort(phba, ndlp);
1508 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
1509 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1510 spin_lock_irq(shost->host_lock);
1511 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1512 spin_unlock_irq(shost->host_lock);
1513 lpfc_disc_set_adisc(vport, ndlp);
1514 return ndlp->nlp_state;
1518 lpfc_rcv_plogi_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1519 void *arg, uint32_t evt)
1521 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1523 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
1524 return ndlp->nlp_state;
1528 lpfc_rcv_prli_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1529 void *arg, uint32_t evt)
1531 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1533 lpfc_rcv_prli(vport, ndlp, cmdiocb);
1534 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1535 return ndlp->nlp_state;
1539 lpfc_rcv_logo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1540 void *arg, uint32_t evt)
1542 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1544 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1545 return ndlp->nlp_state;
1549 lpfc_rcv_padisc_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1550 void *arg, uint32_t evt)
1552 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1554 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1555 return ndlp->nlp_state;
1559 lpfc_rcv_prlo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1560 void *arg, uint32_t evt)
1562 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1564 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
1565 return ndlp->nlp_state;
1569 lpfc_device_recov_unmap_node(struct lpfc_vport *vport,
1570 struct lpfc_nodelist *ndlp,
1574 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1576 ndlp->nlp_prev_state = NLP_STE_UNMAPPED_NODE;
1577 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1578 spin_lock_irq(shost->host_lock);
1579 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1580 spin_unlock_irq(shost->host_lock);
1581 lpfc_disc_set_adisc(vport, ndlp);
1583 return ndlp->nlp_state;
1587 lpfc_rcv_plogi_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1588 void *arg, uint32_t evt)
1590 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1592 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
1593 return ndlp->nlp_state;
1597 lpfc_rcv_prli_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1598 void *arg, uint32_t evt)
1600 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1602 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1603 return ndlp->nlp_state;
1607 lpfc_rcv_logo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1608 void *arg, uint32_t evt)
1610 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1612 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1613 return ndlp->nlp_state;
1617 lpfc_rcv_padisc_mapped_node(struct lpfc_vport *vport,
1618 struct lpfc_nodelist *ndlp,
1619 void *arg, uint32_t evt)
1621 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1623 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1624 return ndlp->nlp_state;
1628 lpfc_rcv_prlo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1629 void *arg, uint32_t evt)
1631 struct lpfc_hba *phba = vport->phba;
1632 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1634 /* flush the target */
1635 lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring],
1636 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
1638 /* Treat like rcv logo */
1639 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
1640 return ndlp->nlp_state;
1644 lpfc_device_recov_mapped_node(struct lpfc_vport *vport,
1645 struct lpfc_nodelist *ndlp,
1649 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1651 ndlp->nlp_prev_state = NLP_STE_MAPPED_NODE;
1652 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1653 spin_lock_irq(shost->host_lock);
1654 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1655 spin_unlock_irq(shost->host_lock);
1656 lpfc_disc_set_adisc(vport, ndlp);
1657 return ndlp->nlp_state;
1661 lpfc_rcv_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1662 void *arg, uint32_t evt)
1664 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1665 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1667 /* Ignore PLOGI if we have an outstanding LOGO */
1668 if (ndlp->nlp_flag & (NLP_LOGO_SND | NLP_LOGO_ACC)) {
1669 return ndlp->nlp_state;
1672 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
1673 spin_lock_irq(shost->host_lock);
1674 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1675 spin_unlock_irq(shost->host_lock);
1676 return ndlp->nlp_state;
1679 /* send PLOGI immediately, move to PLOGI issue state */
1680 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
1681 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
1682 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1683 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
1686 return ndlp->nlp_state;
1690 lpfc_rcv_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1691 void *arg, uint32_t evt)
1693 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1694 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1697 memset(&stat, 0, sizeof (struct ls_rjt));
1698 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
1699 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
1700 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
1702 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
1703 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
1704 spin_lock_irq(shost->host_lock);
1705 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1706 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
1707 spin_unlock_irq(shost->host_lock);
1708 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
1709 lpfc_issue_els_adisc(vport, ndlp, 0);
1711 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
1712 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1713 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
1716 return ndlp->nlp_state;
1720 lpfc_rcv_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1721 void *arg, uint32_t evt)
1723 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1725 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1726 return ndlp->nlp_state;
1730 lpfc_rcv_padisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1731 void *arg, uint32_t evt)
1733 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1735 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1738 * Do not start discovery if discovery is about to start
1739 * or discovery in progress for this node. Starting discovery
1740 * here will affect the counting of discovery threads.
1742 if (!(ndlp->nlp_flag & NLP_DELAY_TMO) &&
1743 !(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
1744 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
1745 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1746 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
1747 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
1748 lpfc_issue_els_adisc(vport, ndlp, 0);
1750 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
1751 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1752 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
1755 return ndlp->nlp_state;
1759 lpfc_rcv_prlo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1760 void *arg, uint32_t evt)
1762 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1763 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1765 spin_lock_irq(shost->host_lock);
1766 ndlp->nlp_flag |= NLP_LOGO_ACC;
1767 spin_unlock_irq(shost->host_lock);
1769 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
1771 if ((ndlp->nlp_flag & NLP_DELAY_TMO) == 0) {
1772 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
1773 spin_lock_irq(shost->host_lock);
1774 ndlp->nlp_flag |= NLP_DELAY_TMO;
1775 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1776 spin_unlock_irq(shost->host_lock);
1777 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1779 spin_lock_irq(shost->host_lock);
1780 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1781 spin_unlock_irq(shost->host_lock);
1783 return ndlp->nlp_state;
1787 lpfc_cmpl_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1788 void *arg, uint32_t evt)
1790 struct lpfc_iocbq *cmdiocb, *rspiocb;
1793 cmdiocb = (struct lpfc_iocbq *) arg;
1794 rspiocb = cmdiocb->context_un.rsp_iocb;
1796 irsp = &rspiocb->iocb;
1797 if (irsp->ulpStatus) {
1798 lpfc_nlp_not_used(ndlp);
1799 return NLP_STE_FREED_NODE;
1801 return ndlp->nlp_state;
1805 lpfc_cmpl_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1806 void *arg, uint32_t evt)
1808 struct lpfc_iocbq *cmdiocb, *rspiocb;
1811 cmdiocb = (struct lpfc_iocbq *) arg;
1812 rspiocb = cmdiocb->context_un.rsp_iocb;
1814 irsp = &rspiocb->iocb;
1815 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
1816 lpfc_drop_node(vport, ndlp);
1817 return NLP_STE_FREED_NODE;
1819 return ndlp->nlp_state;
1823 lpfc_cmpl_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1824 void *arg, uint32_t evt)
1826 lpfc_unreg_rpi(vport, ndlp);
1827 /* This routine does nothing, just return the current state */
1828 return ndlp->nlp_state;
1832 lpfc_cmpl_adisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1833 void *arg, uint32_t evt)
1835 struct lpfc_iocbq *cmdiocb, *rspiocb;
1838 cmdiocb = (struct lpfc_iocbq *) arg;
1839 rspiocb = cmdiocb->context_un.rsp_iocb;
1841 irsp = &rspiocb->iocb;
1842 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
1843 lpfc_drop_node(vport, ndlp);
1844 return NLP_STE_FREED_NODE;
1846 return ndlp->nlp_state;
1850 lpfc_cmpl_reglogin_npr_node(struct lpfc_vport *vport,
1851 struct lpfc_nodelist *ndlp,
1852 void *arg, uint32_t evt)
1854 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1855 MAILBOX_t *mb = &pmb->mb;
1858 ndlp->nlp_rpi = mb->un.varWords[0];
1860 if (ndlp->nlp_flag & NLP_NODEV_REMOVE) {
1861 lpfc_drop_node(vport, ndlp);
1862 return NLP_STE_FREED_NODE;
1865 return ndlp->nlp_state;
1869 lpfc_device_rm_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1870 void *arg, uint32_t evt)
1872 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1874 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1875 spin_lock_irq(shost->host_lock);
1876 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1877 spin_unlock_irq(shost->host_lock);
1878 return ndlp->nlp_state;
1880 lpfc_drop_node(vport, ndlp);
1881 return NLP_STE_FREED_NODE;
1885 lpfc_device_recov_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1886 void *arg, uint32_t evt)
1888 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1890 /* Don't do anything that will mess up processing of the
1893 if (vport->fc_flag & FC_RSCN_DEFERRED)
1894 return ndlp->nlp_state;
1896 spin_lock_irq(shost->host_lock);
1897 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1898 spin_unlock_irq(shost->host_lock);
1899 if (ndlp->nlp_flag & NLP_DELAY_TMO) {
1900 lpfc_cancel_retry_delay_tmo(vport, ndlp);
1902 return ndlp->nlp_state;
1906 /* This next section defines the NPort Discovery State Machine */
1908 /* There are 4 different double linked lists nodelist entries can reside on.
1909 * The plogi list and adisc list are used when Link Up discovery or RSCN
1910 * processing is needed. Each list holds the nodes that we will send PLOGI
1911 * or ADISC on. These lists will keep track of what nodes will be effected
1912 * by an RSCN, or a Link Up (Typically, all nodes are effected on Link Up).
1913 * The unmapped_list will contain all nodes that we have successfully logged
1914 * into at the Fibre Channel level. The mapped_list will contain all nodes
1915 * that are mapped FCP targets.
1918 * The bind list is a list of undiscovered (potentially non-existent) nodes
1919 * that we have saved binding information on. This information is used when
1920 * nodes transition from the unmapped to the mapped list.
1922 /* For UNUSED_NODE state, the node has just been allocated .
1923 * For PLOGI_ISSUE and REG_LOGIN_ISSUE, the node is on
1924 * the PLOGI list. For REG_LOGIN_COMPL, the node is taken off the PLOGI list
1925 * and put on the unmapped list. For ADISC processing, the node is taken off
1926 * the ADISC list and placed on either the mapped or unmapped list (depending
1927 * on its previous state). Once on the unmapped list, a PRLI is issued and the
1928 * state changed to PRLI_ISSUE. When the PRLI completion occurs, the state is
1929 * changed to UNMAPPED_NODE. If the completion indicates a mapped
1930 * node, the node is taken off the unmapped list. The binding list is checked
1931 * for a valid binding, or a binding is automatically assigned. If binding
1932 * assignment is unsuccessful, the node is left on the unmapped list. If
1933 * binding assignment is successful, the associated binding list entry (if
1934 * any) is removed, and the node is placed on the mapped list.
1937 * For a Link Down, all nodes on the ADISC, PLOGI, unmapped or mapped
1938 * lists will receive a DEVICE_RECOVERY event. If the linkdown or devloss timers
1939 * expire, all effected nodes will receive a DEVICE_RM event.
1942 * For a Link Up or RSCN, all nodes will move from the mapped / unmapped lists
1943 * to either the ADISC or PLOGI list. After a Nameserver query or ALPA loopmap
1944 * check, additional nodes may be added or removed (via DEVICE_RM) to / from
1945 * the PLOGI or ADISC lists. Once the PLOGI and ADISC lists are populated,
1946 * we will first process the ADISC list. 32 entries are processed initially and
1947 * ADISC is initited for each one. Completions / Events for each node are
1948 * funnelled thru the state machine. As each node finishes ADISC processing, it
1949 * starts ADISC for any nodes waiting for ADISC processing. If no nodes are
1950 * waiting, and the ADISC list count is identically 0, then we are done. For
1951 * Link Up discovery, since all nodes on the PLOGI list are UNREG_LOGIN'ed, we
1952 * can issue a CLEAR_LA and reenable Link Events. Next we will process the PLOGI
1953 * list. 32 entries are processed initially and PLOGI is initited for each one.
1954 * Completions / Events for each node are funnelled thru the state machine. As
1955 * each node finishes PLOGI processing, it starts PLOGI for any nodes waiting
1956 * for PLOGI processing. If no nodes are waiting, and the PLOGI list count is
1957 * indentically 0, then we are done. We have now completed discovery / RSCN
1958 * handling. Upon completion, ALL nodes should be on either the mapped or
1962 static uint32_t (*lpfc_disc_action[NLP_STE_MAX_STATE * NLP_EVT_MAX_EVENT])
1963 (struct lpfc_vport *, struct lpfc_nodelist *, void *, uint32_t) = {
1964 /* Action routine Event Current State */
1965 lpfc_rcv_plogi_unused_node, /* RCV_PLOGI UNUSED_NODE */
1966 lpfc_rcv_els_unused_node, /* RCV_PRLI */
1967 lpfc_rcv_logo_unused_node, /* RCV_LOGO */
1968 lpfc_rcv_els_unused_node, /* RCV_ADISC */
1969 lpfc_rcv_els_unused_node, /* RCV_PDISC */
1970 lpfc_rcv_els_unused_node, /* RCV_PRLO */
1971 lpfc_disc_illegal, /* CMPL_PLOGI */
1972 lpfc_disc_illegal, /* CMPL_PRLI */
1973 lpfc_cmpl_logo_unused_node, /* CMPL_LOGO */
1974 lpfc_disc_illegal, /* CMPL_ADISC */
1975 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
1976 lpfc_device_rm_unused_node, /* DEVICE_RM */
1977 lpfc_disc_illegal, /* DEVICE_RECOVERY */
1979 lpfc_rcv_plogi_plogi_issue, /* RCV_PLOGI PLOGI_ISSUE */
1980 lpfc_rcv_prli_plogi_issue, /* RCV_PRLI */
1981 lpfc_rcv_logo_plogi_issue, /* RCV_LOGO */
1982 lpfc_rcv_els_plogi_issue, /* RCV_ADISC */
1983 lpfc_rcv_els_plogi_issue, /* RCV_PDISC */
1984 lpfc_rcv_els_plogi_issue, /* RCV_PRLO */
1985 lpfc_cmpl_plogi_plogi_issue, /* CMPL_PLOGI */
1986 lpfc_disc_illegal, /* CMPL_PRLI */
1987 lpfc_disc_illegal, /* CMPL_LOGO */
1988 lpfc_disc_illegal, /* CMPL_ADISC */
1989 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
1990 lpfc_device_rm_plogi_issue, /* DEVICE_RM */
1991 lpfc_device_recov_plogi_issue, /* DEVICE_RECOVERY */
1993 lpfc_rcv_plogi_adisc_issue, /* RCV_PLOGI ADISC_ISSUE */
1994 lpfc_rcv_prli_adisc_issue, /* RCV_PRLI */
1995 lpfc_rcv_logo_adisc_issue, /* RCV_LOGO */
1996 lpfc_rcv_padisc_adisc_issue, /* RCV_ADISC */
1997 lpfc_rcv_padisc_adisc_issue, /* RCV_PDISC */
1998 lpfc_rcv_prlo_adisc_issue, /* RCV_PRLO */
1999 lpfc_disc_illegal, /* CMPL_PLOGI */
2000 lpfc_disc_illegal, /* CMPL_PRLI */
2001 lpfc_disc_illegal, /* CMPL_LOGO */
2002 lpfc_cmpl_adisc_adisc_issue, /* CMPL_ADISC */
2003 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2004 lpfc_device_rm_adisc_issue, /* DEVICE_RM */
2005 lpfc_device_recov_adisc_issue, /* DEVICE_RECOVERY */
2007 lpfc_rcv_plogi_reglogin_issue, /* RCV_PLOGI REG_LOGIN_ISSUE */
2008 lpfc_rcv_prli_reglogin_issue, /* RCV_PLOGI */
2009 lpfc_rcv_logo_reglogin_issue, /* RCV_LOGO */
2010 lpfc_rcv_padisc_reglogin_issue, /* RCV_ADISC */
2011 lpfc_rcv_padisc_reglogin_issue, /* RCV_PDISC */
2012 lpfc_rcv_prlo_reglogin_issue, /* RCV_PRLO */
2013 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
2014 lpfc_disc_illegal, /* CMPL_PRLI */
2015 lpfc_disc_illegal, /* CMPL_LOGO */
2016 lpfc_disc_illegal, /* CMPL_ADISC */
2017 lpfc_cmpl_reglogin_reglogin_issue,/* CMPL_REG_LOGIN */
2018 lpfc_device_rm_reglogin_issue, /* DEVICE_RM */
2019 lpfc_device_recov_reglogin_issue,/* DEVICE_RECOVERY */
2021 lpfc_rcv_plogi_prli_issue, /* RCV_PLOGI PRLI_ISSUE */
2022 lpfc_rcv_prli_prli_issue, /* RCV_PRLI */
2023 lpfc_rcv_logo_prli_issue, /* RCV_LOGO */
2024 lpfc_rcv_padisc_prli_issue, /* RCV_ADISC */
2025 lpfc_rcv_padisc_prli_issue, /* RCV_PDISC */
2026 lpfc_rcv_prlo_prli_issue, /* RCV_PRLO */
2027 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
2028 lpfc_cmpl_prli_prli_issue, /* CMPL_PRLI */
2029 lpfc_disc_illegal, /* CMPL_LOGO */
2030 lpfc_disc_illegal, /* CMPL_ADISC */
2031 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2032 lpfc_device_rm_prli_issue, /* DEVICE_RM */
2033 lpfc_device_recov_prli_issue, /* DEVICE_RECOVERY */
2035 lpfc_rcv_plogi_unmap_node, /* RCV_PLOGI UNMAPPED_NODE */
2036 lpfc_rcv_prli_unmap_node, /* RCV_PRLI */
2037 lpfc_rcv_logo_unmap_node, /* RCV_LOGO */
2038 lpfc_rcv_padisc_unmap_node, /* RCV_ADISC */
2039 lpfc_rcv_padisc_unmap_node, /* RCV_PDISC */
2040 lpfc_rcv_prlo_unmap_node, /* RCV_PRLO */
2041 lpfc_disc_illegal, /* CMPL_PLOGI */
2042 lpfc_disc_illegal, /* CMPL_PRLI */
2043 lpfc_disc_illegal, /* CMPL_LOGO */
2044 lpfc_disc_illegal, /* CMPL_ADISC */
2045 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2046 lpfc_disc_illegal, /* DEVICE_RM */
2047 lpfc_device_recov_unmap_node, /* DEVICE_RECOVERY */
2049 lpfc_rcv_plogi_mapped_node, /* RCV_PLOGI MAPPED_NODE */
2050 lpfc_rcv_prli_mapped_node, /* RCV_PRLI */
2051 lpfc_rcv_logo_mapped_node, /* RCV_LOGO */
2052 lpfc_rcv_padisc_mapped_node, /* RCV_ADISC */
2053 lpfc_rcv_padisc_mapped_node, /* RCV_PDISC */
2054 lpfc_rcv_prlo_mapped_node, /* RCV_PRLO */
2055 lpfc_disc_illegal, /* CMPL_PLOGI */
2056 lpfc_disc_illegal, /* CMPL_PRLI */
2057 lpfc_disc_illegal, /* CMPL_LOGO */
2058 lpfc_disc_illegal, /* CMPL_ADISC */
2059 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2060 lpfc_disc_illegal, /* DEVICE_RM */
2061 lpfc_device_recov_mapped_node, /* DEVICE_RECOVERY */
2063 lpfc_rcv_plogi_npr_node, /* RCV_PLOGI NPR_NODE */
2064 lpfc_rcv_prli_npr_node, /* RCV_PRLI */
2065 lpfc_rcv_logo_npr_node, /* RCV_LOGO */
2066 lpfc_rcv_padisc_npr_node, /* RCV_ADISC */
2067 lpfc_rcv_padisc_npr_node, /* RCV_PDISC */
2068 lpfc_rcv_prlo_npr_node, /* RCV_PRLO */
2069 lpfc_cmpl_plogi_npr_node, /* CMPL_PLOGI */
2070 lpfc_cmpl_prli_npr_node, /* CMPL_PRLI */
2071 lpfc_cmpl_logo_npr_node, /* CMPL_LOGO */
2072 lpfc_cmpl_adisc_npr_node, /* CMPL_ADISC */
2073 lpfc_cmpl_reglogin_npr_node, /* CMPL_REG_LOGIN */
2074 lpfc_device_rm_npr_node, /* DEVICE_RM */
2075 lpfc_device_recov_npr_node, /* DEVICE_RECOVERY */
2079 lpfc_disc_state_machine(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2080 void *arg, uint32_t evt)
2082 uint32_t cur_state, rc;
2083 uint32_t(*func) (struct lpfc_vport *, struct lpfc_nodelist *, void *,
2087 cur_state = ndlp->nlp_state;
2089 /* DSM in event <evt> on NPort <nlp_DID> in state <cur_state> */
2090 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2091 "0211 DSM in event x%x on NPort x%x in "
2092 "state %d Data: x%x\n",
2093 evt, ndlp->nlp_DID, cur_state, ndlp->nlp_flag);
2095 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2096 "DSM in: evt:%d ste:%d did:x%x",
2097 evt, cur_state, ndlp->nlp_DID);
2099 func = lpfc_disc_action[(cur_state * NLP_EVT_MAX_EVENT) + evt];
2100 rc = (func) (vport, ndlp, arg, evt);
2102 /* DSM out state <rc> on NPort <nlp_DID> */
2103 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2104 "0212 DSM out state %d on NPort x%x Data: x%x\n",
2105 rc, ndlp->nlp_DID, ndlp->nlp_flag);
2107 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2108 "DSM out: ste:%d did:x%x flg:x%x",
2109 rc, ndlp->nlp_DID, ndlp->nlp_flag);