1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2007 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 *******************************************************************/
22 #include <linux/blkdev.h>
23 #include <linux/pci.h>
24 #include <linux/interrupt.h>
26 #include <scsi/scsi.h>
27 #include <scsi/scsi_device.h>
28 #include <scsi/scsi_host.h>
29 #include <scsi/scsi_transport_fc.h>
33 #include "lpfc_disc.h"
34 #include "lpfc_scsi.h"
36 #include "lpfc_logmsg.h"
37 #include "lpfc_crtn.h"
38 #include "lpfc_vport.h"
39 #include "lpfc_debugfs.h"
41 static int lpfc_els_retry(struct lpfc_hba
*, struct lpfc_iocbq
*,
43 static void lpfc_cmpl_fabric_iocb(struct lpfc_hba
*, struct lpfc_iocbq
*,
46 static int lpfc_max_els_tries
= 3;
49 lpfc_els_chk_latt(struct lpfc_vport
*vport
)
51 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
52 struct lpfc_hba
*phba
= vport
->phba
;
55 if (vport
->port_state
>= LPFC_VPORT_READY
||
56 phba
->link_state
== LPFC_LINK_DOWN
)
59 /* Read the HBA Host Attention Register */
60 ha_copy
= readl(phba
->HAregaddr
);
62 if (!(ha_copy
& HA_LATT
))
65 /* Pending Link Event during Discovery */
66 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
67 "0237 Pending Link Event during "
68 "Discovery: State x%x\n",
69 phba
->pport
->port_state
);
71 /* CLEAR_LA should re-enable link attention events and
72 * we should then imediately take a LATT event. The
73 * LATT processing should call lpfc_linkdown() which
74 * will cleanup any left over in-progress discovery
77 spin_lock_irq(shost
->host_lock
);
78 vport
->fc_flag
|= FC_ABORT_DISCOVERY
;
79 spin_unlock_irq(shost
->host_lock
);
81 if (phba
->link_state
!= LPFC_CLEAR_LA
)
82 lpfc_issue_clear_la(phba
, vport
);
87 static struct lpfc_iocbq
*
88 lpfc_prep_els_iocb(struct lpfc_vport
*vport
, uint8_t expectRsp
,
89 uint16_t cmdSize
, uint8_t retry
,
90 struct lpfc_nodelist
*ndlp
, uint32_t did
,
93 struct lpfc_hba
*phba
= vport
->phba
;
94 struct lpfc_iocbq
*elsiocb
;
95 struct lpfc_dmabuf
*pcmd
, *prsp
, *pbuflist
;
96 struct ulp_bde64
*bpl
;
100 if (!lpfc_is_link_up(phba
))
103 /* Allocate buffer for command iocb */
104 elsiocb
= lpfc_sli_get_iocbq(phba
);
108 icmd
= &elsiocb
->iocb
;
110 /* fill in BDEs for command */
111 /* Allocate buffer for command payload */
112 if (((pcmd
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
)) == 0) ||
113 ((pcmd
->virt
= lpfc_mbuf_alloc(phba
,
114 MEM_PRI
, &(pcmd
->phys
))) == 0)) {
117 lpfc_sli_release_iocbq(phba
, elsiocb
);
121 INIT_LIST_HEAD(&pcmd
->list
);
123 /* Allocate buffer for response payload */
125 prsp
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
127 prsp
->virt
= lpfc_mbuf_alloc(phba
, MEM_PRI
,
129 if (prsp
== 0 || prsp
->virt
== 0) {
131 lpfc_mbuf_free(phba
, pcmd
->virt
, pcmd
->phys
);
133 lpfc_sli_release_iocbq(phba
, elsiocb
);
136 INIT_LIST_HEAD(&prsp
->list
);
141 /* Allocate buffer for Buffer ptr list */
142 pbuflist
= kmalloc(sizeof(struct lpfc_dmabuf
), GFP_KERNEL
);
144 pbuflist
->virt
= lpfc_mbuf_alloc(phba
, MEM_PRI
,
146 if (pbuflist
== 0 || pbuflist
->virt
== 0) {
147 lpfc_sli_release_iocbq(phba
, elsiocb
);
148 lpfc_mbuf_free(phba
, pcmd
->virt
, pcmd
->phys
);
149 lpfc_mbuf_free(phba
, prsp
->virt
, prsp
->phys
);
156 INIT_LIST_HEAD(&pbuflist
->list
);
158 icmd
->un
.elsreq64
.bdl
.addrHigh
= putPaddrHigh(pbuflist
->phys
);
159 icmd
->un
.elsreq64
.bdl
.addrLow
= putPaddrLow(pbuflist
->phys
);
160 icmd
->un
.elsreq64
.bdl
.bdeFlags
= BUFF_TYPE_BDL
;
161 icmd
->un
.elsreq64
.remoteID
= did
; /* DID */
163 icmd
->un
.elsreq64
.bdl
.bdeSize
= (2 * sizeof(struct ulp_bde64
));
164 icmd
->ulpCommand
= CMD_ELS_REQUEST64_CR
;
165 icmd
->ulpTimeout
= phba
->fc_ratov
* 2;
167 icmd
->un
.elsreq64
.bdl
.bdeSize
= sizeof(struct ulp_bde64
);
168 icmd
->ulpCommand
= CMD_XMIT_ELS_RSP64_CX
;
170 icmd
->ulpBdeCount
= 1;
172 icmd
->ulpClass
= CLASS3
;
174 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) {
175 icmd
->un
.elsreq64
.myID
= vport
->fc_myDID
;
177 /* For ELS_REQUEST64_CR, use the VPI by default */
178 icmd
->ulpContext
= vport
->vpi
;
183 bpl
= (struct ulp_bde64
*) pbuflist
->virt
;
184 bpl
->addrLow
= le32_to_cpu(putPaddrLow(pcmd
->phys
));
185 bpl
->addrHigh
= le32_to_cpu(putPaddrHigh(pcmd
->phys
));
186 bpl
->tus
.f
.bdeSize
= cmdSize
;
187 bpl
->tus
.f
.bdeFlags
= 0;
188 bpl
->tus
.w
= le32_to_cpu(bpl
->tus
.w
);
192 bpl
->addrLow
= le32_to_cpu(putPaddrLow(prsp
->phys
));
193 bpl
->addrHigh
= le32_to_cpu(putPaddrHigh(prsp
->phys
));
194 bpl
->tus
.f
.bdeSize
= FCELSSIZE
;
195 bpl
->tus
.f
.bdeFlags
= BUFF_USE_RCV
;
196 bpl
->tus
.w
= le32_to_cpu(bpl
->tus
.w
);
199 elsiocb
->context1
= lpfc_nlp_get(ndlp
);
200 elsiocb
->context2
= pcmd
;
201 elsiocb
->context3
= pbuflist
;
202 elsiocb
->retry
= retry
;
203 elsiocb
->vport
= vport
;
204 elsiocb
->drvrTimeout
= (phba
->fc_ratov
<< 1) + LPFC_DRVR_TIMEOUT
;
207 list_add(&prsp
->list
, &pcmd
->list
);
210 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
211 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
212 "0116 Xmit ELS command x%x to remote "
213 "NPORT x%x I/O tag: x%x, port state: x%x\n",
214 elscmd
, did
, elsiocb
->iotag
,
217 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
218 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
219 "0117 Xmit ELS response x%x to remote "
220 "NPORT x%x I/O tag: x%x, size: x%x\n",
221 elscmd
, ndlp
->nlp_DID
, elsiocb
->iotag
,
229 lpfc_issue_fabric_reglogin(struct lpfc_vport
*vport
)
231 struct lpfc_hba
*phba
= vport
->phba
;
233 struct lpfc_dmabuf
*mp
;
234 struct lpfc_nodelist
*ndlp
;
235 struct serv_parm
*sp
;
238 sp
= &phba
->fc_fabparam
;
239 ndlp
= lpfc_findnode_did(vport
, Fabric_DID
);
243 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
247 vport
->port_state
= LPFC_FABRIC_CFG_LINK
;
248 lpfc_config_link(phba
, mbox
);
249 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
252 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
| MBX_STOP_IOCB
);
253 if (rc
== MBX_NOT_FINISHED
)
256 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
259 rc
= lpfc_reg_login(phba
, vport
->vpi
, Fabric_DID
, (uint8_t *)sp
, mbox
,
264 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_fabric_reg_login
;
266 mbox
->context2
= lpfc_nlp_get(ndlp
);
268 rc
= lpfc_sli_issue_mbox(phba
, mbox
, MBX_NOWAIT
| MBX_STOP_IOCB
);
269 if (rc
== MBX_NOT_FINISHED
)
270 goto fail_issue_reg_login
;
274 fail_issue_reg_login
:
276 mp
= (struct lpfc_dmabuf
*) mbox
->context1
;
277 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
280 mempool_free(mbox
, phba
->mbox_mem_pool
);
283 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
284 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
285 "0249 Cannot issue Register Fabric login\n");
290 lpfc_cmpl_els_flogi_fabric(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
291 struct serv_parm
*sp
, IOCB_t
*irsp
)
293 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
294 struct lpfc_hba
*phba
= vport
->phba
;
295 struct lpfc_nodelist
*np
;
296 struct lpfc_nodelist
*next_np
;
298 spin_lock_irq(shost
->host_lock
);
299 vport
->fc_flag
|= FC_FABRIC
;
300 spin_unlock_irq(shost
->host_lock
);
302 phba
->fc_edtov
= be32_to_cpu(sp
->cmn
.e_d_tov
);
303 if (sp
->cmn
.edtovResolution
) /* E_D_TOV ticks are in nanoseconds */
304 phba
->fc_edtov
= (phba
->fc_edtov
+ 999999) / 1000000;
306 phba
->fc_ratov
= (be32_to_cpu(sp
->cmn
.w2
.r_a_tov
) + 999) / 1000;
308 if (phba
->fc_topology
== TOPOLOGY_LOOP
) {
309 spin_lock_irq(shost
->host_lock
);
310 vport
->fc_flag
|= FC_PUBLIC_LOOP
;
311 spin_unlock_irq(shost
->host_lock
);
314 * If we are a N-port connected to a Fabric, fixup sparam's so
315 * logins to devices on remote loops work.
317 vport
->fc_sparam
.cmn
.altBbCredit
= 1;
320 vport
->fc_myDID
= irsp
->un
.ulpWord
[4] & Mask_DID
;
321 memcpy(&ndlp
->nlp_portname
, &sp
->portName
, sizeof(struct lpfc_name
));
322 memcpy(&ndlp
->nlp_nodename
, &sp
->nodeName
, sizeof(struct lpfc_name
));
323 ndlp
->nlp_class_sup
= 0;
324 if (sp
->cls1
.classValid
)
325 ndlp
->nlp_class_sup
|= FC_COS_CLASS1
;
326 if (sp
->cls2
.classValid
)
327 ndlp
->nlp_class_sup
|= FC_COS_CLASS2
;
328 if (sp
->cls3
.classValid
)
329 ndlp
->nlp_class_sup
|= FC_COS_CLASS3
;
330 if (sp
->cls4
.classValid
)
331 ndlp
->nlp_class_sup
|= FC_COS_CLASS4
;
332 ndlp
->nlp_maxframe
= ((sp
->cmn
.bbRcvSizeMsb
& 0x0F) << 8) |
333 sp
->cmn
.bbRcvSizeLsb
;
334 memcpy(&phba
->fc_fabparam
, sp
, sizeof(struct serv_parm
));
336 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) {
337 if (sp
->cmn
.response_multiple_NPort
) {
338 lpfc_printf_vlog(vport
, KERN_WARNING
,
340 "1816 FLOGI NPIV supported, "
341 "response data 0x%x\n",
342 sp
->cmn
.response_multiple_NPort
);
343 phba
->link_flag
|= LS_NPIV_FAB_SUPPORTED
;
345 /* Because we asked f/w for NPIV it still expects us
346 to call reg_vnpid atleast for the physcial host */
347 lpfc_printf_vlog(vport
, KERN_WARNING
,
349 "1817 Fabric does not support NPIV "
350 "- configuring single port mode.\n");
351 phba
->link_flag
&= ~LS_NPIV_FAB_SUPPORTED
;
355 if ((vport
->fc_prevDID
!= vport
->fc_myDID
) &&
356 !(vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
)) {
358 /* If our NportID changed, we need to ensure all
359 * remaining NPORTs get unreg_login'ed.
361 list_for_each_entry_safe(np
, next_np
,
362 &vport
->fc_nodes
, nlp_listp
) {
363 if ((np
->nlp_state
!= NLP_STE_NPR_NODE
) ||
364 !(np
->nlp_flag
& NLP_NPR_ADISC
))
366 spin_lock_irq(shost
->host_lock
);
367 np
->nlp_flag
&= ~NLP_NPR_ADISC
;
368 spin_unlock_irq(shost
->host_lock
);
369 lpfc_unreg_rpi(vport
, np
);
371 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) {
372 lpfc_mbx_unreg_vpi(vport
);
373 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
377 ndlp
->nlp_sid
= irsp
->un
.ulpWord
[4] & Mask_DID
;
378 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_REG_LOGIN_ISSUE
);
380 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
&&
381 vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
) {
382 lpfc_register_new_vport(phba
, vport
, ndlp
);
385 lpfc_issue_fabric_reglogin(vport
);
390 * We FLOGIed into an NPort, initiate pt2pt protocol
393 lpfc_cmpl_els_flogi_nport(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
394 struct serv_parm
*sp
)
396 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
397 struct lpfc_hba
*phba
= vport
->phba
;
401 spin_lock_irq(shost
->host_lock
);
402 vport
->fc_flag
&= ~(FC_FABRIC
| FC_PUBLIC_LOOP
);
403 spin_unlock_irq(shost
->host_lock
);
405 phba
->fc_edtov
= FF_DEF_EDTOV
;
406 phba
->fc_ratov
= FF_DEF_RATOV
;
407 rc
= memcmp(&vport
->fc_portname
, &sp
->portName
,
408 sizeof(vport
->fc_portname
));
410 /* This side will initiate the PLOGI */
411 spin_lock_irq(shost
->host_lock
);
412 vport
->fc_flag
|= FC_PT2PT_PLOGI
;
413 spin_unlock_irq(shost
->host_lock
);
416 * N_Port ID cannot be 0, set our to LocalID the other
417 * side will be RemoteID.
422 vport
->fc_myDID
= PT2PT_LocalID
;
424 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
428 lpfc_config_link(phba
, mbox
);
430 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
432 rc
= lpfc_sli_issue_mbox(phba
, mbox
,
433 MBX_NOWAIT
| MBX_STOP_IOCB
);
434 if (rc
== MBX_NOT_FINISHED
) {
435 mempool_free(mbox
, phba
->mbox_mem_pool
);
440 ndlp
= lpfc_findnode_did(vport
, PT2PT_RemoteID
);
443 * Cannot find existing Fabric ndlp, so allocate a
446 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
450 lpfc_nlp_init(vport
, ndlp
, PT2PT_RemoteID
);
453 memcpy(&ndlp
->nlp_portname
, &sp
->portName
,
454 sizeof(struct lpfc_name
));
455 memcpy(&ndlp
->nlp_nodename
, &sp
->nodeName
,
456 sizeof(struct lpfc_name
));
457 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
458 spin_lock_irq(shost
->host_lock
);
459 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
460 spin_unlock_irq(shost
->host_lock
);
462 /* This side will wait for the PLOGI */
466 spin_lock_irq(shost
->host_lock
);
467 vport
->fc_flag
|= FC_PT2PT
;
468 spin_unlock_irq(shost
->host_lock
);
470 /* Start discovery - this should just do CLEAR_LA */
471 lpfc_disc_start(vport
);
478 lpfc_cmpl_els_flogi(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
479 struct lpfc_iocbq
*rspiocb
)
481 struct lpfc_vport
*vport
= cmdiocb
->vport
;
482 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
483 IOCB_t
*irsp
= &rspiocb
->iocb
;
484 struct lpfc_nodelist
*ndlp
= cmdiocb
->context1
;
485 struct lpfc_dmabuf
*pcmd
= cmdiocb
->context2
, *prsp
;
486 struct serv_parm
*sp
;
489 /* Check to see if link went down during discovery */
490 if (lpfc_els_chk_latt(vport
)) {
495 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
496 "FLOGI cmpl: status:x%x/x%x state:x%x",
497 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
500 if (irsp
->ulpStatus
) {
501 /* Check for retry */
502 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
))
505 /* FLOGI failed, so there is no fabric */
506 spin_lock_irq(shost
->host_lock
);
507 vport
->fc_flag
&= ~(FC_FABRIC
| FC_PUBLIC_LOOP
);
508 spin_unlock_irq(shost
->host_lock
);
510 /* If private loop, then allow max outstanding els to be
511 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
512 * alpa map would take too long otherwise.
514 if (phba
->alpa_map
[0] == 0) {
515 vport
->cfg_discovery_threads
= LPFC_MAX_DISC_THREADS
;
519 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
520 "0100 FLOGI failure Data: x%x x%x "
522 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
528 * The FLogI succeeded. Sync the data for the CPU before
531 prsp
= list_get_first(&pcmd
->list
, struct lpfc_dmabuf
, list
);
533 sp
= prsp
->virt
+ sizeof(uint32_t);
535 /* FLOGI completes successfully */
536 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
537 "0101 FLOGI completes sucessfully "
538 "Data: x%x x%x x%x x%x\n",
539 irsp
->un
.ulpWord
[4], sp
->cmn
.e_d_tov
,
540 sp
->cmn
.w2
.r_a_tov
, sp
->cmn
.edtovResolution
);
542 if (vport
->port_state
== LPFC_FLOGI
) {
544 * If Common Service Parameters indicate Nport
545 * we are point to point, if Fport we are Fabric.
548 rc
= lpfc_cmpl_els_flogi_fabric(vport
, ndlp
, sp
, irsp
);
550 rc
= lpfc_cmpl_els_flogi_nport(vport
, ndlp
, sp
);
559 if (!lpfc_error_lost_link(irsp
)) {
560 /* FLOGI failed, so just use loop map to make discovery list */
561 lpfc_disc_list_loopmap(vport
);
563 /* Start discovery */
564 lpfc_disc_start(vport
);
568 lpfc_els_free_iocb(phba
, cmdiocb
);
572 lpfc_issue_els_flogi(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
575 struct lpfc_hba
*phba
= vport
->phba
;
576 struct serv_parm
*sp
;
578 struct lpfc_iocbq
*elsiocb
;
579 struct lpfc_sli_ring
*pring
;
585 pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
587 cmdsize
= (sizeof(uint32_t) + sizeof(struct serv_parm
));
588 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
589 ndlp
->nlp_DID
, ELS_CMD_FLOGI
);
594 icmd
= &elsiocb
->iocb
;
595 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
597 /* For FLOGI request, remainder of payload is service parameters */
598 *((uint32_t *) (pcmd
)) = ELS_CMD_FLOGI
;
599 pcmd
+= sizeof(uint32_t);
600 memcpy(pcmd
, &vport
->fc_sparam
, sizeof(struct serv_parm
));
601 sp
= (struct serv_parm
*) pcmd
;
603 /* Setup CSPs accordingly for Fabric */
605 sp
->cmn
.w2
.r_a_tov
= 0;
606 sp
->cls1
.classValid
= 0;
607 sp
->cls2
.seqDelivery
= 1;
608 sp
->cls3
.seqDelivery
= 1;
609 if (sp
->cmn
.fcphLow
< FC_PH3
)
610 sp
->cmn
.fcphLow
= FC_PH3
;
611 if (sp
->cmn
.fcphHigh
< FC_PH3
)
612 sp
->cmn
.fcphHigh
= FC_PH3
;
614 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) {
615 sp
->cmn
.request_multiple_Nport
= 1;
617 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
622 if (phba
->fc_topology
!= TOPOLOGY_LOOP
) {
623 icmd
->un
.elsreq64
.myID
= 0;
624 icmd
->un
.elsreq64
.fl
= 1;
627 tmo
= phba
->fc_ratov
;
628 phba
->fc_ratov
= LPFC_DISC_FLOGI_TMO
;
629 lpfc_set_disctmo(vport
);
630 phba
->fc_ratov
= tmo
;
632 phba
->fc_stat
.elsXmitFLOGI
++;
633 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_flogi
;
635 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
636 "Issue FLOGI: opt:x%x",
637 phba
->sli3_options
, 0, 0);
639 rc
= lpfc_issue_fabric_iocb(phba
, elsiocb
);
640 if (rc
== IOCB_ERROR
) {
641 lpfc_els_free_iocb(phba
, elsiocb
);
648 lpfc_els_abort_flogi(struct lpfc_hba
*phba
)
650 struct lpfc_sli_ring
*pring
;
651 struct lpfc_iocbq
*iocb
, *next_iocb
;
652 struct lpfc_nodelist
*ndlp
;
655 /* Abort outstanding I/O on NPort <nlp_DID> */
656 lpfc_printf_log(phba
, KERN_INFO
, LOG_DISCOVERY
,
657 "0201 Abort outstanding I/O on NPort x%x\n",
660 pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
663 * Check the txcmplq for an iocb that matches the nport the driver is
666 spin_lock_irq(&phba
->hbalock
);
667 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
, list
) {
669 if (icmd
->ulpCommand
== CMD_ELS_REQUEST64_CR
&&
670 icmd
->un
.elsreq64
.bdl
.ulpIoTag32
) {
671 ndlp
= (struct lpfc_nodelist
*)(iocb
->context1
);
672 if (ndlp
&& (ndlp
->nlp_DID
== Fabric_DID
)) {
673 lpfc_sli_issue_abort_iotag(phba
, pring
, iocb
);
677 spin_unlock_irq(&phba
->hbalock
);
683 lpfc_initial_flogi(struct lpfc_vport
*vport
)
685 struct lpfc_hba
*phba
= vport
->phba
;
686 struct lpfc_nodelist
*ndlp
;
688 /* First look for the Fabric ndlp */
689 ndlp
= lpfc_findnode_did(vport
, Fabric_DID
);
691 /* Cannot find existing Fabric ndlp, so allocate a new one */
692 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
695 lpfc_nlp_init(vport
, ndlp
, Fabric_DID
);
697 lpfc_dequeue_node(vport
, ndlp
);
699 if (lpfc_issue_els_flogi(vport
, ndlp
, 0)) {
706 lpfc_initial_fdisc(struct lpfc_vport
*vport
)
708 struct lpfc_hba
*phba
= vport
->phba
;
709 struct lpfc_nodelist
*ndlp
;
711 /* First look for the Fabric ndlp */
712 ndlp
= lpfc_findnode_did(vport
, Fabric_DID
);
714 /* Cannot find existing Fabric ndlp, so allocate a new one */
715 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
718 lpfc_nlp_init(vport
, ndlp
, Fabric_DID
);
720 lpfc_dequeue_node(vport
, ndlp
);
722 if (lpfc_issue_els_fdisc(vport
, ndlp
, 0)) {
728 lpfc_more_plogi(struct lpfc_vport
*vport
)
732 if (vport
->num_disc_nodes
)
733 vport
->num_disc_nodes
--;
735 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
736 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
737 "0232 Continue discovery with %d PLOGIs to go "
738 "Data: x%x x%x x%x\n",
739 vport
->num_disc_nodes
, vport
->fc_plogi_cnt
,
740 vport
->fc_flag
, vport
->port_state
);
741 /* Check to see if there are more PLOGIs to be sent */
742 if (vport
->fc_flag
& FC_NLP_MORE
)
743 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
744 sentplogi
= lpfc_els_disc_plogi(vport
);
749 static struct lpfc_nodelist
*
750 lpfc_plogi_confirm_nport(struct lpfc_hba
*phba
, uint32_t *prsp
,
751 struct lpfc_nodelist
*ndlp
)
753 struct lpfc_vport
*vport
= ndlp
->vport
;
754 struct lpfc_nodelist
*new_ndlp
;
755 struct serv_parm
*sp
;
756 uint8_t name
[sizeof(struct lpfc_name
)];
759 /* Fabric nodes can have the same WWPN so we don't bother searching
760 * by WWPN. Just return the ndlp that was given to us.
762 if (ndlp
->nlp_type
& NLP_FABRIC
)
765 sp
= (struct serv_parm
*) ((uint8_t *) prsp
+ sizeof(uint32_t));
766 memset(name
, 0, sizeof(struct lpfc_name
));
768 /* Now we find out if the NPort we are logging into, matches the WWPN
769 * we have for that ndlp. If not, we have some work to do.
771 new_ndlp
= lpfc_findnode_wwpn(vport
, &sp
->portName
);
773 if (new_ndlp
== ndlp
)
777 rc
= memcmp(&ndlp
->nlp_portname
, name
,
778 sizeof(struct lpfc_name
));
781 new_ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_ATOMIC
);
785 lpfc_nlp_init(vport
, new_ndlp
, ndlp
->nlp_DID
);
788 lpfc_unreg_rpi(vport
, new_ndlp
);
789 new_ndlp
->nlp_DID
= ndlp
->nlp_DID
;
790 new_ndlp
->nlp_prev_state
= ndlp
->nlp_prev_state
;
791 lpfc_nlp_set_state(vport
, new_ndlp
, ndlp
->nlp_state
);
793 /* Move this back to NPR state */
794 if (memcmp(&ndlp
->nlp_portname
, name
, sizeof(struct lpfc_name
)) == 0)
795 lpfc_drop_node(vport
, ndlp
);
797 lpfc_unreg_rpi(vport
, ndlp
);
798 ndlp
->nlp_DID
= 0; /* Two ndlps cannot have the same did */
799 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
805 lpfc_cmpl_els_plogi(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
806 struct lpfc_iocbq
*rspiocb
)
808 struct lpfc_vport
*vport
= cmdiocb
->vport
;
809 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
811 struct lpfc_nodelist
*ndlp
;
812 struct lpfc_dmabuf
*prsp
;
813 int disc
, rc
, did
, type
;
815 /* we pass cmdiocb to state machine which needs rspiocb as well */
816 cmdiocb
->context_un
.rsp_iocb
= rspiocb
;
818 irsp
= &rspiocb
->iocb
;
819 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
820 "PLOGI cmpl: status:x%x/x%x did:x%x",
821 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
822 irsp
->un
.elsreq64
.remoteID
);
824 ndlp
= lpfc_findnode_did(vport
, irsp
->un
.elsreq64
.remoteID
);
826 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
827 "0136 PLOGI completes to NPort x%x "
828 "with no ndlp. Data: x%x x%x x%x\n",
829 irsp
->un
.elsreq64
.remoteID
,
830 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
835 /* Since ndlp can be freed in the disc state machine, note if this node
836 * is being used during discovery.
838 spin_lock_irq(shost
->host_lock
);
839 disc
= (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
);
840 ndlp
->nlp_flag
&= ~NLP_NPR_2B_DISC
;
841 spin_unlock_irq(shost
->host_lock
);
844 /* PLOGI completes to NPort <nlp_DID> */
845 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
846 "0102 PLOGI completes to NPort x%x "
847 "Data: x%x x%x x%x x%x x%x\n",
848 ndlp
->nlp_DID
, irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
849 irsp
->ulpTimeout
, disc
, vport
->num_disc_nodes
);
850 /* Check to see if link went down during discovery */
851 if (lpfc_els_chk_latt(vport
)) {
852 spin_lock_irq(shost
->host_lock
);
853 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
854 spin_unlock_irq(shost
->host_lock
);
858 /* ndlp could be freed in DSM, save these values now */
859 type
= ndlp
->nlp_type
;
862 if (irsp
->ulpStatus
) {
863 /* Check for retry */
864 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
)) {
865 /* ELS command is being retried */
867 spin_lock_irq(shost
->host_lock
);
868 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
869 spin_unlock_irq(shost
->host_lock
);
874 if (ndlp
->nlp_DID
== NameServer_DID
) {
875 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
876 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
877 "0250 Nameserver login error: "
879 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4]);
881 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
882 if (lpfc_error_lost_link(irsp
)) {
883 rc
= NLP_STE_FREED_NODE
;
885 rc
= lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
889 /* Good status, call state machine */
890 prsp
= list_entry(((struct lpfc_dmabuf
*)
891 cmdiocb
->context2
)->list
.next
,
892 struct lpfc_dmabuf
, list
);
893 ndlp
= lpfc_plogi_confirm_nport(phba
, prsp
->virt
, ndlp
);
894 rc
= lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
898 if (disc
&& vport
->num_disc_nodes
) {
899 /* Check to see if there are more PLOGIs to be sent */
900 lpfc_more_plogi(vport
);
902 if (vport
->num_disc_nodes
== 0) {
903 spin_lock_irq(shost
->host_lock
);
904 vport
->fc_flag
&= ~FC_NDISC_ACTIVE
;
905 spin_unlock_irq(shost
->host_lock
);
907 lpfc_can_disctmo(vport
);
908 if (vport
->fc_flag
& FC_RSCN_MODE
) {
910 * Check to see if more RSCNs came in while
911 * we were processing this one.
913 if ((vport
->fc_rscn_id_cnt
== 0) &&
914 (!(vport
->fc_flag
& FC_RSCN_DISCOVERY
))) {
915 spin_lock_irq(shost
->host_lock
);
916 vport
->fc_flag
&= ~FC_RSCN_MODE
;
917 spin_unlock_irq(shost
->host_lock
);
919 lpfc_els_handle_rscn(vport
);
926 lpfc_els_free_iocb(phba
, cmdiocb
);
931 lpfc_issue_els_plogi(struct lpfc_vport
*vport
, uint32_t did
, uint8_t retry
)
933 struct lpfc_hba
*phba
= vport
->phba
;
934 struct serv_parm
*sp
;
936 struct lpfc_iocbq
*elsiocb
;
937 struct lpfc_sli_ring
*pring
;
938 struct lpfc_sli
*psli
;
944 pring
= &psli
->ring
[LPFC_ELS_RING
]; /* ELS ring */
946 cmdsize
= (sizeof(uint32_t) + sizeof(struct serv_parm
));
947 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, NULL
, did
,
952 icmd
= &elsiocb
->iocb
;
953 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
955 /* For PLOGI request, remainder of payload is service parameters */
956 *((uint32_t *) (pcmd
)) = ELS_CMD_PLOGI
;
957 pcmd
+= sizeof(uint32_t);
958 memcpy(pcmd
, &vport
->fc_sparam
, sizeof(struct serv_parm
));
959 sp
= (struct serv_parm
*) pcmd
;
961 if (sp
->cmn
.fcphLow
< FC_PH_4_3
)
962 sp
->cmn
.fcphLow
= FC_PH_4_3
;
964 if (sp
->cmn
.fcphHigh
< FC_PH3
)
965 sp
->cmn
.fcphHigh
= FC_PH3
;
967 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
968 "Issue PLOGI: did:x%x",
971 phba
->fc_stat
.elsXmitPLOGI
++;
972 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_plogi
;
973 ret
= lpfc_sli_issue_iocb(phba
, pring
, elsiocb
, 0);
975 if (ret
== IOCB_ERROR
) {
976 lpfc_els_free_iocb(phba
, elsiocb
);
983 lpfc_cmpl_els_prli(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
984 struct lpfc_iocbq
*rspiocb
)
986 struct lpfc_vport
*vport
= cmdiocb
->vport
;
987 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
989 struct lpfc_sli
*psli
;
990 struct lpfc_nodelist
*ndlp
;
993 /* we pass cmdiocb to state machine which needs rspiocb as well */
994 cmdiocb
->context_un
.rsp_iocb
= rspiocb
;
996 irsp
= &(rspiocb
->iocb
);
997 ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
998 spin_lock_irq(shost
->host_lock
);
999 ndlp
->nlp_flag
&= ~NLP_PRLI_SND
;
1000 spin_unlock_irq(shost
->host_lock
);
1002 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1003 "PRLI cmpl: status:x%x/x%x did:x%x",
1004 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1006 /* PRLI completes to NPort <nlp_DID> */
1007 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
1008 "0103 PRLI completes to NPort x%x "
1009 "Data: x%x x%x x%x x%x\n",
1010 ndlp
->nlp_DID
, irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1011 irsp
->ulpTimeout
, vport
->num_disc_nodes
);
1013 vport
->fc_prli_sent
--;
1014 /* Check to see if link went down during discovery */
1015 if (lpfc_els_chk_latt(vport
))
1018 if (irsp
->ulpStatus
) {
1019 /* Check for retry */
1020 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
)) {
1021 /* ELS command is being retried */
1025 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1026 if (lpfc_error_lost_link(irsp
)) {
1029 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
1033 /* Good status, call state machine */
1034 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
1039 lpfc_els_free_iocb(phba
, cmdiocb
);
1044 lpfc_issue_els_prli(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1047 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1048 struct lpfc_hba
*phba
= vport
->phba
;
1051 struct lpfc_iocbq
*elsiocb
;
1052 struct lpfc_sli_ring
*pring
;
1053 struct lpfc_sli
*psli
;
1058 pring
= &psli
->ring
[LPFC_ELS_RING
]; /* ELS ring */
1060 cmdsize
= (sizeof(uint32_t) + sizeof(PRLI
));
1061 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
1062 ndlp
->nlp_DID
, ELS_CMD_PRLI
);
1066 icmd
= &elsiocb
->iocb
;
1067 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
1069 /* For PRLI request, remainder of payload is service parameters */
1070 memset(pcmd
, 0, (sizeof(PRLI
) + sizeof(uint32_t)));
1071 *((uint32_t *) (pcmd
)) = ELS_CMD_PRLI
;
1072 pcmd
+= sizeof(uint32_t);
1074 /* For PRLI, remainder of payload is PRLI parameter page */
1075 npr
= (PRLI
*) pcmd
;
1077 * If our firmware version is 3.20 or later,
1078 * set the following bits for FC-TAPE support.
1080 if (phba
->vpd
.rev
.feaLevelHigh
>= 0x02) {
1081 npr
->ConfmComplAllowed
= 1;
1083 npr
->TaskRetryIdReq
= 1;
1085 npr
->estabImagePair
= 1;
1086 npr
->readXferRdyDis
= 1;
1088 /* For FCP support */
1089 npr
->prliType
= PRLI_FCP_TYPE
;
1090 npr
->initiatorFunc
= 1;
1092 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1093 "Issue PRLI: did:x%x",
1094 ndlp
->nlp_DID
, 0, 0);
1096 phba
->fc_stat
.elsXmitPRLI
++;
1097 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_prli
;
1098 spin_lock_irq(shost
->host_lock
);
1099 ndlp
->nlp_flag
|= NLP_PRLI_SND
;
1100 spin_unlock_irq(shost
->host_lock
);
1101 if (lpfc_sli_issue_iocb(phba
, pring
, elsiocb
, 0) == IOCB_ERROR
) {
1102 spin_lock_irq(shost
->host_lock
);
1103 ndlp
->nlp_flag
&= ~NLP_PRLI_SND
;
1104 spin_unlock_irq(shost
->host_lock
);
1105 lpfc_els_free_iocb(phba
, elsiocb
);
1108 vport
->fc_prli_sent
++;
1113 lpfc_more_adisc(struct lpfc_vport
*vport
)
1117 if (vport
->num_disc_nodes
)
1118 vport
->num_disc_nodes
--;
1119 /* Continue discovery with <num_disc_nodes> ADISCs to go */
1120 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
1121 "0210 Continue discovery with %d ADISCs to go "
1122 "Data: x%x x%x x%x\n",
1123 vport
->num_disc_nodes
, vport
->fc_adisc_cnt
,
1124 vport
->fc_flag
, vport
->port_state
);
1125 /* Check to see if there are more ADISCs to be sent */
1126 if (vport
->fc_flag
& FC_NLP_MORE
) {
1127 lpfc_set_disctmo(vport
);
1128 /* go thru NPR nodes and issue any remaining ELS ADISCs */
1129 sentadisc
= lpfc_els_disc_adisc(vport
);
1135 lpfc_rscn_disc(struct lpfc_vport
*vport
)
1137 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1139 lpfc_can_disctmo(vport
);
1141 /* RSCN discovery */
1142 /* go thru NPR nodes and issue ELS PLOGIs */
1143 if (vport
->fc_npr_cnt
)
1144 if (lpfc_els_disc_plogi(vport
))
1147 if (vport
->fc_flag
& FC_RSCN_MODE
) {
1148 /* Check to see if more RSCNs came in while we were
1149 * processing this one.
1151 if ((vport
->fc_rscn_id_cnt
== 0) &&
1152 (!(vport
->fc_flag
& FC_RSCN_DISCOVERY
))) {
1153 spin_lock_irq(shost
->host_lock
);
1154 vport
->fc_flag
&= ~FC_RSCN_MODE
;
1155 spin_unlock_irq(shost
->host_lock
);
1157 lpfc_els_handle_rscn(vport
);
1163 lpfc_cmpl_els_adisc(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
1164 struct lpfc_iocbq
*rspiocb
)
1166 struct lpfc_vport
*vport
= cmdiocb
->vport
;
1167 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1169 struct lpfc_nodelist
*ndlp
;
1172 /* we pass cmdiocb to state machine which needs rspiocb as well */
1173 cmdiocb
->context_un
.rsp_iocb
= rspiocb
;
1175 irsp
= &(rspiocb
->iocb
);
1176 ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
1178 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1179 "ADISC cmpl: status:x%x/x%x did:x%x",
1180 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1183 /* Since ndlp can be freed in the disc state machine, note if this node
1184 * is being used during discovery.
1186 spin_lock_irq(shost
->host_lock
);
1187 disc
= (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
);
1188 ndlp
->nlp_flag
&= ~(NLP_ADISC_SND
| NLP_NPR_2B_DISC
);
1189 spin_unlock_irq(shost
->host_lock
);
1190 /* ADISC completes to NPort <nlp_DID> */
1191 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
1192 "0104 ADISC completes to NPort x%x "
1193 "Data: x%x x%x x%x x%x x%x\n",
1194 ndlp
->nlp_DID
, irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1195 irsp
->ulpTimeout
, disc
, vport
->num_disc_nodes
);
1196 /* Check to see if link went down during discovery */
1197 if (lpfc_els_chk_latt(vport
)) {
1198 spin_lock_irq(shost
->host_lock
);
1199 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
1200 spin_unlock_irq(shost
->host_lock
);
1204 if (irsp
->ulpStatus
) {
1205 /* Check for retry */
1206 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
)) {
1207 /* ELS command is being retried */
1209 spin_lock_irq(shost
->host_lock
);
1210 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
1211 spin_unlock_irq(shost
->host_lock
);
1212 lpfc_set_disctmo(vport
);
1217 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1218 if (!lpfc_error_lost_link(irsp
)) {
1219 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
1220 NLP_EVT_CMPL_ADISC
);
1223 /* Good status, call state machine */
1224 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
1225 NLP_EVT_CMPL_ADISC
);
1228 if (disc
&& vport
->num_disc_nodes
) {
1229 /* Check to see if there are more ADISCs to be sent */
1230 lpfc_more_adisc(vport
);
1232 /* Check to see if we are done with ADISC authentication */
1233 if (vport
->num_disc_nodes
== 0) {
1234 /* If we get here, there is nothing left to ADISC */
1236 * For NPIV, cmpl_reg_vpi will set port_state to READY,
1237 * and continue discovery.
1239 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
1240 !(vport
->fc_flag
& FC_RSCN_MODE
)) {
1241 lpfc_issue_reg_vpi(phba
, vport
);
1245 * For SLI2, we need to set port_state to READY
1246 * and continue discovery.
1248 if (vport
->port_state
< LPFC_VPORT_READY
) {
1249 /* If we get here, there is nothing to ADISC */
1250 if (vport
->port_type
== LPFC_PHYSICAL_PORT
)
1251 lpfc_issue_clear_la(phba
, vport
);
1253 if (!(vport
->fc_flag
& FC_ABORT_DISCOVERY
)) {
1254 vport
->num_disc_nodes
= 0;
1255 /* go thru NPR list, issue ELS PLOGIs */
1256 if (vport
->fc_npr_cnt
)
1257 lpfc_els_disc_plogi(vport
);
1259 if (!vport
->num_disc_nodes
) {
1260 spin_lock_irq(shost
->host_lock
);
1265 lpfc_can_disctmo(vport
);
1268 vport
->port_state
= LPFC_VPORT_READY
;
1270 lpfc_rscn_disc(vport
);
1275 lpfc_els_free_iocb(phba
, cmdiocb
);
1280 lpfc_issue_els_adisc(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1283 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1284 struct lpfc_hba
*phba
= vport
->phba
;
1287 struct lpfc_iocbq
*elsiocb
;
1288 struct lpfc_sli
*psli
= &phba
->sli
;
1289 struct lpfc_sli_ring
*pring
= &psli
->ring
[LPFC_ELS_RING
];
1293 cmdsize
= (sizeof(uint32_t) + sizeof(ADISC
));
1294 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
1295 ndlp
->nlp_DID
, ELS_CMD_ADISC
);
1299 icmd
= &elsiocb
->iocb
;
1300 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
1302 /* For ADISC request, remainder of payload is service parameters */
1303 *((uint32_t *) (pcmd
)) = ELS_CMD_ADISC
;
1304 pcmd
+= sizeof(uint32_t);
1306 /* Fill in ADISC payload */
1307 ap
= (ADISC
*) pcmd
;
1308 ap
->hardAL_PA
= phba
->fc_pref_ALPA
;
1309 memcpy(&ap
->portName
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
1310 memcpy(&ap
->nodeName
, &vport
->fc_nodename
, sizeof(struct lpfc_name
));
1311 ap
->DID
= be32_to_cpu(vport
->fc_myDID
);
1313 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1314 "Issue ADISC: did:x%x",
1315 ndlp
->nlp_DID
, 0, 0);
1317 phba
->fc_stat
.elsXmitADISC
++;
1318 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_adisc
;
1319 spin_lock_irq(shost
->host_lock
);
1320 ndlp
->nlp_flag
|= NLP_ADISC_SND
;
1321 spin_unlock_irq(shost
->host_lock
);
1322 if (lpfc_sli_issue_iocb(phba
, pring
, elsiocb
, 0) == IOCB_ERROR
) {
1323 spin_lock_irq(shost
->host_lock
);
1324 ndlp
->nlp_flag
&= ~NLP_ADISC_SND
;
1325 spin_unlock_irq(shost
->host_lock
);
1326 lpfc_els_free_iocb(phba
, elsiocb
);
1333 lpfc_cmpl_els_logo(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
1334 struct lpfc_iocbq
*rspiocb
)
1336 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
1337 struct lpfc_vport
*vport
= ndlp
->vport
;
1338 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1340 struct lpfc_sli
*psli
;
1343 /* we pass cmdiocb to state machine which needs rspiocb as well */
1344 cmdiocb
->context_un
.rsp_iocb
= rspiocb
;
1346 irsp
= &(rspiocb
->iocb
);
1347 spin_lock_irq(shost
->host_lock
);
1348 ndlp
->nlp_flag
&= ~NLP_LOGO_SND
;
1349 spin_unlock_irq(shost
->host_lock
);
1351 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1352 "LOGO cmpl: status:x%x/x%x did:x%x",
1353 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1355 /* LOGO completes to NPort <nlp_DID> */
1356 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
1357 "0105 LOGO completes to NPort x%x "
1358 "Data: x%x x%x x%x x%x\n",
1359 ndlp
->nlp_DID
, irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1360 irsp
->ulpTimeout
, vport
->num_disc_nodes
);
1361 /* Check to see if link went down during discovery */
1362 if (lpfc_els_chk_latt(vport
))
1365 if (ndlp
->nlp_flag
& NLP_TARGET_REMOVE
) {
1366 /* NLP_EVT_DEVICE_RM should unregister the RPI
1367 * which should abort all outstanding IOs.
1369 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
1374 if (irsp
->ulpStatus
) {
1375 /* Check for retry */
1376 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
))
1377 /* ELS command is being retried */
1380 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1381 if (lpfc_error_lost_link(irsp
))
1384 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
1387 /* Good status, call state machine.
1388 * This will unregister the rpi if needed.
1390 lpfc_disc_state_machine(vport
, ndlp
, cmdiocb
,
1395 lpfc_els_free_iocb(phba
, cmdiocb
);
1400 lpfc_issue_els_logo(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1403 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1404 struct lpfc_hba
*phba
= vport
->phba
;
1406 struct lpfc_iocbq
*elsiocb
;
1407 struct lpfc_sli_ring
*pring
;
1408 struct lpfc_sli
*psli
;
1414 pring
= &psli
->ring
[LPFC_ELS_RING
];
1416 cmdsize
= (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name
);
1417 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
1418 ndlp
->nlp_DID
, ELS_CMD_LOGO
);
1422 icmd
= &elsiocb
->iocb
;
1423 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
1424 *((uint32_t *) (pcmd
)) = ELS_CMD_LOGO
;
1425 pcmd
+= sizeof(uint32_t);
1427 /* Fill in LOGO payload */
1428 *((uint32_t *) (pcmd
)) = be32_to_cpu(vport
->fc_myDID
);
1429 pcmd
+= sizeof(uint32_t);
1430 memcpy(pcmd
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
1432 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1433 "Issue LOGO: did:x%x",
1434 ndlp
->nlp_DID
, 0, 0);
1436 phba
->fc_stat
.elsXmitLOGO
++;
1437 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_logo
;
1438 spin_lock_irq(shost
->host_lock
);
1439 ndlp
->nlp_flag
|= NLP_LOGO_SND
;
1440 spin_unlock_irq(shost
->host_lock
);
1441 rc
= lpfc_sli_issue_iocb(phba
, pring
, elsiocb
, 0);
1443 if (rc
== IOCB_ERROR
) {
1444 spin_lock_irq(shost
->host_lock
);
1445 ndlp
->nlp_flag
&= ~NLP_LOGO_SND
;
1446 spin_unlock_irq(shost
->host_lock
);
1447 lpfc_els_free_iocb(phba
, elsiocb
);
1454 lpfc_cmpl_els_cmd(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
1455 struct lpfc_iocbq
*rspiocb
)
1457 struct lpfc_vport
*vport
= cmdiocb
->vport
;
1460 irsp
= &rspiocb
->iocb
;
1462 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1463 "ELS cmd cmpl: status:x%x/x%x did:x%x",
1464 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
1465 irsp
->un
.elsreq64
.remoteID
);
1466 /* ELS cmd tag <ulpIoTag> completes */
1467 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
1468 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
1469 irsp
->ulpIoTag
, irsp
->ulpStatus
,
1470 irsp
->un
.ulpWord
[4], irsp
->ulpTimeout
);
1471 /* Check to see if link went down during discovery */
1472 lpfc_els_chk_latt(vport
);
1473 lpfc_els_free_iocb(phba
, cmdiocb
);
1478 lpfc_issue_els_scr(struct lpfc_vport
*vport
, uint32_t nportid
, uint8_t retry
)
1480 struct lpfc_hba
*phba
= vport
->phba
;
1482 struct lpfc_iocbq
*elsiocb
;
1483 struct lpfc_sli_ring
*pring
;
1484 struct lpfc_sli
*psli
;
1487 struct lpfc_nodelist
*ndlp
;
1490 pring
= &psli
->ring
[LPFC_ELS_RING
]; /* ELS ring */
1491 cmdsize
= (sizeof(uint32_t) + sizeof(SCR
));
1492 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
1496 lpfc_nlp_init(vport
, ndlp
, nportid
);
1498 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
1499 ndlp
->nlp_DID
, ELS_CMD_SCR
);
1506 icmd
= &elsiocb
->iocb
;
1507 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
1509 *((uint32_t *) (pcmd
)) = ELS_CMD_SCR
;
1510 pcmd
+= sizeof(uint32_t);
1512 /* For SCR, remainder of payload is SCR parameter page */
1513 memset(pcmd
, 0, sizeof(SCR
));
1514 ((SCR
*) pcmd
)->Function
= SCR_FUNC_FULL
;
1516 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1517 "Issue SCR: did:x%x",
1518 ndlp
->nlp_DID
, 0, 0);
1520 phba
->fc_stat
.elsXmitSCR
++;
1521 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_cmd
;
1522 if (lpfc_sli_issue_iocb(phba
, pring
, elsiocb
, 0) == IOCB_ERROR
) {
1524 lpfc_els_free_iocb(phba
, elsiocb
);
1532 lpfc_issue_els_farpr(struct lpfc_vport
*vport
, uint32_t nportid
, uint8_t retry
)
1534 struct lpfc_hba
*phba
= vport
->phba
;
1536 struct lpfc_iocbq
*elsiocb
;
1537 struct lpfc_sli_ring
*pring
;
1538 struct lpfc_sli
*psli
;
1543 struct lpfc_nodelist
*ondlp
;
1544 struct lpfc_nodelist
*ndlp
;
1547 pring
= &psli
->ring
[LPFC_ELS_RING
]; /* ELS ring */
1548 cmdsize
= (sizeof(uint32_t) + sizeof(FARP
));
1549 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
1553 lpfc_nlp_init(vport
, ndlp
, nportid
);
1555 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
,
1556 ndlp
->nlp_DID
, ELS_CMD_RNID
);
1562 icmd
= &elsiocb
->iocb
;
1563 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
1565 *((uint32_t *) (pcmd
)) = ELS_CMD_FARPR
;
1566 pcmd
+= sizeof(uint32_t);
1568 /* Fill in FARPR payload */
1569 fp
= (FARP
*) (pcmd
);
1570 memset(fp
, 0, sizeof(FARP
));
1571 lp
= (uint32_t *) pcmd
;
1572 *lp
++ = be32_to_cpu(nportid
);
1573 *lp
++ = be32_to_cpu(vport
->fc_myDID
);
1575 fp
->Mflags
= (FARP_MATCH_PORT
| FARP_MATCH_NODE
);
1577 memcpy(&fp
->RportName
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
1578 memcpy(&fp
->RnodeName
, &vport
->fc_nodename
, sizeof(struct lpfc_name
));
1579 ondlp
= lpfc_findnode_did(vport
, nportid
);
1581 memcpy(&fp
->OportName
, &ondlp
->nlp_portname
,
1582 sizeof(struct lpfc_name
));
1583 memcpy(&fp
->OnodeName
, &ondlp
->nlp_nodename
,
1584 sizeof(struct lpfc_name
));
1587 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1588 "Issue FARPR: did:x%x",
1589 ndlp
->nlp_DID
, 0, 0);
1591 phba
->fc_stat
.elsXmitFARPR
++;
1592 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_cmd
;
1593 if (lpfc_sli_issue_iocb(phba
, pring
, elsiocb
, 0) == IOCB_ERROR
) {
1595 lpfc_els_free_iocb(phba
, elsiocb
);
1603 lpfc_end_rscn(struct lpfc_vport
*vport
)
1605 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1607 if (vport
->fc_flag
& FC_RSCN_MODE
) {
1609 * Check to see if more RSCNs came in while we were
1610 * processing this one.
1612 if (vport
->fc_rscn_id_cnt
||
1613 (vport
->fc_flag
& FC_RSCN_DISCOVERY
) != 0)
1614 lpfc_els_handle_rscn(vport
);
1616 spin_lock_irq(shost
->host_lock
);
1617 vport
->fc_flag
&= ~FC_RSCN_MODE
;
1618 spin_unlock_irq(shost
->host_lock
);
1624 lpfc_cancel_retry_delay_tmo(struct lpfc_vport
*vport
, struct lpfc_nodelist
*nlp
)
1626 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1628 spin_lock_irq(shost
->host_lock
);
1629 nlp
->nlp_flag
&= ~NLP_DELAY_TMO
;
1630 spin_unlock_irq(shost
->host_lock
);
1631 del_timer_sync(&nlp
->nlp_delayfunc
);
1632 nlp
->nlp_last_elscmd
= 0;
1634 if (!list_empty(&nlp
->els_retry_evt
.evt_listp
))
1635 list_del_init(&nlp
->els_retry_evt
.evt_listp
);
1637 if (nlp
->nlp_flag
& NLP_NPR_2B_DISC
) {
1638 spin_lock_irq(shost
->host_lock
);
1639 nlp
->nlp_flag
&= ~NLP_NPR_2B_DISC
;
1640 spin_unlock_irq(shost
->host_lock
);
1641 if (vport
->num_disc_nodes
) {
1642 /* Check to see if there are more
1645 lpfc_more_plogi(vport
);
1647 if (vport
->num_disc_nodes
== 0) {
1648 spin_lock_irq(shost
->host_lock
);
1649 vport
->fc_flag
&= ~FC_NDISC_ACTIVE
;
1650 spin_unlock_irq(shost
->host_lock
);
1651 lpfc_can_disctmo(vport
);
1652 lpfc_end_rscn(vport
);
1660 lpfc_els_retry_delay(unsigned long ptr
)
1662 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) ptr
;
1663 struct lpfc_vport
*vport
= ndlp
->vport
;
1664 struct lpfc_hba
*phba
= vport
->phba
;
1665 unsigned long flags
;
1666 struct lpfc_work_evt
*evtp
= &ndlp
->els_retry_evt
;
1668 ndlp
= (struct lpfc_nodelist
*) ptr
;
1669 phba
= ndlp
->vport
->phba
;
1670 evtp
= &ndlp
->els_retry_evt
;
1672 spin_lock_irqsave(&phba
->hbalock
, flags
);
1673 if (!list_empty(&evtp
->evt_listp
)) {
1674 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1678 evtp
->evt_arg1
= ndlp
;
1679 evtp
->evt
= LPFC_EVT_ELS_RETRY
;
1680 list_add_tail(&evtp
->evt_listp
, &phba
->work_list
);
1681 if (phba
->work_wait
)
1682 lpfc_worker_wake_up(phba
);
1684 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
1689 lpfc_els_retry_delay_handler(struct lpfc_nodelist
*ndlp
)
1691 struct lpfc_vport
*vport
= ndlp
->vport
;
1692 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1693 uint32_t cmd
, did
, retry
;
1695 spin_lock_irq(shost
->host_lock
);
1696 did
= ndlp
->nlp_DID
;
1697 cmd
= ndlp
->nlp_last_elscmd
;
1698 ndlp
->nlp_last_elscmd
= 0;
1700 if (!(ndlp
->nlp_flag
& NLP_DELAY_TMO
)) {
1701 spin_unlock_irq(shost
->host_lock
);
1705 ndlp
->nlp_flag
&= ~NLP_DELAY_TMO
;
1706 spin_unlock_irq(shost
->host_lock
);
1708 * If a discovery event readded nlp_delayfunc after timer
1709 * firing and before processing the timer, cancel the
1712 del_timer_sync(&ndlp
->nlp_delayfunc
);
1713 retry
= ndlp
->nlp_retry
;
1717 lpfc_issue_els_flogi(vport
, ndlp
, retry
);
1720 if (!lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, retry
)) {
1721 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
1722 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
1726 if (!lpfc_issue_els_adisc(vport
, ndlp
, retry
)) {
1727 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
1728 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_ADISC_ISSUE
);
1732 if (!lpfc_issue_els_prli(vport
, ndlp
, retry
)) {
1733 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
1734 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PRLI_ISSUE
);
1738 if (!lpfc_issue_els_logo(vport
, ndlp
, retry
)) {
1739 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
1740 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
1744 lpfc_issue_els_fdisc(vport
, ndlp
, retry
);
1751 lpfc_els_retry(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
1752 struct lpfc_iocbq
*rspiocb
)
1754 struct lpfc_vport
*vport
= cmdiocb
->vport
;
1755 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1756 IOCB_t
*irsp
= &rspiocb
->iocb
;
1757 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
1758 struct lpfc_dmabuf
*pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
1761 int retry
= 0, maxretry
= lpfc_max_els_tries
, delay
= 0;
1766 /* Note: context2 may be 0 for internal driver abort
1767 * of delays ELS command.
1770 if (pcmd
&& pcmd
->virt
) {
1771 elscmd
= (uint32_t *) (pcmd
->virt
);
1776 did
= ndlp
->nlp_DID
;
1778 /* We should only hit this case for retrying PLOGI */
1779 did
= irsp
->un
.elsreq64
.remoteID
;
1780 ndlp
= lpfc_findnode_did(vport
, did
);
1781 if (!ndlp
&& (cmd
!= ELS_CMD_PLOGI
))
1785 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1786 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
1787 *(((uint32_t *) irsp
) + 7), irsp
->un
.ulpWord
[4], ndlp
->nlp_DID
);
1789 switch (irsp
->ulpStatus
) {
1790 case IOSTAT_FCP_RSP_ERROR
:
1791 case IOSTAT_REMOTE_STOP
:
1794 case IOSTAT_LOCAL_REJECT
:
1795 switch ((irsp
->un
.ulpWord
[4] & 0xff)) {
1796 case IOERR_LOOP_OPEN_FAILURE
:
1797 if (cmd
== ELS_CMD_PLOGI
&& cmdiocb
->retry
== 0)
1802 case IOERR_ILLEGAL_COMMAND
:
1803 if ((phba
->sli3_options
& LPFC_SLI3_VPORT_TEARDOWN
) &&
1804 (cmd
== ELS_CMD_FDISC
)) {
1805 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1806 "0124 FDISC failed (3/6) "
1808 lpfc_mbx_unreg_vpi(vport
);
1810 /* FDISC retry policy */
1812 if (cmdiocb
->retry
>= 32)
1817 case IOERR_NO_RESOURCES
:
1819 if (cmdiocb
->retry
> 100)
1824 case IOERR_ILLEGAL_FRAME
:
1829 case IOERR_SEQUENCE_TIMEOUT
:
1830 case IOERR_INVALID_RPI
:
1836 case IOSTAT_NPORT_RJT
:
1837 case IOSTAT_FABRIC_RJT
:
1838 if (irsp
->un
.ulpWord
[4] & RJT_UNAVAIL_TEMP
) {
1844 case IOSTAT_NPORT_BSY
:
1845 case IOSTAT_FABRIC_BSY
:
1850 stat
.un
.lsRjtError
= be32_to_cpu(irsp
->un
.ulpWord
[4]);
1851 /* Added for Vendor specifc support
1852 * Just keep retrying for these Rsn / Exp codes
1854 switch (stat
.un
.b
.lsRjtRsnCode
) {
1855 case LSRJT_UNABLE_TPC
:
1856 if (stat
.un
.b
.lsRjtRsnCodeExp
==
1857 LSEXP_CMD_IN_PROGRESS
) {
1858 if (cmd
== ELS_CMD_PLOGI
) {
1865 if (cmd
== ELS_CMD_PLOGI
) {
1867 maxretry
= lpfc_max_els_tries
+ 1;
1871 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
1872 (cmd
== ELS_CMD_FDISC
) &&
1873 (stat
.un
.b
.lsRjtRsnCodeExp
== LSEXP_OUT_OF_RESOURCE
)){
1874 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1875 "0125 FDISC Failed (x%x). "
1876 "Fabric out of resources\n",
1877 stat
.un
.lsRjtError
);
1878 lpfc_vport_set_state(vport
,
1879 FC_VPORT_NO_FABRIC_RSCS
);
1883 case LSRJT_LOGICAL_BSY
:
1884 if ((cmd
== ELS_CMD_PLOGI
) ||
1885 (cmd
== ELS_CMD_PRLI
)) {
1888 } else if (cmd
== ELS_CMD_FDISC
) {
1889 /* FDISC retry policy */
1891 if (cmdiocb
->retry
>= 32)
1897 case LSRJT_LOGICAL_ERR
:
1898 case LSRJT_PROTOCOL_ERR
:
1899 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
1900 (cmd
== ELS_CMD_FDISC
) &&
1901 ((stat
.un
.b
.lsRjtRsnCodeExp
== LSEXP_INVALID_PNAME
) ||
1902 (stat
.un
.b
.lsRjtRsnCodeExp
== LSEXP_INVALID_NPORT_ID
))
1904 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1905 "0123 FDISC Failed (x%x). "
1906 "Fabric Detected Bad WWN\n",
1907 stat
.un
.lsRjtError
);
1908 lpfc_vport_set_state(vport
,
1909 FC_VPORT_FABRIC_REJ_WWN
);
1915 case IOSTAT_INTERMED_RSP
:
1923 if (did
== FDMI_DID
)
1926 if ((++cmdiocb
->retry
) >= maxretry
) {
1927 phba
->fc_stat
.elsRetryExceeded
++;
1931 if ((vport
->load_flag
& FC_UNLOADING
) != 0)
1936 /* Retry ELS command <elsCmd> to remote NPORT <did> */
1937 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
1938 "0107 Retry ELS command x%x to remote "
1939 "NPORT x%x Data: x%x x%x\n",
1940 cmd
, did
, cmdiocb
->retry
, delay
);
1942 if (((cmd
== ELS_CMD_PLOGI
) || (cmd
== ELS_CMD_ADISC
)) &&
1943 ((irsp
->ulpStatus
!= IOSTAT_LOCAL_REJECT
) ||
1944 ((irsp
->un
.ulpWord
[4] & 0xff) != IOERR_NO_RESOURCES
))) {
1945 /* Don't reset timer for no resources */
1947 /* If discovery / RSCN timer is running, reset it */
1948 if (timer_pending(&vport
->fc_disctmo
) ||
1949 (vport
->fc_flag
& FC_RSCN_MODE
))
1950 lpfc_set_disctmo(vport
);
1953 phba
->fc_stat
.elsXmitRetry
++;
1954 if (ndlp
&& delay
) {
1955 phba
->fc_stat
.elsDelayRetry
++;
1956 ndlp
->nlp_retry
= cmdiocb
->retry
;
1958 /* delay is specified in milliseconds */
1959 mod_timer(&ndlp
->nlp_delayfunc
,
1960 jiffies
+ msecs_to_jiffies(delay
));
1961 spin_lock_irq(shost
->host_lock
);
1962 ndlp
->nlp_flag
|= NLP_DELAY_TMO
;
1963 spin_unlock_irq(shost
->host_lock
);
1965 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
1966 if (cmd
== ELS_CMD_PRLI
)
1967 lpfc_nlp_set_state(vport
, ndlp
,
1968 NLP_STE_REG_LOGIN_ISSUE
);
1970 lpfc_nlp_set_state(vport
, ndlp
,
1972 ndlp
->nlp_last_elscmd
= cmd
;
1978 lpfc_issue_els_flogi(vport
, ndlp
, cmdiocb
->retry
);
1981 lpfc_issue_els_fdisc(vport
, ndlp
, cmdiocb
->retry
);
1985 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
1986 lpfc_nlp_set_state(vport
, ndlp
,
1987 NLP_STE_PLOGI_ISSUE
);
1989 lpfc_issue_els_plogi(vport
, did
, cmdiocb
->retry
);
1992 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
1993 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_ADISC_ISSUE
);
1994 lpfc_issue_els_adisc(vport
, ndlp
, cmdiocb
->retry
);
1997 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
1998 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PRLI_ISSUE
);
1999 lpfc_issue_els_prli(vport
, ndlp
, cmdiocb
->retry
);
2002 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
2003 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
2004 lpfc_issue_els_logo(vport
, ndlp
, cmdiocb
->retry
);
2008 /* No retry ELS command <elsCmd> to remote NPORT <did> */
2009 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
2010 "0108 No retry ELS command x%x to remote "
2011 "NPORT x%x Retried:%d Error:x%x/%x\n",
2012 cmd
, did
, cmdiocb
->retry
, irsp
->ulpStatus
,
2013 irsp
->un
.ulpWord
[4]);
2018 lpfc_els_free_iocb(struct lpfc_hba
*phba
, struct lpfc_iocbq
*elsiocb
)
2020 struct lpfc_dmabuf
*buf_ptr
, *buf_ptr1
;
2022 if (elsiocb
->context1
) {
2023 lpfc_nlp_put(elsiocb
->context1
);
2024 elsiocb
->context1
= NULL
;
2026 /* context2 = cmd, context2->next = rsp, context3 = bpl */
2027 if (elsiocb
->context2
) {
2028 buf_ptr1
= (struct lpfc_dmabuf
*) elsiocb
->context2
;
2029 /* Free the response before processing the command. */
2030 if (!list_empty(&buf_ptr1
->list
)) {
2031 list_remove_head(&buf_ptr1
->list
, buf_ptr
,
2034 lpfc_mbuf_free(phba
, buf_ptr
->virt
, buf_ptr
->phys
);
2037 lpfc_mbuf_free(phba
, buf_ptr1
->virt
, buf_ptr1
->phys
);
2041 if (elsiocb
->context3
) {
2042 buf_ptr
= (struct lpfc_dmabuf
*) elsiocb
->context3
;
2043 lpfc_mbuf_free(phba
, buf_ptr
->virt
, buf_ptr
->phys
);
2046 lpfc_sli_release_iocbq(phba
, elsiocb
);
2051 lpfc_cmpl_els_logo_acc(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
2052 struct lpfc_iocbq
*rspiocb
)
2054 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
2055 struct lpfc_vport
*vport
= cmdiocb
->vport
;
2058 irsp
= &rspiocb
->iocb
;
2059 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
2060 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
2061 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4], ndlp
->nlp_DID
);
2062 /* ACC to LOGO completes to NPort <nlp_DID> */
2063 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
2064 "0109 ACC to LOGO completes to NPort x%x "
2065 "Data: x%x x%x x%x\n",
2066 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
2068 switch (ndlp
->nlp_state
) {
2069 case NLP_STE_UNUSED_NODE
: /* node is just allocated */
2070 lpfc_drop_node(vport
, ndlp
);
2072 case NLP_STE_NPR_NODE
: /* NPort Recovery mode */
2073 lpfc_unreg_rpi(vport
, ndlp
);
2078 lpfc_els_free_iocb(phba
, cmdiocb
);
2083 lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
2085 struct lpfc_dmabuf
*mp
= (struct lpfc_dmabuf
*) (pmb
->context1
);
2086 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
2088 pmb
->context1
= NULL
;
2089 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
2091 mempool_free(pmb
, phba
->mbox_mem_pool
);
2097 lpfc_cmpl_els_rsp(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
2098 struct lpfc_iocbq
*rspiocb
)
2100 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
2101 struct lpfc_vport
*vport
= ndlp
? ndlp
->vport
: NULL
;
2102 struct Scsi_Host
*shost
= vport
? lpfc_shost_from_vport(vport
) : NULL
;
2104 LPFC_MBOXQ_t
*mbox
= NULL
;
2105 struct lpfc_dmabuf
*mp
= NULL
;
2107 irsp
= &rspiocb
->iocb
;
2109 if (cmdiocb
->context_un
.mbox
)
2110 mbox
= cmdiocb
->context_un
.mbox
;
2112 /* Check to see if link went down during discovery */
2113 if (!ndlp
|| lpfc_els_chk_latt(vport
)) {
2115 mp
= (struct lpfc_dmabuf
*) mbox
->context1
;
2117 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
2120 mempool_free(mbox
, phba
->mbox_mem_pool
);
2125 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
2126 "ELS rsp cmpl: status:x%x/x%x did:x%x",
2127 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
2128 cmdiocb
->iocb
.un
.elsreq64
.remoteID
);
2129 /* ELS response tag <ulpIoTag> completes */
2130 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
2131 "0110 ELS response tag x%x completes "
2132 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
2133 cmdiocb
->iocb
.ulpIoTag
, rspiocb
->iocb
.ulpStatus
,
2134 rspiocb
->iocb
.un
.ulpWord
[4], rspiocb
->iocb
.ulpTimeout
,
2135 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
2138 if ((rspiocb
->iocb
.ulpStatus
== 0)
2139 && (ndlp
->nlp_flag
& NLP_ACC_REGLOGIN
)) {
2140 lpfc_unreg_rpi(vport
, ndlp
);
2141 mbox
->context2
= lpfc_nlp_get(ndlp
);
2142 mbox
->vport
= vport
;
2143 if (ndlp
->nlp_flag
& NLP_RM_DFLT_RPI
) {
2144 mbox
->mbox_flag
|= LPFC_MBX_IMED_UNREG
;
2145 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_dflt_rpi
;
2148 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_reg_login
;
2149 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
2150 lpfc_nlp_set_state(vport
, ndlp
,
2151 NLP_STE_REG_LOGIN_ISSUE
);
2153 if (lpfc_sli_issue_mbox(phba
, mbox
,
2154 (MBX_NOWAIT
| MBX_STOP_IOCB
))
2155 != MBX_NOT_FINISHED
) {
2159 /* NOTE: we should have messages for unsuccessful
2162 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
2163 if (!lpfc_error_lost_link(irsp
) &&
2164 ndlp
->nlp_flag
& NLP_ACC_REGLOGIN
) {
2165 lpfc_drop_node(vport
, ndlp
);
2169 mp
= (struct lpfc_dmabuf
*) mbox
->context1
;
2171 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
2174 mempool_free(mbox
, phba
->mbox_mem_pool
);
2178 spin_lock_irq(shost
->host_lock
);
2179 ndlp
->nlp_flag
&= ~(NLP_ACC_REGLOGIN
| NLP_RM_DFLT_RPI
);
2180 spin_unlock_irq(shost
->host_lock
);
2182 lpfc_els_free_iocb(phba
, cmdiocb
);
2187 lpfc_els_rsp_acc(struct lpfc_vport
*vport
, uint32_t flag
,
2188 struct lpfc_iocbq
*oldiocb
, struct lpfc_nodelist
*ndlp
,
2191 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2192 struct lpfc_hba
*phba
= vport
->phba
;
2195 struct lpfc_iocbq
*elsiocb
;
2196 struct lpfc_sli_ring
*pring
;
2197 struct lpfc_sli
*psli
;
2201 ELS_PKT
*els_pkt_ptr
;
2204 pring
= &psli
->ring
[LPFC_ELS_RING
]; /* ELS ring */
2205 oldcmd
= &oldiocb
->iocb
;
2209 cmdsize
= sizeof(uint32_t);
2210 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
,
2211 ndlp
, ndlp
->nlp_DID
, ELS_CMD_ACC
);
2213 spin_lock_irq(shost
->host_lock
);
2214 ndlp
->nlp_flag
&= ~NLP_LOGO_ACC
;
2215 spin_unlock_irq(shost
->host_lock
);
2219 icmd
= &elsiocb
->iocb
;
2220 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri */
2221 pcmd
= (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
2222 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
2223 pcmd
+= sizeof(uint32_t);
2225 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
2226 "Issue ACC: did:x%x flg:x%x",
2227 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
2230 cmdsize
= (sizeof(struct serv_parm
) + sizeof(uint32_t));
2231 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
,
2232 ndlp
, ndlp
->nlp_DID
, ELS_CMD_ACC
);
2236 icmd
= &elsiocb
->iocb
;
2237 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri */
2238 pcmd
= (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
2241 elsiocb
->context_un
.mbox
= mbox
;
2243 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
2244 pcmd
+= sizeof(uint32_t);
2245 memcpy(pcmd
, &vport
->fc_sparam
, sizeof(struct serv_parm
));
2247 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
2248 "Issue ACC PLOGI: did:x%x flg:x%x",
2249 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
2252 cmdsize
= sizeof(uint32_t) + sizeof(PRLO
);
2253 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
,
2254 ndlp
, ndlp
->nlp_DID
, ELS_CMD_PRLO
);
2258 icmd
= &elsiocb
->iocb
;
2259 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri */
2260 pcmd
= (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
2262 memcpy(pcmd
, ((struct lpfc_dmabuf
*) oldiocb
->context2
)->virt
,
2263 sizeof(uint32_t) + sizeof(PRLO
));
2264 *((uint32_t *) (pcmd
)) = ELS_CMD_PRLO_ACC
;
2265 els_pkt_ptr
= (ELS_PKT
*) pcmd
;
2266 els_pkt_ptr
->un
.prlo
.acceptRspCode
= PRLO_REQ_EXECUTED
;
2268 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
2269 "Issue ACC PRLO: did:x%x flg:x%x",
2270 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
2275 /* Xmit ELS ACC response tag <ulpIoTag> */
2276 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
2277 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
2278 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n",
2279 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
2280 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
2282 if (ndlp
->nlp_flag
& NLP_LOGO_ACC
) {
2283 spin_lock_irq(shost
->host_lock
);
2284 ndlp
->nlp_flag
&= ~NLP_LOGO_ACC
;
2285 spin_unlock_irq(shost
->host_lock
);
2286 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_logo_acc
;
2288 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
2291 phba
->fc_stat
.elsXmitACC
++;
2292 rc
= lpfc_sli_issue_iocb(phba
, pring
, elsiocb
, 0);
2293 if (rc
== IOCB_ERROR
) {
2294 lpfc_els_free_iocb(phba
, elsiocb
);
2301 lpfc_els_rsp_reject(struct lpfc_vport
*vport
, uint32_t rejectError
,
2302 struct lpfc_iocbq
*oldiocb
, struct lpfc_nodelist
*ndlp
,
2305 struct lpfc_hba
*phba
= vport
->phba
;
2308 struct lpfc_iocbq
*elsiocb
;
2309 struct lpfc_sli_ring
*pring
;
2310 struct lpfc_sli
*psli
;
2316 pring
= &psli
->ring
[LPFC_ELS_RING
]; /* ELS ring */
2318 cmdsize
= 2 * sizeof(uint32_t);
2319 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
2320 ndlp
->nlp_DID
, ELS_CMD_LS_RJT
);
2324 icmd
= &elsiocb
->iocb
;
2325 oldcmd
= &oldiocb
->iocb
;
2326 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri */
2327 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
2329 *((uint32_t *) (pcmd
)) = ELS_CMD_LS_RJT
;
2330 pcmd
+= sizeof(uint32_t);
2331 *((uint32_t *) (pcmd
)) = rejectError
;
2334 elsiocb
->context_un
.mbox
= mbox
;
2336 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
2337 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
2338 "0129 Xmit ELS RJT x%x response tag x%x "
2339 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
2341 rejectError
, elsiocb
->iotag
,
2342 elsiocb
->iocb
.ulpContext
, ndlp
->nlp_DID
,
2343 ndlp
->nlp_flag
, ndlp
->nlp_state
, ndlp
->nlp_rpi
);
2344 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
2345 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
2346 ndlp
->nlp_DID
, ndlp
->nlp_flag
, rejectError
);
2348 phba
->fc_stat
.elsXmitLSRJT
++;
2349 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
2350 rc
= lpfc_sli_issue_iocb(phba
, pring
, elsiocb
, 0);
2352 /* If the node is in the UNUSED state, and we are sending
2353 * a reject, we are done with it. Release driver reference
2354 * count here. The outstanding els will release its reference on
2355 * completion and the node can be freed then.
2357 if (ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
)
2360 if (rc
== IOCB_ERROR
) {
2361 lpfc_els_free_iocb(phba
, elsiocb
);
2368 lpfc_els_rsp_adisc_acc(struct lpfc_vport
*vport
, struct lpfc_iocbq
*oldiocb
,
2369 struct lpfc_nodelist
*ndlp
)
2371 struct lpfc_hba
*phba
= vport
->phba
;
2372 struct lpfc_sli
*psli
= &phba
->sli
;
2373 struct lpfc_sli_ring
*pring
= &psli
->ring
[LPFC_ELS_RING
];
2375 IOCB_t
*icmd
, *oldcmd
;
2376 struct lpfc_iocbq
*elsiocb
;
2381 cmdsize
= sizeof(uint32_t) + sizeof(ADISC
);
2382 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
2383 ndlp
->nlp_DID
, ELS_CMD_ACC
);
2387 icmd
= &elsiocb
->iocb
;
2388 oldcmd
= &oldiocb
->iocb
;
2389 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri */
2391 /* Xmit ADISC ACC response tag <ulpIoTag> */
2392 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
2393 "0130 Xmit ADISC ACC response iotag x%x xri: "
2394 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
2395 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
2396 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
2398 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
2400 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
2401 pcmd
+= sizeof(uint32_t);
2403 ap
= (ADISC
*) (pcmd
);
2404 ap
->hardAL_PA
= phba
->fc_pref_ALPA
;
2405 memcpy(&ap
->portName
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
2406 memcpy(&ap
->nodeName
, &vport
->fc_nodename
, sizeof(struct lpfc_name
));
2407 ap
->DID
= be32_to_cpu(vport
->fc_myDID
);
2409 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
2410 "Issue ACC ADISC: did:x%x flg:x%x",
2411 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
2413 phba
->fc_stat
.elsXmitACC
++;
2414 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
2415 rc
= lpfc_sli_issue_iocb(phba
, pring
, elsiocb
, 0);
2416 if (rc
== IOCB_ERROR
) {
2417 lpfc_els_free_iocb(phba
, elsiocb
);
2424 lpfc_els_rsp_prli_acc(struct lpfc_vport
*vport
, struct lpfc_iocbq
*oldiocb
,
2425 struct lpfc_nodelist
*ndlp
)
2427 struct lpfc_hba
*phba
= vport
->phba
;
2432 struct lpfc_iocbq
*elsiocb
;
2433 struct lpfc_sli_ring
*pring
;
2434 struct lpfc_sli
*psli
;
2440 pring
= &psli
->ring
[LPFC_ELS_RING
]; /* ELS ring */
2442 cmdsize
= sizeof(uint32_t) + sizeof(PRLI
);
2443 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
2444 ndlp
->nlp_DID
, (ELS_CMD_ACC
| (ELS_CMD_PRLI
& ~ELS_RSP_MASK
)));
2448 icmd
= &elsiocb
->iocb
;
2449 oldcmd
= &oldiocb
->iocb
;
2450 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri */
2451 /* Xmit PRLI ACC response tag <ulpIoTag> */
2452 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
2453 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
2454 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
2455 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
2456 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
2458 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
2460 *((uint32_t *) (pcmd
)) = (ELS_CMD_ACC
| (ELS_CMD_PRLI
& ~ELS_RSP_MASK
));
2461 pcmd
+= sizeof(uint32_t);
2463 /* For PRLI, remainder of payload is PRLI parameter page */
2464 memset(pcmd
, 0, sizeof(PRLI
));
2466 npr
= (PRLI
*) pcmd
;
2469 * If our firmware version is 3.20 or later,
2470 * set the following bits for FC-TAPE support.
2472 if (vpd
->rev
.feaLevelHigh
>= 0x02) {
2473 npr
->ConfmComplAllowed
= 1;
2475 npr
->TaskRetryIdReq
= 1;
2478 npr
->acceptRspCode
= PRLI_REQ_EXECUTED
;
2479 npr
->estabImagePair
= 1;
2480 npr
->readXferRdyDis
= 1;
2481 npr
->ConfmComplAllowed
= 1;
2483 npr
->prliType
= PRLI_FCP_TYPE
;
2484 npr
->initiatorFunc
= 1;
2486 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
2487 "Issue ACC PRLI: did:x%x flg:x%x",
2488 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
2490 phba
->fc_stat
.elsXmitACC
++;
2491 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
2493 rc
= lpfc_sli_issue_iocb(phba
, pring
, elsiocb
, 0);
2494 if (rc
== IOCB_ERROR
) {
2495 lpfc_els_free_iocb(phba
, elsiocb
);
2502 lpfc_els_rsp_rnid_acc(struct lpfc_vport
*vport
, uint8_t format
,
2503 struct lpfc_iocbq
*oldiocb
, struct lpfc_nodelist
*ndlp
)
2505 struct lpfc_hba
*phba
= vport
->phba
;
2507 IOCB_t
*icmd
, *oldcmd
;
2508 struct lpfc_iocbq
*elsiocb
;
2509 struct lpfc_sli_ring
*pring
;
2510 struct lpfc_sli
*psli
;
2516 pring
= &psli
->ring
[LPFC_ELS_RING
];
2518 cmdsize
= sizeof(uint32_t) + sizeof(uint32_t)
2519 + (2 * sizeof(struct lpfc_name
));
2521 cmdsize
+= sizeof(RNID_TOP_DISC
);
2523 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
2524 ndlp
->nlp_DID
, ELS_CMD_ACC
);
2528 icmd
= &elsiocb
->iocb
;
2529 oldcmd
= &oldiocb
->iocb
;
2530 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri */
2531 /* Xmit RNID ACC response tag <ulpIoTag> */
2532 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
2533 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
2534 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
);
2535 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
2536 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
2537 pcmd
+= sizeof(uint32_t);
2539 memset(pcmd
, 0, sizeof(RNID
));
2540 rn
= (RNID
*) (pcmd
);
2541 rn
->Format
= format
;
2542 rn
->CommonLen
= (2 * sizeof(struct lpfc_name
));
2543 memcpy(&rn
->portName
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
2544 memcpy(&rn
->nodeName
, &vport
->fc_nodename
, sizeof(struct lpfc_name
));
2547 rn
->SpecificLen
= 0;
2549 case RNID_TOPOLOGY_DISC
:
2550 rn
->SpecificLen
= sizeof(RNID_TOP_DISC
);
2551 memcpy(&rn
->un
.topologyDisc
.portName
,
2552 &vport
->fc_portname
, sizeof(struct lpfc_name
));
2553 rn
->un
.topologyDisc
.unitType
= RNID_HBA
;
2554 rn
->un
.topologyDisc
.physPort
= 0;
2555 rn
->un
.topologyDisc
.attachedNodes
= 0;
2559 rn
->SpecificLen
= 0;
2563 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_RSP
,
2564 "Issue ACC RNID: did:x%x flg:x%x",
2565 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
2567 phba
->fc_stat
.elsXmitACC
++;
2568 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
2570 elsiocb
->context1
= NULL
; /* Don't need ndlp for cmpl,
2571 * it could be freed */
2573 rc
= lpfc_sli_issue_iocb(phba
, pring
, elsiocb
, 0);
2574 if (rc
== IOCB_ERROR
) {
2575 lpfc_els_free_iocb(phba
, elsiocb
);
2582 lpfc_els_disc_adisc(struct lpfc_vport
*vport
)
2584 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2585 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
2588 /* go thru NPR nodes and issue any remaining ELS ADISCs */
2589 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
, nlp_listp
) {
2590 if (ndlp
->nlp_state
== NLP_STE_NPR_NODE
&&
2591 (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) != 0 &&
2592 (ndlp
->nlp_flag
& NLP_NPR_ADISC
) != 0) {
2593 spin_lock_irq(shost
->host_lock
);
2594 ndlp
->nlp_flag
&= ~NLP_NPR_ADISC
;
2595 spin_unlock_irq(shost
->host_lock
);
2596 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
2597 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_ADISC_ISSUE
);
2598 lpfc_issue_els_adisc(vport
, ndlp
, 0);
2600 vport
->num_disc_nodes
++;
2601 if (vport
->num_disc_nodes
>=
2602 vport
->cfg_discovery_threads
) {
2603 spin_lock_irq(shost
->host_lock
);
2604 vport
->fc_flag
|= FC_NLP_MORE
;
2605 spin_unlock_irq(shost
->host_lock
);
2610 if (sentadisc
== 0) {
2611 spin_lock_irq(shost
->host_lock
);
2612 vport
->fc_flag
&= ~FC_NLP_MORE
;
2613 spin_unlock_irq(shost
->host_lock
);
2619 lpfc_els_disc_plogi(struct lpfc_vport
*vport
)
2621 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2622 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
2625 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
2626 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
, nlp_listp
) {
2627 if (ndlp
->nlp_state
== NLP_STE_NPR_NODE
&&
2628 (ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) != 0 &&
2629 (ndlp
->nlp_flag
& NLP_DELAY_TMO
) == 0 &&
2630 (ndlp
->nlp_flag
& NLP_NPR_ADISC
) == 0) {
2631 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
2632 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
2633 lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0);
2635 vport
->num_disc_nodes
++;
2636 if (vport
->num_disc_nodes
>=
2637 vport
->cfg_discovery_threads
) {
2638 spin_lock_irq(shost
->host_lock
);
2639 vport
->fc_flag
|= FC_NLP_MORE
;
2640 spin_unlock_irq(shost
->host_lock
);
2645 if (sentplogi
== 0) {
2646 spin_lock_irq(shost
->host_lock
);
2647 vport
->fc_flag
&= ~FC_NLP_MORE
;
2648 spin_unlock_irq(shost
->host_lock
);
2654 lpfc_els_flush_rscn(struct lpfc_vport
*vport
)
2656 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2657 struct lpfc_hba
*phba
= vport
->phba
;
2660 for (i
= 0; i
< vport
->fc_rscn_id_cnt
; i
++) {
2661 lpfc_in_buf_free(phba
, vport
->fc_rscn_id_list
[i
]);
2662 vport
->fc_rscn_id_list
[i
] = NULL
;
2664 spin_lock_irq(shost
->host_lock
);
2665 vport
->fc_rscn_id_cnt
= 0;
2666 vport
->fc_flag
&= ~(FC_RSCN_MODE
| FC_RSCN_DISCOVERY
);
2667 spin_unlock_irq(shost
->host_lock
);
2668 lpfc_can_disctmo(vport
);
2672 lpfc_rscn_payload_check(struct lpfc_vport
*vport
, uint32_t did
)
2677 uint32_t payload_len
, i
;
2679 ns_did
.un
.word
= did
;
2681 /* Never match fabric nodes for RSCNs */
2682 if ((did
& Fabric_DID_MASK
) == Fabric_DID_MASK
)
2685 /* If we are doing a FULL RSCN rediscovery, match everything */
2686 if (vport
->fc_flag
& FC_RSCN_DISCOVERY
)
2689 for (i
= 0; i
< vport
->fc_rscn_id_cnt
; i
++) {
2690 lp
= vport
->fc_rscn_id_list
[i
]->virt
;
2691 payload_len
= be32_to_cpu(*lp
++ & ~ELS_CMD_MASK
);
2692 payload_len
-= sizeof(uint32_t); /* take off word 0 */
2693 while (payload_len
) {
2694 rscn_did
.un
.word
= be32_to_cpu(*lp
++);
2695 payload_len
-= sizeof(uint32_t);
2696 switch (rscn_did
.un
.b
.resv
) {
2697 case 0: /* Single N_Port ID effected */
2698 if (ns_did
.un
.word
== rscn_did
.un
.word
)
2701 case 1: /* Whole N_Port Area effected */
2702 if ((ns_did
.un
.b
.domain
== rscn_did
.un
.b
.domain
)
2703 && (ns_did
.un
.b
.area
== rscn_did
.un
.b
.area
))
2706 case 2: /* Whole N_Port Domain effected */
2707 if (ns_did
.un
.b
.domain
== rscn_did
.un
.b
.domain
)
2711 /* Unknown Identifier in RSCN node */
2712 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
2713 "0217 Unknown Identifier in "
2714 "RSCN payload Data: x%x\n",
2716 case 3: /* Whole Fabric effected */
2725 lpfc_rscn_recovery_check(struct lpfc_vport
*vport
)
2727 struct lpfc_nodelist
*ndlp
= NULL
;
2729 /* Look at all nodes effected by pending RSCNs and move
2730 * them to NPR state.
2733 list_for_each_entry(ndlp
, &vport
->fc_nodes
, nlp_listp
) {
2734 if (ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
||
2735 lpfc_rscn_payload_check(vport
, ndlp
->nlp_DID
) == 0)
2738 lpfc_disc_state_machine(vport
, ndlp
, NULL
,
2739 NLP_EVT_DEVICE_RECOVERY
);
2742 * Make sure NLP_DELAY_TMO is NOT running after a device
2745 if (ndlp
->nlp_flag
& NLP_DELAY_TMO
)
2746 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
2753 lpfc_els_rcv_rscn(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
2754 struct lpfc_nodelist
*ndlp
)
2756 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2757 struct lpfc_hba
*phba
= vport
->phba
;
2758 struct lpfc_dmabuf
*pcmd
;
2759 uint32_t *lp
, *datap
;
2761 uint32_t payload_len
, length
, nportid
, *cmd
;
2762 int rscn_cnt
= vport
->fc_rscn_id_cnt
;
2763 int rscn_id
= 0, hba_id
= 0;
2766 icmd
= &cmdiocb
->iocb
;
2767 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
2768 lp
= (uint32_t *) pcmd
->virt
;
2770 payload_len
= be32_to_cpu(*lp
++ & ~ELS_CMD_MASK
);
2771 payload_len
-= sizeof(uint32_t); /* take off word 0 */
2773 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
2774 "0214 RSCN received Data: x%x x%x x%x x%x\n",
2775 vport
->fc_flag
, payload_len
, *lp
, rscn_cnt
);
2776 for (i
= 0; i
< payload_len
/sizeof(uint32_t); i
++)
2777 fc_host_post_event(shost
, fc_get_event_number(),
2778 FCH_EVT_RSCN
, lp
[i
]);
2780 /* If we are about to begin discovery, just ACC the RSCN.
2781 * Discovery processing will satisfy it.
2783 if (vport
->port_state
<= LPFC_NS_QRY
) {
2784 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
2785 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
2786 ndlp
->nlp_DID
, vport
->port_state
, ndlp
->nlp_flag
);
2788 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
2792 /* If this RSCN just contains NPortIDs for other vports on this HBA,
2793 * just ACC and ignore it.
2795 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
2796 !(vport
->cfg_peer_port_login
)) {
2801 nportid
= ((be32_to_cpu(nportid
)) & Mask_DID
);
2802 i
-= sizeof(uint32_t);
2804 if (lpfc_find_vport_by_did(phba
, nportid
))
2807 if (rscn_id
== hba_id
) {
2808 /* ALL NPortIDs in RSCN are on HBA */
2809 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
2811 "Data: x%x x%x x%x x%x\n",
2812 vport
->fc_flag
, payload_len
,
2814 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
2815 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
2816 ndlp
->nlp_DID
, vport
->port_state
,
2819 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
,
2825 /* If we are already processing an RSCN, save the received
2826 * RSCN payload buffer, cmdiocb->context2 to process later.
2828 if (vport
->fc_flag
& (FC_RSCN_MODE
| FC_NDISC_ACTIVE
)) {
2829 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
2830 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
2831 ndlp
->nlp_DID
, vport
->port_state
, ndlp
->nlp_flag
);
2833 vport
->fc_flag
|= FC_RSCN_DEFERRED
;
2834 if ((rscn_cnt
< FC_MAX_HOLD_RSCN
) &&
2835 !(vport
->fc_flag
& FC_RSCN_DISCOVERY
)) {
2836 spin_lock_irq(shost
->host_lock
);
2837 vport
->fc_flag
|= FC_RSCN_MODE
;
2838 spin_unlock_irq(shost
->host_lock
);
2840 cmd
= vport
->fc_rscn_id_list
[rscn_cnt
-1]->virt
;
2841 length
= be32_to_cpu(*cmd
& ~ELS_CMD_MASK
);
2844 (payload_len
+ length
<= LPFC_BPL_SIZE
)) {
2845 *cmd
&= ELS_CMD_MASK
;
2846 *cmd
|= be32_to_cpu(payload_len
+ length
);
2847 memcpy(((uint8_t *)cmd
) + length
, lp
,
2850 vport
->fc_rscn_id_list
[rscn_cnt
] = pcmd
;
2851 vport
->fc_rscn_id_cnt
++;
2852 /* If we zero, cmdiocb->context2, the calling
2853 * routine will not try to free it.
2855 cmdiocb
->context2
= NULL
;
2859 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
2860 "0235 Deferred RSCN "
2861 "Data: x%x x%x x%x\n",
2862 vport
->fc_rscn_id_cnt
, vport
->fc_flag
,
2865 spin_lock_irq(shost
->host_lock
);
2866 vport
->fc_flag
|= FC_RSCN_DISCOVERY
;
2867 spin_unlock_irq(shost
->host_lock
);
2868 /* ReDiscovery RSCN */
2869 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
2870 "0234 ReDiscovery RSCN "
2871 "Data: x%x x%x x%x\n",
2872 vport
->fc_rscn_id_cnt
, vport
->fc_flag
,
2876 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
2878 /* send RECOVERY event for ALL nodes that match RSCN payload */
2879 lpfc_rscn_recovery_check(vport
);
2880 vport
->fc_flag
&= ~FC_RSCN_DEFERRED
;
2884 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
2885 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
2886 ndlp
->nlp_DID
, vport
->port_state
, ndlp
->nlp_flag
);
2888 spin_lock_irq(shost
->host_lock
);
2889 vport
->fc_flag
|= FC_RSCN_MODE
;
2890 spin_unlock_irq(shost
->host_lock
);
2891 vport
->fc_rscn_id_list
[vport
->fc_rscn_id_cnt
++] = pcmd
;
2893 * If we zero, cmdiocb->context2, the calling routine will
2894 * not try to free it.
2896 cmdiocb
->context2
= NULL
;
2898 lpfc_set_disctmo(vport
);
2901 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
2903 /* send RECOVERY event for ALL nodes that match RSCN payload */
2904 lpfc_rscn_recovery_check(vport
);
2906 return lpfc_els_handle_rscn(vport
);
2910 lpfc_els_handle_rscn(struct lpfc_vport
*vport
)
2912 struct lpfc_nodelist
*ndlp
;
2913 struct lpfc_hba
*phba
= vport
->phba
;
2915 /* Ignore RSCN if the port is being torn down. */
2916 if (vport
->load_flag
& FC_UNLOADING
) {
2917 lpfc_els_flush_rscn(vport
);
2921 /* Start timer for RSCN processing */
2922 lpfc_set_disctmo(vport
);
2924 /* RSCN processed */
2925 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
2926 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
2927 vport
->fc_flag
, 0, vport
->fc_rscn_id_cnt
,
2930 /* To process RSCN, first compare RSCN data with NameServer */
2931 vport
->fc_ns_retry
= 0;
2932 ndlp
= lpfc_findnode_did(vport
, NameServer_DID
);
2933 if (ndlp
&& ndlp
->nlp_state
== NLP_STE_UNMAPPED_NODE
) {
2934 /* Good ndlp, issue CT Request to NameServer */
2935 if (lpfc_ns_cmd(vport
, SLI_CTNS_GID_FT
, 0, 0) == 0)
2936 /* Wait for NameServer query cmpl before we can
2940 /* If login to NameServer does not exist, issue one */
2941 /* Good status, issue PLOGI to NameServer */
2942 ndlp
= lpfc_findnode_did(vport
, NameServer_DID
);
2944 /* Wait for NameServer login cmpl before we can
2948 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
2950 lpfc_els_flush_rscn(vport
);
2953 lpfc_nlp_init(vport
, ndlp
, NameServer_DID
);
2954 ndlp
->nlp_type
|= NLP_FABRIC
;
2955 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
2956 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
2957 lpfc_issue_els_plogi(vport
, NameServer_DID
, 0);
2958 /* Wait for NameServer login cmpl before we can
2964 lpfc_els_flush_rscn(vport
);
2969 lpfc_els_rcv_flogi(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
2970 struct lpfc_nodelist
*ndlp
)
2972 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2973 struct lpfc_hba
*phba
= vport
->phba
;
2974 struct lpfc_dmabuf
*pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
2975 uint32_t *lp
= (uint32_t *) pcmd
->virt
;
2976 IOCB_t
*icmd
= &cmdiocb
->iocb
;
2977 struct serv_parm
*sp
;
2984 sp
= (struct serv_parm
*) lp
;
2986 /* FLOGI received */
2988 lpfc_set_disctmo(vport
);
2990 if (phba
->fc_topology
== TOPOLOGY_LOOP
) {
2991 /* We should never receive a FLOGI in loop mode, ignore it */
2992 did
= icmd
->un
.elsreq64
.remoteID
;
2994 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
2996 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
2997 "0113 An FLOGI ELS command x%x was "
2998 "received from DID x%x in Loop Mode\n",
3005 if ((lpfc_check_sparm(vport
, ndlp
, sp
, CLASS3
))) {
3006 /* For a FLOGI we accept, then if our portname is greater
3007 * then the remote portname we initiate Nport login.
3010 rc
= memcmp(&vport
->fc_portname
, &sp
->portName
,
3011 sizeof(struct lpfc_name
));
3014 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
3018 lpfc_linkdown(phba
);
3019 lpfc_init_link(phba
, mbox
,
3021 phba
->cfg_link_speed
);
3022 mbox
->mb
.un
.varInitLnk
.lipsr_AL_PA
= 0;
3023 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
3024 mbox
->vport
= vport
;
3025 rc
= lpfc_sli_issue_mbox
3026 (phba
, mbox
, (MBX_NOWAIT
| MBX_STOP_IOCB
));
3027 lpfc_set_loopback_flag(phba
);
3028 if (rc
== MBX_NOT_FINISHED
) {
3029 mempool_free(mbox
, phba
->mbox_mem_pool
);
3032 } else if (rc
> 0) { /* greater than */
3033 spin_lock_irq(shost
->host_lock
);
3034 vport
->fc_flag
|= FC_PT2PT_PLOGI
;
3035 spin_unlock_irq(shost
->host_lock
);
3037 spin_lock_irq(shost
->host_lock
);
3038 vport
->fc_flag
|= FC_PT2PT
;
3039 vport
->fc_flag
&= ~(FC_FABRIC
| FC_PUBLIC_LOOP
);
3040 spin_unlock_irq(shost
->host_lock
);
3042 /* Reject this request because invalid parameters */
3043 stat
.un
.b
.lsRjtRsvd0
= 0;
3044 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
3045 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_SPARM_OPTIONS
;
3046 stat
.un
.b
.vendorUnique
= 0;
3047 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
,
3053 lpfc_els_rsp_acc(vport
, ELS_CMD_PLOGI
, cmdiocb
, ndlp
, NULL
);
3059 lpfc_els_rcv_rnid(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
3060 struct lpfc_nodelist
*ndlp
)
3062 struct lpfc_dmabuf
*pcmd
;
3069 icmd
= &cmdiocb
->iocb
;
3070 did
= icmd
->un
.elsreq64
.remoteID
;
3071 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
3072 lp
= (uint32_t *) pcmd
->virt
;
3079 switch (rn
->Format
) {
3081 case RNID_TOPOLOGY_DISC
:
3083 lpfc_els_rsp_rnid_acc(vport
, rn
->Format
, cmdiocb
, ndlp
);
3086 /* Reject this request because format not supported */
3087 stat
.un
.b
.lsRjtRsvd0
= 0;
3088 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
3089 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CANT_GIVE_DATA
;
3090 stat
.un
.b
.vendorUnique
= 0;
3091 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
,
3098 lpfc_els_rcv_lirr(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
3099 struct lpfc_nodelist
*ndlp
)
3103 /* For now, unconditionally reject this command */
3104 stat
.un
.b
.lsRjtRsvd0
= 0;
3105 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
3106 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CANT_GIVE_DATA
;
3107 stat
.un
.b
.vendorUnique
= 0;
3108 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
3113 lpfc_els_rsp_rps_acc(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
3115 struct lpfc_sli
*psli
= &phba
->sli
;
3116 struct lpfc_sli_ring
*pring
= &psli
->ring
[LPFC_ELS_RING
];
3121 struct lpfc_iocbq
*elsiocb
;
3122 struct lpfc_nodelist
*ndlp
;
3123 uint16_t xri
, status
;
3128 ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
3129 xri
= (uint16_t) ((unsigned long)(pmb
->context1
));
3130 pmb
->context1
= NULL
;
3131 pmb
->context2
= NULL
;
3133 if (mb
->mbxStatus
) {
3134 mempool_free(pmb
, phba
->mbox_mem_pool
);
3138 cmdsize
= sizeof(RPS_RSP
) + sizeof(uint32_t);
3139 mempool_free(pmb
, phba
->mbox_mem_pool
);
3140 elsiocb
= lpfc_prep_els_iocb(phba
->pport
, 0, cmdsize
,
3141 lpfc_max_els_tries
, ndlp
,
3142 ndlp
->nlp_DID
, ELS_CMD_ACC
);
3147 icmd
= &elsiocb
->iocb
;
3148 icmd
->ulpContext
= xri
;
3150 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
3151 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
3152 pcmd
+= sizeof(uint32_t); /* Skip past command */
3153 rps_rsp
= (RPS_RSP
*)pcmd
;
3155 if (phba
->fc_topology
!= TOPOLOGY_LOOP
)
3159 if (phba
->pport
->fc_flag
& FC_FABRIC
)
3163 rps_rsp
->portStatus
= be16_to_cpu(status
);
3164 rps_rsp
->linkFailureCnt
= be32_to_cpu(mb
->un
.varRdLnk
.linkFailureCnt
);
3165 rps_rsp
->lossSyncCnt
= be32_to_cpu(mb
->un
.varRdLnk
.lossSyncCnt
);
3166 rps_rsp
->lossSignalCnt
= be32_to_cpu(mb
->un
.varRdLnk
.lossSignalCnt
);
3167 rps_rsp
->primSeqErrCnt
= be32_to_cpu(mb
->un
.varRdLnk
.primSeqErrCnt
);
3168 rps_rsp
->invalidXmitWord
= be32_to_cpu(mb
->un
.varRdLnk
.invalidXmitWord
);
3169 rps_rsp
->crcCnt
= be32_to_cpu(mb
->un
.varRdLnk
.crcCnt
);
3170 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
3171 lpfc_printf_vlog(ndlp
->vport
, KERN_INFO
, LOG_ELS
,
3172 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
3173 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
3174 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
3175 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
3177 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
3178 phba
->fc_stat
.elsXmitACC
++;
3179 if (lpfc_sli_issue_iocb(phba
, pring
, elsiocb
, 0) == IOCB_ERROR
)
3180 lpfc_els_free_iocb(phba
, elsiocb
);
3185 lpfc_els_rcv_rps(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
3186 struct lpfc_nodelist
*ndlp
)
3188 struct lpfc_hba
*phba
= vport
->phba
;
3192 struct lpfc_dmabuf
*pcmd
;
3196 if ((ndlp
->nlp_state
!= NLP_STE_UNMAPPED_NODE
) &&
3197 (ndlp
->nlp_state
!= NLP_STE_MAPPED_NODE
)) {
3198 stat
.un
.b
.lsRjtRsvd0
= 0;
3199 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
3200 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CANT_GIVE_DATA
;
3201 stat
.un
.b
.vendorUnique
= 0;
3202 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
,
3206 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
3207 lp
= (uint32_t *) pcmd
->virt
;
3208 flag
= (be32_to_cpu(*lp
++) & 0xf);
3212 ((flag
== 1) && (be32_to_cpu(rps
->un
.portNum
) == 0)) ||
3213 ((flag
== 2) && (memcmp(&rps
->un
.portName
, &vport
->fc_portname
,
3214 sizeof(struct lpfc_name
)) == 0))) {
3216 printk("Fix me....\n");
3218 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_ATOMIC
);
3220 lpfc_read_lnk_stat(phba
, mbox
);
3222 (void *)((unsigned long) cmdiocb
->iocb
.ulpContext
);
3223 mbox
->context2
= lpfc_nlp_get(ndlp
);
3224 mbox
->vport
= vport
;
3225 mbox
->mbox_cmpl
= lpfc_els_rsp_rps_acc
;
3226 if (lpfc_sli_issue_mbox (phba
, mbox
,
3227 (MBX_NOWAIT
| MBX_STOP_IOCB
)) != MBX_NOT_FINISHED
)
3228 /* Mbox completion will send ELS Response */
3232 mempool_free(mbox
, phba
->mbox_mem_pool
);
3235 stat
.un
.b
.lsRjtRsvd0
= 0;
3236 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
3237 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CANT_GIVE_DATA
;
3238 stat
.un
.b
.vendorUnique
= 0;
3239 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
, NULL
);
3244 lpfc_els_rsp_rpl_acc(struct lpfc_vport
*vport
, uint16_t cmdsize
,
3245 struct lpfc_iocbq
*oldiocb
, struct lpfc_nodelist
*ndlp
)
3247 struct lpfc_hba
*phba
= vport
->phba
;
3248 IOCB_t
*icmd
, *oldcmd
;
3250 struct lpfc_iocbq
*elsiocb
;
3251 struct lpfc_sli
*psli
= &phba
->sli
;
3252 struct lpfc_sli_ring
*pring
= &psli
->ring
[LPFC_ELS_RING
];
3255 elsiocb
= lpfc_prep_els_iocb(vport
, 0, cmdsize
, oldiocb
->retry
, ndlp
,
3256 ndlp
->nlp_DID
, ELS_CMD_ACC
);
3261 icmd
= &elsiocb
->iocb
;
3262 oldcmd
= &oldiocb
->iocb
;
3263 icmd
->ulpContext
= oldcmd
->ulpContext
; /* Xri */
3265 pcmd
= (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
3266 *((uint32_t *) (pcmd
)) = ELS_CMD_ACC
;
3267 pcmd
+= sizeof(uint16_t);
3268 *((uint16_t *)(pcmd
)) = be16_to_cpu(cmdsize
);
3269 pcmd
+= sizeof(uint16_t);
3271 /* Setup the RPL ACC payload */
3272 rpl_rsp
.listLen
= be32_to_cpu(1);
3274 rpl_rsp
.port_num_blk
.portNum
= 0;
3275 rpl_rsp
.port_num_blk
.portID
= be32_to_cpu(vport
->fc_myDID
);
3276 memcpy(&rpl_rsp
.port_num_blk
.portName
, &vport
->fc_portname
,
3277 sizeof(struct lpfc_name
));
3278 memcpy(pcmd
, &rpl_rsp
, cmdsize
- sizeof(uint32_t));
3279 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
3280 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3281 "0120 Xmit ELS RPL ACC response tag x%x "
3282 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
3284 elsiocb
->iotag
, elsiocb
->iocb
.ulpContext
,
3285 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_state
,
3287 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_rsp
;
3288 phba
->fc_stat
.elsXmitACC
++;
3289 if (lpfc_sli_issue_iocb(phba
, pring
, elsiocb
, 0) == IOCB_ERROR
) {
3290 lpfc_els_free_iocb(phba
, elsiocb
);
3297 lpfc_els_rcv_rpl(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
3298 struct lpfc_nodelist
*ndlp
)
3300 struct lpfc_dmabuf
*pcmd
;
3307 if ((ndlp
->nlp_state
!= NLP_STE_UNMAPPED_NODE
) &&
3308 (ndlp
->nlp_state
!= NLP_STE_MAPPED_NODE
)) {
3309 stat
.un
.b
.lsRjtRsvd0
= 0;
3310 stat
.un
.b
.lsRjtRsnCode
= LSRJT_UNABLE_TPC
;
3311 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_CANT_GIVE_DATA
;
3312 stat
.un
.b
.vendorUnique
= 0;
3313 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, cmdiocb
, ndlp
,
3317 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
3318 lp
= (uint32_t *) pcmd
->virt
;
3319 rpl
= (RPL
*) (lp
+ 1);
3321 maxsize
= be32_to_cpu(rpl
->maxsize
);
3323 /* We support only one port */
3324 if ((rpl
->index
== 0) &&
3326 ((maxsize
* sizeof(uint32_t)) >= sizeof(RPL_RSP
)))) {
3327 cmdsize
= sizeof(uint32_t) + sizeof(RPL_RSP
);
3329 cmdsize
= sizeof(uint32_t) + maxsize
* sizeof(uint32_t);
3331 lpfc_els_rsp_rpl_acc(vport
, cmdsize
, cmdiocb
, ndlp
);
3337 lpfc_els_rcv_farp(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
3338 struct lpfc_nodelist
*ndlp
)
3340 struct lpfc_dmabuf
*pcmd
;
3344 uint32_t cmd
, cnt
, did
;
3346 icmd
= &cmdiocb
->iocb
;
3347 did
= icmd
->un
.elsreq64
.remoteID
;
3348 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
3349 lp
= (uint32_t *) pcmd
->virt
;
3353 /* FARP-REQ received from DID <did> */
3354 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3355 "0601 FARP-REQ received from DID x%x\n", did
);
3356 /* We will only support match on WWPN or WWNN */
3357 if (fp
->Mflags
& ~(FARP_MATCH_NODE
| FARP_MATCH_PORT
)) {
3362 /* If this FARP command is searching for my portname */
3363 if (fp
->Mflags
& FARP_MATCH_PORT
) {
3364 if (memcmp(&fp
->RportName
, &vport
->fc_portname
,
3365 sizeof(struct lpfc_name
)) == 0)
3369 /* If this FARP command is searching for my nodename */
3370 if (fp
->Mflags
& FARP_MATCH_NODE
) {
3371 if (memcmp(&fp
->RnodeName
, &vport
->fc_nodename
,
3372 sizeof(struct lpfc_name
)) == 0)
3377 if ((ndlp
->nlp_state
== NLP_STE_UNMAPPED_NODE
) ||
3378 (ndlp
->nlp_state
== NLP_STE_MAPPED_NODE
)) {
3379 /* Log back into the node before sending the FARP. */
3380 if (fp
->Rflags
& FARP_REQUEST_PLOGI
) {
3381 ndlp
->nlp_prev_state
= ndlp
->nlp_state
;
3382 lpfc_nlp_set_state(vport
, ndlp
,
3383 NLP_STE_PLOGI_ISSUE
);
3384 lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0);
3387 /* Send a FARP response to that node */
3388 if (fp
->Rflags
& FARP_REQUEST_FARPR
)
3389 lpfc_issue_els_farpr(vport
, did
, 0);
3396 lpfc_els_rcv_farpr(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
3397 struct lpfc_nodelist
*ndlp
)
3399 struct lpfc_dmabuf
*pcmd
;
3404 icmd
= &cmdiocb
->iocb
;
3405 did
= icmd
->un
.elsreq64
.remoteID
;
3406 pcmd
= (struct lpfc_dmabuf
*) cmdiocb
->context2
;
3407 lp
= (uint32_t *) pcmd
->virt
;
3410 /* FARP-RSP received from DID <did> */
3411 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3412 "0600 FARP-RSP received from DID x%x\n", did
);
3413 /* ACCEPT the Farp resp request */
3414 lpfc_els_rsp_acc(vport
, ELS_CMD_ACC
, cmdiocb
, ndlp
, NULL
);
3420 lpfc_els_rcv_fan(struct lpfc_vport
*vport
, struct lpfc_iocbq
*cmdiocb
,
3421 struct lpfc_nodelist
*fan_ndlp
)
3423 struct lpfc_dmabuf
*pcmd
;
3428 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
3429 struct lpfc_hba
*phba
= vport
->phba
;
3432 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3433 "0265 FAN received\n");
3434 icmd
= &cmdiocb
->iocb
;
3435 did
= icmd
->un
.elsreq64
.remoteID
;
3436 pcmd
= (struct lpfc_dmabuf
*)cmdiocb
->context2
;
3437 lp
= (uint32_t *)pcmd
->virt
;
3442 /* FAN received; Fan does not have a reply sequence */
3444 if (phba
->pport
->port_state
== LPFC_LOCAL_CFG_LINK
) {
3445 if ((memcmp(&phba
->fc_fabparam
.nodeName
, &fp
->FnodeName
,
3446 sizeof(struct lpfc_name
)) != 0) ||
3447 (memcmp(&phba
->fc_fabparam
.portName
, &fp
->FportName
,
3448 sizeof(struct lpfc_name
)) != 0)) {
3450 * This node has switched fabrics. FLOGI is required
3451 * Clean up the old rpi's
3454 list_for_each_entry_safe(ndlp
, next_ndlp
,
3455 &vport
->fc_nodes
, nlp_listp
) {
3456 if (ndlp
->nlp_state
!= NLP_STE_NPR_NODE
)
3458 if (ndlp
->nlp_type
& NLP_FABRIC
) {
3460 * Clean up old Fabric, Nameserver and
3461 * other NLP_FABRIC logins
3463 lpfc_drop_node(vport
, ndlp
);
3464 } else if (!(ndlp
->nlp_flag
& NLP_NPR_ADISC
)) {
3465 /* Fail outstanding I/O now since this
3466 * device is marked for PLOGI
3468 lpfc_unreg_rpi(vport
, ndlp
);
3472 vport
->port_state
= LPFC_FLOGI
;
3473 lpfc_set_disctmo(vport
);
3474 lpfc_initial_flogi(vport
);
3477 /* Discovery not needed,
3478 * move the nodes to their original state.
3480 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
,
3482 if (ndlp
->nlp_state
!= NLP_STE_NPR_NODE
)
3485 switch (ndlp
->nlp_prev_state
) {
3486 case NLP_STE_UNMAPPED_NODE
:
3487 ndlp
->nlp_prev_state
= NLP_STE_NPR_NODE
;
3488 lpfc_nlp_set_state(vport
, ndlp
,
3489 NLP_STE_UNMAPPED_NODE
);
3492 case NLP_STE_MAPPED_NODE
:
3493 ndlp
->nlp_prev_state
= NLP_STE_NPR_NODE
;
3494 lpfc_nlp_set_state(vport
, ndlp
,
3495 NLP_STE_MAPPED_NODE
);
3503 /* Start discovery - this should just do CLEAR_LA */
3504 lpfc_disc_start(vport
);
3510 lpfc_els_timeout(unsigned long ptr
)
3512 struct lpfc_vport
*vport
= (struct lpfc_vport
*) ptr
;
3513 struct lpfc_hba
*phba
= vport
->phba
;
3514 unsigned long iflag
;
3516 spin_lock_irqsave(&vport
->work_port_lock
, iflag
);
3517 if ((vport
->work_port_events
& WORKER_ELS_TMO
) == 0) {
3518 vport
->work_port_events
|= WORKER_ELS_TMO
;
3519 spin_unlock_irqrestore(&vport
->work_port_lock
, iflag
);
3521 spin_lock_irqsave(&phba
->hbalock
, iflag
);
3522 if (phba
->work_wait
)
3523 lpfc_worker_wake_up(phba
);
3524 spin_unlock_irqrestore(&phba
->hbalock
, iflag
);
3527 spin_unlock_irqrestore(&vport
->work_port_lock
, iflag
);
3532 lpfc_els_timeout_handler(struct lpfc_vport
*vport
)
3534 struct lpfc_hba
*phba
= vport
->phba
;
3535 struct lpfc_sli_ring
*pring
;
3536 struct lpfc_iocbq
*tmp_iocb
, *piocb
;
3538 struct lpfc_dmabuf
*pcmd
;
3539 uint32_t els_command
= 0;
3541 uint32_t remote_ID
= 0xffffffff;
3543 /* If the timer is already canceled do nothing */
3544 if ((vport
->work_port_events
& WORKER_ELS_TMO
) == 0) {
3547 spin_lock_irq(&phba
->hbalock
);
3548 timeout
= (uint32_t)(phba
->fc_ratov
<< 1);
3550 pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
3552 list_for_each_entry_safe(piocb
, tmp_iocb
, &pring
->txcmplq
, list
) {
3555 if ((piocb
->iocb_flag
& LPFC_IO_LIBDFC
) != 0 ||
3556 piocb
->iocb
.ulpCommand
== CMD_ABORT_XRI_CN
||
3557 piocb
->iocb
.ulpCommand
== CMD_CLOSE_XRI_CN
)
3560 if (piocb
->vport
!= vport
)
3563 pcmd
= (struct lpfc_dmabuf
*) piocb
->context2
;
3565 els_command
= *(uint32_t *) (pcmd
->virt
);
3567 if (els_command
== ELS_CMD_FARP
||
3568 els_command
== ELS_CMD_FARPR
||
3569 els_command
== ELS_CMD_FDISC
)
3572 if (vport
!= piocb
->vport
)
3575 if (piocb
->drvrTimeout
> 0) {
3576 if (piocb
->drvrTimeout
>= timeout
)
3577 piocb
->drvrTimeout
-= timeout
;
3579 piocb
->drvrTimeout
= 0;
3583 remote_ID
= 0xffffffff;
3584 if (cmd
->ulpCommand
!= CMD_GEN_REQUEST64_CR
)
3585 remote_ID
= cmd
->un
.elsreq64
.remoteID
;
3587 struct lpfc_nodelist
*ndlp
;
3588 ndlp
= __lpfc_findnode_rpi(vport
, cmd
->ulpContext
);
3590 remote_ID
= ndlp
->nlp_DID
;
3592 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
3593 "0127 ELS timeout Data: x%x x%x x%x "
3594 "x%x\n", els_command
,
3595 remote_ID
, cmd
->ulpCommand
, cmd
->ulpIoTag
);
3596 lpfc_sli_issue_abort_iotag(phba
, pring
, piocb
);
3598 spin_unlock_irq(&phba
->hbalock
);
3600 if (phba
->sli
.ring
[LPFC_ELS_RING
].txcmplq_cnt
)
3601 mod_timer(&vport
->els_tmofunc
, jiffies
+ HZ
* timeout
);
3605 lpfc_els_flush_cmd(struct lpfc_vport
*vport
)
3607 LIST_HEAD(completions
);
3608 struct lpfc_hba
*phba
= vport
->phba
;
3609 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
3610 struct lpfc_iocbq
*tmp_iocb
, *piocb
;
3613 lpfc_fabric_abort_vport(vport
);
3615 spin_lock_irq(&phba
->hbalock
);
3616 list_for_each_entry_safe(piocb
, tmp_iocb
, &pring
->txq
, list
) {
3619 if (piocb
->iocb_flag
& LPFC_IO_LIBDFC
) {
3623 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
3624 if (cmd
->ulpCommand
== CMD_QUE_RING_BUF_CN
||
3625 cmd
->ulpCommand
== CMD_QUE_RING_BUF64_CN
||
3626 cmd
->ulpCommand
== CMD_CLOSE_XRI_CN
||
3627 cmd
->ulpCommand
== CMD_ABORT_XRI_CN
)
3630 if (piocb
->vport
!= vport
)
3633 list_move_tail(&piocb
->list
, &completions
);
3637 list_for_each_entry_safe(piocb
, tmp_iocb
, &pring
->txcmplq
, list
) {
3638 if (piocb
->iocb_flag
& LPFC_IO_LIBDFC
) {
3642 if (piocb
->vport
!= vport
)
3645 lpfc_sli_issue_abort_iotag(phba
, pring
, piocb
);
3647 spin_unlock_irq(&phba
->hbalock
);
3649 while (!list_empty(&completions
)) {
3650 piocb
= list_get_first(&completions
, struct lpfc_iocbq
, list
);
3652 list_del_init(&piocb
->list
);
3654 if (!piocb
->iocb_cmpl
)
3655 lpfc_sli_release_iocbq(phba
, piocb
);
3657 cmd
->ulpStatus
= IOSTAT_LOCAL_REJECT
;
3658 cmd
->un
.ulpWord
[4] = IOERR_SLI_ABORTED
;
3659 (piocb
->iocb_cmpl
) (phba
, piocb
, piocb
);
3667 lpfc_els_flush_all_cmd(struct lpfc_hba
*phba
)
3669 LIST_HEAD(completions
);
3670 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
3671 struct lpfc_iocbq
*tmp_iocb
, *piocb
;
3674 lpfc_fabric_abort_hba(phba
);
3675 spin_lock_irq(&phba
->hbalock
);
3676 list_for_each_entry_safe(piocb
, tmp_iocb
, &pring
->txq
, list
) {
3678 if (piocb
->iocb_flag
& LPFC_IO_LIBDFC
)
3680 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
3681 if (cmd
->ulpCommand
== CMD_QUE_RING_BUF_CN
||
3682 cmd
->ulpCommand
== CMD_QUE_RING_BUF64_CN
||
3683 cmd
->ulpCommand
== CMD_CLOSE_XRI_CN
||
3684 cmd
->ulpCommand
== CMD_ABORT_XRI_CN
)
3686 list_move_tail(&piocb
->list
, &completions
);
3689 list_for_each_entry_safe(piocb
, tmp_iocb
, &pring
->txcmplq
, list
) {
3690 if (piocb
->iocb_flag
& LPFC_IO_LIBDFC
)
3692 lpfc_sli_issue_abort_iotag(phba
, pring
, piocb
);
3694 spin_unlock_irq(&phba
->hbalock
);
3695 while (!list_empty(&completions
)) {
3696 piocb
= list_get_first(&completions
, struct lpfc_iocbq
, list
);
3698 list_del_init(&piocb
->list
);
3699 if (!piocb
->iocb_cmpl
)
3700 lpfc_sli_release_iocbq(phba
, piocb
);
3702 cmd
->ulpStatus
= IOSTAT_LOCAL_REJECT
;
3703 cmd
->un
.ulpWord
[4] = IOERR_SLI_ABORTED
;
3704 (piocb
->iocb_cmpl
) (phba
, piocb
, piocb
);
3711 lpfc_els_unsol_buffer(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
3712 struct lpfc_vport
*vport
, struct lpfc_iocbq
*elsiocb
)
3714 struct lpfc_nodelist
*ndlp
;
3717 uint32_t cmd
, did
, newnode
, rjt_err
= 0;
3718 IOCB_t
*icmd
= &elsiocb
->iocb
;
3720 if (vport
== NULL
|| elsiocb
->context2
== NULL
)
3724 payload
= ((struct lpfc_dmabuf
*)elsiocb
->context2
)->virt
;
3726 if ((phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) == 0)
3727 lpfc_post_buffer(phba
, pring
, 1, 1);
3729 did
= icmd
->un
.rcvels
.remoteID
;
3730 if (icmd
->ulpStatus
) {
3731 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
3732 "RCV Unsol ELS: status:x%x/x%x did:x%x",
3733 icmd
->ulpStatus
, icmd
->un
.ulpWord
[4], did
);
3737 /* Check to see if link went down during discovery */
3738 if (lpfc_els_chk_latt(vport
))
3741 /* Ignore traffic recevied during vport shutdown. */
3742 if (vport
->load_flag
& FC_UNLOADING
)
3745 ndlp
= lpfc_findnode_did(vport
, did
);
3747 /* Cannot find existing Fabric ndlp, so allocate a new one */
3748 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
3752 lpfc_nlp_init(vport
, ndlp
, did
);
3754 if ((did
& Fabric_DID_MASK
) == Fabric_DID_MASK
) {
3755 ndlp
->nlp_type
|= NLP_FABRIC
;
3757 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNUSED_NODE
);
3760 phba
->fc_stat
.elsRcvFrame
++;
3761 if (elsiocb
->context1
)
3762 lpfc_nlp_put(elsiocb
->context1
);
3763 elsiocb
->context1
= lpfc_nlp_get(ndlp
);
3764 elsiocb
->vport
= vport
;
3766 if ((cmd
& ELS_CMD_MASK
) == ELS_CMD_RSCN
) {
3767 cmd
&= ELS_CMD_MASK
;
3769 /* ELS command <elsCmd> received from NPORT <did> */
3770 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
3771 "0112 ELS command x%x received from NPORT x%x "
3772 "Data: x%x\n", cmd
, did
, vport
->port_state
);
3775 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
3776 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
3777 did
, vport
->port_state
, ndlp
->nlp_flag
);
3779 phba
->fc_stat
.elsRcvPLOGI
++;
3780 ndlp
= lpfc_plogi_confirm_nport(phba
, payload
, ndlp
);
3782 if (vport
->port_state
< LPFC_DISC_AUTH
) {
3783 rjt_err
= LSRJT_UNABLE_TPC
;
3786 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
,
3791 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
3792 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
3793 did
, vport
->port_state
, ndlp
->nlp_flag
);
3795 phba
->fc_stat
.elsRcvFLOGI
++;
3796 lpfc_els_rcv_flogi(vport
, elsiocb
, ndlp
);
3798 lpfc_drop_node(vport
, ndlp
);
3801 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
3802 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
3803 did
, vport
->port_state
, ndlp
->nlp_flag
);
3805 phba
->fc_stat
.elsRcvLOGO
++;
3806 if (vport
->port_state
< LPFC_DISC_AUTH
) {
3807 rjt_err
= LSRJT_UNABLE_TPC
;
3810 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
, NLP_EVT_RCV_LOGO
);
3813 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
3814 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
3815 did
, vport
->port_state
, ndlp
->nlp_flag
);
3817 phba
->fc_stat
.elsRcvPRLO
++;
3818 if (vport
->port_state
< LPFC_DISC_AUTH
) {
3819 rjt_err
= LSRJT_UNABLE_TPC
;
3822 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
, NLP_EVT_RCV_PRLO
);
3825 phba
->fc_stat
.elsRcvRSCN
++;
3826 lpfc_els_rcv_rscn(vport
, elsiocb
, ndlp
);
3828 lpfc_drop_node(vport
, ndlp
);
3831 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
3832 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
3833 did
, vport
->port_state
, ndlp
->nlp_flag
);
3835 phba
->fc_stat
.elsRcvADISC
++;
3836 if (vport
->port_state
< LPFC_DISC_AUTH
) {
3837 rjt_err
= LSRJT_UNABLE_TPC
;
3840 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
,
3844 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
3845 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
3846 did
, vport
->port_state
, ndlp
->nlp_flag
);
3848 phba
->fc_stat
.elsRcvPDISC
++;
3849 if (vport
->port_state
< LPFC_DISC_AUTH
) {
3850 rjt_err
= LSRJT_UNABLE_TPC
;
3853 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
,
3857 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
3858 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
3859 did
, vport
->port_state
, ndlp
->nlp_flag
);
3861 phba
->fc_stat
.elsRcvFARPR
++;
3862 lpfc_els_rcv_farpr(vport
, elsiocb
, ndlp
);
3865 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
3866 "RCV FARP: did:x%x/ste:x%x flg:x%x",
3867 did
, vport
->port_state
, ndlp
->nlp_flag
);
3869 phba
->fc_stat
.elsRcvFARP
++;
3870 lpfc_els_rcv_farp(vport
, elsiocb
, ndlp
);
3873 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
3874 "RCV FAN: did:x%x/ste:x%x flg:x%x",
3875 did
, vport
->port_state
, ndlp
->nlp_flag
);
3877 phba
->fc_stat
.elsRcvFAN
++;
3878 lpfc_els_rcv_fan(vport
, elsiocb
, ndlp
);
3881 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
3882 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
3883 did
, vport
->port_state
, ndlp
->nlp_flag
);
3885 phba
->fc_stat
.elsRcvPRLI
++;
3886 if (vport
->port_state
< LPFC_DISC_AUTH
) {
3887 rjt_err
= LSRJT_UNABLE_TPC
;
3890 lpfc_disc_state_machine(vport
, ndlp
, elsiocb
, NLP_EVT_RCV_PRLI
);
3893 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
3894 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
3895 did
, vport
->port_state
, ndlp
->nlp_flag
);
3897 phba
->fc_stat
.elsRcvLIRR
++;
3898 lpfc_els_rcv_lirr(vport
, elsiocb
, ndlp
);
3900 lpfc_drop_node(vport
, ndlp
);
3903 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
3904 "RCV RPS: did:x%x/ste:x%x flg:x%x",
3905 did
, vport
->port_state
, ndlp
->nlp_flag
);
3907 phba
->fc_stat
.elsRcvRPS
++;
3908 lpfc_els_rcv_rps(vport
, elsiocb
, ndlp
);
3910 lpfc_drop_node(vport
, ndlp
);
3913 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
3914 "RCV RPL: did:x%x/ste:x%x flg:x%x",
3915 did
, vport
->port_state
, ndlp
->nlp_flag
);
3917 phba
->fc_stat
.elsRcvRPL
++;
3918 lpfc_els_rcv_rpl(vport
, elsiocb
, ndlp
);
3920 lpfc_drop_node(vport
, ndlp
);
3923 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
3924 "RCV RNID: did:x%x/ste:x%x flg:x%x",
3925 did
, vport
->port_state
, ndlp
->nlp_flag
);
3927 phba
->fc_stat
.elsRcvRNID
++;
3928 lpfc_els_rcv_rnid(vport
, elsiocb
, ndlp
);
3930 lpfc_drop_node(vport
, ndlp
);
3933 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_UNSOL
,
3934 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
3935 cmd
, did
, vport
->port_state
);
3937 /* Unsupported ELS command, reject */
3938 rjt_err
= LSRJT_INVALID_CMD
;
3940 /* Unknown ELS command <elsCmd> received from NPORT <did> */
3941 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
3942 "0115 Unknown ELS command x%x "
3943 "received from NPORT x%x\n", cmd
, did
);
3945 lpfc_drop_node(vport
, ndlp
);
3949 /* check if need to LS_RJT received ELS cmd */
3951 memset(&stat
, 0, sizeof(stat
));
3952 stat
.un
.b
.lsRjtRsnCode
= rjt_err
;
3953 stat
.un
.b
.lsRjtRsnCodeExp
= LSEXP_NOTHING_MORE
;
3954 lpfc_els_rsp_reject(vport
, stat
.un
.lsRjtError
, elsiocb
, ndlp
,
3961 lpfc_printf_log(phba
, KERN_ERR
, LOG_ELS
,
3962 "(%d):0111 Dropping received ELS cmd "
3963 "Data: x%x x%x x%x\n",
3964 vport
? vport
->vpi
: 0xffff, icmd
->ulpStatus
,
3965 icmd
->un
.ulpWord
[4], icmd
->ulpTimeout
);
3966 phba
->fc_stat
.elsRcvDrop
++;
3969 static struct lpfc_vport
*
3970 lpfc_find_vport_by_vpid(struct lpfc_hba
*phba
, uint16_t vpi
)
3972 struct lpfc_vport
*vport
;
3973 unsigned long flags
;
3975 spin_lock_irqsave(&phba
->hbalock
, flags
);
3976 list_for_each_entry(vport
, &phba
->port_list
, listentry
) {
3977 if (vport
->vpi
== vpi
) {
3978 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
3982 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
3987 lpfc_els_unsol_event(struct lpfc_hba
*phba
, struct lpfc_sli_ring
*pring
,
3988 struct lpfc_iocbq
*elsiocb
)
3990 struct lpfc_vport
*vport
= phba
->pport
;
3991 IOCB_t
*icmd
= &elsiocb
->iocb
;
3993 struct lpfc_dmabuf
*bdeBuf1
= elsiocb
->context2
;
3994 struct lpfc_dmabuf
*bdeBuf2
= elsiocb
->context3
;
3996 elsiocb
->context2
= NULL
;
3997 elsiocb
->context3
= NULL
;
3999 if (icmd
->ulpStatus
== IOSTAT_NEED_BUFFER
) {
4000 lpfc_sli_hbqbuf_add_hbqs(phba
, LPFC_ELS_HBQ
);
4001 } else if (icmd
->ulpStatus
== IOSTAT_LOCAL_REJECT
&&
4002 (icmd
->un
.ulpWord
[4] & 0xff) == IOERR_RCV_BUFFER_WAITING
) {
4003 phba
->fc_stat
.NoRcvBuf
++;
4004 /* Not enough posted buffers; Try posting more buffers */
4005 if (!(phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
))
4006 lpfc_post_buffer(phba
, pring
, 0, 1);
4010 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
4011 (icmd
->ulpCommand
== CMD_IOCB_RCV_ELS64_CX
||
4012 icmd
->ulpCommand
== CMD_IOCB_RCV_SEQ64_CX
)) {
4013 if (icmd
->unsli3
.rcvsli3
.vpi
== 0xffff)
4014 vport
= phba
->pport
;
4016 uint16_t vpi
= icmd
->unsli3
.rcvsli3
.vpi
;
4017 vport
= lpfc_find_vport_by_vpid(phba
, vpi
);
4020 /* If there are no BDEs associated
4021 * with this IOCB, there is nothing to do.
4023 if (icmd
->ulpBdeCount
== 0)
4026 /* type of ELS cmd is first 32bit word
4029 if (phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) {
4030 elsiocb
->context2
= bdeBuf1
;
4032 paddr
= getPaddr(icmd
->un
.cont64
[0].addrHigh
,
4033 icmd
->un
.cont64
[0].addrLow
);
4034 elsiocb
->context2
= lpfc_sli_ringpostbuf_get(phba
, pring
,
4038 lpfc_els_unsol_buffer(phba
, pring
, vport
, elsiocb
);
4040 * The different unsolicited event handlers would tell us
4041 * if they are done with "mp" by setting context2 to NULL.
4043 lpfc_nlp_put(elsiocb
->context1
);
4044 elsiocb
->context1
= NULL
;
4045 if (elsiocb
->context2
) {
4046 lpfc_in_buf_free(phba
, (struct lpfc_dmabuf
*)elsiocb
->context2
);
4047 elsiocb
->context2
= NULL
;
4050 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
4051 if ((phba
->sli3_options
& LPFC_SLI3_HBQ_ENABLED
) &&
4052 icmd
->ulpBdeCount
== 2) {
4053 elsiocb
->context2
= bdeBuf2
;
4054 lpfc_els_unsol_buffer(phba
, pring
, vport
, elsiocb
);
4055 /* free mp if we are done with it */
4056 if (elsiocb
->context2
) {
4057 lpfc_in_buf_free(phba
, elsiocb
->context2
);
4058 elsiocb
->context2
= NULL
;
4064 lpfc_do_scr_ns_plogi(struct lpfc_hba
*phba
, struct lpfc_vport
*vport
)
4066 struct lpfc_nodelist
*ndlp
, *ndlp_fdmi
;
4068 ndlp
= lpfc_findnode_did(vport
, NameServer_DID
);
4070 ndlp
= mempool_alloc(phba
->nlp_mem_pool
, GFP_KERNEL
);
4072 if (phba
->fc_topology
== TOPOLOGY_LOOP
) {
4073 lpfc_disc_start(vport
);
4076 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
4077 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
4078 "0251 NameServer login: no memory\n");
4081 lpfc_nlp_init(vport
, ndlp
, NameServer_DID
);
4082 ndlp
->nlp_type
|= NLP_FABRIC
;
4085 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_PLOGI_ISSUE
);
4087 if (lpfc_issue_els_plogi(vport
, ndlp
->nlp_DID
, 0)) {
4088 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
4089 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
4090 "0252 Cannot issue NameServer login\n");
4094 if (vport
->cfg_fdmi_on
) {
4095 ndlp_fdmi
= mempool_alloc(phba
->nlp_mem_pool
,
4098 lpfc_nlp_init(vport
, ndlp_fdmi
, FDMI_DID
);
4099 ndlp_fdmi
->nlp_type
|= NLP_FABRIC
;
4100 ndlp_fdmi
->nlp_state
=
4101 NLP_STE_PLOGI_ISSUE
;
4102 lpfc_issue_els_plogi(vport
, ndlp_fdmi
->nlp_DID
,
4110 lpfc_cmpl_reg_new_vport(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
4112 struct lpfc_vport
*vport
= pmb
->vport
;
4113 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4114 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
4115 MAILBOX_t
*mb
= &pmb
->mb
;
4117 vport
->fc_flag
&= ~FC_VPORT_NEEDS_REG_VPI
;
4120 if (mb
->mbxStatus
) {
4121 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
4122 "0915 Register VPI failed: 0x%x\n",
4125 switch (mb
->mbxStatus
) {
4126 case 0x11: /* unsupported feature */
4127 case 0x9603: /* max_vpi exceeded */
4128 /* giving up on vport registration */
4129 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
4130 spin_lock_irq(shost
->host_lock
);
4131 vport
->fc_flag
&= ~(FC_FABRIC
| FC_PUBLIC_LOOP
);
4132 spin_unlock_irq(shost
->host_lock
);
4133 lpfc_can_disctmo(vport
);
4136 /* Try to recover from this error */
4137 lpfc_mbx_unreg_vpi(vport
);
4138 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
4139 lpfc_initial_fdisc(vport
);
4144 if (vport
== phba
->pport
)
4145 lpfc_issue_fabric_reglogin(vport
);
4147 lpfc_do_scr_ns_plogi(phba
, vport
);
4149 mempool_free(pmb
, phba
->mbox_mem_pool
);
4154 lpfc_register_new_vport(struct lpfc_hba
*phba
, struct lpfc_vport
*vport
,
4155 struct lpfc_nodelist
*ndlp
)
4159 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
4161 lpfc_reg_vpi(phba
, vport
->vpi
, vport
->fc_myDID
, mbox
);
4162 mbox
->vport
= vport
;
4163 mbox
->context2
= lpfc_nlp_get(ndlp
);
4164 mbox
->mbox_cmpl
= lpfc_cmpl_reg_new_vport
;
4165 if (lpfc_sli_issue_mbox(phba
, mbox
,
4166 MBX_NOWAIT
| MBX_STOP_IOCB
)
4167 == MBX_NOT_FINISHED
) {
4168 mempool_free(mbox
, phba
->mbox_mem_pool
);
4169 vport
->fc_flag
&= ~FC_VPORT_NEEDS_REG_VPI
;
4171 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
4172 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
4173 "0253 Register VPI: Can't send mbox\n");
4176 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
4178 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
4179 "0254 Register VPI: no memory\n");
4181 vport
->fc_flag
&= ~FC_VPORT_NEEDS_REG_VPI
;
4187 lpfc_cmpl_els_fdisc(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
4188 struct lpfc_iocbq
*rspiocb
)
4190 struct lpfc_vport
*vport
= cmdiocb
->vport
;
4191 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4192 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) cmdiocb
->context1
;
4193 struct lpfc_nodelist
*np
;
4194 struct lpfc_nodelist
*next_np
;
4195 IOCB_t
*irsp
= &rspiocb
->iocb
;
4196 struct lpfc_iocbq
*piocb
;
4198 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_ELS
,
4199 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
4200 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4],
4202 /* Since all FDISCs are being single threaded, we
4203 * must reset the discovery timer for ALL vports
4204 * waiting to send FDISC when one completes.
4206 list_for_each_entry(piocb
, &phba
->fabric_iocb_list
, list
) {
4207 lpfc_set_disctmo(piocb
->vport
);
4210 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
4211 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
4212 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4], vport
->fc_prevDID
);
4214 if (irsp
->ulpStatus
) {
4215 /* Check for retry */
4216 if (lpfc_els_retry(phba
, cmdiocb
, rspiocb
))
4219 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
4220 "0124 FDISC failed. (%d/%d)\n",
4221 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4]);
4222 if (vport
->fc_vport
->vport_state
== FC_VPORT_INITIALIZING
)
4223 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
4226 /* giving up on FDISC. Cancel discovery timer */
4227 lpfc_can_disctmo(vport
);
4229 spin_lock_irq(shost
->host_lock
);
4230 vport
->fc_flag
|= FC_FABRIC
;
4231 if (vport
->phba
->fc_topology
== TOPOLOGY_LOOP
)
4232 vport
->fc_flag
|= FC_PUBLIC_LOOP
;
4233 spin_unlock_irq(shost
->host_lock
);
4235 vport
->fc_myDID
= irsp
->un
.ulpWord
[4] & Mask_DID
;
4236 lpfc_vport_set_state(vport
, FC_VPORT_ACTIVE
);
4237 if ((vport
->fc_prevDID
!= vport
->fc_myDID
) &&
4238 !(vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
)) {
4239 /* If our NportID changed, we need to ensure all
4240 * remaining NPORTs get unreg_login'ed so we can
4243 list_for_each_entry_safe(np
, next_np
,
4244 &vport
->fc_nodes
, nlp_listp
) {
4245 if (np
->nlp_state
!= NLP_STE_NPR_NODE
4246 || !(np
->nlp_flag
& NLP_NPR_ADISC
))
4248 spin_lock_irq(shost
->host_lock
);
4249 np
->nlp_flag
&= ~NLP_NPR_ADISC
;
4250 spin_unlock_irq(shost
->host_lock
);
4251 lpfc_unreg_rpi(vport
, np
);
4253 lpfc_mbx_unreg_vpi(vport
);
4254 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
4257 if (vport
->fc_flag
& FC_VPORT_NEEDS_REG_VPI
)
4258 lpfc_register_new_vport(phba
, vport
, ndlp
);
4260 lpfc_do_scr_ns_plogi(phba
, vport
);
4262 lpfc_nlp_put(ndlp
); /* Free Fabric ndlp for vports */
4266 lpfc_els_free_iocb(phba
, cmdiocb
);
4270 lpfc_issue_els_fdisc(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
4273 struct lpfc_hba
*phba
= vport
->phba
;
4275 struct lpfc_iocbq
*elsiocb
;
4276 struct serv_parm
*sp
;
4279 int did
= ndlp
->nlp_DID
;
4282 cmdsize
= (sizeof(uint32_t) + sizeof(struct serv_parm
));
4283 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, retry
, ndlp
, did
,
4286 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
4287 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
4288 "0255 Issue FDISC: no IOCB\n");
4292 icmd
= &elsiocb
->iocb
;
4293 icmd
->un
.elsreq64
.myID
= 0;
4294 icmd
->un
.elsreq64
.fl
= 1;
4296 /* For FDISC, Let FDISC rsp set the NPortID for this VPI */
4300 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
4301 *((uint32_t *) (pcmd
)) = ELS_CMD_FDISC
;
4302 pcmd
+= sizeof(uint32_t); /* CSP Word 1 */
4303 memcpy(pcmd
, &vport
->phba
->pport
->fc_sparam
, sizeof(struct serv_parm
));
4304 sp
= (struct serv_parm
*) pcmd
;
4305 /* Setup CSPs accordingly for Fabric */
4306 sp
->cmn
.e_d_tov
= 0;
4307 sp
->cmn
.w2
.r_a_tov
= 0;
4308 sp
->cls1
.classValid
= 0;
4309 sp
->cls2
.seqDelivery
= 1;
4310 sp
->cls3
.seqDelivery
= 1;
4312 pcmd
+= sizeof(uint32_t); /* CSP Word 2 */
4313 pcmd
+= sizeof(uint32_t); /* CSP Word 3 */
4314 pcmd
+= sizeof(uint32_t); /* CSP Word 4 */
4315 pcmd
+= sizeof(uint32_t); /* Port Name */
4316 memcpy(pcmd
, &vport
->fc_portname
, 8);
4317 pcmd
+= sizeof(uint32_t); /* Node Name */
4318 pcmd
+= sizeof(uint32_t); /* Node Name */
4319 memcpy(pcmd
, &vport
->fc_nodename
, 8);
4321 lpfc_set_disctmo(vport
);
4323 phba
->fc_stat
.elsXmitFDISC
++;
4324 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_fdisc
;
4326 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
4327 "Issue FDISC: did:x%x",
4330 rc
= lpfc_issue_fabric_iocb(phba
, elsiocb
);
4331 if (rc
== IOCB_ERROR
) {
4332 lpfc_els_free_iocb(phba
, elsiocb
);
4333 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
4334 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
4335 "0256 Issue FDISC: Cannot send IOCB\n");
4338 lpfc_vport_set_state(vport
, FC_VPORT_INITIALIZING
);
4339 vport
->port_state
= LPFC_FDISC
;
4344 lpfc_cmpl_els_npiv_logo(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
4345 struct lpfc_iocbq
*rspiocb
)
4347 struct lpfc_vport
*vport
= cmdiocb
->vport
;
4350 irsp
= &rspiocb
->iocb
;
4351 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
4352 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
4353 irsp
->ulpStatus
, irsp
->un
.ulpWord
[4], irsp
->un
.rcvels
.remoteID
);
4355 lpfc_els_free_iocb(phba
, cmdiocb
);
4356 vport
->unreg_vpi_cmpl
= VPORT_ERROR
;
4360 lpfc_issue_els_npiv_logo(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
4362 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
4363 struct lpfc_hba
*phba
= vport
->phba
;
4364 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
4366 struct lpfc_iocbq
*elsiocb
;
4370 cmdsize
= 2 * sizeof(uint32_t) + sizeof(struct lpfc_name
);
4371 elsiocb
= lpfc_prep_els_iocb(vport
, 1, cmdsize
, 0, ndlp
, ndlp
->nlp_DID
,
4376 icmd
= &elsiocb
->iocb
;
4377 pcmd
= (uint8_t *) (((struct lpfc_dmabuf
*) elsiocb
->context2
)->virt
);
4378 *((uint32_t *) (pcmd
)) = ELS_CMD_LOGO
;
4379 pcmd
+= sizeof(uint32_t);
4381 /* Fill in LOGO payload */
4382 *((uint32_t *) (pcmd
)) = be32_to_cpu(vport
->fc_myDID
);
4383 pcmd
+= sizeof(uint32_t);
4384 memcpy(pcmd
, &vport
->fc_portname
, sizeof(struct lpfc_name
));
4386 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
4387 "Issue LOGO npiv did:x%x flg:x%x",
4388 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
4390 elsiocb
->iocb_cmpl
= lpfc_cmpl_els_npiv_logo
;
4391 spin_lock_irq(shost
->host_lock
);
4392 ndlp
->nlp_flag
|= NLP_LOGO_SND
;
4393 spin_unlock_irq(shost
->host_lock
);
4394 if (lpfc_sli_issue_iocb(phba
, pring
, elsiocb
, 0) == IOCB_ERROR
) {
4395 spin_lock_irq(shost
->host_lock
);
4396 ndlp
->nlp_flag
&= ~NLP_LOGO_SND
;
4397 spin_unlock_irq(shost
->host_lock
);
4398 lpfc_els_free_iocb(phba
, elsiocb
);
4405 lpfc_fabric_block_timeout(unsigned long ptr
)
4407 struct lpfc_hba
*phba
= (struct lpfc_hba
*) ptr
;
4408 unsigned long iflags
;
4409 uint32_t tmo_posted
;
4410 spin_lock_irqsave(&phba
->pport
->work_port_lock
, iflags
);
4411 tmo_posted
= phba
->pport
->work_port_events
& WORKER_FABRIC_BLOCK_TMO
;
4413 phba
->pport
->work_port_events
|= WORKER_FABRIC_BLOCK_TMO
;
4414 spin_unlock_irqrestore(&phba
->pport
->work_port_lock
, iflags
);
4417 spin_lock_irqsave(&phba
->hbalock
, iflags
);
4418 if (phba
->work_wait
)
4419 lpfc_worker_wake_up(phba
);
4420 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
4425 lpfc_resume_fabric_iocbs(struct lpfc_hba
*phba
)
4427 struct lpfc_iocbq
*iocb
;
4428 unsigned long iflags
;
4430 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
4435 spin_lock_irqsave(&phba
->hbalock
, iflags
);
4436 /* Post any pending iocb to the SLI layer */
4437 if (atomic_read(&phba
->fabric_iocb_count
) == 0) {
4438 list_remove_head(&phba
->fabric_iocb_list
, iocb
, typeof(*iocb
),
4441 atomic_inc(&phba
->fabric_iocb_count
);
4443 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
4445 iocb
->fabric_iocb_cmpl
= iocb
->iocb_cmpl
;
4446 iocb
->iocb_cmpl
= lpfc_cmpl_fabric_iocb
;
4447 iocb
->iocb_flag
|= LPFC_IO_FABRIC
;
4449 lpfc_debugfs_disc_trc(iocb
->vport
, LPFC_DISC_TRC_ELS_CMD
,
4450 "Fabric sched1: ste:x%x",
4451 iocb
->vport
->port_state
, 0, 0);
4453 ret
= lpfc_sli_issue_iocb(phba
, pring
, iocb
, 0);
4455 if (ret
== IOCB_ERROR
) {
4456 iocb
->iocb_cmpl
= iocb
->fabric_iocb_cmpl
;
4457 iocb
->fabric_iocb_cmpl
= NULL
;
4458 iocb
->iocb_flag
&= ~LPFC_IO_FABRIC
;
4460 cmd
->ulpStatus
= IOSTAT_LOCAL_REJECT
;
4461 cmd
->un
.ulpWord
[4] = IOERR_SLI_ABORTED
;
4462 iocb
->iocb_cmpl(phba
, iocb
, iocb
);
4464 atomic_dec(&phba
->fabric_iocb_count
);
4473 lpfc_unblock_fabric_iocbs(struct lpfc_hba
*phba
)
4475 clear_bit(FABRIC_COMANDS_BLOCKED
, &phba
->bit_flags
);
4477 lpfc_resume_fabric_iocbs(phba
);
4482 lpfc_block_fabric_iocbs(struct lpfc_hba
*phba
)
4486 blocked
= test_and_set_bit(FABRIC_COMANDS_BLOCKED
, &phba
->bit_flags
);
4487 /* Start a timer to unblock fabric
4491 mod_timer(&phba
->fabric_block_timer
, jiffies
+ HZ
/10 );
4497 lpfc_cmpl_fabric_iocb(struct lpfc_hba
*phba
, struct lpfc_iocbq
*cmdiocb
,
4498 struct lpfc_iocbq
*rspiocb
)
4502 if ((cmdiocb
->iocb_flag
& LPFC_IO_FABRIC
) != LPFC_IO_FABRIC
)
4505 switch (rspiocb
->iocb
.ulpStatus
) {
4506 case IOSTAT_NPORT_RJT
:
4507 case IOSTAT_FABRIC_RJT
:
4508 if (rspiocb
->iocb
.un
.ulpWord
[4] & RJT_UNAVAIL_TEMP
) {
4509 lpfc_block_fabric_iocbs(phba
);
4513 case IOSTAT_NPORT_BSY
:
4514 case IOSTAT_FABRIC_BSY
:
4515 lpfc_block_fabric_iocbs(phba
);
4519 stat
.un
.lsRjtError
=
4520 be32_to_cpu(rspiocb
->iocb
.un
.ulpWord
[4]);
4521 if ((stat
.un
.b
.lsRjtRsnCode
== LSRJT_UNABLE_TPC
) ||
4522 (stat
.un
.b
.lsRjtRsnCode
== LSRJT_LOGICAL_BSY
))
4523 lpfc_block_fabric_iocbs(phba
);
4527 if (atomic_read(&phba
->fabric_iocb_count
) == 0)
4530 cmdiocb
->iocb_cmpl
= cmdiocb
->fabric_iocb_cmpl
;
4531 cmdiocb
->fabric_iocb_cmpl
= NULL
;
4532 cmdiocb
->iocb_flag
&= ~LPFC_IO_FABRIC
;
4533 cmdiocb
->iocb_cmpl(phba
, cmdiocb
, rspiocb
);
4535 atomic_dec(&phba
->fabric_iocb_count
);
4536 if (!test_bit(FABRIC_COMANDS_BLOCKED
, &phba
->bit_flags
)) {
4537 /* Post any pending iocbs to HBA */
4538 lpfc_resume_fabric_iocbs(phba
);
4543 lpfc_issue_fabric_iocb(struct lpfc_hba
*phba
, struct lpfc_iocbq
*iocb
)
4545 unsigned long iflags
;
4546 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
4550 if (atomic_read(&phba
->fabric_iocb_count
) > 1)
4553 spin_lock_irqsave(&phba
->hbalock
, iflags
);
4554 ready
= atomic_read(&phba
->fabric_iocb_count
) == 0 &&
4555 !test_bit(FABRIC_COMANDS_BLOCKED
, &phba
->bit_flags
);
4557 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
4559 iocb
->fabric_iocb_cmpl
= iocb
->iocb_cmpl
;
4560 iocb
->iocb_cmpl
= lpfc_cmpl_fabric_iocb
;
4561 iocb
->iocb_flag
|= LPFC_IO_FABRIC
;
4563 lpfc_debugfs_disc_trc(iocb
->vport
, LPFC_DISC_TRC_ELS_CMD
,
4564 "Fabric sched2: ste:x%x",
4565 iocb
->vport
->port_state
, 0, 0);
4567 atomic_inc(&phba
->fabric_iocb_count
);
4568 ret
= lpfc_sli_issue_iocb(phba
, pring
, iocb
, 0);
4570 if (ret
== IOCB_ERROR
) {
4571 iocb
->iocb_cmpl
= iocb
->fabric_iocb_cmpl
;
4572 iocb
->fabric_iocb_cmpl
= NULL
;
4573 iocb
->iocb_flag
&= ~LPFC_IO_FABRIC
;
4574 atomic_dec(&phba
->fabric_iocb_count
);
4577 spin_lock_irqsave(&phba
->hbalock
, iflags
);
4578 list_add_tail(&iocb
->list
, &phba
->fabric_iocb_list
);
4579 spin_unlock_irqrestore(&phba
->hbalock
, iflags
);
4586 void lpfc_fabric_abort_vport(struct lpfc_vport
*vport
)
4588 LIST_HEAD(completions
);
4589 struct lpfc_hba
*phba
= vport
->phba
;
4590 struct lpfc_iocbq
*tmp_iocb
, *piocb
;
4593 spin_lock_irq(&phba
->hbalock
);
4594 list_for_each_entry_safe(piocb
, tmp_iocb
, &phba
->fabric_iocb_list
,
4597 if (piocb
->vport
!= vport
)
4600 list_move_tail(&piocb
->list
, &completions
);
4602 spin_unlock_irq(&phba
->hbalock
);
4604 while (!list_empty(&completions
)) {
4605 piocb
= list_get_first(&completions
, struct lpfc_iocbq
, list
);
4606 list_del_init(&piocb
->list
);
4609 cmd
->ulpStatus
= IOSTAT_LOCAL_REJECT
;
4610 cmd
->un
.ulpWord
[4] = IOERR_SLI_ABORTED
;
4611 (piocb
->iocb_cmpl
) (phba
, piocb
, piocb
);
4615 void lpfc_fabric_abort_nport(struct lpfc_nodelist
*ndlp
)
4617 LIST_HEAD(completions
);
4618 struct lpfc_hba
*phba
= ndlp
->vport
->phba
;
4619 struct lpfc_iocbq
*tmp_iocb
, *piocb
;
4620 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
4623 spin_lock_irq(&phba
->hbalock
);
4624 list_for_each_entry_safe(piocb
, tmp_iocb
, &phba
->fabric_iocb_list
,
4626 if ((lpfc_check_sli_ndlp(phba
, pring
, piocb
, ndlp
))) {
4628 list_move_tail(&piocb
->list
, &completions
);
4631 spin_unlock_irq(&phba
->hbalock
);
4633 while (!list_empty(&completions
)) {
4634 piocb
= list_get_first(&completions
, struct lpfc_iocbq
, list
);
4635 list_del_init(&piocb
->list
);
4638 cmd
->ulpStatus
= IOSTAT_LOCAL_REJECT
;
4639 cmd
->un
.ulpWord
[4] = IOERR_SLI_ABORTED
;
4640 (piocb
->iocb_cmpl
) (phba
, piocb
, piocb
);
4644 void lpfc_fabric_abort_hba(struct lpfc_hba
*phba
)
4646 LIST_HEAD(completions
);
4647 struct lpfc_iocbq
*piocb
;
4650 spin_lock_irq(&phba
->hbalock
);
4651 list_splice_init(&phba
->fabric_iocb_list
, &completions
);
4652 spin_unlock_irq(&phba
->hbalock
);
4654 while (!list_empty(&completions
)) {
4655 piocb
= list_get_first(&completions
, struct lpfc_iocbq
, list
);
4656 list_del_init(&piocb
->list
);
4659 cmd
->ulpStatus
= IOSTAT_LOCAL_REJECT
;
4660 cmd
->un
.ulpWord
[4] = IOERR_SLI_ABORTED
;
4661 (piocb
->iocb_cmpl
) (phba
, piocb
, piocb
);
4666 void lpfc_fabric_abort_flogi(struct lpfc_hba
*phba
)
4668 LIST_HEAD(completions
);
4669 struct lpfc_iocbq
*tmp_iocb
, *piocb
;
4671 struct lpfc_nodelist
*ndlp
;
4673 spin_lock_irq(&phba
->hbalock
);
4674 list_for_each_entry_safe(piocb
, tmp_iocb
, &phba
->fabric_iocb_list
,
4678 ndlp
= (struct lpfc_nodelist
*) piocb
->context1
;
4679 if (cmd
->ulpCommand
== CMD_ELS_REQUEST64_CR
&&
4681 ndlp
->nlp_DID
== Fabric_DID
)
4682 list_move_tail(&piocb
->list
, &completions
);
4684 spin_unlock_irq(&phba
->hbalock
);
4686 while (!list_empty(&completions
)) {
4687 piocb
= list_get_first(&completions
, struct lpfc_iocbq
, list
);
4688 list_del_init(&piocb
->list
);
4691 cmd
->ulpStatus
= IOSTAT_LOCAL_REJECT
;
4692 cmd
->un
.ulpWord
[4] = IOERR_SLI_ABORTED
;
4693 (piocb
->iocb_cmpl
) (phba
, piocb
, piocb
);