1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2012 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>
35 #include "lpfc_sli4.h"
37 #include "lpfc_disc.h"
38 #include "lpfc_scsi.h"
40 #include "lpfc_logmsg.h"
41 #include "lpfc_crtn.h"
42 #include "lpfc_vport.h"
43 #include "lpfc_debugfs.h"
45 static int lpfc_els_retry(struct lpfc_hba
*, struct lpfc_iocbq
*,
47 static void lpfc_cmpl_fabric_iocb(struct lpfc_hba
*, struct lpfc_iocbq
*,
49 static void lpfc_fabric_abort_vport(struct lpfc_vport
*vport
);
50 static int lpfc_issue_els_fdisc(struct lpfc_vport
*vport
,
51 struct lpfc_nodelist
*ndlp
, uint8_t retry
);
52 static int lpfc_issue_fabric_iocb(struct lpfc_hba
*phba
,
53 struct lpfc_iocbq
*iocb
);
55 static int lpfc_max_els_tries
= 3;
58 * lpfc_els_chk_latt - Check host link attention event for a vport
59 * @vport: pointer to a host virtual N_Port data structure.
61 * This routine checks whether there is an outstanding host link
62 * attention event during the discovery process with the @vport. It is done
63 * by reading the HBA's Host Attention (HA) register. If there is any host
64 * link attention events during this @vport's discovery process, the @vport
65 * shall be marked as FC_ABORT_DISCOVERY, a host link attention clear shall
66 * be issued if the link state is not already in host link cleared state,
67 * and a return code shall indicate whether the host link attention event
70 * Note that, if either the host link is in state LPFC_LINK_DOWN or @vport
71 * state in LPFC_VPORT_READY, the request for checking host link attention
72 * event will be ignored and a return code shall indicate no host link
73 * attention event had happened.
76 * 0 - no host link attention event happened
77 * 1 - host link attention event happened
80 lpfc_els_chk_latt(struct lpfc_vport
*vport
)
82 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
83 struct lpfc_hba
*phba
= vport
->phba
;
86 if (vport
->port_state
>= LPFC_VPORT_READY
||
87 phba
->link_state
== LPFC_LINK_DOWN
||
88 phba
->sli_rev
> LPFC_SLI_REV3
)
91 /* Read the HBA Host Attention Register */
92 if (lpfc_readl(phba
->HAregaddr
, &ha_copy
))
95 if (!(ha_copy
& HA_LATT
))
98 /* Pending Link Event during Discovery */
99 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
100 "0237 Pending Link Event during "
101 "Discovery: State x%x\n",
102 phba
->pport
->port_state
);
104 /* CLEAR_LA should re-enable link attention events and
105 * we should then immediately take a LATT event. The
106 * LATT processing should call lpfc_linkdown() which
107 * will cleanup any left over in-progress discovery
110 spin_lock_irq(shost
->host_lock
);
111 vport
->fc_flag
|= FC_ABORT_DISCOVERY
;
112 spin_unlock_irq(shost
->host_lock
);
114 if (phba
->link_state
!= LPFC_CLEAR_LA
)
115 lpfc_issue_clear_la(phba
, vport
);
121 * lpfc_prep_els_iocb - Allocate and prepare a lpfc iocb data structure
122 * @vport: pointer to a host virtual N_Port data structure.
123 * @expectRsp: flag indicating whether response is expected.
124 * @cmdSize: size of the ELS command.
125 * @retry: number of retries to the command IOCB when it fails.
126 * @ndlp: pointer to a node-list data structure.
127 * @did: destination identifier.
128 * @elscmd: the ELS command code.
130 * This routine is used for allocating a lpfc-IOCB data structure from
131 * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters
132 * passed into the routine for discovery state machine to issue an Extended
133 * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation
134 * and preparation routine that is used by all the discovery state machine
135 * routines and the ELS command-specific fields will be later set up by
136 * the individual discovery machine routines after calling this routine
137 * allocating and preparing a generic IOCB data structure. It fills in the
138 * Buffer Descriptor Entries (BDEs), allocates buffers for both command
139 * payload and response payload (if expected). The reference count on the
140 * ndlp is incremented by 1 and the reference to the ndlp is put into
141 * context1 of the IOCB data structure for this IOCB to hold the ndlp
142 * reference for the command's callback function to access later.
145 * Pointer to the newly allocated/prepared els iocb data structure
146 * NULL - when els iocb data structure allocation/preparation failed
149 lpfc_prep_els_iocb(struct lpfc_vport
*vport
, uint8_t expectRsp
,
150 uint16_t cmdSize
, uint8_t retry
,
151 struct lpfc_nodelist
*ndlp
, uint32_t did
,
154 struct lpfc_hba
*phba
= vport
->phba
;
155 struct lpfc_iocbq
*elsiocb
;
156 struct lpfc_dmabuf
*pcmd
, *prsp
, *pbuflist
;
157 struct ulp_bde64
*bpl
;
161 if (!lpfc_is_link_up(phba
))
164 /* Allocate buffer for command iocb */
165 elsiocb
= lpfc_sli_get_iocbq(phba
);
171 * If this command is for fabric controller and HBA running
172 * in FIP mode send FLOGI, FDISC and LOGO as FIP frames.
174 if ((did
== Fabric_DID
) &&
175 (phba
->hba_flag
& HBA_FIP_SUPPORT
) &&
176 ((elscmd
== ELS_CMD_FLOGI
) ||
177 (elscmd
== ELS_CMD_FDISC
) ||
178 (elscmd
== ELS_CMD_LOGO
)))
181 elsiocb
->iocb_flag
|=
182 ((LPFC_ELS_ID_FLOGI
<< LPFC_FIP_ELS_ID_SHIFT
)
183 & LPFC_FIP_ELS_ID_MASK
);
186 elsiocb
->iocb_flag
|=
187 ((LPFC_ELS_ID_FDISC
<< LPFC_FIP_ELS_ID_SHIFT
)
188 & LPFC_FIP_ELS_ID_MASK
);
191 elsiocb
->iocb_flag
|=
192 ((LPFC_ELS_ID_LOGO
<< LPFC_FIP_ELS_ID_SHIFT
)
193 & LPFC_FIP_ELS_ID_MASK
);
197 elsiocb
->iocb_flag
&= ~LPFC_FIP_ELS_ID_MASK
;
199 icmd
= &elsiocb
->iocb
;
201 /* fill in BDEs for command */
202 /* Allocate buffer for command payload */
203 pcmd
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
205 pcmd
->virt
= lpfc_mbuf_alloc(phba
, MEM_PRI
, &pcmd
->phys
);
206 if (!pcmd
|| !pcmd
->virt
)
207 goto els_iocb_free_pcmb_exit
;
209 INIT_LIST_HEAD(&pcmd
->list
);
211 /* Allocate buffer for response payload */
213 prsp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
215 prsp
->virt
= lpfc_mbuf_alloc(phba
, MEM_PRI
,
217 if (!prsp
|| !prsp
->virt
)
218 goto els_iocb_free_prsp_exit
;
219 INIT_LIST_HEAD(&prsp
->list
);
223 /* Allocate buffer for Buffer ptr list */
224 pbuflist
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
226 pbuflist
->virt
= lpfc_mbuf_alloc(phba
, MEM_PRI
,
228 if (!pbuflist
|| !pbuflist
->virt
)
229 goto els_iocb_free_pbuf_exit
;
231 INIT_LIST_HEAD(&pbuflist
->list
);
234 icmd
->un
.elsreq64
.bdl
.addrHigh
= putPaddrHigh(pbuflist
->phys
);
235 icmd
->un
.elsreq64
.bdl
.addrLow
= putPaddrLow(pbuflist
->phys
);
236 icmd
->un
.elsreq64
.bdl
.bdeFlags
= BUFF_TYPE_BLP_64
;
237 icmd
->un
.elsreq64
.bdl
.bdeSize
= (2 * sizeof(struct ulp_bde64
));
239 icmd
->un
.elsreq64
.remoteID
= did
; /* DID */
240 icmd
->ulpCommand
= CMD_ELS_REQUEST64_CR
;
241 icmd
->ulpTimeout
= phba
->fc_ratov
* 2;
243 icmd
->un
.xseq64
.bdl
.addrHigh
= putPaddrHigh(pbuflist
->phys
);
244 icmd
->un
.xseq64
.bdl
.addrLow
= putPaddrLow(pbuflist
->phys
);
245 icmd
->un
.xseq64
.bdl
.bdeFlags
= BUFF_TYPE_BLP_64
;
246 icmd
->un
.xseq64
.bdl
.bdeSize
= sizeof(struct ulp_bde64
);
247 icmd
->un
.xseq64
.xmit_els_remoteID
= did
; /* DID */
248 icmd
->ulpCommand
= CMD_XMIT_ELS_RSP64_CX
;
250 icmd
->ulpBdeCount
= 1;
252 icmd
->ulpClass
= CLASS3
;
255 * If we have NPIV enabled, we want to send ELS traffic by VPI.
256 * For SLI4, since the driver controls VPIs we also want to include
257 * all ELS pt2pt protocol traffic as well.
259 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) ||
260 ((phba
->sli_rev
== LPFC_SLI_REV4
) &&
261 (vport
->fc_flag
& FC_PT2PT
))) {
264 icmd
->un
.elsreq64
.myID
= vport
->fc_myDID
;
266 /* For ELS_REQUEST64_CR, use the VPI by default */
267 icmd
->ulpContext
= phba
->vpi_ids
[vport
->vpi
];
271 /* The CT field must be 0=INVALID_RPI for the ECHO cmd */
272 if (elscmd
== ELS_CMD_ECHO
)
273 icmd
->ulpCt_l
= 0; /* context = invalid RPI */
275 icmd
->ulpCt_l
= 1; /* context = VPI */
278 bpl
= (struct ulp_bde64
*) pbuflist
->virt
;
279 bpl
->addrLow
= le32_to_cpu(putPaddrLow(pcmd
->phys
));
280 bpl
->addrHigh
= le32_to_cpu(putPaddrHigh(pcmd
->phys
));
281 bpl
->tus
.f
.bdeSize
= cmdSize
;
282 bpl
->tus
.f
.bdeFlags
= 0;
283 bpl
->tus
.w
= le32_to_cpu(bpl
->tus
.w
);
287 bpl
->addrLow
= le32_to_cpu(putPaddrLow(prsp
->phys
));
288 bpl
->addrHigh
= le32_to_cpu(putPaddrHigh(prsp
->phys
));
289 bpl
->tus
.f
.bdeSize
= FCELSSIZE
;
290 bpl
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64
;
291 bpl
->tus
.w
= le32_to_cpu(bpl
->tus
.w
);
294 /* prevent preparing iocb with NULL ndlp reference */
295 elsiocb
->context1
= lpfc_nlp_get(ndlp
);
296 if (!elsiocb
->context1
)
297 goto els_iocb_free_pbuf_exit
;
298 elsiocb
->context2
= pcmd
;
299 elsiocb
->context3
= pbuflist
;
300 elsiocb
->retry
= retry
;
301 elsiocb
->vport
= vport
;
302 elsiocb
->drvrTimeout
= (phba
->fc_ratov
<< 1) + LPFC_DRVR_TIMEOUT
;
305 list_add(&prsp
->list
, &pcmd
->list
);
308 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
309 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
310 "0116 Xmit ELS command x%x to remote "
311 "NPORT x%x I/O tag: x%x, port state: x%x\n",
312 elscmd
, did
, elsiocb
->iotag
,
315 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
316 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
317 "0117 Xmit ELS response x%x to remote "
318 "NPORT x%x I/O tag: x%x, size: x%x\n",
319 elscmd
, ndlp
->nlp_DID
, elsiocb
->iotag
,
324 els_iocb_free_pbuf_exit
:
326 lpfc_mbuf_free(phba
, prsp
->virt
, prsp
->phys
);
329 els_iocb_free_prsp_exit
:
330 lpfc_mbuf_free(phba
, pcmd
->virt
, pcmd
->phys
);
333 els_iocb_free_pcmb_exit
:
335 lpfc_sli_release_iocbq(phba
, elsiocb
);
340 * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport
341 * @vport: pointer to a host virtual N_Port data structure.
343 * This routine issues a fabric registration login for a @vport. An
344 * active ndlp node with Fabric_DID must already exist for this @vport.
345 * The routine invokes two mailbox commands to carry out fabric registration
346 * login through the HBA firmware: the first mailbox command requests the
347 * HBA to perform link configuration for the @vport; and the second mailbox
348 * command requests the HBA to perform the actual fabric registration login
352 * 0 - successfully issued fabric registration login for @vport
353 * -ENXIO -- failed to issue fabric registration login for @vport
356 lpfc_issue_fabric_reglogin(struct lpfc_vport
*vport
)
358 struct lpfc_hba
*phba
= vport
->phba
;
360 struct lpfc_dmabuf
*mp
;
361 struct lpfc_nodelist
*ndlp
;
362 struct serv_parm
*sp
;
366 sp
= &phba
->fc_fabparam
;
367 ndlp
= lpfc_findnode_did(vport
, Fabric_DID
);
368 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
)) {
373 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
379 vport
->port_state
= LPFC_FABRIC_CFG_LINK
;
380 lpfc_config_link(phba
, mbox
);
381 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
384 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
385 if (rc
== MBX_NOT_FINISHED
) {
390 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
395 rc
= lpfc_reg_rpi(phba
, vport
->vpi
, Fabric_DID
, (uint8_t *)sp
, mbox
,
402 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_fabric_reg_login
;
404 /* increment the reference count on ndlp to hold reference
405 * for the callback routine.
407 mbox
->context2
= lpfc_nlp_get(ndlp
);
409 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
410 if (rc
== MBX_NOT_FINISHED
) {
412 goto fail_issue_reg_login
;
417 fail_issue_reg_login
:
418 /* decrement the reference count on ndlp just incremented
419 * for the failed mbox command.
422 mp
= (struct lpfc_dmabuf
*) mbox
->context1
;
423 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
426 mempool_free(mbox
, phba
->mbox_mem_pool
);
429 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
430 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
431 "0249 Cannot issue Register Fabric login: Err %d\n", err
);
436 * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login
437 * @vport: pointer to a host virtual N_Port data structure.
439 * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for
440 * the @vport. This mailbox command is necessary for SLI4 port only.
443 * 0 - successfully issued REG_VFI for @vport
444 * A failure code otherwise.
447 lpfc_issue_reg_vfi(struct lpfc_vport
*vport
)
449 struct lpfc_hba
*phba
= vport
->phba
;
451 struct lpfc_nodelist
*ndlp
;
452 struct serv_parm
*sp
;
453 struct lpfc_dmabuf
*dmabuf
;
456 sp
= &phba
->fc_fabparam
;
457 /* move forward in case of SLI4 FC port loopback test and pt2pt mode */
458 if ((phba
->sli_rev
== LPFC_SLI_REV4
) &&
459 !(phba
->link_flag
& LS_LOOPBACK_MODE
) &&
460 !(vport
->fc_flag
& FC_PT2PT
)) {
461 ndlp
= lpfc_findnode_did(vport
, Fabric_DID
);
462 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
)) {
468 dmabuf
= kzalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
473 dmabuf
->virt
= lpfc_mbuf_alloc(phba
, MEM_PRI
, &dmabuf
->phys
);
476 goto fail_free_dmabuf
;
479 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
482 goto fail_free_coherent
;
484 vport
->port_state
= LPFC_FABRIC_CFG_LINK
;
485 memcpy(dmabuf
->virt
, &phba
->fc_fabparam
, sizeof(vport
->fc_sparam
));
486 lpfc_reg_vfi(mboxq
, vport
, dmabuf
->phys
);
487 mboxq
->mbox_cmpl
= lpfc_mbx_cmpl_reg_vfi
;
488 mboxq
->vport
= vport
;
489 mboxq
->context1
= dmabuf
;
490 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
491 if (rc
== MBX_NOT_FINISHED
) {
498 mempool_free(mboxq
, phba
->mbox_mem_pool
);
500 lpfc_mbuf_free(phba
, dmabuf
->virt
, dmabuf
->phys
);
504 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
505 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
506 "0289 Issue Register VFI failed: Err %d\n", rc
);
511 * lpfc_issue_unreg_vfi - Unregister VFI for this vport's fabric login
512 * @vport: pointer to a host virtual N_Port data structure.
514 * This routine issues a UNREG_VFI mailbox with the vfi, vpi, fcfi triplet for
515 * the @vport. This mailbox command is necessary for SLI4 port only.
518 * 0 - successfully issued REG_VFI for @vport
519 * A failure code otherwise.
522 lpfc_issue_unreg_vfi(struct lpfc_vport
*vport
)
524 struct lpfc_hba
*phba
= vport
->phba
;
525 struct Scsi_Host
*shost
;
529 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
531 lpfc_printf_log(phba
, KERN_ERR
, LOG_DISCOVERY
|LOG_MBOX
,
532 "2556 UNREG_VFI mbox allocation failed"
533 "HBA state x%x\n", phba
->pport
->port_state
);
537 lpfc_unreg_vfi(mboxq
, vport
);
538 mboxq
->vport
= vport
;
539 mboxq
->mbox_cmpl
= lpfc_unregister_vfi_cmpl
;
541 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
542 if (rc
== MBX_NOT_FINISHED
) {
543 lpfc_printf_log(phba
, KERN_ERR
, LOG_DISCOVERY
|LOG_MBOX
,
544 "2557 UNREG_VFI issue mbox failed rc x%x "
546 rc
, phba
->pport
->port_state
);
547 mempool_free(mboxq
, phba
->mbox_mem_pool
);
551 shost
= lpfc_shost_from_vport(vport
);
552 spin_lock_irq(shost
->host_lock
);
553 vport
->fc_flag
&= ~FC_VFI_REGISTERED
;
554 spin_unlock_irq(shost
->host_lock
);
559 * lpfc_check_clean_addr_bit - Check whether assigned FCID is clean.
560 * @vport: pointer to a host virtual N_Port data structure.
561 * @sp: pointer to service parameter data structure.
563 * This routine is called from FLOGI/FDISC completion handler functions.
564 * lpfc_check_clean_addr_bit return 1 when FCID/Fabric portname/ Fabric
565 * node nodename is changed in the completion service parameter else return
566 * 0. This function also set flag in the vport data structure to delay
567 * NP_Port discovery after the FLOGI/FDISC completion if Clean address bit
568 * in FLOGI/FDISC response is cleared and FCID/Fabric portname/ Fabric
569 * node nodename is changed in the completion service parameter.
572 * 0 - FCID and Fabric Nodename and Fabric portname is not changed.
573 * 1 - FCID or Fabric Nodename or Fabric portname is changed.
577 lpfc_check_clean_addr_bit(struct lpfc_vport
*vport
,
578 struct serv_parm
*sp
)
580 uint8_t fabric_param_changed
= 0;
581 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
583 if ((vport
->fc_prevDID
!= vport
->fc_myDID
) ||
584 memcmp(&vport
->fabric_portname
, &sp
->portName
,
585 sizeof(struct lpfc_name
)) ||
586 memcmp(&vport
->fabric_nodename
, &sp
->nodeName
,
587 sizeof(struct lpfc_name
)))
588 fabric_param_changed
= 1;
591 * Word 1 Bit 31 in common service parameter is overloaded.
592 * Word 1 Bit 31 in FLOGI request is multiple NPort request
593 * Word 1 Bit 31 in FLOGI response is clean address bit
595 * If fabric parameter is changed and clean address bit is
596 * cleared delay nport discovery if
597 * - vport->fc_prevDID != 0 (not initial discovery) OR
598 * - lpfc_delay_discovery module parameter is set.
600 if (fabric_param_changed
&& !sp
->cmn
.clean_address_bit
&&
601 (vport
->fc_prevDID
|| lpfc_delay_discovery
)) {
602 spin_lock_irq(shost
->host_lock
);
603 vport
->fc_flag
|= FC_DISC_DELAYED
;
604 spin_unlock_irq(shost
->host_lock
);
607 return fabric_param_changed
;
612 * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port
613 * @vport: pointer to a host virtual N_Port data structure.
614 * @ndlp: pointer to a node-list data structure.
615 * @sp: pointer to service parameter data structure.
616 * @irsp: pointer to the IOCB within the lpfc response IOCB.
618 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
619 * function to handle the completion of a Fabric Login (FLOGI) into a fabric
620 * port in a fabric topology. It properly sets up the parameters to the @ndlp
621 * from the IOCB response. It also check the newly assigned N_Port ID to the
622 * @vport against the previously assigned N_Port ID. If it is different from
623 * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
624 * is invoked on all the remaining nodes with the @vport to unregister the
625 * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
626 * is invoked to register login to the fabric.
629 * 0 - Success (currently, always return 0)
632 lpfc_cmpl_els_flogi_fabric(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
633 struct serv_parm
*sp
, IOCB_t
*irsp
)
635 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
636 struct lpfc_hba
*phba
= vport
->phba
;
637 struct lpfc_nodelist
*np
;
638 struct lpfc_nodelist
*next_np
;
639 uint8_t fabric_param_changed
;
641 spin_lock_irq(shost
->host_lock
);
642 vport
->fc_flag
|= FC_FABRIC
;
643 spin_unlock_irq(shost
->host_lock
);
645 phba
->fc_edtov
= be32_to_cpu(sp
->cmn
.e_d_tov
);
646 if (sp
->cmn
.edtovResolution
) /* E_D_TOV ticks are in nanoseconds */
647 phba
->fc_edtov
= (phba
->fc_edtov
+ 999999) / 1000000;
649 phba
->fc_edtovResol
= sp
->cmn
.edtovResolution
;
650 phba
->fc_ratov
= (be32_to_cpu(sp
->cmn
.w2
.r_a_tov
) + 999) / 1000;
652 if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) {
653 spin_lock_irq(shost
->host_lock
);
654 vport
->fc_flag
|= FC_PUBLIC_LOOP
;
655 spin_unlock_irq(shost
->host_lock
);
658 vport
->fc_myDID
= irsp
->un
.ulpWord
[4] & Mask_DID
;
659 memcpy(&ndlp
->nlp_portname
, &sp
->portName
, sizeof(struct lpfc_name
));
660 memcpy(&ndlp
->nlp_nodename
, &sp
->nodeName
, sizeof(struct lpfc_name
));
661 ndlp
->nlp_class_sup
= 0;
662 if (sp
->cls1
.classValid
)
663 ndlp
->nlp_class_sup
|= FC_COS_CLASS1
;
664 if (sp
->cls2
.classValid
)
665 ndlp
->nlp_class_sup
|= FC_COS_CLASS2
;
666 if (sp
->cls3
.classValid
)
667 ndlp
->nlp_class_sup
|= FC_COS_CLASS3
;
668 if (sp
->cls4
.classValid
)
669 ndlp
->nlp_class_sup
|= FC_COS_CLASS4
;
670 ndlp
->nlp_maxframe
= ((sp
->cmn
.bbRcvSizeMsb
& 0x0F) << 8) |
671 sp
->cmn
.bbRcvSizeLsb
;
673 fabric_param_changed
= lpfc_check_clean_addr_bit(vport
, sp
);
674 memcpy(&vport
->fabric_portname
, &sp
->portName
,
675 sizeof(struct lpfc_name
));
676 memcpy(&vport
->fabric_nodename
, &sp
->nodeName
,
677 sizeof(struct lpfc_name
));
678 memcpy(&phba
->fc_fabparam
, sp
, sizeof(struct serv_parm
));
680 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) {
681 if (sp
->cmn
.response_multiple_NPort
) {
682 lpfc_printf_vlog(vport
, KERN_WARNING
,
684 "1816 FLOGI NPIV supported, "
685 "response data 0x%x\n",
686 sp
->cmn
.response_multiple_NPort
);
687 spin_lock_irq(&phba
->hbalock
);
688 phba
->link_flag
|= LS_NPIV_FAB_SUPPORTED
;
689 spin_unlock_irq(&phba
->hbalock
);
691 /* Because we asked f/w for NPIV it still expects us
692 to call reg_vnpid atleast for the physcial host */
693 lpfc_printf_vlog(vport
, KERN_WARNING
,
695 "1817 Fabric does not support NPIV "
696 "- configuring single port mode.\n");
697 spin_lock_irq(&phba
->hbalock
);
698 phba
->link_flag
&= ~LS_NPIV_FAB_SUPPORTED
;
699 spin_unlock_irq(&phba
->hbalock
);
703 if (fabric_param_changed
&&
704 !(vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
)) {
706 /* If our NportID changed, we need to ensure all
707 * remaining NPORTs get unreg_login'ed.
709 list_for_each_entry_safe(np
, next_np
,
710 &vport
->fc_nodes
, nlp_listp
) {
711 if (!NLP_CHK_NODE_ACT(np
))
713 if ((np
->nlp_state
!= NLP_STE_NPR_NODE
) ||
714 !(np
->nlp_flag
& NLP_NPR_ADISC
))
716 spin_lock_irq(shost
->host_lock
);
717 np
->nlp_flag
&= ~NLP_NPR_ADISC
;
718 spin_unlock_irq(shost
->host_lock
);
719 lpfc_unreg_rpi(vport
, np
);
721 lpfc_cleanup_pending_mbox(vport
);
723 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
724 lpfc_sli4_unreg_all_rpis(vport
);
725 lpfc_mbx_unreg_vpi(vport
);
726 spin_lock_irq(shost
->host_lock
);
727 vport
->fc_flag
|= FC_VPORT_NEEDS_INIT_VPI
;
728 spin_unlock_irq(shost
->host_lock
);
732 * For SLI3 and SLI4, the VPI needs to be reregistered in
733 * response to this fabric parameter change event.
735 spin_lock_irq(shost
->host_lock
);
736 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
737 spin_unlock_irq(shost
->host_lock
);
738 } else if ((phba
->sli_rev
== LPFC_SLI_REV4
) &&
739 !(vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
)) {
741 * Driver needs to re-reg VPI in order for f/w
742 * to update the MAC address.
744 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
745 lpfc_register_new_vport(phba
, vport
, ndlp
);
749 if (phba
->sli_rev
< LPFC_SLI_REV4
) {
750 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_REG_LOGIN_ISSUE
);
751 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
&&
752 vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
)
753 lpfc_register_new_vport(phba
, vport
, ndlp
);
755 lpfc_issue_fabric_reglogin(vport
);
757 ndlp
->nlp_type
|= NLP_FABRIC
;
758 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
759 if ((!(vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
)) &&
760 (vport
->vpi_state
& LPFC_VPI_REGISTERED
)) {
761 lpfc_start_fdiscs(phba
);
762 lpfc_do_scr_ns_plogi(phba
, vport
);
763 } else if (vport
->fc_flag
& FC_VFI_REGISTERED
)
764 lpfc_issue_init_vpi(vport
);
766 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
767 "3135 Need register VFI: (x%x/%x)\n",
768 vport
->fc_prevDID
, vport
->fc_myDID
);
769 lpfc_issue_reg_vfi(vport
);
776 * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
777 * @vport: pointer to a host virtual N_Port data structure.
778 * @ndlp: pointer to a node-list data structure.
779 * @sp: pointer to service parameter data structure.
781 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
782 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
783 * in a point-to-point topology. First, the @vport's N_Port Name is compared
784 * with the received N_Port Name: if the @vport's N_Port Name is greater than
785 * the received N_Port Name lexicographically, this node shall assign local
786 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
787 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
788 * this node shall just wait for the remote node to issue PLOGI and assign
796 lpfc_cmpl_els_flogi_nport(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
797 struct serv_parm
*sp
)
799 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
800 struct lpfc_hba
*phba
= vport
->phba
;
804 spin_lock_irq(shost
->host_lock
);
805 vport
->fc_flag
&= ~(FC_FABRIC
| FC_PUBLIC_LOOP
);
806 spin_unlock_irq(shost
->host_lock
);
808 phba
->fc_edtov
= FF_DEF_EDTOV
;
809 phba
->fc_ratov
= FF_DEF_RATOV
;
810 rc
= memcmp(&vport
->fc_portname
, &sp
->portName
,
811 sizeof(vport
->fc_portname
));
813 /* This side will initiate the PLOGI */
814 spin_lock_irq(shost
->host_lock
);
815 vport
->fc_flag
|= FC_PT2PT_PLOGI
;
816 spin_unlock_irq(shost
->host_lock
);
819 * N_Port ID cannot be 0, set our to LocalID the other
820 * side will be RemoteID.
825 vport
->fc_myDID
= PT2PT_LocalID
;
827 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
831 lpfc_config_link(phba
, mbox
);
833 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
835 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
836 if (rc
== MBX_NOT_FINISHED
) {
837 mempool_free(mbox
, phba
->mbox_mem_pool
);
842 * For SLI4, the VFI/VPI are registered AFTER the
843 * Nport with the higher WWPN sends the PLOGI with
844 * an assigned NPortId.
848 if ((phba
->sli_rev
== LPFC_SLI_REV4
) && rc
)
849 lpfc_issue_reg_vfi(vport
);
851 /* Decrement ndlp reference count indicating that ndlp can be
852 * safely released when other references to it are done.
856 ndlp
= lpfc_findnode_did(vport
, PT2PT_RemoteID
);
859 * Cannot find existing Fabric ndlp, so allocate a
862 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
865 lpfc_nlp_init(vport
, ndlp
, PT2PT_RemoteID
);
866 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
867 ndlp
= lpfc_enable_node(vport
, ndlp
,
868 NLP_STE_UNUSED_NODE
);
873 memcpy(&ndlp
->nlp_portname
, &sp
->portName
,
874 sizeof(struct lpfc_name
));
875 memcpy(&ndlp
->nlp_nodename
, &sp
->nodeName
,
876 sizeof(struct lpfc_name
));
877 /* Set state will put ndlp onto node list if not already done */
878 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
879 spin_lock_irq(shost
->host_lock
);
880 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
881 spin_unlock_irq(shost
->host_lock
);
883 /* This side will wait for the PLOGI, decrement ndlp reference
884 * count indicating that ndlp can be released when other
885 * references to it are done.
889 /* If we are pt2pt with another NPort, force NPIV off! */
890 phba
->sli3_options
&= ~LPFC_SLI3_NPIV_ENABLED
;
892 spin_lock_irq(shost
->host_lock
);
893 vport
->fc_flag
|= FC_PT2PT
;
894 spin_unlock_irq(shost
->host_lock
);
896 /* Start discovery - this should just do CLEAR_LA */
897 lpfc_disc_start(vport
);
904 * lpfc_cmpl_els_flogi - Completion callback function for flogi
905 * @phba: pointer to lpfc hba data structure.
906 * @cmdiocb: pointer to lpfc command iocb data structure.
907 * @rspiocb: pointer to lpfc response iocb data structure.
909 * This routine is the top-level completion callback function for issuing
910 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
911 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
912 * retry has been made (either immediately or delayed with lpfc_els_retry()
913 * returning 1), the command IOCB will be released and function returned.
914 * If the retry attempt has been given up (possibly reach the maximum
915 * number of retries), one additional decrement of ndlp reference shall be
916 * invoked before going out after releasing the command IOCB. This will
917 * actually release the remote node (Note, lpfc_els_free_iocb() will also
918 * invoke one decrement of ndlp reference count). If no error reported in
919 * the IOCB status, the command Port ID field is used to determine whether
920 * this is a point-to-point topology or a fabric topology: if the Port ID
921 * field is assigned, it is a fabric topology; otherwise, it is a
922 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
923 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
924 * specific topology completion conditions.
927 lpfc_cmpl_els_flogi(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
928 struct lpfc_iocbq
*rspiocb
)
930 struct lpfc_vport
*vport
= cmdiocb
->vport
;
931 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
932 IOCB_t
*irsp
= &rspiocb
->iocb
;
933 struct lpfc_nodelist
*ndlp
= cmdiocb
->context1
;
934 struct lpfc_dmabuf
*pcmd
= cmdiocb
->context2
, *prsp
;
935 struct serv_parm
*sp
;
939 /* Check to see if link went down during discovery */
940 if (lpfc_els_chk_latt(vport
)) {
941 /* One additional decrement on node reference count to
942 * trigger the release of the node
948 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
949 "FLOGI cmpl: status:x%x/x%x state:x%x",
950 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
953 if (irsp
->ulpStatus
) {
955 * In case of FIP mode, perform roundrobin FCF failover
956 * due to new FCF discovery
958 if ((phba
->hba_flag
& HBA_FIP_SUPPORT
) &&
959 (phba
->fcf
.fcf_flag
& FCF_DISCOVERY
)) {
960 if (phba
->link_state
< LPFC_LINK_UP
)
961 goto stop_rr_fcf_flogi
;
962 if ((phba
->fcoe_cvl_eventtag_attn
==
963 phba
->fcoe_cvl_eventtag
) &&
964 (irsp
->ulpStatus
== IOSTAT_LOCAL_REJECT
) &&
965 ((irsp
->un
.ulpWord
[4] & IOERR_PARAM_MASK
) ==
967 goto stop_rr_fcf_flogi
;
969 phba
->fcoe_cvl_eventtag_attn
=
970 phba
->fcoe_cvl_eventtag
;
971 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FIP
| LOG_ELS
,
972 "2611 FLOGI failed on FCF (x%x), "
973 "status:x%x/x%x, tmo:x%x, perform "
974 "roundrobin FCF failover\n",
975 phba
->fcf
.current_rec
.fcf_indx
,
976 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
978 lpfc_sli4_set_fcf_flogi_fail(phba
,
979 phba
->fcf
.current_rec
.fcf_indx
);
980 fcf_index
= lpfc_sli4_fcf_rr_next_index_get(phba
);
981 rc
= lpfc_sli4_fcf_rr_next_proc(vport
, fcf_index
);
988 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
989 "2858 FLOGI failure Status:x%x/x%x TMO:x%x\n",
990 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
993 /* Check for retry */
994 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
))
998 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
999 "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n",
1000 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1003 /* FLOGI failed, so there is no fabric */
1004 spin_lock_irq(shost
->host_lock
);
1005 vport
->fc_flag
&= ~(FC_FABRIC
| FC_PUBLIC_LOOP
);
1006 spin_unlock_irq(shost
->host_lock
);
1008 /* If private loop, then allow max outstanding els to be
1009 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
1010 * alpa map would take too long otherwise.
1012 if (phba
->alpa_map
[0] == 0)
1013 vport
->cfg_discovery_threads
= LPFC_MAX_DISC_THREADS
;
1014 if ((phba
->sli_rev
== LPFC_SLI_REV4
) &&
1015 (!(vport
->fc_flag
& FC_VFI_REGISTERED
) ||
1016 (vport
->fc_prevDID
!= vport
->fc_myDID
))) {
1017 if (vport
->fc_flag
& FC_VFI_REGISTERED
)
1018 lpfc_sli4_unreg_all_rpis(vport
);
1019 lpfc_issue_reg_vfi(vport
);
1025 spin_lock_irq(shost
->host_lock
);
1026 vport
->fc_flag
&= ~FC_VPORT_CVL_RCVD
;
1027 vport
->fc_flag
&= ~FC_VPORT_LOGO_RCVD
;
1028 spin_unlock_irq(shost
->host_lock
);
1031 * The FLogI succeeded. Sync the data for the CPU before
1034 prsp
= list_get_first(&pcmd
->list
, struct lpfc_dmabuf
, list
);
1036 sp
= prsp
->virt
+ sizeof(uint32_t);
1038 /* FLOGI completes successfully */
1039 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
1040 "0101 FLOGI completes successfully "
1041 "Data: x%x x%x x%x x%x\n",
1042 irsp
->un
.ulpWord
[4], sp
->cmn
.e_d_tov
,
1043 sp
->cmn
.w2
.r_a_tov
, sp
->cmn
.edtovResolution
);
1045 if (vport
->port_state
== LPFC_FLOGI
) {
1047 * If Common Service Parameters indicate Nport
1048 * we are point to point, if Fport we are Fabric.
1051 rc
= lpfc_cmpl_els_flogi_fabric(vport
, ndlp
, sp
, irsp
);
1052 else if (!(phba
->hba_flag
& HBA_FCOE_MODE
))
1053 rc
= lpfc_cmpl_els_flogi_nport(vport
, ndlp
, sp
);
1055 lpfc_printf_vlog(vport
, KERN_ERR
,
1057 "2831 FLOGI response with cleared Fabric "
1058 "bit fcf_index 0x%x "
1059 "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
1061 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
1062 phba
->fcf
.current_rec
.fcf_indx
,
1063 phba
->fcf
.current_rec
.switch_name
[0],
1064 phba
->fcf
.current_rec
.switch_name
[1],
1065 phba
->fcf
.current_rec
.switch_name
[2],
1066 phba
->fcf
.current_rec
.switch_name
[3],
1067 phba
->fcf
.current_rec
.switch_name
[4],
1068 phba
->fcf
.current_rec
.switch_name
[5],
1069 phba
->fcf
.current_rec
.switch_name
[6],
1070 phba
->fcf
.current_rec
.switch_name
[7],
1071 phba
->fcf
.current_rec
.fabric_name
[0],
1072 phba
->fcf
.current_rec
.fabric_name
[1],
1073 phba
->fcf
.current_rec
.fabric_name
[2],
1074 phba
->fcf
.current_rec
.fabric_name
[3],
1075 phba
->fcf
.current_rec
.fabric_name
[4],
1076 phba
->fcf
.current_rec
.fabric_name
[5],
1077 phba
->fcf
.current_rec
.fabric_name
[6],
1078 phba
->fcf
.current_rec
.fabric_name
[7]);
1080 spin_lock_irq(&phba
->hbalock
);
1081 phba
->fcf
.fcf_flag
&= ~FCF_DISCOVERY
;
1082 phba
->hba_flag
&= ~(FCF_RR_INPROG
| HBA_DEVLOSS_TMO
);
1083 spin_unlock_irq(&phba
->hbalock
);
1087 /* Mark the FCF discovery process done */
1088 if (phba
->hba_flag
& HBA_FIP_SUPPORT
)
1089 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_FIP
|
1091 "2769 FLOGI to FCF (x%x) "
1092 "completed successfully\n",
1093 phba
->fcf
.current_rec
.fcf_indx
);
1094 spin_lock_irq(&phba
->hbalock
);
1095 phba
->fcf
.fcf_flag
&= ~FCF_DISCOVERY
;
1096 phba
->hba_flag
&= ~(FCF_RR_INPROG
| HBA_DEVLOSS_TMO
);
1097 spin_unlock_irq(&phba
->hbalock
);
1105 if (!lpfc_error_lost_link(irsp
)) {
1106 /* FLOGI failed, so just use loop map to make discovery list */
1107 lpfc_disc_list_loopmap(vport
);
1109 /* Start discovery */
1110 lpfc_disc_start(vport
);
1111 } else if (((irsp
->ulpStatus
!= IOSTAT_LOCAL_REJECT
) ||
1112 (((irsp
->un
.ulpWord
[4] & IOERR_PARAM_MASK
) !=
1113 IOERR_SLI_ABORTED
) &&
1114 ((irsp
->un
.ulpWord
[4] & IOERR_PARAM_MASK
) !=
1115 IOERR_SLI_DOWN
))) &&
1116 (phba
->link_state
!= LPFC_CLEAR_LA
)) {
1117 /* If FLOGI failed enable link interrupt. */
1118 lpfc_issue_clear_la(phba
, vport
);
1121 lpfc_els_free_iocb(phba
, cmdiocb
);
1125 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
1126 * @vport: pointer to a host virtual N_Port data structure.
1127 * @ndlp: pointer to a node-list data structure.
1128 * @retry: number of retries to the command IOCB.
1130 * This routine issues a Fabric Login (FLOGI) Request ELS command
1131 * for a @vport. The initiator service parameters are put into the payload
1132 * of the FLOGI Request IOCB and the top-level callback function pointer
1133 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
1134 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
1135 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
1137 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1138 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1139 * will be stored into the context1 field of the IOCB for the completion
1140 * callback function to the FLOGI ELS command.
1143 * 0 - successfully issued flogi iocb for @vport
1144 * 1 - failed to issue flogi iocb for @vport
1147 lpfc_issue_els_flogi(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1150 struct lpfc_hba
*phba
= vport
->phba
;
1151 struct serv_parm
*sp
;
1153 struct lpfc_iocbq
*elsiocb
;
1154 struct lpfc_sli_ring
*pring
;
1160 pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
1162 cmdsize
= (sizeof(uint32_t) + sizeof(struct serv_parm
));
1163 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
1164 ndlp
->nlp_DID
, ELS_CMD_FLOGI
);
1169 icmd
= &elsiocb
->iocb
;
1170 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
1172 /* For FLOGI request, remainder of payload is service parameters */
1173 *((uint32_t *) (pcmd
)) = ELS_CMD_FLOGI
;
1174 pcmd
+= sizeof(uint32_t);
1175 memcpy(pcmd
, &vport
->fc_sparam
, sizeof(struct serv_parm
));
1176 sp
= (struct serv_parm
*) pcmd
;
1178 /* Setup CSPs accordingly for Fabric */
1179 sp
->cmn
.e_d_tov
= 0;
1180 sp
->cmn
.w2
.r_a_tov
= 0;
1181 sp
->cmn
.virtual_fabric_support
= 0;
1182 sp
->cls1
.classValid
= 0;
1183 sp
->cls2
.seqDelivery
= 1;
1184 sp
->cls3
.seqDelivery
= 1;
1185 if (sp
->cmn
.fcphLow
< FC_PH3
)
1186 sp
->cmn
.fcphLow
= FC_PH3
;
1187 if (sp
->cmn
.fcphHigh
< FC_PH3
)
1188 sp
->cmn
.fcphHigh
= FC_PH3
;
1190 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
1191 if (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) ==
1192 LPFC_SLI_INTF_IF_TYPE_0
) {
1193 elsiocb
->iocb
.ulpCt_h
= ((SLI4_CT_FCFI
>> 1) & 1);
1194 elsiocb
->iocb
.ulpCt_l
= (SLI4_CT_FCFI
& 1);
1195 /* FLOGI needs to be 3 for WQE FCFI */
1196 /* Set the fcfi to the fcfi we registered with */
1197 elsiocb
->iocb
.ulpContext
= phba
->fcf
.fcfi
;
1200 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) {
1201 sp
->cmn
.request_multiple_Nport
= 1;
1202 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1206 sp
->cmn
.request_multiple_Nport
= 0;
1209 if (phba
->fc_topology
!= LPFC_TOPOLOGY_LOOP
) {
1210 icmd
->un
.elsreq64
.myID
= 0;
1211 icmd
->un
.elsreq64
.fl
= 1;
1214 tmo
= phba
->fc_ratov
;
1215 phba
->fc_ratov
= LPFC_DISC_FLOGI_TMO
;
1216 lpfc_set_disctmo(vport
);
1217 phba
->fc_ratov
= tmo
;
1219 phba
->fc_stat
.elsXmitFLOGI
++;
1220 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_flogi
;
1222 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1223 "Issue FLOGI: opt:x%x",
1224 phba
->sli3_options
, 0, 0);
1226 rc
= lpfc_issue_fabric_iocb(phba
, elsiocb
);
1227 if (rc
== IOCB_ERROR
) {
1228 lpfc_els_free_iocb(phba
, elsiocb
);
1235 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
1236 * @phba: pointer to lpfc hba data structure.
1238 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1239 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1240 * list and issues an abort IOCB commond on each outstanding IOCB that
1241 * contains a active Fabric_DID ndlp. Note that this function is to issue
1242 * the abort IOCB command on all the outstanding IOCBs, thus when this
1243 * function returns, it does not guarantee all the IOCBs are actually aborted.
1246 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
1249 lpfc_els_abort_flogi(struct lpfc_hba
*phba
)
1251 struct lpfc_sli_ring
*pring
;
1252 struct lpfc_iocbq
*iocb
, *next_iocb
;
1253 struct lpfc_nodelist
*ndlp
;
1256 /* Abort outstanding I/O on NPort <nlp_DID> */
1257 lpfc_printf_log(phba
, KERN_INFO
, LOG_DISCOVERY
,
1258 "0201 Abort outstanding I/O on NPort x%x\n",
1261 pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
1264 * Check the txcmplq for an iocb that matches the nport the driver is
1267 spin_lock_irq(&phba
->hbalock
);
1268 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
, list
) {
1270 if (icmd
->ulpCommand
== CMD_ELS_REQUEST64_CR
) {
1271 ndlp
= (struct lpfc_nodelist
*)(iocb
->context1
);
1272 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
) &&
1273 (ndlp
->nlp_DID
== Fabric_DID
))
1274 lpfc_sli_issue_abort_iotag(phba
, pring
, iocb
);
1277 spin_unlock_irq(&phba
->hbalock
);
1283 * lpfc_initial_flogi - Issue an initial fabric login for a vport
1284 * @vport: pointer to a host virtual N_Port data structure.
1286 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1287 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1288 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1289 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1290 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1291 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1295 * 0 - failed to issue initial flogi for @vport
1296 * 1 - successfully issued initial flogi for @vport
1299 lpfc_initial_flogi(struct lpfc_vport
*vport
)
1301 struct lpfc_hba
*phba
= vport
->phba
;
1302 struct lpfc_nodelist
*ndlp
;
1304 vport
->port_state
= LPFC_FLOGI
;
1305 lpfc_set_disctmo(vport
);
1307 /* First look for the Fabric ndlp */
1308 ndlp
= lpfc_findnode_did(vport
, Fabric_DID
);
1310 /* Cannot find existing Fabric ndlp, so allocate a new one */
1311 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
1314 lpfc_nlp_init(vport
, ndlp
, Fabric_DID
);
1315 /* Set the node type */
1316 ndlp
->nlp_type
|= NLP_FABRIC
;
1317 /* Put ndlp onto node list */
1318 lpfc_enqueue_node(vport
, ndlp
);
1319 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
1320 /* re-setup ndlp without removing from node list */
1321 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
1326 if (lpfc_issue_els_flogi(vport
, ndlp
, 0)) {
1327 /* This decrement of reference count to node shall kick off
1328 * the release of the node.
1337 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
1338 * @vport: pointer to a host virtual N_Port data structure.
1340 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1341 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1342 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1343 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1344 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1345 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1349 * 0 - failed to issue initial fdisc for @vport
1350 * 1 - successfully issued initial fdisc for @vport
1353 lpfc_initial_fdisc(struct lpfc_vport
*vport
)
1355 struct lpfc_hba
*phba
= vport
->phba
;
1356 struct lpfc_nodelist
*ndlp
;
1358 /* First look for the Fabric ndlp */
1359 ndlp
= lpfc_findnode_did(vport
, Fabric_DID
);
1361 /* Cannot find existing Fabric ndlp, so allocate a new one */
1362 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
1365 lpfc_nlp_init(vport
, ndlp
, Fabric_DID
);
1366 /* Put ndlp onto node list */
1367 lpfc_enqueue_node(vport
, ndlp
);
1368 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
1369 /* re-setup ndlp without removing from node list */
1370 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
1375 if (lpfc_issue_els_fdisc(vport
, ndlp
, 0)) {
1376 /* decrement node reference count to trigger the release of
1386 * lpfc_more_plogi - Check and issue remaining plogis for a vport
1387 * @vport: pointer to a host virtual N_Port data structure.
1389 * This routine checks whether there are more remaining Port Logins
1390 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1391 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1392 * to issue ELS PLOGIs up to the configured discover threads with the
1393 * @vport (@vport->cfg_discovery_threads). The function also decrement
1394 * the @vport's num_disc_node by 1 if it is not already 0.
1397 lpfc_more_plogi(struct lpfc_vport
*vport
)
1401 if (vport
->num_disc_nodes
)
1402 vport
->num_disc_nodes
--;
1404 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
1405 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
1406 "0232 Continue discovery with %d PLOGIs to go "
1407 "Data: x%x x%x x%x\n",
1408 vport
->num_disc_nodes
, vport
->fc_plogi_cnt
,
1409 vport
->fc_flag
, vport
->port_state
);
1410 /* Check to see if there are more PLOGIs to be sent */
1411 if (vport
->fc_flag
& FC_NLP_MORE
)
1412 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1413 sentplogi
= lpfc_els_disc_plogi(vport
);
1419 * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
1420 * @phba: pointer to lpfc hba data structure.
1421 * @prsp: pointer to response IOCB payload.
1422 * @ndlp: pointer to a node-list data structure.
1424 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1425 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1426 * The following cases are considered N_Port confirmed:
1427 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1428 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1429 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1430 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1431 * 1) if there is a node on vport list other than the @ndlp with the same
1432 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1433 * on that node to release the RPI associated with the node; 2) if there is
1434 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1435 * into, a new node shall be allocated (or activated). In either case, the
1436 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1437 * be released and the new_ndlp shall be put on to the vport node list and
1438 * its pointer returned as the confirmed node.
1440 * Note that before the @ndlp got "released", the keepDID from not-matching
1441 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1442 * of the @ndlp. This is because the release of @ndlp is actually to put it
1443 * into an inactive state on the vport node list and the vport node list
1444 * management algorithm does not allow two node with a same DID.
1447 * pointer to the PLOGI N_Port @ndlp
1449 static struct lpfc_nodelist
*
1450 lpfc_plogi_confirm_nport(struct lpfc_hba
*phba
, uint32_t *prsp
,
1451 struct lpfc_nodelist
*ndlp
)
1453 struct lpfc_vport
*vport
= ndlp
->vport
;
1454 struct lpfc_nodelist
*new_ndlp
;
1455 struct lpfc_rport_data
*rdata
;
1456 struct fc_rport
*rport
;
1457 struct serv_parm
*sp
;
1458 uint8_t name
[sizeof(struct lpfc_name
)];
1459 uint32_t rc
, keepDID
= 0;
1462 struct lpfc_node_rrqs rrq
;
1464 /* Fabric nodes can have the same WWPN so we don't bother searching
1465 * by WWPN. Just return the ndlp that was given to us.
1467 if (ndlp
->nlp_type
& NLP_FABRIC
)
1470 sp
= (struct serv_parm
*) ((uint8_t *) prsp
+ sizeof(uint32_t));
1471 memset(name
, 0, sizeof(struct lpfc_name
));
1473 /* Now we find out if the NPort we are logging into, matches the WWPN
1474 * we have for that ndlp. If not, we have some work to do.
1476 new_ndlp
= lpfc_findnode_wwpn(vport
, &sp
->portName
);
1478 if (new_ndlp
== ndlp
&& NLP_CHK_NODE_ACT(new_ndlp
))
1480 memset(&rrq
.xri_bitmap
, 0, sizeof(new_ndlp
->active_rrqs
.xri_bitmap
));
1482 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
1483 "3178 PLOGI confirm: ndlp %p x%x: new_ndlp %p\n",
1484 ndlp
, ndlp
->nlp_DID
, new_ndlp
);
1487 rc
= memcmp(&ndlp
->nlp_portname
, name
,
1488 sizeof(struct lpfc_name
));
1491 new_ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_ATOMIC
);
1494 lpfc_nlp_init(vport
, new_ndlp
, ndlp
->nlp_DID
);
1495 } else if (!NLP_CHK_NODE_ACT(new_ndlp
)) {
1496 rc
= memcmp(&ndlp
->nlp_portname
, name
,
1497 sizeof(struct lpfc_name
));
1500 new_ndlp
= lpfc_enable_node(vport
, new_ndlp
,
1501 NLP_STE_UNUSED_NODE
);
1504 keepDID
= new_ndlp
->nlp_DID
;
1505 if (phba
->sli_rev
== LPFC_SLI_REV4
)
1506 memcpy(&rrq
.xri_bitmap
,
1507 &new_ndlp
->active_rrqs
.xri_bitmap
,
1508 sizeof(new_ndlp
->active_rrqs
.xri_bitmap
));
1510 keepDID
= new_ndlp
->nlp_DID
;
1511 if (phba
->sli_rev
== LPFC_SLI_REV4
)
1512 memcpy(&rrq
.xri_bitmap
,
1513 &new_ndlp
->active_rrqs
.xri_bitmap
,
1514 sizeof(new_ndlp
->active_rrqs
.xri_bitmap
));
1517 lpfc_unreg_rpi(vport
, new_ndlp
);
1518 new_ndlp
->nlp_DID
= ndlp
->nlp_DID
;
1519 new_ndlp
->nlp_prev_state
= ndlp
->nlp_prev_state
;
1520 if (phba
->sli_rev
== LPFC_SLI_REV4
)
1521 memcpy(new_ndlp
->active_rrqs
.xri_bitmap
,
1522 &ndlp
->active_rrqs
.xri_bitmap
,
1523 sizeof(ndlp
->active_rrqs
.xri_bitmap
));
1525 if (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
)
1526 new_ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
1527 ndlp
->nlp_flag
&= ~NLP_NPR_2B_DISC
;
1529 /* Set state will put new_ndlp on to node list if not already done */
1530 lpfc_nlp_set_state(vport
, new_ndlp
, ndlp
->nlp_state
);
1532 /* Move this back to NPR state */
1533 if (memcmp(&ndlp
->nlp_portname
, name
, sizeof(struct lpfc_name
)) == 0) {
1534 /* The new_ndlp is replacing ndlp totally, so we need
1535 * to put ndlp on UNUSED list and try to free it.
1537 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
1538 "3179 PLOGI confirm NEW: %x %x\n",
1539 new_ndlp
->nlp_DID
, keepDID
);
1541 /* Fix up the rport accordingly */
1542 rport
= ndlp
->rport
;
1544 rdata
= rport
->dd_data
;
1545 if (rdata
->pnode
== ndlp
) {
1548 rdata
->pnode
= lpfc_nlp_get(new_ndlp
);
1549 new_ndlp
->rport
= rport
;
1551 new_ndlp
->nlp_type
= ndlp
->nlp_type
;
1553 /* We shall actually free the ndlp with both nlp_DID and
1554 * nlp_portname fields equals 0 to avoid any ndlp on the
1555 * nodelist never to be used.
1557 if (ndlp
->nlp_DID
== 0) {
1558 spin_lock_irq(&phba
->ndlp_lock
);
1559 NLP_SET_FREE_REQ(ndlp
);
1560 spin_unlock_irq(&phba
->ndlp_lock
);
1563 /* Two ndlps cannot have the same did on the nodelist */
1564 ndlp
->nlp_DID
= keepDID
;
1565 if (phba
->sli_rev
== LPFC_SLI_REV4
)
1566 memcpy(&ndlp
->active_rrqs
.xri_bitmap
,
1568 sizeof(ndlp
->active_rrqs
.xri_bitmap
));
1569 lpfc_drop_node(vport
, ndlp
);
1572 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
1573 "3180 PLOGI confirm SWAP: %x %x\n",
1574 new_ndlp
->nlp_DID
, keepDID
);
1576 lpfc_unreg_rpi(vport
, ndlp
);
1578 /* Two ndlps cannot have the same did */
1579 ndlp
->nlp_DID
= keepDID
;
1580 if (phba
->sli_rev
== LPFC_SLI_REV4
)
1581 memcpy(&ndlp
->active_rrqs
.xri_bitmap
,
1583 sizeof(ndlp
->active_rrqs
.xri_bitmap
));
1585 /* Since we are swapping the ndlp passed in with the new one
1586 * and the did has already been swapped, copy over state.
1587 * The new WWNs are already in new_ndlp since thats what
1588 * we looked it up by in the begining of this routine.
1590 new_ndlp
->nlp_state
= ndlp
->nlp_state
;
1592 /* Since we are switching over to the new_ndlp, the old
1593 * ndlp should be put in the NPR state, unless we have
1594 * already started re-discovery on it.
1596 if ((ndlp
->nlp_state
== NLP_STE_UNMAPPED_NODE
) ||
1597 (ndlp
->nlp_state
== NLP_STE_MAPPED_NODE
))
1598 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1600 /* Fix up the rport accordingly */
1601 rport
= ndlp
->rport
;
1603 rdata
= rport
->dd_data
;
1604 put_node
= rdata
->pnode
!= NULL
;
1605 put_rport
= ndlp
->rport
!= NULL
;
1606 rdata
->pnode
= NULL
;
1611 put_device(&rport
->dev
);
1618 * lpfc_end_rscn - Check and handle more rscn for a vport
1619 * @vport: pointer to a host virtual N_Port data structure.
1621 * This routine checks whether more Registration State Change
1622 * Notifications (RSCNs) came in while the discovery state machine was in
1623 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1624 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1625 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1626 * handling the RSCNs.
1629 lpfc_end_rscn(struct lpfc_vport
*vport
)
1631 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1633 if (vport
->fc_flag
& FC_RSCN_MODE
) {
1635 * Check to see if more RSCNs came in while we were
1636 * processing this one.
1638 if (vport
->fc_rscn_id_cnt
||
1639 (vport
->fc_flag
& FC_RSCN_DISCOVERY
) != 0)
1640 lpfc_els_handle_rscn(vport
);
1642 spin_lock_irq(shost
->host_lock
);
1643 vport
->fc_flag
&= ~FC_RSCN_MODE
;
1644 spin_unlock_irq(shost
->host_lock
);
1650 * lpfc_cmpl_els_rrq - Completion handled for els RRQs.
1651 * @phba: pointer to lpfc hba data structure.
1652 * @cmdiocb: pointer to lpfc command iocb data structure.
1653 * @rspiocb: pointer to lpfc response iocb data structure.
1655 * This routine will call the clear rrq function to free the rrq and
1656 * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not
1657 * exist then the clear_rrq is still called because the rrq needs to
1662 lpfc_cmpl_els_rrq(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
1663 struct lpfc_iocbq
*rspiocb
)
1665 struct lpfc_vport
*vport
= cmdiocb
->vport
;
1667 struct lpfc_nodelist
*ndlp
;
1668 struct lpfc_node_rrq
*rrq
;
1670 /* we pass cmdiocb to state machine which needs rspiocb as well */
1671 rrq
= cmdiocb
->context_un
.rrq
;
1672 cmdiocb
->context_un
.rsp_iocb
= rspiocb
;
1674 irsp
= &rspiocb
->iocb
;
1675 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1676 "RRQ cmpl: status:x%x/x%x did:x%x",
1677 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1678 irsp
->un
.elsreq64
.remoteID
);
1680 ndlp
= lpfc_findnode_did(vport
, irsp
->un
.elsreq64
.remoteID
);
1681 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
) || ndlp
!= rrq
->ndlp
) {
1682 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1683 "2882 RRQ completes to NPort x%x "
1684 "with no ndlp. Data: x%x x%x x%x\n",
1685 irsp
->un
.elsreq64
.remoteID
,
1686 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1691 /* rrq completes to NPort <nlp_DID> */
1692 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
1693 "2880 RRQ completes to NPort x%x "
1694 "Data: x%x x%x x%x x%x x%x\n",
1695 ndlp
->nlp_DID
, irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1696 irsp
->ulpTimeout
, rrq
->xritag
, rrq
->rxid
);
1698 if (irsp
->ulpStatus
) {
1699 /* Check for retry */
1700 /* RRQ failed Don't print the vport to vport rjts */
1701 if (irsp
->ulpStatus
!= IOSTAT_LS_RJT
||
1702 (((irsp
->un
.ulpWord
[4]) >> 16 != LSRJT_INVALID_CMD
) &&
1703 ((irsp
->un
.ulpWord
[4]) >> 16 != LSRJT_UNABLE_TPC
)) ||
1704 (phba
)->pport
->cfg_log_verbose
& LOG_ELS
)
1705 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1706 "2881 RRQ failure DID:%06X Status:x%x/x%x\n",
1707 ndlp
->nlp_DID
, irsp
->ulpStatus
,
1708 irsp
->un
.ulpWord
[4]);
1712 lpfc_clr_rrq_active(phba
, rrq
->xritag
, rrq
);
1713 lpfc_els_free_iocb(phba
, cmdiocb
);
1717 * lpfc_cmpl_els_plogi - Completion callback function for plogi
1718 * @phba: pointer to lpfc hba data structure.
1719 * @cmdiocb: pointer to lpfc command iocb data structure.
1720 * @rspiocb: pointer to lpfc response iocb data structure.
1722 * This routine is the completion callback function for issuing the Port
1723 * Login (PLOGI) command. For PLOGI completion, there must be an active
1724 * ndlp on the vport node list that matches the remote node ID from the
1725 * PLOGI response IOCB. If such ndlp does not exist, the PLOGI is simply
1726 * ignored and command IOCB released. The PLOGI response IOCB status is
1727 * checked for error conditons. If there is error status reported, PLOGI
1728 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1729 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1730 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1731 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1732 * there are additional N_Port nodes with the vport that need to perform
1733 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1737 lpfc_cmpl_els_plogi(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
1738 struct lpfc_iocbq
*rspiocb
)
1740 struct lpfc_vport
*vport
= cmdiocb
->vport
;
1741 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1743 struct lpfc_nodelist
*ndlp
;
1744 struct lpfc_dmabuf
*prsp
;
1745 int disc
, rc
, did
, type
;
1747 /* we pass cmdiocb to state machine which needs rspiocb as well */
1748 cmdiocb
->context_un
.rsp_iocb
= rspiocb
;
1750 irsp
= &rspiocb
->iocb
;
1751 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1752 "PLOGI cmpl: status:x%x/x%x did:x%x",
1753 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1754 irsp
->un
.elsreq64
.remoteID
);
1756 ndlp
= lpfc_findnode_did(vport
, irsp
->un
.elsreq64
.remoteID
);
1757 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
)) {
1758 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1759 "0136 PLOGI completes to NPort x%x "
1760 "with no ndlp. Data: x%x x%x x%x\n",
1761 irsp
->un
.elsreq64
.remoteID
,
1762 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1767 /* Since ndlp can be freed in the disc state machine, note if this node
1768 * is being used during discovery.
1770 spin_lock_irq(shost
->host_lock
);
1771 disc
= (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
);
1772 ndlp
->nlp_flag
&= ~NLP_NPR_2B_DISC
;
1773 spin_unlock_irq(shost
->host_lock
);
1776 /* PLOGI completes to NPort <nlp_DID> */
1777 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
1778 "0102 PLOGI completes to NPort x%x "
1779 "Data: x%x x%x x%x x%x x%x\n",
1780 ndlp
->nlp_DID
, irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1781 irsp
->ulpTimeout
, disc
, vport
->num_disc_nodes
);
1782 /* Check to see if link went down during discovery */
1783 if (lpfc_els_chk_latt(vport
)) {
1784 spin_lock_irq(shost
->host_lock
);
1785 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
1786 spin_unlock_irq(shost
->host_lock
);
1790 /* ndlp could be freed in DSM, save these values now */
1791 type
= ndlp
->nlp_type
;
1792 did
= ndlp
->nlp_DID
;
1794 if (irsp
->ulpStatus
) {
1795 /* Check for retry */
1796 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
)) {
1797 /* ELS command is being retried */
1799 spin_lock_irq(shost
->host_lock
);
1800 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
1801 spin_unlock_irq(shost
->host_lock
);
1805 /* PLOGI failed Don't print the vport to vport rjts */
1806 if (irsp
->ulpStatus
!= IOSTAT_LS_RJT
||
1807 (((irsp
->un
.ulpWord
[4]) >> 16 != LSRJT_INVALID_CMD
) &&
1808 ((irsp
->un
.ulpWord
[4]) >> 16 != LSRJT_UNABLE_TPC
)) ||
1809 (phba
)->pport
->cfg_log_verbose
& LOG_ELS
)
1810 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1811 "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
1812 ndlp
->nlp_DID
, irsp
->ulpStatus
,
1813 irsp
->un
.ulpWord
[4]);
1814 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1815 if (lpfc_error_lost_link(irsp
))
1816 rc
= NLP_STE_FREED_NODE
;
1818 rc
= lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
1819 NLP_EVT_CMPL_PLOGI
);
1821 /* Good status, call state machine */
1822 prsp
= list_entry(((struct lpfc_dmabuf
*)
1823 cmdiocb
->context2
)->list
.next
,
1824 struct lpfc_dmabuf
, list
);
1825 ndlp
= lpfc_plogi_confirm_nport(phba
, prsp
->virt
, ndlp
);
1826 rc
= lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
1827 NLP_EVT_CMPL_PLOGI
);
1830 if (disc
&& vport
->num_disc_nodes
) {
1831 /* Check to see if there are more PLOGIs to be sent */
1832 lpfc_more_plogi(vport
);
1834 if (vport
->num_disc_nodes
== 0) {
1835 spin_lock_irq(shost
->host_lock
);
1836 vport
->fc_flag
&= ~FC_NDISC_ACTIVE
;
1837 spin_unlock_irq(shost
->host_lock
);
1839 lpfc_can_disctmo(vport
);
1840 lpfc_end_rscn(vport
);
1845 lpfc_els_free_iocb(phba
, cmdiocb
);
1850 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
1851 * @vport: pointer to a host virtual N_Port data structure.
1852 * @did: destination port identifier.
1853 * @retry: number of retries to the command IOCB.
1855 * This routine issues a Port Login (PLOGI) command to a remote N_Port
1856 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
1857 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
1858 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
1859 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
1861 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1862 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1863 * will be stored into the context1 field of the IOCB for the completion
1864 * callback function to the PLOGI ELS command.
1867 * 0 - Successfully issued a plogi for @vport
1868 * 1 - failed to issue a plogi for @vport
1871 lpfc_issue_els_plogi(struct lpfc_vport
*vport
, uint32_t did
, uint8_t retry
)
1873 struct lpfc_hba
*phba
= vport
->phba
;
1874 struct serv_parm
*sp
;
1876 struct lpfc_nodelist
*ndlp
;
1877 struct lpfc_iocbq
*elsiocb
;
1878 struct lpfc_sli
*psli
;
1885 ndlp
= lpfc_findnode_did(vport
, did
);
1886 if (ndlp
&& !NLP_CHK_NODE_ACT(ndlp
))
1889 /* If ndlp is not NULL, we will bump the reference count on it */
1890 cmdsize
= (sizeof(uint32_t) + sizeof(struct serv_parm
));
1891 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
, did
,
1896 icmd
= &elsiocb
->iocb
;
1897 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
1899 /* For PLOGI request, remainder of payload is service parameters */
1900 *((uint32_t *) (pcmd
)) = ELS_CMD_PLOGI
;
1901 pcmd
+= sizeof(uint32_t);
1902 memcpy(pcmd
, &vport
->fc_sparam
, sizeof(struct serv_parm
));
1903 sp
= (struct serv_parm
*) pcmd
;
1906 * If we are a N-port connected to a Fabric, fix-up paramm's so logins
1907 * to device on remote loops work.
1909 if ((vport
->fc_flag
& FC_FABRIC
) && !(vport
->fc_flag
& FC_PUBLIC_LOOP
))
1910 sp
->cmn
.altBbCredit
= 1;
1912 if (sp
->cmn
.fcphLow
< FC_PH_4_3
)
1913 sp
->cmn
.fcphLow
= FC_PH_4_3
;
1915 if (sp
->cmn
.fcphHigh
< FC_PH3
)
1916 sp
->cmn
.fcphHigh
= FC_PH3
;
1918 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1919 "Issue PLOGI: did:x%x",
1922 phba
->fc_stat
.elsXmitPLOGI
++;
1923 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_plogi
;
1924 ret
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
1926 if (ret
== IOCB_ERROR
) {
1927 lpfc_els_free_iocb(phba
, elsiocb
);
1934 * lpfc_cmpl_els_prli - Completion callback function for prli
1935 * @phba: pointer to lpfc hba data structure.
1936 * @cmdiocb: pointer to lpfc command iocb data structure.
1937 * @rspiocb: pointer to lpfc response iocb data structure.
1939 * This routine is the completion callback function for a Process Login
1940 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
1941 * status. If there is error status reported, PRLI retry shall be attempted
1942 * by invoking the lpfc_els_retry() routine. Otherwise, the state
1943 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
1944 * ndlp to mark the PRLI completion.
1947 lpfc_cmpl_els_prli(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
1948 struct lpfc_iocbq
*rspiocb
)
1950 struct lpfc_vport
*vport
= cmdiocb
->vport
;
1951 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1953 struct lpfc_sli
*psli
;
1954 struct lpfc_nodelist
*ndlp
;
1957 /* we pass cmdiocb to state machine which needs rspiocb as well */
1958 cmdiocb
->context_un
.rsp_iocb
= rspiocb
;
1960 irsp
= &(rspiocb
->iocb
);
1961 ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
1962 spin_lock_irq(shost
->host_lock
);
1963 ndlp
->nlp_flag
&= ~NLP_PRLI_SND
;
1964 spin_unlock_irq(shost
->host_lock
);
1966 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1967 "PRLI cmpl: status:x%x/x%x did:x%x",
1968 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1970 /* PRLI completes to NPort <nlp_DID> */
1971 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
1972 "0103 PRLI completes to NPort x%x "
1973 "Data: x%x x%x x%x x%x\n",
1974 ndlp
->nlp_DID
, irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1975 irsp
->ulpTimeout
, vport
->num_disc_nodes
);
1977 vport
->fc_prli_sent
--;
1978 /* Check to see if link went down during discovery */
1979 if (lpfc_els_chk_latt(vport
))
1982 if (irsp
->ulpStatus
) {
1983 /* Check for retry */
1984 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
)) {
1985 /* ELS command is being retried */
1989 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1990 "2754 PRLI failure DID:%06X Status:x%x/x%x\n",
1991 ndlp
->nlp_DID
, irsp
->ulpStatus
,
1992 irsp
->un
.ulpWord
[4]);
1993 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1994 if (lpfc_error_lost_link(irsp
))
1997 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
2000 /* Good status, call state machine */
2001 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
2004 lpfc_els_free_iocb(phba
, cmdiocb
);
2009 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
2010 * @vport: pointer to a host virtual N_Port data structure.
2011 * @ndlp: pointer to a node-list data structure.
2012 * @retry: number of retries to the command IOCB.
2014 * This routine issues a Process Login (PRLI) ELS command for the
2015 * @vport. The PRLI service parameters are set up in the payload of the
2016 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
2017 * is put to the IOCB completion callback func field before invoking the
2018 * routine lpfc_sli_issue_iocb() to send out PRLI command.
2020 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2021 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2022 * will be stored into the context1 field of the IOCB for the completion
2023 * callback function to the PRLI ELS command.
2026 * 0 - successfully issued prli iocb command for @vport
2027 * 1 - failed to issue prli iocb command for @vport
2030 lpfc_issue_els_prli(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2033 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2034 struct lpfc_hba
*phba
= vport
->phba
;
2037 struct lpfc_iocbq
*elsiocb
;
2041 cmdsize
= (sizeof(uint32_t) + sizeof(PRLI
));
2042 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
2043 ndlp
->nlp_DID
, ELS_CMD_PRLI
);
2047 icmd
= &elsiocb
->iocb
;
2048 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
2050 /* For PRLI request, remainder of payload is service parameters */
2051 memset(pcmd
, 0, (sizeof(PRLI
) + sizeof(uint32_t)));
2052 *((uint32_t *) (pcmd
)) = ELS_CMD_PRLI
;
2053 pcmd
+= sizeof(uint32_t);
2055 /* For PRLI, remainder of payload is PRLI parameter page */
2056 npr
= (PRLI
*) pcmd
;
2058 * If our firmware version is 3.20 or later,
2059 * set the following bits for FC-TAPE support.
2061 if (phba
->vpd
.rev
.feaLevelHigh
>= 0x02) {
2062 npr
->ConfmComplAllowed
= 1;
2064 npr
->TaskRetryIdReq
= 1;
2066 npr
->estabImagePair
= 1;
2067 npr
->readXferRdyDis
= 1;
2069 /* For FCP support */
2070 npr
->prliType
= PRLI_FCP_TYPE
;
2071 npr
->initiatorFunc
= 1;
2073 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2074 "Issue PRLI: did:x%x",
2075 ndlp
->nlp_DID
, 0, 0);
2077 phba
->fc_stat
.elsXmitPRLI
++;
2078 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_prli
;
2079 spin_lock_irq(shost
->host_lock
);
2080 ndlp
->nlp_flag
|= NLP_PRLI_SND
;
2081 spin_unlock_irq(shost
->host_lock
);
2082 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) ==
2084 spin_lock_irq(shost
->host_lock
);
2085 ndlp
->nlp_flag
&= ~NLP_PRLI_SND
;
2086 spin_unlock_irq(shost
->host_lock
);
2087 lpfc_els_free_iocb(phba
, elsiocb
);
2090 vport
->fc_prli_sent
++;
2095 * lpfc_rscn_disc - Perform rscn discovery for a vport
2096 * @vport: pointer to a host virtual N_Port data structure.
2098 * This routine performs Registration State Change Notification (RSCN)
2099 * discovery for a @vport. If the @vport's node port recovery count is not
2100 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
2101 * the nodes that need recovery. If none of the PLOGI were needed through
2102 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
2103 * invoked to check and handle possible more RSCN came in during the period
2104 * of processing the current ones.
2107 lpfc_rscn_disc(struct lpfc_vport
*vport
)
2109 lpfc_can_disctmo(vport
);
2111 /* RSCN discovery */
2112 /* go thru NPR nodes and issue ELS PLOGIs */
2113 if (vport
->fc_npr_cnt
)
2114 if (lpfc_els_disc_plogi(vport
))
2117 lpfc_end_rscn(vport
);
2121 * lpfc_adisc_done - Complete the adisc phase of discovery
2122 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
2124 * This function is called when the final ADISC is completed during discovery.
2125 * This function handles clearing link attention or issuing reg_vpi depending
2126 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
2128 * This function is called with no locks held.
2131 lpfc_adisc_done(struct lpfc_vport
*vport
)
2133 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2134 struct lpfc_hba
*phba
= vport
->phba
;
2137 * For NPIV, cmpl_reg_vpi will set port_state to READY,
2138 * and continue discovery.
2140 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
2141 !(vport
->fc_flag
& FC_RSCN_MODE
) &&
2142 (phba
->sli_rev
< LPFC_SLI_REV4
)) {
2143 lpfc_issue_reg_vpi(phba
, vport
);
2147 * For SLI2, we need to set port_state to READY
2148 * and continue discovery.
2150 if (vport
->port_state
< LPFC_VPORT_READY
) {
2151 /* If we get here, there is nothing to ADISC */
2152 if (vport
->port_type
== LPFC_PHYSICAL_PORT
)
2153 lpfc_issue_clear_la(phba
, vport
);
2154 if (!(vport
->fc_flag
& FC_ABORT_DISCOVERY
)) {
2155 vport
->num_disc_nodes
= 0;
2156 /* go thru NPR list, issue ELS PLOGIs */
2157 if (vport
->fc_npr_cnt
)
2158 lpfc_els_disc_plogi(vport
);
2159 if (!vport
->num_disc_nodes
) {
2160 spin_lock_irq(shost
->host_lock
);
2161 vport
->fc_flag
&= ~FC_NDISC_ACTIVE
;
2162 spin_unlock_irq(shost
->host_lock
);
2163 lpfc_can_disctmo(vport
);
2164 lpfc_end_rscn(vport
);
2167 vport
->port_state
= LPFC_VPORT_READY
;
2169 lpfc_rscn_disc(vport
);
2173 * lpfc_more_adisc - Issue more adisc as needed
2174 * @vport: pointer to a host virtual N_Port data structure.
2176 * This routine determines whether there are more ndlps on a @vport
2177 * node list need to have Address Discover (ADISC) issued. If so, it will
2178 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
2179 * remaining nodes which need to have ADISC sent.
2182 lpfc_more_adisc(struct lpfc_vport
*vport
)
2186 if (vport
->num_disc_nodes
)
2187 vport
->num_disc_nodes
--;
2188 /* Continue discovery with <num_disc_nodes> ADISCs to go */
2189 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
2190 "0210 Continue discovery with %d ADISCs to go "
2191 "Data: x%x x%x x%x\n",
2192 vport
->num_disc_nodes
, vport
->fc_adisc_cnt
,
2193 vport
->fc_flag
, vport
->port_state
);
2194 /* Check to see if there are more ADISCs to be sent */
2195 if (vport
->fc_flag
& FC_NLP_MORE
) {
2196 lpfc_set_disctmo(vport
);
2197 /* go thru NPR nodes and issue any remaining ELS ADISCs */
2198 sentadisc
= lpfc_els_disc_adisc(vport
);
2200 if (!vport
->num_disc_nodes
)
2201 lpfc_adisc_done(vport
);
2206 * lpfc_cmpl_els_adisc - Completion callback function for adisc
2207 * @phba: pointer to lpfc hba data structure.
2208 * @cmdiocb: pointer to lpfc command iocb data structure.
2209 * @rspiocb: pointer to lpfc response iocb data structure.
2211 * This routine is the completion function for issuing the Address Discover
2212 * (ADISC) command. It first checks to see whether link went down during
2213 * the discovery process. If so, the node will be marked as node port
2214 * recovery for issuing discover IOCB by the link attention handler and
2215 * exit. Otherwise, the response status is checked. If error was reported
2216 * in the response status, the ADISC command shall be retried by invoking
2217 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
2218 * the response status, the state machine is invoked to set transition
2219 * with respect to NLP_EVT_CMPL_ADISC event.
2222 lpfc_cmpl_els_adisc(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
2223 struct lpfc_iocbq
*rspiocb
)
2225 struct lpfc_vport
*vport
= cmdiocb
->vport
;
2226 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2228 struct lpfc_nodelist
*ndlp
;
2231 /* we pass cmdiocb to state machine which needs rspiocb as well */
2232 cmdiocb
->context_un
.rsp_iocb
= rspiocb
;
2234 irsp
= &(rspiocb
->iocb
);
2235 ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
2237 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2238 "ADISC cmpl: status:x%x/x%x did:x%x",
2239 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
2242 /* Since ndlp can be freed in the disc state machine, note if this node
2243 * is being used during discovery.
2245 spin_lock_irq(shost
->host_lock
);
2246 disc
= (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
);
2247 ndlp
->nlp_flag
&= ~(NLP_ADISC_SND
| NLP_NPR_2B_DISC
);
2248 spin_unlock_irq(shost
->host_lock
);
2249 /* ADISC completes to NPort <nlp_DID> */
2250 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
2251 "0104 ADISC completes to NPort x%x "
2252 "Data: x%x x%x x%x x%x x%x\n",
2253 ndlp
->nlp_DID
, irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
2254 irsp
->ulpTimeout
, disc
, vport
->num_disc_nodes
);
2255 /* Check to see if link went down during discovery */
2256 if (lpfc_els_chk_latt(vport
)) {
2257 spin_lock_irq(shost
->host_lock
);
2258 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
2259 spin_unlock_irq(shost
->host_lock
);
2263 if (irsp
->ulpStatus
) {
2264 /* Check for retry */
2265 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
)) {
2266 /* ELS command is being retried */
2268 spin_lock_irq(shost
->host_lock
);
2269 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
2270 spin_unlock_irq(shost
->host_lock
);
2271 lpfc_set_disctmo(vport
);
2276 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
2277 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
2278 ndlp
->nlp_DID
, irsp
->ulpStatus
,
2279 irsp
->un
.ulpWord
[4]);
2280 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2281 if (!lpfc_error_lost_link(irsp
))
2282 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
2283 NLP_EVT_CMPL_ADISC
);
2285 /* Good status, call state machine */
2286 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
2287 NLP_EVT_CMPL_ADISC
);
2289 /* Check to see if there are more ADISCs to be sent */
2290 if (disc
&& vport
->num_disc_nodes
)
2291 lpfc_more_adisc(vport
);
2293 lpfc_els_free_iocb(phba
, cmdiocb
);
2298 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
2299 * @vport: pointer to a virtual N_Port data structure.
2300 * @ndlp: pointer to a node-list data structure.
2301 * @retry: number of retries to the command IOCB.
2303 * This routine issues an Address Discover (ADISC) for an @ndlp on a
2304 * @vport. It prepares the payload of the ADISC ELS command, updates the
2305 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
2306 * to issue the ADISC ELS command.
2308 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2309 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2310 * will be stored into the context1 field of the IOCB for the completion
2311 * callback function to the ADISC ELS command.
2314 * 0 - successfully issued adisc
2315 * 1 - failed to issue adisc
2318 lpfc_issue_els_adisc(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2321 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2322 struct lpfc_hba
*phba
= vport
->phba
;
2325 struct lpfc_iocbq
*elsiocb
;
2329 cmdsize
= (sizeof(uint32_t) + sizeof(ADISC
));
2330 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
2331 ndlp
->nlp_DID
, ELS_CMD_ADISC
);
2335 icmd
= &elsiocb
->iocb
;
2336 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
2338 /* For ADISC request, remainder of payload is service parameters */
2339 *((uint32_t *) (pcmd
)) = ELS_CMD_ADISC
;
2340 pcmd
+= sizeof(uint32_t);
2342 /* Fill in ADISC payload */
2343 ap
= (ADISC
*) pcmd
;
2344 ap
->hardAL_PA
= phba
->fc_pref_ALPA
;
2345 memcpy(&ap
->portName
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
2346 memcpy(&ap
->nodeName
, &vport
->fc_nodename
, sizeof(struct lpfc_name
));
2347 ap
->DID
= be32_to_cpu(vport
->fc_myDID
);
2349 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2350 "Issue ADISC: did:x%x",
2351 ndlp
->nlp_DID
, 0, 0);
2353 phba
->fc_stat
.elsXmitADISC
++;
2354 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_adisc
;
2355 spin_lock_irq(shost
->host_lock
);
2356 ndlp
->nlp_flag
|= NLP_ADISC_SND
;
2357 spin_unlock_irq(shost
->host_lock
);
2358 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) ==
2360 spin_lock_irq(shost
->host_lock
);
2361 ndlp
->nlp_flag
&= ~NLP_ADISC_SND
;
2362 spin_unlock_irq(shost
->host_lock
);
2363 lpfc_els_free_iocb(phba
, elsiocb
);
2370 * lpfc_cmpl_els_logo - Completion callback function for logo
2371 * @phba: pointer to lpfc hba data structure.
2372 * @cmdiocb: pointer to lpfc command iocb data structure.
2373 * @rspiocb: pointer to lpfc response iocb data structure.
2375 * This routine is the completion function for issuing the ELS Logout (LOGO)
2376 * command. If no error status was reported from the LOGO response, the
2377 * state machine of the associated ndlp shall be invoked for transition with
2378 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
2379 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
2382 lpfc_cmpl_els_logo(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
2383 struct lpfc_iocbq
*rspiocb
)
2385 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
2386 struct lpfc_vport
*vport
= ndlp
->vport
;
2387 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2389 struct lpfc_sli
*psli
;
2390 struct lpfcMboxq
*mbox
;
2391 unsigned long flags
;
2392 uint32_t skip_recovery
= 0;
2395 /* we pass cmdiocb to state machine which needs rspiocb as well */
2396 cmdiocb
->context_un
.rsp_iocb
= rspiocb
;
2398 irsp
= &(rspiocb
->iocb
);
2399 spin_lock_irq(shost
->host_lock
);
2400 ndlp
->nlp_flag
&= ~NLP_LOGO_SND
;
2401 spin_unlock_irq(shost
->host_lock
);
2403 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2404 "LOGO cmpl: status:x%x/x%x did:x%x",
2405 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
2408 /* LOGO completes to NPort <nlp_DID> */
2409 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
2410 "0105 LOGO completes to NPort x%x "
2411 "Data: x%x x%x x%x x%x\n",
2412 ndlp
->nlp_DID
, irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
2413 irsp
->ulpTimeout
, vport
->num_disc_nodes
);
2415 if (lpfc_els_chk_latt(vport
)) {
2420 /* Check to see if link went down during discovery */
2421 if (ndlp
->nlp_flag
& NLP_TARGET_REMOVE
) {
2422 /* NLP_EVT_DEVICE_RM should unregister the RPI
2423 * which should abort all outstanding IOs.
2425 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
2431 if (irsp
->ulpStatus
) {
2432 /* Check for retry */
2433 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
)) {
2434 /* ELS command is being retried */
2439 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
2440 "2756 LOGO failure DID:%06X Status:x%x/x%x\n",
2441 ndlp
->nlp_DID
, irsp
->ulpStatus
,
2442 irsp
->un
.ulpWord
[4]);
2443 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2444 if (lpfc_error_lost_link(irsp
)) {
2450 /* Call state machine. This will unregister the rpi if needed. */
2451 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
, NLP_EVT_CMPL_LOGO
);
2454 lpfc_els_free_iocb(phba
, cmdiocb
);
2455 /* If we are in pt2pt mode, we could rcv new S_ID on PLOGI */
2456 if ((vport
->fc_flag
& FC_PT2PT
) &&
2457 !(vport
->fc_flag
& FC_PT2PT_PLOGI
)) {
2458 phba
->pport
->fc_myDID
= 0;
2459 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
2461 lpfc_config_link(phba
, mbox
);
2462 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
2463 mbox
->vport
= vport
;
2464 if (lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
) ==
2466 mempool_free(mbox
, phba
->mbox_mem_pool
);
2473 * If the node is a target, the handling attempts to recover the port.
2474 * For any other port type, the rpi is unregistered as an implicit
2477 if ((ndlp
->nlp_type
& NLP_FCP_TARGET
) && (skip_recovery
== 0)) {
2478 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
2479 spin_lock_irqsave(shost
->host_lock
, flags
);
2480 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
2481 spin_unlock_irqrestore(shost
->host_lock
, flags
);
2483 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
2484 "3187 LOGO completes to NPort x%x: Start "
2485 "Recovery Data: x%x x%x x%x x%x\n",
2486 ndlp
->nlp_DID
, irsp
->ulpStatus
,
2487 irsp
->un
.ulpWord
[4], irsp
->ulpTimeout
,
2488 vport
->num_disc_nodes
);
2489 lpfc_disc_start(vport
);
2495 * lpfc_issue_els_logo - Issue a logo to an node on a vport
2496 * @vport: pointer to a virtual N_Port data structure.
2497 * @ndlp: pointer to a node-list data structure.
2498 * @retry: number of retries to the command IOCB.
2500 * This routine constructs and issues an ELS Logout (LOGO) iocb command
2501 * to a remote node, referred by an @ndlp on a @vport. It constructs the
2502 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2503 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2505 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2506 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2507 * will be stored into the context1 field of the IOCB for the completion
2508 * callback function to the LOGO ELS command.
2511 * 0 - successfully issued logo
2512 * 1 - failed to issue logo
2515 lpfc_issue_els_logo(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2518 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2519 struct lpfc_hba
*phba
= vport
->phba
;
2521 struct lpfc_iocbq
*elsiocb
;
2526 spin_lock_irq(shost
->host_lock
);
2527 if (ndlp
->nlp_flag
& NLP_LOGO_SND
) {
2528 spin_unlock_irq(shost
->host_lock
);
2531 spin_unlock_irq(shost
->host_lock
);
2533 cmdsize
= (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name
);
2534 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
2535 ndlp
->nlp_DID
, ELS_CMD_LOGO
);
2539 icmd
= &elsiocb
->iocb
;
2540 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
2541 *((uint32_t *) (pcmd
)) = ELS_CMD_LOGO
;
2542 pcmd
+= sizeof(uint32_t);
2544 /* Fill in LOGO payload */
2545 *((uint32_t *) (pcmd
)) = be32_to_cpu(vport
->fc_myDID
);
2546 pcmd
+= sizeof(uint32_t);
2547 memcpy(pcmd
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
2549 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2550 "Issue LOGO: did:x%x",
2551 ndlp
->nlp_DID
, 0, 0);
2554 * If we are issuing a LOGO, we may try to recover the remote NPort
2555 * by issuing a PLOGI later. Even though we issue ELS cmds by the
2556 * VPI, if we have a valid RPI, and that RPI gets unreg'ed while
2557 * that ELS command is in-flight, the HBA returns a IOERR_INVALID_RPI
2558 * for that ELS cmd. To avoid this situation, lets get rid of the
2559 * RPI right now, before any ELS cmds are sent.
2561 spin_lock_irq(shost
->host_lock
);
2562 ndlp
->nlp_flag
|= NLP_ISSUE_LOGO
;
2563 spin_unlock_irq(shost
->host_lock
);
2564 if (lpfc_unreg_rpi(vport
, ndlp
)) {
2565 lpfc_els_free_iocb(phba
, elsiocb
);
2569 phba
->fc_stat
.elsXmitLOGO
++;
2570 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_logo
;
2571 spin_lock_irq(shost
->host_lock
);
2572 ndlp
->nlp_flag
|= NLP_LOGO_SND
;
2573 ndlp
->nlp_flag
&= ~NLP_ISSUE_LOGO
;
2574 spin_unlock_irq(shost
->host_lock
);
2575 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
2577 if (rc
== IOCB_ERROR
) {
2578 spin_lock_irq(shost
->host_lock
);
2579 ndlp
->nlp_flag
&= ~NLP_LOGO_SND
;
2580 spin_unlock_irq(shost
->host_lock
);
2581 lpfc_els_free_iocb(phba
, elsiocb
);
2588 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
2589 * @phba: pointer to lpfc hba data structure.
2590 * @cmdiocb: pointer to lpfc command iocb data structure.
2591 * @rspiocb: pointer to lpfc response iocb data structure.
2593 * This routine is a generic completion callback function for ELS commands.
2594 * Specifically, it is the callback function which does not need to perform
2595 * any command specific operations. It is currently used by the ELS command
2596 * issuing routines for the ELS State Change Request (SCR),
2597 * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
2598 * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
2599 * certain debug loggings, this callback function simply invokes the
2600 * lpfc_els_chk_latt() routine to check whether link went down during the
2601 * discovery process.
2604 lpfc_cmpl_els_cmd(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
2605 struct lpfc_iocbq
*rspiocb
)
2607 struct lpfc_vport
*vport
= cmdiocb
->vport
;
2610 irsp
= &rspiocb
->iocb
;
2612 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2613 "ELS cmd cmpl: status:x%x/x%x did:x%x",
2614 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
2615 irsp
->un
.elsreq64
.remoteID
);
2616 /* ELS cmd tag <ulpIoTag> completes */
2617 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
2618 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
2619 irsp
->ulpIoTag
, irsp
->ulpStatus
,
2620 irsp
->un
.ulpWord
[4], irsp
->ulpTimeout
);
2621 /* Check to see if link went down during discovery */
2622 lpfc_els_chk_latt(vport
);
2623 lpfc_els_free_iocb(phba
, cmdiocb
);
2628 * lpfc_issue_els_scr - Issue a scr to an node on a vport
2629 * @vport: pointer to a host virtual N_Port data structure.
2630 * @nportid: N_Port identifier to the remote node.
2631 * @retry: number of retries to the command IOCB.
2633 * This routine issues a State Change Request (SCR) to a fabric node
2634 * on a @vport. The remote node @nportid is passed into the function. It
2635 * first search the @vport node list to find the matching ndlp. If no such
2636 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
2637 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
2638 * routine is invoked to send the SCR IOCB.
2640 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2641 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2642 * will be stored into the context1 field of the IOCB for the completion
2643 * callback function to the SCR ELS command.
2646 * 0 - Successfully issued scr command
2647 * 1 - Failed to issue scr command
2650 lpfc_issue_els_scr(struct lpfc_vport
*vport
, uint32_t nportid
, uint8_t retry
)
2652 struct lpfc_hba
*phba
= vport
->phba
;
2654 struct lpfc_iocbq
*elsiocb
;
2655 struct lpfc_sli
*psli
;
2658 struct lpfc_nodelist
*ndlp
;
2661 cmdsize
= (sizeof(uint32_t) + sizeof(SCR
));
2663 ndlp
= lpfc_findnode_did(vport
, nportid
);
2665 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
2668 lpfc_nlp_init(vport
, ndlp
, nportid
);
2669 lpfc_enqueue_node(vport
, ndlp
);
2670 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
2671 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
2676 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
2677 ndlp
->nlp_DID
, ELS_CMD_SCR
);
2680 /* This will trigger the release of the node just
2687 icmd
= &elsiocb
->iocb
;
2688 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
2690 *((uint32_t *) (pcmd
)) = ELS_CMD_SCR
;
2691 pcmd
+= sizeof(uint32_t);
2693 /* For SCR, remainder of payload is SCR parameter page */
2694 memset(pcmd
, 0, sizeof(SCR
));
2695 ((SCR
*) pcmd
)->Function
= SCR_FUNC_FULL
;
2697 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2698 "Issue SCR: did:x%x",
2699 ndlp
->nlp_DID
, 0, 0);
2701 phba
->fc_stat
.elsXmitSCR
++;
2702 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_cmd
;
2703 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) ==
2705 /* The additional lpfc_nlp_put will cause the following
2706 * lpfc_els_free_iocb routine to trigger the rlease of
2710 lpfc_els_free_iocb(phba
, elsiocb
);
2713 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2714 * trigger the release of node.
2721 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
2722 * @vport: pointer to a host virtual N_Port data structure.
2723 * @nportid: N_Port identifier to the remote node.
2724 * @retry: number of retries to the command IOCB.
2726 * This routine issues a Fibre Channel Address Resolution Response
2727 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
2728 * is passed into the function. It first search the @vport node list to find
2729 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
2730 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
2731 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
2733 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2734 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2735 * will be stored into the context1 field of the IOCB for the completion
2736 * callback function to the PARPR ELS command.
2739 * 0 - Successfully issued farpr command
2740 * 1 - Failed to issue farpr command
2743 lpfc_issue_els_farpr(struct lpfc_vport
*vport
, uint32_t nportid
, uint8_t retry
)
2745 struct lpfc_hba
*phba
= vport
->phba
;
2747 struct lpfc_iocbq
*elsiocb
;
2748 struct lpfc_sli
*psli
;
2753 struct lpfc_nodelist
*ondlp
;
2754 struct lpfc_nodelist
*ndlp
;
2757 cmdsize
= (sizeof(uint32_t) + sizeof(FARP
));
2759 ndlp
= lpfc_findnode_did(vport
, nportid
);
2761 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
2764 lpfc_nlp_init(vport
, ndlp
, nportid
);
2765 lpfc_enqueue_node(vport
, ndlp
);
2766 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
2767 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
2772 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
2773 ndlp
->nlp_DID
, ELS_CMD_RNID
);
2775 /* This will trigger the release of the node just
2782 icmd
= &elsiocb
->iocb
;
2783 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
2785 *((uint32_t *) (pcmd
)) = ELS_CMD_FARPR
;
2786 pcmd
+= sizeof(uint32_t);
2788 /* Fill in FARPR payload */
2789 fp
= (FARP
*) (pcmd
);
2790 memset(fp
, 0, sizeof(FARP
));
2791 lp
= (uint32_t *) pcmd
;
2792 *lp
++ = be32_to_cpu(nportid
);
2793 *lp
++ = be32_to_cpu(vport
->fc_myDID
);
2795 fp
->Mflags
= (FARP_MATCH_PORT
| FARP_MATCH_NODE
);
2797 memcpy(&fp
->RportName
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
2798 memcpy(&fp
->RnodeName
, &vport
->fc_nodename
, sizeof(struct lpfc_name
));
2799 ondlp
= lpfc_findnode_did(vport
, nportid
);
2800 if (ondlp
&& NLP_CHK_NODE_ACT(ondlp
)) {
2801 memcpy(&fp
->OportName
, &ondlp
->nlp_portname
,
2802 sizeof(struct lpfc_name
));
2803 memcpy(&fp
->OnodeName
, &ondlp
->nlp_nodename
,
2804 sizeof(struct lpfc_name
));
2807 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2808 "Issue FARPR: did:x%x",
2809 ndlp
->nlp_DID
, 0, 0);
2811 phba
->fc_stat
.elsXmitFARPR
++;
2812 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_cmd
;
2813 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) ==
2815 /* The additional lpfc_nlp_put will cause the following
2816 * lpfc_els_free_iocb routine to trigger the release of
2820 lpfc_els_free_iocb(phba
, elsiocb
);
2823 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2824 * trigger the release of the node.
2831 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
2832 * @vport: pointer to a host virtual N_Port data structure.
2833 * @nlp: pointer to a node-list data structure.
2835 * This routine cancels the timer with a delayed IOCB-command retry for
2836 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
2837 * removes the ELS retry event if it presents. In addition, if the
2838 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
2839 * commands are sent for the @vport's nodes that require issuing discovery
2843 lpfc_cancel_retry_delay_tmo(struct lpfc_vport
*vport
, struct lpfc_nodelist
*nlp
)
2845 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2846 struct lpfc_work_evt
*evtp
;
2848 if (!(nlp
->nlp_flag
& NLP_DELAY_TMO
))
2850 spin_lock_irq(shost
->host_lock
);
2851 nlp
->nlp_flag
&= ~NLP_DELAY_TMO
;
2852 spin_unlock_irq(shost
->host_lock
);
2853 del_timer_sync(&nlp
->nlp_delayfunc
);
2854 nlp
->nlp_last_elscmd
= 0;
2855 if (!list_empty(&nlp
->els_retry_evt
.evt_listp
)) {
2856 list_del_init(&nlp
->els_retry_evt
.evt_listp
);
2857 /* Decrement nlp reference count held for the delayed retry */
2858 evtp
= &nlp
->els_retry_evt
;
2859 lpfc_nlp_put((struct lpfc_nodelist
*)evtp
->evt_arg1
);
2861 if (nlp
->nlp_flag
& NLP_NPR_2B_DISC
) {
2862 spin_lock_irq(shost
->host_lock
);
2863 nlp
->nlp_flag
&= ~NLP_NPR_2B_DISC
;
2864 spin_unlock_irq(shost
->host_lock
);
2865 if (vport
->num_disc_nodes
) {
2866 if (vport
->port_state
< LPFC_VPORT_READY
) {
2867 /* Check if there are more ADISCs to be sent */
2868 lpfc_more_adisc(vport
);
2870 /* Check if there are more PLOGIs to be sent */
2871 lpfc_more_plogi(vport
);
2872 if (vport
->num_disc_nodes
== 0) {
2873 spin_lock_irq(shost
->host_lock
);
2874 vport
->fc_flag
&= ~FC_NDISC_ACTIVE
;
2875 spin_unlock_irq(shost
->host_lock
);
2876 lpfc_can_disctmo(vport
);
2877 lpfc_end_rscn(vport
);
2886 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
2887 * @ptr: holder for the pointer to the timer function associated data (ndlp).
2889 * This routine is invoked by the ndlp delayed-function timer to check
2890 * whether there is any pending ELS retry event(s) with the node. If not, it
2891 * simply returns. Otherwise, if there is at least one ELS delayed event, it
2892 * adds the delayed events to the HBA work list and invokes the
2893 * lpfc_worker_wake_up() routine to wake up worker thread to process the
2894 * event. Note that lpfc_nlp_get() is called before posting the event to
2895 * the work list to hold reference count of ndlp so that it guarantees the
2896 * reference to ndlp will still be available when the worker thread gets
2897 * to the event associated with the ndlp.
2900 lpfc_els_retry_delay(unsigned long ptr
)
2902 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) ptr
;
2903 struct lpfc_vport
*vport
= ndlp
->vport
;
2904 struct lpfc_hba
*phba
= vport
->phba
;
2905 unsigned long flags
;
2906 struct lpfc_work_evt
*evtp
= &ndlp
->els_retry_evt
;
2908 spin_lock_irqsave(&phba
->hbalock
, flags
);
2909 if (!list_empty(&evtp
->evt_listp
)) {
2910 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
2914 /* We need to hold the node by incrementing the reference
2915 * count until the queued work is done
2917 evtp
->evt_arg1
= lpfc_nlp_get(ndlp
);
2918 if (evtp
->evt_arg1
) {
2919 evtp
->evt
= LPFC_EVT_ELS_RETRY
;
2920 list_add_tail(&evtp
->evt_listp
, &phba
->work_list
);
2921 lpfc_worker_wake_up(phba
);
2923 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
2928 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
2929 * @ndlp: pointer to a node-list data structure.
2931 * This routine is the worker-thread handler for processing the @ndlp delayed
2932 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
2933 * the last ELS command from the associated ndlp and invokes the proper ELS
2934 * function according to the delayed ELS command to retry the command.
2937 lpfc_els_retry_delay_handler(struct lpfc_nodelist
*ndlp
)
2939 struct lpfc_vport
*vport
= ndlp
->vport
;
2940 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2941 uint32_t cmd
, did
, retry
;
2943 spin_lock_irq(shost
->host_lock
);
2944 did
= ndlp
->nlp_DID
;
2945 cmd
= ndlp
->nlp_last_elscmd
;
2946 ndlp
->nlp_last_elscmd
= 0;
2948 if (!(ndlp
->nlp_flag
& NLP_DELAY_TMO
)) {
2949 spin_unlock_irq(shost
->host_lock
);
2953 ndlp
->nlp_flag
&= ~NLP_DELAY_TMO
;
2954 spin_unlock_irq(shost
->host_lock
);
2956 * If a discovery event readded nlp_delayfunc after timer
2957 * firing and before processing the timer, cancel the
2960 del_timer_sync(&ndlp
->nlp_delayfunc
);
2961 retry
= ndlp
->nlp_retry
;
2962 ndlp
->nlp_retry
= 0;
2966 lpfc_issue_els_flogi(vport
, ndlp
, retry
);
2969 if (!lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, retry
)) {
2970 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
2971 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
2975 if (!lpfc_issue_els_adisc(vport
, ndlp
, retry
)) {
2976 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
2977 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_ADISC_ISSUE
);
2981 if (!lpfc_issue_els_prli(vport
, ndlp
, retry
)) {
2982 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
2983 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PRLI_ISSUE
);
2987 if (!lpfc_issue_els_logo(vport
, ndlp
, retry
)) {
2988 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
2989 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_LOGO_ISSUE
);
2993 if (!(vport
->fc_flag
& FC_VPORT_NEEDS_INIT_VPI
))
2994 lpfc_issue_els_fdisc(vport
, ndlp
, retry
);
3001 * lpfc_els_retry - Make retry decision on an els command iocb
3002 * @phba: pointer to lpfc hba data structure.
3003 * @cmdiocb: pointer to lpfc command iocb data structure.
3004 * @rspiocb: pointer to lpfc response iocb data structure.
3006 * This routine makes a retry decision on an ELS command IOCB, which has
3007 * failed. The following ELS IOCBs use this function for retrying the command
3008 * when previously issued command responsed with error status: FLOGI, PLOGI,
3009 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
3010 * returned error status, it makes the decision whether a retry shall be
3011 * issued for the command, and whether a retry shall be made immediately or
3012 * delayed. In the former case, the corresponding ELS command issuing-function
3013 * is called to retry the command. In the later case, the ELS command shall
3014 * be posted to the ndlp delayed event and delayed function timer set to the
3015 * ndlp for the delayed command issusing.
3018 * 0 - No retry of els command is made
3019 * 1 - Immediate or delayed retry of els command is made
3022 lpfc_els_retry(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
3023 struct lpfc_iocbq
*rspiocb
)
3025 struct lpfc_vport
*vport
= cmdiocb
->vport
;
3026 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3027 IOCB_t
*irsp
= &rspiocb
->iocb
;
3028 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
3029 struct lpfc_dmabuf
*pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
3032 int retry
= 0, maxretry
= lpfc_max_els_tries
, delay
= 0;
3038 /* Note: context2 may be 0 for internal driver abort
3039 * of delays ELS command.
3042 if (pcmd
&& pcmd
->virt
) {
3043 elscmd
= (uint32_t *) (pcmd
->virt
);
3047 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
))
3048 did
= ndlp
->nlp_DID
;
3050 /* We should only hit this case for retrying PLOGI */
3051 did
= irsp
->un
.elsreq64
.remoteID
;
3052 ndlp
= lpfc_findnode_did(vport
, did
);
3053 if ((!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
))
3054 && (cmd
!= ELS_CMD_PLOGI
))
3058 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
3059 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
3060 *(((uint32_t *) irsp
) + 7), irsp
->un
.ulpWord
[4], ndlp
->nlp_DID
);
3062 switch (irsp
->ulpStatus
) {
3063 case IOSTAT_FCP_RSP_ERROR
:
3065 case IOSTAT_REMOTE_STOP
:
3066 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
3067 /* This IO was aborted by the target, we don't
3068 * know the rxid and because we did not send the
3069 * ABTS we cannot generate and RRQ.
3071 lpfc_set_rrq_active(phba
, ndlp
,
3072 cmdiocb
->sli4_lxritag
, 0, 0);
3075 case IOSTAT_LOCAL_REJECT
:
3076 switch ((irsp
->un
.ulpWord
[4] & IOERR_PARAM_MASK
)) {
3077 case IOERR_LOOP_OPEN_FAILURE
:
3078 if (cmd
== ELS_CMD_FLOGI
) {
3079 if (PCI_DEVICE_ID_HORNET
==
3080 phba
->pcidev
->device
) {
3081 phba
->fc_topology
= LPFC_TOPOLOGY_LOOP
;
3082 phba
->pport
->fc_myDID
= 0;
3083 phba
->alpa_map
[0] = 0;
3084 phba
->alpa_map
[1] = 0;
3087 if (cmd
== ELS_CMD_PLOGI
&& cmdiocb
->retry
== 0)
3092 case IOERR_ILLEGAL_COMMAND
:
3093 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
3094 "0124 Retry illegal cmd x%x "
3095 "retry:x%x delay:x%x\n",
3096 cmd
, cmdiocb
->retry
, delay
);
3098 /* All command's retry policy */
3100 if (cmdiocb
->retry
> 2)
3104 case IOERR_NO_RESOURCES
:
3105 logerr
= 1; /* HBA out of resources */
3107 if (cmdiocb
->retry
> 100)
3112 case IOERR_ILLEGAL_FRAME
:
3117 case IOERR_SEQUENCE_TIMEOUT
:
3118 case IOERR_INVALID_RPI
:
3124 case IOSTAT_NPORT_RJT
:
3125 case IOSTAT_FABRIC_RJT
:
3126 if (irsp
->un
.ulpWord
[4] & RJT_UNAVAIL_TEMP
) {
3132 case IOSTAT_NPORT_BSY
:
3133 case IOSTAT_FABRIC_BSY
:
3134 logerr
= 1; /* Fabric / Remote NPort out of resources */
3139 stat
.un
.lsRjtError
= be32_to_cpu(irsp
->un
.ulpWord
[4]);
3140 /* Added for Vendor specifc support
3141 * Just keep retrying for these Rsn / Exp codes
3143 switch (stat
.un
.b
.lsRjtRsnCode
) {
3144 case LSRJT_UNABLE_TPC
:
3145 if (stat
.un
.b
.lsRjtRsnCodeExp
==
3146 LSEXP_CMD_IN_PROGRESS
) {
3147 if (cmd
== ELS_CMD_PLOGI
) {
3154 if (stat
.un
.b
.lsRjtRsnCodeExp
==
3155 LSEXP_CANT_GIVE_DATA
) {
3156 if (cmd
== ELS_CMD_PLOGI
) {
3163 if (cmd
== ELS_CMD_PLOGI
) {
3165 maxretry
= lpfc_max_els_tries
+ 1;
3169 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
3170 (cmd
== ELS_CMD_FDISC
) &&
3171 (stat
.un
.b
.lsRjtRsnCodeExp
== LSEXP_OUT_OF_RESOURCE
)){
3172 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
3173 "0125 FDISC Failed (x%x). "
3174 "Fabric out of resources\n",
3175 stat
.un
.lsRjtError
);
3176 lpfc_vport_set_state(vport
,
3177 FC_VPORT_NO_FABRIC_RSCS
);
3181 case LSRJT_LOGICAL_BSY
:
3182 if ((cmd
== ELS_CMD_PLOGI
) ||
3183 (cmd
== ELS_CMD_PRLI
)) {
3186 } else if (cmd
== ELS_CMD_FDISC
) {
3187 /* FDISC retry policy */
3189 if (cmdiocb
->retry
>= 32)
3195 case LSRJT_LOGICAL_ERR
:
3196 /* There are some cases where switches return this
3197 * error when they are not ready and should be returning
3198 * Logical Busy. We should delay every time.
3200 if (cmd
== ELS_CMD_FDISC
&&
3201 stat
.un
.b
.lsRjtRsnCodeExp
== LSEXP_PORT_LOGIN_REQ
) {
3207 case LSRJT_PROTOCOL_ERR
:
3208 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
3209 (cmd
== ELS_CMD_FDISC
) &&
3210 ((stat
.un
.b
.lsRjtRsnCodeExp
== LSEXP_INVALID_PNAME
) ||
3211 (stat
.un
.b
.lsRjtRsnCodeExp
== LSEXP_INVALID_NPORT_ID
))
3213 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
3214 "0122 FDISC Failed (x%x). "
3215 "Fabric Detected Bad WWN\n",
3216 stat
.un
.lsRjtError
);
3217 lpfc_vport_set_state(vport
,
3218 FC_VPORT_FABRIC_REJ_WWN
);
3224 case IOSTAT_INTERMED_RSP
:
3232 if (did
== FDMI_DID
)
3235 if ((cmd
== ELS_CMD_FLOGI
) &&
3236 (phba
->fc_topology
!= LPFC_TOPOLOGY_LOOP
) &&
3237 !lpfc_error_lost_link(irsp
)) {
3238 /* FLOGI retry policy */
3240 /* retry FLOGI forever */
3242 if (cmdiocb
->retry
>= 100)
3244 else if (cmdiocb
->retry
>= 32)
3246 } else if ((cmd
== ELS_CMD_FDISC
) && !lpfc_error_lost_link(irsp
)) {
3247 /* retry FDISCs every second up to devloss */
3249 maxretry
= vport
->cfg_devloss_tmo
;
3254 if (maxretry
&& (cmdiocb
->retry
>= maxretry
)) {
3255 phba
->fc_stat
.elsRetryExceeded
++;
3259 if ((vport
->load_flag
& FC_UNLOADING
) != 0)
3263 if ((cmd
== ELS_CMD_PLOGI
) || (cmd
== ELS_CMD_FDISC
)) {
3264 /* Stop retrying PLOGI and FDISC if in FCF discovery */
3265 if (phba
->fcf
.fcf_flag
& FCF_DISCOVERY
) {
3266 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3267 "2849 Stop retry ELS command "
3268 "x%x to remote NPORT x%x, "
3269 "Data: x%x x%x\n", cmd
, did
,
3270 cmdiocb
->retry
, delay
);
3275 /* Retry ELS command <elsCmd> to remote NPORT <did> */
3276 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3277 "0107 Retry ELS command x%x to remote "
3278 "NPORT x%x Data: x%x x%x\n",
3279 cmd
, did
, cmdiocb
->retry
, delay
);
3281 if (((cmd
== ELS_CMD_PLOGI
) || (cmd
== ELS_CMD_ADISC
)) &&
3282 ((irsp
->ulpStatus
!= IOSTAT_LOCAL_REJECT
) ||
3283 ((irsp
->un
.ulpWord
[4] & IOERR_PARAM_MASK
) !=
3284 IOERR_NO_RESOURCES
))) {
3285 /* Don't reset timer for no resources */
3287 /* If discovery / RSCN timer is running, reset it */
3288 if (timer_pending(&vport
->fc_disctmo
) ||
3289 (vport
->fc_flag
& FC_RSCN_MODE
))
3290 lpfc_set_disctmo(vport
);
3293 phba
->fc_stat
.elsXmitRetry
++;
3294 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
) && delay
) {
3295 phba
->fc_stat
.elsDelayRetry
++;
3296 ndlp
->nlp_retry
= cmdiocb
->retry
;
3298 /* delay is specified in milliseconds */
3299 mod_timer(&ndlp
->nlp_delayfunc
,
3300 jiffies
+ msecs_to_jiffies(delay
));
3301 spin_lock_irq(shost
->host_lock
);
3302 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
3303 spin_unlock_irq(shost
->host_lock
);
3305 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
3306 if (cmd
== ELS_CMD_PRLI
)
3307 lpfc_nlp_set_state(vport
, ndlp
,
3308 NLP_STE_REG_LOGIN_ISSUE
);
3310 lpfc_nlp_set_state(vport
, ndlp
,
3312 ndlp
->nlp_last_elscmd
= cmd
;
3318 lpfc_issue_els_flogi(vport
, ndlp
, cmdiocb
->retry
);
3321 lpfc_issue_els_fdisc(vport
, ndlp
, cmdiocb
->retry
);
3324 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
)) {
3325 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
3326 lpfc_nlp_set_state(vport
, ndlp
,
3327 NLP_STE_PLOGI_ISSUE
);
3329 lpfc_issue_els_plogi(vport
, did
, cmdiocb
->retry
);
3332 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
3333 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_ADISC_ISSUE
);
3334 lpfc_issue_els_adisc(vport
, ndlp
, cmdiocb
->retry
);
3337 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
3338 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PRLI_ISSUE
);
3339 lpfc_issue_els_prli(vport
, ndlp
, cmdiocb
->retry
);
3342 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
3343 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_LOGO_ISSUE
);
3344 lpfc_issue_els_logo(vport
, ndlp
, cmdiocb
->retry
);
3348 /* No retry ELS command <elsCmd> to remote NPORT <did> */
3350 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
3351 "0137 No retry ELS command x%x to remote "
3352 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
3353 cmd
, did
, irsp
->ulpStatus
,
3354 irsp
->un
.ulpWord
[4]);
3357 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3358 "0108 No retry ELS command x%x to remote "
3359 "NPORT x%x Retried:%d Error:x%x/%x\n",
3360 cmd
, did
, cmdiocb
->retry
, irsp
->ulpStatus
,
3361 irsp
->un
.ulpWord
[4]);
3367 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
3368 * @phba: pointer to lpfc hba data structure.
3369 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
3371 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
3372 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
3373 * checks to see whether there is a lpfc DMA buffer associated with the
3374 * response of the command IOCB. If so, it will be released before releasing
3375 * the lpfc DMA buffer associated with the IOCB itself.
3378 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3381 lpfc_els_free_data(struct lpfc_hba
*phba
, struct lpfc_dmabuf
*buf_ptr1
)
3383 struct lpfc_dmabuf
*buf_ptr
;
3385 /* Free the response before processing the command. */
3386 if (!list_empty(&buf_ptr1
->list
)) {
3387 list_remove_head(&buf_ptr1
->list
, buf_ptr
,
3390 lpfc_mbuf_free(phba
, buf_ptr
->virt
, buf_ptr
->phys
);
3393 lpfc_mbuf_free(phba
, buf_ptr1
->virt
, buf_ptr1
->phys
);
3399 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
3400 * @phba: pointer to lpfc hba data structure.
3401 * @buf_ptr: pointer to the lpfc dma buffer data structure.
3403 * This routine releases the lpfc Direct Memory Access (DMA) buffer
3404 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
3408 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3411 lpfc_els_free_bpl(struct lpfc_hba
*phba
, struct lpfc_dmabuf
*buf_ptr
)
3413 lpfc_mbuf_free(phba
, buf_ptr
->virt
, buf_ptr
->phys
);
3419 * lpfc_els_free_iocb - Free a command iocb and its associated resources
3420 * @phba: pointer to lpfc hba data structure.
3421 * @elsiocb: pointer to lpfc els command iocb data structure.
3423 * This routine frees a command IOCB and its associated resources. The
3424 * command IOCB data structure contains the reference to various associated
3425 * resources, these fields must be set to NULL if the associated reference
3427 * context1 - reference to ndlp
3428 * context2 - reference to cmd
3429 * context2->next - reference to rsp
3430 * context3 - reference to bpl
3432 * It first properly decrements the reference count held on ndlp for the
3433 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
3434 * set, it invokes the lpfc_els_free_data() routine to release the Direct
3435 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
3436 * adds the DMA buffer the @phba data structure for the delayed release.
3437 * If reference to the Buffer Pointer List (BPL) is present, the
3438 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
3439 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
3440 * invoked to release the IOCB data structure back to @phba IOCBQ list.
3443 * 0 - Success (currently, always return 0)
3446 lpfc_els_free_iocb(struct lpfc_hba
*phba
, struct lpfc_iocbq
*elsiocb
)
3448 struct lpfc_dmabuf
*buf_ptr
, *buf_ptr1
;
3449 struct lpfc_nodelist
*ndlp
;
3451 ndlp
= (struct lpfc_nodelist
*)elsiocb
->context1
;
3453 if (ndlp
->nlp_flag
& NLP_DEFER_RM
) {
3456 /* If the ndlp is not being used by another discovery
3459 if (!lpfc_nlp_not_used(ndlp
)) {
3460 /* If ndlp is being used by another discovery
3461 * thread, just clear NLP_DEFER_RM
3463 ndlp
->nlp_flag
&= ~NLP_DEFER_RM
;
3468 elsiocb
->context1
= NULL
;
3470 /* context2 = cmd, context2->next = rsp, context3 = bpl */
3471 if (elsiocb
->context2
) {
3472 if (elsiocb
->iocb_flag
& LPFC_DELAY_MEM_FREE
) {
3473 /* Firmware could still be in progress of DMAing
3474 * payload, so don't free data buffer till after
3477 elsiocb
->iocb_flag
&= ~LPFC_DELAY_MEM_FREE
;
3478 buf_ptr
= elsiocb
->context2
;
3479 elsiocb
->context2
= NULL
;
3482 spin_lock_irq(&phba
->hbalock
);
3483 if (!list_empty(&buf_ptr
->list
)) {
3484 list_remove_head(&buf_ptr
->list
,
3485 buf_ptr1
, struct lpfc_dmabuf
,
3487 INIT_LIST_HEAD(&buf_ptr1
->list
);
3488 list_add_tail(&buf_ptr1
->list
,
3492 INIT_LIST_HEAD(&buf_ptr
->list
);
3493 list_add_tail(&buf_ptr
->list
, &phba
->elsbuf
);
3495 spin_unlock_irq(&phba
->hbalock
);
3498 buf_ptr1
= (struct lpfc_dmabuf
*) elsiocb
->context2
;
3499 lpfc_els_free_data(phba
, buf_ptr1
);
3503 if (elsiocb
->context3
) {
3504 buf_ptr
= (struct lpfc_dmabuf
*) elsiocb
->context3
;
3505 lpfc_els_free_bpl(phba
, buf_ptr
);
3507 lpfc_sli_release_iocbq(phba
, elsiocb
);
3512 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
3513 * @phba: pointer to lpfc hba data structure.
3514 * @cmdiocb: pointer to lpfc command iocb data structure.
3515 * @rspiocb: pointer to lpfc response iocb data structure.
3517 * This routine is the completion callback function to the Logout (LOGO)
3518 * Accept (ACC) Response ELS command. This routine is invoked to indicate
3519 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
3520 * release the ndlp if it has the last reference remaining (reference count
3521 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
3522 * field to NULL to inform the following lpfc_els_free_iocb() routine no
3523 * ndlp reference count needs to be decremented. Otherwise, the ndlp
3524 * reference use-count shall be decremented by the lpfc_els_free_iocb()
3525 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
3526 * IOCB data structure.
3529 lpfc_cmpl_els_logo_acc(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
3530 struct lpfc_iocbq
*rspiocb
)
3532 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
3533 struct lpfc_vport
*vport
= cmdiocb
->vport
;
3536 irsp
= &rspiocb
->iocb
;
3537 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
3538 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
3539 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4], ndlp
->nlp_DID
);
3540 /* ACC to LOGO completes to NPort <nlp_DID> */
3541 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3542 "0109 ACC to LOGO completes to NPort x%x "
3543 "Data: x%x x%x x%x\n",
3544 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
3547 if (ndlp
->nlp_state
== NLP_STE_NPR_NODE
) {
3548 /* NPort Recovery mode or node is just allocated */
3549 if (!lpfc_nlp_not_used(ndlp
)) {
3550 /* If the ndlp is being used by another discovery
3551 * thread, just unregister the RPI.
3553 lpfc_unreg_rpi(vport
, ndlp
);
3555 /* Indicate the node has already released, should
3556 * not reference to it from within lpfc_els_free_iocb.
3558 cmdiocb
->context1
= NULL
;
3563 * The driver received a LOGO from the rport and has ACK'd it.
3564 * At this point, the driver is done so release the IOCB
3566 lpfc_els_free_iocb(phba
, cmdiocb
);
3569 * Remove the ndlp reference if it's a fabric node that has
3570 * sent us an unsolicted LOGO.
3572 if (ndlp
->nlp_type
& NLP_FABRIC
)
3579 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
3580 * @phba: pointer to lpfc hba data structure.
3581 * @pmb: pointer to the driver internal queue element for mailbox command.
3583 * This routine is the completion callback function for unregister default
3584 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
3585 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
3586 * decrements the ndlp reference count held for this completion callback
3587 * function. After that, it invokes the lpfc_nlp_not_used() to check
3588 * whether there is only one reference left on the ndlp. If so, it will
3589 * perform one more decrement and trigger the release of the ndlp.
3592 lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
3594 struct lpfc_dmabuf
*mp
= (struct lpfc_dmabuf
*) (pmb
->context1
);
3595 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
3597 pmb
->context1
= NULL
;
3598 pmb
->context2
= NULL
;
3600 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
3602 mempool_free(pmb
, phba
->mbox_mem_pool
);
3604 if (NLP_CHK_NODE_ACT(ndlp
)) {
3606 /* This is the end of the default RPI cleanup logic for
3607 * this ndlp. If no other discovery threads are using
3608 * this ndlp, free all resources associated with it.
3610 lpfc_nlp_not_used(ndlp
);
3612 lpfc_drop_node(ndlp
->vport
, ndlp
);
3620 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
3621 * @phba: pointer to lpfc hba data structure.
3622 * @cmdiocb: pointer to lpfc command iocb data structure.
3623 * @rspiocb: pointer to lpfc response iocb data structure.
3625 * This routine is the completion callback function for ELS Response IOCB
3626 * command. In normal case, this callback function just properly sets the
3627 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
3628 * field in the command IOCB is not NULL, the referred mailbox command will
3629 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
3630 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
3631 * link down event occurred during the discovery, the lpfc_nlp_not_used()
3632 * routine shall be invoked trying to release the ndlp if no other threads
3633 * are currently referring it.
3636 lpfc_cmpl_els_rsp(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
3637 struct lpfc_iocbq
*rspiocb
)
3639 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
3640 struct lpfc_vport
*vport
= ndlp
? ndlp
->vport
: NULL
;
3641 struct Scsi_Host
*shost
= vport
? lpfc_shost_from_vport(vport
) : NULL
;
3644 LPFC_MBOXQ_t
*mbox
= NULL
;
3645 struct lpfc_dmabuf
*mp
= NULL
;
3646 uint32_t ls_rjt
= 0;
3648 irsp
= &rspiocb
->iocb
;
3650 if (cmdiocb
->context_un
.mbox
)
3651 mbox
= cmdiocb
->context_un
.mbox
;
3653 /* First determine if this is a LS_RJT cmpl. Note, this callback
3654 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
3656 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) cmdiocb
->context2
)->virt
);
3657 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
) &&
3658 (*((uint32_t *) (pcmd
)) == ELS_CMD_LS_RJT
)) {
3659 /* A LS_RJT associated with Default RPI cleanup has its own
3660 * separate code path.
3662 if (!(ndlp
->nlp_flag
& NLP_RM_DFLT_RPI
))
3666 /* Check to see if link went down during discovery */
3667 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
) || lpfc_els_chk_latt(vport
)) {
3669 mp
= (struct lpfc_dmabuf
*) mbox
->context1
;
3671 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
3674 mempool_free(mbox
, phba
->mbox_mem_pool
);
3676 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
) &&
3677 (ndlp
->nlp_flag
& NLP_RM_DFLT_RPI
))
3678 if (lpfc_nlp_not_used(ndlp
)) {
3680 /* Indicate the node has already released,
3681 * should not reference to it from within
3682 * the routine lpfc_els_free_iocb.
3684 cmdiocb
->context1
= NULL
;
3689 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
3690 "ELS rsp cmpl: status:x%x/x%x did:x%x",
3691 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
3692 cmdiocb
->iocb
.un
.elsreq64
.remoteID
);
3693 /* ELS response tag <ulpIoTag> completes */
3694 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3695 "0110 ELS response tag x%x completes "
3696 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
3697 cmdiocb
->iocb
.ulpIoTag
, rspiocb
->iocb
.ulpStatus
,
3698 rspiocb
->iocb
.un
.ulpWord
[4], rspiocb
->iocb
.ulpTimeout
,
3699 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
3702 if ((rspiocb
->iocb
.ulpStatus
== 0)
3703 && (ndlp
->nlp_flag
& NLP_ACC_REGLOGIN
)) {
3704 lpfc_unreg_rpi(vport
, ndlp
);
3705 /* Increment reference count to ndlp to hold the
3706 * reference to ndlp for the callback function.
3708 mbox
->context2
= lpfc_nlp_get(ndlp
);
3709 mbox
->vport
= vport
;
3710 if (ndlp
->nlp_flag
& NLP_RM_DFLT_RPI
) {
3711 mbox
->mbox_flag
|= LPFC_MBX_IMED_UNREG
;
3712 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_dflt_rpi
;
3715 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_reg_login
;
3716 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
3717 lpfc_nlp_set_state(vport
, ndlp
,
3718 NLP_STE_REG_LOGIN_ISSUE
);
3720 if (lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
)
3721 != MBX_NOT_FINISHED
)
3724 /* Decrement the ndlp reference count we
3725 * set for this failed mailbox command.
3729 /* ELS rsp: Cannot issue reg_login for <NPortid> */
3730 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
3731 "0138 ELS rsp: Cannot issue reg_login for x%x "
3732 "Data: x%x x%x x%x\n",
3733 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
3736 if (lpfc_nlp_not_used(ndlp
)) {
3738 /* Indicate node has already been released,
3739 * should not reference to it from within
3740 * the routine lpfc_els_free_iocb.
3742 cmdiocb
->context1
= NULL
;
3745 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
3746 if (!lpfc_error_lost_link(irsp
) &&
3747 ndlp
->nlp_flag
& NLP_ACC_REGLOGIN
) {
3748 if (lpfc_nlp_not_used(ndlp
)) {
3750 /* Indicate node has already been
3751 * released, should not reference
3752 * to it from within the routine
3753 * lpfc_els_free_iocb.
3755 cmdiocb
->context1
= NULL
;
3759 mp
= (struct lpfc_dmabuf
*) mbox
->context1
;
3761 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
3764 mempool_free(mbox
, phba
->mbox_mem_pool
);
3767 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
)) {
3768 spin_lock_irq(shost
->host_lock
);
3769 ndlp
->nlp_flag
&= ~(NLP_ACC_REGLOGIN
| NLP_RM_DFLT_RPI
);
3770 spin_unlock_irq(shost
->host_lock
);
3772 /* If the node is not being used by another discovery thread,
3773 * and we are sending a reject, we are done with it.
3774 * Release driver reference count here and free associated
3778 if (lpfc_nlp_not_used(ndlp
))
3779 /* Indicate node has already been released,
3780 * should not reference to it from within
3781 * the routine lpfc_els_free_iocb.
3783 cmdiocb
->context1
= NULL
;
3786 lpfc_els_free_iocb(phba
, cmdiocb
);
3791 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
3792 * @vport: pointer to a host virtual N_Port data structure.
3793 * @flag: the els command code to be accepted.
3794 * @oldiocb: pointer to the original lpfc command iocb data structure.
3795 * @ndlp: pointer to a node-list data structure.
3796 * @mbox: pointer to the driver internal queue element for mailbox command.
3798 * This routine prepares and issues an Accept (ACC) response IOCB
3799 * command. It uses the @flag to properly set up the IOCB field for the
3800 * specific ACC response command to be issued and invokes the
3801 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
3802 * @mbox pointer is passed in, it will be put into the context_un.mbox
3803 * field of the IOCB for the completion callback function to issue the
3804 * mailbox command to the HBA later when callback is invoked.
3806 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3807 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3808 * will be stored into the context1 field of the IOCB for the completion
3809 * callback function to the corresponding response ELS IOCB command.
3812 * 0 - Successfully issued acc response
3813 * 1 - Failed to issue acc response
3816 lpfc_els_rsp_acc(struct lpfc_vport
*vport
, uint32_t flag
,
3817 struct lpfc_iocbq
*oldiocb
, struct lpfc_nodelist
*ndlp
,
3820 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3821 struct lpfc_hba
*phba
= vport
->phba
;
3824 struct lpfc_iocbq
*elsiocb
;
3825 struct lpfc_sli
*psli
;
3829 ELS_PKT
*els_pkt_ptr
;
3832 oldcmd
= &oldiocb
->iocb
;
3836 cmdsize
= sizeof(uint32_t);
3837 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
,
3838 ndlp
, ndlp
->nlp_DID
, ELS_CMD_ACC
);
3840 spin_lock_irq(shost
->host_lock
);
3841 ndlp
->nlp_flag
&= ~NLP_LOGO_ACC
;
3842 spin_unlock_irq(shost
->host_lock
);
3846 icmd
= &elsiocb
->iocb
;
3847 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri / rx_id */
3848 icmd
->unsli3
.rcvsli3
.ox_id
= oldcmd
->unsli3
.rcvsli3
.ox_id
;
3849 pcmd
= (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
3850 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
3851 pcmd
+= sizeof(uint32_t);
3853 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
3854 "Issue ACC: did:x%x flg:x%x",
3855 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
3858 cmdsize
= (sizeof(struct serv_parm
) + sizeof(uint32_t));
3859 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
,
3860 ndlp
, ndlp
->nlp_DID
, ELS_CMD_ACC
);
3864 icmd
= &elsiocb
->iocb
;
3865 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri / rx_id */
3866 icmd
->unsli3
.rcvsli3
.ox_id
= oldcmd
->unsli3
.rcvsli3
.ox_id
;
3867 pcmd
= (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
3870 elsiocb
->context_un
.mbox
= mbox
;
3872 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
3873 pcmd
+= sizeof(uint32_t);
3874 memcpy(pcmd
, &vport
->fc_sparam
, sizeof(struct serv_parm
));
3876 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
3877 "Issue ACC PLOGI: did:x%x flg:x%x",
3878 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
3881 cmdsize
= sizeof(uint32_t) + sizeof(PRLO
);
3882 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
,
3883 ndlp
, ndlp
->nlp_DID
, ELS_CMD_PRLO
);
3887 icmd
= &elsiocb
->iocb
;
3888 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri / rx_id */
3889 icmd
->unsli3
.rcvsli3
.ox_id
= oldcmd
->unsli3
.rcvsli3
.ox_id
;
3890 pcmd
= (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
3892 memcpy(pcmd
, ((struct lpfc_dmabuf
*) oldiocb
->context2
)->virt
,
3893 sizeof(uint32_t) + sizeof(PRLO
));
3894 *((uint32_t *) (pcmd
)) = ELS_CMD_PRLO_ACC
;
3895 els_pkt_ptr
= (ELS_PKT
*) pcmd
;
3896 els_pkt_ptr
->un
.prlo
.acceptRspCode
= PRLO_REQ_EXECUTED
;
3898 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
3899 "Issue ACC PRLO: did:x%x flg:x%x",
3900 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
3905 /* Xmit ELS ACC response tag <ulpIoTag> */
3906 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3907 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
3908 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x "
3910 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
3911 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
3912 ndlp
->nlp_rpi
, vport
->fc_flag
);
3913 if (ndlp
->nlp_flag
& NLP_LOGO_ACC
) {
3914 spin_lock_irq(shost
->host_lock
);
3915 ndlp
->nlp_flag
&= ~NLP_LOGO_ACC
;
3916 spin_unlock_irq(shost
->host_lock
);
3917 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_logo_acc
;
3919 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
3922 phba
->fc_stat
.elsXmitACC
++;
3923 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
3924 if (rc
== IOCB_ERROR
) {
3925 lpfc_els_free_iocb(phba
, elsiocb
);
3932 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
3933 * @vport: pointer to a virtual N_Port data structure.
3935 * @oldiocb: pointer to the original lpfc command iocb data structure.
3936 * @ndlp: pointer to a node-list data structure.
3937 * @mbox: pointer to the driver internal queue element for mailbox command.
3939 * This routine prepares and issue an Reject (RJT) response IOCB
3940 * command. If a @mbox pointer is passed in, it will be put into the
3941 * context_un.mbox field of the IOCB for the completion callback function
3942 * to issue to the HBA later.
3944 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3945 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3946 * will be stored into the context1 field of the IOCB for the completion
3947 * callback function to the reject response ELS IOCB command.
3950 * 0 - Successfully issued reject response
3951 * 1 - Failed to issue reject response
3954 lpfc_els_rsp_reject(struct lpfc_vport
*vport
, uint32_t rejectError
,
3955 struct lpfc_iocbq
*oldiocb
, struct lpfc_nodelist
*ndlp
,
3958 struct lpfc_hba
*phba
= vport
->phba
;
3961 struct lpfc_iocbq
*elsiocb
;
3962 struct lpfc_sli
*psli
;
3968 cmdsize
= 2 * sizeof(uint32_t);
3969 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
3970 ndlp
->nlp_DID
, ELS_CMD_LS_RJT
);
3974 icmd
= &elsiocb
->iocb
;
3975 oldcmd
= &oldiocb
->iocb
;
3976 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri / rx_id */
3977 icmd
->unsli3
.rcvsli3
.ox_id
= oldcmd
->unsli3
.rcvsli3
.ox_id
;
3978 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
3980 *((uint32_t *) (pcmd
)) = ELS_CMD_LS_RJT
;
3981 pcmd
+= sizeof(uint32_t);
3982 *((uint32_t *) (pcmd
)) = rejectError
;
3985 elsiocb
->context_un
.mbox
= mbox
;
3987 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
3988 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3989 "0129 Xmit ELS RJT x%x response tag x%x "
3990 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
3992 rejectError
, elsiocb
->iotag
,
3993 elsiocb
->iocb
.ulpContext
, ndlp
->nlp_DID
,
3994 ndlp
->nlp_flag
, ndlp
->nlp_state
, ndlp
->nlp_rpi
);
3995 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
3996 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
3997 ndlp
->nlp_DID
, ndlp
->nlp_flag
, rejectError
);
3999 phba
->fc_stat
.elsXmitLSRJT
++;
4000 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
4001 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
4003 if (rc
== IOCB_ERROR
) {
4004 lpfc_els_free_iocb(phba
, elsiocb
);
4011 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
4012 * @vport: pointer to a virtual N_Port data structure.
4013 * @oldiocb: pointer to the original lpfc command iocb data structure.
4014 * @ndlp: pointer to a node-list data structure.
4016 * This routine prepares and issues an Accept (ACC) response to Address
4017 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
4018 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
4020 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4021 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4022 * will be stored into the context1 field of the IOCB for the completion
4023 * callback function to the ADISC Accept response ELS IOCB command.
4026 * 0 - Successfully issued acc adisc response
4027 * 1 - Failed to issue adisc acc response
4030 lpfc_els_rsp_adisc_acc(struct lpfc_vport
*vport
, struct lpfc_iocbq
*oldiocb
,
4031 struct lpfc_nodelist
*ndlp
)
4033 struct lpfc_hba
*phba
= vport
->phba
;
4035 IOCB_t
*icmd
, *oldcmd
;
4036 struct lpfc_iocbq
*elsiocb
;
4041 cmdsize
= sizeof(uint32_t) + sizeof(ADISC
);
4042 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
4043 ndlp
->nlp_DID
, ELS_CMD_ACC
);
4047 icmd
= &elsiocb
->iocb
;
4048 oldcmd
= &oldiocb
->iocb
;
4049 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri / rx_id */
4050 icmd
->unsli3
.rcvsli3
.ox_id
= oldcmd
->unsli3
.rcvsli3
.ox_id
;
4052 /* Xmit ADISC ACC response tag <ulpIoTag> */
4053 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
4054 "0130 Xmit ADISC ACC response iotag x%x xri: "
4055 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
4056 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
4057 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
4059 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
4061 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
4062 pcmd
+= sizeof(uint32_t);
4064 ap
= (ADISC
*) (pcmd
);
4065 ap
->hardAL_PA
= phba
->fc_pref_ALPA
;
4066 memcpy(&ap
->portName
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
4067 memcpy(&ap
->nodeName
, &vport
->fc_nodename
, sizeof(struct lpfc_name
));
4068 ap
->DID
= be32_to_cpu(vport
->fc_myDID
);
4070 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
4071 "Issue ACC ADISC: did:x%x flg:x%x",
4072 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
4074 phba
->fc_stat
.elsXmitACC
++;
4075 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
4076 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
4077 if (rc
== IOCB_ERROR
) {
4078 lpfc_els_free_iocb(phba
, elsiocb
);
4085 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
4086 * @vport: pointer to a virtual N_Port data structure.
4087 * @oldiocb: pointer to the original lpfc command iocb data structure.
4088 * @ndlp: pointer to a node-list data structure.
4090 * This routine prepares and issues an Accept (ACC) response to Process
4091 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
4092 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
4094 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4095 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4096 * will be stored into the context1 field of the IOCB for the completion
4097 * callback function to the PRLI Accept response ELS IOCB command.
4100 * 0 - Successfully issued acc prli response
4101 * 1 - Failed to issue acc prli response
4104 lpfc_els_rsp_prli_acc(struct lpfc_vport
*vport
, struct lpfc_iocbq
*oldiocb
,
4105 struct lpfc_nodelist
*ndlp
)
4107 struct lpfc_hba
*phba
= vport
->phba
;
4112 struct lpfc_iocbq
*elsiocb
;
4113 struct lpfc_sli
*psli
;
4120 cmdsize
= sizeof(uint32_t) + sizeof(PRLI
);
4121 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
4122 ndlp
->nlp_DID
, (ELS_CMD_ACC
| (ELS_CMD_PRLI
& ~ELS_RSP_MASK
)));
4126 icmd
= &elsiocb
->iocb
;
4127 oldcmd
= &oldiocb
->iocb
;
4128 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri / rx_id */
4129 icmd
->unsli3
.rcvsli3
.ox_id
= oldcmd
->unsli3
.rcvsli3
.ox_id
;
4131 /* Xmit PRLI ACC response tag <ulpIoTag> */
4132 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
4133 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
4134 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
4135 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
4136 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
4138 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
4140 *((uint32_t *) (pcmd
)) = (ELS_CMD_ACC
| (ELS_CMD_PRLI
& ~ELS_RSP_MASK
));
4141 pcmd
+= sizeof(uint32_t);
4143 /* For PRLI, remainder of payload is PRLI parameter page */
4144 memset(pcmd
, 0, sizeof(PRLI
));
4146 npr
= (PRLI
*) pcmd
;
4149 * If the remote port is a target and our firmware version is 3.20 or
4150 * later, set the following bits for FC-TAPE support.
4152 if ((ndlp
->nlp_type
& NLP_FCP_TARGET
) &&
4153 (vpd
->rev
.feaLevelHigh
>= 0x02)) {
4154 npr
->ConfmComplAllowed
= 1;
4156 npr
->TaskRetryIdReq
= 1;
4159 npr
->acceptRspCode
= PRLI_REQ_EXECUTED
;
4160 npr
->estabImagePair
= 1;
4161 npr
->readXferRdyDis
= 1;
4162 npr
->ConfmComplAllowed
= 1;
4164 npr
->prliType
= PRLI_FCP_TYPE
;
4165 npr
->initiatorFunc
= 1;
4167 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
4168 "Issue ACC PRLI: did:x%x flg:x%x",
4169 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
4171 phba
->fc_stat
.elsXmitACC
++;
4172 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
4174 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
4175 if (rc
== IOCB_ERROR
) {
4176 lpfc_els_free_iocb(phba
, elsiocb
);
4183 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
4184 * @vport: pointer to a virtual N_Port data structure.
4185 * @format: rnid command format.
4186 * @oldiocb: pointer to the original lpfc command iocb data structure.
4187 * @ndlp: pointer to a node-list data structure.
4189 * This routine issues a Request Node Identification Data (RNID) Accept
4190 * (ACC) response. It constructs the RNID ACC response command according to
4191 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
4192 * issue the response. Note that this command does not need to hold the ndlp
4193 * reference count for the callback. So, the ndlp reference count taken by
4194 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
4195 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
4196 * there is no ndlp reference available.
4198 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4199 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4200 * will be stored into the context1 field of the IOCB for the completion
4201 * callback function. However, for the RNID Accept Response ELS command,
4202 * this is undone later by this routine after the IOCB is allocated.
4205 * 0 - Successfully issued acc rnid response
4206 * 1 - Failed to issue acc rnid response
4209 lpfc_els_rsp_rnid_acc(struct lpfc_vport
*vport
, uint8_t format
,
4210 struct lpfc_iocbq
*oldiocb
, struct lpfc_nodelist
*ndlp
)
4212 struct lpfc_hba
*phba
= vport
->phba
;
4214 IOCB_t
*icmd
, *oldcmd
;
4215 struct lpfc_iocbq
*elsiocb
;
4216 struct lpfc_sli
*psli
;
4222 cmdsize
= sizeof(uint32_t) + sizeof(uint32_t)
4223 + (2 * sizeof(struct lpfc_name
));
4225 cmdsize
+= sizeof(RNID_TOP_DISC
);
4227 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
4228 ndlp
->nlp_DID
, ELS_CMD_ACC
);
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 RNID ACC response tag <ulpIoTag> */
4238 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
4239 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
4240 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
);
4241 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
4242 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
4243 pcmd
+= sizeof(uint32_t);
4245 memset(pcmd
, 0, sizeof(RNID
));
4246 rn
= (RNID
*) (pcmd
);
4247 rn
->Format
= format
;
4248 rn
->CommonLen
= (2 * sizeof(struct lpfc_name
));
4249 memcpy(&rn
->portName
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
4250 memcpy(&rn
->nodeName
, &vport
->fc_nodename
, sizeof(struct lpfc_name
));
4253 rn
->SpecificLen
= 0;
4255 case RNID_TOPOLOGY_DISC
:
4256 rn
->SpecificLen
= sizeof(RNID_TOP_DISC
);
4257 memcpy(&rn
->un
.topologyDisc
.portName
,
4258 &vport
->fc_portname
, sizeof(struct lpfc_name
));
4259 rn
->un
.topologyDisc
.unitType
= RNID_HBA
;
4260 rn
->un
.topologyDisc
.physPort
= 0;
4261 rn
->un
.topologyDisc
.attachedNodes
= 0;
4265 rn
->SpecificLen
= 0;
4269 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
4270 "Issue ACC RNID: did:x%x flg:x%x",
4271 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
4273 phba
->fc_stat
.elsXmitACC
++;
4274 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
4276 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
4277 if (rc
== IOCB_ERROR
) {
4278 lpfc_els_free_iocb(phba
, elsiocb
);
4285 * lpfc_els_clear_rrq - Clear the rq that this rrq describes.
4286 * @vport: pointer to a virtual N_Port data structure.
4287 * @iocb: pointer to the lpfc command iocb data structure.
4288 * @ndlp: pointer to a node-list data structure.
4293 lpfc_els_clear_rrq(struct lpfc_vport
*vport
,
4294 struct lpfc_iocbq
*iocb
, struct lpfc_nodelist
*ndlp
)
4296 struct lpfc_hba
*phba
= vport
->phba
;
4301 struct lpfc_node_rrq
*prrq
;
4304 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) iocb
->context2
)->virt
);
4305 pcmd
+= sizeof(uint32_t);
4306 rrq
= (struct RRQ
*)pcmd
;
4307 rrq
->rrq_exchg
= be32_to_cpu(rrq
->rrq_exchg
);
4308 rxid
= bf_get(rrq_rxid
, rrq
);
4310 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
4311 "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x"
4313 be32_to_cpu(bf_get(rrq_did
, rrq
)),
4314 bf_get(rrq_oxid
, rrq
),
4316 iocb
->iotag
, iocb
->iocb
.ulpContext
);
4318 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
4319 "Clear RRQ: did:x%x flg:x%x exchg:x%.08x",
4320 ndlp
->nlp_DID
, ndlp
->nlp_flag
, rrq
->rrq_exchg
);
4321 if (vport
->fc_myDID
== be32_to_cpu(bf_get(rrq_did
, rrq
)))
4322 xri
= bf_get(rrq_oxid
, rrq
);
4325 prrq
= lpfc_get_active_rrq(vport
, xri
, ndlp
->nlp_DID
);
4327 lpfc_clr_rrq_active(phba
, xri
, prrq
);
4332 * lpfc_els_rsp_echo_acc - Issue echo acc response
4333 * @vport: pointer to a virtual N_Port data structure.
4334 * @data: pointer to echo data to return in the accept.
4335 * @oldiocb: pointer to the original lpfc command iocb data structure.
4336 * @ndlp: pointer to a node-list data structure.
4339 * 0 - Successfully issued acc echo response
4340 * 1 - Failed to issue acc echo response
4343 lpfc_els_rsp_echo_acc(struct lpfc_vport
*vport
, uint8_t *data
,
4344 struct lpfc_iocbq
*oldiocb
, struct lpfc_nodelist
*ndlp
)
4346 struct lpfc_hba
*phba
= vport
->phba
;
4347 struct lpfc_iocbq
*elsiocb
;
4348 struct lpfc_sli
*psli
;
4354 cmdsize
= oldiocb
->iocb
.unsli3
.rcvsli3
.acc_len
;
4356 /* The accumulated length can exceed the BPL_SIZE. For
4357 * now, use this as the limit
4359 if (cmdsize
> LPFC_BPL_SIZE
)
4360 cmdsize
= LPFC_BPL_SIZE
;
4361 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
4362 ndlp
->nlp_DID
, ELS_CMD_ACC
);
4366 elsiocb
->iocb
.ulpContext
= oldiocb
->iocb
.ulpContext
; /* Xri / rx_id */
4367 elsiocb
->iocb
.unsli3
.rcvsli3
.ox_id
= oldiocb
->iocb
.unsli3
.rcvsli3
.ox_id
;
4369 /* Xmit ECHO ACC response tag <ulpIoTag> */
4370 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
4371 "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
4372 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
);
4373 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
4374 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
4375 pcmd
+= sizeof(uint32_t);
4376 memcpy(pcmd
, data
, cmdsize
- sizeof(uint32_t));
4378 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
4379 "Issue ACC ECHO: did:x%x flg:x%x",
4380 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
4382 phba
->fc_stat
.elsXmitACC
++;
4383 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
4385 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
4386 if (rc
== IOCB_ERROR
) {
4387 lpfc_els_free_iocb(phba
, elsiocb
);
4394 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
4395 * @vport: pointer to a host virtual N_Port data structure.
4397 * This routine issues Address Discover (ADISC) ELS commands to those
4398 * N_Ports which are in node port recovery state and ADISC has not been issued
4399 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
4400 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
4401 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
4402 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
4403 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
4404 * IOCBs quit for later pick up. On the other hand, after walking through
4405 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
4406 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
4407 * no more ADISC need to be sent.
4410 * The number of N_Ports with adisc issued.
4413 lpfc_els_disc_adisc(struct lpfc_vport
*vport
)
4415 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4416 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
4419 /* go thru NPR nodes and issue any remaining ELS ADISCs */
4420 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
, nlp_listp
) {
4421 if (!NLP_CHK_NODE_ACT(ndlp
))
4423 if (ndlp
->nlp_state
== NLP_STE_NPR_NODE
&&
4424 (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) != 0 &&
4425 (ndlp
->nlp_flag
& NLP_NPR_ADISC
) != 0) {
4426 spin_lock_irq(shost
->host_lock
);
4427 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
4428 spin_unlock_irq(shost
->host_lock
);
4429 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
4430 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_ADISC_ISSUE
);
4431 lpfc_issue_els_adisc(vport
, ndlp
, 0);
4433 vport
->num_disc_nodes
++;
4434 if (vport
->num_disc_nodes
>=
4435 vport
->cfg_discovery_threads
) {
4436 spin_lock_irq(shost
->host_lock
);
4437 vport
->fc_flag
|= FC_NLP_MORE
;
4438 spin_unlock_irq(shost
->host_lock
);
4443 if (sentadisc
== 0) {
4444 spin_lock_irq(shost
->host_lock
);
4445 vport
->fc_flag
&= ~FC_NLP_MORE
;
4446 spin_unlock_irq(shost
->host_lock
);
4452 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
4453 * @vport: pointer to a host virtual N_Port data structure.
4455 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
4456 * which are in node port recovery state, with a @vport. Each time an ELS
4457 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
4458 * the per @vport number of discover count (num_disc_nodes) shall be
4459 * incremented. If the num_disc_nodes reaches a pre-configured threshold
4460 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
4461 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
4462 * later pick up. On the other hand, after walking through all the ndlps with
4463 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
4464 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
4465 * PLOGI need to be sent.
4468 * The number of N_Ports with plogi issued.
4471 lpfc_els_disc_plogi(struct lpfc_vport
*vport
)
4473 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4474 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
4477 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
4478 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
, nlp_listp
) {
4479 if (!NLP_CHK_NODE_ACT(ndlp
))
4481 if (ndlp
->nlp_state
== NLP_STE_NPR_NODE
&&
4482 (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) != 0 &&
4483 (ndlp
->nlp_flag
& NLP_DELAY_TMO
) == 0 &&
4484 (ndlp
->nlp_flag
& NLP_NPR_ADISC
) == 0) {
4485 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
4486 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
4487 lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0);
4489 vport
->num_disc_nodes
++;
4490 if (vport
->num_disc_nodes
>=
4491 vport
->cfg_discovery_threads
) {
4492 spin_lock_irq(shost
->host_lock
);
4493 vport
->fc_flag
|= FC_NLP_MORE
;
4494 spin_unlock_irq(shost
->host_lock
);
4500 lpfc_set_disctmo(vport
);
4503 spin_lock_irq(shost
->host_lock
);
4504 vport
->fc_flag
&= ~FC_NLP_MORE
;
4505 spin_unlock_irq(shost
->host_lock
);
4511 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
4512 * @vport: pointer to a host virtual N_Port data structure.
4514 * This routine cleans up any Registration State Change Notification
4515 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
4516 * @vport together with the host_lock is used to prevent multiple thread
4517 * trying to access the RSCN array on a same @vport at the same time.
4520 lpfc_els_flush_rscn(struct lpfc_vport
*vport
)
4522 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4523 struct lpfc_hba
*phba
= vport
->phba
;
4526 spin_lock_irq(shost
->host_lock
);
4527 if (vport
->fc_rscn_flush
) {
4528 /* Another thread is walking fc_rscn_id_list on this vport */
4529 spin_unlock_irq(shost
->host_lock
);
4532 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
4533 vport
->fc_rscn_flush
= 1;
4534 spin_unlock_irq(shost
->host_lock
);
4536 for (i
= 0; i
< vport
->fc_rscn_id_cnt
; i
++) {
4537 lpfc_in_buf_free(phba
, vport
->fc_rscn_id_list
[i
]);
4538 vport
->fc_rscn_id_list
[i
] = NULL
;
4540 spin_lock_irq(shost
->host_lock
);
4541 vport
->fc_rscn_id_cnt
= 0;
4542 vport
->fc_flag
&= ~(FC_RSCN_MODE
| FC_RSCN_DISCOVERY
);
4543 spin_unlock_irq(shost
->host_lock
);
4544 lpfc_can_disctmo(vport
);
4545 /* Indicate we are done walking this fc_rscn_id_list */
4546 vport
->fc_rscn_flush
= 0;
4550 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
4551 * @vport: pointer to a host virtual N_Port data structure.
4552 * @did: remote destination port identifier.
4554 * This routine checks whether there is any pending Registration State
4555 * Configuration Notification (RSCN) to a @did on @vport.
4558 * None zero - The @did matched with a pending rscn
4559 * 0 - not able to match @did with a pending rscn
4562 lpfc_rscn_payload_check(struct lpfc_vport
*vport
, uint32_t did
)
4567 uint32_t payload_len
, i
;
4568 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4570 ns_did
.un
.word
= did
;
4572 /* Never match fabric nodes for RSCNs */
4573 if ((did
& Fabric_DID_MASK
) == Fabric_DID_MASK
)
4576 /* If we are doing a FULL RSCN rediscovery, match everything */
4577 if (vport
->fc_flag
& FC_RSCN_DISCOVERY
)
4580 spin_lock_irq(shost
->host_lock
);
4581 if (vport
->fc_rscn_flush
) {
4582 /* Another thread is walking fc_rscn_id_list on this vport */
4583 spin_unlock_irq(shost
->host_lock
);
4586 /* Indicate we are walking fc_rscn_id_list on this vport */
4587 vport
->fc_rscn_flush
= 1;
4588 spin_unlock_irq(shost
->host_lock
);
4589 for (i
= 0; i
< vport
->fc_rscn_id_cnt
; i
++) {
4590 lp
= vport
->fc_rscn_id_list
[i
]->virt
;
4591 payload_len
= be32_to_cpu(*lp
++ & ~ELS_CMD_MASK
);
4592 payload_len
-= sizeof(uint32_t); /* take off word 0 */
4593 while (payload_len
) {
4594 rscn_did
.un
.word
= be32_to_cpu(*lp
++);
4595 payload_len
-= sizeof(uint32_t);
4596 switch (rscn_did
.un
.b
.resv
& RSCN_ADDRESS_FORMAT_MASK
) {
4597 case RSCN_ADDRESS_FORMAT_PORT
:
4598 if ((ns_did
.un
.b
.domain
== rscn_did
.un
.b
.domain
)
4599 && (ns_did
.un
.b
.area
== rscn_did
.un
.b
.area
)
4600 && (ns_did
.un
.b
.id
== rscn_did
.un
.b
.id
))
4601 goto return_did_out
;
4603 case RSCN_ADDRESS_FORMAT_AREA
:
4604 if ((ns_did
.un
.b
.domain
== rscn_did
.un
.b
.domain
)
4605 && (ns_did
.un
.b
.area
== rscn_did
.un
.b
.area
))
4606 goto return_did_out
;
4608 case RSCN_ADDRESS_FORMAT_DOMAIN
:
4609 if (ns_did
.un
.b
.domain
== rscn_did
.un
.b
.domain
)
4610 goto return_did_out
;
4612 case RSCN_ADDRESS_FORMAT_FABRIC
:
4613 goto return_did_out
;
4617 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4618 vport
->fc_rscn_flush
= 0;
4621 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4622 vport
->fc_rscn_flush
= 0;
4627 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
4628 * @vport: pointer to a host virtual N_Port data structure.
4630 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
4631 * state machine for a @vport's nodes that are with pending RSCN (Registration
4632 * State Change Notification).
4635 * 0 - Successful (currently alway return 0)
4638 lpfc_rscn_recovery_check(struct lpfc_vport
*vport
)
4640 struct lpfc_nodelist
*ndlp
= NULL
;
4642 /* Move all affected nodes by pending RSCNs to NPR state. */
4643 list_for_each_entry(ndlp
, &vport
->fc_nodes
, nlp_listp
) {
4644 if (!NLP_CHK_NODE_ACT(ndlp
) ||
4645 (ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
) ||
4646 !lpfc_rscn_payload_check(vport
, ndlp
->nlp_DID
))
4648 lpfc_disc_state_machine(vport
, ndlp
, NULL
,
4649 NLP_EVT_DEVICE_RECOVERY
);
4650 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
4656 * lpfc_send_rscn_event - Send an RSCN event to management application
4657 * @vport: pointer to a host virtual N_Port data structure.
4658 * @cmdiocb: pointer to lpfc command iocb data structure.
4660 * lpfc_send_rscn_event sends an RSCN netlink event to management
4664 lpfc_send_rscn_event(struct lpfc_vport
*vport
,
4665 struct lpfc_iocbq
*cmdiocb
)
4667 struct lpfc_dmabuf
*pcmd
;
4668 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4669 uint32_t *payload_ptr
;
4670 uint32_t payload_len
;
4671 struct lpfc_rscn_event_header
*rscn_event_data
;
4673 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
4674 payload_ptr
= (uint32_t *) pcmd
->virt
;
4675 payload_len
= be32_to_cpu(*payload_ptr
& ~ELS_CMD_MASK
);
4677 rscn_event_data
= kmalloc(sizeof(struct lpfc_rscn_event_header
) +
4678 payload_len
, GFP_KERNEL
);
4679 if (!rscn_event_data
) {
4680 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
4681 "0147 Failed to allocate memory for RSCN event\n");
4684 rscn_event_data
->event_type
= FC_REG_RSCN_EVENT
;
4685 rscn_event_data
->payload_length
= payload_len
;
4686 memcpy(rscn_event_data
->rscn_payload
, payload_ptr
,
4689 fc_host_post_vendor_event(shost
,
4690 fc_get_event_number(),
4691 sizeof(struct lpfc_els_event_header
) + payload_len
,
4692 (char *)rscn_event_data
,
4695 kfree(rscn_event_data
);
4699 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
4700 * @vport: pointer to a host virtual N_Port data structure.
4701 * @cmdiocb: pointer to lpfc command iocb data structure.
4702 * @ndlp: pointer to a node-list data structure.
4704 * This routine processes an unsolicited RSCN (Registration State Change
4705 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
4706 * to invoke fc_host_post_event() routine to the FC transport layer. If the
4707 * discover state machine is about to begin discovery, it just accepts the
4708 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
4709 * contains N_Port IDs for other vports on this HBA, it just accepts the
4710 * RSCN and ignore processing it. If the state machine is in the recovery
4711 * state, the fc_rscn_id_list of this @vport is walked and the
4712 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
4713 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
4714 * routine is invoked to handle the RSCN event.
4717 * 0 - Just sent the acc response
4718 * 1 - Sent the acc response and waited for name server completion
4721 lpfc_els_rcv_rscn(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
4722 struct lpfc_nodelist
*ndlp
)
4724 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4725 struct lpfc_hba
*phba
= vport
->phba
;
4726 struct lpfc_dmabuf
*pcmd
;
4727 uint32_t *lp
, *datap
;
4729 uint32_t payload_len
, length
, nportid
, *cmd
;
4731 int rscn_id
= 0, hba_id
= 0;
4734 icmd
= &cmdiocb
->iocb
;
4735 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
4736 lp
= (uint32_t *) pcmd
->virt
;
4738 payload_len
= be32_to_cpu(*lp
++ & ~ELS_CMD_MASK
);
4739 payload_len
-= sizeof(uint32_t); /* take off word 0 */
4741 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
4742 "0214 RSCN received Data: x%x x%x x%x x%x\n",
4743 vport
->fc_flag
, payload_len
, *lp
,
4744 vport
->fc_rscn_id_cnt
);
4746 /* Send an RSCN event to the management application */
4747 lpfc_send_rscn_event(vport
, cmdiocb
);
4749 for (i
= 0; i
< payload_len
/sizeof(uint32_t); i
++)
4750 fc_host_post_event(shost
, fc_get_event_number(),
4751 FCH_EVT_RSCN
, lp
[i
]);
4753 /* If we are about to begin discovery, just ACC the RSCN.
4754 * Discovery processing will satisfy it.
4756 if (vport
->port_state
<= LPFC_NS_QRY
) {
4757 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
4758 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
4759 ndlp
->nlp_DID
, vport
->port_state
, ndlp
->nlp_flag
);
4761 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
4765 /* If this RSCN just contains NPortIDs for other vports on this HBA,
4766 * just ACC and ignore it.
4768 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
4769 !(vport
->cfg_peer_port_login
)) {
4774 nportid
= ((be32_to_cpu(nportid
)) & Mask_DID
);
4775 i
-= sizeof(uint32_t);
4777 if (lpfc_find_vport_by_did(phba
, nportid
))
4780 if (rscn_id
== hba_id
) {
4781 /* ALL NPortIDs in RSCN are on HBA */
4782 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
4784 "Data: x%x x%x x%x x%x\n",
4785 vport
->fc_flag
, payload_len
,
4786 *lp
, vport
->fc_rscn_id_cnt
);
4787 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
4788 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
4789 ndlp
->nlp_DID
, vport
->port_state
,
4792 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
,
4798 spin_lock_irq(shost
->host_lock
);
4799 if (vport
->fc_rscn_flush
) {
4800 /* Another thread is walking fc_rscn_id_list on this vport */
4801 vport
->fc_flag
|= FC_RSCN_DISCOVERY
;
4802 spin_unlock_irq(shost
->host_lock
);
4804 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
4807 /* Indicate we are walking fc_rscn_id_list on this vport */
4808 vport
->fc_rscn_flush
= 1;
4809 spin_unlock_irq(shost
->host_lock
);
4810 /* Get the array count after successfully have the token */
4811 rscn_cnt
= vport
->fc_rscn_id_cnt
;
4812 /* If we are already processing an RSCN, save the received
4813 * RSCN payload buffer, cmdiocb->context2 to process later.
4815 if (vport
->fc_flag
& (FC_RSCN_MODE
| FC_NDISC_ACTIVE
)) {
4816 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
4817 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
4818 ndlp
->nlp_DID
, vport
->port_state
, ndlp
->nlp_flag
);
4820 spin_lock_irq(shost
->host_lock
);
4821 vport
->fc_flag
|= FC_RSCN_DEFERRED
;
4822 if ((rscn_cnt
< FC_MAX_HOLD_RSCN
) &&
4823 !(vport
->fc_flag
& FC_RSCN_DISCOVERY
)) {
4824 vport
->fc_flag
|= FC_RSCN_MODE
;
4825 spin_unlock_irq(shost
->host_lock
);
4827 cmd
= vport
->fc_rscn_id_list
[rscn_cnt
-1]->virt
;
4828 length
= be32_to_cpu(*cmd
& ~ELS_CMD_MASK
);
4831 (payload_len
+ length
<= LPFC_BPL_SIZE
)) {
4832 *cmd
&= ELS_CMD_MASK
;
4833 *cmd
|= cpu_to_be32(payload_len
+ length
);
4834 memcpy(((uint8_t *)cmd
) + length
, lp
,
4837 vport
->fc_rscn_id_list
[rscn_cnt
] = pcmd
;
4838 vport
->fc_rscn_id_cnt
++;
4839 /* If we zero, cmdiocb->context2, the calling
4840 * routine will not try to free it.
4842 cmdiocb
->context2
= NULL
;
4845 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
4846 "0235 Deferred RSCN "
4847 "Data: x%x x%x x%x\n",
4848 vport
->fc_rscn_id_cnt
, vport
->fc_flag
,
4851 vport
->fc_flag
|= FC_RSCN_DISCOVERY
;
4852 spin_unlock_irq(shost
->host_lock
);
4853 /* ReDiscovery RSCN */
4854 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
4855 "0234 ReDiscovery RSCN "
4856 "Data: x%x x%x x%x\n",
4857 vport
->fc_rscn_id_cnt
, vport
->fc_flag
,
4860 /* Indicate we are done walking fc_rscn_id_list on this vport */
4861 vport
->fc_rscn_flush
= 0;
4863 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
4864 /* send RECOVERY event for ALL nodes that match RSCN payload */
4865 lpfc_rscn_recovery_check(vport
);
4866 spin_lock_irq(shost
->host_lock
);
4867 vport
->fc_flag
&= ~FC_RSCN_DEFERRED
;
4868 spin_unlock_irq(shost
->host_lock
);
4871 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
4872 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
4873 ndlp
->nlp_DID
, vport
->port_state
, ndlp
->nlp_flag
);
4875 spin_lock_irq(shost
->host_lock
);
4876 vport
->fc_flag
|= FC_RSCN_MODE
;
4877 spin_unlock_irq(shost
->host_lock
);
4878 vport
->fc_rscn_id_list
[vport
->fc_rscn_id_cnt
++] = pcmd
;
4879 /* Indicate we are done walking fc_rscn_id_list on this vport */
4880 vport
->fc_rscn_flush
= 0;
4882 * If we zero, cmdiocb->context2, the calling routine will
4883 * not try to free it.
4885 cmdiocb
->context2
= NULL
;
4886 lpfc_set_disctmo(vport
);
4888 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
4889 /* send RECOVERY event for ALL nodes that match RSCN payload */
4890 lpfc_rscn_recovery_check(vport
);
4891 return lpfc_els_handle_rscn(vport
);
4895 * lpfc_els_handle_rscn - Handle rscn for a vport
4896 * @vport: pointer to a host virtual N_Port data structure.
4898 * This routine handles the Registration State Configuration Notification
4899 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
4900 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
4901 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
4902 * NameServer shall be issued. If CT command to the NameServer fails to be
4903 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
4904 * RSCN activities with the @vport.
4907 * 0 - Cleaned up rscn on the @vport
4908 * 1 - Wait for plogi to name server before proceed
4911 lpfc_els_handle_rscn(struct lpfc_vport
*vport
)
4913 struct lpfc_nodelist
*ndlp
;
4914 struct lpfc_hba
*phba
= vport
->phba
;
4916 /* Ignore RSCN if the port is being torn down. */
4917 if (vport
->load_flag
& FC_UNLOADING
) {
4918 lpfc_els_flush_rscn(vport
);
4922 /* Start timer for RSCN processing */
4923 lpfc_set_disctmo(vport
);
4925 /* RSCN processed */
4926 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
4927 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
4928 vport
->fc_flag
, 0, vport
->fc_rscn_id_cnt
,
4931 /* To process RSCN, first compare RSCN data with NameServer */
4932 vport
->fc_ns_retry
= 0;
4933 vport
->num_disc_nodes
= 0;
4935 ndlp
= lpfc_findnode_did(vport
, NameServer_DID
);
4936 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
)
4937 && ndlp
->nlp_state
== NLP_STE_UNMAPPED_NODE
) {
4938 /* Good ndlp, issue CT Request to NameServer */
4939 if (lpfc_ns_cmd(vport
, SLI_CTNS_GID_FT
, 0, 0) == 0)
4940 /* Wait for NameServer query cmpl before we can
4944 /* If login to NameServer does not exist, issue one */
4945 /* Good status, issue PLOGI to NameServer */
4946 ndlp
= lpfc_findnode_did(vport
, NameServer_DID
);
4947 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
))
4948 /* Wait for NameServer login cmpl before we can
4953 ndlp
= lpfc_enable_node(vport
, ndlp
,
4954 NLP_STE_PLOGI_ISSUE
);
4956 lpfc_els_flush_rscn(vport
);
4959 ndlp
->nlp_prev_state
= NLP_STE_UNUSED_NODE
;
4961 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
4963 lpfc_els_flush_rscn(vport
);
4966 lpfc_nlp_init(vport
, ndlp
, NameServer_DID
);
4967 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
4968 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
4970 ndlp
->nlp_type
|= NLP_FABRIC
;
4971 lpfc_issue_els_plogi(vport
, NameServer_DID
, 0);
4972 /* Wait for NameServer login cmpl before we can
4978 lpfc_els_flush_rscn(vport
);
4983 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
4984 * @vport: pointer to a host virtual N_Port data structure.
4985 * @cmdiocb: pointer to lpfc command iocb data structure.
4986 * @ndlp: pointer to a node-list data structure.
4988 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
4989 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
4990 * point topology. As an unsolicited FLOGI should not be received in a loop
4991 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
4992 * lpfc_check_sparm() routine is invoked to check the parameters in the
4993 * unsolicited FLOGI. If parameters validation failed, the routine
4994 * lpfc_els_rsp_reject() shall be called with reject reason code set to
4995 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
4996 * FLOGI shall be compared with the Port WWN of the @vport to determine who
4997 * will initiate PLOGI. The higher lexicographical value party shall has
4998 * higher priority (as the winning port) and will initiate PLOGI and
4999 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
5000 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
5001 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
5004 * 0 - Successfully processed the unsolicited flogi
5005 * 1 - Failed to process the unsolicited flogi
5008 lpfc_els_rcv_flogi(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
5009 struct lpfc_nodelist
*ndlp
)
5011 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
5012 struct lpfc_hba
*phba
= vport
->phba
;
5013 struct lpfc_dmabuf
*pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
5014 uint32_t *lp
= (uint32_t *) pcmd
->virt
;
5015 IOCB_t
*icmd
= &cmdiocb
->iocb
;
5016 struct serv_parm
*sp
;
5023 sp
= (struct serv_parm
*) lp
;
5025 /* FLOGI received */
5027 lpfc_set_disctmo(vport
);
5029 if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) {
5030 /* We should never receive a FLOGI in loop mode, ignore it */
5031 did
= icmd
->un
.elsreq64
.remoteID
;
5033 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
5035 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
5036 "0113 An FLOGI ELS command x%x was "
5037 "received from DID x%x in Loop Mode\n",
5042 if ((lpfc_check_sparm(vport
, ndlp
, sp
, CLASS3
, 1))) {
5043 /* For a FLOGI we accept, then if our portname is greater
5044 * then the remote portname we initiate Nport login.
5047 rc
= memcmp(&vport
->fc_portname
, &sp
->portName
,
5048 sizeof(struct lpfc_name
));
5051 if (phba
->sli_rev
< LPFC_SLI_REV4
) {
5052 mbox
= mempool_alloc(phba
->mbox_mem_pool
,
5056 lpfc_linkdown(phba
);
5057 lpfc_init_link(phba
, mbox
,
5059 phba
->cfg_link_speed
);
5060 mbox
->u
.mb
.un
.varInitLnk
.lipsr_AL_PA
= 0;
5061 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
5062 mbox
->vport
= vport
;
5063 rc
= lpfc_sli_issue_mbox(phba
, mbox
,
5065 lpfc_set_loopback_flag(phba
);
5066 if (rc
== MBX_NOT_FINISHED
)
5067 mempool_free(mbox
, phba
->mbox_mem_pool
);
5070 /* abort the flogi coming back to ourselves
5071 * due to external loopback on the port.
5073 lpfc_els_abort_flogi(phba
);
5076 } else if (rc
> 0) { /* greater than */
5077 spin_lock_irq(shost
->host_lock
);
5078 vport
->fc_flag
|= FC_PT2PT_PLOGI
;
5079 spin_unlock_irq(shost
->host_lock
);
5081 /* If we have the high WWPN we can assign our own
5082 * myDID; otherwise, we have to WAIT for a PLOGI
5083 * from the remote NPort to find out what it
5086 vport
->fc_myDID
= PT2PT_LocalID
;
5090 * The vport state should go to LPFC_FLOGI only
5091 * AFTER we issue a FLOGI, not receive one.
5093 spin_lock_irq(shost
->host_lock
);
5094 vport
->fc_flag
|= FC_PT2PT
;
5095 vport
->fc_flag
&= ~(FC_FABRIC
| FC_PUBLIC_LOOP
);
5096 spin_unlock_irq(shost
->host_lock
);
5099 * We temporarily set fc_myDID to make it look like we are
5100 * a Fabric. This is done just so we end up with the right
5101 * did / sid on the FLOGI ACC rsp.
5103 did
= vport
->fc_myDID
;
5104 vport
->fc_myDID
= Fabric_DID
;
5107 /* Reject this request because invalid parameters */
5108 stat
.un
.b
.lsRjtRsvd0
= 0;
5109 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
5110 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_SPARM_OPTIONS
;
5111 stat
.un
.b
.vendorUnique
= 0;
5114 * We temporarily set fc_myDID to make it look like we are
5115 * a Fabric. This is done just so we end up with the right
5116 * did / sid on the FLOGI LS_RJT rsp.
5118 did
= vport
->fc_myDID
;
5119 vport
->fc_myDID
= Fabric_DID
;
5121 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
,
5124 /* Now lets put fc_myDID back to what its supposed to be */
5125 vport
->fc_myDID
= did
;
5131 lpfc_els_rsp_acc(vport
, ELS_CMD_PLOGI
, cmdiocb
, ndlp
, NULL
);
5133 /* Now lets put fc_myDID back to what its supposed to be */
5134 vport
->fc_myDID
= did
;
5136 if (!(vport
->fc_flag
& FC_PT2PT_PLOGI
)) {
5138 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
5142 lpfc_config_link(phba
, mbox
);
5144 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
5145 mbox
->vport
= vport
;
5146 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
5147 if (rc
== MBX_NOT_FINISHED
) {
5148 mempool_free(mbox
, phba
->mbox_mem_pool
);
5159 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
5160 * @vport: pointer to a host virtual N_Port data structure.
5161 * @cmdiocb: pointer to lpfc command iocb data structure.
5162 * @ndlp: pointer to a node-list data structure.
5164 * This routine processes Request Node Identification Data (RNID) IOCB
5165 * received as an ELS unsolicited event. Only when the RNID specified format
5166 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
5167 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
5168 * Accept (ACC) the RNID ELS command. All the other RNID formats are
5169 * rejected by invoking the lpfc_els_rsp_reject() routine.
5172 * 0 - Successfully processed rnid iocb (currently always return 0)
5175 lpfc_els_rcv_rnid(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
5176 struct lpfc_nodelist
*ndlp
)
5178 struct lpfc_dmabuf
*pcmd
;
5185 icmd
= &cmdiocb
->iocb
;
5186 did
= icmd
->un
.elsreq64
.remoteID
;
5187 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
5188 lp
= (uint32_t *) pcmd
->virt
;
5195 switch (rn
->Format
) {
5197 case RNID_TOPOLOGY_DISC
:
5199 lpfc_els_rsp_rnid_acc(vport
, rn
->Format
, cmdiocb
, ndlp
);
5202 /* Reject this request because format not supported */
5203 stat
.un
.b
.lsRjtRsvd0
= 0;
5204 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
5205 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CANT_GIVE_DATA
;
5206 stat
.un
.b
.vendorUnique
= 0;
5207 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
,
5214 * lpfc_els_rcv_echo - Process an unsolicited echo iocb
5215 * @vport: pointer to a host virtual N_Port data structure.
5216 * @cmdiocb: pointer to lpfc command iocb data structure.
5217 * @ndlp: pointer to a node-list data structure.
5220 * 0 - Successfully processed echo iocb (currently always return 0)
5223 lpfc_els_rcv_echo(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
5224 struct lpfc_nodelist
*ndlp
)
5228 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) cmdiocb
->context2
)->virt
);
5230 /* skip over first word of echo command to find echo data */
5231 pcmd
+= sizeof(uint32_t);
5233 lpfc_els_rsp_echo_acc(vport
, pcmd
, cmdiocb
, ndlp
);
5238 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
5239 * @vport: pointer to a host virtual N_Port data structure.
5240 * @cmdiocb: pointer to lpfc command iocb data structure.
5241 * @ndlp: pointer to a node-list data structure.
5243 * This routine processes a Link Incident Report Registration(LIRR) IOCB
5244 * received as an ELS unsolicited event. Currently, this function just invokes
5245 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
5248 * 0 - Successfully processed lirr iocb (currently always return 0)
5251 lpfc_els_rcv_lirr(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
5252 struct lpfc_nodelist
*ndlp
)
5256 /* For now, unconditionally reject this command */
5257 stat
.un
.b
.lsRjtRsvd0
= 0;
5258 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
5259 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CANT_GIVE_DATA
;
5260 stat
.un
.b
.vendorUnique
= 0;
5261 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
5266 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
5267 * @vport: pointer to a host virtual N_Port data structure.
5268 * @cmdiocb: pointer to lpfc command iocb data structure.
5269 * @ndlp: pointer to a node-list data structure.
5271 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
5272 * received as an ELS unsolicited event. A request to RRQ shall only
5273 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
5274 * Nx_Port N_Port_ID of the target Exchange is the same as the
5275 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
5276 * not accepted, an LS_RJT with reason code "Unable to perform
5277 * command request" and reason code explanation "Invalid Originator
5278 * S_ID" shall be returned. For now, we just unconditionally accept
5279 * RRQ from the target.
5282 lpfc_els_rcv_rrq(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
5283 struct lpfc_nodelist
*ndlp
)
5285 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
5286 if (vport
->phba
->sli_rev
== LPFC_SLI_REV4
)
5287 lpfc_els_clear_rrq(vport
, cmdiocb
, ndlp
);
5291 * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
5292 * @phba: pointer to lpfc hba data structure.
5293 * @pmb: pointer to the driver internal queue element for mailbox command.
5295 * This routine is the completion callback function for the MBX_READ_LNK_STAT
5296 * mailbox command. This callback function is to actually send the Accept
5297 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
5298 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
5299 * mailbox command, constructs the RPS response with the link statistics
5300 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
5301 * response to the RPS.
5303 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5304 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5305 * will be stored into the context1 field of the IOCB for the completion
5306 * callback function to the RPS Accept Response ELS IOCB command.
5310 lpfc_els_rsp_rls_acc(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
5314 struct RLS_RSP
*rls_rsp
;
5316 struct lpfc_iocbq
*elsiocb
;
5317 struct lpfc_nodelist
*ndlp
;
5324 ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
5325 rxid
= (uint16_t) ((unsigned long)(pmb
->context1
) & 0xffff);
5326 oxid
= (uint16_t) (((unsigned long)(pmb
->context1
) >> 16) & 0xffff);
5327 pmb
->context1
= NULL
;
5328 pmb
->context2
= NULL
;
5330 if (mb
->mbxStatus
) {
5331 mempool_free(pmb
, phba
->mbox_mem_pool
);
5335 cmdsize
= sizeof(struct RLS_RSP
) + sizeof(uint32_t);
5336 elsiocb
= lpfc_prep_els_iocb(phba
->pport
, 0, cmdsize
,
5337 lpfc_max_els_tries
, ndlp
,
5338 ndlp
->nlp_DID
, ELS_CMD_ACC
);
5340 /* Decrement the ndlp reference count from previous mbox command */
5344 mempool_free(pmb
, phba
->mbox_mem_pool
);
5348 icmd
= &elsiocb
->iocb
;
5349 icmd
->ulpContext
= rxid
;
5350 icmd
->unsli3
.rcvsli3
.ox_id
= oxid
;
5352 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
5353 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
5354 pcmd
+= sizeof(uint32_t); /* Skip past command */
5355 rls_rsp
= (struct RLS_RSP
*)pcmd
;
5357 rls_rsp
->linkFailureCnt
= cpu_to_be32(mb
->un
.varRdLnk
.linkFailureCnt
);
5358 rls_rsp
->lossSyncCnt
= cpu_to_be32(mb
->un
.varRdLnk
.lossSyncCnt
);
5359 rls_rsp
->lossSignalCnt
= cpu_to_be32(mb
->un
.varRdLnk
.lossSignalCnt
);
5360 rls_rsp
->primSeqErrCnt
= cpu_to_be32(mb
->un
.varRdLnk
.primSeqErrCnt
);
5361 rls_rsp
->invalidXmitWord
= cpu_to_be32(mb
->un
.varRdLnk
.invalidXmitWord
);
5362 rls_rsp
->crcCnt
= cpu_to_be32(mb
->un
.varRdLnk
.crcCnt
);
5363 mempool_free(pmb
, phba
->mbox_mem_pool
);
5364 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
5365 lpfc_printf_vlog(ndlp
->vport
, KERN_INFO
, LOG_ELS
,
5366 "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
5367 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
5368 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
5369 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
5371 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
5372 phba
->fc_stat
.elsXmitACC
++;
5373 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) == IOCB_ERROR
)
5374 lpfc_els_free_iocb(phba
, elsiocb
);
5378 * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
5379 * @phba: pointer to lpfc hba data structure.
5380 * @pmb: pointer to the driver internal queue element for mailbox command.
5382 * This routine is the completion callback function for the MBX_READ_LNK_STAT
5383 * mailbox command. This callback function is to actually send the Accept
5384 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
5385 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
5386 * mailbox command, constructs the RPS response with the link statistics
5387 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
5388 * response to the RPS.
5390 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5391 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5392 * will be stored into the context1 field of the IOCB for the completion
5393 * callback function to the RPS Accept Response ELS IOCB command.
5397 lpfc_els_rsp_rps_acc(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
5403 struct lpfc_iocbq
*elsiocb
;
5404 struct lpfc_nodelist
*ndlp
;
5412 ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
5413 rxid
= (uint16_t) ((unsigned long)(pmb
->context1
) & 0xffff);
5414 oxid
= (uint16_t) (((unsigned long)(pmb
->context1
) >> 16) & 0xffff);
5415 pmb
->context1
= NULL
;
5416 pmb
->context2
= NULL
;
5418 if (mb
->mbxStatus
) {
5419 mempool_free(pmb
, phba
->mbox_mem_pool
);
5423 cmdsize
= sizeof(RPS_RSP
) + sizeof(uint32_t);
5424 mempool_free(pmb
, phba
->mbox_mem_pool
);
5425 elsiocb
= lpfc_prep_els_iocb(phba
->pport
, 0, cmdsize
,
5426 lpfc_max_els_tries
, ndlp
,
5427 ndlp
->nlp_DID
, ELS_CMD_ACC
);
5429 /* Decrement the ndlp reference count from previous mbox command */
5435 icmd
= &elsiocb
->iocb
;
5436 icmd
->ulpContext
= rxid
;
5437 icmd
->unsli3
.rcvsli3
.ox_id
= oxid
;
5439 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
5440 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
5441 pcmd
+= sizeof(uint32_t); /* Skip past command */
5442 rps_rsp
= (RPS_RSP
*)pcmd
;
5444 if (phba
->fc_topology
!= LPFC_TOPOLOGY_LOOP
)
5448 if (phba
->pport
->fc_flag
& FC_FABRIC
)
5452 rps_rsp
->portStatus
= cpu_to_be16(status
);
5453 rps_rsp
->linkFailureCnt
= cpu_to_be32(mb
->un
.varRdLnk
.linkFailureCnt
);
5454 rps_rsp
->lossSyncCnt
= cpu_to_be32(mb
->un
.varRdLnk
.lossSyncCnt
);
5455 rps_rsp
->lossSignalCnt
= cpu_to_be32(mb
->un
.varRdLnk
.lossSignalCnt
);
5456 rps_rsp
->primSeqErrCnt
= cpu_to_be32(mb
->un
.varRdLnk
.primSeqErrCnt
);
5457 rps_rsp
->invalidXmitWord
= cpu_to_be32(mb
->un
.varRdLnk
.invalidXmitWord
);
5458 rps_rsp
->crcCnt
= cpu_to_be32(mb
->un
.varRdLnk
.crcCnt
);
5459 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
5460 lpfc_printf_vlog(ndlp
->vport
, KERN_INFO
, LOG_ELS
,
5461 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
5462 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
5463 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
5464 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
5466 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
5467 phba
->fc_stat
.elsXmitACC
++;
5468 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) == IOCB_ERROR
)
5469 lpfc_els_free_iocb(phba
, elsiocb
);
5474 * lpfc_els_rcv_rls - Process an unsolicited rls iocb
5475 * @vport: pointer to a host virtual N_Port data structure.
5476 * @cmdiocb: pointer to lpfc command iocb data structure.
5477 * @ndlp: pointer to a node-list data structure.
5479 * This routine processes Read Port Status (RPL) IOCB received as an
5480 * ELS unsolicited event. It first checks the remote port state. If the
5481 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5482 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
5483 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
5484 * for reading the HBA link statistics. It is for the callback function,
5485 * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
5486 * to actually sending out RPL Accept (ACC) response.
5489 * 0 - Successfully processed rls iocb (currently always return 0)
5492 lpfc_els_rcv_rls(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
5493 struct lpfc_nodelist
*ndlp
)
5495 struct lpfc_hba
*phba
= vport
->phba
;
5497 struct lpfc_dmabuf
*pcmd
;
5500 if ((ndlp
->nlp_state
!= NLP_STE_UNMAPPED_NODE
) &&
5501 (ndlp
->nlp_state
!= NLP_STE_MAPPED_NODE
))
5502 /* reject the unsolicited RPS request and done with it */
5505 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
5507 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_ATOMIC
);
5509 lpfc_read_lnk_stat(phba
, mbox
);
5510 mbox
->context1
= (void *)((unsigned long)
5511 ((cmdiocb
->iocb
.unsli3
.rcvsli3
.ox_id
<< 16) |
5512 cmdiocb
->iocb
.ulpContext
)); /* rx_id */
5513 mbox
->context2
= lpfc_nlp_get(ndlp
);
5514 mbox
->vport
= vport
;
5515 mbox
->mbox_cmpl
= lpfc_els_rsp_rls_acc
;
5516 if (lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
)
5517 != MBX_NOT_FINISHED
)
5518 /* Mbox completion will send ELS Response */
5520 /* Decrement reference count used for the failed mbox
5524 mempool_free(mbox
, phba
->mbox_mem_pool
);
5527 /* issue rejection response */
5528 stat
.un
.b
.lsRjtRsvd0
= 0;
5529 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
5530 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CANT_GIVE_DATA
;
5531 stat
.un
.b
.vendorUnique
= 0;
5532 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
5537 * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
5538 * @vport: pointer to a host virtual N_Port data structure.
5539 * @cmdiocb: pointer to lpfc command iocb data structure.
5540 * @ndlp: pointer to a node-list data structure.
5542 * This routine processes Read Timout Value (RTV) IOCB received as an
5543 * ELS unsolicited event. It first checks the remote port state. If the
5544 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5545 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
5546 * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
5547 * Value (RTV) unsolicited IOCB event.
5549 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5550 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5551 * will be stored into the context1 field of the IOCB for the completion
5552 * callback function to the RPS Accept Response ELS IOCB command.
5555 * 0 - Successfully processed rtv iocb (currently always return 0)
5558 lpfc_els_rcv_rtv(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
5559 struct lpfc_nodelist
*ndlp
)
5561 struct lpfc_hba
*phba
= vport
->phba
;
5563 struct RTV_RSP
*rtv_rsp
;
5565 struct lpfc_iocbq
*elsiocb
;
5569 if ((ndlp
->nlp_state
!= NLP_STE_UNMAPPED_NODE
) &&
5570 (ndlp
->nlp_state
!= NLP_STE_MAPPED_NODE
))
5571 /* reject the unsolicited RPS request and done with it */
5574 cmdsize
= sizeof(struct RTV_RSP
) + sizeof(uint32_t);
5575 elsiocb
= lpfc_prep_els_iocb(phba
->pport
, 0, cmdsize
,
5576 lpfc_max_els_tries
, ndlp
,
5577 ndlp
->nlp_DID
, ELS_CMD_ACC
);
5582 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
5583 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
5584 pcmd
+= sizeof(uint32_t); /* Skip past command */
5586 /* use the command's xri in the response */
5587 elsiocb
->iocb
.ulpContext
= cmdiocb
->iocb
.ulpContext
; /* Xri / rx_id */
5588 elsiocb
->iocb
.unsli3
.rcvsli3
.ox_id
= cmdiocb
->iocb
.unsli3
.rcvsli3
.ox_id
;
5590 rtv_rsp
= (struct RTV_RSP
*)pcmd
;
5592 /* populate RTV payload */
5593 rtv_rsp
->ratov
= cpu_to_be32(phba
->fc_ratov
* 1000); /* report msecs */
5594 rtv_rsp
->edtov
= cpu_to_be32(phba
->fc_edtov
);
5595 bf_set(qtov_edtovres
, rtv_rsp
, phba
->fc_edtovResol
? 1 : 0);
5596 bf_set(qtov_rttov
, rtv_rsp
, 0); /* Field is for FC ONLY */
5597 rtv_rsp
->qtov
= cpu_to_be32(rtv_rsp
->qtov
);
5599 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
5600 lpfc_printf_vlog(ndlp
->vport
, KERN_INFO
, LOG_ELS
,
5601 "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
5602 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
5603 "Data: x%x x%x x%x\n",
5604 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
5605 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
5607 rtv_rsp
->ratov
, rtv_rsp
->edtov
, rtv_rsp
->qtov
);
5608 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
5609 phba
->fc_stat
.elsXmitACC
++;
5610 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) == IOCB_ERROR
)
5611 lpfc_els_free_iocb(phba
, elsiocb
);
5615 /* issue rejection response */
5616 stat
.un
.b
.lsRjtRsvd0
= 0;
5617 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
5618 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CANT_GIVE_DATA
;
5619 stat
.un
.b
.vendorUnique
= 0;
5620 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
5624 /* lpfc_els_rcv_rps - Process an unsolicited rps iocb
5625 * @vport: pointer to a host virtual N_Port data structure.
5626 * @cmdiocb: pointer to lpfc command iocb data structure.
5627 * @ndlp: pointer to a node-list data structure.
5629 * This routine processes Read Port Status (RPS) IOCB received as an
5630 * ELS unsolicited event. It first checks the remote port state. If the
5631 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5632 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
5633 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
5634 * for reading the HBA link statistics. It is for the callback function,
5635 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
5636 * to actually sending out RPS Accept (ACC) response.
5639 * 0 - Successfully processed rps iocb (currently always return 0)
5642 lpfc_els_rcv_rps(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
5643 struct lpfc_nodelist
*ndlp
)
5645 struct lpfc_hba
*phba
= vport
->phba
;
5649 struct lpfc_dmabuf
*pcmd
;
5653 if ((ndlp
->nlp_state
!= NLP_STE_UNMAPPED_NODE
) &&
5654 (ndlp
->nlp_state
!= NLP_STE_MAPPED_NODE
))
5655 /* reject the unsolicited RPS request and done with it */
5658 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
5659 lp
= (uint32_t *) pcmd
->virt
;
5660 flag
= (be32_to_cpu(*lp
++) & 0xf);
5664 ((flag
== 1) && (be32_to_cpu(rps
->un
.portNum
) == 0)) ||
5665 ((flag
== 2) && (memcmp(&rps
->un
.portName
, &vport
->fc_portname
,
5666 sizeof(struct lpfc_name
)) == 0))) {
5668 printk("Fix me....\n");
5670 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_ATOMIC
);
5672 lpfc_read_lnk_stat(phba
, mbox
);
5673 mbox
->context1
= (void *)((unsigned long)
5674 ((cmdiocb
->iocb
.unsli3
.rcvsli3
.ox_id
<< 16) |
5675 cmdiocb
->iocb
.ulpContext
)); /* rx_id */
5676 mbox
->context2
= lpfc_nlp_get(ndlp
);
5677 mbox
->vport
= vport
;
5678 mbox
->mbox_cmpl
= lpfc_els_rsp_rps_acc
;
5679 if (lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
)
5680 != MBX_NOT_FINISHED
)
5681 /* Mbox completion will send ELS Response */
5683 /* Decrement reference count used for the failed mbox
5687 mempool_free(mbox
, phba
->mbox_mem_pool
);
5692 /* issue rejection response */
5693 stat
.un
.b
.lsRjtRsvd0
= 0;
5694 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
5695 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CANT_GIVE_DATA
;
5696 stat
.un
.b
.vendorUnique
= 0;
5697 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
5701 /* lpfc_issue_els_rrq - Process an unsolicited rps iocb
5702 * @vport: pointer to a host virtual N_Port data structure.
5703 * @ndlp: pointer to a node-list data structure.
5704 * @did: DID of the target.
5705 * @rrq: Pointer to the rrq struct.
5707 * Build a ELS RRQ command and send it to the target. If the issue_iocb is
5708 * Successful the the completion handler will clear the RRQ.
5711 * 0 - Successfully sent rrq els iocb.
5712 * 1 - Failed to send rrq els iocb.
5715 lpfc_issue_els_rrq(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
5716 uint32_t did
, struct lpfc_node_rrq
*rrq
)
5718 struct lpfc_hba
*phba
= vport
->phba
;
5719 struct RRQ
*els_rrq
;
5721 struct lpfc_iocbq
*elsiocb
;
5727 if (ndlp
!= rrq
->ndlp
)
5729 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
))
5732 /* If ndlp is not NULL, we will bump the reference count on it */
5733 cmdsize
= (sizeof(uint32_t) + sizeof(struct RRQ
));
5734 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, 0, ndlp
, did
,
5739 icmd
= &elsiocb
->iocb
;
5740 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
5742 /* For RRQ request, remainder of payload is Exchange IDs */
5743 *((uint32_t *) (pcmd
)) = ELS_CMD_RRQ
;
5744 pcmd
+= sizeof(uint32_t);
5745 els_rrq
= (struct RRQ
*) pcmd
;
5747 bf_set(rrq_oxid
, els_rrq
, phba
->sli4_hba
.xri_ids
[rrq
->xritag
]);
5748 bf_set(rrq_rxid
, els_rrq
, rrq
->rxid
);
5749 bf_set(rrq_did
, els_rrq
, vport
->fc_myDID
);
5750 els_rrq
->rrq
= cpu_to_be32(els_rrq
->rrq
);
5751 els_rrq
->rrq_exchg
= cpu_to_be32(els_rrq
->rrq_exchg
);
5754 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
5755 "Issue RRQ: did:x%x",
5756 did
, rrq
->xritag
, rrq
->rxid
);
5757 elsiocb
->context_un
.rrq
= rrq
;
5758 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rrq
;
5759 ret
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
5761 if (ret
== IOCB_ERROR
) {
5762 lpfc_els_free_iocb(phba
, elsiocb
);
5769 * lpfc_send_rrq - Sends ELS RRQ if needed.
5770 * @phba: pointer to lpfc hba data structure.
5771 * @rrq: pointer to the active rrq.
5773 * This routine will call the lpfc_issue_els_rrq if the rrq is
5774 * still active for the xri. If this function returns a failure then
5775 * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq.
5777 * Returns 0 Success.
5781 lpfc_send_rrq(struct lpfc_hba
*phba
, struct lpfc_node_rrq
*rrq
)
5783 struct lpfc_nodelist
*ndlp
= lpfc_findnode_did(rrq
->vport
,
5785 if (lpfc_test_rrq_active(phba
, ndlp
, rrq
->xritag
))
5786 return lpfc_issue_els_rrq(rrq
->vport
, ndlp
,
5793 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
5794 * @vport: pointer to a host virtual N_Port data structure.
5795 * @cmdsize: size of the ELS command.
5796 * @oldiocb: pointer to the original lpfc command iocb data structure.
5797 * @ndlp: pointer to a node-list data structure.
5799 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
5800 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
5802 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5803 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5804 * will be stored into the context1 field of the IOCB for the completion
5805 * callback function to the RPL Accept Response ELS command.
5808 * 0 - Successfully issued ACC RPL ELS command
5809 * 1 - Failed to issue ACC RPL ELS command
5812 lpfc_els_rsp_rpl_acc(struct lpfc_vport
*vport
, uint16_t cmdsize
,
5813 struct lpfc_iocbq
*oldiocb
, struct lpfc_nodelist
*ndlp
)
5815 struct lpfc_hba
*phba
= vport
->phba
;
5816 IOCB_t
*icmd
, *oldcmd
;
5818 struct lpfc_iocbq
*elsiocb
;
5821 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
5822 ndlp
->nlp_DID
, ELS_CMD_ACC
);
5827 icmd
= &elsiocb
->iocb
;
5828 oldcmd
= &oldiocb
->iocb
;
5829 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri / rx_id */
5830 icmd
->unsli3
.rcvsli3
.ox_id
= oldcmd
->unsli3
.rcvsli3
.ox_id
;
5832 pcmd
= (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
5833 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
5834 pcmd
+= sizeof(uint16_t);
5835 *((uint16_t *)(pcmd
)) = be16_to_cpu(cmdsize
);
5836 pcmd
+= sizeof(uint16_t);
5838 /* Setup the RPL ACC payload */
5839 rpl_rsp
.listLen
= be32_to_cpu(1);
5841 rpl_rsp
.port_num_blk
.portNum
= 0;
5842 rpl_rsp
.port_num_blk
.portID
= be32_to_cpu(vport
->fc_myDID
);
5843 memcpy(&rpl_rsp
.port_num_blk
.portName
, &vport
->fc_portname
,
5844 sizeof(struct lpfc_name
));
5845 memcpy(pcmd
, &rpl_rsp
, cmdsize
- sizeof(uint32_t));
5846 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
5847 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
5848 "0120 Xmit ELS RPL ACC response tag x%x "
5849 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
5851 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
5852 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
5854 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
5855 phba
->fc_stat
.elsXmitACC
++;
5856 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) ==
5858 lpfc_els_free_iocb(phba
, elsiocb
);
5865 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
5866 * @vport: pointer to a host virtual N_Port data structure.
5867 * @cmdiocb: pointer to lpfc command iocb data structure.
5868 * @ndlp: pointer to a node-list data structure.
5870 * This routine processes Read Port List (RPL) IOCB received as an ELS
5871 * unsolicited event. It first checks the remote port state. If the remote
5872 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
5873 * invokes the lpfc_els_rsp_reject() routine to send reject response.
5874 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
5875 * to accept the RPL.
5878 * 0 - Successfully processed rpl iocb (currently always return 0)
5881 lpfc_els_rcv_rpl(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
5882 struct lpfc_nodelist
*ndlp
)
5884 struct lpfc_dmabuf
*pcmd
;
5891 if ((ndlp
->nlp_state
!= NLP_STE_UNMAPPED_NODE
) &&
5892 (ndlp
->nlp_state
!= NLP_STE_MAPPED_NODE
)) {
5893 /* issue rejection response */
5894 stat
.un
.b
.lsRjtRsvd0
= 0;
5895 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
5896 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CANT_GIVE_DATA
;
5897 stat
.un
.b
.vendorUnique
= 0;
5898 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
,
5900 /* rejected the unsolicited RPL request and done with it */
5904 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
5905 lp
= (uint32_t *) pcmd
->virt
;
5906 rpl
= (RPL
*) (lp
+ 1);
5907 maxsize
= be32_to_cpu(rpl
->maxsize
);
5909 /* We support only one port */
5910 if ((rpl
->index
== 0) &&
5912 ((maxsize
* sizeof(uint32_t)) >= sizeof(RPL_RSP
)))) {
5913 cmdsize
= sizeof(uint32_t) + sizeof(RPL_RSP
);
5915 cmdsize
= sizeof(uint32_t) + maxsize
* sizeof(uint32_t);
5917 lpfc_els_rsp_rpl_acc(vport
, cmdsize
, cmdiocb
, ndlp
);
5923 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
5924 * @vport: pointer to a 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 Fibre Channel Address Resolution Protocol
5929 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
5930 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
5931 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
5932 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
5933 * remote PortName is compared against the FC PortName stored in the @vport
5934 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
5935 * compared against the FC NodeName stored in the @vport data structure.
5936 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
5937 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
5938 * invoked to send out FARP Response to the remote node. Before sending the
5939 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
5940 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
5941 * routine is invoked to log into the remote port first.
5944 * 0 - Either the FARP Match Mode not supported or successfully processed
5947 lpfc_els_rcv_farp(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
5948 struct lpfc_nodelist
*ndlp
)
5950 struct lpfc_dmabuf
*pcmd
;
5954 uint32_t cmd
, cnt
, did
;
5956 icmd
= &cmdiocb
->iocb
;
5957 did
= icmd
->un
.elsreq64
.remoteID
;
5958 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
5959 lp
= (uint32_t *) pcmd
->virt
;
5963 /* FARP-REQ received from DID <did> */
5964 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
5965 "0601 FARP-REQ received from DID x%x\n", did
);
5966 /* We will only support match on WWPN or WWNN */
5967 if (fp
->Mflags
& ~(FARP_MATCH_NODE
| FARP_MATCH_PORT
)) {
5972 /* If this FARP command is searching for my portname */
5973 if (fp
->Mflags
& FARP_MATCH_PORT
) {
5974 if (memcmp(&fp
->RportName
, &vport
->fc_portname
,
5975 sizeof(struct lpfc_name
)) == 0)
5979 /* If this FARP command is searching for my nodename */
5980 if (fp
->Mflags
& FARP_MATCH_NODE
) {
5981 if (memcmp(&fp
->RnodeName
, &vport
->fc_nodename
,
5982 sizeof(struct lpfc_name
)) == 0)
5987 if ((ndlp
->nlp_state
== NLP_STE_UNMAPPED_NODE
) ||
5988 (ndlp
->nlp_state
== NLP_STE_MAPPED_NODE
)) {
5989 /* Log back into the node before sending the FARP. */
5990 if (fp
->Rflags
& FARP_REQUEST_PLOGI
) {
5991 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
5992 lpfc_nlp_set_state(vport
, ndlp
,
5993 NLP_STE_PLOGI_ISSUE
);
5994 lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0);
5997 /* Send a FARP response to that node */
5998 if (fp
->Rflags
& FARP_REQUEST_FARPR
)
5999 lpfc_issue_els_farpr(vport
, did
, 0);
6006 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
6007 * @vport: pointer to a host virtual N_Port data structure.
6008 * @cmdiocb: pointer to lpfc command iocb data structure.
6009 * @ndlp: pointer to a node-list data structure.
6011 * This routine processes Fibre Channel Address Resolution Protocol
6012 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
6013 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
6014 * the FARP response request.
6017 * 0 - Successfully processed FARPR IOCB (currently always return 0)
6020 lpfc_els_rcv_farpr(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
6021 struct lpfc_nodelist
*ndlp
)
6023 struct lpfc_dmabuf
*pcmd
;
6028 icmd
= &cmdiocb
->iocb
;
6029 did
= icmd
->un
.elsreq64
.remoteID
;
6030 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
6031 lp
= (uint32_t *) pcmd
->virt
;
6034 /* FARP-RSP received from DID <did> */
6035 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
6036 "0600 FARP-RSP received from DID x%x\n", did
);
6037 /* ACCEPT the Farp resp request */
6038 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
6044 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
6045 * @vport: pointer to a host virtual N_Port data structure.
6046 * @cmdiocb: pointer to lpfc command iocb data structure.
6047 * @fan_ndlp: pointer to a node-list data structure.
6049 * This routine processes a Fabric Address Notification (FAN) IOCB
6050 * command received as an ELS unsolicited event. The FAN ELS command will
6051 * only be processed on a physical port (i.e., the @vport represents the
6052 * physical port). The fabric NodeName and PortName from the FAN IOCB are
6053 * compared against those in the phba data structure. If any of those is
6054 * different, the lpfc_initial_flogi() routine is invoked to initialize
6055 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
6056 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
6057 * is invoked to register login to the fabric.
6060 * 0 - Successfully processed fan iocb (currently always return 0).
6063 lpfc_els_rcv_fan(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
6064 struct lpfc_nodelist
*fan_ndlp
)
6066 struct lpfc_hba
*phba
= vport
->phba
;
6070 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
, "0265 FAN received\n");
6071 lp
= (uint32_t *)((struct lpfc_dmabuf
*)cmdiocb
->context2
)->virt
;
6073 /* FAN received; Fan does not have a reply sequence */
6074 if ((vport
== phba
->pport
) &&
6075 (vport
->port_state
== LPFC_LOCAL_CFG_LINK
)) {
6076 if ((memcmp(&phba
->fc_fabparam
.nodeName
, &fp
->FnodeName
,
6077 sizeof(struct lpfc_name
))) ||
6078 (memcmp(&phba
->fc_fabparam
.portName
, &fp
->FportName
,
6079 sizeof(struct lpfc_name
)))) {
6080 /* This port has switched fabrics. FLOGI is required */
6081 lpfc_issue_init_vfi(vport
);
6083 /* FAN verified - skip FLOGI */
6084 vport
->fc_myDID
= vport
->fc_prevDID
;
6085 if (phba
->sli_rev
< LPFC_SLI_REV4
)
6086 lpfc_issue_fabric_reglogin(vport
);
6088 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
6089 "3138 Need register VFI: (x%x/%x)\n",
6090 vport
->fc_prevDID
, vport
->fc_myDID
);
6091 lpfc_issue_reg_vfi(vport
);
6099 * lpfc_els_timeout - Handler funciton to the els timer
6100 * @ptr: holder for the timer function associated data.
6102 * This routine is invoked by the ELS timer after timeout. It posts the ELS
6103 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
6104 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
6105 * up the worker thread. It is for the worker thread to invoke the routine
6106 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
6109 lpfc_els_timeout(unsigned long ptr
)
6111 struct lpfc_vport
*vport
= (struct lpfc_vport
*) ptr
;
6112 struct lpfc_hba
*phba
= vport
->phba
;
6113 uint32_t tmo_posted
;
6114 unsigned long iflag
;
6116 spin_lock_irqsave(&vport
->work_port_lock
, iflag
);
6117 tmo_posted
= vport
->work_port_events
& WORKER_ELS_TMO
;
6119 vport
->work_port_events
|= WORKER_ELS_TMO
;
6120 spin_unlock_irqrestore(&vport
->work_port_lock
, iflag
);
6123 lpfc_worker_wake_up(phba
);
6129 * lpfc_els_timeout_handler - Process an els timeout event
6130 * @vport: pointer to a virtual N_Port data structure.
6132 * This routine is the actual handler function that processes an ELS timeout
6133 * event. It walks the ELS ring to get and abort all the IOCBs (except the
6134 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
6135 * invoking the lpfc_sli_issue_abort_iotag() routine.
6138 lpfc_els_timeout_handler(struct lpfc_vport
*vport
)
6140 struct lpfc_hba
*phba
= vport
->phba
;
6141 struct lpfc_sli_ring
*pring
;
6142 struct lpfc_iocbq
*tmp_iocb
, *piocb
;
6144 struct lpfc_dmabuf
*pcmd
;
6145 uint32_t els_command
= 0;
6147 uint32_t remote_ID
= 0xffffffff;
6148 LIST_HEAD(txcmplq_completions
);
6149 LIST_HEAD(abort_list
);
6152 timeout
= (uint32_t)(phba
->fc_ratov
<< 1);
6154 pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
6156 spin_lock_irq(&phba
->hbalock
);
6157 list_splice_init(&pring
->txcmplq
, &txcmplq_completions
);
6158 spin_unlock_irq(&phba
->hbalock
);
6160 list_for_each_entry_safe(piocb
, tmp_iocb
, &txcmplq_completions
, list
) {
6163 if ((piocb
->iocb_flag
& LPFC_IO_LIBDFC
) != 0 ||
6164 piocb
->iocb
.ulpCommand
== CMD_ABORT_XRI_CN
||
6165 piocb
->iocb
.ulpCommand
== CMD_CLOSE_XRI_CN
)
6168 if (piocb
->vport
!= vport
)
6171 pcmd
= (struct lpfc_dmabuf
*) piocb
->context2
;
6173 els_command
= *(uint32_t *) (pcmd
->virt
);
6175 if (els_command
== ELS_CMD_FARP
||
6176 els_command
== ELS_CMD_FARPR
||
6177 els_command
== ELS_CMD_FDISC
)
6180 if (piocb
->drvrTimeout
> 0) {
6181 if (piocb
->drvrTimeout
>= timeout
)
6182 piocb
->drvrTimeout
-= timeout
;
6184 piocb
->drvrTimeout
= 0;
6188 remote_ID
= 0xffffffff;
6189 if (cmd
->ulpCommand
!= CMD_GEN_REQUEST64_CR
)
6190 remote_ID
= cmd
->un
.elsreq64
.remoteID
;
6192 struct lpfc_nodelist
*ndlp
;
6193 ndlp
= __lpfc_findnode_rpi(vport
, cmd
->ulpContext
);
6194 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
))
6195 remote_ID
= ndlp
->nlp_DID
;
6197 list_add_tail(&piocb
->dlist
, &abort_list
);
6199 spin_lock_irq(&phba
->hbalock
);
6200 list_splice(&txcmplq_completions
, &pring
->txcmplq
);
6201 spin_unlock_irq(&phba
->hbalock
);
6203 list_for_each_entry_safe(piocb
, tmp_iocb
, &abort_list
, dlist
) {
6204 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
6205 "0127 ELS timeout Data: x%x x%x x%x "
6206 "x%x\n", els_command
,
6207 remote_ID
, cmd
->ulpCommand
, cmd
->ulpIoTag
);
6208 spin_lock_irq(&phba
->hbalock
);
6209 list_del_init(&piocb
->dlist
);
6210 lpfc_sli_issue_abort_iotag(phba
, pring
, piocb
);
6211 spin_unlock_irq(&phba
->hbalock
);
6214 if (phba
->sli
.ring
[LPFC_ELS_RING
].txcmplq_cnt
)
6215 mod_timer(&vport
->els_tmofunc
, jiffies
+ HZ
* timeout
);
6219 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
6220 * @vport: pointer to a host virtual N_Port data structure.
6222 * This routine is used to clean up all the outstanding ELS commands on a
6223 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
6224 * routine. After that, it walks the ELS transmit queue to remove all the
6225 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
6226 * the IOCBs with a non-NULL completion callback function, the callback
6227 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
6228 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
6229 * callback function, the IOCB will simply be released. Finally, it walks
6230 * the ELS transmit completion queue to issue an abort IOCB to any transmit
6231 * completion queue IOCB that is associated with the @vport and is not
6232 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
6233 * part of the discovery state machine) out to HBA by invoking the
6234 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
6235 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
6236 * the IOCBs are aborted when this function returns.
6239 lpfc_els_flush_cmd(struct lpfc_vport
*vport
)
6241 LIST_HEAD(completions
);
6242 struct lpfc_hba
*phba
= vport
->phba
;
6243 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
6244 struct lpfc_iocbq
*tmp_iocb
, *piocb
;
6247 lpfc_fabric_abort_vport(vport
);
6249 spin_lock_irq(&phba
->hbalock
);
6250 list_for_each_entry_safe(piocb
, tmp_iocb
, &pring
->txq
, list
) {
6253 if (piocb
->iocb_flag
& LPFC_IO_LIBDFC
) {
6257 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
6258 if (cmd
->ulpCommand
== CMD_QUE_RING_BUF_CN
||
6259 cmd
->ulpCommand
== CMD_QUE_RING_BUF64_CN
||
6260 cmd
->ulpCommand
== CMD_CLOSE_XRI_CN
||
6261 cmd
->ulpCommand
== CMD_ABORT_XRI_CN
)
6264 if (piocb
->vport
!= vport
)
6267 list_move_tail(&piocb
->list
, &completions
);
6271 list_for_each_entry_safe(piocb
, tmp_iocb
, &pring
->txcmplq
, list
) {
6272 if (piocb
->iocb_flag
& LPFC_IO_LIBDFC
) {
6276 if (piocb
->vport
!= vport
)
6279 lpfc_sli_issue_abort_iotag(phba
, pring
, piocb
);
6281 spin_unlock_irq(&phba
->hbalock
);
6283 /* Cancell all the IOCBs from the completions list */
6284 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
6291 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
6292 * @phba: pointer to lpfc hba data structure.
6294 * This routine is used to clean up all the outstanding ELS commands on a
6295 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
6296 * routine. After that, it walks the ELS transmit queue to remove all the
6297 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
6298 * the IOCBs with the completion callback function associated, the callback
6299 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
6300 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
6301 * callback function associated, the IOCB will simply be released. Finally,
6302 * it walks the ELS transmit completion queue to issue an abort IOCB to any
6303 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
6304 * management plane IOCBs that are not part of the discovery state machine)
6305 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
6308 lpfc_els_flush_all_cmd(struct lpfc_hba
*phba
)
6310 LIST_HEAD(completions
);
6311 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
6312 struct lpfc_iocbq
*tmp_iocb
, *piocb
;
6315 lpfc_fabric_abort_hba(phba
);
6316 spin_lock_irq(&phba
->hbalock
);
6317 list_for_each_entry_safe(piocb
, tmp_iocb
, &pring
->txq
, list
) {
6319 if (piocb
->iocb_flag
& LPFC_IO_LIBDFC
)
6321 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
6322 if (cmd
->ulpCommand
== CMD_QUE_RING_BUF_CN
||
6323 cmd
->ulpCommand
== CMD_QUE_RING_BUF64_CN
||
6324 cmd
->ulpCommand
== CMD_CLOSE_XRI_CN
||
6325 cmd
->ulpCommand
== CMD_ABORT_XRI_CN
)
6327 list_move_tail(&piocb
->list
, &completions
);
6330 list_for_each_entry_safe(piocb
, tmp_iocb
, &pring
->txcmplq
, list
) {
6331 if (piocb
->iocb_flag
& LPFC_IO_LIBDFC
)
6333 lpfc_sli_issue_abort_iotag(phba
, pring
, piocb
);
6335 spin_unlock_irq(&phba
->hbalock
);
6337 /* Cancel all the IOCBs from the completions list */
6338 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
6345 * lpfc_send_els_failure_event - Posts an ELS command failure event
6346 * @phba: Pointer to hba context object.
6347 * @cmdiocbp: Pointer to command iocb which reported error.
6348 * @rspiocbp: Pointer to response iocb which reported error.
6350 * This function sends an event when there is an ELS command
6354 lpfc_send_els_failure_event(struct lpfc_hba
*phba
,
6355 struct lpfc_iocbq
*cmdiocbp
,
6356 struct lpfc_iocbq
*rspiocbp
)
6358 struct lpfc_vport
*vport
= cmdiocbp
->vport
;
6359 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
6360 struct lpfc_lsrjt_event lsrjt_event
;
6361 struct lpfc_fabric_event_header fabric_event
;
6363 struct lpfc_nodelist
*ndlp
;
6366 ndlp
= cmdiocbp
->context1
;
6367 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
))
6370 if (rspiocbp
->iocb
.ulpStatus
== IOSTAT_LS_RJT
) {
6371 lsrjt_event
.header
.event_type
= FC_REG_ELS_EVENT
;
6372 lsrjt_event
.header
.subcategory
= LPFC_EVENT_LSRJT_RCV
;
6373 memcpy(lsrjt_event
.header
.wwpn
, &ndlp
->nlp_portname
,
6374 sizeof(struct lpfc_name
));
6375 memcpy(lsrjt_event
.header
.wwnn
, &ndlp
->nlp_nodename
,
6376 sizeof(struct lpfc_name
));
6377 pcmd
= (uint32_t *) (((struct lpfc_dmabuf
*)
6378 cmdiocbp
->context2
)->virt
);
6379 lsrjt_event
.command
= (pcmd
!= NULL
) ? *pcmd
: 0;
6380 stat
.un
.lsRjtError
= be32_to_cpu(rspiocbp
->iocb
.un
.ulpWord
[4]);
6381 lsrjt_event
.reason_code
= stat
.un
.b
.lsRjtRsnCode
;
6382 lsrjt_event
.explanation
= stat
.un
.b
.lsRjtRsnCodeExp
;
6383 fc_host_post_vendor_event(shost
,
6384 fc_get_event_number(),
6385 sizeof(lsrjt_event
),
6386 (char *)&lsrjt_event
,
6390 if ((rspiocbp
->iocb
.ulpStatus
== IOSTAT_NPORT_BSY
) ||
6391 (rspiocbp
->iocb
.ulpStatus
== IOSTAT_FABRIC_BSY
)) {
6392 fabric_event
.event_type
= FC_REG_FABRIC_EVENT
;
6393 if (rspiocbp
->iocb
.ulpStatus
== IOSTAT_NPORT_BSY
)
6394 fabric_event
.subcategory
= LPFC_EVENT_PORT_BUSY
;
6396 fabric_event
.subcategory
= LPFC_EVENT_FABRIC_BUSY
;
6397 memcpy(fabric_event
.wwpn
, &ndlp
->nlp_portname
,
6398 sizeof(struct lpfc_name
));
6399 memcpy(fabric_event
.wwnn
, &ndlp
->nlp_nodename
,
6400 sizeof(struct lpfc_name
));
6401 fc_host_post_vendor_event(shost
,
6402 fc_get_event_number(),
6403 sizeof(fabric_event
),
6404 (char *)&fabric_event
,
6412 * lpfc_send_els_event - Posts unsolicited els event
6413 * @vport: Pointer to vport object.
6414 * @ndlp: Pointer FC node object.
6415 * @cmd: ELS command code.
6417 * This function posts an event when there is an incoming
6418 * unsolicited ELS command.
6421 lpfc_send_els_event(struct lpfc_vport
*vport
,
6422 struct lpfc_nodelist
*ndlp
,
6425 struct lpfc_els_event_header
*els_data
= NULL
;
6426 struct lpfc_logo_event
*logo_data
= NULL
;
6427 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
6429 if (*payload
== ELS_CMD_LOGO
) {
6430 logo_data
= kmalloc(sizeof(struct lpfc_logo_event
), GFP_KERNEL
);
6432 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
6433 "0148 Failed to allocate memory "
6434 "for LOGO event\n");
6437 els_data
= &logo_data
->header
;
6439 els_data
= kmalloc(sizeof(struct lpfc_els_event_header
),
6442 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
6443 "0149 Failed to allocate memory "
6448 els_data
->event_type
= FC_REG_ELS_EVENT
;
6451 els_data
->subcategory
= LPFC_EVENT_PLOGI_RCV
;
6454 els_data
->subcategory
= LPFC_EVENT_PRLO_RCV
;
6457 els_data
->subcategory
= LPFC_EVENT_ADISC_RCV
;
6460 els_data
->subcategory
= LPFC_EVENT_LOGO_RCV
;
6461 /* Copy the WWPN in the LOGO payload */
6462 memcpy(logo_data
->logo_wwpn
, &payload
[2],
6463 sizeof(struct lpfc_name
));
6469 memcpy(els_data
->wwpn
, &ndlp
->nlp_portname
, sizeof(struct lpfc_name
));
6470 memcpy(els_data
->wwnn
, &ndlp
->nlp_nodename
, sizeof(struct lpfc_name
));
6471 if (*payload
== ELS_CMD_LOGO
) {
6472 fc_host_post_vendor_event(shost
,
6473 fc_get_event_number(),
6474 sizeof(struct lpfc_logo_event
),
6479 fc_host_post_vendor_event(shost
,
6480 fc_get_event_number(),
6481 sizeof(struct lpfc_els_event_header
),
6492 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
6493 * @phba: pointer to lpfc hba data structure.
6494 * @pring: pointer to a SLI ring.
6495 * @vport: pointer to a host virtual N_Port data structure.
6496 * @elsiocb: pointer to lpfc els command iocb data structure.
6498 * This routine is used for processing the IOCB associated with a unsolicited
6499 * event. It first determines whether there is an existing ndlp that matches
6500 * the DID from the unsolicited IOCB. If not, it will create a new one with
6501 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
6502 * IOCB is then used to invoke the proper routine and to set up proper state
6503 * of the discovery state machine.
6506 lpfc_els_unsol_buffer(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
6507 struct lpfc_vport
*vport
, struct lpfc_iocbq
*elsiocb
)
6509 struct Scsi_Host
*shost
;
6510 struct lpfc_nodelist
*ndlp
;
6513 uint32_t cmd
, did
, newnode
, rjt_err
= 0;
6514 IOCB_t
*icmd
= &elsiocb
->iocb
;
6516 if (!vport
|| !(elsiocb
->context2
))
6520 payload
= ((struct lpfc_dmabuf
*)elsiocb
->context2
)->virt
;
6522 if ((phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) == 0)
6523 lpfc_post_buffer(phba
, pring
, 1);
6525 did
= icmd
->un
.rcvels
.remoteID
;
6526 if (icmd
->ulpStatus
) {
6527 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6528 "RCV Unsol ELS: status:x%x/x%x did:x%x",
6529 icmd
->ulpStatus
, icmd
->un
.ulpWord
[4], did
);
6533 /* Check to see if link went down during discovery */
6534 if (lpfc_els_chk_latt(vport
))
6537 /* Ignore traffic received during vport shutdown. */
6538 if (vport
->load_flag
& FC_UNLOADING
)
6541 /* If NPort discovery is delayed drop incoming ELS */
6542 if ((vport
->fc_flag
& FC_DISC_DELAYED
) &&
6543 (cmd
!= ELS_CMD_PLOGI
))
6546 ndlp
= lpfc_findnode_did(vport
, did
);
6548 /* Cannot find existing Fabric ndlp, so allocate a new one */
6549 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
6553 lpfc_nlp_init(vport
, ndlp
, did
);
6554 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
6556 if ((did
& Fabric_DID_MASK
) == Fabric_DID_MASK
)
6557 ndlp
->nlp_type
|= NLP_FABRIC
;
6558 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
6559 ndlp
= lpfc_enable_node(vport
, ndlp
,
6560 NLP_STE_UNUSED_NODE
);
6563 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
6565 if ((did
& Fabric_DID_MASK
) == Fabric_DID_MASK
)
6566 ndlp
->nlp_type
|= NLP_FABRIC
;
6567 } else if (ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
) {
6568 /* This is similar to the new node path */
6569 ndlp
= lpfc_nlp_get(ndlp
);
6572 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
6576 phba
->fc_stat
.elsRcvFrame
++;
6578 elsiocb
->context1
= lpfc_nlp_get(ndlp
);
6579 elsiocb
->vport
= vport
;
6581 if ((cmd
& ELS_CMD_MASK
) == ELS_CMD_RSCN
) {
6582 cmd
&= ELS_CMD_MASK
;
6584 /* ELS command <elsCmd> received from NPORT <did> */
6585 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
6586 "0112 ELS command x%x received from NPORT x%x "
6587 "Data: x%x\n", cmd
, did
, vport
->port_state
);
6590 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6591 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
6592 did
, vport
->port_state
, ndlp
->nlp_flag
);
6594 phba
->fc_stat
.elsRcvPLOGI
++;
6595 ndlp
= lpfc_plogi_confirm_nport(phba
, payload
, ndlp
);
6597 lpfc_send_els_event(vport
, ndlp
, payload
);
6599 /* If Nport discovery is delayed, reject PLOGIs */
6600 if (vport
->fc_flag
& FC_DISC_DELAYED
) {
6601 rjt_err
= LSRJT_UNABLE_TPC
;
6604 if (vport
->port_state
< LPFC_DISC_AUTH
) {
6605 if (!(phba
->pport
->fc_flag
& FC_PT2PT
) ||
6606 (phba
->pport
->fc_flag
& FC_PT2PT_PLOGI
)) {
6607 rjt_err
= LSRJT_UNABLE_TPC
;
6610 /* We get here, and drop thru, if we are PT2PT with
6611 * another NPort and the other side has initiated
6612 * the PLOGI before responding to our FLOGI.
6616 shost
= lpfc_shost_from_vport(vport
);
6617 spin_lock_irq(shost
->host_lock
);
6618 ndlp
->nlp_flag
&= ~NLP_TARGET_REMOVE
;
6619 spin_unlock_irq(shost
->host_lock
);
6621 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
,
6626 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6627 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
6628 did
, vport
->port_state
, ndlp
->nlp_flag
);
6630 phba
->fc_stat
.elsRcvFLOGI
++;
6631 lpfc_els_rcv_flogi(vport
, elsiocb
, ndlp
);
6636 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6637 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
6638 did
, vport
->port_state
, ndlp
->nlp_flag
);
6640 phba
->fc_stat
.elsRcvLOGO
++;
6641 lpfc_send_els_event(vport
, ndlp
, payload
);
6642 if (vport
->port_state
< LPFC_DISC_AUTH
) {
6643 rjt_err
= LSRJT_UNABLE_TPC
;
6646 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
, NLP_EVT_RCV_LOGO
);
6649 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6650 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
6651 did
, vport
->port_state
, ndlp
->nlp_flag
);
6653 phba
->fc_stat
.elsRcvPRLO
++;
6654 lpfc_send_els_event(vport
, ndlp
, payload
);
6655 if (vport
->port_state
< LPFC_DISC_AUTH
) {
6656 rjt_err
= LSRJT_UNABLE_TPC
;
6659 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
, NLP_EVT_RCV_PRLO
);
6662 phba
->fc_stat
.elsRcvRSCN
++;
6663 lpfc_els_rcv_rscn(vport
, elsiocb
, ndlp
);
6668 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6669 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
6670 did
, vport
->port_state
, ndlp
->nlp_flag
);
6672 lpfc_send_els_event(vport
, ndlp
, payload
);
6673 phba
->fc_stat
.elsRcvADISC
++;
6674 if (vport
->port_state
< LPFC_DISC_AUTH
) {
6675 rjt_err
= LSRJT_UNABLE_TPC
;
6678 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
,
6682 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6683 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
6684 did
, vport
->port_state
, ndlp
->nlp_flag
);
6686 phba
->fc_stat
.elsRcvPDISC
++;
6687 if (vport
->port_state
< LPFC_DISC_AUTH
) {
6688 rjt_err
= LSRJT_UNABLE_TPC
;
6691 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
,
6695 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6696 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
6697 did
, vport
->port_state
, ndlp
->nlp_flag
);
6699 phba
->fc_stat
.elsRcvFARPR
++;
6700 lpfc_els_rcv_farpr(vport
, elsiocb
, ndlp
);
6703 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6704 "RCV FARP: did:x%x/ste:x%x flg:x%x",
6705 did
, vport
->port_state
, ndlp
->nlp_flag
);
6707 phba
->fc_stat
.elsRcvFARP
++;
6708 lpfc_els_rcv_farp(vport
, elsiocb
, ndlp
);
6711 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6712 "RCV FAN: did:x%x/ste:x%x flg:x%x",
6713 did
, vport
->port_state
, ndlp
->nlp_flag
);
6715 phba
->fc_stat
.elsRcvFAN
++;
6716 lpfc_els_rcv_fan(vport
, elsiocb
, ndlp
);
6719 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6720 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
6721 did
, vport
->port_state
, ndlp
->nlp_flag
);
6723 phba
->fc_stat
.elsRcvPRLI
++;
6724 if (vport
->port_state
< LPFC_DISC_AUTH
) {
6725 rjt_err
= LSRJT_UNABLE_TPC
;
6728 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
, NLP_EVT_RCV_PRLI
);
6731 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6732 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
6733 did
, vport
->port_state
, ndlp
->nlp_flag
);
6735 phba
->fc_stat
.elsRcvLIRR
++;
6736 lpfc_els_rcv_lirr(vport
, elsiocb
, ndlp
);
6741 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6742 "RCV RLS: did:x%x/ste:x%x flg:x%x",
6743 did
, vport
->port_state
, ndlp
->nlp_flag
);
6745 phba
->fc_stat
.elsRcvRLS
++;
6746 lpfc_els_rcv_rls(vport
, elsiocb
, ndlp
);
6751 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6752 "RCV RPS: did:x%x/ste:x%x flg:x%x",
6753 did
, vport
->port_state
, ndlp
->nlp_flag
);
6755 phba
->fc_stat
.elsRcvRPS
++;
6756 lpfc_els_rcv_rps(vport
, elsiocb
, ndlp
);
6761 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6762 "RCV RPL: did:x%x/ste:x%x flg:x%x",
6763 did
, vport
->port_state
, ndlp
->nlp_flag
);
6765 phba
->fc_stat
.elsRcvRPL
++;
6766 lpfc_els_rcv_rpl(vport
, elsiocb
, ndlp
);
6771 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6772 "RCV RNID: did:x%x/ste:x%x flg:x%x",
6773 did
, vport
->port_state
, ndlp
->nlp_flag
);
6775 phba
->fc_stat
.elsRcvRNID
++;
6776 lpfc_els_rcv_rnid(vport
, elsiocb
, ndlp
);
6781 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6782 "RCV RTV: did:x%x/ste:x%x flg:x%x",
6783 did
, vport
->port_state
, ndlp
->nlp_flag
);
6784 phba
->fc_stat
.elsRcvRTV
++;
6785 lpfc_els_rcv_rtv(vport
, elsiocb
, ndlp
);
6790 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6791 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
6792 did
, vport
->port_state
, ndlp
->nlp_flag
);
6794 phba
->fc_stat
.elsRcvRRQ
++;
6795 lpfc_els_rcv_rrq(vport
, elsiocb
, ndlp
);
6800 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6801 "RCV ECHO: did:x%x/ste:x%x flg:x%x",
6802 did
, vport
->port_state
, ndlp
->nlp_flag
);
6804 phba
->fc_stat
.elsRcvECHO
++;
6805 lpfc_els_rcv_echo(vport
, elsiocb
, ndlp
);
6810 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6811 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
6812 cmd
, did
, vport
->port_state
);
6814 /* Unsupported ELS command, reject */
6815 rjt_err
= LSRJT_CMD_UNSUPPORTED
;
6817 /* Unknown ELS command <elsCmd> received from NPORT <did> */
6818 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
6819 "0115 Unknown ELS command x%x "
6820 "received from NPORT x%x\n", cmd
, did
);
6826 /* check if need to LS_RJT received ELS cmd */
6828 memset(&stat
, 0, sizeof(stat
));
6829 stat
.un
.b
.lsRjtRsnCode
= rjt_err
;
6830 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_NOTHING_MORE
;
6831 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, elsiocb
, ndlp
,
6835 lpfc_nlp_put(elsiocb
->context1
);
6836 elsiocb
->context1
= NULL
;
6840 if (vport
&& !(vport
->load_flag
& FC_UNLOADING
))
6841 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
6842 "0111 Dropping received ELS cmd "
6843 "Data: x%x x%x x%x\n",
6844 icmd
->ulpStatus
, icmd
->un
.ulpWord
[4], icmd
->ulpTimeout
);
6845 phba
->fc_stat
.elsRcvDrop
++;
6849 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
6850 * @phba: pointer to lpfc hba data structure.
6851 * @pring: pointer to a SLI ring.
6852 * @elsiocb: pointer to lpfc els iocb data structure.
6854 * This routine is used to process an unsolicited event received from a SLI
6855 * (Service Level Interface) ring. The actual processing of the data buffer
6856 * associated with the unsolicited event is done by invoking the routine
6857 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
6858 * SLI ring on which the unsolicited event was received.
6861 lpfc_els_unsol_event(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
6862 struct lpfc_iocbq
*elsiocb
)
6864 struct lpfc_vport
*vport
= phba
->pport
;
6865 IOCB_t
*icmd
= &elsiocb
->iocb
;
6867 struct lpfc_dmabuf
*bdeBuf1
= elsiocb
->context2
;
6868 struct lpfc_dmabuf
*bdeBuf2
= elsiocb
->context3
;
6870 elsiocb
->context1
= NULL
;
6871 elsiocb
->context2
= NULL
;
6872 elsiocb
->context3
= NULL
;
6874 if (icmd
->ulpStatus
== IOSTAT_NEED_BUFFER
) {
6875 lpfc_sli_hbqbuf_add_hbqs(phba
, LPFC_ELS_HBQ
);
6876 } else if (icmd
->ulpStatus
== IOSTAT_LOCAL_REJECT
&&
6877 (icmd
->un
.ulpWord
[4] & IOERR_PARAM_MASK
) ==
6878 IOERR_RCV_BUFFER_WAITING
) {
6879 phba
->fc_stat
.NoRcvBuf
++;
6880 /* Not enough posted buffers; Try posting more buffers */
6881 if (!(phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
))
6882 lpfc_post_buffer(phba
, pring
, 0);
6886 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
6887 (icmd
->ulpCommand
== CMD_IOCB_RCV_ELS64_CX
||
6888 icmd
->ulpCommand
== CMD_IOCB_RCV_SEQ64_CX
)) {
6889 if (icmd
->unsli3
.rcvsli3
.vpi
== 0xffff)
6890 vport
= phba
->pport
;
6892 vport
= lpfc_find_vport_by_vpid(phba
,
6893 icmd
->unsli3
.rcvsli3
.vpi
);
6896 /* If there are no BDEs associated
6897 * with this IOCB, there is nothing to do.
6899 if (icmd
->ulpBdeCount
== 0)
6902 /* type of ELS cmd is first 32bit word
6905 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) {
6906 elsiocb
->context2
= bdeBuf1
;
6908 paddr
= getPaddr(icmd
->un
.cont64
[0].addrHigh
,
6909 icmd
->un
.cont64
[0].addrLow
);
6910 elsiocb
->context2
= lpfc_sli_ringpostbuf_get(phba
, pring
,
6914 lpfc_els_unsol_buffer(phba
, pring
, vport
, elsiocb
);
6916 * The different unsolicited event handlers would tell us
6917 * if they are done with "mp" by setting context2 to NULL.
6919 if (elsiocb
->context2
) {
6920 lpfc_in_buf_free(phba
, (struct lpfc_dmabuf
*)elsiocb
->context2
);
6921 elsiocb
->context2
= NULL
;
6924 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
6925 if ((phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) &&
6926 icmd
->ulpBdeCount
== 2) {
6927 elsiocb
->context2
= bdeBuf2
;
6928 lpfc_els_unsol_buffer(phba
, pring
, vport
, elsiocb
);
6929 /* free mp if we are done with it */
6930 if (elsiocb
->context2
) {
6931 lpfc_in_buf_free(phba
, elsiocb
->context2
);
6932 elsiocb
->context2
= NULL
;
6938 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
6939 * @phba: pointer to lpfc hba data structure.
6940 * @vport: pointer to a virtual N_Port data structure.
6942 * This routine issues a Port Login (PLOGI) to the Name Server with
6943 * State Change Request (SCR) for a @vport. This routine will create an
6944 * ndlp for the Name Server associated to the @vport if such node does
6945 * not already exist. The PLOGI to Name Server is issued by invoking the
6946 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
6947 * (FDMI) is configured to the @vport, a FDMI node will be created and
6948 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
6951 lpfc_do_scr_ns_plogi(struct lpfc_hba
*phba
, struct lpfc_vport
*vport
)
6953 struct lpfc_nodelist
*ndlp
, *ndlp_fdmi
;
6954 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
6957 * If lpfc_delay_discovery parameter is set and the clean address
6958 * bit is cleared and fc fabric parameters chenged, delay FC NPort
6961 spin_lock_irq(shost
->host_lock
);
6962 if (vport
->fc_flag
& FC_DISC_DELAYED
) {
6963 spin_unlock_irq(shost
->host_lock
);
6964 mod_timer(&vport
->delayed_disc_tmo
,
6965 jiffies
+ HZ
* phba
->fc_ratov
);
6968 spin_unlock_irq(shost
->host_lock
);
6970 ndlp
= lpfc_findnode_did(vport
, NameServer_DID
);
6972 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
6974 if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) {
6975 lpfc_disc_start(vport
);
6978 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
6979 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
6980 "0251 NameServer login: no memory\n");
6983 lpfc_nlp_init(vport
, ndlp
, NameServer_DID
);
6984 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
6985 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
6987 if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) {
6988 lpfc_disc_start(vport
);
6991 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
6992 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
6993 "0348 NameServer login: node freed\n");
6997 ndlp
->nlp_type
|= NLP_FABRIC
;
6999 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
7001 if (lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0)) {
7002 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
7003 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
7004 "0252 Cannot issue NameServer login\n");
7008 if (vport
->cfg_fdmi_on
) {
7009 /* If this is the first time, allocate an ndlp and initialize
7010 * it. Otherwise, make sure the node is enabled and then do the
7013 ndlp_fdmi
= lpfc_findnode_did(vport
, FDMI_DID
);
7015 ndlp_fdmi
= mempool_alloc(phba
->nlp_mem_pool
,
7018 lpfc_nlp_init(vport
, ndlp_fdmi
, FDMI_DID
);
7019 ndlp_fdmi
->nlp_type
|= NLP_FABRIC
;
7023 if (!NLP_CHK_NODE_ACT(ndlp_fdmi
))
7024 ndlp_fdmi
= lpfc_enable_node(vport
,
7029 lpfc_nlp_set_state(vport
, ndlp_fdmi
,
7030 NLP_STE_PLOGI_ISSUE
);
7031 lpfc_issue_els_plogi(vport
, ndlp_fdmi
->nlp_DID
, 0);
7037 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
7038 * @phba: pointer to lpfc hba data structure.
7039 * @pmb: pointer to the driver internal queue element for mailbox command.
7041 * This routine is the completion callback function to register new vport
7042 * mailbox command. If the new vport mailbox command completes successfully,
7043 * the fabric registration login shall be performed on physical port (the
7044 * new vport created is actually a physical port, with VPI 0) or the port
7045 * login to Name Server for State Change Request (SCR) will be performed
7046 * on virtual port (real virtual port, with VPI greater than 0).
7049 lpfc_cmpl_reg_new_vport(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
7051 struct lpfc_vport
*vport
= pmb
->vport
;
7052 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
7053 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
7054 MAILBOX_t
*mb
= &pmb
->u
.mb
;
7057 spin_lock_irq(shost
->host_lock
);
7058 vport
->fc_flag
&= ~FC_VPORT_NEEDS_REG_VPI
;
7059 spin_unlock_irq(shost
->host_lock
);
7061 if (mb
->mbxStatus
) {
7062 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
7063 "0915 Register VPI failed : Status: x%x"
7064 " upd bit: x%x \n", mb
->mbxStatus
,
7065 mb
->un
.varRegVpi
.upd
);
7066 if (phba
->sli_rev
== LPFC_SLI_REV4
&&
7067 mb
->un
.varRegVpi
.upd
)
7068 goto mbox_err_exit
;
7070 switch (mb
->mbxStatus
) {
7071 case 0x11: /* unsupported feature */
7072 case 0x9603: /* max_vpi exceeded */
7073 case 0x9602: /* Link event since CLEAR_LA */
7074 /* giving up on vport registration */
7075 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
7076 spin_lock_irq(shost
->host_lock
);
7077 vport
->fc_flag
&= ~(FC_FABRIC
| FC_PUBLIC_LOOP
);
7078 spin_unlock_irq(shost
->host_lock
);
7079 lpfc_can_disctmo(vport
);
7081 /* If reg_vpi fail with invalid VPI status, re-init VPI */
7083 spin_lock_irq(shost
->host_lock
);
7084 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
7085 spin_unlock_irq(shost
->host_lock
);
7086 lpfc_init_vpi(phba
, pmb
, vport
->vpi
);
7088 pmb
->mbox_cmpl
= lpfc_init_vpi_cmpl
;
7089 rc
= lpfc_sli_issue_mbox(phba
, pmb
,
7091 if (rc
== MBX_NOT_FINISHED
) {
7092 lpfc_printf_vlog(vport
,
7094 "2732 Failed to issue INIT_VPI"
7095 " mailbox command\n");
7102 /* Try to recover from this error */
7103 if (phba
->sli_rev
== LPFC_SLI_REV4
)
7104 lpfc_sli4_unreg_all_rpis(vport
);
7105 lpfc_mbx_unreg_vpi(vport
);
7106 spin_lock_irq(shost
->host_lock
);
7107 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
7108 spin_unlock_irq(shost
->host_lock
);
7109 if (vport
->port_type
== LPFC_PHYSICAL_PORT
7110 && !(vport
->fc_flag
& FC_LOGO_RCVD_DID_CHNG
))
7111 lpfc_issue_init_vfi(vport
);
7113 lpfc_initial_fdisc(vport
);
7117 spin_lock_irq(shost
->host_lock
);
7118 vport
->vpi_state
|= LPFC_VPI_REGISTERED
;
7119 spin_unlock_irq(shost
->host_lock
);
7120 if (vport
== phba
->pport
) {
7121 if (phba
->sli_rev
< LPFC_SLI_REV4
)
7122 lpfc_issue_fabric_reglogin(vport
);
7125 * If the physical port is instantiated using
7126 * FDISC, do not start vport discovery.
7128 if (vport
->port_state
!= LPFC_FDISC
)
7129 lpfc_start_fdiscs(phba
);
7130 lpfc_do_scr_ns_plogi(phba
, vport
);
7133 lpfc_do_scr_ns_plogi(phba
, vport
);
7136 /* Now, we decrement the ndlp reference count held for this
7141 mempool_free(pmb
, phba
->mbox_mem_pool
);
7146 * lpfc_register_new_vport - Register a new vport with a HBA
7147 * @phba: pointer to lpfc hba data structure.
7148 * @vport: pointer to a host virtual N_Port data structure.
7149 * @ndlp: pointer to a node-list data structure.
7151 * This routine registers the @vport as a new virtual port with a HBA.
7152 * It is done through a registering vpi mailbox command.
7155 lpfc_register_new_vport(struct lpfc_hba
*phba
, struct lpfc_vport
*vport
,
7156 struct lpfc_nodelist
*ndlp
)
7158 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
7161 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
7163 lpfc_reg_vpi(vport
, mbox
);
7164 mbox
->vport
= vport
;
7165 mbox
->context2
= lpfc_nlp_get(ndlp
);
7166 mbox
->mbox_cmpl
= lpfc_cmpl_reg_new_vport
;
7167 if (lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
)
7168 == MBX_NOT_FINISHED
) {
7169 /* mailbox command not success, decrement ndlp
7170 * reference count for this command
7173 mempool_free(mbox
, phba
->mbox_mem_pool
);
7175 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
7176 "0253 Register VPI: Can't send mbox\n");
7180 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
7181 "0254 Register VPI: no memory\n");
7187 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
7188 spin_lock_irq(shost
->host_lock
);
7189 vport
->fc_flag
&= ~FC_VPORT_NEEDS_REG_VPI
;
7190 spin_unlock_irq(shost
->host_lock
);
7195 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
7196 * @phba: pointer to lpfc hba data structure.
7198 * This routine cancels the retry delay timers to all the vports.
7201 lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba
*phba
)
7203 struct lpfc_vport
**vports
;
7204 struct lpfc_nodelist
*ndlp
;
7205 uint32_t link_state
;
7208 /* Treat this failure as linkdown for all vports */
7209 link_state
= phba
->link_state
;
7210 lpfc_linkdown(phba
);
7211 phba
->link_state
= link_state
;
7213 vports
= lpfc_create_vport_work_array(phba
);
7216 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
7217 ndlp
= lpfc_findnode_did(vports
[i
], Fabric_DID
);
7219 lpfc_cancel_retry_delay_tmo(vports
[i
], ndlp
);
7220 lpfc_els_flush_cmd(vports
[i
]);
7222 lpfc_destroy_vport_work_array(phba
, vports
);
7227 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
7228 * @phba: pointer to lpfc hba data structure.
7230 * This routine abort all pending discovery commands and
7231 * start a timer to retry FLOGI for the physical port
7235 lpfc_retry_pport_discovery(struct lpfc_hba
*phba
)
7237 struct lpfc_nodelist
*ndlp
;
7238 struct Scsi_Host
*shost
;
7240 /* Cancel the all vports retry delay retry timers */
7241 lpfc_cancel_all_vport_retry_delay_timer(phba
);
7243 /* If fabric require FLOGI, then re-instantiate physical login */
7244 ndlp
= lpfc_findnode_did(phba
->pport
, Fabric_DID
);
7248 shost
= lpfc_shost_from_vport(phba
->pport
);
7249 mod_timer(&ndlp
->nlp_delayfunc
, jiffies
+ HZ
);
7250 spin_lock_irq(shost
->host_lock
);
7251 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
7252 spin_unlock_irq(shost
->host_lock
);
7253 ndlp
->nlp_last_elscmd
= ELS_CMD_FLOGI
;
7254 phba
->pport
->port_state
= LPFC_FLOGI
;
7259 * lpfc_fabric_login_reqd - Check if FLOGI required.
7260 * @phba: pointer to lpfc hba data structure.
7261 * @cmdiocb: pointer to FDISC command iocb.
7262 * @rspiocb: pointer to FDISC response iocb.
7264 * This routine checks if a FLOGI is reguired for FDISC
7268 lpfc_fabric_login_reqd(struct lpfc_hba
*phba
,
7269 struct lpfc_iocbq
*cmdiocb
,
7270 struct lpfc_iocbq
*rspiocb
)
7273 if ((rspiocb
->iocb
.ulpStatus
!= IOSTAT_FABRIC_RJT
) ||
7274 (rspiocb
->iocb
.un
.ulpWord
[4] != RJT_LOGIN_REQUIRED
))
7281 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
7282 * @phba: pointer to lpfc hba data structure.
7283 * @cmdiocb: pointer to lpfc command iocb data structure.
7284 * @rspiocb: pointer to lpfc response iocb data structure.
7286 * This routine is the completion callback function to a Fabric Discover
7287 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
7288 * single threaded, each FDISC completion callback function will reset
7289 * the discovery timer for all vports such that the timers will not get
7290 * unnecessary timeout. The function checks the FDISC IOCB status. If error
7291 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
7292 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
7293 * assigned to the vport has been changed with the completion of the FDISC
7294 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
7295 * are unregistered from the HBA, and then the lpfc_register_new_vport()
7296 * routine is invoked to register new vport with the HBA. Otherwise, the
7297 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
7298 * Server for State Change Request (SCR).
7301 lpfc_cmpl_els_fdisc(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
7302 struct lpfc_iocbq
*rspiocb
)
7304 struct lpfc_vport
*vport
= cmdiocb
->vport
;
7305 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
7306 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
7307 struct lpfc_nodelist
*np
;
7308 struct lpfc_nodelist
*next_np
;
7309 IOCB_t
*irsp
= &rspiocb
->iocb
;
7310 struct lpfc_iocbq
*piocb
;
7311 struct lpfc_dmabuf
*pcmd
= cmdiocb
->context2
, *prsp
;
7312 struct serv_parm
*sp
;
7313 uint8_t fabric_param_changed
;
7315 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
7316 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
7317 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
7319 /* Since all FDISCs are being single threaded, we
7320 * must reset the discovery timer for ALL vports
7321 * waiting to send FDISC when one completes.
7323 list_for_each_entry(piocb
, &phba
->fabric_iocb_list
, list
) {
7324 lpfc_set_disctmo(piocb
->vport
);
7327 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
7328 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
7329 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4], vport
->fc_prevDID
);
7331 if (irsp
->ulpStatus
) {
7333 if (lpfc_fabric_login_reqd(phba
, cmdiocb
, rspiocb
)) {
7334 lpfc_retry_pport_discovery(phba
);
7338 /* Check for retry */
7339 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
))
7342 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
7343 "0126 FDISC failed. (x%x/x%x)\n",
7344 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4]);
7347 spin_lock_irq(shost
->host_lock
);
7348 vport
->fc_flag
&= ~FC_VPORT_CVL_RCVD
;
7349 vport
->fc_flag
&= ~FC_VPORT_LOGO_RCVD
;
7350 vport
->fc_flag
|= FC_FABRIC
;
7351 if (vport
->phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
)
7352 vport
->fc_flag
|= FC_PUBLIC_LOOP
;
7353 spin_unlock_irq(shost
->host_lock
);
7355 vport
->fc_myDID
= irsp
->un
.ulpWord
[4] & Mask_DID
;
7356 lpfc_vport_set_state(vport
, FC_VPORT_ACTIVE
);
7357 prsp
= list_get_first(&pcmd
->list
, struct lpfc_dmabuf
, list
);
7358 sp
= prsp
->virt
+ sizeof(uint32_t);
7359 fabric_param_changed
= lpfc_check_clean_addr_bit(vport
, sp
);
7360 memcpy(&vport
->fabric_portname
, &sp
->portName
,
7361 sizeof(struct lpfc_name
));
7362 memcpy(&vport
->fabric_nodename
, &sp
->nodeName
,
7363 sizeof(struct lpfc_name
));
7364 if (fabric_param_changed
&&
7365 !(vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
)) {
7366 /* If our NportID changed, we need to ensure all
7367 * remaining NPORTs get unreg_login'ed so we can
7370 list_for_each_entry_safe(np
, next_np
,
7371 &vport
->fc_nodes
, nlp_listp
) {
7372 if (!NLP_CHK_NODE_ACT(ndlp
) ||
7373 (np
->nlp_state
!= NLP_STE_NPR_NODE
) ||
7374 !(np
->nlp_flag
& NLP_NPR_ADISC
))
7376 spin_lock_irq(shost
->host_lock
);
7377 np
->nlp_flag
&= ~NLP_NPR_ADISC
;
7378 spin_unlock_irq(shost
->host_lock
);
7379 lpfc_unreg_rpi(vport
, np
);
7381 lpfc_cleanup_pending_mbox(vport
);
7383 if (phba
->sli_rev
== LPFC_SLI_REV4
)
7384 lpfc_sli4_unreg_all_rpis(vport
);
7386 lpfc_mbx_unreg_vpi(vport
);
7387 spin_lock_irq(shost
->host_lock
);
7388 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
7389 if (phba
->sli_rev
== LPFC_SLI_REV4
)
7390 vport
->fc_flag
|= FC_VPORT_NEEDS_INIT_VPI
;
7392 vport
->fc_flag
|= FC_LOGO_RCVD_DID_CHNG
;
7393 spin_unlock_irq(shost
->host_lock
);
7394 } else if ((phba
->sli_rev
== LPFC_SLI_REV4
) &&
7395 !(vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
)) {
7397 * Driver needs to re-reg VPI in order for f/w
7398 * to update the MAC address.
7400 lpfc_register_new_vport(phba
, vport
, ndlp
);
7404 if (vport
->fc_flag
& FC_VPORT_NEEDS_INIT_VPI
)
7405 lpfc_issue_init_vpi(vport
);
7406 else if (vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
)
7407 lpfc_register_new_vport(phba
, vport
, ndlp
);
7409 lpfc_do_scr_ns_plogi(phba
, vport
);
7412 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
7413 /* Cancel discovery timer */
7414 lpfc_can_disctmo(vport
);
7417 lpfc_els_free_iocb(phba
, cmdiocb
);
7421 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
7422 * @vport: pointer to a virtual N_Port data structure.
7423 * @ndlp: pointer to a node-list data structure.
7424 * @retry: number of retries to the command IOCB.
7426 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
7427 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
7428 * routine to issue the IOCB, which makes sure only one outstanding fabric
7429 * IOCB will be sent off HBA at any given time.
7431 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7432 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7433 * will be stored into the context1 field of the IOCB for the completion
7434 * callback function to the FDISC ELS command.
7437 * 0 - Successfully issued fdisc iocb command
7438 * 1 - Failed to issue fdisc iocb command
7441 lpfc_issue_els_fdisc(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
7444 struct lpfc_hba
*phba
= vport
->phba
;
7446 struct lpfc_iocbq
*elsiocb
;
7447 struct serv_parm
*sp
;
7450 int did
= ndlp
->nlp_DID
;
7453 vport
->port_state
= LPFC_FDISC
;
7454 vport
->fc_myDID
= 0;
7455 cmdsize
= (sizeof(uint32_t) + sizeof(struct serv_parm
));
7456 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
, did
,
7459 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
7460 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
7461 "0255 Issue FDISC: no IOCB\n");
7465 icmd
= &elsiocb
->iocb
;
7466 icmd
->un
.elsreq64
.myID
= 0;
7467 icmd
->un
.elsreq64
.fl
= 1;
7470 * SLI3 ports require a different context type value than SLI4.
7471 * Catch SLI3 ports here and override the prep.
7473 if (phba
->sli_rev
== LPFC_SLI_REV3
) {
7478 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
7479 *((uint32_t *) (pcmd
)) = ELS_CMD_FDISC
;
7480 pcmd
+= sizeof(uint32_t); /* CSP Word 1 */
7481 memcpy(pcmd
, &vport
->phba
->pport
->fc_sparam
, sizeof(struct serv_parm
));
7482 sp
= (struct serv_parm
*) pcmd
;
7483 /* Setup CSPs accordingly for Fabric */
7484 sp
->cmn
.e_d_tov
= 0;
7485 sp
->cmn
.w2
.r_a_tov
= 0;
7486 sp
->cmn
.virtual_fabric_support
= 0;
7487 sp
->cls1
.classValid
= 0;
7488 sp
->cls2
.seqDelivery
= 1;
7489 sp
->cls3
.seqDelivery
= 1;
7491 pcmd
+= sizeof(uint32_t); /* CSP Word 2 */
7492 pcmd
+= sizeof(uint32_t); /* CSP Word 3 */
7493 pcmd
+= sizeof(uint32_t); /* CSP Word 4 */
7494 pcmd
+= sizeof(uint32_t); /* Port Name */
7495 memcpy(pcmd
, &vport
->fc_portname
, 8);
7496 pcmd
+= sizeof(uint32_t); /* Node Name */
7497 pcmd
+= sizeof(uint32_t); /* Node Name */
7498 memcpy(pcmd
, &vport
->fc_nodename
, 8);
7500 lpfc_set_disctmo(vport
);
7502 phba
->fc_stat
.elsXmitFDISC
++;
7503 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_fdisc
;
7505 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
7506 "Issue FDISC: did:x%x",
7509 rc
= lpfc_issue_fabric_iocb(phba
, elsiocb
);
7510 if (rc
== IOCB_ERROR
) {
7511 lpfc_els_free_iocb(phba
, elsiocb
);
7512 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
7513 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
7514 "0256 Issue FDISC: Cannot send IOCB\n");
7517 lpfc_vport_set_state(vport
, FC_VPORT_INITIALIZING
);
7522 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
7523 * @phba: pointer to lpfc hba data structure.
7524 * @cmdiocb: pointer to lpfc command iocb data structure.
7525 * @rspiocb: pointer to lpfc response iocb data structure.
7527 * This routine is the completion callback function to the issuing of a LOGO
7528 * ELS command off a vport. It frees the command IOCB and then decrement the
7529 * reference count held on ndlp for this completion function, indicating that
7530 * the reference to the ndlp is no long needed. Note that the
7531 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
7532 * callback function and an additional explicit ndlp reference decrementation
7533 * will trigger the actual release of the ndlp.
7536 lpfc_cmpl_els_npiv_logo(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
7537 struct lpfc_iocbq
*rspiocb
)
7539 struct lpfc_vport
*vport
= cmdiocb
->vport
;
7541 struct lpfc_nodelist
*ndlp
;
7542 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
7544 ndlp
= (struct lpfc_nodelist
*)cmdiocb
->context1
;
7545 irsp
= &rspiocb
->iocb
;
7546 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
7547 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
7548 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4], irsp
->un
.rcvels
.remoteID
);
7550 lpfc_els_free_iocb(phba
, cmdiocb
);
7551 vport
->unreg_vpi_cmpl
= VPORT_ERROR
;
7553 /* Trigger the release of the ndlp after logo */
7556 /* NPIV LOGO completes to NPort <nlp_DID> */
7557 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
7558 "2928 NPIV LOGO completes to NPort x%x "
7559 "Data: x%x x%x x%x x%x\n",
7560 ndlp
->nlp_DID
, irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
7561 irsp
->ulpTimeout
, vport
->num_disc_nodes
);
7563 if (irsp
->ulpStatus
== IOSTAT_SUCCESS
) {
7564 spin_lock_irq(shost
->host_lock
);
7565 vport
->fc_flag
&= ~FC_FABRIC
;
7566 spin_unlock_irq(shost
->host_lock
);
7571 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
7572 * @vport: pointer to a virtual N_Port data structure.
7573 * @ndlp: pointer to a node-list data structure.
7575 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
7577 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7578 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7579 * will be stored into the context1 field of the IOCB for the completion
7580 * callback function to the LOGO ELS command.
7583 * 0 - Successfully issued logo off the @vport
7584 * 1 - Failed to issue logo off the @vport
7587 lpfc_issue_els_npiv_logo(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
7589 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
7590 struct lpfc_hba
*phba
= vport
->phba
;
7592 struct lpfc_iocbq
*elsiocb
;
7596 cmdsize
= 2 * sizeof(uint32_t) + sizeof(struct lpfc_name
);
7597 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, 0, ndlp
, ndlp
->nlp_DID
,
7602 icmd
= &elsiocb
->iocb
;
7603 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
7604 *((uint32_t *) (pcmd
)) = ELS_CMD_LOGO
;
7605 pcmd
+= sizeof(uint32_t);
7607 /* Fill in LOGO payload */
7608 *((uint32_t *) (pcmd
)) = be32_to_cpu(vport
->fc_myDID
);
7609 pcmd
+= sizeof(uint32_t);
7610 memcpy(pcmd
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
7612 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
7613 "Issue LOGO npiv did:x%x flg:x%x",
7614 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
7616 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_npiv_logo
;
7617 spin_lock_irq(shost
->host_lock
);
7618 ndlp
->nlp_flag
|= NLP_LOGO_SND
;
7619 spin_unlock_irq(shost
->host_lock
);
7620 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) ==
7622 spin_lock_irq(shost
->host_lock
);
7623 ndlp
->nlp_flag
&= ~NLP_LOGO_SND
;
7624 spin_unlock_irq(shost
->host_lock
);
7625 lpfc_els_free_iocb(phba
, elsiocb
);
7632 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
7633 * @ptr: holder for the timer function associated data.
7635 * This routine is invoked by the fabric iocb block timer after
7636 * timeout. It posts the fabric iocb block timeout event by setting the
7637 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
7638 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
7639 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
7640 * posted event WORKER_FABRIC_BLOCK_TMO.
7643 lpfc_fabric_block_timeout(unsigned long ptr
)
7645 struct lpfc_hba
*phba
= (struct lpfc_hba
*) ptr
;
7646 unsigned long iflags
;
7647 uint32_t tmo_posted
;
7649 spin_lock_irqsave(&phba
->pport
->work_port_lock
, iflags
);
7650 tmo_posted
= phba
->pport
->work_port_events
& WORKER_FABRIC_BLOCK_TMO
;
7652 phba
->pport
->work_port_events
|= WORKER_FABRIC_BLOCK_TMO
;
7653 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, iflags
);
7656 lpfc_worker_wake_up(phba
);
7661 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
7662 * @phba: pointer to lpfc hba data structure.
7664 * This routine issues one fabric iocb from the driver internal list to
7665 * the HBA. It first checks whether it's ready to issue one fabric iocb to
7666 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
7667 * remove one pending fabric iocb from the driver internal list and invokes
7668 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
7671 lpfc_resume_fabric_iocbs(struct lpfc_hba
*phba
)
7673 struct lpfc_iocbq
*iocb
;
7674 unsigned long iflags
;
7680 spin_lock_irqsave(&phba
->hbalock
, iflags
);
7681 /* Post any pending iocb to the SLI layer */
7682 if (atomic_read(&phba
->fabric_iocb_count
) == 0) {
7683 list_remove_head(&phba
->fabric_iocb_list
, iocb
, typeof(*iocb
),
7686 /* Increment fabric iocb count to hold the position */
7687 atomic_inc(&phba
->fabric_iocb_count
);
7689 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7691 iocb
->fabric_iocb_cmpl
= iocb
->iocb_cmpl
;
7692 iocb
->iocb_cmpl
= lpfc_cmpl_fabric_iocb
;
7693 iocb
->iocb_flag
|= LPFC_IO_FABRIC
;
7695 lpfc_debugfs_disc_trc(iocb
->vport
, LPFC_DISC_TRC_ELS_CMD
,
7696 "Fabric sched1: ste:x%x",
7697 iocb
->vport
->port_state
, 0, 0);
7699 ret
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, iocb
, 0);
7701 if (ret
== IOCB_ERROR
) {
7702 iocb
->iocb_cmpl
= iocb
->fabric_iocb_cmpl
;
7703 iocb
->fabric_iocb_cmpl
= NULL
;
7704 iocb
->iocb_flag
&= ~LPFC_IO_FABRIC
;
7706 cmd
->ulpStatus
= IOSTAT_LOCAL_REJECT
;
7707 cmd
->un
.ulpWord
[4] = IOERR_SLI_ABORTED
;
7708 iocb
->iocb_cmpl(phba
, iocb
, iocb
);
7710 atomic_dec(&phba
->fabric_iocb_count
);
7719 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
7720 * @phba: pointer to lpfc hba data structure.
7722 * This routine unblocks the issuing fabric iocb command. The function
7723 * will clear the fabric iocb block bit and then invoke the routine
7724 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
7725 * from the driver internal fabric iocb list.
7728 lpfc_unblock_fabric_iocbs(struct lpfc_hba
*phba
)
7730 clear_bit(FABRIC_COMANDS_BLOCKED
, &phba
->bit_flags
);
7732 lpfc_resume_fabric_iocbs(phba
);
7737 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
7738 * @phba: pointer to lpfc hba data structure.
7740 * This routine blocks the issuing fabric iocb for a specified amount of
7741 * time (currently 100 ms). This is done by set the fabric iocb block bit
7742 * and set up a timeout timer for 100ms. When the block bit is set, no more
7743 * fabric iocb will be issued out of the HBA.
7746 lpfc_block_fabric_iocbs(struct lpfc_hba
*phba
)
7750 blocked
= test_and_set_bit(FABRIC_COMANDS_BLOCKED
, &phba
->bit_flags
);
7751 /* Start a timer to unblock fabric iocbs after 100ms */
7753 mod_timer(&phba
->fabric_block_timer
, jiffies
+ HZ
/10 );
7759 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
7760 * @phba: pointer to lpfc hba data structure.
7761 * @cmdiocb: pointer to lpfc command iocb data structure.
7762 * @rspiocb: pointer to lpfc response iocb data structure.
7764 * This routine is the callback function that is put to the fabric iocb's
7765 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
7766 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
7767 * function first restores and invokes the original iocb's callback function
7768 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
7769 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
7772 lpfc_cmpl_fabric_iocb(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
7773 struct lpfc_iocbq
*rspiocb
)
7777 if ((cmdiocb
->iocb_flag
& LPFC_IO_FABRIC
) != LPFC_IO_FABRIC
)
7780 switch (rspiocb
->iocb
.ulpStatus
) {
7781 case IOSTAT_NPORT_RJT
:
7782 case IOSTAT_FABRIC_RJT
:
7783 if (rspiocb
->iocb
.un
.ulpWord
[4] & RJT_UNAVAIL_TEMP
) {
7784 lpfc_block_fabric_iocbs(phba
);
7788 case IOSTAT_NPORT_BSY
:
7789 case IOSTAT_FABRIC_BSY
:
7790 lpfc_block_fabric_iocbs(phba
);
7794 stat
.un
.lsRjtError
=
7795 be32_to_cpu(rspiocb
->iocb
.un
.ulpWord
[4]);
7796 if ((stat
.un
.b
.lsRjtRsnCode
== LSRJT_UNABLE_TPC
) ||
7797 (stat
.un
.b
.lsRjtRsnCode
== LSRJT_LOGICAL_BSY
))
7798 lpfc_block_fabric_iocbs(phba
);
7802 if (atomic_read(&phba
->fabric_iocb_count
) == 0)
7805 cmdiocb
->iocb_cmpl
= cmdiocb
->fabric_iocb_cmpl
;
7806 cmdiocb
->fabric_iocb_cmpl
= NULL
;
7807 cmdiocb
->iocb_flag
&= ~LPFC_IO_FABRIC
;
7808 cmdiocb
->iocb_cmpl(phba
, cmdiocb
, rspiocb
);
7810 atomic_dec(&phba
->fabric_iocb_count
);
7811 if (!test_bit(FABRIC_COMANDS_BLOCKED
, &phba
->bit_flags
)) {
7812 /* Post any pending iocbs to HBA */
7813 lpfc_resume_fabric_iocbs(phba
);
7818 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
7819 * @phba: pointer to lpfc hba data structure.
7820 * @iocb: pointer to lpfc command iocb data structure.
7822 * This routine is used as the top-level API for issuing a fabric iocb command
7823 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
7824 * function makes sure that only one fabric bound iocb will be outstanding at
7825 * any given time. As such, this function will first check to see whether there
7826 * is already an outstanding fabric iocb on the wire. If so, it will put the
7827 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
7828 * issued later. Otherwise, it will issue the iocb on the wire and update the
7829 * fabric iocb count it indicate that there is one fabric iocb on the wire.
7831 * Note, this implementation has a potential sending out fabric IOCBs out of
7832 * order. The problem is caused by the construction of the "ready" boolen does
7833 * not include the condition that the internal fabric IOCB list is empty. As
7834 * such, it is possible a fabric IOCB issued by this routine might be "jump"
7835 * ahead of the fabric IOCBs in the internal list.
7838 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
7839 * IOCB_ERROR - failed to issue fabric iocb
7842 lpfc_issue_fabric_iocb(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocb
)
7844 unsigned long iflags
;
7848 if (atomic_read(&phba
->fabric_iocb_count
) > 1)
7851 spin_lock_irqsave(&phba
->hbalock
, iflags
);
7852 ready
= atomic_read(&phba
->fabric_iocb_count
) == 0 &&
7853 !test_bit(FABRIC_COMANDS_BLOCKED
, &phba
->bit_flags
);
7856 /* Increment fabric iocb count to hold the position */
7857 atomic_inc(&phba
->fabric_iocb_count
);
7858 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7860 iocb
->fabric_iocb_cmpl
= iocb
->iocb_cmpl
;
7861 iocb
->iocb_cmpl
= lpfc_cmpl_fabric_iocb
;
7862 iocb
->iocb_flag
|= LPFC_IO_FABRIC
;
7864 lpfc_debugfs_disc_trc(iocb
->vport
, LPFC_DISC_TRC_ELS_CMD
,
7865 "Fabric sched2: ste:x%x",
7866 iocb
->vport
->port_state
, 0, 0);
7868 ret
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, iocb
, 0);
7870 if (ret
== IOCB_ERROR
) {
7871 iocb
->iocb_cmpl
= iocb
->fabric_iocb_cmpl
;
7872 iocb
->fabric_iocb_cmpl
= NULL
;
7873 iocb
->iocb_flag
&= ~LPFC_IO_FABRIC
;
7874 atomic_dec(&phba
->fabric_iocb_count
);
7877 spin_lock_irqsave(&phba
->hbalock
, iflags
);
7878 list_add_tail(&iocb
->list
, &phba
->fabric_iocb_list
);
7879 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7886 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
7887 * @vport: pointer to a virtual N_Port data structure.
7889 * This routine aborts all the IOCBs associated with a @vport from the
7890 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
7891 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
7892 * list, removes each IOCB associated with the @vport off the list, set the
7893 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
7894 * associated with the IOCB.
7896 static void lpfc_fabric_abort_vport(struct lpfc_vport
*vport
)
7898 LIST_HEAD(completions
);
7899 struct lpfc_hba
*phba
= vport
->phba
;
7900 struct lpfc_iocbq
*tmp_iocb
, *piocb
;
7902 spin_lock_irq(&phba
->hbalock
);
7903 list_for_each_entry_safe(piocb
, tmp_iocb
, &phba
->fabric_iocb_list
,
7906 if (piocb
->vport
!= vport
)
7909 list_move_tail(&piocb
->list
, &completions
);
7911 spin_unlock_irq(&phba
->hbalock
);
7913 /* Cancel all the IOCBs from the completions list */
7914 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
7919 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
7920 * @ndlp: pointer to a node-list data structure.
7922 * This routine aborts all the IOCBs associated with an @ndlp from the
7923 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
7924 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
7925 * list, removes each IOCB associated with the @ndlp off the list, set the
7926 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
7927 * associated with the IOCB.
7929 void lpfc_fabric_abort_nport(struct lpfc_nodelist
*ndlp
)
7931 LIST_HEAD(completions
);
7932 struct lpfc_hba
*phba
= ndlp
->phba
;
7933 struct lpfc_iocbq
*tmp_iocb
, *piocb
;
7934 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
7936 spin_lock_irq(&phba
->hbalock
);
7937 list_for_each_entry_safe(piocb
, tmp_iocb
, &phba
->fabric_iocb_list
,
7939 if ((lpfc_check_sli_ndlp(phba
, pring
, piocb
, ndlp
))) {
7941 list_move_tail(&piocb
->list
, &completions
);
7944 spin_unlock_irq(&phba
->hbalock
);
7946 /* Cancel all the IOCBs from the completions list */
7947 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
7952 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
7953 * @phba: pointer to lpfc hba data structure.
7955 * This routine aborts all the IOCBs currently on the driver internal
7956 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
7957 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
7958 * list, removes IOCBs off the list, set the status feild to
7959 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
7962 void lpfc_fabric_abort_hba(struct lpfc_hba
*phba
)
7964 LIST_HEAD(completions
);
7966 spin_lock_irq(&phba
->hbalock
);
7967 list_splice_init(&phba
->fabric_iocb_list
, &completions
);
7968 spin_unlock_irq(&phba
->hbalock
);
7970 /* Cancel all the IOCBs from the completions list */
7971 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
7976 * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport
7977 * @vport: pointer to lpfc vport data structure.
7979 * This routine is invoked by the vport cleanup for deletions and the cleanup
7980 * for an ndlp on removal.
7983 lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport
*vport
)
7985 struct lpfc_hba
*phba
= vport
->phba
;
7986 struct lpfc_sglq
*sglq_entry
= NULL
, *sglq_next
= NULL
;
7987 unsigned long iflag
= 0;
7989 spin_lock_irqsave(&phba
->hbalock
, iflag
);
7990 spin_lock(&phba
->sli4_hba
.abts_sgl_list_lock
);
7991 list_for_each_entry_safe(sglq_entry
, sglq_next
,
7992 &phba
->sli4_hba
.lpfc_abts_els_sgl_list
, list
) {
7993 if (sglq_entry
->ndlp
&& sglq_entry
->ndlp
->vport
== vport
)
7994 sglq_entry
->ndlp
= NULL
;
7996 spin_unlock(&phba
->sli4_hba
.abts_sgl_list_lock
);
7997 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
8002 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
8003 * @phba: pointer to lpfc hba data structure.
8004 * @axri: pointer to the els xri abort wcqe structure.
8006 * This routine is invoked by the worker thread to process a SLI4 slow-path
8010 lpfc_sli4_els_xri_aborted(struct lpfc_hba
*phba
,
8011 struct sli4_wcqe_xri_aborted
*axri
)
8013 uint16_t xri
= bf_get(lpfc_wcqe_xa_xri
, axri
);
8014 uint16_t rxid
= bf_get(lpfc_wcqe_xa_remote_xid
, axri
);
8017 struct lpfc_sglq
*sglq_entry
= NULL
, *sglq_next
= NULL
;
8018 unsigned long iflag
= 0;
8019 struct lpfc_nodelist
*ndlp
;
8020 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
8022 spin_lock_irqsave(&phba
->hbalock
, iflag
);
8023 spin_lock(&phba
->sli4_hba
.abts_sgl_list_lock
);
8024 list_for_each_entry_safe(sglq_entry
, sglq_next
,
8025 &phba
->sli4_hba
.lpfc_abts_els_sgl_list
, list
) {
8026 if (sglq_entry
->sli4_xritag
== xri
) {
8027 list_del(&sglq_entry
->list
);
8028 ndlp
= sglq_entry
->ndlp
;
8029 sglq_entry
->ndlp
= NULL
;
8030 list_add_tail(&sglq_entry
->list
,
8031 &phba
->sli4_hba
.lpfc_sgl_list
);
8032 sglq_entry
->state
= SGL_FREED
;
8033 spin_unlock(&phba
->sli4_hba
.abts_sgl_list_lock
);
8034 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
8035 lpfc_set_rrq_active(phba
, ndlp
,
8036 sglq_entry
->sli4_lxritag
,
8039 /* Check if TXQ queue needs to be serviced */
8041 lpfc_worker_wake_up(phba
);
8045 spin_unlock(&phba
->sli4_hba
.abts_sgl_list_lock
);
8046 lxri
= lpfc_sli4_xri_inrange(phba
, xri
);
8047 if (lxri
== NO_XRI
) {
8048 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
8051 sglq_entry
= __lpfc_get_active_sglq(phba
, lxri
);
8052 if (!sglq_entry
|| (sglq_entry
->sli4_xritag
!= xri
)) {
8053 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
8056 sglq_entry
->state
= SGL_XRI_ABORTED
;
8057 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
8061 /* lpfc_sli_abts_recover_port - Recover a port that failed a BLS_ABORT req.
8062 * @vport: pointer to virtual port object.
8063 * @ndlp: nodelist pointer for the impacted node.
8065 * The driver calls this routine in response to an SLI4 XRI ABORT CQE
8066 * or an SLI3 ASYNC_STATUS_CN event from the port. For either event,
8067 * the driver is required to send a LOGO to the remote node before it
8068 * attempts to recover its login to the remote node.
8071 lpfc_sli_abts_recover_port(struct lpfc_vport
*vport
,
8072 struct lpfc_nodelist
*ndlp
)
8074 struct Scsi_Host
*shost
;
8075 struct lpfc_hba
*phba
;
8076 unsigned long flags
= 0;
8078 shost
= lpfc_shost_from_vport(vport
);
8080 if (ndlp
->nlp_state
!= NLP_STE_MAPPED_NODE
) {
8081 lpfc_printf_log(phba
, KERN_INFO
,
8082 LOG_SLI
, "3093 No rport recovery needed. "
8083 "rport in state 0x%x\n", ndlp
->nlp_state
);
8086 lpfc_printf_log(phba
, KERN_INFO
, LOG_SLI
,
8087 "3094 Start rport recovery on shost id 0x%x "
8088 "fc_id 0x%06x vpi 0x%x rpi 0x%x state 0x%x "
8090 shost
->host_no
, ndlp
->nlp_DID
,
8091 vport
->vpi
, ndlp
->nlp_rpi
, ndlp
->nlp_state
,
8094 * The rport is not responding. Remove the FCP-2 flag to prevent
8095 * an ADISC in the follow-up recovery code.
8097 spin_lock_irqsave(shost
->host_lock
, flags
);
8098 ndlp
->nlp_fcp_info
&= ~NLP_FCP_2_DEVICE
;
8099 spin_unlock_irqrestore(shost
->host_lock
, flags
);
8100 lpfc_issue_els_logo(vport
, ndlp
, 0);
8101 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_LOGO_ISSUE
);