1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2017-2018 Broadcom. All Rights Reserved. The term *
5 * “Broadcom” refers to Broadcom Limited and/or its subsidiaries. *
6 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
7 * EMULEX and SLI are trademarks of Emulex. *
9 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
11 * This program is free software; you can redistribute it and/or *
12 * modify it under the terms of version 2 of the GNU General *
13 * Public License as published by the Free Software Foundation. *
14 * This program is distributed in the hope that it will be useful. *
15 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
16 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
17 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
18 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
19 * TO BE LEGALLY INVALID. See the GNU General Public License for *
20 * more details, a copy of which can be found in the file COPYING *
21 * included with this package. *
22 *******************************************************************/
23 /* See Fibre Channel protocol T11 FC-LS for details */
24 #include <linux/blkdev.h>
25 #include <linux/pci.h>
26 #include <linux/slab.h>
27 #include <linux/interrupt.h>
29 #include <scsi/scsi.h>
30 #include <scsi/scsi_device.h>
31 #include <scsi/scsi_host.h>
32 #include <scsi/scsi_transport_fc.h>
37 #include "lpfc_sli4.h"
39 #include "lpfc_disc.h"
40 #include "lpfc_scsi.h"
42 #include "lpfc_logmsg.h"
43 #include "lpfc_crtn.h"
44 #include "lpfc_vport.h"
45 #include "lpfc_debugfs.h"
47 static int lpfc_els_retry(struct lpfc_hba
*, struct lpfc_iocbq
*,
49 static void lpfc_cmpl_fabric_iocb(struct lpfc_hba
*, struct lpfc_iocbq
*,
51 static void lpfc_fabric_abort_vport(struct lpfc_vport
*vport
);
52 static int lpfc_issue_els_fdisc(struct lpfc_vport
*vport
,
53 struct lpfc_nodelist
*ndlp
, uint8_t retry
);
54 static int lpfc_issue_fabric_iocb(struct lpfc_hba
*phba
,
55 struct lpfc_iocbq
*iocb
);
57 static int lpfc_max_els_tries
= 3;
60 * lpfc_els_chk_latt - Check host link attention event for a vport
61 * @vport: pointer to a host virtual N_Port data structure.
63 * This routine checks whether there is an outstanding host link
64 * attention event during the discovery process with the @vport. It is done
65 * by reading the HBA's Host Attention (HA) register. If there is any host
66 * link attention events during this @vport's discovery process, the @vport
67 * shall be marked as FC_ABORT_DISCOVERY, a host link attention clear shall
68 * be issued if the link state is not already in host link cleared state,
69 * and a return code shall indicate whether the host link attention event
72 * Note that, if either the host link is in state LPFC_LINK_DOWN or @vport
73 * state in LPFC_VPORT_READY, the request for checking host link attention
74 * event will be ignored and a return code shall indicate no host link
75 * attention event had happened.
78 * 0 - no host link attention event happened
79 * 1 - host link attention event happened
82 lpfc_els_chk_latt(struct lpfc_vport
*vport
)
84 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
85 struct lpfc_hba
*phba
= vport
->phba
;
88 if (vport
->port_state
>= LPFC_VPORT_READY
||
89 phba
->link_state
== LPFC_LINK_DOWN
||
90 phba
->sli_rev
> LPFC_SLI_REV3
)
93 /* Read the HBA Host Attention Register */
94 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
97 if (!(ha_copy
& HA_LATT
))
100 /* Pending Link Event during Discovery */
101 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
102 "0237 Pending Link Event during "
103 "Discovery: State x%x\n",
104 phba
->pport
->port_state
);
106 /* CLEAR_LA should re-enable link attention events and
107 * we should then immediately take a LATT event. The
108 * LATT processing should call lpfc_linkdown() which
109 * will cleanup any left over in-progress discovery
112 spin_lock_irq(shost
->host_lock
);
113 vport
->fc_flag
|= FC_ABORT_DISCOVERY
;
114 spin_unlock_irq(shost
->host_lock
);
116 if (phba
->link_state
!= LPFC_CLEAR_LA
)
117 lpfc_issue_clear_la(phba
, vport
);
123 * lpfc_prep_els_iocb - Allocate and prepare a lpfc iocb data structure
124 * @vport: pointer to a host virtual N_Port data structure.
125 * @expectRsp: flag indicating whether response is expected.
126 * @cmdSize: size of the ELS command.
127 * @retry: number of retries to the command IOCB when it fails.
128 * @ndlp: pointer to a node-list data structure.
129 * @did: destination identifier.
130 * @elscmd: the ELS command code.
132 * This routine is used for allocating a lpfc-IOCB data structure from
133 * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters
134 * passed into the routine for discovery state machine to issue an Extended
135 * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation
136 * and preparation routine that is used by all the discovery state machine
137 * routines and the ELS command-specific fields will be later set up by
138 * the individual discovery machine routines after calling this routine
139 * allocating and preparing a generic IOCB data structure. It fills in the
140 * Buffer Descriptor Entries (BDEs), allocates buffers for both command
141 * payload and response payload (if expected). The reference count on the
142 * ndlp is incremented by 1 and the reference to the ndlp is put into
143 * context1 of the IOCB data structure for this IOCB to hold the ndlp
144 * reference for the command's callback function to access later.
147 * Pointer to the newly allocated/prepared els iocb data structure
148 * NULL - when els iocb data structure allocation/preparation failed
151 lpfc_prep_els_iocb(struct lpfc_vport
*vport
, uint8_t expectRsp
,
152 uint16_t cmdSize
, uint8_t retry
,
153 struct lpfc_nodelist
*ndlp
, uint32_t did
,
156 struct lpfc_hba
*phba
= vport
->phba
;
157 struct lpfc_iocbq
*elsiocb
;
158 struct lpfc_dmabuf
*pcmd
, *prsp
, *pbuflist
;
159 struct ulp_bde64
*bpl
;
163 if (!lpfc_is_link_up(phba
))
166 /* Allocate buffer for command iocb */
167 elsiocb
= lpfc_sli_get_iocbq(phba
);
173 * If this command is for fabric controller and HBA running
174 * in FIP mode send FLOGI, FDISC and LOGO as FIP frames.
176 if ((did
== Fabric_DID
) &&
177 (phba
->hba_flag
& HBA_FIP_SUPPORT
) &&
178 ((elscmd
== ELS_CMD_FLOGI
) ||
179 (elscmd
== ELS_CMD_FDISC
) ||
180 (elscmd
== ELS_CMD_LOGO
)))
183 elsiocb
->iocb_flag
|=
184 ((LPFC_ELS_ID_FLOGI
<< LPFC_FIP_ELS_ID_SHIFT
)
185 & LPFC_FIP_ELS_ID_MASK
);
188 elsiocb
->iocb_flag
|=
189 ((LPFC_ELS_ID_FDISC
<< LPFC_FIP_ELS_ID_SHIFT
)
190 & LPFC_FIP_ELS_ID_MASK
);
193 elsiocb
->iocb_flag
|=
194 ((LPFC_ELS_ID_LOGO
<< LPFC_FIP_ELS_ID_SHIFT
)
195 & LPFC_FIP_ELS_ID_MASK
);
199 elsiocb
->iocb_flag
&= ~LPFC_FIP_ELS_ID_MASK
;
201 icmd
= &elsiocb
->iocb
;
203 /* fill in BDEs for command */
204 /* Allocate buffer for command payload */
205 pcmd
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
207 pcmd
->virt
= lpfc_mbuf_alloc(phba
, MEM_PRI
, &pcmd
->phys
);
208 if (!pcmd
|| !pcmd
->virt
)
209 goto els_iocb_free_pcmb_exit
;
211 INIT_LIST_HEAD(&pcmd
->list
);
213 /* Allocate buffer for response payload */
215 prsp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
217 prsp
->virt
= lpfc_mbuf_alloc(phba
, MEM_PRI
,
219 if (!prsp
|| !prsp
->virt
)
220 goto els_iocb_free_prsp_exit
;
221 INIT_LIST_HEAD(&prsp
->list
);
225 /* Allocate buffer for Buffer ptr list */
226 pbuflist
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
228 pbuflist
->virt
= lpfc_mbuf_alloc(phba
, MEM_PRI
,
230 if (!pbuflist
|| !pbuflist
->virt
)
231 goto els_iocb_free_pbuf_exit
;
233 INIT_LIST_HEAD(&pbuflist
->list
);
236 icmd
->un
.elsreq64
.bdl
.addrHigh
= putPaddrHigh(pbuflist
->phys
);
237 icmd
->un
.elsreq64
.bdl
.addrLow
= putPaddrLow(pbuflist
->phys
);
238 icmd
->un
.elsreq64
.bdl
.bdeFlags
= BUFF_TYPE_BLP_64
;
239 icmd
->un
.elsreq64
.bdl
.bdeSize
= (2 * sizeof(struct ulp_bde64
));
241 icmd
->un
.elsreq64
.remoteID
= did
; /* DID */
242 icmd
->ulpCommand
= CMD_ELS_REQUEST64_CR
;
243 if (elscmd
== ELS_CMD_FLOGI
)
244 icmd
->ulpTimeout
= FF_DEF_RATOV
* 2;
245 else if (elscmd
== ELS_CMD_LOGO
)
246 icmd
->ulpTimeout
= phba
->fc_ratov
;
248 icmd
->ulpTimeout
= phba
->fc_ratov
* 2;
250 icmd
->un
.xseq64
.bdl
.addrHigh
= putPaddrHigh(pbuflist
->phys
);
251 icmd
->un
.xseq64
.bdl
.addrLow
= putPaddrLow(pbuflist
->phys
);
252 icmd
->un
.xseq64
.bdl
.bdeFlags
= BUFF_TYPE_BLP_64
;
253 icmd
->un
.xseq64
.bdl
.bdeSize
= sizeof(struct ulp_bde64
);
254 icmd
->un
.xseq64
.xmit_els_remoteID
= did
; /* DID */
255 icmd
->ulpCommand
= CMD_XMIT_ELS_RSP64_CX
;
257 icmd
->ulpBdeCount
= 1;
259 icmd
->ulpClass
= CLASS3
;
262 * If we have NPIV enabled, we want to send ELS traffic by VPI.
263 * For SLI4, since the driver controls VPIs we also want to include
264 * all ELS pt2pt protocol traffic as well.
266 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) ||
267 ((phba
->sli_rev
== LPFC_SLI_REV4
) &&
268 (vport
->fc_flag
& FC_PT2PT
))) {
271 icmd
->un
.elsreq64
.myID
= vport
->fc_myDID
;
273 /* For ELS_REQUEST64_CR, use the VPI by default */
274 icmd
->ulpContext
= phba
->vpi_ids
[vport
->vpi
];
278 /* The CT field must be 0=INVALID_RPI for the ECHO cmd */
279 if (elscmd
== ELS_CMD_ECHO
)
280 icmd
->ulpCt_l
= 0; /* context = invalid RPI */
282 icmd
->ulpCt_l
= 1; /* context = VPI */
285 bpl
= (struct ulp_bde64
*) pbuflist
->virt
;
286 bpl
->addrLow
= le32_to_cpu(putPaddrLow(pcmd
->phys
));
287 bpl
->addrHigh
= le32_to_cpu(putPaddrHigh(pcmd
->phys
));
288 bpl
->tus
.f
.bdeSize
= cmdSize
;
289 bpl
->tus
.f
.bdeFlags
= 0;
290 bpl
->tus
.w
= le32_to_cpu(bpl
->tus
.w
);
294 bpl
->addrLow
= le32_to_cpu(putPaddrLow(prsp
->phys
));
295 bpl
->addrHigh
= le32_to_cpu(putPaddrHigh(prsp
->phys
));
296 bpl
->tus
.f
.bdeSize
= FCELSSIZE
;
297 bpl
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64
;
298 bpl
->tus
.w
= le32_to_cpu(bpl
->tus
.w
);
301 /* prevent preparing iocb with NULL ndlp reference */
302 elsiocb
->context1
= lpfc_nlp_get(ndlp
);
303 if (!elsiocb
->context1
)
304 goto els_iocb_free_pbuf_exit
;
305 elsiocb
->context2
= pcmd
;
306 elsiocb
->context3
= pbuflist
;
307 elsiocb
->retry
= retry
;
308 elsiocb
->vport
= vport
;
309 elsiocb
->drvrTimeout
= (phba
->fc_ratov
<< 1) + LPFC_DRVR_TIMEOUT
;
312 list_add(&prsp
->list
, &pcmd
->list
);
315 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
316 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
317 "0116 Xmit ELS command x%x to remote "
318 "NPORT x%x I/O tag: x%x, port state:x%x"
320 elscmd
, did
, elsiocb
->iotag
,
324 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
325 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
326 "0117 Xmit ELS response x%x to remote "
327 "NPORT x%x I/O tag: x%x, size: x%x "
328 "port_state x%x fc_flag x%x\n",
329 elscmd
, ndlp
->nlp_DID
, elsiocb
->iotag
,
330 cmdSize
, vport
->port_state
,
335 els_iocb_free_pbuf_exit
:
337 lpfc_mbuf_free(phba
, prsp
->virt
, prsp
->phys
);
340 els_iocb_free_prsp_exit
:
341 lpfc_mbuf_free(phba
, pcmd
->virt
, pcmd
->phys
);
344 els_iocb_free_pcmb_exit
:
346 lpfc_sli_release_iocbq(phba
, elsiocb
);
351 * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport
352 * @vport: pointer to a host virtual N_Port data structure.
354 * This routine issues a fabric registration login for a @vport. An
355 * active ndlp node with Fabric_DID must already exist for this @vport.
356 * The routine invokes two mailbox commands to carry out fabric registration
357 * login through the HBA firmware: the first mailbox command requests the
358 * HBA to perform link configuration for the @vport; and the second mailbox
359 * command requests the HBA to perform the actual fabric registration login
363 * 0 - successfully issued fabric registration login for @vport
364 * -ENXIO -- failed to issue fabric registration login for @vport
367 lpfc_issue_fabric_reglogin(struct lpfc_vport
*vport
)
369 struct lpfc_hba
*phba
= vport
->phba
;
371 struct lpfc_dmabuf
*mp
;
372 struct lpfc_nodelist
*ndlp
;
373 struct serv_parm
*sp
;
377 sp
= &phba
->fc_fabparam
;
378 ndlp
= lpfc_findnode_did(vport
, Fabric_DID
);
379 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
)) {
384 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
390 vport
->port_state
= LPFC_FABRIC_CFG_LINK
;
391 lpfc_config_link(phba
, mbox
);
392 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
395 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
396 if (rc
== MBX_NOT_FINISHED
) {
401 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
406 rc
= lpfc_reg_rpi(phba
, vport
->vpi
, Fabric_DID
, (uint8_t *)sp
, mbox
,
413 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_fabric_reg_login
;
415 /* increment the reference count on ndlp to hold reference
416 * for the callback routine.
418 mbox
->context2
= lpfc_nlp_get(ndlp
);
420 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
421 if (rc
== MBX_NOT_FINISHED
) {
423 goto fail_issue_reg_login
;
428 fail_issue_reg_login
:
429 /* decrement the reference count on ndlp just incremented
430 * for the failed mbox command.
433 mp
= (struct lpfc_dmabuf
*) mbox
->context1
;
434 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
437 mempool_free(mbox
, phba
->mbox_mem_pool
);
440 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
441 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
442 "0249 Cannot issue Register Fabric login: Err %d\n", err
);
447 * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login
448 * @vport: pointer to a host virtual N_Port data structure.
450 * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for
451 * the @vport. This mailbox command is necessary for SLI4 port only.
454 * 0 - successfully issued REG_VFI for @vport
455 * A failure code otherwise.
458 lpfc_issue_reg_vfi(struct lpfc_vport
*vport
)
460 struct lpfc_hba
*phba
= vport
->phba
;
461 LPFC_MBOXQ_t
*mboxq
= NULL
;
462 struct lpfc_nodelist
*ndlp
;
463 struct lpfc_dmabuf
*dmabuf
= NULL
;
466 /* move forward in case of SLI4 FC port loopback test and pt2pt mode */
467 if ((phba
->sli_rev
== LPFC_SLI_REV4
) &&
468 !(phba
->link_flag
& LS_LOOPBACK_MODE
) &&
469 !(vport
->fc_flag
& FC_PT2PT
)) {
470 ndlp
= lpfc_findnode_did(vport
, Fabric_DID
);
471 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
)) {
477 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
483 /* Supply CSP's only if we are fabric connect or pt-to-pt connect */
484 if ((vport
->fc_flag
& FC_FABRIC
) || (vport
->fc_flag
& FC_PT2PT
)) {
485 dmabuf
= kzalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
490 dmabuf
->virt
= lpfc_mbuf_alloc(phba
, MEM_PRI
, &dmabuf
->phys
);
495 memcpy(dmabuf
->virt
, &phba
->fc_fabparam
,
496 sizeof(struct serv_parm
));
499 vport
->port_state
= LPFC_FABRIC_CFG_LINK
;
501 lpfc_reg_vfi(mboxq
, vport
, dmabuf
->phys
);
503 lpfc_reg_vfi(mboxq
, vport
, 0);
505 mboxq
->mbox_cmpl
= lpfc_mbx_cmpl_reg_vfi
;
506 mboxq
->vport
= vport
;
507 mboxq
->context1
= dmabuf
;
508 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
509 if (rc
== MBX_NOT_FINISHED
) {
517 mempool_free(mboxq
, phba
->mbox_mem_pool
);
520 lpfc_mbuf_free(phba
, dmabuf
->virt
, dmabuf
->phys
);
524 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
525 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
526 "0289 Issue Register VFI failed: Err %d\n", rc
);
531 * lpfc_issue_unreg_vfi - Unregister VFI for this vport's fabric login
532 * @vport: pointer to a host virtual N_Port data structure.
534 * This routine issues a UNREG_VFI mailbox with the vfi, vpi, fcfi triplet for
535 * the @vport. This mailbox command is necessary for SLI4 port only.
538 * 0 - successfully issued REG_VFI for @vport
539 * A failure code otherwise.
542 lpfc_issue_unreg_vfi(struct lpfc_vport
*vport
)
544 struct lpfc_hba
*phba
= vport
->phba
;
545 struct Scsi_Host
*shost
;
549 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
551 lpfc_printf_log(phba
, KERN_ERR
, LOG_DISCOVERY
|LOG_MBOX
,
552 "2556 UNREG_VFI mbox allocation failed"
553 "HBA state x%x\n", phba
->pport
->port_state
);
557 lpfc_unreg_vfi(mboxq
, vport
);
558 mboxq
->vport
= vport
;
559 mboxq
->mbox_cmpl
= lpfc_unregister_vfi_cmpl
;
561 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
562 if (rc
== MBX_NOT_FINISHED
) {
563 lpfc_printf_log(phba
, KERN_ERR
, LOG_DISCOVERY
|LOG_MBOX
,
564 "2557 UNREG_VFI issue mbox failed rc x%x "
566 rc
, phba
->pport
->port_state
);
567 mempool_free(mboxq
, phba
->mbox_mem_pool
);
571 shost
= lpfc_shost_from_vport(vport
);
572 spin_lock_irq(shost
->host_lock
);
573 vport
->fc_flag
&= ~FC_VFI_REGISTERED
;
574 spin_unlock_irq(shost
->host_lock
);
579 * lpfc_check_clean_addr_bit - Check whether assigned FCID is clean.
580 * @vport: pointer to a host virtual N_Port data structure.
581 * @sp: pointer to service parameter data structure.
583 * This routine is called from FLOGI/FDISC completion handler functions.
584 * lpfc_check_clean_addr_bit return 1 when FCID/Fabric portname/ Fabric
585 * node nodename is changed in the completion service parameter else return
586 * 0. This function also set flag in the vport data structure to delay
587 * NP_Port discovery after the FLOGI/FDISC completion if Clean address bit
588 * in FLOGI/FDISC response is cleared and FCID/Fabric portname/ Fabric
589 * node nodename is changed in the completion service parameter.
592 * 0 - FCID and Fabric Nodename and Fabric portname is not changed.
593 * 1 - FCID or Fabric Nodename or Fabric portname is changed.
597 lpfc_check_clean_addr_bit(struct lpfc_vport
*vport
,
598 struct serv_parm
*sp
)
600 struct lpfc_hba
*phba
= vport
->phba
;
601 uint8_t fabric_param_changed
= 0;
602 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
604 if ((vport
->fc_prevDID
!= vport
->fc_myDID
) ||
605 memcmp(&vport
->fabric_portname
, &sp
->portName
,
606 sizeof(struct lpfc_name
)) ||
607 memcmp(&vport
->fabric_nodename
, &sp
->nodeName
,
608 sizeof(struct lpfc_name
)) ||
609 (vport
->vport_flag
& FAWWPN_PARAM_CHG
)) {
610 fabric_param_changed
= 1;
611 vport
->vport_flag
&= ~FAWWPN_PARAM_CHG
;
614 * Word 1 Bit 31 in common service parameter is overloaded.
615 * Word 1 Bit 31 in FLOGI request is multiple NPort request
616 * Word 1 Bit 31 in FLOGI response is clean address bit
618 * If fabric parameter is changed and clean address bit is
619 * cleared delay nport discovery if
620 * - vport->fc_prevDID != 0 (not initial discovery) OR
621 * - lpfc_delay_discovery module parameter is set.
623 if (fabric_param_changed
&& !sp
->cmn
.clean_address_bit
&&
624 (vport
->fc_prevDID
|| phba
->cfg_delay_discovery
)) {
625 spin_lock_irq(shost
->host_lock
);
626 vport
->fc_flag
|= FC_DISC_DELAYED
;
627 spin_unlock_irq(shost
->host_lock
);
630 return fabric_param_changed
;
635 * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port
636 * @vport: pointer to a host virtual N_Port data structure.
637 * @ndlp: pointer to a node-list data structure.
638 * @sp: pointer to service parameter data structure.
639 * @irsp: pointer to the IOCB within the lpfc response IOCB.
641 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
642 * function to handle the completion of a Fabric Login (FLOGI) into a fabric
643 * port in a fabric topology. It properly sets up the parameters to the @ndlp
644 * from the IOCB response. It also check the newly assigned N_Port ID to the
645 * @vport against the previously assigned N_Port ID. If it is different from
646 * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
647 * is invoked on all the remaining nodes with the @vport to unregister the
648 * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
649 * is invoked to register login to the fabric.
652 * 0 - Success (currently, always return 0)
655 lpfc_cmpl_els_flogi_fabric(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
656 struct serv_parm
*sp
, IOCB_t
*irsp
)
658 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
659 struct lpfc_hba
*phba
= vport
->phba
;
660 struct lpfc_nodelist
*np
;
661 struct lpfc_nodelist
*next_np
;
662 uint8_t fabric_param_changed
;
664 spin_lock_irq(shost
->host_lock
);
665 vport
->fc_flag
|= FC_FABRIC
;
666 spin_unlock_irq(shost
->host_lock
);
668 phba
->fc_edtov
= be32_to_cpu(sp
->cmn
.e_d_tov
);
669 if (sp
->cmn
.edtovResolution
) /* E_D_TOV ticks are in nanoseconds */
670 phba
->fc_edtov
= (phba
->fc_edtov
+ 999999) / 1000000;
672 phba
->fc_edtovResol
= sp
->cmn
.edtovResolution
;
673 phba
->fc_ratov
= (be32_to_cpu(sp
->cmn
.w2
.r_a_tov
) + 999) / 1000;
675 if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) {
676 spin_lock_irq(shost
->host_lock
);
677 vport
->fc_flag
|= FC_PUBLIC_LOOP
;
678 spin_unlock_irq(shost
->host_lock
);
681 vport
->fc_myDID
= irsp
->un
.ulpWord
[4] & Mask_DID
;
682 memcpy(&ndlp
->nlp_portname
, &sp
->portName
, sizeof(struct lpfc_name
));
683 memcpy(&ndlp
->nlp_nodename
, &sp
->nodeName
, sizeof(struct lpfc_name
));
684 ndlp
->nlp_class_sup
= 0;
685 if (sp
->cls1
.classValid
)
686 ndlp
->nlp_class_sup
|= FC_COS_CLASS1
;
687 if (sp
->cls2
.classValid
)
688 ndlp
->nlp_class_sup
|= FC_COS_CLASS2
;
689 if (sp
->cls3
.classValid
)
690 ndlp
->nlp_class_sup
|= FC_COS_CLASS3
;
691 if (sp
->cls4
.classValid
)
692 ndlp
->nlp_class_sup
|= FC_COS_CLASS4
;
693 ndlp
->nlp_maxframe
= ((sp
->cmn
.bbRcvSizeMsb
& 0x0F) << 8) |
694 sp
->cmn
.bbRcvSizeLsb
;
696 fabric_param_changed
= lpfc_check_clean_addr_bit(vport
, sp
);
697 if (fabric_param_changed
) {
698 /* Reset FDMI attribute masks based on config parameter */
699 if (phba
->cfg_enable_SmartSAN
||
700 (phba
->cfg_fdmi_on
== LPFC_FDMI_SUPPORT
)) {
701 /* Setup appropriate attribute masks */
702 vport
->fdmi_hba_mask
= LPFC_FDMI2_HBA_ATTR
;
703 if (phba
->cfg_enable_SmartSAN
)
704 vport
->fdmi_port_mask
= LPFC_FDMI2_SMART_ATTR
;
706 vport
->fdmi_port_mask
= LPFC_FDMI2_PORT_ATTR
;
708 vport
->fdmi_hba_mask
= 0;
709 vport
->fdmi_port_mask
= 0;
713 memcpy(&vport
->fabric_portname
, &sp
->portName
,
714 sizeof(struct lpfc_name
));
715 memcpy(&vport
->fabric_nodename
, &sp
->nodeName
,
716 sizeof(struct lpfc_name
));
717 memcpy(&phba
->fc_fabparam
, sp
, sizeof(struct serv_parm
));
719 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) {
720 if (sp
->cmn
.response_multiple_NPort
) {
721 lpfc_printf_vlog(vport
, KERN_WARNING
,
723 "1816 FLOGI NPIV supported, "
724 "response data 0x%x\n",
725 sp
->cmn
.response_multiple_NPort
);
726 spin_lock_irq(&phba
->hbalock
);
727 phba
->link_flag
|= LS_NPIV_FAB_SUPPORTED
;
728 spin_unlock_irq(&phba
->hbalock
);
730 /* Because we asked f/w for NPIV it still expects us
731 to call reg_vnpid atleast for the physcial host */
732 lpfc_printf_vlog(vport
, KERN_WARNING
,
734 "1817 Fabric does not support NPIV "
735 "- configuring single port mode.\n");
736 spin_lock_irq(&phba
->hbalock
);
737 phba
->link_flag
&= ~LS_NPIV_FAB_SUPPORTED
;
738 spin_unlock_irq(&phba
->hbalock
);
743 * For FC we need to do some special processing because of the SLI
744 * Port's default settings of the Common Service Parameters.
746 if ((phba
->sli_rev
== LPFC_SLI_REV4
) &&
747 (phba
->sli4_hba
.lnk_info
.lnk_tp
== LPFC_LNK_TYPE_FC
)) {
748 /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */
749 if (fabric_param_changed
)
750 lpfc_unregister_fcf_prep(phba
);
752 /* This should just update the VFI CSPs*/
753 if (vport
->fc_flag
& FC_VFI_REGISTERED
)
754 lpfc_issue_reg_vfi(vport
);
757 if (fabric_param_changed
&&
758 !(vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
)) {
760 /* If our NportID changed, we need to ensure all
761 * remaining NPORTs get unreg_login'ed.
763 list_for_each_entry_safe(np
, next_np
,
764 &vport
->fc_nodes
, nlp_listp
) {
765 if (!NLP_CHK_NODE_ACT(np
))
767 if ((np
->nlp_state
!= NLP_STE_NPR_NODE
) ||
768 !(np
->nlp_flag
& NLP_NPR_ADISC
))
770 spin_lock_irq(shost
->host_lock
);
771 np
->nlp_flag
&= ~NLP_NPR_ADISC
;
772 spin_unlock_irq(shost
->host_lock
);
773 lpfc_unreg_rpi(vport
, np
);
775 lpfc_cleanup_pending_mbox(vport
);
777 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
778 lpfc_sli4_unreg_all_rpis(vport
);
779 lpfc_mbx_unreg_vpi(vport
);
780 spin_lock_irq(shost
->host_lock
);
781 vport
->fc_flag
|= FC_VPORT_NEEDS_INIT_VPI
;
782 spin_unlock_irq(shost
->host_lock
);
786 * For SLI3 and SLI4, the VPI needs to be reregistered in
787 * response to this fabric parameter change event.
789 spin_lock_irq(shost
->host_lock
);
790 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
791 spin_unlock_irq(shost
->host_lock
);
792 } else if ((phba
->sli_rev
== LPFC_SLI_REV4
) &&
793 !(vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
)) {
795 * Driver needs to re-reg VPI in order for f/w
796 * to update the MAC address.
798 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
799 lpfc_register_new_vport(phba
, vport
, ndlp
);
803 if (phba
->sli_rev
< LPFC_SLI_REV4
) {
804 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_REG_LOGIN_ISSUE
);
805 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
&&
806 vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
)
807 lpfc_register_new_vport(phba
, vport
, ndlp
);
809 lpfc_issue_fabric_reglogin(vport
);
811 ndlp
->nlp_type
|= NLP_FABRIC
;
812 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
813 if ((!(vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
)) &&
814 (vport
->vpi_state
& LPFC_VPI_REGISTERED
)) {
815 lpfc_start_fdiscs(phba
);
816 lpfc_do_scr_ns_plogi(phba
, vport
);
817 } else if (vport
->fc_flag
& FC_VFI_REGISTERED
)
818 lpfc_issue_init_vpi(vport
);
820 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
821 "3135 Need register VFI: (x%x/%x)\n",
822 vport
->fc_prevDID
, vport
->fc_myDID
);
823 lpfc_issue_reg_vfi(vport
);
830 * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
831 * @vport: pointer to a host virtual N_Port data structure.
832 * @ndlp: pointer to a node-list data structure.
833 * @sp: pointer to service parameter data structure.
835 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
836 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
837 * in a point-to-point topology. First, the @vport's N_Port Name is compared
838 * with the received N_Port Name: if the @vport's N_Port Name is greater than
839 * the received N_Port Name lexicographically, this node shall assign local
840 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
841 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
842 * this node shall just wait for the remote node to issue PLOGI and assign
850 lpfc_cmpl_els_flogi_nport(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
851 struct serv_parm
*sp
)
853 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
854 struct lpfc_hba
*phba
= vport
->phba
;
858 spin_lock_irq(shost
->host_lock
);
859 vport
->fc_flag
&= ~(FC_FABRIC
| FC_PUBLIC_LOOP
);
860 vport
->fc_flag
|= FC_PT2PT
;
861 spin_unlock_irq(shost
->host_lock
);
863 /* If we are pt2pt with another NPort, force NPIV off! */
864 phba
->sli3_options
&= ~LPFC_SLI3_NPIV_ENABLED
;
866 /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */
867 if ((phba
->sli_rev
== LPFC_SLI_REV4
) && phba
->fc_topology_changed
) {
868 lpfc_unregister_fcf_prep(phba
);
870 spin_lock_irq(shost
->host_lock
);
871 vport
->fc_flag
&= ~FC_VFI_REGISTERED
;
872 spin_unlock_irq(shost
->host_lock
);
873 phba
->fc_topology_changed
= 0;
876 rc
= memcmp(&vport
->fc_portname
, &sp
->portName
,
877 sizeof(vport
->fc_portname
));
880 /* This side will initiate the PLOGI */
881 spin_lock_irq(shost
->host_lock
);
882 vport
->fc_flag
|= FC_PT2PT_PLOGI
;
883 spin_unlock_irq(shost
->host_lock
);
886 * N_Port ID cannot be 0, set our Id to LocalID
887 * the other side will be RemoteID.
892 vport
->fc_myDID
= PT2PT_LocalID
;
894 /* Decrement ndlp reference count indicating that ndlp can be
895 * safely released when other references to it are done.
899 ndlp
= lpfc_findnode_did(vport
, PT2PT_RemoteID
);
902 * Cannot find existing Fabric ndlp, so allocate a
905 ndlp
= lpfc_nlp_init(vport
, PT2PT_RemoteID
);
908 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
909 ndlp
= lpfc_enable_node(vport
, ndlp
,
910 NLP_STE_UNUSED_NODE
);
915 memcpy(&ndlp
->nlp_portname
, &sp
->portName
,
916 sizeof(struct lpfc_name
));
917 memcpy(&ndlp
->nlp_nodename
, &sp
->nodeName
,
918 sizeof(struct lpfc_name
));
919 /* Set state will put ndlp onto node list if not already done */
920 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
921 spin_lock_irq(shost
->host_lock
);
922 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
923 spin_unlock_irq(shost
->host_lock
);
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
);
939 /* This side will wait for the PLOGI, decrement ndlp reference
940 * count indicating that ndlp can be released when other
941 * references to it are done.
945 /* Start discovery - this should just do CLEAR_LA */
946 lpfc_disc_start(vport
);
955 * lpfc_cmpl_els_flogi - Completion callback function for flogi
956 * @phba: pointer to lpfc hba data structure.
957 * @cmdiocb: pointer to lpfc command iocb data structure.
958 * @rspiocb: pointer to lpfc response iocb data structure.
960 * This routine is the top-level completion callback function for issuing
961 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
962 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
963 * retry has been made (either immediately or delayed with lpfc_els_retry()
964 * returning 1), the command IOCB will be released and function returned.
965 * If the retry attempt has been given up (possibly reach the maximum
966 * number of retries), one additional decrement of ndlp reference shall be
967 * invoked before going out after releasing the command IOCB. This will
968 * actually release the remote node (Note, lpfc_els_free_iocb() will also
969 * invoke one decrement of ndlp reference count). If no error reported in
970 * the IOCB status, the command Port ID field is used to determine whether
971 * this is a point-to-point topology or a fabric topology: if the Port ID
972 * field is assigned, it is a fabric topology; otherwise, it is a
973 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
974 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
975 * specific topology completion conditions.
978 lpfc_cmpl_els_flogi(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
979 struct lpfc_iocbq
*rspiocb
)
981 struct lpfc_vport
*vport
= cmdiocb
->vport
;
982 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
983 IOCB_t
*irsp
= &rspiocb
->iocb
;
984 struct lpfc_nodelist
*ndlp
= cmdiocb
->context1
;
985 struct lpfc_dmabuf
*pcmd
= cmdiocb
->context2
, *prsp
;
986 struct serv_parm
*sp
;
990 /* Check to see if link went down during discovery */
991 if (lpfc_els_chk_latt(vport
)) {
992 /* One additional decrement on node reference count to
993 * trigger the release of the node
999 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1000 "FLOGI cmpl: status:x%x/x%x state:x%x",
1001 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1004 if (irsp
->ulpStatus
) {
1006 * In case of FIP mode, perform roundrobin FCF failover
1007 * due to new FCF discovery
1009 if ((phba
->hba_flag
& HBA_FIP_SUPPORT
) &&
1010 (phba
->fcf
.fcf_flag
& FCF_DISCOVERY
)) {
1011 if (phba
->link_state
< LPFC_LINK_UP
)
1012 goto stop_rr_fcf_flogi
;
1013 if ((phba
->fcoe_cvl_eventtag_attn
==
1014 phba
->fcoe_cvl_eventtag
) &&
1015 (irsp
->ulpStatus
== IOSTAT_LOCAL_REJECT
) &&
1016 ((irsp
->un
.ulpWord
[4] & IOERR_PARAM_MASK
) ==
1018 goto stop_rr_fcf_flogi
;
1020 phba
->fcoe_cvl_eventtag_attn
=
1021 phba
->fcoe_cvl_eventtag
;
1022 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FIP
| LOG_ELS
,
1023 "2611 FLOGI failed on FCF (x%x), "
1024 "status:x%x/x%x, tmo:x%x, perform "
1025 "roundrobin FCF failover\n",
1026 phba
->fcf
.current_rec
.fcf_indx
,
1027 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1029 lpfc_sli4_set_fcf_flogi_fail(phba
,
1030 phba
->fcf
.current_rec
.fcf_indx
);
1031 fcf_index
= lpfc_sli4_fcf_rr_next_index_get(phba
);
1032 rc
= lpfc_sli4_fcf_rr_next_proc(vport
, fcf_index
);
1039 if (!(irsp
->ulpStatus
== IOSTAT_LOCAL_REJECT
&&
1040 ((irsp
->un
.ulpWord
[4] & IOERR_PARAM_MASK
) ==
1041 IOERR_LOOP_OPEN_FAILURE
)))
1042 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1043 "2858 FLOGI failure Status:x%x/x%x "
1044 "TMO:x%x Data x%x x%x\n",
1045 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1046 irsp
->ulpTimeout
, phba
->hba_flag
,
1047 phba
->fcf
.fcf_flag
);
1049 /* Check for retry */
1050 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
))
1053 /* If this is not a loop open failure, bail out */
1054 if (!(irsp
->ulpStatus
== IOSTAT_LOCAL_REJECT
&&
1055 ((irsp
->un
.ulpWord
[4] & IOERR_PARAM_MASK
) ==
1056 IOERR_LOOP_OPEN_FAILURE
)))
1059 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_ELS
,
1060 "0150 FLOGI failure Status:x%x/x%x xri x%x TMO:x%x\n",
1061 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1062 cmdiocb
->sli4_xritag
, irsp
->ulpTimeout
);
1064 /* FLOGI failed, so there is no fabric */
1065 spin_lock_irq(shost
->host_lock
);
1066 vport
->fc_flag
&= ~(FC_FABRIC
| FC_PUBLIC_LOOP
);
1067 spin_unlock_irq(shost
->host_lock
);
1069 /* If private loop, then allow max outstanding els to be
1070 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
1071 * alpa map would take too long otherwise.
1073 if (phba
->alpa_map
[0] == 0)
1074 vport
->cfg_discovery_threads
= LPFC_MAX_DISC_THREADS
;
1075 if ((phba
->sli_rev
== LPFC_SLI_REV4
) &&
1076 (!(vport
->fc_flag
& FC_VFI_REGISTERED
) ||
1077 (vport
->fc_prevDID
!= vport
->fc_myDID
) ||
1078 phba
->fc_topology_changed
)) {
1079 if (vport
->fc_flag
& FC_VFI_REGISTERED
) {
1080 if (phba
->fc_topology_changed
) {
1081 lpfc_unregister_fcf_prep(phba
);
1082 spin_lock_irq(shost
->host_lock
);
1083 vport
->fc_flag
&= ~FC_VFI_REGISTERED
;
1084 spin_unlock_irq(shost
->host_lock
);
1085 phba
->fc_topology_changed
= 0;
1087 lpfc_sli4_unreg_all_rpis(vport
);
1091 /* Do not register VFI if the driver aborted FLOGI */
1092 if (!lpfc_error_lost_link(irsp
))
1093 lpfc_issue_reg_vfi(vport
);
1099 spin_lock_irq(shost
->host_lock
);
1100 vport
->fc_flag
&= ~FC_VPORT_CVL_RCVD
;
1101 vport
->fc_flag
&= ~FC_VPORT_LOGO_RCVD
;
1102 spin_unlock_irq(shost
->host_lock
);
1105 * The FLogI succeeded. Sync the data for the CPU before
1108 prsp
= list_get_first(&pcmd
->list
, struct lpfc_dmabuf
, list
);
1111 sp
= prsp
->virt
+ sizeof(uint32_t);
1113 /* FLOGI completes successfully */
1114 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
1115 "0101 FLOGI completes successfully, I/O tag:x%x, "
1116 "xri x%x Data: x%x x%x x%x x%x x%x %x\n",
1117 cmdiocb
->iotag
, cmdiocb
->sli4_xritag
,
1118 irsp
->un
.ulpWord
[4], sp
->cmn
.e_d_tov
,
1119 sp
->cmn
.w2
.r_a_tov
, sp
->cmn
.edtovResolution
,
1120 vport
->port_state
, vport
->fc_flag
);
1122 if (vport
->port_state
== LPFC_FLOGI
) {
1124 * If Common Service Parameters indicate Nport
1125 * we are point to point, if Fport we are Fabric.
1128 rc
= lpfc_cmpl_els_flogi_fabric(vport
, ndlp
, sp
, irsp
);
1129 else if (!(phba
->hba_flag
& HBA_FCOE_MODE
))
1130 rc
= lpfc_cmpl_els_flogi_nport(vport
, ndlp
, sp
);
1132 lpfc_printf_vlog(vport
, KERN_ERR
,
1134 "2831 FLOGI response with cleared Fabric "
1135 "bit fcf_index 0x%x "
1136 "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
1138 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
1139 phba
->fcf
.current_rec
.fcf_indx
,
1140 phba
->fcf
.current_rec
.switch_name
[0],
1141 phba
->fcf
.current_rec
.switch_name
[1],
1142 phba
->fcf
.current_rec
.switch_name
[2],
1143 phba
->fcf
.current_rec
.switch_name
[3],
1144 phba
->fcf
.current_rec
.switch_name
[4],
1145 phba
->fcf
.current_rec
.switch_name
[5],
1146 phba
->fcf
.current_rec
.switch_name
[6],
1147 phba
->fcf
.current_rec
.switch_name
[7],
1148 phba
->fcf
.current_rec
.fabric_name
[0],
1149 phba
->fcf
.current_rec
.fabric_name
[1],
1150 phba
->fcf
.current_rec
.fabric_name
[2],
1151 phba
->fcf
.current_rec
.fabric_name
[3],
1152 phba
->fcf
.current_rec
.fabric_name
[4],
1153 phba
->fcf
.current_rec
.fabric_name
[5],
1154 phba
->fcf
.current_rec
.fabric_name
[6],
1155 phba
->fcf
.current_rec
.fabric_name
[7]);
1157 spin_lock_irq(&phba
->hbalock
);
1158 phba
->fcf
.fcf_flag
&= ~FCF_DISCOVERY
;
1159 phba
->hba_flag
&= ~(FCF_RR_INPROG
| HBA_DEVLOSS_TMO
);
1160 spin_unlock_irq(&phba
->hbalock
);
1161 phba
->fcf
.fcf_redisc_attempted
= 0; /* reset */
1165 /* Mark the FCF discovery process done */
1166 if (phba
->hba_flag
& HBA_FIP_SUPPORT
)
1167 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_FIP
|
1169 "2769 FLOGI to FCF (x%x) "
1170 "completed successfully\n",
1171 phba
->fcf
.current_rec
.fcf_indx
);
1172 spin_lock_irq(&phba
->hbalock
);
1173 phba
->fcf
.fcf_flag
&= ~FCF_DISCOVERY
;
1174 phba
->hba_flag
&= ~(FCF_RR_INPROG
| HBA_DEVLOSS_TMO
);
1175 spin_unlock_irq(&phba
->hbalock
);
1176 phba
->fcf
.fcf_redisc_attempted
= 0; /* reset */
1182 spin_lock_irq(&phba
->hbalock
);
1183 phba
->fcf
.fcf_flag
&= ~FCF_DISCOVERY
;
1184 spin_unlock_irq(&phba
->hbalock
);
1188 if (!lpfc_error_lost_link(irsp
)) {
1189 /* FLOGI failed, so just use loop map to make discovery list */
1190 lpfc_disc_list_loopmap(vport
);
1192 /* Start discovery */
1193 lpfc_disc_start(vport
);
1194 } else if (((irsp
->ulpStatus
!= IOSTAT_LOCAL_REJECT
) ||
1195 (((irsp
->un
.ulpWord
[4] & IOERR_PARAM_MASK
) !=
1196 IOERR_SLI_ABORTED
) &&
1197 ((irsp
->un
.ulpWord
[4] & IOERR_PARAM_MASK
) !=
1198 IOERR_SLI_DOWN
))) &&
1199 (phba
->link_state
!= LPFC_CLEAR_LA
)) {
1200 /* If FLOGI failed enable link interrupt. */
1201 lpfc_issue_clear_la(phba
, vport
);
1204 lpfc_els_free_iocb(phba
, cmdiocb
);
1208 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
1209 * @vport: pointer to a host virtual N_Port data structure.
1210 * @ndlp: pointer to a node-list data structure.
1211 * @retry: number of retries to the command IOCB.
1213 * This routine issues a Fabric Login (FLOGI) Request ELS command
1214 * for a @vport. The initiator service parameters are put into the payload
1215 * of the FLOGI Request IOCB and the top-level callback function pointer
1216 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
1217 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
1218 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
1220 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1221 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1222 * will be stored into the context1 field of the IOCB for the completion
1223 * callback function to the FLOGI ELS command.
1226 * 0 - successfully issued flogi iocb for @vport
1227 * 1 - failed to issue flogi iocb for @vport
1230 lpfc_issue_els_flogi(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1233 struct lpfc_hba
*phba
= vport
->phba
;
1234 struct serv_parm
*sp
;
1236 struct lpfc_iocbq
*elsiocb
;
1242 cmdsize
= (sizeof(uint32_t) + sizeof(struct serv_parm
));
1243 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
1244 ndlp
->nlp_DID
, ELS_CMD_FLOGI
);
1249 icmd
= &elsiocb
->iocb
;
1250 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
1252 /* For FLOGI request, remainder of payload is service parameters */
1253 *((uint32_t *) (pcmd
)) = ELS_CMD_FLOGI
;
1254 pcmd
+= sizeof(uint32_t);
1255 memcpy(pcmd
, &vport
->fc_sparam
, sizeof(struct serv_parm
));
1256 sp
= (struct serv_parm
*) pcmd
;
1258 /* Setup CSPs accordingly for Fabric */
1259 sp
->cmn
.e_d_tov
= 0;
1260 sp
->cmn
.w2
.r_a_tov
= 0;
1261 sp
->cmn
.virtual_fabric_support
= 0;
1262 sp
->cls1
.classValid
= 0;
1263 if (sp
->cmn
.fcphLow
< FC_PH3
)
1264 sp
->cmn
.fcphLow
= FC_PH3
;
1265 if (sp
->cmn
.fcphHigh
< FC_PH3
)
1266 sp
->cmn
.fcphHigh
= FC_PH3
;
1268 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
1269 if (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) ==
1270 LPFC_SLI_INTF_IF_TYPE_0
) {
1271 elsiocb
->iocb
.ulpCt_h
= ((SLI4_CT_FCFI
>> 1) & 1);
1272 elsiocb
->iocb
.ulpCt_l
= (SLI4_CT_FCFI
& 1);
1273 /* FLOGI needs to be 3 for WQE FCFI */
1274 /* Set the fcfi to the fcfi we registered with */
1275 elsiocb
->iocb
.ulpContext
= phba
->fcf
.fcfi
;
1277 /* Can't do SLI4 class2 without support sequence coalescing */
1278 sp
->cls2
.classValid
= 0;
1279 sp
->cls2
.seqDelivery
= 0;
1281 /* Historical, setting sequential-delivery bit for SLI3 */
1282 sp
->cls2
.seqDelivery
= (sp
->cls2
.classValid
) ? 1 : 0;
1283 sp
->cls3
.seqDelivery
= (sp
->cls3
.classValid
) ? 1 : 0;
1284 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) {
1285 sp
->cmn
.request_multiple_Nport
= 1;
1286 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1290 sp
->cmn
.request_multiple_Nport
= 0;
1293 if (phba
->fc_topology
!= LPFC_TOPOLOGY_LOOP
) {
1294 icmd
->un
.elsreq64
.myID
= 0;
1295 icmd
->un
.elsreq64
.fl
= 1;
1298 tmo
= phba
->fc_ratov
;
1299 phba
->fc_ratov
= LPFC_DISC_FLOGI_TMO
;
1300 lpfc_set_disctmo(vport
);
1301 phba
->fc_ratov
= tmo
;
1303 phba
->fc_stat
.elsXmitFLOGI
++;
1304 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_flogi
;
1306 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1307 "Issue FLOGI: opt:x%x",
1308 phba
->sli3_options
, 0, 0);
1310 rc
= lpfc_issue_fabric_iocb(phba
, elsiocb
);
1311 if (rc
== IOCB_ERROR
) {
1312 lpfc_els_free_iocb(phba
, elsiocb
);
1319 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
1320 * @phba: pointer to lpfc hba data structure.
1322 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1323 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1324 * list and issues an abort IOCB commond on each outstanding IOCB that
1325 * contains a active Fabric_DID ndlp. Note that this function is to issue
1326 * the abort IOCB command on all the outstanding IOCBs, thus when this
1327 * function returns, it does not guarantee all the IOCBs are actually aborted.
1330 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
1333 lpfc_els_abort_flogi(struct lpfc_hba
*phba
)
1335 struct lpfc_sli_ring
*pring
;
1336 struct lpfc_iocbq
*iocb
, *next_iocb
;
1337 struct lpfc_nodelist
*ndlp
;
1340 /* Abort outstanding I/O on NPort <nlp_DID> */
1341 lpfc_printf_log(phba
, KERN_INFO
, LOG_DISCOVERY
,
1342 "0201 Abort outstanding I/O on NPort x%x\n",
1345 pring
= lpfc_phba_elsring(phba
);
1346 if (unlikely(!pring
))
1350 * Check the txcmplq for an iocb that matches the nport the driver is
1353 spin_lock_irq(&phba
->hbalock
);
1354 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
, list
) {
1356 if (icmd
->ulpCommand
== CMD_ELS_REQUEST64_CR
) {
1357 ndlp
= (struct lpfc_nodelist
*)(iocb
->context1
);
1358 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
) &&
1359 (ndlp
->nlp_DID
== Fabric_DID
))
1360 lpfc_sli_issue_abort_iotag(phba
, pring
, iocb
);
1363 spin_unlock_irq(&phba
->hbalock
);
1369 * lpfc_initial_flogi - Issue an initial fabric login for a vport
1370 * @vport: pointer to a host virtual N_Port data structure.
1372 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1373 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1374 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1375 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1376 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1377 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1381 * 0 - failed to issue initial flogi for @vport
1382 * 1 - successfully issued initial flogi for @vport
1385 lpfc_initial_flogi(struct lpfc_vport
*vport
)
1387 struct lpfc_nodelist
*ndlp
;
1389 vport
->port_state
= LPFC_FLOGI
;
1390 lpfc_set_disctmo(vport
);
1392 /* First look for the Fabric ndlp */
1393 ndlp
= lpfc_findnode_did(vport
, Fabric_DID
);
1395 /* Cannot find existing Fabric ndlp, so allocate a new one */
1396 ndlp
= lpfc_nlp_init(vport
, Fabric_DID
);
1399 /* Set the node type */
1400 ndlp
->nlp_type
|= NLP_FABRIC
;
1401 /* Put ndlp onto node list */
1402 lpfc_enqueue_node(vport
, ndlp
);
1403 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
1404 /* re-setup ndlp without removing from node list */
1405 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
1410 if (lpfc_issue_els_flogi(vport
, ndlp
, 0)) {
1411 /* This decrement of reference count to node shall kick off
1412 * the release of the node.
1421 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
1422 * @vport: pointer to a host virtual N_Port data structure.
1424 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1425 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1426 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1427 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1428 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1429 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1433 * 0 - failed to issue initial fdisc for @vport
1434 * 1 - successfully issued initial fdisc for @vport
1437 lpfc_initial_fdisc(struct lpfc_vport
*vport
)
1439 struct lpfc_nodelist
*ndlp
;
1441 /* First look for the Fabric ndlp */
1442 ndlp
= lpfc_findnode_did(vport
, Fabric_DID
);
1444 /* Cannot find existing Fabric ndlp, so allocate a new one */
1445 ndlp
= lpfc_nlp_init(vport
, Fabric_DID
);
1448 /* Put ndlp onto node list */
1449 lpfc_enqueue_node(vport
, ndlp
);
1450 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
1451 /* re-setup ndlp without removing from node list */
1452 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
1457 if (lpfc_issue_els_fdisc(vport
, ndlp
, 0)) {
1458 /* decrement node reference count to trigger the release of
1468 * lpfc_more_plogi - Check and issue remaining plogis for a vport
1469 * @vport: pointer to a host virtual N_Port data structure.
1471 * This routine checks whether there are more remaining Port Logins
1472 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1473 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1474 * to issue ELS PLOGIs up to the configured discover threads with the
1475 * @vport (@vport->cfg_discovery_threads). The function also decrement
1476 * the @vport's num_disc_node by 1 if it is not already 0.
1479 lpfc_more_plogi(struct lpfc_vport
*vport
)
1481 if (vport
->num_disc_nodes
)
1482 vport
->num_disc_nodes
--;
1484 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
1485 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
1486 "0232 Continue discovery with %d PLOGIs to go "
1487 "Data: x%x x%x x%x\n",
1488 vport
->num_disc_nodes
, vport
->fc_plogi_cnt
,
1489 vport
->fc_flag
, vport
->port_state
);
1490 /* Check to see if there are more PLOGIs to be sent */
1491 if (vport
->fc_flag
& FC_NLP_MORE
)
1492 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1493 lpfc_els_disc_plogi(vport
);
1499 * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
1500 * @phba: pointer to lpfc hba data structure.
1501 * @prsp: pointer to response IOCB payload.
1502 * @ndlp: pointer to a node-list data structure.
1504 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1505 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1506 * The following cases are considered N_Port confirmed:
1507 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1508 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1509 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1510 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1511 * 1) if there is a node on vport list other than the @ndlp with the same
1512 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1513 * on that node to release the RPI associated with the node; 2) if there is
1514 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1515 * into, a new node shall be allocated (or activated). In either case, the
1516 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1517 * be released and the new_ndlp shall be put on to the vport node list and
1518 * its pointer returned as the confirmed node.
1520 * Note that before the @ndlp got "released", the keepDID from not-matching
1521 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1522 * of the @ndlp. This is because the release of @ndlp is actually to put it
1523 * into an inactive state on the vport node list and the vport node list
1524 * management algorithm does not allow two node with a same DID.
1527 * pointer to the PLOGI N_Port @ndlp
1529 static struct lpfc_nodelist
*
1530 lpfc_plogi_confirm_nport(struct lpfc_hba
*phba
, uint32_t *prsp
,
1531 struct lpfc_nodelist
*ndlp
)
1533 struct lpfc_vport
*vport
= ndlp
->vport
;
1534 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1535 struct lpfc_nodelist
*new_ndlp
;
1536 struct lpfc_rport_data
*rdata
;
1537 struct fc_rport
*rport
;
1538 struct serv_parm
*sp
;
1539 uint8_t name
[sizeof(struct lpfc_name
)];
1540 uint32_t rc
, keepDID
= 0, keep_nlp_flag
= 0;
1541 uint16_t keep_nlp_state
;
1542 struct lpfc_nvme_rport
*keep_nrport
= NULL
;
1545 unsigned long *active_rrqs_xri_bitmap
= NULL
;
1547 /* Fabric nodes can have the same WWPN so we don't bother searching
1548 * by WWPN. Just return the ndlp that was given to us.
1550 if (ndlp
->nlp_type
& NLP_FABRIC
)
1553 sp
= (struct serv_parm
*) ((uint8_t *) prsp
+ sizeof(uint32_t));
1554 memset(name
, 0, sizeof(struct lpfc_name
));
1556 /* Now we find out if the NPort we are logging into, matches the WWPN
1557 * we have for that ndlp. If not, we have some work to do.
1559 new_ndlp
= lpfc_findnode_wwpn(vport
, &sp
->portName
);
1561 /* return immediately if the WWPN matches ndlp */
1562 if (new_ndlp
== ndlp
&& NLP_CHK_NODE_ACT(new_ndlp
))
1565 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
1566 active_rrqs_xri_bitmap
= mempool_alloc(phba
->active_rrq_pool
,
1568 if (active_rrqs_xri_bitmap
)
1569 memset(active_rrqs_xri_bitmap
, 0,
1570 phba
->cfg_rrq_xri_bitmap_sz
);
1573 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
| LOG_NODE
,
1574 "3178 PLOGI confirm: ndlp x%x x%x x%x: "
1575 "new_ndlp x%x x%x x%x\n",
1576 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_fc4_type
,
1577 (new_ndlp
? new_ndlp
->nlp_DID
: 0),
1578 (new_ndlp
? new_ndlp
->nlp_flag
: 0),
1579 (new_ndlp
? new_ndlp
->nlp_fc4_type
: 0));
1582 rc
= memcmp(&ndlp
->nlp_portname
, name
,
1583 sizeof(struct lpfc_name
));
1585 if (active_rrqs_xri_bitmap
)
1586 mempool_free(active_rrqs_xri_bitmap
,
1587 phba
->active_rrq_pool
);
1590 new_ndlp
= lpfc_nlp_init(vport
, ndlp
->nlp_DID
);
1592 if (active_rrqs_xri_bitmap
)
1593 mempool_free(active_rrqs_xri_bitmap
,
1594 phba
->active_rrq_pool
);
1597 } else if (!NLP_CHK_NODE_ACT(new_ndlp
)) {
1598 rc
= memcmp(&ndlp
->nlp_portname
, name
,
1599 sizeof(struct lpfc_name
));
1601 if (active_rrqs_xri_bitmap
)
1602 mempool_free(active_rrqs_xri_bitmap
,
1603 phba
->active_rrq_pool
);
1606 new_ndlp
= lpfc_enable_node(vport
, new_ndlp
,
1607 NLP_STE_UNUSED_NODE
);
1609 if (active_rrqs_xri_bitmap
)
1610 mempool_free(active_rrqs_xri_bitmap
,
1611 phba
->active_rrq_pool
);
1614 keepDID
= new_ndlp
->nlp_DID
;
1615 if ((phba
->sli_rev
== LPFC_SLI_REV4
) && active_rrqs_xri_bitmap
)
1616 memcpy(active_rrqs_xri_bitmap
,
1617 new_ndlp
->active_rrqs_xri_bitmap
,
1618 phba
->cfg_rrq_xri_bitmap_sz
);
1620 keepDID
= new_ndlp
->nlp_DID
;
1621 if (phba
->sli_rev
== LPFC_SLI_REV4
&&
1622 active_rrqs_xri_bitmap
)
1623 memcpy(active_rrqs_xri_bitmap
,
1624 new_ndlp
->active_rrqs_xri_bitmap
,
1625 phba
->cfg_rrq_xri_bitmap_sz
);
1628 /* At this point in this routine, we know new_ndlp will be
1629 * returned. however, any previous GID_FTs that were done
1630 * would have updated nlp_fc4_type in ndlp, so we must ensure
1631 * new_ndlp has the right value.
1633 if (vport
->fc_flag
& FC_FABRIC
)
1634 new_ndlp
->nlp_fc4_type
= ndlp
->nlp_fc4_type
;
1636 lpfc_unreg_rpi(vport
, new_ndlp
);
1637 new_ndlp
->nlp_DID
= ndlp
->nlp_DID
;
1638 new_ndlp
->nlp_prev_state
= ndlp
->nlp_prev_state
;
1639 if (phba
->sli_rev
== LPFC_SLI_REV4
)
1640 memcpy(new_ndlp
->active_rrqs_xri_bitmap
,
1641 ndlp
->active_rrqs_xri_bitmap
,
1642 phba
->cfg_rrq_xri_bitmap_sz
);
1644 spin_lock_irq(shost
->host_lock
);
1645 keep_nlp_flag
= new_ndlp
->nlp_flag
;
1646 new_ndlp
->nlp_flag
= ndlp
->nlp_flag
;
1647 ndlp
->nlp_flag
= keep_nlp_flag
;
1648 spin_unlock_irq(shost
->host_lock
);
1650 /* Set nlp_states accordingly */
1651 keep_nlp_state
= new_ndlp
->nlp_state
;
1652 lpfc_nlp_set_state(vport
, new_ndlp
, ndlp
->nlp_state
);
1654 /* interchange the nvme remoteport structs */
1655 keep_nrport
= new_ndlp
->nrport
;
1656 new_ndlp
->nrport
= ndlp
->nrport
;
1658 /* Move this back to NPR state */
1659 if (memcmp(&ndlp
->nlp_portname
, name
, sizeof(struct lpfc_name
)) == 0) {
1660 /* The new_ndlp is replacing ndlp totally, so we need
1661 * to put ndlp on UNUSED list and try to free it.
1663 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
1664 "3179 PLOGI confirm NEW: %x %x\n",
1665 new_ndlp
->nlp_DID
, keepDID
);
1667 /* Fix up the rport accordingly */
1668 rport
= ndlp
->rport
;
1670 rdata
= rport
->dd_data
;
1671 if (rdata
->pnode
== ndlp
) {
1672 /* break the link before dropping the ref */
1675 rdata
->pnode
= lpfc_nlp_get(new_ndlp
);
1676 new_ndlp
->rport
= rport
;
1678 new_ndlp
->nlp_type
= ndlp
->nlp_type
;
1681 /* Fix up the nvme rport */
1683 ndlp
->nrport
= NULL
;
1687 /* We shall actually free the ndlp with both nlp_DID and
1688 * nlp_portname fields equals 0 to avoid any ndlp on the
1689 * nodelist never to be used.
1691 if (ndlp
->nlp_DID
== 0) {
1692 spin_lock_irq(&phba
->ndlp_lock
);
1693 NLP_SET_FREE_REQ(ndlp
);
1694 spin_unlock_irq(&phba
->ndlp_lock
);
1697 /* Two ndlps cannot have the same did on the nodelist */
1698 ndlp
->nlp_DID
= keepDID
;
1699 lpfc_nlp_set_state(vport
, ndlp
, keep_nlp_state
);
1700 if (phba
->sli_rev
== LPFC_SLI_REV4
&&
1701 active_rrqs_xri_bitmap
)
1702 memcpy(ndlp
->active_rrqs_xri_bitmap
,
1703 active_rrqs_xri_bitmap
,
1704 phba
->cfg_rrq_xri_bitmap_sz
);
1706 if (!NLP_CHK_NODE_ACT(ndlp
))
1707 lpfc_drop_node(vport
, ndlp
);
1710 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
1711 "3180 PLOGI confirm SWAP: %x %x\n",
1712 new_ndlp
->nlp_DID
, keepDID
);
1714 lpfc_unreg_rpi(vport
, ndlp
);
1716 /* Two ndlps cannot have the same did */
1717 ndlp
->nlp_DID
= keepDID
;
1718 if (phba
->sli_rev
== LPFC_SLI_REV4
&&
1719 active_rrqs_xri_bitmap
)
1720 memcpy(ndlp
->active_rrqs_xri_bitmap
,
1721 active_rrqs_xri_bitmap
,
1722 phba
->cfg_rrq_xri_bitmap_sz
);
1724 /* Since we are switching over to the new_ndlp,
1725 * reset the old ndlp state
1727 if ((ndlp
->nlp_state
== NLP_STE_UNMAPPED_NODE
) ||
1728 (ndlp
->nlp_state
== NLP_STE_MAPPED_NODE
))
1729 keep_nlp_state
= NLP_STE_NPR_NODE
;
1730 lpfc_nlp_set_state(vport
, ndlp
, keep_nlp_state
);
1732 /* Previous ndlp no longer active with nvme host transport.
1733 * Remove reference from earlier registration unless the
1734 * nvme host took care of it.
1738 ndlp
->nrport
= keep_nrport
;
1740 /* Fix up the rport accordingly */
1741 rport
= ndlp
->rport
;
1743 rdata
= rport
->dd_data
;
1744 put_node
= rdata
->pnode
!= NULL
;
1745 put_rport
= ndlp
->rport
!= NULL
;
1746 rdata
->pnode
= NULL
;
1751 put_device(&rport
->dev
);
1754 if (phba
->sli_rev
== LPFC_SLI_REV4
&&
1755 active_rrqs_xri_bitmap
)
1756 mempool_free(active_rrqs_xri_bitmap
,
1757 phba
->active_rrq_pool
);
1759 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
| LOG_NODE
,
1760 "3173 PLOGI confirm exit: new_ndlp x%x x%x x%x\n",
1761 new_ndlp
->nlp_DID
, new_ndlp
->nlp_flag
,
1762 new_ndlp
->nlp_fc4_type
);
1768 * lpfc_end_rscn - Check and handle more rscn for a vport
1769 * @vport: pointer to a host virtual N_Port data structure.
1771 * This routine checks whether more Registration State Change
1772 * Notifications (RSCNs) came in while the discovery state machine was in
1773 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1774 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1775 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1776 * handling the RSCNs.
1779 lpfc_end_rscn(struct lpfc_vport
*vport
)
1781 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1783 if (vport
->fc_flag
& FC_RSCN_MODE
) {
1785 * Check to see if more RSCNs came in while we were
1786 * processing this one.
1788 if (vport
->fc_rscn_id_cnt
||
1789 (vport
->fc_flag
& FC_RSCN_DISCOVERY
) != 0)
1790 lpfc_els_handle_rscn(vport
);
1792 spin_lock_irq(shost
->host_lock
);
1793 vport
->fc_flag
&= ~FC_RSCN_MODE
;
1794 spin_unlock_irq(shost
->host_lock
);
1800 * lpfc_cmpl_els_rrq - Completion handled for els RRQs.
1801 * @phba: pointer to lpfc hba data structure.
1802 * @cmdiocb: pointer to lpfc command iocb data structure.
1803 * @rspiocb: pointer to lpfc response iocb data structure.
1805 * This routine will call the clear rrq function to free the rrq and
1806 * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not
1807 * exist then the clear_rrq is still called because the rrq needs to
1812 lpfc_cmpl_els_rrq(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
1813 struct lpfc_iocbq
*rspiocb
)
1815 struct lpfc_vport
*vport
= cmdiocb
->vport
;
1817 struct lpfc_nodelist
*ndlp
;
1818 struct lpfc_node_rrq
*rrq
;
1820 /* we pass cmdiocb to state machine which needs rspiocb as well */
1821 rrq
= cmdiocb
->context_un
.rrq
;
1822 cmdiocb
->context_un
.rsp_iocb
= rspiocb
;
1824 irsp
= &rspiocb
->iocb
;
1825 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1826 "RRQ cmpl: status:x%x/x%x did:x%x",
1827 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1828 irsp
->un
.elsreq64
.remoteID
);
1830 ndlp
= lpfc_findnode_did(vport
, irsp
->un
.elsreq64
.remoteID
);
1831 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
) || ndlp
!= rrq
->ndlp
) {
1832 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1833 "2882 RRQ completes to NPort x%x "
1834 "with no ndlp. Data: x%x x%x x%x\n",
1835 irsp
->un
.elsreq64
.remoteID
,
1836 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1841 /* rrq completes to NPort <nlp_DID> */
1842 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
1843 "2880 RRQ completes to NPort x%x "
1844 "Data: x%x x%x x%x x%x x%x\n",
1845 ndlp
->nlp_DID
, irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1846 irsp
->ulpTimeout
, rrq
->xritag
, rrq
->rxid
);
1848 if (irsp
->ulpStatus
) {
1849 /* Check for retry */
1850 /* RRQ failed Don't print the vport to vport rjts */
1851 if (irsp
->ulpStatus
!= IOSTAT_LS_RJT
||
1852 (((irsp
->un
.ulpWord
[4]) >> 16 != LSRJT_INVALID_CMD
) &&
1853 ((irsp
->un
.ulpWord
[4]) >> 16 != LSRJT_UNABLE_TPC
)) ||
1854 (phba
)->pport
->cfg_log_verbose
& LOG_ELS
)
1855 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1856 "2881 RRQ failure DID:%06X Status:x%x/x%x\n",
1857 ndlp
->nlp_DID
, irsp
->ulpStatus
,
1858 irsp
->un
.ulpWord
[4]);
1862 lpfc_clr_rrq_active(phba
, rrq
->xritag
, rrq
);
1863 lpfc_els_free_iocb(phba
, cmdiocb
);
1867 * lpfc_cmpl_els_plogi - Completion callback function for plogi
1868 * @phba: pointer to lpfc hba data structure.
1869 * @cmdiocb: pointer to lpfc command iocb data structure.
1870 * @rspiocb: pointer to lpfc response iocb data structure.
1872 * This routine is the completion callback function for issuing the Port
1873 * Login (PLOGI) command. For PLOGI completion, there must be an active
1874 * ndlp on the vport node list that matches the remote node ID from the
1875 * PLOGI response IOCB. If such ndlp does not exist, the PLOGI is simply
1876 * ignored and command IOCB released. The PLOGI response IOCB status is
1877 * checked for error conditons. If there is error status reported, PLOGI
1878 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1879 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1880 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1881 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1882 * there are additional N_Port nodes with the vport that need to perform
1883 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1887 lpfc_cmpl_els_plogi(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
1888 struct lpfc_iocbq
*rspiocb
)
1890 struct lpfc_vport
*vport
= cmdiocb
->vport
;
1891 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1893 struct lpfc_nodelist
*ndlp
;
1894 struct lpfc_dmabuf
*prsp
;
1897 /* we pass cmdiocb to state machine which needs rspiocb as well */
1898 cmdiocb
->context_un
.rsp_iocb
= rspiocb
;
1900 irsp
= &rspiocb
->iocb
;
1901 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1902 "PLOGI cmpl: status:x%x/x%x did:x%x",
1903 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1904 irsp
->un
.elsreq64
.remoteID
);
1906 ndlp
= lpfc_findnode_did(vport
, irsp
->un
.elsreq64
.remoteID
);
1907 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
)) {
1908 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1909 "0136 PLOGI completes to NPort x%x "
1910 "with no ndlp. Data: x%x x%x x%x\n",
1911 irsp
->un
.elsreq64
.remoteID
,
1912 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1917 /* Since ndlp can be freed in the disc state machine, note if this node
1918 * is being used during discovery.
1920 spin_lock_irq(shost
->host_lock
);
1921 disc
= (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
);
1922 ndlp
->nlp_flag
&= ~NLP_NPR_2B_DISC
;
1923 spin_unlock_irq(shost
->host_lock
);
1926 /* PLOGI completes to NPort <nlp_DID> */
1927 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
1928 "0102 PLOGI completes to NPort x%06x "
1929 "Data: x%x x%x x%x x%x x%x\n",
1930 ndlp
->nlp_DID
, ndlp
->nlp_fc4_type
,
1931 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1932 disc
, vport
->num_disc_nodes
);
1934 /* Check to see if link went down during discovery */
1935 if (lpfc_els_chk_latt(vport
)) {
1936 spin_lock_irq(shost
->host_lock
);
1937 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
1938 spin_unlock_irq(shost
->host_lock
);
1942 if (irsp
->ulpStatus
) {
1943 /* Check for retry */
1944 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
)) {
1945 /* ELS command is being retried */
1947 spin_lock_irq(shost
->host_lock
);
1948 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
1949 spin_unlock_irq(shost
->host_lock
);
1953 /* PLOGI failed Don't print the vport to vport rjts */
1954 if (irsp
->ulpStatus
!= IOSTAT_LS_RJT
||
1955 (((irsp
->un
.ulpWord
[4]) >> 16 != LSRJT_INVALID_CMD
) &&
1956 ((irsp
->un
.ulpWord
[4]) >> 16 != LSRJT_UNABLE_TPC
)) ||
1957 (phba
)->pport
->cfg_log_verbose
& LOG_ELS
)
1958 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1959 "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
1960 ndlp
->nlp_DID
, irsp
->ulpStatus
,
1961 irsp
->un
.ulpWord
[4]);
1962 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1963 if (lpfc_error_lost_link(irsp
))
1964 rc
= NLP_STE_FREED_NODE
;
1966 rc
= lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
1967 NLP_EVT_CMPL_PLOGI
);
1969 /* Good status, call state machine */
1970 prsp
= list_entry(((struct lpfc_dmabuf
*)
1971 cmdiocb
->context2
)->list
.next
,
1972 struct lpfc_dmabuf
, list
);
1973 ndlp
= lpfc_plogi_confirm_nport(phba
, prsp
->virt
, ndlp
);
1974 rc
= lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
1975 NLP_EVT_CMPL_PLOGI
);
1978 if (disc
&& vport
->num_disc_nodes
) {
1979 /* Check to see if there are more PLOGIs to be sent */
1980 lpfc_more_plogi(vport
);
1982 if (vport
->num_disc_nodes
== 0) {
1983 spin_lock_irq(shost
->host_lock
);
1984 vport
->fc_flag
&= ~FC_NDISC_ACTIVE
;
1985 spin_unlock_irq(shost
->host_lock
);
1987 lpfc_can_disctmo(vport
);
1988 lpfc_end_rscn(vport
);
1993 lpfc_els_free_iocb(phba
, cmdiocb
);
1998 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
1999 * @vport: pointer to a host virtual N_Port data structure.
2000 * @did: destination port identifier.
2001 * @retry: number of retries to the command IOCB.
2003 * This routine issues a Port Login (PLOGI) command to a remote N_Port
2004 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
2005 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
2006 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
2007 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
2009 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2010 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2011 * will be stored into the context1 field of the IOCB for the completion
2012 * callback function to the PLOGI ELS command.
2015 * 0 - Successfully issued a plogi for @vport
2016 * 1 - failed to issue a plogi for @vport
2019 lpfc_issue_els_plogi(struct lpfc_vport
*vport
, uint32_t did
, uint8_t retry
)
2021 struct lpfc_hba
*phba
= vport
->phba
;
2022 struct Scsi_Host
*shost
;
2023 struct serv_parm
*sp
;
2024 struct lpfc_nodelist
*ndlp
;
2025 struct lpfc_iocbq
*elsiocb
;
2030 ndlp
= lpfc_findnode_did(vport
, did
);
2031 if (ndlp
&& !NLP_CHK_NODE_ACT(ndlp
))
2034 /* If ndlp is not NULL, we will bump the reference count on it */
2035 cmdsize
= (sizeof(uint32_t) + sizeof(struct serv_parm
));
2036 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
, did
,
2041 shost
= lpfc_shost_from_vport(vport
);
2042 spin_lock_irq(shost
->host_lock
);
2043 ndlp
->nlp_flag
&= ~NLP_FCP_PRLI_RJT
;
2044 spin_unlock_irq(shost
->host_lock
);
2046 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
2048 /* For PLOGI request, remainder of payload is service parameters */
2049 *((uint32_t *) (pcmd
)) = ELS_CMD_PLOGI
;
2050 pcmd
+= sizeof(uint32_t);
2051 memcpy(pcmd
, &vport
->fc_sparam
, sizeof(struct serv_parm
));
2052 sp
= (struct serv_parm
*) pcmd
;
2055 * If we are a N-port connected to a Fabric, fix-up paramm's so logins
2056 * to device on remote loops work.
2058 if ((vport
->fc_flag
& FC_FABRIC
) && !(vport
->fc_flag
& FC_PUBLIC_LOOP
))
2059 sp
->cmn
.altBbCredit
= 1;
2061 if (sp
->cmn
.fcphLow
< FC_PH_4_3
)
2062 sp
->cmn
.fcphLow
= FC_PH_4_3
;
2064 if (sp
->cmn
.fcphHigh
< FC_PH3
)
2065 sp
->cmn
.fcphHigh
= FC_PH3
;
2067 sp
->cmn
.valid_vendor_ver_level
= 0;
2068 memset(sp
->un
.vendorVersion
, 0, sizeof(sp
->un
.vendorVersion
));
2069 sp
->cmn
.bbRcvSizeMsb
&= 0xF;
2071 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2072 "Issue PLOGI: did:x%x",
2075 /* If our firmware supports this feature, convey that
2076 * information to the target using the vendor specific field.
2078 if (phba
->sli
.sli_flag
& LPFC_SLI_SUPPRESS_RSP
) {
2079 sp
->cmn
.valid_vendor_ver_level
= 1;
2080 sp
->un
.vv
.vid
= cpu_to_be32(LPFC_VV_EMLX_ID
);
2081 sp
->un
.vv
.flags
= cpu_to_be32(LPFC_VV_SUPPRESS_RSP
);
2084 phba
->fc_stat
.elsXmitPLOGI
++;
2085 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_plogi
;
2086 ret
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
2088 if (ret
== IOCB_ERROR
) {
2089 lpfc_els_free_iocb(phba
, elsiocb
);
2096 * lpfc_cmpl_els_prli - Completion callback function for prli
2097 * @phba: pointer to lpfc hba data structure.
2098 * @cmdiocb: pointer to lpfc command iocb data structure.
2099 * @rspiocb: pointer to lpfc response iocb data structure.
2101 * This routine is the completion callback function for a Process Login
2102 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
2103 * status. If there is error status reported, PRLI retry shall be attempted
2104 * by invoking the lpfc_els_retry() routine. Otherwise, the state
2105 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
2106 * ndlp to mark the PRLI completion.
2109 lpfc_cmpl_els_prli(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
2110 struct lpfc_iocbq
*rspiocb
)
2112 struct lpfc_vport
*vport
= cmdiocb
->vport
;
2113 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2115 struct lpfc_nodelist
*ndlp
;
2117 /* we pass cmdiocb to state machine which needs rspiocb as well */
2118 cmdiocb
->context_un
.rsp_iocb
= rspiocb
;
2120 irsp
= &(rspiocb
->iocb
);
2121 ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
2122 spin_lock_irq(shost
->host_lock
);
2123 ndlp
->nlp_flag
&= ~NLP_PRLI_SND
;
2125 /* Driver supports multiple FC4 types. Counters matter. */
2126 vport
->fc_prli_sent
--;
2127 ndlp
->fc4_prli_sent
--;
2128 spin_unlock_irq(shost
->host_lock
);
2130 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2131 "PRLI cmpl: status:x%x/x%x did:x%x",
2132 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
2135 /* PRLI completes to NPort <nlp_DID> */
2136 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
2137 "0103 PRLI completes to NPort x%06x "
2138 "Data: x%x x%x x%x x%x\n",
2139 ndlp
->nlp_DID
, irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
2140 vport
->num_disc_nodes
, ndlp
->fc4_prli_sent
);
2142 /* Check to see if link went down during discovery */
2143 if (lpfc_els_chk_latt(vport
))
2146 if (irsp
->ulpStatus
) {
2147 /* Check for retry */
2148 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
)) {
2149 /* ELS command is being retried */
2154 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
2155 "2754 PRLI failure DID:%06X Status:x%x/x%x, "
2157 ndlp
->nlp_DID
, irsp
->ulpStatus
,
2158 irsp
->un
.ulpWord
[4], ndlp
->fc4_prli_sent
);
2160 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2161 if (lpfc_error_lost_link(irsp
))
2164 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
2167 /* Good status, call state machine. However, if another
2168 * PRLI is outstanding, don't call the state machine
2169 * because final disposition to Mapped or Unmapped is
2172 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
2176 lpfc_els_free_iocb(phba
, cmdiocb
);
2181 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
2182 * @vport: pointer to a host virtual N_Port data structure.
2183 * @ndlp: pointer to a node-list data structure.
2184 * @retry: number of retries to the command IOCB.
2186 * This routine issues a Process Login (PRLI) ELS command for the
2187 * @vport. The PRLI service parameters are set up in the payload of the
2188 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
2189 * is put to the IOCB completion callback func field before invoking the
2190 * routine lpfc_sli_issue_iocb() to send out PRLI command.
2192 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2193 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2194 * will be stored into the context1 field of the IOCB for the completion
2195 * callback function to the PRLI ELS command.
2198 * 0 - successfully issued prli iocb command for @vport
2199 * 1 - failed to issue prli iocb command for @vport
2202 lpfc_issue_els_prli(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2205 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2206 struct lpfc_hba
*phba
= vport
->phba
;
2208 struct lpfc_nvme_prli
*npr_nvme
;
2209 struct lpfc_iocbq
*elsiocb
;
2212 u32 local_nlp_type
, elscmd
;
2215 * If we are in RSCN mode, the FC4 types supported from a
2216 * previous GFT_ID command may not be accurate. So, if we
2217 * are a NVME Initiator, always look for the possibility of
2218 * the remote NPort beng a NVME Target.
2220 if (phba
->sli_rev
== LPFC_SLI_REV4
&&
2221 vport
->fc_flag
& FC_RSCN_MODE
&&
2222 vport
->nvmei_support
)
2223 ndlp
->nlp_fc4_type
|= NLP_FC4_NVME
;
2224 local_nlp_type
= ndlp
->nlp_fc4_type
;
2226 /* This routine will issue 1 or 2 PRLIs, so zero all the ndlp
2227 * fields here before any of them can complete.
2229 ndlp
->nlp_type
&= ~(NLP_FCP_TARGET
| NLP_FCP_INITIATOR
);
2230 ndlp
->nlp_type
&= ~(NLP_NVME_TARGET
| NLP_NVME_INITIATOR
);
2231 ndlp
->nlp_fcp_info
&= ~NLP_FCP_2_DEVICE
;
2232 ndlp
->nlp_flag
&= ~NLP_FIRSTBURST
;
2233 ndlp
->nvme_fb_size
= 0;
2236 if (local_nlp_type
& NLP_FC4_FCP
) {
2237 /* Payload is 4 + 16 = 20 x14 bytes. */
2238 cmdsize
= (sizeof(uint32_t) + sizeof(PRLI
));
2239 elscmd
= ELS_CMD_PRLI
;
2240 } else if (local_nlp_type
& NLP_FC4_NVME
) {
2241 /* Payload is 4 + 20 = 24 x18 bytes. */
2242 cmdsize
= (sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli
));
2243 elscmd
= ELS_CMD_NVMEPRLI
;
2245 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
2246 "3083 Unknown FC_TYPE x%x ndlp x%06x\n",
2247 ndlp
->nlp_fc4_type
, ndlp
->nlp_DID
);
2251 /* SLI3 ports don't support NVME. If this rport is a strict NVME
2252 * FC4 type, implicitly LOGO.
2254 if (phba
->sli_rev
== LPFC_SLI_REV3
&&
2255 ndlp
->nlp_fc4_type
== NLP_FC4_NVME
) {
2256 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
2257 "3088 Rport fc4 type 0x%x not supported by SLI3 adapter\n",
2259 lpfc_disc_state_machine(vport
, ndlp
, NULL
, NLP_EVT_DEVICE_RM
);
2263 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
2264 ndlp
->nlp_DID
, elscmd
);
2268 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
2270 /* For PRLI request, remainder of payload is service parameters */
2271 memset(pcmd
, 0, cmdsize
);
2273 if (local_nlp_type
& NLP_FC4_FCP
) {
2274 /* Remainder of payload is FCP PRLI parameter page.
2275 * Note: this data structure is defined as
2276 * BE/LE in the structure definition so no
2277 * byte swap call is made.
2279 *((uint32_t *)(pcmd
)) = ELS_CMD_PRLI
;
2280 pcmd
+= sizeof(uint32_t);
2284 * If our firmware version is 3.20 or later,
2285 * set the following bits for FC-TAPE support.
2287 if (phba
->vpd
.rev
.feaLevelHigh
>= 0x02) {
2288 npr
->ConfmComplAllowed
= 1;
2290 npr
->TaskRetryIdReq
= 1;
2292 npr
->estabImagePair
= 1;
2293 npr
->readXferRdyDis
= 1;
2294 if (vport
->cfg_first_burst_size
)
2295 npr
->writeXferRdyDis
= 1;
2297 /* For FCP support */
2298 npr
->prliType
= PRLI_FCP_TYPE
;
2299 npr
->initiatorFunc
= 1;
2300 elsiocb
->iocb_flag
|= LPFC_PRLI_FCP_REQ
;
2302 /* Remove FCP type - processed. */
2303 local_nlp_type
&= ~NLP_FC4_FCP
;
2304 } else if (local_nlp_type
& NLP_FC4_NVME
) {
2305 /* Remainder of payload is NVME PRLI parameter page.
2306 * This data structure is the newer definition that
2307 * uses bf macros so a byte swap is required.
2309 *((uint32_t *)(pcmd
)) = ELS_CMD_NVMEPRLI
;
2310 pcmd
+= sizeof(uint32_t);
2311 npr_nvme
= (struct lpfc_nvme_prli
*)pcmd
;
2312 bf_set(prli_type_code
, npr_nvme
, PRLI_NVME_TYPE
);
2313 bf_set(prli_estabImagePair
, npr_nvme
, 0); /* Should be 0 */
2315 /* Only initiators request first burst. */
2316 if ((phba
->cfg_nvme_enable_fb
) &&
2317 !phba
->nvmet_support
)
2318 bf_set(prli_fba
, npr_nvme
, 1);
2320 if (phba
->nvmet_support
) {
2321 bf_set(prli_tgt
, npr_nvme
, 1);
2322 bf_set(prli_disc
, npr_nvme
, 1);
2324 bf_set(prli_init
, npr_nvme
, 1);
2325 bf_set(prli_conf
, npr_nvme
, 1);
2328 npr_nvme
->word1
= cpu_to_be32(npr_nvme
->word1
);
2329 npr_nvme
->word4
= cpu_to_be32(npr_nvme
->word4
);
2330 elsiocb
->iocb_flag
|= LPFC_PRLI_NVME_REQ
;
2332 /* Remove NVME type - processed. */
2333 local_nlp_type
&= ~NLP_FC4_NVME
;
2336 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2337 "Issue PRLI: did:x%x",
2338 ndlp
->nlp_DID
, 0, 0);
2340 phba
->fc_stat
.elsXmitPRLI
++;
2341 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_prli
;
2342 spin_lock_irq(shost
->host_lock
);
2343 ndlp
->nlp_flag
|= NLP_PRLI_SND
;
2345 /* The vport counters are used for lpfc_scan_finished, but
2346 * the ndlp is used to track outstanding PRLIs for different
2349 vport
->fc_prli_sent
++;
2350 ndlp
->fc4_prli_sent
++;
2351 spin_unlock_irq(shost
->host_lock
);
2352 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) ==
2354 spin_lock_irq(shost
->host_lock
);
2355 ndlp
->nlp_flag
&= ~NLP_PRLI_SND
;
2356 spin_unlock_irq(shost
->host_lock
);
2357 lpfc_els_free_iocb(phba
, elsiocb
);
2362 /* The driver supports 2 FC4 types. Make sure
2363 * a PRLI is issued for all types before exiting.
2365 if (phba
->sli_rev
== LPFC_SLI_REV4
&&
2366 local_nlp_type
& (NLP_FC4_FCP
| NLP_FC4_NVME
))
2367 goto send_next_prli
;
2373 * lpfc_rscn_disc - Perform rscn discovery for a vport
2374 * @vport: pointer to a host virtual N_Port data structure.
2376 * This routine performs Registration State Change Notification (RSCN)
2377 * discovery for a @vport. If the @vport's node port recovery count is not
2378 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
2379 * the nodes that need recovery. If none of the PLOGI were needed through
2380 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
2381 * invoked to check and handle possible more RSCN came in during the period
2382 * of processing the current ones.
2385 lpfc_rscn_disc(struct lpfc_vport
*vport
)
2387 lpfc_can_disctmo(vport
);
2389 /* RSCN discovery */
2390 /* go thru NPR nodes and issue ELS PLOGIs */
2391 if (vport
->fc_npr_cnt
)
2392 if (lpfc_els_disc_plogi(vport
))
2395 lpfc_end_rscn(vport
);
2399 * lpfc_adisc_done - Complete the adisc phase of discovery
2400 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
2402 * This function is called when the final ADISC is completed during discovery.
2403 * This function handles clearing link attention or issuing reg_vpi depending
2404 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
2406 * This function is called with no locks held.
2409 lpfc_adisc_done(struct lpfc_vport
*vport
)
2411 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2412 struct lpfc_hba
*phba
= vport
->phba
;
2415 * For NPIV, cmpl_reg_vpi will set port_state to READY,
2416 * and continue discovery.
2418 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
2419 !(vport
->fc_flag
& FC_RSCN_MODE
) &&
2420 (phba
->sli_rev
< LPFC_SLI_REV4
)) {
2421 /* The ADISCs are complete. Doesn't matter if they
2422 * succeeded or failed because the ADISC completion
2423 * routine guarantees to call the state machine and
2424 * the RPI is either unregistered (failed ADISC response)
2425 * or the RPI is still valid and the node is marked
2426 * mapped for a target. The exchanges should be in the
2427 * correct state. This code is specific to SLI3.
2429 lpfc_issue_clear_la(phba
, vport
);
2430 lpfc_issue_reg_vpi(phba
, vport
);
2434 * For SLI2, we need to set port_state to READY
2435 * and continue discovery.
2437 if (vport
->port_state
< LPFC_VPORT_READY
) {
2438 /* If we get here, there is nothing to ADISC */
2439 lpfc_issue_clear_la(phba
, vport
);
2440 if (!(vport
->fc_flag
& FC_ABORT_DISCOVERY
)) {
2441 vport
->num_disc_nodes
= 0;
2442 /* go thru NPR list, issue ELS PLOGIs */
2443 if (vport
->fc_npr_cnt
)
2444 lpfc_els_disc_plogi(vport
);
2445 if (!vport
->num_disc_nodes
) {
2446 spin_lock_irq(shost
->host_lock
);
2447 vport
->fc_flag
&= ~FC_NDISC_ACTIVE
;
2448 spin_unlock_irq(shost
->host_lock
);
2449 lpfc_can_disctmo(vport
);
2450 lpfc_end_rscn(vport
);
2453 vport
->port_state
= LPFC_VPORT_READY
;
2455 lpfc_rscn_disc(vport
);
2459 * lpfc_more_adisc - Issue more adisc as needed
2460 * @vport: pointer to a host virtual N_Port data structure.
2462 * This routine determines whether there are more ndlps on a @vport
2463 * node list need to have Address Discover (ADISC) issued. If so, it will
2464 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
2465 * remaining nodes which need to have ADISC sent.
2468 lpfc_more_adisc(struct lpfc_vport
*vport
)
2470 if (vport
->num_disc_nodes
)
2471 vport
->num_disc_nodes
--;
2472 /* Continue discovery with <num_disc_nodes> ADISCs to go */
2473 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
2474 "0210 Continue discovery with %d ADISCs to go "
2475 "Data: x%x x%x x%x\n",
2476 vport
->num_disc_nodes
, vport
->fc_adisc_cnt
,
2477 vport
->fc_flag
, vport
->port_state
);
2478 /* Check to see if there are more ADISCs to be sent */
2479 if (vport
->fc_flag
& FC_NLP_MORE
) {
2480 lpfc_set_disctmo(vport
);
2481 /* go thru NPR nodes and issue any remaining ELS ADISCs */
2482 lpfc_els_disc_adisc(vport
);
2484 if (!vport
->num_disc_nodes
)
2485 lpfc_adisc_done(vport
);
2490 * lpfc_cmpl_els_adisc - Completion callback function for adisc
2491 * @phba: pointer to lpfc hba data structure.
2492 * @cmdiocb: pointer to lpfc command iocb data structure.
2493 * @rspiocb: pointer to lpfc response iocb data structure.
2495 * This routine is the completion function for issuing the Address Discover
2496 * (ADISC) command. It first checks to see whether link went down during
2497 * the discovery process. If so, the node will be marked as node port
2498 * recovery for issuing discover IOCB by the link attention handler and
2499 * exit. Otherwise, the response status is checked. If error was reported
2500 * in the response status, the ADISC command shall be retried by invoking
2501 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
2502 * the response status, the state machine is invoked to set transition
2503 * with respect to NLP_EVT_CMPL_ADISC event.
2506 lpfc_cmpl_els_adisc(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
2507 struct lpfc_iocbq
*rspiocb
)
2509 struct lpfc_vport
*vport
= cmdiocb
->vport
;
2510 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2512 struct lpfc_nodelist
*ndlp
;
2515 /* we pass cmdiocb to state machine which needs rspiocb as well */
2516 cmdiocb
->context_un
.rsp_iocb
= rspiocb
;
2518 irsp
= &(rspiocb
->iocb
);
2519 ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
2521 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2522 "ADISC cmpl: status:x%x/x%x did:x%x",
2523 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
2526 /* Since ndlp can be freed in the disc state machine, note if this node
2527 * is being used during discovery.
2529 spin_lock_irq(shost
->host_lock
);
2530 disc
= (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
);
2531 ndlp
->nlp_flag
&= ~(NLP_ADISC_SND
| NLP_NPR_2B_DISC
);
2532 spin_unlock_irq(shost
->host_lock
);
2533 /* ADISC completes to NPort <nlp_DID> */
2534 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
2535 "0104 ADISC completes to NPort x%x "
2536 "Data: x%x x%x x%x x%x x%x\n",
2537 ndlp
->nlp_DID
, irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
2538 irsp
->ulpTimeout
, disc
, vport
->num_disc_nodes
);
2539 /* Check to see if link went down during discovery */
2540 if (lpfc_els_chk_latt(vport
)) {
2541 spin_lock_irq(shost
->host_lock
);
2542 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
2543 spin_unlock_irq(shost
->host_lock
);
2547 if (irsp
->ulpStatus
) {
2548 /* Check for retry */
2549 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
)) {
2550 /* ELS command is being retried */
2552 spin_lock_irq(shost
->host_lock
);
2553 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
2554 spin_unlock_irq(shost
->host_lock
);
2555 lpfc_set_disctmo(vport
);
2560 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
2561 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
2562 ndlp
->nlp_DID
, irsp
->ulpStatus
,
2563 irsp
->un
.ulpWord
[4]);
2564 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2565 if (!lpfc_error_lost_link(irsp
))
2566 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
2567 NLP_EVT_CMPL_ADISC
);
2569 /* Good status, call state machine */
2570 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
2571 NLP_EVT_CMPL_ADISC
);
2573 /* Check to see if there are more ADISCs to be sent */
2574 if (disc
&& vport
->num_disc_nodes
)
2575 lpfc_more_adisc(vport
);
2577 lpfc_els_free_iocb(phba
, cmdiocb
);
2582 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
2583 * @vport: pointer to a virtual N_Port data structure.
2584 * @ndlp: pointer to a node-list data structure.
2585 * @retry: number of retries to the command IOCB.
2587 * This routine issues an Address Discover (ADISC) for an @ndlp on a
2588 * @vport. It prepares the payload of the ADISC ELS command, updates the
2589 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
2590 * to issue the ADISC ELS command.
2592 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2593 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2594 * will be stored into the context1 field of the IOCB for the completion
2595 * callback function to the ADISC ELS command.
2598 * 0 - successfully issued adisc
2599 * 1 - failed to issue adisc
2602 lpfc_issue_els_adisc(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2605 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2606 struct lpfc_hba
*phba
= vport
->phba
;
2608 struct lpfc_iocbq
*elsiocb
;
2612 cmdsize
= (sizeof(uint32_t) + sizeof(ADISC
));
2613 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
2614 ndlp
->nlp_DID
, ELS_CMD_ADISC
);
2618 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
2620 /* For ADISC request, remainder of payload is service parameters */
2621 *((uint32_t *) (pcmd
)) = ELS_CMD_ADISC
;
2622 pcmd
+= sizeof(uint32_t);
2624 /* Fill in ADISC payload */
2625 ap
= (ADISC
*) pcmd
;
2626 ap
->hardAL_PA
= phba
->fc_pref_ALPA
;
2627 memcpy(&ap
->portName
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
2628 memcpy(&ap
->nodeName
, &vport
->fc_nodename
, sizeof(struct lpfc_name
));
2629 ap
->DID
= be32_to_cpu(vport
->fc_myDID
);
2631 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2632 "Issue ADISC: did:x%x",
2633 ndlp
->nlp_DID
, 0, 0);
2635 phba
->fc_stat
.elsXmitADISC
++;
2636 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_adisc
;
2637 spin_lock_irq(shost
->host_lock
);
2638 ndlp
->nlp_flag
|= NLP_ADISC_SND
;
2639 spin_unlock_irq(shost
->host_lock
);
2640 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) ==
2642 spin_lock_irq(shost
->host_lock
);
2643 ndlp
->nlp_flag
&= ~NLP_ADISC_SND
;
2644 spin_unlock_irq(shost
->host_lock
);
2645 lpfc_els_free_iocb(phba
, elsiocb
);
2652 * lpfc_cmpl_els_logo - Completion callback function for logo
2653 * @phba: pointer to lpfc hba data structure.
2654 * @cmdiocb: pointer to lpfc command iocb data structure.
2655 * @rspiocb: pointer to lpfc response iocb data structure.
2657 * This routine is the completion function for issuing the ELS Logout (LOGO)
2658 * command. If no error status was reported from the LOGO response, the
2659 * state machine of the associated ndlp shall be invoked for transition with
2660 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
2661 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
2664 lpfc_cmpl_els_logo(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
2665 struct lpfc_iocbq
*rspiocb
)
2667 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
2668 struct lpfc_vport
*vport
= ndlp
->vport
;
2669 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2671 struct lpfcMboxq
*mbox
;
2672 unsigned long flags
;
2673 uint32_t skip_recovery
= 0;
2675 /* we pass cmdiocb to state machine which needs rspiocb as well */
2676 cmdiocb
->context_un
.rsp_iocb
= rspiocb
;
2678 irsp
= &(rspiocb
->iocb
);
2679 spin_lock_irq(shost
->host_lock
);
2680 ndlp
->nlp_flag
&= ~NLP_LOGO_SND
;
2681 spin_unlock_irq(shost
->host_lock
);
2683 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2684 "LOGO cmpl: status:x%x/x%x did:x%x",
2685 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
2688 /* LOGO completes to NPort <nlp_DID> */
2689 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
2690 "0105 LOGO completes to NPort x%x "
2691 "Data: x%x x%x x%x x%x\n",
2692 ndlp
->nlp_DID
, irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
2693 irsp
->ulpTimeout
, vport
->num_disc_nodes
);
2695 if (lpfc_els_chk_latt(vport
)) {
2700 /* Check to see if link went down during discovery */
2701 if (ndlp
->nlp_flag
& NLP_TARGET_REMOVE
) {
2702 /* NLP_EVT_DEVICE_RM should unregister the RPI
2703 * which should abort all outstanding IOs.
2705 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
2711 /* The LOGO will not be retried on failure. A LOGO was
2712 * issued to the remote rport and a ACC or RJT or no Answer are
2713 * all acceptable. Note the failure and move forward with
2714 * discovery. The PLOGI will retry.
2716 if (irsp
->ulpStatus
) {
2718 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
2719 "2756 LOGO failure, No Retry DID:%06X Status:x%x/x%x\n",
2720 ndlp
->nlp_DID
, irsp
->ulpStatus
,
2721 irsp
->un
.ulpWord
[4]);
2722 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2723 if (lpfc_error_lost_link(irsp
)) {
2729 /* Call state machine. This will unregister the rpi if needed. */
2730 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
, NLP_EVT_CMPL_LOGO
);
2733 lpfc_els_free_iocb(phba
, cmdiocb
);
2734 /* If we are in pt2pt mode, we could rcv new S_ID on PLOGI */
2735 if ((vport
->fc_flag
& FC_PT2PT
) &&
2736 !(vport
->fc_flag
& FC_PT2PT_PLOGI
)) {
2737 phba
->pport
->fc_myDID
= 0;
2739 if ((phba
->cfg_enable_fc4_type
== LPFC_ENABLE_BOTH
) ||
2740 (phba
->cfg_enable_fc4_type
== LPFC_ENABLE_NVME
)) {
2741 if (phba
->nvmet_support
)
2742 lpfc_nvmet_update_targetport(phba
);
2744 lpfc_nvme_update_localport(phba
->pport
);
2747 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
2749 lpfc_config_link(phba
, mbox
);
2750 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
2751 mbox
->vport
= vport
;
2752 if (lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
) ==
2754 mempool_free(mbox
, phba
->mbox_mem_pool
);
2761 * If the node is a target, the handling attempts to recover the port.
2762 * For any other port type, the rpi is unregistered as an implicit
2765 if (ndlp
->nlp_type
& (NLP_FCP_TARGET
| NLP_NVME_TARGET
) &&
2766 skip_recovery
== 0) {
2767 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
2768 spin_lock_irqsave(shost
->host_lock
, flags
);
2769 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
2770 spin_unlock_irqrestore(shost
->host_lock
, flags
);
2772 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
2773 "3187 LOGO completes to NPort x%x: Start "
2774 "Recovery Data: x%x x%x x%x x%x\n",
2775 ndlp
->nlp_DID
, irsp
->ulpStatus
,
2776 irsp
->un
.ulpWord
[4], irsp
->ulpTimeout
,
2777 vport
->num_disc_nodes
);
2778 lpfc_disc_start(vport
);
2784 * lpfc_issue_els_logo - Issue a logo to an node on a vport
2785 * @vport: pointer to a virtual N_Port data structure.
2786 * @ndlp: pointer to a node-list data structure.
2787 * @retry: number of retries to the command IOCB.
2789 * This routine constructs and issues an ELS Logout (LOGO) iocb command
2790 * to a remote node, referred by an @ndlp on a @vport. It constructs the
2791 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2792 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2794 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2795 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2796 * will be stored into the context1 field of the IOCB for the completion
2797 * callback function to the LOGO ELS command.
2799 * Callers of this routine are expected to unregister the RPI first
2802 * 0 - successfully issued logo
2803 * 1 - failed to issue logo
2806 lpfc_issue_els_logo(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2809 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2810 struct lpfc_hba
*phba
= vport
->phba
;
2811 struct lpfc_iocbq
*elsiocb
;
2816 spin_lock_irq(shost
->host_lock
);
2817 if (ndlp
->nlp_flag
& NLP_LOGO_SND
) {
2818 spin_unlock_irq(shost
->host_lock
);
2821 spin_unlock_irq(shost
->host_lock
);
2823 cmdsize
= (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name
);
2824 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
2825 ndlp
->nlp_DID
, ELS_CMD_LOGO
);
2829 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
2830 *((uint32_t *) (pcmd
)) = ELS_CMD_LOGO
;
2831 pcmd
+= sizeof(uint32_t);
2833 /* Fill in LOGO payload */
2834 *((uint32_t *) (pcmd
)) = be32_to_cpu(vport
->fc_myDID
);
2835 pcmd
+= sizeof(uint32_t);
2836 memcpy(pcmd
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
2838 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2839 "Issue LOGO: did:x%x",
2840 ndlp
->nlp_DID
, 0, 0);
2842 phba
->fc_stat
.elsXmitLOGO
++;
2843 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_logo
;
2844 spin_lock_irq(shost
->host_lock
);
2845 ndlp
->nlp_flag
|= NLP_LOGO_SND
;
2846 ndlp
->nlp_flag
&= ~NLP_ISSUE_LOGO
;
2847 spin_unlock_irq(shost
->host_lock
);
2848 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
2849 if (rc
== IOCB_ERROR
) {
2850 spin_lock_irq(shost
->host_lock
);
2851 ndlp
->nlp_flag
&= ~NLP_LOGO_SND
;
2852 spin_unlock_irq(shost
->host_lock
);
2853 lpfc_els_free_iocb(phba
, elsiocb
);
2857 spin_lock_irq(shost
->host_lock
);
2858 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
2859 spin_unlock_irq(shost
->host_lock
);
2860 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_LOGO_ISSUE
);
2865 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
2866 * @phba: pointer to lpfc hba data structure.
2867 * @cmdiocb: pointer to lpfc command iocb data structure.
2868 * @rspiocb: pointer to lpfc response iocb data structure.
2870 * This routine is a generic completion callback function for ELS commands.
2871 * Specifically, it is the callback function which does not need to perform
2872 * any command specific operations. It is currently used by the ELS command
2873 * issuing routines for the ELS State Change Request (SCR),
2874 * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
2875 * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
2876 * certain debug loggings, this callback function simply invokes the
2877 * lpfc_els_chk_latt() routine to check whether link went down during the
2878 * discovery process.
2881 lpfc_cmpl_els_cmd(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
2882 struct lpfc_iocbq
*rspiocb
)
2884 struct lpfc_vport
*vport
= cmdiocb
->vport
;
2887 irsp
= &rspiocb
->iocb
;
2889 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2890 "ELS cmd cmpl: status:x%x/x%x did:x%x",
2891 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
2892 irsp
->un
.elsreq64
.remoteID
);
2893 /* ELS cmd tag <ulpIoTag> completes */
2894 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
2895 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
2896 irsp
->ulpIoTag
, irsp
->ulpStatus
,
2897 irsp
->un
.ulpWord
[4], irsp
->ulpTimeout
);
2898 /* Check to see if link went down during discovery */
2899 lpfc_els_chk_latt(vport
);
2900 lpfc_els_free_iocb(phba
, cmdiocb
);
2905 * lpfc_issue_els_scr - Issue a scr to an node on a vport
2906 * @vport: pointer to a host virtual N_Port data structure.
2907 * @nportid: N_Port identifier to the remote node.
2908 * @retry: number of retries to the command IOCB.
2910 * This routine issues a State Change Request (SCR) to a fabric node
2911 * on a @vport. The remote node @nportid is passed into the function. It
2912 * first search the @vport node list to find the matching ndlp. If no such
2913 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
2914 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
2915 * routine is invoked to send the SCR IOCB.
2917 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2918 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2919 * will be stored into the context1 field of the IOCB for the completion
2920 * callback function to the SCR ELS command.
2923 * 0 - Successfully issued scr command
2924 * 1 - Failed to issue scr command
2927 lpfc_issue_els_scr(struct lpfc_vport
*vport
, uint32_t nportid
, uint8_t retry
)
2929 struct lpfc_hba
*phba
= vport
->phba
;
2930 struct lpfc_iocbq
*elsiocb
;
2933 struct lpfc_nodelist
*ndlp
;
2935 cmdsize
= (sizeof(uint32_t) + sizeof(SCR
));
2937 ndlp
= lpfc_findnode_did(vport
, nportid
);
2939 ndlp
= lpfc_nlp_init(vport
, nportid
);
2942 lpfc_enqueue_node(vport
, ndlp
);
2943 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
2944 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
2949 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
2950 ndlp
->nlp_DID
, ELS_CMD_SCR
);
2953 /* This will trigger the release of the node just
2960 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
2962 *((uint32_t *) (pcmd
)) = ELS_CMD_SCR
;
2963 pcmd
+= sizeof(uint32_t);
2965 /* For SCR, remainder of payload is SCR parameter page */
2966 memset(pcmd
, 0, sizeof(SCR
));
2967 ((SCR
*) pcmd
)->Function
= SCR_FUNC_FULL
;
2969 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2970 "Issue SCR: did:x%x",
2971 ndlp
->nlp_DID
, 0, 0);
2973 phba
->fc_stat
.elsXmitSCR
++;
2974 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_cmd
;
2975 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) ==
2977 /* The additional lpfc_nlp_put will cause the following
2978 * lpfc_els_free_iocb routine to trigger the rlease of
2982 lpfc_els_free_iocb(phba
, elsiocb
);
2985 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2986 * trigger the release of node.
2988 if (!(vport
->fc_flag
& FC_PT2PT
))
2994 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
2995 * @vport: pointer to a host virtual N_Port data structure.
2996 * @nportid: N_Port identifier to the remote node.
2997 * @retry: number of retries to the command IOCB.
2999 * This routine issues a Fibre Channel Address Resolution Response
3000 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
3001 * is passed into the function. It first search the @vport node list to find
3002 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
3003 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
3004 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
3006 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3007 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3008 * will be stored into the context1 field of the IOCB for the completion
3009 * callback function to the PARPR ELS command.
3012 * 0 - Successfully issued farpr command
3013 * 1 - Failed to issue farpr command
3016 lpfc_issue_els_farpr(struct lpfc_vport
*vport
, uint32_t nportid
, uint8_t retry
)
3018 struct lpfc_hba
*phba
= vport
->phba
;
3019 struct lpfc_iocbq
*elsiocb
;
3024 struct lpfc_nodelist
*ondlp
;
3025 struct lpfc_nodelist
*ndlp
;
3027 cmdsize
= (sizeof(uint32_t) + sizeof(FARP
));
3029 ndlp
= lpfc_findnode_did(vport
, nportid
);
3031 ndlp
= lpfc_nlp_init(vport
, nportid
);
3034 lpfc_enqueue_node(vport
, ndlp
);
3035 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
3036 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
3041 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
3042 ndlp
->nlp_DID
, ELS_CMD_RNID
);
3044 /* This will trigger the release of the node just
3051 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
3053 *((uint32_t *) (pcmd
)) = ELS_CMD_FARPR
;
3054 pcmd
+= sizeof(uint32_t);
3056 /* Fill in FARPR payload */
3057 fp
= (FARP
*) (pcmd
);
3058 memset(fp
, 0, sizeof(FARP
));
3059 lp
= (uint32_t *) pcmd
;
3060 *lp
++ = be32_to_cpu(nportid
);
3061 *lp
++ = be32_to_cpu(vport
->fc_myDID
);
3063 fp
->Mflags
= (FARP_MATCH_PORT
| FARP_MATCH_NODE
);
3065 memcpy(&fp
->RportName
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
3066 memcpy(&fp
->RnodeName
, &vport
->fc_nodename
, sizeof(struct lpfc_name
));
3067 ondlp
= lpfc_findnode_did(vport
, nportid
);
3068 if (ondlp
&& NLP_CHK_NODE_ACT(ondlp
)) {
3069 memcpy(&fp
->OportName
, &ondlp
->nlp_portname
,
3070 sizeof(struct lpfc_name
));
3071 memcpy(&fp
->OnodeName
, &ondlp
->nlp_nodename
,
3072 sizeof(struct lpfc_name
));
3075 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
3076 "Issue FARPR: did:x%x",
3077 ndlp
->nlp_DID
, 0, 0);
3079 phba
->fc_stat
.elsXmitFARPR
++;
3080 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_cmd
;
3081 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) ==
3083 /* The additional lpfc_nlp_put will cause the following
3084 * lpfc_els_free_iocb routine to trigger the release of
3088 lpfc_els_free_iocb(phba
, elsiocb
);
3091 /* This will cause the callback-function lpfc_cmpl_els_cmd to
3092 * trigger the release of the node.
3099 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
3100 * @vport: pointer to a host virtual N_Port data structure.
3101 * @nlp: pointer to a node-list data structure.
3103 * This routine cancels the timer with a delayed IOCB-command retry for
3104 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
3105 * removes the ELS retry event if it presents. In addition, if the
3106 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
3107 * commands are sent for the @vport's nodes that require issuing discovery
3111 lpfc_cancel_retry_delay_tmo(struct lpfc_vport
*vport
, struct lpfc_nodelist
*nlp
)
3113 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3114 struct lpfc_work_evt
*evtp
;
3116 if (!(nlp
->nlp_flag
& NLP_DELAY_TMO
))
3118 spin_lock_irq(shost
->host_lock
);
3119 nlp
->nlp_flag
&= ~NLP_DELAY_TMO
;
3120 spin_unlock_irq(shost
->host_lock
);
3121 del_timer_sync(&nlp
->nlp_delayfunc
);
3122 nlp
->nlp_last_elscmd
= 0;
3123 if (!list_empty(&nlp
->els_retry_evt
.evt_listp
)) {
3124 list_del_init(&nlp
->els_retry_evt
.evt_listp
);
3125 /* Decrement nlp reference count held for the delayed retry */
3126 evtp
= &nlp
->els_retry_evt
;
3127 lpfc_nlp_put((struct lpfc_nodelist
*)evtp
->evt_arg1
);
3129 if (nlp
->nlp_flag
& NLP_NPR_2B_DISC
) {
3130 spin_lock_irq(shost
->host_lock
);
3131 nlp
->nlp_flag
&= ~NLP_NPR_2B_DISC
;
3132 spin_unlock_irq(shost
->host_lock
);
3133 if (vport
->num_disc_nodes
) {
3134 if (vport
->port_state
< LPFC_VPORT_READY
) {
3135 /* Check if there are more ADISCs to be sent */
3136 lpfc_more_adisc(vport
);
3138 /* Check if there are more PLOGIs to be sent */
3139 lpfc_more_plogi(vport
);
3140 if (vport
->num_disc_nodes
== 0) {
3141 spin_lock_irq(shost
->host_lock
);
3142 vport
->fc_flag
&= ~FC_NDISC_ACTIVE
;
3143 spin_unlock_irq(shost
->host_lock
);
3144 lpfc_can_disctmo(vport
);
3145 lpfc_end_rscn(vport
);
3154 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
3155 * @ptr: holder for the pointer to the timer function associated data (ndlp).
3157 * This routine is invoked by the ndlp delayed-function timer to check
3158 * whether there is any pending ELS retry event(s) with the node. If not, it
3159 * simply returns. Otherwise, if there is at least one ELS delayed event, it
3160 * adds the delayed events to the HBA work list and invokes the
3161 * lpfc_worker_wake_up() routine to wake up worker thread to process the
3162 * event. Note that lpfc_nlp_get() is called before posting the event to
3163 * the work list to hold reference count of ndlp so that it guarantees the
3164 * reference to ndlp will still be available when the worker thread gets
3165 * to the event associated with the ndlp.
3168 lpfc_els_retry_delay(struct timer_list
*t
)
3170 struct lpfc_nodelist
*ndlp
= from_timer(ndlp
, t
, nlp_delayfunc
);
3171 struct lpfc_vport
*vport
= ndlp
->vport
;
3172 struct lpfc_hba
*phba
= vport
->phba
;
3173 unsigned long flags
;
3174 struct lpfc_work_evt
*evtp
= &ndlp
->els_retry_evt
;
3176 spin_lock_irqsave(&phba
->hbalock
, flags
);
3177 if (!list_empty(&evtp
->evt_listp
)) {
3178 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
3182 /* We need to hold the node by incrementing the reference
3183 * count until the queued work is done
3185 evtp
->evt_arg1
= lpfc_nlp_get(ndlp
);
3186 if (evtp
->evt_arg1
) {
3187 evtp
->evt
= LPFC_EVT_ELS_RETRY
;
3188 list_add_tail(&evtp
->evt_listp
, &phba
->work_list
);
3189 lpfc_worker_wake_up(phba
);
3191 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
3196 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
3197 * @ndlp: pointer to a node-list data structure.
3199 * This routine is the worker-thread handler for processing the @ndlp delayed
3200 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
3201 * the last ELS command from the associated ndlp and invokes the proper ELS
3202 * function according to the delayed ELS command to retry the command.
3205 lpfc_els_retry_delay_handler(struct lpfc_nodelist
*ndlp
)
3207 struct lpfc_vport
*vport
= ndlp
->vport
;
3208 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3209 uint32_t cmd
, retry
;
3211 spin_lock_irq(shost
->host_lock
);
3212 cmd
= ndlp
->nlp_last_elscmd
;
3213 ndlp
->nlp_last_elscmd
= 0;
3215 if (!(ndlp
->nlp_flag
& NLP_DELAY_TMO
)) {
3216 spin_unlock_irq(shost
->host_lock
);
3220 ndlp
->nlp_flag
&= ~NLP_DELAY_TMO
;
3221 spin_unlock_irq(shost
->host_lock
);
3223 * If a discovery event readded nlp_delayfunc after timer
3224 * firing and before processing the timer, cancel the
3227 del_timer_sync(&ndlp
->nlp_delayfunc
);
3228 retry
= ndlp
->nlp_retry
;
3229 ndlp
->nlp_retry
= 0;
3233 lpfc_issue_els_flogi(vport
, ndlp
, retry
);
3236 if (!lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, retry
)) {
3237 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
3238 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
3242 if (!lpfc_issue_els_adisc(vport
, ndlp
, retry
)) {
3243 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
3244 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_ADISC_ISSUE
);
3248 case ELS_CMD_NVMEPRLI
:
3249 if (!lpfc_issue_els_prli(vport
, ndlp
, retry
)) {
3250 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
3251 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PRLI_ISSUE
);
3255 if (!lpfc_issue_els_logo(vport
, ndlp
, retry
)) {
3256 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
3257 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_LOGO_ISSUE
);
3261 if (!(vport
->fc_flag
& FC_VPORT_NEEDS_INIT_VPI
))
3262 lpfc_issue_els_fdisc(vport
, ndlp
, retry
);
3269 * lpfc_els_retry - Make retry decision on an els command iocb
3270 * @phba: pointer to lpfc hba data structure.
3271 * @cmdiocb: pointer to lpfc command iocb data structure.
3272 * @rspiocb: pointer to lpfc response iocb data structure.
3274 * This routine makes a retry decision on an ELS command IOCB, which has
3275 * failed. The following ELS IOCBs use this function for retrying the command
3276 * when previously issued command responsed with error status: FLOGI, PLOGI,
3277 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
3278 * returned error status, it makes the decision whether a retry shall be
3279 * issued for the command, and whether a retry shall be made immediately or
3280 * delayed. In the former case, the corresponding ELS command issuing-function
3281 * is called to retry the command. In the later case, the ELS command shall
3282 * be posted to the ndlp delayed event and delayed function timer set to the
3283 * ndlp for the delayed command issusing.
3286 * 0 - No retry of els command is made
3287 * 1 - Immediate or delayed retry of els command is made
3290 lpfc_els_retry(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
3291 struct lpfc_iocbq
*rspiocb
)
3293 struct lpfc_vport
*vport
= cmdiocb
->vport
;
3294 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3295 IOCB_t
*irsp
= &rspiocb
->iocb
;
3296 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
3297 struct lpfc_dmabuf
*pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
3300 int retry
= 0, maxretry
= lpfc_max_els_tries
, delay
= 0;
3306 /* Note: context2 may be 0 for internal driver abort
3307 * of delays ELS command.
3310 if (pcmd
&& pcmd
->virt
) {
3311 elscmd
= (uint32_t *) (pcmd
->virt
);
3315 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
))
3316 did
= ndlp
->nlp_DID
;
3318 /* We should only hit this case for retrying PLOGI */
3319 did
= irsp
->un
.elsreq64
.remoteID
;
3320 ndlp
= lpfc_findnode_did(vport
, did
);
3321 if ((!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
))
3322 && (cmd
!= ELS_CMD_PLOGI
))
3326 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
3327 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
3328 *(((uint32_t *) irsp
) + 7), irsp
->un
.ulpWord
[4], ndlp
->nlp_DID
);
3330 switch (irsp
->ulpStatus
) {
3331 case IOSTAT_FCP_RSP_ERROR
:
3333 case IOSTAT_REMOTE_STOP
:
3334 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
3335 /* This IO was aborted by the target, we don't
3336 * know the rxid and because we did not send the
3337 * ABTS we cannot generate and RRQ.
3339 lpfc_set_rrq_active(phba
, ndlp
,
3340 cmdiocb
->sli4_lxritag
, 0, 0);
3343 case IOSTAT_LOCAL_REJECT
:
3344 switch ((irsp
->un
.ulpWord
[4] & IOERR_PARAM_MASK
)) {
3345 case IOERR_LOOP_OPEN_FAILURE
:
3346 if (cmd
== ELS_CMD_FLOGI
) {
3347 if (PCI_DEVICE_ID_HORNET
==
3348 phba
->pcidev
->device
) {
3349 phba
->fc_topology
= LPFC_TOPOLOGY_LOOP
;
3350 phba
->pport
->fc_myDID
= 0;
3351 phba
->alpa_map
[0] = 0;
3352 phba
->alpa_map
[1] = 0;
3355 if (cmd
== ELS_CMD_PLOGI
&& cmdiocb
->retry
== 0)
3360 case IOERR_ILLEGAL_COMMAND
:
3361 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
3362 "0124 Retry illegal cmd x%x "
3363 "retry:x%x delay:x%x\n",
3364 cmd
, cmdiocb
->retry
, delay
);
3366 /* All command's retry policy */
3368 if (cmdiocb
->retry
> 2)
3372 case IOERR_NO_RESOURCES
:
3373 logerr
= 1; /* HBA out of resources */
3375 if (cmdiocb
->retry
> 100)
3380 case IOERR_ILLEGAL_FRAME
:
3385 case IOERR_SEQUENCE_TIMEOUT
:
3386 case IOERR_INVALID_RPI
:
3387 if (cmd
== ELS_CMD_PLOGI
&&
3388 did
== NameServer_DID
) {
3389 /* Continue forever if plogi to */
3390 /* the nameserver fails */
3399 case IOSTAT_NPORT_RJT
:
3400 case IOSTAT_FABRIC_RJT
:
3401 if (irsp
->un
.ulpWord
[4] & RJT_UNAVAIL_TEMP
) {
3407 case IOSTAT_NPORT_BSY
:
3408 case IOSTAT_FABRIC_BSY
:
3409 logerr
= 1; /* Fabric / Remote NPort out of resources */
3414 stat
.un
.lsRjtError
= be32_to_cpu(irsp
->un
.ulpWord
[4]);
3415 /* Added for Vendor specifc support
3416 * Just keep retrying for these Rsn / Exp codes
3418 switch (stat
.un
.b
.lsRjtRsnCode
) {
3419 case LSRJT_UNABLE_TPC
:
3420 /* The driver has a VALID PLOGI but the rport has
3421 * rejected the PRLI - can't do it now. Delay
3422 * for 1 second and try again - don't care about
3425 if (cmd
== ELS_CMD_PRLI
|| cmd
== ELS_CMD_NVMEPRLI
) {
3427 maxretry
= lpfc_max_els_tries
+ 1;
3432 /* Legacy bug fix code for targets with PLOGI delays. */
3433 if (stat
.un
.b
.lsRjtRsnCodeExp
==
3434 LSEXP_CMD_IN_PROGRESS
) {
3435 if (cmd
== ELS_CMD_PLOGI
) {
3442 if (stat
.un
.b
.lsRjtRsnCodeExp
==
3443 LSEXP_CANT_GIVE_DATA
) {
3444 if (cmd
== ELS_CMD_PLOGI
) {
3451 if (cmd
== ELS_CMD_PLOGI
) {
3453 maxretry
= lpfc_max_els_tries
+ 1;
3457 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
3458 (cmd
== ELS_CMD_FDISC
) &&
3459 (stat
.un
.b
.lsRjtRsnCodeExp
== LSEXP_OUT_OF_RESOURCE
)){
3460 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
3461 "0125 FDISC Failed (x%x). "
3462 "Fabric out of resources\n",
3463 stat
.un
.lsRjtError
);
3464 lpfc_vport_set_state(vport
,
3465 FC_VPORT_NO_FABRIC_RSCS
);
3469 case LSRJT_LOGICAL_BSY
:
3470 if ((cmd
== ELS_CMD_PLOGI
) ||
3471 (cmd
== ELS_CMD_PRLI
) ||
3472 (cmd
== ELS_CMD_NVMEPRLI
)) {
3475 } else if (cmd
== ELS_CMD_FDISC
) {
3476 /* FDISC retry policy */
3478 if (cmdiocb
->retry
>= 32)
3484 case LSRJT_LOGICAL_ERR
:
3485 /* There are some cases where switches return this
3486 * error when they are not ready and should be returning
3487 * Logical Busy. We should delay every time.
3489 if (cmd
== ELS_CMD_FDISC
&&
3490 stat
.un
.b
.lsRjtRsnCodeExp
== LSEXP_PORT_LOGIN_REQ
) {
3494 } else if (cmd
== ELS_CMD_FLOGI
&&
3495 stat
.un
.b
.lsRjtRsnCodeExp
==
3496 LSEXP_NOTHING_MORE
) {
3497 vport
->fc_sparam
.cmn
.bbRcvSizeMsb
&= 0xf;
3499 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
3500 "0820 FLOGI Failed (x%x). "
3501 "BBCredit Not Supported\n",
3502 stat
.un
.lsRjtError
);
3506 case LSRJT_PROTOCOL_ERR
:
3507 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
3508 (cmd
== ELS_CMD_FDISC
) &&
3509 ((stat
.un
.b
.lsRjtRsnCodeExp
== LSEXP_INVALID_PNAME
) ||
3510 (stat
.un
.b
.lsRjtRsnCodeExp
== LSEXP_INVALID_NPORT_ID
))
3512 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
3513 "0122 FDISC Failed (x%x). "
3514 "Fabric Detected Bad WWN\n",
3515 stat
.un
.lsRjtError
);
3516 lpfc_vport_set_state(vport
,
3517 FC_VPORT_FABRIC_REJ_WWN
);
3520 case LSRJT_VENDOR_UNIQUE
:
3521 if ((stat
.un
.b
.vendorUnique
== 0x45) &&
3522 (cmd
== ELS_CMD_FLOGI
)) {
3526 case LSRJT_CMD_UNSUPPORTED
:
3527 /* lpfc nvmet returns this type of LS_RJT when it
3528 * receives an FCP PRLI because lpfc nvmet only
3529 * support NVME. ELS request is terminated for FCP4
3532 if (stat
.un
.b
.lsRjtRsnCodeExp
==
3533 LSEXP_REQ_UNSUPPORTED
&& cmd
== ELS_CMD_PRLI
) {
3534 spin_lock_irq(shost
->host_lock
);
3535 ndlp
->nlp_flag
|= NLP_FCP_PRLI_RJT
;
3536 spin_unlock_irq(shost
->host_lock
);
3544 case IOSTAT_INTERMED_RSP
:
3552 if (did
== FDMI_DID
)
3555 if ((cmd
== ELS_CMD_FLOGI
) &&
3556 (phba
->fc_topology
!= LPFC_TOPOLOGY_LOOP
) &&
3557 !lpfc_error_lost_link(irsp
)) {
3558 /* FLOGI retry policy */
3560 /* retry FLOGI forever */
3561 if (phba
->link_flag
!= LS_LOOPBACK_MODE
)
3566 if (cmdiocb
->retry
>= 100)
3568 else if (cmdiocb
->retry
>= 32)
3570 } else if ((cmd
== ELS_CMD_FDISC
) && !lpfc_error_lost_link(irsp
)) {
3571 /* retry FDISCs every second up to devloss */
3573 maxretry
= vport
->cfg_devloss_tmo
;
3578 if (maxretry
&& (cmdiocb
->retry
>= maxretry
)) {
3579 phba
->fc_stat
.elsRetryExceeded
++;
3583 if ((vport
->load_flag
& FC_UNLOADING
) != 0)
3588 if ((cmd
== ELS_CMD_PLOGI
) || (cmd
== ELS_CMD_FDISC
)) {
3589 /* Stop retrying PLOGI and FDISC if in FCF discovery */
3590 if (phba
->fcf
.fcf_flag
& FCF_DISCOVERY
) {
3591 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3592 "2849 Stop retry ELS command "
3593 "x%x to remote NPORT x%x, "
3594 "Data: x%x x%x\n", cmd
, did
,
3595 cmdiocb
->retry
, delay
);
3600 /* Retry ELS command <elsCmd> to remote NPORT <did> */
3601 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3602 "0107 Retry ELS command x%x to remote "
3603 "NPORT x%x Data: x%x x%x\n",
3604 cmd
, did
, cmdiocb
->retry
, delay
);
3606 if (((cmd
== ELS_CMD_PLOGI
) || (cmd
== ELS_CMD_ADISC
)) &&
3607 ((irsp
->ulpStatus
!= IOSTAT_LOCAL_REJECT
) ||
3608 ((irsp
->un
.ulpWord
[4] & IOERR_PARAM_MASK
) !=
3609 IOERR_NO_RESOURCES
))) {
3610 /* Don't reset timer for no resources */
3612 /* If discovery / RSCN timer is running, reset it */
3613 if (timer_pending(&vport
->fc_disctmo
) ||
3614 (vport
->fc_flag
& FC_RSCN_MODE
))
3615 lpfc_set_disctmo(vport
);
3618 phba
->fc_stat
.elsXmitRetry
++;
3619 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
) && delay
) {
3620 phba
->fc_stat
.elsDelayRetry
++;
3621 ndlp
->nlp_retry
= cmdiocb
->retry
;
3623 /* delay is specified in milliseconds */
3624 mod_timer(&ndlp
->nlp_delayfunc
,
3625 jiffies
+ msecs_to_jiffies(delay
));
3626 spin_lock_irq(shost
->host_lock
);
3627 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
3628 spin_unlock_irq(shost
->host_lock
);
3630 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
3631 if ((cmd
== ELS_CMD_PRLI
) ||
3632 (cmd
== ELS_CMD_NVMEPRLI
))
3633 lpfc_nlp_set_state(vport
, ndlp
,
3634 NLP_STE_PRLI_ISSUE
);
3636 lpfc_nlp_set_state(vport
, ndlp
,
3638 ndlp
->nlp_last_elscmd
= cmd
;
3644 lpfc_issue_els_flogi(vport
, ndlp
, cmdiocb
->retry
);
3647 lpfc_issue_els_fdisc(vport
, ndlp
, cmdiocb
->retry
);
3650 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
)) {
3651 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
3652 lpfc_nlp_set_state(vport
, ndlp
,
3653 NLP_STE_PLOGI_ISSUE
);
3655 lpfc_issue_els_plogi(vport
, did
, cmdiocb
->retry
);
3658 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
3659 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_ADISC_ISSUE
);
3660 lpfc_issue_els_adisc(vport
, ndlp
, cmdiocb
->retry
);
3663 case ELS_CMD_NVMEPRLI
:
3664 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
3665 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PRLI_ISSUE
);
3666 lpfc_issue_els_prli(vport
, ndlp
, cmdiocb
->retry
);
3669 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
3670 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_LOGO_ISSUE
);
3671 lpfc_issue_els_logo(vport
, ndlp
, cmdiocb
->retry
);
3675 /* No retry ELS command <elsCmd> to remote NPORT <did> */
3677 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
3678 "0137 No retry ELS command x%x to remote "
3679 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
3680 cmd
, did
, irsp
->ulpStatus
,
3681 irsp
->un
.ulpWord
[4]);
3684 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3685 "0108 No retry ELS command x%x to remote "
3686 "NPORT x%x Retried:%d Error:x%x/%x\n",
3687 cmd
, did
, cmdiocb
->retry
, irsp
->ulpStatus
,
3688 irsp
->un
.ulpWord
[4]);
3694 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
3695 * @phba: pointer to lpfc hba data structure.
3696 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
3698 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
3699 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
3700 * checks to see whether there is a lpfc DMA buffer associated with the
3701 * response of the command IOCB. If so, it will be released before releasing
3702 * the lpfc DMA buffer associated with the IOCB itself.
3705 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3708 lpfc_els_free_data(struct lpfc_hba
*phba
, struct lpfc_dmabuf
*buf_ptr1
)
3710 struct lpfc_dmabuf
*buf_ptr
;
3712 /* Free the response before processing the command. */
3713 if (!list_empty(&buf_ptr1
->list
)) {
3714 list_remove_head(&buf_ptr1
->list
, buf_ptr
,
3717 lpfc_mbuf_free(phba
, buf_ptr
->virt
, buf_ptr
->phys
);
3720 lpfc_mbuf_free(phba
, buf_ptr1
->virt
, buf_ptr1
->phys
);
3726 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
3727 * @phba: pointer to lpfc hba data structure.
3728 * @buf_ptr: pointer to the lpfc dma buffer data structure.
3730 * This routine releases the lpfc Direct Memory Access (DMA) buffer
3731 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
3735 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3738 lpfc_els_free_bpl(struct lpfc_hba
*phba
, struct lpfc_dmabuf
*buf_ptr
)
3740 lpfc_mbuf_free(phba
, buf_ptr
->virt
, buf_ptr
->phys
);
3746 * lpfc_els_free_iocb - Free a command iocb and its associated resources
3747 * @phba: pointer to lpfc hba data structure.
3748 * @elsiocb: pointer to lpfc els command iocb data structure.
3750 * This routine frees a command IOCB and its associated resources. The
3751 * command IOCB data structure contains the reference to various associated
3752 * resources, these fields must be set to NULL if the associated reference
3754 * context1 - reference to ndlp
3755 * context2 - reference to cmd
3756 * context2->next - reference to rsp
3757 * context3 - reference to bpl
3759 * It first properly decrements the reference count held on ndlp for the
3760 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
3761 * set, it invokes the lpfc_els_free_data() routine to release the Direct
3762 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
3763 * adds the DMA buffer the @phba data structure for the delayed release.
3764 * If reference to the Buffer Pointer List (BPL) is present, the
3765 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
3766 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
3767 * invoked to release the IOCB data structure back to @phba IOCBQ list.
3770 * 0 - Success (currently, always return 0)
3773 lpfc_els_free_iocb(struct lpfc_hba
*phba
, struct lpfc_iocbq
*elsiocb
)
3775 struct lpfc_dmabuf
*buf_ptr
, *buf_ptr1
;
3776 struct lpfc_nodelist
*ndlp
;
3778 ndlp
= (struct lpfc_nodelist
*)elsiocb
->context1
;
3780 if (ndlp
->nlp_flag
& NLP_DEFER_RM
) {
3783 /* If the ndlp is not being used by another discovery
3786 if (!lpfc_nlp_not_used(ndlp
)) {
3787 /* If ndlp is being used by another discovery
3788 * thread, just clear NLP_DEFER_RM
3790 ndlp
->nlp_flag
&= ~NLP_DEFER_RM
;
3795 elsiocb
->context1
= NULL
;
3797 /* context2 = cmd, context2->next = rsp, context3 = bpl */
3798 if (elsiocb
->context2
) {
3799 if (elsiocb
->iocb_flag
& LPFC_DELAY_MEM_FREE
) {
3800 /* Firmware could still be in progress of DMAing
3801 * payload, so don't free data buffer till after
3804 elsiocb
->iocb_flag
&= ~LPFC_DELAY_MEM_FREE
;
3805 buf_ptr
= elsiocb
->context2
;
3806 elsiocb
->context2
= NULL
;
3809 spin_lock_irq(&phba
->hbalock
);
3810 if (!list_empty(&buf_ptr
->list
)) {
3811 list_remove_head(&buf_ptr
->list
,
3812 buf_ptr1
, struct lpfc_dmabuf
,
3814 INIT_LIST_HEAD(&buf_ptr1
->list
);
3815 list_add_tail(&buf_ptr1
->list
,
3819 INIT_LIST_HEAD(&buf_ptr
->list
);
3820 list_add_tail(&buf_ptr
->list
, &phba
->elsbuf
);
3822 spin_unlock_irq(&phba
->hbalock
);
3825 buf_ptr1
= (struct lpfc_dmabuf
*) elsiocb
->context2
;
3826 lpfc_els_free_data(phba
, buf_ptr1
);
3827 elsiocb
->context2
= NULL
;
3831 if (elsiocb
->context3
) {
3832 buf_ptr
= (struct lpfc_dmabuf
*) elsiocb
->context3
;
3833 lpfc_els_free_bpl(phba
, buf_ptr
);
3834 elsiocb
->context3
= NULL
;
3836 lpfc_sli_release_iocbq(phba
, elsiocb
);
3841 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
3842 * @phba: pointer to lpfc hba data structure.
3843 * @cmdiocb: pointer to lpfc command iocb data structure.
3844 * @rspiocb: pointer to lpfc response iocb data structure.
3846 * This routine is the completion callback function to the Logout (LOGO)
3847 * Accept (ACC) Response ELS command. This routine is invoked to indicate
3848 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
3849 * release the ndlp if it has the last reference remaining (reference count
3850 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
3851 * field to NULL to inform the following lpfc_els_free_iocb() routine no
3852 * ndlp reference count needs to be decremented. Otherwise, the ndlp
3853 * reference use-count shall be decremented by the lpfc_els_free_iocb()
3854 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
3855 * IOCB data structure.
3858 lpfc_cmpl_els_logo_acc(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
3859 struct lpfc_iocbq
*rspiocb
)
3861 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
3862 struct lpfc_vport
*vport
= cmdiocb
->vport
;
3865 irsp
= &rspiocb
->iocb
;
3866 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
3867 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
3868 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4], ndlp
->nlp_DID
);
3869 /* ACC to LOGO completes to NPort <nlp_DID> */
3870 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3871 "0109 ACC to LOGO completes to NPort x%x "
3872 "Data: x%x x%x x%x\n",
3873 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
3876 if (ndlp
->nlp_state
== NLP_STE_NPR_NODE
) {
3877 /* NPort Recovery mode or node is just allocated */
3878 if (!lpfc_nlp_not_used(ndlp
)) {
3879 /* If the ndlp is being used by another discovery
3880 * thread, just unregister the RPI.
3882 lpfc_unreg_rpi(vport
, ndlp
);
3884 /* Indicate the node has already released, should
3885 * not reference to it from within lpfc_els_free_iocb.
3887 cmdiocb
->context1
= NULL
;
3892 * The driver received a LOGO from the rport and has ACK'd it.
3893 * At this point, the driver is done so release the IOCB
3895 lpfc_els_free_iocb(phba
, cmdiocb
);
3899 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
3900 * @phba: pointer to lpfc hba data structure.
3901 * @pmb: pointer to the driver internal queue element for mailbox command.
3903 * This routine is the completion callback function for unregister default
3904 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
3905 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
3906 * decrements the ndlp reference count held for this completion callback
3907 * function. After that, it invokes the lpfc_nlp_not_used() to check
3908 * whether there is only one reference left on the ndlp. If so, it will
3909 * perform one more decrement and trigger the release of the ndlp.
3912 lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
3914 struct lpfc_dmabuf
*mp
= (struct lpfc_dmabuf
*) (pmb
->context1
);
3915 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
3917 pmb
->context1
= NULL
;
3918 pmb
->context2
= NULL
;
3920 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
3922 mempool_free(pmb
, phba
->mbox_mem_pool
);
3924 lpfc_printf_vlog(ndlp
->vport
, KERN_INFO
, LOG_NODE
,
3925 "0006 rpi%x DID:%x flg:%x %d map:%x %p\n",
3926 ndlp
->nlp_rpi
, ndlp
->nlp_DID
, ndlp
->nlp_flag
,
3927 kref_read(&ndlp
->kref
),
3928 ndlp
->nlp_usg_map
, ndlp
);
3929 if (NLP_CHK_NODE_ACT(ndlp
)) {
3931 /* This is the end of the default RPI cleanup logic for
3932 * this ndlp. If no other discovery threads are using
3933 * this ndlp, free all resources associated with it.
3935 lpfc_nlp_not_used(ndlp
);
3937 lpfc_drop_node(ndlp
->vport
, ndlp
);
3945 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
3946 * @phba: pointer to lpfc hba data structure.
3947 * @cmdiocb: pointer to lpfc command iocb data structure.
3948 * @rspiocb: pointer to lpfc response iocb data structure.
3950 * This routine is the completion callback function for ELS Response IOCB
3951 * command. In normal case, this callback function just properly sets the
3952 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
3953 * field in the command IOCB is not NULL, the referred mailbox command will
3954 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
3955 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
3956 * link down event occurred during the discovery, the lpfc_nlp_not_used()
3957 * routine shall be invoked trying to release the ndlp if no other threads
3958 * are currently referring it.
3961 lpfc_cmpl_els_rsp(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
3962 struct lpfc_iocbq
*rspiocb
)
3964 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
3965 struct lpfc_vport
*vport
= ndlp
? ndlp
->vport
: NULL
;
3966 struct Scsi_Host
*shost
= vport
? lpfc_shost_from_vport(vport
) : NULL
;
3969 LPFC_MBOXQ_t
*mbox
= NULL
;
3970 struct lpfc_dmabuf
*mp
= NULL
;
3971 uint32_t ls_rjt
= 0;
3973 irsp
= &rspiocb
->iocb
;
3975 if (cmdiocb
->context_un
.mbox
)
3976 mbox
= cmdiocb
->context_un
.mbox
;
3978 /* First determine if this is a LS_RJT cmpl. Note, this callback
3979 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
3981 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) cmdiocb
->context2
)->virt
);
3982 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
) &&
3983 (*((uint32_t *) (pcmd
)) == ELS_CMD_LS_RJT
)) {
3984 /* A LS_RJT associated with Default RPI cleanup has its own
3985 * separate code path.
3987 if (!(ndlp
->nlp_flag
& NLP_RM_DFLT_RPI
))
3991 /* Check to see if link went down during discovery */
3992 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
) || lpfc_els_chk_latt(vport
)) {
3994 mp
= (struct lpfc_dmabuf
*) mbox
->context1
;
3996 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
3999 mempool_free(mbox
, phba
->mbox_mem_pool
);
4001 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
) &&
4002 (ndlp
->nlp_flag
& NLP_RM_DFLT_RPI
))
4003 if (lpfc_nlp_not_used(ndlp
)) {
4005 /* Indicate the node has already released,
4006 * should not reference to it from within
4007 * the routine lpfc_els_free_iocb.
4009 cmdiocb
->context1
= NULL
;
4014 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
4015 "ELS rsp cmpl: status:x%x/x%x did:x%x",
4016 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
4017 cmdiocb
->iocb
.un
.elsreq64
.remoteID
);
4018 /* ELS response tag <ulpIoTag> completes */
4019 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
4020 "0110 ELS response tag x%x completes "
4021 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
4022 cmdiocb
->iocb
.ulpIoTag
, rspiocb
->iocb
.ulpStatus
,
4023 rspiocb
->iocb
.un
.ulpWord
[4], rspiocb
->iocb
.ulpTimeout
,
4024 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
4027 if ((rspiocb
->iocb
.ulpStatus
== 0)
4028 && (ndlp
->nlp_flag
& NLP_ACC_REGLOGIN
)) {
4029 if (!lpfc_unreg_rpi(vport
, ndlp
) &&
4030 (ndlp
->nlp_state
== NLP_STE_PLOGI_ISSUE
||
4031 ndlp
->nlp_state
== NLP_STE_REG_LOGIN_ISSUE
)) {
4032 lpfc_printf_vlog(vport
, KERN_INFO
,
4034 "0314 PLOGI recov DID x%x "
4035 "Data: x%x x%x x%x\n",
4036 ndlp
->nlp_DID
, ndlp
->nlp_state
,
4037 ndlp
->nlp_rpi
, ndlp
->nlp_flag
);
4038 mp
= mbox
->context1
;
4040 lpfc_mbuf_free(phba
, mp
->virt
,
4044 mempool_free(mbox
, phba
->mbox_mem_pool
);
4048 /* Increment reference count to ndlp to hold the
4049 * reference to ndlp for the callback function.
4051 mbox
->context2
= lpfc_nlp_get(ndlp
);
4052 mbox
->vport
= vport
;
4053 if (ndlp
->nlp_flag
& NLP_RM_DFLT_RPI
) {
4054 mbox
->mbox_flag
|= LPFC_MBX_IMED_UNREG
;
4055 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_dflt_rpi
;
4058 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_reg_login
;
4059 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
4060 lpfc_nlp_set_state(vport
, ndlp
,
4061 NLP_STE_REG_LOGIN_ISSUE
);
4064 ndlp
->nlp_flag
|= NLP_REG_LOGIN_SEND
;
4065 if (lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
)
4066 != MBX_NOT_FINISHED
)
4069 /* Decrement the ndlp reference count we
4070 * set for this failed mailbox command.
4073 ndlp
->nlp_flag
&= ~NLP_REG_LOGIN_SEND
;
4075 /* ELS rsp: Cannot issue reg_login for <NPortid> */
4076 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
4077 "0138 ELS rsp: Cannot issue reg_login for x%x "
4078 "Data: x%x x%x x%x\n",
4079 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
4082 if (lpfc_nlp_not_used(ndlp
)) {
4084 /* Indicate node has already been released,
4085 * should not reference to it from within
4086 * the routine lpfc_els_free_iocb.
4088 cmdiocb
->context1
= NULL
;
4091 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
4092 if (!lpfc_error_lost_link(irsp
) &&
4093 ndlp
->nlp_flag
& NLP_ACC_REGLOGIN
) {
4094 if (lpfc_nlp_not_used(ndlp
)) {
4096 /* Indicate node has already been
4097 * released, should not reference
4098 * to it from within the routine
4099 * lpfc_els_free_iocb.
4101 cmdiocb
->context1
= NULL
;
4105 mp
= (struct lpfc_dmabuf
*) mbox
->context1
;
4107 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
4110 mempool_free(mbox
, phba
->mbox_mem_pool
);
4113 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
) && shost
) {
4114 spin_lock_irq(shost
->host_lock
);
4115 ndlp
->nlp_flag
&= ~(NLP_ACC_REGLOGIN
| NLP_RM_DFLT_RPI
);
4116 spin_unlock_irq(shost
->host_lock
);
4118 /* If the node is not being used by another discovery thread,
4119 * and we are sending a reject, we are done with it.
4120 * Release driver reference count here and free associated
4124 if (lpfc_nlp_not_used(ndlp
))
4125 /* Indicate node has already been released,
4126 * should not reference to it from within
4127 * the routine lpfc_els_free_iocb.
4129 cmdiocb
->context1
= NULL
;
4133 lpfc_els_free_iocb(phba
, cmdiocb
);
4138 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
4139 * @vport: pointer to a host virtual N_Port data structure.
4140 * @flag: the els command code to be accepted.
4141 * @oldiocb: pointer to the original lpfc command iocb data structure.
4142 * @ndlp: pointer to a node-list data structure.
4143 * @mbox: pointer to the driver internal queue element for mailbox command.
4145 * This routine prepares and issues an Accept (ACC) response IOCB
4146 * command. It uses the @flag to properly set up the IOCB field for the
4147 * specific ACC response command to be issued and invokes the
4148 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
4149 * @mbox pointer is passed in, it will be put into the context_un.mbox
4150 * field of the IOCB for the completion callback function to issue the
4151 * mailbox command to the HBA later when callback is invoked.
4153 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4154 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4155 * will be stored into the context1 field of the IOCB for the completion
4156 * callback function to the corresponding response ELS IOCB command.
4159 * 0 - Successfully issued acc response
4160 * 1 - Failed to issue acc response
4163 lpfc_els_rsp_acc(struct lpfc_vport
*vport
, uint32_t flag
,
4164 struct lpfc_iocbq
*oldiocb
, struct lpfc_nodelist
*ndlp
,
4167 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4168 struct lpfc_hba
*phba
= vport
->phba
;
4171 struct lpfc_iocbq
*elsiocb
;
4173 struct serv_parm
*sp
;
4176 ELS_PKT
*els_pkt_ptr
;
4178 oldcmd
= &oldiocb
->iocb
;
4182 cmdsize
= sizeof(uint32_t);
4183 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
,
4184 ndlp
, ndlp
->nlp_DID
, ELS_CMD_ACC
);
4186 spin_lock_irq(shost
->host_lock
);
4187 ndlp
->nlp_flag
&= ~NLP_LOGO_ACC
;
4188 spin_unlock_irq(shost
->host_lock
);
4192 icmd
= &elsiocb
->iocb
;
4193 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri / rx_id */
4194 icmd
->unsli3
.rcvsli3
.ox_id
= oldcmd
->unsli3
.rcvsli3
.ox_id
;
4195 pcmd
= (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
4196 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
4197 pcmd
+= sizeof(uint32_t);
4199 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
4200 "Issue ACC: did:x%x flg:x%x",
4201 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
4205 cmdsize
= (sizeof(struct serv_parm
) + sizeof(uint32_t));
4206 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
,
4207 ndlp
, ndlp
->nlp_DID
, ELS_CMD_ACC
);
4211 icmd
= &elsiocb
->iocb
;
4212 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri / rx_id */
4213 icmd
->unsli3
.rcvsli3
.ox_id
= oldcmd
->unsli3
.rcvsli3
.ox_id
;
4214 pcmd
= (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
4217 elsiocb
->context_un
.mbox
= mbox
;
4219 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
4220 pcmd
+= sizeof(uint32_t);
4221 sp
= (struct serv_parm
*)pcmd
;
4223 if (flag
== ELS_CMD_FLOGI
) {
4224 /* Copy the received service parameters back */
4225 memcpy(sp
, &phba
->fc_fabparam
,
4226 sizeof(struct serv_parm
));
4228 /* Clear the F_Port bit */
4231 /* Mark all class service parameters as invalid */
4232 sp
->cls1
.classValid
= 0;
4233 sp
->cls2
.classValid
= 0;
4234 sp
->cls3
.classValid
= 0;
4235 sp
->cls4
.classValid
= 0;
4237 /* Copy our worldwide names */
4238 memcpy(&sp
->portName
, &vport
->fc_sparam
.portName
,
4239 sizeof(struct lpfc_name
));
4240 memcpy(&sp
->nodeName
, &vport
->fc_sparam
.nodeName
,
4241 sizeof(struct lpfc_name
));
4243 memcpy(pcmd
, &vport
->fc_sparam
,
4244 sizeof(struct serv_parm
));
4246 sp
->cmn
.valid_vendor_ver_level
= 0;
4247 memset(sp
->un
.vendorVersion
, 0,
4248 sizeof(sp
->un
.vendorVersion
));
4249 sp
->cmn
.bbRcvSizeMsb
&= 0xF;
4251 /* If our firmware supports this feature, convey that
4252 * info to the target using the vendor specific field.
4254 if (phba
->sli
.sli_flag
& LPFC_SLI_SUPPRESS_RSP
) {
4255 sp
->cmn
.valid_vendor_ver_level
= 1;
4256 sp
->un
.vv
.vid
= cpu_to_be32(LPFC_VV_EMLX_ID
);
4258 cpu_to_be32(LPFC_VV_SUPPRESS_RSP
);
4262 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
4263 "Issue ACC FLOGI/PLOGI: did:x%x flg:x%x",
4264 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
4267 cmdsize
= sizeof(uint32_t) + sizeof(PRLO
);
4268 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
,
4269 ndlp
, ndlp
->nlp_DID
, ELS_CMD_PRLO
);
4273 icmd
= &elsiocb
->iocb
;
4274 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri / rx_id */
4275 icmd
->unsli3
.rcvsli3
.ox_id
= oldcmd
->unsli3
.rcvsli3
.ox_id
;
4276 pcmd
= (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
4278 memcpy(pcmd
, ((struct lpfc_dmabuf
*) oldiocb
->context2
)->virt
,
4279 sizeof(uint32_t) + sizeof(PRLO
));
4280 *((uint32_t *) (pcmd
)) = ELS_CMD_PRLO_ACC
;
4281 els_pkt_ptr
= (ELS_PKT
*) pcmd
;
4282 els_pkt_ptr
->un
.prlo
.acceptRspCode
= PRLO_REQ_EXECUTED
;
4284 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
4285 "Issue ACC PRLO: did:x%x flg:x%x",
4286 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
4291 if (ndlp
->nlp_flag
& NLP_LOGO_ACC
) {
4292 spin_lock_irq(shost
->host_lock
);
4293 if (!(ndlp
->nlp_flag
& NLP_RPI_REGISTERED
||
4294 ndlp
->nlp_flag
& NLP_REG_LOGIN_SEND
))
4295 ndlp
->nlp_flag
&= ~NLP_LOGO_ACC
;
4296 spin_unlock_irq(shost
->host_lock
);
4297 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_logo_acc
;
4299 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
4302 phba
->fc_stat
.elsXmitACC
++;
4303 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
4304 if (rc
== IOCB_ERROR
) {
4305 lpfc_els_free_iocb(phba
, elsiocb
);
4312 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
4313 * @vport: pointer to a virtual N_Port data structure.
4315 * @oldiocb: pointer to the original lpfc command iocb data structure.
4316 * @ndlp: pointer to a node-list data structure.
4317 * @mbox: pointer to the driver internal queue element for mailbox command.
4319 * This routine prepares and issue an Reject (RJT) response IOCB
4320 * command. If a @mbox pointer is passed in, it will be put into the
4321 * context_un.mbox field of the IOCB for the completion callback function
4322 * to issue to the HBA later.
4324 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4325 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4326 * will be stored into the context1 field of the IOCB for the completion
4327 * callback function to the reject response ELS IOCB command.
4330 * 0 - Successfully issued reject response
4331 * 1 - Failed to issue reject response
4334 lpfc_els_rsp_reject(struct lpfc_vport
*vport
, uint32_t rejectError
,
4335 struct lpfc_iocbq
*oldiocb
, struct lpfc_nodelist
*ndlp
,
4338 struct lpfc_hba
*phba
= vport
->phba
;
4341 struct lpfc_iocbq
*elsiocb
;
4346 cmdsize
= 2 * sizeof(uint32_t);
4347 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
4348 ndlp
->nlp_DID
, ELS_CMD_LS_RJT
);
4352 icmd
= &elsiocb
->iocb
;
4353 oldcmd
= &oldiocb
->iocb
;
4354 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri / rx_id */
4355 icmd
->unsli3
.rcvsli3
.ox_id
= oldcmd
->unsli3
.rcvsli3
.ox_id
;
4356 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
4358 *((uint32_t *) (pcmd
)) = ELS_CMD_LS_RJT
;
4359 pcmd
+= sizeof(uint32_t);
4360 *((uint32_t *) (pcmd
)) = rejectError
;
4363 elsiocb
->context_un
.mbox
= mbox
;
4365 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
4366 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
4367 "0129 Xmit ELS RJT x%x response tag x%x "
4368 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
4370 rejectError
, elsiocb
->iotag
,
4371 elsiocb
->iocb
.ulpContext
, ndlp
->nlp_DID
,
4372 ndlp
->nlp_flag
, ndlp
->nlp_state
, ndlp
->nlp_rpi
);
4373 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
4374 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
4375 ndlp
->nlp_DID
, ndlp
->nlp_flag
, rejectError
);
4377 phba
->fc_stat
.elsXmitLSRJT
++;
4378 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
4379 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
4381 if (rc
== IOCB_ERROR
) {
4382 lpfc_els_free_iocb(phba
, elsiocb
);
4389 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
4390 * @vport: pointer to a virtual N_Port data structure.
4391 * @oldiocb: pointer to the original lpfc command iocb data structure.
4392 * @ndlp: pointer to a node-list data structure.
4394 * This routine prepares and issues an Accept (ACC) response to Address
4395 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
4396 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
4398 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4399 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4400 * will be stored into the context1 field of the IOCB for the completion
4401 * callback function to the ADISC Accept response ELS IOCB command.
4404 * 0 - Successfully issued acc adisc response
4405 * 1 - Failed to issue adisc acc response
4408 lpfc_els_rsp_adisc_acc(struct lpfc_vport
*vport
, struct lpfc_iocbq
*oldiocb
,
4409 struct lpfc_nodelist
*ndlp
)
4411 struct lpfc_hba
*phba
= vport
->phba
;
4413 IOCB_t
*icmd
, *oldcmd
;
4414 struct lpfc_iocbq
*elsiocb
;
4419 cmdsize
= sizeof(uint32_t) + sizeof(ADISC
);
4420 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
4421 ndlp
->nlp_DID
, ELS_CMD_ACC
);
4425 icmd
= &elsiocb
->iocb
;
4426 oldcmd
= &oldiocb
->iocb
;
4427 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri / rx_id */
4428 icmd
->unsli3
.rcvsli3
.ox_id
= oldcmd
->unsli3
.rcvsli3
.ox_id
;
4430 /* Xmit ADISC ACC response tag <ulpIoTag> */
4431 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
4432 "0130 Xmit ADISC ACC response iotag x%x xri: "
4433 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
4434 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
4435 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
4437 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
4439 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
4440 pcmd
+= sizeof(uint32_t);
4442 ap
= (ADISC
*) (pcmd
);
4443 ap
->hardAL_PA
= phba
->fc_pref_ALPA
;
4444 memcpy(&ap
->portName
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
4445 memcpy(&ap
->nodeName
, &vport
->fc_nodename
, sizeof(struct lpfc_name
));
4446 ap
->DID
= be32_to_cpu(vport
->fc_myDID
);
4448 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
4449 "Issue ACC ADISC: did:x%x flg:x%x",
4450 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
4452 phba
->fc_stat
.elsXmitACC
++;
4453 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
4454 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
4455 if (rc
== IOCB_ERROR
) {
4456 lpfc_els_free_iocb(phba
, elsiocb
);
4460 /* Xmit ELS ACC response tag <ulpIoTag> */
4461 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
4462 "0128 Xmit ELS ACC response Status: x%x, IoTag: x%x, "
4463 "XRI: x%x, DID: x%x, nlp_flag: x%x nlp_state: x%x "
4464 "RPI: x%x, fc_flag x%x\n",
4465 rc
, elsiocb
->iotag
, elsiocb
->sli4_xritag
,
4466 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
4467 ndlp
->nlp_rpi
, vport
->fc_flag
);
4472 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
4473 * @vport: pointer to a virtual N_Port data structure.
4474 * @oldiocb: pointer to the original lpfc command iocb data structure.
4475 * @ndlp: pointer to a node-list data structure.
4477 * This routine prepares and issues an Accept (ACC) response to Process
4478 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
4479 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
4481 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4482 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4483 * will be stored into the context1 field of the IOCB for the completion
4484 * callback function to the PRLI Accept response ELS IOCB command.
4487 * 0 - Successfully issued acc prli response
4488 * 1 - Failed to issue acc prli response
4491 lpfc_els_rsp_prli_acc(struct lpfc_vport
*vport
, struct lpfc_iocbq
*oldiocb
,
4492 struct lpfc_nodelist
*ndlp
)
4494 struct lpfc_hba
*phba
= vport
->phba
;
4496 struct lpfc_nvme_prli
*npr_nvme
;
4500 struct lpfc_iocbq
*elsiocb
;
4503 uint32_t prli_fc4_req
, *req_payload
;
4504 struct lpfc_dmabuf
*req_buf
;
4508 /* Need the incoming PRLI payload to determine if the ACC is for an
4509 * FC4 or NVME PRLI type. The PRLI type is at word 1.
4511 req_buf
= (struct lpfc_dmabuf
*)oldiocb
->context2
;
4512 req_payload
= (((uint32_t *)req_buf
->virt
) + 1);
4514 /* PRLI type payload is at byte 3 for FCP or NVME. */
4515 prli_fc4_req
= be32_to_cpu(*req_payload
);
4516 prli_fc4_req
= (prli_fc4_req
>> 24) & 0xff;
4517 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
4518 "6127 PRLI_ACC: Req Type x%x, Word1 x%08x\n",
4519 prli_fc4_req
, *((uint32_t *)req_payload
));
4521 if (prli_fc4_req
== PRLI_FCP_TYPE
) {
4522 cmdsize
= sizeof(uint32_t) + sizeof(PRLI
);
4523 elsrspcmd
= (ELS_CMD_ACC
| (ELS_CMD_PRLI
& ~ELS_RSP_MASK
));
4524 } else if (prli_fc4_req
& PRLI_NVME_TYPE
) {
4525 cmdsize
= sizeof(uint32_t) + sizeof(struct lpfc_nvme_prli
);
4526 elsrspcmd
= (ELS_CMD_ACC
| (ELS_CMD_NVMEPRLI
& ~ELS_RSP_MASK
));
4531 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
4532 ndlp
->nlp_DID
, elsrspcmd
);
4536 icmd
= &elsiocb
->iocb
;
4537 oldcmd
= &oldiocb
->iocb
;
4538 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri / rx_id */
4539 icmd
->unsli3
.rcvsli3
.ox_id
= oldcmd
->unsli3
.rcvsli3
.ox_id
;
4541 /* Xmit PRLI ACC response tag <ulpIoTag> */
4542 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
4543 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
4544 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
4545 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
4546 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
4548 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
4549 memset(pcmd
, 0, cmdsize
);
4551 *((uint32_t *)(pcmd
)) = elsrspcmd
;
4552 pcmd
+= sizeof(uint32_t);
4554 /* For PRLI, remainder of payload is PRLI parameter page */
4557 if (prli_fc4_req
== PRLI_FCP_TYPE
) {
4559 * If the remote port is a target and our firmware version
4560 * is 3.20 or later, set the following bits for FC-TAPE
4563 npr
= (PRLI
*) pcmd
;
4564 if ((ndlp
->nlp_type
& NLP_FCP_TARGET
) &&
4565 (vpd
->rev
.feaLevelHigh
>= 0x02)) {
4566 npr
->ConfmComplAllowed
= 1;
4568 npr
->TaskRetryIdReq
= 1;
4570 npr
->acceptRspCode
= PRLI_REQ_EXECUTED
;
4571 npr
->estabImagePair
= 1;
4572 npr
->readXferRdyDis
= 1;
4573 npr
->ConfmComplAllowed
= 1;
4574 npr
->prliType
= PRLI_FCP_TYPE
;
4575 npr
->initiatorFunc
= 1;
4576 } else if (prli_fc4_req
& PRLI_NVME_TYPE
) {
4577 /* Respond with an NVME PRLI Type */
4578 npr_nvme
= (struct lpfc_nvme_prli
*) pcmd
;
4579 bf_set(prli_type_code
, npr_nvme
, PRLI_NVME_TYPE
);
4580 bf_set(prli_estabImagePair
, npr_nvme
, 0); /* Should be 0 */
4581 bf_set(prli_acc_rsp_code
, npr_nvme
, PRLI_REQ_EXECUTED
);
4582 if (phba
->nvmet_support
) {
4583 bf_set(prli_tgt
, npr_nvme
, 1);
4584 bf_set(prli_disc
, npr_nvme
, 1);
4585 if (phba
->cfg_nvme_enable_fb
) {
4586 bf_set(prli_fba
, npr_nvme
, 1);
4588 /* TBD. Target mode needs to post buffers
4589 * that support the configured first burst
4592 bf_set(prli_fb_sz
, npr_nvme
,
4593 phba
->cfg_nvmet_fb_size
);
4596 bf_set(prli_init
, npr_nvme
, 1);
4599 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NVME_DISC
,
4600 "6015 NVME issue PRLI ACC word1 x%08x "
4601 "word4 x%08x word5 x%08x flag x%x, "
4602 "fcp_info x%x nlp_type x%x\n",
4603 npr_nvme
->word1
, npr_nvme
->word4
,
4604 npr_nvme
->word5
, ndlp
->nlp_flag
,
4605 ndlp
->nlp_fcp_info
, ndlp
->nlp_type
);
4606 npr_nvme
->word1
= cpu_to_be32(npr_nvme
->word1
);
4607 npr_nvme
->word4
= cpu_to_be32(npr_nvme
->word4
);
4608 npr_nvme
->word5
= cpu_to_be32(npr_nvme
->word5
);
4610 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
4611 "6128 Unknown FC_TYPE x%x x%x ndlp x%06x\n",
4612 prli_fc4_req
, ndlp
->nlp_fc4_type
,
4615 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
4616 "Issue ACC PRLI: did:x%x flg:x%x",
4617 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
4619 phba
->fc_stat
.elsXmitACC
++;
4620 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
4622 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
4623 if (rc
== IOCB_ERROR
) {
4624 lpfc_els_free_iocb(phba
, elsiocb
);
4631 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
4632 * @vport: pointer to a virtual N_Port data structure.
4633 * @format: rnid command format.
4634 * @oldiocb: pointer to the original lpfc command iocb data structure.
4635 * @ndlp: pointer to a node-list data structure.
4637 * This routine issues a Request Node Identification Data (RNID) Accept
4638 * (ACC) response. It constructs the RNID ACC response command according to
4639 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
4640 * issue the response. Note that this command does not need to hold the ndlp
4641 * reference count for the callback. So, the ndlp reference count taken by
4642 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
4643 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
4644 * there is no ndlp reference available.
4646 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4647 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4648 * will be stored into the context1 field of the IOCB for the completion
4649 * callback function. However, for the RNID Accept Response ELS command,
4650 * this is undone later by this routine after the IOCB is allocated.
4653 * 0 - Successfully issued acc rnid response
4654 * 1 - Failed to issue acc rnid response
4657 lpfc_els_rsp_rnid_acc(struct lpfc_vport
*vport
, uint8_t format
,
4658 struct lpfc_iocbq
*oldiocb
, struct lpfc_nodelist
*ndlp
)
4660 struct lpfc_hba
*phba
= vport
->phba
;
4662 IOCB_t
*icmd
, *oldcmd
;
4663 struct lpfc_iocbq
*elsiocb
;
4668 cmdsize
= sizeof(uint32_t) + sizeof(uint32_t)
4669 + (2 * sizeof(struct lpfc_name
));
4671 cmdsize
+= sizeof(RNID_TOP_DISC
);
4673 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
4674 ndlp
->nlp_DID
, ELS_CMD_ACC
);
4678 icmd
= &elsiocb
->iocb
;
4679 oldcmd
= &oldiocb
->iocb
;
4680 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri / rx_id */
4681 icmd
->unsli3
.rcvsli3
.ox_id
= oldcmd
->unsli3
.rcvsli3
.ox_id
;
4683 /* Xmit RNID ACC response tag <ulpIoTag> */
4684 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
4685 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
4686 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
);
4687 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
4688 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
4689 pcmd
+= sizeof(uint32_t);
4691 memset(pcmd
, 0, sizeof(RNID
));
4692 rn
= (RNID
*) (pcmd
);
4693 rn
->Format
= format
;
4694 rn
->CommonLen
= (2 * sizeof(struct lpfc_name
));
4695 memcpy(&rn
->portName
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
4696 memcpy(&rn
->nodeName
, &vport
->fc_nodename
, sizeof(struct lpfc_name
));
4699 rn
->SpecificLen
= 0;
4701 case RNID_TOPOLOGY_DISC
:
4702 rn
->SpecificLen
= sizeof(RNID_TOP_DISC
);
4703 memcpy(&rn
->un
.topologyDisc
.portName
,
4704 &vport
->fc_portname
, sizeof(struct lpfc_name
));
4705 rn
->un
.topologyDisc
.unitType
= RNID_HBA
;
4706 rn
->un
.topologyDisc
.physPort
= 0;
4707 rn
->un
.topologyDisc
.attachedNodes
= 0;
4711 rn
->SpecificLen
= 0;
4715 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
4716 "Issue ACC RNID: did:x%x flg:x%x",
4717 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
4719 phba
->fc_stat
.elsXmitACC
++;
4720 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
4722 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
4723 if (rc
== IOCB_ERROR
) {
4724 lpfc_els_free_iocb(phba
, elsiocb
);
4731 * lpfc_els_clear_rrq - Clear the rq that this rrq describes.
4732 * @vport: pointer to a virtual N_Port data structure.
4733 * @iocb: pointer to the lpfc command iocb data structure.
4734 * @ndlp: pointer to a node-list data structure.
4739 lpfc_els_clear_rrq(struct lpfc_vport
*vport
,
4740 struct lpfc_iocbq
*iocb
, struct lpfc_nodelist
*ndlp
)
4742 struct lpfc_hba
*phba
= vport
->phba
;
4747 struct lpfc_node_rrq
*prrq
;
4750 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) iocb
->context2
)->virt
);
4751 pcmd
+= sizeof(uint32_t);
4752 rrq
= (struct RRQ
*)pcmd
;
4753 rrq
->rrq_exchg
= be32_to_cpu(rrq
->rrq_exchg
);
4754 rxid
= bf_get(rrq_rxid
, rrq
);
4756 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
4757 "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x"
4759 be32_to_cpu(bf_get(rrq_did
, rrq
)),
4760 bf_get(rrq_oxid
, rrq
),
4762 iocb
->iotag
, iocb
->iocb
.ulpContext
);
4764 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
4765 "Clear RRQ: did:x%x flg:x%x exchg:x%.08x",
4766 ndlp
->nlp_DID
, ndlp
->nlp_flag
, rrq
->rrq_exchg
);
4767 if (vport
->fc_myDID
== be32_to_cpu(bf_get(rrq_did
, rrq
)))
4768 xri
= bf_get(rrq_oxid
, rrq
);
4771 prrq
= lpfc_get_active_rrq(vport
, xri
, ndlp
->nlp_DID
);
4773 lpfc_clr_rrq_active(phba
, xri
, prrq
);
4778 * lpfc_els_rsp_echo_acc - Issue echo acc response
4779 * @vport: pointer to a virtual N_Port data structure.
4780 * @data: pointer to echo data to return in the accept.
4781 * @oldiocb: pointer to the original lpfc command iocb data structure.
4782 * @ndlp: pointer to a node-list data structure.
4785 * 0 - Successfully issued acc echo response
4786 * 1 - Failed to issue acc echo response
4789 lpfc_els_rsp_echo_acc(struct lpfc_vport
*vport
, uint8_t *data
,
4790 struct lpfc_iocbq
*oldiocb
, struct lpfc_nodelist
*ndlp
)
4792 struct lpfc_hba
*phba
= vport
->phba
;
4793 struct lpfc_iocbq
*elsiocb
;
4798 cmdsize
= oldiocb
->iocb
.unsli3
.rcvsli3
.acc_len
;
4800 /* The accumulated length can exceed the BPL_SIZE. For
4801 * now, use this as the limit
4803 if (cmdsize
> LPFC_BPL_SIZE
)
4804 cmdsize
= LPFC_BPL_SIZE
;
4805 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
4806 ndlp
->nlp_DID
, ELS_CMD_ACC
);
4810 elsiocb
->iocb
.ulpContext
= oldiocb
->iocb
.ulpContext
; /* Xri / rx_id */
4811 elsiocb
->iocb
.unsli3
.rcvsli3
.ox_id
= oldiocb
->iocb
.unsli3
.rcvsli3
.ox_id
;
4813 /* Xmit ECHO ACC response tag <ulpIoTag> */
4814 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
4815 "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
4816 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
);
4817 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
4818 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
4819 pcmd
+= sizeof(uint32_t);
4820 memcpy(pcmd
, data
, cmdsize
- sizeof(uint32_t));
4822 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
4823 "Issue ACC ECHO: did:x%x flg:x%x",
4824 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
4826 phba
->fc_stat
.elsXmitACC
++;
4827 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
4829 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
4830 if (rc
== IOCB_ERROR
) {
4831 lpfc_els_free_iocb(phba
, elsiocb
);
4838 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
4839 * @vport: pointer to a host virtual N_Port data structure.
4841 * This routine issues Address Discover (ADISC) ELS commands to those
4842 * N_Ports which are in node port recovery state and ADISC has not been issued
4843 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
4844 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
4845 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
4846 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
4847 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
4848 * IOCBs quit for later pick up. On the other hand, after walking through
4849 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
4850 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
4851 * no more ADISC need to be sent.
4854 * The number of N_Ports with adisc issued.
4857 lpfc_els_disc_adisc(struct lpfc_vport
*vport
)
4859 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4860 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
4863 /* go thru NPR nodes and issue any remaining ELS ADISCs */
4864 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
, nlp_listp
) {
4865 if (!NLP_CHK_NODE_ACT(ndlp
))
4867 if (ndlp
->nlp_state
== NLP_STE_NPR_NODE
&&
4868 (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) != 0 &&
4869 (ndlp
->nlp_flag
& NLP_NPR_ADISC
) != 0) {
4870 spin_lock_irq(shost
->host_lock
);
4871 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
4872 spin_unlock_irq(shost
->host_lock
);
4873 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
4874 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_ADISC_ISSUE
);
4875 lpfc_issue_els_adisc(vport
, ndlp
, 0);
4877 vport
->num_disc_nodes
++;
4878 if (vport
->num_disc_nodes
>=
4879 vport
->cfg_discovery_threads
) {
4880 spin_lock_irq(shost
->host_lock
);
4881 vport
->fc_flag
|= FC_NLP_MORE
;
4882 spin_unlock_irq(shost
->host_lock
);
4887 if (sentadisc
== 0) {
4888 spin_lock_irq(shost
->host_lock
);
4889 vport
->fc_flag
&= ~FC_NLP_MORE
;
4890 spin_unlock_irq(shost
->host_lock
);
4896 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
4897 * @vport: pointer to a host virtual N_Port data structure.
4899 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
4900 * which are in node port recovery state, with a @vport. Each time an ELS
4901 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
4902 * the per @vport number of discover count (num_disc_nodes) shall be
4903 * incremented. If the num_disc_nodes reaches a pre-configured threshold
4904 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
4905 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
4906 * later pick up. On the other hand, after walking through all the ndlps with
4907 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
4908 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
4909 * PLOGI need to be sent.
4912 * The number of N_Ports with plogi issued.
4915 lpfc_els_disc_plogi(struct lpfc_vport
*vport
)
4917 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4918 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
4921 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
4922 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
, nlp_listp
) {
4923 if (!NLP_CHK_NODE_ACT(ndlp
))
4925 if (ndlp
->nlp_state
== NLP_STE_NPR_NODE
&&
4926 (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) != 0 &&
4927 (ndlp
->nlp_flag
& NLP_DELAY_TMO
) == 0 &&
4928 (ndlp
->nlp_flag
& NLP_NPR_ADISC
) == 0) {
4929 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
4930 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
4931 lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0);
4933 vport
->num_disc_nodes
++;
4934 if (vport
->num_disc_nodes
>=
4935 vport
->cfg_discovery_threads
) {
4936 spin_lock_irq(shost
->host_lock
);
4937 vport
->fc_flag
|= FC_NLP_MORE
;
4938 spin_unlock_irq(shost
->host_lock
);
4944 lpfc_set_disctmo(vport
);
4947 spin_lock_irq(shost
->host_lock
);
4948 vport
->fc_flag
&= ~FC_NLP_MORE
;
4949 spin_unlock_irq(shost
->host_lock
);
4955 lpfc_rdp_res_link_service(struct fc_rdp_link_service_desc
*desc
,
4959 desc
->tag
= cpu_to_be32(RDP_LINK_SERVICE_DESC_TAG
);
4960 desc
->payload
.els_req
= word0
;
4961 desc
->length
= cpu_to_be32(sizeof(desc
->payload
));
4963 return sizeof(struct fc_rdp_link_service_desc
);
4967 lpfc_rdp_res_sfp_desc(struct fc_rdp_sfp_desc
*desc
,
4968 uint8_t *page_a0
, uint8_t *page_a2
)
4970 uint16_t wavelength
;
4971 uint16_t temperature
;
4977 struct sff_trasnceiver_codes_byte4
*trasn_code_byte4
;
4978 struct sff_trasnceiver_codes_byte5
*trasn_code_byte5
;
4980 desc
->tag
= cpu_to_be32(RDP_SFP_DESC_TAG
);
4982 trasn_code_byte4
= (struct sff_trasnceiver_codes_byte4
*)
4983 &page_a0
[SSF_TRANSCEIVER_CODE_B4
];
4984 trasn_code_byte5
= (struct sff_trasnceiver_codes_byte5
*)
4985 &page_a0
[SSF_TRANSCEIVER_CODE_B5
];
4987 if ((trasn_code_byte4
->fc_sw_laser
) ||
4988 (trasn_code_byte5
->fc_sw_laser_sl
) ||
4989 (trasn_code_byte5
->fc_sw_laser_sn
)) { /* check if its short WL */
4990 flag
|= (SFP_FLAG_PT_SWLASER
<< SFP_FLAG_PT_SHIFT
);
4991 } else if (trasn_code_byte4
->fc_lw_laser
) {
4992 wavelength
= (page_a0
[SSF_WAVELENGTH_B1
] << 8) |
4993 page_a0
[SSF_WAVELENGTH_B0
];
4994 if (wavelength
== SFP_WAVELENGTH_LC1310
)
4995 flag
|= SFP_FLAG_PT_LWLASER_LC1310
<< SFP_FLAG_PT_SHIFT
;
4996 if (wavelength
== SFP_WAVELENGTH_LL1550
)
4997 flag
|= SFP_FLAG_PT_LWLASER_LL1550
<< SFP_FLAG_PT_SHIFT
;
4999 /* check if its SFP+ */
5000 flag
|= ((page_a0
[SSF_IDENTIFIER
] == SFF_PG0_IDENT_SFP
) ?
5001 SFP_FLAG_CT_SFP_PLUS
: SFP_FLAG_CT_UNKNOWN
)
5002 << SFP_FLAG_CT_SHIFT
;
5004 /* check if its OPTICAL */
5005 flag
|= ((page_a0
[SSF_CONNECTOR
] == SFF_PG0_CONNECTOR_LC
) ?
5006 SFP_FLAG_IS_OPTICAL_PORT
: 0)
5007 << SFP_FLAG_IS_OPTICAL_SHIFT
;
5009 temperature
= (page_a2
[SFF_TEMPERATURE_B1
] << 8 |
5010 page_a2
[SFF_TEMPERATURE_B0
]);
5011 vcc
= (page_a2
[SFF_VCC_B1
] << 8 |
5012 page_a2
[SFF_VCC_B0
]);
5013 tx_power
= (page_a2
[SFF_TXPOWER_B1
] << 8 |
5014 page_a2
[SFF_TXPOWER_B0
]);
5015 tx_bias
= (page_a2
[SFF_TX_BIAS_CURRENT_B1
] << 8 |
5016 page_a2
[SFF_TX_BIAS_CURRENT_B0
]);
5017 rx_power
= (page_a2
[SFF_RXPOWER_B1
] << 8 |
5018 page_a2
[SFF_RXPOWER_B0
]);
5019 desc
->sfp_info
.temperature
= cpu_to_be16(temperature
);
5020 desc
->sfp_info
.rx_power
= cpu_to_be16(rx_power
);
5021 desc
->sfp_info
.tx_bias
= cpu_to_be16(tx_bias
);
5022 desc
->sfp_info
.tx_power
= cpu_to_be16(tx_power
);
5023 desc
->sfp_info
.vcc
= cpu_to_be16(vcc
);
5025 desc
->sfp_info
.flags
= cpu_to_be16(flag
);
5026 desc
->length
= cpu_to_be32(sizeof(desc
->sfp_info
));
5028 return sizeof(struct fc_rdp_sfp_desc
);
5032 lpfc_rdp_res_link_error(struct fc_rdp_link_error_status_desc
*desc
,
5037 desc
->tag
= cpu_to_be32(RDP_LINK_ERROR_STATUS_DESC_TAG
);
5039 type
= VN_PT_PHY_PF_PORT
<< VN_PT_PHY_SHIFT
;
5041 desc
->info
.port_type
= cpu_to_be32(type
);
5043 desc
->info
.link_status
.link_failure_cnt
=
5044 cpu_to_be32(stat
->linkFailureCnt
);
5045 desc
->info
.link_status
.loss_of_synch_cnt
=
5046 cpu_to_be32(stat
->lossSyncCnt
);
5047 desc
->info
.link_status
.loss_of_signal_cnt
=
5048 cpu_to_be32(stat
->lossSignalCnt
);
5049 desc
->info
.link_status
.primitive_seq_proto_err
=
5050 cpu_to_be32(stat
->primSeqErrCnt
);
5051 desc
->info
.link_status
.invalid_trans_word
=
5052 cpu_to_be32(stat
->invalidXmitWord
);
5053 desc
->info
.link_status
.invalid_crc_cnt
= cpu_to_be32(stat
->crcCnt
);
5055 desc
->length
= cpu_to_be32(sizeof(desc
->info
));
5057 return sizeof(struct fc_rdp_link_error_status_desc
);
5061 lpfc_rdp_res_bbc_desc(struct fc_rdp_bbc_desc
*desc
, READ_LNK_VAR
*stat
,
5062 struct lpfc_vport
*vport
)
5066 desc
->tag
= cpu_to_be32(RDP_BBC_DESC_TAG
);
5068 bbCredit
= vport
->fc_sparam
.cmn
.bbCreditLsb
|
5069 (vport
->fc_sparam
.cmn
.bbCreditMsb
<< 8);
5070 desc
->bbc_info
.port_bbc
= cpu_to_be32(bbCredit
);
5071 if (vport
->phba
->fc_topology
!= LPFC_TOPOLOGY_LOOP
) {
5072 bbCredit
= vport
->phba
->fc_fabparam
.cmn
.bbCreditLsb
|
5073 (vport
->phba
->fc_fabparam
.cmn
.bbCreditMsb
<< 8);
5074 desc
->bbc_info
.attached_port_bbc
= cpu_to_be32(bbCredit
);
5076 desc
->bbc_info
.attached_port_bbc
= 0;
5079 desc
->bbc_info
.rtt
= 0;
5080 desc
->length
= cpu_to_be32(sizeof(desc
->bbc_info
));
5082 return sizeof(struct fc_rdp_bbc_desc
);
5086 lpfc_rdp_res_oed_temp_desc(struct lpfc_hba
*phba
,
5087 struct fc_rdp_oed_sfp_desc
*desc
, uint8_t *page_a2
)
5091 desc
->tag
= cpu_to_be32(RDP_OED_DESC_TAG
);
5093 desc
->oed_info
.hi_alarm
= page_a2
[SSF_TEMP_HIGH_ALARM
];
5094 desc
->oed_info
.lo_alarm
= page_a2
[SSF_TEMP_LOW_ALARM
];
5095 desc
->oed_info
.hi_warning
= page_a2
[SSF_TEMP_HIGH_WARNING
];
5096 desc
->oed_info
.lo_warning
= page_a2
[SSF_TEMP_LOW_WARNING
];
5098 if (phba
->sfp_alarm
& LPFC_TRANSGRESSION_HIGH_TEMPERATURE
)
5099 flags
|= RDP_OET_HIGH_ALARM
;
5100 if (phba
->sfp_alarm
& LPFC_TRANSGRESSION_LOW_TEMPERATURE
)
5101 flags
|= RDP_OET_LOW_ALARM
;
5102 if (phba
->sfp_warning
& LPFC_TRANSGRESSION_HIGH_TEMPERATURE
)
5103 flags
|= RDP_OET_HIGH_WARNING
;
5104 if (phba
->sfp_warning
& LPFC_TRANSGRESSION_LOW_TEMPERATURE
)
5105 flags
|= RDP_OET_LOW_WARNING
;
5107 flags
|= ((0xf & RDP_OED_TEMPERATURE
) << RDP_OED_TYPE_SHIFT
);
5108 desc
->oed_info
.function_flags
= cpu_to_be32(flags
);
5109 desc
->length
= cpu_to_be32(sizeof(desc
->oed_info
));
5110 return sizeof(struct fc_rdp_oed_sfp_desc
);
5114 lpfc_rdp_res_oed_voltage_desc(struct lpfc_hba
*phba
,
5115 struct fc_rdp_oed_sfp_desc
*desc
,
5120 desc
->tag
= cpu_to_be32(RDP_OED_DESC_TAG
);
5122 desc
->oed_info
.hi_alarm
= page_a2
[SSF_VOLTAGE_HIGH_ALARM
];
5123 desc
->oed_info
.lo_alarm
= page_a2
[SSF_VOLTAGE_LOW_ALARM
];
5124 desc
->oed_info
.hi_warning
= page_a2
[SSF_VOLTAGE_HIGH_WARNING
];
5125 desc
->oed_info
.lo_warning
= page_a2
[SSF_VOLTAGE_LOW_WARNING
];
5127 if (phba
->sfp_alarm
& LPFC_TRANSGRESSION_HIGH_VOLTAGE
)
5128 flags
|= RDP_OET_HIGH_ALARM
;
5129 if (phba
->sfp_alarm
& LPFC_TRANSGRESSION_LOW_VOLTAGE
)
5130 flags
|= RDP_OET_LOW_ALARM
;
5131 if (phba
->sfp_warning
& LPFC_TRANSGRESSION_HIGH_VOLTAGE
)
5132 flags
|= RDP_OET_HIGH_WARNING
;
5133 if (phba
->sfp_warning
& LPFC_TRANSGRESSION_LOW_VOLTAGE
)
5134 flags
|= RDP_OET_LOW_WARNING
;
5136 flags
|= ((0xf & RDP_OED_VOLTAGE
) << RDP_OED_TYPE_SHIFT
);
5137 desc
->oed_info
.function_flags
= cpu_to_be32(flags
);
5138 desc
->length
= cpu_to_be32(sizeof(desc
->oed_info
));
5139 return sizeof(struct fc_rdp_oed_sfp_desc
);
5143 lpfc_rdp_res_oed_txbias_desc(struct lpfc_hba
*phba
,
5144 struct fc_rdp_oed_sfp_desc
*desc
,
5149 desc
->tag
= cpu_to_be32(RDP_OED_DESC_TAG
);
5151 desc
->oed_info
.hi_alarm
= page_a2
[SSF_BIAS_HIGH_ALARM
];
5152 desc
->oed_info
.lo_alarm
= page_a2
[SSF_BIAS_LOW_ALARM
];
5153 desc
->oed_info
.hi_warning
= page_a2
[SSF_BIAS_HIGH_WARNING
];
5154 desc
->oed_info
.lo_warning
= page_a2
[SSF_BIAS_LOW_WARNING
];
5156 if (phba
->sfp_alarm
& LPFC_TRANSGRESSION_HIGH_TXBIAS
)
5157 flags
|= RDP_OET_HIGH_ALARM
;
5158 if (phba
->sfp_alarm
& LPFC_TRANSGRESSION_LOW_TXBIAS
)
5159 flags
|= RDP_OET_LOW_ALARM
;
5160 if (phba
->sfp_warning
& LPFC_TRANSGRESSION_HIGH_TXBIAS
)
5161 flags
|= RDP_OET_HIGH_WARNING
;
5162 if (phba
->sfp_warning
& LPFC_TRANSGRESSION_LOW_TXBIAS
)
5163 flags
|= RDP_OET_LOW_WARNING
;
5165 flags
|= ((0xf & RDP_OED_TXBIAS
) << RDP_OED_TYPE_SHIFT
);
5166 desc
->oed_info
.function_flags
= cpu_to_be32(flags
);
5167 desc
->length
= cpu_to_be32(sizeof(desc
->oed_info
));
5168 return sizeof(struct fc_rdp_oed_sfp_desc
);
5172 lpfc_rdp_res_oed_txpower_desc(struct lpfc_hba
*phba
,
5173 struct fc_rdp_oed_sfp_desc
*desc
,
5178 desc
->tag
= cpu_to_be32(RDP_OED_DESC_TAG
);
5180 desc
->oed_info
.hi_alarm
= page_a2
[SSF_TXPOWER_HIGH_ALARM
];
5181 desc
->oed_info
.lo_alarm
= page_a2
[SSF_TXPOWER_LOW_ALARM
];
5182 desc
->oed_info
.hi_warning
= page_a2
[SSF_TXPOWER_HIGH_WARNING
];
5183 desc
->oed_info
.lo_warning
= page_a2
[SSF_TXPOWER_LOW_WARNING
];
5185 if (phba
->sfp_alarm
& LPFC_TRANSGRESSION_HIGH_TXPOWER
)
5186 flags
|= RDP_OET_HIGH_ALARM
;
5187 if (phba
->sfp_alarm
& LPFC_TRANSGRESSION_LOW_TXPOWER
)
5188 flags
|= RDP_OET_LOW_ALARM
;
5189 if (phba
->sfp_warning
& LPFC_TRANSGRESSION_HIGH_TXPOWER
)
5190 flags
|= RDP_OET_HIGH_WARNING
;
5191 if (phba
->sfp_warning
& LPFC_TRANSGRESSION_LOW_TXPOWER
)
5192 flags
|= RDP_OET_LOW_WARNING
;
5194 flags
|= ((0xf & RDP_OED_TXPOWER
) << RDP_OED_TYPE_SHIFT
);
5195 desc
->oed_info
.function_flags
= cpu_to_be32(flags
);
5196 desc
->length
= cpu_to_be32(sizeof(desc
->oed_info
));
5197 return sizeof(struct fc_rdp_oed_sfp_desc
);
5202 lpfc_rdp_res_oed_rxpower_desc(struct lpfc_hba
*phba
,
5203 struct fc_rdp_oed_sfp_desc
*desc
,
5208 desc
->tag
= cpu_to_be32(RDP_OED_DESC_TAG
);
5210 desc
->oed_info
.hi_alarm
= page_a2
[SSF_RXPOWER_HIGH_ALARM
];
5211 desc
->oed_info
.lo_alarm
= page_a2
[SSF_RXPOWER_LOW_ALARM
];
5212 desc
->oed_info
.hi_warning
= page_a2
[SSF_RXPOWER_HIGH_WARNING
];
5213 desc
->oed_info
.lo_warning
= page_a2
[SSF_RXPOWER_LOW_WARNING
];
5215 if (phba
->sfp_alarm
& LPFC_TRANSGRESSION_HIGH_RXPOWER
)
5216 flags
|= RDP_OET_HIGH_ALARM
;
5217 if (phba
->sfp_alarm
& LPFC_TRANSGRESSION_LOW_RXPOWER
)
5218 flags
|= RDP_OET_LOW_ALARM
;
5219 if (phba
->sfp_warning
& LPFC_TRANSGRESSION_HIGH_RXPOWER
)
5220 flags
|= RDP_OET_HIGH_WARNING
;
5221 if (phba
->sfp_warning
& LPFC_TRANSGRESSION_LOW_RXPOWER
)
5222 flags
|= RDP_OET_LOW_WARNING
;
5224 flags
|= ((0xf & RDP_OED_RXPOWER
) << RDP_OED_TYPE_SHIFT
);
5225 desc
->oed_info
.function_flags
= cpu_to_be32(flags
);
5226 desc
->length
= cpu_to_be32(sizeof(desc
->oed_info
));
5227 return sizeof(struct fc_rdp_oed_sfp_desc
);
5231 lpfc_rdp_res_opd_desc(struct fc_rdp_opd_sfp_desc
*desc
,
5232 uint8_t *page_a0
, struct lpfc_vport
*vport
)
5234 desc
->tag
= cpu_to_be32(RDP_OPD_DESC_TAG
);
5235 memcpy(desc
->opd_info
.vendor_name
, &page_a0
[SSF_VENDOR_NAME
], 16);
5236 memcpy(desc
->opd_info
.model_number
, &page_a0
[SSF_VENDOR_PN
], 16);
5237 memcpy(desc
->opd_info
.serial_number
, &page_a0
[SSF_VENDOR_SN
], 16);
5238 memcpy(desc
->opd_info
.revision
, &page_a0
[SSF_VENDOR_REV
], 4);
5239 memcpy(desc
->opd_info
.date
, &page_a0
[SSF_DATE_CODE
], 8);
5240 desc
->length
= cpu_to_be32(sizeof(desc
->opd_info
));
5241 return sizeof(struct fc_rdp_opd_sfp_desc
);
5245 lpfc_rdp_res_fec_desc(struct fc_fec_rdp_desc
*desc
, READ_LNK_VAR
*stat
)
5247 if (bf_get(lpfc_read_link_stat_gec2
, stat
) == 0)
5249 desc
->tag
= cpu_to_be32(RDP_FEC_DESC_TAG
);
5251 desc
->info
.CorrectedBlocks
=
5252 cpu_to_be32(stat
->fecCorrBlkCount
);
5253 desc
->info
.UncorrectableBlocks
=
5254 cpu_to_be32(stat
->fecUncorrBlkCount
);
5256 desc
->length
= cpu_to_be32(sizeof(desc
->info
));
5258 return sizeof(struct fc_fec_rdp_desc
);
5262 lpfc_rdp_res_speed(struct fc_rdp_port_speed_desc
*desc
, struct lpfc_hba
*phba
)
5264 uint16_t rdp_cap
= 0;
5267 desc
->tag
= cpu_to_be32(RDP_PORT_SPEED_DESC_TAG
);
5269 switch (phba
->fc_linkspeed
) {
5270 case LPFC_LINK_SPEED_1GHZ
:
5271 rdp_speed
= RDP_PS_1GB
;
5273 case LPFC_LINK_SPEED_2GHZ
:
5274 rdp_speed
= RDP_PS_2GB
;
5276 case LPFC_LINK_SPEED_4GHZ
:
5277 rdp_speed
= RDP_PS_4GB
;
5279 case LPFC_LINK_SPEED_8GHZ
:
5280 rdp_speed
= RDP_PS_8GB
;
5282 case LPFC_LINK_SPEED_10GHZ
:
5283 rdp_speed
= RDP_PS_10GB
;
5285 case LPFC_LINK_SPEED_16GHZ
:
5286 rdp_speed
= RDP_PS_16GB
;
5288 case LPFC_LINK_SPEED_32GHZ
:
5289 rdp_speed
= RDP_PS_32GB
;
5291 case LPFC_LINK_SPEED_64GHZ
:
5292 rdp_speed
= RDP_PS_64GB
;
5295 rdp_speed
= RDP_PS_UNKNOWN
;
5299 desc
->info
.port_speed
.speed
= cpu_to_be16(rdp_speed
);
5301 if (phba
->lmt
& LMT_64Gb
)
5302 rdp_cap
|= RDP_PS_64GB
;
5303 if (phba
->lmt
& LMT_32Gb
)
5304 rdp_cap
|= RDP_PS_32GB
;
5305 if (phba
->lmt
& LMT_16Gb
)
5306 rdp_cap
|= RDP_PS_16GB
;
5307 if (phba
->lmt
& LMT_10Gb
)
5308 rdp_cap
|= RDP_PS_10GB
;
5309 if (phba
->lmt
& LMT_8Gb
)
5310 rdp_cap
|= RDP_PS_8GB
;
5311 if (phba
->lmt
& LMT_4Gb
)
5312 rdp_cap
|= RDP_PS_4GB
;
5313 if (phba
->lmt
& LMT_2Gb
)
5314 rdp_cap
|= RDP_PS_2GB
;
5315 if (phba
->lmt
& LMT_1Gb
)
5316 rdp_cap
|= RDP_PS_1GB
;
5319 rdp_cap
= RDP_CAP_UNKNOWN
;
5320 if (phba
->cfg_link_speed
!= LPFC_USER_LINK_SPEED_AUTO
)
5321 rdp_cap
|= RDP_CAP_USER_CONFIGURED
;
5323 desc
->info
.port_speed
.capabilities
= cpu_to_be16(rdp_cap
);
5324 desc
->length
= cpu_to_be32(sizeof(desc
->info
));
5325 return sizeof(struct fc_rdp_port_speed_desc
);
5329 lpfc_rdp_res_diag_port_names(struct fc_rdp_port_name_desc
*desc
,
5330 struct lpfc_vport
*vport
)
5333 desc
->tag
= cpu_to_be32(RDP_PORT_NAMES_DESC_TAG
);
5335 memcpy(desc
->port_names
.wwnn
, &vport
->fc_nodename
,
5336 sizeof(desc
->port_names
.wwnn
));
5338 memcpy(desc
->port_names
.wwpn
, &vport
->fc_portname
,
5339 sizeof(desc
->port_names
.wwpn
));
5341 desc
->length
= cpu_to_be32(sizeof(desc
->port_names
));
5342 return sizeof(struct fc_rdp_port_name_desc
);
5346 lpfc_rdp_res_attach_port_names(struct fc_rdp_port_name_desc
*desc
,
5347 struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
5350 desc
->tag
= cpu_to_be32(RDP_PORT_NAMES_DESC_TAG
);
5351 if (vport
->fc_flag
& FC_FABRIC
) {
5352 memcpy(desc
->port_names
.wwnn
, &vport
->fabric_nodename
,
5353 sizeof(desc
->port_names
.wwnn
));
5355 memcpy(desc
->port_names
.wwpn
, &vport
->fabric_portname
,
5356 sizeof(desc
->port_names
.wwpn
));
5357 } else { /* Point to Point */
5358 memcpy(desc
->port_names
.wwnn
, &ndlp
->nlp_nodename
,
5359 sizeof(desc
->port_names
.wwnn
));
5361 memcpy(desc
->port_names
.wwnn
, &ndlp
->nlp_portname
,
5362 sizeof(desc
->port_names
.wwpn
));
5365 desc
->length
= cpu_to_be32(sizeof(desc
->port_names
));
5366 return sizeof(struct fc_rdp_port_name_desc
);
5370 lpfc_els_rdp_cmpl(struct lpfc_hba
*phba
, struct lpfc_rdp_context
*rdp_context
,
5373 struct lpfc_nodelist
*ndlp
= rdp_context
->ndlp
;
5374 struct lpfc_vport
*vport
= ndlp
->vport
;
5375 struct lpfc_iocbq
*elsiocb
;
5376 struct ulp_bde64
*bpl
;
5379 struct ls_rjt
*stat
;
5380 struct fc_rdp_res_frame
*rdp_res
;
5381 uint32_t cmdsize
, len
;
5385 if (status
!= SUCCESS
)
5388 /* This will change once we know the true size of the RDP payload */
5389 cmdsize
= sizeof(struct fc_rdp_res_frame
);
5391 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
,
5392 lpfc_max_els_tries
, rdp_context
->ndlp
,
5393 rdp_context
->ndlp
->nlp_DID
, ELS_CMD_ACC
);
5396 goto free_rdp_context
;
5398 icmd
= &elsiocb
->iocb
;
5399 icmd
->ulpContext
= rdp_context
->rx_id
;
5400 icmd
->unsli3
.rcvsli3
.ox_id
= rdp_context
->ox_id
;
5402 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
5403 "2171 Xmit RDP response tag x%x xri x%x, "
5404 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x",
5405 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
5406 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
5408 rdp_res
= (struct fc_rdp_res_frame
*)
5409 (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
5410 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
5411 memset(pcmd
, 0, sizeof(struct fc_rdp_res_frame
));
5412 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
5414 /* Update Alarm and Warning */
5415 flag_ptr
= (uint16_t *)(rdp_context
->page_a2
+ SSF_ALARM_FLAGS
);
5416 phba
->sfp_alarm
|= *flag_ptr
;
5417 flag_ptr
= (uint16_t *)(rdp_context
->page_a2
+ SSF_WARNING_FLAGS
);
5418 phba
->sfp_warning
|= *flag_ptr
;
5420 /* For RDP payload */
5422 len
+= lpfc_rdp_res_link_service((struct fc_rdp_link_service_desc
*)
5423 (len
+ pcmd
), ELS_CMD_RDP
);
5425 len
+= lpfc_rdp_res_sfp_desc((struct fc_rdp_sfp_desc
*)(len
+ pcmd
),
5426 rdp_context
->page_a0
, rdp_context
->page_a2
);
5427 len
+= lpfc_rdp_res_speed((struct fc_rdp_port_speed_desc
*)(len
+ pcmd
),
5429 len
+= lpfc_rdp_res_link_error((struct fc_rdp_link_error_status_desc
*)
5430 (len
+ pcmd
), &rdp_context
->link_stat
);
5431 len
+= lpfc_rdp_res_diag_port_names((struct fc_rdp_port_name_desc
*)
5432 (len
+ pcmd
), vport
);
5433 len
+= lpfc_rdp_res_attach_port_names((struct fc_rdp_port_name_desc
*)
5434 (len
+ pcmd
), vport
, ndlp
);
5435 len
+= lpfc_rdp_res_fec_desc((struct fc_fec_rdp_desc
*)(len
+ pcmd
),
5436 &rdp_context
->link_stat
);
5437 len
+= lpfc_rdp_res_bbc_desc((struct fc_rdp_bbc_desc
*)(len
+ pcmd
),
5438 &rdp_context
->link_stat
, vport
);
5439 len
+= lpfc_rdp_res_oed_temp_desc(phba
,
5440 (struct fc_rdp_oed_sfp_desc
*)(len
+ pcmd
),
5441 rdp_context
->page_a2
);
5442 len
+= lpfc_rdp_res_oed_voltage_desc(phba
,
5443 (struct fc_rdp_oed_sfp_desc
*)(len
+ pcmd
),
5444 rdp_context
->page_a2
);
5445 len
+= lpfc_rdp_res_oed_txbias_desc(phba
,
5446 (struct fc_rdp_oed_sfp_desc
*)(len
+ pcmd
),
5447 rdp_context
->page_a2
);
5448 len
+= lpfc_rdp_res_oed_txpower_desc(phba
,
5449 (struct fc_rdp_oed_sfp_desc
*)(len
+ pcmd
),
5450 rdp_context
->page_a2
);
5451 len
+= lpfc_rdp_res_oed_rxpower_desc(phba
,
5452 (struct fc_rdp_oed_sfp_desc
*)(len
+ pcmd
),
5453 rdp_context
->page_a2
);
5454 len
+= lpfc_rdp_res_opd_desc((struct fc_rdp_opd_sfp_desc
*)(len
+ pcmd
),
5455 rdp_context
->page_a0
, vport
);
5457 rdp_res
->length
= cpu_to_be32(len
- 8);
5458 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
5460 /* Now that we know the true size of the payload, update the BPL */
5461 bpl
= (struct ulp_bde64
*)
5462 (((struct lpfc_dmabuf
*)(elsiocb
->context3
))->virt
);
5463 bpl
->tus
.f
.bdeSize
= len
;
5464 bpl
->tus
.f
.bdeFlags
= 0;
5465 bpl
->tus
.w
= le32_to_cpu(bpl
->tus
.w
);
5467 phba
->fc_stat
.elsXmitACC
++;
5468 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
5469 if (rc
== IOCB_ERROR
)
5470 lpfc_els_free_iocb(phba
, elsiocb
);
5476 cmdsize
= 2 * sizeof(uint32_t);
5477 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, lpfc_max_els_tries
,
5478 ndlp
, ndlp
->nlp_DID
, ELS_CMD_LS_RJT
);
5481 goto free_rdp_context
;
5483 icmd
= &elsiocb
->iocb
;
5484 icmd
->ulpContext
= rdp_context
->rx_id
;
5485 icmd
->unsli3
.rcvsli3
.ox_id
= rdp_context
->ox_id
;
5486 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
5488 *((uint32_t *) (pcmd
)) = ELS_CMD_LS_RJT
;
5489 stat
= (struct ls_rjt
*)(pcmd
+ sizeof(uint32_t));
5490 stat
->un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
5492 phba
->fc_stat
.elsXmitLSRJT
++;
5493 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
5494 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
5496 if (rc
== IOCB_ERROR
)
5497 lpfc_els_free_iocb(phba
, elsiocb
);
5503 lpfc_get_rdp_info(struct lpfc_hba
*phba
, struct lpfc_rdp_context
*rdp_context
)
5505 LPFC_MBOXQ_t
*mbox
= NULL
;
5508 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
5510 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_ELS
,
5511 "7105 failed to allocate mailbox memory");
5515 if (lpfc_sli4_dump_page_a0(phba
, mbox
))
5516 goto prep_mbox_fail
;
5517 mbox
->vport
= rdp_context
->ndlp
->vport
;
5518 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_rdp_page_a0
;
5519 mbox
->context2
= (struct lpfc_rdp_context
*) rdp_context
;
5520 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
5521 if (rc
== MBX_NOT_FINISHED
)
5522 goto issue_mbox_fail
;
5528 mempool_free(mbox
, phba
->mbox_mem_pool
);
5533 * lpfc_els_rcv_rdp - Process an unsolicited RDP ELS.
5534 * @vport: pointer to a host virtual N_Port data structure.
5535 * @cmdiocb: pointer to lpfc command iocb data structure.
5536 * @ndlp: pointer to a node-list data structure.
5538 * This routine processes an unsolicited RDP(Read Diagnostic Parameters)
5539 * IOCB. First, the payload of the unsolicited RDP is checked.
5540 * Then it will (1) send MBX_DUMP_MEMORY, Embedded DMP_LMSD sub command TYPE-3
5541 * for Page A0, (2) send MBX_DUMP_MEMORY, DMP_LMSD for Page A2,
5542 * (3) send MBX_READ_LNK_STAT to get link stat, (4) Call lpfc_els_rdp_cmpl
5543 * gather all data and send RDP response.
5546 * 0 - Sent the acc response
5547 * 1 - Sent the reject response.
5550 lpfc_els_rcv_rdp(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
5551 struct lpfc_nodelist
*ndlp
)
5553 struct lpfc_hba
*phba
= vport
->phba
;
5554 struct lpfc_dmabuf
*pcmd
;
5555 uint8_t rjt_err
, rjt_expl
= LSEXP_NOTHING_MORE
;
5556 struct fc_rdp_req_frame
*rdp_req
;
5557 struct lpfc_rdp_context
*rdp_context
;
5561 if (phba
->sli_rev
< LPFC_SLI_REV4
||
5562 bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) <
5563 LPFC_SLI_INTF_IF_TYPE_2
) {
5564 rjt_err
= LSRJT_UNABLE_TPC
;
5565 rjt_expl
= LSEXP_REQ_UNSUPPORTED
;
5569 if (phba
->sli_rev
< LPFC_SLI_REV4
|| (phba
->hba_flag
& HBA_FCOE_MODE
)) {
5570 rjt_err
= LSRJT_UNABLE_TPC
;
5571 rjt_expl
= LSEXP_REQ_UNSUPPORTED
;
5575 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
5576 rdp_req
= (struct fc_rdp_req_frame
*) pcmd
->virt
;
5578 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
5579 "2422 ELS RDP Request "
5580 "dec len %d tag x%x port_id %d len %d\n",
5581 be32_to_cpu(rdp_req
->rdp_des_length
),
5582 be32_to_cpu(rdp_req
->nport_id_desc
.tag
),
5583 be32_to_cpu(rdp_req
->nport_id_desc
.nport_id
),
5584 be32_to_cpu(rdp_req
->nport_id_desc
.length
));
5586 if (sizeof(struct fc_rdp_nport_desc
) !=
5587 be32_to_cpu(rdp_req
->rdp_des_length
))
5589 if (RDP_N_PORT_DESC_TAG
!= be32_to_cpu(rdp_req
->nport_id_desc
.tag
))
5591 if (RDP_NPORT_ID_SIZE
!=
5592 be32_to_cpu(rdp_req
->nport_id_desc
.length
))
5594 rdp_context
= kzalloc(sizeof(struct lpfc_rdp_context
), GFP_KERNEL
);
5596 rjt_err
= LSRJT_UNABLE_TPC
;
5600 cmd
= &cmdiocb
->iocb
;
5601 rdp_context
->ndlp
= lpfc_nlp_get(ndlp
);
5602 rdp_context
->ox_id
= cmd
->unsli3
.rcvsli3
.ox_id
;
5603 rdp_context
->rx_id
= cmd
->ulpContext
;
5604 rdp_context
->cmpl
= lpfc_els_rdp_cmpl
;
5605 if (lpfc_get_rdp_info(phba
, rdp_context
)) {
5606 lpfc_printf_vlog(ndlp
->vport
, KERN_WARNING
, LOG_ELS
,
5607 "2423 Unable to send mailbox");
5609 rjt_err
= LSRJT_UNABLE_TPC
;
5617 rjt_err
= LSRJT_LOGICAL_ERR
;
5620 memset(&stat
, 0, sizeof(stat
));
5621 stat
.un
.b
.lsRjtRsnCode
= rjt_err
;
5622 stat
.un
.b
.lsRjtRsnCodeExp
= rjt_expl
;
5623 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
5629 lpfc_els_lcb_rsp(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
5634 struct lpfc_iocbq
*elsiocb
;
5635 struct lpfc_nodelist
*ndlp
;
5636 struct ls_rjt
*stat
;
5637 union lpfc_sli4_cfg_shdr
*shdr
;
5638 struct lpfc_lcb_context
*lcb_context
;
5639 struct fc_lcb_res_frame
*lcb_res
;
5640 uint32_t cmdsize
, shdr_status
, shdr_add_status
;
5644 lcb_context
= (struct lpfc_lcb_context
*)pmb
->context1
;
5645 ndlp
= lcb_context
->ndlp
;
5646 pmb
->context1
= NULL
;
5647 pmb
->context2
= NULL
;
5649 shdr
= (union lpfc_sli4_cfg_shdr
*)
5650 &pmb
->u
.mqe
.un
.beacon_config
.header
.cfg_shdr
;
5651 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
5652 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
5654 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
,
5655 "0194 SET_BEACON_CONFIG mailbox "
5656 "completed with status x%x add_status x%x,"
5657 " mbx status x%x\n",
5658 shdr_status
, shdr_add_status
, mb
->mbxStatus
);
5660 if (mb
->mbxStatus
&& !(shdr_status
&&
5661 shdr_add_status
== ADD_STATUS_OPERATION_ALREADY_ACTIVE
)) {
5662 mempool_free(pmb
, phba
->mbox_mem_pool
);
5666 mempool_free(pmb
, phba
->mbox_mem_pool
);
5667 cmdsize
= sizeof(struct fc_lcb_res_frame
);
5668 elsiocb
= lpfc_prep_els_iocb(phba
->pport
, 0, cmdsize
,
5669 lpfc_max_els_tries
, ndlp
,
5670 ndlp
->nlp_DID
, ELS_CMD_ACC
);
5672 /* Decrement the ndlp reference count from previous mbox command */
5676 goto free_lcb_context
;
5678 lcb_res
= (struct fc_lcb_res_frame
*)
5679 (((struct lpfc_dmabuf
*)elsiocb
->context2
)->virt
);
5681 icmd
= &elsiocb
->iocb
;
5682 icmd
->ulpContext
= lcb_context
->rx_id
;
5683 icmd
->unsli3
.rcvsli3
.ox_id
= lcb_context
->ox_id
;
5685 pcmd
= (uint8_t *)(((struct lpfc_dmabuf
*)elsiocb
->context2
)->virt
);
5686 *((uint32_t *)(pcmd
)) = ELS_CMD_ACC
;
5687 lcb_res
->lcb_sub_command
= lcb_context
->sub_command
;
5688 lcb_res
->lcb_type
= lcb_context
->type
;
5689 lcb_res
->lcb_frequency
= lcb_context
->frequency
;
5690 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
5691 phba
->fc_stat
.elsXmitACC
++;
5692 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
5693 if (rc
== IOCB_ERROR
)
5694 lpfc_els_free_iocb(phba
, elsiocb
);
5700 cmdsize
= sizeof(struct fc_lcb_res_frame
);
5701 elsiocb
= lpfc_prep_els_iocb(phba
->pport
, 0, cmdsize
,
5702 lpfc_max_els_tries
, ndlp
,
5703 ndlp
->nlp_DID
, ELS_CMD_LS_RJT
);
5706 goto free_lcb_context
;
5708 icmd
= &elsiocb
->iocb
;
5709 icmd
->ulpContext
= lcb_context
->rx_id
;
5710 icmd
->unsli3
.rcvsli3
.ox_id
= lcb_context
->ox_id
;
5711 pcmd
= (uint8_t *)(((struct lpfc_dmabuf
*)elsiocb
->context2
)->virt
);
5713 *((uint32_t *)(pcmd
)) = ELS_CMD_LS_RJT
;
5714 stat
= (struct ls_rjt
*)(pcmd
+ sizeof(uint32_t));
5715 stat
->un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
5717 if (shdr_add_status
== ADD_STATUS_OPERATION_ALREADY_ACTIVE
)
5718 stat
->un
.b
.lsRjtRsnCodeExp
= LSEXP_CMD_IN_PROGRESS
;
5720 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
5721 phba
->fc_stat
.elsXmitLSRJT
++;
5722 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
5723 if (rc
== IOCB_ERROR
)
5724 lpfc_els_free_iocb(phba
, elsiocb
);
5730 lpfc_sli4_set_beacon(struct lpfc_vport
*vport
,
5731 struct lpfc_lcb_context
*lcb_context
,
5732 uint32_t beacon_state
)
5734 struct lpfc_hba
*phba
= vport
->phba
;
5735 LPFC_MBOXQ_t
*mbox
= NULL
;
5739 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
5743 len
= sizeof(struct lpfc_mbx_set_beacon_config
) -
5744 sizeof(struct lpfc_sli4_cfg_mhdr
);
5745 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
5746 LPFC_MBOX_OPCODE_SET_BEACON_CONFIG
, len
,
5747 LPFC_SLI4_MBX_EMBED
);
5748 mbox
->context1
= (void *)lcb_context
;
5749 mbox
->vport
= phba
->pport
;
5750 mbox
->mbox_cmpl
= lpfc_els_lcb_rsp
;
5751 bf_set(lpfc_mbx_set_beacon_port_num
, &mbox
->u
.mqe
.un
.beacon_config
,
5752 phba
->sli4_hba
.physical_port
);
5753 bf_set(lpfc_mbx_set_beacon_state
, &mbox
->u
.mqe
.un
.beacon_config
,
5755 bf_set(lpfc_mbx_set_beacon_port_type
, &mbox
->u
.mqe
.un
.beacon_config
, 1);
5756 bf_set(lpfc_mbx_set_beacon_duration
, &mbox
->u
.mqe
.un
.beacon_config
, 0);
5757 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
5758 if (rc
== MBX_NOT_FINISHED
) {
5759 mempool_free(mbox
, phba
->mbox_mem_pool
);
5768 * lpfc_els_rcv_lcb - Process an unsolicited LCB
5769 * @vport: pointer to a host virtual N_Port data structure.
5770 * @cmdiocb: pointer to lpfc command iocb data structure.
5771 * @ndlp: pointer to a node-list data structure.
5773 * This routine processes an unsolicited LCB(LINK CABLE BEACON) IOCB.
5774 * First, the payload of the unsolicited LCB is checked.
5775 * Then based on Subcommand beacon will either turn on or off.
5778 * 0 - Sent the acc response
5779 * 1 - Sent the reject response.
5782 lpfc_els_rcv_lcb(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
5783 struct lpfc_nodelist
*ndlp
)
5785 struct lpfc_hba
*phba
= vport
->phba
;
5786 struct lpfc_dmabuf
*pcmd
;
5788 struct fc_lcb_request_frame
*beacon
;
5789 struct lpfc_lcb_context
*lcb_context
;
5790 uint8_t state
, rjt_err
;
5793 pcmd
= (struct lpfc_dmabuf
*)cmdiocb
->context2
;
5794 lp
= (uint8_t *)pcmd
->virt
;
5795 beacon
= (struct fc_lcb_request_frame
*)pcmd
->virt
;
5797 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
5798 "0192 ELS LCB Data x%x x%x x%x x%x sub x%x "
5799 "type x%x frequency %x duration x%x\n",
5800 lp
[0], lp
[1], lp
[2],
5801 beacon
->lcb_command
,
5802 beacon
->lcb_sub_command
,
5804 beacon
->lcb_frequency
,
5805 be16_to_cpu(beacon
->lcb_duration
));
5807 if (phba
->sli_rev
< LPFC_SLI_REV4
||
5808 (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) !=
5809 LPFC_SLI_INTF_IF_TYPE_2
)) {
5810 rjt_err
= LSRJT_CMD_UNSUPPORTED
;
5814 if (phba
->hba_flag
& HBA_FCOE_MODE
) {
5815 rjt_err
= LSRJT_CMD_UNSUPPORTED
;
5818 if (beacon
->lcb_sub_command
!= LPFC_LCB_ON
&&
5819 beacon
->lcb_sub_command
!= LPFC_LCB_OFF
) {
5820 rjt_err
= LSRJT_CMD_UNSUPPORTED
;
5823 if (beacon
->lcb_sub_command
== LPFC_LCB_ON
&&
5824 be16_to_cpu(beacon
->lcb_duration
) != 0) {
5825 rjt_err
= LSRJT_CMD_UNSUPPORTED
;
5829 lcb_context
= kmalloc(sizeof(*lcb_context
), GFP_KERNEL
);
5831 rjt_err
= LSRJT_UNABLE_TPC
;
5835 state
= (beacon
->lcb_sub_command
== LPFC_LCB_ON
) ? 1 : 0;
5836 lcb_context
->sub_command
= beacon
->lcb_sub_command
;
5837 lcb_context
->type
= beacon
->lcb_type
;
5838 lcb_context
->frequency
= beacon
->lcb_frequency
;
5839 lcb_context
->ox_id
= cmdiocb
->iocb
.unsli3
.rcvsli3
.ox_id
;
5840 lcb_context
->rx_id
= cmdiocb
->iocb
.ulpContext
;
5841 lcb_context
->ndlp
= lpfc_nlp_get(ndlp
);
5842 if (lpfc_sli4_set_beacon(vport
, lcb_context
, state
)) {
5843 lpfc_printf_vlog(ndlp
->vport
, KERN_ERR
,
5844 LOG_ELS
, "0193 failed to send mail box");
5847 rjt_err
= LSRJT_UNABLE_TPC
;
5852 memset(&stat
, 0, sizeof(stat
));
5853 stat
.un
.b
.lsRjtRsnCode
= rjt_err
;
5854 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
5860 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
5861 * @vport: pointer to a host virtual N_Port data structure.
5863 * This routine cleans up any Registration State Change Notification
5864 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
5865 * @vport together with the host_lock is used to prevent multiple thread
5866 * trying to access the RSCN array on a same @vport at the same time.
5869 lpfc_els_flush_rscn(struct lpfc_vport
*vport
)
5871 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
5872 struct lpfc_hba
*phba
= vport
->phba
;
5875 spin_lock_irq(shost
->host_lock
);
5876 if (vport
->fc_rscn_flush
) {
5877 /* Another thread is walking fc_rscn_id_list on this vport */
5878 spin_unlock_irq(shost
->host_lock
);
5881 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
5882 vport
->fc_rscn_flush
= 1;
5883 spin_unlock_irq(shost
->host_lock
);
5885 for (i
= 0; i
< vport
->fc_rscn_id_cnt
; i
++) {
5886 lpfc_in_buf_free(phba
, vport
->fc_rscn_id_list
[i
]);
5887 vport
->fc_rscn_id_list
[i
] = NULL
;
5889 spin_lock_irq(shost
->host_lock
);
5890 vport
->fc_rscn_id_cnt
= 0;
5891 vport
->fc_flag
&= ~(FC_RSCN_MODE
| FC_RSCN_DISCOVERY
);
5892 spin_unlock_irq(shost
->host_lock
);
5893 lpfc_can_disctmo(vport
);
5894 /* Indicate we are done walking this fc_rscn_id_list */
5895 vport
->fc_rscn_flush
= 0;
5899 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
5900 * @vport: pointer to a host virtual N_Port data structure.
5901 * @did: remote destination port identifier.
5903 * This routine checks whether there is any pending Registration State
5904 * Configuration Notification (RSCN) to a @did on @vport.
5907 * None zero - The @did matched with a pending rscn
5908 * 0 - not able to match @did with a pending rscn
5911 lpfc_rscn_payload_check(struct lpfc_vport
*vport
, uint32_t did
)
5916 uint32_t payload_len
, i
;
5917 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
5919 ns_did
.un
.word
= did
;
5921 /* Never match fabric nodes for RSCNs */
5922 if ((did
& Fabric_DID_MASK
) == Fabric_DID_MASK
)
5925 /* If we are doing a FULL RSCN rediscovery, match everything */
5926 if (vport
->fc_flag
& FC_RSCN_DISCOVERY
)
5929 spin_lock_irq(shost
->host_lock
);
5930 if (vport
->fc_rscn_flush
) {
5931 /* Another thread is walking fc_rscn_id_list on this vport */
5932 spin_unlock_irq(shost
->host_lock
);
5935 /* Indicate we are walking fc_rscn_id_list on this vport */
5936 vport
->fc_rscn_flush
= 1;
5937 spin_unlock_irq(shost
->host_lock
);
5938 for (i
= 0; i
< vport
->fc_rscn_id_cnt
; i
++) {
5939 lp
= vport
->fc_rscn_id_list
[i
]->virt
;
5940 payload_len
= be32_to_cpu(*lp
++ & ~ELS_CMD_MASK
);
5941 payload_len
-= sizeof(uint32_t); /* take off word 0 */
5942 while (payload_len
) {
5943 rscn_did
.un
.word
= be32_to_cpu(*lp
++);
5944 payload_len
-= sizeof(uint32_t);
5945 switch (rscn_did
.un
.b
.resv
& RSCN_ADDRESS_FORMAT_MASK
) {
5946 case RSCN_ADDRESS_FORMAT_PORT
:
5947 if ((ns_did
.un
.b
.domain
== rscn_did
.un
.b
.domain
)
5948 && (ns_did
.un
.b
.area
== rscn_did
.un
.b
.area
)
5949 && (ns_did
.un
.b
.id
== rscn_did
.un
.b
.id
))
5950 goto return_did_out
;
5952 case RSCN_ADDRESS_FORMAT_AREA
:
5953 if ((ns_did
.un
.b
.domain
== rscn_did
.un
.b
.domain
)
5954 && (ns_did
.un
.b
.area
== rscn_did
.un
.b
.area
))
5955 goto return_did_out
;
5957 case RSCN_ADDRESS_FORMAT_DOMAIN
:
5958 if (ns_did
.un
.b
.domain
== rscn_did
.un
.b
.domain
)
5959 goto return_did_out
;
5961 case RSCN_ADDRESS_FORMAT_FABRIC
:
5962 goto return_did_out
;
5966 /* Indicate we are done with walking fc_rscn_id_list on this vport */
5967 vport
->fc_rscn_flush
= 0;
5970 /* Indicate we are done with walking fc_rscn_id_list on this vport */
5971 vport
->fc_rscn_flush
= 0;
5976 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
5977 * @vport: pointer to a host virtual N_Port data structure.
5979 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
5980 * state machine for a @vport's nodes that are with pending RSCN (Registration
5981 * State Change Notification).
5984 * 0 - Successful (currently alway return 0)
5987 lpfc_rscn_recovery_check(struct lpfc_vport
*vport
)
5989 struct lpfc_nodelist
*ndlp
= NULL
;
5991 /* Move all affected nodes by pending RSCNs to NPR state. */
5992 list_for_each_entry(ndlp
, &vport
->fc_nodes
, nlp_listp
) {
5993 if (!NLP_CHK_NODE_ACT(ndlp
) ||
5994 (ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
) ||
5995 !lpfc_rscn_payload_check(vport
, ndlp
->nlp_DID
))
5998 /* NVME Target mode does not do RSCN Recovery. */
5999 if (vport
->phba
->nvmet_support
)
6002 lpfc_disc_state_machine(vport
, ndlp
, NULL
,
6003 NLP_EVT_DEVICE_RECOVERY
);
6004 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
6010 * lpfc_send_rscn_event - Send an RSCN event to management application
6011 * @vport: pointer to a host virtual N_Port data structure.
6012 * @cmdiocb: pointer to lpfc command iocb data structure.
6014 * lpfc_send_rscn_event sends an RSCN netlink event to management
6018 lpfc_send_rscn_event(struct lpfc_vport
*vport
,
6019 struct lpfc_iocbq
*cmdiocb
)
6021 struct lpfc_dmabuf
*pcmd
;
6022 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
6023 uint32_t *payload_ptr
;
6024 uint32_t payload_len
;
6025 struct lpfc_rscn_event_header
*rscn_event_data
;
6027 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
6028 payload_ptr
= (uint32_t *) pcmd
->virt
;
6029 payload_len
= be32_to_cpu(*payload_ptr
& ~ELS_CMD_MASK
);
6031 rscn_event_data
= kmalloc(sizeof(struct lpfc_rscn_event_header
) +
6032 payload_len
, GFP_KERNEL
);
6033 if (!rscn_event_data
) {
6034 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
6035 "0147 Failed to allocate memory for RSCN event\n");
6038 rscn_event_data
->event_type
= FC_REG_RSCN_EVENT
;
6039 rscn_event_data
->payload_length
= payload_len
;
6040 memcpy(rscn_event_data
->rscn_payload
, payload_ptr
,
6043 fc_host_post_vendor_event(shost
,
6044 fc_get_event_number(),
6045 sizeof(struct lpfc_rscn_event_header
) + payload_len
,
6046 (char *)rscn_event_data
,
6049 kfree(rscn_event_data
);
6053 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
6054 * @vport: pointer to a host virtual N_Port data structure.
6055 * @cmdiocb: pointer to lpfc command iocb data structure.
6056 * @ndlp: pointer to a node-list data structure.
6058 * This routine processes an unsolicited RSCN (Registration State Change
6059 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
6060 * to invoke fc_host_post_event() routine to the FC transport layer. If the
6061 * discover state machine is about to begin discovery, it just accepts the
6062 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
6063 * contains N_Port IDs for other vports on this HBA, it just accepts the
6064 * RSCN and ignore processing it. If the state machine is in the recovery
6065 * state, the fc_rscn_id_list of this @vport is walked and the
6066 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
6067 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
6068 * routine is invoked to handle the RSCN event.
6071 * 0 - Just sent the acc response
6072 * 1 - Sent the acc response and waited for name server completion
6075 lpfc_els_rcv_rscn(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
6076 struct lpfc_nodelist
*ndlp
)
6078 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
6079 struct lpfc_hba
*phba
= vport
->phba
;
6080 struct lpfc_dmabuf
*pcmd
;
6081 uint32_t *lp
, *datap
;
6082 uint32_t payload_len
, length
, nportid
, *cmd
;
6084 int rscn_id
= 0, hba_id
= 0;
6087 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
6088 lp
= (uint32_t *) pcmd
->virt
;
6090 payload_len
= be32_to_cpu(*lp
++ & ~ELS_CMD_MASK
);
6091 payload_len
-= sizeof(uint32_t); /* take off word 0 */
6093 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
6094 "0214 RSCN received Data: x%x x%x x%x x%x\n",
6095 vport
->fc_flag
, payload_len
, *lp
,
6096 vport
->fc_rscn_id_cnt
);
6098 /* Send an RSCN event to the management application */
6099 lpfc_send_rscn_event(vport
, cmdiocb
);
6101 for (i
= 0; i
< payload_len
/sizeof(uint32_t); i
++)
6102 fc_host_post_event(shost
, fc_get_event_number(),
6103 FCH_EVT_RSCN
, lp
[i
]);
6105 /* If we are about to begin discovery, just ACC the RSCN.
6106 * Discovery processing will satisfy it.
6108 if (vport
->port_state
<= LPFC_NS_QRY
) {
6109 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6110 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
6111 ndlp
->nlp_DID
, vport
->port_state
, ndlp
->nlp_flag
);
6113 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
6117 /* If this RSCN just contains NPortIDs for other vports on this HBA,
6118 * just ACC and ignore it.
6120 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
6121 !(vport
->cfg_peer_port_login
)) {
6126 nportid
= ((be32_to_cpu(nportid
)) & Mask_DID
);
6127 i
-= sizeof(uint32_t);
6129 if (lpfc_find_vport_by_did(phba
, nportid
))
6132 if (rscn_id
== hba_id
) {
6133 /* ALL NPortIDs in RSCN are on HBA */
6134 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
6136 "Data: x%x x%x x%x x%x\n",
6137 vport
->fc_flag
, payload_len
,
6138 *lp
, vport
->fc_rscn_id_cnt
);
6139 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6140 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
6141 ndlp
->nlp_DID
, vport
->port_state
,
6144 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
,
6150 spin_lock_irq(shost
->host_lock
);
6151 if (vport
->fc_rscn_flush
) {
6152 /* Another thread is walking fc_rscn_id_list on this vport */
6153 vport
->fc_flag
|= FC_RSCN_DISCOVERY
;
6154 spin_unlock_irq(shost
->host_lock
);
6156 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
6159 /* Indicate we are walking fc_rscn_id_list on this vport */
6160 vport
->fc_rscn_flush
= 1;
6161 spin_unlock_irq(shost
->host_lock
);
6162 /* Get the array count after successfully have the token */
6163 rscn_cnt
= vport
->fc_rscn_id_cnt
;
6164 /* If we are already processing an RSCN, save the received
6165 * RSCN payload buffer, cmdiocb->context2 to process later.
6167 if (vport
->fc_flag
& (FC_RSCN_MODE
| FC_NDISC_ACTIVE
)) {
6168 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6169 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
6170 ndlp
->nlp_DID
, vport
->port_state
, ndlp
->nlp_flag
);
6172 spin_lock_irq(shost
->host_lock
);
6173 vport
->fc_flag
|= FC_RSCN_DEFERRED
;
6174 if ((rscn_cnt
< FC_MAX_HOLD_RSCN
) &&
6175 !(vport
->fc_flag
& FC_RSCN_DISCOVERY
)) {
6176 vport
->fc_flag
|= FC_RSCN_MODE
;
6177 spin_unlock_irq(shost
->host_lock
);
6179 cmd
= vport
->fc_rscn_id_list
[rscn_cnt
-1]->virt
;
6180 length
= be32_to_cpu(*cmd
& ~ELS_CMD_MASK
);
6183 (payload_len
+ length
<= LPFC_BPL_SIZE
)) {
6184 *cmd
&= ELS_CMD_MASK
;
6185 *cmd
|= cpu_to_be32(payload_len
+ length
);
6186 memcpy(((uint8_t *)cmd
) + length
, lp
,
6189 vport
->fc_rscn_id_list
[rscn_cnt
] = pcmd
;
6190 vport
->fc_rscn_id_cnt
++;
6191 /* If we zero, cmdiocb->context2, the calling
6192 * routine will not try to free it.
6194 cmdiocb
->context2
= NULL
;
6197 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
6198 "0235 Deferred RSCN "
6199 "Data: x%x x%x x%x\n",
6200 vport
->fc_rscn_id_cnt
, vport
->fc_flag
,
6203 vport
->fc_flag
|= FC_RSCN_DISCOVERY
;
6204 spin_unlock_irq(shost
->host_lock
);
6205 /* ReDiscovery RSCN */
6206 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
6207 "0234 ReDiscovery RSCN "
6208 "Data: x%x x%x x%x\n",
6209 vport
->fc_rscn_id_cnt
, vport
->fc_flag
,
6212 /* Indicate we are done walking fc_rscn_id_list on this vport */
6213 vport
->fc_rscn_flush
= 0;
6215 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
6216 /* send RECOVERY event for ALL nodes that match RSCN payload */
6217 lpfc_rscn_recovery_check(vport
);
6220 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6221 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
6222 ndlp
->nlp_DID
, vport
->port_state
, ndlp
->nlp_flag
);
6224 spin_lock_irq(shost
->host_lock
);
6225 vport
->fc_flag
|= FC_RSCN_MODE
;
6226 spin_unlock_irq(shost
->host_lock
);
6227 vport
->fc_rscn_id_list
[vport
->fc_rscn_id_cnt
++] = pcmd
;
6228 /* Indicate we are done walking fc_rscn_id_list on this vport */
6229 vport
->fc_rscn_flush
= 0;
6231 * If we zero, cmdiocb->context2, the calling routine will
6232 * not try to free it.
6234 cmdiocb
->context2
= NULL
;
6235 lpfc_set_disctmo(vport
);
6237 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
6238 /* send RECOVERY event for ALL nodes that match RSCN payload */
6239 lpfc_rscn_recovery_check(vport
);
6240 return lpfc_els_handle_rscn(vport
);
6244 * lpfc_els_handle_rscn - Handle rscn for a vport
6245 * @vport: pointer to a host virtual N_Port data structure.
6247 * This routine handles the Registration State Configuration Notification
6248 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
6249 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
6250 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
6251 * NameServer shall be issued. If CT command to the NameServer fails to be
6252 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
6253 * RSCN activities with the @vport.
6256 * 0 - Cleaned up rscn on the @vport
6257 * 1 - Wait for plogi to name server before proceed
6260 lpfc_els_handle_rscn(struct lpfc_vport
*vport
)
6262 struct lpfc_nodelist
*ndlp
;
6264 /* Ignore RSCN if the port is being torn down. */
6265 if (vport
->load_flag
& FC_UNLOADING
) {
6266 lpfc_els_flush_rscn(vport
);
6270 /* Start timer for RSCN processing */
6271 lpfc_set_disctmo(vport
);
6273 /* RSCN processed */
6274 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
6275 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
6276 vport
->fc_flag
, 0, vport
->fc_rscn_id_cnt
,
6279 /* To process RSCN, first compare RSCN data with NameServer */
6280 vport
->fc_ns_retry
= 0;
6281 vport
->num_disc_nodes
= 0;
6283 ndlp
= lpfc_findnode_did(vport
, NameServer_DID
);
6284 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
)
6285 && ndlp
->nlp_state
== NLP_STE_UNMAPPED_NODE
) {
6286 /* Good ndlp, issue CT Request to NameServer. Need to
6287 * know how many gidfts were issued. If none, then just
6288 * flush the RSCN. Otherwise, the outstanding requests
6291 vport
->gidft_inp
= 0;
6292 if (lpfc_issue_gidft(vport
) > 0)
6295 /* Nameserver login in question. Revalidate. */
6297 ndlp
= lpfc_enable_node(vport
, ndlp
,
6298 NLP_STE_PLOGI_ISSUE
);
6300 lpfc_els_flush_rscn(vport
);
6303 ndlp
->nlp_prev_state
= NLP_STE_UNUSED_NODE
;
6305 ndlp
= lpfc_nlp_init(vport
, NameServer_DID
);
6307 lpfc_els_flush_rscn(vport
);
6310 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
6311 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
6313 ndlp
->nlp_type
|= NLP_FABRIC
;
6314 lpfc_issue_els_plogi(vport
, NameServer_DID
, 0);
6315 /* Wait for NameServer login cmpl before we can
6321 lpfc_els_flush_rscn(vport
);
6326 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
6327 * @vport: pointer to a host virtual N_Port data structure.
6328 * @cmdiocb: pointer to lpfc command iocb data structure.
6329 * @ndlp: pointer to a node-list data structure.
6331 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
6332 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
6333 * point topology. As an unsolicited FLOGI should not be received in a loop
6334 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
6335 * lpfc_check_sparm() routine is invoked to check the parameters in the
6336 * unsolicited FLOGI. If parameters validation failed, the routine
6337 * lpfc_els_rsp_reject() shall be called with reject reason code set to
6338 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
6339 * FLOGI shall be compared with the Port WWN of the @vport to determine who
6340 * will initiate PLOGI. The higher lexicographical value party shall has
6341 * higher priority (as the winning port) and will initiate PLOGI and
6342 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
6343 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
6344 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
6347 * 0 - Successfully processed the unsolicited flogi
6348 * 1 - Failed to process the unsolicited flogi
6351 lpfc_els_rcv_flogi(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
6352 struct lpfc_nodelist
*ndlp
)
6354 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
6355 struct lpfc_hba
*phba
= vport
->phba
;
6356 struct lpfc_dmabuf
*pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
6357 uint32_t *lp
= (uint32_t *) pcmd
->virt
;
6358 IOCB_t
*icmd
= &cmdiocb
->iocb
;
6359 struct serv_parm
*sp
;
6363 uint32_t fc_flag
= 0;
6364 uint32_t port_state
= 0;
6367 sp
= (struct serv_parm
*) lp
;
6369 /* FLOGI received */
6371 lpfc_set_disctmo(vport
);
6373 if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) {
6374 /* We should never receive a FLOGI in loop mode, ignore it */
6375 did
= icmd
->un
.elsreq64
.remoteID
;
6377 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
6379 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
6380 "0113 An FLOGI ELS command x%x was "
6381 "received from DID x%x in Loop Mode\n",
6386 (void) lpfc_check_sparm(vport
, ndlp
, sp
, CLASS3
, 1);
6389 * If our portname is greater than the remote portname,
6390 * then we initiate Nport login.
6393 rc
= memcmp(&vport
->fc_portname
, &sp
->portName
,
6394 sizeof(struct lpfc_name
));
6397 if (phba
->sli_rev
< LPFC_SLI_REV4
) {
6398 mbox
= mempool_alloc(phba
->mbox_mem_pool
,
6402 lpfc_linkdown(phba
);
6403 lpfc_init_link(phba
, mbox
,
6405 phba
->cfg_link_speed
);
6406 mbox
->u
.mb
.un
.varInitLnk
.lipsr_AL_PA
= 0;
6407 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
6408 mbox
->vport
= vport
;
6409 rc
= lpfc_sli_issue_mbox(phba
, mbox
,
6411 lpfc_set_loopback_flag(phba
);
6412 if (rc
== MBX_NOT_FINISHED
)
6413 mempool_free(mbox
, phba
->mbox_mem_pool
);
6417 /* abort the flogi coming back to ourselves
6418 * due to external loopback on the port.
6420 lpfc_els_abort_flogi(phba
);
6423 } else if (rc
> 0) { /* greater than */
6424 spin_lock_irq(shost
->host_lock
);
6425 vport
->fc_flag
|= FC_PT2PT_PLOGI
;
6426 spin_unlock_irq(shost
->host_lock
);
6428 /* If we have the high WWPN we can assign our own
6429 * myDID; otherwise, we have to WAIT for a PLOGI
6430 * from the remote NPort to find out what it
6433 vport
->fc_myDID
= PT2PT_LocalID
;
6435 vport
->fc_myDID
= PT2PT_RemoteID
;
6439 * The vport state should go to LPFC_FLOGI only
6440 * AFTER we issue a FLOGI, not receive one.
6442 spin_lock_irq(shost
->host_lock
);
6443 fc_flag
= vport
->fc_flag
;
6444 port_state
= vport
->port_state
;
6445 vport
->fc_flag
|= FC_PT2PT
;
6446 vport
->fc_flag
&= ~(FC_FABRIC
| FC_PUBLIC_LOOP
);
6448 /* Acking an unsol FLOGI. Count 1 for link bounce
6451 vport
->rcv_flogi_cnt
++;
6452 spin_unlock_irq(shost
->host_lock
);
6453 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
6454 "3311 Rcv Flogi PS x%x new PS x%x "
6455 "fc_flag x%x new fc_flag x%x\n",
6456 port_state
, vport
->port_state
,
6457 fc_flag
, vport
->fc_flag
);
6460 * We temporarily set fc_myDID to make it look like we are
6461 * a Fabric. This is done just so we end up with the right
6462 * did / sid on the FLOGI ACC rsp.
6464 did
= vport
->fc_myDID
;
6465 vport
->fc_myDID
= Fabric_DID
;
6467 memcpy(&phba
->fc_fabparam
, sp
, sizeof(struct serv_parm
));
6470 lpfc_els_rsp_acc(vport
, ELS_CMD_FLOGI
, cmdiocb
, ndlp
, NULL
);
6472 /* Now lets put fc_myDID back to what its supposed to be */
6473 vport
->fc_myDID
= did
;
6479 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
6480 * @vport: pointer to a host virtual N_Port data structure.
6481 * @cmdiocb: pointer to lpfc command iocb data structure.
6482 * @ndlp: pointer to a node-list data structure.
6484 * This routine processes Request Node Identification Data (RNID) IOCB
6485 * received as an ELS unsolicited event. Only when the RNID specified format
6486 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
6487 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
6488 * Accept (ACC) the RNID ELS command. All the other RNID formats are
6489 * rejected by invoking the lpfc_els_rsp_reject() routine.
6492 * 0 - Successfully processed rnid iocb (currently always return 0)
6495 lpfc_els_rcv_rnid(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
6496 struct lpfc_nodelist
*ndlp
)
6498 struct lpfc_dmabuf
*pcmd
;
6504 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
6505 lp
= (uint32_t *) pcmd
->virt
;
6512 switch (rn
->Format
) {
6514 case RNID_TOPOLOGY_DISC
:
6516 lpfc_els_rsp_rnid_acc(vport
, rn
->Format
, cmdiocb
, ndlp
);
6519 /* Reject this request because format not supported */
6520 stat
.un
.b
.lsRjtRsvd0
= 0;
6521 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
6522 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CANT_GIVE_DATA
;
6523 stat
.un
.b
.vendorUnique
= 0;
6524 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
,
6531 * lpfc_els_rcv_echo - Process an unsolicited echo iocb
6532 * @vport: pointer to a host virtual N_Port data structure.
6533 * @cmdiocb: pointer to lpfc command iocb data structure.
6534 * @ndlp: pointer to a node-list data structure.
6537 * 0 - Successfully processed echo iocb (currently always return 0)
6540 lpfc_els_rcv_echo(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
6541 struct lpfc_nodelist
*ndlp
)
6545 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) cmdiocb
->context2
)->virt
);
6547 /* skip over first word of echo command to find echo data */
6548 pcmd
+= sizeof(uint32_t);
6550 lpfc_els_rsp_echo_acc(vport
, pcmd
, cmdiocb
, ndlp
);
6555 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
6556 * @vport: pointer to a host virtual N_Port data structure.
6557 * @cmdiocb: pointer to lpfc command iocb data structure.
6558 * @ndlp: pointer to a node-list data structure.
6560 * This routine processes a Link Incident Report Registration(LIRR) IOCB
6561 * received as an ELS unsolicited event. Currently, this function just invokes
6562 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
6565 * 0 - Successfully processed lirr iocb (currently always return 0)
6568 lpfc_els_rcv_lirr(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
6569 struct lpfc_nodelist
*ndlp
)
6573 /* For now, unconditionally reject this command */
6574 stat
.un
.b
.lsRjtRsvd0
= 0;
6575 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
6576 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CANT_GIVE_DATA
;
6577 stat
.un
.b
.vendorUnique
= 0;
6578 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
6583 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
6584 * @vport: pointer to a host virtual N_Port data structure.
6585 * @cmdiocb: pointer to lpfc command iocb data structure.
6586 * @ndlp: pointer to a node-list data structure.
6588 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
6589 * received as an ELS unsolicited event. A request to RRQ shall only
6590 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
6591 * Nx_Port N_Port_ID of the target Exchange is the same as the
6592 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
6593 * not accepted, an LS_RJT with reason code "Unable to perform
6594 * command request" and reason code explanation "Invalid Originator
6595 * S_ID" shall be returned. For now, we just unconditionally accept
6596 * RRQ from the target.
6599 lpfc_els_rcv_rrq(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
6600 struct lpfc_nodelist
*ndlp
)
6602 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
6603 if (vport
->phba
->sli_rev
== LPFC_SLI_REV4
)
6604 lpfc_els_clear_rrq(vport
, cmdiocb
, ndlp
);
6608 * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
6609 * @phba: pointer to lpfc hba data structure.
6610 * @pmb: pointer to the driver internal queue element for mailbox command.
6612 * This routine is the completion callback function for the MBX_READ_LNK_STAT
6613 * mailbox command. This callback function is to actually send the Accept
6614 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
6615 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
6616 * mailbox command, constructs the RPS response with the link statistics
6617 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
6618 * response to the RPS.
6620 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6621 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6622 * will be stored into the context1 field of the IOCB for the completion
6623 * callback function to the RPS Accept Response ELS IOCB command.
6627 lpfc_els_rsp_rls_acc(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
6631 struct RLS_RSP
*rls_rsp
;
6633 struct lpfc_iocbq
*elsiocb
;
6634 struct lpfc_nodelist
*ndlp
;
6641 ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
6642 rxid
= (uint16_t) ((unsigned long)(pmb
->context1
) & 0xffff);
6643 oxid
= (uint16_t) (((unsigned long)(pmb
->context1
) >> 16) & 0xffff);
6644 pmb
->context1
= NULL
;
6645 pmb
->context2
= NULL
;
6647 if (mb
->mbxStatus
) {
6648 mempool_free(pmb
, phba
->mbox_mem_pool
);
6652 cmdsize
= sizeof(struct RLS_RSP
) + sizeof(uint32_t);
6653 elsiocb
= lpfc_prep_els_iocb(phba
->pport
, 0, cmdsize
,
6654 lpfc_max_els_tries
, ndlp
,
6655 ndlp
->nlp_DID
, ELS_CMD_ACC
);
6657 /* Decrement the ndlp reference count from previous mbox command */
6661 mempool_free(pmb
, phba
->mbox_mem_pool
);
6665 icmd
= &elsiocb
->iocb
;
6666 icmd
->ulpContext
= rxid
;
6667 icmd
->unsli3
.rcvsli3
.ox_id
= oxid
;
6669 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
6670 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
6671 pcmd
+= sizeof(uint32_t); /* Skip past command */
6672 rls_rsp
= (struct RLS_RSP
*)pcmd
;
6674 rls_rsp
->linkFailureCnt
= cpu_to_be32(mb
->un
.varRdLnk
.linkFailureCnt
);
6675 rls_rsp
->lossSyncCnt
= cpu_to_be32(mb
->un
.varRdLnk
.lossSyncCnt
);
6676 rls_rsp
->lossSignalCnt
= cpu_to_be32(mb
->un
.varRdLnk
.lossSignalCnt
);
6677 rls_rsp
->primSeqErrCnt
= cpu_to_be32(mb
->un
.varRdLnk
.primSeqErrCnt
);
6678 rls_rsp
->invalidXmitWord
= cpu_to_be32(mb
->un
.varRdLnk
.invalidXmitWord
);
6679 rls_rsp
->crcCnt
= cpu_to_be32(mb
->un
.varRdLnk
.crcCnt
);
6680 mempool_free(pmb
, phba
->mbox_mem_pool
);
6681 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
6682 lpfc_printf_vlog(ndlp
->vport
, KERN_INFO
, LOG_ELS
,
6683 "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
6684 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
6685 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
6686 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
6688 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
6689 phba
->fc_stat
.elsXmitACC
++;
6690 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) == IOCB_ERROR
)
6691 lpfc_els_free_iocb(phba
, elsiocb
);
6695 * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
6696 * @phba: pointer to lpfc hba data structure.
6697 * @pmb: pointer to the driver internal queue element for mailbox command.
6699 * This routine is the completion callback function for the MBX_READ_LNK_STAT
6700 * mailbox command. This callback function is to actually send the Accept
6701 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
6702 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
6703 * mailbox command, constructs the RPS response with the link statistics
6704 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
6705 * response to the RPS.
6707 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6708 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6709 * will be stored into the context1 field of the IOCB for the completion
6710 * callback function to the RPS Accept Response ELS IOCB command.
6714 lpfc_els_rsp_rps_acc(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
6720 struct lpfc_iocbq
*elsiocb
;
6721 struct lpfc_nodelist
*ndlp
;
6729 ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
6730 rxid
= (uint16_t) ((unsigned long)(pmb
->context1
) & 0xffff);
6731 oxid
= (uint16_t) (((unsigned long)(pmb
->context1
) >> 16) & 0xffff);
6732 pmb
->context1
= NULL
;
6733 pmb
->context2
= NULL
;
6735 if (mb
->mbxStatus
) {
6736 mempool_free(pmb
, phba
->mbox_mem_pool
);
6740 cmdsize
= sizeof(RPS_RSP
) + sizeof(uint32_t);
6741 mempool_free(pmb
, phba
->mbox_mem_pool
);
6742 elsiocb
= lpfc_prep_els_iocb(phba
->pport
, 0, cmdsize
,
6743 lpfc_max_els_tries
, ndlp
,
6744 ndlp
->nlp_DID
, ELS_CMD_ACC
);
6746 /* Decrement the ndlp reference count from previous mbox command */
6752 icmd
= &elsiocb
->iocb
;
6753 icmd
->ulpContext
= rxid
;
6754 icmd
->unsli3
.rcvsli3
.ox_id
= oxid
;
6756 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
6757 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
6758 pcmd
+= sizeof(uint32_t); /* Skip past command */
6759 rps_rsp
= (RPS_RSP
*)pcmd
;
6761 if (phba
->fc_topology
!= LPFC_TOPOLOGY_LOOP
)
6765 if (phba
->pport
->fc_flag
& FC_FABRIC
)
6769 rps_rsp
->portStatus
= cpu_to_be16(status
);
6770 rps_rsp
->linkFailureCnt
= cpu_to_be32(mb
->un
.varRdLnk
.linkFailureCnt
);
6771 rps_rsp
->lossSyncCnt
= cpu_to_be32(mb
->un
.varRdLnk
.lossSyncCnt
);
6772 rps_rsp
->lossSignalCnt
= cpu_to_be32(mb
->un
.varRdLnk
.lossSignalCnt
);
6773 rps_rsp
->primSeqErrCnt
= cpu_to_be32(mb
->un
.varRdLnk
.primSeqErrCnt
);
6774 rps_rsp
->invalidXmitWord
= cpu_to_be32(mb
->un
.varRdLnk
.invalidXmitWord
);
6775 rps_rsp
->crcCnt
= cpu_to_be32(mb
->un
.varRdLnk
.crcCnt
);
6776 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
6777 lpfc_printf_vlog(ndlp
->vport
, KERN_INFO
, LOG_ELS
,
6778 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
6779 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
6780 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
6781 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
6783 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
6784 phba
->fc_stat
.elsXmitACC
++;
6785 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) == IOCB_ERROR
)
6786 lpfc_els_free_iocb(phba
, elsiocb
);
6791 * lpfc_els_rcv_rls - Process an unsolicited rls iocb
6792 * @vport: pointer to a host virtual N_Port data structure.
6793 * @cmdiocb: pointer to lpfc command iocb data structure.
6794 * @ndlp: pointer to a node-list data structure.
6796 * This routine processes Read Port Status (RPL) IOCB received as an
6797 * ELS unsolicited event. It first checks the remote port state. If the
6798 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
6799 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
6800 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
6801 * for reading the HBA link statistics. It is for the callback function,
6802 * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
6803 * to actually sending out RPL Accept (ACC) response.
6806 * 0 - Successfully processed rls iocb (currently always return 0)
6809 lpfc_els_rcv_rls(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
6810 struct lpfc_nodelist
*ndlp
)
6812 struct lpfc_hba
*phba
= vport
->phba
;
6816 if ((ndlp
->nlp_state
!= NLP_STE_UNMAPPED_NODE
) &&
6817 (ndlp
->nlp_state
!= NLP_STE_MAPPED_NODE
))
6818 /* reject the unsolicited RPS request and done with it */
6821 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_ATOMIC
);
6823 lpfc_read_lnk_stat(phba
, mbox
);
6824 mbox
->context1
= (void *)((unsigned long)
6825 ((cmdiocb
->iocb
.unsli3
.rcvsli3
.ox_id
<< 16) |
6826 cmdiocb
->iocb
.ulpContext
)); /* rx_id */
6827 mbox
->context2
= lpfc_nlp_get(ndlp
);
6828 mbox
->vport
= vport
;
6829 mbox
->mbox_cmpl
= lpfc_els_rsp_rls_acc
;
6830 if (lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
)
6831 != MBX_NOT_FINISHED
)
6832 /* Mbox completion will send ELS Response */
6834 /* Decrement reference count used for the failed mbox
6838 mempool_free(mbox
, phba
->mbox_mem_pool
);
6841 /* issue rejection response */
6842 stat
.un
.b
.lsRjtRsvd0
= 0;
6843 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
6844 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CANT_GIVE_DATA
;
6845 stat
.un
.b
.vendorUnique
= 0;
6846 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
6851 * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
6852 * @vport: pointer to a host virtual N_Port data structure.
6853 * @cmdiocb: pointer to lpfc command iocb data structure.
6854 * @ndlp: pointer to a node-list data structure.
6856 * This routine processes Read Timout Value (RTV) IOCB received as an
6857 * ELS unsolicited event. It first checks the remote port state. If the
6858 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
6859 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
6860 * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
6861 * Value (RTV) unsolicited IOCB event.
6863 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6864 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6865 * will be stored into the context1 field of the IOCB for the completion
6866 * callback function to the RPS Accept Response ELS IOCB command.
6869 * 0 - Successfully processed rtv iocb (currently always return 0)
6872 lpfc_els_rcv_rtv(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
6873 struct lpfc_nodelist
*ndlp
)
6875 struct lpfc_hba
*phba
= vport
->phba
;
6877 struct RTV_RSP
*rtv_rsp
;
6879 struct lpfc_iocbq
*elsiocb
;
6883 if ((ndlp
->nlp_state
!= NLP_STE_UNMAPPED_NODE
) &&
6884 (ndlp
->nlp_state
!= NLP_STE_MAPPED_NODE
))
6885 /* reject the unsolicited RPS request and done with it */
6888 cmdsize
= sizeof(struct RTV_RSP
) + sizeof(uint32_t);
6889 elsiocb
= lpfc_prep_els_iocb(phba
->pport
, 0, cmdsize
,
6890 lpfc_max_els_tries
, ndlp
,
6891 ndlp
->nlp_DID
, ELS_CMD_ACC
);
6896 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
6897 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
6898 pcmd
+= sizeof(uint32_t); /* Skip past command */
6900 /* use the command's xri in the response */
6901 elsiocb
->iocb
.ulpContext
= cmdiocb
->iocb
.ulpContext
; /* Xri / rx_id */
6902 elsiocb
->iocb
.unsli3
.rcvsli3
.ox_id
= cmdiocb
->iocb
.unsli3
.rcvsli3
.ox_id
;
6904 rtv_rsp
= (struct RTV_RSP
*)pcmd
;
6906 /* populate RTV payload */
6907 rtv_rsp
->ratov
= cpu_to_be32(phba
->fc_ratov
* 1000); /* report msecs */
6908 rtv_rsp
->edtov
= cpu_to_be32(phba
->fc_edtov
);
6909 bf_set(qtov_edtovres
, rtv_rsp
, phba
->fc_edtovResol
? 1 : 0);
6910 bf_set(qtov_rttov
, rtv_rsp
, 0); /* Field is for FC ONLY */
6911 rtv_rsp
->qtov
= cpu_to_be32(rtv_rsp
->qtov
);
6913 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
6914 lpfc_printf_vlog(ndlp
->vport
, KERN_INFO
, LOG_ELS
,
6915 "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
6916 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
6917 "Data: x%x x%x x%x\n",
6918 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
6919 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
6921 rtv_rsp
->ratov
, rtv_rsp
->edtov
, rtv_rsp
->qtov
);
6922 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
6923 phba
->fc_stat
.elsXmitACC
++;
6924 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) == IOCB_ERROR
)
6925 lpfc_els_free_iocb(phba
, elsiocb
);
6929 /* issue rejection response */
6930 stat
.un
.b
.lsRjtRsvd0
= 0;
6931 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
6932 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CANT_GIVE_DATA
;
6933 stat
.un
.b
.vendorUnique
= 0;
6934 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
6938 /* lpfc_els_rcv_rps - Process an unsolicited rps iocb
6939 * @vport: pointer to a host virtual N_Port data structure.
6940 * @cmdiocb: pointer to lpfc command iocb data structure.
6941 * @ndlp: pointer to a node-list data structure.
6943 * This routine processes Read Port Status (RPS) IOCB received as an
6944 * ELS unsolicited event. It first checks the remote port state. If the
6945 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
6946 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
6947 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
6948 * for reading the HBA link statistics. It is for the callback function,
6949 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
6950 * to actually sending out RPS Accept (ACC) response.
6953 * 0 - Successfully processed rps iocb (currently always return 0)
6956 lpfc_els_rcv_rps(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
6957 struct lpfc_nodelist
*ndlp
)
6959 struct lpfc_hba
*phba
= vport
->phba
;
6963 struct lpfc_dmabuf
*pcmd
;
6967 if ((ndlp
->nlp_state
!= NLP_STE_UNMAPPED_NODE
) &&
6968 (ndlp
->nlp_state
!= NLP_STE_MAPPED_NODE
))
6969 /* reject the unsolicited RPS request and done with it */
6972 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
6973 lp
= (uint32_t *) pcmd
->virt
;
6974 flag
= (be32_to_cpu(*lp
++) & 0xf);
6978 ((flag
== 1) && (be32_to_cpu(rps
->un
.portNum
) == 0)) ||
6979 ((flag
== 2) && (memcmp(&rps
->un
.portName
, &vport
->fc_portname
,
6980 sizeof(struct lpfc_name
)) == 0))) {
6982 printk("Fix me....\n");
6984 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_ATOMIC
);
6986 lpfc_read_lnk_stat(phba
, mbox
);
6987 mbox
->context1
= (void *)((unsigned long)
6988 ((cmdiocb
->iocb
.unsli3
.rcvsli3
.ox_id
<< 16) |
6989 cmdiocb
->iocb
.ulpContext
)); /* rx_id */
6990 mbox
->context2
= lpfc_nlp_get(ndlp
);
6991 mbox
->vport
= vport
;
6992 mbox
->mbox_cmpl
= lpfc_els_rsp_rps_acc
;
6993 if (lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
)
6994 != MBX_NOT_FINISHED
)
6995 /* Mbox completion will send ELS Response */
6997 /* Decrement reference count used for the failed mbox
7001 mempool_free(mbox
, phba
->mbox_mem_pool
);
7006 /* issue rejection response */
7007 stat
.un
.b
.lsRjtRsvd0
= 0;
7008 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
7009 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CANT_GIVE_DATA
;
7010 stat
.un
.b
.vendorUnique
= 0;
7011 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
7015 /* lpfc_issue_els_rrq - Process an unsolicited rps iocb
7016 * @vport: pointer to a host virtual N_Port data structure.
7017 * @ndlp: pointer to a node-list data structure.
7018 * @did: DID of the target.
7019 * @rrq: Pointer to the rrq struct.
7021 * Build a ELS RRQ command and send it to the target. If the issue_iocb is
7022 * Successful the the completion handler will clear the RRQ.
7025 * 0 - Successfully sent rrq els iocb.
7026 * 1 - Failed to send rrq els iocb.
7029 lpfc_issue_els_rrq(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
7030 uint32_t did
, struct lpfc_node_rrq
*rrq
)
7032 struct lpfc_hba
*phba
= vport
->phba
;
7033 struct RRQ
*els_rrq
;
7034 struct lpfc_iocbq
*elsiocb
;
7040 if (ndlp
!= rrq
->ndlp
)
7042 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
))
7045 /* If ndlp is not NULL, we will bump the reference count on it */
7046 cmdsize
= (sizeof(uint32_t) + sizeof(struct RRQ
));
7047 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, 0, ndlp
, did
,
7052 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
7054 /* For RRQ request, remainder of payload is Exchange IDs */
7055 *((uint32_t *) (pcmd
)) = ELS_CMD_RRQ
;
7056 pcmd
+= sizeof(uint32_t);
7057 els_rrq
= (struct RRQ
*) pcmd
;
7059 bf_set(rrq_oxid
, els_rrq
, phba
->sli4_hba
.xri_ids
[rrq
->xritag
]);
7060 bf_set(rrq_rxid
, els_rrq
, rrq
->rxid
);
7061 bf_set(rrq_did
, els_rrq
, vport
->fc_myDID
);
7062 els_rrq
->rrq
= cpu_to_be32(els_rrq
->rrq
);
7063 els_rrq
->rrq_exchg
= cpu_to_be32(els_rrq
->rrq_exchg
);
7066 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
7067 "Issue RRQ: did:x%x",
7068 did
, rrq
->xritag
, rrq
->rxid
);
7069 elsiocb
->context_un
.rrq
= rrq
;
7070 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rrq
;
7071 ret
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
7073 if (ret
== IOCB_ERROR
) {
7074 lpfc_els_free_iocb(phba
, elsiocb
);
7081 * lpfc_send_rrq - Sends ELS RRQ if needed.
7082 * @phba: pointer to lpfc hba data structure.
7083 * @rrq: pointer to the active rrq.
7085 * This routine will call the lpfc_issue_els_rrq if the rrq is
7086 * still active for the xri. If this function returns a failure then
7087 * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq.
7089 * Returns 0 Success.
7093 lpfc_send_rrq(struct lpfc_hba
*phba
, struct lpfc_node_rrq
*rrq
)
7095 struct lpfc_nodelist
*ndlp
= lpfc_findnode_did(rrq
->vport
,
7100 if (lpfc_test_rrq_active(phba
, ndlp
, rrq
->xritag
))
7101 return lpfc_issue_els_rrq(rrq
->vport
, ndlp
,
7108 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
7109 * @vport: pointer to a host virtual N_Port data structure.
7110 * @cmdsize: size of the ELS command.
7111 * @oldiocb: pointer to the original lpfc command iocb data structure.
7112 * @ndlp: pointer to a node-list data structure.
7114 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
7115 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
7117 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7118 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7119 * will be stored into the context1 field of the IOCB for the completion
7120 * callback function to the RPL Accept Response ELS command.
7123 * 0 - Successfully issued ACC RPL ELS command
7124 * 1 - Failed to issue ACC RPL ELS command
7127 lpfc_els_rsp_rpl_acc(struct lpfc_vport
*vport
, uint16_t cmdsize
,
7128 struct lpfc_iocbq
*oldiocb
, struct lpfc_nodelist
*ndlp
)
7130 struct lpfc_hba
*phba
= vport
->phba
;
7131 IOCB_t
*icmd
, *oldcmd
;
7133 struct lpfc_iocbq
*elsiocb
;
7136 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
7137 ndlp
->nlp_DID
, ELS_CMD_ACC
);
7142 icmd
= &elsiocb
->iocb
;
7143 oldcmd
= &oldiocb
->iocb
;
7144 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri / rx_id */
7145 icmd
->unsli3
.rcvsli3
.ox_id
= oldcmd
->unsli3
.rcvsli3
.ox_id
;
7147 pcmd
= (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
7148 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
7149 pcmd
+= sizeof(uint16_t);
7150 *((uint16_t *)(pcmd
)) = be16_to_cpu(cmdsize
);
7151 pcmd
+= sizeof(uint16_t);
7153 /* Setup the RPL ACC payload */
7154 rpl_rsp
.listLen
= be32_to_cpu(1);
7156 rpl_rsp
.port_num_blk
.portNum
= 0;
7157 rpl_rsp
.port_num_blk
.portID
= be32_to_cpu(vport
->fc_myDID
);
7158 memcpy(&rpl_rsp
.port_num_blk
.portName
, &vport
->fc_portname
,
7159 sizeof(struct lpfc_name
));
7160 memcpy(pcmd
, &rpl_rsp
, cmdsize
- sizeof(uint32_t));
7161 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
7162 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
7163 "0120 Xmit ELS RPL ACC response tag x%x "
7164 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
7166 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
7167 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
7169 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
7170 phba
->fc_stat
.elsXmitACC
++;
7171 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) ==
7173 lpfc_els_free_iocb(phba
, elsiocb
);
7180 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
7181 * @vport: pointer to a host virtual N_Port data structure.
7182 * @cmdiocb: pointer to lpfc command iocb data structure.
7183 * @ndlp: pointer to a node-list data structure.
7185 * This routine processes Read Port List (RPL) IOCB received as an ELS
7186 * unsolicited event. It first checks the remote port state. If the remote
7187 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
7188 * invokes the lpfc_els_rsp_reject() routine to send reject response.
7189 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
7190 * to accept the RPL.
7193 * 0 - Successfully processed rpl iocb (currently always return 0)
7196 lpfc_els_rcv_rpl(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
7197 struct lpfc_nodelist
*ndlp
)
7199 struct lpfc_dmabuf
*pcmd
;
7206 if ((ndlp
->nlp_state
!= NLP_STE_UNMAPPED_NODE
) &&
7207 (ndlp
->nlp_state
!= NLP_STE_MAPPED_NODE
)) {
7208 /* issue rejection response */
7209 stat
.un
.b
.lsRjtRsvd0
= 0;
7210 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
7211 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CANT_GIVE_DATA
;
7212 stat
.un
.b
.vendorUnique
= 0;
7213 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
,
7215 /* rejected the unsolicited RPL request and done with it */
7219 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
7220 lp
= (uint32_t *) pcmd
->virt
;
7221 rpl
= (RPL
*) (lp
+ 1);
7222 maxsize
= be32_to_cpu(rpl
->maxsize
);
7224 /* We support only one port */
7225 if ((rpl
->index
== 0) &&
7227 ((maxsize
* sizeof(uint32_t)) >= sizeof(RPL_RSP
)))) {
7228 cmdsize
= sizeof(uint32_t) + sizeof(RPL_RSP
);
7230 cmdsize
= sizeof(uint32_t) + maxsize
* sizeof(uint32_t);
7232 lpfc_els_rsp_rpl_acc(vport
, cmdsize
, cmdiocb
, ndlp
);
7238 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
7239 * @vport: pointer to a virtual N_Port data structure.
7240 * @cmdiocb: pointer to lpfc command iocb data structure.
7241 * @ndlp: pointer to a node-list data structure.
7243 * This routine processes Fibre Channel Address Resolution Protocol
7244 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
7245 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
7246 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
7247 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
7248 * remote PortName is compared against the FC PortName stored in the @vport
7249 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
7250 * compared against the FC NodeName stored in the @vport data structure.
7251 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
7252 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
7253 * invoked to send out FARP Response to the remote node. Before sending the
7254 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
7255 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
7256 * routine is invoked to log into the remote port first.
7259 * 0 - Either the FARP Match Mode not supported or successfully processed
7262 lpfc_els_rcv_farp(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
7263 struct lpfc_nodelist
*ndlp
)
7265 struct lpfc_dmabuf
*pcmd
;
7269 uint32_t cmd
, cnt
, did
;
7271 icmd
= &cmdiocb
->iocb
;
7272 did
= icmd
->un
.elsreq64
.remoteID
;
7273 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
7274 lp
= (uint32_t *) pcmd
->virt
;
7278 /* FARP-REQ received from DID <did> */
7279 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
7280 "0601 FARP-REQ received from DID x%x\n", did
);
7281 /* We will only support match on WWPN or WWNN */
7282 if (fp
->Mflags
& ~(FARP_MATCH_NODE
| FARP_MATCH_PORT
)) {
7287 /* If this FARP command is searching for my portname */
7288 if (fp
->Mflags
& FARP_MATCH_PORT
) {
7289 if (memcmp(&fp
->RportName
, &vport
->fc_portname
,
7290 sizeof(struct lpfc_name
)) == 0)
7294 /* If this FARP command is searching for my nodename */
7295 if (fp
->Mflags
& FARP_MATCH_NODE
) {
7296 if (memcmp(&fp
->RnodeName
, &vport
->fc_nodename
,
7297 sizeof(struct lpfc_name
)) == 0)
7302 if ((ndlp
->nlp_state
== NLP_STE_UNMAPPED_NODE
) ||
7303 (ndlp
->nlp_state
== NLP_STE_MAPPED_NODE
)) {
7304 /* Log back into the node before sending the FARP. */
7305 if (fp
->Rflags
& FARP_REQUEST_PLOGI
) {
7306 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
7307 lpfc_nlp_set_state(vport
, ndlp
,
7308 NLP_STE_PLOGI_ISSUE
);
7309 lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0);
7312 /* Send a FARP response to that node */
7313 if (fp
->Rflags
& FARP_REQUEST_FARPR
)
7314 lpfc_issue_els_farpr(vport
, did
, 0);
7321 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
7322 * @vport: pointer to a host virtual N_Port data structure.
7323 * @cmdiocb: pointer to lpfc command iocb data structure.
7324 * @ndlp: pointer to a node-list data structure.
7326 * This routine processes Fibre Channel Address Resolution Protocol
7327 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
7328 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
7329 * the FARP response request.
7332 * 0 - Successfully processed FARPR IOCB (currently always return 0)
7335 lpfc_els_rcv_farpr(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
7336 struct lpfc_nodelist
*ndlp
)
7338 struct lpfc_dmabuf
*pcmd
;
7343 icmd
= &cmdiocb
->iocb
;
7344 did
= icmd
->un
.elsreq64
.remoteID
;
7345 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
7346 lp
= (uint32_t *) pcmd
->virt
;
7349 /* FARP-RSP received from DID <did> */
7350 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
7351 "0600 FARP-RSP received from DID x%x\n", did
);
7352 /* ACCEPT the Farp resp request */
7353 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
7359 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
7360 * @vport: pointer to a host virtual N_Port data structure.
7361 * @cmdiocb: pointer to lpfc command iocb data structure.
7362 * @fan_ndlp: pointer to a node-list data structure.
7364 * This routine processes a Fabric Address Notification (FAN) IOCB
7365 * command received as an ELS unsolicited event. The FAN ELS command will
7366 * only be processed on a physical port (i.e., the @vport represents the
7367 * physical port). The fabric NodeName and PortName from the FAN IOCB are
7368 * compared against those in the phba data structure. If any of those is
7369 * different, the lpfc_initial_flogi() routine is invoked to initialize
7370 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
7371 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
7372 * is invoked to register login to the fabric.
7375 * 0 - Successfully processed fan iocb (currently always return 0).
7378 lpfc_els_rcv_fan(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
7379 struct lpfc_nodelist
*fan_ndlp
)
7381 struct lpfc_hba
*phba
= vport
->phba
;
7385 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
, "0265 FAN received\n");
7386 lp
= (uint32_t *)((struct lpfc_dmabuf
*)cmdiocb
->context2
)->virt
;
7388 /* FAN received; Fan does not have a reply sequence */
7389 if ((vport
== phba
->pport
) &&
7390 (vport
->port_state
== LPFC_LOCAL_CFG_LINK
)) {
7391 if ((memcmp(&phba
->fc_fabparam
.nodeName
, &fp
->FnodeName
,
7392 sizeof(struct lpfc_name
))) ||
7393 (memcmp(&phba
->fc_fabparam
.portName
, &fp
->FportName
,
7394 sizeof(struct lpfc_name
)))) {
7395 /* This port has switched fabrics. FLOGI is required */
7396 lpfc_issue_init_vfi(vport
);
7398 /* FAN verified - skip FLOGI */
7399 vport
->fc_myDID
= vport
->fc_prevDID
;
7400 if (phba
->sli_rev
< LPFC_SLI_REV4
)
7401 lpfc_issue_fabric_reglogin(vport
);
7403 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
7404 "3138 Need register VFI: (x%x/%x)\n",
7405 vport
->fc_prevDID
, vport
->fc_myDID
);
7406 lpfc_issue_reg_vfi(vport
);
7414 * lpfc_els_timeout - Handler funciton to the els timer
7415 * @ptr: holder for the timer function associated data.
7417 * This routine is invoked by the ELS timer after timeout. It posts the ELS
7418 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
7419 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
7420 * up the worker thread. It is for the worker thread to invoke the routine
7421 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
7424 lpfc_els_timeout(struct timer_list
*t
)
7426 struct lpfc_vport
*vport
= from_timer(vport
, t
, els_tmofunc
);
7427 struct lpfc_hba
*phba
= vport
->phba
;
7428 uint32_t tmo_posted
;
7429 unsigned long iflag
;
7431 spin_lock_irqsave(&vport
->work_port_lock
, iflag
);
7432 tmo_posted
= vport
->work_port_events
& WORKER_ELS_TMO
;
7433 if ((!tmo_posted
) && (!(vport
->load_flag
& FC_UNLOADING
)))
7434 vport
->work_port_events
|= WORKER_ELS_TMO
;
7435 spin_unlock_irqrestore(&vport
->work_port_lock
, iflag
);
7437 if ((!tmo_posted
) && (!(vport
->load_flag
& FC_UNLOADING
)))
7438 lpfc_worker_wake_up(phba
);
7444 * lpfc_els_timeout_handler - Process an els timeout event
7445 * @vport: pointer to a virtual N_Port data structure.
7447 * This routine is the actual handler function that processes an ELS timeout
7448 * event. It walks the ELS ring to get and abort all the IOCBs (except the
7449 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
7450 * invoking the lpfc_sli_issue_abort_iotag() routine.
7453 lpfc_els_timeout_handler(struct lpfc_vport
*vport
)
7455 struct lpfc_hba
*phba
= vport
->phba
;
7456 struct lpfc_sli_ring
*pring
;
7457 struct lpfc_iocbq
*tmp_iocb
, *piocb
;
7459 struct lpfc_dmabuf
*pcmd
;
7460 uint32_t els_command
= 0;
7462 uint32_t remote_ID
= 0xffffffff;
7463 LIST_HEAD(abort_list
);
7466 timeout
= (uint32_t)(phba
->fc_ratov
<< 1);
7468 pring
= lpfc_phba_elsring(phba
);
7469 if (unlikely(!pring
))
7472 if ((phba
->pport
->load_flag
& FC_UNLOADING
))
7474 spin_lock_irq(&phba
->hbalock
);
7475 if (phba
->sli_rev
== LPFC_SLI_REV4
)
7476 spin_lock(&pring
->ring_lock
);
7478 if ((phba
->pport
->load_flag
& FC_UNLOADING
)) {
7479 if (phba
->sli_rev
== LPFC_SLI_REV4
)
7480 spin_unlock(&pring
->ring_lock
);
7481 spin_unlock_irq(&phba
->hbalock
);
7485 list_for_each_entry_safe(piocb
, tmp_iocb
, &pring
->txcmplq
, list
) {
7488 if ((piocb
->iocb_flag
& LPFC_IO_LIBDFC
) != 0 ||
7489 piocb
->iocb
.ulpCommand
== CMD_ABORT_XRI_CN
||
7490 piocb
->iocb
.ulpCommand
== CMD_CLOSE_XRI_CN
)
7493 if (piocb
->vport
!= vport
)
7496 pcmd
= (struct lpfc_dmabuf
*) piocb
->context2
;
7498 els_command
= *(uint32_t *) (pcmd
->virt
);
7500 if (els_command
== ELS_CMD_FARP
||
7501 els_command
== ELS_CMD_FARPR
||
7502 els_command
== ELS_CMD_FDISC
)
7505 if (piocb
->drvrTimeout
> 0) {
7506 if (piocb
->drvrTimeout
>= timeout
)
7507 piocb
->drvrTimeout
-= timeout
;
7509 piocb
->drvrTimeout
= 0;
7513 remote_ID
= 0xffffffff;
7514 if (cmd
->ulpCommand
!= CMD_GEN_REQUEST64_CR
)
7515 remote_ID
= cmd
->un
.elsreq64
.remoteID
;
7517 struct lpfc_nodelist
*ndlp
;
7518 ndlp
= __lpfc_findnode_rpi(vport
, cmd
->ulpContext
);
7519 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
))
7520 remote_ID
= ndlp
->nlp_DID
;
7522 list_add_tail(&piocb
->dlist
, &abort_list
);
7524 if (phba
->sli_rev
== LPFC_SLI_REV4
)
7525 spin_unlock(&pring
->ring_lock
);
7526 spin_unlock_irq(&phba
->hbalock
);
7528 list_for_each_entry_safe(piocb
, tmp_iocb
, &abort_list
, dlist
) {
7530 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
7531 "0127 ELS timeout Data: x%x x%x x%x "
7532 "x%x\n", els_command
,
7533 remote_ID
, cmd
->ulpCommand
, cmd
->ulpIoTag
);
7534 spin_lock_irq(&phba
->hbalock
);
7535 list_del_init(&piocb
->dlist
);
7536 lpfc_sli_issue_abort_iotag(phba
, pring
, piocb
);
7537 spin_unlock_irq(&phba
->hbalock
);
7540 if (!list_empty(&pring
->txcmplq
))
7541 if (!(phba
->pport
->load_flag
& FC_UNLOADING
))
7542 mod_timer(&vport
->els_tmofunc
,
7543 jiffies
+ msecs_to_jiffies(1000 * timeout
));
7547 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
7548 * @vport: pointer to a host virtual N_Port data structure.
7550 * This routine is used to clean up all the outstanding ELS commands on a
7551 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
7552 * routine. After that, it walks the ELS transmit queue to remove all the
7553 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
7554 * the IOCBs with a non-NULL completion callback function, the callback
7555 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
7556 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
7557 * callback function, the IOCB will simply be released. Finally, it walks
7558 * the ELS transmit completion queue to issue an abort IOCB to any transmit
7559 * completion queue IOCB that is associated with the @vport and is not
7560 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
7561 * part of the discovery state machine) out to HBA by invoking the
7562 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
7563 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
7564 * the IOCBs are aborted when this function returns.
7567 lpfc_els_flush_cmd(struct lpfc_vport
*vport
)
7569 LIST_HEAD(abort_list
);
7570 struct lpfc_hba
*phba
= vport
->phba
;
7571 struct lpfc_sli_ring
*pring
;
7572 struct lpfc_iocbq
*tmp_iocb
, *piocb
;
7575 lpfc_fabric_abort_vport(vport
);
7577 * For SLI3, only the hbalock is required. But SLI4 needs to coordinate
7578 * with the ring insert operation. Because lpfc_sli_issue_abort_iotag
7579 * ultimately grabs the ring_lock, the driver must splice the list into
7580 * a working list and release the locks before calling the abort.
7582 spin_lock_irq(&phba
->hbalock
);
7583 pring
= lpfc_phba_elsring(phba
);
7585 /* Bail out if we've no ELS wq, like in PCI error recovery case. */
7586 if (unlikely(!pring
)) {
7587 spin_unlock_irq(&phba
->hbalock
);
7591 if (phba
->sli_rev
== LPFC_SLI_REV4
)
7592 spin_lock(&pring
->ring_lock
);
7594 list_for_each_entry_safe(piocb
, tmp_iocb
, &pring
->txcmplq
, list
) {
7595 if (piocb
->iocb_flag
& LPFC_IO_LIBDFC
)
7598 if (piocb
->vport
!= vport
)
7600 list_add_tail(&piocb
->dlist
, &abort_list
);
7602 if (phba
->sli_rev
== LPFC_SLI_REV4
)
7603 spin_unlock(&pring
->ring_lock
);
7604 spin_unlock_irq(&phba
->hbalock
);
7605 /* Abort each iocb on the aborted list and remove the dlist links. */
7606 list_for_each_entry_safe(piocb
, tmp_iocb
, &abort_list
, dlist
) {
7607 spin_lock_irq(&phba
->hbalock
);
7608 list_del_init(&piocb
->dlist
);
7609 lpfc_sli_issue_abort_iotag(phba
, pring
, piocb
);
7610 spin_unlock_irq(&phba
->hbalock
);
7612 if (!list_empty(&abort_list
))
7613 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
7614 "3387 abort list for txq not empty\n");
7615 INIT_LIST_HEAD(&abort_list
);
7617 spin_lock_irq(&phba
->hbalock
);
7618 if (phba
->sli_rev
== LPFC_SLI_REV4
)
7619 spin_lock(&pring
->ring_lock
);
7621 list_for_each_entry_safe(piocb
, tmp_iocb
, &pring
->txq
, list
) {
7624 if (piocb
->iocb_flag
& LPFC_IO_LIBDFC
) {
7628 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
7629 if (cmd
->ulpCommand
== CMD_QUE_RING_BUF_CN
||
7630 cmd
->ulpCommand
== CMD_QUE_RING_BUF64_CN
||
7631 cmd
->ulpCommand
== CMD_CLOSE_XRI_CN
||
7632 cmd
->ulpCommand
== CMD_ABORT_XRI_CN
)
7635 if (piocb
->vport
!= vport
)
7638 list_del_init(&piocb
->list
);
7639 list_add_tail(&piocb
->list
, &abort_list
);
7641 if (phba
->sli_rev
== LPFC_SLI_REV4
)
7642 spin_unlock(&pring
->ring_lock
);
7643 spin_unlock_irq(&phba
->hbalock
);
7645 /* Cancell all the IOCBs from the completions list */
7646 lpfc_sli_cancel_iocbs(phba
, &abort_list
,
7647 IOSTAT_LOCAL_REJECT
, IOERR_SLI_ABORTED
);
7653 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
7654 * @phba: pointer to lpfc hba data structure.
7656 * This routine is used to clean up all the outstanding ELS commands on a
7657 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
7658 * routine. After that, it walks the ELS transmit queue to remove all the
7659 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
7660 * the IOCBs with the completion callback function associated, the callback
7661 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
7662 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
7663 * callback function associated, the IOCB will simply be released. Finally,
7664 * it walks the ELS transmit completion queue to issue an abort IOCB to any
7665 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
7666 * management plane IOCBs that are not part of the discovery state machine)
7667 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
7670 lpfc_els_flush_all_cmd(struct lpfc_hba
*phba
)
7672 struct lpfc_vport
*vport
;
7673 list_for_each_entry(vport
, &phba
->port_list
, listentry
)
7674 lpfc_els_flush_cmd(vport
);
7680 * lpfc_send_els_failure_event - Posts an ELS command failure event
7681 * @phba: Pointer to hba context object.
7682 * @cmdiocbp: Pointer to command iocb which reported error.
7683 * @rspiocbp: Pointer to response iocb which reported error.
7685 * This function sends an event when there is an ELS command
7689 lpfc_send_els_failure_event(struct lpfc_hba
*phba
,
7690 struct lpfc_iocbq
*cmdiocbp
,
7691 struct lpfc_iocbq
*rspiocbp
)
7693 struct lpfc_vport
*vport
= cmdiocbp
->vport
;
7694 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
7695 struct lpfc_lsrjt_event lsrjt_event
;
7696 struct lpfc_fabric_event_header fabric_event
;
7698 struct lpfc_nodelist
*ndlp
;
7701 ndlp
= cmdiocbp
->context1
;
7702 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
))
7705 if (rspiocbp
->iocb
.ulpStatus
== IOSTAT_LS_RJT
) {
7706 lsrjt_event
.header
.event_type
= FC_REG_ELS_EVENT
;
7707 lsrjt_event
.header
.subcategory
= LPFC_EVENT_LSRJT_RCV
;
7708 memcpy(lsrjt_event
.header
.wwpn
, &ndlp
->nlp_portname
,
7709 sizeof(struct lpfc_name
));
7710 memcpy(lsrjt_event
.header
.wwnn
, &ndlp
->nlp_nodename
,
7711 sizeof(struct lpfc_name
));
7712 pcmd
= (uint32_t *) (((struct lpfc_dmabuf
*)
7713 cmdiocbp
->context2
)->virt
);
7714 lsrjt_event
.command
= (pcmd
!= NULL
) ? *pcmd
: 0;
7715 stat
.un
.lsRjtError
= be32_to_cpu(rspiocbp
->iocb
.un
.ulpWord
[4]);
7716 lsrjt_event
.reason_code
= stat
.un
.b
.lsRjtRsnCode
;
7717 lsrjt_event
.explanation
= stat
.un
.b
.lsRjtRsnCodeExp
;
7718 fc_host_post_vendor_event(shost
,
7719 fc_get_event_number(),
7720 sizeof(lsrjt_event
),
7721 (char *)&lsrjt_event
,
7725 if ((rspiocbp
->iocb
.ulpStatus
== IOSTAT_NPORT_BSY
) ||
7726 (rspiocbp
->iocb
.ulpStatus
== IOSTAT_FABRIC_BSY
)) {
7727 fabric_event
.event_type
= FC_REG_FABRIC_EVENT
;
7728 if (rspiocbp
->iocb
.ulpStatus
== IOSTAT_NPORT_BSY
)
7729 fabric_event
.subcategory
= LPFC_EVENT_PORT_BUSY
;
7731 fabric_event
.subcategory
= LPFC_EVENT_FABRIC_BUSY
;
7732 memcpy(fabric_event
.wwpn
, &ndlp
->nlp_portname
,
7733 sizeof(struct lpfc_name
));
7734 memcpy(fabric_event
.wwnn
, &ndlp
->nlp_nodename
,
7735 sizeof(struct lpfc_name
));
7736 fc_host_post_vendor_event(shost
,
7737 fc_get_event_number(),
7738 sizeof(fabric_event
),
7739 (char *)&fabric_event
,
7747 * lpfc_send_els_event - Posts unsolicited els event
7748 * @vport: Pointer to vport object.
7749 * @ndlp: Pointer FC node object.
7750 * @cmd: ELS command code.
7752 * This function posts an event when there is an incoming
7753 * unsolicited ELS command.
7756 lpfc_send_els_event(struct lpfc_vport
*vport
,
7757 struct lpfc_nodelist
*ndlp
,
7760 struct lpfc_els_event_header
*els_data
= NULL
;
7761 struct lpfc_logo_event
*logo_data
= NULL
;
7762 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
7764 if (*payload
== ELS_CMD_LOGO
) {
7765 logo_data
= kmalloc(sizeof(struct lpfc_logo_event
), GFP_KERNEL
);
7767 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
7768 "0148 Failed to allocate memory "
7769 "for LOGO event\n");
7772 els_data
= &logo_data
->header
;
7774 els_data
= kmalloc(sizeof(struct lpfc_els_event_header
),
7777 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
7778 "0149 Failed to allocate memory "
7783 els_data
->event_type
= FC_REG_ELS_EVENT
;
7786 els_data
->subcategory
= LPFC_EVENT_PLOGI_RCV
;
7789 els_data
->subcategory
= LPFC_EVENT_PRLO_RCV
;
7792 els_data
->subcategory
= LPFC_EVENT_ADISC_RCV
;
7795 els_data
->subcategory
= LPFC_EVENT_LOGO_RCV
;
7796 /* Copy the WWPN in the LOGO payload */
7797 memcpy(logo_data
->logo_wwpn
, &payload
[2],
7798 sizeof(struct lpfc_name
));
7804 memcpy(els_data
->wwpn
, &ndlp
->nlp_portname
, sizeof(struct lpfc_name
));
7805 memcpy(els_data
->wwnn
, &ndlp
->nlp_nodename
, sizeof(struct lpfc_name
));
7806 if (*payload
== ELS_CMD_LOGO
) {
7807 fc_host_post_vendor_event(shost
,
7808 fc_get_event_number(),
7809 sizeof(struct lpfc_logo_event
),
7814 fc_host_post_vendor_event(shost
,
7815 fc_get_event_number(),
7816 sizeof(struct lpfc_els_event_header
),
7827 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
7828 * @phba: pointer to lpfc hba data structure.
7829 * @pring: pointer to a SLI ring.
7830 * @vport: pointer to a host virtual N_Port data structure.
7831 * @elsiocb: pointer to lpfc els command iocb data structure.
7833 * This routine is used for processing the IOCB associated with a unsolicited
7834 * event. It first determines whether there is an existing ndlp that matches
7835 * the DID from the unsolicited IOCB. If not, it will create a new one with
7836 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
7837 * IOCB is then used to invoke the proper routine and to set up proper state
7838 * of the discovery state machine.
7841 lpfc_els_unsol_buffer(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
7842 struct lpfc_vport
*vport
, struct lpfc_iocbq
*elsiocb
)
7844 struct Scsi_Host
*shost
;
7845 struct lpfc_nodelist
*ndlp
;
7848 uint32_t cmd
, did
, newnode
;
7849 uint8_t rjt_exp
, rjt_err
= 0, init_link
= 0;
7850 IOCB_t
*icmd
= &elsiocb
->iocb
;
7853 if (!vport
|| !(elsiocb
->context2
))
7857 payload
= ((struct lpfc_dmabuf
*)elsiocb
->context2
)->virt
;
7859 if ((phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) == 0)
7860 lpfc_post_buffer(phba
, pring
, 1);
7862 did
= icmd
->un
.rcvels
.remoteID
;
7863 if (icmd
->ulpStatus
) {
7864 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
7865 "RCV Unsol ELS: status:x%x/x%x did:x%x",
7866 icmd
->ulpStatus
, icmd
->un
.ulpWord
[4], did
);
7870 /* Check to see if link went down during discovery */
7871 if (lpfc_els_chk_latt(vport
))
7874 /* Ignore traffic received during vport shutdown. */
7875 if (vport
->load_flag
& FC_UNLOADING
)
7878 /* If NPort discovery is delayed drop incoming ELS */
7879 if ((vport
->fc_flag
& FC_DISC_DELAYED
) &&
7880 (cmd
!= ELS_CMD_PLOGI
))
7883 ndlp
= lpfc_findnode_did(vport
, did
);
7885 /* Cannot find existing Fabric ndlp, so allocate a new one */
7886 ndlp
= lpfc_nlp_init(vport
, did
);
7889 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
7891 if ((did
& Fabric_DID_MASK
) == Fabric_DID_MASK
)
7892 ndlp
->nlp_type
|= NLP_FABRIC
;
7893 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
7894 ndlp
= lpfc_enable_node(vport
, ndlp
,
7895 NLP_STE_UNUSED_NODE
);
7898 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
7900 if ((did
& Fabric_DID_MASK
) == Fabric_DID_MASK
)
7901 ndlp
->nlp_type
|= NLP_FABRIC
;
7902 } else if (ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
) {
7903 /* This is similar to the new node path */
7904 ndlp
= lpfc_nlp_get(ndlp
);
7907 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
7911 phba
->fc_stat
.elsRcvFrame
++;
7914 * Do not process any unsolicited ELS commands
7915 * if the ndlp is in DEV_LOSS
7917 shost
= lpfc_shost_from_vport(vport
);
7918 spin_lock_irq(shost
->host_lock
);
7919 if (ndlp
->nlp_flag
& NLP_IN_DEV_LOSS
) {
7920 spin_unlock_irq(shost
->host_lock
);
7923 spin_unlock_irq(shost
->host_lock
);
7925 elsiocb
->context1
= lpfc_nlp_get(ndlp
);
7926 elsiocb
->vport
= vport
;
7928 if ((cmd
& ELS_CMD_MASK
) == ELS_CMD_RSCN
) {
7929 cmd
&= ELS_CMD_MASK
;
7931 /* ELS command <elsCmd> received from NPORT <did> */
7932 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
7933 "0112 ELS command x%x received from NPORT x%x "
7934 "Data: x%x x%x x%x x%x\n",
7935 cmd
, did
, vport
->port_state
, vport
->fc_flag
,
7936 vport
->fc_myDID
, vport
->fc_prevDID
);
7938 /* reject till our FLOGI completes */
7939 if ((vport
->port_state
< LPFC_FABRIC_CFG_LINK
) &&
7940 (cmd
!= ELS_CMD_FLOGI
)) {
7941 rjt_err
= LSRJT_LOGICAL_BSY
;
7942 rjt_exp
= LSEXP_NOTHING_MORE
;
7948 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
7949 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
7950 did
, vport
->port_state
, ndlp
->nlp_flag
);
7952 phba
->fc_stat
.elsRcvPLOGI
++;
7953 ndlp
= lpfc_plogi_confirm_nport(phba
, payload
, ndlp
);
7954 if (phba
->sli_rev
== LPFC_SLI_REV4
&&
7955 (phba
->pport
->fc_flag
& FC_PT2PT
)) {
7956 vport
->fc_prevDID
= vport
->fc_myDID
;
7957 /* Our DID needs to be updated before registering
7958 * the vfi. This is done in lpfc_rcv_plogi but
7959 * that is called after the reg_vfi.
7961 vport
->fc_myDID
= elsiocb
->iocb
.un
.rcvels
.parmRo
;
7962 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
7963 "3312 Remote port assigned DID x%x "
7964 "%x\n", vport
->fc_myDID
,
7968 lpfc_send_els_event(vport
, ndlp
, payload
);
7970 /* If Nport discovery is delayed, reject PLOGIs */
7971 if (vport
->fc_flag
& FC_DISC_DELAYED
) {
7972 rjt_err
= LSRJT_UNABLE_TPC
;
7973 rjt_exp
= LSEXP_NOTHING_MORE
;
7977 if (vport
->port_state
< LPFC_DISC_AUTH
) {
7978 if (!(phba
->pport
->fc_flag
& FC_PT2PT
) ||
7979 (phba
->pport
->fc_flag
& FC_PT2PT_PLOGI
)) {
7980 rjt_err
= LSRJT_UNABLE_TPC
;
7981 rjt_exp
= LSEXP_NOTHING_MORE
;
7986 spin_lock_irq(shost
->host_lock
);
7987 ndlp
->nlp_flag
&= ~NLP_TARGET_REMOVE
;
7988 spin_unlock_irq(shost
->host_lock
);
7990 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
,
7995 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
7996 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
7997 did
, vport
->port_state
, ndlp
->nlp_flag
);
7999 phba
->fc_stat
.elsRcvFLOGI
++;
8001 /* If the driver believes fabric discovery is done and is ready,
8002 * bounce the link. There is some descrepancy.
8004 if (vport
->port_state
>= LPFC_LOCAL_CFG_LINK
&&
8005 vport
->fc_flag
& FC_PT2PT
&&
8006 vport
->rcv_flogi_cnt
>= 1) {
8007 rjt_err
= LSRJT_LOGICAL_BSY
;
8008 rjt_exp
= LSEXP_NOTHING_MORE
;
8013 lpfc_els_rcv_flogi(vport
, elsiocb
, ndlp
);
8018 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
8019 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
8020 did
, vport
->port_state
, ndlp
->nlp_flag
);
8022 phba
->fc_stat
.elsRcvLOGO
++;
8023 lpfc_send_els_event(vport
, ndlp
, payload
);
8024 if (vport
->port_state
< LPFC_DISC_AUTH
) {
8025 rjt_err
= LSRJT_UNABLE_TPC
;
8026 rjt_exp
= LSEXP_NOTHING_MORE
;
8029 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
, NLP_EVT_RCV_LOGO
);
8032 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
8033 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
8034 did
, vport
->port_state
, ndlp
->nlp_flag
);
8036 phba
->fc_stat
.elsRcvPRLO
++;
8037 lpfc_send_els_event(vport
, ndlp
, payload
);
8038 if (vport
->port_state
< LPFC_DISC_AUTH
) {
8039 rjt_err
= LSRJT_UNABLE_TPC
;
8040 rjt_exp
= LSEXP_NOTHING_MORE
;
8043 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
, NLP_EVT_RCV_PRLO
);
8046 phba
->fc_stat
.elsRcvLCB
++;
8047 lpfc_els_rcv_lcb(vport
, elsiocb
, ndlp
);
8050 phba
->fc_stat
.elsRcvRDP
++;
8051 lpfc_els_rcv_rdp(vport
, elsiocb
, ndlp
);
8054 phba
->fc_stat
.elsRcvRSCN
++;
8055 lpfc_els_rcv_rscn(vport
, elsiocb
, ndlp
);
8060 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
8061 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
8062 did
, vport
->port_state
, ndlp
->nlp_flag
);
8064 lpfc_send_els_event(vport
, ndlp
, payload
);
8065 phba
->fc_stat
.elsRcvADISC
++;
8066 if (vport
->port_state
< LPFC_DISC_AUTH
) {
8067 rjt_err
= LSRJT_UNABLE_TPC
;
8068 rjt_exp
= LSEXP_NOTHING_MORE
;
8071 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
,
8075 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
8076 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
8077 did
, vport
->port_state
, ndlp
->nlp_flag
);
8079 phba
->fc_stat
.elsRcvPDISC
++;
8080 if (vport
->port_state
< LPFC_DISC_AUTH
) {
8081 rjt_err
= LSRJT_UNABLE_TPC
;
8082 rjt_exp
= LSEXP_NOTHING_MORE
;
8085 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
,
8089 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
8090 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
8091 did
, vport
->port_state
, ndlp
->nlp_flag
);
8093 phba
->fc_stat
.elsRcvFARPR
++;
8094 lpfc_els_rcv_farpr(vport
, elsiocb
, ndlp
);
8097 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
8098 "RCV FARP: did:x%x/ste:x%x flg:x%x",
8099 did
, vport
->port_state
, ndlp
->nlp_flag
);
8101 phba
->fc_stat
.elsRcvFARP
++;
8102 lpfc_els_rcv_farp(vport
, elsiocb
, ndlp
);
8105 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
8106 "RCV FAN: did:x%x/ste:x%x flg:x%x",
8107 did
, vport
->port_state
, ndlp
->nlp_flag
);
8109 phba
->fc_stat
.elsRcvFAN
++;
8110 lpfc_els_rcv_fan(vport
, elsiocb
, ndlp
);
8113 case ELS_CMD_NVMEPRLI
:
8114 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
8115 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
8116 did
, vport
->port_state
, ndlp
->nlp_flag
);
8118 phba
->fc_stat
.elsRcvPRLI
++;
8119 if ((vport
->port_state
< LPFC_DISC_AUTH
) &&
8120 (vport
->fc_flag
& FC_FABRIC
)) {
8121 rjt_err
= LSRJT_UNABLE_TPC
;
8122 rjt_exp
= LSEXP_NOTHING_MORE
;
8125 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
, NLP_EVT_RCV_PRLI
);
8128 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
8129 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
8130 did
, vport
->port_state
, ndlp
->nlp_flag
);
8132 phba
->fc_stat
.elsRcvLIRR
++;
8133 lpfc_els_rcv_lirr(vport
, elsiocb
, ndlp
);
8138 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
8139 "RCV RLS: did:x%x/ste:x%x flg:x%x",
8140 did
, vport
->port_state
, ndlp
->nlp_flag
);
8142 phba
->fc_stat
.elsRcvRLS
++;
8143 lpfc_els_rcv_rls(vport
, elsiocb
, ndlp
);
8148 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
8149 "RCV RPS: did:x%x/ste:x%x flg:x%x",
8150 did
, vport
->port_state
, ndlp
->nlp_flag
);
8152 phba
->fc_stat
.elsRcvRPS
++;
8153 lpfc_els_rcv_rps(vport
, elsiocb
, ndlp
);
8158 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
8159 "RCV RPL: did:x%x/ste:x%x flg:x%x",
8160 did
, vport
->port_state
, ndlp
->nlp_flag
);
8162 phba
->fc_stat
.elsRcvRPL
++;
8163 lpfc_els_rcv_rpl(vport
, elsiocb
, ndlp
);
8168 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
8169 "RCV RNID: did:x%x/ste:x%x flg:x%x",
8170 did
, vport
->port_state
, ndlp
->nlp_flag
);
8172 phba
->fc_stat
.elsRcvRNID
++;
8173 lpfc_els_rcv_rnid(vport
, elsiocb
, ndlp
);
8178 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
8179 "RCV RTV: did:x%x/ste:x%x flg:x%x",
8180 did
, vport
->port_state
, ndlp
->nlp_flag
);
8181 phba
->fc_stat
.elsRcvRTV
++;
8182 lpfc_els_rcv_rtv(vport
, elsiocb
, ndlp
);
8187 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
8188 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
8189 did
, vport
->port_state
, ndlp
->nlp_flag
);
8191 phba
->fc_stat
.elsRcvRRQ
++;
8192 lpfc_els_rcv_rrq(vport
, elsiocb
, ndlp
);
8197 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
8198 "RCV ECHO: did:x%x/ste:x%x flg:x%x",
8199 did
, vport
->port_state
, ndlp
->nlp_flag
);
8201 phba
->fc_stat
.elsRcvECHO
++;
8202 lpfc_els_rcv_echo(vport
, elsiocb
, ndlp
);
8207 /* receive this due to exchange closed */
8208 rjt_err
= LSRJT_UNABLE_TPC
;
8209 rjt_exp
= LSEXP_INVALID_OX_RX
;
8212 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
8213 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
8214 cmd
, did
, vport
->port_state
);
8216 /* Unsupported ELS command, reject */
8217 rjt_err
= LSRJT_CMD_UNSUPPORTED
;
8218 rjt_exp
= LSEXP_NOTHING_MORE
;
8220 /* Unknown ELS command <elsCmd> received from NPORT <did> */
8221 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
8222 "0115 Unknown ELS command x%x "
8223 "received from NPORT x%x\n", cmd
, did
);
8230 /* check if need to LS_RJT received ELS cmd */
8232 memset(&stat
, 0, sizeof(stat
));
8233 stat
.un
.b
.lsRjtRsnCode
= rjt_err
;
8234 stat
.un
.b
.lsRjtRsnCodeExp
= rjt_exp
;
8235 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, elsiocb
, ndlp
,
8239 lpfc_nlp_put(elsiocb
->context1
);
8240 elsiocb
->context1
= NULL
;
8242 /* Special case. Driver received an unsolicited command that
8243 * unsupportable given the driver's current state. Reset the
8244 * link and start over.
8247 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
8250 lpfc_linkdown(phba
);
8251 lpfc_init_link(phba
, mbox
,
8253 phba
->cfg_link_speed
);
8254 mbox
->u
.mb
.un
.varInitLnk
.lipsr_AL_PA
= 0;
8255 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
8256 mbox
->vport
= vport
;
8257 if (lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
) ==
8259 mempool_free(mbox
, phba
->mbox_mem_pool
);
8265 if (vport
&& !(vport
->load_flag
& FC_UNLOADING
))
8266 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
8267 "0111 Dropping received ELS cmd "
8268 "Data: x%x x%x x%x\n",
8269 icmd
->ulpStatus
, icmd
->un
.ulpWord
[4], icmd
->ulpTimeout
);
8270 phba
->fc_stat
.elsRcvDrop
++;
8274 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
8275 * @phba: pointer to lpfc hba data structure.
8276 * @pring: pointer to a SLI ring.
8277 * @elsiocb: pointer to lpfc els iocb data structure.
8279 * This routine is used to process an unsolicited event received from a SLI
8280 * (Service Level Interface) ring. The actual processing of the data buffer
8281 * associated with the unsolicited event is done by invoking the routine
8282 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
8283 * SLI ring on which the unsolicited event was received.
8286 lpfc_els_unsol_event(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
8287 struct lpfc_iocbq
*elsiocb
)
8289 struct lpfc_vport
*vport
= phba
->pport
;
8290 IOCB_t
*icmd
= &elsiocb
->iocb
;
8292 struct lpfc_dmabuf
*bdeBuf1
= elsiocb
->context2
;
8293 struct lpfc_dmabuf
*bdeBuf2
= elsiocb
->context3
;
8295 elsiocb
->context1
= NULL
;
8296 elsiocb
->context2
= NULL
;
8297 elsiocb
->context3
= NULL
;
8299 if (icmd
->ulpStatus
== IOSTAT_NEED_BUFFER
) {
8300 lpfc_sli_hbqbuf_add_hbqs(phba
, LPFC_ELS_HBQ
);
8301 } else if (icmd
->ulpStatus
== IOSTAT_LOCAL_REJECT
&&
8302 (icmd
->un
.ulpWord
[4] & IOERR_PARAM_MASK
) ==
8303 IOERR_RCV_BUFFER_WAITING
) {
8304 phba
->fc_stat
.NoRcvBuf
++;
8305 /* Not enough posted buffers; Try posting more buffers */
8306 if (!(phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
))
8307 lpfc_post_buffer(phba
, pring
, 0);
8311 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
8312 (icmd
->ulpCommand
== CMD_IOCB_RCV_ELS64_CX
||
8313 icmd
->ulpCommand
== CMD_IOCB_RCV_SEQ64_CX
)) {
8314 if (icmd
->unsli3
.rcvsli3
.vpi
== 0xffff)
8315 vport
= phba
->pport
;
8317 vport
= lpfc_find_vport_by_vpid(phba
,
8318 icmd
->unsli3
.rcvsli3
.vpi
);
8321 /* If there are no BDEs associated
8322 * with this IOCB, there is nothing to do.
8324 if (icmd
->ulpBdeCount
== 0)
8327 /* type of ELS cmd is first 32bit word
8330 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) {
8331 elsiocb
->context2
= bdeBuf1
;
8333 paddr
= getPaddr(icmd
->un
.cont64
[0].addrHigh
,
8334 icmd
->un
.cont64
[0].addrLow
);
8335 elsiocb
->context2
= lpfc_sli_ringpostbuf_get(phba
, pring
,
8339 lpfc_els_unsol_buffer(phba
, pring
, vport
, elsiocb
);
8341 * The different unsolicited event handlers would tell us
8342 * if they are done with "mp" by setting context2 to NULL.
8344 if (elsiocb
->context2
) {
8345 lpfc_in_buf_free(phba
, (struct lpfc_dmabuf
*)elsiocb
->context2
);
8346 elsiocb
->context2
= NULL
;
8349 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
8350 if ((phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) &&
8351 icmd
->ulpBdeCount
== 2) {
8352 elsiocb
->context2
= bdeBuf2
;
8353 lpfc_els_unsol_buffer(phba
, pring
, vport
, elsiocb
);
8354 /* free mp if we are done with it */
8355 if (elsiocb
->context2
) {
8356 lpfc_in_buf_free(phba
, elsiocb
->context2
);
8357 elsiocb
->context2
= NULL
;
8363 lpfc_start_fdmi(struct lpfc_vport
*vport
)
8365 struct lpfc_nodelist
*ndlp
;
8367 /* If this is the first time, allocate an ndlp and initialize
8368 * it. Otherwise, make sure the node is enabled and then do the
8371 ndlp
= lpfc_findnode_did(vport
, FDMI_DID
);
8373 ndlp
= lpfc_nlp_init(vport
, FDMI_DID
);
8375 ndlp
->nlp_type
|= NLP_FABRIC
;
8380 if (!NLP_CHK_NODE_ACT(ndlp
))
8381 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_NPR_NODE
);
8384 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
8385 lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0);
8390 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
8391 * @phba: pointer to lpfc hba data structure.
8392 * @vport: pointer to a virtual N_Port data structure.
8394 * This routine issues a Port Login (PLOGI) to the Name Server with
8395 * State Change Request (SCR) for a @vport. This routine will create an
8396 * ndlp for the Name Server associated to the @vport if such node does
8397 * not already exist. The PLOGI to Name Server is issued by invoking the
8398 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
8399 * (FDMI) is configured to the @vport, a FDMI node will be created and
8400 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
8403 lpfc_do_scr_ns_plogi(struct lpfc_hba
*phba
, struct lpfc_vport
*vport
)
8405 struct lpfc_nodelist
*ndlp
;
8406 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
8409 * If lpfc_delay_discovery parameter is set and the clean address
8410 * bit is cleared and fc fabric parameters chenged, delay FC NPort
8413 spin_lock_irq(shost
->host_lock
);
8414 if (vport
->fc_flag
& FC_DISC_DELAYED
) {
8415 spin_unlock_irq(shost
->host_lock
);
8416 lpfc_printf_log(phba
, KERN_ERR
, LOG_DISCOVERY
,
8417 "3334 Delay fc port discovery for %d seconds\n",
8419 mod_timer(&vport
->delayed_disc_tmo
,
8420 jiffies
+ msecs_to_jiffies(1000 * phba
->fc_ratov
));
8423 spin_unlock_irq(shost
->host_lock
);
8425 ndlp
= lpfc_findnode_did(vport
, NameServer_DID
);
8427 ndlp
= lpfc_nlp_init(vport
, NameServer_DID
);
8429 if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) {
8430 lpfc_disc_start(vport
);
8433 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
8434 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
8435 "0251 NameServer login: no memory\n");
8438 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
8439 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
8441 if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) {
8442 lpfc_disc_start(vport
);
8445 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
8446 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
8447 "0348 NameServer login: node freed\n");
8451 ndlp
->nlp_type
|= NLP_FABRIC
;
8453 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
8455 if (lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0)) {
8456 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
8457 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
8458 "0252 Cannot issue NameServer login\n");
8462 if ((phba
->cfg_enable_SmartSAN
||
8463 (phba
->cfg_fdmi_on
== LPFC_FDMI_SUPPORT
)) &&
8464 (vport
->load_flag
& FC_ALLOW_FDMI
))
8465 lpfc_start_fdmi(vport
);
8469 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
8470 * @phba: pointer to lpfc hba data structure.
8471 * @pmb: pointer to the driver internal queue element for mailbox command.
8473 * This routine is the completion callback function to register new vport
8474 * mailbox command. If the new vport mailbox command completes successfully,
8475 * the fabric registration login shall be performed on physical port (the
8476 * new vport created is actually a physical port, with VPI 0) or the port
8477 * login to Name Server for State Change Request (SCR) will be performed
8478 * on virtual port (real virtual port, with VPI greater than 0).
8481 lpfc_cmpl_reg_new_vport(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
8483 struct lpfc_vport
*vport
= pmb
->vport
;
8484 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
8485 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
8486 MAILBOX_t
*mb
= &pmb
->u
.mb
;
8489 spin_lock_irq(shost
->host_lock
);
8490 vport
->fc_flag
&= ~FC_VPORT_NEEDS_REG_VPI
;
8491 spin_unlock_irq(shost
->host_lock
);
8493 if (mb
->mbxStatus
) {
8494 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
8495 "0915 Register VPI failed : Status: x%x"
8496 " upd bit: x%x \n", mb
->mbxStatus
,
8497 mb
->un
.varRegVpi
.upd
);
8498 if (phba
->sli_rev
== LPFC_SLI_REV4
&&
8499 mb
->un
.varRegVpi
.upd
)
8500 goto mbox_err_exit
;
8502 switch (mb
->mbxStatus
) {
8503 case 0x11: /* unsupported feature */
8504 case 0x9603: /* max_vpi exceeded */
8505 case 0x9602: /* Link event since CLEAR_LA */
8506 /* giving up on vport registration */
8507 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
8508 spin_lock_irq(shost
->host_lock
);
8509 vport
->fc_flag
&= ~(FC_FABRIC
| FC_PUBLIC_LOOP
);
8510 spin_unlock_irq(shost
->host_lock
);
8511 lpfc_can_disctmo(vport
);
8513 /* If reg_vpi fail with invalid VPI status, re-init VPI */
8515 spin_lock_irq(shost
->host_lock
);
8516 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
8517 spin_unlock_irq(shost
->host_lock
);
8518 lpfc_init_vpi(phba
, pmb
, vport
->vpi
);
8520 pmb
->mbox_cmpl
= lpfc_init_vpi_cmpl
;
8521 rc
= lpfc_sli_issue_mbox(phba
, pmb
,
8523 if (rc
== MBX_NOT_FINISHED
) {
8524 lpfc_printf_vlog(vport
,
8526 "2732 Failed to issue INIT_VPI"
8527 " mailbox command\n");
8534 /* Try to recover from this error */
8535 if (phba
->sli_rev
== LPFC_SLI_REV4
)
8536 lpfc_sli4_unreg_all_rpis(vport
);
8537 lpfc_mbx_unreg_vpi(vport
);
8538 spin_lock_irq(shost
->host_lock
);
8539 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
8540 spin_unlock_irq(shost
->host_lock
);
8541 if (mb
->mbxStatus
== MBX_NOT_FINISHED
)
8543 if ((vport
->port_type
== LPFC_PHYSICAL_PORT
) &&
8544 !(vport
->fc_flag
& FC_LOGO_RCVD_DID_CHNG
)) {
8545 if (phba
->sli_rev
== LPFC_SLI_REV4
)
8546 lpfc_issue_init_vfi(vport
);
8548 lpfc_initial_flogi(vport
);
8550 lpfc_initial_fdisc(vport
);
8555 spin_lock_irq(shost
->host_lock
);
8556 vport
->vpi_state
|= LPFC_VPI_REGISTERED
;
8557 spin_unlock_irq(shost
->host_lock
);
8558 if (vport
== phba
->pport
) {
8559 if (phba
->sli_rev
< LPFC_SLI_REV4
)
8560 lpfc_issue_fabric_reglogin(vport
);
8563 * If the physical port is instantiated using
8564 * FDISC, do not start vport discovery.
8566 if (vport
->port_state
!= LPFC_FDISC
)
8567 lpfc_start_fdiscs(phba
);
8568 lpfc_do_scr_ns_plogi(phba
, vport
);
8571 lpfc_do_scr_ns_plogi(phba
, vport
);
8574 /* Now, we decrement the ndlp reference count held for this
8579 mempool_free(pmb
, phba
->mbox_mem_pool
);
8584 * lpfc_register_new_vport - Register a new vport with a HBA
8585 * @phba: pointer to lpfc hba data structure.
8586 * @vport: pointer to a host virtual N_Port data structure.
8587 * @ndlp: pointer to a node-list data structure.
8589 * This routine registers the @vport as a new virtual port with a HBA.
8590 * It is done through a registering vpi mailbox command.
8593 lpfc_register_new_vport(struct lpfc_hba
*phba
, struct lpfc_vport
*vport
,
8594 struct lpfc_nodelist
*ndlp
)
8596 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
8599 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
8601 lpfc_reg_vpi(vport
, mbox
);
8602 mbox
->vport
= vport
;
8603 mbox
->context2
= lpfc_nlp_get(ndlp
);
8604 mbox
->mbox_cmpl
= lpfc_cmpl_reg_new_vport
;
8605 if (lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
)
8606 == MBX_NOT_FINISHED
) {
8607 /* mailbox command not success, decrement ndlp
8608 * reference count for this command
8611 mempool_free(mbox
, phba
->mbox_mem_pool
);
8613 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
8614 "0253 Register VPI: Can't send mbox\n");
8618 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
8619 "0254 Register VPI: no memory\n");
8625 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
8626 spin_lock_irq(shost
->host_lock
);
8627 vport
->fc_flag
&= ~FC_VPORT_NEEDS_REG_VPI
;
8628 spin_unlock_irq(shost
->host_lock
);
8633 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
8634 * @phba: pointer to lpfc hba data structure.
8636 * This routine cancels the retry delay timers to all the vports.
8639 lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba
*phba
)
8641 struct lpfc_vport
**vports
;
8642 struct lpfc_nodelist
*ndlp
;
8643 uint32_t link_state
;
8646 /* Treat this failure as linkdown for all vports */
8647 link_state
= phba
->link_state
;
8648 lpfc_linkdown(phba
);
8649 phba
->link_state
= link_state
;
8651 vports
= lpfc_create_vport_work_array(phba
);
8654 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
8655 ndlp
= lpfc_findnode_did(vports
[i
], Fabric_DID
);
8657 lpfc_cancel_retry_delay_tmo(vports
[i
], ndlp
);
8658 lpfc_els_flush_cmd(vports
[i
]);
8660 lpfc_destroy_vport_work_array(phba
, vports
);
8665 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
8666 * @phba: pointer to lpfc hba data structure.
8668 * This routine abort all pending discovery commands and
8669 * start a timer to retry FLOGI for the physical port
8673 lpfc_retry_pport_discovery(struct lpfc_hba
*phba
)
8675 struct lpfc_nodelist
*ndlp
;
8676 struct Scsi_Host
*shost
;
8678 /* Cancel the all vports retry delay retry timers */
8679 lpfc_cancel_all_vport_retry_delay_timer(phba
);
8681 /* If fabric require FLOGI, then re-instantiate physical login */
8682 ndlp
= lpfc_findnode_did(phba
->pport
, Fabric_DID
);
8686 shost
= lpfc_shost_from_vport(phba
->pport
);
8687 mod_timer(&ndlp
->nlp_delayfunc
, jiffies
+ msecs_to_jiffies(1000));
8688 spin_lock_irq(shost
->host_lock
);
8689 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
8690 spin_unlock_irq(shost
->host_lock
);
8691 ndlp
->nlp_last_elscmd
= ELS_CMD_FLOGI
;
8692 phba
->pport
->port_state
= LPFC_FLOGI
;
8697 * lpfc_fabric_login_reqd - Check if FLOGI required.
8698 * @phba: pointer to lpfc hba data structure.
8699 * @cmdiocb: pointer to FDISC command iocb.
8700 * @rspiocb: pointer to FDISC response iocb.
8702 * This routine checks if a FLOGI is reguired for FDISC
8706 lpfc_fabric_login_reqd(struct lpfc_hba
*phba
,
8707 struct lpfc_iocbq
*cmdiocb
,
8708 struct lpfc_iocbq
*rspiocb
)
8711 if ((rspiocb
->iocb
.ulpStatus
!= IOSTAT_FABRIC_RJT
) ||
8712 (rspiocb
->iocb
.un
.ulpWord
[4] != RJT_LOGIN_REQUIRED
))
8719 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
8720 * @phba: pointer to lpfc hba data structure.
8721 * @cmdiocb: pointer to lpfc command iocb data structure.
8722 * @rspiocb: pointer to lpfc response iocb data structure.
8724 * This routine is the completion callback function to a Fabric Discover
8725 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
8726 * single threaded, each FDISC completion callback function will reset
8727 * the discovery timer for all vports such that the timers will not get
8728 * unnecessary timeout. The function checks the FDISC IOCB status. If error
8729 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
8730 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
8731 * assigned to the vport has been changed with the completion of the FDISC
8732 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
8733 * are unregistered from the HBA, and then the lpfc_register_new_vport()
8734 * routine is invoked to register new vport with the HBA. Otherwise, the
8735 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
8736 * Server for State Change Request (SCR).
8739 lpfc_cmpl_els_fdisc(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
8740 struct lpfc_iocbq
*rspiocb
)
8742 struct lpfc_vport
*vport
= cmdiocb
->vport
;
8743 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
8744 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
8745 struct lpfc_nodelist
*np
;
8746 struct lpfc_nodelist
*next_np
;
8747 IOCB_t
*irsp
= &rspiocb
->iocb
;
8748 struct lpfc_iocbq
*piocb
;
8749 struct lpfc_dmabuf
*pcmd
= cmdiocb
->context2
, *prsp
;
8750 struct serv_parm
*sp
;
8751 uint8_t fabric_param_changed
;
8753 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
8754 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
8755 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
8757 /* Since all FDISCs are being single threaded, we
8758 * must reset the discovery timer for ALL vports
8759 * waiting to send FDISC when one completes.
8761 list_for_each_entry(piocb
, &phba
->fabric_iocb_list
, list
) {
8762 lpfc_set_disctmo(piocb
->vport
);
8765 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
8766 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
8767 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4], vport
->fc_prevDID
);
8769 if (irsp
->ulpStatus
) {
8771 if (lpfc_fabric_login_reqd(phba
, cmdiocb
, rspiocb
)) {
8772 lpfc_retry_pport_discovery(phba
);
8776 /* Check for retry */
8777 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
))
8780 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
8781 "0126 FDISC failed. (x%x/x%x)\n",
8782 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4]);
8785 spin_lock_irq(shost
->host_lock
);
8786 vport
->fc_flag
&= ~FC_VPORT_CVL_RCVD
;
8787 vport
->fc_flag
&= ~FC_VPORT_LOGO_RCVD
;
8788 vport
->fc_flag
|= FC_FABRIC
;
8789 if (vport
->phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
)
8790 vport
->fc_flag
|= FC_PUBLIC_LOOP
;
8791 spin_unlock_irq(shost
->host_lock
);
8793 vport
->fc_myDID
= irsp
->un
.ulpWord
[4] & Mask_DID
;
8794 lpfc_vport_set_state(vport
, FC_VPORT_ACTIVE
);
8795 prsp
= list_get_first(&pcmd
->list
, struct lpfc_dmabuf
, list
);
8798 sp
= prsp
->virt
+ sizeof(uint32_t);
8799 fabric_param_changed
= lpfc_check_clean_addr_bit(vport
, sp
);
8800 memcpy(&vport
->fabric_portname
, &sp
->portName
,
8801 sizeof(struct lpfc_name
));
8802 memcpy(&vport
->fabric_nodename
, &sp
->nodeName
,
8803 sizeof(struct lpfc_name
));
8804 if (fabric_param_changed
&&
8805 !(vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
)) {
8806 /* If our NportID changed, we need to ensure all
8807 * remaining NPORTs get unreg_login'ed so we can
8810 list_for_each_entry_safe(np
, next_np
,
8811 &vport
->fc_nodes
, nlp_listp
) {
8812 if (!NLP_CHK_NODE_ACT(ndlp
) ||
8813 (np
->nlp_state
!= NLP_STE_NPR_NODE
) ||
8814 !(np
->nlp_flag
& NLP_NPR_ADISC
))
8816 spin_lock_irq(shost
->host_lock
);
8817 np
->nlp_flag
&= ~NLP_NPR_ADISC
;
8818 spin_unlock_irq(shost
->host_lock
);
8819 lpfc_unreg_rpi(vport
, np
);
8821 lpfc_cleanup_pending_mbox(vport
);
8823 if (phba
->sli_rev
== LPFC_SLI_REV4
)
8824 lpfc_sli4_unreg_all_rpis(vport
);
8826 lpfc_mbx_unreg_vpi(vport
);
8827 spin_lock_irq(shost
->host_lock
);
8828 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
8829 if (phba
->sli_rev
== LPFC_SLI_REV4
)
8830 vport
->fc_flag
|= FC_VPORT_NEEDS_INIT_VPI
;
8832 vport
->fc_flag
|= FC_LOGO_RCVD_DID_CHNG
;
8833 spin_unlock_irq(shost
->host_lock
);
8834 } else if ((phba
->sli_rev
== LPFC_SLI_REV4
) &&
8835 !(vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
)) {
8837 * Driver needs to re-reg VPI in order for f/w
8838 * to update the MAC address.
8840 lpfc_register_new_vport(phba
, vport
, ndlp
);
8844 if (vport
->fc_flag
& FC_VPORT_NEEDS_INIT_VPI
)
8845 lpfc_issue_init_vpi(vport
);
8846 else if (vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
)
8847 lpfc_register_new_vport(phba
, vport
, ndlp
);
8849 lpfc_do_scr_ns_plogi(phba
, vport
);
8852 if (vport
->fc_vport
&&
8853 (vport
->fc_vport
->vport_state
!= FC_VPORT_NO_FABRIC_RSCS
))
8854 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
8855 /* Cancel discovery timer */
8856 lpfc_can_disctmo(vport
);
8859 lpfc_els_free_iocb(phba
, cmdiocb
);
8863 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
8864 * @vport: pointer to a virtual N_Port data structure.
8865 * @ndlp: pointer to a node-list data structure.
8866 * @retry: number of retries to the command IOCB.
8868 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
8869 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
8870 * routine to issue the IOCB, which makes sure only one outstanding fabric
8871 * IOCB will be sent off HBA at any given time.
8873 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
8874 * will be incremented by 1 for holding the ndlp and the reference to ndlp
8875 * will be stored into the context1 field of the IOCB for the completion
8876 * callback function to the FDISC ELS command.
8879 * 0 - Successfully issued fdisc iocb command
8880 * 1 - Failed to issue fdisc iocb command
8883 lpfc_issue_els_fdisc(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
8886 struct lpfc_hba
*phba
= vport
->phba
;
8888 struct lpfc_iocbq
*elsiocb
;
8889 struct serv_parm
*sp
;
8892 int did
= ndlp
->nlp_DID
;
8895 vport
->port_state
= LPFC_FDISC
;
8896 vport
->fc_myDID
= 0;
8897 cmdsize
= (sizeof(uint32_t) + sizeof(struct serv_parm
));
8898 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
, did
,
8901 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
8902 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
8903 "0255 Issue FDISC: no IOCB\n");
8907 icmd
= &elsiocb
->iocb
;
8908 icmd
->un
.elsreq64
.myID
= 0;
8909 icmd
->un
.elsreq64
.fl
= 1;
8912 * SLI3 ports require a different context type value than SLI4.
8913 * Catch SLI3 ports here and override the prep.
8915 if (phba
->sli_rev
== LPFC_SLI_REV3
) {
8920 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
8921 *((uint32_t *) (pcmd
)) = ELS_CMD_FDISC
;
8922 pcmd
+= sizeof(uint32_t); /* CSP Word 1 */
8923 memcpy(pcmd
, &vport
->phba
->pport
->fc_sparam
, sizeof(struct serv_parm
));
8924 sp
= (struct serv_parm
*) pcmd
;
8925 /* Setup CSPs accordingly for Fabric */
8926 sp
->cmn
.e_d_tov
= 0;
8927 sp
->cmn
.w2
.r_a_tov
= 0;
8928 sp
->cmn
.virtual_fabric_support
= 0;
8929 sp
->cls1
.classValid
= 0;
8930 sp
->cls2
.seqDelivery
= 1;
8931 sp
->cls3
.seqDelivery
= 1;
8933 pcmd
+= sizeof(uint32_t); /* CSP Word 2 */
8934 pcmd
+= sizeof(uint32_t); /* CSP Word 3 */
8935 pcmd
+= sizeof(uint32_t); /* CSP Word 4 */
8936 pcmd
+= sizeof(uint32_t); /* Port Name */
8937 memcpy(pcmd
, &vport
->fc_portname
, 8);
8938 pcmd
+= sizeof(uint32_t); /* Node Name */
8939 pcmd
+= sizeof(uint32_t); /* Node Name */
8940 memcpy(pcmd
, &vport
->fc_nodename
, 8);
8941 sp
->cmn
.valid_vendor_ver_level
= 0;
8942 memset(sp
->un
.vendorVersion
, 0, sizeof(sp
->un
.vendorVersion
));
8943 lpfc_set_disctmo(vport
);
8945 phba
->fc_stat
.elsXmitFDISC
++;
8946 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_fdisc
;
8948 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
8949 "Issue FDISC: did:x%x",
8952 rc
= lpfc_issue_fabric_iocb(phba
, elsiocb
);
8953 if (rc
== IOCB_ERROR
) {
8954 lpfc_els_free_iocb(phba
, elsiocb
);
8955 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
8956 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
8957 "0256 Issue FDISC: Cannot send IOCB\n");
8960 lpfc_vport_set_state(vport
, FC_VPORT_INITIALIZING
);
8965 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
8966 * @phba: pointer to lpfc hba data structure.
8967 * @cmdiocb: pointer to lpfc command iocb data structure.
8968 * @rspiocb: pointer to lpfc response iocb data structure.
8970 * This routine is the completion callback function to the issuing of a LOGO
8971 * ELS command off a vport. It frees the command IOCB and then decrement the
8972 * reference count held on ndlp for this completion function, indicating that
8973 * the reference to the ndlp is no long needed. Note that the
8974 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
8975 * callback function and an additional explicit ndlp reference decrementation
8976 * will trigger the actual release of the ndlp.
8979 lpfc_cmpl_els_npiv_logo(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
8980 struct lpfc_iocbq
*rspiocb
)
8982 struct lpfc_vport
*vport
= cmdiocb
->vport
;
8984 struct lpfc_nodelist
*ndlp
;
8985 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
8987 ndlp
= (struct lpfc_nodelist
*)cmdiocb
->context1
;
8988 irsp
= &rspiocb
->iocb
;
8989 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
8990 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
8991 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4], irsp
->un
.rcvels
.remoteID
);
8993 lpfc_els_free_iocb(phba
, cmdiocb
);
8994 vport
->unreg_vpi_cmpl
= VPORT_ERROR
;
8996 /* Trigger the release of the ndlp after logo */
8999 /* NPIV LOGO completes to NPort <nlp_DID> */
9000 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
9001 "2928 NPIV LOGO completes to NPort x%x "
9002 "Data: x%x x%x x%x x%x\n",
9003 ndlp
->nlp_DID
, irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
9004 irsp
->ulpTimeout
, vport
->num_disc_nodes
);
9006 if (irsp
->ulpStatus
== IOSTAT_SUCCESS
) {
9007 spin_lock_irq(shost
->host_lock
);
9008 vport
->fc_flag
&= ~FC_NDISC_ACTIVE
;
9009 vport
->fc_flag
&= ~FC_FABRIC
;
9010 spin_unlock_irq(shost
->host_lock
);
9011 lpfc_can_disctmo(vport
);
9016 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
9017 * @vport: pointer to a virtual N_Port data structure.
9018 * @ndlp: pointer to a node-list data structure.
9020 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
9022 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
9023 * will be incremented by 1 for holding the ndlp and the reference to ndlp
9024 * will be stored into the context1 field of the IOCB for the completion
9025 * callback function to the LOGO ELS command.
9028 * 0 - Successfully issued logo off the @vport
9029 * 1 - Failed to issue logo off the @vport
9032 lpfc_issue_els_npiv_logo(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
9034 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
9035 struct lpfc_hba
*phba
= vport
->phba
;
9036 struct lpfc_iocbq
*elsiocb
;
9040 cmdsize
= 2 * sizeof(uint32_t) + sizeof(struct lpfc_name
);
9041 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, 0, ndlp
, ndlp
->nlp_DID
,
9046 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
9047 *((uint32_t *) (pcmd
)) = ELS_CMD_LOGO
;
9048 pcmd
+= sizeof(uint32_t);
9050 /* Fill in LOGO payload */
9051 *((uint32_t *) (pcmd
)) = be32_to_cpu(vport
->fc_myDID
);
9052 pcmd
+= sizeof(uint32_t);
9053 memcpy(pcmd
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
9055 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
9056 "Issue LOGO npiv did:x%x flg:x%x",
9057 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
9059 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_npiv_logo
;
9060 spin_lock_irq(shost
->host_lock
);
9061 ndlp
->nlp_flag
|= NLP_LOGO_SND
;
9062 spin_unlock_irq(shost
->host_lock
);
9063 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) ==
9065 spin_lock_irq(shost
->host_lock
);
9066 ndlp
->nlp_flag
&= ~NLP_LOGO_SND
;
9067 spin_unlock_irq(shost
->host_lock
);
9068 lpfc_els_free_iocb(phba
, elsiocb
);
9075 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
9076 * @ptr: holder for the timer function associated data.
9078 * This routine is invoked by the fabric iocb block timer after
9079 * timeout. It posts the fabric iocb block timeout event by setting the
9080 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
9081 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
9082 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
9083 * posted event WORKER_FABRIC_BLOCK_TMO.
9086 lpfc_fabric_block_timeout(struct timer_list
*t
)
9088 struct lpfc_hba
*phba
= from_timer(phba
, t
, fabric_block_timer
);
9089 unsigned long iflags
;
9090 uint32_t tmo_posted
;
9092 spin_lock_irqsave(&phba
->pport
->work_port_lock
, iflags
);
9093 tmo_posted
= phba
->pport
->work_port_events
& WORKER_FABRIC_BLOCK_TMO
;
9095 phba
->pport
->work_port_events
|= WORKER_FABRIC_BLOCK_TMO
;
9096 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, iflags
);
9099 lpfc_worker_wake_up(phba
);
9104 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
9105 * @phba: pointer to lpfc hba data structure.
9107 * This routine issues one fabric iocb from the driver internal list to
9108 * the HBA. It first checks whether it's ready to issue one fabric iocb to
9109 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
9110 * remove one pending fabric iocb from the driver internal list and invokes
9111 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
9114 lpfc_resume_fabric_iocbs(struct lpfc_hba
*phba
)
9116 struct lpfc_iocbq
*iocb
;
9117 unsigned long iflags
;
9123 spin_lock_irqsave(&phba
->hbalock
, iflags
);
9124 /* Post any pending iocb to the SLI layer */
9125 if (atomic_read(&phba
->fabric_iocb_count
) == 0) {
9126 list_remove_head(&phba
->fabric_iocb_list
, iocb
, typeof(*iocb
),
9129 /* Increment fabric iocb count to hold the position */
9130 atomic_inc(&phba
->fabric_iocb_count
);
9132 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
9134 iocb
->fabric_iocb_cmpl
= iocb
->iocb_cmpl
;
9135 iocb
->iocb_cmpl
= lpfc_cmpl_fabric_iocb
;
9136 iocb
->iocb_flag
|= LPFC_IO_FABRIC
;
9138 lpfc_debugfs_disc_trc(iocb
->vport
, LPFC_DISC_TRC_ELS_CMD
,
9139 "Fabric sched1: ste:x%x",
9140 iocb
->vport
->port_state
, 0, 0);
9142 ret
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, iocb
, 0);
9144 if (ret
== IOCB_ERROR
) {
9145 iocb
->iocb_cmpl
= iocb
->fabric_iocb_cmpl
;
9146 iocb
->fabric_iocb_cmpl
= NULL
;
9147 iocb
->iocb_flag
&= ~LPFC_IO_FABRIC
;
9149 cmd
->ulpStatus
= IOSTAT_LOCAL_REJECT
;
9150 cmd
->un
.ulpWord
[4] = IOERR_SLI_ABORTED
;
9151 iocb
->iocb_cmpl(phba
, iocb
, iocb
);
9153 atomic_dec(&phba
->fabric_iocb_count
);
9162 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
9163 * @phba: pointer to lpfc hba data structure.
9165 * This routine unblocks the issuing fabric iocb command. The function
9166 * will clear the fabric iocb block bit and then invoke the routine
9167 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
9168 * from the driver internal fabric iocb list.
9171 lpfc_unblock_fabric_iocbs(struct lpfc_hba
*phba
)
9173 clear_bit(FABRIC_COMANDS_BLOCKED
, &phba
->bit_flags
);
9175 lpfc_resume_fabric_iocbs(phba
);
9180 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
9181 * @phba: pointer to lpfc hba data structure.
9183 * This routine blocks the issuing fabric iocb for a specified amount of
9184 * time (currently 100 ms). This is done by set the fabric iocb block bit
9185 * and set up a timeout timer for 100ms. When the block bit is set, no more
9186 * fabric iocb will be issued out of the HBA.
9189 lpfc_block_fabric_iocbs(struct lpfc_hba
*phba
)
9193 blocked
= test_and_set_bit(FABRIC_COMANDS_BLOCKED
, &phba
->bit_flags
);
9194 /* Start a timer to unblock fabric iocbs after 100ms */
9196 mod_timer(&phba
->fabric_block_timer
,
9197 jiffies
+ msecs_to_jiffies(100));
9203 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
9204 * @phba: pointer to lpfc hba data structure.
9205 * @cmdiocb: pointer to lpfc command iocb data structure.
9206 * @rspiocb: pointer to lpfc response iocb data structure.
9208 * This routine is the callback function that is put to the fabric iocb's
9209 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
9210 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
9211 * function first restores and invokes the original iocb's callback function
9212 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
9213 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
9216 lpfc_cmpl_fabric_iocb(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
9217 struct lpfc_iocbq
*rspiocb
)
9221 BUG_ON((cmdiocb
->iocb_flag
& LPFC_IO_FABRIC
) != LPFC_IO_FABRIC
);
9223 switch (rspiocb
->iocb
.ulpStatus
) {
9224 case IOSTAT_NPORT_RJT
:
9225 case IOSTAT_FABRIC_RJT
:
9226 if (rspiocb
->iocb
.un
.ulpWord
[4] & RJT_UNAVAIL_TEMP
) {
9227 lpfc_block_fabric_iocbs(phba
);
9231 case IOSTAT_NPORT_BSY
:
9232 case IOSTAT_FABRIC_BSY
:
9233 lpfc_block_fabric_iocbs(phba
);
9237 stat
.un
.lsRjtError
=
9238 be32_to_cpu(rspiocb
->iocb
.un
.ulpWord
[4]);
9239 if ((stat
.un
.b
.lsRjtRsnCode
== LSRJT_UNABLE_TPC
) ||
9240 (stat
.un
.b
.lsRjtRsnCode
== LSRJT_LOGICAL_BSY
))
9241 lpfc_block_fabric_iocbs(phba
);
9245 BUG_ON(atomic_read(&phba
->fabric_iocb_count
) == 0);
9247 cmdiocb
->iocb_cmpl
= cmdiocb
->fabric_iocb_cmpl
;
9248 cmdiocb
->fabric_iocb_cmpl
= NULL
;
9249 cmdiocb
->iocb_flag
&= ~LPFC_IO_FABRIC
;
9250 cmdiocb
->iocb_cmpl(phba
, cmdiocb
, rspiocb
);
9252 atomic_dec(&phba
->fabric_iocb_count
);
9253 if (!test_bit(FABRIC_COMANDS_BLOCKED
, &phba
->bit_flags
)) {
9254 /* Post any pending iocbs to HBA */
9255 lpfc_resume_fabric_iocbs(phba
);
9260 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
9261 * @phba: pointer to lpfc hba data structure.
9262 * @iocb: pointer to lpfc command iocb data structure.
9264 * This routine is used as the top-level API for issuing a fabric iocb command
9265 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
9266 * function makes sure that only one fabric bound iocb will be outstanding at
9267 * any given time. As such, this function will first check to see whether there
9268 * is already an outstanding fabric iocb on the wire. If so, it will put the
9269 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
9270 * issued later. Otherwise, it will issue the iocb on the wire and update the
9271 * fabric iocb count it indicate that there is one fabric iocb on the wire.
9273 * Note, this implementation has a potential sending out fabric IOCBs out of
9274 * order. The problem is caused by the construction of the "ready" boolen does
9275 * not include the condition that the internal fabric IOCB list is empty. As
9276 * such, it is possible a fabric IOCB issued by this routine might be "jump"
9277 * ahead of the fabric IOCBs in the internal list.
9280 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
9281 * IOCB_ERROR - failed to issue fabric iocb
9284 lpfc_issue_fabric_iocb(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocb
)
9286 unsigned long iflags
;
9290 BUG_ON(atomic_read(&phba
->fabric_iocb_count
) > 1);
9292 spin_lock_irqsave(&phba
->hbalock
, iflags
);
9293 ready
= atomic_read(&phba
->fabric_iocb_count
) == 0 &&
9294 !test_bit(FABRIC_COMANDS_BLOCKED
, &phba
->bit_flags
);
9297 /* Increment fabric iocb count to hold the position */
9298 atomic_inc(&phba
->fabric_iocb_count
);
9299 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
9301 iocb
->fabric_iocb_cmpl
= iocb
->iocb_cmpl
;
9302 iocb
->iocb_cmpl
= lpfc_cmpl_fabric_iocb
;
9303 iocb
->iocb_flag
|= LPFC_IO_FABRIC
;
9305 lpfc_debugfs_disc_trc(iocb
->vport
, LPFC_DISC_TRC_ELS_CMD
,
9306 "Fabric sched2: ste:x%x",
9307 iocb
->vport
->port_state
, 0, 0);
9309 ret
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, iocb
, 0);
9311 if (ret
== IOCB_ERROR
) {
9312 iocb
->iocb_cmpl
= iocb
->fabric_iocb_cmpl
;
9313 iocb
->fabric_iocb_cmpl
= NULL
;
9314 iocb
->iocb_flag
&= ~LPFC_IO_FABRIC
;
9315 atomic_dec(&phba
->fabric_iocb_count
);
9318 spin_lock_irqsave(&phba
->hbalock
, iflags
);
9319 list_add_tail(&iocb
->list
, &phba
->fabric_iocb_list
);
9320 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
9327 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
9328 * @vport: pointer to a virtual N_Port data structure.
9330 * This routine aborts all the IOCBs associated with a @vport from the
9331 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
9332 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
9333 * list, removes each IOCB associated with the @vport off the list, set the
9334 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
9335 * associated with the IOCB.
9337 static void lpfc_fabric_abort_vport(struct lpfc_vport
*vport
)
9339 LIST_HEAD(completions
);
9340 struct lpfc_hba
*phba
= vport
->phba
;
9341 struct lpfc_iocbq
*tmp_iocb
, *piocb
;
9343 spin_lock_irq(&phba
->hbalock
);
9344 list_for_each_entry_safe(piocb
, tmp_iocb
, &phba
->fabric_iocb_list
,
9347 if (piocb
->vport
!= vport
)
9350 list_move_tail(&piocb
->list
, &completions
);
9352 spin_unlock_irq(&phba
->hbalock
);
9354 /* Cancel all the IOCBs from the completions list */
9355 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
9360 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
9361 * @ndlp: pointer to a node-list data structure.
9363 * This routine aborts all the IOCBs associated with an @ndlp from the
9364 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
9365 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
9366 * list, removes each IOCB associated with the @ndlp off the list, set the
9367 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
9368 * associated with the IOCB.
9370 void lpfc_fabric_abort_nport(struct lpfc_nodelist
*ndlp
)
9372 LIST_HEAD(completions
);
9373 struct lpfc_hba
*phba
= ndlp
->phba
;
9374 struct lpfc_iocbq
*tmp_iocb
, *piocb
;
9375 struct lpfc_sli_ring
*pring
;
9377 pring
= lpfc_phba_elsring(phba
);
9379 if (unlikely(!pring
))
9382 spin_lock_irq(&phba
->hbalock
);
9383 list_for_each_entry_safe(piocb
, tmp_iocb
, &phba
->fabric_iocb_list
,
9385 if ((lpfc_check_sli_ndlp(phba
, pring
, piocb
, ndlp
))) {
9387 list_move_tail(&piocb
->list
, &completions
);
9390 spin_unlock_irq(&phba
->hbalock
);
9392 /* Cancel all the IOCBs from the completions list */
9393 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
9398 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
9399 * @phba: pointer to lpfc hba data structure.
9401 * This routine aborts all the IOCBs currently on the driver internal
9402 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
9403 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
9404 * list, removes IOCBs off the list, set the status feild to
9405 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
9408 void lpfc_fabric_abort_hba(struct lpfc_hba
*phba
)
9410 LIST_HEAD(completions
);
9412 spin_lock_irq(&phba
->hbalock
);
9413 list_splice_init(&phba
->fabric_iocb_list
, &completions
);
9414 spin_unlock_irq(&phba
->hbalock
);
9416 /* Cancel all the IOCBs from the completions list */
9417 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
9422 * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport
9423 * @vport: pointer to lpfc vport data structure.
9425 * This routine is invoked by the vport cleanup for deletions and the cleanup
9426 * for an ndlp on removal.
9429 lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport
*vport
)
9431 struct lpfc_hba
*phba
= vport
->phba
;
9432 struct lpfc_sglq
*sglq_entry
= NULL
, *sglq_next
= NULL
;
9433 unsigned long iflag
= 0;
9435 spin_lock_irqsave(&phba
->hbalock
, iflag
);
9436 spin_lock(&phba
->sli4_hba
.sgl_list_lock
);
9437 list_for_each_entry_safe(sglq_entry
, sglq_next
,
9438 &phba
->sli4_hba
.lpfc_abts_els_sgl_list
, list
) {
9439 if (sglq_entry
->ndlp
&& sglq_entry
->ndlp
->vport
== vport
)
9440 sglq_entry
->ndlp
= NULL
;
9442 spin_unlock(&phba
->sli4_hba
.sgl_list_lock
);
9443 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
9448 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
9449 * @phba: pointer to lpfc hba data structure.
9450 * @axri: pointer to the els xri abort wcqe structure.
9452 * This routine is invoked by the worker thread to process a SLI4 slow-path
9456 lpfc_sli4_els_xri_aborted(struct lpfc_hba
*phba
,
9457 struct sli4_wcqe_xri_aborted
*axri
)
9459 uint16_t xri
= bf_get(lpfc_wcqe_xa_xri
, axri
);
9460 uint16_t rxid
= bf_get(lpfc_wcqe_xa_remote_xid
, axri
);
9463 struct lpfc_sglq
*sglq_entry
= NULL
, *sglq_next
= NULL
;
9464 unsigned long iflag
= 0;
9465 struct lpfc_nodelist
*ndlp
;
9466 struct lpfc_sli_ring
*pring
;
9468 pring
= lpfc_phba_elsring(phba
);
9470 spin_lock_irqsave(&phba
->hbalock
, iflag
);
9471 spin_lock(&phba
->sli4_hba
.sgl_list_lock
);
9472 list_for_each_entry_safe(sglq_entry
, sglq_next
,
9473 &phba
->sli4_hba
.lpfc_abts_els_sgl_list
, list
) {
9474 if (sglq_entry
->sli4_xritag
== xri
) {
9475 list_del(&sglq_entry
->list
);
9476 ndlp
= sglq_entry
->ndlp
;
9477 sglq_entry
->ndlp
= NULL
;
9478 list_add_tail(&sglq_entry
->list
,
9479 &phba
->sli4_hba
.lpfc_els_sgl_list
);
9480 sglq_entry
->state
= SGL_FREED
;
9481 spin_unlock(&phba
->sli4_hba
.sgl_list_lock
);
9482 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
9483 lpfc_set_rrq_active(phba
, ndlp
,
9484 sglq_entry
->sli4_lxritag
,
9487 /* Check if TXQ queue needs to be serviced */
9488 if (pring
&& !list_empty(&pring
->txq
))
9489 lpfc_worker_wake_up(phba
);
9493 spin_unlock(&phba
->sli4_hba
.sgl_list_lock
);
9494 lxri
= lpfc_sli4_xri_inrange(phba
, xri
);
9495 if (lxri
== NO_XRI
) {
9496 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
9499 spin_lock(&phba
->sli4_hba
.sgl_list_lock
);
9500 sglq_entry
= __lpfc_get_active_sglq(phba
, lxri
);
9501 if (!sglq_entry
|| (sglq_entry
->sli4_xritag
!= xri
)) {
9502 spin_unlock(&phba
->sli4_hba
.sgl_list_lock
);
9503 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
9506 sglq_entry
->state
= SGL_XRI_ABORTED
;
9507 spin_unlock(&phba
->sli4_hba
.sgl_list_lock
);
9508 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
9512 /* lpfc_sli_abts_recover_port - Recover a port that failed a BLS_ABORT req.
9513 * @vport: pointer to virtual port object.
9514 * @ndlp: nodelist pointer for the impacted node.
9516 * The driver calls this routine in response to an SLI4 XRI ABORT CQE
9517 * or an SLI3 ASYNC_STATUS_CN event from the port. For either event,
9518 * the driver is required to send a LOGO to the remote node before it
9519 * attempts to recover its login to the remote node.
9522 lpfc_sli_abts_recover_port(struct lpfc_vport
*vport
,
9523 struct lpfc_nodelist
*ndlp
)
9525 struct Scsi_Host
*shost
;
9526 struct lpfc_hba
*phba
;
9527 unsigned long flags
= 0;
9529 shost
= lpfc_shost_from_vport(vport
);
9531 if (ndlp
->nlp_state
!= NLP_STE_MAPPED_NODE
) {
9532 lpfc_printf_log(phba
, KERN_INFO
,
9533 LOG_SLI
, "3093 No rport recovery needed. "
9534 "rport in state 0x%x\n", ndlp
->nlp_state
);
9537 lpfc_printf_log(phba
, KERN_ERR
,
9538 LOG_ELS
| LOG_FCP_ERROR
| LOG_NVME_IOERR
,
9539 "3094 Start rport recovery on shost id 0x%x "
9540 "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x "
9542 shost
->host_no
, ndlp
->nlp_DID
,
9543 vport
->vpi
, ndlp
->nlp_rpi
, ndlp
->nlp_state
,
9546 * The rport is not responding. Remove the FCP-2 flag to prevent
9547 * an ADISC in the follow-up recovery code.
9549 spin_lock_irqsave(shost
->host_lock
, flags
);
9550 ndlp
->nlp_fcp_info
&= ~NLP_FCP_2_DEVICE
;
9551 ndlp
->nlp_flag
|= NLP_ISSUE_LOGO
;
9552 spin_unlock_irqrestore(shost
->host_lock
, flags
);
9553 lpfc_unreg_rpi(vport
, ndlp
);