1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2009 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>
34 #include "lpfc_sli4.h"
36 #include "lpfc_disc.h"
37 #include "lpfc_scsi.h"
39 #include "lpfc_logmsg.h"
40 #include "lpfc_crtn.h"
41 #include "lpfc_vport.h"
42 #include "lpfc_debugfs.h"
45 /* Called to verify a rcv'ed ADISC was intended for us. */
47 lpfc_check_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
48 struct lpfc_name *nn, struct lpfc_name *pn)
50 /* Compare the ADISC rsp WWNN / WWPN matches our internal node
51 * table entry for that node.
53 if (memcmp(nn, &ndlp->nlp_nodename, sizeof (struct lpfc_name)))
56 if (memcmp(pn, &ndlp->nlp_portname, sizeof (struct lpfc_name)))
59 /* we match, return success */
64 lpfc_check_sparm(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
65 struct serv_parm *sp, uint32_t class, int flogi)
67 volatile struct serv_parm *hsp = &vport->fc_sparam;
68 uint16_t hsp_value, ssp_value = 0;
71 * The receive data field size and buffer-to-buffer receive data field
72 * size entries are 16 bits but are represented as two 8-bit fields in
73 * the driver data structure to account for rsvd bits and other control
74 * bits. Reconstruct and compare the fields as a 16-bit values before
75 * correcting the byte values.
77 if (sp->cls1.classValid) {
79 hsp_value = ((hsp->cls1.rcvDataSizeMsb << 8) |
80 hsp->cls1.rcvDataSizeLsb);
81 ssp_value = ((sp->cls1.rcvDataSizeMsb << 8) |
82 sp->cls1.rcvDataSizeLsb);
84 goto bad_service_param;
85 if (ssp_value > hsp_value) {
86 sp->cls1.rcvDataSizeLsb =
87 hsp->cls1.rcvDataSizeLsb;
88 sp->cls1.rcvDataSizeMsb =
89 hsp->cls1.rcvDataSizeMsb;
92 } else if (class == CLASS1)
93 goto bad_service_param;
94 if (sp->cls2.classValid) {
96 hsp_value = ((hsp->cls2.rcvDataSizeMsb << 8) |
97 hsp->cls2.rcvDataSizeLsb);
98 ssp_value = ((sp->cls2.rcvDataSizeMsb << 8) |
99 sp->cls2.rcvDataSizeLsb);
101 goto bad_service_param;
102 if (ssp_value > hsp_value) {
103 sp->cls2.rcvDataSizeLsb =
104 hsp->cls2.rcvDataSizeLsb;
105 sp->cls2.rcvDataSizeMsb =
106 hsp->cls2.rcvDataSizeMsb;
109 } else if (class == CLASS2)
110 goto bad_service_param;
111 if (sp->cls3.classValid) {
113 hsp_value = ((hsp->cls3.rcvDataSizeMsb << 8) |
114 hsp->cls3.rcvDataSizeLsb);
115 ssp_value = ((sp->cls3.rcvDataSizeMsb << 8) |
116 sp->cls3.rcvDataSizeLsb);
118 goto bad_service_param;
119 if (ssp_value > hsp_value) {
120 sp->cls3.rcvDataSizeLsb =
121 hsp->cls3.rcvDataSizeLsb;
122 sp->cls3.rcvDataSizeMsb =
123 hsp->cls3.rcvDataSizeMsb;
126 } else if (class == CLASS3)
127 goto bad_service_param;
130 * Preserve the upper four bits of the MSB from the PLOGI response.
131 * These bits contain the Buffer-to-Buffer State Change Number
132 * from the target and need to be passed to the FW.
134 hsp_value = (hsp->cmn.bbRcvSizeMsb << 8) | hsp->cmn.bbRcvSizeLsb;
135 ssp_value = (sp->cmn.bbRcvSizeMsb << 8) | sp->cmn.bbRcvSizeLsb;
136 if (ssp_value > hsp_value) {
137 sp->cmn.bbRcvSizeLsb = hsp->cmn.bbRcvSizeLsb;
138 sp->cmn.bbRcvSizeMsb = (sp->cmn.bbRcvSizeMsb & 0xF0) |
139 (hsp->cmn.bbRcvSizeMsb & 0x0F);
142 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof (struct lpfc_name));
143 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof (struct lpfc_name));
146 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
148 "(%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x) sent "
149 "invalid service parameters. Ignoring device.\n",
151 sp->nodeName.u.wwn[0], sp->nodeName.u.wwn[1],
152 sp->nodeName.u.wwn[2], sp->nodeName.u.wwn[3],
153 sp->nodeName.u.wwn[4], sp->nodeName.u.wwn[5],
154 sp->nodeName.u.wwn[6], sp->nodeName.u.wwn[7]);
159 lpfc_check_elscmpl_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
160 struct lpfc_iocbq *rspiocb)
162 struct lpfc_dmabuf *pcmd, *prsp;
167 irsp = &rspiocb->iocb;
168 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
170 /* For lpfc_els_abort, context2 could be zero'ed to delay
171 * freeing associated memory till after ABTS completes.
174 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf,
177 lp = (uint32_t *) prsp->virt;
178 ptr = (void *)((uint8_t *)lp + sizeof(uint32_t));
181 /* Force ulpStatus error since we are returning NULL ptr */
182 if (!(irsp->ulpStatus)) {
183 irsp->ulpStatus = IOSTAT_LOCAL_REJECT;
184 irsp->un.ulpWord[4] = IOERR_SLI_ABORTED;
193 * Free resources / clean up outstanding I/Os
194 * associated with a LPFC_NODELIST entry. This
195 * routine effectively results in a "software abort".
198 lpfc_els_abort(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
200 LIST_HEAD(completions);
201 struct lpfc_sli *psli = &phba->sli;
202 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
203 struct lpfc_iocbq *iocb, *next_iocb;
205 /* Abort outstanding I/O on NPort <nlp_DID> */
206 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_DISCOVERY,
207 "0205 Abort outstanding I/O on NPort x%x "
208 "Data: x%x x%x x%x\n",
209 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
212 lpfc_fabric_abort_nport(ndlp);
214 /* First check the txq */
215 spin_lock_irq(&phba->hbalock);
216 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
217 /* Check to see if iocb matches the nport we are looking for */
218 if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp)) {
219 /* It matches, so deque and call compl with anp error */
220 list_move_tail(&iocb->list, &completions);
225 /* Next check the txcmplq */
226 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
227 /* Check to see if iocb matches the nport we are looking for */
228 if (lpfc_check_sli_ndlp(phba, pring, iocb, ndlp)) {
229 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
232 spin_unlock_irq(&phba->hbalock);
234 /* Cancel all the IOCBs from the completions list */
235 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
238 lpfc_cancel_retry_delay_tmo(phba->pport, ndlp);
243 lpfc_rcv_plogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
244 struct lpfc_iocbq *cmdiocb)
246 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
247 struct lpfc_hba *phba = vport->phba;
248 struct lpfc_dmabuf *pcmd;
251 struct serv_parm *sp;
256 memset(&stat, 0, sizeof (struct ls_rjt));
257 if (vport->port_state <= LPFC_FDISC) {
258 /* Before responding to PLOGI, check for pt2pt mode.
259 * If we are pt2pt, with an outstanding FLOGI, abort
260 * the FLOGI and resend it first.
262 if (vport->fc_flag & FC_PT2PT) {
263 lpfc_els_abort_flogi(phba);
264 if (!(vport->fc_flag & FC_PT2PT_PLOGI)) {
265 /* If the other side is supposed to initiate
266 * the PLOGI anyway, just ACC it now and
267 * move on with discovery.
269 phba->fc_edtov = FF_DEF_EDTOV;
270 phba->fc_ratov = FF_DEF_RATOV;
271 /* Start discovery - this should just do
273 lpfc_disc_start(vport);
275 lpfc_initial_flogi(vport);
277 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
278 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
279 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
284 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
285 lp = (uint32_t *) pcmd->virt;
286 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
287 if (wwn_to_u64(sp->portName.u.wwn) == 0) {
288 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
289 "0140 PLOGI Reject: invalid nname\n");
290 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
291 stat.un.b.lsRjtRsnCodeExp = LSEXP_INVALID_PNAME;
292 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
296 if (wwn_to_u64(sp->nodeName.u.wwn) == 0) {
297 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
298 "0141 PLOGI Reject: invalid pname\n");
299 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
300 stat.un.b.lsRjtRsnCodeExp = LSEXP_INVALID_NNAME;
301 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
305 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 0) == 0)) {
306 /* Reject this request because invalid parameters */
307 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
308 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
309 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
313 icmd = &cmdiocb->iocb;
315 /* PLOGI chkparm OK */
316 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
317 "0114 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
318 ndlp->nlp_DID, ndlp->nlp_state, ndlp->nlp_flag,
321 if (vport->cfg_fcp_class == 2 && sp->cls2.classValid)
322 ndlp->nlp_fcp_info |= CLASS2;
324 ndlp->nlp_fcp_info |= CLASS3;
326 ndlp->nlp_class_sup = 0;
327 if (sp->cls1.classValid)
328 ndlp->nlp_class_sup |= FC_COS_CLASS1;
329 if (sp->cls2.classValid)
330 ndlp->nlp_class_sup |= FC_COS_CLASS2;
331 if (sp->cls3.classValid)
332 ndlp->nlp_class_sup |= FC_COS_CLASS3;
333 if (sp->cls4.classValid)
334 ndlp->nlp_class_sup |= FC_COS_CLASS4;
336 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
338 /* no need to reg_login if we are already in one of these states */
339 switch (ndlp->nlp_state) {
340 case NLP_STE_NPR_NODE:
341 if (!(ndlp->nlp_flag & NLP_NPR_ADISC))
343 case NLP_STE_REG_LOGIN_ISSUE:
344 case NLP_STE_PRLI_ISSUE:
345 case NLP_STE_UNMAPPED_NODE:
346 case NLP_STE_MAPPED_NODE:
347 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
351 if ((vport->fc_flag & FC_PT2PT) &&
352 !(vport->fc_flag & FC_PT2PT_PLOGI)) {
353 /* rcv'ed PLOGI decides what our NPortId will be */
354 vport->fc_myDID = icmd->un.rcvels.parmRo;
355 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
358 lpfc_config_link(phba, mbox);
359 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
361 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
362 if (rc == MBX_NOT_FINISHED) {
363 mempool_free(mbox, phba->mbox_mem_pool);
367 lpfc_can_disctmo(vport);
369 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
373 rc = lpfc_reg_rpi(phba, vport->vpi, icmd->un.rcvels.remoteID,
374 (uint8_t *) sp, mbox, 0);
376 mempool_free(mbox, phba->mbox_mem_pool);
380 /* ACC PLOGI rsp command needs to execute first,
381 * queue this mbox command to be processed later.
383 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
385 * mbox->context2 = lpfc_nlp_get(ndlp) deferred until mailbox
386 * command issued in lpfc_cmpl_els_acc().
389 spin_lock_irq(shost->host_lock);
390 ndlp->nlp_flag |= (NLP_ACC_REGLOGIN | NLP_RCV_PLOGI);
391 spin_unlock_irq(shost->host_lock);
394 * If there is an outstanding PLOGI issued, abort it before
395 * sending ACC rsp for received PLOGI. If pending plogi
396 * is not canceled here, the plogi will be rejected by
397 * remote port and will be retried. On a configuration with
398 * single discovery thread, this will cause a huge delay in
399 * discovery. Also this will cause multiple state machines
400 * running in parallel for this node.
402 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE) {
403 /* software abort outstanding PLOGI */
404 lpfc_els_abort(phba, ndlp);
407 if ((vport->port_type == LPFC_NPIV_PORT &&
408 vport->cfg_restrict_login)) {
410 /* In order to preserve RPIs, we want to cleanup
411 * the default RPI the firmware created to rcv
412 * this ELS request. The only way to do this is
413 * to register, then unregister the RPI.
415 spin_lock_irq(shost->host_lock);
416 ndlp->nlp_flag |= NLP_RM_DFLT_RPI;
417 spin_unlock_irq(shost->host_lock);
418 stat.un.b.lsRjtRsnCode = LSRJT_INVALID_CMD;
419 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
420 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb,
424 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, mbox);
427 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
428 stat.un.b.lsRjtRsnCodeExp = LSEXP_OUT_OF_RESOURCE;
429 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
434 lpfc_rcv_padisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
435 struct lpfc_iocbq *cmdiocb)
437 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
438 struct lpfc_dmabuf *pcmd;
439 struct serv_parm *sp;
440 struct lpfc_name *pnn, *ppn;
447 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
448 lp = (uint32_t *) pcmd->virt;
451 if (cmd == ELS_CMD_ADISC) {
453 pnn = (struct lpfc_name *) & ap->nodeName;
454 ppn = (struct lpfc_name *) & ap->portName;
456 sp = (struct serv_parm *) lp;
457 pnn = (struct lpfc_name *) & sp->nodeName;
458 ppn = (struct lpfc_name *) & sp->portName;
461 icmd = &cmdiocb->iocb;
462 if (icmd->ulpStatus == 0 && lpfc_check_adisc(vport, ndlp, pnn, ppn)) {
463 if (cmd == ELS_CMD_ADISC) {
464 lpfc_els_rsp_adisc_acc(vport, cmdiocb, ndlp);
466 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp,
471 /* Reject this request because invalid parameters */
472 stat.un.b.lsRjtRsvd0 = 0;
473 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
474 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
475 stat.un.b.vendorUnique = 0;
476 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
479 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
481 spin_lock_irq(shost->host_lock);
482 ndlp->nlp_flag |= NLP_DELAY_TMO;
483 spin_unlock_irq(shost->host_lock);
484 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
485 ndlp->nlp_prev_state = ndlp->nlp_state;
486 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
491 lpfc_rcv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
492 struct lpfc_iocbq *cmdiocb, uint32_t els_cmd)
494 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
496 /* Put ndlp in NPR state with 1 sec timeout for plogi, ACC logo */
497 /* Only call LOGO ACC for first LOGO, this avoids sending unnecessary
498 * PLOGIs during LOGO storms from a device.
500 spin_lock_irq(shost->host_lock);
501 ndlp->nlp_flag |= NLP_LOGO_ACC;
502 spin_unlock_irq(shost->host_lock);
503 if (els_cmd == ELS_CMD_PRLO)
504 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
506 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
507 if ((ndlp->nlp_DID == Fabric_DID) &&
508 vport->port_type == LPFC_NPIV_PORT) {
509 lpfc_linkdown_port(vport);
510 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
511 spin_lock_irq(shost->host_lock);
512 ndlp->nlp_flag |= NLP_DELAY_TMO;
513 spin_unlock_irq(shost->host_lock);
515 ndlp->nlp_last_elscmd = ELS_CMD_FDISC;
516 } else if ((!(ndlp->nlp_type & NLP_FABRIC) &&
517 ((ndlp->nlp_type & NLP_FCP_TARGET) ||
518 !(ndlp->nlp_type & NLP_FCP_INITIATOR))) ||
519 (ndlp->nlp_state == NLP_STE_ADISC_ISSUE)) {
520 /* Only try to re-login if this is NOT a Fabric Node */
521 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
522 spin_lock_irq(shost->host_lock);
523 ndlp->nlp_flag |= NLP_DELAY_TMO;
524 spin_unlock_irq(shost->host_lock);
526 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
528 ndlp->nlp_prev_state = ndlp->nlp_state;
529 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
531 spin_lock_irq(shost->host_lock);
532 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
533 spin_unlock_irq(shost->host_lock);
534 /* The driver has to wait until the ACC completes before it continues
535 * processing the LOGO. The action will resume in
536 * lpfc_cmpl_els_logo_acc routine. Since part of processing includes an
537 * unreg_login, the driver waits so the ACC does not get aborted.
543 lpfc_rcv_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
544 struct lpfc_iocbq *cmdiocb)
546 struct lpfc_dmabuf *pcmd;
549 struct fc_rport *rport = ndlp->rport;
552 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
553 lp = (uint32_t *) pcmd->virt;
554 npr = (PRLI *) ((uint8_t *) lp + sizeof (uint32_t));
556 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
557 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
558 if (npr->prliType == PRLI_FCP_TYPE) {
559 if (npr->initiatorFunc)
560 ndlp->nlp_type |= NLP_FCP_INITIATOR;
562 ndlp->nlp_type |= NLP_FCP_TARGET;
564 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
567 /* We need to update the rport role values */
568 roles = FC_RPORT_ROLE_UNKNOWN;
569 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
570 roles |= FC_RPORT_ROLE_FCP_INITIATOR;
571 if (ndlp->nlp_type & NLP_FCP_TARGET)
572 roles |= FC_RPORT_ROLE_FCP_TARGET;
574 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
575 "rport rolechg: role:x%x did:x%x flg:x%x",
576 roles, ndlp->nlp_DID, ndlp->nlp_flag);
578 fc_remote_port_rolechg(rport, roles);
583 lpfc_disc_set_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
585 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
587 if (!(ndlp->nlp_flag & NLP_RPI_VALID)) {
588 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
592 if (!(vport->fc_flag & FC_PT2PT)) {
593 /* Check config parameter use-adisc or FCP-2 */
594 if ((vport->cfg_use_adisc && (vport->fc_flag & FC_RSCN_MODE)) ||
595 ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE) {
596 spin_lock_irq(shost->host_lock);
597 ndlp->nlp_flag |= NLP_NPR_ADISC;
598 spin_unlock_irq(shost->host_lock);
602 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
603 lpfc_unreg_rpi(vport, ndlp);
608 lpfc_disc_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
609 void *arg, uint32_t evt)
611 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
612 "0271 Illegal State Transition: node x%x "
613 "event x%x, state x%x Data: x%x x%x\n",
614 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
616 return ndlp->nlp_state;
620 lpfc_cmpl_plogi_illegal(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
621 void *arg, uint32_t evt)
623 /* This transition is only legal if we previously
624 * rcv'ed a PLOGI. Since we don't want 2 discovery threads
625 * working on the same NPortID, do nothing for this thread
628 if (!(ndlp->nlp_flag & NLP_RCV_PLOGI)) {
629 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
630 "0272 Illegal State Transition: node x%x "
631 "event x%x, state x%x Data: x%x x%x\n",
632 ndlp->nlp_DID, evt, ndlp->nlp_state, ndlp->nlp_rpi,
635 return ndlp->nlp_state;
638 /* Start of Discovery State Machine routines */
641 lpfc_rcv_plogi_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
642 void *arg, uint32_t evt)
644 struct lpfc_iocbq *cmdiocb;
646 cmdiocb = (struct lpfc_iocbq *) arg;
648 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
649 return ndlp->nlp_state;
651 return NLP_STE_FREED_NODE;
655 lpfc_rcv_els_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
656 void *arg, uint32_t evt)
658 lpfc_issue_els_logo(vport, ndlp, 0);
659 return ndlp->nlp_state;
663 lpfc_rcv_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
664 void *arg, uint32_t evt)
666 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
667 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
669 spin_lock_irq(shost->host_lock);
670 ndlp->nlp_flag |= NLP_LOGO_ACC;
671 spin_unlock_irq(shost->host_lock);
672 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
674 return ndlp->nlp_state;
678 lpfc_cmpl_logo_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
679 void *arg, uint32_t evt)
681 return NLP_STE_FREED_NODE;
685 lpfc_device_rm_unused_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
686 void *arg, uint32_t evt)
688 return NLP_STE_FREED_NODE;
692 lpfc_rcv_plogi_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
693 void *arg, uint32_t evt)
695 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
696 struct lpfc_hba *phba = vport->phba;
697 struct lpfc_iocbq *cmdiocb = arg;
698 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
699 uint32_t *lp = (uint32_t *) pcmd->virt;
700 struct serv_parm *sp = (struct serv_parm *) (lp + 1);
704 memset(&stat, 0, sizeof (struct ls_rjt));
706 /* For a PLOGI, we only accept if our portname is less
707 * than the remote portname.
709 phba->fc_stat.elsLogiCol++;
710 port_cmp = memcmp(&vport->fc_portname, &sp->portName,
711 sizeof(struct lpfc_name));
714 /* Reject this request because the remote node will accept
716 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
717 stat.un.b.lsRjtRsnCodeExp = LSEXP_CMD_IN_PROGRESS;
718 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
721 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb) &&
722 (ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
723 (vport->num_disc_nodes)) {
724 spin_lock_irq(shost->host_lock);
725 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
726 spin_unlock_irq(shost->host_lock);
727 /* Check if there are more PLOGIs to be sent */
728 lpfc_more_plogi(vport);
729 if (vport->num_disc_nodes == 0) {
730 spin_lock_irq(shost->host_lock);
731 vport->fc_flag &= ~FC_NDISC_ACTIVE;
732 spin_unlock_irq(shost->host_lock);
733 lpfc_can_disctmo(vport);
734 lpfc_end_rscn(vport);
737 } /* If our portname was less */
739 return ndlp->nlp_state;
743 lpfc_rcv_prli_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
744 void *arg, uint32_t evt)
746 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
749 memset(&stat, 0, sizeof (struct ls_rjt));
750 stat.un.b.lsRjtRsnCode = LSRJT_LOGICAL_BSY;
751 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
752 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
753 return ndlp->nlp_state;
757 lpfc_rcv_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
758 void *arg, uint32_t evt)
760 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
762 /* software abort outstanding PLOGI */
763 lpfc_els_abort(vport->phba, ndlp);
765 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
766 return ndlp->nlp_state;
770 lpfc_rcv_els_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
771 void *arg, uint32_t evt)
773 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
774 struct lpfc_hba *phba = vport->phba;
775 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
777 /* software abort outstanding PLOGI */
778 lpfc_els_abort(phba, ndlp);
780 if (evt == NLP_EVT_RCV_LOGO) {
781 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
783 lpfc_issue_els_logo(vport, ndlp, 0);
786 /* Put ndlp in npr state set plogi timer for 1 sec */
787 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
788 spin_lock_irq(shost->host_lock);
789 ndlp->nlp_flag |= NLP_DELAY_TMO;
790 spin_unlock_irq(shost->host_lock);
791 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
792 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
793 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
795 return ndlp->nlp_state;
799 lpfc_cmpl_plogi_plogi_issue(struct lpfc_vport *vport,
800 struct lpfc_nodelist *ndlp,
804 struct lpfc_hba *phba = vport->phba;
805 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
806 struct lpfc_iocbq *cmdiocb, *rspiocb;
807 struct lpfc_dmabuf *pcmd, *prsp, *mp;
810 struct serv_parm *sp;
813 cmdiocb = (struct lpfc_iocbq *) arg;
814 rspiocb = cmdiocb->context_un.rsp_iocb;
816 if (ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
817 /* Recovery from PLOGI collision logic */
818 return ndlp->nlp_state;
821 irsp = &rspiocb->iocb;
826 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
828 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
830 lp = (uint32_t *) prsp->virt;
831 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
833 /* Some switches have FDMI servers returning 0 for WWN */
834 if ((ndlp->nlp_DID != FDMI_DID) &&
835 (wwn_to_u64(sp->portName.u.wwn) == 0 ||
836 wwn_to_u64(sp->nodeName.u.wwn) == 0)) {
837 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
838 "0142 PLOGI RSP: Invalid WWN.\n");
841 if (!lpfc_check_sparm(vport, ndlp, sp, CLASS3, 0))
843 /* PLOGI chkparm OK */
844 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
845 "0121 PLOGI chkparm OK Data: x%x x%x x%x x%x\n",
846 ndlp->nlp_DID, ndlp->nlp_state,
847 ndlp->nlp_flag, ndlp->nlp_rpi);
848 if (vport->cfg_fcp_class == 2 && (sp->cls2.classValid))
849 ndlp->nlp_fcp_info |= CLASS2;
851 ndlp->nlp_fcp_info |= CLASS3;
853 ndlp->nlp_class_sup = 0;
854 if (sp->cls1.classValid)
855 ndlp->nlp_class_sup |= FC_COS_CLASS1;
856 if (sp->cls2.classValid)
857 ndlp->nlp_class_sup |= FC_COS_CLASS2;
858 if (sp->cls3.classValid)
859 ndlp->nlp_class_sup |= FC_COS_CLASS3;
860 if (sp->cls4.classValid)
861 ndlp->nlp_class_sup |= FC_COS_CLASS4;
863 ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) | sp->cmn.bbRcvSizeLsb;
865 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
867 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
868 "0133 PLOGI: no memory for reg_login "
869 "Data: x%x x%x x%x x%x\n",
870 ndlp->nlp_DID, ndlp->nlp_state,
871 ndlp->nlp_flag, ndlp->nlp_rpi);
875 lpfc_unreg_rpi(vport, ndlp);
877 if (lpfc_reg_rpi(phba, vport->vpi, irsp->un.elsreq64.remoteID,
878 (uint8_t *) sp, mbox, 0) == 0) {
879 switch (ndlp->nlp_DID) {
881 mbox->mbox_cmpl = lpfc_mbx_cmpl_ns_reg_login;
884 mbox->mbox_cmpl = lpfc_mbx_cmpl_fdmi_reg_login;
887 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
889 mbox->context2 = lpfc_nlp_get(ndlp);
891 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
892 != MBX_NOT_FINISHED) {
893 lpfc_nlp_set_state(vport, ndlp,
894 NLP_STE_REG_LOGIN_ISSUE);
895 return ndlp->nlp_state;
897 /* decrement node reference count to the failed mbox
901 mp = (struct lpfc_dmabuf *) mbox->context1;
902 lpfc_mbuf_free(phba, mp->virt, mp->phys);
904 mempool_free(mbox, phba->mbox_mem_pool);
906 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
907 "0134 PLOGI: cannot issue reg_login "
908 "Data: x%x x%x x%x x%x\n",
909 ndlp->nlp_DID, ndlp->nlp_state,
910 ndlp->nlp_flag, ndlp->nlp_rpi);
912 mempool_free(mbox, phba->mbox_mem_pool);
914 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
915 "0135 PLOGI: cannot format reg_login "
916 "Data: x%x x%x x%x x%x\n",
917 ndlp->nlp_DID, ndlp->nlp_state,
918 ndlp->nlp_flag, ndlp->nlp_rpi);
923 if (ndlp->nlp_DID == NameServer_DID) {
924 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
925 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
926 "0261 Cannot Register NameServer login\n");
929 spin_lock_irq(shost->host_lock);
930 ndlp->nlp_flag |= NLP_DEFER_RM;
931 spin_unlock_irq(shost->host_lock);
932 return NLP_STE_FREED_NODE;
936 lpfc_cmpl_logo_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
937 void *arg, uint32_t evt)
939 return ndlp->nlp_state;
943 lpfc_cmpl_reglogin_plogi_issue(struct lpfc_vport *vport,
944 struct lpfc_nodelist *ndlp, void *arg, uint32_t evt)
946 return ndlp->nlp_state;
950 lpfc_device_rm_plogi_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
951 void *arg, uint32_t evt)
953 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
955 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
956 spin_lock_irq(shost->host_lock);
957 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
958 spin_unlock_irq(shost->host_lock);
959 return ndlp->nlp_state;
961 /* software abort outstanding PLOGI */
962 lpfc_els_abort(vport->phba, ndlp);
964 lpfc_drop_node(vport, ndlp);
965 return NLP_STE_FREED_NODE;
970 lpfc_device_recov_plogi_issue(struct lpfc_vport *vport,
971 struct lpfc_nodelist *ndlp,
975 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
976 struct lpfc_hba *phba = vport->phba;
978 /* Don't do anything that will mess up processing of the
981 if (vport->fc_flag & FC_RSCN_DEFERRED)
982 return ndlp->nlp_state;
984 /* software abort outstanding PLOGI */
985 lpfc_els_abort(phba, ndlp);
987 ndlp->nlp_prev_state = NLP_STE_PLOGI_ISSUE;
988 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
989 spin_lock_irq(shost->host_lock);
990 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
991 spin_unlock_irq(shost->host_lock);
993 return ndlp->nlp_state;
997 lpfc_rcv_plogi_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
998 void *arg, uint32_t evt)
1000 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1001 struct lpfc_hba *phba = vport->phba;
1002 struct lpfc_iocbq *cmdiocb;
1004 /* software abort outstanding ADISC */
1005 lpfc_els_abort(phba, ndlp);
1007 cmdiocb = (struct lpfc_iocbq *) arg;
1009 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
1010 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1011 spin_lock_irq(shost->host_lock);
1012 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1013 spin_unlock_irq(shost->host_lock);
1014 if (vport->num_disc_nodes)
1015 lpfc_more_adisc(vport);
1017 return ndlp->nlp_state;
1019 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1020 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
1021 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1023 return ndlp->nlp_state;
1027 lpfc_rcv_prli_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1028 void *arg, uint32_t evt)
1030 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1032 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1033 return ndlp->nlp_state;
1037 lpfc_rcv_logo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1038 void *arg, uint32_t evt)
1040 struct lpfc_hba *phba = vport->phba;
1041 struct lpfc_iocbq *cmdiocb;
1043 cmdiocb = (struct lpfc_iocbq *) arg;
1045 /* software abort outstanding ADISC */
1046 lpfc_els_abort(phba, ndlp);
1048 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1049 return ndlp->nlp_state;
1053 lpfc_rcv_padisc_adisc_issue(struct lpfc_vport *vport,
1054 struct lpfc_nodelist *ndlp,
1055 void *arg, uint32_t evt)
1057 struct lpfc_iocbq *cmdiocb;
1059 cmdiocb = (struct lpfc_iocbq *) arg;
1061 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1062 return ndlp->nlp_state;
1066 lpfc_rcv_prlo_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1067 void *arg, uint32_t evt)
1069 struct lpfc_iocbq *cmdiocb;
1071 cmdiocb = (struct lpfc_iocbq *) arg;
1073 /* Treat like rcv logo */
1074 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
1075 return ndlp->nlp_state;
1079 lpfc_cmpl_adisc_adisc_issue(struct lpfc_vport *vport,
1080 struct lpfc_nodelist *ndlp,
1081 void *arg, uint32_t evt)
1083 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1084 struct lpfc_hba *phba = vport->phba;
1085 struct lpfc_iocbq *cmdiocb, *rspiocb;
1090 cmdiocb = (struct lpfc_iocbq *) arg;
1091 rspiocb = cmdiocb->context_un.rsp_iocb;
1093 ap = (ADISC *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1094 irsp = &rspiocb->iocb;
1096 if ((irsp->ulpStatus) ||
1097 (!lpfc_check_adisc(vport, ndlp, &ap->nodeName, &ap->portName))) {
1099 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
1100 spin_lock_irq(shost->host_lock);
1101 ndlp->nlp_flag |= NLP_DELAY_TMO;
1102 spin_unlock_irq(shost->host_lock);
1103 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1105 memset(&ndlp->nlp_nodename, 0, sizeof(struct lpfc_name));
1106 memset(&ndlp->nlp_portname, 0, sizeof(struct lpfc_name));
1108 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1109 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1110 lpfc_unreg_rpi(vport, ndlp);
1111 return ndlp->nlp_state;
1114 if (phba->sli_rev == LPFC_SLI_REV4) {
1115 rc = lpfc_sli4_resume_rpi(ndlp);
1117 /* Stay in state and retry. */
1118 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1119 return ndlp->nlp_state;
1123 if (ndlp->nlp_type & NLP_FCP_TARGET) {
1124 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1125 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
1127 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1128 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1131 return ndlp->nlp_state;
1135 lpfc_device_rm_adisc_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1136 void *arg, uint32_t evt)
1138 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1140 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1141 spin_lock_irq(shost->host_lock);
1142 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1143 spin_unlock_irq(shost->host_lock);
1144 return ndlp->nlp_state;
1146 /* software abort outstanding ADISC */
1147 lpfc_els_abort(vport->phba, ndlp);
1149 lpfc_drop_node(vport, ndlp);
1150 return NLP_STE_FREED_NODE;
1155 lpfc_device_recov_adisc_issue(struct lpfc_vport *vport,
1156 struct lpfc_nodelist *ndlp,
1160 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1161 struct lpfc_hba *phba = vport->phba;
1163 /* Don't do anything that will mess up processing of the
1166 if (vport->fc_flag & FC_RSCN_DEFERRED)
1167 return ndlp->nlp_state;
1169 /* software abort outstanding ADISC */
1170 lpfc_els_abort(phba, ndlp);
1172 ndlp->nlp_prev_state = NLP_STE_ADISC_ISSUE;
1173 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1174 spin_lock_irq(shost->host_lock);
1175 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1176 spin_unlock_irq(shost->host_lock);
1177 lpfc_disc_set_adisc(vport, ndlp);
1178 return ndlp->nlp_state;
1182 lpfc_rcv_plogi_reglogin_issue(struct lpfc_vport *vport,
1183 struct lpfc_nodelist *ndlp,
1187 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1189 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
1190 return ndlp->nlp_state;
1194 lpfc_rcv_prli_reglogin_issue(struct lpfc_vport *vport,
1195 struct lpfc_nodelist *ndlp,
1199 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1201 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1202 return ndlp->nlp_state;
1206 lpfc_rcv_logo_reglogin_issue(struct lpfc_vport *vport,
1207 struct lpfc_nodelist *ndlp,
1211 struct lpfc_hba *phba = vport->phba;
1212 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1214 LPFC_MBOXQ_t *nextmb;
1215 struct lpfc_dmabuf *mp;
1217 cmdiocb = (struct lpfc_iocbq *) arg;
1219 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
1220 if ((mb = phba->sli.mbox_active)) {
1221 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
1222 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1224 mb->context2 = NULL;
1225 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1229 spin_lock_irq(&phba->hbalock);
1230 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
1231 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
1232 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1233 if (phba->sli_rev == LPFC_SLI_REV4) {
1234 spin_unlock_irq(&phba->hbalock);
1235 lpfc_sli4_free_rpi(phba,
1236 mb->u.mb.un.varRegLogin.rpi);
1237 spin_lock_irq(&phba->hbalock);
1239 mp = (struct lpfc_dmabuf *) (mb->context1);
1241 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
1245 list_del(&mb->list);
1246 phba->sli.mboxq_cnt--;
1247 mempool_free(mb, phba->mbox_mem_pool);
1250 spin_unlock_irq(&phba->hbalock);
1252 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1253 return ndlp->nlp_state;
1257 lpfc_rcv_padisc_reglogin_issue(struct lpfc_vport *vport,
1258 struct lpfc_nodelist *ndlp,
1262 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1264 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1265 return ndlp->nlp_state;
1269 lpfc_rcv_prlo_reglogin_issue(struct lpfc_vport *vport,
1270 struct lpfc_nodelist *ndlp,
1274 struct lpfc_iocbq *cmdiocb;
1276 cmdiocb = (struct lpfc_iocbq *) arg;
1277 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
1278 return ndlp->nlp_state;
1282 lpfc_cmpl_reglogin_reglogin_issue(struct lpfc_vport *vport,
1283 struct lpfc_nodelist *ndlp,
1287 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1288 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1289 MAILBOX_t *mb = &pmb->u.mb;
1290 uint32_t did = mb->un.varWords[1];
1292 if (mb->mbxStatus) {
1293 /* RegLogin failed */
1294 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1295 "0246 RegLogin failed Data: x%x x%x x%x\n",
1296 did, mb->mbxStatus, vport->port_state);
1298 * If RegLogin failed due to lack of HBA resources do not
1301 if (mb->mbxStatus == MBXERR_RPI_FULL) {
1302 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1303 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1304 return ndlp->nlp_state;
1307 /* Put ndlp in npr state set plogi timer for 1 sec */
1308 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
1309 spin_lock_irq(shost->host_lock);
1310 ndlp->nlp_flag |= NLP_DELAY_TMO;
1311 spin_unlock_irq(shost->host_lock);
1312 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1314 lpfc_issue_els_logo(vport, ndlp, 0);
1315 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1316 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1317 return ndlp->nlp_state;
1320 ndlp->nlp_rpi = mb->un.varWords[0];
1321 ndlp->nlp_flag |= NLP_RPI_VALID;
1323 /* Only if we are not a fabric nport do we issue PRLI */
1324 if (!(ndlp->nlp_type & NLP_FABRIC)) {
1325 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1326 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
1327 lpfc_issue_els_prli(vport, ndlp, 0);
1329 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1330 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1332 return ndlp->nlp_state;
1336 lpfc_device_rm_reglogin_issue(struct lpfc_vport *vport,
1337 struct lpfc_nodelist *ndlp,
1341 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1343 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1344 spin_lock_irq(shost->host_lock);
1345 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1346 spin_unlock_irq(shost->host_lock);
1347 return ndlp->nlp_state;
1349 lpfc_drop_node(vport, ndlp);
1350 return NLP_STE_FREED_NODE;
1355 lpfc_device_recov_reglogin_issue(struct lpfc_vport *vport,
1356 struct lpfc_nodelist *ndlp,
1360 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1362 /* Don't do anything that will mess up processing of the
1365 if (vport->fc_flag & FC_RSCN_DEFERRED)
1366 return ndlp->nlp_state;
1368 ndlp->nlp_prev_state = NLP_STE_REG_LOGIN_ISSUE;
1369 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1370 spin_lock_irq(shost->host_lock);
1371 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1372 spin_unlock_irq(shost->host_lock);
1373 lpfc_disc_set_adisc(vport, ndlp);
1374 return ndlp->nlp_state;
1378 lpfc_rcv_plogi_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1379 void *arg, uint32_t evt)
1381 struct lpfc_iocbq *cmdiocb;
1383 cmdiocb = (struct lpfc_iocbq *) arg;
1385 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
1386 return ndlp->nlp_state;
1390 lpfc_rcv_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1391 void *arg, uint32_t evt)
1393 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1395 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1396 return ndlp->nlp_state;
1400 lpfc_rcv_logo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1401 void *arg, uint32_t evt)
1403 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1405 /* Software abort outstanding PRLI before sending acc */
1406 lpfc_els_abort(vport->phba, ndlp);
1408 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1409 return ndlp->nlp_state;
1413 lpfc_rcv_padisc_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1414 void *arg, uint32_t evt)
1416 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1418 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1419 return ndlp->nlp_state;
1422 /* This routine is envoked when we rcv a PRLO request from a nport
1423 * we are logged into. We should send back a PRLO rsp setting the
1425 * NEXT STATE = PRLI_ISSUE
1428 lpfc_rcv_prlo_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1429 void *arg, uint32_t evt)
1431 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1433 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
1434 return ndlp->nlp_state;
1438 lpfc_cmpl_prli_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1439 void *arg, uint32_t evt)
1441 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1442 struct lpfc_iocbq *cmdiocb, *rspiocb;
1443 struct lpfc_hba *phba = vport->phba;
1447 cmdiocb = (struct lpfc_iocbq *) arg;
1448 rspiocb = cmdiocb->context_un.rsp_iocb;
1449 npr = (PRLI *)lpfc_check_elscmpl_iocb(phba, cmdiocb, rspiocb);
1451 irsp = &rspiocb->iocb;
1452 if (irsp->ulpStatus) {
1453 if ((vport->port_type == LPFC_NPIV_PORT) &&
1454 vport->cfg_restrict_login) {
1457 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
1458 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1459 return ndlp->nlp_state;
1462 /* Check out PRLI rsp */
1463 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
1464 ndlp->nlp_fcp_info &= ~NLP_FCP_2_DEVICE;
1465 if ((npr->acceptRspCode == PRLI_REQ_EXECUTED) &&
1466 (npr->prliType == PRLI_FCP_TYPE)) {
1467 if (npr->initiatorFunc)
1468 ndlp->nlp_type |= NLP_FCP_INITIATOR;
1469 if (npr->targetFunc)
1470 ndlp->nlp_type |= NLP_FCP_TARGET;
1472 ndlp->nlp_fcp_info |= NLP_FCP_2_DEVICE;
1474 if (!(ndlp->nlp_type & NLP_FCP_TARGET) &&
1475 (vport->port_type == LPFC_NPIV_PORT) &&
1476 vport->cfg_restrict_login) {
1478 spin_lock_irq(shost->host_lock);
1479 ndlp->nlp_flag |= NLP_TARGET_REMOVE;
1480 spin_unlock_irq(shost->host_lock);
1481 lpfc_issue_els_logo(vport, ndlp, 0);
1483 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
1484 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1485 return ndlp->nlp_state;
1488 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
1489 if (ndlp->nlp_type & NLP_FCP_TARGET)
1490 lpfc_nlp_set_state(vport, ndlp, NLP_STE_MAPPED_NODE);
1492 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
1493 return ndlp->nlp_state;
1496 /*! lpfc_device_rm_prli_issue
1507 * This routine is envoked when we a request to remove a nport we are in the
1508 * process of PRLIing. We should software abort outstanding prli, unreg
1509 * login, send a logout. We will change node state to UNUSED_NODE, put it
1510 * on plogi list so it can be freed when LOGO completes.
1515 lpfc_device_rm_prli_issue(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1516 void *arg, uint32_t evt)
1518 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1520 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1521 spin_lock_irq(shost->host_lock);
1522 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1523 spin_unlock_irq(shost->host_lock);
1524 return ndlp->nlp_state;
1526 /* software abort outstanding PLOGI */
1527 lpfc_els_abort(vport->phba, ndlp);
1529 lpfc_drop_node(vport, ndlp);
1530 return NLP_STE_FREED_NODE;
1535 /*! lpfc_device_recov_prli_issue
1546 * The routine is envoked when the state of a device is unknown, like
1547 * during a link down. We should remove the nodelist entry from the
1548 * unmapped list, issue a UNREG_LOGIN, do a software abort of the
1549 * outstanding PRLI command, then free the node entry.
1552 lpfc_device_recov_prli_issue(struct lpfc_vport *vport,
1553 struct lpfc_nodelist *ndlp,
1557 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1558 struct lpfc_hba *phba = vport->phba;
1560 /* Don't do anything that will mess up processing of the
1563 if (vport->fc_flag & FC_RSCN_DEFERRED)
1564 return ndlp->nlp_state;
1566 /* software abort outstanding PRLI */
1567 lpfc_els_abort(phba, ndlp);
1569 ndlp->nlp_prev_state = NLP_STE_PRLI_ISSUE;
1570 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1571 spin_lock_irq(shost->host_lock);
1572 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1573 spin_unlock_irq(shost->host_lock);
1574 lpfc_disc_set_adisc(vport, ndlp);
1575 return ndlp->nlp_state;
1579 lpfc_rcv_plogi_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1580 void *arg, uint32_t evt)
1582 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1584 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
1585 return ndlp->nlp_state;
1589 lpfc_rcv_prli_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1590 void *arg, uint32_t evt)
1592 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1594 lpfc_rcv_prli(vport, ndlp, cmdiocb);
1595 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1596 return ndlp->nlp_state;
1600 lpfc_rcv_logo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1601 void *arg, uint32_t evt)
1603 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1605 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1606 return ndlp->nlp_state;
1610 lpfc_rcv_padisc_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1611 void *arg, uint32_t evt)
1613 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1615 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1616 return ndlp->nlp_state;
1620 lpfc_rcv_prlo_unmap_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1621 void *arg, uint32_t evt)
1623 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1625 lpfc_els_rsp_acc(vport, ELS_CMD_PRLO, cmdiocb, ndlp, NULL);
1626 return ndlp->nlp_state;
1630 lpfc_device_recov_unmap_node(struct lpfc_vport *vport,
1631 struct lpfc_nodelist *ndlp,
1635 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1637 ndlp->nlp_prev_state = NLP_STE_UNMAPPED_NODE;
1638 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1639 spin_lock_irq(shost->host_lock);
1640 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1641 spin_unlock_irq(shost->host_lock);
1642 lpfc_disc_set_adisc(vport, ndlp);
1644 return ndlp->nlp_state;
1648 lpfc_rcv_plogi_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1649 void *arg, uint32_t evt)
1651 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1653 lpfc_rcv_plogi(vport, ndlp, cmdiocb);
1654 return ndlp->nlp_state;
1658 lpfc_rcv_prli_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1659 void *arg, uint32_t evt)
1661 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1663 lpfc_els_rsp_prli_acc(vport, cmdiocb, ndlp);
1664 return ndlp->nlp_state;
1668 lpfc_rcv_logo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1669 void *arg, uint32_t evt)
1671 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1673 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1674 return ndlp->nlp_state;
1678 lpfc_rcv_padisc_mapped_node(struct lpfc_vport *vport,
1679 struct lpfc_nodelist *ndlp,
1680 void *arg, uint32_t evt)
1682 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1684 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1685 return ndlp->nlp_state;
1689 lpfc_rcv_prlo_mapped_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1690 void *arg, uint32_t evt)
1692 struct lpfc_hba *phba = vport->phba;
1693 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1695 /* flush the target */
1696 lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring],
1697 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
1699 /* Treat like rcv logo */
1700 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_PRLO);
1701 return ndlp->nlp_state;
1705 lpfc_device_recov_mapped_node(struct lpfc_vport *vport,
1706 struct lpfc_nodelist *ndlp,
1710 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1712 ndlp->nlp_prev_state = NLP_STE_MAPPED_NODE;
1713 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1714 spin_lock_irq(shost->host_lock);
1715 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1716 spin_unlock_irq(shost->host_lock);
1717 lpfc_disc_set_adisc(vport, ndlp);
1718 return ndlp->nlp_state;
1722 lpfc_rcv_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1723 void *arg, uint32_t evt)
1725 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1726 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1728 /* Ignore PLOGI if we have an outstanding LOGO */
1729 if (ndlp->nlp_flag & (NLP_LOGO_SND | NLP_LOGO_ACC))
1730 return ndlp->nlp_state;
1731 if (lpfc_rcv_plogi(vport, ndlp, cmdiocb)) {
1732 lpfc_cancel_retry_delay_tmo(vport, ndlp);
1733 spin_lock_irq(shost->host_lock);
1734 ndlp->nlp_flag &= ~(NLP_NPR_ADISC | NLP_NPR_2B_DISC);
1735 spin_unlock_irq(shost->host_lock);
1736 } else if (!(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
1737 /* send PLOGI immediately, move to PLOGI issue state */
1738 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
1739 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
1740 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1741 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
1744 return ndlp->nlp_state;
1748 lpfc_rcv_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1749 void *arg, uint32_t evt)
1751 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1752 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1755 memset(&stat, 0, sizeof (struct ls_rjt));
1756 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
1757 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
1758 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
1760 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
1761 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
1762 spin_lock_irq(shost->host_lock);
1763 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1764 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
1765 spin_unlock_irq(shost->host_lock);
1766 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
1767 lpfc_issue_els_adisc(vport, ndlp, 0);
1769 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
1770 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1771 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
1774 return ndlp->nlp_state;
1778 lpfc_rcv_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1779 void *arg, uint32_t evt)
1781 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1783 lpfc_rcv_logo(vport, ndlp, cmdiocb, ELS_CMD_LOGO);
1784 return ndlp->nlp_state;
1788 lpfc_rcv_padisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1789 void *arg, uint32_t evt)
1791 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1793 lpfc_rcv_padisc(vport, ndlp, cmdiocb);
1795 * Do not start discovery if discovery is about to start
1796 * or discovery in progress for this node. Starting discovery
1797 * here will affect the counting of discovery threads.
1799 if (!(ndlp->nlp_flag & NLP_DELAY_TMO) &&
1800 !(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
1801 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
1802 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1803 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
1804 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
1805 lpfc_issue_els_adisc(vport, ndlp, 0);
1807 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
1808 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1809 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
1812 return ndlp->nlp_state;
1816 lpfc_rcv_prlo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1817 void *arg, uint32_t evt)
1819 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1820 struct lpfc_iocbq *cmdiocb = (struct lpfc_iocbq *) arg;
1822 spin_lock_irq(shost->host_lock);
1823 ndlp->nlp_flag |= NLP_LOGO_ACC;
1824 spin_unlock_irq(shost->host_lock);
1826 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
1828 if ((ndlp->nlp_flag & NLP_DELAY_TMO) == 0) {
1829 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ * 1);
1830 spin_lock_irq(shost->host_lock);
1831 ndlp->nlp_flag |= NLP_DELAY_TMO;
1832 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1833 spin_unlock_irq(shost->host_lock);
1834 ndlp->nlp_last_elscmd = ELS_CMD_PLOGI;
1836 spin_lock_irq(shost->host_lock);
1837 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
1838 spin_unlock_irq(shost->host_lock);
1840 return ndlp->nlp_state;
1844 lpfc_cmpl_plogi_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1845 void *arg, uint32_t evt)
1847 struct lpfc_iocbq *cmdiocb, *rspiocb;
1850 cmdiocb = (struct lpfc_iocbq *) arg;
1851 rspiocb = cmdiocb->context_un.rsp_iocb;
1853 irsp = &rspiocb->iocb;
1854 if (irsp->ulpStatus) {
1855 ndlp->nlp_flag |= NLP_DEFER_RM;
1856 return NLP_STE_FREED_NODE;
1858 return ndlp->nlp_state;
1862 lpfc_cmpl_prli_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1863 void *arg, uint32_t evt)
1865 struct lpfc_iocbq *cmdiocb, *rspiocb;
1868 cmdiocb = (struct lpfc_iocbq *) arg;
1869 rspiocb = cmdiocb->context_un.rsp_iocb;
1871 irsp = &rspiocb->iocb;
1872 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
1873 lpfc_drop_node(vport, ndlp);
1874 return NLP_STE_FREED_NODE;
1876 return ndlp->nlp_state;
1880 lpfc_cmpl_logo_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1881 void *arg, uint32_t evt)
1883 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1884 if (ndlp->nlp_DID == Fabric_DID) {
1885 spin_lock_irq(shost->host_lock);
1886 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
1887 spin_unlock_irq(shost->host_lock);
1889 lpfc_unreg_rpi(vport, ndlp);
1890 return ndlp->nlp_state;
1894 lpfc_cmpl_adisc_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1895 void *arg, uint32_t evt)
1897 struct lpfc_iocbq *cmdiocb, *rspiocb;
1900 cmdiocb = (struct lpfc_iocbq *) arg;
1901 rspiocb = cmdiocb->context_un.rsp_iocb;
1903 irsp = &rspiocb->iocb;
1904 if (irsp->ulpStatus && (ndlp->nlp_flag & NLP_NODEV_REMOVE)) {
1905 lpfc_drop_node(vport, ndlp);
1906 return NLP_STE_FREED_NODE;
1908 return ndlp->nlp_state;
1912 lpfc_cmpl_reglogin_npr_node(struct lpfc_vport *vport,
1913 struct lpfc_nodelist *ndlp,
1914 void *arg, uint32_t evt)
1916 LPFC_MBOXQ_t *pmb = (LPFC_MBOXQ_t *) arg;
1917 MAILBOX_t *mb = &pmb->u.mb;
1919 if (!mb->mbxStatus) {
1920 ndlp->nlp_rpi = mb->un.varWords[0];
1921 ndlp->nlp_flag |= NLP_RPI_VALID;
1923 if (ndlp->nlp_flag & NLP_NODEV_REMOVE) {
1924 lpfc_drop_node(vport, ndlp);
1925 return NLP_STE_FREED_NODE;
1928 return ndlp->nlp_state;
1932 lpfc_device_rm_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1933 void *arg, uint32_t evt)
1935 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1937 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
1938 spin_lock_irq(shost->host_lock);
1939 ndlp->nlp_flag |= NLP_NODEV_REMOVE;
1940 spin_unlock_irq(shost->host_lock);
1941 return ndlp->nlp_state;
1943 lpfc_drop_node(vport, ndlp);
1944 return NLP_STE_FREED_NODE;
1948 lpfc_device_recov_npr_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1949 void *arg, uint32_t evt)
1951 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1953 /* Don't do anything that will mess up processing of the
1956 if (vport->fc_flag & FC_RSCN_DEFERRED)
1957 return ndlp->nlp_state;
1959 lpfc_cancel_retry_delay_tmo(vport, ndlp);
1960 spin_lock_irq(shost->host_lock);
1961 ndlp->nlp_flag &= ~(NLP_NODEV_REMOVE | NLP_NPR_2B_DISC);
1962 spin_unlock_irq(shost->host_lock);
1963 return ndlp->nlp_state;
1967 /* This next section defines the NPort Discovery State Machine */
1969 /* There are 4 different double linked lists nodelist entries can reside on.
1970 * The plogi list and adisc list are used when Link Up discovery or RSCN
1971 * processing is needed. Each list holds the nodes that we will send PLOGI
1972 * or ADISC on. These lists will keep track of what nodes will be effected
1973 * by an RSCN, or a Link Up (Typically, all nodes are effected on Link Up).
1974 * The unmapped_list will contain all nodes that we have successfully logged
1975 * into at the Fibre Channel level. The mapped_list will contain all nodes
1976 * that are mapped FCP targets.
1979 * The bind list is a list of undiscovered (potentially non-existent) nodes
1980 * that we have saved binding information on. This information is used when
1981 * nodes transition from the unmapped to the mapped list.
1983 /* For UNUSED_NODE state, the node has just been allocated .
1984 * For PLOGI_ISSUE and REG_LOGIN_ISSUE, the node is on
1985 * the PLOGI list. For REG_LOGIN_COMPL, the node is taken off the PLOGI list
1986 * and put on the unmapped list. For ADISC processing, the node is taken off
1987 * the ADISC list and placed on either the mapped or unmapped list (depending
1988 * on its previous state). Once on the unmapped list, a PRLI is issued and the
1989 * state changed to PRLI_ISSUE. When the PRLI completion occurs, the state is
1990 * changed to UNMAPPED_NODE. If the completion indicates a mapped
1991 * node, the node is taken off the unmapped list. The binding list is checked
1992 * for a valid binding, or a binding is automatically assigned. If binding
1993 * assignment is unsuccessful, the node is left on the unmapped list. If
1994 * binding assignment is successful, the associated binding list entry (if
1995 * any) is removed, and the node is placed on the mapped list.
1998 * For a Link Down, all nodes on the ADISC, PLOGI, unmapped or mapped
1999 * lists will receive a DEVICE_RECOVERY event. If the linkdown or devloss timers
2000 * expire, all effected nodes will receive a DEVICE_RM event.
2003 * For a Link Up or RSCN, all nodes will move from the mapped / unmapped lists
2004 * to either the ADISC or PLOGI list. After a Nameserver query or ALPA loopmap
2005 * check, additional nodes may be added or removed (via DEVICE_RM) to / from
2006 * the PLOGI or ADISC lists. Once the PLOGI and ADISC lists are populated,
2007 * we will first process the ADISC list. 32 entries are processed initially and
2008 * ADISC is initited for each one. Completions / Events for each node are
2009 * funnelled thru the state machine. As each node finishes ADISC processing, it
2010 * starts ADISC for any nodes waiting for ADISC processing. If no nodes are
2011 * waiting, and the ADISC list count is identically 0, then we are done. For
2012 * Link Up discovery, since all nodes on the PLOGI list are UNREG_LOGIN'ed, we
2013 * can issue a CLEAR_LA and reenable Link Events. Next we will process the PLOGI
2014 * list. 32 entries are processed initially and PLOGI is initited for each one.
2015 * Completions / Events for each node are funnelled thru the state machine. As
2016 * each node finishes PLOGI processing, it starts PLOGI for any nodes waiting
2017 * for PLOGI processing. If no nodes are waiting, and the PLOGI list count is
2018 * indentically 0, then we are done. We have now completed discovery / RSCN
2019 * handling. Upon completion, ALL nodes should be on either the mapped or
2023 static uint32_t (*lpfc_disc_action[NLP_STE_MAX_STATE * NLP_EVT_MAX_EVENT])
2024 (struct lpfc_vport *, struct lpfc_nodelist *, void *, uint32_t) = {
2025 /* Action routine Event Current State */
2026 lpfc_rcv_plogi_unused_node, /* RCV_PLOGI UNUSED_NODE */
2027 lpfc_rcv_els_unused_node, /* RCV_PRLI */
2028 lpfc_rcv_logo_unused_node, /* RCV_LOGO */
2029 lpfc_rcv_els_unused_node, /* RCV_ADISC */
2030 lpfc_rcv_els_unused_node, /* RCV_PDISC */
2031 lpfc_rcv_els_unused_node, /* RCV_PRLO */
2032 lpfc_disc_illegal, /* CMPL_PLOGI */
2033 lpfc_disc_illegal, /* CMPL_PRLI */
2034 lpfc_cmpl_logo_unused_node, /* CMPL_LOGO */
2035 lpfc_disc_illegal, /* CMPL_ADISC */
2036 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2037 lpfc_device_rm_unused_node, /* DEVICE_RM */
2038 lpfc_disc_illegal, /* DEVICE_RECOVERY */
2040 lpfc_rcv_plogi_plogi_issue, /* RCV_PLOGI PLOGI_ISSUE */
2041 lpfc_rcv_prli_plogi_issue, /* RCV_PRLI */
2042 lpfc_rcv_logo_plogi_issue, /* RCV_LOGO */
2043 lpfc_rcv_els_plogi_issue, /* RCV_ADISC */
2044 lpfc_rcv_els_plogi_issue, /* RCV_PDISC */
2045 lpfc_rcv_els_plogi_issue, /* RCV_PRLO */
2046 lpfc_cmpl_plogi_plogi_issue, /* CMPL_PLOGI */
2047 lpfc_disc_illegal, /* CMPL_PRLI */
2048 lpfc_cmpl_logo_plogi_issue, /* CMPL_LOGO */
2049 lpfc_disc_illegal, /* CMPL_ADISC */
2050 lpfc_cmpl_reglogin_plogi_issue,/* CMPL_REG_LOGIN */
2051 lpfc_device_rm_plogi_issue, /* DEVICE_RM */
2052 lpfc_device_recov_plogi_issue, /* DEVICE_RECOVERY */
2054 lpfc_rcv_plogi_adisc_issue, /* RCV_PLOGI ADISC_ISSUE */
2055 lpfc_rcv_prli_adisc_issue, /* RCV_PRLI */
2056 lpfc_rcv_logo_adisc_issue, /* RCV_LOGO */
2057 lpfc_rcv_padisc_adisc_issue, /* RCV_ADISC */
2058 lpfc_rcv_padisc_adisc_issue, /* RCV_PDISC */
2059 lpfc_rcv_prlo_adisc_issue, /* RCV_PRLO */
2060 lpfc_disc_illegal, /* CMPL_PLOGI */
2061 lpfc_disc_illegal, /* CMPL_PRLI */
2062 lpfc_disc_illegal, /* CMPL_LOGO */
2063 lpfc_cmpl_adisc_adisc_issue, /* CMPL_ADISC */
2064 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2065 lpfc_device_rm_adisc_issue, /* DEVICE_RM */
2066 lpfc_device_recov_adisc_issue, /* DEVICE_RECOVERY */
2068 lpfc_rcv_plogi_reglogin_issue, /* RCV_PLOGI REG_LOGIN_ISSUE */
2069 lpfc_rcv_prli_reglogin_issue, /* RCV_PLOGI */
2070 lpfc_rcv_logo_reglogin_issue, /* RCV_LOGO */
2071 lpfc_rcv_padisc_reglogin_issue, /* RCV_ADISC */
2072 lpfc_rcv_padisc_reglogin_issue, /* RCV_PDISC */
2073 lpfc_rcv_prlo_reglogin_issue, /* RCV_PRLO */
2074 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
2075 lpfc_disc_illegal, /* CMPL_PRLI */
2076 lpfc_disc_illegal, /* CMPL_LOGO */
2077 lpfc_disc_illegal, /* CMPL_ADISC */
2078 lpfc_cmpl_reglogin_reglogin_issue,/* CMPL_REG_LOGIN */
2079 lpfc_device_rm_reglogin_issue, /* DEVICE_RM */
2080 lpfc_device_recov_reglogin_issue,/* DEVICE_RECOVERY */
2082 lpfc_rcv_plogi_prli_issue, /* RCV_PLOGI PRLI_ISSUE */
2083 lpfc_rcv_prli_prli_issue, /* RCV_PRLI */
2084 lpfc_rcv_logo_prli_issue, /* RCV_LOGO */
2085 lpfc_rcv_padisc_prli_issue, /* RCV_ADISC */
2086 lpfc_rcv_padisc_prli_issue, /* RCV_PDISC */
2087 lpfc_rcv_prlo_prli_issue, /* RCV_PRLO */
2088 lpfc_cmpl_plogi_illegal, /* CMPL_PLOGI */
2089 lpfc_cmpl_prli_prli_issue, /* CMPL_PRLI */
2090 lpfc_disc_illegal, /* CMPL_LOGO */
2091 lpfc_disc_illegal, /* CMPL_ADISC */
2092 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2093 lpfc_device_rm_prli_issue, /* DEVICE_RM */
2094 lpfc_device_recov_prli_issue, /* DEVICE_RECOVERY */
2096 lpfc_rcv_plogi_unmap_node, /* RCV_PLOGI UNMAPPED_NODE */
2097 lpfc_rcv_prli_unmap_node, /* RCV_PRLI */
2098 lpfc_rcv_logo_unmap_node, /* RCV_LOGO */
2099 lpfc_rcv_padisc_unmap_node, /* RCV_ADISC */
2100 lpfc_rcv_padisc_unmap_node, /* RCV_PDISC */
2101 lpfc_rcv_prlo_unmap_node, /* RCV_PRLO */
2102 lpfc_disc_illegal, /* CMPL_PLOGI */
2103 lpfc_disc_illegal, /* CMPL_PRLI */
2104 lpfc_disc_illegal, /* CMPL_LOGO */
2105 lpfc_disc_illegal, /* CMPL_ADISC */
2106 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2107 lpfc_disc_illegal, /* DEVICE_RM */
2108 lpfc_device_recov_unmap_node, /* DEVICE_RECOVERY */
2110 lpfc_rcv_plogi_mapped_node, /* RCV_PLOGI MAPPED_NODE */
2111 lpfc_rcv_prli_mapped_node, /* RCV_PRLI */
2112 lpfc_rcv_logo_mapped_node, /* RCV_LOGO */
2113 lpfc_rcv_padisc_mapped_node, /* RCV_ADISC */
2114 lpfc_rcv_padisc_mapped_node, /* RCV_PDISC */
2115 lpfc_rcv_prlo_mapped_node, /* RCV_PRLO */
2116 lpfc_disc_illegal, /* CMPL_PLOGI */
2117 lpfc_disc_illegal, /* CMPL_PRLI */
2118 lpfc_disc_illegal, /* CMPL_LOGO */
2119 lpfc_disc_illegal, /* CMPL_ADISC */
2120 lpfc_disc_illegal, /* CMPL_REG_LOGIN */
2121 lpfc_disc_illegal, /* DEVICE_RM */
2122 lpfc_device_recov_mapped_node, /* DEVICE_RECOVERY */
2124 lpfc_rcv_plogi_npr_node, /* RCV_PLOGI NPR_NODE */
2125 lpfc_rcv_prli_npr_node, /* RCV_PRLI */
2126 lpfc_rcv_logo_npr_node, /* RCV_LOGO */
2127 lpfc_rcv_padisc_npr_node, /* RCV_ADISC */
2128 lpfc_rcv_padisc_npr_node, /* RCV_PDISC */
2129 lpfc_rcv_prlo_npr_node, /* RCV_PRLO */
2130 lpfc_cmpl_plogi_npr_node, /* CMPL_PLOGI */
2131 lpfc_cmpl_prli_npr_node, /* CMPL_PRLI */
2132 lpfc_cmpl_logo_npr_node, /* CMPL_LOGO */
2133 lpfc_cmpl_adisc_npr_node, /* CMPL_ADISC */
2134 lpfc_cmpl_reglogin_npr_node, /* CMPL_REG_LOGIN */
2135 lpfc_device_rm_npr_node, /* DEVICE_RM */
2136 lpfc_device_recov_npr_node, /* DEVICE_RECOVERY */
2140 lpfc_disc_state_machine(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2141 void *arg, uint32_t evt)
2143 uint32_t cur_state, rc;
2144 uint32_t(*func) (struct lpfc_vport *, struct lpfc_nodelist *, void *,
2146 uint32_t got_ndlp = 0;
2148 if (lpfc_nlp_get(ndlp))
2151 cur_state = ndlp->nlp_state;
2153 /* DSM in event <evt> on NPort <nlp_DID> in state <cur_state> */
2154 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2155 "0211 DSM in event x%x on NPort x%x in "
2156 "state %d Data: x%x\n",
2157 evt, ndlp->nlp_DID, cur_state, ndlp->nlp_flag);
2159 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2160 "DSM in: evt:%d ste:%d did:x%x",
2161 evt, cur_state, ndlp->nlp_DID);
2163 func = lpfc_disc_action[(cur_state * NLP_EVT_MAX_EVENT) + evt];
2164 rc = (func) (vport, ndlp, arg, evt);
2166 /* DSM out state <rc> on NPort <nlp_DID> */
2168 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2169 "0212 DSM out state %d on NPort x%x Data: x%x\n",
2170 rc, ndlp->nlp_DID, ndlp->nlp_flag);
2172 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2173 "DSM out: ste:%d did:x%x flg:x%x",
2174 rc, ndlp->nlp_DID, ndlp->nlp_flag);
2175 /* Decrement the ndlp reference count held for this function */
2178 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2179 "0213 DSM out state %d on NPort free\n", rc);
2181 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_DSM,
2182 "DSM out: ste:%d did:x%x flg:x%x",