1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2007 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. *
7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
9 * This program is free software; you can redistribute it and/or *
10 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
20 *******************************************************************/
22 #include <linux/blkdev.h>
23 #include <linux/pci.h>
24 #include <linux/interrupt.h>
26 #include <scsi/scsi.h>
27 #include <scsi/scsi_device.h>
28 #include <scsi/scsi_host.h>
29 #include <scsi/scsi_transport_fc.h>
33 #include "lpfc_disc.h"
34 #include "lpfc_scsi.h"
36 #include "lpfc_logmsg.h"
37 #include "lpfc_crtn.h"
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_vport *vport)
46 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
47 struct lpfc_hba *phba = vport->phba;
50 if (vport->port_state >= LPFC_VPORT_READY ||
51 phba->link_state == LPFC_LINK_DOWN)
54 /* Read the HBA Host Attention Register */
55 ha_copy = readl(phba->HAregaddr);
57 if (!(ha_copy & HA_LATT))
60 /* Pending Link Event during Discovery */
61 lpfc_printf_log(phba, KERN_WARNING, LOG_DISCOVERY,
62 "%d:0237 Pending Link Event during "
63 "Discovery: State x%x\n",
64 phba->brd_no, phba->pport->port_state);
66 /* CLEAR_LA should re-enable link attention events and
67 * we should then imediately take a LATT event. The
68 * LATT processing should call lpfc_linkdown() which
69 * will cleanup any left over in-progress discovery
72 spin_lock_irq(shost->host_lock);
73 vport->fc_flag |= FC_ABORT_DISCOVERY;
74 spin_unlock_irq(shost->host_lock);
76 if (phba->link_state != LPFC_CLEAR_LA) {
77 lpfc_issue_clear_la(phba, vport);
84 static struct lpfc_iocbq *
85 lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp,
86 uint16_t cmdSize, uint8_t retry,
87 struct lpfc_nodelist *ndlp, uint32_t did,
90 struct lpfc_hba *phba = vport->phba;
91 struct lpfc_iocbq *elsiocb;
92 struct lpfc_dmabuf *pcmd, *prsp, *pbuflist;
93 struct ulp_bde64 *bpl;
97 if (!lpfc_is_link_up(phba))
100 /* Allocate buffer for command iocb */
101 elsiocb = lpfc_sli_get_iocbq(phba);
105 icmd = &elsiocb->iocb;
107 /* fill in BDEs for command */
108 /* Allocate buffer for command payload */
109 if (((pcmd = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL)) == 0) ||
110 ((pcmd->virt = lpfc_mbuf_alloc(phba,
111 MEM_PRI, &(pcmd->phys))) == 0)) {
114 lpfc_sli_release_iocbq(phba, elsiocb);
118 INIT_LIST_HEAD(&pcmd->list);
120 /* Allocate buffer for response payload */
122 prsp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
124 prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
126 if (prsp == 0 || prsp->virt == 0) {
128 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
130 lpfc_sli_release_iocbq(phba, elsiocb);
133 INIT_LIST_HEAD(&prsp->list);
138 /* Allocate buffer for Buffer ptr list */
139 pbuflist = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
141 pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
143 if (pbuflist == 0 || pbuflist->virt == 0) {
144 lpfc_sli_release_iocbq(phba, elsiocb);
145 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
146 lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
153 INIT_LIST_HEAD(&pbuflist->list);
155 icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
156 icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
157 icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BDL;
158 icmd->un.elsreq64.remoteID = did; /* DID */
160 icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof (struct ulp_bde64));
161 icmd->ulpCommand = CMD_ELS_REQUEST64_CR;
162 icmd->ulpTimeout = phba->fc_ratov * 2;
164 icmd->un.elsreq64.bdl.bdeSize = sizeof (struct ulp_bde64);
165 icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
168 icmd->ulpBdeCount = 1;
170 icmd->ulpClass = CLASS3;
172 bpl = (struct ulp_bde64 *) pbuflist->virt;
173 bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys));
174 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys));
175 bpl->tus.f.bdeSize = cmdSize;
176 bpl->tus.f.bdeFlags = 0;
177 bpl->tus.w = le32_to_cpu(bpl->tus.w);
181 bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys));
182 bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys));
183 bpl->tus.f.bdeSize = FCELSSIZE;
184 bpl->tus.f.bdeFlags = BUFF_USE_RCV;
185 bpl->tus.w = le32_to_cpu(bpl->tus.w);
188 /* Save for completion so we can release these resources */
189 elsiocb->context1 = lpfc_nlp_get(ndlp);
190 elsiocb->context2 = pcmd;
191 elsiocb->context3 = pbuflist;
192 elsiocb->retry = retry;
193 elsiocb->vport = vport;
194 elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
197 list_add(&prsp->list, &pcmd->list);
201 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
202 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
203 "%d:0116 Xmit ELS command x%x to remote "
204 "NPORT x%x I/O tag: x%x, port state: x%x\n",
205 phba->brd_no, elscmd, did,
206 elsiocb->iotag, vport->port_state);
208 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
209 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
210 "%d:0117 Xmit ELS response x%x to remote "
211 "NPORT x%x I/O tag: x%x, size: x%x\n",
212 phba->brd_no, elscmd,
213 ndlp->nlp_DID, elsiocb->iotag, cmdSize);
221 lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
222 struct serv_parm *sp, IOCB_t *irsp)
224 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
225 struct lpfc_hba *phba = vport->phba;
227 struct lpfc_dmabuf *mp;
230 spin_lock_irq(shost->host_lock);
231 vport->fc_flag |= FC_FABRIC;
232 spin_unlock_irq(shost->host_lock);
234 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
235 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
236 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
238 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
240 if (phba->fc_topology == TOPOLOGY_LOOP) {
241 spin_lock_irq(shost->host_lock);
242 vport->fc_flag |= FC_PUBLIC_LOOP;
243 spin_unlock_irq(shost->host_lock);
246 * If we are a N-port connected to a Fabric, fixup sparam's so
247 * logins to devices on remote loops work.
249 vport->fc_sparam.cmn.altBbCredit = 1;
252 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
253 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
254 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof (struct lpfc_name));
255 ndlp->nlp_class_sup = 0;
256 if (sp->cls1.classValid)
257 ndlp->nlp_class_sup |= FC_COS_CLASS1;
258 if (sp->cls2.classValid)
259 ndlp->nlp_class_sup |= FC_COS_CLASS2;
260 if (sp->cls3.classValid)
261 ndlp->nlp_class_sup |= FC_COS_CLASS3;
262 if (sp->cls4.classValid)
263 ndlp->nlp_class_sup |= FC_COS_CLASS4;
264 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
265 sp->cmn.bbRcvSizeLsb;
266 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
268 ndlp->nlp_sid = irsp->un.ulpWord[4] & Mask_DID;
270 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
274 vport->port_state = LPFC_FABRIC_CFG_LINK;
275 lpfc_config_link(phba, mbox);
276 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
279 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT | MBX_STOP_IOCB);
280 if (rc == MBX_NOT_FINISHED)
283 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
286 rc = lpfc_reg_login(phba, Fabric_DID, (uint8_t *) sp, mbox, 0);
290 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
292 mbox->context2 = lpfc_nlp_get(ndlp);
294 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT | MBX_STOP_IOCB);
295 if (rc == MBX_NOT_FINISHED)
296 goto fail_issue_reg_login;
300 fail_issue_reg_login:
302 mp = (struct lpfc_dmabuf *) mbox->context1;
303 lpfc_mbuf_free(phba, mp->virt, mp->phys);
306 mempool_free(mbox, phba->mbox_mem_pool);
312 * We FLOGIed into an NPort, initiate pt2pt protocol
315 lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
316 struct serv_parm *sp)
318 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
319 struct lpfc_hba *phba = vport->phba;
323 spin_lock_irq(shost->host_lock);
324 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
325 spin_unlock_irq(shost->host_lock);
327 phba->fc_edtov = FF_DEF_EDTOV;
328 phba->fc_ratov = FF_DEF_RATOV;
329 rc = memcmp(&vport->fc_portname, &sp->portName,
330 sizeof(struct lpfc_name));
332 /* This side will initiate the PLOGI */
333 spin_lock_irq(shost->host_lock);
334 vport->fc_flag |= FC_PT2PT_PLOGI;
335 spin_unlock_irq(shost->host_lock);
338 * N_Port ID cannot be 0, set our to LocalID the other
339 * side will be RemoteID.
344 vport->fc_myDID = PT2PT_LocalID;
346 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
350 lpfc_config_link(phba, mbox);
352 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
354 rc = lpfc_sli_issue_mbox(phba, mbox,
355 MBX_NOWAIT | MBX_STOP_IOCB);
356 if (rc == MBX_NOT_FINISHED) {
357 mempool_free(mbox, phba->mbox_mem_pool);
362 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
365 * Cannot find existing Fabric ndlp, so allocate a
368 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
372 lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID);
375 memcpy(&ndlp->nlp_portname, &sp->portName,
376 sizeof(struct lpfc_name));
377 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
378 sizeof(struct lpfc_name));
379 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
380 spin_lock_irq(shost->host_lock);
381 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
382 spin_unlock_irq(shost->host_lock);
384 /* This side will wait for the PLOGI */
388 spin_lock_irq(shost->host_lock);
389 vport->fc_flag |= FC_PT2PT;
390 spin_unlock_irq(shost->host_lock);
392 /* Start discovery - this should just do CLEAR_LA */
393 lpfc_disc_start(vport);
400 lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
401 struct lpfc_iocbq *rspiocb)
403 struct lpfc_vport *vport = cmdiocb->vport;
404 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
405 IOCB_t *irsp = &rspiocb->iocb;
406 struct lpfc_nodelist *ndlp = cmdiocb->context1;
407 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
408 struct serv_parm *sp;
411 /* Check to see if link went down during discovery */
412 if (lpfc_els_chk_latt(vport)) {
417 if (irsp->ulpStatus) {
418 /* Check for retry */
419 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
422 /* FLOGI failed, so there is no fabric */
423 spin_lock_irq(shost->host_lock);
424 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
425 spin_unlock_irq(shost->host_lock);
427 /* If private loop, then allow max outstanding els to be
428 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
429 * alpa map would take too long otherwise.
431 if (phba->alpa_map[0] == 0) {
432 phba->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
436 lpfc_printf_log(phba,
439 "%d:0100 FLOGI failure Data: x%x x%x x%x\n",
441 irsp->ulpStatus, irsp->un.ulpWord[4],
447 * The FLogI succeeded. Sync the data for the CPU before
450 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
452 sp = prsp->virt + sizeof(uint32_t);
454 /* FLOGI completes successfully */
455 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
456 "%d:0101 FLOGI completes sucessfully "
457 "Data: x%x x%x x%x x%x\n",
459 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
460 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution);
462 if (vport->port_state == LPFC_FLOGI) {
464 * If Common Service Parameters indicate Nport
465 * we are point to point, if Fport we are Fabric.
468 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
470 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
479 if (irsp->ulpStatus != IOSTAT_LOCAL_REJECT ||
480 (irsp->un.ulpWord[4] != IOERR_SLI_ABORTED &&
481 irsp->un.ulpWord[4] != IOERR_SLI_DOWN)) {
482 /* FLOGI failed, so just use loop map to make discovery list */
483 lpfc_disc_list_loopmap(vport);
485 /* Start discovery */
486 lpfc_disc_start(vport);
490 lpfc_els_free_iocb(phba, cmdiocb);
494 lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
497 struct lpfc_hba *phba = vport->phba;
498 struct serv_parm *sp;
500 struct lpfc_iocbq *elsiocb;
501 struct lpfc_sli_ring *pring;
507 pring = &phba->sli.ring[LPFC_ELS_RING];
509 cmdsize = (sizeof (uint32_t) + sizeof (struct serv_parm));
510 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
511 ndlp->nlp_DID, ELS_CMD_FLOGI);
515 icmd = &elsiocb->iocb;
516 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
518 /* For FLOGI request, remainder of payload is service parameters */
519 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
520 pcmd += sizeof (uint32_t);
521 memcpy(pcmd, &vport->fc_sparam, sizeof (struct serv_parm));
522 sp = (struct serv_parm *) pcmd;
524 /* Setup CSPs accordingly for Fabric */
526 sp->cmn.w2.r_a_tov = 0;
527 sp->cls1.classValid = 0;
528 sp->cls2.seqDelivery = 1;
529 sp->cls3.seqDelivery = 1;
530 if (sp->cmn.fcphLow < FC_PH3)
531 sp->cmn.fcphLow = FC_PH3;
532 if (sp->cmn.fcphHigh < FC_PH3)
533 sp->cmn.fcphHigh = FC_PH3;
535 tmo = phba->fc_ratov;
536 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
537 lpfc_set_disctmo(vport);
538 phba->fc_ratov = tmo;
540 phba->fc_stat.elsXmitFLOGI++;
541 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
542 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
543 if (rc == IOCB_ERROR) {
544 lpfc_els_free_iocb(phba, elsiocb);
551 lpfc_els_abort_flogi(struct lpfc_hba *phba)
553 struct lpfc_sli_ring *pring;
554 struct lpfc_iocbq *iocb, *next_iocb;
555 struct lpfc_nodelist *ndlp;
558 /* Abort outstanding I/O on NPort <nlp_DID> */
559 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
560 "%d:0201 Abort outstanding I/O on NPort x%x\n",
561 phba->brd_no, Fabric_DID);
563 pring = &phba->sli.ring[LPFC_ELS_RING];
566 * Check the txcmplq for an iocb that matches the nport the driver is
569 spin_lock_irq(&phba->hbalock);
570 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
572 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR &&
573 icmd->un.elsreq64.bdl.ulpIoTag32) {
574 ndlp = (struct lpfc_nodelist *)(iocb->context1);
575 if (ndlp && (ndlp->nlp_DID == Fabric_DID))
576 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
579 spin_unlock_irq(&phba->hbalock);
585 lpfc_initial_flogi(struct lpfc_vport *vport)
587 struct lpfc_hba *phba = vport->phba;
588 struct lpfc_nodelist *ndlp;
590 /* First look for the Fabric ndlp */
591 ndlp = lpfc_findnode_did(vport, Fabric_DID);
593 /* Cannot find existing Fabric ndlp, so allocate a new one */
594 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
597 lpfc_nlp_init(vport, ndlp, Fabric_DID);
599 lpfc_dequeue_node(vport, ndlp);
601 if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
608 lpfc_more_plogi(struct lpfc_vport *vport)
611 struct lpfc_hba *phba = vport->phba;
613 if (vport->num_disc_nodes)
614 vport->num_disc_nodes--;
616 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
617 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
618 "%d:0232 Continue discovery with %d PLOGIs to go "
619 "Data: x%x x%x x%x\n",
620 phba->brd_no, vport->num_disc_nodes,
621 vport->fc_plogi_cnt, vport->fc_flag, vport->port_state);
623 /* Check to see if there are more PLOGIs to be sent */
624 if (vport->fc_flag & FC_NLP_MORE)
625 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
626 sentplogi = lpfc_els_disc_plogi(vport);
631 static struct lpfc_nodelist *
632 lpfc_plogi_confirm_nport(struct lpfc_hba *phba, struct lpfc_dmabuf *prsp,
633 struct lpfc_nodelist *ndlp)
635 struct lpfc_vport *vport = ndlp->vport;
636 struct lpfc_nodelist *new_ndlp;
638 struct serv_parm *sp;
639 uint8_t name[sizeof (struct lpfc_name)];
642 /* Fabric nodes can have the same WWPN so we don't bother searching
643 * by WWPN. Just return the ndlp that was given to us.
645 if (ndlp->nlp_type & NLP_FABRIC)
648 lp = (uint32_t *) prsp->virt;
649 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
650 memset(name, 0, sizeof(struct lpfc_name));
652 /* Now we find out if the NPort we are logging into, matches the WWPN
653 * we have for that ndlp. If not, we have some work to do.
655 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
657 if (new_ndlp == ndlp)
661 rc = memcmp(&ndlp->nlp_portname, name,
662 sizeof(struct lpfc_name));
665 new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
669 lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID);
672 lpfc_unreg_rpi(vport, new_ndlp);
673 new_ndlp->nlp_DID = ndlp->nlp_DID;
674 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
675 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
677 /* Move this back to NPR state */
678 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0)
679 lpfc_drop_node(vport, ndlp);
681 lpfc_unreg_rpi(vport, ndlp);
682 ndlp->nlp_DID = 0; /* Two ndlps cannot have the same did */
683 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
689 lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
690 struct lpfc_iocbq *rspiocb)
692 struct lpfc_vport *vport = cmdiocb->vport;
693 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
695 struct lpfc_nodelist *ndlp;
696 struct lpfc_dmabuf *prsp;
697 int disc, rc, did, type;
699 /* we pass cmdiocb to state machine which needs rspiocb as well */
700 cmdiocb->context_un.rsp_iocb = rspiocb;
702 irsp = &rspiocb->iocb;
703 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
709 /* Since ndlp can be freed in the disc state machine, note if this node
710 * is being used during discovery.
712 spin_lock_irq(shost->host_lock);
713 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
714 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
715 spin_unlock_irq(shost->host_lock);
718 /* PLOGI completes to NPort <nlp_DID> */
719 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
720 "%d:0102 PLOGI completes to NPort x%x "
721 "Data: x%x x%x x%x x%x x%x\n",
722 phba->brd_no, ndlp->nlp_DID, irsp->ulpStatus,
723 irsp->un.ulpWord[4], irsp->ulpTimeout, disc,
724 vport->num_disc_nodes);
726 /* Check to see if link went down during discovery */
727 if (lpfc_els_chk_latt(vport)) {
728 spin_lock_irq(shost->host_lock);
729 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
730 spin_unlock_irq(shost->host_lock);
734 /* ndlp could be freed in DSM, save these values now */
735 type = ndlp->nlp_type;
738 if (irsp->ulpStatus) {
739 /* Check for retry */
740 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
741 /* ELS command is being retried */
743 spin_lock_irq(shost->host_lock);
744 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
745 spin_unlock_irq(shost->host_lock);
751 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
752 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
753 ((irsp->un.ulpWord[4] == IOERR_SLI_ABORTED) ||
754 (irsp->un.ulpWord[4] == IOERR_LINK_DOWN) ||
755 (irsp->un.ulpWord[4] == IOERR_SLI_DOWN))) {
756 rc = NLP_STE_FREED_NODE;
758 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
762 /* Good status, call state machine */
763 prsp = list_entry(((struct lpfc_dmabuf *)
764 cmdiocb->context2)->list.next,
765 struct lpfc_dmabuf, list);
766 ndlp = lpfc_plogi_confirm_nport(phba, prsp, ndlp);
767 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
771 if (disc && vport->num_disc_nodes) {
772 /* Check to see if there are more PLOGIs to be sent */
773 lpfc_more_plogi(vport);
775 if (vport->num_disc_nodes == 0) {
776 spin_lock_irq(shost->host_lock);
777 vport->fc_flag &= ~FC_NDISC_ACTIVE;
778 spin_unlock_irq(shost->host_lock);
780 lpfc_can_disctmo(vport);
781 if (vport->fc_flag & FC_RSCN_MODE) {
783 * Check to see if more RSCNs came in while
784 * we were processing this one.
786 if ((vport->fc_rscn_id_cnt == 0) &&
787 (!(vport->fc_flag & FC_RSCN_DISCOVERY))) {
788 spin_lock_irq(shost->host_lock);
789 vport->fc_flag &= ~FC_RSCN_MODE;
790 spin_unlock_irq(shost->host_lock);
792 lpfc_els_handle_rscn(vport);
799 lpfc_els_free_iocb(phba, cmdiocb);
804 lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
806 struct lpfc_hba *phba = vport->phba;
807 struct serv_parm *sp;
809 struct lpfc_iocbq *elsiocb;
810 struct lpfc_sli_ring *pring;
811 struct lpfc_sli *psli;
816 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
818 cmdsize = (sizeof (uint32_t) + sizeof (struct serv_parm));
819 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, NULL, did,
824 icmd = &elsiocb->iocb;
825 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
827 /* For PLOGI request, remainder of payload is service parameters */
828 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
829 pcmd += sizeof (uint32_t);
830 memcpy(pcmd, &vport->fc_sparam, sizeof (struct serv_parm));
831 sp = (struct serv_parm *) pcmd;
833 if (sp->cmn.fcphLow < FC_PH_4_3)
834 sp->cmn.fcphLow = FC_PH_4_3;
836 if (sp->cmn.fcphHigh < FC_PH3)
837 sp->cmn.fcphHigh = FC_PH3;
839 phba->fc_stat.elsXmitPLOGI++;
840 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
841 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
842 lpfc_els_free_iocb(phba, elsiocb);
849 lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
850 struct lpfc_iocbq *rspiocb)
852 struct lpfc_vport *vport = cmdiocb->vport;
853 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
855 struct lpfc_sli *psli;
856 struct lpfc_nodelist *ndlp;
859 /* we pass cmdiocb to state machine which needs rspiocb as well */
860 cmdiocb->context_un.rsp_iocb = rspiocb;
862 irsp = &(rspiocb->iocb);
863 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
864 spin_lock_irq(shost->host_lock);
865 ndlp->nlp_flag &= ~NLP_PRLI_SND;
866 spin_unlock_irq(shost->host_lock);
868 /* PRLI completes to NPort <nlp_DID> */
869 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
870 "%d:0103 PRLI completes to NPort x%x "
871 "Data: x%x x%x x%x x%x\n",
872 phba->brd_no, ndlp->nlp_DID, irsp->ulpStatus,
873 irsp->un.ulpWord[4], irsp->ulpTimeout,
874 vport->num_disc_nodes);
876 vport->fc_prli_sent--;
877 /* Check to see if link went down during discovery */
878 if (lpfc_els_chk_latt(vport))
881 if (irsp->ulpStatus) {
882 /* Check for retry */
883 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
884 /* ELS command is being retried */
888 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
889 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
890 ((irsp->un.ulpWord[4] == IOERR_SLI_ABORTED) ||
891 (irsp->un.ulpWord[4] == IOERR_LINK_DOWN) ||
892 (irsp->un.ulpWord[4] == IOERR_SLI_DOWN))) {
895 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
899 /* Good status, call state machine */
900 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
905 lpfc_els_free_iocb(phba, cmdiocb);
910 lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
913 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
914 struct lpfc_hba *phba = vport->phba;
917 struct lpfc_iocbq *elsiocb;
918 struct lpfc_sli_ring *pring;
919 struct lpfc_sli *psli;
924 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
926 cmdsize = (sizeof (uint32_t) + sizeof (PRLI));
927 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
928 ndlp->nlp_DID, ELS_CMD_PRLI);
932 icmd = &elsiocb->iocb;
933 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
935 /* For PRLI request, remainder of payload is service parameters */
936 memset(pcmd, 0, (sizeof (PRLI) + sizeof (uint32_t)));
937 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
938 pcmd += sizeof (uint32_t);
940 /* For PRLI, remainder of payload is PRLI parameter page */
943 * If our firmware version is 3.20 or later,
944 * set the following bits for FC-TAPE support.
946 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
947 npr->ConfmComplAllowed = 1;
949 npr->TaskRetryIdReq = 1;
951 npr->estabImagePair = 1;
952 npr->readXferRdyDis = 1;
954 /* For FCP support */
955 npr->prliType = PRLI_FCP_TYPE;
956 npr->initiatorFunc = 1;
958 phba->fc_stat.elsXmitPRLI++;
959 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
960 spin_lock_irq(shost->host_lock);
961 ndlp->nlp_flag |= NLP_PRLI_SND;
962 spin_unlock_irq(shost->host_lock);
963 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
964 spin_lock_irq(shost->host_lock);
965 ndlp->nlp_flag &= ~NLP_PRLI_SND;
966 spin_unlock_irq(shost->host_lock);
967 lpfc_els_free_iocb(phba, elsiocb);
970 vport->fc_prli_sent++;
975 lpfc_more_adisc(struct lpfc_vport *vport)
978 struct lpfc_hba *phba = vport->phba;
980 if (vport->num_disc_nodes)
981 vport->num_disc_nodes--;
983 /* Continue discovery with <num_disc_nodes> ADISCs to go */
984 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
985 "%d:0210 Continue discovery with %d ADISCs to go "
986 "Data: x%x x%x x%x\n",
987 phba->brd_no, vport->num_disc_nodes,
988 vport->fc_adisc_cnt, vport->fc_flag, vport->port_state);
990 /* Check to see if there are more ADISCs to be sent */
991 if (vport->fc_flag & FC_NLP_MORE) {
992 lpfc_set_disctmo(vport);
993 /* go thru NPR nodes and issue any remaining ELS ADISCs */
994 sentadisc = lpfc_els_disc_adisc(vport);
1000 lpfc_rscn_disc(struct lpfc_vport *vport)
1002 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1004 /* RSCN discovery */
1005 /* go thru NPR nodes and issue ELS PLOGIs */
1006 if (vport->fc_npr_cnt)
1007 if (lpfc_els_disc_plogi(vport))
1010 if (vport->fc_flag & FC_RSCN_MODE) {
1011 /* Check to see if more RSCNs came in while we were
1012 * processing this one.
1014 if ((vport->fc_rscn_id_cnt == 0) &&
1015 (!(vport->fc_flag & FC_RSCN_DISCOVERY))) {
1016 spin_lock_irq(shost->host_lock);
1017 vport->fc_flag &= ~FC_RSCN_MODE;
1018 spin_unlock_irq(shost->host_lock);
1020 lpfc_els_handle_rscn(vport);
1026 lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1027 struct lpfc_iocbq *rspiocb)
1029 struct lpfc_vport *vport = cmdiocb->vport;
1030 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1032 struct lpfc_nodelist *ndlp;
1035 /* we pass cmdiocb to state machine which needs rspiocb as well */
1036 cmdiocb->context_un.rsp_iocb = rspiocb;
1038 irsp = &(rspiocb->iocb);
1039 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1041 /* Since ndlp can be freed in the disc state machine, note if this node
1042 * is being used during discovery.
1044 spin_lock_irq(shost->host_lock);
1045 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
1046 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
1047 spin_unlock_irq(shost->host_lock);
1049 /* ADISC completes to NPort <nlp_DID> */
1050 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1051 "%d:0104 ADISC completes to NPort x%x "
1052 "Data: x%x x%x x%x x%x x%x\n",
1053 phba->brd_no, ndlp->nlp_DID, irsp->ulpStatus,
1054 irsp->un.ulpWord[4], irsp->ulpTimeout, disc,
1055 vport->num_disc_nodes);
1057 /* Check to see if link went down during discovery */
1058 if (lpfc_els_chk_latt(vport)) {
1059 spin_lock_irq(shost->host_lock);
1060 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1061 spin_unlock_irq(shost->host_lock);
1065 if (irsp->ulpStatus) {
1066 /* Check for retry */
1067 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1068 /* ELS command is being retried */
1070 spin_lock_irq(shost->host_lock);
1071 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1072 spin_unlock_irq(shost->host_lock);
1073 lpfc_set_disctmo(vport);
1078 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1079 if ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
1080 ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) &&
1081 (irsp->un.ulpWord[4] != IOERR_LINK_DOWN) &&
1082 (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) {
1083 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1084 NLP_EVT_CMPL_ADISC);
1087 /* Good status, call state machine */
1088 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1089 NLP_EVT_CMPL_ADISC);
1092 if (disc && vport->num_disc_nodes) {
1093 /* Check to see if there are more ADISCs to be sent */
1094 lpfc_more_adisc(vport);
1096 /* Check to see if we are done with ADISC authentication */
1097 if (vport->num_disc_nodes == 0) {
1098 lpfc_can_disctmo(vport);
1099 /* If we get here, there is nothing left to wait for */
1100 if (vport->port_state < LPFC_VPORT_READY &&
1101 phba->link_state != LPFC_CLEAR_LA) {
1102 if (vport->port_type == LPFC_PHYSICAL_PORT)
1103 lpfc_issue_clear_la(phba, vport);
1105 lpfc_rscn_disc(vport);
1110 lpfc_els_free_iocb(phba, cmdiocb);
1115 lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1118 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1119 struct lpfc_hba *phba = vport->phba;
1122 struct lpfc_iocbq *elsiocb;
1123 struct lpfc_sli *psli = &phba->sli;
1124 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
1128 cmdsize = (sizeof (uint32_t) + sizeof (ADISC));
1129 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1130 ndlp->nlp_DID, ELS_CMD_ADISC);
1134 icmd = &elsiocb->iocb;
1135 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1137 /* For ADISC request, remainder of payload is service parameters */
1138 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
1139 pcmd += sizeof (uint32_t);
1141 /* Fill in ADISC payload */
1142 ap = (ADISC *) pcmd;
1143 ap->hardAL_PA = phba->fc_pref_ALPA;
1144 memcpy(&ap->portName, &vport->fc_portname, sizeof (struct lpfc_name));
1145 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof (struct lpfc_name));
1146 ap->DID = be32_to_cpu(vport->fc_myDID);
1148 phba->fc_stat.elsXmitADISC++;
1149 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
1150 spin_lock_irq(shost->host_lock);
1151 ndlp->nlp_flag |= NLP_ADISC_SND;
1152 spin_unlock_irq(shost->host_lock);
1153 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
1154 spin_lock_irq(shost->host_lock);
1155 ndlp->nlp_flag &= ~NLP_ADISC_SND;
1156 spin_unlock_irq(shost->host_lock);
1157 lpfc_els_free_iocb(phba, elsiocb);
1164 lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1165 struct lpfc_iocbq *rspiocb)
1167 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1168 struct lpfc_vport *vport = ndlp->vport;
1169 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1171 struct lpfc_sli *psli;
1174 /* we pass cmdiocb to state machine which needs rspiocb as well */
1175 cmdiocb->context_un.rsp_iocb = rspiocb;
1177 irsp = &(rspiocb->iocb);
1178 spin_lock_irq(shost->host_lock);
1179 ndlp->nlp_flag &= ~NLP_LOGO_SND;
1180 spin_unlock_irq(shost->host_lock);
1182 /* LOGO completes to NPort <nlp_DID> */
1183 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1184 "%d:0105 LOGO completes to NPort x%x "
1185 "Data: x%x x%x x%x x%x\n",
1186 phba->brd_no, ndlp->nlp_DID, irsp->ulpStatus,
1187 irsp->un.ulpWord[4], irsp->ulpTimeout,
1188 vport->num_disc_nodes);
1190 /* Check to see if link went down during discovery */
1191 if (lpfc_els_chk_latt(vport))
1194 if (irsp->ulpStatus) {
1195 /* Check for retry */
1196 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
1197 /* ELS command is being retried */
1200 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1201 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
1202 ((irsp->un.ulpWord[4] == IOERR_SLI_ABORTED) ||
1203 (irsp->un.ulpWord[4] == IOERR_LINK_DOWN) ||
1204 (irsp->un.ulpWord[4] == IOERR_SLI_DOWN))) {
1207 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1211 /* Good status, call state machine.
1212 * This will unregister the rpi if needed.
1214 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1219 lpfc_els_free_iocb(phba, cmdiocb);
1224 lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1227 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1228 struct lpfc_hba *phba = vport->phba;
1230 struct lpfc_iocbq *elsiocb;
1231 struct lpfc_sli_ring *pring;
1232 struct lpfc_sli *psli;
1237 pring = &psli->ring[LPFC_ELS_RING];
1239 cmdsize = (2 * sizeof (uint32_t)) + sizeof (struct lpfc_name);
1240 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1241 ndlp->nlp_DID, ELS_CMD_LOGO);
1245 icmd = &elsiocb->iocb;
1246 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1247 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
1248 pcmd += sizeof (uint32_t);
1250 /* Fill in LOGO payload */
1251 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
1252 pcmd += sizeof (uint32_t);
1253 memcpy(pcmd, &vport->fc_portname, sizeof (struct lpfc_name));
1255 phba->fc_stat.elsXmitLOGO++;
1256 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
1257 spin_lock_irq(shost->host_lock);
1258 ndlp->nlp_flag |= NLP_LOGO_SND;
1259 spin_unlock_irq(shost->host_lock);
1260 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
1261 spin_lock_irq(shost->host_lock);
1262 ndlp->nlp_flag &= ~NLP_LOGO_SND;
1263 spin_unlock_irq(shost->host_lock);
1264 lpfc_els_free_iocb(phba, elsiocb);
1271 lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1272 struct lpfc_iocbq *rspiocb)
1274 struct lpfc_vport *vport = cmdiocb->vport;
1277 irsp = &rspiocb->iocb;
1279 /* ELS cmd tag <ulpIoTag> completes */
1280 lpfc_printf_log(phba,
1283 "%d:0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
1285 irsp->ulpIoTag, irsp->ulpStatus,
1286 irsp->un.ulpWord[4], irsp->ulpTimeout);
1288 /* Check to see if link went down during discovery */
1289 lpfc_els_chk_latt(vport);
1290 lpfc_els_free_iocb(phba, cmdiocb);
1295 lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
1297 struct lpfc_hba *phba = vport->phba;
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 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1313 lpfc_nlp_init(vport, ndlp, nportid);
1315 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1316 ndlp->nlp_DID, ELS_CMD_SCR);
1323 icmd = &elsiocb->iocb;
1324 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1326 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
1327 pcmd += sizeof (uint32_t);
1329 /* For SCR, remainder of payload is SCR parameter page */
1330 memset(pcmd, 0, sizeof (SCR));
1331 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
1333 phba->fc_stat.elsXmitSCR++;
1334 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
1335 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
1337 lpfc_els_free_iocb(phba, elsiocb);
1345 lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
1347 struct lpfc_hba *phba = vport->phba;
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 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1366 lpfc_nlp_init(vport, ndlp, nportid);
1368 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1369 ndlp->nlp_DID, ELS_CMD_RNID);
1375 icmd = &elsiocb->iocb;
1376 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1378 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
1379 pcmd += sizeof (uint32_t);
1381 /* Fill in FARPR payload */
1382 fp = (FARP *) (pcmd);
1383 memset(fp, 0, sizeof (FARP));
1384 lp = (uint32_t *) pcmd;
1385 *lp++ = be32_to_cpu(nportid);
1386 *lp++ = be32_to_cpu(vport->fc_myDID);
1388 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
1390 memcpy(&fp->RportName, &vport->fc_portname, sizeof (struct lpfc_name));
1391 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof (struct lpfc_name));
1392 ondlp = lpfc_findnode_did(vport, nportid);
1394 memcpy(&fp->OportName, &ondlp->nlp_portname,
1395 sizeof (struct lpfc_name));
1396 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
1397 sizeof (struct lpfc_name));
1400 phba->fc_stat.elsXmitFARPR++;
1401 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
1402 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
1404 lpfc_els_free_iocb(phba, elsiocb);
1412 lpfc_end_rscn(struct lpfc_vport *vport)
1414 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1416 if (vport->fc_flag & FC_RSCN_MODE) {
1418 * Check to see if more RSCNs came in while we were
1419 * processing this one.
1421 if (vport->fc_rscn_id_cnt ||
1422 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1423 lpfc_els_handle_rscn(vport);
1425 spin_lock_irq(shost->host_lock);
1426 vport->fc_flag &= ~FC_RSCN_MODE;
1427 spin_unlock_irq(shost->host_lock);
1433 lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
1435 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1437 spin_lock_irq(shost->host_lock);
1438 nlp->nlp_flag &= ~NLP_DELAY_TMO;
1439 spin_unlock_irq(shost->host_lock);
1440 del_timer_sync(&nlp->nlp_delayfunc);
1441 nlp->nlp_last_elscmd = 0;
1443 if (!list_empty(&nlp->els_retry_evt.evt_listp))
1444 list_del_init(&nlp->els_retry_evt.evt_listp);
1446 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
1447 spin_lock_irq(shost->host_lock);
1448 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1449 spin_unlock_irq(shost->host_lock);
1450 if (vport->num_disc_nodes) {
1451 /* Check to see if there are more
1454 lpfc_more_plogi(vport);
1456 if (vport->num_disc_nodes == 0) {
1457 spin_lock_irq(shost->host_lock);
1458 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1459 spin_unlock_irq(shost->host_lock);
1460 lpfc_can_disctmo(vport);
1461 lpfc_end_rscn(vport);
1469 lpfc_els_retry_delay(unsigned long ptr)
1471 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
1472 struct lpfc_vport *vport = ndlp->vport;
1473 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1474 struct lpfc_hba *phba = vport->phba;
1475 unsigned long iflag;
1476 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
1478 ndlp = (struct lpfc_nodelist *) ptr;
1479 phba = ndlp->vport->phba;
1480 evtp = &ndlp->els_retry_evt;
1482 spin_lock_irqsave(shost->host_lock, iflag);
1483 if (!list_empty(&evtp->evt_listp)) {
1484 spin_unlock_irqrestore(shost->host_lock, iflag);
1488 evtp->evt_arg1 = ndlp;
1489 evtp->evt = LPFC_EVT_ELS_RETRY;
1490 list_add_tail(&evtp->evt_listp, &phba->work_list);
1491 if (phba->work_wait)
1492 wake_up(phba->work_wait);
1494 spin_unlock_irqrestore(shost->host_lock, iflag);
1499 lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
1501 struct lpfc_vport *vport = ndlp->vport;
1502 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1503 uint32_t cmd, did, retry;
1505 spin_lock_irq(shost->host_lock);
1506 did = ndlp->nlp_DID;
1507 cmd = ndlp->nlp_last_elscmd;
1508 ndlp->nlp_last_elscmd = 0;
1510 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
1511 spin_unlock_irq(shost->host_lock);
1515 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
1516 spin_unlock_irq(shost->host_lock);
1518 * If a discovery event readded nlp_delayfunc after timer
1519 * firing and before processing the timer, cancel the
1522 del_timer_sync(&ndlp->nlp_delayfunc);
1523 retry = ndlp->nlp_retry;
1527 lpfc_issue_els_flogi(vport, ndlp, retry);
1530 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
1531 ndlp->nlp_prev_state = ndlp->nlp_state;
1532 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1536 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
1537 ndlp->nlp_prev_state = ndlp->nlp_state;
1538 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
1542 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
1543 ndlp->nlp_prev_state = ndlp->nlp_state;
1544 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
1548 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
1549 ndlp->nlp_prev_state = ndlp->nlp_state;
1550 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1558 lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1559 struct lpfc_iocbq *rspiocb)
1561 struct lpfc_vport *vport = cmdiocb->vport;
1562 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1563 IOCB_t *irsp = &rspiocb->iocb;
1564 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1565 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
1568 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
1573 /* Note: context2 may be 0 for internal driver abort
1574 * of delays ELS command.
1577 if (pcmd && pcmd->virt) {
1578 elscmd = (uint32_t *) (pcmd->virt);
1583 did = ndlp->nlp_DID;
1585 /* We should only hit this case for retrying PLOGI */
1586 did = irsp->un.elsreq64.remoteID;
1587 ndlp = lpfc_findnode_did(vport, did);
1588 if (!ndlp && (cmd != ELS_CMD_PLOGI))
1592 switch (irsp->ulpStatus) {
1593 case IOSTAT_FCP_RSP_ERROR:
1594 case IOSTAT_REMOTE_STOP:
1597 case IOSTAT_LOCAL_REJECT:
1598 switch ((irsp->un.ulpWord[4] & 0xff)) {
1599 case IOERR_LOOP_OPEN_FAILURE:
1600 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
1605 case IOERR_SEQUENCE_TIMEOUT:
1609 case IOERR_NO_RESOURCES:
1610 if (cmd == ELS_CMD_PLOGI)
1615 case IOERR_INVALID_RPI:
1621 case IOSTAT_NPORT_RJT:
1622 case IOSTAT_FABRIC_RJT:
1623 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
1629 case IOSTAT_NPORT_BSY:
1630 case IOSTAT_FABRIC_BSY:
1635 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
1636 /* Added for Vendor specifc support
1637 * Just keep retrying for these Rsn / Exp codes
1639 switch (stat.un.b.lsRjtRsnCode) {
1640 case LSRJT_UNABLE_TPC:
1641 if (stat.un.b.lsRjtRsnCodeExp ==
1642 LSEXP_CMD_IN_PROGRESS) {
1643 if (cmd == ELS_CMD_PLOGI) {
1650 if (cmd == ELS_CMD_PLOGI) {
1652 maxretry = lpfc_max_els_tries + 1;
1658 case LSRJT_LOGICAL_BSY:
1659 if (cmd == ELS_CMD_PLOGI) {
1668 case IOSTAT_INTERMED_RSP:
1676 if (did == FDMI_DID)
1679 if ((++cmdiocb->retry) >= maxretry) {
1680 phba->fc_stat.elsRetryExceeded++;
1684 if ((vport->load_flag & FC_UNLOADING) != 0)
1689 /* Retry ELS command <elsCmd> to remote NPORT <did> */
1690 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1691 "%d:0107 Retry ELS command x%x to remote "
1692 "NPORT x%x Data: x%x x%x\n",
1694 cmd, did, cmdiocb->retry, delay);
1696 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) {
1697 /* If discovery / RSCN timer is running, reset it */
1698 if (timer_pending(&vport->fc_disctmo) ||
1699 (vport->fc_flag & FC_RSCN_MODE))
1700 lpfc_set_disctmo(vport);
1703 phba->fc_stat.elsXmitRetry++;
1704 if (ndlp && delay) {
1705 phba->fc_stat.elsDelayRetry++;
1706 ndlp->nlp_retry = cmdiocb->retry;
1708 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
1709 spin_lock_irq(shost->host_lock);
1710 ndlp->nlp_flag |= NLP_DELAY_TMO;
1711 spin_unlock_irq(shost->host_lock);
1713 ndlp->nlp_prev_state = ndlp->nlp_state;
1714 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1715 ndlp->nlp_last_elscmd = cmd;
1721 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
1725 ndlp->nlp_prev_state = ndlp->nlp_state;
1726 lpfc_nlp_set_state(vport, ndlp,
1727 NLP_STE_PLOGI_ISSUE);
1729 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
1732 ndlp->nlp_prev_state = ndlp->nlp_state;
1733 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
1734 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
1737 ndlp->nlp_prev_state = ndlp->nlp_state;
1738 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
1739 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
1742 ndlp->nlp_prev_state = ndlp->nlp_state;
1743 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1744 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
1749 /* No retry ELS command <elsCmd> to remote NPORT <did> */
1750 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1751 "%d:0108 No retry ELS command x%x to remote NPORT x%x "
1754 cmd, did, cmdiocb->retry);
1760 lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
1762 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
1764 if (elsiocb->context1) {
1765 lpfc_nlp_put(elsiocb->context1);
1766 elsiocb->context1 = NULL;
1768 /* context2 = cmd, context2->next = rsp, context3 = bpl */
1769 if (elsiocb->context2) {
1770 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
1771 /* Free the response before processing the command. */
1772 if (!list_empty(&buf_ptr1->list)) {
1773 list_remove_head(&buf_ptr1->list, buf_ptr,
1776 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
1779 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
1783 if (elsiocb->context3) {
1784 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
1785 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
1788 lpfc_sli_release_iocbq(phba, elsiocb);
1793 lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1794 struct lpfc_iocbq *rspiocb)
1796 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1797 struct lpfc_vport *vport = cmdiocb->vport;
1799 /* ACC to LOGO completes to NPort <nlp_DID> */
1800 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1801 "%d:0109 ACC to LOGO completes to NPort x%x "
1802 "Data: x%x x%x x%x\n",
1803 phba->brd_no, ndlp->nlp_DID, ndlp->nlp_flag,
1804 ndlp->nlp_state, ndlp->nlp_rpi);
1806 switch (ndlp->nlp_state) {
1807 case NLP_STE_UNUSED_NODE: /* node is just allocated */
1808 lpfc_drop_node(vport, ndlp);
1810 case NLP_STE_NPR_NODE: /* NPort Recovery mode */
1811 lpfc_unreg_rpi(vport, ndlp);
1816 lpfc_els_free_iocb(phba, cmdiocb);
1821 lpfc_cmpl_els_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1822 struct lpfc_iocbq *rspiocb)
1824 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1825 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
1826 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
1828 LPFC_MBOXQ_t *mbox = NULL;
1829 struct lpfc_dmabuf *mp = NULL;
1831 irsp = &rspiocb->iocb;
1833 if (cmdiocb->context_un.mbox)
1834 mbox = cmdiocb->context_un.mbox;
1836 /* Check to see if link went down during discovery */
1837 if (!ndlp || lpfc_els_chk_latt(vport)) {
1839 mp = (struct lpfc_dmabuf *) mbox->context1;
1841 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1844 mempool_free(mbox, phba->mbox_mem_pool);
1849 /* ELS response tag <ulpIoTag> completes */
1850 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1851 "%d:0110 ELS response tag x%x completes "
1852 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
1854 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
1855 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
1856 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
1860 if ((rspiocb->iocb.ulpStatus == 0)
1861 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
1862 lpfc_unreg_rpi(vport, ndlp);
1863 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
1864 mbox->context2 = lpfc_nlp_get(ndlp);
1865 mbox->vport = vport;
1866 ndlp->nlp_prev_state = ndlp->nlp_state;
1867 lpfc_nlp_set_state(vport, ndlp,
1868 NLP_STE_REG_LOGIN_ISSUE);
1869 if (lpfc_sli_issue_mbox(phba, mbox,
1870 (MBX_NOWAIT | MBX_STOP_IOCB))
1871 != MBX_NOT_FINISHED) {
1875 /* NOTE: we should have messages for unsuccessful
1878 /* Do not call NO_LIST for lpfc_els_abort'ed ELS cmds */
1879 if (!((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
1880 ((irsp->un.ulpWord[4] == IOERR_SLI_ABORTED) ||
1881 (irsp->un.ulpWord[4] == IOERR_LINK_DOWN) ||
1882 (irsp->un.ulpWord[4] == IOERR_SLI_DOWN)))) {
1883 if (ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
1884 lpfc_drop_node(vport, ndlp);
1889 mp = (struct lpfc_dmabuf *) mbox->context1;
1891 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1894 mempool_free(mbox, phba->mbox_mem_pool);
1898 spin_lock_irq(shost->host_lock);
1899 ndlp->nlp_flag &= ~NLP_ACC_REGLOGIN;
1900 spin_unlock_irq(shost->host_lock);
1902 lpfc_els_free_iocb(phba, cmdiocb);
1907 lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
1908 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
1909 LPFC_MBOXQ_t *mbox, uint8_t newnode)
1911 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1912 struct lpfc_hba *phba = vport->phba;
1915 struct lpfc_iocbq *elsiocb;
1916 struct lpfc_sli_ring *pring;
1917 struct lpfc_sli *psli;
1921 ELS_PKT *els_pkt_ptr;
1924 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1925 oldcmd = &oldiocb->iocb;
1929 cmdsize = sizeof (uint32_t);
1930 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
1931 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
1933 spin_lock_irq(shost->host_lock);
1934 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
1935 spin_unlock_irq(shost->host_lock);
1939 icmd = &elsiocb->iocb;
1940 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
1941 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1942 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
1943 pcmd += sizeof (uint32_t);
1946 cmdsize = (sizeof (struct serv_parm) + sizeof (uint32_t));
1947 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
1948 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
1952 icmd = &elsiocb->iocb;
1953 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
1954 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1957 elsiocb->context_un.mbox = mbox;
1959 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
1960 pcmd += sizeof (uint32_t);
1961 memcpy(pcmd, &vport->fc_sparam, sizeof (struct serv_parm));
1964 cmdsize = sizeof (uint32_t) + sizeof (PRLO);
1965 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
1966 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
1970 icmd = &elsiocb->iocb;
1971 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
1972 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1974 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
1975 sizeof (uint32_t) + sizeof (PRLO));
1976 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
1977 els_pkt_ptr = (ELS_PKT *) pcmd;
1978 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
1986 elsiocb->context1 = NULL;
1989 /* Xmit ELS ACC response tag <ulpIoTag> */
1990 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1991 "%d:0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
1992 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n",
1993 phba->brd_no, elsiocb->iotag,
1994 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
1995 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
1997 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
1998 spin_lock_irq(shost->host_lock);
1999 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
2000 spin_unlock_irq(shost->host_lock);
2001 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
2003 elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
2006 phba->fc_stat.elsXmitACC++;
2007 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
2008 if (rc == IOCB_ERROR) {
2009 lpfc_els_free_iocb(phba, elsiocb);
2016 lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
2017 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
2019 struct lpfc_hba *phba = vport->phba;
2022 struct lpfc_iocbq *elsiocb;
2023 struct lpfc_sli_ring *pring;
2024 struct lpfc_sli *psli;
2030 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2032 cmdsize = 2 * sizeof (uint32_t);
2033 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
2034 ndlp->nlp_DID, ELS_CMD_LS_RJT);
2038 icmd = &elsiocb->iocb;
2039 oldcmd = &oldiocb->iocb;
2040 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2041 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2043 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
2044 pcmd += sizeof (uint32_t);
2045 *((uint32_t *) (pcmd)) = rejectError;
2047 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
2048 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
2049 "%d:0129 Xmit ELS RJT x%x response tag x%x xri x%x, "
2050 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
2051 phba->brd_no, rejectError, elsiocb->iotag,
2052 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
2053 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
2055 phba->fc_stat.elsXmitLSRJT++;
2056 elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
2057 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
2058 if (rc == IOCB_ERROR) {
2059 lpfc_els_free_iocb(phba, elsiocb);
2066 lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
2067 struct lpfc_nodelist *ndlp)
2069 struct lpfc_hba *phba = vport->phba;
2070 struct lpfc_sli *psli = &phba->sli;
2071 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
2073 IOCB_t *icmd, *oldcmd;
2074 struct lpfc_iocbq *elsiocb;
2079 cmdsize = sizeof (uint32_t) + sizeof (ADISC);
2080 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
2081 ndlp->nlp_DID, ELS_CMD_ACC);
2085 icmd = &elsiocb->iocb;
2086 oldcmd = &oldiocb->iocb;
2087 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2089 /* Xmit ADISC ACC response tag <ulpIoTag> */
2090 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
2091 "%d:0130 Xmit ADISC ACC response iotag x%x xri: "
2092 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
2093 phba->brd_no, elsiocb->iotag,
2094 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
2095 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
2097 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2099 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
2100 pcmd += sizeof (uint32_t);
2102 ap = (ADISC *) (pcmd);
2103 ap->hardAL_PA = phba->fc_pref_ALPA;
2104 memcpy(&ap->portName, &vport->fc_portname, sizeof (struct lpfc_name));
2105 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof (struct lpfc_name));
2106 ap->DID = be32_to_cpu(vport->fc_myDID);
2108 phba->fc_stat.elsXmitACC++;
2109 elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
2110 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
2111 if (rc == IOCB_ERROR) {
2112 lpfc_els_free_iocb(phba, elsiocb);
2119 lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
2120 struct lpfc_nodelist *ndlp)
2122 struct lpfc_hba *phba = vport->phba;
2127 struct lpfc_iocbq *elsiocb;
2128 struct lpfc_sli_ring *pring;
2129 struct lpfc_sli *psli;
2135 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2137 cmdsize = sizeof (uint32_t) + sizeof (PRLI);
2138 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
2139 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
2143 icmd = &elsiocb->iocb;
2144 oldcmd = &oldiocb->iocb;
2145 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2147 /* Xmit PRLI ACC response tag <ulpIoTag> */
2148 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
2149 "%d:0131 Xmit PRLI ACC response tag x%x xri x%x, "
2150 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
2151 phba->brd_no, elsiocb->iotag,
2152 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
2153 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
2155 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2157 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
2158 pcmd += sizeof (uint32_t);
2160 /* For PRLI, remainder of payload is PRLI parameter page */
2161 memset(pcmd, 0, sizeof (PRLI));
2163 npr = (PRLI *) pcmd;
2166 * If our firmware version is 3.20 or later,
2167 * set the following bits for FC-TAPE support.
2169 if (vpd->rev.feaLevelHigh >= 0x02) {
2170 npr->ConfmComplAllowed = 1;
2172 npr->TaskRetryIdReq = 1;
2175 npr->acceptRspCode = PRLI_REQ_EXECUTED;
2176 npr->estabImagePair = 1;
2177 npr->readXferRdyDis = 1;
2178 npr->ConfmComplAllowed = 1;
2180 npr->prliType = PRLI_FCP_TYPE;
2181 npr->initiatorFunc = 1;
2183 phba->fc_stat.elsXmitACC++;
2184 elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
2186 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
2187 if (rc == IOCB_ERROR) {
2188 lpfc_els_free_iocb(phba, elsiocb);
2195 lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
2196 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
2198 struct lpfc_hba *phba = vport->phba;
2200 IOCB_t *icmd, *oldcmd;
2201 struct lpfc_iocbq *elsiocb;
2202 struct lpfc_sli_ring *pring;
2203 struct lpfc_sli *psli;
2209 pring = &psli->ring[LPFC_ELS_RING];
2211 cmdsize = sizeof (uint32_t) + sizeof (uint32_t)
2212 + (2 * sizeof (struct lpfc_name));
2214 cmdsize += sizeof (RNID_TOP_DISC);
2216 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
2217 ndlp->nlp_DID, ELS_CMD_ACC);
2221 icmd = &elsiocb->iocb;
2222 oldcmd = &oldiocb->iocb;
2223 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2225 /* Xmit RNID ACC response tag <ulpIoTag> */
2226 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
2227 "%d:0132 Xmit RNID ACC response tag x%x "
2229 phba->brd_no, elsiocb->iotag,
2230 elsiocb->iocb.ulpContext);
2232 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2234 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
2235 pcmd += sizeof (uint32_t);
2237 memset(pcmd, 0, sizeof (RNID));
2238 rn = (RNID *) (pcmd);
2239 rn->Format = format;
2240 rn->CommonLen = (2 * sizeof (struct lpfc_name));
2241 memcpy(&rn->portName, &vport->fc_portname, sizeof (struct lpfc_name));
2242 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof (struct lpfc_name));
2245 rn->SpecificLen = 0;
2247 case RNID_TOPOLOGY_DISC:
2248 rn->SpecificLen = sizeof (RNID_TOP_DISC);
2249 memcpy(&rn->un.topologyDisc.portName,
2250 &vport->fc_portname, sizeof (struct lpfc_name));
2251 rn->un.topologyDisc.unitType = RNID_HBA;
2252 rn->un.topologyDisc.physPort = 0;
2253 rn->un.topologyDisc.attachedNodes = 0;
2257 rn->SpecificLen = 0;
2261 phba->fc_stat.elsXmitACC++;
2262 elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
2264 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
2265 * it could be freed */
2267 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
2268 if (rc == IOCB_ERROR) {
2269 lpfc_els_free_iocb(phba, elsiocb);
2276 lpfc_els_disc_adisc(struct lpfc_vport *vport)
2278 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2279 struct lpfc_nodelist *ndlp, *next_ndlp;
2282 /* go thru NPR nodes and issue any remaining ELS ADISCs */
2283 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
2284 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
2285 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
2286 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
2287 spin_lock_irq(shost->host_lock);
2288 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2289 spin_unlock_irq(shost->host_lock);
2290 ndlp->nlp_prev_state = ndlp->nlp_state;
2291 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2292 lpfc_issue_els_adisc(vport, ndlp, 0);
2294 vport->num_disc_nodes++;
2295 if (vport->num_disc_nodes >=
2296 vport->phba->cfg_discovery_threads) {
2297 spin_lock_irq(shost->host_lock);
2298 vport->fc_flag |= FC_NLP_MORE;
2299 spin_unlock_irq(shost->host_lock);
2304 if (sentadisc == 0) {
2305 spin_lock_irq(shost->host_lock);
2306 vport->fc_flag &= ~FC_NLP_MORE;
2307 spin_unlock_irq(shost->host_lock);
2313 lpfc_els_disc_plogi(struct lpfc_vport *vport)
2315 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2316 struct lpfc_nodelist *ndlp, *next_ndlp;
2319 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
2320 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
2321 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
2322 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
2323 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
2324 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
2325 ndlp->nlp_prev_state = ndlp->nlp_state;
2326 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2327 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
2329 vport->num_disc_nodes++;
2330 if (vport->num_disc_nodes >=
2331 vport->phba->cfg_discovery_threads) {
2332 spin_lock_irq(shost->host_lock);
2333 vport->fc_flag |= FC_NLP_MORE;
2334 spin_unlock_irq(shost->host_lock);
2339 if (sentplogi == 0) {
2340 spin_lock_irq(shost->host_lock);
2341 vport->fc_flag &= ~FC_NLP_MORE;
2342 spin_unlock_irq(shost->host_lock);
2348 lpfc_els_flush_rscn(struct lpfc_vport *vport)
2350 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2351 struct lpfc_hba *phba = vport->phba;
2352 struct lpfc_dmabuf *mp;
2355 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
2356 mp = vport->fc_rscn_id_list[i];
2357 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)
2358 lpfc_sli_hbqbuf_free(phba, mp->virt, mp->phys);
2360 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2363 vport->fc_rscn_id_list[i] = NULL;
2365 spin_lock_irq(shost->host_lock);
2366 vport->fc_rscn_id_cnt = 0;
2367 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
2368 spin_unlock_irq(shost->host_lock);
2369 lpfc_can_disctmo(vport);
2374 lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
2378 struct lpfc_dmabuf *mp;
2380 uint32_t payload_len, cmd, i, match;
2381 struct lpfc_hba *phba = vport->phba;
2383 ns_did.un.word = did;
2386 /* Never match fabric nodes for RSCNs */
2387 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
2390 /* If we are doing a FULL RSCN rediscovery, match everything */
2391 if (vport->fc_flag & FC_RSCN_DISCOVERY)
2394 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
2395 mp = vport->fc_rscn_id_list[i];
2396 lp = (uint32_t *) mp->virt;
2398 payload_len = be32_to_cpu(cmd) & 0xffff; /* payload length */
2399 payload_len -= sizeof (uint32_t); /* take off word 0 */
2400 while (payload_len) {
2401 rscn_did.un.word = *lp++;
2402 rscn_did.un.word = be32_to_cpu(rscn_did.un.word);
2403 payload_len -= sizeof (uint32_t);
2404 switch (rscn_did.un.b.resv) {
2405 case 0: /* Single N_Port ID effected */
2406 if (ns_did.un.word == rscn_did.un.word)
2409 case 1: /* Whole N_Port Area effected */
2410 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
2411 && (ns_did.un.b.area == rscn_did.un.b.area))
2414 case 2: /* Whole N_Port Domain effected */
2415 if (ns_did.un.b.domain == rscn_did.un.b.domain)
2418 case 3: /* Whole Fabric effected */
2422 /* Unknown Identifier in RSCN node */
2423 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2424 "%d:0217 Unknown Identifier in "
2425 "RSCN payload Data: x%x\n",
2426 phba->brd_no, rscn_did.un.word);
2437 lpfc_rscn_recovery_check(struct lpfc_vport *vport)
2439 struct lpfc_nodelist *ndlp = NULL;
2441 /* Look at all nodes effected by pending RSCNs and move
2442 * them to NPR state.
2445 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
2446 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE ||
2447 lpfc_rscn_payload_check(vport, ndlp->nlp_DID) == 0)
2450 lpfc_disc_state_machine(vport, ndlp, NULL,
2451 NLP_EVT_DEVICE_RECOVERY);
2454 * Make sure NLP_DELAY_TMO is NOT running after a device
2457 if (ndlp->nlp_flag & NLP_DELAY_TMO)
2458 lpfc_cancel_retry_delay_tmo(vport, ndlp);
2465 lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
2466 struct lpfc_nodelist *ndlp, uint8_t newnode)
2468 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2469 struct lpfc_hba *phba = vport->phba;
2470 struct lpfc_dmabuf *pcmd;
2473 uint32_t payload_len, cmd;
2476 icmd = &cmdiocb->iocb;
2477 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2478 lp = (uint32_t *) pcmd->virt;
2481 payload_len = be32_to_cpu(cmd) & 0xffff; /* payload length */
2482 payload_len -= sizeof (uint32_t); /* take off word 0 */
2483 cmd &= ELS_CMD_MASK;
2486 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
2487 "%d:0214 RSCN received Data: x%x x%x x%x x%x\n",
2488 phba->brd_no, vport->fc_flag, payload_len, *lp,
2489 vport->fc_rscn_id_cnt);
2491 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
2492 fc_host_post_event(shost, fc_get_event_number(),
2493 FCH_EVT_RSCN, lp[i]);
2495 /* If we are about to begin discovery, just ACC the RSCN.
2496 * Discovery processing will satisfy it.
2498 if (vport->port_state <= LPFC_NS_QRY) {
2499 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL,
2504 /* If we are already processing an RSCN, save the received
2505 * RSCN payload buffer, cmdiocb->context2 to process later.
2507 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
2508 if ((vport->fc_rscn_id_cnt < FC_MAX_HOLD_RSCN) &&
2509 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
2510 spin_lock_irq(shost->host_lock);
2511 vport->fc_flag |= FC_RSCN_MODE;
2512 spin_unlock_irq(shost->host_lock);
2513 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
2515 /* If we zero, cmdiocb->context2, the calling
2516 * routine will not try to free it.
2518 cmdiocb->context2 = NULL;
2521 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
2522 "%d:0235 Deferred RSCN "
2523 "Data: x%x x%x x%x\n",
2524 phba->brd_no, vport->fc_rscn_id_cnt,
2528 spin_lock_irq(shost->host_lock);
2529 vport->fc_flag |= FC_RSCN_DISCOVERY;
2530 spin_unlock_irq(shost->host_lock);
2531 /* ReDiscovery RSCN */
2532 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
2533 "%d:0234 ReDiscovery RSCN "
2534 "Data: x%x x%x x%x\n",
2535 phba->brd_no, vport->fc_rscn_id_cnt,
2540 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL,
2543 /* send RECOVERY event for ALL nodes that match RSCN payload */
2544 lpfc_rscn_recovery_check(vport);
2548 spin_lock_irq(shost->host_lock);
2549 vport->fc_flag |= FC_RSCN_MODE;
2550 spin_unlock_irq(shost->host_lock);
2551 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
2553 * If we zero, cmdiocb->context2, the calling routine will
2554 * not try to free it.
2556 cmdiocb->context2 = NULL;
2558 lpfc_set_disctmo(vport);
2561 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL, newnode);
2563 /* send RECOVERY event for ALL nodes that match RSCN payload */
2564 lpfc_rscn_recovery_check(vport);
2566 return lpfc_els_handle_rscn(vport);
2570 lpfc_els_handle_rscn(struct lpfc_vport *vport)
2572 struct lpfc_nodelist *ndlp;
2573 struct lpfc_hba *phba = vport->phba;
2575 /* Start timer for RSCN processing */
2576 lpfc_set_disctmo(vport);
2578 /* RSCN processed */
2579 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
2580 "%d:0215 RSCN processed Data: x%x x%x x%x x%x\n",
2582 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
2585 /* To process RSCN, first compare RSCN data with NameServer */
2586 vport->fc_ns_retry = 0;
2587 ndlp = lpfc_findnode_did(vport, NameServer_DID);
2588 if (ndlp && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
2589 /* Good ndlp, issue CT Request to NameServer */
2590 if (lpfc_ns_cmd(vport, ndlp, SLI_CTNS_GID_FT) == 0)
2591 /* Wait for NameServer query cmpl before we can
2595 /* If login to NameServer does not exist, issue one */
2596 /* Good status, issue PLOGI to NameServer */
2597 ndlp = lpfc_findnode_did(vport, NameServer_DID);
2599 /* Wait for NameServer login cmpl before we can
2603 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2605 lpfc_els_flush_rscn(vport);
2608 lpfc_nlp_init(vport, ndlp, NameServer_DID);
2609 ndlp->nlp_type |= NLP_FABRIC;
2610 ndlp->nlp_prev_state = ndlp->nlp_state;
2611 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2612 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
2613 /* Wait for NameServer login cmpl before we can
2619 lpfc_els_flush_rscn(vport);
2624 lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
2625 struct lpfc_nodelist *ndlp, uint8_t newnode)
2627 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2628 struct lpfc_hba *phba = vport->phba;
2629 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2630 uint32_t *lp = (uint32_t *) pcmd->virt;
2631 IOCB_t *icmd = &cmdiocb->iocb;
2632 struct serv_parm *sp;
2639 sp = (struct serv_parm *) lp;
2641 /* FLOGI received */
2643 lpfc_set_disctmo(vport);
2645 if (phba->fc_topology == TOPOLOGY_LOOP) {
2646 /* We should never receive a FLOGI in loop mode, ignore it */
2647 did = icmd->un.elsreq64.remoteID;
2649 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
2651 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
2652 "%d:0113 An FLOGI ELS command x%x was received "
2653 "from DID x%x in Loop Mode\n",
2654 phba->brd_no, cmd, did);
2660 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3))) {
2661 /* For a FLOGI we accept, then if our portname is greater
2662 * then the remote portname we initiate Nport login.
2665 rc = memcmp(&vport->fc_portname, &sp->portName,
2666 sizeof (struct lpfc_name));
2669 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2673 lpfc_linkdown(phba);
2674 lpfc_init_link(phba, mbox,
2676 phba->cfg_link_speed);
2677 mbox->mb.un.varInitLnk.lipsr_AL_PA = 0;
2678 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
2679 mbox->vport = vport;
2680 rc = lpfc_sli_issue_mbox
2681 (phba, mbox, (MBX_NOWAIT | MBX_STOP_IOCB));
2682 lpfc_set_loopback_flag(phba);
2683 if (rc == MBX_NOT_FINISHED) {
2684 mempool_free(mbox, phba->mbox_mem_pool);
2687 } else if (rc > 0) { /* greater than */
2688 spin_lock_irq(shost->host_lock);
2689 vport->fc_flag |= FC_PT2PT_PLOGI;
2690 spin_unlock_irq(shost->host_lock);
2692 spin_lock_irq(shost->host_lock);
2693 vport->fc_flag |= FC_PT2PT;
2694 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
2695 spin_unlock_irq(shost->host_lock);
2697 /* Reject this request because invalid parameters */
2698 stat.un.b.lsRjtRsvd0 = 0;
2699 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2700 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
2701 stat.un.b.vendorUnique = 0;
2702 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp);
2707 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL, newnode);
2713 lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
2714 struct lpfc_nodelist *ndlp)
2716 struct lpfc_dmabuf *pcmd;
2723 icmd = &cmdiocb->iocb;
2724 did = icmd->un.elsreq64.remoteID;
2725 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2726 lp = (uint32_t *) pcmd->virt;
2733 switch (rn->Format) {
2735 case RNID_TOPOLOGY_DISC:
2737 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
2740 /* Reject this request because format not supported */
2741 stat.un.b.lsRjtRsvd0 = 0;
2742 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2743 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
2744 stat.un.b.vendorUnique = 0;
2745 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp);
2751 lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
2752 struct lpfc_nodelist *ndlp)
2756 /* For now, unconditionally reject this command */
2757 stat.un.b.lsRjtRsvd0 = 0;
2758 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2759 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
2760 stat.un.b.vendorUnique = 0;
2761 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp);
2766 lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
2768 struct lpfc_sli *psli = &phba->sli;
2769 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
2774 struct lpfc_iocbq *elsiocb;
2775 struct lpfc_nodelist *ndlp;
2776 uint16_t xri, status;
2781 ndlp = (struct lpfc_nodelist *) pmb->context2;
2782 xri = (uint16_t) ((unsigned long)(pmb->context1));
2783 pmb->context1 = NULL;
2784 pmb->context2 = NULL;
2786 if (mb->mbxStatus) {
2787 mempool_free(pmb, phba->mbox_mem_pool);
2791 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
2792 mempool_free(pmb, phba->mbox_mem_pool);
2793 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
2794 lpfc_max_els_tries, ndlp,
2795 ndlp->nlp_DID, ELS_CMD_ACC);
2800 icmd = &elsiocb->iocb;
2801 icmd->ulpContext = xri;
2803 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2804 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
2805 pcmd += sizeof (uint32_t); /* Skip past command */
2806 rps_rsp = (RPS_RSP *)pcmd;
2808 if (phba->fc_topology != TOPOLOGY_LOOP)
2812 if (phba->pport->fc_flag & FC_FABRIC)
2816 rps_rsp->portStatus = be16_to_cpu(status);
2817 rps_rsp->linkFailureCnt = be32_to_cpu(mb->un.varRdLnk.linkFailureCnt);
2818 rps_rsp->lossSyncCnt = be32_to_cpu(mb->un.varRdLnk.lossSyncCnt);
2819 rps_rsp->lossSignalCnt = be32_to_cpu(mb->un.varRdLnk.lossSignalCnt);
2820 rps_rsp->primSeqErrCnt = be32_to_cpu(mb->un.varRdLnk.primSeqErrCnt);
2821 rps_rsp->invalidXmitWord = be32_to_cpu(mb->un.varRdLnk.invalidXmitWord);
2822 rps_rsp->crcCnt = be32_to_cpu(mb->un.varRdLnk.crcCnt);
2824 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
2825 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
2826 "%d:0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
2827 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
2828 phba->brd_no, elsiocb->iotag,
2829 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
2830 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
2832 elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
2833 phba->fc_stat.elsXmitACC++;
2834 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR)
2835 lpfc_els_free_iocb(phba, elsiocb);
2840 lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
2841 struct lpfc_nodelist *ndlp)
2843 struct lpfc_hba *phba = vport->phba;
2847 struct lpfc_dmabuf *pcmd;
2851 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
2852 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
2853 stat.un.b.lsRjtRsvd0 = 0;
2854 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2855 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
2856 stat.un.b.vendorUnique = 0;
2857 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp);
2860 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2861 lp = (uint32_t *) pcmd->virt;
2862 flag = (be32_to_cpu(*lp++) & 0xf);
2866 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
2867 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
2868 sizeof (struct lpfc_name)) == 0))) {
2870 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
2872 lpfc_read_lnk_stat(phba, mbox);
2874 (void *)((unsigned long)cmdiocb->iocb.ulpContext);
2875 mbox->context2 = lpfc_nlp_get(ndlp);
2876 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
2877 if (lpfc_sli_issue_mbox (phba, mbox,
2878 (MBX_NOWAIT | MBX_STOP_IOCB)) != MBX_NOT_FINISHED)
2879 /* Mbox completion will send ELS Response */
2883 mempool_free(mbox, phba->mbox_mem_pool);
2886 stat.un.b.lsRjtRsvd0 = 0;
2887 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2888 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
2889 stat.un.b.vendorUnique = 0;
2890 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp);
2895 lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
2896 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
2898 struct lpfc_hba *phba = vport->phba;
2899 IOCB_t *icmd, *oldcmd;
2901 struct lpfc_iocbq *elsiocb;
2902 struct lpfc_sli *psli = &phba->sli;
2903 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
2906 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
2907 ndlp->nlp_DID, ELS_CMD_ACC);
2912 icmd = &elsiocb->iocb;
2913 oldcmd = &oldiocb->iocb;
2914 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2916 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2917 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
2918 pcmd += sizeof (uint16_t);
2919 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
2920 pcmd += sizeof(uint16_t);
2922 /* Setup the RPL ACC payload */
2923 rpl_rsp.listLen = be32_to_cpu(1);
2925 rpl_rsp.port_num_blk.portNum = 0;
2926 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
2927 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
2928 sizeof(struct lpfc_name));
2930 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
2933 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
2934 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
2935 "%d:0120 Xmit ELS RPL ACC response tag x%x xri x%x, "
2936 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
2937 phba->brd_no, elsiocb->iotag,
2938 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
2939 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
2941 elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
2943 phba->fc_stat.elsXmitACC++;
2944 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
2945 lpfc_els_free_iocb(phba, elsiocb);
2952 lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
2953 struct lpfc_nodelist *ndlp)
2955 struct lpfc_dmabuf *pcmd;
2962 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
2963 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
2964 stat.un.b.lsRjtRsvd0 = 0;
2965 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2966 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
2967 stat.un.b.vendorUnique = 0;
2968 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp);
2971 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2972 lp = (uint32_t *) pcmd->virt;
2973 rpl = (RPL *) (lp + 1);
2975 maxsize = be32_to_cpu(rpl->maxsize);
2977 /* We support only one port */
2978 if ((rpl->index == 0) &&
2980 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
2981 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
2983 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
2985 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
2991 lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
2992 struct lpfc_nodelist *ndlp)
2994 struct lpfc_hba *phba = vport->phba;
2995 struct lpfc_dmabuf *pcmd;
2999 uint32_t cmd, cnt, did;
3001 icmd = &cmdiocb->iocb;
3002 did = icmd->un.elsreq64.remoteID;
3003 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3004 lp = (uint32_t *) pcmd->virt;
3009 /* FARP-REQ received from DID <did> */
3010 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
3011 "%d:0601 FARP-REQ received from DID x%x\n",
3014 /* We will only support match on WWPN or WWNN */
3015 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
3020 /* If this FARP command is searching for my portname */
3021 if (fp->Mflags & FARP_MATCH_PORT) {
3022 if (memcmp(&fp->RportName, &vport->fc_portname,
3023 sizeof (struct lpfc_name)) == 0)
3027 /* If this FARP command is searching for my nodename */
3028 if (fp->Mflags & FARP_MATCH_NODE) {
3029 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
3030 sizeof (struct lpfc_name)) == 0)
3035 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
3036 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
3037 /* Log back into the node before sending the FARP. */
3038 if (fp->Rflags & FARP_REQUEST_PLOGI) {
3039 ndlp->nlp_prev_state = ndlp->nlp_state;
3040 lpfc_nlp_set_state(vport, ndlp,
3041 NLP_STE_PLOGI_ISSUE);
3042 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
3045 /* Send a FARP response to that node */
3046 if (fp->Rflags & FARP_REQUEST_FARPR)
3047 lpfc_issue_els_farpr(vport, did, 0);
3054 lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3055 struct lpfc_nodelist *ndlp)
3057 struct lpfc_dmabuf *pcmd;
3061 struct lpfc_hba *phba = vport->phba;
3063 icmd = &cmdiocb->iocb;
3064 did = icmd->un.elsreq64.remoteID;
3065 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3066 lp = (uint32_t *) pcmd->virt;
3069 /* FARP-RSP received from DID <did> */
3070 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
3071 "%d:0600 FARP-RSP received from DID x%x\n",
3073 /* ACCEPT the Farp resp request */
3074 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
3080 lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3081 struct lpfc_nodelist *fan_ndlp)
3083 struct lpfc_dmabuf *pcmd;
3088 struct lpfc_nodelist *ndlp, *next_ndlp;
3089 struct lpfc_hba *phba = vport->phba;
3092 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
3093 "%d:0265 FAN received\n",
3096 icmd = &cmdiocb->iocb;
3097 did = icmd->un.elsreq64.remoteID;
3098 pcmd = (struct lpfc_dmabuf *)cmdiocb->context2;
3099 lp = (uint32_t *)pcmd->virt;
3104 /* FAN received; Fan does not have a reply sequence */
3106 if (phba->pport->port_state == LPFC_LOCAL_CFG_LINK) {
3107 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
3108 sizeof(struct lpfc_name)) != 0) ||
3109 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
3110 sizeof(struct lpfc_name)) != 0)) {
3112 * This node has switched fabrics. FLOGI is required
3113 * Clean up the old rpi's
3116 list_for_each_entry_safe(ndlp, next_ndlp,
3117 &vport->fc_nodes, nlp_listp) {
3118 if (ndlp->nlp_state != NLP_STE_NPR_NODE)
3120 if (ndlp->nlp_type & NLP_FABRIC) {
3122 * Clean up old Fabric, Nameserver and
3123 * other NLP_FABRIC logins
3125 lpfc_drop_node(vport, ndlp);
3126 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
3127 /* Fail outstanding I/O now since this
3128 * device is marked for PLOGI
3130 lpfc_unreg_rpi(vport, ndlp);
3134 vport->port_state = LPFC_FLOGI;
3135 lpfc_set_disctmo(vport);
3136 lpfc_initial_flogi(vport);
3139 /* Discovery not needed,
3140 * move the nodes to their original state.
3142 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
3144 if (ndlp->nlp_state != NLP_STE_NPR_NODE)
3147 switch (ndlp->nlp_prev_state) {
3148 case NLP_STE_UNMAPPED_NODE:
3149 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
3150 lpfc_nlp_set_state(vport, ndlp,
3151 NLP_STE_UNMAPPED_NODE);
3154 case NLP_STE_MAPPED_NODE:
3155 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
3156 lpfc_nlp_set_state(vport, ndlp,
3157 NLP_STE_MAPPED_NODE);
3165 /* Start discovery - this should just do CLEAR_LA */
3166 lpfc_disc_start(vport);
3172 lpfc_els_timeout(unsigned long ptr)
3174 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
3175 struct lpfc_hba *phba = vport->phba;
3176 unsigned long iflag;
3178 spin_lock_irqsave(&vport->work_port_lock, iflag);
3179 if ((vport->work_port_events & WORKER_ELS_TMO) == 0) {
3180 vport->work_port_events |= WORKER_ELS_TMO;
3181 if (phba->work_wait)
3182 wake_up(phba->work_wait);
3184 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
3189 lpfc_els_timeout_handler(struct lpfc_vport *vport)
3191 struct lpfc_hba *phba = vport->phba;
3192 struct lpfc_sli_ring *pring;
3193 struct lpfc_iocbq *tmp_iocb, *piocb;
3195 struct lpfc_dmabuf *pcmd;
3196 uint32_t els_command = 0;
3198 uint32_t remote_ID = 0xffffffff;
3200 /* If the timer is already canceled do nothing */
3201 if ((vport->work_port_events & WORKER_ELS_TMO) == 0) {
3204 spin_lock_irq(&phba->hbalock);
3205 timeout = (uint32_t)(phba->fc_ratov << 1);
3207 pring = &phba->sli.ring[LPFC_ELS_RING];
3209 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
3212 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
3213 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
3214 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
3217 if (piocb->vport != vport)
3220 pcmd = (struct lpfc_dmabuf *) piocb->context2;
3222 els_command = *(uint32_t *) (pcmd->virt);
3224 if ((els_command == ELS_CMD_FARP)
3225 || (els_command == ELS_CMD_FARPR)) {
3229 if (piocb->drvrTimeout > 0) {
3230 if (piocb->drvrTimeout >= timeout) {
3231 piocb->drvrTimeout -= timeout;
3233 piocb->drvrTimeout = 0;
3238 remote_ID = 0xffffffff;
3239 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
3240 remote_ID = cmd->un.elsreq64.remoteID;
3242 struct lpfc_nodelist *ndlp;
3243 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
3245 remote_ID = ndlp->nlp_DID;
3248 lpfc_printf_log(phba,
3251 "%d:0127 ELS timeout Data: x%x x%x x%x x%x\n",
3252 phba->brd_no, els_command,
3253 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
3255 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
3257 spin_unlock_irq(&phba->hbalock);
3259 if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt)
3260 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
3264 lpfc_els_flush_cmd(struct lpfc_vport *vport)
3266 LIST_HEAD(completions);
3267 struct lpfc_hba *phba = vport->phba;
3268 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
3269 struct lpfc_iocbq *tmp_iocb, *piocb;
3272 spin_lock_irq(&phba->hbalock);
3273 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
3276 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
3280 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
3281 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
3282 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
3283 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
3284 cmd->ulpCommand == CMD_ABORT_XRI_CN)
3287 if (piocb->vport != vport)
3290 list_move_tail(&piocb->list, &completions);
3294 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
3295 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
3299 if (piocb->vport != vport)
3302 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
3304 spin_unlock_irq(&phba->hbalock);
3306 while (!list_empty(&completions)) {
3307 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
3309 list_del(&piocb->list);
3311 if (!piocb->iocb_cmpl)
3312 lpfc_sli_release_iocbq(phba, piocb);
3314 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
3315 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
3316 (piocb->iocb_cmpl) (phba, piocb, piocb);
3324 lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3325 struct lpfc_vport *vport, struct lpfc_dmabuf *mp,
3326 struct lpfc_iocbq *elsiocb)
3328 struct lpfc_nodelist *ndlp;
3331 uint32_t cmd, did, newnode, rjt_err = 0;
3332 IOCB_t *icmd = &elsiocb->iocb;
3338 lp = (uint32_t *) mp->virt;
3340 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
3341 lpfc_post_buffer(phba, pring, 1, 1);
3343 if (icmd->ulpStatus)
3346 /* Check to see if link went down during discovery */
3347 if (lpfc_els_chk_latt(vport))
3350 did = icmd->un.rcvels.remoteID;
3351 ndlp = lpfc_findnode_did(vport, did);
3353 /* Cannot find existing Fabric ndlp, so allocate a new one */
3354 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
3358 lpfc_nlp_init(vport, ndlp, did);
3360 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) {
3361 ndlp->nlp_type |= NLP_FABRIC;
3363 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE);
3366 phba->fc_stat.elsRcvFrame++;
3367 if (elsiocb->context1)
3368 lpfc_nlp_put(elsiocb->context1);
3369 elsiocb->context1 = lpfc_nlp_get(ndlp);
3370 elsiocb->context2 = mp;
3371 elsiocb->vport = vport;
3373 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
3374 cmd &= ELS_CMD_MASK;
3376 /* ELS command <elsCmd> received from NPORT <did> */
3377 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
3378 "%d:0112 ELS command x%x received from NPORT x%x "
3379 "Data: x%x\n", phba->brd_no, cmd, did,
3384 phba->fc_stat.elsRcvPLOGI++;
3385 if (vport->port_state < LPFC_DISC_AUTH) {
3389 ndlp = lpfc_plogi_confirm_nport(phba, mp, ndlp);
3390 lpfc_disc_state_machine(vport, ndlp, elsiocb,
3394 phba->fc_stat.elsRcvFLOGI++;
3395 lpfc_els_rcv_flogi(vport, elsiocb, ndlp, newnode);
3397 lpfc_drop_node(vport, ndlp);
3400 phba->fc_stat.elsRcvLOGO++;
3401 if (vport->port_state < LPFC_DISC_AUTH) {
3405 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
3408 phba->fc_stat.elsRcvPRLO++;
3409 if (vport->port_state < LPFC_DISC_AUTH) {
3413 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
3416 phba->fc_stat.elsRcvRSCN++;
3417 lpfc_els_rcv_rscn(vport, elsiocb, ndlp, newnode);
3419 lpfc_drop_node(vport, ndlp);
3422 phba->fc_stat.elsRcvADISC++;
3423 if (vport->port_state < LPFC_DISC_AUTH) {
3427 lpfc_disc_state_machine(vport, ndlp, elsiocb,
3431 phba->fc_stat.elsRcvPDISC++;
3432 if (vport->port_state < LPFC_DISC_AUTH) {
3436 lpfc_disc_state_machine(vport, ndlp, elsiocb,
3440 phba->fc_stat.elsRcvFARPR++;
3441 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
3444 phba->fc_stat.elsRcvFARP++;
3445 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
3448 phba->fc_stat.elsRcvFAN++;
3449 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
3452 phba->fc_stat.elsRcvPRLI++;
3453 if (vport->port_state < LPFC_DISC_AUTH) {
3457 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
3460 phba->fc_stat.elsRcvLIRR++;
3461 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
3463 lpfc_drop_node(vport, ndlp);
3466 phba->fc_stat.elsRcvRPS++;
3467 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
3469 lpfc_drop_node(vport, ndlp);
3472 phba->fc_stat.elsRcvRPL++;
3473 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
3475 lpfc_drop_node(vport, ndlp);
3478 phba->fc_stat.elsRcvRNID++;
3479 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
3481 lpfc_drop_node(vport, ndlp);
3484 /* Unsupported ELS command, reject */
3487 /* Unknown ELS command <elsCmd> received from NPORT <did> */
3488 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
3489 "%d:0115 Unknown ELS command x%x "
3490 "received from NPORT x%x\n",
3491 phba->brd_no, cmd, did);
3493 lpfc_drop_node(vport, ndlp);
3497 /* check if need to LS_RJT received ELS cmd */
3499 stat.un.b.lsRjtRsvd0 = 0;
3500 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3501 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
3502 stat.un.b.vendorUnique = 0;
3503 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp);
3509 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
3510 "%d:0111 Dropping received ELS cmd "
3511 "Data: x%x x%x x%x\n",
3513 icmd->ulpStatus, icmd->un.ulpWord[4],
3515 phba->fc_stat.elsRcvDrop++;
3520 lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3521 struct lpfc_iocbq *elsiocb)
3523 struct lpfc_vport *vport = phba->pport;
3524 struct lpfc_dmabuf *mp = NULL;
3525 IOCB_t *icmd = &elsiocb->iocb;
3526 struct hbq_dmabuf *sp = NULL;
3529 if ((icmd->ulpStatus == IOSTAT_LOCAL_REJECT) &&
3530 ((icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING)) {
3531 phba->fc_stat.NoRcvBuf++;
3532 /* Not enough posted buffers; Try posting more buffers */
3533 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)
3534 lpfc_sli_hbqbuf_fill_hbq(phba);
3536 lpfc_post_buffer(phba, pring, 0, 1);
3540 /* If there are no BDEs associated with this IOCB,
3541 * there is nothing to do.
3543 if (icmd->ulpBdeCount == 0)
3546 /* type of ELS cmd is first 32bit word in packet */
3547 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
3548 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
3549 icmd->un.cont64[0].addrLow);
3550 sp = lpfc_sli_hbqbuf_find(phba, icmd->un.ulpWord[3]);
3552 phba->hbq_buff_count--;
3553 mp = sp ? &sp->dbuf : NULL;
3555 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
3556 icmd->un.cont64[0].addrLow);
3557 mp = lpfc_sli_ringpostbuf_get(phba, pring, paddr);
3560 lpfc_els_unsol_buffer(phba, pring, vport, mp, elsiocb);
3562 lpfc_nlp_put(elsiocb->context1);
3563 elsiocb->context1 = NULL;
3564 if (elsiocb->context2) {
3565 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)
3566 lpfc_sli_free_hbq(phba, sp);
3568 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3573 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
3574 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) != 0 &&
3575 icmd->ulpBdeCount == 2) {
3576 sp = lpfc_sli_hbqbuf_find(phba, icmd->un.ulpWord[15]);
3578 phba->hbq_buff_count--;
3579 mp = sp ? &sp->dbuf : NULL;
3580 lpfc_els_unsol_buffer(phba, pring, vport, mp, elsiocb);
3581 /* free mp if we are done with it */
3582 if (elsiocb->context2) {
3583 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED)
3584 lpfc_sli_free_hbq(phba, sp);
3586 lpfc_mbuf_free(phba, mp->virt, mp->phys);