blob: 9365e19696e2167e179a18e428b43b57168cdd82 [file] [log] [blame]
dea31012005-04-17 16:05:31 -05001/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04003 * Fibre Channel Host Bus Adapters. *
James Smart9413aff2007-04-25 09:53:35 -04004 * Copyright (C) 2004-2007 Emulex. All rights reserved. *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04005 * EMULEX and SLI are trademarks of Emulex. *
dea31012005-04-17 16:05:31 -05006 * www.emulex.com *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04007 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea31012005-04-17 16:05:31 -05008 * *
9 * This program is free software; you can redistribute it and/or *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040010 * 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. *
dea31012005-04-17 16:05:31 -050020 *******************************************************************/
21
dea31012005-04-17 16:05:31 -050022#include <linux/blkdev.h>
23#include <linux/pci.h>
24#include <linux/interrupt.h>
25
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040026#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050027#include <scsi/scsi_device.h>
28#include <scsi/scsi_host.h>
29#include <scsi/scsi_transport_fc.h>
30
31#include "lpfc_hw.h"
32#include "lpfc_sli.h"
33#include "lpfc_disc.h"
34#include "lpfc_scsi.h"
35#include "lpfc.h"
36#include "lpfc_logmsg.h"
37#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050038#include "lpfc_vport.h"
James Smart858c9f62007-06-17 19:56:39 -050039#include "lpfc_debugfs.h"
dea31012005-04-17 16:05:31 -050040
41static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *,
42 struct lpfc_iocbq *);
James Smart92d7f7b2007-06-17 19:56:38 -050043static void lpfc_cmpl_fabric_iocb(struct lpfc_hba *, struct lpfc_iocbq *,
44 struct lpfc_iocbq *);
45
dea31012005-04-17 16:05:31 -050046static int lpfc_max_els_tries = 3;
47
James Smart858c9f62007-06-17 19:56:39 -050048int
James Smart2e0fef82007-06-17 19:56:36 -050049lpfc_els_chk_latt(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -050050{
James Smart2e0fef82007-06-17 19:56:36 -050051 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
52 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -050053 uint32_t ha_copy;
dea31012005-04-17 16:05:31 -050054
James Smart2e0fef82007-06-17 19:56:36 -050055 if (vport->port_state >= LPFC_VPORT_READY ||
56 phba->link_state == LPFC_LINK_DOWN)
dea31012005-04-17 16:05:31 -050057 return 0;
58
59 /* Read the HBA Host Attention Register */
dea31012005-04-17 16:05:31 -050060 ha_copy = readl(phba->HAregaddr);
dea31012005-04-17 16:05:31 -050061
62 if (!(ha_copy & HA_LATT))
63 return 0;
64
65 /* Pending Link Event during Discovery */
James Smarte8b62012007-08-02 11:10:09 -040066 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);
dea31012005-04-17 16:05:31 -050070
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
75 * events.
76 */
James Smart2e0fef82007-06-17 19:56:36 -050077 spin_lock_irq(shost->host_lock);
78 vport->fc_flag |= FC_ABORT_DISCOVERY;
79 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -050080
James Smart92d7f7b2007-06-17 19:56:38 -050081 if (phba->link_state != LPFC_CLEAR_LA)
James Smarted957682007-06-17 19:56:37 -050082 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -050083
Jamie Wellnitzc9f87352006-02-28 19:25:23 -050084 return 1;
dea31012005-04-17 16:05:31 -050085}
86
87static struct lpfc_iocbq *
James Smart2e0fef82007-06-17 19:56:36 -050088lpfc_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,
91 uint32_t elscmd)
dea31012005-04-17 16:05:31 -050092{
James Smart2e0fef82007-06-17 19:56:36 -050093 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -040094 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -050095 struct lpfc_dmabuf *pcmd, *prsp, *pbuflist;
96 struct ulp_bde64 *bpl;
97 IOCB_t *icmd;
98
dea31012005-04-17 16:05:31 -050099
James Smart2e0fef82007-06-17 19:56:36 -0500100 if (!lpfc_is_link_up(phba))
101 return NULL;
dea31012005-04-17 16:05:31 -0500102
dea31012005-04-17 16:05:31 -0500103 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400104 elsiocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -0500105
106 if (elsiocb == NULL)
107 return NULL;
dea31012005-04-17 16:05:31 -0500108 icmd = &elsiocb->iocb;
109
110 /* fill in BDEs for command */
111 /* Allocate buffer for command payload */
James Smart92d7f7b2007-06-17 19:56:38 -0500112 if (((pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL)) == 0) ||
dea31012005-04-17 16:05:31 -0500113 ((pcmd->virt = lpfc_mbuf_alloc(phba,
114 MEM_PRI, &(pcmd->phys))) == 0)) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -0800115 kfree(pcmd);
dea31012005-04-17 16:05:31 -0500116
James Bottomley604a3e32005-10-29 10:28:33 -0500117 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -0500118 return NULL;
119 }
120
121 INIT_LIST_HEAD(&pcmd->list);
122
123 /* Allocate buffer for response payload */
124 if (expectRsp) {
James Smart92d7f7b2007-06-17 19:56:38 -0500125 prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -0500126 if (prsp)
127 prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
128 &prsp->phys);
129 if (prsp == 0 || prsp->virt == 0) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -0800130 kfree(prsp);
dea31012005-04-17 16:05:31 -0500131 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
132 kfree(pcmd);
James Bottomley604a3e32005-10-29 10:28:33 -0500133 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -0500134 return NULL;
135 }
136 INIT_LIST_HEAD(&prsp->list);
137 } else {
138 prsp = NULL;
139 }
140
141 /* Allocate buffer for Buffer ptr list */
James Smart92d7f7b2007-06-17 19:56:38 -0500142 pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -0500143 if (pbuflist)
James Smarted957682007-06-17 19:56:37 -0500144 pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
145 &pbuflist->phys);
dea31012005-04-17 16:05:31 -0500146 if (pbuflist == 0 || pbuflist->virt == 0) {
James Bottomley604a3e32005-10-29 10:28:33 -0500147 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -0500148 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
149 lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
150 kfree(pcmd);
151 kfree(prsp);
Jesper Juhlc9475cb2005-11-07 01:01:26 -0800152 kfree(pbuflist);
dea31012005-04-17 16:05:31 -0500153 return NULL;
154 }
155
156 INIT_LIST_HEAD(&pbuflist->list);
157
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;
James Smart2e0fef82007-06-17 19:56:36 -0500161 icmd->un.elsreq64.remoteID = did; /* DID */
dea31012005-04-17 16:05:31 -0500162 if (expectRsp) {
James Smart92d7f7b2007-06-17 19:56:38 -0500163 icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
dea31012005-04-17 16:05:31 -0500164 icmd->ulpCommand = CMD_ELS_REQUEST64_CR;
James Smart2680eea2007-04-25 09:52:55 -0400165 icmd->ulpTimeout = phba->fc_ratov * 2;
dea31012005-04-17 16:05:31 -0500166 } else {
James Smart92d7f7b2007-06-17 19:56:38 -0500167 icmd->un.elsreq64.bdl.bdeSize = sizeof(struct ulp_bde64);
dea31012005-04-17 16:05:31 -0500168 icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
169 }
dea31012005-04-17 16:05:31 -0500170 icmd->ulpBdeCount = 1;
171 icmd->ulpLe = 1;
172 icmd->ulpClass = CLASS3;
173
James Smart92d7f7b2007-06-17 19:56:38 -0500174 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
175 icmd->un.elsreq64.myID = vport->fc_myDID;
176
177 /* For ELS_REQUEST64_CR, use the VPI by default */
178 icmd->ulpContext = vport->vpi;
179 icmd->ulpCt_h = 0;
180 icmd->ulpCt_l = 1;
181 }
182
dea31012005-04-17 16:05:31 -0500183 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);
189
190 if (expectRsp) {
191 bpl++;
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);
197 }
198
199 /* Save for completion so we can release these resources */
James Smart92d7f7b2007-06-17 19:56:38 -0500200 if (elscmd != ELS_CMD_LS_RJT)
201 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart329f9bc2007-04-25 09:53:01 -0400202 elsiocb->context2 = pcmd;
203 elsiocb->context3 = pbuflist;
dea31012005-04-17 16:05:31 -0500204 elsiocb->retry = retry;
James Smart2e0fef82007-06-17 19:56:36 -0500205 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -0500206 elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
207
208 if (prsp) {
209 list_add(&prsp->list, &pcmd->list);
210 }
dea31012005-04-17 16:05:31 -0500211 if (expectRsp) {
212 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400213 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
214 "0116 Xmit ELS command x%x to remote "
215 "NPORT x%x I/O tag: x%x, port state: x%x\n",
216 elscmd, did, elsiocb->iotag,
217 vport->port_state);
dea31012005-04-17 16:05:31 -0500218 } else {
219 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400220 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
221 "0117 Xmit ELS response x%x to remote "
222 "NPORT x%x I/O tag: x%x, size: x%x\n",
223 elscmd, ndlp->nlp_DID, elsiocb->iotag,
224 cmdSize);
dea31012005-04-17 16:05:31 -0500225 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500226 return elsiocb;
dea31012005-04-17 16:05:31 -0500227}
228
229
230static int
James Smart92d7f7b2007-06-17 19:56:38 -0500231lpfc_issue_fabric_reglogin(struct lpfc_vport *vport)
232{
233 struct lpfc_hba *phba = vport->phba;
234 LPFC_MBOXQ_t *mbox;
235 struct lpfc_dmabuf *mp;
236 struct lpfc_nodelist *ndlp;
237 struct serv_parm *sp;
238 int rc;
239
240 sp = &phba->fc_fabparam;
241 ndlp = lpfc_findnode_did(vport, Fabric_DID);
242 if (!ndlp)
243 goto fail;
244
245 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
246 if (!mbox)
247 goto fail;
248
249 vport->port_state = LPFC_FABRIC_CFG_LINK;
250 lpfc_config_link(phba, mbox);
251 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
252 mbox->vport = vport;
253
254 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT | MBX_STOP_IOCB);
255 if (rc == MBX_NOT_FINISHED)
256 goto fail_free_mbox;
257
258 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
259 if (!mbox)
260 goto fail;
261 rc = lpfc_reg_login(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox,
262 0);
263 if (rc)
264 goto fail_free_mbox;
265
266 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
267 mbox->vport = vport;
268 mbox->context2 = lpfc_nlp_get(ndlp);
269
270 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT | MBX_STOP_IOCB);
271 if (rc == MBX_NOT_FINISHED)
272 goto fail_issue_reg_login;
273
274 return 0;
275
276fail_issue_reg_login:
277 lpfc_nlp_put(ndlp);
278 mp = (struct lpfc_dmabuf *) mbox->context1;
279 lpfc_mbuf_free(phba, mp->virt, mp->phys);
280 kfree(mp);
281fail_free_mbox:
282 mempool_free(mbox, phba->mbox_mem_pool);
283
284fail:
285 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -0400286 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
287 "0249 Cannot issue Register Fabric login\n");
James Smart92d7f7b2007-06-17 19:56:38 -0500288 return -ENXIO;
289}
290
291static int
James Smart2e0fef82007-06-17 19:56:36 -0500292lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
293 struct serv_parm *sp, IOCB_t *irsp)
dea31012005-04-17 16:05:31 -0500294{
James Smart2e0fef82007-06-17 19:56:36 -0500295 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
296 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -0500297 struct lpfc_nodelist *np;
298 struct lpfc_nodelist *next_np;
dea31012005-04-17 16:05:31 -0500299
James Smart2e0fef82007-06-17 19:56:36 -0500300 spin_lock_irq(shost->host_lock);
301 vport->fc_flag |= FC_FABRIC;
302 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500303
304 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
305 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
306 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
307
308 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
309
310 if (phba->fc_topology == TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500311 spin_lock_irq(shost->host_lock);
312 vport->fc_flag |= FC_PUBLIC_LOOP;
313 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500314 } else {
315 /*
316 * If we are a N-port connected to a Fabric, fixup sparam's so
317 * logins to devices on remote loops work.
318 */
James Smart2e0fef82007-06-17 19:56:36 -0500319 vport->fc_sparam.cmn.altBbCredit = 1;
dea31012005-04-17 16:05:31 -0500320 }
321
James Smart2e0fef82007-06-17 19:56:36 -0500322 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
dea31012005-04-17 16:05:31 -0500323 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
James Smart92d7f7b2007-06-17 19:56:38 -0500324 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500325 ndlp->nlp_class_sup = 0;
326 if (sp->cls1.classValid)
327 ndlp->nlp_class_sup |= FC_COS_CLASS1;
328 if (sp->cls2.classValid)
329 ndlp->nlp_class_sup |= FC_COS_CLASS2;
330 if (sp->cls3.classValid)
331 ndlp->nlp_class_sup |= FC_COS_CLASS3;
332 if (sp->cls4.classValid)
333 ndlp->nlp_class_sup |= FC_COS_CLASS4;
334 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
335 sp->cmn.bbRcvSizeLsb;
336 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
337
James Smart92d7f7b2007-06-17 19:56:38 -0500338 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
339 if (sp->cmn.response_multiple_NPort) {
James Smarte8b62012007-08-02 11:10:09 -0400340 lpfc_printf_vlog(vport, KERN_WARNING,
341 LOG_ELS | LOG_VPORT,
342 "1816 FLOGI NPIV supported, "
343 "response data 0x%x\n",
344 sp->cmn.response_multiple_NPort);
James Smart92d7f7b2007-06-17 19:56:38 -0500345 phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
James Smart92d7f7b2007-06-17 19:56:38 -0500346 } else {
347 /* Because we asked f/w for NPIV it still expects us
James Smarte8b62012007-08-02 11:10:09 -0400348 to call reg_vnpid atleast for the physcial host */
349 lpfc_printf_vlog(vport, KERN_WARNING,
350 LOG_ELS | LOG_VPORT,
351 "1817 Fabric does not support NPIV "
352 "- configuring single port mode.\n");
James Smart92d7f7b2007-06-17 19:56:38 -0500353 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
354 }
355 }
356
357 if ((vport->fc_prevDID != vport->fc_myDID) &&
358 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
359
360 /* If our NportID changed, we need to ensure all
361 * remaining NPORTs get unreg_login'ed.
362 */
363 list_for_each_entry_safe(np, next_np,
364 &vport->fc_nodes, nlp_listp) {
365 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
366 !(np->nlp_flag & NLP_NPR_ADISC))
367 continue;
368 spin_lock_irq(shost->host_lock);
369 np->nlp_flag &= ~NLP_NPR_ADISC;
370 spin_unlock_irq(shost->host_lock);
371 lpfc_unreg_rpi(vport, np);
372 }
373 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
374 lpfc_mbx_unreg_vpi(vport);
375 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
376 }
377 }
378
James Smart2e0fef82007-06-17 19:56:36 -0500379 ndlp->nlp_sid = irsp->un.ulpWord[4] & Mask_DID;
James Smart92d7f7b2007-06-17 19:56:38 -0500380 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -0500381
James Smart92d7f7b2007-06-17 19:56:38 -0500382 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
383 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) {
384 lpfc_register_new_vport(phba, vport, ndlp);
385 return 0;
386 }
387 lpfc_issue_fabric_reglogin(vport);
dea31012005-04-17 16:05:31 -0500388 return 0;
dea31012005-04-17 16:05:31 -0500389}
390
391/*
392 * We FLOGIed into an NPort, initiate pt2pt protocol
393 */
394static int
James Smart2e0fef82007-06-17 19:56:36 -0500395lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
396 struct serv_parm *sp)
dea31012005-04-17 16:05:31 -0500397{
James Smart2e0fef82007-06-17 19:56:36 -0500398 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
399 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500400 LPFC_MBOXQ_t *mbox;
401 int rc;
402
James Smart2e0fef82007-06-17 19:56:36 -0500403 spin_lock_irq(shost->host_lock);
404 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
405 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500406
407 phba->fc_edtov = FF_DEF_EDTOV;
408 phba->fc_ratov = FF_DEF_RATOV;
James Smart2e0fef82007-06-17 19:56:36 -0500409 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -0500410 sizeof(vport->fc_portname));
dea31012005-04-17 16:05:31 -0500411 if (rc >= 0) {
412 /* This side will initiate the PLOGI */
James Smart2e0fef82007-06-17 19:56:36 -0500413 spin_lock_irq(shost->host_lock);
414 vport->fc_flag |= FC_PT2PT_PLOGI;
415 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500416
417 /*
418 * N_Port ID cannot be 0, set our to LocalID the other
419 * side will be RemoteID.
420 */
421
422 /* not equal */
423 if (rc)
James Smart2e0fef82007-06-17 19:56:36 -0500424 vport->fc_myDID = PT2PT_LocalID;
dea31012005-04-17 16:05:31 -0500425
426 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
427 if (!mbox)
428 goto fail;
429
430 lpfc_config_link(phba, mbox);
431
432 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -0500433 mbox->vport = vport;
dea31012005-04-17 16:05:31 -0500434 rc = lpfc_sli_issue_mbox(phba, mbox,
James Smart92d7f7b2007-06-17 19:56:38 -0500435 MBX_NOWAIT | MBX_STOP_IOCB);
dea31012005-04-17 16:05:31 -0500436 if (rc == MBX_NOT_FINISHED) {
437 mempool_free(mbox, phba->mbox_mem_pool);
438 goto fail;
439 }
James Smart329f9bc2007-04-25 09:53:01 -0400440 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500441
James Smart2e0fef82007-06-17 19:56:36 -0500442 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
dea31012005-04-17 16:05:31 -0500443 if (!ndlp) {
444 /*
445 * Cannot find existing Fabric ndlp, so allocate a
446 * new one
447 */
448 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
449 if (!ndlp)
450 goto fail;
451
James Smart2e0fef82007-06-17 19:56:36 -0500452 lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID);
dea31012005-04-17 16:05:31 -0500453 }
454
455 memcpy(&ndlp->nlp_portname, &sp->portName,
James Smart2e0fef82007-06-17 19:56:36 -0500456 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500457 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
James Smart2e0fef82007-06-17 19:56:36 -0500458 sizeof(struct lpfc_name));
459 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
460 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500461 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500462 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500463 } else {
464 /* This side will wait for the PLOGI */
James Smart329f9bc2007-04-25 09:53:01 -0400465 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500466 }
467
James Smart2e0fef82007-06-17 19:56:36 -0500468 spin_lock_irq(shost->host_lock);
469 vport->fc_flag |= FC_PT2PT;
470 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500471
472 /* Start discovery - this should just do CLEAR_LA */
James Smart2e0fef82007-06-17 19:56:36 -0500473 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -0500474 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500475fail:
dea31012005-04-17 16:05:31 -0500476 return -ENXIO;
477}
478
479static void
James Smart329f9bc2007-04-25 09:53:01 -0400480lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
481 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500482{
James Smart2e0fef82007-06-17 19:56:36 -0500483 struct lpfc_vport *vport = cmdiocb->vport;
484 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500485 IOCB_t *irsp = &rspiocb->iocb;
486 struct lpfc_nodelist *ndlp = cmdiocb->context1;
487 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
488 struct serv_parm *sp;
489 int rc;
490
491 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500492 if (lpfc_els_chk_latt(vport)) {
James Smart329f9bc2007-04-25 09:53:01 -0400493 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500494 goto out;
495 }
496
James Smart858c9f62007-06-17 19:56:39 -0500497 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
498 "FLOGI cmpl: status:x%x/x%x state:x%x",
499 irsp->ulpStatus, irsp->un.ulpWord[4],
500 vport->port_state);
501
dea31012005-04-17 16:05:31 -0500502 if (irsp->ulpStatus) {
503 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -0500504 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -0500505 goto out;
James Smart2e0fef82007-06-17 19:56:36 -0500506
dea31012005-04-17 16:05:31 -0500507 /* FLOGI failed, so there is no fabric */
James Smart2e0fef82007-06-17 19:56:36 -0500508 spin_lock_irq(shost->host_lock);
509 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
510 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500511
James Smart329f9bc2007-04-25 09:53:01 -0400512 /* If private loop, then allow max outstanding els to be
dea31012005-04-17 16:05:31 -0500513 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
514 * alpa map would take too long otherwise.
515 */
516 if (phba->alpa_map[0] == 0) {
James Smart3de2a652007-08-02 11:09:59 -0400517 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
dea31012005-04-17 16:05:31 -0500518 }
519
520 /* FLOGI failure */
James Smarte8b62012007-08-02 11:10:09 -0400521 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
522 "0100 FLOGI failure Data: x%x x%x "
523 "x%x\n",
524 irsp->ulpStatus, irsp->un.ulpWord[4],
525 irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -0500526 goto flogifail;
527 }
528
529 /*
530 * The FLogI succeeded. Sync the data for the CPU before
531 * accessing it.
532 */
533 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
534
535 sp = prsp->virt + sizeof(uint32_t);
536
537 /* FLOGI completes successfully */
James Smarte8b62012007-08-02 11:10:09 -0400538 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
539 "0101 FLOGI completes sucessfully "
540 "Data: x%x x%x x%x x%x\n",
541 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
542 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution);
dea31012005-04-17 16:05:31 -0500543
James Smart2e0fef82007-06-17 19:56:36 -0500544 if (vport->port_state == LPFC_FLOGI) {
dea31012005-04-17 16:05:31 -0500545 /*
546 * If Common Service Parameters indicate Nport
547 * we are point to point, if Fport we are Fabric.
548 */
549 if (sp->cmn.fPort)
James Smart2e0fef82007-06-17 19:56:36 -0500550 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
dea31012005-04-17 16:05:31 -0500551 else
James Smart2e0fef82007-06-17 19:56:36 -0500552 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
dea31012005-04-17 16:05:31 -0500553
554 if (!rc)
555 goto out;
556 }
557
558flogifail:
James Smart329f9bc2007-04-25 09:53:01 -0400559 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500560
James Smart858c9f62007-06-17 19:56:39 -0500561 if (!lpfc_error_lost_link(irsp)) {
dea31012005-04-17 16:05:31 -0500562 /* FLOGI failed, so just use loop map to make discovery list */
James Smart2e0fef82007-06-17 19:56:36 -0500563 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -0500564
565 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500566 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -0500567 }
568
569out:
570 lpfc_els_free_iocb(phba, cmdiocb);
571}
572
573static int
James Smart2e0fef82007-06-17 19:56:36 -0500574lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -0500575 uint8_t retry)
576{
James Smart2e0fef82007-06-17 19:56:36 -0500577 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500578 struct serv_parm *sp;
579 IOCB_t *icmd;
580 struct lpfc_iocbq *elsiocb;
581 struct lpfc_sli_ring *pring;
582 uint8_t *pcmd;
583 uint16_t cmdsize;
584 uint32_t tmo;
585 int rc;
586
587 pring = &phba->sli.ring[LPFC_ELS_RING];
588
James Smart92d7f7b2007-06-17 19:56:38 -0500589 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart2e0fef82007-06-17 19:56:36 -0500590 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
591 ndlp->nlp_DID, ELS_CMD_FLOGI);
James Smart92d7f7b2007-06-17 19:56:38 -0500592
James Smart488d1462006-03-07 15:02:37 -0500593 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500594 return 1;
dea31012005-04-17 16:05:31 -0500595
596 icmd = &elsiocb->iocb;
597 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
598
599 /* For FLOGI request, remainder of payload is service parameters */
600 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -0500601 pcmd += sizeof(uint32_t);
602 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -0500603 sp = (struct serv_parm *) pcmd;
604
605 /* Setup CSPs accordingly for Fabric */
606 sp->cmn.e_d_tov = 0;
607 sp->cmn.w2.r_a_tov = 0;
608 sp->cls1.classValid = 0;
609 sp->cls2.seqDelivery = 1;
610 sp->cls3.seqDelivery = 1;
611 if (sp->cmn.fcphLow < FC_PH3)
612 sp->cmn.fcphLow = FC_PH3;
613 if (sp->cmn.fcphHigh < FC_PH3)
614 sp->cmn.fcphHigh = FC_PH3;
615
James Smart92d7f7b2007-06-17 19:56:38 -0500616 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
617 sp->cmn.request_multiple_Nport = 1;
618
619 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
620 icmd->ulpCt_h = 1;
621 icmd->ulpCt_l = 0;
622 }
623
James Smart858c9f62007-06-17 19:56:39 -0500624 if (phba->fc_topology != TOPOLOGY_LOOP) {
625 icmd->un.elsreq64.myID = 0;
626 icmd->un.elsreq64.fl = 1;
627 }
628
dea31012005-04-17 16:05:31 -0500629 tmo = phba->fc_ratov;
630 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
James Smart2e0fef82007-06-17 19:56:36 -0500631 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -0500632 phba->fc_ratov = tmo;
633
634 phba->fc_stat.elsXmitFLOGI++;
635 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
James Smart858c9f62007-06-17 19:56:39 -0500636
637 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
638 "Issue FLOGI: opt:x%x",
639 phba->sli3_options, 0, 0);
640
James Smart92d7f7b2007-06-17 19:56:38 -0500641 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
dea31012005-04-17 16:05:31 -0500642 if (rc == IOCB_ERROR) {
643 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500644 return 1;
dea31012005-04-17 16:05:31 -0500645 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500646 return 0;
dea31012005-04-17 16:05:31 -0500647}
648
649int
James Smart2e0fef82007-06-17 19:56:36 -0500650lpfc_els_abort_flogi(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500651{
652 struct lpfc_sli_ring *pring;
653 struct lpfc_iocbq *iocb, *next_iocb;
654 struct lpfc_nodelist *ndlp;
655 IOCB_t *icmd;
656
657 /* Abort outstanding I/O on NPort <nlp_DID> */
658 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -0400659 "0201 Abort outstanding I/O on NPort x%x\n",
660 Fabric_DID);
dea31012005-04-17 16:05:31 -0500661
662 pring = &phba->sli.ring[LPFC_ELS_RING];
663
664 /*
665 * Check the txcmplq for an iocb that matches the nport the driver is
666 * searching for.
667 */
James Smart2e0fef82007-06-17 19:56:36 -0500668 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500669 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
670 icmd = &iocb->iocb;
James Smart2e0fef82007-06-17 19:56:36 -0500671 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR &&
672 icmd->un.elsreq64.bdl.ulpIoTag32) {
dea31012005-04-17 16:05:31 -0500673 ndlp = (struct lpfc_nodelist *)(iocb->context1);
James Smart92d7f7b2007-06-17 19:56:38 -0500674 if (ndlp && (ndlp->nlp_DID == Fabric_DID)) {
James Smart07951072007-04-25 09:51:38 -0400675 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
James Smart92d7f7b2007-06-17 19:56:38 -0500676 }
dea31012005-04-17 16:05:31 -0500677 }
678 }
James Smart2e0fef82007-06-17 19:56:36 -0500679 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500680
681 return 0;
682}
683
684int
James Smart2e0fef82007-06-17 19:56:36 -0500685lpfc_initial_flogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -0500686{
James Smart2e0fef82007-06-17 19:56:36 -0500687 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500688 struct lpfc_nodelist *ndlp;
689
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500690 /* First look for the Fabric ndlp */
James Smart2e0fef82007-06-17 19:56:36 -0500691 ndlp = lpfc_findnode_did(vport, Fabric_DID);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500692 if (!ndlp) {
dea31012005-04-17 16:05:31 -0500693 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500694 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
695 if (!ndlp)
696 return 0;
James Smart2e0fef82007-06-17 19:56:36 -0500697 lpfc_nlp_init(vport, ndlp, Fabric_DID);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500698 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500699 lpfc_dequeue_node(vport, ndlp);
dea31012005-04-17 16:05:31 -0500700 }
James Smart2e0fef82007-06-17 19:56:36 -0500701 if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
James Smart329f9bc2007-04-25 09:53:01 -0400702 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500703 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500704 return 1;
dea31012005-04-17 16:05:31 -0500705}
706
James Smart92d7f7b2007-06-17 19:56:38 -0500707int
708lpfc_initial_fdisc(struct lpfc_vport *vport)
709{
710 struct lpfc_hba *phba = vport->phba;
711 struct lpfc_nodelist *ndlp;
712
713 /* First look for the Fabric ndlp */
714 ndlp = lpfc_findnode_did(vport, Fabric_DID);
715 if (!ndlp) {
716 /* Cannot find existing Fabric ndlp, so allocate a new one */
717 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
718 if (!ndlp)
719 return 0;
720 lpfc_nlp_init(vport, ndlp, Fabric_DID);
721 } else {
722 lpfc_dequeue_node(vport, ndlp);
723 }
724 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
725 lpfc_nlp_put(ndlp);
726 }
727 return 1;
728}
dea31012005-04-17 16:05:31 -0500729static void
James Smart2e0fef82007-06-17 19:56:36 -0500730lpfc_more_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -0500731{
732 int sentplogi;
733
James Smart2e0fef82007-06-17 19:56:36 -0500734 if (vport->num_disc_nodes)
735 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -0500736
737 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
James Smarte8b62012007-08-02 11:10:09 -0400738 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
739 "0232 Continue discovery with %d PLOGIs to go "
740 "Data: x%x x%x x%x\n",
741 vport->num_disc_nodes, vport->fc_plogi_cnt,
742 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -0500743 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -0500744 if (vport->fc_flag & FC_NLP_MORE)
745 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
746 sentplogi = lpfc_els_disc_plogi(vport);
747
dea31012005-04-17 16:05:31 -0500748 return;
749}
750
James Smart488d1462006-03-07 15:02:37 -0500751static struct lpfc_nodelist *
James Smart92d7f7b2007-06-17 19:56:38 -0500752lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
James Smart488d1462006-03-07 15:02:37 -0500753 struct lpfc_nodelist *ndlp)
754{
James Smart2e0fef82007-06-17 19:56:36 -0500755 struct lpfc_vport *vport = ndlp->vport;
James Smart488d1462006-03-07 15:02:37 -0500756 struct lpfc_nodelist *new_ndlp;
James Smart488d1462006-03-07 15:02:37 -0500757 struct serv_parm *sp;
James Smart92d7f7b2007-06-17 19:56:38 -0500758 uint8_t name[sizeof(struct lpfc_name)];
James Smart488d1462006-03-07 15:02:37 -0500759 uint32_t rc;
760
James Smart2fb9bd82006-12-02 13:33:57 -0500761 /* Fabric nodes can have the same WWPN so we don't bother searching
762 * by WWPN. Just return the ndlp that was given to us.
763 */
764 if (ndlp->nlp_type & NLP_FABRIC)
765 return ndlp;
766
James Smart92d7f7b2007-06-17 19:56:38 -0500767 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
James Smart685f0bf2007-04-25 09:53:08 -0400768 memset(name, 0, sizeof(struct lpfc_name));
James Smart488d1462006-03-07 15:02:37 -0500769
James Smart685f0bf2007-04-25 09:53:08 -0400770 /* Now we find out if the NPort we are logging into, matches the WWPN
James Smart488d1462006-03-07 15:02:37 -0500771 * we have for that ndlp. If not, we have some work to do.
772 */
James Smart2e0fef82007-06-17 19:56:36 -0500773 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
James Smart488d1462006-03-07 15:02:37 -0500774
James Smart92795652006-07-06 15:50:02 -0400775 if (new_ndlp == ndlp)
James Smart488d1462006-03-07 15:02:37 -0500776 return ndlp;
James Smart488d1462006-03-07 15:02:37 -0500777
778 if (!new_ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -0500779 rc = memcmp(&ndlp->nlp_portname, name,
780 sizeof(struct lpfc_name));
James Smart92795652006-07-06 15:50:02 -0400781 if (!rc)
782 return ndlp;
James Smart488d1462006-03-07 15:02:37 -0500783 new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
784 if (!new_ndlp)
785 return ndlp;
786
James Smart2e0fef82007-06-17 19:56:36 -0500787 lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID);
James Smart488d1462006-03-07 15:02:37 -0500788 }
789
James Smart2e0fef82007-06-17 19:56:36 -0500790 lpfc_unreg_rpi(vport, new_ndlp);
James Smart488d1462006-03-07 15:02:37 -0500791 new_ndlp->nlp_DID = ndlp->nlp_DID;
James Smart92795652006-07-06 15:50:02 -0400792 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
James Smart2e0fef82007-06-17 19:56:36 -0500793 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
James Smart488d1462006-03-07 15:02:37 -0500794
James Smart2e0fef82007-06-17 19:56:36 -0500795 /* Move this back to NPR state */
James Smartde0c5b32007-04-25 09:52:27 -0400796 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0)
James Smart2e0fef82007-06-17 19:56:36 -0500797 lpfc_drop_node(vport, ndlp);
James Smart92795652006-07-06 15:50:02 -0400798 else {
James Smart2e0fef82007-06-17 19:56:36 -0500799 lpfc_unreg_rpi(vport, ndlp);
James Smart92795652006-07-06 15:50:02 -0400800 ndlp->nlp_DID = 0; /* Two ndlps cannot have the same did */
James Smart2e0fef82007-06-17 19:56:36 -0500801 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smart92795652006-07-06 15:50:02 -0400802 }
James Smart488d1462006-03-07 15:02:37 -0500803 return new_ndlp;
804}
805
dea31012005-04-17 16:05:31 -0500806static void
James Smart2e0fef82007-06-17 19:56:36 -0500807lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
808 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500809{
James Smart2e0fef82007-06-17 19:56:36 -0500810 struct lpfc_vport *vport = cmdiocb->vport;
811 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500812 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -0500813 struct lpfc_nodelist *ndlp;
James Smart92795652006-07-06 15:50:02 -0400814 struct lpfc_dmabuf *prsp;
dea31012005-04-17 16:05:31 -0500815 int disc, rc, did, type;
816
dea31012005-04-17 16:05:31 -0500817 /* we pass cmdiocb to state machine which needs rspiocb as well */
818 cmdiocb->context_un.rsp_iocb = rspiocb;
819
820 irsp = &rspiocb->iocb;
James Smart858c9f62007-06-17 19:56:39 -0500821 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
822 "PLOGI cmpl: status:x%x/x%x did:x%x",
823 irsp->ulpStatus, irsp->un.ulpWord[4],
824 irsp->un.elsreq64.remoteID);
825
James Smart2e0fef82007-06-17 19:56:36 -0500826 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
James Smarted957682007-06-17 19:56:37 -0500827 if (!ndlp) {
James Smarte8b62012007-08-02 11:10:09 -0400828 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
829 "0136 PLOGI completes to NPort x%x "
830 "with no ndlp. Data: x%x x%x x%x\n",
831 irsp->un.elsreq64.remoteID,
832 irsp->ulpStatus, irsp->un.ulpWord[4],
833 irsp->ulpIoTag);
James Smart488d1462006-03-07 15:02:37 -0500834 goto out;
James Smarted957682007-06-17 19:56:37 -0500835 }
dea31012005-04-17 16:05:31 -0500836
837 /* Since ndlp can be freed in the disc state machine, note if this node
838 * is being used during discovery.
839 */
James Smart2e0fef82007-06-17 19:56:36 -0500840 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500841 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
James Smart488d1462006-03-07 15:02:37 -0500842 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500843 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500844 rc = 0;
845
846 /* PLOGI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -0400847 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
848 "0102 PLOGI completes to NPort x%x "
849 "Data: x%x x%x x%x x%x x%x\n",
850 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
851 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -0500852 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500853 if (lpfc_els_chk_latt(vport)) {
854 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500855 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500856 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500857 goto out;
858 }
859
860 /* ndlp could be freed in DSM, save these values now */
861 type = ndlp->nlp_type;
862 did = ndlp->nlp_DID;
863
864 if (irsp->ulpStatus) {
865 /* Check for retry */
866 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
867 /* ELS command is being retried */
868 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -0500869 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500870 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500871 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500872 }
873 goto out;
874 }
dea31012005-04-17 16:05:31 -0500875 /* PLOGI failed */
James Smart92d7f7b2007-06-17 19:56:38 -0500876 if (ndlp->nlp_DID == NameServer_DID) {
877 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -0400878 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
879 "0250 Nameserver login error: "
880 "0x%x / 0x%x\n",
881 irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smart92d7f7b2007-06-17 19:56:38 -0500882 }
dea31012005-04-17 16:05:31 -0500883 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart858c9f62007-06-17 19:56:39 -0500884 if (lpfc_error_lost_link(irsp)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500885 rc = NLP_STE_FREED_NODE;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500886 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500887 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -0500888 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -0500889 }
890 } else {
891 /* Good status, call state machine */
James Smart92795652006-07-06 15:50:02 -0400892 prsp = list_entry(((struct lpfc_dmabuf *)
James Smart92d7f7b2007-06-17 19:56:38 -0500893 cmdiocb->context2)->list.next,
894 struct lpfc_dmabuf, list);
895 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -0500896 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -0500897 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -0500898 }
899
James Smart2e0fef82007-06-17 19:56:36 -0500900 if (disc && vport->num_disc_nodes) {
dea31012005-04-17 16:05:31 -0500901 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -0500902 lpfc_more_plogi(vport);
dea31012005-04-17 16:05:31 -0500903
James Smart2e0fef82007-06-17 19:56:36 -0500904 if (vport->num_disc_nodes == 0) {
905 spin_lock_irq(shost->host_lock);
906 vport->fc_flag &= ~FC_NDISC_ACTIVE;
907 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500908
James Smart2e0fef82007-06-17 19:56:36 -0500909 lpfc_can_disctmo(vport);
910 if (vport->fc_flag & FC_RSCN_MODE) {
James Smart10d4e952006-04-15 11:53:15 -0400911 /*
912 * Check to see if more RSCNs came in while
913 * we were processing this one.
914 */
James Smart2e0fef82007-06-17 19:56:36 -0500915 if ((vport->fc_rscn_id_cnt == 0) &&
916 (!(vport->fc_flag & FC_RSCN_DISCOVERY))) {
917 spin_lock_irq(shost->host_lock);
918 vport->fc_flag &= ~FC_RSCN_MODE;
919 spin_unlock_irq(shost->host_lock);
James Smart10d4e952006-04-15 11:53:15 -0400920 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500921 lpfc_els_handle_rscn(vport);
James Smart10d4e952006-04-15 11:53:15 -0400922 }
dea31012005-04-17 16:05:31 -0500923 }
924 }
925 }
926
927out:
928 lpfc_els_free_iocb(phba, cmdiocb);
929 return;
930}
931
932int
James Smart2e0fef82007-06-17 19:56:36 -0500933lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
dea31012005-04-17 16:05:31 -0500934{
James Smart2e0fef82007-06-17 19:56:36 -0500935 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500936 struct serv_parm *sp;
937 IOCB_t *icmd;
938 struct lpfc_iocbq *elsiocb;
939 struct lpfc_sli_ring *pring;
940 struct lpfc_sli *psli;
941 uint8_t *pcmd;
942 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -0500943 int ret;
dea31012005-04-17 16:05:31 -0500944
945 psli = &phba->sli;
946 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
947
James Smart92d7f7b2007-06-17 19:56:38 -0500948 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart2e0fef82007-06-17 19:56:36 -0500949 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, NULL, did,
950 ELS_CMD_PLOGI);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500951 if (!elsiocb)
952 return 1;
dea31012005-04-17 16:05:31 -0500953
954 icmd = &elsiocb->iocb;
955 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
956
957 /* For PLOGI request, remainder of payload is service parameters */
958 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -0500959 pcmd += sizeof(uint32_t);
960 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -0500961 sp = (struct serv_parm *) pcmd;
962
963 if (sp->cmn.fcphLow < FC_PH_4_3)
964 sp->cmn.fcphLow = FC_PH_4_3;
965
966 if (sp->cmn.fcphHigh < FC_PH3)
967 sp->cmn.fcphHigh = FC_PH3;
968
James Smart858c9f62007-06-17 19:56:39 -0500969 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
970 "Issue PLOGI: did:x%x",
971 did, 0, 0);
972
dea31012005-04-17 16:05:31 -0500973 phba->fc_stat.elsXmitPLOGI++;
974 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
James Smart92d7f7b2007-06-17 19:56:38 -0500975 ret = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
976
977 if (ret == IOCB_ERROR) {
dea31012005-04-17 16:05:31 -0500978 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500979 return 1;
dea31012005-04-17 16:05:31 -0500980 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500981 return 0;
dea31012005-04-17 16:05:31 -0500982}
983
984static void
James Smart2e0fef82007-06-17 19:56:36 -0500985lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
986 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500987{
James Smart2e0fef82007-06-17 19:56:36 -0500988 struct lpfc_vport *vport = cmdiocb->vport;
989 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500990 IOCB_t *irsp;
991 struct lpfc_sli *psli;
992 struct lpfc_nodelist *ndlp;
993
994 psli = &phba->sli;
995 /* we pass cmdiocb to state machine which needs rspiocb as well */
996 cmdiocb->context_un.rsp_iocb = rspiocb;
997
998 irsp = &(rspiocb->iocb);
999 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
James Smart2e0fef82007-06-17 19:56:36 -05001000 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001001 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001002 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001003
James Smart858c9f62007-06-17 19:56:39 -05001004 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1005 "PRLI cmpl: status:x%x/x%x did:x%x",
1006 irsp->ulpStatus, irsp->un.ulpWord[4],
1007 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05001008 /* PRLI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001009 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1010 "0103 PRLI completes to NPort x%x "
1011 "Data: x%x x%x x%x x%x\n",
1012 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1013 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001014
James Smart2e0fef82007-06-17 19:56:36 -05001015 vport->fc_prli_sent--;
dea31012005-04-17 16:05:31 -05001016 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001017 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05001018 goto out;
1019
1020 if (irsp->ulpStatus) {
1021 /* Check for retry */
1022 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1023 /* ELS command is being retried */
1024 goto out;
1025 }
1026 /* PRLI failed */
1027 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart858c9f62007-06-17 19:56:39 -05001028 if (lpfc_error_lost_link(irsp)) {
dea31012005-04-17 16:05:31 -05001029 goto out;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001030 } else {
James Smart2e0fef82007-06-17 19:56:36 -05001031 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001032 NLP_EVT_CMPL_PRLI);
dea31012005-04-17 16:05:31 -05001033 }
1034 } else {
1035 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05001036 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001037 NLP_EVT_CMPL_PRLI);
dea31012005-04-17 16:05:31 -05001038 }
1039
1040out:
1041 lpfc_els_free_iocb(phba, cmdiocb);
1042 return;
1043}
1044
1045int
James Smart2e0fef82007-06-17 19:56:36 -05001046lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001047 uint8_t retry)
1048{
James Smart2e0fef82007-06-17 19:56:36 -05001049 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1050 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001051 PRLI *npr;
1052 IOCB_t *icmd;
1053 struct lpfc_iocbq *elsiocb;
1054 struct lpfc_sli_ring *pring;
1055 struct lpfc_sli *psli;
1056 uint8_t *pcmd;
1057 uint16_t cmdsize;
1058
1059 psli = &phba->sli;
1060 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1061
James Smart92d7f7b2007-06-17 19:56:38 -05001062 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
James Smart2e0fef82007-06-17 19:56:36 -05001063 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1064 ndlp->nlp_DID, ELS_CMD_PRLI);
James Smart488d1462006-03-07 15:02:37 -05001065 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001066 return 1;
dea31012005-04-17 16:05:31 -05001067
1068 icmd = &elsiocb->iocb;
1069 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1070
1071 /* For PRLI request, remainder of payload is service parameters */
James Smart92d7f7b2007-06-17 19:56:38 -05001072 memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t)));
dea31012005-04-17 16:05:31 -05001073 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
James Smart92d7f7b2007-06-17 19:56:38 -05001074 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001075
1076 /* For PRLI, remainder of payload is PRLI parameter page */
1077 npr = (PRLI *) pcmd;
1078 /*
1079 * If our firmware version is 3.20 or later,
1080 * set the following bits for FC-TAPE support.
1081 */
1082 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
1083 npr->ConfmComplAllowed = 1;
1084 npr->Retry = 1;
1085 npr->TaskRetryIdReq = 1;
1086 }
1087 npr->estabImagePair = 1;
1088 npr->readXferRdyDis = 1;
1089
1090 /* For FCP support */
1091 npr->prliType = PRLI_FCP_TYPE;
1092 npr->initiatorFunc = 1;
1093
James Smart858c9f62007-06-17 19:56:39 -05001094 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1095 "Issue PRLI: did:x%x",
1096 ndlp->nlp_DID, 0, 0);
1097
dea31012005-04-17 16:05:31 -05001098 phba->fc_stat.elsXmitPRLI++;
1099 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
James Smart2e0fef82007-06-17 19:56:36 -05001100 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001101 ndlp->nlp_flag |= NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001102 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001103 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05001104 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001105 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001106 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001107 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001108 return 1;
dea31012005-04-17 16:05:31 -05001109 }
James Smart2e0fef82007-06-17 19:56:36 -05001110 vport->fc_prli_sent++;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001111 return 0;
dea31012005-04-17 16:05:31 -05001112}
1113
1114static void
James Smart2e0fef82007-06-17 19:56:36 -05001115lpfc_more_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001116{
1117 int sentadisc;
1118
James Smart2e0fef82007-06-17 19:56:36 -05001119 if (vport->num_disc_nodes)
1120 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001121 /* Continue discovery with <num_disc_nodes> ADISCs to go */
James Smarte8b62012007-08-02 11:10:09 -04001122 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1123 "0210 Continue discovery with %d ADISCs to go "
1124 "Data: x%x x%x x%x\n",
1125 vport->num_disc_nodes, vport->fc_adisc_cnt,
1126 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001127 /* Check to see if there are more ADISCs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001128 if (vport->fc_flag & FC_NLP_MORE) {
1129 lpfc_set_disctmo(vport);
1130 /* go thru NPR nodes and issue any remaining ELS ADISCs */
1131 sentadisc = lpfc_els_disc_adisc(vport);
dea31012005-04-17 16:05:31 -05001132 }
1133 return;
1134}
1135
1136static void
James Smart2e0fef82007-06-17 19:56:36 -05001137lpfc_rscn_disc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001138{
James Smart2e0fef82007-06-17 19:56:36 -05001139 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1140
James Smart858c9f62007-06-17 19:56:39 -05001141 lpfc_can_disctmo(vport);
1142
dea31012005-04-17 16:05:31 -05001143 /* RSCN discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001144 /* go thru NPR nodes and issue ELS PLOGIs */
1145 if (vport->fc_npr_cnt)
1146 if (lpfc_els_disc_plogi(vport))
dea31012005-04-17 16:05:31 -05001147 return;
James Smart2e0fef82007-06-17 19:56:36 -05001148
1149 if (vport->fc_flag & FC_RSCN_MODE) {
dea31012005-04-17 16:05:31 -05001150 /* Check to see if more RSCNs came in while we were
1151 * processing this one.
1152 */
James Smart2e0fef82007-06-17 19:56:36 -05001153 if ((vport->fc_rscn_id_cnt == 0) &&
1154 (!(vport->fc_flag & FC_RSCN_DISCOVERY))) {
1155 spin_lock_irq(shost->host_lock);
1156 vport->fc_flag &= ~FC_RSCN_MODE;
1157 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001158 } else {
James Smart2e0fef82007-06-17 19:56:36 -05001159 lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05001160 }
1161 }
1162}
1163
1164static void
James Smart2e0fef82007-06-17 19:56:36 -05001165lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1166 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001167{
James Smart2e0fef82007-06-17 19:56:36 -05001168 struct lpfc_vport *vport = cmdiocb->vport;
1169 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001170 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001171 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001172 int disc;
dea31012005-04-17 16:05:31 -05001173
1174 /* we pass cmdiocb to state machine which needs rspiocb as well */
1175 cmdiocb->context_un.rsp_iocb = rspiocb;
1176
1177 irsp = &(rspiocb->iocb);
1178 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
dea31012005-04-17 16:05:31 -05001179
James Smart858c9f62007-06-17 19:56:39 -05001180 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1181 "ADISC cmpl: status:x%x/x%x did:x%x",
1182 irsp->ulpStatus, irsp->un.ulpWord[4],
1183 ndlp->nlp_DID);
1184
dea31012005-04-17 16:05:31 -05001185 /* Since ndlp can be freed in the disc state machine, note if this node
1186 * is being used during discovery.
1187 */
James Smart2e0fef82007-06-17 19:56:36 -05001188 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001189 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001190 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001191 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001192 /* ADISC completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001193 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1194 "0104 ADISC completes to NPort x%x "
1195 "Data: x%x x%x x%x x%x x%x\n",
1196 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1197 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001198 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001199 if (lpfc_els_chk_latt(vport)) {
1200 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001201 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001202 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001203 goto out;
1204 }
1205
1206 if (irsp->ulpStatus) {
1207 /* Check for retry */
1208 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1209 /* ELS command is being retried */
1210 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05001211 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001212 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001213 spin_unlock_irq(shost->host_lock);
1214 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001215 }
1216 goto out;
1217 }
1218 /* ADISC failed */
1219 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart858c9f62007-06-17 19:56:39 -05001220 if (!lpfc_error_lost_link(irsp)) {
James Smart2e0fef82007-06-17 19:56:36 -05001221 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart858c9f62007-06-17 19:56:39 -05001222 NLP_EVT_CMPL_ADISC);
dea31012005-04-17 16:05:31 -05001223 }
1224 } else {
1225 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05001226 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
dea31012005-04-17 16:05:31 -05001227 NLP_EVT_CMPL_ADISC);
1228 }
1229
James Smart2e0fef82007-06-17 19:56:36 -05001230 if (disc && vport->num_disc_nodes) {
dea31012005-04-17 16:05:31 -05001231 /* Check to see if there are more ADISCs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001232 lpfc_more_adisc(vport);
dea31012005-04-17 16:05:31 -05001233
1234 /* Check to see if we are done with ADISC authentication */
James Smart2e0fef82007-06-17 19:56:36 -05001235 if (vport->num_disc_nodes == 0) {
James Smart92d7f7b2007-06-17 19:56:38 -05001236 /* If we get here, there is nothing left to ADISC */
1237 /*
1238 * For NPIV, cmpl_reg_vpi will set port_state to READY,
1239 * and continue discovery.
1240 */
1241 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
1242 !(vport->fc_flag & FC_RSCN_MODE)) {
1243 lpfc_issue_reg_vpi(phba, vport);
1244 goto out;
1245 }
1246 /*
1247 * For SLI2, we need to set port_state to READY
1248 * and continue discovery.
1249 */
1250 if (vport->port_state < LPFC_VPORT_READY) {
1251 /* If we get here, there is nothing to ADISC */
James Smarted957682007-06-17 19:56:37 -05001252 if (vport->port_type == LPFC_PHYSICAL_PORT)
James Smart2e0fef82007-06-17 19:56:36 -05001253 lpfc_issue_clear_la(phba, vport);
James Smart92d7f7b2007-06-17 19:56:38 -05001254
1255 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
1256 vport->num_disc_nodes = 0;
1257 /* go thru NPR list, issue ELS PLOGIs */
1258 if (vport->fc_npr_cnt)
1259 lpfc_els_disc_plogi(vport);
1260
1261 if (!vport->num_disc_nodes) {
1262 spin_lock_irq(shost->host_lock);
1263 vport->fc_flag &=
1264 ~FC_NDISC_ACTIVE;
1265 spin_unlock_irq(
1266 shost->host_lock);
1267 lpfc_can_disctmo(vport);
1268 }
1269 }
1270 vport->port_state = LPFC_VPORT_READY;
dea31012005-04-17 16:05:31 -05001271 } else {
James Smart2e0fef82007-06-17 19:56:36 -05001272 lpfc_rscn_disc(vport);
dea31012005-04-17 16:05:31 -05001273 }
1274 }
1275 }
dea31012005-04-17 16:05:31 -05001276out:
1277 lpfc_els_free_iocb(phba, cmdiocb);
1278 return;
1279}
1280
1281int
James Smart2e0fef82007-06-17 19:56:36 -05001282lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001283 uint8_t retry)
1284{
James Smart2e0fef82007-06-17 19:56:36 -05001285 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1286 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001287 ADISC *ap;
1288 IOCB_t *icmd;
1289 struct lpfc_iocbq *elsiocb;
James Smart2e0fef82007-06-17 19:56:36 -05001290 struct lpfc_sli *psli = &phba->sli;
1291 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05001292 uint8_t *pcmd;
1293 uint16_t cmdsize;
1294
James Smart92d7f7b2007-06-17 19:56:38 -05001295 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
James Smart2e0fef82007-06-17 19:56:36 -05001296 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1297 ndlp->nlp_DID, ELS_CMD_ADISC);
James Smart488d1462006-03-07 15:02:37 -05001298 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001299 return 1;
dea31012005-04-17 16:05:31 -05001300
1301 icmd = &elsiocb->iocb;
1302 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1303
1304 /* For ADISC request, remainder of payload is service parameters */
1305 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
James Smart92d7f7b2007-06-17 19:56:38 -05001306 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001307
1308 /* Fill in ADISC payload */
1309 ap = (ADISC *) pcmd;
1310 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05001311 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
1312 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05001313 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05001314
James Smart858c9f62007-06-17 19:56:39 -05001315 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1316 "Issue ADISC: did:x%x",
1317 ndlp->nlp_DID, 0, 0);
1318
dea31012005-04-17 16:05:31 -05001319 phba->fc_stat.elsXmitADISC++;
1320 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
James Smart2e0fef82007-06-17 19:56:36 -05001321 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001322 ndlp->nlp_flag |= NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001323 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001324 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05001325 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001326 ndlp->nlp_flag &= ~NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001327 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001328 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001329 return 1;
dea31012005-04-17 16:05:31 -05001330 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001331 return 0;
dea31012005-04-17 16:05:31 -05001332}
1333
1334static void
James Smart2e0fef82007-06-17 19:56:36 -05001335lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1336 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001337{
James Smart2e0fef82007-06-17 19:56:36 -05001338 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1339 struct lpfc_vport *vport = ndlp->vport;
1340 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001341 IOCB_t *irsp;
1342 struct lpfc_sli *psli;
dea31012005-04-17 16:05:31 -05001343
1344 psli = &phba->sli;
1345 /* we pass cmdiocb to state machine which needs rspiocb as well */
1346 cmdiocb->context_un.rsp_iocb = rspiocb;
1347
1348 irsp = &(rspiocb->iocb);
James Smart2e0fef82007-06-17 19:56:36 -05001349 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001350 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001351 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001352
James Smart858c9f62007-06-17 19:56:39 -05001353 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1354 "LOGO cmpl: status:x%x/x%x did:x%x",
1355 irsp->ulpStatus, irsp->un.ulpWord[4],
1356 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05001357 /* LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001358 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1359 "0105 LOGO completes to NPort x%x "
1360 "Data: x%x x%x x%x x%x\n",
1361 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1362 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001363 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001364 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05001365 goto out;
1366
James Smart92d7f7b2007-06-17 19:56:38 -05001367 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
1368 /* NLP_EVT_DEVICE_RM should unregister the RPI
1369 * which should abort all outstanding IOs.
1370 */
1371 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1372 NLP_EVT_DEVICE_RM);
1373 goto out;
1374 }
1375
dea31012005-04-17 16:05:31 -05001376 if (irsp->ulpStatus) {
1377 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -05001378 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -05001379 /* ELS command is being retried */
1380 goto out;
dea31012005-04-17 16:05:31 -05001381 /* LOGO failed */
1382 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart858c9f62007-06-17 19:56:39 -05001383 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05001384 goto out;
James Smart858c9f62007-06-17 19:56:39 -05001385 else
James Smart2e0fef82007-06-17 19:56:36 -05001386 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001387 NLP_EVT_CMPL_LOGO);
dea31012005-04-17 16:05:31 -05001388 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001389 /* Good status, call state machine.
1390 * This will unregister the rpi if needed.
1391 */
James Smart2e0fef82007-06-17 19:56:36 -05001392 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001393 NLP_EVT_CMPL_LOGO);
dea31012005-04-17 16:05:31 -05001394 }
1395
1396out:
1397 lpfc_els_free_iocb(phba, cmdiocb);
1398 return;
1399}
1400
1401int
James Smart2e0fef82007-06-17 19:56:36 -05001402lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001403 uint8_t retry)
1404{
James Smart2e0fef82007-06-17 19:56:36 -05001405 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1406 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001407 IOCB_t *icmd;
1408 struct lpfc_iocbq *elsiocb;
1409 struct lpfc_sli_ring *pring;
1410 struct lpfc_sli *psli;
1411 uint8_t *pcmd;
1412 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05001413 int rc;
dea31012005-04-17 16:05:31 -05001414
1415 psli = &phba->sli;
1416 pring = &psli->ring[LPFC_ELS_RING];
1417
James Smart92d7f7b2007-06-17 19:56:38 -05001418 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
James Smart2e0fef82007-06-17 19:56:36 -05001419 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1420 ndlp->nlp_DID, ELS_CMD_LOGO);
James Smart488d1462006-03-07 15:02:37 -05001421 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001422 return 1;
dea31012005-04-17 16:05:31 -05001423
1424 icmd = &elsiocb->iocb;
1425 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1426 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
James Smart92d7f7b2007-06-17 19:56:38 -05001427 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001428
1429 /* Fill in LOGO payload */
James Smart2e0fef82007-06-17 19:56:36 -05001430 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05001431 pcmd += sizeof(uint32_t);
1432 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05001433
James Smart858c9f62007-06-17 19:56:39 -05001434 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1435 "Issue LOGO: did:x%x",
1436 ndlp->nlp_DID, 0, 0);
1437
dea31012005-04-17 16:05:31 -05001438 phba->fc_stat.elsXmitLOGO++;
1439 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
James Smart2e0fef82007-06-17 19:56:36 -05001440 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001441 ndlp->nlp_flag |= NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001442 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05001443 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
1444
1445 if (rc == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05001446 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001447 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001448 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001449 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001450 return 1;
dea31012005-04-17 16:05:31 -05001451 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001452 return 0;
dea31012005-04-17 16:05:31 -05001453}
1454
1455static void
James Smart2e0fef82007-06-17 19:56:36 -05001456lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1457 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001458{
James Smart2e0fef82007-06-17 19:56:36 -05001459 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -05001460 IOCB_t *irsp;
1461
1462 irsp = &rspiocb->iocb;
1463
James Smart858c9f62007-06-17 19:56:39 -05001464 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1465 "ELS cmd cmpl: status:x%x/x%x did:x%x",
1466 irsp->ulpStatus, irsp->un.ulpWord[4],
1467 irsp->un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05001468 /* ELS cmd tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04001469 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1470 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
1471 irsp->ulpIoTag, irsp->ulpStatus,
1472 irsp->un.ulpWord[4], irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -05001473 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001474 lpfc_els_chk_latt(vport);
dea31012005-04-17 16:05:31 -05001475 lpfc_els_free_iocb(phba, cmdiocb);
1476 return;
1477}
1478
1479int
James Smart2e0fef82007-06-17 19:56:36 -05001480lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05001481{
James Smart2e0fef82007-06-17 19:56:36 -05001482 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001483 IOCB_t *icmd;
1484 struct lpfc_iocbq *elsiocb;
1485 struct lpfc_sli_ring *pring;
1486 struct lpfc_sli *psli;
1487 uint8_t *pcmd;
1488 uint16_t cmdsize;
1489 struct lpfc_nodelist *ndlp;
1490
1491 psli = &phba->sli;
1492 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
James Smart92d7f7b2007-06-17 19:56:38 -05001493 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001494 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1495 if (!ndlp)
1496 return 1;
dea31012005-04-17 16:05:31 -05001497
James Smart2e0fef82007-06-17 19:56:36 -05001498 lpfc_nlp_init(vport, ndlp, nportid);
dea31012005-04-17 16:05:31 -05001499
James Smart2e0fef82007-06-17 19:56:36 -05001500 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1501 ndlp->nlp_DID, ELS_CMD_SCR);
1502
James Smart488d1462006-03-07 15:02:37 -05001503 if (!elsiocb) {
James Smart329f9bc2007-04-25 09:53:01 -04001504 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001505 return 1;
dea31012005-04-17 16:05:31 -05001506 }
1507
1508 icmd = &elsiocb->iocb;
1509 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1510
1511 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
James Smart92d7f7b2007-06-17 19:56:38 -05001512 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001513
1514 /* For SCR, remainder of payload is SCR parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05001515 memset(pcmd, 0, sizeof(SCR));
dea31012005-04-17 16:05:31 -05001516 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
1517
James Smart858c9f62007-06-17 19:56:39 -05001518 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1519 "Issue SCR: did:x%x",
1520 ndlp->nlp_DID, 0, 0);
1521
dea31012005-04-17 16:05:31 -05001522 phba->fc_stat.elsXmitSCR++;
1523 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
dea31012005-04-17 16:05:31 -05001524 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
James Smart329f9bc2007-04-25 09:53:01 -04001525 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001526 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001527 return 1;
dea31012005-04-17 16:05:31 -05001528 }
James Smart329f9bc2007-04-25 09:53:01 -04001529 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001530 return 0;
dea31012005-04-17 16:05:31 -05001531}
1532
1533static int
James Smart2e0fef82007-06-17 19:56:36 -05001534lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05001535{
James Smart2e0fef82007-06-17 19:56:36 -05001536 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001537 IOCB_t *icmd;
1538 struct lpfc_iocbq *elsiocb;
1539 struct lpfc_sli_ring *pring;
1540 struct lpfc_sli *psli;
1541 FARP *fp;
1542 uint8_t *pcmd;
1543 uint32_t *lp;
1544 uint16_t cmdsize;
1545 struct lpfc_nodelist *ondlp;
1546 struct lpfc_nodelist *ndlp;
1547
1548 psli = &phba->sli;
1549 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
James Smart92d7f7b2007-06-17 19:56:38 -05001550 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001551 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1552 if (!ndlp)
1553 return 1;
dea31012005-04-17 16:05:31 -05001554
James Smart2e0fef82007-06-17 19:56:36 -05001555 lpfc_nlp_init(vport, ndlp, nportid);
1556
1557 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1558 ndlp->nlp_DID, ELS_CMD_RNID);
James Smart488d1462006-03-07 15:02:37 -05001559 if (!elsiocb) {
James Smart329f9bc2007-04-25 09:53:01 -04001560 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001561 return 1;
dea31012005-04-17 16:05:31 -05001562 }
1563
1564 icmd = &elsiocb->iocb;
1565 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1566
1567 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
James Smart92d7f7b2007-06-17 19:56:38 -05001568 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001569
1570 /* Fill in FARPR payload */
1571 fp = (FARP *) (pcmd);
James Smart92d7f7b2007-06-17 19:56:38 -05001572 memset(fp, 0, sizeof(FARP));
dea31012005-04-17 16:05:31 -05001573 lp = (uint32_t *) pcmd;
1574 *lp++ = be32_to_cpu(nportid);
James Smart2e0fef82007-06-17 19:56:36 -05001575 *lp++ = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05001576 fp->Rflags = 0;
1577 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
1578
James Smart92d7f7b2007-06-17 19:56:38 -05001579 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
1580 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05001581 ondlp = lpfc_findnode_did(vport, nportid);
1582 if (ondlp) {
dea31012005-04-17 16:05:31 -05001583 memcpy(&fp->OportName, &ondlp->nlp_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05001584 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05001585 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05001586 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05001587 }
1588
James Smart858c9f62007-06-17 19:56:39 -05001589 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1590 "Issue FARPR: did:x%x",
1591 ndlp->nlp_DID, 0, 0);
1592
dea31012005-04-17 16:05:31 -05001593 phba->fc_stat.elsXmitFARPR++;
1594 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
dea31012005-04-17 16:05:31 -05001595 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
James Smart329f9bc2007-04-25 09:53:01 -04001596 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001597 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001598 return 1;
dea31012005-04-17 16:05:31 -05001599 }
James Smart329f9bc2007-04-25 09:53:01 -04001600 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001601 return 0;
dea31012005-04-17 16:05:31 -05001602}
1603
James Smarted957682007-06-17 19:56:37 -05001604static void
1605lpfc_end_rscn(struct lpfc_vport *vport)
1606{
1607 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1608
1609 if (vport->fc_flag & FC_RSCN_MODE) {
1610 /*
1611 * Check to see if more RSCNs came in while we were
1612 * processing this one.
1613 */
1614 if (vport->fc_rscn_id_cnt ||
1615 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1616 lpfc_els_handle_rscn(vport);
1617 else {
1618 spin_lock_irq(shost->host_lock);
1619 vport->fc_flag &= ~FC_RSCN_MODE;
1620 spin_unlock_irq(shost->host_lock);
1621 }
1622 }
1623}
1624
dea31012005-04-17 16:05:31 -05001625void
James Smart2e0fef82007-06-17 19:56:36 -05001626lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
James Smartfdcebe22006-03-07 15:04:01 -05001627{
James Smart2e0fef82007-06-17 19:56:36 -05001628 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1629
1630 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05001631 nlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001632 spin_unlock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05001633 del_timer_sync(&nlp->nlp_delayfunc);
1634 nlp->nlp_last_elscmd = 0;
1635
1636 if (!list_empty(&nlp->els_retry_evt.evt_listp))
1637 list_del_init(&nlp->els_retry_evt.evt_listp);
1638
1639 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
James Smart2e0fef82007-06-17 19:56:36 -05001640 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05001641 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001642 spin_unlock_irq(shost->host_lock);
1643 if (vport->num_disc_nodes) {
James Smartfdcebe22006-03-07 15:04:01 -05001644 /* Check to see if there are more
1645 * PLOGIs to be sent
1646 */
James Smart2e0fef82007-06-17 19:56:36 -05001647 lpfc_more_plogi(vport);
James Smartfdcebe22006-03-07 15:04:01 -05001648
James Smart2e0fef82007-06-17 19:56:36 -05001649 if (vport->num_disc_nodes == 0) {
1650 spin_lock_irq(shost->host_lock);
1651 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1652 spin_unlock_irq(shost->host_lock);
1653 lpfc_can_disctmo(vport);
James Smarted957682007-06-17 19:56:37 -05001654 lpfc_end_rscn(vport);
James Smartfdcebe22006-03-07 15:04:01 -05001655 }
1656 }
1657 }
1658 return;
1659}
1660
1661void
dea31012005-04-17 16:05:31 -05001662lpfc_els_retry_delay(unsigned long ptr)
1663{
James Smart2e0fef82007-06-17 19:56:36 -05001664 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
1665 struct lpfc_vport *vport = ndlp->vport;
James Smart2e0fef82007-06-17 19:56:36 -05001666 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05001667 unsigned long flags;
James Smart2e0fef82007-06-17 19:56:36 -05001668 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
dea31012005-04-17 16:05:31 -05001669
James Smart2e0fef82007-06-17 19:56:36 -05001670 ndlp = (struct lpfc_nodelist *) ptr;
1671 phba = ndlp->vport->phba;
dea31012005-04-17 16:05:31 -05001672 evtp = &ndlp->els_retry_evt;
1673
James Smart92d7f7b2007-06-17 19:56:38 -05001674 spin_lock_irqsave(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05001675 if (!list_empty(&evtp->evt_listp)) {
James Smart92d7f7b2007-06-17 19:56:38 -05001676 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05001677 return;
1678 }
1679
1680 evtp->evt_arg1 = ndlp;
1681 evtp->evt = LPFC_EVT_ELS_RETRY;
1682 list_add_tail(&evtp->evt_listp, &phba->work_list);
1683 if (phba->work_wait)
James Smart92d7f7b2007-06-17 19:56:38 -05001684 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05001685
James Smart92d7f7b2007-06-17 19:56:38 -05001686 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05001687 return;
1688}
1689
1690void
1691lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
1692{
James Smart2e0fef82007-06-17 19:56:36 -05001693 struct lpfc_vport *vport = ndlp->vport;
1694 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1695 uint32_t cmd, did, retry;
dea31012005-04-17 16:05:31 -05001696
James Smart2e0fef82007-06-17 19:56:36 -05001697 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001698 did = ndlp->nlp_DID;
1699 cmd = ndlp->nlp_last_elscmd;
1700 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05001701
1702 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
James Smart2e0fef82007-06-17 19:56:36 -05001703 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001704 return;
1705 }
1706
1707 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001708 spin_unlock_irq(shost->host_lock);
James Smart1a169682006-03-07 15:04:06 -05001709 /*
1710 * If a discovery event readded nlp_delayfunc after timer
1711 * firing and before processing the timer, cancel the
1712 * nlp_delayfunc.
1713 */
1714 del_timer_sync(&ndlp->nlp_delayfunc);
dea31012005-04-17 16:05:31 -05001715 retry = ndlp->nlp_retry;
1716
1717 switch (cmd) {
1718 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05001719 lpfc_issue_els_flogi(vport, ndlp, retry);
dea31012005-04-17 16:05:31 -05001720 break;
1721 case ELS_CMD_PLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05001722 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001723 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001724 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05001725 }
dea31012005-04-17 16:05:31 -05001726 break;
1727 case ELS_CMD_ADISC:
James Smart2e0fef82007-06-17 19:56:36 -05001728 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001729 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001730 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05001731 }
dea31012005-04-17 16:05:31 -05001732 break;
1733 case ELS_CMD_PRLI:
James Smart2e0fef82007-06-17 19:56:36 -05001734 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001735 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001736 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05001737 }
dea31012005-04-17 16:05:31 -05001738 break;
1739 case ELS_CMD_LOGO:
James Smart2e0fef82007-06-17 19:56:36 -05001740 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001741 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001742 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05001743 }
dea31012005-04-17 16:05:31 -05001744 break;
James Smart92d7f7b2007-06-17 19:56:38 -05001745 case ELS_CMD_FDISC:
1746 lpfc_issue_els_fdisc(vport, ndlp, retry);
1747 break;
dea31012005-04-17 16:05:31 -05001748 }
1749 return;
1750}
1751
1752static int
James Smart2e0fef82007-06-17 19:56:36 -05001753lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1754 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001755{
James Smart2e0fef82007-06-17 19:56:36 -05001756 struct lpfc_vport *vport = cmdiocb->vport;
1757 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1758 IOCB_t *irsp = &rspiocb->iocb;
1759 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1760 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
dea31012005-04-17 16:05:31 -05001761 uint32_t *elscmd;
1762 struct ls_rjt stat;
James Smart2e0fef82007-06-17 19:56:36 -05001763 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
1764 uint32_t cmd = 0;
James Smart488d1462006-03-07 15:02:37 -05001765 uint32_t did;
dea31012005-04-17 16:05:31 -05001766
James Smart488d1462006-03-07 15:02:37 -05001767
dea31012005-04-17 16:05:31 -05001768 /* Note: context2 may be 0 for internal driver abort
1769 * of delays ELS command.
1770 */
1771
1772 if (pcmd && pcmd->virt) {
1773 elscmd = (uint32_t *) (pcmd->virt);
1774 cmd = *elscmd++;
1775 }
1776
James Smart329f9bc2007-04-25 09:53:01 -04001777 if (ndlp)
James Smart488d1462006-03-07 15:02:37 -05001778 did = ndlp->nlp_DID;
1779 else {
1780 /* We should only hit this case for retrying PLOGI */
1781 did = irsp->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05001782 ndlp = lpfc_findnode_did(vport, did);
James Smart488d1462006-03-07 15:02:37 -05001783 if (!ndlp && (cmd != ELS_CMD_PLOGI))
1784 return 1;
1785 }
1786
James Smart858c9f62007-06-17 19:56:39 -05001787 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1788 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
1789 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
1790
dea31012005-04-17 16:05:31 -05001791 switch (irsp->ulpStatus) {
1792 case IOSTAT_FCP_RSP_ERROR:
1793 case IOSTAT_REMOTE_STOP:
1794 break;
1795
1796 case IOSTAT_LOCAL_REJECT:
1797 switch ((irsp->un.ulpWord[4] & 0xff)) {
1798 case IOERR_LOOP_OPEN_FAILURE:
James Smart2e0fef82007-06-17 19:56:36 -05001799 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05001800 delay = 1000;
dea31012005-04-17 16:05:31 -05001801 retry = 1;
1802 break;
1803
James Smart92d7f7b2007-06-17 19:56:38 -05001804 case IOERR_ILLEGAL_COMMAND:
1805 if ((phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) &&
1806 (cmd == ELS_CMD_FDISC)) {
James Smarte8b62012007-08-02 11:10:09 -04001807 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1808 "0124 FDISC failed (3/6) "
1809 "retrying...\n");
James Smart92d7f7b2007-06-17 19:56:38 -05001810 lpfc_mbx_unreg_vpi(vport);
1811 retry = 1;
1812 /* Always retry for this case */
1813 cmdiocb->retry = 0;
1814 }
1815 break;
1816
dea31012005-04-17 16:05:31 -05001817 case IOERR_NO_RESOURCES:
James Smart858c9f62007-06-17 19:56:39 -05001818 retry = 1;
1819 if (cmdiocb->retry > 100)
1820 delay = 100;
1821 maxretry = 250;
1822 break;
1823
1824 case IOERR_ILLEGAL_FRAME:
James Smart92d7f7b2007-06-17 19:56:38 -05001825 delay = 100;
dea31012005-04-17 16:05:31 -05001826 retry = 1;
1827 break;
1828
James Smart858c9f62007-06-17 19:56:39 -05001829 case IOERR_SEQUENCE_TIMEOUT:
dea31012005-04-17 16:05:31 -05001830 case IOERR_INVALID_RPI:
1831 retry = 1;
1832 break;
1833 }
1834 break;
1835
1836 case IOSTAT_NPORT_RJT:
1837 case IOSTAT_FABRIC_RJT:
1838 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
1839 retry = 1;
1840 break;
1841 }
1842 break;
1843
1844 case IOSTAT_NPORT_BSY:
1845 case IOSTAT_FABRIC_BSY:
1846 retry = 1;
1847 break;
1848
1849 case IOSTAT_LS_RJT:
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
1853 */
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) {
James Smart92d7f7b2007-06-17 19:56:38 -05001859 delay = 1000;
dea31012005-04-17 16:05:31 -05001860 maxretry = 48;
1861 }
1862 retry = 1;
1863 break;
1864 }
1865 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05001866 delay = 1000;
dea31012005-04-17 16:05:31 -05001867 maxretry = lpfc_max_els_tries + 1;
1868 retry = 1;
1869 break;
1870 }
James Smart92d7f7b2007-06-17 19:56:38 -05001871 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
1872 (cmd == ELS_CMD_FDISC) &&
1873 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
James Smarte8b62012007-08-02 11:10:09 -04001874 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1875 "0125 FDISC Failed (x%x). "
1876 "Fabric out of resources\n",
1877 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05001878 lpfc_vport_set_state(vport,
1879 FC_VPORT_NO_FABRIC_RSCS);
1880 }
dea31012005-04-17 16:05:31 -05001881 break;
1882
1883 case LSRJT_LOGICAL_BSY:
James Smart858c9f62007-06-17 19:56:39 -05001884 if ((cmd == ELS_CMD_PLOGI) ||
1885 (cmd == ELS_CMD_PRLI)) {
James Smart92d7f7b2007-06-17 19:56:38 -05001886 delay = 1000;
dea31012005-04-17 16:05:31 -05001887 maxretry = 48;
James Smart92d7f7b2007-06-17 19:56:38 -05001888 } else if (cmd == ELS_CMD_FDISC) {
1889 /* Always retry for this case */
1890 cmdiocb->retry = 0;
dea31012005-04-17 16:05:31 -05001891 }
1892 retry = 1;
1893 break;
James Smart92d7f7b2007-06-17 19:56:38 -05001894
1895 case LSRJT_LOGICAL_ERR:
1896 case LSRJT_PROTOCOL_ERR:
1897 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
1898 (cmd == ELS_CMD_FDISC) &&
1899 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
1900 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
1901 ) {
James Smarte8b62012007-08-02 11:10:09 -04001902 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1903 "0123 FDISC Failed (x%x). "
1904 "Fabric Detected Bad WWN\n",
1905 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05001906 lpfc_vport_set_state(vport,
1907 FC_VPORT_FABRIC_REJ_WWN);
1908 }
1909 break;
dea31012005-04-17 16:05:31 -05001910 }
1911 break;
1912
1913 case IOSTAT_INTERMED_RSP:
1914 case IOSTAT_BA_RJT:
1915 break;
1916
1917 default:
1918 break;
1919 }
1920
James Smart488d1462006-03-07 15:02:37 -05001921 if (did == FDMI_DID)
dea31012005-04-17 16:05:31 -05001922 retry = 1;
dea31012005-04-17 16:05:31 -05001923
1924 if ((++cmdiocb->retry) >= maxretry) {
1925 phba->fc_stat.elsRetryExceeded++;
1926 retry = 0;
1927 }
1928
James Smarted957682007-06-17 19:56:37 -05001929 if ((vport->load_flag & FC_UNLOADING) != 0)
1930 retry = 0;
1931
dea31012005-04-17 16:05:31 -05001932 if (retry) {
1933
1934 /* Retry ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04001935 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1936 "0107 Retry ELS command x%x to remote "
1937 "NPORT x%x Data: x%x x%x\n",
1938 cmd, did, cmdiocb->retry, delay);
dea31012005-04-17 16:05:31 -05001939
James Smart858c9f62007-06-17 19:56:39 -05001940 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
1941 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
1942 ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) {
1943 /* Don't reset timer for no resources */
1944
dea31012005-04-17 16:05:31 -05001945 /* If discovery / RSCN timer is running, reset it */
James Smart2e0fef82007-06-17 19:56:36 -05001946 if (timer_pending(&vport->fc_disctmo) ||
James Smart92d7f7b2007-06-17 19:56:38 -05001947 (vport->fc_flag & FC_RSCN_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05001948 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001949 }
1950
1951 phba->fc_stat.elsXmitRetry++;
James Smart488d1462006-03-07 15:02:37 -05001952 if (ndlp && delay) {
dea31012005-04-17 16:05:31 -05001953 phba->fc_stat.elsDelayRetry++;
1954 ndlp->nlp_retry = cmdiocb->retry;
1955
James Smart92d7f7b2007-06-17 19:56:38 -05001956 /* delay is specified in milliseconds */
1957 mod_timer(&ndlp->nlp_delayfunc,
1958 jiffies + msecs_to_jiffies(delay));
James Smart2e0fef82007-06-17 19:56:36 -05001959 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001960 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001961 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001962
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001963 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart858c9f62007-06-17 19:56:39 -05001964 if (cmd == ELS_CMD_PRLI)
1965 lpfc_nlp_set_state(vport, ndlp,
1966 NLP_STE_REG_LOGIN_ISSUE);
1967 else
1968 lpfc_nlp_set_state(vport, ndlp,
1969 NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05001970 ndlp->nlp_last_elscmd = cmd;
1971
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001972 return 1;
dea31012005-04-17 16:05:31 -05001973 }
1974 switch (cmd) {
1975 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05001976 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001977 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -05001978 case ELS_CMD_FDISC:
1979 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
1980 return 1;
dea31012005-04-17 16:05:31 -05001981 case ELS_CMD_PLOGI:
James Smart488d1462006-03-07 15:02:37 -05001982 if (ndlp) {
1983 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001984 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04001985 NLP_STE_PLOGI_ISSUE);
James Smart488d1462006-03-07 15:02:37 -05001986 }
James Smart2e0fef82007-06-17 19:56:36 -05001987 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001988 return 1;
dea31012005-04-17 16:05:31 -05001989 case ELS_CMD_ADISC:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001990 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001991 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
1992 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001993 return 1;
dea31012005-04-17 16:05:31 -05001994 case ELS_CMD_PRLI:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001995 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001996 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
1997 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001998 return 1;
dea31012005-04-17 16:05:31 -05001999 case ELS_CMD_LOGO:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002000 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002001 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2002 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002003 return 1;
dea31012005-04-17 16:05:31 -05002004 }
2005 }
dea31012005-04-17 16:05:31 -05002006 /* No retry ELS command <elsCmd> to remote NPORT <did> */
James Smarta58cbd52007-08-02 11:09:43 -04002007 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2008 "0108 No retry ELS command x%x to remote "
2009 "NPORT x%x Retried:%d Error:x%x/%x\n",
2010 cmd, did, cmdiocb->retry, irsp->ulpStatus,
2011 irsp->un.ulpWord[4]);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002012 return 0;
dea31012005-04-17 16:05:31 -05002013}
2014
2015int
James Smart329f9bc2007-04-25 09:53:01 -04002016lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05002017{
2018 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
2019
James Smart329f9bc2007-04-25 09:53:01 -04002020 if (elsiocb->context1) {
2021 lpfc_nlp_put(elsiocb->context1);
2022 elsiocb->context1 = NULL;
2023 }
dea31012005-04-17 16:05:31 -05002024 /* context2 = cmd, context2->next = rsp, context3 = bpl */
2025 if (elsiocb->context2) {
2026 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
2027 /* Free the response before processing the command. */
2028 if (!list_empty(&buf_ptr1->list)) {
2029 list_remove_head(&buf_ptr1->list, buf_ptr,
2030 struct lpfc_dmabuf,
2031 list);
2032 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
2033 kfree(buf_ptr);
2034 }
2035 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
2036 kfree(buf_ptr1);
2037 }
2038
2039 if (elsiocb->context3) {
2040 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
2041 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
2042 kfree(buf_ptr);
2043 }
James Bottomley604a3e32005-10-29 10:28:33 -05002044 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -05002045 return 0;
2046}
2047
2048static void
James Smart2e0fef82007-06-17 19:56:36 -05002049lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2050 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002051{
James Smart2e0fef82007-06-17 19:56:36 -05002052 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2053 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05002054 IOCB_t *irsp;
2055
2056 irsp = &rspiocb->iocb;
2057 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2058 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
2059 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05002060 /* ACC to LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002061 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2062 "0109 ACC to LOGO completes to NPort x%x "
2063 "Data: x%x x%x x%x\n",
2064 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2065 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05002066 switch (ndlp->nlp_state) {
2067 case NLP_STE_UNUSED_NODE: /* node is just allocated */
James Smart2e0fef82007-06-17 19:56:36 -05002068 lpfc_drop_node(vport, ndlp);
dea31012005-04-17 16:05:31 -05002069 break;
2070 case NLP_STE_NPR_NODE: /* NPort Recovery mode */
James Smart2e0fef82007-06-17 19:56:36 -05002071 lpfc_unreg_rpi(vport, ndlp);
dea31012005-04-17 16:05:31 -05002072 break;
2073 default:
2074 break;
2075 }
2076 lpfc_els_free_iocb(phba, cmdiocb);
2077 return;
2078}
2079
James Smart858c9f62007-06-17 19:56:39 -05002080void
2081lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
2082{
2083 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
2084 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
2085
2086 pmb->context1 = NULL;
2087 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2088 kfree(mp);
2089 mempool_free(pmb, phba->mbox_mem_pool);
2090 lpfc_nlp_put(ndlp);
2091 return;
2092}
2093
dea31012005-04-17 16:05:31 -05002094static void
James Smart858c9f62007-06-17 19:56:39 -05002095lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
James Smart329f9bc2007-04-25 09:53:01 -04002096 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002097{
James Smart2e0fef82007-06-17 19:56:36 -05002098 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2099 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
2100 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
James Smart33ccf8d2006-08-17 11:57:58 -04002101 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05002102 LPFC_MBOXQ_t *mbox = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05002103 struct lpfc_dmabuf *mp = NULL;
dea31012005-04-17 16:05:31 -05002104
James Smart33ccf8d2006-08-17 11:57:58 -04002105 irsp = &rspiocb->iocb;
2106
dea31012005-04-17 16:05:31 -05002107 if (cmdiocb->context_un.mbox)
2108 mbox = cmdiocb->context_un.mbox;
2109
dea31012005-04-17 16:05:31 -05002110 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002111 if (!ndlp || lpfc_els_chk_latt(vport)) {
dea31012005-04-17 16:05:31 -05002112 if (mbox) {
James Smart14691152006-12-02 13:34:28 -05002113 mp = (struct lpfc_dmabuf *) mbox->context1;
2114 if (mp) {
2115 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2116 kfree(mp);
2117 }
James Smart329f9bc2007-04-25 09:53:01 -04002118 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05002119 }
2120 goto out;
2121 }
2122
James Smart858c9f62007-06-17 19:56:39 -05002123 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2124 "ACC cmpl: status:x%x/x%x did:x%x",
2125 irsp->ulpStatus, irsp->un.ulpWord[4],
2126 irsp->un.rcvels.remoteID);
dea31012005-04-17 16:05:31 -05002127 /* ELS response tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04002128 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2129 "0110 ELS response tag x%x completes "
2130 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
2131 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
2132 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
2133 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2134 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05002135 if (mbox) {
2136 if ((rspiocb->iocb.ulpStatus == 0)
2137 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
James Smart2e0fef82007-06-17 19:56:36 -05002138 lpfc_unreg_rpi(vport, ndlp);
James Smart329f9bc2007-04-25 09:53:01 -04002139 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05002140 mbox->vport = vport;
James Smart858c9f62007-06-17 19:56:39 -05002141 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
2142 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
2143 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
2144 }
2145 else {
2146 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
2147 ndlp->nlp_prev_state = ndlp->nlp_state;
2148 lpfc_nlp_set_state(vport, ndlp,
James Smart2e0fef82007-06-17 19:56:36 -05002149 NLP_STE_REG_LOGIN_ISSUE);
James Smart858c9f62007-06-17 19:56:39 -05002150 }
dea31012005-04-17 16:05:31 -05002151 if (lpfc_sli_issue_mbox(phba, mbox,
2152 (MBX_NOWAIT | MBX_STOP_IOCB))
2153 != MBX_NOT_FINISHED) {
2154 goto out;
2155 }
James Smart329f9bc2007-04-25 09:53:01 -04002156 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002157 /* NOTE: we should have messages for unsuccessful
2158 reglogin */
dea31012005-04-17 16:05:31 -05002159 } else {
James Smart858c9f62007-06-17 19:56:39 -05002160 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
2161 if (!lpfc_error_lost_link(irsp) &&
2162 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
2163 lpfc_drop_node(vport, ndlp);
2164 ndlp = NULL;
dea31012005-04-17 16:05:31 -05002165 }
2166 }
James Smart14691152006-12-02 13:34:28 -05002167 mp = (struct lpfc_dmabuf *) mbox->context1;
2168 if (mp) {
2169 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2170 kfree(mp);
2171 }
2172 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05002173 }
2174out:
2175 if (ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05002176 spin_lock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05002177 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
James Smart2e0fef82007-06-17 19:56:36 -05002178 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002179 }
2180 lpfc_els_free_iocb(phba, cmdiocb);
2181 return;
2182}
2183
2184int
James Smart2e0fef82007-06-17 19:56:36 -05002185lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
2186 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
2187 LPFC_MBOXQ_t *mbox, uint8_t newnode)
dea31012005-04-17 16:05:31 -05002188{
James Smart2e0fef82007-06-17 19:56:36 -05002189 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2190 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002191 IOCB_t *icmd;
2192 IOCB_t *oldcmd;
2193 struct lpfc_iocbq *elsiocb;
2194 struct lpfc_sli_ring *pring;
2195 struct lpfc_sli *psli;
2196 uint8_t *pcmd;
2197 uint16_t cmdsize;
2198 int rc;
James Smart82d9a2a2006-04-15 11:53:05 -04002199 ELS_PKT *els_pkt_ptr;
dea31012005-04-17 16:05:31 -05002200
2201 psli = &phba->sli;
2202 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2203 oldcmd = &oldiocb->iocb;
2204
2205 switch (flag) {
2206 case ELS_CMD_ACC:
James Smart92d7f7b2007-06-17 19:56:38 -05002207 cmdsize = sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05002208 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
2209 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05002210 if (!elsiocb) {
James Smart2e0fef82007-06-17 19:56:36 -05002211 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002212 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05002213 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002214 return 1;
dea31012005-04-17 16:05:31 -05002215 }
James Smart2e0fef82007-06-17 19:56:36 -05002216
dea31012005-04-17 16:05:31 -05002217 icmd = &elsiocb->iocb;
2218 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2219 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2220 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05002221 pcmd += sizeof(uint32_t);
James Smart858c9f62007-06-17 19:56:39 -05002222
2223 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2224 "Issue ACC: did:x%x flg:x%x",
2225 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05002226 break;
2227 case ELS_CMD_PLOGI:
James Smart92d7f7b2007-06-17 19:56:38 -05002228 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
James Smart2e0fef82007-06-17 19:56:36 -05002229 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
2230 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05002231 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002232 return 1;
James Smart488d1462006-03-07 15:02:37 -05002233
dea31012005-04-17 16:05:31 -05002234 icmd = &elsiocb->iocb;
2235 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2236 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2237
2238 if (mbox)
2239 elsiocb->context_un.mbox = mbox;
2240
2241 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05002242 pcmd += sizeof(uint32_t);
2243 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
James Smart858c9f62007-06-17 19:56:39 -05002244
2245 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2246 "Issue ACC PLOGI: did:x%x flg:x%x",
2247 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05002248 break;
James Smart82d9a2a2006-04-15 11:53:05 -04002249 case ELS_CMD_PRLO:
James Smart92d7f7b2007-06-17 19:56:38 -05002250 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
James Smart2e0fef82007-06-17 19:56:36 -05002251 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
James Smart82d9a2a2006-04-15 11:53:05 -04002252 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
2253 if (!elsiocb)
2254 return 1;
2255
2256 icmd = &elsiocb->iocb;
2257 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2258 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2259
2260 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
James Smart92d7f7b2007-06-17 19:56:38 -05002261 sizeof(uint32_t) + sizeof(PRLO));
James Smart82d9a2a2006-04-15 11:53:05 -04002262 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
2263 els_pkt_ptr = (ELS_PKT *) pcmd;
2264 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
James Smart858c9f62007-06-17 19:56:39 -05002265
2266 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2267 "Issue ACC PRLO: did:x%x flg:x%x",
2268 ndlp->nlp_DID, ndlp->nlp_flag, 0);
James Smart82d9a2a2006-04-15 11:53:05 -04002269 break;
dea31012005-04-17 16:05:31 -05002270 default:
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002271 return 1;
dea31012005-04-17 16:05:31 -05002272 }
2273
James Smart329f9bc2007-04-25 09:53:01 -04002274 if (newnode) {
2275 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002276 elsiocb->context1 = NULL;
James Smart329f9bc2007-04-25 09:53:01 -04002277 }
dea31012005-04-17 16:05:31 -05002278 /* Xmit ELS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04002279 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2280 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
2281 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n",
2282 elsiocb->iotag, elsiocb->iocb.ulpContext,
2283 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2284 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05002285 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
James Smart2e0fef82007-06-17 19:56:36 -05002286 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002287 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05002288 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002289 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
2290 } else {
James Smart858c9f62007-06-17 19:56:39 -05002291 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05002292 }
2293
2294 phba->fc_stat.elsXmitACC++;
dea31012005-04-17 16:05:31 -05002295 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
dea31012005-04-17 16:05:31 -05002296 if (rc == IOCB_ERROR) {
2297 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002298 return 1;
dea31012005-04-17 16:05:31 -05002299 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002300 return 0;
dea31012005-04-17 16:05:31 -05002301}
2302
2303int
James Smart2e0fef82007-06-17 19:56:36 -05002304lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
James Smart858c9f62007-06-17 19:56:39 -05002305 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
2306 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05002307{
James Smart2e0fef82007-06-17 19:56:36 -05002308 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002309 IOCB_t *icmd;
2310 IOCB_t *oldcmd;
2311 struct lpfc_iocbq *elsiocb;
2312 struct lpfc_sli_ring *pring;
2313 struct lpfc_sli *psli;
2314 uint8_t *pcmd;
2315 uint16_t cmdsize;
2316 int rc;
2317
2318 psli = &phba->sli;
2319 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2320
James Smart92d7f7b2007-06-17 19:56:38 -05002321 cmdsize = 2 * sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05002322 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
2323 ndlp->nlp_DID, ELS_CMD_LS_RJT);
James Smart488d1462006-03-07 15:02:37 -05002324 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002325 return 1;
dea31012005-04-17 16:05:31 -05002326
2327 icmd = &elsiocb->iocb;
2328 oldcmd = &oldiocb->iocb;
2329 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2330 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2331
2332 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
James Smart92d7f7b2007-06-17 19:56:38 -05002333 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002334 *((uint32_t *) (pcmd)) = rejectError;
2335
James Smart858c9f62007-06-17 19:56:39 -05002336 if (mbox) {
2337 elsiocb->context_un.mbox = mbox;
2338 elsiocb->context1 = lpfc_nlp_get(ndlp);
2339 }
2340
dea31012005-04-17 16:05:31 -05002341 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04002342 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2343 "0129 Xmit ELS RJT x%x response tag x%x "
2344 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
2345 "rpi x%x\n",
2346 rejectError, elsiocb->iotag,
2347 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
2348 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05002349 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2350 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
2351 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
2352
dea31012005-04-17 16:05:31 -05002353 phba->fc_stat.elsXmitLSRJT++;
James Smart858c9f62007-06-17 19:56:39 -05002354 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05002355 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
dea31012005-04-17 16:05:31 -05002356 if (rc == IOCB_ERROR) {
2357 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002358 return 1;
dea31012005-04-17 16:05:31 -05002359 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002360 return 0;
dea31012005-04-17 16:05:31 -05002361}
2362
2363int
James Smart2e0fef82007-06-17 19:56:36 -05002364lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
2365 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05002366{
James Smart2e0fef82007-06-17 19:56:36 -05002367 struct lpfc_hba *phba = vport->phba;
2368 struct lpfc_sli *psli = &phba->sli;
2369 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05002370 ADISC *ap;
James Smart2e0fef82007-06-17 19:56:36 -05002371 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05002372 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002373 uint8_t *pcmd;
2374 uint16_t cmdsize;
2375 int rc;
2376
James Smart92d7f7b2007-06-17 19:56:38 -05002377 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
James Smart2e0fef82007-06-17 19:56:36 -05002378 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
2379 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05002380 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002381 return 1;
dea31012005-04-17 16:05:31 -05002382
dea31012005-04-17 16:05:31 -05002383 icmd = &elsiocb->iocb;
2384 oldcmd = &oldiocb->iocb;
2385 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04002386
2387 /* Xmit ADISC ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04002388 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2389 "0130 Xmit ADISC ACC response iotag x%x xri: "
2390 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
2391 elsiocb->iotag, elsiocb->iocb.ulpContext,
2392 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2393 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05002394 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2395
2396 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05002397 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002398
2399 ap = (ADISC *) (pcmd);
2400 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05002401 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2402 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002403 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002404
James Smart858c9f62007-06-17 19:56:39 -05002405 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2406 "Issue ACC ADISC: did:x%x flg:x%x",
2407 ndlp->nlp_DID, ndlp->nlp_flag, 0);
2408
dea31012005-04-17 16:05:31 -05002409 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05002410 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05002411 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
dea31012005-04-17 16:05:31 -05002412 if (rc == IOCB_ERROR) {
2413 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002414 return 1;
dea31012005-04-17 16:05:31 -05002415 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002416 return 0;
dea31012005-04-17 16:05:31 -05002417}
2418
2419int
James Smart2e0fef82007-06-17 19:56:36 -05002420lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
James Smart5b8bd0c2007-04-25 09:52:49 -04002421 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05002422{
James Smart2e0fef82007-06-17 19:56:36 -05002423 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002424 PRLI *npr;
2425 lpfc_vpd_t *vpd;
2426 IOCB_t *icmd;
2427 IOCB_t *oldcmd;
2428 struct lpfc_iocbq *elsiocb;
2429 struct lpfc_sli_ring *pring;
2430 struct lpfc_sli *psli;
2431 uint8_t *pcmd;
2432 uint16_t cmdsize;
2433 int rc;
2434
2435 psli = &phba->sli;
2436 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2437
James Smart92d7f7b2007-06-17 19:56:38 -05002438 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
James Smart2e0fef82007-06-17 19:56:36 -05002439 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
James Smart92d7f7b2007-06-17 19:56:38 -05002440 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002441 if (!elsiocb)
2442 return 1;
dea31012005-04-17 16:05:31 -05002443
dea31012005-04-17 16:05:31 -05002444 icmd = &elsiocb->iocb;
2445 oldcmd = &oldiocb->iocb;
2446 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04002447 /* Xmit PRLI ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04002448 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2449 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
2450 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
2451 elsiocb->iotag, elsiocb->iocb.ulpContext,
2452 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2453 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05002454 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2455
2456 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
James Smart92d7f7b2007-06-17 19:56:38 -05002457 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002458
2459 /* For PRLI, remainder of payload is PRLI parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05002460 memset(pcmd, 0, sizeof(PRLI));
dea31012005-04-17 16:05:31 -05002461
2462 npr = (PRLI *) pcmd;
2463 vpd = &phba->vpd;
2464 /*
2465 * If our firmware version is 3.20 or later,
2466 * set the following bits for FC-TAPE support.
2467 */
2468 if (vpd->rev.feaLevelHigh >= 0x02) {
2469 npr->ConfmComplAllowed = 1;
2470 npr->Retry = 1;
2471 npr->TaskRetryIdReq = 1;
2472 }
2473
2474 npr->acceptRspCode = PRLI_REQ_EXECUTED;
2475 npr->estabImagePair = 1;
2476 npr->readXferRdyDis = 1;
2477 npr->ConfmComplAllowed = 1;
2478
2479 npr->prliType = PRLI_FCP_TYPE;
2480 npr->initiatorFunc = 1;
2481
James Smart858c9f62007-06-17 19:56:39 -05002482 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2483 "Issue ACC PRLI: did:x%x flg:x%x",
2484 ndlp->nlp_DID, ndlp->nlp_flag, 0);
2485
dea31012005-04-17 16:05:31 -05002486 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05002487 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05002488
dea31012005-04-17 16:05:31 -05002489 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
dea31012005-04-17 16:05:31 -05002490 if (rc == IOCB_ERROR) {
2491 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002492 return 1;
dea31012005-04-17 16:05:31 -05002493 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002494 return 0;
dea31012005-04-17 16:05:31 -05002495}
2496
2497static int
James Smart2e0fef82007-06-17 19:56:36 -05002498lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
James Smart329f9bc2007-04-25 09:53:01 -04002499 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05002500{
James Smart2e0fef82007-06-17 19:56:36 -05002501 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002502 RNID *rn;
James Smart2e0fef82007-06-17 19:56:36 -05002503 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05002504 struct lpfc_iocbq *elsiocb;
2505 struct lpfc_sli_ring *pring;
2506 struct lpfc_sli *psli;
2507 uint8_t *pcmd;
2508 uint16_t cmdsize;
2509 int rc;
2510
2511 psli = &phba->sli;
2512 pring = &psli->ring[LPFC_ELS_RING];
2513
James Smart92d7f7b2007-06-17 19:56:38 -05002514 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
2515 + (2 * sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002516 if (format)
James Smart92d7f7b2007-06-17 19:56:38 -05002517 cmdsize += sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05002518
James Smart2e0fef82007-06-17 19:56:36 -05002519 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
2520 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05002521 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002522 return 1;
dea31012005-04-17 16:05:31 -05002523
dea31012005-04-17 16:05:31 -05002524 icmd = &elsiocb->iocb;
2525 oldcmd = &oldiocb->iocb;
2526 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04002527 /* Xmit RNID ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04002528 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2529 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
2530 elsiocb->iotag, elsiocb->iocb.ulpContext);
dea31012005-04-17 16:05:31 -05002531 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
dea31012005-04-17 16:05:31 -05002532 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05002533 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002534
James Smart92d7f7b2007-06-17 19:56:38 -05002535 memset(pcmd, 0, sizeof(RNID));
dea31012005-04-17 16:05:31 -05002536 rn = (RNID *) (pcmd);
2537 rn->Format = format;
James Smart92d7f7b2007-06-17 19:56:38 -05002538 rn->CommonLen = (2 * sizeof(struct lpfc_name));
2539 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2540 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002541 switch (format) {
2542 case 0:
2543 rn->SpecificLen = 0;
2544 break;
2545 case RNID_TOPOLOGY_DISC:
James Smart92d7f7b2007-06-17 19:56:38 -05002546 rn->SpecificLen = sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05002547 memcpy(&rn->un.topologyDisc.portName,
James Smart92d7f7b2007-06-17 19:56:38 -05002548 &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002549 rn->un.topologyDisc.unitType = RNID_HBA;
2550 rn->un.topologyDisc.physPort = 0;
2551 rn->un.topologyDisc.attachedNodes = 0;
2552 break;
2553 default:
2554 rn->CommonLen = 0;
2555 rn->SpecificLen = 0;
2556 break;
2557 }
2558
James Smart858c9f62007-06-17 19:56:39 -05002559 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2560 "Issue ACC RNID: did:x%x flg:x%x",
2561 ndlp->nlp_DID, ndlp->nlp_flag, 0);
2562
dea31012005-04-17 16:05:31 -05002563 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05002564 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart329f9bc2007-04-25 09:53:01 -04002565 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002566 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
2567 * it could be freed */
2568
dea31012005-04-17 16:05:31 -05002569 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
dea31012005-04-17 16:05:31 -05002570 if (rc == IOCB_ERROR) {
2571 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002572 return 1;
dea31012005-04-17 16:05:31 -05002573 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002574 return 0;
dea31012005-04-17 16:05:31 -05002575}
2576
2577int
James Smart2e0fef82007-06-17 19:56:36 -05002578lpfc_els_disc_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002579{
James Smart2e0fef82007-06-17 19:56:36 -05002580 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002581 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05002582 int sentadisc = 0;
dea31012005-04-17 16:05:31 -05002583
James Smart685f0bf2007-04-25 09:53:08 -04002584 /* go thru NPR nodes and issue any remaining ELS ADISCs */
James Smart2e0fef82007-06-17 19:56:36 -05002585 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smart685f0bf2007-04-25 09:53:08 -04002586 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
2587 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
2588 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
James Smart2e0fef82007-06-17 19:56:36 -05002589 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04002590 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05002591 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04002592 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002593 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2594 lpfc_issue_els_adisc(vport, ndlp, 0);
James Smart685f0bf2007-04-25 09:53:08 -04002595 sentadisc++;
James Smart2e0fef82007-06-17 19:56:36 -05002596 vport->num_disc_nodes++;
2597 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04002598 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05002599 spin_lock_irq(shost->host_lock);
2600 vport->fc_flag |= FC_NLP_MORE;
2601 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04002602 break;
dea31012005-04-17 16:05:31 -05002603 }
2604 }
2605 }
2606 if (sentadisc == 0) {
James Smart2e0fef82007-06-17 19:56:36 -05002607 spin_lock_irq(shost->host_lock);
2608 vport->fc_flag &= ~FC_NLP_MORE;
2609 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002610 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002611 return sentadisc;
dea31012005-04-17 16:05:31 -05002612}
2613
2614int
James Smart2e0fef82007-06-17 19:56:36 -05002615lpfc_els_disc_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002616{
James Smart2e0fef82007-06-17 19:56:36 -05002617 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002618 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05002619 int sentplogi = 0;
dea31012005-04-17 16:05:31 -05002620
James Smart2e0fef82007-06-17 19:56:36 -05002621 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
2622 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smart685f0bf2007-04-25 09:53:08 -04002623 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
2624 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
2625 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
2626 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
2627 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002628 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2629 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
James Smart685f0bf2007-04-25 09:53:08 -04002630 sentplogi++;
James Smart2e0fef82007-06-17 19:56:36 -05002631 vport->num_disc_nodes++;
2632 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04002633 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05002634 spin_lock_irq(shost->host_lock);
2635 vport->fc_flag |= FC_NLP_MORE;
2636 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04002637 break;
dea31012005-04-17 16:05:31 -05002638 }
2639 }
2640 }
2641 if (sentplogi == 0) {
James Smart2e0fef82007-06-17 19:56:36 -05002642 spin_lock_irq(shost->host_lock);
2643 vport->fc_flag &= ~FC_NLP_MORE;
2644 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002645 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002646 return sentplogi;
dea31012005-04-17 16:05:31 -05002647}
2648
James Smart92d7f7b2007-06-17 19:56:38 -05002649void
James Smart2e0fef82007-06-17 19:56:36 -05002650lpfc_els_flush_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002651{
James Smart2e0fef82007-06-17 19:56:36 -05002652 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2653 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002654 int i;
2655
James Smart2e0fef82007-06-17 19:56:36 -05002656 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05002657 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
James Smart2e0fef82007-06-17 19:56:36 -05002658 vport->fc_rscn_id_list[i] = NULL;
dea31012005-04-17 16:05:31 -05002659 }
James Smart2e0fef82007-06-17 19:56:36 -05002660 spin_lock_irq(shost->host_lock);
2661 vport->fc_rscn_id_cnt = 0;
2662 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
2663 spin_unlock_irq(shost->host_lock);
2664 lpfc_can_disctmo(vport);
dea31012005-04-17 16:05:31 -05002665}
2666
2667int
James Smart2e0fef82007-06-17 19:56:36 -05002668lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05002669{
2670 D_ID ns_did;
2671 D_ID rscn_did;
dea31012005-04-17 16:05:31 -05002672 uint32_t *lp;
James Smart92d7f7b2007-06-17 19:56:38 -05002673 uint32_t payload_len, i;
dea31012005-04-17 16:05:31 -05002674
2675 ns_did.un.word = did;
dea31012005-04-17 16:05:31 -05002676
2677 /* Never match fabric nodes for RSCNs */
2678 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
James Smart2e0fef82007-06-17 19:56:36 -05002679 return 0;
dea31012005-04-17 16:05:31 -05002680
2681 /* If we are doing a FULL RSCN rediscovery, match everything */
James Smart2e0fef82007-06-17 19:56:36 -05002682 if (vport->fc_flag & FC_RSCN_DISCOVERY)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002683 return did;
dea31012005-04-17 16:05:31 -05002684
James Smart2e0fef82007-06-17 19:56:36 -05002685 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05002686 lp = vport->fc_rscn_id_list[i]->virt;
2687 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
2688 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05002689 while (payload_len) {
James Smart92d7f7b2007-06-17 19:56:38 -05002690 rscn_did.un.word = be32_to_cpu(*lp++);
2691 payload_len -= sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002692 switch (rscn_did.un.b.resv) {
2693 case 0: /* Single N_Port ID effected */
James Smart2e0fef82007-06-17 19:56:36 -05002694 if (ns_did.un.word == rscn_did.un.word)
James Smart92d7f7b2007-06-17 19:56:38 -05002695 return did;
dea31012005-04-17 16:05:31 -05002696 break;
2697 case 1: /* Whole N_Port Area effected */
2698 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
2699 && (ns_did.un.b.area == rscn_did.un.b.area))
James Smart92d7f7b2007-06-17 19:56:38 -05002700 return did;
dea31012005-04-17 16:05:31 -05002701 break;
2702 case 2: /* Whole N_Port Domain effected */
2703 if (ns_did.un.b.domain == rscn_did.un.b.domain)
James Smart92d7f7b2007-06-17 19:56:38 -05002704 return did;
dea31012005-04-17 16:05:31 -05002705 break;
2706 default:
James Smart2e0fef82007-06-17 19:56:36 -05002707 /* Unknown Identifier in RSCN node */
James Smarte8b62012007-08-02 11:10:09 -04002708 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
2709 "0217 Unknown Identifier in "
2710 "RSCN payload Data: x%x\n",
2711 rscn_did.un.word);
James Smart92d7f7b2007-06-17 19:56:38 -05002712 case 3: /* Whole Fabric effected */
2713 return did;
dea31012005-04-17 16:05:31 -05002714 }
2715 }
James Smart92d7f7b2007-06-17 19:56:38 -05002716 }
2717 return 0;
dea31012005-04-17 16:05:31 -05002718}
2719
2720static int
James Smart2e0fef82007-06-17 19:56:36 -05002721lpfc_rscn_recovery_check(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002722{
James Smart685f0bf2007-04-25 09:53:08 -04002723 struct lpfc_nodelist *ndlp = NULL;
dea31012005-04-17 16:05:31 -05002724
2725 /* Look at all nodes effected by pending RSCNs and move
James Smart685f0bf2007-04-25 09:53:08 -04002726 * them to NPR state.
dea31012005-04-17 16:05:31 -05002727 */
James Smart685f0bf2007-04-25 09:53:08 -04002728
James Smart2e0fef82007-06-17 19:56:36 -05002729 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smart685f0bf2007-04-25 09:53:08 -04002730 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE ||
James Smart2e0fef82007-06-17 19:56:36 -05002731 lpfc_rscn_payload_check(vport, ndlp->nlp_DID) == 0)
dea31012005-04-17 16:05:31 -05002732 continue;
2733
James Smart2e0fef82007-06-17 19:56:36 -05002734 lpfc_disc_state_machine(vport, ndlp, NULL,
James Smart92d7f7b2007-06-17 19:56:38 -05002735 NLP_EVT_DEVICE_RECOVERY);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002736
James Smart685f0bf2007-04-25 09:53:08 -04002737 /*
2738 * Make sure NLP_DELAY_TMO is NOT running after a device
2739 * recovery event.
2740 */
2741 if (ndlp->nlp_flag & NLP_DELAY_TMO)
James Smart2e0fef82007-06-17 19:56:36 -05002742 lpfc_cancel_retry_delay_tmo(vport, ndlp);
dea31012005-04-17 16:05:31 -05002743 }
James Smart685f0bf2007-04-25 09:53:08 -04002744
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002745 return 0;
dea31012005-04-17 16:05:31 -05002746}
2747
2748static int
James Smart2e0fef82007-06-17 19:56:36 -05002749lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
2750 struct lpfc_nodelist *ndlp, uint8_t newnode)
dea31012005-04-17 16:05:31 -05002751{
James Smart2e0fef82007-06-17 19:56:36 -05002752 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2753 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002754 struct lpfc_dmabuf *pcmd;
James Smart92d7f7b2007-06-17 19:56:38 -05002755 uint32_t *lp, *datap;
dea31012005-04-17 16:05:31 -05002756 IOCB_t *icmd;
James Smart92d7f7b2007-06-17 19:56:38 -05002757 uint32_t payload_len, length, nportid, *cmd;
2758 int rscn_cnt = vport->fc_rscn_id_cnt;
2759 int rscn_id = 0, hba_id = 0;
James Smartd2873e42006-08-18 17:46:43 -04002760 int i;
dea31012005-04-17 16:05:31 -05002761
2762 icmd = &cmdiocb->iocb;
2763 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2764 lp = (uint32_t *) pcmd->virt;
2765
James Smart92d7f7b2007-06-17 19:56:38 -05002766 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
2767 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05002768 /* RSCN received */
James Smarte8b62012007-08-02 11:10:09 -04002769 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2770 "0214 RSCN received Data: x%x x%x x%x x%x\n",
2771 vport->fc_flag, payload_len, *lp, rscn_cnt);
James Smartd2873e42006-08-18 17:46:43 -04002772 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
James Smart2e0fef82007-06-17 19:56:36 -05002773 fc_host_post_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04002774 FCH_EVT_RSCN, lp[i]);
2775
dea31012005-04-17 16:05:31 -05002776 /* If we are about to begin discovery, just ACC the RSCN.
2777 * Discovery processing will satisfy it.
2778 */
James Smart2e0fef82007-06-17 19:56:36 -05002779 if (vport->port_state <= LPFC_NS_QRY) {
James Smart858c9f62007-06-17 19:56:39 -05002780 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
2781 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
2782 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
2783
James Smart2e0fef82007-06-17 19:56:36 -05002784 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL,
James Smart92d7f7b2007-06-17 19:56:38 -05002785 newnode);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002786 return 0;
dea31012005-04-17 16:05:31 -05002787 }
2788
James Smart92d7f7b2007-06-17 19:56:38 -05002789 /* If this RSCN just contains NPortIDs for other vports on this HBA,
2790 * just ACC and ignore it.
2791 */
2792 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart3de2a652007-08-02 11:09:59 -04002793 !(vport->cfg_peer_port_login)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002794 i = payload_len;
2795 datap = lp;
2796 while (i > 0) {
2797 nportid = *datap++;
2798 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
2799 i -= sizeof(uint32_t);
2800 rscn_id++;
James Smart549e55c2007-08-02 11:09:51 -04002801 if (lpfc_find_vport_by_did(phba, nportid))
2802 hba_id++;
James Smart92d7f7b2007-06-17 19:56:38 -05002803 }
2804 if (rscn_id == hba_id) {
2805 /* ALL NPortIDs in RSCN are on HBA */
James Smarte8b62012007-08-02 11:10:09 -04002806 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2807 "0214 Ignore RSCN "
2808 "Data: x%x x%x x%x x%x\n",
2809 vport->fc_flag, payload_len,
2810 *lp, rscn_cnt);
James Smart858c9f62007-06-17 19:56:39 -05002811 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
2812 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
2813 ndlp->nlp_DID, vport->port_state,
2814 ndlp->nlp_flag);
2815
James Smart92d7f7b2007-06-17 19:56:38 -05002816 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
2817 ndlp, NULL, newnode);
2818 return 0;
2819 }
2820 }
2821
dea31012005-04-17 16:05:31 -05002822 /* If we are already processing an RSCN, save the received
2823 * RSCN payload buffer, cmdiocb->context2 to process later.
2824 */
James Smart2e0fef82007-06-17 19:56:36 -05002825 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
James Smart858c9f62007-06-17 19:56:39 -05002826 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
2827 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
2828 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
2829
James Smart92d7f7b2007-06-17 19:56:38 -05002830 vport->fc_flag |= FC_RSCN_DEFERRED;
2831 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
James Smart2e0fef82007-06-17 19:56:36 -05002832 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
2833 spin_lock_irq(shost->host_lock);
2834 vport->fc_flag |= FC_RSCN_MODE;
2835 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05002836 if (rscn_cnt) {
2837 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
2838 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
2839 }
2840 if ((rscn_cnt) &&
2841 (payload_len + length <= LPFC_BPL_SIZE)) {
2842 *cmd &= ELS_CMD_MASK;
2843 *cmd |= be32_to_cpu(payload_len + length);
2844 memcpy(((uint8_t *)cmd) + length, lp,
2845 payload_len);
2846 } else {
2847 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
2848 vport->fc_rscn_id_cnt++;
2849 /* If we zero, cmdiocb->context2, the calling
2850 * routine will not try to free it.
2851 */
2852 cmdiocb->context2 = NULL;
2853 }
dea31012005-04-17 16:05:31 -05002854
2855 /* Deferred RSCN */
James Smarte8b62012007-08-02 11:10:09 -04002856 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2857 "0235 Deferred RSCN "
2858 "Data: x%x x%x x%x\n",
2859 vport->fc_rscn_id_cnt, vport->fc_flag,
2860 vport->port_state);
dea31012005-04-17 16:05:31 -05002861 } else {
James Smart2e0fef82007-06-17 19:56:36 -05002862 spin_lock_irq(shost->host_lock);
2863 vport->fc_flag |= FC_RSCN_DISCOVERY;
2864 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002865 /* ReDiscovery RSCN */
James Smarte8b62012007-08-02 11:10:09 -04002866 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2867 "0234 ReDiscovery RSCN "
2868 "Data: x%x x%x x%x\n",
2869 vport->fc_rscn_id_cnt, vport->fc_flag,
2870 vport->port_state);
dea31012005-04-17 16:05:31 -05002871 }
2872 /* Send back ACC */
James Smart2e0fef82007-06-17 19:56:36 -05002873 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL,
dea31012005-04-17 16:05:31 -05002874 newnode);
2875
2876 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05002877 lpfc_rscn_recovery_check(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05002878 vport->fc_flag &= ~FC_RSCN_DEFERRED;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002879 return 0;
dea31012005-04-17 16:05:31 -05002880 }
2881
James Smart858c9f62007-06-17 19:56:39 -05002882 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
2883 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
2884 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
2885
James Smart2e0fef82007-06-17 19:56:36 -05002886 spin_lock_irq(shost->host_lock);
2887 vport->fc_flag |= FC_RSCN_MODE;
2888 spin_unlock_irq(shost->host_lock);
2889 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
dea31012005-04-17 16:05:31 -05002890 /*
2891 * If we zero, cmdiocb->context2, the calling routine will
2892 * not try to free it.
2893 */
2894 cmdiocb->context2 = NULL;
2895
James Smart2e0fef82007-06-17 19:56:36 -05002896 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05002897
2898 /* Send back ACC */
James Smart2e0fef82007-06-17 19:56:36 -05002899 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL, newnode);
dea31012005-04-17 16:05:31 -05002900
2901 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05002902 lpfc_rscn_recovery_check(vport);
dea31012005-04-17 16:05:31 -05002903
James Smart2e0fef82007-06-17 19:56:36 -05002904 return lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05002905}
2906
2907int
James Smart2e0fef82007-06-17 19:56:36 -05002908lpfc_els_handle_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002909{
2910 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05002911 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002912
James Smart92d7f7b2007-06-17 19:56:38 -05002913 /* Ignore RSCN if the port is being torn down. */
2914 if (vport->load_flag & FC_UNLOADING) {
2915 lpfc_els_flush_rscn(vport);
2916 return 0;
2917 }
2918
dea31012005-04-17 16:05:31 -05002919 /* Start timer for RSCN processing */
James Smart2e0fef82007-06-17 19:56:36 -05002920 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05002921
2922 /* RSCN processed */
James Smarte8b62012007-08-02 11:10:09 -04002923 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2924 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
2925 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
2926 vport->port_state);
dea31012005-04-17 16:05:31 -05002927
2928 /* To process RSCN, first compare RSCN data with NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05002929 vport->fc_ns_retry = 0;
2930 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smart685f0bf2007-04-25 09:53:08 -04002931 if (ndlp && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
dea31012005-04-17 16:05:31 -05002932 /* Good ndlp, issue CT Request to NameServer */
James Smart92d7f7b2007-06-17 19:56:38 -05002933 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
dea31012005-04-17 16:05:31 -05002934 /* Wait for NameServer query cmpl before we can
2935 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002936 return 1;
dea31012005-04-17 16:05:31 -05002937 } else {
2938 /* If login to NameServer does not exist, issue one */
2939 /* Good status, issue PLOGI to NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05002940 ndlp = lpfc_findnode_did(vport, NameServer_DID);
2941 if (ndlp)
dea31012005-04-17 16:05:31 -05002942 /* Wait for NameServer login cmpl before we can
2943 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002944 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05002945
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002946 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2947 if (!ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05002948 lpfc_els_flush_rscn(vport);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002949 return 0;
dea31012005-04-17 16:05:31 -05002950 } else {
James Smart2e0fef82007-06-17 19:56:36 -05002951 lpfc_nlp_init(vport, ndlp, NameServer_DID);
dea31012005-04-17 16:05:31 -05002952 ndlp->nlp_type |= NLP_FABRIC;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002953 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002954 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2955 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
dea31012005-04-17 16:05:31 -05002956 /* Wait for NameServer login cmpl before we can
2957 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002958 return 1;
dea31012005-04-17 16:05:31 -05002959 }
2960 }
2961
James Smart2e0fef82007-06-17 19:56:36 -05002962 lpfc_els_flush_rscn(vport);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002963 return 0;
dea31012005-04-17 16:05:31 -05002964}
2965
2966static int
James Smart2e0fef82007-06-17 19:56:36 -05002967lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
2968 struct lpfc_nodelist *ndlp, uint8_t newnode)
dea31012005-04-17 16:05:31 -05002969{
James Smart2e0fef82007-06-17 19:56:36 -05002970 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2971 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002972 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2973 uint32_t *lp = (uint32_t *) pcmd->virt;
2974 IOCB_t *icmd = &cmdiocb->iocb;
2975 struct serv_parm *sp;
2976 LPFC_MBOXQ_t *mbox;
2977 struct ls_rjt stat;
2978 uint32_t cmd, did;
2979 int rc;
2980
2981 cmd = *lp++;
2982 sp = (struct serv_parm *) lp;
2983
2984 /* FLOGI received */
2985
James Smart2e0fef82007-06-17 19:56:36 -05002986 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05002987
2988 if (phba->fc_topology == TOPOLOGY_LOOP) {
2989 /* We should never receive a FLOGI in loop mode, ignore it */
2990 did = icmd->un.elsreq64.remoteID;
2991
2992 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
2993 Loop Mode */
James Smarte8b62012007-08-02 11:10:09 -04002994 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2995 "0113 An FLOGI ELS command x%x was "
2996 "received from DID x%x in Loop Mode\n",
2997 cmd, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002998 return 1;
dea31012005-04-17 16:05:31 -05002999 }
3000
3001 did = Fabric_DID;
3002
James Smart2e0fef82007-06-17 19:56:36 -05003003 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3))) {
dea31012005-04-17 16:05:31 -05003004 /* For a FLOGI we accept, then if our portname is greater
3005 * then the remote portname we initiate Nport login.
3006 */
3007
James Smart2e0fef82007-06-17 19:56:36 -05003008 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -05003009 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003010
3011 if (!rc) {
James Smart2e0fef82007-06-17 19:56:36 -05003012 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3013 if (!mbox)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003014 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05003015
dea31012005-04-17 16:05:31 -05003016 lpfc_linkdown(phba);
3017 lpfc_init_link(phba, mbox,
3018 phba->cfg_topology,
3019 phba->cfg_link_speed);
3020 mbox->mb.un.varInitLnk.lipsr_AL_PA = 0;
3021 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -05003022 mbox->vport = vport;
dea31012005-04-17 16:05:31 -05003023 rc = lpfc_sli_issue_mbox
3024 (phba, mbox, (MBX_NOWAIT | MBX_STOP_IOCB));
James Smart5b8bd0c2007-04-25 09:52:49 -04003025 lpfc_set_loopback_flag(phba);
dea31012005-04-17 16:05:31 -05003026 if (rc == MBX_NOT_FINISHED) {
James Smart329f9bc2007-04-25 09:53:01 -04003027 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003028 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003029 return 1;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003030 } else if (rc > 0) { /* greater than */
James Smart2e0fef82007-06-17 19:56:36 -05003031 spin_lock_irq(shost->host_lock);
3032 vport->fc_flag |= FC_PT2PT_PLOGI;
3033 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003034 }
James Smart2e0fef82007-06-17 19:56:36 -05003035 spin_lock_irq(shost->host_lock);
3036 vport->fc_flag |= FC_PT2PT;
3037 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
3038 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003039 } else {
3040 /* Reject this request because invalid parameters */
3041 stat.un.b.lsRjtRsvd0 = 0;
3042 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3043 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
3044 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05003045 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
3046 NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003047 return 1;
dea31012005-04-17 16:05:31 -05003048 }
3049
3050 /* Send back ACC */
James Smart2e0fef82007-06-17 19:56:36 -05003051 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL, newnode);
dea31012005-04-17 16:05:31 -05003052
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003053 return 0;
dea31012005-04-17 16:05:31 -05003054}
3055
3056static int
James Smart2e0fef82007-06-17 19:56:36 -05003057lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3058 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003059{
3060 struct lpfc_dmabuf *pcmd;
3061 uint32_t *lp;
3062 IOCB_t *icmd;
3063 RNID *rn;
3064 struct ls_rjt stat;
3065 uint32_t cmd, did;
3066
3067 icmd = &cmdiocb->iocb;
3068 did = icmd->un.elsreq64.remoteID;
3069 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3070 lp = (uint32_t *) pcmd->virt;
3071
3072 cmd = *lp++;
3073 rn = (RNID *) lp;
3074
3075 /* RNID received */
3076
3077 switch (rn->Format) {
3078 case 0:
3079 case RNID_TOPOLOGY_DISC:
3080 /* Send back ACC */
James Smart2e0fef82007-06-17 19:56:36 -05003081 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05003082 break;
3083 default:
3084 /* Reject this request because format not supported */
3085 stat.un.b.lsRjtRsvd0 = 0;
3086 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3087 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
3088 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05003089 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
3090 NULL);
dea31012005-04-17 16:05:31 -05003091 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003092 return 0;
dea31012005-04-17 16:05:31 -05003093}
3094
3095static int
James Smart2e0fef82007-06-17 19:56:36 -05003096lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3097 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003098{
3099 struct ls_rjt stat;
3100
3101 /* For now, unconditionally reject this command */
3102 stat.un.b.lsRjtRsvd0 = 0;
3103 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3104 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
3105 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05003106 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003107 return 0;
3108}
3109
Jamie Wellnitz082c0262006-02-28 19:25:30 -05003110static void
James Smart329f9bc2007-04-25 09:53:01 -04003111lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003112{
James Smart2e0fef82007-06-17 19:56:36 -05003113 struct lpfc_sli *psli = &phba->sli;
3114 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003115 MAILBOX_t *mb;
3116 IOCB_t *icmd;
3117 RPS_RSP *rps_rsp;
3118 uint8_t *pcmd;
3119 struct lpfc_iocbq *elsiocb;
3120 struct lpfc_nodelist *ndlp;
3121 uint16_t xri, status;
3122 uint32_t cmdsize;
3123
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003124 mb = &pmb->mb;
3125
3126 ndlp = (struct lpfc_nodelist *) pmb->context2;
3127 xri = (uint16_t) ((unsigned long)(pmb->context1));
Randy Dunlap041976f2006-06-25 01:58:51 -07003128 pmb->context1 = NULL;
3129 pmb->context2 = NULL;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003130
3131 if (mb->mbxStatus) {
James Smart329f9bc2007-04-25 09:53:01 -04003132 mempool_free(pmb, phba->mbox_mem_pool);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003133 return;
3134 }
3135
3136 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
James Smart329f9bc2007-04-25 09:53:01 -04003137 mempool_free(pmb, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05003138 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
3139 lpfc_max_els_tries, ndlp,
3140 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart329f9bc2007-04-25 09:53:01 -04003141 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003142 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003143 return;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003144
3145 icmd = &elsiocb->iocb;
3146 icmd->ulpContext = xri;
3147
3148 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3149 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003150 pcmd += sizeof(uint32_t); /* Skip past command */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003151 rps_rsp = (RPS_RSP *)pcmd;
3152
3153 if (phba->fc_topology != TOPOLOGY_LOOP)
3154 status = 0x10;
3155 else
3156 status = 0x8;
James Smart2e0fef82007-06-17 19:56:36 -05003157 if (phba->pport->fc_flag & FC_FABRIC)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003158 status |= 0x4;
3159
3160 rps_rsp->rsvd1 = 0;
3161 rps_rsp->portStatus = be16_to_cpu(status);
3162 rps_rsp->linkFailureCnt = be32_to_cpu(mb->un.varRdLnk.linkFailureCnt);
3163 rps_rsp->lossSyncCnt = be32_to_cpu(mb->un.varRdLnk.lossSyncCnt);
3164 rps_rsp->lossSignalCnt = be32_to_cpu(mb->un.varRdLnk.lossSignalCnt);
3165 rps_rsp->primSeqErrCnt = be32_to_cpu(mb->un.varRdLnk.primSeqErrCnt);
3166 rps_rsp->invalidXmitWord = be32_to_cpu(mb->un.varRdLnk.invalidXmitWord);
3167 rps_rsp->crcCnt = be32_to_cpu(mb->un.varRdLnk.crcCnt);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003168 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003169 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
3170 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
3171 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
3172 elsiocb->iotag, elsiocb->iocb.ulpContext,
3173 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3174 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05003175 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003176 phba->fc_stat.elsXmitACC++;
James Smarted957682007-06-17 19:56:37 -05003177 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003178 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003179 return;
3180}
3181
3182static int
James Smart2e0fef82007-06-17 19:56:36 -05003183lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3184 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003185{
James Smart2e0fef82007-06-17 19:56:36 -05003186 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003187 uint32_t *lp;
3188 uint8_t flag;
3189 LPFC_MBOXQ_t *mbox;
3190 struct lpfc_dmabuf *pcmd;
3191 RPS *rps;
3192 struct ls_rjt stat;
3193
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003194 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
3195 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003196 stat.un.b.lsRjtRsvd0 = 0;
3197 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3198 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
3199 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05003200 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
3201 NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003202 }
3203
3204 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3205 lp = (uint32_t *) pcmd->virt;
3206 flag = (be32_to_cpu(*lp++) & 0xf);
3207 rps = (RPS *) lp;
3208
3209 if ((flag == 0) ||
3210 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
James Smart2e0fef82007-06-17 19:56:36 -05003211 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05003212 sizeof(struct lpfc_name)) == 0))) {
James Smart2e0fef82007-06-17 19:56:36 -05003213
James Smart92d7f7b2007-06-17 19:56:38 -05003214 printk("Fix me....\n");
3215 dump_stack();
James Smart2e0fef82007-06-17 19:56:36 -05003216 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
3217 if (mbox) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003218 lpfc_read_lnk_stat(phba, mbox);
3219 mbox->context1 =
James Smart92d7f7b2007-06-17 19:56:38 -05003220 (void *)((unsigned long) cmdiocb->iocb.ulpContext);
James Smart329f9bc2007-04-25 09:53:01 -04003221 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05003222 mbox->vport = vport;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003223 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
3224 if (lpfc_sli_issue_mbox (phba, mbox,
James Smart2e0fef82007-06-17 19:56:36 -05003225 (MBX_NOWAIT | MBX_STOP_IOCB)) != MBX_NOT_FINISHED)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003226 /* Mbox completion will send ELS Response */
3227 return 0;
James Smart2e0fef82007-06-17 19:56:36 -05003228
James Smart329f9bc2007-04-25 09:53:01 -04003229 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003230 mempool_free(mbox, phba->mbox_mem_pool);
3231 }
3232 }
3233 stat.un.b.lsRjtRsvd0 = 0;
3234 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3235 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
3236 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05003237 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003238 return 0;
3239}
3240
Jamie Wellnitz082c0262006-02-28 19:25:30 -05003241static int
James Smart2e0fef82007-06-17 19:56:36 -05003242lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
3243 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003244{
James Smart2e0fef82007-06-17 19:56:36 -05003245 struct lpfc_hba *phba = vport->phba;
3246 IOCB_t *icmd, *oldcmd;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003247 RPL_RSP rpl_rsp;
3248 struct lpfc_iocbq *elsiocb;
James Smart2e0fef82007-06-17 19:56:36 -05003249 struct lpfc_sli *psli = &phba->sli;
3250 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003251 uint8_t *pcmd;
3252
James Smart2e0fef82007-06-17 19:56:36 -05003253 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3254 ndlp->nlp_DID, ELS_CMD_ACC);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003255
James Smart488d1462006-03-07 15:02:37 -05003256 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003257 return 1;
James Smart488d1462006-03-07 15:02:37 -05003258
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003259 icmd = &elsiocb->iocb;
3260 oldcmd = &oldiocb->iocb;
3261 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3262
3263 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3264 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003265 pcmd += sizeof(uint16_t);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003266 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
3267 pcmd += sizeof(uint16_t);
3268
3269 /* Setup the RPL ACC payload */
3270 rpl_rsp.listLen = be32_to_cpu(1);
3271 rpl_rsp.index = 0;
3272 rpl_rsp.port_num_blk.portNum = 0;
James Smart2e0fef82007-06-17 19:56:36 -05003273 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
3274 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003275 sizeof(struct lpfc_name));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003276 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003277 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003278 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3279 "0120 Xmit ELS RPL ACC response tag x%x "
3280 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
3281 "rpi x%x\n",
3282 elsiocb->iotag, elsiocb->iocb.ulpContext,
3283 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3284 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05003285 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003286 phba->fc_stat.elsXmitACC++;
3287 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
3288 lpfc_els_free_iocb(phba, elsiocb);
3289 return 1;
3290 }
3291 return 0;
3292}
3293
3294static int
James Smart2e0fef82007-06-17 19:56:36 -05003295lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3296 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003297{
3298 struct lpfc_dmabuf *pcmd;
3299 uint32_t *lp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003300 uint32_t maxsize;
3301 uint16_t cmdsize;
3302 RPL *rpl;
3303 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05003304
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003305 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
3306 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003307 stat.un.b.lsRjtRsvd0 = 0;
3308 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3309 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
3310 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05003311 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
3312 NULL);
dea31012005-04-17 16:05:31 -05003313 }
3314
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003315 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3316 lp = (uint32_t *) pcmd->virt;
3317 rpl = (RPL *) (lp + 1);
3318
3319 maxsize = be32_to_cpu(rpl->maxsize);
3320
3321 /* We support only one port */
3322 if ((rpl->index == 0) &&
3323 ((maxsize == 0) ||
3324 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
3325 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003326 } else {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003327 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
3328 }
James Smart2e0fef82007-06-17 19:56:36 -05003329 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05003330
3331 return 0;
3332}
3333
3334static int
James Smart2e0fef82007-06-17 19:56:36 -05003335lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3336 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003337{
3338 struct lpfc_dmabuf *pcmd;
3339 uint32_t *lp;
3340 IOCB_t *icmd;
3341 FARP *fp;
3342 uint32_t cmd, cnt, did;
3343
3344 icmd = &cmdiocb->iocb;
3345 did = icmd->un.elsreq64.remoteID;
3346 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3347 lp = (uint32_t *) pcmd->virt;
3348
3349 cmd = *lp++;
3350 fp = (FARP *) lp;
dea31012005-04-17 16:05:31 -05003351 /* FARP-REQ received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04003352 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3353 "0601 FARP-REQ received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05003354 /* We will only support match on WWPN or WWNN */
3355 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003356 return 0;
dea31012005-04-17 16:05:31 -05003357 }
3358
3359 cnt = 0;
3360 /* If this FARP command is searching for my portname */
3361 if (fp->Mflags & FARP_MATCH_PORT) {
James Smart2e0fef82007-06-17 19:56:36 -05003362 if (memcmp(&fp->RportName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05003363 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05003364 cnt = 1;
3365 }
3366
3367 /* If this FARP command is searching for my nodename */
3368 if (fp->Mflags & FARP_MATCH_NODE) {
James Smart2e0fef82007-06-17 19:56:36 -05003369 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05003370 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05003371 cnt = 1;
3372 }
3373
3374 if (cnt) {
3375 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
3376 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
3377 /* Log back into the node before sending the FARP. */
3378 if (fp->Rflags & FARP_REQUEST_PLOGI) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003379 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003380 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04003381 NLP_STE_PLOGI_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05003382 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05003383 }
3384
3385 /* Send a FARP response to that node */
James Smart2e0fef82007-06-17 19:56:36 -05003386 if (fp->Rflags & FARP_REQUEST_FARPR)
3387 lpfc_issue_els_farpr(vport, did, 0);
dea31012005-04-17 16:05:31 -05003388 }
3389 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003390 return 0;
dea31012005-04-17 16:05:31 -05003391}
3392
3393static int
James Smart2e0fef82007-06-17 19:56:36 -05003394lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3395 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003396{
3397 struct lpfc_dmabuf *pcmd;
3398 uint32_t *lp;
3399 IOCB_t *icmd;
3400 uint32_t cmd, did;
3401
3402 icmd = &cmdiocb->iocb;
3403 did = icmd->un.elsreq64.remoteID;
3404 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3405 lp = (uint32_t *) pcmd->virt;
3406
3407 cmd = *lp++;
3408 /* FARP-RSP received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04003409 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3410 "0600 FARP-RSP received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05003411 /* ACCEPT the Farp resp request */
James Smart2e0fef82007-06-17 19:56:36 -05003412 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
dea31012005-04-17 16:05:31 -05003413
3414 return 0;
3415}
3416
3417static int
James Smart2e0fef82007-06-17 19:56:36 -05003418lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3419 struct lpfc_nodelist *fan_ndlp)
dea31012005-04-17 16:05:31 -05003420{
3421 struct lpfc_dmabuf *pcmd;
3422 uint32_t *lp;
3423 IOCB_t *icmd;
dea31012005-04-17 16:05:31 -05003424 uint32_t cmd, did;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003425 FAN *fp;
3426 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05003427 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003428
3429 /* FAN received */
James Smarte8b62012007-08-02 11:10:09 -04003430 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3431 "0265 FAN received\n");
dea31012005-04-17 16:05:31 -05003432 icmd = &cmdiocb->iocb;
3433 did = icmd->un.elsreq64.remoteID;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003434 pcmd = (struct lpfc_dmabuf *)cmdiocb->context2;
3435 lp = (uint32_t *)pcmd->virt;
dea31012005-04-17 16:05:31 -05003436
3437 cmd = *lp++;
James Smart92d7f7b2007-06-17 19:56:38 -05003438 fp = (FAN *) lp;
dea31012005-04-17 16:05:31 -05003439
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003440 /* FAN received; Fan does not have a reply sequence */
dea31012005-04-17 16:05:31 -05003441
James Smart2e0fef82007-06-17 19:56:36 -05003442 if (phba->pport->port_state == LPFC_LOCAL_CFG_LINK) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003443 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
3444 sizeof(struct lpfc_name)) != 0) ||
3445 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
3446 sizeof(struct lpfc_name)) != 0)) {
3447 /*
3448 * This node has switched fabrics. FLOGI is required
3449 * Clean up the old rpi's
dea31012005-04-17 16:05:31 -05003450 */
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003451
3452 list_for_each_entry_safe(ndlp, next_ndlp,
James Smart2e0fef82007-06-17 19:56:36 -05003453 &vport->fc_nodes, nlp_listp) {
James Smart685f0bf2007-04-25 09:53:08 -04003454 if (ndlp->nlp_state != NLP_STE_NPR_NODE)
3455 continue;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003456 if (ndlp->nlp_type & NLP_FABRIC) {
3457 /*
3458 * Clean up old Fabric, Nameserver and
3459 * other NLP_FABRIC logins
3460 */
James Smart2e0fef82007-06-17 19:56:36 -05003461 lpfc_drop_node(vport, ndlp);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003462 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003463 /* Fail outstanding I/O now since this
3464 * device is marked for PLOGI
3465 */
James Smart2e0fef82007-06-17 19:56:36 -05003466 lpfc_unreg_rpi(vport, ndlp);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003467 }
3468 }
3469
James Smart2e0fef82007-06-17 19:56:36 -05003470 vport->port_state = LPFC_FLOGI;
3471 lpfc_set_disctmo(vport);
3472 lpfc_initial_flogi(vport);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003473 return 0;
dea31012005-04-17 16:05:31 -05003474 }
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003475 /* Discovery not needed,
3476 * move the nodes to their original state.
3477 */
James Smart2e0fef82007-06-17 19:56:36 -05003478 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
James Smart685f0bf2007-04-25 09:53:08 -04003479 nlp_listp) {
3480 if (ndlp->nlp_state != NLP_STE_NPR_NODE)
3481 continue;
dea31012005-04-17 16:05:31 -05003482
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003483 switch (ndlp->nlp_prev_state) {
3484 case NLP_STE_UNMAPPED_NODE:
3485 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05003486 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04003487 NLP_STE_UNMAPPED_NODE);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003488 break;
3489
3490 case NLP_STE_MAPPED_NODE:
3491 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05003492 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04003493 NLP_STE_MAPPED_NODE);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003494 break;
3495
3496 default:
3497 break;
3498 }
3499 }
3500
3501 /* Start discovery - this should just do CLEAR_LA */
James Smart2e0fef82007-06-17 19:56:36 -05003502 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -05003503 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003504 return 0;
dea31012005-04-17 16:05:31 -05003505}
3506
3507void
3508lpfc_els_timeout(unsigned long ptr)
3509{
James Smart2e0fef82007-06-17 19:56:36 -05003510 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
3511 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003512 unsigned long iflag;
3513
James Smart2e0fef82007-06-17 19:56:36 -05003514 spin_lock_irqsave(&vport->work_port_lock, iflag);
3515 if ((vport->work_port_events & WORKER_ELS_TMO) == 0) {
3516 vport->work_port_events |= WORKER_ELS_TMO;
James Smart92d7f7b2007-06-17 19:56:38 -05003517 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
3518
3519 spin_lock_irqsave(&phba->hbalock, iflag);
dea31012005-04-17 16:05:31 -05003520 if (phba->work_wait)
James Smart92d7f7b2007-06-17 19:56:38 -05003521 lpfc_worker_wake_up(phba);
3522 spin_unlock_irqrestore(&phba->hbalock, iflag);
dea31012005-04-17 16:05:31 -05003523 }
James Smart92d7f7b2007-06-17 19:56:38 -05003524 else
3525 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
dea31012005-04-17 16:05:31 -05003526 return;
3527}
3528
3529void
James Smart2e0fef82007-06-17 19:56:36 -05003530lpfc_els_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003531{
James Smart2e0fef82007-06-17 19:56:36 -05003532 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003533 struct lpfc_sli_ring *pring;
3534 struct lpfc_iocbq *tmp_iocb, *piocb;
3535 IOCB_t *cmd = NULL;
3536 struct lpfc_dmabuf *pcmd;
James Smart2e0fef82007-06-17 19:56:36 -05003537 uint32_t els_command = 0;
dea31012005-04-17 16:05:31 -05003538 uint32_t timeout;
James Smart2e0fef82007-06-17 19:56:36 -05003539 uint32_t remote_ID = 0xffffffff;
dea31012005-04-17 16:05:31 -05003540
dea31012005-04-17 16:05:31 -05003541 /* If the timer is already canceled do nothing */
James Smart2e0fef82007-06-17 19:56:36 -05003542 if ((vport->work_port_events & WORKER_ELS_TMO) == 0) {
dea31012005-04-17 16:05:31 -05003543 return;
3544 }
James Smart2e0fef82007-06-17 19:56:36 -05003545 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003546 timeout = (uint32_t)(phba->fc_ratov << 1);
3547
3548 pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05003549
3550 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
3551 cmd = &piocb->iocb;
3552
James Smart2e0fef82007-06-17 19:56:36 -05003553 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
3554 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
3555 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
dea31012005-04-17 16:05:31 -05003556 continue;
James Smart2e0fef82007-06-17 19:56:36 -05003557
3558 if (piocb->vport != vport)
3559 continue;
3560
dea31012005-04-17 16:05:31 -05003561 pcmd = (struct lpfc_dmabuf *) piocb->context2;
James Smart2e0fef82007-06-17 19:56:36 -05003562 if (pcmd)
3563 els_command = *(uint32_t *) (pcmd->virt);
dea31012005-04-17 16:05:31 -05003564
James Smart92d7f7b2007-06-17 19:56:38 -05003565 if (els_command == ELS_CMD_FARP ||
3566 els_command == ELS_CMD_FARPR ||
3567 els_command == ELS_CMD_FDISC)
dea31012005-04-17 16:05:31 -05003568 continue;
James Smart92d7f7b2007-06-17 19:56:38 -05003569
3570 if (vport != piocb->vport)
3571 continue;
dea31012005-04-17 16:05:31 -05003572
3573 if (piocb->drvrTimeout > 0) {
James Smart92d7f7b2007-06-17 19:56:38 -05003574 if (piocb->drvrTimeout >= timeout)
dea31012005-04-17 16:05:31 -05003575 piocb->drvrTimeout -= timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05003576 else
dea31012005-04-17 16:05:31 -05003577 piocb->drvrTimeout = 0;
dea31012005-04-17 16:05:31 -05003578 continue;
3579 }
3580
James Smart2e0fef82007-06-17 19:56:36 -05003581 remote_ID = 0xffffffff;
3582 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
dea31012005-04-17 16:05:31 -05003583 remote_ID = cmd->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05003584 else {
3585 struct lpfc_nodelist *ndlp;
3586 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
3587 if (ndlp)
3588 remote_ID = ndlp->nlp_DID;
dea31012005-04-17 16:05:31 -05003589 }
James Smarte8b62012007-08-02 11:10:09 -04003590 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3591 "0127 ELS timeout Data: x%x x%x x%x "
3592 "x%x\n", els_command,
3593 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
James Smart07951072007-04-25 09:51:38 -04003594 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05003595 }
James Smart2e0fef82007-06-17 19:56:36 -05003596 spin_unlock_irq(&phba->hbalock);
James Smart5a0e3262006-07-06 15:49:16 -04003597
James Smart2e0fef82007-06-17 19:56:36 -05003598 if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt)
3599 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
dea31012005-04-17 16:05:31 -05003600}
3601
3602void
James Smart2e0fef82007-06-17 19:56:36 -05003603lpfc_els_flush_cmd(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003604{
James Smart2534ba72007-04-25 09:52:20 -04003605 LIST_HEAD(completions);
James Smart2e0fef82007-06-17 19:56:36 -05003606 struct lpfc_hba *phba = vport->phba;
James Smart329f9bc2007-04-25 09:53:01 -04003607 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05003608 struct lpfc_iocbq *tmp_iocb, *piocb;
3609 IOCB_t *cmd = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05003610
3611 lpfc_fabric_abort_vport(vport);
dea31012005-04-17 16:05:31 -05003612
James Smart2e0fef82007-06-17 19:56:36 -05003613 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003614 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
3615 cmd = &piocb->iocb;
3616
3617 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
3618 continue;
3619 }
3620
3621 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
James Smart329f9bc2007-04-25 09:53:01 -04003622 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
3623 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
3624 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
3625 cmd->ulpCommand == CMD_ABORT_XRI_CN)
dea31012005-04-17 16:05:31 -05003626 continue;
dea31012005-04-17 16:05:31 -05003627
James Smart2e0fef82007-06-17 19:56:36 -05003628 if (piocb->vport != vport)
3629 continue;
3630
James Smart2534ba72007-04-25 09:52:20 -04003631 list_move_tail(&piocb->list, &completions);
James Smart1dcb58e2007-04-25 09:51:30 -04003632 pring->txq_cnt--;
dea31012005-04-17 16:05:31 -05003633 }
3634
3635 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
dea31012005-04-17 16:05:31 -05003636 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
3637 continue;
3638 }
dea31012005-04-17 16:05:31 -05003639
James Smart2e0fef82007-06-17 19:56:36 -05003640 if (piocb->vport != vport)
3641 continue;
3642
James Smart07951072007-04-25 09:51:38 -04003643 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05003644 }
James Smart2e0fef82007-06-17 19:56:36 -05003645 spin_unlock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04003646
James Smart2e0fef82007-06-17 19:56:36 -05003647 while (!list_empty(&completions)) {
James Smart2534ba72007-04-25 09:52:20 -04003648 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
3649 cmd = &piocb->iocb;
James Smart92d7f7b2007-06-17 19:56:38 -05003650 list_del_init(&piocb->list);
James Smart2534ba72007-04-25 09:52:20 -04003651
James Smart2e0fef82007-06-17 19:56:36 -05003652 if (!piocb->iocb_cmpl)
3653 lpfc_sli_release_iocbq(phba, piocb);
3654 else {
James Smart2534ba72007-04-25 09:52:20 -04003655 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
3656 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
3657 (piocb->iocb_cmpl) (phba, piocb, piocb);
James Smart2e0fef82007-06-17 19:56:36 -05003658 }
James Smart2534ba72007-04-25 09:52:20 -04003659 }
3660
dea31012005-04-17 16:05:31 -05003661 return;
3662}
3663
James Smart549e55c2007-08-02 11:09:51 -04003664void
3665lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
3666{
3667 LIST_HEAD(completions);
3668 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
3669 struct lpfc_iocbq *tmp_iocb, *piocb;
3670 IOCB_t *cmd = NULL;
3671
3672 lpfc_fabric_abort_hba(phba);
3673 spin_lock_irq(&phba->hbalock);
3674 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
3675 cmd = &piocb->iocb;
3676 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
3677 continue;
3678 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
3679 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
3680 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
3681 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
3682 cmd->ulpCommand == CMD_ABORT_XRI_CN)
3683 continue;
3684 list_move_tail(&piocb->list, &completions);
3685 pring->txq_cnt--;
3686 }
3687 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
3688 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
3689 continue;
3690 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
3691 }
3692 spin_unlock_irq(&phba->hbalock);
3693 while (!list_empty(&completions)) {
3694 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
3695 cmd = &piocb->iocb;
3696 list_del_init(&piocb->list);
3697 if (!piocb->iocb_cmpl)
3698 lpfc_sli_release_iocbq(phba, piocb);
3699 else {
3700 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
3701 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
3702 (piocb->iocb_cmpl) (phba, piocb, piocb);
3703 }
3704 }
3705 return;
3706}
3707
James Smarted957682007-06-17 19:56:37 -05003708static void
3709lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
James Smart92d7f7b2007-06-17 19:56:38 -05003710 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05003711{
dea31012005-04-17 16:05:31 -05003712 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05003713 struct ls_rjt stat;
James Smart92d7f7b2007-06-17 19:56:38 -05003714 uint32_t *payload;
James Smart2e0fef82007-06-17 19:56:36 -05003715 uint32_t cmd, did, newnode, rjt_err = 0;
James Smarted957682007-06-17 19:56:37 -05003716 IOCB_t *icmd = &elsiocb->iocb;
dea31012005-04-17 16:05:31 -05003717
James Smart92d7f7b2007-06-17 19:56:38 -05003718 if (vport == NULL || elsiocb->context2 == NULL)
dea31012005-04-17 16:05:31 -05003719 goto dropit;
James Smart2e0fef82007-06-17 19:56:36 -05003720
dea31012005-04-17 16:05:31 -05003721 newnode = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05003722 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
3723 cmd = *payload;
James Smarted957682007-06-17 19:56:37 -05003724 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
3725 lpfc_post_buffer(phba, pring, 1, 1);
dea31012005-04-17 16:05:31 -05003726
James Smart858c9f62007-06-17 19:56:39 -05003727 did = icmd->un.rcvels.remoteID;
3728 if (icmd->ulpStatus) {
3729 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3730 "RCV Unsol ELS: status:x%x/x%x did:x%x",
3731 icmd->ulpStatus, icmd->un.ulpWord[4], did);
dea31012005-04-17 16:05:31 -05003732 goto dropit;
James Smart858c9f62007-06-17 19:56:39 -05003733 }
dea31012005-04-17 16:05:31 -05003734
3735 /* Check to see if link went down during discovery */
James Smarted957682007-06-17 19:56:37 -05003736 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05003737 goto dropit;
dea31012005-04-17 16:05:31 -05003738
James Smart92d7f7b2007-06-17 19:56:38 -05003739 /* Ignore traffic recevied during vport shutdown. */
3740 if (vport->load_flag & FC_UNLOADING)
3741 goto dropit;
3742
James Smart2e0fef82007-06-17 19:56:36 -05003743 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003744 if (!ndlp) {
dea31012005-04-17 16:05:31 -05003745 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003746 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
James Smarted957682007-06-17 19:56:37 -05003747 if (!ndlp)
dea31012005-04-17 16:05:31 -05003748 goto dropit;
dea31012005-04-17 16:05:31 -05003749
James Smart2e0fef82007-06-17 19:56:36 -05003750 lpfc_nlp_init(vport, ndlp, did);
dea31012005-04-17 16:05:31 -05003751 newnode = 1;
3752 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) {
3753 ndlp->nlp_type |= NLP_FABRIC;
3754 }
James Smart2e0fef82007-06-17 19:56:36 -05003755 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE);
dea31012005-04-17 16:05:31 -05003756 }
3757
3758 phba->fc_stat.elsRcvFrame++;
James Smart329f9bc2007-04-25 09:53:01 -04003759 if (elsiocb->context1)
3760 lpfc_nlp_put(elsiocb->context1);
3761 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05003762 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -05003763
3764 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
3765 cmd &= ELS_CMD_MASK;
3766 }
3767 /* ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04003768 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3769 "0112 ELS command x%x received from NPORT x%x "
3770 "Data: x%x\n", cmd, did, vport->port_state);
dea31012005-04-17 16:05:31 -05003771 switch (cmd) {
3772 case ELS_CMD_PLOGI:
James Smart858c9f62007-06-17 19:56:39 -05003773 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3774 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
3775 did, vport->port_state, ndlp->nlp_flag);
3776
dea31012005-04-17 16:05:31 -05003777 phba->fc_stat.elsRcvPLOGI++;
James Smart858c9f62007-06-17 19:56:39 -05003778 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
3779
3780 if (vport->port_state < LPFC_DISC_AUTH) {
3781 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05003782 break;
3783 }
James Smart2e0fef82007-06-17 19:56:36 -05003784 lpfc_disc_state_machine(vport, ndlp, elsiocb,
3785 NLP_EVT_RCV_PLOGI);
James Smart858c9f62007-06-17 19:56:39 -05003786
dea31012005-04-17 16:05:31 -05003787 break;
3788 case ELS_CMD_FLOGI:
James Smart858c9f62007-06-17 19:56:39 -05003789 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3790 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
3791 did, vport->port_state, ndlp->nlp_flag);
3792
dea31012005-04-17 16:05:31 -05003793 phba->fc_stat.elsRcvFLOGI++;
James Smart2e0fef82007-06-17 19:56:36 -05003794 lpfc_els_rcv_flogi(vport, elsiocb, ndlp, newnode);
James Smartde0c5b32007-04-25 09:52:27 -04003795 if (newnode)
James Smart2e0fef82007-06-17 19:56:36 -05003796 lpfc_drop_node(vport, ndlp);
dea31012005-04-17 16:05:31 -05003797 break;
3798 case ELS_CMD_LOGO:
James Smart858c9f62007-06-17 19:56:39 -05003799 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3800 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
3801 did, vport->port_state, ndlp->nlp_flag);
3802
dea31012005-04-17 16:05:31 -05003803 phba->fc_stat.elsRcvLOGO++;
James Smart2e0fef82007-06-17 19:56:36 -05003804 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05003805 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05003806 break;
3807 }
James Smart2e0fef82007-06-17 19:56:36 -05003808 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
dea31012005-04-17 16:05:31 -05003809 break;
3810 case ELS_CMD_PRLO:
James Smart858c9f62007-06-17 19:56:39 -05003811 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3812 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
3813 did, vport->port_state, ndlp->nlp_flag);
3814
dea31012005-04-17 16:05:31 -05003815 phba->fc_stat.elsRcvPRLO++;
James Smart2e0fef82007-06-17 19:56:36 -05003816 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05003817 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05003818 break;
3819 }
James Smart2e0fef82007-06-17 19:56:36 -05003820 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
dea31012005-04-17 16:05:31 -05003821 break;
3822 case ELS_CMD_RSCN:
3823 phba->fc_stat.elsRcvRSCN++;
James Smart2e0fef82007-06-17 19:56:36 -05003824 lpfc_els_rcv_rscn(vport, elsiocb, ndlp, newnode);
James Smartde0c5b32007-04-25 09:52:27 -04003825 if (newnode)
James Smart2e0fef82007-06-17 19:56:36 -05003826 lpfc_drop_node(vport, ndlp);
dea31012005-04-17 16:05:31 -05003827 break;
3828 case ELS_CMD_ADISC:
James Smart858c9f62007-06-17 19:56:39 -05003829 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3830 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
3831 did, vport->port_state, ndlp->nlp_flag);
3832
dea31012005-04-17 16:05:31 -05003833 phba->fc_stat.elsRcvADISC++;
James Smart2e0fef82007-06-17 19:56:36 -05003834 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05003835 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05003836 break;
3837 }
James Smart2e0fef82007-06-17 19:56:36 -05003838 lpfc_disc_state_machine(vport, ndlp, elsiocb,
3839 NLP_EVT_RCV_ADISC);
dea31012005-04-17 16:05:31 -05003840 break;
3841 case ELS_CMD_PDISC:
James Smart858c9f62007-06-17 19:56:39 -05003842 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3843 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
3844 did, vport->port_state, ndlp->nlp_flag);
3845
dea31012005-04-17 16:05:31 -05003846 phba->fc_stat.elsRcvPDISC++;
James Smart2e0fef82007-06-17 19:56:36 -05003847 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05003848 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05003849 break;
3850 }
James Smart2e0fef82007-06-17 19:56:36 -05003851 lpfc_disc_state_machine(vport, ndlp, elsiocb,
3852 NLP_EVT_RCV_PDISC);
dea31012005-04-17 16:05:31 -05003853 break;
3854 case ELS_CMD_FARPR:
James Smart858c9f62007-06-17 19:56:39 -05003855 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3856 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
3857 did, vport->port_state, ndlp->nlp_flag);
3858
dea31012005-04-17 16:05:31 -05003859 phba->fc_stat.elsRcvFARPR++;
James Smart2e0fef82007-06-17 19:56:36 -05003860 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05003861 break;
3862 case ELS_CMD_FARP:
James Smart858c9f62007-06-17 19:56:39 -05003863 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3864 "RCV FARP: did:x%x/ste:x%x flg:x%x",
3865 did, vport->port_state, ndlp->nlp_flag);
3866
dea31012005-04-17 16:05:31 -05003867 phba->fc_stat.elsRcvFARP++;
James Smart2e0fef82007-06-17 19:56:36 -05003868 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05003869 break;
3870 case ELS_CMD_FAN:
James Smart858c9f62007-06-17 19:56:39 -05003871 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3872 "RCV FAN: did:x%x/ste:x%x flg:x%x",
3873 did, vport->port_state, ndlp->nlp_flag);
3874
dea31012005-04-17 16:05:31 -05003875 phba->fc_stat.elsRcvFAN++;
James Smart2e0fef82007-06-17 19:56:36 -05003876 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05003877 break;
dea31012005-04-17 16:05:31 -05003878 case ELS_CMD_PRLI:
James Smart858c9f62007-06-17 19:56:39 -05003879 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3880 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
3881 did, vport->port_state, ndlp->nlp_flag);
3882
dea31012005-04-17 16:05:31 -05003883 phba->fc_stat.elsRcvPRLI++;
James Smart2e0fef82007-06-17 19:56:36 -05003884 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05003885 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05003886 break;
3887 }
James Smart2e0fef82007-06-17 19:56:36 -05003888 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
dea31012005-04-17 16:05:31 -05003889 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003890 case ELS_CMD_LIRR:
James Smart858c9f62007-06-17 19:56:39 -05003891 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3892 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
3893 did, vport->port_state, ndlp->nlp_flag);
3894
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003895 phba->fc_stat.elsRcvLIRR++;
James Smart2e0fef82007-06-17 19:56:36 -05003896 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04003897 if (newnode)
James Smart2e0fef82007-06-17 19:56:36 -05003898 lpfc_drop_node(vport, ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003899 break;
3900 case ELS_CMD_RPS:
James Smart858c9f62007-06-17 19:56:39 -05003901 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3902 "RCV RPS: did:x%x/ste:x%x flg:x%x",
3903 did, vport->port_state, ndlp->nlp_flag);
3904
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003905 phba->fc_stat.elsRcvRPS++;
James Smart2e0fef82007-06-17 19:56:36 -05003906 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04003907 if (newnode)
James Smart2e0fef82007-06-17 19:56:36 -05003908 lpfc_drop_node(vport, ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003909 break;
3910 case ELS_CMD_RPL:
James Smart858c9f62007-06-17 19:56:39 -05003911 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3912 "RCV RPL: did:x%x/ste:x%x flg:x%x",
3913 did, vport->port_state, ndlp->nlp_flag);
3914
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003915 phba->fc_stat.elsRcvRPL++;
James Smart2e0fef82007-06-17 19:56:36 -05003916 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04003917 if (newnode)
James Smart2e0fef82007-06-17 19:56:36 -05003918 lpfc_drop_node(vport, ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003919 break;
dea31012005-04-17 16:05:31 -05003920 case ELS_CMD_RNID:
James Smart858c9f62007-06-17 19:56:39 -05003921 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3922 "RCV RNID: did:x%x/ste:x%x flg:x%x",
3923 did, vport->port_state, ndlp->nlp_flag);
3924
dea31012005-04-17 16:05:31 -05003925 phba->fc_stat.elsRcvRNID++;
James Smart2e0fef82007-06-17 19:56:36 -05003926 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04003927 if (newnode)
James Smart2e0fef82007-06-17 19:56:36 -05003928 lpfc_drop_node(vport, ndlp);
dea31012005-04-17 16:05:31 -05003929 break;
3930 default:
James Smart858c9f62007-06-17 19:56:39 -05003931 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3932 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
3933 cmd, did, vport->port_state);
3934
dea31012005-04-17 16:05:31 -05003935 /* Unsupported ELS command, reject */
James Smart858c9f62007-06-17 19:56:39 -05003936 rjt_err = LSRJT_INVALID_CMD;
dea31012005-04-17 16:05:31 -05003937
3938 /* Unknown ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04003939 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3940 "0115 Unknown ELS command x%x "
3941 "received from NPORT x%x\n", cmd, did);
James Smartde0c5b32007-04-25 09:52:27 -04003942 if (newnode)
James Smart2e0fef82007-06-17 19:56:36 -05003943 lpfc_drop_node(vport, ndlp);
dea31012005-04-17 16:05:31 -05003944 break;
3945 }
3946
3947 /* check if need to LS_RJT received ELS cmd */
3948 if (rjt_err) {
James Smart92d7f7b2007-06-17 19:56:38 -05003949 memset(&stat, 0, sizeof(stat));
James Smart858c9f62007-06-17 19:56:39 -05003950 stat.un.b.lsRjtRsnCode = rjt_err;
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04003951 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart858c9f62007-06-17 19:56:39 -05003952 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
3953 NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05003954 if (newnode)
3955 lpfc_drop_node(vport, ndlp);
dea31012005-04-17 16:05:31 -05003956 }
3957
James Smarted957682007-06-17 19:56:37 -05003958 return;
3959
3960dropit:
3961 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
James Smarte8b62012007-08-02 11:10:09 -04003962 "(%d):0111 Dropping received ELS cmd "
James Smarted957682007-06-17 19:56:37 -05003963 "Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04003964 vport ? vport->vpi : 0xffff, icmd->ulpStatus,
3965 icmd->un.ulpWord[4], icmd->ulpTimeout);
James Smarted957682007-06-17 19:56:37 -05003966 phba->fc_stat.elsRcvDrop++;
3967}
3968
James Smart92d7f7b2007-06-17 19:56:38 -05003969static struct lpfc_vport *
3970lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
3971{
3972 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -04003973 unsigned long flags;
James Smart92d7f7b2007-06-17 19:56:38 -05003974
James Smart549e55c2007-08-02 11:09:51 -04003975 spin_lock_irqsave(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05003976 list_for_each_entry(vport, &phba->port_list, listentry) {
James Smart549e55c2007-08-02 11:09:51 -04003977 if (vport->vpi == vpi) {
3978 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05003979 return vport;
James Smart549e55c2007-08-02 11:09:51 -04003980 }
James Smart92d7f7b2007-06-17 19:56:38 -05003981 }
James Smart549e55c2007-08-02 11:09:51 -04003982 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05003983 return NULL;
3984}
James Smarted957682007-06-17 19:56:37 -05003985
3986void
3987lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3988 struct lpfc_iocbq *elsiocb)
3989{
3990 struct lpfc_vport *vport = phba->pport;
James Smarted957682007-06-17 19:56:37 -05003991 IOCB_t *icmd = &elsiocb->iocb;
James Smarted957682007-06-17 19:56:37 -05003992 dma_addr_t paddr;
James Smart92d7f7b2007-06-17 19:56:38 -05003993 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
3994 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
James Smarted957682007-06-17 19:56:37 -05003995
James Smart92d7f7b2007-06-17 19:56:38 -05003996 elsiocb->context2 = NULL;
3997 elsiocb->context3 = NULL;
3998
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) {
James Smarted957682007-06-17 19:56:37 -05004003 phba->fc_stat.NoRcvBuf++;
4004 /* Not enough posted buffers; Try posting more buffers */
James Smart92d7f7b2007-06-17 19:56:38 -05004005 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
James Smarted957682007-06-17 19:56:37 -05004006 lpfc_post_buffer(phba, pring, 0, 1);
4007 return;
4008 }
4009
James Smart92d7f7b2007-06-17 19:56:38 -05004010 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;
4015 else {
4016 uint16_t vpi = icmd->unsli3.rcvsli3.vpi;
4017 vport = lpfc_find_vport_by_vpid(phba, vpi);
4018 }
4019 }
4020 /* If there are no BDEs associated
4021 * with this IOCB, there is nothing to do.
4022 */
James Smarted957682007-06-17 19:56:37 -05004023 if (icmd->ulpBdeCount == 0)
4024 return;
4025
James Smart92d7f7b2007-06-17 19:56:38 -05004026 /* type of ELS cmd is first 32bit word
4027 * in packet
4028 */
James Smarted957682007-06-17 19:56:37 -05004029 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05004030 elsiocb->context2 = bdeBuf1;
James Smarted957682007-06-17 19:56:37 -05004031 } else {
4032 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
4033 icmd->un.cont64[0].addrLow);
James Smart92d7f7b2007-06-17 19:56:38 -05004034 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
4035 paddr);
James Smarted957682007-06-17 19:56:37 -05004036 }
4037
James Smart92d7f7b2007-06-17 19:56:38 -05004038 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
4039 /*
4040 * The different unsolicited event handlers would tell us
4041 * if they are done with "mp" by setting context2 to NULL.
4042 */
James Smart329f9bc2007-04-25 09:53:01 -04004043 lpfc_nlp_put(elsiocb->context1);
4044 elsiocb->context1 = NULL;
dea31012005-04-17 16:05:31 -05004045 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05004046 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
4047 elsiocb->context2 = NULL;
dea31012005-04-17 16:05:31 -05004048 }
James Smarted957682007-06-17 19:56:37 -05004049
4050 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
James Smart92d7f7b2007-06-17 19:56:38 -05004051 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
James Smarted957682007-06-17 19:56:37 -05004052 icmd->ulpBdeCount == 2) {
James Smart92d7f7b2007-06-17 19:56:38 -05004053 elsiocb->context2 = bdeBuf2;
4054 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
James Smarted957682007-06-17 19:56:37 -05004055 /* free mp if we are done with it */
4056 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05004057 lpfc_in_buf_free(phba, elsiocb->context2);
4058 elsiocb->context2 = NULL;
James Smarted957682007-06-17 19:56:37 -05004059 }
dea31012005-04-17 16:05:31 -05004060 }
dea31012005-04-17 16:05:31 -05004061}
James Smart92d7f7b2007-06-17 19:56:38 -05004062
4063void
4064lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
4065{
4066 struct lpfc_nodelist *ndlp, *ndlp_fdmi;
4067
4068 ndlp = lpfc_findnode_did(vport, NameServer_DID);
4069 if (!ndlp) {
4070 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
4071 if (!ndlp) {
4072 if (phba->fc_topology == TOPOLOGY_LOOP) {
4073 lpfc_disc_start(vport);
4074 return;
4075 }
4076 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04004077 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4078 "0251 NameServer login: no memory\n");
James Smart92d7f7b2007-06-17 19:56:38 -05004079 return;
4080 }
4081 lpfc_nlp_init(vport, ndlp, NameServer_DID);
4082 ndlp->nlp_type |= NLP_FABRIC;
4083 }
4084
4085 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
4086
4087 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
4088 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04004089 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4090 "0252 Cannot issue NameServer login\n");
James Smart92d7f7b2007-06-17 19:56:38 -05004091 return;
4092 }
4093
James Smart3de2a652007-08-02 11:09:59 -04004094 if (vport->cfg_fdmi_on) {
James Smart92d7f7b2007-06-17 19:56:38 -05004095 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
4096 GFP_KERNEL);
4097 if (ndlp_fdmi) {
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,
4103 0);
4104 }
4105 }
4106 return;
4107}
4108
4109static void
4110lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4111{
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;
4116
4117 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
4118 lpfc_nlp_put(ndlp);
4119
4120 if (mb->mbxStatus) {
James Smarte8b62012007-08-02 11:10:09 -04004121 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
4122 "0915 Register VPI failed: 0x%x\n",
4123 mb->mbxStatus);
James Smart92d7f7b2007-06-17 19:56:38 -05004124
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);
4134 break;
4135 default:
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);
4140 break;
4141 }
4142
4143 } else {
4144 if (vport == phba->pport)
4145 lpfc_issue_fabric_reglogin(vport);
4146 else
4147 lpfc_do_scr_ns_plogi(phba, vport);
4148 }
4149 mempool_free(pmb, phba->mbox_mem_pool);
4150 return;
4151}
4152
4153void
4154lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
4155 struct lpfc_nodelist *ndlp)
4156{
4157 LPFC_MBOXQ_t *mbox;
4158
4159 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4160 if (mbox) {
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;
4170
4171 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04004172 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
4173 "0253 Register VPI: Can't send mbox\n");
James Smart92d7f7b2007-06-17 19:56:38 -05004174 }
4175 } else {
4176 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4177
James Smarte8b62012007-08-02 11:10:09 -04004178 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
4179 "0254 Register VPI: no memory\n");
James Smart92d7f7b2007-06-17 19:56:38 -05004180
4181 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
4182 lpfc_nlp_put(ndlp);
4183 }
4184}
4185
4186static void
4187lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4188 struct lpfc_iocbq *rspiocb)
4189{
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;
4197
James Smarte8b62012007-08-02 11:10:09 -04004198 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],
4201 vport->fc_prevDID);
James Smart92d7f7b2007-06-17 19:56:38 -05004202 /* 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.
4205 */
4206 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
4207 lpfc_set_disctmo(piocb->vport);
4208 }
4209
James Smart858c9f62007-06-17 19:56:39 -05004210 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);
4213
James Smart92d7f7b2007-06-17 19:56:38 -05004214 if (irsp->ulpStatus) {
4215 /* Check for retry */
4216 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
4217 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05004218 /* FDISC failed */
James Smarte8b62012007-08-02 11:10:09 -04004219 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4220 "0124 FDISC failed. (%d/%d)\n",
4221 irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smart92d7f7b2007-06-17 19:56:38 -05004222 if (vport->fc_vport->vport_state == FC_VPORT_INITIALIZING)
4223 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4224
4225 lpfc_nlp_put(ndlp);
4226 /* giving up on FDISC. Cancel discovery timer */
4227 lpfc_can_disctmo(vport);
4228 } else {
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);
4234
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
4241 * issue unreg_vpi.
4242 */
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))
4247 continue;
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);
4252 }
4253 lpfc_mbx_unreg_vpi(vport);
4254 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
4255 }
4256
4257 if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
4258 lpfc_register_new_vport(phba, vport, ndlp);
4259 else
4260 lpfc_do_scr_ns_plogi(phba, vport);
4261
4262 lpfc_nlp_put(ndlp); /* Free Fabric ndlp for vports */
4263 }
4264
4265out:
4266 lpfc_els_free_iocb(phba, cmdiocb);
4267}
4268
4269int
4270lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4271 uint8_t retry)
4272{
4273 struct lpfc_hba *phba = vport->phba;
4274 IOCB_t *icmd;
4275 struct lpfc_iocbq *elsiocb;
4276 struct serv_parm *sp;
4277 uint8_t *pcmd;
4278 uint16_t cmdsize;
4279 int did = ndlp->nlp_DID;
4280 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05004281
4282 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
4283 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
4284 ELS_CMD_FDISC);
4285 if (!elsiocb) {
James Smart92d7f7b2007-06-17 19:56:38 -05004286 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04004287 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4288 "0255 Issue FDISC: no IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05004289 return 1;
4290 }
4291
4292 icmd = &elsiocb->iocb;
4293 icmd->un.elsreq64.myID = 0;
4294 icmd->un.elsreq64.fl = 1;
4295
4296 /* For FDISC, Let FDISC rsp set the NPortID for this VPI */
4297 icmd->ulpCt_h = 1;
4298 icmd->ulpCt_l = 0;
4299
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;
4311
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);
4320
4321 lpfc_set_disctmo(vport);
4322
4323 phba->fc_stat.elsXmitFDISC++;
4324 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
4325
James Smart858c9f62007-06-17 19:56:39 -05004326 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4327 "Issue FDISC: did:x%x",
4328 did, 0, 0);
4329
James Smart92d7f7b2007-06-17 19:56:38 -05004330 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
4331 if (rc == IOCB_ERROR) {
4332 lpfc_els_free_iocb(phba, elsiocb);
James Smart92d7f7b2007-06-17 19:56:38 -05004333 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04004334 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4335 "0256 Issue FDISC: Cannot send IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05004336 return 1;
4337 }
4338 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
4339 vport->port_state = LPFC_FDISC;
4340 return 0;
4341}
4342
4343static void
4344lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4345 struct lpfc_iocbq *rspiocb)
4346{
4347 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05004348 IOCB_t *irsp;
4349
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);
James Smart92d7f7b2007-06-17 19:56:38 -05004354
4355 lpfc_els_free_iocb(phba, cmdiocb);
4356 vport->unreg_vpi_cmpl = VPORT_ERROR;
4357}
4358
4359int
4360lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4361{
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];
4365 IOCB_t *icmd;
4366 struct lpfc_iocbq *elsiocb;
4367 uint8_t *pcmd;
4368 uint16_t cmdsize;
4369
4370 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
4371 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
4372 ELS_CMD_LOGO);
4373 if (!elsiocb)
4374 return 1;
4375
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);
4380
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));
4385
James Smart858c9f62007-06-17 19:56:39 -05004386 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);
4389
James Smart92d7f7b2007-06-17 19:56:38 -05004390 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);
4399 return 1;
4400 }
4401 return 0;
4402}
4403
4404void
4405lpfc_fabric_block_timeout(unsigned long ptr)
4406{
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;
4412 if (!tmo_posted)
4413 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
4414 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
4415
4416 if (!tmo_posted) {
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);
4421 }
4422}
4423
4424static void
4425lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
4426{
4427 struct lpfc_iocbq *iocb;
4428 unsigned long iflags;
4429 int ret;
4430 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
4431 IOCB_t *cmd;
4432
4433repeat:
4434 iocb = NULL;
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),
4439 list);
4440 if (iocb)
4441 atomic_inc(&phba->fabric_iocb_count);
4442 }
4443 spin_unlock_irqrestore(&phba->hbalock, iflags);
4444 if (iocb) {
4445 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
4446 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
4447 iocb->iocb_flag |= LPFC_IO_FABRIC;
4448
James Smart858c9f62007-06-17 19:56:39 -05004449 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
4450 "Fabric sched1: ste:x%x",
4451 iocb->vport->port_state, 0, 0);
4452
James Smart92d7f7b2007-06-17 19:56:38 -05004453 ret = lpfc_sli_issue_iocb(phba, pring, iocb, 0);
4454
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;
4459 cmd = &iocb->iocb;
4460 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
4461 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
4462 iocb->iocb_cmpl(phba, iocb, iocb);
4463
4464 atomic_dec(&phba->fabric_iocb_count);
4465 goto repeat;
4466 }
4467 }
4468
4469 return;
4470}
4471
4472void
4473lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
4474{
4475 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
4476
4477 lpfc_resume_fabric_iocbs(phba);
4478 return;
4479}
4480
4481static void
4482lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
4483{
4484 int blocked;
4485
4486 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
4487 /* Start a timer to unblock fabric
4488 * iocbs after 100ms
4489 */
4490 if (!blocked)
4491 mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 );
4492
4493 return;
4494}
4495
4496static void
4497lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4498 struct lpfc_iocbq *rspiocb)
4499{
4500 struct ls_rjt stat;
4501
4502 if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
4503 BUG();
4504
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);
4510 }
4511 break;
4512
4513 case IOSTAT_NPORT_BSY:
4514 case IOSTAT_FABRIC_BSY:
4515 lpfc_block_fabric_iocbs(phba);
4516 break;
4517
4518 case IOSTAT_LS_RJT:
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);
4524 break;
4525 }
4526
4527 if (atomic_read(&phba->fabric_iocb_count) == 0)
4528 BUG();
4529
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);
4534
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);
4539 }
4540}
4541
4542int
4543lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
4544{
4545 unsigned long iflags;
4546 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
4547 int ready;
4548 int ret;
4549
4550 if (atomic_read(&phba->fabric_iocb_count) > 1)
4551 BUG();
4552
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);
4556
4557 spin_unlock_irqrestore(&phba->hbalock, iflags);
4558 if (ready) {
4559 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
4560 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
4561 iocb->iocb_flag |= LPFC_IO_FABRIC;
4562
James Smart858c9f62007-06-17 19:56:39 -05004563 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
4564 "Fabric sched2: ste:x%x",
4565 iocb->vport->port_state, 0, 0);
4566
James Smart92d7f7b2007-06-17 19:56:38 -05004567 atomic_inc(&phba->fabric_iocb_count);
4568 ret = lpfc_sli_issue_iocb(phba, pring, iocb, 0);
4569
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);
4575 }
4576 } else {
4577 spin_lock_irqsave(&phba->hbalock, iflags);
4578 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
4579 spin_unlock_irqrestore(&phba->hbalock, iflags);
4580 ret = IOCB_SUCCESS;
4581 }
4582 return ret;
4583}
4584
4585
4586void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
4587{
4588 LIST_HEAD(completions);
4589 struct lpfc_hba *phba = vport->phba;
4590 struct lpfc_iocbq *tmp_iocb, *piocb;
4591 IOCB_t *cmd;
4592
4593 spin_lock_irq(&phba->hbalock);
4594 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
4595 list) {
4596
4597 if (piocb->vport != vport)
4598 continue;
4599
4600 list_move_tail(&piocb->list, &completions);
4601 }
4602 spin_unlock_irq(&phba->hbalock);
4603
4604 while (!list_empty(&completions)) {
4605 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
4606 list_del_init(&piocb->list);
4607
4608 cmd = &piocb->iocb;
4609 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
4610 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
4611 (piocb->iocb_cmpl) (phba, piocb, piocb);
4612 }
4613}
4614
4615void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
4616{
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];
4621 IOCB_t *cmd;
4622
4623 spin_lock_irq(&phba->hbalock);
4624 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
4625 list) {
4626 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
4627
4628 list_move_tail(&piocb->list, &completions);
4629 }
4630 }
4631 spin_unlock_irq(&phba->hbalock);
4632
4633 while (!list_empty(&completions)) {
4634 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
4635 list_del_init(&piocb->list);
4636
4637 cmd = &piocb->iocb;
4638 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
4639 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
4640 (piocb->iocb_cmpl) (phba, piocb, piocb);
4641 }
4642}
4643
4644void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
4645{
4646 LIST_HEAD(completions);
4647 struct lpfc_iocbq *piocb;
4648 IOCB_t *cmd;
4649
4650 spin_lock_irq(&phba->hbalock);
4651 list_splice_init(&phba->fabric_iocb_list, &completions);
4652 spin_unlock_irq(&phba->hbalock);
4653
4654 while (!list_empty(&completions)) {
4655 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
4656 list_del_init(&piocb->list);
4657
4658 cmd = &piocb->iocb;
4659 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
4660 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
4661 (piocb->iocb_cmpl) (phba, piocb, piocb);
4662 }
4663}
4664
4665
4666void lpfc_fabric_abort_flogi(struct lpfc_hba *phba)
4667{
4668 LIST_HEAD(completions);
4669 struct lpfc_iocbq *tmp_iocb, *piocb;
4670 IOCB_t *cmd;
4671 struct lpfc_nodelist *ndlp;
4672
4673 spin_lock_irq(&phba->hbalock);
4674 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
4675 list) {
4676
4677 cmd = &piocb->iocb;
4678 ndlp = (struct lpfc_nodelist *) piocb->context1;
4679 if (cmd->ulpCommand == CMD_ELS_REQUEST64_CR &&
4680 ndlp != NULL &&
4681 ndlp->nlp_DID == Fabric_DID)
4682 list_move_tail(&piocb->list, &completions);
4683 }
4684 spin_unlock_irq(&phba->hbalock);
4685
4686 while (!list_empty(&completions)) {
4687 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
4688 list_del_init(&piocb->list);
4689
4690 cmd = &piocb->iocb;
4691 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
4692 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
4693 (piocb->iocb_cmpl) (phba, piocb, piocb);
4694 }
4695}
4696
4697