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 imediately 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
= vport
->vpi
+ phba
->vpi_base
;
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
;
457 mboxq
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
460 goto fail_free_coherent
;
462 vport
->port_state
= LPFC_FABRIC_CFG_LINK
;
463 memcpy(dmabuf
->virt
, &phba
->fc_fabparam
, sizeof(vport
->fc_sparam
));
464 lpfc_reg_vfi(mboxq
, vport
, dmabuf
->phys
);
465 mboxq
->mbox_cmpl
= lpfc_mbx_cmpl_reg_vfi
;
466 mboxq
->vport
= vport
;
467 mboxq
->context1
= dmabuf
;
468 rc
= lpfc_sli_issue_mbox(phba
, mboxq
, MBX_NOWAIT
);
469 if (rc
== MBX_NOT_FINISHED
) {
476 mempool_free(mboxq
, phba
->mbox_mem_pool
);
478 lpfc_mbuf_free(phba
, dmabuf
->virt
, dmabuf
->phys
);
482 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
483 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
484 "0289 Issue Register VFI failed: Err %d\n", rc
);
489 * lpfc_check_clean_addr_bit - Check whether assigned FCID is clean.
490 * @vport: pointer to a host virtual N_Port data structure.
491 * @sp: pointer to service parameter data structure.
493 * This routine is called from FLOGI/FDISC completion handler functions.
494 * lpfc_check_clean_addr_bit return 1 when FCID/Fabric portname/ Fabric
495 * node nodename is changed in the completion service parameter else return
496 * 0. This function also set flag in the vport data structure to delay
497 * NP_Port discovery after the FLOGI/FDISC completion if Clean address bit
498 * in FLOGI/FDISC response is cleared and FCID/Fabric portname/ Fabric
499 * node nodename is changed in the completion service parameter.
502 * 0 - FCID and Fabric Nodename and Fabric portname is not changed.
503 * 1 - FCID or Fabric Nodename or Fabric portname is changed.
507 lpfc_check_clean_addr_bit(struct lpfc_vport
*vport
,
508 struct serv_parm
*sp
)
510 uint8_t fabric_param_changed
= 0;
511 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
513 if ((vport
->fc_prevDID
!= vport
->fc_myDID
) ||
514 memcmp(&vport
->fabric_portname
, &sp
->portName
,
515 sizeof(struct lpfc_name
)) ||
516 memcmp(&vport
->fabric_nodename
, &sp
->nodeName
,
517 sizeof(struct lpfc_name
)))
518 fabric_param_changed
= 1;
521 * Word 1 Bit 31 in common service parameter is overloaded.
522 * Word 1 Bit 31 in FLOGI request is multiple NPort request
523 * Word 1 Bit 31 in FLOGI response is clean address bit
525 * If fabric parameter is changed and clean address bit is
526 * cleared delay nport discovery if
527 * - vport->fc_prevDID != 0 (not initial discovery) OR
528 * - lpfc_delay_discovery module parameter is set.
530 if (fabric_param_changed
&& !sp
->cmn
.clean_address_bit
&&
531 (vport
->fc_prevDID
|| lpfc_delay_discovery
)) {
532 spin_lock_irq(shost
->host_lock
);
533 vport
->fc_flag
|= FC_DISC_DELAYED
;
534 spin_unlock_irq(shost
->host_lock
);
537 return fabric_param_changed
;
542 * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port
543 * @vport: pointer to a host virtual N_Port data structure.
544 * @ndlp: pointer to a node-list data structure.
545 * @sp: pointer to service parameter data structure.
546 * @irsp: pointer to the IOCB within the lpfc response IOCB.
548 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
549 * function to handle the completion of a Fabric Login (FLOGI) into a fabric
550 * port in a fabric topology. It properly sets up the parameters to the @ndlp
551 * from the IOCB response. It also check the newly assigned N_Port ID to the
552 * @vport against the previously assigned N_Port ID. If it is different from
553 * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
554 * is invoked on all the remaining nodes with the @vport to unregister the
555 * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
556 * is invoked to register login to the fabric.
559 * 0 - Success (currently, always return 0)
562 lpfc_cmpl_els_flogi_fabric(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
563 struct serv_parm
*sp
, IOCB_t
*irsp
)
565 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
566 struct lpfc_hba
*phba
= vport
->phba
;
567 struct lpfc_nodelist
*np
;
568 struct lpfc_nodelist
*next_np
;
569 uint8_t fabric_param_changed
;
571 spin_lock_irq(shost
->host_lock
);
572 vport
->fc_flag
|= FC_FABRIC
;
573 spin_unlock_irq(shost
->host_lock
);
575 phba
->fc_edtov
= be32_to_cpu(sp
->cmn
.e_d_tov
);
576 if (sp
->cmn
.edtovResolution
) /* E_D_TOV ticks are in nanoseconds */
577 phba
->fc_edtov
= (phba
->fc_edtov
+ 999999) / 1000000;
579 phba
->fc_edtovResol
= sp
->cmn
.edtovResolution
;
580 phba
->fc_ratov
= (be32_to_cpu(sp
->cmn
.w2
.r_a_tov
) + 999) / 1000;
582 if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) {
583 spin_lock_irq(shost
->host_lock
);
584 vport
->fc_flag
|= FC_PUBLIC_LOOP
;
585 spin_unlock_irq(shost
->host_lock
);
588 vport
->fc_myDID
= irsp
->un
.ulpWord
[4] & Mask_DID
;
589 memcpy(&ndlp
->nlp_portname
, &sp
->portName
, sizeof(struct lpfc_name
));
590 memcpy(&ndlp
->nlp_nodename
, &sp
->nodeName
, sizeof(struct lpfc_name
));
591 ndlp
->nlp_class_sup
= 0;
592 if (sp
->cls1
.classValid
)
593 ndlp
->nlp_class_sup
|= FC_COS_CLASS1
;
594 if (sp
->cls2
.classValid
)
595 ndlp
->nlp_class_sup
|= FC_COS_CLASS2
;
596 if (sp
->cls3
.classValid
)
597 ndlp
->nlp_class_sup
|= FC_COS_CLASS3
;
598 if (sp
->cls4
.classValid
)
599 ndlp
->nlp_class_sup
|= FC_COS_CLASS4
;
600 ndlp
->nlp_maxframe
= ((sp
->cmn
.bbRcvSizeMsb
& 0x0F) << 8) |
601 sp
->cmn
.bbRcvSizeLsb
;
603 fabric_param_changed
= lpfc_check_clean_addr_bit(vport
, sp
);
604 memcpy(&vport
->fabric_portname
, &sp
->portName
,
605 sizeof(struct lpfc_name
));
606 memcpy(&vport
->fabric_nodename
, &sp
->nodeName
,
607 sizeof(struct lpfc_name
));
608 memcpy(&phba
->fc_fabparam
, sp
, sizeof(struct serv_parm
));
610 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) {
611 if (sp
->cmn
.response_multiple_NPort
) {
612 lpfc_printf_vlog(vport
, KERN_WARNING
,
614 "1816 FLOGI NPIV supported, "
615 "response data 0x%x\n",
616 sp
->cmn
.response_multiple_NPort
);
617 phba
->link_flag
|= LS_NPIV_FAB_SUPPORTED
;
619 /* Because we asked f/w for NPIV it still expects us
620 to call reg_vnpid atleast for the physcial host */
621 lpfc_printf_vlog(vport
, KERN_WARNING
,
623 "1817 Fabric does not support NPIV "
624 "- configuring single port mode.\n");
625 phba
->link_flag
&= ~LS_NPIV_FAB_SUPPORTED
;
629 if (fabric_param_changed
&&
630 !(vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
)) {
632 /* If our NportID changed, we need to ensure all
633 * remaining NPORTs get unreg_login'ed.
635 list_for_each_entry_safe(np
, next_np
,
636 &vport
->fc_nodes
, nlp_listp
) {
637 if (!NLP_CHK_NODE_ACT(np
))
639 if ((np
->nlp_state
!= NLP_STE_NPR_NODE
) ||
640 !(np
->nlp_flag
& NLP_NPR_ADISC
))
642 spin_lock_irq(shost
->host_lock
);
643 np
->nlp_flag
&= ~NLP_NPR_ADISC
;
644 spin_unlock_irq(shost
->host_lock
);
645 lpfc_unreg_rpi(vport
, np
);
647 lpfc_cleanup_pending_mbox(vport
);
649 if (phba
->sli_rev
== LPFC_SLI_REV4
)
650 lpfc_sli4_unreg_all_rpis(vport
);
652 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) {
653 lpfc_mbx_unreg_vpi(vport
);
654 spin_lock_irq(shost
->host_lock
);
655 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
656 spin_unlock_irq(shost
->host_lock
);
659 * If VPI is unreged, driver need to do INIT_VPI
660 * before re-registering
662 if (phba
->sli_rev
== LPFC_SLI_REV4
) {
663 spin_lock_irq(shost
->host_lock
);
664 vport
->fc_flag
|= FC_VPORT_NEEDS_INIT_VPI
;
665 spin_unlock_irq(shost
->host_lock
);
667 } else if ((phba
->sli_rev
== LPFC_SLI_REV4
) &&
668 !(vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
)) {
670 * Driver needs to re-reg VPI in order for f/w
671 * to update the MAC address.
673 lpfc_register_new_vport(phba
, vport
, ndlp
);
677 if (phba
->sli_rev
< LPFC_SLI_REV4
) {
678 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_REG_LOGIN_ISSUE
);
679 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
&&
680 vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
)
681 lpfc_register_new_vport(phba
, vport
, ndlp
);
683 lpfc_issue_fabric_reglogin(vport
);
685 ndlp
->nlp_type
|= NLP_FABRIC
;
686 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
687 if ((!(vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
)) &&
688 (vport
->vpi_state
& LPFC_VPI_REGISTERED
)) {
689 lpfc_start_fdiscs(phba
);
690 lpfc_do_scr_ns_plogi(phba
, vport
);
691 } else if (vport
->fc_flag
& FC_VFI_REGISTERED
)
692 lpfc_issue_init_vpi(vport
);
694 lpfc_issue_reg_vfi(vport
);
699 * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
700 * @vport: pointer to a host virtual N_Port data structure.
701 * @ndlp: pointer to a node-list data structure.
702 * @sp: pointer to service parameter data structure.
704 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
705 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
706 * in a point-to-point topology. First, the @vport's N_Port Name is compared
707 * with the received N_Port Name: if the @vport's N_Port Name is greater than
708 * the received N_Port Name lexicographically, this node shall assign local
709 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
710 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
711 * this node shall just wait for the remote node to issue PLOGI and assign
719 lpfc_cmpl_els_flogi_nport(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
720 struct serv_parm
*sp
)
722 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
723 struct lpfc_hba
*phba
= vport
->phba
;
727 spin_lock_irq(shost
->host_lock
);
728 vport
->fc_flag
&= ~(FC_FABRIC
| FC_PUBLIC_LOOP
);
729 spin_unlock_irq(shost
->host_lock
);
731 phba
->fc_edtov
= FF_DEF_EDTOV
;
732 phba
->fc_ratov
= FF_DEF_RATOV
;
733 rc
= memcmp(&vport
->fc_portname
, &sp
->portName
,
734 sizeof(vport
->fc_portname
));
736 /* This side will initiate the PLOGI */
737 spin_lock_irq(shost
->host_lock
);
738 vport
->fc_flag
|= FC_PT2PT_PLOGI
;
739 spin_unlock_irq(shost
->host_lock
);
742 * N_Port ID cannot be 0, set our to LocalID the other
743 * side will be RemoteID.
748 vport
->fc_myDID
= PT2PT_LocalID
;
750 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
754 lpfc_config_link(phba
, mbox
);
756 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
758 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
759 if (rc
== MBX_NOT_FINISHED
) {
760 mempool_free(mbox
, phba
->mbox_mem_pool
);
763 /* Decrement ndlp reference count indicating that ndlp can be
764 * safely released when other references to it are done.
768 ndlp
= lpfc_findnode_did(vport
, PT2PT_RemoteID
);
771 * Cannot find existing Fabric ndlp, so allocate a
774 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
777 lpfc_nlp_init(vport
, ndlp
, PT2PT_RemoteID
);
778 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
779 ndlp
= lpfc_enable_node(vport
, ndlp
,
780 NLP_STE_UNUSED_NODE
);
785 memcpy(&ndlp
->nlp_portname
, &sp
->portName
,
786 sizeof(struct lpfc_name
));
787 memcpy(&ndlp
->nlp_nodename
, &sp
->nodeName
,
788 sizeof(struct lpfc_name
));
789 /* Set state will put ndlp onto node list if not already done */
790 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
791 spin_lock_irq(shost
->host_lock
);
792 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
793 spin_unlock_irq(shost
->host_lock
);
795 /* This side will wait for the PLOGI, decrement ndlp reference
796 * count indicating that ndlp can be released when other
797 * references to it are done.
801 /* If we are pt2pt with another NPort, force NPIV off! */
802 phba
->sli3_options
&= ~LPFC_SLI3_NPIV_ENABLED
;
804 spin_lock_irq(shost
->host_lock
);
805 vport
->fc_flag
|= FC_PT2PT
;
806 spin_unlock_irq(shost
->host_lock
);
808 /* Start discovery - this should just do CLEAR_LA */
809 lpfc_disc_start(vport
);
816 * lpfc_cmpl_els_flogi - Completion callback function for flogi
817 * @phba: pointer to lpfc hba data structure.
818 * @cmdiocb: pointer to lpfc command iocb data structure.
819 * @rspiocb: pointer to lpfc response iocb data structure.
821 * This routine is the top-level completion callback function for issuing
822 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
823 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
824 * retry has been made (either immediately or delayed with lpfc_els_retry()
825 * returning 1), the command IOCB will be released and function returned.
826 * If the retry attempt has been given up (possibly reach the maximum
827 * number of retries), one additional decrement of ndlp reference shall be
828 * invoked before going out after releasing the command IOCB. This will
829 * actually release the remote node (Note, lpfc_els_free_iocb() will also
830 * invoke one decrement of ndlp reference count). If no error reported in
831 * the IOCB status, the command Port ID field is used to determine whether
832 * this is a point-to-point topology or a fabric topology: if the Port ID
833 * field is assigned, it is a fabric topology; otherwise, it is a
834 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
835 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
836 * specific topology completion conditions.
839 lpfc_cmpl_els_flogi(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
840 struct lpfc_iocbq
*rspiocb
)
842 struct lpfc_vport
*vport
= cmdiocb
->vport
;
843 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
844 IOCB_t
*irsp
= &rspiocb
->iocb
;
845 struct lpfc_nodelist
*ndlp
= cmdiocb
->context1
;
846 struct lpfc_dmabuf
*pcmd
= cmdiocb
->context2
, *prsp
;
847 struct serv_parm
*sp
;
851 /* Check to see if link went down during discovery */
852 if (lpfc_els_chk_latt(vport
)) {
853 /* One additional decrement on node reference count to
854 * trigger the release of the node
860 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
861 "FLOGI cmpl: status:x%x/x%x state:x%x",
862 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
865 if (irsp
->ulpStatus
) {
867 * In case of FIP mode, perform roundrobin FCF failover
868 * due to new FCF discovery
870 if ((phba
->hba_flag
& HBA_FIP_SUPPORT
) &&
871 (phba
->fcf
.fcf_flag
& FCF_DISCOVERY
) &&
872 (irsp
->ulpStatus
!= IOSTAT_LOCAL_REJECT
) &&
873 (irsp
->un
.ulpWord
[4] != IOERR_SLI_ABORTED
)) {
874 lpfc_printf_log(phba
, KERN_WARNING
, LOG_FIP
| LOG_ELS
,
875 "2611 FLOGI failed on FCF (x%x), "
876 "status:x%x/x%x, tmo:x%x, perform "
877 "roundrobin FCF failover\n",
878 phba
->fcf
.current_rec
.fcf_indx
,
879 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
881 fcf_index
= lpfc_sli4_fcf_rr_next_index_get(phba
);
882 rc
= lpfc_sli4_fcf_rr_next_proc(vport
, fcf_index
);
888 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
889 "2858 FLOGI failure Status:x%x/x%x TMO:x%x\n",
890 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
893 /* Check for retry */
894 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
))
898 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
899 "0100 FLOGI failure Status:x%x/x%x TMO:x%x\n",
900 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
903 /* FLOGI failed, so there is no fabric */
904 spin_lock_irq(shost
->host_lock
);
905 vport
->fc_flag
&= ~(FC_FABRIC
| FC_PUBLIC_LOOP
);
906 spin_unlock_irq(shost
->host_lock
);
908 /* If private loop, then allow max outstanding els to be
909 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
910 * alpa map would take too long otherwise.
912 if (phba
->alpa_map
[0] == 0) {
913 vport
->cfg_discovery_threads
= LPFC_MAX_DISC_THREADS
;
914 if ((phba
->sli_rev
== LPFC_SLI_REV4
) &&
915 (!(vport
->fc_flag
& FC_VFI_REGISTERED
) ||
916 (vport
->fc_prevDID
!= vport
->fc_myDID
))) {
917 if (vport
->fc_flag
& FC_VFI_REGISTERED
)
918 lpfc_sli4_unreg_all_rpis(vport
);
919 lpfc_issue_reg_vfi(vport
);
926 spin_lock_irq(shost
->host_lock
);
927 vport
->fc_flag
&= ~FC_VPORT_CVL_RCVD
;
928 vport
->fc_flag
&= ~FC_VPORT_LOGO_RCVD
;
929 spin_unlock_irq(shost
->host_lock
);
932 * The FLogI succeeded. Sync the data for the CPU before
935 prsp
= list_get_first(&pcmd
->list
, struct lpfc_dmabuf
, list
);
937 sp
= prsp
->virt
+ sizeof(uint32_t);
939 /* FLOGI completes successfully */
940 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
941 "0101 FLOGI completes successfully "
942 "Data: x%x x%x x%x x%x\n",
943 irsp
->un
.ulpWord
[4], sp
->cmn
.e_d_tov
,
944 sp
->cmn
.w2
.r_a_tov
, sp
->cmn
.edtovResolution
);
946 if (vport
->port_state
== LPFC_FLOGI
) {
948 * If Common Service Parameters indicate Nport
949 * we are point to point, if Fport we are Fabric.
952 rc
= lpfc_cmpl_els_flogi_fabric(vport
, ndlp
, sp
, irsp
);
953 else if (!(phba
->hba_flag
& HBA_FCOE_MODE
))
954 rc
= lpfc_cmpl_els_flogi_nport(vport
, ndlp
, sp
);
956 lpfc_printf_vlog(vport
, KERN_ERR
,
958 "2831 FLOGI response with cleared Fabric "
959 "bit fcf_index 0x%x "
960 "Switch Name %02x%02x%02x%02x%02x%02x%02x%02x "
962 "%02x%02x%02x%02x%02x%02x%02x%02x\n",
963 phba
->fcf
.current_rec
.fcf_indx
,
964 phba
->fcf
.current_rec
.switch_name
[0],
965 phba
->fcf
.current_rec
.switch_name
[1],
966 phba
->fcf
.current_rec
.switch_name
[2],
967 phba
->fcf
.current_rec
.switch_name
[3],
968 phba
->fcf
.current_rec
.switch_name
[4],
969 phba
->fcf
.current_rec
.switch_name
[5],
970 phba
->fcf
.current_rec
.switch_name
[6],
971 phba
->fcf
.current_rec
.switch_name
[7],
972 phba
->fcf
.current_rec
.fabric_name
[0],
973 phba
->fcf
.current_rec
.fabric_name
[1],
974 phba
->fcf
.current_rec
.fabric_name
[2],
975 phba
->fcf
.current_rec
.fabric_name
[3],
976 phba
->fcf
.current_rec
.fabric_name
[4],
977 phba
->fcf
.current_rec
.fabric_name
[5],
978 phba
->fcf
.current_rec
.fabric_name
[6],
979 phba
->fcf
.current_rec
.fabric_name
[7]);
981 spin_lock_irq(&phba
->hbalock
);
982 phba
->fcf
.fcf_flag
&= ~FCF_DISCOVERY
;
983 phba
->hba_flag
&= ~(FCF_RR_INPROG
| HBA_DEVLOSS_TMO
);
984 spin_unlock_irq(&phba
->hbalock
);
988 /* Mark the FCF discovery process done */
989 if (phba
->hba_flag
& HBA_FIP_SUPPORT
)
990 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_FIP
|
992 "2769 FLOGI to FCF (x%x) "
993 "completed successfully\n",
994 phba
->fcf
.current_rec
.fcf_indx
);
995 spin_lock_irq(&phba
->hbalock
);
996 phba
->fcf
.fcf_flag
&= ~FCF_DISCOVERY
;
997 phba
->hba_flag
&= ~(FCF_RR_INPROG
| HBA_DEVLOSS_TMO
);
998 spin_unlock_irq(&phba
->hbalock
);
1006 if (!lpfc_error_lost_link(irsp
)) {
1007 /* FLOGI failed, so just use loop map to make discovery list */
1008 lpfc_disc_list_loopmap(vport
);
1010 /* Start discovery */
1011 lpfc_disc_start(vport
);
1012 } else if (((irsp
->ulpStatus
!= IOSTAT_LOCAL_REJECT
) ||
1013 ((irsp
->un
.ulpWord
[4] != IOERR_SLI_ABORTED
) &&
1014 (irsp
->un
.ulpWord
[4] != IOERR_SLI_DOWN
))) &&
1015 (phba
->link_state
!= LPFC_CLEAR_LA
)) {
1016 /* If FLOGI failed enable link interrupt. */
1017 lpfc_issue_clear_la(phba
, vport
);
1020 lpfc_els_free_iocb(phba
, cmdiocb
);
1024 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
1025 * @vport: pointer to a host virtual N_Port data structure.
1026 * @ndlp: pointer to a node-list data structure.
1027 * @retry: number of retries to the command IOCB.
1029 * This routine issues a Fabric Login (FLOGI) Request ELS command
1030 * for a @vport. The initiator service parameters are put into the payload
1031 * of the FLOGI Request IOCB and the top-level callback function pointer
1032 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
1033 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
1034 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
1036 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1037 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1038 * will be stored into the context1 field of the IOCB for the completion
1039 * callback function to the FLOGI ELS command.
1042 * 0 - successfully issued flogi iocb for @vport
1043 * 1 - failed to issue flogi iocb for @vport
1046 lpfc_issue_els_flogi(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1049 struct lpfc_hba
*phba
= vport
->phba
;
1050 struct serv_parm
*sp
;
1052 struct lpfc_iocbq
*elsiocb
;
1053 struct lpfc_sli_ring
*pring
;
1059 pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
1061 cmdsize
= (sizeof(uint32_t) + sizeof(struct serv_parm
));
1062 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
1063 ndlp
->nlp_DID
, ELS_CMD_FLOGI
);
1068 icmd
= &elsiocb
->iocb
;
1069 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
1071 /* For FLOGI request, remainder of payload is service parameters */
1072 *((uint32_t *) (pcmd
)) = ELS_CMD_FLOGI
;
1073 pcmd
+= sizeof(uint32_t);
1074 memcpy(pcmd
, &vport
->fc_sparam
, sizeof(struct serv_parm
));
1075 sp
= (struct serv_parm
*) pcmd
;
1077 /* Setup CSPs accordingly for Fabric */
1078 sp
->cmn
.e_d_tov
= 0;
1079 sp
->cmn
.w2
.r_a_tov
= 0;
1080 sp
->cls1
.classValid
= 0;
1081 sp
->cls2
.seqDelivery
= 1;
1082 sp
->cls3
.seqDelivery
= 1;
1083 if (sp
->cmn
.fcphLow
< FC_PH3
)
1084 sp
->cmn
.fcphLow
= FC_PH3
;
1085 if (sp
->cmn
.fcphHigh
< FC_PH3
)
1086 sp
->cmn
.fcphHigh
= FC_PH3
;
1088 if ((phba
->sli_rev
== LPFC_SLI_REV4
) &&
1089 (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) ==
1090 LPFC_SLI_INTF_IF_TYPE_0
)) {
1091 elsiocb
->iocb
.ulpCt_h
= ((SLI4_CT_FCFI
>> 1) & 1);
1092 elsiocb
->iocb
.ulpCt_l
= (SLI4_CT_FCFI
& 1);
1093 /* FLOGI needs to be 3 for WQE FCFI */
1094 /* Set the fcfi to the fcfi we registered with */
1095 elsiocb
->iocb
.ulpContext
= phba
->fcf
.fcfi
;
1096 } else if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) {
1097 sp
->cmn
.request_multiple_Nport
= 1;
1098 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 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 reponse 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 */
3657 pcmd
= (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
3658 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
3659 pcmd
+= sizeof(uint32_t);
3661 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
3662 "Issue ACC: did:x%x flg:x%x",
3663 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
3666 cmdsize
= (sizeof(struct serv_parm
) + sizeof(uint32_t));
3667 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
,
3668 ndlp
, ndlp
->nlp_DID
, ELS_CMD_ACC
);
3672 icmd
= &elsiocb
->iocb
;
3673 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri */
3674 pcmd
= (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
3677 elsiocb
->context_un
.mbox
= mbox
;
3679 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
3680 pcmd
+= sizeof(uint32_t);
3681 memcpy(pcmd
, &vport
->fc_sparam
, sizeof(struct serv_parm
));
3683 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
3684 "Issue ACC PLOGI: did:x%x flg:x%x",
3685 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
3688 cmdsize
= sizeof(uint32_t) + sizeof(PRLO
);
3689 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
,
3690 ndlp
, ndlp
->nlp_DID
, ELS_CMD_PRLO
);
3694 icmd
= &elsiocb
->iocb
;
3695 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri */
3696 pcmd
= (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
3698 memcpy(pcmd
, ((struct lpfc_dmabuf
*) oldiocb
->context2
)->virt
,
3699 sizeof(uint32_t) + sizeof(PRLO
));
3700 *((uint32_t *) (pcmd
)) = ELS_CMD_PRLO_ACC
;
3701 els_pkt_ptr
= (ELS_PKT
*) pcmd
;
3702 els_pkt_ptr
->un
.prlo
.acceptRspCode
= PRLO_REQ_EXECUTED
;
3704 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
3705 "Issue ACC PRLO: did:x%x flg:x%x",
3706 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
3711 /* Xmit ELS ACC response tag <ulpIoTag> */
3712 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3713 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
3714 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n",
3715 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
3716 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
3718 if (ndlp
->nlp_flag
& NLP_LOGO_ACC
) {
3719 spin_lock_irq(shost
->host_lock
);
3720 ndlp
->nlp_flag
&= ~NLP_LOGO_ACC
;
3721 spin_unlock_irq(shost
->host_lock
);
3722 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_logo_acc
;
3724 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
3727 phba
->fc_stat
.elsXmitACC
++;
3728 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
3729 if (rc
== IOCB_ERROR
) {
3730 lpfc_els_free_iocb(phba
, elsiocb
);
3737 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
3738 * @vport: pointer to a virtual N_Port data structure.
3740 * @oldiocb: pointer to the original lpfc command iocb data structure.
3741 * @ndlp: pointer to a node-list data structure.
3742 * @mbox: pointer to the driver internal queue element for mailbox command.
3744 * This routine prepares and issue an Reject (RJT) response IOCB
3745 * command. If a @mbox pointer is passed in, it will be put into the
3746 * context_un.mbox field of the IOCB for the completion callback function
3747 * to issue to the HBA later.
3749 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3750 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3751 * will be stored into the context1 field of the IOCB for the completion
3752 * callback function to the reject response ELS IOCB command.
3755 * 0 - Successfully issued reject response
3756 * 1 - Failed to issue reject response
3759 lpfc_els_rsp_reject(struct lpfc_vport
*vport
, uint32_t rejectError
,
3760 struct lpfc_iocbq
*oldiocb
, struct lpfc_nodelist
*ndlp
,
3763 struct lpfc_hba
*phba
= vport
->phba
;
3766 struct lpfc_iocbq
*elsiocb
;
3767 struct lpfc_sli
*psli
;
3773 cmdsize
= 2 * sizeof(uint32_t);
3774 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
3775 ndlp
->nlp_DID
, ELS_CMD_LS_RJT
);
3779 icmd
= &elsiocb
->iocb
;
3780 oldcmd
= &oldiocb
->iocb
;
3781 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri */
3782 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
3784 *((uint32_t *) (pcmd
)) = ELS_CMD_LS_RJT
;
3785 pcmd
+= sizeof(uint32_t);
3786 *((uint32_t *) (pcmd
)) = rejectError
;
3789 elsiocb
->context_un
.mbox
= mbox
;
3791 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
3792 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3793 "0129 Xmit ELS RJT x%x response tag x%x "
3794 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
3796 rejectError
, elsiocb
->iotag
,
3797 elsiocb
->iocb
.ulpContext
, ndlp
->nlp_DID
,
3798 ndlp
->nlp_flag
, ndlp
->nlp_state
, ndlp
->nlp_rpi
);
3799 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
3800 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
3801 ndlp
->nlp_DID
, ndlp
->nlp_flag
, rejectError
);
3803 phba
->fc_stat
.elsXmitLSRJT
++;
3804 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
3805 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
3807 if (rc
== IOCB_ERROR
) {
3808 lpfc_els_free_iocb(phba
, elsiocb
);
3815 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
3816 * @vport: pointer to a virtual N_Port data structure.
3817 * @oldiocb: pointer to the original lpfc command iocb data structure.
3818 * @ndlp: pointer to a node-list data structure.
3820 * This routine prepares and issues an Accept (ACC) response to Address
3821 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
3822 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3824 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3825 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3826 * will be stored into the context1 field of the IOCB for the completion
3827 * callback function to the ADISC Accept response ELS IOCB command.
3830 * 0 - Successfully issued acc adisc response
3831 * 1 - Failed to issue adisc acc response
3834 lpfc_els_rsp_adisc_acc(struct lpfc_vport
*vport
, struct lpfc_iocbq
*oldiocb
,
3835 struct lpfc_nodelist
*ndlp
)
3837 struct lpfc_hba
*phba
= vport
->phba
;
3839 IOCB_t
*icmd
, *oldcmd
;
3840 struct lpfc_iocbq
*elsiocb
;
3845 cmdsize
= sizeof(uint32_t) + sizeof(ADISC
);
3846 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
3847 ndlp
->nlp_DID
, ELS_CMD_ACC
);
3851 icmd
= &elsiocb
->iocb
;
3852 oldcmd
= &oldiocb
->iocb
;
3853 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri */
3855 /* Xmit ADISC ACC response tag <ulpIoTag> */
3856 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3857 "0130 Xmit ADISC ACC response iotag x%x xri: "
3858 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
3859 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
3860 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
3862 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
3864 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
3865 pcmd
+= sizeof(uint32_t);
3867 ap
= (ADISC
*) (pcmd
);
3868 ap
->hardAL_PA
= phba
->fc_pref_ALPA
;
3869 memcpy(&ap
->portName
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
3870 memcpy(&ap
->nodeName
, &vport
->fc_nodename
, sizeof(struct lpfc_name
));
3871 ap
->DID
= be32_to_cpu(vport
->fc_myDID
);
3873 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
3874 "Issue ACC ADISC: did:x%x flg:x%x",
3875 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
3877 phba
->fc_stat
.elsXmitACC
++;
3878 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
3879 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
3880 if (rc
== IOCB_ERROR
) {
3881 lpfc_els_free_iocb(phba
, elsiocb
);
3888 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
3889 * @vport: pointer to a virtual N_Port data structure.
3890 * @oldiocb: pointer to the original lpfc command iocb data structure.
3891 * @ndlp: pointer to a node-list data structure.
3893 * This routine prepares and issues an Accept (ACC) response to Process
3894 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
3895 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3897 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3898 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3899 * will be stored into the context1 field of the IOCB for the completion
3900 * callback function to the PRLI Accept response ELS IOCB command.
3903 * 0 - Successfully issued acc prli response
3904 * 1 - Failed to issue acc prli response
3907 lpfc_els_rsp_prli_acc(struct lpfc_vport
*vport
, struct lpfc_iocbq
*oldiocb
,
3908 struct lpfc_nodelist
*ndlp
)
3910 struct lpfc_hba
*phba
= vport
->phba
;
3915 struct lpfc_iocbq
*elsiocb
;
3916 struct lpfc_sli
*psli
;
3923 cmdsize
= sizeof(uint32_t) + sizeof(PRLI
);
3924 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
3925 ndlp
->nlp_DID
, (ELS_CMD_ACC
| (ELS_CMD_PRLI
& ~ELS_RSP_MASK
)));
3929 icmd
= &elsiocb
->iocb
;
3930 oldcmd
= &oldiocb
->iocb
;
3931 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri */
3932 /* Xmit PRLI ACC response tag <ulpIoTag> */
3933 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3934 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
3935 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
3936 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
3937 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
3939 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
3941 *((uint32_t *) (pcmd
)) = (ELS_CMD_ACC
| (ELS_CMD_PRLI
& ~ELS_RSP_MASK
));
3942 pcmd
+= sizeof(uint32_t);
3944 /* For PRLI, remainder of payload is PRLI parameter page */
3945 memset(pcmd
, 0, sizeof(PRLI
));
3947 npr
= (PRLI
*) pcmd
;
3950 * If the remote port is a target and our firmware version is 3.20 or
3951 * later, set the following bits for FC-TAPE support.
3953 if ((ndlp
->nlp_type
& NLP_FCP_TARGET
) &&
3954 (vpd
->rev
.feaLevelHigh
>= 0x02)) {
3955 npr
->ConfmComplAllowed
= 1;
3957 npr
->TaskRetryIdReq
= 1;
3960 npr
->acceptRspCode
= PRLI_REQ_EXECUTED
;
3961 npr
->estabImagePair
= 1;
3962 npr
->readXferRdyDis
= 1;
3963 npr
->ConfmComplAllowed
= 1;
3965 npr
->prliType
= PRLI_FCP_TYPE
;
3966 npr
->initiatorFunc
= 1;
3968 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
3969 "Issue ACC PRLI: did:x%x flg:x%x",
3970 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
3972 phba
->fc_stat
.elsXmitACC
++;
3973 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
3975 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
3976 if (rc
== IOCB_ERROR
) {
3977 lpfc_els_free_iocb(phba
, elsiocb
);
3984 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
3985 * @vport: pointer to a virtual N_Port data structure.
3986 * @format: rnid command format.
3987 * @oldiocb: pointer to the original lpfc command iocb data structure.
3988 * @ndlp: pointer to a node-list data structure.
3990 * This routine issues a Request Node Identification Data (RNID) Accept
3991 * (ACC) response. It constructs the RNID ACC response command according to
3992 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
3993 * issue the response. Note that this command does not need to hold the ndlp
3994 * reference count for the callback. So, the ndlp reference count taken by
3995 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
3996 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
3997 * there is no ndlp reference available.
3999 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4000 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4001 * will be stored into the context1 field of the IOCB for the completion
4002 * callback function. However, for the RNID Accept Response ELS command,
4003 * this is undone later by this routine after the IOCB is allocated.
4006 * 0 - Successfully issued acc rnid response
4007 * 1 - Failed to issue acc rnid response
4010 lpfc_els_rsp_rnid_acc(struct lpfc_vport
*vport
, uint8_t format
,
4011 struct lpfc_iocbq
*oldiocb
, struct lpfc_nodelist
*ndlp
)
4013 struct lpfc_hba
*phba
= vport
->phba
;
4015 IOCB_t
*icmd
, *oldcmd
;
4016 struct lpfc_iocbq
*elsiocb
;
4017 struct lpfc_sli
*psli
;
4023 cmdsize
= sizeof(uint32_t) + sizeof(uint32_t)
4024 + (2 * sizeof(struct lpfc_name
));
4026 cmdsize
+= sizeof(RNID_TOP_DISC
);
4028 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
4029 ndlp
->nlp_DID
, ELS_CMD_ACC
);
4033 icmd
= &elsiocb
->iocb
;
4034 oldcmd
= &oldiocb
->iocb
;
4035 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri */
4036 /* Xmit RNID ACC response tag <ulpIoTag> */
4037 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
4038 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
4039 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
);
4040 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
4041 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
4042 pcmd
+= sizeof(uint32_t);
4044 memset(pcmd
, 0, sizeof(RNID
));
4045 rn
= (RNID
*) (pcmd
);
4046 rn
->Format
= format
;
4047 rn
->CommonLen
= (2 * sizeof(struct lpfc_name
));
4048 memcpy(&rn
->portName
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
4049 memcpy(&rn
->nodeName
, &vport
->fc_nodename
, sizeof(struct lpfc_name
));
4052 rn
->SpecificLen
= 0;
4054 case RNID_TOPOLOGY_DISC
:
4055 rn
->SpecificLen
= sizeof(RNID_TOP_DISC
);
4056 memcpy(&rn
->un
.topologyDisc
.portName
,
4057 &vport
->fc_portname
, sizeof(struct lpfc_name
));
4058 rn
->un
.topologyDisc
.unitType
= RNID_HBA
;
4059 rn
->un
.topologyDisc
.physPort
= 0;
4060 rn
->un
.topologyDisc
.attachedNodes
= 0;
4064 rn
->SpecificLen
= 0;
4068 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
4069 "Issue ACC RNID: did:x%x flg:x%x",
4070 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
4072 phba
->fc_stat
.elsXmitACC
++;
4073 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
4075 elsiocb
->context1
= NULL
; /* Don't need ndlp for cmpl,
4076 * it could be freed */
4078 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
4079 if (rc
== IOCB_ERROR
) {
4080 lpfc_els_free_iocb(phba
, elsiocb
);
4087 * lpfc_els_clear_rrq - Clear the rq that this rrq describes.
4088 * @vport: pointer to a virtual N_Port data structure.
4089 * @iocb: pointer to the lpfc command iocb data structure.
4090 * @ndlp: pointer to a node-list data structure.
4095 lpfc_els_clear_rrq(struct lpfc_vport
*vport
,
4096 struct lpfc_iocbq
*iocb
, struct lpfc_nodelist
*ndlp
)
4098 struct lpfc_hba
*phba
= vport
->phba
;
4103 struct lpfc_node_rrq
*prrq
;
4106 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) iocb
->context2
)->virt
);
4107 pcmd
+= sizeof(uint32_t);
4108 rrq
= (struct RRQ
*)pcmd
;
4109 rrq
->rrq_exchg
= be32_to_cpu(rrq
->rrq_exchg
);
4110 rxid
= be16_to_cpu(bf_get(rrq_rxid
, rrq
));
4112 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
4113 "2883 Clear RRQ for SID:x%x OXID:x%x RXID:x%x"
4115 be32_to_cpu(bf_get(rrq_did
, rrq
)),
4116 be16_to_cpu(bf_get(rrq_oxid
, rrq
)),
4118 iocb
->iotag
, iocb
->iocb
.ulpContext
);
4120 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
4121 "Clear RRQ: did:x%x flg:x%x exchg:x%.08x",
4122 ndlp
->nlp_DID
, ndlp
->nlp_flag
, rrq
->rrq_exchg
);
4123 if (vport
->fc_myDID
== be32_to_cpu(bf_get(rrq_did
, rrq
)))
4124 xri
= be16_to_cpu(bf_get(rrq_oxid
, rrq
));
4127 prrq
= lpfc_get_active_rrq(vport
, xri
, ndlp
->nlp_DID
);
4129 lpfc_clr_rrq_active(phba
, xri
, prrq
);
4134 * lpfc_els_rsp_echo_acc - Issue echo acc response
4135 * @vport: pointer to a virtual N_Port data structure.
4136 * @data: pointer to echo data to return in the accept.
4137 * @oldiocb: pointer to the original lpfc command iocb data structure.
4138 * @ndlp: pointer to a node-list data structure.
4141 * 0 - Successfully issued acc echo response
4142 * 1 - Failed to issue acc echo response
4145 lpfc_els_rsp_echo_acc(struct lpfc_vport
*vport
, uint8_t *data
,
4146 struct lpfc_iocbq
*oldiocb
, struct lpfc_nodelist
*ndlp
)
4148 struct lpfc_hba
*phba
= vport
->phba
;
4149 struct lpfc_iocbq
*elsiocb
;
4150 struct lpfc_sli
*psli
;
4156 cmdsize
= oldiocb
->iocb
.unsli3
.rcvsli3
.acc_len
;
4158 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
4159 ndlp
->nlp_DID
, ELS_CMD_ACC
);
4163 elsiocb
->iocb
.ulpContext
= oldiocb
->iocb
.ulpContext
; /* Xri */
4164 /* Xmit ECHO ACC response tag <ulpIoTag> */
4165 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
4166 "2876 Xmit ECHO ACC response tag x%x xri x%x\n",
4167 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
);
4168 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
4169 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
4170 pcmd
+= sizeof(uint32_t);
4171 memcpy(pcmd
, data
, cmdsize
- sizeof(uint32_t));
4173 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
4174 "Issue ACC ECHO: did:x%x flg:x%x",
4175 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
4177 phba
->fc_stat
.elsXmitACC
++;
4178 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
4180 elsiocb
->context1
= NULL
; /* Don't need ndlp for cmpl,
4181 * it could be freed */
4183 rc
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
4184 if (rc
== IOCB_ERROR
) {
4185 lpfc_els_free_iocb(phba
, elsiocb
);
4192 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
4193 * @vport: pointer to a host virtual N_Port data structure.
4195 * This routine issues Address Discover (ADISC) ELS commands to those
4196 * N_Ports which are in node port recovery state and ADISC has not been issued
4197 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
4198 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
4199 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
4200 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
4201 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
4202 * IOCBs quit for later pick up. On the other hand, after walking through
4203 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
4204 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
4205 * no more ADISC need to be sent.
4208 * The number of N_Ports with adisc issued.
4211 lpfc_els_disc_adisc(struct lpfc_vport
*vport
)
4213 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4214 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
4217 /* go thru NPR nodes and issue any remaining ELS ADISCs */
4218 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
, nlp_listp
) {
4219 if (!NLP_CHK_NODE_ACT(ndlp
))
4221 if (ndlp
->nlp_state
== NLP_STE_NPR_NODE
&&
4222 (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) != 0 &&
4223 (ndlp
->nlp_flag
& NLP_NPR_ADISC
) != 0) {
4224 spin_lock_irq(shost
->host_lock
);
4225 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
4226 spin_unlock_irq(shost
->host_lock
);
4227 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
4228 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_ADISC_ISSUE
);
4229 lpfc_issue_els_adisc(vport
, ndlp
, 0);
4231 vport
->num_disc_nodes
++;
4232 if (vport
->num_disc_nodes
>=
4233 vport
->cfg_discovery_threads
) {
4234 spin_lock_irq(shost
->host_lock
);
4235 vport
->fc_flag
|= FC_NLP_MORE
;
4236 spin_unlock_irq(shost
->host_lock
);
4241 if (sentadisc
== 0) {
4242 spin_lock_irq(shost
->host_lock
);
4243 vport
->fc_flag
&= ~FC_NLP_MORE
;
4244 spin_unlock_irq(shost
->host_lock
);
4250 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
4251 * @vport: pointer to a host virtual N_Port data structure.
4253 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
4254 * which are in node port recovery state, with a @vport. Each time an ELS
4255 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
4256 * the per @vport number of discover count (num_disc_nodes) shall be
4257 * incremented. If the num_disc_nodes reaches a pre-configured threshold
4258 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
4259 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
4260 * later pick up. On the other hand, after walking through all the ndlps with
4261 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
4262 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
4263 * PLOGI need to be sent.
4266 * The number of N_Ports with plogi issued.
4269 lpfc_els_disc_plogi(struct lpfc_vport
*vport
)
4271 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4272 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
4275 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
4276 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
, nlp_listp
) {
4277 if (!NLP_CHK_NODE_ACT(ndlp
))
4279 if (ndlp
->nlp_state
== NLP_STE_NPR_NODE
&&
4280 (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) != 0 &&
4281 (ndlp
->nlp_flag
& NLP_DELAY_TMO
) == 0 &&
4282 (ndlp
->nlp_flag
& NLP_NPR_ADISC
) == 0) {
4283 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
4284 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
4285 lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0);
4287 vport
->num_disc_nodes
++;
4288 if (vport
->num_disc_nodes
>=
4289 vport
->cfg_discovery_threads
) {
4290 spin_lock_irq(shost
->host_lock
);
4291 vport
->fc_flag
|= FC_NLP_MORE
;
4292 spin_unlock_irq(shost
->host_lock
);
4298 lpfc_set_disctmo(vport
);
4301 spin_lock_irq(shost
->host_lock
);
4302 vport
->fc_flag
&= ~FC_NLP_MORE
;
4303 spin_unlock_irq(shost
->host_lock
);
4309 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
4310 * @vport: pointer to a host virtual N_Port data structure.
4312 * This routine cleans up any Registration State Change Notification
4313 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
4314 * @vport together with the host_lock is used to prevent multiple thread
4315 * trying to access the RSCN array on a same @vport at the same time.
4318 lpfc_els_flush_rscn(struct lpfc_vport
*vport
)
4320 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4321 struct lpfc_hba
*phba
= vport
->phba
;
4324 spin_lock_irq(shost
->host_lock
);
4325 if (vport
->fc_rscn_flush
) {
4326 /* Another thread is walking fc_rscn_id_list on this vport */
4327 spin_unlock_irq(shost
->host_lock
);
4330 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
4331 vport
->fc_rscn_flush
= 1;
4332 spin_unlock_irq(shost
->host_lock
);
4334 for (i
= 0; i
< vport
->fc_rscn_id_cnt
; i
++) {
4335 lpfc_in_buf_free(phba
, vport
->fc_rscn_id_list
[i
]);
4336 vport
->fc_rscn_id_list
[i
] = NULL
;
4338 spin_lock_irq(shost
->host_lock
);
4339 vport
->fc_rscn_id_cnt
= 0;
4340 vport
->fc_flag
&= ~(FC_RSCN_MODE
| FC_RSCN_DISCOVERY
);
4341 spin_unlock_irq(shost
->host_lock
);
4342 lpfc_can_disctmo(vport
);
4343 /* Indicate we are done walking this fc_rscn_id_list */
4344 vport
->fc_rscn_flush
= 0;
4348 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
4349 * @vport: pointer to a host virtual N_Port data structure.
4350 * @did: remote destination port identifier.
4352 * This routine checks whether there is any pending Registration State
4353 * Configuration Notification (RSCN) to a @did on @vport.
4356 * None zero - The @did matched with a pending rscn
4357 * 0 - not able to match @did with a pending rscn
4360 lpfc_rscn_payload_check(struct lpfc_vport
*vport
, uint32_t did
)
4365 uint32_t payload_len
, i
;
4366 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4368 ns_did
.un
.word
= did
;
4370 /* Never match fabric nodes for RSCNs */
4371 if ((did
& Fabric_DID_MASK
) == Fabric_DID_MASK
)
4374 /* If we are doing a FULL RSCN rediscovery, match everything */
4375 if (vport
->fc_flag
& FC_RSCN_DISCOVERY
)
4378 spin_lock_irq(shost
->host_lock
);
4379 if (vport
->fc_rscn_flush
) {
4380 /* Another thread is walking fc_rscn_id_list on this vport */
4381 spin_unlock_irq(shost
->host_lock
);
4384 /* Indicate we are walking fc_rscn_id_list on this vport */
4385 vport
->fc_rscn_flush
= 1;
4386 spin_unlock_irq(shost
->host_lock
);
4387 for (i
= 0; i
< vport
->fc_rscn_id_cnt
; i
++) {
4388 lp
= vport
->fc_rscn_id_list
[i
]->virt
;
4389 payload_len
= be32_to_cpu(*lp
++ & ~ELS_CMD_MASK
);
4390 payload_len
-= sizeof(uint32_t); /* take off word 0 */
4391 while (payload_len
) {
4392 rscn_did
.un
.word
= be32_to_cpu(*lp
++);
4393 payload_len
-= sizeof(uint32_t);
4394 switch (rscn_did
.un
.b
.resv
& RSCN_ADDRESS_FORMAT_MASK
) {
4395 case RSCN_ADDRESS_FORMAT_PORT
:
4396 if ((ns_did
.un
.b
.domain
== rscn_did
.un
.b
.domain
)
4397 && (ns_did
.un
.b
.area
== rscn_did
.un
.b
.area
)
4398 && (ns_did
.un
.b
.id
== rscn_did
.un
.b
.id
))
4399 goto return_did_out
;
4401 case RSCN_ADDRESS_FORMAT_AREA
:
4402 if ((ns_did
.un
.b
.domain
== rscn_did
.un
.b
.domain
)
4403 && (ns_did
.un
.b
.area
== rscn_did
.un
.b
.area
))
4404 goto return_did_out
;
4406 case RSCN_ADDRESS_FORMAT_DOMAIN
:
4407 if (ns_did
.un
.b
.domain
== rscn_did
.un
.b
.domain
)
4408 goto return_did_out
;
4410 case RSCN_ADDRESS_FORMAT_FABRIC
:
4411 goto return_did_out
;
4415 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4416 vport
->fc_rscn_flush
= 0;
4419 /* Indicate we are done with walking fc_rscn_id_list on this vport */
4420 vport
->fc_rscn_flush
= 0;
4425 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
4426 * @vport: pointer to a host virtual N_Port data structure.
4428 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
4429 * state machine for a @vport's nodes that are with pending RSCN (Registration
4430 * State Change Notification).
4433 * 0 - Successful (currently alway return 0)
4436 lpfc_rscn_recovery_check(struct lpfc_vport
*vport
)
4438 struct lpfc_nodelist
*ndlp
= NULL
;
4440 /* Move all affected nodes by pending RSCNs to NPR state. */
4441 list_for_each_entry(ndlp
, &vport
->fc_nodes
, nlp_listp
) {
4442 if (!NLP_CHK_NODE_ACT(ndlp
) ||
4443 (ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
) ||
4444 !lpfc_rscn_payload_check(vport
, ndlp
->nlp_DID
))
4446 lpfc_disc_state_machine(vport
, ndlp
, NULL
,
4447 NLP_EVT_DEVICE_RECOVERY
);
4448 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
4454 * lpfc_send_rscn_event - Send an RSCN event to management application
4455 * @vport: pointer to a host virtual N_Port data structure.
4456 * @cmdiocb: pointer to lpfc command iocb data structure.
4458 * lpfc_send_rscn_event sends an RSCN netlink event to management
4462 lpfc_send_rscn_event(struct lpfc_vport
*vport
,
4463 struct lpfc_iocbq
*cmdiocb
)
4465 struct lpfc_dmabuf
*pcmd
;
4466 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4467 uint32_t *payload_ptr
;
4468 uint32_t payload_len
;
4469 struct lpfc_rscn_event_header
*rscn_event_data
;
4471 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
4472 payload_ptr
= (uint32_t *) pcmd
->virt
;
4473 payload_len
= be32_to_cpu(*payload_ptr
& ~ELS_CMD_MASK
);
4475 rscn_event_data
= kmalloc(sizeof(struct lpfc_rscn_event_header
) +
4476 payload_len
, GFP_KERNEL
);
4477 if (!rscn_event_data
) {
4478 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
4479 "0147 Failed to allocate memory for RSCN event\n");
4482 rscn_event_data
->event_type
= FC_REG_RSCN_EVENT
;
4483 rscn_event_data
->payload_length
= payload_len
;
4484 memcpy(rscn_event_data
->rscn_payload
, payload_ptr
,
4487 fc_host_post_vendor_event(shost
,
4488 fc_get_event_number(),
4489 sizeof(struct lpfc_els_event_header
) + payload_len
,
4490 (char *)rscn_event_data
,
4493 kfree(rscn_event_data
);
4497 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
4498 * @vport: pointer to a host virtual N_Port data structure.
4499 * @cmdiocb: pointer to lpfc command iocb data structure.
4500 * @ndlp: pointer to a node-list data structure.
4502 * This routine processes an unsolicited RSCN (Registration State Change
4503 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
4504 * to invoke fc_host_post_event() routine to the FC transport layer. If the
4505 * discover state machine is about to begin discovery, it just accepts the
4506 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
4507 * contains N_Port IDs for other vports on this HBA, it just accepts the
4508 * RSCN and ignore processing it. If the state machine is in the recovery
4509 * state, the fc_rscn_id_list of this @vport is walked and the
4510 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
4511 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
4512 * routine is invoked to handle the RSCN event.
4515 * 0 - Just sent the acc response
4516 * 1 - Sent the acc response and waited for name server completion
4519 lpfc_els_rcv_rscn(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
4520 struct lpfc_nodelist
*ndlp
)
4522 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4523 struct lpfc_hba
*phba
= vport
->phba
;
4524 struct lpfc_dmabuf
*pcmd
;
4525 uint32_t *lp
, *datap
;
4527 uint32_t payload_len
, length
, nportid
, *cmd
;
4529 int rscn_id
= 0, hba_id
= 0;
4532 icmd
= &cmdiocb
->iocb
;
4533 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
4534 lp
= (uint32_t *) pcmd
->virt
;
4536 payload_len
= be32_to_cpu(*lp
++ & ~ELS_CMD_MASK
);
4537 payload_len
-= sizeof(uint32_t); /* take off word 0 */
4539 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
4540 "0214 RSCN received Data: x%x x%x x%x x%x\n",
4541 vport
->fc_flag
, payload_len
, *lp
,
4542 vport
->fc_rscn_id_cnt
);
4544 /* Send an RSCN event to the management application */
4545 lpfc_send_rscn_event(vport
, cmdiocb
);
4547 for (i
= 0; i
< payload_len
/sizeof(uint32_t); i
++)
4548 fc_host_post_event(shost
, fc_get_event_number(),
4549 FCH_EVT_RSCN
, lp
[i
]);
4551 /* If we are about to begin discovery, just ACC the RSCN.
4552 * Discovery processing will satisfy it.
4554 if (vport
->port_state
<= LPFC_NS_QRY
) {
4555 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
4556 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
4557 ndlp
->nlp_DID
, vport
->port_state
, ndlp
->nlp_flag
);
4559 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
4563 /* If this RSCN just contains NPortIDs for other vports on this HBA,
4564 * just ACC and ignore it.
4566 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
4567 !(vport
->cfg_peer_port_login
)) {
4572 nportid
= ((be32_to_cpu(nportid
)) & Mask_DID
);
4573 i
-= sizeof(uint32_t);
4575 if (lpfc_find_vport_by_did(phba
, nportid
))
4578 if (rscn_id
== hba_id
) {
4579 /* ALL NPortIDs in RSCN are on HBA */
4580 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
4582 "Data: x%x x%x x%x x%x\n",
4583 vport
->fc_flag
, payload_len
,
4584 *lp
, vport
->fc_rscn_id_cnt
);
4585 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
4586 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
4587 ndlp
->nlp_DID
, vport
->port_state
,
4590 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
,
4596 spin_lock_irq(shost
->host_lock
);
4597 if (vport
->fc_rscn_flush
) {
4598 /* Another thread is walking fc_rscn_id_list on this vport */
4599 vport
->fc_flag
|= FC_RSCN_DISCOVERY
;
4600 spin_unlock_irq(shost
->host_lock
);
4602 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
4605 /* Indicate we are walking fc_rscn_id_list on this vport */
4606 vport
->fc_rscn_flush
= 1;
4607 spin_unlock_irq(shost
->host_lock
);
4608 /* Get the array count after successfully have the token */
4609 rscn_cnt
= vport
->fc_rscn_id_cnt
;
4610 /* If we are already processing an RSCN, save the received
4611 * RSCN payload buffer, cmdiocb->context2 to process later.
4613 if (vport
->fc_flag
& (FC_RSCN_MODE
| FC_NDISC_ACTIVE
)) {
4614 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
4615 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
4616 ndlp
->nlp_DID
, vport
->port_state
, ndlp
->nlp_flag
);
4618 spin_lock_irq(shost
->host_lock
);
4619 vport
->fc_flag
|= FC_RSCN_DEFERRED
;
4620 if ((rscn_cnt
< FC_MAX_HOLD_RSCN
) &&
4621 !(vport
->fc_flag
& FC_RSCN_DISCOVERY
)) {
4622 vport
->fc_flag
|= FC_RSCN_MODE
;
4623 spin_unlock_irq(shost
->host_lock
);
4625 cmd
= vport
->fc_rscn_id_list
[rscn_cnt
-1]->virt
;
4626 length
= be32_to_cpu(*cmd
& ~ELS_CMD_MASK
);
4629 (payload_len
+ length
<= LPFC_BPL_SIZE
)) {
4630 *cmd
&= ELS_CMD_MASK
;
4631 *cmd
|= cpu_to_be32(payload_len
+ length
);
4632 memcpy(((uint8_t *)cmd
) + length
, lp
,
4635 vport
->fc_rscn_id_list
[rscn_cnt
] = pcmd
;
4636 vport
->fc_rscn_id_cnt
++;
4637 /* If we zero, cmdiocb->context2, the calling
4638 * routine will not try to free it.
4640 cmdiocb
->context2
= NULL
;
4643 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
4644 "0235 Deferred RSCN "
4645 "Data: x%x x%x x%x\n",
4646 vport
->fc_rscn_id_cnt
, vport
->fc_flag
,
4649 vport
->fc_flag
|= FC_RSCN_DISCOVERY
;
4650 spin_unlock_irq(shost
->host_lock
);
4651 /* ReDiscovery RSCN */
4652 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
4653 "0234 ReDiscovery RSCN "
4654 "Data: x%x x%x x%x\n",
4655 vport
->fc_rscn_id_cnt
, vport
->fc_flag
,
4658 /* Indicate we are done walking fc_rscn_id_list on this vport */
4659 vport
->fc_rscn_flush
= 0;
4661 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
4662 /* send RECOVERY event for ALL nodes that match RSCN payload */
4663 lpfc_rscn_recovery_check(vport
);
4664 spin_lock_irq(shost
->host_lock
);
4665 vport
->fc_flag
&= ~FC_RSCN_DEFERRED
;
4666 spin_unlock_irq(shost
->host_lock
);
4669 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
4670 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
4671 ndlp
->nlp_DID
, vport
->port_state
, ndlp
->nlp_flag
);
4673 spin_lock_irq(shost
->host_lock
);
4674 vport
->fc_flag
|= FC_RSCN_MODE
;
4675 spin_unlock_irq(shost
->host_lock
);
4676 vport
->fc_rscn_id_list
[vport
->fc_rscn_id_cnt
++] = pcmd
;
4677 /* Indicate we are done walking fc_rscn_id_list on this vport */
4678 vport
->fc_rscn_flush
= 0;
4680 * If we zero, cmdiocb->context2, the calling routine will
4681 * not try to free it.
4683 cmdiocb
->context2
= NULL
;
4684 lpfc_set_disctmo(vport
);
4686 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
4687 /* send RECOVERY event for ALL nodes that match RSCN payload */
4688 lpfc_rscn_recovery_check(vport
);
4689 return lpfc_els_handle_rscn(vport
);
4693 * lpfc_els_handle_rscn - Handle rscn for a vport
4694 * @vport: pointer to a host virtual N_Port data structure.
4696 * This routine handles the Registration State Configuration Notification
4697 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
4698 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
4699 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
4700 * NameServer shall be issued. If CT command to the NameServer fails to be
4701 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
4702 * RSCN activities with the @vport.
4705 * 0 - Cleaned up rscn on the @vport
4706 * 1 - Wait for plogi to name server before proceed
4709 lpfc_els_handle_rscn(struct lpfc_vport
*vport
)
4711 struct lpfc_nodelist
*ndlp
;
4712 struct lpfc_hba
*phba
= vport
->phba
;
4714 /* Ignore RSCN if the port is being torn down. */
4715 if (vport
->load_flag
& FC_UNLOADING
) {
4716 lpfc_els_flush_rscn(vport
);
4720 /* Start timer for RSCN processing */
4721 lpfc_set_disctmo(vport
);
4723 /* RSCN processed */
4724 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
4725 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
4726 vport
->fc_flag
, 0, vport
->fc_rscn_id_cnt
,
4729 /* To process RSCN, first compare RSCN data with NameServer */
4730 vport
->fc_ns_retry
= 0;
4731 vport
->num_disc_nodes
= 0;
4733 ndlp
= lpfc_findnode_did(vport
, NameServer_DID
);
4734 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
)
4735 && ndlp
->nlp_state
== NLP_STE_UNMAPPED_NODE
) {
4736 /* Good ndlp, issue CT Request to NameServer */
4737 if (lpfc_ns_cmd(vport
, SLI_CTNS_GID_FT
, 0, 0) == 0)
4738 /* Wait for NameServer query cmpl before we can
4742 /* If login to NameServer does not exist, issue one */
4743 /* Good status, issue PLOGI to NameServer */
4744 ndlp
= lpfc_findnode_did(vport
, NameServer_DID
);
4745 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
))
4746 /* Wait for NameServer login cmpl before we can
4751 ndlp
= lpfc_enable_node(vport
, ndlp
,
4752 NLP_STE_PLOGI_ISSUE
);
4754 lpfc_els_flush_rscn(vport
);
4757 ndlp
->nlp_prev_state
= NLP_STE_UNUSED_NODE
;
4759 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
4761 lpfc_els_flush_rscn(vport
);
4764 lpfc_nlp_init(vport
, ndlp
, NameServer_DID
);
4765 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
4766 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
4768 ndlp
->nlp_type
|= NLP_FABRIC
;
4769 lpfc_issue_els_plogi(vport
, NameServer_DID
, 0);
4770 /* Wait for NameServer login cmpl before we can
4776 lpfc_els_flush_rscn(vport
);
4781 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
4782 * @vport: pointer to a host virtual N_Port data structure.
4783 * @cmdiocb: pointer to lpfc command iocb data structure.
4784 * @ndlp: pointer to a node-list data structure.
4786 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
4787 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
4788 * point topology. As an unsolicited FLOGI should not be received in a loop
4789 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
4790 * lpfc_check_sparm() routine is invoked to check the parameters in the
4791 * unsolicited FLOGI. If parameters validation failed, the routine
4792 * lpfc_els_rsp_reject() shall be called with reject reason code set to
4793 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
4794 * FLOGI shall be compared with the Port WWN of the @vport to determine who
4795 * will initiate PLOGI. The higher lexicographical value party shall has
4796 * higher priority (as the winning port) and will initiate PLOGI and
4797 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
4798 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
4799 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
4802 * 0 - Successfully processed the unsolicited flogi
4803 * 1 - Failed to process the unsolicited flogi
4806 lpfc_els_rcv_flogi(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
4807 struct lpfc_nodelist
*ndlp
)
4809 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4810 struct lpfc_hba
*phba
= vport
->phba
;
4811 struct lpfc_dmabuf
*pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
4812 uint32_t *lp
= (uint32_t *) pcmd
->virt
;
4813 IOCB_t
*icmd
= &cmdiocb
->iocb
;
4814 struct serv_parm
*sp
;
4821 sp
= (struct serv_parm
*) lp
;
4823 /* FLOGI received */
4825 lpfc_set_disctmo(vport
);
4827 if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) {
4828 /* We should never receive a FLOGI in loop mode, ignore it */
4829 did
= icmd
->un
.elsreq64
.remoteID
;
4831 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
4833 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
4834 "0113 An FLOGI ELS command x%x was "
4835 "received from DID x%x in Loop Mode\n",
4842 if ((lpfc_check_sparm(vport
, ndlp
, sp
, CLASS3
, 1))) {
4843 /* For a FLOGI we accept, then if our portname is greater
4844 * then the remote portname we initiate Nport login.
4847 rc
= memcmp(&vport
->fc_portname
, &sp
->portName
,
4848 sizeof(struct lpfc_name
));
4851 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4855 lpfc_linkdown(phba
);
4856 lpfc_init_link(phba
, mbox
,
4858 phba
->cfg_link_speed
);
4859 mbox
->u
.mb
.un
.varInitLnk
.lipsr_AL_PA
= 0;
4860 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
4861 mbox
->vport
= vport
;
4862 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
);
4863 lpfc_set_loopback_flag(phba
);
4864 if (rc
== MBX_NOT_FINISHED
) {
4865 mempool_free(mbox
, phba
->mbox_mem_pool
);
4868 } else if (rc
> 0) { /* greater than */
4869 spin_lock_irq(shost
->host_lock
);
4870 vport
->fc_flag
|= FC_PT2PT_PLOGI
;
4871 spin_unlock_irq(shost
->host_lock
);
4873 spin_lock_irq(shost
->host_lock
);
4874 vport
->fc_flag
|= FC_PT2PT
;
4875 vport
->fc_flag
&= ~(FC_FABRIC
| FC_PUBLIC_LOOP
);
4876 spin_unlock_irq(shost
->host_lock
);
4878 /* Reject this request because invalid parameters */
4879 stat
.un
.b
.lsRjtRsvd0
= 0;
4880 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
4881 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_SPARM_OPTIONS
;
4882 stat
.un
.b
.vendorUnique
= 0;
4883 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
,
4889 lpfc_els_rsp_acc(vport
, ELS_CMD_PLOGI
, cmdiocb
, ndlp
, NULL
);
4895 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
4896 * @vport: pointer to a host virtual N_Port data structure.
4897 * @cmdiocb: pointer to lpfc command iocb data structure.
4898 * @ndlp: pointer to a node-list data structure.
4900 * This routine processes Request Node Identification Data (RNID) IOCB
4901 * received as an ELS unsolicited event. Only when the RNID specified format
4902 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
4903 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
4904 * Accept (ACC) the RNID ELS command. All the other RNID formats are
4905 * rejected by invoking the lpfc_els_rsp_reject() routine.
4908 * 0 - Successfully processed rnid iocb (currently always return 0)
4911 lpfc_els_rcv_rnid(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
4912 struct lpfc_nodelist
*ndlp
)
4914 struct lpfc_dmabuf
*pcmd
;
4921 icmd
= &cmdiocb
->iocb
;
4922 did
= icmd
->un
.elsreq64
.remoteID
;
4923 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
4924 lp
= (uint32_t *) pcmd
->virt
;
4931 switch (rn
->Format
) {
4933 case RNID_TOPOLOGY_DISC
:
4935 lpfc_els_rsp_rnid_acc(vport
, rn
->Format
, cmdiocb
, ndlp
);
4938 /* Reject this request because format not supported */
4939 stat
.un
.b
.lsRjtRsvd0
= 0;
4940 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
4941 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CANT_GIVE_DATA
;
4942 stat
.un
.b
.vendorUnique
= 0;
4943 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
,
4950 * lpfc_els_rcv_echo - Process an unsolicited echo iocb
4951 * @vport: pointer to a host virtual N_Port data structure.
4952 * @cmdiocb: pointer to lpfc command iocb data structure.
4953 * @ndlp: pointer to a node-list data structure.
4956 * 0 - Successfully processed echo iocb (currently always return 0)
4959 lpfc_els_rcv_echo(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
4960 struct lpfc_nodelist
*ndlp
)
4964 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) cmdiocb
->context2
)->virt
);
4966 /* skip over first word of echo command to find echo data */
4967 pcmd
+= sizeof(uint32_t);
4969 lpfc_els_rsp_echo_acc(vport
, pcmd
, cmdiocb
, ndlp
);
4974 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
4975 * @vport: pointer to a host virtual N_Port data structure.
4976 * @cmdiocb: pointer to lpfc command iocb data structure.
4977 * @ndlp: pointer to a node-list data structure.
4979 * This routine processes a Link Incident Report Registration(LIRR) IOCB
4980 * received as an ELS unsolicited event. Currently, this function just invokes
4981 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
4984 * 0 - Successfully processed lirr iocb (currently always return 0)
4987 lpfc_els_rcv_lirr(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
4988 struct lpfc_nodelist
*ndlp
)
4992 /* For now, unconditionally reject this command */
4993 stat
.un
.b
.lsRjtRsvd0
= 0;
4994 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
4995 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CANT_GIVE_DATA
;
4996 stat
.un
.b
.vendorUnique
= 0;
4997 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
5002 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
5003 * @vport: pointer to a host virtual N_Port data structure.
5004 * @cmdiocb: pointer to lpfc command iocb data structure.
5005 * @ndlp: pointer to a node-list data structure.
5007 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
5008 * received as an ELS unsolicited event. A request to RRQ shall only
5009 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
5010 * Nx_Port N_Port_ID of the target Exchange is the same as the
5011 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
5012 * not accepted, an LS_RJT with reason code "Unable to perform
5013 * command request" and reason code explanation "Invalid Originator
5014 * S_ID" shall be returned. For now, we just unconditionally accept
5015 * RRQ from the target.
5018 lpfc_els_rcv_rrq(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
5019 struct lpfc_nodelist
*ndlp
)
5021 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
5022 if (vport
->phba
->sli_rev
== LPFC_SLI_REV4
)
5023 lpfc_els_clear_rrq(vport
, cmdiocb
, ndlp
);
5027 * lpfc_els_rsp_rls_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
5028 * @phba: pointer to lpfc hba data structure.
5029 * @pmb: pointer to the driver internal queue element for mailbox command.
5031 * This routine is the completion callback function for the MBX_READ_LNK_STAT
5032 * mailbox command. This callback function is to actually send the Accept
5033 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
5034 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
5035 * mailbox command, constructs the RPS response with the link statistics
5036 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
5037 * response to the RPS.
5039 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5040 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5041 * will be stored into the context1 field of the IOCB for the completion
5042 * callback function to the RPS Accept Response ELS IOCB command.
5046 lpfc_els_rsp_rls_acc(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
5050 struct RLS_RSP
*rls_rsp
;
5052 struct lpfc_iocbq
*elsiocb
;
5053 struct lpfc_nodelist
*ndlp
;
5059 ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
5060 xri
= (uint16_t) ((unsigned long)(pmb
->context1
));
5061 pmb
->context1
= NULL
;
5062 pmb
->context2
= NULL
;
5064 if (mb
->mbxStatus
) {
5065 mempool_free(pmb
, phba
->mbox_mem_pool
);
5069 cmdsize
= sizeof(struct RLS_RSP
) + sizeof(uint32_t);
5070 mempool_free(pmb
, phba
->mbox_mem_pool
);
5071 elsiocb
= lpfc_prep_els_iocb(phba
->pport
, 0, cmdsize
,
5072 lpfc_max_els_tries
, ndlp
,
5073 ndlp
->nlp_DID
, ELS_CMD_ACC
);
5075 /* Decrement the ndlp reference count from previous mbox command */
5081 icmd
= &elsiocb
->iocb
;
5082 icmd
->ulpContext
= xri
;
5084 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
5085 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
5086 pcmd
+= sizeof(uint32_t); /* Skip past command */
5087 rls_rsp
= (struct RLS_RSP
*)pcmd
;
5089 rls_rsp
->linkFailureCnt
= cpu_to_be32(mb
->un
.varRdLnk
.linkFailureCnt
);
5090 rls_rsp
->lossSyncCnt
= cpu_to_be32(mb
->un
.varRdLnk
.lossSyncCnt
);
5091 rls_rsp
->lossSignalCnt
= cpu_to_be32(mb
->un
.varRdLnk
.lossSignalCnt
);
5092 rls_rsp
->primSeqErrCnt
= cpu_to_be32(mb
->un
.varRdLnk
.primSeqErrCnt
);
5093 rls_rsp
->invalidXmitWord
= cpu_to_be32(mb
->un
.varRdLnk
.invalidXmitWord
);
5094 rls_rsp
->crcCnt
= cpu_to_be32(mb
->un
.varRdLnk
.crcCnt
);
5096 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
5097 lpfc_printf_vlog(ndlp
->vport
, KERN_INFO
, LOG_ELS
,
5098 "2874 Xmit ELS RLS ACC response tag x%x xri x%x, "
5099 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
5100 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
5101 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
5103 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
5104 phba
->fc_stat
.elsXmitACC
++;
5105 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) == IOCB_ERROR
)
5106 lpfc_els_free_iocb(phba
, elsiocb
);
5110 * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
5111 * @phba: pointer to lpfc hba data structure.
5112 * @pmb: pointer to the driver internal queue element for mailbox command.
5114 * This routine is the completion callback function for the MBX_READ_LNK_STAT
5115 * mailbox command. This callback function is to actually send the Accept
5116 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
5117 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
5118 * mailbox command, constructs the RPS response with the link statistics
5119 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
5120 * response to the RPS.
5122 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5123 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5124 * will be stored into the context1 field of the IOCB for the completion
5125 * callback function to the RPS Accept Response ELS IOCB command.
5129 lpfc_els_rsp_rps_acc(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
5135 struct lpfc_iocbq
*elsiocb
;
5136 struct lpfc_nodelist
*ndlp
;
5137 uint16_t xri
, status
;
5142 ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
5143 xri
= (uint16_t) ((unsigned long)(pmb
->context1
));
5144 pmb
->context1
= NULL
;
5145 pmb
->context2
= NULL
;
5147 if (mb
->mbxStatus
) {
5148 mempool_free(pmb
, phba
->mbox_mem_pool
);
5152 cmdsize
= sizeof(RPS_RSP
) + sizeof(uint32_t);
5153 mempool_free(pmb
, phba
->mbox_mem_pool
);
5154 elsiocb
= lpfc_prep_els_iocb(phba
->pport
, 0, cmdsize
,
5155 lpfc_max_els_tries
, ndlp
,
5156 ndlp
->nlp_DID
, ELS_CMD_ACC
);
5158 /* Decrement the ndlp reference count from previous mbox command */
5164 icmd
= &elsiocb
->iocb
;
5165 icmd
->ulpContext
= xri
;
5167 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
5168 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
5169 pcmd
+= sizeof(uint32_t); /* Skip past command */
5170 rps_rsp
= (RPS_RSP
*)pcmd
;
5172 if (phba
->fc_topology
!= LPFC_TOPOLOGY_LOOP
)
5176 if (phba
->pport
->fc_flag
& FC_FABRIC
)
5180 rps_rsp
->portStatus
= cpu_to_be16(status
);
5181 rps_rsp
->linkFailureCnt
= cpu_to_be32(mb
->un
.varRdLnk
.linkFailureCnt
);
5182 rps_rsp
->lossSyncCnt
= cpu_to_be32(mb
->un
.varRdLnk
.lossSyncCnt
);
5183 rps_rsp
->lossSignalCnt
= cpu_to_be32(mb
->un
.varRdLnk
.lossSignalCnt
);
5184 rps_rsp
->primSeqErrCnt
= cpu_to_be32(mb
->un
.varRdLnk
.primSeqErrCnt
);
5185 rps_rsp
->invalidXmitWord
= cpu_to_be32(mb
->un
.varRdLnk
.invalidXmitWord
);
5186 rps_rsp
->crcCnt
= cpu_to_be32(mb
->un
.varRdLnk
.crcCnt
);
5187 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
5188 lpfc_printf_vlog(ndlp
->vport
, KERN_INFO
, LOG_ELS
,
5189 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
5190 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
5191 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
5192 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
5194 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
5195 phba
->fc_stat
.elsXmitACC
++;
5196 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) == IOCB_ERROR
)
5197 lpfc_els_free_iocb(phba
, elsiocb
);
5202 * lpfc_els_rcv_rls - Process an unsolicited rls iocb
5203 * @vport: pointer to a host virtual N_Port data structure.
5204 * @cmdiocb: pointer to lpfc command iocb data structure.
5205 * @ndlp: pointer to a node-list data structure.
5207 * This routine processes Read Port Status (RPL) IOCB received as an
5208 * ELS unsolicited event. It first checks the remote port state. If the
5209 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5210 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
5211 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
5212 * for reading the HBA link statistics. It is for the callback function,
5213 * lpfc_els_rsp_rls_acc(), set to the MBX_READ_LNK_STAT mailbox command
5214 * to actually sending out RPL Accept (ACC) response.
5217 * 0 - Successfully processed rls iocb (currently always return 0)
5220 lpfc_els_rcv_rls(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
5221 struct lpfc_nodelist
*ndlp
)
5223 struct lpfc_hba
*phba
= vport
->phba
;
5225 struct lpfc_dmabuf
*pcmd
;
5228 if ((ndlp
->nlp_state
!= NLP_STE_UNMAPPED_NODE
) &&
5229 (ndlp
->nlp_state
!= NLP_STE_MAPPED_NODE
))
5230 /* reject the unsolicited RPS request and done with it */
5233 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
5235 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_ATOMIC
);
5237 lpfc_read_lnk_stat(phba
, mbox
);
5239 (void *)((unsigned long) cmdiocb
->iocb
.ulpContext
);
5240 mbox
->context2
= lpfc_nlp_get(ndlp
);
5241 mbox
->vport
= vport
;
5242 mbox
->mbox_cmpl
= lpfc_els_rsp_rls_acc
;
5243 if (lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
)
5244 != MBX_NOT_FINISHED
)
5245 /* Mbox completion will send ELS Response */
5247 /* Decrement reference count used for the failed mbox
5251 mempool_free(mbox
, phba
->mbox_mem_pool
);
5254 /* issue rejection response */
5255 stat
.un
.b
.lsRjtRsvd0
= 0;
5256 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
5257 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CANT_GIVE_DATA
;
5258 stat
.un
.b
.vendorUnique
= 0;
5259 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
5264 * lpfc_els_rcv_rtv - Process an unsolicited rtv iocb
5265 * @vport: pointer to a host virtual N_Port data structure.
5266 * @cmdiocb: pointer to lpfc command iocb data structure.
5267 * @ndlp: pointer to a node-list data structure.
5269 * This routine processes Read Timout Value (RTV) IOCB received as an
5270 * ELS unsolicited event. It first checks the remote port state. If the
5271 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5272 * state, it invokes the lpfc_els_rsl_reject() routine to send the reject
5273 * response. Otherwise, it sends the Accept(ACC) response to a Read Timeout
5274 * Value (RTV) unsolicited IOCB event.
5276 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5277 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5278 * will be stored into the context1 field of the IOCB for the completion
5279 * callback function to the RPS Accept Response ELS IOCB command.
5282 * 0 - Successfully processed rtv iocb (currently always return 0)
5285 lpfc_els_rcv_rtv(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
5286 struct lpfc_nodelist
*ndlp
)
5288 struct lpfc_hba
*phba
= vport
->phba
;
5290 struct RTV_RSP
*rtv_rsp
;
5292 struct lpfc_iocbq
*elsiocb
;
5296 if ((ndlp
->nlp_state
!= NLP_STE_UNMAPPED_NODE
) &&
5297 (ndlp
->nlp_state
!= NLP_STE_MAPPED_NODE
))
5298 /* reject the unsolicited RPS request and done with it */
5301 cmdsize
= sizeof(struct RTV_RSP
) + sizeof(uint32_t);
5302 elsiocb
= lpfc_prep_els_iocb(phba
->pport
, 0, cmdsize
,
5303 lpfc_max_els_tries
, ndlp
,
5304 ndlp
->nlp_DID
, ELS_CMD_ACC
);
5309 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
5310 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
5311 pcmd
+= sizeof(uint32_t); /* Skip past command */
5313 /* use the command's xri in the response */
5314 elsiocb
->iocb
.ulpContext
= cmdiocb
->iocb
.ulpContext
;
5316 rtv_rsp
= (struct RTV_RSP
*)pcmd
;
5318 /* populate RTV payload */
5319 rtv_rsp
->ratov
= cpu_to_be32(phba
->fc_ratov
* 1000); /* report msecs */
5320 rtv_rsp
->edtov
= cpu_to_be32(phba
->fc_edtov
);
5321 bf_set(qtov_edtovres
, rtv_rsp
, phba
->fc_edtovResol
? 1 : 0);
5322 bf_set(qtov_rttov
, rtv_rsp
, 0); /* Field is for FC ONLY */
5323 rtv_rsp
->qtov
= cpu_to_be32(rtv_rsp
->qtov
);
5325 /* Xmit ELS RLS ACC response tag <ulpIoTag> */
5326 lpfc_printf_vlog(ndlp
->vport
, KERN_INFO
, LOG_ELS
,
5327 "2875 Xmit ELS RTV ACC response tag x%x xri x%x, "
5328 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x, "
5329 "Data: x%x x%x x%x\n",
5330 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
5331 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
5333 rtv_rsp
->ratov
, rtv_rsp
->edtov
, rtv_rsp
->qtov
);
5334 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
5335 phba
->fc_stat
.elsXmitACC
++;
5336 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) == IOCB_ERROR
)
5337 lpfc_els_free_iocb(phba
, elsiocb
);
5341 /* issue rejection response */
5342 stat
.un
.b
.lsRjtRsvd0
= 0;
5343 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
5344 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CANT_GIVE_DATA
;
5345 stat
.un
.b
.vendorUnique
= 0;
5346 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
5350 /* lpfc_els_rcv_rps - Process an unsolicited rps iocb
5351 * @vport: pointer to a host virtual N_Port data structure.
5352 * @cmdiocb: pointer to lpfc command iocb data structure.
5353 * @ndlp: pointer to a node-list data structure.
5355 * This routine processes Read Port Status (RPS) IOCB received as an
5356 * ELS unsolicited event. It first checks the remote port state. If the
5357 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
5358 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
5359 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
5360 * for reading the HBA link statistics. It is for the callback function,
5361 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
5362 * to actually sending out RPS Accept (ACC) response.
5365 * 0 - Successfully processed rps iocb (currently always return 0)
5368 lpfc_els_rcv_rps(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
5369 struct lpfc_nodelist
*ndlp
)
5371 struct lpfc_hba
*phba
= vport
->phba
;
5375 struct lpfc_dmabuf
*pcmd
;
5379 if ((ndlp
->nlp_state
!= NLP_STE_UNMAPPED_NODE
) &&
5380 (ndlp
->nlp_state
!= NLP_STE_MAPPED_NODE
))
5381 /* reject the unsolicited RPS request and done with it */
5384 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
5385 lp
= (uint32_t *) pcmd
->virt
;
5386 flag
= (be32_to_cpu(*lp
++) & 0xf);
5390 ((flag
== 1) && (be32_to_cpu(rps
->un
.portNum
) == 0)) ||
5391 ((flag
== 2) && (memcmp(&rps
->un
.portName
, &vport
->fc_portname
,
5392 sizeof(struct lpfc_name
)) == 0))) {
5394 printk("Fix me....\n");
5396 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_ATOMIC
);
5398 lpfc_read_lnk_stat(phba
, mbox
);
5400 (void *)((unsigned long) cmdiocb
->iocb
.ulpContext
);
5401 mbox
->context2
= lpfc_nlp_get(ndlp
);
5402 mbox
->vport
= vport
;
5403 mbox
->mbox_cmpl
= lpfc_els_rsp_rps_acc
;
5404 if (lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
)
5405 != MBX_NOT_FINISHED
)
5406 /* Mbox completion will send ELS Response */
5408 /* Decrement reference count used for the failed mbox
5412 mempool_free(mbox
, phba
->mbox_mem_pool
);
5417 /* issue rejection response */
5418 stat
.un
.b
.lsRjtRsvd0
= 0;
5419 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
5420 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CANT_GIVE_DATA
;
5421 stat
.un
.b
.vendorUnique
= 0;
5422 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
5426 /* lpfc_issue_els_rrq - Process an unsolicited rps iocb
5427 * @vport: pointer to a host virtual N_Port data structure.
5428 * @ndlp: pointer to a node-list data structure.
5429 * @did: DID of the target.
5430 * @rrq: Pointer to the rrq struct.
5432 * Build a ELS RRQ command and send it to the target. If the issue_iocb is
5433 * Successful the the completion handler will clear the RRQ.
5436 * 0 - Successfully sent rrq els iocb.
5437 * 1 - Failed to send rrq els iocb.
5440 lpfc_issue_els_rrq(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
5441 uint32_t did
, struct lpfc_node_rrq
*rrq
)
5443 struct lpfc_hba
*phba
= vport
->phba
;
5444 struct RRQ
*els_rrq
;
5446 struct lpfc_iocbq
*elsiocb
;
5452 if (ndlp
!= rrq
->ndlp
)
5454 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
))
5457 /* If ndlp is not NULL, we will bump the reference count on it */
5458 cmdsize
= (sizeof(uint32_t) + sizeof(struct RRQ
));
5459 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, 0, ndlp
, did
,
5464 icmd
= &elsiocb
->iocb
;
5465 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
5467 /* For RRQ request, remainder of payload is Exchange IDs */
5468 *((uint32_t *) (pcmd
)) = ELS_CMD_RRQ
;
5469 pcmd
+= sizeof(uint32_t);
5470 els_rrq
= (struct RRQ
*) pcmd
;
5472 bf_set(rrq_oxid
, els_rrq
, rrq
->xritag
);
5473 bf_set(rrq_rxid
, els_rrq
, rrq
->rxid
);
5474 bf_set(rrq_did
, els_rrq
, vport
->fc_myDID
);
5475 els_rrq
->rrq
= cpu_to_be32(els_rrq
->rrq
);
5476 els_rrq
->rrq_exchg
= cpu_to_be32(els_rrq
->rrq_exchg
);
5479 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
5480 "Issue RRQ: did:x%x",
5481 did
, rrq
->xritag
, rrq
->rxid
);
5482 elsiocb
->context_un
.rrq
= rrq
;
5483 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rrq
;
5484 ret
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0);
5486 if (ret
== IOCB_ERROR
) {
5487 lpfc_els_free_iocb(phba
, elsiocb
);
5494 * lpfc_send_rrq - Sends ELS RRQ if needed.
5495 * @phba: pointer to lpfc hba data structure.
5496 * @rrq: pointer to the active rrq.
5498 * This routine will call the lpfc_issue_els_rrq if the rrq is
5499 * still active for the xri. If this function returns a failure then
5500 * the caller needs to clean up the RRQ by calling lpfc_clr_active_rrq.
5502 * Returns 0 Success.
5506 lpfc_send_rrq(struct lpfc_hba
*phba
, struct lpfc_node_rrq
*rrq
)
5508 struct lpfc_nodelist
*ndlp
= lpfc_findnode_did(rrq
->vport
,
5510 if (lpfc_test_rrq_active(phba
, ndlp
, rrq
->xritag
))
5511 return lpfc_issue_els_rrq(rrq
->vport
, ndlp
,
5518 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
5519 * @vport: pointer to a host virtual N_Port data structure.
5520 * @cmdsize: size of the ELS command.
5521 * @oldiocb: pointer to the original lpfc command iocb data structure.
5522 * @ndlp: pointer to a node-list data structure.
5524 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
5525 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
5527 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5528 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5529 * will be stored into the context1 field of the IOCB for the completion
5530 * callback function to the RPL Accept Response ELS command.
5533 * 0 - Successfully issued ACC RPL ELS command
5534 * 1 - Failed to issue ACC RPL ELS command
5537 lpfc_els_rsp_rpl_acc(struct lpfc_vport
*vport
, uint16_t cmdsize
,
5538 struct lpfc_iocbq
*oldiocb
, struct lpfc_nodelist
*ndlp
)
5540 struct lpfc_hba
*phba
= vport
->phba
;
5541 IOCB_t
*icmd
, *oldcmd
;
5543 struct lpfc_iocbq
*elsiocb
;
5546 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
5547 ndlp
->nlp_DID
, ELS_CMD_ACC
);
5552 icmd
= &elsiocb
->iocb
;
5553 oldcmd
= &oldiocb
->iocb
;
5554 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri */
5556 pcmd
= (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
5557 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
5558 pcmd
+= sizeof(uint16_t);
5559 *((uint16_t *)(pcmd
)) = be16_to_cpu(cmdsize
);
5560 pcmd
+= sizeof(uint16_t);
5562 /* Setup the RPL ACC payload */
5563 rpl_rsp
.listLen
= be32_to_cpu(1);
5565 rpl_rsp
.port_num_blk
.portNum
= 0;
5566 rpl_rsp
.port_num_blk
.portID
= be32_to_cpu(vport
->fc_myDID
);
5567 memcpy(&rpl_rsp
.port_num_blk
.portName
, &vport
->fc_portname
,
5568 sizeof(struct lpfc_name
));
5569 memcpy(pcmd
, &rpl_rsp
, cmdsize
- sizeof(uint32_t));
5570 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
5571 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
5572 "0120 Xmit ELS RPL ACC response tag x%x "
5573 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
5575 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
5576 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
5578 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
5579 phba
->fc_stat
.elsXmitACC
++;
5580 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) ==
5582 lpfc_els_free_iocb(phba
, elsiocb
);
5589 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
5590 * @vport: pointer to a host virtual N_Port data structure.
5591 * @cmdiocb: pointer to lpfc command iocb data structure.
5592 * @ndlp: pointer to a node-list data structure.
5594 * This routine processes Read Port List (RPL) IOCB received as an ELS
5595 * unsolicited event. It first checks the remote port state. If the remote
5596 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
5597 * invokes the lpfc_els_rsp_reject() routine to send reject response.
5598 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
5599 * to accept the RPL.
5602 * 0 - Successfully processed rpl iocb (currently always return 0)
5605 lpfc_els_rcv_rpl(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
5606 struct lpfc_nodelist
*ndlp
)
5608 struct lpfc_dmabuf
*pcmd
;
5615 if ((ndlp
->nlp_state
!= NLP_STE_UNMAPPED_NODE
) &&
5616 (ndlp
->nlp_state
!= NLP_STE_MAPPED_NODE
)) {
5617 /* issue rejection response */
5618 stat
.un
.b
.lsRjtRsvd0
= 0;
5619 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
5620 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CANT_GIVE_DATA
;
5621 stat
.un
.b
.vendorUnique
= 0;
5622 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
,
5624 /* rejected the unsolicited RPL request and done with it */
5628 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
5629 lp
= (uint32_t *) pcmd
->virt
;
5630 rpl
= (RPL
*) (lp
+ 1);
5631 maxsize
= be32_to_cpu(rpl
->maxsize
);
5633 /* We support only one port */
5634 if ((rpl
->index
== 0) &&
5636 ((maxsize
* sizeof(uint32_t)) >= sizeof(RPL_RSP
)))) {
5637 cmdsize
= sizeof(uint32_t) + sizeof(RPL_RSP
);
5639 cmdsize
= sizeof(uint32_t) + maxsize
* sizeof(uint32_t);
5641 lpfc_els_rsp_rpl_acc(vport
, cmdsize
, cmdiocb
, ndlp
);
5647 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
5648 * @vport: pointer to a virtual N_Port data structure.
5649 * @cmdiocb: pointer to lpfc command iocb data structure.
5650 * @ndlp: pointer to a node-list data structure.
5652 * This routine processes Fibre Channel Address Resolution Protocol
5653 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
5654 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
5655 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
5656 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
5657 * remote PortName is compared against the FC PortName stored in the @vport
5658 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
5659 * compared against the FC NodeName stored in the @vport data structure.
5660 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
5661 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
5662 * invoked to send out FARP Response to the remote node. Before sending the
5663 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
5664 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
5665 * routine is invoked to log into the remote port first.
5668 * 0 - Either the FARP Match Mode not supported or successfully processed
5671 lpfc_els_rcv_farp(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
5672 struct lpfc_nodelist
*ndlp
)
5674 struct lpfc_dmabuf
*pcmd
;
5678 uint32_t cmd
, cnt
, did
;
5680 icmd
= &cmdiocb
->iocb
;
5681 did
= icmd
->un
.elsreq64
.remoteID
;
5682 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
5683 lp
= (uint32_t *) pcmd
->virt
;
5687 /* FARP-REQ received from DID <did> */
5688 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
5689 "0601 FARP-REQ received from DID x%x\n", did
);
5690 /* We will only support match on WWPN or WWNN */
5691 if (fp
->Mflags
& ~(FARP_MATCH_NODE
| FARP_MATCH_PORT
)) {
5696 /* If this FARP command is searching for my portname */
5697 if (fp
->Mflags
& FARP_MATCH_PORT
) {
5698 if (memcmp(&fp
->RportName
, &vport
->fc_portname
,
5699 sizeof(struct lpfc_name
)) == 0)
5703 /* If this FARP command is searching for my nodename */
5704 if (fp
->Mflags
& FARP_MATCH_NODE
) {
5705 if (memcmp(&fp
->RnodeName
, &vport
->fc_nodename
,
5706 sizeof(struct lpfc_name
)) == 0)
5711 if ((ndlp
->nlp_state
== NLP_STE_UNMAPPED_NODE
) ||
5712 (ndlp
->nlp_state
== NLP_STE_MAPPED_NODE
)) {
5713 /* Log back into the node before sending the FARP. */
5714 if (fp
->Rflags
& FARP_REQUEST_PLOGI
) {
5715 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
5716 lpfc_nlp_set_state(vport
, ndlp
,
5717 NLP_STE_PLOGI_ISSUE
);
5718 lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0);
5721 /* Send a FARP response to that node */
5722 if (fp
->Rflags
& FARP_REQUEST_FARPR
)
5723 lpfc_issue_els_farpr(vport
, did
, 0);
5730 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
5731 * @vport: pointer to a host virtual N_Port data structure.
5732 * @cmdiocb: pointer to lpfc command iocb data structure.
5733 * @ndlp: pointer to a node-list data structure.
5735 * This routine processes Fibre Channel Address Resolution Protocol
5736 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
5737 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
5738 * the FARP response request.
5741 * 0 - Successfully processed FARPR IOCB (currently always return 0)
5744 lpfc_els_rcv_farpr(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
5745 struct lpfc_nodelist
*ndlp
)
5747 struct lpfc_dmabuf
*pcmd
;
5752 icmd
= &cmdiocb
->iocb
;
5753 did
= icmd
->un
.elsreq64
.remoteID
;
5754 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
5755 lp
= (uint32_t *) pcmd
->virt
;
5758 /* FARP-RSP received from DID <did> */
5759 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
5760 "0600 FARP-RSP received from DID x%x\n", did
);
5761 /* ACCEPT the Farp resp request */
5762 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
5768 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
5769 * @vport: pointer to a host virtual N_Port data structure.
5770 * @cmdiocb: pointer to lpfc command iocb data structure.
5771 * @fan_ndlp: pointer to a node-list data structure.
5773 * This routine processes a Fabric Address Notification (FAN) IOCB
5774 * command received as an ELS unsolicited event. The FAN ELS command will
5775 * only be processed on a physical port (i.e., the @vport represents the
5776 * physical port). The fabric NodeName and PortName from the FAN IOCB are
5777 * compared against those in the phba data structure. If any of those is
5778 * different, the lpfc_initial_flogi() routine is invoked to initialize
5779 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
5780 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
5781 * is invoked to register login to the fabric.
5784 * 0 - Successfully processed fan iocb (currently always return 0).
5787 lpfc_els_rcv_fan(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
5788 struct lpfc_nodelist
*fan_ndlp
)
5790 struct lpfc_hba
*phba
= vport
->phba
;
5794 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
, "0265 FAN received\n");
5795 lp
= (uint32_t *)((struct lpfc_dmabuf
*)cmdiocb
->context2
)->virt
;
5797 /* FAN received; Fan does not have a reply sequence */
5798 if ((vport
== phba
->pport
) &&
5799 (vport
->port_state
== LPFC_LOCAL_CFG_LINK
)) {
5800 if ((memcmp(&phba
->fc_fabparam
.nodeName
, &fp
->FnodeName
,
5801 sizeof(struct lpfc_name
))) ||
5802 (memcmp(&phba
->fc_fabparam
.portName
, &fp
->FportName
,
5803 sizeof(struct lpfc_name
)))) {
5804 /* This port has switched fabrics. FLOGI is required */
5805 lpfc_issue_init_vfi(vport
);
5807 /* FAN verified - skip FLOGI */
5808 vport
->fc_myDID
= vport
->fc_prevDID
;
5809 if (phba
->sli_rev
< LPFC_SLI_REV4
)
5810 lpfc_issue_fabric_reglogin(vport
);
5812 lpfc_issue_reg_vfi(vport
);
5819 * lpfc_els_timeout - Handler funciton to the els timer
5820 * @ptr: holder for the timer function associated data.
5822 * This routine is invoked by the ELS timer after timeout. It posts the ELS
5823 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
5824 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
5825 * up the worker thread. It is for the worker thread to invoke the routine
5826 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
5829 lpfc_els_timeout(unsigned long ptr
)
5831 struct lpfc_vport
*vport
= (struct lpfc_vport
*) ptr
;
5832 struct lpfc_hba
*phba
= vport
->phba
;
5833 uint32_t tmo_posted
;
5834 unsigned long iflag
;
5836 spin_lock_irqsave(&vport
->work_port_lock
, iflag
);
5837 tmo_posted
= vport
->work_port_events
& WORKER_ELS_TMO
;
5839 vport
->work_port_events
|= WORKER_ELS_TMO
;
5840 spin_unlock_irqrestore(&vport
->work_port_lock
, iflag
);
5843 lpfc_worker_wake_up(phba
);
5849 * lpfc_els_timeout_handler - Process an els timeout event
5850 * @vport: pointer to a virtual N_Port data structure.
5852 * This routine is the actual handler function that processes an ELS timeout
5853 * event. It walks the ELS ring to get and abort all the IOCBs (except the
5854 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
5855 * invoking the lpfc_sli_issue_abort_iotag() routine.
5858 lpfc_els_timeout_handler(struct lpfc_vport
*vport
)
5860 struct lpfc_hba
*phba
= vport
->phba
;
5861 struct lpfc_sli_ring
*pring
;
5862 struct lpfc_iocbq
*tmp_iocb
, *piocb
;
5864 struct lpfc_dmabuf
*pcmd
;
5865 uint32_t els_command
= 0;
5867 uint32_t remote_ID
= 0xffffffff;
5868 LIST_HEAD(txcmplq_completions
);
5869 LIST_HEAD(abort_list
);
5872 timeout
= (uint32_t)(phba
->fc_ratov
<< 1);
5874 pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
5876 spin_lock_irq(&phba
->hbalock
);
5877 list_splice_init(&pring
->txcmplq
, &txcmplq_completions
);
5878 spin_unlock_irq(&phba
->hbalock
);
5880 list_for_each_entry_safe(piocb
, tmp_iocb
, &txcmplq_completions
, list
) {
5883 if ((piocb
->iocb_flag
& LPFC_IO_LIBDFC
) != 0 ||
5884 piocb
->iocb
.ulpCommand
== CMD_ABORT_XRI_CN
||
5885 piocb
->iocb
.ulpCommand
== CMD_CLOSE_XRI_CN
)
5888 if (piocb
->vport
!= vport
)
5891 pcmd
= (struct lpfc_dmabuf
*) piocb
->context2
;
5893 els_command
= *(uint32_t *) (pcmd
->virt
);
5895 if (els_command
== ELS_CMD_FARP
||
5896 els_command
== ELS_CMD_FARPR
||
5897 els_command
== ELS_CMD_FDISC
)
5900 if (piocb
->drvrTimeout
> 0) {
5901 if (piocb
->drvrTimeout
>= timeout
)
5902 piocb
->drvrTimeout
-= timeout
;
5904 piocb
->drvrTimeout
= 0;
5908 remote_ID
= 0xffffffff;
5909 if (cmd
->ulpCommand
!= CMD_GEN_REQUEST64_CR
)
5910 remote_ID
= cmd
->un
.elsreq64
.remoteID
;
5912 struct lpfc_nodelist
*ndlp
;
5913 ndlp
= __lpfc_findnode_rpi(vport
, cmd
->ulpContext
);
5914 if (ndlp
&& NLP_CHK_NODE_ACT(ndlp
))
5915 remote_ID
= ndlp
->nlp_DID
;
5917 list_add_tail(&piocb
->dlist
, &abort_list
);
5919 spin_lock_irq(&phba
->hbalock
);
5920 list_splice(&txcmplq_completions
, &pring
->txcmplq
);
5921 spin_unlock_irq(&phba
->hbalock
);
5923 list_for_each_entry_safe(piocb
, tmp_iocb
, &abort_list
, dlist
) {
5924 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
5925 "0127 ELS timeout Data: x%x x%x x%x "
5926 "x%x\n", els_command
,
5927 remote_ID
, cmd
->ulpCommand
, cmd
->ulpIoTag
);
5928 spin_lock_irq(&phba
->hbalock
);
5929 list_del_init(&piocb
->dlist
);
5930 lpfc_sli_issue_abort_iotag(phba
, pring
, piocb
);
5931 spin_unlock_irq(&phba
->hbalock
);
5934 if (phba
->sli
.ring
[LPFC_ELS_RING
].txcmplq_cnt
)
5935 mod_timer(&vport
->els_tmofunc
, jiffies
+ HZ
* timeout
);
5939 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
5940 * @vport: pointer to a host virtual N_Port data structure.
5942 * This routine is used to clean up all the outstanding ELS commands on a
5943 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
5944 * routine. After that, it walks the ELS transmit queue to remove all the
5945 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
5946 * the IOCBs with a non-NULL completion callback function, the callback
5947 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
5948 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
5949 * callback function, the IOCB will simply be released. Finally, it walks
5950 * the ELS transmit completion queue to issue an abort IOCB to any transmit
5951 * completion queue IOCB that is associated with the @vport and is not
5952 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
5953 * part of the discovery state machine) out to HBA by invoking the
5954 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
5955 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
5956 * the IOCBs are aborted when this function returns.
5959 lpfc_els_flush_cmd(struct lpfc_vport
*vport
)
5961 LIST_HEAD(completions
);
5962 struct lpfc_hba
*phba
= vport
->phba
;
5963 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
5964 struct lpfc_iocbq
*tmp_iocb
, *piocb
;
5967 lpfc_fabric_abort_vport(vport
);
5969 spin_lock_irq(&phba
->hbalock
);
5970 list_for_each_entry_safe(piocb
, tmp_iocb
, &pring
->txq
, list
) {
5973 if (piocb
->iocb_flag
& LPFC_IO_LIBDFC
) {
5977 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
5978 if (cmd
->ulpCommand
== CMD_QUE_RING_BUF_CN
||
5979 cmd
->ulpCommand
== CMD_QUE_RING_BUF64_CN
||
5980 cmd
->ulpCommand
== CMD_CLOSE_XRI_CN
||
5981 cmd
->ulpCommand
== CMD_ABORT_XRI_CN
)
5984 if (piocb
->vport
!= vport
)
5987 list_move_tail(&piocb
->list
, &completions
);
5991 list_for_each_entry_safe(piocb
, tmp_iocb
, &pring
->txcmplq
, list
) {
5992 if (piocb
->iocb_flag
& LPFC_IO_LIBDFC
) {
5996 if (piocb
->vport
!= vport
)
5999 lpfc_sli_issue_abort_iotag(phba
, pring
, piocb
);
6001 spin_unlock_irq(&phba
->hbalock
);
6003 /* Cancell all the IOCBs from the completions list */
6004 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
6011 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
6012 * @phba: pointer to lpfc hba data structure.
6014 * This routine is used to clean up all the outstanding ELS commands on a
6015 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
6016 * routine. After that, it walks the ELS transmit queue to remove all the
6017 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
6018 * the IOCBs with the completion callback function associated, the callback
6019 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
6020 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
6021 * callback function associated, the IOCB will simply be released. Finally,
6022 * it walks the ELS transmit completion queue to issue an abort IOCB to any
6023 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
6024 * management plane IOCBs that are not part of the discovery state machine)
6025 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
6028 lpfc_els_flush_all_cmd(struct lpfc_hba
*phba
)
6030 LIST_HEAD(completions
);
6031 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
6032 struct lpfc_iocbq
*tmp_iocb
, *piocb
;
6035 lpfc_fabric_abort_hba(phba
);
6036 spin_lock_irq(&phba
->hbalock
);
6037 list_for_each_entry_safe(piocb
, tmp_iocb
, &pring
->txq
, list
) {
6039 if (piocb
->iocb_flag
& LPFC_IO_LIBDFC
)
6041 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
6042 if (cmd
->ulpCommand
== CMD_QUE_RING_BUF_CN
||
6043 cmd
->ulpCommand
== CMD_QUE_RING_BUF64_CN
||
6044 cmd
->ulpCommand
== CMD_CLOSE_XRI_CN
||
6045 cmd
->ulpCommand
== CMD_ABORT_XRI_CN
)
6047 list_move_tail(&piocb
->list
, &completions
);
6050 list_for_each_entry_safe(piocb
, tmp_iocb
, &pring
->txcmplq
, list
) {
6051 if (piocb
->iocb_flag
& LPFC_IO_LIBDFC
)
6053 lpfc_sli_issue_abort_iotag(phba
, pring
, piocb
);
6055 spin_unlock_irq(&phba
->hbalock
);
6057 /* Cancel all the IOCBs from the completions list */
6058 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
6065 * lpfc_send_els_failure_event - Posts an ELS command failure event
6066 * @phba: Pointer to hba context object.
6067 * @cmdiocbp: Pointer to command iocb which reported error.
6068 * @rspiocbp: Pointer to response iocb which reported error.
6070 * This function sends an event when there is an ELS command
6074 lpfc_send_els_failure_event(struct lpfc_hba
*phba
,
6075 struct lpfc_iocbq
*cmdiocbp
,
6076 struct lpfc_iocbq
*rspiocbp
)
6078 struct lpfc_vport
*vport
= cmdiocbp
->vport
;
6079 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
6080 struct lpfc_lsrjt_event lsrjt_event
;
6081 struct lpfc_fabric_event_header fabric_event
;
6083 struct lpfc_nodelist
*ndlp
;
6086 ndlp
= cmdiocbp
->context1
;
6087 if (!ndlp
|| !NLP_CHK_NODE_ACT(ndlp
))
6090 if (rspiocbp
->iocb
.ulpStatus
== IOSTAT_LS_RJT
) {
6091 lsrjt_event
.header
.event_type
= FC_REG_ELS_EVENT
;
6092 lsrjt_event
.header
.subcategory
= LPFC_EVENT_LSRJT_RCV
;
6093 memcpy(lsrjt_event
.header
.wwpn
, &ndlp
->nlp_portname
,
6094 sizeof(struct lpfc_name
));
6095 memcpy(lsrjt_event
.header
.wwnn
, &ndlp
->nlp_nodename
,
6096 sizeof(struct lpfc_name
));
6097 pcmd
= (uint32_t *) (((struct lpfc_dmabuf
*)
6098 cmdiocbp
->context2
)->virt
);
6099 lsrjt_event
.command
= (pcmd
!= NULL
) ? *pcmd
: 0;
6100 stat
.un
.lsRjtError
= be32_to_cpu(rspiocbp
->iocb
.un
.ulpWord
[4]);
6101 lsrjt_event
.reason_code
= stat
.un
.b
.lsRjtRsnCode
;
6102 lsrjt_event
.explanation
= stat
.un
.b
.lsRjtRsnCodeExp
;
6103 fc_host_post_vendor_event(shost
,
6104 fc_get_event_number(),
6105 sizeof(lsrjt_event
),
6106 (char *)&lsrjt_event
,
6110 if ((rspiocbp
->iocb
.ulpStatus
== IOSTAT_NPORT_BSY
) ||
6111 (rspiocbp
->iocb
.ulpStatus
== IOSTAT_FABRIC_BSY
)) {
6112 fabric_event
.event_type
= FC_REG_FABRIC_EVENT
;
6113 if (rspiocbp
->iocb
.ulpStatus
== IOSTAT_NPORT_BSY
)
6114 fabric_event
.subcategory
= LPFC_EVENT_PORT_BUSY
;
6116 fabric_event
.subcategory
= LPFC_EVENT_FABRIC_BUSY
;
6117 memcpy(fabric_event
.wwpn
, &ndlp
->nlp_portname
,
6118 sizeof(struct lpfc_name
));
6119 memcpy(fabric_event
.wwnn
, &ndlp
->nlp_nodename
,
6120 sizeof(struct lpfc_name
));
6121 fc_host_post_vendor_event(shost
,
6122 fc_get_event_number(),
6123 sizeof(fabric_event
),
6124 (char *)&fabric_event
,
6132 * lpfc_send_els_event - Posts unsolicited els event
6133 * @vport: Pointer to vport object.
6134 * @ndlp: Pointer FC node object.
6135 * @cmd: ELS command code.
6137 * This function posts an event when there is an incoming
6138 * unsolicited ELS command.
6141 lpfc_send_els_event(struct lpfc_vport
*vport
,
6142 struct lpfc_nodelist
*ndlp
,
6145 struct lpfc_els_event_header
*els_data
= NULL
;
6146 struct lpfc_logo_event
*logo_data
= NULL
;
6147 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
6149 if (*payload
== ELS_CMD_LOGO
) {
6150 logo_data
= kmalloc(sizeof(struct lpfc_logo_event
), GFP_KERNEL
);
6152 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
6153 "0148 Failed to allocate memory "
6154 "for LOGO event\n");
6157 els_data
= &logo_data
->header
;
6159 els_data
= kmalloc(sizeof(struct lpfc_els_event_header
),
6162 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
6163 "0149 Failed to allocate memory "
6168 els_data
->event_type
= FC_REG_ELS_EVENT
;
6171 els_data
->subcategory
= LPFC_EVENT_PLOGI_RCV
;
6174 els_data
->subcategory
= LPFC_EVENT_PRLO_RCV
;
6177 els_data
->subcategory
= LPFC_EVENT_ADISC_RCV
;
6180 els_data
->subcategory
= LPFC_EVENT_LOGO_RCV
;
6181 /* Copy the WWPN in the LOGO payload */
6182 memcpy(logo_data
->logo_wwpn
, &payload
[2],
6183 sizeof(struct lpfc_name
));
6189 memcpy(els_data
->wwpn
, &ndlp
->nlp_portname
, sizeof(struct lpfc_name
));
6190 memcpy(els_data
->wwnn
, &ndlp
->nlp_nodename
, sizeof(struct lpfc_name
));
6191 if (*payload
== ELS_CMD_LOGO
) {
6192 fc_host_post_vendor_event(shost
,
6193 fc_get_event_number(),
6194 sizeof(struct lpfc_logo_event
),
6199 fc_host_post_vendor_event(shost
,
6200 fc_get_event_number(),
6201 sizeof(struct lpfc_els_event_header
),
6212 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
6213 * @phba: pointer to lpfc hba data structure.
6214 * @pring: pointer to a SLI ring.
6215 * @vport: pointer to a host virtual N_Port data structure.
6216 * @elsiocb: pointer to lpfc els command iocb data structure.
6218 * This routine is used for processing the IOCB associated with a unsolicited
6219 * event. It first determines whether there is an existing ndlp that matches
6220 * the DID from the unsolicited IOCB. If not, it will create a new one with
6221 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
6222 * IOCB is then used to invoke the proper routine and to set up proper state
6223 * of the discovery state machine.
6226 lpfc_els_unsol_buffer(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
6227 struct lpfc_vport
*vport
, struct lpfc_iocbq
*elsiocb
)
6229 struct Scsi_Host
*shost
;
6230 struct lpfc_nodelist
*ndlp
;
6233 uint32_t cmd
, did
, newnode
, rjt_err
= 0;
6234 IOCB_t
*icmd
= &elsiocb
->iocb
;
6236 if (!vport
|| !(elsiocb
->context2
))
6240 payload
= ((struct lpfc_dmabuf
*)elsiocb
->context2
)->virt
;
6242 if ((phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) == 0)
6243 lpfc_post_buffer(phba
, pring
, 1);
6245 did
= icmd
->un
.rcvels
.remoteID
;
6246 if (icmd
->ulpStatus
) {
6247 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6248 "RCV Unsol ELS: status:x%x/x%x did:x%x",
6249 icmd
->ulpStatus
, icmd
->un
.ulpWord
[4], did
);
6253 /* Check to see if link went down during discovery */
6254 if (lpfc_els_chk_latt(vport
))
6257 /* Ignore traffic received during vport shutdown. */
6258 if (vport
->load_flag
& FC_UNLOADING
)
6261 /* If NPort discovery is delayed drop incoming ELS */
6262 if ((vport
->fc_flag
& FC_DISC_DELAYED
) &&
6263 (cmd
!= ELS_CMD_PLOGI
))
6266 ndlp
= lpfc_findnode_did(vport
, did
);
6268 /* Cannot find existing Fabric ndlp, so allocate a new one */
6269 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
6273 lpfc_nlp_init(vport
, ndlp
, did
);
6274 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
6276 if ((did
& Fabric_DID_MASK
) == Fabric_DID_MASK
)
6277 ndlp
->nlp_type
|= NLP_FABRIC
;
6278 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
6279 ndlp
= lpfc_enable_node(vport
, ndlp
,
6280 NLP_STE_UNUSED_NODE
);
6283 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
6285 if ((did
& Fabric_DID_MASK
) == Fabric_DID_MASK
)
6286 ndlp
->nlp_type
|= NLP_FABRIC
;
6287 } else if (ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
) {
6288 /* This is similar to the new node path */
6289 ndlp
= lpfc_nlp_get(ndlp
);
6292 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
6296 phba
->fc_stat
.elsRcvFrame
++;
6298 elsiocb
->context1
= lpfc_nlp_get(ndlp
);
6299 elsiocb
->vport
= vport
;
6301 if ((cmd
& ELS_CMD_MASK
) == ELS_CMD_RSCN
) {
6302 cmd
&= ELS_CMD_MASK
;
6304 /* ELS command <elsCmd> received from NPORT <did> */
6305 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
6306 "0112 ELS command x%x received from NPORT x%x "
6307 "Data: x%x\n", cmd
, did
, vport
->port_state
);
6310 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6311 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
6312 did
, vport
->port_state
, ndlp
->nlp_flag
);
6314 phba
->fc_stat
.elsRcvPLOGI
++;
6315 ndlp
= lpfc_plogi_confirm_nport(phba
, payload
, ndlp
);
6317 lpfc_send_els_event(vport
, ndlp
, payload
);
6319 /* If Nport discovery is delayed, reject PLOGIs */
6320 if (vport
->fc_flag
& FC_DISC_DELAYED
) {
6321 rjt_err
= LSRJT_UNABLE_TPC
;
6324 if (vport
->port_state
< LPFC_DISC_AUTH
) {
6325 if (!(phba
->pport
->fc_flag
& FC_PT2PT
) ||
6326 (phba
->pport
->fc_flag
& FC_PT2PT_PLOGI
)) {
6327 rjt_err
= LSRJT_UNABLE_TPC
;
6330 /* We get here, and drop thru, if we are PT2PT with
6331 * another NPort and the other side has initiated
6332 * the PLOGI before responding to our FLOGI.
6336 shost
= lpfc_shost_from_vport(vport
);
6337 spin_lock_irq(shost
->host_lock
);
6338 ndlp
->nlp_flag
&= ~NLP_TARGET_REMOVE
;
6339 spin_unlock_irq(shost
->host_lock
);
6341 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
,
6346 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6347 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
6348 did
, vport
->port_state
, ndlp
->nlp_flag
);
6350 phba
->fc_stat
.elsRcvFLOGI
++;
6351 lpfc_els_rcv_flogi(vport
, elsiocb
, ndlp
);
6356 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6357 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
6358 did
, vport
->port_state
, ndlp
->nlp_flag
);
6360 phba
->fc_stat
.elsRcvLOGO
++;
6361 lpfc_send_els_event(vport
, ndlp
, payload
);
6362 if (vport
->port_state
< LPFC_DISC_AUTH
) {
6363 rjt_err
= LSRJT_UNABLE_TPC
;
6366 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
, NLP_EVT_RCV_LOGO
);
6369 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6370 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
6371 did
, vport
->port_state
, ndlp
->nlp_flag
);
6373 phba
->fc_stat
.elsRcvPRLO
++;
6374 lpfc_send_els_event(vport
, ndlp
, payload
);
6375 if (vport
->port_state
< LPFC_DISC_AUTH
) {
6376 rjt_err
= LSRJT_UNABLE_TPC
;
6379 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
, NLP_EVT_RCV_PRLO
);
6382 phba
->fc_stat
.elsRcvRSCN
++;
6383 lpfc_els_rcv_rscn(vport
, elsiocb
, ndlp
);
6388 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6389 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
6390 did
, vport
->port_state
, ndlp
->nlp_flag
);
6392 lpfc_send_els_event(vport
, ndlp
, payload
);
6393 phba
->fc_stat
.elsRcvADISC
++;
6394 if (vport
->port_state
< LPFC_DISC_AUTH
) {
6395 rjt_err
= LSRJT_UNABLE_TPC
;
6398 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
,
6402 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6403 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
6404 did
, vport
->port_state
, ndlp
->nlp_flag
);
6406 phba
->fc_stat
.elsRcvPDISC
++;
6407 if (vport
->port_state
< LPFC_DISC_AUTH
) {
6408 rjt_err
= LSRJT_UNABLE_TPC
;
6411 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
,
6415 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6416 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
6417 did
, vport
->port_state
, ndlp
->nlp_flag
);
6419 phba
->fc_stat
.elsRcvFARPR
++;
6420 lpfc_els_rcv_farpr(vport
, elsiocb
, ndlp
);
6423 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6424 "RCV FARP: did:x%x/ste:x%x flg:x%x",
6425 did
, vport
->port_state
, ndlp
->nlp_flag
);
6427 phba
->fc_stat
.elsRcvFARP
++;
6428 lpfc_els_rcv_farp(vport
, elsiocb
, ndlp
);
6431 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6432 "RCV FAN: did:x%x/ste:x%x flg:x%x",
6433 did
, vport
->port_state
, ndlp
->nlp_flag
);
6435 phba
->fc_stat
.elsRcvFAN
++;
6436 lpfc_els_rcv_fan(vport
, elsiocb
, ndlp
);
6439 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6440 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
6441 did
, vport
->port_state
, ndlp
->nlp_flag
);
6443 phba
->fc_stat
.elsRcvPRLI
++;
6444 if (vport
->port_state
< LPFC_DISC_AUTH
) {
6445 rjt_err
= LSRJT_UNABLE_TPC
;
6448 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
, NLP_EVT_RCV_PRLI
);
6451 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6452 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
6453 did
, vport
->port_state
, ndlp
->nlp_flag
);
6455 phba
->fc_stat
.elsRcvLIRR
++;
6456 lpfc_els_rcv_lirr(vport
, elsiocb
, ndlp
);
6461 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6462 "RCV RLS: did:x%x/ste:x%x flg:x%x",
6463 did
, vport
->port_state
, ndlp
->nlp_flag
);
6465 phba
->fc_stat
.elsRcvRLS
++;
6466 lpfc_els_rcv_rls(vport
, elsiocb
, ndlp
);
6471 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6472 "RCV RPS: did:x%x/ste:x%x flg:x%x",
6473 did
, vport
->port_state
, ndlp
->nlp_flag
);
6475 phba
->fc_stat
.elsRcvRPS
++;
6476 lpfc_els_rcv_rps(vport
, elsiocb
, ndlp
);
6481 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6482 "RCV RPL: did:x%x/ste:x%x flg:x%x",
6483 did
, vport
->port_state
, ndlp
->nlp_flag
);
6485 phba
->fc_stat
.elsRcvRPL
++;
6486 lpfc_els_rcv_rpl(vport
, elsiocb
, ndlp
);
6491 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6492 "RCV RNID: did:x%x/ste:x%x flg:x%x",
6493 did
, vport
->port_state
, ndlp
->nlp_flag
);
6495 phba
->fc_stat
.elsRcvRNID
++;
6496 lpfc_els_rcv_rnid(vport
, elsiocb
, ndlp
);
6501 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6502 "RCV RTV: did:x%x/ste:x%x flg:x%x",
6503 did
, vport
->port_state
, ndlp
->nlp_flag
);
6504 phba
->fc_stat
.elsRcvRTV
++;
6505 lpfc_els_rcv_rtv(vport
, elsiocb
, ndlp
);
6510 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6511 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
6512 did
, vport
->port_state
, ndlp
->nlp_flag
);
6514 phba
->fc_stat
.elsRcvRRQ
++;
6515 lpfc_els_rcv_rrq(vport
, elsiocb
, ndlp
);
6520 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6521 "RCV ECHO: did:x%x/ste:x%x flg:x%x",
6522 did
, vport
->port_state
, ndlp
->nlp_flag
);
6524 phba
->fc_stat
.elsRcvECHO
++;
6525 lpfc_els_rcv_echo(vport
, elsiocb
, ndlp
);
6530 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
6531 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
6532 cmd
, did
, vport
->port_state
);
6534 /* Unsupported ELS command, reject */
6535 rjt_err
= LSRJT_CMD_UNSUPPORTED
;
6537 /* Unknown ELS command <elsCmd> received from NPORT <did> */
6538 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
6539 "0115 Unknown ELS command x%x "
6540 "received from NPORT x%x\n", cmd
, did
);
6546 /* check if need to LS_RJT received ELS cmd */
6548 memset(&stat
, 0, sizeof(stat
));
6549 stat
.un
.b
.lsRjtRsnCode
= rjt_err
;
6550 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_NOTHING_MORE
;
6551 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, elsiocb
, ndlp
,
6555 lpfc_nlp_put(elsiocb
->context1
);
6556 elsiocb
->context1
= NULL
;
6560 if (vport
&& !(vport
->load_flag
& FC_UNLOADING
))
6561 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
6562 "0111 Dropping received ELS cmd "
6563 "Data: x%x x%x x%x\n",
6564 icmd
->ulpStatus
, icmd
->un
.ulpWord
[4], icmd
->ulpTimeout
);
6565 phba
->fc_stat
.elsRcvDrop
++;
6569 * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier
6570 * @phba: pointer to lpfc hba data structure.
6571 * @vpi: host virtual N_Port identifier.
6573 * This routine finds a vport on a HBA (referred by @phba) through a
6574 * @vpi. The function walks the HBA's vport list and returns the address
6575 * of the vport with the matching @vpi.
6578 * NULL - No vport with the matching @vpi found
6579 * Otherwise - Address to the vport with the matching @vpi.
6582 lpfc_find_vport_by_vpid(struct lpfc_hba
*phba
, uint16_t vpi
)
6584 struct lpfc_vport
*vport
;
6585 unsigned long flags
;
6587 spin_lock_irqsave(&phba
->hbalock
, flags
);
6588 list_for_each_entry(vport
, &phba
->port_list
, listentry
) {
6589 if (vport
->vpi
== vpi
) {
6590 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
6594 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
6599 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
6600 * @phba: pointer to lpfc hba data structure.
6601 * @pring: pointer to a SLI ring.
6602 * @elsiocb: pointer to lpfc els iocb data structure.
6604 * This routine is used to process an unsolicited event received from a SLI
6605 * (Service Level Interface) ring. The actual processing of the data buffer
6606 * associated with the unsolicited event is done by invoking the routine
6607 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
6608 * SLI ring on which the unsolicited event was received.
6611 lpfc_els_unsol_event(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
6612 struct lpfc_iocbq
*elsiocb
)
6614 struct lpfc_vport
*vport
= phba
->pport
;
6615 IOCB_t
*icmd
= &elsiocb
->iocb
;
6617 struct lpfc_dmabuf
*bdeBuf1
= elsiocb
->context2
;
6618 struct lpfc_dmabuf
*bdeBuf2
= elsiocb
->context3
;
6620 elsiocb
->context1
= NULL
;
6621 elsiocb
->context2
= NULL
;
6622 elsiocb
->context3
= NULL
;
6624 if (icmd
->ulpStatus
== IOSTAT_NEED_BUFFER
) {
6625 lpfc_sli_hbqbuf_add_hbqs(phba
, LPFC_ELS_HBQ
);
6626 } else if (icmd
->ulpStatus
== IOSTAT_LOCAL_REJECT
&&
6627 (icmd
->un
.ulpWord
[4] & 0xff) == IOERR_RCV_BUFFER_WAITING
) {
6628 phba
->fc_stat
.NoRcvBuf
++;
6629 /* Not enough posted buffers; Try posting more buffers */
6630 if (!(phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
))
6631 lpfc_post_buffer(phba
, pring
, 0);
6635 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
6636 (icmd
->ulpCommand
== CMD_IOCB_RCV_ELS64_CX
||
6637 icmd
->ulpCommand
== CMD_IOCB_RCV_SEQ64_CX
)) {
6638 if (icmd
->unsli3
.rcvsli3
.vpi
== 0xffff)
6639 vport
= phba
->pport
;
6641 vport
= lpfc_find_vport_by_vpid(phba
,
6642 icmd
->unsli3
.rcvsli3
.vpi
- phba
->vpi_base
);
6644 /* If there are no BDEs associated
6645 * with this IOCB, there is nothing to do.
6647 if (icmd
->ulpBdeCount
== 0)
6650 /* type of ELS cmd is first 32bit word
6653 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) {
6654 elsiocb
->context2
= bdeBuf1
;
6656 paddr
= getPaddr(icmd
->un
.cont64
[0].addrHigh
,
6657 icmd
->un
.cont64
[0].addrLow
);
6658 elsiocb
->context2
= lpfc_sli_ringpostbuf_get(phba
, pring
,
6662 lpfc_els_unsol_buffer(phba
, pring
, vport
, elsiocb
);
6664 * The different unsolicited event handlers would tell us
6665 * if they are done with "mp" by setting context2 to NULL.
6667 if (elsiocb
->context2
) {
6668 lpfc_in_buf_free(phba
, (struct lpfc_dmabuf
*)elsiocb
->context2
);
6669 elsiocb
->context2
= NULL
;
6672 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
6673 if ((phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) &&
6674 icmd
->ulpBdeCount
== 2) {
6675 elsiocb
->context2
= bdeBuf2
;
6676 lpfc_els_unsol_buffer(phba
, pring
, vport
, elsiocb
);
6677 /* free mp if we are done with it */
6678 if (elsiocb
->context2
) {
6679 lpfc_in_buf_free(phba
, elsiocb
->context2
);
6680 elsiocb
->context2
= NULL
;
6686 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
6687 * @phba: pointer to lpfc hba data structure.
6688 * @vport: pointer to a virtual N_Port data structure.
6690 * This routine issues a Port Login (PLOGI) to the Name Server with
6691 * State Change Request (SCR) for a @vport. This routine will create an
6692 * ndlp for the Name Server associated to the @vport if such node does
6693 * not already exist. The PLOGI to Name Server is issued by invoking the
6694 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
6695 * (FDMI) is configured to the @vport, a FDMI node will be created and
6696 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
6699 lpfc_do_scr_ns_plogi(struct lpfc_hba
*phba
, struct lpfc_vport
*vport
)
6701 struct lpfc_nodelist
*ndlp
, *ndlp_fdmi
;
6702 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
6705 * If lpfc_delay_discovery parameter is set and the clean address
6706 * bit is cleared and fc fabric parameters chenged, delay FC NPort
6709 spin_lock_irq(shost
->host_lock
);
6710 if (vport
->fc_flag
& FC_DISC_DELAYED
) {
6711 spin_unlock_irq(shost
->host_lock
);
6712 mod_timer(&vport
->delayed_disc_tmo
,
6713 jiffies
+ HZ
* phba
->fc_ratov
);
6716 spin_unlock_irq(shost
->host_lock
);
6718 ndlp
= lpfc_findnode_did(vport
, NameServer_DID
);
6720 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
6722 if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) {
6723 lpfc_disc_start(vport
);
6726 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
6727 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
6728 "0251 NameServer login: no memory\n");
6731 lpfc_nlp_init(vport
, ndlp
, NameServer_DID
);
6732 } else if (!NLP_CHK_NODE_ACT(ndlp
)) {
6733 ndlp
= lpfc_enable_node(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
6735 if (phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
) {
6736 lpfc_disc_start(vport
);
6739 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
6740 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
6741 "0348 NameServer login: node freed\n");
6745 ndlp
->nlp_type
|= NLP_FABRIC
;
6747 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
6749 if (lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0)) {
6750 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
6751 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
6752 "0252 Cannot issue NameServer login\n");
6756 if (vport
->cfg_fdmi_on
) {
6757 /* If this is the first time, allocate an ndlp and initialize
6758 * it. Otherwise, make sure the node is enabled and then do the
6761 ndlp_fdmi
= lpfc_findnode_did(vport
, FDMI_DID
);
6763 ndlp_fdmi
= mempool_alloc(phba
->nlp_mem_pool
,
6766 lpfc_nlp_init(vport
, ndlp_fdmi
, FDMI_DID
);
6767 ndlp_fdmi
->nlp_type
|= NLP_FABRIC
;
6771 if (!NLP_CHK_NODE_ACT(ndlp_fdmi
))
6772 ndlp_fdmi
= lpfc_enable_node(vport
,
6777 lpfc_nlp_set_state(vport
, ndlp_fdmi
,
6778 NLP_STE_PLOGI_ISSUE
);
6779 lpfc_issue_els_plogi(vport
, ndlp_fdmi
->nlp_DID
, 0);
6785 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
6786 * @phba: pointer to lpfc hba data structure.
6787 * @pmb: pointer to the driver internal queue element for mailbox command.
6789 * This routine is the completion callback function to register new vport
6790 * mailbox command. If the new vport mailbox command completes successfully,
6791 * the fabric registration login shall be performed on physical port (the
6792 * new vport created is actually a physical port, with VPI 0) or the port
6793 * login to Name Server for State Change Request (SCR) will be performed
6794 * on virtual port (real virtual port, with VPI greater than 0).
6797 lpfc_cmpl_reg_new_vport(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
6799 struct lpfc_vport
*vport
= pmb
->vport
;
6800 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
6801 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
6802 MAILBOX_t
*mb
= &pmb
->u
.mb
;
6805 spin_lock_irq(shost
->host_lock
);
6806 vport
->fc_flag
&= ~FC_VPORT_NEEDS_REG_VPI
;
6807 spin_unlock_irq(shost
->host_lock
);
6809 if (mb
->mbxStatus
) {
6810 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
6811 "0915 Register VPI failed : Status: x%x"
6812 " upd bit: x%x \n", mb
->mbxStatus
,
6813 mb
->un
.varRegVpi
.upd
);
6814 if (phba
->sli_rev
== LPFC_SLI_REV4
&&
6815 mb
->un
.varRegVpi
.upd
)
6816 goto mbox_err_exit
;
6818 switch (mb
->mbxStatus
) {
6819 case 0x11: /* unsupported feature */
6820 case 0x9603: /* max_vpi exceeded */
6821 case 0x9602: /* Link event since CLEAR_LA */
6822 /* giving up on vport registration */
6823 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
6824 spin_lock_irq(shost
->host_lock
);
6825 vport
->fc_flag
&= ~(FC_FABRIC
| FC_PUBLIC_LOOP
);
6826 spin_unlock_irq(shost
->host_lock
);
6827 lpfc_can_disctmo(vport
);
6829 /* If reg_vpi fail with invalid VPI status, re-init VPI */
6831 spin_lock_irq(shost
->host_lock
);
6832 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
6833 spin_unlock_irq(shost
->host_lock
);
6834 lpfc_init_vpi(phba
, pmb
, vport
->vpi
);
6836 pmb
->mbox_cmpl
= lpfc_init_vpi_cmpl
;
6837 rc
= lpfc_sli_issue_mbox(phba
, pmb
,
6839 if (rc
== MBX_NOT_FINISHED
) {
6840 lpfc_printf_vlog(vport
,
6842 "2732 Failed to issue INIT_VPI"
6843 " mailbox command\n");
6850 /* Try to recover from this error */
6851 if (phba
->sli_rev
== LPFC_SLI_REV4
)
6852 lpfc_sli4_unreg_all_rpis(vport
);
6853 lpfc_mbx_unreg_vpi(vport
);
6854 spin_lock_irq(shost
->host_lock
);
6855 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
6856 spin_unlock_irq(shost
->host_lock
);
6857 if (vport
->port_type
== LPFC_PHYSICAL_PORT
6858 && !(vport
->fc_flag
& FC_LOGO_RCVD_DID_CHNG
))
6859 lpfc_issue_init_vfi(vport
);
6861 lpfc_initial_fdisc(vport
);
6865 spin_lock_irq(shost
->host_lock
);
6866 vport
->vpi_state
|= LPFC_VPI_REGISTERED
;
6867 spin_unlock_irq(shost
->host_lock
);
6868 if (vport
== phba
->pport
) {
6869 if (phba
->sli_rev
< LPFC_SLI_REV4
)
6870 lpfc_issue_fabric_reglogin(vport
);
6873 * If the physical port is instantiated using
6874 * FDISC, do not start vport discovery.
6876 if (vport
->port_state
!= LPFC_FDISC
)
6877 lpfc_start_fdiscs(phba
);
6878 lpfc_do_scr_ns_plogi(phba
, vport
);
6881 lpfc_do_scr_ns_plogi(phba
, vport
);
6884 /* Now, we decrement the ndlp reference count held for this
6889 mempool_free(pmb
, phba
->mbox_mem_pool
);
6894 * lpfc_register_new_vport - Register a new vport with a HBA
6895 * @phba: pointer to lpfc hba data structure.
6896 * @vport: pointer to a host virtual N_Port data structure.
6897 * @ndlp: pointer to a node-list data structure.
6899 * This routine registers the @vport as a new virtual port with a HBA.
6900 * It is done through a registering vpi mailbox command.
6903 lpfc_register_new_vport(struct lpfc_hba
*phba
, struct lpfc_vport
*vport
,
6904 struct lpfc_nodelist
*ndlp
)
6906 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
6909 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
6911 lpfc_reg_vpi(vport
, mbox
);
6912 mbox
->vport
= vport
;
6913 mbox
->context2
= lpfc_nlp_get(ndlp
);
6914 mbox
->mbox_cmpl
= lpfc_cmpl_reg_new_vport
;
6915 if (lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
)
6916 == MBX_NOT_FINISHED
) {
6917 /* mailbox command not success, decrement ndlp
6918 * reference count for this command
6921 mempool_free(mbox
, phba
->mbox_mem_pool
);
6923 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
6924 "0253 Register VPI: Can't send mbox\n");
6928 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
6929 "0254 Register VPI: no memory\n");
6935 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
6936 spin_lock_irq(shost
->host_lock
);
6937 vport
->fc_flag
&= ~FC_VPORT_NEEDS_REG_VPI
;
6938 spin_unlock_irq(shost
->host_lock
);
6943 * lpfc_cancel_all_vport_retry_delay_timer - Cancel all vport retry delay timer
6944 * @phba: pointer to lpfc hba data structure.
6946 * This routine cancels the retry delay timers to all the vports.
6949 lpfc_cancel_all_vport_retry_delay_timer(struct lpfc_hba
*phba
)
6951 struct lpfc_vport
**vports
;
6952 struct lpfc_nodelist
*ndlp
;
6953 uint32_t link_state
;
6956 /* Treat this failure as linkdown for all vports */
6957 link_state
= phba
->link_state
;
6958 lpfc_linkdown(phba
);
6959 phba
->link_state
= link_state
;
6961 vports
= lpfc_create_vport_work_array(phba
);
6964 for (i
= 0; i
<= phba
->max_vports
&& vports
[i
] != NULL
; i
++) {
6965 ndlp
= lpfc_findnode_did(vports
[i
], Fabric_DID
);
6967 lpfc_cancel_retry_delay_tmo(vports
[i
], ndlp
);
6968 lpfc_els_flush_cmd(vports
[i
]);
6970 lpfc_destroy_vport_work_array(phba
, vports
);
6975 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
6976 * @phba: pointer to lpfc hba data structure.
6978 * This routine abort all pending discovery commands and
6979 * start a timer to retry FLOGI for the physical port
6983 lpfc_retry_pport_discovery(struct lpfc_hba
*phba
)
6985 struct lpfc_nodelist
*ndlp
;
6986 struct Scsi_Host
*shost
;
6988 /* Cancel the all vports retry delay retry timers */
6989 lpfc_cancel_all_vport_retry_delay_timer(phba
);
6991 /* If fabric require FLOGI, then re-instantiate physical login */
6992 ndlp
= lpfc_findnode_did(phba
->pport
, Fabric_DID
);
6996 shost
= lpfc_shost_from_vport(phba
->pport
);
6997 mod_timer(&ndlp
->nlp_delayfunc
, jiffies
+ HZ
);
6998 spin_lock_irq(shost
->host_lock
);
6999 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
7000 spin_unlock_irq(shost
->host_lock
);
7001 ndlp
->nlp_last_elscmd
= ELS_CMD_FLOGI
;
7002 phba
->pport
->port_state
= LPFC_FLOGI
;
7007 * lpfc_fabric_login_reqd - Check if FLOGI required.
7008 * @phba: pointer to lpfc hba data structure.
7009 * @cmdiocb: pointer to FDISC command iocb.
7010 * @rspiocb: pointer to FDISC response iocb.
7012 * This routine checks if a FLOGI is reguired for FDISC
7016 lpfc_fabric_login_reqd(struct lpfc_hba
*phba
,
7017 struct lpfc_iocbq
*cmdiocb
,
7018 struct lpfc_iocbq
*rspiocb
)
7021 if ((rspiocb
->iocb
.ulpStatus
!= IOSTAT_FABRIC_RJT
) ||
7022 (rspiocb
->iocb
.un
.ulpWord
[4] != RJT_LOGIN_REQUIRED
))
7029 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
7030 * @phba: pointer to lpfc hba data structure.
7031 * @cmdiocb: pointer to lpfc command iocb data structure.
7032 * @rspiocb: pointer to lpfc response iocb data structure.
7034 * This routine is the completion callback function to a Fabric Discover
7035 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
7036 * single threaded, each FDISC completion callback function will reset
7037 * the discovery timer for all vports such that the timers will not get
7038 * unnecessary timeout. The function checks the FDISC IOCB status. If error
7039 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
7040 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
7041 * assigned to the vport has been changed with the completion of the FDISC
7042 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
7043 * are unregistered from the HBA, and then the lpfc_register_new_vport()
7044 * routine is invoked to register new vport with the HBA. Otherwise, the
7045 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
7046 * Server for State Change Request (SCR).
7049 lpfc_cmpl_els_fdisc(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
7050 struct lpfc_iocbq
*rspiocb
)
7052 struct lpfc_vport
*vport
= cmdiocb
->vport
;
7053 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
7054 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
7055 struct lpfc_nodelist
*np
;
7056 struct lpfc_nodelist
*next_np
;
7057 IOCB_t
*irsp
= &rspiocb
->iocb
;
7058 struct lpfc_iocbq
*piocb
;
7059 struct lpfc_dmabuf
*pcmd
= cmdiocb
->context2
, *prsp
;
7060 struct serv_parm
*sp
;
7061 uint8_t fabric_param_changed
;
7063 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
7064 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
7065 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
7067 /* Since all FDISCs are being single threaded, we
7068 * must reset the discovery timer for ALL vports
7069 * waiting to send FDISC when one completes.
7071 list_for_each_entry(piocb
, &phba
->fabric_iocb_list
, list
) {
7072 lpfc_set_disctmo(piocb
->vport
);
7075 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
7076 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
7077 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4], vport
->fc_prevDID
);
7079 if (irsp
->ulpStatus
) {
7081 if (lpfc_fabric_login_reqd(phba
, cmdiocb
, rspiocb
)) {
7082 lpfc_retry_pport_discovery(phba
);
7086 /* Check for retry */
7087 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
))
7090 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
7091 "0126 FDISC failed. (%d/%d)\n",
7092 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4]);
7095 spin_lock_irq(shost
->host_lock
);
7096 vport
->fc_flag
&= ~FC_VPORT_CVL_RCVD
;
7097 vport
->fc_flag
&= ~FC_VPORT_LOGO_RCVD
;
7098 vport
->fc_flag
|= FC_FABRIC
;
7099 if (vport
->phba
->fc_topology
== LPFC_TOPOLOGY_LOOP
)
7100 vport
->fc_flag
|= FC_PUBLIC_LOOP
;
7101 spin_unlock_irq(shost
->host_lock
);
7103 vport
->fc_myDID
= irsp
->un
.ulpWord
[4] & Mask_DID
;
7104 lpfc_vport_set_state(vport
, FC_VPORT_ACTIVE
);
7105 prsp
= list_get_first(&pcmd
->list
, struct lpfc_dmabuf
, list
);
7106 sp
= prsp
->virt
+ sizeof(uint32_t);
7107 fabric_param_changed
= lpfc_check_clean_addr_bit(vport
, sp
);
7108 memcpy(&vport
->fabric_portname
, &sp
->portName
,
7109 sizeof(struct lpfc_name
));
7110 memcpy(&vport
->fabric_nodename
, &sp
->nodeName
,
7111 sizeof(struct lpfc_name
));
7112 if (fabric_param_changed
&&
7113 !(vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
)) {
7114 /* If our NportID changed, we need to ensure all
7115 * remaining NPORTs get unreg_login'ed so we can
7118 list_for_each_entry_safe(np
, next_np
,
7119 &vport
->fc_nodes
, nlp_listp
) {
7120 if (!NLP_CHK_NODE_ACT(ndlp
) ||
7121 (np
->nlp_state
!= NLP_STE_NPR_NODE
) ||
7122 !(np
->nlp_flag
& NLP_NPR_ADISC
))
7124 spin_lock_irq(shost
->host_lock
);
7125 np
->nlp_flag
&= ~NLP_NPR_ADISC
;
7126 spin_unlock_irq(shost
->host_lock
);
7127 lpfc_unreg_rpi(vport
, np
);
7129 lpfc_cleanup_pending_mbox(vport
);
7131 if (phba
->sli_rev
== LPFC_SLI_REV4
)
7132 lpfc_sli4_unreg_all_rpis(vport
);
7134 lpfc_mbx_unreg_vpi(vport
);
7135 spin_lock_irq(shost
->host_lock
);
7136 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
7137 if (phba
->sli_rev
== LPFC_SLI_REV4
)
7138 vport
->fc_flag
|= FC_VPORT_NEEDS_INIT_VPI
;
7140 vport
->fc_flag
|= FC_LOGO_RCVD_DID_CHNG
;
7141 spin_unlock_irq(shost
->host_lock
);
7142 } else if ((phba
->sli_rev
== LPFC_SLI_REV4
) &&
7143 !(vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
)) {
7145 * Driver needs to re-reg VPI in order for f/w
7146 * to update the MAC address.
7148 lpfc_register_new_vport(phba
, vport
, ndlp
);
7152 if (vport
->fc_flag
& FC_VPORT_NEEDS_INIT_VPI
)
7153 lpfc_issue_init_vpi(vport
);
7154 else if (vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
)
7155 lpfc_register_new_vport(phba
, vport
, ndlp
);
7157 lpfc_do_scr_ns_plogi(phba
, vport
);
7160 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
7161 /* Cancel discovery timer */
7162 lpfc_can_disctmo(vport
);
7165 lpfc_els_free_iocb(phba
, cmdiocb
);
7169 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
7170 * @vport: pointer to a virtual N_Port data structure.
7171 * @ndlp: pointer to a node-list data structure.
7172 * @retry: number of retries to the command IOCB.
7174 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
7175 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
7176 * routine to issue the IOCB, which makes sure only one outstanding fabric
7177 * IOCB will be sent off HBA at any given time.
7179 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7180 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7181 * will be stored into the context1 field of the IOCB for the completion
7182 * callback function to the FDISC ELS command.
7185 * 0 - Successfully issued fdisc iocb command
7186 * 1 - Failed to issue fdisc iocb command
7189 lpfc_issue_els_fdisc(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
7192 struct lpfc_hba
*phba
= vport
->phba
;
7194 struct lpfc_iocbq
*elsiocb
;
7195 struct serv_parm
*sp
;
7198 int did
= ndlp
->nlp_DID
;
7201 vport
->port_state
= LPFC_FDISC
;
7202 cmdsize
= (sizeof(uint32_t) + sizeof(struct serv_parm
));
7203 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
, did
,
7206 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
7207 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
7208 "0255 Issue FDISC: no IOCB\n");
7212 icmd
= &elsiocb
->iocb
;
7213 icmd
->un
.elsreq64
.myID
= 0;
7214 icmd
->un
.elsreq64
.fl
= 1;
7216 if ((phba
->sli_rev
== LPFC_SLI_REV4
) &&
7217 (bf_get(lpfc_sli_intf_if_type
, &phba
->sli4_hba
.sli_intf
) ==
7218 LPFC_SLI_INTF_IF_TYPE_0
)) {
7219 /* FDISC needs to be 1 for WQE VPI */
7220 elsiocb
->iocb
.ulpCt_h
= (SLI4_CT_VPI
>> 1) & 1;
7221 elsiocb
->iocb
.ulpCt_l
= SLI4_CT_VPI
& 1 ;
7222 /* Set the ulpContext to the vpi */
7223 elsiocb
->iocb
.ulpContext
= vport
->vpi
+ phba
->vpi_base
;
7225 /* For FDISC, Let FDISC rsp set the NPortID for this VPI */
7230 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
7231 *((uint32_t *) (pcmd
)) = ELS_CMD_FDISC
;
7232 pcmd
+= sizeof(uint32_t); /* CSP Word 1 */
7233 memcpy(pcmd
, &vport
->phba
->pport
->fc_sparam
, sizeof(struct serv_parm
));
7234 sp
= (struct serv_parm
*) pcmd
;
7235 /* Setup CSPs accordingly for Fabric */
7236 sp
->cmn
.e_d_tov
= 0;
7237 sp
->cmn
.w2
.r_a_tov
= 0;
7238 sp
->cls1
.classValid
= 0;
7239 sp
->cls2
.seqDelivery
= 1;
7240 sp
->cls3
.seqDelivery
= 1;
7242 pcmd
+= sizeof(uint32_t); /* CSP Word 2 */
7243 pcmd
+= sizeof(uint32_t); /* CSP Word 3 */
7244 pcmd
+= sizeof(uint32_t); /* CSP Word 4 */
7245 pcmd
+= sizeof(uint32_t); /* Port Name */
7246 memcpy(pcmd
, &vport
->fc_portname
, 8);
7247 pcmd
+= sizeof(uint32_t); /* Node Name */
7248 pcmd
+= sizeof(uint32_t); /* Node Name */
7249 memcpy(pcmd
, &vport
->fc_nodename
, 8);
7251 lpfc_set_disctmo(vport
);
7253 phba
->fc_stat
.elsXmitFDISC
++;
7254 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_fdisc
;
7256 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
7257 "Issue FDISC: did:x%x",
7260 rc
= lpfc_issue_fabric_iocb(phba
, elsiocb
);
7261 if (rc
== IOCB_ERROR
) {
7262 lpfc_els_free_iocb(phba
, elsiocb
);
7263 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
7264 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
7265 "0256 Issue FDISC: Cannot send IOCB\n");
7268 lpfc_vport_set_state(vport
, FC_VPORT_INITIALIZING
);
7273 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
7274 * @phba: pointer to lpfc hba data structure.
7275 * @cmdiocb: pointer to lpfc command iocb data structure.
7276 * @rspiocb: pointer to lpfc response iocb data structure.
7278 * This routine is the completion callback function to the issuing of a LOGO
7279 * ELS command off a vport. It frees the command IOCB and then decrement the
7280 * reference count held on ndlp for this completion function, indicating that
7281 * the reference to the ndlp is no long needed. Note that the
7282 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
7283 * callback function and an additional explicit ndlp reference decrementation
7284 * will trigger the actual release of the ndlp.
7287 lpfc_cmpl_els_npiv_logo(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
7288 struct lpfc_iocbq
*rspiocb
)
7290 struct lpfc_vport
*vport
= cmdiocb
->vport
;
7292 struct lpfc_nodelist
*ndlp
;
7293 ndlp
= (struct lpfc_nodelist
*)cmdiocb
->context1
;
7295 irsp
= &rspiocb
->iocb
;
7296 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
7297 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
7298 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4], irsp
->un
.rcvels
.remoteID
);
7300 lpfc_els_free_iocb(phba
, cmdiocb
);
7301 vport
->unreg_vpi_cmpl
= VPORT_ERROR
;
7303 /* Trigger the release of the ndlp after logo */
7308 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
7309 * @vport: pointer to a virtual N_Port data structure.
7310 * @ndlp: pointer to a node-list data structure.
7312 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
7314 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
7315 * will be incremented by 1 for holding the ndlp and the reference to ndlp
7316 * will be stored into the context1 field of the IOCB for the completion
7317 * callback function to the LOGO ELS command.
7320 * 0 - Successfully issued logo off the @vport
7321 * 1 - Failed to issue logo off the @vport
7324 lpfc_issue_els_npiv_logo(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
7326 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
7327 struct lpfc_hba
*phba
= vport
->phba
;
7329 struct lpfc_iocbq
*elsiocb
;
7333 cmdsize
= 2 * sizeof(uint32_t) + sizeof(struct lpfc_name
);
7334 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, 0, ndlp
, ndlp
->nlp_DID
,
7339 icmd
= &elsiocb
->iocb
;
7340 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
7341 *((uint32_t *) (pcmd
)) = ELS_CMD_LOGO
;
7342 pcmd
+= sizeof(uint32_t);
7344 /* Fill in LOGO payload */
7345 *((uint32_t *) (pcmd
)) = be32_to_cpu(vport
->fc_myDID
);
7346 pcmd
+= sizeof(uint32_t);
7347 memcpy(pcmd
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
7349 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
7350 "Issue LOGO npiv did:x%x flg:x%x",
7351 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
7353 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_npiv_logo
;
7354 spin_lock_irq(shost
->host_lock
);
7355 ndlp
->nlp_flag
|= NLP_LOGO_SND
;
7356 spin_unlock_irq(shost
->host_lock
);
7357 if (lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, elsiocb
, 0) ==
7359 spin_lock_irq(shost
->host_lock
);
7360 ndlp
->nlp_flag
&= ~NLP_LOGO_SND
;
7361 spin_unlock_irq(shost
->host_lock
);
7362 lpfc_els_free_iocb(phba
, elsiocb
);
7369 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
7370 * @ptr: holder for the timer function associated data.
7372 * This routine is invoked by the fabric iocb block timer after
7373 * timeout. It posts the fabric iocb block timeout event by setting the
7374 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
7375 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
7376 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
7377 * posted event WORKER_FABRIC_BLOCK_TMO.
7380 lpfc_fabric_block_timeout(unsigned long ptr
)
7382 struct lpfc_hba
*phba
= (struct lpfc_hba
*) ptr
;
7383 unsigned long iflags
;
7384 uint32_t tmo_posted
;
7386 spin_lock_irqsave(&phba
->pport
->work_port_lock
, iflags
);
7387 tmo_posted
= phba
->pport
->work_port_events
& WORKER_FABRIC_BLOCK_TMO
;
7389 phba
->pport
->work_port_events
|= WORKER_FABRIC_BLOCK_TMO
;
7390 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, iflags
);
7393 lpfc_worker_wake_up(phba
);
7398 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
7399 * @phba: pointer to lpfc hba data structure.
7401 * This routine issues one fabric iocb from the driver internal list to
7402 * the HBA. It first checks whether it's ready to issue one fabric iocb to
7403 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
7404 * remove one pending fabric iocb from the driver internal list and invokes
7405 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
7408 lpfc_resume_fabric_iocbs(struct lpfc_hba
*phba
)
7410 struct lpfc_iocbq
*iocb
;
7411 unsigned long iflags
;
7417 spin_lock_irqsave(&phba
->hbalock
, iflags
);
7418 /* Post any pending iocb to the SLI layer */
7419 if (atomic_read(&phba
->fabric_iocb_count
) == 0) {
7420 list_remove_head(&phba
->fabric_iocb_list
, iocb
, typeof(*iocb
),
7423 /* Increment fabric iocb count to hold the position */
7424 atomic_inc(&phba
->fabric_iocb_count
);
7426 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7428 iocb
->fabric_iocb_cmpl
= iocb
->iocb_cmpl
;
7429 iocb
->iocb_cmpl
= lpfc_cmpl_fabric_iocb
;
7430 iocb
->iocb_flag
|= LPFC_IO_FABRIC
;
7432 lpfc_debugfs_disc_trc(iocb
->vport
, LPFC_DISC_TRC_ELS_CMD
,
7433 "Fabric sched1: ste:x%x",
7434 iocb
->vport
->port_state
, 0, 0);
7436 ret
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, iocb
, 0);
7438 if (ret
== IOCB_ERROR
) {
7439 iocb
->iocb_cmpl
= iocb
->fabric_iocb_cmpl
;
7440 iocb
->fabric_iocb_cmpl
= NULL
;
7441 iocb
->iocb_flag
&= ~LPFC_IO_FABRIC
;
7443 cmd
->ulpStatus
= IOSTAT_LOCAL_REJECT
;
7444 cmd
->un
.ulpWord
[4] = IOERR_SLI_ABORTED
;
7445 iocb
->iocb_cmpl(phba
, iocb
, iocb
);
7447 atomic_dec(&phba
->fabric_iocb_count
);
7456 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
7457 * @phba: pointer to lpfc hba data structure.
7459 * This routine unblocks the issuing fabric iocb command. The function
7460 * will clear the fabric iocb block bit and then invoke the routine
7461 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
7462 * from the driver internal fabric iocb list.
7465 lpfc_unblock_fabric_iocbs(struct lpfc_hba
*phba
)
7467 clear_bit(FABRIC_COMANDS_BLOCKED
, &phba
->bit_flags
);
7469 lpfc_resume_fabric_iocbs(phba
);
7474 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
7475 * @phba: pointer to lpfc hba data structure.
7477 * This routine blocks the issuing fabric iocb for a specified amount of
7478 * time (currently 100 ms). This is done by set the fabric iocb block bit
7479 * and set up a timeout timer for 100ms. When the block bit is set, no more
7480 * fabric iocb will be issued out of the HBA.
7483 lpfc_block_fabric_iocbs(struct lpfc_hba
*phba
)
7487 blocked
= test_and_set_bit(FABRIC_COMANDS_BLOCKED
, &phba
->bit_flags
);
7488 /* Start a timer to unblock fabric iocbs after 100ms */
7490 mod_timer(&phba
->fabric_block_timer
, jiffies
+ HZ
/10 );
7496 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
7497 * @phba: pointer to lpfc hba data structure.
7498 * @cmdiocb: pointer to lpfc command iocb data structure.
7499 * @rspiocb: pointer to lpfc response iocb data structure.
7501 * This routine is the callback function that is put to the fabric iocb's
7502 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
7503 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
7504 * function first restores and invokes the original iocb's callback function
7505 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
7506 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
7509 lpfc_cmpl_fabric_iocb(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
7510 struct lpfc_iocbq
*rspiocb
)
7514 if ((cmdiocb
->iocb_flag
& LPFC_IO_FABRIC
) != LPFC_IO_FABRIC
)
7517 switch (rspiocb
->iocb
.ulpStatus
) {
7518 case IOSTAT_NPORT_RJT
:
7519 case IOSTAT_FABRIC_RJT
:
7520 if (rspiocb
->iocb
.un
.ulpWord
[4] & RJT_UNAVAIL_TEMP
) {
7521 lpfc_block_fabric_iocbs(phba
);
7525 case IOSTAT_NPORT_BSY
:
7526 case IOSTAT_FABRIC_BSY
:
7527 lpfc_block_fabric_iocbs(phba
);
7531 stat
.un
.lsRjtError
=
7532 be32_to_cpu(rspiocb
->iocb
.un
.ulpWord
[4]);
7533 if ((stat
.un
.b
.lsRjtRsnCode
== LSRJT_UNABLE_TPC
) ||
7534 (stat
.un
.b
.lsRjtRsnCode
== LSRJT_LOGICAL_BSY
))
7535 lpfc_block_fabric_iocbs(phba
);
7539 if (atomic_read(&phba
->fabric_iocb_count
) == 0)
7542 cmdiocb
->iocb_cmpl
= cmdiocb
->fabric_iocb_cmpl
;
7543 cmdiocb
->fabric_iocb_cmpl
= NULL
;
7544 cmdiocb
->iocb_flag
&= ~LPFC_IO_FABRIC
;
7545 cmdiocb
->iocb_cmpl(phba
, cmdiocb
, rspiocb
);
7547 atomic_dec(&phba
->fabric_iocb_count
);
7548 if (!test_bit(FABRIC_COMANDS_BLOCKED
, &phba
->bit_flags
)) {
7549 /* Post any pending iocbs to HBA */
7550 lpfc_resume_fabric_iocbs(phba
);
7555 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
7556 * @phba: pointer to lpfc hba data structure.
7557 * @iocb: pointer to lpfc command iocb data structure.
7559 * This routine is used as the top-level API for issuing a fabric iocb command
7560 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
7561 * function makes sure that only one fabric bound iocb will be outstanding at
7562 * any given time. As such, this function will first check to see whether there
7563 * is already an outstanding fabric iocb on the wire. If so, it will put the
7564 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
7565 * issued later. Otherwise, it will issue the iocb on the wire and update the
7566 * fabric iocb count it indicate that there is one fabric iocb on the wire.
7568 * Note, this implementation has a potential sending out fabric IOCBs out of
7569 * order. The problem is caused by the construction of the "ready" boolen does
7570 * not include the condition that the internal fabric IOCB list is empty. As
7571 * such, it is possible a fabric IOCB issued by this routine might be "jump"
7572 * ahead of the fabric IOCBs in the internal list.
7575 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
7576 * IOCB_ERROR - failed to issue fabric iocb
7579 lpfc_issue_fabric_iocb(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocb
)
7581 unsigned long iflags
;
7585 if (atomic_read(&phba
->fabric_iocb_count
) > 1)
7588 spin_lock_irqsave(&phba
->hbalock
, iflags
);
7589 ready
= atomic_read(&phba
->fabric_iocb_count
) == 0 &&
7590 !test_bit(FABRIC_COMANDS_BLOCKED
, &phba
->bit_flags
);
7593 /* Increment fabric iocb count to hold the position */
7594 atomic_inc(&phba
->fabric_iocb_count
);
7595 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7597 iocb
->fabric_iocb_cmpl
= iocb
->iocb_cmpl
;
7598 iocb
->iocb_cmpl
= lpfc_cmpl_fabric_iocb
;
7599 iocb
->iocb_flag
|= LPFC_IO_FABRIC
;
7601 lpfc_debugfs_disc_trc(iocb
->vport
, LPFC_DISC_TRC_ELS_CMD
,
7602 "Fabric sched2: ste:x%x",
7603 iocb
->vport
->port_state
, 0, 0);
7605 ret
= lpfc_sli_issue_iocb(phba
, LPFC_ELS_RING
, iocb
, 0);
7607 if (ret
== IOCB_ERROR
) {
7608 iocb
->iocb_cmpl
= iocb
->fabric_iocb_cmpl
;
7609 iocb
->fabric_iocb_cmpl
= NULL
;
7610 iocb
->iocb_flag
&= ~LPFC_IO_FABRIC
;
7611 atomic_dec(&phba
->fabric_iocb_count
);
7614 spin_lock_irqsave(&phba
->hbalock
, iflags
);
7615 list_add_tail(&iocb
->list
, &phba
->fabric_iocb_list
);
7616 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
7623 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
7624 * @vport: pointer to a virtual N_Port data structure.
7626 * This routine aborts all the IOCBs associated with a @vport from the
7627 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
7628 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
7629 * list, removes each IOCB associated with the @vport off the list, set the
7630 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
7631 * associated with the IOCB.
7633 static void lpfc_fabric_abort_vport(struct lpfc_vport
*vport
)
7635 LIST_HEAD(completions
);
7636 struct lpfc_hba
*phba
= vport
->phba
;
7637 struct lpfc_iocbq
*tmp_iocb
, *piocb
;
7639 spin_lock_irq(&phba
->hbalock
);
7640 list_for_each_entry_safe(piocb
, tmp_iocb
, &phba
->fabric_iocb_list
,
7643 if (piocb
->vport
!= vport
)
7646 list_move_tail(&piocb
->list
, &completions
);
7648 spin_unlock_irq(&phba
->hbalock
);
7650 /* Cancel all the IOCBs from the completions list */
7651 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
7656 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
7657 * @ndlp: pointer to a node-list data structure.
7659 * This routine aborts all the IOCBs associated with an @ndlp from the
7660 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
7661 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
7662 * list, removes each IOCB associated with the @ndlp off the list, set the
7663 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
7664 * associated with the IOCB.
7666 void lpfc_fabric_abort_nport(struct lpfc_nodelist
*ndlp
)
7668 LIST_HEAD(completions
);
7669 struct lpfc_hba
*phba
= ndlp
->phba
;
7670 struct lpfc_iocbq
*tmp_iocb
, *piocb
;
7671 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
7673 spin_lock_irq(&phba
->hbalock
);
7674 list_for_each_entry_safe(piocb
, tmp_iocb
, &phba
->fabric_iocb_list
,
7676 if ((lpfc_check_sli_ndlp(phba
, pring
, piocb
, ndlp
))) {
7678 list_move_tail(&piocb
->list
, &completions
);
7681 spin_unlock_irq(&phba
->hbalock
);
7683 /* Cancel all the IOCBs from the completions list */
7684 lpfc_sli_cancel_iocbs(phba
, &completions
, IOSTAT_LOCAL_REJECT
,
7689 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
7690 * @phba: pointer to lpfc hba data structure.
7692 * This routine aborts all the IOCBs currently on the driver internal
7693 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
7694 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
7695 * list, removes IOCBs off the list, set the status feild to
7696 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
7699 void lpfc_fabric_abort_hba(struct lpfc_hba
*phba
)
7701 LIST_HEAD(completions
);
7703 spin_lock_irq(&phba
->hbalock
);
7704 list_splice_init(&phba
->fabric_iocb_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_sli4_vport_delete_els_xri_aborted -Remove all ndlp references for vport
7714 * @vport: pointer to lpfc vport data structure.
7716 * This routine is invoked by the vport cleanup for deletions and the cleanup
7717 * for an ndlp on removal.
7720 lpfc_sli4_vport_delete_els_xri_aborted(struct lpfc_vport
*vport
)
7722 struct lpfc_hba
*phba
= vport
->phba
;
7723 struct lpfc_sglq
*sglq_entry
= NULL
, *sglq_next
= NULL
;
7724 unsigned long iflag
= 0;
7726 spin_lock_irqsave(&phba
->hbalock
, iflag
);
7727 spin_lock(&phba
->sli4_hba
.abts_sgl_list_lock
);
7728 list_for_each_entry_safe(sglq_entry
, sglq_next
,
7729 &phba
->sli4_hba
.lpfc_abts_els_sgl_list
, list
) {
7730 if (sglq_entry
->ndlp
&& sglq_entry
->ndlp
->vport
== vport
)
7731 sglq_entry
->ndlp
= NULL
;
7733 spin_unlock(&phba
->sli4_hba
.abts_sgl_list_lock
);
7734 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
7739 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
7740 * @phba: pointer to lpfc hba data structure.
7741 * @axri: pointer to the els xri abort wcqe structure.
7743 * This routine is invoked by the worker thread to process a SLI4 slow-path
7747 lpfc_sli4_els_xri_aborted(struct lpfc_hba
*phba
,
7748 struct sli4_wcqe_xri_aborted
*axri
)
7750 uint16_t xri
= bf_get(lpfc_wcqe_xa_xri
, axri
);
7751 uint16_t rxid
= bf_get(lpfc_wcqe_xa_remote_xid
, axri
);
7753 struct lpfc_sglq
*sglq_entry
= NULL
, *sglq_next
= NULL
;
7754 unsigned long iflag
= 0;
7755 struct lpfc_nodelist
*ndlp
;
7756 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
7758 spin_lock_irqsave(&phba
->hbalock
, iflag
);
7759 spin_lock(&phba
->sli4_hba
.abts_sgl_list_lock
);
7760 list_for_each_entry_safe(sglq_entry
, sglq_next
,
7761 &phba
->sli4_hba
.lpfc_abts_els_sgl_list
, list
) {
7762 if (sglq_entry
->sli4_xritag
== xri
) {
7763 list_del(&sglq_entry
->list
);
7764 ndlp
= sglq_entry
->ndlp
;
7765 sglq_entry
->ndlp
= NULL
;
7766 list_add_tail(&sglq_entry
->list
,
7767 &phba
->sli4_hba
.lpfc_sgl_list
);
7768 sglq_entry
->state
= SGL_FREED
;
7769 spin_unlock(&phba
->sli4_hba
.abts_sgl_list_lock
);
7770 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
7771 lpfc_set_rrq_active(phba
, ndlp
, xri
, rxid
, 1);
7773 /* Check if TXQ queue needs to be serviced */
7775 lpfc_worker_wake_up(phba
);
7779 spin_unlock(&phba
->sli4_hba
.abts_sgl_list_lock
);
7780 sglq_entry
= __lpfc_get_active_sglq(phba
, xri
);
7781 if (!sglq_entry
|| (sglq_entry
->sli4_xritag
!= xri
)) {
7782 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
7785 sglq_entry
->state
= SGL_XRI_ABORTED
;
7786 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);