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);
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;
252 struct lpfc_work_evt *evtp;
255 struct serv_parm *sp;
260 memset(&stat, 0, sizeof (struct ls_rjt));
261 if (vport->port_state <= LPFC_FLOGI) {
262 /* Before responding to PLOGI, check for pt2pt mode.
263 * If we are pt2pt, with an outstanding FLOGI, abort
264 * the FLOGI and resend it first.
266 if (vport->fc_flag & FC_PT2PT) {
267 lpfc_els_abort_flogi(phba);
268 if (!(vport->fc_flag & FC_PT2PT_PLOGI)) {
269 /* If the other side is supposed to initiate
270 * the PLOGI anyway, just ACC it now and
271 * move on with discovery.
273 phba->fc_edtov = FF_DEF_EDTOV;
274 phba->fc_ratov = FF_DEF_RATOV;
275 /* Start discovery - this should just do
277 lpfc_disc_start(vport);
279 lpfc_initial_flogi(vport);
281 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
282 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
283 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
288 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
289 lp = (uint32_t *) pcmd->virt;
290 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
291 if (wwn_to_u64(sp->portName.u.wwn) == 0) {
292 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
293 "0140 PLOGI Reject: invalid nname\n");
294 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
295 stat.un.b.lsRjtRsnCodeExp = LSEXP_INVALID_PNAME;
296 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
300 if (wwn_to_u64(sp->nodeName.u.wwn) == 0) {
301 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
302 "0141 PLOGI Reject: invalid pname\n");
303 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
304 stat.un.b.lsRjtRsnCodeExp = LSEXP_INVALID_NNAME;
305 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
309 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3) == 0)) {
310 /* Reject this request because invalid parameters */
311 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
312 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
313 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
317 icmd = &cmdiocb->iocb;
319 /* PLOGI chkparm OK */
320 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
321 "0114 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
322 ndlp->nlp_DID, ndlp->nlp_state, ndlp->nlp_flag,
325 if (vport->cfg_fcp_class == 2 && sp->cls2.classValid)
326 ndlp->nlp_fcp_info |= CLASS2;
328 ndlp->nlp_fcp_info |= CLASS3;
330 ndlp->nlp_class_sup = 0;
331 if (sp->cls1.classValid)
332 ndlp->nlp_class_sup |= FC_COS_CLASS1;
333 if (sp->cls2.classValid)
334 ndlp->nlp_class_sup |= FC_COS_CLASS2;
335 if (sp->cls3.classValid)
336 ndlp->nlp_class_sup |= FC_COS_CLASS3;
337 if (sp->cls4.classValid)
338 ndlp->nlp_class_sup |= FC_COS_CLASS4;
340 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
342 /* no need to reg_login if we are already in one of these states */
343 switch (ndlp->nlp_state) {
344 case NLP_STE_NPR_NODE:
345 if (!(ndlp->nlp_flag & NLP_NPR_ADISC))
347 case NLP_STE_REG_LOGIN_ISSUE:
348 case NLP_STE_PRLI_ISSUE:
349 case NLP_STE_UNMAPPED_NODE:
350 case NLP_STE_MAPPED_NODE:
351 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
355 if ((vport->fc_flag & FC_PT2PT) &&
356 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
357 /* rcv'ed PLOGI decides what our NPortId will be */
358 vport->fc_myDID = icmd->un.rcvels.parmRo;
359 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
362 lpfc_config_link(phba, mbox);
363 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
365 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
366 if (rc == MBX_NOT_FINISHED) {
367 mempool_free(mbox, phba->mbox_mem_pool);
371 lpfc_can_disctmo(vport);
373 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
377 rc = lpfc_reg_login(phba, vport->vpi, icmd->un.rcvels.remoteID,
378 (uint8_t *) sp, mbox, 0);
380 mempool_free(mbox, phba->mbox_mem_pool);
384 /* ACC PLOGI rsp command needs to execute first,
385 * queue this mbox command to be processed later.
387 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
389 * mbox->context2 = lpfc_nlp_get(ndlp) deferred until mailbox
390 * command issued in lpfc_cmpl_els_acc().
393 spin_lock_irq(shost->host_lock);
394 ndlp->nlp_flag |= (NLP_ACC_REGLOGIN | NLP_RCV_PLOGI);
395 spin_unlock_irq(shost->host_lock);
398 * If there is an outstanding PLOGI issued, abort it before
399 * sending ACC rsp for received PLOGI. If pending plogi
400 * is not canceled here, the plogi will be rejected by
401 * remote port and will be retried. On a configuration with
402 * single discovery thread, this will cause a huge delay in
403 * discovery. Also this will cause multiple state machines
404 * running in parallel for this node.
406 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE) {
407 /* software abort outstanding PLOGI */
408 lpfc_els_abort(phba, ndlp);
411 if ((vport->port_type == LPFC_NPIV_PORT &&
412 vport->cfg_restrict_login)) {
414 /* In order to preserve RPIs, we want to cleanup
415 * the default RPI the firmware created to rcv
416 * this ELS request. The only way to do this is
417 * to register, then unregister the RPI.
419 spin_lock_irq(shost->host_lock);
420 ndlp->nlp_flag |= NLP_RM_DFLT_RPI;
421 spin_unlock_irq(shost->host_lock);
422 stat.un.b.lsRjtRsnCode = LSRJT_INVALID_CMD;
423 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
424 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
429 /* If the remote NPort logs into us, before we can initiate
430 * discovery to them, cleanup the NPort from discovery accordingly.
432 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
433 spin_lock_irq(shost->host_lock);
434 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
435 spin_unlock_irq(shost->host_lock);
436 del_timer_sync(&ndlp->nlp_delayfunc);
437 ndlp->nlp_last_elscmd = 0;
439 if (!list_empty(&ndlp->els_retry_evt.evt_listp)) {
440 list_del_init(&ndlp->els_retry_evt.evt_listp);
441 /* Decrement ndlp reference count held for the
444 evtp = &ndlp->els_retry_evt;
445 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
448 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
449 spin_lock_irq(shost->host_lock);
450 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
451 spin_unlock_irq(shost->host_lock);
453 if ((ndlp->nlp_flag & NLP_ADISC_SND) &&
454 (vport->num_disc_nodes)) {
455 /* Check to see if there are more
458 lpfc_more_adisc(vport);
460 if ((vport->num_disc_nodes == 0) &&
462 lpfc_els_disc_plogi(vport);
464 if (vport->num_disc_nodes == 0) {
465 spin_lock_irq(shost->host_lock);
466 vport->fc_flag &= ~FC_NDISC_ACTIVE;
467 spin_unlock_irq(shost->host_lock);
468 lpfc_can_disctmo(vport);
469 lpfc_end_rscn(vport);
472 else if (vport->num_disc_nodes) {
473 /* Check to see if there are more
476 lpfc_more_plogi(vport);
478 if (vport->num_disc_nodes == 0) {
479 spin_lock_irq(shost->host_lock);
480 vport->fc_flag &= ~FC_NDISC_ACTIVE;
481 spin_unlock_irq(shost->host_lock);
482 lpfc_can_disctmo(vport);
483 lpfc_end_rscn(vport);
489 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, mbox);
493 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
494 stat.un.b.lsRjtRsnCodeExp = LSEXP_OUT_OF_RESOURCE;
495 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
500 lpfc_rcv_padisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
501 struct lpfc_iocbq *cmdiocb)
503 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
504 struct lpfc_dmabuf *pcmd;
505 struct serv_parm *sp;
506 struct lpfc_name *pnn, *ppn;
513 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
514 lp = (uint32_t *) pcmd->virt;
517 if (cmd == ELS_CMD_ADISC) {
519 pnn = (struct lpfc_name *) & ap->nodeName;
520 ppn = (struct lpfc_name *) & ap->portName;
522 sp = (struct serv_parm *) lp;
523 pnn = (struct lpfc_name *) & sp->nodeName;
524 ppn = (struct lpfc_name *) & sp->portName;
527 icmd = &cmdiocb->iocb;
528 if (icmd->ulpStatus == 0 && lpfc_check_adisc(vport, ndlp, pnn, ppn)) {
529 if (cmd == ELS_CMD_ADISC) {
530 lpfc_els_rsp_adisc_acc(vport, cmdiocb, ndlp);
532 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp,
537 /* Reject this request because invalid parameters */
538 stat.un.b.lsRjtRsvd0 = 0;
539 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
540 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
541 stat.un.b.vendorUnique = 0;
542 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
545 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
547 spin_lock_irq(shost->host_lock);
548 ndlp->nlp_flag |= NLP_DELAY_TMO;
549 spin_unlock_irq(shost->host_lock);
550 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
551 ndlp->nlp_prev_state = ndlp->nlp_state;
552 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
557 lpfc_rcv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
558 struct lpfc_iocbq *cmdiocb, uint32_t els_cmd)
560 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
562 /* Put ndlp in NPR state with 1 sec timeout for plogi, ACC logo */
563 /* Only call LOGO ACC for first LOGO, this avoids sending unnecessary
564 * PLOGIs during LOGO storms from a device.
566 spin_lock_irq(shost->host_lock);
567 ndlp->nlp_flag |= NLP_LOGO_ACC;
568 spin_unlock_irq(shost->host_lock);
569 if (els_cmd == ELS_CMD_PRLO)
570 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
572 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
574 if (!(ndlp->nlp_type & NLP_FABRIC) ||
575 (ndlp->nlp_state == NLP_STE_ADISC_ISSUE)) {
576 /* Only try to re-login if this is NOT a Fabric Node */
577 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
578 spin_lock_irq(shost->host_lock);
579 ndlp->nlp_flag |= NLP_DELAY_TMO;
580 spin_unlock_irq(shost->host_lock);
582 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
584 ndlp->nlp_prev_state = ndlp->nlp_state;
585 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
587 spin_lock_irq(shost->host_lock);
588 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
589 spin_unlock_irq(shost->host_lock);
590 /* The driver has to wait until the ACC completes before it continues
591 * processing the LOGO. The action will resume in
592 * lpfc_cmpl_els_logo_acc routine. Since part of processing includes an
593 * unreg_login, the driver waits so the ACC does not get aborted.
599 lpfc_rcv_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
600 struct lpfc_iocbq *cmdiocb)
602 struct lpfc_dmabuf *pcmd;
605 struct fc_rport *rport = ndlp->rport;
608 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
609 lp = (uint32_t *) pcmd->virt;
610 npr = (PRLI *) ((uint8_t *) lp + sizeof (uint32_t));
612 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
613 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
614 if (npr->prliType == PRLI_FCP_TYPE) {
615 if (npr->initiatorFunc)
616 ndlp->nlp_type |= NLP_FCP_INITIATOR;
618 ndlp->nlp_type |= NLP_FCP_TARGET;
620 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
623 /* We need to update the rport role values */
624 roles = FC_RPORT_ROLE_UNKNOWN;
625 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
626 roles |= FC_RPORT_ROLE_FCP_INITIATOR;
627 if (ndlp->nlp_type & NLP_FCP_TARGET)
628 roles |= FC_RPORT_ROLE_FCP_TARGET;
630 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
631 "rport rolechg: role:x%x did:x%x flg:x%x",
632 roles, ndlp->nlp_DID, ndlp->nlp_flag);
634 fc_remote_port_rolechg(rport, roles);
639 lpfc_disc_set_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
641 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
643 if (!ndlp->nlp_rpi) {
644 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
648 /* Check config parameter use-adisc or FCP-2 */
649 if ((vport->cfg_use_adisc && (vport->fc_flag & FC_RSCN_MODE)) ||
650 ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) {
651 spin_lock_irq(shost->host_lock);
652 ndlp->nlp_flag |= NLP_NPR_ADISC;
653 spin_unlock_irq(shost->host_lock);
656 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
657 lpfc_unreg_rpi(vport, ndlp);
662 lpfc_disc_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
663 void *arg, uint32_t evt)
665 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
666 "0271 Illegal State Transition: node x%x "
667 "event x%x, state x%x Data: x%x x%x\n",
668 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
670 return ndlp->nlp_state;
674 lpfc_cmpl_plogi_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
675 void *arg, uint32_t evt)
677 /* This transition is only legal if we previously
678 * rcv'ed a PLOGI. Since we don't want 2 discovery threads
679 * working on the same NPortID, do nothing for this thread
682 if (!(ndlp->nlp_flag & NLP_RCV_PLOGI)) {
683 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
684 "0272 Illegal State Transition: node x%x "
685 "event x%x, state x%x Data: x%x x%x\n",
686 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
689 return ndlp->nlp_state;
692 /* Start of Discovery State Machine routines */
695 lpfc_rcv_plogi_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
696 void *arg, uint32_t evt)
698 struct lpfc_iocbq *cmdiocb;
700 cmdiocb = (struct lpfc_iocbq *) arg;
702 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
703 return ndlp->nlp_state;
705 return NLP_STE_FREED_NODE;
709 lpfc_rcv_els_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
710 void *arg, uint32_t evt)
712 lpfc_issue_els_logo(vport, ndlp, 0);
713 return ndlp->nlp_state;
717 lpfc_rcv_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
718 void *arg, uint32_t evt)
720 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
721 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
723 spin_lock_irq(shost->host_lock);
724 ndlp->nlp_flag |= NLP_LOGO_ACC;
725 spin_unlock_irq(shost->host_lock);
726 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
728 return ndlp->nlp_state;
732 lpfc_cmpl_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
733 void *arg, uint32_t evt)
735 return NLP_STE_FREED_NODE;
739 lpfc_device_rm_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
740 void *arg, uint32_t evt)
742 return NLP_STE_FREED_NODE;
746 lpfc_rcv_plogi_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
747 void *arg, uint32_t evt)
749 struct lpfc_hba *phba = vport->phba;
750 struct lpfc_iocbq *cmdiocb = arg;
751 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
752 uint32_t *lp = (uint32_t *) pcmd->virt;
753 struct serv_parm *sp = (struct serv_parm *) (lp + 1);
757 memset(&stat, 0, sizeof (struct ls_rjt));
759 /* For a PLOGI, we only accept if our portname is less
760 * than the remote portname.
762 phba->fc_stat.elsLogiCol++;
763 port_cmp = memcmp(&vport->fc_portname, &sp->portName,
764 sizeof(struct lpfc_name));
767 /* Reject this request because the remote node will accept
769 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
770 stat.un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
771 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
774 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
775 } /* If our portname was less */
777 return ndlp->nlp_state;
781 lpfc_rcv_prli_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
782 void *arg, uint32_t evt)
784 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
787 memset(&stat, 0, sizeof (struct ls_rjt));
788 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
789 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
790 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
791 return ndlp->nlp_state;
795 lpfc_rcv_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
796 void *arg, uint32_t evt)
798 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
800 /* software abort outstanding PLOGI */
801 lpfc_els_abort(vport->phba, ndlp);
803 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
804 return ndlp->nlp_state;
808 lpfc_rcv_els_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
809 void *arg, uint32_t evt)
811 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
812 struct lpfc_hba *phba = vport->phba;
813 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
815 /* software abort outstanding PLOGI */
816 lpfc_els_abort(phba, ndlp);
818 if (evt == NLP_EVT_RCV_LOGO) {
819 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
821 lpfc_issue_els_logo(vport, ndlp, 0);
824 /* Put ndlp in npr state set plogi timer for 1 sec */
825 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
826 spin_lock_irq(shost->host_lock);
827 ndlp->nlp_flag |= NLP_DELAY_TMO;
828 spin_unlock_irq(shost->host_lock);
829 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
830 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
831 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
833 return ndlp->nlp_state;
837 lpfc_cmpl_plogi_plogi_issue(struct lpfc_vport *vport,
838 struct lpfc_nodelist *ndlp,
842 struct lpfc_hba *phba = vport->phba;
843 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
844 struct lpfc_iocbq *cmdiocb, *rspiocb;
845 struct lpfc_dmabuf *pcmd, *prsp, *mp;
848 struct serv_parm *sp;
851 cmdiocb = (struct lpfc_iocbq *) arg;
852 rspiocb = cmdiocb->context_un.rsp_iocb;
854 if (ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
855 /* Recovery from PLOGI collision logic */
856 return ndlp->nlp_state;
859 irsp = &rspiocb->iocb;
864 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
866 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
868 lp = (uint32_t *) prsp->virt;
869 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
870 if (wwn_to_u64(sp->portName.u.wwn) == 0 ||
871 wwn_to_u64(sp->nodeName.u.wwn) == 0) {
872 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
873 "0142 PLOGI RSP: Invalid WWN.\n");
876 if (!lpfc_check_sparm(vport, ndlp, sp, CLASS3))
878 /* PLOGI chkparm OK */
879 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
880 "0121 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
881 ndlp->nlp_DID, ndlp->nlp_state,
882 ndlp->nlp_flag, ndlp->nlp_rpi);
883 if (vport->cfg_fcp_class == 2 && (sp->cls2.classValid))
884 ndlp->nlp_fcp_info |= CLASS2;
886 ndlp->nlp_fcp_info |= CLASS3;
888 ndlp->nlp_class_sup = 0;
889 if (sp->cls1.classValid)
890 ndlp->nlp_class_sup |= FC_COS_CLASS1;
891 if (sp->cls2.classValid)
892 ndlp->nlp_class_sup |= FC_COS_CLASS2;
893 if (sp->cls3.classValid)
894 ndlp->nlp_class_sup |= FC_COS_CLASS3;
895 if (sp->cls4.classValid)
896 ndlp->nlp_class_sup |= FC_COS_CLASS4;
898 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
900 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
902 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
903 "0133 PLOGI: no memory for reg_login "
904 "Data: x%x x%x x%x x%x\n",
905 ndlp->nlp_DID, ndlp->nlp_state,
906 ndlp->nlp_flag, ndlp->nlp_rpi);
910 lpfc_unreg_rpi(vport, ndlp);
912 if (lpfc_reg_login(phba, vport->vpi, irsp->un.elsreq64.remoteID,
913 (uint8_t *) sp, mbox, 0) == 0) {
914 switch (ndlp->nlp_DID) {
916 mbox->mbox_cmpl = lpfc_mbx_cmpl_ns_reg_login;
919 mbox->mbox_cmpl = lpfc_mbx_cmpl_fdmi_reg_login;
922 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
924 mbox->context2 = lpfc_nlp_get(ndlp);
926 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
927 != MBX_NOT_FINISHED) {
928 lpfc_nlp_set_state(vport, ndlp,
929 NLP_STE_REG_LOGIN_ISSUE);
930 return ndlp->nlp_state;
932 /* decrement node reference count to the failed mbox
936 mp = (struct lpfc_dmabuf *) mbox->context1;
937 lpfc_mbuf_free(phba, mp->virt, mp->phys);
939 mempool_free(mbox, phba->mbox_mem_pool);
941 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
942 "0134 PLOGI: cannot issue reg_login "
943 "Data: x%x x%x x%x x%x\n",
944 ndlp->nlp_DID, ndlp->nlp_state,
945 ndlp->nlp_flag, ndlp->nlp_rpi);
947 mempool_free(mbox, phba->mbox_mem_pool);
949 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
950 "0135 PLOGI: cannot format reg_login "
951 "Data: x%x x%x x%x x%x\n",
952 ndlp->nlp_DID, ndlp->nlp_state,
953 ndlp->nlp_flag, ndlp->nlp_rpi);
958 if (ndlp->nlp_DID == NameServer_DID) {
959 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
960 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
961 "0261 Cannot Register NameServer login\n");
964 spin_lock_irq(shost->host_lock);
965 ndlp->nlp_flag |= NLP_DEFER_RM;
966 spin_unlock_irq(shost->host_lock);
967 return NLP_STE_FREED_NODE;
971 lpfc_cmpl_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
972 void *arg, uint32_t evt)
974 return ndlp->nlp_state;
978 lpfc_cmpl_reglogin_plogi_issue(struct lpfc_vport *vport,
979 struct lpfc_nodelist *ndlp, void *arg, uint32_t evt)
981 return ndlp->nlp_state;
985 lpfc_device_rm_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
986 void *arg, uint32_t evt)
988 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
990 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
991 spin_lock_irq(shost->host_lock);
992 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
993 spin_unlock_irq(shost->host_lock);
994 return ndlp->nlp_state;
996 /* software abort outstanding PLOGI */
997 lpfc_els_abort(vport->phba, ndlp);
999 lpfc_drop_node(vport, ndlp);
1000 return NLP_STE_FREED_NODE;
1005 lpfc_device_recov_plogi_issue(struct lpfc_vport *vport,
1006 struct lpfc_nodelist *ndlp,
1010 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1011 struct lpfc_hba *phba = vport->phba;
1013 /* Don't do anything that will mess up processing of the
1016 if (vport->fc_flag & FC_RSCN_DEFERRED)
1017 return ndlp->nlp_state;
1019 /* software abort outstanding PLOGI */
1020 lpfc_els_abort(phba, ndlp);
1022 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
1023 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1024 spin_lock_irq(shost->host_lock);
1025 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1026 spin_unlock_irq(shost->host_lock);
1028 return ndlp->nlp_state;
1032 lpfc_rcv_plogi_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1033 void *arg, uint32_t evt)
1035 struct lpfc_hba *phba = vport->phba;
1036 struct lpfc_iocbq *cmdiocb;
1038 /* software abort outstanding ADISC */
1039 lpfc_els_abort(phba, ndlp);
1041 cmdiocb = (struct lpfc_iocbq *) arg;
1043 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb))
1044 return ndlp->nlp_state;
1046 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1047 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
1048 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1050 return ndlp->nlp_state;
1054 lpfc_rcv_prli_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1055 void *arg, uint32_t evt)
1057 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1059 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1060 return ndlp->nlp_state;
1064 lpfc_rcv_logo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1065 void *arg, uint32_t evt)
1067 struct lpfc_hba *phba = vport->phba;
1068 struct lpfc_iocbq *cmdiocb;
1070 cmdiocb = (struct lpfc_iocbq *) arg;
1072 /* software abort outstanding ADISC */
1073 lpfc_els_abort(phba, ndlp);
1075 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1076 return ndlp->nlp_state;
1080 lpfc_rcv_padisc_adisc_issue(struct lpfc_vport *vport,
1081 struct lpfc_nodelist *ndlp,
1082 void *arg, uint32_t evt)
1084 struct lpfc_iocbq *cmdiocb;
1086 cmdiocb = (struct lpfc_iocbq *) arg;
1088 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1089 return ndlp->nlp_state;
1093 lpfc_rcv_prlo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1094 void *arg, uint32_t evt)
1096 struct lpfc_iocbq *cmdiocb;
1098 cmdiocb = (struct lpfc_iocbq *) arg;
1100 /* Treat like rcv logo */
1101 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
1102 return ndlp->nlp_state;
1106 lpfc_cmpl_adisc_adisc_issue(struct lpfc_vport *vport,
1107 struct lpfc_nodelist *ndlp,
1108 void *arg, uint32_t evt)
1110 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1111 struct lpfc_hba *phba = vport->phba;
1112 struct lpfc_iocbq *cmdiocb, *rspiocb;
1116 cmdiocb = (struct lpfc_iocbq *) arg;
1117 rspiocb = cmdiocb->context_un.rsp_iocb;
1119 ap = (ADISC *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1120 irsp = &rspiocb->iocb;
1122 if ((irsp->ulpStatus) ||
1123 (!lpfc_check_adisc(vport, ndlp, &ap->nodeName, &ap->portName))) {
1125 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
1126 spin_lock_irq(shost->host_lock);
1127 ndlp->nlp_flag |= NLP_DELAY_TMO;
1128 spin_unlock_irq(shost->host_lock);
1129 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1131 memset(&ndlp->nlp_nodename, 0, sizeof(struct lpfc_name));
1132 memset(&ndlp->nlp_portname, 0, sizeof(struct lpfc_name));
1134 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1135 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1136 lpfc_unreg_rpi(vport, ndlp);
1137 return ndlp->nlp_state;
1140 if (ndlp->nlp_type & NLP_FCP_TARGET) {
1141 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1142 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
1144 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1145 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1147 return ndlp->nlp_state;
1151 lpfc_device_rm_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1152 void *arg, uint32_t evt)
1154 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1156 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1157 spin_lock_irq(shost->host_lock);
1158 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1159 spin_unlock_irq(shost->host_lock);
1160 return ndlp->nlp_state;
1162 /* software abort outstanding ADISC */
1163 lpfc_els_abort(vport->phba, ndlp);
1165 lpfc_drop_node(vport, ndlp);
1166 return NLP_STE_FREED_NODE;
1171 lpfc_device_recov_adisc_issue(struct lpfc_vport *vport,
1172 struct lpfc_nodelist *ndlp,
1176 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1177 struct lpfc_hba *phba = vport->phba;
1179 /* Don't do anything that will mess up processing of the
1182 if (vport->fc_flag & FC_RSCN_DEFERRED)
1183 return ndlp->nlp_state;
1185 /* software abort outstanding ADISC */
1186 lpfc_els_abort(phba, ndlp);
1188 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1189 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1190 spin_lock_irq(shost->host_lock);
1191 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1192 spin_unlock_irq(shost->host_lock);
1193 lpfc_disc_set_adisc(vport, ndlp);
1194 return ndlp->nlp_state;
1198 lpfc_rcv_plogi_reglogin_issue(struct lpfc_vport *vport,
1199 struct lpfc_nodelist *ndlp,
1203 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1205 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
1206 return ndlp->nlp_state;
1210 lpfc_rcv_prli_reglogin_issue(struct lpfc_vport *vport,
1211 struct lpfc_nodelist *ndlp,
1215 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1217 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1218 return ndlp->nlp_state;
1222 lpfc_rcv_logo_reglogin_issue(struct lpfc_vport *vport,
1223 struct lpfc_nodelist *ndlp,
1227 struct lpfc_hba *phba = vport->phba;
1228 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1230 LPFC_MBOXQ_t *nextmb;
1231 struct lpfc_dmabuf *mp;
1233 cmdiocb = (struct lpfc_iocbq *) arg;
1235 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
1236 if ((mb = phba->sli.mbox_active)) {
1237 if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
1238 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1240 mb->context2 = NULL;
1241 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1245 spin_lock_irq(&phba->hbalock);
1246 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
1247 if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
1248 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1249 mp = (struct lpfc_dmabuf *) (mb->context1);
1251 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
1255 list_del(&mb->list);
1256 mempool_free(mb, phba->mbox_mem_pool);
1259 spin_unlock_irq(&phba->hbalock);
1261 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1262 return ndlp->nlp_state;
1266 lpfc_rcv_padisc_reglogin_issue(struct lpfc_vport *vport,
1267 struct lpfc_nodelist *ndlp,
1271 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1273 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1274 return ndlp->nlp_state;
1278 lpfc_rcv_prlo_reglogin_issue(struct lpfc_vport *vport,
1279 struct lpfc_nodelist *ndlp,
1283 struct lpfc_iocbq *cmdiocb;
1285 cmdiocb = (struct lpfc_iocbq *) arg;
1286 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
1287 return ndlp->nlp_state;
1291 lpfc_cmpl_reglogin_reglogin_issue(struct lpfc_vport *vport,
1292 struct lpfc_nodelist *ndlp,
1296 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1297 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1298 MAILBOX_t *mb = &pmb->mb;
1299 uint32_t did = mb->un.varWords[1];
1301 if (mb->mbxStatus) {
1302 /* RegLogin failed */
1303 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1304 "0246 RegLogin failed Data: x%x x%x x%x\n",
1305 did, mb->mbxStatus, vport->port_state);
1307 * If RegLogin failed due to lack of HBA resources do not
1310 if (mb->mbxStatus == MBXERR_RPI_FULL) {
1311 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1312 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1313 return ndlp->nlp_state;
1316 /* Put ndlp in npr state set plogi timer for 1 sec */
1317 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
1318 spin_lock_irq(shost->host_lock);
1319 ndlp->nlp_flag |= NLP_DELAY_TMO;
1320 spin_unlock_irq(shost->host_lock);
1321 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1323 lpfc_issue_els_logo(vport, ndlp, 0);
1324 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1325 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1326 return ndlp->nlp_state;
1329 ndlp->nlp_rpi = mb->un.varWords[0];
1331 /* Only if we are not a fabric nport do we issue PRLI */
1332 if (!(ndlp->nlp_type & NLP_FABRIC)) {
1333 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1334 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
1335 lpfc_issue_els_prli(vport, ndlp, 0);
1337 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1338 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1340 return ndlp->nlp_state;
1344 lpfc_device_rm_reglogin_issue(struct lpfc_vport *vport,
1345 struct lpfc_nodelist *ndlp,
1349 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1351 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1352 spin_lock_irq(shost->host_lock);
1353 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1354 spin_unlock_irq(shost->host_lock);
1355 return ndlp->nlp_state;
1357 lpfc_drop_node(vport, ndlp);
1358 return NLP_STE_FREED_NODE;
1363 lpfc_device_recov_reglogin_issue(struct lpfc_vport *vport,
1364 struct lpfc_nodelist *ndlp,
1368 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1370 /* Don't do anything that will mess up processing of the
1373 if (vport->fc_flag & FC_RSCN_DEFERRED)
1374 return ndlp->nlp_state;
1376 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1377 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1378 spin_lock_irq(shost->host_lock);
1379 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1380 spin_unlock_irq(shost->host_lock);
1381 lpfc_disc_set_adisc(vport, ndlp);
1382 return ndlp->nlp_state;
1386 lpfc_rcv_plogi_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1387 void *arg, uint32_t evt)
1389 struct lpfc_iocbq *cmdiocb;
1391 cmdiocb = (struct lpfc_iocbq *) arg;
1393 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
1394 return ndlp->nlp_state;
1398 lpfc_rcv_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1399 void *arg, uint32_t evt)
1401 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1403 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1404 return ndlp->nlp_state;
1408 lpfc_rcv_logo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1409 void *arg, uint32_t evt)
1411 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1413 /* Software abort outstanding PRLI before sending acc */
1414 lpfc_els_abort(vport->phba, ndlp);
1416 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1417 return ndlp->nlp_state;
1421 lpfc_rcv_padisc_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1422 void *arg, uint32_t evt)
1424 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1426 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1427 return ndlp->nlp_state;
1430 /* This routine is envoked when we rcv a PRLO request from a nport
1431 * we are logged into. We should send back a PRLO rsp setting the
1433 * NEXT STATE = PRLI_ISSUE
1436 lpfc_rcv_prlo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1437 void *arg, uint32_t evt)
1439 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1441 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
1442 return ndlp->nlp_state;
1446 lpfc_cmpl_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1447 void *arg, uint32_t evt)
1449 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1450 struct lpfc_iocbq *cmdiocb, *rspiocb;
1451 struct lpfc_hba *phba = vport->phba;
1455 cmdiocb = (struct lpfc_iocbq *) arg;
1456 rspiocb = cmdiocb->context_un.rsp_iocb;
1457 npr = (PRLI *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1459 irsp = &rspiocb->iocb;
1460 if (irsp->ulpStatus) {
1461 if ((vport->port_type == LPFC_NPIV_PORT) &&
1462 vport->cfg_restrict_login) {
1465 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
1466 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1467 return ndlp->nlp_state;
1470 /* Check out PRLI rsp */
1471 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
1472 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
1473 if ((npr->acceptRspCode == PRLI_REQ_EXECUTED) &&
1474 (npr->prliType == PRLI_FCP_TYPE)) {
1475 if (npr->initiatorFunc)
1476 ndlp->nlp_type |= NLP_FCP_INITIATOR;
1477 if (npr->targetFunc)
1478 ndlp->nlp_type |= NLP_FCP_TARGET;
1480 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
1482 if (!(ndlp->nlp_type & NLP_FCP_TARGET) &&
1483 (vport->port_type == LPFC_NPIV_PORT) &&
1484 vport->cfg_restrict_login) {
1486 spin_lock_irq(shost->host_lock);
1487 ndlp->nlp_flag |= NLP_TARGET_REMOVE;
1488 spin_unlock_irq(shost->host_lock);
1489 lpfc_issue_els_logo(vport, ndlp, 0);
1491 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
1492 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1493 return ndlp->nlp_state;
1496 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
1497 if (ndlp->nlp_type & NLP_FCP_TARGET)
1498 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
1500 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1501 return ndlp->nlp_state;
1504 /*! lpfc_device_rm_prli_issue
1515 * This routine is envoked when we a request to remove a nport we are in the
1516 * process of PRLIing. We should software abort outstanding prli, unreg
1517 * login, send a logout. We will change node state to UNUSED_NODE, put it
1518 * on plogi list so it can be freed when LOGO completes.
1523 lpfc_device_rm_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1524 void *arg, uint32_t evt)
1526 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1528 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1529 spin_lock_irq(shost->host_lock);
1530 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1531 spin_unlock_irq(shost->host_lock);
1532 return ndlp->nlp_state;
1534 /* software abort outstanding PLOGI */
1535 lpfc_els_abort(vport->phba, ndlp);
1537 lpfc_drop_node(vport, ndlp);
1538 return NLP_STE_FREED_NODE;
1543 /*! lpfc_device_recov_prli_issue
1554 * The routine is envoked when the state of a device is unknown, like
1555 * during a link down. We should remove the nodelist entry from the
1556 * unmapped list, issue a UNREG_LOGIN, do a software abort of the
1557 * outstanding PRLI command, then free the node entry.
1560 lpfc_device_recov_prli_issue(struct lpfc_vport *vport,
1561 struct lpfc_nodelist *ndlp,
1565 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1566 struct lpfc_hba *phba = vport->phba;
1568 /* Don't do anything that will mess up processing of the
1571 if (vport->fc_flag & FC_RSCN_DEFERRED)
1572 return ndlp->nlp_state;
1574 /* software abort outstanding PRLI */
1575 lpfc_els_abort(phba, ndlp);
1577 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
1578 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1579 spin_lock_irq(shost->host_lock);
1580 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1581 spin_unlock_irq(shost->host_lock);
1582 lpfc_disc_set_adisc(vport, ndlp);
1583 return ndlp->nlp_state;
1587 lpfc_rcv_plogi_unmap_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_unmap_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_rcv_prli(vport, ndlp, cmdiocb);
1603 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1604 return ndlp->nlp_state;
1608 lpfc_rcv_logo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1609 void *arg, uint32_t evt)
1611 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1613 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1614 return ndlp->nlp_state;
1618 lpfc_rcv_padisc_unmap_node(struct lpfc_vport *vport, 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_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1629 void *arg, uint32_t evt)
1631 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1633 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
1634 return ndlp->nlp_state;
1638 lpfc_device_recov_unmap_node(struct lpfc_vport *vport,
1639 struct lpfc_nodelist *ndlp,
1643 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1645 ndlp->nlp_prev_state = NLP_STE_UNMAPPED_NODE;
1646 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1647 spin_lock_irq(shost->host_lock);
1648 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1649 spin_unlock_irq(shost->host_lock);
1650 lpfc_disc_set_adisc(vport, ndlp);
1652 return ndlp->nlp_state;
1656 lpfc_rcv_plogi_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1657 void *arg, uint32_t evt)
1659 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1661 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
1662 return ndlp->nlp_state;
1666 lpfc_rcv_prli_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1667 void *arg, uint32_t evt)
1669 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1671 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1672 return ndlp->nlp_state;
1676 lpfc_rcv_logo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1677 void *arg, uint32_t evt)
1679 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1681 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1682 return ndlp->nlp_state;
1686 lpfc_rcv_padisc_mapped_node(struct lpfc_vport *vport,
1687 struct lpfc_nodelist *ndlp,
1688 void *arg, uint32_t evt)
1690 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1692 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1693 return ndlp->nlp_state;
1697 lpfc_rcv_prlo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1698 void *arg, uint32_t evt)
1700 struct lpfc_hba *phba = vport->phba;
1701 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1703 /* flush the target */
1704 lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring],
1705 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
1707 /* Treat like rcv logo */
1708 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
1709 return ndlp->nlp_state;
1713 lpfc_device_recov_mapped_node(struct lpfc_vport *vport,
1714 struct lpfc_nodelist *ndlp,
1718 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1720 ndlp->nlp_prev_state = NLP_STE_MAPPED_NODE;
1721 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1722 spin_lock_irq(shost->host_lock);
1723 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1724 spin_unlock_irq(shost->host_lock);
1725 lpfc_disc_set_adisc(vport, ndlp);
1726 return ndlp->nlp_state;
1730 lpfc_rcv_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1731 void *arg, uint32_t evt)
1733 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1734 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1736 /* Ignore PLOGI if we have an outstanding LOGO */
1737 if (ndlp->nlp_flag & (NLP_LOGO_SND | NLP_LOGO_ACC)) {
1738 return ndlp->nlp_state;
1741 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
1742 spin_lock_irq(shost->host_lock);
1743 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1744 spin_unlock_irq(shost->host_lock);
1745 return ndlp->nlp_state;
1748 /* send PLOGI immediately, move to PLOGI issue state */
1749 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
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_prli_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;
1766 memset(&stat, 0, sizeof (struct ls_rjt));
1767 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
1768 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
1769 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
1771 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
1772 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
1773 spin_lock_irq(shost->host_lock);
1774 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1775 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
1776 spin_unlock_irq(shost->host_lock);
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_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1790 void *arg, uint32_t evt)
1792 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1794 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1795 return ndlp->nlp_state;
1799 lpfc_rcv_padisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1800 void *arg, uint32_t evt)
1802 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1804 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1807 * Do not start discovery if discovery is about to start
1808 * or discovery in progress for this node. Starting discovery
1809 * here will affect the counting of discovery threads.
1811 if (!(ndlp->nlp_flag & NLP_DELAY_TMO) &&
1812 !(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
1813 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
1814 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1815 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
1816 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
1817 lpfc_issue_els_adisc(vport, ndlp, 0);
1819 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
1820 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1821 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
1824 return ndlp->nlp_state;
1828 lpfc_rcv_prlo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1829 void *arg, uint32_t evt)
1831 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1832 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1834 spin_lock_irq(shost->host_lock);
1835 ndlp->nlp_flag |= NLP_LOGO_ACC;
1836 spin_unlock_irq(shost->host_lock);
1838 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
1840 if ((ndlp->nlp_flag & NLP_DELAY_TMO) == 0) {
1841 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
1842 spin_lock_irq(shost->host_lock);
1843 ndlp->nlp_flag |= NLP_DELAY_TMO;
1844 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1845 spin_unlock_irq(shost->host_lock);
1846 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1848 spin_lock_irq(shost->host_lock);
1849 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1850 spin_unlock_irq(shost->host_lock);
1852 return ndlp->nlp_state;
1856 lpfc_cmpl_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1857 void *arg, uint32_t evt)
1859 struct lpfc_iocbq *cmdiocb, *rspiocb;
1862 cmdiocb = (struct lpfc_iocbq *) arg;
1863 rspiocb = cmdiocb->context_un.rsp_iocb;
1865 irsp = &rspiocb->iocb;
1866 if (irsp->ulpStatus) {
1867 ndlp->nlp_flag |= NLP_DEFER_RM;
1868 return NLP_STE_FREED_NODE;
1870 return ndlp->nlp_state;
1874 lpfc_cmpl_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1875 void *arg, uint32_t evt)
1877 struct lpfc_iocbq *cmdiocb, *rspiocb;
1880 cmdiocb = (struct lpfc_iocbq *) arg;
1881 rspiocb = cmdiocb->context_un.rsp_iocb;
1883 irsp = &rspiocb->iocb;
1884 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
1885 lpfc_drop_node(vport, ndlp);
1886 return NLP_STE_FREED_NODE;
1888 return ndlp->nlp_state;
1892 lpfc_cmpl_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1893 void *arg, uint32_t evt)
1895 lpfc_unreg_rpi(vport, ndlp);
1896 /* This routine does nothing, just return the current state */
1897 return ndlp->nlp_state;
1901 lpfc_cmpl_adisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1902 void *arg, uint32_t evt)
1904 struct lpfc_iocbq *cmdiocb, *rspiocb;
1907 cmdiocb = (struct lpfc_iocbq *) arg;
1908 rspiocb = cmdiocb->context_un.rsp_iocb;
1910 irsp = &rspiocb->iocb;
1911 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
1912 lpfc_drop_node(vport, ndlp);
1913 return NLP_STE_FREED_NODE;
1915 return ndlp->nlp_state;
1919 lpfc_cmpl_reglogin_npr_node(struct lpfc_vport *vport,
1920 struct lpfc_nodelist *ndlp,
1921 void *arg, uint32_t evt)
1923 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1924 MAILBOX_t *mb = &pmb->mb;
1927 ndlp->nlp_rpi = mb->un.varWords[0];
1929 if (ndlp->nlp_flag & NLP_NODEV_REMOVE) {
1930 lpfc_drop_node(vport, ndlp);
1931 return NLP_STE_FREED_NODE;
1934 return ndlp->nlp_state;
1938 lpfc_device_rm_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1939 void *arg, uint32_t evt)
1941 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1943 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1944 spin_lock_irq(shost->host_lock);
1945 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1946 spin_unlock_irq(shost->host_lock);
1947 return ndlp->nlp_state;
1949 lpfc_drop_node(vport, ndlp);
1950 return NLP_STE_FREED_NODE;
1954 lpfc_device_recov_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1955 void *arg, uint32_t evt)
1957 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1959 /* Don't do anything that will mess up processing of the
1962 if (vport->fc_flag & FC_RSCN_DEFERRED)
1963 return ndlp->nlp_state;
1965 spin_lock_irq(shost->host_lock);
1966 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1967 spin_unlock_irq(shost->host_lock);
1968 if (ndlp->nlp_flag & NLP_DELAY_TMO) {
1969 lpfc_cancel_retry_delay_tmo(vport, ndlp);
1971 return ndlp->nlp_state;
1975 /* This next section defines the NPort Discovery State Machine */
1977 /* There are 4 different double linked lists nodelist entries can reside on.
1978 * The plogi list and adisc list are used when Link Up discovery or RSCN
1979 * processing is needed. Each list holds the nodes that we will send PLOGI
1980 * or ADISC on. These lists will keep track of what nodes will be effected
1981 * by an RSCN, or a Link Up (Typically, all nodes are effected on Link Up).
1982 * The unmapped_list will contain all nodes that we have successfully logged
1983 * into at the Fibre Channel level. The mapped_list will contain all nodes
1984 * that are mapped FCP targets.
1987 * The bind list is a list of undiscovered (potentially non-existent) nodes
1988 * that we have saved binding information on. This information is used when
1989 * nodes transition from the unmapped to the mapped list.
1991 /* For UNUSED_NODE state, the node has just been allocated .
1992 * For PLOGI_ISSUE and REG_LOGIN_ISSUE, the node is on
1993 * the PLOGI list. For REG_LOGIN_COMPL, the node is taken off the PLOGI list
1994 * and put on the unmapped list. For ADISC processing, the node is taken off
1995 * the ADISC list and placed on either the mapped or unmapped list (depending
1996 * on its previous state). Once on the unmapped list, a PRLI is issued and the
1997 * state changed to PRLI_ISSUE. When the PRLI completion occurs, the state is
1998 * changed to UNMAPPED_NODE. If the completion indicates a mapped
1999 * node, the node is taken off the unmapped list. The binding list is checked
2000 * for a valid binding, or a binding is automatically assigned. If binding
2001 * assignment is unsuccessful, the node is left on the unmapped list. If
2002 * binding assignment is successful, the associated binding list entry (if
2003 * any) is removed, and the node is placed on the mapped list.
2006 * For a Link Down, all nodes on the ADISC, PLOGI, unmapped or mapped
2007 * lists will receive a DEVICE_RECOVERY event. If the linkdown or devloss timers
2008 * expire, all effected nodes will receive a DEVICE_RM event.
2011 * For a Link Up or RSCN, all nodes will move from the mapped / unmapped lists
2012 * to either the ADISC or PLOGI list. After a Nameserver query or ALPA loopmap
2013 * check, additional nodes may be added or removed (via DEVICE_RM) to / from
2014 * the PLOGI or ADISC lists. Once the PLOGI and ADISC lists are populated,
2015 * we will first process the ADISC list. 32 entries are processed initially and
2016 * ADISC is initited for each one. Completions / Events for each node are
2017 * funnelled thru the state machine. As each node finishes ADISC processing, it
2018 * starts ADISC for any nodes waiting for ADISC processing. If no nodes are
2019 * waiting, and the ADISC list count is identically 0, then we are done. For
2020 * Link Up discovery, since all nodes on the PLOGI list are UNREG_LOGIN'ed, we
2021 * can issue a CLEAR_LA and reenable Link Events. Next we will process the PLOGI
2022 * list. 32 entries are processed initially and PLOGI is initited for each one.
2023 * Completions / Events for each node are funnelled thru the state machine. As
2024 * each node finishes PLOGI processing, it starts PLOGI for any nodes waiting
2025 * for PLOGI processing. If no nodes are waiting, and the PLOGI list count is
2026 * indentically 0, then we are done. We have now completed discovery / RSCN
2027 * handling. Upon completion, ALL nodes should be on either the mapped or
2031 static uint32_t (*lpfc_disc_action[NLP_STE_MAX_STATE * NLP_EVT_MAX_EVENT])
2032 (struct lpfc_vport *, struct lpfc_nodelist *, void *, uint32_t) = {
2033 /* Action routine Event Current State */
2034 lpfc_rcv_plogi_unused_node, /* RCV_PLOGI UNUSED_NODE */
2035 lpfc_rcv_els_unused_node, /* RCV_PRLI */
2036 lpfc_rcv_logo_unused_node, /* RCV_LOGO */
2037 lpfc_rcv_els_unused_node, /* RCV_ADISC */
2038 lpfc_rcv_els_unused_node, /* RCV_PDISC */
2039 lpfc_rcv_els_unused_node, /* RCV_PRLO */
2040 lpfc_disc_illegal, /* CMPL_PLOGI */
2041 lpfc_disc_illegal, /* CMPL_PRLI */
2042 lpfc_cmpl_logo_unused_node, /* CMPL_LOGO */
2043 lpfc_disc_illegal, /* CMPL_ADISC */
2044 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2045 lpfc_device_rm_unused_node, /* DEVICE_RM */
2046 lpfc_disc_illegal, /* DEVICE_RECOVERY */
2048 lpfc_rcv_plogi_plogi_issue, /* RCV_PLOGI PLOGI_ISSUE */
2049 lpfc_rcv_prli_plogi_issue, /* RCV_PRLI */
2050 lpfc_rcv_logo_plogi_issue, /* RCV_LOGO */
2051 lpfc_rcv_els_plogi_issue, /* RCV_ADISC */
2052 lpfc_rcv_els_plogi_issue, /* RCV_PDISC */
2053 lpfc_rcv_els_plogi_issue, /* RCV_PRLO */
2054 lpfc_cmpl_plogi_plogi_issue, /* CMPL_PLOGI */
2055 lpfc_disc_illegal, /* CMPL_PRLI */
2056 lpfc_cmpl_logo_plogi_issue, /* CMPL_LOGO */
2057 lpfc_disc_illegal, /* CMPL_ADISC */
2058 lpfc_cmpl_reglogin_plogi_issue,/* CMPL_REG_LOGIN */
2059 lpfc_device_rm_plogi_issue, /* DEVICE_RM */
2060 lpfc_device_recov_plogi_issue, /* DEVICE_RECOVERY */
2062 lpfc_rcv_plogi_adisc_issue, /* RCV_PLOGI ADISC_ISSUE */
2063 lpfc_rcv_prli_adisc_issue, /* RCV_PRLI */
2064 lpfc_rcv_logo_adisc_issue, /* RCV_LOGO */
2065 lpfc_rcv_padisc_adisc_issue, /* RCV_ADISC */
2066 lpfc_rcv_padisc_adisc_issue, /* RCV_PDISC */
2067 lpfc_rcv_prlo_adisc_issue, /* RCV_PRLO */
2068 lpfc_disc_illegal, /* CMPL_PLOGI */
2069 lpfc_disc_illegal, /* CMPL_PRLI */
2070 lpfc_disc_illegal, /* CMPL_LOGO */
2071 lpfc_cmpl_adisc_adisc_issue, /* CMPL_ADISC */
2072 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2073 lpfc_device_rm_adisc_issue, /* DEVICE_RM */
2074 lpfc_device_recov_adisc_issue, /* DEVICE_RECOVERY */
2076 lpfc_rcv_plogi_reglogin_issue, /* RCV_PLOGI REG_LOGIN_ISSUE */
2077 lpfc_rcv_prli_reglogin_issue, /* RCV_PLOGI */
2078 lpfc_rcv_logo_reglogin_issue, /* RCV_LOGO */
2079 lpfc_rcv_padisc_reglogin_issue, /* RCV_ADISC */
2080 lpfc_rcv_padisc_reglogin_issue, /* RCV_PDISC */
2081 lpfc_rcv_prlo_reglogin_issue, /* RCV_PRLO */
2082 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
2083 lpfc_disc_illegal, /* CMPL_PRLI */
2084 lpfc_disc_illegal, /* CMPL_LOGO */
2085 lpfc_disc_illegal, /* CMPL_ADISC */
2086 lpfc_cmpl_reglogin_reglogin_issue,/* CMPL_REG_LOGIN */
2087 lpfc_device_rm_reglogin_issue, /* DEVICE_RM */
2088 lpfc_device_recov_reglogin_issue,/* DEVICE_RECOVERY */
2090 lpfc_rcv_plogi_prli_issue, /* RCV_PLOGI PRLI_ISSUE */
2091 lpfc_rcv_prli_prli_issue, /* RCV_PRLI */
2092 lpfc_rcv_logo_prli_issue, /* RCV_LOGO */
2093 lpfc_rcv_padisc_prli_issue, /* RCV_ADISC */
2094 lpfc_rcv_padisc_prli_issue, /* RCV_PDISC */
2095 lpfc_rcv_prlo_prli_issue, /* RCV_PRLO */
2096 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
2097 lpfc_cmpl_prli_prli_issue, /* CMPL_PRLI */
2098 lpfc_disc_illegal, /* CMPL_LOGO */
2099 lpfc_disc_illegal, /* CMPL_ADISC */
2100 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2101 lpfc_device_rm_prli_issue, /* DEVICE_RM */
2102 lpfc_device_recov_prli_issue, /* DEVICE_RECOVERY */
2104 lpfc_rcv_plogi_unmap_node, /* RCV_PLOGI UNMAPPED_NODE */
2105 lpfc_rcv_prli_unmap_node, /* RCV_PRLI */
2106 lpfc_rcv_logo_unmap_node, /* RCV_LOGO */
2107 lpfc_rcv_padisc_unmap_node, /* RCV_ADISC */
2108 lpfc_rcv_padisc_unmap_node, /* RCV_PDISC */
2109 lpfc_rcv_prlo_unmap_node, /* RCV_PRLO */
2110 lpfc_disc_illegal, /* CMPL_PLOGI */
2111 lpfc_disc_illegal, /* CMPL_PRLI */
2112 lpfc_disc_illegal, /* CMPL_LOGO */
2113 lpfc_disc_illegal, /* CMPL_ADISC */
2114 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2115 lpfc_disc_illegal, /* DEVICE_RM */
2116 lpfc_device_recov_unmap_node, /* DEVICE_RECOVERY */
2118 lpfc_rcv_plogi_mapped_node, /* RCV_PLOGI MAPPED_NODE */
2119 lpfc_rcv_prli_mapped_node, /* RCV_PRLI */
2120 lpfc_rcv_logo_mapped_node, /* RCV_LOGO */
2121 lpfc_rcv_padisc_mapped_node, /* RCV_ADISC */
2122 lpfc_rcv_padisc_mapped_node, /* RCV_PDISC */
2123 lpfc_rcv_prlo_mapped_node, /* RCV_PRLO */
2124 lpfc_disc_illegal, /* CMPL_PLOGI */
2125 lpfc_disc_illegal, /* CMPL_PRLI */
2126 lpfc_disc_illegal, /* CMPL_LOGO */
2127 lpfc_disc_illegal, /* CMPL_ADISC */
2128 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2129 lpfc_disc_illegal, /* DEVICE_RM */
2130 lpfc_device_recov_mapped_node, /* DEVICE_RECOVERY */
2132 lpfc_rcv_plogi_npr_node, /* RCV_PLOGI NPR_NODE */
2133 lpfc_rcv_prli_npr_node, /* RCV_PRLI */
2134 lpfc_rcv_logo_npr_node, /* RCV_LOGO */
2135 lpfc_rcv_padisc_npr_node, /* RCV_ADISC */
2136 lpfc_rcv_padisc_npr_node, /* RCV_PDISC */
2137 lpfc_rcv_prlo_npr_node, /* RCV_PRLO */
2138 lpfc_cmpl_plogi_npr_node, /* CMPL_PLOGI */
2139 lpfc_cmpl_prli_npr_node, /* CMPL_PRLI */
2140 lpfc_cmpl_logo_npr_node, /* CMPL_LOGO */
2141 lpfc_cmpl_adisc_npr_node, /* CMPL_ADISC */
2142 lpfc_cmpl_reglogin_npr_node, /* CMPL_REG_LOGIN */
2143 lpfc_device_rm_npr_node, /* DEVICE_RM */
2144 lpfc_device_recov_npr_node, /* DEVICE_RECOVERY */
2148 lpfc_disc_state_machine(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2149 void *arg, uint32_t evt)
2151 uint32_t cur_state, rc;
2152 uint32_t(*func) (struct lpfc_vport *, struct lpfc_nodelist *, void *,
2154 uint32_t got_ndlp = 0;
2156 if (lpfc_nlp_get(ndlp))
2159 cur_state = ndlp->nlp_state;
2161 /* DSM in event <evt> on NPort <nlp_DID> in state <cur_state> */
2162 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2163 "0211 DSM in event x%x on NPort x%x in "
2164 "state %d Data: x%x\n",
2165 evt, ndlp->nlp_DID, cur_state, ndlp->nlp_flag);
2167 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2168 "DSM in: evt:%d ste:%d did:x%x",
2169 evt, cur_state, ndlp->nlp_DID);
2171 func = lpfc_disc_action[(cur_state * NLP_EVT_MAX_EVENT) + evt];
2172 rc = (func) (vport, ndlp, arg, evt);
2174 /* DSM out state <rc> on NPort <nlp_DID> */
2176 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2177 "0212 DSM out state %d on NPort x%x Data: x%x\n",
2178 rc, ndlp->nlp_DID, ndlp->nlp_flag);
2180 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2181 "DSM out: ste:%d did:x%x flg:x%x",
2182 rc, ndlp->nlp_DID, ndlp->nlp_flag);
2183 /* Decrement the ndlp reference count held for this function */
2186 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2187 "0212 DSM out state %d on NPort free\n", rc);
2189 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2190 "DSM out: ste:%d did:x%x flg:x%x",