blob: 0af33bead30242a1c6f740e94ab25617c9d30f48 [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"
38
39static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *,
40 struct lpfc_iocbq *);
41static int lpfc_max_els_tries = 3;
42
43static int
James Smart2e0fef82007-06-17 19:56:36 -050044lpfc_els_chk_latt(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -050045{
James Smart2e0fef82007-06-17 19:56:36 -050046 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
47 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -050048 LPFC_MBOXQ_t *mbox;
49 uint32_t ha_copy;
50 int rc;
51
James Smart2e0fef82007-06-17 19:56:36 -050052 if (vport->port_state >= LPFC_VPORT_READY ||
53 phba->link_state == LPFC_LINK_DOWN)
dea31012005-04-17 16:05:31 -050054 return 0;
55
56 /* Read the HBA Host Attention Register */
dea31012005-04-17 16:05:31 -050057 ha_copy = readl(phba->HAregaddr);
dea31012005-04-17 16:05:31 -050058
59 if (!(ha_copy & HA_LATT))
60 return 0;
61
62 /* Pending Link Event during Discovery */
63 lpfc_printf_log(phba, KERN_WARNING, LOG_DISCOVERY,
64 "%d:0237 Pending Link Event during "
65 "Discovery: State x%x\n",
James Smart2e0fef82007-06-17 19:56:36 -050066 phba->brd_no, phba->pport->port_state);
dea31012005-04-17 16:05:31 -050067
68 /* CLEAR_LA should re-enable link attention events and
69 * we should then imediately take a LATT event. The
70 * LATT processing should call lpfc_linkdown() which
71 * will cleanup any left over in-progress discovery
72 * events.
73 */
James Smart2e0fef82007-06-17 19:56:36 -050074 spin_lock_irq(shost->host_lock);
75 vport->fc_flag |= FC_ABORT_DISCOVERY;
76 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -050077
James Smart2e0fef82007-06-17 19:56:36 -050078 if (phba->link_state != LPFC_CLEAR_LA) {
dea31012005-04-17 16:05:31 -050079 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) {
James Smart2e0fef82007-06-17 19:56:36 -050080 phba->link_state = LPFC_CLEAR_LA;
dea31012005-04-17 16:05:31 -050081 lpfc_clear_la(phba, mbox);
82 mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
James Smart2e0fef82007-06-17 19:56:36 -050083 mbox->vport = vport;
84 printk(KERN_ERR "%s (%d): do clear_la\n",
85 __FUNCTION__, __LINE__);
86 rc = lpfc_sli_issue_mbox(phba, mbox,
87 (MBX_NOWAIT | MBX_STOP_IOCB));
dea31012005-04-17 16:05:31 -050088 if (rc == MBX_NOT_FINISHED) {
89 mempool_free(mbox, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -050090 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -050091 }
92 }
93 }
94
Jamie Wellnitzc9f87352006-02-28 19:25:23 -050095 return 1;
dea31012005-04-17 16:05:31 -050096
97}
98
99static struct lpfc_iocbq *
James Smart2e0fef82007-06-17 19:56:36 -0500100lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp,
101 uint16_t cmdSize, uint8_t retry,
102 struct lpfc_nodelist *ndlp, uint32_t did,
103 uint32_t elscmd)
dea31012005-04-17 16:05:31 -0500104{
James Smart2e0fef82007-06-17 19:56:36 -0500105 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400106 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -0500107 struct lpfc_dmabuf *pcmd, *prsp, *pbuflist;
108 struct ulp_bde64 *bpl;
109 IOCB_t *icmd;
110
dea31012005-04-17 16:05:31 -0500111
James Smart2e0fef82007-06-17 19:56:36 -0500112 if (!lpfc_is_link_up(phba))
113 return NULL;
dea31012005-04-17 16:05:31 -0500114
dea31012005-04-17 16:05:31 -0500115 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400116 elsiocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -0500117
118 if (elsiocb == NULL)
119 return NULL;
dea31012005-04-17 16:05:31 -0500120 icmd = &elsiocb->iocb;
121
122 /* fill in BDEs for command */
123 /* Allocate buffer for command payload */
124 if (((pcmd = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL)) == 0) ||
125 ((pcmd->virt = lpfc_mbuf_alloc(phba,
126 MEM_PRI, &(pcmd->phys))) == 0)) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -0800127 kfree(pcmd);
dea31012005-04-17 16:05:31 -0500128
James Bottomley604a3e32005-10-29 10:28:33 -0500129 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -0500130 return NULL;
131 }
132
133 INIT_LIST_HEAD(&pcmd->list);
134
135 /* Allocate buffer for response payload */
136 if (expectRsp) {
137 prsp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
138 if (prsp)
139 prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
140 &prsp->phys);
141 if (prsp == 0 || prsp->virt == 0) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -0800142 kfree(prsp);
dea31012005-04-17 16:05:31 -0500143 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
144 kfree(pcmd);
James Bottomley604a3e32005-10-29 10:28:33 -0500145 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -0500146 return NULL;
147 }
148 INIT_LIST_HEAD(&prsp->list);
149 } else {
150 prsp = NULL;
151 }
152
153 /* Allocate buffer for Buffer ptr list */
154 pbuflist = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
155 if (pbuflist)
156 pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
157 &pbuflist->phys);
158 if (pbuflist == 0 || pbuflist->virt == 0) {
James Bottomley604a3e32005-10-29 10:28:33 -0500159 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -0500160 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
161 lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
162 kfree(pcmd);
163 kfree(prsp);
Jesper Juhlc9475cb2005-11-07 01:01:26 -0800164 kfree(pbuflist);
dea31012005-04-17 16:05:31 -0500165 return NULL;
166 }
167
168 INIT_LIST_HEAD(&pbuflist->list);
169
170 icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
171 icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
172 icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BDL;
James Smart2e0fef82007-06-17 19:56:36 -0500173 icmd->un.elsreq64.remoteID = did; /* DID */
dea31012005-04-17 16:05:31 -0500174 if (expectRsp) {
175 icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof (struct ulp_bde64));
dea31012005-04-17 16:05:31 -0500176 icmd->ulpCommand = CMD_ELS_REQUEST64_CR;
James Smart2680eea2007-04-25 09:52:55 -0400177 icmd->ulpTimeout = phba->fc_ratov * 2;
dea31012005-04-17 16:05:31 -0500178 } else {
179 icmd->un.elsreq64.bdl.bdeSize = sizeof (struct ulp_bde64);
180 icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
181 }
182
183 icmd->ulpBdeCount = 1;
184 icmd->ulpLe = 1;
185 icmd->ulpClass = CLASS3;
186
187 bpl = (struct ulp_bde64 *) pbuflist->virt;
188 bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys));
189 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys));
190 bpl->tus.f.bdeSize = cmdSize;
191 bpl->tus.f.bdeFlags = 0;
192 bpl->tus.w = le32_to_cpu(bpl->tus.w);
193
194 if (expectRsp) {
195 bpl++;
196 bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys));
197 bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys));
198 bpl->tus.f.bdeSize = FCELSSIZE;
199 bpl->tus.f.bdeFlags = BUFF_USE_RCV;
200 bpl->tus.w = le32_to_cpu(bpl->tus.w);
201 }
202
203 /* Save for completion so we can release these resources */
James Smart329f9bc2007-04-25 09:53:01 -0400204 elsiocb->context1 = lpfc_nlp_get(ndlp);
205 elsiocb->context2 = pcmd;
206 elsiocb->context3 = pbuflist;
dea31012005-04-17 16:05:31 -0500207 elsiocb->retry = retry;
James Smart2e0fef82007-06-17 19:56:36 -0500208 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -0500209 elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
210
211 if (prsp) {
212 list_add(&prsp->list, &pcmd->list);
213 }
214
215 if (expectRsp) {
216 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
217 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
218 "%d:0116 Xmit ELS command x%x to remote "
James Smart2e0fef82007-06-17 19:56:36 -0500219 "NPORT x%x I/O tag: x%x, port state: x%x\n",
220 phba->brd_no, elscmd, did,
221 elsiocb->iotag, vport->port_state);
dea31012005-04-17 16:05:31 -0500222 } else {
223 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
224 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
225 "%d:0117 Xmit ELS response x%x to remote "
James Smart1dcb58e2007-04-25 09:51:30 -0400226 "NPORT x%x I/O tag: x%x, size: x%x\n",
dea31012005-04-17 16:05:31 -0500227 phba->brd_no, elscmd,
James Smart1dcb58e2007-04-25 09:51:30 -0400228 ndlp->nlp_DID, elsiocb->iotag, cmdSize);
dea31012005-04-17 16:05:31 -0500229 }
230
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500231 return elsiocb;
dea31012005-04-17 16:05:31 -0500232}
233
234
235static int
James Smart2e0fef82007-06-17 19:56:36 -0500236lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
237 struct serv_parm *sp, IOCB_t *irsp)
dea31012005-04-17 16:05:31 -0500238{
James Smart2e0fef82007-06-17 19:56:36 -0500239 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
240 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500241 LPFC_MBOXQ_t *mbox;
James Smart14691152006-12-02 13:34:28 -0500242 struct lpfc_dmabuf *mp;
dea31012005-04-17 16:05:31 -0500243 int rc;
244
James Smart2e0fef82007-06-17 19:56:36 -0500245 spin_lock_irq(shost->host_lock);
246 vport->fc_flag |= FC_FABRIC;
247 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500248
249 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
250 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
251 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
252
253 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
254
255 if (phba->fc_topology == TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500256 spin_lock_irq(shost->host_lock);
257 vport->fc_flag |= FC_PUBLIC_LOOP;
258 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500259 } else {
260 /*
261 * If we are a N-port connected to a Fabric, fixup sparam's so
262 * logins to devices on remote loops work.
263 */
James Smart2e0fef82007-06-17 19:56:36 -0500264 vport->fc_sparam.cmn.altBbCredit = 1;
dea31012005-04-17 16:05:31 -0500265 }
266
James Smart2e0fef82007-06-17 19:56:36 -0500267 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
dea31012005-04-17 16:05:31 -0500268 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
269 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof (struct lpfc_name));
270 ndlp->nlp_class_sup = 0;
271 if (sp->cls1.classValid)
272 ndlp->nlp_class_sup |= FC_COS_CLASS1;
273 if (sp->cls2.classValid)
274 ndlp->nlp_class_sup |= FC_COS_CLASS2;
275 if (sp->cls3.classValid)
276 ndlp->nlp_class_sup |= FC_COS_CLASS3;
277 if (sp->cls4.classValid)
278 ndlp->nlp_class_sup |= FC_COS_CLASS4;
279 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
280 sp->cmn.bbRcvSizeLsb;
281 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
282
James Smart2e0fef82007-06-17 19:56:36 -0500283 ndlp->nlp_sid = irsp->un.ulpWord[4] & Mask_DID;
284
dea31012005-04-17 16:05:31 -0500285 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
286 if (!mbox)
287 goto fail;
288
James Smart2e0fef82007-06-17 19:56:36 -0500289 vport->port_state = LPFC_FABRIC_CFG_LINK;
dea31012005-04-17 16:05:31 -0500290 lpfc_config_link(phba, mbox);
291 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
292
293 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT | MBX_STOP_IOCB);
294 if (rc == MBX_NOT_FINISHED)
295 goto fail_free_mbox;
296
297 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
298 if (!mbox)
299 goto fail;
James Smart2e0fef82007-06-17 19:56:36 -0500300 rc = lpfc_reg_login(phba, Fabric_DID, (uint8_t *) sp, mbox, 0);
301 if (rc)
dea31012005-04-17 16:05:31 -0500302 goto fail_free_mbox;
303
dea31012005-04-17 16:05:31 -0500304 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
James Smart2e0fef82007-06-17 19:56:36 -0500305 mbox->vport = vport;
James Smart329f9bc2007-04-25 09:53:01 -0400306 mbox->context2 = lpfc_nlp_get(ndlp);
dea31012005-04-17 16:05:31 -0500307
308 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT | MBX_STOP_IOCB);
309 if (rc == MBX_NOT_FINISHED)
James Smart14691152006-12-02 13:34:28 -0500310 goto fail_issue_reg_login;
dea31012005-04-17 16:05:31 -0500311
312 return 0;
313
James Smart14691152006-12-02 13:34:28 -0500314 fail_issue_reg_login:
James Smart329f9bc2007-04-25 09:53:01 -0400315 lpfc_nlp_put(ndlp);
James Smart14691152006-12-02 13:34:28 -0500316 mp = (struct lpfc_dmabuf *) mbox->context1;
317 lpfc_mbuf_free(phba, mp->virt, mp->phys);
318 kfree(mp);
dea31012005-04-17 16:05:31 -0500319 fail_free_mbox:
320 mempool_free(mbox, phba->mbox_mem_pool);
321 fail:
322 return -ENXIO;
323}
324
325/*
326 * We FLOGIed into an NPort, initiate pt2pt protocol
327 */
328static int
James Smart2e0fef82007-06-17 19:56:36 -0500329lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
330 struct serv_parm *sp)
dea31012005-04-17 16:05:31 -0500331{
James Smart2e0fef82007-06-17 19:56:36 -0500332 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
333 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500334 LPFC_MBOXQ_t *mbox;
335 int rc;
336
James Smart2e0fef82007-06-17 19:56:36 -0500337 spin_lock_irq(shost->host_lock);
338 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
339 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500340
341 phba->fc_edtov = FF_DEF_EDTOV;
342 phba->fc_ratov = FF_DEF_RATOV;
James Smart2e0fef82007-06-17 19:56:36 -0500343 rc = memcmp(&vport->fc_portname, &sp->portName,
dea31012005-04-17 16:05:31 -0500344 sizeof(struct lpfc_name));
345 if (rc >= 0) {
346 /* This side will initiate the PLOGI */
James Smart2e0fef82007-06-17 19:56:36 -0500347 spin_lock_irq(shost->host_lock);
348 vport->fc_flag |= FC_PT2PT_PLOGI;
349 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500350
351 /*
352 * N_Port ID cannot be 0, set our to LocalID the other
353 * side will be RemoteID.
354 */
355
356 /* not equal */
357 if (rc)
James Smart2e0fef82007-06-17 19:56:36 -0500358 vport->fc_myDID = PT2PT_LocalID;
dea31012005-04-17 16:05:31 -0500359
360 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
361 if (!mbox)
362 goto fail;
363
364 lpfc_config_link(phba, mbox);
365
366 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
367 rc = lpfc_sli_issue_mbox(phba, mbox,
368 MBX_NOWAIT | MBX_STOP_IOCB);
369 if (rc == MBX_NOT_FINISHED) {
370 mempool_free(mbox, phba->mbox_mem_pool);
371 goto fail;
372 }
James Smart329f9bc2007-04-25 09:53:01 -0400373 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500374
James Smart2e0fef82007-06-17 19:56:36 -0500375 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
dea31012005-04-17 16:05:31 -0500376 if (!ndlp) {
377 /*
378 * Cannot find existing Fabric ndlp, so allocate a
379 * new one
380 */
381 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
382 if (!ndlp)
383 goto fail;
384
James Smart2e0fef82007-06-17 19:56:36 -0500385 lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID);
dea31012005-04-17 16:05:31 -0500386 }
387
388 memcpy(&ndlp->nlp_portname, &sp->portName,
James Smart2e0fef82007-06-17 19:56:36 -0500389 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500390 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
James Smart2e0fef82007-06-17 19:56:36 -0500391 sizeof(struct lpfc_name));
392 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
393 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500394 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500395 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500396 } else {
397 /* This side will wait for the PLOGI */
James Smart329f9bc2007-04-25 09:53:01 -0400398 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500399 }
400
James Smart2e0fef82007-06-17 19:56:36 -0500401 spin_lock_irq(shost->host_lock);
402 vport->fc_flag |= FC_PT2PT;
403 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500404
405 /* Start discovery - this should just do CLEAR_LA */
James Smart2e0fef82007-06-17 19:56:36 -0500406 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -0500407 return 0;
408 fail:
409 return -ENXIO;
410}
411
412static void
James Smart329f9bc2007-04-25 09:53:01 -0400413lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
414 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500415{
James Smart2e0fef82007-06-17 19:56:36 -0500416 struct lpfc_vport *vport = cmdiocb->vport;
417 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500418 IOCB_t *irsp = &rspiocb->iocb;
419 struct lpfc_nodelist *ndlp = cmdiocb->context1;
420 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
421 struct serv_parm *sp;
422 int rc;
423
424 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500425 if (lpfc_els_chk_latt(vport)) {
James Smart329f9bc2007-04-25 09:53:01 -0400426 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500427 goto out;
428 }
429
430 if (irsp->ulpStatus) {
431 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -0500432 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -0500433 goto out;
James Smart2e0fef82007-06-17 19:56:36 -0500434
dea31012005-04-17 16:05:31 -0500435 /* FLOGI failed, so there is no fabric */
James Smart2e0fef82007-06-17 19:56:36 -0500436 spin_lock_irq(shost->host_lock);
437 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
438 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500439
James Smart329f9bc2007-04-25 09:53:01 -0400440 /* If private loop, then allow max outstanding els to be
dea31012005-04-17 16:05:31 -0500441 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
442 * alpa map would take too long otherwise.
443 */
444 if (phba->alpa_map[0] == 0) {
James Smart329f9bc2007-04-25 09:53:01 -0400445 phba->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
dea31012005-04-17 16:05:31 -0500446 }
447
448 /* FLOGI failure */
449 lpfc_printf_log(phba,
450 KERN_INFO,
451 LOG_ELS,
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500452 "%d:0100 FLOGI failure Data: x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -0500453 phba->brd_no,
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500454 irsp->ulpStatus, irsp->un.ulpWord[4],
455 irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -0500456 goto flogifail;
457 }
458
459 /*
460 * The FLogI succeeded. Sync the data for the CPU before
461 * accessing it.
462 */
463 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
464
465 sp = prsp->virt + sizeof(uint32_t);
466
467 /* FLOGI completes successfully */
468 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
469 "%d:0101 FLOGI completes sucessfully "
470 "Data: x%x x%x x%x x%x\n",
471 phba->brd_no,
472 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
473 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution);
474
James Smart2e0fef82007-06-17 19:56:36 -0500475 if (vport->port_state == LPFC_FLOGI) {
dea31012005-04-17 16:05:31 -0500476 /*
477 * If Common Service Parameters indicate Nport
478 * we are point to point, if Fport we are Fabric.
479 */
480 if (sp->cmn.fPort)
James Smart2e0fef82007-06-17 19:56:36 -0500481 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
dea31012005-04-17 16:05:31 -0500482 else
James Smart2e0fef82007-06-17 19:56:36 -0500483 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
dea31012005-04-17 16:05:31 -0500484
485 if (!rc)
486 goto out;
487 }
488
489flogifail:
James Smart329f9bc2007-04-25 09:53:01 -0400490 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500491
492 if (irsp->ulpStatus != IOSTAT_LOCAL_REJECT ||
493 (irsp->un.ulpWord[4] != IOERR_SLI_ABORTED &&
494 irsp->un.ulpWord[4] != IOERR_SLI_DOWN)) {
495 /* FLOGI failed, so just use loop map to make discovery list */
James Smart2e0fef82007-06-17 19:56:36 -0500496 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -0500497
498 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500499 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -0500500 }
501
502out:
503 lpfc_els_free_iocb(phba, cmdiocb);
504}
505
506static int
James Smart2e0fef82007-06-17 19:56:36 -0500507lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -0500508 uint8_t retry)
509{
James Smart2e0fef82007-06-17 19:56:36 -0500510 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500511 struct serv_parm *sp;
512 IOCB_t *icmd;
513 struct lpfc_iocbq *elsiocb;
514 struct lpfc_sli_ring *pring;
515 uint8_t *pcmd;
516 uint16_t cmdsize;
517 uint32_t tmo;
518 int rc;
519
520 pring = &phba->sli.ring[LPFC_ELS_RING];
521
522 cmdsize = (sizeof (uint32_t) + sizeof (struct serv_parm));
James Smart2e0fef82007-06-17 19:56:36 -0500523 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
524 ndlp->nlp_DID, ELS_CMD_FLOGI);
James Smart488d1462006-03-07 15:02:37 -0500525 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500526 return 1;
dea31012005-04-17 16:05:31 -0500527
528 icmd = &elsiocb->iocb;
529 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
530
531 /* For FLOGI request, remainder of payload is service parameters */
532 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
533 pcmd += sizeof (uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -0500534 memcpy(pcmd, &vport->fc_sparam, sizeof (struct serv_parm));
dea31012005-04-17 16:05:31 -0500535 sp = (struct serv_parm *) pcmd;
536
537 /* Setup CSPs accordingly for Fabric */
538 sp->cmn.e_d_tov = 0;
539 sp->cmn.w2.r_a_tov = 0;
540 sp->cls1.classValid = 0;
541 sp->cls2.seqDelivery = 1;
542 sp->cls3.seqDelivery = 1;
543 if (sp->cmn.fcphLow < FC_PH3)
544 sp->cmn.fcphLow = FC_PH3;
545 if (sp->cmn.fcphHigh < FC_PH3)
546 sp->cmn.fcphHigh = FC_PH3;
547
548 tmo = phba->fc_ratov;
549 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
James Smart2e0fef82007-06-17 19:56:36 -0500550 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -0500551 phba->fc_ratov = tmo;
552
553 phba->fc_stat.elsXmitFLOGI++;
554 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
dea31012005-04-17 16:05:31 -0500555 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
dea31012005-04-17 16:05:31 -0500556 if (rc == IOCB_ERROR) {
557 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500558 return 1;
dea31012005-04-17 16:05:31 -0500559 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500560 return 0;
dea31012005-04-17 16:05:31 -0500561}
562
563int
James Smart2e0fef82007-06-17 19:56:36 -0500564lpfc_els_abort_flogi(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500565{
566 struct lpfc_sli_ring *pring;
567 struct lpfc_iocbq *iocb, *next_iocb;
568 struct lpfc_nodelist *ndlp;
569 IOCB_t *icmd;
570
571 /* Abort outstanding I/O on NPort <nlp_DID> */
572 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
573 "%d:0201 Abort outstanding I/O on NPort x%x\n",
574 phba->brd_no, Fabric_DID);
575
576 pring = &phba->sli.ring[LPFC_ELS_RING];
577
578 /*
579 * Check the txcmplq for an iocb that matches the nport the driver is
580 * searching for.
581 */
James Smart2e0fef82007-06-17 19:56:36 -0500582 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500583 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
584 icmd = &iocb->iocb;
James Smart2e0fef82007-06-17 19:56:36 -0500585 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR &&
586 icmd->un.elsreq64.bdl.ulpIoTag32) {
dea31012005-04-17 16:05:31 -0500587 ndlp = (struct lpfc_nodelist *)(iocb->context1);
James Smart07951072007-04-25 09:51:38 -0400588 if (ndlp && (ndlp->nlp_DID == Fabric_DID))
589 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
dea31012005-04-17 16:05:31 -0500590 }
591 }
James Smart2e0fef82007-06-17 19:56:36 -0500592 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500593
594 return 0;
595}
596
597int
James Smart2e0fef82007-06-17 19:56:36 -0500598lpfc_initial_flogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -0500599{
James Smart2e0fef82007-06-17 19:56:36 -0500600 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500601 struct lpfc_nodelist *ndlp;
602
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500603 /* First look for the Fabric ndlp */
James Smart2e0fef82007-06-17 19:56:36 -0500604 ndlp = lpfc_findnode_did(vport, Fabric_DID);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500605 if (!ndlp) {
dea31012005-04-17 16:05:31 -0500606 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500607 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
608 if (!ndlp)
609 return 0;
James Smart2e0fef82007-06-17 19:56:36 -0500610 lpfc_nlp_init(vport, ndlp, Fabric_DID);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500611 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500612 lpfc_dequeue_node(vport, ndlp);
dea31012005-04-17 16:05:31 -0500613 }
James Smart2e0fef82007-06-17 19:56:36 -0500614 if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
James Smart329f9bc2007-04-25 09:53:01 -0400615 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500616 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500617 return 1;
dea31012005-04-17 16:05:31 -0500618}
619
620static void
James Smart2e0fef82007-06-17 19:56:36 -0500621lpfc_more_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -0500622{
623 int sentplogi;
James Smart2e0fef82007-06-17 19:56:36 -0500624 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500625
James Smart2e0fef82007-06-17 19:56:36 -0500626 if (vport->num_disc_nodes)
627 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -0500628
629 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
630 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
631 "%d:0232 Continue discovery with %d PLOGIs to go "
632 "Data: x%x x%x x%x\n",
James Smart2e0fef82007-06-17 19:56:36 -0500633 phba->brd_no, vport->num_disc_nodes,
634 vport->fc_plogi_cnt, vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -0500635
636 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -0500637 if (vport->fc_flag & FC_NLP_MORE)
638 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
639 sentplogi = lpfc_els_disc_plogi(vport);
640
dea31012005-04-17 16:05:31 -0500641 return;
642}
643
James Smart488d1462006-03-07 15:02:37 -0500644static struct lpfc_nodelist *
James Smart685f0bf2007-04-25 09:53:08 -0400645lpfc_plogi_confirm_nport(struct lpfc_hba *phba, struct lpfc_dmabuf *prsp,
James Smart488d1462006-03-07 15:02:37 -0500646 struct lpfc_nodelist *ndlp)
647{
James Smart2e0fef82007-06-17 19:56:36 -0500648 struct lpfc_vport *vport = ndlp->vport;
James Smart488d1462006-03-07 15:02:37 -0500649 struct lpfc_nodelist *new_ndlp;
James Smart488d1462006-03-07 15:02:37 -0500650 uint32_t *lp;
651 struct serv_parm *sp;
652 uint8_t name[sizeof (struct lpfc_name)];
653 uint32_t rc;
654
James Smart2fb9bd82006-12-02 13:33:57 -0500655 /* Fabric nodes can have the same WWPN so we don't bother searching
656 * by WWPN. Just return the ndlp that was given to us.
657 */
658 if (ndlp->nlp_type & NLP_FABRIC)
659 return ndlp;
660
James Smart488d1462006-03-07 15:02:37 -0500661 lp = (uint32_t *) prsp->virt;
662 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
James Smart685f0bf2007-04-25 09:53:08 -0400663 memset(name, 0, sizeof(struct lpfc_name));
James Smart488d1462006-03-07 15:02:37 -0500664
James Smart685f0bf2007-04-25 09:53:08 -0400665 /* Now we find out if the NPort we are logging into, matches the WWPN
James Smart488d1462006-03-07 15:02:37 -0500666 * we have for that ndlp. If not, we have some work to do.
667 */
James Smart2e0fef82007-06-17 19:56:36 -0500668 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
James Smart488d1462006-03-07 15:02:37 -0500669
James Smart92795652006-07-06 15:50:02 -0400670 if (new_ndlp == ndlp)
James Smart488d1462006-03-07 15:02:37 -0500671 return ndlp;
James Smart488d1462006-03-07 15:02:37 -0500672
673 if (!new_ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -0500674 rc = memcmp(&ndlp->nlp_portname, name,
675 sizeof(struct lpfc_name));
James Smart92795652006-07-06 15:50:02 -0400676 if (!rc)
677 return ndlp;
James Smart488d1462006-03-07 15:02:37 -0500678 new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
679 if (!new_ndlp)
680 return ndlp;
681
James Smart2e0fef82007-06-17 19:56:36 -0500682 lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID);
James Smart488d1462006-03-07 15:02:37 -0500683 }
684
James Smart2e0fef82007-06-17 19:56:36 -0500685 lpfc_unreg_rpi(vport, new_ndlp);
James Smart488d1462006-03-07 15:02:37 -0500686 new_ndlp->nlp_DID = ndlp->nlp_DID;
James Smart92795652006-07-06 15:50:02 -0400687 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
James Smart2e0fef82007-06-17 19:56:36 -0500688 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
James Smart488d1462006-03-07 15:02:37 -0500689
James Smart2e0fef82007-06-17 19:56:36 -0500690 /* Move this back to NPR state */
James Smartde0c5b32007-04-25 09:52:27 -0400691 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0)
James Smart2e0fef82007-06-17 19:56:36 -0500692 lpfc_drop_node(vport, ndlp);
James Smart92795652006-07-06 15:50:02 -0400693 else {
James Smart2e0fef82007-06-17 19:56:36 -0500694 lpfc_unreg_rpi(vport, ndlp);
James Smart92795652006-07-06 15:50:02 -0400695 ndlp->nlp_DID = 0; /* Two ndlps cannot have the same did */
James Smart2e0fef82007-06-17 19:56:36 -0500696 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smart92795652006-07-06 15:50:02 -0400697 }
James Smart488d1462006-03-07 15:02:37 -0500698 return new_ndlp;
699}
700
dea31012005-04-17 16:05:31 -0500701static void
James Smart2e0fef82007-06-17 19:56:36 -0500702lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
703 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500704{
James Smart2e0fef82007-06-17 19:56:36 -0500705 struct lpfc_vport *vport = cmdiocb->vport;
706 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500707 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -0500708 struct lpfc_nodelist *ndlp;
James Smart92795652006-07-06 15:50:02 -0400709 struct lpfc_dmabuf *prsp;
dea31012005-04-17 16:05:31 -0500710 int disc, rc, did, type;
711
dea31012005-04-17 16:05:31 -0500712 /* we pass cmdiocb to state machine which needs rspiocb as well */
713 cmdiocb->context_un.rsp_iocb = rspiocb;
714
715 irsp = &rspiocb->iocb;
James Smart2e0fef82007-06-17 19:56:36 -0500716 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
James Smart488d1462006-03-07 15:02:37 -0500717 if (!ndlp)
718 goto out;
dea31012005-04-17 16:05:31 -0500719
720 /* Since ndlp can be freed in the disc state machine, note if this node
721 * is being used during discovery.
722 */
James Smart2e0fef82007-06-17 19:56:36 -0500723 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500724 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
James Smart488d1462006-03-07 15:02:37 -0500725 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500726 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500727 rc = 0;
728
729 /* PLOGI completes to NPort <nlp_DID> */
730 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
731 "%d:0102 PLOGI completes to NPort x%x "
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500732 "Data: x%x x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -0500733 phba->brd_no, ndlp->nlp_DID, irsp->ulpStatus,
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500734 irsp->un.ulpWord[4], irsp->ulpTimeout, disc,
James Smart2e0fef82007-06-17 19:56:36 -0500735 vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -0500736
737 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500738 if (lpfc_els_chk_latt(vport)) {
739 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500740 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500741 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500742 goto out;
743 }
744
745 /* ndlp could be freed in DSM, save these values now */
746 type = ndlp->nlp_type;
747 did = ndlp->nlp_DID;
748
749 if (irsp->ulpStatus) {
750 /* Check for retry */
751 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
752 /* ELS command is being retried */
753 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -0500754 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500755 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500756 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500757 }
758 goto out;
759 }
760
761 /* PLOGI failed */
762 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
763 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
764 ((irsp->un.ulpWord[4] == IOERR_SLI_ABORTED) ||
James.Smart@Emulex.Com6281bfe2005-11-28 11:41:33 -0500765 (irsp->un.ulpWord[4] == IOERR_LINK_DOWN) ||
dea31012005-04-17 16:05:31 -0500766 (irsp->un.ulpWord[4] == IOERR_SLI_DOWN))) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500767 rc = NLP_STE_FREED_NODE;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500768 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500769 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
dea31012005-04-17 16:05:31 -0500770 NLP_EVT_CMPL_PLOGI);
771 }
772 } else {
773 /* Good status, call state machine */
James Smart92795652006-07-06 15:50:02 -0400774 prsp = list_entry(((struct lpfc_dmabuf *)
775 cmdiocb->context2)->list.next,
776 struct lpfc_dmabuf, list);
777 ndlp = lpfc_plogi_confirm_nport(phba, prsp, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -0500778 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
dea31012005-04-17 16:05:31 -0500779 NLP_EVT_CMPL_PLOGI);
780 }
781
James Smart2e0fef82007-06-17 19:56:36 -0500782 if (disc && vport->num_disc_nodes) {
dea31012005-04-17 16:05:31 -0500783 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -0500784 lpfc_more_plogi(vport);
dea31012005-04-17 16:05:31 -0500785
James Smart2e0fef82007-06-17 19:56:36 -0500786 if (vport->num_disc_nodes == 0) {
787 spin_lock_irq(shost->host_lock);
788 vport->fc_flag &= ~FC_NDISC_ACTIVE;
789 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500790
James Smart2e0fef82007-06-17 19:56:36 -0500791 lpfc_can_disctmo(vport);
792 if (vport->fc_flag & FC_RSCN_MODE) {
James Smart10d4e952006-04-15 11:53:15 -0400793 /*
794 * Check to see if more RSCNs came in while
795 * we were processing this one.
796 */
James Smart2e0fef82007-06-17 19:56:36 -0500797 if ((vport->fc_rscn_id_cnt == 0) &&
798 (!(vport->fc_flag & FC_RSCN_DISCOVERY))) {
799 spin_lock_irq(shost->host_lock);
800 vport->fc_flag &= ~FC_RSCN_MODE;
801 spin_unlock_irq(shost->host_lock);
James Smart10d4e952006-04-15 11:53:15 -0400802 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500803 lpfc_els_handle_rscn(vport);
James Smart10d4e952006-04-15 11:53:15 -0400804 }
dea31012005-04-17 16:05:31 -0500805 }
806 }
807 }
808
809out:
810 lpfc_els_free_iocb(phba, cmdiocb);
811 return;
812}
813
814int
James Smart2e0fef82007-06-17 19:56:36 -0500815lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
dea31012005-04-17 16:05:31 -0500816{
James Smart2e0fef82007-06-17 19:56:36 -0500817 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500818 struct serv_parm *sp;
819 IOCB_t *icmd;
820 struct lpfc_iocbq *elsiocb;
821 struct lpfc_sli_ring *pring;
822 struct lpfc_sli *psli;
823 uint8_t *pcmd;
824 uint16_t cmdsize;
825
826 psli = &phba->sli;
827 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
828
829 cmdsize = (sizeof (uint32_t) + sizeof (struct serv_parm));
James Smart2e0fef82007-06-17 19:56:36 -0500830 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, NULL, did,
831 ELS_CMD_PLOGI);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500832 if (!elsiocb)
833 return 1;
dea31012005-04-17 16:05:31 -0500834
835 icmd = &elsiocb->iocb;
836 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
837
838 /* For PLOGI request, remainder of payload is service parameters */
839 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
840 pcmd += sizeof (uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -0500841 memcpy(pcmd, &vport->fc_sparam, sizeof (struct serv_parm));
dea31012005-04-17 16:05:31 -0500842 sp = (struct serv_parm *) pcmd;
843
844 if (sp->cmn.fcphLow < FC_PH_4_3)
845 sp->cmn.fcphLow = FC_PH_4_3;
846
847 if (sp->cmn.fcphHigh < FC_PH3)
848 sp->cmn.fcphHigh = FC_PH3;
849
850 phba->fc_stat.elsXmitPLOGI++;
851 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
dea31012005-04-17 16:05:31 -0500852 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
dea31012005-04-17 16:05:31 -0500853 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500854 return 1;
dea31012005-04-17 16:05:31 -0500855 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500856 return 0;
dea31012005-04-17 16:05:31 -0500857}
858
859static void
James Smart2e0fef82007-06-17 19:56:36 -0500860lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
861 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500862{
James Smart2e0fef82007-06-17 19:56:36 -0500863 struct lpfc_vport *vport = cmdiocb->vport;
864 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500865 IOCB_t *irsp;
866 struct lpfc_sli *psli;
867 struct lpfc_nodelist *ndlp;
868
869 psli = &phba->sli;
870 /* we pass cmdiocb to state machine which needs rspiocb as well */
871 cmdiocb->context_un.rsp_iocb = rspiocb;
872
873 irsp = &(rspiocb->iocb);
874 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
James Smart2e0fef82007-06-17 19:56:36 -0500875 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500876 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -0500877 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500878
879 /* PRLI completes to NPort <nlp_DID> */
880 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
881 "%d:0103 PRLI completes to NPort x%x "
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500882 "Data: x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -0500883 phba->brd_no, ndlp->nlp_DID, irsp->ulpStatus,
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500884 irsp->un.ulpWord[4], irsp->ulpTimeout,
James Smart2e0fef82007-06-17 19:56:36 -0500885 vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -0500886
James Smart2e0fef82007-06-17 19:56:36 -0500887 vport->fc_prli_sent--;
dea31012005-04-17 16:05:31 -0500888 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500889 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -0500890 goto out;
891
892 if (irsp->ulpStatus) {
893 /* Check for retry */
894 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
895 /* ELS command is being retried */
896 goto out;
897 }
898 /* PRLI failed */
899 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
900 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
901 ((irsp->un.ulpWord[4] == IOERR_SLI_ABORTED) ||
James.Smart@Emulex.Com6281bfe2005-11-28 11:41:33 -0500902 (irsp->un.ulpWord[4] == IOERR_LINK_DOWN) ||
dea31012005-04-17 16:05:31 -0500903 (irsp->un.ulpWord[4] == IOERR_SLI_DOWN))) {
904 goto out;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500905 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500906 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
dea31012005-04-17 16:05:31 -0500907 NLP_EVT_CMPL_PRLI);
908 }
909 } else {
910 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -0500911 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
912 NLP_EVT_CMPL_PRLI);
dea31012005-04-17 16:05:31 -0500913 }
914
915out:
916 lpfc_els_free_iocb(phba, cmdiocb);
917 return;
918}
919
920int
James Smart2e0fef82007-06-17 19:56:36 -0500921lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -0500922 uint8_t retry)
923{
James Smart2e0fef82007-06-17 19:56:36 -0500924 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
925 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500926 PRLI *npr;
927 IOCB_t *icmd;
928 struct lpfc_iocbq *elsiocb;
929 struct lpfc_sli_ring *pring;
930 struct lpfc_sli *psli;
931 uint8_t *pcmd;
932 uint16_t cmdsize;
933
934 psli = &phba->sli;
935 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
936
937 cmdsize = (sizeof (uint32_t) + sizeof (PRLI));
James Smart2e0fef82007-06-17 19:56:36 -0500938 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
939 ndlp->nlp_DID, ELS_CMD_PRLI);
James Smart488d1462006-03-07 15:02:37 -0500940 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500941 return 1;
dea31012005-04-17 16:05:31 -0500942
943 icmd = &elsiocb->iocb;
944 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
945
946 /* For PRLI request, remainder of payload is service parameters */
947 memset(pcmd, 0, (sizeof (PRLI) + sizeof (uint32_t)));
948 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
949 pcmd += sizeof (uint32_t);
950
951 /* For PRLI, remainder of payload is PRLI parameter page */
952 npr = (PRLI *) pcmd;
953 /*
954 * If our firmware version is 3.20 or later,
955 * set the following bits for FC-TAPE support.
956 */
957 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
958 npr->ConfmComplAllowed = 1;
959 npr->Retry = 1;
960 npr->TaskRetryIdReq = 1;
961 }
962 npr->estabImagePair = 1;
963 npr->readXferRdyDis = 1;
964
965 /* For FCP support */
966 npr->prliType = PRLI_FCP_TYPE;
967 npr->initiatorFunc = 1;
968
969 phba->fc_stat.elsXmitPRLI++;
970 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
James Smart2e0fef82007-06-17 19:56:36 -0500971 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500972 ndlp->nlp_flag |= NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -0500973 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500974 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -0500975 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500976 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -0500977 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500978 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500979 return 1;
dea31012005-04-17 16:05:31 -0500980 }
James Smart2e0fef82007-06-17 19:56:36 -0500981 vport->fc_prli_sent++;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500982 return 0;
dea31012005-04-17 16:05:31 -0500983}
984
985static void
James Smart2e0fef82007-06-17 19:56:36 -0500986lpfc_more_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -0500987{
988 int sentadisc;
James Smart2e0fef82007-06-17 19:56:36 -0500989 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500990
James Smart2e0fef82007-06-17 19:56:36 -0500991 if (vport->num_disc_nodes)
992 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -0500993
994 /* Continue discovery with <num_disc_nodes> ADISCs to go */
995 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
996 "%d:0210 Continue discovery with %d ADISCs to go "
997 "Data: x%x x%x x%x\n",
James Smart2e0fef82007-06-17 19:56:36 -0500998 phba->brd_no, vport->num_disc_nodes,
999 vport->fc_adisc_cnt, vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001000
1001 /* Check to see if there are more ADISCs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001002 if (vport->fc_flag & FC_NLP_MORE) {
1003 lpfc_set_disctmo(vport);
1004 /* go thru NPR nodes and issue any remaining ELS ADISCs */
1005 sentadisc = lpfc_els_disc_adisc(vport);
dea31012005-04-17 16:05:31 -05001006 }
1007 return;
1008}
1009
1010static void
James Smart2e0fef82007-06-17 19:56:36 -05001011lpfc_rscn_disc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001012{
James Smart2e0fef82007-06-17 19:56:36 -05001013 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1014
dea31012005-04-17 16:05:31 -05001015 /* RSCN discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001016 /* go thru NPR nodes and issue ELS PLOGIs */
1017 if (vport->fc_npr_cnt)
1018 if (lpfc_els_disc_plogi(vport))
dea31012005-04-17 16:05:31 -05001019 return;
James Smart2e0fef82007-06-17 19:56:36 -05001020
1021 if (vport->fc_flag & FC_RSCN_MODE) {
dea31012005-04-17 16:05:31 -05001022 /* Check to see if more RSCNs came in while we were
1023 * processing this one.
1024 */
James Smart2e0fef82007-06-17 19:56:36 -05001025 if ((vport->fc_rscn_id_cnt == 0) &&
1026 (!(vport->fc_flag & FC_RSCN_DISCOVERY))) {
1027 spin_lock_irq(shost->host_lock);
1028 vport->fc_flag &= ~FC_RSCN_MODE;
1029 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001030 } else {
James Smart2e0fef82007-06-17 19:56:36 -05001031 lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05001032 }
1033 }
1034}
1035
1036static void
James Smart2e0fef82007-06-17 19:56:36 -05001037lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1038 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001039{
James Smart2e0fef82007-06-17 19:56:36 -05001040 struct lpfc_vport *vport = cmdiocb->vport;
1041 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001042 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001043 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001044 int disc;
dea31012005-04-17 16:05:31 -05001045
1046 /* we pass cmdiocb to state machine which needs rspiocb as well */
1047 cmdiocb->context_un.rsp_iocb = rspiocb;
1048
1049 irsp = &(rspiocb->iocb);
1050 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
dea31012005-04-17 16:05:31 -05001051
1052 /* Since ndlp can be freed in the disc state machine, note if this node
1053 * is being used during discovery.
1054 */
James Smart2e0fef82007-06-17 19:56:36 -05001055 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001056 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001057 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001058 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001059
1060 /* ADISC completes to NPort <nlp_DID> */
1061 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1062 "%d:0104 ADISC completes to NPort x%x "
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001063 "Data: x%x x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -05001064 phba->brd_no, ndlp->nlp_DID, irsp->ulpStatus,
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001065 irsp->un.ulpWord[4], irsp->ulpTimeout, disc,
James Smart2e0fef82007-06-17 19:56:36 -05001066 vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001067
1068 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001069 if (lpfc_els_chk_latt(vport)) {
1070 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001071 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001072 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001073 goto out;
1074 }
1075
1076 if (irsp->ulpStatus) {
1077 /* Check for retry */
1078 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1079 /* ELS command is being retried */
1080 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05001081 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001082 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001083 spin_unlock_irq(shost->host_lock);
1084 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001085 }
1086 goto out;
1087 }
1088 /* ADISC failed */
1089 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001090 if ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
1091 ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) &&
1092 (irsp->un.ulpWord[4] != IOERR_LINK_DOWN) &&
1093 (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) {
James Smart2e0fef82007-06-17 19:56:36 -05001094 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
dea31012005-04-17 16:05:31 -05001095 NLP_EVT_CMPL_ADISC);
1096 }
1097 } else {
1098 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05001099 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
dea31012005-04-17 16:05:31 -05001100 NLP_EVT_CMPL_ADISC);
1101 }
1102
James Smart2e0fef82007-06-17 19:56:36 -05001103 if (disc && vport->num_disc_nodes) {
dea31012005-04-17 16:05:31 -05001104 /* Check to see if there are more ADISCs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001105 lpfc_more_adisc(vport);
dea31012005-04-17 16:05:31 -05001106
1107 /* Check to see if we are done with ADISC authentication */
James Smart2e0fef82007-06-17 19:56:36 -05001108 if (vport->num_disc_nodes == 0) {
1109 lpfc_can_disctmo(vport);
dea31012005-04-17 16:05:31 -05001110 /* If we get here, there is nothing left to wait for */
James Smart2e0fef82007-06-17 19:56:36 -05001111 if (vport->port_state < LPFC_VPORT_READY &&
1112 phba->link_state != LPFC_CLEAR_LA) {
1113 if (vport->port_type == LPFC_PHYSICAL_PORT) {
1114 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -05001115 }
1116 } else {
James Smart2e0fef82007-06-17 19:56:36 -05001117 lpfc_rscn_disc(vport);
dea31012005-04-17 16:05:31 -05001118 }
1119 }
1120 }
dea31012005-04-17 16:05:31 -05001121out:
1122 lpfc_els_free_iocb(phba, cmdiocb);
1123 return;
1124}
1125
1126int
James Smart2e0fef82007-06-17 19:56:36 -05001127lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001128 uint8_t retry)
1129{
James Smart2e0fef82007-06-17 19:56:36 -05001130 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1131 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001132 ADISC *ap;
1133 IOCB_t *icmd;
1134 struct lpfc_iocbq *elsiocb;
James Smart2e0fef82007-06-17 19:56:36 -05001135 struct lpfc_sli *psli = &phba->sli;
1136 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05001137 uint8_t *pcmd;
1138 uint16_t cmdsize;
1139
dea31012005-04-17 16:05:31 -05001140 cmdsize = (sizeof (uint32_t) + sizeof (ADISC));
James Smart2e0fef82007-06-17 19:56:36 -05001141 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1142 ndlp->nlp_DID, ELS_CMD_ADISC);
James Smart488d1462006-03-07 15:02:37 -05001143 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001144 return 1;
dea31012005-04-17 16:05:31 -05001145
1146 icmd = &elsiocb->iocb;
1147 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1148
1149 /* For ADISC request, remainder of payload is service parameters */
1150 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
1151 pcmd += sizeof (uint32_t);
1152
1153 /* Fill in ADISC payload */
1154 ap = (ADISC *) pcmd;
1155 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart2e0fef82007-06-17 19:56:36 -05001156 memcpy(&ap->portName, &vport->fc_portname, sizeof (struct lpfc_name));
1157 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof (struct lpfc_name));
1158 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05001159
1160 phba->fc_stat.elsXmitADISC++;
1161 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
James Smart2e0fef82007-06-17 19:56:36 -05001162 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001163 ndlp->nlp_flag |= NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001164 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001165 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05001166 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001167 ndlp->nlp_flag &= ~NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001168 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001169 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001170 return 1;
dea31012005-04-17 16:05:31 -05001171 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001172 return 0;
dea31012005-04-17 16:05:31 -05001173}
1174
1175static void
James Smart2e0fef82007-06-17 19:56:36 -05001176lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1177 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001178{
James Smart2e0fef82007-06-17 19:56:36 -05001179 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1180 struct lpfc_vport *vport = ndlp->vport;
1181 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001182 IOCB_t *irsp;
1183 struct lpfc_sli *psli;
dea31012005-04-17 16:05:31 -05001184
1185 psli = &phba->sli;
1186 /* we pass cmdiocb to state machine which needs rspiocb as well */
1187 cmdiocb->context_un.rsp_iocb = rspiocb;
1188
1189 irsp = &(rspiocb->iocb);
James Smart2e0fef82007-06-17 19:56:36 -05001190 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001191 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001192 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001193
1194 /* LOGO completes to NPort <nlp_DID> */
1195 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1196 "%d:0105 LOGO completes to NPort x%x "
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001197 "Data: x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -05001198 phba->brd_no, ndlp->nlp_DID, irsp->ulpStatus,
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001199 irsp->un.ulpWord[4], irsp->ulpTimeout,
James Smart2e0fef82007-06-17 19:56:36 -05001200 vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001201
1202 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001203 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05001204 goto out;
1205
1206 if (irsp->ulpStatus) {
1207 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -05001208 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -05001209 /* ELS command is being retried */
1210 goto out;
dea31012005-04-17 16:05:31 -05001211 /* LOGO failed */
1212 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1213 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
1214 ((irsp->un.ulpWord[4] == IOERR_SLI_ABORTED) ||
James.Smart@Emulex.Com6281bfe2005-11-28 11:41:33 -05001215 (irsp->un.ulpWord[4] == IOERR_LINK_DOWN) ||
dea31012005-04-17 16:05:31 -05001216 (irsp->un.ulpWord[4] == IOERR_SLI_DOWN))) {
1217 goto out;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001218 } else {
James Smart2e0fef82007-06-17 19:56:36 -05001219 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
dea31012005-04-17 16:05:31 -05001220 NLP_EVT_CMPL_LOGO);
1221 }
1222 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001223 /* Good status, call state machine.
1224 * This will unregister the rpi if needed.
1225 */
James Smart2e0fef82007-06-17 19:56:36 -05001226 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1227 NLP_EVT_CMPL_LOGO);
dea31012005-04-17 16:05:31 -05001228 }
1229
1230out:
1231 lpfc_els_free_iocb(phba, cmdiocb);
1232 return;
1233}
1234
1235int
James Smart2e0fef82007-06-17 19:56:36 -05001236lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001237 uint8_t retry)
1238{
James Smart2e0fef82007-06-17 19:56:36 -05001239 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1240 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001241 IOCB_t *icmd;
1242 struct lpfc_iocbq *elsiocb;
1243 struct lpfc_sli_ring *pring;
1244 struct lpfc_sli *psli;
1245 uint8_t *pcmd;
1246 uint16_t cmdsize;
1247
1248 psli = &phba->sli;
1249 pring = &psli->ring[LPFC_ELS_RING];
1250
James Smart10d4e952006-04-15 11:53:15 -04001251 cmdsize = (2 * sizeof (uint32_t)) + sizeof (struct lpfc_name);
James Smart2e0fef82007-06-17 19:56:36 -05001252 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1253 ndlp->nlp_DID, ELS_CMD_LOGO);
James Smart488d1462006-03-07 15:02:37 -05001254 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001255 return 1;
dea31012005-04-17 16:05:31 -05001256
1257 icmd = &elsiocb->iocb;
1258 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1259 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
1260 pcmd += sizeof (uint32_t);
1261
1262 /* Fill in LOGO payload */
James Smart2e0fef82007-06-17 19:56:36 -05001263 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05001264 pcmd += sizeof (uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05001265 memcpy(pcmd, &vport->fc_portname, sizeof (struct lpfc_name));
dea31012005-04-17 16:05:31 -05001266
1267 phba->fc_stat.elsXmitLOGO++;
1268 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
James Smart2e0fef82007-06-17 19:56:36 -05001269 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001270 ndlp->nlp_flag |= NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001271 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001272 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05001273 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001274 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001275 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001276 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001277 return 1;
dea31012005-04-17 16:05:31 -05001278 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001279 return 0;
dea31012005-04-17 16:05:31 -05001280}
1281
1282static void
James Smart2e0fef82007-06-17 19:56:36 -05001283lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1284 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001285{
James Smart2e0fef82007-06-17 19:56:36 -05001286 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -05001287 IOCB_t *irsp;
1288
1289 irsp = &rspiocb->iocb;
1290
1291 /* ELS cmd tag <ulpIoTag> completes */
1292 lpfc_printf_log(phba,
1293 KERN_INFO,
1294 LOG_ELS,
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001295 "%d:0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -05001296 phba->brd_no,
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001297 irsp->ulpIoTag, irsp->ulpStatus,
1298 irsp->un.ulpWord[4], irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -05001299
1300 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001301 lpfc_els_chk_latt(vport);
dea31012005-04-17 16:05:31 -05001302 lpfc_els_free_iocb(phba, cmdiocb);
1303 return;
1304}
1305
1306int
James Smart2e0fef82007-06-17 19:56:36 -05001307lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05001308{
James Smart2e0fef82007-06-17 19:56:36 -05001309 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001310 IOCB_t *icmd;
1311 struct lpfc_iocbq *elsiocb;
1312 struct lpfc_sli_ring *pring;
1313 struct lpfc_sli *psli;
1314 uint8_t *pcmd;
1315 uint16_t cmdsize;
1316 struct lpfc_nodelist *ndlp;
1317
1318 psli = &phba->sli;
1319 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1320 cmdsize = (sizeof (uint32_t) + sizeof (SCR));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001321 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1322 if (!ndlp)
1323 return 1;
dea31012005-04-17 16:05:31 -05001324
James Smart2e0fef82007-06-17 19:56:36 -05001325 lpfc_nlp_init(vport, ndlp, nportid);
dea31012005-04-17 16:05:31 -05001326
James Smart2e0fef82007-06-17 19:56:36 -05001327 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1328 ndlp->nlp_DID, ELS_CMD_SCR);
1329
James Smart488d1462006-03-07 15:02:37 -05001330 if (!elsiocb) {
James Smart329f9bc2007-04-25 09:53:01 -04001331 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001332 return 1;
dea31012005-04-17 16:05:31 -05001333 }
1334
1335 icmd = &elsiocb->iocb;
1336 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1337
1338 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
1339 pcmd += sizeof (uint32_t);
1340
1341 /* For SCR, remainder of payload is SCR parameter page */
1342 memset(pcmd, 0, sizeof (SCR));
1343 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
1344
1345 phba->fc_stat.elsXmitSCR++;
1346 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
dea31012005-04-17 16:05:31 -05001347 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
James Smart329f9bc2007-04-25 09:53:01 -04001348 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001349 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001350 return 1;
dea31012005-04-17 16:05:31 -05001351 }
James Smart329f9bc2007-04-25 09:53:01 -04001352 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001353 return 0;
dea31012005-04-17 16:05:31 -05001354}
1355
1356static int
James Smart2e0fef82007-06-17 19:56:36 -05001357lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05001358{
James Smart2e0fef82007-06-17 19:56:36 -05001359 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001360 IOCB_t *icmd;
1361 struct lpfc_iocbq *elsiocb;
1362 struct lpfc_sli_ring *pring;
1363 struct lpfc_sli *psli;
1364 FARP *fp;
1365 uint8_t *pcmd;
1366 uint32_t *lp;
1367 uint16_t cmdsize;
1368 struct lpfc_nodelist *ondlp;
1369 struct lpfc_nodelist *ndlp;
1370
1371 psli = &phba->sli;
1372 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1373 cmdsize = (sizeof (uint32_t) + sizeof (FARP));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001374 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1375 if (!ndlp)
1376 return 1;
dea31012005-04-17 16:05:31 -05001377
James Smart2e0fef82007-06-17 19:56:36 -05001378 lpfc_nlp_init(vport, ndlp, nportid);
1379
1380 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1381 ndlp->nlp_DID, ELS_CMD_RNID);
James Smart488d1462006-03-07 15:02:37 -05001382 if (!elsiocb) {
James Smart329f9bc2007-04-25 09:53:01 -04001383 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001384 return 1;
dea31012005-04-17 16:05:31 -05001385 }
1386
1387 icmd = &elsiocb->iocb;
1388 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1389
1390 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
1391 pcmd += sizeof (uint32_t);
1392
1393 /* Fill in FARPR payload */
1394 fp = (FARP *) (pcmd);
1395 memset(fp, 0, sizeof (FARP));
1396 lp = (uint32_t *) pcmd;
1397 *lp++ = be32_to_cpu(nportid);
James Smart2e0fef82007-06-17 19:56:36 -05001398 *lp++ = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05001399 fp->Rflags = 0;
1400 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
1401
James Smart2e0fef82007-06-17 19:56:36 -05001402 memcpy(&fp->RportName, &vport->fc_portname, sizeof (struct lpfc_name));
1403 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof (struct lpfc_name));
1404 ondlp = lpfc_findnode_did(vport, nportid);
1405 if (ondlp) {
dea31012005-04-17 16:05:31 -05001406 memcpy(&fp->OportName, &ondlp->nlp_portname,
1407 sizeof (struct lpfc_name));
1408 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
1409 sizeof (struct lpfc_name));
1410 }
1411
1412 phba->fc_stat.elsXmitFARPR++;
1413 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
dea31012005-04-17 16:05:31 -05001414 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
James Smart329f9bc2007-04-25 09:53:01 -04001415 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001416 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001417 return 1;
dea31012005-04-17 16:05:31 -05001418 }
James Smart329f9bc2007-04-25 09:53:01 -04001419 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001420 return 0;
dea31012005-04-17 16:05:31 -05001421}
1422
1423void
James Smart2e0fef82007-06-17 19:56:36 -05001424lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
James Smartfdcebe22006-03-07 15:04:01 -05001425{
James Smart2e0fef82007-06-17 19:56:36 -05001426 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1427
1428 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05001429 nlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001430 spin_unlock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05001431 del_timer_sync(&nlp->nlp_delayfunc);
1432 nlp->nlp_last_elscmd = 0;
1433
1434 if (!list_empty(&nlp->els_retry_evt.evt_listp))
1435 list_del_init(&nlp->els_retry_evt.evt_listp);
1436
1437 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
James Smart2e0fef82007-06-17 19:56:36 -05001438 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05001439 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001440 spin_unlock_irq(shost->host_lock);
1441 if (vport->num_disc_nodes) {
James Smartfdcebe22006-03-07 15:04:01 -05001442 /* Check to see if there are more
1443 * PLOGIs to be sent
1444 */
James Smart2e0fef82007-06-17 19:56:36 -05001445 lpfc_more_plogi(vport);
James Smartfdcebe22006-03-07 15:04:01 -05001446
James Smart2e0fef82007-06-17 19:56:36 -05001447 if (vport->num_disc_nodes == 0) {
1448 spin_lock_irq(shost->host_lock);
1449 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1450 spin_unlock_irq(shost->host_lock);
1451 lpfc_can_disctmo(vport);
1452 if (vport->fc_flag & FC_RSCN_MODE) {
James Smart10d4e952006-04-15 11:53:15 -04001453 /*
1454 * Check to see if more RSCNs
1455 * came in while we were
1456 * processing this one.
1457 */
James Smart2e0fef82007-06-17 19:56:36 -05001458 if (!vport->fc_rscn_id_cnt &&
1459 !(vport->fc_flag &
1460 FC_RSCN_DISCOVERY)) {
1461 spin_lock_irq(shost->host_lock);
1462 vport->fc_flag &= ~FC_RSCN_MODE;
1463 spin_unlock_irq(
1464 shost->host_lock);
James Smart10d4e952006-04-15 11:53:15 -04001465 }
1466 else {
James Smart2e0fef82007-06-17 19:56:36 -05001467 lpfc_els_handle_rscn(vport);
James Smart10d4e952006-04-15 11:53:15 -04001468 }
James Smartfdcebe22006-03-07 15:04:01 -05001469 }
1470 }
1471 }
1472 }
1473 return;
1474}
1475
1476void
dea31012005-04-17 16:05:31 -05001477lpfc_els_retry_delay(unsigned long ptr)
1478{
James Smart2e0fef82007-06-17 19:56:36 -05001479 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
1480 struct lpfc_vport *vport = ndlp->vport;
1481 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1482 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001483 unsigned long iflag;
James Smart2e0fef82007-06-17 19:56:36 -05001484 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
dea31012005-04-17 16:05:31 -05001485
James Smart2e0fef82007-06-17 19:56:36 -05001486 ndlp = (struct lpfc_nodelist *) ptr;
1487 phba = ndlp->vport->phba;
dea31012005-04-17 16:05:31 -05001488 evtp = &ndlp->els_retry_evt;
1489
James Smart2e0fef82007-06-17 19:56:36 -05001490 spin_lock_irqsave(shost->host_lock, iflag);
dea31012005-04-17 16:05:31 -05001491 if (!list_empty(&evtp->evt_listp)) {
James Smart2e0fef82007-06-17 19:56:36 -05001492 spin_unlock_irqrestore(shost->host_lock, iflag);
dea31012005-04-17 16:05:31 -05001493 return;
1494 }
1495
1496 evtp->evt_arg1 = ndlp;
1497 evtp->evt = LPFC_EVT_ELS_RETRY;
1498 list_add_tail(&evtp->evt_listp, &phba->work_list);
1499 if (phba->work_wait)
1500 wake_up(phba->work_wait);
1501
James Smart2e0fef82007-06-17 19:56:36 -05001502 spin_unlock_irqrestore(shost->host_lock, iflag);
dea31012005-04-17 16:05:31 -05001503 return;
1504}
1505
1506void
1507lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
1508{
James Smart2e0fef82007-06-17 19:56:36 -05001509 struct lpfc_vport *vport = ndlp->vport;
1510 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1511 uint32_t cmd, did, retry;
dea31012005-04-17 16:05:31 -05001512
James Smart2e0fef82007-06-17 19:56:36 -05001513 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001514 did = ndlp->nlp_DID;
1515 cmd = ndlp->nlp_last_elscmd;
1516 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05001517
1518 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
James Smart2e0fef82007-06-17 19:56:36 -05001519 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001520 return;
1521 }
1522
1523 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001524 spin_unlock_irq(shost->host_lock);
James Smart1a169682006-03-07 15:04:06 -05001525 /*
1526 * If a discovery event readded nlp_delayfunc after timer
1527 * firing and before processing the timer, cancel the
1528 * nlp_delayfunc.
1529 */
1530 del_timer_sync(&ndlp->nlp_delayfunc);
dea31012005-04-17 16:05:31 -05001531 retry = ndlp->nlp_retry;
1532
1533 switch (cmd) {
1534 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05001535 lpfc_issue_els_flogi(vport, ndlp, retry);
dea31012005-04-17 16:05:31 -05001536 break;
1537 case ELS_CMD_PLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05001538 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001539 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001540 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05001541 }
dea31012005-04-17 16:05:31 -05001542 break;
1543 case ELS_CMD_ADISC:
James Smart2e0fef82007-06-17 19:56:36 -05001544 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001545 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001546 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05001547 }
dea31012005-04-17 16:05:31 -05001548 break;
1549 case ELS_CMD_PRLI:
James Smart2e0fef82007-06-17 19:56:36 -05001550 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001551 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001552 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05001553 }
dea31012005-04-17 16:05:31 -05001554 break;
1555 case ELS_CMD_LOGO:
James Smart2e0fef82007-06-17 19:56:36 -05001556 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001557 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001558 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05001559 }
dea31012005-04-17 16:05:31 -05001560 break;
1561 }
1562 return;
1563}
1564
1565static int
James Smart2e0fef82007-06-17 19:56:36 -05001566lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1567 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001568{
James Smart2e0fef82007-06-17 19:56:36 -05001569 struct lpfc_vport *vport = cmdiocb->vport;
1570 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1571 IOCB_t *irsp = &rspiocb->iocb;
1572 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1573 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
dea31012005-04-17 16:05:31 -05001574 uint32_t *elscmd;
1575 struct ls_rjt stat;
James Smart2e0fef82007-06-17 19:56:36 -05001576 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
1577 uint32_t cmd = 0;
James Smart488d1462006-03-07 15:02:37 -05001578 uint32_t did;
dea31012005-04-17 16:05:31 -05001579
James Smart488d1462006-03-07 15:02:37 -05001580
dea31012005-04-17 16:05:31 -05001581 /* Note: context2 may be 0 for internal driver abort
1582 * of delays ELS command.
1583 */
1584
1585 if (pcmd && pcmd->virt) {
1586 elscmd = (uint32_t *) (pcmd->virt);
1587 cmd = *elscmd++;
1588 }
1589
James Smart329f9bc2007-04-25 09:53:01 -04001590 if (ndlp)
James Smart488d1462006-03-07 15:02:37 -05001591 did = ndlp->nlp_DID;
1592 else {
1593 /* We should only hit this case for retrying PLOGI */
1594 did = irsp->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05001595 ndlp = lpfc_findnode_did(vport, did);
James Smart488d1462006-03-07 15:02:37 -05001596 if (!ndlp && (cmd != ELS_CMD_PLOGI))
1597 return 1;
1598 }
1599
dea31012005-04-17 16:05:31 -05001600 switch (irsp->ulpStatus) {
1601 case IOSTAT_FCP_RSP_ERROR:
1602 case IOSTAT_REMOTE_STOP:
1603 break;
1604
1605 case IOSTAT_LOCAL_REJECT:
1606 switch ((irsp->un.ulpWord[4] & 0xff)) {
1607 case IOERR_LOOP_OPEN_FAILURE:
James Smart2e0fef82007-06-17 19:56:36 -05001608 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
dea31012005-04-17 16:05:31 -05001609 delay = 1;
dea31012005-04-17 16:05:31 -05001610 retry = 1;
1611 break;
1612
1613 case IOERR_SEQUENCE_TIMEOUT:
1614 retry = 1;
dea31012005-04-17 16:05:31 -05001615 break;
1616
1617 case IOERR_NO_RESOURCES:
James Smart2e0fef82007-06-17 19:56:36 -05001618 if (cmd == ELS_CMD_PLOGI)
dea31012005-04-17 16:05:31 -05001619 delay = 1;
dea31012005-04-17 16:05:31 -05001620 retry = 1;
1621 break;
1622
1623 case IOERR_INVALID_RPI:
1624 retry = 1;
1625 break;
1626 }
1627 break;
1628
1629 case IOSTAT_NPORT_RJT:
1630 case IOSTAT_FABRIC_RJT:
1631 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
1632 retry = 1;
1633 break;
1634 }
1635 break;
1636
1637 case IOSTAT_NPORT_BSY:
1638 case IOSTAT_FABRIC_BSY:
1639 retry = 1;
1640 break;
1641
1642 case IOSTAT_LS_RJT:
1643 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
1644 /* Added for Vendor specifc support
1645 * Just keep retrying for these Rsn / Exp codes
1646 */
1647 switch (stat.un.b.lsRjtRsnCode) {
1648 case LSRJT_UNABLE_TPC:
1649 if (stat.un.b.lsRjtRsnCodeExp ==
1650 LSEXP_CMD_IN_PROGRESS) {
1651 if (cmd == ELS_CMD_PLOGI) {
1652 delay = 1;
1653 maxretry = 48;
1654 }
1655 retry = 1;
1656 break;
1657 }
1658 if (cmd == ELS_CMD_PLOGI) {
1659 delay = 1;
1660 maxretry = lpfc_max_els_tries + 1;
1661 retry = 1;
1662 break;
1663 }
1664 break;
1665
1666 case LSRJT_LOGICAL_BSY:
1667 if (cmd == ELS_CMD_PLOGI) {
1668 delay = 1;
1669 maxretry = 48;
1670 }
1671 retry = 1;
1672 break;
1673 }
1674 break;
1675
1676 case IOSTAT_INTERMED_RSP:
1677 case IOSTAT_BA_RJT:
1678 break;
1679
1680 default:
1681 break;
1682 }
1683
James Smart488d1462006-03-07 15:02:37 -05001684 if (did == FDMI_DID)
dea31012005-04-17 16:05:31 -05001685 retry = 1;
dea31012005-04-17 16:05:31 -05001686
1687 if ((++cmdiocb->retry) >= maxretry) {
1688 phba->fc_stat.elsRetryExceeded++;
1689 retry = 0;
1690 }
1691
1692 if (retry) {
1693
1694 /* Retry ELS command <elsCmd> to remote NPORT <did> */
1695 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1696 "%d:0107 Retry ELS command x%x to remote "
1697 "NPORT x%x Data: x%x x%x\n",
1698 phba->brd_no,
James Smart488d1462006-03-07 15:02:37 -05001699 cmd, did, cmdiocb->retry, delay);
dea31012005-04-17 16:05:31 -05001700
1701 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) {
1702 /* If discovery / RSCN timer is running, reset it */
James Smart2e0fef82007-06-17 19:56:36 -05001703 if (timer_pending(&vport->fc_disctmo) ||
1704 (vport->fc_flag & FC_RSCN_MODE))
1705 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001706 }
1707
1708 phba->fc_stat.elsXmitRetry++;
James Smart488d1462006-03-07 15:02:37 -05001709 if (ndlp && delay) {
dea31012005-04-17 16:05:31 -05001710 phba->fc_stat.elsDelayRetry++;
1711 ndlp->nlp_retry = cmdiocb->retry;
1712
1713 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
James Smart2e0fef82007-06-17 19:56:36 -05001714 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001715 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001716 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001717
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001718 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001719 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05001720 ndlp->nlp_last_elscmd = cmd;
1721
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001722 return 1;
dea31012005-04-17 16:05:31 -05001723 }
1724 switch (cmd) {
1725 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05001726 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001727 return 1;
dea31012005-04-17 16:05:31 -05001728 case ELS_CMD_PLOGI:
James Smart488d1462006-03-07 15:02:37 -05001729 if (ndlp) {
1730 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001731 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04001732 NLP_STE_PLOGI_ISSUE);
James Smart488d1462006-03-07 15:02:37 -05001733 }
James Smart2e0fef82007-06-17 19:56:36 -05001734 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001735 return 1;
dea31012005-04-17 16:05:31 -05001736 case ELS_CMD_ADISC:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001737 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001738 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
1739 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001740 return 1;
dea31012005-04-17 16:05:31 -05001741 case ELS_CMD_PRLI:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001742 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001743 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
1744 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001745 return 1;
dea31012005-04-17 16:05:31 -05001746 case ELS_CMD_LOGO:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001747 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001748 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1749 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001750 return 1;
dea31012005-04-17 16:05:31 -05001751 }
1752 }
1753
1754 /* No retry ELS command <elsCmd> to remote NPORT <did> */
1755 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1756 "%d:0108 No retry ELS command x%x to remote NPORT x%x "
James Smart488d1462006-03-07 15:02:37 -05001757 "Data: x%x\n",
dea31012005-04-17 16:05:31 -05001758 phba->brd_no,
James Smart488d1462006-03-07 15:02:37 -05001759 cmd, did, cmdiocb->retry);
dea31012005-04-17 16:05:31 -05001760
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001761 return 0;
dea31012005-04-17 16:05:31 -05001762}
1763
1764int
James Smart329f9bc2007-04-25 09:53:01 -04001765lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05001766{
1767 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
1768
James Smart329f9bc2007-04-25 09:53:01 -04001769 if (elsiocb->context1) {
1770 lpfc_nlp_put(elsiocb->context1);
1771 elsiocb->context1 = NULL;
1772 }
dea31012005-04-17 16:05:31 -05001773 /* context2 = cmd, context2->next = rsp, context3 = bpl */
1774 if (elsiocb->context2) {
1775 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
1776 /* Free the response before processing the command. */
1777 if (!list_empty(&buf_ptr1->list)) {
1778 list_remove_head(&buf_ptr1->list, buf_ptr,
1779 struct lpfc_dmabuf,
1780 list);
1781 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
1782 kfree(buf_ptr);
1783 }
1784 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
1785 kfree(buf_ptr1);
1786 }
1787
1788 if (elsiocb->context3) {
1789 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
1790 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
1791 kfree(buf_ptr);
1792 }
James Bottomley604a3e32005-10-29 10:28:33 -05001793 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -05001794 return 0;
1795}
1796
1797static void
James Smart2e0fef82007-06-17 19:56:36 -05001798lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1799 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001800{
James Smart2e0fef82007-06-17 19:56:36 -05001801 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1802 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -05001803
1804 /* ACC to LOGO completes to NPort <nlp_DID> */
1805 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1806 "%d:0109 ACC to LOGO completes to NPort x%x "
1807 "Data: x%x x%x x%x\n",
1808 phba->brd_no, ndlp->nlp_DID, ndlp->nlp_flag,
1809 ndlp->nlp_state, ndlp->nlp_rpi);
1810
dea31012005-04-17 16:05:31 -05001811 switch (ndlp->nlp_state) {
1812 case NLP_STE_UNUSED_NODE: /* node is just allocated */
James Smart2e0fef82007-06-17 19:56:36 -05001813 lpfc_drop_node(vport, ndlp);
dea31012005-04-17 16:05:31 -05001814 break;
1815 case NLP_STE_NPR_NODE: /* NPort Recovery mode */
James Smart2e0fef82007-06-17 19:56:36 -05001816 lpfc_unreg_rpi(vport, ndlp);
dea31012005-04-17 16:05:31 -05001817 break;
1818 default:
1819 break;
1820 }
1821 lpfc_els_free_iocb(phba, cmdiocb);
1822 return;
1823}
1824
1825static void
James Smart329f9bc2007-04-25 09:53:01 -04001826lpfc_cmpl_els_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1827 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001828{
James Smart2e0fef82007-06-17 19:56:36 -05001829 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1830 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
1831 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
James Smart33ccf8d2006-08-17 11:57:58 -04001832 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001833 LPFC_MBOXQ_t *mbox = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05001834 struct lpfc_dmabuf *mp = NULL;
dea31012005-04-17 16:05:31 -05001835
James Smart33ccf8d2006-08-17 11:57:58 -04001836 irsp = &rspiocb->iocb;
1837
dea31012005-04-17 16:05:31 -05001838 if (cmdiocb->context_un.mbox)
1839 mbox = cmdiocb->context_un.mbox;
1840
dea31012005-04-17 16:05:31 -05001841 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001842 if (!ndlp || lpfc_els_chk_latt(vport)) {
dea31012005-04-17 16:05:31 -05001843 if (mbox) {
James Smart14691152006-12-02 13:34:28 -05001844 mp = (struct lpfc_dmabuf *) mbox->context1;
1845 if (mp) {
1846 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1847 kfree(mp);
1848 }
James Smart329f9bc2007-04-25 09:53:01 -04001849 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05001850 }
1851 goto out;
1852 }
1853
1854 /* ELS response tag <ulpIoTag> completes */
1855 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1856 "%d:0110 ELS response tag x%x completes "
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001857 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -05001858 phba->brd_no,
1859 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001860 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
James Smart2e0fef82007-06-17 19:56:36 -05001861 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001862 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05001863
1864 if (mbox) {
1865 if ((rspiocb->iocb.ulpStatus == 0)
1866 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
James Smart2e0fef82007-06-17 19:56:36 -05001867 lpfc_unreg_rpi(vport, ndlp);
dea31012005-04-17 16:05:31 -05001868 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
James Smart329f9bc2007-04-25 09:53:01 -04001869 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05001870 mbox->vport = vport;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001871 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001872 lpfc_nlp_set_state(vport, ndlp,
1873 NLP_STE_REG_LOGIN_ISSUE);
dea31012005-04-17 16:05:31 -05001874 if (lpfc_sli_issue_mbox(phba, mbox,
1875 (MBX_NOWAIT | MBX_STOP_IOCB))
1876 != MBX_NOT_FINISHED) {
1877 goto out;
1878 }
James Smart329f9bc2007-04-25 09:53:01 -04001879 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001880 /* NOTE: we should have messages for unsuccessful
1881 reglogin */
dea31012005-04-17 16:05:31 -05001882 } else {
James Smart33ccf8d2006-08-17 11:57:58 -04001883 /* Do not call NO_LIST for lpfc_els_abort'ed ELS cmds */
1884 if (!((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
1885 ((irsp->un.ulpWord[4] == IOERR_SLI_ABORTED) ||
1886 (irsp->un.ulpWord[4] == IOERR_LINK_DOWN) ||
1887 (irsp->un.ulpWord[4] == IOERR_SLI_DOWN)))) {
1888 if (ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
James Smart2e0fef82007-06-17 19:56:36 -05001889 lpfc_drop_node(vport, ndlp);
James Smart33ccf8d2006-08-17 11:57:58 -04001890 ndlp = NULL;
1891 }
dea31012005-04-17 16:05:31 -05001892 }
1893 }
James Smart14691152006-12-02 13:34:28 -05001894 mp = (struct lpfc_dmabuf *) mbox->context1;
1895 if (mp) {
1896 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1897 kfree(mp);
1898 }
1899 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05001900 }
1901out:
1902 if (ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05001903 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001904 ndlp->nlp_flag &= ~NLP_ACC_REGLOGIN;
James Smart2e0fef82007-06-17 19:56:36 -05001905 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001906 }
1907 lpfc_els_free_iocb(phba, cmdiocb);
1908 return;
1909}
1910
1911int
James Smart2e0fef82007-06-17 19:56:36 -05001912lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
1913 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
1914 LPFC_MBOXQ_t *mbox, uint8_t newnode)
dea31012005-04-17 16:05:31 -05001915{
James Smart2e0fef82007-06-17 19:56:36 -05001916 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1917 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001918 IOCB_t *icmd;
1919 IOCB_t *oldcmd;
1920 struct lpfc_iocbq *elsiocb;
1921 struct lpfc_sli_ring *pring;
1922 struct lpfc_sli *psli;
1923 uint8_t *pcmd;
1924 uint16_t cmdsize;
1925 int rc;
James Smart82d9a2a2006-04-15 11:53:05 -04001926 ELS_PKT *els_pkt_ptr;
dea31012005-04-17 16:05:31 -05001927
1928 psli = &phba->sli;
1929 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1930 oldcmd = &oldiocb->iocb;
1931
1932 switch (flag) {
1933 case ELS_CMD_ACC:
1934 cmdsize = sizeof (uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05001935 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
1936 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05001937 if (!elsiocb) {
James Smart2e0fef82007-06-17 19:56:36 -05001938 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001939 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05001940 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001941 return 1;
dea31012005-04-17 16:05:31 -05001942 }
James Smart2e0fef82007-06-17 19:56:36 -05001943
dea31012005-04-17 16:05:31 -05001944 icmd = &elsiocb->iocb;
1945 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
1946 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1947 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
1948 pcmd += sizeof (uint32_t);
1949 break;
1950 case ELS_CMD_PLOGI:
1951 cmdsize = (sizeof (struct serv_parm) + sizeof (uint32_t));
James Smart2e0fef82007-06-17 19:56:36 -05001952 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
1953 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05001954 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001955 return 1;
James Smart488d1462006-03-07 15:02:37 -05001956
dea31012005-04-17 16:05:31 -05001957 icmd = &elsiocb->iocb;
1958 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
1959 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1960
1961 if (mbox)
1962 elsiocb->context_un.mbox = mbox;
1963
1964 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
1965 pcmd += sizeof (uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05001966 memcpy(pcmd, &vport->fc_sparam, sizeof (struct serv_parm));
dea31012005-04-17 16:05:31 -05001967 break;
James Smart82d9a2a2006-04-15 11:53:05 -04001968 case ELS_CMD_PRLO:
1969 cmdsize = sizeof (uint32_t) + sizeof (PRLO);
James Smart2e0fef82007-06-17 19:56:36 -05001970 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
James Smart82d9a2a2006-04-15 11:53:05 -04001971 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
1972 if (!elsiocb)
1973 return 1;
1974
1975 icmd = &elsiocb->iocb;
1976 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
1977 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1978
1979 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
1980 sizeof (uint32_t) + sizeof (PRLO));
1981 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
1982 els_pkt_ptr = (ELS_PKT *) pcmd;
1983 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
1984 break;
dea31012005-04-17 16:05:31 -05001985 default:
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001986 return 1;
dea31012005-04-17 16:05:31 -05001987 }
1988
James Smart329f9bc2007-04-25 09:53:01 -04001989 if (newnode) {
1990 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001991 elsiocb->context1 = NULL;
James Smart329f9bc2007-04-25 09:53:01 -04001992 }
dea31012005-04-17 16:05:31 -05001993
1994 /* Xmit ELS ACC response tag <ulpIoTag> */
1995 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
James Smart1dcb58e2007-04-25 09:51:30 -04001996 "%d:0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
1997 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n",
1998 phba->brd_no, elsiocb->iotag,
dea31012005-04-17 16:05:31 -05001999 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
2000 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
2001
2002 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
James Smart2e0fef82007-06-17 19:56:36 -05002003 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002004 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05002005 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002006 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
2007 } else {
2008 elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
2009 }
2010
2011 phba->fc_stat.elsXmitACC++;
dea31012005-04-17 16:05:31 -05002012 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
dea31012005-04-17 16:05:31 -05002013 if (rc == IOCB_ERROR) {
2014 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002015 return 1;
dea31012005-04-17 16:05:31 -05002016 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002017 return 0;
dea31012005-04-17 16:05:31 -05002018}
2019
2020int
James Smart2e0fef82007-06-17 19:56:36 -05002021lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
2022 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05002023{
James Smart2e0fef82007-06-17 19:56:36 -05002024 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002025 IOCB_t *icmd;
2026 IOCB_t *oldcmd;
2027 struct lpfc_iocbq *elsiocb;
2028 struct lpfc_sli_ring *pring;
2029 struct lpfc_sli *psli;
2030 uint8_t *pcmd;
2031 uint16_t cmdsize;
2032 int rc;
2033
2034 psli = &phba->sli;
2035 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2036
2037 cmdsize = 2 * sizeof (uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05002038 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
2039 ndlp->nlp_DID, ELS_CMD_LS_RJT);
James Smart488d1462006-03-07 15:02:37 -05002040 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002041 return 1;
dea31012005-04-17 16:05:31 -05002042
2043 icmd = &elsiocb->iocb;
2044 oldcmd = &oldiocb->iocb;
2045 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2046 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2047
2048 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
2049 pcmd += sizeof (uint32_t);
2050 *((uint32_t *) (pcmd)) = rejectError;
2051
2052 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
2053 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
James Smart5b8bd0c2007-04-25 09:52:49 -04002054 "%d:0129 Xmit ELS RJT x%x response tag x%x xri x%x, "
2055 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
2056 phba->brd_no, rejectError, elsiocb->iotag,
dea31012005-04-17 16:05:31 -05002057 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
2058 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
2059
2060 phba->fc_stat.elsXmitLSRJT++;
2061 elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
dea31012005-04-17 16:05:31 -05002062 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
dea31012005-04-17 16:05:31 -05002063 if (rc == IOCB_ERROR) {
2064 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002065 return 1;
dea31012005-04-17 16:05:31 -05002066 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002067 return 0;
dea31012005-04-17 16:05:31 -05002068}
2069
2070int
James Smart2e0fef82007-06-17 19:56:36 -05002071lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
2072 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05002073{
James Smart2e0fef82007-06-17 19:56:36 -05002074 struct lpfc_hba *phba = vport->phba;
2075 struct lpfc_sli *psli = &phba->sli;
2076 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05002077 ADISC *ap;
James Smart2e0fef82007-06-17 19:56:36 -05002078 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05002079 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002080 uint8_t *pcmd;
2081 uint16_t cmdsize;
2082 int rc;
2083
dea31012005-04-17 16:05:31 -05002084 cmdsize = sizeof (uint32_t) + sizeof (ADISC);
James Smart2e0fef82007-06-17 19:56:36 -05002085 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
2086 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05002087 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002088 return 1;
dea31012005-04-17 16:05:31 -05002089
dea31012005-04-17 16:05:31 -05002090 icmd = &elsiocb->iocb;
2091 oldcmd = &oldiocb->iocb;
2092 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04002093
2094 /* Xmit ADISC ACC response tag <ulpIoTag> */
2095 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
2096 "%d:0130 Xmit ADISC ACC response iotag x%x xri: "
2097 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
2098 phba->brd_no, elsiocb->iotag,
2099 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
2100 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
2101
dea31012005-04-17 16:05:31 -05002102 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2103
2104 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
2105 pcmd += sizeof (uint32_t);
2106
2107 ap = (ADISC *) (pcmd);
2108 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart2e0fef82007-06-17 19:56:36 -05002109 memcpy(&ap->portName, &vport->fc_portname, sizeof (struct lpfc_name));
2110 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof (struct lpfc_name));
2111 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002112
2113 phba->fc_stat.elsXmitACC++;
2114 elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
dea31012005-04-17 16:05:31 -05002115 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
dea31012005-04-17 16:05:31 -05002116 if (rc == IOCB_ERROR) {
2117 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002118 return 1;
dea31012005-04-17 16:05:31 -05002119 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002120 return 0;
dea31012005-04-17 16:05:31 -05002121}
2122
2123int
James Smart2e0fef82007-06-17 19:56:36 -05002124lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
James Smart5b8bd0c2007-04-25 09:52:49 -04002125 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05002126{
James Smart2e0fef82007-06-17 19:56:36 -05002127 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002128 PRLI *npr;
2129 lpfc_vpd_t *vpd;
2130 IOCB_t *icmd;
2131 IOCB_t *oldcmd;
2132 struct lpfc_iocbq *elsiocb;
2133 struct lpfc_sli_ring *pring;
2134 struct lpfc_sli *psli;
2135 uint8_t *pcmd;
2136 uint16_t cmdsize;
2137 int rc;
2138
2139 psli = &phba->sli;
2140 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2141
2142 cmdsize = sizeof (uint32_t) + sizeof (PRLI);
James Smart2e0fef82007-06-17 19:56:36 -05002143 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
2144 ndlp->nlp_DID,
2145 (ELS_CMD_ACC |
2146 (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002147 if (!elsiocb)
2148 return 1;
dea31012005-04-17 16:05:31 -05002149
dea31012005-04-17 16:05:31 -05002150 icmd = &elsiocb->iocb;
2151 oldcmd = &oldiocb->iocb;
2152 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04002153
2154 /* Xmit PRLI ACC response tag <ulpIoTag> */
2155 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
2156 "%d:0131 Xmit PRLI ACC response tag x%x xri x%x, "
2157 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
2158 phba->brd_no, elsiocb->iotag,
2159 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
2160 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
2161
dea31012005-04-17 16:05:31 -05002162 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2163
2164 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
2165 pcmd += sizeof (uint32_t);
2166
2167 /* For PRLI, remainder of payload is PRLI parameter page */
2168 memset(pcmd, 0, sizeof (PRLI));
2169
2170 npr = (PRLI *) pcmd;
2171 vpd = &phba->vpd;
2172 /*
2173 * If our firmware version is 3.20 or later,
2174 * set the following bits for FC-TAPE support.
2175 */
2176 if (vpd->rev.feaLevelHigh >= 0x02) {
2177 npr->ConfmComplAllowed = 1;
2178 npr->Retry = 1;
2179 npr->TaskRetryIdReq = 1;
2180 }
2181
2182 npr->acceptRspCode = PRLI_REQ_EXECUTED;
2183 npr->estabImagePair = 1;
2184 npr->readXferRdyDis = 1;
2185 npr->ConfmComplAllowed = 1;
2186
2187 npr->prliType = PRLI_FCP_TYPE;
2188 npr->initiatorFunc = 1;
2189
2190 phba->fc_stat.elsXmitACC++;
2191 elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
2192
dea31012005-04-17 16:05:31 -05002193 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
dea31012005-04-17 16:05:31 -05002194 if (rc == IOCB_ERROR) {
2195 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002196 return 1;
dea31012005-04-17 16:05:31 -05002197 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002198 return 0;
dea31012005-04-17 16:05:31 -05002199}
2200
2201static int
James Smart2e0fef82007-06-17 19:56:36 -05002202lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
James Smart329f9bc2007-04-25 09:53:01 -04002203 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05002204{
James Smart2e0fef82007-06-17 19:56:36 -05002205 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002206 RNID *rn;
James Smart2e0fef82007-06-17 19:56:36 -05002207 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05002208 struct lpfc_iocbq *elsiocb;
2209 struct lpfc_sli_ring *pring;
2210 struct lpfc_sli *psli;
2211 uint8_t *pcmd;
2212 uint16_t cmdsize;
2213 int rc;
2214
2215 psli = &phba->sli;
2216 pring = &psli->ring[LPFC_ELS_RING];
2217
2218 cmdsize = sizeof (uint32_t) + sizeof (uint32_t)
2219 + (2 * sizeof (struct lpfc_name));
2220 if (format)
2221 cmdsize += sizeof (RNID_TOP_DISC);
2222
James Smart2e0fef82007-06-17 19:56:36 -05002223 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
2224 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05002225 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002226 return 1;
dea31012005-04-17 16:05:31 -05002227
dea31012005-04-17 16:05:31 -05002228 icmd = &elsiocb->iocb;
2229 oldcmd = &oldiocb->iocb;
2230 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04002231
2232 /* Xmit RNID ACC response tag <ulpIoTag> */
2233 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
2234 "%d:0132 Xmit RNID ACC response tag x%x "
2235 "xri x%x\n",
2236 phba->brd_no, elsiocb->iotag,
2237 elsiocb->iocb.ulpContext);
2238
dea31012005-04-17 16:05:31 -05002239 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2240
2241 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
2242 pcmd += sizeof (uint32_t);
2243
2244 memset(pcmd, 0, sizeof (RNID));
2245 rn = (RNID *) (pcmd);
2246 rn->Format = format;
2247 rn->CommonLen = (2 * sizeof (struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002248 memcpy(&rn->portName, &vport->fc_portname, sizeof (struct lpfc_name));
2249 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof (struct lpfc_name));
dea31012005-04-17 16:05:31 -05002250 switch (format) {
2251 case 0:
2252 rn->SpecificLen = 0;
2253 break;
2254 case RNID_TOPOLOGY_DISC:
2255 rn->SpecificLen = sizeof (RNID_TOP_DISC);
2256 memcpy(&rn->un.topologyDisc.portName,
James Smart2e0fef82007-06-17 19:56:36 -05002257 &vport->fc_portname, sizeof (struct lpfc_name));
dea31012005-04-17 16:05:31 -05002258 rn->un.topologyDisc.unitType = RNID_HBA;
2259 rn->un.topologyDisc.physPort = 0;
2260 rn->un.topologyDisc.attachedNodes = 0;
2261 break;
2262 default:
2263 rn->CommonLen = 0;
2264 rn->SpecificLen = 0;
2265 break;
2266 }
2267
2268 phba->fc_stat.elsXmitACC++;
2269 elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
James Smart329f9bc2007-04-25 09:53:01 -04002270 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002271 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
2272 * it could be freed */
2273
dea31012005-04-17 16:05:31 -05002274 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
dea31012005-04-17 16:05:31 -05002275 if (rc == IOCB_ERROR) {
2276 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002277 return 1;
dea31012005-04-17 16:05:31 -05002278 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002279 return 0;
dea31012005-04-17 16:05:31 -05002280}
2281
2282int
James Smart2e0fef82007-06-17 19:56:36 -05002283lpfc_els_disc_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002284{
James Smart2e0fef82007-06-17 19:56:36 -05002285 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002286 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05002287 int sentadisc = 0;
dea31012005-04-17 16:05:31 -05002288
James Smart685f0bf2007-04-25 09:53:08 -04002289 /* go thru NPR nodes and issue any remaining ELS ADISCs */
James Smart2e0fef82007-06-17 19:56:36 -05002290 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smart685f0bf2007-04-25 09:53:08 -04002291 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
2292 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
2293 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
James Smart2e0fef82007-06-17 19:56:36 -05002294 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04002295 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05002296 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04002297 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002298 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2299 lpfc_issue_els_adisc(vport, ndlp, 0);
James Smart685f0bf2007-04-25 09:53:08 -04002300 sentadisc++;
James Smart2e0fef82007-06-17 19:56:36 -05002301 vport->num_disc_nodes++;
2302 if (vport->num_disc_nodes >=
2303 vport->phba->cfg_discovery_threads) {
2304 spin_lock_irq(shost->host_lock);
2305 vport->fc_flag |= FC_NLP_MORE;
2306 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04002307 break;
dea31012005-04-17 16:05:31 -05002308 }
2309 }
2310 }
2311 if (sentadisc == 0) {
James Smart2e0fef82007-06-17 19:56:36 -05002312 spin_lock_irq(shost->host_lock);
2313 vport->fc_flag &= ~FC_NLP_MORE;
2314 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002315 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002316 return sentadisc;
dea31012005-04-17 16:05:31 -05002317}
2318
2319int
James Smart2e0fef82007-06-17 19:56:36 -05002320lpfc_els_disc_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002321{
James Smart2e0fef82007-06-17 19:56:36 -05002322 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002323 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05002324 int sentplogi = 0;
dea31012005-04-17 16:05:31 -05002325
James Smart2e0fef82007-06-17 19:56:36 -05002326 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
2327 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smart685f0bf2007-04-25 09:53:08 -04002328 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
2329 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
2330 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
2331 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
2332 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002333 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2334 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
James Smart685f0bf2007-04-25 09:53:08 -04002335 sentplogi++;
James Smart2e0fef82007-06-17 19:56:36 -05002336 vport->num_disc_nodes++;
2337 if (vport->num_disc_nodes >=
2338 vport->phba->cfg_discovery_threads) {
2339 spin_lock_irq(shost->host_lock);
2340 vport->fc_flag |= FC_NLP_MORE;
2341 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04002342 break;
dea31012005-04-17 16:05:31 -05002343 }
2344 }
2345 }
2346 if (sentplogi == 0) {
James Smart2e0fef82007-06-17 19:56:36 -05002347 spin_lock_irq(shost->host_lock);
2348 vport->fc_flag &= ~FC_NLP_MORE;
2349 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002350 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002351 return sentplogi;
dea31012005-04-17 16:05:31 -05002352}
2353
2354int
James Smart2e0fef82007-06-17 19:56:36 -05002355lpfc_els_flush_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002356{
James Smart2e0fef82007-06-17 19:56:36 -05002357 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2358 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002359 struct lpfc_dmabuf *mp;
2360 int i;
2361
James Smart2e0fef82007-06-17 19:56:36 -05002362 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
2363 mp = vport->fc_rscn_id_list[i];
dea31012005-04-17 16:05:31 -05002364 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2365 kfree(mp);
James Smart2e0fef82007-06-17 19:56:36 -05002366 vport->fc_rscn_id_list[i] = NULL;
dea31012005-04-17 16:05:31 -05002367 }
James Smart2e0fef82007-06-17 19:56:36 -05002368 spin_lock_irq(shost->host_lock);
2369 vport->fc_rscn_id_cnt = 0;
2370 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
2371 spin_unlock_irq(shost->host_lock);
2372 lpfc_can_disctmo(vport);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002373 return 0;
dea31012005-04-17 16:05:31 -05002374}
2375
2376int
James Smart2e0fef82007-06-17 19:56:36 -05002377lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05002378{
2379 D_ID ns_did;
2380 D_ID rscn_did;
2381 struct lpfc_dmabuf *mp;
2382 uint32_t *lp;
2383 uint32_t payload_len, cmd, i, match;
James Smart2e0fef82007-06-17 19:56:36 -05002384 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002385
2386 ns_did.un.word = did;
2387 match = 0;
2388
2389 /* Never match fabric nodes for RSCNs */
2390 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
James Smart2e0fef82007-06-17 19:56:36 -05002391 return 0;
dea31012005-04-17 16:05:31 -05002392
2393 /* If we are doing a FULL RSCN rediscovery, match everything */
James Smart2e0fef82007-06-17 19:56:36 -05002394 if (vport->fc_flag & FC_RSCN_DISCOVERY)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002395 return did;
dea31012005-04-17 16:05:31 -05002396
James Smart2e0fef82007-06-17 19:56:36 -05002397 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
2398 mp = vport->fc_rscn_id_list[i];
dea31012005-04-17 16:05:31 -05002399 lp = (uint32_t *) mp->virt;
2400 cmd = *lp++;
2401 payload_len = be32_to_cpu(cmd) & 0xffff; /* payload length */
2402 payload_len -= sizeof (uint32_t); /* take off word 0 */
2403 while (payload_len) {
2404 rscn_did.un.word = *lp++;
2405 rscn_did.un.word = be32_to_cpu(rscn_did.un.word);
2406 payload_len -= sizeof (uint32_t);
2407 switch (rscn_did.un.b.resv) {
2408 case 0: /* Single N_Port ID effected */
James Smart2e0fef82007-06-17 19:56:36 -05002409 if (ns_did.un.word == rscn_did.un.word)
dea31012005-04-17 16:05:31 -05002410 match = did;
dea31012005-04-17 16:05:31 -05002411 break;
2412 case 1: /* Whole N_Port Area effected */
2413 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
2414 && (ns_did.un.b.area == rscn_did.un.b.area))
dea31012005-04-17 16:05:31 -05002415 match = did;
dea31012005-04-17 16:05:31 -05002416 break;
2417 case 2: /* Whole N_Port Domain effected */
2418 if (ns_did.un.b.domain == rscn_did.un.b.domain)
dea31012005-04-17 16:05:31 -05002419 match = did;
dea31012005-04-17 16:05:31 -05002420 break;
2421 case 3: /* Whole Fabric effected */
2422 match = did;
2423 break;
2424 default:
James Smart2e0fef82007-06-17 19:56:36 -05002425 /* Unknown Identifier in RSCN node */
dea31012005-04-17 16:05:31 -05002426 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2427 "%d:0217 Unknown Identifier in "
2428 "RSCN payload Data: x%x\n",
2429 phba->brd_no, rscn_did.un.word);
2430 break;
2431 }
James Smart2e0fef82007-06-17 19:56:36 -05002432 if (match)
dea31012005-04-17 16:05:31 -05002433 break;
2434 }
2435 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002436 return match;
dea31012005-04-17 16:05:31 -05002437}
2438
2439static int
James Smart2e0fef82007-06-17 19:56:36 -05002440lpfc_rscn_recovery_check(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002441{
James Smart685f0bf2007-04-25 09:53:08 -04002442 struct lpfc_nodelist *ndlp = NULL;
dea31012005-04-17 16:05:31 -05002443
2444 /* Look at all nodes effected by pending RSCNs and move
James Smart685f0bf2007-04-25 09:53:08 -04002445 * them to NPR state.
dea31012005-04-17 16:05:31 -05002446 */
James Smart685f0bf2007-04-25 09:53:08 -04002447
James Smart2e0fef82007-06-17 19:56:36 -05002448 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smart685f0bf2007-04-25 09:53:08 -04002449 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE ||
James Smart2e0fef82007-06-17 19:56:36 -05002450 lpfc_rscn_payload_check(vport, ndlp->nlp_DID) == 0)
dea31012005-04-17 16:05:31 -05002451 continue;
2452
James Smart2e0fef82007-06-17 19:56:36 -05002453 lpfc_disc_state_machine(vport, ndlp, NULL,
dea31012005-04-17 16:05:31 -05002454 NLP_EVT_DEVICE_RECOVERY);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002455
James Smart685f0bf2007-04-25 09:53:08 -04002456 /*
2457 * Make sure NLP_DELAY_TMO is NOT running after a device
2458 * recovery event.
2459 */
2460 if (ndlp->nlp_flag & NLP_DELAY_TMO)
James Smart2e0fef82007-06-17 19:56:36 -05002461 lpfc_cancel_retry_delay_tmo(vport, ndlp);
dea31012005-04-17 16:05:31 -05002462 }
James Smart685f0bf2007-04-25 09:53:08 -04002463
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002464 return 0;
dea31012005-04-17 16:05:31 -05002465}
2466
2467static int
James Smart2e0fef82007-06-17 19:56:36 -05002468lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
2469 struct lpfc_nodelist *ndlp, uint8_t newnode)
dea31012005-04-17 16:05:31 -05002470{
James Smart2e0fef82007-06-17 19:56:36 -05002471 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2472 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002473 struct lpfc_dmabuf *pcmd;
2474 uint32_t *lp;
2475 IOCB_t *icmd;
2476 uint32_t payload_len, cmd;
James Smartd2873e42006-08-18 17:46:43 -04002477 int i;
dea31012005-04-17 16:05:31 -05002478
2479 icmd = &cmdiocb->iocb;
2480 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2481 lp = (uint32_t *) pcmd->virt;
2482
2483 cmd = *lp++;
2484 payload_len = be32_to_cpu(cmd) & 0xffff; /* payload length */
2485 payload_len -= sizeof (uint32_t); /* take off word 0 */
2486 cmd &= ELS_CMD_MASK;
2487
2488 /* RSCN received */
2489 lpfc_printf_log(phba,
2490 KERN_INFO,
2491 LOG_DISCOVERY,
2492 "%d:0214 RSCN received Data: x%x x%x x%x x%x\n",
James Smart2e0fef82007-06-17 19:56:36 -05002493 phba->brd_no, vport->fc_flag, payload_len, *lp,
2494 vport->fc_rscn_id_cnt);
dea31012005-04-17 16:05:31 -05002495
James Smartd2873e42006-08-18 17:46:43 -04002496 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
James Smart2e0fef82007-06-17 19:56:36 -05002497 fc_host_post_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04002498 FCH_EVT_RSCN, lp[i]);
2499
dea31012005-04-17 16:05:31 -05002500 /* If we are about to begin discovery, just ACC the RSCN.
2501 * Discovery processing will satisfy it.
2502 */
James Smart2e0fef82007-06-17 19:56:36 -05002503 if (vport->port_state <= LPFC_NS_QRY) {
2504 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL,
dea31012005-04-17 16:05:31 -05002505 newnode);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002506 return 0;
dea31012005-04-17 16:05:31 -05002507 }
2508
2509 /* If we are already processing an RSCN, save the received
2510 * RSCN payload buffer, cmdiocb->context2 to process later.
2511 */
James Smart2e0fef82007-06-17 19:56:36 -05002512 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
2513 if ((vport->fc_rscn_id_cnt < FC_MAX_HOLD_RSCN) &&
2514 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
2515 spin_lock_irq(shost->host_lock);
2516 vport->fc_flag |= FC_RSCN_MODE;
2517 spin_unlock_irq(shost->host_lock);
2518 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
dea31012005-04-17 16:05:31 -05002519
2520 /* If we zero, cmdiocb->context2, the calling
2521 * routine will not try to free it.
2522 */
2523 cmdiocb->context2 = NULL;
2524
2525 /* Deferred RSCN */
2526 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
2527 "%d:0235 Deferred RSCN "
2528 "Data: x%x x%x x%x\n",
James Smart2e0fef82007-06-17 19:56:36 -05002529 phba->brd_no, vport->fc_rscn_id_cnt,
2530 vport->fc_flag,
2531 vport->port_state);
dea31012005-04-17 16:05:31 -05002532 } else {
James Smart2e0fef82007-06-17 19:56:36 -05002533 spin_lock_irq(shost->host_lock);
2534 vport->fc_flag |= FC_RSCN_DISCOVERY;
2535 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002536 /* ReDiscovery RSCN */
2537 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
2538 "%d:0234 ReDiscovery RSCN "
2539 "Data: x%x x%x x%x\n",
James Smart2e0fef82007-06-17 19:56:36 -05002540 phba->brd_no, vport->fc_rscn_id_cnt,
2541 vport->fc_flag,
2542 vport->port_state);
dea31012005-04-17 16:05:31 -05002543 }
2544 /* Send back ACC */
James Smart2e0fef82007-06-17 19:56:36 -05002545 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL,
dea31012005-04-17 16:05:31 -05002546 newnode);
2547
2548 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05002549 lpfc_rscn_recovery_check(vport);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002550 return 0;
dea31012005-04-17 16:05:31 -05002551 }
2552
James Smart2e0fef82007-06-17 19:56:36 -05002553 spin_lock_irq(shost->host_lock);
2554 vport->fc_flag |= FC_RSCN_MODE;
2555 spin_unlock_irq(shost->host_lock);
2556 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
dea31012005-04-17 16:05:31 -05002557 /*
2558 * If we zero, cmdiocb->context2, the calling routine will
2559 * not try to free it.
2560 */
2561 cmdiocb->context2 = NULL;
2562
James Smart2e0fef82007-06-17 19:56:36 -05002563 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05002564
2565 /* Send back ACC */
James Smart2e0fef82007-06-17 19:56:36 -05002566 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL, newnode);
dea31012005-04-17 16:05:31 -05002567
2568 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05002569 lpfc_rscn_recovery_check(vport);
dea31012005-04-17 16:05:31 -05002570
James Smart2e0fef82007-06-17 19:56:36 -05002571 return lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05002572}
2573
2574int
James Smart2e0fef82007-06-17 19:56:36 -05002575lpfc_els_handle_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002576{
2577 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05002578 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002579
2580 /* Start timer for RSCN processing */
James Smart2e0fef82007-06-17 19:56:36 -05002581 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05002582
2583 /* RSCN processed */
2584 lpfc_printf_log(phba,
2585 KERN_INFO,
2586 LOG_DISCOVERY,
2587 "%d:0215 RSCN processed Data: x%x x%x x%x x%x\n",
2588 phba->brd_no,
James Smart2e0fef82007-06-17 19:56:36 -05002589 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
2590 vport->port_state);
dea31012005-04-17 16:05:31 -05002591
2592 /* To process RSCN, first compare RSCN data with NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05002593 vport->fc_ns_retry = 0;
2594 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smart685f0bf2007-04-25 09:53:08 -04002595 if (ndlp && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
dea31012005-04-17 16:05:31 -05002596 /* Good ndlp, issue CT Request to NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05002597 if (lpfc_ns_cmd(vport, ndlp, SLI_CTNS_GID_FT) == 0)
dea31012005-04-17 16:05:31 -05002598 /* Wait for NameServer query cmpl before we can
2599 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002600 return 1;
dea31012005-04-17 16:05:31 -05002601 } else {
2602 /* If login to NameServer does not exist, issue one */
2603 /* Good status, issue PLOGI to NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05002604 ndlp = lpfc_findnode_did(vport, NameServer_DID);
2605 if (ndlp)
dea31012005-04-17 16:05:31 -05002606 /* Wait for NameServer login cmpl before we can
2607 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002608 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05002609
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002610 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2611 if (!ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05002612 lpfc_els_flush_rscn(vport);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002613 return 0;
dea31012005-04-17 16:05:31 -05002614 } else {
James Smart2e0fef82007-06-17 19:56:36 -05002615 lpfc_nlp_init(vport, ndlp, NameServer_DID);
dea31012005-04-17 16:05:31 -05002616 ndlp->nlp_type |= NLP_FABRIC;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002617 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002618 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2619 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
dea31012005-04-17 16:05:31 -05002620 /* Wait for NameServer login cmpl before we can
2621 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002622 return 1;
dea31012005-04-17 16:05:31 -05002623 }
2624 }
2625
James Smart2e0fef82007-06-17 19:56:36 -05002626 lpfc_els_flush_rscn(vport);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002627 return 0;
dea31012005-04-17 16:05:31 -05002628}
2629
2630static int
James Smart2e0fef82007-06-17 19:56:36 -05002631lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
2632 struct lpfc_nodelist *ndlp, uint8_t newnode)
dea31012005-04-17 16:05:31 -05002633{
James Smart2e0fef82007-06-17 19:56:36 -05002634 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2635 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002636 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2637 uint32_t *lp = (uint32_t *) pcmd->virt;
2638 IOCB_t *icmd = &cmdiocb->iocb;
2639 struct serv_parm *sp;
2640 LPFC_MBOXQ_t *mbox;
2641 struct ls_rjt stat;
2642 uint32_t cmd, did;
2643 int rc;
2644
2645 cmd = *lp++;
2646 sp = (struct serv_parm *) lp;
2647
2648 /* FLOGI received */
2649
James Smart2e0fef82007-06-17 19:56:36 -05002650 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05002651
2652 if (phba->fc_topology == TOPOLOGY_LOOP) {
2653 /* We should never receive a FLOGI in loop mode, ignore it */
2654 did = icmd->un.elsreq64.remoteID;
2655
2656 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
2657 Loop Mode */
2658 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
2659 "%d:0113 An FLOGI ELS command x%x was received "
2660 "from DID x%x in Loop Mode\n",
2661 phba->brd_no, cmd, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002662 return 1;
dea31012005-04-17 16:05:31 -05002663 }
2664
2665 did = Fabric_DID;
2666
James Smart2e0fef82007-06-17 19:56:36 -05002667 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3))) {
dea31012005-04-17 16:05:31 -05002668 /* For a FLOGI we accept, then if our portname is greater
2669 * then the remote portname we initiate Nport login.
2670 */
2671
James Smart2e0fef82007-06-17 19:56:36 -05002672 rc = memcmp(&vport->fc_portname, &sp->portName,
dea31012005-04-17 16:05:31 -05002673 sizeof (struct lpfc_name));
2674
2675 if (!rc) {
James Smart2e0fef82007-06-17 19:56:36 -05002676 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2677 if (!mbox)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002678 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05002679
dea31012005-04-17 16:05:31 -05002680 lpfc_linkdown(phba);
2681 lpfc_init_link(phba, mbox,
2682 phba->cfg_topology,
2683 phba->cfg_link_speed);
2684 mbox->mb.un.varInitLnk.lipsr_AL_PA = 0;
2685 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
2686 rc = lpfc_sli_issue_mbox
2687 (phba, mbox, (MBX_NOWAIT | MBX_STOP_IOCB));
James Smart5b8bd0c2007-04-25 09:52:49 -04002688 lpfc_set_loopback_flag(phba);
dea31012005-04-17 16:05:31 -05002689 if (rc == MBX_NOT_FINISHED) {
James Smart329f9bc2007-04-25 09:53:01 -04002690 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05002691 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002692 return 1;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002693 } else if (rc > 0) { /* greater than */
James Smart2e0fef82007-06-17 19:56:36 -05002694 spin_lock_irq(shost->host_lock);
2695 vport->fc_flag |= FC_PT2PT_PLOGI;
2696 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002697 }
James Smart2e0fef82007-06-17 19:56:36 -05002698 spin_lock_irq(shost->host_lock);
2699 vport->fc_flag |= FC_PT2PT;
2700 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
2701 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002702 } else {
2703 /* Reject this request because invalid parameters */
2704 stat.un.b.lsRjtRsvd0 = 0;
2705 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2706 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
2707 stat.un.b.vendorUnique = 0;
James Smart2e0fef82007-06-17 19:56:36 -05002708 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002709 return 1;
dea31012005-04-17 16:05:31 -05002710 }
2711
2712 /* Send back ACC */
James Smart2e0fef82007-06-17 19:56:36 -05002713 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL, newnode);
dea31012005-04-17 16:05:31 -05002714
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002715 return 0;
dea31012005-04-17 16:05:31 -05002716}
2717
2718static int
James Smart2e0fef82007-06-17 19:56:36 -05002719lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
2720 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05002721{
2722 struct lpfc_dmabuf *pcmd;
2723 uint32_t *lp;
2724 IOCB_t *icmd;
2725 RNID *rn;
2726 struct ls_rjt stat;
2727 uint32_t cmd, did;
2728
2729 icmd = &cmdiocb->iocb;
2730 did = icmd->un.elsreq64.remoteID;
2731 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2732 lp = (uint32_t *) pcmd->virt;
2733
2734 cmd = *lp++;
2735 rn = (RNID *) lp;
2736
2737 /* RNID received */
2738
2739 switch (rn->Format) {
2740 case 0:
2741 case RNID_TOPOLOGY_DISC:
2742 /* Send back ACC */
James Smart2e0fef82007-06-17 19:56:36 -05002743 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05002744 break;
2745 default:
2746 /* Reject this request because format not supported */
2747 stat.un.b.lsRjtRsvd0 = 0;
2748 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2749 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
2750 stat.un.b.vendorUnique = 0;
James Smart2e0fef82007-06-17 19:56:36 -05002751 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05002752 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002753 return 0;
dea31012005-04-17 16:05:31 -05002754}
2755
2756static int
James Smart2e0fef82007-06-17 19:56:36 -05002757lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
2758 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002759{
2760 struct ls_rjt stat;
2761
2762 /* For now, unconditionally reject this command */
2763 stat.un.b.lsRjtRsvd0 = 0;
2764 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2765 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
2766 stat.un.b.vendorUnique = 0;
James Smart2e0fef82007-06-17 19:56:36 -05002767 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002768 return 0;
2769}
2770
Jamie Wellnitz082c0262006-02-28 19:25:30 -05002771static void
James Smart329f9bc2007-04-25 09:53:01 -04002772lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002773{
James Smart2e0fef82007-06-17 19:56:36 -05002774 struct lpfc_sli *psli = &phba->sli;
2775 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002776 MAILBOX_t *mb;
2777 IOCB_t *icmd;
2778 RPS_RSP *rps_rsp;
2779 uint8_t *pcmd;
2780 struct lpfc_iocbq *elsiocb;
2781 struct lpfc_nodelist *ndlp;
2782 uint16_t xri, status;
2783 uint32_t cmdsize;
2784
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002785 mb = &pmb->mb;
2786
2787 ndlp = (struct lpfc_nodelist *) pmb->context2;
2788 xri = (uint16_t) ((unsigned long)(pmb->context1));
Randy Dunlap041976f2006-06-25 01:58:51 -07002789 pmb->context1 = NULL;
2790 pmb->context2 = NULL;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002791
2792 if (mb->mbxStatus) {
James Smart329f9bc2007-04-25 09:53:01 -04002793 mempool_free(pmb, phba->mbox_mem_pool);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002794 return;
2795 }
2796
2797 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
James Smart329f9bc2007-04-25 09:53:01 -04002798 mempool_free(pmb, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05002799 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
2800 lpfc_max_els_tries, ndlp,
2801 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart329f9bc2007-04-25 09:53:01 -04002802 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002803 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002804 return;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002805
2806 icmd = &elsiocb->iocb;
2807 icmd->ulpContext = xri;
2808
2809 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2810 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
2811 pcmd += sizeof (uint32_t); /* Skip past command */
2812 rps_rsp = (RPS_RSP *)pcmd;
2813
2814 if (phba->fc_topology != TOPOLOGY_LOOP)
2815 status = 0x10;
2816 else
2817 status = 0x8;
James Smart2e0fef82007-06-17 19:56:36 -05002818 if (phba->pport->fc_flag & FC_FABRIC)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002819 status |= 0x4;
2820
2821 rps_rsp->rsvd1 = 0;
2822 rps_rsp->portStatus = be16_to_cpu(status);
2823 rps_rsp->linkFailureCnt = be32_to_cpu(mb->un.varRdLnk.linkFailureCnt);
2824 rps_rsp->lossSyncCnt = be32_to_cpu(mb->un.varRdLnk.lossSyncCnt);
2825 rps_rsp->lossSignalCnt = be32_to_cpu(mb->un.varRdLnk.lossSignalCnt);
2826 rps_rsp->primSeqErrCnt = be32_to_cpu(mb->un.varRdLnk.primSeqErrCnt);
2827 rps_rsp->invalidXmitWord = be32_to_cpu(mb->un.varRdLnk.invalidXmitWord);
2828 rps_rsp->crcCnt = be32_to_cpu(mb->un.varRdLnk.crcCnt);
2829
2830 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
2831 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
James Smart5b8bd0c2007-04-25 09:52:49 -04002832 "%d:0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
2833 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
2834 phba->brd_no, elsiocb->iotag,
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002835 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
2836 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
2837
2838 elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
2839 phba->fc_stat.elsXmitACC++;
James Smart685f0bf2007-04-25 09:53:08 -04002840
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002841 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
2842 lpfc_els_free_iocb(phba, elsiocb);
2843 }
2844 return;
2845}
2846
2847static int
James Smart2e0fef82007-06-17 19:56:36 -05002848lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
2849 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002850{
James Smart2e0fef82007-06-17 19:56:36 -05002851 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002852 uint32_t *lp;
2853 uint8_t flag;
2854 LPFC_MBOXQ_t *mbox;
2855 struct lpfc_dmabuf *pcmd;
2856 RPS *rps;
2857 struct ls_rjt stat;
2858
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002859 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
2860 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002861 stat.un.b.lsRjtRsvd0 = 0;
2862 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2863 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
2864 stat.un.b.vendorUnique = 0;
James Smart2e0fef82007-06-17 19:56:36 -05002865 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002866 }
2867
2868 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2869 lp = (uint32_t *) pcmd->virt;
2870 flag = (be32_to_cpu(*lp++) & 0xf);
2871 rps = (RPS *) lp;
2872
2873 if ((flag == 0) ||
2874 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
James Smart2e0fef82007-06-17 19:56:36 -05002875 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002876 sizeof (struct lpfc_name)) == 0))) {
James Smart2e0fef82007-06-17 19:56:36 -05002877
2878 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
2879 if (mbox) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002880 lpfc_read_lnk_stat(phba, mbox);
2881 mbox->context1 =
2882 (void *)((unsigned long)cmdiocb->iocb.ulpContext);
James Smart329f9bc2007-04-25 09:53:01 -04002883 mbox->context2 = lpfc_nlp_get(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002884 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
2885 if (lpfc_sli_issue_mbox (phba, mbox,
James Smart2e0fef82007-06-17 19:56:36 -05002886 (MBX_NOWAIT | MBX_STOP_IOCB)) != MBX_NOT_FINISHED)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002887 /* Mbox completion will send ELS Response */
2888 return 0;
James Smart2e0fef82007-06-17 19:56:36 -05002889
James Smart329f9bc2007-04-25 09:53:01 -04002890 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002891 mempool_free(mbox, phba->mbox_mem_pool);
2892 }
2893 }
2894 stat.un.b.lsRjtRsvd0 = 0;
2895 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2896 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
2897 stat.un.b.vendorUnique = 0;
James Smart2e0fef82007-06-17 19:56:36 -05002898 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002899 return 0;
2900}
2901
Jamie Wellnitz082c0262006-02-28 19:25:30 -05002902static int
James Smart2e0fef82007-06-17 19:56:36 -05002903lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
2904 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002905{
James Smart2e0fef82007-06-17 19:56:36 -05002906 struct lpfc_hba *phba = vport->phba;
2907 IOCB_t *icmd, *oldcmd;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002908 RPL_RSP rpl_rsp;
2909 struct lpfc_iocbq *elsiocb;
James Smart2e0fef82007-06-17 19:56:36 -05002910 struct lpfc_sli *psli = &phba->sli;
2911 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002912 uint8_t *pcmd;
2913
James Smart2e0fef82007-06-17 19:56:36 -05002914 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
2915 ndlp->nlp_DID, ELS_CMD_ACC);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002916
James Smart488d1462006-03-07 15:02:37 -05002917 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002918 return 1;
James Smart488d1462006-03-07 15:02:37 -05002919
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002920 icmd = &elsiocb->iocb;
2921 oldcmd = &oldiocb->iocb;
2922 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2923
2924 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2925 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
2926 pcmd += sizeof (uint16_t);
2927 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
2928 pcmd += sizeof(uint16_t);
2929
2930 /* Setup the RPL ACC payload */
2931 rpl_rsp.listLen = be32_to_cpu(1);
2932 rpl_rsp.index = 0;
2933 rpl_rsp.port_num_blk.portNum = 0;
James Smart2e0fef82007-06-17 19:56:36 -05002934 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
2935 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002936 sizeof(struct lpfc_name));
2937
2938 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
2939
2940
2941 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
2942 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
James Smart5b8bd0c2007-04-25 09:52:49 -04002943 "%d:0120 Xmit ELS RPL ACC response tag x%x xri x%x, "
2944 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
2945 phba->brd_no, elsiocb->iotag,
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002946 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
2947 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
2948
2949 elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
2950
2951 phba->fc_stat.elsXmitACC++;
2952 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
2953 lpfc_els_free_iocb(phba, elsiocb);
2954 return 1;
2955 }
2956 return 0;
2957}
2958
2959static int
James Smart2e0fef82007-06-17 19:56:36 -05002960lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
2961 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05002962{
2963 struct lpfc_dmabuf *pcmd;
2964 uint32_t *lp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002965 uint32_t maxsize;
2966 uint16_t cmdsize;
2967 RPL *rpl;
2968 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05002969
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002970 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
2971 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002972 stat.un.b.lsRjtRsvd0 = 0;
2973 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2974 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
2975 stat.un.b.vendorUnique = 0;
James Smart2e0fef82007-06-17 19:56:36 -05002976 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05002977 }
2978
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002979 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2980 lp = (uint32_t *) pcmd->virt;
2981 rpl = (RPL *) (lp + 1);
2982
2983 maxsize = be32_to_cpu(rpl->maxsize);
2984
2985 /* We support only one port */
2986 if ((rpl->index == 0) &&
2987 ((maxsize == 0) ||
2988 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
2989 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002990 } else {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002991 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
2992 }
James Smart2e0fef82007-06-17 19:56:36 -05002993 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05002994
2995 return 0;
2996}
2997
2998static int
James Smart2e0fef82007-06-17 19:56:36 -05002999lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3000 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003001{
James Smart2e0fef82007-06-17 19:56:36 -05003002 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003003 struct lpfc_dmabuf *pcmd;
3004 uint32_t *lp;
3005 IOCB_t *icmd;
3006 FARP *fp;
3007 uint32_t cmd, cnt, did;
3008
3009 icmd = &cmdiocb->iocb;
3010 did = icmd->un.elsreq64.remoteID;
3011 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3012 lp = (uint32_t *) pcmd->virt;
3013
3014 cmd = *lp++;
3015 fp = (FARP *) lp;
3016
3017 /* FARP-REQ received from DID <did> */
3018 lpfc_printf_log(phba,
3019 KERN_INFO,
James Smarta4bc3372006-12-02 13:34:16 -05003020 LOG_ELS,
dea31012005-04-17 16:05:31 -05003021 "%d:0601 FARP-REQ received from DID x%x\n",
3022 phba->brd_no, did);
3023
3024 /* We will only support match on WWPN or WWNN */
3025 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003026 return 0;
dea31012005-04-17 16:05:31 -05003027 }
3028
3029 cnt = 0;
3030 /* If this FARP command is searching for my portname */
3031 if (fp->Mflags & FARP_MATCH_PORT) {
James Smart2e0fef82007-06-17 19:56:36 -05003032 if (memcmp(&fp->RportName, &vport->fc_portname,
dea31012005-04-17 16:05:31 -05003033 sizeof (struct lpfc_name)) == 0)
3034 cnt = 1;
3035 }
3036
3037 /* If this FARP command is searching for my nodename */
3038 if (fp->Mflags & FARP_MATCH_NODE) {
James Smart2e0fef82007-06-17 19:56:36 -05003039 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
dea31012005-04-17 16:05:31 -05003040 sizeof (struct lpfc_name)) == 0)
3041 cnt = 1;
3042 }
3043
3044 if (cnt) {
3045 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
3046 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
3047 /* Log back into the node before sending the FARP. */
3048 if (fp->Rflags & FARP_REQUEST_PLOGI) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003049 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003050 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04003051 NLP_STE_PLOGI_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05003052 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05003053 }
3054
3055 /* Send a FARP response to that node */
James Smart2e0fef82007-06-17 19:56:36 -05003056 if (fp->Rflags & FARP_REQUEST_FARPR)
3057 lpfc_issue_els_farpr(vport, did, 0);
dea31012005-04-17 16:05:31 -05003058 }
3059 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003060 return 0;
dea31012005-04-17 16:05:31 -05003061}
3062
3063static int
James Smart2e0fef82007-06-17 19:56:36 -05003064lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3065 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003066{
3067 struct lpfc_dmabuf *pcmd;
3068 uint32_t *lp;
3069 IOCB_t *icmd;
3070 uint32_t cmd, did;
James Smart2e0fef82007-06-17 19:56:36 -05003071 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003072
3073 icmd = &cmdiocb->iocb;
3074 did = icmd->un.elsreq64.remoteID;
3075 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3076 lp = (uint32_t *) pcmd->virt;
3077
3078 cmd = *lp++;
3079 /* FARP-RSP received from DID <did> */
3080 lpfc_printf_log(phba,
3081 KERN_INFO,
James Smarta4bc3372006-12-02 13:34:16 -05003082 LOG_ELS,
dea31012005-04-17 16:05:31 -05003083 "%d:0600 FARP-RSP received from DID x%x\n",
3084 phba->brd_no, did);
3085
3086 /* ACCEPT the Farp resp request */
James Smart2e0fef82007-06-17 19:56:36 -05003087 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
dea31012005-04-17 16:05:31 -05003088
3089 return 0;
3090}
3091
3092static int
James Smart2e0fef82007-06-17 19:56:36 -05003093lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3094 struct lpfc_nodelist *fan_ndlp)
dea31012005-04-17 16:05:31 -05003095{
3096 struct lpfc_dmabuf *pcmd;
3097 uint32_t *lp;
3098 IOCB_t *icmd;
dea31012005-04-17 16:05:31 -05003099 uint32_t cmd, did;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003100 FAN *fp;
3101 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05003102 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003103
3104 /* FAN received */
James Smartdca94792006-08-01 07:34:08 -04003105 lpfc_printf_log(phba, KERN_INFO, LOG_ELS, "%d:0265 FAN received\n",
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003106 phba->brd_no);
dea31012005-04-17 16:05:31 -05003107
3108 icmd = &cmdiocb->iocb;
3109 did = icmd->un.elsreq64.remoteID;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003110 pcmd = (struct lpfc_dmabuf *)cmdiocb->context2;
3111 lp = (uint32_t *)pcmd->virt;
dea31012005-04-17 16:05:31 -05003112
3113 cmd = *lp++;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003114 fp = (FAN *)lp;
dea31012005-04-17 16:05:31 -05003115
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003116 /* FAN received; Fan does not have a reply sequence */
dea31012005-04-17 16:05:31 -05003117
James Smart2e0fef82007-06-17 19:56:36 -05003118 if (phba->pport->port_state == LPFC_LOCAL_CFG_LINK) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003119 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
3120 sizeof(struct lpfc_name)) != 0) ||
3121 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
3122 sizeof(struct lpfc_name)) != 0)) {
3123 /*
3124 * This node has switched fabrics. FLOGI is required
3125 * Clean up the old rpi's
dea31012005-04-17 16:05:31 -05003126 */
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003127
3128 list_for_each_entry_safe(ndlp, next_ndlp,
James Smart2e0fef82007-06-17 19:56:36 -05003129 &vport->fc_nodes, nlp_listp) {
James Smart685f0bf2007-04-25 09:53:08 -04003130 if (ndlp->nlp_state != NLP_STE_NPR_NODE)
3131 continue;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003132 if (ndlp->nlp_type & NLP_FABRIC) {
3133 /*
3134 * Clean up old Fabric, Nameserver and
3135 * other NLP_FABRIC logins
3136 */
James Smart2e0fef82007-06-17 19:56:36 -05003137 lpfc_drop_node(vport, ndlp);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003138 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003139 /* Fail outstanding I/O now since this
3140 * device is marked for PLOGI
3141 */
James Smart2e0fef82007-06-17 19:56:36 -05003142 lpfc_unreg_rpi(vport, ndlp);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003143 }
3144 }
3145
James Smart2e0fef82007-06-17 19:56:36 -05003146 vport->port_state = LPFC_FLOGI;
3147 lpfc_set_disctmo(vport);
3148 lpfc_initial_flogi(vport);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003149 return 0;
dea31012005-04-17 16:05:31 -05003150 }
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003151 /* Discovery not needed,
3152 * move the nodes to their original state.
3153 */
James Smart2e0fef82007-06-17 19:56:36 -05003154 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
James Smart685f0bf2007-04-25 09:53:08 -04003155 nlp_listp) {
3156 if (ndlp->nlp_state != NLP_STE_NPR_NODE)
3157 continue;
dea31012005-04-17 16:05:31 -05003158
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003159 switch (ndlp->nlp_prev_state) {
3160 case NLP_STE_UNMAPPED_NODE:
3161 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05003162 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04003163 NLP_STE_UNMAPPED_NODE);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003164 break;
3165
3166 case NLP_STE_MAPPED_NODE:
3167 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05003168 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04003169 NLP_STE_MAPPED_NODE);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003170 break;
3171
3172 default:
3173 break;
3174 }
3175 }
3176
3177 /* Start discovery - this should just do CLEAR_LA */
James Smart2e0fef82007-06-17 19:56:36 -05003178 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -05003179 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003180 return 0;
dea31012005-04-17 16:05:31 -05003181}
3182
3183void
3184lpfc_els_timeout(unsigned long ptr)
3185{
James Smart2e0fef82007-06-17 19:56:36 -05003186 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
3187 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003188 unsigned long iflag;
3189
James Smart2e0fef82007-06-17 19:56:36 -05003190 spin_lock_irqsave(&vport->work_port_lock, iflag);
3191 if ((vport->work_port_events & WORKER_ELS_TMO) == 0) {
3192 vport->work_port_events |= WORKER_ELS_TMO;
dea31012005-04-17 16:05:31 -05003193 if (phba->work_wait)
3194 wake_up(phba->work_wait);
3195 }
James Smart2e0fef82007-06-17 19:56:36 -05003196 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
dea31012005-04-17 16:05:31 -05003197 return;
3198}
3199
3200void
James Smart2e0fef82007-06-17 19:56:36 -05003201lpfc_els_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003202{
James Smart2e0fef82007-06-17 19:56:36 -05003203 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003204 struct lpfc_sli_ring *pring;
3205 struct lpfc_iocbq *tmp_iocb, *piocb;
3206 IOCB_t *cmd = NULL;
3207 struct lpfc_dmabuf *pcmd;
James Smart2e0fef82007-06-17 19:56:36 -05003208 uint32_t els_command = 0;
dea31012005-04-17 16:05:31 -05003209 uint32_t timeout;
James Smart2e0fef82007-06-17 19:56:36 -05003210 uint32_t remote_ID = 0xffffffff;
dea31012005-04-17 16:05:31 -05003211
dea31012005-04-17 16:05:31 -05003212 /* If the timer is already canceled do nothing */
James Smart2e0fef82007-06-17 19:56:36 -05003213 if ((vport->work_port_events & WORKER_ELS_TMO) == 0) {
dea31012005-04-17 16:05:31 -05003214 return;
3215 }
James Smart2e0fef82007-06-17 19:56:36 -05003216 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003217 timeout = (uint32_t)(phba->fc_ratov << 1);
3218
3219 pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05003220
3221 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
3222 cmd = &piocb->iocb;
3223
James Smart2e0fef82007-06-17 19:56:36 -05003224 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
3225 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
3226 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
dea31012005-04-17 16:05:31 -05003227 continue;
James Smart2e0fef82007-06-17 19:56:36 -05003228
3229 if (piocb->vport != vport)
3230 continue;
3231
dea31012005-04-17 16:05:31 -05003232 pcmd = (struct lpfc_dmabuf *) piocb->context2;
James Smart2e0fef82007-06-17 19:56:36 -05003233 if (pcmd)
3234 els_command = *(uint32_t *) (pcmd->virt);
dea31012005-04-17 16:05:31 -05003235
3236 if ((els_command == ELS_CMD_FARP)
3237 || (els_command == ELS_CMD_FARPR)) {
3238 continue;
3239 }
3240
3241 if (piocb->drvrTimeout > 0) {
3242 if (piocb->drvrTimeout >= timeout) {
3243 piocb->drvrTimeout -= timeout;
3244 } else {
3245 piocb->drvrTimeout = 0;
3246 }
3247 continue;
3248 }
3249
James Smart2e0fef82007-06-17 19:56:36 -05003250 remote_ID = 0xffffffff;
3251 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
dea31012005-04-17 16:05:31 -05003252 remote_ID = cmd->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05003253 else {
3254 struct lpfc_nodelist *ndlp;
3255 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
3256 if (ndlp)
3257 remote_ID = ndlp->nlp_DID;
dea31012005-04-17 16:05:31 -05003258 }
3259
3260 lpfc_printf_log(phba,
3261 KERN_ERR,
3262 LOG_ELS,
3263 "%d:0127 ELS timeout Data: x%x x%x x%x x%x\n",
3264 phba->brd_no, els_command,
3265 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
3266
James Smart07951072007-04-25 09:51:38 -04003267 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05003268 }
James Smart2e0fef82007-06-17 19:56:36 -05003269 spin_unlock_irq(&phba->hbalock);
James Smart5a0e3262006-07-06 15:49:16 -04003270
James Smart2e0fef82007-06-17 19:56:36 -05003271 if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt)
3272 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
dea31012005-04-17 16:05:31 -05003273}
3274
3275void
James Smart2e0fef82007-06-17 19:56:36 -05003276lpfc_els_flush_cmd(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003277{
James Smart2534ba72007-04-25 09:52:20 -04003278 LIST_HEAD(completions);
James Smart2e0fef82007-06-17 19:56:36 -05003279 struct lpfc_hba *phba = vport->phba;
James Smart329f9bc2007-04-25 09:53:01 -04003280 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05003281 struct lpfc_iocbq *tmp_iocb, *piocb;
3282 IOCB_t *cmd = NULL;
dea31012005-04-17 16:05:31 -05003283
James Smart2e0fef82007-06-17 19:56:36 -05003284 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003285 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
3286 cmd = &piocb->iocb;
3287
3288 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
3289 continue;
3290 }
3291
3292 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
James Smart329f9bc2007-04-25 09:53:01 -04003293 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
3294 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
3295 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
3296 cmd->ulpCommand == CMD_ABORT_XRI_CN)
dea31012005-04-17 16:05:31 -05003297 continue;
dea31012005-04-17 16:05:31 -05003298
James Smart2e0fef82007-06-17 19:56:36 -05003299 if (piocb->vport != vport)
3300 continue;
3301
James Smart2534ba72007-04-25 09:52:20 -04003302 list_move_tail(&piocb->list, &completions);
James Smart1dcb58e2007-04-25 09:51:30 -04003303 pring->txq_cnt--;
dea31012005-04-17 16:05:31 -05003304 }
3305
3306 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
dea31012005-04-17 16:05:31 -05003307 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
3308 continue;
3309 }
dea31012005-04-17 16:05:31 -05003310
James Smart2e0fef82007-06-17 19:56:36 -05003311 if (piocb->vport != vport)
3312 continue;
3313
James Smart07951072007-04-25 09:51:38 -04003314 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05003315 }
James Smart2e0fef82007-06-17 19:56:36 -05003316 spin_unlock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04003317
James Smart2e0fef82007-06-17 19:56:36 -05003318 while (!list_empty(&completions)) {
James Smart2534ba72007-04-25 09:52:20 -04003319 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
3320 cmd = &piocb->iocb;
3321 list_del(&piocb->list);
3322
James Smart2e0fef82007-06-17 19:56:36 -05003323 if (!piocb->iocb_cmpl)
3324 lpfc_sli_release_iocbq(phba, piocb);
3325 else {
James Smart2534ba72007-04-25 09:52:20 -04003326 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
3327 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
3328 (piocb->iocb_cmpl) (phba, piocb, piocb);
James Smart2e0fef82007-06-17 19:56:36 -05003329 }
James Smart2534ba72007-04-25 09:52:20 -04003330 }
3331
dea31012005-04-17 16:05:31 -05003332 return;
3333}
3334
3335void
James Smart2e0fef82007-06-17 19:56:36 -05003336lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
3337 struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05003338{
3339 struct lpfc_sli *psli;
3340 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05003341 struct lpfc_dmabuf *mp = NULL;
dea31012005-04-17 16:05:31 -05003342 uint32_t *lp;
3343 IOCB_t *icmd;
3344 struct ls_rjt stat;
James Smart2e0fef82007-06-17 19:56:36 -05003345 uint32_t cmd, did, newnode, rjt_err = 0;
dea31012005-04-17 16:05:31 -05003346 uint32_t drop_cmd = 0; /* by default do NOT drop received cmd */
James Smart2e0fef82007-06-17 19:56:36 -05003347 struct lpfc_vport *vport = NULL;
dea31012005-04-17 16:05:31 -05003348
3349 psli = &phba->sli;
3350 icmd = &elsiocb->iocb;
3351
3352 if ((icmd->ulpStatus == IOSTAT_LOCAL_REJECT) &&
3353 ((icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING)) {
dea31012005-04-17 16:05:31 -05003354 phba->fc_stat.NoRcvBuf++;
James Smart2e0fef82007-06-17 19:56:36 -05003355 /* Not enough posted buffers; Try posting more buffers */
dea31012005-04-17 16:05:31 -05003356 lpfc_post_buffer(phba, pring, 0, 1);
3357 return;
3358 }
3359
3360 /* If there are no BDEs associated with this IOCB,
3361 * there is nothing to do.
3362 */
3363 if (icmd->ulpBdeCount == 0)
3364 return;
3365
James Smart2e0fef82007-06-17 19:56:36 -05003366 /* type of ELS cmd is first 32bit word in packet */
3367 mp = lpfc_sli_ringpostbuf_get(phba, pring,
3368 getPaddr(icmd->un.cont64[0].addrHigh,
3369 icmd->un.cont64[0].addrLow));
dea31012005-04-17 16:05:31 -05003370 if (mp == 0) {
3371 drop_cmd = 1;
3372 goto dropit;
3373 }
3374
James Smart2e0fef82007-06-17 19:56:36 -05003375 vport = phba->pport;
3376
dea31012005-04-17 16:05:31 -05003377 newnode = 0;
3378 lp = (uint32_t *) mp->virt;
3379 cmd = *lp++;
3380 lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], 1, 1);
3381
3382 if (icmd->ulpStatus) {
3383 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3384 kfree(mp);
3385 drop_cmd = 1;
3386 goto dropit;
3387 }
3388
3389 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05003390 if (lpfc_els_chk_latt(vport)) {
dea31012005-04-17 16:05:31 -05003391 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3392 kfree(mp);
3393 drop_cmd = 1;
3394 goto dropit;
3395 }
3396
3397 did = icmd->un.rcvels.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05003398 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003399 if (!ndlp) {
dea31012005-04-17 16:05:31 -05003400 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003401 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
3402 if (!ndlp) {
dea31012005-04-17 16:05:31 -05003403 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3404 kfree(mp);
3405 drop_cmd = 1;
3406 goto dropit;
3407 }
3408
James Smart2e0fef82007-06-17 19:56:36 -05003409 lpfc_nlp_init(vport, ndlp, did);
dea31012005-04-17 16:05:31 -05003410 newnode = 1;
3411 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) {
3412 ndlp->nlp_type |= NLP_FABRIC;
3413 }
James Smart2e0fef82007-06-17 19:56:36 -05003414 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE);
dea31012005-04-17 16:05:31 -05003415 }
3416
3417 phba->fc_stat.elsRcvFrame++;
James Smart329f9bc2007-04-25 09:53:01 -04003418 if (elsiocb->context1)
3419 lpfc_nlp_put(elsiocb->context1);
3420 elsiocb->context1 = lpfc_nlp_get(ndlp);
dea31012005-04-17 16:05:31 -05003421 elsiocb->context2 = mp;
James Smart2e0fef82007-06-17 19:56:36 -05003422 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -05003423
3424 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
3425 cmd &= ELS_CMD_MASK;
3426 }
3427 /* ELS command <elsCmd> received from NPORT <did> */
3428 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
3429 "%d:0112 ELS command x%x received from NPORT x%x "
James Smart2e0fef82007-06-17 19:56:36 -05003430 "Data: x%x\n", phba->brd_no, cmd, did,
3431 vport->port_state);
dea31012005-04-17 16:05:31 -05003432
3433 switch (cmd) {
3434 case ELS_CMD_PLOGI:
3435 phba->fc_stat.elsRcvPLOGI++;
James Smart2e0fef82007-06-17 19:56:36 -05003436 if (vport->port_state < LPFC_DISC_AUTH) {
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04003437 rjt_err = 1;
dea31012005-04-17 16:05:31 -05003438 break;
3439 }
James Smart92795652006-07-06 15:50:02 -04003440 ndlp = lpfc_plogi_confirm_nport(phba, mp, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05003441 lpfc_disc_state_machine(vport, ndlp, elsiocb,
3442 NLP_EVT_RCV_PLOGI);
dea31012005-04-17 16:05:31 -05003443 break;
3444 case ELS_CMD_FLOGI:
3445 phba->fc_stat.elsRcvFLOGI++;
James Smart2e0fef82007-06-17 19:56:36 -05003446 lpfc_els_rcv_flogi(vport, elsiocb, ndlp, newnode);
James Smartde0c5b32007-04-25 09:52:27 -04003447 if (newnode)
James Smart2e0fef82007-06-17 19:56:36 -05003448 lpfc_drop_node(vport, ndlp);
dea31012005-04-17 16:05:31 -05003449 break;
3450 case ELS_CMD_LOGO:
3451 phba->fc_stat.elsRcvLOGO++;
James Smart2e0fef82007-06-17 19:56:36 -05003452 if (vport->port_state < LPFC_DISC_AUTH) {
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04003453 rjt_err = 1;
dea31012005-04-17 16:05:31 -05003454 break;
3455 }
James Smart2e0fef82007-06-17 19:56:36 -05003456 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
dea31012005-04-17 16:05:31 -05003457 break;
3458 case ELS_CMD_PRLO:
3459 phba->fc_stat.elsRcvPRLO++;
James Smart2e0fef82007-06-17 19:56:36 -05003460 if (vport->port_state < LPFC_DISC_AUTH) {
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04003461 rjt_err = 1;
dea31012005-04-17 16:05:31 -05003462 break;
3463 }
James Smart2e0fef82007-06-17 19:56:36 -05003464 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
dea31012005-04-17 16:05:31 -05003465 break;
3466 case ELS_CMD_RSCN:
3467 phba->fc_stat.elsRcvRSCN++;
James Smart2e0fef82007-06-17 19:56:36 -05003468 lpfc_els_rcv_rscn(vport, elsiocb, ndlp, newnode);
James Smartde0c5b32007-04-25 09:52:27 -04003469 if (newnode)
James Smart2e0fef82007-06-17 19:56:36 -05003470 lpfc_drop_node(vport, ndlp);
dea31012005-04-17 16:05:31 -05003471 break;
3472 case ELS_CMD_ADISC:
3473 phba->fc_stat.elsRcvADISC++;
James Smart2e0fef82007-06-17 19:56:36 -05003474 if (vport->port_state < LPFC_DISC_AUTH) {
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04003475 rjt_err = 1;
dea31012005-04-17 16:05:31 -05003476 break;
3477 }
James Smart2e0fef82007-06-17 19:56:36 -05003478 lpfc_disc_state_machine(vport, ndlp, elsiocb,
3479 NLP_EVT_RCV_ADISC);
dea31012005-04-17 16:05:31 -05003480 break;
3481 case ELS_CMD_PDISC:
3482 phba->fc_stat.elsRcvPDISC++;
James Smart2e0fef82007-06-17 19:56:36 -05003483 if (vport->port_state < LPFC_DISC_AUTH) {
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04003484 rjt_err = 1;
dea31012005-04-17 16:05:31 -05003485 break;
3486 }
James Smart2e0fef82007-06-17 19:56:36 -05003487 lpfc_disc_state_machine(vport, ndlp, elsiocb,
3488 NLP_EVT_RCV_PDISC);
dea31012005-04-17 16:05:31 -05003489 break;
3490 case ELS_CMD_FARPR:
3491 phba->fc_stat.elsRcvFARPR++;
James Smart2e0fef82007-06-17 19:56:36 -05003492 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05003493 break;
3494 case ELS_CMD_FARP:
3495 phba->fc_stat.elsRcvFARP++;
James Smart2e0fef82007-06-17 19:56:36 -05003496 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05003497 break;
3498 case ELS_CMD_FAN:
3499 phba->fc_stat.elsRcvFAN++;
James Smart2e0fef82007-06-17 19:56:36 -05003500 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05003501 break;
dea31012005-04-17 16:05:31 -05003502 case ELS_CMD_PRLI:
3503 phba->fc_stat.elsRcvPRLI++;
James Smart2e0fef82007-06-17 19:56:36 -05003504 if (vport->port_state < LPFC_DISC_AUTH) {
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04003505 rjt_err = 1;
dea31012005-04-17 16:05:31 -05003506 break;
3507 }
James Smart2e0fef82007-06-17 19:56:36 -05003508 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
dea31012005-04-17 16:05:31 -05003509 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003510 case ELS_CMD_LIRR:
3511 phba->fc_stat.elsRcvLIRR++;
James Smart2e0fef82007-06-17 19:56:36 -05003512 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04003513 if (newnode)
James Smart2e0fef82007-06-17 19:56:36 -05003514 lpfc_drop_node(vport, ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003515 break;
3516 case ELS_CMD_RPS:
3517 phba->fc_stat.elsRcvRPS++;
James Smart2e0fef82007-06-17 19:56:36 -05003518 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04003519 if (newnode)
James Smart2e0fef82007-06-17 19:56:36 -05003520 lpfc_drop_node(vport, ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003521 break;
3522 case ELS_CMD_RPL:
3523 phba->fc_stat.elsRcvRPL++;
James Smart2e0fef82007-06-17 19:56:36 -05003524 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04003525 if (newnode)
James Smart2e0fef82007-06-17 19:56:36 -05003526 lpfc_drop_node(vport, ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003527 break;
dea31012005-04-17 16:05:31 -05003528 case ELS_CMD_RNID:
3529 phba->fc_stat.elsRcvRNID++;
James Smart2e0fef82007-06-17 19:56:36 -05003530 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04003531 if (newnode)
James Smart2e0fef82007-06-17 19:56:36 -05003532 lpfc_drop_node(vport, ndlp);
dea31012005-04-17 16:05:31 -05003533 break;
3534 default:
3535 /* Unsupported ELS command, reject */
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04003536 rjt_err = 1;
dea31012005-04-17 16:05:31 -05003537
3538 /* Unknown ELS command <elsCmd> received from NPORT <did> */
3539 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
3540 "%d:0115 Unknown ELS command x%x received from "
3541 "NPORT x%x\n", phba->brd_no, cmd, did);
James Smartde0c5b32007-04-25 09:52:27 -04003542 if (newnode)
James Smart2e0fef82007-06-17 19:56:36 -05003543 lpfc_drop_node(vport, ndlp);
dea31012005-04-17 16:05:31 -05003544 break;
3545 }
3546
3547 /* check if need to LS_RJT received ELS cmd */
3548 if (rjt_err) {
3549 stat.un.b.lsRjtRsvd0 = 0;
3550 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04003551 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -05003552 stat.un.b.vendorUnique = 0;
James Smart2e0fef82007-06-17 19:56:36 -05003553 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05003554 }
3555
James Smart329f9bc2007-04-25 09:53:01 -04003556 lpfc_nlp_put(elsiocb->context1);
3557 elsiocb->context1 = NULL;
dea31012005-04-17 16:05:31 -05003558 if (elsiocb->context2) {
3559 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3560 kfree(mp);
3561 }
3562dropit:
3563 /* check if need to drop received ELS cmd */
3564 if (drop_cmd == 1) {
3565 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
3566 "%d:0111 Dropping received ELS cmd "
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003567 "Data: x%x x%x x%x\n", phba->brd_no,
3568 icmd->ulpStatus, icmd->un.ulpWord[4],
3569 icmd->ulpTimeout);
dea31012005-04-17 16:05:31 -05003570 phba->fc_stat.elsRcvDrop++;
3571 }
dea31012005-04-17 16:05:31 -05003572}