blob: 8085900635d4876fd100b7930f41651af584abd1 [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
252 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT | MBX_STOP_IOCB);
253 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
268 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT | MBX_STOP_IOCB);
269 if (rc == MBX_NOT_FINISHED)
270 goto fail_issue_reg_login;
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;
dea31012005-04-17 16:05:31 -0500432 rc = lpfc_sli_issue_mbox(phba, mbox,
James Smart92d7f7b2007-06-17 19:56:38 -0500433 MBX_NOWAIT | MBX_STOP_IOCB);
dea31012005-04-17 16:05:31 -0500434 if (rc == MBX_NOT_FINISHED) {
435 mempool_free(mbox, phba->mbox_mem_pool);
436 goto fail;
437 }
James Smart329f9bc2007-04-25 09:53:01 -0400438 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500439
James Smart2e0fef82007-06-17 19:56:36 -0500440 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
dea31012005-04-17 16:05:31 -0500441 if (!ndlp) {
442 /*
443 * Cannot find existing Fabric ndlp, so allocate a
444 * new one
445 */
446 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
447 if (!ndlp)
448 goto fail;
449
James Smart2e0fef82007-06-17 19:56:36 -0500450 lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID);
dea31012005-04-17 16:05:31 -0500451 }
452
453 memcpy(&ndlp->nlp_portname, &sp->portName,
James Smart2e0fef82007-06-17 19:56:36 -0500454 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500455 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
James Smart2e0fef82007-06-17 19:56:36 -0500456 sizeof(struct lpfc_name));
457 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
458 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500459 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500460 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500461 } else {
462 /* This side will wait for the PLOGI */
James Smart329f9bc2007-04-25 09:53:01 -0400463 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500464 }
465
James Smart2e0fef82007-06-17 19:56:36 -0500466 spin_lock_irq(shost->host_lock);
467 vport->fc_flag |= FC_PT2PT;
468 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500469
470 /* Start discovery - this should just do CLEAR_LA */
James Smart2e0fef82007-06-17 19:56:36 -0500471 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -0500472 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500473fail:
dea31012005-04-17 16:05:31 -0500474 return -ENXIO;
475}
476
477static void
James Smart329f9bc2007-04-25 09:53:01 -0400478lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
479 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500480{
James Smart2e0fef82007-06-17 19:56:36 -0500481 struct lpfc_vport *vport = cmdiocb->vport;
482 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500483 IOCB_t *irsp = &rspiocb->iocb;
484 struct lpfc_nodelist *ndlp = cmdiocb->context1;
485 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
486 struct serv_parm *sp;
487 int rc;
488
489 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500490 if (lpfc_els_chk_latt(vport)) {
James Smart329f9bc2007-04-25 09:53:01 -0400491 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500492 goto out;
493 }
494
James Smart858c9f62007-06-17 19:56:39 -0500495 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
496 "FLOGI cmpl: status:x%x/x%x state:x%x",
497 irsp->ulpStatus, irsp->un.ulpWord[4],
498 vport->port_state);
499
dea31012005-04-17 16:05:31 -0500500 if (irsp->ulpStatus) {
501 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -0500502 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -0500503 goto out;
James Smart2e0fef82007-06-17 19:56:36 -0500504
dea31012005-04-17 16:05:31 -0500505 /* FLOGI failed, so there is no fabric */
James Smart2e0fef82007-06-17 19:56:36 -0500506 spin_lock_irq(shost->host_lock);
507 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
508 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500509
James Smart329f9bc2007-04-25 09:53:01 -0400510 /* If private loop, then allow max outstanding els to be
dea31012005-04-17 16:05:31 -0500511 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
512 * alpa map would take too long otherwise.
513 */
514 if (phba->alpa_map[0] == 0) {
James Smart3de2a652007-08-02 11:09:59 -0400515 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
dea31012005-04-17 16:05:31 -0500516 }
517
518 /* FLOGI failure */
James Smarte8b62012007-08-02 11:10:09 -0400519 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
520 "0100 FLOGI failure Data: x%x x%x "
521 "x%x\n",
522 irsp->ulpStatus, irsp->un.ulpWord[4],
523 irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -0500524 goto flogifail;
525 }
526
527 /*
528 * The FLogI succeeded. Sync the data for the CPU before
529 * accessing it.
530 */
531 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
532
533 sp = prsp->virt + sizeof(uint32_t);
534
535 /* FLOGI completes successfully */
James Smarte8b62012007-08-02 11:10:09 -0400536 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
537 "0101 FLOGI completes sucessfully "
538 "Data: x%x x%x x%x x%x\n",
539 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
540 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution);
dea31012005-04-17 16:05:31 -0500541
James Smart2e0fef82007-06-17 19:56:36 -0500542 if (vport->port_state == LPFC_FLOGI) {
dea31012005-04-17 16:05:31 -0500543 /*
544 * If Common Service Parameters indicate Nport
545 * we are point to point, if Fport we are Fabric.
546 */
547 if (sp->cmn.fPort)
James Smart2e0fef82007-06-17 19:56:36 -0500548 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
dea31012005-04-17 16:05:31 -0500549 else
James Smart2e0fef82007-06-17 19:56:36 -0500550 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
dea31012005-04-17 16:05:31 -0500551
552 if (!rc)
553 goto out;
554 }
555
556flogifail:
James Smart329f9bc2007-04-25 09:53:01 -0400557 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500558
James Smart858c9f62007-06-17 19:56:39 -0500559 if (!lpfc_error_lost_link(irsp)) {
dea31012005-04-17 16:05:31 -0500560 /* FLOGI failed, so just use loop map to make discovery list */
James Smart2e0fef82007-06-17 19:56:36 -0500561 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -0500562
563 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500564 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -0500565 }
566
567out:
568 lpfc_els_free_iocb(phba, cmdiocb);
569}
570
571static int
James Smart2e0fef82007-06-17 19:56:36 -0500572lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -0500573 uint8_t retry)
574{
James Smart2e0fef82007-06-17 19:56:36 -0500575 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500576 struct serv_parm *sp;
577 IOCB_t *icmd;
578 struct lpfc_iocbq *elsiocb;
579 struct lpfc_sli_ring *pring;
580 uint8_t *pcmd;
581 uint16_t cmdsize;
582 uint32_t tmo;
583 int rc;
584
585 pring = &phba->sli.ring[LPFC_ELS_RING];
586
James Smart92d7f7b2007-06-17 19:56:38 -0500587 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart2e0fef82007-06-17 19:56:36 -0500588 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
589 ndlp->nlp_DID, ELS_CMD_FLOGI);
James Smart92d7f7b2007-06-17 19:56:38 -0500590
James Smart488d1462006-03-07 15:02:37 -0500591 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500592 return 1;
dea31012005-04-17 16:05:31 -0500593
594 icmd = &elsiocb->iocb;
595 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
596
597 /* For FLOGI request, remainder of payload is service parameters */
598 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -0500599 pcmd += sizeof(uint32_t);
600 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -0500601 sp = (struct serv_parm *) pcmd;
602
603 /* Setup CSPs accordingly for Fabric */
604 sp->cmn.e_d_tov = 0;
605 sp->cmn.w2.r_a_tov = 0;
606 sp->cls1.classValid = 0;
607 sp->cls2.seqDelivery = 1;
608 sp->cls3.seqDelivery = 1;
609 if (sp->cmn.fcphLow < FC_PH3)
610 sp->cmn.fcphLow = FC_PH3;
611 if (sp->cmn.fcphHigh < FC_PH3)
612 sp->cmn.fcphHigh = FC_PH3;
613
James Smart92d7f7b2007-06-17 19:56:38 -0500614 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
615 sp->cmn.request_multiple_Nport = 1;
616
617 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
618 icmd->ulpCt_h = 1;
619 icmd->ulpCt_l = 0;
620 }
621
James Smart858c9f62007-06-17 19:56:39 -0500622 if (phba->fc_topology != TOPOLOGY_LOOP) {
623 icmd->un.elsreq64.myID = 0;
624 icmd->un.elsreq64.fl = 1;
625 }
626
dea31012005-04-17 16:05:31 -0500627 tmo = phba->fc_ratov;
628 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
James Smart2e0fef82007-06-17 19:56:36 -0500629 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -0500630 phba->fc_ratov = tmo;
631
632 phba->fc_stat.elsXmitFLOGI++;
633 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
James Smart858c9f62007-06-17 19:56:39 -0500634
635 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
636 "Issue FLOGI: opt:x%x",
637 phba->sli3_options, 0, 0);
638
James Smart92d7f7b2007-06-17 19:56:38 -0500639 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
dea31012005-04-17 16:05:31 -0500640 if (rc == IOCB_ERROR) {
641 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500642 return 1;
dea31012005-04-17 16:05:31 -0500643 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500644 return 0;
dea31012005-04-17 16:05:31 -0500645}
646
647int
James Smart2e0fef82007-06-17 19:56:36 -0500648lpfc_els_abort_flogi(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500649{
650 struct lpfc_sli_ring *pring;
651 struct lpfc_iocbq *iocb, *next_iocb;
652 struct lpfc_nodelist *ndlp;
653 IOCB_t *icmd;
654
655 /* Abort outstanding I/O on NPort <nlp_DID> */
656 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -0400657 "0201 Abort outstanding I/O on NPort x%x\n",
658 Fabric_DID);
dea31012005-04-17 16:05:31 -0500659
660 pring = &phba->sli.ring[LPFC_ELS_RING];
661
662 /*
663 * Check the txcmplq for an iocb that matches the nport the driver is
664 * searching for.
665 */
James Smart2e0fef82007-06-17 19:56:36 -0500666 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500667 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
668 icmd = &iocb->iocb;
James Smart2e0fef82007-06-17 19:56:36 -0500669 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR &&
670 icmd->un.elsreq64.bdl.ulpIoTag32) {
dea31012005-04-17 16:05:31 -0500671 ndlp = (struct lpfc_nodelist *)(iocb->context1);
James Smart92d7f7b2007-06-17 19:56:38 -0500672 if (ndlp && (ndlp->nlp_DID == Fabric_DID)) {
James Smart07951072007-04-25 09:51:38 -0400673 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
James Smart92d7f7b2007-06-17 19:56:38 -0500674 }
dea31012005-04-17 16:05:31 -0500675 }
676 }
James Smart2e0fef82007-06-17 19:56:36 -0500677 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500678
679 return 0;
680}
681
682int
James Smart2e0fef82007-06-17 19:56:36 -0500683lpfc_initial_flogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -0500684{
James Smart2e0fef82007-06-17 19:56:36 -0500685 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500686 struct lpfc_nodelist *ndlp;
687
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500688 /* First look for the Fabric ndlp */
James Smart2e0fef82007-06-17 19:56:36 -0500689 ndlp = lpfc_findnode_did(vport, Fabric_DID);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500690 if (!ndlp) {
dea31012005-04-17 16:05:31 -0500691 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500692 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
693 if (!ndlp)
694 return 0;
James Smart2e0fef82007-06-17 19:56:36 -0500695 lpfc_nlp_init(vport, ndlp, Fabric_DID);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500696 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500697 lpfc_dequeue_node(vport, ndlp);
dea31012005-04-17 16:05:31 -0500698 }
James Smart2e0fef82007-06-17 19:56:36 -0500699 if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
James Smart329f9bc2007-04-25 09:53:01 -0400700 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500701 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500702 return 1;
dea31012005-04-17 16:05:31 -0500703}
704
James Smart92d7f7b2007-06-17 19:56:38 -0500705int
706lpfc_initial_fdisc(struct lpfc_vport *vport)
707{
708 struct lpfc_hba *phba = vport->phba;
709 struct lpfc_nodelist *ndlp;
710
711 /* First look for the Fabric ndlp */
712 ndlp = lpfc_findnode_did(vport, Fabric_DID);
713 if (!ndlp) {
714 /* Cannot find existing Fabric ndlp, so allocate a new one */
715 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
716 if (!ndlp)
717 return 0;
718 lpfc_nlp_init(vport, ndlp, Fabric_DID);
719 } else {
720 lpfc_dequeue_node(vport, ndlp);
721 }
722 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
723 lpfc_nlp_put(ndlp);
724 }
725 return 1;
726}
dea31012005-04-17 16:05:31 -0500727static void
James Smart2e0fef82007-06-17 19:56:36 -0500728lpfc_more_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -0500729{
730 int sentplogi;
731
James Smart2e0fef82007-06-17 19:56:36 -0500732 if (vport->num_disc_nodes)
733 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -0500734
735 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
James Smarte8b62012007-08-02 11:10:09 -0400736 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
737 "0232 Continue discovery with %d PLOGIs to go "
738 "Data: x%x x%x x%x\n",
739 vport->num_disc_nodes, vport->fc_plogi_cnt,
740 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -0500741 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -0500742 if (vport->fc_flag & FC_NLP_MORE)
743 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
744 sentplogi = lpfc_els_disc_plogi(vport);
745
dea31012005-04-17 16:05:31 -0500746 return;
747}
748
James Smart488d1462006-03-07 15:02:37 -0500749static struct lpfc_nodelist *
James Smart92d7f7b2007-06-17 19:56:38 -0500750lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
James Smart488d1462006-03-07 15:02:37 -0500751 struct lpfc_nodelist *ndlp)
752{
James Smart2e0fef82007-06-17 19:56:36 -0500753 struct lpfc_vport *vport = ndlp->vport;
James Smart488d1462006-03-07 15:02:37 -0500754 struct lpfc_nodelist *new_ndlp;
James Smart488d1462006-03-07 15:02:37 -0500755 struct serv_parm *sp;
James Smart92d7f7b2007-06-17 19:56:38 -0500756 uint8_t name[sizeof(struct lpfc_name)];
James Smart488d1462006-03-07 15:02:37 -0500757 uint32_t rc;
758
James Smart2fb9bd82006-12-02 13:33:57 -0500759 /* Fabric nodes can have the same WWPN so we don't bother searching
760 * by WWPN. Just return the ndlp that was given to us.
761 */
762 if (ndlp->nlp_type & NLP_FABRIC)
763 return ndlp;
764
James Smart92d7f7b2007-06-17 19:56:38 -0500765 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
James Smart685f0bf2007-04-25 09:53:08 -0400766 memset(name, 0, sizeof(struct lpfc_name));
James Smart488d1462006-03-07 15:02:37 -0500767
James Smart685f0bf2007-04-25 09:53:08 -0400768 /* Now we find out if the NPort we are logging into, matches the WWPN
James Smart488d1462006-03-07 15:02:37 -0500769 * we have for that ndlp. If not, we have some work to do.
770 */
James Smart2e0fef82007-06-17 19:56:36 -0500771 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
James Smart488d1462006-03-07 15:02:37 -0500772
James Smart92795652006-07-06 15:50:02 -0400773 if (new_ndlp == ndlp)
James Smart488d1462006-03-07 15:02:37 -0500774 return ndlp;
James Smart488d1462006-03-07 15:02:37 -0500775
776 if (!new_ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -0500777 rc = memcmp(&ndlp->nlp_portname, name,
778 sizeof(struct lpfc_name));
James Smart92795652006-07-06 15:50:02 -0400779 if (!rc)
780 return ndlp;
James Smart488d1462006-03-07 15:02:37 -0500781 new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
782 if (!new_ndlp)
783 return ndlp;
784
James Smart2e0fef82007-06-17 19:56:36 -0500785 lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID);
James Smart488d1462006-03-07 15:02:37 -0500786 }
787
James Smart2e0fef82007-06-17 19:56:36 -0500788 lpfc_unreg_rpi(vport, new_ndlp);
James Smart488d1462006-03-07 15:02:37 -0500789 new_ndlp->nlp_DID = ndlp->nlp_DID;
James Smart92795652006-07-06 15:50:02 -0400790 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
James Smart2e0fef82007-06-17 19:56:36 -0500791 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
James Smart488d1462006-03-07 15:02:37 -0500792
James Smart2e0fef82007-06-17 19:56:36 -0500793 /* Move this back to NPR state */
James Smartde0c5b32007-04-25 09:52:27 -0400794 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0)
James Smart2e0fef82007-06-17 19:56:36 -0500795 lpfc_drop_node(vport, ndlp);
James Smart92795652006-07-06 15:50:02 -0400796 else {
James Smart2e0fef82007-06-17 19:56:36 -0500797 lpfc_unreg_rpi(vport, ndlp);
James Smart92795652006-07-06 15:50:02 -0400798 ndlp->nlp_DID = 0; /* Two ndlps cannot have the same did */
James Smart2e0fef82007-06-17 19:56:36 -0500799 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smart92795652006-07-06 15:50:02 -0400800 }
James Smart488d1462006-03-07 15:02:37 -0500801 return new_ndlp;
802}
803
dea31012005-04-17 16:05:31 -0500804static void
James Smart2e0fef82007-06-17 19:56:36 -0500805lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
806 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500807{
James Smart2e0fef82007-06-17 19:56:36 -0500808 struct lpfc_vport *vport = cmdiocb->vport;
809 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500810 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -0500811 struct lpfc_nodelist *ndlp;
James Smart92795652006-07-06 15:50:02 -0400812 struct lpfc_dmabuf *prsp;
dea31012005-04-17 16:05:31 -0500813 int disc, rc, did, type;
814
dea31012005-04-17 16:05:31 -0500815 /* we pass cmdiocb to state machine which needs rspiocb as well */
816 cmdiocb->context_un.rsp_iocb = rspiocb;
817
818 irsp = &rspiocb->iocb;
James Smart858c9f62007-06-17 19:56:39 -0500819 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
820 "PLOGI cmpl: status:x%x/x%x did:x%x",
821 irsp->ulpStatus, irsp->un.ulpWord[4],
822 irsp->un.elsreq64.remoteID);
823
James Smart2e0fef82007-06-17 19:56:36 -0500824 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
James Smarted957682007-06-17 19:56:37 -0500825 if (!ndlp) {
James Smarte8b62012007-08-02 11:10:09 -0400826 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
827 "0136 PLOGI completes to NPort x%x "
828 "with no ndlp. Data: x%x x%x x%x\n",
829 irsp->un.elsreq64.remoteID,
830 irsp->ulpStatus, irsp->un.ulpWord[4],
831 irsp->ulpIoTag);
James Smart488d1462006-03-07 15:02:37 -0500832 goto out;
James Smarted957682007-06-17 19:56:37 -0500833 }
dea31012005-04-17 16:05:31 -0500834
835 /* Since ndlp can be freed in the disc state machine, note if this node
836 * is being used during discovery.
837 */
James Smart2e0fef82007-06-17 19:56:36 -0500838 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500839 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
James Smart488d1462006-03-07 15:02:37 -0500840 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500841 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500842 rc = 0;
843
844 /* PLOGI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -0400845 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
846 "0102 PLOGI completes to NPort x%x "
847 "Data: x%x x%x x%x x%x x%x\n",
848 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
849 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -0500850 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500851 if (lpfc_els_chk_latt(vport)) {
852 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500853 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500854 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500855 goto out;
856 }
857
858 /* ndlp could be freed in DSM, save these values now */
859 type = ndlp->nlp_type;
860 did = ndlp->nlp_DID;
861
862 if (irsp->ulpStatus) {
863 /* Check for retry */
864 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
865 /* ELS command is being retried */
866 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -0500867 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500868 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500869 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500870 }
871 goto out;
872 }
dea31012005-04-17 16:05:31 -0500873 /* PLOGI failed */
James Smart92d7f7b2007-06-17 19:56:38 -0500874 if (ndlp->nlp_DID == NameServer_DID) {
875 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -0400876 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
877 "0250 Nameserver login error: "
878 "0x%x / 0x%x\n",
879 irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smart92d7f7b2007-06-17 19:56:38 -0500880 }
dea31012005-04-17 16:05:31 -0500881 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart858c9f62007-06-17 19:56:39 -0500882 if (lpfc_error_lost_link(irsp)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500883 rc = NLP_STE_FREED_NODE;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500884 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500885 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -0500886 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -0500887 }
888 } else {
889 /* Good status, call state machine */
James Smart92795652006-07-06 15:50:02 -0400890 prsp = list_entry(((struct lpfc_dmabuf *)
James Smart92d7f7b2007-06-17 19:56:38 -0500891 cmdiocb->context2)->list.next,
892 struct lpfc_dmabuf, list);
893 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -0500894 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -0500895 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -0500896 }
897
James Smart2e0fef82007-06-17 19:56:36 -0500898 if (disc && vport->num_disc_nodes) {
dea31012005-04-17 16:05:31 -0500899 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -0500900 lpfc_more_plogi(vport);
dea31012005-04-17 16:05:31 -0500901
James Smart2e0fef82007-06-17 19:56:36 -0500902 if (vport->num_disc_nodes == 0) {
903 spin_lock_irq(shost->host_lock);
904 vport->fc_flag &= ~FC_NDISC_ACTIVE;
905 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500906
James Smart2e0fef82007-06-17 19:56:36 -0500907 lpfc_can_disctmo(vport);
908 if (vport->fc_flag & FC_RSCN_MODE) {
James Smart10d4e952006-04-15 11:53:15 -0400909 /*
910 * Check to see if more RSCNs came in while
911 * we were processing this one.
912 */
James Smart2e0fef82007-06-17 19:56:36 -0500913 if ((vport->fc_rscn_id_cnt == 0) &&
914 (!(vport->fc_flag & FC_RSCN_DISCOVERY))) {
915 spin_lock_irq(shost->host_lock);
916 vport->fc_flag &= ~FC_RSCN_MODE;
917 spin_unlock_irq(shost->host_lock);
James Smart10d4e952006-04-15 11:53:15 -0400918 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500919 lpfc_els_handle_rscn(vport);
James Smart10d4e952006-04-15 11:53:15 -0400920 }
dea31012005-04-17 16:05:31 -0500921 }
922 }
923 }
924
925out:
926 lpfc_els_free_iocb(phba, cmdiocb);
927 return;
928}
929
930int
James Smart2e0fef82007-06-17 19:56:36 -0500931lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
dea31012005-04-17 16:05:31 -0500932{
James Smart2e0fef82007-06-17 19:56:36 -0500933 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500934 struct serv_parm *sp;
935 IOCB_t *icmd;
936 struct lpfc_iocbq *elsiocb;
937 struct lpfc_sli_ring *pring;
938 struct lpfc_sli *psli;
939 uint8_t *pcmd;
940 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -0500941 int ret;
dea31012005-04-17 16:05:31 -0500942
943 psli = &phba->sli;
944 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
945
James Smart92d7f7b2007-06-17 19:56:38 -0500946 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart2e0fef82007-06-17 19:56:36 -0500947 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, NULL, did,
948 ELS_CMD_PLOGI);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500949 if (!elsiocb)
950 return 1;
dea31012005-04-17 16:05:31 -0500951
952 icmd = &elsiocb->iocb;
953 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
954
955 /* For PLOGI request, remainder of payload is service parameters */
956 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -0500957 pcmd += sizeof(uint32_t);
958 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -0500959 sp = (struct serv_parm *) pcmd;
960
961 if (sp->cmn.fcphLow < FC_PH_4_3)
962 sp->cmn.fcphLow = FC_PH_4_3;
963
964 if (sp->cmn.fcphHigh < FC_PH3)
965 sp->cmn.fcphHigh = FC_PH3;
966
James Smart858c9f62007-06-17 19:56:39 -0500967 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
968 "Issue PLOGI: did:x%x",
969 did, 0, 0);
970
dea31012005-04-17 16:05:31 -0500971 phba->fc_stat.elsXmitPLOGI++;
972 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
James Smart92d7f7b2007-06-17 19:56:38 -0500973 ret = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
974
975 if (ret == IOCB_ERROR) {
dea31012005-04-17 16:05:31 -0500976 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500977 return 1;
dea31012005-04-17 16:05:31 -0500978 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500979 return 0;
dea31012005-04-17 16:05:31 -0500980}
981
982static void
James Smart2e0fef82007-06-17 19:56:36 -0500983lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
984 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500985{
James Smart2e0fef82007-06-17 19:56:36 -0500986 struct lpfc_vport *vport = cmdiocb->vport;
987 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500988 IOCB_t *irsp;
989 struct lpfc_sli *psli;
990 struct lpfc_nodelist *ndlp;
991
992 psli = &phba->sli;
993 /* we pass cmdiocb to state machine which needs rspiocb as well */
994 cmdiocb->context_un.rsp_iocb = rspiocb;
995
996 irsp = &(rspiocb->iocb);
997 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
James Smart2e0fef82007-06-17 19:56:36 -0500998 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500999 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001000 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001001
James Smart858c9f62007-06-17 19:56:39 -05001002 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1003 "PRLI cmpl: status:x%x/x%x did:x%x",
1004 irsp->ulpStatus, irsp->un.ulpWord[4],
1005 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05001006 /* PRLI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001007 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1008 "0103 PRLI completes to NPort x%x "
1009 "Data: x%x x%x x%x x%x\n",
1010 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1011 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001012
James Smart2e0fef82007-06-17 19:56:36 -05001013 vport->fc_prli_sent--;
dea31012005-04-17 16:05:31 -05001014 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001015 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05001016 goto out;
1017
1018 if (irsp->ulpStatus) {
1019 /* Check for retry */
1020 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1021 /* ELS command is being retried */
1022 goto out;
1023 }
1024 /* PRLI failed */
1025 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart858c9f62007-06-17 19:56:39 -05001026 if (lpfc_error_lost_link(irsp)) {
dea31012005-04-17 16:05:31 -05001027 goto out;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001028 } else {
James Smart2e0fef82007-06-17 19:56:36 -05001029 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001030 NLP_EVT_CMPL_PRLI);
dea31012005-04-17 16:05:31 -05001031 }
1032 } else {
1033 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05001034 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001035 NLP_EVT_CMPL_PRLI);
dea31012005-04-17 16:05:31 -05001036 }
1037
1038out:
1039 lpfc_els_free_iocb(phba, cmdiocb);
1040 return;
1041}
1042
1043int
James Smart2e0fef82007-06-17 19:56:36 -05001044lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001045 uint8_t retry)
1046{
James Smart2e0fef82007-06-17 19:56:36 -05001047 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1048 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001049 PRLI *npr;
1050 IOCB_t *icmd;
1051 struct lpfc_iocbq *elsiocb;
1052 struct lpfc_sli_ring *pring;
1053 struct lpfc_sli *psli;
1054 uint8_t *pcmd;
1055 uint16_t cmdsize;
1056
1057 psli = &phba->sli;
1058 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1059
James Smart92d7f7b2007-06-17 19:56:38 -05001060 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
James Smart2e0fef82007-06-17 19:56:36 -05001061 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1062 ndlp->nlp_DID, ELS_CMD_PRLI);
James Smart488d1462006-03-07 15:02:37 -05001063 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001064 return 1;
dea31012005-04-17 16:05:31 -05001065
1066 icmd = &elsiocb->iocb;
1067 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1068
1069 /* For PRLI request, remainder of payload is service parameters */
James Smart92d7f7b2007-06-17 19:56:38 -05001070 memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t)));
dea31012005-04-17 16:05:31 -05001071 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
James Smart92d7f7b2007-06-17 19:56:38 -05001072 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001073
1074 /* For PRLI, remainder of payload is PRLI parameter page */
1075 npr = (PRLI *) pcmd;
1076 /*
1077 * If our firmware version is 3.20 or later,
1078 * set the following bits for FC-TAPE support.
1079 */
1080 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
1081 npr->ConfmComplAllowed = 1;
1082 npr->Retry = 1;
1083 npr->TaskRetryIdReq = 1;
1084 }
1085 npr->estabImagePair = 1;
1086 npr->readXferRdyDis = 1;
1087
1088 /* For FCP support */
1089 npr->prliType = PRLI_FCP_TYPE;
1090 npr->initiatorFunc = 1;
1091
James Smart858c9f62007-06-17 19:56:39 -05001092 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1093 "Issue PRLI: did:x%x",
1094 ndlp->nlp_DID, 0, 0);
1095
dea31012005-04-17 16:05:31 -05001096 phba->fc_stat.elsXmitPRLI++;
1097 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
James Smart2e0fef82007-06-17 19:56:36 -05001098 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001099 ndlp->nlp_flag |= NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001100 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001101 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05001102 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001103 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001104 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001105 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001106 return 1;
dea31012005-04-17 16:05:31 -05001107 }
James Smart2e0fef82007-06-17 19:56:36 -05001108 vport->fc_prli_sent++;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001109 return 0;
dea31012005-04-17 16:05:31 -05001110}
1111
1112static void
James Smart2e0fef82007-06-17 19:56:36 -05001113lpfc_more_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001114{
1115 int sentadisc;
1116
James Smart2e0fef82007-06-17 19:56:36 -05001117 if (vport->num_disc_nodes)
1118 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001119 /* Continue discovery with <num_disc_nodes> ADISCs to go */
James Smarte8b62012007-08-02 11:10:09 -04001120 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1121 "0210 Continue discovery with %d ADISCs to go "
1122 "Data: x%x x%x x%x\n",
1123 vport->num_disc_nodes, vport->fc_adisc_cnt,
1124 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001125 /* Check to see if there are more ADISCs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001126 if (vport->fc_flag & FC_NLP_MORE) {
1127 lpfc_set_disctmo(vport);
1128 /* go thru NPR nodes and issue any remaining ELS ADISCs */
1129 sentadisc = lpfc_els_disc_adisc(vport);
dea31012005-04-17 16:05:31 -05001130 }
1131 return;
1132}
1133
1134static void
James Smart2e0fef82007-06-17 19:56:36 -05001135lpfc_rscn_disc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001136{
James Smart2e0fef82007-06-17 19:56:36 -05001137 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1138
James Smart858c9f62007-06-17 19:56:39 -05001139 lpfc_can_disctmo(vport);
1140
dea31012005-04-17 16:05:31 -05001141 /* RSCN discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001142 /* go thru NPR nodes and issue ELS PLOGIs */
1143 if (vport->fc_npr_cnt)
1144 if (lpfc_els_disc_plogi(vport))
dea31012005-04-17 16:05:31 -05001145 return;
James Smart2e0fef82007-06-17 19:56:36 -05001146
1147 if (vport->fc_flag & FC_RSCN_MODE) {
dea31012005-04-17 16:05:31 -05001148 /* Check to see if more RSCNs came in while we were
1149 * processing this one.
1150 */
James Smart2e0fef82007-06-17 19:56:36 -05001151 if ((vport->fc_rscn_id_cnt == 0) &&
1152 (!(vport->fc_flag & FC_RSCN_DISCOVERY))) {
1153 spin_lock_irq(shost->host_lock);
1154 vport->fc_flag &= ~FC_RSCN_MODE;
1155 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001156 } else {
James Smart2e0fef82007-06-17 19:56:36 -05001157 lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05001158 }
1159 }
1160}
1161
1162static void
James Smart2e0fef82007-06-17 19:56:36 -05001163lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1164 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001165{
James Smart2e0fef82007-06-17 19:56:36 -05001166 struct lpfc_vport *vport = cmdiocb->vport;
1167 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001168 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001169 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001170 int disc;
dea31012005-04-17 16:05:31 -05001171
1172 /* we pass cmdiocb to state machine which needs rspiocb as well */
1173 cmdiocb->context_un.rsp_iocb = rspiocb;
1174
1175 irsp = &(rspiocb->iocb);
1176 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
dea31012005-04-17 16:05:31 -05001177
James Smart858c9f62007-06-17 19:56:39 -05001178 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1179 "ADISC cmpl: status:x%x/x%x did:x%x",
1180 irsp->ulpStatus, irsp->un.ulpWord[4],
1181 ndlp->nlp_DID);
1182
dea31012005-04-17 16:05:31 -05001183 /* Since ndlp can be freed in the disc state machine, note if this node
1184 * is being used during discovery.
1185 */
James Smart2e0fef82007-06-17 19:56:36 -05001186 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001187 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001188 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001189 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001190 /* ADISC completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001191 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1192 "0104 ADISC completes to NPort x%x "
1193 "Data: x%x x%x x%x x%x x%x\n",
1194 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1195 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001196 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001197 if (lpfc_els_chk_latt(vport)) {
1198 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001199 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001200 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001201 goto out;
1202 }
1203
1204 if (irsp->ulpStatus) {
1205 /* Check for retry */
1206 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1207 /* ELS command is being retried */
1208 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05001209 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001210 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001211 spin_unlock_irq(shost->host_lock);
1212 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001213 }
1214 goto out;
1215 }
1216 /* ADISC failed */
1217 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart858c9f62007-06-17 19:56:39 -05001218 if (!lpfc_error_lost_link(irsp)) {
James Smart2e0fef82007-06-17 19:56:36 -05001219 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart858c9f62007-06-17 19:56:39 -05001220 NLP_EVT_CMPL_ADISC);
dea31012005-04-17 16:05:31 -05001221 }
1222 } else {
1223 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05001224 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
dea31012005-04-17 16:05:31 -05001225 NLP_EVT_CMPL_ADISC);
1226 }
1227
James Smart2e0fef82007-06-17 19:56:36 -05001228 if (disc && vport->num_disc_nodes) {
dea31012005-04-17 16:05:31 -05001229 /* Check to see if there are more ADISCs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001230 lpfc_more_adisc(vport);
dea31012005-04-17 16:05:31 -05001231
1232 /* Check to see if we are done with ADISC authentication */
James Smart2e0fef82007-06-17 19:56:36 -05001233 if (vport->num_disc_nodes == 0) {
James Smart92d7f7b2007-06-17 19:56:38 -05001234 /* If we get here, there is nothing left to ADISC */
1235 /*
1236 * For NPIV, cmpl_reg_vpi will set port_state to READY,
1237 * and continue discovery.
1238 */
1239 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
1240 !(vport->fc_flag & FC_RSCN_MODE)) {
1241 lpfc_issue_reg_vpi(phba, vport);
1242 goto out;
1243 }
1244 /*
1245 * For SLI2, we need to set port_state to READY
1246 * and continue discovery.
1247 */
1248 if (vport->port_state < LPFC_VPORT_READY) {
1249 /* If we get here, there is nothing to ADISC */
James Smarted957682007-06-17 19:56:37 -05001250 if (vport->port_type == LPFC_PHYSICAL_PORT)
James Smart2e0fef82007-06-17 19:56:36 -05001251 lpfc_issue_clear_la(phba, vport);
James Smart92d7f7b2007-06-17 19:56:38 -05001252
1253 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
1254 vport->num_disc_nodes = 0;
1255 /* go thru NPR list, issue ELS PLOGIs */
1256 if (vport->fc_npr_cnt)
1257 lpfc_els_disc_plogi(vport);
1258
1259 if (!vport->num_disc_nodes) {
1260 spin_lock_irq(shost->host_lock);
1261 vport->fc_flag &=
1262 ~FC_NDISC_ACTIVE;
1263 spin_unlock_irq(
1264 shost->host_lock);
1265 lpfc_can_disctmo(vport);
1266 }
1267 }
1268 vport->port_state = LPFC_VPORT_READY;
dea31012005-04-17 16:05:31 -05001269 } else {
James Smart2e0fef82007-06-17 19:56:36 -05001270 lpfc_rscn_disc(vport);
dea31012005-04-17 16:05:31 -05001271 }
1272 }
1273 }
dea31012005-04-17 16:05:31 -05001274out:
1275 lpfc_els_free_iocb(phba, cmdiocb);
1276 return;
1277}
1278
1279int
James Smart2e0fef82007-06-17 19:56:36 -05001280lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001281 uint8_t retry)
1282{
James Smart2e0fef82007-06-17 19:56:36 -05001283 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1284 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001285 ADISC *ap;
1286 IOCB_t *icmd;
1287 struct lpfc_iocbq *elsiocb;
James Smart2e0fef82007-06-17 19:56:36 -05001288 struct lpfc_sli *psli = &phba->sli;
1289 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05001290 uint8_t *pcmd;
1291 uint16_t cmdsize;
1292
James Smart92d7f7b2007-06-17 19:56:38 -05001293 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
James Smart2e0fef82007-06-17 19:56:36 -05001294 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1295 ndlp->nlp_DID, ELS_CMD_ADISC);
James Smart488d1462006-03-07 15:02:37 -05001296 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001297 return 1;
dea31012005-04-17 16:05:31 -05001298
1299 icmd = &elsiocb->iocb;
1300 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1301
1302 /* For ADISC request, remainder of payload is service parameters */
1303 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
James Smart92d7f7b2007-06-17 19:56:38 -05001304 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001305
1306 /* Fill in ADISC payload */
1307 ap = (ADISC *) pcmd;
1308 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05001309 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
1310 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05001311 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05001312
James Smart858c9f62007-06-17 19:56:39 -05001313 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1314 "Issue ADISC: did:x%x",
1315 ndlp->nlp_DID, 0, 0);
1316
dea31012005-04-17 16:05:31 -05001317 phba->fc_stat.elsXmitADISC++;
1318 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
James Smart2e0fef82007-06-17 19:56:36 -05001319 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001320 ndlp->nlp_flag |= NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001321 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001322 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05001323 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001324 ndlp->nlp_flag &= ~NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001325 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001326 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001327 return 1;
dea31012005-04-17 16:05:31 -05001328 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001329 return 0;
dea31012005-04-17 16:05:31 -05001330}
1331
1332static void
James Smart2e0fef82007-06-17 19:56:36 -05001333lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1334 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001335{
James Smart2e0fef82007-06-17 19:56:36 -05001336 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1337 struct lpfc_vport *vport = ndlp->vport;
1338 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001339 IOCB_t *irsp;
1340 struct lpfc_sli *psli;
dea31012005-04-17 16:05:31 -05001341
1342 psli = &phba->sli;
1343 /* we pass cmdiocb to state machine which needs rspiocb as well */
1344 cmdiocb->context_un.rsp_iocb = rspiocb;
1345
1346 irsp = &(rspiocb->iocb);
James Smart2e0fef82007-06-17 19:56:36 -05001347 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001348 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001349 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001350
James Smart858c9f62007-06-17 19:56:39 -05001351 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1352 "LOGO cmpl: status:x%x/x%x did:x%x",
1353 irsp->ulpStatus, irsp->un.ulpWord[4],
1354 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05001355 /* LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001356 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1357 "0105 LOGO completes to NPort x%x "
1358 "Data: x%x x%x x%x x%x\n",
1359 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1360 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001361 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001362 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05001363 goto out;
1364
James Smart92d7f7b2007-06-17 19:56:38 -05001365 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
1366 /* NLP_EVT_DEVICE_RM should unregister the RPI
1367 * which should abort all outstanding IOs.
1368 */
1369 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1370 NLP_EVT_DEVICE_RM);
1371 goto out;
1372 }
1373
dea31012005-04-17 16:05:31 -05001374 if (irsp->ulpStatus) {
1375 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -05001376 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -05001377 /* ELS command is being retried */
1378 goto out;
dea31012005-04-17 16:05:31 -05001379 /* LOGO failed */
1380 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart858c9f62007-06-17 19:56:39 -05001381 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05001382 goto out;
James Smart858c9f62007-06-17 19:56:39 -05001383 else
James Smart2e0fef82007-06-17 19:56:36 -05001384 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001385 NLP_EVT_CMPL_LOGO);
dea31012005-04-17 16:05:31 -05001386 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001387 /* Good status, call state machine.
1388 * This will unregister the rpi if needed.
1389 */
James Smart2e0fef82007-06-17 19:56:36 -05001390 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001391 NLP_EVT_CMPL_LOGO);
dea31012005-04-17 16:05:31 -05001392 }
1393
1394out:
1395 lpfc_els_free_iocb(phba, cmdiocb);
1396 return;
1397}
1398
1399int
James Smart2e0fef82007-06-17 19:56:36 -05001400lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001401 uint8_t retry)
1402{
James Smart2e0fef82007-06-17 19:56:36 -05001403 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1404 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001405 IOCB_t *icmd;
1406 struct lpfc_iocbq *elsiocb;
1407 struct lpfc_sli_ring *pring;
1408 struct lpfc_sli *psli;
1409 uint8_t *pcmd;
1410 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05001411 int rc;
dea31012005-04-17 16:05:31 -05001412
1413 psli = &phba->sli;
1414 pring = &psli->ring[LPFC_ELS_RING];
1415
James Smart92d7f7b2007-06-17 19:56:38 -05001416 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
James Smart2e0fef82007-06-17 19:56:36 -05001417 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1418 ndlp->nlp_DID, ELS_CMD_LOGO);
James Smart488d1462006-03-07 15:02:37 -05001419 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001420 return 1;
dea31012005-04-17 16:05:31 -05001421
1422 icmd = &elsiocb->iocb;
1423 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1424 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
James Smart92d7f7b2007-06-17 19:56:38 -05001425 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001426
1427 /* Fill in LOGO payload */
James Smart2e0fef82007-06-17 19:56:36 -05001428 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05001429 pcmd += sizeof(uint32_t);
1430 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05001431
James Smart858c9f62007-06-17 19:56:39 -05001432 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1433 "Issue LOGO: did:x%x",
1434 ndlp->nlp_DID, 0, 0);
1435
dea31012005-04-17 16:05:31 -05001436 phba->fc_stat.elsXmitLOGO++;
1437 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
James Smart2e0fef82007-06-17 19:56:36 -05001438 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001439 ndlp->nlp_flag |= NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001440 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05001441 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
1442
1443 if (rc == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05001444 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001445 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001446 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001447 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001448 return 1;
dea31012005-04-17 16:05:31 -05001449 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001450 return 0;
dea31012005-04-17 16:05:31 -05001451}
1452
1453static void
James Smart2e0fef82007-06-17 19:56:36 -05001454lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1455 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001456{
James Smart2e0fef82007-06-17 19:56:36 -05001457 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -05001458 IOCB_t *irsp;
1459
1460 irsp = &rspiocb->iocb;
1461
James Smart858c9f62007-06-17 19:56:39 -05001462 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1463 "ELS cmd cmpl: status:x%x/x%x did:x%x",
1464 irsp->ulpStatus, irsp->un.ulpWord[4],
1465 irsp->un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05001466 /* ELS cmd tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04001467 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1468 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
1469 irsp->ulpIoTag, irsp->ulpStatus,
1470 irsp->un.ulpWord[4], irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -05001471 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001472 lpfc_els_chk_latt(vport);
dea31012005-04-17 16:05:31 -05001473 lpfc_els_free_iocb(phba, cmdiocb);
1474 return;
1475}
1476
1477int
James Smart2e0fef82007-06-17 19:56:36 -05001478lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05001479{
James Smart2e0fef82007-06-17 19:56:36 -05001480 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001481 IOCB_t *icmd;
1482 struct lpfc_iocbq *elsiocb;
1483 struct lpfc_sli_ring *pring;
1484 struct lpfc_sli *psli;
1485 uint8_t *pcmd;
1486 uint16_t cmdsize;
1487 struct lpfc_nodelist *ndlp;
1488
1489 psli = &phba->sli;
1490 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
James Smart92d7f7b2007-06-17 19:56:38 -05001491 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001492 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1493 if (!ndlp)
1494 return 1;
dea31012005-04-17 16:05:31 -05001495
James Smart2e0fef82007-06-17 19:56:36 -05001496 lpfc_nlp_init(vport, ndlp, nportid);
dea31012005-04-17 16:05:31 -05001497
James Smart2e0fef82007-06-17 19:56:36 -05001498 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1499 ndlp->nlp_DID, ELS_CMD_SCR);
1500
James Smart488d1462006-03-07 15:02:37 -05001501 if (!elsiocb) {
James Smart329f9bc2007-04-25 09:53:01 -04001502 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001503 return 1;
dea31012005-04-17 16:05:31 -05001504 }
1505
1506 icmd = &elsiocb->iocb;
1507 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1508
1509 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
James Smart92d7f7b2007-06-17 19:56:38 -05001510 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001511
1512 /* For SCR, remainder of payload is SCR parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05001513 memset(pcmd, 0, sizeof(SCR));
dea31012005-04-17 16:05:31 -05001514 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
1515
James Smart858c9f62007-06-17 19:56:39 -05001516 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1517 "Issue SCR: did:x%x",
1518 ndlp->nlp_DID, 0, 0);
1519
dea31012005-04-17 16:05:31 -05001520 phba->fc_stat.elsXmitSCR++;
1521 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
dea31012005-04-17 16:05:31 -05001522 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
James Smart329f9bc2007-04-25 09:53:01 -04001523 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001524 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001525 return 1;
dea31012005-04-17 16:05:31 -05001526 }
James Smart329f9bc2007-04-25 09:53:01 -04001527 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001528 return 0;
dea31012005-04-17 16:05:31 -05001529}
1530
1531static int
James Smart2e0fef82007-06-17 19:56:36 -05001532lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05001533{
James Smart2e0fef82007-06-17 19:56:36 -05001534 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001535 IOCB_t *icmd;
1536 struct lpfc_iocbq *elsiocb;
1537 struct lpfc_sli_ring *pring;
1538 struct lpfc_sli *psli;
1539 FARP *fp;
1540 uint8_t *pcmd;
1541 uint32_t *lp;
1542 uint16_t cmdsize;
1543 struct lpfc_nodelist *ondlp;
1544 struct lpfc_nodelist *ndlp;
1545
1546 psli = &phba->sli;
1547 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
James Smart92d7f7b2007-06-17 19:56:38 -05001548 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001549 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1550 if (!ndlp)
1551 return 1;
dea31012005-04-17 16:05:31 -05001552
James Smart2e0fef82007-06-17 19:56:36 -05001553 lpfc_nlp_init(vport, ndlp, nportid);
1554
1555 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1556 ndlp->nlp_DID, ELS_CMD_RNID);
James Smart488d1462006-03-07 15:02:37 -05001557 if (!elsiocb) {
James Smart329f9bc2007-04-25 09:53:01 -04001558 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001559 return 1;
dea31012005-04-17 16:05:31 -05001560 }
1561
1562 icmd = &elsiocb->iocb;
1563 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1564
1565 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
James Smart92d7f7b2007-06-17 19:56:38 -05001566 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001567
1568 /* Fill in FARPR payload */
1569 fp = (FARP *) (pcmd);
James Smart92d7f7b2007-06-17 19:56:38 -05001570 memset(fp, 0, sizeof(FARP));
dea31012005-04-17 16:05:31 -05001571 lp = (uint32_t *) pcmd;
1572 *lp++ = be32_to_cpu(nportid);
James Smart2e0fef82007-06-17 19:56:36 -05001573 *lp++ = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05001574 fp->Rflags = 0;
1575 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
1576
James Smart92d7f7b2007-06-17 19:56:38 -05001577 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
1578 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05001579 ondlp = lpfc_findnode_did(vport, nportid);
1580 if (ondlp) {
dea31012005-04-17 16:05:31 -05001581 memcpy(&fp->OportName, &ondlp->nlp_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05001582 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05001583 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05001584 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05001585 }
1586
James Smart858c9f62007-06-17 19:56:39 -05001587 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1588 "Issue FARPR: did:x%x",
1589 ndlp->nlp_DID, 0, 0);
1590
dea31012005-04-17 16:05:31 -05001591 phba->fc_stat.elsXmitFARPR++;
1592 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
dea31012005-04-17 16:05:31 -05001593 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
James Smart329f9bc2007-04-25 09:53:01 -04001594 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001595 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001596 return 1;
dea31012005-04-17 16:05:31 -05001597 }
James Smart329f9bc2007-04-25 09:53:01 -04001598 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001599 return 0;
dea31012005-04-17 16:05:31 -05001600}
1601
James Smarted957682007-06-17 19:56:37 -05001602static void
1603lpfc_end_rscn(struct lpfc_vport *vport)
1604{
1605 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1606
1607 if (vport->fc_flag & FC_RSCN_MODE) {
1608 /*
1609 * Check to see if more RSCNs came in while we were
1610 * processing this one.
1611 */
1612 if (vport->fc_rscn_id_cnt ||
1613 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1614 lpfc_els_handle_rscn(vport);
1615 else {
1616 spin_lock_irq(shost->host_lock);
1617 vport->fc_flag &= ~FC_RSCN_MODE;
1618 spin_unlock_irq(shost->host_lock);
1619 }
1620 }
1621}
1622
dea31012005-04-17 16:05:31 -05001623void
James Smart2e0fef82007-06-17 19:56:36 -05001624lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
James Smartfdcebe22006-03-07 15:04:01 -05001625{
James Smart2e0fef82007-06-17 19:56:36 -05001626 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1627
1628 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05001629 nlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001630 spin_unlock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05001631 del_timer_sync(&nlp->nlp_delayfunc);
1632 nlp->nlp_last_elscmd = 0;
1633
1634 if (!list_empty(&nlp->els_retry_evt.evt_listp))
1635 list_del_init(&nlp->els_retry_evt.evt_listp);
1636
1637 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
James Smart2e0fef82007-06-17 19:56:36 -05001638 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05001639 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001640 spin_unlock_irq(shost->host_lock);
1641 if (vport->num_disc_nodes) {
James Smartfdcebe22006-03-07 15:04:01 -05001642 /* Check to see if there are more
1643 * PLOGIs to be sent
1644 */
James Smart2e0fef82007-06-17 19:56:36 -05001645 lpfc_more_plogi(vport);
James Smartfdcebe22006-03-07 15:04:01 -05001646
James Smart2e0fef82007-06-17 19:56:36 -05001647 if (vport->num_disc_nodes == 0) {
1648 spin_lock_irq(shost->host_lock);
1649 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1650 spin_unlock_irq(shost->host_lock);
1651 lpfc_can_disctmo(vport);
James Smarted957682007-06-17 19:56:37 -05001652 lpfc_end_rscn(vport);
James Smartfdcebe22006-03-07 15:04:01 -05001653 }
1654 }
1655 }
1656 return;
1657}
1658
1659void
dea31012005-04-17 16:05:31 -05001660lpfc_els_retry_delay(unsigned long ptr)
1661{
James Smart2e0fef82007-06-17 19:56:36 -05001662 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
1663 struct lpfc_vport *vport = ndlp->vport;
James Smart2e0fef82007-06-17 19:56:36 -05001664 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05001665 unsigned long flags;
James Smart2e0fef82007-06-17 19:56:36 -05001666 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
dea31012005-04-17 16:05:31 -05001667
James Smart2e0fef82007-06-17 19:56:36 -05001668 ndlp = (struct lpfc_nodelist *) ptr;
1669 phba = ndlp->vport->phba;
dea31012005-04-17 16:05:31 -05001670 evtp = &ndlp->els_retry_evt;
1671
James Smart92d7f7b2007-06-17 19:56:38 -05001672 spin_lock_irqsave(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05001673 if (!list_empty(&evtp->evt_listp)) {
James Smart92d7f7b2007-06-17 19:56:38 -05001674 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05001675 return;
1676 }
1677
1678 evtp->evt_arg1 = ndlp;
1679 evtp->evt = LPFC_EVT_ELS_RETRY;
1680 list_add_tail(&evtp->evt_listp, &phba->work_list);
1681 if (phba->work_wait)
James Smart92d7f7b2007-06-17 19:56:38 -05001682 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05001683
James Smart92d7f7b2007-06-17 19:56:38 -05001684 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05001685 return;
1686}
1687
1688void
1689lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
1690{
James Smart2e0fef82007-06-17 19:56:36 -05001691 struct lpfc_vport *vport = ndlp->vport;
1692 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1693 uint32_t cmd, did, retry;
dea31012005-04-17 16:05:31 -05001694
James Smart2e0fef82007-06-17 19:56:36 -05001695 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001696 did = ndlp->nlp_DID;
1697 cmd = ndlp->nlp_last_elscmd;
1698 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05001699
1700 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
James Smart2e0fef82007-06-17 19:56:36 -05001701 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001702 return;
1703 }
1704
1705 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001706 spin_unlock_irq(shost->host_lock);
James Smart1a169682006-03-07 15:04:06 -05001707 /*
1708 * If a discovery event readded nlp_delayfunc after timer
1709 * firing and before processing the timer, cancel the
1710 * nlp_delayfunc.
1711 */
1712 del_timer_sync(&ndlp->nlp_delayfunc);
dea31012005-04-17 16:05:31 -05001713 retry = ndlp->nlp_retry;
1714
1715 switch (cmd) {
1716 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05001717 lpfc_issue_els_flogi(vport, ndlp, retry);
dea31012005-04-17 16:05:31 -05001718 break;
1719 case ELS_CMD_PLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05001720 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001721 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001722 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05001723 }
dea31012005-04-17 16:05:31 -05001724 break;
1725 case ELS_CMD_ADISC:
James Smart2e0fef82007-06-17 19:56:36 -05001726 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001727 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001728 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05001729 }
dea31012005-04-17 16:05:31 -05001730 break;
1731 case ELS_CMD_PRLI:
James Smart2e0fef82007-06-17 19:56:36 -05001732 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001733 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001734 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05001735 }
dea31012005-04-17 16:05:31 -05001736 break;
1737 case ELS_CMD_LOGO:
James Smart2e0fef82007-06-17 19:56:36 -05001738 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001739 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001740 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05001741 }
dea31012005-04-17 16:05:31 -05001742 break;
James Smart92d7f7b2007-06-17 19:56:38 -05001743 case ELS_CMD_FDISC:
1744 lpfc_issue_els_fdisc(vport, ndlp, retry);
1745 break;
dea31012005-04-17 16:05:31 -05001746 }
1747 return;
1748}
1749
1750static int
James Smart2e0fef82007-06-17 19:56:36 -05001751lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1752 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001753{
James Smart2e0fef82007-06-17 19:56:36 -05001754 struct lpfc_vport *vport = cmdiocb->vport;
1755 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1756 IOCB_t *irsp = &rspiocb->iocb;
1757 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1758 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
dea31012005-04-17 16:05:31 -05001759 uint32_t *elscmd;
1760 struct ls_rjt stat;
James Smart2e0fef82007-06-17 19:56:36 -05001761 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
1762 uint32_t cmd = 0;
James Smart488d1462006-03-07 15:02:37 -05001763 uint32_t did;
dea31012005-04-17 16:05:31 -05001764
James Smart488d1462006-03-07 15:02:37 -05001765
dea31012005-04-17 16:05:31 -05001766 /* Note: context2 may be 0 for internal driver abort
1767 * of delays ELS command.
1768 */
1769
1770 if (pcmd && pcmd->virt) {
1771 elscmd = (uint32_t *) (pcmd->virt);
1772 cmd = *elscmd++;
1773 }
1774
James Smart329f9bc2007-04-25 09:53:01 -04001775 if (ndlp)
James Smart488d1462006-03-07 15:02:37 -05001776 did = ndlp->nlp_DID;
1777 else {
1778 /* We should only hit this case for retrying PLOGI */
1779 did = irsp->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05001780 ndlp = lpfc_findnode_did(vport, did);
James Smart488d1462006-03-07 15:02:37 -05001781 if (!ndlp && (cmd != ELS_CMD_PLOGI))
1782 return 1;
1783 }
1784
James Smart858c9f62007-06-17 19:56:39 -05001785 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1786 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
1787 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
1788
dea31012005-04-17 16:05:31 -05001789 switch (irsp->ulpStatus) {
1790 case IOSTAT_FCP_RSP_ERROR:
1791 case IOSTAT_REMOTE_STOP:
1792 break;
1793
1794 case IOSTAT_LOCAL_REJECT:
1795 switch ((irsp->un.ulpWord[4] & 0xff)) {
1796 case IOERR_LOOP_OPEN_FAILURE:
James Smart2e0fef82007-06-17 19:56:36 -05001797 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05001798 delay = 1000;
dea31012005-04-17 16:05:31 -05001799 retry = 1;
1800 break;
1801
James Smart92d7f7b2007-06-17 19:56:38 -05001802 case IOERR_ILLEGAL_COMMAND:
1803 if ((phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) &&
1804 (cmd == ELS_CMD_FDISC)) {
James Smarte8b62012007-08-02 11:10:09 -04001805 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1806 "0124 FDISC failed (3/6) "
1807 "retrying...\n");
James Smart92d7f7b2007-06-17 19:56:38 -05001808 lpfc_mbx_unreg_vpi(vport);
1809 retry = 1;
James Smart51ef4c22007-08-02 11:10:31 -04001810 /* FDISC retry policy */
1811 maxretry = 48;
1812 if (cmdiocb->retry >= 32)
1813 delay = 1000;
James Smart92d7f7b2007-06-17 19:56:38 -05001814 }
1815 break;
1816
dea31012005-04-17 16:05:31 -05001817 case IOERR_NO_RESOURCES:
James Smart858c9f62007-06-17 19:56:39 -05001818 retry = 1;
1819 if (cmdiocb->retry > 100)
1820 delay = 100;
1821 maxretry = 250;
1822 break;
1823
1824 case IOERR_ILLEGAL_FRAME:
James Smart92d7f7b2007-06-17 19:56:38 -05001825 delay = 100;
dea31012005-04-17 16:05:31 -05001826 retry = 1;
1827 break;
1828
James Smart858c9f62007-06-17 19:56:39 -05001829 case IOERR_SEQUENCE_TIMEOUT:
dea31012005-04-17 16:05:31 -05001830 case IOERR_INVALID_RPI:
1831 retry = 1;
1832 break;
1833 }
1834 break;
1835
1836 case IOSTAT_NPORT_RJT:
1837 case IOSTAT_FABRIC_RJT:
1838 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
1839 retry = 1;
1840 break;
1841 }
1842 break;
1843
1844 case IOSTAT_NPORT_BSY:
1845 case IOSTAT_FABRIC_BSY:
1846 retry = 1;
1847 break;
1848
1849 case IOSTAT_LS_RJT:
1850 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
1851 /* Added for Vendor specifc support
1852 * Just keep retrying for these Rsn / Exp codes
1853 */
1854 switch (stat.un.b.lsRjtRsnCode) {
1855 case LSRJT_UNABLE_TPC:
1856 if (stat.un.b.lsRjtRsnCodeExp ==
1857 LSEXP_CMD_IN_PROGRESS) {
1858 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05001859 delay = 1000;
dea31012005-04-17 16:05:31 -05001860 maxretry = 48;
1861 }
1862 retry = 1;
1863 break;
1864 }
1865 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05001866 delay = 1000;
dea31012005-04-17 16:05:31 -05001867 maxretry = lpfc_max_els_tries + 1;
1868 retry = 1;
1869 break;
1870 }
James Smart92d7f7b2007-06-17 19:56:38 -05001871 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
1872 (cmd == ELS_CMD_FDISC) &&
1873 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
James Smarte8b62012007-08-02 11:10:09 -04001874 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1875 "0125 FDISC Failed (x%x). "
1876 "Fabric out of resources\n",
1877 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05001878 lpfc_vport_set_state(vport,
1879 FC_VPORT_NO_FABRIC_RSCS);
1880 }
dea31012005-04-17 16:05:31 -05001881 break;
1882
1883 case LSRJT_LOGICAL_BSY:
James Smart858c9f62007-06-17 19:56:39 -05001884 if ((cmd == ELS_CMD_PLOGI) ||
1885 (cmd == ELS_CMD_PRLI)) {
James Smart92d7f7b2007-06-17 19:56:38 -05001886 delay = 1000;
dea31012005-04-17 16:05:31 -05001887 maxretry = 48;
James Smart92d7f7b2007-06-17 19:56:38 -05001888 } else if (cmd == ELS_CMD_FDISC) {
James Smart51ef4c22007-08-02 11:10:31 -04001889 /* FDISC retry policy */
1890 maxretry = 48;
1891 if (cmdiocb->retry >= 32)
1892 delay = 1000;
dea31012005-04-17 16:05:31 -05001893 }
1894 retry = 1;
1895 break;
James Smart92d7f7b2007-06-17 19:56:38 -05001896
1897 case LSRJT_LOGICAL_ERR:
1898 case LSRJT_PROTOCOL_ERR:
1899 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
1900 (cmd == ELS_CMD_FDISC) &&
1901 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
1902 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
1903 ) {
James Smarte8b62012007-08-02 11:10:09 -04001904 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1905 "0123 FDISC Failed (x%x). "
1906 "Fabric Detected Bad WWN\n",
1907 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05001908 lpfc_vport_set_state(vport,
1909 FC_VPORT_FABRIC_REJ_WWN);
1910 }
1911 break;
dea31012005-04-17 16:05:31 -05001912 }
1913 break;
1914
1915 case IOSTAT_INTERMED_RSP:
1916 case IOSTAT_BA_RJT:
1917 break;
1918
1919 default:
1920 break;
1921 }
1922
James Smart488d1462006-03-07 15:02:37 -05001923 if (did == FDMI_DID)
dea31012005-04-17 16:05:31 -05001924 retry = 1;
dea31012005-04-17 16:05:31 -05001925
1926 if ((++cmdiocb->retry) >= maxretry) {
1927 phba->fc_stat.elsRetryExceeded++;
1928 retry = 0;
1929 }
1930
James Smarted957682007-06-17 19:56:37 -05001931 if ((vport->load_flag & FC_UNLOADING) != 0)
1932 retry = 0;
1933
dea31012005-04-17 16:05:31 -05001934 if (retry) {
1935
1936 /* Retry ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04001937 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1938 "0107 Retry ELS command x%x to remote "
1939 "NPORT x%x Data: x%x x%x\n",
1940 cmd, did, cmdiocb->retry, delay);
dea31012005-04-17 16:05:31 -05001941
James Smart858c9f62007-06-17 19:56:39 -05001942 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
1943 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
1944 ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) {
1945 /* Don't reset timer for no resources */
1946
dea31012005-04-17 16:05:31 -05001947 /* If discovery / RSCN timer is running, reset it */
James Smart2e0fef82007-06-17 19:56:36 -05001948 if (timer_pending(&vport->fc_disctmo) ||
James Smart92d7f7b2007-06-17 19:56:38 -05001949 (vport->fc_flag & FC_RSCN_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05001950 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001951 }
1952
1953 phba->fc_stat.elsXmitRetry++;
James Smart488d1462006-03-07 15:02:37 -05001954 if (ndlp && delay) {
dea31012005-04-17 16:05:31 -05001955 phba->fc_stat.elsDelayRetry++;
1956 ndlp->nlp_retry = cmdiocb->retry;
1957
James Smart92d7f7b2007-06-17 19:56:38 -05001958 /* delay is specified in milliseconds */
1959 mod_timer(&ndlp->nlp_delayfunc,
1960 jiffies + msecs_to_jiffies(delay));
James Smart2e0fef82007-06-17 19:56:36 -05001961 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001962 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001963 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001964
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001965 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart858c9f62007-06-17 19:56:39 -05001966 if (cmd == ELS_CMD_PRLI)
1967 lpfc_nlp_set_state(vport, ndlp,
1968 NLP_STE_REG_LOGIN_ISSUE);
1969 else
1970 lpfc_nlp_set_state(vport, ndlp,
1971 NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05001972 ndlp->nlp_last_elscmd = cmd;
1973
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001974 return 1;
dea31012005-04-17 16:05:31 -05001975 }
1976 switch (cmd) {
1977 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05001978 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001979 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -05001980 case ELS_CMD_FDISC:
1981 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
1982 return 1;
dea31012005-04-17 16:05:31 -05001983 case ELS_CMD_PLOGI:
James Smart488d1462006-03-07 15:02:37 -05001984 if (ndlp) {
1985 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001986 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04001987 NLP_STE_PLOGI_ISSUE);
James Smart488d1462006-03-07 15:02:37 -05001988 }
James Smart2e0fef82007-06-17 19:56:36 -05001989 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001990 return 1;
dea31012005-04-17 16:05:31 -05001991 case ELS_CMD_ADISC:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001992 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001993 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
1994 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001995 return 1;
dea31012005-04-17 16:05:31 -05001996 case ELS_CMD_PRLI:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001997 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001998 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
1999 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002000 return 1;
dea31012005-04-17 16:05:31 -05002001 case ELS_CMD_LOGO:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002002 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002003 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2004 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002005 return 1;
dea31012005-04-17 16:05:31 -05002006 }
2007 }
dea31012005-04-17 16:05:31 -05002008 /* No retry ELS command <elsCmd> to remote NPORT <did> */
James Smarta58cbd52007-08-02 11:09:43 -04002009 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2010 "0108 No retry ELS command x%x to remote "
2011 "NPORT x%x Retried:%d Error:x%x/%x\n",
2012 cmd, did, cmdiocb->retry, irsp->ulpStatus,
2013 irsp->un.ulpWord[4]);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002014 return 0;
dea31012005-04-17 16:05:31 -05002015}
2016
2017int
James Smart329f9bc2007-04-25 09:53:01 -04002018lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05002019{
2020 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
2021
James Smart329f9bc2007-04-25 09:53:01 -04002022 if (elsiocb->context1) {
2023 lpfc_nlp_put(elsiocb->context1);
2024 elsiocb->context1 = NULL;
2025 }
dea31012005-04-17 16:05:31 -05002026 /* context2 = cmd, context2->next = rsp, context3 = bpl */
2027 if (elsiocb->context2) {
2028 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
2029 /* Free the response before processing the command. */
2030 if (!list_empty(&buf_ptr1->list)) {
2031 list_remove_head(&buf_ptr1->list, buf_ptr,
2032 struct lpfc_dmabuf,
2033 list);
2034 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
2035 kfree(buf_ptr);
2036 }
2037 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
2038 kfree(buf_ptr1);
2039 }
2040
2041 if (elsiocb->context3) {
2042 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
2043 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
2044 kfree(buf_ptr);
2045 }
James Bottomley604a3e32005-10-29 10:28:33 -05002046 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -05002047 return 0;
2048}
2049
2050static void
James Smart2e0fef82007-06-17 19:56:36 -05002051lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2052 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002053{
James Smart2e0fef82007-06-17 19:56:36 -05002054 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2055 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05002056 IOCB_t *irsp;
2057
2058 irsp = &rspiocb->iocb;
2059 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2060 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
2061 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05002062 /* ACC to LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002063 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2064 "0109 ACC to LOGO completes to NPort x%x "
2065 "Data: x%x x%x x%x\n",
2066 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2067 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05002068 switch (ndlp->nlp_state) {
2069 case NLP_STE_UNUSED_NODE: /* node is just allocated */
James Smart2e0fef82007-06-17 19:56:36 -05002070 lpfc_drop_node(vport, ndlp);
dea31012005-04-17 16:05:31 -05002071 break;
2072 case NLP_STE_NPR_NODE: /* NPort Recovery mode */
James Smart2e0fef82007-06-17 19:56:36 -05002073 lpfc_unreg_rpi(vport, ndlp);
dea31012005-04-17 16:05:31 -05002074 break;
2075 default:
2076 break;
2077 }
2078 lpfc_els_free_iocb(phba, cmdiocb);
2079 return;
2080}
2081
James Smart858c9f62007-06-17 19:56:39 -05002082void
2083lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
2084{
2085 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
2086 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
2087
2088 pmb->context1 = NULL;
2089 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2090 kfree(mp);
2091 mempool_free(pmb, phba->mbox_mem_pool);
2092 lpfc_nlp_put(ndlp);
2093 return;
2094}
2095
dea31012005-04-17 16:05:31 -05002096static void
James Smart858c9f62007-06-17 19:56:39 -05002097lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
James Smart329f9bc2007-04-25 09:53:01 -04002098 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002099{
James Smart2e0fef82007-06-17 19:56:36 -05002100 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2101 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
2102 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
James Smart33ccf8d2006-08-17 11:57:58 -04002103 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05002104 LPFC_MBOXQ_t *mbox = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05002105 struct lpfc_dmabuf *mp = NULL;
dea31012005-04-17 16:05:31 -05002106
James Smart33ccf8d2006-08-17 11:57:58 -04002107 irsp = &rspiocb->iocb;
2108
dea31012005-04-17 16:05:31 -05002109 if (cmdiocb->context_un.mbox)
2110 mbox = cmdiocb->context_un.mbox;
2111
dea31012005-04-17 16:05:31 -05002112 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002113 if (!ndlp || lpfc_els_chk_latt(vport)) {
dea31012005-04-17 16:05:31 -05002114 if (mbox) {
James Smart14691152006-12-02 13:34:28 -05002115 mp = (struct lpfc_dmabuf *) mbox->context1;
2116 if (mp) {
2117 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2118 kfree(mp);
2119 }
James Smart329f9bc2007-04-25 09:53:01 -04002120 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05002121 }
2122 goto out;
2123 }
2124
James Smart858c9f62007-06-17 19:56:39 -05002125 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smart51ef4c22007-08-02 11:10:31 -04002126 "ELS rsp cmpl: status:x%x/x%x did:x%x",
James Smart858c9f62007-06-17 19:56:39 -05002127 irsp->ulpStatus, irsp->un.ulpWord[4],
James Smart51ef4c22007-08-02 11:10:31 -04002128 cmdiocb->iocb.un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05002129 /* ELS response tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04002130 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2131 "0110 ELS response tag x%x completes "
2132 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
2133 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
2134 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
2135 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2136 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05002137 if (mbox) {
2138 if ((rspiocb->iocb.ulpStatus == 0)
2139 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
James Smart2e0fef82007-06-17 19:56:36 -05002140 lpfc_unreg_rpi(vport, ndlp);
James Smart329f9bc2007-04-25 09:53:01 -04002141 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05002142 mbox->vport = vport;
James Smart858c9f62007-06-17 19:56:39 -05002143 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
2144 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
2145 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
2146 }
2147 else {
2148 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
2149 ndlp->nlp_prev_state = ndlp->nlp_state;
2150 lpfc_nlp_set_state(vport, ndlp,
James Smart2e0fef82007-06-17 19:56:36 -05002151 NLP_STE_REG_LOGIN_ISSUE);
James Smart858c9f62007-06-17 19:56:39 -05002152 }
dea31012005-04-17 16:05:31 -05002153 if (lpfc_sli_issue_mbox(phba, mbox,
2154 (MBX_NOWAIT | MBX_STOP_IOCB))
2155 != MBX_NOT_FINISHED) {
2156 goto out;
2157 }
James Smart329f9bc2007-04-25 09:53:01 -04002158 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002159 /* NOTE: we should have messages for unsuccessful
2160 reglogin */
dea31012005-04-17 16:05:31 -05002161 } else {
James Smart858c9f62007-06-17 19:56:39 -05002162 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
2163 if (!lpfc_error_lost_link(irsp) &&
2164 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
2165 lpfc_drop_node(vport, ndlp);
2166 ndlp = NULL;
dea31012005-04-17 16:05:31 -05002167 }
2168 }
James Smart14691152006-12-02 13:34:28 -05002169 mp = (struct lpfc_dmabuf *) mbox->context1;
2170 if (mp) {
2171 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2172 kfree(mp);
2173 }
2174 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05002175 }
2176out:
2177 if (ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05002178 spin_lock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05002179 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
James Smart2e0fef82007-06-17 19:56:36 -05002180 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002181 }
2182 lpfc_els_free_iocb(phba, cmdiocb);
2183 return;
2184}
2185
2186int
James Smart2e0fef82007-06-17 19:56:36 -05002187lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
2188 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
James Smart51ef4c22007-08-02 11:10:31 -04002189 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05002190{
James Smart2e0fef82007-06-17 19:56:36 -05002191 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2192 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002193 IOCB_t *icmd;
2194 IOCB_t *oldcmd;
2195 struct lpfc_iocbq *elsiocb;
2196 struct lpfc_sli_ring *pring;
2197 struct lpfc_sli *psli;
2198 uint8_t *pcmd;
2199 uint16_t cmdsize;
2200 int rc;
James Smart82d9a2a2006-04-15 11:53:05 -04002201 ELS_PKT *els_pkt_ptr;
dea31012005-04-17 16:05:31 -05002202
2203 psli = &phba->sli;
2204 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2205 oldcmd = &oldiocb->iocb;
2206
2207 switch (flag) {
2208 case ELS_CMD_ACC:
James Smart92d7f7b2007-06-17 19:56:38 -05002209 cmdsize = sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05002210 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
2211 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05002212 if (!elsiocb) {
James Smart2e0fef82007-06-17 19:56:36 -05002213 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002214 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05002215 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002216 return 1;
dea31012005-04-17 16:05:31 -05002217 }
James Smart2e0fef82007-06-17 19:56:36 -05002218
dea31012005-04-17 16:05:31 -05002219 icmd = &elsiocb->iocb;
2220 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2221 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2222 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05002223 pcmd += sizeof(uint32_t);
James Smart858c9f62007-06-17 19:56:39 -05002224
2225 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2226 "Issue ACC: did:x%x flg:x%x",
2227 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05002228 break;
2229 case ELS_CMD_PLOGI:
James Smart92d7f7b2007-06-17 19:56:38 -05002230 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
James Smart2e0fef82007-06-17 19:56:36 -05002231 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
2232 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05002233 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002234 return 1;
James Smart488d1462006-03-07 15:02:37 -05002235
dea31012005-04-17 16:05:31 -05002236 icmd = &elsiocb->iocb;
2237 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2238 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2239
2240 if (mbox)
2241 elsiocb->context_un.mbox = mbox;
2242
2243 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05002244 pcmd += sizeof(uint32_t);
2245 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
James Smart858c9f62007-06-17 19:56:39 -05002246
2247 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2248 "Issue ACC PLOGI: did:x%x flg:x%x",
2249 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05002250 break;
James Smart82d9a2a2006-04-15 11:53:05 -04002251 case ELS_CMD_PRLO:
James Smart92d7f7b2007-06-17 19:56:38 -05002252 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
James Smart2e0fef82007-06-17 19:56:36 -05002253 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
James Smart82d9a2a2006-04-15 11:53:05 -04002254 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
2255 if (!elsiocb)
2256 return 1;
2257
2258 icmd = &elsiocb->iocb;
2259 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2260 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2261
2262 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
James Smart92d7f7b2007-06-17 19:56:38 -05002263 sizeof(uint32_t) + sizeof(PRLO));
James Smart82d9a2a2006-04-15 11:53:05 -04002264 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
2265 els_pkt_ptr = (ELS_PKT *) pcmd;
2266 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
James Smart858c9f62007-06-17 19:56:39 -05002267
2268 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2269 "Issue ACC PRLO: did:x%x flg:x%x",
2270 ndlp->nlp_DID, ndlp->nlp_flag, 0);
James Smart82d9a2a2006-04-15 11:53:05 -04002271 break;
dea31012005-04-17 16:05:31 -05002272 default:
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002273 return 1;
dea31012005-04-17 16:05:31 -05002274 }
dea31012005-04-17 16:05:31 -05002275 /* Xmit ELS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04002276 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2277 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
2278 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n",
2279 elsiocb->iotag, elsiocb->iocb.ulpContext,
2280 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2281 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05002282 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
James Smart2e0fef82007-06-17 19:56:36 -05002283 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002284 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05002285 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002286 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
2287 } else {
James Smart858c9f62007-06-17 19:56:39 -05002288 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05002289 }
2290
2291 phba->fc_stat.elsXmitACC++;
dea31012005-04-17 16:05:31 -05002292 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
dea31012005-04-17 16:05:31 -05002293 if (rc == IOCB_ERROR) {
2294 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002295 return 1;
dea31012005-04-17 16:05:31 -05002296 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002297 return 0;
dea31012005-04-17 16:05:31 -05002298}
2299
2300int
James Smart2e0fef82007-06-17 19:56:36 -05002301lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
James Smart858c9f62007-06-17 19:56:39 -05002302 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
2303 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05002304{
James Smart2e0fef82007-06-17 19:56:36 -05002305 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002306 IOCB_t *icmd;
2307 IOCB_t *oldcmd;
2308 struct lpfc_iocbq *elsiocb;
2309 struct lpfc_sli_ring *pring;
2310 struct lpfc_sli *psli;
2311 uint8_t *pcmd;
2312 uint16_t cmdsize;
2313 int rc;
2314
2315 psli = &phba->sli;
2316 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2317
James Smart92d7f7b2007-06-17 19:56:38 -05002318 cmdsize = 2 * sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05002319 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
2320 ndlp->nlp_DID, ELS_CMD_LS_RJT);
James Smart488d1462006-03-07 15:02:37 -05002321 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002322 return 1;
dea31012005-04-17 16:05:31 -05002323
2324 icmd = &elsiocb->iocb;
2325 oldcmd = &oldiocb->iocb;
2326 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2327 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2328
2329 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
James Smart92d7f7b2007-06-17 19:56:38 -05002330 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002331 *((uint32_t *) (pcmd)) = rejectError;
2332
James Smart51ef4c22007-08-02 11:10:31 -04002333 if (mbox)
James Smart858c9f62007-06-17 19:56:39 -05002334 elsiocb->context_un.mbox = mbox;
James Smart858c9f62007-06-17 19:56:39 -05002335
dea31012005-04-17 16:05:31 -05002336 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04002337 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2338 "0129 Xmit ELS RJT x%x response tag x%x "
2339 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
2340 "rpi x%x\n",
2341 rejectError, elsiocb->iotag,
2342 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
2343 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05002344 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2345 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
2346 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
2347
dea31012005-04-17 16:05:31 -05002348 phba->fc_stat.elsXmitLSRJT++;
James Smart858c9f62007-06-17 19:56:39 -05002349 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05002350 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
James Smart51ef4c22007-08-02 11:10:31 -04002351
2352 /* If the node is in the UNUSED state, and we are sending
2353 * a reject, we are done with it. Release driver reference
2354 * count here. The outstanding els will release its reference on
2355 * completion and the node can be freed then.
2356 */
2357 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
2358 lpfc_nlp_put(ndlp);
2359
dea31012005-04-17 16:05:31 -05002360 if (rc == IOCB_ERROR) {
2361 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002362 return 1;
dea31012005-04-17 16:05:31 -05002363 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002364 return 0;
dea31012005-04-17 16:05:31 -05002365}
2366
2367int
James Smart2e0fef82007-06-17 19:56:36 -05002368lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
2369 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05002370{
James Smart2e0fef82007-06-17 19:56:36 -05002371 struct lpfc_hba *phba = vport->phba;
2372 struct lpfc_sli *psli = &phba->sli;
2373 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05002374 ADISC *ap;
James Smart2e0fef82007-06-17 19:56:36 -05002375 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05002376 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002377 uint8_t *pcmd;
2378 uint16_t cmdsize;
2379 int rc;
2380
James Smart92d7f7b2007-06-17 19:56:38 -05002381 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
James Smart2e0fef82007-06-17 19:56:36 -05002382 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
2383 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05002384 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002385 return 1;
dea31012005-04-17 16:05:31 -05002386
dea31012005-04-17 16:05:31 -05002387 icmd = &elsiocb->iocb;
2388 oldcmd = &oldiocb->iocb;
2389 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04002390
2391 /* Xmit ADISC ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04002392 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2393 "0130 Xmit ADISC ACC response iotag x%x xri: "
2394 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
2395 elsiocb->iotag, elsiocb->iocb.ulpContext,
2396 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2397 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05002398 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2399
2400 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05002401 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002402
2403 ap = (ADISC *) (pcmd);
2404 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05002405 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2406 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002407 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002408
James Smart858c9f62007-06-17 19:56:39 -05002409 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2410 "Issue ACC ADISC: did:x%x flg:x%x",
2411 ndlp->nlp_DID, ndlp->nlp_flag, 0);
2412
dea31012005-04-17 16:05:31 -05002413 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05002414 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05002415 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
dea31012005-04-17 16:05:31 -05002416 if (rc == IOCB_ERROR) {
2417 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002418 return 1;
dea31012005-04-17 16:05:31 -05002419 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002420 return 0;
dea31012005-04-17 16:05:31 -05002421}
2422
2423int
James Smart2e0fef82007-06-17 19:56:36 -05002424lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
James Smart5b8bd0c2007-04-25 09:52:49 -04002425 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05002426{
James Smart2e0fef82007-06-17 19:56:36 -05002427 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002428 PRLI *npr;
2429 lpfc_vpd_t *vpd;
2430 IOCB_t *icmd;
2431 IOCB_t *oldcmd;
2432 struct lpfc_iocbq *elsiocb;
2433 struct lpfc_sli_ring *pring;
2434 struct lpfc_sli *psli;
2435 uint8_t *pcmd;
2436 uint16_t cmdsize;
2437 int rc;
2438
2439 psli = &phba->sli;
2440 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2441
James Smart92d7f7b2007-06-17 19:56:38 -05002442 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
James Smart2e0fef82007-06-17 19:56:36 -05002443 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
James Smart92d7f7b2007-06-17 19:56:38 -05002444 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002445 if (!elsiocb)
2446 return 1;
dea31012005-04-17 16:05:31 -05002447
dea31012005-04-17 16:05:31 -05002448 icmd = &elsiocb->iocb;
2449 oldcmd = &oldiocb->iocb;
2450 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04002451 /* Xmit PRLI ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04002452 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2453 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
2454 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
2455 elsiocb->iotag, elsiocb->iocb.ulpContext,
2456 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2457 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05002458 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2459
2460 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
James Smart92d7f7b2007-06-17 19:56:38 -05002461 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002462
2463 /* For PRLI, remainder of payload is PRLI parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05002464 memset(pcmd, 0, sizeof(PRLI));
dea31012005-04-17 16:05:31 -05002465
2466 npr = (PRLI *) pcmd;
2467 vpd = &phba->vpd;
2468 /*
2469 * If our firmware version is 3.20 or later,
2470 * set the following bits for FC-TAPE support.
2471 */
2472 if (vpd->rev.feaLevelHigh >= 0x02) {
2473 npr->ConfmComplAllowed = 1;
2474 npr->Retry = 1;
2475 npr->TaskRetryIdReq = 1;
2476 }
2477
2478 npr->acceptRspCode = PRLI_REQ_EXECUTED;
2479 npr->estabImagePair = 1;
2480 npr->readXferRdyDis = 1;
2481 npr->ConfmComplAllowed = 1;
2482
2483 npr->prliType = PRLI_FCP_TYPE;
2484 npr->initiatorFunc = 1;
2485
James Smart858c9f62007-06-17 19:56:39 -05002486 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2487 "Issue ACC PRLI: did:x%x flg:x%x",
2488 ndlp->nlp_DID, ndlp->nlp_flag, 0);
2489
dea31012005-04-17 16:05:31 -05002490 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05002491 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05002492
dea31012005-04-17 16:05:31 -05002493 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
dea31012005-04-17 16:05:31 -05002494 if (rc == IOCB_ERROR) {
2495 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002496 return 1;
dea31012005-04-17 16:05:31 -05002497 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002498 return 0;
dea31012005-04-17 16:05:31 -05002499}
2500
2501static int
James Smart2e0fef82007-06-17 19:56:36 -05002502lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
James Smart329f9bc2007-04-25 09:53:01 -04002503 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05002504{
James Smart2e0fef82007-06-17 19:56:36 -05002505 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002506 RNID *rn;
James Smart2e0fef82007-06-17 19:56:36 -05002507 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05002508 struct lpfc_iocbq *elsiocb;
2509 struct lpfc_sli_ring *pring;
2510 struct lpfc_sli *psli;
2511 uint8_t *pcmd;
2512 uint16_t cmdsize;
2513 int rc;
2514
2515 psli = &phba->sli;
2516 pring = &psli->ring[LPFC_ELS_RING];
2517
James Smart92d7f7b2007-06-17 19:56:38 -05002518 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
2519 + (2 * sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002520 if (format)
James Smart92d7f7b2007-06-17 19:56:38 -05002521 cmdsize += sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05002522
James Smart2e0fef82007-06-17 19:56:36 -05002523 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
2524 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05002525 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002526 return 1;
dea31012005-04-17 16:05:31 -05002527
dea31012005-04-17 16:05:31 -05002528 icmd = &elsiocb->iocb;
2529 oldcmd = &oldiocb->iocb;
2530 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04002531 /* Xmit RNID ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04002532 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2533 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
2534 elsiocb->iotag, elsiocb->iocb.ulpContext);
dea31012005-04-17 16:05:31 -05002535 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
dea31012005-04-17 16:05:31 -05002536 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05002537 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002538
James Smart92d7f7b2007-06-17 19:56:38 -05002539 memset(pcmd, 0, sizeof(RNID));
dea31012005-04-17 16:05:31 -05002540 rn = (RNID *) (pcmd);
2541 rn->Format = format;
James Smart92d7f7b2007-06-17 19:56:38 -05002542 rn->CommonLen = (2 * sizeof(struct lpfc_name));
2543 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2544 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002545 switch (format) {
2546 case 0:
2547 rn->SpecificLen = 0;
2548 break;
2549 case RNID_TOPOLOGY_DISC:
James Smart92d7f7b2007-06-17 19:56:38 -05002550 rn->SpecificLen = sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05002551 memcpy(&rn->un.topologyDisc.portName,
James Smart92d7f7b2007-06-17 19:56:38 -05002552 &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002553 rn->un.topologyDisc.unitType = RNID_HBA;
2554 rn->un.topologyDisc.physPort = 0;
2555 rn->un.topologyDisc.attachedNodes = 0;
2556 break;
2557 default:
2558 rn->CommonLen = 0;
2559 rn->SpecificLen = 0;
2560 break;
2561 }
2562
James Smart858c9f62007-06-17 19:56:39 -05002563 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2564 "Issue ACC RNID: did:x%x flg:x%x",
2565 ndlp->nlp_DID, ndlp->nlp_flag, 0);
2566
dea31012005-04-17 16:05:31 -05002567 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05002568 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart329f9bc2007-04-25 09:53:01 -04002569 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002570 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
2571 * it could be freed */
2572
dea31012005-04-17 16:05:31 -05002573 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
dea31012005-04-17 16:05:31 -05002574 if (rc == IOCB_ERROR) {
2575 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002576 return 1;
dea31012005-04-17 16:05:31 -05002577 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002578 return 0;
dea31012005-04-17 16:05:31 -05002579}
2580
2581int
James Smart2e0fef82007-06-17 19:56:36 -05002582lpfc_els_disc_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002583{
James Smart2e0fef82007-06-17 19:56:36 -05002584 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002585 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05002586 int sentadisc = 0;
dea31012005-04-17 16:05:31 -05002587
James Smart685f0bf2007-04-25 09:53:08 -04002588 /* go thru NPR nodes and issue any remaining ELS ADISCs */
James Smart2e0fef82007-06-17 19:56:36 -05002589 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smart685f0bf2007-04-25 09:53:08 -04002590 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
2591 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
2592 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
James Smart2e0fef82007-06-17 19:56:36 -05002593 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04002594 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05002595 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04002596 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002597 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2598 lpfc_issue_els_adisc(vport, ndlp, 0);
James Smart685f0bf2007-04-25 09:53:08 -04002599 sentadisc++;
James Smart2e0fef82007-06-17 19:56:36 -05002600 vport->num_disc_nodes++;
2601 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04002602 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05002603 spin_lock_irq(shost->host_lock);
2604 vport->fc_flag |= FC_NLP_MORE;
2605 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04002606 break;
dea31012005-04-17 16:05:31 -05002607 }
2608 }
2609 }
2610 if (sentadisc == 0) {
James Smart2e0fef82007-06-17 19:56:36 -05002611 spin_lock_irq(shost->host_lock);
2612 vport->fc_flag &= ~FC_NLP_MORE;
2613 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002614 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002615 return sentadisc;
dea31012005-04-17 16:05:31 -05002616}
2617
2618int
James Smart2e0fef82007-06-17 19:56:36 -05002619lpfc_els_disc_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002620{
James Smart2e0fef82007-06-17 19:56:36 -05002621 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002622 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05002623 int sentplogi = 0;
dea31012005-04-17 16:05:31 -05002624
James Smart2e0fef82007-06-17 19:56:36 -05002625 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
2626 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smart685f0bf2007-04-25 09:53:08 -04002627 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
2628 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
2629 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
2630 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
2631 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002632 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2633 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
James Smart685f0bf2007-04-25 09:53:08 -04002634 sentplogi++;
James Smart2e0fef82007-06-17 19:56:36 -05002635 vport->num_disc_nodes++;
2636 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04002637 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05002638 spin_lock_irq(shost->host_lock);
2639 vport->fc_flag |= FC_NLP_MORE;
2640 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04002641 break;
dea31012005-04-17 16:05:31 -05002642 }
2643 }
2644 }
2645 if (sentplogi == 0) {
James Smart2e0fef82007-06-17 19:56:36 -05002646 spin_lock_irq(shost->host_lock);
2647 vport->fc_flag &= ~FC_NLP_MORE;
2648 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002649 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002650 return sentplogi;
dea31012005-04-17 16:05:31 -05002651}
2652
James Smart92d7f7b2007-06-17 19:56:38 -05002653void
James Smart2e0fef82007-06-17 19:56:36 -05002654lpfc_els_flush_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002655{
James Smart2e0fef82007-06-17 19:56:36 -05002656 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2657 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002658 int i;
2659
James Smart2e0fef82007-06-17 19:56:36 -05002660 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05002661 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
James Smart2e0fef82007-06-17 19:56:36 -05002662 vport->fc_rscn_id_list[i] = NULL;
dea31012005-04-17 16:05:31 -05002663 }
James Smart2e0fef82007-06-17 19:56:36 -05002664 spin_lock_irq(shost->host_lock);
2665 vport->fc_rscn_id_cnt = 0;
2666 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
2667 spin_unlock_irq(shost->host_lock);
2668 lpfc_can_disctmo(vport);
dea31012005-04-17 16:05:31 -05002669}
2670
2671int
James Smart2e0fef82007-06-17 19:56:36 -05002672lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05002673{
2674 D_ID ns_did;
2675 D_ID rscn_did;
dea31012005-04-17 16:05:31 -05002676 uint32_t *lp;
James Smart92d7f7b2007-06-17 19:56:38 -05002677 uint32_t payload_len, i;
dea31012005-04-17 16:05:31 -05002678
2679 ns_did.un.word = did;
dea31012005-04-17 16:05:31 -05002680
2681 /* Never match fabric nodes for RSCNs */
2682 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
James Smart2e0fef82007-06-17 19:56:36 -05002683 return 0;
dea31012005-04-17 16:05:31 -05002684
2685 /* If we are doing a FULL RSCN rediscovery, match everything */
James Smart2e0fef82007-06-17 19:56:36 -05002686 if (vport->fc_flag & FC_RSCN_DISCOVERY)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002687 return did;
dea31012005-04-17 16:05:31 -05002688
James Smart2e0fef82007-06-17 19:56:36 -05002689 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05002690 lp = vport->fc_rscn_id_list[i]->virt;
2691 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
2692 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05002693 while (payload_len) {
James Smart92d7f7b2007-06-17 19:56:38 -05002694 rscn_did.un.word = be32_to_cpu(*lp++);
2695 payload_len -= sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002696 switch (rscn_did.un.b.resv) {
2697 case 0: /* Single N_Port ID effected */
James Smart2e0fef82007-06-17 19:56:36 -05002698 if (ns_did.un.word == rscn_did.un.word)
James Smart92d7f7b2007-06-17 19:56:38 -05002699 return did;
dea31012005-04-17 16:05:31 -05002700 break;
2701 case 1: /* Whole N_Port Area effected */
2702 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
2703 && (ns_did.un.b.area == rscn_did.un.b.area))
James Smart92d7f7b2007-06-17 19:56:38 -05002704 return did;
dea31012005-04-17 16:05:31 -05002705 break;
2706 case 2: /* Whole N_Port Domain effected */
2707 if (ns_did.un.b.domain == rscn_did.un.b.domain)
James Smart92d7f7b2007-06-17 19:56:38 -05002708 return did;
dea31012005-04-17 16:05:31 -05002709 break;
2710 default:
James Smart2e0fef82007-06-17 19:56:36 -05002711 /* Unknown Identifier in RSCN node */
James Smarte8b62012007-08-02 11:10:09 -04002712 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
2713 "0217 Unknown Identifier in "
2714 "RSCN payload Data: x%x\n",
2715 rscn_did.un.word);
James Smart92d7f7b2007-06-17 19:56:38 -05002716 case 3: /* Whole Fabric effected */
2717 return did;
dea31012005-04-17 16:05:31 -05002718 }
2719 }
James Smart92d7f7b2007-06-17 19:56:38 -05002720 }
2721 return 0;
dea31012005-04-17 16:05:31 -05002722}
2723
2724static int
James Smart2e0fef82007-06-17 19:56:36 -05002725lpfc_rscn_recovery_check(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002726{
James Smart685f0bf2007-04-25 09:53:08 -04002727 struct lpfc_nodelist *ndlp = NULL;
dea31012005-04-17 16:05:31 -05002728
2729 /* Look at all nodes effected by pending RSCNs and move
James Smart685f0bf2007-04-25 09:53:08 -04002730 * them to NPR state.
dea31012005-04-17 16:05:31 -05002731 */
James Smart685f0bf2007-04-25 09:53:08 -04002732
James Smart2e0fef82007-06-17 19:56:36 -05002733 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smart685f0bf2007-04-25 09:53:08 -04002734 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE ||
James Smart2e0fef82007-06-17 19:56:36 -05002735 lpfc_rscn_payload_check(vport, ndlp->nlp_DID) == 0)
dea31012005-04-17 16:05:31 -05002736 continue;
2737
James Smart2e0fef82007-06-17 19:56:36 -05002738 lpfc_disc_state_machine(vport, ndlp, NULL,
James Smart92d7f7b2007-06-17 19:56:38 -05002739 NLP_EVT_DEVICE_RECOVERY);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002740
James Smart685f0bf2007-04-25 09:53:08 -04002741 /*
2742 * Make sure NLP_DELAY_TMO is NOT running after a device
2743 * recovery event.
2744 */
2745 if (ndlp->nlp_flag & NLP_DELAY_TMO)
James Smart2e0fef82007-06-17 19:56:36 -05002746 lpfc_cancel_retry_delay_tmo(vport, ndlp);
dea31012005-04-17 16:05:31 -05002747 }
James Smart685f0bf2007-04-25 09:53:08 -04002748
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002749 return 0;
dea31012005-04-17 16:05:31 -05002750}
2751
2752static int
James Smart2e0fef82007-06-17 19:56:36 -05002753lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04002754 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05002755{
James Smart2e0fef82007-06-17 19:56:36 -05002756 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2757 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002758 struct lpfc_dmabuf *pcmd;
James Smart92d7f7b2007-06-17 19:56:38 -05002759 uint32_t *lp, *datap;
dea31012005-04-17 16:05:31 -05002760 IOCB_t *icmd;
James Smart92d7f7b2007-06-17 19:56:38 -05002761 uint32_t payload_len, length, nportid, *cmd;
2762 int rscn_cnt = vport->fc_rscn_id_cnt;
2763 int rscn_id = 0, hba_id = 0;
James Smartd2873e42006-08-18 17:46:43 -04002764 int i;
dea31012005-04-17 16:05:31 -05002765
2766 icmd = &cmdiocb->iocb;
2767 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2768 lp = (uint32_t *) pcmd->virt;
2769
James Smart92d7f7b2007-06-17 19:56:38 -05002770 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
2771 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05002772 /* RSCN received */
James Smarte8b62012007-08-02 11:10:09 -04002773 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2774 "0214 RSCN received Data: x%x x%x x%x x%x\n",
2775 vport->fc_flag, payload_len, *lp, rscn_cnt);
James Smartd2873e42006-08-18 17:46:43 -04002776 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
James Smart2e0fef82007-06-17 19:56:36 -05002777 fc_host_post_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04002778 FCH_EVT_RSCN, lp[i]);
2779
dea31012005-04-17 16:05:31 -05002780 /* If we are about to begin discovery, just ACC the RSCN.
2781 * Discovery processing will satisfy it.
2782 */
James Smart2e0fef82007-06-17 19:56:36 -05002783 if (vport->port_state <= LPFC_NS_QRY) {
James Smart858c9f62007-06-17 19:56:39 -05002784 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
2785 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
2786 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
2787
James Smart51ef4c22007-08-02 11:10:31 -04002788 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002789 return 0;
dea31012005-04-17 16:05:31 -05002790 }
2791
James Smart92d7f7b2007-06-17 19:56:38 -05002792 /* If this RSCN just contains NPortIDs for other vports on this HBA,
2793 * just ACC and ignore it.
2794 */
2795 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart3de2a652007-08-02 11:09:59 -04002796 !(vport->cfg_peer_port_login)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002797 i = payload_len;
2798 datap = lp;
2799 while (i > 0) {
2800 nportid = *datap++;
2801 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
2802 i -= sizeof(uint32_t);
2803 rscn_id++;
James Smart549e55c2007-08-02 11:09:51 -04002804 if (lpfc_find_vport_by_did(phba, nportid))
2805 hba_id++;
James Smart92d7f7b2007-06-17 19:56:38 -05002806 }
2807 if (rscn_id == hba_id) {
2808 /* ALL NPortIDs in RSCN are on HBA */
James Smarte8b62012007-08-02 11:10:09 -04002809 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2810 "0214 Ignore RSCN "
2811 "Data: x%x x%x x%x x%x\n",
2812 vport->fc_flag, payload_len,
2813 *lp, rscn_cnt);
James Smart858c9f62007-06-17 19:56:39 -05002814 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
2815 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
2816 ndlp->nlp_DID, vport->port_state,
2817 ndlp->nlp_flag);
2818
James Smart92d7f7b2007-06-17 19:56:38 -05002819 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04002820 ndlp, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05002821 return 0;
2822 }
2823 }
2824
dea31012005-04-17 16:05:31 -05002825 /* If we are already processing an RSCN, save the received
2826 * RSCN payload buffer, cmdiocb->context2 to process later.
2827 */
James Smart2e0fef82007-06-17 19:56:36 -05002828 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
James Smart858c9f62007-06-17 19:56:39 -05002829 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
2830 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
2831 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
2832
James Smart92d7f7b2007-06-17 19:56:38 -05002833 vport->fc_flag |= FC_RSCN_DEFERRED;
2834 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
James Smart2e0fef82007-06-17 19:56:36 -05002835 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
2836 spin_lock_irq(shost->host_lock);
2837 vport->fc_flag |= FC_RSCN_MODE;
2838 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05002839 if (rscn_cnt) {
2840 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
2841 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
2842 }
2843 if ((rscn_cnt) &&
2844 (payload_len + length <= LPFC_BPL_SIZE)) {
2845 *cmd &= ELS_CMD_MASK;
2846 *cmd |= be32_to_cpu(payload_len + length);
2847 memcpy(((uint8_t *)cmd) + length, lp,
2848 payload_len);
2849 } else {
2850 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
2851 vport->fc_rscn_id_cnt++;
2852 /* If we zero, cmdiocb->context2, the calling
2853 * routine will not try to free it.
2854 */
2855 cmdiocb->context2 = NULL;
2856 }
dea31012005-04-17 16:05:31 -05002857
2858 /* Deferred RSCN */
James Smarte8b62012007-08-02 11:10:09 -04002859 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2860 "0235 Deferred RSCN "
2861 "Data: x%x x%x x%x\n",
2862 vport->fc_rscn_id_cnt, vport->fc_flag,
2863 vport->port_state);
dea31012005-04-17 16:05:31 -05002864 } else {
James Smart2e0fef82007-06-17 19:56:36 -05002865 spin_lock_irq(shost->host_lock);
2866 vport->fc_flag |= FC_RSCN_DISCOVERY;
2867 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002868 /* ReDiscovery RSCN */
James Smarte8b62012007-08-02 11:10:09 -04002869 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2870 "0234 ReDiscovery RSCN "
2871 "Data: x%x x%x x%x\n",
2872 vport->fc_rscn_id_cnt, vport->fc_flag,
2873 vport->port_state);
dea31012005-04-17 16:05:31 -05002874 }
2875 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04002876 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05002877
2878 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05002879 lpfc_rscn_recovery_check(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05002880 vport->fc_flag &= ~FC_RSCN_DEFERRED;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002881 return 0;
dea31012005-04-17 16:05:31 -05002882 }
2883
James Smart858c9f62007-06-17 19:56:39 -05002884 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
2885 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
2886 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
2887
James Smart2e0fef82007-06-17 19:56:36 -05002888 spin_lock_irq(shost->host_lock);
2889 vport->fc_flag |= FC_RSCN_MODE;
2890 spin_unlock_irq(shost->host_lock);
2891 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
dea31012005-04-17 16:05:31 -05002892 /*
2893 * If we zero, cmdiocb->context2, the calling routine will
2894 * not try to free it.
2895 */
2896 cmdiocb->context2 = NULL;
2897
James Smart2e0fef82007-06-17 19:56:36 -05002898 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05002899
2900 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04002901 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05002902
2903 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05002904 lpfc_rscn_recovery_check(vport);
dea31012005-04-17 16:05:31 -05002905
James Smart2e0fef82007-06-17 19:56:36 -05002906 return lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05002907}
2908
2909int
James Smart2e0fef82007-06-17 19:56:36 -05002910lpfc_els_handle_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002911{
2912 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05002913 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002914
James Smart92d7f7b2007-06-17 19:56:38 -05002915 /* Ignore RSCN if the port is being torn down. */
2916 if (vport->load_flag & FC_UNLOADING) {
2917 lpfc_els_flush_rscn(vport);
2918 return 0;
2919 }
2920
dea31012005-04-17 16:05:31 -05002921 /* Start timer for RSCN processing */
James Smart2e0fef82007-06-17 19:56:36 -05002922 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05002923
2924 /* RSCN processed */
James Smarte8b62012007-08-02 11:10:09 -04002925 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2926 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
2927 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
2928 vport->port_state);
dea31012005-04-17 16:05:31 -05002929
2930 /* To process RSCN, first compare RSCN data with NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05002931 vport->fc_ns_retry = 0;
2932 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smart685f0bf2007-04-25 09:53:08 -04002933 if (ndlp && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
dea31012005-04-17 16:05:31 -05002934 /* Good ndlp, issue CT Request to NameServer */
James Smart92d7f7b2007-06-17 19:56:38 -05002935 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
dea31012005-04-17 16:05:31 -05002936 /* Wait for NameServer query cmpl before we can
2937 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002938 return 1;
dea31012005-04-17 16:05:31 -05002939 } else {
2940 /* If login to NameServer does not exist, issue one */
2941 /* Good status, issue PLOGI to NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05002942 ndlp = lpfc_findnode_did(vport, NameServer_DID);
2943 if (ndlp)
dea31012005-04-17 16:05:31 -05002944 /* Wait for NameServer login cmpl before we can
2945 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002946 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05002947
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002948 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2949 if (!ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05002950 lpfc_els_flush_rscn(vport);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002951 return 0;
dea31012005-04-17 16:05:31 -05002952 } else {
James Smart2e0fef82007-06-17 19:56:36 -05002953 lpfc_nlp_init(vport, ndlp, NameServer_DID);
dea31012005-04-17 16:05:31 -05002954 ndlp->nlp_type |= NLP_FABRIC;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002955 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002956 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2957 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
dea31012005-04-17 16:05:31 -05002958 /* Wait for NameServer login cmpl before we can
2959 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002960 return 1;
dea31012005-04-17 16:05:31 -05002961 }
2962 }
2963
James Smart2e0fef82007-06-17 19:56:36 -05002964 lpfc_els_flush_rscn(vport);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002965 return 0;
dea31012005-04-17 16:05:31 -05002966}
2967
2968static int
James Smart2e0fef82007-06-17 19:56:36 -05002969lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04002970 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05002971{
James Smart2e0fef82007-06-17 19:56:36 -05002972 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2973 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002974 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2975 uint32_t *lp = (uint32_t *) pcmd->virt;
2976 IOCB_t *icmd = &cmdiocb->iocb;
2977 struct serv_parm *sp;
2978 LPFC_MBOXQ_t *mbox;
2979 struct ls_rjt stat;
2980 uint32_t cmd, did;
2981 int rc;
2982
2983 cmd = *lp++;
2984 sp = (struct serv_parm *) lp;
2985
2986 /* FLOGI received */
2987
James Smart2e0fef82007-06-17 19:56:36 -05002988 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05002989
2990 if (phba->fc_topology == TOPOLOGY_LOOP) {
2991 /* We should never receive a FLOGI in loop mode, ignore it */
2992 did = icmd->un.elsreq64.remoteID;
2993
2994 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
2995 Loop Mode */
James Smarte8b62012007-08-02 11:10:09 -04002996 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2997 "0113 An FLOGI ELS command x%x was "
2998 "received from DID x%x in Loop Mode\n",
2999 cmd, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003000 return 1;
dea31012005-04-17 16:05:31 -05003001 }
3002
3003 did = Fabric_DID;
3004
James Smart2e0fef82007-06-17 19:56:36 -05003005 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3))) {
dea31012005-04-17 16:05:31 -05003006 /* For a FLOGI we accept, then if our portname is greater
3007 * then the remote portname we initiate Nport login.
3008 */
3009
James Smart2e0fef82007-06-17 19:56:36 -05003010 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -05003011 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003012
3013 if (!rc) {
James Smart2e0fef82007-06-17 19:56:36 -05003014 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3015 if (!mbox)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003016 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05003017
dea31012005-04-17 16:05:31 -05003018 lpfc_linkdown(phba);
3019 lpfc_init_link(phba, mbox,
3020 phba->cfg_topology,
3021 phba->cfg_link_speed);
3022 mbox->mb.un.varInitLnk.lipsr_AL_PA = 0;
3023 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -05003024 mbox->vport = vport;
dea31012005-04-17 16:05:31 -05003025 rc = lpfc_sli_issue_mbox
3026 (phba, mbox, (MBX_NOWAIT | MBX_STOP_IOCB));
James Smart5b8bd0c2007-04-25 09:52:49 -04003027 lpfc_set_loopback_flag(phba);
dea31012005-04-17 16:05:31 -05003028 if (rc == MBX_NOT_FINISHED) {
James Smart329f9bc2007-04-25 09:53:01 -04003029 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003030 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003031 return 1;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003032 } else if (rc > 0) { /* greater than */
James Smart2e0fef82007-06-17 19:56:36 -05003033 spin_lock_irq(shost->host_lock);
3034 vport->fc_flag |= FC_PT2PT_PLOGI;
3035 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003036 }
James Smart2e0fef82007-06-17 19:56:36 -05003037 spin_lock_irq(shost->host_lock);
3038 vport->fc_flag |= FC_PT2PT;
3039 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
3040 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003041 } else {
3042 /* Reject this request because invalid parameters */
3043 stat.un.b.lsRjtRsvd0 = 0;
3044 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3045 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
3046 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05003047 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
3048 NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003049 return 1;
dea31012005-04-17 16:05:31 -05003050 }
3051
3052 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04003053 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05003054
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003055 return 0;
dea31012005-04-17 16:05:31 -05003056}
3057
3058static int
James Smart2e0fef82007-06-17 19:56:36 -05003059lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3060 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003061{
3062 struct lpfc_dmabuf *pcmd;
3063 uint32_t *lp;
3064 IOCB_t *icmd;
3065 RNID *rn;
3066 struct ls_rjt stat;
3067 uint32_t cmd, did;
3068
3069 icmd = &cmdiocb->iocb;
3070 did = icmd->un.elsreq64.remoteID;
3071 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3072 lp = (uint32_t *) pcmd->virt;
3073
3074 cmd = *lp++;
3075 rn = (RNID *) lp;
3076
3077 /* RNID received */
3078
3079 switch (rn->Format) {
3080 case 0:
3081 case RNID_TOPOLOGY_DISC:
3082 /* Send back ACC */
James Smart2e0fef82007-06-17 19:56:36 -05003083 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05003084 break;
3085 default:
3086 /* Reject this request because format not supported */
3087 stat.un.b.lsRjtRsvd0 = 0;
3088 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3089 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
3090 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05003091 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
3092 NULL);
dea31012005-04-17 16:05:31 -05003093 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003094 return 0;
dea31012005-04-17 16:05:31 -05003095}
3096
3097static int
James Smart2e0fef82007-06-17 19:56:36 -05003098lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3099 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003100{
3101 struct ls_rjt stat;
3102
3103 /* For now, unconditionally reject this command */
3104 stat.un.b.lsRjtRsvd0 = 0;
3105 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3106 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
3107 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05003108 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003109 return 0;
3110}
3111
Jamie Wellnitz082c0262006-02-28 19:25:30 -05003112static void
James Smart329f9bc2007-04-25 09:53:01 -04003113lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003114{
James Smart2e0fef82007-06-17 19:56:36 -05003115 struct lpfc_sli *psli = &phba->sli;
3116 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003117 MAILBOX_t *mb;
3118 IOCB_t *icmd;
3119 RPS_RSP *rps_rsp;
3120 uint8_t *pcmd;
3121 struct lpfc_iocbq *elsiocb;
3122 struct lpfc_nodelist *ndlp;
3123 uint16_t xri, status;
3124 uint32_t cmdsize;
3125
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003126 mb = &pmb->mb;
3127
3128 ndlp = (struct lpfc_nodelist *) pmb->context2;
3129 xri = (uint16_t) ((unsigned long)(pmb->context1));
Randy Dunlap041976f2006-06-25 01:58:51 -07003130 pmb->context1 = NULL;
3131 pmb->context2 = NULL;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003132
3133 if (mb->mbxStatus) {
James Smart329f9bc2007-04-25 09:53:01 -04003134 mempool_free(pmb, phba->mbox_mem_pool);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003135 return;
3136 }
3137
3138 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
James Smart329f9bc2007-04-25 09:53:01 -04003139 mempool_free(pmb, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05003140 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
3141 lpfc_max_els_tries, ndlp,
3142 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart329f9bc2007-04-25 09:53:01 -04003143 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003144 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003145 return;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003146
3147 icmd = &elsiocb->iocb;
3148 icmd->ulpContext = xri;
3149
3150 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3151 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003152 pcmd += sizeof(uint32_t); /* Skip past command */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003153 rps_rsp = (RPS_RSP *)pcmd;
3154
3155 if (phba->fc_topology != TOPOLOGY_LOOP)
3156 status = 0x10;
3157 else
3158 status = 0x8;
James Smart2e0fef82007-06-17 19:56:36 -05003159 if (phba->pport->fc_flag & FC_FABRIC)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003160 status |= 0x4;
3161
3162 rps_rsp->rsvd1 = 0;
3163 rps_rsp->portStatus = be16_to_cpu(status);
3164 rps_rsp->linkFailureCnt = be32_to_cpu(mb->un.varRdLnk.linkFailureCnt);
3165 rps_rsp->lossSyncCnt = be32_to_cpu(mb->un.varRdLnk.lossSyncCnt);
3166 rps_rsp->lossSignalCnt = be32_to_cpu(mb->un.varRdLnk.lossSignalCnt);
3167 rps_rsp->primSeqErrCnt = be32_to_cpu(mb->un.varRdLnk.primSeqErrCnt);
3168 rps_rsp->invalidXmitWord = be32_to_cpu(mb->un.varRdLnk.invalidXmitWord);
3169 rps_rsp->crcCnt = be32_to_cpu(mb->un.varRdLnk.crcCnt);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003170 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003171 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
3172 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
3173 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
3174 elsiocb->iotag, elsiocb->iocb.ulpContext,
3175 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3176 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05003177 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003178 phba->fc_stat.elsXmitACC++;
James Smarted957682007-06-17 19:56:37 -05003179 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003180 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003181 return;
3182}
3183
3184static int
James Smart2e0fef82007-06-17 19:56:36 -05003185lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3186 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003187{
James Smart2e0fef82007-06-17 19:56:36 -05003188 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003189 uint32_t *lp;
3190 uint8_t flag;
3191 LPFC_MBOXQ_t *mbox;
3192 struct lpfc_dmabuf *pcmd;
3193 RPS *rps;
3194 struct ls_rjt stat;
3195
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003196 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
3197 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003198 stat.un.b.lsRjtRsvd0 = 0;
3199 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3200 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
3201 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05003202 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
3203 NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003204 }
3205
3206 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3207 lp = (uint32_t *) pcmd->virt;
3208 flag = (be32_to_cpu(*lp++) & 0xf);
3209 rps = (RPS *) lp;
3210
3211 if ((flag == 0) ||
3212 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
James Smart2e0fef82007-06-17 19:56:36 -05003213 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05003214 sizeof(struct lpfc_name)) == 0))) {
James Smart2e0fef82007-06-17 19:56:36 -05003215
James Smart92d7f7b2007-06-17 19:56:38 -05003216 printk("Fix me....\n");
3217 dump_stack();
James Smart2e0fef82007-06-17 19:56:36 -05003218 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
3219 if (mbox) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003220 lpfc_read_lnk_stat(phba, mbox);
3221 mbox->context1 =
James Smart92d7f7b2007-06-17 19:56:38 -05003222 (void *)((unsigned long) cmdiocb->iocb.ulpContext);
James Smart329f9bc2007-04-25 09:53:01 -04003223 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05003224 mbox->vport = vport;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003225 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
3226 if (lpfc_sli_issue_mbox (phba, mbox,
James Smart2e0fef82007-06-17 19:56:36 -05003227 (MBX_NOWAIT | MBX_STOP_IOCB)) != MBX_NOT_FINISHED)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003228 /* Mbox completion will send ELS Response */
3229 return 0;
James Smart2e0fef82007-06-17 19:56:36 -05003230
James Smart329f9bc2007-04-25 09:53:01 -04003231 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003232 mempool_free(mbox, phba->mbox_mem_pool);
3233 }
3234 }
3235 stat.un.b.lsRjtRsvd0 = 0;
3236 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3237 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
3238 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05003239 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003240 return 0;
3241}
3242
Jamie Wellnitz082c0262006-02-28 19:25:30 -05003243static int
James Smart2e0fef82007-06-17 19:56:36 -05003244lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
3245 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003246{
James Smart2e0fef82007-06-17 19:56:36 -05003247 struct lpfc_hba *phba = vport->phba;
3248 IOCB_t *icmd, *oldcmd;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003249 RPL_RSP rpl_rsp;
3250 struct lpfc_iocbq *elsiocb;
James Smart2e0fef82007-06-17 19:56:36 -05003251 struct lpfc_sli *psli = &phba->sli;
3252 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003253 uint8_t *pcmd;
3254
James Smart2e0fef82007-06-17 19:56:36 -05003255 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3256 ndlp->nlp_DID, ELS_CMD_ACC);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003257
James Smart488d1462006-03-07 15:02:37 -05003258 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003259 return 1;
James Smart488d1462006-03-07 15:02:37 -05003260
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003261 icmd = &elsiocb->iocb;
3262 oldcmd = &oldiocb->iocb;
3263 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3264
3265 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3266 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003267 pcmd += sizeof(uint16_t);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003268 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
3269 pcmd += sizeof(uint16_t);
3270
3271 /* Setup the RPL ACC payload */
3272 rpl_rsp.listLen = be32_to_cpu(1);
3273 rpl_rsp.index = 0;
3274 rpl_rsp.port_num_blk.portNum = 0;
James Smart2e0fef82007-06-17 19:56:36 -05003275 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
3276 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003277 sizeof(struct lpfc_name));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003278 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003279 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003280 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3281 "0120 Xmit ELS RPL ACC response tag x%x "
3282 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
3283 "rpi x%x\n",
3284 elsiocb->iotag, elsiocb->iocb.ulpContext,
3285 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3286 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05003287 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003288 phba->fc_stat.elsXmitACC++;
3289 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
3290 lpfc_els_free_iocb(phba, elsiocb);
3291 return 1;
3292 }
3293 return 0;
3294}
3295
3296static int
James Smart2e0fef82007-06-17 19:56:36 -05003297lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3298 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003299{
3300 struct lpfc_dmabuf *pcmd;
3301 uint32_t *lp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003302 uint32_t maxsize;
3303 uint16_t cmdsize;
3304 RPL *rpl;
3305 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05003306
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003307 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
3308 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003309 stat.un.b.lsRjtRsvd0 = 0;
3310 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3311 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
3312 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05003313 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
3314 NULL);
dea31012005-04-17 16:05:31 -05003315 }
3316
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003317 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3318 lp = (uint32_t *) pcmd->virt;
3319 rpl = (RPL *) (lp + 1);
3320
3321 maxsize = be32_to_cpu(rpl->maxsize);
3322
3323 /* We support only one port */
3324 if ((rpl->index == 0) &&
3325 ((maxsize == 0) ||
3326 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
3327 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003328 } else {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003329 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
3330 }
James Smart2e0fef82007-06-17 19:56:36 -05003331 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05003332
3333 return 0;
3334}
3335
3336static int
James Smart2e0fef82007-06-17 19:56:36 -05003337lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3338 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003339{
3340 struct lpfc_dmabuf *pcmd;
3341 uint32_t *lp;
3342 IOCB_t *icmd;
3343 FARP *fp;
3344 uint32_t cmd, cnt, did;
3345
3346 icmd = &cmdiocb->iocb;
3347 did = icmd->un.elsreq64.remoteID;
3348 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3349 lp = (uint32_t *) pcmd->virt;
3350
3351 cmd = *lp++;
3352 fp = (FARP *) lp;
dea31012005-04-17 16:05:31 -05003353 /* FARP-REQ received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04003354 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3355 "0601 FARP-REQ received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05003356 /* We will only support match on WWPN or WWNN */
3357 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003358 return 0;
dea31012005-04-17 16:05:31 -05003359 }
3360
3361 cnt = 0;
3362 /* If this FARP command is searching for my portname */
3363 if (fp->Mflags & FARP_MATCH_PORT) {
James Smart2e0fef82007-06-17 19:56:36 -05003364 if (memcmp(&fp->RportName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05003365 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05003366 cnt = 1;
3367 }
3368
3369 /* If this FARP command is searching for my nodename */
3370 if (fp->Mflags & FARP_MATCH_NODE) {
James Smart2e0fef82007-06-17 19:56:36 -05003371 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05003372 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05003373 cnt = 1;
3374 }
3375
3376 if (cnt) {
3377 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
3378 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
3379 /* Log back into the node before sending the FARP. */
3380 if (fp->Rflags & FARP_REQUEST_PLOGI) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003381 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003382 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04003383 NLP_STE_PLOGI_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05003384 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05003385 }
3386
3387 /* Send a FARP response to that node */
James Smart2e0fef82007-06-17 19:56:36 -05003388 if (fp->Rflags & FARP_REQUEST_FARPR)
3389 lpfc_issue_els_farpr(vport, did, 0);
dea31012005-04-17 16:05:31 -05003390 }
3391 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003392 return 0;
dea31012005-04-17 16:05:31 -05003393}
3394
3395static int
James Smart2e0fef82007-06-17 19:56:36 -05003396lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3397 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003398{
3399 struct lpfc_dmabuf *pcmd;
3400 uint32_t *lp;
3401 IOCB_t *icmd;
3402 uint32_t cmd, did;
3403
3404 icmd = &cmdiocb->iocb;
3405 did = icmd->un.elsreq64.remoteID;
3406 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3407 lp = (uint32_t *) pcmd->virt;
3408
3409 cmd = *lp++;
3410 /* FARP-RSP received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04003411 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3412 "0600 FARP-RSP received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05003413 /* ACCEPT the Farp resp request */
James Smart51ef4c22007-08-02 11:10:31 -04003414 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05003415
3416 return 0;
3417}
3418
3419static int
James Smart2e0fef82007-06-17 19:56:36 -05003420lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3421 struct lpfc_nodelist *fan_ndlp)
dea31012005-04-17 16:05:31 -05003422{
3423 struct lpfc_dmabuf *pcmd;
3424 uint32_t *lp;
3425 IOCB_t *icmd;
dea31012005-04-17 16:05:31 -05003426 uint32_t cmd, did;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003427 FAN *fp;
3428 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05003429 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003430
3431 /* FAN received */
James Smarte8b62012007-08-02 11:10:09 -04003432 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3433 "0265 FAN received\n");
dea31012005-04-17 16:05:31 -05003434 icmd = &cmdiocb->iocb;
3435 did = icmd->un.elsreq64.remoteID;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003436 pcmd = (struct lpfc_dmabuf *)cmdiocb->context2;
3437 lp = (uint32_t *)pcmd->virt;
dea31012005-04-17 16:05:31 -05003438
3439 cmd = *lp++;
James Smart92d7f7b2007-06-17 19:56:38 -05003440 fp = (FAN *) lp;
dea31012005-04-17 16:05:31 -05003441
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003442 /* FAN received; Fan does not have a reply sequence */
dea31012005-04-17 16:05:31 -05003443
James Smart2e0fef82007-06-17 19:56:36 -05003444 if (phba->pport->port_state == LPFC_LOCAL_CFG_LINK) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003445 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
3446 sizeof(struct lpfc_name)) != 0) ||
3447 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
3448 sizeof(struct lpfc_name)) != 0)) {
3449 /*
3450 * This node has switched fabrics. FLOGI is required
3451 * Clean up the old rpi's
dea31012005-04-17 16:05:31 -05003452 */
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003453
3454 list_for_each_entry_safe(ndlp, next_ndlp,
James Smart2e0fef82007-06-17 19:56:36 -05003455 &vport->fc_nodes, nlp_listp) {
James Smart685f0bf2007-04-25 09:53:08 -04003456 if (ndlp->nlp_state != NLP_STE_NPR_NODE)
3457 continue;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003458 if (ndlp->nlp_type & NLP_FABRIC) {
3459 /*
3460 * Clean up old Fabric, Nameserver and
3461 * other NLP_FABRIC logins
3462 */
James Smart2e0fef82007-06-17 19:56:36 -05003463 lpfc_drop_node(vport, ndlp);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003464 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003465 /* Fail outstanding I/O now since this
3466 * device is marked for PLOGI
3467 */
James Smart2e0fef82007-06-17 19:56:36 -05003468 lpfc_unreg_rpi(vport, ndlp);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003469 }
3470 }
3471
James Smart2e0fef82007-06-17 19:56:36 -05003472 vport->port_state = LPFC_FLOGI;
3473 lpfc_set_disctmo(vport);
3474 lpfc_initial_flogi(vport);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003475 return 0;
dea31012005-04-17 16:05:31 -05003476 }
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003477 /* Discovery not needed,
3478 * move the nodes to their original state.
3479 */
James Smart2e0fef82007-06-17 19:56:36 -05003480 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
James Smart685f0bf2007-04-25 09:53:08 -04003481 nlp_listp) {
3482 if (ndlp->nlp_state != NLP_STE_NPR_NODE)
3483 continue;
dea31012005-04-17 16:05:31 -05003484
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003485 switch (ndlp->nlp_prev_state) {
3486 case NLP_STE_UNMAPPED_NODE:
3487 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05003488 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04003489 NLP_STE_UNMAPPED_NODE);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003490 break;
3491
3492 case NLP_STE_MAPPED_NODE:
3493 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05003494 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04003495 NLP_STE_MAPPED_NODE);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003496 break;
3497
3498 default:
3499 break;
3500 }
3501 }
3502
3503 /* Start discovery - this should just do CLEAR_LA */
James Smart2e0fef82007-06-17 19:56:36 -05003504 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -05003505 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003506 return 0;
dea31012005-04-17 16:05:31 -05003507}
3508
3509void
3510lpfc_els_timeout(unsigned long ptr)
3511{
James Smart2e0fef82007-06-17 19:56:36 -05003512 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
3513 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003514 unsigned long iflag;
3515
James Smart2e0fef82007-06-17 19:56:36 -05003516 spin_lock_irqsave(&vport->work_port_lock, iflag);
3517 if ((vport->work_port_events & WORKER_ELS_TMO) == 0) {
3518 vport->work_port_events |= WORKER_ELS_TMO;
James Smart92d7f7b2007-06-17 19:56:38 -05003519 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
3520
3521 spin_lock_irqsave(&phba->hbalock, iflag);
dea31012005-04-17 16:05:31 -05003522 if (phba->work_wait)
James Smart92d7f7b2007-06-17 19:56:38 -05003523 lpfc_worker_wake_up(phba);
3524 spin_unlock_irqrestore(&phba->hbalock, iflag);
dea31012005-04-17 16:05:31 -05003525 }
James Smart92d7f7b2007-06-17 19:56:38 -05003526 else
3527 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
dea31012005-04-17 16:05:31 -05003528 return;
3529}
3530
3531void
James Smart2e0fef82007-06-17 19:56:36 -05003532lpfc_els_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003533{
James Smart2e0fef82007-06-17 19:56:36 -05003534 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003535 struct lpfc_sli_ring *pring;
3536 struct lpfc_iocbq *tmp_iocb, *piocb;
3537 IOCB_t *cmd = NULL;
3538 struct lpfc_dmabuf *pcmd;
James Smart2e0fef82007-06-17 19:56:36 -05003539 uint32_t els_command = 0;
dea31012005-04-17 16:05:31 -05003540 uint32_t timeout;
James Smart2e0fef82007-06-17 19:56:36 -05003541 uint32_t remote_ID = 0xffffffff;
dea31012005-04-17 16:05:31 -05003542
dea31012005-04-17 16:05:31 -05003543 /* If the timer is already canceled do nothing */
James Smart2e0fef82007-06-17 19:56:36 -05003544 if ((vport->work_port_events & WORKER_ELS_TMO) == 0) {
dea31012005-04-17 16:05:31 -05003545 return;
3546 }
James Smart2e0fef82007-06-17 19:56:36 -05003547 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003548 timeout = (uint32_t)(phba->fc_ratov << 1);
3549
3550 pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05003551
3552 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
3553 cmd = &piocb->iocb;
3554
James Smart2e0fef82007-06-17 19:56:36 -05003555 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
3556 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
3557 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
dea31012005-04-17 16:05:31 -05003558 continue;
James Smart2e0fef82007-06-17 19:56:36 -05003559
3560 if (piocb->vport != vport)
3561 continue;
3562
dea31012005-04-17 16:05:31 -05003563 pcmd = (struct lpfc_dmabuf *) piocb->context2;
James Smart2e0fef82007-06-17 19:56:36 -05003564 if (pcmd)
3565 els_command = *(uint32_t *) (pcmd->virt);
dea31012005-04-17 16:05:31 -05003566
James Smart92d7f7b2007-06-17 19:56:38 -05003567 if (els_command == ELS_CMD_FARP ||
3568 els_command == ELS_CMD_FARPR ||
3569 els_command == ELS_CMD_FDISC)
dea31012005-04-17 16:05:31 -05003570 continue;
James Smart92d7f7b2007-06-17 19:56:38 -05003571
3572 if (vport != piocb->vport)
3573 continue;
dea31012005-04-17 16:05:31 -05003574
3575 if (piocb->drvrTimeout > 0) {
James Smart92d7f7b2007-06-17 19:56:38 -05003576 if (piocb->drvrTimeout >= timeout)
dea31012005-04-17 16:05:31 -05003577 piocb->drvrTimeout -= timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05003578 else
dea31012005-04-17 16:05:31 -05003579 piocb->drvrTimeout = 0;
dea31012005-04-17 16:05:31 -05003580 continue;
3581 }
3582
James Smart2e0fef82007-06-17 19:56:36 -05003583 remote_ID = 0xffffffff;
3584 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
dea31012005-04-17 16:05:31 -05003585 remote_ID = cmd->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05003586 else {
3587 struct lpfc_nodelist *ndlp;
3588 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
3589 if (ndlp)
3590 remote_ID = ndlp->nlp_DID;
dea31012005-04-17 16:05:31 -05003591 }
James Smarte8b62012007-08-02 11:10:09 -04003592 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3593 "0127 ELS timeout Data: x%x x%x x%x "
3594 "x%x\n", els_command,
3595 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
James Smart07951072007-04-25 09:51:38 -04003596 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05003597 }
James Smart2e0fef82007-06-17 19:56:36 -05003598 spin_unlock_irq(&phba->hbalock);
James Smart5a0e3262006-07-06 15:49:16 -04003599
James Smart2e0fef82007-06-17 19:56:36 -05003600 if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt)
3601 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
dea31012005-04-17 16:05:31 -05003602}
3603
3604void
James Smart2e0fef82007-06-17 19:56:36 -05003605lpfc_els_flush_cmd(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003606{
James Smart2534ba72007-04-25 09:52:20 -04003607 LIST_HEAD(completions);
James Smart2e0fef82007-06-17 19:56:36 -05003608 struct lpfc_hba *phba = vport->phba;
James Smart329f9bc2007-04-25 09:53:01 -04003609 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05003610 struct lpfc_iocbq *tmp_iocb, *piocb;
3611 IOCB_t *cmd = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05003612
3613 lpfc_fabric_abort_vport(vport);
dea31012005-04-17 16:05:31 -05003614
James Smart2e0fef82007-06-17 19:56:36 -05003615 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003616 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
3617 cmd = &piocb->iocb;
3618
3619 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
3620 continue;
3621 }
3622
3623 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
James Smart329f9bc2007-04-25 09:53:01 -04003624 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
3625 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
3626 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
3627 cmd->ulpCommand == CMD_ABORT_XRI_CN)
dea31012005-04-17 16:05:31 -05003628 continue;
dea31012005-04-17 16:05:31 -05003629
James Smart2e0fef82007-06-17 19:56:36 -05003630 if (piocb->vport != vport)
3631 continue;
3632
James Smart2534ba72007-04-25 09:52:20 -04003633 list_move_tail(&piocb->list, &completions);
James Smart1dcb58e2007-04-25 09:51:30 -04003634 pring->txq_cnt--;
dea31012005-04-17 16:05:31 -05003635 }
3636
3637 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
dea31012005-04-17 16:05:31 -05003638 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
3639 continue;
3640 }
dea31012005-04-17 16:05:31 -05003641
James Smart2e0fef82007-06-17 19:56:36 -05003642 if (piocb->vport != vport)
3643 continue;
3644
James Smart07951072007-04-25 09:51:38 -04003645 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05003646 }
James Smart2e0fef82007-06-17 19:56:36 -05003647 spin_unlock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04003648
James Smart2e0fef82007-06-17 19:56:36 -05003649 while (!list_empty(&completions)) {
James Smart2534ba72007-04-25 09:52:20 -04003650 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
3651 cmd = &piocb->iocb;
James Smart92d7f7b2007-06-17 19:56:38 -05003652 list_del_init(&piocb->list);
James Smart2534ba72007-04-25 09:52:20 -04003653
James Smart2e0fef82007-06-17 19:56:36 -05003654 if (!piocb->iocb_cmpl)
3655 lpfc_sli_release_iocbq(phba, piocb);
3656 else {
James Smart2534ba72007-04-25 09:52:20 -04003657 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
3658 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
3659 (piocb->iocb_cmpl) (phba, piocb, piocb);
James Smart2e0fef82007-06-17 19:56:36 -05003660 }
James Smart2534ba72007-04-25 09:52:20 -04003661 }
3662
dea31012005-04-17 16:05:31 -05003663 return;
3664}
3665
James Smart549e55c2007-08-02 11:09:51 -04003666void
3667lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
3668{
3669 LIST_HEAD(completions);
3670 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
3671 struct lpfc_iocbq *tmp_iocb, *piocb;
3672 IOCB_t *cmd = NULL;
3673
3674 lpfc_fabric_abort_hba(phba);
3675 spin_lock_irq(&phba->hbalock);
3676 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
3677 cmd = &piocb->iocb;
3678 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
3679 continue;
3680 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
3681 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
3682 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
3683 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
3684 cmd->ulpCommand == CMD_ABORT_XRI_CN)
3685 continue;
3686 list_move_tail(&piocb->list, &completions);
3687 pring->txq_cnt--;
3688 }
3689 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
3690 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
3691 continue;
3692 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
3693 }
3694 spin_unlock_irq(&phba->hbalock);
3695 while (!list_empty(&completions)) {
3696 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
3697 cmd = &piocb->iocb;
3698 list_del_init(&piocb->list);
3699 if (!piocb->iocb_cmpl)
3700 lpfc_sli_release_iocbq(phba, piocb);
3701 else {
3702 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
3703 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
3704 (piocb->iocb_cmpl) (phba, piocb, piocb);
3705 }
3706 }
3707 return;
3708}
3709
James Smarted957682007-06-17 19:56:37 -05003710static void
3711lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
James Smart92d7f7b2007-06-17 19:56:38 -05003712 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05003713{
dea31012005-04-17 16:05:31 -05003714 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05003715 struct ls_rjt stat;
James Smart92d7f7b2007-06-17 19:56:38 -05003716 uint32_t *payload;
James Smart2e0fef82007-06-17 19:56:36 -05003717 uint32_t cmd, did, newnode, rjt_err = 0;
James Smarted957682007-06-17 19:56:37 -05003718 IOCB_t *icmd = &elsiocb->iocb;
dea31012005-04-17 16:05:31 -05003719
James Smart92d7f7b2007-06-17 19:56:38 -05003720 if (vport == NULL || elsiocb->context2 == NULL)
dea31012005-04-17 16:05:31 -05003721 goto dropit;
James Smart2e0fef82007-06-17 19:56:36 -05003722
dea31012005-04-17 16:05:31 -05003723 newnode = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05003724 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
3725 cmd = *payload;
James Smarted957682007-06-17 19:56:37 -05003726 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
3727 lpfc_post_buffer(phba, pring, 1, 1);
dea31012005-04-17 16:05:31 -05003728
James Smart858c9f62007-06-17 19:56:39 -05003729 did = icmd->un.rcvels.remoteID;
3730 if (icmd->ulpStatus) {
3731 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3732 "RCV Unsol ELS: status:x%x/x%x did:x%x",
3733 icmd->ulpStatus, icmd->un.ulpWord[4], did);
dea31012005-04-17 16:05:31 -05003734 goto dropit;
James Smart858c9f62007-06-17 19:56:39 -05003735 }
dea31012005-04-17 16:05:31 -05003736
3737 /* Check to see if link went down during discovery */
James Smarted957682007-06-17 19:56:37 -05003738 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05003739 goto dropit;
dea31012005-04-17 16:05:31 -05003740
James Smart92d7f7b2007-06-17 19:56:38 -05003741 /* Ignore traffic recevied during vport shutdown. */
3742 if (vport->load_flag & FC_UNLOADING)
3743 goto dropit;
3744
James Smart2e0fef82007-06-17 19:56:36 -05003745 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003746 if (!ndlp) {
dea31012005-04-17 16:05:31 -05003747 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003748 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
James Smarted957682007-06-17 19:56:37 -05003749 if (!ndlp)
dea31012005-04-17 16:05:31 -05003750 goto dropit;
dea31012005-04-17 16:05:31 -05003751
James Smart2e0fef82007-06-17 19:56:36 -05003752 lpfc_nlp_init(vport, ndlp, did);
dea31012005-04-17 16:05:31 -05003753 newnode = 1;
3754 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) {
3755 ndlp->nlp_type |= NLP_FABRIC;
3756 }
James Smart2e0fef82007-06-17 19:56:36 -05003757 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE);
dea31012005-04-17 16:05:31 -05003758 }
3759
3760 phba->fc_stat.elsRcvFrame++;
James Smart329f9bc2007-04-25 09:53:01 -04003761 if (elsiocb->context1)
3762 lpfc_nlp_put(elsiocb->context1);
3763 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05003764 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -05003765
3766 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
3767 cmd &= ELS_CMD_MASK;
3768 }
3769 /* ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04003770 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3771 "0112 ELS command x%x received from NPORT x%x "
3772 "Data: x%x\n", cmd, did, vport->port_state);
dea31012005-04-17 16:05:31 -05003773 switch (cmd) {
3774 case ELS_CMD_PLOGI:
James Smart858c9f62007-06-17 19:56:39 -05003775 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3776 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
3777 did, vport->port_state, ndlp->nlp_flag);
3778
dea31012005-04-17 16:05:31 -05003779 phba->fc_stat.elsRcvPLOGI++;
James Smart858c9f62007-06-17 19:56:39 -05003780 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
3781
3782 if (vport->port_state < LPFC_DISC_AUTH) {
3783 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05003784 break;
3785 }
James Smart2e0fef82007-06-17 19:56:36 -05003786 lpfc_disc_state_machine(vport, ndlp, elsiocb,
3787 NLP_EVT_RCV_PLOGI);
James Smart858c9f62007-06-17 19:56:39 -05003788
dea31012005-04-17 16:05:31 -05003789 break;
3790 case ELS_CMD_FLOGI:
James Smart858c9f62007-06-17 19:56:39 -05003791 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3792 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
3793 did, vport->port_state, ndlp->nlp_flag);
3794
dea31012005-04-17 16:05:31 -05003795 phba->fc_stat.elsRcvFLOGI++;
James Smart51ef4c22007-08-02 11:10:31 -04003796 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04003797 if (newnode)
James Smart2e0fef82007-06-17 19:56:36 -05003798 lpfc_drop_node(vport, ndlp);
dea31012005-04-17 16:05:31 -05003799 break;
3800 case ELS_CMD_LOGO:
James Smart858c9f62007-06-17 19:56:39 -05003801 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3802 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
3803 did, vport->port_state, ndlp->nlp_flag);
3804
dea31012005-04-17 16:05:31 -05003805 phba->fc_stat.elsRcvLOGO++;
James Smart2e0fef82007-06-17 19:56:36 -05003806 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05003807 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05003808 break;
3809 }
James Smart2e0fef82007-06-17 19:56:36 -05003810 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
dea31012005-04-17 16:05:31 -05003811 break;
3812 case ELS_CMD_PRLO:
James Smart858c9f62007-06-17 19:56:39 -05003813 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3814 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
3815 did, vport->port_state, ndlp->nlp_flag);
3816
dea31012005-04-17 16:05:31 -05003817 phba->fc_stat.elsRcvPRLO++;
James Smart2e0fef82007-06-17 19:56:36 -05003818 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05003819 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05003820 break;
3821 }
James Smart2e0fef82007-06-17 19:56:36 -05003822 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
dea31012005-04-17 16:05:31 -05003823 break;
3824 case ELS_CMD_RSCN:
3825 phba->fc_stat.elsRcvRSCN++;
James Smart51ef4c22007-08-02 11:10:31 -04003826 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04003827 if (newnode)
James Smart2e0fef82007-06-17 19:56:36 -05003828 lpfc_drop_node(vport, ndlp);
dea31012005-04-17 16:05:31 -05003829 break;
3830 case ELS_CMD_ADISC:
James Smart858c9f62007-06-17 19:56:39 -05003831 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3832 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
3833 did, vport->port_state, ndlp->nlp_flag);
3834
dea31012005-04-17 16:05:31 -05003835 phba->fc_stat.elsRcvADISC++;
James Smart2e0fef82007-06-17 19:56:36 -05003836 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05003837 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05003838 break;
3839 }
James Smart2e0fef82007-06-17 19:56:36 -05003840 lpfc_disc_state_machine(vport, ndlp, elsiocb,
3841 NLP_EVT_RCV_ADISC);
dea31012005-04-17 16:05:31 -05003842 break;
3843 case ELS_CMD_PDISC:
James Smart858c9f62007-06-17 19:56:39 -05003844 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3845 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
3846 did, vport->port_state, ndlp->nlp_flag);
3847
dea31012005-04-17 16:05:31 -05003848 phba->fc_stat.elsRcvPDISC++;
James Smart2e0fef82007-06-17 19:56:36 -05003849 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05003850 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05003851 break;
3852 }
James Smart2e0fef82007-06-17 19:56:36 -05003853 lpfc_disc_state_machine(vport, ndlp, elsiocb,
3854 NLP_EVT_RCV_PDISC);
dea31012005-04-17 16:05:31 -05003855 break;
3856 case ELS_CMD_FARPR:
James Smart858c9f62007-06-17 19:56:39 -05003857 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3858 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
3859 did, vport->port_state, ndlp->nlp_flag);
3860
dea31012005-04-17 16:05:31 -05003861 phba->fc_stat.elsRcvFARPR++;
James Smart2e0fef82007-06-17 19:56:36 -05003862 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05003863 break;
3864 case ELS_CMD_FARP:
James Smart858c9f62007-06-17 19:56:39 -05003865 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3866 "RCV FARP: did:x%x/ste:x%x flg:x%x",
3867 did, vport->port_state, ndlp->nlp_flag);
3868
dea31012005-04-17 16:05:31 -05003869 phba->fc_stat.elsRcvFARP++;
James Smart2e0fef82007-06-17 19:56:36 -05003870 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05003871 break;
3872 case ELS_CMD_FAN:
James Smart858c9f62007-06-17 19:56:39 -05003873 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3874 "RCV FAN: did:x%x/ste:x%x flg:x%x",
3875 did, vport->port_state, ndlp->nlp_flag);
3876
dea31012005-04-17 16:05:31 -05003877 phba->fc_stat.elsRcvFAN++;
James Smart2e0fef82007-06-17 19:56:36 -05003878 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05003879 break;
dea31012005-04-17 16:05:31 -05003880 case ELS_CMD_PRLI:
James Smart858c9f62007-06-17 19:56:39 -05003881 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3882 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
3883 did, vport->port_state, ndlp->nlp_flag);
3884
dea31012005-04-17 16:05:31 -05003885 phba->fc_stat.elsRcvPRLI++;
James Smart2e0fef82007-06-17 19:56:36 -05003886 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05003887 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05003888 break;
3889 }
James Smart2e0fef82007-06-17 19:56:36 -05003890 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
dea31012005-04-17 16:05:31 -05003891 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003892 case ELS_CMD_LIRR:
James Smart858c9f62007-06-17 19:56:39 -05003893 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3894 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
3895 did, vport->port_state, ndlp->nlp_flag);
3896
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003897 phba->fc_stat.elsRcvLIRR++;
James Smart2e0fef82007-06-17 19:56:36 -05003898 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04003899 if (newnode)
James Smart2e0fef82007-06-17 19:56:36 -05003900 lpfc_drop_node(vport, ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003901 break;
3902 case ELS_CMD_RPS:
James Smart858c9f62007-06-17 19:56:39 -05003903 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3904 "RCV RPS: did:x%x/ste:x%x flg:x%x",
3905 did, vport->port_state, ndlp->nlp_flag);
3906
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003907 phba->fc_stat.elsRcvRPS++;
James Smart2e0fef82007-06-17 19:56:36 -05003908 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04003909 if (newnode)
James Smart2e0fef82007-06-17 19:56:36 -05003910 lpfc_drop_node(vport, ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003911 break;
3912 case ELS_CMD_RPL:
James Smart858c9f62007-06-17 19:56:39 -05003913 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3914 "RCV RPL: did:x%x/ste:x%x flg:x%x",
3915 did, vport->port_state, ndlp->nlp_flag);
3916
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003917 phba->fc_stat.elsRcvRPL++;
James Smart2e0fef82007-06-17 19:56:36 -05003918 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04003919 if (newnode)
James Smart2e0fef82007-06-17 19:56:36 -05003920 lpfc_drop_node(vport, ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003921 break;
dea31012005-04-17 16:05:31 -05003922 case ELS_CMD_RNID:
James Smart858c9f62007-06-17 19:56:39 -05003923 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3924 "RCV RNID: did:x%x/ste:x%x flg:x%x",
3925 did, vport->port_state, ndlp->nlp_flag);
3926
dea31012005-04-17 16:05:31 -05003927 phba->fc_stat.elsRcvRNID++;
James Smart2e0fef82007-06-17 19:56:36 -05003928 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04003929 if (newnode)
James Smart2e0fef82007-06-17 19:56:36 -05003930 lpfc_drop_node(vport, ndlp);
dea31012005-04-17 16:05:31 -05003931 break;
3932 default:
James Smart858c9f62007-06-17 19:56:39 -05003933 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3934 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
3935 cmd, did, vport->port_state);
3936
dea31012005-04-17 16:05:31 -05003937 /* Unsupported ELS command, reject */
James Smart858c9f62007-06-17 19:56:39 -05003938 rjt_err = LSRJT_INVALID_CMD;
dea31012005-04-17 16:05:31 -05003939
3940 /* Unknown ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04003941 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3942 "0115 Unknown ELS command x%x "
3943 "received from NPORT x%x\n", cmd, did);
James Smartde0c5b32007-04-25 09:52:27 -04003944 if (newnode)
James Smart2e0fef82007-06-17 19:56:36 -05003945 lpfc_drop_node(vport, ndlp);
dea31012005-04-17 16:05:31 -05003946 break;
3947 }
3948
3949 /* check if need to LS_RJT received ELS cmd */
3950 if (rjt_err) {
James Smart92d7f7b2007-06-17 19:56:38 -05003951 memset(&stat, 0, sizeof(stat));
James Smart858c9f62007-06-17 19:56:39 -05003952 stat.un.b.lsRjtRsnCode = rjt_err;
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04003953 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart858c9f62007-06-17 19:56:39 -05003954 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
3955 NULL);
dea31012005-04-17 16:05:31 -05003956 }
3957
James Smarted957682007-06-17 19:56:37 -05003958 return;
3959
3960dropit:
3961 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
James Smarte8b62012007-08-02 11:10:09 -04003962 "(%d):0111 Dropping received ELS cmd "
James Smarted957682007-06-17 19:56:37 -05003963 "Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04003964 vport ? vport->vpi : 0xffff, icmd->ulpStatus,
3965 icmd->un.ulpWord[4], icmd->ulpTimeout);
James Smarted957682007-06-17 19:56:37 -05003966 phba->fc_stat.elsRcvDrop++;
3967}
3968
James Smart92d7f7b2007-06-17 19:56:38 -05003969static struct lpfc_vport *
3970lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
3971{
3972 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -04003973 unsigned long flags;
James Smart92d7f7b2007-06-17 19:56:38 -05003974
James Smart549e55c2007-08-02 11:09:51 -04003975 spin_lock_irqsave(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05003976 list_for_each_entry(vport, &phba->port_list, listentry) {
James Smart549e55c2007-08-02 11:09:51 -04003977 if (vport->vpi == vpi) {
3978 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05003979 return vport;
James Smart549e55c2007-08-02 11:09:51 -04003980 }
James Smart92d7f7b2007-06-17 19:56:38 -05003981 }
James Smart549e55c2007-08-02 11:09:51 -04003982 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05003983 return NULL;
3984}
James Smarted957682007-06-17 19:56:37 -05003985
3986void
3987lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3988 struct lpfc_iocbq *elsiocb)
3989{
3990 struct lpfc_vport *vport = phba->pport;
James Smarted957682007-06-17 19:56:37 -05003991 IOCB_t *icmd = &elsiocb->iocb;
James Smarted957682007-06-17 19:56:37 -05003992 dma_addr_t paddr;
James Smart92d7f7b2007-06-17 19:56:38 -05003993 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
3994 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
James Smarted957682007-06-17 19:56:37 -05003995
James Smart92d7f7b2007-06-17 19:56:38 -05003996 elsiocb->context2 = NULL;
3997 elsiocb->context3 = NULL;
3998
3999 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
4000 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
4001 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
4002 (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) {
James Smarted957682007-06-17 19:56:37 -05004003 phba->fc_stat.NoRcvBuf++;
4004 /* Not enough posted buffers; Try posting more buffers */
James Smart92d7f7b2007-06-17 19:56:38 -05004005 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
James Smarted957682007-06-17 19:56:37 -05004006 lpfc_post_buffer(phba, pring, 0, 1);
4007 return;
4008 }
4009
James Smart92d7f7b2007-06-17 19:56:38 -05004010 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
4011 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
4012 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
4013 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
4014 vport = phba->pport;
4015 else {
4016 uint16_t vpi = icmd->unsli3.rcvsli3.vpi;
4017 vport = lpfc_find_vport_by_vpid(phba, vpi);
4018 }
4019 }
4020 /* If there are no BDEs associated
4021 * with this IOCB, there is nothing to do.
4022 */
James Smarted957682007-06-17 19:56:37 -05004023 if (icmd->ulpBdeCount == 0)
4024 return;
4025
James Smart92d7f7b2007-06-17 19:56:38 -05004026 /* type of ELS cmd is first 32bit word
4027 * in packet
4028 */
James Smarted957682007-06-17 19:56:37 -05004029 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05004030 elsiocb->context2 = bdeBuf1;
James Smarted957682007-06-17 19:56:37 -05004031 } else {
4032 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
4033 icmd->un.cont64[0].addrLow);
James Smart92d7f7b2007-06-17 19:56:38 -05004034 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
4035 paddr);
James Smarted957682007-06-17 19:56:37 -05004036 }
4037
James Smart92d7f7b2007-06-17 19:56:38 -05004038 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
4039 /*
4040 * The different unsolicited event handlers would tell us
4041 * if they are done with "mp" by setting context2 to NULL.
4042 */
James Smart329f9bc2007-04-25 09:53:01 -04004043 lpfc_nlp_put(elsiocb->context1);
4044 elsiocb->context1 = NULL;
dea31012005-04-17 16:05:31 -05004045 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05004046 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
4047 elsiocb->context2 = NULL;
dea31012005-04-17 16:05:31 -05004048 }
James Smarted957682007-06-17 19:56:37 -05004049
4050 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
James Smart92d7f7b2007-06-17 19:56:38 -05004051 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
James Smarted957682007-06-17 19:56:37 -05004052 icmd->ulpBdeCount == 2) {
James Smart92d7f7b2007-06-17 19:56:38 -05004053 elsiocb->context2 = bdeBuf2;
4054 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
James Smarted957682007-06-17 19:56:37 -05004055 /* free mp if we are done with it */
4056 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05004057 lpfc_in_buf_free(phba, elsiocb->context2);
4058 elsiocb->context2 = NULL;
James Smarted957682007-06-17 19:56:37 -05004059 }
dea31012005-04-17 16:05:31 -05004060 }
dea31012005-04-17 16:05:31 -05004061}
James Smart92d7f7b2007-06-17 19:56:38 -05004062
4063void
4064lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
4065{
4066 struct lpfc_nodelist *ndlp, *ndlp_fdmi;
4067
4068 ndlp = lpfc_findnode_did(vport, NameServer_DID);
4069 if (!ndlp) {
4070 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
4071 if (!ndlp) {
4072 if (phba->fc_topology == TOPOLOGY_LOOP) {
4073 lpfc_disc_start(vport);
4074 return;
4075 }
4076 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04004077 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4078 "0251 NameServer login: no memory\n");
James Smart92d7f7b2007-06-17 19:56:38 -05004079 return;
4080 }
4081 lpfc_nlp_init(vport, ndlp, NameServer_DID);
4082 ndlp->nlp_type |= NLP_FABRIC;
4083 }
4084
4085 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
4086
4087 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
4088 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04004089 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4090 "0252 Cannot issue NameServer login\n");
James Smart92d7f7b2007-06-17 19:56:38 -05004091 return;
4092 }
4093
James Smart3de2a652007-08-02 11:09:59 -04004094 if (vport->cfg_fdmi_on) {
James Smart92d7f7b2007-06-17 19:56:38 -05004095 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
4096 GFP_KERNEL);
4097 if (ndlp_fdmi) {
4098 lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
4099 ndlp_fdmi->nlp_type |= NLP_FABRIC;
4100 ndlp_fdmi->nlp_state =
4101 NLP_STE_PLOGI_ISSUE;
4102 lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID,
4103 0);
4104 }
4105 }
4106 return;
4107}
4108
4109static void
4110lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4111{
4112 struct lpfc_vport *vport = pmb->vport;
4113 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4114 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
4115 MAILBOX_t *mb = &pmb->mb;
4116
4117 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
4118 lpfc_nlp_put(ndlp);
4119
4120 if (mb->mbxStatus) {
James Smarte8b62012007-08-02 11:10:09 -04004121 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
4122 "0915 Register VPI failed: 0x%x\n",
4123 mb->mbxStatus);
James Smart92d7f7b2007-06-17 19:56:38 -05004124
4125 switch (mb->mbxStatus) {
4126 case 0x11: /* unsupported feature */
4127 case 0x9603: /* max_vpi exceeded */
4128 /* giving up on vport registration */
4129 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4130 spin_lock_irq(shost->host_lock);
4131 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
4132 spin_unlock_irq(shost->host_lock);
4133 lpfc_can_disctmo(vport);
4134 break;
4135 default:
4136 /* Try to recover from this error */
4137 lpfc_mbx_unreg_vpi(vport);
4138 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
4139 lpfc_initial_fdisc(vport);
4140 break;
4141 }
4142
4143 } else {
4144 if (vport == phba->pport)
4145 lpfc_issue_fabric_reglogin(vport);
4146 else
4147 lpfc_do_scr_ns_plogi(phba, vport);
4148 }
4149 mempool_free(pmb, phba->mbox_mem_pool);
4150 return;
4151}
4152
4153void
4154lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
4155 struct lpfc_nodelist *ndlp)
4156{
4157 LPFC_MBOXQ_t *mbox;
4158
4159 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4160 if (mbox) {
4161 lpfc_reg_vpi(phba, vport->vpi, vport->fc_myDID, mbox);
4162 mbox->vport = vport;
4163 mbox->context2 = lpfc_nlp_get(ndlp);
4164 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
4165 if (lpfc_sli_issue_mbox(phba, mbox,
4166 MBX_NOWAIT | MBX_STOP_IOCB)
4167 == MBX_NOT_FINISHED) {
4168 mempool_free(mbox, phba->mbox_mem_pool);
4169 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
4170
4171 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04004172 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
4173 "0253 Register VPI: Can't send mbox\n");
James Smart92d7f7b2007-06-17 19:56:38 -05004174 }
4175 } else {
4176 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4177
James Smarte8b62012007-08-02 11:10:09 -04004178 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
4179 "0254 Register VPI: no memory\n");
James Smart92d7f7b2007-06-17 19:56:38 -05004180
4181 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
4182 lpfc_nlp_put(ndlp);
4183 }
4184}
4185
4186static void
4187lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4188 struct lpfc_iocbq *rspiocb)
4189{
4190 struct lpfc_vport *vport = cmdiocb->vport;
4191 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4192 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
4193 struct lpfc_nodelist *np;
4194 struct lpfc_nodelist *next_np;
4195 IOCB_t *irsp = &rspiocb->iocb;
4196 struct lpfc_iocbq *piocb;
4197
James Smarte8b62012007-08-02 11:10:09 -04004198 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4199 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
4200 irsp->ulpStatus, irsp->un.ulpWord[4],
4201 vport->fc_prevDID);
James Smart92d7f7b2007-06-17 19:56:38 -05004202 /* Since all FDISCs are being single threaded, we
4203 * must reset the discovery timer for ALL vports
4204 * waiting to send FDISC when one completes.
4205 */
4206 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
4207 lpfc_set_disctmo(piocb->vport);
4208 }
4209
James Smart858c9f62007-06-17 19:56:39 -05004210 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4211 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
4212 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
4213
James Smart92d7f7b2007-06-17 19:56:38 -05004214 if (irsp->ulpStatus) {
4215 /* Check for retry */
4216 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
4217 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05004218 /* FDISC failed */
James Smarte8b62012007-08-02 11:10:09 -04004219 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4220 "0124 FDISC failed. (%d/%d)\n",
4221 irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smart92d7f7b2007-06-17 19:56:38 -05004222 if (vport->fc_vport->vport_state == FC_VPORT_INITIALIZING)
4223 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4224
4225 lpfc_nlp_put(ndlp);
4226 /* giving up on FDISC. Cancel discovery timer */
4227 lpfc_can_disctmo(vport);
4228 } else {
4229 spin_lock_irq(shost->host_lock);
4230 vport->fc_flag |= FC_FABRIC;
4231 if (vport->phba->fc_topology == TOPOLOGY_LOOP)
4232 vport->fc_flag |= FC_PUBLIC_LOOP;
4233 spin_unlock_irq(shost->host_lock);
4234
4235 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
4236 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
4237 if ((vport->fc_prevDID != vport->fc_myDID) &&
4238 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
4239 /* If our NportID changed, we need to ensure all
4240 * remaining NPORTs get unreg_login'ed so we can
4241 * issue unreg_vpi.
4242 */
4243 list_for_each_entry_safe(np, next_np,
4244 &vport->fc_nodes, nlp_listp) {
4245 if (np->nlp_state != NLP_STE_NPR_NODE
4246 || !(np->nlp_flag & NLP_NPR_ADISC))
4247 continue;
4248 spin_lock_irq(shost->host_lock);
4249 np->nlp_flag &= ~NLP_NPR_ADISC;
4250 spin_unlock_irq(shost->host_lock);
4251 lpfc_unreg_rpi(vport, np);
4252 }
4253 lpfc_mbx_unreg_vpi(vport);
4254 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
4255 }
4256
4257 if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
4258 lpfc_register_new_vport(phba, vport, ndlp);
4259 else
4260 lpfc_do_scr_ns_plogi(phba, vport);
4261
4262 lpfc_nlp_put(ndlp); /* Free Fabric ndlp for vports */
4263 }
4264
4265out:
4266 lpfc_els_free_iocb(phba, cmdiocb);
4267}
4268
4269int
4270lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4271 uint8_t retry)
4272{
4273 struct lpfc_hba *phba = vport->phba;
4274 IOCB_t *icmd;
4275 struct lpfc_iocbq *elsiocb;
4276 struct serv_parm *sp;
4277 uint8_t *pcmd;
4278 uint16_t cmdsize;
4279 int did = ndlp->nlp_DID;
4280 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05004281
4282 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
4283 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
4284 ELS_CMD_FDISC);
4285 if (!elsiocb) {
James Smart92d7f7b2007-06-17 19:56:38 -05004286 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04004287 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4288 "0255 Issue FDISC: no IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05004289 return 1;
4290 }
4291
4292 icmd = &elsiocb->iocb;
4293 icmd->un.elsreq64.myID = 0;
4294 icmd->un.elsreq64.fl = 1;
4295
4296 /* For FDISC, Let FDISC rsp set the NPortID for this VPI */
4297 icmd->ulpCt_h = 1;
4298 icmd->ulpCt_l = 0;
4299
4300 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4301 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
4302 pcmd += sizeof(uint32_t); /* CSP Word 1 */
4303 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
4304 sp = (struct serv_parm *) pcmd;
4305 /* Setup CSPs accordingly for Fabric */
4306 sp->cmn.e_d_tov = 0;
4307 sp->cmn.w2.r_a_tov = 0;
4308 sp->cls1.classValid = 0;
4309 sp->cls2.seqDelivery = 1;
4310 sp->cls3.seqDelivery = 1;
4311
4312 pcmd += sizeof(uint32_t); /* CSP Word 2 */
4313 pcmd += sizeof(uint32_t); /* CSP Word 3 */
4314 pcmd += sizeof(uint32_t); /* CSP Word 4 */
4315 pcmd += sizeof(uint32_t); /* Port Name */
4316 memcpy(pcmd, &vport->fc_portname, 8);
4317 pcmd += sizeof(uint32_t); /* Node Name */
4318 pcmd += sizeof(uint32_t); /* Node Name */
4319 memcpy(pcmd, &vport->fc_nodename, 8);
4320
4321 lpfc_set_disctmo(vport);
4322
4323 phba->fc_stat.elsXmitFDISC++;
4324 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
4325
James Smart858c9f62007-06-17 19:56:39 -05004326 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4327 "Issue FDISC: did:x%x",
4328 did, 0, 0);
4329
James Smart92d7f7b2007-06-17 19:56:38 -05004330 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
4331 if (rc == IOCB_ERROR) {
4332 lpfc_els_free_iocb(phba, elsiocb);
James Smart92d7f7b2007-06-17 19:56:38 -05004333 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04004334 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4335 "0256 Issue FDISC: Cannot send IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05004336 return 1;
4337 }
4338 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
4339 vport->port_state = LPFC_FDISC;
4340 return 0;
4341}
4342
4343static void
4344lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4345 struct lpfc_iocbq *rspiocb)
4346{
4347 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05004348 IOCB_t *irsp;
4349
4350 irsp = &rspiocb->iocb;
4351 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4352 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
4353 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
James Smart92d7f7b2007-06-17 19:56:38 -05004354
4355 lpfc_els_free_iocb(phba, cmdiocb);
4356 vport->unreg_vpi_cmpl = VPORT_ERROR;
4357}
4358
4359int
4360lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4361{
4362 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4363 struct lpfc_hba *phba = vport->phba;
4364 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
4365 IOCB_t *icmd;
4366 struct lpfc_iocbq *elsiocb;
4367 uint8_t *pcmd;
4368 uint16_t cmdsize;
4369
4370 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
4371 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
4372 ELS_CMD_LOGO);
4373 if (!elsiocb)
4374 return 1;
4375
4376 icmd = &elsiocb->iocb;
4377 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4378 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
4379 pcmd += sizeof(uint32_t);
4380
4381 /* Fill in LOGO payload */
4382 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
4383 pcmd += sizeof(uint32_t);
4384 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
4385
James Smart858c9f62007-06-17 19:56:39 -05004386 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4387 "Issue LOGO npiv did:x%x flg:x%x",
4388 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4389
James Smart92d7f7b2007-06-17 19:56:38 -05004390 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
4391 spin_lock_irq(shost->host_lock);
4392 ndlp->nlp_flag |= NLP_LOGO_SND;
4393 spin_unlock_irq(shost->host_lock);
4394 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
4395 spin_lock_irq(shost->host_lock);
4396 ndlp->nlp_flag &= ~NLP_LOGO_SND;
4397 spin_unlock_irq(shost->host_lock);
4398 lpfc_els_free_iocb(phba, elsiocb);
4399 return 1;
4400 }
4401 return 0;
4402}
4403
4404void
4405lpfc_fabric_block_timeout(unsigned long ptr)
4406{
4407 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
4408 unsigned long iflags;
4409 uint32_t tmo_posted;
4410 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
4411 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
4412 if (!tmo_posted)
4413 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
4414 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
4415
4416 if (!tmo_posted) {
4417 spin_lock_irqsave(&phba->hbalock, iflags);
4418 if (phba->work_wait)
4419 lpfc_worker_wake_up(phba);
4420 spin_unlock_irqrestore(&phba->hbalock, iflags);
4421 }
4422}
4423
4424static void
4425lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
4426{
4427 struct lpfc_iocbq *iocb;
4428 unsigned long iflags;
4429 int ret;
4430 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
4431 IOCB_t *cmd;
4432
4433repeat:
4434 iocb = NULL;
4435 spin_lock_irqsave(&phba->hbalock, iflags);
4436 /* Post any pending iocb to the SLI layer */
4437 if (atomic_read(&phba->fabric_iocb_count) == 0) {
4438 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
4439 list);
4440 if (iocb)
4441 atomic_inc(&phba->fabric_iocb_count);
4442 }
4443 spin_unlock_irqrestore(&phba->hbalock, iflags);
4444 if (iocb) {
4445 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
4446 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
4447 iocb->iocb_flag |= LPFC_IO_FABRIC;
4448
James Smart858c9f62007-06-17 19:56:39 -05004449 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
4450 "Fabric sched1: ste:x%x",
4451 iocb->vport->port_state, 0, 0);
4452
James Smart92d7f7b2007-06-17 19:56:38 -05004453 ret = lpfc_sli_issue_iocb(phba, pring, iocb, 0);
4454
4455 if (ret == IOCB_ERROR) {
4456 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
4457 iocb->fabric_iocb_cmpl = NULL;
4458 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
4459 cmd = &iocb->iocb;
4460 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
4461 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
4462 iocb->iocb_cmpl(phba, iocb, iocb);
4463
4464 atomic_dec(&phba->fabric_iocb_count);
4465 goto repeat;
4466 }
4467 }
4468
4469 return;
4470}
4471
4472void
4473lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
4474{
4475 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
4476
4477 lpfc_resume_fabric_iocbs(phba);
4478 return;
4479}
4480
4481static void
4482lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
4483{
4484 int blocked;
4485
4486 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
4487 /* Start a timer to unblock fabric
4488 * iocbs after 100ms
4489 */
4490 if (!blocked)
4491 mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 );
4492
4493 return;
4494}
4495
4496static void
4497lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4498 struct lpfc_iocbq *rspiocb)
4499{
4500 struct ls_rjt stat;
4501
4502 if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
4503 BUG();
4504
4505 switch (rspiocb->iocb.ulpStatus) {
4506 case IOSTAT_NPORT_RJT:
4507 case IOSTAT_FABRIC_RJT:
4508 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
4509 lpfc_block_fabric_iocbs(phba);
4510 }
4511 break;
4512
4513 case IOSTAT_NPORT_BSY:
4514 case IOSTAT_FABRIC_BSY:
4515 lpfc_block_fabric_iocbs(phba);
4516 break;
4517
4518 case IOSTAT_LS_RJT:
4519 stat.un.lsRjtError =
4520 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
4521 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
4522 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
4523 lpfc_block_fabric_iocbs(phba);
4524 break;
4525 }
4526
4527 if (atomic_read(&phba->fabric_iocb_count) == 0)
4528 BUG();
4529
4530 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
4531 cmdiocb->fabric_iocb_cmpl = NULL;
4532 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
4533 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
4534
4535 atomic_dec(&phba->fabric_iocb_count);
4536 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
4537 /* Post any pending iocbs to HBA */
4538 lpfc_resume_fabric_iocbs(phba);
4539 }
4540}
4541
4542int
4543lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
4544{
4545 unsigned long iflags;
4546 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
4547 int ready;
4548 int ret;
4549
4550 if (atomic_read(&phba->fabric_iocb_count) > 1)
4551 BUG();
4552
4553 spin_lock_irqsave(&phba->hbalock, iflags);
4554 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
4555 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
4556
4557 spin_unlock_irqrestore(&phba->hbalock, iflags);
4558 if (ready) {
4559 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
4560 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
4561 iocb->iocb_flag |= LPFC_IO_FABRIC;
4562
James Smart858c9f62007-06-17 19:56:39 -05004563 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
4564 "Fabric sched2: ste:x%x",
4565 iocb->vport->port_state, 0, 0);
4566
James Smart92d7f7b2007-06-17 19:56:38 -05004567 atomic_inc(&phba->fabric_iocb_count);
4568 ret = lpfc_sli_issue_iocb(phba, pring, iocb, 0);
4569
4570 if (ret == IOCB_ERROR) {
4571 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
4572 iocb->fabric_iocb_cmpl = NULL;
4573 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
4574 atomic_dec(&phba->fabric_iocb_count);
4575 }
4576 } else {
4577 spin_lock_irqsave(&phba->hbalock, iflags);
4578 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
4579 spin_unlock_irqrestore(&phba->hbalock, iflags);
4580 ret = IOCB_SUCCESS;
4581 }
4582 return ret;
4583}
4584
4585
4586void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
4587{
4588 LIST_HEAD(completions);
4589 struct lpfc_hba *phba = vport->phba;
4590 struct lpfc_iocbq *tmp_iocb, *piocb;
4591 IOCB_t *cmd;
4592
4593 spin_lock_irq(&phba->hbalock);
4594 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
4595 list) {
4596
4597 if (piocb->vport != vport)
4598 continue;
4599
4600 list_move_tail(&piocb->list, &completions);
4601 }
4602 spin_unlock_irq(&phba->hbalock);
4603
4604 while (!list_empty(&completions)) {
4605 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
4606 list_del_init(&piocb->list);
4607
4608 cmd = &piocb->iocb;
4609 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
4610 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
4611 (piocb->iocb_cmpl) (phba, piocb, piocb);
4612 }
4613}
4614
4615void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
4616{
4617 LIST_HEAD(completions);
4618 struct lpfc_hba *phba = ndlp->vport->phba;
4619 struct lpfc_iocbq *tmp_iocb, *piocb;
4620 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
4621 IOCB_t *cmd;
4622
4623 spin_lock_irq(&phba->hbalock);
4624 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
4625 list) {
4626 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
4627
4628 list_move_tail(&piocb->list, &completions);
4629 }
4630 }
4631 spin_unlock_irq(&phba->hbalock);
4632
4633 while (!list_empty(&completions)) {
4634 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
4635 list_del_init(&piocb->list);
4636
4637 cmd = &piocb->iocb;
4638 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
4639 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
4640 (piocb->iocb_cmpl) (phba, piocb, piocb);
4641 }
4642}
4643
4644void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
4645{
4646 LIST_HEAD(completions);
4647 struct lpfc_iocbq *piocb;
4648 IOCB_t *cmd;
4649
4650 spin_lock_irq(&phba->hbalock);
4651 list_splice_init(&phba->fabric_iocb_list, &completions);
4652 spin_unlock_irq(&phba->hbalock);
4653
4654 while (!list_empty(&completions)) {
4655 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
4656 list_del_init(&piocb->list);
4657
4658 cmd = &piocb->iocb;
4659 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
4660 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
4661 (piocb->iocb_cmpl) (phba, piocb, piocb);
4662 }
4663}
4664
4665
4666void lpfc_fabric_abort_flogi(struct lpfc_hba *phba)
4667{
4668 LIST_HEAD(completions);
4669 struct lpfc_iocbq *tmp_iocb, *piocb;
4670 IOCB_t *cmd;
4671 struct lpfc_nodelist *ndlp;
4672
4673 spin_lock_irq(&phba->hbalock);
4674 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
4675 list) {
4676
4677 cmd = &piocb->iocb;
4678 ndlp = (struct lpfc_nodelist *) piocb->context1;
4679 if (cmd->ulpCommand == CMD_ELS_REQUEST64_CR &&
4680 ndlp != NULL &&
4681 ndlp->nlp_DID == Fabric_DID)
4682 list_move_tail(&piocb->list, &completions);
4683 }
4684 spin_unlock_irq(&phba->hbalock);
4685
4686 while (!list_empty(&completions)) {
4687 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
4688 list_del_init(&piocb->list);
4689
4690 cmd = &piocb->iocb;
4691 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
4692 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
4693 (piocb->iocb_cmpl) (phba, piocb, piocb);
4694 }
4695}
4696
4697