[SCSI] lpfc 8.3.19: Added support for ELS RRQ command
[linux-2.6/linux-mips.git] / drivers / scsi / lpfc / lpfc_els.c
blob0705ad86538f785a55fe87d7c89c5e6d7543a817
1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2009 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. *
6 * www.emulex.com *
7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
8 * *
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 *******************************************************************/
21 /* See Fibre Channel protocol T11 FC-LS for details */
22 #include <linux/blkdev.h>
23 #include <linux/pci.h>
24 #include <linux/slab.h>
25 #include <linux/interrupt.h>
27 #include <scsi/scsi.h>
28 #include <scsi/scsi_device.h>
29 #include <scsi/scsi_host.h>
30 #include <scsi/scsi_transport_fc.h>
32 #include "lpfc_hw4.h"
33 #include "lpfc_hw.h"
34 #include "lpfc_sli.h"
35 #include "lpfc_sli4.h"
36 #include "lpfc_nl.h"
37 #include "lpfc_disc.h"
38 #include "lpfc_scsi.h"
39 #include "lpfc.h"
40 #include "lpfc_logmsg.h"
41 #include "lpfc_crtn.h"
42 #include "lpfc_vport.h"
43 #include "lpfc_debugfs.h"
45 static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *,
46 struct lpfc_iocbq *);
47 static void lpfc_cmpl_fabric_iocb(struct lpfc_hba *, struct lpfc_iocbq *,
48 struct lpfc_iocbq *);
49 static void lpfc_fabric_abort_vport(struct lpfc_vport *vport);
50 static int lpfc_issue_els_fdisc(struct lpfc_vport *vport,
51 struct lpfc_nodelist *ndlp, uint8_t retry);
52 static int lpfc_issue_fabric_iocb(struct lpfc_hba *phba,
53 struct lpfc_iocbq *iocb);
55 static int lpfc_max_els_tries = 3;
57 /**
58 * lpfc_els_chk_latt - Check host link attention event for a vport
59 * @vport: pointer to a host virtual N_Port data structure.
61 * This routine checks whether there is an outstanding host link
62 * attention event during the discovery process with the @vport. It is done
63 * by reading the HBA's Host Attention (HA) register. If there is any host
64 * link attention events during this @vport's discovery process, the @vport
65 * shall be marked as FC_ABORT_DISCOVERY, a host link attention clear shall
66 * be issued if the link state is not already in host link cleared state,
67 * and a return code shall indicate whether the host link attention event
68 * had happened.
70 * Note that, if either the host link is in state LPFC_LINK_DOWN or @vport
71 * state in LPFC_VPORT_READY, the request for checking host link attention
72 * event will be ignored and a return code shall indicate no host link
73 * attention event had happened.
75 * Return codes
76 * 0 - no host link attention event happened
77 * 1 - host link attention event happened
78 **/
79 int
80 lpfc_els_chk_latt(struct lpfc_vport *vport)
82 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
83 struct lpfc_hba *phba = vport->phba;
84 uint32_t ha_copy;
86 if (vport->port_state >= LPFC_VPORT_READY ||
87 phba->link_state == LPFC_LINK_DOWN ||
88 phba->sli_rev > LPFC_SLI_REV3)
89 return 0;
91 /* Read the HBA Host Attention Register */
92 ha_copy = readl(phba->HAregaddr);
94 if (!(ha_copy & HA_LATT))
95 return 0;
97 /* Pending Link Event during Discovery */
98 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
99 "0237 Pending Link Event during "
100 "Discovery: State x%x\n",
101 phba->pport->port_state);
103 /* CLEAR_LA should re-enable link attention events and
104 * we should then imediately take a LATT event. The
105 * LATT processing should call lpfc_linkdown() which
106 * will cleanup any left over in-progress discovery
107 * events.
109 spin_lock_irq(shost->host_lock);
110 vport->fc_flag |= FC_ABORT_DISCOVERY;
111 spin_unlock_irq(shost->host_lock);
113 if (phba->link_state != LPFC_CLEAR_LA)
114 lpfc_issue_clear_la(phba, vport);
116 return 1;
120 * lpfc_prep_els_iocb - Allocate and prepare a lpfc iocb data structure
121 * @vport: pointer to a host virtual N_Port data structure.
122 * @expectRsp: flag indicating whether response is expected.
123 * @cmdSize: size of the ELS command.
124 * @retry: number of retries to the command IOCB when it fails.
125 * @ndlp: pointer to a node-list data structure.
126 * @did: destination identifier.
127 * @elscmd: the ELS command code.
129 * This routine is used for allocating a lpfc-IOCB data structure from
130 * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters
131 * passed into the routine for discovery state machine to issue an Extended
132 * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation
133 * and preparation routine that is used by all the discovery state machine
134 * routines and the ELS command-specific fields will be later set up by
135 * the individual discovery machine routines after calling this routine
136 * allocating and preparing a generic IOCB data structure. It fills in the
137 * Buffer Descriptor Entries (BDEs), allocates buffers for both command
138 * payload and response payload (if expected). The reference count on the
139 * ndlp is incremented by 1 and the reference to the ndlp is put into
140 * context1 of the IOCB data structure for this IOCB to hold the ndlp
141 * reference for the command's callback function to access later.
143 * Return code
144 * Pointer to the newly allocated/prepared els iocb data structure
145 * NULL - when els iocb data structure allocation/preparation failed
147 struct lpfc_iocbq *
148 lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp,
149 uint16_t cmdSize, uint8_t retry,
150 struct lpfc_nodelist *ndlp, uint32_t did,
151 uint32_t elscmd)
153 struct lpfc_hba *phba = vport->phba;
154 struct lpfc_iocbq *elsiocb;
155 struct lpfc_dmabuf *pcmd, *prsp, *pbuflist;
156 struct ulp_bde64 *bpl;
157 IOCB_t *icmd;
160 if (!lpfc_is_link_up(phba))
161 return NULL;
163 /* Allocate buffer for command iocb */
164 elsiocb = lpfc_sli_get_iocbq(phba);
166 if (elsiocb == NULL)
167 return NULL;
170 * If this command is for fabric controller and HBA running
171 * in FIP mode send FLOGI, FDISC and LOGO as FIP frames.
173 if ((did == Fabric_DID) &&
174 (phba->hba_flag & HBA_FIP_SUPPORT) &&
175 ((elscmd == ELS_CMD_FLOGI) ||
176 (elscmd == ELS_CMD_FDISC) ||
177 (elscmd == ELS_CMD_LOGO)))
178 switch (elscmd) {
179 case ELS_CMD_FLOGI:
180 elsiocb->iocb_flag |=
181 ((LPFC_ELS_ID_FLOGI << LPFC_FIP_ELS_ID_SHIFT)
182 & LPFC_FIP_ELS_ID_MASK);
183 break;
184 case ELS_CMD_FDISC:
185 elsiocb->iocb_flag |=
186 ((LPFC_ELS_ID_FDISC << LPFC_FIP_ELS_ID_SHIFT)
187 & LPFC_FIP_ELS_ID_MASK);
188 break;
189 case ELS_CMD_LOGO:
190 elsiocb->iocb_flag |=
191 ((LPFC_ELS_ID_LOGO << LPFC_FIP_ELS_ID_SHIFT)
192 & LPFC_FIP_ELS_ID_MASK);
193 break;
195 else
196 elsiocb->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK;
198 icmd = &elsiocb->iocb;
200 /* fill in BDEs for command */
201 /* Allocate buffer for command payload */
202 pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
203 if (pcmd)
204 pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys);
205 if (!pcmd || !pcmd->virt)
206 goto els_iocb_free_pcmb_exit;
208 INIT_LIST_HEAD(&pcmd->list);
210 /* Allocate buffer for response payload */
211 if (expectRsp) {
212 prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
213 if (prsp)
214 prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
215 &prsp->phys);
216 if (!prsp || !prsp->virt)
217 goto els_iocb_free_prsp_exit;
218 INIT_LIST_HEAD(&prsp->list);
219 } else
220 prsp = NULL;
222 /* Allocate buffer for Buffer ptr list */
223 pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
224 if (pbuflist)
225 pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
226 &pbuflist->phys);
227 if (!pbuflist || !pbuflist->virt)
228 goto els_iocb_free_pbuf_exit;
230 INIT_LIST_HEAD(&pbuflist->list);
232 icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
233 icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
234 icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
235 icmd->un.elsreq64.remoteID = did; /* DID */
236 if (expectRsp) {
237 icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
238 icmd->ulpCommand = CMD_ELS_REQUEST64_CR;
239 icmd->ulpTimeout = phba->fc_ratov * 2;
240 } else {
241 icmd->un.elsreq64.bdl.bdeSize = sizeof(struct ulp_bde64);
242 icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
244 icmd->ulpBdeCount = 1;
245 icmd->ulpLe = 1;
246 icmd->ulpClass = CLASS3;
248 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
249 icmd->un.elsreq64.myID = vport->fc_myDID;
251 /* For ELS_REQUEST64_CR, use the VPI by default */
252 icmd->ulpContext = vport->vpi + phba->vpi_base;
253 icmd->ulpCt_h = 0;
254 /* The CT field must be 0=INVALID_RPI for the ECHO cmd */
255 if (elscmd == ELS_CMD_ECHO)
256 icmd->ulpCt_l = 0; /* context = invalid RPI */
257 else
258 icmd->ulpCt_l = 1; /* context = VPI */
261 bpl = (struct ulp_bde64 *) pbuflist->virt;
262 bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys));
263 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys));
264 bpl->tus.f.bdeSize = cmdSize;
265 bpl->tus.f.bdeFlags = 0;
266 bpl->tus.w = le32_to_cpu(bpl->tus.w);
268 if (expectRsp) {
269 bpl++;
270 bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys));
271 bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys));
272 bpl->tus.f.bdeSize = FCELSSIZE;
273 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
274 bpl->tus.w = le32_to_cpu(bpl->tus.w);
277 /* prevent preparing iocb with NULL ndlp reference */
278 elsiocb->context1 = lpfc_nlp_get(ndlp);
279 if (!elsiocb->context1)
280 goto els_iocb_free_pbuf_exit;
281 elsiocb->context2 = pcmd;
282 elsiocb->context3 = pbuflist;
283 elsiocb->retry = retry;
284 elsiocb->vport = vport;
285 elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
287 if (prsp) {
288 list_add(&prsp->list, &pcmd->list);
290 if (expectRsp) {
291 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
292 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
293 "0116 Xmit ELS command x%x to remote "
294 "NPORT x%x I/O tag: x%x, port state: x%x\n",
295 elscmd, did, elsiocb->iotag,
296 vport->port_state);
297 } else {
298 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
299 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
300 "0117 Xmit ELS response x%x to remote "
301 "NPORT x%x I/O tag: x%x, size: x%x\n",
302 elscmd, ndlp->nlp_DID, elsiocb->iotag,
303 cmdSize);
305 return elsiocb;
307 els_iocb_free_pbuf_exit:
308 if (expectRsp)
309 lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
310 kfree(pbuflist);
312 els_iocb_free_prsp_exit:
313 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
314 kfree(prsp);
316 els_iocb_free_pcmb_exit:
317 kfree(pcmd);
318 lpfc_sli_release_iocbq(phba, elsiocb);
319 return NULL;
323 * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport
324 * @vport: pointer to a host virtual N_Port data structure.
326 * This routine issues a fabric registration login for a @vport. An
327 * active ndlp node with Fabric_DID must already exist for this @vport.
328 * The routine invokes two mailbox commands to carry out fabric registration
329 * login through the HBA firmware: the first mailbox command requests the
330 * HBA to perform link configuration for the @vport; and the second mailbox
331 * command requests the HBA to perform the actual fabric registration login
332 * with the @vport.
334 * Return code
335 * 0 - successfully issued fabric registration login for @vport
336 * -ENXIO -- failed to issue fabric registration login for @vport
339 lpfc_issue_fabric_reglogin(struct lpfc_vport *vport)
341 struct lpfc_hba *phba = vport->phba;
342 LPFC_MBOXQ_t *mbox;
343 struct lpfc_dmabuf *mp;
344 struct lpfc_nodelist *ndlp;
345 struct serv_parm *sp;
346 int rc;
347 int err = 0;
349 sp = &phba->fc_fabparam;
350 ndlp = lpfc_findnode_did(vport, Fabric_DID);
351 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
352 err = 1;
353 goto fail;
356 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
357 if (!mbox) {
358 err = 2;
359 goto fail;
362 vport->port_state = LPFC_FABRIC_CFG_LINK;
363 lpfc_config_link(phba, mbox);
364 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
365 mbox->vport = vport;
367 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
368 if (rc == MBX_NOT_FINISHED) {
369 err = 3;
370 goto fail_free_mbox;
373 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
374 if (!mbox) {
375 err = 4;
376 goto fail;
378 rc = lpfc_reg_rpi(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox, 0);
379 if (rc) {
380 err = 5;
381 goto fail_free_mbox;
384 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
385 mbox->vport = vport;
386 /* increment the reference count on ndlp to hold reference
387 * for the callback routine.
389 mbox->context2 = lpfc_nlp_get(ndlp);
391 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
392 if (rc == MBX_NOT_FINISHED) {
393 err = 6;
394 goto fail_issue_reg_login;
397 return 0;
399 fail_issue_reg_login:
400 /* decrement the reference count on ndlp just incremented
401 * for the failed mbox command.
403 lpfc_nlp_put(ndlp);
404 mp = (struct lpfc_dmabuf *) mbox->context1;
405 lpfc_mbuf_free(phba, mp->virt, mp->phys);
406 kfree(mp);
407 fail_free_mbox:
408 mempool_free(mbox, phba->mbox_mem_pool);
410 fail:
411 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
412 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
413 "0249 Cannot issue Register Fabric login: Err %d\n", err);
414 return -ENXIO;
418 * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login
419 * @vport: pointer to a host virtual N_Port data structure.
421 * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for
422 * the @vport. This mailbox command is necessary for FCoE only.
424 * Return code
425 * 0 - successfully issued REG_VFI for @vport
426 * A failure code otherwise.
428 static int
429 lpfc_issue_reg_vfi(struct lpfc_vport *vport)
431 struct lpfc_hba *phba = vport->phba;
432 LPFC_MBOXQ_t *mboxq;
433 struct lpfc_nodelist *ndlp;
434 struct serv_parm *sp;
435 struct lpfc_dmabuf *dmabuf;
436 int rc = 0;
438 sp = &phba->fc_fabparam;
439 ndlp = lpfc_findnode_did(vport, Fabric_DID);
440 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
441 rc = -ENODEV;
442 goto fail;
445 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
446 if (!dmabuf) {
447 rc = -ENOMEM;
448 goto fail;
450 dmabuf->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &dmabuf->phys);
451 if (!dmabuf->virt) {
452 rc = -ENOMEM;
453 goto fail_free_dmabuf;
455 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
456 if (!mboxq) {
457 rc = -ENOMEM;
458 goto fail_free_coherent;
460 vport->port_state = LPFC_FABRIC_CFG_LINK;
461 memcpy(dmabuf->virt, &phba->fc_fabparam, sizeof(vport->fc_sparam));
462 lpfc_reg_vfi(mboxq, vport, dmabuf->phys);
463 mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi;
464 mboxq->vport = vport;
465 mboxq->context1 = dmabuf;
466 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
467 if (rc == MBX_NOT_FINISHED) {
468 rc = -ENXIO;
469 goto fail_free_mbox;
471 return 0;
473 fail_free_mbox:
474 mempool_free(mboxq, phba->mbox_mem_pool);
475 fail_free_coherent:
476 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
477 fail_free_dmabuf:
478 kfree(dmabuf);
479 fail:
480 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
481 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
482 "0289 Issue Register VFI failed: Err %d\n", rc);
483 return rc;
487 * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port
488 * @vport: pointer to a host virtual N_Port data structure.
489 * @ndlp: pointer to a node-list data structure.
490 * @sp: pointer to service parameter data structure.
491 * @irsp: pointer to the IOCB within the lpfc response IOCB.
493 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
494 * function to handle the completion of a Fabric Login (FLOGI) into a fabric
495 * port in a fabric topology. It properly sets up the parameters to the @ndlp
496 * from the IOCB response. It also check the newly assigned N_Port ID to the
497 * @vport against the previously assigned N_Port ID. If it is different from
498 * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
499 * is invoked on all the remaining nodes with the @vport to unregister the
500 * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
501 * is invoked to register login to the fabric.
503 * Return code
504 * 0 - Success (currently, always return 0)
506 static int
507 lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
508 struct serv_parm *sp, IOCB_t *irsp)
510 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
511 struct lpfc_hba *phba = vport->phba;
512 struct lpfc_nodelist *np;
513 struct lpfc_nodelist *next_np;
515 spin_lock_irq(shost->host_lock);
516 vport->fc_flag |= FC_FABRIC;
517 spin_unlock_irq(shost->host_lock);
519 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
520 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
521 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
523 phba->fc_edtovResol = sp->cmn.edtovResolution;
524 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
526 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
527 spin_lock_irq(shost->host_lock);
528 vport->fc_flag |= FC_PUBLIC_LOOP;
529 spin_unlock_irq(shost->host_lock);
532 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
533 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
534 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
535 ndlp->nlp_class_sup = 0;
536 if (sp->cls1.classValid)
537 ndlp->nlp_class_sup |= FC_COS_CLASS1;
538 if (sp->cls2.classValid)
539 ndlp->nlp_class_sup |= FC_COS_CLASS2;
540 if (sp->cls3.classValid)
541 ndlp->nlp_class_sup |= FC_COS_CLASS3;
542 if (sp->cls4.classValid)
543 ndlp->nlp_class_sup |= FC_COS_CLASS4;
544 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
545 sp->cmn.bbRcvSizeLsb;
546 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
548 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
549 if (sp->cmn.response_multiple_NPort) {
550 lpfc_printf_vlog(vport, KERN_WARNING,
551 LOG_ELS | LOG_VPORT,
552 "1816 FLOGI NPIV supported, "
553 "response data 0x%x\n",
554 sp->cmn.response_multiple_NPort);
555 phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
556 } else {
557 /* Because we asked f/w for NPIV it still expects us
558 to call reg_vnpid atleast for the physcial host */
559 lpfc_printf_vlog(vport, KERN_WARNING,
560 LOG_ELS | LOG_VPORT,
561 "1817 Fabric does not support NPIV "
562 "- configuring single port mode.\n");
563 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
567 if ((vport->fc_prevDID != vport->fc_myDID) &&
568 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
570 /* If our NportID changed, we need to ensure all
571 * remaining NPORTs get unreg_login'ed.
573 list_for_each_entry_safe(np, next_np,
574 &vport->fc_nodes, nlp_listp) {
575 if (!NLP_CHK_NODE_ACT(np))
576 continue;
577 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
578 !(np->nlp_flag & NLP_NPR_ADISC))
579 continue;
580 spin_lock_irq(shost->host_lock);
581 np->nlp_flag &= ~NLP_NPR_ADISC;
582 spin_unlock_irq(shost->host_lock);
583 lpfc_unreg_rpi(vport, np);
585 lpfc_cleanup_pending_mbox(vport);
587 if (phba->sli_rev == LPFC_SLI_REV4)
588 lpfc_sli4_unreg_all_rpis(vport);
590 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
591 lpfc_mbx_unreg_vpi(vport);
592 spin_lock_irq(shost->host_lock);
593 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
594 spin_unlock_irq(shost->host_lock);
597 * If VPI is unreged, driver need to do INIT_VPI
598 * before re-registering
600 if (phba->sli_rev == LPFC_SLI_REV4) {
601 spin_lock_irq(shost->host_lock);
602 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
603 spin_unlock_irq(shost->host_lock);
605 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
606 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
608 * Driver needs to re-reg VPI in order for f/w
609 * to update the MAC address.
611 lpfc_register_new_vport(phba, vport, ndlp);
612 return 0;
615 if (phba->sli_rev < LPFC_SLI_REV4) {
616 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
617 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
618 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
619 lpfc_register_new_vport(phba, vport, ndlp);
620 else
621 lpfc_issue_fabric_reglogin(vport);
622 } else {
623 ndlp->nlp_type |= NLP_FABRIC;
624 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
625 if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) &&
626 (vport->vpi_state & LPFC_VPI_REGISTERED)) {
627 lpfc_start_fdiscs(phba);
628 lpfc_do_scr_ns_plogi(phba, vport);
629 } else if (vport->fc_flag & FC_VFI_REGISTERED)
630 lpfc_issue_init_vpi(vport);
631 else
632 lpfc_issue_reg_vfi(vport);
634 return 0;
637 * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
638 * @vport: pointer to a host virtual N_Port data structure.
639 * @ndlp: pointer to a node-list data structure.
640 * @sp: pointer to service parameter data structure.
642 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
643 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
644 * in a point-to-point topology. First, the @vport's N_Port Name is compared
645 * with the received N_Port Name: if the @vport's N_Port Name is greater than
646 * the received N_Port Name lexicographically, this node shall assign local
647 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
648 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
649 * this node shall just wait for the remote node to issue PLOGI and assign
650 * N_Port IDs.
652 * Return code
653 * 0 - Success
654 * -ENXIO - Fail
656 static int
657 lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
658 struct serv_parm *sp)
660 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
661 struct lpfc_hba *phba = vport->phba;
662 LPFC_MBOXQ_t *mbox;
663 int rc;
665 spin_lock_irq(shost->host_lock);
666 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
667 spin_unlock_irq(shost->host_lock);
669 phba->fc_edtov = FF_DEF_EDTOV;
670 phba->fc_ratov = FF_DEF_RATOV;
671 rc = memcmp(&vport->fc_portname, &sp->portName,
672 sizeof(vport->fc_portname));
673 if (rc >= 0) {
674 /* This side will initiate the PLOGI */
675 spin_lock_irq(shost->host_lock);
676 vport->fc_flag |= FC_PT2PT_PLOGI;
677 spin_unlock_irq(shost->host_lock);
680 * N_Port ID cannot be 0, set our to LocalID the other
681 * side will be RemoteID.
684 /* not equal */
685 if (rc)
686 vport->fc_myDID = PT2PT_LocalID;
688 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
689 if (!mbox)
690 goto fail;
692 lpfc_config_link(phba, mbox);
694 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
695 mbox->vport = vport;
696 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
697 if (rc == MBX_NOT_FINISHED) {
698 mempool_free(mbox, phba->mbox_mem_pool);
699 goto fail;
701 /* Decrement ndlp reference count indicating that ndlp can be
702 * safely released when other references to it are done.
704 lpfc_nlp_put(ndlp);
706 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
707 if (!ndlp) {
709 * Cannot find existing Fabric ndlp, so allocate a
710 * new one
712 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
713 if (!ndlp)
714 goto fail;
715 lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID);
716 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
717 ndlp = lpfc_enable_node(vport, ndlp,
718 NLP_STE_UNUSED_NODE);
719 if(!ndlp)
720 goto fail;
723 memcpy(&ndlp->nlp_portname, &sp->portName,
724 sizeof(struct lpfc_name));
725 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
726 sizeof(struct lpfc_name));
727 /* Set state will put ndlp onto node list if not already done */
728 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
729 spin_lock_irq(shost->host_lock);
730 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
731 spin_unlock_irq(shost->host_lock);
732 } else
733 /* This side will wait for the PLOGI, decrement ndlp reference
734 * count indicating that ndlp can be released when other
735 * references to it are done.
737 lpfc_nlp_put(ndlp);
739 /* If we are pt2pt with another NPort, force NPIV off! */
740 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
742 spin_lock_irq(shost->host_lock);
743 vport->fc_flag |= FC_PT2PT;
744 spin_unlock_irq(shost->host_lock);
746 /* Start discovery - this should just do CLEAR_LA */
747 lpfc_disc_start(vport);
748 return 0;
749 fail:
750 return -ENXIO;
754 * lpfc_cmpl_els_flogi - Completion callback function for flogi
755 * @phba: pointer to lpfc hba data structure.
756 * @cmdiocb: pointer to lpfc command iocb data structure.
757 * @rspiocb: pointer to lpfc response iocb data structure.
759 * This routine is the top-level completion callback function for issuing
760 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
761 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
762 * retry has been made (either immediately or delayed with lpfc_els_retry()
763 * returning 1), the command IOCB will be released and function returned.
764 * If the retry attempt has been given up (possibly reach the maximum
765 * number of retries), one additional decrement of ndlp reference shall be
766 * invoked before going out after releasing the command IOCB. This will
767 * actually release the remote node (Note, lpfc_els_free_iocb() will also
768 * invoke one decrement of ndlp reference count). If no error reported in
769 * the IOCB status, the command Port ID field is used to determine whether
770 * this is a point-to-point topology or a fabric topology: if the Port ID
771 * field is assigned, it is a fabric topology; otherwise, it is a
772 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
773 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
774 * specific topology completion conditions.
776 static void
777 lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
778 struct lpfc_iocbq *rspiocb)
780 struct lpfc_vport *vport = cmdiocb->vport;
781 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
782 IOCB_t *irsp = &rspiocb->iocb;
783 struct lpfc_nodelist *ndlp = cmdiocb->context1;
784 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
785 struct serv_parm *sp;
786 uint16_t fcf_index;
787 int rc;
789 /* Check to see if link went down during discovery */
790 if (lpfc_els_chk_latt(vport)) {
791 /* One additional decrement on node reference count to
792 * trigger the release of the node
794 lpfc_nlp_put(ndlp);
795 goto out;
798 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
799 "FLOGI cmpl: status:x%x/x%x state:x%x",
800 irsp->ulpStatus, irsp->un.ulpWord[4],
801 vport->port_state);
803 if (irsp->ulpStatus) {
805 * In case of FIP mode, perform roundrobin FCF failover
806 * due to new FCF discovery
808 if ((phba->hba_flag & HBA_FIP_SUPPORT) &&
809 (phba->fcf.fcf_flag & FCF_DISCOVERY) &&
810 (irsp->ulpStatus != IOSTAT_LOCAL_REJECT) &&
811 (irsp->un.ulpWord[4] != IOERR_SLI_ABORTED)) {
812 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
813 "2611 FLOGI failed on FCF (x%x), "
814 "status:x%x/x%x, tmo:x%x, perform "
815 "roundrobin FCF failover\n",
816 phba->fcf.current_rec.fcf_indx,
817 irsp->ulpStatus, irsp->un.ulpWord[4],
818 irsp->ulpTimeout);
819 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
820 rc = lpfc_sli4_fcf_rr_next_proc(vport, fcf_index);
821 if (rc)
822 goto out;
825 /* FLOGI failure */
826 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
827 "2858 FLOGI failure Status:x%x/x%x TMO:x%x\n",
828 irsp->ulpStatus, irsp->un.ulpWord[4],
829 irsp->ulpTimeout);
831 /* Check for retry */
832 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
833 goto out;
835 /* FLOGI failure */
836 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
837 "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n",
838 irsp->ulpStatus, irsp->un.ulpWord[4],
839 irsp->ulpTimeout);
841 /* FLOGI failed, so there is no fabric */
842 spin_lock_irq(shost->host_lock);
843 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
844 spin_unlock_irq(shost->host_lock);
846 /* If private loop, then allow max outstanding els to be
847 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
848 * alpa map would take too long otherwise.
850 if (phba->alpa_map[0] == 0) {
851 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
852 if ((phba->sli_rev == LPFC_SLI_REV4) &&
853 (!(vport->fc_flag & FC_VFI_REGISTERED) ||
854 (vport->fc_prevDID != vport->fc_myDID))) {
855 if (vport->fc_flag & FC_VFI_REGISTERED)
856 lpfc_sli4_unreg_all_rpis(vport);
857 lpfc_issue_reg_vfi(vport);
858 lpfc_nlp_put(ndlp);
859 goto out;
862 goto flogifail;
864 spin_lock_irq(shost->host_lock);
865 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
866 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
867 spin_unlock_irq(shost->host_lock);
870 * The FLogI succeeded. Sync the data for the CPU before
871 * accessing it.
873 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
875 sp = prsp->virt + sizeof(uint32_t);
877 /* FLOGI completes successfully */
878 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
879 "0101 FLOGI completes successfully "
880 "Data: x%x x%x x%x x%x\n",
881 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
882 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution);
884 if (vport->port_state == LPFC_FLOGI) {
886 * If Common Service Parameters indicate Nport
887 * we are point to point, if Fport we are Fabric.
889 if (sp->cmn.fPort)
890 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
891 else if (!(phba->hba_flag & HBA_FCOE_MODE))
892 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
893 else {
894 lpfc_printf_vlog(vport, KERN_ERR,
895 LOG_FIP | LOG_ELS,
896 "2831 FLOGI response with cleared Fabric "
897 "bit fcf_index 0x%x "
898 "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
899 "Fabric Name "
900 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
901 phba->fcf.current_rec.fcf_indx,
902 phba->fcf.current_rec.switch_name[0],
903 phba->fcf.current_rec.switch_name[1],
904 phba->fcf.current_rec.switch_name[2],
905 phba->fcf.current_rec.switch_name[3],
906 phba->fcf.current_rec.switch_name[4],
907 phba->fcf.current_rec.switch_name[5],
908 phba->fcf.current_rec.switch_name[6],
909 phba->fcf.current_rec.switch_name[7],
910 phba->fcf.current_rec.fabric_name[0],
911 phba->fcf.current_rec.fabric_name[1],
912 phba->fcf.current_rec.fabric_name[2],
913 phba->fcf.current_rec.fabric_name[3],
914 phba->fcf.current_rec.fabric_name[4],
915 phba->fcf.current_rec.fabric_name[5],
916 phba->fcf.current_rec.fabric_name[6],
917 phba->fcf.current_rec.fabric_name[7]);
918 lpfc_nlp_put(ndlp);
919 spin_lock_irq(&phba->hbalock);
920 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
921 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
922 spin_unlock_irq(&phba->hbalock);
923 goto out;
925 if (!rc) {
926 /* Mark the FCF discovery process done */
927 if (phba->hba_flag & HBA_FIP_SUPPORT)
928 lpfc_printf_vlog(vport, KERN_INFO, LOG_FIP |
929 LOG_ELS,
930 "2769 FLOGI to FCF (x%x) "
931 "completed successfully\n",
932 phba->fcf.current_rec.fcf_indx);
933 spin_lock_irq(&phba->hbalock);
934 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
935 phba->hba_flag &= ~(FCF_RR_INPROG | HBA_DEVLOSS_TMO);
936 spin_unlock_irq(&phba->hbalock);
937 goto out;
941 flogifail:
942 lpfc_nlp_put(ndlp);
944 if (!lpfc_error_lost_link(irsp)) {
945 /* FLOGI failed, so just use loop map to make discovery list */
946 lpfc_disc_list_loopmap(vport);
948 /* Start discovery */
949 lpfc_disc_start(vport);
950 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
951 ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) &&
952 (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) &&
953 (phba->link_state != LPFC_CLEAR_LA)) {
954 /* If FLOGI failed enable link interrupt. */
955 lpfc_issue_clear_la(phba, vport);
957 out:
958 lpfc_els_free_iocb(phba, cmdiocb);
962 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
963 * @vport: pointer to a host virtual N_Port data structure.
964 * @ndlp: pointer to a node-list data structure.
965 * @retry: number of retries to the command IOCB.
967 * This routine issues a Fabric Login (FLOGI) Request ELS command
968 * for a @vport. The initiator service parameters are put into the payload
969 * of the FLOGI Request IOCB and the top-level callback function pointer
970 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
971 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
972 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
974 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
975 * will be incremented by 1 for holding the ndlp and the reference to ndlp
976 * will be stored into the context1 field of the IOCB for the completion
977 * callback function to the FLOGI ELS command.
979 * Return code
980 * 0 - successfully issued flogi iocb for @vport
981 * 1 - failed to issue flogi iocb for @vport
983 static int
984 lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
985 uint8_t retry)
987 struct lpfc_hba *phba = vport->phba;
988 struct serv_parm *sp;
989 IOCB_t *icmd;
990 struct lpfc_iocbq *elsiocb;
991 struct lpfc_sli_ring *pring;
992 uint8_t *pcmd;
993 uint16_t cmdsize;
994 uint32_t tmo;
995 int rc;
997 pring = &phba->sli.ring[LPFC_ELS_RING];
999 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
1000 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1001 ndlp->nlp_DID, ELS_CMD_FLOGI);
1003 if (!elsiocb)
1004 return 1;
1006 icmd = &elsiocb->iocb;
1007 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1009 /* For FLOGI request, remainder of payload is service parameters */
1010 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
1011 pcmd += sizeof(uint32_t);
1012 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
1013 sp = (struct serv_parm *) pcmd;
1015 /* Setup CSPs accordingly for Fabric */
1016 sp->cmn.e_d_tov = 0;
1017 sp->cmn.w2.r_a_tov = 0;
1018 sp->cls1.classValid = 0;
1019 sp->cls2.seqDelivery = 1;
1020 sp->cls3.seqDelivery = 1;
1021 if (sp->cmn.fcphLow < FC_PH3)
1022 sp->cmn.fcphLow = FC_PH3;
1023 if (sp->cmn.fcphHigh < FC_PH3)
1024 sp->cmn.fcphHigh = FC_PH3;
1026 if (phba->sli_rev == LPFC_SLI_REV4) {
1027 elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1);
1028 elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1);
1029 /* FLOGI needs to be 3 for WQE FCFI */
1030 /* Set the fcfi to the fcfi we registered with */
1031 elsiocb->iocb.ulpContext = phba->fcf.fcfi;
1032 } else if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
1033 sp->cmn.request_multiple_Nport = 1;
1034 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1035 icmd->ulpCt_h = 1;
1036 icmd->ulpCt_l = 0;
1039 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP) {
1040 icmd->un.elsreq64.myID = 0;
1041 icmd->un.elsreq64.fl = 1;
1044 tmo = phba->fc_ratov;
1045 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
1046 lpfc_set_disctmo(vport);
1047 phba->fc_ratov = tmo;
1049 phba->fc_stat.elsXmitFLOGI++;
1050 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
1052 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1053 "Issue FLOGI: opt:x%x",
1054 phba->sli3_options, 0, 0);
1056 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
1057 if (rc == IOCB_ERROR) {
1058 lpfc_els_free_iocb(phba, elsiocb);
1059 return 1;
1061 return 0;
1065 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
1066 * @phba: pointer to lpfc hba data structure.
1068 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1069 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1070 * list and issues an abort IOCB commond on each outstanding IOCB that
1071 * contains a active Fabric_DID ndlp. Note that this function is to issue
1072 * the abort IOCB command on all the outstanding IOCBs, thus when this
1073 * function returns, it does not guarantee all the IOCBs are actually aborted.
1075 * Return code
1076 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
1079 lpfc_els_abort_flogi(struct lpfc_hba *phba)
1081 struct lpfc_sli_ring *pring;
1082 struct lpfc_iocbq *iocb, *next_iocb;
1083 struct lpfc_nodelist *ndlp;
1084 IOCB_t *icmd;
1086 /* Abort outstanding I/O on NPort <nlp_DID> */
1087 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1088 "0201 Abort outstanding I/O on NPort x%x\n",
1089 Fabric_DID);
1091 pring = &phba->sli.ring[LPFC_ELS_RING];
1094 * Check the txcmplq for an iocb that matches the nport the driver is
1095 * searching for.
1097 spin_lock_irq(&phba->hbalock);
1098 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
1099 icmd = &iocb->iocb;
1100 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR &&
1101 icmd->un.elsreq64.bdl.ulpIoTag32) {
1102 ndlp = (struct lpfc_nodelist *)(iocb->context1);
1103 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
1104 (ndlp->nlp_DID == Fabric_DID))
1105 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
1108 spin_unlock_irq(&phba->hbalock);
1110 return 0;
1114 * lpfc_initial_flogi - Issue an initial fabric login for a vport
1115 * @vport: pointer to a host virtual N_Port data structure.
1117 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1118 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1119 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1120 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1121 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1122 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1123 * @vport.
1125 * Return code
1126 * 0 - failed to issue initial flogi for @vport
1127 * 1 - successfully issued initial flogi for @vport
1130 lpfc_initial_flogi(struct lpfc_vport *vport)
1132 struct lpfc_hba *phba = vport->phba;
1133 struct lpfc_nodelist *ndlp;
1135 vport->port_state = LPFC_FLOGI;
1136 lpfc_set_disctmo(vport);
1138 /* First look for the Fabric ndlp */
1139 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1140 if (!ndlp) {
1141 /* Cannot find existing Fabric ndlp, so allocate a new one */
1142 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1143 if (!ndlp)
1144 return 0;
1145 lpfc_nlp_init(vport, ndlp, Fabric_DID);
1146 /* Set the node type */
1147 ndlp->nlp_type |= NLP_FABRIC;
1148 /* Put ndlp onto node list */
1149 lpfc_enqueue_node(vport, ndlp);
1150 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1151 /* re-setup ndlp without removing from node list */
1152 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1153 if (!ndlp)
1154 return 0;
1157 if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
1158 /* This decrement of reference count to node shall kick off
1159 * the release of the node.
1161 lpfc_nlp_put(ndlp);
1162 return 0;
1164 return 1;
1168 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
1169 * @vport: pointer to a host virtual N_Port data structure.
1171 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1172 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1173 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1174 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1175 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1176 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1177 * @vport.
1179 * Return code
1180 * 0 - failed to issue initial fdisc for @vport
1181 * 1 - successfully issued initial fdisc for @vport
1184 lpfc_initial_fdisc(struct lpfc_vport *vport)
1186 struct lpfc_hba *phba = vport->phba;
1187 struct lpfc_nodelist *ndlp;
1189 /* First look for the Fabric ndlp */
1190 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1191 if (!ndlp) {
1192 /* Cannot find existing Fabric ndlp, so allocate a new one */
1193 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1194 if (!ndlp)
1195 return 0;
1196 lpfc_nlp_init(vport, ndlp, Fabric_DID);
1197 /* Put ndlp onto node list */
1198 lpfc_enqueue_node(vport, ndlp);
1199 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1200 /* re-setup ndlp without removing from node list */
1201 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1202 if (!ndlp)
1203 return 0;
1206 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
1207 /* decrement node reference count to trigger the release of
1208 * the node.
1210 lpfc_nlp_put(ndlp);
1211 return 0;
1213 return 1;
1217 * lpfc_more_plogi - Check and issue remaining plogis for a vport
1218 * @vport: pointer to a host virtual N_Port data structure.
1220 * This routine checks whether there are more remaining Port Logins
1221 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1222 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1223 * to issue ELS PLOGIs up to the configured discover threads with the
1224 * @vport (@vport->cfg_discovery_threads). The function also decrement
1225 * the @vport's num_disc_node by 1 if it is not already 0.
1227 void
1228 lpfc_more_plogi(struct lpfc_vport *vport)
1230 int sentplogi;
1232 if (vport->num_disc_nodes)
1233 vport->num_disc_nodes--;
1235 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
1236 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1237 "0232 Continue discovery with %d PLOGIs to go "
1238 "Data: x%x x%x x%x\n",
1239 vport->num_disc_nodes, vport->fc_plogi_cnt,
1240 vport->fc_flag, vport->port_state);
1241 /* Check to see if there are more PLOGIs to be sent */
1242 if (vport->fc_flag & FC_NLP_MORE)
1243 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1244 sentplogi = lpfc_els_disc_plogi(vport);
1246 return;
1250 * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
1251 * @phba: pointer to lpfc hba data structure.
1252 * @prsp: pointer to response IOCB payload.
1253 * @ndlp: pointer to a node-list data structure.
1255 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1256 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1257 * The following cases are considered N_Port confirmed:
1258 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1259 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1260 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1261 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1262 * 1) if there is a node on vport list other than the @ndlp with the same
1263 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1264 * on that node to release the RPI associated with the node; 2) if there is
1265 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1266 * into, a new node shall be allocated (or activated). In either case, the
1267 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1268 * be released and the new_ndlp shall be put on to the vport node list and
1269 * its pointer returned as the confirmed node.
1271 * Note that before the @ndlp got "released", the keepDID from not-matching
1272 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1273 * of the @ndlp. This is because the release of @ndlp is actually to put it
1274 * into an inactive state on the vport node list and the vport node list
1275 * management algorithm does not allow two node with a same DID.
1277 * Return code
1278 * pointer to the PLOGI N_Port @ndlp
1280 static struct lpfc_nodelist *
1281 lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
1282 struct lpfc_nodelist *ndlp)
1284 struct lpfc_vport *vport = ndlp->vport;
1285 struct lpfc_nodelist *new_ndlp;
1286 struct lpfc_rport_data *rdata;
1287 struct fc_rport *rport;
1288 struct serv_parm *sp;
1289 uint8_t name[sizeof(struct lpfc_name)];
1290 uint32_t rc, keepDID = 0;
1291 int put_node;
1292 int put_rport;
1293 struct lpfc_node_rrqs rrq;
1295 /* Fabric nodes can have the same WWPN so we don't bother searching
1296 * by WWPN. Just return the ndlp that was given to us.
1298 if (ndlp->nlp_type & NLP_FABRIC)
1299 return ndlp;
1301 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
1302 memset(name, 0, sizeof(struct lpfc_name));
1304 /* Now we find out if the NPort we are logging into, matches the WWPN
1305 * we have for that ndlp. If not, we have some work to do.
1307 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
1309 if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
1310 return ndlp;
1311 memset(&rrq.xri_bitmap, 0, sizeof(new_ndlp->active_rrqs.xri_bitmap));
1313 if (!new_ndlp) {
1314 rc = memcmp(&ndlp->nlp_portname, name,
1315 sizeof(struct lpfc_name));
1316 if (!rc)
1317 return ndlp;
1318 new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
1319 if (!new_ndlp)
1320 return ndlp;
1321 lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID);
1322 } else if (!NLP_CHK_NODE_ACT(new_ndlp)) {
1323 rc = memcmp(&ndlp->nlp_portname, name,
1324 sizeof(struct lpfc_name));
1325 if (!rc)
1326 return ndlp;
1327 new_ndlp = lpfc_enable_node(vport, new_ndlp,
1328 NLP_STE_UNUSED_NODE);
1329 if (!new_ndlp)
1330 return ndlp;
1331 keepDID = new_ndlp->nlp_DID;
1332 if (phba->sli_rev == LPFC_SLI_REV4)
1333 memcpy(&rrq.xri_bitmap,
1334 &new_ndlp->active_rrqs.xri_bitmap,
1335 sizeof(new_ndlp->active_rrqs.xri_bitmap));
1336 } else {
1337 keepDID = new_ndlp->nlp_DID;
1338 if (phba->sli_rev == LPFC_SLI_REV4)
1339 memcpy(&rrq.xri_bitmap,
1340 &new_ndlp->active_rrqs.xri_bitmap,
1341 sizeof(new_ndlp->active_rrqs.xri_bitmap));
1344 lpfc_unreg_rpi(vport, new_ndlp);
1345 new_ndlp->nlp_DID = ndlp->nlp_DID;
1346 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
1347 if (phba->sli_rev == LPFC_SLI_REV4)
1348 memcpy(new_ndlp->active_rrqs.xri_bitmap,
1349 &ndlp->active_rrqs.xri_bitmap,
1350 sizeof(ndlp->active_rrqs.xri_bitmap));
1352 if (ndlp->nlp_flag & NLP_NPR_2B_DISC)
1353 new_ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1354 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1356 /* Set state will put new_ndlp on to node list if not already done */
1357 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
1359 /* Move this back to NPR state */
1360 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1361 /* The new_ndlp is replacing ndlp totally, so we need
1362 * to put ndlp on UNUSED list and try to free it.
1365 /* Fix up the rport accordingly */
1366 rport = ndlp->rport;
1367 if (rport) {
1368 rdata = rport->dd_data;
1369 if (rdata->pnode == ndlp) {
1370 lpfc_nlp_put(ndlp);
1371 ndlp->rport = NULL;
1372 rdata->pnode = lpfc_nlp_get(new_ndlp);
1373 new_ndlp->rport = rport;
1375 new_ndlp->nlp_type = ndlp->nlp_type;
1377 /* We shall actually free the ndlp with both nlp_DID and
1378 * nlp_portname fields equals 0 to avoid any ndlp on the
1379 * nodelist never to be used.
1381 if (ndlp->nlp_DID == 0) {
1382 spin_lock_irq(&phba->ndlp_lock);
1383 NLP_SET_FREE_REQ(ndlp);
1384 spin_unlock_irq(&phba->ndlp_lock);
1387 /* Two ndlps cannot have the same did on the nodelist */
1388 ndlp->nlp_DID = keepDID;
1389 if (phba->sli_rev == LPFC_SLI_REV4)
1390 memcpy(&ndlp->active_rrqs.xri_bitmap,
1391 &rrq.xri_bitmap,
1392 sizeof(ndlp->active_rrqs.xri_bitmap));
1393 lpfc_drop_node(vport, ndlp);
1395 else {
1396 lpfc_unreg_rpi(vport, ndlp);
1397 /* Two ndlps cannot have the same did */
1398 ndlp->nlp_DID = keepDID;
1399 if (phba->sli_rev == LPFC_SLI_REV4)
1400 memcpy(&ndlp->active_rrqs.xri_bitmap,
1401 &rrq.xri_bitmap,
1402 sizeof(ndlp->active_rrqs.xri_bitmap));
1403 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1404 /* Since we are swapping the ndlp passed in with the new one
1405 * and the did has already been swapped, copy over the
1406 * state and names.
1408 memcpy(&new_ndlp->nlp_portname, &ndlp->nlp_portname,
1409 sizeof(struct lpfc_name));
1410 memcpy(&new_ndlp->nlp_nodename, &ndlp->nlp_nodename,
1411 sizeof(struct lpfc_name));
1412 new_ndlp->nlp_state = ndlp->nlp_state;
1413 /* Fix up the rport accordingly */
1414 rport = ndlp->rport;
1415 if (rport) {
1416 rdata = rport->dd_data;
1417 put_node = rdata->pnode != NULL;
1418 put_rport = ndlp->rport != NULL;
1419 rdata->pnode = NULL;
1420 ndlp->rport = NULL;
1421 if (put_node)
1422 lpfc_nlp_put(ndlp);
1423 if (put_rport)
1424 put_device(&rport->dev);
1427 return new_ndlp;
1431 * lpfc_end_rscn - Check and handle more rscn for a vport
1432 * @vport: pointer to a host virtual N_Port data structure.
1434 * This routine checks whether more Registration State Change
1435 * Notifications (RSCNs) came in while the discovery state machine was in
1436 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1437 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1438 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1439 * handling the RSCNs.
1441 void
1442 lpfc_end_rscn(struct lpfc_vport *vport)
1444 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1446 if (vport->fc_flag & FC_RSCN_MODE) {
1448 * Check to see if more RSCNs came in while we were
1449 * processing this one.
1451 if (vport->fc_rscn_id_cnt ||
1452 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1453 lpfc_els_handle_rscn(vport);
1454 else {
1455 spin_lock_irq(shost->host_lock);
1456 vport->fc_flag &= ~FC_RSCN_MODE;
1457 spin_unlock_irq(shost->host_lock);
1463 * lpfc_cmpl_els_rrq - Completion handled for els RRQs.
1464 * @phba: pointer to lpfc hba data structure.
1465 * @cmdiocb: pointer to lpfc command iocb data structure.
1466 * @rspiocb: pointer to lpfc response iocb data structure.
1468 * This routine will call the clear rrq function to free the rrq and
1469 * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not
1470 * exist then the clear_rrq is still called because the rrq needs to
1471 * be freed.
1474 static void
1475 lpfc_cmpl_els_rrq(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1476 struct lpfc_iocbq *rspiocb)
1478 struct lpfc_vport *vport = cmdiocb->vport;
1479 IOCB_t *irsp;
1480 struct lpfc_nodelist *ndlp;
1481 struct lpfc_node_rrq *rrq;
1483 /* we pass cmdiocb to state machine which needs rspiocb as well */
1484 rrq = cmdiocb->context_un.rrq;
1485 cmdiocb->context_un.rsp_iocb = rspiocb;
1487 irsp = &rspiocb->iocb;
1488 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1489 "RRQ cmpl: status:x%x/x%x did:x%x",
1490 irsp->ulpStatus, irsp->un.ulpWord[4],
1491 irsp->un.elsreq64.remoteID);
1493 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
1494 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || ndlp != rrq->ndlp) {
1495 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1496 "2882 RRQ completes to NPort x%x "
1497 "with no ndlp. Data: x%x x%x x%x\n",
1498 irsp->un.elsreq64.remoteID,
1499 irsp->ulpStatus, irsp->un.ulpWord[4],
1500 irsp->ulpIoTag);
1501 goto out;
1504 /* rrq completes to NPort <nlp_DID> */
1505 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1506 "2880 RRQ completes to NPort x%x "
1507 "Data: x%x x%x x%x x%x x%x\n",
1508 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1509 irsp->ulpTimeout, rrq->xritag, rrq->rxid);
1511 if (irsp->ulpStatus) {
1512 /* Check for retry */
1513 /* RRQ failed Don't print the vport to vport rjts */
1514 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1515 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1516 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1517 (phba)->pport->cfg_log_verbose & LOG_ELS)
1518 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1519 "2881 RRQ failure DID:%06X Status:x%x/x%x\n",
1520 ndlp->nlp_DID, irsp->ulpStatus,
1521 irsp->un.ulpWord[4]);
1523 out:
1524 if (rrq)
1525 lpfc_clr_rrq_active(phba, rrq->xritag, rrq);
1526 lpfc_els_free_iocb(phba, cmdiocb);
1527 return;
1530 * lpfc_cmpl_els_plogi - Completion callback function for plogi
1531 * @phba: pointer to lpfc hba data structure.
1532 * @cmdiocb: pointer to lpfc command iocb data structure.
1533 * @rspiocb: pointer to lpfc response iocb data structure.
1535 * This routine is the completion callback function for issuing the Port
1536 * Login (PLOGI) command. For PLOGI completion, there must be an active
1537 * ndlp on the vport node list that matches the remote node ID from the
1538 * PLOGI reponse IOCB. If such ndlp does not exist, the PLOGI is simply
1539 * ignored and command IOCB released. The PLOGI response IOCB status is
1540 * checked for error conditons. If there is error status reported, PLOGI
1541 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1542 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1543 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1544 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1545 * there are additional N_Port nodes with the vport that need to perform
1546 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1547 * PLOGIs.
1549 static void
1550 lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1551 struct lpfc_iocbq *rspiocb)
1553 struct lpfc_vport *vport = cmdiocb->vport;
1554 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1555 IOCB_t *irsp;
1556 struct lpfc_nodelist *ndlp;
1557 struct lpfc_dmabuf *prsp;
1558 int disc, rc, did, type;
1560 /* we pass cmdiocb to state machine which needs rspiocb as well */
1561 cmdiocb->context_un.rsp_iocb = rspiocb;
1563 irsp = &rspiocb->iocb;
1564 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1565 "PLOGI cmpl: status:x%x/x%x did:x%x",
1566 irsp->ulpStatus, irsp->un.ulpWord[4],
1567 irsp->un.elsreq64.remoteID);
1569 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
1570 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
1571 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1572 "0136 PLOGI completes to NPort x%x "
1573 "with no ndlp. Data: x%x x%x x%x\n",
1574 irsp->un.elsreq64.remoteID,
1575 irsp->ulpStatus, irsp->un.ulpWord[4],
1576 irsp->ulpIoTag);
1577 goto out;
1580 /* Since ndlp can be freed in the disc state machine, note if this node
1581 * is being used during discovery.
1583 spin_lock_irq(shost->host_lock);
1584 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
1585 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1586 spin_unlock_irq(shost->host_lock);
1587 rc = 0;
1589 /* PLOGI completes to NPort <nlp_DID> */
1590 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1591 "0102 PLOGI completes to NPort x%x "
1592 "Data: x%x x%x x%x x%x x%x\n",
1593 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1594 irsp->ulpTimeout, disc, vport->num_disc_nodes);
1595 /* Check to see if link went down during discovery */
1596 if (lpfc_els_chk_latt(vport)) {
1597 spin_lock_irq(shost->host_lock);
1598 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1599 spin_unlock_irq(shost->host_lock);
1600 goto out;
1603 /* ndlp could be freed in DSM, save these values now */
1604 type = ndlp->nlp_type;
1605 did = ndlp->nlp_DID;
1607 if (irsp->ulpStatus) {
1608 /* Check for retry */
1609 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1610 /* ELS command is being retried */
1611 if (disc) {
1612 spin_lock_irq(shost->host_lock);
1613 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1614 spin_unlock_irq(shost->host_lock);
1616 goto out;
1618 /* PLOGI failed Don't print the vport to vport rjts */
1619 if (irsp->ulpStatus != IOSTAT_LS_RJT ||
1620 (((irsp->un.ulpWord[4]) >> 16 != LSRJT_INVALID_CMD) &&
1621 ((irsp->un.ulpWord[4]) >> 16 != LSRJT_UNABLE_TPC)) ||
1622 (phba)->pport->cfg_log_verbose & LOG_ELS)
1623 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1624 "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
1625 ndlp->nlp_DID, irsp->ulpStatus,
1626 irsp->un.ulpWord[4]);
1627 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1628 if (lpfc_error_lost_link(irsp))
1629 rc = NLP_STE_FREED_NODE;
1630 else
1631 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1632 NLP_EVT_CMPL_PLOGI);
1633 } else {
1634 /* Good status, call state machine */
1635 prsp = list_entry(((struct lpfc_dmabuf *)
1636 cmdiocb->context2)->list.next,
1637 struct lpfc_dmabuf, list);
1638 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
1639 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1640 NLP_EVT_CMPL_PLOGI);
1643 if (disc && vport->num_disc_nodes) {
1644 /* Check to see if there are more PLOGIs to be sent */
1645 lpfc_more_plogi(vport);
1647 if (vport->num_disc_nodes == 0) {
1648 spin_lock_irq(shost->host_lock);
1649 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1650 spin_unlock_irq(shost->host_lock);
1652 lpfc_can_disctmo(vport);
1653 lpfc_end_rscn(vport);
1657 out:
1658 lpfc_els_free_iocb(phba, cmdiocb);
1659 return;
1663 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
1664 * @vport: pointer to a host virtual N_Port data structure.
1665 * @did: destination port identifier.
1666 * @retry: number of retries to the command IOCB.
1668 * This routine issues a Port Login (PLOGI) command to a remote N_Port
1669 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
1670 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
1671 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
1672 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
1674 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1675 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1676 * will be stored into the context1 field of the IOCB for the completion
1677 * callback function to the PLOGI ELS command.
1679 * Return code
1680 * 0 - Successfully issued a plogi for @vport
1681 * 1 - failed to issue a plogi for @vport
1684 lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
1686 struct lpfc_hba *phba = vport->phba;
1687 struct serv_parm *sp;
1688 IOCB_t *icmd;
1689 struct lpfc_nodelist *ndlp;
1690 struct lpfc_iocbq *elsiocb;
1691 struct lpfc_sli *psli;
1692 uint8_t *pcmd;
1693 uint16_t cmdsize;
1694 int ret;
1696 psli = &phba->sli;
1698 ndlp = lpfc_findnode_did(vport, did);
1699 if (ndlp && !NLP_CHK_NODE_ACT(ndlp))
1700 ndlp = NULL;
1702 /* If ndlp is not NULL, we will bump the reference count on it */
1703 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
1704 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
1705 ELS_CMD_PLOGI);
1706 if (!elsiocb)
1707 return 1;
1709 icmd = &elsiocb->iocb;
1710 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1712 /* For PLOGI request, remainder of payload is service parameters */
1713 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
1714 pcmd += sizeof(uint32_t);
1715 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
1716 sp = (struct serv_parm *) pcmd;
1719 * If we are a N-port connected to a Fabric, fix-up paramm's so logins
1720 * to device on remote loops work.
1722 if ((vport->fc_flag & FC_FABRIC) && !(vport->fc_flag & FC_PUBLIC_LOOP))
1723 sp->cmn.altBbCredit = 1;
1725 if (sp->cmn.fcphLow < FC_PH_4_3)
1726 sp->cmn.fcphLow = FC_PH_4_3;
1728 if (sp->cmn.fcphHigh < FC_PH3)
1729 sp->cmn.fcphHigh = FC_PH3;
1731 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1732 "Issue PLOGI: did:x%x",
1733 did, 0, 0);
1735 phba->fc_stat.elsXmitPLOGI++;
1736 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
1737 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
1739 if (ret == IOCB_ERROR) {
1740 lpfc_els_free_iocb(phba, elsiocb);
1741 return 1;
1743 return 0;
1747 * lpfc_cmpl_els_prli - Completion callback function for prli
1748 * @phba: pointer to lpfc hba data structure.
1749 * @cmdiocb: pointer to lpfc command iocb data structure.
1750 * @rspiocb: pointer to lpfc response iocb data structure.
1752 * This routine is the completion callback function for a Process Login
1753 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
1754 * status. If there is error status reported, PRLI retry shall be attempted
1755 * by invoking the lpfc_els_retry() routine. Otherwise, the state
1756 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
1757 * ndlp to mark the PRLI completion.
1759 static void
1760 lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1761 struct lpfc_iocbq *rspiocb)
1763 struct lpfc_vport *vport = cmdiocb->vport;
1764 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1765 IOCB_t *irsp;
1766 struct lpfc_sli *psli;
1767 struct lpfc_nodelist *ndlp;
1769 psli = &phba->sli;
1770 /* we pass cmdiocb to state machine which needs rspiocb as well */
1771 cmdiocb->context_un.rsp_iocb = rspiocb;
1773 irsp = &(rspiocb->iocb);
1774 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1775 spin_lock_irq(shost->host_lock);
1776 ndlp->nlp_flag &= ~NLP_PRLI_SND;
1777 spin_unlock_irq(shost->host_lock);
1779 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1780 "PRLI cmpl: status:x%x/x%x did:x%x",
1781 irsp->ulpStatus, irsp->un.ulpWord[4],
1782 ndlp->nlp_DID);
1783 /* PRLI completes to NPort <nlp_DID> */
1784 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1785 "0103 PRLI completes to NPort x%x "
1786 "Data: x%x x%x x%x x%x\n",
1787 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1788 irsp->ulpTimeout, vport->num_disc_nodes);
1790 vport->fc_prli_sent--;
1791 /* Check to see if link went down during discovery */
1792 if (lpfc_els_chk_latt(vport))
1793 goto out;
1795 if (irsp->ulpStatus) {
1796 /* Check for retry */
1797 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1798 /* ELS command is being retried */
1799 goto out;
1801 /* PRLI failed */
1802 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1803 "2754 PRLI failure DID:%06X Status:x%x/x%x\n",
1804 ndlp->nlp_DID, irsp->ulpStatus,
1805 irsp->un.ulpWord[4]);
1806 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1807 if (lpfc_error_lost_link(irsp))
1808 goto out;
1809 else
1810 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1811 NLP_EVT_CMPL_PRLI);
1812 } else
1813 /* Good status, call state machine */
1814 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1815 NLP_EVT_CMPL_PRLI);
1816 out:
1817 lpfc_els_free_iocb(phba, cmdiocb);
1818 return;
1822 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
1823 * @vport: pointer to a host virtual N_Port data structure.
1824 * @ndlp: pointer to a node-list data structure.
1825 * @retry: number of retries to the command IOCB.
1827 * This routine issues a Process Login (PRLI) ELS command for the
1828 * @vport. The PRLI service parameters are set up in the payload of the
1829 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
1830 * is put to the IOCB completion callback func field before invoking the
1831 * routine lpfc_sli_issue_iocb() to send out PRLI command.
1833 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1834 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1835 * will be stored into the context1 field of the IOCB for the completion
1836 * callback function to the PRLI ELS command.
1838 * Return code
1839 * 0 - successfully issued prli iocb command for @vport
1840 * 1 - failed to issue prli iocb command for @vport
1843 lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1844 uint8_t retry)
1846 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1847 struct lpfc_hba *phba = vport->phba;
1848 PRLI *npr;
1849 IOCB_t *icmd;
1850 struct lpfc_iocbq *elsiocb;
1851 uint8_t *pcmd;
1852 uint16_t cmdsize;
1854 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
1855 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1856 ndlp->nlp_DID, ELS_CMD_PRLI);
1857 if (!elsiocb)
1858 return 1;
1860 icmd = &elsiocb->iocb;
1861 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1863 /* For PRLI request, remainder of payload is service parameters */
1864 memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t)));
1865 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
1866 pcmd += sizeof(uint32_t);
1868 /* For PRLI, remainder of payload is PRLI parameter page */
1869 npr = (PRLI *) pcmd;
1871 * If our firmware version is 3.20 or later,
1872 * set the following bits for FC-TAPE support.
1874 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
1875 npr->ConfmComplAllowed = 1;
1876 npr->Retry = 1;
1877 npr->TaskRetryIdReq = 1;
1879 npr->estabImagePair = 1;
1880 npr->readXferRdyDis = 1;
1882 /* For FCP support */
1883 npr->prliType = PRLI_FCP_TYPE;
1884 npr->initiatorFunc = 1;
1886 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1887 "Issue PRLI: did:x%x",
1888 ndlp->nlp_DID, 0, 0);
1890 phba->fc_stat.elsXmitPRLI++;
1891 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
1892 spin_lock_irq(shost->host_lock);
1893 ndlp->nlp_flag |= NLP_PRLI_SND;
1894 spin_unlock_irq(shost->host_lock);
1895 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
1896 IOCB_ERROR) {
1897 spin_lock_irq(shost->host_lock);
1898 ndlp->nlp_flag &= ~NLP_PRLI_SND;
1899 spin_unlock_irq(shost->host_lock);
1900 lpfc_els_free_iocb(phba, elsiocb);
1901 return 1;
1903 vport->fc_prli_sent++;
1904 return 0;
1908 * lpfc_rscn_disc - Perform rscn discovery for a vport
1909 * @vport: pointer to a host virtual N_Port data structure.
1911 * This routine performs Registration State Change Notification (RSCN)
1912 * discovery for a @vport. If the @vport's node port recovery count is not
1913 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
1914 * the nodes that need recovery. If none of the PLOGI were needed through
1915 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
1916 * invoked to check and handle possible more RSCN came in during the period
1917 * of processing the current ones.
1919 static void
1920 lpfc_rscn_disc(struct lpfc_vport *vport)
1922 lpfc_can_disctmo(vport);
1924 /* RSCN discovery */
1925 /* go thru NPR nodes and issue ELS PLOGIs */
1926 if (vport->fc_npr_cnt)
1927 if (lpfc_els_disc_plogi(vport))
1928 return;
1930 lpfc_end_rscn(vport);
1934 * lpfc_adisc_done - Complete the adisc phase of discovery
1935 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
1937 * This function is called when the final ADISC is completed during discovery.
1938 * This function handles clearing link attention or issuing reg_vpi depending
1939 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
1940 * discovery.
1941 * This function is called with no locks held.
1943 static void
1944 lpfc_adisc_done(struct lpfc_vport *vport)
1946 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1947 struct lpfc_hba *phba = vport->phba;
1950 * For NPIV, cmpl_reg_vpi will set port_state to READY,
1951 * and continue discovery.
1953 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
1954 !(vport->fc_flag & FC_RSCN_MODE) &&
1955 (phba->sli_rev < LPFC_SLI_REV4)) {
1956 lpfc_issue_reg_vpi(phba, vport);
1957 return;
1960 * For SLI2, we need to set port_state to READY
1961 * and continue discovery.
1963 if (vport->port_state < LPFC_VPORT_READY) {
1964 /* If we get here, there is nothing to ADISC */
1965 if (vport->port_type == LPFC_PHYSICAL_PORT)
1966 lpfc_issue_clear_la(phba, vport);
1967 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
1968 vport->num_disc_nodes = 0;
1969 /* go thru NPR list, issue ELS PLOGIs */
1970 if (vport->fc_npr_cnt)
1971 lpfc_els_disc_plogi(vport);
1972 if (!vport->num_disc_nodes) {
1973 spin_lock_irq(shost->host_lock);
1974 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1975 spin_unlock_irq(shost->host_lock);
1976 lpfc_can_disctmo(vport);
1977 lpfc_end_rscn(vport);
1980 vport->port_state = LPFC_VPORT_READY;
1981 } else
1982 lpfc_rscn_disc(vport);
1986 * lpfc_more_adisc - Issue more adisc as needed
1987 * @vport: pointer to a host virtual N_Port data structure.
1989 * This routine determines whether there are more ndlps on a @vport
1990 * node list need to have Address Discover (ADISC) issued. If so, it will
1991 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
1992 * remaining nodes which need to have ADISC sent.
1994 void
1995 lpfc_more_adisc(struct lpfc_vport *vport)
1997 int sentadisc;
1999 if (vport->num_disc_nodes)
2000 vport->num_disc_nodes--;
2001 /* Continue discovery with <num_disc_nodes> ADISCs to go */
2002 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2003 "0210 Continue discovery with %d ADISCs to go "
2004 "Data: x%x x%x x%x\n",
2005 vport->num_disc_nodes, vport->fc_adisc_cnt,
2006 vport->fc_flag, vport->port_state);
2007 /* Check to see if there are more ADISCs to be sent */
2008 if (vport->fc_flag & FC_NLP_MORE) {
2009 lpfc_set_disctmo(vport);
2010 /* go thru NPR nodes and issue any remaining ELS ADISCs */
2011 sentadisc = lpfc_els_disc_adisc(vport);
2013 if (!vport->num_disc_nodes)
2014 lpfc_adisc_done(vport);
2015 return;
2019 * lpfc_cmpl_els_adisc - Completion callback function for adisc
2020 * @phba: pointer to lpfc hba data structure.
2021 * @cmdiocb: pointer to lpfc command iocb data structure.
2022 * @rspiocb: pointer to lpfc response iocb data structure.
2024 * This routine is the completion function for issuing the Address Discover
2025 * (ADISC) command. It first checks to see whether link went down during
2026 * the discovery process. If so, the node will be marked as node port
2027 * recovery for issuing discover IOCB by the link attention handler and
2028 * exit. Otherwise, the response status is checked. If error was reported
2029 * in the response status, the ADISC command shall be retried by invoking
2030 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
2031 * the response status, the state machine is invoked to set transition
2032 * with respect to NLP_EVT_CMPL_ADISC event.
2034 static void
2035 lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2036 struct lpfc_iocbq *rspiocb)
2038 struct lpfc_vport *vport = cmdiocb->vport;
2039 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2040 IOCB_t *irsp;
2041 struct lpfc_nodelist *ndlp;
2042 int disc;
2044 /* we pass cmdiocb to state machine which needs rspiocb as well */
2045 cmdiocb->context_un.rsp_iocb = rspiocb;
2047 irsp = &(rspiocb->iocb);
2048 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2050 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2051 "ADISC cmpl: status:x%x/x%x did:x%x",
2052 irsp->ulpStatus, irsp->un.ulpWord[4],
2053 ndlp->nlp_DID);
2055 /* Since ndlp can be freed in the disc state machine, note if this node
2056 * is being used during discovery.
2058 spin_lock_irq(shost->host_lock);
2059 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
2060 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
2061 spin_unlock_irq(shost->host_lock);
2062 /* ADISC completes to NPort <nlp_DID> */
2063 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2064 "0104 ADISC completes to NPort x%x "
2065 "Data: x%x x%x x%x x%x x%x\n",
2066 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2067 irsp->ulpTimeout, disc, vport->num_disc_nodes);
2068 /* Check to see if link went down during discovery */
2069 if (lpfc_els_chk_latt(vport)) {
2070 spin_lock_irq(shost->host_lock);
2071 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2072 spin_unlock_irq(shost->host_lock);
2073 goto out;
2076 if (irsp->ulpStatus) {
2077 /* Check for retry */
2078 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
2079 /* ELS command is being retried */
2080 if (disc) {
2081 spin_lock_irq(shost->host_lock);
2082 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2083 spin_unlock_irq(shost->host_lock);
2084 lpfc_set_disctmo(vport);
2086 goto out;
2088 /* ADISC failed */
2089 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2090 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
2091 ndlp->nlp_DID, irsp->ulpStatus,
2092 irsp->un.ulpWord[4]);
2093 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2094 if (!lpfc_error_lost_link(irsp))
2095 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2096 NLP_EVT_CMPL_ADISC);
2097 } else
2098 /* Good status, call state machine */
2099 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2100 NLP_EVT_CMPL_ADISC);
2102 /* Check to see if there are more ADISCs to be sent */
2103 if (disc && vport->num_disc_nodes)
2104 lpfc_more_adisc(vport);
2105 out:
2106 lpfc_els_free_iocb(phba, cmdiocb);
2107 return;
2111 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
2112 * @vport: pointer to a virtual N_Port data structure.
2113 * @ndlp: pointer to a node-list data structure.
2114 * @retry: number of retries to the command IOCB.
2116 * This routine issues an Address Discover (ADISC) for an @ndlp on a
2117 * @vport. It prepares the payload of the ADISC ELS command, updates the
2118 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
2119 * to issue the ADISC ELS command.
2121 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2122 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2123 * will be stored into the context1 field of the IOCB for the completion
2124 * callback function to the ADISC ELS command.
2126 * Return code
2127 * 0 - successfully issued adisc
2128 * 1 - failed to issue adisc
2131 lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2132 uint8_t retry)
2134 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2135 struct lpfc_hba *phba = vport->phba;
2136 ADISC *ap;
2137 IOCB_t *icmd;
2138 struct lpfc_iocbq *elsiocb;
2139 uint8_t *pcmd;
2140 uint16_t cmdsize;
2142 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
2143 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2144 ndlp->nlp_DID, ELS_CMD_ADISC);
2145 if (!elsiocb)
2146 return 1;
2148 icmd = &elsiocb->iocb;
2149 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2151 /* For ADISC request, remainder of payload is service parameters */
2152 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
2153 pcmd += sizeof(uint32_t);
2155 /* Fill in ADISC payload */
2156 ap = (ADISC *) pcmd;
2157 ap->hardAL_PA = phba->fc_pref_ALPA;
2158 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2159 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
2160 ap->DID = be32_to_cpu(vport->fc_myDID);
2162 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2163 "Issue ADISC: did:x%x",
2164 ndlp->nlp_DID, 0, 0);
2166 phba->fc_stat.elsXmitADISC++;
2167 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
2168 spin_lock_irq(shost->host_lock);
2169 ndlp->nlp_flag |= NLP_ADISC_SND;
2170 spin_unlock_irq(shost->host_lock);
2171 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2172 IOCB_ERROR) {
2173 spin_lock_irq(shost->host_lock);
2174 ndlp->nlp_flag &= ~NLP_ADISC_SND;
2175 spin_unlock_irq(shost->host_lock);
2176 lpfc_els_free_iocb(phba, elsiocb);
2177 return 1;
2179 return 0;
2183 * lpfc_cmpl_els_logo - Completion callback function for logo
2184 * @phba: pointer to lpfc hba data structure.
2185 * @cmdiocb: pointer to lpfc command iocb data structure.
2186 * @rspiocb: pointer to lpfc response iocb data structure.
2188 * This routine is the completion function for issuing the ELS Logout (LOGO)
2189 * command. If no error status was reported from the LOGO response, the
2190 * state machine of the associated ndlp shall be invoked for transition with
2191 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
2192 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
2194 static void
2195 lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2196 struct lpfc_iocbq *rspiocb)
2198 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2199 struct lpfc_vport *vport = ndlp->vport;
2200 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2201 IOCB_t *irsp;
2202 struct lpfc_sli *psli;
2204 psli = &phba->sli;
2205 /* we pass cmdiocb to state machine which needs rspiocb as well */
2206 cmdiocb->context_un.rsp_iocb = rspiocb;
2208 irsp = &(rspiocb->iocb);
2209 spin_lock_irq(shost->host_lock);
2210 ndlp->nlp_flag &= ~NLP_LOGO_SND;
2211 spin_unlock_irq(shost->host_lock);
2213 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2214 "LOGO cmpl: status:x%x/x%x did:x%x",
2215 irsp->ulpStatus, irsp->un.ulpWord[4],
2216 ndlp->nlp_DID);
2217 /* LOGO completes to NPort <nlp_DID> */
2218 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2219 "0105 LOGO completes to NPort x%x "
2220 "Data: x%x x%x x%x x%x\n",
2221 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
2222 irsp->ulpTimeout, vport->num_disc_nodes);
2223 /* Check to see if link went down during discovery */
2224 if (lpfc_els_chk_latt(vport))
2225 goto out;
2227 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
2228 /* NLP_EVT_DEVICE_RM should unregister the RPI
2229 * which should abort all outstanding IOs.
2231 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2232 NLP_EVT_DEVICE_RM);
2233 goto out;
2236 if (irsp->ulpStatus) {
2237 /* Check for retry */
2238 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
2239 /* ELS command is being retried */
2240 goto out;
2241 /* LOGO failed */
2242 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2243 "2756 LOGO failure DID:%06X Status:x%x/x%x\n",
2244 ndlp->nlp_DID, irsp->ulpStatus,
2245 irsp->un.ulpWord[4]);
2246 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2247 if (lpfc_error_lost_link(irsp))
2248 goto out;
2249 else
2250 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2251 NLP_EVT_CMPL_LOGO);
2252 } else
2253 /* Good status, call state machine.
2254 * This will unregister the rpi if needed.
2256 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2257 NLP_EVT_CMPL_LOGO);
2258 out:
2259 lpfc_els_free_iocb(phba, cmdiocb);
2260 return;
2264 * lpfc_issue_els_logo - Issue a logo to an node on a vport
2265 * @vport: pointer to a virtual N_Port data structure.
2266 * @ndlp: pointer to a node-list data structure.
2267 * @retry: number of retries to the command IOCB.
2269 * This routine constructs and issues an ELS Logout (LOGO) iocb command
2270 * to a remote node, referred by an @ndlp on a @vport. It constructs the
2271 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2272 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2274 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2275 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2276 * will be stored into the context1 field of the IOCB for the completion
2277 * callback function to the LOGO ELS command.
2279 * Return code
2280 * 0 - successfully issued logo
2281 * 1 - failed to issue logo
2284 lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2285 uint8_t retry)
2287 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2288 struct lpfc_hba *phba = vport->phba;
2289 IOCB_t *icmd;
2290 struct lpfc_iocbq *elsiocb;
2291 uint8_t *pcmd;
2292 uint16_t cmdsize;
2293 int rc;
2295 spin_lock_irq(shost->host_lock);
2296 if (ndlp->nlp_flag & NLP_LOGO_SND) {
2297 spin_unlock_irq(shost->host_lock);
2298 return 0;
2300 spin_unlock_irq(shost->host_lock);
2302 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
2303 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2304 ndlp->nlp_DID, ELS_CMD_LOGO);
2305 if (!elsiocb)
2306 return 1;
2308 icmd = &elsiocb->iocb;
2309 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2310 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
2311 pcmd += sizeof(uint32_t);
2313 /* Fill in LOGO payload */
2314 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
2315 pcmd += sizeof(uint32_t);
2316 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
2318 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2319 "Issue LOGO: did:x%x",
2320 ndlp->nlp_DID, 0, 0);
2322 phba->fc_stat.elsXmitLOGO++;
2323 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
2324 spin_lock_irq(shost->host_lock);
2325 ndlp->nlp_flag |= NLP_LOGO_SND;
2326 spin_unlock_irq(shost->host_lock);
2327 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
2329 if (rc == IOCB_ERROR) {
2330 spin_lock_irq(shost->host_lock);
2331 ndlp->nlp_flag &= ~NLP_LOGO_SND;
2332 spin_unlock_irq(shost->host_lock);
2333 lpfc_els_free_iocb(phba, elsiocb);
2334 return 1;
2336 return 0;
2340 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
2341 * @phba: pointer to lpfc hba data structure.
2342 * @cmdiocb: pointer to lpfc command iocb data structure.
2343 * @rspiocb: pointer to lpfc response iocb data structure.
2345 * This routine is a generic completion callback function for ELS commands.
2346 * Specifically, it is the callback function which does not need to perform
2347 * any command specific operations. It is currently used by the ELS command
2348 * issuing routines for the ELS State Change Request (SCR),
2349 * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
2350 * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
2351 * certain debug loggings, this callback function simply invokes the
2352 * lpfc_els_chk_latt() routine to check whether link went down during the
2353 * discovery process.
2355 static void
2356 lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2357 struct lpfc_iocbq *rspiocb)
2359 struct lpfc_vport *vport = cmdiocb->vport;
2360 IOCB_t *irsp;
2362 irsp = &rspiocb->iocb;
2364 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2365 "ELS cmd cmpl: status:x%x/x%x did:x%x",
2366 irsp->ulpStatus, irsp->un.ulpWord[4],
2367 irsp->un.elsreq64.remoteID);
2368 /* ELS cmd tag <ulpIoTag> completes */
2369 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2370 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
2371 irsp->ulpIoTag, irsp->ulpStatus,
2372 irsp->un.ulpWord[4], irsp->ulpTimeout);
2373 /* Check to see if link went down during discovery */
2374 lpfc_els_chk_latt(vport);
2375 lpfc_els_free_iocb(phba, cmdiocb);
2376 return;
2380 * lpfc_issue_els_scr - Issue a scr to an node on a vport
2381 * @vport: pointer to a host virtual N_Port data structure.
2382 * @nportid: N_Port identifier to the remote node.
2383 * @retry: number of retries to the command IOCB.
2385 * This routine issues a State Change Request (SCR) to a fabric node
2386 * on a @vport. The remote node @nportid is passed into the function. It
2387 * first search the @vport node list to find the matching ndlp. If no such
2388 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
2389 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
2390 * routine is invoked to send the SCR IOCB.
2392 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2393 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2394 * will be stored into the context1 field of the IOCB for the completion
2395 * callback function to the SCR ELS command.
2397 * Return code
2398 * 0 - Successfully issued scr command
2399 * 1 - Failed to issue scr command
2402 lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
2404 struct lpfc_hba *phba = vport->phba;
2405 IOCB_t *icmd;
2406 struct lpfc_iocbq *elsiocb;
2407 struct lpfc_sli *psli;
2408 uint8_t *pcmd;
2409 uint16_t cmdsize;
2410 struct lpfc_nodelist *ndlp;
2412 psli = &phba->sli;
2413 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
2415 ndlp = lpfc_findnode_did(vport, nportid);
2416 if (!ndlp) {
2417 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2418 if (!ndlp)
2419 return 1;
2420 lpfc_nlp_init(vport, ndlp, nportid);
2421 lpfc_enqueue_node(vport, ndlp);
2422 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2423 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2424 if (!ndlp)
2425 return 1;
2428 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2429 ndlp->nlp_DID, ELS_CMD_SCR);
2431 if (!elsiocb) {
2432 /* This will trigger the release of the node just
2433 * allocated
2435 lpfc_nlp_put(ndlp);
2436 return 1;
2439 icmd = &elsiocb->iocb;
2440 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2442 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
2443 pcmd += sizeof(uint32_t);
2445 /* For SCR, remainder of payload is SCR parameter page */
2446 memset(pcmd, 0, sizeof(SCR));
2447 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
2449 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2450 "Issue SCR: did:x%x",
2451 ndlp->nlp_DID, 0, 0);
2453 phba->fc_stat.elsXmitSCR++;
2454 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
2455 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2456 IOCB_ERROR) {
2457 /* The additional lpfc_nlp_put will cause the following
2458 * lpfc_els_free_iocb routine to trigger the rlease of
2459 * the node.
2461 lpfc_nlp_put(ndlp);
2462 lpfc_els_free_iocb(phba, elsiocb);
2463 return 1;
2465 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2466 * trigger the release of node.
2468 lpfc_nlp_put(ndlp);
2469 return 0;
2473 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
2474 * @vport: pointer to a host virtual N_Port data structure.
2475 * @nportid: N_Port identifier to the remote node.
2476 * @retry: number of retries to the command IOCB.
2478 * This routine issues a Fibre Channel Address Resolution Response
2479 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
2480 * is passed into the function. It first search the @vport node list to find
2481 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
2482 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
2483 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
2485 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2486 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2487 * will be stored into the context1 field of the IOCB for the completion
2488 * callback function to the PARPR ELS command.
2490 * Return code
2491 * 0 - Successfully issued farpr command
2492 * 1 - Failed to issue farpr command
2494 static int
2495 lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
2497 struct lpfc_hba *phba = vport->phba;
2498 IOCB_t *icmd;
2499 struct lpfc_iocbq *elsiocb;
2500 struct lpfc_sli *psli;
2501 FARP *fp;
2502 uint8_t *pcmd;
2503 uint32_t *lp;
2504 uint16_t cmdsize;
2505 struct lpfc_nodelist *ondlp;
2506 struct lpfc_nodelist *ndlp;
2508 psli = &phba->sli;
2509 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
2511 ndlp = lpfc_findnode_did(vport, nportid);
2512 if (!ndlp) {
2513 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2514 if (!ndlp)
2515 return 1;
2516 lpfc_nlp_init(vport, ndlp, nportid);
2517 lpfc_enqueue_node(vport, ndlp);
2518 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2519 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2520 if (!ndlp)
2521 return 1;
2524 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2525 ndlp->nlp_DID, ELS_CMD_RNID);
2526 if (!elsiocb) {
2527 /* This will trigger the release of the node just
2528 * allocated
2530 lpfc_nlp_put(ndlp);
2531 return 1;
2534 icmd = &elsiocb->iocb;
2535 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2537 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
2538 pcmd += sizeof(uint32_t);
2540 /* Fill in FARPR payload */
2541 fp = (FARP *) (pcmd);
2542 memset(fp, 0, sizeof(FARP));
2543 lp = (uint32_t *) pcmd;
2544 *lp++ = be32_to_cpu(nportid);
2545 *lp++ = be32_to_cpu(vport->fc_myDID);
2546 fp->Rflags = 0;
2547 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
2549 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
2550 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
2551 ondlp = lpfc_findnode_did(vport, nportid);
2552 if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
2553 memcpy(&fp->OportName, &ondlp->nlp_portname,
2554 sizeof(struct lpfc_name));
2555 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
2556 sizeof(struct lpfc_name));
2559 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2560 "Issue FARPR: did:x%x",
2561 ndlp->nlp_DID, 0, 0);
2563 phba->fc_stat.elsXmitFARPR++;
2564 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
2565 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2566 IOCB_ERROR) {
2567 /* The additional lpfc_nlp_put will cause the following
2568 * lpfc_els_free_iocb routine to trigger the release of
2569 * the node.
2571 lpfc_nlp_put(ndlp);
2572 lpfc_els_free_iocb(phba, elsiocb);
2573 return 1;
2575 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2576 * trigger the release of the node.
2578 lpfc_nlp_put(ndlp);
2579 return 0;
2583 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
2584 * @vport: pointer to a host virtual N_Port data structure.
2585 * @nlp: pointer to a node-list data structure.
2587 * This routine cancels the timer with a delayed IOCB-command retry for
2588 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
2589 * removes the ELS retry event if it presents. In addition, if the
2590 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
2591 * commands are sent for the @vport's nodes that require issuing discovery
2592 * ADISC.
2594 void
2595 lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
2597 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2598 struct lpfc_work_evt *evtp;
2600 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
2601 return;
2602 spin_lock_irq(shost->host_lock);
2603 nlp->nlp_flag &= ~NLP_DELAY_TMO;
2604 spin_unlock_irq(shost->host_lock);
2605 del_timer_sync(&nlp->nlp_delayfunc);
2606 nlp->nlp_last_elscmd = 0;
2607 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
2608 list_del_init(&nlp->els_retry_evt.evt_listp);
2609 /* Decrement nlp reference count held for the delayed retry */
2610 evtp = &nlp->els_retry_evt;
2611 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
2613 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
2614 spin_lock_irq(shost->host_lock);
2615 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
2616 spin_unlock_irq(shost->host_lock);
2617 if (vport->num_disc_nodes) {
2618 if (vport->port_state < LPFC_VPORT_READY) {
2619 /* Check if there are more ADISCs to be sent */
2620 lpfc_more_adisc(vport);
2621 } else {
2622 /* Check if there are more PLOGIs to be sent */
2623 lpfc_more_plogi(vport);
2624 if (vport->num_disc_nodes == 0) {
2625 spin_lock_irq(shost->host_lock);
2626 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2627 spin_unlock_irq(shost->host_lock);
2628 lpfc_can_disctmo(vport);
2629 lpfc_end_rscn(vport);
2634 return;
2638 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
2639 * @ptr: holder for the pointer to the timer function associated data (ndlp).
2641 * This routine is invoked by the ndlp delayed-function timer to check
2642 * whether there is any pending ELS retry event(s) with the node. If not, it
2643 * simply returns. Otherwise, if there is at least one ELS delayed event, it
2644 * adds the delayed events to the HBA work list and invokes the
2645 * lpfc_worker_wake_up() routine to wake up worker thread to process the
2646 * event. Note that lpfc_nlp_get() is called before posting the event to
2647 * the work list to hold reference count of ndlp so that it guarantees the
2648 * reference to ndlp will still be available when the worker thread gets
2649 * to the event associated with the ndlp.
2651 void
2652 lpfc_els_retry_delay(unsigned long ptr)
2654 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
2655 struct lpfc_vport *vport = ndlp->vport;
2656 struct lpfc_hba *phba = vport->phba;
2657 unsigned long flags;
2658 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
2660 spin_lock_irqsave(&phba->hbalock, flags);
2661 if (!list_empty(&evtp->evt_listp)) {
2662 spin_unlock_irqrestore(&phba->hbalock, flags);
2663 return;
2666 /* We need to hold the node by incrementing the reference
2667 * count until the queued work is done
2669 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
2670 if (evtp->evt_arg1) {
2671 evtp->evt = LPFC_EVT_ELS_RETRY;
2672 list_add_tail(&evtp->evt_listp, &phba->work_list);
2673 lpfc_worker_wake_up(phba);
2675 spin_unlock_irqrestore(&phba->hbalock, flags);
2676 return;
2680 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
2681 * @ndlp: pointer to a node-list data structure.
2683 * This routine is the worker-thread handler for processing the @ndlp delayed
2684 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
2685 * the last ELS command from the associated ndlp and invokes the proper ELS
2686 * function according to the delayed ELS command to retry the command.
2688 void
2689 lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
2691 struct lpfc_vport *vport = ndlp->vport;
2692 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2693 uint32_t cmd, did, retry;
2695 spin_lock_irq(shost->host_lock);
2696 did = ndlp->nlp_DID;
2697 cmd = ndlp->nlp_last_elscmd;
2698 ndlp->nlp_last_elscmd = 0;
2700 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
2701 spin_unlock_irq(shost->host_lock);
2702 return;
2705 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
2706 spin_unlock_irq(shost->host_lock);
2708 * If a discovery event readded nlp_delayfunc after timer
2709 * firing and before processing the timer, cancel the
2710 * nlp_delayfunc.
2712 del_timer_sync(&ndlp->nlp_delayfunc);
2713 retry = ndlp->nlp_retry;
2714 ndlp->nlp_retry = 0;
2716 switch (cmd) {
2717 case ELS_CMD_FLOGI:
2718 lpfc_issue_els_flogi(vport, ndlp, retry);
2719 break;
2720 case ELS_CMD_PLOGI:
2721 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
2722 ndlp->nlp_prev_state = ndlp->nlp_state;
2723 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2725 break;
2726 case ELS_CMD_ADISC:
2727 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
2728 ndlp->nlp_prev_state = ndlp->nlp_state;
2729 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2731 break;
2732 case ELS_CMD_PRLI:
2733 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
2734 ndlp->nlp_prev_state = ndlp->nlp_state;
2735 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
2737 break;
2738 case ELS_CMD_LOGO:
2739 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
2740 ndlp->nlp_prev_state = ndlp->nlp_state;
2741 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2743 break;
2744 case ELS_CMD_FDISC:
2745 lpfc_issue_els_fdisc(vport, ndlp, retry);
2746 break;
2748 return;
2752 * lpfc_els_retry - Make retry decision on an els command iocb
2753 * @phba: pointer to lpfc hba data structure.
2754 * @cmdiocb: pointer to lpfc command iocb data structure.
2755 * @rspiocb: pointer to lpfc response iocb data structure.
2757 * This routine makes a retry decision on an ELS command IOCB, which has
2758 * failed. The following ELS IOCBs use this function for retrying the command
2759 * when previously issued command responsed with error status: FLOGI, PLOGI,
2760 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
2761 * returned error status, it makes the decision whether a retry shall be
2762 * issued for the command, and whether a retry shall be made immediately or
2763 * delayed. In the former case, the corresponding ELS command issuing-function
2764 * is called to retry the command. In the later case, the ELS command shall
2765 * be posted to the ndlp delayed event and delayed function timer set to the
2766 * ndlp for the delayed command issusing.
2768 * Return code
2769 * 0 - No retry of els command is made
2770 * 1 - Immediate or delayed retry of els command is made
2772 static int
2773 lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2774 struct lpfc_iocbq *rspiocb)
2776 struct lpfc_vport *vport = cmdiocb->vport;
2777 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2778 IOCB_t *irsp = &rspiocb->iocb;
2779 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2780 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2781 uint32_t *elscmd;
2782 struct ls_rjt stat;
2783 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
2784 int logerr = 0;
2785 uint32_t cmd = 0;
2786 uint32_t did;
2789 /* Note: context2 may be 0 for internal driver abort
2790 * of delays ELS command.
2793 if (pcmd && pcmd->virt) {
2794 elscmd = (uint32_t *) (pcmd->virt);
2795 cmd = *elscmd++;
2798 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
2799 did = ndlp->nlp_DID;
2800 else {
2801 /* We should only hit this case for retrying PLOGI */
2802 did = irsp->un.elsreq64.remoteID;
2803 ndlp = lpfc_findnode_did(vport, did);
2804 if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
2805 && (cmd != ELS_CMD_PLOGI))
2806 return 1;
2809 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2810 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
2811 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
2813 switch (irsp->ulpStatus) {
2814 case IOSTAT_FCP_RSP_ERROR:
2815 case IOSTAT_REMOTE_STOP:
2816 break;
2818 case IOSTAT_LOCAL_REJECT:
2819 switch ((irsp->un.ulpWord[4] & 0xff)) {
2820 case IOERR_LOOP_OPEN_FAILURE:
2821 if (cmd == ELS_CMD_FLOGI) {
2822 if (PCI_DEVICE_ID_HORNET ==
2823 phba->pcidev->device) {
2824 phba->fc_topology = LPFC_TOPOLOGY_LOOP;
2825 phba->pport->fc_myDID = 0;
2826 phba->alpa_map[0] = 0;
2827 phba->alpa_map[1] = 0;
2830 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
2831 delay = 1000;
2832 retry = 1;
2833 break;
2835 case IOERR_ILLEGAL_COMMAND:
2836 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2837 "0124 Retry illegal cmd x%x "
2838 "retry:x%x delay:x%x\n",
2839 cmd, cmdiocb->retry, delay);
2840 retry = 1;
2841 /* All command's retry policy */
2842 maxretry = 8;
2843 if (cmdiocb->retry > 2)
2844 delay = 1000;
2845 break;
2847 case IOERR_NO_RESOURCES:
2848 logerr = 1; /* HBA out of resources */
2849 retry = 1;
2850 if (cmdiocb->retry > 100)
2851 delay = 100;
2852 maxretry = 250;
2853 break;
2855 case IOERR_ILLEGAL_FRAME:
2856 delay = 100;
2857 retry = 1;
2858 break;
2860 case IOERR_SEQUENCE_TIMEOUT:
2861 case IOERR_INVALID_RPI:
2862 retry = 1;
2863 break;
2865 break;
2867 case IOSTAT_NPORT_RJT:
2868 case IOSTAT_FABRIC_RJT:
2869 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
2870 retry = 1;
2871 break;
2873 break;
2875 case IOSTAT_NPORT_BSY:
2876 case IOSTAT_FABRIC_BSY:
2877 logerr = 1; /* Fabric / Remote NPort out of resources */
2878 retry = 1;
2879 break;
2881 case IOSTAT_LS_RJT:
2882 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
2883 /* Added for Vendor specifc support
2884 * Just keep retrying for these Rsn / Exp codes
2886 switch (stat.un.b.lsRjtRsnCode) {
2887 case LSRJT_UNABLE_TPC:
2888 if (stat.un.b.lsRjtRsnCodeExp ==
2889 LSEXP_CMD_IN_PROGRESS) {
2890 if (cmd == ELS_CMD_PLOGI) {
2891 delay = 1000;
2892 maxretry = 48;
2894 retry = 1;
2895 break;
2897 if (stat.un.b.lsRjtRsnCodeExp ==
2898 LSEXP_CANT_GIVE_DATA) {
2899 if (cmd == ELS_CMD_PLOGI) {
2900 delay = 1000;
2901 maxretry = 48;
2903 retry = 1;
2904 break;
2906 if (cmd == ELS_CMD_PLOGI) {
2907 delay = 1000;
2908 maxretry = lpfc_max_els_tries + 1;
2909 retry = 1;
2910 break;
2912 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2913 (cmd == ELS_CMD_FDISC) &&
2914 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
2915 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2916 "0125 FDISC Failed (x%x). "
2917 "Fabric out of resources\n",
2918 stat.un.lsRjtError);
2919 lpfc_vport_set_state(vport,
2920 FC_VPORT_NO_FABRIC_RSCS);
2922 break;
2924 case LSRJT_LOGICAL_BSY:
2925 if ((cmd == ELS_CMD_PLOGI) ||
2926 (cmd == ELS_CMD_PRLI)) {
2927 delay = 1000;
2928 maxretry = 48;
2929 } else if (cmd == ELS_CMD_FDISC) {
2930 /* FDISC retry policy */
2931 maxretry = 48;
2932 if (cmdiocb->retry >= 32)
2933 delay = 1000;
2935 retry = 1;
2936 break;
2938 case LSRJT_LOGICAL_ERR:
2939 /* There are some cases where switches return this
2940 * error when they are not ready and should be returning
2941 * Logical Busy. We should delay every time.
2943 if (cmd == ELS_CMD_FDISC &&
2944 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
2945 maxretry = 3;
2946 delay = 1000;
2947 retry = 1;
2948 break;
2950 case LSRJT_PROTOCOL_ERR:
2951 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2952 (cmd == ELS_CMD_FDISC) &&
2953 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
2954 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
2956 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2957 "0122 FDISC Failed (x%x). "
2958 "Fabric Detected Bad WWN\n",
2959 stat.un.lsRjtError);
2960 lpfc_vport_set_state(vport,
2961 FC_VPORT_FABRIC_REJ_WWN);
2963 break;
2965 break;
2967 case IOSTAT_INTERMED_RSP:
2968 case IOSTAT_BA_RJT:
2969 break;
2971 default:
2972 break;
2975 if (did == FDMI_DID)
2976 retry = 1;
2978 if (((cmd == ELS_CMD_FLOGI) || (cmd == ELS_CMD_FDISC)) &&
2979 (phba->fc_topology != LPFC_TOPOLOGY_LOOP) &&
2980 !lpfc_error_lost_link(irsp)) {
2981 /* FLOGI retry policy */
2982 retry = 1;
2983 /* retry forever */
2984 maxretry = 0;
2985 if (cmdiocb->retry >= 100)
2986 delay = 5000;
2987 else if (cmdiocb->retry >= 32)
2988 delay = 1000;
2991 cmdiocb->retry++;
2992 if (maxretry && (cmdiocb->retry >= maxretry)) {
2993 phba->fc_stat.elsRetryExceeded++;
2994 retry = 0;
2997 if ((vport->load_flag & FC_UNLOADING) != 0)
2998 retry = 0;
3000 if (retry) {
3001 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_FDISC)) {
3002 /* Stop retrying PLOGI and FDISC if in FCF discovery */
3003 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
3004 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3005 "2849 Stop retry ELS command "
3006 "x%x to remote NPORT x%x, "
3007 "Data: x%x x%x\n", cmd, did,
3008 cmdiocb->retry, delay);
3009 return 0;
3013 /* Retry ELS command <elsCmd> to remote NPORT <did> */
3014 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3015 "0107 Retry ELS command x%x to remote "
3016 "NPORT x%x Data: x%x x%x\n",
3017 cmd, did, cmdiocb->retry, delay);
3019 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
3020 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
3021 ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) {
3022 /* Don't reset timer for no resources */
3024 /* If discovery / RSCN timer is running, reset it */
3025 if (timer_pending(&vport->fc_disctmo) ||
3026 (vport->fc_flag & FC_RSCN_MODE))
3027 lpfc_set_disctmo(vport);
3030 phba->fc_stat.elsXmitRetry++;
3031 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
3032 phba->fc_stat.elsDelayRetry++;
3033 ndlp->nlp_retry = cmdiocb->retry;
3035 /* delay is specified in milliseconds */
3036 mod_timer(&ndlp->nlp_delayfunc,
3037 jiffies + msecs_to_jiffies(delay));
3038 spin_lock_irq(shost->host_lock);
3039 ndlp->nlp_flag |= NLP_DELAY_TMO;
3040 spin_unlock_irq(shost->host_lock);
3042 ndlp->nlp_prev_state = ndlp->nlp_state;
3043 if (cmd == ELS_CMD_PRLI)
3044 lpfc_nlp_set_state(vport, ndlp,
3045 NLP_STE_REG_LOGIN_ISSUE);
3046 else
3047 lpfc_nlp_set_state(vport, ndlp,
3048 NLP_STE_NPR_NODE);
3049 ndlp->nlp_last_elscmd = cmd;
3051 return 1;
3053 switch (cmd) {
3054 case ELS_CMD_FLOGI:
3055 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
3056 return 1;
3057 case ELS_CMD_FDISC:
3058 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
3059 return 1;
3060 case ELS_CMD_PLOGI:
3061 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
3062 ndlp->nlp_prev_state = ndlp->nlp_state;
3063 lpfc_nlp_set_state(vport, ndlp,
3064 NLP_STE_PLOGI_ISSUE);
3066 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
3067 return 1;
3068 case ELS_CMD_ADISC:
3069 ndlp->nlp_prev_state = ndlp->nlp_state;
3070 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3071 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
3072 return 1;
3073 case ELS_CMD_PRLI:
3074 ndlp->nlp_prev_state = ndlp->nlp_state;
3075 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
3076 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
3077 return 1;
3078 case ELS_CMD_LOGO:
3079 ndlp->nlp_prev_state = ndlp->nlp_state;
3080 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
3081 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
3082 return 1;
3085 /* No retry ELS command <elsCmd> to remote NPORT <did> */
3086 if (logerr) {
3087 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3088 "0137 No retry ELS command x%x to remote "
3089 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
3090 cmd, did, irsp->ulpStatus,
3091 irsp->un.ulpWord[4]);
3093 else {
3094 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3095 "0108 No retry ELS command x%x to remote "
3096 "NPORT x%x Retried:%d Error:x%x/%x\n",
3097 cmd, did, cmdiocb->retry, irsp->ulpStatus,
3098 irsp->un.ulpWord[4]);
3100 return 0;
3104 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
3105 * @phba: pointer to lpfc hba data structure.
3106 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
3108 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
3109 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
3110 * checks to see whether there is a lpfc DMA buffer associated with the
3111 * response of the command IOCB. If so, it will be released before releasing
3112 * the lpfc DMA buffer associated with the IOCB itself.
3114 * Return code
3115 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3117 static int
3118 lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
3120 struct lpfc_dmabuf *buf_ptr;
3122 /* Free the response before processing the command. */
3123 if (!list_empty(&buf_ptr1->list)) {
3124 list_remove_head(&buf_ptr1->list, buf_ptr,
3125 struct lpfc_dmabuf,
3126 list);
3127 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3128 kfree(buf_ptr);
3130 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
3131 kfree(buf_ptr1);
3132 return 0;
3136 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
3137 * @phba: pointer to lpfc hba data structure.
3138 * @buf_ptr: pointer to the lpfc dma buffer data structure.
3140 * This routine releases the lpfc Direct Memory Access (DMA) buffer
3141 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
3142 * pool.
3144 * Return code
3145 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3147 static int
3148 lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
3150 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
3151 kfree(buf_ptr);
3152 return 0;
3156 * lpfc_els_free_iocb - Free a command iocb and its associated resources
3157 * @phba: pointer to lpfc hba data structure.
3158 * @elsiocb: pointer to lpfc els command iocb data structure.
3160 * This routine frees a command IOCB and its associated resources. The
3161 * command IOCB data structure contains the reference to various associated
3162 * resources, these fields must be set to NULL if the associated reference
3163 * not present:
3164 * context1 - reference to ndlp
3165 * context2 - reference to cmd
3166 * context2->next - reference to rsp
3167 * context3 - reference to bpl
3169 * It first properly decrements the reference count held on ndlp for the
3170 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
3171 * set, it invokes the lpfc_els_free_data() routine to release the Direct
3172 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
3173 * adds the DMA buffer the @phba data structure for the delayed release.
3174 * If reference to the Buffer Pointer List (BPL) is present, the
3175 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
3176 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
3177 * invoked to release the IOCB data structure back to @phba IOCBQ list.
3179 * Return code
3180 * 0 - Success (currently, always return 0)
3183 lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
3185 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
3186 struct lpfc_nodelist *ndlp;
3188 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
3189 if (ndlp) {
3190 if (ndlp->nlp_flag & NLP_DEFER_RM) {
3191 lpfc_nlp_put(ndlp);
3193 /* If the ndlp is not being used by another discovery
3194 * thread, free it.
3196 if (!lpfc_nlp_not_used(ndlp)) {
3197 /* If ndlp is being used by another discovery
3198 * thread, just clear NLP_DEFER_RM
3200 ndlp->nlp_flag &= ~NLP_DEFER_RM;
3203 else
3204 lpfc_nlp_put(ndlp);
3205 elsiocb->context1 = NULL;
3207 /* context2 = cmd, context2->next = rsp, context3 = bpl */
3208 if (elsiocb->context2) {
3209 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
3210 /* Firmware could still be in progress of DMAing
3211 * payload, so don't free data buffer till after
3212 * a hbeat.
3214 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
3215 buf_ptr = elsiocb->context2;
3216 elsiocb->context2 = NULL;
3217 if (buf_ptr) {
3218 buf_ptr1 = NULL;
3219 spin_lock_irq(&phba->hbalock);
3220 if (!list_empty(&buf_ptr->list)) {
3221 list_remove_head(&buf_ptr->list,
3222 buf_ptr1, struct lpfc_dmabuf,
3223 list);
3224 INIT_LIST_HEAD(&buf_ptr1->list);
3225 list_add_tail(&buf_ptr1->list,
3226 &phba->elsbuf);
3227 phba->elsbuf_cnt++;
3229 INIT_LIST_HEAD(&buf_ptr->list);
3230 list_add_tail(&buf_ptr->list, &phba->elsbuf);
3231 phba->elsbuf_cnt++;
3232 spin_unlock_irq(&phba->hbalock);
3234 } else {
3235 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
3236 lpfc_els_free_data(phba, buf_ptr1);
3240 if (elsiocb->context3) {
3241 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
3242 lpfc_els_free_bpl(phba, buf_ptr);
3244 lpfc_sli_release_iocbq(phba, elsiocb);
3245 return 0;
3249 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
3250 * @phba: pointer to lpfc hba data structure.
3251 * @cmdiocb: pointer to lpfc command iocb data structure.
3252 * @rspiocb: pointer to lpfc response iocb data structure.
3254 * This routine is the completion callback function to the Logout (LOGO)
3255 * Accept (ACC) Response ELS command. This routine is invoked to indicate
3256 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
3257 * release the ndlp if it has the last reference remaining (reference count
3258 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
3259 * field to NULL to inform the following lpfc_els_free_iocb() routine no
3260 * ndlp reference count needs to be decremented. Otherwise, the ndlp
3261 * reference use-count shall be decremented by the lpfc_els_free_iocb()
3262 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
3263 * IOCB data structure.
3265 static void
3266 lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3267 struct lpfc_iocbq *rspiocb)
3269 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3270 struct lpfc_vport *vport = cmdiocb->vport;
3271 IOCB_t *irsp;
3273 irsp = &rspiocb->iocb;
3274 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3275 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
3276 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
3277 /* ACC to LOGO completes to NPort <nlp_DID> */
3278 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3279 "0109 ACC to LOGO completes to NPort x%x "
3280 "Data: x%x x%x x%x\n",
3281 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3282 ndlp->nlp_rpi);
3284 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
3285 /* NPort Recovery mode or node is just allocated */
3286 if (!lpfc_nlp_not_used(ndlp)) {
3287 /* If the ndlp is being used by another discovery
3288 * thread, just unregister the RPI.
3290 lpfc_unreg_rpi(vport, ndlp);
3291 } else {
3292 /* Indicate the node has already released, should
3293 * not reference to it from within lpfc_els_free_iocb.
3295 cmdiocb->context1 = NULL;
3298 lpfc_els_free_iocb(phba, cmdiocb);
3299 return;
3303 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
3304 * @phba: pointer to lpfc hba data structure.
3305 * @pmb: pointer to the driver internal queue element for mailbox command.
3307 * This routine is the completion callback function for unregister default
3308 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
3309 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
3310 * decrements the ndlp reference count held for this completion callback
3311 * function. After that, it invokes the lpfc_nlp_not_used() to check
3312 * whether there is only one reference left on the ndlp. If so, it will
3313 * perform one more decrement and trigger the release of the ndlp.
3315 void
3316 lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3318 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3319 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
3322 * This routine is used to register and unregister in previous SLI
3323 * modes.
3325 if ((pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) &&
3326 (phba->sli_rev == LPFC_SLI_REV4))
3327 lpfc_sli4_free_rpi(phba, pmb->u.mb.un.varUnregLogin.rpi);
3329 pmb->context1 = NULL;
3330 pmb->context2 = NULL;
3332 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3333 kfree(mp);
3334 mempool_free(pmb, phba->mbox_mem_pool);
3335 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
3336 lpfc_nlp_put(ndlp);
3337 /* This is the end of the default RPI cleanup logic for this
3338 * ndlp. If no other discovery threads are using this ndlp.
3339 * we should free all resources associated with it.
3341 lpfc_nlp_not_used(ndlp);
3344 return;
3348 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
3349 * @phba: pointer to lpfc hba data structure.
3350 * @cmdiocb: pointer to lpfc command iocb data structure.
3351 * @rspiocb: pointer to lpfc response iocb data structure.
3353 * This routine is the completion callback function for ELS Response IOCB
3354 * command. In normal case, this callback function just properly sets the
3355 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
3356 * field in the command IOCB is not NULL, the referred mailbox command will
3357 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
3358 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
3359 * link down event occurred during the discovery, the lpfc_nlp_not_used()
3360 * routine shall be invoked trying to release the ndlp if no other threads
3361 * are currently referring it.
3363 static void
3364 lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3365 struct lpfc_iocbq *rspiocb)
3367 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3368 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
3369 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
3370 IOCB_t *irsp;
3371 uint8_t *pcmd;
3372 LPFC_MBOXQ_t *mbox = NULL;
3373 struct lpfc_dmabuf *mp = NULL;
3374 uint32_t ls_rjt = 0;
3376 irsp = &rspiocb->iocb;
3378 if (cmdiocb->context_un.mbox)
3379 mbox = cmdiocb->context_un.mbox;
3381 /* First determine if this is a LS_RJT cmpl. Note, this callback
3382 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
3384 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
3385 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3386 (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
3387 /* A LS_RJT associated with Default RPI cleanup has its own
3388 * separate code path.
3390 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
3391 ls_rjt = 1;
3394 /* Check to see if link went down during discovery */
3395 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
3396 if (mbox) {
3397 mp = (struct lpfc_dmabuf *) mbox->context1;
3398 if (mp) {
3399 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3400 kfree(mp);
3402 mempool_free(mbox, phba->mbox_mem_pool);
3404 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3405 (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
3406 if (lpfc_nlp_not_used(ndlp)) {
3407 ndlp = NULL;
3408 /* Indicate the node has already released,
3409 * should not reference to it from within
3410 * the routine lpfc_els_free_iocb.
3412 cmdiocb->context1 = NULL;
3414 goto out;
3417 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3418 "ELS rsp cmpl: status:x%x/x%x did:x%x",
3419 irsp->ulpStatus, irsp->un.ulpWord[4],
3420 cmdiocb->iocb.un.elsreq64.remoteID);
3421 /* ELS response tag <ulpIoTag> completes */
3422 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3423 "0110 ELS response tag x%x completes "
3424 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
3425 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
3426 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
3427 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3428 ndlp->nlp_rpi);
3429 if (mbox) {
3430 if ((rspiocb->iocb.ulpStatus == 0)
3431 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
3432 lpfc_unreg_rpi(vport, ndlp);
3433 /* Increment reference count to ndlp to hold the
3434 * reference to ndlp for the callback function.
3436 mbox->context2 = lpfc_nlp_get(ndlp);
3437 mbox->vport = vport;
3438 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
3439 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
3440 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
3442 else {
3443 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
3444 ndlp->nlp_prev_state = ndlp->nlp_state;
3445 lpfc_nlp_set_state(vport, ndlp,
3446 NLP_STE_REG_LOGIN_ISSUE);
3448 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
3449 != MBX_NOT_FINISHED)
3450 goto out;
3451 else
3452 /* Decrement the ndlp reference count we
3453 * set for this failed mailbox command.
3455 lpfc_nlp_put(ndlp);
3457 /* ELS rsp: Cannot issue reg_login for <NPortid> */
3458 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3459 "0138 ELS rsp: Cannot issue reg_login for x%x "
3460 "Data: x%x x%x x%x\n",
3461 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3462 ndlp->nlp_rpi);
3464 if (lpfc_nlp_not_used(ndlp)) {
3465 ndlp = NULL;
3466 /* Indicate node has already been released,
3467 * should not reference to it from within
3468 * the routine lpfc_els_free_iocb.
3470 cmdiocb->context1 = NULL;
3472 } else {
3473 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
3474 if (!lpfc_error_lost_link(irsp) &&
3475 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
3476 if (lpfc_nlp_not_used(ndlp)) {
3477 ndlp = NULL;
3478 /* Indicate node has already been
3479 * released, should not reference
3480 * to it from within the routine
3481 * lpfc_els_free_iocb.
3483 cmdiocb->context1 = NULL;
3487 mp = (struct lpfc_dmabuf *) mbox->context1;
3488 if (mp) {
3489 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3490 kfree(mp);
3492 mempool_free(mbox, phba->mbox_mem_pool);
3494 out:
3495 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
3496 spin_lock_irq(shost->host_lock);
3497 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
3498 spin_unlock_irq(shost->host_lock);
3500 /* If the node is not being used by another discovery thread,
3501 * and we are sending a reject, we are done with it.
3502 * Release driver reference count here and free associated
3503 * resources.
3505 if (ls_rjt)
3506 if (lpfc_nlp_not_used(ndlp))
3507 /* Indicate node has already been released,
3508 * should not reference to it from within
3509 * the routine lpfc_els_free_iocb.
3511 cmdiocb->context1 = NULL;
3514 lpfc_els_free_iocb(phba, cmdiocb);
3515 return;
3519 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
3520 * @vport: pointer to a host virtual N_Port data structure.
3521 * @flag: the els command code to be accepted.
3522 * @oldiocb: pointer to the original lpfc command iocb data structure.
3523 * @ndlp: pointer to a node-list data structure.
3524 * @mbox: pointer to the driver internal queue element for mailbox command.
3526 * This routine prepares and issues an Accept (ACC) response IOCB
3527 * command. It uses the @flag to properly set up the IOCB field for the
3528 * specific ACC response command to be issued and invokes the
3529 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
3530 * @mbox pointer is passed in, it will be put into the context_un.mbox
3531 * field of the IOCB for the completion callback function to issue the
3532 * mailbox command to the HBA later when callback is invoked.
3534 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3535 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3536 * will be stored into the context1 field of the IOCB for the completion
3537 * callback function to the corresponding response ELS IOCB command.
3539 * Return code
3540 * 0 - Successfully issued acc response
3541 * 1 - Failed to issue acc response
3544 lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
3545 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
3546 LPFC_MBOXQ_t *mbox)
3548 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3549 struct lpfc_hba *phba = vport->phba;
3550 IOCB_t *icmd;
3551 IOCB_t *oldcmd;
3552 struct lpfc_iocbq *elsiocb;
3553 struct lpfc_sli *psli;
3554 uint8_t *pcmd;
3555 uint16_t cmdsize;
3556 int rc;
3557 ELS_PKT *els_pkt_ptr;
3559 psli = &phba->sli;
3560 oldcmd = &oldiocb->iocb;
3562 switch (flag) {
3563 case ELS_CMD_ACC:
3564 cmdsize = sizeof(uint32_t);
3565 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3566 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
3567 if (!elsiocb) {
3568 spin_lock_irq(shost->host_lock);
3569 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
3570 spin_unlock_irq(shost->host_lock);
3571 return 1;
3574 icmd = &elsiocb->iocb;
3575 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3576 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3577 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
3578 pcmd += sizeof(uint32_t);
3580 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3581 "Issue ACC: did:x%x flg:x%x",
3582 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3583 break;
3584 case ELS_CMD_PLOGI:
3585 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
3586 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3587 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
3588 if (!elsiocb)
3589 return 1;
3591 icmd = &elsiocb->iocb;
3592 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3593 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3595 if (mbox)
3596 elsiocb->context_un.mbox = mbox;
3598 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
3599 pcmd += sizeof(uint32_t);
3600 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
3602 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3603 "Issue ACC PLOGI: did:x%x flg:x%x",
3604 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3605 break;
3606 case ELS_CMD_PRLO:
3607 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
3608 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3609 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
3610 if (!elsiocb)
3611 return 1;
3613 icmd = &elsiocb->iocb;
3614 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3615 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3617 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
3618 sizeof(uint32_t) + sizeof(PRLO));
3619 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
3620 els_pkt_ptr = (ELS_PKT *) pcmd;
3621 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
3623 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3624 "Issue ACC PRLO: did:x%x flg:x%x",
3625 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3626 break;
3627 default:
3628 return 1;
3630 /* Xmit ELS ACC response tag <ulpIoTag> */
3631 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3632 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
3633 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n",
3634 elsiocb->iotag, elsiocb->iocb.ulpContext,
3635 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3636 ndlp->nlp_rpi);
3637 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
3638 spin_lock_irq(shost->host_lock);
3639 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
3640 spin_unlock_irq(shost->host_lock);
3641 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
3642 } else {
3643 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
3646 phba->fc_stat.elsXmitACC++;
3647 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3648 if (rc == IOCB_ERROR) {
3649 lpfc_els_free_iocb(phba, elsiocb);
3650 return 1;
3652 return 0;
3656 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
3657 * @vport: pointer to a virtual N_Port data structure.
3658 * @rejectError:
3659 * @oldiocb: pointer to the original lpfc command iocb data structure.
3660 * @ndlp: pointer to a node-list data structure.
3661 * @mbox: pointer to the driver internal queue element for mailbox command.
3663 * This routine prepares and issue an Reject (RJT) response IOCB
3664 * command. If a @mbox pointer is passed in, it will be put into the
3665 * context_un.mbox field of the IOCB for the completion callback function
3666 * to issue to the HBA later.
3668 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3669 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3670 * will be stored into the context1 field of the IOCB for the completion
3671 * callback function to the reject response ELS IOCB command.
3673 * Return code
3674 * 0 - Successfully issued reject response
3675 * 1 - Failed to issue reject response
3678 lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
3679 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
3680 LPFC_MBOXQ_t *mbox)
3682 struct lpfc_hba *phba = vport->phba;
3683 IOCB_t *icmd;
3684 IOCB_t *oldcmd;
3685 struct lpfc_iocbq *elsiocb;
3686 struct lpfc_sli *psli;
3687 uint8_t *pcmd;
3688 uint16_t cmdsize;
3689 int rc;
3691 psli = &phba->sli;
3692 cmdsize = 2 * sizeof(uint32_t);
3693 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3694 ndlp->nlp_DID, ELS_CMD_LS_RJT);
3695 if (!elsiocb)
3696 return 1;
3698 icmd = &elsiocb->iocb;
3699 oldcmd = &oldiocb->iocb;
3700 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3701 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3703 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
3704 pcmd += sizeof(uint32_t);
3705 *((uint32_t *) (pcmd)) = rejectError;
3707 if (mbox)
3708 elsiocb->context_un.mbox = mbox;
3710 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
3711 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3712 "0129 Xmit ELS RJT x%x response tag x%x "
3713 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
3714 "rpi x%x\n",
3715 rejectError, elsiocb->iotag,
3716 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
3717 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
3718 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3719 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
3720 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
3722 phba->fc_stat.elsXmitLSRJT++;
3723 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
3724 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3726 if (rc == IOCB_ERROR) {
3727 lpfc_els_free_iocb(phba, elsiocb);
3728 return 1;
3730 return 0;
3734 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
3735 * @vport: pointer to a virtual N_Port data structure.
3736 * @oldiocb: pointer to the original lpfc command iocb data structure.
3737 * @ndlp: pointer to a node-list data structure.
3739 * This routine prepares and issues an Accept (ACC) response to Address
3740 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
3741 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3743 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3744 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3745 * will be stored into the context1 field of the IOCB for the completion
3746 * callback function to the ADISC Accept response ELS IOCB command.
3748 * Return code
3749 * 0 - Successfully issued acc adisc response
3750 * 1 - Failed to issue adisc acc response
3753 lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
3754 struct lpfc_nodelist *ndlp)
3756 struct lpfc_hba *phba = vport->phba;
3757 ADISC *ap;
3758 IOCB_t *icmd, *oldcmd;
3759 struct lpfc_iocbq *elsiocb;
3760 uint8_t *pcmd;
3761 uint16_t cmdsize;
3762 int rc;
3764 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
3765 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3766 ndlp->nlp_DID, ELS_CMD_ACC);
3767 if (!elsiocb)
3768 return 1;
3770 icmd = &elsiocb->iocb;
3771 oldcmd = &oldiocb->iocb;
3772 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3774 /* Xmit ADISC ACC response tag <ulpIoTag> */
3775 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3776 "0130 Xmit ADISC ACC response iotag x%x xri: "
3777 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
3778 elsiocb->iotag, elsiocb->iocb.ulpContext,
3779 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3780 ndlp->nlp_rpi);
3781 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3783 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
3784 pcmd += sizeof(uint32_t);
3786 ap = (ADISC *) (pcmd);
3787 ap->hardAL_PA = phba->fc_pref_ALPA;
3788 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
3789 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
3790 ap->DID = be32_to_cpu(vport->fc_myDID);
3792 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3793 "Issue ACC ADISC: did:x%x flg:x%x",
3794 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3796 phba->fc_stat.elsXmitACC++;
3797 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
3798 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3799 if (rc == IOCB_ERROR) {
3800 lpfc_els_free_iocb(phba, elsiocb);
3801 return 1;
3803 return 0;
3807 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
3808 * @vport: pointer to a virtual N_Port data structure.
3809 * @oldiocb: pointer to the original lpfc command iocb data structure.
3810 * @ndlp: pointer to a node-list data structure.
3812 * This routine prepares and issues an Accept (ACC) response to Process
3813 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
3814 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3816 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3817 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3818 * will be stored into the context1 field of the IOCB for the completion
3819 * callback function to the PRLI Accept response ELS IOCB command.
3821 * Return code
3822 * 0 - Successfully issued acc prli response
3823 * 1 - Failed to issue acc prli response
3826 lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
3827 struct lpfc_nodelist *ndlp)
3829 struct lpfc_hba *phba = vport->phba;
3830 PRLI *npr;
3831 lpfc_vpd_t *vpd;
3832 IOCB_t *icmd;
3833 IOCB_t *oldcmd;
3834 struct lpfc_iocbq *elsiocb;
3835 struct lpfc_sli *psli;
3836 uint8_t *pcmd;
3837 uint16_t cmdsize;
3838 int rc;
3840 psli = &phba->sli;
3842 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
3843 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3844 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
3845 if (!elsiocb)
3846 return 1;
3848 icmd = &elsiocb->iocb;
3849 oldcmd = &oldiocb->iocb;
3850 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3851 /* Xmit PRLI ACC response tag <ulpIoTag> */
3852 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3853 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
3854 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
3855 elsiocb->iotag, elsiocb->iocb.ulpContext,
3856 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3857 ndlp->nlp_rpi);
3858 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3860 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
3861 pcmd += sizeof(uint32_t);
3863 /* For PRLI, remainder of payload is PRLI parameter page */
3864 memset(pcmd, 0, sizeof(PRLI));
3866 npr = (PRLI *) pcmd;
3867 vpd = &phba->vpd;
3869 * If the remote port is a target and our firmware version is 3.20 or
3870 * later, set the following bits for FC-TAPE support.
3872 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
3873 (vpd->rev.feaLevelHigh >= 0x02)) {
3874 npr->ConfmComplAllowed = 1;
3875 npr->Retry = 1;
3876 npr->TaskRetryIdReq = 1;
3879 npr->acceptRspCode = PRLI_REQ_EXECUTED;
3880 npr->estabImagePair = 1;
3881 npr->readXferRdyDis = 1;
3882 npr->ConfmComplAllowed = 1;
3884 npr->prliType = PRLI_FCP_TYPE;
3885 npr->initiatorFunc = 1;
3887 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3888 "Issue ACC PRLI: did:x%x flg:x%x",
3889 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3891 phba->fc_stat.elsXmitACC++;
3892 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
3894 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3895 if (rc == IOCB_ERROR) {
3896 lpfc_els_free_iocb(phba, elsiocb);
3897 return 1;
3899 return 0;
3903 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
3904 * @vport: pointer to a virtual N_Port data structure.
3905 * @format: rnid command format.
3906 * @oldiocb: pointer to the original lpfc command iocb data structure.
3907 * @ndlp: pointer to a node-list data structure.
3909 * This routine issues a Request Node Identification Data (RNID) Accept
3910 * (ACC) response. It constructs the RNID ACC response command according to
3911 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
3912 * issue the response. Note that this command does not need to hold the ndlp
3913 * reference count for the callback. So, the ndlp reference count taken by
3914 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
3915 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
3916 * there is no ndlp reference available.
3918 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3919 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3920 * will be stored into the context1 field of the IOCB for the completion
3921 * callback function. However, for the RNID Accept Response ELS command,
3922 * this is undone later by this routine after the IOCB is allocated.
3924 * Return code
3925 * 0 - Successfully issued acc rnid response
3926 * 1 - Failed to issue acc rnid response
3928 static int
3929 lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
3930 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
3932 struct lpfc_hba *phba = vport->phba;
3933 RNID *rn;
3934 IOCB_t *icmd, *oldcmd;
3935 struct lpfc_iocbq *elsiocb;
3936 struct lpfc_sli *psli;
3937 uint8_t *pcmd;
3938 uint16_t cmdsize;
3939 int rc;
3941 psli = &phba->sli;
3942 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
3943 + (2 * sizeof(struct lpfc_name));
3944 if (format)
3945 cmdsize += sizeof(RNID_TOP_DISC);
3947 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3948 ndlp->nlp_DID, ELS_CMD_ACC);
3949 if (!elsiocb)
3950 return 1;
3952 icmd = &elsiocb->iocb;
3953 oldcmd = &oldiocb->iocb;
3954 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3955 /* Xmit RNID ACC response tag <ulpIoTag> */
3956 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3957 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
3958 elsiocb->iotag, elsiocb->iocb.ulpContext);
3959 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3960 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
3961 pcmd += sizeof(uint32_t);
3963 memset(pcmd, 0, sizeof(RNID));
3964 rn = (RNID *) (pcmd);
3965 rn->Format = format;
3966 rn->CommonLen = (2 * sizeof(struct lpfc_name));
3967 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
3968 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
3969 switch (format) {
3970 case 0:
3971 rn->SpecificLen = 0;
3972 break;
3973 case RNID_TOPOLOGY_DISC:
3974 rn->SpecificLen = sizeof(RNID_TOP_DISC);
3975 memcpy(&rn->un.topologyDisc.portName,
3976 &vport->fc_portname, sizeof(struct lpfc_name));
3977 rn->un.topologyDisc.unitType = RNID_HBA;
3978 rn->un.topologyDisc.physPort = 0;
3979 rn->un.topologyDisc.attachedNodes = 0;
3980 break;
3981 default:
3982 rn->CommonLen = 0;
3983 rn->SpecificLen = 0;
3984 break;
3987 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3988 "Issue ACC RNID: did:x%x flg:x%x",
3989 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3991 phba->fc_stat.elsXmitACC++;
3992 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
3993 lpfc_nlp_put(ndlp);
3994 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
3995 * it could be freed */
3997 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
3998 if (rc == IOCB_ERROR) {
3999 lpfc_els_free_iocb(phba, elsiocb);
4000 return 1;
4002 return 0;
4006 * lpfc_els_clear_rrq - Clear the rq that this rrq describes.
4007 * @vport: pointer to a virtual N_Port data structure.
4008 * @iocb: pointer to the lpfc command iocb data structure.
4009 * @ndlp: pointer to a node-list data structure.
4011 * Return
4013 static void
4014 lpfc_els_clear_rrq(struct lpfc_vport *vport,
4015 struct lpfc_iocbq *iocb, struct lpfc_nodelist *ndlp)
4017 struct lpfc_hba *phba = vport->phba;
4018 uint8_t *pcmd;
4019 struct RRQ *rrq;
4020 uint16_t rxid;
4021 struct lpfc_node_rrq *prrq;
4024 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) iocb->context2)->virt);
4025 pcmd += sizeof(uint32_t);
4026 rrq = (struct RRQ *)pcmd;
4027 rxid = bf_get(rrq_oxid, rrq);
4029 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4030 "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x"
4031 " x%x x%x\n",
4032 bf_get(rrq_did, rrq),
4033 bf_get(rrq_oxid, rrq),
4034 rxid,
4035 iocb->iotag, iocb->iocb.ulpContext);
4037 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4038 "Clear RRQ: did:x%x flg:x%x exchg:x%.08x",
4039 ndlp->nlp_DID, ndlp->nlp_flag, rrq->rrq_exchg);
4040 prrq = lpfc_get_active_rrq(vport, rxid, ndlp->nlp_DID);
4041 if (prrq)
4042 lpfc_clr_rrq_active(phba, rxid, prrq);
4043 return;
4047 * lpfc_els_rsp_echo_acc - Issue echo acc response
4048 * @vport: pointer to a virtual N_Port data structure.
4049 * @data: pointer to echo data to return in the accept.
4050 * @oldiocb: pointer to the original lpfc command iocb data structure.
4051 * @ndlp: pointer to a node-list data structure.
4053 * Return code
4054 * 0 - Successfully issued acc echo response
4055 * 1 - Failed to issue acc echo response
4057 static int
4058 lpfc_els_rsp_echo_acc(struct lpfc_vport *vport, uint8_t *data,
4059 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
4061 struct lpfc_hba *phba = vport->phba;
4062 struct lpfc_iocbq *elsiocb;
4063 struct lpfc_sli *psli;
4064 uint8_t *pcmd;
4065 uint16_t cmdsize;
4066 int rc;
4068 psli = &phba->sli;
4069 cmdsize = oldiocb->iocb.unsli3.rcvsli3.acc_len;
4071 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4072 ndlp->nlp_DID, ELS_CMD_ACC);
4073 if (!elsiocb)
4074 return 1;
4076 elsiocb->iocb.ulpContext = oldiocb->iocb.ulpContext; /* Xri */
4077 /* Xmit ECHO ACC response tag <ulpIoTag> */
4078 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4079 "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
4080 elsiocb->iotag, elsiocb->iocb.ulpContext);
4081 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4082 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4083 pcmd += sizeof(uint32_t);
4084 memcpy(pcmd, data, cmdsize - sizeof(uint32_t));
4086 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
4087 "Issue ACC ECHO: did:x%x flg:x%x",
4088 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4090 phba->fc_stat.elsXmitACC++;
4091 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
4092 lpfc_nlp_put(ndlp);
4093 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
4094 * it could be freed */
4096 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
4097 if (rc == IOCB_ERROR) {
4098 lpfc_els_free_iocb(phba, elsiocb);
4099 return 1;
4101 return 0;
4105 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
4106 * @vport: pointer to a host virtual N_Port data structure.
4108 * This routine issues Address Discover (ADISC) ELS commands to those
4109 * N_Ports which are in node port recovery state and ADISC has not been issued
4110 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
4111 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
4112 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
4113 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
4114 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
4115 * IOCBs quit for later pick up. On the other hand, after walking through
4116 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
4117 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
4118 * no more ADISC need to be sent.
4120 * Return code
4121 * The number of N_Ports with adisc issued.
4124 lpfc_els_disc_adisc(struct lpfc_vport *vport)
4126 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4127 struct lpfc_nodelist *ndlp, *next_ndlp;
4128 int sentadisc = 0;
4130 /* go thru NPR nodes and issue any remaining ELS ADISCs */
4131 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
4132 if (!NLP_CHK_NODE_ACT(ndlp))
4133 continue;
4134 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4135 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4136 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
4137 spin_lock_irq(shost->host_lock);
4138 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
4139 spin_unlock_irq(shost->host_lock);
4140 ndlp->nlp_prev_state = ndlp->nlp_state;
4141 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
4142 lpfc_issue_els_adisc(vport, ndlp, 0);
4143 sentadisc++;
4144 vport->num_disc_nodes++;
4145 if (vport->num_disc_nodes >=
4146 vport->cfg_discovery_threads) {
4147 spin_lock_irq(shost->host_lock);
4148 vport->fc_flag |= FC_NLP_MORE;
4149 spin_unlock_irq(shost->host_lock);
4150 break;
4154 if (sentadisc == 0) {
4155 spin_lock_irq(shost->host_lock);
4156 vport->fc_flag &= ~FC_NLP_MORE;
4157 spin_unlock_irq(shost->host_lock);
4159 return sentadisc;
4163 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
4164 * @vport: pointer to a host virtual N_Port data structure.
4166 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
4167 * which are in node port recovery state, with a @vport. Each time an ELS
4168 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
4169 * the per @vport number of discover count (num_disc_nodes) shall be
4170 * incremented. If the num_disc_nodes reaches a pre-configured threshold
4171 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
4172 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
4173 * later pick up. On the other hand, after walking through all the ndlps with
4174 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
4175 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
4176 * PLOGI need to be sent.
4178 * Return code
4179 * The number of N_Ports with plogi issued.
4182 lpfc_els_disc_plogi(struct lpfc_vport *vport)
4184 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4185 struct lpfc_nodelist *ndlp, *next_ndlp;
4186 int sentplogi = 0;
4188 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
4189 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
4190 if (!NLP_CHK_NODE_ACT(ndlp))
4191 continue;
4192 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
4193 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
4194 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
4195 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
4196 ndlp->nlp_prev_state = ndlp->nlp_state;
4197 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
4198 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
4199 sentplogi++;
4200 vport->num_disc_nodes++;
4201 if (vport->num_disc_nodes >=
4202 vport->cfg_discovery_threads) {
4203 spin_lock_irq(shost->host_lock);
4204 vport->fc_flag |= FC_NLP_MORE;
4205 spin_unlock_irq(shost->host_lock);
4206 break;
4210 if (sentplogi) {
4211 lpfc_set_disctmo(vport);
4213 else {
4214 spin_lock_irq(shost->host_lock);
4215 vport->fc_flag &= ~FC_NLP_MORE;
4216 spin_unlock_irq(shost->host_lock);
4218 return sentplogi;
4222 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
4223 * @vport: pointer to a host virtual N_Port data structure.
4225 * This routine cleans up any Registration State Change Notification
4226 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
4227 * @vport together with the host_lock is used to prevent multiple thread
4228 * trying to access the RSCN array on a same @vport at the same time.
4230 void
4231 lpfc_els_flush_rscn(struct lpfc_vport *vport)
4233 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4234 struct lpfc_hba *phba = vport->phba;
4235 int i;
4237 spin_lock_irq(shost->host_lock);
4238 if (vport->fc_rscn_flush) {
4239 /* Another thread is walking fc_rscn_id_list on this vport */
4240 spin_unlock_irq(shost->host_lock);
4241 return;
4243 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
4244 vport->fc_rscn_flush = 1;
4245 spin_unlock_irq(shost->host_lock);
4247 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
4248 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
4249 vport->fc_rscn_id_list[i] = NULL;
4251 spin_lock_irq(shost->host_lock);
4252 vport->fc_rscn_id_cnt = 0;
4253 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
4254 spin_unlock_irq(shost->host_lock);
4255 lpfc_can_disctmo(vport);
4256 /* Indicate we are done walking this fc_rscn_id_list */
4257 vport->fc_rscn_flush = 0;
4261 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
4262 * @vport: pointer to a host virtual N_Port data structure.
4263 * @did: remote destination port identifier.
4265 * This routine checks whether there is any pending Registration State
4266 * Configuration Notification (RSCN) to a @did on @vport.
4268 * Return code
4269 * None zero - The @did matched with a pending rscn
4270 * 0 - not able to match @did with a pending rscn
4273 lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
4275 D_ID ns_did;
4276 D_ID rscn_did;
4277 uint32_t *lp;
4278 uint32_t payload_len, i;
4279 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4281 ns_did.un.word = did;
4283 /* Never match fabric nodes for RSCNs */
4284 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
4285 return 0;
4287 /* If we are doing a FULL RSCN rediscovery, match everything */
4288 if (vport->fc_flag & FC_RSCN_DISCOVERY)
4289 return did;
4291 spin_lock_irq(shost->host_lock);
4292 if (vport->fc_rscn_flush) {
4293 /* Another thread is walking fc_rscn_id_list on this vport */
4294 spin_unlock_irq(shost->host_lock);
4295 return 0;
4297 /* Indicate we are walking fc_rscn_id_list on this vport */
4298 vport->fc_rscn_flush = 1;
4299 spin_unlock_irq(shost->host_lock);
4300 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
4301 lp = vport->fc_rscn_id_list[i]->virt;
4302 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4303 payload_len -= sizeof(uint32_t); /* take off word 0 */
4304 while (payload_len) {
4305 rscn_did.un.word = be32_to_cpu(*lp++);
4306 payload_len -= sizeof(uint32_t);
4307 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
4308 case RSCN_ADDRESS_FORMAT_PORT:
4309 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4310 && (ns_did.un.b.area == rscn_did.un.b.area)
4311 && (ns_did.un.b.id == rscn_did.un.b.id))
4312 goto return_did_out;
4313 break;
4314 case RSCN_ADDRESS_FORMAT_AREA:
4315 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
4316 && (ns_did.un.b.area == rscn_did.un.b.area))
4317 goto return_did_out;
4318 break;
4319 case RSCN_ADDRESS_FORMAT_DOMAIN:
4320 if (ns_did.un.b.domain == rscn_did.un.b.domain)
4321 goto return_did_out;
4322 break;
4323 case RSCN_ADDRESS_FORMAT_FABRIC:
4324 goto return_did_out;
4328 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4329 vport->fc_rscn_flush = 0;
4330 return 0;
4331 return_did_out:
4332 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4333 vport->fc_rscn_flush = 0;
4334 return did;
4338 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
4339 * @vport: pointer to a host virtual N_Port data structure.
4341 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
4342 * state machine for a @vport's nodes that are with pending RSCN (Registration
4343 * State Change Notification).
4345 * Return code
4346 * 0 - Successful (currently alway return 0)
4348 static int
4349 lpfc_rscn_recovery_check(struct lpfc_vport *vport)
4351 struct lpfc_nodelist *ndlp = NULL;
4353 /* Move all affected nodes by pending RSCNs to NPR state. */
4354 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
4355 if (!NLP_CHK_NODE_ACT(ndlp) ||
4356 (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
4357 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
4358 continue;
4359 lpfc_disc_state_machine(vport, ndlp, NULL,
4360 NLP_EVT_DEVICE_RECOVERY);
4361 lpfc_cancel_retry_delay_tmo(vport, ndlp);
4363 return 0;
4367 * lpfc_send_rscn_event - Send an RSCN event to management application
4368 * @vport: pointer to a host virtual N_Port data structure.
4369 * @cmdiocb: pointer to lpfc command iocb data structure.
4371 * lpfc_send_rscn_event sends an RSCN netlink event to management
4372 * applications.
4374 static void
4375 lpfc_send_rscn_event(struct lpfc_vport *vport,
4376 struct lpfc_iocbq *cmdiocb)
4378 struct lpfc_dmabuf *pcmd;
4379 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4380 uint32_t *payload_ptr;
4381 uint32_t payload_len;
4382 struct lpfc_rscn_event_header *rscn_event_data;
4384 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4385 payload_ptr = (uint32_t *) pcmd->virt;
4386 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
4388 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
4389 payload_len, GFP_KERNEL);
4390 if (!rscn_event_data) {
4391 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4392 "0147 Failed to allocate memory for RSCN event\n");
4393 return;
4395 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
4396 rscn_event_data->payload_length = payload_len;
4397 memcpy(rscn_event_data->rscn_payload, payload_ptr,
4398 payload_len);
4400 fc_host_post_vendor_event(shost,
4401 fc_get_event_number(),
4402 sizeof(struct lpfc_els_event_header) + payload_len,
4403 (char *)rscn_event_data,
4404 LPFC_NL_VENDOR_ID);
4406 kfree(rscn_event_data);
4410 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
4411 * @vport: pointer to a host virtual N_Port data structure.
4412 * @cmdiocb: pointer to lpfc command iocb data structure.
4413 * @ndlp: pointer to a node-list data structure.
4415 * This routine processes an unsolicited RSCN (Registration State Change
4416 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
4417 * to invoke fc_host_post_event() routine to the FC transport layer. If the
4418 * discover state machine is about to begin discovery, it just accepts the
4419 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
4420 * contains N_Port IDs for other vports on this HBA, it just accepts the
4421 * RSCN and ignore processing it. If the state machine is in the recovery
4422 * state, the fc_rscn_id_list of this @vport is walked and the
4423 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
4424 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
4425 * routine is invoked to handle the RSCN event.
4427 * Return code
4428 * 0 - Just sent the acc response
4429 * 1 - Sent the acc response and waited for name server completion
4431 static int
4432 lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4433 struct lpfc_nodelist *ndlp)
4435 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4436 struct lpfc_hba *phba = vport->phba;
4437 struct lpfc_dmabuf *pcmd;
4438 uint32_t *lp, *datap;
4439 IOCB_t *icmd;
4440 uint32_t payload_len, length, nportid, *cmd;
4441 int rscn_cnt;
4442 int rscn_id = 0, hba_id = 0;
4443 int i;
4445 icmd = &cmdiocb->iocb;
4446 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4447 lp = (uint32_t *) pcmd->virt;
4449 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4450 payload_len -= sizeof(uint32_t); /* take off word 0 */
4451 /* RSCN received */
4452 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4453 "0214 RSCN received Data: x%x x%x x%x x%x\n",
4454 vport->fc_flag, payload_len, *lp,
4455 vport->fc_rscn_id_cnt);
4457 /* Send an RSCN event to the management application */
4458 lpfc_send_rscn_event(vport, cmdiocb);
4460 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
4461 fc_host_post_event(shost, fc_get_event_number(),
4462 FCH_EVT_RSCN, lp[i]);
4464 /* If we are about to begin discovery, just ACC the RSCN.
4465 * Discovery processing will satisfy it.
4467 if (vport->port_state <= LPFC_NS_QRY) {
4468 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4469 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
4470 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4472 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
4473 return 0;
4476 /* If this RSCN just contains NPortIDs for other vports on this HBA,
4477 * just ACC and ignore it.
4479 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
4480 !(vport->cfg_peer_port_login)) {
4481 i = payload_len;
4482 datap = lp;
4483 while (i > 0) {
4484 nportid = *datap++;
4485 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
4486 i -= sizeof(uint32_t);
4487 rscn_id++;
4488 if (lpfc_find_vport_by_did(phba, nportid))
4489 hba_id++;
4491 if (rscn_id == hba_id) {
4492 /* ALL NPortIDs in RSCN are on HBA */
4493 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4494 "0219 Ignore RSCN "
4495 "Data: x%x x%x x%x x%x\n",
4496 vport->fc_flag, payload_len,
4497 *lp, vport->fc_rscn_id_cnt);
4498 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4499 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
4500 ndlp->nlp_DID, vport->port_state,
4501 ndlp->nlp_flag);
4503 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
4504 ndlp, NULL);
4505 return 0;
4509 spin_lock_irq(shost->host_lock);
4510 if (vport->fc_rscn_flush) {
4511 /* Another thread is walking fc_rscn_id_list on this vport */
4512 vport->fc_flag |= FC_RSCN_DISCOVERY;
4513 spin_unlock_irq(shost->host_lock);
4514 /* Send back ACC */
4515 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
4516 return 0;
4518 /* Indicate we are walking fc_rscn_id_list on this vport */
4519 vport->fc_rscn_flush = 1;
4520 spin_unlock_irq(shost->host_lock);
4521 /* Get the array count after successfully have the token */
4522 rscn_cnt = vport->fc_rscn_id_cnt;
4523 /* If we are already processing an RSCN, save the received
4524 * RSCN payload buffer, cmdiocb->context2 to process later.
4526 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
4527 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4528 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
4529 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4531 spin_lock_irq(shost->host_lock);
4532 vport->fc_flag |= FC_RSCN_DEFERRED;
4533 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
4534 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
4535 vport->fc_flag |= FC_RSCN_MODE;
4536 spin_unlock_irq(shost->host_lock);
4537 if (rscn_cnt) {
4538 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
4539 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
4541 if ((rscn_cnt) &&
4542 (payload_len + length <= LPFC_BPL_SIZE)) {
4543 *cmd &= ELS_CMD_MASK;
4544 *cmd |= cpu_to_be32(payload_len + length);
4545 memcpy(((uint8_t *)cmd) + length, lp,
4546 payload_len);
4547 } else {
4548 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
4549 vport->fc_rscn_id_cnt++;
4550 /* If we zero, cmdiocb->context2, the calling
4551 * routine will not try to free it.
4553 cmdiocb->context2 = NULL;
4555 /* Deferred RSCN */
4556 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4557 "0235 Deferred RSCN "
4558 "Data: x%x x%x x%x\n",
4559 vport->fc_rscn_id_cnt, vport->fc_flag,
4560 vport->port_state);
4561 } else {
4562 vport->fc_flag |= FC_RSCN_DISCOVERY;
4563 spin_unlock_irq(shost->host_lock);
4564 /* ReDiscovery RSCN */
4565 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4566 "0234 ReDiscovery RSCN "
4567 "Data: x%x x%x x%x\n",
4568 vport->fc_rscn_id_cnt, vport->fc_flag,
4569 vport->port_state);
4571 /* Indicate we are done walking fc_rscn_id_list on this vport */
4572 vport->fc_rscn_flush = 0;
4573 /* Send back ACC */
4574 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
4575 /* send RECOVERY event for ALL nodes that match RSCN payload */
4576 lpfc_rscn_recovery_check(vport);
4577 spin_lock_irq(shost->host_lock);
4578 vport->fc_flag &= ~FC_RSCN_DEFERRED;
4579 spin_unlock_irq(shost->host_lock);
4580 return 0;
4582 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4583 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
4584 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4586 spin_lock_irq(shost->host_lock);
4587 vport->fc_flag |= FC_RSCN_MODE;
4588 spin_unlock_irq(shost->host_lock);
4589 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
4590 /* Indicate we are done walking fc_rscn_id_list on this vport */
4591 vport->fc_rscn_flush = 0;
4593 * If we zero, cmdiocb->context2, the calling routine will
4594 * not try to free it.
4596 cmdiocb->context2 = NULL;
4597 lpfc_set_disctmo(vport);
4598 /* Send back ACC */
4599 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
4600 /* send RECOVERY event for ALL nodes that match RSCN payload */
4601 lpfc_rscn_recovery_check(vport);
4602 return lpfc_els_handle_rscn(vport);
4606 * lpfc_els_handle_rscn - Handle rscn for a vport
4607 * @vport: pointer to a host virtual N_Port data structure.
4609 * This routine handles the Registration State Configuration Notification
4610 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
4611 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
4612 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
4613 * NameServer shall be issued. If CT command to the NameServer fails to be
4614 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
4615 * RSCN activities with the @vport.
4617 * Return code
4618 * 0 - Cleaned up rscn on the @vport
4619 * 1 - Wait for plogi to name server before proceed
4622 lpfc_els_handle_rscn(struct lpfc_vport *vport)
4624 struct lpfc_nodelist *ndlp;
4625 struct lpfc_hba *phba = vport->phba;
4627 /* Ignore RSCN if the port is being torn down. */
4628 if (vport->load_flag & FC_UNLOADING) {
4629 lpfc_els_flush_rscn(vport);
4630 return 0;
4633 /* Start timer for RSCN processing */
4634 lpfc_set_disctmo(vport);
4636 /* RSCN processed */
4637 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4638 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
4639 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
4640 vport->port_state);
4642 /* To process RSCN, first compare RSCN data with NameServer */
4643 vport->fc_ns_retry = 0;
4644 vport->num_disc_nodes = 0;
4646 ndlp = lpfc_findnode_did(vport, NameServer_DID);
4647 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
4648 && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
4649 /* Good ndlp, issue CT Request to NameServer */
4650 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
4651 /* Wait for NameServer query cmpl before we can
4652 continue */
4653 return 1;
4654 } else {
4655 /* If login to NameServer does not exist, issue one */
4656 /* Good status, issue PLOGI to NameServer */
4657 ndlp = lpfc_findnode_did(vport, NameServer_DID);
4658 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
4659 /* Wait for NameServer login cmpl before we can
4660 continue */
4661 return 1;
4663 if (ndlp) {
4664 ndlp = lpfc_enable_node(vport, ndlp,
4665 NLP_STE_PLOGI_ISSUE);
4666 if (!ndlp) {
4667 lpfc_els_flush_rscn(vport);
4668 return 0;
4670 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
4671 } else {
4672 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
4673 if (!ndlp) {
4674 lpfc_els_flush_rscn(vport);
4675 return 0;
4677 lpfc_nlp_init(vport, ndlp, NameServer_DID);
4678 ndlp->nlp_prev_state = ndlp->nlp_state;
4679 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
4681 ndlp->nlp_type |= NLP_FABRIC;
4682 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
4683 /* Wait for NameServer login cmpl before we can
4684 * continue
4686 return 1;
4689 lpfc_els_flush_rscn(vport);
4690 return 0;
4694 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
4695 * @vport: pointer to a host virtual N_Port data structure.
4696 * @cmdiocb: pointer to lpfc command iocb data structure.
4697 * @ndlp: pointer to a node-list data structure.
4699 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
4700 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
4701 * point topology. As an unsolicited FLOGI should not be received in a loop
4702 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
4703 * lpfc_check_sparm() routine is invoked to check the parameters in the
4704 * unsolicited FLOGI. If parameters validation failed, the routine
4705 * lpfc_els_rsp_reject() shall be called with reject reason code set to
4706 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
4707 * FLOGI shall be compared with the Port WWN of the @vport to determine who
4708 * will initiate PLOGI. The higher lexicographical value party shall has
4709 * higher priority (as the winning port) and will initiate PLOGI and
4710 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
4711 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
4712 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
4714 * Return code
4715 * 0 - Successfully processed the unsolicited flogi
4716 * 1 - Failed to process the unsolicited flogi
4718 static int
4719 lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4720 struct lpfc_nodelist *ndlp)
4722 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4723 struct lpfc_hba *phba = vport->phba;
4724 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4725 uint32_t *lp = (uint32_t *) pcmd->virt;
4726 IOCB_t *icmd = &cmdiocb->iocb;
4727 struct serv_parm *sp;
4728 LPFC_MBOXQ_t *mbox;
4729 struct ls_rjt stat;
4730 uint32_t cmd, did;
4731 int rc;
4733 cmd = *lp++;
4734 sp = (struct serv_parm *) lp;
4736 /* FLOGI received */
4738 lpfc_set_disctmo(vport);
4740 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
4741 /* We should never receive a FLOGI in loop mode, ignore it */
4742 did = icmd->un.elsreq64.remoteID;
4744 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
4745 Loop Mode */
4746 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4747 "0113 An FLOGI ELS command x%x was "
4748 "received from DID x%x in Loop Mode\n",
4749 cmd, did);
4750 return 1;
4753 did = Fabric_DID;
4755 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1))) {
4756 /* For a FLOGI we accept, then if our portname is greater
4757 * then the remote portname we initiate Nport login.
4760 rc = memcmp(&vport->fc_portname, &sp->portName,
4761 sizeof(struct lpfc_name));
4763 if (!rc) {
4764 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4765 if (!mbox)
4766 return 1;
4768 lpfc_linkdown(phba);
4769 lpfc_init_link(phba, mbox,
4770 phba->cfg_topology,
4771 phba->cfg_link_speed);
4772 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
4773 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
4774 mbox->vport = vport;
4775 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
4776 lpfc_set_loopback_flag(phba);
4777 if (rc == MBX_NOT_FINISHED) {
4778 mempool_free(mbox, phba->mbox_mem_pool);
4780 return 1;
4781 } else if (rc > 0) { /* greater than */
4782 spin_lock_irq(shost->host_lock);
4783 vport->fc_flag |= FC_PT2PT_PLOGI;
4784 spin_unlock_irq(shost->host_lock);
4786 spin_lock_irq(shost->host_lock);
4787 vport->fc_flag |= FC_PT2PT;
4788 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
4789 spin_unlock_irq(shost->host_lock);
4790 } else {
4791 /* Reject this request because invalid parameters */
4792 stat.un.b.lsRjtRsvd0 = 0;
4793 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4794 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
4795 stat.un.b.vendorUnique = 0;
4796 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4797 NULL);
4798 return 1;
4801 /* Send back ACC */
4802 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
4804 return 0;
4808 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
4809 * @vport: pointer to a host virtual N_Port data structure.
4810 * @cmdiocb: pointer to lpfc command iocb data structure.
4811 * @ndlp: pointer to a node-list data structure.
4813 * This routine processes Request Node Identification Data (RNID) IOCB
4814 * received as an ELS unsolicited event. Only when the RNID specified format
4815 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
4816 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
4817 * Accept (ACC) the RNID ELS command. All the other RNID formats are
4818 * rejected by invoking the lpfc_els_rsp_reject() routine.
4820 * Return code
4821 * 0 - Successfully processed rnid iocb (currently always return 0)
4823 static int
4824 lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4825 struct lpfc_nodelist *ndlp)
4827 struct lpfc_dmabuf *pcmd;
4828 uint32_t *lp;
4829 IOCB_t *icmd;
4830 RNID *rn;
4831 struct ls_rjt stat;
4832 uint32_t cmd, did;
4834 icmd = &cmdiocb->iocb;
4835 did = icmd->un.elsreq64.remoteID;
4836 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4837 lp = (uint32_t *) pcmd->virt;
4839 cmd = *lp++;
4840 rn = (RNID *) lp;
4842 /* RNID received */
4844 switch (rn->Format) {
4845 case 0:
4846 case RNID_TOPOLOGY_DISC:
4847 /* Send back ACC */
4848 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
4849 break;
4850 default:
4851 /* Reject this request because format not supported */
4852 stat.un.b.lsRjtRsvd0 = 0;
4853 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4854 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4855 stat.un.b.vendorUnique = 0;
4856 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4857 NULL);
4859 return 0;
4863 * lpfc_els_rcv_echo - Process an unsolicited echo iocb
4864 * @vport: pointer to a host virtual N_Port data structure.
4865 * @cmdiocb: pointer to lpfc command iocb data structure.
4866 * @ndlp: pointer to a node-list data structure.
4868 * Return code
4869 * 0 - Successfully processed echo iocb (currently always return 0)
4871 static int
4872 lpfc_els_rcv_echo(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4873 struct lpfc_nodelist *ndlp)
4875 uint8_t *pcmd;
4877 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
4879 /* skip over first word of echo command to find echo data */
4880 pcmd += sizeof(uint32_t);
4882 lpfc_els_rsp_echo_acc(vport, pcmd, cmdiocb, ndlp);
4883 return 0;
4887 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
4888 * @vport: pointer to a host virtual N_Port data structure.
4889 * @cmdiocb: pointer to lpfc command iocb data structure.
4890 * @ndlp: pointer to a node-list data structure.
4892 * This routine processes a Link Incident Report Registration(LIRR) IOCB
4893 * received as an ELS unsolicited event. Currently, this function just invokes
4894 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
4896 * Return code
4897 * 0 - Successfully processed lirr iocb (currently always return 0)
4899 static int
4900 lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4901 struct lpfc_nodelist *ndlp)
4903 struct ls_rjt stat;
4905 /* For now, unconditionally reject this command */
4906 stat.un.b.lsRjtRsvd0 = 0;
4907 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4908 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4909 stat.un.b.vendorUnique = 0;
4910 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
4911 return 0;
4915 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
4916 * @vport: pointer to a host virtual N_Port data structure.
4917 * @cmdiocb: pointer to lpfc command iocb data structure.
4918 * @ndlp: pointer to a node-list data structure.
4920 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
4921 * received as an ELS unsolicited event. A request to RRQ shall only
4922 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
4923 * Nx_Port N_Port_ID of the target Exchange is the same as the
4924 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
4925 * not accepted, an LS_RJT with reason code "Unable to perform
4926 * command request" and reason code explanation "Invalid Originator
4927 * S_ID" shall be returned. For now, we just unconditionally accept
4928 * RRQ from the target.
4930 static void
4931 lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4932 struct lpfc_nodelist *ndlp)
4934 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
4935 if (vport->phba->sli_rev == LPFC_SLI_REV4)
4936 lpfc_els_clear_rrq(vport, cmdiocb, ndlp);
4940 * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
4941 * @phba: pointer to lpfc hba data structure.
4942 * @pmb: pointer to the driver internal queue element for mailbox command.
4944 * This routine is the completion callback function for the MBX_READ_LNK_STAT
4945 * mailbox command. This callback function is to actually send the Accept
4946 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
4947 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
4948 * mailbox command, constructs the RPS response with the link statistics
4949 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
4950 * response to the RPS.
4952 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4953 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4954 * will be stored into the context1 field of the IOCB for the completion
4955 * callback function to the RPS Accept Response ELS IOCB command.
4958 static void
4959 lpfc_els_rsp_rls_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4961 MAILBOX_t *mb;
4962 IOCB_t *icmd;
4963 struct RLS_RSP *rls_rsp;
4964 uint8_t *pcmd;
4965 struct lpfc_iocbq *elsiocb;
4966 struct lpfc_nodelist *ndlp;
4967 uint16_t xri;
4968 uint32_t cmdsize;
4970 mb = &pmb->u.mb;
4972 ndlp = (struct lpfc_nodelist *) pmb->context2;
4973 xri = (uint16_t) ((unsigned long)(pmb->context1));
4974 pmb->context1 = NULL;
4975 pmb->context2 = NULL;
4977 if (mb->mbxStatus) {
4978 mempool_free(pmb, phba->mbox_mem_pool);
4979 return;
4982 cmdsize = sizeof(struct RLS_RSP) + sizeof(uint32_t);
4983 mempool_free(pmb, phba->mbox_mem_pool);
4984 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
4985 lpfc_max_els_tries, ndlp,
4986 ndlp->nlp_DID, ELS_CMD_ACC);
4988 /* Decrement the ndlp reference count from previous mbox command */
4989 lpfc_nlp_put(ndlp);
4991 if (!elsiocb)
4992 return;
4994 icmd = &elsiocb->iocb;
4995 icmd->ulpContext = xri;
4997 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4998 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
4999 pcmd += sizeof(uint32_t); /* Skip past command */
5000 rls_rsp = (struct RLS_RSP *)pcmd;
5002 rls_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
5003 rls_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
5004 rls_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
5005 rls_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
5006 rls_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
5007 rls_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
5009 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
5010 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
5011 "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
5012 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
5013 elsiocb->iotag, elsiocb->iocb.ulpContext,
5014 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5015 ndlp->nlp_rpi);
5016 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5017 phba->fc_stat.elsXmitACC++;
5018 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
5019 lpfc_els_free_iocb(phba, elsiocb);
5023 * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
5024 * @phba: pointer to lpfc hba data structure.
5025 * @pmb: pointer to the driver internal queue element for mailbox command.
5027 * This routine is the completion callback function for the MBX_READ_LNK_STAT
5028 * mailbox command. This callback function is to actually send the Accept
5029 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
5030 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
5031 * mailbox command, constructs the RPS response with the link statistics
5032 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
5033 * response to the RPS.
5035 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5036 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5037 * will be stored into the context1 field of the IOCB for the completion
5038 * callback function to the RPS Accept Response ELS IOCB command.
5041 static void
5042 lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
5044 MAILBOX_t *mb;
5045 IOCB_t *icmd;
5046 RPS_RSP *rps_rsp;
5047 uint8_t *pcmd;
5048 struct lpfc_iocbq *elsiocb;
5049 struct lpfc_nodelist *ndlp;
5050 uint16_t xri, status;
5051 uint32_t cmdsize;
5053 mb = &pmb->u.mb;
5055 ndlp = (struct lpfc_nodelist *) pmb->context2;
5056 xri = (uint16_t) ((unsigned long)(pmb->context1));
5057 pmb->context1 = NULL;
5058 pmb->context2 = NULL;
5060 if (mb->mbxStatus) {
5061 mempool_free(pmb, phba->mbox_mem_pool);
5062 return;
5065 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
5066 mempool_free(pmb, phba->mbox_mem_pool);
5067 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5068 lpfc_max_els_tries, ndlp,
5069 ndlp->nlp_DID, ELS_CMD_ACC);
5071 /* Decrement the ndlp reference count from previous mbox command */
5072 lpfc_nlp_put(ndlp);
5074 if (!elsiocb)
5075 return;
5077 icmd = &elsiocb->iocb;
5078 icmd->ulpContext = xri;
5080 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5081 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5082 pcmd += sizeof(uint32_t); /* Skip past command */
5083 rps_rsp = (RPS_RSP *)pcmd;
5085 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP)
5086 status = 0x10;
5087 else
5088 status = 0x8;
5089 if (phba->pport->fc_flag & FC_FABRIC)
5090 status |= 0x4;
5092 rps_rsp->rsvd1 = 0;
5093 rps_rsp->portStatus = cpu_to_be16(status);
5094 rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
5095 rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
5096 rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
5097 rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
5098 rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
5099 rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
5100 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
5101 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
5102 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
5103 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
5104 elsiocb->iotag, elsiocb->iocb.ulpContext,
5105 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5106 ndlp->nlp_rpi);
5107 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5108 phba->fc_stat.elsXmitACC++;
5109 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
5110 lpfc_els_free_iocb(phba, elsiocb);
5111 return;
5115 * lpfc_els_rcv_rls - Process an unsolicited rls iocb
5116 * @vport: pointer to a host virtual N_Port data structure.
5117 * @cmdiocb: pointer to lpfc command iocb data structure.
5118 * @ndlp: pointer to a node-list data structure.
5120 * This routine processes Read Port Status (RPL) IOCB received as an
5121 * ELS unsolicited event. It first checks the remote port state. If the
5122 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5123 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
5124 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
5125 * for reading the HBA link statistics. It is for the callback function,
5126 * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
5127 * to actually sending out RPL Accept (ACC) response.
5129 * Return codes
5130 * 0 - Successfully processed rls iocb (currently always return 0)
5132 static int
5133 lpfc_els_rcv_rls(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5134 struct lpfc_nodelist *ndlp)
5136 struct lpfc_hba *phba = vport->phba;
5137 LPFC_MBOXQ_t *mbox;
5138 struct lpfc_dmabuf *pcmd;
5139 struct ls_rjt stat;
5141 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5142 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5143 /* reject the unsolicited RPS request and done with it */
5144 goto reject_out;
5146 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5148 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
5149 if (mbox) {
5150 lpfc_read_lnk_stat(phba, mbox);
5151 mbox->context1 =
5152 (void *)((unsigned long) cmdiocb->iocb.ulpContext);
5153 mbox->context2 = lpfc_nlp_get(ndlp);
5154 mbox->vport = vport;
5155 mbox->mbox_cmpl = lpfc_els_rsp_rls_acc;
5156 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
5157 != MBX_NOT_FINISHED)
5158 /* Mbox completion will send ELS Response */
5159 return 0;
5160 /* Decrement reference count used for the failed mbox
5161 * command.
5163 lpfc_nlp_put(ndlp);
5164 mempool_free(mbox, phba->mbox_mem_pool);
5166 reject_out:
5167 /* issue rejection response */
5168 stat.un.b.lsRjtRsvd0 = 0;
5169 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5170 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5171 stat.un.b.vendorUnique = 0;
5172 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5173 return 0;
5177 * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
5178 * @vport: pointer to a host virtual N_Port data structure.
5179 * @cmdiocb: pointer to lpfc command iocb data structure.
5180 * @ndlp: pointer to a node-list data structure.
5182 * This routine processes Read Timout Value (RTV) IOCB received as an
5183 * ELS unsolicited event. It first checks the remote port state. If the
5184 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5185 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
5186 * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
5187 * Value (RTV) unsolicited IOCB event.
5189 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5190 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5191 * will be stored into the context1 field of the IOCB for the completion
5192 * callback function to the RPS Accept Response ELS IOCB command.
5194 * Return codes
5195 * 0 - Successfully processed rtv iocb (currently always return 0)
5197 static int
5198 lpfc_els_rcv_rtv(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5199 struct lpfc_nodelist *ndlp)
5201 struct lpfc_hba *phba = vport->phba;
5202 struct ls_rjt stat;
5203 struct RTV_RSP *rtv_rsp;
5204 uint8_t *pcmd;
5205 struct lpfc_iocbq *elsiocb;
5206 uint32_t cmdsize;
5209 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5210 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5211 /* reject the unsolicited RPS request and done with it */
5212 goto reject_out;
5214 cmdsize = sizeof(struct RTV_RSP) + sizeof(uint32_t);
5215 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
5216 lpfc_max_els_tries, ndlp,
5217 ndlp->nlp_DID, ELS_CMD_ACC);
5219 if (!elsiocb)
5220 return 1;
5222 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5223 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5224 pcmd += sizeof(uint32_t); /* Skip past command */
5226 /* use the command's xri in the response */
5227 elsiocb->iocb.ulpContext = cmdiocb->iocb.ulpContext;
5229 rtv_rsp = (struct RTV_RSP *)pcmd;
5231 /* populate RTV payload */
5232 rtv_rsp->ratov = cpu_to_be32(phba->fc_ratov * 1000); /* report msecs */
5233 rtv_rsp->edtov = cpu_to_be32(phba->fc_edtov);
5234 bf_set(qtov_edtovres, rtv_rsp, phba->fc_edtovResol ? 1 : 0);
5235 bf_set(qtov_rttov, rtv_rsp, 0); /* Field is for FC ONLY */
5236 rtv_rsp->qtov = cpu_to_be32(rtv_rsp->qtov);
5238 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
5239 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
5240 "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
5241 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
5242 "Data: x%x x%x x%x\n",
5243 elsiocb->iotag, elsiocb->iocb.ulpContext,
5244 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5245 ndlp->nlp_rpi,
5246 rtv_rsp->ratov, rtv_rsp->edtov, rtv_rsp->qtov);
5247 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5248 phba->fc_stat.elsXmitACC++;
5249 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
5250 lpfc_els_free_iocb(phba, elsiocb);
5251 return 0;
5253 reject_out:
5254 /* issue rejection response */
5255 stat.un.b.lsRjtRsvd0 = 0;
5256 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5257 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5258 stat.un.b.vendorUnique = 0;
5259 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5260 return 0;
5263 /* lpfc_els_rcv_rps - Process an unsolicited rps iocb
5264 * @vport: pointer to a host virtual N_Port data structure.
5265 * @cmdiocb: pointer to lpfc command iocb data structure.
5266 * @ndlp: pointer to a node-list data structure.
5268 * This routine processes Read Port Status (RPS) IOCB received as an
5269 * ELS unsolicited event. It first checks the remote port state. If the
5270 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5271 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
5272 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
5273 * for reading the HBA link statistics. It is for the callback function,
5274 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
5275 * to actually sending out RPS Accept (ACC) response.
5277 * Return codes
5278 * 0 - Successfully processed rps iocb (currently always return 0)
5280 static int
5281 lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5282 struct lpfc_nodelist *ndlp)
5284 struct lpfc_hba *phba = vport->phba;
5285 uint32_t *lp;
5286 uint8_t flag;
5287 LPFC_MBOXQ_t *mbox;
5288 struct lpfc_dmabuf *pcmd;
5289 RPS *rps;
5290 struct ls_rjt stat;
5292 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5293 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
5294 /* reject the unsolicited RPS request and done with it */
5295 goto reject_out;
5297 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5298 lp = (uint32_t *) pcmd->virt;
5299 flag = (be32_to_cpu(*lp++) & 0xf);
5300 rps = (RPS *) lp;
5302 if ((flag == 0) ||
5303 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
5304 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
5305 sizeof(struct lpfc_name)) == 0))) {
5307 printk("Fix me....\n");
5308 dump_stack();
5309 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
5310 if (mbox) {
5311 lpfc_read_lnk_stat(phba, mbox);
5312 mbox->context1 =
5313 (void *)((unsigned long) cmdiocb->iocb.ulpContext);
5314 mbox->context2 = lpfc_nlp_get(ndlp);
5315 mbox->vport = vport;
5316 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
5317 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
5318 != MBX_NOT_FINISHED)
5319 /* Mbox completion will send ELS Response */
5320 return 0;
5321 /* Decrement reference count used for the failed mbox
5322 * command.
5324 lpfc_nlp_put(ndlp);
5325 mempool_free(mbox, phba->mbox_mem_pool);
5329 reject_out:
5330 /* issue rejection response */
5331 stat.un.b.lsRjtRsvd0 = 0;
5332 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5333 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5334 stat.un.b.vendorUnique = 0;
5335 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
5336 return 0;
5339 /* lpfc_issue_els_rrq - Process an unsolicited rps iocb
5340 * @vport: pointer to a host virtual N_Port data structure.
5341 * @ndlp: pointer to a node-list data structure.
5342 * @did: DID of the target.
5343 * @rrq: Pointer to the rrq struct.
5345 * Build a ELS RRQ command and send it to the target. If the issue_iocb is
5346 * Successful the the completion handler will clear the RRQ.
5348 * Return codes
5349 * 0 - Successfully sent rrq els iocb.
5350 * 1 - Failed to send rrq els iocb.
5352 static int
5353 lpfc_issue_els_rrq(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
5354 uint32_t did, struct lpfc_node_rrq *rrq)
5356 struct lpfc_hba *phba = vport->phba;
5357 struct RRQ *els_rrq;
5358 IOCB_t *icmd;
5359 struct lpfc_iocbq *elsiocb;
5360 uint8_t *pcmd;
5361 uint16_t cmdsize;
5362 int ret;
5365 if (ndlp != rrq->ndlp)
5366 ndlp = rrq->ndlp;
5367 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
5368 return 1;
5370 /* If ndlp is not NULL, we will bump the reference count on it */
5371 cmdsize = (sizeof(uint32_t) + sizeof(struct RRQ));
5372 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, did,
5373 ELS_CMD_RRQ);
5374 if (!elsiocb)
5375 return 1;
5377 icmd = &elsiocb->iocb;
5378 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5380 /* For RRQ request, remainder of payload is Exchange IDs */
5381 *((uint32_t *) (pcmd)) = ELS_CMD_RRQ;
5382 pcmd += sizeof(uint32_t);
5383 els_rrq = (struct RRQ *) pcmd;
5385 bf_set(rrq_oxid, els_rrq, rrq->xritag);
5386 bf_set(rrq_rxid, els_rrq, rrq->rxid);
5387 bf_set(rrq_did, els_rrq, vport->fc_myDID);
5388 els_rrq->rrq = cpu_to_be32(els_rrq->rrq);
5389 els_rrq->rrq_exchg = cpu_to_be32(els_rrq->rrq_exchg);
5392 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
5393 "Issue RRQ: did:x%x",
5394 did, rrq->xritag, rrq->rxid);
5395 elsiocb->context_un.rrq = rrq;
5396 elsiocb->iocb_cmpl = lpfc_cmpl_els_rrq;
5397 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
5399 if (ret == IOCB_ERROR) {
5400 lpfc_els_free_iocb(phba, elsiocb);
5401 return 1;
5403 return 0;
5407 * lpfc_send_rrq - Sends ELS RRQ if needed.
5408 * @phba: pointer to lpfc hba data structure.
5409 * @rrq: pointer to the active rrq.
5411 * This routine will call the lpfc_issue_els_rrq if the rrq is
5412 * still active for the xri. If this function returns a failure then
5413 * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq.
5415 * Returns 0 Success.
5416 * 1 Failure.
5419 lpfc_send_rrq(struct lpfc_hba *phba, struct lpfc_node_rrq *rrq)
5421 struct lpfc_nodelist *ndlp = lpfc_findnode_did(rrq->vport,
5422 rrq->nlp_DID);
5423 if (lpfc_test_rrq_active(phba, ndlp, rrq->xritag))
5424 return lpfc_issue_els_rrq(rrq->vport, ndlp,
5425 rrq->nlp_DID, rrq);
5426 else
5427 return 1;
5431 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
5432 * @vport: pointer to a host virtual N_Port data structure.
5433 * @cmdsize: size of the ELS command.
5434 * @oldiocb: pointer to the original lpfc command iocb data structure.
5435 * @ndlp: pointer to a node-list data structure.
5437 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
5438 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
5440 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5441 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5442 * will be stored into the context1 field of the IOCB for the completion
5443 * callback function to the RPL Accept Response ELS command.
5445 * Return code
5446 * 0 - Successfully issued ACC RPL ELS command
5447 * 1 - Failed to issue ACC RPL ELS command
5449 static int
5450 lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
5451 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
5453 struct lpfc_hba *phba = vport->phba;
5454 IOCB_t *icmd, *oldcmd;
5455 RPL_RSP rpl_rsp;
5456 struct lpfc_iocbq *elsiocb;
5457 uint8_t *pcmd;
5459 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
5460 ndlp->nlp_DID, ELS_CMD_ACC);
5462 if (!elsiocb)
5463 return 1;
5465 icmd = &elsiocb->iocb;
5466 oldcmd = &oldiocb->iocb;
5467 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
5469 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5470 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
5471 pcmd += sizeof(uint16_t);
5472 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
5473 pcmd += sizeof(uint16_t);
5475 /* Setup the RPL ACC payload */
5476 rpl_rsp.listLen = be32_to_cpu(1);
5477 rpl_rsp.index = 0;
5478 rpl_rsp.port_num_blk.portNum = 0;
5479 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
5480 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
5481 sizeof(struct lpfc_name));
5482 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
5483 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
5484 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5485 "0120 Xmit ELS RPL ACC response tag x%x "
5486 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
5487 "rpi x%x\n",
5488 elsiocb->iotag, elsiocb->iocb.ulpContext,
5489 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
5490 ndlp->nlp_rpi);
5491 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
5492 phba->fc_stat.elsXmitACC++;
5493 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
5494 IOCB_ERROR) {
5495 lpfc_els_free_iocb(phba, elsiocb);
5496 return 1;
5498 return 0;
5502 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
5503 * @vport: pointer to a host virtual N_Port data structure.
5504 * @cmdiocb: pointer to lpfc command iocb data structure.
5505 * @ndlp: pointer to a node-list data structure.
5507 * This routine processes Read Port List (RPL) IOCB received as an ELS
5508 * unsolicited event. It first checks the remote port state. If the remote
5509 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
5510 * invokes the lpfc_els_rsp_reject() routine to send reject response.
5511 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
5512 * to accept the RPL.
5514 * Return code
5515 * 0 - Successfully processed rpl iocb (currently always return 0)
5517 static int
5518 lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5519 struct lpfc_nodelist *ndlp)
5521 struct lpfc_dmabuf *pcmd;
5522 uint32_t *lp;
5523 uint32_t maxsize;
5524 uint16_t cmdsize;
5525 RPL *rpl;
5526 struct ls_rjt stat;
5528 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
5529 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
5530 /* issue rejection response */
5531 stat.un.b.lsRjtRsvd0 = 0;
5532 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
5533 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
5534 stat.un.b.vendorUnique = 0;
5535 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
5536 NULL);
5537 /* rejected the unsolicited RPL request and done with it */
5538 return 0;
5541 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5542 lp = (uint32_t *) pcmd->virt;
5543 rpl = (RPL *) (lp + 1);
5544 maxsize = be32_to_cpu(rpl->maxsize);
5546 /* We support only one port */
5547 if ((rpl->index == 0) &&
5548 ((maxsize == 0) ||
5549 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
5550 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
5551 } else {
5552 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
5554 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
5556 return 0;
5560 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
5561 * @vport: pointer to a virtual N_Port data structure.
5562 * @cmdiocb: pointer to lpfc command iocb data structure.
5563 * @ndlp: pointer to a node-list data structure.
5565 * This routine processes Fibre Channel Address Resolution Protocol
5566 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
5567 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
5568 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
5569 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
5570 * remote PortName is compared against the FC PortName stored in the @vport
5571 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
5572 * compared against the FC NodeName stored in the @vport data structure.
5573 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
5574 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
5575 * invoked to send out FARP Response to the remote node. Before sending the
5576 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
5577 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
5578 * routine is invoked to log into the remote port first.
5580 * Return code
5581 * 0 - Either the FARP Match Mode not supported or successfully processed
5583 static int
5584 lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5585 struct lpfc_nodelist *ndlp)
5587 struct lpfc_dmabuf *pcmd;
5588 uint32_t *lp;
5589 IOCB_t *icmd;
5590 FARP *fp;
5591 uint32_t cmd, cnt, did;
5593 icmd = &cmdiocb->iocb;
5594 did = icmd->un.elsreq64.remoteID;
5595 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5596 lp = (uint32_t *) pcmd->virt;
5598 cmd = *lp++;
5599 fp = (FARP *) lp;
5600 /* FARP-REQ received from DID <did> */
5601 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5602 "0601 FARP-REQ received from DID x%x\n", did);
5603 /* We will only support match on WWPN or WWNN */
5604 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
5605 return 0;
5608 cnt = 0;
5609 /* If this FARP command is searching for my portname */
5610 if (fp->Mflags & FARP_MATCH_PORT) {
5611 if (memcmp(&fp->RportName, &vport->fc_portname,
5612 sizeof(struct lpfc_name)) == 0)
5613 cnt = 1;
5616 /* If this FARP command is searching for my nodename */
5617 if (fp->Mflags & FARP_MATCH_NODE) {
5618 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
5619 sizeof(struct lpfc_name)) == 0)
5620 cnt = 1;
5623 if (cnt) {
5624 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
5625 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
5626 /* Log back into the node before sending the FARP. */
5627 if (fp->Rflags & FARP_REQUEST_PLOGI) {
5628 ndlp->nlp_prev_state = ndlp->nlp_state;
5629 lpfc_nlp_set_state(vport, ndlp,
5630 NLP_STE_PLOGI_ISSUE);
5631 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
5634 /* Send a FARP response to that node */
5635 if (fp->Rflags & FARP_REQUEST_FARPR)
5636 lpfc_issue_els_farpr(vport, did, 0);
5639 return 0;
5643 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
5644 * @vport: pointer to a host virtual N_Port data structure.
5645 * @cmdiocb: pointer to lpfc command iocb data structure.
5646 * @ndlp: pointer to a node-list data structure.
5648 * This routine processes Fibre Channel Address Resolution Protocol
5649 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
5650 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
5651 * the FARP response request.
5653 * Return code
5654 * 0 - Successfully processed FARPR IOCB (currently always return 0)
5656 static int
5657 lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5658 struct lpfc_nodelist *ndlp)
5660 struct lpfc_dmabuf *pcmd;
5661 uint32_t *lp;
5662 IOCB_t *icmd;
5663 uint32_t cmd, did;
5665 icmd = &cmdiocb->iocb;
5666 did = icmd->un.elsreq64.remoteID;
5667 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
5668 lp = (uint32_t *) pcmd->virt;
5670 cmd = *lp++;
5671 /* FARP-RSP received from DID <did> */
5672 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5673 "0600 FARP-RSP received from DID x%x\n", did);
5674 /* ACCEPT the Farp resp request */
5675 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
5677 return 0;
5681 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
5682 * @vport: pointer to a host virtual N_Port data structure.
5683 * @cmdiocb: pointer to lpfc command iocb data structure.
5684 * @fan_ndlp: pointer to a node-list data structure.
5686 * This routine processes a Fabric Address Notification (FAN) IOCB
5687 * command received as an ELS unsolicited event. The FAN ELS command will
5688 * only be processed on a physical port (i.e., the @vport represents the
5689 * physical port). The fabric NodeName and PortName from the FAN IOCB are
5690 * compared against those in the phba data structure. If any of those is
5691 * different, the lpfc_initial_flogi() routine is invoked to initialize
5692 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
5693 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
5694 * is invoked to register login to the fabric.
5696 * Return code
5697 * 0 - Successfully processed fan iocb (currently always return 0).
5699 static int
5700 lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
5701 struct lpfc_nodelist *fan_ndlp)
5703 struct lpfc_hba *phba = vport->phba;
5704 uint32_t *lp;
5705 FAN *fp;
5707 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
5708 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
5709 fp = (FAN *) ++lp;
5710 /* FAN received; Fan does not have a reply sequence */
5711 if ((vport == phba->pport) &&
5712 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
5713 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
5714 sizeof(struct lpfc_name))) ||
5715 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
5716 sizeof(struct lpfc_name)))) {
5717 /* This port has switched fabrics. FLOGI is required */
5718 lpfc_issue_init_vfi(vport);
5719 } else {
5720 /* FAN verified - skip FLOGI */
5721 vport->fc_myDID = vport->fc_prevDID;
5722 if (phba->sli_rev < LPFC_SLI_REV4)
5723 lpfc_issue_fabric_reglogin(vport);
5724 else
5725 lpfc_issue_reg_vfi(vport);
5728 return 0;
5732 * lpfc_els_timeout - Handler funciton to the els timer
5733 * @ptr: holder for the timer function associated data.
5735 * This routine is invoked by the ELS timer after timeout. It posts the ELS
5736 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
5737 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
5738 * up the worker thread. It is for the worker thread to invoke the routine
5739 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
5741 void
5742 lpfc_els_timeout(unsigned long ptr)
5744 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
5745 struct lpfc_hba *phba = vport->phba;
5746 uint32_t tmo_posted;
5747 unsigned long iflag;
5749 spin_lock_irqsave(&vport->work_port_lock, iflag);
5750 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
5751 if (!tmo_posted)
5752 vport->work_port_events |= WORKER_ELS_TMO;
5753 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
5755 if (!tmo_posted)
5756 lpfc_worker_wake_up(phba);
5757 return;
5762 * lpfc_els_timeout_handler - Process an els timeout event
5763 * @vport: pointer to a virtual N_Port data structure.
5765 * This routine is the actual handler function that processes an ELS timeout
5766 * event. It walks the ELS ring to get and abort all the IOCBs (except the
5767 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
5768 * invoking the lpfc_sli_issue_abort_iotag() routine.
5770 void
5771 lpfc_els_timeout_handler(struct lpfc_vport *vport)
5773 struct lpfc_hba *phba = vport->phba;
5774 struct lpfc_sli_ring *pring;
5775 struct lpfc_iocbq *tmp_iocb, *piocb;
5776 IOCB_t *cmd = NULL;
5777 struct lpfc_dmabuf *pcmd;
5778 uint32_t els_command = 0;
5779 uint32_t timeout;
5780 uint32_t remote_ID = 0xffffffff;
5781 LIST_HEAD(txcmplq_completions);
5782 LIST_HEAD(abort_list);
5785 timeout = (uint32_t)(phba->fc_ratov << 1);
5787 pring = &phba->sli.ring[LPFC_ELS_RING];
5789 spin_lock_irq(&phba->hbalock);
5790 list_splice_init(&pring->txcmplq, &txcmplq_completions);
5791 spin_unlock_irq(&phba->hbalock);
5793 list_for_each_entry_safe(piocb, tmp_iocb, &txcmplq_completions, list) {
5794 cmd = &piocb->iocb;
5796 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
5797 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
5798 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
5799 continue;
5801 if (piocb->vport != vport)
5802 continue;
5804 pcmd = (struct lpfc_dmabuf *) piocb->context2;
5805 if (pcmd)
5806 els_command = *(uint32_t *) (pcmd->virt);
5808 if (els_command == ELS_CMD_FARP ||
5809 els_command == ELS_CMD_FARPR ||
5810 els_command == ELS_CMD_FDISC)
5811 continue;
5813 if (piocb->drvrTimeout > 0) {
5814 if (piocb->drvrTimeout >= timeout)
5815 piocb->drvrTimeout -= timeout;
5816 else
5817 piocb->drvrTimeout = 0;
5818 continue;
5821 remote_ID = 0xffffffff;
5822 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
5823 remote_ID = cmd->un.elsreq64.remoteID;
5824 else {
5825 struct lpfc_nodelist *ndlp;
5826 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
5827 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
5828 remote_ID = ndlp->nlp_DID;
5830 list_add_tail(&piocb->dlist, &abort_list);
5832 spin_lock_irq(&phba->hbalock);
5833 list_splice(&txcmplq_completions, &pring->txcmplq);
5834 spin_unlock_irq(&phba->hbalock);
5836 list_for_each_entry_safe(piocb, tmp_iocb, &abort_list, dlist) {
5837 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5838 "0127 ELS timeout Data: x%x x%x x%x "
5839 "x%x\n", els_command,
5840 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
5841 spin_lock_irq(&phba->hbalock);
5842 list_del_init(&piocb->dlist);
5843 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
5844 spin_unlock_irq(&phba->hbalock);
5847 if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt)
5848 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
5852 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
5853 * @vport: pointer to a host virtual N_Port data structure.
5855 * This routine is used to clean up all the outstanding ELS commands on a
5856 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
5857 * routine. After that, it walks the ELS transmit queue to remove all the
5858 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
5859 * the IOCBs with a non-NULL completion callback function, the callback
5860 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
5861 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
5862 * callback function, the IOCB will simply be released. Finally, it walks
5863 * the ELS transmit completion queue to issue an abort IOCB to any transmit
5864 * completion queue IOCB that is associated with the @vport and is not
5865 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
5866 * part of the discovery state machine) out to HBA by invoking the
5867 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
5868 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
5869 * the IOCBs are aborted when this function returns.
5871 void
5872 lpfc_els_flush_cmd(struct lpfc_vport *vport)
5874 LIST_HEAD(completions);
5875 struct lpfc_hba *phba = vport->phba;
5876 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
5877 struct lpfc_iocbq *tmp_iocb, *piocb;
5878 IOCB_t *cmd = NULL;
5880 lpfc_fabric_abort_vport(vport);
5882 spin_lock_irq(&phba->hbalock);
5883 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
5884 cmd = &piocb->iocb;
5886 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
5887 continue;
5890 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
5891 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
5892 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
5893 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
5894 cmd->ulpCommand == CMD_ABORT_XRI_CN)
5895 continue;
5897 if (piocb->vport != vport)
5898 continue;
5900 list_move_tail(&piocb->list, &completions);
5901 pring->txq_cnt--;
5904 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
5905 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
5906 continue;
5909 if (piocb->vport != vport)
5910 continue;
5912 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
5914 spin_unlock_irq(&phba->hbalock);
5916 /* Cancell all the IOCBs from the completions list */
5917 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
5918 IOERR_SLI_ABORTED);
5920 return;
5924 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
5925 * @phba: pointer to lpfc hba data structure.
5927 * This routine is used to clean up all the outstanding ELS commands on a
5928 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
5929 * routine. After that, it walks the ELS transmit queue to remove all the
5930 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
5931 * the IOCBs with the completion callback function associated, the callback
5932 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
5933 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
5934 * callback function associated, the IOCB will simply be released. Finally,
5935 * it walks the ELS transmit completion queue to issue an abort IOCB to any
5936 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
5937 * management plane IOCBs that are not part of the discovery state machine)
5938 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
5940 void
5941 lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
5943 LIST_HEAD(completions);
5944 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
5945 struct lpfc_iocbq *tmp_iocb, *piocb;
5946 IOCB_t *cmd = NULL;
5948 lpfc_fabric_abort_hba(phba);
5949 spin_lock_irq(&phba->hbalock);
5950 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
5951 cmd = &piocb->iocb;
5952 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
5953 continue;
5954 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
5955 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
5956 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
5957 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
5958 cmd->ulpCommand == CMD_ABORT_XRI_CN)
5959 continue;
5960 list_move_tail(&piocb->list, &completions);
5961 pring->txq_cnt--;
5963 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
5964 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
5965 continue;
5966 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
5968 spin_unlock_irq(&phba->hbalock);
5970 /* Cancel all the IOCBs from the completions list */
5971 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
5972 IOERR_SLI_ABORTED);
5974 return;
5978 * lpfc_send_els_failure_event - Posts an ELS command failure event
5979 * @phba: Pointer to hba context object.
5980 * @cmdiocbp: Pointer to command iocb which reported error.
5981 * @rspiocbp: Pointer to response iocb which reported error.
5983 * This function sends an event when there is an ELS command
5984 * failure.
5986 void
5987 lpfc_send_els_failure_event(struct lpfc_hba *phba,
5988 struct lpfc_iocbq *cmdiocbp,
5989 struct lpfc_iocbq *rspiocbp)
5991 struct lpfc_vport *vport = cmdiocbp->vport;
5992 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5993 struct lpfc_lsrjt_event lsrjt_event;
5994 struct lpfc_fabric_event_header fabric_event;
5995 struct ls_rjt stat;
5996 struct lpfc_nodelist *ndlp;
5997 uint32_t *pcmd;
5999 ndlp = cmdiocbp->context1;
6000 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
6001 return;
6003 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
6004 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
6005 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
6006 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
6007 sizeof(struct lpfc_name));
6008 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
6009 sizeof(struct lpfc_name));
6010 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
6011 cmdiocbp->context2)->virt);
6012 lsrjt_event.command = (pcmd != NULL) ? *pcmd : 0;
6013 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
6014 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
6015 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
6016 fc_host_post_vendor_event(shost,
6017 fc_get_event_number(),
6018 sizeof(lsrjt_event),
6019 (char *)&lsrjt_event,
6020 LPFC_NL_VENDOR_ID);
6021 return;
6023 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
6024 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
6025 fabric_event.event_type = FC_REG_FABRIC_EVENT;
6026 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
6027 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
6028 else
6029 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
6030 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
6031 sizeof(struct lpfc_name));
6032 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
6033 sizeof(struct lpfc_name));
6034 fc_host_post_vendor_event(shost,
6035 fc_get_event_number(),
6036 sizeof(fabric_event),
6037 (char *)&fabric_event,
6038 LPFC_NL_VENDOR_ID);
6039 return;
6045 * lpfc_send_els_event - Posts unsolicited els event
6046 * @vport: Pointer to vport object.
6047 * @ndlp: Pointer FC node object.
6048 * @cmd: ELS command code.
6050 * This function posts an event when there is an incoming
6051 * unsolicited ELS command.
6053 static void
6054 lpfc_send_els_event(struct lpfc_vport *vport,
6055 struct lpfc_nodelist *ndlp,
6056 uint32_t *payload)
6058 struct lpfc_els_event_header *els_data = NULL;
6059 struct lpfc_logo_event *logo_data = NULL;
6060 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6062 if (*payload == ELS_CMD_LOGO) {
6063 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
6064 if (!logo_data) {
6065 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6066 "0148 Failed to allocate memory "
6067 "for LOGO event\n");
6068 return;
6070 els_data = &logo_data->header;
6071 } else {
6072 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
6073 GFP_KERNEL);
6074 if (!els_data) {
6075 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6076 "0149 Failed to allocate memory "
6077 "for ELS event\n");
6078 return;
6081 els_data->event_type = FC_REG_ELS_EVENT;
6082 switch (*payload) {
6083 case ELS_CMD_PLOGI:
6084 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
6085 break;
6086 case ELS_CMD_PRLO:
6087 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
6088 break;
6089 case ELS_CMD_ADISC:
6090 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
6091 break;
6092 case ELS_CMD_LOGO:
6093 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
6094 /* Copy the WWPN in the LOGO payload */
6095 memcpy(logo_data->logo_wwpn, &payload[2],
6096 sizeof(struct lpfc_name));
6097 break;
6098 default:
6099 kfree(els_data);
6100 return;
6102 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
6103 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
6104 if (*payload == ELS_CMD_LOGO) {
6105 fc_host_post_vendor_event(shost,
6106 fc_get_event_number(),
6107 sizeof(struct lpfc_logo_event),
6108 (char *)logo_data,
6109 LPFC_NL_VENDOR_ID);
6110 kfree(logo_data);
6111 } else {
6112 fc_host_post_vendor_event(shost,
6113 fc_get_event_number(),
6114 sizeof(struct lpfc_els_event_header),
6115 (char *)els_data,
6116 LPFC_NL_VENDOR_ID);
6117 kfree(els_data);
6120 return;
6125 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
6126 * @phba: pointer to lpfc hba data structure.
6127 * @pring: pointer to a SLI ring.
6128 * @vport: pointer to a host virtual N_Port data structure.
6129 * @elsiocb: pointer to lpfc els command iocb data structure.
6131 * This routine is used for processing the IOCB associated with a unsolicited
6132 * event. It first determines whether there is an existing ndlp that matches
6133 * the DID from the unsolicited IOCB. If not, it will create a new one with
6134 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
6135 * IOCB is then used to invoke the proper routine and to set up proper state
6136 * of the discovery state machine.
6138 static void
6139 lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
6140 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
6142 struct Scsi_Host *shost;
6143 struct lpfc_nodelist *ndlp;
6144 struct ls_rjt stat;
6145 uint32_t *payload;
6146 uint32_t cmd, did, newnode, rjt_err = 0;
6147 IOCB_t *icmd = &elsiocb->iocb;
6149 if (!vport || !(elsiocb->context2))
6150 goto dropit;
6152 newnode = 0;
6153 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
6154 cmd = *payload;
6155 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
6156 lpfc_post_buffer(phba, pring, 1);
6158 did = icmd->un.rcvels.remoteID;
6159 if (icmd->ulpStatus) {
6160 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6161 "RCV Unsol ELS: status:x%x/x%x did:x%x",
6162 icmd->ulpStatus, icmd->un.ulpWord[4], did);
6163 goto dropit;
6166 /* Check to see if link went down during discovery */
6167 if (lpfc_els_chk_latt(vport))
6168 goto dropit;
6170 /* Ignore traffic received during vport shutdown. */
6171 if (vport->load_flag & FC_UNLOADING)
6172 goto dropit;
6174 ndlp = lpfc_findnode_did(vport, did);
6175 if (!ndlp) {
6176 /* Cannot find existing Fabric ndlp, so allocate a new one */
6177 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
6178 if (!ndlp)
6179 goto dropit;
6181 lpfc_nlp_init(vport, ndlp, did);
6182 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
6183 newnode = 1;
6184 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
6185 ndlp->nlp_type |= NLP_FABRIC;
6186 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
6187 ndlp = lpfc_enable_node(vport, ndlp,
6188 NLP_STE_UNUSED_NODE);
6189 if (!ndlp)
6190 goto dropit;
6191 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
6192 newnode = 1;
6193 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
6194 ndlp->nlp_type |= NLP_FABRIC;
6195 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
6196 /* This is similar to the new node path */
6197 ndlp = lpfc_nlp_get(ndlp);
6198 if (!ndlp)
6199 goto dropit;
6200 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
6201 newnode = 1;
6204 phba->fc_stat.elsRcvFrame++;
6206 elsiocb->context1 = lpfc_nlp_get(ndlp);
6207 elsiocb->vport = vport;
6209 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
6210 cmd &= ELS_CMD_MASK;
6212 /* ELS command <elsCmd> received from NPORT <did> */
6213 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6214 "0112 ELS command x%x received from NPORT x%x "
6215 "Data: x%x\n", cmd, did, vport->port_state);
6216 switch (cmd) {
6217 case ELS_CMD_PLOGI:
6218 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6219 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
6220 did, vport->port_state, ndlp->nlp_flag);
6222 phba->fc_stat.elsRcvPLOGI++;
6223 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
6225 lpfc_send_els_event(vport, ndlp, payload);
6226 if (vport->port_state < LPFC_DISC_AUTH) {
6227 if (!(phba->pport->fc_flag & FC_PT2PT) ||
6228 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
6229 rjt_err = LSRJT_UNABLE_TPC;
6230 break;
6232 /* We get here, and drop thru, if we are PT2PT with
6233 * another NPort and the other side has initiated
6234 * the PLOGI before responding to our FLOGI.
6238 shost = lpfc_shost_from_vport(vport);
6239 spin_lock_irq(shost->host_lock);
6240 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
6241 spin_unlock_irq(shost->host_lock);
6243 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6244 NLP_EVT_RCV_PLOGI);
6246 break;
6247 case ELS_CMD_FLOGI:
6248 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6249 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
6250 did, vport->port_state, ndlp->nlp_flag);
6252 phba->fc_stat.elsRcvFLOGI++;
6253 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
6254 if (newnode)
6255 lpfc_nlp_put(ndlp);
6256 break;
6257 case ELS_CMD_LOGO:
6258 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6259 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
6260 did, vport->port_state, ndlp->nlp_flag);
6262 phba->fc_stat.elsRcvLOGO++;
6263 lpfc_send_els_event(vport, ndlp, payload);
6264 if (vport->port_state < LPFC_DISC_AUTH) {
6265 rjt_err = LSRJT_UNABLE_TPC;
6266 break;
6268 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
6269 break;
6270 case ELS_CMD_PRLO:
6271 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6272 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
6273 did, vport->port_state, ndlp->nlp_flag);
6275 phba->fc_stat.elsRcvPRLO++;
6276 lpfc_send_els_event(vport, ndlp, payload);
6277 if (vport->port_state < LPFC_DISC_AUTH) {
6278 rjt_err = LSRJT_UNABLE_TPC;
6279 break;
6281 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
6282 break;
6283 case ELS_CMD_RSCN:
6284 phba->fc_stat.elsRcvRSCN++;
6285 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
6286 if (newnode)
6287 lpfc_nlp_put(ndlp);
6288 break;
6289 case ELS_CMD_ADISC:
6290 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6291 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
6292 did, vport->port_state, ndlp->nlp_flag);
6294 lpfc_send_els_event(vport, ndlp, payload);
6295 phba->fc_stat.elsRcvADISC++;
6296 if (vport->port_state < LPFC_DISC_AUTH) {
6297 rjt_err = LSRJT_UNABLE_TPC;
6298 break;
6300 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6301 NLP_EVT_RCV_ADISC);
6302 break;
6303 case ELS_CMD_PDISC:
6304 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6305 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
6306 did, vport->port_state, ndlp->nlp_flag);
6308 phba->fc_stat.elsRcvPDISC++;
6309 if (vport->port_state < LPFC_DISC_AUTH) {
6310 rjt_err = LSRJT_UNABLE_TPC;
6311 break;
6313 lpfc_disc_state_machine(vport, ndlp, elsiocb,
6314 NLP_EVT_RCV_PDISC);
6315 break;
6316 case ELS_CMD_FARPR:
6317 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6318 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
6319 did, vport->port_state, ndlp->nlp_flag);
6321 phba->fc_stat.elsRcvFARPR++;
6322 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
6323 break;
6324 case ELS_CMD_FARP:
6325 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6326 "RCV FARP: did:x%x/ste:x%x flg:x%x",
6327 did, vport->port_state, ndlp->nlp_flag);
6329 phba->fc_stat.elsRcvFARP++;
6330 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
6331 break;
6332 case ELS_CMD_FAN:
6333 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6334 "RCV FAN: did:x%x/ste:x%x flg:x%x",
6335 did, vport->port_state, ndlp->nlp_flag);
6337 phba->fc_stat.elsRcvFAN++;
6338 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
6339 break;
6340 case ELS_CMD_PRLI:
6341 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6342 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
6343 did, vport->port_state, ndlp->nlp_flag);
6345 phba->fc_stat.elsRcvPRLI++;
6346 if (vport->port_state < LPFC_DISC_AUTH) {
6347 rjt_err = LSRJT_UNABLE_TPC;
6348 break;
6350 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
6351 break;
6352 case ELS_CMD_LIRR:
6353 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6354 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
6355 did, vport->port_state, ndlp->nlp_flag);
6357 phba->fc_stat.elsRcvLIRR++;
6358 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
6359 if (newnode)
6360 lpfc_nlp_put(ndlp);
6361 break;
6362 case ELS_CMD_RLS:
6363 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6364 "RCV RLS: did:x%x/ste:x%x flg:x%x",
6365 did, vport->port_state, ndlp->nlp_flag);
6367 phba->fc_stat.elsRcvRLS++;
6368 lpfc_els_rcv_rls(vport, elsiocb, ndlp);
6369 if (newnode)
6370 lpfc_nlp_put(ndlp);
6371 break;
6372 case ELS_CMD_RPS:
6373 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6374 "RCV RPS: did:x%x/ste:x%x flg:x%x",
6375 did, vport->port_state, ndlp->nlp_flag);
6377 phba->fc_stat.elsRcvRPS++;
6378 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
6379 if (newnode)
6380 lpfc_nlp_put(ndlp);
6381 break;
6382 case ELS_CMD_RPL:
6383 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6384 "RCV RPL: did:x%x/ste:x%x flg:x%x",
6385 did, vport->port_state, ndlp->nlp_flag);
6387 phba->fc_stat.elsRcvRPL++;
6388 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
6389 if (newnode)
6390 lpfc_nlp_put(ndlp);
6391 break;
6392 case ELS_CMD_RNID:
6393 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6394 "RCV RNID: did:x%x/ste:x%x flg:x%x",
6395 did, vport->port_state, ndlp->nlp_flag);
6397 phba->fc_stat.elsRcvRNID++;
6398 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
6399 if (newnode)
6400 lpfc_nlp_put(ndlp);
6401 break;
6402 case ELS_CMD_RTV:
6403 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6404 "RCV RTV: did:x%x/ste:x%x flg:x%x",
6405 did, vport->port_state, ndlp->nlp_flag);
6406 phba->fc_stat.elsRcvRTV++;
6407 lpfc_els_rcv_rtv(vport, elsiocb, ndlp);
6408 if (newnode)
6409 lpfc_nlp_put(ndlp);
6410 break;
6411 case ELS_CMD_RRQ:
6412 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6413 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
6414 did, vport->port_state, ndlp->nlp_flag);
6416 phba->fc_stat.elsRcvRRQ++;
6417 lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
6418 if (newnode)
6419 lpfc_nlp_put(ndlp);
6420 break;
6421 case ELS_CMD_ECHO:
6422 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6423 "RCV ECHO: did:x%x/ste:x%x flg:x%x",
6424 did, vport->port_state, ndlp->nlp_flag);
6426 phba->fc_stat.elsRcvECHO++;
6427 lpfc_els_rcv_echo(vport, elsiocb, ndlp);
6428 if (newnode)
6429 lpfc_nlp_put(ndlp);
6430 break;
6431 default:
6432 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
6433 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
6434 cmd, did, vport->port_state);
6436 /* Unsupported ELS command, reject */
6437 rjt_err = LSRJT_CMD_UNSUPPORTED;
6439 /* Unknown ELS command <elsCmd> received from NPORT <did> */
6440 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6441 "0115 Unknown ELS command x%x "
6442 "received from NPORT x%x\n", cmd, did);
6443 if (newnode)
6444 lpfc_nlp_put(ndlp);
6445 break;
6448 /* check if need to LS_RJT received ELS cmd */
6449 if (rjt_err) {
6450 memset(&stat, 0, sizeof(stat));
6451 stat.un.b.lsRjtRsnCode = rjt_err;
6452 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
6453 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
6454 NULL);
6457 lpfc_nlp_put(elsiocb->context1);
6458 elsiocb->context1 = NULL;
6459 return;
6461 dropit:
6462 if (vport && !(vport->load_flag & FC_UNLOADING))
6463 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6464 "0111 Dropping received ELS cmd "
6465 "Data: x%x x%x x%x\n",
6466 icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout);
6467 phba->fc_stat.elsRcvDrop++;
6471 * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier
6472 * @phba: pointer to lpfc hba data structure.
6473 * @vpi: host virtual N_Port identifier.
6475 * This routine finds a vport on a HBA (referred by @phba) through a
6476 * @vpi. The function walks the HBA's vport list and returns the address
6477 * of the vport with the matching @vpi.
6479 * Return code
6480 * NULL - No vport with the matching @vpi found
6481 * Otherwise - Address to the vport with the matching @vpi.
6483 struct lpfc_vport *
6484 lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
6486 struct lpfc_vport *vport;
6487 unsigned long flags;
6489 spin_lock_irqsave(&phba->hbalock, flags);
6490 list_for_each_entry(vport, &phba->port_list, listentry) {
6491 if (vport->vpi == vpi) {
6492 spin_unlock_irqrestore(&phba->hbalock, flags);
6493 return vport;
6496 spin_unlock_irqrestore(&phba->hbalock, flags);
6497 return NULL;
6501 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
6502 * @phba: pointer to lpfc hba data structure.
6503 * @pring: pointer to a SLI ring.
6504 * @elsiocb: pointer to lpfc els iocb data structure.
6506 * This routine is used to process an unsolicited event received from a SLI
6507 * (Service Level Interface) ring. The actual processing of the data buffer
6508 * associated with the unsolicited event is done by invoking the routine
6509 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
6510 * SLI ring on which the unsolicited event was received.
6512 void
6513 lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
6514 struct lpfc_iocbq *elsiocb)
6516 struct lpfc_vport *vport = phba->pport;
6517 IOCB_t *icmd = &elsiocb->iocb;
6518 dma_addr_t paddr;
6519 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
6520 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
6522 elsiocb->context1 = NULL;
6523 elsiocb->context2 = NULL;
6524 elsiocb->context3 = NULL;
6526 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
6527 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
6528 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
6529 (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) {
6530 phba->fc_stat.NoRcvBuf++;
6531 /* Not enough posted buffers; Try posting more buffers */
6532 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
6533 lpfc_post_buffer(phba, pring, 0);
6534 return;
6537 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
6538 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
6539 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
6540 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
6541 vport = phba->pport;
6542 else
6543 vport = lpfc_find_vport_by_vpid(phba,
6544 icmd->unsli3.rcvsli3.vpi - phba->vpi_base);
6546 /* If there are no BDEs associated
6547 * with this IOCB, there is nothing to do.
6549 if (icmd->ulpBdeCount == 0)
6550 return;
6552 /* type of ELS cmd is first 32bit word
6553 * in packet
6555 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
6556 elsiocb->context2 = bdeBuf1;
6557 } else {
6558 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
6559 icmd->un.cont64[0].addrLow);
6560 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
6561 paddr);
6564 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
6566 * The different unsolicited event handlers would tell us
6567 * if they are done with "mp" by setting context2 to NULL.
6569 if (elsiocb->context2) {
6570 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
6571 elsiocb->context2 = NULL;
6574 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
6575 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
6576 icmd->ulpBdeCount == 2) {
6577 elsiocb->context2 = bdeBuf2;
6578 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
6579 /* free mp if we are done with it */
6580 if (elsiocb->context2) {
6581 lpfc_in_buf_free(phba, elsiocb->context2);
6582 elsiocb->context2 = NULL;
6588 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
6589 * @phba: pointer to lpfc hba data structure.
6590 * @vport: pointer to a virtual N_Port data structure.
6592 * This routine issues a Port Login (PLOGI) to the Name Server with
6593 * State Change Request (SCR) for a @vport. This routine will create an
6594 * ndlp for the Name Server associated to the @vport if such node does
6595 * not already exist. The PLOGI to Name Server is issued by invoking the
6596 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
6597 * (FDMI) is configured to the @vport, a FDMI node will be created and
6598 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
6600 void
6601 lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
6603 struct lpfc_nodelist *ndlp, *ndlp_fdmi;
6605 ndlp = lpfc_findnode_did(vport, NameServer_DID);
6606 if (!ndlp) {
6607 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
6608 if (!ndlp) {
6609 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
6610 lpfc_disc_start(vport);
6611 return;
6613 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6614 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6615 "0251 NameServer login: no memory\n");
6616 return;
6618 lpfc_nlp_init(vport, ndlp, NameServer_DID);
6619 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
6620 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
6621 if (!ndlp) {
6622 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
6623 lpfc_disc_start(vport);
6624 return;
6626 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6627 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6628 "0348 NameServer login: node freed\n");
6629 return;
6632 ndlp->nlp_type |= NLP_FABRIC;
6634 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
6636 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
6637 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6638 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6639 "0252 Cannot issue NameServer login\n");
6640 return;
6643 if (vport->cfg_fdmi_on) {
6644 /* If this is the first time, allocate an ndlp and initialize
6645 * it. Otherwise, make sure the node is enabled and then do the
6646 * login.
6648 ndlp_fdmi = lpfc_findnode_did(vport, FDMI_DID);
6649 if (!ndlp_fdmi) {
6650 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
6651 GFP_KERNEL);
6652 if (ndlp_fdmi) {
6653 lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
6654 ndlp_fdmi->nlp_type |= NLP_FABRIC;
6655 } else
6656 return;
6658 if (!NLP_CHK_NODE_ACT(ndlp_fdmi))
6659 ndlp_fdmi = lpfc_enable_node(vport,
6660 ndlp_fdmi,
6661 NLP_STE_NPR_NODE);
6663 if (ndlp_fdmi) {
6664 lpfc_nlp_set_state(vport, ndlp_fdmi,
6665 NLP_STE_PLOGI_ISSUE);
6666 lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID, 0);
6672 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
6673 * @phba: pointer to lpfc hba data structure.
6674 * @pmb: pointer to the driver internal queue element for mailbox command.
6676 * This routine is the completion callback function to register new vport
6677 * mailbox command. If the new vport mailbox command completes successfully,
6678 * the fabric registration login shall be performed on physical port (the
6679 * new vport created is actually a physical port, with VPI 0) or the port
6680 * login to Name Server for State Change Request (SCR) will be performed
6681 * on virtual port (real virtual port, with VPI greater than 0).
6683 static void
6684 lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
6686 struct lpfc_vport *vport = pmb->vport;
6687 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6688 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
6689 MAILBOX_t *mb = &pmb->u.mb;
6690 int rc;
6692 spin_lock_irq(shost->host_lock);
6693 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
6694 spin_unlock_irq(shost->host_lock);
6696 if (mb->mbxStatus) {
6697 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
6698 "0915 Register VPI failed : Status: x%x"
6699 " upd bit: x%x \n", mb->mbxStatus,
6700 mb->un.varRegVpi.upd);
6701 if (phba->sli_rev == LPFC_SLI_REV4 &&
6702 mb->un.varRegVpi.upd)
6703 goto mbox_err_exit ;
6705 switch (mb->mbxStatus) {
6706 case 0x11: /* unsupported feature */
6707 case 0x9603: /* max_vpi exceeded */
6708 case 0x9602: /* Link event since CLEAR_LA */
6709 /* giving up on vport registration */
6710 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6711 spin_lock_irq(shost->host_lock);
6712 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
6713 spin_unlock_irq(shost->host_lock);
6714 lpfc_can_disctmo(vport);
6715 break;
6716 /* If reg_vpi fail with invalid VPI status, re-init VPI */
6717 case 0x20:
6718 spin_lock_irq(shost->host_lock);
6719 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
6720 spin_unlock_irq(shost->host_lock);
6721 lpfc_init_vpi(phba, pmb, vport->vpi);
6722 pmb->vport = vport;
6723 pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
6724 rc = lpfc_sli_issue_mbox(phba, pmb,
6725 MBX_NOWAIT);
6726 if (rc == MBX_NOT_FINISHED) {
6727 lpfc_printf_vlog(vport,
6728 KERN_ERR, LOG_MBOX,
6729 "2732 Failed to issue INIT_VPI"
6730 " mailbox command\n");
6731 } else {
6732 lpfc_nlp_put(ndlp);
6733 return;
6736 default:
6737 /* Try to recover from this error */
6738 if (phba->sli_rev == LPFC_SLI_REV4)
6739 lpfc_sli4_unreg_all_rpis(vport);
6740 lpfc_mbx_unreg_vpi(vport);
6741 spin_lock_irq(shost->host_lock);
6742 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
6743 spin_unlock_irq(shost->host_lock);
6744 if (vport->port_type == LPFC_PHYSICAL_PORT
6745 && !(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG))
6746 lpfc_issue_init_vfi(vport);
6747 else
6748 lpfc_initial_fdisc(vport);
6749 break;
6751 } else {
6752 spin_lock_irq(shost->host_lock);
6753 vport->vpi_state |= LPFC_VPI_REGISTERED;
6754 spin_unlock_irq(shost->host_lock);
6755 if (vport == phba->pport) {
6756 if (phba->sli_rev < LPFC_SLI_REV4)
6757 lpfc_issue_fabric_reglogin(vport);
6758 else {
6760 * If the physical port is instantiated using
6761 * FDISC, do not start vport discovery.
6763 if (vport->port_state != LPFC_FDISC)
6764 lpfc_start_fdiscs(phba);
6765 lpfc_do_scr_ns_plogi(phba, vport);
6767 } else
6768 lpfc_do_scr_ns_plogi(phba, vport);
6770 mbox_err_exit:
6771 /* Now, we decrement the ndlp reference count held for this
6772 * callback function
6774 lpfc_nlp_put(ndlp);
6776 mempool_free(pmb, phba->mbox_mem_pool);
6777 return;
6781 * lpfc_register_new_vport - Register a new vport with a HBA
6782 * @phba: pointer to lpfc hba data structure.
6783 * @vport: pointer to a host virtual N_Port data structure.
6784 * @ndlp: pointer to a node-list data structure.
6786 * This routine registers the @vport as a new virtual port with a HBA.
6787 * It is done through a registering vpi mailbox command.
6789 void
6790 lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
6791 struct lpfc_nodelist *ndlp)
6793 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6794 LPFC_MBOXQ_t *mbox;
6796 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6797 if (mbox) {
6798 lpfc_reg_vpi(vport, mbox);
6799 mbox->vport = vport;
6800 mbox->context2 = lpfc_nlp_get(ndlp);
6801 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
6802 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
6803 == MBX_NOT_FINISHED) {
6804 /* mailbox command not success, decrement ndlp
6805 * reference count for this command
6807 lpfc_nlp_put(ndlp);
6808 mempool_free(mbox, phba->mbox_mem_pool);
6810 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
6811 "0253 Register VPI: Can't send mbox\n");
6812 goto mbox_err_exit;
6814 } else {
6815 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
6816 "0254 Register VPI: no memory\n");
6817 goto mbox_err_exit;
6819 return;
6821 mbox_err_exit:
6822 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6823 spin_lock_irq(shost->host_lock);
6824 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
6825 spin_unlock_irq(shost->host_lock);
6826 return;
6830 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
6831 * @phba: pointer to lpfc hba data structure.
6833 * This routine cancels the retry delay timers to all the vports.
6835 void
6836 lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba *phba)
6838 struct lpfc_vport **vports;
6839 struct lpfc_nodelist *ndlp;
6840 uint32_t link_state;
6841 int i;
6843 /* Treat this failure as linkdown for all vports */
6844 link_state = phba->link_state;
6845 lpfc_linkdown(phba);
6846 phba->link_state = link_state;
6848 vports = lpfc_create_vport_work_array(phba);
6850 if (vports) {
6851 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
6852 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
6853 if (ndlp)
6854 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
6855 lpfc_els_flush_cmd(vports[i]);
6857 lpfc_destroy_vport_work_array(phba, vports);
6862 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
6863 * @phba: pointer to lpfc hba data structure.
6865 * This routine abort all pending discovery commands and
6866 * start a timer to retry FLOGI for the physical port
6867 * discovery.
6869 void
6870 lpfc_retry_pport_discovery(struct lpfc_hba *phba)
6872 struct lpfc_nodelist *ndlp;
6873 struct Scsi_Host *shost;
6875 /* Cancel the all vports retry delay retry timers */
6876 lpfc_cancel_all_vport_retry_delay_timer(phba);
6878 /* If fabric require FLOGI, then re-instantiate physical login */
6879 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
6880 if (!ndlp)
6881 return;
6883 shost = lpfc_shost_from_vport(phba->pport);
6884 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
6885 spin_lock_irq(shost->host_lock);
6886 ndlp->nlp_flag |= NLP_DELAY_TMO;
6887 spin_unlock_irq(shost->host_lock);
6888 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
6889 phba->pport->port_state = LPFC_FLOGI;
6890 return;
6894 * lpfc_fabric_login_reqd - Check if FLOGI required.
6895 * @phba: pointer to lpfc hba data structure.
6896 * @cmdiocb: pointer to FDISC command iocb.
6897 * @rspiocb: pointer to FDISC response iocb.
6899 * This routine checks if a FLOGI is reguired for FDISC
6900 * to succeed.
6902 static int
6903 lpfc_fabric_login_reqd(struct lpfc_hba *phba,
6904 struct lpfc_iocbq *cmdiocb,
6905 struct lpfc_iocbq *rspiocb)
6908 if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) ||
6909 (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED))
6910 return 0;
6911 else
6912 return 1;
6916 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
6917 * @phba: pointer to lpfc hba data structure.
6918 * @cmdiocb: pointer to lpfc command iocb data structure.
6919 * @rspiocb: pointer to lpfc response iocb data structure.
6921 * This routine is the completion callback function to a Fabric Discover
6922 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
6923 * single threaded, each FDISC completion callback function will reset
6924 * the discovery timer for all vports such that the timers will not get
6925 * unnecessary timeout. The function checks the FDISC IOCB status. If error
6926 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
6927 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
6928 * assigned to the vport has been changed with the completion of the FDISC
6929 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
6930 * are unregistered from the HBA, and then the lpfc_register_new_vport()
6931 * routine is invoked to register new vport with the HBA. Otherwise, the
6932 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
6933 * Server for State Change Request (SCR).
6935 static void
6936 lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6937 struct lpfc_iocbq *rspiocb)
6939 struct lpfc_vport *vport = cmdiocb->vport;
6940 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6941 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
6942 struct lpfc_nodelist *np;
6943 struct lpfc_nodelist *next_np;
6944 IOCB_t *irsp = &rspiocb->iocb;
6945 struct lpfc_iocbq *piocb;
6947 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6948 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
6949 irsp->ulpStatus, irsp->un.ulpWord[4],
6950 vport->fc_prevDID);
6951 /* Since all FDISCs are being single threaded, we
6952 * must reset the discovery timer for ALL vports
6953 * waiting to send FDISC when one completes.
6955 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
6956 lpfc_set_disctmo(piocb->vport);
6959 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6960 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
6961 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
6963 if (irsp->ulpStatus) {
6965 if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
6966 lpfc_retry_pport_discovery(phba);
6967 goto out;
6970 /* Check for retry */
6971 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
6972 goto out;
6973 /* FDISC failed */
6974 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6975 "0126 FDISC failed. (%d/%d)\n",
6976 irsp->ulpStatus, irsp->un.ulpWord[4]);
6977 goto fdisc_failed;
6979 spin_lock_irq(shost->host_lock);
6980 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
6981 vport->fc_flag &= ~FC_VPORT_LOGO_RCVD;
6982 vport->fc_flag |= FC_FABRIC;
6983 if (vport->phba->fc_topology == LPFC_TOPOLOGY_LOOP)
6984 vport->fc_flag |= FC_PUBLIC_LOOP;
6985 spin_unlock_irq(shost->host_lock);
6987 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
6988 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
6989 if ((vport->fc_prevDID != vport->fc_myDID) &&
6990 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
6991 /* If our NportID changed, we need to ensure all
6992 * remaining NPORTs get unreg_login'ed so we can
6993 * issue unreg_vpi.
6995 list_for_each_entry_safe(np, next_np,
6996 &vport->fc_nodes, nlp_listp) {
6997 if (!NLP_CHK_NODE_ACT(ndlp) ||
6998 (np->nlp_state != NLP_STE_NPR_NODE) ||
6999 !(np->nlp_flag & NLP_NPR_ADISC))
7000 continue;
7001 spin_lock_irq(shost->host_lock);
7002 np->nlp_flag &= ~NLP_NPR_ADISC;
7003 spin_unlock_irq(shost->host_lock);
7004 lpfc_unreg_rpi(vport, np);
7006 lpfc_cleanup_pending_mbox(vport);
7008 if (phba->sli_rev == LPFC_SLI_REV4)
7009 lpfc_sli4_unreg_all_rpis(vport);
7011 lpfc_mbx_unreg_vpi(vport);
7012 spin_lock_irq(shost->host_lock);
7013 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
7014 if (phba->sli_rev == LPFC_SLI_REV4)
7015 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
7016 else
7017 vport->fc_flag |= FC_LOGO_RCVD_DID_CHNG;
7018 spin_unlock_irq(shost->host_lock);
7019 } else if ((phba->sli_rev == LPFC_SLI_REV4) &&
7020 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
7022 * Driver needs to re-reg VPI in order for f/w
7023 * to update the MAC address.
7025 lpfc_register_new_vport(phba, vport, ndlp);
7026 goto out;
7029 if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
7030 lpfc_issue_init_vpi(vport);
7031 else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
7032 lpfc_register_new_vport(phba, vport, ndlp);
7033 else
7034 lpfc_do_scr_ns_plogi(phba, vport);
7035 goto out;
7036 fdisc_failed:
7037 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
7038 /* Cancel discovery timer */
7039 lpfc_can_disctmo(vport);
7040 lpfc_nlp_put(ndlp);
7041 out:
7042 lpfc_els_free_iocb(phba, cmdiocb);
7046 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
7047 * @vport: pointer to a virtual N_Port data structure.
7048 * @ndlp: pointer to a node-list data structure.
7049 * @retry: number of retries to the command IOCB.
7051 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
7052 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
7053 * routine to issue the IOCB, which makes sure only one outstanding fabric
7054 * IOCB will be sent off HBA at any given time.
7056 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7057 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7058 * will be stored into the context1 field of the IOCB for the completion
7059 * callback function to the FDISC ELS command.
7061 * Return code
7062 * 0 - Successfully issued fdisc iocb command
7063 * 1 - Failed to issue fdisc iocb command
7065 static int
7066 lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
7067 uint8_t retry)
7069 struct lpfc_hba *phba = vport->phba;
7070 IOCB_t *icmd;
7071 struct lpfc_iocbq *elsiocb;
7072 struct serv_parm *sp;
7073 uint8_t *pcmd;
7074 uint16_t cmdsize;
7075 int did = ndlp->nlp_DID;
7076 int rc;
7078 vport->port_state = LPFC_FDISC;
7079 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
7080 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
7081 ELS_CMD_FDISC);
7082 if (!elsiocb) {
7083 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
7084 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7085 "0255 Issue FDISC: no IOCB\n");
7086 return 1;
7089 icmd = &elsiocb->iocb;
7090 icmd->un.elsreq64.myID = 0;
7091 icmd->un.elsreq64.fl = 1;
7093 if (phba->sli_rev == LPFC_SLI_REV4) {
7094 /* FDISC needs to be 1 for WQE VPI */
7095 elsiocb->iocb.ulpCt_h = (SLI4_CT_VPI >> 1) & 1;
7096 elsiocb->iocb.ulpCt_l = SLI4_CT_VPI & 1 ;
7097 /* Set the ulpContext to the vpi */
7098 elsiocb->iocb.ulpContext = vport->vpi + phba->vpi_base;
7099 } else {
7100 /* For FDISC, Let FDISC rsp set the NPortID for this VPI */
7101 icmd->ulpCt_h = 1;
7102 icmd->ulpCt_l = 0;
7105 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7106 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
7107 pcmd += sizeof(uint32_t); /* CSP Word 1 */
7108 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
7109 sp = (struct serv_parm *) pcmd;
7110 /* Setup CSPs accordingly for Fabric */
7111 sp->cmn.e_d_tov = 0;
7112 sp->cmn.w2.r_a_tov = 0;
7113 sp->cls1.classValid = 0;
7114 sp->cls2.seqDelivery = 1;
7115 sp->cls3.seqDelivery = 1;
7117 pcmd += sizeof(uint32_t); /* CSP Word 2 */
7118 pcmd += sizeof(uint32_t); /* CSP Word 3 */
7119 pcmd += sizeof(uint32_t); /* CSP Word 4 */
7120 pcmd += sizeof(uint32_t); /* Port Name */
7121 memcpy(pcmd, &vport->fc_portname, 8);
7122 pcmd += sizeof(uint32_t); /* Node Name */
7123 pcmd += sizeof(uint32_t); /* Node Name */
7124 memcpy(pcmd, &vport->fc_nodename, 8);
7126 lpfc_set_disctmo(vport);
7128 phba->fc_stat.elsXmitFDISC++;
7129 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
7131 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7132 "Issue FDISC: did:x%x",
7133 did, 0, 0);
7135 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
7136 if (rc == IOCB_ERROR) {
7137 lpfc_els_free_iocb(phba, elsiocb);
7138 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
7139 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
7140 "0256 Issue FDISC: Cannot send IOCB\n");
7141 return 1;
7143 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
7144 return 0;
7148 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
7149 * @phba: pointer to lpfc hba data structure.
7150 * @cmdiocb: pointer to lpfc command iocb data structure.
7151 * @rspiocb: pointer to lpfc response iocb data structure.
7153 * This routine is the completion callback function to the issuing of a LOGO
7154 * ELS command off a vport. It frees the command IOCB and then decrement the
7155 * reference count held on ndlp for this completion function, indicating that
7156 * the reference to the ndlp is no long needed. Note that the
7157 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
7158 * callback function and an additional explicit ndlp reference decrementation
7159 * will trigger the actual release of the ndlp.
7161 static void
7162 lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7163 struct lpfc_iocbq *rspiocb)
7165 struct lpfc_vport *vport = cmdiocb->vport;
7166 IOCB_t *irsp;
7167 struct lpfc_nodelist *ndlp;
7168 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
7170 irsp = &rspiocb->iocb;
7171 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7172 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
7173 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
7175 lpfc_els_free_iocb(phba, cmdiocb);
7176 vport->unreg_vpi_cmpl = VPORT_ERROR;
7178 /* Trigger the release of the ndlp after logo */
7179 lpfc_nlp_put(ndlp);
7183 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
7184 * @vport: pointer to a virtual N_Port data structure.
7185 * @ndlp: pointer to a node-list data structure.
7187 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
7189 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7190 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7191 * will be stored into the context1 field of the IOCB for the completion
7192 * callback function to the LOGO ELS command.
7194 * Return codes
7195 * 0 - Successfully issued logo off the @vport
7196 * 1 - Failed to issue logo off the @vport
7199 lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
7201 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
7202 struct lpfc_hba *phba = vport->phba;
7203 IOCB_t *icmd;
7204 struct lpfc_iocbq *elsiocb;
7205 uint8_t *pcmd;
7206 uint16_t cmdsize;
7208 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
7209 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
7210 ELS_CMD_LOGO);
7211 if (!elsiocb)
7212 return 1;
7214 icmd = &elsiocb->iocb;
7215 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
7216 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
7217 pcmd += sizeof(uint32_t);
7219 /* Fill in LOGO payload */
7220 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
7221 pcmd += sizeof(uint32_t);
7222 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
7224 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
7225 "Issue LOGO npiv did:x%x flg:x%x",
7226 ndlp->nlp_DID, ndlp->nlp_flag, 0);
7228 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
7229 spin_lock_irq(shost->host_lock);
7230 ndlp->nlp_flag |= NLP_LOGO_SND;
7231 spin_unlock_irq(shost->host_lock);
7232 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
7233 IOCB_ERROR) {
7234 spin_lock_irq(shost->host_lock);
7235 ndlp->nlp_flag &= ~NLP_LOGO_SND;
7236 spin_unlock_irq(shost->host_lock);
7237 lpfc_els_free_iocb(phba, elsiocb);
7238 return 1;
7240 return 0;
7244 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
7245 * @ptr: holder for the timer function associated data.
7247 * This routine is invoked by the fabric iocb block timer after
7248 * timeout. It posts the fabric iocb block timeout event by setting the
7249 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
7250 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
7251 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
7252 * posted event WORKER_FABRIC_BLOCK_TMO.
7254 void
7255 lpfc_fabric_block_timeout(unsigned long ptr)
7257 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
7258 unsigned long iflags;
7259 uint32_t tmo_posted;
7261 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
7262 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
7263 if (!tmo_posted)
7264 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
7265 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
7267 if (!tmo_posted)
7268 lpfc_worker_wake_up(phba);
7269 return;
7273 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
7274 * @phba: pointer to lpfc hba data structure.
7276 * This routine issues one fabric iocb from the driver internal list to
7277 * the HBA. It first checks whether it's ready to issue one fabric iocb to
7278 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
7279 * remove one pending fabric iocb from the driver internal list and invokes
7280 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
7282 static void
7283 lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
7285 struct lpfc_iocbq *iocb;
7286 unsigned long iflags;
7287 int ret;
7288 IOCB_t *cmd;
7290 repeat:
7291 iocb = NULL;
7292 spin_lock_irqsave(&phba->hbalock, iflags);
7293 /* Post any pending iocb to the SLI layer */
7294 if (atomic_read(&phba->fabric_iocb_count) == 0) {
7295 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
7296 list);
7297 if (iocb)
7298 /* Increment fabric iocb count to hold the position */
7299 atomic_inc(&phba->fabric_iocb_count);
7301 spin_unlock_irqrestore(&phba->hbalock, iflags);
7302 if (iocb) {
7303 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
7304 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
7305 iocb->iocb_flag |= LPFC_IO_FABRIC;
7307 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
7308 "Fabric sched1: ste:x%x",
7309 iocb->vport->port_state, 0, 0);
7311 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
7313 if (ret == IOCB_ERROR) {
7314 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
7315 iocb->fabric_iocb_cmpl = NULL;
7316 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
7317 cmd = &iocb->iocb;
7318 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
7319 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
7320 iocb->iocb_cmpl(phba, iocb, iocb);
7322 atomic_dec(&phba->fabric_iocb_count);
7323 goto repeat;
7327 return;
7331 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
7332 * @phba: pointer to lpfc hba data structure.
7334 * This routine unblocks the issuing fabric iocb command. The function
7335 * will clear the fabric iocb block bit and then invoke the routine
7336 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
7337 * from the driver internal fabric iocb list.
7339 void
7340 lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
7342 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
7344 lpfc_resume_fabric_iocbs(phba);
7345 return;
7349 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
7350 * @phba: pointer to lpfc hba data structure.
7352 * This routine blocks the issuing fabric iocb for a specified amount of
7353 * time (currently 100 ms). This is done by set the fabric iocb block bit
7354 * and set up a timeout timer for 100ms. When the block bit is set, no more
7355 * fabric iocb will be issued out of the HBA.
7357 static void
7358 lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
7360 int blocked;
7362 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
7363 /* Start a timer to unblock fabric iocbs after 100ms */
7364 if (!blocked)
7365 mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 );
7367 return;
7371 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
7372 * @phba: pointer to lpfc hba data structure.
7373 * @cmdiocb: pointer to lpfc command iocb data structure.
7374 * @rspiocb: pointer to lpfc response iocb data structure.
7376 * This routine is the callback function that is put to the fabric iocb's
7377 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
7378 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
7379 * function first restores and invokes the original iocb's callback function
7380 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
7381 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
7383 static void
7384 lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
7385 struct lpfc_iocbq *rspiocb)
7387 struct ls_rjt stat;
7389 if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
7390 BUG();
7392 switch (rspiocb->iocb.ulpStatus) {
7393 case IOSTAT_NPORT_RJT:
7394 case IOSTAT_FABRIC_RJT:
7395 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
7396 lpfc_block_fabric_iocbs(phba);
7398 break;
7400 case IOSTAT_NPORT_BSY:
7401 case IOSTAT_FABRIC_BSY:
7402 lpfc_block_fabric_iocbs(phba);
7403 break;
7405 case IOSTAT_LS_RJT:
7406 stat.un.lsRjtError =
7407 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
7408 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
7409 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
7410 lpfc_block_fabric_iocbs(phba);
7411 break;
7414 if (atomic_read(&phba->fabric_iocb_count) == 0)
7415 BUG();
7417 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
7418 cmdiocb->fabric_iocb_cmpl = NULL;
7419 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
7420 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
7422 atomic_dec(&phba->fabric_iocb_count);
7423 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
7424 /* Post any pending iocbs to HBA */
7425 lpfc_resume_fabric_iocbs(phba);
7430 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
7431 * @phba: pointer to lpfc hba data structure.
7432 * @iocb: pointer to lpfc command iocb data structure.
7434 * This routine is used as the top-level API for issuing a fabric iocb command
7435 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
7436 * function makes sure that only one fabric bound iocb will be outstanding at
7437 * any given time. As such, this function will first check to see whether there
7438 * is already an outstanding fabric iocb on the wire. If so, it will put the
7439 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
7440 * issued later. Otherwise, it will issue the iocb on the wire and update the
7441 * fabric iocb count it indicate that there is one fabric iocb on the wire.
7443 * Note, this implementation has a potential sending out fabric IOCBs out of
7444 * order. The problem is caused by the construction of the "ready" boolen does
7445 * not include the condition that the internal fabric IOCB list is empty. As
7446 * such, it is possible a fabric IOCB issued by this routine might be "jump"
7447 * ahead of the fabric IOCBs in the internal list.
7449 * Return code
7450 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
7451 * IOCB_ERROR - failed to issue fabric iocb
7453 static int
7454 lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
7456 unsigned long iflags;
7457 int ready;
7458 int ret;
7460 if (atomic_read(&phba->fabric_iocb_count) > 1)
7461 BUG();
7463 spin_lock_irqsave(&phba->hbalock, iflags);
7464 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
7465 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
7467 if (ready)
7468 /* Increment fabric iocb count to hold the position */
7469 atomic_inc(&phba->fabric_iocb_count);
7470 spin_unlock_irqrestore(&phba->hbalock, iflags);
7471 if (ready) {
7472 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
7473 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
7474 iocb->iocb_flag |= LPFC_IO_FABRIC;
7476 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
7477 "Fabric sched2: ste:x%x",
7478 iocb->vport->port_state, 0, 0);
7480 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
7482 if (ret == IOCB_ERROR) {
7483 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
7484 iocb->fabric_iocb_cmpl = NULL;
7485 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
7486 atomic_dec(&phba->fabric_iocb_count);
7488 } else {
7489 spin_lock_irqsave(&phba->hbalock, iflags);
7490 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
7491 spin_unlock_irqrestore(&phba->hbalock, iflags);
7492 ret = IOCB_SUCCESS;
7494 return ret;
7498 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
7499 * @vport: pointer to a virtual N_Port data structure.
7501 * This routine aborts all the IOCBs associated with a @vport from the
7502 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
7503 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
7504 * list, removes each IOCB associated with the @vport off the list, set the
7505 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
7506 * associated with the IOCB.
7508 static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
7510 LIST_HEAD(completions);
7511 struct lpfc_hba *phba = vport->phba;
7512 struct lpfc_iocbq *tmp_iocb, *piocb;
7514 spin_lock_irq(&phba->hbalock);
7515 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
7516 list) {
7518 if (piocb->vport != vport)
7519 continue;
7521 list_move_tail(&piocb->list, &completions);
7523 spin_unlock_irq(&phba->hbalock);
7525 /* Cancel all the IOCBs from the completions list */
7526 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7527 IOERR_SLI_ABORTED);
7531 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
7532 * @ndlp: pointer to a node-list data structure.
7534 * This routine aborts all the IOCBs associated with an @ndlp from the
7535 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
7536 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
7537 * list, removes each IOCB associated with the @ndlp off the list, set the
7538 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
7539 * associated with the IOCB.
7541 void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
7543 LIST_HEAD(completions);
7544 struct lpfc_hba *phba = ndlp->phba;
7545 struct lpfc_iocbq *tmp_iocb, *piocb;
7546 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
7548 spin_lock_irq(&phba->hbalock);
7549 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
7550 list) {
7551 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
7553 list_move_tail(&piocb->list, &completions);
7556 spin_unlock_irq(&phba->hbalock);
7558 /* Cancel all the IOCBs from the completions list */
7559 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7560 IOERR_SLI_ABORTED);
7564 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
7565 * @phba: pointer to lpfc hba data structure.
7567 * This routine aborts all the IOCBs currently on the driver internal
7568 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
7569 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
7570 * list, removes IOCBs off the list, set the status feild to
7571 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
7572 * the IOCB.
7574 void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
7576 LIST_HEAD(completions);
7578 spin_lock_irq(&phba->hbalock);
7579 list_splice_init(&phba->fabric_iocb_list, &completions);
7580 spin_unlock_irq(&phba->hbalock);
7582 /* Cancel all the IOCBs from the completions list */
7583 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
7584 IOERR_SLI_ABORTED);
7588 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
7589 * @phba: pointer to lpfc hba data structure.
7590 * @axri: pointer to the els xri abort wcqe structure.
7592 * This routine is invoked by the worker thread to process a SLI4 slow-path
7593 * ELS aborted xri.
7595 void
7596 lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
7597 struct sli4_wcqe_xri_aborted *axri)
7599 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
7600 uint16_t rxid = bf_get(lpfc_wcqe_xa_remote_xid, axri);
7602 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
7603 unsigned long iflag = 0;
7604 struct lpfc_nodelist *ndlp;
7605 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
7607 spin_lock_irqsave(&phba->hbalock, iflag);
7608 spin_lock(&phba->sli4_hba.abts_sgl_list_lock);
7609 list_for_each_entry_safe(sglq_entry, sglq_next,
7610 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
7611 if (sglq_entry->sli4_xritag == xri) {
7612 list_del(&sglq_entry->list);
7613 ndlp = sglq_entry->ndlp;
7614 sglq_entry->ndlp = NULL;
7615 list_add_tail(&sglq_entry->list,
7616 &phba->sli4_hba.lpfc_sgl_list);
7617 sglq_entry->state = SGL_FREED;
7618 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
7619 spin_unlock_irqrestore(&phba->hbalock, iflag);
7620 lpfc_set_rrq_active(phba, ndlp, xri, rxid, 1);
7622 /* Check if TXQ queue needs to be serviced */
7623 if (pring->txq_cnt)
7624 lpfc_worker_wake_up(phba);
7625 return;
7628 spin_unlock(&phba->sli4_hba.abts_sgl_list_lock);
7629 sglq_entry = __lpfc_get_active_sglq(phba, xri);
7630 if (!sglq_entry || (sglq_entry->sli4_xritag != xri)) {
7631 spin_unlock_irqrestore(&phba->hbalock, iflag);
7632 return;
7634 sglq_entry->state = SGL_XRI_ABORTED;
7635 spin_unlock_irqrestore(&phba->hbalock, iflag);
7636 return;