1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2011 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
);
233 icmd
->un
.elsreq64
.bdl
.addrHigh
= putPaddrHigh(pbuflist
->phys
);
234 icmd
->un
.elsreq64
.bdl
.addrLow
= putPaddrLow(pbuflist
->phys
);
235 icmd
->un
.elsreq64
.bdl
.bdeFlags
= BUFF_TYPE_BLP_64
;
236 icmd
->un
.elsreq64
.remoteID
= did
; /* DID */
238 icmd
->un
.elsreq64
.bdl
.bdeSize
= (2 * sizeof(struct ulp_bde64
));
239 icmd
->ulpCommand
= CMD_ELS_REQUEST64_CR
;
240 icmd
->ulpTimeout
= phba
->fc_ratov
* 2;
242 icmd
->un
.elsreq64
.bdl
.bdeSize
= sizeof(struct ulp_bde64
);
243 icmd
->ulpCommand
= CMD_XMIT_ELS_RSP64_CX
;
245 icmd
->ulpBdeCount
= 1;
247 icmd
->ulpClass
= CLASS3
;
249 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) {
250 icmd
->un
.elsreq64
.myID
= vport
->fc_myDID
;
252 /* For ELS_REQUEST64_CR, use the VPI by default */
253 icmd
->ulpContext
= phba
->vpi_ids
[vport
->vpi
];
255 /* The CT field must be 0=INVALID_RPI for the ECHO cmd */
256 if (elscmd
== ELS_CMD_ECHO
)
257 icmd
->ulpCt_l
= 0; /* context = invalid RPI */
259 icmd
->ulpCt_l
= 1; /* context = VPI */
262 bpl
= (struct ulp_bde64
*) pbuflist
->virt
;
263 bpl
->addrLow
= le32_to_cpu(putPaddrLow(pcmd
->phys
));
264 bpl
->addrHigh
= le32_to_cpu(putPaddrHigh(pcmd
->phys
));
265 bpl
->tus
.f
.bdeSize
= cmdSize
;
266 bpl
->tus
.f
.bdeFlags
= 0;
267 bpl
->tus
.w
= le32_to_cpu(bpl
->tus
.w
);
271 bpl
->addrLow
= le32_to_cpu(putPaddrLow(prsp
->phys
));
272 bpl
->addrHigh
= le32_to_cpu(putPaddrHigh(prsp
->phys
));
273 bpl
->tus
.f
.bdeSize
= FCELSSIZE
;
274 bpl
->tus
.f
.bdeFlags
= BUFF_TYPE_BDE_64
;
275 bpl
->tus
.w
= le32_to_cpu(bpl
->tus
.w
);
278 /* prevent preparing iocb with NULL ndlp reference */
279 elsiocb
->context1
= lpfc_nlp_get(ndlp
);
280 if (!elsiocb
->context1
)
281 goto els_iocb_free_pbuf_exit
;
282 elsiocb
->context2
= pcmd
;
283 elsiocb
->context3
= pbuflist
;
284 elsiocb
->retry
= retry
;
285 elsiocb
->vport
= vport
;
286 elsiocb
->drvrTimeout
= (phba
->fc_ratov
<< 1) + LPFC_DRVR_TIMEOUT
;
289 list_add(&prsp
->list
, &pcmd
->list
);
292 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
293 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
294 "0116 Xmit ELS command x%x to remote "
295 "NPORT x%x I/O tag: x%x, port state: x%x\n",
296 elscmd
, did
, elsiocb
->iotag
,
299 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
300 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
301 "0117 Xmit ELS response x%x to remote "
302 "NPORT x%x I/O tag: x%x, size: x%x\n",
303 elscmd
, ndlp
->nlp_DID
, elsiocb
->iotag
,
308 els_iocb_free_pbuf_exit
:
310 lpfc_mbuf_free(phba
, prsp
->virt
, prsp
->phys
);
313 els_iocb_free_prsp_exit
:
314 lpfc_mbuf_free(phba
, pcmd
->virt
, pcmd
->phys
);
317 els_iocb_free_pcmb_exit
:
319 lpfc_sli_release_iocbq(phba
, elsiocb
);
324 * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport
325 * @vport: pointer to a host virtual N_Port data structure.
327 * This routine issues a fabric registration login for a @vport. An
328 * active ndlp node with Fabric_DID must already exist for this @vport.
329 * The routine invokes two mailbox commands to carry out fabric registration
330 * login through the HBA firmware: the first mailbox command requests the
331 * HBA to perform link configuration for the @vport; and the second mailbox
332 * command requests the HBA to perform the actual fabric registration login
336 * 0 - successfully issued fabric registration login for @vport
337 * -ENXIO -- failed to issue fabric registration login for @vport
340 lpfc_issue_fabric_reglogin(struct lpfc_vport
*vport
)
342 struct lpfc_hba
*phba
= vport
->phba
;
344 struct lpfc_dmabuf
*mp
;
345 struct lpfc_nodelist
*ndlp
;
346 struct serv_parm
*sp
;
350 sp
= &phba
->fc_fabparam
;
351 ndlp
= lpfc_findnode_did(vport
, Fabric_DID
);
352 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
)) {
357 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
363 vport
->port_state
= LPFC_FABRIC_CFG_LINK
;
364 lpfc_config_link(phba
, mbox
);
365 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
368 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
369 if (rc
== MBX_NOT_FINISHED
) {
374 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
379 rc
= lpfc_reg_rpi(phba
, vport
->vpi
, Fabric_DID
, (uint8_t *)sp
, mbox
,
386 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_fabric_reg_login
;
388 /* increment the reference count on ndlp to hold reference
389 * for the callback routine.
391 mbox
->context2
= lpfc_nlp_get(ndlp
);
393 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
394 if (rc
== MBX_NOT_FINISHED
) {
396 goto fail_issue_reg_login
;
401 fail_issue_reg_login
:
402 /* decrement the reference count on ndlp just incremented
403 * for the failed mbox command.
406 mp
= (struct lpfc_dmabuf
*) mbox
->context1
;
407 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
410 mempool_free(mbox
, phba
->mbox_mem_pool
);
413 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
414 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
415 "0249 Cannot issue Register Fabric login: Err %d\n", err
);
420 * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login
421 * @vport: pointer to a host virtual N_Port data structure.
423 * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for
424 * the @vport. This mailbox command is necessary for FCoE only.
427 * 0 - successfully issued REG_VFI for @vport
428 * A failure code otherwise.
431 lpfc_issue_reg_vfi(struct lpfc_vport
*vport
)
433 struct lpfc_hba
*phba
= vport
->phba
;
435 struct lpfc_nodelist
*ndlp
;
436 struct serv_parm
*sp
;
437 struct lpfc_dmabuf
*dmabuf
;
440 sp
= &phba
->fc_fabparam
;
441 ndlp
= lpfc_findnode_did(vport
, Fabric_DID
);
442 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
)) {
447 dmabuf
= kzalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
452 dmabuf
->virt
= lpfc_mbuf_alloc(phba
, MEM_PRI
, &dmabuf
->phys
);
455 goto fail_free_dmabuf
;
458 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
461 goto fail_free_coherent
;
463 vport
->port_state
= LPFC_FABRIC_CFG_LINK
;
464 memcpy(dmabuf
->virt
, &phba
->fc_fabparam
, sizeof(vport
->fc_sparam
));
465 lpfc_reg_vfi(mboxq
, vport
, dmabuf
->phys
);
466 mboxq
->mbox_cmpl
= lpfc_mbx_cmpl_reg_vfi
;
467 mboxq
->vport
= vport
;
468 mboxq
->context1
= dmabuf
;
469 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
470 if (rc
== MBX_NOT_FINISHED
) {
477 mempool_free(mboxq
, phba
->mbox_mem_pool
);
479 lpfc_mbuf_free(phba
, dmabuf
->virt
, dmabuf
->phys
);
483 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
484 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
485 "0289 Issue Register VFI failed: Err %d\n", rc
);
490 * lpfc_check_clean_addr_bit - Check whether assigned FCID is clean.
491 * @vport: pointer to a host virtual N_Port data structure.
492 * @sp: pointer to service parameter data structure.
494 * This routine is called from FLOGI/FDISC completion handler functions.
495 * lpfc_check_clean_addr_bit return 1 when FCID/Fabric portname/ Fabric
496 * node nodename is changed in the completion service parameter else return
497 * 0. This function also set flag in the vport data structure to delay
498 * NP_Port discovery after the FLOGI/FDISC completion if Clean address bit
499 * in FLOGI/FDISC response is cleared and FCID/Fabric portname/ Fabric
500 * node nodename is changed in the completion service parameter.
503 * 0 - FCID and Fabric Nodename and Fabric portname is not changed.
504 * 1 - FCID or Fabric Nodename or Fabric portname is changed.
508 lpfc_check_clean_addr_bit(struct lpfc_vport
*vport
,
509 struct serv_parm
*sp
)
511 uint8_t fabric_param_changed
= 0;
512 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
514 if ((vport
->fc_prevDID
!= vport
->fc_myDID
) ||
515 memcmp(&vport
->fabric_portname
, &sp
->portName
,
516 sizeof(struct lpfc_name
)) ||
517 memcmp(&vport
->fabric_nodename
, &sp
->nodeName
,
518 sizeof(struct lpfc_name
)))
519 fabric_param_changed
= 1;
522 * Word 1 Bit 31 in common service parameter is overloaded.
523 * Word 1 Bit 31 in FLOGI request is multiple NPort request
524 * Word 1 Bit 31 in FLOGI response is clean address bit
526 * If fabric parameter is changed and clean address bit is
527 * cleared delay nport discovery if
528 * - vport->fc_prevDID != 0 (not initial discovery) OR
529 * - lpfc_delay_discovery module parameter is set.
531 if (fabric_param_changed
&& !sp
->cmn
.clean_address_bit
&&
532 (vport
->fc_prevDID
|| lpfc_delay_discovery
)) {
533 spin_lock_irq(shost
->host_lock
);
534 vport
->fc_flag
|= FC_DISC_DELAYED
;
535 spin_unlock_irq(shost
->host_lock
);
538 return fabric_param_changed
;
543 * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port
544 * @vport: pointer to a host virtual N_Port data structure.
545 * @ndlp: pointer to a node-list data structure.
546 * @sp: pointer to service parameter data structure.
547 * @irsp: pointer to the IOCB within the lpfc response IOCB.
549 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
550 * function to handle the completion of a Fabric Login (FLOGI) into a fabric
551 * port in a fabric topology. It properly sets up the parameters to the @ndlp
552 * from the IOCB response. It also check the newly assigned N_Port ID to the
553 * @vport against the previously assigned N_Port ID. If it is different from
554 * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
555 * is invoked on all the remaining nodes with the @vport to unregister the
556 * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
557 * is invoked to register login to the fabric.
560 * 0 - Success (currently, always return 0)
563 lpfc_cmpl_els_flogi_fabric(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
564 struct serv_parm
*sp
, IOCB_t
*irsp
)
566 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
567 struct lpfc_hba
*phba
= vport
->phba
;
568 struct lpfc_nodelist
*np
;
569 struct lpfc_nodelist
*next_np
;
570 uint8_t fabric_param_changed
;
572 spin_lock_irq(shost
->host_lock
);
573 vport
->fc_flag
|= FC_FABRIC
;
574 spin_unlock_irq(shost
->host_lock
);
576 phba
->fc_edtov
= be32_to_cpu(sp
->cmn
.e_d_tov
);
577 if (sp
->cmn
.edtovResolution
) /* E_D_TOV ticks are in nanoseconds */
578 phba
->fc_edtov
= (phba
->fc_edtov
+ 999999) / 1000000;
580 phba
->fc_edtovResol
= sp
->cmn
.edtovResolution
;
581 phba
->fc_ratov
= (be32_to_cpu(sp
->cmn
.w2
.r_a_tov
) + 999) / 1000;
583 if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) {
584 spin_lock_irq(shost
->host_lock
);
585 vport
->fc_flag
|= FC_PUBLIC_LOOP
;
586 spin_unlock_irq(shost
->host_lock
);
589 vport
->fc_myDID
= irsp
->un
.ulpWord
[4] & Mask_DID
;
590 memcpy(&ndlp
->nlp_portname
, &sp
->portName
, sizeof(struct lpfc_name
));
591 memcpy(&ndlp
->nlp_nodename
, &sp
->nodeName
, sizeof(struct lpfc_name
));
592 ndlp
->nlp_class_sup
= 0;
593 if (sp
->cls1
.classValid
)
594 ndlp
->nlp_class_sup
|= FC_COS_CLASS1
;
595 if (sp
->cls2
.classValid
)
596 ndlp
->nlp_class_sup
|= FC_COS_CLASS2
;
597 if (sp
->cls3
.classValid
)
598 ndlp
->nlp_class_sup
|= FC_COS_CLASS3
;
599 if (sp
->cls4
.classValid
)
600 ndlp
->nlp_class_sup
|= FC_COS_CLASS4
;
601 ndlp
->nlp_maxframe
= ((sp
->cmn
.bbRcvSizeMsb
& 0x0F) << 8) |
602 sp
->cmn
.bbRcvSizeLsb
;
604 fabric_param_changed
= lpfc_check_clean_addr_bit(vport
, sp
);
605 memcpy(&vport
->fabric_portname
, &sp
->portName
,
606 sizeof(struct lpfc_name
));
607 memcpy(&vport
->fabric_nodename
, &sp
->nodeName
,
608 sizeof(struct lpfc_name
));
609 memcpy(&phba
->fc_fabparam
, sp
, sizeof(struct serv_parm
));
611 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) {
612 if (sp
->cmn
.response_multiple_NPort
) {
613 lpfc_printf_vlog(vport
, KERN_WARNING
,
615 "1816 FLOGI NPIV supported, "
616 "response data 0x%x\n",
617 sp
->cmn
.response_multiple_NPort
);
618 phba
->link_flag
|= LS_NPIV_FAB_SUPPORTED
;
620 /* Because we asked f/w for NPIV it still expects us
621 to call reg_vnpid atleast for the physcial host */
622 lpfc_printf_vlog(vport
, KERN_WARNING
,
624 "1817 Fabric does not support NPIV "
625 "- configuring single port mode.\n");
626 phba
->link_flag
&= ~LS_NPIV_FAB_SUPPORTED
;
630 if (fabric_param_changed
&&
631 !(vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
)) {
633 /* If our NportID changed, we need to ensure all
634 * remaining NPORTs get unreg_login'ed.
636 list_for_each_entry_safe(np
, next_np
,
637 &vport
->fc_nodes
, nlp_listp
) {
638 if (!NLP_CHK_NODE_ACT(np
))
640 if ((np
->nlp_state
!= NLP_STE_NPR_NODE
) ||
641 !(np
->nlp_flag
& NLP_NPR_ADISC
))
643 spin_lock_irq(shost
->host_lock
);
644 np
->nlp_flag
&= ~NLP_NPR_ADISC
;
645 spin_unlock_irq(shost
->host_lock
);
646 lpfc_unreg_rpi(vport
, np
);
648 lpfc_cleanup_pending_mbox(vport
);
650 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
651 lpfc_sli4_unreg_all_rpis(vport
);
652 lpfc_mbx_unreg_vpi(vport
);
653 spin_lock_irq(shost
->host_lock
);
654 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
656 * If VPI is unreged, driver need to do INIT_VPI
657 * before re-registering
659 vport
->fc_flag
|= FC_VPORT_NEEDS_INIT_VPI
;
660 spin_unlock_irq(shost
->host_lock
);
662 } else if ((phba
->sli_rev
== LPFC_SLI_REV4
) &&
663 !(vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
)) {
665 * Driver needs to re-reg VPI in order for f/w
666 * to update the MAC address.
668 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
669 lpfc_register_new_vport(phba
, vport
, ndlp
);
673 if (phba
->sli_rev
< LPFC_SLI_REV4
) {
674 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_REG_LOGIN_ISSUE
);
675 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
&&
676 vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
)
677 lpfc_register_new_vport(phba
, vport
, ndlp
);
679 lpfc_issue_fabric_reglogin(vport
);
681 ndlp
->nlp_type
|= NLP_FABRIC
;
682 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
683 if ((!(vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
)) &&
684 (vport
->vpi_state
& LPFC_VPI_REGISTERED
)) {
685 lpfc_start_fdiscs(phba
);
686 lpfc_do_scr_ns_plogi(phba
, vport
);
687 } else if (vport
->fc_flag
& FC_VFI_REGISTERED
)
688 lpfc_issue_init_vpi(vport
);
690 lpfc_issue_reg_vfi(vport
);
695 * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
696 * @vport: pointer to a host virtual N_Port data structure.
697 * @ndlp: pointer to a node-list data structure.
698 * @sp: pointer to service parameter data structure.
700 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
701 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
702 * in a point-to-point topology. First, the @vport's N_Port Name is compared
703 * with the received N_Port Name: if the @vport's N_Port Name is greater than
704 * the received N_Port Name lexicographically, this node shall assign local
705 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
706 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
707 * this node shall just wait for the remote node to issue PLOGI and assign
715 lpfc_cmpl_els_flogi_nport(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
716 struct serv_parm
*sp
)
718 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
719 struct lpfc_hba
*phba
= vport
->phba
;
723 spin_lock_irq(shost
->host_lock
);
724 vport
->fc_flag
&= ~(FC_FABRIC
| FC_PUBLIC_LOOP
);
725 spin_unlock_irq(shost
->host_lock
);
727 phba
->fc_edtov
= FF_DEF_EDTOV
;
728 phba
->fc_ratov
= FF_DEF_RATOV
;
729 rc
= memcmp(&vport
->fc_portname
, &sp
->portName
,
730 sizeof(vport
->fc_portname
));
732 /* This side will initiate the PLOGI */
733 spin_lock_irq(shost
->host_lock
);
734 vport
->fc_flag
|= FC_PT2PT_PLOGI
;
735 spin_unlock_irq(shost
->host_lock
);
738 * N_Port ID cannot be 0, set our to LocalID the other
739 * side will be RemoteID.
744 vport
->fc_myDID
= PT2PT_LocalID
;
746 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
750 lpfc_config_link(phba
, mbox
);
752 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
754 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
755 if (rc
== MBX_NOT_FINISHED
) {
756 mempool_free(mbox
, phba
->mbox_mem_pool
);
759 /* Decrement ndlp reference count indicating that ndlp can be
760 * safely released when other references to it are done.
764 ndlp
= lpfc_findnode_did(vport
, PT2PT_RemoteID
);
767 * Cannot find existing Fabric ndlp, so allocate a
770 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
773 lpfc_nlp_init(vport
, ndlp
, PT2PT_RemoteID
);
774 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
775 ndlp
= lpfc_enable_node(vport
, ndlp
,
776 NLP_STE_UNUSED_NODE
);
781 memcpy(&ndlp
->nlp_portname
, &sp
->portName
,
782 sizeof(struct lpfc_name
));
783 memcpy(&ndlp
->nlp_nodename
, &sp
->nodeName
,
784 sizeof(struct lpfc_name
));
785 /* Set state will put ndlp onto node list if not already done */
786 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
787 spin_lock_irq(shost
->host_lock
);
788 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
789 spin_unlock_irq(shost
->host_lock
);
791 /* This side will wait for the PLOGI, decrement ndlp reference
792 * count indicating that ndlp can be released when other
793 * references to it are done.
797 /* If we are pt2pt with another NPort, force NPIV off! */
798 phba
->sli3_options
&= ~LPFC_SLI3_NPIV_ENABLED
;
800 spin_lock_irq(shost
->host_lock
);
801 vport
->fc_flag
|= FC_PT2PT
;
802 spin_unlock_irq(shost
->host_lock
);
804 /* Start discovery - this should just do CLEAR_LA */
805 lpfc_disc_start(vport
);
812 * lpfc_cmpl_els_flogi - Completion callback function for flogi
813 * @phba: pointer to lpfc hba data structure.
814 * @cmdiocb: pointer to lpfc command iocb data structure.
815 * @rspiocb: pointer to lpfc response iocb data structure.
817 * This routine is the top-level completion callback function for issuing
818 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
819 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
820 * retry has been made (either immediately or delayed with lpfc_els_retry()
821 * returning 1), the command IOCB will be released and function returned.
822 * If the retry attempt has been given up (possibly reach the maximum
823 * number of retries), one additional decrement of ndlp reference shall be
824 * invoked before going out after releasing the command IOCB. This will
825 * actually release the remote node (Note, lpfc_els_free_iocb() will also
826 * invoke one decrement of ndlp reference count). If no error reported in
827 * the IOCB status, the command Port ID field is used to determine whether
828 * this is a point-to-point topology or a fabric topology: if the Port ID
829 * field is assigned, it is a fabric topology; otherwise, it is a
830 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
831 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
832 * specific topology completion conditions.
835 lpfc_cmpl_els_flogi(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
836 struct lpfc_iocbq
*rspiocb
)
838 struct lpfc_vport
*vport
= cmdiocb
->vport
;
839 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
840 IOCB_t
*irsp
= &rspiocb
->iocb
;
841 struct lpfc_nodelist
*ndlp
= cmdiocb
->context1
;
842 struct lpfc_dmabuf
*pcmd
= cmdiocb
->context2
, *prsp
;
843 struct serv_parm
*sp
;
847 /* Check to see if link went down during discovery */
848 if (lpfc_els_chk_latt(vport
)) {
849 /* One additional decrement on node reference count to
850 * trigger the release of the node
856 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
857 "FLOGI cmpl: status:x%x/x%x state:x%x",
858 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
861 if (irsp
->ulpStatus
) {
863 * In case of FIP mode, perform roundrobin FCF failover
864 * due to new FCF discovery
866 if ((phba
->hba_flag
& HBA_FIP_SUPPORT
) &&
867 (phba
->fcf
.fcf_flag
& FCF_DISCOVERY
) &&
868 !((irsp
->ulpStatus
== IOSTAT_LOCAL_REJECT
) &&
869 (irsp
->un
.ulpWord
[4] == IOERR_SLI_ABORTED
))) {
870 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FIP
| LOG_ELS
,
871 "2611 FLOGI failed on FCF (x%x), "
872 "status:x%x/x%x, tmo:x%x, perform "
873 "roundrobin FCF failover\n",
874 phba
->fcf
.current_rec
.fcf_indx
,
875 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
877 fcf_index
= lpfc_sli4_fcf_rr_next_index_get(phba
);
878 rc
= lpfc_sli4_fcf_rr_next_proc(vport
, fcf_index
);
884 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
885 "2858 FLOGI failure Status:x%x/x%x TMO:x%x\n",
886 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
889 /* Check for retry */
890 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
))
894 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
895 "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n",
896 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
899 /* FLOGI failed, so there is no fabric */
900 spin_lock_irq(shost
->host_lock
);
901 vport
->fc_flag
&= ~(FC_FABRIC
| FC_PUBLIC_LOOP
);
902 spin_unlock_irq(shost
->host_lock
);
904 /* If private loop, then allow max outstanding els to be
905 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
906 * alpa map would take too long otherwise.
908 if (phba
->alpa_map
[0] == 0) {
909 vport
->cfg_discovery_threads
= LPFC_MAX_DISC_THREADS
;
910 if ((phba
->sli_rev
== LPFC_SLI_REV4
) &&
911 (!(vport
->fc_flag
& FC_VFI_REGISTERED
) ||
912 (vport
->fc_prevDID
!= vport
->fc_myDID
))) {
913 if (vport
->fc_flag
& FC_VFI_REGISTERED
)
914 lpfc_sli4_unreg_all_rpis(vport
);
915 lpfc_issue_reg_vfi(vport
);
922 spin_lock_irq(shost
->host_lock
);
923 vport
->fc_flag
&= ~FC_VPORT_CVL_RCVD
;
924 vport
->fc_flag
&= ~FC_VPORT_LOGO_RCVD
;
925 spin_unlock_irq(shost
->host_lock
);
928 * The FLogI succeeded. Sync the data for the CPU before
931 prsp
= list_get_first(&pcmd
->list
, struct lpfc_dmabuf
, list
);
933 sp
= prsp
->virt
+ sizeof(uint32_t);
935 /* FLOGI completes successfully */
936 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
937 "0101 FLOGI completes successfully "
938 "Data: x%x x%x x%x x%x\n",
939 irsp
->un
.ulpWord
[4], sp
->cmn
.e_d_tov
,
940 sp
->cmn
.w2
.r_a_tov
, sp
->cmn
.edtovResolution
);
942 if (vport
->port_state
== LPFC_FLOGI
) {
944 * If Common Service Parameters indicate Nport
945 * we are point to point, if Fport we are Fabric.
948 rc
= lpfc_cmpl_els_flogi_fabric(vport
, ndlp
, sp
, irsp
);
949 else if (!(phba
->hba_flag
& HBA_FCOE_MODE
))
950 rc
= lpfc_cmpl_els_flogi_nport(vport
, ndlp
, sp
);
952 lpfc_printf_vlog(vport
, KERN_ERR
,
954 "2831 FLOGI response with cleared Fabric "
955 "bit fcf_index 0x%x "
956 "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
958 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
959 phba
->fcf
.current_rec
.fcf_indx
,
960 phba
->fcf
.current_rec
.switch_name
[0],
961 phba
->fcf
.current_rec
.switch_name
[1],
962 phba
->fcf
.current_rec
.switch_name
[2],
963 phba
->fcf
.current_rec
.switch_name
[3],
964 phba
->fcf
.current_rec
.switch_name
[4],
965 phba
->fcf
.current_rec
.switch_name
[5],
966 phba
->fcf
.current_rec
.switch_name
[6],
967 phba
->fcf
.current_rec
.switch_name
[7],
968 phba
->fcf
.current_rec
.fabric_name
[0],
969 phba
->fcf
.current_rec
.fabric_name
[1],
970 phba
->fcf
.current_rec
.fabric_name
[2],
971 phba
->fcf
.current_rec
.fabric_name
[3],
972 phba
->fcf
.current_rec
.fabric_name
[4],
973 phba
->fcf
.current_rec
.fabric_name
[5],
974 phba
->fcf
.current_rec
.fabric_name
[6],
975 phba
->fcf
.current_rec
.fabric_name
[7]);
977 spin_lock_irq(&phba
->hbalock
);
978 phba
->fcf
.fcf_flag
&= ~FCF_DISCOVERY
;
979 phba
->hba_flag
&= ~(FCF_RR_INPROG
| HBA_DEVLOSS_TMO
);
980 spin_unlock_irq(&phba
->hbalock
);
984 /* Mark the FCF discovery process done */
985 if (phba
->hba_flag
& HBA_FIP_SUPPORT
)
986 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_FIP
|
988 "2769 FLOGI to FCF (x%x) "
989 "completed successfully\n",
990 phba
->fcf
.current_rec
.fcf_indx
);
991 spin_lock_irq(&phba
->hbalock
);
992 phba
->fcf
.fcf_flag
&= ~FCF_DISCOVERY
;
993 phba
->hba_flag
&= ~(FCF_RR_INPROG
| HBA_DEVLOSS_TMO
);
994 spin_unlock_irq(&phba
->hbalock
);
1002 if (!lpfc_error_lost_link(irsp
)) {
1003 /* FLOGI failed, so just use loop map to make discovery list */
1004 lpfc_disc_list_loopmap(vport
);
1006 /* Start discovery */
1007 lpfc_disc_start(vport
);
1008 } else if (((irsp
->ulpStatus
!= IOSTAT_LOCAL_REJECT
) ||
1009 ((irsp
->un
.ulpWord
[4] != IOERR_SLI_ABORTED
) &&
1010 (irsp
->un
.ulpWord
[4] != IOERR_SLI_DOWN
))) &&
1011 (phba
->link_state
!= LPFC_CLEAR_LA
)) {
1012 /* If FLOGI failed enable link interrupt. */
1013 lpfc_issue_clear_la(phba
, vport
);
1016 lpfc_els_free_iocb(phba
, cmdiocb
);
1020 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
1021 * @vport: pointer to a host virtual N_Port data structure.
1022 * @ndlp: pointer to a node-list data structure.
1023 * @retry: number of retries to the command IOCB.
1025 * This routine issues a Fabric Login (FLOGI) Request ELS command
1026 * for a @vport. The initiator service parameters are put into the payload
1027 * of the FLOGI Request IOCB and the top-level callback function pointer
1028 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
1029 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
1030 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
1032 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1033 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1034 * will be stored into the context1 field of the IOCB for the completion
1035 * callback function to the FLOGI ELS command.
1038 * 0 - successfully issued flogi iocb for @vport
1039 * 1 - failed to issue flogi iocb for @vport
1042 lpfc_issue_els_flogi(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1045 struct lpfc_hba
*phba
= vport
->phba
;
1046 struct serv_parm
*sp
;
1048 struct lpfc_iocbq
*elsiocb
;
1049 struct lpfc_sli_ring
*pring
;
1055 pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
1057 cmdsize
= (sizeof(uint32_t) + sizeof(struct serv_parm
));
1058 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
1059 ndlp
->nlp_DID
, ELS_CMD_FLOGI
);
1064 icmd
= &elsiocb
->iocb
;
1065 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
1067 /* For FLOGI request, remainder of payload is service parameters */
1068 *((uint32_t *) (pcmd
)) = ELS_CMD_FLOGI
;
1069 pcmd
+= sizeof(uint32_t);
1070 memcpy(pcmd
, &vport
->fc_sparam
, sizeof(struct serv_parm
));
1071 sp
= (struct serv_parm
*) pcmd
;
1073 /* Setup CSPs accordingly for Fabric */
1074 sp
->cmn
.e_d_tov
= 0;
1075 sp
->cmn
.w2
.r_a_tov
= 0;
1076 sp
->cls1
.classValid
= 0;
1077 sp
->cls2
.seqDelivery
= 1;
1078 sp
->cls3
.seqDelivery
= 1;
1079 if (sp
->cmn
.fcphLow
< FC_PH3
)
1080 sp
->cmn
.fcphLow
= FC_PH3
;
1081 if (sp
->cmn
.fcphHigh
< FC_PH3
)
1082 sp
->cmn
.fcphHigh
= FC_PH3
;
1084 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
1085 if (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) ==
1086 LPFC_SLI_INTF_IF_TYPE_0
) {
1087 elsiocb
->iocb
.ulpCt_h
= ((SLI4_CT_FCFI
>> 1) & 1);
1088 elsiocb
->iocb
.ulpCt_l
= (SLI4_CT_FCFI
& 1);
1089 /* FLOGI needs to be 3 for WQE FCFI */
1090 /* Set the fcfi to the fcfi we registered with */
1091 elsiocb
->iocb
.ulpContext
= phba
->fcf
.fcfi
;
1094 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) {
1095 sp
->cmn
.request_multiple_Nport
= 1;
1096 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
1100 sp
->cmn
.request_multiple_Nport
= 0;
1103 if (phba
->fc_topology
!= LPFC_TOPOLOGY_LOOP
) {
1104 icmd
->un
.elsreq64
.myID
= 0;
1105 icmd
->un
.elsreq64
.fl
= 1;
1108 tmo
= phba
->fc_ratov
;
1109 phba
->fc_ratov
= LPFC_DISC_FLOGI_TMO
;
1110 lpfc_set_disctmo(vport
);
1111 phba
->fc_ratov
= tmo
;
1113 phba
->fc_stat
.elsXmitFLOGI
++;
1114 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_flogi
;
1116 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1117 "Issue FLOGI: opt:x%x",
1118 phba
->sli3_options
, 0, 0);
1120 rc
= lpfc_issue_fabric_iocb(phba
, elsiocb
);
1121 if (rc
== IOCB_ERROR
) {
1122 lpfc_els_free_iocb(phba
, elsiocb
);
1129 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
1130 * @phba: pointer to lpfc hba data structure.
1132 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
1133 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
1134 * list and issues an abort IOCB commond on each outstanding IOCB that
1135 * contains a active Fabric_DID ndlp. Note that this function is to issue
1136 * the abort IOCB command on all the outstanding IOCBs, thus when this
1137 * function returns, it does not guarantee all the IOCBs are actually aborted.
1140 * 0 - Successfully issued abort iocb on all outstanding flogis (Always 0)
1143 lpfc_els_abort_flogi(struct lpfc_hba
*phba
)
1145 struct lpfc_sli_ring
*pring
;
1146 struct lpfc_iocbq
*iocb
, *next_iocb
;
1147 struct lpfc_nodelist
*ndlp
;
1150 /* Abort outstanding I/O on NPort <nlp_DID> */
1151 lpfc_printf_log(phba
, KERN_INFO
, LOG_DISCOVERY
,
1152 "0201 Abort outstanding I/O on NPort x%x\n",
1155 pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
1158 * Check the txcmplq for an iocb that matches the nport the driver is
1161 spin_lock_irq(&phba
->hbalock
);
1162 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
, list
) {
1164 if (icmd
->ulpCommand
== CMD_ELS_REQUEST64_CR
&&
1165 icmd
->un
.elsreq64
.bdl
.ulpIoTag32
) {
1166 ndlp
= (struct lpfc_nodelist
*)(iocb
->context1
);
1167 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
) &&
1168 (ndlp
->nlp_DID
== Fabric_DID
))
1169 lpfc_sli_issue_abort_iotag(phba
, pring
, iocb
);
1172 spin_unlock_irq(&phba
->hbalock
);
1178 * lpfc_initial_flogi - Issue an initial fabric login for a vport
1179 * @vport: pointer to a host virtual N_Port data structure.
1181 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1182 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1183 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1184 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1185 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1186 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1190 * 0 - failed to issue initial flogi for @vport
1191 * 1 - successfully issued initial flogi for @vport
1194 lpfc_initial_flogi(struct lpfc_vport
*vport
)
1196 struct lpfc_hba
*phba
= vport
->phba
;
1197 struct lpfc_nodelist
*ndlp
;
1199 vport
->port_state
= LPFC_FLOGI
;
1200 lpfc_set_disctmo(vport
);
1202 /* First look for the Fabric ndlp */
1203 ndlp
= lpfc_findnode_did(vport
, Fabric_DID
);
1205 /* Cannot find existing Fabric ndlp, so allocate a new one */
1206 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
1209 lpfc_nlp_init(vport
, ndlp
, Fabric_DID
);
1210 /* Set the node type */
1211 ndlp
->nlp_type
|= NLP_FABRIC
;
1212 /* Put ndlp onto node list */
1213 lpfc_enqueue_node(vport
, ndlp
);
1214 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
1215 /* re-setup ndlp without removing from node list */
1216 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
1221 if (lpfc_issue_els_flogi(vport
, ndlp
, 0)) {
1222 /* This decrement of reference count to node shall kick off
1223 * the release of the node.
1232 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
1233 * @vport: pointer to a host virtual N_Port data structure.
1235 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1236 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1237 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1238 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1239 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1240 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1244 * 0 - failed to issue initial fdisc for @vport
1245 * 1 - successfully issued initial fdisc for @vport
1248 lpfc_initial_fdisc(struct lpfc_vport
*vport
)
1250 struct lpfc_hba
*phba
= vport
->phba
;
1251 struct lpfc_nodelist
*ndlp
;
1253 /* First look for the Fabric ndlp */
1254 ndlp
= lpfc_findnode_did(vport
, Fabric_DID
);
1256 /* Cannot find existing Fabric ndlp, so allocate a new one */
1257 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
1260 lpfc_nlp_init(vport
, ndlp
, Fabric_DID
);
1261 /* Put ndlp onto node list */
1262 lpfc_enqueue_node(vport
, ndlp
);
1263 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
1264 /* re-setup ndlp without removing from node list */
1265 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
1270 if (lpfc_issue_els_fdisc(vport
, ndlp
, 0)) {
1271 /* decrement node reference count to trigger the release of
1281 * lpfc_more_plogi - Check and issue remaining plogis for a vport
1282 * @vport: pointer to a host virtual N_Port data structure.
1284 * This routine checks whether there are more remaining Port Logins
1285 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1286 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1287 * to issue ELS PLOGIs up to the configured discover threads with the
1288 * @vport (@vport->cfg_discovery_threads). The function also decrement
1289 * the @vport's num_disc_node by 1 if it is not already 0.
1292 lpfc_more_plogi(struct lpfc_vport
*vport
)
1296 if (vport
->num_disc_nodes
)
1297 vport
->num_disc_nodes
--;
1299 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
1300 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
1301 "0232 Continue discovery with %d PLOGIs to go "
1302 "Data: x%x x%x x%x\n",
1303 vport
->num_disc_nodes
, vport
->fc_plogi_cnt
,
1304 vport
->fc_flag
, vport
->port_state
);
1305 /* Check to see if there are more PLOGIs to be sent */
1306 if (vport
->fc_flag
& FC_NLP_MORE
)
1307 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1308 sentplogi
= lpfc_els_disc_plogi(vport
);
1314 * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
1315 * @phba: pointer to lpfc hba data structure.
1316 * @prsp: pointer to response IOCB payload.
1317 * @ndlp: pointer to a node-list data structure.
1319 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1320 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1321 * The following cases are considered N_Port confirmed:
1322 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1323 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1324 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1325 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1326 * 1) if there is a node on vport list other than the @ndlp with the same
1327 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1328 * on that node to release the RPI associated with the node; 2) if there is
1329 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1330 * into, a new node shall be allocated (or activated). In either case, the
1331 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1332 * be released and the new_ndlp shall be put on to the vport node list and
1333 * its pointer returned as the confirmed node.
1335 * Note that before the @ndlp got "released", the keepDID from not-matching
1336 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1337 * of the @ndlp. This is because the release of @ndlp is actually to put it
1338 * into an inactive state on the vport node list and the vport node list
1339 * management algorithm does not allow two node with a same DID.
1342 * pointer to the PLOGI N_Port @ndlp
1344 static struct lpfc_nodelist
*
1345 lpfc_plogi_confirm_nport(struct lpfc_hba
*phba
, uint32_t *prsp
,
1346 struct lpfc_nodelist
*ndlp
)
1348 struct lpfc_vport
*vport
= ndlp
->vport
;
1349 struct lpfc_nodelist
*new_ndlp
;
1350 struct lpfc_rport_data
*rdata
;
1351 struct fc_rport
*rport
;
1352 struct serv_parm
*sp
;
1353 uint8_t name
[sizeof(struct lpfc_name
)];
1354 uint32_t rc
, keepDID
= 0;
1357 struct lpfc_node_rrqs rrq
;
1359 /* Fabric nodes can have the same WWPN so we don't bother searching
1360 * by WWPN. Just return the ndlp that was given to us.
1362 if (ndlp
->nlp_type
& NLP_FABRIC
)
1365 sp
= (struct serv_parm
*) ((uint8_t *) prsp
+ sizeof(uint32_t));
1366 memset(name
, 0, sizeof(struct lpfc_name
));
1368 /* Now we find out if the NPort we are logging into, matches the WWPN
1369 * we have for that ndlp. If not, we have some work to do.
1371 new_ndlp
= lpfc_findnode_wwpn(vport
, &sp
->portName
);
1373 if (new_ndlp
== ndlp
&& NLP_CHK_NODE_ACT(new_ndlp
))
1375 memset(&rrq
.xri_bitmap
, 0, sizeof(new_ndlp
->active_rrqs
.xri_bitmap
));
1378 rc
= memcmp(&ndlp
->nlp_portname
, name
,
1379 sizeof(struct lpfc_name
));
1382 new_ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_ATOMIC
);
1385 lpfc_nlp_init(vport
, new_ndlp
, ndlp
->nlp_DID
);
1386 } else if (!NLP_CHK_NODE_ACT(new_ndlp
)) {
1387 rc
= memcmp(&ndlp
->nlp_portname
, name
,
1388 sizeof(struct lpfc_name
));
1391 new_ndlp
= lpfc_enable_node(vport
, new_ndlp
,
1392 NLP_STE_UNUSED_NODE
);
1395 keepDID
= new_ndlp
->nlp_DID
;
1396 if (phba
->sli_rev
== LPFC_SLI_REV4
)
1397 memcpy(&rrq
.xri_bitmap
,
1398 &new_ndlp
->active_rrqs
.xri_bitmap
,
1399 sizeof(new_ndlp
->active_rrqs
.xri_bitmap
));
1401 keepDID
= new_ndlp
->nlp_DID
;
1402 if (phba
->sli_rev
== LPFC_SLI_REV4
)
1403 memcpy(&rrq
.xri_bitmap
,
1404 &new_ndlp
->active_rrqs
.xri_bitmap
,
1405 sizeof(new_ndlp
->active_rrqs
.xri_bitmap
));
1408 lpfc_unreg_rpi(vport
, new_ndlp
);
1409 new_ndlp
->nlp_DID
= ndlp
->nlp_DID
;
1410 new_ndlp
->nlp_prev_state
= ndlp
->nlp_prev_state
;
1411 if (phba
->sli_rev
== LPFC_SLI_REV4
)
1412 memcpy(new_ndlp
->active_rrqs
.xri_bitmap
,
1413 &ndlp
->active_rrqs
.xri_bitmap
,
1414 sizeof(ndlp
->active_rrqs
.xri_bitmap
));
1416 if (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
)
1417 new_ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
1418 ndlp
->nlp_flag
&= ~NLP_NPR_2B_DISC
;
1420 /* Set state will put new_ndlp on to node list if not already done */
1421 lpfc_nlp_set_state(vport
, new_ndlp
, ndlp
->nlp_state
);
1423 /* Move this back to NPR state */
1424 if (memcmp(&ndlp
->nlp_portname
, name
, sizeof(struct lpfc_name
)) == 0) {
1425 /* The new_ndlp is replacing ndlp totally, so we need
1426 * to put ndlp on UNUSED list and try to free it.
1429 /* Fix up the rport accordingly */
1430 rport
= ndlp
->rport
;
1432 rdata
= rport
->dd_data
;
1433 if (rdata
->pnode
== ndlp
) {
1436 rdata
->pnode
= lpfc_nlp_get(new_ndlp
);
1437 new_ndlp
->rport
= rport
;
1439 new_ndlp
->nlp_type
= ndlp
->nlp_type
;
1441 /* We shall actually free the ndlp with both nlp_DID and
1442 * nlp_portname fields equals 0 to avoid any ndlp on the
1443 * nodelist never to be used.
1445 if (ndlp
->nlp_DID
== 0) {
1446 spin_lock_irq(&phba
->ndlp_lock
);
1447 NLP_SET_FREE_REQ(ndlp
);
1448 spin_unlock_irq(&phba
->ndlp_lock
);
1451 /* Two ndlps cannot have the same did on the nodelist */
1452 ndlp
->nlp_DID
= keepDID
;
1453 if (phba
->sli_rev
== LPFC_SLI_REV4
)
1454 memcpy(&ndlp
->active_rrqs
.xri_bitmap
,
1456 sizeof(ndlp
->active_rrqs
.xri_bitmap
));
1457 lpfc_drop_node(vport
, ndlp
);
1460 lpfc_unreg_rpi(vport
, ndlp
);
1461 /* Two ndlps cannot have the same did */
1462 ndlp
->nlp_DID
= keepDID
;
1463 if (phba
->sli_rev
== LPFC_SLI_REV4
)
1464 memcpy(&ndlp
->active_rrqs
.xri_bitmap
,
1466 sizeof(ndlp
->active_rrqs
.xri_bitmap
));
1467 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1468 /* Since we are swapping the ndlp passed in with the new one
1469 * and the did has already been swapped, copy over the
1472 memcpy(&new_ndlp
->nlp_portname
, &ndlp
->nlp_portname
,
1473 sizeof(struct lpfc_name
));
1474 memcpy(&new_ndlp
->nlp_nodename
, &ndlp
->nlp_nodename
,
1475 sizeof(struct lpfc_name
));
1476 new_ndlp
->nlp_state
= ndlp
->nlp_state
;
1477 /* Fix up the rport accordingly */
1478 rport
= ndlp
->rport
;
1480 rdata
= rport
->dd_data
;
1481 put_node
= rdata
->pnode
!= NULL
;
1482 put_rport
= ndlp
->rport
!= NULL
;
1483 rdata
->pnode
= NULL
;
1488 put_device(&rport
->dev
);
1495 * lpfc_end_rscn - Check and handle more rscn for a vport
1496 * @vport: pointer to a host virtual N_Port data structure.
1498 * This routine checks whether more Registration State Change
1499 * Notifications (RSCNs) came in while the discovery state machine was in
1500 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1501 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1502 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1503 * handling the RSCNs.
1506 lpfc_end_rscn(struct lpfc_vport
*vport
)
1508 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1510 if (vport
->fc_flag
& FC_RSCN_MODE
) {
1512 * Check to see if more RSCNs came in while we were
1513 * processing this one.
1515 if (vport
->fc_rscn_id_cnt
||
1516 (vport
->fc_flag
& FC_RSCN_DISCOVERY
) != 0)
1517 lpfc_els_handle_rscn(vport
);
1519 spin_lock_irq(shost
->host_lock
);
1520 vport
->fc_flag
&= ~FC_RSCN_MODE
;
1521 spin_unlock_irq(shost
->host_lock
);
1527 * lpfc_cmpl_els_rrq - Completion handled for els RRQs.
1528 * @phba: pointer to lpfc hba data structure.
1529 * @cmdiocb: pointer to lpfc command iocb data structure.
1530 * @rspiocb: pointer to lpfc response iocb data structure.
1532 * This routine will call the clear rrq function to free the rrq and
1533 * clear the xri's bit in the ndlp's xri_bitmap. If the ndlp does not
1534 * exist then the clear_rrq is still called because the rrq needs to
1539 lpfc_cmpl_els_rrq(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
1540 struct lpfc_iocbq
*rspiocb
)
1542 struct lpfc_vport
*vport
= cmdiocb
->vport
;
1544 struct lpfc_nodelist
*ndlp
;
1545 struct lpfc_node_rrq
*rrq
;
1547 /* we pass cmdiocb to state machine which needs rspiocb as well */
1548 rrq
= cmdiocb
->context_un
.rrq
;
1549 cmdiocb
->context_un
.rsp_iocb
= rspiocb
;
1551 irsp
= &rspiocb
->iocb
;
1552 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1553 "RRQ cmpl: status:x%x/x%x did:x%x",
1554 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1555 irsp
->un
.elsreq64
.remoteID
);
1557 ndlp
= lpfc_findnode_did(vport
, irsp
->un
.elsreq64
.remoteID
);
1558 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
) || ndlp
!= rrq
->ndlp
) {
1559 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1560 "2882 RRQ completes to NPort x%x "
1561 "with no ndlp. Data: x%x x%x x%x\n",
1562 irsp
->un
.elsreq64
.remoteID
,
1563 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1568 /* rrq completes to NPort <nlp_DID> */
1569 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
1570 "2880 RRQ completes to NPort x%x "
1571 "Data: x%x x%x x%x x%x x%x\n",
1572 ndlp
->nlp_DID
, irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1573 irsp
->ulpTimeout
, rrq
->xritag
, rrq
->rxid
);
1575 if (irsp
->ulpStatus
) {
1576 /* Check for retry */
1577 /* RRQ failed Don't print the vport to vport rjts */
1578 if (irsp
->ulpStatus
!= IOSTAT_LS_RJT
||
1579 (((irsp
->un
.ulpWord
[4]) >> 16 != LSRJT_INVALID_CMD
) &&
1580 ((irsp
->un
.ulpWord
[4]) >> 16 != LSRJT_UNABLE_TPC
)) ||
1581 (phba
)->pport
->cfg_log_verbose
& LOG_ELS
)
1582 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1583 "2881 RRQ failure DID:%06X Status:x%x/x%x\n",
1584 ndlp
->nlp_DID
, irsp
->ulpStatus
,
1585 irsp
->un
.ulpWord
[4]);
1589 lpfc_clr_rrq_active(phba
, rrq
->xritag
, rrq
);
1590 lpfc_els_free_iocb(phba
, cmdiocb
);
1594 * lpfc_cmpl_els_plogi - Completion callback function for plogi
1595 * @phba: pointer to lpfc hba data structure.
1596 * @cmdiocb: pointer to lpfc command iocb data structure.
1597 * @rspiocb: pointer to lpfc response iocb data structure.
1599 * This routine is the completion callback function for issuing the Port
1600 * Login (PLOGI) command. For PLOGI completion, there must be an active
1601 * ndlp on the vport node list that matches the remote node ID from the
1602 * PLOGI response IOCB. If such ndlp does not exist, the PLOGI is simply
1603 * ignored and command IOCB released. The PLOGI response IOCB status is
1604 * checked for error conditons. If there is error status reported, PLOGI
1605 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1606 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1607 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1608 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1609 * there are additional N_Port nodes with the vport that need to perform
1610 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1614 lpfc_cmpl_els_plogi(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
1615 struct lpfc_iocbq
*rspiocb
)
1617 struct lpfc_vport
*vport
= cmdiocb
->vport
;
1618 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1620 struct lpfc_nodelist
*ndlp
;
1621 struct lpfc_dmabuf
*prsp
;
1622 int disc
, rc
, did
, type
;
1624 /* we pass cmdiocb to state machine which needs rspiocb as well */
1625 cmdiocb
->context_un
.rsp_iocb
= rspiocb
;
1627 irsp
= &rspiocb
->iocb
;
1628 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1629 "PLOGI cmpl: status:x%x/x%x did:x%x",
1630 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1631 irsp
->un
.elsreq64
.remoteID
);
1633 ndlp
= lpfc_findnode_did(vport
, irsp
->un
.elsreq64
.remoteID
);
1634 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
)) {
1635 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1636 "0136 PLOGI completes to NPort x%x "
1637 "with no ndlp. Data: x%x x%x x%x\n",
1638 irsp
->un
.elsreq64
.remoteID
,
1639 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1644 /* Since ndlp can be freed in the disc state machine, note if this node
1645 * is being used during discovery.
1647 spin_lock_irq(shost
->host_lock
);
1648 disc
= (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
);
1649 ndlp
->nlp_flag
&= ~NLP_NPR_2B_DISC
;
1650 spin_unlock_irq(shost
->host_lock
);
1653 /* PLOGI completes to NPort <nlp_DID> */
1654 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
1655 "0102 PLOGI completes to NPort x%x "
1656 "Data: x%x x%x x%x x%x x%x\n",
1657 ndlp
->nlp_DID
, irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1658 irsp
->ulpTimeout
, disc
, vport
->num_disc_nodes
);
1659 /* Check to see if link went down during discovery */
1660 if (lpfc_els_chk_latt(vport
)) {
1661 spin_lock_irq(shost
->host_lock
);
1662 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
1663 spin_unlock_irq(shost
->host_lock
);
1667 /* ndlp could be freed in DSM, save these values now */
1668 type
= ndlp
->nlp_type
;
1669 did
= ndlp
->nlp_DID
;
1671 if (irsp
->ulpStatus
) {
1672 /* Check for retry */
1673 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
)) {
1674 /* ELS command is being retried */
1676 spin_lock_irq(shost
->host_lock
);
1677 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
1678 spin_unlock_irq(shost
->host_lock
);
1682 /* PLOGI failed Don't print the vport to vport rjts */
1683 if (irsp
->ulpStatus
!= IOSTAT_LS_RJT
||
1684 (((irsp
->un
.ulpWord
[4]) >> 16 != LSRJT_INVALID_CMD
) &&
1685 ((irsp
->un
.ulpWord
[4]) >> 16 != LSRJT_UNABLE_TPC
)) ||
1686 (phba
)->pport
->cfg_log_verbose
& LOG_ELS
)
1687 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1688 "2753 PLOGI failure DID:%06X Status:x%x/x%x\n",
1689 ndlp
->nlp_DID
, irsp
->ulpStatus
,
1690 irsp
->un
.ulpWord
[4]);
1691 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1692 if (lpfc_error_lost_link(irsp
))
1693 rc
= NLP_STE_FREED_NODE
;
1695 rc
= lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
1696 NLP_EVT_CMPL_PLOGI
);
1698 /* Good status, call state machine */
1699 prsp
= list_entry(((struct lpfc_dmabuf
*)
1700 cmdiocb
->context2
)->list
.next
,
1701 struct lpfc_dmabuf
, list
);
1702 ndlp
= lpfc_plogi_confirm_nport(phba
, prsp
->virt
, ndlp
);
1703 rc
= lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
1704 NLP_EVT_CMPL_PLOGI
);
1707 if (disc
&& vport
->num_disc_nodes
) {
1708 /* Check to see if there are more PLOGIs to be sent */
1709 lpfc_more_plogi(vport
);
1711 if (vport
->num_disc_nodes
== 0) {
1712 spin_lock_irq(shost
->host_lock
);
1713 vport
->fc_flag
&= ~FC_NDISC_ACTIVE
;
1714 spin_unlock_irq(shost
->host_lock
);
1716 lpfc_can_disctmo(vport
);
1717 lpfc_end_rscn(vport
);
1722 lpfc_els_free_iocb(phba
, cmdiocb
);
1727 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
1728 * @vport: pointer to a host virtual N_Port data structure.
1729 * @did: destination port identifier.
1730 * @retry: number of retries to the command IOCB.
1732 * This routine issues a Port Login (PLOGI) command to a remote N_Port
1733 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
1734 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
1735 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
1736 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
1738 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1739 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1740 * will be stored into the context1 field of the IOCB for the completion
1741 * callback function to the PLOGI ELS command.
1744 * 0 - Successfully issued a plogi for @vport
1745 * 1 - failed to issue a plogi for @vport
1748 lpfc_issue_els_plogi(struct lpfc_vport
*vport
, uint32_t did
, uint8_t retry
)
1750 struct lpfc_hba
*phba
= vport
->phba
;
1751 struct serv_parm
*sp
;
1753 struct lpfc_nodelist
*ndlp
;
1754 struct lpfc_iocbq
*elsiocb
;
1755 struct lpfc_sli
*psli
;
1762 ndlp
= lpfc_findnode_did(vport
, did
);
1763 if (ndlp
&& !NLP_CHK_NODE_ACT(ndlp
))
1766 /* If ndlp is not NULL, we will bump the reference count on it */
1767 cmdsize
= (sizeof(uint32_t) + sizeof(struct serv_parm
));
1768 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
, did
,
1773 icmd
= &elsiocb
->iocb
;
1774 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
1776 /* For PLOGI request, remainder of payload is service parameters */
1777 *((uint32_t *) (pcmd
)) = ELS_CMD_PLOGI
;
1778 pcmd
+= sizeof(uint32_t);
1779 memcpy(pcmd
, &vport
->fc_sparam
, sizeof(struct serv_parm
));
1780 sp
= (struct serv_parm
*) pcmd
;
1783 * If we are a N-port connected to a Fabric, fix-up paramm's so logins
1784 * to device on remote loops work.
1786 if ((vport
->fc_flag
& FC_FABRIC
) && !(vport
->fc_flag
& FC_PUBLIC_LOOP
))
1787 sp
->cmn
.altBbCredit
= 1;
1789 if (sp
->cmn
.fcphLow
< FC_PH_4_3
)
1790 sp
->cmn
.fcphLow
= FC_PH_4_3
;
1792 if (sp
->cmn
.fcphHigh
< FC_PH3
)
1793 sp
->cmn
.fcphHigh
= FC_PH3
;
1795 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1796 "Issue PLOGI: did:x%x",
1799 phba
->fc_stat
.elsXmitPLOGI
++;
1800 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_plogi
;
1801 ret
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
1803 if (ret
== IOCB_ERROR
) {
1804 lpfc_els_free_iocb(phba
, elsiocb
);
1811 * lpfc_cmpl_els_prli - Completion callback function for prli
1812 * @phba: pointer to lpfc hba data structure.
1813 * @cmdiocb: pointer to lpfc command iocb data structure.
1814 * @rspiocb: pointer to lpfc response iocb data structure.
1816 * This routine is the completion callback function for a Process Login
1817 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
1818 * status. If there is error status reported, PRLI retry shall be attempted
1819 * by invoking the lpfc_els_retry() routine. Otherwise, the state
1820 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
1821 * ndlp to mark the PRLI completion.
1824 lpfc_cmpl_els_prli(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
1825 struct lpfc_iocbq
*rspiocb
)
1827 struct lpfc_vport
*vport
= cmdiocb
->vport
;
1828 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1830 struct lpfc_sli
*psli
;
1831 struct lpfc_nodelist
*ndlp
;
1834 /* we pass cmdiocb to state machine which needs rspiocb as well */
1835 cmdiocb
->context_un
.rsp_iocb
= rspiocb
;
1837 irsp
= &(rspiocb
->iocb
);
1838 ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
1839 spin_lock_irq(shost
->host_lock
);
1840 ndlp
->nlp_flag
&= ~NLP_PRLI_SND
;
1841 spin_unlock_irq(shost
->host_lock
);
1843 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1844 "PRLI cmpl: status:x%x/x%x did:x%x",
1845 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1847 /* PRLI completes to NPort <nlp_DID> */
1848 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
1849 "0103 PRLI completes to NPort x%x "
1850 "Data: x%x x%x x%x x%x\n",
1851 ndlp
->nlp_DID
, irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1852 irsp
->ulpTimeout
, vport
->num_disc_nodes
);
1854 vport
->fc_prli_sent
--;
1855 /* Check to see if link went down during discovery */
1856 if (lpfc_els_chk_latt(vport
))
1859 if (irsp
->ulpStatus
) {
1860 /* Check for retry */
1861 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
)) {
1862 /* ELS command is being retried */
1866 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1867 "2754 PRLI failure DID:%06X Status:x%x/x%x\n",
1868 ndlp
->nlp_DID
, irsp
->ulpStatus
,
1869 irsp
->un
.ulpWord
[4]);
1870 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1871 if (lpfc_error_lost_link(irsp
))
1874 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
1877 /* Good status, call state machine */
1878 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
1881 lpfc_els_free_iocb(phba
, cmdiocb
);
1886 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
1887 * @vport: pointer to a host virtual N_Port data structure.
1888 * @ndlp: pointer to a node-list data structure.
1889 * @retry: number of retries to the command IOCB.
1891 * This routine issues a Process Login (PRLI) ELS command for the
1892 * @vport. The PRLI service parameters are set up in the payload of the
1893 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
1894 * is put to the IOCB completion callback func field before invoking the
1895 * routine lpfc_sli_issue_iocb() to send out PRLI command.
1897 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1898 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1899 * will be stored into the context1 field of the IOCB for the completion
1900 * callback function to the PRLI ELS command.
1903 * 0 - successfully issued prli iocb command for @vport
1904 * 1 - failed to issue prli iocb command for @vport
1907 lpfc_issue_els_prli(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1910 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1911 struct lpfc_hba
*phba
= vport
->phba
;
1914 struct lpfc_iocbq
*elsiocb
;
1918 cmdsize
= (sizeof(uint32_t) + sizeof(PRLI
));
1919 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
1920 ndlp
->nlp_DID
, ELS_CMD_PRLI
);
1924 icmd
= &elsiocb
->iocb
;
1925 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
1927 /* For PRLI request, remainder of payload is service parameters */
1928 memset(pcmd
, 0, (sizeof(PRLI
) + sizeof(uint32_t)));
1929 *((uint32_t *) (pcmd
)) = ELS_CMD_PRLI
;
1930 pcmd
+= sizeof(uint32_t);
1932 /* For PRLI, remainder of payload is PRLI parameter page */
1933 npr
= (PRLI
*) pcmd
;
1935 * If our firmware version is 3.20 or later,
1936 * set the following bits for FC-TAPE support.
1938 if (phba
->vpd
.rev
.feaLevelHigh
>= 0x02) {
1939 npr
->ConfmComplAllowed
= 1;
1941 npr
->TaskRetryIdReq
= 1;
1943 npr
->estabImagePair
= 1;
1944 npr
->readXferRdyDis
= 1;
1946 /* For FCP support */
1947 npr
->prliType
= PRLI_FCP_TYPE
;
1948 npr
->initiatorFunc
= 1;
1950 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1951 "Issue PRLI: did:x%x",
1952 ndlp
->nlp_DID
, 0, 0);
1954 phba
->fc_stat
.elsXmitPRLI
++;
1955 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_prli
;
1956 spin_lock_irq(shost
->host_lock
);
1957 ndlp
->nlp_flag
|= NLP_PRLI_SND
;
1958 spin_unlock_irq(shost
->host_lock
);
1959 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) ==
1961 spin_lock_irq(shost
->host_lock
);
1962 ndlp
->nlp_flag
&= ~NLP_PRLI_SND
;
1963 spin_unlock_irq(shost
->host_lock
);
1964 lpfc_els_free_iocb(phba
, elsiocb
);
1967 vport
->fc_prli_sent
++;
1972 * lpfc_rscn_disc - Perform rscn discovery for a vport
1973 * @vport: pointer to a host virtual N_Port data structure.
1975 * This routine performs Registration State Change Notification (RSCN)
1976 * discovery for a @vport. If the @vport's node port recovery count is not
1977 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
1978 * the nodes that need recovery. If none of the PLOGI were needed through
1979 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
1980 * invoked to check and handle possible more RSCN came in during the period
1981 * of processing the current ones.
1984 lpfc_rscn_disc(struct lpfc_vport
*vport
)
1986 lpfc_can_disctmo(vport
);
1988 /* RSCN discovery */
1989 /* go thru NPR nodes and issue ELS PLOGIs */
1990 if (vport
->fc_npr_cnt
)
1991 if (lpfc_els_disc_plogi(vport
))
1994 lpfc_end_rscn(vport
);
1998 * lpfc_adisc_done - Complete the adisc phase of discovery
1999 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
2001 * This function is called when the final ADISC is completed during discovery.
2002 * This function handles clearing link attention or issuing reg_vpi depending
2003 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
2005 * This function is called with no locks held.
2008 lpfc_adisc_done(struct lpfc_vport
*vport
)
2010 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2011 struct lpfc_hba
*phba
= vport
->phba
;
2014 * For NPIV, cmpl_reg_vpi will set port_state to READY,
2015 * and continue discovery.
2017 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
2018 !(vport
->fc_flag
& FC_RSCN_MODE
) &&
2019 (phba
->sli_rev
< LPFC_SLI_REV4
)) {
2020 lpfc_issue_reg_vpi(phba
, vport
);
2024 * For SLI2, we need to set port_state to READY
2025 * and continue discovery.
2027 if (vport
->port_state
< LPFC_VPORT_READY
) {
2028 /* If we get here, there is nothing to ADISC */
2029 if (vport
->port_type
== LPFC_PHYSICAL_PORT
)
2030 lpfc_issue_clear_la(phba
, vport
);
2031 if (!(vport
->fc_flag
& FC_ABORT_DISCOVERY
)) {
2032 vport
->num_disc_nodes
= 0;
2033 /* go thru NPR list, issue ELS PLOGIs */
2034 if (vport
->fc_npr_cnt
)
2035 lpfc_els_disc_plogi(vport
);
2036 if (!vport
->num_disc_nodes
) {
2037 spin_lock_irq(shost
->host_lock
);
2038 vport
->fc_flag
&= ~FC_NDISC_ACTIVE
;
2039 spin_unlock_irq(shost
->host_lock
);
2040 lpfc_can_disctmo(vport
);
2041 lpfc_end_rscn(vport
);
2044 vport
->port_state
= LPFC_VPORT_READY
;
2046 lpfc_rscn_disc(vport
);
2050 * lpfc_more_adisc - Issue more adisc as needed
2051 * @vport: pointer to a host virtual N_Port data structure.
2053 * This routine determines whether there are more ndlps on a @vport
2054 * node list need to have Address Discover (ADISC) issued. If so, it will
2055 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
2056 * remaining nodes which need to have ADISC sent.
2059 lpfc_more_adisc(struct lpfc_vport
*vport
)
2063 if (vport
->num_disc_nodes
)
2064 vport
->num_disc_nodes
--;
2065 /* Continue discovery with <num_disc_nodes> ADISCs to go */
2066 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
2067 "0210 Continue discovery with %d ADISCs to go "
2068 "Data: x%x x%x x%x\n",
2069 vport
->num_disc_nodes
, vport
->fc_adisc_cnt
,
2070 vport
->fc_flag
, vport
->port_state
);
2071 /* Check to see if there are more ADISCs to be sent */
2072 if (vport
->fc_flag
& FC_NLP_MORE
) {
2073 lpfc_set_disctmo(vport
);
2074 /* go thru NPR nodes and issue any remaining ELS ADISCs */
2075 sentadisc
= lpfc_els_disc_adisc(vport
);
2077 if (!vport
->num_disc_nodes
)
2078 lpfc_adisc_done(vport
);
2083 * lpfc_cmpl_els_adisc - Completion callback function for adisc
2084 * @phba: pointer to lpfc hba data structure.
2085 * @cmdiocb: pointer to lpfc command iocb data structure.
2086 * @rspiocb: pointer to lpfc response iocb data structure.
2088 * This routine is the completion function for issuing the Address Discover
2089 * (ADISC) command. It first checks to see whether link went down during
2090 * the discovery process. If so, the node will be marked as node port
2091 * recovery for issuing discover IOCB by the link attention handler and
2092 * exit. Otherwise, the response status is checked. If error was reported
2093 * in the response status, the ADISC command shall be retried by invoking
2094 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
2095 * the response status, the state machine is invoked to set transition
2096 * with respect to NLP_EVT_CMPL_ADISC event.
2099 lpfc_cmpl_els_adisc(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
2100 struct lpfc_iocbq
*rspiocb
)
2102 struct lpfc_vport
*vport
= cmdiocb
->vport
;
2103 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2105 struct lpfc_nodelist
*ndlp
;
2108 /* we pass cmdiocb to state machine which needs rspiocb as well */
2109 cmdiocb
->context_un
.rsp_iocb
= rspiocb
;
2111 irsp
= &(rspiocb
->iocb
);
2112 ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
2114 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2115 "ADISC cmpl: status:x%x/x%x did:x%x",
2116 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
2119 /* Since ndlp can be freed in the disc state machine, note if this node
2120 * is being used during discovery.
2122 spin_lock_irq(shost
->host_lock
);
2123 disc
= (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
);
2124 ndlp
->nlp_flag
&= ~(NLP_ADISC_SND
| NLP_NPR_2B_DISC
);
2125 spin_unlock_irq(shost
->host_lock
);
2126 /* ADISC completes to NPort <nlp_DID> */
2127 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
2128 "0104 ADISC completes to NPort x%x "
2129 "Data: x%x x%x x%x x%x x%x\n",
2130 ndlp
->nlp_DID
, irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
2131 irsp
->ulpTimeout
, disc
, vport
->num_disc_nodes
);
2132 /* Check to see if link went down during discovery */
2133 if (lpfc_els_chk_latt(vport
)) {
2134 spin_lock_irq(shost
->host_lock
);
2135 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
2136 spin_unlock_irq(shost
->host_lock
);
2140 if (irsp
->ulpStatus
) {
2141 /* Check for retry */
2142 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
)) {
2143 /* ELS command is being retried */
2145 spin_lock_irq(shost
->host_lock
);
2146 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
2147 spin_unlock_irq(shost
->host_lock
);
2148 lpfc_set_disctmo(vport
);
2153 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
2154 "2755 ADISC failure DID:%06X Status:x%x/x%x\n",
2155 ndlp
->nlp_DID
, irsp
->ulpStatus
,
2156 irsp
->un
.ulpWord
[4]);
2157 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2158 if (!lpfc_error_lost_link(irsp
))
2159 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
2160 NLP_EVT_CMPL_ADISC
);
2162 /* Good status, call state machine */
2163 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
2164 NLP_EVT_CMPL_ADISC
);
2166 /* Check to see if there are more ADISCs to be sent */
2167 if (disc
&& vport
->num_disc_nodes
)
2168 lpfc_more_adisc(vport
);
2170 lpfc_els_free_iocb(phba
, cmdiocb
);
2175 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
2176 * @vport: pointer to a virtual N_Port data structure.
2177 * @ndlp: pointer to a node-list data structure.
2178 * @retry: number of retries to the command IOCB.
2180 * This routine issues an Address Discover (ADISC) for an @ndlp on a
2181 * @vport. It prepares the payload of the ADISC ELS command, updates the
2182 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
2183 * to issue the ADISC ELS command.
2185 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2186 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2187 * will be stored into the context1 field of the IOCB for the completion
2188 * callback function to the ADISC ELS command.
2191 * 0 - successfully issued adisc
2192 * 1 - failed to issue adisc
2195 lpfc_issue_els_adisc(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2198 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2199 struct lpfc_hba
*phba
= vport
->phba
;
2202 struct lpfc_iocbq
*elsiocb
;
2206 cmdsize
= (sizeof(uint32_t) + sizeof(ADISC
));
2207 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
2208 ndlp
->nlp_DID
, ELS_CMD_ADISC
);
2212 icmd
= &elsiocb
->iocb
;
2213 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
2215 /* For ADISC request, remainder of payload is service parameters */
2216 *((uint32_t *) (pcmd
)) = ELS_CMD_ADISC
;
2217 pcmd
+= sizeof(uint32_t);
2219 /* Fill in ADISC payload */
2220 ap
= (ADISC
*) pcmd
;
2221 ap
->hardAL_PA
= phba
->fc_pref_ALPA
;
2222 memcpy(&ap
->portName
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
2223 memcpy(&ap
->nodeName
, &vport
->fc_nodename
, sizeof(struct lpfc_name
));
2224 ap
->DID
= be32_to_cpu(vport
->fc_myDID
);
2226 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2227 "Issue ADISC: did:x%x",
2228 ndlp
->nlp_DID
, 0, 0);
2230 phba
->fc_stat
.elsXmitADISC
++;
2231 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_adisc
;
2232 spin_lock_irq(shost
->host_lock
);
2233 ndlp
->nlp_flag
|= NLP_ADISC_SND
;
2234 spin_unlock_irq(shost
->host_lock
);
2235 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) ==
2237 spin_lock_irq(shost
->host_lock
);
2238 ndlp
->nlp_flag
&= ~NLP_ADISC_SND
;
2239 spin_unlock_irq(shost
->host_lock
);
2240 lpfc_els_free_iocb(phba
, elsiocb
);
2247 * lpfc_cmpl_els_logo - Completion callback function for logo
2248 * @phba: pointer to lpfc hba data structure.
2249 * @cmdiocb: pointer to lpfc command iocb data structure.
2250 * @rspiocb: pointer to lpfc response iocb data structure.
2252 * This routine is the completion function for issuing the ELS Logout (LOGO)
2253 * command. If no error status was reported from the LOGO response, the
2254 * state machine of the associated ndlp shall be invoked for transition with
2255 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
2256 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
2259 lpfc_cmpl_els_logo(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
2260 struct lpfc_iocbq
*rspiocb
)
2262 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
2263 struct lpfc_vport
*vport
= ndlp
->vport
;
2264 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2266 struct lpfc_sli
*psli
;
2267 struct lpfcMboxq
*mbox
;
2270 /* we pass cmdiocb to state machine which needs rspiocb as well */
2271 cmdiocb
->context_un
.rsp_iocb
= rspiocb
;
2273 irsp
= &(rspiocb
->iocb
);
2274 spin_lock_irq(shost
->host_lock
);
2275 ndlp
->nlp_flag
&= ~NLP_LOGO_SND
;
2276 spin_unlock_irq(shost
->host_lock
);
2278 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2279 "LOGO cmpl: status:x%x/x%x did:x%x",
2280 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
2282 /* LOGO completes to NPort <nlp_DID> */
2283 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
2284 "0105 LOGO completes to NPort x%x "
2285 "Data: x%x x%x x%x x%x\n",
2286 ndlp
->nlp_DID
, irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
2287 irsp
->ulpTimeout
, vport
->num_disc_nodes
);
2288 /* Check to see if link went down during discovery */
2289 if (lpfc_els_chk_latt(vport
))
2292 if (ndlp
->nlp_flag
& NLP_TARGET_REMOVE
) {
2293 /* NLP_EVT_DEVICE_RM should unregister the RPI
2294 * which should abort all outstanding IOs.
2296 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
2301 if (irsp
->ulpStatus
) {
2302 /* Check for retry */
2303 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
))
2304 /* ELS command is being retried */
2307 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
2308 "2756 LOGO failure DID:%06X Status:x%x/x%x\n",
2309 ndlp
->nlp_DID
, irsp
->ulpStatus
,
2310 irsp
->un
.ulpWord
[4]);
2311 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
2312 if (lpfc_error_lost_link(irsp
))
2315 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
2318 /* Good status, call state machine.
2319 * This will unregister the rpi if needed.
2321 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
2324 lpfc_els_free_iocb(phba
, cmdiocb
);
2325 /* If we are in pt2pt mode, we could rcv new S_ID on PLOGI */
2326 if ((vport
->fc_flag
& FC_PT2PT
) &&
2327 !(vport
->fc_flag
& FC_PT2PT_PLOGI
)) {
2328 phba
->pport
->fc_myDID
= 0;
2329 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
2331 lpfc_config_link(phba
, mbox
);
2332 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
2333 mbox
->vport
= vport
;
2334 if (lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
) ==
2336 mempool_free(mbox
, phba
->mbox_mem_pool
);
2344 * lpfc_issue_els_logo - Issue a logo to an node on a vport
2345 * @vport: pointer to a virtual N_Port data structure.
2346 * @ndlp: pointer to a node-list data structure.
2347 * @retry: number of retries to the command IOCB.
2349 * This routine constructs and issues an ELS Logout (LOGO) iocb command
2350 * to a remote node, referred by an @ndlp on a @vport. It constructs the
2351 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2352 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2354 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2355 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2356 * will be stored into the context1 field of the IOCB for the completion
2357 * callback function to the LOGO ELS command.
2360 * 0 - successfully issued logo
2361 * 1 - failed to issue logo
2364 lpfc_issue_els_logo(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2367 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2368 struct lpfc_hba
*phba
= vport
->phba
;
2370 struct lpfc_iocbq
*elsiocb
;
2375 spin_lock_irq(shost
->host_lock
);
2376 if (ndlp
->nlp_flag
& NLP_LOGO_SND
) {
2377 spin_unlock_irq(shost
->host_lock
);
2380 spin_unlock_irq(shost
->host_lock
);
2382 cmdsize
= (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name
);
2383 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
2384 ndlp
->nlp_DID
, ELS_CMD_LOGO
);
2388 icmd
= &elsiocb
->iocb
;
2389 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
2390 *((uint32_t *) (pcmd
)) = ELS_CMD_LOGO
;
2391 pcmd
+= sizeof(uint32_t);
2393 /* Fill in LOGO payload */
2394 *((uint32_t *) (pcmd
)) = be32_to_cpu(vport
->fc_myDID
);
2395 pcmd
+= sizeof(uint32_t);
2396 memcpy(pcmd
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
2398 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2399 "Issue LOGO: did:x%x",
2400 ndlp
->nlp_DID
, 0, 0);
2402 phba
->fc_stat
.elsXmitLOGO
++;
2403 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_logo
;
2404 spin_lock_irq(shost
->host_lock
);
2405 ndlp
->nlp_flag
|= NLP_LOGO_SND
;
2406 spin_unlock_irq(shost
->host_lock
);
2407 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
2409 if (rc
== IOCB_ERROR
) {
2410 spin_lock_irq(shost
->host_lock
);
2411 ndlp
->nlp_flag
&= ~NLP_LOGO_SND
;
2412 spin_unlock_irq(shost
->host_lock
);
2413 lpfc_els_free_iocb(phba
, elsiocb
);
2420 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
2421 * @phba: pointer to lpfc hba data structure.
2422 * @cmdiocb: pointer to lpfc command iocb data structure.
2423 * @rspiocb: pointer to lpfc response iocb data structure.
2425 * This routine is a generic completion callback function for ELS commands.
2426 * Specifically, it is the callback function which does not need to perform
2427 * any command specific operations. It is currently used by the ELS command
2428 * issuing routines for the ELS State Change Request (SCR),
2429 * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
2430 * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
2431 * certain debug loggings, this callback function simply invokes the
2432 * lpfc_els_chk_latt() routine to check whether link went down during the
2433 * discovery process.
2436 lpfc_cmpl_els_cmd(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
2437 struct lpfc_iocbq
*rspiocb
)
2439 struct lpfc_vport
*vport
= cmdiocb
->vport
;
2442 irsp
= &rspiocb
->iocb
;
2444 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2445 "ELS cmd cmpl: status:x%x/x%x did:x%x",
2446 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
2447 irsp
->un
.elsreq64
.remoteID
);
2448 /* ELS cmd tag <ulpIoTag> completes */
2449 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
2450 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
2451 irsp
->ulpIoTag
, irsp
->ulpStatus
,
2452 irsp
->un
.ulpWord
[4], irsp
->ulpTimeout
);
2453 /* Check to see if link went down during discovery */
2454 lpfc_els_chk_latt(vport
);
2455 lpfc_els_free_iocb(phba
, cmdiocb
);
2460 * lpfc_issue_els_scr - Issue a scr to an node on a vport
2461 * @vport: pointer to a host virtual N_Port data structure.
2462 * @nportid: N_Port identifier to the remote node.
2463 * @retry: number of retries to the command IOCB.
2465 * This routine issues a State Change Request (SCR) to a fabric node
2466 * on a @vport. The remote node @nportid is passed into the function. It
2467 * first search the @vport node list to find the matching ndlp. If no such
2468 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
2469 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
2470 * routine is invoked to send the SCR IOCB.
2472 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2473 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2474 * will be stored into the context1 field of the IOCB for the completion
2475 * callback function to the SCR ELS command.
2478 * 0 - Successfully issued scr command
2479 * 1 - Failed to issue scr command
2482 lpfc_issue_els_scr(struct lpfc_vport
*vport
, uint32_t nportid
, uint8_t retry
)
2484 struct lpfc_hba
*phba
= vport
->phba
;
2486 struct lpfc_iocbq
*elsiocb
;
2487 struct lpfc_sli
*psli
;
2490 struct lpfc_nodelist
*ndlp
;
2493 cmdsize
= (sizeof(uint32_t) + sizeof(SCR
));
2495 ndlp
= lpfc_findnode_did(vport
, nportid
);
2497 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
2500 lpfc_nlp_init(vport
, ndlp
, nportid
);
2501 lpfc_enqueue_node(vport
, ndlp
);
2502 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
2503 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
2508 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
2509 ndlp
->nlp_DID
, ELS_CMD_SCR
);
2512 /* This will trigger the release of the node just
2519 icmd
= &elsiocb
->iocb
;
2520 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
2522 *((uint32_t *) (pcmd
)) = ELS_CMD_SCR
;
2523 pcmd
+= sizeof(uint32_t);
2525 /* For SCR, remainder of payload is SCR parameter page */
2526 memset(pcmd
, 0, sizeof(SCR
));
2527 ((SCR
*) pcmd
)->Function
= SCR_FUNC_FULL
;
2529 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2530 "Issue SCR: did:x%x",
2531 ndlp
->nlp_DID
, 0, 0);
2533 phba
->fc_stat
.elsXmitSCR
++;
2534 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_cmd
;
2535 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) ==
2537 /* The additional lpfc_nlp_put will cause the following
2538 * lpfc_els_free_iocb routine to trigger the rlease of
2542 lpfc_els_free_iocb(phba
, elsiocb
);
2545 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2546 * trigger the release of node.
2553 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
2554 * @vport: pointer to a host virtual N_Port data structure.
2555 * @nportid: N_Port identifier to the remote node.
2556 * @retry: number of retries to the command IOCB.
2558 * This routine issues a Fibre Channel Address Resolution Response
2559 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
2560 * is passed into the function. It first search the @vport node list to find
2561 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
2562 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
2563 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
2565 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2566 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2567 * will be stored into the context1 field of the IOCB for the completion
2568 * callback function to the PARPR ELS command.
2571 * 0 - Successfully issued farpr command
2572 * 1 - Failed to issue farpr command
2575 lpfc_issue_els_farpr(struct lpfc_vport
*vport
, uint32_t nportid
, uint8_t retry
)
2577 struct lpfc_hba
*phba
= vport
->phba
;
2579 struct lpfc_iocbq
*elsiocb
;
2580 struct lpfc_sli
*psli
;
2585 struct lpfc_nodelist
*ondlp
;
2586 struct lpfc_nodelist
*ndlp
;
2589 cmdsize
= (sizeof(uint32_t) + sizeof(FARP
));
2591 ndlp
= lpfc_findnode_did(vport
, nportid
);
2593 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
2596 lpfc_nlp_init(vport
, ndlp
, nportid
);
2597 lpfc_enqueue_node(vport
, ndlp
);
2598 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
2599 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
2604 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
2605 ndlp
->nlp_DID
, ELS_CMD_RNID
);
2607 /* This will trigger the release of the node just
2614 icmd
= &elsiocb
->iocb
;
2615 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
2617 *((uint32_t *) (pcmd
)) = ELS_CMD_FARPR
;
2618 pcmd
+= sizeof(uint32_t);
2620 /* Fill in FARPR payload */
2621 fp
= (FARP
*) (pcmd
);
2622 memset(fp
, 0, sizeof(FARP
));
2623 lp
= (uint32_t *) pcmd
;
2624 *lp
++ = be32_to_cpu(nportid
);
2625 *lp
++ = be32_to_cpu(vport
->fc_myDID
);
2627 fp
->Mflags
= (FARP_MATCH_PORT
| FARP_MATCH_NODE
);
2629 memcpy(&fp
->RportName
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
2630 memcpy(&fp
->RnodeName
, &vport
->fc_nodename
, sizeof(struct lpfc_name
));
2631 ondlp
= lpfc_findnode_did(vport
, nportid
);
2632 if (ondlp
&& NLP_CHK_NODE_ACT(ondlp
)) {
2633 memcpy(&fp
->OportName
, &ondlp
->nlp_portname
,
2634 sizeof(struct lpfc_name
));
2635 memcpy(&fp
->OnodeName
, &ondlp
->nlp_nodename
,
2636 sizeof(struct lpfc_name
));
2639 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2640 "Issue FARPR: did:x%x",
2641 ndlp
->nlp_DID
, 0, 0);
2643 phba
->fc_stat
.elsXmitFARPR
++;
2644 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_cmd
;
2645 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) ==
2647 /* The additional lpfc_nlp_put will cause the following
2648 * lpfc_els_free_iocb routine to trigger the release of
2652 lpfc_els_free_iocb(phba
, elsiocb
);
2655 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2656 * trigger the release of the node.
2663 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
2664 * @vport: pointer to a host virtual N_Port data structure.
2665 * @nlp: pointer to a node-list data structure.
2667 * This routine cancels the timer with a delayed IOCB-command retry for
2668 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
2669 * removes the ELS retry event if it presents. In addition, if the
2670 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
2671 * commands are sent for the @vport's nodes that require issuing discovery
2675 lpfc_cancel_retry_delay_tmo(struct lpfc_vport
*vport
, struct lpfc_nodelist
*nlp
)
2677 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2678 struct lpfc_work_evt
*evtp
;
2680 if (!(nlp
->nlp_flag
& NLP_DELAY_TMO
))
2682 spin_lock_irq(shost
->host_lock
);
2683 nlp
->nlp_flag
&= ~NLP_DELAY_TMO
;
2684 spin_unlock_irq(shost
->host_lock
);
2685 del_timer_sync(&nlp
->nlp_delayfunc
);
2686 nlp
->nlp_last_elscmd
= 0;
2687 if (!list_empty(&nlp
->els_retry_evt
.evt_listp
)) {
2688 list_del_init(&nlp
->els_retry_evt
.evt_listp
);
2689 /* Decrement nlp reference count held for the delayed retry */
2690 evtp
= &nlp
->els_retry_evt
;
2691 lpfc_nlp_put((struct lpfc_nodelist
*)evtp
->evt_arg1
);
2693 if (nlp
->nlp_flag
& NLP_NPR_2B_DISC
) {
2694 spin_lock_irq(shost
->host_lock
);
2695 nlp
->nlp_flag
&= ~NLP_NPR_2B_DISC
;
2696 spin_unlock_irq(shost
->host_lock
);
2697 if (vport
->num_disc_nodes
) {
2698 if (vport
->port_state
< LPFC_VPORT_READY
) {
2699 /* Check if there are more ADISCs to be sent */
2700 lpfc_more_adisc(vport
);
2702 /* Check if there are more PLOGIs to be sent */
2703 lpfc_more_plogi(vport
);
2704 if (vport
->num_disc_nodes
== 0) {
2705 spin_lock_irq(shost
->host_lock
);
2706 vport
->fc_flag
&= ~FC_NDISC_ACTIVE
;
2707 spin_unlock_irq(shost
->host_lock
);
2708 lpfc_can_disctmo(vport
);
2709 lpfc_end_rscn(vport
);
2718 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
2719 * @ptr: holder for the pointer to the timer function associated data (ndlp).
2721 * This routine is invoked by the ndlp delayed-function timer to check
2722 * whether there is any pending ELS retry event(s) with the node. If not, it
2723 * simply returns. Otherwise, if there is at least one ELS delayed event, it
2724 * adds the delayed events to the HBA work list and invokes the
2725 * lpfc_worker_wake_up() routine to wake up worker thread to process the
2726 * event. Note that lpfc_nlp_get() is called before posting the event to
2727 * the work list to hold reference count of ndlp so that it guarantees the
2728 * reference to ndlp will still be available when the worker thread gets
2729 * to the event associated with the ndlp.
2732 lpfc_els_retry_delay(unsigned long ptr
)
2734 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) ptr
;
2735 struct lpfc_vport
*vport
= ndlp
->vport
;
2736 struct lpfc_hba
*phba
= vport
->phba
;
2737 unsigned long flags
;
2738 struct lpfc_work_evt
*evtp
= &ndlp
->els_retry_evt
;
2740 spin_lock_irqsave(&phba
->hbalock
, flags
);
2741 if (!list_empty(&evtp
->evt_listp
)) {
2742 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
2746 /* We need to hold the node by incrementing the reference
2747 * count until the queued work is done
2749 evtp
->evt_arg1
= lpfc_nlp_get(ndlp
);
2750 if (evtp
->evt_arg1
) {
2751 evtp
->evt
= LPFC_EVT_ELS_RETRY
;
2752 list_add_tail(&evtp
->evt_listp
, &phba
->work_list
);
2753 lpfc_worker_wake_up(phba
);
2755 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
2760 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
2761 * @ndlp: pointer to a node-list data structure.
2763 * This routine is the worker-thread handler for processing the @ndlp delayed
2764 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
2765 * the last ELS command from the associated ndlp and invokes the proper ELS
2766 * function according to the delayed ELS command to retry the command.
2769 lpfc_els_retry_delay_handler(struct lpfc_nodelist
*ndlp
)
2771 struct lpfc_vport
*vport
= ndlp
->vport
;
2772 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2773 uint32_t cmd
, did
, retry
;
2775 spin_lock_irq(shost
->host_lock
);
2776 did
= ndlp
->nlp_DID
;
2777 cmd
= ndlp
->nlp_last_elscmd
;
2778 ndlp
->nlp_last_elscmd
= 0;
2780 if (!(ndlp
->nlp_flag
& NLP_DELAY_TMO
)) {
2781 spin_unlock_irq(shost
->host_lock
);
2785 ndlp
->nlp_flag
&= ~NLP_DELAY_TMO
;
2786 spin_unlock_irq(shost
->host_lock
);
2788 * If a discovery event readded nlp_delayfunc after timer
2789 * firing and before processing the timer, cancel the
2792 del_timer_sync(&ndlp
->nlp_delayfunc
);
2793 retry
= ndlp
->nlp_retry
;
2794 ndlp
->nlp_retry
= 0;
2798 lpfc_issue_els_flogi(vport
, ndlp
, retry
);
2801 if (!lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, retry
)) {
2802 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
2803 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
2807 if (!lpfc_issue_els_adisc(vport
, ndlp
, retry
)) {
2808 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
2809 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_ADISC_ISSUE
);
2813 if (!lpfc_issue_els_prli(vport
, ndlp
, retry
)) {
2814 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
2815 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PRLI_ISSUE
);
2819 if (!lpfc_issue_els_logo(vport
, ndlp
, retry
)) {
2820 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
2821 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
2825 if (!(vport
->fc_flag
& FC_VPORT_NEEDS_INIT_VPI
))
2826 lpfc_issue_els_fdisc(vport
, ndlp
, retry
);
2833 * lpfc_els_retry - Make retry decision on an els command iocb
2834 * @phba: pointer to lpfc hba data structure.
2835 * @cmdiocb: pointer to lpfc command iocb data structure.
2836 * @rspiocb: pointer to lpfc response iocb data structure.
2838 * This routine makes a retry decision on an ELS command IOCB, which has
2839 * failed. The following ELS IOCBs use this function for retrying the command
2840 * when previously issued command responsed with error status: FLOGI, PLOGI,
2841 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
2842 * returned error status, it makes the decision whether a retry shall be
2843 * issued for the command, and whether a retry shall be made immediately or
2844 * delayed. In the former case, the corresponding ELS command issuing-function
2845 * is called to retry the command. In the later case, the ELS command shall
2846 * be posted to the ndlp delayed event and delayed function timer set to the
2847 * ndlp for the delayed command issusing.
2850 * 0 - No retry of els command is made
2851 * 1 - Immediate or delayed retry of els command is made
2854 lpfc_els_retry(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
2855 struct lpfc_iocbq
*rspiocb
)
2857 struct lpfc_vport
*vport
= cmdiocb
->vport
;
2858 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2859 IOCB_t
*irsp
= &rspiocb
->iocb
;
2860 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
2861 struct lpfc_dmabuf
*pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
2864 int retry
= 0, maxretry
= lpfc_max_els_tries
, delay
= 0;
2870 /* Note: context2 may be 0 for internal driver abort
2871 * of delays ELS command.
2874 if (pcmd
&& pcmd
->virt
) {
2875 elscmd
= (uint32_t *) (pcmd
->virt
);
2879 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
))
2880 did
= ndlp
->nlp_DID
;
2882 /* We should only hit this case for retrying PLOGI */
2883 did
= irsp
->un
.elsreq64
.remoteID
;
2884 ndlp
= lpfc_findnode_did(vport
, did
);
2885 if ((!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
))
2886 && (cmd
!= ELS_CMD_PLOGI
))
2890 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2891 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
2892 *(((uint32_t *) irsp
) + 7), irsp
->un
.ulpWord
[4], ndlp
->nlp_DID
);
2894 switch (irsp
->ulpStatus
) {
2895 case IOSTAT_FCP_RSP_ERROR
:
2897 case IOSTAT_REMOTE_STOP
:
2898 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
2899 /* This IO was aborted by the target, we don't
2900 * know the rxid and because we did not send the
2901 * ABTS we cannot generate and RRQ.
2903 lpfc_set_rrq_active(phba
, ndlp
,
2904 cmdiocb
->sli4_xritag
, 0, 0);
2907 case IOSTAT_LOCAL_REJECT
:
2908 switch ((irsp
->un
.ulpWord
[4] & 0xff)) {
2909 case IOERR_LOOP_OPEN_FAILURE
:
2910 if (cmd
== ELS_CMD_FLOGI
) {
2911 if (PCI_DEVICE_ID_HORNET
==
2912 phba
->pcidev
->device
) {
2913 phba
->fc_topology
= LPFC_TOPOLOGY_LOOP
;
2914 phba
->pport
->fc_myDID
= 0;
2915 phba
->alpa_map
[0] = 0;
2916 phba
->alpa_map
[1] = 0;
2919 if (cmd
== ELS_CMD_PLOGI
&& cmdiocb
->retry
== 0)
2924 case IOERR_ILLEGAL_COMMAND
:
2925 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
2926 "0124 Retry illegal cmd x%x "
2927 "retry:x%x delay:x%x\n",
2928 cmd
, cmdiocb
->retry
, delay
);
2930 /* All command's retry policy */
2932 if (cmdiocb
->retry
> 2)
2936 case IOERR_NO_RESOURCES
:
2937 logerr
= 1; /* HBA out of resources */
2939 if (cmdiocb
->retry
> 100)
2944 case IOERR_ILLEGAL_FRAME
:
2949 case IOERR_SEQUENCE_TIMEOUT
:
2950 case IOERR_INVALID_RPI
:
2956 case IOSTAT_NPORT_RJT
:
2957 case IOSTAT_FABRIC_RJT
:
2958 if (irsp
->un
.ulpWord
[4] & RJT_UNAVAIL_TEMP
) {
2964 case IOSTAT_NPORT_BSY
:
2965 case IOSTAT_FABRIC_BSY
:
2966 logerr
= 1; /* Fabric / Remote NPort out of resources */
2971 stat
.un
.lsRjtError
= be32_to_cpu(irsp
->un
.ulpWord
[4]);
2972 /* Added for Vendor specifc support
2973 * Just keep retrying for these Rsn / Exp codes
2975 switch (stat
.un
.b
.lsRjtRsnCode
) {
2976 case LSRJT_UNABLE_TPC
:
2977 if (stat
.un
.b
.lsRjtRsnCodeExp
==
2978 LSEXP_CMD_IN_PROGRESS
) {
2979 if (cmd
== ELS_CMD_PLOGI
) {
2986 if (stat
.un
.b
.lsRjtRsnCodeExp
==
2987 LSEXP_CANT_GIVE_DATA
) {
2988 if (cmd
== ELS_CMD_PLOGI
) {
2995 if (cmd
== ELS_CMD_PLOGI
) {
2997 maxretry
= lpfc_max_els_tries
+ 1;
3001 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
3002 (cmd
== ELS_CMD_FDISC
) &&
3003 (stat
.un
.b
.lsRjtRsnCodeExp
== LSEXP_OUT_OF_RESOURCE
)){
3004 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
3005 "0125 FDISC Failed (x%x). "
3006 "Fabric out of resources\n",
3007 stat
.un
.lsRjtError
);
3008 lpfc_vport_set_state(vport
,
3009 FC_VPORT_NO_FABRIC_RSCS
);
3013 case LSRJT_LOGICAL_BSY
:
3014 if ((cmd
== ELS_CMD_PLOGI
) ||
3015 (cmd
== ELS_CMD_PRLI
)) {
3018 } else if (cmd
== ELS_CMD_FDISC
) {
3019 /* FDISC retry policy */
3021 if (cmdiocb
->retry
>= 32)
3027 case LSRJT_LOGICAL_ERR
:
3028 /* There are some cases where switches return this
3029 * error when they are not ready and should be returning
3030 * Logical Busy. We should delay every time.
3032 if (cmd
== ELS_CMD_FDISC
&&
3033 stat
.un
.b
.lsRjtRsnCodeExp
== LSEXP_PORT_LOGIN_REQ
) {
3039 case LSRJT_PROTOCOL_ERR
:
3040 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
3041 (cmd
== ELS_CMD_FDISC
) &&
3042 ((stat
.un
.b
.lsRjtRsnCodeExp
== LSEXP_INVALID_PNAME
) ||
3043 (stat
.un
.b
.lsRjtRsnCodeExp
== LSEXP_INVALID_NPORT_ID
))
3045 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
3046 "0122 FDISC Failed (x%x). "
3047 "Fabric Detected Bad WWN\n",
3048 stat
.un
.lsRjtError
);
3049 lpfc_vport_set_state(vport
,
3050 FC_VPORT_FABRIC_REJ_WWN
);
3056 case IOSTAT_INTERMED_RSP
:
3064 if (did
== FDMI_DID
)
3067 if (((cmd
== ELS_CMD_FLOGI
) || (cmd
== ELS_CMD_FDISC
)) &&
3068 (phba
->fc_topology
!= LPFC_TOPOLOGY_LOOP
) &&
3069 !lpfc_error_lost_link(irsp
)) {
3070 /* FLOGI retry policy */
3074 if (cmdiocb
->retry
>= 100)
3076 else if (cmdiocb
->retry
>= 32)
3081 if (maxretry
&& (cmdiocb
->retry
>= maxretry
)) {
3082 phba
->fc_stat
.elsRetryExceeded
++;
3086 if ((vport
->load_flag
& FC_UNLOADING
) != 0)
3090 if ((cmd
== ELS_CMD_PLOGI
) || (cmd
== ELS_CMD_FDISC
)) {
3091 /* Stop retrying PLOGI and FDISC if in FCF discovery */
3092 if (phba
->fcf
.fcf_flag
& FCF_DISCOVERY
) {
3093 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3094 "2849 Stop retry ELS command "
3095 "x%x to remote NPORT x%x, "
3096 "Data: x%x x%x\n", cmd
, did
,
3097 cmdiocb
->retry
, delay
);
3102 /* Retry ELS command <elsCmd> to remote NPORT <did> */
3103 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3104 "0107 Retry ELS command x%x to remote "
3105 "NPORT x%x Data: x%x x%x\n",
3106 cmd
, did
, cmdiocb
->retry
, delay
);
3108 if (((cmd
== ELS_CMD_PLOGI
) || (cmd
== ELS_CMD_ADISC
)) &&
3109 ((irsp
->ulpStatus
!= IOSTAT_LOCAL_REJECT
) ||
3110 ((irsp
->un
.ulpWord
[4] & 0xff) != IOERR_NO_RESOURCES
))) {
3111 /* Don't reset timer for no resources */
3113 /* If discovery / RSCN timer is running, reset it */
3114 if (timer_pending(&vport
->fc_disctmo
) ||
3115 (vport
->fc_flag
& FC_RSCN_MODE
))
3116 lpfc_set_disctmo(vport
);
3119 phba
->fc_stat
.elsXmitRetry
++;
3120 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
) && delay
) {
3121 phba
->fc_stat
.elsDelayRetry
++;
3122 ndlp
->nlp_retry
= cmdiocb
->retry
;
3124 /* delay is specified in milliseconds */
3125 mod_timer(&ndlp
->nlp_delayfunc
,
3126 jiffies
+ msecs_to_jiffies(delay
));
3127 spin_lock_irq(shost
->host_lock
);
3128 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
3129 spin_unlock_irq(shost
->host_lock
);
3131 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
3132 if (cmd
== ELS_CMD_PRLI
)
3133 lpfc_nlp_set_state(vport
, ndlp
,
3134 NLP_STE_REG_LOGIN_ISSUE
);
3136 lpfc_nlp_set_state(vport
, ndlp
,
3138 ndlp
->nlp_last_elscmd
= cmd
;
3144 lpfc_issue_els_flogi(vport
, ndlp
, cmdiocb
->retry
);
3147 lpfc_issue_els_fdisc(vport
, ndlp
, cmdiocb
->retry
);
3150 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
)) {
3151 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
3152 lpfc_nlp_set_state(vport
, ndlp
,
3153 NLP_STE_PLOGI_ISSUE
);
3155 lpfc_issue_els_plogi(vport
, did
, cmdiocb
->retry
);
3158 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
3159 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_ADISC_ISSUE
);
3160 lpfc_issue_els_adisc(vport
, ndlp
, cmdiocb
->retry
);
3163 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
3164 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PRLI_ISSUE
);
3165 lpfc_issue_els_prli(vport
, ndlp
, cmdiocb
->retry
);
3168 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
3169 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
3170 lpfc_issue_els_logo(vport
, ndlp
, cmdiocb
->retry
);
3174 /* No retry ELS command <elsCmd> to remote NPORT <did> */
3176 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
3177 "0137 No retry ELS command x%x to remote "
3178 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
3179 cmd
, did
, irsp
->ulpStatus
,
3180 irsp
->un
.ulpWord
[4]);
3183 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3184 "0108 No retry ELS command x%x to remote "
3185 "NPORT x%x Retried:%d Error:x%x/%x\n",
3186 cmd
, did
, cmdiocb
->retry
, irsp
->ulpStatus
,
3187 irsp
->un
.ulpWord
[4]);
3193 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
3194 * @phba: pointer to lpfc hba data structure.
3195 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
3197 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
3198 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
3199 * checks to see whether there is a lpfc DMA buffer associated with the
3200 * response of the command IOCB. If so, it will be released before releasing
3201 * the lpfc DMA buffer associated with the IOCB itself.
3204 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3207 lpfc_els_free_data(struct lpfc_hba
*phba
, struct lpfc_dmabuf
*buf_ptr1
)
3209 struct lpfc_dmabuf
*buf_ptr
;
3211 /* Free the response before processing the command. */
3212 if (!list_empty(&buf_ptr1
->list
)) {
3213 list_remove_head(&buf_ptr1
->list
, buf_ptr
,
3216 lpfc_mbuf_free(phba
, buf_ptr
->virt
, buf_ptr
->phys
);
3219 lpfc_mbuf_free(phba
, buf_ptr1
->virt
, buf_ptr1
->phys
);
3225 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
3226 * @phba: pointer to lpfc hba data structure.
3227 * @buf_ptr: pointer to the lpfc dma buffer data structure.
3229 * This routine releases the lpfc Direct Memory Access (DMA) buffer
3230 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
3234 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
3237 lpfc_els_free_bpl(struct lpfc_hba
*phba
, struct lpfc_dmabuf
*buf_ptr
)
3239 lpfc_mbuf_free(phba
, buf_ptr
->virt
, buf_ptr
->phys
);
3245 * lpfc_els_free_iocb - Free a command iocb and its associated resources
3246 * @phba: pointer to lpfc hba data structure.
3247 * @elsiocb: pointer to lpfc els command iocb data structure.
3249 * This routine frees a command IOCB and its associated resources. The
3250 * command IOCB data structure contains the reference to various associated
3251 * resources, these fields must be set to NULL if the associated reference
3253 * context1 - reference to ndlp
3254 * context2 - reference to cmd
3255 * context2->next - reference to rsp
3256 * context3 - reference to bpl
3258 * It first properly decrements the reference count held on ndlp for the
3259 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
3260 * set, it invokes the lpfc_els_free_data() routine to release the Direct
3261 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
3262 * adds the DMA buffer the @phba data structure for the delayed release.
3263 * If reference to the Buffer Pointer List (BPL) is present, the
3264 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
3265 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
3266 * invoked to release the IOCB data structure back to @phba IOCBQ list.
3269 * 0 - Success (currently, always return 0)
3272 lpfc_els_free_iocb(struct lpfc_hba
*phba
, struct lpfc_iocbq
*elsiocb
)
3274 struct lpfc_dmabuf
*buf_ptr
, *buf_ptr1
;
3275 struct lpfc_nodelist
*ndlp
;
3277 ndlp
= (struct lpfc_nodelist
*)elsiocb
->context1
;
3279 if (ndlp
->nlp_flag
& NLP_DEFER_RM
) {
3282 /* If the ndlp is not being used by another discovery
3285 if (!lpfc_nlp_not_used(ndlp
)) {
3286 /* If ndlp is being used by another discovery
3287 * thread, just clear NLP_DEFER_RM
3289 ndlp
->nlp_flag
&= ~NLP_DEFER_RM
;
3294 elsiocb
->context1
= NULL
;
3296 /* context2 = cmd, context2->next = rsp, context3 = bpl */
3297 if (elsiocb
->context2
) {
3298 if (elsiocb
->iocb_flag
& LPFC_DELAY_MEM_FREE
) {
3299 /* Firmware could still be in progress of DMAing
3300 * payload, so don't free data buffer till after
3303 elsiocb
->iocb_flag
&= ~LPFC_DELAY_MEM_FREE
;
3304 buf_ptr
= elsiocb
->context2
;
3305 elsiocb
->context2
= NULL
;
3308 spin_lock_irq(&phba
->hbalock
);
3309 if (!list_empty(&buf_ptr
->list
)) {
3310 list_remove_head(&buf_ptr
->list
,
3311 buf_ptr1
, struct lpfc_dmabuf
,
3313 INIT_LIST_HEAD(&buf_ptr1
->list
);
3314 list_add_tail(&buf_ptr1
->list
,
3318 INIT_LIST_HEAD(&buf_ptr
->list
);
3319 list_add_tail(&buf_ptr
->list
, &phba
->elsbuf
);
3321 spin_unlock_irq(&phba
->hbalock
);
3324 buf_ptr1
= (struct lpfc_dmabuf
*) elsiocb
->context2
;
3325 lpfc_els_free_data(phba
, buf_ptr1
);
3329 if (elsiocb
->context3
) {
3330 buf_ptr
= (struct lpfc_dmabuf
*) elsiocb
->context3
;
3331 lpfc_els_free_bpl(phba
, buf_ptr
);
3333 lpfc_sli_release_iocbq(phba
, elsiocb
);
3338 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
3339 * @phba: pointer to lpfc hba data structure.
3340 * @cmdiocb: pointer to lpfc command iocb data structure.
3341 * @rspiocb: pointer to lpfc response iocb data structure.
3343 * This routine is the completion callback function to the Logout (LOGO)
3344 * Accept (ACC) Response ELS command. This routine is invoked to indicate
3345 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
3346 * release the ndlp if it has the last reference remaining (reference count
3347 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
3348 * field to NULL to inform the following lpfc_els_free_iocb() routine no
3349 * ndlp reference count needs to be decremented. Otherwise, the ndlp
3350 * reference use-count shall be decremented by the lpfc_els_free_iocb()
3351 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
3352 * IOCB data structure.
3355 lpfc_cmpl_els_logo_acc(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
3356 struct lpfc_iocbq
*rspiocb
)
3358 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
3359 struct lpfc_vport
*vport
= cmdiocb
->vport
;
3362 irsp
= &rspiocb
->iocb
;
3363 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
3364 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
3365 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4], ndlp
->nlp_DID
);
3366 /* ACC to LOGO completes to NPort <nlp_DID> */
3367 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3368 "0109 ACC to LOGO completes to NPort x%x "
3369 "Data: x%x x%x x%x\n",
3370 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
3373 if (ndlp
->nlp_state
== NLP_STE_NPR_NODE
) {
3374 /* NPort Recovery mode or node is just allocated */
3375 if (!lpfc_nlp_not_used(ndlp
)) {
3376 /* If the ndlp is being used by another discovery
3377 * thread, just unregister the RPI.
3379 lpfc_unreg_rpi(vport
, ndlp
);
3381 /* Indicate the node has already released, should
3382 * not reference to it from within lpfc_els_free_iocb.
3384 cmdiocb
->context1
= NULL
;
3387 lpfc_els_free_iocb(phba
, cmdiocb
);
3392 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
3393 * @phba: pointer to lpfc hba data structure.
3394 * @pmb: pointer to the driver internal queue element for mailbox command.
3396 * This routine is the completion callback function for unregister default
3397 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
3398 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
3399 * decrements the ndlp reference count held for this completion callback
3400 * function. After that, it invokes the lpfc_nlp_not_used() to check
3401 * whether there is only one reference left on the ndlp. If so, it will
3402 * perform one more decrement and trigger the release of the ndlp.
3405 lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
3407 struct lpfc_dmabuf
*mp
= (struct lpfc_dmabuf
*) (pmb
->context1
);
3408 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
3410 pmb
->context1
= NULL
;
3411 pmb
->context2
= NULL
;
3413 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
3415 mempool_free(pmb
, phba
->mbox_mem_pool
);
3416 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
)) {
3418 /* This is the end of the default RPI cleanup logic for this
3419 * ndlp. If no other discovery threads are using this ndlp.
3420 * we should free all resources associated with it.
3422 lpfc_nlp_not_used(ndlp
);
3429 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
3430 * @phba: pointer to lpfc hba data structure.
3431 * @cmdiocb: pointer to lpfc command iocb data structure.
3432 * @rspiocb: pointer to lpfc response iocb data structure.
3434 * This routine is the completion callback function for ELS Response IOCB
3435 * command. In normal case, this callback function just properly sets the
3436 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
3437 * field in the command IOCB is not NULL, the referred mailbox command will
3438 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
3439 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
3440 * link down event occurred during the discovery, the lpfc_nlp_not_used()
3441 * routine shall be invoked trying to release the ndlp if no other threads
3442 * are currently referring it.
3445 lpfc_cmpl_els_rsp(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
3446 struct lpfc_iocbq
*rspiocb
)
3448 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
3449 struct lpfc_vport
*vport
= ndlp
? ndlp
->vport
: NULL
;
3450 struct Scsi_Host
*shost
= vport
? lpfc_shost_from_vport(vport
) : NULL
;
3453 LPFC_MBOXQ_t
*mbox
= NULL
;
3454 struct lpfc_dmabuf
*mp
= NULL
;
3455 uint32_t ls_rjt
= 0;
3457 irsp
= &rspiocb
->iocb
;
3459 if (cmdiocb
->context_un
.mbox
)
3460 mbox
= cmdiocb
->context_un
.mbox
;
3462 /* First determine if this is a LS_RJT cmpl. Note, this callback
3463 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
3465 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) cmdiocb
->context2
)->virt
);
3466 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
) &&
3467 (*((uint32_t *) (pcmd
)) == ELS_CMD_LS_RJT
)) {
3468 /* A LS_RJT associated with Default RPI cleanup has its own
3469 * separate code path.
3471 if (!(ndlp
->nlp_flag
& NLP_RM_DFLT_RPI
))
3475 /* Check to see if link went down during discovery */
3476 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
) || lpfc_els_chk_latt(vport
)) {
3478 mp
= (struct lpfc_dmabuf
*) mbox
->context1
;
3480 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
3483 mempool_free(mbox
, phba
->mbox_mem_pool
);
3485 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
) &&
3486 (ndlp
->nlp_flag
& NLP_RM_DFLT_RPI
))
3487 if (lpfc_nlp_not_used(ndlp
)) {
3489 /* Indicate the node has already released,
3490 * should not reference to it from within
3491 * the routine lpfc_els_free_iocb.
3493 cmdiocb
->context1
= NULL
;
3498 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
3499 "ELS rsp cmpl: status:x%x/x%x did:x%x",
3500 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
3501 cmdiocb
->iocb
.un
.elsreq64
.remoteID
);
3502 /* ELS response tag <ulpIoTag> completes */
3503 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3504 "0110 ELS response tag x%x completes "
3505 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
3506 cmdiocb
->iocb
.ulpIoTag
, rspiocb
->iocb
.ulpStatus
,
3507 rspiocb
->iocb
.un
.ulpWord
[4], rspiocb
->iocb
.ulpTimeout
,
3508 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
3511 if ((rspiocb
->iocb
.ulpStatus
== 0)
3512 && (ndlp
->nlp_flag
& NLP_ACC_REGLOGIN
)) {
3513 lpfc_unreg_rpi(vport
, ndlp
);
3514 /* Increment reference count to ndlp to hold the
3515 * reference to ndlp for the callback function.
3517 mbox
->context2
= lpfc_nlp_get(ndlp
);
3518 mbox
->vport
= vport
;
3519 if (ndlp
->nlp_flag
& NLP_RM_DFLT_RPI
) {
3520 mbox
->mbox_flag
|= LPFC_MBX_IMED_UNREG
;
3521 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_dflt_rpi
;
3524 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_reg_login
;
3525 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
3526 lpfc_nlp_set_state(vport
, ndlp
,
3527 NLP_STE_REG_LOGIN_ISSUE
);
3529 if (lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
)
3530 != MBX_NOT_FINISHED
)
3533 /* Decrement the ndlp reference count we
3534 * set for this failed mailbox command.
3538 /* ELS rsp: Cannot issue reg_login for <NPortid> */
3539 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
3540 "0138 ELS rsp: Cannot issue reg_login for x%x "
3541 "Data: x%x x%x x%x\n",
3542 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
3545 if (lpfc_nlp_not_used(ndlp
)) {
3547 /* Indicate node has already been released,
3548 * should not reference to it from within
3549 * the routine lpfc_els_free_iocb.
3551 cmdiocb
->context1
= NULL
;
3554 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
3555 if (!lpfc_error_lost_link(irsp
) &&
3556 ndlp
->nlp_flag
& NLP_ACC_REGLOGIN
) {
3557 if (lpfc_nlp_not_used(ndlp
)) {
3559 /* Indicate node has already been
3560 * released, should not reference
3561 * to it from within the routine
3562 * lpfc_els_free_iocb.
3564 cmdiocb
->context1
= NULL
;
3568 mp
= (struct lpfc_dmabuf
*) mbox
->context1
;
3570 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
3573 mempool_free(mbox
, phba
->mbox_mem_pool
);
3576 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
)) {
3577 spin_lock_irq(shost
->host_lock
);
3578 ndlp
->nlp_flag
&= ~(NLP_ACC_REGLOGIN
| NLP_RM_DFLT_RPI
);
3579 spin_unlock_irq(shost
->host_lock
);
3581 /* If the node is not being used by another discovery thread,
3582 * and we are sending a reject, we are done with it.
3583 * Release driver reference count here and free associated
3587 if (lpfc_nlp_not_used(ndlp
))
3588 /* Indicate node has already been released,
3589 * should not reference to it from within
3590 * the routine lpfc_els_free_iocb.
3592 cmdiocb
->context1
= NULL
;
3595 lpfc_els_free_iocb(phba
, cmdiocb
);
3600 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
3601 * @vport: pointer to a host virtual N_Port data structure.
3602 * @flag: the els command code to be accepted.
3603 * @oldiocb: pointer to the original lpfc command iocb data structure.
3604 * @ndlp: pointer to a node-list data structure.
3605 * @mbox: pointer to the driver internal queue element for mailbox command.
3607 * This routine prepares and issues an Accept (ACC) response IOCB
3608 * command. It uses the @flag to properly set up the IOCB field for the
3609 * specific ACC response command to be issued and invokes the
3610 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
3611 * @mbox pointer is passed in, it will be put into the context_un.mbox
3612 * field of the IOCB for the completion callback function to issue the
3613 * mailbox command to the HBA later when callback is invoked.
3615 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3616 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3617 * will be stored into the context1 field of the IOCB for the completion
3618 * callback function to the corresponding response ELS IOCB command.
3621 * 0 - Successfully issued acc response
3622 * 1 - Failed to issue acc response
3625 lpfc_els_rsp_acc(struct lpfc_vport
*vport
, uint32_t flag
,
3626 struct lpfc_iocbq
*oldiocb
, struct lpfc_nodelist
*ndlp
,
3629 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
3630 struct lpfc_hba
*phba
= vport
->phba
;
3633 struct lpfc_iocbq
*elsiocb
;
3634 struct lpfc_sli
*psli
;
3638 ELS_PKT
*els_pkt_ptr
;
3641 oldcmd
= &oldiocb
->iocb
;
3645 cmdsize
= sizeof(uint32_t);
3646 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
,
3647 ndlp
, ndlp
->nlp_DID
, ELS_CMD_ACC
);
3649 spin_lock_irq(shost
->host_lock
);
3650 ndlp
->nlp_flag
&= ~NLP_LOGO_ACC
;
3651 spin_unlock_irq(shost
->host_lock
);
3655 icmd
= &elsiocb
->iocb
;
3656 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri / rx_id */
3657 icmd
->unsli3
.rcvsli3
.ox_id
= oldcmd
->unsli3
.rcvsli3
.ox_id
;
3658 pcmd
= (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
3659 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
3660 pcmd
+= sizeof(uint32_t);
3662 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
3663 "Issue ACC: did:x%x flg:x%x",
3664 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
3667 cmdsize
= (sizeof(struct serv_parm
) + sizeof(uint32_t));
3668 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
,
3669 ndlp
, ndlp
->nlp_DID
, ELS_CMD_ACC
);
3673 icmd
= &elsiocb
->iocb
;
3674 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri / rx_id */
3675 icmd
->unsli3
.rcvsli3
.ox_id
= oldcmd
->unsli3
.rcvsli3
.ox_id
;
3676 pcmd
= (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
3679 elsiocb
->context_un
.mbox
= mbox
;
3681 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
3682 pcmd
+= sizeof(uint32_t);
3683 memcpy(pcmd
, &vport
->fc_sparam
, sizeof(struct serv_parm
));
3685 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
3686 "Issue ACC PLOGI: did:x%x flg:x%x",
3687 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
3690 cmdsize
= sizeof(uint32_t) + sizeof(PRLO
);
3691 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
,
3692 ndlp
, ndlp
->nlp_DID
, ELS_CMD_PRLO
);
3696 icmd
= &elsiocb
->iocb
;
3697 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri / rx_id */
3698 icmd
->unsli3
.rcvsli3
.ox_id
= oldcmd
->unsli3
.rcvsli3
.ox_id
;
3699 pcmd
= (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
3701 memcpy(pcmd
, ((struct lpfc_dmabuf
*) oldiocb
->context2
)->virt
,
3702 sizeof(uint32_t) + sizeof(PRLO
));
3703 *((uint32_t *) (pcmd
)) = ELS_CMD_PRLO_ACC
;
3704 els_pkt_ptr
= (ELS_PKT
*) pcmd
;
3705 els_pkt_ptr
->un
.prlo
.acceptRspCode
= PRLO_REQ_EXECUTED
;
3707 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
3708 "Issue ACC PRLO: did:x%x flg:x%x",
3709 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
3714 /* Xmit ELS ACC response tag <ulpIoTag> */
3715 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3716 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
3717 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n",
3718 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
3719 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
3721 if (ndlp
->nlp_flag
& NLP_LOGO_ACC
) {
3722 spin_lock_irq(shost
->host_lock
);
3723 ndlp
->nlp_flag
&= ~NLP_LOGO_ACC
;
3724 spin_unlock_irq(shost
->host_lock
);
3725 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_logo_acc
;
3727 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
3730 phba
->fc_stat
.elsXmitACC
++;
3731 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
3732 if (rc
== IOCB_ERROR
) {
3733 lpfc_els_free_iocb(phba
, elsiocb
);
3740 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
3741 * @vport: pointer to a virtual N_Port data structure.
3743 * @oldiocb: pointer to the original lpfc command iocb data structure.
3744 * @ndlp: pointer to a node-list data structure.
3745 * @mbox: pointer to the driver internal queue element for mailbox command.
3747 * This routine prepares and issue an Reject (RJT) response IOCB
3748 * command. If a @mbox pointer is passed in, it will be put into the
3749 * context_un.mbox field of the IOCB for the completion callback function
3750 * to issue to the HBA later.
3752 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3753 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3754 * will be stored into the context1 field of the IOCB for the completion
3755 * callback function to the reject response ELS IOCB command.
3758 * 0 - Successfully issued reject response
3759 * 1 - Failed to issue reject response
3762 lpfc_els_rsp_reject(struct lpfc_vport
*vport
, uint32_t rejectError
,
3763 struct lpfc_iocbq
*oldiocb
, struct lpfc_nodelist
*ndlp
,
3766 struct lpfc_hba
*phba
= vport
->phba
;
3769 struct lpfc_iocbq
*elsiocb
;
3770 struct lpfc_sli
*psli
;
3776 cmdsize
= 2 * sizeof(uint32_t);
3777 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
3778 ndlp
->nlp_DID
, ELS_CMD_LS_RJT
);
3782 icmd
= &elsiocb
->iocb
;
3783 oldcmd
= &oldiocb
->iocb
;
3784 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri / rx_id */
3785 icmd
->unsli3
.rcvsli3
.ox_id
= oldcmd
->unsli3
.rcvsli3
.ox_id
;
3786 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
3788 *((uint32_t *) (pcmd
)) = ELS_CMD_LS_RJT
;
3789 pcmd
+= sizeof(uint32_t);
3790 *((uint32_t *) (pcmd
)) = rejectError
;
3793 elsiocb
->context_un
.mbox
= mbox
;
3795 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
3796 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3797 "0129 Xmit ELS RJT x%x response tag x%x "
3798 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
3800 rejectError
, elsiocb
->iotag
,
3801 elsiocb
->iocb
.ulpContext
, ndlp
->nlp_DID
,
3802 ndlp
->nlp_flag
, ndlp
->nlp_state
, ndlp
->nlp_rpi
);
3803 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
3804 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
3805 ndlp
->nlp_DID
, ndlp
->nlp_flag
, rejectError
);
3807 phba
->fc_stat
.elsXmitLSRJT
++;
3808 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
3809 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
3811 if (rc
== IOCB_ERROR
) {
3812 lpfc_els_free_iocb(phba
, elsiocb
);
3819 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
3820 * @vport: pointer to a virtual N_Port data structure.
3821 * @oldiocb: pointer to the original lpfc command iocb data structure.
3822 * @ndlp: pointer to a node-list data structure.
3824 * This routine prepares and issues an Accept (ACC) response to Address
3825 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
3826 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3828 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3829 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3830 * will be stored into the context1 field of the IOCB for the completion
3831 * callback function to the ADISC Accept response ELS IOCB command.
3834 * 0 - Successfully issued acc adisc response
3835 * 1 - Failed to issue adisc acc response
3838 lpfc_els_rsp_adisc_acc(struct lpfc_vport
*vport
, struct lpfc_iocbq
*oldiocb
,
3839 struct lpfc_nodelist
*ndlp
)
3841 struct lpfc_hba
*phba
= vport
->phba
;
3843 IOCB_t
*icmd
, *oldcmd
;
3844 struct lpfc_iocbq
*elsiocb
;
3849 cmdsize
= sizeof(uint32_t) + sizeof(ADISC
);
3850 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
3851 ndlp
->nlp_DID
, ELS_CMD_ACC
);
3855 icmd
= &elsiocb
->iocb
;
3856 oldcmd
= &oldiocb
->iocb
;
3857 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri / rx_id */
3858 icmd
->unsli3
.rcvsli3
.ox_id
= oldcmd
->unsli3
.rcvsli3
.ox_id
;
3860 /* Xmit ADISC ACC response tag <ulpIoTag> */
3861 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3862 "0130 Xmit ADISC ACC response iotag x%x xri: "
3863 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
3864 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
3865 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
3867 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
3869 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
3870 pcmd
+= sizeof(uint32_t);
3872 ap
= (ADISC
*) (pcmd
);
3873 ap
->hardAL_PA
= phba
->fc_pref_ALPA
;
3874 memcpy(&ap
->portName
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
3875 memcpy(&ap
->nodeName
, &vport
->fc_nodename
, sizeof(struct lpfc_name
));
3876 ap
->DID
= be32_to_cpu(vport
->fc_myDID
);
3878 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
3879 "Issue ACC ADISC: did:x%x flg:x%x",
3880 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
3882 phba
->fc_stat
.elsXmitACC
++;
3883 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
3884 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
3885 if (rc
== IOCB_ERROR
) {
3886 lpfc_els_free_iocb(phba
, elsiocb
);
3893 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
3894 * @vport: pointer to a virtual N_Port data structure.
3895 * @oldiocb: pointer to the original lpfc command iocb data structure.
3896 * @ndlp: pointer to a node-list data structure.
3898 * This routine prepares and issues an Accept (ACC) response to Process
3899 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
3900 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3902 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3903 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3904 * will be stored into the context1 field of the IOCB for the completion
3905 * callback function to the PRLI Accept response ELS IOCB command.
3908 * 0 - Successfully issued acc prli response
3909 * 1 - Failed to issue acc prli response
3912 lpfc_els_rsp_prli_acc(struct lpfc_vport
*vport
, struct lpfc_iocbq
*oldiocb
,
3913 struct lpfc_nodelist
*ndlp
)
3915 struct lpfc_hba
*phba
= vport
->phba
;
3920 struct lpfc_iocbq
*elsiocb
;
3921 struct lpfc_sli
*psli
;
3928 cmdsize
= sizeof(uint32_t) + sizeof(PRLI
);
3929 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
3930 ndlp
->nlp_DID
, (ELS_CMD_ACC
| (ELS_CMD_PRLI
& ~ELS_RSP_MASK
)));
3934 icmd
= &elsiocb
->iocb
;
3935 oldcmd
= &oldiocb
->iocb
;
3936 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri / rx_id */
3937 icmd
->unsli3
.rcvsli3
.ox_id
= oldcmd
->unsli3
.rcvsli3
.ox_id
;
3939 /* Xmit PRLI ACC response tag <ulpIoTag> */
3940 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3941 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
3942 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
3943 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
3944 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
3946 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
3948 *((uint32_t *) (pcmd
)) = (ELS_CMD_ACC
| (ELS_CMD_PRLI
& ~ELS_RSP_MASK
));
3949 pcmd
+= sizeof(uint32_t);
3951 /* For PRLI, remainder of payload is PRLI parameter page */
3952 memset(pcmd
, 0, sizeof(PRLI
));
3954 npr
= (PRLI
*) pcmd
;
3957 * If the remote port is a target and our firmware version is 3.20 or
3958 * later, set the following bits for FC-TAPE support.
3960 if ((ndlp
->nlp_type
& NLP_FCP_TARGET
) &&
3961 (vpd
->rev
.feaLevelHigh
>= 0x02)) {
3962 npr
->ConfmComplAllowed
= 1;
3964 npr
->TaskRetryIdReq
= 1;
3967 npr
->acceptRspCode
= PRLI_REQ_EXECUTED
;
3968 npr
->estabImagePair
= 1;
3969 npr
->readXferRdyDis
= 1;
3970 npr
->ConfmComplAllowed
= 1;
3972 npr
->prliType
= PRLI_FCP_TYPE
;
3973 npr
->initiatorFunc
= 1;
3975 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
3976 "Issue ACC PRLI: did:x%x flg:x%x",
3977 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
3979 phba
->fc_stat
.elsXmitACC
++;
3980 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
3982 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
3983 if (rc
== IOCB_ERROR
) {
3984 lpfc_els_free_iocb(phba
, elsiocb
);
3991 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
3992 * @vport: pointer to a virtual N_Port data structure.
3993 * @format: rnid command format.
3994 * @oldiocb: pointer to the original lpfc command iocb data structure.
3995 * @ndlp: pointer to a node-list data structure.
3997 * This routine issues a Request Node Identification Data (RNID) Accept
3998 * (ACC) response. It constructs the RNID ACC response command according to
3999 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
4000 * issue the response. Note that this command does not need to hold the ndlp
4001 * reference count for the callback. So, the ndlp reference count taken by
4002 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
4003 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
4004 * there is no ndlp reference available.
4006 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4007 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4008 * will be stored into the context1 field of the IOCB for the completion
4009 * callback function. However, for the RNID Accept Response ELS command,
4010 * this is undone later by this routine after the IOCB is allocated.
4013 * 0 - Successfully issued acc rnid response
4014 * 1 - Failed to issue acc rnid response
4017 lpfc_els_rsp_rnid_acc(struct lpfc_vport
*vport
, uint8_t format
,
4018 struct lpfc_iocbq
*oldiocb
, struct lpfc_nodelist
*ndlp
)
4020 struct lpfc_hba
*phba
= vport
->phba
;
4022 IOCB_t
*icmd
, *oldcmd
;
4023 struct lpfc_iocbq
*elsiocb
;
4024 struct lpfc_sli
*psli
;
4030 cmdsize
= sizeof(uint32_t) + sizeof(uint32_t)
4031 + (2 * sizeof(struct lpfc_name
));
4033 cmdsize
+= sizeof(RNID_TOP_DISC
);
4035 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
4036 ndlp
->nlp_DID
, ELS_CMD_ACC
);
4040 icmd
= &elsiocb
->iocb
;
4041 oldcmd
= &oldiocb
->iocb
;
4042 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri / rx_id */
4043 icmd
->unsli3
.rcvsli3
.ox_id
= oldcmd
->unsli3
.rcvsli3
.ox_id
;
4045 /* Xmit RNID ACC response tag <ulpIoTag> */
4046 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
4047 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
4048 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
);
4049 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
4050 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
4051 pcmd
+= sizeof(uint32_t);
4053 memset(pcmd
, 0, sizeof(RNID
));
4054 rn
= (RNID
*) (pcmd
);
4055 rn
->Format
= format
;
4056 rn
->CommonLen
= (2 * sizeof(struct lpfc_name
));
4057 memcpy(&rn
->portName
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
4058 memcpy(&rn
->nodeName
, &vport
->fc_nodename
, sizeof(struct lpfc_name
));
4061 rn
->SpecificLen
= 0;
4063 case RNID_TOPOLOGY_DISC
:
4064 rn
->SpecificLen
= sizeof(RNID_TOP_DISC
);
4065 memcpy(&rn
->un
.topologyDisc
.portName
,
4066 &vport
->fc_portname
, sizeof(struct lpfc_name
));
4067 rn
->un
.topologyDisc
.unitType
= RNID_HBA
;
4068 rn
->un
.topologyDisc
.physPort
= 0;
4069 rn
->un
.topologyDisc
.attachedNodes
= 0;
4073 rn
->SpecificLen
= 0;
4077 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
4078 "Issue ACC RNID: did:x%x flg:x%x",
4079 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
4081 phba
->fc_stat
.elsXmitACC
++;
4082 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
4084 elsiocb
->context1
= NULL
; /* Don't need ndlp for cmpl,
4085 * it could be freed */
4087 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
4088 if (rc
== IOCB_ERROR
) {
4089 lpfc_els_free_iocb(phba
, elsiocb
);
4096 * lpfc_els_clear_rrq - Clear the rq that this rrq describes.
4097 * @vport: pointer to a virtual N_Port data structure.
4098 * @iocb: pointer to the lpfc command iocb data structure.
4099 * @ndlp: pointer to a node-list data structure.
4104 lpfc_els_clear_rrq(struct lpfc_vport
*vport
,
4105 struct lpfc_iocbq
*iocb
, struct lpfc_nodelist
*ndlp
)
4107 struct lpfc_hba
*phba
= vport
->phba
;
4112 struct lpfc_node_rrq
*prrq
;
4115 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) iocb
->context2
)->virt
);
4116 pcmd
+= sizeof(uint32_t);
4117 rrq
= (struct RRQ
*)pcmd
;
4118 rrq
->rrq_exchg
= be32_to_cpu(rrq
->rrq_exchg
);
4119 rxid
= bf_get(rrq_rxid
, rrq
);
4121 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
4122 "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x"
4124 be32_to_cpu(bf_get(rrq_did
, rrq
)),
4125 bf_get(rrq_oxid
, rrq
),
4127 iocb
->iotag
, iocb
->iocb
.ulpContext
);
4129 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
4130 "Clear RRQ: did:x%x flg:x%x exchg:x%.08x",
4131 ndlp
->nlp_DID
, ndlp
->nlp_flag
, rrq
->rrq_exchg
);
4132 if (vport
->fc_myDID
== be32_to_cpu(bf_get(rrq_did
, rrq
)))
4133 xri
= bf_get(rrq_oxid
, rrq
);
4136 prrq
= lpfc_get_active_rrq(vport
, xri
, ndlp
->nlp_DID
);
4138 lpfc_clr_rrq_active(phba
, xri
, prrq
);
4143 * lpfc_els_rsp_echo_acc - Issue echo acc response
4144 * @vport: pointer to a virtual N_Port data structure.
4145 * @data: pointer to echo data to return in the accept.
4146 * @oldiocb: pointer to the original lpfc command iocb data structure.
4147 * @ndlp: pointer to a node-list data structure.
4150 * 0 - Successfully issued acc echo response
4151 * 1 - Failed to issue acc echo response
4154 lpfc_els_rsp_echo_acc(struct lpfc_vport
*vport
, uint8_t *data
,
4155 struct lpfc_iocbq
*oldiocb
, struct lpfc_nodelist
*ndlp
)
4157 struct lpfc_hba
*phba
= vport
->phba
;
4158 struct lpfc_iocbq
*elsiocb
;
4159 struct lpfc_sli
*psli
;
4165 cmdsize
= oldiocb
->iocb
.unsli3
.rcvsli3
.acc_len
;
4167 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
4168 ndlp
->nlp_DID
, ELS_CMD_ACC
);
4172 elsiocb
->iocb
.ulpContext
= oldiocb
->iocb
.ulpContext
; /* Xri / rx_id */
4173 elsiocb
->iocb
.unsli3
.rcvsli3
.ox_id
= oldiocb
->iocb
.unsli3
.rcvsli3
.ox_id
;
4175 /* Xmit ECHO ACC response tag <ulpIoTag> */
4176 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
4177 "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
4178 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
);
4179 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
4180 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
4181 pcmd
+= sizeof(uint32_t);
4182 memcpy(pcmd
, data
, cmdsize
- sizeof(uint32_t));
4184 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
4185 "Issue ACC ECHO: did:x%x flg:x%x",
4186 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
4188 phba
->fc_stat
.elsXmitACC
++;
4189 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
4191 elsiocb
->context1
= NULL
; /* Don't need ndlp for cmpl,
4192 * it could be freed */
4194 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
4195 if (rc
== IOCB_ERROR
) {
4196 lpfc_els_free_iocb(phba
, elsiocb
);
4203 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
4204 * @vport: pointer to a host virtual N_Port data structure.
4206 * This routine issues Address Discover (ADISC) ELS commands to those
4207 * N_Ports which are in node port recovery state and ADISC has not been issued
4208 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
4209 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
4210 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
4211 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
4212 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
4213 * IOCBs quit for later pick up. On the other hand, after walking through
4214 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
4215 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
4216 * no more ADISC need to be sent.
4219 * The number of N_Ports with adisc issued.
4222 lpfc_els_disc_adisc(struct lpfc_vport
*vport
)
4224 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4225 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
4228 /* go thru NPR nodes and issue any remaining ELS ADISCs */
4229 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
, nlp_listp
) {
4230 if (!NLP_CHK_NODE_ACT(ndlp
))
4232 if (ndlp
->nlp_state
== NLP_STE_NPR_NODE
&&
4233 (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) != 0 &&
4234 (ndlp
->nlp_flag
& NLP_NPR_ADISC
) != 0) {
4235 spin_lock_irq(shost
->host_lock
);
4236 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
4237 spin_unlock_irq(shost
->host_lock
);
4238 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
4239 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_ADISC_ISSUE
);
4240 lpfc_issue_els_adisc(vport
, ndlp
, 0);
4242 vport
->num_disc_nodes
++;
4243 if (vport
->num_disc_nodes
>=
4244 vport
->cfg_discovery_threads
) {
4245 spin_lock_irq(shost
->host_lock
);
4246 vport
->fc_flag
|= FC_NLP_MORE
;
4247 spin_unlock_irq(shost
->host_lock
);
4252 if (sentadisc
== 0) {
4253 spin_lock_irq(shost
->host_lock
);
4254 vport
->fc_flag
&= ~FC_NLP_MORE
;
4255 spin_unlock_irq(shost
->host_lock
);
4261 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
4262 * @vport: pointer to a host virtual N_Port data structure.
4264 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
4265 * which are in node port recovery state, with a @vport. Each time an ELS
4266 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
4267 * the per @vport number of discover count (num_disc_nodes) shall be
4268 * incremented. If the num_disc_nodes reaches a pre-configured threshold
4269 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
4270 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
4271 * later pick up. On the other hand, after walking through all the ndlps with
4272 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
4273 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
4274 * PLOGI need to be sent.
4277 * The number of N_Ports with plogi issued.
4280 lpfc_els_disc_plogi(struct lpfc_vport
*vport
)
4282 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4283 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
4286 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
4287 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
, nlp_listp
) {
4288 if (!NLP_CHK_NODE_ACT(ndlp
))
4290 if (ndlp
->nlp_state
== NLP_STE_NPR_NODE
&&
4291 (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) != 0 &&
4292 (ndlp
->nlp_flag
& NLP_DELAY_TMO
) == 0 &&
4293 (ndlp
->nlp_flag
& NLP_NPR_ADISC
) == 0) {
4294 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
4295 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
4296 lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0);
4298 vport
->num_disc_nodes
++;
4299 if (vport
->num_disc_nodes
>=
4300 vport
->cfg_discovery_threads
) {
4301 spin_lock_irq(shost
->host_lock
);
4302 vport
->fc_flag
|= FC_NLP_MORE
;
4303 spin_unlock_irq(shost
->host_lock
);
4309 lpfc_set_disctmo(vport
);
4312 spin_lock_irq(shost
->host_lock
);
4313 vport
->fc_flag
&= ~FC_NLP_MORE
;
4314 spin_unlock_irq(shost
->host_lock
);
4320 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
4321 * @vport: pointer to a host virtual N_Port data structure.
4323 * This routine cleans up any Registration State Change Notification
4324 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
4325 * @vport together with the host_lock is used to prevent multiple thread
4326 * trying to access the RSCN array on a same @vport at the same time.
4329 lpfc_els_flush_rscn(struct lpfc_vport
*vport
)
4331 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4332 struct lpfc_hba
*phba
= vport
->phba
;
4335 spin_lock_irq(shost
->host_lock
);
4336 if (vport
->fc_rscn_flush
) {
4337 /* Another thread is walking fc_rscn_id_list on this vport */
4338 spin_unlock_irq(shost
->host_lock
);
4341 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
4342 vport
->fc_rscn_flush
= 1;
4343 spin_unlock_irq(shost
->host_lock
);
4345 for (i
= 0; i
< vport
->fc_rscn_id_cnt
; i
++) {
4346 lpfc_in_buf_free(phba
, vport
->fc_rscn_id_list
[i
]);
4347 vport
->fc_rscn_id_list
[i
] = NULL
;
4349 spin_lock_irq(shost
->host_lock
);
4350 vport
->fc_rscn_id_cnt
= 0;
4351 vport
->fc_flag
&= ~(FC_RSCN_MODE
| FC_RSCN_DISCOVERY
);
4352 spin_unlock_irq(shost
->host_lock
);
4353 lpfc_can_disctmo(vport
);
4354 /* Indicate we are done walking this fc_rscn_id_list */
4355 vport
->fc_rscn_flush
= 0;
4359 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
4360 * @vport: pointer to a host virtual N_Port data structure.
4361 * @did: remote destination port identifier.
4363 * This routine checks whether there is any pending Registration State
4364 * Configuration Notification (RSCN) to a @did on @vport.
4367 * None zero - The @did matched with a pending rscn
4368 * 0 - not able to match @did with a pending rscn
4371 lpfc_rscn_payload_check(struct lpfc_vport
*vport
, uint32_t did
)
4376 uint32_t payload_len
, i
;
4377 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4379 ns_did
.un
.word
= did
;
4381 /* Never match fabric nodes for RSCNs */
4382 if ((did
& Fabric_DID_MASK
) == Fabric_DID_MASK
)
4385 /* If we are doing a FULL RSCN rediscovery, match everything */
4386 if (vport
->fc_flag
& FC_RSCN_DISCOVERY
)
4389 spin_lock_irq(shost
->host_lock
);
4390 if (vport
->fc_rscn_flush
) {
4391 /* Another thread is walking fc_rscn_id_list on this vport */
4392 spin_unlock_irq(shost
->host_lock
);
4395 /* Indicate we are walking fc_rscn_id_list on this vport */
4396 vport
->fc_rscn_flush
= 1;
4397 spin_unlock_irq(shost
->host_lock
);
4398 for (i
= 0; i
< vport
->fc_rscn_id_cnt
; i
++) {
4399 lp
= vport
->fc_rscn_id_list
[i
]->virt
;
4400 payload_len
= be32_to_cpu(*lp
++ & ~ELS_CMD_MASK
);
4401 payload_len
-= sizeof(uint32_t); /* take off word 0 */
4402 while (payload_len
) {
4403 rscn_did
.un
.word
= be32_to_cpu(*lp
++);
4404 payload_len
-= sizeof(uint32_t);
4405 switch (rscn_did
.un
.b
.resv
& RSCN_ADDRESS_FORMAT_MASK
) {
4406 case RSCN_ADDRESS_FORMAT_PORT
:
4407 if ((ns_did
.un
.b
.domain
== rscn_did
.un
.b
.domain
)
4408 && (ns_did
.un
.b
.area
== rscn_did
.un
.b
.area
)
4409 && (ns_did
.un
.b
.id
== rscn_did
.un
.b
.id
))
4410 goto return_did_out
;
4412 case RSCN_ADDRESS_FORMAT_AREA
:
4413 if ((ns_did
.un
.b
.domain
== rscn_did
.un
.b
.domain
)
4414 && (ns_did
.un
.b
.area
== rscn_did
.un
.b
.area
))
4415 goto return_did_out
;
4417 case RSCN_ADDRESS_FORMAT_DOMAIN
:
4418 if (ns_did
.un
.b
.domain
== rscn_did
.un
.b
.domain
)
4419 goto return_did_out
;
4421 case RSCN_ADDRESS_FORMAT_FABRIC
:
4422 goto return_did_out
;
4426 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4427 vport
->fc_rscn_flush
= 0;
4430 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4431 vport
->fc_rscn_flush
= 0;
4436 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
4437 * @vport: pointer to a host virtual N_Port data structure.
4439 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
4440 * state machine for a @vport's nodes that are with pending RSCN (Registration
4441 * State Change Notification).
4444 * 0 - Successful (currently alway return 0)
4447 lpfc_rscn_recovery_check(struct lpfc_vport
*vport
)
4449 struct lpfc_nodelist
*ndlp
= NULL
;
4451 /* Move all affected nodes by pending RSCNs to NPR state. */
4452 list_for_each_entry(ndlp
, &vport
->fc_nodes
, nlp_listp
) {
4453 if (!NLP_CHK_NODE_ACT(ndlp
) ||
4454 (ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
) ||
4455 !lpfc_rscn_payload_check(vport
, ndlp
->nlp_DID
))
4457 lpfc_disc_state_machine(vport
, ndlp
, NULL
,
4458 NLP_EVT_DEVICE_RECOVERY
);
4459 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
4465 * lpfc_send_rscn_event - Send an RSCN event to management application
4466 * @vport: pointer to a host virtual N_Port data structure.
4467 * @cmdiocb: pointer to lpfc command iocb data structure.
4469 * lpfc_send_rscn_event sends an RSCN netlink event to management
4473 lpfc_send_rscn_event(struct lpfc_vport
*vport
,
4474 struct lpfc_iocbq
*cmdiocb
)
4476 struct lpfc_dmabuf
*pcmd
;
4477 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4478 uint32_t *payload_ptr
;
4479 uint32_t payload_len
;
4480 struct lpfc_rscn_event_header
*rscn_event_data
;
4482 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
4483 payload_ptr
= (uint32_t *) pcmd
->virt
;
4484 payload_len
= be32_to_cpu(*payload_ptr
& ~ELS_CMD_MASK
);
4486 rscn_event_data
= kmalloc(sizeof(struct lpfc_rscn_event_header
) +
4487 payload_len
, GFP_KERNEL
);
4488 if (!rscn_event_data
) {
4489 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
4490 "0147 Failed to allocate memory for RSCN event\n");
4493 rscn_event_data
->event_type
= FC_REG_RSCN_EVENT
;
4494 rscn_event_data
->payload_length
= payload_len
;
4495 memcpy(rscn_event_data
->rscn_payload
, payload_ptr
,
4498 fc_host_post_vendor_event(shost
,
4499 fc_get_event_number(),
4500 sizeof(struct lpfc_els_event_header
) + payload_len
,
4501 (char *)rscn_event_data
,
4504 kfree(rscn_event_data
);
4508 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
4509 * @vport: pointer to a host virtual N_Port data structure.
4510 * @cmdiocb: pointer to lpfc command iocb data structure.
4511 * @ndlp: pointer to a node-list data structure.
4513 * This routine processes an unsolicited RSCN (Registration State Change
4514 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
4515 * to invoke fc_host_post_event() routine to the FC transport layer. If the
4516 * discover state machine is about to begin discovery, it just accepts the
4517 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
4518 * contains N_Port IDs for other vports on this HBA, it just accepts the
4519 * RSCN and ignore processing it. If the state machine is in the recovery
4520 * state, the fc_rscn_id_list of this @vport is walked and the
4521 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
4522 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
4523 * routine is invoked to handle the RSCN event.
4526 * 0 - Just sent the acc response
4527 * 1 - Sent the acc response and waited for name server completion
4530 lpfc_els_rcv_rscn(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
4531 struct lpfc_nodelist
*ndlp
)
4533 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4534 struct lpfc_hba
*phba
= vport
->phba
;
4535 struct lpfc_dmabuf
*pcmd
;
4536 uint32_t *lp
, *datap
;
4538 uint32_t payload_len
, length
, nportid
, *cmd
;
4540 int rscn_id
= 0, hba_id
= 0;
4543 icmd
= &cmdiocb
->iocb
;
4544 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
4545 lp
= (uint32_t *) pcmd
->virt
;
4547 payload_len
= be32_to_cpu(*lp
++ & ~ELS_CMD_MASK
);
4548 payload_len
-= sizeof(uint32_t); /* take off word 0 */
4550 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
4551 "0214 RSCN received Data: x%x x%x x%x x%x\n",
4552 vport
->fc_flag
, payload_len
, *lp
,
4553 vport
->fc_rscn_id_cnt
);
4555 /* Send an RSCN event to the management application */
4556 lpfc_send_rscn_event(vport
, cmdiocb
);
4558 for (i
= 0; i
< payload_len
/sizeof(uint32_t); i
++)
4559 fc_host_post_event(shost
, fc_get_event_number(),
4560 FCH_EVT_RSCN
, lp
[i
]);
4562 /* If we are about to begin discovery, just ACC the RSCN.
4563 * Discovery processing will satisfy it.
4565 if (vport
->port_state
<= LPFC_NS_QRY
) {
4566 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
4567 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
4568 ndlp
->nlp_DID
, vport
->port_state
, ndlp
->nlp_flag
);
4570 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
4574 /* If this RSCN just contains NPortIDs for other vports on this HBA,
4575 * just ACC and ignore it.
4577 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
4578 !(vport
->cfg_peer_port_login
)) {
4583 nportid
= ((be32_to_cpu(nportid
)) & Mask_DID
);
4584 i
-= sizeof(uint32_t);
4586 if (lpfc_find_vport_by_did(phba
, nportid
))
4589 if (rscn_id
== hba_id
) {
4590 /* ALL NPortIDs in RSCN are on HBA */
4591 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
4593 "Data: x%x x%x x%x x%x\n",
4594 vport
->fc_flag
, payload_len
,
4595 *lp
, vport
->fc_rscn_id_cnt
);
4596 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
4597 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
4598 ndlp
->nlp_DID
, vport
->port_state
,
4601 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
,
4607 spin_lock_irq(shost
->host_lock
);
4608 if (vport
->fc_rscn_flush
) {
4609 /* Another thread is walking fc_rscn_id_list on this vport */
4610 vport
->fc_flag
|= FC_RSCN_DISCOVERY
;
4611 spin_unlock_irq(shost
->host_lock
);
4613 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
4616 /* Indicate we are walking fc_rscn_id_list on this vport */
4617 vport
->fc_rscn_flush
= 1;
4618 spin_unlock_irq(shost
->host_lock
);
4619 /* Get the array count after successfully have the token */
4620 rscn_cnt
= vport
->fc_rscn_id_cnt
;
4621 /* If we are already processing an RSCN, save the received
4622 * RSCN payload buffer, cmdiocb->context2 to process later.
4624 if (vport
->fc_flag
& (FC_RSCN_MODE
| FC_NDISC_ACTIVE
)) {
4625 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
4626 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
4627 ndlp
->nlp_DID
, vport
->port_state
, ndlp
->nlp_flag
);
4629 spin_lock_irq(shost
->host_lock
);
4630 vport
->fc_flag
|= FC_RSCN_DEFERRED
;
4631 if ((rscn_cnt
< FC_MAX_HOLD_RSCN
) &&
4632 !(vport
->fc_flag
& FC_RSCN_DISCOVERY
)) {
4633 vport
->fc_flag
|= FC_RSCN_MODE
;
4634 spin_unlock_irq(shost
->host_lock
);
4636 cmd
= vport
->fc_rscn_id_list
[rscn_cnt
-1]->virt
;
4637 length
= be32_to_cpu(*cmd
& ~ELS_CMD_MASK
);
4640 (payload_len
+ length
<= LPFC_BPL_SIZE
)) {
4641 *cmd
&= ELS_CMD_MASK
;
4642 *cmd
|= cpu_to_be32(payload_len
+ length
);
4643 memcpy(((uint8_t *)cmd
) + length
, lp
,
4646 vport
->fc_rscn_id_list
[rscn_cnt
] = pcmd
;
4647 vport
->fc_rscn_id_cnt
++;
4648 /* If we zero, cmdiocb->context2, the calling
4649 * routine will not try to free it.
4651 cmdiocb
->context2
= NULL
;
4654 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
4655 "0235 Deferred RSCN "
4656 "Data: x%x x%x x%x\n",
4657 vport
->fc_rscn_id_cnt
, vport
->fc_flag
,
4660 vport
->fc_flag
|= FC_RSCN_DISCOVERY
;
4661 spin_unlock_irq(shost
->host_lock
);
4662 /* ReDiscovery RSCN */
4663 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
4664 "0234 ReDiscovery RSCN "
4665 "Data: x%x x%x x%x\n",
4666 vport
->fc_rscn_id_cnt
, vport
->fc_flag
,
4669 /* Indicate we are done walking fc_rscn_id_list on this vport */
4670 vport
->fc_rscn_flush
= 0;
4672 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
4673 /* send RECOVERY event for ALL nodes that match RSCN payload */
4674 lpfc_rscn_recovery_check(vport
);
4675 spin_lock_irq(shost
->host_lock
);
4676 vport
->fc_flag
&= ~FC_RSCN_DEFERRED
;
4677 spin_unlock_irq(shost
->host_lock
);
4680 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
4681 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
4682 ndlp
->nlp_DID
, vport
->port_state
, ndlp
->nlp_flag
);
4684 spin_lock_irq(shost
->host_lock
);
4685 vport
->fc_flag
|= FC_RSCN_MODE
;
4686 spin_unlock_irq(shost
->host_lock
);
4687 vport
->fc_rscn_id_list
[vport
->fc_rscn_id_cnt
++] = pcmd
;
4688 /* Indicate we are done walking fc_rscn_id_list on this vport */
4689 vport
->fc_rscn_flush
= 0;
4691 * If we zero, cmdiocb->context2, the calling routine will
4692 * not try to free it.
4694 cmdiocb
->context2
= NULL
;
4695 lpfc_set_disctmo(vport
);
4697 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
4698 /* send RECOVERY event for ALL nodes that match RSCN payload */
4699 lpfc_rscn_recovery_check(vport
);
4700 return lpfc_els_handle_rscn(vport
);
4704 * lpfc_els_handle_rscn - Handle rscn for a vport
4705 * @vport: pointer to a host virtual N_Port data structure.
4707 * This routine handles the Registration State Configuration Notification
4708 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
4709 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
4710 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
4711 * NameServer shall be issued. If CT command to the NameServer fails to be
4712 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
4713 * RSCN activities with the @vport.
4716 * 0 - Cleaned up rscn on the @vport
4717 * 1 - Wait for plogi to name server before proceed
4720 lpfc_els_handle_rscn(struct lpfc_vport
*vport
)
4722 struct lpfc_nodelist
*ndlp
;
4723 struct lpfc_hba
*phba
= vport
->phba
;
4725 /* Ignore RSCN if the port is being torn down. */
4726 if (vport
->load_flag
& FC_UNLOADING
) {
4727 lpfc_els_flush_rscn(vport
);
4731 /* Start timer for RSCN processing */
4732 lpfc_set_disctmo(vport
);
4734 /* RSCN processed */
4735 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
4736 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
4737 vport
->fc_flag
, 0, vport
->fc_rscn_id_cnt
,
4740 /* To process RSCN, first compare RSCN data with NameServer */
4741 vport
->fc_ns_retry
= 0;
4742 vport
->num_disc_nodes
= 0;
4744 ndlp
= lpfc_findnode_did(vport
, NameServer_DID
);
4745 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
)
4746 && ndlp
->nlp_state
== NLP_STE_UNMAPPED_NODE
) {
4747 /* Good ndlp, issue CT Request to NameServer */
4748 if (lpfc_ns_cmd(vport
, SLI_CTNS_GID_FT
, 0, 0) == 0)
4749 /* Wait for NameServer query cmpl before we can
4753 /* If login to NameServer does not exist, issue one */
4754 /* Good status, issue PLOGI to NameServer */
4755 ndlp
= lpfc_findnode_did(vport
, NameServer_DID
);
4756 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
))
4757 /* Wait for NameServer login cmpl before we can
4762 ndlp
= lpfc_enable_node(vport
, ndlp
,
4763 NLP_STE_PLOGI_ISSUE
);
4765 lpfc_els_flush_rscn(vport
);
4768 ndlp
->nlp_prev_state
= NLP_STE_UNUSED_NODE
;
4770 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
4772 lpfc_els_flush_rscn(vport
);
4775 lpfc_nlp_init(vport
, ndlp
, NameServer_DID
);
4776 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
4777 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
4779 ndlp
->nlp_type
|= NLP_FABRIC
;
4780 lpfc_issue_els_plogi(vport
, NameServer_DID
, 0);
4781 /* Wait for NameServer login cmpl before we can
4787 lpfc_els_flush_rscn(vport
);
4792 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
4793 * @vport: pointer to a host virtual N_Port data structure.
4794 * @cmdiocb: pointer to lpfc command iocb data structure.
4795 * @ndlp: pointer to a node-list data structure.
4797 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
4798 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
4799 * point topology. As an unsolicited FLOGI should not be received in a loop
4800 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
4801 * lpfc_check_sparm() routine is invoked to check the parameters in the
4802 * unsolicited FLOGI. If parameters validation failed, the routine
4803 * lpfc_els_rsp_reject() shall be called with reject reason code set to
4804 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
4805 * FLOGI shall be compared with the Port WWN of the @vport to determine who
4806 * will initiate PLOGI. The higher lexicographical value party shall has
4807 * higher priority (as the winning port) and will initiate PLOGI and
4808 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
4809 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
4810 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
4813 * 0 - Successfully processed the unsolicited flogi
4814 * 1 - Failed to process the unsolicited flogi
4817 lpfc_els_rcv_flogi(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
4818 struct lpfc_nodelist
*ndlp
)
4820 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4821 struct lpfc_hba
*phba
= vport
->phba
;
4822 struct lpfc_dmabuf
*pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
4823 uint32_t *lp
= (uint32_t *) pcmd
->virt
;
4824 IOCB_t
*icmd
= &cmdiocb
->iocb
;
4825 struct serv_parm
*sp
;
4832 sp
= (struct serv_parm
*) lp
;
4834 /* FLOGI received */
4836 lpfc_set_disctmo(vport
);
4838 if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) {
4839 /* We should never receive a FLOGI in loop mode, ignore it */
4840 did
= icmd
->un
.elsreq64
.remoteID
;
4842 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
4844 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
4845 "0113 An FLOGI ELS command x%x was "
4846 "received from DID x%x in Loop Mode\n",
4853 if ((lpfc_check_sparm(vport
, ndlp
, sp
, CLASS3
, 1))) {
4854 /* For a FLOGI we accept, then if our portname is greater
4855 * then the remote portname we initiate Nport login.
4858 rc
= memcmp(&vport
->fc_portname
, &sp
->portName
,
4859 sizeof(struct lpfc_name
));
4862 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4866 lpfc_linkdown(phba
);
4867 lpfc_init_link(phba
, mbox
,
4869 phba
->cfg_link_speed
);
4870 mbox
->u
.mb
.un
.varInitLnk
.lipsr_AL_PA
= 0;
4871 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
4872 mbox
->vport
= vport
;
4873 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
4874 lpfc_set_loopback_flag(phba
);
4875 if (rc
== MBX_NOT_FINISHED
) {
4876 mempool_free(mbox
, phba
->mbox_mem_pool
);
4879 } else if (rc
> 0) { /* greater than */
4880 spin_lock_irq(shost
->host_lock
);
4881 vport
->fc_flag
|= FC_PT2PT_PLOGI
;
4882 spin_unlock_irq(shost
->host_lock
);
4884 spin_lock_irq(shost
->host_lock
);
4885 vport
->fc_flag
|= FC_PT2PT
;
4886 vport
->fc_flag
&= ~(FC_FABRIC
| FC_PUBLIC_LOOP
);
4887 spin_unlock_irq(shost
->host_lock
);
4889 /* Reject this request because invalid parameters */
4890 stat
.un
.b
.lsRjtRsvd0
= 0;
4891 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
4892 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_SPARM_OPTIONS
;
4893 stat
.un
.b
.vendorUnique
= 0;
4894 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
,
4900 lpfc_els_rsp_acc(vport
, ELS_CMD_PLOGI
, cmdiocb
, ndlp
, NULL
);
4906 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
4907 * @vport: pointer to a host virtual N_Port data structure.
4908 * @cmdiocb: pointer to lpfc command iocb data structure.
4909 * @ndlp: pointer to a node-list data structure.
4911 * This routine processes Request Node Identification Data (RNID) IOCB
4912 * received as an ELS unsolicited event. Only when the RNID specified format
4913 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
4914 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
4915 * Accept (ACC) the RNID ELS command. All the other RNID formats are
4916 * rejected by invoking the lpfc_els_rsp_reject() routine.
4919 * 0 - Successfully processed rnid iocb (currently always return 0)
4922 lpfc_els_rcv_rnid(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
4923 struct lpfc_nodelist
*ndlp
)
4925 struct lpfc_dmabuf
*pcmd
;
4932 icmd
= &cmdiocb
->iocb
;
4933 did
= icmd
->un
.elsreq64
.remoteID
;
4934 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
4935 lp
= (uint32_t *) pcmd
->virt
;
4942 switch (rn
->Format
) {
4944 case RNID_TOPOLOGY_DISC
:
4946 lpfc_els_rsp_rnid_acc(vport
, rn
->Format
, cmdiocb
, ndlp
);
4949 /* Reject this request because format not supported */
4950 stat
.un
.b
.lsRjtRsvd0
= 0;
4951 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
4952 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CANT_GIVE_DATA
;
4953 stat
.un
.b
.vendorUnique
= 0;
4954 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
,
4961 * lpfc_els_rcv_echo - Process an unsolicited echo iocb
4962 * @vport: pointer to a host virtual N_Port data structure.
4963 * @cmdiocb: pointer to lpfc command iocb data structure.
4964 * @ndlp: pointer to a node-list data structure.
4967 * 0 - Successfully processed echo iocb (currently always return 0)
4970 lpfc_els_rcv_echo(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
4971 struct lpfc_nodelist
*ndlp
)
4975 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) cmdiocb
->context2
)->virt
);
4977 /* skip over first word of echo command to find echo data */
4978 pcmd
+= sizeof(uint32_t);
4980 lpfc_els_rsp_echo_acc(vport
, pcmd
, cmdiocb
, ndlp
);
4985 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
4986 * @vport: pointer to a host virtual N_Port data structure.
4987 * @cmdiocb: pointer to lpfc command iocb data structure.
4988 * @ndlp: pointer to a node-list data structure.
4990 * This routine processes a Link Incident Report Registration(LIRR) IOCB
4991 * received as an ELS unsolicited event. Currently, this function just invokes
4992 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
4995 * 0 - Successfully processed lirr iocb (currently always return 0)
4998 lpfc_els_rcv_lirr(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
4999 struct lpfc_nodelist
*ndlp
)
5003 /* For now, unconditionally reject this command */
5004 stat
.un
.b
.lsRjtRsvd0
= 0;
5005 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
5006 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CANT_GIVE_DATA
;
5007 stat
.un
.b
.vendorUnique
= 0;
5008 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
5013 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
5014 * @vport: pointer to a host virtual N_Port data structure.
5015 * @cmdiocb: pointer to lpfc command iocb data structure.
5016 * @ndlp: pointer to a node-list data structure.
5018 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
5019 * received as an ELS unsolicited event. A request to RRQ shall only
5020 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
5021 * Nx_Port N_Port_ID of the target Exchange is the same as the
5022 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
5023 * not accepted, an LS_RJT with reason code "Unable to perform
5024 * command request" and reason code explanation "Invalid Originator
5025 * S_ID" shall be returned. For now, we just unconditionally accept
5026 * RRQ from the target.
5029 lpfc_els_rcv_rrq(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
5030 struct lpfc_nodelist
*ndlp
)
5032 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
5033 if (vport
->phba
->sli_rev
== LPFC_SLI_REV4
)
5034 lpfc_els_clear_rrq(vport
, cmdiocb
, ndlp
);
5038 * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
5039 * @phba: pointer to lpfc hba data structure.
5040 * @pmb: pointer to the driver internal queue element for mailbox command.
5042 * This routine is the completion callback function for the MBX_READ_LNK_STAT
5043 * mailbox command. This callback function is to actually send the Accept
5044 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
5045 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
5046 * mailbox command, constructs the RPS response with the link statistics
5047 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
5048 * response to the RPS.
5050 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5051 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5052 * will be stored into the context1 field of the IOCB for the completion
5053 * callback function to the RPS Accept Response ELS IOCB command.
5057 lpfc_els_rsp_rls_acc(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
5061 struct RLS_RSP
*rls_rsp
;
5063 struct lpfc_iocbq
*elsiocb
;
5064 struct lpfc_nodelist
*ndlp
;
5071 ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
5072 rxid
= (uint16_t) ((unsigned long)(pmb
->context1
) & 0xffff);
5073 oxid
= (uint16_t) (((unsigned long)(pmb
->context1
) >> 16) & 0xffff);
5074 pmb
->context1
= NULL
;
5075 pmb
->context2
= NULL
;
5077 if (mb
->mbxStatus
) {
5078 mempool_free(pmb
, phba
->mbox_mem_pool
);
5082 cmdsize
= sizeof(struct RLS_RSP
) + sizeof(uint32_t);
5083 mempool_free(pmb
, phba
->mbox_mem_pool
);
5084 elsiocb
= lpfc_prep_els_iocb(phba
->pport
, 0, cmdsize
,
5085 lpfc_max_els_tries
, ndlp
,
5086 ndlp
->nlp_DID
, ELS_CMD_ACC
);
5088 /* Decrement the ndlp reference count from previous mbox command */
5094 icmd
= &elsiocb
->iocb
;
5095 icmd
->ulpContext
= rxid
;
5096 icmd
->unsli3
.rcvsli3
.ox_id
= oxid
;
5098 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
5099 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
5100 pcmd
+= sizeof(uint32_t); /* Skip past command */
5101 rls_rsp
= (struct RLS_RSP
*)pcmd
;
5103 rls_rsp
->linkFailureCnt
= cpu_to_be32(mb
->un
.varRdLnk
.linkFailureCnt
);
5104 rls_rsp
->lossSyncCnt
= cpu_to_be32(mb
->un
.varRdLnk
.lossSyncCnt
);
5105 rls_rsp
->lossSignalCnt
= cpu_to_be32(mb
->un
.varRdLnk
.lossSignalCnt
);
5106 rls_rsp
->primSeqErrCnt
= cpu_to_be32(mb
->un
.varRdLnk
.primSeqErrCnt
);
5107 rls_rsp
->invalidXmitWord
= cpu_to_be32(mb
->un
.varRdLnk
.invalidXmitWord
);
5108 rls_rsp
->crcCnt
= cpu_to_be32(mb
->un
.varRdLnk
.crcCnt
);
5110 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
5111 lpfc_printf_vlog(ndlp
->vport
, KERN_INFO
, LOG_ELS
,
5112 "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
5113 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
5114 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
5115 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
5117 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
5118 phba
->fc_stat
.elsXmitACC
++;
5119 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) == IOCB_ERROR
)
5120 lpfc_els_free_iocb(phba
, elsiocb
);
5124 * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
5125 * @phba: pointer to lpfc hba data structure.
5126 * @pmb: pointer to the driver internal queue element for mailbox command.
5128 * This routine is the completion callback function for the MBX_READ_LNK_STAT
5129 * mailbox command. This callback function is to actually send the Accept
5130 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
5131 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
5132 * mailbox command, constructs the RPS response with the link statistics
5133 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
5134 * response to the RPS.
5136 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5137 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5138 * will be stored into the context1 field of the IOCB for the completion
5139 * callback function to the RPS Accept Response ELS IOCB command.
5143 lpfc_els_rsp_rps_acc(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
5149 struct lpfc_iocbq
*elsiocb
;
5150 struct lpfc_nodelist
*ndlp
;
5158 ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
5159 rxid
= (uint16_t) ((unsigned long)(pmb
->context1
) & 0xffff);
5160 oxid
= (uint16_t) (((unsigned long)(pmb
->context1
) >> 16) & 0xffff);
5161 pmb
->context1
= NULL
;
5162 pmb
->context2
= NULL
;
5164 if (mb
->mbxStatus
) {
5165 mempool_free(pmb
, phba
->mbox_mem_pool
);
5169 cmdsize
= sizeof(RPS_RSP
) + sizeof(uint32_t);
5170 mempool_free(pmb
, phba
->mbox_mem_pool
);
5171 elsiocb
= lpfc_prep_els_iocb(phba
->pport
, 0, cmdsize
,
5172 lpfc_max_els_tries
, ndlp
,
5173 ndlp
->nlp_DID
, ELS_CMD_ACC
);
5175 /* Decrement the ndlp reference count from previous mbox command */
5181 icmd
= &elsiocb
->iocb
;
5182 icmd
->ulpContext
= rxid
;
5183 icmd
->unsli3
.rcvsli3
.ox_id
= oxid
;
5185 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
5186 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
5187 pcmd
+= sizeof(uint32_t); /* Skip past command */
5188 rps_rsp
= (RPS_RSP
*)pcmd
;
5190 if (phba
->fc_topology
!= LPFC_TOPOLOGY_LOOP
)
5194 if (phba
->pport
->fc_flag
& FC_FABRIC
)
5198 rps_rsp
->portStatus
= cpu_to_be16(status
);
5199 rps_rsp
->linkFailureCnt
= cpu_to_be32(mb
->un
.varRdLnk
.linkFailureCnt
);
5200 rps_rsp
->lossSyncCnt
= cpu_to_be32(mb
->un
.varRdLnk
.lossSyncCnt
);
5201 rps_rsp
->lossSignalCnt
= cpu_to_be32(mb
->un
.varRdLnk
.lossSignalCnt
);
5202 rps_rsp
->primSeqErrCnt
= cpu_to_be32(mb
->un
.varRdLnk
.primSeqErrCnt
);
5203 rps_rsp
->invalidXmitWord
= cpu_to_be32(mb
->un
.varRdLnk
.invalidXmitWord
);
5204 rps_rsp
->crcCnt
= cpu_to_be32(mb
->un
.varRdLnk
.crcCnt
);
5205 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
5206 lpfc_printf_vlog(ndlp
->vport
, KERN_INFO
, LOG_ELS
,
5207 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
5208 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
5209 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
5210 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
5212 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
5213 phba
->fc_stat
.elsXmitACC
++;
5214 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) == IOCB_ERROR
)
5215 lpfc_els_free_iocb(phba
, elsiocb
);
5220 * lpfc_els_rcv_rls - Process an unsolicited rls iocb
5221 * @vport: pointer to a host virtual N_Port data structure.
5222 * @cmdiocb: pointer to lpfc command iocb data structure.
5223 * @ndlp: pointer to a node-list data structure.
5225 * This routine processes Read Port Status (RPL) IOCB received as an
5226 * ELS unsolicited event. It first checks the remote port state. If the
5227 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5228 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
5229 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
5230 * for reading the HBA link statistics. It is for the callback function,
5231 * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
5232 * to actually sending out RPL Accept (ACC) response.
5235 * 0 - Successfully processed rls iocb (currently always return 0)
5238 lpfc_els_rcv_rls(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
5239 struct lpfc_nodelist
*ndlp
)
5241 struct lpfc_hba
*phba
= vport
->phba
;
5243 struct lpfc_dmabuf
*pcmd
;
5246 if ((ndlp
->nlp_state
!= NLP_STE_UNMAPPED_NODE
) &&
5247 (ndlp
->nlp_state
!= NLP_STE_MAPPED_NODE
))
5248 /* reject the unsolicited RPS request and done with it */
5251 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
5253 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_ATOMIC
);
5255 lpfc_read_lnk_stat(phba
, mbox
);
5256 mbox
->context1
= (void *)((unsigned long)
5257 ((cmdiocb
->iocb
.unsli3
.rcvsli3
.ox_id
<< 16) |
5258 cmdiocb
->iocb
.ulpContext
)); /* rx_id */
5259 mbox
->context2
= lpfc_nlp_get(ndlp
);
5260 mbox
->vport
= vport
;
5261 mbox
->mbox_cmpl
= lpfc_els_rsp_rls_acc
;
5262 if (lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
)
5263 != MBX_NOT_FINISHED
)
5264 /* Mbox completion will send ELS Response */
5266 /* Decrement reference count used for the failed mbox
5270 mempool_free(mbox
, phba
->mbox_mem_pool
);
5273 /* issue rejection response */
5274 stat
.un
.b
.lsRjtRsvd0
= 0;
5275 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
5276 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CANT_GIVE_DATA
;
5277 stat
.un
.b
.vendorUnique
= 0;
5278 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
5283 * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
5284 * @vport: pointer to a host virtual N_Port data structure.
5285 * @cmdiocb: pointer to lpfc command iocb data structure.
5286 * @ndlp: pointer to a node-list data structure.
5288 * This routine processes Read Timout Value (RTV) IOCB received as an
5289 * ELS unsolicited event. It first checks the remote port state. If the
5290 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5291 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
5292 * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
5293 * Value (RTV) unsolicited IOCB event.
5295 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5296 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5297 * will be stored into the context1 field of the IOCB for the completion
5298 * callback function to the RPS Accept Response ELS IOCB command.
5301 * 0 - Successfully processed rtv iocb (currently always return 0)
5304 lpfc_els_rcv_rtv(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
5305 struct lpfc_nodelist
*ndlp
)
5307 struct lpfc_hba
*phba
= vport
->phba
;
5309 struct RTV_RSP
*rtv_rsp
;
5311 struct lpfc_iocbq
*elsiocb
;
5315 if ((ndlp
->nlp_state
!= NLP_STE_UNMAPPED_NODE
) &&
5316 (ndlp
->nlp_state
!= NLP_STE_MAPPED_NODE
))
5317 /* reject the unsolicited RPS request and done with it */
5320 cmdsize
= sizeof(struct RTV_RSP
) + sizeof(uint32_t);
5321 elsiocb
= lpfc_prep_els_iocb(phba
->pport
, 0, cmdsize
,
5322 lpfc_max_els_tries
, ndlp
,
5323 ndlp
->nlp_DID
, ELS_CMD_ACC
);
5328 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
5329 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
5330 pcmd
+= sizeof(uint32_t); /* Skip past command */
5332 /* use the command's xri in the response */
5333 elsiocb
->iocb
.ulpContext
= cmdiocb
->iocb
.ulpContext
; /* Xri / rx_id */
5334 elsiocb
->iocb
.unsli3
.rcvsli3
.ox_id
= cmdiocb
->iocb
.unsli3
.rcvsli3
.ox_id
;
5336 rtv_rsp
= (struct RTV_RSP
*)pcmd
;
5338 /* populate RTV payload */
5339 rtv_rsp
->ratov
= cpu_to_be32(phba
->fc_ratov
* 1000); /* report msecs */
5340 rtv_rsp
->edtov
= cpu_to_be32(phba
->fc_edtov
);
5341 bf_set(qtov_edtovres
, rtv_rsp
, phba
->fc_edtovResol
? 1 : 0);
5342 bf_set(qtov_rttov
, rtv_rsp
, 0); /* Field is for FC ONLY */
5343 rtv_rsp
->qtov
= cpu_to_be32(rtv_rsp
->qtov
);
5345 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
5346 lpfc_printf_vlog(ndlp
->vport
, KERN_INFO
, LOG_ELS
,
5347 "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
5348 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
5349 "Data: x%x x%x x%x\n",
5350 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
5351 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
5353 rtv_rsp
->ratov
, rtv_rsp
->edtov
, rtv_rsp
->qtov
);
5354 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
5355 phba
->fc_stat
.elsXmitACC
++;
5356 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) == IOCB_ERROR
)
5357 lpfc_els_free_iocb(phba
, elsiocb
);
5361 /* issue rejection response */
5362 stat
.un
.b
.lsRjtRsvd0
= 0;
5363 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
5364 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CANT_GIVE_DATA
;
5365 stat
.un
.b
.vendorUnique
= 0;
5366 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
5370 /* lpfc_els_rcv_rps - Process an unsolicited rps iocb
5371 * @vport: pointer to a host virtual N_Port data structure.
5372 * @cmdiocb: pointer to lpfc command iocb data structure.
5373 * @ndlp: pointer to a node-list data structure.
5375 * This routine processes Read Port Status (RPS) IOCB received as an
5376 * ELS unsolicited event. It first checks the remote port state. If the
5377 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5378 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
5379 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
5380 * for reading the HBA link statistics. It is for the callback function,
5381 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
5382 * to actually sending out RPS Accept (ACC) response.
5385 * 0 - Successfully processed rps iocb (currently always return 0)
5388 lpfc_els_rcv_rps(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
5389 struct lpfc_nodelist
*ndlp
)
5391 struct lpfc_hba
*phba
= vport
->phba
;
5395 struct lpfc_dmabuf
*pcmd
;
5399 if ((ndlp
->nlp_state
!= NLP_STE_UNMAPPED_NODE
) &&
5400 (ndlp
->nlp_state
!= NLP_STE_MAPPED_NODE
))
5401 /* reject the unsolicited RPS request and done with it */
5404 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
5405 lp
= (uint32_t *) pcmd
->virt
;
5406 flag
= (be32_to_cpu(*lp
++) & 0xf);
5410 ((flag
== 1) && (be32_to_cpu(rps
->un
.portNum
) == 0)) ||
5411 ((flag
== 2) && (memcmp(&rps
->un
.portName
, &vport
->fc_portname
,
5412 sizeof(struct lpfc_name
)) == 0))) {
5414 printk("Fix me....\n");
5416 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_ATOMIC
);
5418 lpfc_read_lnk_stat(phba
, mbox
);
5419 mbox
->context1
= (void *)((unsigned long)
5420 ((cmdiocb
->iocb
.unsli3
.rcvsli3
.ox_id
<< 16) |
5421 cmdiocb
->iocb
.ulpContext
)); /* rx_id */
5422 mbox
->context2
= lpfc_nlp_get(ndlp
);
5423 mbox
->vport
= vport
;
5424 mbox
->mbox_cmpl
= lpfc_els_rsp_rps_acc
;
5425 if (lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
)
5426 != MBX_NOT_FINISHED
)
5427 /* Mbox completion will send ELS Response */
5429 /* Decrement reference count used for the failed mbox
5433 mempool_free(mbox
, phba
->mbox_mem_pool
);
5438 /* issue rejection response */
5439 stat
.un
.b
.lsRjtRsvd0
= 0;
5440 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
5441 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CANT_GIVE_DATA
;
5442 stat
.un
.b
.vendorUnique
= 0;
5443 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
5447 /* lpfc_issue_els_rrq - Process an unsolicited rps iocb
5448 * @vport: pointer to a host virtual N_Port data structure.
5449 * @ndlp: pointer to a node-list data structure.
5450 * @did: DID of the target.
5451 * @rrq: Pointer to the rrq struct.
5453 * Build a ELS RRQ command and send it to the target. If the issue_iocb is
5454 * Successful the the completion handler will clear the RRQ.
5457 * 0 - Successfully sent rrq els iocb.
5458 * 1 - Failed to send rrq els iocb.
5461 lpfc_issue_els_rrq(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
5462 uint32_t did
, struct lpfc_node_rrq
*rrq
)
5464 struct lpfc_hba
*phba
= vport
->phba
;
5465 struct RRQ
*els_rrq
;
5467 struct lpfc_iocbq
*elsiocb
;
5473 if (ndlp
!= rrq
->ndlp
)
5475 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
))
5478 /* If ndlp is not NULL, we will bump the reference count on it */
5479 cmdsize
= (sizeof(uint32_t) + sizeof(struct RRQ
));
5480 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, 0, ndlp
, did
,
5485 icmd
= &elsiocb
->iocb
;
5486 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
5488 /* For RRQ request, remainder of payload is Exchange IDs */
5489 *((uint32_t *) (pcmd
)) = ELS_CMD_RRQ
;
5490 pcmd
+= sizeof(uint32_t);
5491 els_rrq
= (struct RRQ
*) pcmd
;
5493 bf_set(rrq_oxid
, els_rrq
, rrq
->xritag
);
5494 bf_set(rrq_rxid
, els_rrq
, rrq
->rxid
);
5495 bf_set(rrq_did
, els_rrq
, vport
->fc_myDID
);
5496 els_rrq
->rrq
= cpu_to_be32(els_rrq
->rrq
);
5497 els_rrq
->rrq_exchg
= cpu_to_be32(els_rrq
->rrq_exchg
);
5500 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
5501 "Issue RRQ: did:x%x",
5502 did
, rrq
->xritag
, rrq
->rxid
);
5503 elsiocb
->context_un
.rrq
= rrq
;
5504 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rrq
;
5505 ret
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
5507 if (ret
== IOCB_ERROR
) {
5508 lpfc_els_free_iocb(phba
, elsiocb
);
5515 * lpfc_send_rrq - Sends ELS RRQ if needed.
5516 * @phba: pointer to lpfc hba data structure.
5517 * @rrq: pointer to the active rrq.
5519 * This routine will call the lpfc_issue_els_rrq if the rrq is
5520 * still active for the xri. If this function returns a failure then
5521 * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq.
5523 * Returns 0 Success.
5527 lpfc_send_rrq(struct lpfc_hba
*phba
, struct lpfc_node_rrq
*rrq
)
5529 struct lpfc_nodelist
*ndlp
= lpfc_findnode_did(rrq
->vport
,
5531 if (lpfc_test_rrq_active(phba
, ndlp
, rrq
->xritag
))
5532 return lpfc_issue_els_rrq(rrq
->vport
, ndlp
,
5539 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
5540 * @vport: pointer to a host virtual N_Port data structure.
5541 * @cmdsize: size of the ELS command.
5542 * @oldiocb: pointer to the original lpfc command iocb data structure.
5543 * @ndlp: pointer to a node-list data structure.
5545 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
5546 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
5548 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5549 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5550 * will be stored into the context1 field of the IOCB for the completion
5551 * callback function to the RPL Accept Response ELS command.
5554 * 0 - Successfully issued ACC RPL ELS command
5555 * 1 - Failed to issue ACC RPL ELS command
5558 lpfc_els_rsp_rpl_acc(struct lpfc_vport
*vport
, uint16_t cmdsize
,
5559 struct lpfc_iocbq
*oldiocb
, struct lpfc_nodelist
*ndlp
)
5561 struct lpfc_hba
*phba
= vport
->phba
;
5562 IOCB_t
*icmd
, *oldcmd
;
5564 struct lpfc_iocbq
*elsiocb
;
5567 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
5568 ndlp
->nlp_DID
, ELS_CMD_ACC
);
5573 icmd
= &elsiocb
->iocb
;
5574 oldcmd
= &oldiocb
->iocb
;
5575 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri / rx_id */
5576 icmd
->unsli3
.rcvsli3
.ox_id
= oldcmd
->unsli3
.rcvsli3
.ox_id
;
5578 pcmd
= (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
5579 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
5580 pcmd
+= sizeof(uint16_t);
5581 *((uint16_t *)(pcmd
)) = be16_to_cpu(cmdsize
);
5582 pcmd
+= sizeof(uint16_t);
5584 /* Setup the RPL ACC payload */
5585 rpl_rsp
.listLen
= be32_to_cpu(1);
5587 rpl_rsp
.port_num_blk
.portNum
= 0;
5588 rpl_rsp
.port_num_blk
.portID
= be32_to_cpu(vport
->fc_myDID
);
5589 memcpy(&rpl_rsp
.port_num_blk
.portName
, &vport
->fc_portname
,
5590 sizeof(struct lpfc_name
));
5591 memcpy(pcmd
, &rpl_rsp
, cmdsize
- sizeof(uint32_t));
5592 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
5593 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
5594 "0120 Xmit ELS RPL ACC response tag x%x "
5595 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
5597 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
5598 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
5600 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
5601 phba
->fc_stat
.elsXmitACC
++;
5602 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) ==
5604 lpfc_els_free_iocb(phba
, elsiocb
);
5611 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
5612 * @vport: pointer to a host virtual N_Port data structure.
5613 * @cmdiocb: pointer to lpfc command iocb data structure.
5614 * @ndlp: pointer to a node-list data structure.
5616 * This routine processes Read Port List (RPL) IOCB received as an ELS
5617 * unsolicited event. It first checks the remote port state. If the remote
5618 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
5619 * invokes the lpfc_els_rsp_reject() routine to send reject response.
5620 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
5621 * to accept the RPL.
5624 * 0 - Successfully processed rpl iocb (currently always return 0)
5627 lpfc_els_rcv_rpl(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
5628 struct lpfc_nodelist
*ndlp
)
5630 struct lpfc_dmabuf
*pcmd
;
5637 if ((ndlp
->nlp_state
!= NLP_STE_UNMAPPED_NODE
) &&
5638 (ndlp
->nlp_state
!= NLP_STE_MAPPED_NODE
)) {
5639 /* issue rejection response */
5640 stat
.un
.b
.lsRjtRsvd0
= 0;
5641 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
5642 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CANT_GIVE_DATA
;
5643 stat
.un
.b
.vendorUnique
= 0;
5644 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
,
5646 /* rejected the unsolicited RPL request and done with it */
5650 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
5651 lp
= (uint32_t *) pcmd
->virt
;
5652 rpl
= (RPL
*) (lp
+ 1);
5653 maxsize
= be32_to_cpu(rpl
->maxsize
);
5655 /* We support only one port */
5656 if ((rpl
->index
== 0) &&
5658 ((maxsize
* sizeof(uint32_t)) >= sizeof(RPL_RSP
)))) {
5659 cmdsize
= sizeof(uint32_t) + sizeof(RPL_RSP
);
5661 cmdsize
= sizeof(uint32_t) + maxsize
* sizeof(uint32_t);
5663 lpfc_els_rsp_rpl_acc(vport
, cmdsize
, cmdiocb
, ndlp
);
5669 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
5670 * @vport: pointer to a virtual N_Port data structure.
5671 * @cmdiocb: pointer to lpfc command iocb data structure.
5672 * @ndlp: pointer to a node-list data structure.
5674 * This routine processes Fibre Channel Address Resolution Protocol
5675 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
5676 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
5677 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
5678 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
5679 * remote PortName is compared against the FC PortName stored in the @vport
5680 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
5681 * compared against the FC NodeName stored in the @vport data structure.
5682 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
5683 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
5684 * invoked to send out FARP Response to the remote node. Before sending the
5685 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
5686 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
5687 * routine is invoked to log into the remote port first.
5690 * 0 - Either the FARP Match Mode not supported or successfully processed
5693 lpfc_els_rcv_farp(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
5694 struct lpfc_nodelist
*ndlp
)
5696 struct lpfc_dmabuf
*pcmd
;
5700 uint32_t cmd
, cnt
, did
;
5702 icmd
= &cmdiocb
->iocb
;
5703 did
= icmd
->un
.elsreq64
.remoteID
;
5704 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
5705 lp
= (uint32_t *) pcmd
->virt
;
5709 /* FARP-REQ received from DID <did> */
5710 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
5711 "0601 FARP-REQ received from DID x%x\n", did
);
5712 /* We will only support match on WWPN or WWNN */
5713 if (fp
->Mflags
& ~(FARP_MATCH_NODE
| FARP_MATCH_PORT
)) {
5718 /* If this FARP command is searching for my portname */
5719 if (fp
->Mflags
& FARP_MATCH_PORT
) {
5720 if (memcmp(&fp
->RportName
, &vport
->fc_portname
,
5721 sizeof(struct lpfc_name
)) == 0)
5725 /* If this FARP command is searching for my nodename */
5726 if (fp
->Mflags
& FARP_MATCH_NODE
) {
5727 if (memcmp(&fp
->RnodeName
, &vport
->fc_nodename
,
5728 sizeof(struct lpfc_name
)) == 0)
5733 if ((ndlp
->nlp_state
== NLP_STE_UNMAPPED_NODE
) ||
5734 (ndlp
->nlp_state
== NLP_STE_MAPPED_NODE
)) {
5735 /* Log back into the node before sending the FARP. */
5736 if (fp
->Rflags
& FARP_REQUEST_PLOGI
) {
5737 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
5738 lpfc_nlp_set_state(vport
, ndlp
,
5739 NLP_STE_PLOGI_ISSUE
);
5740 lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0);
5743 /* Send a FARP response to that node */
5744 if (fp
->Rflags
& FARP_REQUEST_FARPR
)
5745 lpfc_issue_els_farpr(vport
, did
, 0);
5752 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
5753 * @vport: pointer to a host virtual N_Port data structure.
5754 * @cmdiocb: pointer to lpfc command iocb data structure.
5755 * @ndlp: pointer to a node-list data structure.
5757 * This routine processes Fibre Channel Address Resolution Protocol
5758 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
5759 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
5760 * the FARP response request.
5763 * 0 - Successfully processed FARPR IOCB (currently always return 0)
5766 lpfc_els_rcv_farpr(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
5767 struct lpfc_nodelist
*ndlp
)
5769 struct lpfc_dmabuf
*pcmd
;
5774 icmd
= &cmdiocb
->iocb
;
5775 did
= icmd
->un
.elsreq64
.remoteID
;
5776 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
5777 lp
= (uint32_t *) pcmd
->virt
;
5780 /* FARP-RSP received from DID <did> */
5781 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
5782 "0600 FARP-RSP received from DID x%x\n", did
);
5783 /* ACCEPT the Farp resp request */
5784 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
5790 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
5791 * @vport: pointer to a host virtual N_Port data structure.
5792 * @cmdiocb: pointer to lpfc command iocb data structure.
5793 * @fan_ndlp: pointer to a node-list data structure.
5795 * This routine processes a Fabric Address Notification (FAN) IOCB
5796 * command received as an ELS unsolicited event. The FAN ELS command will
5797 * only be processed on a physical port (i.e., the @vport represents the
5798 * physical port). The fabric NodeName and PortName from the FAN IOCB are
5799 * compared against those in the phba data structure. If any of those is
5800 * different, the lpfc_initial_flogi() routine is invoked to initialize
5801 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
5802 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
5803 * is invoked to register login to the fabric.
5806 * 0 - Successfully processed fan iocb (currently always return 0).
5809 lpfc_els_rcv_fan(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
5810 struct lpfc_nodelist
*fan_ndlp
)
5812 struct lpfc_hba
*phba
= vport
->phba
;
5816 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
, "0265 FAN received\n");
5817 lp
= (uint32_t *)((struct lpfc_dmabuf
*)cmdiocb
->context2
)->virt
;
5819 /* FAN received; Fan does not have a reply sequence */
5820 if ((vport
== phba
->pport
) &&
5821 (vport
->port_state
== LPFC_LOCAL_CFG_LINK
)) {
5822 if ((memcmp(&phba
->fc_fabparam
.nodeName
, &fp
->FnodeName
,
5823 sizeof(struct lpfc_name
))) ||
5824 (memcmp(&phba
->fc_fabparam
.portName
, &fp
->FportName
,
5825 sizeof(struct lpfc_name
)))) {
5826 /* This port has switched fabrics. FLOGI is required */
5827 lpfc_issue_init_vfi(vport
);
5829 /* FAN verified - skip FLOGI */
5830 vport
->fc_myDID
= vport
->fc_prevDID
;
5831 if (phba
->sli_rev
< LPFC_SLI_REV4
)
5832 lpfc_issue_fabric_reglogin(vport
);
5834 lpfc_issue_reg_vfi(vport
);
5841 * lpfc_els_timeout - Handler funciton to the els timer
5842 * @ptr: holder for the timer function associated data.
5844 * This routine is invoked by the ELS timer after timeout. It posts the ELS
5845 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
5846 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
5847 * up the worker thread. It is for the worker thread to invoke the routine
5848 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
5851 lpfc_els_timeout(unsigned long ptr
)
5853 struct lpfc_vport
*vport
= (struct lpfc_vport
*) ptr
;
5854 struct lpfc_hba
*phba
= vport
->phba
;
5855 uint32_t tmo_posted
;
5856 unsigned long iflag
;
5858 spin_lock_irqsave(&vport
->work_port_lock
, iflag
);
5859 tmo_posted
= vport
->work_port_events
& WORKER_ELS_TMO
;
5861 vport
->work_port_events
|= WORKER_ELS_TMO
;
5862 spin_unlock_irqrestore(&vport
->work_port_lock
, iflag
);
5865 lpfc_worker_wake_up(phba
);
5871 * lpfc_els_timeout_handler - Process an els timeout event
5872 * @vport: pointer to a virtual N_Port data structure.
5874 * This routine is the actual handler function that processes an ELS timeout
5875 * event. It walks the ELS ring to get and abort all the IOCBs (except the
5876 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
5877 * invoking the lpfc_sli_issue_abort_iotag() routine.
5880 lpfc_els_timeout_handler(struct lpfc_vport
*vport
)
5882 struct lpfc_hba
*phba
= vport
->phba
;
5883 struct lpfc_sli_ring
*pring
;
5884 struct lpfc_iocbq
*tmp_iocb
, *piocb
;
5886 struct lpfc_dmabuf
*pcmd
;
5887 uint32_t els_command
= 0;
5889 uint32_t remote_ID
= 0xffffffff;
5890 LIST_HEAD(txcmplq_completions
);
5891 LIST_HEAD(abort_list
);
5894 timeout
= (uint32_t)(phba
->fc_ratov
<< 1);
5896 pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
5898 spin_lock_irq(&phba
->hbalock
);
5899 list_splice_init(&pring
->txcmplq
, &txcmplq_completions
);
5900 spin_unlock_irq(&phba
->hbalock
);
5902 list_for_each_entry_safe(piocb
, tmp_iocb
, &txcmplq_completions
, list
) {
5905 if ((piocb
->iocb_flag
& LPFC_IO_LIBDFC
) != 0 ||
5906 piocb
->iocb
.ulpCommand
== CMD_ABORT_XRI_CN
||
5907 piocb
->iocb
.ulpCommand
== CMD_CLOSE_XRI_CN
)
5910 if (piocb
->vport
!= vport
)
5913 pcmd
= (struct lpfc_dmabuf
*) piocb
->context2
;
5915 els_command
= *(uint32_t *) (pcmd
->virt
);
5917 if (els_command
== ELS_CMD_FARP
||
5918 els_command
== ELS_CMD_FARPR
||
5919 els_command
== ELS_CMD_FDISC
)
5922 if (piocb
->drvrTimeout
> 0) {
5923 if (piocb
->drvrTimeout
>= timeout
)
5924 piocb
->drvrTimeout
-= timeout
;
5926 piocb
->drvrTimeout
= 0;
5930 remote_ID
= 0xffffffff;
5931 if (cmd
->ulpCommand
!= CMD_GEN_REQUEST64_CR
)
5932 remote_ID
= cmd
->un
.elsreq64
.remoteID
;
5934 struct lpfc_nodelist
*ndlp
;
5935 ndlp
= __lpfc_findnode_rpi(vport
, cmd
->ulpContext
);
5936 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
))
5937 remote_ID
= ndlp
->nlp_DID
;
5939 list_add_tail(&piocb
->dlist
, &abort_list
);
5941 spin_lock_irq(&phba
->hbalock
);
5942 list_splice(&txcmplq_completions
, &pring
->txcmplq
);
5943 spin_unlock_irq(&phba
->hbalock
);
5945 list_for_each_entry_safe(piocb
, tmp_iocb
, &abort_list
, dlist
) {
5946 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
5947 "0127 ELS timeout Data: x%x x%x x%x "
5948 "x%x\n", els_command
,
5949 remote_ID
, cmd
->ulpCommand
, cmd
->ulpIoTag
);
5950 spin_lock_irq(&phba
->hbalock
);
5951 list_del_init(&piocb
->dlist
);
5952 lpfc_sli_issue_abort_iotag(phba
, pring
, piocb
);
5953 spin_unlock_irq(&phba
->hbalock
);
5956 if (phba
->sli
.ring
[LPFC_ELS_RING
].txcmplq_cnt
)
5957 mod_timer(&vport
->els_tmofunc
, jiffies
+ HZ
* timeout
);
5961 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
5962 * @vport: pointer to a host virtual N_Port data structure.
5964 * This routine is used to clean up all the outstanding ELS commands on a
5965 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
5966 * routine. After that, it walks the ELS transmit queue to remove all the
5967 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
5968 * the IOCBs with a non-NULL completion callback function, the callback
5969 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
5970 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
5971 * callback function, the IOCB will simply be released. Finally, it walks
5972 * the ELS transmit completion queue to issue an abort IOCB to any transmit
5973 * completion queue IOCB that is associated with the @vport and is not
5974 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
5975 * part of the discovery state machine) out to HBA by invoking the
5976 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
5977 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
5978 * the IOCBs are aborted when this function returns.
5981 lpfc_els_flush_cmd(struct lpfc_vport
*vport
)
5983 LIST_HEAD(completions
);
5984 struct lpfc_hba
*phba
= vport
->phba
;
5985 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
5986 struct lpfc_iocbq
*tmp_iocb
, *piocb
;
5989 lpfc_fabric_abort_vport(vport
);
5991 spin_lock_irq(&phba
->hbalock
);
5992 list_for_each_entry_safe(piocb
, tmp_iocb
, &pring
->txq
, list
) {
5995 if (piocb
->iocb_flag
& LPFC_IO_LIBDFC
) {
5999 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
6000 if (cmd
->ulpCommand
== CMD_QUE_RING_BUF_CN
||
6001 cmd
->ulpCommand
== CMD_QUE_RING_BUF64_CN
||
6002 cmd
->ulpCommand
== CMD_CLOSE_XRI_CN
||
6003 cmd
->ulpCommand
== CMD_ABORT_XRI_CN
)
6006 if (piocb
->vport
!= vport
)
6009 list_move_tail(&piocb
->list
, &completions
);
6013 list_for_each_entry_safe(piocb
, tmp_iocb
, &pring
->txcmplq
, list
) {
6014 if (piocb
->iocb_flag
& LPFC_IO_LIBDFC
) {
6018 if (piocb
->vport
!= vport
)
6021 lpfc_sli_issue_abort_iotag(phba
, pring
, piocb
);
6023 spin_unlock_irq(&phba
->hbalock
);
6025 /* Cancell all the IOCBs from the completions list */
6026 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
6033 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
6034 * @phba: pointer to lpfc hba data structure.
6036 * This routine is used to clean up all the outstanding ELS commands on a
6037 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
6038 * routine. After that, it walks the ELS transmit queue to remove all the
6039 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
6040 * the IOCBs with the completion callback function associated, the callback
6041 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
6042 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
6043 * callback function associated, the IOCB will simply be released. Finally,
6044 * it walks the ELS transmit completion queue to issue an abort IOCB to any
6045 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
6046 * management plane IOCBs that are not part of the discovery state machine)
6047 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
6050 lpfc_els_flush_all_cmd(struct lpfc_hba
*phba
)
6052 LIST_HEAD(completions
);
6053 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
6054 struct lpfc_iocbq
*tmp_iocb
, *piocb
;
6057 lpfc_fabric_abort_hba(phba
);
6058 spin_lock_irq(&phba
->hbalock
);
6059 list_for_each_entry_safe(piocb
, tmp_iocb
, &pring
->txq
, list
) {
6061 if (piocb
->iocb_flag
& LPFC_IO_LIBDFC
)
6063 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
6064 if (cmd
->ulpCommand
== CMD_QUE_RING_BUF_CN
||
6065 cmd
->ulpCommand
== CMD_QUE_RING_BUF64_CN
||
6066 cmd
->ulpCommand
== CMD_CLOSE_XRI_CN
||
6067 cmd
->ulpCommand
== CMD_ABORT_XRI_CN
)
6069 list_move_tail(&piocb
->list
, &completions
);
6072 list_for_each_entry_safe(piocb
, tmp_iocb
, &pring
->txcmplq
, list
) {
6073 if (piocb
->iocb_flag
& LPFC_IO_LIBDFC
)
6075 lpfc_sli_issue_abort_iotag(phba
, pring
, piocb
);
6077 spin_unlock_irq(&phba
->hbalock
);
6079 /* Cancel all the IOCBs from the completions list */
6080 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
6087 * lpfc_send_els_failure_event - Posts an ELS command failure event
6088 * @phba: Pointer to hba context object.
6089 * @cmdiocbp: Pointer to command iocb which reported error.
6090 * @rspiocbp: Pointer to response iocb which reported error.
6092 * This function sends an event when there is an ELS command
6096 lpfc_send_els_failure_event(struct lpfc_hba
*phba
,
6097 struct lpfc_iocbq
*cmdiocbp
,
6098 struct lpfc_iocbq
*rspiocbp
)
6100 struct lpfc_vport
*vport
= cmdiocbp
->vport
;
6101 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
6102 struct lpfc_lsrjt_event lsrjt_event
;
6103 struct lpfc_fabric_event_header fabric_event
;
6105 struct lpfc_nodelist
*ndlp
;
6108 ndlp
= cmdiocbp
->context1
;
6109 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
))
6112 if (rspiocbp
->iocb
.ulpStatus
== IOSTAT_LS_RJT
) {
6113 lsrjt_event
.header
.event_type
= FC_REG_ELS_EVENT
;
6114 lsrjt_event
.header
.subcategory
= LPFC_EVENT_LSRJT_RCV
;
6115 memcpy(lsrjt_event
.header
.wwpn
, &ndlp
->nlp_portname
,
6116 sizeof(struct lpfc_name
));
6117 memcpy(lsrjt_event
.header
.wwnn
, &ndlp
->nlp_nodename
,
6118 sizeof(struct lpfc_name
));
6119 pcmd
= (uint32_t *) (((struct lpfc_dmabuf
*)
6120 cmdiocbp
->context2
)->virt
);
6121 lsrjt_event
.command
= (pcmd
!= NULL
) ? *pcmd
: 0;
6122 stat
.un
.lsRjtError
= be32_to_cpu(rspiocbp
->iocb
.un
.ulpWord
[4]);
6123 lsrjt_event
.reason_code
= stat
.un
.b
.lsRjtRsnCode
;
6124 lsrjt_event
.explanation
= stat
.un
.b
.lsRjtRsnCodeExp
;
6125 fc_host_post_vendor_event(shost
,
6126 fc_get_event_number(),
6127 sizeof(lsrjt_event
),
6128 (char *)&lsrjt_event
,
6132 if ((rspiocbp
->iocb
.ulpStatus
== IOSTAT_NPORT_BSY
) ||
6133 (rspiocbp
->iocb
.ulpStatus
== IOSTAT_FABRIC_BSY
)) {
6134 fabric_event
.event_type
= FC_REG_FABRIC_EVENT
;
6135 if (rspiocbp
->iocb
.ulpStatus
== IOSTAT_NPORT_BSY
)
6136 fabric_event
.subcategory
= LPFC_EVENT_PORT_BUSY
;
6138 fabric_event
.subcategory
= LPFC_EVENT_FABRIC_BUSY
;
6139 memcpy(fabric_event
.wwpn
, &ndlp
->nlp_portname
,
6140 sizeof(struct lpfc_name
));
6141 memcpy(fabric_event
.wwnn
, &ndlp
->nlp_nodename
,
6142 sizeof(struct lpfc_name
));
6143 fc_host_post_vendor_event(shost
,
6144 fc_get_event_number(),
6145 sizeof(fabric_event
),
6146 (char *)&fabric_event
,
6154 * lpfc_send_els_event - Posts unsolicited els event
6155 * @vport: Pointer to vport object.
6156 * @ndlp: Pointer FC node object.
6157 * @cmd: ELS command code.
6159 * This function posts an event when there is an incoming
6160 * unsolicited ELS command.
6163 lpfc_send_els_event(struct lpfc_vport
*vport
,
6164 struct lpfc_nodelist
*ndlp
,
6167 struct lpfc_els_event_header
*els_data
= NULL
;
6168 struct lpfc_logo_event
*logo_data
= NULL
;
6169 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
6171 if (*payload
== ELS_CMD_LOGO
) {
6172 logo_data
= kmalloc(sizeof(struct lpfc_logo_event
), GFP_KERNEL
);
6174 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
6175 "0148 Failed to allocate memory "
6176 "for LOGO event\n");
6179 els_data
= &logo_data
->header
;
6181 els_data
= kmalloc(sizeof(struct lpfc_els_event_header
),
6184 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
6185 "0149 Failed to allocate memory "
6190 els_data
->event_type
= FC_REG_ELS_EVENT
;
6193 els_data
->subcategory
= LPFC_EVENT_PLOGI_RCV
;
6196 els_data
->subcategory
= LPFC_EVENT_PRLO_RCV
;
6199 els_data
->subcategory
= LPFC_EVENT_ADISC_RCV
;
6202 els_data
->subcategory
= LPFC_EVENT_LOGO_RCV
;
6203 /* Copy the WWPN in the LOGO payload */
6204 memcpy(logo_data
->logo_wwpn
, &payload
[2],
6205 sizeof(struct lpfc_name
));
6211 memcpy(els_data
->wwpn
, &ndlp
->nlp_portname
, sizeof(struct lpfc_name
));
6212 memcpy(els_data
->wwnn
, &ndlp
->nlp_nodename
, sizeof(struct lpfc_name
));
6213 if (*payload
== ELS_CMD_LOGO
) {
6214 fc_host_post_vendor_event(shost
,
6215 fc_get_event_number(),
6216 sizeof(struct lpfc_logo_event
),
6221 fc_host_post_vendor_event(shost
,
6222 fc_get_event_number(),
6223 sizeof(struct lpfc_els_event_header
),
6234 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
6235 * @phba: pointer to lpfc hba data structure.
6236 * @pring: pointer to a SLI ring.
6237 * @vport: pointer to a host virtual N_Port data structure.
6238 * @elsiocb: pointer to lpfc els command iocb data structure.
6240 * This routine is used for processing the IOCB associated with a unsolicited
6241 * event. It first determines whether there is an existing ndlp that matches
6242 * the DID from the unsolicited IOCB. If not, it will create a new one with
6243 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
6244 * IOCB is then used to invoke the proper routine and to set up proper state
6245 * of the discovery state machine.
6248 lpfc_els_unsol_buffer(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
6249 struct lpfc_vport
*vport
, struct lpfc_iocbq
*elsiocb
)
6251 struct Scsi_Host
*shost
;
6252 struct lpfc_nodelist
*ndlp
;
6255 uint32_t cmd
, did
, newnode
, rjt_err
= 0;
6256 IOCB_t
*icmd
= &elsiocb
->iocb
;
6258 if (!vport
|| !(elsiocb
->context2
))
6262 payload
= ((struct lpfc_dmabuf
*)elsiocb
->context2
)->virt
;
6264 if ((phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) == 0)
6265 lpfc_post_buffer(phba
, pring
, 1);
6267 did
= icmd
->un
.rcvels
.remoteID
;
6268 if (icmd
->ulpStatus
) {
6269 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6270 "RCV Unsol ELS: status:x%x/x%x did:x%x",
6271 icmd
->ulpStatus
, icmd
->un
.ulpWord
[4], did
);
6275 /* Check to see if link went down during discovery */
6276 if (lpfc_els_chk_latt(vport
))
6279 /* Ignore traffic received during vport shutdown. */
6280 if (vport
->load_flag
& FC_UNLOADING
)
6283 /* If NPort discovery is delayed drop incoming ELS */
6284 if ((vport
->fc_flag
& FC_DISC_DELAYED
) &&
6285 (cmd
!= ELS_CMD_PLOGI
))
6288 ndlp
= lpfc_findnode_did(vport
, did
);
6290 /* Cannot find existing Fabric ndlp, so allocate a new one */
6291 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
6295 lpfc_nlp_init(vport
, ndlp
, did
);
6296 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
6298 if ((did
& Fabric_DID_MASK
) == Fabric_DID_MASK
)
6299 ndlp
->nlp_type
|= NLP_FABRIC
;
6300 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
6301 ndlp
= lpfc_enable_node(vport
, ndlp
,
6302 NLP_STE_UNUSED_NODE
);
6305 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
6307 if ((did
& Fabric_DID_MASK
) == Fabric_DID_MASK
)
6308 ndlp
->nlp_type
|= NLP_FABRIC
;
6309 } else if (ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
) {
6310 /* This is similar to the new node path */
6311 ndlp
= lpfc_nlp_get(ndlp
);
6314 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
6318 phba
->fc_stat
.elsRcvFrame
++;
6320 elsiocb
->context1
= lpfc_nlp_get(ndlp
);
6321 elsiocb
->vport
= vport
;
6323 if ((cmd
& ELS_CMD_MASK
) == ELS_CMD_RSCN
) {
6324 cmd
&= ELS_CMD_MASK
;
6326 /* ELS command <elsCmd> received from NPORT <did> */
6327 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
6328 "0112 ELS command x%x received from NPORT x%x "
6329 "Data: x%x\n", cmd
, did
, vport
->port_state
);
6332 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6333 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
6334 did
, vport
->port_state
, ndlp
->nlp_flag
);
6336 phba
->fc_stat
.elsRcvPLOGI
++;
6337 ndlp
= lpfc_plogi_confirm_nport(phba
, payload
, ndlp
);
6339 lpfc_send_els_event(vport
, ndlp
, payload
);
6341 /* If Nport discovery is delayed, reject PLOGIs */
6342 if (vport
->fc_flag
& FC_DISC_DELAYED
) {
6343 rjt_err
= LSRJT_UNABLE_TPC
;
6346 if (vport
->port_state
< LPFC_DISC_AUTH
) {
6347 if (!(phba
->pport
->fc_flag
& FC_PT2PT
) ||
6348 (phba
->pport
->fc_flag
& FC_PT2PT_PLOGI
)) {
6349 rjt_err
= LSRJT_UNABLE_TPC
;
6352 /* We get here, and drop thru, if we are PT2PT with
6353 * another NPort and the other side has initiated
6354 * the PLOGI before responding to our FLOGI.
6358 shost
= lpfc_shost_from_vport(vport
);
6359 spin_lock_irq(shost
->host_lock
);
6360 ndlp
->nlp_flag
&= ~NLP_TARGET_REMOVE
;
6361 spin_unlock_irq(shost
->host_lock
);
6363 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
,
6368 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6369 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
6370 did
, vport
->port_state
, ndlp
->nlp_flag
);
6372 phba
->fc_stat
.elsRcvFLOGI
++;
6373 lpfc_els_rcv_flogi(vport
, elsiocb
, ndlp
);
6378 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6379 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
6380 did
, vport
->port_state
, ndlp
->nlp_flag
);
6382 phba
->fc_stat
.elsRcvLOGO
++;
6383 lpfc_send_els_event(vport
, ndlp
, payload
);
6384 if (vport
->port_state
< LPFC_DISC_AUTH
) {
6385 rjt_err
= LSRJT_UNABLE_TPC
;
6388 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
, NLP_EVT_RCV_LOGO
);
6391 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6392 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
6393 did
, vport
->port_state
, ndlp
->nlp_flag
);
6395 phba
->fc_stat
.elsRcvPRLO
++;
6396 lpfc_send_els_event(vport
, ndlp
, payload
);
6397 if (vport
->port_state
< LPFC_DISC_AUTH
) {
6398 rjt_err
= LSRJT_UNABLE_TPC
;
6401 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
, NLP_EVT_RCV_PRLO
);
6404 phba
->fc_stat
.elsRcvRSCN
++;
6405 lpfc_els_rcv_rscn(vport
, elsiocb
, ndlp
);
6410 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6411 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
6412 did
, vport
->port_state
, ndlp
->nlp_flag
);
6414 lpfc_send_els_event(vport
, ndlp
, payload
);
6415 phba
->fc_stat
.elsRcvADISC
++;
6416 if (vport
->port_state
< LPFC_DISC_AUTH
) {
6417 rjt_err
= LSRJT_UNABLE_TPC
;
6420 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
,
6424 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6425 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
6426 did
, vport
->port_state
, ndlp
->nlp_flag
);
6428 phba
->fc_stat
.elsRcvPDISC
++;
6429 if (vport
->port_state
< LPFC_DISC_AUTH
) {
6430 rjt_err
= LSRJT_UNABLE_TPC
;
6433 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
,
6437 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6438 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
6439 did
, vport
->port_state
, ndlp
->nlp_flag
);
6441 phba
->fc_stat
.elsRcvFARPR
++;
6442 lpfc_els_rcv_farpr(vport
, elsiocb
, ndlp
);
6445 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6446 "RCV FARP: did:x%x/ste:x%x flg:x%x",
6447 did
, vport
->port_state
, ndlp
->nlp_flag
);
6449 phba
->fc_stat
.elsRcvFARP
++;
6450 lpfc_els_rcv_farp(vport
, elsiocb
, ndlp
);
6453 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6454 "RCV FAN: did:x%x/ste:x%x flg:x%x",
6455 did
, vport
->port_state
, ndlp
->nlp_flag
);
6457 phba
->fc_stat
.elsRcvFAN
++;
6458 lpfc_els_rcv_fan(vport
, elsiocb
, ndlp
);
6461 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6462 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
6463 did
, vport
->port_state
, ndlp
->nlp_flag
);
6465 phba
->fc_stat
.elsRcvPRLI
++;
6466 if (vport
->port_state
< LPFC_DISC_AUTH
) {
6467 rjt_err
= LSRJT_UNABLE_TPC
;
6470 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
, NLP_EVT_RCV_PRLI
);
6473 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6474 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
6475 did
, vport
->port_state
, ndlp
->nlp_flag
);
6477 phba
->fc_stat
.elsRcvLIRR
++;
6478 lpfc_els_rcv_lirr(vport
, elsiocb
, ndlp
);
6483 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6484 "RCV RLS: did:x%x/ste:x%x flg:x%x",
6485 did
, vport
->port_state
, ndlp
->nlp_flag
);
6487 phba
->fc_stat
.elsRcvRLS
++;
6488 lpfc_els_rcv_rls(vport
, elsiocb
, ndlp
);
6493 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6494 "RCV RPS: did:x%x/ste:x%x flg:x%x",
6495 did
, vport
->port_state
, ndlp
->nlp_flag
);
6497 phba
->fc_stat
.elsRcvRPS
++;
6498 lpfc_els_rcv_rps(vport
, elsiocb
, ndlp
);
6503 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6504 "RCV RPL: did:x%x/ste:x%x flg:x%x",
6505 did
, vport
->port_state
, ndlp
->nlp_flag
);
6507 phba
->fc_stat
.elsRcvRPL
++;
6508 lpfc_els_rcv_rpl(vport
, elsiocb
, ndlp
);
6513 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6514 "RCV RNID: did:x%x/ste:x%x flg:x%x",
6515 did
, vport
->port_state
, ndlp
->nlp_flag
);
6517 phba
->fc_stat
.elsRcvRNID
++;
6518 lpfc_els_rcv_rnid(vport
, elsiocb
, ndlp
);
6523 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6524 "RCV RTV: did:x%x/ste:x%x flg:x%x",
6525 did
, vport
->port_state
, ndlp
->nlp_flag
);
6526 phba
->fc_stat
.elsRcvRTV
++;
6527 lpfc_els_rcv_rtv(vport
, elsiocb
, ndlp
);
6532 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6533 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
6534 did
, vport
->port_state
, ndlp
->nlp_flag
);
6536 phba
->fc_stat
.elsRcvRRQ
++;
6537 lpfc_els_rcv_rrq(vport
, elsiocb
, ndlp
);
6542 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6543 "RCV ECHO: did:x%x/ste:x%x flg:x%x",
6544 did
, vport
->port_state
, ndlp
->nlp_flag
);
6546 phba
->fc_stat
.elsRcvECHO
++;
6547 lpfc_els_rcv_echo(vport
, elsiocb
, ndlp
);
6552 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6553 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
6554 cmd
, did
, vport
->port_state
);
6556 /* Unsupported ELS command, reject */
6557 rjt_err
= LSRJT_CMD_UNSUPPORTED
;
6559 /* Unknown ELS command <elsCmd> received from NPORT <did> */
6560 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
6561 "0115 Unknown ELS command x%x "
6562 "received from NPORT x%x\n", cmd
, did
);
6568 /* check if need to LS_RJT received ELS cmd */
6570 memset(&stat
, 0, sizeof(stat
));
6571 stat
.un
.b
.lsRjtRsnCode
= rjt_err
;
6572 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_NOTHING_MORE
;
6573 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, elsiocb
, ndlp
,
6577 lpfc_nlp_put(elsiocb
->context1
);
6578 elsiocb
->context1
= NULL
;
6582 if (vport
&& !(vport
->load_flag
& FC_UNLOADING
))
6583 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
6584 "0111 Dropping received ELS cmd "
6585 "Data: x%x x%x x%x\n",
6586 icmd
->ulpStatus
, icmd
->un
.ulpWord
[4], icmd
->ulpTimeout
);
6587 phba
->fc_stat
.elsRcvDrop
++;
6591 * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier
6592 * @phba: pointer to lpfc hba data structure.
6593 * @vpi: host virtual N_Port identifier.
6595 * This routine finds a vport on a HBA (referred by @phba) through a
6596 * @vpi. The function walks the HBA's vport list and returns the address
6597 * of the vport with the matching @vpi.
6600 * NULL - No vport with the matching @vpi found
6601 * Otherwise - Address to the vport with the matching @vpi.
6604 lpfc_find_vport_by_vpid(struct lpfc_hba
*phba
, uint16_t vpi
)
6606 struct lpfc_vport
*vport
;
6607 unsigned long flags
;
6610 /* The physical ports are always vpi 0 - translate is unnecessary. */
6613 * Translate the physical vpi to the logical vpi. The
6614 * vport stores the logical vpi.
6616 for (i
= 0; i
< phba
->max_vpi
; i
++) {
6617 if (vpi
== phba
->vpi_ids
[i
])
6621 if (i
>= phba
->max_vpi
) {
6622 lpfc_printf_log(phba
, KERN_ERR
, LOG_ELS
,
6623 "2936 Could not find Vport mapped "
6624 "to vpi %d\n", vpi
);
6629 spin_lock_irqsave(&phba
->hbalock
, flags
);
6630 list_for_each_entry(vport
, &phba
->port_list
, listentry
) {
6631 if (vport
->vpi
== i
) {
6632 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
6636 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
6641 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
6642 * @phba: pointer to lpfc hba data structure.
6643 * @pring: pointer to a SLI ring.
6644 * @elsiocb: pointer to lpfc els iocb data structure.
6646 * This routine is used to process an unsolicited event received from a SLI
6647 * (Service Level Interface) ring. The actual processing of the data buffer
6648 * associated with the unsolicited event is done by invoking the routine
6649 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
6650 * SLI ring on which the unsolicited event was received.
6653 lpfc_els_unsol_event(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
6654 struct lpfc_iocbq
*elsiocb
)
6656 struct lpfc_vport
*vport
= phba
->pport
;
6657 IOCB_t
*icmd
= &elsiocb
->iocb
;
6659 struct lpfc_dmabuf
*bdeBuf1
= elsiocb
->context2
;
6660 struct lpfc_dmabuf
*bdeBuf2
= elsiocb
->context3
;
6662 elsiocb
->context1
= NULL
;
6663 elsiocb
->context2
= NULL
;
6664 elsiocb
->context3
= NULL
;
6666 if (icmd
->ulpStatus
== IOSTAT_NEED_BUFFER
) {
6667 lpfc_sli_hbqbuf_add_hbqs(phba
, LPFC_ELS_HBQ
);
6668 } else if (icmd
->ulpStatus
== IOSTAT_LOCAL_REJECT
&&
6669 (icmd
->un
.ulpWord
[4] & 0xff) == IOERR_RCV_BUFFER_WAITING
) {
6670 phba
->fc_stat
.NoRcvBuf
++;
6671 /* Not enough posted buffers; Try posting more buffers */
6672 if (!(phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
))
6673 lpfc_post_buffer(phba
, pring
, 0);
6677 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
6678 (icmd
->ulpCommand
== CMD_IOCB_RCV_ELS64_CX
||
6679 icmd
->ulpCommand
== CMD_IOCB_RCV_SEQ64_CX
)) {
6680 if (icmd
->unsli3
.rcvsli3
.vpi
== 0xffff)
6681 vport
= phba
->pport
;
6683 vport
= lpfc_find_vport_by_vpid(phba
,
6684 icmd
->unsli3
.rcvsli3
.vpi
);
6687 /* If there are no BDEs associated
6688 * with this IOCB, there is nothing to do.
6690 if (icmd
->ulpBdeCount
== 0)
6693 /* type of ELS cmd is first 32bit word
6696 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) {
6697 elsiocb
->context2
= bdeBuf1
;
6699 paddr
= getPaddr(icmd
->un
.cont64
[0].addrHigh
,
6700 icmd
->un
.cont64
[0].addrLow
);
6701 elsiocb
->context2
= lpfc_sli_ringpostbuf_get(phba
, pring
,
6705 lpfc_els_unsol_buffer(phba
, pring
, vport
, elsiocb
);
6707 * The different unsolicited event handlers would tell us
6708 * if they are done with "mp" by setting context2 to NULL.
6710 if (elsiocb
->context2
) {
6711 lpfc_in_buf_free(phba
, (struct lpfc_dmabuf
*)elsiocb
->context2
);
6712 elsiocb
->context2
= NULL
;
6715 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
6716 if ((phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) &&
6717 icmd
->ulpBdeCount
== 2) {
6718 elsiocb
->context2
= bdeBuf2
;
6719 lpfc_els_unsol_buffer(phba
, pring
, vport
, elsiocb
);
6720 /* free mp if we are done with it */
6721 if (elsiocb
->context2
) {
6722 lpfc_in_buf_free(phba
, elsiocb
->context2
);
6723 elsiocb
->context2
= NULL
;
6729 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
6730 * @phba: pointer to lpfc hba data structure.
6731 * @vport: pointer to a virtual N_Port data structure.
6733 * This routine issues a Port Login (PLOGI) to the Name Server with
6734 * State Change Request (SCR) for a @vport. This routine will create an
6735 * ndlp for the Name Server associated to the @vport if such node does
6736 * not already exist. The PLOGI to Name Server is issued by invoking the
6737 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
6738 * (FDMI) is configured to the @vport, a FDMI node will be created and
6739 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
6742 lpfc_do_scr_ns_plogi(struct lpfc_hba
*phba
, struct lpfc_vport
*vport
)
6744 struct lpfc_nodelist
*ndlp
, *ndlp_fdmi
;
6745 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
6748 * If lpfc_delay_discovery parameter is set and the clean address
6749 * bit is cleared and fc fabric parameters chenged, delay FC NPort
6752 spin_lock_irq(shost
->host_lock
);
6753 if (vport
->fc_flag
& FC_DISC_DELAYED
) {
6754 spin_unlock_irq(shost
->host_lock
);
6755 mod_timer(&vport
->delayed_disc_tmo
,
6756 jiffies
+ HZ
* phba
->fc_ratov
);
6759 spin_unlock_irq(shost
->host_lock
);
6761 ndlp
= lpfc_findnode_did(vport
, NameServer_DID
);
6763 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
6765 if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) {
6766 lpfc_disc_start(vport
);
6769 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
6770 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
6771 "0251 NameServer login: no memory\n");
6774 lpfc_nlp_init(vport
, ndlp
, NameServer_DID
);
6775 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
6776 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
6778 if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) {
6779 lpfc_disc_start(vport
);
6782 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
6783 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
6784 "0348 NameServer login: node freed\n");
6788 ndlp
->nlp_type
|= NLP_FABRIC
;
6790 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
6792 if (lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0)) {
6793 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
6794 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
6795 "0252 Cannot issue NameServer login\n");
6799 if (vport
->cfg_fdmi_on
) {
6800 /* If this is the first time, allocate an ndlp and initialize
6801 * it. Otherwise, make sure the node is enabled and then do the
6804 ndlp_fdmi
= lpfc_findnode_did(vport
, FDMI_DID
);
6806 ndlp_fdmi
= mempool_alloc(phba
->nlp_mem_pool
,
6809 lpfc_nlp_init(vport
, ndlp_fdmi
, FDMI_DID
);
6810 ndlp_fdmi
->nlp_type
|= NLP_FABRIC
;
6814 if (!NLP_CHK_NODE_ACT(ndlp_fdmi
))
6815 ndlp_fdmi
= lpfc_enable_node(vport
,
6820 lpfc_nlp_set_state(vport
, ndlp_fdmi
,
6821 NLP_STE_PLOGI_ISSUE
);
6822 lpfc_issue_els_plogi(vport
, ndlp_fdmi
->nlp_DID
, 0);
6828 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
6829 * @phba: pointer to lpfc hba data structure.
6830 * @pmb: pointer to the driver internal queue element for mailbox command.
6832 * This routine is the completion callback function to register new vport
6833 * mailbox command. If the new vport mailbox command completes successfully,
6834 * the fabric registration login shall be performed on physical port (the
6835 * new vport created is actually a physical port, with VPI 0) or the port
6836 * login to Name Server for State Change Request (SCR) will be performed
6837 * on virtual port (real virtual port, with VPI greater than 0).
6840 lpfc_cmpl_reg_new_vport(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
6842 struct lpfc_vport
*vport
= pmb
->vport
;
6843 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
6844 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
6845 MAILBOX_t
*mb
= &pmb
->u
.mb
;
6848 spin_lock_irq(shost
->host_lock
);
6849 vport
->fc_flag
&= ~FC_VPORT_NEEDS_REG_VPI
;
6850 spin_unlock_irq(shost
->host_lock
);
6852 if (mb
->mbxStatus
) {
6853 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
6854 "0915 Register VPI failed : Status: x%x"
6855 " upd bit: x%x \n", mb
->mbxStatus
,
6856 mb
->un
.varRegVpi
.upd
);
6857 if (phba
->sli_rev
== LPFC_SLI_REV4
&&
6858 mb
->un
.varRegVpi
.upd
)
6859 goto mbox_err_exit
;
6861 switch (mb
->mbxStatus
) {
6862 case 0x11: /* unsupported feature */
6863 case 0x9603: /* max_vpi exceeded */
6864 case 0x9602: /* Link event since CLEAR_LA */
6865 /* giving up on vport registration */
6866 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
6867 spin_lock_irq(shost
->host_lock
);
6868 vport
->fc_flag
&= ~(FC_FABRIC
| FC_PUBLIC_LOOP
);
6869 spin_unlock_irq(shost
->host_lock
);
6870 lpfc_can_disctmo(vport
);
6872 /* If reg_vpi fail with invalid VPI status, re-init VPI */
6874 spin_lock_irq(shost
->host_lock
);
6875 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
6876 spin_unlock_irq(shost
->host_lock
);
6877 lpfc_init_vpi(phba
, pmb
, vport
->vpi
);
6879 pmb
->mbox_cmpl
= lpfc_init_vpi_cmpl
;
6880 rc
= lpfc_sli_issue_mbox(phba
, pmb
,
6882 if (rc
== MBX_NOT_FINISHED
) {
6883 lpfc_printf_vlog(vport
,
6885 "2732 Failed to issue INIT_VPI"
6886 " mailbox command\n");
6893 /* Try to recover from this error */
6894 if (phba
->sli_rev
== LPFC_SLI_REV4
)
6895 lpfc_sli4_unreg_all_rpis(vport
);
6896 lpfc_mbx_unreg_vpi(vport
);
6897 spin_lock_irq(shost
->host_lock
);
6898 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
6899 spin_unlock_irq(shost
->host_lock
);
6900 if (vport
->port_type
== LPFC_PHYSICAL_PORT
6901 && !(vport
->fc_flag
& FC_LOGO_RCVD_DID_CHNG
))
6902 lpfc_issue_init_vfi(vport
);
6904 lpfc_initial_fdisc(vport
);
6908 spin_lock_irq(shost
->host_lock
);
6909 vport
->vpi_state
|= LPFC_VPI_REGISTERED
;
6910 spin_unlock_irq(shost
->host_lock
);
6911 if (vport
== phba
->pport
) {
6912 if (phba
->sli_rev
< LPFC_SLI_REV4
)
6913 lpfc_issue_fabric_reglogin(vport
);
6916 * If the physical port is instantiated using
6917 * FDISC, do not start vport discovery.
6919 if (vport
->port_state
!= LPFC_FDISC
)
6920 lpfc_start_fdiscs(phba
);
6921 lpfc_do_scr_ns_plogi(phba
, vport
);
6924 lpfc_do_scr_ns_plogi(phba
, vport
);
6927 /* Now, we decrement the ndlp reference count held for this
6932 mempool_free(pmb
, phba
->mbox_mem_pool
);
6937 * lpfc_register_new_vport - Register a new vport with a HBA
6938 * @phba: pointer to lpfc hba data structure.
6939 * @vport: pointer to a host virtual N_Port data structure.
6940 * @ndlp: pointer to a node-list data structure.
6942 * This routine registers the @vport as a new virtual port with a HBA.
6943 * It is done through a registering vpi mailbox command.
6946 lpfc_register_new_vport(struct lpfc_hba
*phba
, struct lpfc_vport
*vport
,
6947 struct lpfc_nodelist
*ndlp
)
6949 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
6952 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
6954 lpfc_reg_vpi(vport
, mbox
);
6955 mbox
->vport
= vport
;
6956 mbox
->context2
= lpfc_nlp_get(ndlp
);
6957 mbox
->mbox_cmpl
= lpfc_cmpl_reg_new_vport
;
6958 if (lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
)
6959 == MBX_NOT_FINISHED
) {
6960 /* mailbox command not success, decrement ndlp
6961 * reference count for this command
6964 mempool_free(mbox
, phba
->mbox_mem_pool
);
6966 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
6967 "0253 Register VPI: Can't send mbox\n");
6971 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
6972 "0254 Register VPI: no memory\n");
6978 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
6979 spin_lock_irq(shost
->host_lock
);
6980 vport
->fc_flag
&= ~FC_VPORT_NEEDS_REG_VPI
;
6981 spin_unlock_irq(shost
->host_lock
);
6986 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
6987 * @phba: pointer to lpfc hba data structure.
6989 * This routine cancels the retry delay timers to all the vports.
6992 lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba
*phba
)
6994 struct lpfc_vport
**vports
;
6995 struct lpfc_nodelist
*ndlp
;
6996 uint32_t link_state
;
6999 /* Treat this failure as linkdown for all vports */
7000 link_state
= phba
->link_state
;
7001 lpfc_linkdown(phba
);
7002 phba
->link_state
= link_state
;
7004 vports
= lpfc_create_vport_work_array(phba
);
7007 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
7008 ndlp
= lpfc_findnode_did(vports
[i
], Fabric_DID
);
7010 lpfc_cancel_retry_delay_tmo(vports
[i
], ndlp
);
7011 lpfc_els_flush_cmd(vports
[i
]);
7013 lpfc_destroy_vport_work_array(phba
, vports
);
7018 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
7019 * @phba: pointer to lpfc hba data structure.
7021 * This routine abort all pending discovery commands and
7022 * start a timer to retry FLOGI for the physical port
7026 lpfc_retry_pport_discovery(struct lpfc_hba
*phba
)
7028 struct lpfc_nodelist
*ndlp
;
7029 struct Scsi_Host
*shost
;
7031 /* Cancel the all vports retry delay retry timers */
7032 lpfc_cancel_all_vport_retry_delay_timer(phba
);
7034 /* If fabric require FLOGI, then re-instantiate physical login */
7035 ndlp
= lpfc_findnode_did(phba
->pport
, Fabric_DID
);
7039 shost
= lpfc_shost_from_vport(phba
->pport
);
7040 mod_timer(&ndlp
->nlp_delayfunc
, jiffies
+ HZ
);
7041 spin_lock_irq(shost
->host_lock
);
7042 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
7043 spin_unlock_irq(shost
->host_lock
);
7044 ndlp
->nlp_last_elscmd
= ELS_CMD_FLOGI
;
7045 phba
->pport
->port_state
= LPFC_FLOGI
;
7050 * lpfc_fabric_login_reqd - Check if FLOGI required.
7051 * @phba: pointer to lpfc hba data structure.
7052 * @cmdiocb: pointer to FDISC command iocb.
7053 * @rspiocb: pointer to FDISC response iocb.
7055 * This routine checks if a FLOGI is reguired for FDISC
7059 lpfc_fabric_login_reqd(struct lpfc_hba
*phba
,
7060 struct lpfc_iocbq
*cmdiocb
,
7061 struct lpfc_iocbq
*rspiocb
)
7064 if ((rspiocb
->iocb
.ulpStatus
!= IOSTAT_FABRIC_RJT
) ||
7065 (rspiocb
->iocb
.un
.ulpWord
[4] != RJT_LOGIN_REQUIRED
))
7072 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
7073 * @phba: pointer to lpfc hba data structure.
7074 * @cmdiocb: pointer to lpfc command iocb data structure.
7075 * @rspiocb: pointer to lpfc response iocb data structure.
7077 * This routine is the completion callback function to a Fabric Discover
7078 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
7079 * single threaded, each FDISC completion callback function will reset
7080 * the discovery timer for all vports such that the timers will not get
7081 * unnecessary timeout. The function checks the FDISC IOCB status. If error
7082 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
7083 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
7084 * assigned to the vport has been changed with the completion of the FDISC
7085 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
7086 * are unregistered from the HBA, and then the lpfc_register_new_vport()
7087 * routine is invoked to register new vport with the HBA. Otherwise, the
7088 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
7089 * Server for State Change Request (SCR).
7092 lpfc_cmpl_els_fdisc(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
7093 struct lpfc_iocbq
*rspiocb
)
7095 struct lpfc_vport
*vport
= cmdiocb
->vport
;
7096 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
7097 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
7098 struct lpfc_nodelist
*np
;
7099 struct lpfc_nodelist
*next_np
;
7100 IOCB_t
*irsp
= &rspiocb
->iocb
;
7101 struct lpfc_iocbq
*piocb
;
7102 struct lpfc_dmabuf
*pcmd
= cmdiocb
->context2
, *prsp
;
7103 struct serv_parm
*sp
;
7104 uint8_t fabric_param_changed
;
7106 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
7107 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
7108 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
7110 /* Since all FDISCs are being single threaded, we
7111 * must reset the discovery timer for ALL vports
7112 * waiting to send FDISC when one completes.
7114 list_for_each_entry(piocb
, &phba
->fabric_iocb_list
, list
) {
7115 lpfc_set_disctmo(piocb
->vport
);
7118 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
7119 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
7120 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4], vport
->fc_prevDID
);
7122 if (irsp
->ulpStatus
) {
7124 if (lpfc_fabric_login_reqd(phba
, cmdiocb
, rspiocb
)) {
7125 lpfc_retry_pport_discovery(phba
);
7129 /* Check for retry */
7130 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
))
7133 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
7134 "0126 FDISC failed. (%d/%d)\n",
7135 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4]);
7138 spin_lock_irq(shost
->host_lock
);
7139 vport
->fc_flag
&= ~FC_VPORT_CVL_RCVD
;
7140 vport
->fc_flag
&= ~FC_VPORT_LOGO_RCVD
;
7141 vport
->fc_flag
|= FC_FABRIC
;
7142 if (vport
->phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
)
7143 vport
->fc_flag
|= FC_PUBLIC_LOOP
;
7144 spin_unlock_irq(shost
->host_lock
);
7146 vport
->fc_myDID
= irsp
->un
.ulpWord
[4] & Mask_DID
;
7147 lpfc_vport_set_state(vport
, FC_VPORT_ACTIVE
);
7148 prsp
= list_get_first(&pcmd
->list
, struct lpfc_dmabuf
, list
);
7149 sp
= prsp
->virt
+ sizeof(uint32_t);
7150 fabric_param_changed
= lpfc_check_clean_addr_bit(vport
, sp
);
7151 memcpy(&vport
->fabric_portname
, &sp
->portName
,
7152 sizeof(struct lpfc_name
));
7153 memcpy(&vport
->fabric_nodename
, &sp
->nodeName
,
7154 sizeof(struct lpfc_name
));
7155 if (fabric_param_changed
&&
7156 !(vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
)) {
7157 /* If our NportID changed, we need to ensure all
7158 * remaining NPORTs get unreg_login'ed so we can
7161 list_for_each_entry_safe(np
, next_np
,
7162 &vport
->fc_nodes
, nlp_listp
) {
7163 if (!NLP_CHK_NODE_ACT(ndlp
) ||
7164 (np
->nlp_state
!= NLP_STE_NPR_NODE
) ||
7165 !(np
->nlp_flag
& NLP_NPR_ADISC
))
7167 spin_lock_irq(shost
->host_lock
);
7168 np
->nlp_flag
&= ~NLP_NPR_ADISC
;
7169 spin_unlock_irq(shost
->host_lock
);
7170 lpfc_unreg_rpi(vport
, np
);
7172 lpfc_cleanup_pending_mbox(vport
);
7174 if (phba
->sli_rev
== LPFC_SLI_REV4
)
7175 lpfc_sli4_unreg_all_rpis(vport
);
7177 lpfc_mbx_unreg_vpi(vport
);
7178 spin_lock_irq(shost
->host_lock
);
7179 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
7180 if (phba
->sli_rev
== LPFC_SLI_REV4
)
7181 vport
->fc_flag
|= FC_VPORT_NEEDS_INIT_VPI
;
7183 vport
->fc_flag
|= FC_LOGO_RCVD_DID_CHNG
;
7184 spin_unlock_irq(shost
->host_lock
);
7185 } else if ((phba
->sli_rev
== LPFC_SLI_REV4
) &&
7186 !(vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
)) {
7188 * Driver needs to re-reg VPI in order for f/w
7189 * to update the MAC address.
7191 lpfc_register_new_vport(phba
, vport
, ndlp
);
7195 if (vport
->fc_flag
& FC_VPORT_NEEDS_INIT_VPI
)
7196 lpfc_issue_init_vpi(vport
);
7197 else if (vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
)
7198 lpfc_register_new_vport(phba
, vport
, ndlp
);
7200 lpfc_do_scr_ns_plogi(phba
, vport
);
7203 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
7204 /* Cancel discovery timer */
7205 lpfc_can_disctmo(vport
);
7208 lpfc_els_free_iocb(phba
, cmdiocb
);
7212 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
7213 * @vport: pointer to a virtual N_Port data structure.
7214 * @ndlp: pointer to a node-list data structure.
7215 * @retry: number of retries to the command IOCB.
7217 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
7218 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
7219 * routine to issue the IOCB, which makes sure only one outstanding fabric
7220 * IOCB will be sent off HBA at any given time.
7222 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7223 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7224 * will be stored into the context1 field of the IOCB for the completion
7225 * callback function to the FDISC ELS command.
7228 * 0 - Successfully issued fdisc iocb command
7229 * 1 - Failed to issue fdisc iocb command
7232 lpfc_issue_els_fdisc(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
7235 struct lpfc_hba
*phba
= vport
->phba
;
7237 struct lpfc_iocbq
*elsiocb
;
7238 struct serv_parm
*sp
;
7241 int did
= ndlp
->nlp_DID
;
7244 vport
->port_state
= LPFC_FDISC
;
7245 cmdsize
= (sizeof(uint32_t) + sizeof(struct serv_parm
));
7246 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
, did
,
7249 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
7250 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
7251 "0255 Issue FDISC: no IOCB\n");
7255 icmd
= &elsiocb
->iocb
;
7256 icmd
->un
.elsreq64
.myID
= 0;
7257 icmd
->un
.elsreq64
.fl
= 1;
7259 if ((phba
->sli_rev
== LPFC_SLI_REV4
) &&
7260 (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) ==
7261 LPFC_SLI_INTF_IF_TYPE_0
)) {
7262 /* FDISC needs to be 1 for WQE VPI */
7263 elsiocb
->iocb
.ulpCt_h
= (SLI4_CT_VPI
>> 1) & 1;
7264 elsiocb
->iocb
.ulpCt_l
= SLI4_CT_VPI
& 1 ;
7265 /* Set the ulpContext to the vpi */
7266 elsiocb
->iocb
.ulpContext
= phba
->vpi_ids
[vport
->vpi
];
7268 /* For FDISC, Let FDISC rsp set the NPortID for this VPI */
7273 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
7274 *((uint32_t *) (pcmd
)) = ELS_CMD_FDISC
;
7275 pcmd
+= sizeof(uint32_t); /* CSP Word 1 */
7276 memcpy(pcmd
, &vport
->phba
->pport
->fc_sparam
, sizeof(struct serv_parm
));
7277 sp
= (struct serv_parm
*) pcmd
;
7278 /* Setup CSPs accordingly for Fabric */
7279 sp
->cmn
.e_d_tov
= 0;
7280 sp
->cmn
.w2
.r_a_tov
= 0;
7281 sp
->cls1
.classValid
= 0;
7282 sp
->cls2
.seqDelivery
= 1;
7283 sp
->cls3
.seqDelivery
= 1;
7285 pcmd
+= sizeof(uint32_t); /* CSP Word 2 */
7286 pcmd
+= sizeof(uint32_t); /* CSP Word 3 */
7287 pcmd
+= sizeof(uint32_t); /* CSP Word 4 */
7288 pcmd
+= sizeof(uint32_t); /* Port Name */
7289 memcpy(pcmd
, &vport
->fc_portname
, 8);
7290 pcmd
+= sizeof(uint32_t); /* Node Name */
7291 pcmd
+= sizeof(uint32_t); /* Node Name */
7292 memcpy(pcmd
, &vport
->fc_nodename
, 8);
7294 lpfc_set_disctmo(vport
);
7296 phba
->fc_stat
.elsXmitFDISC
++;
7297 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_fdisc
;
7299 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
7300 "Issue FDISC: did:x%x",
7303 rc
= lpfc_issue_fabric_iocb(phba
, elsiocb
);
7304 if (rc
== IOCB_ERROR
) {
7305 lpfc_els_free_iocb(phba
, elsiocb
);
7306 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
7307 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
7308 "0256 Issue FDISC: Cannot send IOCB\n");
7311 lpfc_vport_set_state(vport
, FC_VPORT_INITIALIZING
);
7316 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
7317 * @phba: pointer to lpfc hba data structure.
7318 * @cmdiocb: pointer to lpfc command iocb data structure.
7319 * @rspiocb: pointer to lpfc response iocb data structure.
7321 * This routine is the completion callback function to the issuing of a LOGO
7322 * ELS command off a vport. It frees the command IOCB and then decrement the
7323 * reference count held on ndlp for this completion function, indicating that
7324 * the reference to the ndlp is no long needed. Note that the
7325 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
7326 * callback function and an additional explicit ndlp reference decrementation
7327 * will trigger the actual release of the ndlp.
7330 lpfc_cmpl_els_npiv_logo(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
7331 struct lpfc_iocbq
*rspiocb
)
7333 struct lpfc_vport
*vport
= cmdiocb
->vport
;
7335 struct lpfc_nodelist
*ndlp
;
7336 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
7338 ndlp
= (struct lpfc_nodelist
*)cmdiocb
->context1
;
7339 irsp
= &rspiocb
->iocb
;
7340 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
7341 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
7342 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4], irsp
->un
.rcvels
.remoteID
);
7344 lpfc_els_free_iocb(phba
, cmdiocb
);
7345 vport
->unreg_vpi_cmpl
= VPORT_ERROR
;
7347 /* Trigger the release of the ndlp after logo */
7350 /* NPIV LOGO completes to NPort <nlp_DID> */
7351 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
7352 "2928 NPIV LOGO completes to NPort x%x "
7353 "Data: x%x x%x x%x x%x\n",
7354 ndlp
->nlp_DID
, irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
7355 irsp
->ulpTimeout
, vport
->num_disc_nodes
);
7357 if (irsp
->ulpStatus
== IOSTAT_SUCCESS
) {
7358 spin_lock_irq(shost
->host_lock
);
7359 vport
->fc_flag
&= ~FC_FABRIC
;
7360 spin_unlock_irq(shost
->host_lock
);
7365 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
7366 * @vport: pointer to a virtual N_Port data structure.
7367 * @ndlp: pointer to a node-list data structure.
7369 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
7371 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7372 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7373 * will be stored into the context1 field of the IOCB for the completion
7374 * callback function to the LOGO ELS command.
7377 * 0 - Successfully issued logo off the @vport
7378 * 1 - Failed to issue logo off the @vport
7381 lpfc_issue_els_npiv_logo(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
7383 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
7384 struct lpfc_hba
*phba
= vport
->phba
;
7386 struct lpfc_iocbq
*elsiocb
;
7390 cmdsize
= 2 * sizeof(uint32_t) + sizeof(struct lpfc_name
);
7391 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, 0, ndlp
, ndlp
->nlp_DID
,
7396 icmd
= &elsiocb
->iocb
;
7397 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
7398 *((uint32_t *) (pcmd
)) = ELS_CMD_LOGO
;
7399 pcmd
+= sizeof(uint32_t);
7401 /* Fill in LOGO payload */
7402 *((uint32_t *) (pcmd
)) = be32_to_cpu(vport
->fc_myDID
);
7403 pcmd
+= sizeof(uint32_t);
7404 memcpy(pcmd
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
7406 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
7407 "Issue LOGO npiv did:x%x flg:x%x",
7408 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
7410 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_npiv_logo
;
7411 spin_lock_irq(shost
->host_lock
);
7412 ndlp
->nlp_flag
|= NLP_LOGO_SND
;
7413 spin_unlock_irq(shost
->host_lock
);
7414 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) ==
7416 spin_lock_irq(shost
->host_lock
);
7417 ndlp
->nlp_flag
&= ~NLP_LOGO_SND
;
7418 spin_unlock_irq(shost
->host_lock
);
7419 lpfc_els_free_iocb(phba
, elsiocb
);
7426 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
7427 * @ptr: holder for the timer function associated data.
7429 * This routine is invoked by the fabric iocb block timer after
7430 * timeout. It posts the fabric iocb block timeout event by setting the
7431 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
7432 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
7433 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
7434 * posted event WORKER_FABRIC_BLOCK_TMO.
7437 lpfc_fabric_block_timeout(unsigned long ptr
)
7439 struct lpfc_hba
*phba
= (struct lpfc_hba
*) ptr
;
7440 unsigned long iflags
;
7441 uint32_t tmo_posted
;
7443 spin_lock_irqsave(&phba
->pport
->work_port_lock
, iflags
);
7444 tmo_posted
= phba
->pport
->work_port_events
& WORKER_FABRIC_BLOCK_TMO
;
7446 phba
->pport
->work_port_events
|= WORKER_FABRIC_BLOCK_TMO
;
7447 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, iflags
);
7450 lpfc_worker_wake_up(phba
);
7455 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
7456 * @phba: pointer to lpfc hba data structure.
7458 * This routine issues one fabric iocb from the driver internal list to
7459 * the HBA. It first checks whether it's ready to issue one fabric iocb to
7460 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
7461 * remove one pending fabric iocb from the driver internal list and invokes
7462 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
7465 lpfc_resume_fabric_iocbs(struct lpfc_hba
*phba
)
7467 struct lpfc_iocbq
*iocb
;
7468 unsigned long iflags
;
7474 spin_lock_irqsave(&phba
->hbalock
, iflags
);
7475 /* Post any pending iocb to the SLI layer */
7476 if (atomic_read(&phba
->fabric_iocb_count
) == 0) {
7477 list_remove_head(&phba
->fabric_iocb_list
, iocb
, typeof(*iocb
),
7480 /* Increment fabric iocb count to hold the position */
7481 atomic_inc(&phba
->fabric_iocb_count
);
7483 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7485 iocb
->fabric_iocb_cmpl
= iocb
->iocb_cmpl
;
7486 iocb
->iocb_cmpl
= lpfc_cmpl_fabric_iocb
;
7487 iocb
->iocb_flag
|= LPFC_IO_FABRIC
;
7489 lpfc_debugfs_disc_trc(iocb
->vport
, LPFC_DISC_TRC_ELS_CMD
,
7490 "Fabric sched1: ste:x%x",
7491 iocb
->vport
->port_state
, 0, 0);
7493 ret
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, iocb
, 0);
7495 if (ret
== IOCB_ERROR
) {
7496 iocb
->iocb_cmpl
= iocb
->fabric_iocb_cmpl
;
7497 iocb
->fabric_iocb_cmpl
= NULL
;
7498 iocb
->iocb_flag
&= ~LPFC_IO_FABRIC
;
7500 cmd
->ulpStatus
= IOSTAT_LOCAL_REJECT
;
7501 cmd
->un
.ulpWord
[4] = IOERR_SLI_ABORTED
;
7502 iocb
->iocb_cmpl(phba
, iocb
, iocb
);
7504 atomic_dec(&phba
->fabric_iocb_count
);
7513 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
7514 * @phba: pointer to lpfc hba data structure.
7516 * This routine unblocks the issuing fabric iocb command. The function
7517 * will clear the fabric iocb block bit and then invoke the routine
7518 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
7519 * from the driver internal fabric iocb list.
7522 lpfc_unblock_fabric_iocbs(struct lpfc_hba
*phba
)
7524 clear_bit(FABRIC_COMANDS_BLOCKED
, &phba
->bit_flags
);
7526 lpfc_resume_fabric_iocbs(phba
);
7531 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
7532 * @phba: pointer to lpfc hba data structure.
7534 * This routine blocks the issuing fabric iocb for a specified amount of
7535 * time (currently 100 ms). This is done by set the fabric iocb block bit
7536 * and set up a timeout timer for 100ms. When the block bit is set, no more
7537 * fabric iocb will be issued out of the HBA.
7540 lpfc_block_fabric_iocbs(struct lpfc_hba
*phba
)
7544 blocked
= test_and_set_bit(FABRIC_COMANDS_BLOCKED
, &phba
->bit_flags
);
7545 /* Start a timer to unblock fabric iocbs after 100ms */
7547 mod_timer(&phba
->fabric_block_timer
, jiffies
+ HZ
/10 );
7553 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
7554 * @phba: pointer to lpfc hba data structure.
7555 * @cmdiocb: pointer to lpfc command iocb data structure.
7556 * @rspiocb: pointer to lpfc response iocb data structure.
7558 * This routine is the callback function that is put to the fabric iocb's
7559 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
7560 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
7561 * function first restores and invokes the original iocb's callback function
7562 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
7563 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
7566 lpfc_cmpl_fabric_iocb(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
7567 struct lpfc_iocbq
*rspiocb
)
7571 if ((cmdiocb
->iocb_flag
& LPFC_IO_FABRIC
) != LPFC_IO_FABRIC
)
7574 switch (rspiocb
->iocb
.ulpStatus
) {
7575 case IOSTAT_NPORT_RJT
:
7576 case IOSTAT_FABRIC_RJT
:
7577 if (rspiocb
->iocb
.un
.ulpWord
[4] & RJT_UNAVAIL_TEMP
) {
7578 lpfc_block_fabric_iocbs(phba
);
7582 case IOSTAT_NPORT_BSY
:
7583 case IOSTAT_FABRIC_BSY
:
7584 lpfc_block_fabric_iocbs(phba
);
7588 stat
.un
.lsRjtError
=
7589 be32_to_cpu(rspiocb
->iocb
.un
.ulpWord
[4]);
7590 if ((stat
.un
.b
.lsRjtRsnCode
== LSRJT_UNABLE_TPC
) ||
7591 (stat
.un
.b
.lsRjtRsnCode
== LSRJT_LOGICAL_BSY
))
7592 lpfc_block_fabric_iocbs(phba
);
7596 if (atomic_read(&phba
->fabric_iocb_count
) == 0)
7599 cmdiocb
->iocb_cmpl
= cmdiocb
->fabric_iocb_cmpl
;
7600 cmdiocb
->fabric_iocb_cmpl
= NULL
;
7601 cmdiocb
->iocb_flag
&= ~LPFC_IO_FABRIC
;
7602 cmdiocb
->iocb_cmpl(phba
, cmdiocb
, rspiocb
);
7604 atomic_dec(&phba
->fabric_iocb_count
);
7605 if (!test_bit(FABRIC_COMANDS_BLOCKED
, &phba
->bit_flags
)) {
7606 /* Post any pending iocbs to HBA */
7607 lpfc_resume_fabric_iocbs(phba
);
7612 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
7613 * @phba: pointer to lpfc hba data structure.
7614 * @iocb: pointer to lpfc command iocb data structure.
7616 * This routine is used as the top-level API for issuing a fabric iocb command
7617 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
7618 * function makes sure that only one fabric bound iocb will be outstanding at
7619 * any given time. As such, this function will first check to see whether there
7620 * is already an outstanding fabric iocb on the wire. If so, it will put the
7621 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
7622 * issued later. Otherwise, it will issue the iocb on the wire and update the
7623 * fabric iocb count it indicate that there is one fabric iocb on the wire.
7625 * Note, this implementation has a potential sending out fabric IOCBs out of
7626 * order. The problem is caused by the construction of the "ready" boolen does
7627 * not include the condition that the internal fabric IOCB list is empty. As
7628 * such, it is possible a fabric IOCB issued by this routine might be "jump"
7629 * ahead of the fabric IOCBs in the internal list.
7632 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
7633 * IOCB_ERROR - failed to issue fabric iocb
7636 lpfc_issue_fabric_iocb(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocb
)
7638 unsigned long iflags
;
7642 if (atomic_read(&phba
->fabric_iocb_count
) > 1)
7645 spin_lock_irqsave(&phba
->hbalock
, iflags
);
7646 ready
= atomic_read(&phba
->fabric_iocb_count
) == 0 &&
7647 !test_bit(FABRIC_COMANDS_BLOCKED
, &phba
->bit_flags
);
7650 /* Increment fabric iocb count to hold the position */
7651 atomic_inc(&phba
->fabric_iocb_count
);
7652 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7654 iocb
->fabric_iocb_cmpl
= iocb
->iocb_cmpl
;
7655 iocb
->iocb_cmpl
= lpfc_cmpl_fabric_iocb
;
7656 iocb
->iocb_flag
|= LPFC_IO_FABRIC
;
7658 lpfc_debugfs_disc_trc(iocb
->vport
, LPFC_DISC_TRC_ELS_CMD
,
7659 "Fabric sched2: ste:x%x",
7660 iocb
->vport
->port_state
, 0, 0);
7662 ret
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, iocb
, 0);
7664 if (ret
== IOCB_ERROR
) {
7665 iocb
->iocb_cmpl
= iocb
->fabric_iocb_cmpl
;
7666 iocb
->fabric_iocb_cmpl
= NULL
;
7667 iocb
->iocb_flag
&= ~LPFC_IO_FABRIC
;
7668 atomic_dec(&phba
->fabric_iocb_count
);
7671 spin_lock_irqsave(&phba
->hbalock
, iflags
);
7672 list_add_tail(&iocb
->list
, &phba
->fabric_iocb_list
);
7673 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7680 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
7681 * @vport: pointer to a virtual N_Port data structure.
7683 * This routine aborts all the IOCBs associated with a @vport from the
7684 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
7685 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
7686 * list, removes each IOCB associated with the @vport off the list, set the
7687 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
7688 * associated with the IOCB.
7690 static void lpfc_fabric_abort_vport(struct lpfc_vport
*vport
)
7692 LIST_HEAD(completions
);
7693 struct lpfc_hba
*phba
= vport
->phba
;
7694 struct lpfc_iocbq
*tmp_iocb
, *piocb
;
7696 spin_lock_irq(&phba
->hbalock
);
7697 list_for_each_entry_safe(piocb
, tmp_iocb
, &phba
->fabric_iocb_list
,
7700 if (piocb
->vport
!= vport
)
7703 list_move_tail(&piocb
->list
, &completions
);
7705 spin_unlock_irq(&phba
->hbalock
);
7707 /* Cancel all the IOCBs from the completions list */
7708 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
7713 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
7714 * @ndlp: pointer to a node-list data structure.
7716 * This routine aborts all the IOCBs associated with an @ndlp from the
7717 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
7718 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
7719 * list, removes each IOCB associated with the @ndlp off the list, set the
7720 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
7721 * associated with the IOCB.
7723 void lpfc_fabric_abort_nport(struct lpfc_nodelist
*ndlp
)
7725 LIST_HEAD(completions
);
7726 struct lpfc_hba
*phba
= ndlp
->phba
;
7727 struct lpfc_iocbq
*tmp_iocb
, *piocb
;
7728 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
7730 spin_lock_irq(&phba
->hbalock
);
7731 list_for_each_entry_safe(piocb
, tmp_iocb
, &phba
->fabric_iocb_list
,
7733 if ((lpfc_check_sli_ndlp(phba
, pring
, piocb
, ndlp
))) {
7735 list_move_tail(&piocb
->list
, &completions
);
7738 spin_unlock_irq(&phba
->hbalock
);
7740 /* Cancel all the IOCBs from the completions list */
7741 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
7746 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
7747 * @phba: pointer to lpfc hba data structure.
7749 * This routine aborts all the IOCBs currently on the driver internal
7750 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
7751 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
7752 * list, removes IOCBs off the list, set the status feild to
7753 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
7756 void lpfc_fabric_abort_hba(struct lpfc_hba
*phba
)
7758 LIST_HEAD(completions
);
7760 spin_lock_irq(&phba
->hbalock
);
7761 list_splice_init(&phba
->fabric_iocb_list
, &completions
);
7762 spin_unlock_irq(&phba
->hbalock
);
7764 /* Cancel all the IOCBs from the completions list */
7765 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
7770 * lpfc_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport
7771 * @vport: pointer to lpfc vport data structure.
7773 * This routine is invoked by the vport cleanup for deletions and the cleanup
7774 * for an ndlp on removal.
7777 lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport
*vport
)
7779 struct lpfc_hba
*phba
= vport
->phba
;
7780 struct lpfc_sglq
*sglq_entry
= NULL
, *sglq_next
= NULL
;
7781 unsigned long iflag
= 0;
7783 spin_lock_irqsave(&phba
->hbalock
, iflag
);
7784 spin_lock(&phba
->sli4_hba
.abts_sgl_list_lock
);
7785 list_for_each_entry_safe(sglq_entry
, sglq_next
,
7786 &phba
->sli4_hba
.lpfc_abts_els_sgl_list
, list
) {
7787 if (sglq_entry
->ndlp
&& sglq_entry
->ndlp
->vport
== vport
)
7788 sglq_entry
->ndlp
= NULL
;
7790 spin_unlock(&phba
->sli4_hba
.abts_sgl_list_lock
);
7791 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
7796 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
7797 * @phba: pointer to lpfc hba data structure.
7798 * @axri: pointer to the els xri abort wcqe structure.
7800 * This routine is invoked by the worker thread to process a SLI4 slow-path
7804 lpfc_sli4_els_xri_aborted(struct lpfc_hba
*phba
,
7805 struct sli4_wcqe_xri_aborted
*axri
)
7807 uint16_t xri
= bf_get(lpfc_wcqe_xa_xri
, axri
);
7808 uint16_t rxid
= bf_get(lpfc_wcqe_xa_remote_xid
, axri
);
7811 struct lpfc_sglq
*sglq_entry
= NULL
, *sglq_next
= NULL
;
7812 unsigned long iflag
= 0;
7813 struct lpfc_nodelist
*ndlp
;
7814 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
7816 spin_lock_irqsave(&phba
->hbalock
, iflag
);
7817 spin_lock(&phba
->sli4_hba
.abts_sgl_list_lock
);
7818 list_for_each_entry_safe(sglq_entry
, sglq_next
,
7819 &phba
->sli4_hba
.lpfc_abts_els_sgl_list
, list
) {
7820 if (sglq_entry
->sli4_xritag
== xri
) {
7821 list_del(&sglq_entry
->list
);
7822 ndlp
= sglq_entry
->ndlp
;
7823 sglq_entry
->ndlp
= NULL
;
7824 list_add_tail(&sglq_entry
->list
,
7825 &phba
->sli4_hba
.lpfc_sgl_list
);
7826 sglq_entry
->state
= SGL_FREED
;
7827 spin_unlock(&phba
->sli4_hba
.abts_sgl_list_lock
);
7828 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
7829 lpfc_set_rrq_active(phba
, ndlp
, xri
, rxid
, 1);
7831 /* Check if TXQ queue needs to be serviced */
7833 lpfc_worker_wake_up(phba
);
7837 spin_unlock(&phba
->sli4_hba
.abts_sgl_list_lock
);
7838 lxri
= lpfc_sli4_xri_inrange(phba
, xri
);
7839 if (lxri
== NO_XRI
) {
7840 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
7843 sglq_entry
= __lpfc_get_active_sglq(phba
, lxri
);
7844 if (!sglq_entry
|| (sglq_entry
->sli4_xritag
!= xri
)) {
7845 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
7848 sglq_entry
->state
= SGL_XRI_ABORTED
;
7849 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);