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_device.h>
27 #include <scsi/scsi_host.h>
28 #include <scsi/scsi_transport_fc.h>
32 #include "lpfc_disc.h"
33 #include "lpfc_scsi.h"
35 #include "lpfc_logmsg.h"
36 #include "lpfc_crtn.h"
38 static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *,
40 static int lpfc_max_els_tries = 3;
43 lpfc_els_chk_latt(struct lpfc_hba * phba)
45 struct lpfc_sli *psli;
52 if ((phba->hba_state >= LPFC_HBA_READY) ||
53 (phba->hba_state == LPFC_LINK_DOWN))
56 /* Read the HBA Host Attention Register */
57 spin_lock_irq(phba->host->host_lock);
58 ha_copy = readl(phba->HAregaddr);
59 spin_unlock_irq(phba->host->host_lock);
61 if (!(ha_copy & HA_LATT))
64 /* Pending Link Event during Discovery */
65 lpfc_printf_log(phba, KERN_WARNING, LOG_DISCOVERY,
66 "%d:0237 Pending Link Event during "
67 "Discovery: State x%x\n",
68 phba->brd_no, phba->hba_state);
70 /* CLEAR_LA should re-enable link attention events and
71 * we should then imediately take a LATT event. The
72 * LATT processing should call lpfc_linkdown() which
73 * will cleanup any left over in-progress discovery
76 spin_lock_irq(phba->host->host_lock);
77 phba->fc_flag |= FC_ABORT_DISCOVERY;
78 spin_unlock_irq(phba->host->host_lock);
80 if (phba->hba_state != LPFC_CLEAR_LA) {
81 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) {
82 phba->hba_state = LPFC_CLEAR_LA;
83 lpfc_clear_la(phba, mbox);
84 mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
85 rc = lpfc_sli_issue_mbox (phba, mbox,
86 (MBX_NOWAIT | MBX_STOP_IOCB));
87 if (rc == MBX_NOT_FINISHED) {
88 mempool_free(mbox, phba->mbox_mem_pool);
89 phba->hba_state = LPFC_HBA_ERROR;
98 static struct lpfc_iocbq *
99 lpfc_prep_els_iocb(struct lpfc_hba * phba,
102 uint8_t retry, struct lpfc_nodelist * ndlp, uint32_t elscmd)
104 struct list_head *lpfc_iocb_list = &phba->lpfc_iocb_list;
105 struct lpfc_sli_ring *pring;
106 struct lpfc_iocbq *elsiocb = NULL;
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)
117 /* Allocate buffer for command iocb */
118 spin_lock_irq(phba->host->host_lock);
119 list_remove_head(lpfc_iocb_list, elsiocb, struct lpfc_iocbq, list);
120 spin_unlock_irq(phba->host->host_lock);
124 memset(elsiocb, 0, sizeof (struct lpfc_iocbq));
125 icmd = &elsiocb->iocb;
127 /* fill in BDEs for command */
128 /* Allocate buffer for command payload */
129 if (((pcmd = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL)) == 0) ||
130 ((pcmd->virt = lpfc_mbuf_alloc(phba,
131 MEM_PRI, &(pcmd->phys))) == 0)) {
135 list_add_tail(&elsiocb->list, lpfc_iocb_list);
139 INIT_LIST_HEAD(&pcmd->list);
141 /* Allocate buffer for response payload */
143 prsp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
145 prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
147 if (prsp == 0 || prsp->virt == 0) {
150 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
152 list_add_tail(&elsiocb->list, lpfc_iocb_list);
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 list_add_tail(&elsiocb->list, lpfc_iocb_list);
167 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
168 lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
176 INIT_LIST_HEAD(&pbuflist->list);
178 icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
179 icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
180 icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BDL;
182 icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof (struct ulp_bde64));
183 icmd->un.elsreq64.remoteID = ndlp->nlp_DID; /* DID */
184 icmd->ulpCommand = CMD_ELS_REQUEST64_CR;
186 icmd->un.elsreq64.bdl.bdeSize = sizeof (struct ulp_bde64);
187 icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
190 icmd->ulpBdeCount = 1;
192 icmd->ulpClass = CLASS3;
194 bpl = (struct ulp_bde64 *) pbuflist->virt;
195 bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys));
196 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys));
197 bpl->tus.f.bdeSize = cmdSize;
198 bpl->tus.f.bdeFlags = 0;
199 bpl->tus.w = le32_to_cpu(bpl->tus.w);
203 bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys));
204 bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys));
205 bpl->tus.f.bdeSize = FCELSSIZE;
206 bpl->tus.f.bdeFlags = BUFF_USE_RCV;
207 bpl->tus.w = le32_to_cpu(bpl->tus.w);
210 /* Save for completion so we can release these resources */
211 elsiocb->context1 = (uint8_t *) ndlp;
212 elsiocb->context2 = (uint8_t *) pcmd;
213 elsiocb->context3 = (uint8_t *) pbuflist;
214 elsiocb->retry = retry;
215 elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
218 list_add(&prsp->list, &pcmd->list);
222 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
223 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
224 "%d:0116 Xmit ELS command x%x to remote "
225 "NPORT x%x Data: x%x x%x\n",
226 phba->brd_no, elscmd,
227 ndlp->nlp_DID, icmd->ulpIoTag, phba->hba_state);
229 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
230 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
231 "%d:0117 Xmit ELS response x%x to remote "
232 "NPORT x%x Data: x%x x%x\n",
233 phba->brd_no, elscmd,
234 ndlp->nlp_DID, icmd->ulpIoTag, cmdSize);
242 lpfc_cmpl_els_flogi_fabric(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
243 struct serv_parm *sp, IOCB_t *irsp)
248 spin_lock_irq(phba->host->host_lock);
249 phba->fc_flag |= FC_FABRIC;
250 spin_unlock_irq(phba->host->host_lock);
252 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
253 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
254 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
256 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
258 if (phba->fc_topology == TOPOLOGY_LOOP) {
259 spin_lock_irq(phba->host->host_lock);
260 phba->fc_flag |= FC_PUBLIC_LOOP;
261 spin_unlock_irq(phba->host->host_lock);
264 * If we are a N-port connected to a Fabric, fixup sparam's so
265 * logins to devices on remote loops work.
267 phba->fc_sparam.cmn.altBbCredit = 1;
270 phba->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
271 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
272 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof (struct lpfc_name));
273 ndlp->nlp_class_sup = 0;
274 if (sp->cls1.classValid)
275 ndlp->nlp_class_sup |= FC_COS_CLASS1;
276 if (sp->cls2.classValid)
277 ndlp->nlp_class_sup |= FC_COS_CLASS2;
278 if (sp->cls3.classValid)
279 ndlp->nlp_class_sup |= FC_COS_CLASS3;
280 if (sp->cls4.classValid)
281 ndlp->nlp_class_sup |= FC_COS_CLASS4;
282 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
283 sp->cmn.bbRcvSizeLsb;
284 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
286 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
290 phba->hba_state = LPFC_FABRIC_CFG_LINK;
291 lpfc_config_link(phba, mbox);
292 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
294 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT | MBX_STOP_IOCB);
295 if (rc == MBX_NOT_FINISHED)
298 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
302 if (lpfc_reg_login(phba, Fabric_DID, (uint8_t *) sp, mbox, 0))
306 * set_slim mailbox command needs to execute first,
307 * queue this command to be processed later.
309 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
310 mbox->context2 = ndlp;
312 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT | MBX_STOP_IOCB);
313 if (rc == MBX_NOT_FINISHED)
319 mempool_free(mbox, phba->mbox_mem_pool);
325 * We FLOGIed into an NPort, initiate pt2pt protocol
328 lpfc_cmpl_els_flogi_nport(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
329 struct serv_parm *sp)
334 spin_lock_irq(phba->host->host_lock);
335 phba->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
336 spin_unlock_irq(phba->host->host_lock);
338 phba->fc_edtov = FF_DEF_EDTOV;
339 phba->fc_ratov = FF_DEF_RATOV;
340 rc = memcmp(&phba->fc_portname, &sp->portName,
341 sizeof(struct lpfc_name));
343 /* This side will initiate the PLOGI */
344 spin_lock_irq(phba->host->host_lock);
345 phba->fc_flag |= FC_PT2PT_PLOGI;
346 spin_unlock_irq(phba->host->host_lock);
349 * N_Port ID cannot be 0, set our to LocalID the other
350 * side will be RemoteID.
355 phba->fc_myDID = PT2PT_LocalID;
357 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
361 lpfc_config_link(phba, mbox);
363 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
364 rc = lpfc_sli_issue_mbox(phba, mbox,
365 MBX_NOWAIT | MBX_STOP_IOCB);
366 if (rc == MBX_NOT_FINISHED) {
367 mempool_free(mbox, phba->mbox_mem_pool);
370 mempool_free(ndlp, phba->nlp_mem_pool);
372 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, PT2PT_RemoteID);
375 * Cannot find existing Fabric ndlp, so allocate a
378 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
382 lpfc_nlp_init(phba, ndlp, PT2PT_RemoteID);
385 memcpy(&ndlp->nlp_portname, &sp->portName,
386 sizeof(struct lpfc_name));
387 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
388 sizeof(struct lpfc_name));
389 ndlp->nlp_state = NLP_STE_NPR_NODE;
390 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
391 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
393 /* This side will wait for the PLOGI */
394 mempool_free( ndlp, phba->nlp_mem_pool);
397 spin_lock_irq(phba->host->host_lock);
398 phba->fc_flag |= FC_PT2PT;
399 spin_unlock_irq(phba->host->host_lock);
401 /* Start discovery - this should just do CLEAR_LA */
402 lpfc_disc_start(phba);
409 lpfc_cmpl_els_flogi(struct lpfc_hba * phba,
410 struct lpfc_iocbq * cmdiocb, struct lpfc_iocbq * rspiocb)
412 IOCB_t *irsp = &rspiocb->iocb;
413 struct lpfc_nodelist *ndlp = cmdiocb->context1;
414 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
415 struct serv_parm *sp;
418 /* Check to see if link went down during discovery */
419 if (lpfc_els_chk_latt(phba)) {
420 lpfc_nlp_remove(phba, ndlp);
424 if (irsp->ulpStatus) {
425 /* Check for retry */
426 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
427 /* ELS command is being retried */
430 /* FLOGI failed, so there is no fabric */
431 spin_lock_irq(phba->host->host_lock);
432 phba->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
433 spin_unlock_irq(phba->host->host_lock);
435 /* If private loop, then allow max outstandting els to be
436 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
437 * alpa map would take too long otherwise.
439 if (phba->alpa_map[0] == 0) {
440 phba->cfg_discovery_threads =
441 LPFC_MAX_DISC_THREADS;
445 lpfc_printf_log(phba,
448 "%d:0100 FLOGI failure Data: x%x x%x\n",
450 irsp->ulpStatus, irsp->un.ulpWord[4]);
455 * The FLogI succeeded. Sync the data for the CPU before
458 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
460 sp = prsp->virt + sizeof(uint32_t);
462 /* FLOGI completes successfully */
463 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
464 "%d:0101 FLOGI completes sucessfully "
465 "Data: x%x x%x x%x x%x\n",
467 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
468 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution);
470 if (phba->hba_state == LPFC_FLOGI) {
472 * If Common Service Parameters indicate Nport
473 * we are point to point, if Fport we are Fabric.
476 rc = lpfc_cmpl_els_flogi_fabric(phba, ndlp, sp, irsp);
478 rc = lpfc_cmpl_els_flogi_nport(phba, ndlp, sp);
485 lpfc_nlp_remove(phba, ndlp);
487 if (irsp->ulpStatus != IOSTAT_LOCAL_REJECT ||
488 (irsp->un.ulpWord[4] != IOERR_SLI_ABORTED &&
489 irsp->un.ulpWord[4] != IOERR_SLI_DOWN)) {
490 /* FLOGI failed, so just use loop map to make discovery list */
491 lpfc_disc_list_loopmap(phba);
493 /* Start discovery */
494 lpfc_disc_start(phba);
498 lpfc_els_free_iocb(phba, cmdiocb);
502 lpfc_issue_els_flogi(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
505 struct serv_parm *sp;
507 struct lpfc_iocbq *elsiocb;
508 struct lpfc_sli_ring *pring;
514 pring = &phba->sli.ring[LPFC_ELS_RING];
516 cmdsize = (sizeof (uint32_t) + sizeof (struct serv_parm));
517 if ((elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry,
518 ndlp, ELS_CMD_FLOGI)) == 0) {
522 icmd = &elsiocb->iocb;
523 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
525 /* For FLOGI request, remainder of payload is service parameters */
526 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
527 pcmd += sizeof (uint32_t);
528 memcpy(pcmd, &phba->fc_sparam, sizeof (struct serv_parm));
529 sp = (struct serv_parm *) pcmd;
531 /* Setup CSPs accordingly for Fabric */
533 sp->cmn.w2.r_a_tov = 0;
534 sp->cls1.classValid = 0;
535 sp->cls2.seqDelivery = 1;
536 sp->cls3.seqDelivery = 1;
537 if (sp->cmn.fcphLow < FC_PH3)
538 sp->cmn.fcphLow = FC_PH3;
539 if (sp->cmn.fcphHigh < FC_PH3)
540 sp->cmn.fcphHigh = FC_PH3;
542 tmo = phba->fc_ratov;
543 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
544 lpfc_set_disctmo(phba);
545 phba->fc_ratov = tmo;
547 phba->fc_stat.elsXmitFLOGI++;
548 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
549 spin_lock_irq(phba->host->host_lock);
550 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
551 spin_unlock_irq(phba->host->host_lock);
552 if (rc == IOCB_ERROR) {
553 lpfc_els_free_iocb(phba, elsiocb);
560 lpfc_els_abort_flogi(struct lpfc_hba * phba)
562 struct lpfc_sli_ring *pring;
563 struct lpfc_iocbq *iocb, *next_iocb;
564 struct lpfc_nodelist *ndlp;
567 /* Abort outstanding I/O on NPort <nlp_DID> */
568 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
569 "%d:0201 Abort outstanding I/O on NPort x%x\n",
570 phba->brd_no, Fabric_DID);
572 pring = &phba->sli.ring[LPFC_ELS_RING];
575 * Check the txcmplq for an iocb that matches the nport the driver is
578 spin_lock_irq(phba->host->host_lock);
579 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
581 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) {
582 ndlp = (struct lpfc_nodelist *)(iocb->context1);
583 if (ndlp && (ndlp->nlp_DID == Fabric_DID)) {
584 list_del(&iocb->list);
585 pring->txcmplq_cnt--;
587 if ((icmd->un.elsreq64.bdl.ulpIoTag32)) {
588 lpfc_sli_issue_abort_iotag32
591 if (iocb->iocb_cmpl) {
592 icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
593 icmd->un.ulpWord[4] =
595 spin_unlock_irq(phba->host->host_lock);
596 (iocb->iocb_cmpl) (phba, iocb, iocb);
597 spin_lock_irq(phba->host->host_lock);
599 list_add_tail(&iocb->list,
600 &phba->lpfc_iocb_list);
605 spin_unlock_irq(phba->host->host_lock);
611 lpfc_initial_flogi(struct lpfc_hba * phba)
613 struct lpfc_nodelist *ndlp;
615 /* First look for Fabric ndlp on the unmapped list */
618 lpfc_findnode_did(phba, NLP_SEARCH_UNMAPPED,
620 /* Cannot find existing Fabric ndlp, so allocate a new one */
621 if ((ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL))
625 lpfc_nlp_init(phba, ndlp, Fabric_DID);
628 phba->fc_unmap_cnt--;
629 list_del(&ndlp->nlp_listp);
630 spin_lock_irq(phba->host->host_lock);
631 ndlp->nlp_flag &= ~NLP_LIST_MASK;
632 spin_unlock_irq(phba->host->host_lock);
634 if (lpfc_issue_els_flogi(phba, ndlp, 0)) {
635 mempool_free( ndlp, phba->nlp_mem_pool);
641 lpfc_more_plogi(struct lpfc_hba * phba)
645 if (phba->num_disc_nodes)
646 phba->num_disc_nodes--;
648 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
649 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
650 "%d:0232 Continue discovery with %d PLOGIs to go "
651 "Data: x%x x%x x%x\n",
652 phba->brd_no, phba->num_disc_nodes, phba->fc_plogi_cnt,
653 phba->fc_flag, phba->hba_state);
655 /* Check to see if there are more PLOGIs to be sent */
656 if (phba->fc_flag & FC_NLP_MORE) {
657 /* go thru NPR list and issue any remaining ELS PLOGIs */
658 sentplogi = lpfc_els_disc_plogi(phba);
664 lpfc_cmpl_els_plogi(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
665 struct lpfc_iocbq * rspiocb)
668 struct lpfc_sli *psli;
669 struct lpfc_nodelist *ndlp;
670 int disc, rc, did, type;
674 /* we pass cmdiocb to state machine which needs rspiocb as well */
675 cmdiocb->context_un.rsp_iocb = rspiocb;
677 irsp = &rspiocb->iocb;
678 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
679 spin_lock_irq(phba->host->host_lock);
680 ndlp->nlp_flag &= ~NLP_PLOGI_SND;
681 spin_unlock_irq(phba->host->host_lock);
683 /* Since ndlp can be freed in the disc state machine, note if this node
684 * is being used during discovery.
686 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
689 /* PLOGI completes to NPort <nlp_DID> */
690 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
691 "%d:0102 PLOGI completes to NPort x%x "
692 "Data: x%x x%x x%x x%x\n",
693 phba->brd_no, ndlp->nlp_DID, irsp->ulpStatus,
694 irsp->un.ulpWord[4], disc, phba->num_disc_nodes);
696 /* Check to see if link went down during discovery */
697 if (lpfc_els_chk_latt(phba)) {
698 spin_lock_irq(phba->host->host_lock);
699 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
700 spin_unlock_irq(phba->host->host_lock);
704 /* ndlp could be freed in DSM, save these values now */
705 type = ndlp->nlp_type;
708 if (irsp->ulpStatus) {
709 /* Check for retry */
710 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
711 /* ELS command is being retried */
713 spin_lock_irq(phba->host->host_lock);
714 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
715 spin_unlock_irq(phba->host->host_lock);
721 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
722 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
723 ((irsp->un.ulpWord[4] == IOERR_SLI_ABORTED) ||
724 (irsp->un.ulpWord[4] == IOERR_SLI_DOWN))) {
725 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
728 rc = lpfc_disc_state_machine(phba, ndlp, cmdiocb,
732 /* Good status, call state machine */
733 rc = lpfc_disc_state_machine(phba, ndlp, cmdiocb,
737 if (type & NLP_FABRIC) {
738 /* If we cannot login to Nameserver, kick off discovery now */
739 if ((did == NameServer_DID) && (rc == NLP_STE_FREED_NODE)) {
740 lpfc_disc_start(phba);
745 if (disc && phba->num_disc_nodes) {
746 /* Check to see if there are more PLOGIs to be sent */
747 lpfc_more_plogi(phba);
750 if (rc != NLP_STE_FREED_NODE) {
751 spin_lock_irq(phba->host->host_lock);
752 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
753 spin_unlock_irq(phba->host->host_lock);
756 if (phba->num_disc_nodes == 0) {
758 spin_lock_irq(phba->host->host_lock);
759 phba->fc_flag &= ~FC_NDISC_ACTIVE;
760 spin_unlock_irq(phba->host->host_lock);
762 lpfc_can_disctmo(phba);
763 if (phba->fc_flag & FC_RSCN_MODE) {
764 /* Check to see if more RSCNs came in while we were
765 * processing this one.
767 if ((phba->fc_rscn_id_cnt == 0) &&
768 (!(phba->fc_flag & FC_RSCN_DISCOVERY))) {
769 spin_lock_irq(phba->host->host_lock);
770 phba->fc_flag &= ~FC_RSCN_MODE;
771 spin_unlock_irq(phba->host->host_lock);
773 lpfc_els_handle_rscn(phba);
779 lpfc_els_free_iocb(phba, cmdiocb);
784 lpfc_issue_els_plogi(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
787 struct serv_parm *sp;
789 struct lpfc_iocbq *elsiocb;
790 struct lpfc_sli_ring *pring;
791 struct lpfc_sli *psli;
796 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
798 cmdsize = (sizeof (uint32_t) + sizeof (struct serv_parm));
799 if ((elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry,
800 ndlp, ELS_CMD_PLOGI)) == 0) {
804 icmd = &elsiocb->iocb;
805 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
807 /* For PLOGI request, remainder of payload is service parameters */
808 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
809 pcmd += sizeof (uint32_t);
810 memcpy(pcmd, &phba->fc_sparam, sizeof (struct serv_parm));
811 sp = (struct serv_parm *) pcmd;
813 if (sp->cmn.fcphLow < FC_PH_4_3)
814 sp->cmn.fcphLow = FC_PH_4_3;
816 if (sp->cmn.fcphHigh < FC_PH3)
817 sp->cmn.fcphHigh = FC_PH3;
819 phba->fc_stat.elsXmitPLOGI++;
820 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
821 spin_lock_irq(phba->host->host_lock);
822 ndlp->nlp_flag |= NLP_PLOGI_SND;
823 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
824 ndlp->nlp_flag &= ~NLP_PLOGI_SND;
825 spin_unlock_irq(phba->host->host_lock);
826 lpfc_els_free_iocb(phba, elsiocb);
829 spin_unlock_irq(phba->host->host_lock);
834 lpfc_cmpl_els_prli(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
835 struct lpfc_iocbq * rspiocb)
838 struct lpfc_sli *psli;
839 struct lpfc_nodelist *ndlp;
842 /* we pass cmdiocb to state machine which needs rspiocb as well */
843 cmdiocb->context_un.rsp_iocb = rspiocb;
845 irsp = &(rspiocb->iocb);
846 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
847 spin_lock_irq(phba->host->host_lock);
848 ndlp->nlp_flag &= ~NLP_PRLI_SND;
849 spin_unlock_irq(phba->host->host_lock);
851 /* PRLI completes to NPort <nlp_DID> */
852 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
853 "%d:0103 PRLI completes to NPort x%x "
854 "Data: x%x x%x x%x\n",
855 phba->brd_no, ndlp->nlp_DID, irsp->ulpStatus,
856 irsp->un.ulpWord[4], phba->num_disc_nodes);
858 phba->fc_prli_sent--;
859 /* Check to see if link went down during discovery */
860 if (lpfc_els_chk_latt(phba))
863 if (irsp->ulpStatus) {
864 /* Check for retry */
865 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
866 /* ELS command is being retried */
870 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
871 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
872 ((irsp->un.ulpWord[4] == IOERR_SLI_ABORTED) ||
873 (irsp->un.ulpWord[4] == IOERR_SLI_DOWN))) {
877 lpfc_disc_state_machine(phba, ndlp, cmdiocb,
881 /* Good status, call state machine */
882 lpfc_disc_state_machine(phba, ndlp, cmdiocb, NLP_EVT_CMPL_PRLI);
886 lpfc_els_free_iocb(phba, cmdiocb);
891 lpfc_issue_els_prli(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
896 struct lpfc_iocbq *elsiocb;
897 struct lpfc_sli_ring *pring;
898 struct lpfc_sli *psli;
903 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
905 cmdsize = (sizeof (uint32_t) + sizeof (PRLI));
906 if ((elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry,
907 ndlp, ELS_CMD_PRLI)) == 0) {
911 icmd = &elsiocb->iocb;
912 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
914 /* For PRLI request, remainder of payload is service parameters */
915 memset(pcmd, 0, (sizeof (PRLI) + sizeof (uint32_t)));
916 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
917 pcmd += sizeof (uint32_t);
919 /* For PRLI, remainder of payload is PRLI parameter page */
922 * If our firmware version is 3.20 or later,
923 * set the following bits for FC-TAPE support.
925 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
926 npr->ConfmComplAllowed = 1;
928 npr->TaskRetryIdReq = 1;
930 npr->estabImagePair = 1;
931 npr->readXferRdyDis = 1;
933 /* For FCP support */
934 npr->prliType = PRLI_FCP_TYPE;
935 npr->initiatorFunc = 1;
937 phba->fc_stat.elsXmitPRLI++;
938 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
939 spin_lock_irq(phba->host->host_lock);
940 ndlp->nlp_flag |= NLP_PRLI_SND;
941 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
942 ndlp->nlp_flag &= ~NLP_PRLI_SND;
943 spin_unlock_irq(phba->host->host_lock);
944 lpfc_els_free_iocb(phba, elsiocb);
947 spin_unlock_irq(phba->host->host_lock);
948 phba->fc_prli_sent++;
953 lpfc_more_adisc(struct lpfc_hba * phba)
957 if (phba->num_disc_nodes)
958 phba->num_disc_nodes--;
960 /* Continue discovery with <num_disc_nodes> ADISCs to go */
961 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
962 "%d:0210 Continue discovery with %d ADISCs to go "
963 "Data: x%x x%x x%x\n",
964 phba->brd_no, phba->num_disc_nodes, phba->fc_adisc_cnt,
965 phba->fc_flag, phba->hba_state);
967 /* Check to see if there are more ADISCs to be sent */
968 if (phba->fc_flag & FC_NLP_MORE) {
969 lpfc_set_disctmo(phba);
971 /* go thru NPR list and issue any remaining ELS ADISCs */
972 sentadisc = lpfc_els_disc_adisc(phba);
978 lpfc_rscn_disc(struct lpfc_hba * phba)
981 /* go thru NPR list and issue ELS PLOGIs */
982 if (phba->fc_npr_cnt) {
983 if (lpfc_els_disc_plogi(phba))
986 if (phba->fc_flag & FC_RSCN_MODE) {
987 /* Check to see if more RSCNs came in while we were
988 * processing this one.
990 if ((phba->fc_rscn_id_cnt == 0) &&
991 (!(phba->fc_flag & FC_RSCN_DISCOVERY))) {
992 spin_lock_irq(phba->host->host_lock);
993 phba->fc_flag &= ~FC_RSCN_MODE;
994 spin_unlock_irq(phba->host->host_lock);
996 lpfc_els_handle_rscn(phba);
1002 lpfc_cmpl_els_adisc(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
1003 struct lpfc_iocbq * rspiocb)
1006 struct lpfc_sli *psli;
1007 struct lpfc_nodelist *ndlp;
1013 /* we pass cmdiocb to state machine which needs rspiocb as well */
1014 cmdiocb->context_un.rsp_iocb = rspiocb;
1016 irsp = &(rspiocb->iocb);
1017 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1018 spin_lock_irq(phba->host->host_lock);
1019 ndlp->nlp_flag &= ~NLP_ADISC_SND;
1020 spin_unlock_irq(phba->host->host_lock);
1022 /* Since ndlp can be freed in the disc state machine, note if this node
1023 * is being used during discovery.
1025 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
1027 /* ADISC completes to NPort <nlp_DID> */
1028 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1029 "%d:0104 ADISC completes to NPort x%x "
1030 "Data: x%x x%x x%x x%x\n",
1031 phba->brd_no, ndlp->nlp_DID, irsp->ulpStatus,
1032 irsp->un.ulpWord[4], disc, phba->num_disc_nodes);
1034 /* Check to see if link went down during discovery */
1035 if (lpfc_els_chk_latt(phba)) {
1036 spin_lock_irq(phba->host->host_lock);
1037 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1038 spin_unlock_irq(phba->host->host_lock);
1042 if (irsp->ulpStatus) {
1043 /* Check for retry */
1044 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1045 /* ELS command is being retried */
1047 spin_lock_irq(phba->host->host_lock);
1048 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1049 spin_unlock_irq(phba->host->host_lock);
1050 lpfc_set_disctmo(phba);
1055 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1056 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
1057 ((irsp->un.ulpWord[4] == IOERR_SLI_ABORTED) ||
1058 (irsp->un.ulpWord[4] == IOERR_SLI_DOWN))) {
1059 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
1062 lpfc_disc_state_machine(phba, ndlp, cmdiocb,
1063 NLP_EVT_CMPL_ADISC);
1066 /* Good status, call state machine */
1067 lpfc_disc_state_machine(phba, ndlp, cmdiocb,
1068 NLP_EVT_CMPL_ADISC);
1071 if (disc && phba->num_disc_nodes) {
1072 /* Check to see if there are more ADISCs to be sent */
1073 lpfc_more_adisc(phba);
1075 /* Check to see if we are done with ADISC authentication */
1076 if (phba->num_disc_nodes == 0) {
1077 lpfc_can_disctmo(phba);
1078 /* If we get here, there is nothing left to wait for */
1079 if ((phba->hba_state < LPFC_HBA_READY) &&
1080 (phba->hba_state != LPFC_CLEAR_LA)) {
1081 /* Link up discovery */
1082 if ((mbox = mempool_alloc(phba->mbox_mem_pool,
1084 phba->hba_state = LPFC_CLEAR_LA;
1085 lpfc_clear_la(phba, mbox);
1087 lpfc_mbx_cmpl_clear_la;
1088 rc = lpfc_sli_issue_mbox
1090 (MBX_NOWAIT | MBX_STOP_IOCB));
1091 if (rc == MBX_NOT_FINISHED) {
1093 phba->mbox_mem_pool);
1094 lpfc_disc_flush_list(phba);
1095 psli->ring[(psli->ip_ring)].
1097 ~LPFC_STOP_IOCB_EVENT;
1098 psli->ring[(psli->fcp_ring)].
1100 ~LPFC_STOP_IOCB_EVENT;
1101 psli->ring[(psli->next_ring)].
1103 ~LPFC_STOP_IOCB_EVENT;
1109 lpfc_rscn_disc(phba);
1113 spin_lock_irq(phba->host->host_lock);
1114 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1115 spin_unlock_irq(phba->host->host_lock);
1117 lpfc_els_free_iocb(phba, cmdiocb);
1122 lpfc_issue_els_adisc(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
1127 struct lpfc_iocbq *elsiocb;
1128 struct lpfc_sli_ring *pring;
1129 struct lpfc_sli *psli;
1134 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1136 cmdsize = (sizeof (uint32_t) + sizeof (ADISC));
1137 if ((elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry,
1138 ndlp, ELS_CMD_ADISC)) == 0) {
1142 icmd = &elsiocb->iocb;
1143 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1145 /* For ADISC request, remainder of payload is service parameters */
1146 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
1147 pcmd += sizeof (uint32_t);
1149 /* Fill in ADISC payload */
1150 ap = (ADISC *) pcmd;
1151 ap->hardAL_PA = phba->fc_pref_ALPA;
1152 memcpy(&ap->portName, &phba->fc_portname, sizeof (struct lpfc_name));
1153 memcpy(&ap->nodeName, &phba->fc_nodename, sizeof (struct lpfc_name));
1154 ap->DID = be32_to_cpu(phba->fc_myDID);
1156 phba->fc_stat.elsXmitADISC++;
1157 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
1158 spin_lock_irq(phba->host->host_lock);
1159 ndlp->nlp_flag |= NLP_ADISC_SND;
1160 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
1161 ndlp->nlp_flag &= ~NLP_ADISC_SND;
1162 spin_unlock_irq(phba->host->host_lock);
1163 lpfc_els_free_iocb(phba, elsiocb);
1166 spin_unlock_irq(phba->host->host_lock);
1171 lpfc_cmpl_els_logo(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
1172 struct lpfc_iocbq * rspiocb)
1175 struct lpfc_sli *psli;
1176 struct lpfc_nodelist *ndlp;
1179 /* we pass cmdiocb to state machine which needs rspiocb as well */
1180 cmdiocb->context_un.rsp_iocb = rspiocb;
1182 irsp = &(rspiocb->iocb);
1183 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1184 spin_lock_irq(phba->host->host_lock);
1185 ndlp->nlp_flag &= ~NLP_LOGO_SND;
1186 spin_unlock_irq(phba->host->host_lock);
1188 /* LOGO completes to NPort <nlp_DID> */
1189 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1190 "%d:0105 LOGO completes to NPort x%x "
1191 "Data: x%x x%x x%x\n",
1192 phba->brd_no, ndlp->nlp_DID, irsp->ulpStatus,
1193 irsp->un.ulpWord[4], phba->num_disc_nodes);
1195 /* Check to see if link went down during discovery */
1196 if (lpfc_els_chk_latt(phba))
1199 if (irsp->ulpStatus) {
1200 /* Check for retry */
1201 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1202 /* ELS command is being retried */
1206 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1207 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
1208 ((irsp->un.ulpWord[4] == IOERR_SLI_ABORTED) ||
1209 (irsp->un.ulpWord[4] == IOERR_SLI_DOWN))) {
1213 lpfc_disc_state_machine(phba, ndlp, cmdiocb,
1217 /* Good status, call state machine */
1218 lpfc_disc_state_machine(phba, ndlp, cmdiocb, NLP_EVT_CMPL_LOGO);
1220 if (ndlp->nlp_flag & NLP_DELAY_TMO) {
1221 lpfc_unreg_rpi(phba, ndlp);
1226 lpfc_els_free_iocb(phba, cmdiocb);
1231 lpfc_issue_els_logo(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
1235 struct lpfc_iocbq *elsiocb;
1236 struct lpfc_sli_ring *pring;
1237 struct lpfc_sli *psli;
1242 pring = &psli->ring[LPFC_ELS_RING];
1244 cmdsize = 2 * (sizeof (uint32_t) + sizeof (struct lpfc_name));
1245 if ((elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry,
1246 ndlp, ELS_CMD_LOGO)) == 0) {
1250 icmd = &elsiocb->iocb;
1251 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1252 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
1253 pcmd += sizeof (uint32_t);
1255 /* Fill in LOGO payload */
1256 *((uint32_t *) (pcmd)) = be32_to_cpu(phba->fc_myDID);
1257 pcmd += sizeof (uint32_t);
1258 memcpy(pcmd, &phba->fc_portname, sizeof (struct lpfc_name));
1260 phba->fc_stat.elsXmitLOGO++;
1261 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
1262 spin_lock_irq(phba->host->host_lock);
1263 ndlp->nlp_flag |= NLP_LOGO_SND;
1264 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
1265 ndlp->nlp_flag &= ~NLP_LOGO_SND;
1266 spin_unlock_irq(phba->host->host_lock);
1267 lpfc_els_free_iocb(phba, elsiocb);
1270 spin_unlock_irq(phba->host->host_lock);
1275 lpfc_cmpl_els_cmd(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
1276 struct lpfc_iocbq * rspiocb)
1280 irsp = &rspiocb->iocb;
1282 /* ELS cmd tag <ulpIoTag> completes */
1283 lpfc_printf_log(phba,
1286 "%d:0106 ELS cmd tag x%x completes Data: x%x x%x\n",
1288 irsp->ulpIoTag, irsp->ulpStatus, irsp->un.ulpWord[4]);
1290 /* Check to see if link went down during discovery */
1291 lpfc_els_chk_latt(phba);
1292 lpfc_els_free_iocb(phba, cmdiocb);
1297 lpfc_issue_els_scr(struct lpfc_hba * phba, uint32_t nportid, uint8_t retry)
1300 struct lpfc_iocbq *elsiocb;
1301 struct lpfc_sli_ring *pring;
1302 struct lpfc_sli *psli;
1305 struct lpfc_nodelist *ndlp;
1308 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1309 cmdsize = (sizeof (uint32_t) + sizeof (SCR));
1310 if ((ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL)) == 0) {
1314 lpfc_nlp_init(phba, ndlp, nportid);
1316 if ((elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry,
1317 ndlp, ELS_CMD_SCR)) == 0) {
1318 mempool_free( ndlp, phba->nlp_mem_pool);
1322 icmd = &elsiocb->iocb;
1323 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1325 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
1326 pcmd += sizeof (uint32_t);
1328 /* For SCR, remainder of payload is SCR parameter page */
1329 memset(pcmd, 0, sizeof (SCR));
1330 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
1332 phba->fc_stat.elsXmitSCR++;
1333 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
1334 spin_lock_irq(phba->host->host_lock);
1335 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
1336 spin_unlock_irq(phba->host->host_lock);
1337 mempool_free( ndlp, phba->nlp_mem_pool);
1338 lpfc_els_free_iocb(phba, elsiocb);
1341 spin_unlock_irq(phba->host->host_lock);
1342 mempool_free( ndlp, phba->nlp_mem_pool);
1347 lpfc_issue_els_farpr(struct lpfc_hba * phba, uint32_t nportid, uint8_t retry)
1350 struct lpfc_iocbq *elsiocb;
1351 struct lpfc_sli_ring *pring;
1352 struct lpfc_sli *psli;
1357 struct lpfc_nodelist *ondlp;
1358 struct lpfc_nodelist *ndlp;
1361 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1362 cmdsize = (sizeof (uint32_t) + sizeof (FARP));
1363 if ((ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL)) == 0) {
1366 lpfc_nlp_init(phba, ndlp, nportid);
1368 if ((elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry,
1369 ndlp, ELS_CMD_RNID)) == 0) {
1370 mempool_free( ndlp, phba->nlp_mem_pool);
1374 icmd = &elsiocb->iocb;
1375 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1377 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
1378 pcmd += sizeof (uint32_t);
1380 /* Fill in FARPR payload */
1381 fp = (FARP *) (pcmd);
1382 memset(fp, 0, sizeof (FARP));
1383 lp = (uint32_t *) pcmd;
1384 *lp++ = be32_to_cpu(nportid);
1385 *lp++ = be32_to_cpu(phba->fc_myDID);
1387 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
1389 memcpy(&fp->RportName, &phba->fc_portname, sizeof (struct lpfc_name));
1390 memcpy(&fp->RnodeName, &phba->fc_nodename, sizeof (struct lpfc_name));
1391 if ((ondlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, nportid))) {
1392 memcpy(&fp->OportName, &ondlp->nlp_portname,
1393 sizeof (struct lpfc_name));
1394 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
1395 sizeof (struct lpfc_name));
1398 phba->fc_stat.elsXmitFARPR++;
1399 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
1400 spin_lock_irq(phba->host->host_lock);
1401 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
1402 spin_unlock_irq(phba->host->host_lock);
1403 mempool_free( ndlp, phba->nlp_mem_pool);
1404 lpfc_els_free_iocb(phba, elsiocb);
1407 spin_unlock_irq(phba->host->host_lock);
1408 mempool_free( ndlp, phba->nlp_mem_pool);
1413 lpfc_els_retry_delay(unsigned long ptr)
1415 struct lpfc_nodelist *ndlp;
1416 struct lpfc_hba *phba;
1417 unsigned long iflag;
1418 struct lpfc_work_evt *evtp;
1420 ndlp = (struct lpfc_nodelist *)ptr;
1421 phba = ndlp->nlp_phba;
1422 evtp = &ndlp->els_retry_evt;
1424 spin_lock_irqsave(phba->host->host_lock, iflag);
1425 if (!list_empty(&evtp->evt_listp)) {
1426 spin_unlock_irqrestore(phba->host->host_lock, iflag);
1430 evtp->evt_arg1 = ndlp;
1431 evtp->evt = LPFC_EVT_ELS_RETRY;
1432 list_add_tail(&evtp->evt_listp, &phba->work_list);
1433 if (phba->work_wait)
1434 wake_up(phba->work_wait);
1436 spin_unlock_irqrestore(phba->host->host_lock, iflag);
1441 lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
1443 struct lpfc_hba *phba;
1448 phba = ndlp->nlp_phba;
1449 spin_lock_irq(phba->host->host_lock);
1450 did = (uint32_t) (ndlp->nlp_DID);
1451 cmd = (uint32_t) (ndlp->nlp_last_elscmd);
1453 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
1454 spin_unlock_irq(phba->host->host_lock);
1458 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
1459 spin_unlock_irq(phba->host->host_lock);
1460 retry = ndlp->nlp_retry;
1464 lpfc_issue_els_flogi(phba, ndlp, retry);
1467 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
1468 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
1469 lpfc_issue_els_plogi(phba, ndlp, retry);
1472 ndlp->nlp_state = NLP_STE_ADISC_ISSUE;
1473 lpfc_nlp_list(phba, ndlp, NLP_ADISC_LIST);
1474 lpfc_issue_els_adisc(phba, ndlp, retry);
1477 ndlp->nlp_state = NLP_STE_PRLI_ISSUE;
1478 lpfc_nlp_list(phba, ndlp, NLP_PRLI_LIST);
1479 lpfc_issue_els_prli(phba, ndlp, retry);
1482 ndlp->nlp_state = NLP_STE_NPR_NODE;
1483 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1484 lpfc_issue_els_logo(phba, ndlp, retry);
1491 lpfc_els_retry(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
1492 struct lpfc_iocbq * rspiocb)
1495 struct lpfc_dmabuf *pcmd;
1496 struct lpfc_nodelist *ndlp;
1499 int retry, maxretry;
1505 maxretry = lpfc_max_els_tries;
1506 irsp = &rspiocb->iocb;
1507 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1508 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
1510 /* Note: context2 may be 0 for internal driver abort
1511 * of delays ELS command.
1514 if (pcmd && pcmd->virt) {
1515 elscmd = (uint32_t *) (pcmd->virt);
1519 switch (irsp->ulpStatus) {
1520 case IOSTAT_FCP_RSP_ERROR:
1521 case IOSTAT_REMOTE_STOP:
1524 case IOSTAT_LOCAL_REJECT:
1525 switch ((irsp->un.ulpWord[4] & 0xff)) {
1526 case IOERR_LOOP_OPEN_FAILURE:
1527 if (cmd == ELS_CMD_PLOGI) {
1528 if (cmdiocb->retry == 0) {
1535 case IOERR_SEQUENCE_TIMEOUT:
1537 if ((cmd == ELS_CMD_FLOGI)
1538 && (phba->fc_topology != TOPOLOGY_LOOP)) {
1544 case IOERR_NO_RESOURCES:
1545 if (cmd == ELS_CMD_PLOGI) {
1551 case IOERR_INVALID_RPI:
1557 case IOSTAT_NPORT_RJT:
1558 case IOSTAT_FABRIC_RJT:
1559 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
1565 case IOSTAT_NPORT_BSY:
1566 case IOSTAT_FABRIC_BSY:
1571 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
1572 /* Added for Vendor specifc support
1573 * Just keep retrying for these Rsn / Exp codes
1575 switch (stat.un.b.lsRjtRsnCode) {
1576 case LSRJT_UNABLE_TPC:
1577 if (stat.un.b.lsRjtRsnCodeExp ==
1578 LSEXP_CMD_IN_PROGRESS) {
1579 if (cmd == ELS_CMD_PLOGI) {
1586 if (cmd == ELS_CMD_PLOGI) {
1588 maxretry = lpfc_max_els_tries + 1;
1594 case LSRJT_LOGICAL_BSY:
1595 if (cmd == ELS_CMD_PLOGI) {
1604 case IOSTAT_INTERMED_RSP:
1612 if (ndlp->nlp_DID == FDMI_DID) {
1616 if ((++cmdiocb->retry) >= maxretry) {
1617 phba->fc_stat.elsRetryExceeded++;
1623 /* Retry ELS command <elsCmd> to remote NPORT <did> */
1624 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1625 "%d:0107 Retry ELS command x%x to remote "
1626 "NPORT x%x Data: x%x x%x\n",
1628 cmd, ndlp->nlp_DID, cmdiocb->retry, delay);
1630 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) {
1631 /* If discovery / RSCN timer is running, reset it */
1632 if (timer_pending(&phba->fc_disctmo) ||
1633 (phba->fc_flag & FC_RSCN_MODE)) {
1634 lpfc_set_disctmo(phba);
1638 phba->fc_stat.elsXmitRetry++;
1640 phba->fc_stat.elsDelayRetry++;
1641 ndlp->nlp_retry = cmdiocb->retry;
1643 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
1644 ndlp->nlp_flag |= NLP_DELAY_TMO;
1646 ndlp->nlp_state = NLP_STE_NPR_NODE;
1647 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1648 ndlp->nlp_last_elscmd = cmd;
1654 lpfc_issue_els_flogi(phba, ndlp, cmdiocb->retry);
1657 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
1658 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
1659 lpfc_issue_els_plogi(phba, ndlp, cmdiocb->retry);
1662 ndlp->nlp_state = NLP_STE_ADISC_ISSUE;
1663 lpfc_nlp_list(phba, ndlp, NLP_ADISC_LIST);
1664 lpfc_issue_els_adisc(phba, ndlp, cmdiocb->retry);
1667 ndlp->nlp_state = NLP_STE_PRLI_ISSUE;
1668 lpfc_nlp_list(phba, ndlp, NLP_PRLI_LIST);
1669 lpfc_issue_els_prli(phba, ndlp, cmdiocb->retry);
1672 ndlp->nlp_state = NLP_STE_NPR_NODE;
1673 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1674 lpfc_issue_els_logo(phba, ndlp, cmdiocb->retry);
1679 /* No retry ELS command <elsCmd> to remote NPORT <did> */
1680 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1681 "%d:0108 No retry ELS command x%x to remote NPORT x%x "
1684 cmd, ndlp->nlp_DID, cmdiocb->retry, ndlp->nlp_flag);
1690 lpfc_els_free_iocb(struct lpfc_hba * phba, struct lpfc_iocbq * elsiocb)
1692 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
1694 /* context2 = cmd, context2->next = rsp, context3 = bpl */
1695 if (elsiocb->context2) {
1696 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
1697 /* Free the response before processing the command. */
1698 if (!list_empty(&buf_ptr1->list)) {
1699 list_remove_head(&buf_ptr1->list, buf_ptr,
1702 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
1705 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
1709 if (elsiocb->context3) {
1710 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
1711 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
1714 spin_lock_irq(phba->host->host_lock);
1715 list_add_tail(&elsiocb->list, &phba->lpfc_iocb_list);
1716 spin_unlock_irq(phba->host->host_lock);
1721 lpfc_cmpl_els_logo_acc(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
1722 struct lpfc_iocbq * rspiocb)
1724 struct lpfc_nodelist *ndlp;
1726 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1728 /* ACC to LOGO completes to NPort <nlp_DID> */
1729 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1730 "%d:0109 ACC to LOGO completes to NPort x%x "
1731 "Data: x%x x%x x%x\n",
1732 phba->brd_no, ndlp->nlp_DID, ndlp->nlp_flag,
1733 ndlp->nlp_state, ndlp->nlp_rpi);
1735 spin_lock_irq(phba->host->host_lock);
1736 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
1737 spin_unlock_irq(phba->host->host_lock);
1739 switch (ndlp->nlp_state) {
1740 case NLP_STE_UNUSED_NODE: /* node is just allocated */
1741 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
1743 case NLP_STE_NPR_NODE: /* NPort Recovery mode */
1744 lpfc_unreg_rpi(phba, ndlp);
1749 lpfc_els_free_iocb(phba, cmdiocb);
1754 lpfc_cmpl_els_acc(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
1755 struct lpfc_iocbq * rspiocb)
1757 struct lpfc_nodelist *ndlp;
1758 LPFC_MBOXQ_t *mbox = NULL;
1760 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1761 if (cmdiocb->context_un.mbox)
1762 mbox = cmdiocb->context_un.mbox;
1765 /* Check to see if link went down during discovery */
1766 if ((lpfc_els_chk_latt(phba)) || !ndlp) {
1768 mempool_free( mbox, phba->mbox_mem_pool);
1773 /* ELS response tag <ulpIoTag> completes */
1774 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1775 "%d:0110 ELS response tag x%x completes "
1776 "Data: x%x x%x x%x x%x x%x x%x\n",
1778 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
1779 rspiocb->iocb.un.ulpWord[4], ndlp->nlp_DID,
1780 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
1783 if ((rspiocb->iocb.ulpStatus == 0)
1784 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
1785 /* set_slim mailbox command needs to execute first,
1786 * queue this command to be processed later.
1788 lpfc_unreg_rpi(phba, ndlp);
1789 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
1790 mbox->context2 = ndlp;
1791 ndlp->nlp_state = NLP_STE_REG_LOGIN_ISSUE;
1792 lpfc_nlp_list(phba, ndlp, NLP_REGLOGIN_LIST);
1793 if (lpfc_sli_issue_mbox(phba, mbox,
1794 (MBX_NOWAIT | MBX_STOP_IOCB))
1795 != MBX_NOT_FINISHED) {
1798 /* NOTE: we should have messages for unsuccessful
1800 mempool_free( mbox, phba->mbox_mem_pool);
1802 mempool_free( mbox, phba->mbox_mem_pool);
1803 if (ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
1804 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
1810 spin_lock_irq(phba->host->host_lock);
1811 ndlp->nlp_flag &= ~NLP_ACC_REGLOGIN;
1812 spin_unlock_irq(phba->host->host_lock);
1814 lpfc_els_free_iocb(phba, cmdiocb);
1819 lpfc_els_rsp_acc(struct lpfc_hba * phba, uint32_t flag,
1820 struct lpfc_iocbq * oldiocb, struct lpfc_nodelist * ndlp,
1821 LPFC_MBOXQ_t * mbox, uint8_t newnode)
1825 struct lpfc_iocbq *elsiocb;
1826 struct lpfc_sli_ring *pring;
1827 struct lpfc_sli *psli;
1833 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1834 oldcmd = &oldiocb->iocb;
1838 cmdsize = sizeof (uint32_t);
1840 lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry,
1841 ndlp, ELS_CMD_ACC)) == 0) {
1844 icmd = &elsiocb->iocb;
1845 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
1846 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1847 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
1848 pcmd += sizeof (uint32_t);
1851 cmdsize = (sizeof (struct serv_parm) + sizeof (uint32_t));
1853 lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry,
1854 ndlp, ELS_CMD_ACC)) == 0) {
1857 icmd = &elsiocb->iocb;
1858 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
1859 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1862 elsiocb->context_un.mbox = mbox;
1864 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
1865 pcmd += sizeof (uint32_t);
1866 memcpy(pcmd, &phba->fc_sparam, sizeof (struct serv_parm));
1873 elsiocb->context1 = NULL;
1875 /* Xmit ELS ACC response tag <ulpIoTag> */
1876 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1877 "%d:0128 Xmit ELS ACC response tag x%x "
1878 "Data: x%x x%x x%x x%x x%x\n",
1880 elsiocb->iocb.ulpIoTag,
1881 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
1882 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
1884 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
1885 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
1887 elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
1890 phba->fc_stat.elsXmitACC++;
1891 spin_lock_irq(phba->host->host_lock);
1892 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
1893 spin_unlock_irq(phba->host->host_lock);
1894 if (rc == IOCB_ERROR) {
1895 lpfc_els_free_iocb(phba, elsiocb);
1902 lpfc_els_rsp_reject(struct lpfc_hba * phba, uint32_t rejectError,
1903 struct lpfc_iocbq * oldiocb, struct lpfc_nodelist * ndlp)
1907 struct lpfc_iocbq *elsiocb;
1908 struct lpfc_sli_ring *pring;
1909 struct lpfc_sli *psli;
1915 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1917 cmdsize = 2 * sizeof (uint32_t);
1918 if ((elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry,
1919 ndlp, ELS_CMD_LS_RJT)) == 0) {
1923 icmd = &elsiocb->iocb;
1924 oldcmd = &oldiocb->iocb;
1925 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
1926 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1928 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
1929 pcmd += sizeof (uint32_t);
1930 *((uint32_t *) (pcmd)) = rejectError;
1932 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
1933 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1934 "%d:0129 Xmit ELS RJT x%x response tag x%x "
1935 "Data: x%x x%x x%x x%x x%x\n",
1937 rejectError, elsiocb->iocb.ulpIoTag,
1938 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
1939 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
1941 phba->fc_stat.elsXmitLSRJT++;
1942 elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
1943 spin_lock_irq(phba->host->host_lock);
1944 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
1945 spin_unlock_irq(phba->host->host_lock);
1946 if (rc == IOCB_ERROR) {
1947 lpfc_els_free_iocb(phba, elsiocb);
1954 lpfc_els_rsp_adisc_acc(struct lpfc_hba * phba,
1955 struct lpfc_iocbq * oldiocb, struct lpfc_nodelist * ndlp)
1960 struct lpfc_iocbq *elsiocb;
1961 struct lpfc_sli_ring *pring;
1962 struct lpfc_sli *psli;
1968 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1970 cmdsize = sizeof (uint32_t) + sizeof (ADISC);
1971 if ((elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry,
1972 ndlp, ELS_CMD_ACC)) == 0) {
1976 /* Xmit ADISC ACC response tag <ulpIoTag> */
1977 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1978 "%d:0130 Xmit ADISC ACC response tag x%x "
1979 "Data: x%x x%x x%x x%x x%x\n",
1981 elsiocb->iocb.ulpIoTag,
1982 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
1983 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
1985 icmd = &elsiocb->iocb;
1986 oldcmd = &oldiocb->iocb;
1987 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
1988 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1990 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
1991 pcmd += sizeof (uint32_t);
1993 ap = (ADISC *) (pcmd);
1994 ap->hardAL_PA = phba->fc_pref_ALPA;
1995 memcpy(&ap->portName, &phba->fc_portname, sizeof (struct lpfc_name));
1996 memcpy(&ap->nodeName, &phba->fc_nodename, sizeof (struct lpfc_name));
1997 ap->DID = be32_to_cpu(phba->fc_myDID);
1999 phba->fc_stat.elsXmitACC++;
2000 elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
2001 spin_lock_irq(phba->host->host_lock);
2002 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
2003 spin_unlock_irq(phba->host->host_lock);
2004 if (rc == IOCB_ERROR) {
2005 lpfc_els_free_iocb(phba, elsiocb);
2012 lpfc_els_rsp_prli_acc(struct lpfc_hba * phba,
2013 struct lpfc_iocbq * oldiocb, struct lpfc_nodelist * ndlp)
2019 struct lpfc_iocbq *elsiocb;
2020 struct lpfc_sli_ring *pring;
2021 struct lpfc_sli *psli;
2027 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2029 cmdsize = sizeof (uint32_t) + sizeof (PRLI);
2030 if ((elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry,
2033 (ELS_CMD_PRLI & ~ELS_RSP_MASK)))) ==
2038 /* Xmit PRLI ACC response tag <ulpIoTag> */
2039 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
2040 "%d:0131 Xmit PRLI ACC response tag x%x "
2041 "Data: x%x x%x x%x x%x x%x\n",
2043 elsiocb->iocb.ulpIoTag,
2044 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
2045 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
2047 icmd = &elsiocb->iocb;
2048 oldcmd = &oldiocb->iocb;
2049 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2050 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2052 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
2053 pcmd += sizeof (uint32_t);
2055 /* For PRLI, remainder of payload is PRLI parameter page */
2056 memset(pcmd, 0, sizeof (PRLI));
2058 npr = (PRLI *) pcmd;
2061 * If our firmware version is 3.20 or later,
2062 * set the following bits for FC-TAPE support.
2064 if (vpd->rev.feaLevelHigh >= 0x02) {
2065 npr->ConfmComplAllowed = 1;
2067 npr->TaskRetryIdReq = 1;
2070 npr->acceptRspCode = PRLI_REQ_EXECUTED;
2071 npr->estabImagePair = 1;
2072 npr->readXferRdyDis = 1;
2073 npr->ConfmComplAllowed = 1;
2075 npr->prliType = PRLI_FCP_TYPE;
2076 npr->initiatorFunc = 1;
2078 phba->fc_stat.elsXmitACC++;
2079 elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
2081 spin_lock_irq(phba->host->host_lock);
2082 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
2083 spin_unlock_irq(phba->host->host_lock);
2084 if (rc == IOCB_ERROR) {
2085 lpfc_els_free_iocb(phba, elsiocb);
2092 lpfc_els_rsp_rnid_acc(struct lpfc_hba * phba,
2094 struct lpfc_iocbq * oldiocb, struct lpfc_nodelist * ndlp)
2099 struct lpfc_iocbq *elsiocb;
2100 struct lpfc_sli_ring *pring;
2101 struct lpfc_sli *psli;
2107 pring = &psli->ring[LPFC_ELS_RING];
2109 cmdsize = sizeof (uint32_t) + sizeof (uint32_t)
2110 + (2 * sizeof (struct lpfc_name));
2112 cmdsize += sizeof (RNID_TOP_DISC);
2114 if ((elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry,
2115 ndlp, ELS_CMD_ACC)) == 0) {
2119 /* Xmit RNID ACC response tag <ulpIoTag> */
2120 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
2121 "%d:0132 Xmit RNID ACC response tag x%x "
2124 elsiocb->iocb.ulpIoTag,
2125 elsiocb->iocb.ulpContext);
2127 icmd = &elsiocb->iocb;
2128 oldcmd = &oldiocb->iocb;
2129 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2130 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2132 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
2133 pcmd += sizeof (uint32_t);
2135 memset(pcmd, 0, sizeof (RNID));
2136 rn = (RNID *) (pcmd);
2137 rn->Format = format;
2138 rn->CommonLen = (2 * sizeof (struct lpfc_name));
2139 memcpy(&rn->portName, &phba->fc_portname, sizeof (struct lpfc_name));
2140 memcpy(&rn->nodeName, &phba->fc_nodename, sizeof (struct lpfc_name));
2143 rn->SpecificLen = 0;
2145 case RNID_TOPOLOGY_DISC:
2146 rn->SpecificLen = sizeof (RNID_TOP_DISC);
2147 memcpy(&rn->un.topologyDisc.portName,
2148 &phba->fc_portname, sizeof (struct lpfc_name));
2149 rn->un.topologyDisc.unitType = RNID_HBA;
2150 rn->un.topologyDisc.physPort = 0;
2151 rn->un.topologyDisc.attachedNodes = 0;
2155 rn->SpecificLen = 0;
2159 phba->fc_stat.elsXmitACC++;
2160 elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
2161 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
2162 * it could be freed */
2164 spin_lock_irq(phba->host->host_lock);
2165 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
2166 spin_unlock_irq(phba->host->host_lock);
2167 if (rc == IOCB_ERROR) {
2168 lpfc_els_free_iocb(phba, elsiocb);
2175 lpfc_els_disc_adisc(struct lpfc_hba * phba)
2178 struct lpfc_nodelist *ndlp, *next_ndlp;
2181 /* go thru NPR list and issue any remaining ELS ADISCs */
2182 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
2184 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
2185 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
2186 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2187 ndlp->nlp_state = NLP_STE_ADISC_ISSUE;
2188 lpfc_nlp_list(phba, ndlp,
2190 lpfc_issue_els_adisc(phba, ndlp, 0);
2192 phba->num_disc_nodes++;
2193 if (phba->num_disc_nodes >=
2194 phba->cfg_discovery_threads) {
2195 spin_lock_irq(phba->host->host_lock);
2196 phba->fc_flag |= FC_NLP_MORE;
2197 spin_unlock_irq(phba->host->host_lock);
2203 if (sentadisc == 0) {
2204 spin_lock_irq(phba->host->host_lock);
2205 phba->fc_flag &= ~FC_NLP_MORE;
2206 spin_unlock_irq(phba->host->host_lock);
2212 lpfc_els_disc_plogi(struct lpfc_hba * phba)
2215 struct lpfc_nodelist *ndlp, *next_ndlp;
2218 /* go thru NPR list and issue any remaining ELS PLOGIs */
2219 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
2221 if ((ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
2222 (!(ndlp->nlp_flag & NLP_DELAY_TMO))) {
2223 if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
2224 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
2225 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
2226 lpfc_issue_els_plogi(phba, ndlp, 0);
2228 phba->num_disc_nodes++;
2229 if (phba->num_disc_nodes >=
2230 phba->cfg_discovery_threads) {
2231 spin_lock_irq(phba->host->host_lock);
2232 phba->fc_flag |= FC_NLP_MORE;
2233 spin_unlock_irq(phba->host->host_lock);
2239 if (sentplogi == 0) {
2240 spin_lock_irq(phba->host->host_lock);
2241 phba->fc_flag &= ~FC_NLP_MORE;
2242 spin_unlock_irq(phba->host->host_lock);
2248 lpfc_els_flush_rscn(struct lpfc_hba * phba)
2250 struct lpfc_dmabuf *mp;
2253 for (i = 0; i < phba->fc_rscn_id_cnt; i++) {
2254 mp = phba->fc_rscn_id_list[i];
2255 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2257 phba->fc_rscn_id_list[i] = NULL;
2259 phba->fc_rscn_id_cnt = 0;
2260 spin_lock_irq(phba->host->host_lock);
2261 phba->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
2262 spin_unlock_irq(phba->host->host_lock);
2263 lpfc_can_disctmo(phba);
2268 lpfc_rscn_payload_check(struct lpfc_hba * phba, uint32_t did)
2272 struct lpfc_dmabuf *mp;
2274 uint32_t payload_len, cmd, i, match;
2276 ns_did.un.word = did;
2279 /* Never match fabric nodes for RSCNs */
2280 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
2283 /* If we are doing a FULL RSCN rediscovery, match everything */
2284 if (phba->fc_flag & FC_RSCN_DISCOVERY) {
2288 for (i = 0; i < phba->fc_rscn_id_cnt; i++) {
2289 mp = phba->fc_rscn_id_list[i];
2290 lp = (uint32_t *) mp->virt;
2292 payload_len = be32_to_cpu(cmd) & 0xffff; /* payload length */
2293 payload_len -= sizeof (uint32_t); /* take off word 0 */
2294 while (payload_len) {
2295 rscn_did.un.word = *lp++;
2296 rscn_did.un.word = be32_to_cpu(rscn_did.un.word);
2297 payload_len -= sizeof (uint32_t);
2298 switch (rscn_did.un.b.resv) {
2299 case 0: /* Single N_Port ID effected */
2300 if (ns_did.un.word == rscn_did.un.word) {
2304 case 1: /* Whole N_Port Area effected */
2305 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
2306 && (ns_did.un.b.area == rscn_did.un.b.area))
2311 case 2: /* Whole N_Port Domain effected */
2312 if (ns_did.un.b.domain == rscn_did.un.b.domain)
2317 case 3: /* Whole Fabric effected */
2321 /* Unknown Identifier in RSCN list */
2322 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2323 "%d:0217 Unknown Identifier in "
2324 "RSCN payload Data: x%x\n",
2325 phba->brd_no, rscn_did.un.word);
2337 lpfc_rscn_recovery_check(struct lpfc_hba * phba)
2339 struct lpfc_nodelist *ndlp = NULL, *next_ndlp;
2340 struct list_head *listp;
2341 struct list_head *node_list[7];
2344 /* Look at all nodes effected by pending RSCNs and move
2347 node_list[0] = &phba->fc_npr_list; /* MUST do this list first */
2348 node_list[1] = &phba->fc_nlpmap_list;
2349 node_list[2] = &phba->fc_nlpunmap_list;
2350 node_list[3] = &phba->fc_prli_list;
2351 node_list[4] = &phba->fc_reglogin_list;
2352 node_list[5] = &phba->fc_adisc_list;
2353 node_list[6] = &phba->fc_plogi_list;
2354 for (i = 0; i < 7; i++) {
2355 listp = node_list[i];
2356 if (list_empty(listp))
2359 list_for_each_entry_safe(ndlp, next_ndlp, listp, nlp_listp) {
2360 if (!(lpfc_rscn_payload_check(phba, ndlp->nlp_DID)))
2363 lpfc_disc_state_machine(phba, ndlp, NULL,
2364 NLP_EVT_DEVICE_RECOVERY);
2365 if (ndlp->nlp_flag & NLP_DELAY_TMO) {
2366 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
2367 del_timer_sync(&ndlp->nlp_delayfunc);
2368 if (!list_empty(&ndlp->
2369 els_retry_evt.evt_listp))
2370 list_del_init(&ndlp->
2371 els_retry_evt.evt_listp);
2379 lpfc_els_rcv_rscn(struct lpfc_hba * phba,
2380 struct lpfc_iocbq * cmdiocb,
2381 struct lpfc_nodelist * ndlp, uint8_t newnode)
2383 struct lpfc_dmabuf *pcmd;
2386 uint32_t payload_len, cmd;
2388 icmd = &cmdiocb->iocb;
2389 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2390 lp = (uint32_t *) pcmd->virt;
2393 payload_len = be32_to_cpu(cmd) & 0xffff; /* payload length */
2394 payload_len -= sizeof (uint32_t); /* take off word 0 */
2395 cmd &= ELS_CMD_MASK;
2398 lpfc_printf_log(phba,
2401 "%d:0214 RSCN received Data: x%x x%x x%x x%x\n",
2403 phba->fc_flag, payload_len, *lp, phba->fc_rscn_id_cnt);
2405 /* If we are about to begin discovery, just ACC the RSCN.
2406 * Discovery processing will satisfy it.
2408 if (phba->hba_state < LPFC_NS_QRY) {
2409 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL,
2414 /* If we are already processing an RSCN, save the received
2415 * RSCN payload buffer, cmdiocb->context2 to process later.
2417 if (phba->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
2418 if ((phba->fc_rscn_id_cnt < FC_MAX_HOLD_RSCN) &&
2419 !(phba->fc_flag & FC_RSCN_DISCOVERY)) {
2420 spin_lock_irq(phba->host->host_lock);
2421 phba->fc_flag |= FC_RSCN_MODE;
2422 spin_unlock_irq(phba->host->host_lock);
2423 phba->fc_rscn_id_list[phba->fc_rscn_id_cnt++] = pcmd;
2425 /* If we zero, cmdiocb->context2, the calling
2426 * routine will not try to free it.
2428 cmdiocb->context2 = NULL;
2431 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
2432 "%d:0235 Deferred RSCN "
2433 "Data: x%x x%x x%x\n",
2434 phba->brd_no, phba->fc_rscn_id_cnt,
2435 phba->fc_flag, phba->hba_state);
2437 spin_lock_irq(phba->host->host_lock);
2438 phba->fc_flag |= FC_RSCN_DISCOVERY;
2439 spin_unlock_irq(phba->host->host_lock);
2440 /* ReDiscovery RSCN */
2441 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
2442 "%d:0234 ReDiscovery RSCN "
2443 "Data: x%x x%x x%x\n",
2444 phba->brd_no, phba->fc_rscn_id_cnt,
2445 phba->fc_flag, phba->hba_state);
2448 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL,
2451 /* send RECOVERY event for ALL nodes that match RSCN payload */
2452 lpfc_rscn_recovery_check(phba);
2456 phba->fc_flag |= FC_RSCN_MODE;
2457 phba->fc_rscn_id_list[phba->fc_rscn_id_cnt++] = pcmd;
2459 * If we zero, cmdiocb->context2, the calling routine will
2460 * not try to free it.
2462 cmdiocb->context2 = NULL;
2464 lpfc_set_disctmo(phba);
2467 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, newnode);
2469 /* send RECOVERY event for ALL nodes that match RSCN payload */
2470 lpfc_rscn_recovery_check(phba);
2472 return (lpfc_els_handle_rscn(phba));
2476 lpfc_els_handle_rscn(struct lpfc_hba * phba)
2478 struct lpfc_nodelist *ndlp;
2480 /* Start timer for RSCN processing */
2481 lpfc_set_disctmo(phba);
2483 /* RSCN processed */
2484 lpfc_printf_log(phba,
2487 "%d:0215 RSCN processed Data: x%x x%x x%x x%x\n",
2489 phba->fc_flag, 0, phba->fc_rscn_id_cnt,
2492 /* To process RSCN, first compare RSCN data with NameServer */
2493 phba->fc_ns_retry = 0;
2494 if ((ndlp = lpfc_findnode_did(phba, NLP_SEARCH_UNMAPPED,
2496 /* Good ndlp, issue CT Request to NameServer */
2497 if (lpfc_ns_cmd(phba, ndlp, SLI_CTNS_GID_FT) == 0) {
2498 /* Wait for NameServer query cmpl before we can
2503 /* If login to NameServer does not exist, issue one */
2504 /* Good status, issue PLOGI to NameServer */
2506 lpfc_findnode_did(phba, NLP_SEARCH_ALL, NameServer_DID))) {
2507 /* Wait for NameServer login cmpl before we can
2511 if ((ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL))
2513 lpfc_els_flush_rscn(phba);
2516 lpfc_nlp_init(phba, ndlp, NameServer_DID);
2517 ndlp->nlp_type |= NLP_FABRIC;
2518 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
2519 lpfc_issue_els_plogi(phba, ndlp, 0);
2520 /* Wait for NameServer login cmpl before we can
2526 lpfc_els_flush_rscn(phba);
2531 lpfc_els_rcv_flogi(struct lpfc_hba * phba,
2532 struct lpfc_iocbq * cmdiocb,
2533 struct lpfc_nodelist * ndlp, uint8_t newnode)
2535 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2536 uint32_t *lp = (uint32_t *) pcmd->virt;
2537 IOCB_t *icmd = &cmdiocb->iocb;
2538 struct serv_parm *sp;
2545 sp = (struct serv_parm *) lp;
2547 /* FLOGI received */
2549 lpfc_set_disctmo(phba);
2551 if (phba->fc_topology == TOPOLOGY_LOOP) {
2552 /* We should never receive a FLOGI in loop mode, ignore it */
2553 did = icmd->un.elsreq64.remoteID;
2555 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
2557 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
2558 "%d:0113 An FLOGI ELS command x%x was received "
2559 "from DID x%x in Loop Mode\n",
2560 phba->brd_no, cmd, did);
2566 if ((lpfc_check_sparm(phba, ndlp, sp, CLASS3))) {
2567 /* For a FLOGI we accept, then if our portname is greater
2568 * then the remote portname we initiate Nport login.
2571 rc = memcmp(&phba->fc_portname, &sp->portName,
2572 sizeof (struct lpfc_name));
2575 if ((mbox = mempool_alloc(phba->mbox_mem_pool,
2576 GFP_KERNEL)) == 0) {
2579 lpfc_linkdown(phba);
2580 lpfc_init_link(phba, mbox,
2582 phba->cfg_link_speed);
2583 mbox->mb.un.varInitLnk.lipsr_AL_PA = 0;
2584 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
2585 rc = lpfc_sli_issue_mbox
2586 (phba, mbox, (MBX_NOWAIT | MBX_STOP_IOCB));
2587 if (rc == MBX_NOT_FINISHED) {
2588 mempool_free( mbox, phba->mbox_mem_pool);
2592 else if (rc > 0) { /* greater than */
2593 spin_lock_irq(phba->host->host_lock);
2594 phba->fc_flag |= FC_PT2PT_PLOGI;
2595 spin_unlock_irq(phba->host->host_lock);
2597 phba->fc_flag |= FC_PT2PT;
2598 phba->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
2600 /* Reject this request because invalid parameters */
2601 stat.un.b.lsRjtRsvd0 = 0;
2602 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2603 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
2604 stat.un.b.vendorUnique = 0;
2605 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
2610 lpfc_els_rsp_acc(phba, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL, newnode);
2616 lpfc_els_rcv_rnid(struct lpfc_hba * phba,
2617 struct lpfc_iocbq * cmdiocb, struct lpfc_nodelist * ndlp)
2619 struct lpfc_dmabuf *pcmd;
2626 icmd = &cmdiocb->iocb;
2627 did = icmd->un.elsreq64.remoteID;
2628 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2629 lp = (uint32_t *) pcmd->virt;
2636 switch (rn->Format) {
2638 case RNID_TOPOLOGY_DISC:
2640 lpfc_els_rsp_rnid_acc(phba, rn->Format, cmdiocb, ndlp);
2643 /* Reject this request because format not supported */
2644 stat.un.b.lsRjtRsvd0 = 0;
2645 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2646 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
2647 stat.un.b.vendorUnique = 0;
2648 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
2654 lpfc_els_rcv_rrq(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
2655 struct lpfc_nodelist * ndlp)
2657 struct lpfc_dmabuf *pcmd;
2660 struct lpfc_sli_ring *pring;
2661 struct lpfc_sli *psli;
2666 pring = &psli->ring[LPFC_FCP_RING];
2667 icmd = &cmdiocb->iocb;
2668 did = icmd->un.elsreq64.remoteID;
2669 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2670 lp = (uint32_t *) pcmd->virt;
2676 /* Get oxid / rxid from payload and abort it */
2677 spin_lock_irq(phba->host->host_lock);
2678 if ((rrq->SID == be32_to_cpu(phba->fc_myDID))) {
2679 lpfc_sli_abort_iocb(phba, pring, 0, 0, rrq->Oxid,
2682 lpfc_sli_abort_iocb(phba, pring, 0, 0, rrq->Rxid,
2686 spin_unlock_irq(phba->host->host_lock);
2687 /* ACCEPT the rrq request */
2688 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
2694 lpfc_els_rcv_farp(struct lpfc_hba * phba,
2695 struct lpfc_iocbq * cmdiocb, struct lpfc_nodelist * ndlp)
2697 struct lpfc_dmabuf *pcmd;
2701 uint32_t cmd, cnt, did;
2703 icmd = &cmdiocb->iocb;
2704 did = icmd->un.elsreq64.remoteID;
2705 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2706 lp = (uint32_t *) pcmd->virt;
2711 /* FARP-REQ received from DID <did> */
2712 lpfc_printf_log(phba,
2715 "%d:0601 FARP-REQ received from DID x%x\n",
2718 /* We will only support match on WWPN or WWNN */
2719 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
2724 /* If this FARP command is searching for my portname */
2725 if (fp->Mflags & FARP_MATCH_PORT) {
2726 if (memcmp(&fp->RportName, &phba->fc_portname,
2727 sizeof (struct lpfc_name)) == 0)
2731 /* If this FARP command is searching for my nodename */
2732 if (fp->Mflags & FARP_MATCH_NODE) {
2733 if (memcmp(&fp->RnodeName, &phba->fc_nodename,
2734 sizeof (struct lpfc_name)) == 0)
2739 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
2740 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
2741 /* Log back into the node before sending the FARP. */
2742 if (fp->Rflags & FARP_REQUEST_PLOGI) {
2743 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
2744 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
2745 lpfc_issue_els_plogi(phba, ndlp, 0);
2748 /* Send a FARP response to that node */
2749 if (fp->Rflags & FARP_REQUEST_FARPR) {
2750 lpfc_issue_els_farpr(phba, did, 0);
2758 lpfc_els_rcv_farpr(struct lpfc_hba * phba,
2759 struct lpfc_iocbq * cmdiocb, struct lpfc_nodelist * ndlp)
2761 struct lpfc_dmabuf *pcmd;
2766 icmd = &cmdiocb->iocb;
2767 did = icmd->un.elsreq64.remoteID;
2768 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2769 lp = (uint32_t *) pcmd->virt;
2772 /* FARP-RSP received from DID <did> */
2773 lpfc_printf_log(phba,
2776 "%d:0600 FARP-RSP received from DID x%x\n",
2779 /* ACCEPT the Farp resp request */
2780 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
2786 lpfc_els_rcv_fan(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
2787 struct lpfc_nodelist * ndlp)
2789 struct lpfc_dmabuf *pcmd;
2795 icmd = &cmdiocb->iocb;
2796 did = icmd->un.elsreq64.remoteID;
2797 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2798 lp = (uint32_t *) pcmd->virt;
2805 /* ACCEPT the FAN request */
2806 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
2808 if (phba->hba_state == LPFC_LOCAL_CFG_LINK) {
2809 /* The discovery state machine needs to take a different
2810 * action if this node has switched fabrics
2812 if ((memcmp(&fp->FportName, &phba->fc_fabparam.portName,
2813 sizeof (struct lpfc_name)) != 0)
2815 (memcmp(&fp->FnodeName, &phba->fc_fabparam.nodeName,
2816 sizeof (struct lpfc_name)) != 0)) {
2817 /* This node has switched fabrics. An FLOGI is required
2823 /* Start discovery */
2824 lpfc_disc_start(phba);
2831 lpfc_els_timeout(unsigned long ptr)
2833 struct lpfc_hba *phba;
2834 unsigned long iflag;
2836 phba = (struct lpfc_hba *)ptr;
2839 spin_lock_irqsave(phba->host->host_lock, iflag);
2840 if (!(phba->work_hba_events & WORKER_ELS_TMO)) {
2841 phba->work_hba_events |= WORKER_ELS_TMO;
2842 if (phba->work_wait)
2843 wake_up(phba->work_wait);
2845 spin_unlock_irqrestore(phba->host->host_lock, iflag);
2850 lpfc_els_timeout_handler(struct lpfc_hba *phba)
2852 struct lpfc_sli_ring *pring;
2853 struct lpfc_iocbq *tmp_iocb, *piocb;
2855 struct lpfc_dmabuf *pcmd;
2856 struct list_head *dlp;
2858 uint32_t els_command;
2864 spin_lock_irq(phba->host->host_lock);
2865 /* If the timer is already canceled do nothing */
2866 if (!(phba->work_hba_events & WORKER_ELS_TMO)) {
2867 spin_unlock_irq(phba->host->host_lock);
2870 timeout = (uint32_t)(phba->fc_ratov << 1);
2872 pring = &phba->sli.ring[LPFC_ELS_RING];
2873 dlp = &pring->txcmplq;
2875 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
2878 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
2881 pcmd = (struct lpfc_dmabuf *) piocb->context2;
2882 elscmd = (uint32_t *) (pcmd->virt);
2883 els_command = *elscmd;
2885 if ((els_command == ELS_CMD_FARP)
2886 || (els_command == ELS_CMD_FARPR)) {
2890 if (piocb->drvrTimeout > 0) {
2891 if (piocb->drvrTimeout >= timeout) {
2892 piocb->drvrTimeout -= timeout;
2894 piocb->drvrTimeout = 0;
2899 list_del(&piocb->list);
2900 pring->txcmplq_cnt--;
2902 if (cmd->ulpCommand == CMD_GEN_REQUEST64_CR) {
2903 struct lpfc_nodelist *ndlp;
2905 ndlp = lpfc_findnode_rpi(phba, cmd->ulpContext);
2906 remote_ID = ndlp->nlp_DID;
2907 if (cmd->un.elsreq64.bdl.ulpIoTag32) {
2908 lpfc_sli_issue_abort_iotag32(phba,
2912 remote_ID = cmd->un.elsreq64.remoteID;
2915 lpfc_printf_log(phba,
2918 "%d:0127 ELS timeout Data: x%x x%x x%x x%x\n",
2919 phba->brd_no, els_command,
2920 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
2923 * The iocb has timed out; abort it.
2925 if (piocb->iocb_cmpl) {
2926 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
2927 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
2928 spin_unlock_irq(phba->host->host_lock);
2929 (piocb->iocb_cmpl) (phba, piocb, piocb);
2930 spin_lock_irq(phba->host->host_lock);
2932 list_add_tail(&piocb->list, &phba->lpfc_iocb_list);
2935 if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt) {
2936 phba->els_tmofunc.expires = jiffies + HZ * timeout;
2937 add_timer(&phba->els_tmofunc);
2939 spin_unlock_irq(phba->host->host_lock);
2943 lpfc_els_flush_cmd(struct lpfc_hba * phba)
2945 struct lpfc_sli_ring *pring;
2946 struct lpfc_iocbq *tmp_iocb, *piocb;
2948 struct lpfc_dmabuf *pcmd;
2950 uint32_t els_command;
2953 pring = &phba->sli.ring[LPFC_ELS_RING];
2954 spin_lock_irq(phba->host->host_lock);
2955 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
2958 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
2962 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
2963 if ((cmd->ulpCommand == CMD_QUE_RING_BUF_CN) ||
2964 (cmd->ulpCommand == CMD_QUE_RING_BUF64_CN) ||
2965 (cmd->ulpCommand == CMD_CLOSE_XRI_CN) ||
2966 (cmd->ulpCommand == CMD_ABORT_XRI_CN)) {
2970 pcmd = (struct lpfc_dmabuf *) piocb->context2;
2971 elscmd = (uint32_t *) (pcmd->virt);
2972 els_command = *elscmd;
2974 if (cmd->ulpCommand == CMD_GEN_REQUEST64_CR) {
2975 struct lpfc_nodelist *ndlp;
2977 ndlp = lpfc_findnode_rpi(phba, cmd->ulpContext);
2978 remote_ID = ndlp->nlp_DID;
2979 if (phba->hba_state == LPFC_HBA_READY) {
2983 remote_ID = cmd->un.elsreq64.remoteID;
2986 list_del(&piocb->list);
2987 pring->txcmplq_cnt--;
2989 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
2990 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
2992 if (piocb->iocb_cmpl) {
2993 spin_unlock_irq(phba->host->host_lock);
2994 (piocb->iocb_cmpl) (phba, piocb, piocb);
2995 spin_lock_irq(phba->host->host_lock);
2998 list_add_tail(&piocb->list, &phba->lpfc_iocb_list);
3001 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
3004 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
3007 pcmd = (struct lpfc_dmabuf *) piocb->context2;
3008 elscmd = (uint32_t *) (pcmd->virt);
3009 els_command = *elscmd;
3011 if (cmd->ulpCommand == CMD_GEN_REQUEST64_CR) {
3012 struct lpfc_nodelist *ndlp;
3014 ndlp = lpfc_findnode_rpi(phba, cmd->ulpContext);
3015 remote_ID = ndlp->nlp_DID;
3016 if (phba->hba_state == LPFC_HBA_READY) {
3020 remote_ID = cmd->un.elsreq64.remoteID;
3023 list_del(&piocb->list);
3024 pring->txcmplq_cnt--;
3026 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
3027 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
3029 if (piocb->iocb_cmpl) {
3030 spin_unlock_irq(phba->host->host_lock);
3031 (piocb->iocb_cmpl) (phba, piocb, piocb);
3032 spin_lock_irq(phba->host->host_lock);
3035 list_add_tail(&piocb->list, &phba->lpfc_iocb_list);
3037 spin_unlock_irq(phba->host->host_lock);
3042 lpfc_els_unsol_event(struct lpfc_hba * phba,
3043 struct lpfc_sli_ring * pring, struct lpfc_iocbq * elsiocb)
3045 struct lpfc_sli *psli;
3046 struct lpfc_nodelist *ndlp;
3047 struct lpfc_dmabuf *mp;
3054 uint32_t drop_cmd = 0; /* by default do NOT drop received cmd */
3055 uint32_t rjt_err = 0;
3058 icmd = &elsiocb->iocb;
3060 if ((icmd->ulpStatus == IOSTAT_LOCAL_REJECT) &&
3061 ((icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING)) {
3062 /* Not enough posted buffers; Try posting more buffers */
3063 phba->fc_stat.NoRcvBuf++;
3064 lpfc_post_buffer(phba, pring, 0, 1);
3068 /* If there are no BDEs associated with this IOCB,
3069 * there is nothing to do.
3071 if (icmd->ulpBdeCount == 0)
3074 /* type of ELS cmd is first 32bit word in packet */
3075 mp = lpfc_sli_ringpostbuf_get(phba, pring, getPaddr(icmd->un.
3079 cont64[0].addrLow));
3086 lp = (uint32_t *) mp->virt;
3088 lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], 1, 1);
3090 if (icmd->ulpStatus) {
3091 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3097 /* Check to see if link went down during discovery */
3098 if (lpfc_els_chk_latt(phba)) {
3099 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3105 did = icmd->un.rcvels.remoteID;
3106 if ((ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, did)) == 0) {
3107 /* Cannot find existing Fabric ndlp, so allocate a new one */
3108 if ((ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL))
3110 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3116 lpfc_nlp_init(phba, ndlp, did);
3118 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) {
3119 ndlp->nlp_type |= NLP_FABRIC;
3123 phba->fc_stat.elsRcvFrame++;
3124 elsiocb->context1 = ndlp;
3125 elsiocb->context2 = mp;
3127 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
3128 cmd &= ELS_CMD_MASK;
3130 /* ELS command <elsCmd> received from NPORT <did> */
3131 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
3132 "%d:0112 ELS command x%x received from NPORT x%x "
3133 "Data: x%x\n", phba->brd_no, cmd, did, phba->hba_state);
3137 phba->fc_stat.elsRcvPLOGI++;
3138 if (phba->hba_state < LPFC_DISC_AUTH) {
3142 lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_PLOGI);
3145 phba->fc_stat.elsRcvFLOGI++;
3146 lpfc_els_rcv_flogi(phba, elsiocb, ndlp, newnode);
3148 mempool_free( ndlp, phba->nlp_mem_pool);
3152 phba->fc_stat.elsRcvLOGO++;
3153 if (phba->hba_state < LPFC_DISC_AUTH) {
3157 lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
3160 phba->fc_stat.elsRcvPRLO++;
3161 if (phba->hba_state < LPFC_DISC_AUTH) {
3165 lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
3168 phba->fc_stat.elsRcvRSCN++;
3169 lpfc_els_rcv_rscn(phba, elsiocb, ndlp, newnode);
3171 mempool_free( ndlp, phba->nlp_mem_pool);
3175 phba->fc_stat.elsRcvADISC++;
3176 if (phba->hba_state < LPFC_DISC_AUTH) {
3180 lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_ADISC);
3183 phba->fc_stat.elsRcvPDISC++;
3184 if (phba->hba_state < LPFC_DISC_AUTH) {
3188 lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_PDISC);
3191 phba->fc_stat.elsRcvFARPR++;
3192 lpfc_els_rcv_farpr(phba, elsiocb, ndlp);
3195 phba->fc_stat.elsRcvFARP++;
3196 lpfc_els_rcv_farp(phba, elsiocb, ndlp);
3199 phba->fc_stat.elsRcvFAN++;
3200 lpfc_els_rcv_fan(phba, elsiocb, ndlp);
3203 phba->fc_stat.elsRcvRRQ++;
3204 lpfc_els_rcv_rrq(phba, elsiocb, ndlp);
3207 phba->fc_stat.elsRcvPRLI++;
3208 if (phba->hba_state < LPFC_DISC_AUTH) {
3212 lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
3215 phba->fc_stat.elsRcvRNID++;
3216 lpfc_els_rcv_rnid(phba, elsiocb, ndlp);
3219 /* Unsupported ELS command, reject */
3222 /* Unknown ELS command <elsCmd> received from NPORT <did> */
3223 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
3224 "%d:0115 Unknown ELS command x%x received from "
3225 "NPORT x%x\n", phba->brd_no, cmd, did);
3227 mempool_free( ndlp, phba->nlp_mem_pool);
3232 /* check if need to LS_RJT received ELS cmd */
3234 stat.un.b.lsRjtRsvd0 = 0;
3235 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3236 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
3237 stat.un.b.vendorUnique = 0;
3238 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, elsiocb, ndlp);
3241 if (elsiocb->context2) {
3242 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3246 /* check if need to drop received ELS cmd */
3247 if (drop_cmd == 1) {
3248 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
3249 "%d:0111 Dropping received ELS cmd "
3250 "Data: x%x x%x\n", phba->brd_no,
3251 icmd->ulpStatus, icmd->un.ulpWord[4]);
3252 phba->fc_stat.elsRcvDrop++;