1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2015 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. *
7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
9 * This program is free software; you can redistribute it and/or *
10 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
20 *******************************************************************/
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>
36 #include "lpfc_sli4.h"
38 #include "lpfc_disc.h"
39 #include "lpfc_scsi.h"
41 #include "lpfc_logmsg.h"
42 #include "lpfc_crtn.h"
43 #include "lpfc_vport.h"
44 #include "lpfc_debugfs.h"
46 static int lpfc_els_retry(struct lpfc_hba
*, struct lpfc_iocbq
*,
48 static void lpfc_cmpl_fabric_iocb(struct lpfc_hba
*, struct lpfc_iocbq
*,
50 static void lpfc_fabric_abort_vport(struct lpfc_vport
*vport
);
51 static int lpfc_issue_els_fdisc(struct lpfc_vport
*vport
,
52 struct lpfc_nodelist
*ndlp
, uint8_t retry
);
53 static int lpfc_issue_fabric_iocb(struct lpfc_hba
*phba
,
54 struct lpfc_iocbq
*iocb
);
56 static int lpfc_max_els_tries
= 3;
59 * lpfc_els_chk_latt - Check host link attention event for a vport
60 * @vport: pointer to a host virtual N_Port data structure.
62 * This routine checks whether there is an outstanding host link
63 * attention event during the discovery process with the @vport. It is done
64 * by reading the HBA's Host Attention (HA) register. If there is any host
65 * link attention events during this @vport's discovery process, the @vport
66 * shall be marked as FC_ABORT_DISCOVERY, a host link attention clear shall
67 * be issued if the link state is not already in host link cleared state,
68 * and a return code shall indicate whether the host link attention event
71 * Note that, if either the host link is in state LPFC_LINK_DOWN or @vport
72 * state in LPFC_VPORT_READY, the request for checking host link attention
73 * event will be ignored and a return code shall indicate no host link
74 * attention event had happened.
77 * 0 - no host link attention event happened
78 * 1 - host link attention event happened
81 lpfc_els_chk_latt(struct lpfc_vport
*vport
)
83 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
84 struct lpfc_hba
*phba
= vport
->phba
;
87 if (vport
->port_state
>= LPFC_VPORT_READY
||
88 phba
->link_state
== LPFC_LINK_DOWN
||
89 phba
->sli_rev
> LPFC_SLI_REV3
)
92 /* Read the HBA Host Attention Register */
93 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
96 if (!(ha_copy
& HA_LATT
))
99 /* Pending Link Event during Discovery */
100 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
101 "0237 Pending Link Event during "
102 "Discovery: State x%x\n",
103 phba
->pport
->port_state
);
105 /* CLEAR_LA should re-enable link attention events and
106 * we should then immediately take a LATT event. The
107 * LATT processing should call lpfc_linkdown() which
108 * will cleanup any left over in-progress discovery
111 spin_lock_irq(shost
->host_lock
);
112 vport
->fc_flag
|= FC_ABORT_DISCOVERY
;
113 spin_unlock_irq(shost
->host_lock
);
115 if (phba
->link_state
!= LPFC_CLEAR_LA
)
116 lpfc_issue_clear_la(phba
, vport
);
122 * lpfc_prep_els_iocb - Allocate and prepare a lpfc iocb data structure
123 * @vport: pointer to a host virtual N_Port data structure.
124 * @expectRsp: flag indicating whether response is expected.
125 * @cmdSize: size of the ELS command.
126 * @retry: number of retries to the command IOCB when it fails.
127 * @ndlp: pointer to a node-list data structure.
128 * @did: destination identifier.
129 * @elscmd: the ELS command code.
131 * This routine is used for allocating a lpfc-IOCB data structure from
132 * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters
133 * passed into the routine for discovery state machine to issue an Extended
134 * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation
135 * and preparation routine that is used by all the discovery state machine
136 * routines and the ELS command-specific fields will be later set up by
137 * the individual discovery machine routines after calling this routine
138 * allocating and preparing a generic IOCB data structure. It fills in the
139 * Buffer Descriptor Entries (BDEs), allocates buffers for both command
140 * payload and response payload (if expected). The reference count on the
141 * ndlp is incremented by 1 and the reference to the ndlp is put into
142 * context1 of the IOCB data structure for this IOCB to hold the ndlp
143 * reference for the command's callback function to access later.
146 * Pointer to the newly allocated/prepared els iocb data structure
147 * NULL - when els iocb data structure allocation/preparation failed
150 lpfc_prep_els_iocb(struct lpfc_vport
*vport
, uint8_t expectRsp
,
151 uint16_t cmdSize
, uint8_t retry
,
152 struct lpfc_nodelist
*ndlp
, uint32_t did
,
155 struct lpfc_hba
*phba
= vport
->phba
;
156 struct lpfc_iocbq
*elsiocb
;
157 struct lpfc_dmabuf
*pcmd
, *prsp
, *pbuflist
;
158 struct ulp_bde64
*bpl
;
162 if (!lpfc_is_link_up(phba
))
165 /* Allocate buffer for command iocb */
166 elsiocb
= lpfc_sli_get_iocbq(phba
);
172 * If this command is for fabric controller and HBA running
173 * in FIP mode send FLOGI, FDISC and LOGO as FIP frames.
175 if ((did
== Fabric_DID
) &&
176 (phba
->hba_flag
& HBA_FIP_SUPPORT
) &&
177 ((elscmd
== ELS_CMD_FLOGI
) ||
178 (elscmd
== ELS_CMD_FDISC
) ||
179 (elscmd
== ELS_CMD_LOGO
)))
182 elsiocb
->iocb_flag
|=
183 ((LPFC_ELS_ID_FLOGI
<< LPFC_FIP_ELS_ID_SHIFT
)
184 & LPFC_FIP_ELS_ID_MASK
);
187 elsiocb
->iocb_flag
|=
188 ((LPFC_ELS_ID_FDISC
<< LPFC_FIP_ELS_ID_SHIFT
)
189 & LPFC_FIP_ELS_ID_MASK
);
192 elsiocb
->iocb_flag
|=
193 ((LPFC_ELS_ID_LOGO
<< LPFC_FIP_ELS_ID_SHIFT
)
194 & LPFC_FIP_ELS_ID_MASK
);
198 elsiocb
->iocb_flag
&= ~LPFC_FIP_ELS_ID_MASK
;
200 icmd
= &elsiocb
->iocb
;
202 /* fill in BDEs for command */
203 /* Allocate buffer for command payload */
204 pcmd
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
206 pcmd
->virt
= lpfc_mbuf_alloc(phba
, MEM_PRI
, &pcmd
->phys
);
207 if (!pcmd
|| !pcmd
->virt
)
208 goto els_iocb_free_pcmb_exit
;
210 INIT_LIST_HEAD(&pcmd
->list
);
212 /* Allocate buffer for response payload */
214 prsp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
216 prsp
->virt
= lpfc_mbuf_alloc(phba
, MEM_PRI
,
218 if (!prsp
|| !prsp
->virt
)
219 goto els_iocb_free_prsp_exit
;
220 INIT_LIST_HEAD(&prsp
->list
);
224 /* Allocate buffer for Buffer ptr list */
225 pbuflist
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
227 pbuflist
->virt
= lpfc_mbuf_alloc(phba
, MEM_PRI
,
229 if (!pbuflist
|| !pbuflist
->virt
)
230 goto els_iocb_free_pbuf_exit
;
232 INIT_LIST_HEAD(&pbuflist
->list
);
235 icmd
->un
.elsreq64
.bdl
.addrHigh
= putPaddrHigh(pbuflist
->phys
);
236 icmd
->un
.elsreq64
.bdl
.addrLow
= putPaddrLow(pbuflist
->phys
);
237 icmd
->un
.elsreq64
.bdl
.bdeFlags
= BUFF_TYPE_BLP_64
;
238 icmd
->un
.elsreq64
.bdl
.bdeSize
= (2 * sizeof(struct ulp_bde64
));
240 icmd
->un
.elsreq64
.remoteID
= did
; /* DID */
241 icmd
->ulpCommand
= CMD_ELS_REQUEST64_CR
;
242 if (elscmd
== ELS_CMD_FLOGI
)
243 icmd
->ulpTimeout
= FF_DEF_RATOV
* 2;
245 icmd
->ulpTimeout
= phba
->fc_ratov
* 2;
247 icmd
->un
.xseq64
.bdl
.addrHigh
= putPaddrHigh(pbuflist
->phys
);
248 icmd
->un
.xseq64
.bdl
.addrLow
= putPaddrLow(pbuflist
->phys
);
249 icmd
->un
.xseq64
.bdl
.bdeFlags
= BUFF_TYPE_BLP_64
;
250 icmd
->un
.xseq64
.bdl
.bdeSize
= sizeof(struct ulp_bde64
);
251 icmd
->un
.xseq64
.xmit_els_remoteID
= did
; /* DID */
252 icmd
->ulpCommand
= CMD_XMIT_ELS_RSP64_CX
;
254 icmd
->ulpBdeCount
= 1;
256 icmd
->ulpClass
= CLASS3
;
259 * If we have NPIV enabled, we want to send ELS traffic by VPI.
260 * For SLI4, since the driver controls VPIs we also want to include
261 * all ELS pt2pt protocol traffic as well.
263 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) ||
264 ((phba
->sli_rev
== LPFC_SLI_REV4
) &&
265 (vport
->fc_flag
& FC_PT2PT
))) {
268 icmd
->un
.elsreq64
.myID
= vport
->fc_myDID
;
270 /* For ELS_REQUEST64_CR, use the VPI by default */
271 icmd
->ulpContext
= phba
->vpi_ids
[vport
->vpi
];
275 /* The CT field must be 0=INVALID_RPI for the ECHO cmd */
276 if (elscmd
== ELS_CMD_ECHO
)
277 icmd
->ulpCt_l
= 0; /* context = invalid RPI */
279 icmd
->ulpCt_l
= 1; /* context = VPI */
282 bpl
= (struct ulp_bde64
*) pbuflist
->virt
;
283 bpl
->addrLow
= le32_to_cpu(putPaddrLow(pcmd
->phys
));
284 bpl
->addrHigh
= le32_to_cpu(putPaddrHigh(pcmd
->phys
));
285 bpl
->tus
.f
.bdeSize
= cmdSize
;
286 bpl
->tus
.f
.bdeFlags
= 0;
287 bpl
->tus
.w
= le32_to_cpu(bpl
->tus
.w
);
291 bpl
->addrLow
= le32_to_cpu(putPaddrLow(prsp
->phys
));
292 bpl
->addrHigh
= le32_to_cpu(putPaddrHigh(prsp
->phys
));
293 bpl
->tus
.f
.bdeSize
= FCELSSIZE
;
294 bpl
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64
;
295 bpl
->tus
.w
= le32_to_cpu(bpl
->tus
.w
);
298 /* prevent preparing iocb with NULL ndlp reference */
299 elsiocb
->context1
= lpfc_nlp_get(ndlp
);
300 if (!elsiocb
->context1
)
301 goto els_iocb_free_pbuf_exit
;
302 elsiocb
->context2
= pcmd
;
303 elsiocb
->context3
= pbuflist
;
304 elsiocb
->retry
= retry
;
305 elsiocb
->vport
= vport
;
306 elsiocb
->drvrTimeout
= (phba
->fc_ratov
<< 1) + LPFC_DRVR_TIMEOUT
;
309 list_add(&prsp
->list
, &pcmd
->list
);
312 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
313 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
314 "0116 Xmit ELS command x%x to remote "
315 "NPORT x%x I/O tag: x%x, port state:x%x"
317 elscmd
, did
, elsiocb
->iotag
,
321 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
322 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
323 "0117 Xmit ELS response x%x to remote "
324 "NPORT x%x I/O tag: x%x, size: x%x "
325 "port_state x%x fc_flag x%x\n",
326 elscmd
, ndlp
->nlp_DID
, elsiocb
->iotag
,
327 cmdSize
, vport
->port_state
,
332 els_iocb_free_pbuf_exit
:
334 lpfc_mbuf_free(phba
, prsp
->virt
, prsp
->phys
);
337 els_iocb_free_prsp_exit
:
338 lpfc_mbuf_free(phba
, pcmd
->virt
, pcmd
->phys
);
341 els_iocb_free_pcmb_exit
:
343 lpfc_sli_release_iocbq(phba
, elsiocb
);
348 * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport
349 * @vport: pointer to a host virtual N_Port data structure.
351 * This routine issues a fabric registration login for a @vport. An
352 * active ndlp node with Fabric_DID must already exist for this @vport.
353 * The routine invokes two mailbox commands to carry out fabric registration
354 * login through the HBA firmware: the first mailbox command requests the
355 * HBA to perform link configuration for the @vport; and the second mailbox
356 * command requests the HBA to perform the actual fabric registration login
360 * 0 - successfully issued fabric registration login for @vport
361 * -ENXIO -- failed to issue fabric registration login for @vport
364 lpfc_issue_fabric_reglogin(struct lpfc_vport
*vport
)
366 struct lpfc_hba
*phba
= vport
->phba
;
368 struct lpfc_dmabuf
*mp
;
369 struct lpfc_nodelist
*ndlp
;
370 struct serv_parm
*sp
;
374 sp
= &phba
->fc_fabparam
;
375 ndlp
= lpfc_findnode_did(vport
, Fabric_DID
);
376 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
)) {
381 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
387 vport
->port_state
= LPFC_FABRIC_CFG_LINK
;
388 lpfc_config_link(phba
, mbox
);
389 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
392 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
393 if (rc
== MBX_NOT_FINISHED
) {
398 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
403 rc
= lpfc_reg_rpi(phba
, vport
->vpi
, Fabric_DID
, (uint8_t *)sp
, mbox
,
410 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_fabric_reg_login
;
412 /* increment the reference count on ndlp to hold reference
413 * for the callback routine.
415 mbox
->context2
= lpfc_nlp_get(ndlp
);
417 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
418 if (rc
== MBX_NOT_FINISHED
) {
420 goto fail_issue_reg_login
;
425 fail_issue_reg_login
:
426 /* decrement the reference count on ndlp just incremented
427 * for the failed mbox command.
430 mp
= (struct lpfc_dmabuf
*) mbox
->context1
;
431 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
434 mempool_free(mbox
, phba
->mbox_mem_pool
);
437 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
438 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
439 "0249 Cannot issue Register Fabric login: Err %d\n", err
);
444 * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login
445 * @vport: pointer to a host virtual N_Port data structure.
447 * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for
448 * the @vport. This mailbox command is necessary for SLI4 port only.
451 * 0 - successfully issued REG_VFI for @vport
452 * A failure code otherwise.
455 lpfc_issue_reg_vfi(struct lpfc_vport
*vport
)
457 struct lpfc_hba
*phba
= vport
->phba
;
458 LPFC_MBOXQ_t
*mboxq
= NULL
;
459 struct lpfc_nodelist
*ndlp
;
460 struct lpfc_dmabuf
*dmabuf
= NULL
;
463 /* move forward in case of SLI4 FC port loopback test and pt2pt mode */
464 if ((phba
->sli_rev
== LPFC_SLI_REV4
) &&
465 !(phba
->link_flag
& LS_LOOPBACK_MODE
) &&
466 !(vport
->fc_flag
& FC_PT2PT
)) {
467 ndlp
= lpfc_findnode_did(vport
, Fabric_DID
);
468 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
)) {
474 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
480 /* Supply CSP's only if we are fabric connect or pt-to-pt connect */
481 if ((vport
->fc_flag
& FC_FABRIC
) || (vport
->fc_flag
& FC_PT2PT
)) {
482 dmabuf
= kzalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
487 dmabuf
->virt
= lpfc_mbuf_alloc(phba
, MEM_PRI
, &dmabuf
->phys
);
492 memcpy(dmabuf
->virt
, &phba
->fc_fabparam
,
493 sizeof(struct serv_parm
));
496 vport
->port_state
= LPFC_FABRIC_CFG_LINK
;
498 lpfc_reg_vfi(mboxq
, vport
, dmabuf
->phys
);
500 lpfc_reg_vfi(mboxq
, vport
, 0);
502 mboxq
->mbox_cmpl
= lpfc_mbx_cmpl_reg_vfi
;
503 mboxq
->vport
= vport
;
504 mboxq
->context1
= dmabuf
;
505 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
506 if (rc
== MBX_NOT_FINISHED
) {
514 mempool_free(mboxq
, phba
->mbox_mem_pool
);
517 lpfc_mbuf_free(phba
, dmabuf
->virt
, dmabuf
->phys
);
521 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
522 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
523 "0289 Issue Register VFI failed: Err %d\n", rc
);
528 * lpfc_issue_unreg_vfi - Unregister VFI for this vport's fabric login
529 * @vport: pointer to a host virtual N_Port data structure.
531 * This routine issues a UNREG_VFI mailbox with the vfi, vpi, fcfi triplet for
532 * the @vport. This mailbox command is necessary for SLI4 port only.
535 * 0 - successfully issued REG_VFI for @vport
536 * A failure code otherwise.
539 lpfc_issue_unreg_vfi(struct lpfc_vport
*vport
)
541 struct lpfc_hba
*phba
= vport
->phba
;
542 struct Scsi_Host
*shost
;
546 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
548 lpfc_printf_log(phba
, KERN_ERR
, LOG_DISCOVERY
|LOG_MBOX
,
549 "2556 UNREG_VFI mbox allocation failed"
550 "HBA state x%x\n", phba
->pport
->port_state
);
554 lpfc_unreg_vfi(mboxq
, vport
);
555 mboxq
->vport
= vport
;
556 mboxq
->mbox_cmpl
= lpfc_unregister_vfi_cmpl
;
558 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
559 if (rc
== MBX_NOT_FINISHED
) {
560 lpfc_printf_log(phba
, KERN_ERR
, LOG_DISCOVERY
|LOG_MBOX
,
561 "2557 UNREG_VFI issue mbox failed rc x%x "
563 rc
, phba
->pport
->port_state
);
564 mempool_free(mboxq
, phba
->mbox_mem_pool
);
568 shost
= lpfc_shost_from_vport(vport
);
569 spin_lock_irq(shost
->host_lock
);
570 vport
->fc_flag
&= ~FC_VFI_REGISTERED
;
571 spin_unlock_irq(shost
->host_lock
);
576 * lpfc_check_clean_addr_bit - Check whether assigned FCID is clean.
577 * @vport: pointer to a host virtual N_Port data structure.
578 * @sp: pointer to service parameter data structure.
580 * This routine is called from FLOGI/FDISC completion handler functions.
581 * lpfc_check_clean_addr_bit return 1 when FCID/Fabric portname/ Fabric
582 * node nodename is changed in the completion service parameter else return
583 * 0. This function also set flag in the vport data structure to delay
584 * NP_Port discovery after the FLOGI/FDISC completion if Clean address bit
585 * in FLOGI/FDISC response is cleared and FCID/Fabric portname/ Fabric
586 * node nodename is changed in the completion service parameter.
589 * 0 - FCID and Fabric Nodename and Fabric portname is not changed.
590 * 1 - FCID or Fabric Nodename or Fabric portname is changed.
594 lpfc_check_clean_addr_bit(struct lpfc_vport
*vport
,
595 struct serv_parm
*sp
)
597 uint8_t fabric_param_changed
= 0;
598 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
600 if ((vport
->fc_prevDID
!= vport
->fc_myDID
) ||
601 memcmp(&vport
->fabric_portname
, &sp
->portName
,
602 sizeof(struct lpfc_name
)) ||
603 memcmp(&vport
->fabric_nodename
, &sp
->nodeName
,
604 sizeof(struct lpfc_name
)))
605 fabric_param_changed
= 1;
608 * Word 1 Bit 31 in common service parameter is overloaded.
609 * Word 1 Bit 31 in FLOGI request is multiple NPort request
610 * Word 1 Bit 31 in FLOGI response is clean address bit
612 * If fabric parameter is changed and clean address bit is
613 * cleared delay nport discovery if
614 * - vport->fc_prevDID != 0 (not initial discovery) OR
615 * - lpfc_delay_discovery module parameter is set.
617 if (fabric_param_changed
&& !sp
->cmn
.clean_address_bit
&&
618 (vport
->fc_prevDID
|| lpfc_delay_discovery
)) {
619 spin_lock_irq(shost
->host_lock
);
620 vport
->fc_flag
|= FC_DISC_DELAYED
;
621 spin_unlock_irq(shost
->host_lock
);
624 return fabric_param_changed
;
629 * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port
630 * @vport: pointer to a host virtual N_Port data structure.
631 * @ndlp: pointer to a node-list data structure.
632 * @sp: pointer to service parameter data structure.
633 * @irsp: pointer to the IOCB within the lpfc response IOCB.
635 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
636 * function to handle the completion of a Fabric Login (FLOGI) into a fabric
637 * port in a fabric topology. It properly sets up the parameters to the @ndlp
638 * from the IOCB response. It also check the newly assigned N_Port ID to the
639 * @vport against the previously assigned N_Port ID. If it is different from
640 * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
641 * is invoked on all the remaining nodes with the @vport to unregister the
642 * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
643 * is invoked to register login to the fabric.
646 * 0 - Success (currently, always return 0)
649 lpfc_cmpl_els_flogi_fabric(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
650 struct serv_parm
*sp
, IOCB_t
*irsp
)
652 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
653 struct lpfc_hba
*phba
= vport
->phba
;
654 struct lpfc_nodelist
*np
;
655 struct lpfc_nodelist
*next_np
;
656 uint8_t fabric_param_changed
;
658 spin_lock_irq(shost
->host_lock
);
659 vport
->fc_flag
|= FC_FABRIC
;
660 spin_unlock_irq(shost
->host_lock
);
662 phba
->fc_edtov
= be32_to_cpu(sp
->cmn
.e_d_tov
);
663 if (sp
->cmn
.edtovResolution
) /* E_D_TOV ticks are in nanoseconds */
664 phba
->fc_edtov
= (phba
->fc_edtov
+ 999999) / 1000000;
666 phba
->fc_edtovResol
= sp
->cmn
.edtovResolution
;
667 phba
->fc_ratov
= (be32_to_cpu(sp
->cmn
.w2
.r_a_tov
) + 999) / 1000;
669 if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) {
670 spin_lock_irq(shost
->host_lock
);
671 vport
->fc_flag
|= FC_PUBLIC_LOOP
;
672 spin_unlock_irq(shost
->host_lock
);
675 vport
->fc_myDID
= irsp
->un
.ulpWord
[4] & Mask_DID
;
676 memcpy(&ndlp
->nlp_portname
, &sp
->portName
, sizeof(struct lpfc_name
));
677 memcpy(&ndlp
->nlp_nodename
, &sp
->nodeName
, sizeof(struct lpfc_name
));
678 ndlp
->nlp_class_sup
= 0;
679 if (sp
->cls1
.classValid
)
680 ndlp
->nlp_class_sup
|= FC_COS_CLASS1
;
681 if (sp
->cls2
.classValid
)
682 ndlp
->nlp_class_sup
|= FC_COS_CLASS2
;
683 if (sp
->cls3
.classValid
)
684 ndlp
->nlp_class_sup
|= FC_COS_CLASS3
;
685 if (sp
->cls4
.classValid
)
686 ndlp
->nlp_class_sup
|= FC_COS_CLASS4
;
687 ndlp
->nlp_maxframe
= ((sp
->cmn
.bbRcvSizeMsb
& 0x0F) << 8) |
688 sp
->cmn
.bbRcvSizeLsb
;
690 fabric_param_changed
= lpfc_check_clean_addr_bit(vport
, sp
);
691 if (fabric_param_changed
) {
692 /* Reset FDMI attribute masks based on config parameter */
693 if (phba
->cfg_fdmi_on
== LPFC_FDMI_NO_SUPPORT
) {
694 vport
->fdmi_hba_mask
= 0;
695 vport
->fdmi_port_mask
= 0;
697 /* Setup appropriate attribute masks */
698 vport
->fdmi_hba_mask
= LPFC_FDMI2_HBA_ATTR
;
699 if (phba
->cfg_fdmi_on
== LPFC_FDMI_SMART_SAN
)
700 vport
->fdmi_port_mask
= LPFC_FDMI2_SMART_ATTR
;
702 vport
->fdmi_port_mask
= LPFC_FDMI2_PORT_ATTR
;
706 memcpy(&vport
->fabric_portname
, &sp
->portName
,
707 sizeof(struct lpfc_name
));
708 memcpy(&vport
->fabric_nodename
, &sp
->nodeName
,
709 sizeof(struct lpfc_name
));
710 memcpy(&phba
->fc_fabparam
, sp
, sizeof(struct serv_parm
));
712 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) {
713 if (sp
->cmn
.response_multiple_NPort
) {
714 lpfc_printf_vlog(vport
, KERN_WARNING
,
716 "1816 FLOGI NPIV supported, "
717 "response data 0x%x\n",
718 sp
->cmn
.response_multiple_NPort
);
719 spin_lock_irq(&phba
->hbalock
);
720 phba
->link_flag
|= LS_NPIV_FAB_SUPPORTED
;
721 spin_unlock_irq(&phba
->hbalock
);
723 /* Because we asked f/w for NPIV it still expects us
724 to call reg_vnpid atleast for the physcial host */
725 lpfc_printf_vlog(vport
, KERN_WARNING
,
727 "1817 Fabric does not support NPIV "
728 "- configuring single port mode.\n");
729 spin_lock_irq(&phba
->hbalock
);
730 phba
->link_flag
&= ~LS_NPIV_FAB_SUPPORTED
;
731 spin_unlock_irq(&phba
->hbalock
);
736 * For FC we need to do some special processing because of the SLI
737 * Port's default settings of the Common Service Parameters.
739 if ((phba
->sli_rev
== LPFC_SLI_REV4
) &&
740 (phba
->sli4_hba
.lnk_info
.lnk_tp
== LPFC_LNK_TYPE_FC
)) {
741 /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */
742 if (fabric_param_changed
)
743 lpfc_unregister_fcf_prep(phba
);
745 /* This should just update the VFI CSPs*/
746 if (vport
->fc_flag
& FC_VFI_REGISTERED
)
747 lpfc_issue_reg_vfi(vport
);
750 if (fabric_param_changed
&&
751 !(vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
)) {
753 /* If our NportID changed, we need to ensure all
754 * remaining NPORTs get unreg_login'ed.
756 list_for_each_entry_safe(np
, next_np
,
757 &vport
->fc_nodes
, nlp_listp
) {
758 if (!NLP_CHK_NODE_ACT(np
))
760 if ((np
->nlp_state
!= NLP_STE_NPR_NODE
) ||
761 !(np
->nlp_flag
& NLP_NPR_ADISC
))
763 spin_lock_irq(shost
->host_lock
);
764 np
->nlp_flag
&= ~NLP_NPR_ADISC
;
765 spin_unlock_irq(shost
->host_lock
);
766 lpfc_unreg_rpi(vport
, np
);
768 lpfc_cleanup_pending_mbox(vport
);
770 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
771 lpfc_sli4_unreg_all_rpis(vport
);
772 lpfc_mbx_unreg_vpi(vport
);
773 spin_lock_irq(shost
->host_lock
);
774 vport
->fc_flag
|= FC_VPORT_NEEDS_INIT_VPI
;
775 spin_unlock_irq(shost
->host_lock
);
779 * For SLI3 and SLI4, the VPI needs to be reregistered in
780 * response to this fabric parameter change event.
782 spin_lock_irq(shost
->host_lock
);
783 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
784 spin_unlock_irq(shost
->host_lock
);
785 } else if ((phba
->sli_rev
== LPFC_SLI_REV4
) &&
786 !(vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
)) {
788 * Driver needs to re-reg VPI in order for f/w
789 * to update the MAC address.
791 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
792 lpfc_register_new_vport(phba
, vport
, ndlp
);
796 if (phba
->sli_rev
< LPFC_SLI_REV4
) {
797 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_REG_LOGIN_ISSUE
);
798 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
&&
799 vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
)
800 lpfc_register_new_vport(phba
, vport
, ndlp
);
802 lpfc_issue_fabric_reglogin(vport
);
804 ndlp
->nlp_type
|= NLP_FABRIC
;
805 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
806 if ((!(vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
)) &&
807 (vport
->vpi_state
& LPFC_VPI_REGISTERED
)) {
808 lpfc_start_fdiscs(phba
);
809 lpfc_do_scr_ns_plogi(phba
, vport
);
810 } else if (vport
->fc_flag
& FC_VFI_REGISTERED
)
811 lpfc_issue_init_vpi(vport
);
813 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
814 "3135 Need register VFI: (x%x/%x)\n",
815 vport
->fc_prevDID
, vport
->fc_myDID
);
816 lpfc_issue_reg_vfi(vport
);
823 * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
824 * @vport: pointer to a host virtual N_Port data structure.
825 * @ndlp: pointer to a node-list data structure.
826 * @sp: pointer to service parameter data structure.
828 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
829 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
830 * in a point-to-point topology. First, the @vport's N_Port Name is compared
831 * with the received N_Port Name: if the @vport's N_Port Name is greater than
832 * the received N_Port Name lexicographically, this node shall assign local
833 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
834 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
835 * this node shall just wait for the remote node to issue PLOGI and assign
843 lpfc_cmpl_els_flogi_nport(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
844 struct serv_parm
*sp
)
846 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
847 struct lpfc_hba
*phba
= vport
->phba
;
851 spin_lock_irq(shost
->host_lock
);
852 vport
->fc_flag
&= ~(FC_FABRIC
| FC_PUBLIC_LOOP
);
853 vport
->fc_flag
|= FC_PT2PT
;
854 spin_unlock_irq(shost
->host_lock
);
856 /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */
857 if ((phba
->sli_rev
== LPFC_SLI_REV4
) && phba
->fc_topology_changed
) {
858 lpfc_unregister_fcf_prep(phba
);
860 spin_lock_irq(shost
->host_lock
);
861 vport
->fc_flag
&= ~FC_VFI_REGISTERED
;
862 spin_unlock_irq(shost
->host_lock
);
863 phba
->fc_topology_changed
= 0;
866 rc
= memcmp(&vport
->fc_portname
, &sp
->portName
,
867 sizeof(vport
->fc_portname
));
870 /* This side will initiate the PLOGI */
871 spin_lock_irq(shost
->host_lock
);
872 vport
->fc_flag
|= FC_PT2PT_PLOGI
;
873 spin_unlock_irq(shost
->host_lock
);
876 * N_Port ID cannot be 0, set our Id to LocalID
877 * the other side will be RemoteID.
882 vport
->fc_myDID
= PT2PT_LocalID
;
884 /* Decrement ndlp reference count indicating that ndlp can be
885 * safely released when other references to it are done.
889 ndlp
= lpfc_findnode_did(vport
, PT2PT_RemoteID
);
892 * Cannot find existing Fabric ndlp, so allocate a
895 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
898 lpfc_nlp_init(vport
, ndlp
, PT2PT_RemoteID
);
899 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
900 ndlp
= lpfc_enable_node(vport
, ndlp
,
901 NLP_STE_UNUSED_NODE
);
906 memcpy(&ndlp
->nlp_portname
, &sp
->portName
,
907 sizeof(struct lpfc_name
));
908 memcpy(&ndlp
->nlp_nodename
, &sp
->nodeName
,
909 sizeof(struct lpfc_name
));
910 /* Set state will put ndlp onto node list if not already done */
911 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
912 spin_lock_irq(shost
->host_lock
);
913 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
914 spin_unlock_irq(shost
->host_lock
);
916 /* This side will wait for the PLOGI, decrement ndlp reference
917 * count indicating that ndlp can be released when other
918 * references to it are done.
922 /* If we are pt2pt with another NPort, force NPIV off! */
923 phba
->sli3_options
&= ~LPFC_SLI3_NPIV_ENABLED
;
925 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
929 lpfc_config_link(phba
, mbox
);
931 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_local_config_link
;
933 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
934 if (rc
== MBX_NOT_FINISHED
) {
935 mempool_free(mbox
, phba
->mbox_mem_pool
);
945 * lpfc_cmpl_els_flogi - Completion callback function for flogi
946 * @phba: pointer to lpfc hba data structure.
947 * @cmdiocb: pointer to lpfc command iocb data structure.
948 * @rspiocb: pointer to lpfc response iocb data structure.
950 * This routine is the top-level completion callback function for issuing
951 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
952 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
953 * retry has been made (either immediately or delayed with lpfc_els_retry()
954 * returning 1), the command IOCB will be released and function returned.
955 * If the retry attempt has been given up (possibly reach the maximum
956 * number of retries), one additional decrement of ndlp reference shall be
957 * invoked before going out after releasing the command IOCB. This will
958 * actually release the remote node (Note, lpfc_els_free_iocb() will also
959 * invoke one decrement of ndlp reference count). If no error reported in
960 * the IOCB status, the command Port ID field is used to determine whether
961 * this is a point-to-point topology or a fabric topology: if the Port ID
962 * field is assigned, it is a fabric topology; otherwise, it is a
963 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
964 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
965 * specific topology completion conditions.
968 lpfc_cmpl_els_flogi(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
969 struct lpfc_iocbq
*rspiocb
)
971 struct lpfc_vport
*vport
= cmdiocb
->vport
;
972 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
973 IOCB_t
*irsp
= &rspiocb
->iocb
;
974 struct lpfc_nodelist
*ndlp
= cmdiocb
->context1
;
975 struct lpfc_dmabuf
*pcmd
= cmdiocb
->context2
, *prsp
;
976 struct serv_parm
*sp
;
980 /* Check to see if link went down during discovery */
981 if (lpfc_els_chk_latt(vport
)) {
982 /* One additional decrement on node reference count to
983 * trigger the release of the node
989 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
990 "FLOGI cmpl: status:x%x/x%x state:x%x",
991 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
994 if (irsp
->ulpStatus
) {
996 * In case of FIP mode, perform roundrobin FCF failover
997 * due to new FCF discovery
999 if ((phba
->hba_flag
& HBA_FIP_SUPPORT
) &&
1000 (phba
->fcf
.fcf_flag
& FCF_DISCOVERY
)) {
1001 if (phba
->link_state
< LPFC_LINK_UP
)
1002 goto stop_rr_fcf_flogi
;
1003 if ((phba
->fcoe_cvl_eventtag_attn
==
1004 phba
->fcoe_cvl_eventtag
) &&
1005 (irsp
->ulpStatus
== IOSTAT_LOCAL_REJECT
) &&
1006 ((irsp
->un
.ulpWord
[4] & IOERR_PARAM_MASK
) ==
1008 goto stop_rr_fcf_flogi
;
1010 phba
->fcoe_cvl_eventtag_attn
=
1011 phba
->fcoe_cvl_eventtag
;
1012 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FIP
| LOG_ELS
,
1013 "2611 FLOGI failed on FCF (x%x), "
1014 "status:x%x/x%x, tmo:x%x, perform "
1015 "roundrobin FCF failover\n",
1016 phba
->fcf
.current_rec
.fcf_indx
,
1017 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1019 lpfc_sli4_set_fcf_flogi_fail(phba
,
1020 phba
->fcf
.current_rec
.fcf_indx
);
1021 fcf_index
= lpfc_sli4_fcf_rr_next_index_get(phba
);
1022 rc
= lpfc_sli4_fcf_rr_next_proc(vport
, fcf_index
);
1029 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1030 "2858 FLOGI failure Status:x%x/x%x TMO:x%x "
1032 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1033 irsp
->ulpTimeout
, phba
->hba_flag
,
1034 phba
->fcf
.fcf_flag
);
1036 /* Check for retry */
1037 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
))
1041 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1042 "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n",
1043 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1046 /* FLOGI failed, so there is no fabric */
1047 spin_lock_irq(shost
->host_lock
);
1048 vport
->fc_flag
&= ~(FC_FABRIC
| FC_PUBLIC_LOOP
);
1049 spin_unlock_irq(shost
->host_lock
);
1051 /* If private loop, then allow max outstanding els to be
1052 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
1053 * alpa map would take too long otherwise.
1055 if (phba
->alpa_map
[0] == 0)
1056 vport
->cfg_discovery_threads
= LPFC_MAX_DISC_THREADS
;
1057 if ((phba
->sli_rev
== LPFC_SLI_REV4
) &&
1058 (!(vport
->fc_flag
& FC_VFI_REGISTERED
) ||
1059 (vport
->fc_prevDID
!= vport
->fc_myDID
) ||
1060 phba
->fc_topology_changed
)) {
1061 if (vport
->fc_flag
& FC_VFI_REGISTERED
) {
1062 if (phba
->fc_topology_changed
) {
1063 lpfc_unregister_fcf_prep(phba
);
1064 spin_lock_irq(shost
->host_lock
);
1065 vport
->fc_flag
&= ~FC_VFI_REGISTERED
;
1066 spin_unlock_irq(shost
->host_lock
);
1067 phba
->fc_topology_changed
= 0;
1069 lpfc_sli4_unreg_all_rpis(vport
);
1072 lpfc_issue_reg_vfi(vport
);
1078 spin_lock_irq(shost
->host_lock
);
1079 vport
->fc_flag
&= ~FC_VPORT_CVL_RCVD
;
1080 vport
->fc_flag
&= ~FC_VPORT_LOGO_RCVD
;
1081 spin_unlock_irq(shost
->host_lock
);
1084 * The FLogI succeeded. Sync the data for the CPU before
1087 prsp
= list_get_first(&pcmd
->list
, struct lpfc_dmabuf
, list
);
1090 sp
= prsp
->virt
+ sizeof(uint32_t);
1092 /* FLOGI completes successfully */
1093 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
1094 "0101 FLOGI completes successfully, I/O tag:x%x, "
1095 "Data: x%x x%x x%x x%x x%x x%x\n", cmdiocb
->iotag
,
1096 irsp
->un
.ulpWord
[4], sp
->cmn
.e_d_tov
,
1097 sp
->cmn
.w2
.r_a_tov
, sp
->cmn
.edtovResolution
,
1098 vport
->port_state
, vport
->fc_flag
);
1100 if (vport
->port_state
== LPFC_FLOGI
) {
1102 * If Common Service Parameters indicate Nport
1103 * we are point to point, if Fport we are Fabric.
1106 rc
= lpfc_cmpl_els_flogi_fabric(vport
, ndlp
, sp
, irsp
);
1107 else if (!(phba
->hba_flag
& HBA_FCOE_MODE
))
1108 rc
= lpfc_cmpl_els_flogi_nport(vport
, ndlp
, sp
);
1110 lpfc_printf_vlog(vport
, KERN_ERR
,
1112 "2831 FLOGI response with cleared Fabric "
1113 "bit fcf_index 0x%x "
1114 "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
1116 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
1117 phba
->fcf
.current_rec
.fcf_indx
,
1118 phba
->fcf
.current_rec
.switch_name
[0],
1119 phba
->fcf
.current_rec
.switch_name
[1],
1120 phba
->fcf
.current_rec
.switch_name
[2],
1121 phba
->fcf
.current_rec
.switch_name
[3],
1122 phba
->fcf
.current_rec
.switch_name
[4],
1123 phba
->fcf
.current_rec
.switch_name
[5],
1124 phba
->fcf
.current_rec
.switch_name
[6],
1125 phba
->fcf
.current_rec
.switch_name
[7],
1126 phba
->fcf
.current_rec
.fabric_name
[0],
1127 phba
->fcf
.current_rec
.fabric_name
[1],
1128 phba
->fcf
.current_rec
.fabric_name
[2],
1129 phba
->fcf
.current_rec
.fabric_name
[3],
1130 phba
->fcf
.current_rec
.fabric_name
[4],
1131 phba
->fcf
.current_rec
.fabric_name
[5],
1132 phba
->fcf
.current_rec
.fabric_name
[6],
1133 phba
->fcf
.current_rec
.fabric_name
[7]);
1135 spin_lock_irq(&phba
->hbalock
);
1136 phba
->fcf
.fcf_flag
&= ~FCF_DISCOVERY
;
1137 phba
->hba_flag
&= ~(FCF_RR_INPROG
| HBA_DEVLOSS_TMO
);
1138 spin_unlock_irq(&phba
->hbalock
);
1142 /* Mark the FCF discovery process done */
1143 if (phba
->hba_flag
& HBA_FIP_SUPPORT
)
1144 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_FIP
|
1146 "2769 FLOGI to FCF (x%x) "
1147 "completed successfully\n",
1148 phba
->fcf
.current_rec
.fcf_indx
);
1149 spin_lock_irq(&phba
->hbalock
);
1150 phba
->fcf
.fcf_flag
&= ~FCF_DISCOVERY
;
1151 phba
->hba_flag
&= ~(FCF_RR_INPROG
| HBA_DEVLOSS_TMO
);
1152 spin_unlock_irq(&phba
->hbalock
);
1158 spin_lock_irq(&phba
->hbalock
);
1159 phba
->fcf
.fcf_flag
&= ~FCF_DISCOVERY
;
1160 spin_unlock_irq(&phba
->hbalock
);
1164 if (!lpfc_error_lost_link(irsp
)) {
1165 /* FLOGI failed, so just use loop map to make discovery list */
1166 lpfc_disc_list_loopmap(vport
);
1168 /* Start discovery */
1169 lpfc_disc_start(vport
);
1170 } else if (((irsp
->ulpStatus
!= IOSTAT_LOCAL_REJECT
) ||
1171 (((irsp
->un
.ulpWord
[4] & IOERR_PARAM_MASK
) !=
1172 IOERR_SLI_ABORTED
) &&
1173 ((irsp
->un
.ulpWord
[4] & IOERR_PARAM_MASK
) !=
1174 IOERR_SLI_DOWN
))) &&
1175 (phba
->link_state
!= LPFC_CLEAR_LA
)) {
1176 /* If FLOGI failed enable link interrupt. */
1177 lpfc_issue_clear_la(phba
, vport
);
1180 lpfc_els_free_iocb(phba
, cmdiocb
);
1184 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
1185 * @vport: pointer to a host virtual N_Port data structure.
1186 * @ndlp: pointer to a node-list data structure.
1187 * @retry: number of retries to the command IOCB.
1189 * This routine issues a Fabric Login (FLOGI) Request ELS command
1190 * for a @vport. The initiator service parameters are put into the payload
1191 * of the FLOGI Request IOCB and the top-level callback function pointer
1192 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
1193 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
1194 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
1196 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1197 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1198 * will be stored into the context1 field of the IOCB for the completion
1199 * callback function to the FLOGI ELS command.
1202 * 0 - successfully issued flogi iocb for @vport
1203 * 1 - failed to issue flogi iocb for @vport
1206 lpfc_issue_els_flogi(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1209 struct lpfc_hba
*phba
= vport
->phba
;
1210 struct serv_parm
*sp
;
1212 struct lpfc_iocbq
*elsiocb
;
1218 cmdsize
= (sizeof(uint32_t) + sizeof(struct serv_parm
));
1219 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
1220 ndlp
->nlp_DID
, ELS_CMD_FLOGI
);
1225 icmd
= &elsiocb
->iocb
;
1226 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
1228 /* For FLOGI request, remainder of payload is service parameters */
1229 *((uint32_t *) (pcmd
)) = ELS_CMD_FLOGI
;
1230 pcmd
+= sizeof(uint32_t);
1231 memcpy(pcmd
, &vport
->fc_sparam
, sizeof(struct serv_parm
));
1232 sp
= (struct serv_parm
*) pcmd
;
1234 /* Setup CSPs accordingly for Fabric */
1235 sp
->cmn
.e_d_tov
= 0;
1236 sp
->cmn
.w2
.r_a_tov
= 0;
1237 sp
->cmn
.virtual_fabric_support
= 0;
1238 sp
->cls1
.classValid
= 0;
1239 if (sp
->cmn
.fcphLow
< FC_PH3
)
1240 sp
->cmn
.fcphLow
= FC_PH3
;
1241 if (sp
->cmn
.fcphHigh
< FC_PH3
)
1242 sp
->cmn
.fcphHigh
= FC_PH3
;
1244 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
1245 if (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) ==
1246 LPFC_SLI_INTF_IF_TYPE_0
) {
1247 elsiocb
->iocb
.ulpCt_h
= ((SLI4_CT_FCFI
>> 1) & 1);
1248 elsiocb
->iocb
.ulpCt_l
= (SLI4_CT_FCFI
& 1);
1249 /* FLOGI needs to be 3 for WQE FCFI */
1250 /* Set the fcfi to the fcfi we registered with */
1251 elsiocb
->iocb
.ulpContext
= phba
->fcf
.fcfi
;
1253 /* Can't do SLI4 class2 without support sequence coalescing */
1254 sp
->cls2
.classValid
= 0;
1255 sp
->cls2
.seqDelivery
= 0;
1257 /* Historical, setting sequential-delivery bit for SLI3 */
1258 sp
->cls2
.seqDelivery
= (sp
->cls2
.classValid
) ? 1 : 0;
1259 sp
->cls3
.seqDelivery
= (sp
->cls3
.classValid
) ? 1 : 0;
1260 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) {
1261 sp
->cmn
.request_multiple_Nport
= 1;
1262 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1266 sp
->cmn
.request_multiple_Nport
= 0;
1269 if (phba
->fc_topology
!= LPFC_TOPOLOGY_LOOP
) {
1270 icmd
->un
.elsreq64
.myID
= 0;
1271 icmd
->un
.elsreq64
.fl
= 1;
1274 tmo
= phba
->fc_ratov
;
1275 phba
->fc_ratov
= LPFC_DISC_FLOGI_TMO
;
1276 lpfc_set_disctmo(vport
);
1277 phba
->fc_ratov
= tmo
;
1279 phba
->fc_stat
.elsXmitFLOGI
++;
1280 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_flogi
;
1282 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1283 "Issue FLOGI: opt:x%x",
1284 phba
->sli3_options
, 0, 0);
1286 rc
= lpfc_issue_fabric_iocb(phba
, elsiocb
);
1287 if (rc
== IOCB_ERROR
) {
1288 lpfc_els_free_iocb(phba
, elsiocb
);
1295 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
1296 * @phba: pointer to lpfc hba data structure.
1298 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1299 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1300 * list and issues an abort IOCB commond on each outstanding IOCB that
1301 * contains a active Fabric_DID ndlp. Note that this function is to issue
1302 * the abort IOCB command on all the outstanding IOCBs, thus when this
1303 * function returns, it does not guarantee all the IOCBs are actually aborted.
1306 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
1309 lpfc_els_abort_flogi(struct lpfc_hba
*phba
)
1311 struct lpfc_sli_ring
*pring
;
1312 struct lpfc_iocbq
*iocb
, *next_iocb
;
1313 struct lpfc_nodelist
*ndlp
;
1316 /* Abort outstanding I/O on NPort <nlp_DID> */
1317 lpfc_printf_log(phba
, KERN_INFO
, LOG_DISCOVERY
,
1318 "0201 Abort outstanding I/O on NPort x%x\n",
1321 pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
1324 * Check the txcmplq for an iocb that matches the nport the driver is
1327 spin_lock_irq(&phba
->hbalock
);
1328 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
, list
) {
1330 if (icmd
->ulpCommand
== CMD_ELS_REQUEST64_CR
) {
1331 ndlp
= (struct lpfc_nodelist
*)(iocb
->context1
);
1332 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
) &&
1333 (ndlp
->nlp_DID
== Fabric_DID
))
1334 lpfc_sli_issue_abort_iotag(phba
, pring
, iocb
);
1337 spin_unlock_irq(&phba
->hbalock
);
1343 * lpfc_initial_flogi - Issue an initial fabric login for a vport
1344 * @vport: pointer to a host virtual N_Port data structure.
1346 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1347 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1348 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1349 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1350 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1351 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1355 * 0 - failed to issue initial flogi for @vport
1356 * 1 - successfully issued initial flogi for @vport
1359 lpfc_initial_flogi(struct lpfc_vport
*vport
)
1361 struct lpfc_hba
*phba
= vport
->phba
;
1362 struct lpfc_nodelist
*ndlp
;
1364 vport
->port_state
= LPFC_FLOGI
;
1365 lpfc_set_disctmo(vport
);
1367 /* First look for the Fabric ndlp */
1368 ndlp
= lpfc_findnode_did(vport
, Fabric_DID
);
1370 /* Cannot find existing Fabric ndlp, so allocate a new one */
1371 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
1374 lpfc_nlp_init(vport
, ndlp
, Fabric_DID
);
1375 /* Set the node type */
1376 ndlp
->nlp_type
|= NLP_FABRIC
;
1377 /* Put ndlp onto node list */
1378 lpfc_enqueue_node(vport
, ndlp
);
1379 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
1380 /* re-setup ndlp without removing from node list */
1381 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
1386 if (lpfc_issue_els_flogi(vport
, ndlp
, 0)) {
1387 /* This decrement of reference count to node shall kick off
1388 * the release of the node.
1397 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
1398 * @vport: pointer to a host virtual N_Port data structure.
1400 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1401 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1402 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1403 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1404 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1405 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1409 * 0 - failed to issue initial fdisc for @vport
1410 * 1 - successfully issued initial fdisc for @vport
1413 lpfc_initial_fdisc(struct lpfc_vport
*vport
)
1415 struct lpfc_hba
*phba
= vport
->phba
;
1416 struct lpfc_nodelist
*ndlp
;
1418 /* First look for the Fabric ndlp */
1419 ndlp
= lpfc_findnode_did(vport
, Fabric_DID
);
1421 /* Cannot find existing Fabric ndlp, so allocate a new one */
1422 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
1425 lpfc_nlp_init(vport
, ndlp
, Fabric_DID
);
1426 /* Put ndlp onto node list */
1427 lpfc_enqueue_node(vport
, ndlp
);
1428 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
1429 /* re-setup ndlp without removing from node list */
1430 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
1435 if (lpfc_issue_els_fdisc(vport
, ndlp
, 0)) {
1436 /* decrement node reference count to trigger the release of
1446 * lpfc_more_plogi - Check and issue remaining plogis for a vport
1447 * @vport: pointer to a host virtual N_Port data structure.
1449 * This routine checks whether there are more remaining Port Logins
1450 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1451 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1452 * to issue ELS PLOGIs up to the configured discover threads with the
1453 * @vport (@vport->cfg_discovery_threads). The function also decrement
1454 * the @vport's num_disc_node by 1 if it is not already 0.
1457 lpfc_more_plogi(struct lpfc_vport
*vport
)
1459 if (vport
->num_disc_nodes
)
1460 vport
->num_disc_nodes
--;
1462 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
1463 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
1464 "0232 Continue discovery with %d PLOGIs to go "
1465 "Data: x%x x%x x%x\n",
1466 vport
->num_disc_nodes
, vport
->fc_plogi_cnt
,
1467 vport
->fc_flag
, vport
->port_state
);
1468 /* Check to see if there are more PLOGIs to be sent */
1469 if (vport
->fc_flag
& FC_NLP_MORE
)
1470 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1471 lpfc_els_disc_plogi(vport
);
1477 * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
1478 * @phba: pointer to lpfc hba data structure.
1479 * @prsp: pointer to response IOCB payload.
1480 * @ndlp: pointer to a node-list data structure.
1482 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1483 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1484 * The following cases are considered N_Port confirmed:
1485 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1486 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1487 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1488 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1489 * 1) if there is a node on vport list other than the @ndlp with the same
1490 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1491 * on that node to release the RPI associated with the node; 2) if there is
1492 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1493 * into, a new node shall be allocated (or activated). In either case, the
1494 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1495 * be released and the new_ndlp shall be put on to the vport node list and
1496 * its pointer returned as the confirmed node.
1498 * Note that before the @ndlp got "released", the keepDID from not-matching
1499 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1500 * of the @ndlp. This is because the release of @ndlp is actually to put it
1501 * into an inactive state on the vport node list and the vport node list
1502 * management algorithm does not allow two node with a same DID.
1505 * pointer to the PLOGI N_Port @ndlp
1507 static struct lpfc_nodelist
*
1508 lpfc_plogi_confirm_nport(struct lpfc_hba
*phba
, uint32_t *prsp
,
1509 struct lpfc_nodelist
*ndlp
)
1511 struct lpfc_vport
*vport
= ndlp
->vport
;
1512 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1513 struct lpfc_nodelist
*new_ndlp
;
1514 struct lpfc_rport_data
*rdata
;
1515 struct fc_rport
*rport
;
1516 struct serv_parm
*sp
;
1517 uint8_t name
[sizeof(struct lpfc_name
)];
1518 uint32_t rc
, keepDID
= 0, keep_nlp_flag
= 0;
1519 uint16_t keep_nlp_state
;
1522 unsigned long *active_rrqs_xri_bitmap
= NULL
;
1524 /* Fabric nodes can have the same WWPN so we don't bother searching
1525 * by WWPN. Just return the ndlp that was given to us.
1527 if (ndlp
->nlp_type
& NLP_FABRIC
)
1530 sp
= (struct serv_parm
*) ((uint8_t *) prsp
+ sizeof(uint32_t));
1531 memset(name
, 0, sizeof(struct lpfc_name
));
1533 /* Now we find out if the NPort we are logging into, matches the WWPN
1534 * we have for that ndlp. If not, we have some work to do.
1536 new_ndlp
= lpfc_findnode_wwpn(vport
, &sp
->portName
);
1538 if (new_ndlp
== ndlp
&& NLP_CHK_NODE_ACT(new_ndlp
))
1540 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
1541 active_rrqs_xri_bitmap
= mempool_alloc(phba
->active_rrq_pool
,
1543 if (active_rrqs_xri_bitmap
)
1544 memset(active_rrqs_xri_bitmap
, 0,
1545 phba
->cfg_rrq_xri_bitmap_sz
);
1548 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
1549 "3178 PLOGI confirm: ndlp %p x%x: new_ndlp %p\n",
1550 ndlp
, ndlp
->nlp_DID
, new_ndlp
);
1553 rc
= memcmp(&ndlp
->nlp_portname
, name
,
1554 sizeof(struct lpfc_name
));
1556 if (active_rrqs_xri_bitmap
)
1557 mempool_free(active_rrqs_xri_bitmap
,
1558 phba
->active_rrq_pool
);
1561 new_ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_ATOMIC
);
1563 if (active_rrqs_xri_bitmap
)
1564 mempool_free(active_rrqs_xri_bitmap
,
1565 phba
->active_rrq_pool
);
1568 lpfc_nlp_init(vport
, new_ndlp
, ndlp
->nlp_DID
);
1569 } else if (!NLP_CHK_NODE_ACT(new_ndlp
)) {
1570 rc
= memcmp(&ndlp
->nlp_portname
, name
,
1571 sizeof(struct lpfc_name
));
1573 if (active_rrqs_xri_bitmap
)
1574 mempool_free(active_rrqs_xri_bitmap
,
1575 phba
->active_rrq_pool
);
1578 new_ndlp
= lpfc_enable_node(vport
, new_ndlp
,
1579 NLP_STE_UNUSED_NODE
);
1581 if (active_rrqs_xri_bitmap
)
1582 mempool_free(active_rrqs_xri_bitmap
,
1583 phba
->active_rrq_pool
);
1586 keepDID
= new_ndlp
->nlp_DID
;
1587 if ((phba
->sli_rev
== LPFC_SLI_REV4
) && active_rrqs_xri_bitmap
)
1588 memcpy(active_rrqs_xri_bitmap
,
1589 new_ndlp
->active_rrqs_xri_bitmap
,
1590 phba
->cfg_rrq_xri_bitmap_sz
);
1592 keepDID
= new_ndlp
->nlp_DID
;
1593 if (phba
->sli_rev
== LPFC_SLI_REV4
&&
1594 active_rrqs_xri_bitmap
)
1595 memcpy(active_rrqs_xri_bitmap
,
1596 new_ndlp
->active_rrqs_xri_bitmap
,
1597 phba
->cfg_rrq_xri_bitmap_sz
);
1600 lpfc_unreg_rpi(vport
, new_ndlp
);
1601 new_ndlp
->nlp_DID
= ndlp
->nlp_DID
;
1602 new_ndlp
->nlp_prev_state
= ndlp
->nlp_prev_state
;
1603 if (phba
->sli_rev
== LPFC_SLI_REV4
)
1604 memcpy(new_ndlp
->active_rrqs_xri_bitmap
,
1605 ndlp
->active_rrqs_xri_bitmap
,
1606 phba
->cfg_rrq_xri_bitmap_sz
);
1608 spin_lock_irq(shost
->host_lock
);
1609 keep_nlp_flag
= new_ndlp
->nlp_flag
;
1610 new_ndlp
->nlp_flag
= ndlp
->nlp_flag
;
1611 ndlp
->nlp_flag
= keep_nlp_flag
;
1612 spin_unlock_irq(shost
->host_lock
);
1614 /* Set nlp_states accordingly */
1615 keep_nlp_state
= new_ndlp
->nlp_state
;
1616 lpfc_nlp_set_state(vport
, new_ndlp
, ndlp
->nlp_state
);
1618 /* Move this back to NPR state */
1619 if (memcmp(&ndlp
->nlp_portname
, name
, sizeof(struct lpfc_name
)) == 0) {
1620 /* The new_ndlp is replacing ndlp totally, so we need
1621 * to put ndlp on UNUSED list and try to free it.
1623 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
1624 "3179 PLOGI confirm NEW: %x %x\n",
1625 new_ndlp
->nlp_DID
, keepDID
);
1627 /* Fix up the rport accordingly */
1628 rport
= ndlp
->rport
;
1630 rdata
= rport
->dd_data
;
1631 if (rdata
->pnode
== ndlp
) {
1632 /* break the link before dropping the ref */
1635 rdata
->pnode
= lpfc_nlp_get(new_ndlp
);
1636 new_ndlp
->rport
= rport
;
1638 new_ndlp
->nlp_type
= ndlp
->nlp_type
;
1640 /* We shall actually free the ndlp with both nlp_DID and
1641 * nlp_portname fields equals 0 to avoid any ndlp on the
1642 * nodelist never to be used.
1644 if (ndlp
->nlp_DID
== 0) {
1645 spin_lock_irq(&phba
->ndlp_lock
);
1646 NLP_SET_FREE_REQ(ndlp
);
1647 spin_unlock_irq(&phba
->ndlp_lock
);
1650 /* Two ndlps cannot have the same did on the nodelist */
1651 ndlp
->nlp_DID
= keepDID
;
1652 if (phba
->sli_rev
== LPFC_SLI_REV4
&&
1653 active_rrqs_xri_bitmap
)
1654 memcpy(ndlp
->active_rrqs_xri_bitmap
,
1655 active_rrqs_xri_bitmap
,
1656 phba
->cfg_rrq_xri_bitmap_sz
);
1658 if (!NLP_CHK_NODE_ACT(ndlp
))
1659 lpfc_drop_node(vport
, ndlp
);
1662 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
1663 "3180 PLOGI confirm SWAP: %x %x\n",
1664 new_ndlp
->nlp_DID
, keepDID
);
1666 lpfc_unreg_rpi(vport
, ndlp
);
1668 /* Two ndlps cannot have the same did */
1669 ndlp
->nlp_DID
= keepDID
;
1670 if (phba
->sli_rev
== LPFC_SLI_REV4
&&
1671 active_rrqs_xri_bitmap
)
1672 memcpy(ndlp
->active_rrqs_xri_bitmap
,
1673 active_rrqs_xri_bitmap
,
1674 phba
->cfg_rrq_xri_bitmap_sz
);
1676 /* Since we are switching over to the new_ndlp,
1677 * reset the old ndlp state
1679 if ((ndlp
->nlp_state
== NLP_STE_UNMAPPED_NODE
) ||
1680 (ndlp
->nlp_state
== NLP_STE_MAPPED_NODE
))
1681 keep_nlp_state
= NLP_STE_NPR_NODE
;
1682 lpfc_nlp_set_state(vport
, ndlp
, keep_nlp_state
);
1684 /* Fix up the rport accordingly */
1685 rport
= ndlp
->rport
;
1687 rdata
= rport
->dd_data
;
1688 put_node
= rdata
->pnode
!= NULL
;
1689 put_rport
= ndlp
->rport
!= NULL
;
1690 rdata
->pnode
= NULL
;
1695 put_device(&rport
->dev
);
1698 if (phba
->sli_rev
== LPFC_SLI_REV4
&&
1699 active_rrqs_xri_bitmap
)
1700 mempool_free(active_rrqs_xri_bitmap
,
1701 phba
->active_rrq_pool
);
1706 * lpfc_end_rscn - Check and handle more rscn for a vport
1707 * @vport: pointer to a host virtual N_Port data structure.
1709 * This routine checks whether more Registration State Change
1710 * Notifications (RSCNs) came in while the discovery state machine was in
1711 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1712 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1713 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1714 * handling the RSCNs.
1717 lpfc_end_rscn(struct lpfc_vport
*vport
)
1719 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1721 if (vport
->fc_flag
& FC_RSCN_MODE
) {
1723 * Check to see if more RSCNs came in while we were
1724 * processing this one.
1726 if (vport
->fc_rscn_id_cnt
||
1727 (vport
->fc_flag
& FC_RSCN_DISCOVERY
) != 0)
1728 lpfc_els_handle_rscn(vport
);
1730 spin_lock_irq(shost
->host_lock
);
1731 vport
->fc_flag
&= ~FC_RSCN_MODE
;
1732 spin_unlock_irq(shost
->host_lock
);
1738 * lpfc_cmpl_els_rrq - Completion handled for els RRQs.
1739 * @phba: pointer to lpfc hba data structure.
1740 * @cmdiocb: pointer to lpfc command iocb data structure.
1741 * @rspiocb: pointer to lpfc response iocb data structure.
1743 * This routine will call the clear rrq function to free the rrq and
1744 * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not
1745 * exist then the clear_rrq is still called because the rrq needs to
1750 lpfc_cmpl_els_rrq(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
1751 struct lpfc_iocbq
*rspiocb
)
1753 struct lpfc_vport
*vport
= cmdiocb
->vport
;
1755 struct lpfc_nodelist
*ndlp
;
1756 struct lpfc_node_rrq
*rrq
;
1758 /* we pass cmdiocb to state machine which needs rspiocb as well */
1759 rrq
= cmdiocb
->context_un
.rrq
;
1760 cmdiocb
->context_un
.rsp_iocb
= rspiocb
;
1762 irsp
= &rspiocb
->iocb
;
1763 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1764 "RRQ cmpl: status:x%x/x%x did:x%x",
1765 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1766 irsp
->un
.elsreq64
.remoteID
);
1768 ndlp
= lpfc_findnode_did(vport
, irsp
->un
.elsreq64
.remoteID
);
1769 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
) || ndlp
!= rrq
->ndlp
) {
1770 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1771 "2882 RRQ completes to NPort x%x "
1772 "with no ndlp. Data: x%x x%x x%x\n",
1773 irsp
->un
.elsreq64
.remoteID
,
1774 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1779 /* rrq completes to NPort <nlp_DID> */
1780 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
1781 "2880 RRQ completes to NPort x%x "
1782 "Data: x%x x%x x%x x%x x%x\n",
1783 ndlp
->nlp_DID
, irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1784 irsp
->ulpTimeout
, rrq
->xritag
, rrq
->rxid
);
1786 if (irsp
->ulpStatus
) {
1787 /* Check for retry */
1788 /* RRQ failed Don't print the vport to vport rjts */
1789 if (irsp
->ulpStatus
!= IOSTAT_LS_RJT
||
1790 (((irsp
->un
.ulpWord
[4]) >> 16 != LSRJT_INVALID_CMD
) &&
1791 ((irsp
->un
.ulpWord
[4]) >> 16 != LSRJT_UNABLE_TPC
)) ||
1792 (phba
)->pport
->cfg_log_verbose
& LOG_ELS
)
1793 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1794 "2881 RRQ failure DID:%06X Status:x%x/x%x\n",
1795 ndlp
->nlp_DID
, irsp
->ulpStatus
,
1796 irsp
->un
.ulpWord
[4]);
1800 lpfc_clr_rrq_active(phba
, rrq
->xritag
, rrq
);
1801 lpfc_els_free_iocb(phba
, cmdiocb
);
1805 * lpfc_cmpl_els_plogi - Completion callback function for plogi
1806 * @phba: pointer to lpfc hba data structure.
1807 * @cmdiocb: pointer to lpfc command iocb data structure.
1808 * @rspiocb: pointer to lpfc response iocb data structure.
1810 * This routine is the completion callback function for issuing the Port
1811 * Login (PLOGI) command. For PLOGI completion, there must be an active
1812 * ndlp on the vport node list that matches the remote node ID from the
1813 * PLOGI response IOCB. If such ndlp does not exist, the PLOGI is simply
1814 * ignored and command IOCB released. The PLOGI response IOCB status is
1815 * checked for error conditons. If there is error status reported, PLOGI
1816 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1817 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1818 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1819 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1820 * there are additional N_Port nodes with the vport that need to perform
1821 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1825 lpfc_cmpl_els_plogi(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
1826 struct lpfc_iocbq
*rspiocb
)
1828 struct lpfc_vport
*vport
= cmdiocb
->vport
;
1829 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1831 struct lpfc_nodelist
*ndlp
;
1832 struct lpfc_dmabuf
*prsp
;
1835 /* we pass cmdiocb to state machine which needs rspiocb as well */
1836 cmdiocb
->context_un
.rsp_iocb
= rspiocb
;
1838 irsp
= &rspiocb
->iocb
;
1839 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1840 "PLOGI cmpl: status:x%x/x%x did:x%x",
1841 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1842 irsp
->un
.elsreq64
.remoteID
);
1844 ndlp
= lpfc_findnode_did(vport
, irsp
->un
.elsreq64
.remoteID
);
1845 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
)) {
1846 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1847 "0136 PLOGI completes to NPort x%x "
1848 "with no ndlp. Data: x%x x%x x%x\n",
1849 irsp
->un
.elsreq64
.remoteID
,
1850 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1855 /* Since ndlp can be freed in the disc state machine, note if this node
1856 * is being used during discovery.
1858 spin_lock_irq(shost
->host_lock
);
1859 disc
= (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
);
1860 ndlp
->nlp_flag
&= ~NLP_NPR_2B_DISC
;
1861 spin_unlock_irq(shost
->host_lock
);
1864 /* PLOGI completes to NPort <nlp_DID> */
1865 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
1866 "0102 PLOGI completes to NPort x%x "
1867 "Data: x%x x%x x%x x%x x%x\n",
1868 ndlp
->nlp_DID
, irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1869 irsp
->ulpTimeout
, disc
, vport
->num_disc_nodes
);
1870 /* Check to see if link went down during discovery */
1871 if (lpfc_els_chk_latt(vport
)) {
1872 spin_lock_irq(shost
->host_lock
);
1873 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
1874 spin_unlock_irq(shost
->host_lock
);
1878 if (irsp
->ulpStatus
) {
1879 /* Check for retry */
1880 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
)) {
1881 /* ELS command is being retried */
1883 spin_lock_irq(shost
->host_lock
);
1884 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
1885 spin_unlock_irq(shost
->host_lock
);
1889 /* PLOGI failed Don't print the vport to vport rjts */
1890 if (irsp
->ulpStatus
!= IOSTAT_LS_RJT
||
1891 (((irsp
->un
.ulpWord
[4]) >> 16 != LSRJT_INVALID_CMD
) &&
1892 ((irsp
->un
.ulpWord
[4]) >> 16 != LSRJT_UNABLE_TPC
)) ||
1893 (phba
)->pport
->cfg_log_verbose
& LOG_ELS
)
1894 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1895 "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
1896 ndlp
->nlp_DID
, irsp
->ulpStatus
,
1897 irsp
->un
.ulpWord
[4]);
1898 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1899 if (lpfc_error_lost_link(irsp
))
1900 rc
= NLP_STE_FREED_NODE
;
1902 rc
= lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
1903 NLP_EVT_CMPL_PLOGI
);
1905 /* Good status, call state machine */
1906 prsp
= list_entry(((struct lpfc_dmabuf
*)
1907 cmdiocb
->context2
)->list
.next
,
1908 struct lpfc_dmabuf
, list
);
1909 ndlp
= lpfc_plogi_confirm_nport(phba
, prsp
->virt
, ndlp
);
1910 rc
= lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
1911 NLP_EVT_CMPL_PLOGI
);
1914 if (disc
&& vport
->num_disc_nodes
) {
1915 /* Check to see if there are more PLOGIs to be sent */
1916 lpfc_more_plogi(vport
);
1918 if (vport
->num_disc_nodes
== 0) {
1919 spin_lock_irq(shost
->host_lock
);
1920 vport
->fc_flag
&= ~FC_NDISC_ACTIVE
;
1921 spin_unlock_irq(shost
->host_lock
);
1923 lpfc_can_disctmo(vport
);
1924 lpfc_end_rscn(vport
);
1929 lpfc_els_free_iocb(phba
, cmdiocb
);
1934 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
1935 * @vport: pointer to a host virtual N_Port data structure.
1936 * @did: destination port identifier.
1937 * @retry: number of retries to the command IOCB.
1939 * This routine issues a Port Login (PLOGI) command to a remote N_Port
1940 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
1941 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
1942 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
1943 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
1945 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1946 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1947 * will be stored into the context1 field of the IOCB for the completion
1948 * callback function to the PLOGI ELS command.
1951 * 0 - Successfully issued a plogi for @vport
1952 * 1 - failed to issue a plogi for @vport
1955 lpfc_issue_els_plogi(struct lpfc_vport
*vport
, uint32_t did
, uint8_t retry
)
1957 struct lpfc_hba
*phba
= vport
->phba
;
1958 struct serv_parm
*sp
;
1959 struct lpfc_nodelist
*ndlp
;
1960 struct lpfc_iocbq
*elsiocb
;
1965 ndlp
= lpfc_findnode_did(vport
, did
);
1966 if (ndlp
&& !NLP_CHK_NODE_ACT(ndlp
))
1969 /* If ndlp is not NULL, we will bump the reference count on it */
1970 cmdsize
= (sizeof(uint32_t) + sizeof(struct serv_parm
));
1971 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
, did
,
1976 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
1978 /* For PLOGI request, remainder of payload is service parameters */
1979 *((uint32_t *) (pcmd
)) = ELS_CMD_PLOGI
;
1980 pcmd
+= sizeof(uint32_t);
1981 memcpy(pcmd
, &vport
->fc_sparam
, sizeof(struct serv_parm
));
1982 sp
= (struct serv_parm
*) pcmd
;
1985 * If we are a N-port connected to a Fabric, fix-up paramm's so logins
1986 * to device on remote loops work.
1988 if ((vport
->fc_flag
& FC_FABRIC
) && !(vport
->fc_flag
& FC_PUBLIC_LOOP
))
1989 sp
->cmn
.altBbCredit
= 1;
1991 if (sp
->cmn
.fcphLow
< FC_PH_4_3
)
1992 sp
->cmn
.fcphLow
= FC_PH_4_3
;
1994 if (sp
->cmn
.fcphHigh
< FC_PH3
)
1995 sp
->cmn
.fcphHigh
= FC_PH3
;
1997 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1998 "Issue PLOGI: did:x%x",
2001 phba
->fc_stat
.elsXmitPLOGI
++;
2002 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_plogi
;
2003 ret
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
2005 if (ret
== IOCB_ERROR
) {
2006 lpfc_els_free_iocb(phba
, elsiocb
);
2013 * lpfc_cmpl_els_prli - Completion callback function for prli
2014 * @phba: pointer to lpfc hba data structure.
2015 * @cmdiocb: pointer to lpfc command iocb data structure.
2016 * @rspiocb: pointer to lpfc response iocb data structure.
2018 * This routine is the completion callback function for a Process Login
2019 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
2020 * status. If there is error status reported, PRLI retry shall be attempted
2021 * by invoking the lpfc_els_retry() routine. Otherwise, the state
2022 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
2023 * ndlp to mark the PRLI completion.
2026 lpfc_cmpl_els_prli(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
2027 struct lpfc_iocbq
*rspiocb
)
2029 struct lpfc_vport
*vport
= cmdiocb
->vport
;
2030 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2032 struct lpfc_nodelist
*ndlp
;
2034 /* we pass cmdiocb to state machine which needs rspiocb as well */
2035 cmdiocb
->context_un
.rsp_iocb
= rspiocb
;
2037 irsp
= &(rspiocb
->iocb
);
2038 ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
2039 spin_lock_irq(shost
->host_lock
);
2040 ndlp
->nlp_flag
&= ~NLP_PRLI_SND
;
2041 spin_unlock_irq(shost
->host_lock
);
2043 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2044 "PRLI cmpl: status:x%x/x%x did:x%x",
2045 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
2047 /* PRLI completes to NPort <nlp_DID> */
2048 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
2049 "0103 PRLI completes to NPort x%x "
2050 "Data: x%x x%x x%x x%x\n",
2051 ndlp
->nlp_DID
, irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
2052 irsp
->ulpTimeout
, vport
->num_disc_nodes
);
2054 vport
->fc_prli_sent
--;
2055 /* Check to see if link went down during discovery */
2056 if (lpfc_els_chk_latt(vport
))
2059 if (irsp
->ulpStatus
) {
2060 /* Check for retry */
2061 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
)) {
2062 /* ELS command is being retried */
2066 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
2067 "2754 PRLI failure DID:%06X Status:x%x/x%x\n",
2068 ndlp
->nlp_DID
, irsp
->ulpStatus
,
2069 irsp
->un
.ulpWord
[4]);
2070 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2071 if (lpfc_error_lost_link(irsp
))
2074 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
2077 /* Good status, call state machine */
2078 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
2081 lpfc_els_free_iocb(phba
, cmdiocb
);
2086 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
2087 * @vport: pointer to a host virtual N_Port data structure.
2088 * @ndlp: pointer to a node-list data structure.
2089 * @retry: number of retries to the command IOCB.
2091 * This routine issues a Process Login (PRLI) ELS command for the
2092 * @vport. The PRLI service parameters are set up in the payload of the
2093 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
2094 * is put to the IOCB completion callback func field before invoking the
2095 * routine lpfc_sli_issue_iocb() to send out PRLI command.
2097 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2098 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2099 * will be stored into the context1 field of the IOCB for the completion
2100 * callback function to the PRLI ELS command.
2103 * 0 - successfully issued prli iocb command for @vport
2104 * 1 - failed to issue prli iocb command for @vport
2107 lpfc_issue_els_prli(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2110 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2111 struct lpfc_hba
*phba
= vport
->phba
;
2113 struct lpfc_iocbq
*elsiocb
;
2117 cmdsize
= (sizeof(uint32_t) + sizeof(PRLI
));
2118 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
2119 ndlp
->nlp_DID
, ELS_CMD_PRLI
);
2123 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
2125 /* For PRLI request, remainder of payload is service parameters */
2126 memset(pcmd
, 0, (sizeof(PRLI
) + sizeof(uint32_t)));
2127 *((uint32_t *) (pcmd
)) = ELS_CMD_PRLI
;
2128 pcmd
+= sizeof(uint32_t);
2130 /* For PRLI, remainder of payload is PRLI parameter page */
2131 npr
= (PRLI
*) pcmd
;
2133 * If our firmware version is 3.20 or later,
2134 * set the following bits for FC-TAPE support.
2136 if (phba
->vpd
.rev
.feaLevelHigh
>= 0x02) {
2137 npr
->ConfmComplAllowed
= 1;
2139 npr
->TaskRetryIdReq
= 1;
2141 npr
->estabImagePair
= 1;
2142 npr
->readXferRdyDis
= 1;
2143 if (vport
->cfg_first_burst_size
)
2144 npr
->writeXferRdyDis
= 1;
2146 /* For FCP support */
2147 npr
->prliType
= PRLI_FCP_TYPE
;
2148 npr
->initiatorFunc
= 1;
2150 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2151 "Issue PRLI: did:x%x",
2152 ndlp
->nlp_DID
, 0, 0);
2154 phba
->fc_stat
.elsXmitPRLI
++;
2155 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_prli
;
2156 spin_lock_irq(shost
->host_lock
);
2157 ndlp
->nlp_flag
|= NLP_PRLI_SND
;
2158 spin_unlock_irq(shost
->host_lock
);
2159 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) ==
2161 spin_lock_irq(shost
->host_lock
);
2162 ndlp
->nlp_flag
&= ~NLP_PRLI_SND
;
2163 spin_unlock_irq(shost
->host_lock
);
2164 lpfc_els_free_iocb(phba
, elsiocb
);
2167 vport
->fc_prli_sent
++;
2172 * lpfc_rscn_disc - Perform rscn discovery for a vport
2173 * @vport: pointer to a host virtual N_Port data structure.
2175 * This routine performs Registration State Change Notification (RSCN)
2176 * discovery for a @vport. If the @vport's node port recovery count is not
2177 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
2178 * the nodes that need recovery. If none of the PLOGI were needed through
2179 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
2180 * invoked to check and handle possible more RSCN came in during the period
2181 * of processing the current ones.
2184 lpfc_rscn_disc(struct lpfc_vport
*vport
)
2186 lpfc_can_disctmo(vport
);
2188 /* RSCN discovery */
2189 /* go thru NPR nodes and issue ELS PLOGIs */
2190 if (vport
->fc_npr_cnt
)
2191 if (lpfc_els_disc_plogi(vport
))
2194 lpfc_end_rscn(vport
);
2198 * lpfc_adisc_done - Complete the adisc phase of discovery
2199 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
2201 * This function is called when the final ADISC is completed during discovery.
2202 * This function handles clearing link attention or issuing reg_vpi depending
2203 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
2205 * This function is called with no locks held.
2208 lpfc_adisc_done(struct lpfc_vport
*vport
)
2210 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2211 struct lpfc_hba
*phba
= vport
->phba
;
2214 * For NPIV, cmpl_reg_vpi will set port_state to READY,
2215 * and continue discovery.
2217 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
2218 !(vport
->fc_flag
& FC_RSCN_MODE
) &&
2219 (phba
->sli_rev
< LPFC_SLI_REV4
)) {
2220 /* The ADISCs are complete. Doesn't matter if they
2221 * succeeded or failed because the ADISC completion
2222 * routine guarantees to call the state machine and
2223 * the RPI is either unregistered (failed ADISC response)
2224 * or the RPI is still valid and the node is marked
2225 * mapped for a target. The exchanges should be in the
2226 * correct state. This code is specific to SLI3.
2228 lpfc_issue_clear_la(phba
, vport
);
2229 lpfc_issue_reg_vpi(phba
, vport
);
2233 * For SLI2, we need to set port_state to READY
2234 * and continue discovery.
2236 if (vport
->port_state
< LPFC_VPORT_READY
) {
2237 /* If we get here, there is nothing to ADISC */
2238 lpfc_issue_clear_la(phba
, vport
);
2239 if (!(vport
->fc_flag
& FC_ABORT_DISCOVERY
)) {
2240 vport
->num_disc_nodes
= 0;
2241 /* go thru NPR list, issue ELS PLOGIs */
2242 if (vport
->fc_npr_cnt
)
2243 lpfc_els_disc_plogi(vport
);
2244 if (!vport
->num_disc_nodes
) {
2245 spin_lock_irq(shost
->host_lock
);
2246 vport
->fc_flag
&= ~FC_NDISC_ACTIVE
;
2247 spin_unlock_irq(shost
->host_lock
);
2248 lpfc_can_disctmo(vport
);
2249 lpfc_end_rscn(vport
);
2252 vport
->port_state
= LPFC_VPORT_READY
;
2254 lpfc_rscn_disc(vport
);
2258 * lpfc_more_adisc - Issue more adisc as needed
2259 * @vport: pointer to a host virtual N_Port data structure.
2261 * This routine determines whether there are more ndlps on a @vport
2262 * node list need to have Address Discover (ADISC) issued. If so, it will
2263 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
2264 * remaining nodes which need to have ADISC sent.
2267 lpfc_more_adisc(struct lpfc_vport
*vport
)
2269 if (vport
->num_disc_nodes
)
2270 vport
->num_disc_nodes
--;
2271 /* Continue discovery with <num_disc_nodes> ADISCs to go */
2272 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
2273 "0210 Continue discovery with %d ADISCs to go "
2274 "Data: x%x x%x x%x\n",
2275 vport
->num_disc_nodes
, vport
->fc_adisc_cnt
,
2276 vport
->fc_flag
, vport
->port_state
);
2277 /* Check to see if there are more ADISCs to be sent */
2278 if (vport
->fc_flag
& FC_NLP_MORE
) {
2279 lpfc_set_disctmo(vport
);
2280 /* go thru NPR nodes and issue any remaining ELS ADISCs */
2281 lpfc_els_disc_adisc(vport
);
2283 if (!vport
->num_disc_nodes
)
2284 lpfc_adisc_done(vport
);
2289 * lpfc_cmpl_els_adisc - Completion callback function for adisc
2290 * @phba: pointer to lpfc hba data structure.
2291 * @cmdiocb: pointer to lpfc command iocb data structure.
2292 * @rspiocb: pointer to lpfc response iocb data structure.
2294 * This routine is the completion function for issuing the Address Discover
2295 * (ADISC) command. It first checks to see whether link went down during
2296 * the discovery process. If so, the node will be marked as node port
2297 * recovery for issuing discover IOCB by the link attention handler and
2298 * exit. Otherwise, the response status is checked. If error was reported
2299 * in the response status, the ADISC command shall be retried by invoking
2300 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
2301 * the response status, the state machine is invoked to set transition
2302 * with respect to NLP_EVT_CMPL_ADISC event.
2305 lpfc_cmpl_els_adisc(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
2306 struct lpfc_iocbq
*rspiocb
)
2308 struct lpfc_vport
*vport
= cmdiocb
->vport
;
2309 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2311 struct lpfc_nodelist
*ndlp
;
2314 /* we pass cmdiocb to state machine which needs rspiocb as well */
2315 cmdiocb
->context_un
.rsp_iocb
= rspiocb
;
2317 irsp
= &(rspiocb
->iocb
);
2318 ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
2320 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2321 "ADISC cmpl: status:x%x/x%x did:x%x",
2322 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
2325 /* Since ndlp can be freed in the disc state machine, note if this node
2326 * is being used during discovery.
2328 spin_lock_irq(shost
->host_lock
);
2329 disc
= (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
);
2330 ndlp
->nlp_flag
&= ~(NLP_ADISC_SND
| NLP_NPR_2B_DISC
);
2331 spin_unlock_irq(shost
->host_lock
);
2332 /* ADISC completes to NPort <nlp_DID> */
2333 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
2334 "0104 ADISC completes to NPort x%x "
2335 "Data: x%x x%x x%x x%x x%x\n",
2336 ndlp
->nlp_DID
, irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
2337 irsp
->ulpTimeout
, disc
, vport
->num_disc_nodes
);
2338 /* Check to see if link went down during discovery */
2339 if (lpfc_els_chk_latt(vport
)) {
2340 spin_lock_irq(shost
->host_lock
);
2341 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
2342 spin_unlock_irq(shost
->host_lock
);
2346 if (irsp
->ulpStatus
) {
2347 /* Check for retry */
2348 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
)) {
2349 /* ELS command is being retried */
2351 spin_lock_irq(shost
->host_lock
);
2352 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
2353 spin_unlock_irq(shost
->host_lock
);
2354 lpfc_set_disctmo(vport
);
2359 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
2360 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
2361 ndlp
->nlp_DID
, irsp
->ulpStatus
,
2362 irsp
->un
.ulpWord
[4]);
2363 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2364 if (!lpfc_error_lost_link(irsp
))
2365 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
2366 NLP_EVT_CMPL_ADISC
);
2368 /* Good status, call state machine */
2369 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
2370 NLP_EVT_CMPL_ADISC
);
2372 /* Check to see if there are more ADISCs to be sent */
2373 if (disc
&& vport
->num_disc_nodes
)
2374 lpfc_more_adisc(vport
);
2376 lpfc_els_free_iocb(phba
, cmdiocb
);
2381 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
2382 * @vport: pointer to a virtual N_Port data structure.
2383 * @ndlp: pointer to a node-list data structure.
2384 * @retry: number of retries to the command IOCB.
2386 * This routine issues an Address Discover (ADISC) for an @ndlp on a
2387 * @vport. It prepares the payload of the ADISC ELS command, updates the
2388 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
2389 * to issue the ADISC ELS command.
2391 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2392 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2393 * will be stored into the context1 field of the IOCB for the completion
2394 * callback function to the ADISC ELS command.
2397 * 0 - successfully issued adisc
2398 * 1 - failed to issue adisc
2401 lpfc_issue_els_adisc(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2404 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2405 struct lpfc_hba
*phba
= vport
->phba
;
2407 struct lpfc_iocbq
*elsiocb
;
2411 cmdsize
= (sizeof(uint32_t) + sizeof(ADISC
));
2412 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
2413 ndlp
->nlp_DID
, ELS_CMD_ADISC
);
2417 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
2419 /* For ADISC request, remainder of payload is service parameters */
2420 *((uint32_t *) (pcmd
)) = ELS_CMD_ADISC
;
2421 pcmd
+= sizeof(uint32_t);
2423 /* Fill in ADISC payload */
2424 ap
= (ADISC
*) pcmd
;
2425 ap
->hardAL_PA
= phba
->fc_pref_ALPA
;
2426 memcpy(&ap
->portName
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
2427 memcpy(&ap
->nodeName
, &vport
->fc_nodename
, sizeof(struct lpfc_name
));
2428 ap
->DID
= be32_to_cpu(vport
->fc_myDID
);
2430 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2431 "Issue ADISC: did:x%x",
2432 ndlp
->nlp_DID
, 0, 0);
2434 phba
->fc_stat
.elsXmitADISC
++;
2435 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_adisc
;
2436 spin_lock_irq(shost
->host_lock
);
2437 ndlp
->nlp_flag
|= NLP_ADISC_SND
;
2438 spin_unlock_irq(shost
->host_lock
);
2439 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) ==
2441 spin_lock_irq(shost
->host_lock
);
2442 ndlp
->nlp_flag
&= ~NLP_ADISC_SND
;
2443 spin_unlock_irq(shost
->host_lock
);
2444 lpfc_els_free_iocb(phba
, elsiocb
);
2451 * lpfc_cmpl_els_logo - Completion callback function for logo
2452 * @phba: pointer to lpfc hba data structure.
2453 * @cmdiocb: pointer to lpfc command iocb data structure.
2454 * @rspiocb: pointer to lpfc response iocb data structure.
2456 * This routine is the completion function for issuing the ELS Logout (LOGO)
2457 * command. If no error status was reported from the LOGO response, the
2458 * state machine of the associated ndlp shall be invoked for transition with
2459 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
2460 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
2463 lpfc_cmpl_els_logo(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
2464 struct lpfc_iocbq
*rspiocb
)
2466 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
2467 struct lpfc_vport
*vport
= ndlp
->vport
;
2468 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2470 struct lpfcMboxq
*mbox
;
2471 unsigned long flags
;
2472 uint32_t skip_recovery
= 0;
2474 /* we pass cmdiocb to state machine which needs rspiocb as well */
2475 cmdiocb
->context_un
.rsp_iocb
= rspiocb
;
2477 irsp
= &(rspiocb
->iocb
);
2478 spin_lock_irq(shost
->host_lock
);
2479 ndlp
->nlp_flag
&= ~NLP_LOGO_SND
;
2480 spin_unlock_irq(shost
->host_lock
);
2482 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2483 "LOGO cmpl: status:x%x/x%x did:x%x",
2484 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
2487 /* LOGO completes to NPort <nlp_DID> */
2488 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
2489 "0105 LOGO completes to NPort x%x "
2490 "Data: x%x x%x x%x x%x\n",
2491 ndlp
->nlp_DID
, irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
2492 irsp
->ulpTimeout
, vport
->num_disc_nodes
);
2494 if (lpfc_els_chk_latt(vport
)) {
2499 /* Check to see if link went down during discovery */
2500 if (ndlp
->nlp_flag
& NLP_TARGET_REMOVE
) {
2501 /* NLP_EVT_DEVICE_RM should unregister the RPI
2502 * which should abort all outstanding IOs.
2504 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
2510 if (irsp
->ulpStatus
) {
2511 /* Check for retry */
2512 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
)) {
2513 /* ELS command is being retried */
2518 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
2519 "2756 LOGO failure DID:%06X Status:x%x/x%x\n",
2520 ndlp
->nlp_DID
, irsp
->ulpStatus
,
2521 irsp
->un
.ulpWord
[4]);
2522 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2523 if (lpfc_error_lost_link(irsp
)) {
2529 /* Call state machine. This will unregister the rpi if needed. */
2530 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
, NLP_EVT_CMPL_LOGO
);
2533 lpfc_els_free_iocb(phba
, cmdiocb
);
2534 /* If we are in pt2pt mode, we could rcv new S_ID on PLOGI */
2535 if ((vport
->fc_flag
& FC_PT2PT
) &&
2536 !(vport
->fc_flag
& FC_PT2PT_PLOGI
)) {
2537 phba
->pport
->fc_myDID
= 0;
2538 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
2540 lpfc_config_link(phba
, mbox
);
2541 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
2542 mbox
->vport
= vport
;
2543 if (lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
) ==
2545 mempool_free(mbox
, phba
->mbox_mem_pool
);
2552 * If the node is a target, the handling attempts to recover the port.
2553 * For any other port type, the rpi is unregistered as an implicit
2556 if ((ndlp
->nlp_type
& NLP_FCP_TARGET
) && (skip_recovery
== 0)) {
2557 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
2558 spin_lock_irqsave(shost
->host_lock
, flags
);
2559 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
2560 spin_unlock_irqrestore(shost
->host_lock
, flags
);
2562 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
2563 "3187 LOGO completes to NPort x%x: Start "
2564 "Recovery Data: x%x x%x x%x x%x\n",
2565 ndlp
->nlp_DID
, irsp
->ulpStatus
,
2566 irsp
->un
.ulpWord
[4], irsp
->ulpTimeout
,
2567 vport
->num_disc_nodes
);
2568 lpfc_disc_start(vport
);
2574 * lpfc_issue_els_logo - Issue a logo to an node on a vport
2575 * @vport: pointer to a virtual N_Port data structure.
2576 * @ndlp: pointer to a node-list data structure.
2577 * @retry: number of retries to the command IOCB.
2579 * This routine constructs and issues an ELS Logout (LOGO) iocb command
2580 * to a remote node, referred by an @ndlp on a @vport. It constructs the
2581 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2582 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2584 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2585 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2586 * will be stored into the context1 field of the IOCB for the completion
2587 * callback function to the LOGO ELS command.
2590 * 0 - successfully issued logo
2591 * 1 - failed to issue logo
2594 lpfc_issue_els_logo(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2597 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2598 struct lpfc_hba
*phba
= vport
->phba
;
2599 struct lpfc_iocbq
*elsiocb
;
2604 spin_lock_irq(shost
->host_lock
);
2605 if (ndlp
->nlp_flag
& NLP_LOGO_SND
) {
2606 spin_unlock_irq(shost
->host_lock
);
2609 spin_unlock_irq(shost
->host_lock
);
2611 cmdsize
= (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name
);
2612 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
2613 ndlp
->nlp_DID
, ELS_CMD_LOGO
);
2617 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
2618 *((uint32_t *) (pcmd
)) = ELS_CMD_LOGO
;
2619 pcmd
+= sizeof(uint32_t);
2621 /* Fill in LOGO payload */
2622 *((uint32_t *) (pcmd
)) = be32_to_cpu(vport
->fc_myDID
);
2623 pcmd
+= sizeof(uint32_t);
2624 memcpy(pcmd
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
2626 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2627 "Issue LOGO: did:x%x",
2628 ndlp
->nlp_DID
, 0, 0);
2631 * If we are issuing a LOGO, we may try to recover the remote NPort
2632 * by issuing a PLOGI later. Even though we issue ELS cmds by the
2633 * VPI, if we have a valid RPI, and that RPI gets unreg'ed while
2634 * that ELS command is in-flight, the HBA returns a IOERR_INVALID_RPI
2635 * for that ELS cmd. To avoid this situation, lets get rid of the
2636 * RPI right now, before any ELS cmds are sent.
2638 spin_lock_irq(shost
->host_lock
);
2639 ndlp
->nlp_flag
|= NLP_ISSUE_LOGO
;
2640 spin_unlock_irq(shost
->host_lock
);
2641 if (lpfc_unreg_rpi(vport
, ndlp
)) {
2642 lpfc_els_free_iocb(phba
, elsiocb
);
2646 phba
->fc_stat
.elsXmitLOGO
++;
2647 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_logo
;
2648 spin_lock_irq(shost
->host_lock
);
2649 ndlp
->nlp_flag
|= NLP_LOGO_SND
;
2650 ndlp
->nlp_flag
&= ~NLP_ISSUE_LOGO
;
2651 spin_unlock_irq(shost
->host_lock
);
2652 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
2654 if (rc
== IOCB_ERROR
) {
2655 spin_lock_irq(shost
->host_lock
);
2656 ndlp
->nlp_flag
&= ~NLP_LOGO_SND
;
2657 spin_unlock_irq(shost
->host_lock
);
2658 lpfc_els_free_iocb(phba
, elsiocb
);
2665 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
2666 * @phba: pointer to lpfc hba data structure.
2667 * @cmdiocb: pointer to lpfc command iocb data structure.
2668 * @rspiocb: pointer to lpfc response iocb data structure.
2670 * This routine is a generic completion callback function for ELS commands.
2671 * Specifically, it is the callback function which does not need to perform
2672 * any command specific operations. It is currently used by the ELS command
2673 * issuing routines for the ELS State Change Request (SCR),
2674 * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
2675 * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
2676 * certain debug loggings, this callback function simply invokes the
2677 * lpfc_els_chk_latt() routine to check whether link went down during the
2678 * discovery process.
2681 lpfc_cmpl_els_cmd(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
2682 struct lpfc_iocbq
*rspiocb
)
2684 struct lpfc_vport
*vport
= cmdiocb
->vport
;
2687 irsp
= &rspiocb
->iocb
;
2689 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2690 "ELS cmd cmpl: status:x%x/x%x did:x%x",
2691 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
2692 irsp
->un
.elsreq64
.remoteID
);
2693 /* ELS cmd tag <ulpIoTag> completes */
2694 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
2695 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
2696 irsp
->ulpIoTag
, irsp
->ulpStatus
,
2697 irsp
->un
.ulpWord
[4], irsp
->ulpTimeout
);
2698 /* Check to see if link went down during discovery */
2699 lpfc_els_chk_latt(vport
);
2700 lpfc_els_free_iocb(phba
, cmdiocb
);
2705 * lpfc_issue_els_scr - Issue a scr to an node on a vport
2706 * @vport: pointer to a host virtual N_Port data structure.
2707 * @nportid: N_Port identifier to the remote node.
2708 * @retry: number of retries to the command IOCB.
2710 * This routine issues a State Change Request (SCR) to a fabric node
2711 * on a @vport. The remote node @nportid is passed into the function. It
2712 * first search the @vport node list to find the matching ndlp. If no such
2713 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
2714 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
2715 * routine is invoked to send the SCR IOCB.
2717 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2718 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2719 * will be stored into the context1 field of the IOCB for the completion
2720 * callback function to the SCR ELS command.
2723 * 0 - Successfully issued scr command
2724 * 1 - Failed to issue scr command
2727 lpfc_issue_els_scr(struct lpfc_vport
*vport
, uint32_t nportid
, uint8_t retry
)
2729 struct lpfc_hba
*phba
= vport
->phba
;
2730 struct lpfc_iocbq
*elsiocb
;
2733 struct lpfc_nodelist
*ndlp
;
2735 cmdsize
= (sizeof(uint32_t) + sizeof(SCR
));
2737 ndlp
= lpfc_findnode_did(vport
, nportid
);
2739 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
2742 lpfc_nlp_init(vport
, ndlp
, nportid
);
2743 lpfc_enqueue_node(vport
, ndlp
);
2744 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
2745 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
2750 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
2751 ndlp
->nlp_DID
, ELS_CMD_SCR
);
2754 /* This will trigger the release of the node just
2761 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
2763 *((uint32_t *) (pcmd
)) = ELS_CMD_SCR
;
2764 pcmd
+= sizeof(uint32_t);
2766 /* For SCR, remainder of payload is SCR parameter page */
2767 memset(pcmd
, 0, sizeof(SCR
));
2768 ((SCR
*) pcmd
)->Function
= SCR_FUNC_FULL
;
2770 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2771 "Issue SCR: did:x%x",
2772 ndlp
->nlp_DID
, 0, 0);
2774 phba
->fc_stat
.elsXmitSCR
++;
2775 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_cmd
;
2776 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) ==
2778 /* The additional lpfc_nlp_put will cause the following
2779 * lpfc_els_free_iocb routine to trigger the rlease of
2783 lpfc_els_free_iocb(phba
, elsiocb
);
2786 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2787 * trigger the release of node.
2795 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
2796 * @vport: pointer to a host virtual N_Port data structure.
2797 * @nportid: N_Port identifier to the remote node.
2798 * @retry: number of retries to the command IOCB.
2800 * This routine issues a Fibre Channel Address Resolution Response
2801 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
2802 * is passed into the function. It first search the @vport node list to find
2803 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
2804 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
2805 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
2807 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2808 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2809 * will be stored into the context1 field of the IOCB for the completion
2810 * callback function to the PARPR ELS command.
2813 * 0 - Successfully issued farpr command
2814 * 1 - Failed to issue farpr command
2817 lpfc_issue_els_farpr(struct lpfc_vport
*vport
, uint32_t nportid
, uint8_t retry
)
2819 struct lpfc_hba
*phba
= vport
->phba
;
2820 struct lpfc_iocbq
*elsiocb
;
2825 struct lpfc_nodelist
*ondlp
;
2826 struct lpfc_nodelist
*ndlp
;
2828 cmdsize
= (sizeof(uint32_t) + sizeof(FARP
));
2830 ndlp
= lpfc_findnode_did(vport
, nportid
);
2832 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
2835 lpfc_nlp_init(vport
, ndlp
, nportid
);
2836 lpfc_enqueue_node(vport
, ndlp
);
2837 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
2838 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
2843 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
2844 ndlp
->nlp_DID
, ELS_CMD_RNID
);
2846 /* This will trigger the release of the node just
2853 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
2855 *((uint32_t *) (pcmd
)) = ELS_CMD_FARPR
;
2856 pcmd
+= sizeof(uint32_t);
2858 /* Fill in FARPR payload */
2859 fp
= (FARP
*) (pcmd
);
2860 memset(fp
, 0, sizeof(FARP
));
2861 lp
= (uint32_t *) pcmd
;
2862 *lp
++ = be32_to_cpu(nportid
);
2863 *lp
++ = be32_to_cpu(vport
->fc_myDID
);
2865 fp
->Mflags
= (FARP_MATCH_PORT
| FARP_MATCH_NODE
);
2867 memcpy(&fp
->RportName
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
2868 memcpy(&fp
->RnodeName
, &vport
->fc_nodename
, sizeof(struct lpfc_name
));
2869 ondlp
= lpfc_findnode_did(vport
, nportid
);
2870 if (ondlp
&& NLP_CHK_NODE_ACT(ondlp
)) {
2871 memcpy(&fp
->OportName
, &ondlp
->nlp_portname
,
2872 sizeof(struct lpfc_name
));
2873 memcpy(&fp
->OnodeName
, &ondlp
->nlp_nodename
,
2874 sizeof(struct lpfc_name
));
2877 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2878 "Issue FARPR: did:x%x",
2879 ndlp
->nlp_DID
, 0, 0);
2881 phba
->fc_stat
.elsXmitFARPR
++;
2882 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_cmd
;
2883 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) ==
2885 /* The additional lpfc_nlp_put will cause the following
2886 * lpfc_els_free_iocb routine to trigger the release of
2890 lpfc_els_free_iocb(phba
, elsiocb
);
2893 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2894 * trigger the release of the node.
2901 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
2902 * @vport: pointer to a host virtual N_Port data structure.
2903 * @nlp: pointer to a node-list data structure.
2905 * This routine cancels the timer with a delayed IOCB-command retry for
2906 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
2907 * removes the ELS retry event if it presents. In addition, if the
2908 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
2909 * commands are sent for the @vport's nodes that require issuing discovery
2913 lpfc_cancel_retry_delay_tmo(struct lpfc_vport
*vport
, struct lpfc_nodelist
*nlp
)
2915 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2916 struct lpfc_work_evt
*evtp
;
2918 if (!(nlp
->nlp_flag
& NLP_DELAY_TMO
))
2920 spin_lock_irq(shost
->host_lock
);
2921 nlp
->nlp_flag
&= ~NLP_DELAY_TMO
;
2922 spin_unlock_irq(shost
->host_lock
);
2923 del_timer_sync(&nlp
->nlp_delayfunc
);
2924 nlp
->nlp_last_elscmd
= 0;
2925 if (!list_empty(&nlp
->els_retry_evt
.evt_listp
)) {
2926 list_del_init(&nlp
->els_retry_evt
.evt_listp
);
2927 /* Decrement nlp reference count held for the delayed retry */
2928 evtp
= &nlp
->els_retry_evt
;
2929 lpfc_nlp_put((struct lpfc_nodelist
*)evtp
->evt_arg1
);
2931 if (nlp
->nlp_flag
& NLP_NPR_2B_DISC
) {
2932 spin_lock_irq(shost
->host_lock
);
2933 nlp
->nlp_flag
&= ~NLP_NPR_2B_DISC
;
2934 spin_unlock_irq(shost
->host_lock
);
2935 if (vport
->num_disc_nodes
) {
2936 if (vport
->port_state
< LPFC_VPORT_READY
) {
2937 /* Check if there are more ADISCs to be sent */
2938 lpfc_more_adisc(vport
);
2940 /* Check if there are more PLOGIs to be sent */
2941 lpfc_more_plogi(vport
);
2942 if (vport
->num_disc_nodes
== 0) {
2943 spin_lock_irq(shost
->host_lock
);
2944 vport
->fc_flag
&= ~FC_NDISC_ACTIVE
;
2945 spin_unlock_irq(shost
->host_lock
);
2946 lpfc_can_disctmo(vport
);
2947 lpfc_end_rscn(vport
);
2956 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
2957 * @ptr: holder for the pointer to the timer function associated data (ndlp).
2959 * This routine is invoked by the ndlp delayed-function timer to check
2960 * whether there is any pending ELS retry event(s) with the node. If not, it
2961 * simply returns. Otherwise, if there is at least one ELS delayed event, it
2962 * adds the delayed events to the HBA work list and invokes the
2963 * lpfc_worker_wake_up() routine to wake up worker thread to process the
2964 * event. Note that lpfc_nlp_get() is called before posting the event to
2965 * the work list to hold reference count of ndlp so that it guarantees the
2966 * reference to ndlp will still be available when the worker thread gets
2967 * to the event associated with the ndlp.
2970 lpfc_els_retry_delay(unsigned long ptr
)
2972 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) ptr
;
2973 struct lpfc_vport
*vport
= ndlp
->vport
;
2974 struct lpfc_hba
*phba
= vport
->phba
;
2975 unsigned long flags
;
2976 struct lpfc_work_evt
*evtp
= &ndlp
->els_retry_evt
;
2978 spin_lock_irqsave(&phba
->hbalock
, flags
);
2979 if (!list_empty(&evtp
->evt_listp
)) {
2980 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
2984 /* We need to hold the node by incrementing the reference
2985 * count until the queued work is done
2987 evtp
->evt_arg1
= lpfc_nlp_get(ndlp
);
2988 if (evtp
->evt_arg1
) {
2989 evtp
->evt
= LPFC_EVT_ELS_RETRY
;
2990 list_add_tail(&evtp
->evt_listp
, &phba
->work_list
);
2991 lpfc_worker_wake_up(phba
);
2993 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
2998 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
2999 * @ndlp: pointer to a node-list data structure.
3001 * This routine is the worker-thread handler for processing the @ndlp delayed
3002 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
3003 * the last ELS command from the associated ndlp and invokes the proper ELS
3004 * function according to the delayed ELS command to retry the command.
3007 lpfc_els_retry_delay_handler(struct lpfc_nodelist
*ndlp
)
3009 struct lpfc_vport
*vport
= ndlp
->vport
;
3010 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3011 uint32_t cmd
, retry
;
3013 spin_lock_irq(shost
->host_lock
);
3014 cmd
= ndlp
->nlp_last_elscmd
;
3015 ndlp
->nlp_last_elscmd
= 0;
3017 if (!(ndlp
->nlp_flag
& NLP_DELAY_TMO
)) {
3018 spin_unlock_irq(shost
->host_lock
);
3022 ndlp
->nlp_flag
&= ~NLP_DELAY_TMO
;
3023 spin_unlock_irq(shost
->host_lock
);
3025 * If a discovery event readded nlp_delayfunc after timer
3026 * firing and before processing the timer, cancel the
3029 del_timer_sync(&ndlp
->nlp_delayfunc
);
3030 retry
= ndlp
->nlp_retry
;
3031 ndlp
->nlp_retry
= 0;
3035 lpfc_issue_els_flogi(vport
, ndlp
, retry
);
3038 if (!lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, retry
)) {
3039 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
3040 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
3044 if (!lpfc_issue_els_adisc(vport
, ndlp
, retry
)) {
3045 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
3046 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_ADISC_ISSUE
);
3050 if (!lpfc_issue_els_prli(vport
, ndlp
, retry
)) {
3051 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
3052 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PRLI_ISSUE
);
3056 if (!lpfc_issue_els_logo(vport
, ndlp
, retry
)) {
3057 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
3058 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_LOGO_ISSUE
);
3062 if (!(vport
->fc_flag
& FC_VPORT_NEEDS_INIT_VPI
))
3063 lpfc_issue_els_fdisc(vport
, ndlp
, retry
);
3070 * lpfc_els_retry - Make retry decision on an els command iocb
3071 * @phba: pointer to lpfc hba data structure.
3072 * @cmdiocb: pointer to lpfc command iocb data structure.
3073 * @rspiocb: pointer to lpfc response iocb data structure.
3075 * This routine makes a retry decision on an ELS command IOCB, which has
3076 * failed. The following ELS IOCBs use this function for retrying the command
3077 * when previously issued command responsed with error status: FLOGI, PLOGI,
3078 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
3079 * returned error status, it makes the decision whether a retry shall be
3080 * issued for the command, and whether a retry shall be made immediately or
3081 * delayed. In the former case, the corresponding ELS command issuing-function
3082 * is called to retry the command. In the later case, the ELS command shall
3083 * be posted to the ndlp delayed event and delayed function timer set to the
3084 * ndlp for the delayed command issusing.
3087 * 0 - No retry of els command is made
3088 * 1 - Immediate or delayed retry of els command is made
3091 lpfc_els_retry(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
3092 struct lpfc_iocbq
*rspiocb
)
3094 struct lpfc_vport
*vport
= cmdiocb
->vport
;
3095 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3096 IOCB_t
*irsp
= &rspiocb
->iocb
;
3097 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
3098 struct lpfc_dmabuf
*pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
3101 int retry
= 0, maxretry
= lpfc_max_els_tries
, delay
= 0;
3107 /* Note: context2 may be 0 for internal driver abort
3108 * of delays ELS command.
3111 if (pcmd
&& pcmd
->virt
) {
3112 elscmd
= (uint32_t *) (pcmd
->virt
);
3116 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
))
3117 did
= ndlp
->nlp_DID
;
3119 /* We should only hit this case for retrying PLOGI */
3120 did
= irsp
->un
.elsreq64
.remoteID
;
3121 ndlp
= lpfc_findnode_did(vport
, did
);
3122 if ((!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
))
3123 && (cmd
!= ELS_CMD_PLOGI
))
3127 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
3128 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
3129 *(((uint32_t *) irsp
) + 7), irsp
->un
.ulpWord
[4], ndlp
->nlp_DID
);
3131 switch (irsp
->ulpStatus
) {
3132 case IOSTAT_FCP_RSP_ERROR
:
3134 case IOSTAT_REMOTE_STOP
:
3135 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
3136 /* This IO was aborted by the target, we don't
3137 * know the rxid and because we did not send the
3138 * ABTS we cannot generate and RRQ.
3140 lpfc_set_rrq_active(phba
, ndlp
,
3141 cmdiocb
->sli4_lxritag
, 0, 0);
3144 case IOSTAT_LOCAL_REJECT
:
3145 switch ((irsp
->un
.ulpWord
[4] & IOERR_PARAM_MASK
)) {
3146 case IOERR_LOOP_OPEN_FAILURE
:
3147 if (cmd
== ELS_CMD_FLOGI
) {
3148 if (PCI_DEVICE_ID_HORNET
==
3149 phba
->pcidev
->device
) {
3150 phba
->fc_topology
= LPFC_TOPOLOGY_LOOP
;
3151 phba
->pport
->fc_myDID
= 0;
3152 phba
->alpa_map
[0] = 0;
3153 phba
->alpa_map
[1] = 0;
3156 if (cmd
== ELS_CMD_PLOGI
&& cmdiocb
->retry
== 0)
3161 case IOERR_ILLEGAL_COMMAND
:
3162 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
3163 "0124 Retry illegal cmd x%x "
3164 "retry:x%x delay:x%x\n",
3165 cmd
, cmdiocb
->retry
, delay
);
3167 /* All command's retry policy */
3169 if (cmdiocb
->retry
> 2)
3173 case IOERR_NO_RESOURCES
:
3174 logerr
= 1; /* HBA out of resources */
3176 if (cmdiocb
->retry
> 100)
3181 case IOERR_ILLEGAL_FRAME
:
3186 case IOERR_SEQUENCE_TIMEOUT
:
3187 case IOERR_INVALID_RPI
:
3188 if (cmd
== ELS_CMD_PLOGI
&&
3189 did
== NameServer_DID
) {
3190 /* Continue forever if plogi to */
3191 /* the nameserver fails */
3200 case IOSTAT_NPORT_RJT
:
3201 case IOSTAT_FABRIC_RJT
:
3202 if (irsp
->un
.ulpWord
[4] & RJT_UNAVAIL_TEMP
) {
3208 case IOSTAT_NPORT_BSY
:
3209 case IOSTAT_FABRIC_BSY
:
3210 logerr
= 1; /* Fabric / Remote NPort out of resources */
3215 stat
.un
.lsRjtError
= be32_to_cpu(irsp
->un
.ulpWord
[4]);
3216 /* Added for Vendor specifc support
3217 * Just keep retrying for these Rsn / Exp codes
3219 switch (stat
.un
.b
.lsRjtRsnCode
) {
3220 case LSRJT_UNABLE_TPC
:
3221 if (stat
.un
.b
.lsRjtRsnCodeExp
==
3222 LSEXP_CMD_IN_PROGRESS
) {
3223 if (cmd
== ELS_CMD_PLOGI
) {
3230 if (stat
.un
.b
.lsRjtRsnCodeExp
==
3231 LSEXP_CANT_GIVE_DATA
) {
3232 if (cmd
== ELS_CMD_PLOGI
) {
3239 if ((cmd
== ELS_CMD_PLOGI
) ||
3240 (cmd
== ELS_CMD_PRLI
)) {
3242 maxretry
= lpfc_max_els_tries
+ 1;
3246 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
3247 (cmd
== ELS_CMD_FDISC
) &&
3248 (stat
.un
.b
.lsRjtRsnCodeExp
== LSEXP_OUT_OF_RESOURCE
)){
3249 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
3250 "0125 FDISC Failed (x%x). "
3251 "Fabric out of resources\n",
3252 stat
.un
.lsRjtError
);
3253 lpfc_vport_set_state(vport
,
3254 FC_VPORT_NO_FABRIC_RSCS
);
3258 case LSRJT_LOGICAL_BSY
:
3259 if ((cmd
== ELS_CMD_PLOGI
) ||
3260 (cmd
== ELS_CMD_PRLI
)) {
3263 } else if (cmd
== ELS_CMD_FDISC
) {
3264 /* FDISC retry policy */
3266 if (cmdiocb
->retry
>= 32)
3272 case LSRJT_LOGICAL_ERR
:
3273 /* There are some cases where switches return this
3274 * error when they are not ready and should be returning
3275 * Logical Busy. We should delay every time.
3277 if (cmd
== ELS_CMD_FDISC
&&
3278 stat
.un
.b
.lsRjtRsnCodeExp
== LSEXP_PORT_LOGIN_REQ
) {
3284 case LSRJT_PROTOCOL_ERR
:
3285 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
3286 (cmd
== ELS_CMD_FDISC
) &&
3287 ((stat
.un
.b
.lsRjtRsnCodeExp
== LSEXP_INVALID_PNAME
) ||
3288 (stat
.un
.b
.lsRjtRsnCodeExp
== LSEXP_INVALID_NPORT_ID
))
3290 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
3291 "0122 FDISC Failed (x%x). "
3292 "Fabric Detected Bad WWN\n",
3293 stat
.un
.lsRjtError
);
3294 lpfc_vport_set_state(vport
,
3295 FC_VPORT_FABRIC_REJ_WWN
);
3301 case IOSTAT_INTERMED_RSP
:
3309 if (did
== FDMI_DID
)
3312 if ((cmd
== ELS_CMD_FLOGI
) &&
3313 (phba
->fc_topology
!= LPFC_TOPOLOGY_LOOP
) &&
3314 !lpfc_error_lost_link(irsp
)) {
3315 /* FLOGI retry policy */
3317 /* retry FLOGI forever */
3318 if (phba
->link_flag
!= LS_LOOPBACK_MODE
)
3323 if (cmdiocb
->retry
>= 100)
3325 else if (cmdiocb
->retry
>= 32)
3327 } else if ((cmd
== ELS_CMD_FDISC
) && !lpfc_error_lost_link(irsp
)) {
3328 /* retry FDISCs every second up to devloss */
3330 maxretry
= vport
->cfg_devloss_tmo
;
3335 if (maxretry
&& (cmdiocb
->retry
>= maxretry
)) {
3336 phba
->fc_stat
.elsRetryExceeded
++;
3340 if ((vport
->load_flag
& FC_UNLOADING
) != 0)
3344 if ((cmd
== ELS_CMD_PLOGI
) || (cmd
== ELS_CMD_FDISC
)) {
3345 /* Stop retrying PLOGI and FDISC if in FCF discovery */
3346 if (phba
->fcf
.fcf_flag
& FCF_DISCOVERY
) {
3347 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3348 "2849 Stop retry ELS command "
3349 "x%x to remote NPORT x%x, "
3350 "Data: x%x x%x\n", cmd
, did
,
3351 cmdiocb
->retry
, delay
);
3356 /* Retry ELS command <elsCmd> to remote NPORT <did> */
3357 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3358 "0107 Retry ELS command x%x to remote "
3359 "NPORT x%x Data: x%x x%x\n",
3360 cmd
, did
, cmdiocb
->retry
, delay
);
3362 if (((cmd
== ELS_CMD_PLOGI
) || (cmd
== ELS_CMD_ADISC
)) &&
3363 ((irsp
->ulpStatus
!= IOSTAT_LOCAL_REJECT
) ||
3364 ((irsp
->un
.ulpWord
[4] & IOERR_PARAM_MASK
) !=
3365 IOERR_NO_RESOURCES
))) {
3366 /* Don't reset timer for no resources */
3368 /* If discovery / RSCN timer is running, reset it */
3369 if (timer_pending(&vport
->fc_disctmo
) ||
3370 (vport
->fc_flag
& FC_RSCN_MODE
))
3371 lpfc_set_disctmo(vport
);
3374 phba
->fc_stat
.elsXmitRetry
++;
3375 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
) && delay
) {
3376 phba
->fc_stat
.elsDelayRetry
++;
3377 ndlp
->nlp_retry
= cmdiocb
->retry
;
3379 /* delay is specified in milliseconds */
3380 mod_timer(&ndlp
->nlp_delayfunc
,
3381 jiffies
+ msecs_to_jiffies(delay
));
3382 spin_lock_irq(shost
->host_lock
);
3383 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
3384 spin_unlock_irq(shost
->host_lock
);
3386 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
3387 if (cmd
== ELS_CMD_PRLI
)
3388 lpfc_nlp_set_state(vport
, ndlp
,
3389 NLP_STE_PRLI_ISSUE
);
3391 lpfc_nlp_set_state(vport
, ndlp
,
3393 ndlp
->nlp_last_elscmd
= cmd
;
3399 lpfc_issue_els_flogi(vport
, ndlp
, cmdiocb
->retry
);
3402 lpfc_issue_els_fdisc(vport
, ndlp
, cmdiocb
->retry
);
3405 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
)) {
3406 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
3407 lpfc_nlp_set_state(vport
, ndlp
,
3408 NLP_STE_PLOGI_ISSUE
);
3410 lpfc_issue_els_plogi(vport
, did
, cmdiocb
->retry
);
3413 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
3414 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_ADISC_ISSUE
);
3415 lpfc_issue_els_adisc(vport
, ndlp
, cmdiocb
->retry
);
3418 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
3419 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PRLI_ISSUE
);
3420 lpfc_issue_els_prli(vport
, ndlp
, cmdiocb
->retry
);
3423 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
3424 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_LOGO_ISSUE
);
3425 lpfc_issue_els_logo(vport
, ndlp
, cmdiocb
->retry
);
3429 /* No retry ELS command <elsCmd> to remote NPORT <did> */
3431 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
3432 "0137 No retry ELS command x%x to remote "
3433 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
3434 cmd
, did
, irsp
->ulpStatus
,
3435 irsp
->un
.ulpWord
[4]);
3438 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3439 "0108 No retry ELS command x%x to remote "
3440 "NPORT x%x Retried:%d Error:x%x/%x\n",
3441 cmd
, did
, cmdiocb
->retry
, irsp
->ulpStatus
,
3442 irsp
->un
.ulpWord
[4]);
3448 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
3449 * @phba: pointer to lpfc hba data structure.
3450 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
3452 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
3453 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
3454 * checks to see whether there is a lpfc DMA buffer associated with the
3455 * response of the command IOCB. If so, it will be released before releasing
3456 * the lpfc DMA buffer associated with the IOCB itself.
3459 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3462 lpfc_els_free_data(struct lpfc_hba
*phba
, struct lpfc_dmabuf
*buf_ptr1
)
3464 struct lpfc_dmabuf
*buf_ptr
;
3466 /* Free the response before processing the command. */
3467 if (!list_empty(&buf_ptr1
->list
)) {
3468 list_remove_head(&buf_ptr1
->list
, buf_ptr
,
3471 lpfc_mbuf_free(phba
, buf_ptr
->virt
, buf_ptr
->phys
);
3474 lpfc_mbuf_free(phba
, buf_ptr1
->virt
, buf_ptr1
->phys
);
3480 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
3481 * @phba: pointer to lpfc hba data structure.
3482 * @buf_ptr: pointer to the lpfc dma buffer data structure.
3484 * This routine releases the lpfc Direct Memory Access (DMA) buffer
3485 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
3489 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3492 lpfc_els_free_bpl(struct lpfc_hba
*phba
, struct lpfc_dmabuf
*buf_ptr
)
3494 lpfc_mbuf_free(phba
, buf_ptr
->virt
, buf_ptr
->phys
);
3500 * lpfc_els_free_iocb - Free a command iocb and its associated resources
3501 * @phba: pointer to lpfc hba data structure.
3502 * @elsiocb: pointer to lpfc els command iocb data structure.
3504 * This routine frees a command IOCB and its associated resources. The
3505 * command IOCB data structure contains the reference to various associated
3506 * resources, these fields must be set to NULL if the associated reference
3508 * context1 - reference to ndlp
3509 * context2 - reference to cmd
3510 * context2->next - reference to rsp
3511 * context3 - reference to bpl
3513 * It first properly decrements the reference count held on ndlp for the
3514 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
3515 * set, it invokes the lpfc_els_free_data() routine to release the Direct
3516 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
3517 * adds the DMA buffer the @phba data structure for the delayed release.
3518 * If reference to the Buffer Pointer List (BPL) is present, the
3519 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
3520 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
3521 * invoked to release the IOCB data structure back to @phba IOCBQ list.
3524 * 0 - Success (currently, always return 0)
3527 lpfc_els_free_iocb(struct lpfc_hba
*phba
, struct lpfc_iocbq
*elsiocb
)
3529 struct lpfc_dmabuf
*buf_ptr
, *buf_ptr1
;
3530 struct lpfc_nodelist
*ndlp
;
3532 ndlp
= (struct lpfc_nodelist
*)elsiocb
->context1
;
3534 if (ndlp
->nlp_flag
& NLP_DEFER_RM
) {
3537 /* If the ndlp is not being used by another discovery
3540 if (!lpfc_nlp_not_used(ndlp
)) {
3541 /* If ndlp is being used by another discovery
3542 * thread, just clear NLP_DEFER_RM
3544 ndlp
->nlp_flag
&= ~NLP_DEFER_RM
;
3549 elsiocb
->context1
= NULL
;
3551 /* context2 = cmd, context2->next = rsp, context3 = bpl */
3552 if (elsiocb
->context2
) {
3553 if (elsiocb
->iocb_flag
& LPFC_DELAY_MEM_FREE
) {
3554 /* Firmware could still be in progress of DMAing
3555 * payload, so don't free data buffer till after
3558 elsiocb
->iocb_flag
&= ~LPFC_DELAY_MEM_FREE
;
3559 buf_ptr
= elsiocb
->context2
;
3560 elsiocb
->context2
= NULL
;
3563 spin_lock_irq(&phba
->hbalock
);
3564 if (!list_empty(&buf_ptr
->list
)) {
3565 list_remove_head(&buf_ptr
->list
,
3566 buf_ptr1
, struct lpfc_dmabuf
,
3568 INIT_LIST_HEAD(&buf_ptr1
->list
);
3569 list_add_tail(&buf_ptr1
->list
,
3573 INIT_LIST_HEAD(&buf_ptr
->list
);
3574 list_add_tail(&buf_ptr
->list
, &phba
->elsbuf
);
3576 spin_unlock_irq(&phba
->hbalock
);
3579 buf_ptr1
= (struct lpfc_dmabuf
*) elsiocb
->context2
;
3580 lpfc_els_free_data(phba
, buf_ptr1
);
3584 if (elsiocb
->context3
) {
3585 buf_ptr
= (struct lpfc_dmabuf
*) elsiocb
->context3
;
3586 lpfc_els_free_bpl(phba
, buf_ptr
);
3588 lpfc_sli_release_iocbq(phba
, elsiocb
);
3593 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
3594 * @phba: pointer to lpfc hba data structure.
3595 * @cmdiocb: pointer to lpfc command iocb data structure.
3596 * @rspiocb: pointer to lpfc response iocb data structure.
3598 * This routine is the completion callback function to the Logout (LOGO)
3599 * Accept (ACC) Response ELS command. This routine is invoked to indicate
3600 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
3601 * release the ndlp if it has the last reference remaining (reference count
3602 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
3603 * field to NULL to inform the following lpfc_els_free_iocb() routine no
3604 * ndlp reference count needs to be decremented. Otherwise, the ndlp
3605 * reference use-count shall be decremented by the lpfc_els_free_iocb()
3606 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
3607 * IOCB data structure.
3610 lpfc_cmpl_els_logo_acc(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
3611 struct lpfc_iocbq
*rspiocb
)
3613 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
3614 struct lpfc_vport
*vport
= cmdiocb
->vport
;
3617 irsp
= &rspiocb
->iocb
;
3618 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
3619 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
3620 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4], ndlp
->nlp_DID
);
3621 /* ACC to LOGO completes to NPort <nlp_DID> */
3622 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3623 "0109 ACC to LOGO completes to NPort x%x "
3624 "Data: x%x x%x x%x\n",
3625 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
3628 if (ndlp
->nlp_state
== NLP_STE_NPR_NODE
) {
3629 /* NPort Recovery mode or node is just allocated */
3630 if (!lpfc_nlp_not_used(ndlp
)) {
3631 /* If the ndlp is being used by another discovery
3632 * thread, just unregister the RPI.
3634 lpfc_unreg_rpi(vport
, ndlp
);
3636 /* Indicate the node has already released, should
3637 * not reference to it from within lpfc_els_free_iocb.
3639 cmdiocb
->context1
= NULL
;
3644 * The driver received a LOGO from the rport and has ACK'd it.
3645 * At this point, the driver is done so release the IOCB
3647 lpfc_els_free_iocb(phba
, cmdiocb
);
3651 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
3652 * @phba: pointer to lpfc hba data structure.
3653 * @pmb: pointer to the driver internal queue element for mailbox command.
3655 * This routine is the completion callback function for unregister default
3656 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
3657 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
3658 * decrements the ndlp reference count held for this completion callback
3659 * function. After that, it invokes the lpfc_nlp_not_used() to check
3660 * whether there is only one reference left on the ndlp. If so, it will
3661 * perform one more decrement and trigger the release of the ndlp.
3664 lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
3666 struct lpfc_dmabuf
*mp
= (struct lpfc_dmabuf
*) (pmb
->context1
);
3667 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
3669 pmb
->context1
= NULL
;
3670 pmb
->context2
= NULL
;
3672 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
3674 mempool_free(pmb
, phba
->mbox_mem_pool
);
3676 lpfc_printf_vlog(ndlp
->vport
, KERN_INFO
, LOG_NODE
,
3677 "0006 rpi%x DID:%x flg:%x %d map:%x %p\n",
3678 ndlp
->nlp_rpi
, ndlp
->nlp_DID
, ndlp
->nlp_flag
,
3679 atomic_read(&ndlp
->kref
.refcount
),
3680 ndlp
->nlp_usg_map
, ndlp
);
3681 if (NLP_CHK_NODE_ACT(ndlp
)) {
3683 /* This is the end of the default RPI cleanup logic for
3684 * this ndlp. If no other discovery threads are using
3685 * this ndlp, free all resources associated with it.
3687 lpfc_nlp_not_used(ndlp
);
3689 lpfc_drop_node(ndlp
->vport
, ndlp
);
3697 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
3698 * @phba: pointer to lpfc hba data structure.
3699 * @cmdiocb: pointer to lpfc command iocb data structure.
3700 * @rspiocb: pointer to lpfc response iocb data structure.
3702 * This routine is the completion callback function for ELS Response IOCB
3703 * command. In normal case, this callback function just properly sets the
3704 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
3705 * field in the command IOCB is not NULL, the referred mailbox command will
3706 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
3707 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
3708 * link down event occurred during the discovery, the lpfc_nlp_not_used()
3709 * routine shall be invoked trying to release the ndlp if no other threads
3710 * are currently referring it.
3713 lpfc_cmpl_els_rsp(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
3714 struct lpfc_iocbq
*rspiocb
)
3716 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
3717 struct lpfc_vport
*vport
= ndlp
? ndlp
->vport
: NULL
;
3718 struct Scsi_Host
*shost
= vport
? lpfc_shost_from_vport(vport
) : NULL
;
3721 LPFC_MBOXQ_t
*mbox
= NULL
;
3722 struct lpfc_dmabuf
*mp
= NULL
;
3723 uint32_t ls_rjt
= 0;
3725 irsp
= &rspiocb
->iocb
;
3727 if (cmdiocb
->context_un
.mbox
)
3728 mbox
= cmdiocb
->context_un
.mbox
;
3730 /* First determine if this is a LS_RJT cmpl. Note, this callback
3731 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
3733 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) cmdiocb
->context2
)->virt
);
3734 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
) &&
3735 (*((uint32_t *) (pcmd
)) == ELS_CMD_LS_RJT
)) {
3736 /* A LS_RJT associated with Default RPI cleanup has its own
3737 * separate code path.
3739 if (!(ndlp
->nlp_flag
& NLP_RM_DFLT_RPI
))
3743 /* Check to see if link went down during discovery */
3744 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
) || lpfc_els_chk_latt(vport
)) {
3746 mp
= (struct lpfc_dmabuf
*) mbox
->context1
;
3748 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
3751 mempool_free(mbox
, phba
->mbox_mem_pool
);
3753 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
) &&
3754 (ndlp
->nlp_flag
& NLP_RM_DFLT_RPI
))
3755 if (lpfc_nlp_not_used(ndlp
)) {
3757 /* Indicate the node has already released,
3758 * should not reference to it from within
3759 * the routine lpfc_els_free_iocb.
3761 cmdiocb
->context1
= NULL
;
3766 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
3767 "ELS rsp cmpl: status:x%x/x%x did:x%x",
3768 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
3769 cmdiocb
->iocb
.un
.elsreq64
.remoteID
);
3770 /* ELS response tag <ulpIoTag> completes */
3771 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3772 "0110 ELS response tag x%x completes "
3773 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
3774 cmdiocb
->iocb
.ulpIoTag
, rspiocb
->iocb
.ulpStatus
,
3775 rspiocb
->iocb
.un
.ulpWord
[4], rspiocb
->iocb
.ulpTimeout
,
3776 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
3779 if ((rspiocb
->iocb
.ulpStatus
== 0)
3780 && (ndlp
->nlp_flag
& NLP_ACC_REGLOGIN
)) {
3781 lpfc_unreg_rpi(vport
, ndlp
);
3782 /* Increment reference count to ndlp to hold the
3783 * reference to ndlp for the callback function.
3785 mbox
->context2
= lpfc_nlp_get(ndlp
);
3786 mbox
->vport
= vport
;
3787 if (ndlp
->nlp_flag
& NLP_RM_DFLT_RPI
) {
3788 mbox
->mbox_flag
|= LPFC_MBX_IMED_UNREG
;
3789 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_dflt_rpi
;
3792 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_reg_login
;
3793 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
3794 lpfc_nlp_set_state(vport
, ndlp
,
3795 NLP_STE_REG_LOGIN_ISSUE
);
3798 ndlp
->nlp_flag
|= NLP_REG_LOGIN_SEND
;
3799 if (lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
)
3800 != MBX_NOT_FINISHED
)
3803 /* Decrement the ndlp reference count we
3804 * set for this failed mailbox command.
3807 ndlp
->nlp_flag
&= ~NLP_REG_LOGIN_SEND
;
3809 /* ELS rsp: Cannot issue reg_login for <NPortid> */
3810 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
3811 "0138 ELS rsp: Cannot issue reg_login for x%x "
3812 "Data: x%x x%x x%x\n",
3813 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
3816 if (lpfc_nlp_not_used(ndlp
)) {
3818 /* Indicate node has already been released,
3819 * should not reference to it from within
3820 * the routine lpfc_els_free_iocb.
3822 cmdiocb
->context1
= NULL
;
3825 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
3826 if (!lpfc_error_lost_link(irsp
) &&
3827 ndlp
->nlp_flag
& NLP_ACC_REGLOGIN
) {
3828 if (lpfc_nlp_not_used(ndlp
)) {
3830 /* Indicate node has already been
3831 * released, should not reference
3832 * to it from within the routine
3833 * lpfc_els_free_iocb.
3835 cmdiocb
->context1
= NULL
;
3839 mp
= (struct lpfc_dmabuf
*) mbox
->context1
;
3841 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
3844 mempool_free(mbox
, phba
->mbox_mem_pool
);
3847 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
)) {
3848 spin_lock_irq(shost
->host_lock
);
3849 ndlp
->nlp_flag
&= ~(NLP_ACC_REGLOGIN
| NLP_RM_DFLT_RPI
);
3850 spin_unlock_irq(shost
->host_lock
);
3852 /* If the node is not being used by another discovery thread,
3853 * and we are sending a reject, we are done with it.
3854 * Release driver reference count here and free associated
3858 if (lpfc_nlp_not_used(ndlp
))
3859 /* Indicate node has already been released,
3860 * should not reference to it from within
3861 * the routine lpfc_els_free_iocb.
3863 cmdiocb
->context1
= NULL
;
3867 lpfc_els_free_iocb(phba
, cmdiocb
);
3872 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
3873 * @vport: pointer to a host virtual N_Port data structure.
3874 * @flag: the els command code to be accepted.
3875 * @oldiocb: pointer to the original lpfc command iocb data structure.
3876 * @ndlp: pointer to a node-list data structure.
3877 * @mbox: pointer to the driver internal queue element for mailbox command.
3879 * This routine prepares and issues an Accept (ACC) response IOCB
3880 * command. It uses the @flag to properly set up the IOCB field for the
3881 * specific ACC response command to be issued and invokes the
3882 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
3883 * @mbox pointer is passed in, it will be put into the context_un.mbox
3884 * field of the IOCB for the completion callback function to issue the
3885 * mailbox command to the HBA later when callback is invoked.
3887 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3888 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3889 * will be stored into the context1 field of the IOCB for the completion
3890 * callback function to the corresponding response ELS IOCB command.
3893 * 0 - Successfully issued acc response
3894 * 1 - Failed to issue acc response
3897 lpfc_els_rsp_acc(struct lpfc_vport
*vport
, uint32_t flag
,
3898 struct lpfc_iocbq
*oldiocb
, struct lpfc_nodelist
*ndlp
,
3901 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3902 struct lpfc_hba
*phba
= vport
->phba
;
3905 struct lpfc_iocbq
*elsiocb
;
3907 struct serv_parm
*sp
;
3910 ELS_PKT
*els_pkt_ptr
;
3912 oldcmd
= &oldiocb
->iocb
;
3916 cmdsize
= sizeof(uint32_t);
3917 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
,
3918 ndlp
, ndlp
->nlp_DID
, ELS_CMD_ACC
);
3920 spin_lock_irq(shost
->host_lock
);
3921 ndlp
->nlp_flag
&= ~NLP_LOGO_ACC
;
3922 spin_unlock_irq(shost
->host_lock
);
3926 icmd
= &elsiocb
->iocb
;
3927 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri / rx_id */
3928 icmd
->unsli3
.rcvsli3
.ox_id
= oldcmd
->unsli3
.rcvsli3
.ox_id
;
3929 pcmd
= (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
3930 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
3931 pcmd
+= sizeof(uint32_t);
3933 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
3934 "Issue ACC: did:x%x flg:x%x",
3935 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
3939 cmdsize
= (sizeof(struct serv_parm
) + sizeof(uint32_t));
3940 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
,
3941 ndlp
, ndlp
->nlp_DID
, ELS_CMD_ACC
);
3945 icmd
= &elsiocb
->iocb
;
3946 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri / rx_id */
3947 icmd
->unsli3
.rcvsli3
.ox_id
= oldcmd
->unsli3
.rcvsli3
.ox_id
;
3948 pcmd
= (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
3951 elsiocb
->context_un
.mbox
= mbox
;
3953 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
3954 pcmd
+= sizeof(uint32_t);
3955 sp
= (struct serv_parm
*)pcmd
;
3957 if (flag
== ELS_CMD_FLOGI
) {
3958 /* Copy the received service parameters back */
3959 memcpy(sp
, &phba
->fc_fabparam
,
3960 sizeof(struct serv_parm
));
3962 /* Clear the F_Port bit */
3965 /* Mark all class service parameters as invalid */
3966 sp
->cls1
.classValid
= 0;
3967 sp
->cls2
.classValid
= 0;
3968 sp
->cls3
.classValid
= 0;
3969 sp
->cls4
.classValid
= 0;
3971 /* Copy our worldwide names */
3972 memcpy(&sp
->portName
, &vport
->fc_sparam
.portName
,
3973 sizeof(struct lpfc_name
));
3974 memcpy(&sp
->nodeName
, &vport
->fc_sparam
.nodeName
,
3975 sizeof(struct lpfc_name
));
3977 memcpy(pcmd
, &vport
->fc_sparam
,
3978 sizeof(struct serv_parm
));
3981 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
3982 "Issue ACC FLOGI/PLOGI: did:x%x flg:x%x",
3983 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
3986 cmdsize
= sizeof(uint32_t) + sizeof(PRLO
);
3987 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
,
3988 ndlp
, ndlp
->nlp_DID
, ELS_CMD_PRLO
);
3992 icmd
= &elsiocb
->iocb
;
3993 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri / rx_id */
3994 icmd
->unsli3
.rcvsli3
.ox_id
= oldcmd
->unsli3
.rcvsli3
.ox_id
;
3995 pcmd
= (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
3997 memcpy(pcmd
, ((struct lpfc_dmabuf
*) oldiocb
->context2
)->virt
,
3998 sizeof(uint32_t) + sizeof(PRLO
));
3999 *((uint32_t *) (pcmd
)) = ELS_CMD_PRLO_ACC
;
4000 els_pkt_ptr
= (ELS_PKT
*) pcmd
;
4001 els_pkt_ptr
->un
.prlo
.acceptRspCode
= PRLO_REQ_EXECUTED
;
4003 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
4004 "Issue ACC PRLO: did:x%x flg:x%x",
4005 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
4010 /* Xmit ELS ACC response tag <ulpIoTag> */
4011 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
4012 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
4013 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x "
4015 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
4016 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
4017 ndlp
->nlp_rpi
, vport
->fc_flag
);
4018 if (ndlp
->nlp_flag
& NLP_LOGO_ACC
) {
4019 spin_lock_irq(shost
->host_lock
);
4020 if (!(ndlp
->nlp_flag
& NLP_RPI_REGISTERED
||
4021 ndlp
->nlp_flag
& NLP_REG_LOGIN_SEND
))
4022 ndlp
->nlp_flag
&= ~NLP_LOGO_ACC
;
4023 spin_unlock_irq(shost
->host_lock
);
4024 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_logo_acc
;
4026 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
4029 phba
->fc_stat
.elsXmitACC
++;
4030 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
4031 if (rc
== IOCB_ERROR
) {
4032 lpfc_els_free_iocb(phba
, elsiocb
);
4039 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
4040 * @vport: pointer to a virtual N_Port data structure.
4042 * @oldiocb: pointer to the original lpfc command iocb data structure.
4043 * @ndlp: pointer to a node-list data structure.
4044 * @mbox: pointer to the driver internal queue element for mailbox command.
4046 * This routine prepares and issue an Reject (RJT) response IOCB
4047 * command. If a @mbox pointer is passed in, it will be put into the
4048 * context_un.mbox field of the IOCB for the completion callback function
4049 * to issue to the HBA later.
4051 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4052 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4053 * will be stored into the context1 field of the IOCB for the completion
4054 * callback function to the reject response ELS IOCB command.
4057 * 0 - Successfully issued reject response
4058 * 1 - Failed to issue reject response
4061 lpfc_els_rsp_reject(struct lpfc_vport
*vport
, uint32_t rejectError
,
4062 struct lpfc_iocbq
*oldiocb
, struct lpfc_nodelist
*ndlp
,
4065 struct lpfc_hba
*phba
= vport
->phba
;
4068 struct lpfc_iocbq
*elsiocb
;
4073 cmdsize
= 2 * sizeof(uint32_t);
4074 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
4075 ndlp
->nlp_DID
, ELS_CMD_LS_RJT
);
4079 icmd
= &elsiocb
->iocb
;
4080 oldcmd
= &oldiocb
->iocb
;
4081 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri / rx_id */
4082 icmd
->unsli3
.rcvsli3
.ox_id
= oldcmd
->unsli3
.rcvsli3
.ox_id
;
4083 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
4085 *((uint32_t *) (pcmd
)) = ELS_CMD_LS_RJT
;
4086 pcmd
+= sizeof(uint32_t);
4087 *((uint32_t *) (pcmd
)) = rejectError
;
4090 elsiocb
->context_un
.mbox
= mbox
;
4092 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
4093 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
4094 "0129 Xmit ELS RJT x%x response tag x%x "
4095 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
4097 rejectError
, elsiocb
->iotag
,
4098 elsiocb
->iocb
.ulpContext
, ndlp
->nlp_DID
,
4099 ndlp
->nlp_flag
, ndlp
->nlp_state
, ndlp
->nlp_rpi
);
4100 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
4101 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
4102 ndlp
->nlp_DID
, ndlp
->nlp_flag
, rejectError
);
4104 phba
->fc_stat
.elsXmitLSRJT
++;
4105 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
4106 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
4108 if (rc
== IOCB_ERROR
) {
4109 lpfc_els_free_iocb(phba
, elsiocb
);
4116 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
4117 * @vport: pointer to a virtual N_Port data structure.
4118 * @oldiocb: pointer to the original lpfc command iocb data structure.
4119 * @ndlp: pointer to a node-list data structure.
4121 * This routine prepares and issues an Accept (ACC) response to Address
4122 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
4123 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
4125 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4126 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4127 * will be stored into the context1 field of the IOCB for the completion
4128 * callback function to the ADISC Accept response ELS IOCB command.
4131 * 0 - Successfully issued acc adisc response
4132 * 1 - Failed to issue adisc acc response
4135 lpfc_els_rsp_adisc_acc(struct lpfc_vport
*vport
, struct lpfc_iocbq
*oldiocb
,
4136 struct lpfc_nodelist
*ndlp
)
4138 struct lpfc_hba
*phba
= vport
->phba
;
4140 IOCB_t
*icmd
, *oldcmd
;
4141 struct lpfc_iocbq
*elsiocb
;
4146 cmdsize
= sizeof(uint32_t) + sizeof(ADISC
);
4147 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
4148 ndlp
->nlp_DID
, ELS_CMD_ACC
);
4152 icmd
= &elsiocb
->iocb
;
4153 oldcmd
= &oldiocb
->iocb
;
4154 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri / rx_id */
4155 icmd
->unsli3
.rcvsli3
.ox_id
= oldcmd
->unsli3
.rcvsli3
.ox_id
;
4157 /* Xmit ADISC ACC response tag <ulpIoTag> */
4158 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
4159 "0130 Xmit ADISC ACC response iotag x%x xri: "
4160 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
4161 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
4162 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
4164 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
4166 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
4167 pcmd
+= sizeof(uint32_t);
4169 ap
= (ADISC
*) (pcmd
);
4170 ap
->hardAL_PA
= phba
->fc_pref_ALPA
;
4171 memcpy(&ap
->portName
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
4172 memcpy(&ap
->nodeName
, &vport
->fc_nodename
, sizeof(struct lpfc_name
));
4173 ap
->DID
= be32_to_cpu(vport
->fc_myDID
);
4175 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
4176 "Issue ACC ADISC: did:x%x flg:x%x",
4177 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
4179 phba
->fc_stat
.elsXmitACC
++;
4180 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
4181 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
4182 if (rc
== IOCB_ERROR
) {
4183 lpfc_els_free_iocb(phba
, elsiocb
);
4190 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
4191 * @vport: pointer to a virtual N_Port data structure.
4192 * @oldiocb: pointer to the original lpfc command iocb data structure.
4193 * @ndlp: pointer to a node-list data structure.
4195 * This routine prepares and issues an Accept (ACC) response to Process
4196 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
4197 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
4199 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4200 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4201 * will be stored into the context1 field of the IOCB for the completion
4202 * callback function to the PRLI Accept response ELS IOCB command.
4205 * 0 - Successfully issued acc prli response
4206 * 1 - Failed to issue acc prli response
4209 lpfc_els_rsp_prli_acc(struct lpfc_vport
*vport
, struct lpfc_iocbq
*oldiocb
,
4210 struct lpfc_nodelist
*ndlp
)
4212 struct lpfc_hba
*phba
= vport
->phba
;
4217 struct lpfc_iocbq
*elsiocb
;
4222 cmdsize
= sizeof(uint32_t) + sizeof(PRLI
);
4223 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
4224 ndlp
->nlp_DID
, (ELS_CMD_ACC
| (ELS_CMD_PRLI
& ~ELS_RSP_MASK
)));
4228 icmd
= &elsiocb
->iocb
;
4229 oldcmd
= &oldiocb
->iocb
;
4230 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri / rx_id */
4231 icmd
->unsli3
.rcvsli3
.ox_id
= oldcmd
->unsli3
.rcvsli3
.ox_id
;
4233 /* Xmit PRLI ACC response tag <ulpIoTag> */
4234 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
4235 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
4236 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
4237 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
4238 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
4240 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
4242 *((uint32_t *) (pcmd
)) = (ELS_CMD_ACC
| (ELS_CMD_PRLI
& ~ELS_RSP_MASK
));
4243 pcmd
+= sizeof(uint32_t);
4245 /* For PRLI, remainder of payload is PRLI parameter page */
4246 memset(pcmd
, 0, sizeof(PRLI
));
4248 npr
= (PRLI
*) pcmd
;
4251 * If the remote port is a target and our firmware version is 3.20 or
4252 * later, set the following bits for FC-TAPE support.
4254 if ((ndlp
->nlp_type
& NLP_FCP_TARGET
) &&
4255 (vpd
->rev
.feaLevelHigh
>= 0x02)) {
4256 npr
->ConfmComplAllowed
= 1;
4258 npr
->TaskRetryIdReq
= 1;
4261 npr
->acceptRspCode
= PRLI_REQ_EXECUTED
;
4262 npr
->estabImagePair
= 1;
4263 npr
->readXferRdyDis
= 1;
4264 npr
->ConfmComplAllowed
= 1;
4266 npr
->prliType
= PRLI_FCP_TYPE
;
4267 npr
->initiatorFunc
= 1;
4269 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
4270 "Issue ACC PRLI: did:x%x flg:x%x",
4271 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
4273 phba
->fc_stat
.elsXmitACC
++;
4274 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
4276 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
4277 if (rc
== IOCB_ERROR
) {
4278 lpfc_els_free_iocb(phba
, elsiocb
);
4285 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
4286 * @vport: pointer to a virtual N_Port data structure.
4287 * @format: rnid command format.
4288 * @oldiocb: pointer to the original lpfc command iocb data structure.
4289 * @ndlp: pointer to a node-list data structure.
4291 * This routine issues a Request Node Identification Data (RNID) Accept
4292 * (ACC) response. It constructs the RNID ACC response command according to
4293 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
4294 * issue the response. Note that this command does not need to hold the ndlp
4295 * reference count for the callback. So, the ndlp reference count taken by
4296 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
4297 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
4298 * there is no ndlp reference available.
4300 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4301 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4302 * will be stored into the context1 field of the IOCB for the completion
4303 * callback function. However, for the RNID Accept Response ELS command,
4304 * this is undone later by this routine after the IOCB is allocated.
4307 * 0 - Successfully issued acc rnid response
4308 * 1 - Failed to issue acc rnid response
4311 lpfc_els_rsp_rnid_acc(struct lpfc_vport
*vport
, uint8_t format
,
4312 struct lpfc_iocbq
*oldiocb
, struct lpfc_nodelist
*ndlp
)
4314 struct lpfc_hba
*phba
= vport
->phba
;
4316 IOCB_t
*icmd
, *oldcmd
;
4317 struct lpfc_iocbq
*elsiocb
;
4322 cmdsize
= sizeof(uint32_t) + sizeof(uint32_t)
4323 + (2 * sizeof(struct lpfc_name
));
4325 cmdsize
+= sizeof(RNID_TOP_DISC
);
4327 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
4328 ndlp
->nlp_DID
, ELS_CMD_ACC
);
4332 icmd
= &elsiocb
->iocb
;
4333 oldcmd
= &oldiocb
->iocb
;
4334 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri / rx_id */
4335 icmd
->unsli3
.rcvsli3
.ox_id
= oldcmd
->unsli3
.rcvsli3
.ox_id
;
4337 /* Xmit RNID ACC response tag <ulpIoTag> */
4338 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
4339 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
4340 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
);
4341 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
4342 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
4343 pcmd
+= sizeof(uint32_t);
4345 memset(pcmd
, 0, sizeof(RNID
));
4346 rn
= (RNID
*) (pcmd
);
4347 rn
->Format
= format
;
4348 rn
->CommonLen
= (2 * sizeof(struct lpfc_name
));
4349 memcpy(&rn
->portName
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
4350 memcpy(&rn
->nodeName
, &vport
->fc_nodename
, sizeof(struct lpfc_name
));
4353 rn
->SpecificLen
= 0;
4355 case RNID_TOPOLOGY_DISC
:
4356 rn
->SpecificLen
= sizeof(RNID_TOP_DISC
);
4357 memcpy(&rn
->un
.topologyDisc
.portName
,
4358 &vport
->fc_portname
, sizeof(struct lpfc_name
));
4359 rn
->un
.topologyDisc
.unitType
= RNID_HBA
;
4360 rn
->un
.topologyDisc
.physPort
= 0;
4361 rn
->un
.topologyDisc
.attachedNodes
= 0;
4365 rn
->SpecificLen
= 0;
4369 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
4370 "Issue ACC RNID: did:x%x flg:x%x",
4371 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
4373 phba
->fc_stat
.elsXmitACC
++;
4374 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
4376 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
4377 if (rc
== IOCB_ERROR
) {
4378 lpfc_els_free_iocb(phba
, elsiocb
);
4385 * lpfc_els_clear_rrq - Clear the rq that this rrq describes.
4386 * @vport: pointer to a virtual N_Port data structure.
4387 * @iocb: pointer to the lpfc command iocb data structure.
4388 * @ndlp: pointer to a node-list data structure.
4393 lpfc_els_clear_rrq(struct lpfc_vport
*vport
,
4394 struct lpfc_iocbq
*iocb
, struct lpfc_nodelist
*ndlp
)
4396 struct lpfc_hba
*phba
= vport
->phba
;
4401 struct lpfc_node_rrq
*prrq
;
4404 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) iocb
->context2
)->virt
);
4405 pcmd
+= sizeof(uint32_t);
4406 rrq
= (struct RRQ
*)pcmd
;
4407 rrq
->rrq_exchg
= be32_to_cpu(rrq
->rrq_exchg
);
4408 rxid
= bf_get(rrq_rxid
, rrq
);
4410 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
4411 "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x"
4413 be32_to_cpu(bf_get(rrq_did
, rrq
)),
4414 bf_get(rrq_oxid
, rrq
),
4416 iocb
->iotag
, iocb
->iocb
.ulpContext
);
4418 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
4419 "Clear RRQ: did:x%x flg:x%x exchg:x%.08x",
4420 ndlp
->nlp_DID
, ndlp
->nlp_flag
, rrq
->rrq_exchg
);
4421 if (vport
->fc_myDID
== be32_to_cpu(bf_get(rrq_did
, rrq
)))
4422 xri
= bf_get(rrq_oxid
, rrq
);
4425 prrq
= lpfc_get_active_rrq(vport
, xri
, ndlp
->nlp_DID
);
4427 lpfc_clr_rrq_active(phba
, xri
, prrq
);
4432 * lpfc_els_rsp_echo_acc - Issue echo acc response
4433 * @vport: pointer to a virtual N_Port data structure.
4434 * @data: pointer to echo data to return in the accept.
4435 * @oldiocb: pointer to the original lpfc command iocb data structure.
4436 * @ndlp: pointer to a node-list data structure.
4439 * 0 - Successfully issued acc echo response
4440 * 1 - Failed to issue acc echo response
4443 lpfc_els_rsp_echo_acc(struct lpfc_vport
*vport
, uint8_t *data
,
4444 struct lpfc_iocbq
*oldiocb
, struct lpfc_nodelist
*ndlp
)
4446 struct lpfc_hba
*phba
= vport
->phba
;
4447 struct lpfc_iocbq
*elsiocb
;
4452 cmdsize
= oldiocb
->iocb
.unsli3
.rcvsli3
.acc_len
;
4454 /* The accumulated length can exceed the BPL_SIZE. For
4455 * now, use this as the limit
4457 if (cmdsize
> LPFC_BPL_SIZE
)
4458 cmdsize
= LPFC_BPL_SIZE
;
4459 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
4460 ndlp
->nlp_DID
, ELS_CMD_ACC
);
4464 elsiocb
->iocb
.ulpContext
= oldiocb
->iocb
.ulpContext
; /* Xri / rx_id */
4465 elsiocb
->iocb
.unsli3
.rcvsli3
.ox_id
= oldiocb
->iocb
.unsli3
.rcvsli3
.ox_id
;
4467 /* Xmit ECHO ACC response tag <ulpIoTag> */
4468 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
4469 "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
4470 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
);
4471 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
4472 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
4473 pcmd
+= sizeof(uint32_t);
4474 memcpy(pcmd
, data
, cmdsize
- sizeof(uint32_t));
4476 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
4477 "Issue ACC ECHO: did:x%x flg:x%x",
4478 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
4480 phba
->fc_stat
.elsXmitACC
++;
4481 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
4483 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
4484 if (rc
== IOCB_ERROR
) {
4485 lpfc_els_free_iocb(phba
, elsiocb
);
4492 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
4493 * @vport: pointer to a host virtual N_Port data structure.
4495 * This routine issues Address Discover (ADISC) ELS commands to those
4496 * N_Ports which are in node port recovery state and ADISC has not been issued
4497 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
4498 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
4499 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
4500 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
4501 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
4502 * IOCBs quit for later pick up. On the other hand, after walking through
4503 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
4504 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
4505 * no more ADISC need to be sent.
4508 * The number of N_Ports with adisc issued.
4511 lpfc_els_disc_adisc(struct lpfc_vport
*vport
)
4513 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4514 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
4517 /* go thru NPR nodes and issue any remaining ELS ADISCs */
4518 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
, nlp_listp
) {
4519 if (!NLP_CHK_NODE_ACT(ndlp
))
4521 if (ndlp
->nlp_state
== NLP_STE_NPR_NODE
&&
4522 (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) != 0 &&
4523 (ndlp
->nlp_flag
& NLP_NPR_ADISC
) != 0) {
4524 spin_lock_irq(shost
->host_lock
);
4525 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
4526 spin_unlock_irq(shost
->host_lock
);
4527 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
4528 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_ADISC_ISSUE
);
4529 lpfc_issue_els_adisc(vport
, ndlp
, 0);
4531 vport
->num_disc_nodes
++;
4532 if (vport
->num_disc_nodes
>=
4533 vport
->cfg_discovery_threads
) {
4534 spin_lock_irq(shost
->host_lock
);
4535 vport
->fc_flag
|= FC_NLP_MORE
;
4536 spin_unlock_irq(shost
->host_lock
);
4541 if (sentadisc
== 0) {
4542 spin_lock_irq(shost
->host_lock
);
4543 vport
->fc_flag
&= ~FC_NLP_MORE
;
4544 spin_unlock_irq(shost
->host_lock
);
4550 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
4551 * @vport: pointer to a host virtual N_Port data structure.
4553 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
4554 * which are in node port recovery state, with a @vport. Each time an ELS
4555 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
4556 * the per @vport number of discover count (num_disc_nodes) shall be
4557 * incremented. If the num_disc_nodes reaches a pre-configured threshold
4558 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
4559 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
4560 * later pick up. On the other hand, after walking through all the ndlps with
4561 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
4562 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
4563 * PLOGI need to be sent.
4566 * The number of N_Ports with plogi issued.
4569 lpfc_els_disc_plogi(struct lpfc_vport
*vport
)
4571 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4572 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
4575 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
4576 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
, nlp_listp
) {
4577 if (!NLP_CHK_NODE_ACT(ndlp
))
4579 if (ndlp
->nlp_state
== NLP_STE_NPR_NODE
&&
4580 (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) != 0 &&
4581 (ndlp
->nlp_flag
& NLP_DELAY_TMO
) == 0 &&
4582 (ndlp
->nlp_flag
& NLP_NPR_ADISC
) == 0) {
4583 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
4584 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
4585 lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0);
4587 vport
->num_disc_nodes
++;
4588 if (vport
->num_disc_nodes
>=
4589 vport
->cfg_discovery_threads
) {
4590 spin_lock_irq(shost
->host_lock
);
4591 vport
->fc_flag
|= FC_NLP_MORE
;
4592 spin_unlock_irq(shost
->host_lock
);
4598 lpfc_set_disctmo(vport
);
4601 spin_lock_irq(shost
->host_lock
);
4602 vport
->fc_flag
&= ~FC_NLP_MORE
;
4603 spin_unlock_irq(shost
->host_lock
);
4609 lpfc_rdp_res_link_service(struct fc_rdp_link_service_desc
*desc
,
4613 desc
->tag
= cpu_to_be32(RDP_LINK_SERVICE_DESC_TAG
);
4614 desc
->payload
.els_req
= word0
;
4615 desc
->length
= cpu_to_be32(sizeof(desc
->payload
));
4619 lpfc_rdp_res_sfp_desc(struct fc_rdp_sfp_desc
*desc
,
4620 uint8_t *page_a0
, uint8_t *page_a2
)
4622 uint16_t wavelength
;
4623 uint16_t temperature
;
4629 struct sff_trasnceiver_codes_byte4
*trasn_code_byte4
;
4630 struct sff_trasnceiver_codes_byte5
*trasn_code_byte5
;
4632 desc
->tag
= cpu_to_be32(RDP_SFP_DESC_TAG
);
4634 trasn_code_byte4
= (struct sff_trasnceiver_codes_byte4
*)
4635 &page_a0
[SSF_TRANSCEIVER_CODE_B4
];
4636 trasn_code_byte5
= (struct sff_trasnceiver_codes_byte5
*)
4637 &page_a0
[SSF_TRANSCEIVER_CODE_B5
];
4639 if ((trasn_code_byte4
->fc_sw_laser
) ||
4640 (trasn_code_byte5
->fc_sw_laser_sl
) ||
4641 (trasn_code_byte5
->fc_sw_laser_sn
)) { /* check if its short WL */
4642 flag
|= (SFP_FLAG_PT_SWLASER
<< SFP_FLAG_PT_SHIFT
);
4643 } else if (trasn_code_byte4
->fc_lw_laser
) {
4644 wavelength
= (page_a0
[SSF_WAVELENGTH_B1
] << 8) |
4645 page_a0
[SSF_WAVELENGTH_B0
];
4646 if (wavelength
== SFP_WAVELENGTH_LC1310
)
4647 flag
|= SFP_FLAG_PT_LWLASER_LC1310
<< SFP_FLAG_PT_SHIFT
;
4648 if (wavelength
== SFP_WAVELENGTH_LL1550
)
4649 flag
|= SFP_FLAG_PT_LWLASER_LL1550
<< SFP_FLAG_PT_SHIFT
;
4651 /* check if its SFP+ */
4652 flag
|= ((page_a0
[SSF_IDENTIFIER
] == SFF_PG0_IDENT_SFP
) ?
4653 SFP_FLAG_CT_SFP_PLUS
: SFP_FLAG_CT_UNKNOWN
)
4654 << SFP_FLAG_CT_SHIFT
;
4656 /* check if its OPTICAL */
4657 flag
|= ((page_a0
[SSF_CONNECTOR
] == SFF_PG0_CONNECTOR_LC
) ?
4658 SFP_FLAG_IS_OPTICAL_PORT
: 0)
4659 << SFP_FLAG_IS_OPTICAL_SHIFT
;
4661 temperature
= (page_a2
[SFF_TEMPERATURE_B1
] << 8 |
4662 page_a2
[SFF_TEMPERATURE_B0
]);
4663 vcc
= (page_a2
[SFF_VCC_B1
] << 8 |
4664 page_a2
[SFF_VCC_B0
]);
4665 tx_power
= (page_a2
[SFF_TXPOWER_B1
] << 8 |
4666 page_a2
[SFF_TXPOWER_B0
]);
4667 tx_bias
= (page_a2
[SFF_TX_BIAS_CURRENT_B1
] << 8 |
4668 page_a2
[SFF_TX_BIAS_CURRENT_B0
]);
4669 rx_power
= (page_a2
[SFF_RXPOWER_B1
] << 8 |
4670 page_a2
[SFF_RXPOWER_B0
]);
4671 desc
->sfp_info
.temperature
= cpu_to_be16(temperature
);
4672 desc
->sfp_info
.rx_power
= cpu_to_be16(rx_power
);
4673 desc
->sfp_info
.tx_bias
= cpu_to_be16(tx_bias
);
4674 desc
->sfp_info
.tx_power
= cpu_to_be16(tx_power
);
4675 desc
->sfp_info
.vcc
= cpu_to_be16(vcc
);
4677 desc
->sfp_info
.flags
= cpu_to_be16(flag
);
4678 desc
->length
= cpu_to_be32(sizeof(desc
->sfp_info
));
4682 lpfc_rdp_res_link_error(struct fc_rdp_link_error_status_desc
*desc
,
4687 desc
->tag
= cpu_to_be32(RDP_LINK_ERROR_STATUS_DESC_TAG
);
4689 type
= VN_PT_PHY_PF_PORT
<< VN_PT_PHY_SHIFT
;
4691 desc
->info
.port_type
= cpu_to_be32(type
);
4693 desc
->info
.link_status
.link_failure_cnt
=
4694 cpu_to_be32(stat
->linkFailureCnt
);
4695 desc
->info
.link_status
.loss_of_synch_cnt
=
4696 cpu_to_be32(stat
->lossSyncCnt
);
4697 desc
->info
.link_status
.loss_of_signal_cnt
=
4698 cpu_to_be32(stat
->lossSignalCnt
);
4699 desc
->info
.link_status
.primitive_seq_proto_err
=
4700 cpu_to_be32(stat
->primSeqErrCnt
);
4701 desc
->info
.link_status
.invalid_trans_word
=
4702 cpu_to_be32(stat
->invalidXmitWord
);
4703 desc
->info
.link_status
.invalid_crc_cnt
= cpu_to_be32(stat
->crcCnt
);
4705 desc
->length
= cpu_to_be32(sizeof(desc
->info
));
4709 lpfc_rdp_res_fec_desc(struct fc_fec_rdp_desc
*desc
, READ_LNK_VAR
*stat
)
4711 if (bf_get(lpfc_read_link_stat_gec2
, stat
) == 0)
4713 desc
->tag
= cpu_to_be32(RDP_FEC_DESC_TAG
);
4715 desc
->info
.CorrectedBlocks
=
4716 cpu_to_be32(stat
->fecCorrBlkCount
);
4717 desc
->info
.UncorrectableBlocks
=
4718 cpu_to_be32(stat
->fecUncorrBlkCount
);
4720 desc
->length
= cpu_to_be32(sizeof(desc
->info
));
4722 return sizeof(struct fc_fec_rdp_desc
);
4726 lpfc_rdp_res_speed(struct fc_rdp_port_speed_desc
*desc
, struct lpfc_hba
*phba
)
4728 uint16_t rdp_cap
= 0;
4731 desc
->tag
= cpu_to_be32(RDP_PORT_SPEED_DESC_TAG
);
4733 switch (phba
->sli4_hba
.link_state
.speed
) {
4734 case LPFC_FC_LA_SPEED_1G
:
4735 rdp_speed
= RDP_PS_1GB
;
4737 case LPFC_FC_LA_SPEED_2G
:
4738 rdp_speed
= RDP_PS_2GB
;
4740 case LPFC_FC_LA_SPEED_4G
:
4741 rdp_speed
= RDP_PS_4GB
;
4743 case LPFC_FC_LA_SPEED_8G
:
4744 rdp_speed
= RDP_PS_8GB
;
4746 case LPFC_FC_LA_SPEED_10G
:
4747 rdp_speed
= RDP_PS_10GB
;
4749 case LPFC_FC_LA_SPEED_16G
:
4750 rdp_speed
= RDP_PS_16GB
;
4752 case LPFC_FC_LA_SPEED_32G
:
4753 rdp_speed
= RDP_PS_32GB
;
4756 rdp_speed
= RDP_PS_UNKNOWN
;
4760 desc
->info
.port_speed
.speed
= cpu_to_be16(rdp_speed
);
4762 if (phba
->lmt
& LMT_32Gb
)
4763 rdp_cap
|= RDP_PS_32GB
;
4764 if (phba
->lmt
& LMT_16Gb
)
4765 rdp_cap
|= RDP_PS_16GB
;
4766 if (phba
->lmt
& LMT_10Gb
)
4767 rdp_cap
|= RDP_PS_10GB
;
4768 if (phba
->lmt
& LMT_8Gb
)
4769 rdp_cap
|= RDP_PS_8GB
;
4770 if (phba
->lmt
& LMT_4Gb
)
4771 rdp_cap
|= RDP_PS_4GB
;
4772 if (phba
->lmt
& LMT_2Gb
)
4773 rdp_cap
|= RDP_PS_2GB
;
4774 if (phba
->lmt
& LMT_1Gb
)
4775 rdp_cap
|= RDP_PS_1GB
;
4778 rdp_cap
= RDP_CAP_UNKNOWN
;
4780 desc
->info
.port_speed
.capabilities
= cpu_to_be16(rdp_cap
);
4781 desc
->length
= cpu_to_be32(sizeof(desc
->info
));
4785 lpfc_rdp_res_diag_port_names(struct fc_rdp_port_name_desc
*desc
,
4786 struct lpfc_hba
*phba
)
4789 desc
->tag
= cpu_to_be32(RDP_PORT_NAMES_DESC_TAG
);
4791 memcpy(desc
->port_names
.wwnn
, phba
->wwnn
,
4792 sizeof(desc
->port_names
.wwnn
));
4794 memcpy(desc
->port_names
.wwpn
, &phba
->wwpn
,
4795 sizeof(desc
->port_names
.wwpn
));
4797 desc
->length
= cpu_to_be32(sizeof(desc
->port_names
));
4801 lpfc_rdp_res_attach_port_names(struct fc_rdp_port_name_desc
*desc
,
4802 struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
4805 desc
->tag
= cpu_to_be32(RDP_PORT_NAMES_DESC_TAG
);
4806 if (vport
->fc_flag
& FC_FABRIC
) {
4807 memcpy(desc
->port_names
.wwnn
, &vport
->fabric_nodename
,
4808 sizeof(desc
->port_names
.wwnn
));
4810 memcpy(desc
->port_names
.wwpn
, &vport
->fabric_portname
,
4811 sizeof(desc
->port_names
.wwpn
));
4812 } else { /* Point to Point */
4813 memcpy(desc
->port_names
.wwnn
, &ndlp
->nlp_nodename
,
4814 sizeof(desc
->port_names
.wwnn
));
4816 memcpy(desc
->port_names
.wwnn
, &ndlp
->nlp_portname
,
4817 sizeof(desc
->port_names
.wwpn
));
4820 desc
->length
= cpu_to_be32(sizeof(desc
->port_names
));
4824 lpfc_els_rdp_cmpl(struct lpfc_hba
*phba
, struct lpfc_rdp_context
*rdp_context
,
4827 struct lpfc_nodelist
*ndlp
= rdp_context
->ndlp
;
4828 struct lpfc_vport
*vport
= ndlp
->vport
;
4829 struct lpfc_iocbq
*elsiocb
;
4832 struct ls_rjt
*stat
;
4833 struct fc_rdp_res_frame
*rdp_res
;
4837 if (status
!= SUCCESS
)
4839 cmdsize
= sizeof(struct fc_rdp_res_frame
);
4841 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
,
4842 lpfc_max_els_tries
, rdp_context
->ndlp
,
4843 rdp_context
->ndlp
->nlp_DID
, ELS_CMD_ACC
);
4846 goto free_rdp_context
;
4848 icmd
= &elsiocb
->iocb
;
4849 icmd
->ulpContext
= rdp_context
->rx_id
;
4850 icmd
->unsli3
.rcvsli3
.ox_id
= rdp_context
->ox_id
;
4852 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
4853 "2171 Xmit RDP response tag x%x xri x%x, "
4854 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x",
4855 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
4856 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
4858 rdp_res
= (struct fc_rdp_res_frame
*)
4859 (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
4860 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
4861 memset(pcmd
, 0, sizeof(struct fc_rdp_res_frame
));
4862 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
4864 /* For RDP payload */
4865 lpfc_rdp_res_link_service(&rdp_res
->link_service_desc
, ELS_CMD_RDP
);
4867 lpfc_rdp_res_sfp_desc(&rdp_res
->sfp_desc
,
4868 rdp_context
->page_a0
, rdp_context
->page_a2
);
4869 lpfc_rdp_res_speed(&rdp_res
->portspeed_desc
, phba
);
4870 lpfc_rdp_res_link_error(&rdp_res
->link_error_desc
,
4871 &rdp_context
->link_stat
);
4872 lpfc_rdp_res_diag_port_names(&rdp_res
->diag_port_names_desc
, phba
);
4873 lpfc_rdp_res_attach_port_names(&rdp_res
->attached_port_names_desc
,
4875 fec_size
= lpfc_rdp_res_fec_desc(&rdp_res
->fec_desc
,
4876 &rdp_context
->link_stat
);
4877 rdp_res
->length
= cpu_to_be32(fec_size
+ RDP_DESC_PAYLOAD_SIZE
);
4878 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
4880 phba
->fc_stat
.elsXmitACC
++;
4881 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
4882 if (rc
== IOCB_ERROR
)
4883 lpfc_els_free_iocb(phba
, elsiocb
);
4889 cmdsize
= 2 * sizeof(uint32_t);
4890 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, lpfc_max_els_tries
,
4891 ndlp
, ndlp
->nlp_DID
, ELS_CMD_LS_RJT
);
4894 goto free_rdp_context
;
4896 icmd
= &elsiocb
->iocb
;
4897 icmd
->ulpContext
= rdp_context
->rx_id
;
4898 icmd
->unsli3
.rcvsli3
.ox_id
= rdp_context
->ox_id
;
4899 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
4901 *((uint32_t *) (pcmd
)) = ELS_CMD_LS_RJT
;
4902 stat
= (struct ls_rjt
*)(pcmd
+ sizeof(uint32_t));
4903 stat
->un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
4905 phba
->fc_stat
.elsXmitLSRJT
++;
4906 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
4907 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
4909 if (rc
== IOCB_ERROR
)
4910 lpfc_els_free_iocb(phba
, elsiocb
);
4916 lpfc_get_rdp_info(struct lpfc_hba
*phba
, struct lpfc_rdp_context
*rdp_context
)
4918 LPFC_MBOXQ_t
*mbox
= NULL
;
4921 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4923 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_ELS
,
4924 "7105 failed to allocate mailbox memory");
4928 if (lpfc_sli4_dump_page_a0(phba
, mbox
))
4929 goto prep_mbox_fail
;
4930 mbox
->vport
= rdp_context
->ndlp
->vport
;
4931 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_rdp_page_a0
;
4932 mbox
->context2
= (struct lpfc_rdp_context
*) rdp_context
;
4933 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
4934 if (rc
== MBX_NOT_FINISHED
)
4935 goto issue_mbox_fail
;
4941 mempool_free(mbox
, phba
->mbox_mem_pool
);
4946 * lpfc_els_rcv_rdp - Process an unsolicited RDP ELS.
4947 * @vport: pointer to a host virtual N_Port data structure.
4948 * @cmdiocb: pointer to lpfc command iocb data structure.
4949 * @ndlp: pointer to a node-list data structure.
4951 * This routine processes an unsolicited RDP(Read Diagnostic Parameters)
4952 * IOCB. First, the payload of the unsolicited RDP is checked.
4953 * Then it will (1) send MBX_DUMP_MEMORY, Embedded DMP_LMSD sub command TYPE-3
4954 * for Page A0, (2) send MBX_DUMP_MEMORY, DMP_LMSD for Page A2,
4955 * (3) send MBX_READ_LNK_STAT to get link stat, (4) Call lpfc_els_rdp_cmpl
4956 * gather all data and send RDP response.
4959 * 0 - Sent the acc response
4960 * 1 - Sent the reject response.
4963 lpfc_els_rcv_rdp(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
4964 struct lpfc_nodelist
*ndlp
)
4966 struct lpfc_hba
*phba
= vport
->phba
;
4967 struct lpfc_dmabuf
*pcmd
;
4968 uint8_t rjt_err
, rjt_expl
= LSEXP_NOTHING_MORE
;
4969 struct fc_rdp_req_frame
*rdp_req
;
4970 struct lpfc_rdp_context
*rdp_context
;
4974 if (phba
->sli_rev
< LPFC_SLI_REV4
||
4975 (bf_get(lpfc_sli_intf_if_type
,
4976 &phba
->sli4_hba
.sli_intf
) !=
4977 LPFC_SLI_INTF_IF_TYPE_2
)) {
4978 rjt_err
= LSRJT_UNABLE_TPC
;
4979 rjt_expl
= LSEXP_REQ_UNSUPPORTED
;
4983 if (phba
->sli_rev
< LPFC_SLI_REV4
|| (phba
->hba_flag
& HBA_FCOE_MODE
)) {
4984 rjt_err
= LSRJT_UNABLE_TPC
;
4985 rjt_expl
= LSEXP_REQ_UNSUPPORTED
;
4989 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
4990 rdp_req
= (struct fc_rdp_req_frame
*) pcmd
->virt
;
4993 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
4994 "2422 ELS RDP Request "
4995 "dec len %d tag x%x port_id %d len %d\n",
4996 be32_to_cpu(rdp_req
->rdp_des_length
),
4997 be32_to_cpu(rdp_req
->nport_id_desc
.tag
),
4998 be32_to_cpu(rdp_req
->nport_id_desc
.nport_id
),
4999 be32_to_cpu(rdp_req
->nport_id_desc
.length
));
5001 if (sizeof(struct fc_rdp_nport_desc
) !=
5002 be32_to_cpu(rdp_req
->rdp_des_length
))
5004 if (RDP_N_PORT_DESC_TAG
!= be32_to_cpu(rdp_req
->nport_id_desc
.tag
))
5006 if (RDP_NPORT_ID_SIZE
!=
5007 be32_to_cpu(rdp_req
->nport_id_desc
.length
))
5009 rdp_context
= kmalloc(sizeof(struct lpfc_rdp_context
), GFP_KERNEL
);
5011 rjt_err
= LSRJT_UNABLE_TPC
;
5015 memset(rdp_context
, 0, sizeof(struct lpfc_rdp_context
));
5016 cmd
= &cmdiocb
->iocb
;
5017 rdp_context
->ndlp
= lpfc_nlp_get(ndlp
);
5018 rdp_context
->ox_id
= cmd
->unsli3
.rcvsli3
.ox_id
;
5019 rdp_context
->rx_id
= cmd
->ulpContext
;
5020 rdp_context
->cmpl
= lpfc_els_rdp_cmpl
;
5021 if (lpfc_get_rdp_info(phba
, rdp_context
)) {
5022 lpfc_printf_vlog(ndlp
->vport
, KERN_WARNING
, LOG_ELS
,
5023 "2423 Unable to send mailbox");
5025 rjt_err
= LSRJT_UNABLE_TPC
;
5033 rjt_err
= LSRJT_LOGICAL_ERR
;
5036 memset(&stat
, 0, sizeof(stat
));
5037 stat
.un
.b
.lsRjtRsnCode
= rjt_err
;
5038 stat
.un
.b
.lsRjtRsnCodeExp
= rjt_expl
;
5039 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
5045 lpfc_els_lcb_rsp(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
5050 struct lpfc_iocbq
*elsiocb
;
5051 struct lpfc_nodelist
*ndlp
;
5052 struct ls_rjt
*stat
;
5053 union lpfc_sli4_cfg_shdr
*shdr
;
5054 struct lpfc_lcb_context
*lcb_context
;
5055 struct fc_lcb_res_frame
*lcb_res
;
5056 uint32_t cmdsize
, shdr_status
, shdr_add_status
;
5060 lcb_context
= (struct lpfc_lcb_context
*)pmb
->context1
;
5061 ndlp
= lcb_context
->ndlp
;
5062 pmb
->context1
= NULL
;
5063 pmb
->context2
= NULL
;
5065 shdr
= (union lpfc_sli4_cfg_shdr
*)
5066 &pmb
->u
.mqe
.un
.beacon_config
.header
.cfg_shdr
;
5067 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
5068 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
5070 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
,
5071 "0194 SET_BEACON_CONFIG mailbox "
5072 "completed with status x%x add_status x%x,"
5073 " mbx status x%x\n",
5074 shdr_status
, shdr_add_status
, mb
->mbxStatus
);
5076 if (mb
->mbxStatus
&& !(shdr_status
&&
5077 shdr_add_status
== ADD_STATUS_OPERATION_ALREADY_ACTIVE
)) {
5078 mempool_free(pmb
, phba
->mbox_mem_pool
);
5082 mempool_free(pmb
, phba
->mbox_mem_pool
);
5083 cmdsize
= sizeof(struct fc_lcb_res_frame
);
5084 elsiocb
= lpfc_prep_els_iocb(phba
->pport
, 0, cmdsize
,
5085 lpfc_max_els_tries
, ndlp
,
5086 ndlp
->nlp_DID
, ELS_CMD_ACC
);
5088 /* Decrement the ndlp reference count from previous mbox command */
5092 goto free_lcb_context
;
5094 lcb_res
= (struct fc_lcb_res_frame
*)
5095 (((struct lpfc_dmabuf
*)elsiocb
->context2
)->virt
);
5097 icmd
= &elsiocb
->iocb
;
5098 icmd
->ulpContext
= lcb_context
->rx_id
;
5099 icmd
->unsli3
.rcvsli3
.ox_id
= lcb_context
->ox_id
;
5101 pcmd
= (uint8_t *)(((struct lpfc_dmabuf
*)elsiocb
->context2
)->virt
);
5102 *((uint32_t *)(pcmd
)) = ELS_CMD_ACC
;
5103 lcb_res
->lcb_sub_command
= lcb_context
->sub_command
;
5104 lcb_res
->lcb_type
= lcb_context
->type
;
5105 lcb_res
->lcb_frequency
= lcb_context
->frequency
;
5106 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
5107 phba
->fc_stat
.elsXmitACC
++;
5108 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
5109 if (rc
== IOCB_ERROR
)
5110 lpfc_els_free_iocb(phba
, elsiocb
);
5116 cmdsize
= sizeof(struct fc_lcb_res_frame
);
5117 elsiocb
= lpfc_prep_els_iocb(phba
->pport
, 0, cmdsize
,
5118 lpfc_max_els_tries
, ndlp
,
5119 ndlp
->nlp_DID
, ELS_CMD_LS_RJT
);
5122 goto free_lcb_context
;
5124 icmd
= &elsiocb
->iocb
;
5125 icmd
->ulpContext
= lcb_context
->rx_id
;
5126 icmd
->unsli3
.rcvsli3
.ox_id
= lcb_context
->ox_id
;
5127 pcmd
= (uint8_t *)(((struct lpfc_dmabuf
*)elsiocb
->context2
)->virt
);
5129 *((uint32_t *)(pcmd
)) = ELS_CMD_LS_RJT
;
5130 stat
= (struct ls_rjt
*)(pcmd
+ sizeof(uint32_t));
5131 stat
->un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
5133 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
5134 phba
->fc_stat
.elsXmitLSRJT
++;
5135 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
5136 if (rc
== IOCB_ERROR
)
5137 lpfc_els_free_iocb(phba
, elsiocb
);
5143 lpfc_sli4_set_beacon(struct lpfc_vport
*vport
,
5144 struct lpfc_lcb_context
*lcb_context
,
5145 uint32_t beacon_state
)
5147 struct lpfc_hba
*phba
= vport
->phba
;
5148 LPFC_MBOXQ_t
*mbox
= NULL
;
5152 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
5156 len
= sizeof(struct lpfc_mbx_set_beacon_config
) -
5157 sizeof(struct lpfc_sli4_cfg_mhdr
);
5158 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
5159 LPFC_MBOX_OPCODE_SET_BEACON_CONFIG
, len
,
5160 LPFC_SLI4_MBX_EMBED
);
5161 mbox
->context1
= (void *)lcb_context
;
5162 mbox
->vport
= phba
->pport
;
5163 mbox
->mbox_cmpl
= lpfc_els_lcb_rsp
;
5164 bf_set(lpfc_mbx_set_beacon_port_num
, &mbox
->u
.mqe
.un
.beacon_config
,
5165 phba
->sli4_hba
.physical_port
);
5166 bf_set(lpfc_mbx_set_beacon_state
, &mbox
->u
.mqe
.un
.beacon_config
,
5168 bf_set(lpfc_mbx_set_beacon_port_type
, &mbox
->u
.mqe
.un
.beacon_config
, 1);
5169 bf_set(lpfc_mbx_set_beacon_duration
, &mbox
->u
.mqe
.un
.beacon_config
, 0);
5170 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
5171 if (rc
== MBX_NOT_FINISHED
) {
5172 mempool_free(mbox
, phba
->mbox_mem_pool
);
5181 * lpfc_els_rcv_lcb - Process an unsolicited LCB
5182 * @vport: pointer to a host virtual N_Port data structure.
5183 * @cmdiocb: pointer to lpfc command iocb data structure.
5184 * @ndlp: pointer to a node-list data structure.
5186 * This routine processes an unsolicited LCB(LINK CABLE BEACON) IOCB.
5187 * First, the payload of the unsolicited LCB is checked.
5188 * Then based on Subcommand beacon will either turn on or off.
5191 * 0 - Sent the acc response
5192 * 1 - Sent the reject response.
5195 lpfc_els_rcv_lcb(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
5196 struct lpfc_nodelist
*ndlp
)
5198 struct lpfc_hba
*phba
= vport
->phba
;
5199 struct lpfc_dmabuf
*pcmd
;
5201 struct fc_lcb_request_frame
*beacon
;
5202 struct lpfc_lcb_context
*lcb_context
;
5203 uint8_t state
, rjt_err
;
5206 pcmd
= (struct lpfc_dmabuf
*)cmdiocb
->context2
;
5207 lp
= (uint8_t *)pcmd
->virt
;
5208 beacon
= (struct fc_lcb_request_frame
*)pcmd
->virt
;
5210 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
5211 "0192 ELS LCB Data x%x x%x x%x x%x sub x%x "
5212 "type x%x frequency %x duration x%x\n",
5213 lp
[0], lp
[1], lp
[2],
5214 beacon
->lcb_command
,
5215 beacon
->lcb_sub_command
,
5217 beacon
->lcb_frequency
,
5218 be16_to_cpu(beacon
->lcb_duration
));
5220 if (phba
->sli_rev
< LPFC_SLI_REV4
||
5221 (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) !=
5222 LPFC_SLI_INTF_IF_TYPE_2
)) {
5223 rjt_err
= LSRJT_CMD_UNSUPPORTED
;
5227 if (phba
->hba_flag
& HBA_FCOE_MODE
) {
5228 rjt_err
= LSRJT_CMD_UNSUPPORTED
;
5231 if (beacon
->lcb_frequency
== 0) {
5232 rjt_err
= LSRJT_CMD_UNSUPPORTED
;
5235 if ((beacon
->lcb_type
!= LPFC_LCB_GREEN
) &&
5236 (beacon
->lcb_type
!= LPFC_LCB_AMBER
)) {
5237 rjt_err
= LSRJT_CMD_UNSUPPORTED
;
5240 if ((beacon
->lcb_sub_command
!= LPFC_LCB_ON
) &&
5241 (beacon
->lcb_sub_command
!= LPFC_LCB_OFF
)) {
5242 rjt_err
= LSRJT_CMD_UNSUPPORTED
;
5245 if ((beacon
->lcb_sub_command
== LPFC_LCB_ON
) &&
5246 (beacon
->lcb_type
!= LPFC_LCB_GREEN
) &&
5247 (beacon
->lcb_type
!= LPFC_LCB_AMBER
)) {
5248 rjt_err
= LSRJT_CMD_UNSUPPORTED
;
5251 if (be16_to_cpu(beacon
->lcb_duration
) != 0) {
5252 rjt_err
= LSRJT_CMD_UNSUPPORTED
;
5256 lcb_context
= kmalloc(sizeof(*lcb_context
), GFP_KERNEL
);
5258 rjt_err
= LSRJT_UNABLE_TPC
;
5262 state
= (beacon
->lcb_sub_command
== LPFC_LCB_ON
) ? 1 : 0;
5263 lcb_context
->sub_command
= beacon
->lcb_sub_command
;
5264 lcb_context
->type
= beacon
->lcb_type
;
5265 lcb_context
->frequency
= beacon
->lcb_frequency
;
5266 lcb_context
->ox_id
= cmdiocb
->iocb
.unsli3
.rcvsli3
.ox_id
;
5267 lcb_context
->rx_id
= cmdiocb
->iocb
.ulpContext
;
5268 lcb_context
->ndlp
= lpfc_nlp_get(ndlp
);
5269 if (lpfc_sli4_set_beacon(vport
, lcb_context
, state
)) {
5270 lpfc_printf_vlog(ndlp
->vport
, KERN_ERR
,
5271 LOG_ELS
, "0193 failed to send mail box");
5274 rjt_err
= LSRJT_UNABLE_TPC
;
5279 memset(&stat
, 0, sizeof(stat
));
5280 stat
.un
.b
.lsRjtRsnCode
= rjt_err
;
5281 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
5287 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
5288 * @vport: pointer to a host virtual N_Port data structure.
5290 * This routine cleans up any Registration State Change Notification
5291 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
5292 * @vport together with the host_lock is used to prevent multiple thread
5293 * trying to access the RSCN array on a same @vport at the same time.
5296 lpfc_els_flush_rscn(struct lpfc_vport
*vport
)
5298 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
5299 struct lpfc_hba
*phba
= vport
->phba
;
5302 spin_lock_irq(shost
->host_lock
);
5303 if (vport
->fc_rscn_flush
) {
5304 /* Another thread is walking fc_rscn_id_list on this vport */
5305 spin_unlock_irq(shost
->host_lock
);
5308 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
5309 vport
->fc_rscn_flush
= 1;
5310 spin_unlock_irq(shost
->host_lock
);
5312 for (i
= 0; i
< vport
->fc_rscn_id_cnt
; i
++) {
5313 lpfc_in_buf_free(phba
, vport
->fc_rscn_id_list
[i
]);
5314 vport
->fc_rscn_id_list
[i
] = NULL
;
5316 spin_lock_irq(shost
->host_lock
);
5317 vport
->fc_rscn_id_cnt
= 0;
5318 vport
->fc_flag
&= ~(FC_RSCN_MODE
| FC_RSCN_DISCOVERY
);
5319 spin_unlock_irq(shost
->host_lock
);
5320 lpfc_can_disctmo(vport
);
5321 /* Indicate we are done walking this fc_rscn_id_list */
5322 vport
->fc_rscn_flush
= 0;
5326 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
5327 * @vport: pointer to a host virtual N_Port data structure.
5328 * @did: remote destination port identifier.
5330 * This routine checks whether there is any pending Registration State
5331 * Configuration Notification (RSCN) to a @did on @vport.
5334 * None zero - The @did matched with a pending rscn
5335 * 0 - not able to match @did with a pending rscn
5338 lpfc_rscn_payload_check(struct lpfc_vport
*vport
, uint32_t did
)
5343 uint32_t payload_len
, i
;
5344 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
5346 ns_did
.un
.word
= did
;
5348 /* Never match fabric nodes for RSCNs */
5349 if ((did
& Fabric_DID_MASK
) == Fabric_DID_MASK
)
5352 /* If we are doing a FULL RSCN rediscovery, match everything */
5353 if (vport
->fc_flag
& FC_RSCN_DISCOVERY
)
5356 spin_lock_irq(shost
->host_lock
);
5357 if (vport
->fc_rscn_flush
) {
5358 /* Another thread is walking fc_rscn_id_list on this vport */
5359 spin_unlock_irq(shost
->host_lock
);
5362 /* Indicate we are walking fc_rscn_id_list on this vport */
5363 vport
->fc_rscn_flush
= 1;
5364 spin_unlock_irq(shost
->host_lock
);
5365 for (i
= 0; i
< vport
->fc_rscn_id_cnt
; i
++) {
5366 lp
= vport
->fc_rscn_id_list
[i
]->virt
;
5367 payload_len
= be32_to_cpu(*lp
++ & ~ELS_CMD_MASK
);
5368 payload_len
-= sizeof(uint32_t); /* take off word 0 */
5369 while (payload_len
) {
5370 rscn_did
.un
.word
= be32_to_cpu(*lp
++);
5371 payload_len
-= sizeof(uint32_t);
5372 switch (rscn_did
.un
.b
.resv
& RSCN_ADDRESS_FORMAT_MASK
) {
5373 case RSCN_ADDRESS_FORMAT_PORT
:
5374 if ((ns_did
.un
.b
.domain
== rscn_did
.un
.b
.domain
)
5375 && (ns_did
.un
.b
.area
== rscn_did
.un
.b
.area
)
5376 && (ns_did
.un
.b
.id
== rscn_did
.un
.b
.id
))
5377 goto return_did_out
;
5379 case RSCN_ADDRESS_FORMAT_AREA
:
5380 if ((ns_did
.un
.b
.domain
== rscn_did
.un
.b
.domain
)
5381 && (ns_did
.un
.b
.area
== rscn_did
.un
.b
.area
))
5382 goto return_did_out
;
5384 case RSCN_ADDRESS_FORMAT_DOMAIN
:
5385 if (ns_did
.un
.b
.domain
== rscn_did
.un
.b
.domain
)
5386 goto return_did_out
;
5388 case RSCN_ADDRESS_FORMAT_FABRIC
:
5389 goto return_did_out
;
5393 /* Indicate we are done with walking fc_rscn_id_list on this vport */
5394 vport
->fc_rscn_flush
= 0;
5397 /* Indicate we are done with walking fc_rscn_id_list on this vport */
5398 vport
->fc_rscn_flush
= 0;
5403 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
5404 * @vport: pointer to a host virtual N_Port data structure.
5406 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
5407 * state machine for a @vport's nodes that are with pending RSCN (Registration
5408 * State Change Notification).
5411 * 0 - Successful (currently alway return 0)
5414 lpfc_rscn_recovery_check(struct lpfc_vport
*vport
)
5416 struct lpfc_nodelist
*ndlp
= NULL
;
5418 /* Move all affected nodes by pending RSCNs to NPR state. */
5419 list_for_each_entry(ndlp
, &vport
->fc_nodes
, nlp_listp
) {
5420 if (!NLP_CHK_NODE_ACT(ndlp
) ||
5421 (ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
) ||
5422 !lpfc_rscn_payload_check(vport
, ndlp
->nlp_DID
))
5424 lpfc_disc_state_machine(vport
, ndlp
, NULL
,
5425 NLP_EVT_DEVICE_RECOVERY
);
5426 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
5432 * lpfc_send_rscn_event - Send an RSCN event to management application
5433 * @vport: pointer to a host virtual N_Port data structure.
5434 * @cmdiocb: pointer to lpfc command iocb data structure.
5436 * lpfc_send_rscn_event sends an RSCN netlink event to management
5440 lpfc_send_rscn_event(struct lpfc_vport
*vport
,
5441 struct lpfc_iocbq
*cmdiocb
)
5443 struct lpfc_dmabuf
*pcmd
;
5444 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
5445 uint32_t *payload_ptr
;
5446 uint32_t payload_len
;
5447 struct lpfc_rscn_event_header
*rscn_event_data
;
5449 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
5450 payload_ptr
= (uint32_t *) pcmd
->virt
;
5451 payload_len
= be32_to_cpu(*payload_ptr
& ~ELS_CMD_MASK
);
5453 rscn_event_data
= kmalloc(sizeof(struct lpfc_rscn_event_header
) +
5454 payload_len
, GFP_KERNEL
);
5455 if (!rscn_event_data
) {
5456 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
5457 "0147 Failed to allocate memory for RSCN event\n");
5460 rscn_event_data
->event_type
= FC_REG_RSCN_EVENT
;
5461 rscn_event_data
->payload_length
= payload_len
;
5462 memcpy(rscn_event_data
->rscn_payload
, payload_ptr
,
5465 fc_host_post_vendor_event(shost
,
5466 fc_get_event_number(),
5467 sizeof(struct lpfc_rscn_event_header
) + payload_len
,
5468 (char *)rscn_event_data
,
5471 kfree(rscn_event_data
);
5475 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
5476 * @vport: pointer to a host virtual N_Port data structure.
5477 * @cmdiocb: pointer to lpfc command iocb data structure.
5478 * @ndlp: pointer to a node-list data structure.
5480 * This routine processes an unsolicited RSCN (Registration State Change
5481 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
5482 * to invoke fc_host_post_event() routine to the FC transport layer. If the
5483 * discover state machine is about to begin discovery, it just accepts the
5484 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
5485 * contains N_Port IDs for other vports on this HBA, it just accepts the
5486 * RSCN and ignore processing it. If the state machine is in the recovery
5487 * state, the fc_rscn_id_list of this @vport is walked and the
5488 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
5489 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
5490 * routine is invoked to handle the RSCN event.
5493 * 0 - Just sent the acc response
5494 * 1 - Sent the acc response and waited for name server completion
5497 lpfc_els_rcv_rscn(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
5498 struct lpfc_nodelist
*ndlp
)
5500 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
5501 struct lpfc_hba
*phba
= vport
->phba
;
5502 struct lpfc_dmabuf
*pcmd
;
5503 uint32_t *lp
, *datap
;
5504 uint32_t payload_len
, length
, nportid
, *cmd
;
5506 int rscn_id
= 0, hba_id
= 0;
5509 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
5510 lp
= (uint32_t *) pcmd
->virt
;
5512 payload_len
= be32_to_cpu(*lp
++ & ~ELS_CMD_MASK
);
5513 payload_len
-= sizeof(uint32_t); /* take off word 0 */
5515 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
5516 "0214 RSCN received Data: x%x x%x x%x x%x\n",
5517 vport
->fc_flag
, payload_len
, *lp
,
5518 vport
->fc_rscn_id_cnt
);
5520 /* Send an RSCN event to the management application */
5521 lpfc_send_rscn_event(vport
, cmdiocb
);
5523 for (i
= 0; i
< payload_len
/sizeof(uint32_t); i
++)
5524 fc_host_post_event(shost
, fc_get_event_number(),
5525 FCH_EVT_RSCN
, lp
[i
]);
5527 /* If we are about to begin discovery, just ACC the RSCN.
5528 * Discovery processing will satisfy it.
5530 if (vport
->port_state
<= LPFC_NS_QRY
) {
5531 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
5532 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
5533 ndlp
->nlp_DID
, vport
->port_state
, ndlp
->nlp_flag
);
5535 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
5539 /* If this RSCN just contains NPortIDs for other vports on this HBA,
5540 * just ACC and ignore it.
5542 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
5543 !(vport
->cfg_peer_port_login
)) {
5548 nportid
= ((be32_to_cpu(nportid
)) & Mask_DID
);
5549 i
-= sizeof(uint32_t);
5551 if (lpfc_find_vport_by_did(phba
, nportid
))
5554 if (rscn_id
== hba_id
) {
5555 /* ALL NPortIDs in RSCN are on HBA */
5556 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
5558 "Data: x%x x%x x%x x%x\n",
5559 vport
->fc_flag
, payload_len
,
5560 *lp
, vport
->fc_rscn_id_cnt
);
5561 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
5562 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
5563 ndlp
->nlp_DID
, vport
->port_state
,
5566 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
,
5572 spin_lock_irq(shost
->host_lock
);
5573 if (vport
->fc_rscn_flush
) {
5574 /* Another thread is walking fc_rscn_id_list on this vport */
5575 vport
->fc_flag
|= FC_RSCN_DISCOVERY
;
5576 spin_unlock_irq(shost
->host_lock
);
5578 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
5581 /* Indicate we are walking fc_rscn_id_list on this vport */
5582 vport
->fc_rscn_flush
= 1;
5583 spin_unlock_irq(shost
->host_lock
);
5584 /* Get the array count after successfully have the token */
5585 rscn_cnt
= vport
->fc_rscn_id_cnt
;
5586 /* If we are already processing an RSCN, save the received
5587 * RSCN payload buffer, cmdiocb->context2 to process later.
5589 if (vport
->fc_flag
& (FC_RSCN_MODE
| FC_NDISC_ACTIVE
)) {
5590 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
5591 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
5592 ndlp
->nlp_DID
, vport
->port_state
, ndlp
->nlp_flag
);
5594 spin_lock_irq(shost
->host_lock
);
5595 vport
->fc_flag
|= FC_RSCN_DEFERRED
;
5596 if ((rscn_cnt
< FC_MAX_HOLD_RSCN
) &&
5597 !(vport
->fc_flag
& FC_RSCN_DISCOVERY
)) {
5598 vport
->fc_flag
|= FC_RSCN_MODE
;
5599 spin_unlock_irq(shost
->host_lock
);
5601 cmd
= vport
->fc_rscn_id_list
[rscn_cnt
-1]->virt
;
5602 length
= be32_to_cpu(*cmd
& ~ELS_CMD_MASK
);
5605 (payload_len
+ length
<= LPFC_BPL_SIZE
)) {
5606 *cmd
&= ELS_CMD_MASK
;
5607 *cmd
|= cpu_to_be32(payload_len
+ length
);
5608 memcpy(((uint8_t *)cmd
) + length
, lp
,
5611 vport
->fc_rscn_id_list
[rscn_cnt
] = pcmd
;
5612 vport
->fc_rscn_id_cnt
++;
5613 /* If we zero, cmdiocb->context2, the calling
5614 * routine will not try to free it.
5616 cmdiocb
->context2
= NULL
;
5619 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
5620 "0235 Deferred RSCN "
5621 "Data: x%x x%x x%x\n",
5622 vport
->fc_rscn_id_cnt
, vport
->fc_flag
,
5625 vport
->fc_flag
|= FC_RSCN_DISCOVERY
;
5626 spin_unlock_irq(shost
->host_lock
);
5627 /* ReDiscovery RSCN */
5628 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
5629 "0234 ReDiscovery RSCN "
5630 "Data: x%x x%x x%x\n",
5631 vport
->fc_rscn_id_cnt
, vport
->fc_flag
,
5634 /* Indicate we are done walking fc_rscn_id_list on this vport */
5635 vport
->fc_rscn_flush
= 0;
5637 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
5638 /* send RECOVERY event for ALL nodes that match RSCN payload */
5639 lpfc_rscn_recovery_check(vport
);
5640 spin_lock_irq(shost
->host_lock
);
5641 vport
->fc_flag
&= ~FC_RSCN_DEFERRED
;
5642 spin_unlock_irq(shost
->host_lock
);
5645 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
5646 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
5647 ndlp
->nlp_DID
, vport
->port_state
, ndlp
->nlp_flag
);
5649 spin_lock_irq(shost
->host_lock
);
5650 vport
->fc_flag
|= FC_RSCN_MODE
;
5651 spin_unlock_irq(shost
->host_lock
);
5652 vport
->fc_rscn_id_list
[vport
->fc_rscn_id_cnt
++] = pcmd
;
5653 /* Indicate we are done walking fc_rscn_id_list on this vport */
5654 vport
->fc_rscn_flush
= 0;
5656 * If we zero, cmdiocb->context2, the calling routine will
5657 * not try to free it.
5659 cmdiocb
->context2
= NULL
;
5660 lpfc_set_disctmo(vport
);
5662 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
5663 /* send RECOVERY event for ALL nodes that match RSCN payload */
5664 lpfc_rscn_recovery_check(vport
);
5665 return lpfc_els_handle_rscn(vport
);
5669 * lpfc_els_handle_rscn - Handle rscn for a vport
5670 * @vport: pointer to a host virtual N_Port data structure.
5672 * This routine handles the Registration State Configuration Notification
5673 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
5674 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
5675 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
5676 * NameServer shall be issued. If CT command to the NameServer fails to be
5677 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
5678 * RSCN activities with the @vport.
5681 * 0 - Cleaned up rscn on the @vport
5682 * 1 - Wait for plogi to name server before proceed
5685 lpfc_els_handle_rscn(struct lpfc_vport
*vport
)
5687 struct lpfc_nodelist
*ndlp
;
5688 struct lpfc_hba
*phba
= vport
->phba
;
5690 /* Ignore RSCN if the port is being torn down. */
5691 if (vport
->load_flag
& FC_UNLOADING
) {
5692 lpfc_els_flush_rscn(vport
);
5696 /* Start timer for RSCN processing */
5697 lpfc_set_disctmo(vport
);
5699 /* RSCN processed */
5700 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
5701 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
5702 vport
->fc_flag
, 0, vport
->fc_rscn_id_cnt
,
5705 /* To process RSCN, first compare RSCN data with NameServer */
5706 vport
->fc_ns_retry
= 0;
5707 vport
->num_disc_nodes
= 0;
5709 ndlp
= lpfc_findnode_did(vport
, NameServer_DID
);
5710 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
)
5711 && ndlp
->nlp_state
== NLP_STE_UNMAPPED_NODE
) {
5712 /* Good ndlp, issue CT Request to NameServer */
5713 if (lpfc_ns_cmd(vport
, SLI_CTNS_GID_FT
, 0, 0) == 0)
5714 /* Wait for NameServer query cmpl before we can
5718 /* If login to NameServer does not exist, issue one */
5719 /* Good status, issue PLOGI to NameServer */
5720 ndlp
= lpfc_findnode_did(vport
, NameServer_DID
);
5721 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
))
5722 /* Wait for NameServer login cmpl before we can
5727 ndlp
= lpfc_enable_node(vport
, ndlp
,
5728 NLP_STE_PLOGI_ISSUE
);
5730 lpfc_els_flush_rscn(vport
);
5733 ndlp
->nlp_prev_state
= NLP_STE_UNUSED_NODE
;
5735 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
5737 lpfc_els_flush_rscn(vport
);
5740 lpfc_nlp_init(vport
, ndlp
, NameServer_DID
);
5741 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
5742 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
5744 ndlp
->nlp_type
|= NLP_FABRIC
;
5745 lpfc_issue_els_plogi(vport
, NameServer_DID
, 0);
5746 /* Wait for NameServer login cmpl before we can
5752 lpfc_els_flush_rscn(vport
);
5757 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
5758 * @vport: pointer to a host virtual N_Port data structure.
5759 * @cmdiocb: pointer to lpfc command iocb data structure.
5760 * @ndlp: pointer to a node-list data structure.
5762 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
5763 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
5764 * point topology. As an unsolicited FLOGI should not be received in a loop
5765 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
5766 * lpfc_check_sparm() routine is invoked to check the parameters in the
5767 * unsolicited FLOGI. If parameters validation failed, the routine
5768 * lpfc_els_rsp_reject() shall be called with reject reason code set to
5769 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
5770 * FLOGI shall be compared with the Port WWN of the @vport to determine who
5771 * will initiate PLOGI. The higher lexicographical value party shall has
5772 * higher priority (as the winning port) and will initiate PLOGI and
5773 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
5774 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
5775 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
5778 * 0 - Successfully processed the unsolicited flogi
5779 * 1 - Failed to process the unsolicited flogi
5782 lpfc_els_rcv_flogi(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
5783 struct lpfc_nodelist
*ndlp
)
5785 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
5786 struct lpfc_hba
*phba
= vport
->phba
;
5787 struct lpfc_dmabuf
*pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
5788 uint32_t *lp
= (uint32_t *) pcmd
->virt
;
5789 IOCB_t
*icmd
= &cmdiocb
->iocb
;
5790 struct serv_parm
*sp
;
5794 uint32_t fc_flag
= 0;
5795 uint32_t port_state
= 0;
5798 sp
= (struct serv_parm
*) lp
;
5800 /* FLOGI received */
5802 lpfc_set_disctmo(vport
);
5804 if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) {
5805 /* We should never receive a FLOGI in loop mode, ignore it */
5806 did
= icmd
->un
.elsreq64
.remoteID
;
5808 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
5810 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
5811 "0113 An FLOGI ELS command x%x was "
5812 "received from DID x%x in Loop Mode\n",
5817 (void) lpfc_check_sparm(vport
, ndlp
, sp
, CLASS3
, 1);
5821 * If our portname is greater than the remote portname,
5822 * then we initiate Nport login.
5825 rc
= memcmp(&vport
->fc_portname
, &sp
->portName
,
5826 sizeof(struct lpfc_name
));
5829 if (phba
->sli_rev
< LPFC_SLI_REV4
) {
5830 mbox
= mempool_alloc(phba
->mbox_mem_pool
,
5834 lpfc_linkdown(phba
);
5835 lpfc_init_link(phba
, mbox
,
5837 phba
->cfg_link_speed
);
5838 mbox
->u
.mb
.un
.varInitLnk
.lipsr_AL_PA
= 0;
5839 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
5840 mbox
->vport
= vport
;
5841 rc
= lpfc_sli_issue_mbox(phba
, mbox
,
5843 lpfc_set_loopback_flag(phba
);
5844 if (rc
== MBX_NOT_FINISHED
)
5845 mempool_free(mbox
, phba
->mbox_mem_pool
);
5849 /* abort the flogi coming back to ourselves
5850 * due to external loopback on the port.
5852 lpfc_els_abort_flogi(phba
);
5855 } else if (rc
> 0) { /* greater than */
5856 spin_lock_irq(shost
->host_lock
);
5857 vport
->fc_flag
|= FC_PT2PT_PLOGI
;
5858 spin_unlock_irq(shost
->host_lock
);
5860 /* If we have the high WWPN we can assign our own
5861 * myDID; otherwise, we have to WAIT for a PLOGI
5862 * from the remote NPort to find out what it
5865 vport
->fc_myDID
= PT2PT_LocalID
;
5867 vport
->fc_myDID
= PT2PT_RemoteID
;
5871 * The vport state should go to LPFC_FLOGI only
5872 * AFTER we issue a FLOGI, not receive one.
5874 spin_lock_irq(shost
->host_lock
);
5875 fc_flag
= vport
->fc_flag
;
5876 port_state
= vport
->port_state
;
5877 vport
->fc_flag
|= FC_PT2PT
;
5878 vport
->fc_flag
&= ~(FC_FABRIC
| FC_PUBLIC_LOOP
);
5879 spin_unlock_irq(shost
->host_lock
);
5880 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
5881 "3311 Rcv Flogi PS x%x new PS x%x "
5882 "fc_flag x%x new fc_flag x%x\n",
5883 port_state
, vport
->port_state
,
5884 fc_flag
, vport
->fc_flag
);
5887 * We temporarily set fc_myDID to make it look like we are
5888 * a Fabric. This is done just so we end up with the right
5889 * did / sid on the FLOGI ACC rsp.
5891 did
= vport
->fc_myDID
;
5892 vport
->fc_myDID
= Fabric_DID
;
5894 memcpy(&phba
->fc_fabparam
, sp
, sizeof(struct serv_parm
));
5897 lpfc_els_rsp_acc(vport
, ELS_CMD_FLOGI
, cmdiocb
, ndlp
, NULL
);
5899 /* Now lets put fc_myDID back to what its supposed to be */
5900 vport
->fc_myDID
= did
;
5906 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
5907 * @vport: pointer to a host virtual N_Port data structure.
5908 * @cmdiocb: pointer to lpfc command iocb data structure.
5909 * @ndlp: pointer to a node-list data structure.
5911 * This routine processes Request Node Identification Data (RNID) IOCB
5912 * received as an ELS unsolicited event. Only when the RNID specified format
5913 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
5914 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
5915 * Accept (ACC) the RNID ELS command. All the other RNID formats are
5916 * rejected by invoking the lpfc_els_rsp_reject() routine.
5919 * 0 - Successfully processed rnid iocb (currently always return 0)
5922 lpfc_els_rcv_rnid(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
5923 struct lpfc_nodelist
*ndlp
)
5925 struct lpfc_dmabuf
*pcmd
;
5931 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
5932 lp
= (uint32_t *) pcmd
->virt
;
5939 switch (rn
->Format
) {
5941 case RNID_TOPOLOGY_DISC
:
5943 lpfc_els_rsp_rnid_acc(vport
, rn
->Format
, cmdiocb
, ndlp
);
5946 /* Reject this request because format not supported */
5947 stat
.un
.b
.lsRjtRsvd0
= 0;
5948 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
5949 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CANT_GIVE_DATA
;
5950 stat
.un
.b
.vendorUnique
= 0;
5951 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
,
5958 * lpfc_els_rcv_echo - Process an unsolicited echo iocb
5959 * @vport: pointer to a host virtual N_Port data structure.
5960 * @cmdiocb: pointer to lpfc command iocb data structure.
5961 * @ndlp: pointer to a node-list data structure.
5964 * 0 - Successfully processed echo iocb (currently always return 0)
5967 lpfc_els_rcv_echo(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
5968 struct lpfc_nodelist
*ndlp
)
5972 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) cmdiocb
->context2
)->virt
);
5974 /* skip over first word of echo command to find echo data */
5975 pcmd
+= sizeof(uint32_t);
5977 lpfc_els_rsp_echo_acc(vport
, pcmd
, cmdiocb
, ndlp
);
5982 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
5983 * @vport: pointer to a host virtual N_Port data structure.
5984 * @cmdiocb: pointer to lpfc command iocb data structure.
5985 * @ndlp: pointer to a node-list data structure.
5987 * This routine processes a Link Incident Report Registration(LIRR) IOCB
5988 * received as an ELS unsolicited event. Currently, this function just invokes
5989 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
5992 * 0 - Successfully processed lirr iocb (currently always return 0)
5995 lpfc_els_rcv_lirr(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
5996 struct lpfc_nodelist
*ndlp
)
6000 /* For now, unconditionally reject this command */
6001 stat
.un
.b
.lsRjtRsvd0
= 0;
6002 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
6003 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CANT_GIVE_DATA
;
6004 stat
.un
.b
.vendorUnique
= 0;
6005 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
6010 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
6011 * @vport: pointer to a host virtual N_Port data structure.
6012 * @cmdiocb: pointer to lpfc command iocb data structure.
6013 * @ndlp: pointer to a node-list data structure.
6015 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
6016 * received as an ELS unsolicited event. A request to RRQ shall only
6017 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
6018 * Nx_Port N_Port_ID of the target Exchange is the same as the
6019 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
6020 * not accepted, an LS_RJT with reason code "Unable to perform
6021 * command request" and reason code explanation "Invalid Originator
6022 * S_ID" shall be returned. For now, we just unconditionally accept
6023 * RRQ from the target.
6026 lpfc_els_rcv_rrq(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
6027 struct lpfc_nodelist
*ndlp
)
6029 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
6030 if (vport
->phba
->sli_rev
== LPFC_SLI_REV4
)
6031 lpfc_els_clear_rrq(vport
, cmdiocb
, ndlp
);
6035 * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
6036 * @phba: pointer to lpfc hba data structure.
6037 * @pmb: pointer to the driver internal queue element for mailbox command.
6039 * This routine is the completion callback function for the MBX_READ_LNK_STAT
6040 * mailbox command. This callback function is to actually send the Accept
6041 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
6042 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
6043 * mailbox command, constructs the RPS response with the link statistics
6044 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
6045 * response to the RPS.
6047 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6048 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6049 * will be stored into the context1 field of the IOCB for the completion
6050 * callback function to the RPS Accept Response ELS IOCB command.
6054 lpfc_els_rsp_rls_acc(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
6058 struct RLS_RSP
*rls_rsp
;
6060 struct lpfc_iocbq
*elsiocb
;
6061 struct lpfc_nodelist
*ndlp
;
6068 ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
6069 rxid
= (uint16_t) ((unsigned long)(pmb
->context1
) & 0xffff);
6070 oxid
= (uint16_t) (((unsigned long)(pmb
->context1
) >> 16) & 0xffff);
6071 pmb
->context1
= NULL
;
6072 pmb
->context2
= NULL
;
6074 if (mb
->mbxStatus
) {
6075 mempool_free(pmb
, phba
->mbox_mem_pool
);
6079 cmdsize
= sizeof(struct RLS_RSP
) + sizeof(uint32_t);
6080 elsiocb
= lpfc_prep_els_iocb(phba
->pport
, 0, cmdsize
,
6081 lpfc_max_els_tries
, ndlp
,
6082 ndlp
->nlp_DID
, ELS_CMD_ACC
);
6084 /* Decrement the ndlp reference count from previous mbox command */
6088 mempool_free(pmb
, phba
->mbox_mem_pool
);
6092 icmd
= &elsiocb
->iocb
;
6093 icmd
->ulpContext
= rxid
;
6094 icmd
->unsli3
.rcvsli3
.ox_id
= oxid
;
6096 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
6097 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
6098 pcmd
+= sizeof(uint32_t); /* Skip past command */
6099 rls_rsp
= (struct RLS_RSP
*)pcmd
;
6101 rls_rsp
->linkFailureCnt
= cpu_to_be32(mb
->un
.varRdLnk
.linkFailureCnt
);
6102 rls_rsp
->lossSyncCnt
= cpu_to_be32(mb
->un
.varRdLnk
.lossSyncCnt
);
6103 rls_rsp
->lossSignalCnt
= cpu_to_be32(mb
->un
.varRdLnk
.lossSignalCnt
);
6104 rls_rsp
->primSeqErrCnt
= cpu_to_be32(mb
->un
.varRdLnk
.primSeqErrCnt
);
6105 rls_rsp
->invalidXmitWord
= cpu_to_be32(mb
->un
.varRdLnk
.invalidXmitWord
);
6106 rls_rsp
->crcCnt
= cpu_to_be32(mb
->un
.varRdLnk
.crcCnt
);
6107 mempool_free(pmb
, phba
->mbox_mem_pool
);
6108 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
6109 lpfc_printf_vlog(ndlp
->vport
, KERN_INFO
, LOG_ELS
,
6110 "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
6111 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
6112 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
6113 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
6115 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
6116 phba
->fc_stat
.elsXmitACC
++;
6117 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) == IOCB_ERROR
)
6118 lpfc_els_free_iocb(phba
, elsiocb
);
6122 * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
6123 * @phba: pointer to lpfc hba data structure.
6124 * @pmb: pointer to the driver internal queue element for mailbox command.
6126 * This routine is the completion callback function for the MBX_READ_LNK_STAT
6127 * mailbox command. This callback function is to actually send the Accept
6128 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
6129 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
6130 * mailbox command, constructs the RPS response with the link statistics
6131 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
6132 * response to the RPS.
6134 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6135 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6136 * will be stored into the context1 field of the IOCB for the completion
6137 * callback function to the RPS Accept Response ELS IOCB command.
6141 lpfc_els_rsp_rps_acc(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
6147 struct lpfc_iocbq
*elsiocb
;
6148 struct lpfc_nodelist
*ndlp
;
6156 ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
6157 rxid
= (uint16_t) ((unsigned long)(pmb
->context1
) & 0xffff);
6158 oxid
= (uint16_t) (((unsigned long)(pmb
->context1
) >> 16) & 0xffff);
6159 pmb
->context1
= NULL
;
6160 pmb
->context2
= NULL
;
6162 if (mb
->mbxStatus
) {
6163 mempool_free(pmb
, phba
->mbox_mem_pool
);
6167 cmdsize
= sizeof(RPS_RSP
) + sizeof(uint32_t);
6168 mempool_free(pmb
, phba
->mbox_mem_pool
);
6169 elsiocb
= lpfc_prep_els_iocb(phba
->pport
, 0, cmdsize
,
6170 lpfc_max_els_tries
, ndlp
,
6171 ndlp
->nlp_DID
, ELS_CMD_ACC
);
6173 /* Decrement the ndlp reference count from previous mbox command */
6179 icmd
= &elsiocb
->iocb
;
6180 icmd
->ulpContext
= rxid
;
6181 icmd
->unsli3
.rcvsli3
.ox_id
= oxid
;
6183 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
6184 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
6185 pcmd
+= sizeof(uint32_t); /* Skip past command */
6186 rps_rsp
= (RPS_RSP
*)pcmd
;
6188 if (phba
->fc_topology
!= LPFC_TOPOLOGY_LOOP
)
6192 if (phba
->pport
->fc_flag
& FC_FABRIC
)
6196 rps_rsp
->portStatus
= cpu_to_be16(status
);
6197 rps_rsp
->linkFailureCnt
= cpu_to_be32(mb
->un
.varRdLnk
.linkFailureCnt
);
6198 rps_rsp
->lossSyncCnt
= cpu_to_be32(mb
->un
.varRdLnk
.lossSyncCnt
);
6199 rps_rsp
->lossSignalCnt
= cpu_to_be32(mb
->un
.varRdLnk
.lossSignalCnt
);
6200 rps_rsp
->primSeqErrCnt
= cpu_to_be32(mb
->un
.varRdLnk
.primSeqErrCnt
);
6201 rps_rsp
->invalidXmitWord
= cpu_to_be32(mb
->un
.varRdLnk
.invalidXmitWord
);
6202 rps_rsp
->crcCnt
= cpu_to_be32(mb
->un
.varRdLnk
.crcCnt
);
6203 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
6204 lpfc_printf_vlog(ndlp
->vport
, KERN_INFO
, LOG_ELS
,
6205 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
6206 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
6207 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
6208 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
6210 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
6211 phba
->fc_stat
.elsXmitACC
++;
6212 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) == IOCB_ERROR
)
6213 lpfc_els_free_iocb(phba
, elsiocb
);
6218 * lpfc_els_rcv_rls - Process an unsolicited rls iocb
6219 * @vport: pointer to a host virtual N_Port data structure.
6220 * @cmdiocb: pointer to lpfc command iocb data structure.
6221 * @ndlp: pointer to a node-list data structure.
6223 * This routine processes Read Port Status (RPL) IOCB received as an
6224 * ELS unsolicited event. It first checks the remote port state. If the
6225 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
6226 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
6227 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
6228 * for reading the HBA link statistics. It is for the callback function,
6229 * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
6230 * to actually sending out RPL Accept (ACC) response.
6233 * 0 - Successfully processed rls iocb (currently always return 0)
6236 lpfc_els_rcv_rls(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
6237 struct lpfc_nodelist
*ndlp
)
6239 struct lpfc_hba
*phba
= vport
->phba
;
6243 if ((ndlp
->nlp_state
!= NLP_STE_UNMAPPED_NODE
) &&
6244 (ndlp
->nlp_state
!= NLP_STE_MAPPED_NODE
))
6245 /* reject the unsolicited RPS request and done with it */
6248 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_ATOMIC
);
6250 lpfc_read_lnk_stat(phba
, mbox
);
6251 mbox
->context1
= (void *)((unsigned long)
6252 ((cmdiocb
->iocb
.unsli3
.rcvsli3
.ox_id
<< 16) |
6253 cmdiocb
->iocb
.ulpContext
)); /* rx_id */
6254 mbox
->context2
= lpfc_nlp_get(ndlp
);
6255 mbox
->vport
= vport
;
6256 mbox
->mbox_cmpl
= lpfc_els_rsp_rls_acc
;
6257 if (lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
)
6258 != MBX_NOT_FINISHED
)
6259 /* Mbox completion will send ELS Response */
6261 /* Decrement reference count used for the failed mbox
6265 mempool_free(mbox
, phba
->mbox_mem_pool
);
6268 /* issue rejection response */
6269 stat
.un
.b
.lsRjtRsvd0
= 0;
6270 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
6271 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CANT_GIVE_DATA
;
6272 stat
.un
.b
.vendorUnique
= 0;
6273 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
6278 * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
6279 * @vport: pointer to a host virtual N_Port data structure.
6280 * @cmdiocb: pointer to lpfc command iocb data structure.
6281 * @ndlp: pointer to a node-list data structure.
6283 * This routine processes Read Timout Value (RTV) IOCB received as an
6284 * ELS unsolicited event. It first checks the remote port state. If the
6285 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
6286 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
6287 * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
6288 * Value (RTV) unsolicited IOCB event.
6290 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6291 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6292 * will be stored into the context1 field of the IOCB for the completion
6293 * callback function to the RPS Accept Response ELS IOCB command.
6296 * 0 - Successfully processed rtv iocb (currently always return 0)
6299 lpfc_els_rcv_rtv(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
6300 struct lpfc_nodelist
*ndlp
)
6302 struct lpfc_hba
*phba
= vport
->phba
;
6304 struct RTV_RSP
*rtv_rsp
;
6306 struct lpfc_iocbq
*elsiocb
;
6310 if ((ndlp
->nlp_state
!= NLP_STE_UNMAPPED_NODE
) &&
6311 (ndlp
->nlp_state
!= NLP_STE_MAPPED_NODE
))
6312 /* reject the unsolicited RPS request and done with it */
6315 cmdsize
= sizeof(struct RTV_RSP
) + sizeof(uint32_t);
6316 elsiocb
= lpfc_prep_els_iocb(phba
->pport
, 0, cmdsize
,
6317 lpfc_max_els_tries
, ndlp
,
6318 ndlp
->nlp_DID
, ELS_CMD_ACC
);
6323 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
6324 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
6325 pcmd
+= sizeof(uint32_t); /* Skip past command */
6327 /* use the command's xri in the response */
6328 elsiocb
->iocb
.ulpContext
= cmdiocb
->iocb
.ulpContext
; /* Xri / rx_id */
6329 elsiocb
->iocb
.unsli3
.rcvsli3
.ox_id
= cmdiocb
->iocb
.unsli3
.rcvsli3
.ox_id
;
6331 rtv_rsp
= (struct RTV_RSP
*)pcmd
;
6333 /* populate RTV payload */
6334 rtv_rsp
->ratov
= cpu_to_be32(phba
->fc_ratov
* 1000); /* report msecs */
6335 rtv_rsp
->edtov
= cpu_to_be32(phba
->fc_edtov
);
6336 bf_set(qtov_edtovres
, rtv_rsp
, phba
->fc_edtovResol
? 1 : 0);
6337 bf_set(qtov_rttov
, rtv_rsp
, 0); /* Field is for FC ONLY */
6338 rtv_rsp
->qtov
= cpu_to_be32(rtv_rsp
->qtov
);
6340 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
6341 lpfc_printf_vlog(ndlp
->vport
, KERN_INFO
, LOG_ELS
,
6342 "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
6343 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
6344 "Data: x%x x%x x%x\n",
6345 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
6346 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
6348 rtv_rsp
->ratov
, rtv_rsp
->edtov
, rtv_rsp
->qtov
);
6349 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
6350 phba
->fc_stat
.elsXmitACC
++;
6351 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) == IOCB_ERROR
)
6352 lpfc_els_free_iocb(phba
, elsiocb
);
6356 /* issue rejection response */
6357 stat
.un
.b
.lsRjtRsvd0
= 0;
6358 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
6359 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CANT_GIVE_DATA
;
6360 stat
.un
.b
.vendorUnique
= 0;
6361 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
6365 /* lpfc_els_rcv_rps - Process an unsolicited rps iocb
6366 * @vport: pointer to a host virtual N_Port data structure.
6367 * @cmdiocb: pointer to lpfc command iocb data structure.
6368 * @ndlp: pointer to a node-list data structure.
6370 * This routine processes Read Port Status (RPS) IOCB received as an
6371 * ELS unsolicited event. It first checks the remote port state. If the
6372 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
6373 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
6374 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
6375 * for reading the HBA link statistics. It is for the callback function,
6376 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
6377 * to actually sending out RPS Accept (ACC) response.
6380 * 0 - Successfully processed rps iocb (currently always return 0)
6383 lpfc_els_rcv_rps(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
6384 struct lpfc_nodelist
*ndlp
)
6386 struct lpfc_hba
*phba
= vport
->phba
;
6390 struct lpfc_dmabuf
*pcmd
;
6394 if ((ndlp
->nlp_state
!= NLP_STE_UNMAPPED_NODE
) &&
6395 (ndlp
->nlp_state
!= NLP_STE_MAPPED_NODE
))
6396 /* reject the unsolicited RPS request and done with it */
6399 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
6400 lp
= (uint32_t *) pcmd
->virt
;
6401 flag
= (be32_to_cpu(*lp
++) & 0xf);
6405 ((flag
== 1) && (be32_to_cpu(rps
->un
.portNum
) == 0)) ||
6406 ((flag
== 2) && (memcmp(&rps
->un
.portName
, &vport
->fc_portname
,
6407 sizeof(struct lpfc_name
)) == 0))) {
6409 printk("Fix me....\n");
6411 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_ATOMIC
);
6413 lpfc_read_lnk_stat(phba
, mbox
);
6414 mbox
->context1
= (void *)((unsigned long)
6415 ((cmdiocb
->iocb
.unsli3
.rcvsli3
.ox_id
<< 16) |
6416 cmdiocb
->iocb
.ulpContext
)); /* rx_id */
6417 mbox
->context2
= lpfc_nlp_get(ndlp
);
6418 mbox
->vport
= vport
;
6419 mbox
->mbox_cmpl
= lpfc_els_rsp_rps_acc
;
6420 if (lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
)
6421 != MBX_NOT_FINISHED
)
6422 /* Mbox completion will send ELS Response */
6424 /* Decrement reference count used for the failed mbox
6428 mempool_free(mbox
, phba
->mbox_mem_pool
);
6433 /* issue rejection response */
6434 stat
.un
.b
.lsRjtRsvd0
= 0;
6435 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
6436 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CANT_GIVE_DATA
;
6437 stat
.un
.b
.vendorUnique
= 0;
6438 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
6442 /* lpfc_issue_els_rrq - Process an unsolicited rps iocb
6443 * @vport: pointer to a host virtual N_Port data structure.
6444 * @ndlp: pointer to a node-list data structure.
6445 * @did: DID of the target.
6446 * @rrq: Pointer to the rrq struct.
6448 * Build a ELS RRQ command and send it to the target. If the issue_iocb is
6449 * Successful the the completion handler will clear the RRQ.
6452 * 0 - Successfully sent rrq els iocb.
6453 * 1 - Failed to send rrq els iocb.
6456 lpfc_issue_els_rrq(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
6457 uint32_t did
, struct lpfc_node_rrq
*rrq
)
6459 struct lpfc_hba
*phba
= vport
->phba
;
6460 struct RRQ
*els_rrq
;
6461 struct lpfc_iocbq
*elsiocb
;
6467 if (ndlp
!= rrq
->ndlp
)
6469 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
))
6472 /* If ndlp is not NULL, we will bump the reference count on it */
6473 cmdsize
= (sizeof(uint32_t) + sizeof(struct RRQ
));
6474 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, 0, ndlp
, did
,
6479 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
6481 /* For RRQ request, remainder of payload is Exchange IDs */
6482 *((uint32_t *) (pcmd
)) = ELS_CMD_RRQ
;
6483 pcmd
+= sizeof(uint32_t);
6484 els_rrq
= (struct RRQ
*) pcmd
;
6486 bf_set(rrq_oxid
, els_rrq
, phba
->sli4_hba
.xri_ids
[rrq
->xritag
]);
6487 bf_set(rrq_rxid
, els_rrq
, rrq
->rxid
);
6488 bf_set(rrq_did
, els_rrq
, vport
->fc_myDID
);
6489 els_rrq
->rrq
= cpu_to_be32(els_rrq
->rrq
);
6490 els_rrq
->rrq_exchg
= cpu_to_be32(els_rrq
->rrq_exchg
);
6493 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
6494 "Issue RRQ: did:x%x",
6495 did
, rrq
->xritag
, rrq
->rxid
);
6496 elsiocb
->context_un
.rrq
= rrq
;
6497 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rrq
;
6498 ret
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
6500 if (ret
== IOCB_ERROR
) {
6501 lpfc_els_free_iocb(phba
, elsiocb
);
6508 * lpfc_send_rrq - Sends ELS RRQ if needed.
6509 * @phba: pointer to lpfc hba data structure.
6510 * @rrq: pointer to the active rrq.
6512 * This routine will call the lpfc_issue_els_rrq if the rrq is
6513 * still active for the xri. If this function returns a failure then
6514 * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq.
6516 * Returns 0 Success.
6520 lpfc_send_rrq(struct lpfc_hba
*phba
, struct lpfc_node_rrq
*rrq
)
6522 struct lpfc_nodelist
*ndlp
= lpfc_findnode_did(rrq
->vport
,
6524 if (lpfc_test_rrq_active(phba
, ndlp
, rrq
->xritag
))
6525 return lpfc_issue_els_rrq(rrq
->vport
, ndlp
,
6532 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
6533 * @vport: pointer to a host virtual N_Port data structure.
6534 * @cmdsize: size of the ELS command.
6535 * @oldiocb: pointer to the original lpfc command iocb data structure.
6536 * @ndlp: pointer to a node-list data structure.
6538 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
6539 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
6541 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6542 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6543 * will be stored into the context1 field of the IOCB for the completion
6544 * callback function to the RPL Accept Response ELS command.
6547 * 0 - Successfully issued ACC RPL ELS command
6548 * 1 - Failed to issue ACC RPL ELS command
6551 lpfc_els_rsp_rpl_acc(struct lpfc_vport
*vport
, uint16_t cmdsize
,
6552 struct lpfc_iocbq
*oldiocb
, struct lpfc_nodelist
*ndlp
)
6554 struct lpfc_hba
*phba
= vport
->phba
;
6555 IOCB_t
*icmd
, *oldcmd
;
6557 struct lpfc_iocbq
*elsiocb
;
6560 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
6561 ndlp
->nlp_DID
, ELS_CMD_ACC
);
6566 icmd
= &elsiocb
->iocb
;
6567 oldcmd
= &oldiocb
->iocb
;
6568 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri / rx_id */
6569 icmd
->unsli3
.rcvsli3
.ox_id
= oldcmd
->unsli3
.rcvsli3
.ox_id
;
6571 pcmd
= (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
6572 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
6573 pcmd
+= sizeof(uint16_t);
6574 *((uint16_t *)(pcmd
)) = be16_to_cpu(cmdsize
);
6575 pcmd
+= sizeof(uint16_t);
6577 /* Setup the RPL ACC payload */
6578 rpl_rsp
.listLen
= be32_to_cpu(1);
6580 rpl_rsp
.port_num_blk
.portNum
= 0;
6581 rpl_rsp
.port_num_blk
.portID
= be32_to_cpu(vport
->fc_myDID
);
6582 memcpy(&rpl_rsp
.port_num_blk
.portName
, &vport
->fc_portname
,
6583 sizeof(struct lpfc_name
));
6584 memcpy(pcmd
, &rpl_rsp
, cmdsize
- sizeof(uint32_t));
6585 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
6586 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
6587 "0120 Xmit ELS RPL ACC response tag x%x "
6588 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
6590 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
6591 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
6593 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
6594 phba
->fc_stat
.elsXmitACC
++;
6595 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) ==
6597 lpfc_els_free_iocb(phba
, elsiocb
);
6604 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
6605 * @vport: pointer to a host virtual N_Port data structure.
6606 * @cmdiocb: pointer to lpfc command iocb data structure.
6607 * @ndlp: pointer to a node-list data structure.
6609 * This routine processes Read Port List (RPL) IOCB received as an ELS
6610 * unsolicited event. It first checks the remote port state. If the remote
6611 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
6612 * invokes the lpfc_els_rsp_reject() routine to send reject response.
6613 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
6614 * to accept the RPL.
6617 * 0 - Successfully processed rpl iocb (currently always return 0)
6620 lpfc_els_rcv_rpl(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
6621 struct lpfc_nodelist
*ndlp
)
6623 struct lpfc_dmabuf
*pcmd
;
6630 if ((ndlp
->nlp_state
!= NLP_STE_UNMAPPED_NODE
) &&
6631 (ndlp
->nlp_state
!= NLP_STE_MAPPED_NODE
)) {
6632 /* issue rejection response */
6633 stat
.un
.b
.lsRjtRsvd0
= 0;
6634 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
6635 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CANT_GIVE_DATA
;
6636 stat
.un
.b
.vendorUnique
= 0;
6637 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
,
6639 /* rejected the unsolicited RPL request and done with it */
6643 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
6644 lp
= (uint32_t *) pcmd
->virt
;
6645 rpl
= (RPL
*) (lp
+ 1);
6646 maxsize
= be32_to_cpu(rpl
->maxsize
);
6648 /* We support only one port */
6649 if ((rpl
->index
== 0) &&
6651 ((maxsize
* sizeof(uint32_t)) >= sizeof(RPL_RSP
)))) {
6652 cmdsize
= sizeof(uint32_t) + sizeof(RPL_RSP
);
6654 cmdsize
= sizeof(uint32_t) + maxsize
* sizeof(uint32_t);
6656 lpfc_els_rsp_rpl_acc(vport
, cmdsize
, cmdiocb
, ndlp
);
6662 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
6663 * @vport: pointer to a virtual N_Port data structure.
6664 * @cmdiocb: pointer to lpfc command iocb data structure.
6665 * @ndlp: pointer to a node-list data structure.
6667 * This routine processes Fibre Channel Address Resolution Protocol
6668 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
6669 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
6670 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
6671 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
6672 * remote PortName is compared against the FC PortName stored in the @vport
6673 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
6674 * compared against the FC NodeName stored in the @vport data structure.
6675 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
6676 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
6677 * invoked to send out FARP Response to the remote node. Before sending the
6678 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
6679 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
6680 * routine is invoked to log into the remote port first.
6683 * 0 - Either the FARP Match Mode not supported or successfully processed
6686 lpfc_els_rcv_farp(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
6687 struct lpfc_nodelist
*ndlp
)
6689 struct lpfc_dmabuf
*pcmd
;
6693 uint32_t cmd
, cnt
, did
;
6695 icmd
= &cmdiocb
->iocb
;
6696 did
= icmd
->un
.elsreq64
.remoteID
;
6697 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
6698 lp
= (uint32_t *) pcmd
->virt
;
6702 /* FARP-REQ received from DID <did> */
6703 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
6704 "0601 FARP-REQ received from DID x%x\n", did
);
6705 /* We will only support match on WWPN or WWNN */
6706 if (fp
->Mflags
& ~(FARP_MATCH_NODE
| FARP_MATCH_PORT
)) {
6711 /* If this FARP command is searching for my portname */
6712 if (fp
->Mflags
& FARP_MATCH_PORT
) {
6713 if (memcmp(&fp
->RportName
, &vport
->fc_portname
,
6714 sizeof(struct lpfc_name
)) == 0)
6718 /* If this FARP command is searching for my nodename */
6719 if (fp
->Mflags
& FARP_MATCH_NODE
) {
6720 if (memcmp(&fp
->RnodeName
, &vport
->fc_nodename
,
6721 sizeof(struct lpfc_name
)) == 0)
6726 if ((ndlp
->nlp_state
== NLP_STE_UNMAPPED_NODE
) ||
6727 (ndlp
->nlp_state
== NLP_STE_MAPPED_NODE
)) {
6728 /* Log back into the node before sending the FARP. */
6729 if (fp
->Rflags
& FARP_REQUEST_PLOGI
) {
6730 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
6731 lpfc_nlp_set_state(vport
, ndlp
,
6732 NLP_STE_PLOGI_ISSUE
);
6733 lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0);
6736 /* Send a FARP response to that node */
6737 if (fp
->Rflags
& FARP_REQUEST_FARPR
)
6738 lpfc_issue_els_farpr(vport
, did
, 0);
6745 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
6746 * @vport: pointer to a host virtual N_Port data structure.
6747 * @cmdiocb: pointer to lpfc command iocb data structure.
6748 * @ndlp: pointer to a node-list data structure.
6750 * This routine processes Fibre Channel Address Resolution Protocol
6751 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
6752 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
6753 * the FARP response request.
6756 * 0 - Successfully processed FARPR IOCB (currently always return 0)
6759 lpfc_els_rcv_farpr(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
6760 struct lpfc_nodelist
*ndlp
)
6762 struct lpfc_dmabuf
*pcmd
;
6767 icmd
= &cmdiocb
->iocb
;
6768 did
= icmd
->un
.elsreq64
.remoteID
;
6769 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
6770 lp
= (uint32_t *) pcmd
->virt
;
6773 /* FARP-RSP received from DID <did> */
6774 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
6775 "0600 FARP-RSP received from DID x%x\n", did
);
6776 /* ACCEPT the Farp resp request */
6777 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
6783 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
6784 * @vport: pointer to a host virtual N_Port data structure.
6785 * @cmdiocb: pointer to lpfc command iocb data structure.
6786 * @fan_ndlp: pointer to a node-list data structure.
6788 * This routine processes a Fabric Address Notification (FAN) IOCB
6789 * command received as an ELS unsolicited event. The FAN ELS command will
6790 * only be processed on a physical port (i.e., the @vport represents the
6791 * physical port). The fabric NodeName and PortName from the FAN IOCB are
6792 * compared against those in the phba data structure. If any of those is
6793 * different, the lpfc_initial_flogi() routine is invoked to initialize
6794 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
6795 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
6796 * is invoked to register login to the fabric.
6799 * 0 - Successfully processed fan iocb (currently always return 0).
6802 lpfc_els_rcv_fan(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
6803 struct lpfc_nodelist
*fan_ndlp
)
6805 struct lpfc_hba
*phba
= vport
->phba
;
6809 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
, "0265 FAN received\n");
6810 lp
= (uint32_t *)((struct lpfc_dmabuf
*)cmdiocb
->context2
)->virt
;
6812 /* FAN received; Fan does not have a reply sequence */
6813 if ((vport
== phba
->pport
) &&
6814 (vport
->port_state
== LPFC_LOCAL_CFG_LINK
)) {
6815 if ((memcmp(&phba
->fc_fabparam
.nodeName
, &fp
->FnodeName
,
6816 sizeof(struct lpfc_name
))) ||
6817 (memcmp(&phba
->fc_fabparam
.portName
, &fp
->FportName
,
6818 sizeof(struct lpfc_name
)))) {
6819 /* This port has switched fabrics. FLOGI is required */
6820 lpfc_issue_init_vfi(vport
);
6822 /* FAN verified - skip FLOGI */
6823 vport
->fc_myDID
= vport
->fc_prevDID
;
6824 if (phba
->sli_rev
< LPFC_SLI_REV4
)
6825 lpfc_issue_fabric_reglogin(vport
);
6827 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
6828 "3138 Need register VFI: (x%x/%x)\n",
6829 vport
->fc_prevDID
, vport
->fc_myDID
);
6830 lpfc_issue_reg_vfi(vport
);
6838 * lpfc_els_timeout - Handler funciton to the els timer
6839 * @ptr: holder for the timer function associated data.
6841 * This routine is invoked by the ELS timer after timeout. It posts the ELS
6842 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
6843 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
6844 * up the worker thread. It is for the worker thread to invoke the routine
6845 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
6848 lpfc_els_timeout(unsigned long ptr
)
6850 struct lpfc_vport
*vport
= (struct lpfc_vport
*) ptr
;
6851 struct lpfc_hba
*phba
= vport
->phba
;
6852 uint32_t tmo_posted
;
6853 unsigned long iflag
;
6855 spin_lock_irqsave(&vport
->work_port_lock
, iflag
);
6856 tmo_posted
= vport
->work_port_events
& WORKER_ELS_TMO
;
6857 if ((!tmo_posted
) && (!(vport
->load_flag
& FC_UNLOADING
)))
6858 vport
->work_port_events
|= WORKER_ELS_TMO
;
6859 spin_unlock_irqrestore(&vport
->work_port_lock
, iflag
);
6861 if ((!tmo_posted
) && (!(vport
->load_flag
& FC_UNLOADING
)))
6862 lpfc_worker_wake_up(phba
);
6868 * lpfc_els_timeout_handler - Process an els timeout event
6869 * @vport: pointer to a virtual N_Port data structure.
6871 * This routine is the actual handler function that processes an ELS timeout
6872 * event. It walks the ELS ring to get and abort all the IOCBs (except the
6873 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
6874 * invoking the lpfc_sli_issue_abort_iotag() routine.
6877 lpfc_els_timeout_handler(struct lpfc_vport
*vport
)
6879 struct lpfc_hba
*phba
= vport
->phba
;
6880 struct lpfc_sli_ring
*pring
;
6881 struct lpfc_iocbq
*tmp_iocb
, *piocb
;
6883 struct lpfc_dmabuf
*pcmd
;
6884 uint32_t els_command
= 0;
6886 uint32_t remote_ID
= 0xffffffff;
6887 LIST_HEAD(abort_list
);
6890 timeout
= (uint32_t)(phba
->fc_ratov
<< 1);
6892 pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
6893 if ((phba
->pport
->load_flag
& FC_UNLOADING
))
6895 spin_lock_irq(&phba
->hbalock
);
6896 if (phba
->sli_rev
== LPFC_SLI_REV4
)
6897 spin_lock(&pring
->ring_lock
);
6899 if ((phba
->pport
->load_flag
& FC_UNLOADING
)) {
6900 if (phba
->sli_rev
== LPFC_SLI_REV4
)
6901 spin_unlock(&pring
->ring_lock
);
6902 spin_unlock_irq(&phba
->hbalock
);
6906 list_for_each_entry_safe(piocb
, tmp_iocb
, &pring
->txcmplq
, list
) {
6909 if ((piocb
->iocb_flag
& LPFC_IO_LIBDFC
) != 0 ||
6910 piocb
->iocb
.ulpCommand
== CMD_ABORT_XRI_CN
||
6911 piocb
->iocb
.ulpCommand
== CMD_CLOSE_XRI_CN
)
6914 if (piocb
->vport
!= vport
)
6917 pcmd
= (struct lpfc_dmabuf
*) piocb
->context2
;
6919 els_command
= *(uint32_t *) (pcmd
->virt
);
6921 if (els_command
== ELS_CMD_FARP
||
6922 els_command
== ELS_CMD_FARPR
||
6923 els_command
== ELS_CMD_FDISC
)
6926 if (piocb
->drvrTimeout
> 0) {
6927 if (piocb
->drvrTimeout
>= timeout
)
6928 piocb
->drvrTimeout
-= timeout
;
6930 piocb
->drvrTimeout
= 0;
6934 remote_ID
= 0xffffffff;
6935 if (cmd
->ulpCommand
!= CMD_GEN_REQUEST64_CR
)
6936 remote_ID
= cmd
->un
.elsreq64
.remoteID
;
6938 struct lpfc_nodelist
*ndlp
;
6939 ndlp
= __lpfc_findnode_rpi(vport
, cmd
->ulpContext
);
6940 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
))
6941 remote_ID
= ndlp
->nlp_DID
;
6943 list_add_tail(&piocb
->dlist
, &abort_list
);
6945 if (phba
->sli_rev
== LPFC_SLI_REV4
)
6946 spin_unlock(&pring
->ring_lock
);
6947 spin_unlock_irq(&phba
->hbalock
);
6949 list_for_each_entry_safe(piocb
, tmp_iocb
, &abort_list
, dlist
) {
6951 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
6952 "0127 ELS timeout Data: x%x x%x x%x "
6953 "x%x\n", els_command
,
6954 remote_ID
, cmd
->ulpCommand
, cmd
->ulpIoTag
);
6955 spin_lock_irq(&phba
->hbalock
);
6956 list_del_init(&piocb
->dlist
);
6957 lpfc_sli_issue_abort_iotag(phba
, pring
, piocb
);
6958 spin_unlock_irq(&phba
->hbalock
);
6961 if (!list_empty(&phba
->sli
.ring
[LPFC_ELS_RING
].txcmplq
))
6962 if (!(phba
->pport
->load_flag
& FC_UNLOADING
))
6963 mod_timer(&vport
->els_tmofunc
,
6964 jiffies
+ msecs_to_jiffies(1000 * timeout
));
6968 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
6969 * @vport: pointer to a host virtual N_Port data structure.
6971 * This routine is used to clean up all the outstanding ELS commands on a
6972 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
6973 * routine. After that, it walks the ELS transmit queue to remove all the
6974 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
6975 * the IOCBs with a non-NULL completion callback function, the callback
6976 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
6977 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
6978 * callback function, the IOCB will simply be released. Finally, it walks
6979 * the ELS transmit completion queue to issue an abort IOCB to any transmit
6980 * completion queue IOCB that is associated with the @vport and is not
6981 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
6982 * part of the discovery state machine) out to HBA by invoking the
6983 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
6984 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
6985 * the IOCBs are aborted when this function returns.
6988 lpfc_els_flush_cmd(struct lpfc_vport
*vport
)
6990 LIST_HEAD(abort_list
);
6991 struct lpfc_hba
*phba
= vport
->phba
;
6992 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
6993 struct lpfc_iocbq
*tmp_iocb
, *piocb
;
6996 lpfc_fabric_abort_vport(vport
);
6998 * For SLI3, only the hbalock is required. But SLI4 needs to coordinate
6999 * with the ring insert operation. Because lpfc_sli_issue_abort_iotag
7000 * ultimately grabs the ring_lock, the driver must splice the list into
7001 * a working list and release the locks before calling the abort.
7003 spin_lock_irq(&phba
->hbalock
);
7004 if (phba
->sli_rev
== LPFC_SLI_REV4
)
7005 spin_lock(&pring
->ring_lock
);
7007 list_for_each_entry_safe(piocb
, tmp_iocb
, &pring
->txcmplq
, list
) {
7008 if (piocb
->iocb_flag
& LPFC_IO_LIBDFC
)
7011 if (piocb
->vport
!= vport
)
7013 list_add_tail(&piocb
->dlist
, &abort_list
);
7015 if (phba
->sli_rev
== LPFC_SLI_REV4
)
7016 spin_unlock(&pring
->ring_lock
);
7017 spin_unlock_irq(&phba
->hbalock
);
7018 /* Abort each iocb on the aborted list and remove the dlist links. */
7019 list_for_each_entry_safe(piocb
, tmp_iocb
, &abort_list
, dlist
) {
7020 spin_lock_irq(&phba
->hbalock
);
7021 list_del_init(&piocb
->dlist
);
7022 lpfc_sli_issue_abort_iotag(phba
, pring
, piocb
);
7023 spin_unlock_irq(&phba
->hbalock
);
7025 if (!list_empty(&abort_list
))
7026 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
7027 "3387 abort list for txq not empty\n");
7028 INIT_LIST_HEAD(&abort_list
);
7030 spin_lock_irq(&phba
->hbalock
);
7031 if (phba
->sli_rev
== LPFC_SLI_REV4
)
7032 spin_lock(&pring
->ring_lock
);
7034 list_for_each_entry_safe(piocb
, tmp_iocb
, &pring
->txq
, list
) {
7037 if (piocb
->iocb_flag
& LPFC_IO_LIBDFC
) {
7041 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
7042 if (cmd
->ulpCommand
== CMD_QUE_RING_BUF_CN
||
7043 cmd
->ulpCommand
== CMD_QUE_RING_BUF64_CN
||
7044 cmd
->ulpCommand
== CMD_CLOSE_XRI_CN
||
7045 cmd
->ulpCommand
== CMD_ABORT_XRI_CN
)
7048 if (piocb
->vport
!= vport
)
7051 list_del_init(&piocb
->list
);
7052 list_add_tail(&piocb
->list
, &abort_list
);
7054 if (phba
->sli_rev
== LPFC_SLI_REV4
)
7055 spin_unlock(&pring
->ring_lock
);
7056 spin_unlock_irq(&phba
->hbalock
);
7058 /* Cancell all the IOCBs from the completions list */
7059 lpfc_sli_cancel_iocbs(phba
, &abort_list
,
7060 IOSTAT_LOCAL_REJECT
, IOERR_SLI_ABORTED
);
7066 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
7067 * @phba: pointer to lpfc hba data structure.
7069 * This routine is used to clean up all the outstanding ELS commands on a
7070 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
7071 * routine. After that, it walks the ELS transmit queue to remove all the
7072 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
7073 * the IOCBs with the completion callback function associated, the callback
7074 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
7075 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
7076 * callback function associated, the IOCB will simply be released. Finally,
7077 * it walks the ELS transmit completion queue to issue an abort IOCB to any
7078 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
7079 * management plane IOCBs that are not part of the discovery state machine)
7080 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
7083 lpfc_els_flush_all_cmd(struct lpfc_hba
*phba
)
7085 struct lpfc_vport
*vport
;
7086 list_for_each_entry(vport
, &phba
->port_list
, listentry
)
7087 lpfc_els_flush_cmd(vport
);
7093 * lpfc_send_els_failure_event - Posts an ELS command failure event
7094 * @phba: Pointer to hba context object.
7095 * @cmdiocbp: Pointer to command iocb which reported error.
7096 * @rspiocbp: Pointer to response iocb which reported error.
7098 * This function sends an event when there is an ELS command
7102 lpfc_send_els_failure_event(struct lpfc_hba
*phba
,
7103 struct lpfc_iocbq
*cmdiocbp
,
7104 struct lpfc_iocbq
*rspiocbp
)
7106 struct lpfc_vport
*vport
= cmdiocbp
->vport
;
7107 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
7108 struct lpfc_lsrjt_event lsrjt_event
;
7109 struct lpfc_fabric_event_header fabric_event
;
7111 struct lpfc_nodelist
*ndlp
;
7114 ndlp
= cmdiocbp
->context1
;
7115 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
))
7118 if (rspiocbp
->iocb
.ulpStatus
== IOSTAT_LS_RJT
) {
7119 lsrjt_event
.header
.event_type
= FC_REG_ELS_EVENT
;
7120 lsrjt_event
.header
.subcategory
= LPFC_EVENT_LSRJT_RCV
;
7121 memcpy(lsrjt_event
.header
.wwpn
, &ndlp
->nlp_portname
,
7122 sizeof(struct lpfc_name
));
7123 memcpy(lsrjt_event
.header
.wwnn
, &ndlp
->nlp_nodename
,
7124 sizeof(struct lpfc_name
));
7125 pcmd
= (uint32_t *) (((struct lpfc_dmabuf
*)
7126 cmdiocbp
->context2
)->virt
);
7127 lsrjt_event
.command
= (pcmd
!= NULL
) ? *pcmd
: 0;
7128 stat
.un
.lsRjtError
= be32_to_cpu(rspiocbp
->iocb
.un
.ulpWord
[4]);
7129 lsrjt_event
.reason_code
= stat
.un
.b
.lsRjtRsnCode
;
7130 lsrjt_event
.explanation
= stat
.un
.b
.lsRjtRsnCodeExp
;
7131 fc_host_post_vendor_event(shost
,
7132 fc_get_event_number(),
7133 sizeof(lsrjt_event
),
7134 (char *)&lsrjt_event
,
7138 if ((rspiocbp
->iocb
.ulpStatus
== IOSTAT_NPORT_BSY
) ||
7139 (rspiocbp
->iocb
.ulpStatus
== IOSTAT_FABRIC_BSY
)) {
7140 fabric_event
.event_type
= FC_REG_FABRIC_EVENT
;
7141 if (rspiocbp
->iocb
.ulpStatus
== IOSTAT_NPORT_BSY
)
7142 fabric_event
.subcategory
= LPFC_EVENT_PORT_BUSY
;
7144 fabric_event
.subcategory
= LPFC_EVENT_FABRIC_BUSY
;
7145 memcpy(fabric_event
.wwpn
, &ndlp
->nlp_portname
,
7146 sizeof(struct lpfc_name
));
7147 memcpy(fabric_event
.wwnn
, &ndlp
->nlp_nodename
,
7148 sizeof(struct lpfc_name
));
7149 fc_host_post_vendor_event(shost
,
7150 fc_get_event_number(),
7151 sizeof(fabric_event
),
7152 (char *)&fabric_event
,
7160 * lpfc_send_els_event - Posts unsolicited els event
7161 * @vport: Pointer to vport object.
7162 * @ndlp: Pointer FC node object.
7163 * @cmd: ELS command code.
7165 * This function posts an event when there is an incoming
7166 * unsolicited ELS command.
7169 lpfc_send_els_event(struct lpfc_vport
*vport
,
7170 struct lpfc_nodelist
*ndlp
,
7173 struct lpfc_els_event_header
*els_data
= NULL
;
7174 struct lpfc_logo_event
*logo_data
= NULL
;
7175 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
7177 if (*payload
== ELS_CMD_LOGO
) {
7178 logo_data
= kmalloc(sizeof(struct lpfc_logo_event
), GFP_KERNEL
);
7180 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
7181 "0148 Failed to allocate memory "
7182 "for LOGO event\n");
7185 els_data
= &logo_data
->header
;
7187 els_data
= kmalloc(sizeof(struct lpfc_els_event_header
),
7190 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
7191 "0149 Failed to allocate memory "
7196 els_data
->event_type
= FC_REG_ELS_EVENT
;
7199 els_data
->subcategory
= LPFC_EVENT_PLOGI_RCV
;
7202 els_data
->subcategory
= LPFC_EVENT_PRLO_RCV
;
7205 els_data
->subcategory
= LPFC_EVENT_ADISC_RCV
;
7208 els_data
->subcategory
= LPFC_EVENT_LOGO_RCV
;
7209 /* Copy the WWPN in the LOGO payload */
7210 memcpy(logo_data
->logo_wwpn
, &payload
[2],
7211 sizeof(struct lpfc_name
));
7217 memcpy(els_data
->wwpn
, &ndlp
->nlp_portname
, sizeof(struct lpfc_name
));
7218 memcpy(els_data
->wwnn
, &ndlp
->nlp_nodename
, sizeof(struct lpfc_name
));
7219 if (*payload
== ELS_CMD_LOGO
) {
7220 fc_host_post_vendor_event(shost
,
7221 fc_get_event_number(),
7222 sizeof(struct lpfc_logo_event
),
7227 fc_host_post_vendor_event(shost
,
7228 fc_get_event_number(),
7229 sizeof(struct lpfc_els_event_header
),
7240 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
7241 * @phba: pointer to lpfc hba data structure.
7242 * @pring: pointer to a SLI ring.
7243 * @vport: pointer to a host virtual N_Port data structure.
7244 * @elsiocb: pointer to lpfc els command iocb data structure.
7246 * This routine is used for processing the IOCB associated with a unsolicited
7247 * event. It first determines whether there is an existing ndlp that matches
7248 * the DID from the unsolicited IOCB. If not, it will create a new one with
7249 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
7250 * IOCB is then used to invoke the proper routine and to set up proper state
7251 * of the discovery state machine.
7254 lpfc_els_unsol_buffer(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
7255 struct lpfc_vport
*vport
, struct lpfc_iocbq
*elsiocb
)
7257 struct Scsi_Host
*shost
;
7258 struct lpfc_nodelist
*ndlp
;
7261 uint32_t cmd
, did
, newnode
;
7262 uint8_t rjt_exp
, rjt_err
= 0;
7263 IOCB_t
*icmd
= &elsiocb
->iocb
;
7265 if (!vport
|| !(elsiocb
->context2
))
7269 payload
= ((struct lpfc_dmabuf
*)elsiocb
->context2
)->virt
;
7271 if ((phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) == 0)
7272 lpfc_post_buffer(phba
, pring
, 1);
7274 did
= icmd
->un
.rcvels
.remoteID
;
7275 if (icmd
->ulpStatus
) {
7276 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
7277 "RCV Unsol ELS: status:x%x/x%x did:x%x",
7278 icmd
->ulpStatus
, icmd
->un
.ulpWord
[4], did
);
7282 /* Check to see if link went down during discovery */
7283 if (lpfc_els_chk_latt(vport
))
7286 /* Ignore traffic received during vport shutdown. */
7287 if (vport
->load_flag
& FC_UNLOADING
)
7290 /* If NPort discovery is delayed drop incoming ELS */
7291 if ((vport
->fc_flag
& FC_DISC_DELAYED
) &&
7292 (cmd
!= ELS_CMD_PLOGI
))
7295 ndlp
= lpfc_findnode_did(vport
, did
);
7297 /* Cannot find existing Fabric ndlp, so allocate a new one */
7298 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
7302 lpfc_nlp_init(vport
, ndlp
, did
);
7303 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
7305 if ((did
& Fabric_DID_MASK
) == Fabric_DID_MASK
)
7306 ndlp
->nlp_type
|= NLP_FABRIC
;
7307 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
7308 ndlp
= lpfc_enable_node(vport
, ndlp
,
7309 NLP_STE_UNUSED_NODE
);
7312 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
7314 if ((did
& Fabric_DID_MASK
) == Fabric_DID_MASK
)
7315 ndlp
->nlp_type
|= NLP_FABRIC
;
7316 } else if (ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
) {
7317 /* This is similar to the new node path */
7318 ndlp
= lpfc_nlp_get(ndlp
);
7321 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
7325 phba
->fc_stat
.elsRcvFrame
++;
7328 * Do not process any unsolicited ELS commands
7329 * if the ndlp is in DEV_LOSS
7331 shost
= lpfc_shost_from_vport(vport
);
7332 spin_lock_irq(shost
->host_lock
);
7333 if (ndlp
->nlp_flag
& NLP_IN_DEV_LOSS
) {
7334 spin_unlock_irq(shost
->host_lock
);
7337 spin_unlock_irq(shost
->host_lock
);
7339 elsiocb
->context1
= lpfc_nlp_get(ndlp
);
7340 elsiocb
->vport
= vport
;
7342 if ((cmd
& ELS_CMD_MASK
) == ELS_CMD_RSCN
) {
7343 cmd
&= ELS_CMD_MASK
;
7345 /* ELS command <elsCmd> received from NPORT <did> */
7346 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
7347 "0112 ELS command x%x received from NPORT x%x "
7348 "Data: x%x x%x x%x x%x\n",
7349 cmd
, did
, vport
->port_state
, vport
->fc_flag
,
7350 vport
->fc_myDID
, vport
->fc_prevDID
);
7352 /* reject till our FLOGI completes */
7353 if ((vport
->port_state
< LPFC_FABRIC_CFG_LINK
) &&
7354 (cmd
!= ELS_CMD_FLOGI
)) {
7355 rjt_err
= LSRJT_UNABLE_TPC
;
7356 rjt_exp
= LSEXP_NOTHING_MORE
;
7362 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
7363 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
7364 did
, vport
->port_state
, ndlp
->nlp_flag
);
7366 phba
->fc_stat
.elsRcvPLOGI
++;
7367 ndlp
= lpfc_plogi_confirm_nport(phba
, payload
, ndlp
);
7368 if (phba
->sli_rev
== LPFC_SLI_REV4
&&
7369 (phba
->pport
->fc_flag
& FC_PT2PT
)) {
7370 vport
->fc_prevDID
= vport
->fc_myDID
;
7371 /* Our DID needs to be updated before registering
7372 * the vfi. This is done in lpfc_rcv_plogi but
7373 * that is called after the reg_vfi.
7375 vport
->fc_myDID
= elsiocb
->iocb
.un
.rcvels
.parmRo
;
7376 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
7377 "3312 Remote port assigned DID x%x "
7378 "%x\n", vport
->fc_myDID
,
7382 lpfc_send_els_event(vport
, ndlp
, payload
);
7384 /* If Nport discovery is delayed, reject PLOGIs */
7385 if (vport
->fc_flag
& FC_DISC_DELAYED
) {
7386 rjt_err
= LSRJT_UNABLE_TPC
;
7387 rjt_exp
= LSEXP_NOTHING_MORE
;
7391 if (vport
->port_state
< LPFC_DISC_AUTH
) {
7392 if (!(phba
->pport
->fc_flag
& FC_PT2PT
) ||
7393 (phba
->pport
->fc_flag
& FC_PT2PT_PLOGI
)) {
7394 rjt_err
= LSRJT_UNABLE_TPC
;
7395 rjt_exp
= LSEXP_NOTHING_MORE
;
7400 spin_lock_irq(shost
->host_lock
);
7401 ndlp
->nlp_flag
&= ~NLP_TARGET_REMOVE
;
7402 spin_unlock_irq(shost
->host_lock
);
7404 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
,
7409 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
7410 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
7411 did
, vport
->port_state
, ndlp
->nlp_flag
);
7413 phba
->fc_stat
.elsRcvFLOGI
++;
7414 lpfc_els_rcv_flogi(vport
, elsiocb
, ndlp
);
7419 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
7420 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
7421 did
, vport
->port_state
, ndlp
->nlp_flag
);
7423 phba
->fc_stat
.elsRcvLOGO
++;
7424 lpfc_send_els_event(vport
, ndlp
, payload
);
7425 if (vport
->port_state
< LPFC_DISC_AUTH
) {
7426 rjt_err
= LSRJT_UNABLE_TPC
;
7427 rjt_exp
= LSEXP_NOTHING_MORE
;
7430 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
, NLP_EVT_RCV_LOGO
);
7433 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
7434 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
7435 did
, vport
->port_state
, ndlp
->nlp_flag
);
7437 phba
->fc_stat
.elsRcvPRLO
++;
7438 lpfc_send_els_event(vport
, ndlp
, payload
);
7439 if (vport
->port_state
< LPFC_DISC_AUTH
) {
7440 rjt_err
= LSRJT_UNABLE_TPC
;
7441 rjt_exp
= LSEXP_NOTHING_MORE
;
7444 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
, NLP_EVT_RCV_PRLO
);
7447 phba
->fc_stat
.elsRcvLCB
++;
7448 lpfc_els_rcv_lcb(vport
, elsiocb
, ndlp
);
7451 phba
->fc_stat
.elsRcvRDP
++;
7452 lpfc_els_rcv_rdp(vport
, elsiocb
, ndlp
);
7455 phba
->fc_stat
.elsRcvRSCN
++;
7456 lpfc_els_rcv_rscn(vport
, elsiocb
, ndlp
);
7461 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
7462 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
7463 did
, vport
->port_state
, ndlp
->nlp_flag
);
7465 lpfc_send_els_event(vport
, ndlp
, payload
);
7466 phba
->fc_stat
.elsRcvADISC
++;
7467 if (vport
->port_state
< LPFC_DISC_AUTH
) {
7468 rjt_err
= LSRJT_UNABLE_TPC
;
7469 rjt_exp
= LSEXP_NOTHING_MORE
;
7472 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
,
7476 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
7477 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
7478 did
, vport
->port_state
, ndlp
->nlp_flag
);
7480 phba
->fc_stat
.elsRcvPDISC
++;
7481 if (vport
->port_state
< LPFC_DISC_AUTH
) {
7482 rjt_err
= LSRJT_UNABLE_TPC
;
7483 rjt_exp
= LSEXP_NOTHING_MORE
;
7486 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
,
7490 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
7491 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
7492 did
, vport
->port_state
, ndlp
->nlp_flag
);
7494 phba
->fc_stat
.elsRcvFARPR
++;
7495 lpfc_els_rcv_farpr(vport
, elsiocb
, ndlp
);
7498 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
7499 "RCV FARP: did:x%x/ste:x%x flg:x%x",
7500 did
, vport
->port_state
, ndlp
->nlp_flag
);
7502 phba
->fc_stat
.elsRcvFARP
++;
7503 lpfc_els_rcv_farp(vport
, elsiocb
, ndlp
);
7506 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
7507 "RCV FAN: did:x%x/ste:x%x flg:x%x",
7508 did
, vport
->port_state
, ndlp
->nlp_flag
);
7510 phba
->fc_stat
.elsRcvFAN
++;
7511 lpfc_els_rcv_fan(vport
, elsiocb
, ndlp
);
7514 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
7515 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
7516 did
, vport
->port_state
, ndlp
->nlp_flag
);
7518 phba
->fc_stat
.elsRcvPRLI
++;
7519 if (vport
->port_state
< LPFC_DISC_AUTH
) {
7520 rjt_err
= LSRJT_UNABLE_TPC
;
7521 rjt_exp
= LSEXP_NOTHING_MORE
;
7524 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
, NLP_EVT_RCV_PRLI
);
7527 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
7528 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
7529 did
, vport
->port_state
, ndlp
->nlp_flag
);
7531 phba
->fc_stat
.elsRcvLIRR
++;
7532 lpfc_els_rcv_lirr(vport
, elsiocb
, ndlp
);
7537 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
7538 "RCV RLS: did:x%x/ste:x%x flg:x%x",
7539 did
, vport
->port_state
, ndlp
->nlp_flag
);
7541 phba
->fc_stat
.elsRcvRLS
++;
7542 lpfc_els_rcv_rls(vport
, elsiocb
, ndlp
);
7547 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
7548 "RCV RPS: did:x%x/ste:x%x flg:x%x",
7549 did
, vport
->port_state
, ndlp
->nlp_flag
);
7551 phba
->fc_stat
.elsRcvRPS
++;
7552 lpfc_els_rcv_rps(vport
, elsiocb
, ndlp
);
7557 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
7558 "RCV RPL: did:x%x/ste:x%x flg:x%x",
7559 did
, vport
->port_state
, ndlp
->nlp_flag
);
7561 phba
->fc_stat
.elsRcvRPL
++;
7562 lpfc_els_rcv_rpl(vport
, elsiocb
, ndlp
);
7567 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
7568 "RCV RNID: did:x%x/ste:x%x flg:x%x",
7569 did
, vport
->port_state
, ndlp
->nlp_flag
);
7571 phba
->fc_stat
.elsRcvRNID
++;
7572 lpfc_els_rcv_rnid(vport
, elsiocb
, ndlp
);
7577 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
7578 "RCV RTV: did:x%x/ste:x%x flg:x%x",
7579 did
, vport
->port_state
, ndlp
->nlp_flag
);
7580 phba
->fc_stat
.elsRcvRTV
++;
7581 lpfc_els_rcv_rtv(vport
, elsiocb
, ndlp
);
7586 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
7587 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
7588 did
, vport
->port_state
, ndlp
->nlp_flag
);
7590 phba
->fc_stat
.elsRcvRRQ
++;
7591 lpfc_els_rcv_rrq(vport
, elsiocb
, ndlp
);
7596 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
7597 "RCV ECHO: did:x%x/ste:x%x flg:x%x",
7598 did
, vport
->port_state
, ndlp
->nlp_flag
);
7600 phba
->fc_stat
.elsRcvECHO
++;
7601 lpfc_els_rcv_echo(vport
, elsiocb
, ndlp
);
7606 /* receive this due to exchange closed */
7607 rjt_err
= LSRJT_UNABLE_TPC
;
7608 rjt_exp
= LSEXP_INVALID_OX_RX
;
7611 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
7612 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
7613 cmd
, did
, vport
->port_state
);
7615 /* Unsupported ELS command, reject */
7616 rjt_err
= LSRJT_CMD_UNSUPPORTED
;
7617 rjt_exp
= LSEXP_NOTHING_MORE
;
7619 /* Unknown ELS command <elsCmd> received from NPORT <did> */
7620 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
7621 "0115 Unknown ELS command x%x "
7622 "received from NPORT x%x\n", cmd
, did
);
7629 /* check if need to LS_RJT received ELS cmd */
7631 memset(&stat
, 0, sizeof(stat
));
7632 stat
.un
.b
.lsRjtRsnCode
= rjt_err
;
7633 stat
.un
.b
.lsRjtRsnCodeExp
= rjt_exp
;
7634 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, elsiocb
, ndlp
,
7638 lpfc_nlp_put(elsiocb
->context1
);
7639 elsiocb
->context1
= NULL
;
7643 if (vport
&& !(vport
->load_flag
& FC_UNLOADING
))
7644 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
7645 "0111 Dropping received ELS cmd "
7646 "Data: x%x x%x x%x\n",
7647 icmd
->ulpStatus
, icmd
->un
.ulpWord
[4], icmd
->ulpTimeout
);
7648 phba
->fc_stat
.elsRcvDrop
++;
7652 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
7653 * @phba: pointer to lpfc hba data structure.
7654 * @pring: pointer to a SLI ring.
7655 * @elsiocb: pointer to lpfc els iocb data structure.
7657 * This routine is used to process an unsolicited event received from a SLI
7658 * (Service Level Interface) ring. The actual processing of the data buffer
7659 * associated with the unsolicited event is done by invoking the routine
7660 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
7661 * SLI ring on which the unsolicited event was received.
7664 lpfc_els_unsol_event(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
7665 struct lpfc_iocbq
*elsiocb
)
7667 struct lpfc_vport
*vport
= phba
->pport
;
7668 IOCB_t
*icmd
= &elsiocb
->iocb
;
7670 struct lpfc_dmabuf
*bdeBuf1
= elsiocb
->context2
;
7671 struct lpfc_dmabuf
*bdeBuf2
= elsiocb
->context3
;
7673 elsiocb
->context1
= NULL
;
7674 elsiocb
->context2
= NULL
;
7675 elsiocb
->context3
= NULL
;
7677 if (icmd
->ulpStatus
== IOSTAT_NEED_BUFFER
) {
7678 lpfc_sli_hbqbuf_add_hbqs(phba
, LPFC_ELS_HBQ
);
7679 } else if (icmd
->ulpStatus
== IOSTAT_LOCAL_REJECT
&&
7680 (icmd
->un
.ulpWord
[4] & IOERR_PARAM_MASK
) ==
7681 IOERR_RCV_BUFFER_WAITING
) {
7682 phba
->fc_stat
.NoRcvBuf
++;
7683 /* Not enough posted buffers; Try posting more buffers */
7684 if (!(phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
))
7685 lpfc_post_buffer(phba
, pring
, 0);
7689 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
7690 (icmd
->ulpCommand
== CMD_IOCB_RCV_ELS64_CX
||
7691 icmd
->ulpCommand
== CMD_IOCB_RCV_SEQ64_CX
)) {
7692 if (icmd
->unsli3
.rcvsli3
.vpi
== 0xffff)
7693 vport
= phba
->pport
;
7695 vport
= lpfc_find_vport_by_vpid(phba
,
7696 icmd
->unsli3
.rcvsli3
.vpi
);
7699 /* If there are no BDEs associated
7700 * with this IOCB, there is nothing to do.
7702 if (icmd
->ulpBdeCount
== 0)
7705 /* type of ELS cmd is first 32bit word
7708 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) {
7709 elsiocb
->context2
= bdeBuf1
;
7711 paddr
= getPaddr(icmd
->un
.cont64
[0].addrHigh
,
7712 icmd
->un
.cont64
[0].addrLow
);
7713 elsiocb
->context2
= lpfc_sli_ringpostbuf_get(phba
, pring
,
7717 lpfc_els_unsol_buffer(phba
, pring
, vport
, elsiocb
);
7719 * The different unsolicited event handlers would tell us
7720 * if they are done with "mp" by setting context2 to NULL.
7722 if (elsiocb
->context2
) {
7723 lpfc_in_buf_free(phba
, (struct lpfc_dmabuf
*)elsiocb
->context2
);
7724 elsiocb
->context2
= NULL
;
7727 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
7728 if ((phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) &&
7729 icmd
->ulpBdeCount
== 2) {
7730 elsiocb
->context2
= bdeBuf2
;
7731 lpfc_els_unsol_buffer(phba
, pring
, vport
, elsiocb
);
7732 /* free mp if we are done with it */
7733 if (elsiocb
->context2
) {
7734 lpfc_in_buf_free(phba
, elsiocb
->context2
);
7735 elsiocb
->context2
= NULL
;
7741 lpfc_start_fdmi(struct lpfc_vport
*vport
)
7743 struct lpfc_hba
*phba
= vport
->phba
;
7744 struct lpfc_nodelist
*ndlp
;
7746 /* If this is the first time, allocate an ndlp and initialize
7747 * it. Otherwise, make sure the node is enabled and then do the
7750 ndlp
= lpfc_findnode_did(vport
, FDMI_DID
);
7752 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
7754 lpfc_nlp_init(vport
, ndlp
, FDMI_DID
);
7755 ndlp
->nlp_type
|= NLP_FABRIC
;
7760 if (!NLP_CHK_NODE_ACT(ndlp
))
7761 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_NPR_NODE
);
7764 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
7765 lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0);
7770 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
7771 * @phba: pointer to lpfc hba data structure.
7772 * @vport: pointer to a virtual N_Port data structure.
7774 * This routine issues a Port Login (PLOGI) to the Name Server with
7775 * State Change Request (SCR) for a @vport. This routine will create an
7776 * ndlp for the Name Server associated to the @vport if such node does
7777 * not already exist. The PLOGI to Name Server is issued by invoking the
7778 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
7779 * (FDMI) is configured to the @vport, a FDMI node will be created and
7780 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
7783 lpfc_do_scr_ns_plogi(struct lpfc_hba
*phba
, struct lpfc_vport
*vport
)
7785 struct lpfc_nodelist
*ndlp
;
7786 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
7789 * If lpfc_delay_discovery parameter is set and the clean address
7790 * bit is cleared and fc fabric parameters chenged, delay FC NPort
7793 spin_lock_irq(shost
->host_lock
);
7794 if (vport
->fc_flag
& FC_DISC_DELAYED
) {
7795 spin_unlock_irq(shost
->host_lock
);
7796 lpfc_printf_log(phba
, KERN_ERR
, LOG_DISCOVERY
,
7797 "3334 Delay fc port discovery for %d seconds\n",
7799 mod_timer(&vport
->delayed_disc_tmo
,
7800 jiffies
+ msecs_to_jiffies(1000 * phba
->fc_ratov
));
7803 spin_unlock_irq(shost
->host_lock
);
7805 ndlp
= lpfc_findnode_did(vport
, NameServer_DID
);
7807 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
7809 if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) {
7810 lpfc_disc_start(vport
);
7813 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
7814 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
7815 "0251 NameServer login: no memory\n");
7818 lpfc_nlp_init(vport
, ndlp
, NameServer_DID
);
7819 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
7820 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
7822 if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) {
7823 lpfc_disc_start(vport
);
7826 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
7827 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
7828 "0348 NameServer login: node freed\n");
7832 ndlp
->nlp_type
|= NLP_FABRIC
;
7834 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
7836 if (lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0)) {
7837 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
7838 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
7839 "0252 Cannot issue NameServer login\n");
7843 if ((phba
->cfg_fdmi_on
> LPFC_FDMI_NO_SUPPORT
) &&
7844 (vport
->load_flag
& FC_ALLOW_FDMI
))
7845 lpfc_start_fdmi(vport
);
7849 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
7850 * @phba: pointer to lpfc hba data structure.
7851 * @pmb: pointer to the driver internal queue element for mailbox command.
7853 * This routine is the completion callback function to register new vport
7854 * mailbox command. If the new vport mailbox command completes successfully,
7855 * the fabric registration login shall be performed on physical port (the
7856 * new vport created is actually a physical port, with VPI 0) or the port
7857 * login to Name Server for State Change Request (SCR) will be performed
7858 * on virtual port (real virtual port, with VPI greater than 0).
7861 lpfc_cmpl_reg_new_vport(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
7863 struct lpfc_vport
*vport
= pmb
->vport
;
7864 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
7865 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
7866 MAILBOX_t
*mb
= &pmb
->u
.mb
;
7869 spin_lock_irq(shost
->host_lock
);
7870 vport
->fc_flag
&= ~FC_VPORT_NEEDS_REG_VPI
;
7871 spin_unlock_irq(shost
->host_lock
);
7873 if (mb
->mbxStatus
) {
7874 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
7875 "0915 Register VPI failed : Status: x%x"
7876 " upd bit: x%x \n", mb
->mbxStatus
,
7877 mb
->un
.varRegVpi
.upd
);
7878 if (phba
->sli_rev
== LPFC_SLI_REV4
&&
7879 mb
->un
.varRegVpi
.upd
)
7880 goto mbox_err_exit
;
7882 switch (mb
->mbxStatus
) {
7883 case 0x11: /* unsupported feature */
7884 case 0x9603: /* max_vpi exceeded */
7885 case 0x9602: /* Link event since CLEAR_LA */
7886 /* giving up on vport registration */
7887 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
7888 spin_lock_irq(shost
->host_lock
);
7889 vport
->fc_flag
&= ~(FC_FABRIC
| FC_PUBLIC_LOOP
);
7890 spin_unlock_irq(shost
->host_lock
);
7891 lpfc_can_disctmo(vport
);
7893 /* If reg_vpi fail with invalid VPI status, re-init VPI */
7895 spin_lock_irq(shost
->host_lock
);
7896 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
7897 spin_unlock_irq(shost
->host_lock
);
7898 lpfc_init_vpi(phba
, pmb
, vport
->vpi
);
7900 pmb
->mbox_cmpl
= lpfc_init_vpi_cmpl
;
7901 rc
= lpfc_sli_issue_mbox(phba
, pmb
,
7903 if (rc
== MBX_NOT_FINISHED
) {
7904 lpfc_printf_vlog(vport
,
7906 "2732 Failed to issue INIT_VPI"
7907 " mailbox command\n");
7914 /* Try to recover from this error */
7915 if (phba
->sli_rev
== LPFC_SLI_REV4
)
7916 lpfc_sli4_unreg_all_rpis(vport
);
7917 lpfc_mbx_unreg_vpi(vport
);
7918 spin_lock_irq(shost
->host_lock
);
7919 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
7920 spin_unlock_irq(shost
->host_lock
);
7921 if (vport
->port_type
== LPFC_PHYSICAL_PORT
7922 && !(vport
->fc_flag
& FC_LOGO_RCVD_DID_CHNG
))
7923 lpfc_issue_init_vfi(vport
);
7925 lpfc_initial_fdisc(vport
);
7929 spin_lock_irq(shost
->host_lock
);
7930 vport
->vpi_state
|= LPFC_VPI_REGISTERED
;
7931 spin_unlock_irq(shost
->host_lock
);
7932 if (vport
== phba
->pport
) {
7933 if (phba
->sli_rev
< LPFC_SLI_REV4
)
7934 lpfc_issue_fabric_reglogin(vport
);
7937 * If the physical port is instantiated using
7938 * FDISC, do not start vport discovery.
7940 if (vport
->port_state
!= LPFC_FDISC
)
7941 lpfc_start_fdiscs(phba
);
7942 lpfc_do_scr_ns_plogi(phba
, vport
);
7945 lpfc_do_scr_ns_plogi(phba
, vport
);
7948 /* Now, we decrement the ndlp reference count held for this
7953 mempool_free(pmb
, phba
->mbox_mem_pool
);
7958 * lpfc_register_new_vport - Register a new vport with a HBA
7959 * @phba: pointer to lpfc hba data structure.
7960 * @vport: pointer to a host virtual N_Port data structure.
7961 * @ndlp: pointer to a node-list data structure.
7963 * This routine registers the @vport as a new virtual port with a HBA.
7964 * It is done through a registering vpi mailbox command.
7967 lpfc_register_new_vport(struct lpfc_hba
*phba
, struct lpfc_vport
*vport
,
7968 struct lpfc_nodelist
*ndlp
)
7970 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
7973 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
7975 lpfc_reg_vpi(vport
, mbox
);
7976 mbox
->vport
= vport
;
7977 mbox
->context2
= lpfc_nlp_get(ndlp
);
7978 mbox
->mbox_cmpl
= lpfc_cmpl_reg_new_vport
;
7979 if (lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
)
7980 == MBX_NOT_FINISHED
) {
7981 /* mailbox command not success, decrement ndlp
7982 * reference count for this command
7985 mempool_free(mbox
, phba
->mbox_mem_pool
);
7987 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
7988 "0253 Register VPI: Can't send mbox\n");
7992 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
7993 "0254 Register VPI: no memory\n");
7999 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
8000 spin_lock_irq(shost
->host_lock
);
8001 vport
->fc_flag
&= ~FC_VPORT_NEEDS_REG_VPI
;
8002 spin_unlock_irq(shost
->host_lock
);
8007 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
8008 * @phba: pointer to lpfc hba data structure.
8010 * This routine cancels the retry delay timers to all the vports.
8013 lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba
*phba
)
8015 struct lpfc_vport
**vports
;
8016 struct lpfc_nodelist
*ndlp
;
8017 uint32_t link_state
;
8020 /* Treat this failure as linkdown for all vports */
8021 link_state
= phba
->link_state
;
8022 lpfc_linkdown(phba
);
8023 phba
->link_state
= link_state
;
8025 vports
= lpfc_create_vport_work_array(phba
);
8028 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
8029 ndlp
= lpfc_findnode_did(vports
[i
], Fabric_DID
);
8031 lpfc_cancel_retry_delay_tmo(vports
[i
], ndlp
);
8032 lpfc_els_flush_cmd(vports
[i
]);
8034 lpfc_destroy_vport_work_array(phba
, vports
);
8039 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
8040 * @phba: pointer to lpfc hba data structure.
8042 * This routine abort all pending discovery commands and
8043 * start a timer to retry FLOGI for the physical port
8047 lpfc_retry_pport_discovery(struct lpfc_hba
*phba
)
8049 struct lpfc_nodelist
*ndlp
;
8050 struct Scsi_Host
*shost
;
8052 /* Cancel the all vports retry delay retry timers */
8053 lpfc_cancel_all_vport_retry_delay_timer(phba
);
8055 /* If fabric require FLOGI, then re-instantiate physical login */
8056 ndlp
= lpfc_findnode_did(phba
->pport
, Fabric_DID
);
8060 shost
= lpfc_shost_from_vport(phba
->pport
);
8061 mod_timer(&ndlp
->nlp_delayfunc
, jiffies
+ msecs_to_jiffies(1000));
8062 spin_lock_irq(shost
->host_lock
);
8063 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
8064 spin_unlock_irq(shost
->host_lock
);
8065 ndlp
->nlp_last_elscmd
= ELS_CMD_FLOGI
;
8066 phba
->pport
->port_state
= LPFC_FLOGI
;
8071 * lpfc_fabric_login_reqd - Check if FLOGI required.
8072 * @phba: pointer to lpfc hba data structure.
8073 * @cmdiocb: pointer to FDISC command iocb.
8074 * @rspiocb: pointer to FDISC response iocb.
8076 * This routine checks if a FLOGI is reguired for FDISC
8080 lpfc_fabric_login_reqd(struct lpfc_hba
*phba
,
8081 struct lpfc_iocbq
*cmdiocb
,
8082 struct lpfc_iocbq
*rspiocb
)
8085 if ((rspiocb
->iocb
.ulpStatus
!= IOSTAT_FABRIC_RJT
) ||
8086 (rspiocb
->iocb
.un
.ulpWord
[4] != RJT_LOGIN_REQUIRED
))
8093 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
8094 * @phba: pointer to lpfc hba data structure.
8095 * @cmdiocb: pointer to lpfc command iocb data structure.
8096 * @rspiocb: pointer to lpfc response iocb data structure.
8098 * This routine is the completion callback function to a Fabric Discover
8099 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
8100 * single threaded, each FDISC completion callback function will reset
8101 * the discovery timer for all vports such that the timers will not get
8102 * unnecessary timeout. The function checks the FDISC IOCB status. If error
8103 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
8104 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
8105 * assigned to the vport has been changed with the completion of the FDISC
8106 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
8107 * are unregistered from the HBA, and then the lpfc_register_new_vport()
8108 * routine is invoked to register new vport with the HBA. Otherwise, the
8109 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
8110 * Server for State Change Request (SCR).
8113 lpfc_cmpl_els_fdisc(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
8114 struct lpfc_iocbq
*rspiocb
)
8116 struct lpfc_vport
*vport
= cmdiocb
->vport
;
8117 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
8118 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
8119 struct lpfc_nodelist
*np
;
8120 struct lpfc_nodelist
*next_np
;
8121 IOCB_t
*irsp
= &rspiocb
->iocb
;
8122 struct lpfc_iocbq
*piocb
;
8123 struct lpfc_dmabuf
*pcmd
= cmdiocb
->context2
, *prsp
;
8124 struct serv_parm
*sp
;
8125 uint8_t fabric_param_changed
;
8127 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
8128 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
8129 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
8131 /* Since all FDISCs are being single threaded, we
8132 * must reset the discovery timer for ALL vports
8133 * waiting to send FDISC when one completes.
8135 list_for_each_entry(piocb
, &phba
->fabric_iocb_list
, list
) {
8136 lpfc_set_disctmo(piocb
->vport
);
8139 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
8140 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
8141 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4], vport
->fc_prevDID
);
8143 if (irsp
->ulpStatus
) {
8145 if (lpfc_fabric_login_reqd(phba
, cmdiocb
, rspiocb
)) {
8146 lpfc_retry_pport_discovery(phba
);
8150 /* Check for retry */
8151 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
))
8154 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
8155 "0126 FDISC failed. (x%x/x%x)\n",
8156 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4]);
8159 spin_lock_irq(shost
->host_lock
);
8160 vport
->fc_flag
&= ~FC_VPORT_CVL_RCVD
;
8161 vport
->fc_flag
&= ~FC_VPORT_LOGO_RCVD
;
8162 vport
->fc_flag
|= FC_FABRIC
;
8163 if (vport
->phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
)
8164 vport
->fc_flag
|= FC_PUBLIC_LOOP
;
8165 spin_unlock_irq(shost
->host_lock
);
8167 vport
->fc_myDID
= irsp
->un
.ulpWord
[4] & Mask_DID
;
8168 lpfc_vport_set_state(vport
, FC_VPORT_ACTIVE
);
8169 prsp
= list_get_first(&pcmd
->list
, struct lpfc_dmabuf
, list
);
8172 sp
= prsp
->virt
+ sizeof(uint32_t);
8173 fabric_param_changed
= lpfc_check_clean_addr_bit(vport
, sp
);
8174 memcpy(&vport
->fabric_portname
, &sp
->portName
,
8175 sizeof(struct lpfc_name
));
8176 memcpy(&vport
->fabric_nodename
, &sp
->nodeName
,
8177 sizeof(struct lpfc_name
));
8178 if (fabric_param_changed
&&
8179 !(vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
)) {
8180 /* If our NportID changed, we need to ensure all
8181 * remaining NPORTs get unreg_login'ed so we can
8184 list_for_each_entry_safe(np
, next_np
,
8185 &vport
->fc_nodes
, nlp_listp
) {
8186 if (!NLP_CHK_NODE_ACT(ndlp
) ||
8187 (np
->nlp_state
!= NLP_STE_NPR_NODE
) ||
8188 !(np
->nlp_flag
& NLP_NPR_ADISC
))
8190 spin_lock_irq(shost
->host_lock
);
8191 np
->nlp_flag
&= ~NLP_NPR_ADISC
;
8192 spin_unlock_irq(shost
->host_lock
);
8193 lpfc_unreg_rpi(vport
, np
);
8195 lpfc_cleanup_pending_mbox(vport
);
8197 if (phba
->sli_rev
== LPFC_SLI_REV4
)
8198 lpfc_sli4_unreg_all_rpis(vport
);
8200 lpfc_mbx_unreg_vpi(vport
);
8201 spin_lock_irq(shost
->host_lock
);
8202 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
8203 if (phba
->sli_rev
== LPFC_SLI_REV4
)
8204 vport
->fc_flag
|= FC_VPORT_NEEDS_INIT_VPI
;
8206 vport
->fc_flag
|= FC_LOGO_RCVD_DID_CHNG
;
8207 spin_unlock_irq(shost
->host_lock
);
8208 } else if ((phba
->sli_rev
== LPFC_SLI_REV4
) &&
8209 !(vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
)) {
8211 * Driver needs to re-reg VPI in order for f/w
8212 * to update the MAC address.
8214 lpfc_register_new_vport(phba
, vport
, ndlp
);
8218 if (vport
->fc_flag
& FC_VPORT_NEEDS_INIT_VPI
)
8219 lpfc_issue_init_vpi(vport
);
8220 else if (vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
)
8221 lpfc_register_new_vport(phba
, vport
, ndlp
);
8223 lpfc_do_scr_ns_plogi(phba
, vport
);
8226 if (vport
->fc_vport
->vport_state
!= FC_VPORT_NO_FABRIC_RSCS
)
8227 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
8228 /* Cancel discovery timer */
8229 lpfc_can_disctmo(vport
);
8232 lpfc_els_free_iocb(phba
, cmdiocb
);
8236 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
8237 * @vport: pointer to a virtual N_Port data structure.
8238 * @ndlp: pointer to a node-list data structure.
8239 * @retry: number of retries to the command IOCB.
8241 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
8242 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
8243 * routine to issue the IOCB, which makes sure only one outstanding fabric
8244 * IOCB will be sent off HBA at any given time.
8246 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
8247 * will be incremented by 1 for holding the ndlp and the reference to ndlp
8248 * will be stored into the context1 field of the IOCB for the completion
8249 * callback function to the FDISC ELS command.
8252 * 0 - Successfully issued fdisc iocb command
8253 * 1 - Failed to issue fdisc iocb command
8256 lpfc_issue_els_fdisc(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
8259 struct lpfc_hba
*phba
= vport
->phba
;
8261 struct lpfc_iocbq
*elsiocb
;
8262 struct serv_parm
*sp
;
8265 int did
= ndlp
->nlp_DID
;
8268 vport
->port_state
= LPFC_FDISC
;
8269 vport
->fc_myDID
= 0;
8270 cmdsize
= (sizeof(uint32_t) + sizeof(struct serv_parm
));
8271 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
, did
,
8274 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
8275 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
8276 "0255 Issue FDISC: no IOCB\n");
8280 icmd
= &elsiocb
->iocb
;
8281 icmd
->un
.elsreq64
.myID
= 0;
8282 icmd
->un
.elsreq64
.fl
= 1;
8285 * SLI3 ports require a different context type value than SLI4.
8286 * Catch SLI3 ports here and override the prep.
8288 if (phba
->sli_rev
== LPFC_SLI_REV3
) {
8293 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
8294 *((uint32_t *) (pcmd
)) = ELS_CMD_FDISC
;
8295 pcmd
+= sizeof(uint32_t); /* CSP Word 1 */
8296 memcpy(pcmd
, &vport
->phba
->pport
->fc_sparam
, sizeof(struct serv_parm
));
8297 sp
= (struct serv_parm
*) pcmd
;
8298 /* Setup CSPs accordingly for Fabric */
8299 sp
->cmn
.e_d_tov
= 0;
8300 sp
->cmn
.w2
.r_a_tov
= 0;
8301 sp
->cmn
.virtual_fabric_support
= 0;
8302 sp
->cls1
.classValid
= 0;
8303 sp
->cls2
.seqDelivery
= 1;
8304 sp
->cls3
.seqDelivery
= 1;
8306 pcmd
+= sizeof(uint32_t); /* CSP Word 2 */
8307 pcmd
+= sizeof(uint32_t); /* CSP Word 3 */
8308 pcmd
+= sizeof(uint32_t); /* CSP Word 4 */
8309 pcmd
+= sizeof(uint32_t); /* Port Name */
8310 memcpy(pcmd
, &vport
->fc_portname
, 8);
8311 pcmd
+= sizeof(uint32_t); /* Node Name */
8312 pcmd
+= sizeof(uint32_t); /* Node Name */
8313 memcpy(pcmd
, &vport
->fc_nodename
, 8);
8315 lpfc_set_disctmo(vport
);
8317 phba
->fc_stat
.elsXmitFDISC
++;
8318 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_fdisc
;
8320 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
8321 "Issue FDISC: did:x%x",
8324 rc
= lpfc_issue_fabric_iocb(phba
, elsiocb
);
8325 if (rc
== IOCB_ERROR
) {
8326 lpfc_els_free_iocb(phba
, elsiocb
);
8327 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
8328 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
8329 "0256 Issue FDISC: Cannot send IOCB\n");
8332 lpfc_vport_set_state(vport
, FC_VPORT_INITIALIZING
);
8337 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
8338 * @phba: pointer to lpfc hba data structure.
8339 * @cmdiocb: pointer to lpfc command iocb data structure.
8340 * @rspiocb: pointer to lpfc response iocb data structure.
8342 * This routine is the completion callback function to the issuing of a LOGO
8343 * ELS command off a vport. It frees the command IOCB and then decrement the
8344 * reference count held on ndlp for this completion function, indicating that
8345 * the reference to the ndlp is no long needed. Note that the
8346 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
8347 * callback function and an additional explicit ndlp reference decrementation
8348 * will trigger the actual release of the ndlp.
8351 lpfc_cmpl_els_npiv_logo(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
8352 struct lpfc_iocbq
*rspiocb
)
8354 struct lpfc_vport
*vport
= cmdiocb
->vport
;
8356 struct lpfc_nodelist
*ndlp
;
8357 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
8359 ndlp
= (struct lpfc_nodelist
*)cmdiocb
->context1
;
8360 irsp
= &rspiocb
->iocb
;
8361 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
8362 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
8363 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4], irsp
->un
.rcvels
.remoteID
);
8365 lpfc_els_free_iocb(phba
, cmdiocb
);
8366 vport
->unreg_vpi_cmpl
= VPORT_ERROR
;
8368 /* Trigger the release of the ndlp after logo */
8371 /* NPIV LOGO completes to NPort <nlp_DID> */
8372 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
8373 "2928 NPIV LOGO completes to NPort x%x "
8374 "Data: x%x x%x x%x x%x\n",
8375 ndlp
->nlp_DID
, irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
8376 irsp
->ulpTimeout
, vport
->num_disc_nodes
);
8378 if (irsp
->ulpStatus
== IOSTAT_SUCCESS
) {
8379 spin_lock_irq(shost
->host_lock
);
8380 vport
->fc_flag
&= ~FC_NDISC_ACTIVE
;
8381 vport
->fc_flag
&= ~FC_FABRIC
;
8382 spin_unlock_irq(shost
->host_lock
);
8383 lpfc_can_disctmo(vport
);
8388 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
8389 * @vport: pointer to a virtual N_Port data structure.
8390 * @ndlp: pointer to a node-list data structure.
8392 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
8394 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
8395 * will be incremented by 1 for holding the ndlp and the reference to ndlp
8396 * will be stored into the context1 field of the IOCB for the completion
8397 * callback function to the LOGO ELS command.
8400 * 0 - Successfully issued logo off the @vport
8401 * 1 - Failed to issue logo off the @vport
8404 lpfc_issue_els_npiv_logo(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
8406 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
8407 struct lpfc_hba
*phba
= vport
->phba
;
8408 struct lpfc_iocbq
*elsiocb
;
8412 cmdsize
= 2 * sizeof(uint32_t) + sizeof(struct lpfc_name
);
8413 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, 0, ndlp
, ndlp
->nlp_DID
,
8418 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
8419 *((uint32_t *) (pcmd
)) = ELS_CMD_LOGO
;
8420 pcmd
+= sizeof(uint32_t);
8422 /* Fill in LOGO payload */
8423 *((uint32_t *) (pcmd
)) = be32_to_cpu(vport
->fc_myDID
);
8424 pcmd
+= sizeof(uint32_t);
8425 memcpy(pcmd
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
8427 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
8428 "Issue LOGO npiv did:x%x flg:x%x",
8429 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
8431 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_npiv_logo
;
8432 spin_lock_irq(shost
->host_lock
);
8433 ndlp
->nlp_flag
|= NLP_LOGO_SND
;
8434 spin_unlock_irq(shost
->host_lock
);
8435 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) ==
8437 spin_lock_irq(shost
->host_lock
);
8438 ndlp
->nlp_flag
&= ~NLP_LOGO_SND
;
8439 spin_unlock_irq(shost
->host_lock
);
8440 lpfc_els_free_iocb(phba
, elsiocb
);
8447 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
8448 * @ptr: holder for the timer function associated data.
8450 * This routine is invoked by the fabric iocb block timer after
8451 * timeout. It posts the fabric iocb block timeout event by setting the
8452 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
8453 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
8454 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
8455 * posted event WORKER_FABRIC_BLOCK_TMO.
8458 lpfc_fabric_block_timeout(unsigned long ptr
)
8460 struct lpfc_hba
*phba
= (struct lpfc_hba
*) ptr
;
8461 unsigned long iflags
;
8462 uint32_t tmo_posted
;
8464 spin_lock_irqsave(&phba
->pport
->work_port_lock
, iflags
);
8465 tmo_posted
= phba
->pport
->work_port_events
& WORKER_FABRIC_BLOCK_TMO
;
8467 phba
->pport
->work_port_events
|= WORKER_FABRIC_BLOCK_TMO
;
8468 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, iflags
);
8471 lpfc_worker_wake_up(phba
);
8476 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
8477 * @phba: pointer to lpfc hba data structure.
8479 * This routine issues one fabric iocb from the driver internal list to
8480 * the HBA. It first checks whether it's ready to issue one fabric iocb to
8481 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
8482 * remove one pending fabric iocb from the driver internal list and invokes
8483 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
8486 lpfc_resume_fabric_iocbs(struct lpfc_hba
*phba
)
8488 struct lpfc_iocbq
*iocb
;
8489 unsigned long iflags
;
8495 spin_lock_irqsave(&phba
->hbalock
, iflags
);
8496 /* Post any pending iocb to the SLI layer */
8497 if (atomic_read(&phba
->fabric_iocb_count
) == 0) {
8498 list_remove_head(&phba
->fabric_iocb_list
, iocb
, typeof(*iocb
),
8501 /* Increment fabric iocb count to hold the position */
8502 atomic_inc(&phba
->fabric_iocb_count
);
8504 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8506 iocb
->fabric_iocb_cmpl
= iocb
->iocb_cmpl
;
8507 iocb
->iocb_cmpl
= lpfc_cmpl_fabric_iocb
;
8508 iocb
->iocb_flag
|= LPFC_IO_FABRIC
;
8510 lpfc_debugfs_disc_trc(iocb
->vport
, LPFC_DISC_TRC_ELS_CMD
,
8511 "Fabric sched1: ste:x%x",
8512 iocb
->vport
->port_state
, 0, 0);
8514 ret
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, iocb
, 0);
8516 if (ret
== IOCB_ERROR
) {
8517 iocb
->iocb_cmpl
= iocb
->fabric_iocb_cmpl
;
8518 iocb
->fabric_iocb_cmpl
= NULL
;
8519 iocb
->iocb_flag
&= ~LPFC_IO_FABRIC
;
8521 cmd
->ulpStatus
= IOSTAT_LOCAL_REJECT
;
8522 cmd
->un
.ulpWord
[4] = IOERR_SLI_ABORTED
;
8523 iocb
->iocb_cmpl(phba
, iocb
, iocb
);
8525 atomic_dec(&phba
->fabric_iocb_count
);
8534 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
8535 * @phba: pointer to lpfc hba data structure.
8537 * This routine unblocks the issuing fabric iocb command. The function
8538 * will clear the fabric iocb block bit and then invoke the routine
8539 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
8540 * from the driver internal fabric iocb list.
8543 lpfc_unblock_fabric_iocbs(struct lpfc_hba
*phba
)
8545 clear_bit(FABRIC_COMANDS_BLOCKED
, &phba
->bit_flags
);
8547 lpfc_resume_fabric_iocbs(phba
);
8552 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
8553 * @phba: pointer to lpfc hba data structure.
8555 * This routine blocks the issuing fabric iocb for a specified amount of
8556 * time (currently 100 ms). This is done by set the fabric iocb block bit
8557 * and set up a timeout timer for 100ms. When the block bit is set, no more
8558 * fabric iocb will be issued out of the HBA.
8561 lpfc_block_fabric_iocbs(struct lpfc_hba
*phba
)
8565 blocked
= test_and_set_bit(FABRIC_COMANDS_BLOCKED
, &phba
->bit_flags
);
8566 /* Start a timer to unblock fabric iocbs after 100ms */
8568 mod_timer(&phba
->fabric_block_timer
,
8569 jiffies
+ msecs_to_jiffies(100));
8575 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
8576 * @phba: pointer to lpfc hba data structure.
8577 * @cmdiocb: pointer to lpfc command iocb data structure.
8578 * @rspiocb: pointer to lpfc response iocb data structure.
8580 * This routine is the callback function that is put to the fabric iocb's
8581 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
8582 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
8583 * function first restores and invokes the original iocb's callback function
8584 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
8585 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
8588 lpfc_cmpl_fabric_iocb(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
8589 struct lpfc_iocbq
*rspiocb
)
8593 if ((cmdiocb
->iocb_flag
& LPFC_IO_FABRIC
) != LPFC_IO_FABRIC
)
8596 switch (rspiocb
->iocb
.ulpStatus
) {
8597 case IOSTAT_NPORT_RJT
:
8598 case IOSTAT_FABRIC_RJT
:
8599 if (rspiocb
->iocb
.un
.ulpWord
[4] & RJT_UNAVAIL_TEMP
) {
8600 lpfc_block_fabric_iocbs(phba
);
8604 case IOSTAT_NPORT_BSY
:
8605 case IOSTAT_FABRIC_BSY
:
8606 lpfc_block_fabric_iocbs(phba
);
8610 stat
.un
.lsRjtError
=
8611 be32_to_cpu(rspiocb
->iocb
.un
.ulpWord
[4]);
8612 if ((stat
.un
.b
.lsRjtRsnCode
== LSRJT_UNABLE_TPC
) ||
8613 (stat
.un
.b
.lsRjtRsnCode
== LSRJT_LOGICAL_BSY
))
8614 lpfc_block_fabric_iocbs(phba
);
8618 if (atomic_read(&phba
->fabric_iocb_count
) == 0)
8621 cmdiocb
->iocb_cmpl
= cmdiocb
->fabric_iocb_cmpl
;
8622 cmdiocb
->fabric_iocb_cmpl
= NULL
;
8623 cmdiocb
->iocb_flag
&= ~LPFC_IO_FABRIC
;
8624 cmdiocb
->iocb_cmpl(phba
, cmdiocb
, rspiocb
);
8626 atomic_dec(&phba
->fabric_iocb_count
);
8627 if (!test_bit(FABRIC_COMANDS_BLOCKED
, &phba
->bit_flags
)) {
8628 /* Post any pending iocbs to HBA */
8629 lpfc_resume_fabric_iocbs(phba
);
8634 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
8635 * @phba: pointer to lpfc hba data structure.
8636 * @iocb: pointer to lpfc command iocb data structure.
8638 * This routine is used as the top-level API for issuing a fabric iocb command
8639 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
8640 * function makes sure that only one fabric bound iocb will be outstanding at
8641 * any given time. As such, this function will first check to see whether there
8642 * is already an outstanding fabric iocb on the wire. If so, it will put the
8643 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
8644 * issued later. Otherwise, it will issue the iocb on the wire and update the
8645 * fabric iocb count it indicate that there is one fabric iocb on the wire.
8647 * Note, this implementation has a potential sending out fabric IOCBs out of
8648 * order. The problem is caused by the construction of the "ready" boolen does
8649 * not include the condition that the internal fabric IOCB list is empty. As
8650 * such, it is possible a fabric IOCB issued by this routine might be "jump"
8651 * ahead of the fabric IOCBs in the internal list.
8654 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
8655 * IOCB_ERROR - failed to issue fabric iocb
8658 lpfc_issue_fabric_iocb(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocb
)
8660 unsigned long iflags
;
8664 if (atomic_read(&phba
->fabric_iocb_count
) > 1)
8667 spin_lock_irqsave(&phba
->hbalock
, iflags
);
8668 ready
= atomic_read(&phba
->fabric_iocb_count
) == 0 &&
8669 !test_bit(FABRIC_COMANDS_BLOCKED
, &phba
->bit_flags
);
8672 /* Increment fabric iocb count to hold the position */
8673 atomic_inc(&phba
->fabric_iocb_count
);
8674 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8676 iocb
->fabric_iocb_cmpl
= iocb
->iocb_cmpl
;
8677 iocb
->iocb_cmpl
= lpfc_cmpl_fabric_iocb
;
8678 iocb
->iocb_flag
|= LPFC_IO_FABRIC
;
8680 lpfc_debugfs_disc_trc(iocb
->vport
, LPFC_DISC_TRC_ELS_CMD
,
8681 "Fabric sched2: ste:x%x",
8682 iocb
->vport
->port_state
, 0, 0);
8684 ret
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, iocb
, 0);
8686 if (ret
== IOCB_ERROR
) {
8687 iocb
->iocb_cmpl
= iocb
->fabric_iocb_cmpl
;
8688 iocb
->fabric_iocb_cmpl
= NULL
;
8689 iocb
->iocb_flag
&= ~LPFC_IO_FABRIC
;
8690 atomic_dec(&phba
->fabric_iocb_count
);
8693 spin_lock_irqsave(&phba
->hbalock
, iflags
);
8694 list_add_tail(&iocb
->list
, &phba
->fabric_iocb_list
);
8695 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8702 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
8703 * @vport: pointer to a virtual N_Port data structure.
8705 * This routine aborts all the IOCBs associated with a @vport from the
8706 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
8707 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
8708 * list, removes each IOCB associated with the @vport off the list, set the
8709 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
8710 * associated with the IOCB.
8712 static void lpfc_fabric_abort_vport(struct lpfc_vport
*vport
)
8714 LIST_HEAD(completions
);
8715 struct lpfc_hba
*phba
= vport
->phba
;
8716 struct lpfc_iocbq
*tmp_iocb
, *piocb
;
8718 spin_lock_irq(&phba
->hbalock
);
8719 list_for_each_entry_safe(piocb
, tmp_iocb
, &phba
->fabric_iocb_list
,
8722 if (piocb
->vport
!= vport
)
8725 list_move_tail(&piocb
->list
, &completions
);
8727 spin_unlock_irq(&phba
->hbalock
);
8729 /* Cancel all the IOCBs from the completions list */
8730 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
8735 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
8736 * @ndlp: pointer to a node-list data structure.
8738 * This routine aborts all the IOCBs associated with an @ndlp from the
8739 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
8740 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
8741 * list, removes each IOCB associated with the @ndlp off the list, set the
8742 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
8743 * associated with the IOCB.
8745 void lpfc_fabric_abort_nport(struct lpfc_nodelist
*ndlp
)
8747 LIST_HEAD(completions
);
8748 struct lpfc_hba
*phba
= ndlp
->phba
;
8749 struct lpfc_iocbq
*tmp_iocb
, *piocb
;
8750 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
8752 spin_lock_irq(&phba
->hbalock
);
8753 list_for_each_entry_safe(piocb
, tmp_iocb
, &phba
->fabric_iocb_list
,
8755 if ((lpfc_check_sli_ndlp(phba
, pring
, piocb
, ndlp
))) {
8757 list_move_tail(&piocb
->list
, &completions
);
8760 spin_unlock_irq(&phba
->hbalock
);
8762 /* Cancel all the IOCBs from the completions list */
8763 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
8768 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
8769 * @phba: pointer to lpfc hba data structure.
8771 * This routine aborts all the IOCBs currently on the driver internal
8772 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
8773 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
8774 * list, removes IOCBs off the list, set the status feild to
8775 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
8778 void lpfc_fabric_abort_hba(struct lpfc_hba
*phba
)
8780 LIST_HEAD(completions
);
8782 spin_lock_irq(&phba
->hbalock
);
8783 list_splice_init(&phba
->fabric_iocb_list
, &completions
);
8784 spin_unlock_irq(&phba
->hbalock
);
8786 /* Cancel all the IOCBs from the completions list */
8787 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
8792 * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport
8793 * @vport: pointer to lpfc vport data structure.
8795 * This routine is invoked by the vport cleanup for deletions and the cleanup
8796 * for an ndlp on removal.
8799 lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport
*vport
)
8801 struct lpfc_hba
*phba
= vport
->phba
;
8802 struct lpfc_sglq
*sglq_entry
= NULL
, *sglq_next
= NULL
;
8803 unsigned long iflag
= 0;
8805 spin_lock_irqsave(&phba
->hbalock
, iflag
);
8806 spin_lock(&phba
->sli4_hba
.abts_sgl_list_lock
);
8807 list_for_each_entry_safe(sglq_entry
, sglq_next
,
8808 &phba
->sli4_hba
.lpfc_abts_els_sgl_list
, list
) {
8809 if (sglq_entry
->ndlp
&& sglq_entry
->ndlp
->vport
== vport
)
8810 sglq_entry
->ndlp
= NULL
;
8812 spin_unlock(&phba
->sli4_hba
.abts_sgl_list_lock
);
8813 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
8818 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
8819 * @phba: pointer to lpfc hba data structure.
8820 * @axri: pointer to the els xri abort wcqe structure.
8822 * This routine is invoked by the worker thread to process a SLI4 slow-path
8826 lpfc_sli4_els_xri_aborted(struct lpfc_hba
*phba
,
8827 struct sli4_wcqe_xri_aborted
*axri
)
8829 uint16_t xri
= bf_get(lpfc_wcqe_xa_xri
, axri
);
8830 uint16_t rxid
= bf_get(lpfc_wcqe_xa_remote_xid
, axri
);
8833 struct lpfc_sglq
*sglq_entry
= NULL
, *sglq_next
= NULL
;
8834 unsigned long iflag
= 0;
8835 struct lpfc_nodelist
*ndlp
;
8836 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
8838 spin_lock_irqsave(&phba
->hbalock
, iflag
);
8839 spin_lock(&phba
->sli4_hba
.abts_sgl_list_lock
);
8840 list_for_each_entry_safe(sglq_entry
, sglq_next
,
8841 &phba
->sli4_hba
.lpfc_abts_els_sgl_list
, list
) {
8842 if (sglq_entry
->sli4_xritag
== xri
) {
8843 list_del(&sglq_entry
->list
);
8844 ndlp
= sglq_entry
->ndlp
;
8845 sglq_entry
->ndlp
= NULL
;
8846 spin_lock(&pring
->ring_lock
);
8847 list_add_tail(&sglq_entry
->list
,
8848 &phba
->sli4_hba
.lpfc_sgl_list
);
8849 sglq_entry
->state
= SGL_FREED
;
8850 spin_unlock(&pring
->ring_lock
);
8851 spin_unlock(&phba
->sli4_hba
.abts_sgl_list_lock
);
8852 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
8853 lpfc_set_rrq_active(phba
, ndlp
,
8854 sglq_entry
->sli4_lxritag
,
8857 /* Check if TXQ queue needs to be serviced */
8858 if (!(list_empty(&pring
->txq
)))
8859 lpfc_worker_wake_up(phba
);
8863 spin_unlock(&phba
->sli4_hba
.abts_sgl_list_lock
);
8864 lxri
= lpfc_sli4_xri_inrange(phba
, xri
);
8865 if (lxri
== NO_XRI
) {
8866 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
8869 spin_lock(&pring
->ring_lock
);
8870 sglq_entry
= __lpfc_get_active_sglq(phba
, lxri
);
8871 if (!sglq_entry
|| (sglq_entry
->sli4_xritag
!= xri
)) {
8872 spin_unlock(&pring
->ring_lock
);
8873 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
8876 sglq_entry
->state
= SGL_XRI_ABORTED
;
8877 spin_unlock(&pring
->ring_lock
);
8878 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
8882 /* lpfc_sli_abts_recover_port - Recover a port that failed a BLS_ABORT req.
8883 * @vport: pointer to virtual port object.
8884 * @ndlp: nodelist pointer for the impacted node.
8886 * The driver calls this routine in response to an SLI4 XRI ABORT CQE
8887 * or an SLI3 ASYNC_STATUS_CN event from the port. For either event,
8888 * the driver is required to send a LOGO to the remote node before it
8889 * attempts to recover its login to the remote node.
8892 lpfc_sli_abts_recover_port(struct lpfc_vport
*vport
,
8893 struct lpfc_nodelist
*ndlp
)
8895 struct Scsi_Host
*shost
;
8896 struct lpfc_hba
*phba
;
8897 unsigned long flags
= 0;
8899 shost
= lpfc_shost_from_vport(vport
);
8901 if (ndlp
->nlp_state
!= NLP_STE_MAPPED_NODE
) {
8902 lpfc_printf_log(phba
, KERN_INFO
,
8903 LOG_SLI
, "3093 No rport recovery needed. "
8904 "rport in state 0x%x\n", ndlp
->nlp_state
);
8907 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
8908 "3094 Start rport recovery on shost id 0x%x "
8909 "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x "
8911 shost
->host_no
, ndlp
->nlp_DID
,
8912 vport
->vpi
, ndlp
->nlp_rpi
, ndlp
->nlp_state
,
8915 * The rport is not responding. Remove the FCP-2 flag to prevent
8916 * an ADISC in the follow-up recovery code.
8918 spin_lock_irqsave(shost
->host_lock
, flags
);
8919 ndlp
->nlp_fcp_info
&= ~NLP_FCP_2_DEVICE
;
8920 spin_unlock_irqrestore(shost
->host_lock
, flags
);
8921 lpfc_issue_els_logo(vport
, ndlp
, 0);
8922 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_LOGO_ISSUE
);