1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2016 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. *
7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
9 * This program is free software; you can redistribute it and/or *
10 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
20 *******************************************************************/
21 /* See Fibre Channel protocol T11 FC-LS for details */
22 #include <linux/blkdev.h>
23 #include <linux/pci.h>
24 #include <linux/slab.h>
25 #include <linux/interrupt.h>
27 #include <scsi/scsi.h>
28 #include <scsi/scsi_device.h>
29 #include <scsi/scsi_host.h>
30 #include <scsi/scsi_transport_fc.h>
36 #include "lpfc_sli4.h"
38 #include "lpfc_disc.h"
39 #include "lpfc_scsi.h"
41 #include "lpfc_logmsg.h"
42 #include "lpfc_crtn.h"
43 #include "lpfc_vport.h"
44 #include "lpfc_debugfs.h"
46 static int lpfc_els_retry(struct lpfc_hba
*, struct lpfc_iocbq
*,
48 static void lpfc_cmpl_fabric_iocb(struct lpfc_hba
*, struct lpfc_iocbq
*,
50 static void lpfc_fabric_abort_vport(struct lpfc_vport
*vport
);
51 static int lpfc_issue_els_fdisc(struct lpfc_vport
*vport
,
52 struct lpfc_nodelist
*ndlp
, uint8_t retry
);
53 static int lpfc_issue_fabric_iocb(struct lpfc_hba
*phba
,
54 struct lpfc_iocbq
*iocb
);
56 static int lpfc_max_els_tries
= 3;
59 * lpfc_els_chk_latt - Check host link attention event for a vport
60 * @vport: pointer to a host virtual N_Port data structure.
62 * This routine checks whether there is an outstanding host link
63 * attention event during the discovery process with the @vport. It is done
64 * by reading the HBA's Host Attention (HA) register. If there is any host
65 * link attention events during this @vport's discovery process, the @vport
66 * shall be marked as FC_ABORT_DISCOVERY, a host link attention clear shall
67 * be issued if the link state is not already in host link cleared state,
68 * and a return code shall indicate whether the host link attention event
71 * Note that, if either the host link is in state LPFC_LINK_DOWN or @vport
72 * state in LPFC_VPORT_READY, the request for checking host link attention
73 * event will be ignored and a return code shall indicate no host link
74 * attention event had happened.
77 * 0 - no host link attention event happened
78 * 1 - host link attention event happened
81 lpfc_els_chk_latt(struct lpfc_vport
*vport
)
83 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
84 struct lpfc_hba
*phba
= vport
->phba
;
87 if (vport
->port_state
>= LPFC_VPORT_READY
||
88 phba
->link_state
== LPFC_LINK_DOWN
||
89 phba
->sli_rev
> LPFC_SLI_REV3
)
92 /* Read the HBA Host Attention Register */
93 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
96 if (!(ha_copy
& HA_LATT
))
99 /* Pending Link Event during Discovery */
100 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
101 "0237 Pending Link Event during "
102 "Discovery: State x%x\n",
103 phba
->pport
->port_state
);
105 /* CLEAR_LA should re-enable link attention events and
106 * we should then immediately take a LATT event. The
107 * LATT processing should call lpfc_linkdown() which
108 * will cleanup any left over in-progress discovery
111 spin_lock_irq(shost
->host_lock
);
112 vport
->fc_flag
|= FC_ABORT_DISCOVERY
;
113 spin_unlock_irq(shost
->host_lock
);
115 if (phba
->link_state
!= LPFC_CLEAR_LA
)
116 lpfc_issue_clear_la(phba
, vport
);
122 * lpfc_prep_els_iocb - Allocate and prepare a lpfc iocb data structure
123 * @vport: pointer to a host virtual N_Port data structure.
124 * @expectRsp: flag indicating whether response is expected.
125 * @cmdSize: size of the ELS command.
126 * @retry: number of retries to the command IOCB when it fails.
127 * @ndlp: pointer to a node-list data structure.
128 * @did: destination identifier.
129 * @elscmd: the ELS command code.
131 * This routine is used for allocating a lpfc-IOCB data structure from
132 * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters
133 * passed into the routine for discovery state machine to issue an Extended
134 * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation
135 * and preparation routine that is used by all the discovery state machine
136 * routines and the ELS command-specific fields will be later set up by
137 * the individual discovery machine routines after calling this routine
138 * allocating and preparing a generic IOCB data structure. It fills in the
139 * Buffer Descriptor Entries (BDEs), allocates buffers for both command
140 * payload and response payload (if expected). The reference count on the
141 * ndlp is incremented by 1 and the reference to the ndlp is put into
142 * context1 of the IOCB data structure for this IOCB to hold the ndlp
143 * reference for the command's callback function to access later.
146 * Pointer to the newly allocated/prepared els iocb data structure
147 * NULL - when els iocb data structure allocation/preparation failed
150 lpfc_prep_els_iocb(struct lpfc_vport
*vport
, uint8_t expectRsp
,
151 uint16_t cmdSize
, uint8_t retry
,
152 struct lpfc_nodelist
*ndlp
, uint32_t did
,
155 struct lpfc_hba
*phba
= vport
->phba
;
156 struct lpfc_iocbq
*elsiocb
;
157 struct lpfc_dmabuf
*pcmd
, *prsp
, *pbuflist
;
158 struct ulp_bde64
*bpl
;
162 if (!lpfc_is_link_up(phba
))
165 /* Allocate buffer for command iocb */
166 elsiocb
= lpfc_sli_get_iocbq(phba
);
172 * If this command is for fabric controller and HBA running
173 * in FIP mode send FLOGI, FDISC and LOGO as FIP frames.
175 if ((did
== Fabric_DID
) &&
176 (phba
->hba_flag
& HBA_FIP_SUPPORT
) &&
177 ((elscmd
== ELS_CMD_FLOGI
) ||
178 (elscmd
== ELS_CMD_FDISC
) ||
179 (elscmd
== ELS_CMD_LOGO
)))
182 elsiocb
->iocb_flag
|=
183 ((LPFC_ELS_ID_FLOGI
<< LPFC_FIP_ELS_ID_SHIFT
)
184 & LPFC_FIP_ELS_ID_MASK
);
187 elsiocb
->iocb_flag
|=
188 ((LPFC_ELS_ID_FDISC
<< LPFC_FIP_ELS_ID_SHIFT
)
189 & LPFC_FIP_ELS_ID_MASK
);
192 elsiocb
->iocb_flag
|=
193 ((LPFC_ELS_ID_LOGO
<< LPFC_FIP_ELS_ID_SHIFT
)
194 & LPFC_FIP_ELS_ID_MASK
);
198 elsiocb
->iocb_flag
&= ~LPFC_FIP_ELS_ID_MASK
;
200 icmd
= &elsiocb
->iocb
;
202 /* fill in BDEs for command */
203 /* Allocate buffer for command payload */
204 pcmd
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
206 pcmd
->virt
= lpfc_mbuf_alloc(phba
, MEM_PRI
, &pcmd
->phys
);
207 if (!pcmd
|| !pcmd
->virt
)
208 goto els_iocb_free_pcmb_exit
;
210 INIT_LIST_HEAD(&pcmd
->list
);
212 /* Allocate buffer for response payload */
214 prsp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
216 prsp
->virt
= lpfc_mbuf_alloc(phba
, MEM_PRI
,
218 if (!prsp
|| !prsp
->virt
)
219 goto els_iocb_free_prsp_exit
;
220 INIT_LIST_HEAD(&prsp
->list
);
224 /* Allocate buffer for Buffer ptr list */
225 pbuflist
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
227 pbuflist
->virt
= lpfc_mbuf_alloc(phba
, MEM_PRI
,
229 if (!pbuflist
|| !pbuflist
->virt
)
230 goto els_iocb_free_pbuf_exit
;
232 INIT_LIST_HEAD(&pbuflist
->list
);
235 icmd
->un
.elsreq64
.bdl
.addrHigh
= putPaddrHigh(pbuflist
->phys
);
236 icmd
->un
.elsreq64
.bdl
.addrLow
= putPaddrLow(pbuflist
->phys
);
237 icmd
->un
.elsreq64
.bdl
.bdeFlags
= BUFF_TYPE_BLP_64
;
238 icmd
->un
.elsreq64
.bdl
.bdeSize
= (2 * sizeof(struct ulp_bde64
));
240 icmd
->un
.elsreq64
.remoteID
= did
; /* DID */
241 icmd
->ulpCommand
= CMD_ELS_REQUEST64_CR
;
242 if (elscmd
== ELS_CMD_FLOGI
)
243 icmd
->ulpTimeout
= FF_DEF_RATOV
* 2;
245 icmd
->ulpTimeout
= phba
->fc_ratov
* 2;
247 icmd
->un
.xseq64
.bdl
.addrHigh
= putPaddrHigh(pbuflist
->phys
);
248 icmd
->un
.xseq64
.bdl
.addrLow
= putPaddrLow(pbuflist
->phys
);
249 icmd
->un
.xseq64
.bdl
.bdeFlags
= BUFF_TYPE_BLP_64
;
250 icmd
->un
.xseq64
.bdl
.bdeSize
= sizeof(struct ulp_bde64
);
251 icmd
->un
.xseq64
.xmit_els_remoteID
= did
; /* DID */
252 icmd
->ulpCommand
= CMD_XMIT_ELS_RSP64_CX
;
254 icmd
->ulpBdeCount
= 1;
256 icmd
->ulpClass
= CLASS3
;
259 * If we have NPIV enabled, we want to send ELS traffic by VPI.
260 * For SLI4, since the driver controls VPIs we also want to include
261 * all ELS pt2pt protocol traffic as well.
263 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) ||
264 ((phba
->sli_rev
== LPFC_SLI_REV4
) &&
265 (vport
->fc_flag
& FC_PT2PT
))) {
268 icmd
->un
.elsreq64
.myID
= vport
->fc_myDID
;
270 /* For ELS_REQUEST64_CR, use the VPI by default */
271 icmd
->ulpContext
= phba
->vpi_ids
[vport
->vpi
];
275 /* The CT field must be 0=INVALID_RPI for the ECHO cmd */
276 if (elscmd
== ELS_CMD_ECHO
)
277 icmd
->ulpCt_l
= 0; /* context = invalid RPI */
279 icmd
->ulpCt_l
= 1; /* context = VPI */
282 bpl
= (struct ulp_bde64
*) pbuflist
->virt
;
283 bpl
->addrLow
= le32_to_cpu(putPaddrLow(pcmd
->phys
));
284 bpl
->addrHigh
= le32_to_cpu(putPaddrHigh(pcmd
->phys
));
285 bpl
->tus
.f
.bdeSize
= cmdSize
;
286 bpl
->tus
.f
.bdeFlags
= 0;
287 bpl
->tus
.w
= le32_to_cpu(bpl
->tus
.w
);
291 bpl
->addrLow
= le32_to_cpu(putPaddrLow(prsp
->phys
));
292 bpl
->addrHigh
= le32_to_cpu(putPaddrHigh(prsp
->phys
));
293 bpl
->tus
.f
.bdeSize
= FCELSSIZE
;
294 bpl
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64
;
295 bpl
->tus
.w
= le32_to_cpu(bpl
->tus
.w
);
298 /* prevent preparing iocb with NULL ndlp reference */
299 elsiocb
->context1
= lpfc_nlp_get(ndlp
);
300 if (!elsiocb
->context1
)
301 goto els_iocb_free_pbuf_exit
;
302 elsiocb
->context2
= pcmd
;
303 elsiocb
->context3
= pbuflist
;
304 elsiocb
->retry
= retry
;
305 elsiocb
->vport
= vport
;
306 elsiocb
->drvrTimeout
= (phba
->fc_ratov
<< 1) + LPFC_DRVR_TIMEOUT
;
309 list_add(&prsp
->list
, &pcmd
->list
);
312 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
313 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
314 "0116 Xmit ELS command x%x to remote "
315 "NPORT x%x I/O tag: x%x, port state:x%x"
317 elscmd
, did
, elsiocb
->iotag
,
321 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
322 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
323 "0117 Xmit ELS response x%x to remote "
324 "NPORT x%x I/O tag: x%x, size: x%x "
325 "port_state x%x fc_flag x%x\n",
326 elscmd
, ndlp
->nlp_DID
, elsiocb
->iotag
,
327 cmdSize
, vport
->port_state
,
332 els_iocb_free_pbuf_exit
:
334 lpfc_mbuf_free(phba
, prsp
->virt
, prsp
->phys
);
337 els_iocb_free_prsp_exit
:
338 lpfc_mbuf_free(phba
, pcmd
->virt
, pcmd
->phys
);
341 els_iocb_free_pcmb_exit
:
343 lpfc_sli_release_iocbq(phba
, elsiocb
);
348 * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport
349 * @vport: pointer to a host virtual N_Port data structure.
351 * This routine issues a fabric registration login for a @vport. An
352 * active ndlp node with Fabric_DID must already exist for this @vport.
353 * The routine invokes two mailbox commands to carry out fabric registration
354 * login through the HBA firmware: the first mailbox command requests the
355 * HBA to perform link configuration for the @vport; and the second mailbox
356 * command requests the HBA to perform the actual fabric registration login
360 * 0 - successfully issued fabric registration login for @vport
361 * -ENXIO -- failed to issue fabric registration login for @vport
364 lpfc_issue_fabric_reglogin(struct lpfc_vport
*vport
)
366 struct lpfc_hba
*phba
= vport
->phba
;
368 struct lpfc_dmabuf
*mp
;
369 struct lpfc_nodelist
*ndlp
;
370 struct serv_parm
*sp
;
374 sp
= &phba
->fc_fabparam
;
375 ndlp
= lpfc_findnode_did(vport
, Fabric_DID
);
376 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
)) {
381 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
387 vport
->port_state
= LPFC_FABRIC_CFG_LINK
;
388 lpfc_config_link(phba
, mbox
);
389 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
392 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
393 if (rc
== MBX_NOT_FINISHED
) {
398 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
403 rc
= lpfc_reg_rpi(phba
, vport
->vpi
, Fabric_DID
, (uint8_t *)sp
, mbox
,
410 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_fabric_reg_login
;
412 /* increment the reference count on ndlp to hold reference
413 * for the callback routine.
415 mbox
->context2
= lpfc_nlp_get(ndlp
);
417 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
418 if (rc
== MBX_NOT_FINISHED
) {
420 goto fail_issue_reg_login
;
425 fail_issue_reg_login
:
426 /* decrement the reference count on ndlp just incremented
427 * for the failed mbox command.
430 mp
= (struct lpfc_dmabuf
*) mbox
->context1
;
431 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
434 mempool_free(mbox
, phba
->mbox_mem_pool
);
437 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
438 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
439 "0249 Cannot issue Register Fabric login: Err %d\n", err
);
444 * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login
445 * @vport: pointer to a host virtual N_Port data structure.
447 * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for
448 * the @vport. This mailbox command is necessary for SLI4 port only.
451 * 0 - successfully issued REG_VFI for @vport
452 * A failure code otherwise.
455 lpfc_issue_reg_vfi(struct lpfc_vport
*vport
)
457 struct lpfc_hba
*phba
= vport
->phba
;
458 LPFC_MBOXQ_t
*mboxq
= NULL
;
459 struct lpfc_nodelist
*ndlp
;
460 struct lpfc_dmabuf
*dmabuf
= NULL
;
463 /* move forward in case of SLI4 FC port loopback test and pt2pt mode */
464 if ((phba
->sli_rev
== LPFC_SLI_REV4
) &&
465 !(phba
->link_flag
& LS_LOOPBACK_MODE
) &&
466 !(vport
->fc_flag
& FC_PT2PT
)) {
467 ndlp
= lpfc_findnode_did(vport
, Fabric_DID
);
468 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
)) {
474 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
480 /* Supply CSP's only if we are fabric connect or pt-to-pt connect */
481 if ((vport
->fc_flag
& FC_FABRIC
) || (vport
->fc_flag
& FC_PT2PT
)) {
482 dmabuf
= kzalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
487 dmabuf
->virt
= lpfc_mbuf_alloc(phba
, MEM_PRI
, &dmabuf
->phys
);
492 memcpy(dmabuf
->virt
, &phba
->fc_fabparam
,
493 sizeof(struct serv_parm
));
496 vport
->port_state
= LPFC_FABRIC_CFG_LINK
;
498 lpfc_reg_vfi(mboxq
, vport
, dmabuf
->phys
);
500 lpfc_reg_vfi(mboxq
, vport
, 0);
502 mboxq
->mbox_cmpl
= lpfc_mbx_cmpl_reg_vfi
;
503 mboxq
->vport
= vport
;
504 mboxq
->context1
= dmabuf
;
505 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
506 if (rc
== MBX_NOT_FINISHED
) {
514 mempool_free(mboxq
, phba
->mbox_mem_pool
);
517 lpfc_mbuf_free(phba
, dmabuf
->virt
, dmabuf
->phys
);
521 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
522 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
523 "0289 Issue Register VFI failed: Err %d\n", rc
);
528 * lpfc_issue_unreg_vfi - Unregister VFI for this vport's fabric login
529 * @vport: pointer to a host virtual N_Port data structure.
531 * This routine issues a UNREG_VFI mailbox with the vfi, vpi, fcfi triplet for
532 * the @vport. This mailbox command is necessary for SLI4 port only.
535 * 0 - successfully issued REG_VFI for @vport
536 * A failure code otherwise.
539 lpfc_issue_unreg_vfi(struct lpfc_vport
*vport
)
541 struct lpfc_hba
*phba
= vport
->phba
;
542 struct Scsi_Host
*shost
;
546 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
548 lpfc_printf_log(phba
, KERN_ERR
, LOG_DISCOVERY
|LOG_MBOX
,
549 "2556 UNREG_VFI mbox allocation failed"
550 "HBA state x%x\n", phba
->pport
->port_state
);
554 lpfc_unreg_vfi(mboxq
, vport
);
555 mboxq
->vport
= vport
;
556 mboxq
->mbox_cmpl
= lpfc_unregister_vfi_cmpl
;
558 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
559 if (rc
== MBX_NOT_FINISHED
) {
560 lpfc_printf_log(phba
, KERN_ERR
, LOG_DISCOVERY
|LOG_MBOX
,
561 "2557 UNREG_VFI issue mbox failed rc x%x "
563 rc
, phba
->pport
->port_state
);
564 mempool_free(mboxq
, phba
->mbox_mem_pool
);
568 shost
= lpfc_shost_from_vport(vport
);
569 spin_lock_irq(shost
->host_lock
);
570 vport
->fc_flag
&= ~FC_VFI_REGISTERED
;
571 spin_unlock_irq(shost
->host_lock
);
576 * lpfc_check_clean_addr_bit - Check whether assigned FCID is clean.
577 * @vport: pointer to a host virtual N_Port data structure.
578 * @sp: pointer to service parameter data structure.
580 * This routine is called from FLOGI/FDISC completion handler functions.
581 * lpfc_check_clean_addr_bit return 1 when FCID/Fabric portname/ Fabric
582 * node nodename is changed in the completion service parameter else return
583 * 0. This function also set flag in the vport data structure to delay
584 * NP_Port discovery after the FLOGI/FDISC completion if Clean address bit
585 * in FLOGI/FDISC response is cleared and FCID/Fabric portname/ Fabric
586 * node nodename is changed in the completion service parameter.
589 * 0 - FCID and Fabric Nodename and Fabric portname is not changed.
590 * 1 - FCID or Fabric Nodename or Fabric portname is changed.
594 lpfc_check_clean_addr_bit(struct lpfc_vport
*vport
,
595 struct serv_parm
*sp
)
597 uint8_t fabric_param_changed
= 0;
598 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
600 if ((vport
->fc_prevDID
!= vport
->fc_myDID
) ||
601 memcmp(&vport
->fabric_portname
, &sp
->portName
,
602 sizeof(struct lpfc_name
)) ||
603 memcmp(&vport
->fabric_nodename
, &sp
->nodeName
,
604 sizeof(struct lpfc_name
)))
605 fabric_param_changed
= 1;
608 * Word 1 Bit 31 in common service parameter is overloaded.
609 * Word 1 Bit 31 in FLOGI request is multiple NPort request
610 * Word 1 Bit 31 in FLOGI response is clean address bit
612 * If fabric parameter is changed and clean address bit is
613 * cleared delay nport discovery if
614 * - vport->fc_prevDID != 0 (not initial discovery) OR
615 * - lpfc_delay_discovery module parameter is set.
617 if (fabric_param_changed
&& !sp
->cmn
.clean_address_bit
&&
618 (vport
->fc_prevDID
|| lpfc_delay_discovery
)) {
619 spin_lock_irq(shost
->host_lock
);
620 vport
->fc_flag
|= FC_DISC_DELAYED
;
621 spin_unlock_irq(shost
->host_lock
);
624 return fabric_param_changed
;
629 * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port
630 * @vport: pointer to a host virtual N_Port data structure.
631 * @ndlp: pointer to a node-list data structure.
632 * @sp: pointer to service parameter data structure.
633 * @irsp: pointer to the IOCB within the lpfc response IOCB.
635 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
636 * function to handle the completion of a Fabric Login (FLOGI) into a fabric
637 * port in a fabric topology. It properly sets up the parameters to the @ndlp
638 * from the IOCB response. It also check the newly assigned N_Port ID to the
639 * @vport against the previously assigned N_Port ID. If it is different from
640 * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
641 * is invoked on all the remaining nodes with the @vport to unregister the
642 * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
643 * is invoked to register login to the fabric.
646 * 0 - Success (currently, always return 0)
649 lpfc_cmpl_els_flogi_fabric(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
650 struct serv_parm
*sp
, IOCB_t
*irsp
)
652 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
653 struct lpfc_hba
*phba
= vport
->phba
;
654 struct lpfc_nodelist
*np
;
655 struct lpfc_nodelist
*next_np
;
656 uint8_t fabric_param_changed
;
658 spin_lock_irq(shost
->host_lock
);
659 vport
->fc_flag
|= FC_FABRIC
;
660 spin_unlock_irq(shost
->host_lock
);
662 phba
->fc_edtov
= be32_to_cpu(sp
->cmn
.e_d_tov
);
663 if (sp
->cmn
.edtovResolution
) /* E_D_TOV ticks are in nanoseconds */
664 phba
->fc_edtov
= (phba
->fc_edtov
+ 999999) / 1000000;
666 phba
->fc_edtovResol
= sp
->cmn
.edtovResolution
;
667 phba
->fc_ratov
= (be32_to_cpu(sp
->cmn
.w2
.r_a_tov
) + 999) / 1000;
669 if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) {
670 spin_lock_irq(shost
->host_lock
);
671 vport
->fc_flag
|= FC_PUBLIC_LOOP
;
672 spin_unlock_irq(shost
->host_lock
);
675 vport
->fc_myDID
= irsp
->un
.ulpWord
[4] & Mask_DID
;
676 memcpy(&ndlp
->nlp_portname
, &sp
->portName
, sizeof(struct lpfc_name
));
677 memcpy(&ndlp
->nlp_nodename
, &sp
->nodeName
, sizeof(struct lpfc_name
));
678 ndlp
->nlp_class_sup
= 0;
679 if (sp
->cls1
.classValid
)
680 ndlp
->nlp_class_sup
|= FC_COS_CLASS1
;
681 if (sp
->cls2
.classValid
)
682 ndlp
->nlp_class_sup
|= FC_COS_CLASS2
;
683 if (sp
->cls3
.classValid
)
684 ndlp
->nlp_class_sup
|= FC_COS_CLASS3
;
685 if (sp
->cls4
.classValid
)
686 ndlp
->nlp_class_sup
|= FC_COS_CLASS4
;
687 ndlp
->nlp_maxframe
= ((sp
->cmn
.bbRcvSizeMsb
& 0x0F) << 8) |
688 sp
->cmn
.bbRcvSizeLsb
;
690 fabric_param_changed
= lpfc_check_clean_addr_bit(vport
, sp
);
691 if (fabric_param_changed
) {
692 /* Reset FDMI attribute masks based on config parameter */
693 if (phba
->cfg_enable_SmartSAN
||
694 (phba
->cfg_fdmi_on
== LPFC_FDMI_SUPPORT
)) {
695 /* Setup appropriate attribute masks */
696 vport
->fdmi_hba_mask
= LPFC_FDMI2_HBA_ATTR
;
697 if (phba
->cfg_enable_SmartSAN
)
698 vport
->fdmi_port_mask
= LPFC_FDMI2_SMART_ATTR
;
700 vport
->fdmi_port_mask
= LPFC_FDMI2_PORT_ATTR
;
702 vport
->fdmi_hba_mask
= 0;
703 vport
->fdmi_port_mask
= 0;
707 memcpy(&vport
->fabric_portname
, &sp
->portName
,
708 sizeof(struct lpfc_name
));
709 memcpy(&vport
->fabric_nodename
, &sp
->nodeName
,
710 sizeof(struct lpfc_name
));
711 memcpy(&phba
->fc_fabparam
, sp
, sizeof(struct serv_parm
));
713 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) {
714 if (sp
->cmn
.response_multiple_NPort
) {
715 lpfc_printf_vlog(vport
, KERN_WARNING
,
717 "1816 FLOGI NPIV supported, "
718 "response data 0x%x\n",
719 sp
->cmn
.response_multiple_NPort
);
720 spin_lock_irq(&phba
->hbalock
);
721 phba
->link_flag
|= LS_NPIV_FAB_SUPPORTED
;
722 spin_unlock_irq(&phba
->hbalock
);
724 /* Because we asked f/w for NPIV it still expects us
725 to call reg_vnpid atleast for the physcial host */
726 lpfc_printf_vlog(vport
, KERN_WARNING
,
728 "1817 Fabric does not support NPIV "
729 "- configuring single port mode.\n");
730 spin_lock_irq(&phba
->hbalock
);
731 phba
->link_flag
&= ~LS_NPIV_FAB_SUPPORTED
;
732 spin_unlock_irq(&phba
->hbalock
);
737 * For FC we need to do some special processing because of the SLI
738 * Port's default settings of the Common Service Parameters.
740 if ((phba
->sli_rev
== LPFC_SLI_REV4
) &&
741 (phba
->sli4_hba
.lnk_info
.lnk_tp
== LPFC_LNK_TYPE_FC
)) {
742 /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */
743 if (fabric_param_changed
)
744 lpfc_unregister_fcf_prep(phba
);
746 /* This should just update the VFI CSPs*/
747 if (vport
->fc_flag
& FC_VFI_REGISTERED
)
748 lpfc_issue_reg_vfi(vport
);
751 if (fabric_param_changed
&&
752 !(vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
)) {
754 /* If our NportID changed, we need to ensure all
755 * remaining NPORTs get unreg_login'ed.
757 list_for_each_entry_safe(np
, next_np
,
758 &vport
->fc_nodes
, nlp_listp
) {
759 if (!NLP_CHK_NODE_ACT(np
))
761 if ((np
->nlp_state
!= NLP_STE_NPR_NODE
) ||
762 !(np
->nlp_flag
& NLP_NPR_ADISC
))
764 spin_lock_irq(shost
->host_lock
);
765 np
->nlp_flag
&= ~NLP_NPR_ADISC
;
766 spin_unlock_irq(shost
->host_lock
);
767 lpfc_unreg_rpi(vport
, np
);
769 lpfc_cleanup_pending_mbox(vport
);
771 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
772 lpfc_sli4_unreg_all_rpis(vport
);
773 lpfc_mbx_unreg_vpi(vport
);
774 spin_lock_irq(shost
->host_lock
);
775 vport
->fc_flag
|= FC_VPORT_NEEDS_INIT_VPI
;
776 spin_unlock_irq(shost
->host_lock
);
780 * For SLI3 and SLI4, the VPI needs to be reregistered in
781 * response to this fabric parameter change event.
783 spin_lock_irq(shost
->host_lock
);
784 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
785 spin_unlock_irq(shost
->host_lock
);
786 } else if ((phba
->sli_rev
== LPFC_SLI_REV4
) &&
787 !(vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
)) {
789 * Driver needs to re-reg VPI in order for f/w
790 * to update the MAC address.
792 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
793 lpfc_register_new_vport(phba
, vport
, ndlp
);
797 if (phba
->sli_rev
< LPFC_SLI_REV4
) {
798 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_REG_LOGIN_ISSUE
);
799 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
&&
800 vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
)
801 lpfc_register_new_vport(phba
, vport
, ndlp
);
803 lpfc_issue_fabric_reglogin(vport
);
805 ndlp
->nlp_type
|= NLP_FABRIC
;
806 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
807 if ((!(vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
)) &&
808 (vport
->vpi_state
& LPFC_VPI_REGISTERED
)) {
809 lpfc_start_fdiscs(phba
);
810 lpfc_do_scr_ns_plogi(phba
, vport
);
811 } else if (vport
->fc_flag
& FC_VFI_REGISTERED
)
812 lpfc_issue_init_vpi(vport
);
814 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
815 "3135 Need register VFI: (x%x/%x)\n",
816 vport
->fc_prevDID
, vport
->fc_myDID
);
817 lpfc_issue_reg_vfi(vport
);
824 * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
825 * @vport: pointer to a host virtual N_Port data structure.
826 * @ndlp: pointer to a node-list data structure.
827 * @sp: pointer to service parameter data structure.
829 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
830 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
831 * in a point-to-point topology. First, the @vport's N_Port Name is compared
832 * with the received N_Port Name: if the @vport's N_Port Name is greater than
833 * the received N_Port Name lexicographically, this node shall assign local
834 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
835 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
836 * this node shall just wait for the remote node to issue PLOGI and assign
844 lpfc_cmpl_els_flogi_nport(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
845 struct serv_parm
*sp
)
847 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
848 struct lpfc_hba
*phba
= vport
->phba
;
852 spin_lock_irq(shost
->host_lock
);
853 vport
->fc_flag
&= ~(FC_FABRIC
| FC_PUBLIC_LOOP
);
854 vport
->fc_flag
|= FC_PT2PT
;
855 spin_unlock_irq(shost
->host_lock
);
857 /* If physical FC port changed, unreg VFI and ALL VPIs / RPIs */
858 if ((phba
->sli_rev
== LPFC_SLI_REV4
) && phba
->fc_topology_changed
) {
859 lpfc_unregister_fcf_prep(phba
);
861 spin_lock_irq(shost
->host_lock
);
862 vport
->fc_flag
&= ~FC_VFI_REGISTERED
;
863 spin_unlock_irq(shost
->host_lock
);
864 phba
->fc_topology_changed
= 0;
867 rc
= memcmp(&vport
->fc_portname
, &sp
->portName
,
868 sizeof(vport
->fc_portname
));
871 /* This side will initiate the PLOGI */
872 spin_lock_irq(shost
->host_lock
);
873 vport
->fc_flag
|= FC_PT2PT_PLOGI
;
874 spin_unlock_irq(shost
->host_lock
);
877 * N_Port ID cannot be 0, set our Id to LocalID
878 * the other side will be RemoteID.
883 vport
->fc_myDID
= PT2PT_LocalID
;
885 /* Decrement ndlp reference count indicating that ndlp can be
886 * safely released when other references to it are done.
890 ndlp
= lpfc_findnode_did(vport
, PT2PT_RemoteID
);
893 * Cannot find existing Fabric ndlp, so allocate a
896 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
899 lpfc_nlp_init(vport
, ndlp
, PT2PT_RemoteID
);
900 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
901 ndlp
= lpfc_enable_node(vport
, ndlp
,
902 NLP_STE_UNUSED_NODE
);
907 memcpy(&ndlp
->nlp_portname
, &sp
->portName
,
908 sizeof(struct lpfc_name
));
909 memcpy(&ndlp
->nlp_nodename
, &sp
->nodeName
,
910 sizeof(struct lpfc_name
));
911 /* Set state will put ndlp onto node list if not already done */
912 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
913 spin_lock_irq(shost
->host_lock
);
914 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
915 spin_unlock_irq(shost
->host_lock
);
917 /* This side will wait for the PLOGI, decrement ndlp reference
918 * count indicating that ndlp can be released when other
919 * references to it are done.
923 /* If we are pt2pt with another NPort, force NPIV off! */
924 phba
->sli3_options
&= ~LPFC_SLI3_NPIV_ENABLED
;
926 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
930 lpfc_config_link(phba
, mbox
);
932 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_local_config_link
;
934 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
935 if (rc
== MBX_NOT_FINISHED
) {
936 mempool_free(mbox
, phba
->mbox_mem_pool
);
946 * lpfc_cmpl_els_flogi - Completion callback function for flogi
947 * @phba: pointer to lpfc hba data structure.
948 * @cmdiocb: pointer to lpfc command iocb data structure.
949 * @rspiocb: pointer to lpfc response iocb data structure.
951 * This routine is the top-level completion callback function for issuing
952 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
953 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
954 * retry has been made (either immediately or delayed with lpfc_els_retry()
955 * returning 1), the command IOCB will be released and function returned.
956 * If the retry attempt has been given up (possibly reach the maximum
957 * number of retries), one additional decrement of ndlp reference shall be
958 * invoked before going out after releasing the command IOCB. This will
959 * actually release the remote node (Note, lpfc_els_free_iocb() will also
960 * invoke one decrement of ndlp reference count). If no error reported in
961 * the IOCB status, the command Port ID field is used to determine whether
962 * this is a point-to-point topology or a fabric topology: if the Port ID
963 * field is assigned, it is a fabric topology; otherwise, it is a
964 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
965 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
966 * specific topology completion conditions.
969 lpfc_cmpl_els_flogi(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
970 struct lpfc_iocbq
*rspiocb
)
972 struct lpfc_vport
*vport
= cmdiocb
->vport
;
973 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
974 IOCB_t
*irsp
= &rspiocb
->iocb
;
975 struct lpfc_nodelist
*ndlp
= cmdiocb
->context1
;
976 struct lpfc_dmabuf
*pcmd
= cmdiocb
->context2
, *prsp
;
977 struct serv_parm
*sp
;
981 /* Check to see if link went down during discovery */
982 if (lpfc_els_chk_latt(vport
)) {
983 /* One additional decrement on node reference count to
984 * trigger the release of the node
990 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
991 "FLOGI cmpl: status:x%x/x%x state:x%x",
992 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
995 if (irsp
->ulpStatus
) {
997 * In case of FIP mode, perform roundrobin FCF failover
998 * due to new FCF discovery
1000 if ((phba
->hba_flag
& HBA_FIP_SUPPORT
) &&
1001 (phba
->fcf
.fcf_flag
& FCF_DISCOVERY
)) {
1002 if (phba
->link_state
< LPFC_LINK_UP
)
1003 goto stop_rr_fcf_flogi
;
1004 if ((phba
->fcoe_cvl_eventtag_attn
==
1005 phba
->fcoe_cvl_eventtag
) &&
1006 (irsp
->ulpStatus
== IOSTAT_LOCAL_REJECT
) &&
1007 ((irsp
->un
.ulpWord
[4] & IOERR_PARAM_MASK
) ==
1009 goto stop_rr_fcf_flogi
;
1011 phba
->fcoe_cvl_eventtag_attn
=
1012 phba
->fcoe_cvl_eventtag
;
1013 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FIP
| LOG_ELS
,
1014 "2611 FLOGI failed on FCF (x%x), "
1015 "status:x%x/x%x, tmo:x%x, perform "
1016 "roundrobin FCF failover\n",
1017 phba
->fcf
.current_rec
.fcf_indx
,
1018 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1020 lpfc_sli4_set_fcf_flogi_fail(phba
,
1021 phba
->fcf
.current_rec
.fcf_indx
);
1022 fcf_index
= lpfc_sli4_fcf_rr_next_index_get(phba
);
1023 rc
= lpfc_sli4_fcf_rr_next_proc(vport
, fcf_index
);
1030 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1031 "2858 FLOGI failure Status:x%x/x%x TMO:x%x "
1033 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1034 irsp
->ulpTimeout
, phba
->hba_flag
,
1035 phba
->fcf
.fcf_flag
);
1037 /* Check for retry */
1038 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
))
1042 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1043 "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n",
1044 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1047 /* FLOGI failed, so there is no fabric */
1048 spin_lock_irq(shost
->host_lock
);
1049 vport
->fc_flag
&= ~(FC_FABRIC
| FC_PUBLIC_LOOP
);
1050 spin_unlock_irq(shost
->host_lock
);
1052 /* If private loop, then allow max outstanding els to be
1053 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
1054 * alpa map would take too long otherwise.
1056 if (phba
->alpa_map
[0] == 0)
1057 vport
->cfg_discovery_threads
= LPFC_MAX_DISC_THREADS
;
1058 if ((phba
->sli_rev
== LPFC_SLI_REV4
) &&
1059 (!(vport
->fc_flag
& FC_VFI_REGISTERED
) ||
1060 (vport
->fc_prevDID
!= vport
->fc_myDID
) ||
1061 phba
->fc_topology_changed
)) {
1062 if (vport
->fc_flag
& FC_VFI_REGISTERED
) {
1063 if (phba
->fc_topology_changed
) {
1064 lpfc_unregister_fcf_prep(phba
);
1065 spin_lock_irq(shost
->host_lock
);
1066 vport
->fc_flag
&= ~FC_VFI_REGISTERED
;
1067 spin_unlock_irq(shost
->host_lock
);
1068 phba
->fc_topology_changed
= 0;
1070 lpfc_sli4_unreg_all_rpis(vport
);
1074 /* Do not register VFI if the driver aborted FLOGI */
1075 if (!lpfc_error_lost_link(irsp
))
1076 lpfc_issue_reg_vfi(vport
);
1082 spin_lock_irq(shost
->host_lock
);
1083 vport
->fc_flag
&= ~FC_VPORT_CVL_RCVD
;
1084 vport
->fc_flag
&= ~FC_VPORT_LOGO_RCVD
;
1085 spin_unlock_irq(shost
->host_lock
);
1088 * The FLogI succeeded. Sync the data for the CPU before
1091 prsp
= list_get_first(&pcmd
->list
, struct lpfc_dmabuf
, list
);
1094 sp
= prsp
->virt
+ sizeof(uint32_t);
1096 /* FLOGI completes successfully */
1097 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
1098 "0101 FLOGI completes successfully, I/O tag:x%x, "
1099 "Data: x%x x%x x%x x%x x%x x%x\n", cmdiocb
->iotag
,
1100 irsp
->un
.ulpWord
[4], sp
->cmn
.e_d_tov
,
1101 sp
->cmn
.w2
.r_a_tov
, sp
->cmn
.edtovResolution
,
1102 vport
->port_state
, vport
->fc_flag
);
1104 if (vport
->port_state
== LPFC_FLOGI
) {
1106 * If Common Service Parameters indicate Nport
1107 * we are point to point, if Fport we are Fabric.
1110 rc
= lpfc_cmpl_els_flogi_fabric(vport
, ndlp
, sp
, irsp
);
1111 else if (!(phba
->hba_flag
& HBA_FCOE_MODE
))
1112 rc
= lpfc_cmpl_els_flogi_nport(vport
, ndlp
, sp
);
1114 lpfc_printf_vlog(vport
, KERN_ERR
,
1116 "2831 FLOGI response with cleared Fabric "
1117 "bit fcf_index 0x%x "
1118 "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
1120 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
1121 phba
->fcf
.current_rec
.fcf_indx
,
1122 phba
->fcf
.current_rec
.switch_name
[0],
1123 phba
->fcf
.current_rec
.switch_name
[1],
1124 phba
->fcf
.current_rec
.switch_name
[2],
1125 phba
->fcf
.current_rec
.switch_name
[3],
1126 phba
->fcf
.current_rec
.switch_name
[4],
1127 phba
->fcf
.current_rec
.switch_name
[5],
1128 phba
->fcf
.current_rec
.switch_name
[6],
1129 phba
->fcf
.current_rec
.switch_name
[7],
1130 phba
->fcf
.current_rec
.fabric_name
[0],
1131 phba
->fcf
.current_rec
.fabric_name
[1],
1132 phba
->fcf
.current_rec
.fabric_name
[2],
1133 phba
->fcf
.current_rec
.fabric_name
[3],
1134 phba
->fcf
.current_rec
.fabric_name
[4],
1135 phba
->fcf
.current_rec
.fabric_name
[5],
1136 phba
->fcf
.current_rec
.fabric_name
[6],
1137 phba
->fcf
.current_rec
.fabric_name
[7]);
1139 spin_lock_irq(&phba
->hbalock
);
1140 phba
->fcf
.fcf_flag
&= ~FCF_DISCOVERY
;
1141 phba
->hba_flag
&= ~(FCF_RR_INPROG
| HBA_DEVLOSS_TMO
);
1142 spin_unlock_irq(&phba
->hbalock
);
1146 /* Mark the FCF discovery process done */
1147 if (phba
->hba_flag
& HBA_FIP_SUPPORT
)
1148 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_FIP
|
1150 "2769 FLOGI to FCF (x%x) "
1151 "completed successfully\n",
1152 phba
->fcf
.current_rec
.fcf_indx
);
1153 spin_lock_irq(&phba
->hbalock
);
1154 phba
->fcf
.fcf_flag
&= ~FCF_DISCOVERY
;
1155 phba
->hba_flag
&= ~(FCF_RR_INPROG
| HBA_DEVLOSS_TMO
);
1156 spin_unlock_irq(&phba
->hbalock
);
1162 spin_lock_irq(&phba
->hbalock
);
1163 phba
->fcf
.fcf_flag
&= ~FCF_DISCOVERY
;
1164 spin_unlock_irq(&phba
->hbalock
);
1168 if (!lpfc_error_lost_link(irsp
)) {
1169 /* FLOGI failed, so just use loop map to make discovery list */
1170 lpfc_disc_list_loopmap(vport
);
1172 /* Start discovery */
1173 lpfc_disc_start(vport
);
1174 } else if (((irsp
->ulpStatus
!= IOSTAT_LOCAL_REJECT
) ||
1175 (((irsp
->un
.ulpWord
[4] & IOERR_PARAM_MASK
) !=
1176 IOERR_SLI_ABORTED
) &&
1177 ((irsp
->un
.ulpWord
[4] & IOERR_PARAM_MASK
) !=
1178 IOERR_SLI_DOWN
))) &&
1179 (phba
->link_state
!= LPFC_CLEAR_LA
)) {
1180 /* If FLOGI failed enable link interrupt. */
1181 lpfc_issue_clear_la(phba
, vport
);
1184 lpfc_els_free_iocb(phba
, cmdiocb
);
1188 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
1189 * @vport: pointer to a host virtual N_Port data structure.
1190 * @ndlp: pointer to a node-list data structure.
1191 * @retry: number of retries to the command IOCB.
1193 * This routine issues a Fabric Login (FLOGI) Request ELS command
1194 * for a @vport. The initiator service parameters are put into the payload
1195 * of the FLOGI Request IOCB and the top-level callback function pointer
1196 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
1197 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
1198 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
1200 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1201 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1202 * will be stored into the context1 field of the IOCB for the completion
1203 * callback function to the FLOGI ELS command.
1206 * 0 - successfully issued flogi iocb for @vport
1207 * 1 - failed to issue flogi iocb for @vport
1210 lpfc_issue_els_flogi(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1213 struct lpfc_hba
*phba
= vport
->phba
;
1214 struct serv_parm
*sp
;
1216 struct lpfc_iocbq
*elsiocb
;
1222 cmdsize
= (sizeof(uint32_t) + sizeof(struct serv_parm
));
1223 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
1224 ndlp
->nlp_DID
, ELS_CMD_FLOGI
);
1229 icmd
= &elsiocb
->iocb
;
1230 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
1232 /* For FLOGI request, remainder of payload is service parameters */
1233 *((uint32_t *) (pcmd
)) = ELS_CMD_FLOGI
;
1234 pcmd
+= sizeof(uint32_t);
1235 memcpy(pcmd
, &vport
->fc_sparam
, sizeof(struct serv_parm
));
1236 sp
= (struct serv_parm
*) pcmd
;
1238 /* Setup CSPs accordingly for Fabric */
1239 sp
->cmn
.e_d_tov
= 0;
1240 sp
->cmn
.w2
.r_a_tov
= 0;
1241 sp
->cmn
.virtual_fabric_support
= 0;
1242 sp
->cls1
.classValid
= 0;
1243 if (sp
->cmn
.fcphLow
< FC_PH3
)
1244 sp
->cmn
.fcphLow
= FC_PH3
;
1245 if (sp
->cmn
.fcphHigh
< FC_PH3
)
1246 sp
->cmn
.fcphHigh
= FC_PH3
;
1248 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
1249 if (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) ==
1250 LPFC_SLI_INTF_IF_TYPE_0
) {
1251 elsiocb
->iocb
.ulpCt_h
= ((SLI4_CT_FCFI
>> 1) & 1);
1252 elsiocb
->iocb
.ulpCt_l
= (SLI4_CT_FCFI
& 1);
1253 /* FLOGI needs to be 3 for WQE FCFI */
1254 /* Set the fcfi to the fcfi we registered with */
1255 elsiocb
->iocb
.ulpContext
= phba
->fcf
.fcfi
;
1257 /* Can't do SLI4 class2 without support sequence coalescing */
1258 sp
->cls2
.classValid
= 0;
1259 sp
->cls2
.seqDelivery
= 0;
1261 /* Historical, setting sequential-delivery bit for SLI3 */
1262 sp
->cls2
.seqDelivery
= (sp
->cls2
.classValid
) ? 1 : 0;
1263 sp
->cls3
.seqDelivery
= (sp
->cls3
.classValid
) ? 1 : 0;
1264 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) {
1265 sp
->cmn
.request_multiple_Nport
= 1;
1266 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1270 sp
->cmn
.request_multiple_Nport
= 0;
1273 if (phba
->fc_topology
!= LPFC_TOPOLOGY_LOOP
) {
1274 icmd
->un
.elsreq64
.myID
= 0;
1275 icmd
->un
.elsreq64
.fl
= 1;
1278 tmo
= phba
->fc_ratov
;
1279 phba
->fc_ratov
= LPFC_DISC_FLOGI_TMO
;
1280 lpfc_set_disctmo(vport
);
1281 phba
->fc_ratov
= tmo
;
1283 phba
->fc_stat
.elsXmitFLOGI
++;
1284 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_flogi
;
1286 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1287 "Issue FLOGI: opt:x%x",
1288 phba
->sli3_options
, 0, 0);
1290 rc
= lpfc_issue_fabric_iocb(phba
, elsiocb
);
1291 if (rc
== IOCB_ERROR
) {
1292 lpfc_els_free_iocb(phba
, elsiocb
);
1299 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
1300 * @phba: pointer to lpfc hba data structure.
1302 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1303 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1304 * list and issues an abort IOCB commond on each outstanding IOCB that
1305 * contains a active Fabric_DID ndlp. Note that this function is to issue
1306 * the abort IOCB command on all the outstanding IOCBs, thus when this
1307 * function returns, it does not guarantee all the IOCBs are actually aborted.
1310 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
1313 lpfc_els_abort_flogi(struct lpfc_hba
*phba
)
1315 struct lpfc_sli_ring
*pring
;
1316 struct lpfc_iocbq
*iocb
, *next_iocb
;
1317 struct lpfc_nodelist
*ndlp
;
1320 /* Abort outstanding I/O on NPort <nlp_DID> */
1321 lpfc_printf_log(phba
, KERN_INFO
, LOG_DISCOVERY
,
1322 "0201 Abort outstanding I/O on NPort x%x\n",
1325 pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
1328 * Check the txcmplq for an iocb that matches the nport the driver is
1331 spin_lock_irq(&phba
->hbalock
);
1332 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
, list
) {
1334 if (icmd
->ulpCommand
== CMD_ELS_REQUEST64_CR
) {
1335 ndlp
= (struct lpfc_nodelist
*)(iocb
->context1
);
1336 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
) &&
1337 (ndlp
->nlp_DID
== Fabric_DID
))
1338 lpfc_sli_issue_abort_iotag(phba
, pring
, iocb
);
1341 spin_unlock_irq(&phba
->hbalock
);
1347 * lpfc_initial_flogi - Issue an initial fabric login for a vport
1348 * @vport: pointer to a host virtual N_Port data structure.
1350 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1351 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1352 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1353 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1354 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1355 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1359 * 0 - failed to issue initial flogi for @vport
1360 * 1 - successfully issued initial flogi for @vport
1363 lpfc_initial_flogi(struct lpfc_vport
*vport
)
1365 struct lpfc_hba
*phba
= vport
->phba
;
1366 struct lpfc_nodelist
*ndlp
;
1368 vport
->port_state
= LPFC_FLOGI
;
1369 lpfc_set_disctmo(vport
);
1371 /* First look for the Fabric ndlp */
1372 ndlp
= lpfc_findnode_did(vport
, Fabric_DID
);
1374 /* Cannot find existing Fabric ndlp, so allocate a new one */
1375 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
1378 lpfc_nlp_init(vport
, ndlp
, Fabric_DID
);
1379 /* Set the node type */
1380 ndlp
->nlp_type
|= NLP_FABRIC
;
1381 /* Put ndlp onto node list */
1382 lpfc_enqueue_node(vport
, ndlp
);
1383 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
1384 /* re-setup ndlp without removing from node list */
1385 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
1390 if (lpfc_issue_els_flogi(vport
, ndlp
, 0)) {
1391 /* This decrement of reference count to node shall kick off
1392 * the release of the node.
1401 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
1402 * @vport: pointer to a host virtual N_Port data structure.
1404 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1405 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1406 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1407 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1408 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1409 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1413 * 0 - failed to issue initial fdisc for @vport
1414 * 1 - successfully issued initial fdisc for @vport
1417 lpfc_initial_fdisc(struct lpfc_vport
*vport
)
1419 struct lpfc_hba
*phba
= vport
->phba
;
1420 struct lpfc_nodelist
*ndlp
;
1422 /* First look for the Fabric ndlp */
1423 ndlp
= lpfc_findnode_did(vport
, Fabric_DID
);
1425 /* Cannot find existing Fabric ndlp, so allocate a new one */
1426 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
1429 lpfc_nlp_init(vport
, ndlp
, Fabric_DID
);
1430 /* Put ndlp onto node list */
1431 lpfc_enqueue_node(vport
, ndlp
);
1432 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
1433 /* re-setup ndlp without removing from node list */
1434 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
1439 if (lpfc_issue_els_fdisc(vport
, ndlp
, 0)) {
1440 /* decrement node reference count to trigger the release of
1450 * lpfc_more_plogi - Check and issue remaining plogis for a vport
1451 * @vport: pointer to a host virtual N_Port data structure.
1453 * This routine checks whether there are more remaining Port Logins
1454 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1455 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1456 * to issue ELS PLOGIs up to the configured discover threads with the
1457 * @vport (@vport->cfg_discovery_threads). The function also decrement
1458 * the @vport's num_disc_node by 1 if it is not already 0.
1461 lpfc_more_plogi(struct lpfc_vport
*vport
)
1463 if (vport
->num_disc_nodes
)
1464 vport
->num_disc_nodes
--;
1466 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
1467 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
1468 "0232 Continue discovery with %d PLOGIs to go "
1469 "Data: x%x x%x x%x\n",
1470 vport
->num_disc_nodes
, vport
->fc_plogi_cnt
,
1471 vport
->fc_flag
, vport
->port_state
);
1472 /* Check to see if there are more PLOGIs to be sent */
1473 if (vport
->fc_flag
& FC_NLP_MORE
)
1474 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1475 lpfc_els_disc_plogi(vport
);
1481 * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
1482 * @phba: pointer to lpfc hba data structure.
1483 * @prsp: pointer to response IOCB payload.
1484 * @ndlp: pointer to a node-list data structure.
1486 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1487 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1488 * The following cases are considered N_Port confirmed:
1489 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1490 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1491 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1492 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1493 * 1) if there is a node on vport list other than the @ndlp with the same
1494 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1495 * on that node to release the RPI associated with the node; 2) if there is
1496 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1497 * into, a new node shall be allocated (or activated). In either case, the
1498 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1499 * be released and the new_ndlp shall be put on to the vport node list and
1500 * its pointer returned as the confirmed node.
1502 * Note that before the @ndlp got "released", the keepDID from not-matching
1503 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1504 * of the @ndlp. This is because the release of @ndlp is actually to put it
1505 * into an inactive state on the vport node list and the vport node list
1506 * management algorithm does not allow two node with a same DID.
1509 * pointer to the PLOGI N_Port @ndlp
1511 static struct lpfc_nodelist
*
1512 lpfc_plogi_confirm_nport(struct lpfc_hba
*phba
, uint32_t *prsp
,
1513 struct lpfc_nodelist
*ndlp
)
1515 struct lpfc_vport
*vport
= ndlp
->vport
;
1516 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1517 struct lpfc_nodelist
*new_ndlp
;
1518 struct lpfc_rport_data
*rdata
;
1519 struct fc_rport
*rport
;
1520 struct serv_parm
*sp
;
1521 uint8_t name
[sizeof(struct lpfc_name
)];
1522 uint32_t rc
, keepDID
= 0, keep_nlp_flag
= 0;
1523 uint16_t keep_nlp_state
;
1526 unsigned long *active_rrqs_xri_bitmap
= NULL
;
1528 /* Fabric nodes can have the same WWPN so we don't bother searching
1529 * by WWPN. Just return the ndlp that was given to us.
1531 if (ndlp
->nlp_type
& NLP_FABRIC
)
1534 sp
= (struct serv_parm
*) ((uint8_t *) prsp
+ sizeof(uint32_t));
1535 memset(name
, 0, sizeof(struct lpfc_name
));
1537 /* Now we find out if the NPort we are logging into, matches the WWPN
1538 * we have for that ndlp. If not, we have some work to do.
1540 new_ndlp
= lpfc_findnode_wwpn(vport
, &sp
->portName
);
1542 if (new_ndlp
== ndlp
&& NLP_CHK_NODE_ACT(new_ndlp
))
1544 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
1545 active_rrqs_xri_bitmap
= mempool_alloc(phba
->active_rrq_pool
,
1547 if (active_rrqs_xri_bitmap
)
1548 memset(active_rrqs_xri_bitmap
, 0,
1549 phba
->cfg_rrq_xri_bitmap_sz
);
1552 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
1553 "3178 PLOGI confirm: ndlp %p x%x: new_ndlp %p\n",
1554 ndlp
, ndlp
->nlp_DID
, new_ndlp
);
1557 rc
= memcmp(&ndlp
->nlp_portname
, name
,
1558 sizeof(struct lpfc_name
));
1560 if (active_rrqs_xri_bitmap
)
1561 mempool_free(active_rrqs_xri_bitmap
,
1562 phba
->active_rrq_pool
);
1565 new_ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_ATOMIC
);
1567 if (active_rrqs_xri_bitmap
)
1568 mempool_free(active_rrqs_xri_bitmap
,
1569 phba
->active_rrq_pool
);
1572 lpfc_nlp_init(vport
, new_ndlp
, ndlp
->nlp_DID
);
1573 } else if (!NLP_CHK_NODE_ACT(new_ndlp
)) {
1574 rc
= memcmp(&ndlp
->nlp_portname
, name
,
1575 sizeof(struct lpfc_name
));
1577 if (active_rrqs_xri_bitmap
)
1578 mempool_free(active_rrqs_xri_bitmap
,
1579 phba
->active_rrq_pool
);
1582 new_ndlp
= lpfc_enable_node(vport
, new_ndlp
,
1583 NLP_STE_UNUSED_NODE
);
1585 if (active_rrqs_xri_bitmap
)
1586 mempool_free(active_rrqs_xri_bitmap
,
1587 phba
->active_rrq_pool
);
1590 keepDID
= new_ndlp
->nlp_DID
;
1591 if ((phba
->sli_rev
== LPFC_SLI_REV4
) && active_rrqs_xri_bitmap
)
1592 memcpy(active_rrqs_xri_bitmap
,
1593 new_ndlp
->active_rrqs_xri_bitmap
,
1594 phba
->cfg_rrq_xri_bitmap_sz
);
1596 keepDID
= new_ndlp
->nlp_DID
;
1597 if (phba
->sli_rev
== LPFC_SLI_REV4
&&
1598 active_rrqs_xri_bitmap
)
1599 memcpy(active_rrqs_xri_bitmap
,
1600 new_ndlp
->active_rrqs_xri_bitmap
,
1601 phba
->cfg_rrq_xri_bitmap_sz
);
1604 lpfc_unreg_rpi(vport
, new_ndlp
);
1605 new_ndlp
->nlp_DID
= ndlp
->nlp_DID
;
1606 new_ndlp
->nlp_prev_state
= ndlp
->nlp_prev_state
;
1607 if (phba
->sli_rev
== LPFC_SLI_REV4
)
1608 memcpy(new_ndlp
->active_rrqs_xri_bitmap
,
1609 ndlp
->active_rrqs_xri_bitmap
,
1610 phba
->cfg_rrq_xri_bitmap_sz
);
1612 spin_lock_irq(shost
->host_lock
);
1613 keep_nlp_flag
= new_ndlp
->nlp_flag
;
1614 new_ndlp
->nlp_flag
= ndlp
->nlp_flag
;
1615 ndlp
->nlp_flag
= keep_nlp_flag
;
1616 spin_unlock_irq(shost
->host_lock
);
1618 /* Set nlp_states accordingly */
1619 keep_nlp_state
= new_ndlp
->nlp_state
;
1620 lpfc_nlp_set_state(vport
, new_ndlp
, ndlp
->nlp_state
);
1622 /* Move this back to NPR state */
1623 if (memcmp(&ndlp
->nlp_portname
, name
, sizeof(struct lpfc_name
)) == 0) {
1624 /* The new_ndlp is replacing ndlp totally, so we need
1625 * to put ndlp on UNUSED list and try to free it.
1627 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
1628 "3179 PLOGI confirm NEW: %x %x\n",
1629 new_ndlp
->nlp_DID
, keepDID
);
1631 /* Fix up the rport accordingly */
1632 rport
= ndlp
->rport
;
1634 rdata
= rport
->dd_data
;
1635 if (rdata
->pnode
== ndlp
) {
1636 /* break the link before dropping the ref */
1639 rdata
->pnode
= lpfc_nlp_get(new_ndlp
);
1640 new_ndlp
->rport
= rport
;
1642 new_ndlp
->nlp_type
= ndlp
->nlp_type
;
1644 /* We shall actually free the ndlp with both nlp_DID and
1645 * nlp_portname fields equals 0 to avoid any ndlp on the
1646 * nodelist never to be used.
1648 if (ndlp
->nlp_DID
== 0) {
1649 spin_lock_irq(&phba
->ndlp_lock
);
1650 NLP_SET_FREE_REQ(ndlp
);
1651 spin_unlock_irq(&phba
->ndlp_lock
);
1654 /* Two ndlps cannot have the same did on the nodelist */
1655 ndlp
->nlp_DID
= keepDID
;
1656 if (phba
->sli_rev
== LPFC_SLI_REV4
&&
1657 active_rrqs_xri_bitmap
)
1658 memcpy(ndlp
->active_rrqs_xri_bitmap
,
1659 active_rrqs_xri_bitmap
,
1660 phba
->cfg_rrq_xri_bitmap_sz
);
1662 if (!NLP_CHK_NODE_ACT(ndlp
))
1663 lpfc_drop_node(vport
, ndlp
);
1666 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
1667 "3180 PLOGI confirm SWAP: %x %x\n",
1668 new_ndlp
->nlp_DID
, keepDID
);
1670 lpfc_unreg_rpi(vport
, ndlp
);
1672 /* Two ndlps cannot have the same did */
1673 ndlp
->nlp_DID
= keepDID
;
1674 if (phba
->sli_rev
== LPFC_SLI_REV4
&&
1675 active_rrqs_xri_bitmap
)
1676 memcpy(ndlp
->active_rrqs_xri_bitmap
,
1677 active_rrqs_xri_bitmap
,
1678 phba
->cfg_rrq_xri_bitmap_sz
);
1680 /* Since we are switching over to the new_ndlp,
1681 * reset the old ndlp state
1683 if ((ndlp
->nlp_state
== NLP_STE_UNMAPPED_NODE
) ||
1684 (ndlp
->nlp_state
== NLP_STE_MAPPED_NODE
))
1685 keep_nlp_state
= NLP_STE_NPR_NODE
;
1686 lpfc_nlp_set_state(vport
, ndlp
, keep_nlp_state
);
1688 /* Fix up the rport accordingly */
1689 rport
= ndlp
->rport
;
1691 rdata
= rport
->dd_data
;
1692 put_node
= rdata
->pnode
!= NULL
;
1693 put_rport
= ndlp
->rport
!= NULL
;
1694 rdata
->pnode
= NULL
;
1699 put_device(&rport
->dev
);
1702 if (phba
->sli_rev
== LPFC_SLI_REV4
&&
1703 active_rrqs_xri_bitmap
)
1704 mempool_free(active_rrqs_xri_bitmap
,
1705 phba
->active_rrq_pool
);
1710 * lpfc_end_rscn - Check and handle more rscn for a vport
1711 * @vport: pointer to a host virtual N_Port data structure.
1713 * This routine checks whether more Registration State Change
1714 * Notifications (RSCNs) came in while the discovery state machine was in
1715 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1716 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1717 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1718 * handling the RSCNs.
1721 lpfc_end_rscn(struct lpfc_vport
*vport
)
1723 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1725 if (vport
->fc_flag
& FC_RSCN_MODE
) {
1727 * Check to see if more RSCNs came in while we were
1728 * processing this one.
1730 if (vport
->fc_rscn_id_cnt
||
1731 (vport
->fc_flag
& FC_RSCN_DISCOVERY
) != 0)
1732 lpfc_els_handle_rscn(vport
);
1734 spin_lock_irq(shost
->host_lock
);
1735 vport
->fc_flag
&= ~FC_RSCN_MODE
;
1736 spin_unlock_irq(shost
->host_lock
);
1742 * lpfc_cmpl_els_rrq - Completion handled for els RRQs.
1743 * @phba: pointer to lpfc hba data structure.
1744 * @cmdiocb: pointer to lpfc command iocb data structure.
1745 * @rspiocb: pointer to lpfc response iocb data structure.
1747 * This routine will call the clear rrq function to free the rrq and
1748 * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not
1749 * exist then the clear_rrq is still called because the rrq needs to
1754 lpfc_cmpl_els_rrq(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
1755 struct lpfc_iocbq
*rspiocb
)
1757 struct lpfc_vport
*vport
= cmdiocb
->vport
;
1759 struct lpfc_nodelist
*ndlp
;
1760 struct lpfc_node_rrq
*rrq
;
1762 /* we pass cmdiocb to state machine which needs rspiocb as well */
1763 rrq
= cmdiocb
->context_un
.rrq
;
1764 cmdiocb
->context_un
.rsp_iocb
= rspiocb
;
1766 irsp
= &rspiocb
->iocb
;
1767 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1768 "RRQ cmpl: status:x%x/x%x did:x%x",
1769 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1770 irsp
->un
.elsreq64
.remoteID
);
1772 ndlp
= lpfc_findnode_did(vport
, irsp
->un
.elsreq64
.remoteID
);
1773 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
) || ndlp
!= rrq
->ndlp
) {
1774 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1775 "2882 RRQ completes to NPort x%x "
1776 "with no ndlp. Data: x%x x%x x%x\n",
1777 irsp
->un
.elsreq64
.remoteID
,
1778 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1783 /* rrq completes to NPort <nlp_DID> */
1784 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
1785 "2880 RRQ completes to NPort x%x "
1786 "Data: x%x x%x x%x x%x x%x\n",
1787 ndlp
->nlp_DID
, irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1788 irsp
->ulpTimeout
, rrq
->xritag
, rrq
->rxid
);
1790 if (irsp
->ulpStatus
) {
1791 /* Check for retry */
1792 /* RRQ failed Don't print the vport to vport rjts */
1793 if (irsp
->ulpStatus
!= IOSTAT_LS_RJT
||
1794 (((irsp
->un
.ulpWord
[4]) >> 16 != LSRJT_INVALID_CMD
) &&
1795 ((irsp
->un
.ulpWord
[4]) >> 16 != LSRJT_UNABLE_TPC
)) ||
1796 (phba
)->pport
->cfg_log_verbose
& LOG_ELS
)
1797 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1798 "2881 RRQ failure DID:%06X Status:x%x/x%x\n",
1799 ndlp
->nlp_DID
, irsp
->ulpStatus
,
1800 irsp
->un
.ulpWord
[4]);
1804 lpfc_clr_rrq_active(phba
, rrq
->xritag
, rrq
);
1805 lpfc_els_free_iocb(phba
, cmdiocb
);
1809 * lpfc_cmpl_els_plogi - Completion callback function for plogi
1810 * @phba: pointer to lpfc hba data structure.
1811 * @cmdiocb: pointer to lpfc command iocb data structure.
1812 * @rspiocb: pointer to lpfc response iocb data structure.
1814 * This routine is the completion callback function for issuing the Port
1815 * Login (PLOGI) command. For PLOGI completion, there must be an active
1816 * ndlp on the vport node list that matches the remote node ID from the
1817 * PLOGI response IOCB. If such ndlp does not exist, the PLOGI is simply
1818 * ignored and command IOCB released. The PLOGI response IOCB status is
1819 * checked for error conditons. If there is error status reported, PLOGI
1820 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1821 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1822 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1823 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1824 * there are additional N_Port nodes with the vport that need to perform
1825 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1829 lpfc_cmpl_els_plogi(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
1830 struct lpfc_iocbq
*rspiocb
)
1832 struct lpfc_vport
*vport
= cmdiocb
->vport
;
1833 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1835 struct lpfc_nodelist
*ndlp
;
1836 struct lpfc_dmabuf
*prsp
;
1839 /* we pass cmdiocb to state machine which needs rspiocb as well */
1840 cmdiocb
->context_un
.rsp_iocb
= rspiocb
;
1842 irsp
= &rspiocb
->iocb
;
1843 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1844 "PLOGI cmpl: status:x%x/x%x did:x%x",
1845 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1846 irsp
->un
.elsreq64
.remoteID
);
1848 ndlp
= lpfc_findnode_did(vport
, irsp
->un
.elsreq64
.remoteID
);
1849 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
)) {
1850 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1851 "0136 PLOGI completes to NPort x%x "
1852 "with no ndlp. Data: x%x x%x x%x\n",
1853 irsp
->un
.elsreq64
.remoteID
,
1854 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1859 /* Since ndlp can be freed in the disc state machine, note if this node
1860 * is being used during discovery.
1862 spin_lock_irq(shost
->host_lock
);
1863 disc
= (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
);
1864 ndlp
->nlp_flag
&= ~NLP_NPR_2B_DISC
;
1865 spin_unlock_irq(shost
->host_lock
);
1868 /* PLOGI completes to NPort <nlp_DID> */
1869 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
1870 "0102 PLOGI completes to NPort x%x "
1871 "Data: x%x x%x x%x x%x x%x\n",
1872 ndlp
->nlp_DID
, irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1873 irsp
->ulpTimeout
, disc
, vport
->num_disc_nodes
);
1874 /* Check to see if link went down during discovery */
1875 if (lpfc_els_chk_latt(vport
)) {
1876 spin_lock_irq(shost
->host_lock
);
1877 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
1878 spin_unlock_irq(shost
->host_lock
);
1882 if (irsp
->ulpStatus
) {
1883 /* Check for retry */
1884 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
)) {
1885 /* ELS command is being retried */
1887 spin_lock_irq(shost
->host_lock
);
1888 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
1889 spin_unlock_irq(shost
->host_lock
);
1893 /* PLOGI failed Don't print the vport to vport rjts */
1894 if (irsp
->ulpStatus
!= IOSTAT_LS_RJT
||
1895 (((irsp
->un
.ulpWord
[4]) >> 16 != LSRJT_INVALID_CMD
) &&
1896 ((irsp
->un
.ulpWord
[4]) >> 16 != LSRJT_UNABLE_TPC
)) ||
1897 (phba
)->pport
->cfg_log_verbose
& LOG_ELS
)
1898 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1899 "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
1900 ndlp
->nlp_DID
, irsp
->ulpStatus
,
1901 irsp
->un
.ulpWord
[4]);
1902 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1903 if (lpfc_error_lost_link(irsp
))
1904 rc
= NLP_STE_FREED_NODE
;
1906 rc
= lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
1907 NLP_EVT_CMPL_PLOGI
);
1909 /* Good status, call state machine */
1910 prsp
= list_entry(((struct lpfc_dmabuf
*)
1911 cmdiocb
->context2
)->list
.next
,
1912 struct lpfc_dmabuf
, list
);
1913 ndlp
= lpfc_plogi_confirm_nport(phba
, prsp
->virt
, ndlp
);
1914 rc
= lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
1915 NLP_EVT_CMPL_PLOGI
);
1918 if (disc
&& vport
->num_disc_nodes
) {
1919 /* Check to see if there are more PLOGIs to be sent */
1920 lpfc_more_plogi(vport
);
1922 if (vport
->num_disc_nodes
== 0) {
1923 spin_lock_irq(shost
->host_lock
);
1924 vport
->fc_flag
&= ~FC_NDISC_ACTIVE
;
1925 spin_unlock_irq(shost
->host_lock
);
1927 lpfc_can_disctmo(vport
);
1928 lpfc_end_rscn(vport
);
1933 lpfc_els_free_iocb(phba
, cmdiocb
);
1938 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
1939 * @vport: pointer to a host virtual N_Port data structure.
1940 * @did: destination port identifier.
1941 * @retry: number of retries to the command IOCB.
1943 * This routine issues a Port Login (PLOGI) command to a remote N_Port
1944 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
1945 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
1946 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
1947 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
1949 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1950 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1951 * will be stored into the context1 field of the IOCB for the completion
1952 * callback function to the PLOGI ELS command.
1955 * 0 - Successfully issued a plogi for @vport
1956 * 1 - failed to issue a plogi for @vport
1959 lpfc_issue_els_plogi(struct lpfc_vport
*vport
, uint32_t did
, uint8_t retry
)
1961 struct lpfc_hba
*phba
= vport
->phba
;
1962 struct serv_parm
*sp
;
1963 struct lpfc_nodelist
*ndlp
;
1964 struct lpfc_iocbq
*elsiocb
;
1969 ndlp
= lpfc_findnode_did(vport
, did
);
1970 if (ndlp
&& !NLP_CHK_NODE_ACT(ndlp
))
1973 /* If ndlp is not NULL, we will bump the reference count on it */
1974 cmdsize
= (sizeof(uint32_t) + sizeof(struct serv_parm
));
1975 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
, did
,
1980 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
1982 /* For PLOGI request, remainder of payload is service parameters */
1983 *((uint32_t *) (pcmd
)) = ELS_CMD_PLOGI
;
1984 pcmd
+= sizeof(uint32_t);
1985 memcpy(pcmd
, &vport
->fc_sparam
, sizeof(struct serv_parm
));
1986 sp
= (struct serv_parm
*) pcmd
;
1989 * If we are a N-port connected to a Fabric, fix-up paramm's so logins
1990 * to device on remote loops work.
1992 if ((vport
->fc_flag
& FC_FABRIC
) && !(vport
->fc_flag
& FC_PUBLIC_LOOP
))
1993 sp
->cmn
.altBbCredit
= 1;
1995 if (sp
->cmn
.fcphLow
< FC_PH_4_3
)
1996 sp
->cmn
.fcphLow
= FC_PH_4_3
;
1998 if (sp
->cmn
.fcphHigh
< FC_PH3
)
1999 sp
->cmn
.fcphHigh
= FC_PH3
;
2001 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2002 "Issue PLOGI: did:x%x",
2005 phba
->fc_stat
.elsXmitPLOGI
++;
2006 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_plogi
;
2007 ret
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
2009 if (ret
== IOCB_ERROR
) {
2010 lpfc_els_free_iocb(phba
, elsiocb
);
2017 * lpfc_cmpl_els_prli - Completion callback function for prli
2018 * @phba: pointer to lpfc hba data structure.
2019 * @cmdiocb: pointer to lpfc command iocb data structure.
2020 * @rspiocb: pointer to lpfc response iocb data structure.
2022 * This routine is the completion callback function for a Process Login
2023 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
2024 * status. If there is error status reported, PRLI retry shall be attempted
2025 * by invoking the lpfc_els_retry() routine. Otherwise, the state
2026 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
2027 * ndlp to mark the PRLI completion.
2030 lpfc_cmpl_els_prli(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
2031 struct lpfc_iocbq
*rspiocb
)
2033 struct lpfc_vport
*vport
= cmdiocb
->vport
;
2034 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2036 struct lpfc_nodelist
*ndlp
;
2038 /* we pass cmdiocb to state machine which needs rspiocb as well */
2039 cmdiocb
->context_un
.rsp_iocb
= rspiocb
;
2041 irsp
= &(rspiocb
->iocb
);
2042 ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
2043 spin_lock_irq(shost
->host_lock
);
2044 ndlp
->nlp_flag
&= ~NLP_PRLI_SND
;
2045 spin_unlock_irq(shost
->host_lock
);
2047 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2048 "PRLI cmpl: status:x%x/x%x did:x%x",
2049 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
2051 /* PRLI completes to NPort <nlp_DID> */
2052 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
2053 "0103 PRLI completes to NPort x%x "
2054 "Data: x%x x%x x%x x%x\n",
2055 ndlp
->nlp_DID
, irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
2056 irsp
->ulpTimeout
, vport
->num_disc_nodes
);
2058 vport
->fc_prli_sent
--;
2059 /* Check to see if link went down during discovery */
2060 if (lpfc_els_chk_latt(vport
))
2063 if (irsp
->ulpStatus
) {
2064 /* Check for retry */
2065 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
)) {
2066 /* ELS command is being retried */
2070 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
2071 "2754 PRLI failure DID:%06X Status:x%x/x%x\n",
2072 ndlp
->nlp_DID
, irsp
->ulpStatus
,
2073 irsp
->un
.ulpWord
[4]);
2074 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2075 if (lpfc_error_lost_link(irsp
))
2078 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
2081 /* Good status, call state machine */
2082 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
2085 lpfc_els_free_iocb(phba
, cmdiocb
);
2090 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
2091 * @vport: pointer to a host virtual N_Port data structure.
2092 * @ndlp: pointer to a node-list data structure.
2093 * @retry: number of retries to the command IOCB.
2095 * This routine issues a Process Login (PRLI) ELS command for the
2096 * @vport. The PRLI service parameters are set up in the payload of the
2097 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
2098 * is put to the IOCB completion callback func field before invoking the
2099 * routine lpfc_sli_issue_iocb() to send out PRLI command.
2101 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2102 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2103 * will be stored into the context1 field of the IOCB for the completion
2104 * callback function to the PRLI ELS command.
2107 * 0 - successfully issued prli iocb command for @vport
2108 * 1 - failed to issue prli iocb command for @vport
2111 lpfc_issue_els_prli(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2114 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2115 struct lpfc_hba
*phba
= vport
->phba
;
2117 struct lpfc_iocbq
*elsiocb
;
2121 cmdsize
= (sizeof(uint32_t) + sizeof(PRLI
));
2122 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
2123 ndlp
->nlp_DID
, ELS_CMD_PRLI
);
2127 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
2129 /* For PRLI request, remainder of payload is service parameters */
2130 memset(pcmd
, 0, (sizeof(PRLI
) + sizeof(uint32_t)));
2131 *((uint32_t *) (pcmd
)) = ELS_CMD_PRLI
;
2132 pcmd
+= sizeof(uint32_t);
2134 /* For PRLI, remainder of payload is PRLI parameter page */
2135 npr
= (PRLI
*) pcmd
;
2137 * If our firmware version is 3.20 or later,
2138 * set the following bits for FC-TAPE support.
2140 if (phba
->vpd
.rev
.feaLevelHigh
>= 0x02) {
2141 npr
->ConfmComplAllowed
= 1;
2143 npr
->TaskRetryIdReq
= 1;
2145 npr
->estabImagePair
= 1;
2146 npr
->readXferRdyDis
= 1;
2147 if (vport
->cfg_first_burst_size
)
2148 npr
->writeXferRdyDis
= 1;
2150 /* For FCP support */
2151 npr
->prliType
= PRLI_FCP_TYPE
;
2152 npr
->initiatorFunc
= 1;
2154 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2155 "Issue PRLI: did:x%x",
2156 ndlp
->nlp_DID
, 0, 0);
2158 phba
->fc_stat
.elsXmitPRLI
++;
2159 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_prli
;
2160 spin_lock_irq(shost
->host_lock
);
2161 ndlp
->nlp_flag
|= NLP_PRLI_SND
;
2162 spin_unlock_irq(shost
->host_lock
);
2163 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) ==
2165 spin_lock_irq(shost
->host_lock
);
2166 ndlp
->nlp_flag
&= ~NLP_PRLI_SND
;
2167 spin_unlock_irq(shost
->host_lock
);
2168 lpfc_els_free_iocb(phba
, elsiocb
);
2171 vport
->fc_prli_sent
++;
2176 * lpfc_rscn_disc - Perform rscn discovery for a vport
2177 * @vport: pointer to a host virtual N_Port data structure.
2179 * This routine performs Registration State Change Notification (RSCN)
2180 * discovery for a @vport. If the @vport's node port recovery count is not
2181 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
2182 * the nodes that need recovery. If none of the PLOGI were needed through
2183 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
2184 * invoked to check and handle possible more RSCN came in during the period
2185 * of processing the current ones.
2188 lpfc_rscn_disc(struct lpfc_vport
*vport
)
2190 lpfc_can_disctmo(vport
);
2192 /* RSCN discovery */
2193 /* go thru NPR nodes and issue ELS PLOGIs */
2194 if (vport
->fc_npr_cnt
)
2195 if (lpfc_els_disc_plogi(vport
))
2198 lpfc_end_rscn(vport
);
2202 * lpfc_adisc_done - Complete the adisc phase of discovery
2203 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
2205 * This function is called when the final ADISC is completed during discovery.
2206 * This function handles clearing link attention or issuing reg_vpi depending
2207 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
2209 * This function is called with no locks held.
2212 lpfc_adisc_done(struct lpfc_vport
*vport
)
2214 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2215 struct lpfc_hba
*phba
= vport
->phba
;
2218 * For NPIV, cmpl_reg_vpi will set port_state to READY,
2219 * and continue discovery.
2221 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
2222 !(vport
->fc_flag
& FC_RSCN_MODE
) &&
2223 (phba
->sli_rev
< LPFC_SLI_REV4
)) {
2224 /* The ADISCs are complete. Doesn't matter if they
2225 * succeeded or failed because the ADISC completion
2226 * routine guarantees to call the state machine and
2227 * the RPI is either unregistered (failed ADISC response)
2228 * or the RPI is still valid and the node is marked
2229 * mapped for a target. The exchanges should be in the
2230 * correct state. This code is specific to SLI3.
2232 lpfc_issue_clear_la(phba
, vport
);
2233 lpfc_issue_reg_vpi(phba
, vport
);
2237 * For SLI2, we need to set port_state to READY
2238 * and continue discovery.
2240 if (vport
->port_state
< LPFC_VPORT_READY
) {
2241 /* If we get here, there is nothing to ADISC */
2242 lpfc_issue_clear_la(phba
, vport
);
2243 if (!(vport
->fc_flag
& FC_ABORT_DISCOVERY
)) {
2244 vport
->num_disc_nodes
= 0;
2245 /* go thru NPR list, issue ELS PLOGIs */
2246 if (vport
->fc_npr_cnt
)
2247 lpfc_els_disc_plogi(vport
);
2248 if (!vport
->num_disc_nodes
) {
2249 spin_lock_irq(shost
->host_lock
);
2250 vport
->fc_flag
&= ~FC_NDISC_ACTIVE
;
2251 spin_unlock_irq(shost
->host_lock
);
2252 lpfc_can_disctmo(vport
);
2253 lpfc_end_rscn(vport
);
2256 vport
->port_state
= LPFC_VPORT_READY
;
2258 lpfc_rscn_disc(vport
);
2262 * lpfc_more_adisc - Issue more adisc as needed
2263 * @vport: pointer to a host virtual N_Port data structure.
2265 * This routine determines whether there are more ndlps on a @vport
2266 * node list need to have Address Discover (ADISC) issued. If so, it will
2267 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
2268 * remaining nodes which need to have ADISC sent.
2271 lpfc_more_adisc(struct lpfc_vport
*vport
)
2273 if (vport
->num_disc_nodes
)
2274 vport
->num_disc_nodes
--;
2275 /* Continue discovery with <num_disc_nodes> ADISCs to go */
2276 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
2277 "0210 Continue discovery with %d ADISCs to go "
2278 "Data: x%x x%x x%x\n",
2279 vport
->num_disc_nodes
, vport
->fc_adisc_cnt
,
2280 vport
->fc_flag
, vport
->port_state
);
2281 /* Check to see if there are more ADISCs to be sent */
2282 if (vport
->fc_flag
& FC_NLP_MORE
) {
2283 lpfc_set_disctmo(vport
);
2284 /* go thru NPR nodes and issue any remaining ELS ADISCs */
2285 lpfc_els_disc_adisc(vport
);
2287 if (!vport
->num_disc_nodes
)
2288 lpfc_adisc_done(vport
);
2293 * lpfc_cmpl_els_adisc - Completion callback function for adisc
2294 * @phba: pointer to lpfc hba data structure.
2295 * @cmdiocb: pointer to lpfc command iocb data structure.
2296 * @rspiocb: pointer to lpfc response iocb data structure.
2298 * This routine is the completion function for issuing the Address Discover
2299 * (ADISC) command. It first checks to see whether link went down during
2300 * the discovery process. If so, the node will be marked as node port
2301 * recovery for issuing discover IOCB by the link attention handler and
2302 * exit. Otherwise, the response status is checked. If error was reported
2303 * in the response status, the ADISC command shall be retried by invoking
2304 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
2305 * the response status, the state machine is invoked to set transition
2306 * with respect to NLP_EVT_CMPL_ADISC event.
2309 lpfc_cmpl_els_adisc(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
2310 struct lpfc_iocbq
*rspiocb
)
2312 struct lpfc_vport
*vport
= cmdiocb
->vport
;
2313 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2315 struct lpfc_nodelist
*ndlp
;
2318 /* we pass cmdiocb to state machine which needs rspiocb as well */
2319 cmdiocb
->context_un
.rsp_iocb
= rspiocb
;
2321 irsp
= &(rspiocb
->iocb
);
2322 ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
2324 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2325 "ADISC cmpl: status:x%x/x%x did:x%x",
2326 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
2329 /* Since ndlp can be freed in the disc state machine, note if this node
2330 * is being used during discovery.
2332 spin_lock_irq(shost
->host_lock
);
2333 disc
= (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
);
2334 ndlp
->nlp_flag
&= ~(NLP_ADISC_SND
| NLP_NPR_2B_DISC
);
2335 spin_unlock_irq(shost
->host_lock
);
2336 /* ADISC completes to NPort <nlp_DID> */
2337 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
2338 "0104 ADISC completes to NPort x%x "
2339 "Data: x%x x%x x%x x%x x%x\n",
2340 ndlp
->nlp_DID
, irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
2341 irsp
->ulpTimeout
, disc
, vport
->num_disc_nodes
);
2342 /* Check to see if link went down during discovery */
2343 if (lpfc_els_chk_latt(vport
)) {
2344 spin_lock_irq(shost
->host_lock
);
2345 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
2346 spin_unlock_irq(shost
->host_lock
);
2350 if (irsp
->ulpStatus
) {
2351 /* Check for retry */
2352 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
)) {
2353 /* ELS command is being retried */
2355 spin_lock_irq(shost
->host_lock
);
2356 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
2357 spin_unlock_irq(shost
->host_lock
);
2358 lpfc_set_disctmo(vport
);
2363 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
2364 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
2365 ndlp
->nlp_DID
, irsp
->ulpStatus
,
2366 irsp
->un
.ulpWord
[4]);
2367 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2368 if (!lpfc_error_lost_link(irsp
))
2369 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
2370 NLP_EVT_CMPL_ADISC
);
2372 /* Good status, call state machine */
2373 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
2374 NLP_EVT_CMPL_ADISC
);
2376 /* Check to see if there are more ADISCs to be sent */
2377 if (disc
&& vport
->num_disc_nodes
)
2378 lpfc_more_adisc(vport
);
2380 lpfc_els_free_iocb(phba
, cmdiocb
);
2385 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
2386 * @vport: pointer to a virtual N_Port data structure.
2387 * @ndlp: pointer to a node-list data structure.
2388 * @retry: number of retries to the command IOCB.
2390 * This routine issues an Address Discover (ADISC) for an @ndlp on a
2391 * @vport. It prepares the payload of the ADISC ELS command, updates the
2392 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
2393 * to issue the ADISC ELS command.
2395 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2396 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2397 * will be stored into the context1 field of the IOCB for the completion
2398 * callback function to the ADISC ELS command.
2401 * 0 - successfully issued adisc
2402 * 1 - failed to issue adisc
2405 lpfc_issue_els_adisc(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2408 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2409 struct lpfc_hba
*phba
= vport
->phba
;
2411 struct lpfc_iocbq
*elsiocb
;
2415 cmdsize
= (sizeof(uint32_t) + sizeof(ADISC
));
2416 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
2417 ndlp
->nlp_DID
, ELS_CMD_ADISC
);
2421 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
2423 /* For ADISC request, remainder of payload is service parameters */
2424 *((uint32_t *) (pcmd
)) = ELS_CMD_ADISC
;
2425 pcmd
+= sizeof(uint32_t);
2427 /* Fill in ADISC payload */
2428 ap
= (ADISC
*) pcmd
;
2429 ap
->hardAL_PA
= phba
->fc_pref_ALPA
;
2430 memcpy(&ap
->portName
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
2431 memcpy(&ap
->nodeName
, &vport
->fc_nodename
, sizeof(struct lpfc_name
));
2432 ap
->DID
= be32_to_cpu(vport
->fc_myDID
);
2434 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2435 "Issue ADISC: did:x%x",
2436 ndlp
->nlp_DID
, 0, 0);
2438 phba
->fc_stat
.elsXmitADISC
++;
2439 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_adisc
;
2440 spin_lock_irq(shost
->host_lock
);
2441 ndlp
->nlp_flag
|= NLP_ADISC_SND
;
2442 spin_unlock_irq(shost
->host_lock
);
2443 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) ==
2445 spin_lock_irq(shost
->host_lock
);
2446 ndlp
->nlp_flag
&= ~NLP_ADISC_SND
;
2447 spin_unlock_irq(shost
->host_lock
);
2448 lpfc_els_free_iocb(phba
, elsiocb
);
2455 * lpfc_cmpl_els_logo - Completion callback function for logo
2456 * @phba: pointer to lpfc hba data structure.
2457 * @cmdiocb: pointer to lpfc command iocb data structure.
2458 * @rspiocb: pointer to lpfc response iocb data structure.
2460 * This routine is the completion function for issuing the ELS Logout (LOGO)
2461 * command. If no error status was reported from the LOGO response, the
2462 * state machine of the associated ndlp shall be invoked for transition with
2463 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
2464 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
2467 lpfc_cmpl_els_logo(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
2468 struct lpfc_iocbq
*rspiocb
)
2470 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
2471 struct lpfc_vport
*vport
= ndlp
->vport
;
2472 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2474 struct lpfcMboxq
*mbox
;
2475 unsigned long flags
;
2476 uint32_t skip_recovery
= 0;
2478 /* we pass cmdiocb to state machine which needs rspiocb as well */
2479 cmdiocb
->context_un
.rsp_iocb
= rspiocb
;
2481 irsp
= &(rspiocb
->iocb
);
2482 spin_lock_irq(shost
->host_lock
);
2483 ndlp
->nlp_flag
&= ~NLP_LOGO_SND
;
2484 spin_unlock_irq(shost
->host_lock
);
2486 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2487 "LOGO cmpl: status:x%x/x%x did:x%x",
2488 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
2491 /* LOGO completes to NPort <nlp_DID> */
2492 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
2493 "0105 LOGO completes to NPort x%x "
2494 "Data: x%x x%x x%x x%x\n",
2495 ndlp
->nlp_DID
, irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
2496 irsp
->ulpTimeout
, vport
->num_disc_nodes
);
2498 if (lpfc_els_chk_latt(vport
)) {
2503 /* Check to see if link went down during discovery */
2504 if (ndlp
->nlp_flag
& NLP_TARGET_REMOVE
) {
2505 /* NLP_EVT_DEVICE_RM should unregister the RPI
2506 * which should abort all outstanding IOs.
2508 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
2514 if (irsp
->ulpStatus
) {
2515 /* Check for retry */
2516 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
)) {
2517 /* ELS command is being retried */
2522 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
2523 "2756 LOGO failure DID:%06X Status:x%x/x%x\n",
2524 ndlp
->nlp_DID
, irsp
->ulpStatus
,
2525 irsp
->un
.ulpWord
[4]);
2526 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2527 if (lpfc_error_lost_link(irsp
)) {
2533 /* Call state machine. This will unregister the rpi if needed. */
2534 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
, NLP_EVT_CMPL_LOGO
);
2537 lpfc_els_free_iocb(phba
, cmdiocb
);
2538 /* If we are in pt2pt mode, we could rcv new S_ID on PLOGI */
2539 if ((vport
->fc_flag
& FC_PT2PT
) &&
2540 !(vport
->fc_flag
& FC_PT2PT_PLOGI
)) {
2541 phba
->pport
->fc_myDID
= 0;
2542 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
2544 lpfc_config_link(phba
, mbox
);
2545 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
2546 mbox
->vport
= vport
;
2547 if (lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
) ==
2549 mempool_free(mbox
, phba
->mbox_mem_pool
);
2556 * If the node is a target, the handling attempts to recover the port.
2557 * For any other port type, the rpi is unregistered as an implicit
2560 if ((ndlp
->nlp_type
& NLP_FCP_TARGET
) && (skip_recovery
== 0)) {
2561 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
2562 spin_lock_irqsave(shost
->host_lock
, flags
);
2563 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
2564 spin_unlock_irqrestore(shost
->host_lock
, flags
);
2566 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
2567 "3187 LOGO completes to NPort x%x: Start "
2568 "Recovery Data: x%x x%x x%x x%x\n",
2569 ndlp
->nlp_DID
, irsp
->ulpStatus
,
2570 irsp
->un
.ulpWord
[4], irsp
->ulpTimeout
,
2571 vport
->num_disc_nodes
);
2572 lpfc_disc_start(vport
);
2578 * lpfc_issue_els_logo - Issue a logo to an node on a vport
2579 * @vport: pointer to a virtual N_Port data structure.
2580 * @ndlp: pointer to a node-list data structure.
2581 * @retry: number of retries to the command IOCB.
2583 * This routine constructs and issues an ELS Logout (LOGO) iocb command
2584 * to a remote node, referred by an @ndlp on a @vport. It constructs the
2585 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2586 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2588 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2589 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2590 * will be stored into the context1 field of the IOCB for the completion
2591 * callback function to the LOGO ELS command.
2594 * 0 - successfully issued logo
2595 * 1 - failed to issue logo
2598 lpfc_issue_els_logo(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2601 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2602 struct lpfc_hba
*phba
= vport
->phba
;
2603 struct lpfc_iocbq
*elsiocb
;
2608 spin_lock_irq(shost
->host_lock
);
2609 if (ndlp
->nlp_flag
& NLP_LOGO_SND
) {
2610 spin_unlock_irq(shost
->host_lock
);
2613 spin_unlock_irq(shost
->host_lock
);
2615 cmdsize
= (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name
);
2616 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
2617 ndlp
->nlp_DID
, ELS_CMD_LOGO
);
2621 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
2622 *((uint32_t *) (pcmd
)) = ELS_CMD_LOGO
;
2623 pcmd
+= sizeof(uint32_t);
2625 /* Fill in LOGO payload */
2626 *((uint32_t *) (pcmd
)) = be32_to_cpu(vport
->fc_myDID
);
2627 pcmd
+= sizeof(uint32_t);
2628 memcpy(pcmd
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
2630 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2631 "Issue LOGO: did:x%x",
2632 ndlp
->nlp_DID
, 0, 0);
2635 * If we are issuing a LOGO, we may try to recover the remote NPort
2636 * by issuing a PLOGI later. Even though we issue ELS cmds by the
2637 * VPI, if we have a valid RPI, and that RPI gets unreg'ed while
2638 * that ELS command is in-flight, the HBA returns a IOERR_INVALID_RPI
2639 * for that ELS cmd. To avoid this situation, lets get rid of the
2640 * RPI right now, before any ELS cmds are sent.
2642 spin_lock_irq(shost
->host_lock
);
2643 ndlp
->nlp_flag
|= NLP_ISSUE_LOGO
;
2644 spin_unlock_irq(shost
->host_lock
);
2645 if (lpfc_unreg_rpi(vport
, ndlp
)) {
2646 lpfc_els_free_iocb(phba
, elsiocb
);
2650 phba
->fc_stat
.elsXmitLOGO
++;
2651 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_logo
;
2652 spin_lock_irq(shost
->host_lock
);
2653 ndlp
->nlp_flag
|= NLP_LOGO_SND
;
2654 ndlp
->nlp_flag
&= ~NLP_ISSUE_LOGO
;
2655 spin_unlock_irq(shost
->host_lock
);
2656 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
2658 if (rc
== IOCB_ERROR
) {
2659 spin_lock_irq(shost
->host_lock
);
2660 ndlp
->nlp_flag
&= ~NLP_LOGO_SND
;
2661 spin_unlock_irq(shost
->host_lock
);
2662 lpfc_els_free_iocb(phba
, elsiocb
);
2669 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
2670 * @phba: pointer to lpfc hba data structure.
2671 * @cmdiocb: pointer to lpfc command iocb data structure.
2672 * @rspiocb: pointer to lpfc response iocb data structure.
2674 * This routine is a generic completion callback function for ELS commands.
2675 * Specifically, it is the callback function which does not need to perform
2676 * any command specific operations. It is currently used by the ELS command
2677 * issuing routines for the ELS State Change Request (SCR),
2678 * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
2679 * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
2680 * certain debug loggings, this callback function simply invokes the
2681 * lpfc_els_chk_latt() routine to check whether link went down during the
2682 * discovery process.
2685 lpfc_cmpl_els_cmd(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
2686 struct lpfc_iocbq
*rspiocb
)
2688 struct lpfc_vport
*vport
= cmdiocb
->vport
;
2691 irsp
= &rspiocb
->iocb
;
2693 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2694 "ELS cmd cmpl: status:x%x/x%x did:x%x",
2695 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
2696 irsp
->un
.elsreq64
.remoteID
);
2697 /* ELS cmd tag <ulpIoTag> completes */
2698 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
2699 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
2700 irsp
->ulpIoTag
, irsp
->ulpStatus
,
2701 irsp
->un
.ulpWord
[4], irsp
->ulpTimeout
);
2702 /* Check to see if link went down during discovery */
2703 lpfc_els_chk_latt(vport
);
2704 lpfc_els_free_iocb(phba
, cmdiocb
);
2709 * lpfc_issue_els_scr - Issue a scr to an node on a vport
2710 * @vport: pointer to a host virtual N_Port data structure.
2711 * @nportid: N_Port identifier to the remote node.
2712 * @retry: number of retries to the command IOCB.
2714 * This routine issues a State Change Request (SCR) to a fabric node
2715 * on a @vport. The remote node @nportid is passed into the function. It
2716 * first search the @vport node list to find the matching ndlp. If no such
2717 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
2718 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
2719 * routine is invoked to send the SCR IOCB.
2721 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2722 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2723 * will be stored into the context1 field of the IOCB for the completion
2724 * callback function to the SCR ELS command.
2727 * 0 - Successfully issued scr command
2728 * 1 - Failed to issue scr command
2731 lpfc_issue_els_scr(struct lpfc_vport
*vport
, uint32_t nportid
, uint8_t retry
)
2733 struct lpfc_hba
*phba
= vport
->phba
;
2734 struct lpfc_iocbq
*elsiocb
;
2737 struct lpfc_nodelist
*ndlp
;
2739 cmdsize
= (sizeof(uint32_t) + sizeof(SCR
));
2741 ndlp
= lpfc_findnode_did(vport
, nportid
);
2743 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
2746 lpfc_nlp_init(vport
, ndlp
, nportid
);
2747 lpfc_enqueue_node(vport
, ndlp
);
2748 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
2749 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
2754 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
2755 ndlp
->nlp_DID
, ELS_CMD_SCR
);
2758 /* This will trigger the release of the node just
2765 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
2767 *((uint32_t *) (pcmd
)) = ELS_CMD_SCR
;
2768 pcmd
+= sizeof(uint32_t);
2770 /* For SCR, remainder of payload is SCR parameter page */
2771 memset(pcmd
, 0, sizeof(SCR
));
2772 ((SCR
*) pcmd
)->Function
= SCR_FUNC_FULL
;
2774 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2775 "Issue SCR: did:x%x",
2776 ndlp
->nlp_DID
, 0, 0);
2778 phba
->fc_stat
.elsXmitSCR
++;
2779 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_cmd
;
2780 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) ==
2782 /* The additional lpfc_nlp_put will cause the following
2783 * lpfc_els_free_iocb routine to trigger the rlease of
2787 lpfc_els_free_iocb(phba
, elsiocb
);
2790 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2791 * trigger the release of node.
2799 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
2800 * @vport: pointer to a host virtual N_Port data structure.
2801 * @nportid: N_Port identifier to the remote node.
2802 * @retry: number of retries to the command IOCB.
2804 * This routine issues a Fibre Channel Address Resolution Response
2805 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
2806 * is passed into the function. It first search the @vport node list to find
2807 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
2808 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
2809 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
2811 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2812 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2813 * will be stored into the context1 field of the IOCB for the completion
2814 * callback function to the PARPR ELS command.
2817 * 0 - Successfully issued farpr command
2818 * 1 - Failed to issue farpr command
2821 lpfc_issue_els_farpr(struct lpfc_vport
*vport
, uint32_t nportid
, uint8_t retry
)
2823 struct lpfc_hba
*phba
= vport
->phba
;
2824 struct lpfc_iocbq
*elsiocb
;
2829 struct lpfc_nodelist
*ondlp
;
2830 struct lpfc_nodelist
*ndlp
;
2832 cmdsize
= (sizeof(uint32_t) + sizeof(FARP
));
2834 ndlp
= lpfc_findnode_did(vport
, nportid
);
2836 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
2839 lpfc_nlp_init(vport
, ndlp
, nportid
);
2840 lpfc_enqueue_node(vport
, ndlp
);
2841 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
2842 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
2847 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
2848 ndlp
->nlp_DID
, ELS_CMD_RNID
);
2850 /* This will trigger the release of the node just
2857 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
2859 *((uint32_t *) (pcmd
)) = ELS_CMD_FARPR
;
2860 pcmd
+= sizeof(uint32_t);
2862 /* Fill in FARPR payload */
2863 fp
= (FARP
*) (pcmd
);
2864 memset(fp
, 0, sizeof(FARP
));
2865 lp
= (uint32_t *) pcmd
;
2866 *lp
++ = be32_to_cpu(nportid
);
2867 *lp
++ = be32_to_cpu(vport
->fc_myDID
);
2869 fp
->Mflags
= (FARP_MATCH_PORT
| FARP_MATCH_NODE
);
2871 memcpy(&fp
->RportName
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
2872 memcpy(&fp
->RnodeName
, &vport
->fc_nodename
, sizeof(struct lpfc_name
));
2873 ondlp
= lpfc_findnode_did(vport
, nportid
);
2874 if (ondlp
&& NLP_CHK_NODE_ACT(ondlp
)) {
2875 memcpy(&fp
->OportName
, &ondlp
->nlp_portname
,
2876 sizeof(struct lpfc_name
));
2877 memcpy(&fp
->OnodeName
, &ondlp
->nlp_nodename
,
2878 sizeof(struct lpfc_name
));
2881 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2882 "Issue FARPR: did:x%x",
2883 ndlp
->nlp_DID
, 0, 0);
2885 phba
->fc_stat
.elsXmitFARPR
++;
2886 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_cmd
;
2887 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) ==
2889 /* The additional lpfc_nlp_put will cause the following
2890 * lpfc_els_free_iocb routine to trigger the release of
2894 lpfc_els_free_iocb(phba
, elsiocb
);
2897 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2898 * trigger the release of the node.
2905 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
2906 * @vport: pointer to a host virtual N_Port data structure.
2907 * @nlp: pointer to a node-list data structure.
2909 * This routine cancels the timer with a delayed IOCB-command retry for
2910 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
2911 * removes the ELS retry event if it presents. In addition, if the
2912 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
2913 * commands are sent for the @vport's nodes that require issuing discovery
2917 lpfc_cancel_retry_delay_tmo(struct lpfc_vport
*vport
, struct lpfc_nodelist
*nlp
)
2919 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2920 struct lpfc_work_evt
*evtp
;
2922 if (!(nlp
->nlp_flag
& NLP_DELAY_TMO
))
2924 spin_lock_irq(shost
->host_lock
);
2925 nlp
->nlp_flag
&= ~NLP_DELAY_TMO
;
2926 spin_unlock_irq(shost
->host_lock
);
2927 del_timer_sync(&nlp
->nlp_delayfunc
);
2928 nlp
->nlp_last_elscmd
= 0;
2929 if (!list_empty(&nlp
->els_retry_evt
.evt_listp
)) {
2930 list_del_init(&nlp
->els_retry_evt
.evt_listp
);
2931 /* Decrement nlp reference count held for the delayed retry */
2932 evtp
= &nlp
->els_retry_evt
;
2933 lpfc_nlp_put((struct lpfc_nodelist
*)evtp
->evt_arg1
);
2935 if (nlp
->nlp_flag
& NLP_NPR_2B_DISC
) {
2936 spin_lock_irq(shost
->host_lock
);
2937 nlp
->nlp_flag
&= ~NLP_NPR_2B_DISC
;
2938 spin_unlock_irq(shost
->host_lock
);
2939 if (vport
->num_disc_nodes
) {
2940 if (vport
->port_state
< LPFC_VPORT_READY
) {
2941 /* Check if there are more ADISCs to be sent */
2942 lpfc_more_adisc(vport
);
2944 /* Check if there are more PLOGIs to be sent */
2945 lpfc_more_plogi(vport
);
2946 if (vport
->num_disc_nodes
== 0) {
2947 spin_lock_irq(shost
->host_lock
);
2948 vport
->fc_flag
&= ~FC_NDISC_ACTIVE
;
2949 spin_unlock_irq(shost
->host_lock
);
2950 lpfc_can_disctmo(vport
);
2951 lpfc_end_rscn(vport
);
2960 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
2961 * @ptr: holder for the pointer to the timer function associated data (ndlp).
2963 * This routine is invoked by the ndlp delayed-function timer to check
2964 * whether there is any pending ELS retry event(s) with the node. If not, it
2965 * simply returns. Otherwise, if there is at least one ELS delayed event, it
2966 * adds the delayed events to the HBA work list and invokes the
2967 * lpfc_worker_wake_up() routine to wake up worker thread to process the
2968 * event. Note that lpfc_nlp_get() is called before posting the event to
2969 * the work list to hold reference count of ndlp so that it guarantees the
2970 * reference to ndlp will still be available when the worker thread gets
2971 * to the event associated with the ndlp.
2974 lpfc_els_retry_delay(unsigned long ptr
)
2976 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) ptr
;
2977 struct lpfc_vport
*vport
= ndlp
->vport
;
2978 struct lpfc_hba
*phba
= vport
->phba
;
2979 unsigned long flags
;
2980 struct lpfc_work_evt
*evtp
= &ndlp
->els_retry_evt
;
2982 spin_lock_irqsave(&phba
->hbalock
, flags
);
2983 if (!list_empty(&evtp
->evt_listp
)) {
2984 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
2988 /* We need to hold the node by incrementing the reference
2989 * count until the queued work is done
2991 evtp
->evt_arg1
= lpfc_nlp_get(ndlp
);
2992 if (evtp
->evt_arg1
) {
2993 evtp
->evt
= LPFC_EVT_ELS_RETRY
;
2994 list_add_tail(&evtp
->evt_listp
, &phba
->work_list
);
2995 lpfc_worker_wake_up(phba
);
2997 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
3002 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
3003 * @ndlp: pointer to a node-list data structure.
3005 * This routine is the worker-thread handler for processing the @ndlp delayed
3006 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
3007 * the last ELS command from the associated ndlp and invokes the proper ELS
3008 * function according to the delayed ELS command to retry the command.
3011 lpfc_els_retry_delay_handler(struct lpfc_nodelist
*ndlp
)
3013 struct lpfc_vport
*vport
= ndlp
->vport
;
3014 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3015 uint32_t cmd
, retry
;
3017 spin_lock_irq(shost
->host_lock
);
3018 cmd
= ndlp
->nlp_last_elscmd
;
3019 ndlp
->nlp_last_elscmd
= 0;
3021 if (!(ndlp
->nlp_flag
& NLP_DELAY_TMO
)) {
3022 spin_unlock_irq(shost
->host_lock
);
3026 ndlp
->nlp_flag
&= ~NLP_DELAY_TMO
;
3027 spin_unlock_irq(shost
->host_lock
);
3029 * If a discovery event readded nlp_delayfunc after timer
3030 * firing and before processing the timer, cancel the
3033 del_timer_sync(&ndlp
->nlp_delayfunc
);
3034 retry
= ndlp
->nlp_retry
;
3035 ndlp
->nlp_retry
= 0;
3039 lpfc_issue_els_flogi(vport
, ndlp
, retry
);
3042 if (!lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, retry
)) {
3043 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
3044 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
3048 if (!lpfc_issue_els_adisc(vport
, ndlp
, retry
)) {
3049 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
3050 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_ADISC_ISSUE
);
3054 if (!lpfc_issue_els_prli(vport
, ndlp
, retry
)) {
3055 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
3056 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PRLI_ISSUE
);
3060 if (!lpfc_issue_els_logo(vport
, ndlp
, retry
)) {
3061 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
3062 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_LOGO_ISSUE
);
3066 if (!(vport
->fc_flag
& FC_VPORT_NEEDS_INIT_VPI
))
3067 lpfc_issue_els_fdisc(vport
, ndlp
, retry
);
3074 * lpfc_els_retry - Make retry decision on an els command iocb
3075 * @phba: pointer to lpfc hba data structure.
3076 * @cmdiocb: pointer to lpfc command iocb data structure.
3077 * @rspiocb: pointer to lpfc response iocb data structure.
3079 * This routine makes a retry decision on an ELS command IOCB, which has
3080 * failed. The following ELS IOCBs use this function for retrying the command
3081 * when previously issued command responsed with error status: FLOGI, PLOGI,
3082 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
3083 * returned error status, it makes the decision whether a retry shall be
3084 * issued for the command, and whether a retry shall be made immediately or
3085 * delayed. In the former case, the corresponding ELS command issuing-function
3086 * is called to retry the command. In the later case, the ELS command shall
3087 * be posted to the ndlp delayed event and delayed function timer set to the
3088 * ndlp for the delayed command issusing.
3091 * 0 - No retry of els command is made
3092 * 1 - Immediate or delayed retry of els command is made
3095 lpfc_els_retry(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
3096 struct lpfc_iocbq
*rspiocb
)
3098 struct lpfc_vport
*vport
= cmdiocb
->vport
;
3099 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3100 IOCB_t
*irsp
= &rspiocb
->iocb
;
3101 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
3102 struct lpfc_dmabuf
*pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
3105 int retry
= 0, maxretry
= lpfc_max_els_tries
, delay
= 0;
3111 /* Note: context2 may be 0 for internal driver abort
3112 * of delays ELS command.
3115 if (pcmd
&& pcmd
->virt
) {
3116 elscmd
= (uint32_t *) (pcmd
->virt
);
3120 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
))
3121 did
= ndlp
->nlp_DID
;
3123 /* We should only hit this case for retrying PLOGI */
3124 did
= irsp
->un
.elsreq64
.remoteID
;
3125 ndlp
= lpfc_findnode_did(vport
, did
);
3126 if ((!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
))
3127 && (cmd
!= ELS_CMD_PLOGI
))
3131 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
3132 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
3133 *(((uint32_t *) irsp
) + 7), irsp
->un
.ulpWord
[4], ndlp
->nlp_DID
);
3135 switch (irsp
->ulpStatus
) {
3136 case IOSTAT_FCP_RSP_ERROR
:
3138 case IOSTAT_REMOTE_STOP
:
3139 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
3140 /* This IO was aborted by the target, we don't
3141 * know the rxid and because we did not send the
3142 * ABTS we cannot generate and RRQ.
3144 lpfc_set_rrq_active(phba
, ndlp
,
3145 cmdiocb
->sli4_lxritag
, 0, 0);
3148 case IOSTAT_LOCAL_REJECT
:
3149 switch ((irsp
->un
.ulpWord
[4] & IOERR_PARAM_MASK
)) {
3150 case IOERR_LOOP_OPEN_FAILURE
:
3151 if (cmd
== ELS_CMD_FLOGI
) {
3152 if (PCI_DEVICE_ID_HORNET
==
3153 phba
->pcidev
->device
) {
3154 phba
->fc_topology
= LPFC_TOPOLOGY_LOOP
;
3155 phba
->pport
->fc_myDID
= 0;
3156 phba
->alpa_map
[0] = 0;
3157 phba
->alpa_map
[1] = 0;
3160 if (cmd
== ELS_CMD_PLOGI
&& cmdiocb
->retry
== 0)
3165 case IOERR_ILLEGAL_COMMAND
:
3166 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
3167 "0124 Retry illegal cmd x%x "
3168 "retry:x%x delay:x%x\n",
3169 cmd
, cmdiocb
->retry
, delay
);
3171 /* All command's retry policy */
3173 if (cmdiocb
->retry
> 2)
3177 case IOERR_NO_RESOURCES
:
3178 logerr
= 1; /* HBA out of resources */
3180 if (cmdiocb
->retry
> 100)
3185 case IOERR_ILLEGAL_FRAME
:
3190 case IOERR_SEQUENCE_TIMEOUT
:
3191 case IOERR_INVALID_RPI
:
3192 if (cmd
== ELS_CMD_PLOGI
&&
3193 did
== NameServer_DID
) {
3194 /* Continue forever if plogi to */
3195 /* the nameserver fails */
3204 case IOSTAT_NPORT_RJT
:
3205 case IOSTAT_FABRIC_RJT
:
3206 if (irsp
->un
.ulpWord
[4] & RJT_UNAVAIL_TEMP
) {
3212 case IOSTAT_NPORT_BSY
:
3213 case IOSTAT_FABRIC_BSY
:
3214 logerr
= 1; /* Fabric / Remote NPort out of resources */
3219 stat
.un
.lsRjtError
= be32_to_cpu(irsp
->un
.ulpWord
[4]);
3220 /* Added for Vendor specifc support
3221 * Just keep retrying for these Rsn / Exp codes
3223 switch (stat
.un
.b
.lsRjtRsnCode
) {
3224 case LSRJT_UNABLE_TPC
:
3225 if (stat
.un
.b
.lsRjtRsnCodeExp
==
3226 LSEXP_CMD_IN_PROGRESS
) {
3227 if (cmd
== ELS_CMD_PLOGI
) {
3234 if (stat
.un
.b
.lsRjtRsnCodeExp
==
3235 LSEXP_CANT_GIVE_DATA
) {
3236 if (cmd
== ELS_CMD_PLOGI
) {
3243 if ((cmd
== ELS_CMD_PLOGI
) ||
3244 (cmd
== ELS_CMD_PRLI
)) {
3246 maxretry
= lpfc_max_els_tries
+ 1;
3250 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
3251 (cmd
== ELS_CMD_FDISC
) &&
3252 (stat
.un
.b
.lsRjtRsnCodeExp
== LSEXP_OUT_OF_RESOURCE
)){
3253 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
3254 "0125 FDISC Failed (x%x). "
3255 "Fabric out of resources\n",
3256 stat
.un
.lsRjtError
);
3257 lpfc_vport_set_state(vport
,
3258 FC_VPORT_NO_FABRIC_RSCS
);
3262 case LSRJT_LOGICAL_BSY
:
3263 if ((cmd
== ELS_CMD_PLOGI
) ||
3264 (cmd
== ELS_CMD_PRLI
)) {
3267 } else if (cmd
== ELS_CMD_FDISC
) {
3268 /* FDISC retry policy */
3270 if (cmdiocb
->retry
>= 32)
3276 case LSRJT_LOGICAL_ERR
:
3277 /* There are some cases where switches return this
3278 * error when they are not ready and should be returning
3279 * Logical Busy. We should delay every time.
3281 if (cmd
== ELS_CMD_FDISC
&&
3282 stat
.un
.b
.lsRjtRsnCodeExp
== LSEXP_PORT_LOGIN_REQ
) {
3288 case LSRJT_PROTOCOL_ERR
:
3289 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
3290 (cmd
== ELS_CMD_FDISC
) &&
3291 ((stat
.un
.b
.lsRjtRsnCodeExp
== LSEXP_INVALID_PNAME
) ||
3292 (stat
.un
.b
.lsRjtRsnCodeExp
== LSEXP_INVALID_NPORT_ID
))
3294 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
3295 "0122 FDISC Failed (x%x). "
3296 "Fabric Detected Bad WWN\n",
3297 stat
.un
.lsRjtError
);
3298 lpfc_vport_set_state(vport
,
3299 FC_VPORT_FABRIC_REJ_WWN
);
3305 case IOSTAT_INTERMED_RSP
:
3313 if (did
== FDMI_DID
)
3316 if ((cmd
== ELS_CMD_FLOGI
) &&
3317 (phba
->fc_topology
!= LPFC_TOPOLOGY_LOOP
) &&
3318 !lpfc_error_lost_link(irsp
)) {
3319 /* FLOGI retry policy */
3321 /* retry FLOGI forever */
3322 if (phba
->link_flag
!= LS_LOOPBACK_MODE
)
3327 if (cmdiocb
->retry
>= 100)
3329 else if (cmdiocb
->retry
>= 32)
3331 } else if ((cmd
== ELS_CMD_FDISC
) && !lpfc_error_lost_link(irsp
)) {
3332 /* retry FDISCs every second up to devloss */
3334 maxretry
= vport
->cfg_devloss_tmo
;
3339 if (maxretry
&& (cmdiocb
->retry
>= maxretry
)) {
3340 phba
->fc_stat
.elsRetryExceeded
++;
3344 if ((vport
->load_flag
& FC_UNLOADING
) != 0)
3348 if ((cmd
== ELS_CMD_PLOGI
) || (cmd
== ELS_CMD_FDISC
)) {
3349 /* Stop retrying PLOGI and FDISC if in FCF discovery */
3350 if (phba
->fcf
.fcf_flag
& FCF_DISCOVERY
) {
3351 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3352 "2849 Stop retry ELS command "
3353 "x%x to remote NPORT x%x, "
3354 "Data: x%x x%x\n", cmd
, did
,
3355 cmdiocb
->retry
, delay
);
3360 /* Retry ELS command <elsCmd> to remote NPORT <did> */
3361 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3362 "0107 Retry ELS command x%x to remote "
3363 "NPORT x%x Data: x%x x%x\n",
3364 cmd
, did
, cmdiocb
->retry
, delay
);
3366 if (((cmd
== ELS_CMD_PLOGI
) || (cmd
== ELS_CMD_ADISC
)) &&
3367 ((irsp
->ulpStatus
!= IOSTAT_LOCAL_REJECT
) ||
3368 ((irsp
->un
.ulpWord
[4] & IOERR_PARAM_MASK
) !=
3369 IOERR_NO_RESOURCES
))) {
3370 /* Don't reset timer for no resources */
3372 /* If discovery / RSCN timer is running, reset it */
3373 if (timer_pending(&vport
->fc_disctmo
) ||
3374 (vport
->fc_flag
& FC_RSCN_MODE
))
3375 lpfc_set_disctmo(vport
);
3378 phba
->fc_stat
.elsXmitRetry
++;
3379 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
) && delay
) {
3380 phba
->fc_stat
.elsDelayRetry
++;
3381 ndlp
->nlp_retry
= cmdiocb
->retry
;
3383 /* delay is specified in milliseconds */
3384 mod_timer(&ndlp
->nlp_delayfunc
,
3385 jiffies
+ msecs_to_jiffies(delay
));
3386 spin_lock_irq(shost
->host_lock
);
3387 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
3388 spin_unlock_irq(shost
->host_lock
);
3390 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
3391 if (cmd
== ELS_CMD_PRLI
)
3392 lpfc_nlp_set_state(vport
, ndlp
,
3393 NLP_STE_PRLI_ISSUE
);
3395 lpfc_nlp_set_state(vport
, ndlp
,
3397 ndlp
->nlp_last_elscmd
= cmd
;
3403 lpfc_issue_els_flogi(vport
, ndlp
, cmdiocb
->retry
);
3406 lpfc_issue_els_fdisc(vport
, ndlp
, cmdiocb
->retry
);
3409 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
)) {
3410 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
3411 lpfc_nlp_set_state(vport
, ndlp
,
3412 NLP_STE_PLOGI_ISSUE
);
3414 lpfc_issue_els_plogi(vport
, did
, cmdiocb
->retry
);
3417 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
3418 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_ADISC_ISSUE
);
3419 lpfc_issue_els_adisc(vport
, ndlp
, cmdiocb
->retry
);
3422 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
3423 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PRLI_ISSUE
);
3424 lpfc_issue_els_prli(vport
, ndlp
, cmdiocb
->retry
);
3427 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
3428 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_LOGO_ISSUE
);
3429 lpfc_issue_els_logo(vport
, ndlp
, cmdiocb
->retry
);
3433 /* No retry ELS command <elsCmd> to remote NPORT <did> */
3435 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
3436 "0137 No retry ELS command x%x to remote "
3437 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
3438 cmd
, did
, irsp
->ulpStatus
,
3439 irsp
->un
.ulpWord
[4]);
3442 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3443 "0108 No retry ELS command x%x to remote "
3444 "NPORT x%x Retried:%d Error:x%x/%x\n",
3445 cmd
, did
, cmdiocb
->retry
, irsp
->ulpStatus
,
3446 irsp
->un
.ulpWord
[4]);
3452 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
3453 * @phba: pointer to lpfc hba data structure.
3454 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
3456 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
3457 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
3458 * checks to see whether there is a lpfc DMA buffer associated with the
3459 * response of the command IOCB. If so, it will be released before releasing
3460 * the lpfc DMA buffer associated with the IOCB itself.
3463 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3466 lpfc_els_free_data(struct lpfc_hba
*phba
, struct lpfc_dmabuf
*buf_ptr1
)
3468 struct lpfc_dmabuf
*buf_ptr
;
3470 /* Free the response before processing the command. */
3471 if (!list_empty(&buf_ptr1
->list
)) {
3472 list_remove_head(&buf_ptr1
->list
, buf_ptr
,
3475 lpfc_mbuf_free(phba
, buf_ptr
->virt
, buf_ptr
->phys
);
3478 lpfc_mbuf_free(phba
, buf_ptr1
->virt
, buf_ptr1
->phys
);
3484 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
3485 * @phba: pointer to lpfc hba data structure.
3486 * @buf_ptr: pointer to the lpfc dma buffer data structure.
3488 * This routine releases the lpfc Direct Memory Access (DMA) buffer
3489 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
3493 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3496 lpfc_els_free_bpl(struct lpfc_hba
*phba
, struct lpfc_dmabuf
*buf_ptr
)
3498 lpfc_mbuf_free(phba
, buf_ptr
->virt
, buf_ptr
->phys
);
3504 * lpfc_els_free_iocb - Free a command iocb and its associated resources
3505 * @phba: pointer to lpfc hba data structure.
3506 * @elsiocb: pointer to lpfc els command iocb data structure.
3508 * This routine frees a command IOCB and its associated resources. The
3509 * command IOCB data structure contains the reference to various associated
3510 * resources, these fields must be set to NULL if the associated reference
3512 * context1 - reference to ndlp
3513 * context2 - reference to cmd
3514 * context2->next - reference to rsp
3515 * context3 - reference to bpl
3517 * It first properly decrements the reference count held on ndlp for the
3518 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
3519 * set, it invokes the lpfc_els_free_data() routine to release the Direct
3520 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
3521 * adds the DMA buffer the @phba data structure for the delayed release.
3522 * If reference to the Buffer Pointer List (BPL) is present, the
3523 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
3524 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
3525 * invoked to release the IOCB data structure back to @phba IOCBQ list.
3528 * 0 - Success (currently, always return 0)
3531 lpfc_els_free_iocb(struct lpfc_hba
*phba
, struct lpfc_iocbq
*elsiocb
)
3533 struct lpfc_dmabuf
*buf_ptr
, *buf_ptr1
;
3534 struct lpfc_nodelist
*ndlp
;
3536 ndlp
= (struct lpfc_nodelist
*)elsiocb
->context1
;
3538 if (ndlp
->nlp_flag
& NLP_DEFER_RM
) {
3541 /* If the ndlp is not being used by another discovery
3544 if (!lpfc_nlp_not_used(ndlp
)) {
3545 /* If ndlp is being used by another discovery
3546 * thread, just clear NLP_DEFER_RM
3548 ndlp
->nlp_flag
&= ~NLP_DEFER_RM
;
3553 elsiocb
->context1
= NULL
;
3555 /* context2 = cmd, context2->next = rsp, context3 = bpl */
3556 if (elsiocb
->context2
) {
3557 if (elsiocb
->iocb_flag
& LPFC_DELAY_MEM_FREE
) {
3558 /* Firmware could still be in progress of DMAing
3559 * payload, so don't free data buffer till after
3562 elsiocb
->iocb_flag
&= ~LPFC_DELAY_MEM_FREE
;
3563 buf_ptr
= elsiocb
->context2
;
3564 elsiocb
->context2
= NULL
;
3567 spin_lock_irq(&phba
->hbalock
);
3568 if (!list_empty(&buf_ptr
->list
)) {
3569 list_remove_head(&buf_ptr
->list
,
3570 buf_ptr1
, struct lpfc_dmabuf
,
3572 INIT_LIST_HEAD(&buf_ptr1
->list
);
3573 list_add_tail(&buf_ptr1
->list
,
3577 INIT_LIST_HEAD(&buf_ptr
->list
);
3578 list_add_tail(&buf_ptr
->list
, &phba
->elsbuf
);
3580 spin_unlock_irq(&phba
->hbalock
);
3583 buf_ptr1
= (struct lpfc_dmabuf
*) elsiocb
->context2
;
3584 lpfc_els_free_data(phba
, buf_ptr1
);
3588 if (elsiocb
->context3
) {
3589 buf_ptr
= (struct lpfc_dmabuf
*) elsiocb
->context3
;
3590 lpfc_els_free_bpl(phba
, buf_ptr
);
3592 lpfc_sli_release_iocbq(phba
, elsiocb
);
3597 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
3598 * @phba: pointer to lpfc hba data structure.
3599 * @cmdiocb: pointer to lpfc command iocb data structure.
3600 * @rspiocb: pointer to lpfc response iocb data structure.
3602 * This routine is the completion callback function to the Logout (LOGO)
3603 * Accept (ACC) Response ELS command. This routine is invoked to indicate
3604 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
3605 * release the ndlp if it has the last reference remaining (reference count
3606 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
3607 * field to NULL to inform the following lpfc_els_free_iocb() routine no
3608 * ndlp reference count needs to be decremented. Otherwise, the ndlp
3609 * reference use-count shall be decremented by the lpfc_els_free_iocb()
3610 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
3611 * IOCB data structure.
3614 lpfc_cmpl_els_logo_acc(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
3615 struct lpfc_iocbq
*rspiocb
)
3617 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
3618 struct lpfc_vport
*vport
= cmdiocb
->vport
;
3621 irsp
= &rspiocb
->iocb
;
3622 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
3623 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
3624 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4], ndlp
->nlp_DID
);
3625 /* ACC to LOGO completes to NPort <nlp_DID> */
3626 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3627 "0109 ACC to LOGO completes to NPort x%x "
3628 "Data: x%x x%x x%x\n",
3629 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
3632 if (ndlp
->nlp_state
== NLP_STE_NPR_NODE
) {
3633 /* NPort Recovery mode or node is just allocated */
3634 if (!lpfc_nlp_not_used(ndlp
)) {
3635 /* If the ndlp is being used by another discovery
3636 * thread, just unregister the RPI.
3638 lpfc_unreg_rpi(vport
, ndlp
);
3640 /* Indicate the node has already released, should
3641 * not reference to it from within lpfc_els_free_iocb.
3643 cmdiocb
->context1
= NULL
;
3648 * The driver received a LOGO from the rport and has ACK'd it.
3649 * At this point, the driver is done so release the IOCB
3651 lpfc_els_free_iocb(phba
, cmdiocb
);
3655 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
3656 * @phba: pointer to lpfc hba data structure.
3657 * @pmb: pointer to the driver internal queue element for mailbox command.
3659 * This routine is the completion callback function for unregister default
3660 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
3661 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
3662 * decrements the ndlp reference count held for this completion callback
3663 * function. After that, it invokes the lpfc_nlp_not_used() to check
3664 * whether there is only one reference left on the ndlp. If so, it will
3665 * perform one more decrement and trigger the release of the ndlp.
3668 lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
3670 struct lpfc_dmabuf
*mp
= (struct lpfc_dmabuf
*) (pmb
->context1
);
3671 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
3673 pmb
->context1
= NULL
;
3674 pmb
->context2
= NULL
;
3676 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
3678 mempool_free(pmb
, phba
->mbox_mem_pool
);
3680 lpfc_printf_vlog(ndlp
->vport
, KERN_INFO
, LOG_NODE
,
3681 "0006 rpi%x DID:%x flg:%x %d map:%x %p\n",
3682 ndlp
->nlp_rpi
, ndlp
->nlp_DID
, ndlp
->nlp_flag
,
3683 atomic_read(&ndlp
->kref
.refcount
),
3684 ndlp
->nlp_usg_map
, ndlp
);
3685 if (NLP_CHK_NODE_ACT(ndlp
)) {
3687 /* This is the end of the default RPI cleanup logic for
3688 * this ndlp. If no other discovery threads are using
3689 * this ndlp, free all resources associated with it.
3691 lpfc_nlp_not_used(ndlp
);
3693 lpfc_drop_node(ndlp
->vport
, ndlp
);
3701 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
3702 * @phba: pointer to lpfc hba data structure.
3703 * @cmdiocb: pointer to lpfc command iocb data structure.
3704 * @rspiocb: pointer to lpfc response iocb data structure.
3706 * This routine is the completion callback function for ELS Response IOCB
3707 * command. In normal case, this callback function just properly sets the
3708 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
3709 * field in the command IOCB is not NULL, the referred mailbox command will
3710 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
3711 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
3712 * link down event occurred during the discovery, the lpfc_nlp_not_used()
3713 * routine shall be invoked trying to release the ndlp if no other threads
3714 * are currently referring it.
3717 lpfc_cmpl_els_rsp(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
3718 struct lpfc_iocbq
*rspiocb
)
3720 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
3721 struct lpfc_vport
*vport
= ndlp
? ndlp
->vport
: NULL
;
3722 struct Scsi_Host
*shost
= vport
? lpfc_shost_from_vport(vport
) : NULL
;
3725 LPFC_MBOXQ_t
*mbox
= NULL
;
3726 struct lpfc_dmabuf
*mp
= NULL
;
3727 uint32_t ls_rjt
= 0;
3729 irsp
= &rspiocb
->iocb
;
3731 if (cmdiocb
->context_un
.mbox
)
3732 mbox
= cmdiocb
->context_un
.mbox
;
3734 /* First determine if this is a LS_RJT cmpl. Note, this callback
3735 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
3737 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) cmdiocb
->context2
)->virt
);
3738 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
) &&
3739 (*((uint32_t *) (pcmd
)) == ELS_CMD_LS_RJT
)) {
3740 /* A LS_RJT associated with Default RPI cleanup has its own
3741 * separate code path.
3743 if (!(ndlp
->nlp_flag
& NLP_RM_DFLT_RPI
))
3747 /* Check to see if link went down during discovery */
3748 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
) || lpfc_els_chk_latt(vport
)) {
3750 mp
= (struct lpfc_dmabuf
*) mbox
->context1
;
3752 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
3755 mempool_free(mbox
, phba
->mbox_mem_pool
);
3757 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
) &&
3758 (ndlp
->nlp_flag
& NLP_RM_DFLT_RPI
))
3759 if (lpfc_nlp_not_used(ndlp
)) {
3761 /* Indicate the node has already released,
3762 * should not reference to it from within
3763 * the routine lpfc_els_free_iocb.
3765 cmdiocb
->context1
= NULL
;
3770 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
3771 "ELS rsp cmpl: status:x%x/x%x did:x%x",
3772 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
3773 cmdiocb
->iocb
.un
.elsreq64
.remoteID
);
3774 /* ELS response tag <ulpIoTag> completes */
3775 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3776 "0110 ELS response tag x%x completes "
3777 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
3778 cmdiocb
->iocb
.ulpIoTag
, rspiocb
->iocb
.ulpStatus
,
3779 rspiocb
->iocb
.un
.ulpWord
[4], rspiocb
->iocb
.ulpTimeout
,
3780 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
3783 if ((rspiocb
->iocb
.ulpStatus
== 0)
3784 && (ndlp
->nlp_flag
& NLP_ACC_REGLOGIN
)) {
3785 lpfc_unreg_rpi(vport
, ndlp
);
3786 /* Increment reference count to ndlp to hold the
3787 * reference to ndlp for the callback function.
3789 mbox
->context2
= lpfc_nlp_get(ndlp
);
3790 mbox
->vport
= vport
;
3791 if (ndlp
->nlp_flag
& NLP_RM_DFLT_RPI
) {
3792 mbox
->mbox_flag
|= LPFC_MBX_IMED_UNREG
;
3793 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_dflt_rpi
;
3796 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_reg_login
;
3797 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
3798 lpfc_nlp_set_state(vport
, ndlp
,
3799 NLP_STE_REG_LOGIN_ISSUE
);
3802 ndlp
->nlp_flag
|= NLP_REG_LOGIN_SEND
;
3803 if (lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
)
3804 != MBX_NOT_FINISHED
)
3807 /* Decrement the ndlp reference count we
3808 * set for this failed mailbox command.
3811 ndlp
->nlp_flag
&= ~NLP_REG_LOGIN_SEND
;
3813 /* ELS rsp: Cannot issue reg_login for <NPortid> */
3814 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
3815 "0138 ELS rsp: Cannot issue reg_login for x%x "
3816 "Data: x%x x%x x%x\n",
3817 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
3820 if (lpfc_nlp_not_used(ndlp
)) {
3822 /* Indicate node has already been released,
3823 * should not reference to it from within
3824 * the routine lpfc_els_free_iocb.
3826 cmdiocb
->context1
= NULL
;
3829 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
3830 if (!lpfc_error_lost_link(irsp
) &&
3831 ndlp
->nlp_flag
& NLP_ACC_REGLOGIN
) {
3832 if (lpfc_nlp_not_used(ndlp
)) {
3834 /* Indicate node has already been
3835 * released, should not reference
3836 * to it from within the routine
3837 * lpfc_els_free_iocb.
3839 cmdiocb
->context1
= NULL
;
3843 mp
= (struct lpfc_dmabuf
*) mbox
->context1
;
3845 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
3848 mempool_free(mbox
, phba
->mbox_mem_pool
);
3851 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
)) {
3852 spin_lock_irq(shost
->host_lock
);
3853 ndlp
->nlp_flag
&= ~(NLP_ACC_REGLOGIN
| NLP_RM_DFLT_RPI
);
3854 spin_unlock_irq(shost
->host_lock
);
3856 /* If the node is not being used by another discovery thread,
3857 * and we are sending a reject, we are done with it.
3858 * Release driver reference count here and free associated
3862 if (lpfc_nlp_not_used(ndlp
))
3863 /* Indicate node has already been released,
3864 * should not reference to it from within
3865 * the routine lpfc_els_free_iocb.
3867 cmdiocb
->context1
= NULL
;
3871 lpfc_els_free_iocb(phba
, cmdiocb
);
3876 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
3877 * @vport: pointer to a host virtual N_Port data structure.
3878 * @flag: the els command code to be accepted.
3879 * @oldiocb: pointer to the original lpfc command iocb data structure.
3880 * @ndlp: pointer to a node-list data structure.
3881 * @mbox: pointer to the driver internal queue element for mailbox command.
3883 * This routine prepares and issues an Accept (ACC) response IOCB
3884 * command. It uses the @flag to properly set up the IOCB field for the
3885 * specific ACC response command to be issued and invokes the
3886 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
3887 * @mbox pointer is passed in, it will be put into the context_un.mbox
3888 * field of the IOCB for the completion callback function to issue the
3889 * mailbox command to the HBA later when callback is invoked.
3891 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3892 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3893 * will be stored into the context1 field of the IOCB for the completion
3894 * callback function to the corresponding response ELS IOCB command.
3897 * 0 - Successfully issued acc response
3898 * 1 - Failed to issue acc response
3901 lpfc_els_rsp_acc(struct lpfc_vport
*vport
, uint32_t flag
,
3902 struct lpfc_iocbq
*oldiocb
, struct lpfc_nodelist
*ndlp
,
3905 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3906 struct lpfc_hba
*phba
= vport
->phba
;
3909 struct lpfc_iocbq
*elsiocb
;
3911 struct serv_parm
*sp
;
3914 ELS_PKT
*els_pkt_ptr
;
3916 oldcmd
= &oldiocb
->iocb
;
3920 cmdsize
= sizeof(uint32_t);
3921 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
,
3922 ndlp
, ndlp
->nlp_DID
, ELS_CMD_ACC
);
3924 spin_lock_irq(shost
->host_lock
);
3925 ndlp
->nlp_flag
&= ~NLP_LOGO_ACC
;
3926 spin_unlock_irq(shost
->host_lock
);
3930 icmd
= &elsiocb
->iocb
;
3931 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri / rx_id */
3932 icmd
->unsli3
.rcvsli3
.ox_id
= oldcmd
->unsli3
.rcvsli3
.ox_id
;
3933 pcmd
= (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
3934 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
3935 pcmd
+= sizeof(uint32_t);
3937 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
3938 "Issue ACC: did:x%x flg:x%x",
3939 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
3943 cmdsize
= (sizeof(struct serv_parm
) + sizeof(uint32_t));
3944 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
,
3945 ndlp
, ndlp
->nlp_DID
, ELS_CMD_ACC
);
3949 icmd
= &elsiocb
->iocb
;
3950 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri / rx_id */
3951 icmd
->unsli3
.rcvsli3
.ox_id
= oldcmd
->unsli3
.rcvsli3
.ox_id
;
3952 pcmd
= (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
3955 elsiocb
->context_un
.mbox
= mbox
;
3957 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
3958 pcmd
+= sizeof(uint32_t);
3959 sp
= (struct serv_parm
*)pcmd
;
3961 if (flag
== ELS_CMD_FLOGI
) {
3962 /* Copy the received service parameters back */
3963 memcpy(sp
, &phba
->fc_fabparam
,
3964 sizeof(struct serv_parm
));
3966 /* Clear the F_Port bit */
3969 /* Mark all class service parameters as invalid */
3970 sp
->cls1
.classValid
= 0;
3971 sp
->cls2
.classValid
= 0;
3972 sp
->cls3
.classValid
= 0;
3973 sp
->cls4
.classValid
= 0;
3975 /* Copy our worldwide names */
3976 memcpy(&sp
->portName
, &vport
->fc_sparam
.portName
,
3977 sizeof(struct lpfc_name
));
3978 memcpy(&sp
->nodeName
, &vport
->fc_sparam
.nodeName
,
3979 sizeof(struct lpfc_name
));
3981 memcpy(pcmd
, &vport
->fc_sparam
,
3982 sizeof(struct serv_parm
));
3985 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
3986 "Issue ACC FLOGI/PLOGI: did:x%x flg:x%x",
3987 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
3990 cmdsize
= sizeof(uint32_t) + sizeof(PRLO
);
3991 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
,
3992 ndlp
, ndlp
->nlp_DID
, ELS_CMD_PRLO
);
3996 icmd
= &elsiocb
->iocb
;
3997 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri / rx_id */
3998 icmd
->unsli3
.rcvsli3
.ox_id
= oldcmd
->unsli3
.rcvsli3
.ox_id
;
3999 pcmd
= (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
4001 memcpy(pcmd
, ((struct lpfc_dmabuf
*) oldiocb
->context2
)->virt
,
4002 sizeof(uint32_t) + sizeof(PRLO
));
4003 *((uint32_t *) (pcmd
)) = ELS_CMD_PRLO_ACC
;
4004 els_pkt_ptr
= (ELS_PKT
*) pcmd
;
4005 els_pkt_ptr
->un
.prlo
.acceptRspCode
= PRLO_REQ_EXECUTED
;
4007 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
4008 "Issue ACC PRLO: did:x%x flg:x%x",
4009 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
4014 /* Xmit ELS ACC response tag <ulpIoTag> */
4015 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
4016 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
4017 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x "
4019 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
4020 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
4021 ndlp
->nlp_rpi
, vport
->fc_flag
);
4022 if (ndlp
->nlp_flag
& NLP_LOGO_ACC
) {
4023 spin_lock_irq(shost
->host_lock
);
4024 if (!(ndlp
->nlp_flag
& NLP_RPI_REGISTERED
||
4025 ndlp
->nlp_flag
& NLP_REG_LOGIN_SEND
))
4026 ndlp
->nlp_flag
&= ~NLP_LOGO_ACC
;
4027 spin_unlock_irq(shost
->host_lock
);
4028 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_logo_acc
;
4030 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
4033 phba
->fc_stat
.elsXmitACC
++;
4034 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
4035 if (rc
== IOCB_ERROR
) {
4036 lpfc_els_free_iocb(phba
, elsiocb
);
4043 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
4044 * @vport: pointer to a virtual N_Port data structure.
4046 * @oldiocb: pointer to the original lpfc command iocb data structure.
4047 * @ndlp: pointer to a node-list data structure.
4048 * @mbox: pointer to the driver internal queue element for mailbox command.
4050 * This routine prepares and issue an Reject (RJT) response IOCB
4051 * command. If a @mbox pointer is passed in, it will be put into the
4052 * context_un.mbox field of the IOCB for the completion callback function
4053 * to issue to the HBA later.
4055 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4056 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4057 * will be stored into the context1 field of the IOCB for the completion
4058 * callback function to the reject response ELS IOCB command.
4061 * 0 - Successfully issued reject response
4062 * 1 - Failed to issue reject response
4065 lpfc_els_rsp_reject(struct lpfc_vport
*vport
, uint32_t rejectError
,
4066 struct lpfc_iocbq
*oldiocb
, struct lpfc_nodelist
*ndlp
,
4069 struct lpfc_hba
*phba
= vport
->phba
;
4072 struct lpfc_iocbq
*elsiocb
;
4077 cmdsize
= 2 * sizeof(uint32_t);
4078 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
4079 ndlp
->nlp_DID
, ELS_CMD_LS_RJT
);
4083 icmd
= &elsiocb
->iocb
;
4084 oldcmd
= &oldiocb
->iocb
;
4085 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri / rx_id */
4086 icmd
->unsli3
.rcvsli3
.ox_id
= oldcmd
->unsli3
.rcvsli3
.ox_id
;
4087 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
4089 *((uint32_t *) (pcmd
)) = ELS_CMD_LS_RJT
;
4090 pcmd
+= sizeof(uint32_t);
4091 *((uint32_t *) (pcmd
)) = rejectError
;
4094 elsiocb
->context_un
.mbox
= mbox
;
4096 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
4097 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
4098 "0129 Xmit ELS RJT x%x response tag x%x "
4099 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
4101 rejectError
, elsiocb
->iotag
,
4102 elsiocb
->iocb
.ulpContext
, ndlp
->nlp_DID
,
4103 ndlp
->nlp_flag
, ndlp
->nlp_state
, ndlp
->nlp_rpi
);
4104 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
4105 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
4106 ndlp
->nlp_DID
, ndlp
->nlp_flag
, rejectError
);
4108 phba
->fc_stat
.elsXmitLSRJT
++;
4109 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
4110 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
4112 if (rc
== IOCB_ERROR
) {
4113 lpfc_els_free_iocb(phba
, elsiocb
);
4120 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
4121 * @vport: pointer to a virtual N_Port data structure.
4122 * @oldiocb: pointer to the original lpfc command iocb data structure.
4123 * @ndlp: pointer to a node-list data structure.
4125 * This routine prepares and issues an Accept (ACC) response to Address
4126 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
4127 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
4129 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4130 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4131 * will be stored into the context1 field of the IOCB for the completion
4132 * callback function to the ADISC Accept response ELS IOCB command.
4135 * 0 - Successfully issued acc adisc response
4136 * 1 - Failed to issue adisc acc response
4139 lpfc_els_rsp_adisc_acc(struct lpfc_vport
*vport
, struct lpfc_iocbq
*oldiocb
,
4140 struct lpfc_nodelist
*ndlp
)
4142 struct lpfc_hba
*phba
= vport
->phba
;
4144 IOCB_t
*icmd
, *oldcmd
;
4145 struct lpfc_iocbq
*elsiocb
;
4150 cmdsize
= sizeof(uint32_t) + sizeof(ADISC
);
4151 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
4152 ndlp
->nlp_DID
, ELS_CMD_ACC
);
4156 icmd
= &elsiocb
->iocb
;
4157 oldcmd
= &oldiocb
->iocb
;
4158 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri / rx_id */
4159 icmd
->unsli3
.rcvsli3
.ox_id
= oldcmd
->unsli3
.rcvsli3
.ox_id
;
4161 /* Xmit ADISC ACC response tag <ulpIoTag> */
4162 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
4163 "0130 Xmit ADISC ACC response iotag x%x xri: "
4164 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
4165 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
4166 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
4168 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
4170 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
4171 pcmd
+= sizeof(uint32_t);
4173 ap
= (ADISC
*) (pcmd
);
4174 ap
->hardAL_PA
= phba
->fc_pref_ALPA
;
4175 memcpy(&ap
->portName
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
4176 memcpy(&ap
->nodeName
, &vport
->fc_nodename
, sizeof(struct lpfc_name
));
4177 ap
->DID
= be32_to_cpu(vport
->fc_myDID
);
4179 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
4180 "Issue ACC ADISC: did:x%x flg:x%x",
4181 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
4183 phba
->fc_stat
.elsXmitACC
++;
4184 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
4185 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
4186 if (rc
== IOCB_ERROR
) {
4187 lpfc_els_free_iocb(phba
, elsiocb
);
4194 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
4195 * @vport: pointer to a virtual N_Port data structure.
4196 * @oldiocb: pointer to the original lpfc command iocb data structure.
4197 * @ndlp: pointer to a node-list data structure.
4199 * This routine prepares and issues an Accept (ACC) response to Process
4200 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
4201 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
4203 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4204 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4205 * will be stored into the context1 field of the IOCB for the completion
4206 * callback function to the PRLI Accept response ELS IOCB command.
4209 * 0 - Successfully issued acc prli response
4210 * 1 - Failed to issue acc prli response
4213 lpfc_els_rsp_prli_acc(struct lpfc_vport
*vport
, struct lpfc_iocbq
*oldiocb
,
4214 struct lpfc_nodelist
*ndlp
)
4216 struct lpfc_hba
*phba
= vport
->phba
;
4221 struct lpfc_iocbq
*elsiocb
;
4226 cmdsize
= sizeof(uint32_t) + sizeof(PRLI
);
4227 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
4228 ndlp
->nlp_DID
, (ELS_CMD_ACC
| (ELS_CMD_PRLI
& ~ELS_RSP_MASK
)));
4232 icmd
= &elsiocb
->iocb
;
4233 oldcmd
= &oldiocb
->iocb
;
4234 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri / rx_id */
4235 icmd
->unsli3
.rcvsli3
.ox_id
= oldcmd
->unsli3
.rcvsli3
.ox_id
;
4237 /* Xmit PRLI ACC response tag <ulpIoTag> */
4238 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
4239 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
4240 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
4241 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
4242 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
4244 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
4246 *((uint32_t *) (pcmd
)) = (ELS_CMD_ACC
| (ELS_CMD_PRLI
& ~ELS_RSP_MASK
));
4247 pcmd
+= sizeof(uint32_t);
4249 /* For PRLI, remainder of payload is PRLI parameter page */
4250 memset(pcmd
, 0, sizeof(PRLI
));
4252 npr
= (PRLI
*) pcmd
;
4255 * If the remote port is a target and our firmware version is 3.20 or
4256 * later, set the following bits for FC-TAPE support.
4258 if ((ndlp
->nlp_type
& NLP_FCP_TARGET
) &&
4259 (vpd
->rev
.feaLevelHigh
>= 0x02)) {
4260 npr
->ConfmComplAllowed
= 1;
4262 npr
->TaskRetryIdReq
= 1;
4265 npr
->acceptRspCode
= PRLI_REQ_EXECUTED
;
4266 npr
->estabImagePair
= 1;
4267 npr
->readXferRdyDis
= 1;
4268 npr
->ConfmComplAllowed
= 1;
4270 npr
->prliType
= PRLI_FCP_TYPE
;
4271 npr
->initiatorFunc
= 1;
4273 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
4274 "Issue ACC PRLI: did:x%x flg:x%x",
4275 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
4277 phba
->fc_stat
.elsXmitACC
++;
4278 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
4280 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
4281 if (rc
== IOCB_ERROR
) {
4282 lpfc_els_free_iocb(phba
, elsiocb
);
4289 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
4290 * @vport: pointer to a virtual N_Port data structure.
4291 * @format: rnid command format.
4292 * @oldiocb: pointer to the original lpfc command iocb data structure.
4293 * @ndlp: pointer to a node-list data structure.
4295 * This routine issues a Request Node Identification Data (RNID) Accept
4296 * (ACC) response. It constructs the RNID ACC response command according to
4297 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
4298 * issue the response. Note that this command does not need to hold the ndlp
4299 * reference count for the callback. So, the ndlp reference count taken by
4300 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
4301 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
4302 * there is no ndlp reference available.
4304 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4305 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4306 * will be stored into the context1 field of the IOCB for the completion
4307 * callback function. However, for the RNID Accept Response ELS command,
4308 * this is undone later by this routine after the IOCB is allocated.
4311 * 0 - Successfully issued acc rnid response
4312 * 1 - Failed to issue acc rnid response
4315 lpfc_els_rsp_rnid_acc(struct lpfc_vport
*vport
, uint8_t format
,
4316 struct lpfc_iocbq
*oldiocb
, struct lpfc_nodelist
*ndlp
)
4318 struct lpfc_hba
*phba
= vport
->phba
;
4320 IOCB_t
*icmd
, *oldcmd
;
4321 struct lpfc_iocbq
*elsiocb
;
4326 cmdsize
= sizeof(uint32_t) + sizeof(uint32_t)
4327 + (2 * sizeof(struct lpfc_name
));
4329 cmdsize
+= sizeof(RNID_TOP_DISC
);
4331 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
4332 ndlp
->nlp_DID
, ELS_CMD_ACC
);
4336 icmd
= &elsiocb
->iocb
;
4337 oldcmd
= &oldiocb
->iocb
;
4338 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri / rx_id */
4339 icmd
->unsli3
.rcvsli3
.ox_id
= oldcmd
->unsli3
.rcvsli3
.ox_id
;
4341 /* Xmit RNID ACC response tag <ulpIoTag> */
4342 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
4343 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
4344 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
);
4345 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
4346 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
4347 pcmd
+= sizeof(uint32_t);
4349 memset(pcmd
, 0, sizeof(RNID
));
4350 rn
= (RNID
*) (pcmd
);
4351 rn
->Format
= format
;
4352 rn
->CommonLen
= (2 * sizeof(struct lpfc_name
));
4353 memcpy(&rn
->portName
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
4354 memcpy(&rn
->nodeName
, &vport
->fc_nodename
, sizeof(struct lpfc_name
));
4357 rn
->SpecificLen
= 0;
4359 case RNID_TOPOLOGY_DISC
:
4360 rn
->SpecificLen
= sizeof(RNID_TOP_DISC
);
4361 memcpy(&rn
->un
.topologyDisc
.portName
,
4362 &vport
->fc_portname
, sizeof(struct lpfc_name
));
4363 rn
->un
.topologyDisc
.unitType
= RNID_HBA
;
4364 rn
->un
.topologyDisc
.physPort
= 0;
4365 rn
->un
.topologyDisc
.attachedNodes
= 0;
4369 rn
->SpecificLen
= 0;
4373 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
4374 "Issue ACC RNID: did:x%x flg:x%x",
4375 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
4377 phba
->fc_stat
.elsXmitACC
++;
4378 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
4380 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_clear_rrq - Clear the rq that this rrq describes.
4390 * @vport: pointer to a virtual N_Port data structure.
4391 * @iocb: pointer to the lpfc command iocb data structure.
4392 * @ndlp: pointer to a node-list data structure.
4397 lpfc_els_clear_rrq(struct lpfc_vport
*vport
,
4398 struct lpfc_iocbq
*iocb
, struct lpfc_nodelist
*ndlp
)
4400 struct lpfc_hba
*phba
= vport
->phba
;
4405 struct lpfc_node_rrq
*prrq
;
4408 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) iocb
->context2
)->virt
);
4409 pcmd
+= sizeof(uint32_t);
4410 rrq
= (struct RRQ
*)pcmd
;
4411 rrq
->rrq_exchg
= be32_to_cpu(rrq
->rrq_exchg
);
4412 rxid
= bf_get(rrq_rxid
, rrq
);
4414 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
4415 "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x"
4417 be32_to_cpu(bf_get(rrq_did
, rrq
)),
4418 bf_get(rrq_oxid
, rrq
),
4420 iocb
->iotag
, iocb
->iocb
.ulpContext
);
4422 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
4423 "Clear RRQ: did:x%x flg:x%x exchg:x%.08x",
4424 ndlp
->nlp_DID
, ndlp
->nlp_flag
, rrq
->rrq_exchg
);
4425 if (vport
->fc_myDID
== be32_to_cpu(bf_get(rrq_did
, rrq
)))
4426 xri
= bf_get(rrq_oxid
, rrq
);
4429 prrq
= lpfc_get_active_rrq(vport
, xri
, ndlp
->nlp_DID
);
4431 lpfc_clr_rrq_active(phba
, xri
, prrq
);
4436 * lpfc_els_rsp_echo_acc - Issue echo acc response
4437 * @vport: pointer to a virtual N_Port data structure.
4438 * @data: pointer to echo data to return in the accept.
4439 * @oldiocb: pointer to the original lpfc command iocb data structure.
4440 * @ndlp: pointer to a node-list data structure.
4443 * 0 - Successfully issued acc echo response
4444 * 1 - Failed to issue acc echo response
4447 lpfc_els_rsp_echo_acc(struct lpfc_vport
*vport
, uint8_t *data
,
4448 struct lpfc_iocbq
*oldiocb
, struct lpfc_nodelist
*ndlp
)
4450 struct lpfc_hba
*phba
= vport
->phba
;
4451 struct lpfc_iocbq
*elsiocb
;
4456 cmdsize
= oldiocb
->iocb
.unsli3
.rcvsli3
.acc_len
;
4458 /* The accumulated length can exceed the BPL_SIZE. For
4459 * now, use this as the limit
4461 if (cmdsize
> LPFC_BPL_SIZE
)
4462 cmdsize
= LPFC_BPL_SIZE
;
4463 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
4464 ndlp
->nlp_DID
, ELS_CMD_ACC
);
4468 elsiocb
->iocb
.ulpContext
= oldiocb
->iocb
.ulpContext
; /* Xri / rx_id */
4469 elsiocb
->iocb
.unsli3
.rcvsli3
.ox_id
= oldiocb
->iocb
.unsli3
.rcvsli3
.ox_id
;
4471 /* Xmit ECHO ACC response tag <ulpIoTag> */
4472 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
4473 "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
4474 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
);
4475 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
4476 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
4477 pcmd
+= sizeof(uint32_t);
4478 memcpy(pcmd
, data
, cmdsize
- sizeof(uint32_t));
4480 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
4481 "Issue ACC ECHO: did:x%x flg:x%x",
4482 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
4484 phba
->fc_stat
.elsXmitACC
++;
4485 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
4487 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
4488 if (rc
== IOCB_ERROR
) {
4489 lpfc_els_free_iocb(phba
, elsiocb
);
4496 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
4497 * @vport: pointer to a host virtual N_Port data structure.
4499 * This routine issues Address Discover (ADISC) ELS commands to those
4500 * N_Ports which are in node port recovery state and ADISC has not been issued
4501 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
4502 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
4503 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
4504 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
4505 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
4506 * IOCBs quit for later pick up. On the other hand, after walking through
4507 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
4508 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
4509 * no more ADISC need to be sent.
4512 * The number of N_Ports with adisc issued.
4515 lpfc_els_disc_adisc(struct lpfc_vport
*vport
)
4517 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4518 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
4521 /* go thru NPR nodes and issue any remaining ELS ADISCs */
4522 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
, nlp_listp
) {
4523 if (!NLP_CHK_NODE_ACT(ndlp
))
4525 if (ndlp
->nlp_state
== NLP_STE_NPR_NODE
&&
4526 (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) != 0 &&
4527 (ndlp
->nlp_flag
& NLP_NPR_ADISC
) != 0) {
4528 spin_lock_irq(shost
->host_lock
);
4529 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
4530 spin_unlock_irq(shost
->host_lock
);
4531 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
4532 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_ADISC_ISSUE
);
4533 lpfc_issue_els_adisc(vport
, ndlp
, 0);
4535 vport
->num_disc_nodes
++;
4536 if (vport
->num_disc_nodes
>=
4537 vport
->cfg_discovery_threads
) {
4538 spin_lock_irq(shost
->host_lock
);
4539 vport
->fc_flag
|= FC_NLP_MORE
;
4540 spin_unlock_irq(shost
->host_lock
);
4545 if (sentadisc
== 0) {
4546 spin_lock_irq(shost
->host_lock
);
4547 vport
->fc_flag
&= ~FC_NLP_MORE
;
4548 spin_unlock_irq(shost
->host_lock
);
4554 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
4555 * @vport: pointer to a host virtual N_Port data structure.
4557 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
4558 * which are in node port recovery state, with a @vport. Each time an ELS
4559 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
4560 * the per @vport number of discover count (num_disc_nodes) shall be
4561 * incremented. If the num_disc_nodes reaches a pre-configured threshold
4562 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
4563 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
4564 * later pick up. On the other hand, after walking through all the ndlps with
4565 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
4566 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
4567 * PLOGI need to be sent.
4570 * The number of N_Ports with plogi issued.
4573 lpfc_els_disc_plogi(struct lpfc_vport
*vport
)
4575 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4576 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
4579 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
4580 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
, nlp_listp
) {
4581 if (!NLP_CHK_NODE_ACT(ndlp
))
4583 if (ndlp
->nlp_state
== NLP_STE_NPR_NODE
&&
4584 (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) != 0 &&
4585 (ndlp
->nlp_flag
& NLP_DELAY_TMO
) == 0 &&
4586 (ndlp
->nlp_flag
& NLP_NPR_ADISC
) == 0) {
4587 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
4588 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
4589 lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0);
4591 vport
->num_disc_nodes
++;
4592 if (vport
->num_disc_nodes
>=
4593 vport
->cfg_discovery_threads
) {
4594 spin_lock_irq(shost
->host_lock
);
4595 vport
->fc_flag
|= FC_NLP_MORE
;
4596 spin_unlock_irq(shost
->host_lock
);
4602 lpfc_set_disctmo(vport
);
4605 spin_lock_irq(shost
->host_lock
);
4606 vport
->fc_flag
&= ~FC_NLP_MORE
;
4607 spin_unlock_irq(shost
->host_lock
);
4613 lpfc_rdp_res_link_service(struct fc_rdp_link_service_desc
*desc
,
4617 desc
->tag
= cpu_to_be32(RDP_LINK_SERVICE_DESC_TAG
);
4618 desc
->payload
.els_req
= word0
;
4619 desc
->length
= cpu_to_be32(sizeof(desc
->payload
));
4623 lpfc_rdp_res_sfp_desc(struct fc_rdp_sfp_desc
*desc
,
4624 uint8_t *page_a0
, uint8_t *page_a2
)
4626 uint16_t wavelength
;
4627 uint16_t temperature
;
4633 struct sff_trasnceiver_codes_byte4
*trasn_code_byte4
;
4634 struct sff_trasnceiver_codes_byte5
*trasn_code_byte5
;
4636 desc
->tag
= cpu_to_be32(RDP_SFP_DESC_TAG
);
4638 trasn_code_byte4
= (struct sff_trasnceiver_codes_byte4
*)
4639 &page_a0
[SSF_TRANSCEIVER_CODE_B4
];
4640 trasn_code_byte5
= (struct sff_trasnceiver_codes_byte5
*)
4641 &page_a0
[SSF_TRANSCEIVER_CODE_B5
];
4643 if ((trasn_code_byte4
->fc_sw_laser
) ||
4644 (trasn_code_byte5
->fc_sw_laser_sl
) ||
4645 (trasn_code_byte5
->fc_sw_laser_sn
)) { /* check if its short WL */
4646 flag
|= (SFP_FLAG_PT_SWLASER
<< SFP_FLAG_PT_SHIFT
);
4647 } else if (trasn_code_byte4
->fc_lw_laser
) {
4648 wavelength
= (page_a0
[SSF_WAVELENGTH_B1
] << 8) |
4649 page_a0
[SSF_WAVELENGTH_B0
];
4650 if (wavelength
== SFP_WAVELENGTH_LC1310
)
4651 flag
|= SFP_FLAG_PT_LWLASER_LC1310
<< SFP_FLAG_PT_SHIFT
;
4652 if (wavelength
== SFP_WAVELENGTH_LL1550
)
4653 flag
|= SFP_FLAG_PT_LWLASER_LL1550
<< SFP_FLAG_PT_SHIFT
;
4655 /* check if its SFP+ */
4656 flag
|= ((page_a0
[SSF_IDENTIFIER
] == SFF_PG0_IDENT_SFP
) ?
4657 SFP_FLAG_CT_SFP_PLUS
: SFP_FLAG_CT_UNKNOWN
)
4658 << SFP_FLAG_CT_SHIFT
;
4660 /* check if its OPTICAL */
4661 flag
|= ((page_a0
[SSF_CONNECTOR
] == SFF_PG0_CONNECTOR_LC
) ?
4662 SFP_FLAG_IS_OPTICAL_PORT
: 0)
4663 << SFP_FLAG_IS_OPTICAL_SHIFT
;
4665 temperature
= (page_a2
[SFF_TEMPERATURE_B1
] << 8 |
4666 page_a2
[SFF_TEMPERATURE_B0
]);
4667 vcc
= (page_a2
[SFF_VCC_B1
] << 8 |
4668 page_a2
[SFF_VCC_B0
]);
4669 tx_power
= (page_a2
[SFF_TXPOWER_B1
] << 8 |
4670 page_a2
[SFF_TXPOWER_B0
]);
4671 tx_bias
= (page_a2
[SFF_TX_BIAS_CURRENT_B1
] << 8 |
4672 page_a2
[SFF_TX_BIAS_CURRENT_B0
]);
4673 rx_power
= (page_a2
[SFF_RXPOWER_B1
] << 8 |
4674 page_a2
[SFF_RXPOWER_B0
]);
4675 desc
->sfp_info
.temperature
= cpu_to_be16(temperature
);
4676 desc
->sfp_info
.rx_power
= cpu_to_be16(rx_power
);
4677 desc
->sfp_info
.tx_bias
= cpu_to_be16(tx_bias
);
4678 desc
->sfp_info
.tx_power
= cpu_to_be16(tx_power
);
4679 desc
->sfp_info
.vcc
= cpu_to_be16(vcc
);
4681 desc
->sfp_info
.flags
= cpu_to_be16(flag
);
4682 desc
->length
= cpu_to_be32(sizeof(desc
->sfp_info
));
4686 lpfc_rdp_res_link_error(struct fc_rdp_link_error_status_desc
*desc
,
4691 desc
->tag
= cpu_to_be32(RDP_LINK_ERROR_STATUS_DESC_TAG
);
4693 type
= VN_PT_PHY_PF_PORT
<< VN_PT_PHY_SHIFT
;
4695 desc
->info
.port_type
= cpu_to_be32(type
);
4697 desc
->info
.link_status
.link_failure_cnt
=
4698 cpu_to_be32(stat
->linkFailureCnt
);
4699 desc
->info
.link_status
.loss_of_synch_cnt
=
4700 cpu_to_be32(stat
->lossSyncCnt
);
4701 desc
->info
.link_status
.loss_of_signal_cnt
=
4702 cpu_to_be32(stat
->lossSignalCnt
);
4703 desc
->info
.link_status
.primitive_seq_proto_err
=
4704 cpu_to_be32(stat
->primSeqErrCnt
);
4705 desc
->info
.link_status
.invalid_trans_word
=
4706 cpu_to_be32(stat
->invalidXmitWord
);
4707 desc
->info
.link_status
.invalid_crc_cnt
= cpu_to_be32(stat
->crcCnt
);
4709 desc
->length
= cpu_to_be32(sizeof(desc
->info
));
4713 lpfc_rdp_res_bbc_desc(struct fc_rdp_bbc_desc
*desc
, READ_LNK_VAR
*stat
,
4714 struct lpfc_vport
*vport
)
4716 desc
->tag
= cpu_to_be32(RDP_BBC_DESC_TAG
);
4718 desc
->bbc_info
.port_bbc
= cpu_to_be32(
4719 vport
->fc_sparam
.cmn
.bbCreditMsb
|
4720 vport
->fc_sparam
.cmn
.bbCreditlsb
<< 8);
4721 if (vport
->phba
->fc_topology
!= LPFC_TOPOLOGY_LOOP
)
4722 desc
->bbc_info
.attached_port_bbc
= cpu_to_be32(
4723 vport
->phba
->fc_fabparam
.cmn
.bbCreditMsb
|
4724 vport
->phba
->fc_fabparam
.cmn
.bbCreditlsb
<< 8);
4726 desc
->bbc_info
.attached_port_bbc
= 0;
4728 desc
->bbc_info
.rtt
= 0;
4729 desc
->length
= cpu_to_be32(sizeof(desc
->bbc_info
));
4733 lpfc_rdp_res_oed_temp_desc(struct fc_rdp_oed_sfp_desc
*desc
, uint8_t *page_a2
)
4737 desc
->tag
= cpu_to_be32(RDP_OED_DESC_TAG
);
4739 desc
->oed_info
.hi_alarm
=
4740 cpu_to_be16(page_a2
[SSF_TEMP_HIGH_ALARM
]);
4741 desc
->oed_info
.lo_alarm
= cpu_to_be16(page_a2
[SSF_TEMP_LOW_ALARM
]);
4742 desc
->oed_info
.hi_warning
=
4743 cpu_to_be16(page_a2
[SSF_TEMP_HIGH_WARNING
]);
4744 desc
->oed_info
.lo_warning
=
4745 cpu_to_be16(page_a2
[SSF_TEMP_LOW_WARNING
]);
4746 flags
= 0xf; /* All four are valid */
4747 flags
|= ((0xf & RDP_OED_TEMPERATURE
) << RDP_OED_TYPE_SHIFT
);
4748 desc
->oed_info
.function_flags
= cpu_to_be32(flags
);
4749 desc
->length
= cpu_to_be32(sizeof(desc
->oed_info
));
4753 lpfc_rdp_res_oed_voltage_desc(struct fc_rdp_oed_sfp_desc
*desc
,
4758 desc
->tag
= cpu_to_be32(RDP_OED_DESC_TAG
);
4760 desc
->oed_info
.hi_alarm
=
4761 cpu_to_be16(page_a2
[SSF_VOLTAGE_HIGH_ALARM
]);
4762 desc
->oed_info
.lo_alarm
= cpu_to_be16(page_a2
[SSF_VOLTAGE_LOW_ALARM
]);
4763 desc
->oed_info
.hi_warning
=
4764 cpu_to_be16(page_a2
[SSF_VOLTAGE_HIGH_WARNING
]);
4765 desc
->oed_info
.lo_warning
=
4766 cpu_to_be16(page_a2
[SSF_VOLTAGE_LOW_WARNING
]);
4767 flags
= 0xf; /* All four are valid */
4768 flags
|= ((0xf & RDP_OED_VOLTAGE
) << RDP_OED_TYPE_SHIFT
);
4769 desc
->oed_info
.function_flags
= cpu_to_be32(flags
);
4770 desc
->length
= cpu_to_be32(sizeof(desc
->oed_info
));
4774 lpfc_rdp_res_oed_txbias_desc(struct fc_rdp_oed_sfp_desc
*desc
,
4779 desc
->tag
= cpu_to_be32(RDP_OED_DESC_TAG
);
4781 desc
->oed_info
.hi_alarm
=
4782 cpu_to_be16(page_a2
[SSF_BIAS_HIGH_ALARM
]);
4783 desc
->oed_info
.lo_alarm
= cpu_to_be16(page_a2
[SSF_BIAS_LOW_ALARM
]);
4784 desc
->oed_info
.hi_warning
=
4785 cpu_to_be16(page_a2
[SSF_BIAS_HIGH_WARNING
]);
4786 desc
->oed_info
.lo_warning
=
4787 cpu_to_be16(page_a2
[SSF_BIAS_LOW_WARNING
]);
4788 flags
= 0xf; /* All four are valid */
4789 flags
|= ((0xf & RDP_OED_TXBIAS
) << RDP_OED_TYPE_SHIFT
);
4790 desc
->oed_info
.function_flags
= cpu_to_be32(flags
);
4791 desc
->length
= cpu_to_be32(sizeof(desc
->oed_info
));
4795 lpfc_rdp_res_oed_txpower_desc(struct fc_rdp_oed_sfp_desc
*desc
,
4800 desc
->tag
= cpu_to_be32(RDP_OED_DESC_TAG
);
4802 desc
->oed_info
.hi_alarm
=
4803 cpu_to_be16(page_a2
[SSF_TXPOWER_HIGH_ALARM
]);
4804 desc
->oed_info
.lo_alarm
= cpu_to_be16(page_a2
[SSF_TXPOWER_LOW_ALARM
]);
4805 desc
->oed_info
.hi_warning
=
4806 cpu_to_be16(page_a2
[SSF_TXPOWER_HIGH_WARNING
]);
4807 desc
->oed_info
.lo_warning
=
4808 cpu_to_be16(page_a2
[SSF_TXPOWER_LOW_WARNING
]);
4809 flags
= 0xf; /* All four are valid */
4810 flags
|= ((0xf & RDP_OED_TXPOWER
) << RDP_OED_TYPE_SHIFT
);
4811 desc
->oed_info
.function_flags
= cpu_to_be32(flags
);
4812 desc
->length
= cpu_to_be32(sizeof(desc
->oed_info
));
4817 lpfc_rdp_res_oed_rxpower_desc(struct fc_rdp_oed_sfp_desc
*desc
,
4822 desc
->tag
= cpu_to_be32(RDP_OED_DESC_TAG
);
4824 desc
->oed_info
.hi_alarm
=
4825 cpu_to_be16(page_a2
[SSF_RXPOWER_HIGH_ALARM
]);
4826 desc
->oed_info
.lo_alarm
= cpu_to_be16(page_a2
[SSF_RXPOWER_LOW_ALARM
]);
4827 desc
->oed_info
.hi_warning
=
4828 cpu_to_be16(page_a2
[SSF_RXPOWER_HIGH_WARNING
]);
4829 desc
->oed_info
.lo_warning
=
4830 cpu_to_be16(page_a2
[SSF_RXPOWER_LOW_WARNING
]);
4831 flags
= 0xf; /* All four are valid */
4832 flags
|= ((0xf & RDP_OED_RXPOWER
) << RDP_OED_TYPE_SHIFT
);
4833 desc
->oed_info
.function_flags
= cpu_to_be32(flags
);
4834 desc
->length
= cpu_to_be32(sizeof(desc
->oed_info
));
4838 lpfc_rdp_res_opd_desc(struct fc_rdp_opd_sfp_desc
*desc
,
4839 uint8_t *page_a0
, struct lpfc_vport
*vport
)
4841 desc
->tag
= cpu_to_be32(RDP_OPD_DESC_TAG
);
4842 memcpy(desc
->opd_info
.vendor_name
, &page_a0
[SSF_VENDOR_NAME
], 16);
4843 memcpy(desc
->opd_info
.model_number
, &page_a0
[SSF_VENDOR_PN
], 16);
4844 memcpy(desc
->opd_info
.serial_number
, &page_a0
[SSF_VENDOR_SN
], 16);
4845 memcpy(desc
->opd_info
.revision
, &page_a0
[SSF_VENDOR_REV
], 2);
4846 memcpy(desc
->opd_info
.date
, &page_a0
[SSF_DATE_CODE
], 8);
4847 desc
->length
= cpu_to_be32(sizeof(desc
->opd_info
));
4851 lpfc_rdp_res_fec_desc(struct fc_fec_rdp_desc
*desc
, READ_LNK_VAR
*stat
)
4853 if (bf_get(lpfc_read_link_stat_gec2
, stat
) == 0)
4855 desc
->tag
= cpu_to_be32(RDP_FEC_DESC_TAG
);
4857 desc
->info
.CorrectedBlocks
=
4858 cpu_to_be32(stat
->fecCorrBlkCount
);
4859 desc
->info
.UncorrectableBlocks
=
4860 cpu_to_be32(stat
->fecUncorrBlkCount
);
4862 desc
->length
= cpu_to_be32(sizeof(desc
->info
));
4864 return sizeof(struct fc_fec_rdp_desc
);
4868 lpfc_rdp_res_speed(struct fc_rdp_port_speed_desc
*desc
, struct lpfc_hba
*phba
)
4870 uint16_t rdp_cap
= 0;
4873 desc
->tag
= cpu_to_be32(RDP_PORT_SPEED_DESC_TAG
);
4875 switch (phba
->fc_linkspeed
) {
4876 case LPFC_LINK_SPEED_1GHZ
:
4877 rdp_speed
= RDP_PS_1GB
;
4879 case LPFC_LINK_SPEED_2GHZ
:
4880 rdp_speed
= RDP_PS_2GB
;
4882 case LPFC_LINK_SPEED_4GHZ
:
4883 rdp_speed
= RDP_PS_4GB
;
4885 case LPFC_LINK_SPEED_8GHZ
:
4886 rdp_speed
= RDP_PS_8GB
;
4888 case LPFC_LINK_SPEED_10GHZ
:
4889 rdp_speed
= RDP_PS_10GB
;
4891 case LPFC_LINK_SPEED_16GHZ
:
4892 rdp_speed
= RDP_PS_16GB
;
4894 case LPFC_LINK_SPEED_32GHZ
:
4895 rdp_speed
= RDP_PS_32GB
;
4898 rdp_speed
= RDP_PS_UNKNOWN
;
4902 desc
->info
.port_speed
.speed
= cpu_to_be16(rdp_speed
);
4904 if (phba
->lmt
& LMT_32Gb
)
4905 rdp_cap
|= RDP_PS_32GB
;
4906 if (phba
->lmt
& LMT_16Gb
)
4907 rdp_cap
|= RDP_PS_16GB
;
4908 if (phba
->lmt
& LMT_10Gb
)
4909 rdp_cap
|= RDP_PS_10GB
;
4910 if (phba
->lmt
& LMT_8Gb
)
4911 rdp_cap
|= RDP_PS_8GB
;
4912 if (phba
->lmt
& LMT_4Gb
)
4913 rdp_cap
|= RDP_PS_4GB
;
4914 if (phba
->lmt
& LMT_2Gb
)
4915 rdp_cap
|= RDP_PS_2GB
;
4916 if (phba
->lmt
& LMT_1Gb
)
4917 rdp_cap
|= RDP_PS_1GB
;
4920 rdp_cap
= RDP_CAP_UNKNOWN
;
4921 if (phba
->cfg_link_speed
!= LPFC_USER_LINK_SPEED_AUTO
)
4922 rdp_cap
|= RDP_CAP_USER_CONFIGURED
;
4924 desc
->info
.port_speed
.capabilities
= cpu_to_be16(rdp_cap
);
4925 desc
->length
= cpu_to_be32(sizeof(desc
->info
));
4929 lpfc_rdp_res_diag_port_names(struct fc_rdp_port_name_desc
*desc
,
4930 struct lpfc_hba
*phba
)
4933 desc
->tag
= cpu_to_be32(RDP_PORT_NAMES_DESC_TAG
);
4935 memcpy(desc
->port_names
.wwnn
, phba
->wwnn
,
4936 sizeof(desc
->port_names
.wwnn
));
4938 memcpy(desc
->port_names
.wwpn
, &phba
->wwpn
,
4939 sizeof(desc
->port_names
.wwpn
));
4941 desc
->length
= cpu_to_be32(sizeof(desc
->port_names
));
4945 lpfc_rdp_res_attach_port_names(struct fc_rdp_port_name_desc
*desc
,
4946 struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
4949 desc
->tag
= cpu_to_be32(RDP_PORT_NAMES_DESC_TAG
);
4950 if (vport
->fc_flag
& FC_FABRIC
) {
4951 memcpy(desc
->port_names
.wwnn
, &vport
->fabric_nodename
,
4952 sizeof(desc
->port_names
.wwnn
));
4954 memcpy(desc
->port_names
.wwpn
, &vport
->fabric_portname
,
4955 sizeof(desc
->port_names
.wwpn
));
4956 } else { /* Point to Point */
4957 memcpy(desc
->port_names
.wwnn
, &ndlp
->nlp_nodename
,
4958 sizeof(desc
->port_names
.wwnn
));
4960 memcpy(desc
->port_names
.wwnn
, &ndlp
->nlp_portname
,
4961 sizeof(desc
->port_names
.wwpn
));
4964 desc
->length
= cpu_to_be32(sizeof(desc
->port_names
));
4968 lpfc_els_rdp_cmpl(struct lpfc_hba
*phba
, struct lpfc_rdp_context
*rdp_context
,
4971 struct lpfc_nodelist
*ndlp
= rdp_context
->ndlp
;
4972 struct lpfc_vport
*vport
= ndlp
->vport
;
4973 struct lpfc_iocbq
*elsiocb
;
4974 struct ulp_bde64
*bpl
;
4977 struct ls_rjt
*stat
;
4978 struct fc_rdp_res_frame
*rdp_res
;
4982 if (status
!= SUCCESS
)
4985 /* This will change once we know the true size of the RDP payload */
4986 cmdsize
= sizeof(struct fc_rdp_res_frame
);
4988 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
,
4989 lpfc_max_els_tries
, rdp_context
->ndlp
,
4990 rdp_context
->ndlp
->nlp_DID
, ELS_CMD_ACC
);
4993 goto free_rdp_context
;
4995 icmd
= &elsiocb
->iocb
;
4996 icmd
->ulpContext
= rdp_context
->rx_id
;
4997 icmd
->unsli3
.rcvsli3
.ox_id
= rdp_context
->ox_id
;
4999 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
5000 "2171 Xmit RDP response tag x%x xri x%x, "
5001 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x",
5002 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
5003 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
5005 rdp_res
= (struct fc_rdp_res_frame
*)
5006 (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
5007 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
5008 memset(pcmd
, 0, sizeof(struct fc_rdp_res_frame
));
5009 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
5011 /* For RDP payload */
5012 lpfc_rdp_res_link_service(&rdp_res
->link_service_desc
, ELS_CMD_RDP
);
5014 lpfc_rdp_res_sfp_desc(&rdp_res
->sfp_desc
,
5015 rdp_context
->page_a0
, rdp_context
->page_a2
);
5016 lpfc_rdp_res_speed(&rdp_res
->portspeed_desc
, phba
);
5017 lpfc_rdp_res_link_error(&rdp_res
->link_error_desc
,
5018 &rdp_context
->link_stat
);
5019 lpfc_rdp_res_diag_port_names(&rdp_res
->diag_port_names_desc
, phba
);
5020 lpfc_rdp_res_attach_port_names(&rdp_res
->attached_port_names_desc
,
5022 lpfc_rdp_res_bbc_desc(&rdp_res
->bbc_desc
, &rdp_context
->link_stat
,
5024 lpfc_rdp_res_oed_temp_desc(&rdp_res
->oed_temp_desc
,
5025 rdp_context
->page_a2
);
5026 lpfc_rdp_res_oed_voltage_desc(&rdp_res
->oed_voltage_desc
,
5027 rdp_context
->page_a2
);
5028 lpfc_rdp_res_oed_txbias_desc(&rdp_res
->oed_txbias_desc
,
5029 rdp_context
->page_a2
);
5030 lpfc_rdp_res_oed_txpower_desc(&rdp_res
->oed_txpower_desc
,
5031 rdp_context
->page_a2
);
5032 lpfc_rdp_res_oed_rxpower_desc(&rdp_res
->oed_rxpower_desc
,
5033 rdp_context
->page_a2
);
5034 lpfc_rdp_res_opd_desc(&rdp_res
->opd_desc
, rdp_context
->page_a0
, vport
);
5035 fec_size
= lpfc_rdp_res_fec_desc(&rdp_res
->fec_desc
,
5036 &rdp_context
->link_stat
);
5037 rdp_res
->length
= cpu_to_be32(fec_size
+ RDP_DESC_PAYLOAD_SIZE
);
5038 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
5040 /* Now that we know the true size of the payload, update the BPL */
5041 bpl
= (struct ulp_bde64
*)
5042 (((struct lpfc_dmabuf
*)(elsiocb
->context3
))->virt
);
5043 bpl
->tus
.f
.bdeSize
= (fec_size
+ RDP_DESC_PAYLOAD_SIZE
+ 8);
5044 bpl
->tus
.f
.bdeFlags
= 0;
5045 bpl
->tus
.w
= le32_to_cpu(bpl
->tus
.w
);
5047 phba
->fc_stat
.elsXmitACC
++;
5048 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
5049 if (rc
== IOCB_ERROR
)
5050 lpfc_els_free_iocb(phba
, elsiocb
);
5056 cmdsize
= 2 * sizeof(uint32_t);
5057 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, lpfc_max_els_tries
,
5058 ndlp
, ndlp
->nlp_DID
, ELS_CMD_LS_RJT
);
5061 goto free_rdp_context
;
5063 icmd
= &elsiocb
->iocb
;
5064 icmd
->ulpContext
= rdp_context
->rx_id
;
5065 icmd
->unsli3
.rcvsli3
.ox_id
= rdp_context
->ox_id
;
5066 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
5068 *((uint32_t *) (pcmd
)) = ELS_CMD_LS_RJT
;
5069 stat
= (struct ls_rjt
*)(pcmd
+ sizeof(uint32_t));
5070 stat
->un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
5072 phba
->fc_stat
.elsXmitLSRJT
++;
5073 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
5074 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
5076 if (rc
== IOCB_ERROR
)
5077 lpfc_els_free_iocb(phba
, elsiocb
);
5083 lpfc_get_rdp_info(struct lpfc_hba
*phba
, struct lpfc_rdp_context
*rdp_context
)
5085 LPFC_MBOXQ_t
*mbox
= NULL
;
5088 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
5090 lpfc_printf_log(phba
, KERN_WARNING
, LOG_MBOX
| LOG_ELS
,
5091 "7105 failed to allocate mailbox memory");
5095 if (lpfc_sli4_dump_page_a0(phba
, mbox
))
5096 goto prep_mbox_fail
;
5097 mbox
->vport
= rdp_context
->ndlp
->vport
;
5098 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_rdp_page_a0
;
5099 mbox
->context2
= (struct lpfc_rdp_context
*) rdp_context
;
5100 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
5101 if (rc
== MBX_NOT_FINISHED
)
5102 goto issue_mbox_fail
;
5108 mempool_free(mbox
, phba
->mbox_mem_pool
);
5113 * lpfc_els_rcv_rdp - Process an unsolicited RDP ELS.
5114 * @vport: pointer to a host virtual N_Port data structure.
5115 * @cmdiocb: pointer to lpfc command iocb data structure.
5116 * @ndlp: pointer to a node-list data structure.
5118 * This routine processes an unsolicited RDP(Read Diagnostic Parameters)
5119 * IOCB. First, the payload of the unsolicited RDP is checked.
5120 * Then it will (1) send MBX_DUMP_MEMORY, Embedded DMP_LMSD sub command TYPE-3
5121 * for Page A0, (2) send MBX_DUMP_MEMORY, DMP_LMSD for Page A2,
5122 * (3) send MBX_READ_LNK_STAT to get link stat, (4) Call lpfc_els_rdp_cmpl
5123 * gather all data and send RDP response.
5126 * 0 - Sent the acc response
5127 * 1 - Sent the reject response.
5130 lpfc_els_rcv_rdp(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
5131 struct lpfc_nodelist
*ndlp
)
5133 struct lpfc_hba
*phba
= vport
->phba
;
5134 struct lpfc_dmabuf
*pcmd
;
5135 uint8_t rjt_err
, rjt_expl
= LSEXP_NOTHING_MORE
;
5136 struct fc_rdp_req_frame
*rdp_req
;
5137 struct lpfc_rdp_context
*rdp_context
;
5141 if (phba
->sli_rev
< LPFC_SLI_REV4
||
5142 (bf_get(lpfc_sli_intf_if_type
,
5143 &phba
->sli4_hba
.sli_intf
) !=
5144 LPFC_SLI_INTF_IF_TYPE_2
)) {
5145 rjt_err
= LSRJT_UNABLE_TPC
;
5146 rjt_expl
= LSEXP_REQ_UNSUPPORTED
;
5150 if (phba
->sli_rev
< LPFC_SLI_REV4
|| (phba
->hba_flag
& HBA_FCOE_MODE
)) {
5151 rjt_err
= LSRJT_UNABLE_TPC
;
5152 rjt_expl
= LSEXP_REQ_UNSUPPORTED
;
5156 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
5157 rdp_req
= (struct fc_rdp_req_frame
*) pcmd
->virt
;
5160 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
5161 "2422 ELS RDP Request "
5162 "dec len %d tag x%x port_id %d len %d\n",
5163 be32_to_cpu(rdp_req
->rdp_des_length
),
5164 be32_to_cpu(rdp_req
->nport_id_desc
.tag
),
5165 be32_to_cpu(rdp_req
->nport_id_desc
.nport_id
),
5166 be32_to_cpu(rdp_req
->nport_id_desc
.length
));
5168 if (sizeof(struct fc_rdp_nport_desc
) !=
5169 be32_to_cpu(rdp_req
->rdp_des_length
))
5171 if (RDP_N_PORT_DESC_TAG
!= be32_to_cpu(rdp_req
->nport_id_desc
.tag
))
5173 if (RDP_NPORT_ID_SIZE
!=
5174 be32_to_cpu(rdp_req
->nport_id_desc
.length
))
5176 rdp_context
= kzalloc(sizeof(struct lpfc_rdp_context
), GFP_KERNEL
);
5178 rjt_err
= LSRJT_UNABLE_TPC
;
5182 cmd
= &cmdiocb
->iocb
;
5183 rdp_context
->ndlp
= lpfc_nlp_get(ndlp
);
5184 rdp_context
->ox_id
= cmd
->unsli3
.rcvsli3
.ox_id
;
5185 rdp_context
->rx_id
= cmd
->ulpContext
;
5186 rdp_context
->cmpl
= lpfc_els_rdp_cmpl
;
5187 if (lpfc_get_rdp_info(phba
, rdp_context
)) {
5188 lpfc_printf_vlog(ndlp
->vport
, KERN_WARNING
, LOG_ELS
,
5189 "2423 Unable to send mailbox");
5191 rjt_err
= LSRJT_UNABLE_TPC
;
5199 rjt_err
= LSRJT_LOGICAL_ERR
;
5202 memset(&stat
, 0, sizeof(stat
));
5203 stat
.un
.b
.lsRjtRsnCode
= rjt_err
;
5204 stat
.un
.b
.lsRjtRsnCodeExp
= rjt_expl
;
5205 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
5211 lpfc_els_lcb_rsp(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
5216 struct lpfc_iocbq
*elsiocb
;
5217 struct lpfc_nodelist
*ndlp
;
5218 struct ls_rjt
*stat
;
5219 union lpfc_sli4_cfg_shdr
*shdr
;
5220 struct lpfc_lcb_context
*lcb_context
;
5221 struct fc_lcb_res_frame
*lcb_res
;
5222 uint32_t cmdsize
, shdr_status
, shdr_add_status
;
5226 lcb_context
= (struct lpfc_lcb_context
*)pmb
->context1
;
5227 ndlp
= lcb_context
->ndlp
;
5228 pmb
->context1
= NULL
;
5229 pmb
->context2
= NULL
;
5231 shdr
= (union lpfc_sli4_cfg_shdr
*)
5232 &pmb
->u
.mqe
.un
.beacon_config
.header
.cfg_shdr
;
5233 shdr_status
= bf_get(lpfc_mbox_hdr_status
, &shdr
->response
);
5234 shdr_add_status
= bf_get(lpfc_mbox_hdr_add_status
, &shdr
->response
);
5236 lpfc_printf_log(phba
, KERN_INFO
, LOG_MBOX
,
5237 "0194 SET_BEACON_CONFIG mailbox "
5238 "completed with status x%x add_status x%x,"
5239 " mbx status x%x\n",
5240 shdr_status
, shdr_add_status
, mb
->mbxStatus
);
5242 if (mb
->mbxStatus
&& !(shdr_status
&&
5243 shdr_add_status
== ADD_STATUS_OPERATION_ALREADY_ACTIVE
)) {
5244 mempool_free(pmb
, phba
->mbox_mem_pool
);
5248 mempool_free(pmb
, phba
->mbox_mem_pool
);
5249 cmdsize
= sizeof(struct fc_lcb_res_frame
);
5250 elsiocb
= lpfc_prep_els_iocb(phba
->pport
, 0, cmdsize
,
5251 lpfc_max_els_tries
, ndlp
,
5252 ndlp
->nlp_DID
, ELS_CMD_ACC
);
5254 /* Decrement the ndlp reference count from previous mbox command */
5258 goto free_lcb_context
;
5260 lcb_res
= (struct fc_lcb_res_frame
*)
5261 (((struct lpfc_dmabuf
*)elsiocb
->context2
)->virt
);
5263 icmd
= &elsiocb
->iocb
;
5264 icmd
->ulpContext
= lcb_context
->rx_id
;
5265 icmd
->unsli3
.rcvsli3
.ox_id
= lcb_context
->ox_id
;
5267 pcmd
= (uint8_t *)(((struct lpfc_dmabuf
*)elsiocb
->context2
)->virt
);
5268 *((uint32_t *)(pcmd
)) = ELS_CMD_ACC
;
5269 lcb_res
->lcb_sub_command
= lcb_context
->sub_command
;
5270 lcb_res
->lcb_type
= lcb_context
->type
;
5271 lcb_res
->lcb_frequency
= lcb_context
->frequency
;
5272 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
5273 phba
->fc_stat
.elsXmitACC
++;
5274 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
5275 if (rc
== IOCB_ERROR
)
5276 lpfc_els_free_iocb(phba
, elsiocb
);
5282 cmdsize
= sizeof(struct fc_lcb_res_frame
);
5283 elsiocb
= lpfc_prep_els_iocb(phba
->pport
, 0, cmdsize
,
5284 lpfc_max_els_tries
, ndlp
,
5285 ndlp
->nlp_DID
, ELS_CMD_LS_RJT
);
5288 goto free_lcb_context
;
5290 icmd
= &elsiocb
->iocb
;
5291 icmd
->ulpContext
= lcb_context
->rx_id
;
5292 icmd
->unsli3
.rcvsli3
.ox_id
= lcb_context
->ox_id
;
5293 pcmd
= (uint8_t *)(((struct lpfc_dmabuf
*)elsiocb
->context2
)->virt
);
5295 *((uint32_t *)(pcmd
)) = ELS_CMD_LS_RJT
;
5296 stat
= (struct ls_rjt
*)(pcmd
+ sizeof(uint32_t));
5297 stat
->un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
5299 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
5300 phba
->fc_stat
.elsXmitLSRJT
++;
5301 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
5302 if (rc
== IOCB_ERROR
)
5303 lpfc_els_free_iocb(phba
, elsiocb
);
5309 lpfc_sli4_set_beacon(struct lpfc_vport
*vport
,
5310 struct lpfc_lcb_context
*lcb_context
,
5311 uint32_t beacon_state
)
5313 struct lpfc_hba
*phba
= vport
->phba
;
5314 LPFC_MBOXQ_t
*mbox
= NULL
;
5318 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
5322 len
= sizeof(struct lpfc_mbx_set_beacon_config
) -
5323 sizeof(struct lpfc_sli4_cfg_mhdr
);
5324 lpfc_sli4_config(phba
, mbox
, LPFC_MBOX_SUBSYSTEM_COMMON
,
5325 LPFC_MBOX_OPCODE_SET_BEACON_CONFIG
, len
,
5326 LPFC_SLI4_MBX_EMBED
);
5327 mbox
->context1
= (void *)lcb_context
;
5328 mbox
->vport
= phba
->pport
;
5329 mbox
->mbox_cmpl
= lpfc_els_lcb_rsp
;
5330 bf_set(lpfc_mbx_set_beacon_port_num
, &mbox
->u
.mqe
.un
.beacon_config
,
5331 phba
->sli4_hba
.physical_port
);
5332 bf_set(lpfc_mbx_set_beacon_state
, &mbox
->u
.mqe
.un
.beacon_config
,
5334 bf_set(lpfc_mbx_set_beacon_port_type
, &mbox
->u
.mqe
.un
.beacon_config
, 1);
5335 bf_set(lpfc_mbx_set_beacon_duration
, &mbox
->u
.mqe
.un
.beacon_config
, 0);
5336 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
5337 if (rc
== MBX_NOT_FINISHED
) {
5338 mempool_free(mbox
, phba
->mbox_mem_pool
);
5347 * lpfc_els_rcv_lcb - Process an unsolicited LCB
5348 * @vport: pointer to a host virtual N_Port data structure.
5349 * @cmdiocb: pointer to lpfc command iocb data structure.
5350 * @ndlp: pointer to a node-list data structure.
5352 * This routine processes an unsolicited LCB(LINK CABLE BEACON) IOCB.
5353 * First, the payload of the unsolicited LCB is checked.
5354 * Then based on Subcommand beacon will either turn on or off.
5357 * 0 - Sent the acc response
5358 * 1 - Sent the reject response.
5361 lpfc_els_rcv_lcb(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
5362 struct lpfc_nodelist
*ndlp
)
5364 struct lpfc_hba
*phba
= vport
->phba
;
5365 struct lpfc_dmabuf
*pcmd
;
5367 struct fc_lcb_request_frame
*beacon
;
5368 struct lpfc_lcb_context
*lcb_context
;
5369 uint8_t state
, rjt_err
;
5372 pcmd
= (struct lpfc_dmabuf
*)cmdiocb
->context2
;
5373 lp
= (uint8_t *)pcmd
->virt
;
5374 beacon
= (struct fc_lcb_request_frame
*)pcmd
->virt
;
5376 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
5377 "0192 ELS LCB Data x%x x%x x%x x%x sub x%x "
5378 "type x%x frequency %x duration x%x\n",
5379 lp
[0], lp
[1], lp
[2],
5380 beacon
->lcb_command
,
5381 beacon
->lcb_sub_command
,
5383 beacon
->lcb_frequency
,
5384 be16_to_cpu(beacon
->lcb_duration
));
5386 if (phba
->sli_rev
< LPFC_SLI_REV4
||
5387 (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) !=
5388 LPFC_SLI_INTF_IF_TYPE_2
)) {
5389 rjt_err
= LSRJT_CMD_UNSUPPORTED
;
5393 if (phba
->hba_flag
& HBA_FCOE_MODE
) {
5394 rjt_err
= LSRJT_CMD_UNSUPPORTED
;
5397 if (beacon
->lcb_frequency
== 0) {
5398 rjt_err
= LSRJT_CMD_UNSUPPORTED
;
5401 if ((beacon
->lcb_type
!= LPFC_LCB_GREEN
) &&
5402 (beacon
->lcb_type
!= LPFC_LCB_AMBER
)) {
5403 rjt_err
= LSRJT_CMD_UNSUPPORTED
;
5406 if ((beacon
->lcb_sub_command
!= LPFC_LCB_ON
) &&
5407 (beacon
->lcb_sub_command
!= LPFC_LCB_OFF
)) {
5408 rjt_err
= LSRJT_CMD_UNSUPPORTED
;
5411 if ((beacon
->lcb_sub_command
== LPFC_LCB_ON
) &&
5412 (beacon
->lcb_type
!= LPFC_LCB_GREEN
) &&
5413 (beacon
->lcb_type
!= LPFC_LCB_AMBER
)) {
5414 rjt_err
= LSRJT_CMD_UNSUPPORTED
;
5417 if (be16_to_cpu(beacon
->lcb_duration
) != 0) {
5418 rjt_err
= LSRJT_CMD_UNSUPPORTED
;
5422 lcb_context
= kmalloc(sizeof(*lcb_context
), GFP_KERNEL
);
5424 rjt_err
= LSRJT_UNABLE_TPC
;
5428 state
= (beacon
->lcb_sub_command
== LPFC_LCB_ON
) ? 1 : 0;
5429 lcb_context
->sub_command
= beacon
->lcb_sub_command
;
5430 lcb_context
->type
= beacon
->lcb_type
;
5431 lcb_context
->frequency
= beacon
->lcb_frequency
;
5432 lcb_context
->ox_id
= cmdiocb
->iocb
.unsli3
.rcvsli3
.ox_id
;
5433 lcb_context
->rx_id
= cmdiocb
->iocb
.ulpContext
;
5434 lcb_context
->ndlp
= lpfc_nlp_get(ndlp
);
5435 if (lpfc_sli4_set_beacon(vport
, lcb_context
, state
)) {
5436 lpfc_printf_vlog(ndlp
->vport
, KERN_ERR
,
5437 LOG_ELS
, "0193 failed to send mail box");
5440 rjt_err
= LSRJT_UNABLE_TPC
;
5445 memset(&stat
, 0, sizeof(stat
));
5446 stat
.un
.b
.lsRjtRsnCode
= rjt_err
;
5447 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
5453 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
5454 * @vport: pointer to a host virtual N_Port data structure.
5456 * This routine cleans up any Registration State Change Notification
5457 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
5458 * @vport together with the host_lock is used to prevent multiple thread
5459 * trying to access the RSCN array on a same @vport at the same time.
5462 lpfc_els_flush_rscn(struct lpfc_vport
*vport
)
5464 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
5465 struct lpfc_hba
*phba
= vport
->phba
;
5468 spin_lock_irq(shost
->host_lock
);
5469 if (vport
->fc_rscn_flush
) {
5470 /* Another thread is walking fc_rscn_id_list on this vport */
5471 spin_unlock_irq(shost
->host_lock
);
5474 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
5475 vport
->fc_rscn_flush
= 1;
5476 spin_unlock_irq(shost
->host_lock
);
5478 for (i
= 0; i
< vport
->fc_rscn_id_cnt
; i
++) {
5479 lpfc_in_buf_free(phba
, vport
->fc_rscn_id_list
[i
]);
5480 vport
->fc_rscn_id_list
[i
] = NULL
;
5482 spin_lock_irq(shost
->host_lock
);
5483 vport
->fc_rscn_id_cnt
= 0;
5484 vport
->fc_flag
&= ~(FC_RSCN_MODE
| FC_RSCN_DISCOVERY
);
5485 spin_unlock_irq(shost
->host_lock
);
5486 lpfc_can_disctmo(vport
);
5487 /* Indicate we are done walking this fc_rscn_id_list */
5488 vport
->fc_rscn_flush
= 0;
5492 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
5493 * @vport: pointer to a host virtual N_Port data structure.
5494 * @did: remote destination port identifier.
5496 * This routine checks whether there is any pending Registration State
5497 * Configuration Notification (RSCN) to a @did on @vport.
5500 * None zero - The @did matched with a pending rscn
5501 * 0 - not able to match @did with a pending rscn
5504 lpfc_rscn_payload_check(struct lpfc_vport
*vport
, uint32_t did
)
5509 uint32_t payload_len
, i
;
5510 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
5512 ns_did
.un
.word
= did
;
5514 /* Never match fabric nodes for RSCNs */
5515 if ((did
& Fabric_DID_MASK
) == Fabric_DID_MASK
)
5518 /* If we are doing a FULL RSCN rediscovery, match everything */
5519 if (vport
->fc_flag
& FC_RSCN_DISCOVERY
)
5522 spin_lock_irq(shost
->host_lock
);
5523 if (vport
->fc_rscn_flush
) {
5524 /* Another thread is walking fc_rscn_id_list on this vport */
5525 spin_unlock_irq(shost
->host_lock
);
5528 /* Indicate we are walking fc_rscn_id_list on this vport */
5529 vport
->fc_rscn_flush
= 1;
5530 spin_unlock_irq(shost
->host_lock
);
5531 for (i
= 0; i
< vport
->fc_rscn_id_cnt
; i
++) {
5532 lp
= vport
->fc_rscn_id_list
[i
]->virt
;
5533 payload_len
= be32_to_cpu(*lp
++ & ~ELS_CMD_MASK
);
5534 payload_len
-= sizeof(uint32_t); /* take off word 0 */
5535 while (payload_len
) {
5536 rscn_did
.un
.word
= be32_to_cpu(*lp
++);
5537 payload_len
-= sizeof(uint32_t);
5538 switch (rscn_did
.un
.b
.resv
& RSCN_ADDRESS_FORMAT_MASK
) {
5539 case RSCN_ADDRESS_FORMAT_PORT
:
5540 if ((ns_did
.un
.b
.domain
== rscn_did
.un
.b
.domain
)
5541 && (ns_did
.un
.b
.area
== rscn_did
.un
.b
.area
)
5542 && (ns_did
.un
.b
.id
== rscn_did
.un
.b
.id
))
5543 goto return_did_out
;
5545 case RSCN_ADDRESS_FORMAT_AREA
:
5546 if ((ns_did
.un
.b
.domain
== rscn_did
.un
.b
.domain
)
5547 && (ns_did
.un
.b
.area
== rscn_did
.un
.b
.area
))
5548 goto return_did_out
;
5550 case RSCN_ADDRESS_FORMAT_DOMAIN
:
5551 if (ns_did
.un
.b
.domain
== rscn_did
.un
.b
.domain
)
5552 goto return_did_out
;
5554 case RSCN_ADDRESS_FORMAT_FABRIC
:
5555 goto return_did_out
;
5559 /* Indicate we are done with walking fc_rscn_id_list on this vport */
5560 vport
->fc_rscn_flush
= 0;
5563 /* Indicate we are done with walking fc_rscn_id_list on this vport */
5564 vport
->fc_rscn_flush
= 0;
5569 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
5570 * @vport: pointer to a host virtual N_Port data structure.
5572 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
5573 * state machine for a @vport's nodes that are with pending RSCN (Registration
5574 * State Change Notification).
5577 * 0 - Successful (currently alway return 0)
5580 lpfc_rscn_recovery_check(struct lpfc_vport
*vport
)
5582 struct lpfc_nodelist
*ndlp
= NULL
;
5584 /* Move all affected nodes by pending RSCNs to NPR state. */
5585 list_for_each_entry(ndlp
, &vport
->fc_nodes
, nlp_listp
) {
5586 if (!NLP_CHK_NODE_ACT(ndlp
) ||
5587 (ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
) ||
5588 !lpfc_rscn_payload_check(vport
, ndlp
->nlp_DID
))
5590 lpfc_disc_state_machine(vport
, ndlp
, NULL
,
5591 NLP_EVT_DEVICE_RECOVERY
);
5592 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
5598 * lpfc_send_rscn_event - Send an RSCN event to management application
5599 * @vport: pointer to a host virtual N_Port data structure.
5600 * @cmdiocb: pointer to lpfc command iocb data structure.
5602 * lpfc_send_rscn_event sends an RSCN netlink event to management
5606 lpfc_send_rscn_event(struct lpfc_vport
*vport
,
5607 struct lpfc_iocbq
*cmdiocb
)
5609 struct lpfc_dmabuf
*pcmd
;
5610 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
5611 uint32_t *payload_ptr
;
5612 uint32_t payload_len
;
5613 struct lpfc_rscn_event_header
*rscn_event_data
;
5615 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
5616 payload_ptr
= (uint32_t *) pcmd
->virt
;
5617 payload_len
= be32_to_cpu(*payload_ptr
& ~ELS_CMD_MASK
);
5619 rscn_event_data
= kmalloc(sizeof(struct lpfc_rscn_event_header
) +
5620 payload_len
, GFP_KERNEL
);
5621 if (!rscn_event_data
) {
5622 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
5623 "0147 Failed to allocate memory for RSCN event\n");
5626 rscn_event_data
->event_type
= FC_REG_RSCN_EVENT
;
5627 rscn_event_data
->payload_length
= payload_len
;
5628 memcpy(rscn_event_data
->rscn_payload
, payload_ptr
,
5631 fc_host_post_vendor_event(shost
,
5632 fc_get_event_number(),
5633 sizeof(struct lpfc_rscn_event_header
) + payload_len
,
5634 (char *)rscn_event_data
,
5637 kfree(rscn_event_data
);
5641 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
5642 * @vport: pointer to a host virtual N_Port data structure.
5643 * @cmdiocb: pointer to lpfc command iocb data structure.
5644 * @ndlp: pointer to a node-list data structure.
5646 * This routine processes an unsolicited RSCN (Registration State Change
5647 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
5648 * to invoke fc_host_post_event() routine to the FC transport layer. If the
5649 * discover state machine is about to begin discovery, it just accepts the
5650 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
5651 * contains N_Port IDs for other vports on this HBA, it just accepts the
5652 * RSCN and ignore processing it. If the state machine is in the recovery
5653 * state, the fc_rscn_id_list of this @vport is walked and the
5654 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
5655 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
5656 * routine is invoked to handle the RSCN event.
5659 * 0 - Just sent the acc response
5660 * 1 - Sent the acc response and waited for name server completion
5663 lpfc_els_rcv_rscn(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
5664 struct lpfc_nodelist
*ndlp
)
5666 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
5667 struct lpfc_hba
*phba
= vport
->phba
;
5668 struct lpfc_dmabuf
*pcmd
;
5669 uint32_t *lp
, *datap
;
5670 uint32_t payload_len
, length
, nportid
, *cmd
;
5672 int rscn_id
= 0, hba_id
= 0;
5675 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
5676 lp
= (uint32_t *) pcmd
->virt
;
5678 payload_len
= be32_to_cpu(*lp
++ & ~ELS_CMD_MASK
);
5679 payload_len
-= sizeof(uint32_t); /* take off word 0 */
5681 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
5682 "0214 RSCN received Data: x%x x%x x%x x%x\n",
5683 vport
->fc_flag
, payload_len
, *lp
,
5684 vport
->fc_rscn_id_cnt
);
5686 /* Send an RSCN event to the management application */
5687 lpfc_send_rscn_event(vport
, cmdiocb
);
5689 for (i
= 0; i
< payload_len
/sizeof(uint32_t); i
++)
5690 fc_host_post_event(shost
, fc_get_event_number(),
5691 FCH_EVT_RSCN
, lp
[i
]);
5693 /* If we are about to begin discovery, just ACC the RSCN.
5694 * Discovery processing will satisfy it.
5696 if (vport
->port_state
<= LPFC_NS_QRY
) {
5697 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
5698 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
5699 ndlp
->nlp_DID
, vport
->port_state
, ndlp
->nlp_flag
);
5701 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
5705 /* If this RSCN just contains NPortIDs for other vports on this HBA,
5706 * just ACC and ignore it.
5708 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
5709 !(vport
->cfg_peer_port_login
)) {
5714 nportid
= ((be32_to_cpu(nportid
)) & Mask_DID
);
5715 i
-= sizeof(uint32_t);
5717 if (lpfc_find_vport_by_did(phba
, nportid
))
5720 if (rscn_id
== hba_id
) {
5721 /* ALL NPortIDs in RSCN are on HBA */
5722 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
5724 "Data: x%x x%x x%x x%x\n",
5725 vport
->fc_flag
, payload_len
,
5726 *lp
, vport
->fc_rscn_id_cnt
);
5727 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
5728 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
5729 ndlp
->nlp_DID
, vport
->port_state
,
5732 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
,
5738 spin_lock_irq(shost
->host_lock
);
5739 if (vport
->fc_rscn_flush
) {
5740 /* Another thread is walking fc_rscn_id_list on this vport */
5741 vport
->fc_flag
|= FC_RSCN_DISCOVERY
;
5742 spin_unlock_irq(shost
->host_lock
);
5744 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
5747 /* Indicate we are walking fc_rscn_id_list on this vport */
5748 vport
->fc_rscn_flush
= 1;
5749 spin_unlock_irq(shost
->host_lock
);
5750 /* Get the array count after successfully have the token */
5751 rscn_cnt
= vport
->fc_rscn_id_cnt
;
5752 /* If we are already processing an RSCN, save the received
5753 * RSCN payload buffer, cmdiocb->context2 to process later.
5755 if (vport
->fc_flag
& (FC_RSCN_MODE
| FC_NDISC_ACTIVE
)) {
5756 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
5757 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
5758 ndlp
->nlp_DID
, vport
->port_state
, ndlp
->nlp_flag
);
5760 spin_lock_irq(shost
->host_lock
);
5761 vport
->fc_flag
|= FC_RSCN_DEFERRED
;
5762 if ((rscn_cnt
< FC_MAX_HOLD_RSCN
) &&
5763 !(vport
->fc_flag
& FC_RSCN_DISCOVERY
)) {
5764 vport
->fc_flag
|= FC_RSCN_MODE
;
5765 spin_unlock_irq(shost
->host_lock
);
5767 cmd
= vport
->fc_rscn_id_list
[rscn_cnt
-1]->virt
;
5768 length
= be32_to_cpu(*cmd
& ~ELS_CMD_MASK
);
5771 (payload_len
+ length
<= LPFC_BPL_SIZE
)) {
5772 *cmd
&= ELS_CMD_MASK
;
5773 *cmd
|= cpu_to_be32(payload_len
+ length
);
5774 memcpy(((uint8_t *)cmd
) + length
, lp
,
5777 vport
->fc_rscn_id_list
[rscn_cnt
] = pcmd
;
5778 vport
->fc_rscn_id_cnt
++;
5779 /* If we zero, cmdiocb->context2, the calling
5780 * routine will not try to free it.
5782 cmdiocb
->context2
= NULL
;
5785 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
5786 "0235 Deferred RSCN "
5787 "Data: x%x x%x x%x\n",
5788 vport
->fc_rscn_id_cnt
, vport
->fc_flag
,
5791 vport
->fc_flag
|= FC_RSCN_DISCOVERY
;
5792 spin_unlock_irq(shost
->host_lock
);
5793 /* ReDiscovery RSCN */
5794 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
5795 "0234 ReDiscovery RSCN "
5796 "Data: x%x x%x x%x\n",
5797 vport
->fc_rscn_id_cnt
, vport
->fc_flag
,
5800 /* Indicate we are done walking fc_rscn_id_list on this vport */
5801 vport
->fc_rscn_flush
= 0;
5803 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
5804 /* send RECOVERY event for ALL nodes that match RSCN payload */
5805 lpfc_rscn_recovery_check(vport
);
5806 spin_lock_irq(shost
->host_lock
);
5807 vport
->fc_flag
&= ~FC_RSCN_DEFERRED
;
5808 spin_unlock_irq(shost
->host_lock
);
5811 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
5812 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
5813 ndlp
->nlp_DID
, vport
->port_state
, ndlp
->nlp_flag
);
5815 spin_lock_irq(shost
->host_lock
);
5816 vport
->fc_flag
|= FC_RSCN_MODE
;
5817 spin_unlock_irq(shost
->host_lock
);
5818 vport
->fc_rscn_id_list
[vport
->fc_rscn_id_cnt
++] = pcmd
;
5819 /* Indicate we are done walking fc_rscn_id_list on this vport */
5820 vport
->fc_rscn_flush
= 0;
5822 * If we zero, cmdiocb->context2, the calling routine will
5823 * not try to free it.
5825 cmdiocb
->context2
= NULL
;
5826 lpfc_set_disctmo(vport
);
5828 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
5829 /* send RECOVERY event for ALL nodes that match RSCN payload */
5830 lpfc_rscn_recovery_check(vport
);
5831 return lpfc_els_handle_rscn(vport
);
5835 * lpfc_els_handle_rscn - Handle rscn for a vport
5836 * @vport: pointer to a host virtual N_Port data structure.
5838 * This routine handles the Registration State Configuration Notification
5839 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
5840 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
5841 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
5842 * NameServer shall be issued. If CT command to the NameServer fails to be
5843 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
5844 * RSCN activities with the @vport.
5847 * 0 - Cleaned up rscn on the @vport
5848 * 1 - Wait for plogi to name server before proceed
5851 lpfc_els_handle_rscn(struct lpfc_vport
*vport
)
5853 struct lpfc_nodelist
*ndlp
;
5854 struct lpfc_hba
*phba
= vport
->phba
;
5856 /* Ignore RSCN if the port is being torn down. */
5857 if (vport
->load_flag
& FC_UNLOADING
) {
5858 lpfc_els_flush_rscn(vport
);
5862 /* Start timer for RSCN processing */
5863 lpfc_set_disctmo(vport
);
5865 /* RSCN processed */
5866 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
5867 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
5868 vport
->fc_flag
, 0, vport
->fc_rscn_id_cnt
,
5871 /* To process RSCN, first compare RSCN data with NameServer */
5872 vport
->fc_ns_retry
= 0;
5873 vport
->num_disc_nodes
= 0;
5875 ndlp
= lpfc_findnode_did(vport
, NameServer_DID
);
5876 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
)
5877 && ndlp
->nlp_state
== NLP_STE_UNMAPPED_NODE
) {
5878 /* Good ndlp, issue CT Request to NameServer */
5879 if (lpfc_ns_cmd(vport
, SLI_CTNS_GID_FT
, 0, 0) == 0)
5880 /* Wait for NameServer query cmpl before we can
5884 /* If login to NameServer does not exist, issue one */
5885 /* Good status, issue PLOGI to NameServer */
5886 ndlp
= lpfc_findnode_did(vport
, NameServer_DID
);
5887 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
))
5888 /* Wait for NameServer login cmpl before we can
5893 ndlp
= lpfc_enable_node(vport
, ndlp
,
5894 NLP_STE_PLOGI_ISSUE
);
5896 lpfc_els_flush_rscn(vport
);
5899 ndlp
->nlp_prev_state
= NLP_STE_UNUSED_NODE
;
5901 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
5903 lpfc_els_flush_rscn(vport
);
5906 lpfc_nlp_init(vport
, ndlp
, NameServer_DID
);
5907 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
5908 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
5910 ndlp
->nlp_type
|= NLP_FABRIC
;
5911 lpfc_issue_els_plogi(vport
, NameServer_DID
, 0);
5912 /* Wait for NameServer login cmpl before we can
5918 lpfc_els_flush_rscn(vport
);
5923 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
5924 * @vport: pointer to a host virtual N_Port data structure.
5925 * @cmdiocb: pointer to lpfc command iocb data structure.
5926 * @ndlp: pointer to a node-list data structure.
5928 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
5929 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
5930 * point topology. As an unsolicited FLOGI should not be received in a loop
5931 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
5932 * lpfc_check_sparm() routine is invoked to check the parameters in the
5933 * unsolicited FLOGI. If parameters validation failed, the routine
5934 * lpfc_els_rsp_reject() shall be called with reject reason code set to
5935 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
5936 * FLOGI shall be compared with the Port WWN of the @vport to determine who
5937 * will initiate PLOGI. The higher lexicographical value party shall has
5938 * higher priority (as the winning port) and will initiate PLOGI and
5939 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
5940 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
5941 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
5944 * 0 - Successfully processed the unsolicited flogi
5945 * 1 - Failed to process the unsolicited flogi
5948 lpfc_els_rcv_flogi(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
5949 struct lpfc_nodelist
*ndlp
)
5951 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
5952 struct lpfc_hba
*phba
= vport
->phba
;
5953 struct lpfc_dmabuf
*pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
5954 uint32_t *lp
= (uint32_t *) pcmd
->virt
;
5955 IOCB_t
*icmd
= &cmdiocb
->iocb
;
5956 struct serv_parm
*sp
;
5960 uint32_t fc_flag
= 0;
5961 uint32_t port_state
= 0;
5964 sp
= (struct serv_parm
*) lp
;
5966 /* FLOGI received */
5968 lpfc_set_disctmo(vport
);
5970 if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) {
5971 /* We should never receive a FLOGI in loop mode, ignore it */
5972 did
= icmd
->un
.elsreq64
.remoteID
;
5974 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
5976 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
5977 "0113 An FLOGI ELS command x%x was "
5978 "received from DID x%x in Loop Mode\n",
5983 (void) lpfc_check_sparm(vport
, ndlp
, sp
, CLASS3
, 1);
5987 * If our portname is greater than the remote portname,
5988 * then we initiate Nport login.
5991 rc
= memcmp(&vport
->fc_portname
, &sp
->portName
,
5992 sizeof(struct lpfc_name
));
5995 if (phba
->sli_rev
< LPFC_SLI_REV4
) {
5996 mbox
= mempool_alloc(phba
->mbox_mem_pool
,
6000 lpfc_linkdown(phba
);
6001 lpfc_init_link(phba
, mbox
,
6003 phba
->cfg_link_speed
);
6004 mbox
->u
.mb
.un
.varInitLnk
.lipsr_AL_PA
= 0;
6005 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
6006 mbox
->vport
= vport
;
6007 rc
= lpfc_sli_issue_mbox(phba
, mbox
,
6009 lpfc_set_loopback_flag(phba
);
6010 if (rc
== MBX_NOT_FINISHED
)
6011 mempool_free(mbox
, phba
->mbox_mem_pool
);
6015 /* abort the flogi coming back to ourselves
6016 * due to external loopback on the port.
6018 lpfc_els_abort_flogi(phba
);
6021 } else if (rc
> 0) { /* greater than */
6022 spin_lock_irq(shost
->host_lock
);
6023 vport
->fc_flag
|= FC_PT2PT_PLOGI
;
6024 spin_unlock_irq(shost
->host_lock
);
6026 /* If we have the high WWPN we can assign our own
6027 * myDID; otherwise, we have to WAIT for a PLOGI
6028 * from the remote NPort to find out what it
6031 vport
->fc_myDID
= PT2PT_LocalID
;
6033 vport
->fc_myDID
= PT2PT_RemoteID
;
6037 * The vport state should go to LPFC_FLOGI only
6038 * AFTER we issue a FLOGI, not receive one.
6040 spin_lock_irq(shost
->host_lock
);
6041 fc_flag
= vport
->fc_flag
;
6042 port_state
= vport
->port_state
;
6043 vport
->fc_flag
|= FC_PT2PT
;
6044 vport
->fc_flag
&= ~(FC_FABRIC
| FC_PUBLIC_LOOP
);
6045 spin_unlock_irq(shost
->host_lock
);
6046 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
6047 "3311 Rcv Flogi PS x%x new PS x%x "
6048 "fc_flag x%x new fc_flag x%x\n",
6049 port_state
, vport
->port_state
,
6050 fc_flag
, vport
->fc_flag
);
6053 * We temporarily set fc_myDID to make it look like we are
6054 * a Fabric. This is done just so we end up with the right
6055 * did / sid on the FLOGI ACC rsp.
6057 did
= vport
->fc_myDID
;
6058 vport
->fc_myDID
= Fabric_DID
;
6060 memcpy(&phba
->fc_fabparam
, sp
, sizeof(struct serv_parm
));
6063 lpfc_els_rsp_acc(vport
, ELS_CMD_FLOGI
, cmdiocb
, ndlp
, NULL
);
6065 /* Now lets put fc_myDID back to what its supposed to be */
6066 vport
->fc_myDID
= did
;
6072 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
6073 * @vport: pointer to a host virtual N_Port data structure.
6074 * @cmdiocb: pointer to lpfc command iocb data structure.
6075 * @ndlp: pointer to a node-list data structure.
6077 * This routine processes Request Node Identification Data (RNID) IOCB
6078 * received as an ELS unsolicited event. Only when the RNID specified format
6079 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
6080 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
6081 * Accept (ACC) the RNID ELS command. All the other RNID formats are
6082 * rejected by invoking the lpfc_els_rsp_reject() routine.
6085 * 0 - Successfully processed rnid iocb (currently always return 0)
6088 lpfc_els_rcv_rnid(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
6089 struct lpfc_nodelist
*ndlp
)
6091 struct lpfc_dmabuf
*pcmd
;
6097 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
6098 lp
= (uint32_t *) pcmd
->virt
;
6105 switch (rn
->Format
) {
6107 case RNID_TOPOLOGY_DISC
:
6109 lpfc_els_rsp_rnid_acc(vport
, rn
->Format
, cmdiocb
, ndlp
);
6112 /* Reject this request because format not supported */
6113 stat
.un
.b
.lsRjtRsvd0
= 0;
6114 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
6115 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CANT_GIVE_DATA
;
6116 stat
.un
.b
.vendorUnique
= 0;
6117 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
,
6124 * lpfc_els_rcv_echo - Process an unsolicited echo iocb
6125 * @vport: pointer to a host virtual N_Port data structure.
6126 * @cmdiocb: pointer to lpfc command iocb data structure.
6127 * @ndlp: pointer to a node-list data structure.
6130 * 0 - Successfully processed echo iocb (currently always return 0)
6133 lpfc_els_rcv_echo(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
6134 struct lpfc_nodelist
*ndlp
)
6138 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) cmdiocb
->context2
)->virt
);
6140 /* skip over first word of echo command to find echo data */
6141 pcmd
+= sizeof(uint32_t);
6143 lpfc_els_rsp_echo_acc(vport
, pcmd
, cmdiocb
, ndlp
);
6148 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
6149 * @vport: pointer to a host virtual N_Port data structure.
6150 * @cmdiocb: pointer to lpfc command iocb data structure.
6151 * @ndlp: pointer to a node-list data structure.
6153 * This routine processes a Link Incident Report Registration(LIRR) IOCB
6154 * received as an ELS unsolicited event. Currently, this function just invokes
6155 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
6158 * 0 - Successfully processed lirr iocb (currently always return 0)
6161 lpfc_els_rcv_lirr(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
6162 struct lpfc_nodelist
*ndlp
)
6166 /* For now, unconditionally reject this command */
6167 stat
.un
.b
.lsRjtRsvd0
= 0;
6168 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
6169 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CANT_GIVE_DATA
;
6170 stat
.un
.b
.vendorUnique
= 0;
6171 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
6176 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
6177 * @vport: pointer to a host virtual N_Port data structure.
6178 * @cmdiocb: pointer to lpfc command iocb data structure.
6179 * @ndlp: pointer to a node-list data structure.
6181 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
6182 * received as an ELS unsolicited event. A request to RRQ shall only
6183 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
6184 * Nx_Port N_Port_ID of the target Exchange is the same as the
6185 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
6186 * not accepted, an LS_RJT with reason code "Unable to perform
6187 * command request" and reason code explanation "Invalid Originator
6188 * S_ID" shall be returned. For now, we just unconditionally accept
6189 * RRQ from the target.
6192 lpfc_els_rcv_rrq(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
6193 struct lpfc_nodelist
*ndlp
)
6195 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
6196 if (vport
->phba
->sli_rev
== LPFC_SLI_REV4
)
6197 lpfc_els_clear_rrq(vport
, cmdiocb
, ndlp
);
6201 * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
6202 * @phba: pointer to lpfc hba data structure.
6203 * @pmb: pointer to the driver internal queue element for mailbox command.
6205 * This routine is the completion callback function for the MBX_READ_LNK_STAT
6206 * mailbox command. This callback function is to actually send the Accept
6207 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
6208 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
6209 * mailbox command, constructs the RPS response with the link statistics
6210 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
6211 * response to the RPS.
6213 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6214 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6215 * will be stored into the context1 field of the IOCB for the completion
6216 * callback function to the RPS Accept Response ELS IOCB command.
6220 lpfc_els_rsp_rls_acc(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
6224 struct RLS_RSP
*rls_rsp
;
6226 struct lpfc_iocbq
*elsiocb
;
6227 struct lpfc_nodelist
*ndlp
;
6234 ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
6235 rxid
= (uint16_t) ((unsigned long)(pmb
->context1
) & 0xffff);
6236 oxid
= (uint16_t) (((unsigned long)(pmb
->context1
) >> 16) & 0xffff);
6237 pmb
->context1
= NULL
;
6238 pmb
->context2
= NULL
;
6240 if (mb
->mbxStatus
) {
6241 mempool_free(pmb
, phba
->mbox_mem_pool
);
6245 cmdsize
= sizeof(struct RLS_RSP
) + sizeof(uint32_t);
6246 elsiocb
= lpfc_prep_els_iocb(phba
->pport
, 0, cmdsize
,
6247 lpfc_max_els_tries
, ndlp
,
6248 ndlp
->nlp_DID
, ELS_CMD_ACC
);
6250 /* Decrement the ndlp reference count from previous mbox command */
6254 mempool_free(pmb
, phba
->mbox_mem_pool
);
6258 icmd
= &elsiocb
->iocb
;
6259 icmd
->ulpContext
= rxid
;
6260 icmd
->unsli3
.rcvsli3
.ox_id
= oxid
;
6262 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
6263 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
6264 pcmd
+= sizeof(uint32_t); /* Skip past command */
6265 rls_rsp
= (struct RLS_RSP
*)pcmd
;
6267 rls_rsp
->linkFailureCnt
= cpu_to_be32(mb
->un
.varRdLnk
.linkFailureCnt
);
6268 rls_rsp
->lossSyncCnt
= cpu_to_be32(mb
->un
.varRdLnk
.lossSyncCnt
);
6269 rls_rsp
->lossSignalCnt
= cpu_to_be32(mb
->un
.varRdLnk
.lossSignalCnt
);
6270 rls_rsp
->primSeqErrCnt
= cpu_to_be32(mb
->un
.varRdLnk
.primSeqErrCnt
);
6271 rls_rsp
->invalidXmitWord
= cpu_to_be32(mb
->un
.varRdLnk
.invalidXmitWord
);
6272 rls_rsp
->crcCnt
= cpu_to_be32(mb
->un
.varRdLnk
.crcCnt
);
6273 mempool_free(pmb
, phba
->mbox_mem_pool
);
6274 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
6275 lpfc_printf_vlog(ndlp
->vport
, KERN_INFO
, LOG_ELS
,
6276 "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
6277 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
6278 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
6279 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
6281 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
6282 phba
->fc_stat
.elsXmitACC
++;
6283 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) == IOCB_ERROR
)
6284 lpfc_els_free_iocb(phba
, elsiocb
);
6288 * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
6289 * @phba: pointer to lpfc hba data structure.
6290 * @pmb: pointer to the driver internal queue element for mailbox command.
6292 * This routine is the completion callback function for the MBX_READ_LNK_STAT
6293 * mailbox command. This callback function is to actually send the Accept
6294 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
6295 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
6296 * mailbox command, constructs the RPS response with the link statistics
6297 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
6298 * response to the RPS.
6300 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6301 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6302 * will be stored into the context1 field of the IOCB for the completion
6303 * callback function to the RPS Accept Response ELS IOCB command.
6307 lpfc_els_rsp_rps_acc(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
6313 struct lpfc_iocbq
*elsiocb
;
6314 struct lpfc_nodelist
*ndlp
;
6322 ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
6323 rxid
= (uint16_t) ((unsigned long)(pmb
->context1
) & 0xffff);
6324 oxid
= (uint16_t) (((unsigned long)(pmb
->context1
) >> 16) & 0xffff);
6325 pmb
->context1
= NULL
;
6326 pmb
->context2
= NULL
;
6328 if (mb
->mbxStatus
) {
6329 mempool_free(pmb
, phba
->mbox_mem_pool
);
6333 cmdsize
= sizeof(RPS_RSP
) + sizeof(uint32_t);
6334 mempool_free(pmb
, phba
->mbox_mem_pool
);
6335 elsiocb
= lpfc_prep_els_iocb(phba
->pport
, 0, cmdsize
,
6336 lpfc_max_els_tries
, ndlp
,
6337 ndlp
->nlp_DID
, ELS_CMD_ACC
);
6339 /* Decrement the ndlp reference count from previous mbox command */
6345 icmd
= &elsiocb
->iocb
;
6346 icmd
->ulpContext
= rxid
;
6347 icmd
->unsli3
.rcvsli3
.ox_id
= oxid
;
6349 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
6350 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
6351 pcmd
+= sizeof(uint32_t); /* Skip past command */
6352 rps_rsp
= (RPS_RSP
*)pcmd
;
6354 if (phba
->fc_topology
!= LPFC_TOPOLOGY_LOOP
)
6358 if (phba
->pport
->fc_flag
& FC_FABRIC
)
6362 rps_rsp
->portStatus
= cpu_to_be16(status
);
6363 rps_rsp
->linkFailureCnt
= cpu_to_be32(mb
->un
.varRdLnk
.linkFailureCnt
);
6364 rps_rsp
->lossSyncCnt
= cpu_to_be32(mb
->un
.varRdLnk
.lossSyncCnt
);
6365 rps_rsp
->lossSignalCnt
= cpu_to_be32(mb
->un
.varRdLnk
.lossSignalCnt
);
6366 rps_rsp
->primSeqErrCnt
= cpu_to_be32(mb
->un
.varRdLnk
.primSeqErrCnt
);
6367 rps_rsp
->invalidXmitWord
= cpu_to_be32(mb
->un
.varRdLnk
.invalidXmitWord
);
6368 rps_rsp
->crcCnt
= cpu_to_be32(mb
->un
.varRdLnk
.crcCnt
);
6369 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
6370 lpfc_printf_vlog(ndlp
->vport
, KERN_INFO
, LOG_ELS
,
6371 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
6372 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
6373 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
6374 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
6376 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
6377 phba
->fc_stat
.elsXmitACC
++;
6378 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) == IOCB_ERROR
)
6379 lpfc_els_free_iocb(phba
, elsiocb
);
6384 * lpfc_els_rcv_rls - Process an unsolicited rls iocb
6385 * @vport: pointer to a host virtual N_Port data structure.
6386 * @cmdiocb: pointer to lpfc command iocb data structure.
6387 * @ndlp: pointer to a node-list data structure.
6389 * This routine processes Read Port Status (RPL) IOCB received as an
6390 * ELS unsolicited event. It first checks the remote port state. If the
6391 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
6392 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
6393 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
6394 * for reading the HBA link statistics. It is for the callback function,
6395 * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
6396 * to actually sending out RPL Accept (ACC) response.
6399 * 0 - Successfully processed rls iocb (currently always return 0)
6402 lpfc_els_rcv_rls(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
6403 struct lpfc_nodelist
*ndlp
)
6405 struct lpfc_hba
*phba
= vport
->phba
;
6409 if ((ndlp
->nlp_state
!= NLP_STE_UNMAPPED_NODE
) &&
6410 (ndlp
->nlp_state
!= NLP_STE_MAPPED_NODE
))
6411 /* reject the unsolicited RPS request and done with it */
6414 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_ATOMIC
);
6416 lpfc_read_lnk_stat(phba
, mbox
);
6417 mbox
->context1
= (void *)((unsigned long)
6418 ((cmdiocb
->iocb
.unsli3
.rcvsli3
.ox_id
<< 16) |
6419 cmdiocb
->iocb
.ulpContext
)); /* rx_id */
6420 mbox
->context2
= lpfc_nlp_get(ndlp
);
6421 mbox
->vport
= vport
;
6422 mbox
->mbox_cmpl
= lpfc_els_rsp_rls_acc
;
6423 if (lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
)
6424 != MBX_NOT_FINISHED
)
6425 /* Mbox completion will send ELS Response */
6427 /* Decrement reference count used for the failed mbox
6431 mempool_free(mbox
, phba
->mbox_mem_pool
);
6434 /* issue rejection response */
6435 stat
.un
.b
.lsRjtRsvd0
= 0;
6436 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
6437 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CANT_GIVE_DATA
;
6438 stat
.un
.b
.vendorUnique
= 0;
6439 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
6444 * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
6445 * @vport: pointer to a host virtual N_Port data structure.
6446 * @cmdiocb: pointer to lpfc command iocb data structure.
6447 * @ndlp: pointer to a node-list data structure.
6449 * This routine processes Read Timout Value (RTV) IOCB received as an
6450 * ELS unsolicited event. It first checks the remote port state. If the
6451 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
6452 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
6453 * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
6454 * Value (RTV) unsolicited IOCB event.
6456 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6457 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6458 * will be stored into the context1 field of the IOCB for the completion
6459 * callback function to the RPS Accept Response ELS IOCB command.
6462 * 0 - Successfully processed rtv iocb (currently always return 0)
6465 lpfc_els_rcv_rtv(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
6466 struct lpfc_nodelist
*ndlp
)
6468 struct lpfc_hba
*phba
= vport
->phba
;
6470 struct RTV_RSP
*rtv_rsp
;
6472 struct lpfc_iocbq
*elsiocb
;
6476 if ((ndlp
->nlp_state
!= NLP_STE_UNMAPPED_NODE
) &&
6477 (ndlp
->nlp_state
!= NLP_STE_MAPPED_NODE
))
6478 /* reject the unsolicited RPS request and done with it */
6481 cmdsize
= sizeof(struct RTV_RSP
) + sizeof(uint32_t);
6482 elsiocb
= lpfc_prep_els_iocb(phba
->pport
, 0, cmdsize
,
6483 lpfc_max_els_tries
, ndlp
,
6484 ndlp
->nlp_DID
, ELS_CMD_ACC
);
6489 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
6490 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
6491 pcmd
+= sizeof(uint32_t); /* Skip past command */
6493 /* use the command's xri in the response */
6494 elsiocb
->iocb
.ulpContext
= cmdiocb
->iocb
.ulpContext
; /* Xri / rx_id */
6495 elsiocb
->iocb
.unsli3
.rcvsli3
.ox_id
= cmdiocb
->iocb
.unsli3
.rcvsli3
.ox_id
;
6497 rtv_rsp
= (struct RTV_RSP
*)pcmd
;
6499 /* populate RTV payload */
6500 rtv_rsp
->ratov
= cpu_to_be32(phba
->fc_ratov
* 1000); /* report msecs */
6501 rtv_rsp
->edtov
= cpu_to_be32(phba
->fc_edtov
);
6502 bf_set(qtov_edtovres
, rtv_rsp
, phba
->fc_edtovResol
? 1 : 0);
6503 bf_set(qtov_rttov
, rtv_rsp
, 0); /* Field is for FC ONLY */
6504 rtv_rsp
->qtov
= cpu_to_be32(rtv_rsp
->qtov
);
6506 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
6507 lpfc_printf_vlog(ndlp
->vport
, KERN_INFO
, LOG_ELS
,
6508 "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
6509 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
6510 "Data: x%x x%x x%x\n",
6511 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
6512 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
6514 rtv_rsp
->ratov
, rtv_rsp
->edtov
, rtv_rsp
->qtov
);
6515 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
6516 phba
->fc_stat
.elsXmitACC
++;
6517 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) == IOCB_ERROR
)
6518 lpfc_els_free_iocb(phba
, elsiocb
);
6522 /* issue rejection response */
6523 stat
.un
.b
.lsRjtRsvd0
= 0;
6524 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
6525 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CANT_GIVE_DATA
;
6526 stat
.un
.b
.vendorUnique
= 0;
6527 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
6531 /* lpfc_els_rcv_rps - Process an unsolicited rps 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.
6536 * This routine processes Read Port Status (RPS) IOCB received as an
6537 * ELS unsolicited event. It first checks the remote port state. If the
6538 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
6539 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
6540 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
6541 * for reading the HBA link statistics. It is for the callback function,
6542 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
6543 * to actually sending out RPS Accept (ACC) response.
6546 * 0 - Successfully processed rps iocb (currently always return 0)
6549 lpfc_els_rcv_rps(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
6550 struct lpfc_nodelist
*ndlp
)
6552 struct lpfc_hba
*phba
= vport
->phba
;
6556 struct lpfc_dmabuf
*pcmd
;
6560 if ((ndlp
->nlp_state
!= NLP_STE_UNMAPPED_NODE
) &&
6561 (ndlp
->nlp_state
!= NLP_STE_MAPPED_NODE
))
6562 /* reject the unsolicited RPS request and done with it */
6565 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
6566 lp
= (uint32_t *) pcmd
->virt
;
6567 flag
= (be32_to_cpu(*lp
++) & 0xf);
6571 ((flag
== 1) && (be32_to_cpu(rps
->un
.portNum
) == 0)) ||
6572 ((flag
== 2) && (memcmp(&rps
->un
.portName
, &vport
->fc_portname
,
6573 sizeof(struct lpfc_name
)) == 0))) {
6575 printk("Fix me....\n");
6577 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_ATOMIC
);
6579 lpfc_read_lnk_stat(phba
, mbox
);
6580 mbox
->context1
= (void *)((unsigned long)
6581 ((cmdiocb
->iocb
.unsli3
.rcvsli3
.ox_id
<< 16) |
6582 cmdiocb
->iocb
.ulpContext
)); /* rx_id */
6583 mbox
->context2
= lpfc_nlp_get(ndlp
);
6584 mbox
->vport
= vport
;
6585 mbox
->mbox_cmpl
= lpfc_els_rsp_rps_acc
;
6586 if (lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
)
6587 != MBX_NOT_FINISHED
)
6588 /* Mbox completion will send ELS Response */
6590 /* Decrement reference count used for the failed mbox
6594 mempool_free(mbox
, phba
->mbox_mem_pool
);
6599 /* issue rejection response */
6600 stat
.un
.b
.lsRjtRsvd0
= 0;
6601 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
6602 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CANT_GIVE_DATA
;
6603 stat
.un
.b
.vendorUnique
= 0;
6604 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
6608 /* lpfc_issue_els_rrq - Process an unsolicited rps iocb
6609 * @vport: pointer to a host virtual N_Port data structure.
6610 * @ndlp: pointer to a node-list data structure.
6611 * @did: DID of the target.
6612 * @rrq: Pointer to the rrq struct.
6614 * Build a ELS RRQ command and send it to the target. If the issue_iocb is
6615 * Successful the the completion handler will clear the RRQ.
6618 * 0 - Successfully sent rrq els iocb.
6619 * 1 - Failed to send rrq els iocb.
6622 lpfc_issue_els_rrq(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
6623 uint32_t did
, struct lpfc_node_rrq
*rrq
)
6625 struct lpfc_hba
*phba
= vport
->phba
;
6626 struct RRQ
*els_rrq
;
6627 struct lpfc_iocbq
*elsiocb
;
6633 if (ndlp
!= rrq
->ndlp
)
6635 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
))
6638 /* If ndlp is not NULL, we will bump the reference count on it */
6639 cmdsize
= (sizeof(uint32_t) + sizeof(struct RRQ
));
6640 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, 0, ndlp
, did
,
6645 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
6647 /* For RRQ request, remainder of payload is Exchange IDs */
6648 *((uint32_t *) (pcmd
)) = ELS_CMD_RRQ
;
6649 pcmd
+= sizeof(uint32_t);
6650 els_rrq
= (struct RRQ
*) pcmd
;
6652 bf_set(rrq_oxid
, els_rrq
, phba
->sli4_hba
.xri_ids
[rrq
->xritag
]);
6653 bf_set(rrq_rxid
, els_rrq
, rrq
->rxid
);
6654 bf_set(rrq_did
, els_rrq
, vport
->fc_myDID
);
6655 els_rrq
->rrq
= cpu_to_be32(els_rrq
->rrq
);
6656 els_rrq
->rrq_exchg
= cpu_to_be32(els_rrq
->rrq_exchg
);
6659 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
6660 "Issue RRQ: did:x%x",
6661 did
, rrq
->xritag
, rrq
->rxid
);
6662 elsiocb
->context_un
.rrq
= rrq
;
6663 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rrq
;
6664 ret
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
6666 if (ret
== IOCB_ERROR
) {
6667 lpfc_els_free_iocb(phba
, elsiocb
);
6674 * lpfc_send_rrq - Sends ELS RRQ if needed.
6675 * @phba: pointer to lpfc hba data structure.
6676 * @rrq: pointer to the active rrq.
6678 * This routine will call the lpfc_issue_els_rrq if the rrq is
6679 * still active for the xri. If this function returns a failure then
6680 * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq.
6682 * Returns 0 Success.
6686 lpfc_send_rrq(struct lpfc_hba
*phba
, struct lpfc_node_rrq
*rrq
)
6688 struct lpfc_nodelist
*ndlp
= lpfc_findnode_did(rrq
->vport
,
6690 if (lpfc_test_rrq_active(phba
, ndlp
, rrq
->xritag
))
6691 return lpfc_issue_els_rrq(rrq
->vport
, ndlp
,
6698 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
6699 * @vport: pointer to a host virtual N_Port data structure.
6700 * @cmdsize: size of the ELS command.
6701 * @oldiocb: pointer to the original lpfc command iocb data structure.
6702 * @ndlp: pointer to a node-list data structure.
6704 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
6705 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
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 RPL Accept Response ELS command.
6713 * 0 - Successfully issued ACC RPL ELS command
6714 * 1 - Failed to issue ACC RPL ELS command
6717 lpfc_els_rsp_rpl_acc(struct lpfc_vport
*vport
, uint16_t cmdsize
,
6718 struct lpfc_iocbq
*oldiocb
, struct lpfc_nodelist
*ndlp
)
6720 struct lpfc_hba
*phba
= vport
->phba
;
6721 IOCB_t
*icmd
, *oldcmd
;
6723 struct lpfc_iocbq
*elsiocb
;
6726 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
6727 ndlp
->nlp_DID
, ELS_CMD_ACC
);
6732 icmd
= &elsiocb
->iocb
;
6733 oldcmd
= &oldiocb
->iocb
;
6734 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri / rx_id */
6735 icmd
->unsli3
.rcvsli3
.ox_id
= oldcmd
->unsli3
.rcvsli3
.ox_id
;
6737 pcmd
= (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
6738 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
6739 pcmd
+= sizeof(uint16_t);
6740 *((uint16_t *)(pcmd
)) = be16_to_cpu(cmdsize
);
6741 pcmd
+= sizeof(uint16_t);
6743 /* Setup the RPL ACC payload */
6744 rpl_rsp
.listLen
= be32_to_cpu(1);
6746 rpl_rsp
.port_num_blk
.portNum
= 0;
6747 rpl_rsp
.port_num_blk
.portID
= be32_to_cpu(vport
->fc_myDID
);
6748 memcpy(&rpl_rsp
.port_num_blk
.portName
, &vport
->fc_portname
,
6749 sizeof(struct lpfc_name
));
6750 memcpy(pcmd
, &rpl_rsp
, cmdsize
- sizeof(uint32_t));
6751 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
6752 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
6753 "0120 Xmit ELS RPL ACC response tag x%x "
6754 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
6756 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
6757 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
6759 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
6760 phba
->fc_stat
.elsXmitACC
++;
6761 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) ==
6763 lpfc_els_free_iocb(phba
, elsiocb
);
6770 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
6771 * @vport: pointer to a host virtual N_Port data structure.
6772 * @cmdiocb: pointer to lpfc command iocb data structure.
6773 * @ndlp: pointer to a node-list data structure.
6775 * This routine processes Read Port List (RPL) IOCB received as an ELS
6776 * unsolicited event. It first checks the remote port state. If the remote
6777 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
6778 * invokes the lpfc_els_rsp_reject() routine to send reject response.
6779 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
6780 * to accept the RPL.
6783 * 0 - Successfully processed rpl iocb (currently always return 0)
6786 lpfc_els_rcv_rpl(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
6787 struct lpfc_nodelist
*ndlp
)
6789 struct lpfc_dmabuf
*pcmd
;
6796 if ((ndlp
->nlp_state
!= NLP_STE_UNMAPPED_NODE
) &&
6797 (ndlp
->nlp_state
!= NLP_STE_MAPPED_NODE
)) {
6798 /* issue rejection response */
6799 stat
.un
.b
.lsRjtRsvd0
= 0;
6800 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
6801 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CANT_GIVE_DATA
;
6802 stat
.un
.b
.vendorUnique
= 0;
6803 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
,
6805 /* rejected the unsolicited RPL request and done with it */
6809 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
6810 lp
= (uint32_t *) pcmd
->virt
;
6811 rpl
= (RPL
*) (lp
+ 1);
6812 maxsize
= be32_to_cpu(rpl
->maxsize
);
6814 /* We support only one port */
6815 if ((rpl
->index
== 0) &&
6817 ((maxsize
* sizeof(uint32_t)) >= sizeof(RPL_RSP
)))) {
6818 cmdsize
= sizeof(uint32_t) + sizeof(RPL_RSP
);
6820 cmdsize
= sizeof(uint32_t) + maxsize
* sizeof(uint32_t);
6822 lpfc_els_rsp_rpl_acc(vport
, cmdsize
, cmdiocb
, ndlp
);
6828 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
6829 * @vport: pointer to a virtual N_Port data structure.
6830 * @cmdiocb: pointer to lpfc command iocb data structure.
6831 * @ndlp: pointer to a node-list data structure.
6833 * This routine processes Fibre Channel Address Resolution Protocol
6834 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
6835 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
6836 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
6837 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
6838 * remote PortName is compared against the FC PortName stored in the @vport
6839 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
6840 * compared against the FC NodeName stored in the @vport data structure.
6841 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
6842 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
6843 * invoked to send out FARP Response to the remote node. Before sending the
6844 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
6845 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
6846 * routine is invoked to log into the remote port first.
6849 * 0 - Either the FARP Match Mode not supported or successfully processed
6852 lpfc_els_rcv_farp(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
6853 struct lpfc_nodelist
*ndlp
)
6855 struct lpfc_dmabuf
*pcmd
;
6859 uint32_t cmd
, cnt
, did
;
6861 icmd
= &cmdiocb
->iocb
;
6862 did
= icmd
->un
.elsreq64
.remoteID
;
6863 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
6864 lp
= (uint32_t *) pcmd
->virt
;
6868 /* FARP-REQ received from DID <did> */
6869 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
6870 "0601 FARP-REQ received from DID x%x\n", did
);
6871 /* We will only support match on WWPN or WWNN */
6872 if (fp
->Mflags
& ~(FARP_MATCH_NODE
| FARP_MATCH_PORT
)) {
6877 /* If this FARP command is searching for my portname */
6878 if (fp
->Mflags
& FARP_MATCH_PORT
) {
6879 if (memcmp(&fp
->RportName
, &vport
->fc_portname
,
6880 sizeof(struct lpfc_name
)) == 0)
6884 /* If this FARP command is searching for my nodename */
6885 if (fp
->Mflags
& FARP_MATCH_NODE
) {
6886 if (memcmp(&fp
->RnodeName
, &vport
->fc_nodename
,
6887 sizeof(struct lpfc_name
)) == 0)
6892 if ((ndlp
->nlp_state
== NLP_STE_UNMAPPED_NODE
) ||
6893 (ndlp
->nlp_state
== NLP_STE_MAPPED_NODE
)) {
6894 /* Log back into the node before sending the FARP. */
6895 if (fp
->Rflags
& FARP_REQUEST_PLOGI
) {
6896 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
6897 lpfc_nlp_set_state(vport
, ndlp
,
6898 NLP_STE_PLOGI_ISSUE
);
6899 lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0);
6902 /* Send a FARP response to that node */
6903 if (fp
->Rflags
& FARP_REQUEST_FARPR
)
6904 lpfc_issue_els_farpr(vport
, did
, 0);
6911 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
6912 * @vport: pointer to a host virtual N_Port data structure.
6913 * @cmdiocb: pointer to lpfc command iocb data structure.
6914 * @ndlp: pointer to a node-list data structure.
6916 * This routine processes Fibre Channel Address Resolution Protocol
6917 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
6918 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
6919 * the FARP response request.
6922 * 0 - Successfully processed FARPR IOCB (currently always return 0)
6925 lpfc_els_rcv_farpr(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
6926 struct lpfc_nodelist
*ndlp
)
6928 struct lpfc_dmabuf
*pcmd
;
6933 icmd
= &cmdiocb
->iocb
;
6934 did
= icmd
->un
.elsreq64
.remoteID
;
6935 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
6936 lp
= (uint32_t *) pcmd
->virt
;
6939 /* FARP-RSP received from DID <did> */
6940 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
6941 "0600 FARP-RSP received from DID x%x\n", did
);
6942 /* ACCEPT the Farp resp request */
6943 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
6949 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
6950 * @vport: pointer to a host virtual N_Port data structure.
6951 * @cmdiocb: pointer to lpfc command iocb data structure.
6952 * @fan_ndlp: pointer to a node-list data structure.
6954 * This routine processes a Fabric Address Notification (FAN) IOCB
6955 * command received as an ELS unsolicited event. The FAN ELS command will
6956 * only be processed on a physical port (i.e., the @vport represents the
6957 * physical port). The fabric NodeName and PortName from the FAN IOCB are
6958 * compared against those in the phba data structure. If any of those is
6959 * different, the lpfc_initial_flogi() routine is invoked to initialize
6960 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
6961 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
6962 * is invoked to register login to the fabric.
6965 * 0 - Successfully processed fan iocb (currently always return 0).
6968 lpfc_els_rcv_fan(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
6969 struct lpfc_nodelist
*fan_ndlp
)
6971 struct lpfc_hba
*phba
= vport
->phba
;
6975 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
, "0265 FAN received\n");
6976 lp
= (uint32_t *)((struct lpfc_dmabuf
*)cmdiocb
->context2
)->virt
;
6978 /* FAN received; Fan does not have a reply sequence */
6979 if ((vport
== phba
->pport
) &&
6980 (vport
->port_state
== LPFC_LOCAL_CFG_LINK
)) {
6981 if ((memcmp(&phba
->fc_fabparam
.nodeName
, &fp
->FnodeName
,
6982 sizeof(struct lpfc_name
))) ||
6983 (memcmp(&phba
->fc_fabparam
.portName
, &fp
->FportName
,
6984 sizeof(struct lpfc_name
)))) {
6985 /* This port has switched fabrics. FLOGI is required */
6986 lpfc_issue_init_vfi(vport
);
6988 /* FAN verified - skip FLOGI */
6989 vport
->fc_myDID
= vport
->fc_prevDID
;
6990 if (phba
->sli_rev
< LPFC_SLI_REV4
)
6991 lpfc_issue_fabric_reglogin(vport
);
6993 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
6994 "3138 Need register VFI: (x%x/%x)\n",
6995 vport
->fc_prevDID
, vport
->fc_myDID
);
6996 lpfc_issue_reg_vfi(vport
);
7004 * lpfc_els_timeout - Handler funciton to the els timer
7005 * @ptr: holder for the timer function associated data.
7007 * This routine is invoked by the ELS timer after timeout. It posts the ELS
7008 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
7009 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
7010 * up the worker thread. It is for the worker thread to invoke the routine
7011 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
7014 lpfc_els_timeout(unsigned long ptr
)
7016 struct lpfc_vport
*vport
= (struct lpfc_vport
*) ptr
;
7017 struct lpfc_hba
*phba
= vport
->phba
;
7018 uint32_t tmo_posted
;
7019 unsigned long iflag
;
7021 spin_lock_irqsave(&vport
->work_port_lock
, iflag
);
7022 tmo_posted
= vport
->work_port_events
& WORKER_ELS_TMO
;
7023 if ((!tmo_posted
) && (!(vport
->load_flag
& FC_UNLOADING
)))
7024 vport
->work_port_events
|= WORKER_ELS_TMO
;
7025 spin_unlock_irqrestore(&vport
->work_port_lock
, iflag
);
7027 if ((!tmo_posted
) && (!(vport
->load_flag
& FC_UNLOADING
)))
7028 lpfc_worker_wake_up(phba
);
7034 * lpfc_els_timeout_handler - Process an els timeout event
7035 * @vport: pointer to a virtual N_Port data structure.
7037 * This routine is the actual handler function that processes an ELS timeout
7038 * event. It walks the ELS ring to get and abort all the IOCBs (except the
7039 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
7040 * invoking the lpfc_sli_issue_abort_iotag() routine.
7043 lpfc_els_timeout_handler(struct lpfc_vport
*vport
)
7045 struct lpfc_hba
*phba
= vport
->phba
;
7046 struct lpfc_sli_ring
*pring
;
7047 struct lpfc_iocbq
*tmp_iocb
, *piocb
;
7049 struct lpfc_dmabuf
*pcmd
;
7050 uint32_t els_command
= 0;
7052 uint32_t remote_ID
= 0xffffffff;
7053 LIST_HEAD(abort_list
);
7056 timeout
= (uint32_t)(phba
->fc_ratov
<< 1);
7058 pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
7059 if ((phba
->pport
->load_flag
& FC_UNLOADING
))
7061 spin_lock_irq(&phba
->hbalock
);
7062 if (phba
->sli_rev
== LPFC_SLI_REV4
)
7063 spin_lock(&pring
->ring_lock
);
7065 if ((phba
->pport
->load_flag
& FC_UNLOADING
)) {
7066 if (phba
->sli_rev
== LPFC_SLI_REV4
)
7067 spin_unlock(&pring
->ring_lock
);
7068 spin_unlock_irq(&phba
->hbalock
);
7072 list_for_each_entry_safe(piocb
, tmp_iocb
, &pring
->txcmplq
, list
) {
7075 if ((piocb
->iocb_flag
& LPFC_IO_LIBDFC
) != 0 ||
7076 piocb
->iocb
.ulpCommand
== CMD_ABORT_XRI_CN
||
7077 piocb
->iocb
.ulpCommand
== CMD_CLOSE_XRI_CN
)
7080 if (piocb
->vport
!= vport
)
7083 pcmd
= (struct lpfc_dmabuf
*) piocb
->context2
;
7085 els_command
= *(uint32_t *) (pcmd
->virt
);
7087 if (els_command
== ELS_CMD_FARP
||
7088 els_command
== ELS_CMD_FARPR
||
7089 els_command
== ELS_CMD_FDISC
)
7092 if (piocb
->drvrTimeout
> 0) {
7093 if (piocb
->drvrTimeout
>= timeout
)
7094 piocb
->drvrTimeout
-= timeout
;
7096 piocb
->drvrTimeout
= 0;
7100 remote_ID
= 0xffffffff;
7101 if (cmd
->ulpCommand
!= CMD_GEN_REQUEST64_CR
)
7102 remote_ID
= cmd
->un
.elsreq64
.remoteID
;
7104 struct lpfc_nodelist
*ndlp
;
7105 ndlp
= __lpfc_findnode_rpi(vport
, cmd
->ulpContext
);
7106 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
))
7107 remote_ID
= ndlp
->nlp_DID
;
7109 list_add_tail(&piocb
->dlist
, &abort_list
);
7111 if (phba
->sli_rev
== LPFC_SLI_REV4
)
7112 spin_unlock(&pring
->ring_lock
);
7113 spin_unlock_irq(&phba
->hbalock
);
7115 list_for_each_entry_safe(piocb
, tmp_iocb
, &abort_list
, dlist
) {
7117 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
7118 "0127 ELS timeout Data: x%x x%x x%x "
7119 "x%x\n", els_command
,
7120 remote_ID
, cmd
->ulpCommand
, cmd
->ulpIoTag
);
7121 spin_lock_irq(&phba
->hbalock
);
7122 list_del_init(&piocb
->dlist
);
7123 lpfc_sli_issue_abort_iotag(phba
, pring
, piocb
);
7124 spin_unlock_irq(&phba
->hbalock
);
7127 if (!list_empty(&phba
->sli
.ring
[LPFC_ELS_RING
].txcmplq
))
7128 if (!(phba
->pport
->load_flag
& FC_UNLOADING
))
7129 mod_timer(&vport
->els_tmofunc
,
7130 jiffies
+ msecs_to_jiffies(1000 * timeout
));
7134 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
7135 * @vport: pointer to a host virtual N_Port data structure.
7137 * This routine is used to clean up all the outstanding ELS commands on a
7138 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
7139 * routine. After that, it walks the ELS transmit queue to remove all the
7140 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
7141 * the IOCBs with a non-NULL completion callback function, the callback
7142 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
7143 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
7144 * callback function, the IOCB will simply be released. Finally, it walks
7145 * the ELS transmit completion queue to issue an abort IOCB to any transmit
7146 * completion queue IOCB that is associated with the @vport and is not
7147 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
7148 * part of the discovery state machine) out to HBA by invoking the
7149 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
7150 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
7151 * the IOCBs are aborted when this function returns.
7154 lpfc_els_flush_cmd(struct lpfc_vport
*vport
)
7156 LIST_HEAD(abort_list
);
7157 struct lpfc_hba
*phba
= vport
->phba
;
7158 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
7159 struct lpfc_iocbq
*tmp_iocb
, *piocb
;
7162 lpfc_fabric_abort_vport(vport
);
7164 * For SLI3, only the hbalock is required. But SLI4 needs to coordinate
7165 * with the ring insert operation. Because lpfc_sli_issue_abort_iotag
7166 * ultimately grabs the ring_lock, the driver must splice the list into
7167 * a working list and release the locks before calling the abort.
7169 spin_lock_irq(&phba
->hbalock
);
7170 if (phba
->sli_rev
== LPFC_SLI_REV4
)
7171 spin_lock(&pring
->ring_lock
);
7173 list_for_each_entry_safe(piocb
, tmp_iocb
, &pring
->txcmplq
, list
) {
7174 if (piocb
->iocb_flag
& LPFC_IO_LIBDFC
)
7177 if (piocb
->vport
!= vport
)
7179 list_add_tail(&piocb
->dlist
, &abort_list
);
7181 if (phba
->sli_rev
== LPFC_SLI_REV4
)
7182 spin_unlock(&pring
->ring_lock
);
7183 spin_unlock_irq(&phba
->hbalock
);
7184 /* Abort each iocb on the aborted list and remove the dlist links. */
7185 list_for_each_entry_safe(piocb
, tmp_iocb
, &abort_list
, dlist
) {
7186 spin_lock_irq(&phba
->hbalock
);
7187 list_del_init(&piocb
->dlist
);
7188 lpfc_sli_issue_abort_iotag(phba
, pring
, piocb
);
7189 spin_unlock_irq(&phba
->hbalock
);
7191 if (!list_empty(&abort_list
))
7192 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
7193 "3387 abort list for txq not empty\n");
7194 INIT_LIST_HEAD(&abort_list
);
7196 spin_lock_irq(&phba
->hbalock
);
7197 if (phba
->sli_rev
== LPFC_SLI_REV4
)
7198 spin_lock(&pring
->ring_lock
);
7200 list_for_each_entry_safe(piocb
, tmp_iocb
, &pring
->txq
, list
) {
7203 if (piocb
->iocb_flag
& LPFC_IO_LIBDFC
) {
7207 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
7208 if (cmd
->ulpCommand
== CMD_QUE_RING_BUF_CN
||
7209 cmd
->ulpCommand
== CMD_QUE_RING_BUF64_CN
||
7210 cmd
->ulpCommand
== CMD_CLOSE_XRI_CN
||
7211 cmd
->ulpCommand
== CMD_ABORT_XRI_CN
)
7214 if (piocb
->vport
!= vport
)
7217 list_del_init(&piocb
->list
);
7218 list_add_tail(&piocb
->list
, &abort_list
);
7220 if (phba
->sli_rev
== LPFC_SLI_REV4
)
7221 spin_unlock(&pring
->ring_lock
);
7222 spin_unlock_irq(&phba
->hbalock
);
7224 /* Cancell all the IOCBs from the completions list */
7225 lpfc_sli_cancel_iocbs(phba
, &abort_list
,
7226 IOSTAT_LOCAL_REJECT
, IOERR_SLI_ABORTED
);
7232 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
7233 * @phba: pointer to lpfc hba data structure.
7235 * This routine is used to clean up all the outstanding ELS commands on a
7236 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
7237 * routine. After that, it walks the ELS transmit queue to remove all the
7238 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
7239 * the IOCBs with the completion callback function associated, the callback
7240 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
7241 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
7242 * callback function associated, the IOCB will simply be released. Finally,
7243 * it walks the ELS transmit completion queue to issue an abort IOCB to any
7244 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
7245 * management plane IOCBs that are not part of the discovery state machine)
7246 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
7249 lpfc_els_flush_all_cmd(struct lpfc_hba
*phba
)
7251 struct lpfc_vport
*vport
;
7252 list_for_each_entry(vport
, &phba
->port_list
, listentry
)
7253 lpfc_els_flush_cmd(vport
);
7259 * lpfc_send_els_failure_event - Posts an ELS command failure event
7260 * @phba: Pointer to hba context object.
7261 * @cmdiocbp: Pointer to command iocb which reported error.
7262 * @rspiocbp: Pointer to response iocb which reported error.
7264 * This function sends an event when there is an ELS command
7268 lpfc_send_els_failure_event(struct lpfc_hba
*phba
,
7269 struct lpfc_iocbq
*cmdiocbp
,
7270 struct lpfc_iocbq
*rspiocbp
)
7272 struct lpfc_vport
*vport
= cmdiocbp
->vport
;
7273 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
7274 struct lpfc_lsrjt_event lsrjt_event
;
7275 struct lpfc_fabric_event_header fabric_event
;
7277 struct lpfc_nodelist
*ndlp
;
7280 ndlp
= cmdiocbp
->context1
;
7281 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
))
7284 if (rspiocbp
->iocb
.ulpStatus
== IOSTAT_LS_RJT
) {
7285 lsrjt_event
.header
.event_type
= FC_REG_ELS_EVENT
;
7286 lsrjt_event
.header
.subcategory
= LPFC_EVENT_LSRJT_RCV
;
7287 memcpy(lsrjt_event
.header
.wwpn
, &ndlp
->nlp_portname
,
7288 sizeof(struct lpfc_name
));
7289 memcpy(lsrjt_event
.header
.wwnn
, &ndlp
->nlp_nodename
,
7290 sizeof(struct lpfc_name
));
7291 pcmd
= (uint32_t *) (((struct lpfc_dmabuf
*)
7292 cmdiocbp
->context2
)->virt
);
7293 lsrjt_event
.command
= (pcmd
!= NULL
) ? *pcmd
: 0;
7294 stat
.un
.lsRjtError
= be32_to_cpu(rspiocbp
->iocb
.un
.ulpWord
[4]);
7295 lsrjt_event
.reason_code
= stat
.un
.b
.lsRjtRsnCode
;
7296 lsrjt_event
.explanation
= stat
.un
.b
.lsRjtRsnCodeExp
;
7297 fc_host_post_vendor_event(shost
,
7298 fc_get_event_number(),
7299 sizeof(lsrjt_event
),
7300 (char *)&lsrjt_event
,
7304 if ((rspiocbp
->iocb
.ulpStatus
== IOSTAT_NPORT_BSY
) ||
7305 (rspiocbp
->iocb
.ulpStatus
== IOSTAT_FABRIC_BSY
)) {
7306 fabric_event
.event_type
= FC_REG_FABRIC_EVENT
;
7307 if (rspiocbp
->iocb
.ulpStatus
== IOSTAT_NPORT_BSY
)
7308 fabric_event
.subcategory
= LPFC_EVENT_PORT_BUSY
;
7310 fabric_event
.subcategory
= LPFC_EVENT_FABRIC_BUSY
;
7311 memcpy(fabric_event
.wwpn
, &ndlp
->nlp_portname
,
7312 sizeof(struct lpfc_name
));
7313 memcpy(fabric_event
.wwnn
, &ndlp
->nlp_nodename
,
7314 sizeof(struct lpfc_name
));
7315 fc_host_post_vendor_event(shost
,
7316 fc_get_event_number(),
7317 sizeof(fabric_event
),
7318 (char *)&fabric_event
,
7326 * lpfc_send_els_event - Posts unsolicited els event
7327 * @vport: Pointer to vport object.
7328 * @ndlp: Pointer FC node object.
7329 * @cmd: ELS command code.
7331 * This function posts an event when there is an incoming
7332 * unsolicited ELS command.
7335 lpfc_send_els_event(struct lpfc_vport
*vport
,
7336 struct lpfc_nodelist
*ndlp
,
7339 struct lpfc_els_event_header
*els_data
= NULL
;
7340 struct lpfc_logo_event
*logo_data
= NULL
;
7341 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
7343 if (*payload
== ELS_CMD_LOGO
) {
7344 logo_data
= kmalloc(sizeof(struct lpfc_logo_event
), GFP_KERNEL
);
7346 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
7347 "0148 Failed to allocate memory "
7348 "for LOGO event\n");
7351 els_data
= &logo_data
->header
;
7353 els_data
= kmalloc(sizeof(struct lpfc_els_event_header
),
7356 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
7357 "0149 Failed to allocate memory "
7362 els_data
->event_type
= FC_REG_ELS_EVENT
;
7365 els_data
->subcategory
= LPFC_EVENT_PLOGI_RCV
;
7368 els_data
->subcategory
= LPFC_EVENT_PRLO_RCV
;
7371 els_data
->subcategory
= LPFC_EVENT_ADISC_RCV
;
7374 els_data
->subcategory
= LPFC_EVENT_LOGO_RCV
;
7375 /* Copy the WWPN in the LOGO payload */
7376 memcpy(logo_data
->logo_wwpn
, &payload
[2],
7377 sizeof(struct lpfc_name
));
7383 memcpy(els_data
->wwpn
, &ndlp
->nlp_portname
, sizeof(struct lpfc_name
));
7384 memcpy(els_data
->wwnn
, &ndlp
->nlp_nodename
, sizeof(struct lpfc_name
));
7385 if (*payload
== ELS_CMD_LOGO
) {
7386 fc_host_post_vendor_event(shost
,
7387 fc_get_event_number(),
7388 sizeof(struct lpfc_logo_event
),
7393 fc_host_post_vendor_event(shost
,
7394 fc_get_event_number(),
7395 sizeof(struct lpfc_els_event_header
),
7406 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
7407 * @phba: pointer to lpfc hba data structure.
7408 * @pring: pointer to a SLI ring.
7409 * @vport: pointer to a host virtual N_Port data structure.
7410 * @elsiocb: pointer to lpfc els command iocb data structure.
7412 * This routine is used for processing the IOCB associated with a unsolicited
7413 * event. It first determines whether there is an existing ndlp that matches
7414 * the DID from the unsolicited IOCB. If not, it will create a new one with
7415 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
7416 * IOCB is then used to invoke the proper routine and to set up proper state
7417 * of the discovery state machine.
7420 lpfc_els_unsol_buffer(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
7421 struct lpfc_vport
*vport
, struct lpfc_iocbq
*elsiocb
)
7423 struct Scsi_Host
*shost
;
7424 struct lpfc_nodelist
*ndlp
;
7427 uint32_t cmd
, did
, newnode
;
7428 uint8_t rjt_exp
, rjt_err
= 0;
7429 IOCB_t
*icmd
= &elsiocb
->iocb
;
7431 if (!vport
|| !(elsiocb
->context2
))
7435 payload
= ((struct lpfc_dmabuf
*)elsiocb
->context2
)->virt
;
7437 if ((phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) == 0)
7438 lpfc_post_buffer(phba
, pring
, 1);
7440 did
= icmd
->un
.rcvels
.remoteID
;
7441 if (icmd
->ulpStatus
) {
7442 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
7443 "RCV Unsol ELS: status:x%x/x%x did:x%x",
7444 icmd
->ulpStatus
, icmd
->un
.ulpWord
[4], did
);
7448 /* Check to see if link went down during discovery */
7449 if (lpfc_els_chk_latt(vport
))
7452 /* Ignore traffic received during vport shutdown. */
7453 if (vport
->load_flag
& FC_UNLOADING
)
7456 /* If NPort discovery is delayed drop incoming ELS */
7457 if ((vport
->fc_flag
& FC_DISC_DELAYED
) &&
7458 (cmd
!= ELS_CMD_PLOGI
))
7461 ndlp
= lpfc_findnode_did(vport
, did
);
7463 /* Cannot find existing Fabric ndlp, so allocate a new one */
7464 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
7468 lpfc_nlp_init(vport
, ndlp
, did
);
7469 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
7471 if ((did
& Fabric_DID_MASK
) == Fabric_DID_MASK
)
7472 ndlp
->nlp_type
|= NLP_FABRIC
;
7473 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
7474 ndlp
= lpfc_enable_node(vport
, ndlp
,
7475 NLP_STE_UNUSED_NODE
);
7478 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
7480 if ((did
& Fabric_DID_MASK
) == Fabric_DID_MASK
)
7481 ndlp
->nlp_type
|= NLP_FABRIC
;
7482 } else if (ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
) {
7483 /* This is similar to the new node path */
7484 ndlp
= lpfc_nlp_get(ndlp
);
7487 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
7491 phba
->fc_stat
.elsRcvFrame
++;
7494 * Do not process any unsolicited ELS commands
7495 * if the ndlp is in DEV_LOSS
7497 shost
= lpfc_shost_from_vport(vport
);
7498 spin_lock_irq(shost
->host_lock
);
7499 if (ndlp
->nlp_flag
& NLP_IN_DEV_LOSS
) {
7500 spin_unlock_irq(shost
->host_lock
);
7503 spin_unlock_irq(shost
->host_lock
);
7505 elsiocb
->context1
= lpfc_nlp_get(ndlp
);
7506 elsiocb
->vport
= vport
;
7508 if ((cmd
& ELS_CMD_MASK
) == ELS_CMD_RSCN
) {
7509 cmd
&= ELS_CMD_MASK
;
7511 /* ELS command <elsCmd> received from NPORT <did> */
7512 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
7513 "0112 ELS command x%x received from NPORT x%x "
7514 "Data: x%x x%x x%x x%x\n",
7515 cmd
, did
, vport
->port_state
, vport
->fc_flag
,
7516 vport
->fc_myDID
, vport
->fc_prevDID
);
7518 /* reject till our FLOGI completes */
7519 if ((vport
->port_state
< LPFC_FABRIC_CFG_LINK
) &&
7520 (cmd
!= ELS_CMD_FLOGI
)) {
7521 rjt_err
= LSRJT_UNABLE_TPC
;
7522 rjt_exp
= LSEXP_NOTHING_MORE
;
7528 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
7529 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
7530 did
, vport
->port_state
, ndlp
->nlp_flag
);
7532 phba
->fc_stat
.elsRcvPLOGI
++;
7533 ndlp
= lpfc_plogi_confirm_nport(phba
, payload
, ndlp
);
7534 if (phba
->sli_rev
== LPFC_SLI_REV4
&&
7535 (phba
->pport
->fc_flag
& FC_PT2PT
)) {
7536 vport
->fc_prevDID
= vport
->fc_myDID
;
7537 /* Our DID needs to be updated before registering
7538 * the vfi. This is done in lpfc_rcv_plogi but
7539 * that is called after the reg_vfi.
7541 vport
->fc_myDID
= elsiocb
->iocb
.un
.rcvels
.parmRo
;
7542 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
7543 "3312 Remote port assigned DID x%x "
7544 "%x\n", vport
->fc_myDID
,
7548 lpfc_send_els_event(vport
, ndlp
, payload
);
7550 /* If Nport discovery is delayed, reject PLOGIs */
7551 if (vport
->fc_flag
& FC_DISC_DELAYED
) {
7552 rjt_err
= LSRJT_UNABLE_TPC
;
7553 rjt_exp
= LSEXP_NOTHING_MORE
;
7557 if (vport
->port_state
< LPFC_DISC_AUTH
) {
7558 if (!(phba
->pport
->fc_flag
& FC_PT2PT
) ||
7559 (phba
->pport
->fc_flag
& FC_PT2PT_PLOGI
)) {
7560 rjt_err
= LSRJT_UNABLE_TPC
;
7561 rjt_exp
= LSEXP_NOTHING_MORE
;
7566 spin_lock_irq(shost
->host_lock
);
7567 ndlp
->nlp_flag
&= ~NLP_TARGET_REMOVE
;
7568 spin_unlock_irq(shost
->host_lock
);
7570 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
,
7575 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
7576 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
7577 did
, vport
->port_state
, ndlp
->nlp_flag
);
7579 phba
->fc_stat
.elsRcvFLOGI
++;
7580 lpfc_els_rcv_flogi(vport
, elsiocb
, ndlp
);
7585 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
7586 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
7587 did
, vport
->port_state
, ndlp
->nlp_flag
);
7589 phba
->fc_stat
.elsRcvLOGO
++;
7590 lpfc_send_els_event(vport
, ndlp
, payload
);
7591 if (vport
->port_state
< LPFC_DISC_AUTH
) {
7592 rjt_err
= LSRJT_UNABLE_TPC
;
7593 rjt_exp
= LSEXP_NOTHING_MORE
;
7596 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
, NLP_EVT_RCV_LOGO
);
7599 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
7600 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
7601 did
, vport
->port_state
, ndlp
->nlp_flag
);
7603 phba
->fc_stat
.elsRcvPRLO
++;
7604 lpfc_send_els_event(vport
, ndlp
, payload
);
7605 if (vport
->port_state
< LPFC_DISC_AUTH
) {
7606 rjt_err
= LSRJT_UNABLE_TPC
;
7607 rjt_exp
= LSEXP_NOTHING_MORE
;
7610 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
, NLP_EVT_RCV_PRLO
);
7613 phba
->fc_stat
.elsRcvLCB
++;
7614 lpfc_els_rcv_lcb(vport
, elsiocb
, ndlp
);
7617 phba
->fc_stat
.elsRcvRDP
++;
7618 lpfc_els_rcv_rdp(vport
, elsiocb
, ndlp
);
7621 phba
->fc_stat
.elsRcvRSCN
++;
7622 lpfc_els_rcv_rscn(vport
, elsiocb
, ndlp
);
7627 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
7628 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
7629 did
, vport
->port_state
, ndlp
->nlp_flag
);
7631 lpfc_send_els_event(vport
, ndlp
, payload
);
7632 phba
->fc_stat
.elsRcvADISC
++;
7633 if (vport
->port_state
< LPFC_DISC_AUTH
) {
7634 rjt_err
= LSRJT_UNABLE_TPC
;
7635 rjt_exp
= LSEXP_NOTHING_MORE
;
7638 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
,
7642 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
7643 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
7644 did
, vport
->port_state
, ndlp
->nlp_flag
);
7646 phba
->fc_stat
.elsRcvPDISC
++;
7647 if (vport
->port_state
< LPFC_DISC_AUTH
) {
7648 rjt_err
= LSRJT_UNABLE_TPC
;
7649 rjt_exp
= LSEXP_NOTHING_MORE
;
7652 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
,
7656 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
7657 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
7658 did
, vport
->port_state
, ndlp
->nlp_flag
);
7660 phba
->fc_stat
.elsRcvFARPR
++;
7661 lpfc_els_rcv_farpr(vport
, elsiocb
, ndlp
);
7664 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
7665 "RCV FARP: did:x%x/ste:x%x flg:x%x",
7666 did
, vport
->port_state
, ndlp
->nlp_flag
);
7668 phba
->fc_stat
.elsRcvFARP
++;
7669 lpfc_els_rcv_farp(vport
, elsiocb
, ndlp
);
7672 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
7673 "RCV FAN: did:x%x/ste:x%x flg:x%x",
7674 did
, vport
->port_state
, ndlp
->nlp_flag
);
7676 phba
->fc_stat
.elsRcvFAN
++;
7677 lpfc_els_rcv_fan(vport
, elsiocb
, ndlp
);
7680 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
7681 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
7682 did
, vport
->port_state
, ndlp
->nlp_flag
);
7684 phba
->fc_stat
.elsRcvPRLI
++;
7685 if (vport
->port_state
< LPFC_DISC_AUTH
) {
7686 rjt_err
= LSRJT_UNABLE_TPC
;
7687 rjt_exp
= LSEXP_NOTHING_MORE
;
7690 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
, NLP_EVT_RCV_PRLI
);
7693 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
7694 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
7695 did
, vport
->port_state
, ndlp
->nlp_flag
);
7697 phba
->fc_stat
.elsRcvLIRR
++;
7698 lpfc_els_rcv_lirr(vport
, elsiocb
, ndlp
);
7703 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
7704 "RCV RLS: did:x%x/ste:x%x flg:x%x",
7705 did
, vport
->port_state
, ndlp
->nlp_flag
);
7707 phba
->fc_stat
.elsRcvRLS
++;
7708 lpfc_els_rcv_rls(vport
, elsiocb
, ndlp
);
7713 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
7714 "RCV RPS: did:x%x/ste:x%x flg:x%x",
7715 did
, vport
->port_state
, ndlp
->nlp_flag
);
7717 phba
->fc_stat
.elsRcvRPS
++;
7718 lpfc_els_rcv_rps(vport
, elsiocb
, ndlp
);
7723 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
7724 "RCV RPL: did:x%x/ste:x%x flg:x%x",
7725 did
, vport
->port_state
, ndlp
->nlp_flag
);
7727 phba
->fc_stat
.elsRcvRPL
++;
7728 lpfc_els_rcv_rpl(vport
, elsiocb
, ndlp
);
7733 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
7734 "RCV RNID: did:x%x/ste:x%x flg:x%x",
7735 did
, vport
->port_state
, ndlp
->nlp_flag
);
7737 phba
->fc_stat
.elsRcvRNID
++;
7738 lpfc_els_rcv_rnid(vport
, elsiocb
, ndlp
);
7743 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
7744 "RCV RTV: did:x%x/ste:x%x flg:x%x",
7745 did
, vport
->port_state
, ndlp
->nlp_flag
);
7746 phba
->fc_stat
.elsRcvRTV
++;
7747 lpfc_els_rcv_rtv(vport
, elsiocb
, ndlp
);
7752 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
7753 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
7754 did
, vport
->port_state
, ndlp
->nlp_flag
);
7756 phba
->fc_stat
.elsRcvRRQ
++;
7757 lpfc_els_rcv_rrq(vport
, elsiocb
, ndlp
);
7762 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
7763 "RCV ECHO: did:x%x/ste:x%x flg:x%x",
7764 did
, vport
->port_state
, ndlp
->nlp_flag
);
7766 phba
->fc_stat
.elsRcvECHO
++;
7767 lpfc_els_rcv_echo(vport
, elsiocb
, ndlp
);
7772 /* receive this due to exchange closed */
7773 rjt_err
= LSRJT_UNABLE_TPC
;
7774 rjt_exp
= LSEXP_INVALID_OX_RX
;
7777 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
7778 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
7779 cmd
, did
, vport
->port_state
);
7781 /* Unsupported ELS command, reject */
7782 rjt_err
= LSRJT_CMD_UNSUPPORTED
;
7783 rjt_exp
= LSEXP_NOTHING_MORE
;
7785 /* Unknown ELS command <elsCmd> received from NPORT <did> */
7786 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
7787 "0115 Unknown ELS command x%x "
7788 "received from NPORT x%x\n", cmd
, did
);
7795 /* check if need to LS_RJT received ELS cmd */
7797 memset(&stat
, 0, sizeof(stat
));
7798 stat
.un
.b
.lsRjtRsnCode
= rjt_err
;
7799 stat
.un
.b
.lsRjtRsnCodeExp
= rjt_exp
;
7800 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, elsiocb
, ndlp
,
7804 lpfc_nlp_put(elsiocb
->context1
);
7805 elsiocb
->context1
= NULL
;
7809 if (vport
&& !(vport
->load_flag
& FC_UNLOADING
))
7810 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
7811 "0111 Dropping received ELS cmd "
7812 "Data: x%x x%x x%x\n",
7813 icmd
->ulpStatus
, icmd
->un
.ulpWord
[4], icmd
->ulpTimeout
);
7814 phba
->fc_stat
.elsRcvDrop
++;
7818 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
7819 * @phba: pointer to lpfc hba data structure.
7820 * @pring: pointer to a SLI ring.
7821 * @elsiocb: pointer to lpfc els iocb data structure.
7823 * This routine is used to process an unsolicited event received from a SLI
7824 * (Service Level Interface) ring. The actual processing of the data buffer
7825 * associated with the unsolicited event is done by invoking the routine
7826 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
7827 * SLI ring on which the unsolicited event was received.
7830 lpfc_els_unsol_event(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
7831 struct lpfc_iocbq
*elsiocb
)
7833 struct lpfc_vport
*vport
= phba
->pport
;
7834 IOCB_t
*icmd
= &elsiocb
->iocb
;
7836 struct lpfc_dmabuf
*bdeBuf1
= elsiocb
->context2
;
7837 struct lpfc_dmabuf
*bdeBuf2
= elsiocb
->context3
;
7839 elsiocb
->context1
= NULL
;
7840 elsiocb
->context2
= NULL
;
7841 elsiocb
->context3
= NULL
;
7843 if (icmd
->ulpStatus
== IOSTAT_NEED_BUFFER
) {
7844 lpfc_sli_hbqbuf_add_hbqs(phba
, LPFC_ELS_HBQ
);
7845 } else if (icmd
->ulpStatus
== IOSTAT_LOCAL_REJECT
&&
7846 (icmd
->un
.ulpWord
[4] & IOERR_PARAM_MASK
) ==
7847 IOERR_RCV_BUFFER_WAITING
) {
7848 phba
->fc_stat
.NoRcvBuf
++;
7849 /* Not enough posted buffers; Try posting more buffers */
7850 if (!(phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
))
7851 lpfc_post_buffer(phba
, pring
, 0);
7855 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
7856 (icmd
->ulpCommand
== CMD_IOCB_RCV_ELS64_CX
||
7857 icmd
->ulpCommand
== CMD_IOCB_RCV_SEQ64_CX
)) {
7858 if (icmd
->unsli3
.rcvsli3
.vpi
== 0xffff)
7859 vport
= phba
->pport
;
7861 vport
= lpfc_find_vport_by_vpid(phba
,
7862 icmd
->unsli3
.rcvsli3
.vpi
);
7865 /* If there are no BDEs associated
7866 * with this IOCB, there is nothing to do.
7868 if (icmd
->ulpBdeCount
== 0)
7871 /* type of ELS cmd is first 32bit word
7874 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) {
7875 elsiocb
->context2
= bdeBuf1
;
7877 paddr
= getPaddr(icmd
->un
.cont64
[0].addrHigh
,
7878 icmd
->un
.cont64
[0].addrLow
);
7879 elsiocb
->context2
= lpfc_sli_ringpostbuf_get(phba
, pring
,
7883 lpfc_els_unsol_buffer(phba
, pring
, vport
, elsiocb
);
7885 * The different unsolicited event handlers would tell us
7886 * if they are done with "mp" by setting context2 to NULL.
7888 if (elsiocb
->context2
) {
7889 lpfc_in_buf_free(phba
, (struct lpfc_dmabuf
*)elsiocb
->context2
);
7890 elsiocb
->context2
= NULL
;
7893 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
7894 if ((phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) &&
7895 icmd
->ulpBdeCount
== 2) {
7896 elsiocb
->context2
= bdeBuf2
;
7897 lpfc_els_unsol_buffer(phba
, pring
, vport
, elsiocb
);
7898 /* free mp if we are done with it */
7899 if (elsiocb
->context2
) {
7900 lpfc_in_buf_free(phba
, elsiocb
->context2
);
7901 elsiocb
->context2
= NULL
;
7907 lpfc_start_fdmi(struct lpfc_vport
*vport
)
7909 struct lpfc_hba
*phba
= vport
->phba
;
7910 struct lpfc_nodelist
*ndlp
;
7912 /* If this is the first time, allocate an ndlp and initialize
7913 * it. Otherwise, make sure the node is enabled and then do the
7916 ndlp
= lpfc_findnode_did(vport
, FDMI_DID
);
7918 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
7920 lpfc_nlp_init(vport
, ndlp
, FDMI_DID
);
7921 ndlp
->nlp_type
|= NLP_FABRIC
;
7926 if (!NLP_CHK_NODE_ACT(ndlp
))
7927 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_NPR_NODE
);
7930 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
7931 lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0);
7936 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
7937 * @phba: pointer to lpfc hba data structure.
7938 * @vport: pointer to a virtual N_Port data structure.
7940 * This routine issues a Port Login (PLOGI) to the Name Server with
7941 * State Change Request (SCR) for a @vport. This routine will create an
7942 * ndlp for the Name Server associated to the @vport if such node does
7943 * not already exist. The PLOGI to Name Server is issued by invoking the
7944 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
7945 * (FDMI) is configured to the @vport, a FDMI node will be created and
7946 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
7949 lpfc_do_scr_ns_plogi(struct lpfc_hba
*phba
, struct lpfc_vport
*vport
)
7951 struct lpfc_nodelist
*ndlp
;
7952 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
7955 * If lpfc_delay_discovery parameter is set and the clean address
7956 * bit is cleared and fc fabric parameters chenged, delay FC NPort
7959 spin_lock_irq(shost
->host_lock
);
7960 if (vport
->fc_flag
& FC_DISC_DELAYED
) {
7961 spin_unlock_irq(shost
->host_lock
);
7962 lpfc_printf_log(phba
, KERN_ERR
, LOG_DISCOVERY
,
7963 "3334 Delay fc port discovery for %d seconds\n",
7965 mod_timer(&vport
->delayed_disc_tmo
,
7966 jiffies
+ msecs_to_jiffies(1000 * phba
->fc_ratov
));
7969 spin_unlock_irq(shost
->host_lock
);
7971 ndlp
= lpfc_findnode_did(vport
, NameServer_DID
);
7973 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
7975 if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) {
7976 lpfc_disc_start(vport
);
7979 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
7980 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
7981 "0251 NameServer login: no memory\n");
7984 lpfc_nlp_init(vport
, ndlp
, NameServer_DID
);
7985 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
7986 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
7988 if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) {
7989 lpfc_disc_start(vport
);
7992 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
7993 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
7994 "0348 NameServer login: node freed\n");
7998 ndlp
->nlp_type
|= NLP_FABRIC
;
8000 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
8002 if (lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0)) {
8003 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
8004 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
8005 "0252 Cannot issue NameServer login\n");
8009 if ((phba
->cfg_enable_SmartSAN
||
8010 (phba
->cfg_fdmi_on
== LPFC_FDMI_SUPPORT
)) &&
8011 (vport
->load_flag
& FC_ALLOW_FDMI
))
8012 lpfc_start_fdmi(vport
);
8016 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
8017 * @phba: pointer to lpfc hba data structure.
8018 * @pmb: pointer to the driver internal queue element for mailbox command.
8020 * This routine is the completion callback function to register new vport
8021 * mailbox command. If the new vport mailbox command completes successfully,
8022 * the fabric registration login shall be performed on physical port (the
8023 * new vport created is actually a physical port, with VPI 0) or the port
8024 * login to Name Server for State Change Request (SCR) will be performed
8025 * on virtual port (real virtual port, with VPI greater than 0).
8028 lpfc_cmpl_reg_new_vport(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
8030 struct lpfc_vport
*vport
= pmb
->vport
;
8031 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
8032 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
8033 MAILBOX_t
*mb
= &pmb
->u
.mb
;
8036 spin_lock_irq(shost
->host_lock
);
8037 vport
->fc_flag
&= ~FC_VPORT_NEEDS_REG_VPI
;
8038 spin_unlock_irq(shost
->host_lock
);
8040 if (mb
->mbxStatus
) {
8041 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
8042 "0915 Register VPI failed : Status: x%x"
8043 " upd bit: x%x \n", mb
->mbxStatus
,
8044 mb
->un
.varRegVpi
.upd
);
8045 if (phba
->sli_rev
== LPFC_SLI_REV4
&&
8046 mb
->un
.varRegVpi
.upd
)
8047 goto mbox_err_exit
;
8049 switch (mb
->mbxStatus
) {
8050 case 0x11: /* unsupported feature */
8051 case 0x9603: /* max_vpi exceeded */
8052 case 0x9602: /* Link event since CLEAR_LA */
8053 /* giving up on vport registration */
8054 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
8055 spin_lock_irq(shost
->host_lock
);
8056 vport
->fc_flag
&= ~(FC_FABRIC
| FC_PUBLIC_LOOP
);
8057 spin_unlock_irq(shost
->host_lock
);
8058 lpfc_can_disctmo(vport
);
8060 /* If reg_vpi fail with invalid VPI status, re-init VPI */
8062 spin_lock_irq(shost
->host_lock
);
8063 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
8064 spin_unlock_irq(shost
->host_lock
);
8065 lpfc_init_vpi(phba
, pmb
, vport
->vpi
);
8067 pmb
->mbox_cmpl
= lpfc_init_vpi_cmpl
;
8068 rc
= lpfc_sli_issue_mbox(phba
, pmb
,
8070 if (rc
== MBX_NOT_FINISHED
) {
8071 lpfc_printf_vlog(vport
,
8073 "2732 Failed to issue INIT_VPI"
8074 " mailbox command\n");
8081 /* Try to recover from this error */
8082 if (phba
->sli_rev
== LPFC_SLI_REV4
)
8083 lpfc_sli4_unreg_all_rpis(vport
);
8084 lpfc_mbx_unreg_vpi(vport
);
8085 spin_lock_irq(shost
->host_lock
);
8086 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
8087 spin_unlock_irq(shost
->host_lock
);
8088 if (vport
->port_type
== LPFC_PHYSICAL_PORT
8089 && !(vport
->fc_flag
& FC_LOGO_RCVD_DID_CHNG
))
8090 lpfc_issue_init_vfi(vport
);
8092 lpfc_initial_fdisc(vport
);
8096 spin_lock_irq(shost
->host_lock
);
8097 vport
->vpi_state
|= LPFC_VPI_REGISTERED
;
8098 spin_unlock_irq(shost
->host_lock
);
8099 if (vport
== phba
->pport
) {
8100 if (phba
->sli_rev
< LPFC_SLI_REV4
)
8101 lpfc_issue_fabric_reglogin(vport
);
8104 * If the physical port is instantiated using
8105 * FDISC, do not start vport discovery.
8107 if (vport
->port_state
!= LPFC_FDISC
)
8108 lpfc_start_fdiscs(phba
);
8109 lpfc_do_scr_ns_plogi(phba
, vport
);
8112 lpfc_do_scr_ns_plogi(phba
, vport
);
8115 /* Now, we decrement the ndlp reference count held for this
8120 mempool_free(pmb
, phba
->mbox_mem_pool
);
8125 * lpfc_register_new_vport - Register a new vport with a HBA
8126 * @phba: pointer to lpfc hba data structure.
8127 * @vport: pointer to a host virtual N_Port data structure.
8128 * @ndlp: pointer to a node-list data structure.
8130 * This routine registers the @vport as a new virtual port with a HBA.
8131 * It is done through a registering vpi mailbox command.
8134 lpfc_register_new_vport(struct lpfc_hba
*phba
, struct lpfc_vport
*vport
,
8135 struct lpfc_nodelist
*ndlp
)
8137 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
8140 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
8142 lpfc_reg_vpi(vport
, mbox
);
8143 mbox
->vport
= vport
;
8144 mbox
->context2
= lpfc_nlp_get(ndlp
);
8145 mbox
->mbox_cmpl
= lpfc_cmpl_reg_new_vport
;
8146 if (lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
)
8147 == MBX_NOT_FINISHED
) {
8148 /* mailbox command not success, decrement ndlp
8149 * reference count for this command
8152 mempool_free(mbox
, phba
->mbox_mem_pool
);
8154 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
8155 "0253 Register VPI: Can't send mbox\n");
8159 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
8160 "0254 Register VPI: no memory\n");
8166 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
8167 spin_lock_irq(shost
->host_lock
);
8168 vport
->fc_flag
&= ~FC_VPORT_NEEDS_REG_VPI
;
8169 spin_unlock_irq(shost
->host_lock
);
8174 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
8175 * @phba: pointer to lpfc hba data structure.
8177 * This routine cancels the retry delay timers to all the vports.
8180 lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba
*phba
)
8182 struct lpfc_vport
**vports
;
8183 struct lpfc_nodelist
*ndlp
;
8184 uint32_t link_state
;
8187 /* Treat this failure as linkdown for all vports */
8188 link_state
= phba
->link_state
;
8189 lpfc_linkdown(phba
);
8190 phba
->link_state
= link_state
;
8192 vports
= lpfc_create_vport_work_array(phba
);
8195 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
8196 ndlp
= lpfc_findnode_did(vports
[i
], Fabric_DID
);
8198 lpfc_cancel_retry_delay_tmo(vports
[i
], ndlp
);
8199 lpfc_els_flush_cmd(vports
[i
]);
8201 lpfc_destroy_vport_work_array(phba
, vports
);
8206 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
8207 * @phba: pointer to lpfc hba data structure.
8209 * This routine abort all pending discovery commands and
8210 * start a timer to retry FLOGI for the physical port
8214 lpfc_retry_pport_discovery(struct lpfc_hba
*phba
)
8216 struct lpfc_nodelist
*ndlp
;
8217 struct Scsi_Host
*shost
;
8219 /* Cancel the all vports retry delay retry timers */
8220 lpfc_cancel_all_vport_retry_delay_timer(phba
);
8222 /* If fabric require FLOGI, then re-instantiate physical login */
8223 ndlp
= lpfc_findnode_did(phba
->pport
, Fabric_DID
);
8227 shost
= lpfc_shost_from_vport(phba
->pport
);
8228 mod_timer(&ndlp
->nlp_delayfunc
, jiffies
+ msecs_to_jiffies(1000));
8229 spin_lock_irq(shost
->host_lock
);
8230 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
8231 spin_unlock_irq(shost
->host_lock
);
8232 ndlp
->nlp_last_elscmd
= ELS_CMD_FLOGI
;
8233 phba
->pport
->port_state
= LPFC_FLOGI
;
8238 * lpfc_fabric_login_reqd - Check if FLOGI required.
8239 * @phba: pointer to lpfc hba data structure.
8240 * @cmdiocb: pointer to FDISC command iocb.
8241 * @rspiocb: pointer to FDISC response iocb.
8243 * This routine checks if a FLOGI is reguired for FDISC
8247 lpfc_fabric_login_reqd(struct lpfc_hba
*phba
,
8248 struct lpfc_iocbq
*cmdiocb
,
8249 struct lpfc_iocbq
*rspiocb
)
8252 if ((rspiocb
->iocb
.ulpStatus
!= IOSTAT_FABRIC_RJT
) ||
8253 (rspiocb
->iocb
.un
.ulpWord
[4] != RJT_LOGIN_REQUIRED
))
8260 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
8261 * @phba: pointer to lpfc hba data structure.
8262 * @cmdiocb: pointer to lpfc command iocb data structure.
8263 * @rspiocb: pointer to lpfc response iocb data structure.
8265 * This routine is the completion callback function to a Fabric Discover
8266 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
8267 * single threaded, each FDISC completion callback function will reset
8268 * the discovery timer for all vports such that the timers will not get
8269 * unnecessary timeout. The function checks the FDISC IOCB status. If error
8270 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
8271 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
8272 * assigned to the vport has been changed with the completion of the FDISC
8273 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
8274 * are unregistered from the HBA, and then the lpfc_register_new_vport()
8275 * routine is invoked to register new vport with the HBA. Otherwise, the
8276 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
8277 * Server for State Change Request (SCR).
8280 lpfc_cmpl_els_fdisc(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
8281 struct lpfc_iocbq
*rspiocb
)
8283 struct lpfc_vport
*vport
= cmdiocb
->vport
;
8284 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
8285 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
8286 struct lpfc_nodelist
*np
;
8287 struct lpfc_nodelist
*next_np
;
8288 IOCB_t
*irsp
= &rspiocb
->iocb
;
8289 struct lpfc_iocbq
*piocb
;
8290 struct lpfc_dmabuf
*pcmd
= cmdiocb
->context2
, *prsp
;
8291 struct serv_parm
*sp
;
8292 uint8_t fabric_param_changed
;
8294 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
8295 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
8296 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
8298 /* Since all FDISCs are being single threaded, we
8299 * must reset the discovery timer for ALL vports
8300 * waiting to send FDISC when one completes.
8302 list_for_each_entry(piocb
, &phba
->fabric_iocb_list
, list
) {
8303 lpfc_set_disctmo(piocb
->vport
);
8306 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
8307 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
8308 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4], vport
->fc_prevDID
);
8310 if (irsp
->ulpStatus
) {
8312 if (lpfc_fabric_login_reqd(phba
, cmdiocb
, rspiocb
)) {
8313 lpfc_retry_pport_discovery(phba
);
8317 /* Check for retry */
8318 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
))
8321 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
8322 "0126 FDISC failed. (x%x/x%x)\n",
8323 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4]);
8326 spin_lock_irq(shost
->host_lock
);
8327 vport
->fc_flag
&= ~FC_VPORT_CVL_RCVD
;
8328 vport
->fc_flag
&= ~FC_VPORT_LOGO_RCVD
;
8329 vport
->fc_flag
|= FC_FABRIC
;
8330 if (vport
->phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
)
8331 vport
->fc_flag
|= FC_PUBLIC_LOOP
;
8332 spin_unlock_irq(shost
->host_lock
);
8334 vport
->fc_myDID
= irsp
->un
.ulpWord
[4] & Mask_DID
;
8335 lpfc_vport_set_state(vport
, FC_VPORT_ACTIVE
);
8336 prsp
= list_get_first(&pcmd
->list
, struct lpfc_dmabuf
, list
);
8339 sp
= prsp
->virt
+ sizeof(uint32_t);
8340 fabric_param_changed
= lpfc_check_clean_addr_bit(vport
, sp
);
8341 memcpy(&vport
->fabric_portname
, &sp
->portName
,
8342 sizeof(struct lpfc_name
));
8343 memcpy(&vport
->fabric_nodename
, &sp
->nodeName
,
8344 sizeof(struct lpfc_name
));
8345 if (fabric_param_changed
&&
8346 !(vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
)) {
8347 /* If our NportID changed, we need to ensure all
8348 * remaining NPORTs get unreg_login'ed so we can
8351 list_for_each_entry_safe(np
, next_np
,
8352 &vport
->fc_nodes
, nlp_listp
) {
8353 if (!NLP_CHK_NODE_ACT(ndlp
) ||
8354 (np
->nlp_state
!= NLP_STE_NPR_NODE
) ||
8355 !(np
->nlp_flag
& NLP_NPR_ADISC
))
8357 spin_lock_irq(shost
->host_lock
);
8358 np
->nlp_flag
&= ~NLP_NPR_ADISC
;
8359 spin_unlock_irq(shost
->host_lock
);
8360 lpfc_unreg_rpi(vport
, np
);
8362 lpfc_cleanup_pending_mbox(vport
);
8364 if (phba
->sli_rev
== LPFC_SLI_REV4
)
8365 lpfc_sli4_unreg_all_rpis(vport
);
8367 lpfc_mbx_unreg_vpi(vport
);
8368 spin_lock_irq(shost
->host_lock
);
8369 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
8370 if (phba
->sli_rev
== LPFC_SLI_REV4
)
8371 vport
->fc_flag
|= FC_VPORT_NEEDS_INIT_VPI
;
8373 vport
->fc_flag
|= FC_LOGO_RCVD_DID_CHNG
;
8374 spin_unlock_irq(shost
->host_lock
);
8375 } else if ((phba
->sli_rev
== LPFC_SLI_REV4
) &&
8376 !(vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
)) {
8378 * Driver needs to re-reg VPI in order for f/w
8379 * to update the MAC address.
8381 lpfc_register_new_vport(phba
, vport
, ndlp
);
8385 if (vport
->fc_flag
& FC_VPORT_NEEDS_INIT_VPI
)
8386 lpfc_issue_init_vpi(vport
);
8387 else if (vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
)
8388 lpfc_register_new_vport(phba
, vport
, ndlp
);
8390 lpfc_do_scr_ns_plogi(phba
, vport
);
8393 if (vport
->fc_vport
->vport_state
!= FC_VPORT_NO_FABRIC_RSCS
)
8394 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
8395 /* Cancel discovery timer */
8396 lpfc_can_disctmo(vport
);
8399 lpfc_els_free_iocb(phba
, cmdiocb
);
8403 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
8404 * @vport: pointer to a virtual N_Port data structure.
8405 * @ndlp: pointer to a node-list data structure.
8406 * @retry: number of retries to the command IOCB.
8408 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
8409 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
8410 * routine to issue the IOCB, which makes sure only one outstanding fabric
8411 * IOCB will be sent off HBA at any given time.
8413 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
8414 * will be incremented by 1 for holding the ndlp and the reference to ndlp
8415 * will be stored into the context1 field of the IOCB for the completion
8416 * callback function to the FDISC ELS command.
8419 * 0 - Successfully issued fdisc iocb command
8420 * 1 - Failed to issue fdisc iocb command
8423 lpfc_issue_els_fdisc(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
8426 struct lpfc_hba
*phba
= vport
->phba
;
8428 struct lpfc_iocbq
*elsiocb
;
8429 struct serv_parm
*sp
;
8432 int did
= ndlp
->nlp_DID
;
8435 vport
->port_state
= LPFC_FDISC
;
8436 vport
->fc_myDID
= 0;
8437 cmdsize
= (sizeof(uint32_t) + sizeof(struct serv_parm
));
8438 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
, did
,
8441 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
8442 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
8443 "0255 Issue FDISC: no IOCB\n");
8447 icmd
= &elsiocb
->iocb
;
8448 icmd
->un
.elsreq64
.myID
= 0;
8449 icmd
->un
.elsreq64
.fl
= 1;
8452 * SLI3 ports require a different context type value than SLI4.
8453 * Catch SLI3 ports here and override the prep.
8455 if (phba
->sli_rev
== LPFC_SLI_REV3
) {
8460 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
8461 *((uint32_t *) (pcmd
)) = ELS_CMD_FDISC
;
8462 pcmd
+= sizeof(uint32_t); /* CSP Word 1 */
8463 memcpy(pcmd
, &vport
->phba
->pport
->fc_sparam
, sizeof(struct serv_parm
));
8464 sp
= (struct serv_parm
*) pcmd
;
8465 /* Setup CSPs accordingly for Fabric */
8466 sp
->cmn
.e_d_tov
= 0;
8467 sp
->cmn
.w2
.r_a_tov
= 0;
8468 sp
->cmn
.virtual_fabric_support
= 0;
8469 sp
->cls1
.classValid
= 0;
8470 sp
->cls2
.seqDelivery
= 1;
8471 sp
->cls3
.seqDelivery
= 1;
8473 pcmd
+= sizeof(uint32_t); /* CSP Word 2 */
8474 pcmd
+= sizeof(uint32_t); /* CSP Word 3 */
8475 pcmd
+= sizeof(uint32_t); /* CSP Word 4 */
8476 pcmd
+= sizeof(uint32_t); /* Port Name */
8477 memcpy(pcmd
, &vport
->fc_portname
, 8);
8478 pcmd
+= sizeof(uint32_t); /* Node Name */
8479 pcmd
+= sizeof(uint32_t); /* Node Name */
8480 memcpy(pcmd
, &vport
->fc_nodename
, 8);
8482 lpfc_set_disctmo(vport
);
8484 phba
->fc_stat
.elsXmitFDISC
++;
8485 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_fdisc
;
8487 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
8488 "Issue FDISC: did:x%x",
8491 rc
= lpfc_issue_fabric_iocb(phba
, elsiocb
);
8492 if (rc
== IOCB_ERROR
) {
8493 lpfc_els_free_iocb(phba
, elsiocb
);
8494 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
8495 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
8496 "0256 Issue FDISC: Cannot send IOCB\n");
8499 lpfc_vport_set_state(vport
, FC_VPORT_INITIALIZING
);
8504 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
8505 * @phba: pointer to lpfc hba data structure.
8506 * @cmdiocb: pointer to lpfc command iocb data structure.
8507 * @rspiocb: pointer to lpfc response iocb data structure.
8509 * This routine is the completion callback function to the issuing of a LOGO
8510 * ELS command off a vport. It frees the command IOCB and then decrement the
8511 * reference count held on ndlp for this completion function, indicating that
8512 * the reference to the ndlp is no long needed. Note that the
8513 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
8514 * callback function and an additional explicit ndlp reference decrementation
8515 * will trigger the actual release of the ndlp.
8518 lpfc_cmpl_els_npiv_logo(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
8519 struct lpfc_iocbq
*rspiocb
)
8521 struct lpfc_vport
*vport
= cmdiocb
->vport
;
8523 struct lpfc_nodelist
*ndlp
;
8524 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
8526 ndlp
= (struct lpfc_nodelist
*)cmdiocb
->context1
;
8527 irsp
= &rspiocb
->iocb
;
8528 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
8529 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
8530 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4], irsp
->un
.rcvels
.remoteID
);
8532 lpfc_els_free_iocb(phba
, cmdiocb
);
8533 vport
->unreg_vpi_cmpl
= VPORT_ERROR
;
8535 /* Trigger the release of the ndlp after logo */
8538 /* NPIV LOGO completes to NPort <nlp_DID> */
8539 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
8540 "2928 NPIV LOGO completes to NPort x%x "
8541 "Data: x%x x%x x%x x%x\n",
8542 ndlp
->nlp_DID
, irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
8543 irsp
->ulpTimeout
, vport
->num_disc_nodes
);
8545 if (irsp
->ulpStatus
== IOSTAT_SUCCESS
) {
8546 spin_lock_irq(shost
->host_lock
);
8547 vport
->fc_flag
&= ~FC_NDISC_ACTIVE
;
8548 vport
->fc_flag
&= ~FC_FABRIC
;
8549 spin_unlock_irq(shost
->host_lock
);
8550 lpfc_can_disctmo(vport
);
8555 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
8556 * @vport: pointer to a virtual N_Port data structure.
8557 * @ndlp: pointer to a node-list data structure.
8559 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
8561 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
8562 * will be incremented by 1 for holding the ndlp and the reference to ndlp
8563 * will be stored into the context1 field of the IOCB for the completion
8564 * callback function to the LOGO ELS command.
8567 * 0 - Successfully issued logo off the @vport
8568 * 1 - Failed to issue logo off the @vport
8571 lpfc_issue_els_npiv_logo(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
8573 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
8574 struct lpfc_hba
*phba
= vport
->phba
;
8575 struct lpfc_iocbq
*elsiocb
;
8579 cmdsize
= 2 * sizeof(uint32_t) + sizeof(struct lpfc_name
);
8580 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, 0, ndlp
, ndlp
->nlp_DID
,
8585 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
8586 *((uint32_t *) (pcmd
)) = ELS_CMD_LOGO
;
8587 pcmd
+= sizeof(uint32_t);
8589 /* Fill in LOGO payload */
8590 *((uint32_t *) (pcmd
)) = be32_to_cpu(vport
->fc_myDID
);
8591 pcmd
+= sizeof(uint32_t);
8592 memcpy(pcmd
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
8594 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
8595 "Issue LOGO npiv did:x%x flg:x%x",
8596 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
8598 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_npiv_logo
;
8599 spin_lock_irq(shost
->host_lock
);
8600 ndlp
->nlp_flag
|= NLP_LOGO_SND
;
8601 spin_unlock_irq(shost
->host_lock
);
8602 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) ==
8604 spin_lock_irq(shost
->host_lock
);
8605 ndlp
->nlp_flag
&= ~NLP_LOGO_SND
;
8606 spin_unlock_irq(shost
->host_lock
);
8607 lpfc_els_free_iocb(phba
, elsiocb
);
8614 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
8615 * @ptr: holder for the timer function associated data.
8617 * This routine is invoked by the fabric iocb block timer after
8618 * timeout. It posts the fabric iocb block timeout event by setting the
8619 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
8620 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
8621 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
8622 * posted event WORKER_FABRIC_BLOCK_TMO.
8625 lpfc_fabric_block_timeout(unsigned long ptr
)
8627 struct lpfc_hba
*phba
= (struct lpfc_hba
*) ptr
;
8628 unsigned long iflags
;
8629 uint32_t tmo_posted
;
8631 spin_lock_irqsave(&phba
->pport
->work_port_lock
, iflags
);
8632 tmo_posted
= phba
->pport
->work_port_events
& WORKER_FABRIC_BLOCK_TMO
;
8634 phba
->pport
->work_port_events
|= WORKER_FABRIC_BLOCK_TMO
;
8635 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, iflags
);
8638 lpfc_worker_wake_up(phba
);
8643 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
8644 * @phba: pointer to lpfc hba data structure.
8646 * This routine issues one fabric iocb from the driver internal list to
8647 * the HBA. It first checks whether it's ready to issue one fabric iocb to
8648 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
8649 * remove one pending fabric iocb from the driver internal list and invokes
8650 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
8653 lpfc_resume_fabric_iocbs(struct lpfc_hba
*phba
)
8655 struct lpfc_iocbq
*iocb
;
8656 unsigned long iflags
;
8662 spin_lock_irqsave(&phba
->hbalock
, iflags
);
8663 /* Post any pending iocb to the SLI layer */
8664 if (atomic_read(&phba
->fabric_iocb_count
) == 0) {
8665 list_remove_head(&phba
->fabric_iocb_list
, iocb
, typeof(*iocb
),
8668 /* Increment fabric iocb count to hold the position */
8669 atomic_inc(&phba
->fabric_iocb_count
);
8671 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8673 iocb
->fabric_iocb_cmpl
= iocb
->iocb_cmpl
;
8674 iocb
->iocb_cmpl
= lpfc_cmpl_fabric_iocb
;
8675 iocb
->iocb_flag
|= LPFC_IO_FABRIC
;
8677 lpfc_debugfs_disc_trc(iocb
->vport
, LPFC_DISC_TRC_ELS_CMD
,
8678 "Fabric sched1: ste:x%x",
8679 iocb
->vport
->port_state
, 0, 0);
8681 ret
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, iocb
, 0);
8683 if (ret
== IOCB_ERROR
) {
8684 iocb
->iocb_cmpl
= iocb
->fabric_iocb_cmpl
;
8685 iocb
->fabric_iocb_cmpl
= NULL
;
8686 iocb
->iocb_flag
&= ~LPFC_IO_FABRIC
;
8688 cmd
->ulpStatus
= IOSTAT_LOCAL_REJECT
;
8689 cmd
->un
.ulpWord
[4] = IOERR_SLI_ABORTED
;
8690 iocb
->iocb_cmpl(phba
, iocb
, iocb
);
8692 atomic_dec(&phba
->fabric_iocb_count
);
8701 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
8702 * @phba: pointer to lpfc hba data structure.
8704 * This routine unblocks the issuing fabric iocb command. The function
8705 * will clear the fabric iocb block bit and then invoke the routine
8706 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
8707 * from the driver internal fabric iocb list.
8710 lpfc_unblock_fabric_iocbs(struct lpfc_hba
*phba
)
8712 clear_bit(FABRIC_COMANDS_BLOCKED
, &phba
->bit_flags
);
8714 lpfc_resume_fabric_iocbs(phba
);
8719 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
8720 * @phba: pointer to lpfc hba data structure.
8722 * This routine blocks the issuing fabric iocb for a specified amount of
8723 * time (currently 100 ms). This is done by set the fabric iocb block bit
8724 * and set up a timeout timer for 100ms. When the block bit is set, no more
8725 * fabric iocb will be issued out of the HBA.
8728 lpfc_block_fabric_iocbs(struct lpfc_hba
*phba
)
8732 blocked
= test_and_set_bit(FABRIC_COMANDS_BLOCKED
, &phba
->bit_flags
);
8733 /* Start a timer to unblock fabric iocbs after 100ms */
8735 mod_timer(&phba
->fabric_block_timer
,
8736 jiffies
+ msecs_to_jiffies(100));
8742 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
8743 * @phba: pointer to lpfc hba data structure.
8744 * @cmdiocb: pointer to lpfc command iocb data structure.
8745 * @rspiocb: pointer to lpfc response iocb data structure.
8747 * This routine is the callback function that is put to the fabric iocb's
8748 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
8749 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
8750 * function first restores and invokes the original iocb's callback function
8751 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
8752 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
8755 lpfc_cmpl_fabric_iocb(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
8756 struct lpfc_iocbq
*rspiocb
)
8760 if ((cmdiocb
->iocb_flag
& LPFC_IO_FABRIC
) != LPFC_IO_FABRIC
)
8763 switch (rspiocb
->iocb
.ulpStatus
) {
8764 case IOSTAT_NPORT_RJT
:
8765 case IOSTAT_FABRIC_RJT
:
8766 if (rspiocb
->iocb
.un
.ulpWord
[4] & RJT_UNAVAIL_TEMP
) {
8767 lpfc_block_fabric_iocbs(phba
);
8771 case IOSTAT_NPORT_BSY
:
8772 case IOSTAT_FABRIC_BSY
:
8773 lpfc_block_fabric_iocbs(phba
);
8777 stat
.un
.lsRjtError
=
8778 be32_to_cpu(rspiocb
->iocb
.un
.ulpWord
[4]);
8779 if ((stat
.un
.b
.lsRjtRsnCode
== LSRJT_UNABLE_TPC
) ||
8780 (stat
.un
.b
.lsRjtRsnCode
== LSRJT_LOGICAL_BSY
))
8781 lpfc_block_fabric_iocbs(phba
);
8785 if (atomic_read(&phba
->fabric_iocb_count
) == 0)
8788 cmdiocb
->iocb_cmpl
= cmdiocb
->fabric_iocb_cmpl
;
8789 cmdiocb
->fabric_iocb_cmpl
= NULL
;
8790 cmdiocb
->iocb_flag
&= ~LPFC_IO_FABRIC
;
8791 cmdiocb
->iocb_cmpl(phba
, cmdiocb
, rspiocb
);
8793 atomic_dec(&phba
->fabric_iocb_count
);
8794 if (!test_bit(FABRIC_COMANDS_BLOCKED
, &phba
->bit_flags
)) {
8795 /* Post any pending iocbs to HBA */
8796 lpfc_resume_fabric_iocbs(phba
);
8801 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
8802 * @phba: pointer to lpfc hba data structure.
8803 * @iocb: pointer to lpfc command iocb data structure.
8805 * This routine is used as the top-level API for issuing a fabric iocb command
8806 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
8807 * function makes sure that only one fabric bound iocb will be outstanding at
8808 * any given time. As such, this function will first check to see whether there
8809 * is already an outstanding fabric iocb on the wire. If so, it will put the
8810 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
8811 * issued later. Otherwise, it will issue the iocb on the wire and update the
8812 * fabric iocb count it indicate that there is one fabric iocb on the wire.
8814 * Note, this implementation has a potential sending out fabric IOCBs out of
8815 * order. The problem is caused by the construction of the "ready" boolen does
8816 * not include the condition that the internal fabric IOCB list is empty. As
8817 * such, it is possible a fabric IOCB issued by this routine might be "jump"
8818 * ahead of the fabric IOCBs in the internal list.
8821 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
8822 * IOCB_ERROR - failed to issue fabric iocb
8825 lpfc_issue_fabric_iocb(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocb
)
8827 unsigned long iflags
;
8831 if (atomic_read(&phba
->fabric_iocb_count
) > 1)
8834 spin_lock_irqsave(&phba
->hbalock
, iflags
);
8835 ready
= atomic_read(&phba
->fabric_iocb_count
) == 0 &&
8836 !test_bit(FABRIC_COMANDS_BLOCKED
, &phba
->bit_flags
);
8839 /* Increment fabric iocb count to hold the position */
8840 atomic_inc(&phba
->fabric_iocb_count
);
8841 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8843 iocb
->fabric_iocb_cmpl
= iocb
->iocb_cmpl
;
8844 iocb
->iocb_cmpl
= lpfc_cmpl_fabric_iocb
;
8845 iocb
->iocb_flag
|= LPFC_IO_FABRIC
;
8847 lpfc_debugfs_disc_trc(iocb
->vport
, LPFC_DISC_TRC_ELS_CMD
,
8848 "Fabric sched2: ste:x%x",
8849 iocb
->vport
->port_state
, 0, 0);
8851 ret
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, iocb
, 0);
8853 if (ret
== IOCB_ERROR
) {
8854 iocb
->iocb_cmpl
= iocb
->fabric_iocb_cmpl
;
8855 iocb
->fabric_iocb_cmpl
= NULL
;
8856 iocb
->iocb_flag
&= ~LPFC_IO_FABRIC
;
8857 atomic_dec(&phba
->fabric_iocb_count
);
8860 spin_lock_irqsave(&phba
->hbalock
, iflags
);
8861 list_add_tail(&iocb
->list
, &phba
->fabric_iocb_list
);
8862 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
8869 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
8870 * @vport: pointer to a virtual N_Port data structure.
8872 * This routine aborts all the IOCBs associated with a @vport from the
8873 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
8874 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
8875 * list, removes each IOCB associated with the @vport off the list, set the
8876 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
8877 * associated with the IOCB.
8879 static void lpfc_fabric_abort_vport(struct lpfc_vport
*vport
)
8881 LIST_HEAD(completions
);
8882 struct lpfc_hba
*phba
= vport
->phba
;
8883 struct lpfc_iocbq
*tmp_iocb
, *piocb
;
8885 spin_lock_irq(&phba
->hbalock
);
8886 list_for_each_entry_safe(piocb
, tmp_iocb
, &phba
->fabric_iocb_list
,
8889 if (piocb
->vport
!= vport
)
8892 list_move_tail(&piocb
->list
, &completions
);
8894 spin_unlock_irq(&phba
->hbalock
);
8896 /* Cancel all the IOCBs from the completions list */
8897 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
8902 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
8903 * @ndlp: pointer to a node-list data structure.
8905 * This routine aborts all the IOCBs associated with an @ndlp from the
8906 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
8907 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
8908 * list, removes each IOCB associated with the @ndlp off the list, set the
8909 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
8910 * associated with the IOCB.
8912 void lpfc_fabric_abort_nport(struct lpfc_nodelist
*ndlp
)
8914 LIST_HEAD(completions
);
8915 struct lpfc_hba
*phba
= ndlp
->phba
;
8916 struct lpfc_iocbq
*tmp_iocb
, *piocb
;
8917 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
8919 spin_lock_irq(&phba
->hbalock
);
8920 list_for_each_entry_safe(piocb
, tmp_iocb
, &phba
->fabric_iocb_list
,
8922 if ((lpfc_check_sli_ndlp(phba
, pring
, piocb
, ndlp
))) {
8924 list_move_tail(&piocb
->list
, &completions
);
8927 spin_unlock_irq(&phba
->hbalock
);
8929 /* Cancel all the IOCBs from the completions list */
8930 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
8935 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
8936 * @phba: pointer to lpfc hba data structure.
8938 * This routine aborts all the IOCBs currently on the driver internal
8939 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
8940 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
8941 * list, removes IOCBs off the list, set the status feild to
8942 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
8945 void lpfc_fabric_abort_hba(struct lpfc_hba
*phba
)
8947 LIST_HEAD(completions
);
8949 spin_lock_irq(&phba
->hbalock
);
8950 list_splice_init(&phba
->fabric_iocb_list
, &completions
);
8951 spin_unlock_irq(&phba
->hbalock
);
8953 /* Cancel all the IOCBs from the completions list */
8954 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
8959 * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport
8960 * @vport: pointer to lpfc vport data structure.
8962 * This routine is invoked by the vport cleanup for deletions and the cleanup
8963 * for an ndlp on removal.
8966 lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport
*vport
)
8968 struct lpfc_hba
*phba
= vport
->phba
;
8969 struct lpfc_sglq
*sglq_entry
= NULL
, *sglq_next
= NULL
;
8970 unsigned long iflag
= 0;
8972 spin_lock_irqsave(&phba
->hbalock
, iflag
);
8973 spin_lock(&phba
->sli4_hba
.abts_sgl_list_lock
);
8974 list_for_each_entry_safe(sglq_entry
, sglq_next
,
8975 &phba
->sli4_hba
.lpfc_abts_els_sgl_list
, list
) {
8976 if (sglq_entry
->ndlp
&& sglq_entry
->ndlp
->vport
== vport
)
8977 sglq_entry
->ndlp
= NULL
;
8979 spin_unlock(&phba
->sli4_hba
.abts_sgl_list_lock
);
8980 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
8985 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
8986 * @phba: pointer to lpfc hba data structure.
8987 * @axri: pointer to the els xri abort wcqe structure.
8989 * This routine is invoked by the worker thread to process a SLI4 slow-path
8993 lpfc_sli4_els_xri_aborted(struct lpfc_hba
*phba
,
8994 struct sli4_wcqe_xri_aborted
*axri
)
8996 uint16_t xri
= bf_get(lpfc_wcqe_xa_xri
, axri
);
8997 uint16_t rxid
= bf_get(lpfc_wcqe_xa_remote_xid
, axri
);
9000 struct lpfc_sglq
*sglq_entry
= NULL
, *sglq_next
= NULL
;
9001 unsigned long iflag
= 0;
9002 struct lpfc_nodelist
*ndlp
;
9003 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
9005 spin_lock_irqsave(&phba
->hbalock
, iflag
);
9006 spin_lock(&phba
->sli4_hba
.abts_sgl_list_lock
);
9007 list_for_each_entry_safe(sglq_entry
, sglq_next
,
9008 &phba
->sli4_hba
.lpfc_abts_els_sgl_list
, list
) {
9009 if (sglq_entry
->sli4_xritag
== xri
) {
9010 list_del(&sglq_entry
->list
);
9011 ndlp
= sglq_entry
->ndlp
;
9012 sglq_entry
->ndlp
= NULL
;
9013 spin_lock(&pring
->ring_lock
);
9014 list_add_tail(&sglq_entry
->list
,
9015 &phba
->sli4_hba
.lpfc_sgl_list
);
9016 sglq_entry
->state
= SGL_FREED
;
9017 spin_unlock(&pring
->ring_lock
);
9018 spin_unlock(&phba
->sli4_hba
.abts_sgl_list_lock
);
9019 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
9020 lpfc_set_rrq_active(phba
, ndlp
,
9021 sglq_entry
->sli4_lxritag
,
9024 /* Check if TXQ queue needs to be serviced */
9025 if (!(list_empty(&pring
->txq
)))
9026 lpfc_worker_wake_up(phba
);
9030 spin_unlock(&phba
->sli4_hba
.abts_sgl_list_lock
);
9031 lxri
= lpfc_sli4_xri_inrange(phba
, xri
);
9032 if (lxri
== NO_XRI
) {
9033 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
9036 spin_lock(&pring
->ring_lock
);
9037 sglq_entry
= __lpfc_get_active_sglq(phba
, lxri
);
9038 if (!sglq_entry
|| (sglq_entry
->sli4_xritag
!= xri
)) {
9039 spin_unlock(&pring
->ring_lock
);
9040 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
9043 sglq_entry
->state
= SGL_XRI_ABORTED
;
9044 spin_unlock(&pring
->ring_lock
);
9045 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
9049 /* lpfc_sli_abts_recover_port - Recover a port that failed a BLS_ABORT req.
9050 * @vport: pointer to virtual port object.
9051 * @ndlp: nodelist pointer for the impacted node.
9053 * The driver calls this routine in response to an SLI4 XRI ABORT CQE
9054 * or an SLI3 ASYNC_STATUS_CN event from the port. For either event,
9055 * the driver is required to send a LOGO to the remote node before it
9056 * attempts to recover its login to the remote node.
9059 lpfc_sli_abts_recover_port(struct lpfc_vport
*vport
,
9060 struct lpfc_nodelist
*ndlp
)
9062 struct Scsi_Host
*shost
;
9063 struct lpfc_hba
*phba
;
9064 unsigned long flags
= 0;
9066 shost
= lpfc_shost_from_vport(vport
);
9068 if (ndlp
->nlp_state
!= NLP_STE_MAPPED_NODE
) {
9069 lpfc_printf_log(phba
, KERN_INFO
,
9070 LOG_SLI
, "3093 No rport recovery needed. "
9071 "rport in state 0x%x\n", ndlp
->nlp_state
);
9074 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
9075 "3094 Start rport recovery on shost id 0x%x "
9076 "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x "
9078 shost
->host_no
, ndlp
->nlp_DID
,
9079 vport
->vpi
, ndlp
->nlp_rpi
, ndlp
->nlp_state
,
9082 * The rport is not responding. Remove the FCP-2 flag to prevent
9083 * an ADISC in the follow-up recovery code.
9085 spin_lock_irqsave(shost
->host_lock
, flags
);
9086 ndlp
->nlp_fcp_info
&= ~NLP_FCP_2_DEVICE
;
9087 spin_unlock_irqrestore(shost
->host_lock
, flags
);
9088 lpfc_issue_els_logo(vport
, ndlp
, 0);
9089 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_LOGO_ISSUE
);