blob: b73612d4fc53872e5c303ba2e03ecc4838445768 [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
James Smart51ef4c22007-08-02 11:10:31 -0400199 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart329f9bc2007-04-25 09:53:01 -0400200 elsiocb->context2 = pcmd;
201 elsiocb->context3 = pbuflist;
dea31012005-04-17 16:05:31 -0500202 elsiocb->retry = retry;
James Smart2e0fef82007-06-17 19:56:36 -0500203 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -0500204 elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
205
206 if (prsp) {
207 list_add(&prsp->list, &pcmd->list);
208 }
dea31012005-04-17 16:05:31 -0500209 if (expectRsp) {
210 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400211 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
212 "0116 Xmit ELS command x%x to remote "
213 "NPORT x%x I/O tag: x%x, port state: x%x\n",
214 elscmd, did, elsiocb->iotag,
215 vport->port_state);
dea31012005-04-17 16:05:31 -0500216 } else {
217 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400218 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
219 "0117 Xmit ELS response x%x to remote "
220 "NPORT x%x I/O tag: x%x, size: x%x\n",
221 elscmd, ndlp->nlp_DID, elsiocb->iotag,
222 cmdSize);
dea31012005-04-17 16:05:31 -0500223 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500224 return elsiocb;
dea31012005-04-17 16:05:31 -0500225}
226
227
228static int
James Smart92d7f7b2007-06-17 19:56:38 -0500229lpfc_issue_fabric_reglogin(struct lpfc_vport *vport)
230{
231 struct lpfc_hba *phba = vport->phba;
232 LPFC_MBOXQ_t *mbox;
233 struct lpfc_dmabuf *mp;
234 struct lpfc_nodelist *ndlp;
235 struct serv_parm *sp;
236 int rc;
237
238 sp = &phba->fc_fabparam;
239 ndlp = lpfc_findnode_did(vport, Fabric_DID);
240 if (!ndlp)
241 goto fail;
242
243 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
244 if (!mbox)
245 goto fail;
246
247 vport->port_state = LPFC_FABRIC_CFG_LINK;
248 lpfc_config_link(phba, mbox);
249 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
250 mbox->vport = vport;
251
James Smart0b727fe2007-10-27 13:37:25 -0400252 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart92d7f7b2007-06-17 19:56:38 -0500253 if (rc == MBX_NOT_FINISHED)
254 goto fail_free_mbox;
255
256 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
257 if (!mbox)
258 goto fail;
259 rc = lpfc_reg_login(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox,
260 0);
261 if (rc)
262 goto fail_free_mbox;
263
264 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
265 mbox->vport = vport;
266 mbox->context2 = lpfc_nlp_get(ndlp);
267
James Smart0b727fe2007-10-27 13:37:25 -0400268 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart92d7f7b2007-06-17 19:56:38 -0500269 if (rc == MBX_NOT_FINISHED)
270 goto fail_issue_reg_login;
271
272 return 0;
273
274fail_issue_reg_login:
275 lpfc_nlp_put(ndlp);
276 mp = (struct lpfc_dmabuf *) mbox->context1;
277 lpfc_mbuf_free(phba, mp->virt, mp->phys);
278 kfree(mp);
279fail_free_mbox:
280 mempool_free(mbox, phba->mbox_mem_pool);
281
282fail:
283 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -0400284 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
285 "0249 Cannot issue Register Fabric login\n");
James Smart92d7f7b2007-06-17 19:56:38 -0500286 return -ENXIO;
287}
288
289static int
James Smart2e0fef82007-06-17 19:56:36 -0500290lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
291 struct serv_parm *sp, IOCB_t *irsp)
dea31012005-04-17 16:05:31 -0500292{
James Smart2e0fef82007-06-17 19:56:36 -0500293 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
294 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -0500295 struct lpfc_nodelist *np;
296 struct lpfc_nodelist *next_np;
dea31012005-04-17 16:05:31 -0500297
James Smart2e0fef82007-06-17 19:56:36 -0500298 spin_lock_irq(shost->host_lock);
299 vport->fc_flag |= FC_FABRIC;
300 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500301
302 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
303 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
304 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
305
306 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
307
308 if (phba->fc_topology == TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500309 spin_lock_irq(shost->host_lock);
310 vport->fc_flag |= FC_PUBLIC_LOOP;
311 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500312 } else {
313 /*
314 * If we are a N-port connected to a Fabric, fixup sparam's so
315 * logins to devices on remote loops work.
316 */
James Smart2e0fef82007-06-17 19:56:36 -0500317 vport->fc_sparam.cmn.altBbCredit = 1;
dea31012005-04-17 16:05:31 -0500318 }
319
James Smart2e0fef82007-06-17 19:56:36 -0500320 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
dea31012005-04-17 16:05:31 -0500321 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
James Smart92d7f7b2007-06-17 19:56:38 -0500322 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500323 ndlp->nlp_class_sup = 0;
324 if (sp->cls1.classValid)
325 ndlp->nlp_class_sup |= FC_COS_CLASS1;
326 if (sp->cls2.classValid)
327 ndlp->nlp_class_sup |= FC_COS_CLASS2;
328 if (sp->cls3.classValid)
329 ndlp->nlp_class_sup |= FC_COS_CLASS3;
330 if (sp->cls4.classValid)
331 ndlp->nlp_class_sup |= FC_COS_CLASS4;
332 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
333 sp->cmn.bbRcvSizeLsb;
334 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
335
James Smart92d7f7b2007-06-17 19:56:38 -0500336 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
337 if (sp->cmn.response_multiple_NPort) {
James Smarte8b62012007-08-02 11:10:09 -0400338 lpfc_printf_vlog(vport, KERN_WARNING,
339 LOG_ELS | LOG_VPORT,
340 "1816 FLOGI NPIV supported, "
341 "response data 0x%x\n",
342 sp->cmn.response_multiple_NPort);
James Smart92d7f7b2007-06-17 19:56:38 -0500343 phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
James Smart92d7f7b2007-06-17 19:56:38 -0500344 } else {
345 /* Because we asked f/w for NPIV it still expects us
James Smarte8b62012007-08-02 11:10:09 -0400346 to call reg_vnpid atleast for the physcial host */
347 lpfc_printf_vlog(vport, KERN_WARNING,
348 LOG_ELS | LOG_VPORT,
349 "1817 Fabric does not support NPIV "
350 "- configuring single port mode.\n");
James Smart92d7f7b2007-06-17 19:56:38 -0500351 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
352 }
353 }
354
355 if ((vport->fc_prevDID != vport->fc_myDID) &&
356 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
357
358 /* If our NportID changed, we need to ensure all
359 * remaining NPORTs get unreg_login'ed.
360 */
361 list_for_each_entry_safe(np, next_np,
362 &vport->fc_nodes, nlp_listp) {
363 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
364 !(np->nlp_flag & NLP_NPR_ADISC))
365 continue;
366 spin_lock_irq(shost->host_lock);
367 np->nlp_flag &= ~NLP_NPR_ADISC;
368 spin_unlock_irq(shost->host_lock);
369 lpfc_unreg_rpi(vport, np);
370 }
371 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
372 lpfc_mbx_unreg_vpi(vport);
373 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
374 }
375 }
376
James Smart2e0fef82007-06-17 19:56:36 -0500377 ndlp->nlp_sid = irsp->un.ulpWord[4] & Mask_DID;
James Smart92d7f7b2007-06-17 19:56:38 -0500378 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -0500379
James Smart92d7f7b2007-06-17 19:56:38 -0500380 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
381 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) {
382 lpfc_register_new_vport(phba, vport, ndlp);
383 return 0;
384 }
385 lpfc_issue_fabric_reglogin(vport);
dea31012005-04-17 16:05:31 -0500386 return 0;
dea31012005-04-17 16:05:31 -0500387}
388
389/*
390 * We FLOGIed into an NPort, initiate pt2pt protocol
391 */
392static int
James Smart2e0fef82007-06-17 19:56:36 -0500393lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
394 struct serv_parm *sp)
dea31012005-04-17 16:05:31 -0500395{
James Smart2e0fef82007-06-17 19:56:36 -0500396 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
397 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500398 LPFC_MBOXQ_t *mbox;
399 int rc;
400
James Smart2e0fef82007-06-17 19:56:36 -0500401 spin_lock_irq(shost->host_lock);
402 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
403 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500404
405 phba->fc_edtov = FF_DEF_EDTOV;
406 phba->fc_ratov = FF_DEF_RATOV;
James Smart2e0fef82007-06-17 19:56:36 -0500407 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -0500408 sizeof(vport->fc_portname));
dea31012005-04-17 16:05:31 -0500409 if (rc >= 0) {
410 /* This side will initiate the PLOGI */
James Smart2e0fef82007-06-17 19:56:36 -0500411 spin_lock_irq(shost->host_lock);
412 vport->fc_flag |= FC_PT2PT_PLOGI;
413 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500414
415 /*
416 * N_Port ID cannot be 0, set our to LocalID the other
417 * side will be RemoteID.
418 */
419
420 /* not equal */
421 if (rc)
James Smart2e0fef82007-06-17 19:56:36 -0500422 vport->fc_myDID = PT2PT_LocalID;
dea31012005-04-17 16:05:31 -0500423
424 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
425 if (!mbox)
426 goto fail;
427
428 lpfc_config_link(phba, mbox);
429
430 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -0500431 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -0400432 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -0500433 if (rc == MBX_NOT_FINISHED) {
434 mempool_free(mbox, phba->mbox_mem_pool);
435 goto fail;
436 }
James Smart329f9bc2007-04-25 09:53:01 -0400437 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500438
James Smart2e0fef82007-06-17 19:56:36 -0500439 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
dea31012005-04-17 16:05:31 -0500440 if (!ndlp) {
441 /*
442 * Cannot find existing Fabric ndlp, so allocate a
443 * new one
444 */
445 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
446 if (!ndlp)
447 goto fail;
448
James Smart2e0fef82007-06-17 19:56:36 -0500449 lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID);
dea31012005-04-17 16:05:31 -0500450 }
451
452 memcpy(&ndlp->nlp_portname, &sp->portName,
James Smart2e0fef82007-06-17 19:56:36 -0500453 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500454 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
James Smart2e0fef82007-06-17 19:56:36 -0500455 sizeof(struct lpfc_name));
456 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
457 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500458 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500459 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500460 } else {
461 /* This side will wait for the PLOGI */
James Smart329f9bc2007-04-25 09:53:01 -0400462 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500463 }
464
James Smart2e0fef82007-06-17 19:56:36 -0500465 spin_lock_irq(shost->host_lock);
466 vport->fc_flag |= FC_PT2PT;
467 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500468
469 /* Start discovery - this should just do CLEAR_LA */
James Smart2e0fef82007-06-17 19:56:36 -0500470 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -0500471 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500472fail:
dea31012005-04-17 16:05:31 -0500473 return -ENXIO;
474}
475
476static void
James Smart329f9bc2007-04-25 09:53:01 -0400477lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
478 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500479{
James Smart2e0fef82007-06-17 19:56:36 -0500480 struct lpfc_vport *vport = cmdiocb->vport;
481 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500482 IOCB_t *irsp = &rspiocb->iocb;
483 struct lpfc_nodelist *ndlp = cmdiocb->context1;
484 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
485 struct serv_parm *sp;
486 int rc;
487
488 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500489 if (lpfc_els_chk_latt(vport)) {
James Smart329f9bc2007-04-25 09:53:01 -0400490 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500491 goto out;
492 }
493
James Smart858c9f62007-06-17 19:56:39 -0500494 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
495 "FLOGI cmpl: status:x%x/x%x state:x%x",
496 irsp->ulpStatus, irsp->un.ulpWord[4],
497 vport->port_state);
498
dea31012005-04-17 16:05:31 -0500499 if (irsp->ulpStatus) {
500 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -0500501 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -0500502 goto out;
James Smart2e0fef82007-06-17 19:56:36 -0500503
dea31012005-04-17 16:05:31 -0500504 /* FLOGI failed, so there is no fabric */
James Smart2e0fef82007-06-17 19:56:36 -0500505 spin_lock_irq(shost->host_lock);
506 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
507 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500508
James Smart329f9bc2007-04-25 09:53:01 -0400509 /* If private loop, then allow max outstanding els to be
dea31012005-04-17 16:05:31 -0500510 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
511 * alpa map would take too long otherwise.
512 */
513 if (phba->alpa_map[0] == 0) {
James Smart3de2a652007-08-02 11:09:59 -0400514 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
dea31012005-04-17 16:05:31 -0500515 }
516
517 /* FLOGI failure */
James Smarte8b62012007-08-02 11:10:09 -0400518 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
519 "0100 FLOGI failure Data: x%x x%x "
520 "x%x\n",
521 irsp->ulpStatus, irsp->un.ulpWord[4],
522 irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -0500523 goto flogifail;
524 }
525
526 /*
527 * The FLogI succeeded. Sync the data for the CPU before
528 * accessing it.
529 */
530 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
531
532 sp = prsp->virt + sizeof(uint32_t);
533
534 /* FLOGI completes successfully */
James Smarte8b62012007-08-02 11:10:09 -0400535 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
536 "0101 FLOGI completes sucessfully "
537 "Data: x%x x%x x%x x%x\n",
538 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
539 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution);
dea31012005-04-17 16:05:31 -0500540
James Smart2e0fef82007-06-17 19:56:36 -0500541 if (vport->port_state == LPFC_FLOGI) {
dea31012005-04-17 16:05:31 -0500542 /*
543 * If Common Service Parameters indicate Nport
544 * we are point to point, if Fport we are Fabric.
545 */
546 if (sp->cmn.fPort)
James Smart2e0fef82007-06-17 19:56:36 -0500547 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
dea31012005-04-17 16:05:31 -0500548 else
James Smart2e0fef82007-06-17 19:56:36 -0500549 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
dea31012005-04-17 16:05:31 -0500550
551 if (!rc)
552 goto out;
553 }
554
555flogifail:
James Smart329f9bc2007-04-25 09:53:01 -0400556 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500557
James Smart858c9f62007-06-17 19:56:39 -0500558 if (!lpfc_error_lost_link(irsp)) {
dea31012005-04-17 16:05:31 -0500559 /* FLOGI failed, so just use loop map to make discovery list */
James Smart2e0fef82007-06-17 19:56:36 -0500560 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -0500561
562 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500563 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -0500564 }
565
566out:
567 lpfc_els_free_iocb(phba, cmdiocb);
568}
569
570static int
James Smart2e0fef82007-06-17 19:56:36 -0500571lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -0500572 uint8_t retry)
573{
James Smart2e0fef82007-06-17 19:56:36 -0500574 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500575 struct serv_parm *sp;
576 IOCB_t *icmd;
577 struct lpfc_iocbq *elsiocb;
578 struct lpfc_sli_ring *pring;
579 uint8_t *pcmd;
580 uint16_t cmdsize;
581 uint32_t tmo;
582 int rc;
583
584 pring = &phba->sli.ring[LPFC_ELS_RING];
585
James Smart92d7f7b2007-06-17 19:56:38 -0500586 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart2e0fef82007-06-17 19:56:36 -0500587 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
588 ndlp->nlp_DID, ELS_CMD_FLOGI);
James Smart92d7f7b2007-06-17 19:56:38 -0500589
James Smart488d1462006-03-07 15:02:37 -0500590 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500591 return 1;
dea31012005-04-17 16:05:31 -0500592
593 icmd = &elsiocb->iocb;
594 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
595
596 /* For FLOGI request, remainder of payload is service parameters */
597 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -0500598 pcmd += sizeof(uint32_t);
599 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -0500600 sp = (struct serv_parm *) pcmd;
601
602 /* Setup CSPs accordingly for Fabric */
603 sp->cmn.e_d_tov = 0;
604 sp->cmn.w2.r_a_tov = 0;
605 sp->cls1.classValid = 0;
606 sp->cls2.seqDelivery = 1;
607 sp->cls3.seqDelivery = 1;
608 if (sp->cmn.fcphLow < FC_PH3)
609 sp->cmn.fcphLow = FC_PH3;
610 if (sp->cmn.fcphHigh < FC_PH3)
611 sp->cmn.fcphHigh = FC_PH3;
612
James Smart92d7f7b2007-06-17 19:56:38 -0500613 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
614 sp->cmn.request_multiple_Nport = 1;
615
616 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
617 icmd->ulpCt_h = 1;
618 icmd->ulpCt_l = 0;
619 }
620
James Smart858c9f62007-06-17 19:56:39 -0500621 if (phba->fc_topology != TOPOLOGY_LOOP) {
622 icmd->un.elsreq64.myID = 0;
623 icmd->un.elsreq64.fl = 1;
624 }
625
dea31012005-04-17 16:05:31 -0500626 tmo = phba->fc_ratov;
627 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
James Smart2e0fef82007-06-17 19:56:36 -0500628 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -0500629 phba->fc_ratov = tmo;
630
631 phba->fc_stat.elsXmitFLOGI++;
632 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
James Smart858c9f62007-06-17 19:56:39 -0500633
634 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
635 "Issue FLOGI: opt:x%x",
636 phba->sli3_options, 0, 0);
637
James Smart92d7f7b2007-06-17 19:56:38 -0500638 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
dea31012005-04-17 16:05:31 -0500639 if (rc == IOCB_ERROR) {
640 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500641 return 1;
dea31012005-04-17 16:05:31 -0500642 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500643 return 0;
dea31012005-04-17 16:05:31 -0500644}
645
646int
James Smart2e0fef82007-06-17 19:56:36 -0500647lpfc_els_abort_flogi(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500648{
649 struct lpfc_sli_ring *pring;
650 struct lpfc_iocbq *iocb, *next_iocb;
651 struct lpfc_nodelist *ndlp;
652 IOCB_t *icmd;
653
654 /* Abort outstanding I/O on NPort <nlp_DID> */
655 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -0400656 "0201 Abort outstanding I/O on NPort x%x\n",
657 Fabric_DID);
dea31012005-04-17 16:05:31 -0500658
659 pring = &phba->sli.ring[LPFC_ELS_RING];
660
661 /*
662 * Check the txcmplq for an iocb that matches the nport the driver is
663 * searching for.
664 */
James Smart2e0fef82007-06-17 19:56:36 -0500665 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500666 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
667 icmd = &iocb->iocb;
James Smart2e0fef82007-06-17 19:56:36 -0500668 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR &&
669 icmd->un.elsreq64.bdl.ulpIoTag32) {
dea31012005-04-17 16:05:31 -0500670 ndlp = (struct lpfc_nodelist *)(iocb->context1);
James Smart92d7f7b2007-06-17 19:56:38 -0500671 if (ndlp && (ndlp->nlp_DID == Fabric_DID)) {
James Smart07951072007-04-25 09:51:38 -0400672 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
James Smart92d7f7b2007-06-17 19:56:38 -0500673 }
dea31012005-04-17 16:05:31 -0500674 }
675 }
James Smart2e0fef82007-06-17 19:56:36 -0500676 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500677
678 return 0;
679}
680
681int
James Smart2e0fef82007-06-17 19:56:36 -0500682lpfc_initial_flogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -0500683{
James Smart2e0fef82007-06-17 19:56:36 -0500684 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500685 struct lpfc_nodelist *ndlp;
686
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500687 /* First look for the Fabric ndlp */
James Smart2e0fef82007-06-17 19:56:36 -0500688 ndlp = lpfc_findnode_did(vport, Fabric_DID);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500689 if (!ndlp) {
dea31012005-04-17 16:05:31 -0500690 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500691 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
692 if (!ndlp)
693 return 0;
James Smart2e0fef82007-06-17 19:56:36 -0500694 lpfc_nlp_init(vport, ndlp, Fabric_DID);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500695 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500696 lpfc_dequeue_node(vport, ndlp);
dea31012005-04-17 16:05:31 -0500697 }
James Smart2e0fef82007-06-17 19:56:36 -0500698 if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
James Smart329f9bc2007-04-25 09:53:01 -0400699 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500700 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500701 return 1;
dea31012005-04-17 16:05:31 -0500702}
703
James Smart92d7f7b2007-06-17 19:56:38 -0500704int
705lpfc_initial_fdisc(struct lpfc_vport *vport)
706{
707 struct lpfc_hba *phba = vport->phba;
708 struct lpfc_nodelist *ndlp;
709
710 /* First look for the Fabric ndlp */
711 ndlp = lpfc_findnode_did(vport, Fabric_DID);
712 if (!ndlp) {
713 /* Cannot find existing Fabric ndlp, so allocate a new one */
714 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
715 if (!ndlp)
716 return 0;
717 lpfc_nlp_init(vport, ndlp, Fabric_DID);
718 } else {
719 lpfc_dequeue_node(vport, ndlp);
720 }
721 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
722 lpfc_nlp_put(ndlp);
723 }
724 return 1;
725}
dea31012005-04-17 16:05:31 -0500726static void
James Smart2e0fef82007-06-17 19:56:36 -0500727lpfc_more_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -0500728{
729 int sentplogi;
730
James Smart2e0fef82007-06-17 19:56:36 -0500731 if (vport->num_disc_nodes)
732 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -0500733
734 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
James Smarte8b62012007-08-02 11:10:09 -0400735 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
736 "0232 Continue discovery with %d PLOGIs to go "
737 "Data: x%x x%x x%x\n",
738 vport->num_disc_nodes, vport->fc_plogi_cnt,
739 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -0500740 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -0500741 if (vport->fc_flag & FC_NLP_MORE)
742 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
743 sentplogi = lpfc_els_disc_plogi(vport);
744
dea31012005-04-17 16:05:31 -0500745 return;
746}
747
James Smart488d1462006-03-07 15:02:37 -0500748static struct lpfc_nodelist *
James Smart92d7f7b2007-06-17 19:56:38 -0500749lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
James Smart488d1462006-03-07 15:02:37 -0500750 struct lpfc_nodelist *ndlp)
751{
James Smart2e0fef82007-06-17 19:56:36 -0500752 struct lpfc_vport *vport = ndlp->vport;
James Smart488d1462006-03-07 15:02:37 -0500753 struct lpfc_nodelist *new_ndlp;
James Smart488d1462006-03-07 15:02:37 -0500754 struct serv_parm *sp;
James Smart92d7f7b2007-06-17 19:56:38 -0500755 uint8_t name[sizeof(struct lpfc_name)];
James Smart488d1462006-03-07 15:02:37 -0500756 uint32_t rc;
757
James Smart2fb9bd82006-12-02 13:33:57 -0500758 /* Fabric nodes can have the same WWPN so we don't bother searching
759 * by WWPN. Just return the ndlp that was given to us.
760 */
761 if (ndlp->nlp_type & NLP_FABRIC)
762 return ndlp;
763
James Smart92d7f7b2007-06-17 19:56:38 -0500764 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
James Smart685f0bf2007-04-25 09:53:08 -0400765 memset(name, 0, sizeof(struct lpfc_name));
James Smart488d1462006-03-07 15:02:37 -0500766
James Smart685f0bf2007-04-25 09:53:08 -0400767 /* Now we find out if the NPort we are logging into, matches the WWPN
James Smart488d1462006-03-07 15:02:37 -0500768 * we have for that ndlp. If not, we have some work to do.
769 */
James Smart2e0fef82007-06-17 19:56:36 -0500770 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
James Smart488d1462006-03-07 15:02:37 -0500771
James Smart92795652006-07-06 15:50:02 -0400772 if (new_ndlp == ndlp)
James Smart488d1462006-03-07 15:02:37 -0500773 return ndlp;
James Smart488d1462006-03-07 15:02:37 -0500774
775 if (!new_ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -0500776 rc = memcmp(&ndlp->nlp_portname, name,
777 sizeof(struct lpfc_name));
James Smart92795652006-07-06 15:50:02 -0400778 if (!rc)
779 return ndlp;
James Smart488d1462006-03-07 15:02:37 -0500780 new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
781 if (!new_ndlp)
782 return ndlp;
783
James Smart2e0fef82007-06-17 19:56:36 -0500784 lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID);
James Smart488d1462006-03-07 15:02:37 -0500785 }
786
James Smart2e0fef82007-06-17 19:56:36 -0500787 lpfc_unreg_rpi(vport, new_ndlp);
James Smart488d1462006-03-07 15:02:37 -0500788 new_ndlp->nlp_DID = ndlp->nlp_DID;
James Smart92795652006-07-06 15:50:02 -0400789 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
James Smart2e0fef82007-06-17 19:56:36 -0500790 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
James Smart488d1462006-03-07 15:02:37 -0500791
James Smart2e0fef82007-06-17 19:56:36 -0500792 /* Move this back to NPR state */
James Smartde0c5b32007-04-25 09:52:27 -0400793 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0)
James Smart2e0fef82007-06-17 19:56:36 -0500794 lpfc_drop_node(vport, ndlp);
James Smart92795652006-07-06 15:50:02 -0400795 else {
James Smart2e0fef82007-06-17 19:56:36 -0500796 lpfc_unreg_rpi(vport, ndlp);
James Smart92795652006-07-06 15:50:02 -0400797 ndlp->nlp_DID = 0; /* Two ndlps cannot have the same did */
James Smart2e0fef82007-06-17 19:56:36 -0500798 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smart92795652006-07-06 15:50:02 -0400799 }
James Smart488d1462006-03-07 15:02:37 -0500800 return new_ndlp;
801}
802
dea31012005-04-17 16:05:31 -0500803static void
James Smart2e0fef82007-06-17 19:56:36 -0500804lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
805 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500806{
James Smart2e0fef82007-06-17 19:56:36 -0500807 struct lpfc_vport *vport = cmdiocb->vport;
808 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500809 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -0500810 struct lpfc_nodelist *ndlp;
James Smart92795652006-07-06 15:50:02 -0400811 struct lpfc_dmabuf *prsp;
dea31012005-04-17 16:05:31 -0500812 int disc, rc, did, type;
813
dea31012005-04-17 16:05:31 -0500814 /* we pass cmdiocb to state machine which needs rspiocb as well */
815 cmdiocb->context_un.rsp_iocb = rspiocb;
816
817 irsp = &rspiocb->iocb;
James Smart858c9f62007-06-17 19:56:39 -0500818 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
819 "PLOGI cmpl: status:x%x/x%x did:x%x",
820 irsp->ulpStatus, irsp->un.ulpWord[4],
821 irsp->un.elsreq64.remoteID);
822
James Smart2e0fef82007-06-17 19:56:36 -0500823 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
James Smarted957682007-06-17 19:56:37 -0500824 if (!ndlp) {
James Smarte8b62012007-08-02 11:10:09 -0400825 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
826 "0136 PLOGI completes to NPort x%x "
827 "with no ndlp. Data: x%x x%x x%x\n",
828 irsp->un.elsreq64.remoteID,
829 irsp->ulpStatus, irsp->un.ulpWord[4],
830 irsp->ulpIoTag);
James Smart488d1462006-03-07 15:02:37 -0500831 goto out;
James Smarted957682007-06-17 19:56:37 -0500832 }
dea31012005-04-17 16:05:31 -0500833
834 /* Since ndlp can be freed in the disc state machine, note if this node
835 * is being used during discovery.
836 */
James Smart2e0fef82007-06-17 19:56:36 -0500837 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500838 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
James Smart488d1462006-03-07 15:02:37 -0500839 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500840 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500841 rc = 0;
842
843 /* PLOGI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -0400844 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
845 "0102 PLOGI completes to NPort x%x "
846 "Data: x%x x%x x%x x%x x%x\n",
847 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
848 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -0500849 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500850 if (lpfc_els_chk_latt(vport)) {
851 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500852 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500853 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500854 goto out;
855 }
856
857 /* ndlp could be freed in DSM, save these values now */
858 type = ndlp->nlp_type;
859 did = ndlp->nlp_DID;
860
861 if (irsp->ulpStatus) {
862 /* Check for retry */
863 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
864 /* ELS command is being retried */
865 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -0500866 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500867 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500868 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500869 }
870 goto out;
871 }
dea31012005-04-17 16:05:31 -0500872 /* PLOGI failed */
James Smart92d7f7b2007-06-17 19:56:38 -0500873 if (ndlp->nlp_DID == NameServer_DID) {
874 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -0400875 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
876 "0250 Nameserver login error: "
877 "0x%x / 0x%x\n",
878 irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smart92d7f7b2007-06-17 19:56:38 -0500879 }
dea31012005-04-17 16:05:31 -0500880 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart858c9f62007-06-17 19:56:39 -0500881 if (lpfc_error_lost_link(irsp)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500882 rc = NLP_STE_FREED_NODE;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500883 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500884 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -0500885 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -0500886 }
887 } else {
888 /* Good status, call state machine */
James Smart92795652006-07-06 15:50:02 -0400889 prsp = list_entry(((struct lpfc_dmabuf *)
James Smart92d7f7b2007-06-17 19:56:38 -0500890 cmdiocb->context2)->list.next,
891 struct lpfc_dmabuf, list);
892 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -0500893 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -0500894 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -0500895 }
896
James Smart2e0fef82007-06-17 19:56:36 -0500897 if (disc && vport->num_disc_nodes) {
dea31012005-04-17 16:05:31 -0500898 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -0500899 lpfc_more_plogi(vport);
dea31012005-04-17 16:05:31 -0500900
James Smart2e0fef82007-06-17 19:56:36 -0500901 if (vport->num_disc_nodes == 0) {
902 spin_lock_irq(shost->host_lock);
903 vport->fc_flag &= ~FC_NDISC_ACTIVE;
904 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500905
James Smart2e0fef82007-06-17 19:56:36 -0500906 lpfc_can_disctmo(vport);
907 if (vport->fc_flag & FC_RSCN_MODE) {
James Smart10d4e952006-04-15 11:53:15 -0400908 /*
909 * Check to see if more RSCNs came in while
910 * we were processing this one.
911 */
James Smart2e0fef82007-06-17 19:56:36 -0500912 if ((vport->fc_rscn_id_cnt == 0) &&
913 (!(vport->fc_flag & FC_RSCN_DISCOVERY))) {
914 spin_lock_irq(shost->host_lock);
915 vport->fc_flag &= ~FC_RSCN_MODE;
916 spin_unlock_irq(shost->host_lock);
James Smart10d4e952006-04-15 11:53:15 -0400917 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500918 lpfc_els_handle_rscn(vport);
James Smart10d4e952006-04-15 11:53:15 -0400919 }
dea31012005-04-17 16:05:31 -0500920 }
921 }
922 }
923
924out:
925 lpfc_els_free_iocb(phba, cmdiocb);
926 return;
927}
928
929int
James Smart2e0fef82007-06-17 19:56:36 -0500930lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
dea31012005-04-17 16:05:31 -0500931{
James Smart2e0fef82007-06-17 19:56:36 -0500932 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500933 struct serv_parm *sp;
934 IOCB_t *icmd;
935 struct lpfc_iocbq *elsiocb;
936 struct lpfc_sli_ring *pring;
937 struct lpfc_sli *psli;
938 uint8_t *pcmd;
939 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -0500940 int ret;
dea31012005-04-17 16:05:31 -0500941
942 psli = &phba->sli;
943 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
944
James Smart92d7f7b2007-06-17 19:56:38 -0500945 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart2e0fef82007-06-17 19:56:36 -0500946 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, NULL, did,
947 ELS_CMD_PLOGI);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500948 if (!elsiocb)
949 return 1;
dea31012005-04-17 16:05:31 -0500950
951 icmd = &elsiocb->iocb;
952 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
953
954 /* For PLOGI request, remainder of payload is service parameters */
955 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -0500956 pcmd += sizeof(uint32_t);
957 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -0500958 sp = (struct serv_parm *) pcmd;
959
960 if (sp->cmn.fcphLow < FC_PH_4_3)
961 sp->cmn.fcphLow = FC_PH_4_3;
962
963 if (sp->cmn.fcphHigh < FC_PH3)
964 sp->cmn.fcphHigh = FC_PH3;
965
James Smart858c9f62007-06-17 19:56:39 -0500966 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
967 "Issue PLOGI: did:x%x",
968 did, 0, 0);
969
dea31012005-04-17 16:05:31 -0500970 phba->fc_stat.elsXmitPLOGI++;
971 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
James Smart92d7f7b2007-06-17 19:56:38 -0500972 ret = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
973
974 if (ret == IOCB_ERROR) {
dea31012005-04-17 16:05:31 -0500975 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500976 return 1;
dea31012005-04-17 16:05:31 -0500977 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500978 return 0;
dea31012005-04-17 16:05:31 -0500979}
980
981static void
James Smart2e0fef82007-06-17 19:56:36 -0500982lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
983 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500984{
James Smart2e0fef82007-06-17 19:56:36 -0500985 struct lpfc_vport *vport = cmdiocb->vport;
986 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500987 IOCB_t *irsp;
988 struct lpfc_sli *psli;
989 struct lpfc_nodelist *ndlp;
990
991 psli = &phba->sli;
992 /* we pass cmdiocb to state machine which needs rspiocb as well */
993 cmdiocb->context_un.rsp_iocb = rspiocb;
994
995 irsp = &(rspiocb->iocb);
996 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
James Smart2e0fef82007-06-17 19:56:36 -0500997 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500998 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -0500999 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001000
James Smart858c9f62007-06-17 19:56:39 -05001001 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1002 "PRLI cmpl: status:x%x/x%x did:x%x",
1003 irsp->ulpStatus, irsp->un.ulpWord[4],
1004 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05001005 /* PRLI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001006 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1007 "0103 PRLI completes to NPort x%x "
1008 "Data: x%x x%x x%x x%x\n",
1009 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1010 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001011
James Smart2e0fef82007-06-17 19:56:36 -05001012 vport->fc_prli_sent--;
dea31012005-04-17 16:05:31 -05001013 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001014 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05001015 goto out;
1016
1017 if (irsp->ulpStatus) {
1018 /* Check for retry */
1019 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1020 /* ELS command is being retried */
1021 goto out;
1022 }
1023 /* PRLI failed */
1024 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart858c9f62007-06-17 19:56:39 -05001025 if (lpfc_error_lost_link(irsp)) {
dea31012005-04-17 16:05:31 -05001026 goto out;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001027 } else {
James Smart2e0fef82007-06-17 19:56:36 -05001028 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001029 NLP_EVT_CMPL_PRLI);
dea31012005-04-17 16:05:31 -05001030 }
1031 } else {
1032 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05001033 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001034 NLP_EVT_CMPL_PRLI);
dea31012005-04-17 16:05:31 -05001035 }
1036
1037out:
1038 lpfc_els_free_iocb(phba, cmdiocb);
1039 return;
1040}
1041
1042int
James Smart2e0fef82007-06-17 19:56:36 -05001043lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001044 uint8_t retry)
1045{
James Smart2e0fef82007-06-17 19:56:36 -05001046 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1047 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001048 PRLI *npr;
1049 IOCB_t *icmd;
1050 struct lpfc_iocbq *elsiocb;
1051 struct lpfc_sli_ring *pring;
1052 struct lpfc_sli *psli;
1053 uint8_t *pcmd;
1054 uint16_t cmdsize;
1055
1056 psli = &phba->sli;
1057 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1058
James Smart92d7f7b2007-06-17 19:56:38 -05001059 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
James Smart2e0fef82007-06-17 19:56:36 -05001060 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1061 ndlp->nlp_DID, ELS_CMD_PRLI);
James Smart488d1462006-03-07 15:02:37 -05001062 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001063 return 1;
dea31012005-04-17 16:05:31 -05001064
1065 icmd = &elsiocb->iocb;
1066 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1067
1068 /* For PRLI request, remainder of payload is service parameters */
James Smart92d7f7b2007-06-17 19:56:38 -05001069 memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t)));
dea31012005-04-17 16:05:31 -05001070 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
James Smart92d7f7b2007-06-17 19:56:38 -05001071 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001072
1073 /* For PRLI, remainder of payload is PRLI parameter page */
1074 npr = (PRLI *) pcmd;
1075 /*
1076 * If our firmware version is 3.20 or later,
1077 * set the following bits for FC-TAPE support.
1078 */
1079 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
1080 npr->ConfmComplAllowed = 1;
1081 npr->Retry = 1;
1082 npr->TaskRetryIdReq = 1;
1083 }
1084 npr->estabImagePair = 1;
1085 npr->readXferRdyDis = 1;
1086
1087 /* For FCP support */
1088 npr->prliType = PRLI_FCP_TYPE;
1089 npr->initiatorFunc = 1;
1090
James Smart858c9f62007-06-17 19:56:39 -05001091 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1092 "Issue PRLI: did:x%x",
1093 ndlp->nlp_DID, 0, 0);
1094
dea31012005-04-17 16:05:31 -05001095 phba->fc_stat.elsXmitPRLI++;
1096 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
James Smart2e0fef82007-06-17 19:56:36 -05001097 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001098 ndlp->nlp_flag |= NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001099 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001100 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05001101 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001102 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001103 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001104 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001105 return 1;
dea31012005-04-17 16:05:31 -05001106 }
James Smart2e0fef82007-06-17 19:56:36 -05001107 vport->fc_prli_sent++;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001108 return 0;
dea31012005-04-17 16:05:31 -05001109}
1110
1111static void
James Smart2e0fef82007-06-17 19:56:36 -05001112lpfc_more_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001113{
1114 int sentadisc;
1115
James Smart2e0fef82007-06-17 19:56:36 -05001116 if (vport->num_disc_nodes)
1117 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001118 /* Continue discovery with <num_disc_nodes> ADISCs to go */
James Smarte8b62012007-08-02 11:10:09 -04001119 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1120 "0210 Continue discovery with %d ADISCs to go "
1121 "Data: x%x x%x x%x\n",
1122 vport->num_disc_nodes, vport->fc_adisc_cnt,
1123 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001124 /* Check to see if there are more ADISCs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001125 if (vport->fc_flag & FC_NLP_MORE) {
1126 lpfc_set_disctmo(vport);
1127 /* go thru NPR nodes and issue any remaining ELS ADISCs */
1128 sentadisc = lpfc_els_disc_adisc(vport);
dea31012005-04-17 16:05:31 -05001129 }
1130 return;
1131}
1132
1133static void
James Smart2e0fef82007-06-17 19:56:36 -05001134lpfc_rscn_disc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001135{
James Smart2e0fef82007-06-17 19:56:36 -05001136 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1137
James Smart858c9f62007-06-17 19:56:39 -05001138 lpfc_can_disctmo(vport);
1139
dea31012005-04-17 16:05:31 -05001140 /* RSCN discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001141 /* go thru NPR nodes and issue ELS PLOGIs */
1142 if (vport->fc_npr_cnt)
1143 if (lpfc_els_disc_plogi(vport))
dea31012005-04-17 16:05:31 -05001144 return;
James Smart2e0fef82007-06-17 19:56:36 -05001145
1146 if (vport->fc_flag & FC_RSCN_MODE) {
dea31012005-04-17 16:05:31 -05001147 /* Check to see if more RSCNs came in while we were
1148 * processing this one.
1149 */
James Smart2e0fef82007-06-17 19:56:36 -05001150 if ((vport->fc_rscn_id_cnt == 0) &&
1151 (!(vport->fc_flag & FC_RSCN_DISCOVERY))) {
1152 spin_lock_irq(shost->host_lock);
1153 vport->fc_flag &= ~FC_RSCN_MODE;
1154 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001155 } else {
James Smart2e0fef82007-06-17 19:56:36 -05001156 lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05001157 }
1158 }
1159}
1160
1161static void
James Smart2e0fef82007-06-17 19:56:36 -05001162lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1163 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001164{
James Smart2e0fef82007-06-17 19:56:36 -05001165 struct lpfc_vport *vport = cmdiocb->vport;
1166 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001167 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001168 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001169 int disc;
dea31012005-04-17 16:05:31 -05001170
1171 /* we pass cmdiocb to state machine which needs rspiocb as well */
1172 cmdiocb->context_un.rsp_iocb = rspiocb;
1173
1174 irsp = &(rspiocb->iocb);
1175 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
dea31012005-04-17 16:05:31 -05001176
James Smart858c9f62007-06-17 19:56:39 -05001177 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1178 "ADISC cmpl: status:x%x/x%x did:x%x",
1179 irsp->ulpStatus, irsp->un.ulpWord[4],
1180 ndlp->nlp_DID);
1181
dea31012005-04-17 16:05:31 -05001182 /* Since ndlp can be freed in the disc state machine, note if this node
1183 * is being used during discovery.
1184 */
James Smart2e0fef82007-06-17 19:56:36 -05001185 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001186 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001187 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001188 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001189 /* ADISC completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001190 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1191 "0104 ADISC completes to NPort x%x "
1192 "Data: x%x x%x x%x x%x x%x\n",
1193 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1194 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001195 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001196 if (lpfc_els_chk_latt(vport)) {
1197 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001198 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001199 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001200 goto out;
1201 }
1202
1203 if (irsp->ulpStatus) {
1204 /* Check for retry */
1205 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1206 /* ELS command is being retried */
1207 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05001208 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001209 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001210 spin_unlock_irq(shost->host_lock);
1211 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001212 }
1213 goto out;
1214 }
1215 /* ADISC failed */
1216 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart858c9f62007-06-17 19:56:39 -05001217 if (!lpfc_error_lost_link(irsp)) {
James Smart2e0fef82007-06-17 19:56:36 -05001218 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart858c9f62007-06-17 19:56:39 -05001219 NLP_EVT_CMPL_ADISC);
dea31012005-04-17 16:05:31 -05001220 }
1221 } else {
1222 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05001223 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
dea31012005-04-17 16:05:31 -05001224 NLP_EVT_CMPL_ADISC);
1225 }
1226
James Smart2e0fef82007-06-17 19:56:36 -05001227 if (disc && vport->num_disc_nodes) {
dea31012005-04-17 16:05:31 -05001228 /* Check to see if there are more ADISCs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001229 lpfc_more_adisc(vport);
dea31012005-04-17 16:05:31 -05001230
1231 /* Check to see if we are done with ADISC authentication */
James Smart2e0fef82007-06-17 19:56:36 -05001232 if (vport->num_disc_nodes == 0) {
James Smart92d7f7b2007-06-17 19:56:38 -05001233 /* If we get here, there is nothing left to ADISC */
1234 /*
1235 * For NPIV, cmpl_reg_vpi will set port_state to READY,
1236 * and continue discovery.
1237 */
1238 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
1239 !(vport->fc_flag & FC_RSCN_MODE)) {
1240 lpfc_issue_reg_vpi(phba, vport);
1241 goto out;
1242 }
1243 /*
1244 * For SLI2, we need to set port_state to READY
1245 * and continue discovery.
1246 */
1247 if (vport->port_state < LPFC_VPORT_READY) {
1248 /* If we get here, there is nothing to ADISC */
James Smarted957682007-06-17 19:56:37 -05001249 if (vport->port_type == LPFC_PHYSICAL_PORT)
James Smart2e0fef82007-06-17 19:56:36 -05001250 lpfc_issue_clear_la(phba, vport);
James Smart92d7f7b2007-06-17 19:56:38 -05001251
1252 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
1253 vport->num_disc_nodes = 0;
1254 /* go thru NPR list, issue ELS PLOGIs */
1255 if (vport->fc_npr_cnt)
1256 lpfc_els_disc_plogi(vport);
1257
1258 if (!vport->num_disc_nodes) {
1259 spin_lock_irq(shost->host_lock);
1260 vport->fc_flag &=
1261 ~FC_NDISC_ACTIVE;
1262 spin_unlock_irq(
1263 shost->host_lock);
1264 lpfc_can_disctmo(vport);
1265 }
1266 }
1267 vport->port_state = LPFC_VPORT_READY;
dea31012005-04-17 16:05:31 -05001268 } else {
James Smart2e0fef82007-06-17 19:56:36 -05001269 lpfc_rscn_disc(vport);
dea31012005-04-17 16:05:31 -05001270 }
1271 }
1272 }
dea31012005-04-17 16:05:31 -05001273out:
1274 lpfc_els_free_iocb(phba, cmdiocb);
1275 return;
1276}
1277
1278int
James Smart2e0fef82007-06-17 19:56:36 -05001279lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001280 uint8_t retry)
1281{
James Smart2e0fef82007-06-17 19:56:36 -05001282 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1283 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001284 ADISC *ap;
1285 IOCB_t *icmd;
1286 struct lpfc_iocbq *elsiocb;
James Smart2e0fef82007-06-17 19:56:36 -05001287 struct lpfc_sli *psli = &phba->sli;
1288 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05001289 uint8_t *pcmd;
1290 uint16_t cmdsize;
1291
James Smart92d7f7b2007-06-17 19:56:38 -05001292 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
James Smart2e0fef82007-06-17 19:56:36 -05001293 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1294 ndlp->nlp_DID, ELS_CMD_ADISC);
James Smart488d1462006-03-07 15:02:37 -05001295 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001296 return 1;
dea31012005-04-17 16:05:31 -05001297
1298 icmd = &elsiocb->iocb;
1299 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1300
1301 /* For ADISC request, remainder of payload is service parameters */
1302 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
James Smart92d7f7b2007-06-17 19:56:38 -05001303 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001304
1305 /* Fill in ADISC payload */
1306 ap = (ADISC *) pcmd;
1307 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05001308 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
1309 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05001310 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05001311
James Smart858c9f62007-06-17 19:56:39 -05001312 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1313 "Issue ADISC: did:x%x",
1314 ndlp->nlp_DID, 0, 0);
1315
dea31012005-04-17 16:05:31 -05001316 phba->fc_stat.elsXmitADISC++;
1317 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
James Smart2e0fef82007-06-17 19:56:36 -05001318 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001319 ndlp->nlp_flag |= NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001320 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001321 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05001322 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001323 ndlp->nlp_flag &= ~NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001324 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001325 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001326 return 1;
dea31012005-04-17 16:05:31 -05001327 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001328 return 0;
dea31012005-04-17 16:05:31 -05001329}
1330
1331static void
James Smart2e0fef82007-06-17 19:56:36 -05001332lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1333 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001334{
James Smart2e0fef82007-06-17 19:56:36 -05001335 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1336 struct lpfc_vport *vport = ndlp->vport;
1337 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001338 IOCB_t *irsp;
1339 struct lpfc_sli *psli;
dea31012005-04-17 16:05:31 -05001340
1341 psli = &phba->sli;
1342 /* we pass cmdiocb to state machine which needs rspiocb as well */
1343 cmdiocb->context_un.rsp_iocb = rspiocb;
1344
1345 irsp = &(rspiocb->iocb);
James Smart2e0fef82007-06-17 19:56:36 -05001346 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001347 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001348 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001349
James Smart858c9f62007-06-17 19:56:39 -05001350 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1351 "LOGO cmpl: status:x%x/x%x did:x%x",
1352 irsp->ulpStatus, irsp->un.ulpWord[4],
1353 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05001354 /* LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001355 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1356 "0105 LOGO completes to NPort x%x "
1357 "Data: x%x x%x x%x x%x\n",
1358 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1359 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001360 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001361 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05001362 goto out;
1363
James Smart92d7f7b2007-06-17 19:56:38 -05001364 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
1365 /* NLP_EVT_DEVICE_RM should unregister the RPI
1366 * which should abort all outstanding IOs.
1367 */
1368 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1369 NLP_EVT_DEVICE_RM);
1370 goto out;
1371 }
1372
dea31012005-04-17 16:05:31 -05001373 if (irsp->ulpStatus) {
1374 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -05001375 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -05001376 /* ELS command is being retried */
1377 goto out;
dea31012005-04-17 16:05:31 -05001378 /* LOGO failed */
1379 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart858c9f62007-06-17 19:56:39 -05001380 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05001381 goto out;
James Smart858c9f62007-06-17 19:56:39 -05001382 else
James Smart2e0fef82007-06-17 19:56:36 -05001383 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001384 NLP_EVT_CMPL_LOGO);
dea31012005-04-17 16:05:31 -05001385 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001386 /* Good status, call state machine.
1387 * This will unregister the rpi if needed.
1388 */
James Smart2e0fef82007-06-17 19:56:36 -05001389 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001390 NLP_EVT_CMPL_LOGO);
dea31012005-04-17 16:05:31 -05001391 }
1392
1393out:
1394 lpfc_els_free_iocb(phba, cmdiocb);
1395 return;
1396}
1397
1398int
James Smart2e0fef82007-06-17 19:56:36 -05001399lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001400 uint8_t retry)
1401{
James Smart2e0fef82007-06-17 19:56:36 -05001402 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1403 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001404 IOCB_t *icmd;
1405 struct lpfc_iocbq *elsiocb;
1406 struct lpfc_sli_ring *pring;
1407 struct lpfc_sli *psli;
1408 uint8_t *pcmd;
1409 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05001410 int rc;
dea31012005-04-17 16:05:31 -05001411
1412 psli = &phba->sli;
1413 pring = &psli->ring[LPFC_ELS_RING];
1414
James Smart92d7f7b2007-06-17 19:56:38 -05001415 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
James Smart2e0fef82007-06-17 19:56:36 -05001416 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1417 ndlp->nlp_DID, ELS_CMD_LOGO);
James Smart488d1462006-03-07 15:02:37 -05001418 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001419 return 1;
dea31012005-04-17 16:05:31 -05001420
1421 icmd = &elsiocb->iocb;
1422 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1423 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
James Smart92d7f7b2007-06-17 19:56:38 -05001424 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001425
1426 /* Fill in LOGO payload */
James Smart2e0fef82007-06-17 19:56:36 -05001427 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05001428 pcmd += sizeof(uint32_t);
1429 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05001430
James Smart858c9f62007-06-17 19:56:39 -05001431 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1432 "Issue LOGO: did:x%x",
1433 ndlp->nlp_DID, 0, 0);
1434
dea31012005-04-17 16:05:31 -05001435 phba->fc_stat.elsXmitLOGO++;
1436 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
James Smart2e0fef82007-06-17 19:56:36 -05001437 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001438 ndlp->nlp_flag |= NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001439 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05001440 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
1441
1442 if (rc == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05001443 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001444 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001445 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001446 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001447 return 1;
dea31012005-04-17 16:05:31 -05001448 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001449 return 0;
dea31012005-04-17 16:05:31 -05001450}
1451
1452static void
James Smart2e0fef82007-06-17 19:56:36 -05001453lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1454 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001455{
James Smart2e0fef82007-06-17 19:56:36 -05001456 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -05001457 IOCB_t *irsp;
1458
1459 irsp = &rspiocb->iocb;
1460
James Smart858c9f62007-06-17 19:56:39 -05001461 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1462 "ELS cmd cmpl: status:x%x/x%x did:x%x",
1463 irsp->ulpStatus, irsp->un.ulpWord[4],
1464 irsp->un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05001465 /* ELS cmd tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04001466 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1467 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
1468 irsp->ulpIoTag, irsp->ulpStatus,
1469 irsp->un.ulpWord[4], irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -05001470 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001471 lpfc_els_chk_latt(vport);
dea31012005-04-17 16:05:31 -05001472 lpfc_els_free_iocb(phba, cmdiocb);
1473 return;
1474}
1475
1476int
James Smart2e0fef82007-06-17 19:56:36 -05001477lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05001478{
James Smart2e0fef82007-06-17 19:56:36 -05001479 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001480 IOCB_t *icmd;
1481 struct lpfc_iocbq *elsiocb;
1482 struct lpfc_sli_ring *pring;
1483 struct lpfc_sli *psli;
1484 uint8_t *pcmd;
1485 uint16_t cmdsize;
1486 struct lpfc_nodelist *ndlp;
1487
1488 psli = &phba->sli;
1489 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
James Smart92d7f7b2007-06-17 19:56:38 -05001490 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001491 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1492 if (!ndlp)
1493 return 1;
dea31012005-04-17 16:05:31 -05001494
James Smart2e0fef82007-06-17 19:56:36 -05001495 lpfc_nlp_init(vport, ndlp, nportid);
dea31012005-04-17 16:05:31 -05001496
James Smart2e0fef82007-06-17 19:56:36 -05001497 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1498 ndlp->nlp_DID, ELS_CMD_SCR);
1499
James Smart488d1462006-03-07 15:02:37 -05001500 if (!elsiocb) {
James Smart329f9bc2007-04-25 09:53:01 -04001501 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001502 return 1;
dea31012005-04-17 16:05:31 -05001503 }
1504
1505 icmd = &elsiocb->iocb;
1506 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1507
1508 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
James Smart92d7f7b2007-06-17 19:56:38 -05001509 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001510
1511 /* For SCR, remainder of payload is SCR parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05001512 memset(pcmd, 0, sizeof(SCR));
dea31012005-04-17 16:05:31 -05001513 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
1514
James Smart858c9f62007-06-17 19:56:39 -05001515 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1516 "Issue SCR: did:x%x",
1517 ndlp->nlp_DID, 0, 0);
1518
dea31012005-04-17 16:05:31 -05001519 phba->fc_stat.elsXmitSCR++;
1520 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
dea31012005-04-17 16:05:31 -05001521 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
James Smart329f9bc2007-04-25 09:53:01 -04001522 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001523 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001524 return 1;
dea31012005-04-17 16:05:31 -05001525 }
James Smart329f9bc2007-04-25 09:53:01 -04001526 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001527 return 0;
dea31012005-04-17 16:05:31 -05001528}
1529
1530static int
James Smart2e0fef82007-06-17 19:56:36 -05001531lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05001532{
James Smart2e0fef82007-06-17 19:56:36 -05001533 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001534 IOCB_t *icmd;
1535 struct lpfc_iocbq *elsiocb;
1536 struct lpfc_sli_ring *pring;
1537 struct lpfc_sli *psli;
1538 FARP *fp;
1539 uint8_t *pcmd;
1540 uint32_t *lp;
1541 uint16_t cmdsize;
1542 struct lpfc_nodelist *ondlp;
1543 struct lpfc_nodelist *ndlp;
1544
1545 psli = &phba->sli;
1546 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
James Smart92d7f7b2007-06-17 19:56:38 -05001547 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001548 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1549 if (!ndlp)
1550 return 1;
dea31012005-04-17 16:05:31 -05001551
James Smart2e0fef82007-06-17 19:56:36 -05001552 lpfc_nlp_init(vport, ndlp, nportid);
1553
1554 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1555 ndlp->nlp_DID, ELS_CMD_RNID);
James Smart488d1462006-03-07 15:02:37 -05001556 if (!elsiocb) {
James Smart329f9bc2007-04-25 09:53:01 -04001557 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001558 return 1;
dea31012005-04-17 16:05:31 -05001559 }
1560
1561 icmd = &elsiocb->iocb;
1562 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1563
1564 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
James Smart92d7f7b2007-06-17 19:56:38 -05001565 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001566
1567 /* Fill in FARPR payload */
1568 fp = (FARP *) (pcmd);
James Smart92d7f7b2007-06-17 19:56:38 -05001569 memset(fp, 0, sizeof(FARP));
dea31012005-04-17 16:05:31 -05001570 lp = (uint32_t *) pcmd;
1571 *lp++ = be32_to_cpu(nportid);
James Smart2e0fef82007-06-17 19:56:36 -05001572 *lp++ = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05001573 fp->Rflags = 0;
1574 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
1575
James Smart92d7f7b2007-06-17 19:56:38 -05001576 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
1577 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05001578 ondlp = lpfc_findnode_did(vport, nportid);
1579 if (ondlp) {
dea31012005-04-17 16:05:31 -05001580 memcpy(&fp->OportName, &ondlp->nlp_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05001581 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05001582 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05001583 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05001584 }
1585
James Smart858c9f62007-06-17 19:56:39 -05001586 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1587 "Issue FARPR: did:x%x",
1588 ndlp->nlp_DID, 0, 0);
1589
dea31012005-04-17 16:05:31 -05001590 phba->fc_stat.elsXmitFARPR++;
1591 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
dea31012005-04-17 16:05:31 -05001592 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
James Smart329f9bc2007-04-25 09:53:01 -04001593 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001594 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001595 return 1;
dea31012005-04-17 16:05:31 -05001596 }
James Smart329f9bc2007-04-25 09:53:01 -04001597 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001598 return 0;
dea31012005-04-17 16:05:31 -05001599}
1600
James Smarted957682007-06-17 19:56:37 -05001601static void
1602lpfc_end_rscn(struct lpfc_vport *vport)
1603{
1604 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1605
1606 if (vport->fc_flag & FC_RSCN_MODE) {
1607 /*
1608 * Check to see if more RSCNs came in while we were
1609 * processing this one.
1610 */
1611 if (vport->fc_rscn_id_cnt ||
1612 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1613 lpfc_els_handle_rscn(vport);
1614 else {
1615 spin_lock_irq(shost->host_lock);
1616 vport->fc_flag &= ~FC_RSCN_MODE;
1617 spin_unlock_irq(shost->host_lock);
1618 }
1619 }
1620}
1621
dea31012005-04-17 16:05:31 -05001622void
James Smart2e0fef82007-06-17 19:56:36 -05001623lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
James Smartfdcebe22006-03-07 15:04:01 -05001624{
James Smart2e0fef82007-06-17 19:56:36 -05001625 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1626
1627 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05001628 nlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001629 spin_unlock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05001630 del_timer_sync(&nlp->nlp_delayfunc);
1631 nlp->nlp_last_elscmd = 0;
1632
1633 if (!list_empty(&nlp->els_retry_evt.evt_listp))
1634 list_del_init(&nlp->els_retry_evt.evt_listp);
1635
1636 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
James Smart2e0fef82007-06-17 19:56:36 -05001637 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05001638 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001639 spin_unlock_irq(shost->host_lock);
1640 if (vport->num_disc_nodes) {
James Smartfdcebe22006-03-07 15:04:01 -05001641 /* Check to see if there are more
1642 * PLOGIs to be sent
1643 */
James Smart2e0fef82007-06-17 19:56:36 -05001644 lpfc_more_plogi(vport);
James Smartfdcebe22006-03-07 15:04:01 -05001645
James Smart2e0fef82007-06-17 19:56:36 -05001646 if (vport->num_disc_nodes == 0) {
1647 spin_lock_irq(shost->host_lock);
1648 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1649 spin_unlock_irq(shost->host_lock);
1650 lpfc_can_disctmo(vport);
James Smarted957682007-06-17 19:56:37 -05001651 lpfc_end_rscn(vport);
James Smartfdcebe22006-03-07 15:04:01 -05001652 }
1653 }
1654 }
1655 return;
1656}
1657
1658void
dea31012005-04-17 16:05:31 -05001659lpfc_els_retry_delay(unsigned long ptr)
1660{
James Smart2e0fef82007-06-17 19:56:36 -05001661 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
1662 struct lpfc_vport *vport = ndlp->vport;
James Smart2e0fef82007-06-17 19:56:36 -05001663 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05001664 unsigned long flags;
James Smart2e0fef82007-06-17 19:56:36 -05001665 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
dea31012005-04-17 16:05:31 -05001666
James Smart2e0fef82007-06-17 19:56:36 -05001667 ndlp = (struct lpfc_nodelist *) ptr;
1668 phba = ndlp->vport->phba;
dea31012005-04-17 16:05:31 -05001669 evtp = &ndlp->els_retry_evt;
1670
James Smart92d7f7b2007-06-17 19:56:38 -05001671 spin_lock_irqsave(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05001672 if (!list_empty(&evtp->evt_listp)) {
James Smart92d7f7b2007-06-17 19:56:38 -05001673 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05001674 return;
1675 }
1676
1677 evtp->evt_arg1 = ndlp;
1678 evtp->evt = LPFC_EVT_ELS_RETRY;
1679 list_add_tail(&evtp->evt_listp, &phba->work_list);
1680 if (phba->work_wait)
James Smart92d7f7b2007-06-17 19:56:38 -05001681 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05001682
James Smart92d7f7b2007-06-17 19:56:38 -05001683 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05001684 return;
1685}
1686
1687void
1688lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
1689{
James Smart2e0fef82007-06-17 19:56:36 -05001690 struct lpfc_vport *vport = ndlp->vport;
1691 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1692 uint32_t cmd, did, retry;
dea31012005-04-17 16:05:31 -05001693
James Smart2e0fef82007-06-17 19:56:36 -05001694 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001695 did = ndlp->nlp_DID;
1696 cmd = ndlp->nlp_last_elscmd;
1697 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05001698
1699 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
James Smart2e0fef82007-06-17 19:56:36 -05001700 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001701 return;
1702 }
1703
1704 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001705 spin_unlock_irq(shost->host_lock);
James Smart1a169682006-03-07 15:04:06 -05001706 /*
1707 * If a discovery event readded nlp_delayfunc after timer
1708 * firing and before processing the timer, cancel the
1709 * nlp_delayfunc.
1710 */
1711 del_timer_sync(&ndlp->nlp_delayfunc);
dea31012005-04-17 16:05:31 -05001712 retry = ndlp->nlp_retry;
1713
1714 switch (cmd) {
1715 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05001716 lpfc_issue_els_flogi(vport, ndlp, retry);
dea31012005-04-17 16:05:31 -05001717 break;
1718 case ELS_CMD_PLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05001719 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001720 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001721 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05001722 }
dea31012005-04-17 16:05:31 -05001723 break;
1724 case ELS_CMD_ADISC:
James Smart2e0fef82007-06-17 19:56:36 -05001725 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001726 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001727 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05001728 }
dea31012005-04-17 16:05:31 -05001729 break;
1730 case ELS_CMD_PRLI:
James Smart2e0fef82007-06-17 19:56:36 -05001731 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001732 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001733 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05001734 }
dea31012005-04-17 16:05:31 -05001735 break;
1736 case ELS_CMD_LOGO:
James Smart2e0fef82007-06-17 19:56:36 -05001737 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001738 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001739 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05001740 }
dea31012005-04-17 16:05:31 -05001741 break;
James Smart92d7f7b2007-06-17 19:56:38 -05001742 case ELS_CMD_FDISC:
1743 lpfc_issue_els_fdisc(vport, ndlp, retry);
1744 break;
dea31012005-04-17 16:05:31 -05001745 }
1746 return;
1747}
1748
1749static int
James Smart2e0fef82007-06-17 19:56:36 -05001750lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1751 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001752{
James Smart2e0fef82007-06-17 19:56:36 -05001753 struct lpfc_vport *vport = cmdiocb->vport;
1754 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1755 IOCB_t *irsp = &rspiocb->iocb;
1756 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1757 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
dea31012005-04-17 16:05:31 -05001758 uint32_t *elscmd;
1759 struct ls_rjt stat;
James Smart2e0fef82007-06-17 19:56:36 -05001760 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
1761 uint32_t cmd = 0;
James Smart488d1462006-03-07 15:02:37 -05001762 uint32_t did;
dea31012005-04-17 16:05:31 -05001763
James Smart488d1462006-03-07 15:02:37 -05001764
dea31012005-04-17 16:05:31 -05001765 /* Note: context2 may be 0 for internal driver abort
1766 * of delays ELS command.
1767 */
1768
1769 if (pcmd && pcmd->virt) {
1770 elscmd = (uint32_t *) (pcmd->virt);
1771 cmd = *elscmd++;
1772 }
1773
James Smart329f9bc2007-04-25 09:53:01 -04001774 if (ndlp)
James Smart488d1462006-03-07 15:02:37 -05001775 did = ndlp->nlp_DID;
1776 else {
1777 /* We should only hit this case for retrying PLOGI */
1778 did = irsp->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05001779 ndlp = lpfc_findnode_did(vport, did);
James Smart488d1462006-03-07 15:02:37 -05001780 if (!ndlp && (cmd != ELS_CMD_PLOGI))
1781 return 1;
1782 }
1783
James Smart858c9f62007-06-17 19:56:39 -05001784 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1785 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
1786 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
1787
dea31012005-04-17 16:05:31 -05001788 switch (irsp->ulpStatus) {
1789 case IOSTAT_FCP_RSP_ERROR:
1790 case IOSTAT_REMOTE_STOP:
1791 break;
1792
1793 case IOSTAT_LOCAL_REJECT:
1794 switch ((irsp->un.ulpWord[4] & 0xff)) {
1795 case IOERR_LOOP_OPEN_FAILURE:
James Smart2e0fef82007-06-17 19:56:36 -05001796 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05001797 delay = 1000;
dea31012005-04-17 16:05:31 -05001798 retry = 1;
1799 break;
1800
James Smart92d7f7b2007-06-17 19:56:38 -05001801 case IOERR_ILLEGAL_COMMAND:
1802 if ((phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) &&
1803 (cmd == ELS_CMD_FDISC)) {
James Smarte8b62012007-08-02 11:10:09 -04001804 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1805 "0124 FDISC failed (3/6) "
1806 "retrying...\n");
James Smart92d7f7b2007-06-17 19:56:38 -05001807 lpfc_mbx_unreg_vpi(vport);
1808 retry = 1;
James Smart51ef4c22007-08-02 11:10:31 -04001809 /* FDISC retry policy */
1810 maxretry = 48;
1811 if (cmdiocb->retry >= 32)
1812 delay = 1000;
James Smart92d7f7b2007-06-17 19:56:38 -05001813 }
1814 break;
1815
dea31012005-04-17 16:05:31 -05001816 case IOERR_NO_RESOURCES:
James Smart858c9f62007-06-17 19:56:39 -05001817 retry = 1;
1818 if (cmdiocb->retry > 100)
1819 delay = 100;
1820 maxretry = 250;
1821 break;
1822
1823 case IOERR_ILLEGAL_FRAME:
James Smart92d7f7b2007-06-17 19:56:38 -05001824 delay = 100;
dea31012005-04-17 16:05:31 -05001825 retry = 1;
1826 break;
1827
James Smart858c9f62007-06-17 19:56:39 -05001828 case IOERR_SEQUENCE_TIMEOUT:
dea31012005-04-17 16:05:31 -05001829 case IOERR_INVALID_RPI:
1830 retry = 1;
1831 break;
1832 }
1833 break;
1834
1835 case IOSTAT_NPORT_RJT:
1836 case IOSTAT_FABRIC_RJT:
1837 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
1838 retry = 1;
1839 break;
1840 }
1841 break;
1842
1843 case IOSTAT_NPORT_BSY:
1844 case IOSTAT_FABRIC_BSY:
1845 retry = 1;
1846 break;
1847
1848 case IOSTAT_LS_RJT:
1849 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
1850 /* Added for Vendor specifc support
1851 * Just keep retrying for these Rsn / Exp codes
1852 */
1853 switch (stat.un.b.lsRjtRsnCode) {
1854 case LSRJT_UNABLE_TPC:
1855 if (stat.un.b.lsRjtRsnCodeExp ==
1856 LSEXP_CMD_IN_PROGRESS) {
1857 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05001858 delay = 1000;
dea31012005-04-17 16:05:31 -05001859 maxretry = 48;
1860 }
1861 retry = 1;
1862 break;
1863 }
1864 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05001865 delay = 1000;
dea31012005-04-17 16:05:31 -05001866 maxretry = lpfc_max_els_tries + 1;
1867 retry = 1;
1868 break;
1869 }
James Smart92d7f7b2007-06-17 19:56:38 -05001870 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
1871 (cmd == ELS_CMD_FDISC) &&
1872 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
James Smarte8b62012007-08-02 11:10:09 -04001873 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1874 "0125 FDISC Failed (x%x). "
1875 "Fabric out of resources\n",
1876 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05001877 lpfc_vport_set_state(vport,
1878 FC_VPORT_NO_FABRIC_RSCS);
1879 }
dea31012005-04-17 16:05:31 -05001880 break;
1881
1882 case LSRJT_LOGICAL_BSY:
James Smart858c9f62007-06-17 19:56:39 -05001883 if ((cmd == ELS_CMD_PLOGI) ||
1884 (cmd == ELS_CMD_PRLI)) {
James Smart92d7f7b2007-06-17 19:56:38 -05001885 delay = 1000;
dea31012005-04-17 16:05:31 -05001886 maxretry = 48;
James Smart92d7f7b2007-06-17 19:56:38 -05001887 } else if (cmd == ELS_CMD_FDISC) {
James Smart51ef4c22007-08-02 11:10:31 -04001888 /* FDISC retry policy */
1889 maxretry = 48;
1890 if (cmdiocb->retry >= 32)
1891 delay = 1000;
dea31012005-04-17 16:05:31 -05001892 }
1893 retry = 1;
1894 break;
James Smart92d7f7b2007-06-17 19:56:38 -05001895
1896 case LSRJT_LOGICAL_ERR:
1897 case LSRJT_PROTOCOL_ERR:
1898 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
1899 (cmd == ELS_CMD_FDISC) &&
1900 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
1901 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
1902 ) {
James Smarte8b62012007-08-02 11:10:09 -04001903 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1904 "0123 FDISC Failed (x%x). "
1905 "Fabric Detected Bad WWN\n",
1906 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05001907 lpfc_vport_set_state(vport,
1908 FC_VPORT_FABRIC_REJ_WWN);
1909 }
1910 break;
dea31012005-04-17 16:05:31 -05001911 }
1912 break;
1913
1914 case IOSTAT_INTERMED_RSP:
1915 case IOSTAT_BA_RJT:
1916 break;
1917
1918 default:
1919 break;
1920 }
1921
James Smart488d1462006-03-07 15:02:37 -05001922 if (did == FDMI_DID)
dea31012005-04-17 16:05:31 -05001923 retry = 1;
dea31012005-04-17 16:05:31 -05001924
1925 if ((++cmdiocb->retry) >= maxretry) {
1926 phba->fc_stat.elsRetryExceeded++;
1927 retry = 0;
1928 }
1929
James Smarted957682007-06-17 19:56:37 -05001930 if ((vport->load_flag & FC_UNLOADING) != 0)
1931 retry = 0;
1932
dea31012005-04-17 16:05:31 -05001933 if (retry) {
1934
1935 /* Retry ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04001936 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1937 "0107 Retry ELS command x%x to remote "
1938 "NPORT x%x Data: x%x x%x\n",
1939 cmd, did, cmdiocb->retry, delay);
dea31012005-04-17 16:05:31 -05001940
James Smart858c9f62007-06-17 19:56:39 -05001941 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
1942 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
1943 ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) {
1944 /* Don't reset timer for no resources */
1945
dea31012005-04-17 16:05:31 -05001946 /* If discovery / RSCN timer is running, reset it */
James Smart2e0fef82007-06-17 19:56:36 -05001947 if (timer_pending(&vport->fc_disctmo) ||
James Smart92d7f7b2007-06-17 19:56:38 -05001948 (vport->fc_flag & FC_RSCN_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05001949 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001950 }
1951
1952 phba->fc_stat.elsXmitRetry++;
James Smart488d1462006-03-07 15:02:37 -05001953 if (ndlp && delay) {
dea31012005-04-17 16:05:31 -05001954 phba->fc_stat.elsDelayRetry++;
1955 ndlp->nlp_retry = cmdiocb->retry;
1956
James Smart92d7f7b2007-06-17 19:56:38 -05001957 /* delay is specified in milliseconds */
1958 mod_timer(&ndlp->nlp_delayfunc,
1959 jiffies + msecs_to_jiffies(delay));
James Smart2e0fef82007-06-17 19:56:36 -05001960 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001961 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001962 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001963
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001964 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart858c9f62007-06-17 19:56:39 -05001965 if (cmd == ELS_CMD_PRLI)
1966 lpfc_nlp_set_state(vport, ndlp,
1967 NLP_STE_REG_LOGIN_ISSUE);
1968 else
1969 lpfc_nlp_set_state(vport, ndlp,
1970 NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05001971 ndlp->nlp_last_elscmd = cmd;
1972
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001973 return 1;
dea31012005-04-17 16:05:31 -05001974 }
1975 switch (cmd) {
1976 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05001977 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001978 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -05001979 case ELS_CMD_FDISC:
1980 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
1981 return 1;
dea31012005-04-17 16:05:31 -05001982 case ELS_CMD_PLOGI:
James Smart488d1462006-03-07 15:02:37 -05001983 if (ndlp) {
1984 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001985 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04001986 NLP_STE_PLOGI_ISSUE);
James Smart488d1462006-03-07 15:02:37 -05001987 }
James Smart2e0fef82007-06-17 19:56:36 -05001988 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001989 return 1;
dea31012005-04-17 16:05:31 -05001990 case ELS_CMD_ADISC:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001991 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001992 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
1993 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001994 return 1;
dea31012005-04-17 16:05:31 -05001995 case ELS_CMD_PRLI:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001996 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001997 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
1998 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001999 return 1;
dea31012005-04-17 16:05:31 -05002000 case ELS_CMD_LOGO:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002001 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002002 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2003 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002004 return 1;
dea31012005-04-17 16:05:31 -05002005 }
2006 }
dea31012005-04-17 16:05:31 -05002007 /* No retry ELS command <elsCmd> to remote NPORT <did> */
James Smarta58cbd52007-08-02 11:09:43 -04002008 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2009 "0108 No retry ELS command x%x to remote "
2010 "NPORT x%x Retried:%d Error:x%x/%x\n",
2011 cmd, did, cmdiocb->retry, irsp->ulpStatus,
2012 irsp->un.ulpWord[4]);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002013 return 0;
dea31012005-04-17 16:05:31 -05002014}
2015
2016int
James Smart329f9bc2007-04-25 09:53:01 -04002017lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05002018{
2019 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
2020
James Smart329f9bc2007-04-25 09:53:01 -04002021 if (elsiocb->context1) {
2022 lpfc_nlp_put(elsiocb->context1);
2023 elsiocb->context1 = NULL;
2024 }
dea31012005-04-17 16:05:31 -05002025 /* context2 = cmd, context2->next = rsp, context3 = bpl */
2026 if (elsiocb->context2) {
2027 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
2028 /* Free the response before processing the command. */
2029 if (!list_empty(&buf_ptr1->list)) {
2030 list_remove_head(&buf_ptr1->list, buf_ptr,
2031 struct lpfc_dmabuf,
2032 list);
2033 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
2034 kfree(buf_ptr);
2035 }
2036 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
2037 kfree(buf_ptr1);
2038 }
2039
2040 if (elsiocb->context3) {
2041 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
2042 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
2043 kfree(buf_ptr);
2044 }
James Bottomley604a3e32005-10-29 10:28:33 -05002045 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -05002046 return 0;
2047}
2048
2049static void
James Smart2e0fef82007-06-17 19:56:36 -05002050lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2051 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002052{
James Smart2e0fef82007-06-17 19:56:36 -05002053 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2054 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05002055 IOCB_t *irsp;
2056
2057 irsp = &rspiocb->iocb;
2058 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2059 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
2060 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05002061 /* ACC to LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002062 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2063 "0109 ACC to LOGO completes to NPort x%x "
2064 "Data: x%x x%x x%x\n",
2065 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2066 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05002067 switch (ndlp->nlp_state) {
2068 case NLP_STE_UNUSED_NODE: /* node is just allocated */
James Smart2e0fef82007-06-17 19:56:36 -05002069 lpfc_drop_node(vport, ndlp);
dea31012005-04-17 16:05:31 -05002070 break;
2071 case NLP_STE_NPR_NODE: /* NPort Recovery mode */
James Smart2e0fef82007-06-17 19:56:36 -05002072 lpfc_unreg_rpi(vport, ndlp);
dea31012005-04-17 16:05:31 -05002073 break;
2074 default:
2075 break;
2076 }
2077 lpfc_els_free_iocb(phba, cmdiocb);
2078 return;
2079}
2080
James Smart858c9f62007-06-17 19:56:39 -05002081void
2082lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
2083{
2084 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
2085 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
2086
2087 pmb->context1 = NULL;
2088 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2089 kfree(mp);
2090 mempool_free(pmb, phba->mbox_mem_pool);
2091 lpfc_nlp_put(ndlp);
2092 return;
2093}
2094
dea31012005-04-17 16:05:31 -05002095static void
James Smart858c9f62007-06-17 19:56:39 -05002096lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
James Smart329f9bc2007-04-25 09:53:01 -04002097 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002098{
James Smart2e0fef82007-06-17 19:56:36 -05002099 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2100 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
2101 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
James Smart33ccf8d2006-08-17 11:57:58 -04002102 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05002103 LPFC_MBOXQ_t *mbox = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05002104 struct lpfc_dmabuf *mp = NULL;
dea31012005-04-17 16:05:31 -05002105
James Smart33ccf8d2006-08-17 11:57:58 -04002106 irsp = &rspiocb->iocb;
2107
dea31012005-04-17 16:05:31 -05002108 if (cmdiocb->context_un.mbox)
2109 mbox = cmdiocb->context_un.mbox;
2110
dea31012005-04-17 16:05:31 -05002111 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002112 if (!ndlp || lpfc_els_chk_latt(vport)) {
dea31012005-04-17 16:05:31 -05002113 if (mbox) {
James Smart14691152006-12-02 13:34:28 -05002114 mp = (struct lpfc_dmabuf *) mbox->context1;
2115 if (mp) {
2116 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2117 kfree(mp);
2118 }
James Smart329f9bc2007-04-25 09:53:01 -04002119 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05002120 }
2121 goto out;
2122 }
2123
James Smart858c9f62007-06-17 19:56:39 -05002124 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smart51ef4c22007-08-02 11:10:31 -04002125 "ELS rsp cmpl: status:x%x/x%x did:x%x",
James Smart858c9f62007-06-17 19:56:39 -05002126 irsp->ulpStatus, irsp->un.ulpWord[4],
James Smart51ef4c22007-08-02 11:10:31 -04002127 cmdiocb->iocb.un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05002128 /* ELS response tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04002129 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2130 "0110 ELS response tag x%x completes "
2131 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
2132 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
2133 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
2134 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2135 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05002136 if (mbox) {
2137 if ((rspiocb->iocb.ulpStatus == 0)
2138 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
James Smart2e0fef82007-06-17 19:56:36 -05002139 lpfc_unreg_rpi(vport, ndlp);
James Smart329f9bc2007-04-25 09:53:01 -04002140 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05002141 mbox->vport = vport;
James Smart858c9f62007-06-17 19:56:39 -05002142 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
2143 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
2144 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
2145 }
2146 else {
2147 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
2148 ndlp->nlp_prev_state = ndlp->nlp_state;
2149 lpfc_nlp_set_state(vport, ndlp,
James Smart2e0fef82007-06-17 19:56:36 -05002150 NLP_STE_REG_LOGIN_ISSUE);
James Smart858c9f62007-06-17 19:56:39 -05002151 }
James Smart0b727fe2007-10-27 13:37:25 -04002152 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
dea31012005-04-17 16:05:31 -05002153 != 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,
James Smart51ef4c22007-08-02 11:10:31 -04002187 LPFC_MBOXQ_t *mbox)
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 }
dea31012005-04-17 16:05:31 -05002273 /* Xmit ELS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04002274 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2275 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
2276 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n",
2277 elsiocb->iotag, elsiocb->iocb.ulpContext,
2278 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2279 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05002280 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
James Smart2e0fef82007-06-17 19:56:36 -05002281 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002282 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05002283 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002284 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
2285 } else {
James Smart858c9f62007-06-17 19:56:39 -05002286 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05002287 }
2288
2289 phba->fc_stat.elsXmitACC++;
dea31012005-04-17 16:05:31 -05002290 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
dea31012005-04-17 16:05:31 -05002291 if (rc == IOCB_ERROR) {
2292 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002293 return 1;
dea31012005-04-17 16:05:31 -05002294 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002295 return 0;
dea31012005-04-17 16:05:31 -05002296}
2297
2298int
James Smart2e0fef82007-06-17 19:56:36 -05002299lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
James Smart858c9f62007-06-17 19:56:39 -05002300 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
2301 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05002302{
James Smart2e0fef82007-06-17 19:56:36 -05002303 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002304 IOCB_t *icmd;
2305 IOCB_t *oldcmd;
2306 struct lpfc_iocbq *elsiocb;
2307 struct lpfc_sli_ring *pring;
2308 struct lpfc_sli *psli;
2309 uint8_t *pcmd;
2310 uint16_t cmdsize;
2311 int rc;
2312
2313 psli = &phba->sli;
2314 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2315
James Smart92d7f7b2007-06-17 19:56:38 -05002316 cmdsize = 2 * sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05002317 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
2318 ndlp->nlp_DID, ELS_CMD_LS_RJT);
James Smart488d1462006-03-07 15:02:37 -05002319 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002320 return 1;
dea31012005-04-17 16:05:31 -05002321
2322 icmd = &elsiocb->iocb;
2323 oldcmd = &oldiocb->iocb;
2324 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2325 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2326
2327 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
James Smart92d7f7b2007-06-17 19:56:38 -05002328 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002329 *((uint32_t *) (pcmd)) = rejectError;
2330
James Smart51ef4c22007-08-02 11:10:31 -04002331 if (mbox)
James Smart858c9f62007-06-17 19:56:39 -05002332 elsiocb->context_un.mbox = mbox;
James Smart858c9f62007-06-17 19:56:39 -05002333
dea31012005-04-17 16:05:31 -05002334 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04002335 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2336 "0129 Xmit ELS RJT x%x response tag x%x "
2337 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
2338 "rpi x%x\n",
2339 rejectError, elsiocb->iotag,
2340 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
2341 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05002342 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2343 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
2344 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
2345
dea31012005-04-17 16:05:31 -05002346 phba->fc_stat.elsXmitLSRJT++;
James Smart858c9f62007-06-17 19:56:39 -05002347 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05002348 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
James Smart51ef4c22007-08-02 11:10:31 -04002349
2350 /* If the node is in the UNUSED state, and we are sending
2351 * a reject, we are done with it. Release driver reference
2352 * count here. The outstanding els will release its reference on
2353 * completion and the node can be freed then.
2354 */
2355 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
2356 lpfc_nlp_put(ndlp);
2357
dea31012005-04-17 16:05:31 -05002358 if (rc == IOCB_ERROR) {
2359 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002360 return 1;
dea31012005-04-17 16:05:31 -05002361 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002362 return 0;
dea31012005-04-17 16:05:31 -05002363}
2364
2365int
James Smart2e0fef82007-06-17 19:56:36 -05002366lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
2367 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05002368{
James Smart2e0fef82007-06-17 19:56:36 -05002369 struct lpfc_hba *phba = vport->phba;
2370 struct lpfc_sli *psli = &phba->sli;
2371 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05002372 ADISC *ap;
James Smart2e0fef82007-06-17 19:56:36 -05002373 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05002374 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002375 uint8_t *pcmd;
2376 uint16_t cmdsize;
2377 int rc;
2378
James Smart92d7f7b2007-06-17 19:56:38 -05002379 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
James Smart2e0fef82007-06-17 19:56:36 -05002380 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
2381 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05002382 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002383 return 1;
dea31012005-04-17 16:05:31 -05002384
dea31012005-04-17 16:05:31 -05002385 icmd = &elsiocb->iocb;
2386 oldcmd = &oldiocb->iocb;
2387 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04002388
2389 /* Xmit ADISC ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04002390 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2391 "0130 Xmit ADISC ACC response iotag x%x xri: "
2392 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
2393 elsiocb->iotag, elsiocb->iocb.ulpContext,
2394 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2395 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05002396 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2397
2398 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05002399 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002400
2401 ap = (ADISC *) (pcmd);
2402 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05002403 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2404 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002405 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002406
James Smart858c9f62007-06-17 19:56:39 -05002407 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2408 "Issue ACC ADISC: did:x%x flg:x%x",
2409 ndlp->nlp_DID, ndlp->nlp_flag, 0);
2410
dea31012005-04-17 16:05:31 -05002411 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05002412 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05002413 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
dea31012005-04-17 16:05:31 -05002414 if (rc == IOCB_ERROR) {
2415 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002416 return 1;
dea31012005-04-17 16:05:31 -05002417 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002418 return 0;
dea31012005-04-17 16:05:31 -05002419}
2420
2421int
James Smart2e0fef82007-06-17 19:56:36 -05002422lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
James Smart5b8bd0c2007-04-25 09:52:49 -04002423 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05002424{
James Smart2e0fef82007-06-17 19:56:36 -05002425 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002426 PRLI *npr;
2427 lpfc_vpd_t *vpd;
2428 IOCB_t *icmd;
2429 IOCB_t *oldcmd;
2430 struct lpfc_iocbq *elsiocb;
2431 struct lpfc_sli_ring *pring;
2432 struct lpfc_sli *psli;
2433 uint8_t *pcmd;
2434 uint16_t cmdsize;
2435 int rc;
2436
2437 psli = &phba->sli;
2438 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2439
James Smart92d7f7b2007-06-17 19:56:38 -05002440 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
James Smart2e0fef82007-06-17 19:56:36 -05002441 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
James Smart92d7f7b2007-06-17 19:56:38 -05002442 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002443 if (!elsiocb)
2444 return 1;
dea31012005-04-17 16:05:31 -05002445
dea31012005-04-17 16:05:31 -05002446 icmd = &elsiocb->iocb;
2447 oldcmd = &oldiocb->iocb;
2448 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04002449 /* Xmit PRLI ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04002450 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2451 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
2452 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
2453 elsiocb->iotag, elsiocb->iocb.ulpContext,
2454 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2455 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05002456 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2457
2458 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
James Smart92d7f7b2007-06-17 19:56:38 -05002459 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002460
2461 /* For PRLI, remainder of payload is PRLI parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05002462 memset(pcmd, 0, sizeof(PRLI));
dea31012005-04-17 16:05:31 -05002463
2464 npr = (PRLI *) pcmd;
2465 vpd = &phba->vpd;
2466 /*
2467 * If our firmware version is 3.20 or later,
2468 * set the following bits for FC-TAPE support.
2469 */
2470 if (vpd->rev.feaLevelHigh >= 0x02) {
2471 npr->ConfmComplAllowed = 1;
2472 npr->Retry = 1;
2473 npr->TaskRetryIdReq = 1;
2474 }
2475
2476 npr->acceptRspCode = PRLI_REQ_EXECUTED;
2477 npr->estabImagePair = 1;
2478 npr->readXferRdyDis = 1;
2479 npr->ConfmComplAllowed = 1;
2480
2481 npr->prliType = PRLI_FCP_TYPE;
2482 npr->initiatorFunc = 1;
2483
James Smart858c9f62007-06-17 19:56:39 -05002484 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2485 "Issue ACC PRLI: did:x%x flg:x%x",
2486 ndlp->nlp_DID, ndlp->nlp_flag, 0);
2487
dea31012005-04-17 16:05:31 -05002488 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05002489 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05002490
dea31012005-04-17 16:05:31 -05002491 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
dea31012005-04-17 16:05:31 -05002492 if (rc == IOCB_ERROR) {
2493 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002494 return 1;
dea31012005-04-17 16:05:31 -05002495 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002496 return 0;
dea31012005-04-17 16:05:31 -05002497}
2498
2499static int
James Smart2e0fef82007-06-17 19:56:36 -05002500lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
James Smart329f9bc2007-04-25 09:53:01 -04002501 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05002502{
James Smart2e0fef82007-06-17 19:56:36 -05002503 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002504 RNID *rn;
James Smart2e0fef82007-06-17 19:56:36 -05002505 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05002506 struct lpfc_iocbq *elsiocb;
2507 struct lpfc_sli_ring *pring;
2508 struct lpfc_sli *psli;
2509 uint8_t *pcmd;
2510 uint16_t cmdsize;
2511 int rc;
2512
2513 psli = &phba->sli;
2514 pring = &psli->ring[LPFC_ELS_RING];
2515
James Smart92d7f7b2007-06-17 19:56:38 -05002516 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
2517 + (2 * sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002518 if (format)
James Smart92d7f7b2007-06-17 19:56:38 -05002519 cmdsize += sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05002520
James Smart2e0fef82007-06-17 19:56:36 -05002521 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
2522 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05002523 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002524 return 1;
dea31012005-04-17 16:05:31 -05002525
dea31012005-04-17 16:05:31 -05002526 icmd = &elsiocb->iocb;
2527 oldcmd = &oldiocb->iocb;
2528 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04002529 /* Xmit RNID ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04002530 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2531 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
2532 elsiocb->iotag, elsiocb->iocb.ulpContext);
dea31012005-04-17 16:05:31 -05002533 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
dea31012005-04-17 16:05:31 -05002534 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05002535 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002536
James Smart92d7f7b2007-06-17 19:56:38 -05002537 memset(pcmd, 0, sizeof(RNID));
dea31012005-04-17 16:05:31 -05002538 rn = (RNID *) (pcmd);
2539 rn->Format = format;
James Smart92d7f7b2007-06-17 19:56:38 -05002540 rn->CommonLen = (2 * sizeof(struct lpfc_name));
2541 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2542 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002543 switch (format) {
2544 case 0:
2545 rn->SpecificLen = 0;
2546 break;
2547 case RNID_TOPOLOGY_DISC:
James Smart92d7f7b2007-06-17 19:56:38 -05002548 rn->SpecificLen = sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05002549 memcpy(&rn->un.topologyDisc.portName,
James Smart92d7f7b2007-06-17 19:56:38 -05002550 &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002551 rn->un.topologyDisc.unitType = RNID_HBA;
2552 rn->un.topologyDisc.physPort = 0;
2553 rn->un.topologyDisc.attachedNodes = 0;
2554 break;
2555 default:
2556 rn->CommonLen = 0;
2557 rn->SpecificLen = 0;
2558 break;
2559 }
2560
James Smart858c9f62007-06-17 19:56:39 -05002561 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2562 "Issue ACC RNID: did:x%x flg:x%x",
2563 ndlp->nlp_DID, ndlp->nlp_flag, 0);
2564
dea31012005-04-17 16:05:31 -05002565 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05002566 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart329f9bc2007-04-25 09:53:01 -04002567 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002568 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
2569 * it could be freed */
2570
dea31012005-04-17 16:05:31 -05002571 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
dea31012005-04-17 16:05:31 -05002572 if (rc == IOCB_ERROR) {
2573 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002574 return 1;
dea31012005-04-17 16:05:31 -05002575 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002576 return 0;
dea31012005-04-17 16:05:31 -05002577}
2578
2579int
James Smart2e0fef82007-06-17 19:56:36 -05002580lpfc_els_disc_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002581{
James Smart2e0fef82007-06-17 19:56:36 -05002582 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002583 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05002584 int sentadisc = 0;
dea31012005-04-17 16:05:31 -05002585
James Smart685f0bf2007-04-25 09:53:08 -04002586 /* go thru NPR nodes and issue any remaining ELS ADISCs */
James Smart2e0fef82007-06-17 19:56:36 -05002587 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smart685f0bf2007-04-25 09:53:08 -04002588 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
2589 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
2590 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
James Smart2e0fef82007-06-17 19:56:36 -05002591 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04002592 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05002593 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04002594 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002595 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2596 lpfc_issue_els_adisc(vport, ndlp, 0);
James Smart685f0bf2007-04-25 09:53:08 -04002597 sentadisc++;
James Smart2e0fef82007-06-17 19:56:36 -05002598 vport->num_disc_nodes++;
2599 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04002600 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05002601 spin_lock_irq(shost->host_lock);
2602 vport->fc_flag |= FC_NLP_MORE;
2603 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04002604 break;
dea31012005-04-17 16:05:31 -05002605 }
2606 }
2607 }
2608 if (sentadisc == 0) {
James Smart2e0fef82007-06-17 19:56:36 -05002609 spin_lock_irq(shost->host_lock);
2610 vport->fc_flag &= ~FC_NLP_MORE;
2611 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002612 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002613 return sentadisc;
dea31012005-04-17 16:05:31 -05002614}
2615
2616int
James Smart2e0fef82007-06-17 19:56:36 -05002617lpfc_els_disc_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002618{
James Smart2e0fef82007-06-17 19:56:36 -05002619 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002620 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05002621 int sentplogi = 0;
dea31012005-04-17 16:05:31 -05002622
James Smart2e0fef82007-06-17 19:56:36 -05002623 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
2624 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smart685f0bf2007-04-25 09:53:08 -04002625 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
2626 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
2627 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
2628 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
2629 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002630 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2631 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
James Smart685f0bf2007-04-25 09:53:08 -04002632 sentplogi++;
James Smart2e0fef82007-06-17 19:56:36 -05002633 vport->num_disc_nodes++;
2634 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04002635 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05002636 spin_lock_irq(shost->host_lock);
2637 vport->fc_flag |= FC_NLP_MORE;
2638 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04002639 break;
dea31012005-04-17 16:05:31 -05002640 }
2641 }
2642 }
2643 if (sentplogi == 0) {
James Smart2e0fef82007-06-17 19:56:36 -05002644 spin_lock_irq(shost->host_lock);
2645 vport->fc_flag &= ~FC_NLP_MORE;
2646 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002647 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002648 return sentplogi;
dea31012005-04-17 16:05:31 -05002649}
2650
James Smart92d7f7b2007-06-17 19:56:38 -05002651void
James Smart2e0fef82007-06-17 19:56:36 -05002652lpfc_els_flush_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002653{
James Smart2e0fef82007-06-17 19:56:36 -05002654 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2655 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002656 int i;
2657
James Smart2e0fef82007-06-17 19:56:36 -05002658 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05002659 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
James Smart2e0fef82007-06-17 19:56:36 -05002660 vport->fc_rscn_id_list[i] = NULL;
dea31012005-04-17 16:05:31 -05002661 }
James Smart2e0fef82007-06-17 19:56:36 -05002662 spin_lock_irq(shost->host_lock);
2663 vport->fc_rscn_id_cnt = 0;
2664 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
2665 spin_unlock_irq(shost->host_lock);
2666 lpfc_can_disctmo(vport);
dea31012005-04-17 16:05:31 -05002667}
2668
2669int
James Smart2e0fef82007-06-17 19:56:36 -05002670lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05002671{
2672 D_ID ns_did;
2673 D_ID rscn_did;
dea31012005-04-17 16:05:31 -05002674 uint32_t *lp;
James Smart92d7f7b2007-06-17 19:56:38 -05002675 uint32_t payload_len, i;
dea31012005-04-17 16:05:31 -05002676
2677 ns_did.un.word = did;
dea31012005-04-17 16:05:31 -05002678
2679 /* Never match fabric nodes for RSCNs */
2680 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
James Smart2e0fef82007-06-17 19:56:36 -05002681 return 0;
dea31012005-04-17 16:05:31 -05002682
2683 /* If we are doing a FULL RSCN rediscovery, match everything */
James Smart2e0fef82007-06-17 19:56:36 -05002684 if (vport->fc_flag & FC_RSCN_DISCOVERY)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002685 return did;
dea31012005-04-17 16:05:31 -05002686
James Smart2e0fef82007-06-17 19:56:36 -05002687 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05002688 lp = vport->fc_rscn_id_list[i]->virt;
2689 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
2690 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05002691 while (payload_len) {
James Smart92d7f7b2007-06-17 19:56:38 -05002692 rscn_did.un.word = be32_to_cpu(*lp++);
2693 payload_len -= sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002694 switch (rscn_did.un.b.resv) {
2695 case 0: /* Single N_Port ID effected */
James Smart2e0fef82007-06-17 19:56:36 -05002696 if (ns_did.un.word == rscn_did.un.word)
James Smart92d7f7b2007-06-17 19:56:38 -05002697 return did;
dea31012005-04-17 16:05:31 -05002698 break;
2699 case 1: /* Whole N_Port Area effected */
2700 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
2701 && (ns_did.un.b.area == rscn_did.un.b.area))
James Smart92d7f7b2007-06-17 19:56:38 -05002702 return did;
dea31012005-04-17 16:05:31 -05002703 break;
2704 case 2: /* Whole N_Port Domain effected */
2705 if (ns_did.un.b.domain == rscn_did.un.b.domain)
James Smart92d7f7b2007-06-17 19:56:38 -05002706 return did;
dea31012005-04-17 16:05:31 -05002707 break;
2708 default:
James Smart2e0fef82007-06-17 19:56:36 -05002709 /* Unknown Identifier in RSCN node */
James Smarte8b62012007-08-02 11:10:09 -04002710 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
2711 "0217 Unknown Identifier in "
2712 "RSCN payload Data: x%x\n",
2713 rscn_did.un.word);
James Smart92d7f7b2007-06-17 19:56:38 -05002714 case 3: /* Whole Fabric effected */
2715 return did;
dea31012005-04-17 16:05:31 -05002716 }
2717 }
James Smart92d7f7b2007-06-17 19:56:38 -05002718 }
2719 return 0;
dea31012005-04-17 16:05:31 -05002720}
2721
2722static int
James Smart2e0fef82007-06-17 19:56:36 -05002723lpfc_rscn_recovery_check(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002724{
James Smart685f0bf2007-04-25 09:53:08 -04002725 struct lpfc_nodelist *ndlp = NULL;
dea31012005-04-17 16:05:31 -05002726
2727 /* Look at all nodes effected by pending RSCNs and move
James Smart685f0bf2007-04-25 09:53:08 -04002728 * them to NPR state.
dea31012005-04-17 16:05:31 -05002729 */
James Smart685f0bf2007-04-25 09:53:08 -04002730
James Smart2e0fef82007-06-17 19:56:36 -05002731 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smart685f0bf2007-04-25 09:53:08 -04002732 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE ||
James Smart2e0fef82007-06-17 19:56:36 -05002733 lpfc_rscn_payload_check(vport, ndlp->nlp_DID) == 0)
dea31012005-04-17 16:05:31 -05002734 continue;
2735
James Smart2e0fef82007-06-17 19:56:36 -05002736 lpfc_disc_state_machine(vport, ndlp, NULL,
James Smart92d7f7b2007-06-17 19:56:38 -05002737 NLP_EVT_DEVICE_RECOVERY);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002738
James Smart685f0bf2007-04-25 09:53:08 -04002739 /*
2740 * Make sure NLP_DELAY_TMO is NOT running after a device
2741 * recovery event.
2742 */
2743 if (ndlp->nlp_flag & NLP_DELAY_TMO)
James Smart2e0fef82007-06-17 19:56:36 -05002744 lpfc_cancel_retry_delay_tmo(vport, ndlp);
dea31012005-04-17 16:05:31 -05002745 }
James Smart685f0bf2007-04-25 09:53:08 -04002746
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002747 return 0;
dea31012005-04-17 16:05:31 -05002748}
2749
2750static int
James Smart2e0fef82007-06-17 19:56:36 -05002751lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04002752 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05002753{
James Smart2e0fef82007-06-17 19:56:36 -05002754 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2755 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002756 struct lpfc_dmabuf *pcmd;
James Smart92d7f7b2007-06-17 19:56:38 -05002757 uint32_t *lp, *datap;
dea31012005-04-17 16:05:31 -05002758 IOCB_t *icmd;
James Smart92d7f7b2007-06-17 19:56:38 -05002759 uint32_t payload_len, length, nportid, *cmd;
2760 int rscn_cnt = vport->fc_rscn_id_cnt;
2761 int rscn_id = 0, hba_id = 0;
James Smartd2873e42006-08-18 17:46:43 -04002762 int i;
dea31012005-04-17 16:05:31 -05002763
2764 icmd = &cmdiocb->iocb;
2765 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2766 lp = (uint32_t *) pcmd->virt;
2767
James Smart92d7f7b2007-06-17 19:56:38 -05002768 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
2769 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05002770 /* RSCN received */
James Smarte8b62012007-08-02 11:10:09 -04002771 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2772 "0214 RSCN received Data: x%x x%x x%x x%x\n",
2773 vport->fc_flag, payload_len, *lp, rscn_cnt);
James Smartd2873e42006-08-18 17:46:43 -04002774 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
James Smart2e0fef82007-06-17 19:56:36 -05002775 fc_host_post_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04002776 FCH_EVT_RSCN, lp[i]);
2777
dea31012005-04-17 16:05:31 -05002778 /* If we are about to begin discovery, just ACC the RSCN.
2779 * Discovery processing will satisfy it.
2780 */
James Smart2e0fef82007-06-17 19:56:36 -05002781 if (vport->port_state <= LPFC_NS_QRY) {
James Smart858c9f62007-06-17 19:56:39 -05002782 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
2783 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
2784 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
2785
James Smart51ef4c22007-08-02 11:10:31 -04002786 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002787 return 0;
dea31012005-04-17 16:05:31 -05002788 }
2789
James Smart92d7f7b2007-06-17 19:56:38 -05002790 /* If this RSCN just contains NPortIDs for other vports on this HBA,
2791 * just ACC and ignore it.
2792 */
2793 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart3de2a652007-08-02 11:09:59 -04002794 !(vport->cfg_peer_port_login)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002795 i = payload_len;
2796 datap = lp;
2797 while (i > 0) {
2798 nportid = *datap++;
2799 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
2800 i -= sizeof(uint32_t);
2801 rscn_id++;
James Smart549e55c2007-08-02 11:09:51 -04002802 if (lpfc_find_vport_by_did(phba, nportid))
2803 hba_id++;
James Smart92d7f7b2007-06-17 19:56:38 -05002804 }
2805 if (rscn_id == hba_id) {
2806 /* ALL NPortIDs in RSCN are on HBA */
James Smarte8b62012007-08-02 11:10:09 -04002807 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2808 "0214 Ignore RSCN "
2809 "Data: x%x x%x x%x x%x\n",
2810 vport->fc_flag, payload_len,
2811 *lp, rscn_cnt);
James Smart858c9f62007-06-17 19:56:39 -05002812 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
2813 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
2814 ndlp->nlp_DID, vport->port_state,
2815 ndlp->nlp_flag);
2816
James Smart92d7f7b2007-06-17 19:56:38 -05002817 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04002818 ndlp, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05002819 return 0;
2820 }
2821 }
2822
dea31012005-04-17 16:05:31 -05002823 /* If we are already processing an RSCN, save the received
2824 * RSCN payload buffer, cmdiocb->context2 to process later.
2825 */
James Smart2e0fef82007-06-17 19:56:36 -05002826 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
James Smart858c9f62007-06-17 19:56:39 -05002827 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
2828 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
2829 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
2830
James Smart92d7f7b2007-06-17 19:56:38 -05002831 vport->fc_flag |= FC_RSCN_DEFERRED;
2832 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
James Smart2e0fef82007-06-17 19:56:36 -05002833 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
2834 spin_lock_irq(shost->host_lock);
2835 vport->fc_flag |= FC_RSCN_MODE;
2836 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05002837 if (rscn_cnt) {
2838 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
2839 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
2840 }
2841 if ((rscn_cnt) &&
2842 (payload_len + length <= LPFC_BPL_SIZE)) {
2843 *cmd &= ELS_CMD_MASK;
2844 *cmd |= be32_to_cpu(payload_len + length);
2845 memcpy(((uint8_t *)cmd) + length, lp,
2846 payload_len);
2847 } else {
2848 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
2849 vport->fc_rscn_id_cnt++;
2850 /* If we zero, cmdiocb->context2, the calling
2851 * routine will not try to free it.
2852 */
2853 cmdiocb->context2 = NULL;
2854 }
dea31012005-04-17 16:05:31 -05002855
2856 /* Deferred RSCN */
James Smarte8b62012007-08-02 11:10:09 -04002857 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2858 "0235 Deferred RSCN "
2859 "Data: x%x x%x x%x\n",
2860 vport->fc_rscn_id_cnt, vport->fc_flag,
2861 vport->port_state);
dea31012005-04-17 16:05:31 -05002862 } else {
James Smart2e0fef82007-06-17 19:56:36 -05002863 spin_lock_irq(shost->host_lock);
2864 vport->fc_flag |= FC_RSCN_DISCOVERY;
2865 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002866 /* ReDiscovery RSCN */
James Smarte8b62012007-08-02 11:10:09 -04002867 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2868 "0234 ReDiscovery RSCN "
2869 "Data: x%x x%x x%x\n",
2870 vport->fc_rscn_id_cnt, vport->fc_flag,
2871 vport->port_state);
dea31012005-04-17 16:05:31 -05002872 }
2873 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04002874 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05002875
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 Smart51ef4c22007-08-02 11:10:31 -04002899 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
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,
James Smart51ef4c22007-08-02 11:10:31 -04002968 struct lpfc_nodelist *ndlp)
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;
James Smart0b727fe2007-10-27 13:37:25 -04003023 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart5b8bd0c2007-04-25 09:52:49 -04003024 lpfc_set_loopback_flag(phba);
dea31012005-04-17 16:05:31 -05003025 if (rc == MBX_NOT_FINISHED) {
James Smart329f9bc2007-04-25 09:53:01 -04003026 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003027 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003028 return 1;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003029 } else if (rc > 0) { /* greater than */
James Smart2e0fef82007-06-17 19:56:36 -05003030 spin_lock_irq(shost->host_lock);
3031 vport->fc_flag |= FC_PT2PT_PLOGI;
3032 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003033 }
James Smart2e0fef82007-06-17 19:56:36 -05003034 spin_lock_irq(shost->host_lock);
3035 vport->fc_flag |= FC_PT2PT;
3036 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
3037 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003038 } else {
3039 /* Reject this request because invalid parameters */
3040 stat.un.b.lsRjtRsvd0 = 0;
3041 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3042 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
3043 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05003044 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
3045 NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003046 return 1;
dea31012005-04-17 16:05:31 -05003047 }
3048
3049 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04003050 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05003051
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003052 return 0;
dea31012005-04-17 16:05:31 -05003053}
3054
3055static int
James Smart2e0fef82007-06-17 19:56:36 -05003056lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3057 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003058{
3059 struct lpfc_dmabuf *pcmd;
3060 uint32_t *lp;
3061 IOCB_t *icmd;
3062 RNID *rn;
3063 struct ls_rjt stat;
3064 uint32_t cmd, did;
3065
3066 icmd = &cmdiocb->iocb;
3067 did = icmd->un.elsreq64.remoteID;
3068 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3069 lp = (uint32_t *) pcmd->virt;
3070
3071 cmd = *lp++;
3072 rn = (RNID *) lp;
3073
3074 /* RNID received */
3075
3076 switch (rn->Format) {
3077 case 0:
3078 case RNID_TOPOLOGY_DISC:
3079 /* Send back ACC */
James Smart2e0fef82007-06-17 19:56:36 -05003080 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05003081 break;
3082 default:
3083 /* Reject this request because format not supported */
3084 stat.un.b.lsRjtRsvd0 = 0;
3085 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3086 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
3087 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05003088 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
3089 NULL);
dea31012005-04-17 16:05:31 -05003090 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003091 return 0;
dea31012005-04-17 16:05:31 -05003092}
3093
3094static int
James Smart2e0fef82007-06-17 19:56:36 -05003095lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3096 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003097{
3098 struct ls_rjt stat;
3099
3100 /* For now, unconditionally reject this command */
3101 stat.un.b.lsRjtRsvd0 = 0;
3102 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3103 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
3104 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05003105 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003106 return 0;
3107}
3108
Jamie Wellnitz082c0262006-02-28 19:25:30 -05003109static void
James Smart329f9bc2007-04-25 09:53:01 -04003110lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003111{
James Smart2e0fef82007-06-17 19:56:36 -05003112 struct lpfc_sli *psli = &phba->sli;
3113 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003114 MAILBOX_t *mb;
3115 IOCB_t *icmd;
3116 RPS_RSP *rps_rsp;
3117 uint8_t *pcmd;
3118 struct lpfc_iocbq *elsiocb;
3119 struct lpfc_nodelist *ndlp;
3120 uint16_t xri, status;
3121 uint32_t cmdsize;
3122
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003123 mb = &pmb->mb;
3124
3125 ndlp = (struct lpfc_nodelist *) pmb->context2;
3126 xri = (uint16_t) ((unsigned long)(pmb->context1));
Randy Dunlap041976f2006-06-25 01:58:51 -07003127 pmb->context1 = NULL;
3128 pmb->context2 = NULL;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003129
3130 if (mb->mbxStatus) {
James Smart329f9bc2007-04-25 09:53:01 -04003131 mempool_free(pmb, phba->mbox_mem_pool);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003132 return;
3133 }
3134
3135 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
James Smart329f9bc2007-04-25 09:53:01 -04003136 mempool_free(pmb, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05003137 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
3138 lpfc_max_els_tries, ndlp,
3139 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart329f9bc2007-04-25 09:53:01 -04003140 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003141 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003142 return;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003143
3144 icmd = &elsiocb->iocb;
3145 icmd->ulpContext = xri;
3146
3147 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3148 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003149 pcmd += sizeof(uint32_t); /* Skip past command */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003150 rps_rsp = (RPS_RSP *)pcmd;
3151
3152 if (phba->fc_topology != TOPOLOGY_LOOP)
3153 status = 0x10;
3154 else
3155 status = 0x8;
James Smart2e0fef82007-06-17 19:56:36 -05003156 if (phba->pport->fc_flag & FC_FABRIC)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003157 status |= 0x4;
3158
3159 rps_rsp->rsvd1 = 0;
3160 rps_rsp->portStatus = be16_to_cpu(status);
3161 rps_rsp->linkFailureCnt = be32_to_cpu(mb->un.varRdLnk.linkFailureCnt);
3162 rps_rsp->lossSyncCnt = be32_to_cpu(mb->un.varRdLnk.lossSyncCnt);
3163 rps_rsp->lossSignalCnt = be32_to_cpu(mb->un.varRdLnk.lossSignalCnt);
3164 rps_rsp->primSeqErrCnt = be32_to_cpu(mb->un.varRdLnk.primSeqErrCnt);
3165 rps_rsp->invalidXmitWord = be32_to_cpu(mb->un.varRdLnk.invalidXmitWord);
3166 rps_rsp->crcCnt = be32_to_cpu(mb->un.varRdLnk.crcCnt);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003167 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003168 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
3169 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
3170 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
3171 elsiocb->iotag, elsiocb->iocb.ulpContext,
3172 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3173 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05003174 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003175 phba->fc_stat.elsXmitACC++;
James Smarted957682007-06-17 19:56:37 -05003176 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003177 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003178 return;
3179}
3180
3181static int
James Smart2e0fef82007-06-17 19:56:36 -05003182lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3183 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003184{
James Smart2e0fef82007-06-17 19:56:36 -05003185 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003186 uint32_t *lp;
3187 uint8_t flag;
3188 LPFC_MBOXQ_t *mbox;
3189 struct lpfc_dmabuf *pcmd;
3190 RPS *rps;
3191 struct ls_rjt stat;
3192
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003193 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
3194 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003195 stat.un.b.lsRjtRsvd0 = 0;
3196 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3197 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
3198 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05003199 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
3200 NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003201 }
3202
3203 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3204 lp = (uint32_t *) pcmd->virt;
3205 flag = (be32_to_cpu(*lp++) & 0xf);
3206 rps = (RPS *) lp;
3207
3208 if ((flag == 0) ||
3209 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
James Smart2e0fef82007-06-17 19:56:36 -05003210 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05003211 sizeof(struct lpfc_name)) == 0))) {
James Smart2e0fef82007-06-17 19:56:36 -05003212
James Smart92d7f7b2007-06-17 19:56:38 -05003213 printk("Fix me....\n");
3214 dump_stack();
James Smart2e0fef82007-06-17 19:56:36 -05003215 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
3216 if (mbox) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003217 lpfc_read_lnk_stat(phba, mbox);
3218 mbox->context1 =
James Smart92d7f7b2007-06-17 19:56:38 -05003219 (void *)((unsigned long) cmdiocb->iocb.ulpContext);
James Smart329f9bc2007-04-25 09:53:01 -04003220 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05003221 mbox->vport = vport;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003222 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
James Smart0b727fe2007-10-27 13:37:25 -04003223 if (lpfc_sli_issue_mbox (phba, mbox, MBX_NOWAIT)
3224 != MBX_NOT_FINISHED)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003225 /* Mbox completion will send ELS Response */
3226 return 0;
James Smart2e0fef82007-06-17 19:56:36 -05003227
James Smart329f9bc2007-04-25 09:53:01 -04003228 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003229 mempool_free(mbox, phba->mbox_mem_pool);
3230 }
3231 }
3232 stat.un.b.lsRjtRsvd0 = 0;
3233 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3234 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
3235 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05003236 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003237 return 0;
3238}
3239
Jamie Wellnitz082c0262006-02-28 19:25:30 -05003240static int
James Smart2e0fef82007-06-17 19:56:36 -05003241lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
3242 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003243{
James Smart2e0fef82007-06-17 19:56:36 -05003244 struct lpfc_hba *phba = vport->phba;
3245 IOCB_t *icmd, *oldcmd;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003246 RPL_RSP rpl_rsp;
3247 struct lpfc_iocbq *elsiocb;
James Smart2e0fef82007-06-17 19:56:36 -05003248 struct lpfc_sli *psli = &phba->sli;
3249 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003250 uint8_t *pcmd;
3251
James Smart2e0fef82007-06-17 19:56:36 -05003252 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3253 ndlp->nlp_DID, ELS_CMD_ACC);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003254
James Smart488d1462006-03-07 15:02:37 -05003255 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003256 return 1;
James Smart488d1462006-03-07 15:02:37 -05003257
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003258 icmd = &elsiocb->iocb;
3259 oldcmd = &oldiocb->iocb;
3260 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3261
3262 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3263 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003264 pcmd += sizeof(uint16_t);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003265 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
3266 pcmd += sizeof(uint16_t);
3267
3268 /* Setup the RPL ACC payload */
3269 rpl_rsp.listLen = be32_to_cpu(1);
3270 rpl_rsp.index = 0;
3271 rpl_rsp.port_num_blk.portNum = 0;
James Smart2e0fef82007-06-17 19:56:36 -05003272 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
3273 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003274 sizeof(struct lpfc_name));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003275 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003276 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003277 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3278 "0120 Xmit ELS RPL ACC response tag x%x "
3279 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
3280 "rpi x%x\n",
3281 elsiocb->iotag, elsiocb->iocb.ulpContext,
3282 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3283 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05003284 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003285 phba->fc_stat.elsXmitACC++;
3286 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
3287 lpfc_els_free_iocb(phba, elsiocb);
3288 return 1;
3289 }
3290 return 0;
3291}
3292
3293static int
James Smart2e0fef82007-06-17 19:56:36 -05003294lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3295 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003296{
3297 struct lpfc_dmabuf *pcmd;
3298 uint32_t *lp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003299 uint32_t maxsize;
3300 uint16_t cmdsize;
3301 RPL *rpl;
3302 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05003303
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003304 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
3305 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003306 stat.un.b.lsRjtRsvd0 = 0;
3307 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3308 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
3309 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05003310 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
3311 NULL);
dea31012005-04-17 16:05:31 -05003312 }
3313
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003314 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3315 lp = (uint32_t *) pcmd->virt;
3316 rpl = (RPL *) (lp + 1);
3317
3318 maxsize = be32_to_cpu(rpl->maxsize);
3319
3320 /* We support only one port */
3321 if ((rpl->index == 0) &&
3322 ((maxsize == 0) ||
3323 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
3324 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003325 } else {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003326 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
3327 }
James Smart2e0fef82007-06-17 19:56:36 -05003328 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05003329
3330 return 0;
3331}
3332
3333static int
James Smart2e0fef82007-06-17 19:56:36 -05003334lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3335 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003336{
3337 struct lpfc_dmabuf *pcmd;
3338 uint32_t *lp;
3339 IOCB_t *icmd;
3340 FARP *fp;
3341 uint32_t cmd, cnt, did;
3342
3343 icmd = &cmdiocb->iocb;
3344 did = icmd->un.elsreq64.remoteID;
3345 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3346 lp = (uint32_t *) pcmd->virt;
3347
3348 cmd = *lp++;
3349 fp = (FARP *) lp;
dea31012005-04-17 16:05:31 -05003350 /* FARP-REQ received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04003351 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3352 "0601 FARP-REQ received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05003353 /* We will only support match on WWPN or WWNN */
3354 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003355 return 0;
dea31012005-04-17 16:05:31 -05003356 }
3357
3358 cnt = 0;
3359 /* If this FARP command is searching for my portname */
3360 if (fp->Mflags & FARP_MATCH_PORT) {
James Smart2e0fef82007-06-17 19:56:36 -05003361 if (memcmp(&fp->RportName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05003362 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05003363 cnt = 1;
3364 }
3365
3366 /* If this FARP command is searching for my nodename */
3367 if (fp->Mflags & FARP_MATCH_NODE) {
James Smart2e0fef82007-06-17 19:56:36 -05003368 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05003369 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05003370 cnt = 1;
3371 }
3372
3373 if (cnt) {
3374 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
3375 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
3376 /* Log back into the node before sending the FARP. */
3377 if (fp->Rflags & FARP_REQUEST_PLOGI) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003378 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003379 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04003380 NLP_STE_PLOGI_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05003381 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05003382 }
3383
3384 /* Send a FARP response to that node */
James Smart2e0fef82007-06-17 19:56:36 -05003385 if (fp->Rflags & FARP_REQUEST_FARPR)
3386 lpfc_issue_els_farpr(vport, did, 0);
dea31012005-04-17 16:05:31 -05003387 }
3388 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003389 return 0;
dea31012005-04-17 16:05:31 -05003390}
3391
3392static int
James Smart2e0fef82007-06-17 19:56:36 -05003393lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3394 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003395{
3396 struct lpfc_dmabuf *pcmd;
3397 uint32_t *lp;
3398 IOCB_t *icmd;
3399 uint32_t cmd, did;
3400
3401 icmd = &cmdiocb->iocb;
3402 did = icmd->un.elsreq64.remoteID;
3403 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3404 lp = (uint32_t *) pcmd->virt;
3405
3406 cmd = *lp++;
3407 /* FARP-RSP received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04003408 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3409 "0600 FARP-RSP received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05003410 /* ACCEPT the Farp resp request */
James Smart51ef4c22007-08-02 11:10:31 -04003411 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05003412
3413 return 0;
3414}
3415
3416static int
James Smart2e0fef82007-06-17 19:56:36 -05003417lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3418 struct lpfc_nodelist *fan_ndlp)
dea31012005-04-17 16:05:31 -05003419{
3420 struct lpfc_dmabuf *pcmd;
3421 uint32_t *lp;
3422 IOCB_t *icmd;
dea31012005-04-17 16:05:31 -05003423 uint32_t cmd, did;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003424 FAN *fp;
3425 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05003426 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003427
3428 /* FAN received */
James Smarte8b62012007-08-02 11:10:09 -04003429 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3430 "0265 FAN received\n");
dea31012005-04-17 16:05:31 -05003431 icmd = &cmdiocb->iocb;
3432 did = icmd->un.elsreq64.remoteID;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003433 pcmd = (struct lpfc_dmabuf *)cmdiocb->context2;
3434 lp = (uint32_t *)pcmd->virt;
dea31012005-04-17 16:05:31 -05003435
3436 cmd = *lp++;
James Smart92d7f7b2007-06-17 19:56:38 -05003437 fp = (FAN *) lp;
dea31012005-04-17 16:05:31 -05003438
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003439 /* FAN received; Fan does not have a reply sequence */
dea31012005-04-17 16:05:31 -05003440
James Smart2e0fef82007-06-17 19:56:36 -05003441 if (phba->pport->port_state == LPFC_LOCAL_CFG_LINK) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003442 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
3443 sizeof(struct lpfc_name)) != 0) ||
3444 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
3445 sizeof(struct lpfc_name)) != 0)) {
3446 /*
3447 * This node has switched fabrics. FLOGI is required
3448 * Clean up the old rpi's
dea31012005-04-17 16:05:31 -05003449 */
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003450
3451 list_for_each_entry_safe(ndlp, next_ndlp,
James Smart2e0fef82007-06-17 19:56:36 -05003452 &vport->fc_nodes, nlp_listp) {
James Smart685f0bf2007-04-25 09:53:08 -04003453 if (ndlp->nlp_state != NLP_STE_NPR_NODE)
3454 continue;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003455 if (ndlp->nlp_type & NLP_FABRIC) {
3456 /*
3457 * Clean up old Fabric, Nameserver and
3458 * other NLP_FABRIC logins
3459 */
James Smart2e0fef82007-06-17 19:56:36 -05003460 lpfc_drop_node(vport, ndlp);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003461 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003462 /* Fail outstanding I/O now since this
3463 * device is marked for PLOGI
3464 */
James Smart2e0fef82007-06-17 19:56:36 -05003465 lpfc_unreg_rpi(vport, ndlp);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003466 }
3467 }
3468
James Smart2e0fef82007-06-17 19:56:36 -05003469 vport->port_state = LPFC_FLOGI;
3470 lpfc_set_disctmo(vport);
3471 lpfc_initial_flogi(vport);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003472 return 0;
dea31012005-04-17 16:05:31 -05003473 }
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003474 /* Discovery not needed,
3475 * move the nodes to their original state.
3476 */
James Smart2e0fef82007-06-17 19:56:36 -05003477 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
James Smart685f0bf2007-04-25 09:53:08 -04003478 nlp_listp) {
3479 if (ndlp->nlp_state != NLP_STE_NPR_NODE)
3480 continue;
dea31012005-04-17 16:05:31 -05003481
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003482 switch (ndlp->nlp_prev_state) {
3483 case NLP_STE_UNMAPPED_NODE:
3484 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05003485 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04003486 NLP_STE_UNMAPPED_NODE);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003487 break;
3488
3489 case NLP_STE_MAPPED_NODE:
3490 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05003491 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04003492 NLP_STE_MAPPED_NODE);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003493 break;
3494
3495 default:
3496 break;
3497 }
3498 }
3499
3500 /* Start discovery - this should just do CLEAR_LA */
James Smart2e0fef82007-06-17 19:56:36 -05003501 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -05003502 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003503 return 0;
dea31012005-04-17 16:05:31 -05003504}
3505
3506void
3507lpfc_els_timeout(unsigned long ptr)
3508{
James Smart2e0fef82007-06-17 19:56:36 -05003509 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
3510 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003511 unsigned long iflag;
3512
James Smart2e0fef82007-06-17 19:56:36 -05003513 spin_lock_irqsave(&vport->work_port_lock, iflag);
3514 if ((vport->work_port_events & WORKER_ELS_TMO) == 0) {
3515 vport->work_port_events |= WORKER_ELS_TMO;
James Smart92d7f7b2007-06-17 19:56:38 -05003516 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
3517
3518 spin_lock_irqsave(&phba->hbalock, iflag);
dea31012005-04-17 16:05:31 -05003519 if (phba->work_wait)
James Smart92d7f7b2007-06-17 19:56:38 -05003520 lpfc_worker_wake_up(phba);
3521 spin_unlock_irqrestore(&phba->hbalock, iflag);
dea31012005-04-17 16:05:31 -05003522 }
James Smart92d7f7b2007-06-17 19:56:38 -05003523 else
3524 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
dea31012005-04-17 16:05:31 -05003525 return;
3526}
3527
3528void
James Smart2e0fef82007-06-17 19:56:36 -05003529lpfc_els_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003530{
James Smart2e0fef82007-06-17 19:56:36 -05003531 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003532 struct lpfc_sli_ring *pring;
3533 struct lpfc_iocbq *tmp_iocb, *piocb;
3534 IOCB_t *cmd = NULL;
3535 struct lpfc_dmabuf *pcmd;
James Smart2e0fef82007-06-17 19:56:36 -05003536 uint32_t els_command = 0;
dea31012005-04-17 16:05:31 -05003537 uint32_t timeout;
James Smart2e0fef82007-06-17 19:56:36 -05003538 uint32_t remote_ID = 0xffffffff;
dea31012005-04-17 16:05:31 -05003539
dea31012005-04-17 16:05:31 -05003540 /* If the timer is already canceled do nothing */
James Smart2e0fef82007-06-17 19:56:36 -05003541 if ((vport->work_port_events & WORKER_ELS_TMO) == 0) {
dea31012005-04-17 16:05:31 -05003542 return;
3543 }
James Smart2e0fef82007-06-17 19:56:36 -05003544 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003545 timeout = (uint32_t)(phba->fc_ratov << 1);
3546
3547 pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05003548
3549 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
3550 cmd = &piocb->iocb;
3551
James Smart2e0fef82007-06-17 19:56:36 -05003552 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
3553 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
3554 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
dea31012005-04-17 16:05:31 -05003555 continue;
James Smart2e0fef82007-06-17 19:56:36 -05003556
3557 if (piocb->vport != vport)
3558 continue;
3559
dea31012005-04-17 16:05:31 -05003560 pcmd = (struct lpfc_dmabuf *) piocb->context2;
James Smart2e0fef82007-06-17 19:56:36 -05003561 if (pcmd)
3562 els_command = *(uint32_t *) (pcmd->virt);
dea31012005-04-17 16:05:31 -05003563
James Smart92d7f7b2007-06-17 19:56:38 -05003564 if (els_command == ELS_CMD_FARP ||
3565 els_command == ELS_CMD_FARPR ||
3566 els_command == ELS_CMD_FDISC)
dea31012005-04-17 16:05:31 -05003567 continue;
James Smart92d7f7b2007-06-17 19:56:38 -05003568
3569 if (vport != piocb->vport)
3570 continue;
dea31012005-04-17 16:05:31 -05003571
3572 if (piocb->drvrTimeout > 0) {
James Smart92d7f7b2007-06-17 19:56:38 -05003573 if (piocb->drvrTimeout >= timeout)
dea31012005-04-17 16:05:31 -05003574 piocb->drvrTimeout -= timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05003575 else
dea31012005-04-17 16:05:31 -05003576 piocb->drvrTimeout = 0;
dea31012005-04-17 16:05:31 -05003577 continue;
3578 }
3579
James Smart2e0fef82007-06-17 19:56:36 -05003580 remote_ID = 0xffffffff;
3581 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
dea31012005-04-17 16:05:31 -05003582 remote_ID = cmd->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05003583 else {
3584 struct lpfc_nodelist *ndlp;
3585 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
3586 if (ndlp)
3587 remote_ID = ndlp->nlp_DID;
dea31012005-04-17 16:05:31 -05003588 }
James Smarte8b62012007-08-02 11:10:09 -04003589 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3590 "0127 ELS timeout Data: x%x x%x x%x "
3591 "x%x\n", els_command,
3592 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
James Smart07951072007-04-25 09:51:38 -04003593 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05003594 }
James Smart2e0fef82007-06-17 19:56:36 -05003595 spin_unlock_irq(&phba->hbalock);
James Smart5a0e3262006-07-06 15:49:16 -04003596
James Smart2e0fef82007-06-17 19:56:36 -05003597 if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt)
3598 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
dea31012005-04-17 16:05:31 -05003599}
3600
3601void
James Smart2e0fef82007-06-17 19:56:36 -05003602lpfc_els_flush_cmd(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003603{
James Smart2534ba72007-04-25 09:52:20 -04003604 LIST_HEAD(completions);
James Smart2e0fef82007-06-17 19:56:36 -05003605 struct lpfc_hba *phba = vport->phba;
James Smart329f9bc2007-04-25 09:53:01 -04003606 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05003607 struct lpfc_iocbq *tmp_iocb, *piocb;
3608 IOCB_t *cmd = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05003609
3610 lpfc_fabric_abort_vport(vport);
dea31012005-04-17 16:05:31 -05003611
James Smart2e0fef82007-06-17 19:56:36 -05003612 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003613 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
3614 cmd = &piocb->iocb;
3615
3616 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
3617 continue;
3618 }
3619
3620 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
James Smart329f9bc2007-04-25 09:53:01 -04003621 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
3622 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
3623 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
3624 cmd->ulpCommand == CMD_ABORT_XRI_CN)
dea31012005-04-17 16:05:31 -05003625 continue;
dea31012005-04-17 16:05:31 -05003626
James Smart2e0fef82007-06-17 19:56:36 -05003627 if (piocb->vport != vport)
3628 continue;
3629
James Smart2534ba72007-04-25 09:52:20 -04003630 list_move_tail(&piocb->list, &completions);
James Smart1dcb58e2007-04-25 09:51:30 -04003631 pring->txq_cnt--;
dea31012005-04-17 16:05:31 -05003632 }
3633
3634 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
dea31012005-04-17 16:05:31 -05003635 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
3636 continue;
3637 }
dea31012005-04-17 16:05:31 -05003638
James Smart2e0fef82007-06-17 19:56:36 -05003639 if (piocb->vport != vport)
3640 continue;
3641
James Smart07951072007-04-25 09:51:38 -04003642 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05003643 }
James Smart2e0fef82007-06-17 19:56:36 -05003644 spin_unlock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04003645
James Smart2e0fef82007-06-17 19:56:36 -05003646 while (!list_empty(&completions)) {
James Smart2534ba72007-04-25 09:52:20 -04003647 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
3648 cmd = &piocb->iocb;
James Smart92d7f7b2007-06-17 19:56:38 -05003649 list_del_init(&piocb->list);
James Smart2534ba72007-04-25 09:52:20 -04003650
James Smart2e0fef82007-06-17 19:56:36 -05003651 if (!piocb->iocb_cmpl)
3652 lpfc_sli_release_iocbq(phba, piocb);
3653 else {
James Smart2534ba72007-04-25 09:52:20 -04003654 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
3655 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
3656 (piocb->iocb_cmpl) (phba, piocb, piocb);
James Smart2e0fef82007-06-17 19:56:36 -05003657 }
James Smart2534ba72007-04-25 09:52:20 -04003658 }
3659
dea31012005-04-17 16:05:31 -05003660 return;
3661}
3662
James Smart549e55c2007-08-02 11:09:51 -04003663void
3664lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
3665{
3666 LIST_HEAD(completions);
3667 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
3668 struct lpfc_iocbq *tmp_iocb, *piocb;
3669 IOCB_t *cmd = NULL;
3670
3671 lpfc_fabric_abort_hba(phba);
3672 spin_lock_irq(&phba->hbalock);
3673 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
3674 cmd = &piocb->iocb;
3675 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
3676 continue;
3677 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
3678 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
3679 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
3680 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
3681 cmd->ulpCommand == CMD_ABORT_XRI_CN)
3682 continue;
3683 list_move_tail(&piocb->list, &completions);
3684 pring->txq_cnt--;
3685 }
3686 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
3687 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
3688 continue;
3689 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
3690 }
3691 spin_unlock_irq(&phba->hbalock);
3692 while (!list_empty(&completions)) {
3693 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
3694 cmd = &piocb->iocb;
3695 list_del_init(&piocb->list);
3696 if (!piocb->iocb_cmpl)
3697 lpfc_sli_release_iocbq(phba, piocb);
3698 else {
3699 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
3700 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
3701 (piocb->iocb_cmpl) (phba, piocb, piocb);
3702 }
3703 }
3704 return;
3705}
3706
James Smarted957682007-06-17 19:56:37 -05003707static void
3708lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
James Smart92d7f7b2007-06-17 19:56:38 -05003709 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05003710{
dea31012005-04-17 16:05:31 -05003711 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05003712 struct ls_rjt stat;
James Smart92d7f7b2007-06-17 19:56:38 -05003713 uint32_t *payload;
James Smart2e0fef82007-06-17 19:56:36 -05003714 uint32_t cmd, did, newnode, rjt_err = 0;
James Smarted957682007-06-17 19:56:37 -05003715 IOCB_t *icmd = &elsiocb->iocb;
dea31012005-04-17 16:05:31 -05003716
James Smart92d7f7b2007-06-17 19:56:38 -05003717 if (vport == NULL || elsiocb->context2 == NULL)
dea31012005-04-17 16:05:31 -05003718 goto dropit;
James Smart2e0fef82007-06-17 19:56:36 -05003719
dea31012005-04-17 16:05:31 -05003720 newnode = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05003721 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
3722 cmd = *payload;
James Smarted957682007-06-17 19:56:37 -05003723 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
3724 lpfc_post_buffer(phba, pring, 1, 1);
dea31012005-04-17 16:05:31 -05003725
James Smart858c9f62007-06-17 19:56:39 -05003726 did = icmd->un.rcvels.remoteID;
3727 if (icmd->ulpStatus) {
3728 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3729 "RCV Unsol ELS: status:x%x/x%x did:x%x",
3730 icmd->ulpStatus, icmd->un.ulpWord[4], did);
dea31012005-04-17 16:05:31 -05003731 goto dropit;
James Smart858c9f62007-06-17 19:56:39 -05003732 }
dea31012005-04-17 16:05:31 -05003733
3734 /* Check to see if link went down during discovery */
James Smarted957682007-06-17 19:56:37 -05003735 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05003736 goto dropit;
dea31012005-04-17 16:05:31 -05003737
James Smart92d7f7b2007-06-17 19:56:38 -05003738 /* Ignore traffic recevied during vport shutdown. */
3739 if (vport->load_flag & FC_UNLOADING)
3740 goto dropit;
3741
James Smart2e0fef82007-06-17 19:56:36 -05003742 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003743 if (!ndlp) {
dea31012005-04-17 16:05:31 -05003744 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003745 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
James Smarted957682007-06-17 19:56:37 -05003746 if (!ndlp)
dea31012005-04-17 16:05:31 -05003747 goto dropit;
dea31012005-04-17 16:05:31 -05003748
James Smart2e0fef82007-06-17 19:56:36 -05003749 lpfc_nlp_init(vport, ndlp, did);
dea31012005-04-17 16:05:31 -05003750 newnode = 1;
3751 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) {
3752 ndlp->nlp_type |= NLP_FABRIC;
3753 }
James Smart2e0fef82007-06-17 19:56:36 -05003754 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE);
dea31012005-04-17 16:05:31 -05003755 }
3756
3757 phba->fc_stat.elsRcvFrame++;
James Smart329f9bc2007-04-25 09:53:01 -04003758 if (elsiocb->context1)
3759 lpfc_nlp_put(elsiocb->context1);
3760 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05003761 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -05003762
3763 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
3764 cmd &= ELS_CMD_MASK;
3765 }
3766 /* ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04003767 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3768 "0112 ELS command x%x received from NPORT x%x "
3769 "Data: x%x\n", cmd, did, vport->port_state);
dea31012005-04-17 16:05:31 -05003770 switch (cmd) {
3771 case ELS_CMD_PLOGI:
James Smart858c9f62007-06-17 19:56:39 -05003772 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3773 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
3774 did, vport->port_state, ndlp->nlp_flag);
3775
dea31012005-04-17 16:05:31 -05003776 phba->fc_stat.elsRcvPLOGI++;
James Smart858c9f62007-06-17 19:56:39 -05003777 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
3778
3779 if (vport->port_state < LPFC_DISC_AUTH) {
3780 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05003781 break;
3782 }
James Smart2e0fef82007-06-17 19:56:36 -05003783 lpfc_disc_state_machine(vport, ndlp, elsiocb,
3784 NLP_EVT_RCV_PLOGI);
James Smart858c9f62007-06-17 19:56:39 -05003785
dea31012005-04-17 16:05:31 -05003786 break;
3787 case ELS_CMD_FLOGI:
James Smart858c9f62007-06-17 19:56:39 -05003788 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3789 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
3790 did, vport->port_state, ndlp->nlp_flag);
3791
dea31012005-04-17 16:05:31 -05003792 phba->fc_stat.elsRcvFLOGI++;
James Smart51ef4c22007-08-02 11:10:31 -04003793 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04003794 if (newnode)
James Smart2e0fef82007-06-17 19:56:36 -05003795 lpfc_drop_node(vport, ndlp);
dea31012005-04-17 16:05:31 -05003796 break;
3797 case ELS_CMD_LOGO:
James Smart858c9f62007-06-17 19:56:39 -05003798 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3799 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
3800 did, vport->port_state, ndlp->nlp_flag);
3801
dea31012005-04-17 16:05:31 -05003802 phba->fc_stat.elsRcvLOGO++;
James Smart2e0fef82007-06-17 19:56:36 -05003803 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05003804 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05003805 break;
3806 }
James Smart2e0fef82007-06-17 19:56:36 -05003807 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
dea31012005-04-17 16:05:31 -05003808 break;
3809 case ELS_CMD_PRLO:
James Smart858c9f62007-06-17 19:56:39 -05003810 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3811 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
3812 did, vport->port_state, ndlp->nlp_flag);
3813
dea31012005-04-17 16:05:31 -05003814 phba->fc_stat.elsRcvPRLO++;
James Smart2e0fef82007-06-17 19:56:36 -05003815 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05003816 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05003817 break;
3818 }
James Smart2e0fef82007-06-17 19:56:36 -05003819 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
dea31012005-04-17 16:05:31 -05003820 break;
3821 case ELS_CMD_RSCN:
3822 phba->fc_stat.elsRcvRSCN++;
James Smart51ef4c22007-08-02 11:10:31 -04003823 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04003824 if (newnode)
James Smart2e0fef82007-06-17 19:56:36 -05003825 lpfc_drop_node(vport, ndlp);
dea31012005-04-17 16:05:31 -05003826 break;
3827 case ELS_CMD_ADISC:
James Smart858c9f62007-06-17 19:56:39 -05003828 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3829 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
3830 did, vport->port_state, ndlp->nlp_flag);
3831
dea31012005-04-17 16:05:31 -05003832 phba->fc_stat.elsRcvADISC++;
James Smart2e0fef82007-06-17 19:56:36 -05003833 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05003834 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05003835 break;
3836 }
James Smart2e0fef82007-06-17 19:56:36 -05003837 lpfc_disc_state_machine(vport, ndlp, elsiocb,
3838 NLP_EVT_RCV_ADISC);
dea31012005-04-17 16:05:31 -05003839 break;
3840 case ELS_CMD_PDISC:
James Smart858c9f62007-06-17 19:56:39 -05003841 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3842 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
3843 did, vport->port_state, ndlp->nlp_flag);
3844
dea31012005-04-17 16:05:31 -05003845 phba->fc_stat.elsRcvPDISC++;
James Smart2e0fef82007-06-17 19:56:36 -05003846 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05003847 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05003848 break;
3849 }
James Smart2e0fef82007-06-17 19:56:36 -05003850 lpfc_disc_state_machine(vport, ndlp, elsiocb,
3851 NLP_EVT_RCV_PDISC);
dea31012005-04-17 16:05:31 -05003852 break;
3853 case ELS_CMD_FARPR:
James Smart858c9f62007-06-17 19:56:39 -05003854 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3855 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
3856 did, vport->port_state, ndlp->nlp_flag);
3857
dea31012005-04-17 16:05:31 -05003858 phba->fc_stat.elsRcvFARPR++;
James Smart2e0fef82007-06-17 19:56:36 -05003859 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05003860 break;
3861 case ELS_CMD_FARP:
James Smart858c9f62007-06-17 19:56:39 -05003862 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3863 "RCV FARP: did:x%x/ste:x%x flg:x%x",
3864 did, vport->port_state, ndlp->nlp_flag);
3865
dea31012005-04-17 16:05:31 -05003866 phba->fc_stat.elsRcvFARP++;
James Smart2e0fef82007-06-17 19:56:36 -05003867 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05003868 break;
3869 case ELS_CMD_FAN:
James Smart858c9f62007-06-17 19:56:39 -05003870 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3871 "RCV FAN: did:x%x/ste:x%x flg:x%x",
3872 did, vport->port_state, ndlp->nlp_flag);
3873
dea31012005-04-17 16:05:31 -05003874 phba->fc_stat.elsRcvFAN++;
James Smart2e0fef82007-06-17 19:56:36 -05003875 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05003876 break;
dea31012005-04-17 16:05:31 -05003877 case ELS_CMD_PRLI:
James Smart858c9f62007-06-17 19:56:39 -05003878 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3879 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
3880 did, vport->port_state, ndlp->nlp_flag);
3881
dea31012005-04-17 16:05:31 -05003882 phba->fc_stat.elsRcvPRLI++;
James Smart2e0fef82007-06-17 19:56:36 -05003883 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05003884 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05003885 break;
3886 }
James Smart2e0fef82007-06-17 19:56:36 -05003887 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
dea31012005-04-17 16:05:31 -05003888 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003889 case ELS_CMD_LIRR:
James Smart858c9f62007-06-17 19:56:39 -05003890 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3891 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
3892 did, vport->port_state, ndlp->nlp_flag);
3893
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003894 phba->fc_stat.elsRcvLIRR++;
James Smart2e0fef82007-06-17 19:56:36 -05003895 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04003896 if (newnode)
James Smart2e0fef82007-06-17 19:56:36 -05003897 lpfc_drop_node(vport, ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003898 break;
3899 case ELS_CMD_RPS:
James Smart858c9f62007-06-17 19:56:39 -05003900 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3901 "RCV RPS: did:x%x/ste:x%x flg:x%x",
3902 did, vport->port_state, ndlp->nlp_flag);
3903
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003904 phba->fc_stat.elsRcvRPS++;
James Smart2e0fef82007-06-17 19:56:36 -05003905 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04003906 if (newnode)
James Smart2e0fef82007-06-17 19:56:36 -05003907 lpfc_drop_node(vport, ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003908 break;
3909 case ELS_CMD_RPL:
James Smart858c9f62007-06-17 19:56:39 -05003910 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3911 "RCV RPL: did:x%x/ste:x%x flg:x%x",
3912 did, vport->port_state, ndlp->nlp_flag);
3913
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003914 phba->fc_stat.elsRcvRPL++;
James Smart2e0fef82007-06-17 19:56:36 -05003915 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04003916 if (newnode)
James Smart2e0fef82007-06-17 19:56:36 -05003917 lpfc_drop_node(vport, ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003918 break;
dea31012005-04-17 16:05:31 -05003919 case ELS_CMD_RNID:
James Smart858c9f62007-06-17 19:56:39 -05003920 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3921 "RCV RNID: did:x%x/ste:x%x flg:x%x",
3922 did, vport->port_state, ndlp->nlp_flag);
3923
dea31012005-04-17 16:05:31 -05003924 phba->fc_stat.elsRcvRNID++;
James Smart2e0fef82007-06-17 19:56:36 -05003925 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04003926 if (newnode)
James Smart2e0fef82007-06-17 19:56:36 -05003927 lpfc_drop_node(vport, ndlp);
dea31012005-04-17 16:05:31 -05003928 break;
3929 default:
James Smart858c9f62007-06-17 19:56:39 -05003930 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3931 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
3932 cmd, did, vport->port_state);
3933
dea31012005-04-17 16:05:31 -05003934 /* Unsupported ELS command, reject */
James Smart858c9f62007-06-17 19:56:39 -05003935 rjt_err = LSRJT_INVALID_CMD;
dea31012005-04-17 16:05:31 -05003936
3937 /* Unknown ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04003938 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3939 "0115 Unknown ELS command x%x "
3940 "received from NPORT x%x\n", cmd, did);
James Smartde0c5b32007-04-25 09:52:27 -04003941 if (newnode)
James Smart2e0fef82007-06-17 19:56:36 -05003942 lpfc_drop_node(vport, ndlp);
dea31012005-04-17 16:05:31 -05003943 break;
3944 }
3945
3946 /* check if need to LS_RJT received ELS cmd */
3947 if (rjt_err) {
James Smart92d7f7b2007-06-17 19:56:38 -05003948 memset(&stat, 0, sizeof(stat));
James Smart858c9f62007-06-17 19:56:39 -05003949 stat.un.b.lsRjtRsnCode = rjt_err;
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04003950 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart858c9f62007-06-17 19:56:39 -05003951 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
3952 NULL);
dea31012005-04-17 16:05:31 -05003953 }
3954
James Smarted957682007-06-17 19:56:37 -05003955 return;
3956
3957dropit:
3958 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
James Smarte8b62012007-08-02 11:10:09 -04003959 "(%d):0111 Dropping received ELS cmd "
James Smarted957682007-06-17 19:56:37 -05003960 "Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04003961 vport ? vport->vpi : 0xffff, icmd->ulpStatus,
3962 icmd->un.ulpWord[4], icmd->ulpTimeout);
James Smarted957682007-06-17 19:56:37 -05003963 phba->fc_stat.elsRcvDrop++;
3964}
3965
James Smart92d7f7b2007-06-17 19:56:38 -05003966static struct lpfc_vport *
3967lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
3968{
3969 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -04003970 unsigned long flags;
James Smart92d7f7b2007-06-17 19:56:38 -05003971
James Smart549e55c2007-08-02 11:09:51 -04003972 spin_lock_irqsave(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05003973 list_for_each_entry(vport, &phba->port_list, listentry) {
James Smart549e55c2007-08-02 11:09:51 -04003974 if (vport->vpi == vpi) {
3975 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05003976 return vport;
James Smart549e55c2007-08-02 11:09:51 -04003977 }
James Smart92d7f7b2007-06-17 19:56:38 -05003978 }
James Smart549e55c2007-08-02 11:09:51 -04003979 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05003980 return NULL;
3981}
James Smarted957682007-06-17 19:56:37 -05003982
3983void
3984lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3985 struct lpfc_iocbq *elsiocb)
3986{
3987 struct lpfc_vport *vport = phba->pport;
James Smarted957682007-06-17 19:56:37 -05003988 IOCB_t *icmd = &elsiocb->iocb;
James Smarted957682007-06-17 19:56:37 -05003989 dma_addr_t paddr;
James Smart92d7f7b2007-06-17 19:56:38 -05003990 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
3991 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
James Smarted957682007-06-17 19:56:37 -05003992
James Smart92d7f7b2007-06-17 19:56:38 -05003993 elsiocb->context2 = NULL;
3994 elsiocb->context3 = NULL;
3995
3996 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
3997 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
3998 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
3999 (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) {
James Smarted957682007-06-17 19:56:37 -05004000 phba->fc_stat.NoRcvBuf++;
4001 /* Not enough posted buffers; Try posting more buffers */
James Smart92d7f7b2007-06-17 19:56:38 -05004002 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
James Smarted957682007-06-17 19:56:37 -05004003 lpfc_post_buffer(phba, pring, 0, 1);
4004 return;
4005 }
4006
James Smart92d7f7b2007-06-17 19:56:38 -05004007 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
4008 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
4009 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
4010 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
4011 vport = phba->pport;
4012 else {
4013 uint16_t vpi = icmd->unsli3.rcvsli3.vpi;
4014 vport = lpfc_find_vport_by_vpid(phba, vpi);
4015 }
4016 }
4017 /* If there are no BDEs associated
4018 * with this IOCB, there is nothing to do.
4019 */
James Smarted957682007-06-17 19:56:37 -05004020 if (icmd->ulpBdeCount == 0)
4021 return;
4022
James Smart92d7f7b2007-06-17 19:56:38 -05004023 /* type of ELS cmd is first 32bit word
4024 * in packet
4025 */
James Smarted957682007-06-17 19:56:37 -05004026 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05004027 elsiocb->context2 = bdeBuf1;
James Smarted957682007-06-17 19:56:37 -05004028 } else {
4029 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
4030 icmd->un.cont64[0].addrLow);
James Smart92d7f7b2007-06-17 19:56:38 -05004031 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
4032 paddr);
James Smarted957682007-06-17 19:56:37 -05004033 }
4034
James Smart92d7f7b2007-06-17 19:56:38 -05004035 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
4036 /*
4037 * The different unsolicited event handlers would tell us
4038 * if they are done with "mp" by setting context2 to NULL.
4039 */
James Smart329f9bc2007-04-25 09:53:01 -04004040 lpfc_nlp_put(elsiocb->context1);
4041 elsiocb->context1 = NULL;
dea31012005-04-17 16:05:31 -05004042 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05004043 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
4044 elsiocb->context2 = NULL;
dea31012005-04-17 16:05:31 -05004045 }
James Smarted957682007-06-17 19:56:37 -05004046
4047 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
James Smart92d7f7b2007-06-17 19:56:38 -05004048 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
James Smarted957682007-06-17 19:56:37 -05004049 icmd->ulpBdeCount == 2) {
James Smart92d7f7b2007-06-17 19:56:38 -05004050 elsiocb->context2 = bdeBuf2;
4051 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
James Smarted957682007-06-17 19:56:37 -05004052 /* free mp if we are done with it */
4053 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05004054 lpfc_in_buf_free(phba, elsiocb->context2);
4055 elsiocb->context2 = NULL;
James Smarted957682007-06-17 19:56:37 -05004056 }
dea31012005-04-17 16:05:31 -05004057 }
dea31012005-04-17 16:05:31 -05004058}
James Smart92d7f7b2007-06-17 19:56:38 -05004059
4060void
4061lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
4062{
4063 struct lpfc_nodelist *ndlp, *ndlp_fdmi;
4064
4065 ndlp = lpfc_findnode_did(vport, NameServer_DID);
4066 if (!ndlp) {
4067 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
4068 if (!ndlp) {
4069 if (phba->fc_topology == TOPOLOGY_LOOP) {
4070 lpfc_disc_start(vport);
4071 return;
4072 }
4073 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04004074 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4075 "0251 NameServer login: no memory\n");
James Smart92d7f7b2007-06-17 19:56:38 -05004076 return;
4077 }
4078 lpfc_nlp_init(vport, ndlp, NameServer_DID);
4079 ndlp->nlp_type |= NLP_FABRIC;
4080 }
4081
4082 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
4083
4084 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
4085 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04004086 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4087 "0252 Cannot issue NameServer login\n");
James Smart92d7f7b2007-06-17 19:56:38 -05004088 return;
4089 }
4090
James Smart3de2a652007-08-02 11:09:59 -04004091 if (vport->cfg_fdmi_on) {
James Smart92d7f7b2007-06-17 19:56:38 -05004092 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
4093 GFP_KERNEL);
4094 if (ndlp_fdmi) {
4095 lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
4096 ndlp_fdmi->nlp_type |= NLP_FABRIC;
4097 ndlp_fdmi->nlp_state =
4098 NLP_STE_PLOGI_ISSUE;
4099 lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID,
4100 0);
4101 }
4102 }
4103 return;
4104}
4105
4106static void
4107lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4108{
4109 struct lpfc_vport *vport = pmb->vport;
4110 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4111 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
4112 MAILBOX_t *mb = &pmb->mb;
4113
4114 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
4115 lpfc_nlp_put(ndlp);
4116
4117 if (mb->mbxStatus) {
James Smarte8b62012007-08-02 11:10:09 -04004118 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
4119 "0915 Register VPI failed: 0x%x\n",
4120 mb->mbxStatus);
James Smart92d7f7b2007-06-17 19:56:38 -05004121
4122 switch (mb->mbxStatus) {
4123 case 0x11: /* unsupported feature */
4124 case 0x9603: /* max_vpi exceeded */
4125 /* giving up on vport registration */
4126 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4127 spin_lock_irq(shost->host_lock);
4128 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
4129 spin_unlock_irq(shost->host_lock);
4130 lpfc_can_disctmo(vport);
4131 break;
4132 default:
4133 /* Try to recover from this error */
4134 lpfc_mbx_unreg_vpi(vport);
4135 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
4136 lpfc_initial_fdisc(vport);
4137 break;
4138 }
4139
4140 } else {
4141 if (vport == phba->pport)
4142 lpfc_issue_fabric_reglogin(vport);
4143 else
4144 lpfc_do_scr_ns_plogi(phba, vport);
4145 }
4146 mempool_free(pmb, phba->mbox_mem_pool);
4147 return;
4148}
4149
4150void
4151lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
4152 struct lpfc_nodelist *ndlp)
4153{
4154 LPFC_MBOXQ_t *mbox;
4155
4156 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4157 if (mbox) {
4158 lpfc_reg_vpi(phba, vport->vpi, vport->fc_myDID, mbox);
4159 mbox->vport = vport;
4160 mbox->context2 = lpfc_nlp_get(ndlp);
4161 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
James Smart0b727fe2007-10-27 13:37:25 -04004162 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart92d7f7b2007-06-17 19:56:38 -05004163 == MBX_NOT_FINISHED) {
4164 mempool_free(mbox, phba->mbox_mem_pool);
4165 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
4166
4167 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04004168 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
4169 "0253 Register VPI: Can't send mbox\n");
James Smart92d7f7b2007-06-17 19:56:38 -05004170 }
4171 } else {
4172 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4173
James Smarte8b62012007-08-02 11:10:09 -04004174 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
4175 "0254 Register VPI: no memory\n");
James Smart92d7f7b2007-06-17 19:56:38 -05004176
4177 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
4178 lpfc_nlp_put(ndlp);
4179 }
4180}
4181
4182static void
4183lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4184 struct lpfc_iocbq *rspiocb)
4185{
4186 struct lpfc_vport *vport = cmdiocb->vport;
4187 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4188 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
4189 struct lpfc_nodelist *np;
4190 struct lpfc_nodelist *next_np;
4191 IOCB_t *irsp = &rspiocb->iocb;
4192 struct lpfc_iocbq *piocb;
4193
James Smarte8b62012007-08-02 11:10:09 -04004194 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4195 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
4196 irsp->ulpStatus, irsp->un.ulpWord[4],
4197 vport->fc_prevDID);
James Smart92d7f7b2007-06-17 19:56:38 -05004198 /* Since all FDISCs are being single threaded, we
4199 * must reset the discovery timer for ALL vports
4200 * waiting to send FDISC when one completes.
4201 */
4202 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
4203 lpfc_set_disctmo(piocb->vport);
4204 }
4205
James Smart858c9f62007-06-17 19:56:39 -05004206 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4207 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
4208 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
4209
James Smart92d7f7b2007-06-17 19:56:38 -05004210 if (irsp->ulpStatus) {
4211 /* Check for retry */
4212 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
4213 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05004214 /* FDISC failed */
James Smarte8b62012007-08-02 11:10:09 -04004215 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4216 "0124 FDISC failed. (%d/%d)\n",
4217 irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smart92d7f7b2007-06-17 19:56:38 -05004218 if (vport->fc_vport->vport_state == FC_VPORT_INITIALIZING)
4219 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4220
4221 lpfc_nlp_put(ndlp);
4222 /* giving up on FDISC. Cancel discovery timer */
4223 lpfc_can_disctmo(vport);
4224 } else {
4225 spin_lock_irq(shost->host_lock);
4226 vport->fc_flag |= FC_FABRIC;
4227 if (vport->phba->fc_topology == TOPOLOGY_LOOP)
4228 vport->fc_flag |= FC_PUBLIC_LOOP;
4229 spin_unlock_irq(shost->host_lock);
4230
4231 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
4232 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
4233 if ((vport->fc_prevDID != vport->fc_myDID) &&
4234 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
4235 /* If our NportID changed, we need to ensure all
4236 * remaining NPORTs get unreg_login'ed so we can
4237 * issue unreg_vpi.
4238 */
4239 list_for_each_entry_safe(np, next_np,
4240 &vport->fc_nodes, nlp_listp) {
4241 if (np->nlp_state != NLP_STE_NPR_NODE
4242 || !(np->nlp_flag & NLP_NPR_ADISC))
4243 continue;
4244 spin_lock_irq(shost->host_lock);
4245 np->nlp_flag &= ~NLP_NPR_ADISC;
4246 spin_unlock_irq(shost->host_lock);
4247 lpfc_unreg_rpi(vport, np);
4248 }
4249 lpfc_mbx_unreg_vpi(vport);
4250 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
4251 }
4252
4253 if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
4254 lpfc_register_new_vport(phba, vport, ndlp);
4255 else
4256 lpfc_do_scr_ns_plogi(phba, vport);
4257
4258 lpfc_nlp_put(ndlp); /* Free Fabric ndlp for vports */
4259 }
4260
4261out:
4262 lpfc_els_free_iocb(phba, cmdiocb);
4263}
4264
4265int
4266lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4267 uint8_t retry)
4268{
4269 struct lpfc_hba *phba = vport->phba;
4270 IOCB_t *icmd;
4271 struct lpfc_iocbq *elsiocb;
4272 struct serv_parm *sp;
4273 uint8_t *pcmd;
4274 uint16_t cmdsize;
4275 int did = ndlp->nlp_DID;
4276 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05004277
4278 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
4279 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
4280 ELS_CMD_FDISC);
4281 if (!elsiocb) {
James Smart92d7f7b2007-06-17 19:56:38 -05004282 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04004283 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4284 "0255 Issue FDISC: no IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05004285 return 1;
4286 }
4287
4288 icmd = &elsiocb->iocb;
4289 icmd->un.elsreq64.myID = 0;
4290 icmd->un.elsreq64.fl = 1;
4291
4292 /* For FDISC, Let FDISC rsp set the NPortID for this VPI */
4293 icmd->ulpCt_h = 1;
4294 icmd->ulpCt_l = 0;
4295
4296 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4297 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
4298 pcmd += sizeof(uint32_t); /* CSP Word 1 */
4299 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
4300 sp = (struct serv_parm *) pcmd;
4301 /* Setup CSPs accordingly for Fabric */
4302 sp->cmn.e_d_tov = 0;
4303 sp->cmn.w2.r_a_tov = 0;
4304 sp->cls1.classValid = 0;
4305 sp->cls2.seqDelivery = 1;
4306 sp->cls3.seqDelivery = 1;
4307
4308 pcmd += sizeof(uint32_t); /* CSP Word 2 */
4309 pcmd += sizeof(uint32_t); /* CSP Word 3 */
4310 pcmd += sizeof(uint32_t); /* CSP Word 4 */
4311 pcmd += sizeof(uint32_t); /* Port Name */
4312 memcpy(pcmd, &vport->fc_portname, 8);
4313 pcmd += sizeof(uint32_t); /* Node Name */
4314 pcmd += sizeof(uint32_t); /* Node Name */
4315 memcpy(pcmd, &vport->fc_nodename, 8);
4316
4317 lpfc_set_disctmo(vport);
4318
4319 phba->fc_stat.elsXmitFDISC++;
4320 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
4321
James Smart858c9f62007-06-17 19:56:39 -05004322 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4323 "Issue FDISC: did:x%x",
4324 did, 0, 0);
4325
James Smart92d7f7b2007-06-17 19:56:38 -05004326 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
4327 if (rc == IOCB_ERROR) {
4328 lpfc_els_free_iocb(phba, elsiocb);
James Smart92d7f7b2007-06-17 19:56:38 -05004329 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04004330 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4331 "0256 Issue FDISC: Cannot send IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05004332 return 1;
4333 }
4334 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
4335 vport->port_state = LPFC_FDISC;
4336 return 0;
4337}
4338
4339static void
4340lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4341 struct lpfc_iocbq *rspiocb)
4342{
4343 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05004344 IOCB_t *irsp;
4345
4346 irsp = &rspiocb->iocb;
4347 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4348 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
4349 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
James Smart92d7f7b2007-06-17 19:56:38 -05004350
4351 lpfc_els_free_iocb(phba, cmdiocb);
4352 vport->unreg_vpi_cmpl = VPORT_ERROR;
4353}
4354
4355int
4356lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4357{
4358 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4359 struct lpfc_hba *phba = vport->phba;
4360 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
4361 IOCB_t *icmd;
4362 struct lpfc_iocbq *elsiocb;
4363 uint8_t *pcmd;
4364 uint16_t cmdsize;
4365
4366 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
4367 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
4368 ELS_CMD_LOGO);
4369 if (!elsiocb)
4370 return 1;
4371
4372 icmd = &elsiocb->iocb;
4373 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4374 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
4375 pcmd += sizeof(uint32_t);
4376
4377 /* Fill in LOGO payload */
4378 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
4379 pcmd += sizeof(uint32_t);
4380 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
4381
James Smart858c9f62007-06-17 19:56:39 -05004382 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4383 "Issue LOGO npiv did:x%x flg:x%x",
4384 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4385
James Smart92d7f7b2007-06-17 19:56:38 -05004386 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
4387 spin_lock_irq(shost->host_lock);
4388 ndlp->nlp_flag |= NLP_LOGO_SND;
4389 spin_unlock_irq(shost->host_lock);
4390 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
4391 spin_lock_irq(shost->host_lock);
4392 ndlp->nlp_flag &= ~NLP_LOGO_SND;
4393 spin_unlock_irq(shost->host_lock);
4394 lpfc_els_free_iocb(phba, elsiocb);
4395 return 1;
4396 }
4397 return 0;
4398}
4399
4400void
4401lpfc_fabric_block_timeout(unsigned long ptr)
4402{
4403 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
4404 unsigned long iflags;
4405 uint32_t tmo_posted;
4406 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
4407 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
4408 if (!tmo_posted)
4409 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
4410 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
4411
4412 if (!tmo_posted) {
4413 spin_lock_irqsave(&phba->hbalock, iflags);
4414 if (phba->work_wait)
4415 lpfc_worker_wake_up(phba);
4416 spin_unlock_irqrestore(&phba->hbalock, iflags);
4417 }
4418}
4419
4420static void
4421lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
4422{
4423 struct lpfc_iocbq *iocb;
4424 unsigned long iflags;
4425 int ret;
4426 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
4427 IOCB_t *cmd;
4428
4429repeat:
4430 iocb = NULL;
4431 spin_lock_irqsave(&phba->hbalock, iflags);
4432 /* Post any pending iocb to the SLI layer */
4433 if (atomic_read(&phba->fabric_iocb_count) == 0) {
4434 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
4435 list);
4436 if (iocb)
4437 atomic_inc(&phba->fabric_iocb_count);
4438 }
4439 spin_unlock_irqrestore(&phba->hbalock, iflags);
4440 if (iocb) {
4441 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
4442 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
4443 iocb->iocb_flag |= LPFC_IO_FABRIC;
4444
James Smart858c9f62007-06-17 19:56:39 -05004445 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
4446 "Fabric sched1: ste:x%x",
4447 iocb->vport->port_state, 0, 0);
4448
James Smart92d7f7b2007-06-17 19:56:38 -05004449 ret = lpfc_sli_issue_iocb(phba, pring, iocb, 0);
4450
4451 if (ret == IOCB_ERROR) {
4452 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
4453 iocb->fabric_iocb_cmpl = NULL;
4454 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
4455 cmd = &iocb->iocb;
4456 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
4457 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
4458 iocb->iocb_cmpl(phba, iocb, iocb);
4459
4460 atomic_dec(&phba->fabric_iocb_count);
4461 goto repeat;
4462 }
4463 }
4464
4465 return;
4466}
4467
4468void
4469lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
4470{
4471 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
4472
4473 lpfc_resume_fabric_iocbs(phba);
4474 return;
4475}
4476
4477static void
4478lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
4479{
4480 int blocked;
4481
4482 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
4483 /* Start a timer to unblock fabric
4484 * iocbs after 100ms
4485 */
4486 if (!blocked)
4487 mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 );
4488
4489 return;
4490}
4491
4492static void
4493lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4494 struct lpfc_iocbq *rspiocb)
4495{
4496 struct ls_rjt stat;
4497
4498 if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
4499 BUG();
4500
4501 switch (rspiocb->iocb.ulpStatus) {
4502 case IOSTAT_NPORT_RJT:
4503 case IOSTAT_FABRIC_RJT:
4504 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
4505 lpfc_block_fabric_iocbs(phba);
4506 }
4507 break;
4508
4509 case IOSTAT_NPORT_BSY:
4510 case IOSTAT_FABRIC_BSY:
4511 lpfc_block_fabric_iocbs(phba);
4512 break;
4513
4514 case IOSTAT_LS_RJT:
4515 stat.un.lsRjtError =
4516 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
4517 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
4518 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
4519 lpfc_block_fabric_iocbs(phba);
4520 break;
4521 }
4522
4523 if (atomic_read(&phba->fabric_iocb_count) == 0)
4524 BUG();
4525
4526 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
4527 cmdiocb->fabric_iocb_cmpl = NULL;
4528 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
4529 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
4530
4531 atomic_dec(&phba->fabric_iocb_count);
4532 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
4533 /* Post any pending iocbs to HBA */
4534 lpfc_resume_fabric_iocbs(phba);
4535 }
4536}
4537
4538int
4539lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
4540{
4541 unsigned long iflags;
4542 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
4543 int ready;
4544 int ret;
4545
4546 if (atomic_read(&phba->fabric_iocb_count) > 1)
4547 BUG();
4548
4549 spin_lock_irqsave(&phba->hbalock, iflags);
4550 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
4551 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
4552
4553 spin_unlock_irqrestore(&phba->hbalock, iflags);
4554 if (ready) {
4555 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
4556 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
4557 iocb->iocb_flag |= LPFC_IO_FABRIC;
4558
James Smart858c9f62007-06-17 19:56:39 -05004559 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
4560 "Fabric sched2: ste:x%x",
4561 iocb->vport->port_state, 0, 0);
4562
James Smart92d7f7b2007-06-17 19:56:38 -05004563 atomic_inc(&phba->fabric_iocb_count);
4564 ret = lpfc_sli_issue_iocb(phba, pring, iocb, 0);
4565
4566 if (ret == IOCB_ERROR) {
4567 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
4568 iocb->fabric_iocb_cmpl = NULL;
4569 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
4570 atomic_dec(&phba->fabric_iocb_count);
4571 }
4572 } else {
4573 spin_lock_irqsave(&phba->hbalock, iflags);
4574 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
4575 spin_unlock_irqrestore(&phba->hbalock, iflags);
4576 ret = IOCB_SUCCESS;
4577 }
4578 return ret;
4579}
4580
4581
4582void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
4583{
4584 LIST_HEAD(completions);
4585 struct lpfc_hba *phba = vport->phba;
4586 struct lpfc_iocbq *tmp_iocb, *piocb;
4587 IOCB_t *cmd;
4588
4589 spin_lock_irq(&phba->hbalock);
4590 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
4591 list) {
4592
4593 if (piocb->vport != vport)
4594 continue;
4595
4596 list_move_tail(&piocb->list, &completions);
4597 }
4598 spin_unlock_irq(&phba->hbalock);
4599
4600 while (!list_empty(&completions)) {
4601 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
4602 list_del_init(&piocb->list);
4603
4604 cmd = &piocb->iocb;
4605 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
4606 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
4607 (piocb->iocb_cmpl) (phba, piocb, piocb);
4608 }
4609}
4610
4611void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
4612{
4613 LIST_HEAD(completions);
4614 struct lpfc_hba *phba = ndlp->vport->phba;
4615 struct lpfc_iocbq *tmp_iocb, *piocb;
4616 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
4617 IOCB_t *cmd;
4618
4619 spin_lock_irq(&phba->hbalock);
4620 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
4621 list) {
4622 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
4623
4624 list_move_tail(&piocb->list, &completions);
4625 }
4626 }
4627 spin_unlock_irq(&phba->hbalock);
4628
4629 while (!list_empty(&completions)) {
4630 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
4631 list_del_init(&piocb->list);
4632
4633 cmd = &piocb->iocb;
4634 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
4635 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
4636 (piocb->iocb_cmpl) (phba, piocb, piocb);
4637 }
4638}
4639
4640void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
4641{
4642 LIST_HEAD(completions);
4643 struct lpfc_iocbq *piocb;
4644 IOCB_t *cmd;
4645
4646 spin_lock_irq(&phba->hbalock);
4647 list_splice_init(&phba->fabric_iocb_list, &completions);
4648 spin_unlock_irq(&phba->hbalock);
4649
4650 while (!list_empty(&completions)) {
4651 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
4652 list_del_init(&piocb->list);
4653
4654 cmd = &piocb->iocb;
4655 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
4656 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
4657 (piocb->iocb_cmpl) (phba, piocb, piocb);
4658 }
4659}
4660
4661
4662void lpfc_fabric_abort_flogi(struct lpfc_hba *phba)
4663{
4664 LIST_HEAD(completions);
4665 struct lpfc_iocbq *tmp_iocb, *piocb;
4666 IOCB_t *cmd;
4667 struct lpfc_nodelist *ndlp;
4668
4669 spin_lock_irq(&phba->hbalock);
4670 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
4671 list) {
4672
4673 cmd = &piocb->iocb;
4674 ndlp = (struct lpfc_nodelist *) piocb->context1;
4675 if (cmd->ulpCommand == CMD_ELS_REQUEST64_CR &&
4676 ndlp != NULL &&
4677 ndlp->nlp_DID == Fabric_DID)
4678 list_move_tail(&piocb->list, &completions);
4679 }
4680 spin_unlock_irq(&phba->hbalock);
4681
4682 while (!list_empty(&completions)) {
4683 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
4684 list_del_init(&piocb->list);
4685
4686 cmd = &piocb->iocb;
4687 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
4688 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
4689 (piocb->iocb_cmpl) (phba, piocb, piocb);
4690 }
4691}
4692
4693