blob: 68fc975d4e52a58cca7278aa37443df8a194ef17 [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 Smart92d7f7b2007-06-17 19:56:38 -050066 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
67 "%d (%d):0237 Pending Link Event during "
dea31012005-04-17 16:05:31 -050068 "Discovery: State x%x\n",
James Smart92d7f7b2007-06-17 19:56:38 -050069 phba->brd_no, vport->vpi, phba->pport->port_state);
dea31012005-04-17 16:05:31 -050070
71 /* CLEAR_LA should re-enable link attention events and
72 * we should then imediately take a LATT event. The
73 * LATT processing should call lpfc_linkdown() which
74 * will cleanup any left over in-progress discovery
75 * events.
76 */
James Smart2e0fef82007-06-17 19:56:36 -050077 spin_lock_irq(shost->host_lock);
78 vport->fc_flag |= FC_ABORT_DISCOVERY;
79 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -050080
James Smart92d7f7b2007-06-17 19:56:38 -050081 if (phba->link_state != LPFC_CLEAR_LA)
James Smarted957682007-06-17 19:56:37 -050082 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -050083
Jamie Wellnitzc9f87352006-02-28 19:25:23 -050084 return 1;
dea31012005-04-17 16:05:31 -050085}
86
87static struct lpfc_iocbq *
James Smart2e0fef82007-06-17 19:56:36 -050088lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp,
89 uint16_t cmdSize, uint8_t retry,
90 struct lpfc_nodelist *ndlp, uint32_t did,
91 uint32_t elscmd)
dea31012005-04-17 16:05:31 -050092{
James Smart2e0fef82007-06-17 19:56:36 -050093 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -040094 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -050095 struct lpfc_dmabuf *pcmd, *prsp, *pbuflist;
96 struct ulp_bde64 *bpl;
97 IOCB_t *icmd;
98
dea31012005-04-17 16:05:31 -050099
James Smart2e0fef82007-06-17 19:56:36 -0500100 if (!lpfc_is_link_up(phba))
101 return NULL;
dea31012005-04-17 16:05:31 -0500102
dea31012005-04-17 16:05:31 -0500103 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400104 elsiocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -0500105
106 if (elsiocb == NULL)
107 return NULL;
dea31012005-04-17 16:05:31 -0500108 icmd = &elsiocb->iocb;
109
110 /* fill in BDEs for command */
111 /* Allocate buffer for command payload */
James Smart92d7f7b2007-06-17 19:56:38 -0500112 if (((pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL)) == 0) ||
dea31012005-04-17 16:05:31 -0500113 ((pcmd->virt = lpfc_mbuf_alloc(phba,
114 MEM_PRI, &(pcmd->phys))) == 0)) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -0800115 kfree(pcmd);
dea31012005-04-17 16:05:31 -0500116
James Bottomley604a3e32005-10-29 10:28:33 -0500117 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -0500118 return NULL;
119 }
120
121 INIT_LIST_HEAD(&pcmd->list);
122
123 /* Allocate buffer for response payload */
124 if (expectRsp) {
James Smart92d7f7b2007-06-17 19:56:38 -0500125 prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -0500126 if (prsp)
127 prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
128 &prsp->phys);
129 if (prsp == 0 || prsp->virt == 0) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -0800130 kfree(prsp);
dea31012005-04-17 16:05:31 -0500131 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
132 kfree(pcmd);
James Bottomley604a3e32005-10-29 10:28:33 -0500133 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -0500134 return NULL;
135 }
136 INIT_LIST_HEAD(&prsp->list);
137 } else {
138 prsp = NULL;
139 }
140
141 /* Allocate buffer for Buffer ptr list */
James Smart92d7f7b2007-06-17 19:56:38 -0500142 pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -0500143 if (pbuflist)
James Smarted957682007-06-17 19:56:37 -0500144 pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
145 &pbuflist->phys);
dea31012005-04-17 16:05:31 -0500146 if (pbuflist == 0 || pbuflist->virt == 0) {
James Bottomley604a3e32005-10-29 10:28:33 -0500147 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -0500148 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
149 lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
150 kfree(pcmd);
151 kfree(prsp);
Jesper Juhlc9475cb2005-11-07 01:01:26 -0800152 kfree(pbuflist);
dea31012005-04-17 16:05:31 -0500153 return NULL;
154 }
155
156 INIT_LIST_HEAD(&pbuflist->list);
157
158 icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
159 icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
160 icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BDL;
James Smart2e0fef82007-06-17 19:56:36 -0500161 icmd->un.elsreq64.remoteID = did; /* DID */
dea31012005-04-17 16:05:31 -0500162 if (expectRsp) {
James Smart92d7f7b2007-06-17 19:56:38 -0500163 icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
dea31012005-04-17 16:05:31 -0500164 icmd->ulpCommand = CMD_ELS_REQUEST64_CR;
James Smart2680eea2007-04-25 09:52:55 -0400165 icmd->ulpTimeout = phba->fc_ratov * 2;
dea31012005-04-17 16:05:31 -0500166 } else {
James Smart92d7f7b2007-06-17 19:56:38 -0500167 icmd->un.elsreq64.bdl.bdeSize = sizeof(struct ulp_bde64);
dea31012005-04-17 16:05:31 -0500168 icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
169 }
dea31012005-04-17 16:05:31 -0500170 icmd->ulpBdeCount = 1;
171 icmd->ulpLe = 1;
172 icmd->ulpClass = CLASS3;
173
James Smart92d7f7b2007-06-17 19:56:38 -0500174 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
175 icmd->un.elsreq64.myID = vport->fc_myDID;
176
177 /* For ELS_REQUEST64_CR, use the VPI by default */
178 icmd->ulpContext = vport->vpi;
179 icmd->ulpCt_h = 0;
180 icmd->ulpCt_l = 1;
181 }
182
dea31012005-04-17 16:05:31 -0500183 bpl = (struct ulp_bde64 *) pbuflist->virt;
184 bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys));
185 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys));
186 bpl->tus.f.bdeSize = cmdSize;
187 bpl->tus.f.bdeFlags = 0;
188 bpl->tus.w = le32_to_cpu(bpl->tus.w);
189
190 if (expectRsp) {
191 bpl++;
192 bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys));
193 bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys));
194 bpl->tus.f.bdeSize = FCELSSIZE;
195 bpl->tus.f.bdeFlags = BUFF_USE_RCV;
196 bpl->tus.w = le32_to_cpu(bpl->tus.w);
197 }
198
199 /* Save for completion so we can release these resources */
James Smart92d7f7b2007-06-17 19:56:38 -0500200 if (elscmd != ELS_CMD_LS_RJT)
201 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart329f9bc2007-04-25 09:53:01 -0400202 elsiocb->context2 = pcmd;
203 elsiocb->context3 = pbuflist;
dea31012005-04-17 16:05:31 -0500204 elsiocb->retry = retry;
James Smart2e0fef82007-06-17 19:56:36 -0500205 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -0500206 elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
207
208 if (prsp) {
209 list_add(&prsp->list, &pcmd->list);
210 }
211
212 if (expectRsp) {
213 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
214 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
James Smart92d7f7b2007-06-17 19:56:38 -0500215 "%d (%d):0116 Xmit ELS command x%x to remote "
James Smart2e0fef82007-06-17 19:56:36 -0500216 "NPORT x%x I/O tag: x%x, port state: x%x\n",
James Smart92d7f7b2007-06-17 19:56:38 -0500217 phba->brd_no, vport->vpi, elscmd, did,
James Smart2e0fef82007-06-17 19:56:36 -0500218 elsiocb->iotag, vport->port_state);
dea31012005-04-17 16:05:31 -0500219 } else {
220 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
221 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
James Smart92d7f7b2007-06-17 19:56:38 -0500222 "%d (%d):0117 Xmit ELS response x%x to remote "
James Smart1dcb58e2007-04-25 09:51:30 -0400223 "NPORT x%x I/O tag: x%x, size: x%x\n",
James Smart92d7f7b2007-06-17 19:56:38 -0500224 phba->brd_no, vport->vpi, elscmd,
James Smart1dcb58e2007-04-25 09:51:30 -0400225 ndlp->nlp_DID, elsiocb->iotag, cmdSize);
dea31012005-04-17 16:05:31 -0500226 }
227
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500228 return elsiocb;
dea31012005-04-17 16:05:31 -0500229}
230
231
232static int
James Smart92d7f7b2007-06-17 19:56:38 -0500233lpfc_issue_fabric_reglogin(struct lpfc_vport *vport)
234{
235 struct lpfc_hba *phba = vport->phba;
236 LPFC_MBOXQ_t *mbox;
237 struct lpfc_dmabuf *mp;
238 struct lpfc_nodelist *ndlp;
239 struct serv_parm *sp;
240 int rc;
241
242 sp = &phba->fc_fabparam;
243 ndlp = lpfc_findnode_did(vport, Fabric_DID);
244 if (!ndlp)
245 goto fail;
246
247 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
248 if (!mbox)
249 goto fail;
250
251 vport->port_state = LPFC_FABRIC_CFG_LINK;
252 lpfc_config_link(phba, mbox);
253 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
254 mbox->vport = vport;
255
256 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT | MBX_STOP_IOCB);
257 if (rc == MBX_NOT_FINISHED)
258 goto fail_free_mbox;
259
260 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
261 if (!mbox)
262 goto fail;
263 rc = lpfc_reg_login(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox,
264 0);
265 if (rc)
266 goto fail_free_mbox;
267
268 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
269 mbox->vport = vport;
270 mbox->context2 = lpfc_nlp_get(ndlp);
271
272 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT | MBX_STOP_IOCB);
273 if (rc == MBX_NOT_FINISHED)
274 goto fail_issue_reg_login;
275
276 return 0;
277
278fail_issue_reg_login:
279 lpfc_nlp_put(ndlp);
280 mp = (struct lpfc_dmabuf *) mbox->context1;
281 lpfc_mbuf_free(phba, mp->virt, mp->phys);
282 kfree(mp);
283fail_free_mbox:
284 mempool_free(mbox, phba->mbox_mem_pool);
285
286fail:
287 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
288 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
289 "%d (%d):0249 Cannot issue Register Fabric login\n",
290 phba->brd_no, vport->vpi);
291 return -ENXIO;
292}
293
294static int
James Smart2e0fef82007-06-17 19:56:36 -0500295lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
296 struct serv_parm *sp, IOCB_t *irsp)
dea31012005-04-17 16:05:31 -0500297{
James Smart2e0fef82007-06-17 19:56:36 -0500298 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
299 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -0500300 struct lpfc_nodelist *np;
301 struct lpfc_nodelist *next_np;
dea31012005-04-17 16:05:31 -0500302
James Smart2e0fef82007-06-17 19:56:36 -0500303 spin_lock_irq(shost->host_lock);
304 vport->fc_flag |= FC_FABRIC;
305 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500306
307 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
308 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
309 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
310
311 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
312
313 if (phba->fc_topology == TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500314 spin_lock_irq(shost->host_lock);
315 vport->fc_flag |= FC_PUBLIC_LOOP;
316 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500317 } else {
318 /*
319 * If we are a N-port connected to a Fabric, fixup sparam's so
320 * logins to devices on remote loops work.
321 */
James Smart2e0fef82007-06-17 19:56:36 -0500322 vport->fc_sparam.cmn.altBbCredit = 1;
dea31012005-04-17 16:05:31 -0500323 }
324
James Smart2e0fef82007-06-17 19:56:36 -0500325 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
dea31012005-04-17 16:05:31 -0500326 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
James Smart92d7f7b2007-06-17 19:56:38 -0500327 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500328 ndlp->nlp_class_sup = 0;
329 if (sp->cls1.classValid)
330 ndlp->nlp_class_sup |= FC_COS_CLASS1;
331 if (sp->cls2.classValid)
332 ndlp->nlp_class_sup |= FC_COS_CLASS2;
333 if (sp->cls3.classValid)
334 ndlp->nlp_class_sup |= FC_COS_CLASS3;
335 if (sp->cls4.classValid)
336 ndlp->nlp_class_sup |= FC_COS_CLASS4;
337 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
338 sp->cmn.bbRcvSizeLsb;
339 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
340
James Smart92d7f7b2007-06-17 19:56:38 -0500341 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
342 if (sp->cmn.response_multiple_NPort) {
343 lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_VPORT,
344 "%d:1816 FLOGI NPIV supported, "
345 "response data 0x%x\n",
346 phba->brd_no,
347 sp->cmn.response_multiple_NPort);
348 phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
349
350 } else {
351 /* Because we asked f/w for NPIV it still expects us
352 to call reg_vnpid atleast for the physcial host */
353 lpfc_printf_log(phba, KERN_WARNING, LOG_ELS | LOG_VPORT,
354 "%d:1817 Fabric does not support NPIV "
355 "- configuring single port mode.\n",
356 phba->brd_no);
James Smart92d7f7b2007-06-17 19:56:38 -0500357 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
358 }
359 }
360
361 if ((vport->fc_prevDID != vport->fc_myDID) &&
362 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
363
364 /* If our NportID changed, we need to ensure all
365 * remaining NPORTs get unreg_login'ed.
366 */
367 list_for_each_entry_safe(np, next_np,
368 &vport->fc_nodes, nlp_listp) {
369 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
370 !(np->nlp_flag & NLP_NPR_ADISC))
371 continue;
372 spin_lock_irq(shost->host_lock);
373 np->nlp_flag &= ~NLP_NPR_ADISC;
374 spin_unlock_irq(shost->host_lock);
375 lpfc_unreg_rpi(vport, np);
376 }
377 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
378 lpfc_mbx_unreg_vpi(vport);
379 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
380 }
381 }
382
James Smart2e0fef82007-06-17 19:56:36 -0500383 ndlp->nlp_sid = irsp->un.ulpWord[4] & Mask_DID;
James Smart92d7f7b2007-06-17 19:56:38 -0500384 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -0500385
James Smart92d7f7b2007-06-17 19:56:38 -0500386 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
387 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) {
388 lpfc_register_new_vport(phba, vport, ndlp);
389 return 0;
390 }
391 lpfc_issue_fabric_reglogin(vport);
dea31012005-04-17 16:05:31 -0500392 return 0;
dea31012005-04-17 16:05:31 -0500393}
394
395/*
396 * We FLOGIed into an NPort, initiate pt2pt protocol
397 */
398static int
James Smart2e0fef82007-06-17 19:56:36 -0500399lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
400 struct serv_parm *sp)
dea31012005-04-17 16:05:31 -0500401{
James Smart2e0fef82007-06-17 19:56:36 -0500402 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
403 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500404 LPFC_MBOXQ_t *mbox;
405 int rc;
406
James Smart2e0fef82007-06-17 19:56:36 -0500407 spin_lock_irq(shost->host_lock);
408 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
409 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500410
411 phba->fc_edtov = FF_DEF_EDTOV;
412 phba->fc_ratov = FF_DEF_RATOV;
James Smart2e0fef82007-06-17 19:56:36 -0500413 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -0500414 sizeof(vport->fc_portname));
dea31012005-04-17 16:05:31 -0500415 if (rc >= 0) {
416 /* This side will initiate the PLOGI */
James Smart2e0fef82007-06-17 19:56:36 -0500417 spin_lock_irq(shost->host_lock);
418 vport->fc_flag |= FC_PT2PT_PLOGI;
419 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500420
421 /*
422 * N_Port ID cannot be 0, set our to LocalID the other
423 * side will be RemoteID.
424 */
425
426 /* not equal */
427 if (rc)
James Smart2e0fef82007-06-17 19:56:36 -0500428 vport->fc_myDID = PT2PT_LocalID;
dea31012005-04-17 16:05:31 -0500429
430 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
431 if (!mbox)
432 goto fail;
433
434 lpfc_config_link(phba, mbox);
435
436 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -0500437 mbox->vport = vport;
dea31012005-04-17 16:05:31 -0500438 rc = lpfc_sli_issue_mbox(phba, mbox,
James Smart92d7f7b2007-06-17 19:56:38 -0500439 MBX_NOWAIT | MBX_STOP_IOCB);
dea31012005-04-17 16:05:31 -0500440 if (rc == MBX_NOT_FINISHED) {
441 mempool_free(mbox, phba->mbox_mem_pool);
442 goto fail;
443 }
James Smart329f9bc2007-04-25 09:53:01 -0400444 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500445
James Smart2e0fef82007-06-17 19:56:36 -0500446 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
dea31012005-04-17 16:05:31 -0500447 if (!ndlp) {
448 /*
449 * Cannot find existing Fabric ndlp, so allocate a
450 * new one
451 */
452 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
453 if (!ndlp)
454 goto fail;
455
James Smart2e0fef82007-06-17 19:56:36 -0500456 lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID);
dea31012005-04-17 16:05:31 -0500457 }
458
459 memcpy(&ndlp->nlp_portname, &sp->portName,
James Smart2e0fef82007-06-17 19:56:36 -0500460 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500461 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
James Smart2e0fef82007-06-17 19:56:36 -0500462 sizeof(struct lpfc_name));
463 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
464 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500465 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500466 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500467 } else {
468 /* This side will wait for the PLOGI */
James Smart329f9bc2007-04-25 09:53:01 -0400469 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500470 }
471
James Smart2e0fef82007-06-17 19:56:36 -0500472 spin_lock_irq(shost->host_lock);
473 vport->fc_flag |= FC_PT2PT;
474 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500475
476 /* Start discovery - this should just do CLEAR_LA */
James Smart2e0fef82007-06-17 19:56:36 -0500477 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -0500478 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500479fail:
dea31012005-04-17 16:05:31 -0500480 return -ENXIO;
481}
482
483static void
James Smart329f9bc2007-04-25 09:53:01 -0400484lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
485 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500486{
James Smart2e0fef82007-06-17 19:56:36 -0500487 struct lpfc_vport *vport = cmdiocb->vport;
488 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500489 IOCB_t *irsp = &rspiocb->iocb;
490 struct lpfc_nodelist *ndlp = cmdiocb->context1;
491 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
492 struct serv_parm *sp;
493 int rc;
494
495 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500496 if (lpfc_els_chk_latt(vport)) {
James Smart329f9bc2007-04-25 09:53:01 -0400497 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500498 goto out;
499 }
500
James Smart858c9f62007-06-17 19:56:39 -0500501 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
502 "FLOGI cmpl: status:x%x/x%x state:x%x",
503 irsp->ulpStatus, irsp->un.ulpWord[4],
504 vport->port_state);
505
dea31012005-04-17 16:05:31 -0500506 if (irsp->ulpStatus) {
507 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -0500508 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -0500509 goto out;
James Smart2e0fef82007-06-17 19:56:36 -0500510
dea31012005-04-17 16:05:31 -0500511 /* FLOGI failed, so there is no fabric */
James Smart2e0fef82007-06-17 19:56:36 -0500512 spin_lock_irq(shost->host_lock);
513 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
514 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500515
James Smart329f9bc2007-04-25 09:53:01 -0400516 /* If private loop, then allow max outstanding els to be
dea31012005-04-17 16:05:31 -0500517 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
518 * alpa map would take too long otherwise.
519 */
520 if (phba->alpa_map[0] == 0) {
James Smart329f9bc2007-04-25 09:53:01 -0400521 phba->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
dea31012005-04-17 16:05:31 -0500522 }
523
524 /* FLOGI failure */
James Smart92d7f7b2007-06-17 19:56:38 -0500525 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
526 "%d (%d):0100 FLOGI failure Data: x%x x%x "
527 "x%x\n",
528 phba->brd_no, vport->vpi,
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500529 irsp->ulpStatus, irsp->un.ulpWord[4],
530 irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -0500531 goto flogifail;
532 }
533
534 /*
535 * The FLogI succeeded. Sync the data for the CPU before
536 * accessing it.
537 */
538 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
539
540 sp = prsp->virt + sizeof(uint32_t);
541
542 /* FLOGI completes successfully */
543 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
James Smart92d7f7b2007-06-17 19:56:38 -0500544 "%d (%d):0101 FLOGI completes sucessfully "
dea31012005-04-17 16:05:31 -0500545 "Data: x%x x%x x%x x%x\n",
James Smart92d7f7b2007-06-17 19:56:38 -0500546 phba->brd_no, vport->vpi,
dea31012005-04-17 16:05:31 -0500547 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
548 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution);
549
James Smart2e0fef82007-06-17 19:56:36 -0500550 if (vport->port_state == LPFC_FLOGI) {
dea31012005-04-17 16:05:31 -0500551 /*
552 * If Common Service Parameters indicate Nport
553 * we are point to point, if Fport we are Fabric.
554 */
555 if (sp->cmn.fPort)
James Smart2e0fef82007-06-17 19:56:36 -0500556 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
dea31012005-04-17 16:05:31 -0500557 else
James Smart2e0fef82007-06-17 19:56:36 -0500558 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
dea31012005-04-17 16:05:31 -0500559
560 if (!rc)
561 goto out;
562 }
563
564flogifail:
James Smart329f9bc2007-04-25 09:53:01 -0400565 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500566
James Smart858c9f62007-06-17 19:56:39 -0500567 if (!lpfc_error_lost_link(irsp)) {
dea31012005-04-17 16:05:31 -0500568 /* FLOGI failed, so just use loop map to make discovery list */
James Smart2e0fef82007-06-17 19:56:36 -0500569 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -0500570
571 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500572 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -0500573 }
574
575out:
576 lpfc_els_free_iocb(phba, cmdiocb);
577}
578
579static int
James Smart2e0fef82007-06-17 19:56:36 -0500580lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -0500581 uint8_t retry)
582{
James Smart2e0fef82007-06-17 19:56:36 -0500583 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500584 struct serv_parm *sp;
585 IOCB_t *icmd;
586 struct lpfc_iocbq *elsiocb;
587 struct lpfc_sli_ring *pring;
588 uint8_t *pcmd;
589 uint16_t cmdsize;
590 uint32_t tmo;
591 int rc;
592
593 pring = &phba->sli.ring[LPFC_ELS_RING];
594
James Smart92d7f7b2007-06-17 19:56:38 -0500595 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart2e0fef82007-06-17 19:56:36 -0500596 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
597 ndlp->nlp_DID, ELS_CMD_FLOGI);
James Smart92d7f7b2007-06-17 19:56:38 -0500598
James Smart488d1462006-03-07 15:02:37 -0500599 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500600 return 1;
dea31012005-04-17 16:05:31 -0500601
602 icmd = &elsiocb->iocb;
603 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
604
605 /* For FLOGI request, remainder of payload is service parameters */
606 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -0500607 pcmd += sizeof(uint32_t);
608 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -0500609 sp = (struct serv_parm *) pcmd;
610
611 /* Setup CSPs accordingly for Fabric */
612 sp->cmn.e_d_tov = 0;
613 sp->cmn.w2.r_a_tov = 0;
614 sp->cls1.classValid = 0;
615 sp->cls2.seqDelivery = 1;
616 sp->cls3.seqDelivery = 1;
617 if (sp->cmn.fcphLow < FC_PH3)
618 sp->cmn.fcphLow = FC_PH3;
619 if (sp->cmn.fcphHigh < FC_PH3)
620 sp->cmn.fcphHigh = FC_PH3;
621
James Smart92d7f7b2007-06-17 19:56:38 -0500622 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
623 sp->cmn.request_multiple_Nport = 1;
624
625 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
626 icmd->ulpCt_h = 1;
627 icmd->ulpCt_l = 0;
628 }
629
James Smart858c9f62007-06-17 19:56:39 -0500630 if (phba->fc_topology != TOPOLOGY_LOOP) {
631 icmd->un.elsreq64.myID = 0;
632 icmd->un.elsreq64.fl = 1;
633 }
634
dea31012005-04-17 16:05:31 -0500635 tmo = phba->fc_ratov;
636 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
James Smart2e0fef82007-06-17 19:56:36 -0500637 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -0500638 phba->fc_ratov = tmo;
639
640 phba->fc_stat.elsXmitFLOGI++;
641 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
James Smart858c9f62007-06-17 19:56:39 -0500642
643 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
644 "Issue FLOGI: opt:x%x",
645 phba->sli3_options, 0, 0);
646
James Smart92d7f7b2007-06-17 19:56:38 -0500647 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
dea31012005-04-17 16:05:31 -0500648 if (rc == IOCB_ERROR) {
649 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500650 return 1;
dea31012005-04-17 16:05:31 -0500651 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500652 return 0;
dea31012005-04-17 16:05:31 -0500653}
654
655int
James Smart2e0fef82007-06-17 19:56:36 -0500656lpfc_els_abort_flogi(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500657{
658 struct lpfc_sli_ring *pring;
659 struct lpfc_iocbq *iocb, *next_iocb;
660 struct lpfc_nodelist *ndlp;
661 IOCB_t *icmd;
662
663 /* Abort outstanding I/O on NPort <nlp_DID> */
664 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
665 "%d:0201 Abort outstanding I/O on NPort x%x\n",
666 phba->brd_no, Fabric_DID);
667
668 pring = &phba->sli.ring[LPFC_ELS_RING];
669
670 /*
671 * Check the txcmplq for an iocb that matches the nport the driver is
672 * searching for.
673 */
James Smart2e0fef82007-06-17 19:56:36 -0500674 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500675 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
676 icmd = &iocb->iocb;
James Smart2e0fef82007-06-17 19:56:36 -0500677 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR &&
678 icmd->un.elsreq64.bdl.ulpIoTag32) {
dea31012005-04-17 16:05:31 -0500679 ndlp = (struct lpfc_nodelist *)(iocb->context1);
James Smart92d7f7b2007-06-17 19:56:38 -0500680 if (ndlp && (ndlp->nlp_DID == Fabric_DID)) {
James Smart07951072007-04-25 09:51:38 -0400681 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
James Smart92d7f7b2007-06-17 19:56:38 -0500682 }
dea31012005-04-17 16:05:31 -0500683 }
684 }
James Smart2e0fef82007-06-17 19:56:36 -0500685 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500686
687 return 0;
688}
689
690int
James Smart2e0fef82007-06-17 19:56:36 -0500691lpfc_initial_flogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -0500692{
James Smart2e0fef82007-06-17 19:56:36 -0500693 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500694 struct lpfc_nodelist *ndlp;
695
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500696 /* First look for the Fabric ndlp */
James Smart2e0fef82007-06-17 19:56:36 -0500697 ndlp = lpfc_findnode_did(vport, Fabric_DID);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500698 if (!ndlp) {
dea31012005-04-17 16:05:31 -0500699 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500700 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
701 if (!ndlp)
702 return 0;
James Smart2e0fef82007-06-17 19:56:36 -0500703 lpfc_nlp_init(vport, ndlp, Fabric_DID);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500704 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500705 lpfc_dequeue_node(vport, ndlp);
dea31012005-04-17 16:05:31 -0500706 }
James Smart2e0fef82007-06-17 19:56:36 -0500707 if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
James Smart329f9bc2007-04-25 09:53:01 -0400708 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500709 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500710 return 1;
dea31012005-04-17 16:05:31 -0500711}
712
James Smart92d7f7b2007-06-17 19:56:38 -0500713int
714lpfc_initial_fdisc(struct lpfc_vport *vport)
715{
716 struct lpfc_hba *phba = vport->phba;
717 struct lpfc_nodelist *ndlp;
718
719 /* First look for the Fabric ndlp */
720 ndlp = lpfc_findnode_did(vport, Fabric_DID);
721 if (!ndlp) {
722 /* Cannot find existing Fabric ndlp, so allocate a new one */
723 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
724 if (!ndlp)
725 return 0;
726 lpfc_nlp_init(vport, ndlp, Fabric_DID);
727 } else {
728 lpfc_dequeue_node(vport, ndlp);
729 }
730 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
731 lpfc_nlp_put(ndlp);
732 }
733 return 1;
734}
dea31012005-04-17 16:05:31 -0500735static void
James Smart2e0fef82007-06-17 19:56:36 -0500736lpfc_more_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -0500737{
738 int sentplogi;
James Smart2e0fef82007-06-17 19:56:36 -0500739 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500740
James Smart2e0fef82007-06-17 19:56:36 -0500741 if (vport->num_disc_nodes)
742 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -0500743
744 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
745 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smart92d7f7b2007-06-17 19:56:38 -0500746 "%d (%d):0232 Continue discovery with %d PLOGIs to go "
dea31012005-04-17 16:05:31 -0500747 "Data: x%x x%x x%x\n",
James Smart92d7f7b2007-06-17 19:56:38 -0500748 phba->brd_no, vport->vpi, vport->num_disc_nodes,
James Smart2e0fef82007-06-17 19:56:36 -0500749 vport->fc_plogi_cnt, vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -0500750
751 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -0500752 if (vport->fc_flag & FC_NLP_MORE)
753 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
754 sentplogi = lpfc_els_disc_plogi(vport);
755
dea31012005-04-17 16:05:31 -0500756 return;
757}
758
James Smart488d1462006-03-07 15:02:37 -0500759static struct lpfc_nodelist *
James Smart92d7f7b2007-06-17 19:56:38 -0500760lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
James Smart488d1462006-03-07 15:02:37 -0500761 struct lpfc_nodelist *ndlp)
762{
James Smart2e0fef82007-06-17 19:56:36 -0500763 struct lpfc_vport *vport = ndlp->vport;
James Smart488d1462006-03-07 15:02:37 -0500764 struct lpfc_nodelist *new_ndlp;
James Smart488d1462006-03-07 15:02:37 -0500765 struct serv_parm *sp;
James Smart92d7f7b2007-06-17 19:56:38 -0500766 uint8_t name[sizeof(struct lpfc_name)];
James Smart488d1462006-03-07 15:02:37 -0500767 uint32_t rc;
768
James Smart2fb9bd82006-12-02 13:33:57 -0500769 /* Fabric nodes can have the same WWPN so we don't bother searching
770 * by WWPN. Just return the ndlp that was given to us.
771 */
772 if (ndlp->nlp_type & NLP_FABRIC)
773 return ndlp;
774
James Smart92d7f7b2007-06-17 19:56:38 -0500775 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
James Smart685f0bf2007-04-25 09:53:08 -0400776 memset(name, 0, sizeof(struct lpfc_name));
James Smart488d1462006-03-07 15:02:37 -0500777
James Smart685f0bf2007-04-25 09:53:08 -0400778 /* Now we find out if the NPort we are logging into, matches the WWPN
James Smart488d1462006-03-07 15:02:37 -0500779 * we have for that ndlp. If not, we have some work to do.
780 */
James Smart2e0fef82007-06-17 19:56:36 -0500781 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
James Smart488d1462006-03-07 15:02:37 -0500782
James Smart92795652006-07-06 15:50:02 -0400783 if (new_ndlp == ndlp)
James Smart488d1462006-03-07 15:02:37 -0500784 return ndlp;
James Smart488d1462006-03-07 15:02:37 -0500785
786 if (!new_ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -0500787 rc = memcmp(&ndlp->nlp_portname, name,
788 sizeof(struct lpfc_name));
James Smart92795652006-07-06 15:50:02 -0400789 if (!rc)
790 return ndlp;
James Smart488d1462006-03-07 15:02:37 -0500791 new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
792 if (!new_ndlp)
793 return ndlp;
794
James Smart2e0fef82007-06-17 19:56:36 -0500795 lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID);
James Smart488d1462006-03-07 15:02:37 -0500796 }
797
James Smart2e0fef82007-06-17 19:56:36 -0500798 lpfc_unreg_rpi(vport, new_ndlp);
James Smart488d1462006-03-07 15:02:37 -0500799 new_ndlp->nlp_DID = ndlp->nlp_DID;
James Smart92795652006-07-06 15:50:02 -0400800 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
James Smart2e0fef82007-06-17 19:56:36 -0500801 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
James Smart488d1462006-03-07 15:02:37 -0500802
James Smart2e0fef82007-06-17 19:56:36 -0500803 /* Move this back to NPR state */
James Smartde0c5b32007-04-25 09:52:27 -0400804 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0)
James Smart2e0fef82007-06-17 19:56:36 -0500805 lpfc_drop_node(vport, ndlp);
James Smart92795652006-07-06 15:50:02 -0400806 else {
James Smart2e0fef82007-06-17 19:56:36 -0500807 lpfc_unreg_rpi(vport, ndlp);
James Smart92795652006-07-06 15:50:02 -0400808 ndlp->nlp_DID = 0; /* Two ndlps cannot have the same did */
James Smart2e0fef82007-06-17 19:56:36 -0500809 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smart92795652006-07-06 15:50:02 -0400810 }
James Smart488d1462006-03-07 15:02:37 -0500811 return new_ndlp;
812}
813
dea31012005-04-17 16:05:31 -0500814static void
James Smart2e0fef82007-06-17 19:56:36 -0500815lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
816 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500817{
James Smart2e0fef82007-06-17 19:56:36 -0500818 struct lpfc_vport *vport = cmdiocb->vport;
819 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500820 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -0500821 struct lpfc_nodelist *ndlp;
James Smart92795652006-07-06 15:50:02 -0400822 struct lpfc_dmabuf *prsp;
dea31012005-04-17 16:05:31 -0500823 int disc, rc, did, type;
824
dea31012005-04-17 16:05:31 -0500825 /* we pass cmdiocb to state machine which needs rspiocb as well */
826 cmdiocb->context_un.rsp_iocb = rspiocb;
827
828 irsp = &rspiocb->iocb;
James Smart858c9f62007-06-17 19:56:39 -0500829 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
830 "PLOGI cmpl: status:x%x/x%x did:x%x",
831 irsp->ulpStatus, irsp->un.ulpWord[4],
832 irsp->un.elsreq64.remoteID);
833
James Smart2e0fef82007-06-17 19:56:36 -0500834 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
James Smarted957682007-06-17 19:56:37 -0500835 if (!ndlp) {
James Smart92d7f7b2007-06-17 19:56:38 -0500836 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
837 "%d (%d):0136 PLOGI completes to NPort x%x "
838 "with no ndlp. Data: x%x x%x x%x\n",
839 phba->brd_no, vport->vpi, irsp->un.elsreq64.remoteID,
840 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->ulpIoTag);
James Smart488d1462006-03-07 15:02:37 -0500841 goto out;
James Smarted957682007-06-17 19:56:37 -0500842 }
dea31012005-04-17 16:05:31 -0500843
844 /* Since ndlp can be freed in the disc state machine, note if this node
845 * is being used during discovery.
846 */
James Smart2e0fef82007-06-17 19:56:36 -0500847 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500848 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
James Smart488d1462006-03-07 15:02:37 -0500849 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500850 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500851 rc = 0;
852
853 /* PLOGI completes to NPort <nlp_DID> */
854 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
James Smart92d7f7b2007-06-17 19:56:38 -0500855 "%d (%d):0102 PLOGI completes to NPort x%x "
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500856 "Data: x%x x%x x%x x%x x%x\n",
James Smart92d7f7b2007-06-17 19:56:38 -0500857 phba->brd_no, vport->vpi, ndlp->nlp_DID,
858 irsp->ulpStatus, irsp->un.ulpWord[4],
859 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -0500860
861 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500862 if (lpfc_els_chk_latt(vport)) {
863 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500864 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500865 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500866 goto out;
867 }
868
869 /* ndlp could be freed in DSM, save these values now */
870 type = ndlp->nlp_type;
871 did = ndlp->nlp_DID;
872
873 if (irsp->ulpStatus) {
874 /* Check for retry */
875 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
876 /* ELS command is being retried */
877 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -0500878 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500879 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500880 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500881 }
882 goto out;
883 }
884
885 /* PLOGI failed */
James Smart92d7f7b2007-06-17 19:56:38 -0500886 if (ndlp->nlp_DID == NameServer_DID) {
887 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
888 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
889 "%d (%d):0250 Nameserver login error: "
890 "0x%x / 0x%x\n",
891 phba->brd_no, vport->vpi,
892 irsp->ulpStatus, irsp->un.ulpWord[4]);
893 }
894
dea31012005-04-17 16:05:31 -0500895 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart858c9f62007-06-17 19:56:39 -0500896 if (lpfc_error_lost_link(irsp)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500897 rc = NLP_STE_FREED_NODE;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500898 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500899 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -0500900 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -0500901 }
902 } else {
903 /* Good status, call state machine */
James Smart92795652006-07-06 15:50:02 -0400904 prsp = list_entry(((struct lpfc_dmabuf *)
James Smart92d7f7b2007-06-17 19:56:38 -0500905 cmdiocb->context2)->list.next,
906 struct lpfc_dmabuf, list);
907 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -0500908 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -0500909 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -0500910 }
911
James Smart2e0fef82007-06-17 19:56:36 -0500912 if (disc && vport->num_disc_nodes) {
dea31012005-04-17 16:05:31 -0500913 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -0500914 lpfc_more_plogi(vport);
dea31012005-04-17 16:05:31 -0500915
James Smart2e0fef82007-06-17 19:56:36 -0500916 if (vport->num_disc_nodes == 0) {
917 spin_lock_irq(shost->host_lock);
918 vport->fc_flag &= ~FC_NDISC_ACTIVE;
919 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500920
James Smart2e0fef82007-06-17 19:56:36 -0500921 lpfc_can_disctmo(vport);
922 if (vport->fc_flag & FC_RSCN_MODE) {
James Smart10d4e952006-04-15 11:53:15 -0400923 /*
924 * Check to see if more RSCNs came in while
925 * we were processing this one.
926 */
James Smart2e0fef82007-06-17 19:56:36 -0500927 if ((vport->fc_rscn_id_cnt == 0) &&
928 (!(vport->fc_flag & FC_RSCN_DISCOVERY))) {
929 spin_lock_irq(shost->host_lock);
930 vport->fc_flag &= ~FC_RSCN_MODE;
931 spin_unlock_irq(shost->host_lock);
James Smart10d4e952006-04-15 11:53:15 -0400932 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500933 lpfc_els_handle_rscn(vport);
James Smart10d4e952006-04-15 11:53:15 -0400934 }
dea31012005-04-17 16:05:31 -0500935 }
936 }
937 }
938
939out:
940 lpfc_els_free_iocb(phba, cmdiocb);
941 return;
942}
943
944int
James Smart2e0fef82007-06-17 19:56:36 -0500945lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
dea31012005-04-17 16:05:31 -0500946{
James Smart2e0fef82007-06-17 19:56:36 -0500947 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500948 struct serv_parm *sp;
949 IOCB_t *icmd;
950 struct lpfc_iocbq *elsiocb;
951 struct lpfc_sli_ring *pring;
952 struct lpfc_sli *psli;
953 uint8_t *pcmd;
954 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -0500955 int ret;
dea31012005-04-17 16:05:31 -0500956
957 psli = &phba->sli;
958 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
959
James Smart92d7f7b2007-06-17 19:56:38 -0500960 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart2e0fef82007-06-17 19:56:36 -0500961 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, NULL, did,
962 ELS_CMD_PLOGI);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500963 if (!elsiocb)
964 return 1;
dea31012005-04-17 16:05:31 -0500965
966 icmd = &elsiocb->iocb;
967 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
968
969 /* For PLOGI request, remainder of payload is service parameters */
970 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -0500971 pcmd += sizeof(uint32_t);
972 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -0500973 sp = (struct serv_parm *) pcmd;
974
975 if (sp->cmn.fcphLow < FC_PH_4_3)
976 sp->cmn.fcphLow = FC_PH_4_3;
977
978 if (sp->cmn.fcphHigh < FC_PH3)
979 sp->cmn.fcphHigh = FC_PH3;
980
James Smart858c9f62007-06-17 19:56:39 -0500981 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
982 "Issue PLOGI: did:x%x",
983 did, 0, 0);
984
dea31012005-04-17 16:05:31 -0500985 phba->fc_stat.elsXmitPLOGI++;
986 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
James Smart92d7f7b2007-06-17 19:56:38 -0500987 ret = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
988
989 if (ret == IOCB_ERROR) {
dea31012005-04-17 16:05:31 -0500990 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500991 return 1;
dea31012005-04-17 16:05:31 -0500992 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500993 return 0;
dea31012005-04-17 16:05:31 -0500994}
995
996static void
James Smart2e0fef82007-06-17 19:56:36 -0500997lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
998 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500999{
James Smart2e0fef82007-06-17 19:56:36 -05001000 struct lpfc_vport *vport = cmdiocb->vport;
1001 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001002 IOCB_t *irsp;
1003 struct lpfc_sli *psli;
1004 struct lpfc_nodelist *ndlp;
1005
1006 psli = &phba->sli;
1007 /* we pass cmdiocb to state machine which needs rspiocb as well */
1008 cmdiocb->context_un.rsp_iocb = rspiocb;
1009
1010 irsp = &(rspiocb->iocb);
1011 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
James Smart2e0fef82007-06-17 19:56:36 -05001012 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001013 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001014 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001015
James Smart858c9f62007-06-17 19:56:39 -05001016 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1017 "PRLI cmpl: status:x%x/x%x did:x%x",
1018 irsp->ulpStatus, irsp->un.ulpWord[4],
1019 ndlp->nlp_DID);
1020
dea31012005-04-17 16:05:31 -05001021 /* PRLI completes to NPort <nlp_DID> */
1022 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
James Smart92d7f7b2007-06-17 19:56:38 -05001023 "%d (%d):0103 PRLI completes to NPort x%x "
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001024 "Data: x%x x%x x%x x%x\n",
James Smart92d7f7b2007-06-17 19:56:38 -05001025 phba->brd_no, vport->vpi, ndlp->nlp_DID,
1026 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->ulpTimeout,
James Smart2e0fef82007-06-17 19:56:36 -05001027 vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001028
James Smart2e0fef82007-06-17 19:56:36 -05001029 vport->fc_prli_sent--;
dea31012005-04-17 16:05:31 -05001030 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001031 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05001032 goto out;
1033
1034 if (irsp->ulpStatus) {
1035 /* Check for retry */
1036 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1037 /* ELS command is being retried */
1038 goto out;
1039 }
1040 /* PRLI failed */
1041 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart858c9f62007-06-17 19:56:39 -05001042 if (lpfc_error_lost_link(irsp)) {
dea31012005-04-17 16:05:31 -05001043 goto out;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001044 } else {
James Smart2e0fef82007-06-17 19:56:36 -05001045 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001046 NLP_EVT_CMPL_PRLI);
dea31012005-04-17 16:05:31 -05001047 }
1048 } else {
1049 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05001050 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001051 NLP_EVT_CMPL_PRLI);
dea31012005-04-17 16:05:31 -05001052 }
1053
1054out:
1055 lpfc_els_free_iocb(phba, cmdiocb);
1056 return;
1057}
1058
1059int
James Smart2e0fef82007-06-17 19:56:36 -05001060lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001061 uint8_t retry)
1062{
James Smart2e0fef82007-06-17 19:56:36 -05001063 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1064 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001065 PRLI *npr;
1066 IOCB_t *icmd;
1067 struct lpfc_iocbq *elsiocb;
1068 struct lpfc_sli_ring *pring;
1069 struct lpfc_sli *psli;
1070 uint8_t *pcmd;
1071 uint16_t cmdsize;
1072
1073 psli = &phba->sli;
1074 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1075
James Smart92d7f7b2007-06-17 19:56:38 -05001076 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
James Smart2e0fef82007-06-17 19:56:36 -05001077 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1078 ndlp->nlp_DID, ELS_CMD_PRLI);
James Smart488d1462006-03-07 15:02:37 -05001079 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001080 return 1;
dea31012005-04-17 16:05:31 -05001081
1082 icmd = &elsiocb->iocb;
1083 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1084
1085 /* For PRLI request, remainder of payload is service parameters */
James Smart92d7f7b2007-06-17 19:56:38 -05001086 memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t)));
dea31012005-04-17 16:05:31 -05001087 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
James Smart92d7f7b2007-06-17 19:56:38 -05001088 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001089
1090 /* For PRLI, remainder of payload is PRLI parameter page */
1091 npr = (PRLI *) pcmd;
1092 /*
1093 * If our firmware version is 3.20 or later,
1094 * set the following bits for FC-TAPE support.
1095 */
1096 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
1097 npr->ConfmComplAllowed = 1;
1098 npr->Retry = 1;
1099 npr->TaskRetryIdReq = 1;
1100 }
1101 npr->estabImagePair = 1;
1102 npr->readXferRdyDis = 1;
1103
1104 /* For FCP support */
1105 npr->prliType = PRLI_FCP_TYPE;
1106 npr->initiatorFunc = 1;
1107
James Smart858c9f62007-06-17 19:56:39 -05001108 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1109 "Issue PRLI: did:x%x",
1110 ndlp->nlp_DID, 0, 0);
1111
dea31012005-04-17 16:05:31 -05001112 phba->fc_stat.elsXmitPRLI++;
1113 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
James Smart2e0fef82007-06-17 19:56:36 -05001114 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001115 ndlp->nlp_flag |= NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001116 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001117 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05001118 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001119 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001120 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001121 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001122 return 1;
dea31012005-04-17 16:05:31 -05001123 }
James Smart2e0fef82007-06-17 19:56:36 -05001124 vport->fc_prli_sent++;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001125 return 0;
dea31012005-04-17 16:05:31 -05001126}
1127
1128static void
James Smart2e0fef82007-06-17 19:56:36 -05001129lpfc_more_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001130{
1131 int sentadisc;
James Smart2e0fef82007-06-17 19:56:36 -05001132 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001133
James Smart2e0fef82007-06-17 19:56:36 -05001134 if (vport->num_disc_nodes)
1135 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001136
1137 /* Continue discovery with <num_disc_nodes> ADISCs to go */
1138 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smart92d7f7b2007-06-17 19:56:38 -05001139 "%d (%d):0210 Continue discovery with %d ADISCs to go "
dea31012005-04-17 16:05:31 -05001140 "Data: x%x x%x x%x\n",
James Smart92d7f7b2007-06-17 19:56:38 -05001141 phba->brd_no, vport->vpi, vport->num_disc_nodes,
James Smart2e0fef82007-06-17 19:56:36 -05001142 vport->fc_adisc_cnt, vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001143
1144 /* Check to see if there are more ADISCs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001145 if (vport->fc_flag & FC_NLP_MORE) {
1146 lpfc_set_disctmo(vport);
1147 /* go thru NPR nodes and issue any remaining ELS ADISCs */
1148 sentadisc = lpfc_els_disc_adisc(vport);
dea31012005-04-17 16:05:31 -05001149 }
1150 return;
1151}
1152
1153static void
James Smart2e0fef82007-06-17 19:56:36 -05001154lpfc_rscn_disc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001155{
James Smart2e0fef82007-06-17 19:56:36 -05001156 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1157
James Smart858c9f62007-06-17 19:56:39 -05001158 lpfc_can_disctmo(vport);
1159
dea31012005-04-17 16:05:31 -05001160 /* RSCN discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001161 /* go thru NPR nodes and issue ELS PLOGIs */
1162 if (vport->fc_npr_cnt)
1163 if (lpfc_els_disc_plogi(vport))
dea31012005-04-17 16:05:31 -05001164 return;
James Smart2e0fef82007-06-17 19:56:36 -05001165
1166 if (vport->fc_flag & FC_RSCN_MODE) {
dea31012005-04-17 16:05:31 -05001167 /* Check to see if more RSCNs came in while we were
1168 * processing this one.
1169 */
James Smart2e0fef82007-06-17 19:56:36 -05001170 if ((vport->fc_rscn_id_cnt == 0) &&
1171 (!(vport->fc_flag & FC_RSCN_DISCOVERY))) {
1172 spin_lock_irq(shost->host_lock);
1173 vport->fc_flag &= ~FC_RSCN_MODE;
1174 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001175 } else {
James Smart2e0fef82007-06-17 19:56:36 -05001176 lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05001177 }
1178 }
1179}
1180
1181static void
James Smart2e0fef82007-06-17 19:56:36 -05001182lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1183 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001184{
James Smart2e0fef82007-06-17 19:56:36 -05001185 struct lpfc_vport *vport = cmdiocb->vport;
1186 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001187 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001188 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001189 int disc;
dea31012005-04-17 16:05:31 -05001190
1191 /* we pass cmdiocb to state machine which needs rspiocb as well */
1192 cmdiocb->context_un.rsp_iocb = rspiocb;
1193
1194 irsp = &(rspiocb->iocb);
1195 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
dea31012005-04-17 16:05:31 -05001196
James Smart858c9f62007-06-17 19:56:39 -05001197 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1198 "ADISC cmpl: status:x%x/x%x did:x%x",
1199 irsp->ulpStatus, irsp->un.ulpWord[4],
1200 ndlp->nlp_DID);
1201
dea31012005-04-17 16:05:31 -05001202 /* Since ndlp can be freed in the disc state machine, note if this node
1203 * is being used during discovery.
1204 */
James Smart2e0fef82007-06-17 19:56:36 -05001205 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001206 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001207 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001208 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001209
1210 /* ADISC completes to NPort <nlp_DID> */
1211 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
James Smart92d7f7b2007-06-17 19:56:38 -05001212 "%d (%d):0104 ADISC completes to NPort x%x "
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001213 "Data: x%x x%x x%x x%x x%x\n",
James Smart92d7f7b2007-06-17 19:56:38 -05001214 phba->brd_no, vport->vpi, ndlp->nlp_DID,
1215 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->ulpTimeout,
1216 disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001217
1218 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001219 if (lpfc_els_chk_latt(vport)) {
1220 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001221 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001222 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001223 goto out;
1224 }
1225
1226 if (irsp->ulpStatus) {
1227 /* Check for retry */
1228 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1229 /* ELS command is being retried */
1230 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05001231 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001232 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001233 spin_unlock_irq(shost->host_lock);
1234 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001235 }
1236 goto out;
1237 }
1238 /* ADISC failed */
1239 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart858c9f62007-06-17 19:56:39 -05001240 if (!lpfc_error_lost_link(irsp)) {
James Smart2e0fef82007-06-17 19:56:36 -05001241 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart858c9f62007-06-17 19:56:39 -05001242 NLP_EVT_CMPL_ADISC);
dea31012005-04-17 16:05:31 -05001243 }
1244 } else {
1245 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05001246 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
dea31012005-04-17 16:05:31 -05001247 NLP_EVT_CMPL_ADISC);
1248 }
1249
James Smart2e0fef82007-06-17 19:56:36 -05001250 if (disc && vport->num_disc_nodes) {
dea31012005-04-17 16:05:31 -05001251 /* Check to see if there are more ADISCs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001252 lpfc_more_adisc(vport);
dea31012005-04-17 16:05:31 -05001253
1254 /* Check to see if we are done with ADISC authentication */
James Smart2e0fef82007-06-17 19:56:36 -05001255 if (vport->num_disc_nodes == 0) {
James Smart92d7f7b2007-06-17 19:56:38 -05001256 /* If we get here, there is nothing left to ADISC */
1257 /*
1258 * For NPIV, cmpl_reg_vpi will set port_state to READY,
1259 * and continue discovery.
1260 */
1261 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
1262 !(vport->fc_flag & FC_RSCN_MODE)) {
1263 lpfc_issue_reg_vpi(phba, vport);
1264 goto out;
1265 }
1266 /*
1267 * For SLI2, we need to set port_state to READY
1268 * and continue discovery.
1269 */
1270 if (vport->port_state < LPFC_VPORT_READY) {
1271 /* If we get here, there is nothing to ADISC */
James Smarted957682007-06-17 19:56:37 -05001272 if (vport->port_type == LPFC_PHYSICAL_PORT)
James Smart2e0fef82007-06-17 19:56:36 -05001273 lpfc_issue_clear_la(phba, vport);
James Smart92d7f7b2007-06-17 19:56:38 -05001274
1275 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
1276 vport->num_disc_nodes = 0;
1277 /* go thru NPR list, issue ELS PLOGIs */
1278 if (vport->fc_npr_cnt)
1279 lpfc_els_disc_plogi(vport);
1280
1281 if (!vport->num_disc_nodes) {
1282 spin_lock_irq(shost->host_lock);
1283 vport->fc_flag &=
1284 ~FC_NDISC_ACTIVE;
1285 spin_unlock_irq(
1286 shost->host_lock);
1287 lpfc_can_disctmo(vport);
1288 }
1289 }
1290 vport->port_state = LPFC_VPORT_READY;
dea31012005-04-17 16:05:31 -05001291 } else {
James Smart2e0fef82007-06-17 19:56:36 -05001292 lpfc_rscn_disc(vport);
dea31012005-04-17 16:05:31 -05001293 }
1294 }
1295 }
dea31012005-04-17 16:05:31 -05001296out:
1297 lpfc_els_free_iocb(phba, cmdiocb);
1298 return;
1299}
1300
1301int
James Smart2e0fef82007-06-17 19:56:36 -05001302lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001303 uint8_t retry)
1304{
James Smart2e0fef82007-06-17 19:56:36 -05001305 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1306 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001307 ADISC *ap;
1308 IOCB_t *icmd;
1309 struct lpfc_iocbq *elsiocb;
James Smart2e0fef82007-06-17 19:56:36 -05001310 struct lpfc_sli *psli = &phba->sli;
1311 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05001312 uint8_t *pcmd;
1313 uint16_t cmdsize;
1314
James Smart92d7f7b2007-06-17 19:56:38 -05001315 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
James Smart2e0fef82007-06-17 19:56:36 -05001316 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1317 ndlp->nlp_DID, ELS_CMD_ADISC);
James Smart488d1462006-03-07 15:02:37 -05001318 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001319 return 1;
dea31012005-04-17 16:05:31 -05001320
1321 icmd = &elsiocb->iocb;
1322 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1323
1324 /* For ADISC request, remainder of payload is service parameters */
1325 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
James Smart92d7f7b2007-06-17 19:56:38 -05001326 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001327
1328 /* Fill in ADISC payload */
1329 ap = (ADISC *) pcmd;
1330 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05001331 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
1332 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05001333 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05001334
James Smart858c9f62007-06-17 19:56:39 -05001335 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1336 "Issue ADISC: did:x%x",
1337 ndlp->nlp_DID, 0, 0);
1338
dea31012005-04-17 16:05:31 -05001339 phba->fc_stat.elsXmitADISC++;
1340 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
James Smart2e0fef82007-06-17 19:56:36 -05001341 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001342 ndlp->nlp_flag |= NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001343 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001344 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05001345 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001346 ndlp->nlp_flag &= ~NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001347 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001348 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001349 return 1;
dea31012005-04-17 16:05:31 -05001350 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001351 return 0;
dea31012005-04-17 16:05:31 -05001352}
1353
1354static void
James Smart2e0fef82007-06-17 19:56:36 -05001355lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1356 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001357{
James Smart2e0fef82007-06-17 19:56:36 -05001358 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1359 struct lpfc_vport *vport = ndlp->vport;
1360 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001361 IOCB_t *irsp;
1362 struct lpfc_sli *psli;
dea31012005-04-17 16:05:31 -05001363
1364 psli = &phba->sli;
1365 /* we pass cmdiocb to state machine which needs rspiocb as well */
1366 cmdiocb->context_un.rsp_iocb = rspiocb;
1367
1368 irsp = &(rspiocb->iocb);
James Smart2e0fef82007-06-17 19:56:36 -05001369 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001370 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001371 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001372
James Smart858c9f62007-06-17 19:56:39 -05001373 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1374 "LOGO cmpl: status:x%x/x%x did:x%x",
1375 irsp->ulpStatus, irsp->un.ulpWord[4],
1376 ndlp->nlp_DID);
1377
dea31012005-04-17 16:05:31 -05001378 /* LOGO completes to NPort <nlp_DID> */
1379 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
James Smart92d7f7b2007-06-17 19:56:38 -05001380 "%d (%d):0105 LOGO completes to NPort x%x "
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001381 "Data: x%x x%x x%x x%x\n",
James Smart92d7f7b2007-06-17 19:56:38 -05001382 phba->brd_no, vport->vpi, ndlp->nlp_DID,
1383 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->ulpTimeout,
James Smart2e0fef82007-06-17 19:56:36 -05001384 vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001385
1386 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001387 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05001388 goto out;
1389
James Smart92d7f7b2007-06-17 19:56:38 -05001390 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
1391 /* NLP_EVT_DEVICE_RM should unregister the RPI
1392 * which should abort all outstanding IOs.
1393 */
1394 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1395 NLP_EVT_DEVICE_RM);
1396 goto out;
1397 }
1398
dea31012005-04-17 16:05:31 -05001399 if (irsp->ulpStatus) {
1400 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -05001401 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -05001402 /* ELS command is being retried */
1403 goto out;
dea31012005-04-17 16:05:31 -05001404 /* LOGO failed */
1405 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart858c9f62007-06-17 19:56:39 -05001406 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05001407 goto out;
James Smart858c9f62007-06-17 19:56:39 -05001408 else
James Smart2e0fef82007-06-17 19:56:36 -05001409 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001410 NLP_EVT_CMPL_LOGO);
dea31012005-04-17 16:05:31 -05001411 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001412 /* Good status, call state machine.
1413 * This will unregister the rpi if needed.
1414 */
James Smart2e0fef82007-06-17 19:56:36 -05001415 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001416 NLP_EVT_CMPL_LOGO);
dea31012005-04-17 16:05:31 -05001417 }
1418
1419out:
1420 lpfc_els_free_iocb(phba, cmdiocb);
1421 return;
1422}
1423
1424int
James Smart2e0fef82007-06-17 19:56:36 -05001425lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001426 uint8_t retry)
1427{
James Smart2e0fef82007-06-17 19:56:36 -05001428 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1429 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001430 IOCB_t *icmd;
1431 struct lpfc_iocbq *elsiocb;
1432 struct lpfc_sli_ring *pring;
1433 struct lpfc_sli *psli;
1434 uint8_t *pcmd;
1435 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05001436 int rc;
dea31012005-04-17 16:05:31 -05001437
1438 psli = &phba->sli;
1439 pring = &psli->ring[LPFC_ELS_RING];
1440
James Smart92d7f7b2007-06-17 19:56:38 -05001441 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
James Smart2e0fef82007-06-17 19:56:36 -05001442 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1443 ndlp->nlp_DID, ELS_CMD_LOGO);
James Smart488d1462006-03-07 15:02:37 -05001444 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001445 return 1;
dea31012005-04-17 16:05:31 -05001446
1447 icmd = &elsiocb->iocb;
1448 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1449 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
James Smart92d7f7b2007-06-17 19:56:38 -05001450 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001451
1452 /* Fill in LOGO payload */
James Smart2e0fef82007-06-17 19:56:36 -05001453 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05001454 pcmd += sizeof(uint32_t);
1455 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05001456
James Smart858c9f62007-06-17 19:56:39 -05001457 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1458 "Issue LOGO: did:x%x",
1459 ndlp->nlp_DID, 0, 0);
1460
dea31012005-04-17 16:05:31 -05001461 phba->fc_stat.elsXmitLOGO++;
1462 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
James Smart2e0fef82007-06-17 19:56:36 -05001463 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001464 ndlp->nlp_flag |= NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001465 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05001466 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
1467
1468 if (rc == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05001469 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001470 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001471 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001472 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001473 return 1;
dea31012005-04-17 16:05:31 -05001474 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001475 return 0;
dea31012005-04-17 16:05:31 -05001476}
1477
1478static void
James Smart2e0fef82007-06-17 19:56:36 -05001479lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1480 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001481{
James Smart2e0fef82007-06-17 19:56:36 -05001482 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -05001483 IOCB_t *irsp;
1484
1485 irsp = &rspiocb->iocb;
1486
James Smart858c9f62007-06-17 19:56:39 -05001487 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1488 "ELS cmd cmpl: status:x%x/x%x did:x%x",
1489 irsp->ulpStatus, irsp->un.ulpWord[4],
1490 irsp->un.elsreq64.remoteID);
1491
dea31012005-04-17 16:05:31 -05001492 /* ELS cmd tag <ulpIoTag> completes */
James Smart92d7f7b2007-06-17 19:56:38 -05001493 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1494 "%d (%d):0106 ELS cmd tag x%x completes Data: x%x x%x "
1495 "x%x\n",
1496 phba->brd_no, vport->vpi,
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001497 irsp->ulpIoTag, irsp->ulpStatus,
1498 irsp->un.ulpWord[4], irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -05001499
1500 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001501 lpfc_els_chk_latt(vport);
dea31012005-04-17 16:05:31 -05001502 lpfc_els_free_iocb(phba, cmdiocb);
1503 return;
1504}
1505
1506int
James Smart2e0fef82007-06-17 19:56:36 -05001507lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05001508{
James Smart2e0fef82007-06-17 19:56:36 -05001509 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001510 IOCB_t *icmd;
1511 struct lpfc_iocbq *elsiocb;
1512 struct lpfc_sli_ring *pring;
1513 struct lpfc_sli *psli;
1514 uint8_t *pcmd;
1515 uint16_t cmdsize;
1516 struct lpfc_nodelist *ndlp;
1517
1518 psli = &phba->sli;
1519 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
James Smart92d7f7b2007-06-17 19:56:38 -05001520 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001521 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1522 if (!ndlp)
1523 return 1;
dea31012005-04-17 16:05:31 -05001524
James Smart2e0fef82007-06-17 19:56:36 -05001525 lpfc_nlp_init(vport, ndlp, nportid);
dea31012005-04-17 16:05:31 -05001526
James Smart2e0fef82007-06-17 19:56:36 -05001527 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1528 ndlp->nlp_DID, ELS_CMD_SCR);
1529
James Smart488d1462006-03-07 15:02:37 -05001530 if (!elsiocb) {
James Smart329f9bc2007-04-25 09:53:01 -04001531 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001532 return 1;
dea31012005-04-17 16:05:31 -05001533 }
1534
1535 icmd = &elsiocb->iocb;
1536 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1537
1538 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
James Smart92d7f7b2007-06-17 19:56:38 -05001539 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001540
1541 /* For SCR, remainder of payload is SCR parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05001542 memset(pcmd, 0, sizeof(SCR));
dea31012005-04-17 16:05:31 -05001543 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
1544
James Smart858c9f62007-06-17 19:56:39 -05001545 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1546 "Issue SCR: did:x%x",
1547 ndlp->nlp_DID, 0, 0);
1548
dea31012005-04-17 16:05:31 -05001549 phba->fc_stat.elsXmitSCR++;
1550 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
dea31012005-04-17 16:05:31 -05001551 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
James Smart329f9bc2007-04-25 09:53:01 -04001552 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001553 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001554 return 1;
dea31012005-04-17 16:05:31 -05001555 }
James Smart329f9bc2007-04-25 09:53:01 -04001556 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001557 return 0;
dea31012005-04-17 16:05:31 -05001558}
1559
1560static int
James Smart2e0fef82007-06-17 19:56:36 -05001561lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05001562{
James Smart2e0fef82007-06-17 19:56:36 -05001563 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001564 IOCB_t *icmd;
1565 struct lpfc_iocbq *elsiocb;
1566 struct lpfc_sli_ring *pring;
1567 struct lpfc_sli *psli;
1568 FARP *fp;
1569 uint8_t *pcmd;
1570 uint32_t *lp;
1571 uint16_t cmdsize;
1572 struct lpfc_nodelist *ondlp;
1573 struct lpfc_nodelist *ndlp;
1574
1575 psli = &phba->sli;
1576 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
James Smart92d7f7b2007-06-17 19:56:38 -05001577 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001578 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1579 if (!ndlp)
1580 return 1;
dea31012005-04-17 16:05:31 -05001581
James Smart2e0fef82007-06-17 19:56:36 -05001582 lpfc_nlp_init(vport, ndlp, nportid);
1583
1584 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1585 ndlp->nlp_DID, ELS_CMD_RNID);
James Smart488d1462006-03-07 15:02:37 -05001586 if (!elsiocb) {
James Smart329f9bc2007-04-25 09:53:01 -04001587 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001588 return 1;
dea31012005-04-17 16:05:31 -05001589 }
1590
1591 icmd = &elsiocb->iocb;
1592 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1593
1594 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
James Smart92d7f7b2007-06-17 19:56:38 -05001595 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001596
1597 /* Fill in FARPR payload */
1598 fp = (FARP *) (pcmd);
James Smart92d7f7b2007-06-17 19:56:38 -05001599 memset(fp, 0, sizeof(FARP));
dea31012005-04-17 16:05:31 -05001600 lp = (uint32_t *) pcmd;
1601 *lp++ = be32_to_cpu(nportid);
James Smart2e0fef82007-06-17 19:56:36 -05001602 *lp++ = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05001603 fp->Rflags = 0;
1604 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
1605
James Smart92d7f7b2007-06-17 19:56:38 -05001606 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
1607 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05001608 ondlp = lpfc_findnode_did(vport, nportid);
1609 if (ondlp) {
dea31012005-04-17 16:05:31 -05001610 memcpy(&fp->OportName, &ondlp->nlp_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05001611 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05001612 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05001613 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05001614 }
1615
James Smart858c9f62007-06-17 19:56:39 -05001616 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1617 "Issue FARPR: did:x%x",
1618 ndlp->nlp_DID, 0, 0);
1619
dea31012005-04-17 16:05:31 -05001620 phba->fc_stat.elsXmitFARPR++;
1621 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
dea31012005-04-17 16:05:31 -05001622 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
James Smart329f9bc2007-04-25 09:53:01 -04001623 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001624 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001625 return 1;
dea31012005-04-17 16:05:31 -05001626 }
James Smart329f9bc2007-04-25 09:53:01 -04001627 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001628 return 0;
dea31012005-04-17 16:05:31 -05001629}
1630
James Smarted957682007-06-17 19:56:37 -05001631static void
1632lpfc_end_rscn(struct lpfc_vport *vport)
1633{
1634 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1635
1636 if (vport->fc_flag & FC_RSCN_MODE) {
1637 /*
1638 * Check to see if more RSCNs came in while we were
1639 * processing this one.
1640 */
1641 if (vport->fc_rscn_id_cnt ||
1642 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1643 lpfc_els_handle_rscn(vport);
1644 else {
1645 spin_lock_irq(shost->host_lock);
1646 vport->fc_flag &= ~FC_RSCN_MODE;
1647 spin_unlock_irq(shost->host_lock);
1648 }
1649 }
1650}
1651
dea31012005-04-17 16:05:31 -05001652void
James Smart2e0fef82007-06-17 19:56:36 -05001653lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
James Smartfdcebe22006-03-07 15:04:01 -05001654{
James Smart2e0fef82007-06-17 19:56:36 -05001655 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1656
1657 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05001658 nlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001659 spin_unlock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05001660 del_timer_sync(&nlp->nlp_delayfunc);
1661 nlp->nlp_last_elscmd = 0;
1662
1663 if (!list_empty(&nlp->els_retry_evt.evt_listp))
1664 list_del_init(&nlp->els_retry_evt.evt_listp);
1665
1666 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
James Smart2e0fef82007-06-17 19:56:36 -05001667 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05001668 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001669 spin_unlock_irq(shost->host_lock);
1670 if (vport->num_disc_nodes) {
James Smartfdcebe22006-03-07 15:04:01 -05001671 /* Check to see if there are more
1672 * PLOGIs to be sent
1673 */
James Smart2e0fef82007-06-17 19:56:36 -05001674 lpfc_more_plogi(vport);
James Smartfdcebe22006-03-07 15:04:01 -05001675
James Smart2e0fef82007-06-17 19:56:36 -05001676 if (vport->num_disc_nodes == 0) {
1677 spin_lock_irq(shost->host_lock);
1678 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1679 spin_unlock_irq(shost->host_lock);
1680 lpfc_can_disctmo(vport);
James Smarted957682007-06-17 19:56:37 -05001681 lpfc_end_rscn(vport);
James Smartfdcebe22006-03-07 15:04:01 -05001682 }
1683 }
1684 }
1685 return;
1686}
1687
1688void
dea31012005-04-17 16:05:31 -05001689lpfc_els_retry_delay(unsigned long ptr)
1690{
James Smart2e0fef82007-06-17 19:56:36 -05001691 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
1692 struct lpfc_vport *vport = ndlp->vport;
James Smart2e0fef82007-06-17 19:56:36 -05001693 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05001694 unsigned long flags;
James Smart2e0fef82007-06-17 19:56:36 -05001695 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
dea31012005-04-17 16:05:31 -05001696
James Smart2e0fef82007-06-17 19:56:36 -05001697 ndlp = (struct lpfc_nodelist *) ptr;
1698 phba = ndlp->vport->phba;
dea31012005-04-17 16:05:31 -05001699 evtp = &ndlp->els_retry_evt;
1700
James Smart92d7f7b2007-06-17 19:56:38 -05001701 spin_lock_irqsave(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05001702 if (!list_empty(&evtp->evt_listp)) {
James Smart92d7f7b2007-06-17 19:56:38 -05001703 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05001704 return;
1705 }
1706
1707 evtp->evt_arg1 = ndlp;
1708 evtp->evt = LPFC_EVT_ELS_RETRY;
1709 list_add_tail(&evtp->evt_listp, &phba->work_list);
1710 if (phba->work_wait)
James Smart92d7f7b2007-06-17 19:56:38 -05001711 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05001712
James Smart92d7f7b2007-06-17 19:56:38 -05001713 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05001714 return;
1715}
1716
1717void
1718lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
1719{
James Smart2e0fef82007-06-17 19:56:36 -05001720 struct lpfc_vport *vport = ndlp->vport;
1721 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1722 uint32_t cmd, did, retry;
dea31012005-04-17 16:05:31 -05001723
James Smart2e0fef82007-06-17 19:56:36 -05001724 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001725 did = ndlp->nlp_DID;
1726 cmd = ndlp->nlp_last_elscmd;
1727 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05001728
1729 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
James Smart2e0fef82007-06-17 19:56:36 -05001730 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001731 return;
1732 }
1733
1734 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001735 spin_unlock_irq(shost->host_lock);
James Smart1a169682006-03-07 15:04:06 -05001736 /*
1737 * If a discovery event readded nlp_delayfunc after timer
1738 * firing and before processing the timer, cancel the
1739 * nlp_delayfunc.
1740 */
1741 del_timer_sync(&ndlp->nlp_delayfunc);
dea31012005-04-17 16:05:31 -05001742 retry = ndlp->nlp_retry;
1743
1744 switch (cmd) {
1745 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05001746 lpfc_issue_els_flogi(vport, ndlp, retry);
dea31012005-04-17 16:05:31 -05001747 break;
1748 case ELS_CMD_PLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05001749 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001750 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001751 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05001752 }
dea31012005-04-17 16:05:31 -05001753 break;
1754 case ELS_CMD_ADISC:
James Smart2e0fef82007-06-17 19:56:36 -05001755 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001756 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001757 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05001758 }
dea31012005-04-17 16:05:31 -05001759 break;
1760 case ELS_CMD_PRLI:
James Smart2e0fef82007-06-17 19:56:36 -05001761 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001762 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001763 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05001764 }
dea31012005-04-17 16:05:31 -05001765 break;
1766 case ELS_CMD_LOGO:
James Smart2e0fef82007-06-17 19:56:36 -05001767 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001768 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001769 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05001770 }
dea31012005-04-17 16:05:31 -05001771 break;
James Smart92d7f7b2007-06-17 19:56:38 -05001772 case ELS_CMD_FDISC:
1773 lpfc_issue_els_fdisc(vport, ndlp, retry);
1774 break;
dea31012005-04-17 16:05:31 -05001775 }
1776 return;
1777}
1778
1779static int
James Smart2e0fef82007-06-17 19:56:36 -05001780lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1781 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001782{
James Smart2e0fef82007-06-17 19:56:36 -05001783 struct lpfc_vport *vport = cmdiocb->vport;
1784 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1785 IOCB_t *irsp = &rspiocb->iocb;
1786 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1787 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
dea31012005-04-17 16:05:31 -05001788 uint32_t *elscmd;
1789 struct ls_rjt stat;
James Smart2e0fef82007-06-17 19:56:36 -05001790 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
1791 uint32_t cmd = 0;
James Smart488d1462006-03-07 15:02:37 -05001792 uint32_t did;
dea31012005-04-17 16:05:31 -05001793
James Smart488d1462006-03-07 15:02:37 -05001794
dea31012005-04-17 16:05:31 -05001795 /* Note: context2 may be 0 for internal driver abort
1796 * of delays ELS command.
1797 */
1798
1799 if (pcmd && pcmd->virt) {
1800 elscmd = (uint32_t *) (pcmd->virt);
1801 cmd = *elscmd++;
1802 }
1803
James Smart329f9bc2007-04-25 09:53:01 -04001804 if (ndlp)
James Smart488d1462006-03-07 15:02:37 -05001805 did = ndlp->nlp_DID;
1806 else {
1807 /* We should only hit this case for retrying PLOGI */
1808 did = irsp->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05001809 ndlp = lpfc_findnode_did(vport, did);
James Smart488d1462006-03-07 15:02:37 -05001810 if (!ndlp && (cmd != ELS_CMD_PLOGI))
1811 return 1;
1812 }
1813
James Smart858c9f62007-06-17 19:56:39 -05001814 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1815 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
1816 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
1817
dea31012005-04-17 16:05:31 -05001818 switch (irsp->ulpStatus) {
1819 case IOSTAT_FCP_RSP_ERROR:
1820 case IOSTAT_REMOTE_STOP:
1821 break;
1822
1823 case IOSTAT_LOCAL_REJECT:
1824 switch ((irsp->un.ulpWord[4] & 0xff)) {
1825 case IOERR_LOOP_OPEN_FAILURE:
James Smart2e0fef82007-06-17 19:56:36 -05001826 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05001827 delay = 1000;
dea31012005-04-17 16:05:31 -05001828 retry = 1;
1829 break;
1830
James Smart92d7f7b2007-06-17 19:56:38 -05001831 case IOERR_ILLEGAL_COMMAND:
1832 if ((phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) &&
1833 (cmd == ELS_CMD_FDISC)) {
1834 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
1835 "%d (%d):0124 FDISC failed (3/6) retrying...\n",
1836 phba->brd_no, vport->vpi);
1837 lpfc_mbx_unreg_vpi(vport);
1838 retry = 1;
1839 /* Always retry for this case */
1840 cmdiocb->retry = 0;
1841 }
1842 break;
1843
dea31012005-04-17 16:05:31 -05001844 case IOERR_NO_RESOURCES:
James Smart858c9f62007-06-17 19:56:39 -05001845 retry = 1;
1846 if (cmdiocb->retry > 100)
1847 delay = 100;
1848 maxretry = 250;
1849 break;
1850
1851 case IOERR_ILLEGAL_FRAME:
James Smart92d7f7b2007-06-17 19:56:38 -05001852 delay = 100;
dea31012005-04-17 16:05:31 -05001853 retry = 1;
1854 break;
1855
James Smart858c9f62007-06-17 19:56:39 -05001856 case IOERR_SEQUENCE_TIMEOUT:
dea31012005-04-17 16:05:31 -05001857 case IOERR_INVALID_RPI:
1858 retry = 1;
1859 break;
1860 }
1861 break;
1862
1863 case IOSTAT_NPORT_RJT:
1864 case IOSTAT_FABRIC_RJT:
1865 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
1866 retry = 1;
1867 break;
1868 }
1869 break;
1870
1871 case IOSTAT_NPORT_BSY:
1872 case IOSTAT_FABRIC_BSY:
1873 retry = 1;
1874 break;
1875
1876 case IOSTAT_LS_RJT:
1877 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
1878 /* Added for Vendor specifc support
1879 * Just keep retrying for these Rsn / Exp codes
1880 */
1881 switch (stat.un.b.lsRjtRsnCode) {
1882 case LSRJT_UNABLE_TPC:
1883 if (stat.un.b.lsRjtRsnCodeExp ==
1884 LSEXP_CMD_IN_PROGRESS) {
1885 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05001886 delay = 1000;
dea31012005-04-17 16:05:31 -05001887 maxretry = 48;
1888 }
1889 retry = 1;
1890 break;
1891 }
1892 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05001893 delay = 1000;
dea31012005-04-17 16:05:31 -05001894 maxretry = lpfc_max_els_tries + 1;
1895 retry = 1;
1896 break;
1897 }
James Smart92d7f7b2007-06-17 19:56:38 -05001898 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
1899 (cmd == ELS_CMD_FDISC) &&
1900 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
1901 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
1902 "%d (%d):0125 FDISC Failed (x%x)."
1903 " Fabric out of resources\n",
1904 phba->brd_no, vport->vpi, stat.un.lsRjtError);
1905 lpfc_vport_set_state(vport,
1906 FC_VPORT_NO_FABRIC_RSCS);
1907 }
dea31012005-04-17 16:05:31 -05001908 break;
1909
1910 case LSRJT_LOGICAL_BSY:
James Smart858c9f62007-06-17 19:56:39 -05001911 if ((cmd == ELS_CMD_PLOGI) ||
1912 (cmd == ELS_CMD_PRLI)) {
James Smart92d7f7b2007-06-17 19:56:38 -05001913 delay = 1000;
dea31012005-04-17 16:05:31 -05001914 maxretry = 48;
James Smart92d7f7b2007-06-17 19:56:38 -05001915 } else if (cmd == ELS_CMD_FDISC) {
1916 /* Always retry for this case */
1917 cmdiocb->retry = 0;
dea31012005-04-17 16:05:31 -05001918 }
1919 retry = 1;
1920 break;
James Smart92d7f7b2007-06-17 19:56:38 -05001921
1922 case LSRJT_LOGICAL_ERR:
1923 case LSRJT_PROTOCOL_ERR:
1924 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
1925 (cmd == ELS_CMD_FDISC) &&
1926 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
1927 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
1928 ) {
1929 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
1930 "%d (%d):0123 FDISC Failed (x%x)."
1931 " Fabric Detected Bad WWN\n",
1932 phba->brd_no, vport->vpi, stat.un.lsRjtError);
1933 lpfc_vport_set_state(vport,
1934 FC_VPORT_FABRIC_REJ_WWN);
1935 }
1936 break;
dea31012005-04-17 16:05:31 -05001937 }
1938 break;
1939
1940 case IOSTAT_INTERMED_RSP:
1941 case IOSTAT_BA_RJT:
1942 break;
1943
1944 default:
1945 break;
1946 }
1947
James Smart488d1462006-03-07 15:02:37 -05001948 if (did == FDMI_DID)
dea31012005-04-17 16:05:31 -05001949 retry = 1;
dea31012005-04-17 16:05:31 -05001950
1951 if ((++cmdiocb->retry) >= maxretry) {
1952 phba->fc_stat.elsRetryExceeded++;
1953 retry = 0;
1954 }
1955
James Smarted957682007-06-17 19:56:37 -05001956 if ((vport->load_flag & FC_UNLOADING) != 0)
1957 retry = 0;
1958
dea31012005-04-17 16:05:31 -05001959 if (retry) {
1960
1961 /* Retry ELS command <elsCmd> to remote NPORT <did> */
1962 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
James Smart92d7f7b2007-06-17 19:56:38 -05001963 "%d (%d):0107 Retry ELS command x%x to remote "
dea31012005-04-17 16:05:31 -05001964 "NPORT x%x Data: x%x x%x\n",
James Smart92d7f7b2007-06-17 19:56:38 -05001965 phba->brd_no, vport->vpi,
James Smart488d1462006-03-07 15:02:37 -05001966 cmd, did, cmdiocb->retry, delay);
dea31012005-04-17 16:05:31 -05001967
James Smart858c9f62007-06-17 19:56:39 -05001968 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
1969 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
1970 ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) {
1971 /* Don't reset timer for no resources */
1972
dea31012005-04-17 16:05:31 -05001973 /* If discovery / RSCN timer is running, reset it */
James Smart2e0fef82007-06-17 19:56:36 -05001974 if (timer_pending(&vport->fc_disctmo) ||
James Smart92d7f7b2007-06-17 19:56:38 -05001975 (vport->fc_flag & FC_RSCN_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05001976 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001977 }
1978
1979 phba->fc_stat.elsXmitRetry++;
James Smart488d1462006-03-07 15:02:37 -05001980 if (ndlp && delay) {
dea31012005-04-17 16:05:31 -05001981 phba->fc_stat.elsDelayRetry++;
1982 ndlp->nlp_retry = cmdiocb->retry;
1983
James Smart92d7f7b2007-06-17 19:56:38 -05001984 /* delay is specified in milliseconds */
1985 mod_timer(&ndlp->nlp_delayfunc,
1986 jiffies + msecs_to_jiffies(delay));
James Smart2e0fef82007-06-17 19:56:36 -05001987 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001988 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001989 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001990
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001991 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart858c9f62007-06-17 19:56:39 -05001992 if (cmd == ELS_CMD_PRLI)
1993 lpfc_nlp_set_state(vport, ndlp,
1994 NLP_STE_REG_LOGIN_ISSUE);
1995 else
1996 lpfc_nlp_set_state(vport, ndlp,
1997 NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05001998 ndlp->nlp_last_elscmd = cmd;
1999
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002000 return 1;
dea31012005-04-17 16:05:31 -05002001 }
2002 switch (cmd) {
2003 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002004 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002005 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -05002006 case ELS_CMD_FDISC:
2007 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
2008 return 1;
dea31012005-04-17 16:05:31 -05002009 case ELS_CMD_PLOGI:
James Smart488d1462006-03-07 15:02:37 -05002010 if (ndlp) {
2011 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002012 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04002013 NLP_STE_PLOGI_ISSUE);
James Smart488d1462006-03-07 15:02:37 -05002014 }
James Smart2e0fef82007-06-17 19:56:36 -05002015 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002016 return 1;
dea31012005-04-17 16:05:31 -05002017 case ELS_CMD_ADISC:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002018 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002019 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2020 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002021 return 1;
dea31012005-04-17 16:05:31 -05002022 case ELS_CMD_PRLI:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002023 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002024 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
2025 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002026 return 1;
dea31012005-04-17 16:05:31 -05002027 case ELS_CMD_LOGO:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002028 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002029 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2030 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002031 return 1;
dea31012005-04-17 16:05:31 -05002032 }
2033 }
2034
2035 /* No retry ELS command <elsCmd> to remote NPORT <did> */
James Smarta58cbd52007-08-02 11:09:43 -04002036 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2037 "0108 No retry ELS command x%x to remote "
2038 "NPORT x%x Retried:%d Error:x%x/%x\n",
2039 cmd, did, cmdiocb->retry, irsp->ulpStatus,
2040 irsp->un.ulpWord[4]);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002041 return 0;
dea31012005-04-17 16:05:31 -05002042}
2043
2044int
James Smart329f9bc2007-04-25 09:53:01 -04002045lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05002046{
2047 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
2048
James Smart329f9bc2007-04-25 09:53:01 -04002049 if (elsiocb->context1) {
2050 lpfc_nlp_put(elsiocb->context1);
2051 elsiocb->context1 = NULL;
2052 }
dea31012005-04-17 16:05:31 -05002053 /* context2 = cmd, context2->next = rsp, context3 = bpl */
2054 if (elsiocb->context2) {
2055 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
2056 /* Free the response before processing the command. */
2057 if (!list_empty(&buf_ptr1->list)) {
2058 list_remove_head(&buf_ptr1->list, buf_ptr,
2059 struct lpfc_dmabuf,
2060 list);
2061 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
2062 kfree(buf_ptr);
2063 }
2064 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
2065 kfree(buf_ptr1);
2066 }
2067
2068 if (elsiocb->context3) {
2069 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
2070 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
2071 kfree(buf_ptr);
2072 }
James Bottomley604a3e32005-10-29 10:28:33 -05002073 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -05002074 return 0;
2075}
2076
2077static void
James Smart2e0fef82007-06-17 19:56:36 -05002078lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2079 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002080{
James Smart2e0fef82007-06-17 19:56:36 -05002081 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2082 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05002083 IOCB_t *irsp;
2084
2085 irsp = &rspiocb->iocb;
2086 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2087 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
2088 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05002089
2090 /* ACC to LOGO completes to NPort <nlp_DID> */
2091 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
James Smart92d7f7b2007-06-17 19:56:38 -05002092 "%d (%d):0109 ACC to LOGO completes to NPort x%x "
dea31012005-04-17 16:05:31 -05002093 "Data: x%x x%x x%x\n",
James Smart92d7f7b2007-06-17 19:56:38 -05002094 phba->brd_no, vport->vpi, ndlp->nlp_DID,
2095 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05002096
dea31012005-04-17 16:05:31 -05002097 switch (ndlp->nlp_state) {
2098 case NLP_STE_UNUSED_NODE: /* node is just allocated */
James Smart2e0fef82007-06-17 19:56:36 -05002099 lpfc_drop_node(vport, ndlp);
dea31012005-04-17 16:05:31 -05002100 break;
2101 case NLP_STE_NPR_NODE: /* NPort Recovery mode */
James Smart2e0fef82007-06-17 19:56:36 -05002102 lpfc_unreg_rpi(vport, ndlp);
dea31012005-04-17 16:05:31 -05002103 break;
2104 default:
2105 break;
2106 }
2107 lpfc_els_free_iocb(phba, cmdiocb);
2108 return;
2109}
2110
James Smart858c9f62007-06-17 19:56:39 -05002111void
2112lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
2113{
2114 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
2115 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
2116
2117 pmb->context1 = NULL;
2118 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2119 kfree(mp);
2120 mempool_free(pmb, phba->mbox_mem_pool);
2121 lpfc_nlp_put(ndlp);
2122 return;
2123}
2124
dea31012005-04-17 16:05:31 -05002125static void
James Smart858c9f62007-06-17 19:56:39 -05002126lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
James Smart329f9bc2007-04-25 09:53:01 -04002127 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002128{
James Smart2e0fef82007-06-17 19:56:36 -05002129 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2130 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
2131 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
James Smart33ccf8d2006-08-17 11:57:58 -04002132 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05002133 LPFC_MBOXQ_t *mbox = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05002134 struct lpfc_dmabuf *mp = NULL;
dea31012005-04-17 16:05:31 -05002135
James Smart33ccf8d2006-08-17 11:57:58 -04002136 irsp = &rspiocb->iocb;
2137
dea31012005-04-17 16:05:31 -05002138 if (cmdiocb->context_un.mbox)
2139 mbox = cmdiocb->context_un.mbox;
2140
dea31012005-04-17 16:05:31 -05002141 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002142 if (!ndlp || lpfc_els_chk_latt(vport)) {
dea31012005-04-17 16:05:31 -05002143 if (mbox) {
James Smart14691152006-12-02 13:34:28 -05002144 mp = (struct lpfc_dmabuf *) mbox->context1;
2145 if (mp) {
2146 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2147 kfree(mp);
2148 }
James Smart329f9bc2007-04-25 09:53:01 -04002149 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05002150 }
2151 goto out;
2152 }
2153
James Smart858c9f62007-06-17 19:56:39 -05002154 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2155 "ACC cmpl: status:x%x/x%x did:x%x",
2156 irsp->ulpStatus, irsp->un.ulpWord[4],
2157 irsp->un.rcvels.remoteID);
2158
dea31012005-04-17 16:05:31 -05002159 /* ELS response tag <ulpIoTag> completes */
2160 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
James Smart92d7f7b2007-06-17 19:56:38 -05002161 "%d (%d):0110 ELS response tag x%x completes "
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002162 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
James Smart92d7f7b2007-06-17 19:56:38 -05002163 phba->brd_no, vport->vpi,
dea31012005-04-17 16:05:31 -05002164 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002165 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
James Smart2e0fef82007-06-17 19:56:36 -05002166 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002167 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05002168
2169 if (mbox) {
2170 if ((rspiocb->iocb.ulpStatus == 0)
2171 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
James Smart2e0fef82007-06-17 19:56:36 -05002172 lpfc_unreg_rpi(vport, ndlp);
James Smart329f9bc2007-04-25 09:53:01 -04002173 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05002174 mbox->vport = vport;
James Smart858c9f62007-06-17 19:56:39 -05002175 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
2176 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
2177 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
2178 }
2179 else {
2180 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
2181 ndlp->nlp_prev_state = ndlp->nlp_state;
2182 lpfc_nlp_set_state(vport, ndlp,
James Smart2e0fef82007-06-17 19:56:36 -05002183 NLP_STE_REG_LOGIN_ISSUE);
James Smart858c9f62007-06-17 19:56:39 -05002184 }
dea31012005-04-17 16:05:31 -05002185 if (lpfc_sli_issue_mbox(phba, mbox,
2186 (MBX_NOWAIT | MBX_STOP_IOCB))
2187 != MBX_NOT_FINISHED) {
2188 goto out;
2189 }
James Smart329f9bc2007-04-25 09:53:01 -04002190 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002191 /* NOTE: we should have messages for unsuccessful
2192 reglogin */
dea31012005-04-17 16:05:31 -05002193 } else {
James Smart858c9f62007-06-17 19:56:39 -05002194 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
2195 if (!lpfc_error_lost_link(irsp) &&
2196 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
2197 lpfc_drop_node(vport, ndlp);
2198 ndlp = NULL;
dea31012005-04-17 16:05:31 -05002199 }
2200 }
James Smart14691152006-12-02 13:34:28 -05002201 mp = (struct lpfc_dmabuf *) mbox->context1;
2202 if (mp) {
2203 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2204 kfree(mp);
2205 }
2206 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05002207 }
2208out:
2209 if (ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05002210 spin_lock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05002211 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
James Smart2e0fef82007-06-17 19:56:36 -05002212 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002213 }
2214 lpfc_els_free_iocb(phba, cmdiocb);
2215 return;
2216}
2217
2218int
James Smart2e0fef82007-06-17 19:56:36 -05002219lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
2220 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
2221 LPFC_MBOXQ_t *mbox, uint8_t newnode)
dea31012005-04-17 16:05:31 -05002222{
James Smart2e0fef82007-06-17 19:56:36 -05002223 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2224 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002225 IOCB_t *icmd;
2226 IOCB_t *oldcmd;
2227 struct lpfc_iocbq *elsiocb;
2228 struct lpfc_sli_ring *pring;
2229 struct lpfc_sli *psli;
2230 uint8_t *pcmd;
2231 uint16_t cmdsize;
2232 int rc;
James Smart82d9a2a2006-04-15 11:53:05 -04002233 ELS_PKT *els_pkt_ptr;
dea31012005-04-17 16:05:31 -05002234
2235 psli = &phba->sli;
2236 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2237 oldcmd = &oldiocb->iocb;
2238
2239 switch (flag) {
2240 case ELS_CMD_ACC:
James Smart92d7f7b2007-06-17 19:56:38 -05002241 cmdsize = sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05002242 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
2243 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05002244 if (!elsiocb) {
James Smart2e0fef82007-06-17 19:56:36 -05002245 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002246 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05002247 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002248 return 1;
dea31012005-04-17 16:05:31 -05002249 }
James Smart2e0fef82007-06-17 19:56:36 -05002250
dea31012005-04-17 16:05:31 -05002251 icmd = &elsiocb->iocb;
2252 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2253 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2254 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05002255 pcmd += sizeof(uint32_t);
James Smart858c9f62007-06-17 19:56:39 -05002256
2257 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2258 "Issue ACC: did:x%x flg:x%x",
2259 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05002260 break;
2261 case ELS_CMD_PLOGI:
James Smart92d7f7b2007-06-17 19:56:38 -05002262 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
James Smart2e0fef82007-06-17 19:56:36 -05002263 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
2264 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05002265 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002266 return 1;
James Smart488d1462006-03-07 15:02:37 -05002267
dea31012005-04-17 16:05:31 -05002268 icmd = &elsiocb->iocb;
2269 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2270 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2271
2272 if (mbox)
2273 elsiocb->context_un.mbox = mbox;
2274
2275 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05002276 pcmd += sizeof(uint32_t);
2277 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
James Smart858c9f62007-06-17 19:56:39 -05002278
2279 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2280 "Issue ACC PLOGI: did:x%x flg:x%x",
2281 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05002282 break;
James Smart82d9a2a2006-04-15 11:53:05 -04002283 case ELS_CMD_PRLO:
James Smart92d7f7b2007-06-17 19:56:38 -05002284 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
James Smart2e0fef82007-06-17 19:56:36 -05002285 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
James Smart82d9a2a2006-04-15 11:53:05 -04002286 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
2287 if (!elsiocb)
2288 return 1;
2289
2290 icmd = &elsiocb->iocb;
2291 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2292 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2293
2294 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
James Smart92d7f7b2007-06-17 19:56:38 -05002295 sizeof(uint32_t) + sizeof(PRLO));
James Smart82d9a2a2006-04-15 11:53:05 -04002296 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
2297 els_pkt_ptr = (ELS_PKT *) pcmd;
2298 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
James Smart858c9f62007-06-17 19:56:39 -05002299
2300 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2301 "Issue ACC PRLO: did:x%x flg:x%x",
2302 ndlp->nlp_DID, ndlp->nlp_flag, 0);
James Smart82d9a2a2006-04-15 11:53:05 -04002303 break;
dea31012005-04-17 16:05:31 -05002304 default:
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002305 return 1;
dea31012005-04-17 16:05:31 -05002306 }
2307
James Smart329f9bc2007-04-25 09:53:01 -04002308 if (newnode) {
2309 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002310 elsiocb->context1 = NULL;
James Smart329f9bc2007-04-25 09:53:01 -04002311 }
dea31012005-04-17 16:05:31 -05002312
2313 /* Xmit ELS ACC response tag <ulpIoTag> */
2314 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
James Smart92d7f7b2007-06-17 19:56:38 -05002315 "%d (%d):0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
James Smart1dcb58e2007-04-25 09:51:30 -04002316 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n",
James Smart92d7f7b2007-06-17 19:56:38 -05002317 phba->brd_no, vport->vpi, elsiocb->iotag,
dea31012005-04-17 16:05:31 -05002318 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
2319 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
2320
2321 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
James Smart2e0fef82007-06-17 19:56:36 -05002322 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002323 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05002324 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002325 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
2326 } else {
James Smart858c9f62007-06-17 19:56:39 -05002327 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05002328 }
2329
2330 phba->fc_stat.elsXmitACC++;
dea31012005-04-17 16:05:31 -05002331 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
dea31012005-04-17 16:05:31 -05002332 if (rc == IOCB_ERROR) {
2333 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002334 return 1;
dea31012005-04-17 16:05:31 -05002335 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002336 return 0;
dea31012005-04-17 16:05:31 -05002337}
2338
2339int
James Smart2e0fef82007-06-17 19:56:36 -05002340lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
James Smart858c9f62007-06-17 19:56:39 -05002341 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
2342 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05002343{
James Smart2e0fef82007-06-17 19:56:36 -05002344 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002345 IOCB_t *icmd;
2346 IOCB_t *oldcmd;
2347 struct lpfc_iocbq *elsiocb;
2348 struct lpfc_sli_ring *pring;
2349 struct lpfc_sli *psli;
2350 uint8_t *pcmd;
2351 uint16_t cmdsize;
2352 int rc;
2353
2354 psli = &phba->sli;
2355 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2356
James Smart92d7f7b2007-06-17 19:56:38 -05002357 cmdsize = 2 * sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05002358 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
2359 ndlp->nlp_DID, ELS_CMD_LS_RJT);
James Smart488d1462006-03-07 15:02:37 -05002360 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002361 return 1;
dea31012005-04-17 16:05:31 -05002362
2363 icmd = &elsiocb->iocb;
2364 oldcmd = &oldiocb->iocb;
2365 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2366 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2367
2368 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
James Smart92d7f7b2007-06-17 19:56:38 -05002369 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002370 *((uint32_t *) (pcmd)) = rejectError;
2371
James Smart858c9f62007-06-17 19:56:39 -05002372 if (mbox) {
2373 elsiocb->context_un.mbox = mbox;
2374 elsiocb->context1 = lpfc_nlp_get(ndlp);
2375 }
2376
dea31012005-04-17 16:05:31 -05002377 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
2378 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
James Smart92d7f7b2007-06-17 19:56:38 -05002379 "%d (%d):0129 Xmit ELS RJT x%x response tag x%x "
2380 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
2381 "rpi x%x\n",
2382 phba->brd_no, vport->vpi, rejectError, elsiocb->iotag,
dea31012005-04-17 16:05:31 -05002383 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
2384 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
2385
James Smart858c9f62007-06-17 19:56:39 -05002386 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2387 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
2388 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
2389
dea31012005-04-17 16:05:31 -05002390 phba->fc_stat.elsXmitLSRJT++;
James Smart858c9f62007-06-17 19:56:39 -05002391 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05002392 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
dea31012005-04-17 16:05:31 -05002393 if (rc == IOCB_ERROR) {
2394 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002395 return 1;
dea31012005-04-17 16:05:31 -05002396 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002397 return 0;
dea31012005-04-17 16:05:31 -05002398}
2399
2400int
James Smart2e0fef82007-06-17 19:56:36 -05002401lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
2402 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05002403{
James Smart2e0fef82007-06-17 19:56:36 -05002404 struct lpfc_hba *phba = vport->phba;
2405 struct lpfc_sli *psli = &phba->sli;
2406 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05002407 ADISC *ap;
James Smart2e0fef82007-06-17 19:56:36 -05002408 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05002409 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002410 uint8_t *pcmd;
2411 uint16_t cmdsize;
2412 int rc;
2413
James Smart92d7f7b2007-06-17 19:56:38 -05002414 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
James Smart2e0fef82007-06-17 19:56:36 -05002415 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
2416 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05002417 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002418 return 1;
dea31012005-04-17 16:05:31 -05002419
dea31012005-04-17 16:05:31 -05002420 icmd = &elsiocb->iocb;
2421 oldcmd = &oldiocb->iocb;
2422 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04002423
2424 /* Xmit ADISC ACC response tag <ulpIoTag> */
2425 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
James Smart92d7f7b2007-06-17 19:56:38 -05002426 "%d (%d):0130 Xmit ADISC ACC response iotag x%x xri: "
James Smart5b8bd0c2007-04-25 09:52:49 -04002427 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
James Smart92d7f7b2007-06-17 19:56:38 -05002428 phba->brd_no, vport->vpi, elsiocb->iotag,
James Smart5b8bd0c2007-04-25 09:52:49 -04002429 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
2430 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
2431
dea31012005-04-17 16:05:31 -05002432 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2433
2434 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05002435 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002436
2437 ap = (ADISC *) (pcmd);
2438 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05002439 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2440 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002441 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002442
James Smart858c9f62007-06-17 19:56:39 -05002443 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2444 "Issue ACC ADISC: did:x%x flg:x%x",
2445 ndlp->nlp_DID, ndlp->nlp_flag, 0);
2446
dea31012005-04-17 16:05:31 -05002447 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05002448 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05002449 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
dea31012005-04-17 16:05:31 -05002450 if (rc == IOCB_ERROR) {
2451 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002452 return 1;
dea31012005-04-17 16:05:31 -05002453 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002454 return 0;
dea31012005-04-17 16:05:31 -05002455}
2456
2457int
James Smart2e0fef82007-06-17 19:56:36 -05002458lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
James Smart5b8bd0c2007-04-25 09:52:49 -04002459 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05002460{
James Smart2e0fef82007-06-17 19:56:36 -05002461 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002462 PRLI *npr;
2463 lpfc_vpd_t *vpd;
2464 IOCB_t *icmd;
2465 IOCB_t *oldcmd;
2466 struct lpfc_iocbq *elsiocb;
2467 struct lpfc_sli_ring *pring;
2468 struct lpfc_sli *psli;
2469 uint8_t *pcmd;
2470 uint16_t cmdsize;
2471 int rc;
2472
2473 psli = &phba->sli;
2474 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2475
James Smart92d7f7b2007-06-17 19:56:38 -05002476 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
James Smart2e0fef82007-06-17 19:56:36 -05002477 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
James Smart92d7f7b2007-06-17 19:56:38 -05002478 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002479 if (!elsiocb)
2480 return 1;
dea31012005-04-17 16:05:31 -05002481
dea31012005-04-17 16:05:31 -05002482 icmd = &elsiocb->iocb;
2483 oldcmd = &oldiocb->iocb;
2484 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04002485
2486 /* Xmit PRLI ACC response tag <ulpIoTag> */
2487 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
James Smart92d7f7b2007-06-17 19:56:38 -05002488 "%d (%d):0131 Xmit PRLI ACC response tag x%x xri x%x, "
James Smart5b8bd0c2007-04-25 09:52:49 -04002489 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
James Smart92d7f7b2007-06-17 19:56:38 -05002490 phba->brd_no, vport->vpi, elsiocb->iotag,
James Smart5b8bd0c2007-04-25 09:52:49 -04002491 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
2492 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
2493
dea31012005-04-17 16:05:31 -05002494 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2495
2496 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
James Smart92d7f7b2007-06-17 19:56:38 -05002497 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002498
2499 /* For PRLI, remainder of payload is PRLI parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05002500 memset(pcmd, 0, sizeof(PRLI));
dea31012005-04-17 16:05:31 -05002501
2502 npr = (PRLI *) pcmd;
2503 vpd = &phba->vpd;
2504 /*
2505 * If our firmware version is 3.20 or later,
2506 * set the following bits for FC-TAPE support.
2507 */
2508 if (vpd->rev.feaLevelHigh >= 0x02) {
2509 npr->ConfmComplAllowed = 1;
2510 npr->Retry = 1;
2511 npr->TaskRetryIdReq = 1;
2512 }
2513
2514 npr->acceptRspCode = PRLI_REQ_EXECUTED;
2515 npr->estabImagePair = 1;
2516 npr->readXferRdyDis = 1;
2517 npr->ConfmComplAllowed = 1;
2518
2519 npr->prliType = PRLI_FCP_TYPE;
2520 npr->initiatorFunc = 1;
2521
James Smart858c9f62007-06-17 19:56:39 -05002522 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2523 "Issue ACC PRLI: did:x%x flg:x%x",
2524 ndlp->nlp_DID, ndlp->nlp_flag, 0);
2525
dea31012005-04-17 16:05:31 -05002526 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05002527 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05002528
dea31012005-04-17 16:05:31 -05002529 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
dea31012005-04-17 16:05:31 -05002530 if (rc == IOCB_ERROR) {
2531 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002532 return 1;
dea31012005-04-17 16:05:31 -05002533 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002534 return 0;
dea31012005-04-17 16:05:31 -05002535}
2536
2537static int
James Smart2e0fef82007-06-17 19:56:36 -05002538lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
James Smart329f9bc2007-04-25 09:53:01 -04002539 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05002540{
James Smart2e0fef82007-06-17 19:56:36 -05002541 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002542 RNID *rn;
James Smart2e0fef82007-06-17 19:56:36 -05002543 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05002544 struct lpfc_iocbq *elsiocb;
2545 struct lpfc_sli_ring *pring;
2546 struct lpfc_sli *psli;
2547 uint8_t *pcmd;
2548 uint16_t cmdsize;
2549 int rc;
2550
2551 psli = &phba->sli;
2552 pring = &psli->ring[LPFC_ELS_RING];
2553
James Smart92d7f7b2007-06-17 19:56:38 -05002554 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
2555 + (2 * sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002556 if (format)
James Smart92d7f7b2007-06-17 19:56:38 -05002557 cmdsize += sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05002558
James Smart2e0fef82007-06-17 19:56:36 -05002559 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
2560 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05002561 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002562 return 1;
dea31012005-04-17 16:05:31 -05002563
dea31012005-04-17 16:05:31 -05002564 icmd = &elsiocb->iocb;
2565 oldcmd = &oldiocb->iocb;
2566 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04002567
2568 /* Xmit RNID ACC response tag <ulpIoTag> */
2569 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
James Smart92d7f7b2007-06-17 19:56:38 -05002570 "%d (%d):0132 Xmit RNID ACC response tag x%x "
James Smart5b8bd0c2007-04-25 09:52:49 -04002571 "xri x%x\n",
James Smart92d7f7b2007-06-17 19:56:38 -05002572 phba->brd_no, vport->vpi, elsiocb->iotag,
James Smart5b8bd0c2007-04-25 09:52:49 -04002573 elsiocb->iocb.ulpContext);
2574
dea31012005-04-17 16:05:31 -05002575 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2576
2577 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05002578 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002579
James Smart92d7f7b2007-06-17 19:56:38 -05002580 memset(pcmd, 0, sizeof(RNID));
dea31012005-04-17 16:05:31 -05002581 rn = (RNID *) (pcmd);
2582 rn->Format = format;
James Smart92d7f7b2007-06-17 19:56:38 -05002583 rn->CommonLen = (2 * sizeof(struct lpfc_name));
2584 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2585 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002586 switch (format) {
2587 case 0:
2588 rn->SpecificLen = 0;
2589 break;
2590 case RNID_TOPOLOGY_DISC:
James Smart92d7f7b2007-06-17 19:56:38 -05002591 rn->SpecificLen = sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05002592 memcpy(&rn->un.topologyDisc.portName,
James Smart92d7f7b2007-06-17 19:56:38 -05002593 &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002594 rn->un.topologyDisc.unitType = RNID_HBA;
2595 rn->un.topologyDisc.physPort = 0;
2596 rn->un.topologyDisc.attachedNodes = 0;
2597 break;
2598 default:
2599 rn->CommonLen = 0;
2600 rn->SpecificLen = 0;
2601 break;
2602 }
2603
James Smart858c9f62007-06-17 19:56:39 -05002604 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2605 "Issue ACC RNID: did:x%x flg:x%x",
2606 ndlp->nlp_DID, ndlp->nlp_flag, 0);
2607
dea31012005-04-17 16:05:31 -05002608 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05002609 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart329f9bc2007-04-25 09:53:01 -04002610 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002611 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
2612 * it could be freed */
2613
dea31012005-04-17 16:05:31 -05002614 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
dea31012005-04-17 16:05:31 -05002615 if (rc == IOCB_ERROR) {
2616 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002617 return 1;
dea31012005-04-17 16:05:31 -05002618 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002619 return 0;
dea31012005-04-17 16:05:31 -05002620}
2621
2622int
James Smart2e0fef82007-06-17 19:56:36 -05002623lpfc_els_disc_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002624{
James Smart2e0fef82007-06-17 19:56:36 -05002625 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002626 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05002627 int sentadisc = 0;
dea31012005-04-17 16:05:31 -05002628
James Smart685f0bf2007-04-25 09:53:08 -04002629 /* go thru NPR nodes and issue any remaining ELS ADISCs */
James Smart2e0fef82007-06-17 19:56:36 -05002630 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smart685f0bf2007-04-25 09:53:08 -04002631 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
2632 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
2633 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
James Smart2e0fef82007-06-17 19:56:36 -05002634 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04002635 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05002636 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04002637 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002638 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2639 lpfc_issue_els_adisc(vport, ndlp, 0);
James Smart685f0bf2007-04-25 09:53:08 -04002640 sentadisc++;
James Smart2e0fef82007-06-17 19:56:36 -05002641 vport->num_disc_nodes++;
2642 if (vport->num_disc_nodes >=
2643 vport->phba->cfg_discovery_threads) {
2644 spin_lock_irq(shost->host_lock);
2645 vport->fc_flag |= FC_NLP_MORE;
2646 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04002647 break;
dea31012005-04-17 16:05:31 -05002648 }
2649 }
2650 }
2651 if (sentadisc == 0) {
James Smart2e0fef82007-06-17 19:56:36 -05002652 spin_lock_irq(shost->host_lock);
2653 vport->fc_flag &= ~FC_NLP_MORE;
2654 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002655 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002656 return sentadisc;
dea31012005-04-17 16:05:31 -05002657}
2658
2659int
James Smart2e0fef82007-06-17 19:56:36 -05002660lpfc_els_disc_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002661{
James Smart2e0fef82007-06-17 19:56:36 -05002662 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002663 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05002664 int sentplogi = 0;
dea31012005-04-17 16:05:31 -05002665
James Smart2e0fef82007-06-17 19:56:36 -05002666 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
2667 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smart685f0bf2007-04-25 09:53:08 -04002668 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
2669 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
2670 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
2671 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
2672 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002673 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2674 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
James Smart685f0bf2007-04-25 09:53:08 -04002675 sentplogi++;
James Smart2e0fef82007-06-17 19:56:36 -05002676 vport->num_disc_nodes++;
2677 if (vport->num_disc_nodes >=
2678 vport->phba->cfg_discovery_threads) {
2679 spin_lock_irq(shost->host_lock);
2680 vport->fc_flag |= FC_NLP_MORE;
2681 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04002682 break;
dea31012005-04-17 16:05:31 -05002683 }
2684 }
2685 }
2686 if (sentplogi == 0) {
James Smart2e0fef82007-06-17 19:56:36 -05002687 spin_lock_irq(shost->host_lock);
2688 vport->fc_flag &= ~FC_NLP_MORE;
2689 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002690 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002691 return sentplogi;
dea31012005-04-17 16:05:31 -05002692}
2693
James Smart92d7f7b2007-06-17 19:56:38 -05002694void
James Smart2e0fef82007-06-17 19:56:36 -05002695lpfc_els_flush_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002696{
James Smart2e0fef82007-06-17 19:56:36 -05002697 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2698 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002699 int i;
2700
James Smart2e0fef82007-06-17 19:56:36 -05002701 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05002702 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
James Smart2e0fef82007-06-17 19:56:36 -05002703 vport->fc_rscn_id_list[i] = NULL;
dea31012005-04-17 16:05:31 -05002704 }
James Smart2e0fef82007-06-17 19:56:36 -05002705 spin_lock_irq(shost->host_lock);
2706 vport->fc_rscn_id_cnt = 0;
2707 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
2708 spin_unlock_irq(shost->host_lock);
2709 lpfc_can_disctmo(vport);
dea31012005-04-17 16:05:31 -05002710}
2711
2712int
James Smart2e0fef82007-06-17 19:56:36 -05002713lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05002714{
2715 D_ID ns_did;
2716 D_ID rscn_did;
dea31012005-04-17 16:05:31 -05002717 uint32_t *lp;
James Smart92d7f7b2007-06-17 19:56:38 -05002718 uint32_t payload_len, i;
James Smart2e0fef82007-06-17 19:56:36 -05002719 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002720
2721 ns_did.un.word = did;
dea31012005-04-17 16:05:31 -05002722
2723 /* Never match fabric nodes for RSCNs */
2724 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
James Smart2e0fef82007-06-17 19:56:36 -05002725 return 0;
dea31012005-04-17 16:05:31 -05002726
2727 /* If we are doing a FULL RSCN rediscovery, match everything */
James Smart2e0fef82007-06-17 19:56:36 -05002728 if (vport->fc_flag & FC_RSCN_DISCOVERY)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002729 return did;
dea31012005-04-17 16:05:31 -05002730
James Smart2e0fef82007-06-17 19:56:36 -05002731 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05002732 lp = vport->fc_rscn_id_list[i]->virt;
2733 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
2734 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05002735 while (payload_len) {
James Smart92d7f7b2007-06-17 19:56:38 -05002736 rscn_did.un.word = be32_to_cpu(*lp++);
2737 payload_len -= sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002738 switch (rscn_did.un.b.resv) {
2739 case 0: /* Single N_Port ID effected */
James Smart2e0fef82007-06-17 19:56:36 -05002740 if (ns_did.un.word == rscn_did.un.word)
James Smart92d7f7b2007-06-17 19:56:38 -05002741 return did;
dea31012005-04-17 16:05:31 -05002742 break;
2743 case 1: /* Whole N_Port Area effected */
2744 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
2745 && (ns_did.un.b.area == rscn_did.un.b.area))
James Smart92d7f7b2007-06-17 19:56:38 -05002746 return did;
dea31012005-04-17 16:05:31 -05002747 break;
2748 case 2: /* Whole N_Port Domain effected */
2749 if (ns_did.un.b.domain == rscn_did.un.b.domain)
James Smart92d7f7b2007-06-17 19:56:38 -05002750 return did;
dea31012005-04-17 16:05:31 -05002751 break;
2752 default:
James Smart2e0fef82007-06-17 19:56:36 -05002753 /* Unknown Identifier in RSCN node */
dea31012005-04-17 16:05:31 -05002754 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
James Smart92d7f7b2007-06-17 19:56:38 -05002755 "%d (%d):0217 Unknown "
2756 "Identifier in RSCN payload "
2757 "Data: x%x\n",
2758 phba->brd_no, vport->vpi,
2759 rscn_did.un.word);
2760 case 3: /* Whole Fabric effected */
2761 return did;
dea31012005-04-17 16:05:31 -05002762 }
2763 }
James Smart92d7f7b2007-06-17 19:56:38 -05002764 }
2765 return 0;
dea31012005-04-17 16:05:31 -05002766}
2767
2768static int
James Smart2e0fef82007-06-17 19:56:36 -05002769lpfc_rscn_recovery_check(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002770{
James Smart685f0bf2007-04-25 09:53:08 -04002771 struct lpfc_nodelist *ndlp = NULL;
dea31012005-04-17 16:05:31 -05002772
2773 /* Look at all nodes effected by pending RSCNs and move
James Smart685f0bf2007-04-25 09:53:08 -04002774 * them to NPR state.
dea31012005-04-17 16:05:31 -05002775 */
James Smart685f0bf2007-04-25 09:53:08 -04002776
James Smart2e0fef82007-06-17 19:56:36 -05002777 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smart685f0bf2007-04-25 09:53:08 -04002778 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE ||
James Smart2e0fef82007-06-17 19:56:36 -05002779 lpfc_rscn_payload_check(vport, ndlp->nlp_DID) == 0)
dea31012005-04-17 16:05:31 -05002780 continue;
2781
James Smart2e0fef82007-06-17 19:56:36 -05002782 lpfc_disc_state_machine(vport, ndlp, NULL,
James Smart92d7f7b2007-06-17 19:56:38 -05002783 NLP_EVT_DEVICE_RECOVERY);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002784
James Smart685f0bf2007-04-25 09:53:08 -04002785 /*
2786 * Make sure NLP_DELAY_TMO is NOT running after a device
2787 * recovery event.
2788 */
2789 if (ndlp->nlp_flag & NLP_DELAY_TMO)
James Smart2e0fef82007-06-17 19:56:36 -05002790 lpfc_cancel_retry_delay_tmo(vport, ndlp);
dea31012005-04-17 16:05:31 -05002791 }
James Smart685f0bf2007-04-25 09:53:08 -04002792
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002793 return 0;
dea31012005-04-17 16:05:31 -05002794}
2795
2796static int
James Smart2e0fef82007-06-17 19:56:36 -05002797lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
2798 struct lpfc_nodelist *ndlp, uint8_t newnode)
dea31012005-04-17 16:05:31 -05002799{
James Smart2e0fef82007-06-17 19:56:36 -05002800 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2801 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002802 struct lpfc_dmabuf *pcmd;
James Smart92d7f7b2007-06-17 19:56:38 -05002803 struct lpfc_vport *next_vport;
2804 uint32_t *lp, *datap;
dea31012005-04-17 16:05:31 -05002805 IOCB_t *icmd;
James Smart92d7f7b2007-06-17 19:56:38 -05002806 uint32_t payload_len, length, nportid, *cmd;
2807 int rscn_cnt = vport->fc_rscn_id_cnt;
2808 int rscn_id = 0, hba_id = 0;
James Smartd2873e42006-08-18 17:46:43 -04002809 int i;
dea31012005-04-17 16:05:31 -05002810
2811 icmd = &cmdiocb->iocb;
2812 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2813 lp = (uint32_t *) pcmd->virt;
2814
James Smart92d7f7b2007-06-17 19:56:38 -05002815 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
2816 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05002817
2818 /* RSCN received */
James Smarted957682007-06-17 19:56:37 -05002819 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smart92d7f7b2007-06-17 19:56:38 -05002820 "%d (%d):0214 RSCN received Data: x%x x%x x%x x%x\n",
2821 phba->brd_no, vport->vpi, vport->fc_flag, payload_len,
2822 *lp, rscn_cnt);
dea31012005-04-17 16:05:31 -05002823
James Smartd2873e42006-08-18 17:46:43 -04002824 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
James Smart2e0fef82007-06-17 19:56:36 -05002825 fc_host_post_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04002826 FCH_EVT_RSCN, lp[i]);
2827
dea31012005-04-17 16:05:31 -05002828 /* If we are about to begin discovery, just ACC the RSCN.
2829 * Discovery processing will satisfy it.
2830 */
James Smart2e0fef82007-06-17 19:56:36 -05002831 if (vport->port_state <= LPFC_NS_QRY) {
James Smart858c9f62007-06-17 19:56:39 -05002832 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
2833 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
2834 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
2835
James Smart2e0fef82007-06-17 19:56:36 -05002836 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL,
James Smart92d7f7b2007-06-17 19:56:38 -05002837 newnode);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002838 return 0;
dea31012005-04-17 16:05:31 -05002839 }
2840
James Smart92d7f7b2007-06-17 19:56:38 -05002841 /* If this RSCN just contains NPortIDs for other vports on this HBA,
2842 * just ACC and ignore it.
2843 */
2844 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2845 !(phba->cfg_peer_port_login)) {
2846 i = payload_len;
2847 datap = lp;
2848 while (i > 0) {
2849 nportid = *datap++;
2850 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
2851 i -= sizeof(uint32_t);
2852 rscn_id++;
2853 list_for_each_entry(next_vport, &phba->port_list,
2854 listentry) {
2855 if (nportid == next_vport->fc_myDID) {
2856 hba_id++;
2857 break;
2858 }
2859 }
2860 }
2861 if (rscn_id == hba_id) {
2862 /* ALL NPortIDs in RSCN are on HBA */
2863 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
2864 "%d (%d):0214 Ignore RSCN Data: x%x x%x x%x x%x\n",
2865 phba->brd_no, vport->vpi, vport->fc_flag, payload_len,
2866 *lp, rscn_cnt);
James Smart858c9f62007-06-17 19:56:39 -05002867
2868 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
2869 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
2870 ndlp->nlp_DID, vport->port_state,
2871 ndlp->nlp_flag);
2872
James Smart92d7f7b2007-06-17 19:56:38 -05002873 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
2874 ndlp, NULL, newnode);
2875 return 0;
2876 }
2877 }
2878
dea31012005-04-17 16:05:31 -05002879 /* If we are already processing an RSCN, save the received
2880 * RSCN payload buffer, cmdiocb->context2 to process later.
2881 */
James Smart2e0fef82007-06-17 19:56:36 -05002882 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
James Smart858c9f62007-06-17 19:56:39 -05002883 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
2884 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
2885 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
2886
James Smart92d7f7b2007-06-17 19:56:38 -05002887 vport->fc_flag |= FC_RSCN_DEFERRED;
2888 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
James Smart2e0fef82007-06-17 19:56:36 -05002889 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
2890 spin_lock_irq(shost->host_lock);
2891 vport->fc_flag |= FC_RSCN_MODE;
2892 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05002893 if (rscn_cnt) {
2894 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
2895 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
2896 }
2897 if ((rscn_cnt) &&
2898 (payload_len + length <= LPFC_BPL_SIZE)) {
2899 *cmd &= ELS_CMD_MASK;
2900 *cmd |= be32_to_cpu(payload_len + length);
2901 memcpy(((uint8_t *)cmd) + length, lp,
2902 payload_len);
2903 } else {
2904 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
2905 vport->fc_rscn_id_cnt++;
2906 /* If we zero, cmdiocb->context2, the calling
2907 * routine will not try to free it.
2908 */
2909 cmdiocb->context2 = NULL;
2910 }
dea31012005-04-17 16:05:31 -05002911
2912 /* Deferred RSCN */
2913 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smart92d7f7b2007-06-17 19:56:38 -05002914 "%d (%d):0235 Deferred RSCN "
dea31012005-04-17 16:05:31 -05002915 "Data: x%x x%x x%x\n",
James Smart92d7f7b2007-06-17 19:56:38 -05002916 phba->brd_no, vport->vpi,
2917 vport->fc_rscn_id_cnt, vport->fc_flag,
James Smart2e0fef82007-06-17 19:56:36 -05002918 vport->port_state);
dea31012005-04-17 16:05:31 -05002919 } else {
James Smart2e0fef82007-06-17 19:56:36 -05002920 spin_lock_irq(shost->host_lock);
2921 vport->fc_flag |= FC_RSCN_DISCOVERY;
2922 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002923 /* ReDiscovery RSCN */
2924 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smart92d7f7b2007-06-17 19:56:38 -05002925 "%d (%d):0234 ReDiscovery RSCN "
dea31012005-04-17 16:05:31 -05002926 "Data: x%x x%x x%x\n",
James Smart92d7f7b2007-06-17 19:56:38 -05002927 phba->brd_no, vport->vpi,
2928 vport->fc_rscn_id_cnt, vport->fc_flag,
James Smart2e0fef82007-06-17 19:56:36 -05002929 vport->port_state);
dea31012005-04-17 16:05:31 -05002930 }
2931 /* Send back ACC */
James Smart2e0fef82007-06-17 19:56:36 -05002932 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL,
dea31012005-04-17 16:05:31 -05002933 newnode);
2934
2935 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05002936 lpfc_rscn_recovery_check(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05002937 vport->fc_flag &= ~FC_RSCN_DEFERRED;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002938 return 0;
dea31012005-04-17 16:05:31 -05002939 }
2940
James Smart858c9f62007-06-17 19:56:39 -05002941 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
2942 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
2943 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
2944
James Smart2e0fef82007-06-17 19:56:36 -05002945 spin_lock_irq(shost->host_lock);
2946 vport->fc_flag |= FC_RSCN_MODE;
2947 spin_unlock_irq(shost->host_lock);
2948 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
dea31012005-04-17 16:05:31 -05002949 /*
2950 * If we zero, cmdiocb->context2, the calling routine will
2951 * not try to free it.
2952 */
2953 cmdiocb->context2 = NULL;
2954
James Smart2e0fef82007-06-17 19:56:36 -05002955 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05002956
2957 /* Send back ACC */
James Smart2e0fef82007-06-17 19:56:36 -05002958 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL, newnode);
dea31012005-04-17 16:05:31 -05002959
2960 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05002961 lpfc_rscn_recovery_check(vport);
dea31012005-04-17 16:05:31 -05002962
James Smart2e0fef82007-06-17 19:56:36 -05002963 return lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05002964}
2965
2966int
James Smart2e0fef82007-06-17 19:56:36 -05002967lpfc_els_handle_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002968{
2969 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05002970 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002971
James Smart92d7f7b2007-06-17 19:56:38 -05002972 /* Ignore RSCN if the port is being torn down. */
2973 if (vport->load_flag & FC_UNLOADING) {
2974 lpfc_els_flush_rscn(vport);
2975 return 0;
2976 }
2977
dea31012005-04-17 16:05:31 -05002978 /* Start timer for RSCN processing */
James Smart2e0fef82007-06-17 19:56:36 -05002979 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05002980
2981 /* RSCN processed */
James Smarted957682007-06-17 19:56:37 -05002982 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smart92d7f7b2007-06-17 19:56:38 -05002983 "%d (%d):0215 RSCN processed Data: x%x x%x x%x x%x\n",
2984 phba->brd_no, vport->vpi,
James Smart2e0fef82007-06-17 19:56:36 -05002985 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
2986 vport->port_state);
dea31012005-04-17 16:05:31 -05002987
2988 /* To process RSCN, first compare RSCN data with NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05002989 vport->fc_ns_retry = 0;
2990 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smart685f0bf2007-04-25 09:53:08 -04002991 if (ndlp && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
dea31012005-04-17 16:05:31 -05002992 /* Good ndlp, issue CT Request to NameServer */
James Smart92d7f7b2007-06-17 19:56:38 -05002993 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
dea31012005-04-17 16:05:31 -05002994 /* Wait for NameServer query cmpl before we can
2995 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002996 return 1;
dea31012005-04-17 16:05:31 -05002997 } else {
2998 /* If login to NameServer does not exist, issue one */
2999 /* Good status, issue PLOGI to NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05003000 ndlp = lpfc_findnode_did(vport, NameServer_DID);
3001 if (ndlp)
dea31012005-04-17 16:05:31 -05003002 /* Wait for NameServer login cmpl before we can
3003 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003004 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05003005
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003006 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
3007 if (!ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05003008 lpfc_els_flush_rscn(vport);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003009 return 0;
dea31012005-04-17 16:05:31 -05003010 } else {
James Smart2e0fef82007-06-17 19:56:36 -05003011 lpfc_nlp_init(vport, ndlp, NameServer_DID);
dea31012005-04-17 16:05:31 -05003012 ndlp->nlp_type |= NLP_FABRIC;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003013 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003014 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
3015 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
dea31012005-04-17 16:05:31 -05003016 /* Wait for NameServer login cmpl before we can
3017 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003018 return 1;
dea31012005-04-17 16:05:31 -05003019 }
3020 }
3021
James Smart2e0fef82007-06-17 19:56:36 -05003022 lpfc_els_flush_rscn(vport);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003023 return 0;
dea31012005-04-17 16:05:31 -05003024}
3025
3026static int
James Smart2e0fef82007-06-17 19:56:36 -05003027lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3028 struct lpfc_nodelist *ndlp, uint8_t newnode)
dea31012005-04-17 16:05:31 -05003029{
James Smart2e0fef82007-06-17 19:56:36 -05003030 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3031 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003032 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3033 uint32_t *lp = (uint32_t *) pcmd->virt;
3034 IOCB_t *icmd = &cmdiocb->iocb;
3035 struct serv_parm *sp;
3036 LPFC_MBOXQ_t *mbox;
3037 struct ls_rjt stat;
3038 uint32_t cmd, did;
3039 int rc;
3040
3041 cmd = *lp++;
3042 sp = (struct serv_parm *) lp;
3043
3044 /* FLOGI received */
3045
James Smart2e0fef82007-06-17 19:56:36 -05003046 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05003047
3048 if (phba->fc_topology == TOPOLOGY_LOOP) {
3049 /* We should never receive a FLOGI in loop mode, ignore it */
3050 did = icmd->un.elsreq64.remoteID;
3051
3052 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
3053 Loop Mode */
3054 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
James Smart92d7f7b2007-06-17 19:56:38 -05003055 "%d (%d):0113 An FLOGI ELS command x%x was "
3056 "received from DID x%x in Loop Mode\n",
3057 phba->brd_no, vport->vpi, cmd, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003058 return 1;
dea31012005-04-17 16:05:31 -05003059 }
3060
3061 did = Fabric_DID;
3062
James Smart2e0fef82007-06-17 19:56:36 -05003063 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3))) {
dea31012005-04-17 16:05:31 -05003064 /* For a FLOGI we accept, then if our portname is greater
3065 * then the remote portname we initiate Nport login.
3066 */
3067
James Smart2e0fef82007-06-17 19:56:36 -05003068 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -05003069 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003070
3071 if (!rc) {
James Smart2e0fef82007-06-17 19:56:36 -05003072 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3073 if (!mbox)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003074 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05003075
dea31012005-04-17 16:05:31 -05003076 lpfc_linkdown(phba);
3077 lpfc_init_link(phba, mbox,
3078 phba->cfg_topology,
3079 phba->cfg_link_speed);
3080 mbox->mb.un.varInitLnk.lipsr_AL_PA = 0;
3081 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -05003082 mbox->vport = vport;
dea31012005-04-17 16:05:31 -05003083 rc = lpfc_sli_issue_mbox
3084 (phba, mbox, (MBX_NOWAIT | MBX_STOP_IOCB));
James Smart5b8bd0c2007-04-25 09:52:49 -04003085 lpfc_set_loopback_flag(phba);
dea31012005-04-17 16:05:31 -05003086 if (rc == MBX_NOT_FINISHED) {
James Smart329f9bc2007-04-25 09:53:01 -04003087 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003088 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003089 return 1;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003090 } else if (rc > 0) { /* greater than */
James Smart2e0fef82007-06-17 19:56:36 -05003091 spin_lock_irq(shost->host_lock);
3092 vport->fc_flag |= FC_PT2PT_PLOGI;
3093 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003094 }
James Smart2e0fef82007-06-17 19:56:36 -05003095 spin_lock_irq(shost->host_lock);
3096 vport->fc_flag |= FC_PT2PT;
3097 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
3098 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003099 } else {
3100 /* Reject this request because invalid parameters */
3101 stat.un.b.lsRjtRsvd0 = 0;
3102 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3103 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
3104 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05003105 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
3106 NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003107 return 1;
dea31012005-04-17 16:05:31 -05003108 }
3109
3110 /* Send back ACC */
James Smart2e0fef82007-06-17 19:56:36 -05003111 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL, newnode);
dea31012005-04-17 16:05:31 -05003112
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003113 return 0;
dea31012005-04-17 16:05:31 -05003114}
3115
3116static int
James Smart2e0fef82007-06-17 19:56:36 -05003117lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3118 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003119{
3120 struct lpfc_dmabuf *pcmd;
3121 uint32_t *lp;
3122 IOCB_t *icmd;
3123 RNID *rn;
3124 struct ls_rjt stat;
3125 uint32_t cmd, did;
3126
3127 icmd = &cmdiocb->iocb;
3128 did = icmd->un.elsreq64.remoteID;
3129 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3130 lp = (uint32_t *) pcmd->virt;
3131
3132 cmd = *lp++;
3133 rn = (RNID *) lp;
3134
3135 /* RNID received */
3136
3137 switch (rn->Format) {
3138 case 0:
3139 case RNID_TOPOLOGY_DISC:
3140 /* Send back ACC */
James Smart2e0fef82007-06-17 19:56:36 -05003141 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05003142 break;
3143 default:
3144 /* Reject this request because format not supported */
3145 stat.un.b.lsRjtRsvd0 = 0;
3146 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3147 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
3148 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05003149 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
3150 NULL);
dea31012005-04-17 16:05:31 -05003151 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003152 return 0;
dea31012005-04-17 16:05:31 -05003153}
3154
3155static int
James Smart2e0fef82007-06-17 19:56:36 -05003156lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3157 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003158{
3159 struct ls_rjt stat;
3160
3161 /* For now, unconditionally reject this command */
3162 stat.un.b.lsRjtRsvd0 = 0;
3163 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3164 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
3165 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05003166 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003167 return 0;
3168}
3169
Jamie Wellnitz082c0262006-02-28 19:25:30 -05003170static void
James Smart329f9bc2007-04-25 09:53:01 -04003171lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003172{
James Smart2e0fef82007-06-17 19:56:36 -05003173 struct lpfc_sli *psli = &phba->sli;
3174 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003175 MAILBOX_t *mb;
3176 IOCB_t *icmd;
3177 RPS_RSP *rps_rsp;
3178 uint8_t *pcmd;
3179 struct lpfc_iocbq *elsiocb;
3180 struct lpfc_nodelist *ndlp;
3181 uint16_t xri, status;
3182 uint32_t cmdsize;
3183
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003184 mb = &pmb->mb;
3185
3186 ndlp = (struct lpfc_nodelist *) pmb->context2;
3187 xri = (uint16_t) ((unsigned long)(pmb->context1));
Randy Dunlap041976f2006-06-25 01:58:51 -07003188 pmb->context1 = NULL;
3189 pmb->context2 = NULL;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003190
3191 if (mb->mbxStatus) {
James Smart329f9bc2007-04-25 09:53:01 -04003192 mempool_free(pmb, phba->mbox_mem_pool);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003193 return;
3194 }
3195
3196 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
James Smart329f9bc2007-04-25 09:53:01 -04003197 mempool_free(pmb, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05003198 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
3199 lpfc_max_els_tries, ndlp,
3200 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart329f9bc2007-04-25 09:53:01 -04003201 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003202 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003203 return;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003204
3205 icmd = &elsiocb->iocb;
3206 icmd->ulpContext = xri;
3207
3208 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3209 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003210 pcmd += sizeof(uint32_t); /* Skip past command */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003211 rps_rsp = (RPS_RSP *)pcmd;
3212
3213 if (phba->fc_topology != TOPOLOGY_LOOP)
3214 status = 0x10;
3215 else
3216 status = 0x8;
James Smart2e0fef82007-06-17 19:56:36 -05003217 if (phba->pport->fc_flag & FC_FABRIC)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003218 status |= 0x4;
3219
3220 rps_rsp->rsvd1 = 0;
3221 rps_rsp->portStatus = be16_to_cpu(status);
3222 rps_rsp->linkFailureCnt = be32_to_cpu(mb->un.varRdLnk.linkFailureCnt);
3223 rps_rsp->lossSyncCnt = be32_to_cpu(mb->un.varRdLnk.lossSyncCnt);
3224 rps_rsp->lossSignalCnt = be32_to_cpu(mb->un.varRdLnk.lossSignalCnt);
3225 rps_rsp->primSeqErrCnt = be32_to_cpu(mb->un.varRdLnk.primSeqErrCnt);
3226 rps_rsp->invalidXmitWord = be32_to_cpu(mb->un.varRdLnk.invalidXmitWord);
3227 rps_rsp->crcCnt = be32_to_cpu(mb->un.varRdLnk.crcCnt);
3228
3229 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
3230 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
James Smart92d7f7b2007-06-17 19:56:38 -05003231 "%d (%d):0118 Xmit ELS RPS ACC response tag x%x "
3232 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
3233 "rpi x%x\n",
3234 phba->brd_no, ndlp->vport->vpi, elsiocb->iotag,
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003235 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
3236 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
3237
James Smart858c9f62007-06-17 19:56:39 -05003238 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003239 phba->fc_stat.elsXmitACC++;
James Smarted957682007-06-17 19:56:37 -05003240 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003241 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003242 return;
3243}
3244
3245static int
James Smart2e0fef82007-06-17 19:56:36 -05003246lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3247 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003248{
James Smart2e0fef82007-06-17 19:56:36 -05003249 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003250 uint32_t *lp;
3251 uint8_t flag;
3252 LPFC_MBOXQ_t *mbox;
3253 struct lpfc_dmabuf *pcmd;
3254 RPS *rps;
3255 struct ls_rjt stat;
3256
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003257 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
3258 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003259 stat.un.b.lsRjtRsvd0 = 0;
3260 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3261 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
3262 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05003263 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
3264 NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003265 }
3266
3267 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3268 lp = (uint32_t *) pcmd->virt;
3269 flag = (be32_to_cpu(*lp++) & 0xf);
3270 rps = (RPS *) lp;
3271
3272 if ((flag == 0) ||
3273 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
James Smart2e0fef82007-06-17 19:56:36 -05003274 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05003275 sizeof(struct lpfc_name)) == 0))) {
James Smart2e0fef82007-06-17 19:56:36 -05003276
James Smart92d7f7b2007-06-17 19:56:38 -05003277 printk("Fix me....\n");
3278 dump_stack();
James Smart2e0fef82007-06-17 19:56:36 -05003279 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
3280 if (mbox) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003281 lpfc_read_lnk_stat(phba, mbox);
3282 mbox->context1 =
James Smart92d7f7b2007-06-17 19:56:38 -05003283 (void *)((unsigned long) cmdiocb->iocb.ulpContext);
James Smart329f9bc2007-04-25 09:53:01 -04003284 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05003285 mbox->vport = vport;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003286 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
3287 if (lpfc_sli_issue_mbox (phba, mbox,
James Smart2e0fef82007-06-17 19:56:36 -05003288 (MBX_NOWAIT | MBX_STOP_IOCB)) != MBX_NOT_FINISHED)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003289 /* Mbox completion will send ELS Response */
3290 return 0;
James Smart2e0fef82007-06-17 19:56:36 -05003291
James Smart329f9bc2007-04-25 09:53:01 -04003292 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003293 mempool_free(mbox, phba->mbox_mem_pool);
3294 }
3295 }
3296 stat.un.b.lsRjtRsvd0 = 0;
3297 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3298 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
3299 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05003300 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003301 return 0;
3302}
3303
Jamie Wellnitz082c0262006-02-28 19:25:30 -05003304static int
James Smart2e0fef82007-06-17 19:56:36 -05003305lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
3306 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003307{
James Smart2e0fef82007-06-17 19:56:36 -05003308 struct lpfc_hba *phba = vport->phba;
3309 IOCB_t *icmd, *oldcmd;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003310 RPL_RSP rpl_rsp;
3311 struct lpfc_iocbq *elsiocb;
James Smart2e0fef82007-06-17 19:56:36 -05003312 struct lpfc_sli *psli = &phba->sli;
3313 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003314 uint8_t *pcmd;
3315
James Smart2e0fef82007-06-17 19:56:36 -05003316 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3317 ndlp->nlp_DID, ELS_CMD_ACC);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003318
James Smart488d1462006-03-07 15:02:37 -05003319 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003320 return 1;
James Smart488d1462006-03-07 15:02:37 -05003321
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003322 icmd = &elsiocb->iocb;
3323 oldcmd = &oldiocb->iocb;
3324 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3325
3326 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3327 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003328 pcmd += sizeof(uint16_t);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003329 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
3330 pcmd += sizeof(uint16_t);
3331
3332 /* Setup the RPL ACC payload */
3333 rpl_rsp.listLen = be32_to_cpu(1);
3334 rpl_rsp.index = 0;
3335 rpl_rsp.port_num_blk.portNum = 0;
James Smart2e0fef82007-06-17 19:56:36 -05003336 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
3337 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003338 sizeof(struct lpfc_name));
3339
3340 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
3341
3342
3343 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
3344 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
James Smart92d7f7b2007-06-17 19:56:38 -05003345 "%d (%d):0120 Xmit ELS RPL ACC response tag x%x "
3346 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
3347 "rpi x%x\n",
3348 phba->brd_no, vport->vpi, elsiocb->iotag,
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003349 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
3350 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
3351
James Smart858c9f62007-06-17 19:56:39 -05003352 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003353
3354 phba->fc_stat.elsXmitACC++;
3355 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
3356 lpfc_els_free_iocb(phba, elsiocb);
3357 return 1;
3358 }
3359 return 0;
3360}
3361
3362static int
James Smart2e0fef82007-06-17 19:56:36 -05003363lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3364 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003365{
3366 struct lpfc_dmabuf *pcmd;
3367 uint32_t *lp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003368 uint32_t maxsize;
3369 uint16_t cmdsize;
3370 RPL *rpl;
3371 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05003372
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003373 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
3374 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003375 stat.un.b.lsRjtRsvd0 = 0;
3376 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3377 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
3378 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05003379 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
3380 NULL);
dea31012005-04-17 16:05:31 -05003381 }
3382
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003383 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3384 lp = (uint32_t *) pcmd->virt;
3385 rpl = (RPL *) (lp + 1);
3386
3387 maxsize = be32_to_cpu(rpl->maxsize);
3388
3389 /* We support only one port */
3390 if ((rpl->index == 0) &&
3391 ((maxsize == 0) ||
3392 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
3393 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003394 } else {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003395 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
3396 }
James Smart2e0fef82007-06-17 19:56:36 -05003397 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05003398
3399 return 0;
3400}
3401
3402static int
James Smart2e0fef82007-06-17 19:56:36 -05003403lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3404 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003405{
James Smart2e0fef82007-06-17 19:56:36 -05003406 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003407 struct lpfc_dmabuf *pcmd;
3408 uint32_t *lp;
3409 IOCB_t *icmd;
3410 FARP *fp;
3411 uint32_t cmd, cnt, did;
3412
3413 icmd = &cmdiocb->iocb;
3414 did = icmd->un.elsreq64.remoteID;
3415 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3416 lp = (uint32_t *) pcmd->virt;
3417
3418 cmd = *lp++;
3419 fp = (FARP *) lp;
3420
3421 /* FARP-REQ received from DID <did> */
James Smarted957682007-06-17 19:56:37 -05003422 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
James Smart92d7f7b2007-06-17 19:56:38 -05003423 "%d (%d):0601 FARP-REQ received from DID x%x\n",
3424 phba->brd_no, vport->vpi, did);
dea31012005-04-17 16:05:31 -05003425
3426 /* We will only support match on WWPN or WWNN */
3427 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003428 return 0;
dea31012005-04-17 16:05:31 -05003429 }
3430
3431 cnt = 0;
3432 /* If this FARP command is searching for my portname */
3433 if (fp->Mflags & FARP_MATCH_PORT) {
James Smart2e0fef82007-06-17 19:56:36 -05003434 if (memcmp(&fp->RportName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05003435 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05003436 cnt = 1;
3437 }
3438
3439 /* If this FARP command is searching for my nodename */
3440 if (fp->Mflags & FARP_MATCH_NODE) {
James Smart2e0fef82007-06-17 19:56:36 -05003441 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05003442 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05003443 cnt = 1;
3444 }
3445
3446 if (cnt) {
3447 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
3448 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
3449 /* Log back into the node before sending the FARP. */
3450 if (fp->Rflags & FARP_REQUEST_PLOGI) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003451 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003452 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04003453 NLP_STE_PLOGI_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05003454 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05003455 }
3456
3457 /* Send a FARP response to that node */
James Smart2e0fef82007-06-17 19:56:36 -05003458 if (fp->Rflags & FARP_REQUEST_FARPR)
3459 lpfc_issue_els_farpr(vport, did, 0);
dea31012005-04-17 16:05:31 -05003460 }
3461 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003462 return 0;
dea31012005-04-17 16:05:31 -05003463}
3464
3465static int
James Smart2e0fef82007-06-17 19:56:36 -05003466lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3467 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003468{
3469 struct lpfc_dmabuf *pcmd;
3470 uint32_t *lp;
3471 IOCB_t *icmd;
3472 uint32_t cmd, did;
James Smart2e0fef82007-06-17 19:56:36 -05003473 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003474
3475 icmd = &cmdiocb->iocb;
3476 did = icmd->un.elsreq64.remoteID;
3477 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3478 lp = (uint32_t *) pcmd->virt;
3479
3480 cmd = *lp++;
3481 /* FARP-RSP received from DID <did> */
James Smarted957682007-06-17 19:56:37 -05003482 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
James Smart92d7f7b2007-06-17 19:56:38 -05003483 "%d (%d):0600 FARP-RSP received from DID x%x\n",
3484 phba->brd_no, vport->vpi, did);
dea31012005-04-17 16:05:31 -05003485 /* ACCEPT the Farp resp request */
James Smart2e0fef82007-06-17 19:56:36 -05003486 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
dea31012005-04-17 16:05:31 -05003487
3488 return 0;
3489}
3490
3491static int
James Smart2e0fef82007-06-17 19:56:36 -05003492lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3493 struct lpfc_nodelist *fan_ndlp)
dea31012005-04-17 16:05:31 -05003494{
3495 struct lpfc_dmabuf *pcmd;
3496 uint32_t *lp;
3497 IOCB_t *icmd;
dea31012005-04-17 16:05:31 -05003498 uint32_t cmd, did;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003499 FAN *fp;
3500 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05003501 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003502
3503 /* FAN received */
James Smarted957682007-06-17 19:56:37 -05003504 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
James Smart92d7f7b2007-06-17 19:56:38 -05003505 "%d (%d):0265 FAN received\n",
3506 phba->brd_no, vport->vpi);
dea31012005-04-17 16:05:31 -05003507
3508 icmd = &cmdiocb->iocb;
3509 did = icmd->un.elsreq64.remoteID;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003510 pcmd = (struct lpfc_dmabuf *)cmdiocb->context2;
3511 lp = (uint32_t *)pcmd->virt;
dea31012005-04-17 16:05:31 -05003512
3513 cmd = *lp++;
James Smart92d7f7b2007-06-17 19:56:38 -05003514 fp = (FAN *) lp;
dea31012005-04-17 16:05:31 -05003515
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003516 /* FAN received; Fan does not have a reply sequence */
dea31012005-04-17 16:05:31 -05003517
James Smart2e0fef82007-06-17 19:56:36 -05003518 if (phba->pport->port_state == LPFC_LOCAL_CFG_LINK) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003519 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
3520 sizeof(struct lpfc_name)) != 0) ||
3521 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
3522 sizeof(struct lpfc_name)) != 0)) {
3523 /*
3524 * This node has switched fabrics. FLOGI is required
3525 * Clean up the old rpi's
dea31012005-04-17 16:05:31 -05003526 */
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003527
3528 list_for_each_entry_safe(ndlp, next_ndlp,
James Smart2e0fef82007-06-17 19:56:36 -05003529 &vport->fc_nodes, nlp_listp) {
James Smart685f0bf2007-04-25 09:53:08 -04003530 if (ndlp->nlp_state != NLP_STE_NPR_NODE)
3531 continue;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003532 if (ndlp->nlp_type & NLP_FABRIC) {
3533 /*
3534 * Clean up old Fabric, Nameserver and
3535 * other NLP_FABRIC logins
3536 */
James Smart2e0fef82007-06-17 19:56:36 -05003537 lpfc_drop_node(vport, ndlp);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003538 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003539 /* Fail outstanding I/O now since this
3540 * device is marked for PLOGI
3541 */
James Smart2e0fef82007-06-17 19:56:36 -05003542 lpfc_unreg_rpi(vport, ndlp);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003543 }
3544 }
3545
James Smart2e0fef82007-06-17 19:56:36 -05003546 vport->port_state = LPFC_FLOGI;
3547 lpfc_set_disctmo(vport);
3548 lpfc_initial_flogi(vport);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003549 return 0;
dea31012005-04-17 16:05:31 -05003550 }
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003551 /* Discovery not needed,
3552 * move the nodes to their original state.
3553 */
James Smart2e0fef82007-06-17 19:56:36 -05003554 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
James Smart685f0bf2007-04-25 09:53:08 -04003555 nlp_listp) {
3556 if (ndlp->nlp_state != NLP_STE_NPR_NODE)
3557 continue;
dea31012005-04-17 16:05:31 -05003558
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003559 switch (ndlp->nlp_prev_state) {
3560 case NLP_STE_UNMAPPED_NODE:
3561 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05003562 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04003563 NLP_STE_UNMAPPED_NODE);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003564 break;
3565
3566 case NLP_STE_MAPPED_NODE:
3567 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05003568 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04003569 NLP_STE_MAPPED_NODE);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003570 break;
3571
3572 default:
3573 break;
3574 }
3575 }
3576
3577 /* Start discovery - this should just do CLEAR_LA */
James Smart2e0fef82007-06-17 19:56:36 -05003578 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -05003579 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003580 return 0;
dea31012005-04-17 16:05:31 -05003581}
3582
3583void
3584lpfc_els_timeout(unsigned long ptr)
3585{
James Smart2e0fef82007-06-17 19:56:36 -05003586 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
3587 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003588 unsigned long iflag;
3589
James Smart2e0fef82007-06-17 19:56:36 -05003590 spin_lock_irqsave(&vport->work_port_lock, iflag);
3591 if ((vport->work_port_events & WORKER_ELS_TMO) == 0) {
3592 vport->work_port_events |= WORKER_ELS_TMO;
James Smart92d7f7b2007-06-17 19:56:38 -05003593 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
3594
3595 spin_lock_irqsave(&phba->hbalock, iflag);
dea31012005-04-17 16:05:31 -05003596 if (phba->work_wait)
James Smart92d7f7b2007-06-17 19:56:38 -05003597 lpfc_worker_wake_up(phba);
3598 spin_unlock_irqrestore(&phba->hbalock, iflag);
dea31012005-04-17 16:05:31 -05003599 }
James Smart92d7f7b2007-06-17 19:56:38 -05003600 else
3601 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
dea31012005-04-17 16:05:31 -05003602 return;
3603}
3604
3605void
James Smart2e0fef82007-06-17 19:56:36 -05003606lpfc_els_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003607{
James Smart2e0fef82007-06-17 19:56:36 -05003608 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003609 struct lpfc_sli_ring *pring;
3610 struct lpfc_iocbq *tmp_iocb, *piocb;
3611 IOCB_t *cmd = NULL;
3612 struct lpfc_dmabuf *pcmd;
James Smart2e0fef82007-06-17 19:56:36 -05003613 uint32_t els_command = 0;
dea31012005-04-17 16:05:31 -05003614 uint32_t timeout;
James Smart2e0fef82007-06-17 19:56:36 -05003615 uint32_t remote_ID = 0xffffffff;
dea31012005-04-17 16:05:31 -05003616
dea31012005-04-17 16:05:31 -05003617 /* If the timer is already canceled do nothing */
James Smart2e0fef82007-06-17 19:56:36 -05003618 if ((vport->work_port_events & WORKER_ELS_TMO) == 0) {
dea31012005-04-17 16:05:31 -05003619 return;
3620 }
James Smart2e0fef82007-06-17 19:56:36 -05003621 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003622 timeout = (uint32_t)(phba->fc_ratov << 1);
3623
3624 pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05003625
3626 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
3627 cmd = &piocb->iocb;
3628
James Smart2e0fef82007-06-17 19:56:36 -05003629 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
3630 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
3631 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
dea31012005-04-17 16:05:31 -05003632 continue;
James Smart2e0fef82007-06-17 19:56:36 -05003633
3634 if (piocb->vport != vport)
3635 continue;
3636
dea31012005-04-17 16:05:31 -05003637 pcmd = (struct lpfc_dmabuf *) piocb->context2;
James Smart2e0fef82007-06-17 19:56:36 -05003638 if (pcmd)
3639 els_command = *(uint32_t *) (pcmd->virt);
dea31012005-04-17 16:05:31 -05003640
James Smart92d7f7b2007-06-17 19:56:38 -05003641 if (els_command == ELS_CMD_FARP ||
3642 els_command == ELS_CMD_FARPR ||
3643 els_command == ELS_CMD_FDISC)
dea31012005-04-17 16:05:31 -05003644 continue;
James Smart92d7f7b2007-06-17 19:56:38 -05003645
3646 if (vport != piocb->vport)
3647 continue;
dea31012005-04-17 16:05:31 -05003648
3649 if (piocb->drvrTimeout > 0) {
James Smart92d7f7b2007-06-17 19:56:38 -05003650 if (piocb->drvrTimeout >= timeout)
dea31012005-04-17 16:05:31 -05003651 piocb->drvrTimeout -= timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05003652 else
dea31012005-04-17 16:05:31 -05003653 piocb->drvrTimeout = 0;
dea31012005-04-17 16:05:31 -05003654 continue;
3655 }
3656
James Smart2e0fef82007-06-17 19:56:36 -05003657 remote_ID = 0xffffffff;
3658 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
dea31012005-04-17 16:05:31 -05003659 remote_ID = cmd->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05003660 else {
3661 struct lpfc_nodelist *ndlp;
3662 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
3663 if (ndlp)
3664 remote_ID = ndlp->nlp_DID;
dea31012005-04-17 16:05:31 -05003665 }
3666
James Smart92d7f7b2007-06-17 19:56:38 -05003667 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
3668 "%d (%d):0127 ELS timeout Data: x%x x%x x%x "
3669 "x%x\n",
3670 phba->brd_no, vport->vpi, els_command,
dea31012005-04-17 16:05:31 -05003671 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
3672
James Smart07951072007-04-25 09:51:38 -04003673 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05003674 }
James Smart2e0fef82007-06-17 19:56:36 -05003675 spin_unlock_irq(&phba->hbalock);
James Smart5a0e3262006-07-06 15:49:16 -04003676
James Smart2e0fef82007-06-17 19:56:36 -05003677 if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt)
3678 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
dea31012005-04-17 16:05:31 -05003679}
3680
3681void
James Smart2e0fef82007-06-17 19:56:36 -05003682lpfc_els_flush_cmd(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003683{
James Smart2534ba72007-04-25 09:52:20 -04003684 LIST_HEAD(completions);
James Smart2e0fef82007-06-17 19:56:36 -05003685 struct lpfc_hba *phba = vport->phba;
James Smart329f9bc2007-04-25 09:53:01 -04003686 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05003687 struct lpfc_iocbq *tmp_iocb, *piocb;
3688 IOCB_t *cmd = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05003689
3690 lpfc_fabric_abort_vport(vport);
dea31012005-04-17 16:05:31 -05003691
James Smart2e0fef82007-06-17 19:56:36 -05003692 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003693 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
3694 cmd = &piocb->iocb;
3695
3696 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
3697 continue;
3698 }
3699
3700 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
James Smart329f9bc2007-04-25 09:53:01 -04003701 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
3702 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
3703 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
3704 cmd->ulpCommand == CMD_ABORT_XRI_CN)
dea31012005-04-17 16:05:31 -05003705 continue;
dea31012005-04-17 16:05:31 -05003706
James Smart2e0fef82007-06-17 19:56:36 -05003707 if (piocb->vport != vport)
3708 continue;
3709
James Smart2534ba72007-04-25 09:52:20 -04003710 list_move_tail(&piocb->list, &completions);
James Smart1dcb58e2007-04-25 09:51:30 -04003711 pring->txq_cnt--;
dea31012005-04-17 16:05:31 -05003712 }
3713
3714 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
dea31012005-04-17 16:05:31 -05003715 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
3716 continue;
3717 }
dea31012005-04-17 16:05:31 -05003718
James Smart2e0fef82007-06-17 19:56:36 -05003719 if (piocb->vport != vport)
3720 continue;
3721
James Smart07951072007-04-25 09:51:38 -04003722 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05003723 }
James Smart2e0fef82007-06-17 19:56:36 -05003724 spin_unlock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04003725
James Smart2e0fef82007-06-17 19:56:36 -05003726 while (!list_empty(&completions)) {
James Smart2534ba72007-04-25 09:52:20 -04003727 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
3728 cmd = &piocb->iocb;
James Smart92d7f7b2007-06-17 19:56:38 -05003729 list_del_init(&piocb->list);
James Smart2534ba72007-04-25 09:52:20 -04003730
James Smart2e0fef82007-06-17 19:56:36 -05003731 if (!piocb->iocb_cmpl)
3732 lpfc_sli_release_iocbq(phba, piocb);
3733 else {
James Smart2534ba72007-04-25 09:52:20 -04003734 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
3735 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
3736 (piocb->iocb_cmpl) (phba, piocb, piocb);
James Smart2e0fef82007-06-17 19:56:36 -05003737 }
James Smart2534ba72007-04-25 09:52:20 -04003738 }
3739
dea31012005-04-17 16:05:31 -05003740 return;
3741}
3742
James Smarted957682007-06-17 19:56:37 -05003743static void
3744lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
James Smart92d7f7b2007-06-17 19:56:38 -05003745 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05003746{
dea31012005-04-17 16:05:31 -05003747 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05003748 struct ls_rjt stat;
James Smart92d7f7b2007-06-17 19:56:38 -05003749 uint32_t *payload;
James Smart2e0fef82007-06-17 19:56:36 -05003750 uint32_t cmd, did, newnode, rjt_err = 0;
James Smarted957682007-06-17 19:56:37 -05003751 IOCB_t *icmd = &elsiocb->iocb;
dea31012005-04-17 16:05:31 -05003752
James Smart92d7f7b2007-06-17 19:56:38 -05003753 if (vport == NULL || elsiocb->context2 == NULL)
dea31012005-04-17 16:05:31 -05003754 goto dropit;
James Smart2e0fef82007-06-17 19:56:36 -05003755
dea31012005-04-17 16:05:31 -05003756 newnode = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05003757 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
3758 cmd = *payload;
James Smarted957682007-06-17 19:56:37 -05003759 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
3760 lpfc_post_buffer(phba, pring, 1, 1);
dea31012005-04-17 16:05:31 -05003761
James Smart858c9f62007-06-17 19:56:39 -05003762 did = icmd->un.rcvels.remoteID;
3763 if (icmd->ulpStatus) {
3764 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3765 "RCV Unsol ELS: status:x%x/x%x did:x%x",
3766 icmd->ulpStatus, icmd->un.ulpWord[4], did);
dea31012005-04-17 16:05:31 -05003767 goto dropit;
James Smart858c9f62007-06-17 19:56:39 -05003768 }
dea31012005-04-17 16:05:31 -05003769
3770 /* Check to see if link went down during discovery */
James Smarted957682007-06-17 19:56:37 -05003771 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05003772 goto dropit;
dea31012005-04-17 16:05:31 -05003773
James Smart92d7f7b2007-06-17 19:56:38 -05003774 /* Ignore traffic recevied during vport shutdown. */
3775 if (vport->load_flag & FC_UNLOADING)
3776 goto dropit;
3777
James Smart2e0fef82007-06-17 19:56:36 -05003778 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003779 if (!ndlp) {
dea31012005-04-17 16:05:31 -05003780 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003781 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
James Smarted957682007-06-17 19:56:37 -05003782 if (!ndlp)
dea31012005-04-17 16:05:31 -05003783 goto dropit;
dea31012005-04-17 16:05:31 -05003784
James Smart2e0fef82007-06-17 19:56:36 -05003785 lpfc_nlp_init(vport, ndlp, did);
dea31012005-04-17 16:05:31 -05003786 newnode = 1;
3787 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) {
3788 ndlp->nlp_type |= NLP_FABRIC;
3789 }
James Smart2e0fef82007-06-17 19:56:36 -05003790 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE);
dea31012005-04-17 16:05:31 -05003791 }
3792
3793 phba->fc_stat.elsRcvFrame++;
James Smart329f9bc2007-04-25 09:53:01 -04003794 if (elsiocb->context1)
3795 lpfc_nlp_put(elsiocb->context1);
3796 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05003797 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -05003798
3799 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
3800 cmd &= ELS_CMD_MASK;
3801 }
3802 /* ELS command <elsCmd> received from NPORT <did> */
3803 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
James Smart92d7f7b2007-06-17 19:56:38 -05003804 "%d (%d):0112 ELS command x%x received from NPORT x%x "
3805 "Data: x%x\n", phba->brd_no, vport->vpi, cmd, did,
James Smarted957682007-06-17 19:56:37 -05003806 vport->port_state);
dea31012005-04-17 16:05:31 -05003807
3808 switch (cmd) {
3809 case ELS_CMD_PLOGI:
James Smart858c9f62007-06-17 19:56:39 -05003810 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3811 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
3812 did, vport->port_state, ndlp->nlp_flag);
3813
dea31012005-04-17 16:05:31 -05003814 phba->fc_stat.elsRcvPLOGI++;
James Smart858c9f62007-06-17 19:56:39 -05003815 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
3816
3817 if (vport->port_state < LPFC_DISC_AUTH) {
3818 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05003819 break;
3820 }
James Smart2e0fef82007-06-17 19:56:36 -05003821 lpfc_disc_state_machine(vport, ndlp, elsiocb,
3822 NLP_EVT_RCV_PLOGI);
James Smart858c9f62007-06-17 19:56:39 -05003823
dea31012005-04-17 16:05:31 -05003824 break;
3825 case ELS_CMD_FLOGI:
James Smart858c9f62007-06-17 19:56:39 -05003826 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3827 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
3828 did, vport->port_state, ndlp->nlp_flag);
3829
dea31012005-04-17 16:05:31 -05003830 phba->fc_stat.elsRcvFLOGI++;
James Smart2e0fef82007-06-17 19:56:36 -05003831 lpfc_els_rcv_flogi(vport, elsiocb, ndlp, newnode);
James Smartde0c5b32007-04-25 09:52:27 -04003832 if (newnode)
James Smart2e0fef82007-06-17 19:56:36 -05003833 lpfc_drop_node(vport, ndlp);
dea31012005-04-17 16:05:31 -05003834 break;
3835 case ELS_CMD_LOGO:
James Smart858c9f62007-06-17 19:56:39 -05003836 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3837 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
3838 did, vport->port_state, ndlp->nlp_flag);
3839
dea31012005-04-17 16:05:31 -05003840 phba->fc_stat.elsRcvLOGO++;
James Smart2e0fef82007-06-17 19:56:36 -05003841 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05003842 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05003843 break;
3844 }
James Smart2e0fef82007-06-17 19:56:36 -05003845 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
dea31012005-04-17 16:05:31 -05003846 break;
3847 case ELS_CMD_PRLO:
James Smart858c9f62007-06-17 19:56:39 -05003848 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3849 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
3850 did, vport->port_state, ndlp->nlp_flag);
3851
dea31012005-04-17 16:05:31 -05003852 phba->fc_stat.elsRcvPRLO++;
James Smart2e0fef82007-06-17 19:56:36 -05003853 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05003854 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05003855 break;
3856 }
James Smart2e0fef82007-06-17 19:56:36 -05003857 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
dea31012005-04-17 16:05:31 -05003858 break;
3859 case ELS_CMD_RSCN:
3860 phba->fc_stat.elsRcvRSCN++;
James Smart2e0fef82007-06-17 19:56:36 -05003861 lpfc_els_rcv_rscn(vport, elsiocb, ndlp, newnode);
James Smartde0c5b32007-04-25 09:52:27 -04003862 if (newnode)
James Smart2e0fef82007-06-17 19:56:36 -05003863 lpfc_drop_node(vport, ndlp);
dea31012005-04-17 16:05:31 -05003864 break;
3865 case ELS_CMD_ADISC:
James Smart858c9f62007-06-17 19:56:39 -05003866 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3867 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
3868 did, vport->port_state, ndlp->nlp_flag);
3869
dea31012005-04-17 16:05:31 -05003870 phba->fc_stat.elsRcvADISC++;
James Smart2e0fef82007-06-17 19:56:36 -05003871 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05003872 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05003873 break;
3874 }
James Smart2e0fef82007-06-17 19:56:36 -05003875 lpfc_disc_state_machine(vport, ndlp, elsiocb,
3876 NLP_EVT_RCV_ADISC);
dea31012005-04-17 16:05:31 -05003877 break;
3878 case ELS_CMD_PDISC:
James Smart858c9f62007-06-17 19:56:39 -05003879 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3880 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
3881 did, vport->port_state, ndlp->nlp_flag);
3882
dea31012005-04-17 16:05:31 -05003883 phba->fc_stat.elsRcvPDISC++;
James Smart2e0fef82007-06-17 19:56:36 -05003884 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05003885 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05003886 break;
3887 }
James Smart2e0fef82007-06-17 19:56:36 -05003888 lpfc_disc_state_machine(vport, ndlp, elsiocb,
3889 NLP_EVT_RCV_PDISC);
dea31012005-04-17 16:05:31 -05003890 break;
3891 case ELS_CMD_FARPR:
James Smart858c9f62007-06-17 19:56:39 -05003892 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3893 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
3894 did, vport->port_state, ndlp->nlp_flag);
3895
dea31012005-04-17 16:05:31 -05003896 phba->fc_stat.elsRcvFARPR++;
James Smart2e0fef82007-06-17 19:56:36 -05003897 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05003898 break;
3899 case ELS_CMD_FARP:
James Smart858c9f62007-06-17 19:56:39 -05003900 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3901 "RCV FARP: did:x%x/ste:x%x flg:x%x",
3902 did, vport->port_state, ndlp->nlp_flag);
3903
dea31012005-04-17 16:05:31 -05003904 phba->fc_stat.elsRcvFARP++;
James Smart2e0fef82007-06-17 19:56:36 -05003905 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05003906 break;
3907 case ELS_CMD_FAN:
James Smart858c9f62007-06-17 19:56:39 -05003908 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3909 "RCV FAN: did:x%x/ste:x%x flg:x%x",
3910 did, vport->port_state, ndlp->nlp_flag);
3911
dea31012005-04-17 16:05:31 -05003912 phba->fc_stat.elsRcvFAN++;
James Smart2e0fef82007-06-17 19:56:36 -05003913 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05003914 break;
dea31012005-04-17 16:05:31 -05003915 case ELS_CMD_PRLI:
James Smart858c9f62007-06-17 19:56:39 -05003916 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3917 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
3918 did, vport->port_state, ndlp->nlp_flag);
3919
dea31012005-04-17 16:05:31 -05003920 phba->fc_stat.elsRcvPRLI++;
James Smart2e0fef82007-06-17 19:56:36 -05003921 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05003922 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05003923 break;
3924 }
James Smart2e0fef82007-06-17 19:56:36 -05003925 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
dea31012005-04-17 16:05:31 -05003926 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003927 case ELS_CMD_LIRR:
James Smart858c9f62007-06-17 19:56:39 -05003928 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3929 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
3930 did, vport->port_state, ndlp->nlp_flag);
3931
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003932 phba->fc_stat.elsRcvLIRR++;
James Smart2e0fef82007-06-17 19:56:36 -05003933 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04003934 if (newnode)
James Smart2e0fef82007-06-17 19:56:36 -05003935 lpfc_drop_node(vport, ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003936 break;
3937 case ELS_CMD_RPS:
James Smart858c9f62007-06-17 19:56:39 -05003938 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3939 "RCV RPS: did:x%x/ste:x%x flg:x%x",
3940 did, vport->port_state, ndlp->nlp_flag);
3941
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003942 phba->fc_stat.elsRcvRPS++;
James Smart2e0fef82007-06-17 19:56:36 -05003943 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04003944 if (newnode)
James Smart2e0fef82007-06-17 19:56:36 -05003945 lpfc_drop_node(vport, ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003946 break;
3947 case ELS_CMD_RPL:
James Smart858c9f62007-06-17 19:56:39 -05003948 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3949 "RCV RPL: did:x%x/ste:x%x flg:x%x",
3950 did, vport->port_state, ndlp->nlp_flag);
3951
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003952 phba->fc_stat.elsRcvRPL++;
James Smart2e0fef82007-06-17 19:56:36 -05003953 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04003954 if (newnode)
James Smart2e0fef82007-06-17 19:56:36 -05003955 lpfc_drop_node(vport, ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003956 break;
dea31012005-04-17 16:05:31 -05003957 case ELS_CMD_RNID:
James Smart858c9f62007-06-17 19:56:39 -05003958 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3959 "RCV RNID: did:x%x/ste:x%x flg:x%x",
3960 did, vport->port_state, ndlp->nlp_flag);
3961
dea31012005-04-17 16:05:31 -05003962 phba->fc_stat.elsRcvRNID++;
James Smart2e0fef82007-06-17 19:56:36 -05003963 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04003964 if (newnode)
James Smart2e0fef82007-06-17 19:56:36 -05003965 lpfc_drop_node(vport, ndlp);
dea31012005-04-17 16:05:31 -05003966 break;
3967 default:
James Smart858c9f62007-06-17 19:56:39 -05003968 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3969 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
3970 cmd, did, vport->port_state);
3971
dea31012005-04-17 16:05:31 -05003972 /* Unsupported ELS command, reject */
James Smart858c9f62007-06-17 19:56:39 -05003973 rjt_err = LSRJT_INVALID_CMD;
dea31012005-04-17 16:05:31 -05003974
3975 /* Unknown ELS command <elsCmd> received from NPORT <did> */
3976 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
James Smart92d7f7b2007-06-17 19:56:38 -05003977 "%d (%d):0115 Unknown ELS command x%x "
James Smarted957682007-06-17 19:56:37 -05003978 "received from NPORT x%x\n",
James Smart92d7f7b2007-06-17 19:56:38 -05003979 phba->brd_no, vport->vpi, cmd, did);
James Smartde0c5b32007-04-25 09:52:27 -04003980 if (newnode)
James Smart2e0fef82007-06-17 19:56:36 -05003981 lpfc_drop_node(vport, ndlp);
dea31012005-04-17 16:05:31 -05003982 break;
3983 }
3984
3985 /* check if need to LS_RJT received ELS cmd */
3986 if (rjt_err) {
James Smart92d7f7b2007-06-17 19:56:38 -05003987 memset(&stat, 0, sizeof(stat));
James Smart858c9f62007-06-17 19:56:39 -05003988 stat.un.b.lsRjtRsnCode = rjt_err;
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04003989 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart858c9f62007-06-17 19:56:39 -05003990 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
3991 NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05003992 if (newnode)
3993 lpfc_drop_node(vport, ndlp);
dea31012005-04-17 16:05:31 -05003994 }
3995
James Smarted957682007-06-17 19:56:37 -05003996 return;
3997
3998dropit:
3999 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
James Smart92d7f7b2007-06-17 19:56:38 -05004000 "%d (%d):0111 Dropping received ELS cmd "
James Smarted957682007-06-17 19:56:37 -05004001 "Data: x%x x%x x%x\n",
James Smart92d7f7b2007-06-17 19:56:38 -05004002 phba->brd_no, vport ? vport->vpi : 0xffff,
James Smarted957682007-06-17 19:56:37 -05004003 icmd->ulpStatus, icmd->un.ulpWord[4],
4004 icmd->ulpTimeout);
4005 phba->fc_stat.elsRcvDrop++;
4006}
4007
James Smart92d7f7b2007-06-17 19:56:38 -05004008static struct lpfc_vport *
4009lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
4010{
4011 struct lpfc_vport *vport;
4012
4013 list_for_each_entry(vport, &phba->port_list, listentry) {
4014 if (vport->vpi == vpi)
4015 return vport;
4016 }
4017 return NULL;
4018}
James Smarted957682007-06-17 19:56:37 -05004019
4020void
4021lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
4022 struct lpfc_iocbq *elsiocb)
4023{
4024 struct lpfc_vport *vport = phba->pport;
James Smarted957682007-06-17 19:56:37 -05004025 IOCB_t *icmd = &elsiocb->iocb;
James Smarted957682007-06-17 19:56:37 -05004026 dma_addr_t paddr;
James Smart92d7f7b2007-06-17 19:56:38 -05004027 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
4028 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
James Smarted957682007-06-17 19:56:37 -05004029
James Smart92d7f7b2007-06-17 19:56:38 -05004030 elsiocb->context2 = NULL;
4031 elsiocb->context3 = NULL;
4032
4033 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
4034 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
4035 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
4036 (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) {
James Smarted957682007-06-17 19:56:37 -05004037 phba->fc_stat.NoRcvBuf++;
4038 /* Not enough posted buffers; Try posting more buffers */
James Smart92d7f7b2007-06-17 19:56:38 -05004039 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
James Smarted957682007-06-17 19:56:37 -05004040 lpfc_post_buffer(phba, pring, 0, 1);
4041 return;
4042 }
4043
James Smart92d7f7b2007-06-17 19:56:38 -05004044 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
4045 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
4046 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
4047 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
4048 vport = phba->pport;
4049 else {
4050 uint16_t vpi = icmd->unsli3.rcvsli3.vpi;
4051 vport = lpfc_find_vport_by_vpid(phba, vpi);
4052 }
4053 }
4054 /* If there are no BDEs associated
4055 * with this IOCB, there is nothing to do.
4056 */
James Smarted957682007-06-17 19:56:37 -05004057 if (icmd->ulpBdeCount == 0)
4058 return;
4059
James Smart92d7f7b2007-06-17 19:56:38 -05004060 /* type of ELS cmd is first 32bit word
4061 * in packet
4062 */
James Smarted957682007-06-17 19:56:37 -05004063 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05004064 elsiocb->context2 = bdeBuf1;
James Smarted957682007-06-17 19:56:37 -05004065 } else {
4066 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
4067 icmd->un.cont64[0].addrLow);
James Smart92d7f7b2007-06-17 19:56:38 -05004068 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
4069 paddr);
James Smarted957682007-06-17 19:56:37 -05004070 }
4071
James Smart92d7f7b2007-06-17 19:56:38 -05004072 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
4073 /*
4074 * The different unsolicited event handlers would tell us
4075 * if they are done with "mp" by setting context2 to NULL.
4076 */
James Smart329f9bc2007-04-25 09:53:01 -04004077 lpfc_nlp_put(elsiocb->context1);
4078 elsiocb->context1 = NULL;
dea31012005-04-17 16:05:31 -05004079 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05004080 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
4081 elsiocb->context2 = NULL;
dea31012005-04-17 16:05:31 -05004082 }
James Smarted957682007-06-17 19:56:37 -05004083
4084 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
James Smart92d7f7b2007-06-17 19:56:38 -05004085 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
James Smarted957682007-06-17 19:56:37 -05004086 icmd->ulpBdeCount == 2) {
James Smart92d7f7b2007-06-17 19:56:38 -05004087 elsiocb->context2 = bdeBuf2;
4088 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
James Smarted957682007-06-17 19:56:37 -05004089 /* free mp if we are done with it */
4090 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05004091 lpfc_in_buf_free(phba, elsiocb->context2);
4092 elsiocb->context2 = NULL;
James Smarted957682007-06-17 19:56:37 -05004093 }
dea31012005-04-17 16:05:31 -05004094 }
dea31012005-04-17 16:05:31 -05004095}
James Smart92d7f7b2007-06-17 19:56:38 -05004096
4097void
4098lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
4099{
4100 struct lpfc_nodelist *ndlp, *ndlp_fdmi;
4101
4102 ndlp = lpfc_findnode_did(vport, NameServer_DID);
4103 if (!ndlp) {
4104 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
4105 if (!ndlp) {
4106 if (phba->fc_topology == TOPOLOGY_LOOP) {
4107 lpfc_disc_start(vport);
4108 return;
4109 }
4110 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4111 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
4112 "%d (%d):0251 NameServer login: no memory\n",
4113 phba->brd_no, vport->vpi);
4114 return;
4115 }
4116 lpfc_nlp_init(vport, ndlp, NameServer_DID);
4117 ndlp->nlp_type |= NLP_FABRIC;
4118 }
4119
4120 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
4121
4122 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
4123 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4124 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
4125 "%d (%d):0252 Cannot issue NameServer login\n",
4126 phba->brd_no, vport->vpi);
4127 return;
4128 }
4129
4130 if (phba->cfg_fdmi_on) {
4131 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
4132 GFP_KERNEL);
4133 if (ndlp_fdmi) {
4134 lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
4135 ndlp_fdmi->nlp_type |= NLP_FABRIC;
4136 ndlp_fdmi->nlp_state =
4137 NLP_STE_PLOGI_ISSUE;
4138 lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID,
4139 0);
4140 }
4141 }
4142 return;
4143}
4144
4145static void
4146lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4147{
4148 struct lpfc_vport *vport = pmb->vport;
4149 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4150 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
4151 MAILBOX_t *mb = &pmb->mb;
4152
4153 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
4154 lpfc_nlp_put(ndlp);
4155
4156 if (mb->mbxStatus) {
4157 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
4158 "%d (%d):0915 Register VPI failed: 0x%x\n",
4159 phba->brd_no, vport->vpi, mb->mbxStatus);
4160
4161 switch (mb->mbxStatus) {
4162 case 0x11: /* unsupported feature */
4163 case 0x9603: /* max_vpi exceeded */
4164 /* giving up on vport registration */
4165 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4166 spin_lock_irq(shost->host_lock);
4167 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
4168 spin_unlock_irq(shost->host_lock);
4169 lpfc_can_disctmo(vport);
4170 break;
4171 default:
4172 /* Try to recover from this error */
4173 lpfc_mbx_unreg_vpi(vport);
4174 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
4175 lpfc_initial_fdisc(vport);
4176 break;
4177 }
4178
4179 } else {
4180 if (vport == phba->pport)
4181 lpfc_issue_fabric_reglogin(vport);
4182 else
4183 lpfc_do_scr_ns_plogi(phba, vport);
4184 }
4185 mempool_free(pmb, phba->mbox_mem_pool);
4186 return;
4187}
4188
4189void
4190lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
4191 struct lpfc_nodelist *ndlp)
4192{
4193 LPFC_MBOXQ_t *mbox;
4194
4195 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4196 if (mbox) {
4197 lpfc_reg_vpi(phba, vport->vpi, vport->fc_myDID, mbox);
4198 mbox->vport = vport;
4199 mbox->context2 = lpfc_nlp_get(ndlp);
4200 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
4201 if (lpfc_sli_issue_mbox(phba, mbox,
4202 MBX_NOWAIT | MBX_STOP_IOCB)
4203 == MBX_NOT_FINISHED) {
4204 mempool_free(mbox, phba->mbox_mem_pool);
4205 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
4206
4207 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4208
4209 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
4210 "%d (%d):0253 Register VPI: Cannot send mbox\n",
4211 phba->brd_no, vport->vpi);
4212 }
4213 } else {
4214 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4215
4216 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
4217 "%d (%d):0254 Register VPI: no memory\n",
4218 phba->brd_no, vport->vpi);
4219
4220 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
4221 lpfc_nlp_put(ndlp);
4222 }
4223}
4224
4225static void
4226lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4227 struct lpfc_iocbq *rspiocb)
4228{
4229 struct lpfc_vport *vport = cmdiocb->vport;
4230 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4231 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
4232 struct lpfc_nodelist *np;
4233 struct lpfc_nodelist *next_np;
4234 IOCB_t *irsp = &rspiocb->iocb;
4235 struct lpfc_iocbq *piocb;
4236
4237 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
4238 "%d (%d):0123 FDISC completes. x%x/x%x prevDID: x%x\n",
4239 phba->brd_no, vport->vpi,
4240 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
4241
4242 /* Since all FDISCs are being single threaded, we
4243 * must reset the discovery timer for ALL vports
4244 * waiting to send FDISC when one completes.
4245 */
4246 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
4247 lpfc_set_disctmo(piocb->vport);
4248 }
4249
James Smart858c9f62007-06-17 19:56:39 -05004250 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4251 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
4252 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
4253
James Smart92d7f7b2007-06-17 19:56:38 -05004254 if (irsp->ulpStatus) {
4255 /* Check for retry */
4256 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
4257 goto out;
4258
4259 /* FDISC failed */
4260 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
4261 "%d (%d):0124 FDISC failed. (%d/%d)\n",
4262 phba->brd_no, vport->vpi,
4263 irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smart858c9f62007-06-17 19:56:39 -05004264
James Smart92d7f7b2007-06-17 19:56:38 -05004265 if (vport->fc_vport->vport_state == FC_VPORT_INITIALIZING)
4266 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4267
4268 lpfc_nlp_put(ndlp);
4269 /* giving up on FDISC. Cancel discovery timer */
4270 lpfc_can_disctmo(vport);
4271 } else {
4272 spin_lock_irq(shost->host_lock);
4273 vport->fc_flag |= FC_FABRIC;
4274 if (vport->phba->fc_topology == TOPOLOGY_LOOP)
4275 vport->fc_flag |= FC_PUBLIC_LOOP;
4276 spin_unlock_irq(shost->host_lock);
4277
4278 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
4279 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
4280 if ((vport->fc_prevDID != vport->fc_myDID) &&
4281 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
4282 /* If our NportID changed, we need to ensure all
4283 * remaining NPORTs get unreg_login'ed so we can
4284 * issue unreg_vpi.
4285 */
4286 list_for_each_entry_safe(np, next_np,
4287 &vport->fc_nodes, nlp_listp) {
4288 if (np->nlp_state != NLP_STE_NPR_NODE
4289 || !(np->nlp_flag & NLP_NPR_ADISC))
4290 continue;
4291 spin_lock_irq(shost->host_lock);
4292 np->nlp_flag &= ~NLP_NPR_ADISC;
4293 spin_unlock_irq(shost->host_lock);
4294 lpfc_unreg_rpi(vport, np);
4295 }
4296 lpfc_mbx_unreg_vpi(vport);
4297 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
4298 }
4299
4300 if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
4301 lpfc_register_new_vport(phba, vport, ndlp);
4302 else
4303 lpfc_do_scr_ns_plogi(phba, vport);
4304
4305 lpfc_nlp_put(ndlp); /* Free Fabric ndlp for vports */
4306 }
4307
4308out:
4309 lpfc_els_free_iocb(phba, cmdiocb);
4310}
4311
4312int
4313lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4314 uint8_t retry)
4315{
4316 struct lpfc_hba *phba = vport->phba;
4317 IOCB_t *icmd;
4318 struct lpfc_iocbq *elsiocb;
4319 struct serv_parm *sp;
4320 uint8_t *pcmd;
4321 uint16_t cmdsize;
4322 int did = ndlp->nlp_DID;
4323 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05004324
4325 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
4326 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
4327 ELS_CMD_FDISC);
4328 if (!elsiocb) {
James Smart92d7f7b2007-06-17 19:56:38 -05004329 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4330
4331 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
4332 "%d (%d):0255 Issue FDISC: no IOCB\n",
4333 phba->brd_no, vport->vpi);
4334 return 1;
4335 }
4336
4337 icmd = &elsiocb->iocb;
4338 icmd->un.elsreq64.myID = 0;
4339 icmd->un.elsreq64.fl = 1;
4340
4341 /* For FDISC, Let FDISC rsp set the NPortID for this VPI */
4342 icmd->ulpCt_h = 1;
4343 icmd->ulpCt_l = 0;
4344
4345 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4346 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
4347 pcmd += sizeof(uint32_t); /* CSP Word 1 */
4348 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
4349 sp = (struct serv_parm *) pcmd;
4350 /* Setup CSPs accordingly for Fabric */
4351 sp->cmn.e_d_tov = 0;
4352 sp->cmn.w2.r_a_tov = 0;
4353 sp->cls1.classValid = 0;
4354 sp->cls2.seqDelivery = 1;
4355 sp->cls3.seqDelivery = 1;
4356
4357 pcmd += sizeof(uint32_t); /* CSP Word 2 */
4358 pcmd += sizeof(uint32_t); /* CSP Word 3 */
4359 pcmd += sizeof(uint32_t); /* CSP Word 4 */
4360 pcmd += sizeof(uint32_t); /* Port Name */
4361 memcpy(pcmd, &vport->fc_portname, 8);
4362 pcmd += sizeof(uint32_t); /* Node Name */
4363 pcmd += sizeof(uint32_t); /* Node Name */
4364 memcpy(pcmd, &vport->fc_nodename, 8);
4365
4366 lpfc_set_disctmo(vport);
4367
4368 phba->fc_stat.elsXmitFDISC++;
4369 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
4370
James Smart858c9f62007-06-17 19:56:39 -05004371 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4372 "Issue FDISC: did:x%x",
4373 did, 0, 0);
4374
James Smart92d7f7b2007-06-17 19:56:38 -05004375 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
4376 if (rc == IOCB_ERROR) {
4377 lpfc_els_free_iocb(phba, elsiocb);
James Smart92d7f7b2007-06-17 19:56:38 -05004378 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4379
4380 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
4381 "%d (%d):0256 Issue FDISC: Cannot send IOCB\n",
4382 phba->brd_no, vport->vpi);
4383
4384 return 1;
4385 }
4386 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
4387 vport->port_state = LPFC_FDISC;
4388 return 0;
4389}
4390
4391static void
4392lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4393 struct lpfc_iocbq *rspiocb)
4394{
4395 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05004396 IOCB_t *irsp;
4397
4398 irsp = &rspiocb->iocb;
4399 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4400 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
4401 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
James Smart92d7f7b2007-06-17 19:56:38 -05004402
4403 lpfc_els_free_iocb(phba, cmdiocb);
4404 vport->unreg_vpi_cmpl = VPORT_ERROR;
4405}
4406
4407int
4408lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4409{
4410 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4411 struct lpfc_hba *phba = vport->phba;
4412 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
4413 IOCB_t *icmd;
4414 struct lpfc_iocbq *elsiocb;
4415 uint8_t *pcmd;
4416 uint16_t cmdsize;
4417
4418 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
4419 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
4420 ELS_CMD_LOGO);
4421 if (!elsiocb)
4422 return 1;
4423
4424 icmd = &elsiocb->iocb;
4425 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4426 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
4427 pcmd += sizeof(uint32_t);
4428
4429 /* Fill in LOGO payload */
4430 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
4431 pcmd += sizeof(uint32_t);
4432 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
4433
James Smart858c9f62007-06-17 19:56:39 -05004434 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4435 "Issue LOGO npiv did:x%x flg:x%x",
4436 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4437
James Smart92d7f7b2007-06-17 19:56:38 -05004438 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
4439 spin_lock_irq(shost->host_lock);
4440 ndlp->nlp_flag |= NLP_LOGO_SND;
4441 spin_unlock_irq(shost->host_lock);
4442 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
4443 spin_lock_irq(shost->host_lock);
4444 ndlp->nlp_flag &= ~NLP_LOGO_SND;
4445 spin_unlock_irq(shost->host_lock);
4446 lpfc_els_free_iocb(phba, elsiocb);
4447 return 1;
4448 }
4449 return 0;
4450}
4451
4452void
4453lpfc_fabric_block_timeout(unsigned long ptr)
4454{
4455 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
4456 unsigned long iflags;
4457 uint32_t tmo_posted;
4458 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
4459 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
4460 if (!tmo_posted)
4461 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
4462 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
4463
4464 if (!tmo_posted) {
4465 spin_lock_irqsave(&phba->hbalock, iflags);
4466 if (phba->work_wait)
4467 lpfc_worker_wake_up(phba);
4468 spin_unlock_irqrestore(&phba->hbalock, iflags);
4469 }
4470}
4471
4472static void
4473lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
4474{
4475 struct lpfc_iocbq *iocb;
4476 unsigned long iflags;
4477 int ret;
4478 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
4479 IOCB_t *cmd;
4480
4481repeat:
4482 iocb = NULL;
4483 spin_lock_irqsave(&phba->hbalock, iflags);
4484 /* Post any pending iocb to the SLI layer */
4485 if (atomic_read(&phba->fabric_iocb_count) == 0) {
4486 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
4487 list);
4488 if (iocb)
4489 atomic_inc(&phba->fabric_iocb_count);
4490 }
4491 spin_unlock_irqrestore(&phba->hbalock, iflags);
4492 if (iocb) {
4493 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
4494 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
4495 iocb->iocb_flag |= LPFC_IO_FABRIC;
4496
James Smart858c9f62007-06-17 19:56:39 -05004497 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
4498 "Fabric sched1: ste:x%x",
4499 iocb->vport->port_state, 0, 0);
4500
James Smart92d7f7b2007-06-17 19:56:38 -05004501 ret = lpfc_sli_issue_iocb(phba, pring, iocb, 0);
4502
4503 if (ret == IOCB_ERROR) {
4504 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
4505 iocb->fabric_iocb_cmpl = NULL;
4506 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
4507 cmd = &iocb->iocb;
4508 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
4509 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
4510 iocb->iocb_cmpl(phba, iocb, iocb);
4511
4512 atomic_dec(&phba->fabric_iocb_count);
4513 goto repeat;
4514 }
4515 }
4516
4517 return;
4518}
4519
4520void
4521lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
4522{
4523 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
4524
4525 lpfc_resume_fabric_iocbs(phba);
4526 return;
4527}
4528
4529static void
4530lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
4531{
4532 int blocked;
4533
4534 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
4535 /* Start a timer to unblock fabric
4536 * iocbs after 100ms
4537 */
4538 if (!blocked)
4539 mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 );
4540
4541 return;
4542}
4543
4544static void
4545lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4546 struct lpfc_iocbq *rspiocb)
4547{
4548 struct ls_rjt stat;
4549
4550 if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
4551 BUG();
4552
4553 switch (rspiocb->iocb.ulpStatus) {
4554 case IOSTAT_NPORT_RJT:
4555 case IOSTAT_FABRIC_RJT:
4556 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
4557 lpfc_block_fabric_iocbs(phba);
4558 }
4559 break;
4560
4561 case IOSTAT_NPORT_BSY:
4562 case IOSTAT_FABRIC_BSY:
4563 lpfc_block_fabric_iocbs(phba);
4564 break;
4565
4566 case IOSTAT_LS_RJT:
4567 stat.un.lsRjtError =
4568 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
4569 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
4570 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
4571 lpfc_block_fabric_iocbs(phba);
4572 break;
4573 }
4574
4575 if (atomic_read(&phba->fabric_iocb_count) == 0)
4576 BUG();
4577
4578 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
4579 cmdiocb->fabric_iocb_cmpl = NULL;
4580 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
4581 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
4582
4583 atomic_dec(&phba->fabric_iocb_count);
4584 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
4585 /* Post any pending iocbs to HBA */
4586 lpfc_resume_fabric_iocbs(phba);
4587 }
4588}
4589
4590int
4591lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
4592{
4593 unsigned long iflags;
4594 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
4595 int ready;
4596 int ret;
4597
4598 if (atomic_read(&phba->fabric_iocb_count) > 1)
4599 BUG();
4600
4601 spin_lock_irqsave(&phba->hbalock, iflags);
4602 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
4603 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
4604
4605 spin_unlock_irqrestore(&phba->hbalock, iflags);
4606 if (ready) {
4607 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
4608 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
4609 iocb->iocb_flag |= LPFC_IO_FABRIC;
4610
James Smart858c9f62007-06-17 19:56:39 -05004611 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
4612 "Fabric sched2: ste:x%x",
4613 iocb->vport->port_state, 0, 0);
4614
James Smart92d7f7b2007-06-17 19:56:38 -05004615 atomic_inc(&phba->fabric_iocb_count);
4616 ret = lpfc_sli_issue_iocb(phba, pring, iocb, 0);
4617
4618 if (ret == IOCB_ERROR) {
4619 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
4620 iocb->fabric_iocb_cmpl = NULL;
4621 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
4622 atomic_dec(&phba->fabric_iocb_count);
4623 }
4624 } else {
4625 spin_lock_irqsave(&phba->hbalock, iflags);
4626 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
4627 spin_unlock_irqrestore(&phba->hbalock, iflags);
4628 ret = IOCB_SUCCESS;
4629 }
4630 return ret;
4631}
4632
4633
4634void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
4635{
4636 LIST_HEAD(completions);
4637 struct lpfc_hba *phba = vport->phba;
4638 struct lpfc_iocbq *tmp_iocb, *piocb;
4639 IOCB_t *cmd;
4640
4641 spin_lock_irq(&phba->hbalock);
4642 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
4643 list) {
4644
4645 if (piocb->vport != vport)
4646 continue;
4647
4648 list_move_tail(&piocb->list, &completions);
4649 }
4650 spin_unlock_irq(&phba->hbalock);
4651
4652 while (!list_empty(&completions)) {
4653 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
4654 list_del_init(&piocb->list);
4655
4656 cmd = &piocb->iocb;
4657 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
4658 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
4659 (piocb->iocb_cmpl) (phba, piocb, piocb);
4660 }
4661}
4662
4663void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
4664{
4665 LIST_HEAD(completions);
4666 struct lpfc_hba *phba = ndlp->vport->phba;
4667 struct lpfc_iocbq *tmp_iocb, *piocb;
4668 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
4669 IOCB_t *cmd;
4670
4671 spin_lock_irq(&phba->hbalock);
4672 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
4673 list) {
4674 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
4675
4676 list_move_tail(&piocb->list, &completions);
4677 }
4678 }
4679 spin_unlock_irq(&phba->hbalock);
4680
4681 while (!list_empty(&completions)) {
4682 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
4683 list_del_init(&piocb->list);
4684
4685 cmd = &piocb->iocb;
4686 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
4687 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
4688 (piocb->iocb_cmpl) (phba, piocb, piocb);
4689 }
4690}
4691
4692void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
4693{
4694 LIST_HEAD(completions);
4695 struct lpfc_iocbq *piocb;
4696 IOCB_t *cmd;
4697
4698 spin_lock_irq(&phba->hbalock);
4699 list_splice_init(&phba->fabric_iocb_list, &completions);
4700 spin_unlock_irq(&phba->hbalock);
4701
4702 while (!list_empty(&completions)) {
4703 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
4704 list_del_init(&piocb->list);
4705
4706 cmd = &piocb->iocb;
4707 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
4708 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
4709 (piocb->iocb_cmpl) (phba, piocb, piocb);
4710 }
4711}
4712
4713
4714void lpfc_fabric_abort_flogi(struct lpfc_hba *phba)
4715{
4716 LIST_HEAD(completions);
4717 struct lpfc_iocbq *tmp_iocb, *piocb;
4718 IOCB_t *cmd;
4719 struct lpfc_nodelist *ndlp;
4720
4721 spin_lock_irq(&phba->hbalock);
4722 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
4723 list) {
4724
4725 cmd = &piocb->iocb;
4726 ndlp = (struct lpfc_nodelist *) piocb->context1;
4727 if (cmd->ulpCommand == CMD_ELS_REQUEST64_CR &&
4728 ndlp != NULL &&
4729 ndlp->nlp_DID == Fabric_DID)
4730 list_move_tail(&piocb->list, &completions);
4731 }
4732 spin_unlock_irq(&phba->hbalock);
4733
4734 while (!list_empty(&completions)) {
4735 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
4736 list_del_init(&piocb->list);
4737
4738 cmd = &piocb->iocb;
4739 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
4740 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
4741 (piocb->iocb_cmpl) (phba, piocb, piocb);
4742 }
4743}
4744
4745