1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2005 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"
39 static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *,
41 static int lpfc_max_els_tries = 3;
44 lpfc_els_chk_latt(struct lpfc_hba * phba)
46 struct lpfc_sli *psli;
53 if ((phba->hba_state >= LPFC_HBA_READY) ||
54 (phba->hba_state == LPFC_LINK_DOWN))
57 /* Read the HBA Host Attention Register */
58 spin_lock_irq(phba->host->host_lock);
59 ha_copy = readl(phba->HAregaddr);
60 spin_unlock_irq(phba->host->host_lock);
62 if (!(ha_copy & HA_LATT))
65 /* Pending Link Event during Discovery */
66 lpfc_printf_log(phba, KERN_WARNING, LOG_DISCOVERY,
67 "%d:0237 Pending Link Event during "
68 "Discovery: State x%x\n",
69 phba->brd_no, phba->hba_state);
71 /* CLEAR_LA should re-enable link attention events and
72 * we should then imediately take a LATT event. The
73 * LATT processing should call lpfc_linkdown() which
74 * will cleanup any left over in-progress discovery
77 spin_lock_irq(phba->host->host_lock);
78 phba->fc_flag |= FC_ABORT_DISCOVERY;
79 spin_unlock_irq(phba->host->host_lock);
81 if (phba->hba_state != LPFC_CLEAR_LA) {
82 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) {
83 phba->hba_state = LPFC_CLEAR_LA;
84 lpfc_clear_la(phba, mbox);
85 mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
86 rc = lpfc_sli_issue_mbox (phba, mbox,
87 (MBX_NOWAIT | MBX_STOP_IOCB));
88 if (rc == MBX_NOT_FINISHED) {
89 mempool_free(mbox, phba->mbox_mem_pool);
90 phba->hba_state = LPFC_HBA_ERROR;
99 static struct lpfc_iocbq *
100 lpfc_prep_els_iocb(struct lpfc_hba * phba,
103 uint8_t retry, struct lpfc_nodelist * ndlp, uint32_t elscmd)
105 struct lpfc_sli_ring *pring;
106 struct lpfc_iocbq *elsiocb;
107 struct lpfc_dmabuf *pcmd, *prsp, *pbuflist;
108 struct ulp_bde64 *bpl;
111 pring = &phba->sli.ring[LPFC_ELS_RING];
113 if (phba->hba_state < LPFC_LINK_UP)
116 /* Allocate buffer for command iocb */
117 spin_lock_irq(phba->host->host_lock);
118 elsiocb = lpfc_sli_get_iocbq(phba);
119 spin_unlock_irq(phba->host->host_lock);
123 icmd = &elsiocb->iocb;
125 /* fill in BDEs for command */
126 /* Allocate buffer for command payload */
127 if (((pcmd = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL)) == 0) ||
128 ((pcmd->virt = lpfc_mbuf_alloc(phba,
129 MEM_PRI, &(pcmd->phys))) == 0)) {
132 spin_lock_irq(phba->host->host_lock);
133 lpfc_sli_release_iocbq(phba, elsiocb);
134 spin_unlock_irq(phba->host->host_lock);
138 INIT_LIST_HEAD(&pcmd->list);
140 /* Allocate buffer for response payload */
142 prsp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
144 prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
146 if (prsp == 0 || prsp->virt == 0) {
148 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
150 spin_lock_irq(phba->host->host_lock);
151 lpfc_sli_release_iocbq(phba, elsiocb);
152 spin_unlock_irq(phba->host->host_lock);
155 INIT_LIST_HEAD(&prsp->list);
160 /* Allocate buffer for Buffer ptr list */
161 pbuflist = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
163 pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
165 if (pbuflist == 0 || pbuflist->virt == 0) {
166 spin_lock_irq(phba->host->host_lock);
167 lpfc_sli_release_iocbq(phba, elsiocb);
168 spin_unlock_irq(phba->host->host_lock);
169 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
170 lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
177 INIT_LIST_HEAD(&pbuflist->list);
179 icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
180 icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
181 icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BDL;
183 icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof (struct ulp_bde64));
184 icmd->un.elsreq64.remoteID = ndlp->nlp_DID; /* DID */
185 icmd->ulpCommand = CMD_ELS_REQUEST64_CR;
187 icmd->un.elsreq64.bdl.bdeSize = sizeof (struct ulp_bde64);
188 icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
191 icmd->ulpBdeCount = 1;
193 icmd->ulpClass = CLASS3;
195 bpl = (struct ulp_bde64 *) pbuflist->virt;
196 bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys));
197 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys));
198 bpl->tus.f.bdeSize = cmdSize;
199 bpl->tus.f.bdeFlags = 0;
200 bpl->tus.w = le32_to_cpu(bpl->tus.w);
204 bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys));
205 bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys));
206 bpl->tus.f.bdeSize = FCELSSIZE;
207 bpl->tus.f.bdeFlags = BUFF_USE_RCV;
208 bpl->tus.w = le32_to_cpu(bpl->tus.w);
211 /* Save for completion so we can release these resources */
212 elsiocb->context1 = (uint8_t *) ndlp;
213 elsiocb->context2 = (uint8_t *) pcmd;
214 elsiocb->context3 = (uint8_t *) pbuflist;
215 elsiocb->retry = retry;
216 elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
219 list_add(&prsp->list, &pcmd->list);
223 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
224 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
225 "%d:0116 Xmit ELS command x%x to remote "
226 "NPORT x%x Data: x%x x%x\n",
227 phba->brd_no, elscmd,
228 ndlp->nlp_DID, icmd->ulpIoTag, phba->hba_state);
230 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
231 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
232 "%d:0117 Xmit ELS response x%x to remote "
233 "NPORT x%x Data: x%x x%x\n",
234 phba->brd_no, elscmd,
235 ndlp->nlp_DID, icmd->ulpIoTag, cmdSize);
243 lpfc_cmpl_els_flogi_fabric(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
244 struct serv_parm *sp, IOCB_t *irsp)
249 spin_lock_irq(phba->host->host_lock);
250 phba->fc_flag |= FC_FABRIC;
251 spin_unlock_irq(phba->host->host_lock);
253 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
254 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
255 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
257 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
259 if (phba->fc_topology == TOPOLOGY_LOOP) {
260 spin_lock_irq(phba->host->host_lock);
261 phba->fc_flag |= FC_PUBLIC_LOOP;
262 spin_unlock_irq(phba->host->host_lock);
265 * If we are a N-port connected to a Fabric, fixup sparam's so
266 * logins to devices on remote loops work.
268 phba->fc_sparam.cmn.altBbCredit = 1;
271 phba->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
272 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
273 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof (struct lpfc_name));
274 ndlp->nlp_class_sup = 0;
275 if (sp->cls1.classValid)
276 ndlp->nlp_class_sup |= FC_COS_CLASS1;
277 if (sp->cls2.classValid)
278 ndlp->nlp_class_sup |= FC_COS_CLASS2;
279 if (sp->cls3.classValid)
280 ndlp->nlp_class_sup |= FC_COS_CLASS3;
281 if (sp->cls4.classValid)
282 ndlp->nlp_class_sup |= FC_COS_CLASS4;
283 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
284 sp->cmn.bbRcvSizeLsb;
285 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
287 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
291 phba->hba_state = LPFC_FABRIC_CFG_LINK;
292 lpfc_config_link(phba, mbox);
293 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
295 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT | MBX_STOP_IOCB);
296 if (rc == MBX_NOT_FINISHED)
299 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
303 if (lpfc_reg_login(phba, Fabric_DID, (uint8_t *) sp, mbox, 0))
307 * set_slim mailbox command needs to execute first,
308 * queue this command to be processed later.
310 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
311 mbox->context2 = ndlp;
313 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT | MBX_STOP_IOCB);
314 if (rc == MBX_NOT_FINISHED)
320 mempool_free(mbox, phba->mbox_mem_pool);
326 * We FLOGIed into an NPort, initiate pt2pt protocol
329 lpfc_cmpl_els_flogi_nport(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
330 struct serv_parm *sp)
335 spin_lock_irq(phba->host->host_lock);
336 phba->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
337 spin_unlock_irq(phba->host->host_lock);
339 phba->fc_edtov = FF_DEF_EDTOV;
340 phba->fc_ratov = FF_DEF_RATOV;
341 rc = memcmp(&phba->fc_portname, &sp->portName,
342 sizeof(struct lpfc_name));
344 /* This side will initiate the PLOGI */
345 spin_lock_irq(phba->host->host_lock);
346 phba->fc_flag |= FC_PT2PT_PLOGI;
347 spin_unlock_irq(phba->host->host_lock);
350 * N_Port ID cannot be 0, set our to LocalID the other
351 * side will be RemoteID.
356 phba->fc_myDID = PT2PT_LocalID;
358 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
362 lpfc_config_link(phba, mbox);
364 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
365 rc = lpfc_sli_issue_mbox(phba, mbox,
366 MBX_NOWAIT | MBX_STOP_IOCB);
367 if (rc == MBX_NOT_FINISHED) {
368 mempool_free(mbox, phba->mbox_mem_pool);
371 mempool_free(ndlp, phba->nlp_mem_pool);
373 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, PT2PT_RemoteID);
376 * Cannot find existing Fabric ndlp, so allocate a
379 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
383 lpfc_nlp_init(phba, ndlp, PT2PT_RemoteID);
386 memcpy(&ndlp->nlp_portname, &sp->portName,
387 sizeof(struct lpfc_name));
388 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
389 sizeof(struct lpfc_name));
390 ndlp->nlp_state = NLP_STE_NPR_NODE;
391 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
392 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
394 /* This side will wait for the PLOGI */
395 mempool_free( ndlp, phba->nlp_mem_pool);
398 spin_lock_irq(phba->host->host_lock);
399 phba->fc_flag |= FC_PT2PT;
400 spin_unlock_irq(phba->host->host_lock);
402 /* Start discovery - this should just do CLEAR_LA */
403 lpfc_disc_start(phba);
410 lpfc_cmpl_els_flogi(struct lpfc_hba * phba,
411 struct lpfc_iocbq * cmdiocb, struct lpfc_iocbq * rspiocb)
413 IOCB_t *irsp = &rspiocb->iocb;
414 struct lpfc_nodelist *ndlp = cmdiocb->context1;
415 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
416 struct serv_parm *sp;
419 /* Check to see if link went down during discovery */
420 if (lpfc_els_chk_latt(phba)) {
421 lpfc_nlp_remove(phba, ndlp);
425 if (irsp->ulpStatus) {
426 /* Check for retry */
427 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
428 /* ELS command is being retried */
431 /* FLOGI failed, so there is no fabric */
432 spin_lock_irq(phba->host->host_lock);
433 phba->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
434 spin_unlock_irq(phba->host->host_lock);
436 /* If private loop, then allow max outstandting els to be
437 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
438 * alpa map would take too long otherwise.
440 if (phba->alpa_map[0] == 0) {
441 phba->cfg_discovery_threads =
442 LPFC_MAX_DISC_THREADS;
446 lpfc_printf_log(phba,
449 "%d:0100 FLOGI failure Data: x%x x%x\n",
451 irsp->ulpStatus, irsp->un.ulpWord[4]);
456 * The FLogI succeeded. Sync the data for the CPU before
459 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
461 sp = prsp->virt + sizeof(uint32_t);
463 /* FLOGI completes successfully */
464 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
465 "%d:0101 FLOGI completes sucessfully "
466 "Data: x%x x%x x%x x%x\n",
468 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
469 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution);
471 if (phba->hba_state == LPFC_FLOGI) {
473 * If Common Service Parameters indicate Nport
474 * we are point to point, if Fport we are Fabric.
477 rc = lpfc_cmpl_els_flogi_fabric(phba, ndlp, sp, irsp);
479 rc = lpfc_cmpl_els_flogi_nport(phba, ndlp, sp);
486 lpfc_nlp_remove(phba, ndlp);
488 if (irsp->ulpStatus != IOSTAT_LOCAL_REJECT ||
489 (irsp->un.ulpWord[4] != IOERR_SLI_ABORTED &&
490 irsp->un.ulpWord[4] != IOERR_SLI_DOWN)) {
491 /* FLOGI failed, so just use loop map to make discovery list */
492 lpfc_disc_list_loopmap(phba);
494 /* Start discovery */
495 lpfc_disc_start(phba);
499 lpfc_els_free_iocb(phba, cmdiocb);
503 lpfc_issue_els_flogi(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
506 struct serv_parm *sp;
508 struct lpfc_iocbq *elsiocb;
509 struct lpfc_sli_ring *pring;
515 pring = &phba->sli.ring[LPFC_ELS_RING];
517 cmdsize = (sizeof (uint32_t) + sizeof (struct serv_parm));
518 if ((elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry,
519 ndlp, ELS_CMD_FLOGI)) == 0) {
523 icmd = &elsiocb->iocb;
524 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
526 /* For FLOGI request, remainder of payload is service parameters */
527 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
528 pcmd += sizeof (uint32_t);
529 memcpy(pcmd, &phba->fc_sparam, sizeof (struct serv_parm));
530 sp = (struct serv_parm *) pcmd;
532 /* Setup CSPs accordingly for Fabric */
534 sp->cmn.w2.r_a_tov = 0;
535 sp->cls1.classValid = 0;
536 sp->cls2.seqDelivery = 1;
537 sp->cls3.seqDelivery = 1;
538 if (sp->cmn.fcphLow < FC_PH3)
539 sp->cmn.fcphLow = FC_PH3;
540 if (sp->cmn.fcphHigh < FC_PH3)
541 sp->cmn.fcphHigh = FC_PH3;
543 tmo = phba->fc_ratov;
544 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
545 lpfc_set_disctmo(phba);
546 phba->fc_ratov = tmo;
548 phba->fc_stat.elsXmitFLOGI++;
549 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
550 spin_lock_irq(phba->host->host_lock);
551 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
552 spin_unlock_irq(phba->host->host_lock);
553 if (rc == IOCB_ERROR) {
554 lpfc_els_free_iocb(phba, elsiocb);
561 lpfc_els_abort_flogi(struct lpfc_hba * phba)
563 struct lpfc_sli_ring *pring;
564 struct lpfc_iocbq *iocb, *next_iocb;
565 struct lpfc_nodelist *ndlp;
568 /* Abort outstanding I/O on NPort <nlp_DID> */
569 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
570 "%d:0201 Abort outstanding I/O on NPort x%x\n",
571 phba->brd_no, Fabric_DID);
573 pring = &phba->sli.ring[LPFC_ELS_RING];
576 * Check the txcmplq for an iocb that matches the nport the driver is
579 spin_lock_irq(phba->host->host_lock);
580 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
582 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) {
583 ndlp = (struct lpfc_nodelist *)(iocb->context1);
584 if (ndlp && (ndlp->nlp_DID == Fabric_DID)) {
585 list_del(&iocb->list);
586 pring->txcmplq_cnt--;
588 if ((icmd->un.elsreq64.bdl.ulpIoTag32)) {
589 lpfc_sli_issue_abort_iotag32
592 if (iocb->iocb_cmpl) {
593 icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
594 icmd->un.ulpWord[4] =
596 spin_unlock_irq(phba->host->host_lock);
597 (iocb->iocb_cmpl) (phba, iocb, iocb);
598 spin_lock_irq(phba->host->host_lock);
600 lpfc_sli_release_iocbq(phba, iocb);
604 spin_unlock_irq(phba->host->host_lock);
610 lpfc_initial_flogi(struct lpfc_hba * phba)
612 struct lpfc_nodelist *ndlp;
614 /* First look for Fabric ndlp on the unmapped list */
617 lpfc_findnode_did(phba, NLP_SEARCH_UNMAPPED,
619 /* Cannot find existing Fabric ndlp, so allocate a new one */
620 if ((ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL))
624 lpfc_nlp_init(phba, ndlp, Fabric_DID);
627 phba->fc_unmap_cnt--;
628 list_del(&ndlp->nlp_listp);
629 spin_lock_irq(phba->host->host_lock);
630 ndlp->nlp_flag &= ~NLP_LIST_MASK;
631 spin_unlock_irq(phba->host->host_lock);
633 if (lpfc_issue_els_flogi(phba, ndlp, 0)) {
634 mempool_free( ndlp, phba->nlp_mem_pool);
640 lpfc_more_plogi(struct lpfc_hba * phba)
644 if (phba->num_disc_nodes)
645 phba->num_disc_nodes--;
647 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
648 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
649 "%d:0232 Continue discovery with %d PLOGIs to go "
650 "Data: x%x x%x x%x\n",
651 phba->brd_no, phba->num_disc_nodes, phba->fc_plogi_cnt,
652 phba->fc_flag, phba->hba_state);
654 /* Check to see if there are more PLOGIs to be sent */
655 if (phba->fc_flag & FC_NLP_MORE) {
656 /* go thru NPR list and issue any remaining ELS PLOGIs */
657 sentplogi = lpfc_els_disc_plogi(phba);
663 lpfc_cmpl_els_plogi(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
664 struct lpfc_iocbq * rspiocb)
667 struct lpfc_sli *psli;
668 struct lpfc_nodelist *ndlp;
669 int disc, rc, did, type;
673 /* we pass cmdiocb to state machine which needs rspiocb as well */
674 cmdiocb->context_un.rsp_iocb = rspiocb;
676 irsp = &rspiocb->iocb;
677 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
678 spin_lock_irq(phba->host->host_lock);
679 ndlp->nlp_flag &= ~NLP_PLOGI_SND;
680 spin_unlock_irq(phba->host->host_lock);
682 /* Since ndlp can be freed in the disc state machine, note if this node
683 * is being used during discovery.
685 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
688 /* PLOGI completes to NPort <nlp_DID> */
689 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
690 "%d:0102 PLOGI completes to NPort x%x "
691 "Data: x%x x%x x%x x%x\n",
692 phba->brd_no, ndlp->nlp_DID, irsp->ulpStatus,
693 irsp->un.ulpWord[4], disc, phba->num_disc_nodes);
695 /* Check to see if link went down during discovery */
696 if (lpfc_els_chk_latt(phba)) {
697 spin_lock_irq(phba->host->host_lock);
698 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
699 spin_unlock_irq(phba->host->host_lock);
703 /* ndlp could be freed in DSM, save these values now */
704 type = ndlp->nlp_type;
707 if (irsp->ulpStatus) {
708 /* Check for retry */
709 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
710 /* ELS command is being retried */
712 spin_lock_irq(phba->host->host_lock);
713 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
714 spin_unlock_irq(phba->host->host_lock);
720 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
721 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
722 ((irsp->un.ulpWord[4] == IOERR_SLI_ABORTED) ||
723 (irsp->un.ulpWord[4] == IOERR_SLI_DOWN))) {
724 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
727 rc = lpfc_disc_state_machine(phba, ndlp, cmdiocb,
731 /* Good status, call state machine */
732 rc = lpfc_disc_state_machine(phba, ndlp, cmdiocb,
736 if (type & NLP_FABRIC) {
737 /* If we cannot login to Nameserver, kick off discovery now */
738 if ((did == NameServer_DID) && (rc == NLP_STE_FREED_NODE)) {
739 lpfc_disc_start(phba);
744 if (disc && phba->num_disc_nodes) {
745 /* Check to see if there are more PLOGIs to be sent */
746 lpfc_more_plogi(phba);
749 if (rc != NLP_STE_FREED_NODE) {
750 spin_lock_irq(phba->host->host_lock);
751 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
752 spin_unlock_irq(phba->host->host_lock);
755 if (phba->num_disc_nodes == 0) {
757 spin_lock_irq(phba->host->host_lock);
758 phba->fc_flag &= ~FC_NDISC_ACTIVE;
759 spin_unlock_irq(phba->host->host_lock);
761 lpfc_can_disctmo(phba);
762 if (phba->fc_flag & FC_RSCN_MODE) {
763 /* Check to see if more RSCNs came in while we were
764 * processing this one.
766 if ((phba->fc_rscn_id_cnt == 0) &&
767 (!(phba->fc_flag & FC_RSCN_DISCOVERY))) {
768 spin_lock_irq(phba->host->host_lock);
769 phba->fc_flag &= ~FC_RSCN_MODE;
770 spin_unlock_irq(phba->host->host_lock);
772 lpfc_els_handle_rscn(phba);
778 lpfc_els_free_iocb(phba, cmdiocb);
783 lpfc_issue_els_plogi(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
786 struct serv_parm *sp;
788 struct lpfc_iocbq *elsiocb;
789 struct lpfc_sli_ring *pring;
790 struct lpfc_sli *psli;
795 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
797 cmdsize = (sizeof (uint32_t) + sizeof (struct serv_parm));
798 if ((elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry,
799 ndlp, ELS_CMD_PLOGI)) == 0) {
803 icmd = &elsiocb->iocb;
804 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
806 /* For PLOGI request, remainder of payload is service parameters */
807 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
808 pcmd += sizeof (uint32_t);
809 memcpy(pcmd, &phba->fc_sparam, sizeof (struct serv_parm));
810 sp = (struct serv_parm *) pcmd;
812 if (sp->cmn.fcphLow < FC_PH_4_3)
813 sp->cmn.fcphLow = FC_PH_4_3;
815 if (sp->cmn.fcphHigh < FC_PH3)
816 sp->cmn.fcphHigh = FC_PH3;
818 phba->fc_stat.elsXmitPLOGI++;
819 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
820 spin_lock_irq(phba->host->host_lock);
821 ndlp->nlp_flag |= NLP_PLOGI_SND;
822 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
823 ndlp->nlp_flag &= ~NLP_PLOGI_SND;
824 spin_unlock_irq(phba->host->host_lock);
825 lpfc_els_free_iocb(phba, elsiocb);
828 spin_unlock_irq(phba->host->host_lock);
833 lpfc_cmpl_els_prli(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
834 struct lpfc_iocbq * rspiocb)
837 struct lpfc_sli *psli;
838 struct lpfc_nodelist *ndlp;
841 /* we pass cmdiocb to state machine which needs rspiocb as well */
842 cmdiocb->context_un.rsp_iocb = rspiocb;
844 irsp = &(rspiocb->iocb);
845 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
846 spin_lock_irq(phba->host->host_lock);
847 ndlp->nlp_flag &= ~NLP_PRLI_SND;
848 spin_unlock_irq(phba->host->host_lock);
850 /* PRLI completes to NPort <nlp_DID> */
851 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
852 "%d:0103 PRLI completes to NPort x%x "
853 "Data: x%x x%x x%x\n",
854 phba->brd_no, ndlp->nlp_DID, irsp->ulpStatus,
855 irsp->un.ulpWord[4], phba->num_disc_nodes);
857 phba->fc_prli_sent--;
858 /* Check to see if link went down during discovery */
859 if (lpfc_els_chk_latt(phba))
862 if (irsp->ulpStatus) {
863 /* Check for retry */
864 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
865 /* ELS command is being retried */
869 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
870 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
871 ((irsp->un.ulpWord[4] == IOERR_SLI_ABORTED) ||
872 (irsp->un.ulpWord[4] == IOERR_SLI_DOWN))) {
876 lpfc_disc_state_machine(phba, ndlp, cmdiocb,
880 /* Good status, call state machine */
881 lpfc_disc_state_machine(phba, ndlp, cmdiocb, NLP_EVT_CMPL_PRLI);
885 lpfc_els_free_iocb(phba, cmdiocb);
890 lpfc_issue_els_prli(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
895 struct lpfc_iocbq *elsiocb;
896 struct lpfc_sli_ring *pring;
897 struct lpfc_sli *psli;
902 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
904 cmdsize = (sizeof (uint32_t) + sizeof (PRLI));
905 if ((elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry,
906 ndlp, ELS_CMD_PRLI)) == 0) {
910 icmd = &elsiocb->iocb;
911 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
913 /* For PRLI request, remainder of payload is service parameters */
914 memset(pcmd, 0, (sizeof (PRLI) + sizeof (uint32_t)));
915 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
916 pcmd += sizeof (uint32_t);
918 /* For PRLI, remainder of payload is PRLI parameter page */
921 * If our firmware version is 3.20 or later,
922 * set the following bits for FC-TAPE support.
924 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
925 npr->ConfmComplAllowed = 1;
927 npr->TaskRetryIdReq = 1;
929 npr->estabImagePair = 1;
930 npr->readXferRdyDis = 1;
932 /* For FCP support */
933 npr->prliType = PRLI_FCP_TYPE;
934 npr->initiatorFunc = 1;
936 phba->fc_stat.elsXmitPRLI++;
937 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
938 spin_lock_irq(phba->host->host_lock);
939 ndlp->nlp_flag |= NLP_PRLI_SND;
940 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
941 ndlp->nlp_flag &= ~NLP_PRLI_SND;
942 spin_unlock_irq(phba->host->host_lock);
943 lpfc_els_free_iocb(phba, elsiocb);
946 spin_unlock_irq(phba->host->host_lock);
947 phba->fc_prli_sent++;
952 lpfc_more_adisc(struct lpfc_hba * phba)
956 if (phba->num_disc_nodes)
957 phba->num_disc_nodes--;
959 /* Continue discovery with <num_disc_nodes> ADISCs to go */
960 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
961 "%d:0210 Continue discovery with %d ADISCs to go "
962 "Data: x%x x%x x%x\n",
963 phba->brd_no, phba->num_disc_nodes, phba->fc_adisc_cnt,
964 phba->fc_flag, phba->hba_state);
966 /* Check to see if there are more ADISCs to be sent */
967 if (phba->fc_flag & FC_NLP_MORE) {
968 lpfc_set_disctmo(phba);
970 /* go thru NPR list and issue any remaining ELS ADISCs */
971 sentadisc = lpfc_els_disc_adisc(phba);
977 lpfc_rscn_disc(struct lpfc_hba * phba)
980 /* go thru NPR list and issue ELS PLOGIs */
981 if (phba->fc_npr_cnt) {
982 if (lpfc_els_disc_plogi(phba))
985 if (phba->fc_flag & FC_RSCN_MODE) {
986 /* Check to see if more RSCNs came in while we were
987 * processing this one.
989 if ((phba->fc_rscn_id_cnt == 0) &&
990 (!(phba->fc_flag & FC_RSCN_DISCOVERY))) {
991 spin_lock_irq(phba->host->host_lock);
992 phba->fc_flag &= ~FC_RSCN_MODE;
993 spin_unlock_irq(phba->host->host_lock);
995 lpfc_els_handle_rscn(phba);
1001 lpfc_cmpl_els_adisc(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
1002 struct lpfc_iocbq * rspiocb)
1005 struct lpfc_sli *psli;
1006 struct lpfc_nodelist *ndlp;
1012 /* we pass cmdiocb to state machine which needs rspiocb as well */
1013 cmdiocb->context_un.rsp_iocb = rspiocb;
1015 irsp = &(rspiocb->iocb);
1016 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1017 spin_lock_irq(phba->host->host_lock);
1018 ndlp->nlp_flag &= ~NLP_ADISC_SND;
1019 spin_unlock_irq(phba->host->host_lock);
1021 /* Since ndlp can be freed in the disc state machine, note if this node
1022 * is being used during discovery.
1024 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
1026 /* ADISC completes to NPort <nlp_DID> */
1027 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1028 "%d:0104 ADISC completes to NPort x%x "
1029 "Data: x%x x%x x%x x%x\n",
1030 phba->brd_no, ndlp->nlp_DID, irsp->ulpStatus,
1031 irsp->un.ulpWord[4], disc, phba->num_disc_nodes);
1033 /* Check to see if link went down during discovery */
1034 if (lpfc_els_chk_latt(phba)) {
1035 spin_lock_irq(phba->host->host_lock);
1036 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1037 spin_unlock_irq(phba->host->host_lock);
1041 if (irsp->ulpStatus) {
1042 /* Check for retry */
1043 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1044 /* ELS command is being retried */
1046 spin_lock_irq(phba->host->host_lock);
1047 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1048 spin_unlock_irq(phba->host->host_lock);
1049 lpfc_set_disctmo(phba);
1054 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1055 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
1056 ((irsp->un.ulpWord[4] == IOERR_SLI_ABORTED) ||
1057 (irsp->un.ulpWord[4] == IOERR_SLI_DOWN))) {
1058 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
1061 lpfc_disc_state_machine(phba, ndlp, cmdiocb,
1062 NLP_EVT_CMPL_ADISC);
1065 /* Good status, call state machine */
1066 lpfc_disc_state_machine(phba, ndlp, cmdiocb,
1067 NLP_EVT_CMPL_ADISC);
1070 if (disc && phba->num_disc_nodes) {
1071 /* Check to see if there are more ADISCs to be sent */
1072 lpfc_more_adisc(phba);
1074 /* Check to see if we are done with ADISC authentication */
1075 if (phba->num_disc_nodes == 0) {
1076 lpfc_can_disctmo(phba);
1077 /* If we get here, there is nothing left to wait for */
1078 if ((phba->hba_state < LPFC_HBA_READY) &&
1079 (phba->hba_state != LPFC_CLEAR_LA)) {
1080 /* Link up discovery */
1081 if ((mbox = mempool_alloc(phba->mbox_mem_pool,
1083 phba->hba_state = LPFC_CLEAR_LA;
1084 lpfc_clear_la(phba, mbox);
1086 lpfc_mbx_cmpl_clear_la;
1087 rc = lpfc_sli_issue_mbox
1089 (MBX_NOWAIT | MBX_STOP_IOCB));
1090 if (rc == MBX_NOT_FINISHED) {
1092 phba->mbox_mem_pool);
1093 lpfc_disc_flush_list(phba);
1094 psli->ring[(psli->ip_ring)].
1096 ~LPFC_STOP_IOCB_EVENT;
1097 psli->ring[(psli->fcp_ring)].
1099 ~LPFC_STOP_IOCB_EVENT;
1100 psli->ring[(psli->next_ring)].
1102 ~LPFC_STOP_IOCB_EVENT;
1108 lpfc_rscn_disc(phba);
1112 spin_lock_irq(phba->host->host_lock);
1113 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1114 spin_unlock_irq(phba->host->host_lock);
1116 lpfc_els_free_iocb(phba, cmdiocb);
1121 lpfc_issue_els_adisc(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
1126 struct lpfc_iocbq *elsiocb;
1127 struct lpfc_sli_ring *pring;
1128 struct lpfc_sli *psli;
1133 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1135 cmdsize = (sizeof (uint32_t) + sizeof (ADISC));
1136 if ((elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry,
1137 ndlp, ELS_CMD_ADISC)) == 0) {
1141 icmd = &elsiocb->iocb;
1142 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1144 /* For ADISC request, remainder of payload is service parameters */
1145 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
1146 pcmd += sizeof (uint32_t);
1148 /* Fill in ADISC payload */
1149 ap = (ADISC *) pcmd;
1150 ap->hardAL_PA = phba->fc_pref_ALPA;
1151 memcpy(&ap->portName, &phba->fc_portname, sizeof (struct lpfc_name));
1152 memcpy(&ap->nodeName, &phba->fc_nodename, sizeof (struct lpfc_name));
1153 ap->DID = be32_to_cpu(phba->fc_myDID);
1155 phba->fc_stat.elsXmitADISC++;
1156 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
1157 spin_lock_irq(phba->host->host_lock);
1158 ndlp->nlp_flag |= NLP_ADISC_SND;
1159 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
1160 ndlp->nlp_flag &= ~NLP_ADISC_SND;
1161 spin_unlock_irq(phba->host->host_lock);
1162 lpfc_els_free_iocb(phba, elsiocb);
1165 spin_unlock_irq(phba->host->host_lock);
1170 lpfc_cmpl_els_logo(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
1171 struct lpfc_iocbq * rspiocb)
1174 struct lpfc_sli *psli;
1175 struct lpfc_nodelist *ndlp;
1178 /* we pass cmdiocb to state machine which needs rspiocb as well */
1179 cmdiocb->context_un.rsp_iocb = rspiocb;
1181 irsp = &(rspiocb->iocb);
1182 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1183 spin_lock_irq(phba->host->host_lock);
1184 ndlp->nlp_flag &= ~NLP_LOGO_SND;
1185 spin_unlock_irq(phba->host->host_lock);
1187 /* LOGO completes to NPort <nlp_DID> */
1188 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1189 "%d:0105 LOGO completes to NPort x%x "
1190 "Data: x%x x%x x%x\n",
1191 phba->brd_no, ndlp->nlp_DID, irsp->ulpStatus,
1192 irsp->un.ulpWord[4], phba->num_disc_nodes);
1194 /* Check to see if link went down during discovery */
1195 if (lpfc_els_chk_latt(phba))
1198 if (irsp->ulpStatus) {
1199 /* Check for retry */
1200 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1201 /* ELS command is being retried */
1205 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1206 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
1207 ((irsp->un.ulpWord[4] == IOERR_SLI_ABORTED) ||
1208 (irsp->un.ulpWord[4] == IOERR_SLI_DOWN))) {
1212 lpfc_disc_state_machine(phba, ndlp, cmdiocb,
1216 /* Good status, call state machine */
1217 lpfc_disc_state_machine(phba, ndlp, cmdiocb, NLP_EVT_CMPL_LOGO);
1219 if (ndlp->nlp_flag & NLP_DELAY_TMO) {
1220 lpfc_unreg_rpi(phba, ndlp);
1225 lpfc_els_free_iocb(phba, cmdiocb);
1230 lpfc_issue_els_logo(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
1234 struct lpfc_iocbq *elsiocb;
1235 struct lpfc_sli_ring *pring;
1236 struct lpfc_sli *psli;
1241 pring = &psli->ring[LPFC_ELS_RING];
1243 cmdsize = 2 * (sizeof (uint32_t) + sizeof (struct lpfc_name));
1244 if ((elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry,
1245 ndlp, ELS_CMD_LOGO)) == 0) {
1249 icmd = &elsiocb->iocb;
1250 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1251 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
1252 pcmd += sizeof (uint32_t);
1254 /* Fill in LOGO payload */
1255 *((uint32_t *) (pcmd)) = be32_to_cpu(phba->fc_myDID);
1256 pcmd += sizeof (uint32_t);
1257 memcpy(pcmd, &phba->fc_portname, sizeof (struct lpfc_name));
1259 phba->fc_stat.elsXmitLOGO++;
1260 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
1261 spin_lock_irq(phba->host->host_lock);
1262 ndlp->nlp_flag |= NLP_LOGO_SND;
1263 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
1264 ndlp->nlp_flag &= ~NLP_LOGO_SND;
1265 spin_unlock_irq(phba->host->host_lock);
1266 lpfc_els_free_iocb(phba, elsiocb);
1269 spin_unlock_irq(phba->host->host_lock);
1274 lpfc_cmpl_els_cmd(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
1275 struct lpfc_iocbq * rspiocb)
1279 irsp = &rspiocb->iocb;
1281 /* ELS cmd tag <ulpIoTag> completes */
1282 lpfc_printf_log(phba,
1285 "%d:0106 ELS cmd tag x%x completes Data: x%x x%x\n",
1287 irsp->ulpIoTag, irsp->ulpStatus, irsp->un.ulpWord[4]);
1289 /* Check to see if link went down during discovery */
1290 lpfc_els_chk_latt(phba);
1291 lpfc_els_free_iocb(phba, cmdiocb);
1296 lpfc_issue_els_scr(struct lpfc_hba * phba, uint32_t nportid, uint8_t retry)
1299 struct lpfc_iocbq *elsiocb;
1300 struct lpfc_sli_ring *pring;
1301 struct lpfc_sli *psli;
1304 struct lpfc_nodelist *ndlp;
1307 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1308 cmdsize = (sizeof (uint32_t) + sizeof (SCR));
1309 if ((ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL)) == 0) {
1313 lpfc_nlp_init(phba, ndlp, nportid);
1315 if ((elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry,
1316 ndlp, ELS_CMD_SCR)) == 0) {
1317 mempool_free( ndlp, phba->nlp_mem_pool);
1321 icmd = &elsiocb->iocb;
1322 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1324 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
1325 pcmd += sizeof (uint32_t);
1327 /* For SCR, remainder of payload is SCR parameter page */
1328 memset(pcmd, 0, sizeof (SCR));
1329 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
1331 phba->fc_stat.elsXmitSCR++;
1332 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
1333 spin_lock_irq(phba->host->host_lock);
1334 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
1335 spin_unlock_irq(phba->host->host_lock);
1336 mempool_free( ndlp, phba->nlp_mem_pool);
1337 lpfc_els_free_iocb(phba, elsiocb);
1340 spin_unlock_irq(phba->host->host_lock);
1341 mempool_free( ndlp, phba->nlp_mem_pool);
1346 lpfc_issue_els_farpr(struct lpfc_hba * phba, uint32_t nportid, uint8_t retry)
1349 struct lpfc_iocbq *elsiocb;
1350 struct lpfc_sli_ring *pring;
1351 struct lpfc_sli *psli;
1356 struct lpfc_nodelist *ondlp;
1357 struct lpfc_nodelist *ndlp;
1360 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1361 cmdsize = (sizeof (uint32_t) + sizeof (FARP));
1362 if ((ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL)) == 0) {
1365 lpfc_nlp_init(phba, ndlp, nportid);
1367 if ((elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry,
1368 ndlp, ELS_CMD_RNID)) == 0) {
1369 mempool_free( ndlp, phba->nlp_mem_pool);
1373 icmd = &elsiocb->iocb;
1374 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1376 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
1377 pcmd += sizeof (uint32_t);
1379 /* Fill in FARPR payload */
1380 fp = (FARP *) (pcmd);
1381 memset(fp, 0, sizeof (FARP));
1382 lp = (uint32_t *) pcmd;
1383 *lp++ = be32_to_cpu(nportid);
1384 *lp++ = be32_to_cpu(phba->fc_myDID);
1386 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
1388 memcpy(&fp->RportName, &phba->fc_portname, sizeof (struct lpfc_name));
1389 memcpy(&fp->RnodeName, &phba->fc_nodename, sizeof (struct lpfc_name));
1390 if ((ondlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, nportid))) {
1391 memcpy(&fp->OportName, &ondlp->nlp_portname,
1392 sizeof (struct lpfc_name));
1393 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
1394 sizeof (struct lpfc_name));
1397 phba->fc_stat.elsXmitFARPR++;
1398 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
1399 spin_lock_irq(phba->host->host_lock);
1400 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
1401 spin_unlock_irq(phba->host->host_lock);
1402 mempool_free( ndlp, phba->nlp_mem_pool);
1403 lpfc_els_free_iocb(phba, elsiocb);
1406 spin_unlock_irq(phba->host->host_lock);
1407 mempool_free( ndlp, phba->nlp_mem_pool);
1412 lpfc_els_retry_delay(unsigned long ptr)
1414 struct lpfc_nodelist *ndlp;
1415 struct lpfc_hba *phba;
1416 unsigned long iflag;
1417 struct lpfc_work_evt *evtp;
1419 ndlp = (struct lpfc_nodelist *)ptr;
1420 phba = ndlp->nlp_phba;
1421 evtp = &ndlp->els_retry_evt;
1423 spin_lock_irqsave(phba->host->host_lock, iflag);
1424 if (!list_empty(&evtp->evt_listp)) {
1425 spin_unlock_irqrestore(phba->host->host_lock, iflag);
1429 evtp->evt_arg1 = ndlp;
1430 evtp->evt = LPFC_EVT_ELS_RETRY;
1431 list_add_tail(&evtp->evt_listp, &phba->work_list);
1432 if (phba->work_wait)
1433 wake_up(phba->work_wait);
1435 spin_unlock_irqrestore(phba->host->host_lock, iflag);
1440 lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
1442 struct lpfc_hba *phba;
1447 phba = ndlp->nlp_phba;
1448 spin_lock_irq(phba->host->host_lock);
1449 did = (uint32_t) (ndlp->nlp_DID);
1450 cmd = (uint32_t) (ndlp->nlp_last_elscmd);
1452 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
1453 spin_unlock_irq(phba->host->host_lock);
1457 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
1458 spin_unlock_irq(phba->host->host_lock);
1459 retry = ndlp->nlp_retry;
1463 lpfc_issue_els_flogi(phba, ndlp, retry);
1466 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
1467 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
1468 lpfc_issue_els_plogi(phba, ndlp, retry);
1471 ndlp->nlp_state = NLP_STE_ADISC_ISSUE;
1472 lpfc_nlp_list(phba, ndlp, NLP_ADISC_LIST);
1473 lpfc_issue_els_adisc(phba, ndlp, retry);
1476 ndlp->nlp_state = NLP_STE_PRLI_ISSUE;
1477 lpfc_nlp_list(phba, ndlp, NLP_PRLI_LIST);
1478 lpfc_issue_els_prli(phba, ndlp, retry);
1481 ndlp->nlp_state = NLP_STE_NPR_NODE;
1482 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1483 lpfc_issue_els_logo(phba, ndlp, retry);
1490 lpfc_els_retry(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
1491 struct lpfc_iocbq * rspiocb)
1494 struct lpfc_dmabuf *pcmd;
1495 struct lpfc_nodelist *ndlp;
1498 int retry, maxretry;
1504 maxretry = lpfc_max_els_tries;
1505 irsp = &rspiocb->iocb;
1506 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1507 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
1509 /* Note: context2 may be 0 for internal driver abort
1510 * of delays ELS command.
1513 if (pcmd && pcmd->virt) {
1514 elscmd = (uint32_t *) (pcmd->virt);
1518 switch (irsp->ulpStatus) {
1519 case IOSTAT_FCP_RSP_ERROR:
1520 case IOSTAT_REMOTE_STOP:
1523 case IOSTAT_LOCAL_REJECT:
1524 switch ((irsp->un.ulpWord[4] & 0xff)) {
1525 case IOERR_LOOP_OPEN_FAILURE:
1526 if (cmd == ELS_CMD_PLOGI) {
1527 if (cmdiocb->retry == 0) {
1534 case IOERR_SEQUENCE_TIMEOUT:
1536 if ((cmd == ELS_CMD_FLOGI)
1537 && (phba->fc_topology != TOPOLOGY_LOOP)) {
1543 case IOERR_NO_RESOURCES:
1544 if (cmd == ELS_CMD_PLOGI) {
1550 case IOERR_INVALID_RPI:
1556 case IOSTAT_NPORT_RJT:
1557 case IOSTAT_FABRIC_RJT:
1558 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
1564 case IOSTAT_NPORT_BSY:
1565 case IOSTAT_FABRIC_BSY:
1570 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
1571 /* Added for Vendor specifc support
1572 * Just keep retrying for these Rsn / Exp codes
1574 switch (stat.un.b.lsRjtRsnCode) {
1575 case LSRJT_UNABLE_TPC:
1576 if (stat.un.b.lsRjtRsnCodeExp ==
1577 LSEXP_CMD_IN_PROGRESS) {
1578 if (cmd == ELS_CMD_PLOGI) {
1585 if (cmd == ELS_CMD_PLOGI) {
1587 maxretry = lpfc_max_els_tries + 1;
1593 case LSRJT_LOGICAL_BSY:
1594 if (cmd == ELS_CMD_PLOGI) {
1603 case IOSTAT_INTERMED_RSP:
1611 if (ndlp->nlp_DID == FDMI_DID) {
1615 if ((++cmdiocb->retry) >= maxretry) {
1616 phba->fc_stat.elsRetryExceeded++;
1622 /* Retry ELS command <elsCmd> to remote NPORT <did> */
1623 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1624 "%d:0107 Retry ELS command x%x to remote "
1625 "NPORT x%x Data: x%x x%x\n",
1627 cmd, ndlp->nlp_DID, cmdiocb->retry, delay);
1629 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) {
1630 /* If discovery / RSCN timer is running, reset it */
1631 if (timer_pending(&phba->fc_disctmo) ||
1632 (phba->fc_flag & FC_RSCN_MODE)) {
1633 lpfc_set_disctmo(phba);
1637 phba->fc_stat.elsXmitRetry++;
1639 phba->fc_stat.elsDelayRetry++;
1640 ndlp->nlp_retry = cmdiocb->retry;
1642 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
1643 ndlp->nlp_flag |= NLP_DELAY_TMO;
1645 ndlp->nlp_state = NLP_STE_NPR_NODE;
1646 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1647 ndlp->nlp_last_elscmd = cmd;
1653 lpfc_issue_els_flogi(phba, ndlp, cmdiocb->retry);
1656 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
1657 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
1658 lpfc_issue_els_plogi(phba, ndlp, cmdiocb->retry);
1661 ndlp->nlp_state = NLP_STE_ADISC_ISSUE;
1662 lpfc_nlp_list(phba, ndlp, NLP_ADISC_LIST);
1663 lpfc_issue_els_adisc(phba, ndlp, cmdiocb->retry);
1666 ndlp->nlp_state = NLP_STE_PRLI_ISSUE;
1667 lpfc_nlp_list(phba, ndlp, NLP_PRLI_LIST);
1668 lpfc_issue_els_prli(phba, ndlp, cmdiocb->retry);
1671 ndlp->nlp_state = NLP_STE_NPR_NODE;
1672 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1673 lpfc_issue_els_logo(phba, ndlp, cmdiocb->retry);
1678 /* No retry ELS command <elsCmd> to remote NPORT <did> */
1679 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1680 "%d:0108 No retry ELS command x%x to remote NPORT x%x "
1683 cmd, ndlp->nlp_DID, cmdiocb->retry, ndlp->nlp_flag);
1689 lpfc_els_free_iocb(struct lpfc_hba * phba, struct lpfc_iocbq * elsiocb)
1691 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
1693 /* context2 = cmd, context2->next = rsp, context3 = bpl */
1694 if (elsiocb->context2) {
1695 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
1696 /* Free the response before processing the command. */
1697 if (!list_empty(&buf_ptr1->list)) {
1698 list_remove_head(&buf_ptr1->list, buf_ptr,
1701 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
1704 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
1708 if (elsiocb->context3) {
1709 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
1710 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
1713 spin_lock_irq(phba->host->host_lock);
1714 lpfc_sli_release_iocbq(phba, elsiocb);
1715 spin_unlock_irq(phba->host->host_lock);
1720 lpfc_cmpl_els_logo_acc(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
1721 struct lpfc_iocbq * rspiocb)
1723 struct lpfc_nodelist *ndlp;
1725 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1727 /* ACC to LOGO completes to NPort <nlp_DID> */
1728 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1729 "%d:0109 ACC to LOGO completes to NPort x%x "
1730 "Data: x%x x%x x%x\n",
1731 phba->brd_no, ndlp->nlp_DID, ndlp->nlp_flag,
1732 ndlp->nlp_state, ndlp->nlp_rpi);
1734 spin_lock_irq(phba->host->host_lock);
1735 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
1736 spin_unlock_irq(phba->host->host_lock);
1738 switch (ndlp->nlp_state) {
1739 case NLP_STE_UNUSED_NODE: /* node is just allocated */
1740 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
1742 case NLP_STE_NPR_NODE: /* NPort Recovery mode */
1743 lpfc_unreg_rpi(phba, ndlp);
1748 lpfc_els_free_iocb(phba, cmdiocb);
1753 lpfc_cmpl_els_acc(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
1754 struct lpfc_iocbq * rspiocb)
1756 struct lpfc_nodelist *ndlp;
1757 LPFC_MBOXQ_t *mbox = NULL;
1759 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1760 if (cmdiocb->context_un.mbox)
1761 mbox = cmdiocb->context_un.mbox;
1764 /* Check to see if link went down during discovery */
1765 if ((lpfc_els_chk_latt(phba)) || !ndlp) {
1767 mempool_free( mbox, phba->mbox_mem_pool);
1772 /* ELS response tag <ulpIoTag> completes */
1773 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1774 "%d:0110 ELS response tag x%x completes "
1775 "Data: x%x x%x x%x x%x x%x x%x\n",
1777 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
1778 rspiocb->iocb.un.ulpWord[4], ndlp->nlp_DID,
1779 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
1782 if ((rspiocb->iocb.ulpStatus == 0)
1783 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
1784 /* set_slim mailbox command needs to execute first,
1785 * queue this command to be processed later.
1787 lpfc_unreg_rpi(phba, ndlp);
1788 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
1789 mbox->context2 = ndlp;
1790 ndlp->nlp_state = NLP_STE_REG_LOGIN_ISSUE;
1791 lpfc_nlp_list(phba, ndlp, NLP_REGLOGIN_LIST);
1792 if (lpfc_sli_issue_mbox(phba, mbox,
1793 (MBX_NOWAIT | MBX_STOP_IOCB))
1794 != MBX_NOT_FINISHED) {
1797 /* NOTE: we should have messages for unsuccessful
1799 mempool_free( mbox, phba->mbox_mem_pool);
1801 mempool_free( mbox, phba->mbox_mem_pool);
1802 if (ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
1803 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
1809 spin_lock_irq(phba->host->host_lock);
1810 ndlp->nlp_flag &= ~NLP_ACC_REGLOGIN;
1811 spin_unlock_irq(phba->host->host_lock);
1813 lpfc_els_free_iocb(phba, cmdiocb);
1818 lpfc_els_rsp_acc(struct lpfc_hba * phba, uint32_t flag,
1819 struct lpfc_iocbq * oldiocb, struct lpfc_nodelist * ndlp,
1820 LPFC_MBOXQ_t * mbox, uint8_t newnode)
1824 struct lpfc_iocbq *elsiocb;
1825 struct lpfc_sli_ring *pring;
1826 struct lpfc_sli *psli;
1832 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1833 oldcmd = &oldiocb->iocb;
1837 cmdsize = sizeof (uint32_t);
1839 lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry,
1840 ndlp, ELS_CMD_ACC)) == 0) {
1843 icmd = &elsiocb->iocb;
1844 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
1845 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1846 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
1847 pcmd += sizeof (uint32_t);
1850 cmdsize = (sizeof (struct serv_parm) + sizeof (uint32_t));
1852 lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry,
1853 ndlp, ELS_CMD_ACC)) == 0) {
1856 icmd = &elsiocb->iocb;
1857 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
1858 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1861 elsiocb->context_un.mbox = mbox;
1863 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
1864 pcmd += sizeof (uint32_t);
1865 memcpy(pcmd, &phba->fc_sparam, sizeof (struct serv_parm));
1872 elsiocb->context1 = NULL;
1874 /* Xmit ELS ACC response tag <ulpIoTag> */
1875 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1876 "%d:0128 Xmit ELS ACC response tag x%x "
1877 "Data: x%x x%x x%x x%x x%x\n",
1879 elsiocb->iocb.ulpIoTag,
1880 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
1881 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
1883 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
1884 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
1886 elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
1889 phba->fc_stat.elsXmitACC++;
1890 spin_lock_irq(phba->host->host_lock);
1891 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
1892 spin_unlock_irq(phba->host->host_lock);
1893 if (rc == IOCB_ERROR) {
1894 lpfc_els_free_iocb(phba, elsiocb);
1901 lpfc_els_rsp_reject(struct lpfc_hba * phba, uint32_t rejectError,
1902 struct lpfc_iocbq * oldiocb, struct lpfc_nodelist * ndlp)
1906 struct lpfc_iocbq *elsiocb;
1907 struct lpfc_sli_ring *pring;
1908 struct lpfc_sli *psli;
1914 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1916 cmdsize = 2 * sizeof (uint32_t);
1917 if ((elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry,
1918 ndlp, ELS_CMD_LS_RJT)) == 0) {
1922 icmd = &elsiocb->iocb;
1923 oldcmd = &oldiocb->iocb;
1924 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
1925 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1927 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
1928 pcmd += sizeof (uint32_t);
1929 *((uint32_t *) (pcmd)) = rejectError;
1931 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
1932 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1933 "%d:0129 Xmit ELS RJT x%x response tag x%x "
1934 "Data: x%x x%x x%x x%x x%x\n",
1936 rejectError, elsiocb->iocb.ulpIoTag,
1937 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
1938 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
1940 phba->fc_stat.elsXmitLSRJT++;
1941 elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
1942 spin_lock_irq(phba->host->host_lock);
1943 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
1944 spin_unlock_irq(phba->host->host_lock);
1945 if (rc == IOCB_ERROR) {
1946 lpfc_els_free_iocb(phba, elsiocb);
1953 lpfc_els_rsp_adisc_acc(struct lpfc_hba * phba,
1954 struct lpfc_iocbq * oldiocb, struct lpfc_nodelist * ndlp)
1959 struct lpfc_iocbq *elsiocb;
1960 struct lpfc_sli_ring *pring;
1961 struct lpfc_sli *psli;
1967 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1969 cmdsize = sizeof (uint32_t) + sizeof (ADISC);
1970 if ((elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry,
1971 ndlp, ELS_CMD_ACC)) == 0) {
1975 /* Xmit ADISC ACC response tag <ulpIoTag> */
1976 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1977 "%d:0130 Xmit ADISC ACC response tag x%x "
1978 "Data: x%x x%x x%x x%x x%x\n",
1980 elsiocb->iocb.ulpIoTag,
1981 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
1982 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
1984 icmd = &elsiocb->iocb;
1985 oldcmd = &oldiocb->iocb;
1986 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
1987 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1989 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
1990 pcmd += sizeof (uint32_t);
1992 ap = (ADISC *) (pcmd);
1993 ap->hardAL_PA = phba->fc_pref_ALPA;
1994 memcpy(&ap->portName, &phba->fc_portname, sizeof (struct lpfc_name));
1995 memcpy(&ap->nodeName, &phba->fc_nodename, sizeof (struct lpfc_name));
1996 ap->DID = be32_to_cpu(phba->fc_myDID);
1998 phba->fc_stat.elsXmitACC++;
1999 elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
2000 spin_lock_irq(phba->host->host_lock);
2001 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
2002 spin_unlock_irq(phba->host->host_lock);
2003 if (rc == IOCB_ERROR) {
2004 lpfc_els_free_iocb(phba, elsiocb);
2011 lpfc_els_rsp_prli_acc(struct lpfc_hba * phba,
2012 struct lpfc_iocbq * oldiocb, struct lpfc_nodelist * ndlp)
2018 struct lpfc_iocbq *elsiocb;
2019 struct lpfc_sli_ring *pring;
2020 struct lpfc_sli *psli;
2026 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2028 cmdsize = sizeof (uint32_t) + sizeof (PRLI);
2029 if ((elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry,
2032 (ELS_CMD_PRLI & ~ELS_RSP_MASK)))) ==
2037 /* Xmit PRLI ACC response tag <ulpIoTag> */
2038 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
2039 "%d:0131 Xmit PRLI ACC response tag x%x "
2040 "Data: x%x x%x x%x x%x x%x\n",
2042 elsiocb->iocb.ulpIoTag,
2043 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
2044 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
2046 icmd = &elsiocb->iocb;
2047 oldcmd = &oldiocb->iocb;
2048 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2049 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2051 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
2052 pcmd += sizeof (uint32_t);
2054 /* For PRLI, remainder of payload is PRLI parameter page */
2055 memset(pcmd, 0, sizeof (PRLI));
2057 npr = (PRLI *) pcmd;
2060 * If our firmware version is 3.20 or later,
2061 * set the following bits for FC-TAPE support.
2063 if (vpd->rev.feaLevelHigh >= 0x02) {
2064 npr->ConfmComplAllowed = 1;
2066 npr->TaskRetryIdReq = 1;
2069 npr->acceptRspCode = PRLI_REQ_EXECUTED;
2070 npr->estabImagePair = 1;
2071 npr->readXferRdyDis = 1;
2072 npr->ConfmComplAllowed = 1;
2074 npr->prliType = PRLI_FCP_TYPE;
2075 npr->initiatorFunc = 1;
2077 phba->fc_stat.elsXmitACC++;
2078 elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
2080 spin_lock_irq(phba->host->host_lock);
2081 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
2082 spin_unlock_irq(phba->host->host_lock);
2083 if (rc == IOCB_ERROR) {
2084 lpfc_els_free_iocb(phba, elsiocb);
2091 lpfc_els_rsp_rnid_acc(struct lpfc_hba * phba,
2093 struct lpfc_iocbq * oldiocb, struct lpfc_nodelist * ndlp)
2098 struct lpfc_iocbq *elsiocb;
2099 struct lpfc_sli_ring *pring;
2100 struct lpfc_sli *psli;
2106 pring = &psli->ring[LPFC_ELS_RING];
2108 cmdsize = sizeof (uint32_t) + sizeof (uint32_t)
2109 + (2 * sizeof (struct lpfc_name));
2111 cmdsize += sizeof (RNID_TOP_DISC);
2113 if ((elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry,
2114 ndlp, ELS_CMD_ACC)) == 0) {
2118 /* Xmit RNID ACC response tag <ulpIoTag> */
2119 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
2120 "%d:0132 Xmit RNID ACC response tag x%x "
2123 elsiocb->iocb.ulpIoTag,
2124 elsiocb->iocb.ulpContext);
2126 icmd = &elsiocb->iocb;
2127 oldcmd = &oldiocb->iocb;
2128 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2129 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2131 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
2132 pcmd += sizeof (uint32_t);
2134 memset(pcmd, 0, sizeof (RNID));
2135 rn = (RNID *) (pcmd);
2136 rn->Format = format;
2137 rn->CommonLen = (2 * sizeof (struct lpfc_name));
2138 memcpy(&rn->portName, &phba->fc_portname, sizeof (struct lpfc_name));
2139 memcpy(&rn->nodeName, &phba->fc_nodename, sizeof (struct lpfc_name));
2142 rn->SpecificLen = 0;
2144 case RNID_TOPOLOGY_DISC:
2145 rn->SpecificLen = sizeof (RNID_TOP_DISC);
2146 memcpy(&rn->un.topologyDisc.portName,
2147 &phba->fc_portname, sizeof (struct lpfc_name));
2148 rn->un.topologyDisc.unitType = RNID_HBA;
2149 rn->un.topologyDisc.physPort = 0;
2150 rn->un.topologyDisc.attachedNodes = 0;
2154 rn->SpecificLen = 0;
2158 phba->fc_stat.elsXmitACC++;
2159 elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
2160 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
2161 * it could be freed */
2163 spin_lock_irq(phba->host->host_lock);
2164 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
2165 spin_unlock_irq(phba->host->host_lock);
2166 if (rc == IOCB_ERROR) {
2167 lpfc_els_free_iocb(phba, elsiocb);
2174 lpfc_els_disc_adisc(struct lpfc_hba * phba)
2177 struct lpfc_nodelist *ndlp, *next_ndlp;
2180 /* go thru NPR list and issue any remaining ELS ADISCs */
2181 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
2183 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
2184 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
2185 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2186 ndlp->nlp_state = NLP_STE_ADISC_ISSUE;
2187 lpfc_nlp_list(phba, ndlp,
2189 lpfc_issue_els_adisc(phba, ndlp, 0);
2191 phba->num_disc_nodes++;
2192 if (phba->num_disc_nodes >=
2193 phba->cfg_discovery_threads) {
2194 spin_lock_irq(phba->host->host_lock);
2195 phba->fc_flag |= FC_NLP_MORE;
2196 spin_unlock_irq(phba->host->host_lock);
2202 if (sentadisc == 0) {
2203 spin_lock_irq(phba->host->host_lock);
2204 phba->fc_flag &= ~FC_NLP_MORE;
2205 spin_unlock_irq(phba->host->host_lock);
2211 lpfc_els_disc_plogi(struct lpfc_hba * phba)
2214 struct lpfc_nodelist *ndlp, *next_ndlp;
2217 /* go thru NPR list and issue any remaining ELS PLOGIs */
2218 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
2220 if ((ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
2221 (!(ndlp->nlp_flag & NLP_DELAY_TMO))) {
2222 if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
2223 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
2224 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
2225 lpfc_issue_els_plogi(phba, ndlp, 0);
2227 phba->num_disc_nodes++;
2228 if (phba->num_disc_nodes >=
2229 phba->cfg_discovery_threads) {
2230 spin_lock_irq(phba->host->host_lock);
2231 phba->fc_flag |= FC_NLP_MORE;
2232 spin_unlock_irq(phba->host->host_lock);
2238 if (sentplogi == 0) {
2239 spin_lock_irq(phba->host->host_lock);
2240 phba->fc_flag &= ~FC_NLP_MORE;
2241 spin_unlock_irq(phba->host->host_lock);
2247 lpfc_els_flush_rscn(struct lpfc_hba * phba)
2249 struct lpfc_dmabuf *mp;
2252 for (i = 0; i < phba->fc_rscn_id_cnt; i++) {
2253 mp = phba->fc_rscn_id_list[i];
2254 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2256 phba->fc_rscn_id_list[i] = NULL;
2258 phba->fc_rscn_id_cnt = 0;
2259 spin_lock_irq(phba->host->host_lock);
2260 phba->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
2261 spin_unlock_irq(phba->host->host_lock);
2262 lpfc_can_disctmo(phba);
2267 lpfc_rscn_payload_check(struct lpfc_hba * phba, uint32_t did)
2271 struct lpfc_dmabuf *mp;
2273 uint32_t payload_len, cmd, i, match;
2275 ns_did.un.word = did;
2278 /* Never match fabric nodes for RSCNs */
2279 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
2282 /* If we are doing a FULL RSCN rediscovery, match everything */
2283 if (phba->fc_flag & FC_RSCN_DISCOVERY) {
2287 for (i = 0; i < phba->fc_rscn_id_cnt; i++) {
2288 mp = phba->fc_rscn_id_list[i];
2289 lp = (uint32_t *) mp->virt;
2291 payload_len = be32_to_cpu(cmd) & 0xffff; /* payload length */
2292 payload_len -= sizeof (uint32_t); /* take off word 0 */
2293 while (payload_len) {
2294 rscn_did.un.word = *lp++;
2295 rscn_did.un.word = be32_to_cpu(rscn_did.un.word);
2296 payload_len -= sizeof (uint32_t);
2297 switch (rscn_did.un.b.resv) {
2298 case 0: /* Single N_Port ID effected */
2299 if (ns_did.un.word == rscn_did.un.word) {
2303 case 1: /* Whole N_Port Area effected */
2304 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
2305 && (ns_did.un.b.area == rscn_did.un.b.area))
2310 case 2: /* Whole N_Port Domain effected */
2311 if (ns_did.un.b.domain == rscn_did.un.b.domain)
2316 case 3: /* Whole Fabric effected */
2320 /* Unknown Identifier in RSCN list */
2321 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2322 "%d:0217 Unknown Identifier in "
2323 "RSCN payload Data: x%x\n",
2324 phba->brd_no, rscn_did.un.word);
2336 lpfc_rscn_recovery_check(struct lpfc_hba * phba)
2338 struct lpfc_nodelist *ndlp = NULL, *next_ndlp;
2339 struct list_head *listp;
2340 struct list_head *node_list[7];
2343 /* Look at all nodes effected by pending RSCNs and move
2346 node_list[0] = &phba->fc_npr_list; /* MUST do this list first */
2347 node_list[1] = &phba->fc_nlpmap_list;
2348 node_list[2] = &phba->fc_nlpunmap_list;
2349 node_list[3] = &phba->fc_prli_list;
2350 node_list[4] = &phba->fc_reglogin_list;
2351 node_list[5] = &phba->fc_adisc_list;
2352 node_list[6] = &phba->fc_plogi_list;
2353 for (i = 0; i < 7; i++) {
2354 listp = node_list[i];
2355 if (list_empty(listp))
2358 list_for_each_entry_safe(ndlp, next_ndlp, listp, nlp_listp) {
2359 if (!(lpfc_rscn_payload_check(phba, ndlp->nlp_DID)))
2362 lpfc_disc_state_machine(phba, ndlp, NULL,
2363 NLP_EVT_DEVICE_RECOVERY);
2364 if (ndlp->nlp_flag & NLP_DELAY_TMO) {
2365 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
2366 del_timer_sync(&ndlp->nlp_delayfunc);
2367 if (!list_empty(&ndlp->
2368 els_retry_evt.evt_listp))
2369 list_del_init(&ndlp->
2370 els_retry_evt.evt_listp);
2378 lpfc_els_rcv_rscn(struct lpfc_hba * phba,
2379 struct lpfc_iocbq * cmdiocb,
2380 struct lpfc_nodelist * ndlp, uint8_t newnode)
2382 struct lpfc_dmabuf *pcmd;
2385 uint32_t payload_len, cmd;
2387 icmd = &cmdiocb->iocb;
2388 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2389 lp = (uint32_t *) pcmd->virt;
2392 payload_len = be32_to_cpu(cmd) & 0xffff; /* payload length */
2393 payload_len -= sizeof (uint32_t); /* take off word 0 */
2394 cmd &= ELS_CMD_MASK;
2397 lpfc_printf_log(phba,
2400 "%d:0214 RSCN received Data: x%x x%x x%x x%x\n",
2402 phba->fc_flag, payload_len, *lp, phba->fc_rscn_id_cnt);
2404 /* If we are about to begin discovery, just ACC the RSCN.
2405 * Discovery processing will satisfy it.
2407 if (phba->hba_state < LPFC_NS_QRY) {
2408 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL,
2413 /* If we are already processing an RSCN, save the received
2414 * RSCN payload buffer, cmdiocb->context2 to process later.
2416 if (phba->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
2417 if ((phba->fc_rscn_id_cnt < FC_MAX_HOLD_RSCN) &&
2418 !(phba->fc_flag & FC_RSCN_DISCOVERY)) {
2419 spin_lock_irq(phba->host->host_lock);
2420 phba->fc_flag |= FC_RSCN_MODE;
2421 spin_unlock_irq(phba->host->host_lock);
2422 phba->fc_rscn_id_list[phba->fc_rscn_id_cnt++] = pcmd;
2424 /* If we zero, cmdiocb->context2, the calling
2425 * routine will not try to free it.
2427 cmdiocb->context2 = NULL;
2430 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
2431 "%d:0235 Deferred RSCN "
2432 "Data: x%x x%x x%x\n",
2433 phba->brd_no, phba->fc_rscn_id_cnt,
2434 phba->fc_flag, phba->hba_state);
2436 spin_lock_irq(phba->host->host_lock);
2437 phba->fc_flag |= FC_RSCN_DISCOVERY;
2438 spin_unlock_irq(phba->host->host_lock);
2439 /* ReDiscovery RSCN */
2440 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
2441 "%d:0234 ReDiscovery RSCN "
2442 "Data: x%x x%x x%x\n",
2443 phba->brd_no, phba->fc_rscn_id_cnt,
2444 phba->fc_flag, phba->hba_state);
2447 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL,
2450 /* send RECOVERY event for ALL nodes that match RSCN payload */
2451 lpfc_rscn_recovery_check(phba);
2455 phba->fc_flag |= FC_RSCN_MODE;
2456 phba->fc_rscn_id_list[phba->fc_rscn_id_cnt++] = pcmd;
2458 * If we zero, cmdiocb->context2, the calling routine will
2459 * not try to free it.
2461 cmdiocb->context2 = NULL;
2463 lpfc_set_disctmo(phba);
2466 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, newnode);
2468 /* send RECOVERY event for ALL nodes that match RSCN payload */
2469 lpfc_rscn_recovery_check(phba);
2471 return (lpfc_els_handle_rscn(phba));
2475 lpfc_els_handle_rscn(struct lpfc_hba * phba)
2477 struct lpfc_nodelist *ndlp;
2479 /* Start timer for RSCN processing */
2480 lpfc_set_disctmo(phba);
2482 /* RSCN processed */
2483 lpfc_printf_log(phba,
2486 "%d:0215 RSCN processed Data: x%x x%x x%x x%x\n",
2488 phba->fc_flag, 0, phba->fc_rscn_id_cnt,
2491 /* To process RSCN, first compare RSCN data with NameServer */
2492 phba->fc_ns_retry = 0;
2493 if ((ndlp = lpfc_findnode_did(phba, NLP_SEARCH_UNMAPPED,
2495 /* Good ndlp, issue CT Request to NameServer */
2496 if (lpfc_ns_cmd(phba, ndlp, SLI_CTNS_GID_FT) == 0) {
2497 /* Wait for NameServer query cmpl before we can
2502 /* If login to NameServer does not exist, issue one */
2503 /* Good status, issue PLOGI to NameServer */
2505 lpfc_findnode_did(phba, NLP_SEARCH_ALL, NameServer_DID))) {
2506 /* Wait for NameServer login cmpl before we can
2510 if ((ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL))
2512 lpfc_els_flush_rscn(phba);
2515 lpfc_nlp_init(phba, ndlp, NameServer_DID);
2516 ndlp->nlp_type |= NLP_FABRIC;
2517 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
2518 lpfc_issue_els_plogi(phba, ndlp, 0);
2519 /* Wait for NameServer login cmpl before we can
2525 lpfc_els_flush_rscn(phba);
2530 lpfc_els_rcv_flogi(struct lpfc_hba * phba,
2531 struct lpfc_iocbq * cmdiocb,
2532 struct lpfc_nodelist * ndlp, uint8_t newnode)
2534 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2535 uint32_t *lp = (uint32_t *) pcmd->virt;
2536 IOCB_t *icmd = &cmdiocb->iocb;
2537 struct serv_parm *sp;
2544 sp = (struct serv_parm *) lp;
2546 /* FLOGI received */
2548 lpfc_set_disctmo(phba);
2550 if (phba->fc_topology == TOPOLOGY_LOOP) {
2551 /* We should never receive a FLOGI in loop mode, ignore it */
2552 did = icmd->un.elsreq64.remoteID;
2554 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
2556 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
2557 "%d:0113 An FLOGI ELS command x%x was received "
2558 "from DID x%x in Loop Mode\n",
2559 phba->brd_no, cmd, did);
2565 if ((lpfc_check_sparm(phba, ndlp, sp, CLASS3))) {
2566 /* For a FLOGI we accept, then if our portname is greater
2567 * then the remote portname we initiate Nport login.
2570 rc = memcmp(&phba->fc_portname, &sp->portName,
2571 sizeof (struct lpfc_name));
2574 if ((mbox = mempool_alloc(phba->mbox_mem_pool,
2575 GFP_KERNEL)) == 0) {
2578 lpfc_linkdown(phba);
2579 lpfc_init_link(phba, mbox,
2581 phba->cfg_link_speed);
2582 mbox->mb.un.varInitLnk.lipsr_AL_PA = 0;
2583 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
2584 rc = lpfc_sli_issue_mbox
2585 (phba, mbox, (MBX_NOWAIT | MBX_STOP_IOCB));
2586 if (rc == MBX_NOT_FINISHED) {
2587 mempool_free( mbox, phba->mbox_mem_pool);
2591 else if (rc > 0) { /* greater than */
2592 spin_lock_irq(phba->host->host_lock);
2593 phba->fc_flag |= FC_PT2PT_PLOGI;
2594 spin_unlock_irq(phba->host->host_lock);
2596 phba->fc_flag |= FC_PT2PT;
2597 phba->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
2599 /* Reject this request because invalid parameters */
2600 stat.un.b.lsRjtRsvd0 = 0;
2601 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2602 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
2603 stat.un.b.vendorUnique = 0;
2604 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
2609 lpfc_els_rsp_acc(phba, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL, newnode);
2615 lpfc_els_rcv_rnid(struct lpfc_hba * phba,
2616 struct lpfc_iocbq * cmdiocb, struct lpfc_nodelist * ndlp)
2618 struct lpfc_dmabuf *pcmd;
2625 icmd = &cmdiocb->iocb;
2626 did = icmd->un.elsreq64.remoteID;
2627 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2628 lp = (uint32_t *) pcmd->virt;
2635 switch (rn->Format) {
2637 case RNID_TOPOLOGY_DISC:
2639 lpfc_els_rsp_rnid_acc(phba, rn->Format, cmdiocb, ndlp);
2642 /* Reject this request because format not supported */
2643 stat.un.b.lsRjtRsvd0 = 0;
2644 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2645 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
2646 stat.un.b.vendorUnique = 0;
2647 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
2653 lpfc_els_rcv_rrq(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
2654 struct lpfc_nodelist * ndlp)
2656 struct lpfc_dmabuf *pcmd;
2659 struct lpfc_sli_ring *pring;
2660 struct lpfc_sli *psli;
2665 pring = &psli->ring[LPFC_FCP_RING];
2666 icmd = &cmdiocb->iocb;
2667 did = icmd->un.elsreq64.remoteID;
2668 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2669 lp = (uint32_t *) pcmd->virt;
2675 /* Get oxid / rxid from payload and abort it */
2676 spin_lock_irq(phba->host->host_lock);
2677 if ((rrq->SID == be32_to_cpu(phba->fc_myDID))) {
2678 lpfc_sli_abort_iocb(phba, pring, 0, 0, rrq->Oxid,
2681 lpfc_sli_abort_iocb(phba, pring, 0, 0, rrq->Rxid,
2685 spin_unlock_irq(phba->host->host_lock);
2686 /* ACCEPT the rrq request */
2687 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
2693 lpfc_els_rcv_farp(struct lpfc_hba * phba,
2694 struct lpfc_iocbq * cmdiocb, struct lpfc_nodelist * ndlp)
2696 struct lpfc_dmabuf *pcmd;
2700 uint32_t cmd, cnt, did;
2702 icmd = &cmdiocb->iocb;
2703 did = icmd->un.elsreq64.remoteID;
2704 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2705 lp = (uint32_t *) pcmd->virt;
2710 /* FARP-REQ received from DID <did> */
2711 lpfc_printf_log(phba,
2714 "%d:0601 FARP-REQ received from DID x%x\n",
2717 /* We will only support match on WWPN or WWNN */
2718 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
2723 /* If this FARP command is searching for my portname */
2724 if (fp->Mflags & FARP_MATCH_PORT) {
2725 if (memcmp(&fp->RportName, &phba->fc_portname,
2726 sizeof (struct lpfc_name)) == 0)
2730 /* If this FARP command is searching for my nodename */
2731 if (fp->Mflags & FARP_MATCH_NODE) {
2732 if (memcmp(&fp->RnodeName, &phba->fc_nodename,
2733 sizeof (struct lpfc_name)) == 0)
2738 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
2739 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
2740 /* Log back into the node before sending the FARP. */
2741 if (fp->Rflags & FARP_REQUEST_PLOGI) {
2742 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
2743 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
2744 lpfc_issue_els_plogi(phba, ndlp, 0);
2747 /* Send a FARP response to that node */
2748 if (fp->Rflags & FARP_REQUEST_FARPR) {
2749 lpfc_issue_els_farpr(phba, did, 0);
2757 lpfc_els_rcv_farpr(struct lpfc_hba * phba,
2758 struct lpfc_iocbq * cmdiocb, struct lpfc_nodelist * ndlp)
2760 struct lpfc_dmabuf *pcmd;
2765 icmd = &cmdiocb->iocb;
2766 did = icmd->un.elsreq64.remoteID;
2767 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2768 lp = (uint32_t *) pcmd->virt;
2771 /* FARP-RSP received from DID <did> */
2772 lpfc_printf_log(phba,
2775 "%d:0600 FARP-RSP received from DID x%x\n",
2778 /* ACCEPT the Farp resp request */
2779 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
2785 lpfc_els_rcv_fan(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
2786 struct lpfc_nodelist * ndlp)
2788 struct lpfc_dmabuf *pcmd;
2794 icmd = &cmdiocb->iocb;
2795 did = icmd->un.elsreq64.remoteID;
2796 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2797 lp = (uint32_t *) pcmd->virt;
2804 /* ACCEPT the FAN request */
2805 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
2807 if (phba->hba_state == LPFC_LOCAL_CFG_LINK) {
2808 /* The discovery state machine needs to take a different
2809 * action if this node has switched fabrics
2811 if ((memcmp(&fp->FportName, &phba->fc_fabparam.portName,
2812 sizeof (struct lpfc_name)) != 0)
2814 (memcmp(&fp->FnodeName, &phba->fc_fabparam.nodeName,
2815 sizeof (struct lpfc_name)) != 0)) {
2816 /* This node has switched fabrics. An FLOGI is required
2822 /* Start discovery */
2823 lpfc_disc_start(phba);
2830 lpfc_els_timeout(unsigned long ptr)
2832 struct lpfc_hba *phba;
2833 unsigned long iflag;
2835 phba = (struct lpfc_hba *)ptr;
2838 spin_lock_irqsave(phba->host->host_lock, iflag);
2839 if (!(phba->work_hba_events & WORKER_ELS_TMO)) {
2840 phba->work_hba_events |= WORKER_ELS_TMO;
2841 if (phba->work_wait)
2842 wake_up(phba->work_wait);
2844 spin_unlock_irqrestore(phba->host->host_lock, iflag);
2849 lpfc_els_timeout_handler(struct lpfc_hba *phba)
2851 struct lpfc_sli_ring *pring;
2852 struct lpfc_iocbq *tmp_iocb, *piocb;
2854 struct lpfc_dmabuf *pcmd;
2855 struct list_head *dlp;
2857 uint32_t els_command;
2863 spin_lock_irq(phba->host->host_lock);
2864 /* If the timer is already canceled do nothing */
2865 if (!(phba->work_hba_events & WORKER_ELS_TMO)) {
2866 spin_unlock_irq(phba->host->host_lock);
2869 timeout = (uint32_t)(phba->fc_ratov << 1);
2871 pring = &phba->sli.ring[LPFC_ELS_RING];
2872 dlp = &pring->txcmplq;
2874 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
2877 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
2880 pcmd = (struct lpfc_dmabuf *) piocb->context2;
2881 elscmd = (uint32_t *) (pcmd->virt);
2882 els_command = *elscmd;
2884 if ((els_command == ELS_CMD_FARP)
2885 || (els_command == ELS_CMD_FARPR)) {
2889 if (piocb->drvrTimeout > 0) {
2890 if (piocb->drvrTimeout >= timeout) {
2891 piocb->drvrTimeout -= timeout;
2893 piocb->drvrTimeout = 0;
2898 list_del(&piocb->list);
2899 pring->txcmplq_cnt--;
2901 if (cmd->ulpCommand == CMD_GEN_REQUEST64_CR) {
2902 struct lpfc_nodelist *ndlp;
2904 ndlp = lpfc_findnode_rpi(phba, cmd->ulpContext);
2905 remote_ID = ndlp->nlp_DID;
2906 if (cmd->un.elsreq64.bdl.ulpIoTag32) {
2907 lpfc_sli_issue_abort_iotag32(phba,
2911 remote_ID = cmd->un.elsreq64.remoteID;
2914 lpfc_printf_log(phba,
2917 "%d:0127 ELS timeout Data: x%x x%x x%x x%x\n",
2918 phba->brd_no, els_command,
2919 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
2922 * The iocb has timed out; abort it.
2924 if (piocb->iocb_cmpl) {
2925 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
2926 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
2927 spin_unlock_irq(phba->host->host_lock);
2928 (piocb->iocb_cmpl) (phba, piocb, piocb);
2929 spin_lock_irq(phba->host->host_lock);
2931 lpfc_sli_release_iocbq(phba, piocb);
2933 if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt) {
2934 phba->els_tmofunc.expires = jiffies + HZ * timeout;
2935 add_timer(&phba->els_tmofunc);
2937 spin_unlock_irq(phba->host->host_lock);
2941 lpfc_els_flush_cmd(struct lpfc_hba * phba)
2943 struct lpfc_sli_ring *pring;
2944 struct lpfc_iocbq *tmp_iocb, *piocb;
2946 struct lpfc_dmabuf *pcmd;
2948 uint32_t els_command;
2951 pring = &phba->sli.ring[LPFC_ELS_RING];
2952 spin_lock_irq(phba->host->host_lock);
2953 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
2956 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
2960 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
2961 if ((cmd->ulpCommand == CMD_QUE_RING_BUF_CN) ||
2962 (cmd->ulpCommand == CMD_QUE_RING_BUF64_CN) ||
2963 (cmd->ulpCommand == CMD_CLOSE_XRI_CN) ||
2964 (cmd->ulpCommand == CMD_ABORT_XRI_CN)) {
2968 pcmd = (struct lpfc_dmabuf *) piocb->context2;
2969 elscmd = (uint32_t *) (pcmd->virt);
2970 els_command = *elscmd;
2972 if (cmd->ulpCommand == CMD_GEN_REQUEST64_CR) {
2973 struct lpfc_nodelist *ndlp;
2975 ndlp = lpfc_findnode_rpi(phba, cmd->ulpContext);
2976 remote_ID = ndlp->nlp_DID;
2977 if (phba->hba_state == LPFC_HBA_READY) {
2981 remote_ID = cmd->un.elsreq64.remoteID;
2984 list_del(&piocb->list);
2985 pring->txcmplq_cnt--;
2987 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
2988 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
2990 if (piocb->iocb_cmpl) {
2991 spin_unlock_irq(phba->host->host_lock);
2992 (piocb->iocb_cmpl) (phba, piocb, piocb);
2993 spin_lock_irq(phba->host->host_lock);
2996 lpfc_sli_release_iocbq(phba, piocb);
2999 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
3002 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
3005 pcmd = (struct lpfc_dmabuf *) piocb->context2;
3006 elscmd = (uint32_t *) (pcmd->virt);
3007 els_command = *elscmd;
3009 if (cmd->ulpCommand == CMD_GEN_REQUEST64_CR) {
3010 struct lpfc_nodelist *ndlp;
3012 ndlp = lpfc_findnode_rpi(phba, cmd->ulpContext);
3013 remote_ID = ndlp->nlp_DID;
3014 if (phba->hba_state == LPFC_HBA_READY) {
3018 remote_ID = cmd->un.elsreq64.remoteID;
3021 list_del(&piocb->list);
3022 pring->txcmplq_cnt--;
3024 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
3025 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
3027 if (piocb->iocb_cmpl) {
3028 spin_unlock_irq(phba->host->host_lock);
3029 (piocb->iocb_cmpl) (phba, piocb, piocb);
3030 spin_lock_irq(phba->host->host_lock);
3033 lpfc_sli_release_iocbq(phba, piocb);
3035 spin_unlock_irq(phba->host->host_lock);
3040 lpfc_els_unsol_event(struct lpfc_hba * phba,
3041 struct lpfc_sli_ring * pring, struct lpfc_iocbq * elsiocb)
3043 struct lpfc_sli *psli;
3044 struct lpfc_nodelist *ndlp;
3045 struct lpfc_dmabuf *mp;
3052 uint32_t drop_cmd = 0; /* by default do NOT drop received cmd */
3053 uint32_t rjt_err = 0;
3056 icmd = &elsiocb->iocb;
3058 if ((icmd->ulpStatus == IOSTAT_LOCAL_REJECT) &&
3059 ((icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING)) {
3060 /* Not enough posted buffers; Try posting more buffers */
3061 phba->fc_stat.NoRcvBuf++;
3062 lpfc_post_buffer(phba, pring, 0, 1);
3066 /* If there are no BDEs associated with this IOCB,
3067 * there is nothing to do.
3069 if (icmd->ulpBdeCount == 0)
3072 /* type of ELS cmd is first 32bit word in packet */
3073 mp = lpfc_sli_ringpostbuf_get(phba, pring, getPaddr(icmd->un.
3077 cont64[0].addrLow));
3084 lp = (uint32_t *) mp->virt;
3086 lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], 1, 1);
3088 if (icmd->ulpStatus) {
3089 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3095 /* Check to see if link went down during discovery */
3096 if (lpfc_els_chk_latt(phba)) {
3097 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3103 did = icmd->un.rcvels.remoteID;
3104 if ((ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, did)) == 0) {
3105 /* Cannot find existing Fabric ndlp, so allocate a new one */
3106 if ((ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL))
3108 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3114 lpfc_nlp_init(phba, ndlp, did);
3116 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) {
3117 ndlp->nlp_type |= NLP_FABRIC;
3121 phba->fc_stat.elsRcvFrame++;
3122 elsiocb->context1 = ndlp;
3123 elsiocb->context2 = mp;
3125 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
3126 cmd &= ELS_CMD_MASK;
3128 /* ELS command <elsCmd> received from NPORT <did> */
3129 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
3130 "%d:0112 ELS command x%x received from NPORT x%x "
3131 "Data: x%x\n", phba->brd_no, cmd, did, phba->hba_state);
3135 phba->fc_stat.elsRcvPLOGI++;
3136 if (phba->hba_state < LPFC_DISC_AUTH) {
3140 lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_PLOGI);
3143 phba->fc_stat.elsRcvFLOGI++;
3144 lpfc_els_rcv_flogi(phba, elsiocb, ndlp, newnode);
3146 mempool_free( ndlp, phba->nlp_mem_pool);
3150 phba->fc_stat.elsRcvLOGO++;
3151 if (phba->hba_state < LPFC_DISC_AUTH) {
3155 lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
3158 phba->fc_stat.elsRcvPRLO++;
3159 if (phba->hba_state < LPFC_DISC_AUTH) {
3163 lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
3166 phba->fc_stat.elsRcvRSCN++;
3167 lpfc_els_rcv_rscn(phba, elsiocb, ndlp, newnode);
3169 mempool_free( ndlp, phba->nlp_mem_pool);
3173 phba->fc_stat.elsRcvADISC++;
3174 if (phba->hba_state < LPFC_DISC_AUTH) {
3178 lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_ADISC);
3181 phba->fc_stat.elsRcvPDISC++;
3182 if (phba->hba_state < LPFC_DISC_AUTH) {
3186 lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_PDISC);
3189 phba->fc_stat.elsRcvFARPR++;
3190 lpfc_els_rcv_farpr(phba, elsiocb, ndlp);
3193 phba->fc_stat.elsRcvFARP++;
3194 lpfc_els_rcv_farp(phba, elsiocb, ndlp);
3197 phba->fc_stat.elsRcvFAN++;
3198 lpfc_els_rcv_fan(phba, elsiocb, ndlp);
3201 phba->fc_stat.elsRcvRRQ++;
3202 lpfc_els_rcv_rrq(phba, elsiocb, ndlp);
3205 phba->fc_stat.elsRcvPRLI++;
3206 if (phba->hba_state < LPFC_DISC_AUTH) {
3210 lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
3213 phba->fc_stat.elsRcvRNID++;
3214 lpfc_els_rcv_rnid(phba, elsiocb, ndlp);
3217 /* Unsupported ELS command, reject */
3220 /* Unknown ELS command <elsCmd> received from NPORT <did> */
3221 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
3222 "%d:0115 Unknown ELS command x%x received from "
3223 "NPORT x%x\n", phba->brd_no, cmd, did);
3225 mempool_free( ndlp, phba->nlp_mem_pool);
3230 /* check if need to LS_RJT received ELS cmd */
3232 stat.un.b.lsRjtRsvd0 = 0;
3233 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3234 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
3235 stat.un.b.vendorUnique = 0;
3236 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, elsiocb, ndlp);
3239 if (elsiocb->context2) {
3240 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3244 /* check if need to drop received ELS cmd */
3245 if (drop_cmd == 1) {
3246 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
3247 "%d:0111 Dropping received ELS cmd "
3248 "Data: x%x x%x\n", phba->brd_no,
3249 icmd->ulpStatus, icmd->un.ulpWord[4]);
3250 phba->fc_stat.elsRcvDrop++;