blob: ddf7f225ba5cda099a92710385577ced5e9a7ea7 [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. *
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004 * Copyright (C) 2004-2006 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
44lpfc_els_chk_latt(struct lpfc_hba * phba)
45{
46 struct lpfc_sli *psli;
47 LPFC_MBOXQ_t *mbox;
48 uint32_t ha_copy;
49 int rc;
50
51 psli = &phba->sli;
52
53 if ((phba->hba_state >= LPFC_HBA_READY) ||
54 (phba->hba_state == LPFC_LINK_DOWN))
55 return 0;
56
57 /* Read the HBA Host Attention Register */
58 spin_lock_irq(phba->host->host_lock);
59 ha_copy = readl(phba->HAregaddr);
60 spin_unlock_irq(phba->host->host_lock);
61
62 if (!(ha_copy & HA_LATT))
63 return 0;
64
65 /* Pending Link Event during Discovery */
66 lpfc_printf_log(phba, KERN_WARNING, LOG_DISCOVERY,
67 "%d:0237 Pending Link Event during "
68 "Discovery: State x%x\n",
69 phba->brd_no, phba->hba_state);
70
71 /* CLEAR_LA should re-enable link attention events and
72 * we should then imediately take a LATT event. The
73 * LATT processing should call lpfc_linkdown() which
74 * will cleanup any left over in-progress discovery
75 * events.
76 */
77 spin_lock_irq(phba->host->host_lock);
78 phba->fc_flag |= FC_ABORT_DISCOVERY;
79 spin_unlock_irq(phba->host->host_lock);
80
81 if (phba->hba_state != LPFC_CLEAR_LA) {
82 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) {
83 phba->hba_state = LPFC_CLEAR_LA;
84 lpfc_clear_la(phba, mbox);
85 mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
86 rc = lpfc_sli_issue_mbox (phba, mbox,
87 (MBX_NOWAIT | MBX_STOP_IOCB));
88 if (rc == MBX_NOT_FINISHED) {
89 mempool_free(mbox, phba->mbox_mem_pool);
90 phba->hba_state = LPFC_HBA_ERROR;
91 }
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 Smart488d1462006-03-07 15:02:37 -0500100lpfc_prep_els_iocb(struct lpfc_hba * phba, uint8_t expectRsp,
101 uint16_t cmdSize, uint8_t retry, struct lpfc_nodelist * ndlp,
102 uint32_t did, uint32_t elscmd)
dea31012005-04-17 16:05:31 -0500103{
dea31012005-04-17 16:05:31 -0500104 struct lpfc_sli_ring *pring;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400105 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -0500106 struct lpfc_dmabuf *pcmd, *prsp, *pbuflist;
107 struct ulp_bde64 *bpl;
108 IOCB_t *icmd;
109
110 pring = &phba->sli.ring[LPFC_ELS_RING];
111
112 if (phba->hba_state < LPFC_LINK_UP)
113 return NULL;
114
dea31012005-04-17 16:05:31 -0500115 /* Allocate buffer for command iocb */
116 spin_lock_irq(phba->host->host_lock);
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400117 elsiocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -0500118 spin_unlock_irq(phba->host->host_lock);
119
120 if (elsiocb == NULL)
121 return NULL;
dea31012005-04-17 16:05:31 -0500122 icmd = &elsiocb->iocb;
123
124 /* fill in BDEs for command */
125 /* Allocate buffer for command payload */
126 if (((pcmd = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL)) == 0) ||
127 ((pcmd->virt = lpfc_mbuf_alloc(phba,
128 MEM_PRI, &(pcmd->phys))) == 0)) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -0800129 kfree(pcmd);
dea31012005-04-17 16:05:31 -0500130
James Bottomley604a3e32005-10-29 10:28:33 -0500131 spin_lock_irq(phba->host->host_lock);
132 lpfc_sli_release_iocbq(phba, elsiocb);
133 spin_unlock_irq(phba->host->host_lock);
dea31012005-04-17 16:05:31 -0500134 return NULL;
135 }
136
137 INIT_LIST_HEAD(&pcmd->list);
138
139 /* Allocate buffer for response payload */
140 if (expectRsp) {
141 prsp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
142 if (prsp)
143 prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
144 &prsp->phys);
145 if (prsp == 0 || prsp->virt == 0) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -0800146 kfree(prsp);
dea31012005-04-17 16:05:31 -0500147 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
148 kfree(pcmd);
James Bottomley604a3e32005-10-29 10:28:33 -0500149 spin_lock_irq(phba->host->host_lock);
150 lpfc_sli_release_iocbq(phba, elsiocb);
151 spin_unlock_irq(phba->host->host_lock);
dea31012005-04-17 16:05:31 -0500152 return NULL;
153 }
154 INIT_LIST_HEAD(&prsp->list);
155 } else {
156 prsp = NULL;
157 }
158
159 /* Allocate buffer for Buffer ptr list */
160 pbuflist = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
161 if (pbuflist)
162 pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
163 &pbuflist->phys);
164 if (pbuflist == 0 || pbuflist->virt == 0) {
James Bottomley604a3e32005-10-29 10:28:33 -0500165 spin_lock_irq(phba->host->host_lock);
166 lpfc_sli_release_iocbq(phba, elsiocb);
167 spin_unlock_irq(phba->host->host_lock);
dea31012005-04-17 16:05:31 -0500168 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
169 lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
170 kfree(pcmd);
171 kfree(prsp);
Jesper Juhlc9475cb2005-11-07 01:01:26 -0800172 kfree(pbuflist);
dea31012005-04-17 16:05:31 -0500173 return NULL;
174 }
175
176 INIT_LIST_HEAD(&pbuflist->list);
177
178 icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
179 icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
180 icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BDL;
181 if (expectRsp) {
182 icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof (struct ulp_bde64));
James Smart488d1462006-03-07 15:02:37 -0500183 icmd->un.elsreq64.remoteID = did; /* DID */
dea31012005-04-17 16:05:31 -0500184 icmd->ulpCommand = CMD_ELS_REQUEST64_CR;
James Smart2680eea2007-04-25 09:52:55 -0400185 icmd->ulpTimeout = phba->fc_ratov * 2;
dea31012005-04-17 16:05:31 -0500186 } else {
187 icmd->un.elsreq64.bdl.bdeSize = sizeof (struct ulp_bde64);
188 icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
189 }
190
191 icmd->ulpBdeCount = 1;
192 icmd->ulpLe = 1;
193 icmd->ulpClass = CLASS3;
194
195 bpl = (struct ulp_bde64 *) pbuflist->virt;
196 bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys));
197 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys));
198 bpl->tus.f.bdeSize = cmdSize;
199 bpl->tus.f.bdeFlags = 0;
200 bpl->tus.w = le32_to_cpu(bpl->tus.w);
201
202 if (expectRsp) {
203 bpl++;
204 bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys));
205 bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys));
206 bpl->tus.f.bdeSize = FCELSSIZE;
207 bpl->tus.f.bdeFlags = BUFF_USE_RCV;
208 bpl->tus.w = le32_to_cpu(bpl->tus.w);
209 }
210
211 /* Save for completion so we can release these resources */
James Smart329f9bc2007-04-25 09:53:01 -0400212 elsiocb->context1 = lpfc_nlp_get(ndlp);
213 elsiocb->context2 = pcmd;
214 elsiocb->context3 = pbuflist;
dea31012005-04-17 16:05:31 -0500215 elsiocb->retry = retry;
216 elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
217
218 if (prsp) {
219 list_add(&prsp->list, &pcmd->list);
220 }
221
222 if (expectRsp) {
223 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
224 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
225 "%d:0116 Xmit ELS command x%x to remote "
James Smart1dcb58e2007-04-25 09:51:30 -0400226 "NPORT x%x I/O tag: x%x, HBA state: x%x\n",
dea31012005-04-17 16:05:31 -0500227 phba->brd_no, elscmd,
James Smart1dcb58e2007-04-25 09:51:30 -0400228 did, elsiocb->iotag, phba->hba_state);
dea31012005-04-17 16:05:31 -0500229 } else {
230 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
231 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
232 "%d:0117 Xmit ELS response x%x to remote "
James Smart1dcb58e2007-04-25 09:51:30 -0400233 "NPORT x%x I/O tag: x%x, size: x%x\n",
dea31012005-04-17 16:05:31 -0500234 phba->brd_no, elscmd,
James Smart1dcb58e2007-04-25 09:51:30 -0400235 ndlp->nlp_DID, elsiocb->iotag, cmdSize);
dea31012005-04-17 16:05:31 -0500236 }
237
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500238 return elsiocb;
dea31012005-04-17 16:05:31 -0500239}
240
241
242static int
243lpfc_cmpl_els_flogi_fabric(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
244 struct serv_parm *sp, IOCB_t *irsp)
245{
246 LPFC_MBOXQ_t *mbox;
James Smart14691152006-12-02 13:34:28 -0500247 struct lpfc_dmabuf *mp;
dea31012005-04-17 16:05:31 -0500248 int rc;
249
250 spin_lock_irq(phba->host->host_lock);
251 phba->fc_flag |= FC_FABRIC;
252 spin_unlock_irq(phba->host->host_lock);
253
254 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
255 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
256 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
257
258 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
259
260 if (phba->fc_topology == TOPOLOGY_LOOP) {
261 spin_lock_irq(phba->host->host_lock);
262 phba->fc_flag |= FC_PUBLIC_LOOP;
263 spin_unlock_irq(phba->host->host_lock);
264 } else {
265 /*
266 * If we are a N-port connected to a Fabric, fixup sparam's so
267 * logins to devices on remote loops work.
268 */
269 phba->fc_sparam.cmn.altBbCredit = 1;
270 }
271
272 phba->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
273 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
274 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof (struct lpfc_name));
275 ndlp->nlp_class_sup = 0;
276 if (sp->cls1.classValid)
277 ndlp->nlp_class_sup |= FC_COS_CLASS1;
278 if (sp->cls2.classValid)
279 ndlp->nlp_class_sup |= FC_COS_CLASS2;
280 if (sp->cls3.classValid)
281 ndlp->nlp_class_sup |= FC_COS_CLASS3;
282 if (sp->cls4.classValid)
283 ndlp->nlp_class_sup |= FC_COS_CLASS4;
284 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
285 sp->cmn.bbRcvSizeLsb;
286 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
287
288 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
289 if (!mbox)
290 goto fail;
291
292 phba->hba_state = LPFC_FABRIC_CFG_LINK;
293 lpfc_config_link(phba, mbox);
294 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
295
296 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT | MBX_STOP_IOCB);
297 if (rc == MBX_NOT_FINISHED)
298 goto fail_free_mbox;
299
300 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
301 if (!mbox)
302 goto fail;
303
304 if (lpfc_reg_login(phba, Fabric_DID, (uint8_t *) sp, mbox, 0))
305 goto fail_free_mbox;
306
dea31012005-04-17 16:05:31 -0500307 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
James Smart329f9bc2007-04-25 09:53:01 -0400308 mbox->context2 = lpfc_nlp_get(ndlp);
dea31012005-04-17 16:05:31 -0500309
310 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT | MBX_STOP_IOCB);
311 if (rc == MBX_NOT_FINISHED)
James Smart14691152006-12-02 13:34:28 -0500312 goto fail_issue_reg_login;
dea31012005-04-17 16:05:31 -0500313
314 return 0;
315
James Smart14691152006-12-02 13:34:28 -0500316 fail_issue_reg_login:
James Smart329f9bc2007-04-25 09:53:01 -0400317 lpfc_nlp_put(ndlp);
James Smart14691152006-12-02 13:34:28 -0500318 mp = (struct lpfc_dmabuf *) mbox->context1;
319 lpfc_mbuf_free(phba, mp->virt, mp->phys);
320 kfree(mp);
dea31012005-04-17 16:05:31 -0500321 fail_free_mbox:
322 mempool_free(mbox, phba->mbox_mem_pool);
323 fail:
324 return -ENXIO;
325}
326
327/*
328 * We FLOGIed into an NPort, initiate pt2pt protocol
329 */
330static int
331lpfc_cmpl_els_flogi_nport(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
332 struct serv_parm *sp)
333{
334 LPFC_MBOXQ_t *mbox;
335 int rc;
336
337 spin_lock_irq(phba->host->host_lock);
338 phba->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
339 spin_unlock_irq(phba->host->host_lock);
340
341 phba->fc_edtov = FF_DEF_EDTOV;
342 phba->fc_ratov = FF_DEF_RATOV;
343 rc = memcmp(&phba->fc_portname, &sp->portName,
344 sizeof(struct lpfc_name));
345 if (rc >= 0) {
346 /* This side will initiate the PLOGI */
347 spin_lock_irq(phba->host->host_lock);
348 phba->fc_flag |= FC_PT2PT_PLOGI;
349 spin_unlock_irq(phba->host->host_lock);
350
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)
358 phba->fc_myDID = PT2PT_LocalID;
359
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 Smart685f0bf2007-04-25 09:53:08 -0400375 ndlp = lpfc_findnode_did(phba, 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
385 lpfc_nlp_init(phba, ndlp, PT2PT_RemoteID);
386 }
387
388 memcpy(&ndlp->nlp_portname, &sp->portName,
389 sizeof(struct lpfc_name));
390 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
391 sizeof(struct lpfc_name));
James Smartde0c5b32007-04-25 09:52:27 -0400392 lpfc_nlp_set_state(phba, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -0500393 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
394 } else {
395 /* This side will wait for the PLOGI */
James Smart329f9bc2007-04-25 09:53:01 -0400396 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500397 }
398
399 spin_lock_irq(phba->host->host_lock);
400 phba->fc_flag |= FC_PT2PT;
401 spin_unlock_irq(phba->host->host_lock);
402
403 /* Start discovery - this should just do CLEAR_LA */
404 lpfc_disc_start(phba);
405 return 0;
406 fail:
407 return -ENXIO;
408}
409
410static void
James Smart329f9bc2007-04-25 09:53:01 -0400411lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
412 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500413{
414 IOCB_t *irsp = &rspiocb->iocb;
415 struct lpfc_nodelist *ndlp = cmdiocb->context1;
416 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
417 struct serv_parm *sp;
418 int rc;
419
420 /* Check to see if link went down during discovery */
421 if (lpfc_els_chk_latt(phba)) {
James Smart329f9bc2007-04-25 09:53:01 -0400422 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500423 goto out;
424 }
425
426 if (irsp->ulpStatus) {
427 /* Check for retry */
428 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
429 /* ELS command is being retried */
430 goto out;
431 }
432 /* FLOGI failed, so there is no fabric */
433 spin_lock_irq(phba->host->host_lock);
434 phba->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
435 spin_unlock_irq(phba->host->host_lock);
436
James Smart329f9bc2007-04-25 09:53:01 -0400437 /* If private loop, then allow max outstanding els to be
dea31012005-04-17 16:05:31 -0500438 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
439 * alpa map would take too long otherwise.
440 */
441 if (phba->alpa_map[0] == 0) {
James Smart329f9bc2007-04-25 09:53:01 -0400442 phba->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
dea31012005-04-17 16:05:31 -0500443 }
444
445 /* FLOGI failure */
446 lpfc_printf_log(phba,
447 KERN_INFO,
448 LOG_ELS,
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500449 "%d:0100 FLOGI failure Data: x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -0500450 phba->brd_no,
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500451 irsp->ulpStatus, irsp->un.ulpWord[4],
452 irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -0500453 goto flogifail;
454 }
455
456 /*
457 * The FLogI succeeded. Sync the data for the CPU before
458 * accessing it.
459 */
460 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
461
462 sp = prsp->virt + sizeof(uint32_t);
463
464 /* FLOGI completes successfully */
465 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
466 "%d:0101 FLOGI completes sucessfully "
467 "Data: x%x x%x x%x x%x\n",
468 phba->brd_no,
469 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
470 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution);
471
472 if (phba->hba_state == LPFC_FLOGI) {
473 /*
474 * If Common Service Parameters indicate Nport
475 * we are point to point, if Fport we are Fabric.
476 */
477 if (sp->cmn.fPort)
478 rc = lpfc_cmpl_els_flogi_fabric(phba, ndlp, sp, irsp);
479 else
480 rc = lpfc_cmpl_els_flogi_nport(phba, ndlp, sp);
481
482 if (!rc)
483 goto out;
484 }
485
486flogifail:
James Smart329f9bc2007-04-25 09:53:01 -0400487 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500488
489 if (irsp->ulpStatus != IOSTAT_LOCAL_REJECT ||
490 (irsp->un.ulpWord[4] != IOERR_SLI_ABORTED &&
491 irsp->un.ulpWord[4] != IOERR_SLI_DOWN)) {
492 /* FLOGI failed, so just use loop map to make discovery list */
493 lpfc_disc_list_loopmap(phba);
494
495 /* Start discovery */
496 lpfc_disc_start(phba);
497 }
498
499out:
500 lpfc_els_free_iocb(phba, cmdiocb);
501}
502
503static int
504lpfc_issue_els_flogi(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
505 uint8_t retry)
506{
507 struct serv_parm *sp;
508 IOCB_t *icmd;
509 struct lpfc_iocbq *elsiocb;
510 struct lpfc_sli_ring *pring;
511 uint8_t *pcmd;
512 uint16_t cmdsize;
513 uint32_t tmo;
514 int rc;
515
516 pring = &phba->sli.ring[LPFC_ELS_RING];
517
518 cmdsize = (sizeof (uint32_t) + sizeof (struct serv_parm));
James Smart488d1462006-03-07 15:02:37 -0500519 elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry, ndlp,
520 ndlp->nlp_DID, ELS_CMD_FLOGI);
521 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500522 return 1;
dea31012005-04-17 16:05:31 -0500523
524 icmd = &elsiocb->iocb;
525 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
526
527 /* For FLOGI request, remainder of payload is service parameters */
528 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
529 pcmd += sizeof (uint32_t);
530 memcpy(pcmd, &phba->fc_sparam, sizeof (struct serv_parm));
531 sp = (struct serv_parm *) pcmd;
532
533 /* Setup CSPs accordingly for Fabric */
534 sp->cmn.e_d_tov = 0;
535 sp->cmn.w2.r_a_tov = 0;
536 sp->cls1.classValid = 0;
537 sp->cls2.seqDelivery = 1;
538 sp->cls3.seqDelivery = 1;
539 if (sp->cmn.fcphLow < FC_PH3)
540 sp->cmn.fcphLow = FC_PH3;
541 if (sp->cmn.fcphHigh < FC_PH3)
542 sp->cmn.fcphHigh = FC_PH3;
543
544 tmo = phba->fc_ratov;
545 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
546 lpfc_set_disctmo(phba);
547 phba->fc_ratov = tmo;
548
549 phba->fc_stat.elsXmitFLOGI++;
550 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
551 spin_lock_irq(phba->host->host_lock);
552 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
553 spin_unlock_irq(phba->host->host_lock);
554 if (rc == IOCB_ERROR) {
555 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500556 return 1;
dea31012005-04-17 16:05:31 -0500557 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500558 return 0;
dea31012005-04-17 16:05:31 -0500559}
560
561int
562lpfc_els_abort_flogi(struct lpfc_hba * phba)
563{
564 struct lpfc_sli_ring *pring;
565 struct lpfc_iocbq *iocb, *next_iocb;
566 struct lpfc_nodelist *ndlp;
567 IOCB_t *icmd;
568
569 /* Abort outstanding I/O on NPort <nlp_DID> */
570 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
571 "%d:0201 Abort outstanding I/O on NPort x%x\n",
572 phba->brd_no, Fabric_DID);
573
574 pring = &phba->sli.ring[LPFC_ELS_RING];
575
576 /*
577 * Check the txcmplq for an iocb that matches the nport the driver is
578 * searching for.
579 */
580 spin_lock_irq(phba->host->host_lock);
581 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
582 icmd = &iocb->iocb;
583 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) {
584 ndlp = (struct lpfc_nodelist *)(iocb->context1);
James Smart07951072007-04-25 09:51:38 -0400585 if (ndlp && (ndlp->nlp_DID == Fabric_DID))
586 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
dea31012005-04-17 16:05:31 -0500587 }
588 }
589 spin_unlock_irq(phba->host->host_lock);
590
591 return 0;
592}
593
594int
James Smart685f0bf2007-04-25 09:53:08 -0400595lpfc_initial_flogi(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500596{
597 struct lpfc_nodelist *ndlp;
598
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500599 /* First look for the Fabric ndlp */
James Smart685f0bf2007-04-25 09:53:08 -0400600 ndlp = lpfc_findnode_did(phba, Fabric_DID);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500601 if (!ndlp) {
dea31012005-04-17 16:05:31 -0500602 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500603 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
604 if (!ndlp)
605 return 0;
dea31012005-04-17 16:05:31 -0500606 lpfc_nlp_init(phba, ndlp, Fabric_DID);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500607 } else {
James Smartde0c5b32007-04-25 09:52:27 -0400608 lpfc_dequeue_node(phba, ndlp);
dea31012005-04-17 16:05:31 -0500609 }
610 if (lpfc_issue_els_flogi(phba, ndlp, 0)) {
James Smart329f9bc2007-04-25 09:53:01 -0400611 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500612 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500613 return 1;
dea31012005-04-17 16:05:31 -0500614}
615
616static void
617lpfc_more_plogi(struct lpfc_hba * phba)
618{
619 int sentplogi;
620
621 if (phba->num_disc_nodes)
622 phba->num_disc_nodes--;
623
624 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
625 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
626 "%d:0232 Continue discovery with %d PLOGIs to go "
627 "Data: x%x x%x x%x\n",
628 phba->brd_no, phba->num_disc_nodes, phba->fc_plogi_cnt,
629 phba->fc_flag, phba->hba_state);
630
631 /* Check to see if there are more PLOGIs to be sent */
632 if (phba->fc_flag & FC_NLP_MORE) {
633 /* go thru NPR list and issue any remaining ELS PLOGIs */
634 sentplogi = lpfc_els_disc_plogi(phba);
635 }
636 return;
637}
638
James Smart488d1462006-03-07 15:02:37 -0500639static struct lpfc_nodelist *
James Smart685f0bf2007-04-25 09:53:08 -0400640lpfc_plogi_confirm_nport(struct lpfc_hba *phba, struct lpfc_dmabuf *prsp,
James Smart488d1462006-03-07 15:02:37 -0500641 struct lpfc_nodelist *ndlp)
642{
643 struct lpfc_nodelist *new_ndlp;
James Smart488d1462006-03-07 15:02:37 -0500644 uint32_t *lp;
645 struct serv_parm *sp;
646 uint8_t name[sizeof (struct lpfc_name)];
647 uint32_t rc;
648
James Smart2fb9bd82006-12-02 13:33:57 -0500649 /* Fabric nodes can have the same WWPN so we don't bother searching
650 * by WWPN. Just return the ndlp that was given to us.
651 */
652 if (ndlp->nlp_type & NLP_FABRIC)
653 return ndlp;
654
James Smart488d1462006-03-07 15:02:37 -0500655 lp = (uint32_t *) prsp->virt;
656 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
James Smart685f0bf2007-04-25 09:53:08 -0400657 memset(name, 0, sizeof(struct lpfc_name));
James Smart488d1462006-03-07 15:02:37 -0500658
James Smart685f0bf2007-04-25 09:53:08 -0400659 /* Now we find out if the NPort we are logging into, matches the WWPN
James Smart488d1462006-03-07 15:02:37 -0500660 * we have for that ndlp. If not, we have some work to do.
661 */
James Smart685f0bf2007-04-25 09:53:08 -0400662 new_ndlp = lpfc_findnode_wwpn(phba, &sp->portName);
James Smart488d1462006-03-07 15:02:37 -0500663
James Smart92795652006-07-06 15:50:02 -0400664 if (new_ndlp == ndlp)
James Smart488d1462006-03-07 15:02:37 -0500665 return ndlp;
James Smart488d1462006-03-07 15:02:37 -0500666
667 if (!new_ndlp) {
James Smart92795652006-07-06 15:50:02 -0400668 rc =
669 memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name));
670 if (!rc)
671 return ndlp;
James Smart488d1462006-03-07 15:02:37 -0500672 new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
673 if (!new_ndlp)
674 return ndlp;
675
676 lpfc_nlp_init(phba, new_ndlp, ndlp->nlp_DID);
677 }
678
679 lpfc_unreg_rpi(phba, new_ndlp);
James Smart488d1462006-03-07 15:02:37 -0500680 new_ndlp->nlp_DID = ndlp->nlp_DID;
James Smart92795652006-07-06 15:50:02 -0400681 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
James Smartde0c5b32007-04-25 09:52:27 -0400682 lpfc_nlp_set_state(phba, new_ndlp, ndlp->nlp_state);
James Smart488d1462006-03-07 15:02:37 -0500683
684 /* Move this back to NPR list */
James Smartde0c5b32007-04-25 09:52:27 -0400685 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0)
686 lpfc_drop_node(phba, ndlp);
James Smart92795652006-07-06 15:50:02 -0400687 else {
688 lpfc_unreg_rpi(phba, ndlp);
689 ndlp->nlp_DID = 0; /* Two ndlps cannot have the same did */
James Smartde0c5b32007-04-25 09:52:27 -0400690 lpfc_nlp_set_state(phba, ndlp, NLP_STE_NPR_NODE);
James Smart92795652006-07-06 15:50:02 -0400691 }
James Smart488d1462006-03-07 15:02:37 -0500692 return new_ndlp;
693}
694
dea31012005-04-17 16:05:31 -0500695static void
696lpfc_cmpl_els_plogi(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
697 struct lpfc_iocbq * rspiocb)
698{
699 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -0500700 struct lpfc_nodelist *ndlp;
James Smart92795652006-07-06 15:50:02 -0400701 struct lpfc_dmabuf *prsp;
dea31012005-04-17 16:05:31 -0500702 int disc, rc, did, type;
703
dea31012005-04-17 16:05:31 -0500704 /* we pass cmdiocb to state machine which needs rspiocb as well */
705 cmdiocb->context_un.rsp_iocb = rspiocb;
706
707 irsp = &rspiocb->iocb;
James Smart685f0bf2007-04-25 09:53:08 -0400708 ndlp = lpfc_findnode_did(phba, irsp->un.elsreq64.remoteID);
James Smart488d1462006-03-07 15:02:37 -0500709 if (!ndlp)
710 goto out;
dea31012005-04-17 16:05:31 -0500711
712 /* Since ndlp can be freed in the disc state machine, note if this node
713 * is being used during discovery.
714 */
715 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500716 spin_lock_irq(phba->host->host_lock);
James Smart488d1462006-03-07 15:02:37 -0500717 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500718 spin_unlock_irq(phba->host->host_lock);
dea31012005-04-17 16:05:31 -0500719 rc = 0;
720
721 /* PLOGI completes to NPort <nlp_DID> */
722 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
723 "%d:0102 PLOGI completes to NPort x%x "
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500724 "Data: x%x x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -0500725 phba->brd_no, ndlp->nlp_DID, irsp->ulpStatus,
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500726 irsp->un.ulpWord[4], irsp->ulpTimeout, disc,
727 phba->num_disc_nodes);
dea31012005-04-17 16:05:31 -0500728
729 /* Check to see if link went down during discovery */
730 if (lpfc_els_chk_latt(phba)) {
731 spin_lock_irq(phba->host->host_lock);
732 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
733 spin_unlock_irq(phba->host->host_lock);
734 goto out;
735 }
736
737 /* ndlp could be freed in DSM, save these values now */
738 type = ndlp->nlp_type;
739 did = ndlp->nlp_DID;
740
741 if (irsp->ulpStatus) {
742 /* Check for retry */
743 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
744 /* ELS command is being retried */
745 if (disc) {
746 spin_lock_irq(phba->host->host_lock);
747 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
748 spin_unlock_irq(phba->host->host_lock);
749 }
750 goto out;
751 }
752
753 /* PLOGI failed */
754 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
755 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
756 ((irsp->un.ulpWord[4] == IOERR_SLI_ABORTED) ||
James.Smart@Emulex.Com6281bfe2005-11-28 11:41:33 -0500757 (irsp->un.ulpWord[4] == IOERR_LINK_DOWN) ||
dea31012005-04-17 16:05:31 -0500758 (irsp->un.ulpWord[4] == IOERR_SLI_DOWN))) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500759 rc = NLP_STE_FREED_NODE;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500760 } else {
dea31012005-04-17 16:05:31 -0500761 rc = lpfc_disc_state_machine(phba, ndlp, cmdiocb,
762 NLP_EVT_CMPL_PLOGI);
763 }
764 } else {
765 /* Good status, call state machine */
James Smart92795652006-07-06 15:50:02 -0400766 prsp = list_entry(((struct lpfc_dmabuf *)
767 cmdiocb->context2)->list.next,
768 struct lpfc_dmabuf, list);
769 ndlp = lpfc_plogi_confirm_nport(phba, prsp, ndlp);
dea31012005-04-17 16:05:31 -0500770 rc = lpfc_disc_state_machine(phba, ndlp, cmdiocb,
771 NLP_EVT_CMPL_PLOGI);
772 }
773
dea31012005-04-17 16:05:31 -0500774 if (disc && phba->num_disc_nodes) {
775 /* Check to see if there are more PLOGIs to be sent */
776 lpfc_more_plogi(phba);
dea31012005-04-17 16:05:31 -0500777
James Smart10d4e952006-04-15 11:53:15 -0400778 if (phba->num_disc_nodes == 0) {
779 spin_lock_irq(phba->host->host_lock);
780 phba->fc_flag &= ~FC_NDISC_ACTIVE;
781 spin_unlock_irq(phba->host->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500782
James Smart10d4e952006-04-15 11:53:15 -0400783 lpfc_can_disctmo(phba);
784 if (phba->fc_flag & FC_RSCN_MODE) {
785 /*
786 * Check to see if more RSCNs came in while
787 * we were processing this one.
788 */
789 if ((phba->fc_rscn_id_cnt == 0) &&
790 (!(phba->fc_flag & FC_RSCN_DISCOVERY))) {
791 spin_lock_irq(phba->host->host_lock);
792 phba->fc_flag &= ~FC_RSCN_MODE;
793 spin_unlock_irq(phba->host->host_lock);
794 } else {
795 lpfc_els_handle_rscn(phba);
796 }
dea31012005-04-17 16:05:31 -0500797 }
798 }
799 }
800
801out:
802 lpfc_els_free_iocb(phba, cmdiocb);
803 return;
804}
805
806int
James Smart488d1462006-03-07 15:02:37 -0500807lpfc_issue_els_plogi(struct lpfc_hba * phba, uint32_t did, uint8_t retry)
dea31012005-04-17 16:05:31 -0500808{
809 struct serv_parm *sp;
810 IOCB_t *icmd;
811 struct lpfc_iocbq *elsiocb;
812 struct lpfc_sli_ring *pring;
813 struct lpfc_sli *psli;
814 uint8_t *pcmd;
815 uint16_t cmdsize;
816
817 psli = &phba->sli;
818 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
819
820 cmdsize = (sizeof (uint32_t) + sizeof (struct serv_parm));
Randy Dunlap041976f2006-06-25 01:58:51 -0700821 elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry, NULL, did,
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500822 ELS_CMD_PLOGI);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500823 if (!elsiocb)
824 return 1;
dea31012005-04-17 16:05:31 -0500825
826 icmd = &elsiocb->iocb;
827 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
828
829 /* For PLOGI request, remainder of payload is service parameters */
830 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
831 pcmd += sizeof (uint32_t);
832 memcpy(pcmd, &phba->fc_sparam, sizeof (struct serv_parm));
833 sp = (struct serv_parm *) pcmd;
834
835 if (sp->cmn.fcphLow < FC_PH_4_3)
836 sp->cmn.fcphLow = FC_PH_4_3;
837
838 if (sp->cmn.fcphHigh < FC_PH3)
839 sp->cmn.fcphHigh = FC_PH3;
840
841 phba->fc_stat.elsXmitPLOGI++;
842 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
843 spin_lock_irq(phba->host->host_lock);
dea31012005-04-17 16:05:31 -0500844 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
dea31012005-04-17 16:05:31 -0500845 spin_unlock_irq(phba->host->host_lock);
846 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500847 return 1;
dea31012005-04-17 16:05:31 -0500848 }
849 spin_unlock_irq(phba->host->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500850 return 0;
dea31012005-04-17 16:05:31 -0500851}
852
853static void
854lpfc_cmpl_els_prli(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
855 struct lpfc_iocbq * rspiocb)
856{
857 IOCB_t *irsp;
858 struct lpfc_sli *psli;
859 struct lpfc_nodelist *ndlp;
860
861 psli = &phba->sli;
862 /* we pass cmdiocb to state machine which needs rspiocb as well */
863 cmdiocb->context_un.rsp_iocb = rspiocb;
864
865 irsp = &(rspiocb->iocb);
866 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
867 spin_lock_irq(phba->host->host_lock);
868 ndlp->nlp_flag &= ~NLP_PRLI_SND;
869 spin_unlock_irq(phba->host->host_lock);
870
871 /* PRLI completes to NPort <nlp_DID> */
872 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
873 "%d:0103 PRLI completes to NPort x%x "
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500874 "Data: x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -0500875 phba->brd_no, ndlp->nlp_DID, irsp->ulpStatus,
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500876 irsp->un.ulpWord[4], irsp->ulpTimeout,
877 phba->num_disc_nodes);
dea31012005-04-17 16:05:31 -0500878
879 phba->fc_prli_sent--;
880 /* Check to see if link went down during discovery */
881 if (lpfc_els_chk_latt(phba))
882 goto out;
883
884 if (irsp->ulpStatus) {
885 /* Check for retry */
886 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
887 /* ELS command is being retried */
888 goto out;
889 }
890 /* PRLI failed */
891 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
892 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
893 ((irsp->un.ulpWord[4] == IOERR_SLI_ABORTED) ||
James.Smart@Emulex.Com6281bfe2005-11-28 11:41:33 -0500894 (irsp->un.ulpWord[4] == IOERR_LINK_DOWN) ||
dea31012005-04-17 16:05:31 -0500895 (irsp->un.ulpWord[4] == IOERR_SLI_DOWN))) {
896 goto out;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500897 } else {
dea31012005-04-17 16:05:31 -0500898 lpfc_disc_state_machine(phba, ndlp, cmdiocb,
899 NLP_EVT_CMPL_PRLI);
900 }
901 } else {
902 /* Good status, call state machine */
903 lpfc_disc_state_machine(phba, ndlp, cmdiocb, NLP_EVT_CMPL_PRLI);
904 }
905
906out:
907 lpfc_els_free_iocb(phba, cmdiocb);
908 return;
909}
910
911int
912lpfc_issue_els_prli(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
913 uint8_t retry)
914{
915 PRLI *npr;
916 IOCB_t *icmd;
917 struct lpfc_iocbq *elsiocb;
918 struct lpfc_sli_ring *pring;
919 struct lpfc_sli *psli;
920 uint8_t *pcmd;
921 uint16_t cmdsize;
922
923 psli = &phba->sli;
924 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
925
926 cmdsize = (sizeof (uint32_t) + sizeof (PRLI));
James Smart488d1462006-03-07 15:02:37 -0500927 elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry, ndlp,
928 ndlp->nlp_DID, ELS_CMD_PRLI);
929 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500930 return 1;
dea31012005-04-17 16:05:31 -0500931
932 icmd = &elsiocb->iocb;
933 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
934
935 /* For PRLI request, remainder of payload is service parameters */
936 memset(pcmd, 0, (sizeof (PRLI) + sizeof (uint32_t)));
937 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
938 pcmd += sizeof (uint32_t);
939
940 /* For PRLI, remainder of payload is PRLI parameter page */
941 npr = (PRLI *) pcmd;
942 /*
943 * If our firmware version is 3.20 or later,
944 * set the following bits for FC-TAPE support.
945 */
946 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
947 npr->ConfmComplAllowed = 1;
948 npr->Retry = 1;
949 npr->TaskRetryIdReq = 1;
950 }
951 npr->estabImagePair = 1;
952 npr->readXferRdyDis = 1;
953
954 /* For FCP support */
955 npr->prliType = PRLI_FCP_TYPE;
956 npr->initiatorFunc = 1;
957
958 phba->fc_stat.elsXmitPRLI++;
959 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
960 spin_lock_irq(phba->host->host_lock);
961 ndlp->nlp_flag |= NLP_PRLI_SND;
962 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
963 ndlp->nlp_flag &= ~NLP_PRLI_SND;
964 spin_unlock_irq(phba->host->host_lock);
965 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500966 return 1;
dea31012005-04-17 16:05:31 -0500967 }
968 spin_unlock_irq(phba->host->host_lock);
969 phba->fc_prli_sent++;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500970 return 0;
dea31012005-04-17 16:05:31 -0500971}
972
973static void
974lpfc_more_adisc(struct lpfc_hba * phba)
975{
976 int sentadisc;
977
978 if (phba->num_disc_nodes)
979 phba->num_disc_nodes--;
980
981 /* Continue discovery with <num_disc_nodes> ADISCs to go */
982 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
983 "%d:0210 Continue discovery with %d ADISCs to go "
984 "Data: x%x x%x x%x\n",
985 phba->brd_no, phba->num_disc_nodes, phba->fc_adisc_cnt,
986 phba->fc_flag, phba->hba_state);
987
988 /* Check to see if there are more ADISCs to be sent */
989 if (phba->fc_flag & FC_NLP_MORE) {
990 lpfc_set_disctmo(phba);
991
992 /* go thru NPR list and issue any remaining ELS ADISCs */
993 sentadisc = lpfc_els_disc_adisc(phba);
994 }
995 return;
996}
997
998static void
999lpfc_rscn_disc(struct lpfc_hba * phba)
1000{
1001 /* RSCN discovery */
1002 /* go thru NPR list and issue ELS PLOGIs */
1003 if (phba->fc_npr_cnt) {
1004 if (lpfc_els_disc_plogi(phba))
1005 return;
1006 }
1007 if (phba->fc_flag & FC_RSCN_MODE) {
1008 /* Check to see if more RSCNs came in while we were
1009 * processing this one.
1010 */
1011 if ((phba->fc_rscn_id_cnt == 0) &&
1012 (!(phba->fc_flag & FC_RSCN_DISCOVERY))) {
1013 spin_lock_irq(phba->host->host_lock);
1014 phba->fc_flag &= ~FC_RSCN_MODE;
1015 spin_unlock_irq(phba->host->host_lock);
1016 } else {
1017 lpfc_els_handle_rscn(phba);
1018 }
1019 }
1020}
1021
1022static void
1023lpfc_cmpl_els_adisc(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
1024 struct lpfc_iocbq * rspiocb)
1025{
1026 IOCB_t *irsp;
1027 struct lpfc_sli *psli;
1028 struct lpfc_nodelist *ndlp;
1029 LPFC_MBOXQ_t *mbox;
1030 int disc, rc;
1031
1032 psli = &phba->sli;
1033
1034 /* we pass cmdiocb to state machine which needs rspiocb as well */
1035 cmdiocb->context_un.rsp_iocb = rspiocb;
1036
1037 irsp = &(rspiocb->iocb);
1038 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
dea31012005-04-17 16:05:31 -05001039
1040 /* Since ndlp can be freed in the disc state machine, note if this node
1041 * is being used during discovery.
1042 */
1043 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001044 spin_lock_irq(phba->host->host_lock);
1045 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
1046 spin_unlock_irq(phba->host->host_lock);
dea31012005-04-17 16:05:31 -05001047
1048 /* ADISC completes to NPort <nlp_DID> */
1049 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1050 "%d:0104 ADISC completes to NPort x%x "
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001051 "Data: x%x x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -05001052 phba->brd_no, ndlp->nlp_DID, irsp->ulpStatus,
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001053 irsp->un.ulpWord[4], irsp->ulpTimeout, disc,
1054 phba->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001055
1056 /* Check to see if link went down during discovery */
1057 if (lpfc_els_chk_latt(phba)) {
1058 spin_lock_irq(phba->host->host_lock);
1059 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1060 spin_unlock_irq(phba->host->host_lock);
1061 goto out;
1062 }
1063
1064 if (irsp->ulpStatus) {
1065 /* Check for retry */
1066 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1067 /* ELS command is being retried */
1068 if (disc) {
1069 spin_lock_irq(phba->host->host_lock);
1070 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1071 spin_unlock_irq(phba->host->host_lock);
1072 lpfc_set_disctmo(phba);
1073 }
1074 goto out;
1075 }
1076 /* ADISC failed */
1077 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001078 if ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
1079 ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) &&
1080 (irsp->un.ulpWord[4] != IOERR_LINK_DOWN) &&
1081 (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) {
dea31012005-04-17 16:05:31 -05001082 lpfc_disc_state_machine(phba, ndlp, cmdiocb,
1083 NLP_EVT_CMPL_ADISC);
1084 }
1085 } else {
1086 /* Good status, call state machine */
1087 lpfc_disc_state_machine(phba, ndlp, cmdiocb,
1088 NLP_EVT_CMPL_ADISC);
1089 }
1090
1091 if (disc && phba->num_disc_nodes) {
1092 /* Check to see if there are more ADISCs to be sent */
1093 lpfc_more_adisc(phba);
1094
1095 /* Check to see if we are done with ADISC authentication */
1096 if (phba->num_disc_nodes == 0) {
1097 lpfc_can_disctmo(phba);
1098 /* If we get here, there is nothing left to wait for */
1099 if ((phba->hba_state < LPFC_HBA_READY) &&
1100 (phba->hba_state != LPFC_CLEAR_LA)) {
1101 /* Link up discovery */
1102 if ((mbox = mempool_alloc(phba->mbox_mem_pool,
1103 GFP_KERNEL))) {
1104 phba->hba_state = LPFC_CLEAR_LA;
1105 lpfc_clear_la(phba, mbox);
1106 mbox->mbox_cmpl =
1107 lpfc_mbx_cmpl_clear_la;
1108 rc = lpfc_sli_issue_mbox
1109 (phba, mbox,
1110 (MBX_NOWAIT | MBX_STOP_IOCB));
1111 if (rc == MBX_NOT_FINISHED) {
1112 mempool_free(mbox,
1113 phba->mbox_mem_pool);
1114 lpfc_disc_flush_list(phba);
James Smarta4bc3372006-12-02 13:34:16 -05001115 psli->ring[(psli->extra_ring)].
dea31012005-04-17 16:05:31 -05001116 flag &=
1117 ~LPFC_STOP_IOCB_EVENT;
1118 psli->ring[(psli->fcp_ring)].
1119 flag &=
1120 ~LPFC_STOP_IOCB_EVENT;
1121 psli->ring[(psli->next_ring)].
1122 flag &=
1123 ~LPFC_STOP_IOCB_EVENT;
1124 phba->hba_state =
1125 LPFC_HBA_READY;
1126 }
1127 }
1128 } else {
1129 lpfc_rscn_disc(phba);
1130 }
1131 }
1132 }
dea31012005-04-17 16:05:31 -05001133out:
1134 lpfc_els_free_iocb(phba, cmdiocb);
1135 return;
1136}
1137
1138int
1139lpfc_issue_els_adisc(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
1140 uint8_t retry)
1141{
1142 ADISC *ap;
1143 IOCB_t *icmd;
1144 struct lpfc_iocbq *elsiocb;
1145 struct lpfc_sli_ring *pring;
1146 struct lpfc_sli *psli;
1147 uint8_t *pcmd;
1148 uint16_t cmdsize;
1149
1150 psli = &phba->sli;
1151 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1152
1153 cmdsize = (sizeof (uint32_t) + sizeof (ADISC));
James Smart488d1462006-03-07 15:02:37 -05001154 elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry, ndlp,
1155 ndlp->nlp_DID, ELS_CMD_ADISC);
1156 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001157 return 1;
dea31012005-04-17 16:05:31 -05001158
1159 icmd = &elsiocb->iocb;
1160 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1161
1162 /* For ADISC request, remainder of payload is service parameters */
1163 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
1164 pcmd += sizeof (uint32_t);
1165
1166 /* Fill in ADISC payload */
1167 ap = (ADISC *) pcmd;
1168 ap->hardAL_PA = phba->fc_pref_ALPA;
1169 memcpy(&ap->portName, &phba->fc_portname, sizeof (struct lpfc_name));
1170 memcpy(&ap->nodeName, &phba->fc_nodename, sizeof (struct lpfc_name));
1171 ap->DID = be32_to_cpu(phba->fc_myDID);
1172
1173 phba->fc_stat.elsXmitADISC++;
1174 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
1175 spin_lock_irq(phba->host->host_lock);
1176 ndlp->nlp_flag |= NLP_ADISC_SND;
1177 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
1178 ndlp->nlp_flag &= ~NLP_ADISC_SND;
1179 spin_unlock_irq(phba->host->host_lock);
1180 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001181 return 1;
dea31012005-04-17 16:05:31 -05001182 }
1183 spin_unlock_irq(phba->host->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001184 return 0;
dea31012005-04-17 16:05:31 -05001185}
1186
1187static void
1188lpfc_cmpl_els_logo(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
1189 struct lpfc_iocbq * rspiocb)
1190{
1191 IOCB_t *irsp;
1192 struct lpfc_sli *psli;
1193 struct lpfc_nodelist *ndlp;
1194
1195 psli = &phba->sli;
1196 /* we pass cmdiocb to state machine which needs rspiocb as well */
1197 cmdiocb->context_un.rsp_iocb = rspiocb;
1198
1199 irsp = &(rspiocb->iocb);
1200 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1201 spin_lock_irq(phba->host->host_lock);
1202 ndlp->nlp_flag &= ~NLP_LOGO_SND;
1203 spin_unlock_irq(phba->host->host_lock);
1204
1205 /* LOGO completes to NPort <nlp_DID> */
1206 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1207 "%d:0105 LOGO completes to NPort x%x "
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001208 "Data: x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -05001209 phba->brd_no, ndlp->nlp_DID, irsp->ulpStatus,
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001210 irsp->un.ulpWord[4], irsp->ulpTimeout,
1211 phba->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001212
1213 /* Check to see if link went down during discovery */
1214 if (lpfc_els_chk_latt(phba))
1215 goto out;
1216
1217 if (irsp->ulpStatus) {
1218 /* Check for retry */
1219 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1220 /* ELS command is being retried */
1221 goto out;
1222 }
1223 /* LOGO failed */
1224 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1225 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
1226 ((irsp->un.ulpWord[4] == IOERR_SLI_ABORTED) ||
James.Smart@Emulex.Com6281bfe2005-11-28 11:41:33 -05001227 (irsp->un.ulpWord[4] == IOERR_LINK_DOWN) ||
dea31012005-04-17 16:05:31 -05001228 (irsp->un.ulpWord[4] == IOERR_SLI_DOWN))) {
1229 goto out;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001230 } else {
dea31012005-04-17 16:05:31 -05001231 lpfc_disc_state_machine(phba, ndlp, cmdiocb,
1232 NLP_EVT_CMPL_LOGO);
1233 }
1234 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001235 /* Good status, call state machine.
1236 * This will unregister the rpi if needed.
1237 */
dea31012005-04-17 16:05:31 -05001238 lpfc_disc_state_machine(phba, ndlp, cmdiocb, NLP_EVT_CMPL_LOGO);
dea31012005-04-17 16:05:31 -05001239 }
1240
1241out:
1242 lpfc_els_free_iocb(phba, cmdiocb);
1243 return;
1244}
1245
1246int
1247lpfc_issue_els_logo(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
1248 uint8_t retry)
1249{
1250 IOCB_t *icmd;
1251 struct lpfc_iocbq *elsiocb;
1252 struct lpfc_sli_ring *pring;
1253 struct lpfc_sli *psli;
1254 uint8_t *pcmd;
1255 uint16_t cmdsize;
1256
1257 psli = &phba->sli;
1258 pring = &psli->ring[LPFC_ELS_RING];
1259
James Smart10d4e952006-04-15 11:53:15 -04001260 cmdsize = (2 * sizeof (uint32_t)) + sizeof (struct lpfc_name);
James Smart488d1462006-03-07 15:02:37 -05001261 elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry, ndlp,
1262 ndlp->nlp_DID, ELS_CMD_LOGO);
1263 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001264 return 1;
dea31012005-04-17 16:05:31 -05001265
1266 icmd = &elsiocb->iocb;
1267 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1268 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
1269 pcmd += sizeof (uint32_t);
1270
1271 /* Fill in LOGO payload */
1272 *((uint32_t *) (pcmd)) = be32_to_cpu(phba->fc_myDID);
1273 pcmd += sizeof (uint32_t);
1274 memcpy(pcmd, &phba->fc_portname, sizeof (struct lpfc_name));
1275
1276 phba->fc_stat.elsXmitLOGO++;
1277 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
1278 spin_lock_irq(phba->host->host_lock);
1279 ndlp->nlp_flag |= NLP_LOGO_SND;
1280 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
1281 ndlp->nlp_flag &= ~NLP_LOGO_SND;
1282 spin_unlock_irq(phba->host->host_lock);
1283 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001284 return 1;
dea31012005-04-17 16:05:31 -05001285 }
1286 spin_unlock_irq(phba->host->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001287 return 0;
dea31012005-04-17 16:05:31 -05001288}
1289
1290static void
1291lpfc_cmpl_els_cmd(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
1292 struct lpfc_iocbq * rspiocb)
1293{
1294 IOCB_t *irsp;
1295
1296 irsp = &rspiocb->iocb;
1297
1298 /* ELS cmd tag <ulpIoTag> completes */
1299 lpfc_printf_log(phba,
1300 KERN_INFO,
1301 LOG_ELS,
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001302 "%d:0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -05001303 phba->brd_no,
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001304 irsp->ulpIoTag, irsp->ulpStatus,
1305 irsp->un.ulpWord[4], irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -05001306
1307 /* Check to see if link went down during discovery */
1308 lpfc_els_chk_latt(phba);
1309 lpfc_els_free_iocb(phba, cmdiocb);
1310 return;
1311}
1312
1313int
1314lpfc_issue_els_scr(struct lpfc_hba * phba, uint32_t nportid, uint8_t retry)
1315{
1316 IOCB_t *icmd;
1317 struct lpfc_iocbq *elsiocb;
1318 struct lpfc_sli_ring *pring;
1319 struct lpfc_sli *psli;
1320 uint8_t *pcmd;
1321 uint16_t cmdsize;
1322 struct lpfc_nodelist *ndlp;
1323
1324 psli = &phba->sli;
1325 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1326 cmdsize = (sizeof (uint32_t) + sizeof (SCR));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001327 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1328 if (!ndlp)
1329 return 1;
dea31012005-04-17 16:05:31 -05001330
1331 lpfc_nlp_init(phba, ndlp, nportid);
1332
James Smart488d1462006-03-07 15:02:37 -05001333 elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry, ndlp,
1334 ndlp->nlp_DID, ELS_CMD_SCR);
1335 if (!elsiocb) {
James Smart329f9bc2007-04-25 09:53:01 -04001336 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001337 return 1;
dea31012005-04-17 16:05:31 -05001338 }
1339
1340 icmd = &elsiocb->iocb;
1341 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1342
1343 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
1344 pcmd += sizeof (uint32_t);
1345
1346 /* For SCR, remainder of payload is SCR parameter page */
1347 memset(pcmd, 0, sizeof (SCR));
1348 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
1349
1350 phba->fc_stat.elsXmitSCR++;
1351 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
1352 spin_lock_irq(phba->host->host_lock);
1353 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
1354 spin_unlock_irq(phba->host->host_lock);
James Smart329f9bc2007-04-25 09:53:01 -04001355 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001356 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001357 return 1;
dea31012005-04-17 16:05:31 -05001358 }
1359 spin_unlock_irq(phba->host->host_lock);
James Smart329f9bc2007-04-25 09:53:01 -04001360 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001361 return 0;
dea31012005-04-17 16:05:31 -05001362}
1363
1364static int
1365lpfc_issue_els_farpr(struct lpfc_hba * phba, uint32_t nportid, uint8_t retry)
1366{
1367 IOCB_t *icmd;
1368 struct lpfc_iocbq *elsiocb;
1369 struct lpfc_sli_ring *pring;
1370 struct lpfc_sli *psli;
1371 FARP *fp;
1372 uint8_t *pcmd;
1373 uint32_t *lp;
1374 uint16_t cmdsize;
1375 struct lpfc_nodelist *ondlp;
1376 struct lpfc_nodelist *ndlp;
1377
1378 psli = &phba->sli;
1379 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1380 cmdsize = (sizeof (uint32_t) + sizeof (FARP));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001381 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1382 if (!ndlp)
1383 return 1;
dea31012005-04-17 16:05:31 -05001384 lpfc_nlp_init(phba, ndlp, nportid);
1385
James Smart488d1462006-03-07 15:02:37 -05001386 elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry, ndlp,
1387 ndlp->nlp_DID, ELS_CMD_RNID);
1388 if (!elsiocb) {
James Smart329f9bc2007-04-25 09:53:01 -04001389 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001390 return 1;
dea31012005-04-17 16:05:31 -05001391 }
1392
1393 icmd = &elsiocb->iocb;
1394 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1395
1396 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
1397 pcmd += sizeof (uint32_t);
1398
1399 /* Fill in FARPR payload */
1400 fp = (FARP *) (pcmd);
1401 memset(fp, 0, sizeof (FARP));
1402 lp = (uint32_t *) pcmd;
1403 *lp++ = be32_to_cpu(nportid);
1404 *lp++ = be32_to_cpu(phba->fc_myDID);
1405 fp->Rflags = 0;
1406 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
1407
1408 memcpy(&fp->RportName, &phba->fc_portname, sizeof (struct lpfc_name));
1409 memcpy(&fp->RnodeName, &phba->fc_nodename, sizeof (struct lpfc_name));
James Smart685f0bf2007-04-25 09:53:08 -04001410 if ((ondlp = lpfc_findnode_did(phba, nportid))) {
dea31012005-04-17 16:05:31 -05001411 memcpy(&fp->OportName, &ondlp->nlp_portname,
1412 sizeof (struct lpfc_name));
1413 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
1414 sizeof (struct lpfc_name));
1415 }
1416
1417 phba->fc_stat.elsXmitFARPR++;
1418 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
1419 spin_lock_irq(phba->host->host_lock);
1420 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
1421 spin_unlock_irq(phba->host->host_lock);
James Smart329f9bc2007-04-25 09:53:01 -04001422 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001423 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001424 return 1;
dea31012005-04-17 16:05:31 -05001425 }
1426 spin_unlock_irq(phba->host->host_lock);
James Smart329f9bc2007-04-25 09:53:01 -04001427 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001428 return 0;
dea31012005-04-17 16:05:31 -05001429}
1430
1431void
James Smartfdcebe22006-03-07 15:04:01 -05001432lpfc_cancel_retry_delay_tmo(struct lpfc_hba *phba, struct lpfc_nodelist * nlp)
1433{
1434 nlp->nlp_flag &= ~NLP_DELAY_TMO;
1435 del_timer_sync(&nlp->nlp_delayfunc);
1436 nlp->nlp_last_elscmd = 0;
1437
1438 if (!list_empty(&nlp->els_retry_evt.evt_listp))
1439 list_del_init(&nlp->els_retry_evt.evt_listp);
1440
1441 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
1442 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1443 if (phba->num_disc_nodes) {
1444 /* Check to see if there are more
1445 * PLOGIs to be sent
1446 */
1447 lpfc_more_plogi(phba);
James Smartfdcebe22006-03-07 15:04:01 -05001448
James Smart10d4e952006-04-15 11:53:15 -04001449 if (phba->num_disc_nodes == 0) {
1450 phba->fc_flag &= ~FC_NDISC_ACTIVE;
1451 lpfc_can_disctmo(phba);
1452 if (phba->fc_flag & FC_RSCN_MODE) {
1453 /*
1454 * Check to see if more RSCNs
1455 * came in while we were
1456 * processing this one.
1457 */
1458 if((phba->fc_rscn_id_cnt==0) &&
1459 !(phba->fc_flag & FC_RSCN_DISCOVERY)) {
1460 phba->fc_flag &= ~FC_RSCN_MODE;
1461 }
1462 else {
1463 lpfc_els_handle_rscn(phba);
1464 }
James Smartfdcebe22006-03-07 15:04:01 -05001465 }
1466 }
1467 }
1468 }
1469 return;
1470}
1471
1472void
dea31012005-04-17 16:05:31 -05001473lpfc_els_retry_delay(unsigned long ptr)
1474{
1475 struct lpfc_nodelist *ndlp;
1476 struct lpfc_hba *phba;
1477 unsigned long iflag;
1478 struct lpfc_work_evt *evtp;
1479
1480 ndlp = (struct lpfc_nodelist *)ptr;
1481 phba = ndlp->nlp_phba;
1482 evtp = &ndlp->els_retry_evt;
1483
1484 spin_lock_irqsave(phba->host->host_lock, iflag);
1485 if (!list_empty(&evtp->evt_listp)) {
1486 spin_unlock_irqrestore(phba->host->host_lock, iflag);
1487 return;
1488 }
1489
1490 evtp->evt_arg1 = ndlp;
1491 evtp->evt = LPFC_EVT_ELS_RETRY;
1492 list_add_tail(&evtp->evt_listp, &phba->work_list);
1493 if (phba->work_wait)
1494 wake_up(phba->work_wait);
1495
1496 spin_unlock_irqrestore(phba->host->host_lock, iflag);
1497 return;
1498}
1499
1500void
1501lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
1502{
1503 struct lpfc_hba *phba;
1504 uint32_t cmd;
1505 uint32_t did;
1506 uint8_t retry;
1507
1508 phba = ndlp->nlp_phba;
1509 spin_lock_irq(phba->host->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001510 did = ndlp->nlp_DID;
1511 cmd = ndlp->nlp_last_elscmd;
1512 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05001513
1514 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
1515 spin_unlock_irq(phba->host->host_lock);
1516 return;
1517 }
1518
1519 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
1520 spin_unlock_irq(phba->host->host_lock);
James Smart1a169682006-03-07 15:04:06 -05001521 /*
1522 * If a discovery event readded nlp_delayfunc after timer
1523 * firing and before processing the timer, cancel the
1524 * nlp_delayfunc.
1525 */
1526 del_timer_sync(&ndlp->nlp_delayfunc);
dea31012005-04-17 16:05:31 -05001527 retry = ndlp->nlp_retry;
1528
1529 switch (cmd) {
1530 case ELS_CMD_FLOGI:
1531 lpfc_issue_els_flogi(phba, ndlp, retry);
1532 break;
1533 case ELS_CMD_PLOGI:
James Smart488d1462006-03-07 15:02:37 -05001534 if(!lpfc_issue_els_plogi(phba, ndlp->nlp_DID, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001535 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smartde0c5b32007-04-25 09:52:27 -04001536 lpfc_nlp_set_state(phba, ndlp, NLP_STE_PLOGI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05001537 }
dea31012005-04-17 16:05:31 -05001538 break;
1539 case ELS_CMD_ADISC:
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05001540 if (!lpfc_issue_els_adisc(phba, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001541 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smartde0c5b32007-04-25 09:52:27 -04001542 lpfc_nlp_set_state(phba, ndlp, NLP_STE_ADISC_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05001543 }
dea31012005-04-17 16:05:31 -05001544 break;
1545 case ELS_CMD_PRLI:
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05001546 if (!lpfc_issue_els_prli(phba, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001547 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smartde0c5b32007-04-25 09:52:27 -04001548 lpfc_nlp_set_state(phba, ndlp, NLP_STE_PRLI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05001549 }
dea31012005-04-17 16:05:31 -05001550 break;
1551 case ELS_CMD_LOGO:
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05001552 if (!lpfc_issue_els_logo(phba, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001553 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smartde0c5b32007-04-25 09:52:27 -04001554 lpfc_nlp_set_state(phba, ndlp, NLP_STE_NPR_NODE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05001555 }
dea31012005-04-17 16:05:31 -05001556 break;
1557 }
1558 return;
1559}
1560
1561static int
1562lpfc_els_retry(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
1563 struct lpfc_iocbq * rspiocb)
1564{
1565 IOCB_t *irsp;
1566 struct lpfc_dmabuf *pcmd;
1567 struct lpfc_nodelist *ndlp;
1568 uint32_t *elscmd;
1569 struct ls_rjt stat;
1570 int retry, maxretry;
1571 int delay;
1572 uint32_t cmd;
James Smart488d1462006-03-07 15:02:37 -05001573 uint32_t did;
dea31012005-04-17 16:05:31 -05001574
1575 retry = 0;
1576 delay = 0;
1577 maxretry = lpfc_max_els_tries;
1578 irsp = &rspiocb->iocb;
1579 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1580 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
1581 cmd = 0;
James Smart488d1462006-03-07 15:02:37 -05001582
dea31012005-04-17 16:05:31 -05001583 /* Note: context2 may be 0 for internal driver abort
1584 * of delays ELS command.
1585 */
1586
1587 if (pcmd && pcmd->virt) {
1588 elscmd = (uint32_t *) (pcmd->virt);
1589 cmd = *elscmd++;
1590 }
1591
James Smart329f9bc2007-04-25 09:53:01 -04001592 if (ndlp)
James Smart488d1462006-03-07 15:02:37 -05001593 did = ndlp->nlp_DID;
1594 else {
1595 /* We should only hit this case for retrying PLOGI */
1596 did = irsp->un.elsreq64.remoteID;
James Smart685f0bf2007-04-25 09:53:08 -04001597 ndlp = lpfc_findnode_did(phba, did);
James Smart488d1462006-03-07 15:02:37 -05001598 if (!ndlp && (cmd != ELS_CMD_PLOGI))
1599 return 1;
1600 }
1601
dea31012005-04-17 16:05:31 -05001602 switch (irsp->ulpStatus) {
1603 case IOSTAT_FCP_RSP_ERROR:
1604 case IOSTAT_REMOTE_STOP:
1605 break;
1606
1607 case IOSTAT_LOCAL_REJECT:
1608 switch ((irsp->un.ulpWord[4] & 0xff)) {
1609 case IOERR_LOOP_OPEN_FAILURE:
1610 if (cmd == ELS_CMD_PLOGI) {
1611 if (cmdiocb->retry == 0) {
1612 delay = 1;
1613 }
1614 }
1615 retry = 1;
1616 break;
1617
1618 case IOERR_SEQUENCE_TIMEOUT:
1619 retry = 1;
dea31012005-04-17 16:05:31 -05001620 break;
1621
1622 case IOERR_NO_RESOURCES:
1623 if (cmd == ELS_CMD_PLOGI) {
1624 delay = 1;
1625 }
1626 retry = 1;
1627 break;
1628
1629 case IOERR_INVALID_RPI:
1630 retry = 1;
1631 break;
1632 }
1633 break;
1634
1635 case IOSTAT_NPORT_RJT:
1636 case IOSTAT_FABRIC_RJT:
1637 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
1638 retry = 1;
1639 break;
1640 }
1641 break;
1642
1643 case IOSTAT_NPORT_BSY:
1644 case IOSTAT_FABRIC_BSY:
1645 retry = 1;
1646 break;
1647
1648 case IOSTAT_LS_RJT:
1649 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
1650 /* Added for Vendor specifc support
1651 * Just keep retrying for these Rsn / Exp codes
1652 */
1653 switch (stat.un.b.lsRjtRsnCode) {
1654 case LSRJT_UNABLE_TPC:
1655 if (stat.un.b.lsRjtRsnCodeExp ==
1656 LSEXP_CMD_IN_PROGRESS) {
1657 if (cmd == ELS_CMD_PLOGI) {
1658 delay = 1;
1659 maxretry = 48;
1660 }
1661 retry = 1;
1662 break;
1663 }
1664 if (cmd == ELS_CMD_PLOGI) {
1665 delay = 1;
1666 maxretry = lpfc_max_els_tries + 1;
1667 retry = 1;
1668 break;
1669 }
1670 break;
1671
1672 case LSRJT_LOGICAL_BSY:
1673 if (cmd == ELS_CMD_PLOGI) {
1674 delay = 1;
1675 maxretry = 48;
1676 }
1677 retry = 1;
1678 break;
1679 }
1680 break;
1681
1682 case IOSTAT_INTERMED_RSP:
1683 case IOSTAT_BA_RJT:
1684 break;
1685
1686 default:
1687 break;
1688 }
1689
James Smart488d1462006-03-07 15:02:37 -05001690 if (did == FDMI_DID)
dea31012005-04-17 16:05:31 -05001691 retry = 1;
dea31012005-04-17 16:05:31 -05001692
1693 if ((++cmdiocb->retry) >= maxretry) {
1694 phba->fc_stat.elsRetryExceeded++;
1695 retry = 0;
1696 }
1697
1698 if (retry) {
1699
1700 /* Retry ELS command <elsCmd> to remote NPORT <did> */
1701 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1702 "%d:0107 Retry ELS command x%x to remote "
1703 "NPORT x%x Data: x%x x%x\n",
1704 phba->brd_no,
James Smart488d1462006-03-07 15:02:37 -05001705 cmd, did, cmdiocb->retry, delay);
dea31012005-04-17 16:05:31 -05001706
1707 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) {
1708 /* If discovery / RSCN timer is running, reset it */
1709 if (timer_pending(&phba->fc_disctmo) ||
1710 (phba->fc_flag & FC_RSCN_MODE)) {
1711 lpfc_set_disctmo(phba);
1712 }
1713 }
1714
1715 phba->fc_stat.elsXmitRetry++;
James Smart488d1462006-03-07 15:02:37 -05001716 if (ndlp && delay) {
dea31012005-04-17 16:05:31 -05001717 phba->fc_stat.elsDelayRetry++;
1718 ndlp->nlp_retry = cmdiocb->retry;
1719
1720 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
1721 ndlp->nlp_flag |= NLP_DELAY_TMO;
1722
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001723 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smartde0c5b32007-04-25 09:52:27 -04001724 lpfc_nlp_set_state(phba, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05001725 ndlp->nlp_last_elscmd = cmd;
1726
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001727 return 1;
dea31012005-04-17 16:05:31 -05001728 }
1729 switch (cmd) {
1730 case ELS_CMD_FLOGI:
1731 lpfc_issue_els_flogi(phba, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001732 return 1;
dea31012005-04-17 16:05:31 -05001733 case ELS_CMD_PLOGI:
James Smart488d1462006-03-07 15:02:37 -05001734 if (ndlp) {
1735 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smartde0c5b32007-04-25 09:52:27 -04001736 lpfc_nlp_set_state(phba, ndlp,
1737 NLP_STE_PLOGI_ISSUE);
James Smart488d1462006-03-07 15:02:37 -05001738 }
1739 lpfc_issue_els_plogi(phba, did, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001740 return 1;
dea31012005-04-17 16:05:31 -05001741 case ELS_CMD_ADISC:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001742 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smartde0c5b32007-04-25 09:52:27 -04001743 lpfc_nlp_set_state(phba, ndlp, NLP_STE_ADISC_ISSUE);
dea31012005-04-17 16:05:31 -05001744 lpfc_issue_els_adisc(phba, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001745 return 1;
dea31012005-04-17 16:05:31 -05001746 case ELS_CMD_PRLI:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001747 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smartde0c5b32007-04-25 09:52:27 -04001748 lpfc_nlp_set_state(phba, ndlp, NLP_STE_PRLI_ISSUE);
dea31012005-04-17 16:05:31 -05001749 lpfc_issue_els_prli(phba, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001750 return 1;
dea31012005-04-17 16:05:31 -05001751 case ELS_CMD_LOGO:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001752 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smartde0c5b32007-04-25 09:52:27 -04001753 lpfc_nlp_set_state(phba, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05001754 lpfc_issue_els_logo(phba, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001755 return 1;
dea31012005-04-17 16:05:31 -05001756 }
1757 }
1758
1759 /* No retry ELS command <elsCmd> to remote NPORT <did> */
1760 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1761 "%d:0108 No retry ELS command x%x to remote NPORT x%x "
James Smart488d1462006-03-07 15:02:37 -05001762 "Data: x%x\n",
dea31012005-04-17 16:05:31 -05001763 phba->brd_no,
James Smart488d1462006-03-07 15:02:37 -05001764 cmd, did, cmdiocb->retry);
dea31012005-04-17 16:05:31 -05001765
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001766 return 0;
dea31012005-04-17 16:05:31 -05001767}
1768
1769int
James Smart329f9bc2007-04-25 09:53:01 -04001770lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05001771{
1772 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
1773
James Smart329f9bc2007-04-25 09:53:01 -04001774 if (elsiocb->context1) {
1775 lpfc_nlp_put(elsiocb->context1);
1776 elsiocb->context1 = NULL;
1777 }
dea31012005-04-17 16:05:31 -05001778 /* context2 = cmd, context2->next = rsp, context3 = bpl */
1779 if (elsiocb->context2) {
1780 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
1781 /* Free the response before processing the command. */
1782 if (!list_empty(&buf_ptr1->list)) {
1783 list_remove_head(&buf_ptr1->list, buf_ptr,
1784 struct lpfc_dmabuf,
1785 list);
1786 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
1787 kfree(buf_ptr);
1788 }
1789 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
1790 kfree(buf_ptr1);
1791 }
1792
1793 if (elsiocb->context3) {
1794 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
1795 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
1796 kfree(buf_ptr);
1797 }
1798 spin_lock_irq(phba->host->host_lock);
James Bottomley604a3e32005-10-29 10:28:33 -05001799 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -05001800 spin_unlock_irq(phba->host->host_lock);
1801 return 0;
1802}
1803
1804static void
1805lpfc_cmpl_els_logo_acc(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
1806 struct lpfc_iocbq * rspiocb)
1807{
1808 struct lpfc_nodelist *ndlp;
1809
1810 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1811
1812 /* ACC to LOGO completes to NPort <nlp_DID> */
1813 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1814 "%d:0109 ACC to LOGO completes to NPort x%x "
1815 "Data: x%x x%x x%x\n",
1816 phba->brd_no, ndlp->nlp_DID, ndlp->nlp_flag,
1817 ndlp->nlp_state, ndlp->nlp_rpi);
1818
dea31012005-04-17 16:05:31 -05001819 switch (ndlp->nlp_state) {
1820 case NLP_STE_UNUSED_NODE: /* node is just allocated */
James Smartde0c5b32007-04-25 09:52:27 -04001821 lpfc_drop_node(phba, ndlp);
dea31012005-04-17 16:05:31 -05001822 break;
1823 case NLP_STE_NPR_NODE: /* NPort Recovery mode */
1824 lpfc_unreg_rpi(phba, ndlp);
1825 break;
1826 default:
1827 break;
1828 }
1829 lpfc_els_free_iocb(phba, cmdiocb);
1830 return;
1831}
1832
1833static void
James Smart329f9bc2007-04-25 09:53:01 -04001834lpfc_cmpl_els_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1835 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001836{
James Smart33ccf8d2006-08-17 11:57:58 -04001837 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001838 struct lpfc_nodelist *ndlp;
1839 LPFC_MBOXQ_t *mbox = NULL;
James Smart14691152006-12-02 13:34:28 -05001840 struct lpfc_dmabuf *mp;
dea31012005-04-17 16:05:31 -05001841
James Smart33ccf8d2006-08-17 11:57:58 -04001842 irsp = &rspiocb->iocb;
1843
dea31012005-04-17 16:05:31 -05001844 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1845 if (cmdiocb->context_un.mbox)
1846 mbox = cmdiocb->context_un.mbox;
1847
1848
1849 /* Check to see if link went down during discovery */
James Smart329f9bc2007-04-25 09:53:01 -04001850 if (lpfc_els_chk_latt(phba) || !ndlp) {
dea31012005-04-17 16:05:31 -05001851 if (mbox) {
James Smart14691152006-12-02 13:34:28 -05001852 mp = (struct lpfc_dmabuf *) mbox->context1;
1853 if (mp) {
1854 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1855 kfree(mp);
1856 }
James Smart329f9bc2007-04-25 09:53:01 -04001857 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05001858 }
1859 goto out;
1860 }
1861
1862 /* ELS response tag <ulpIoTag> completes */
1863 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1864 "%d:0110 ELS response tag x%x completes "
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001865 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -05001866 phba->brd_no,
1867 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001868 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
1869 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
1870 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05001871
1872 if (mbox) {
1873 if ((rspiocb->iocb.ulpStatus == 0)
1874 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
dea31012005-04-17 16:05:31 -05001875 lpfc_unreg_rpi(phba, ndlp);
1876 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
James Smart329f9bc2007-04-25 09:53:01 -04001877 mbox->context2 = lpfc_nlp_get(ndlp);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001878 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smartde0c5b32007-04-25 09:52:27 -04001879 lpfc_nlp_set_state(phba, ndlp, NLP_STE_REG_LOGIN_ISSUE);
dea31012005-04-17 16:05:31 -05001880 if (lpfc_sli_issue_mbox(phba, mbox,
1881 (MBX_NOWAIT | MBX_STOP_IOCB))
1882 != MBX_NOT_FINISHED) {
1883 goto out;
1884 }
James Smart329f9bc2007-04-25 09:53:01 -04001885 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001886 /* NOTE: we should have messages for unsuccessful
1887 reglogin */
dea31012005-04-17 16:05:31 -05001888 } else {
James Smart33ccf8d2006-08-17 11:57:58 -04001889 /* Do not call NO_LIST for lpfc_els_abort'ed ELS cmds */
1890 if (!((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
1891 ((irsp->un.ulpWord[4] == IOERR_SLI_ABORTED) ||
1892 (irsp->un.ulpWord[4] == IOERR_LINK_DOWN) ||
1893 (irsp->un.ulpWord[4] == IOERR_SLI_DOWN)))) {
1894 if (ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
James Smartde0c5b32007-04-25 09:52:27 -04001895 lpfc_drop_node(phba, ndlp);
James Smart33ccf8d2006-08-17 11:57:58 -04001896 ndlp = NULL;
1897 }
dea31012005-04-17 16:05:31 -05001898 }
1899 }
James Smart14691152006-12-02 13:34:28 -05001900 mp = (struct lpfc_dmabuf *) mbox->context1;
1901 if (mp) {
1902 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1903 kfree(mp);
1904 }
1905 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05001906 }
1907out:
1908 if (ndlp) {
1909 spin_lock_irq(phba->host->host_lock);
1910 ndlp->nlp_flag &= ~NLP_ACC_REGLOGIN;
1911 spin_unlock_irq(phba->host->host_lock);
1912 }
1913 lpfc_els_free_iocb(phba, cmdiocb);
1914 return;
1915}
1916
1917int
1918lpfc_els_rsp_acc(struct lpfc_hba * phba, uint32_t flag,
1919 struct lpfc_iocbq * oldiocb, struct lpfc_nodelist * ndlp,
1920 LPFC_MBOXQ_t * mbox, uint8_t newnode)
1921{
1922 IOCB_t *icmd;
1923 IOCB_t *oldcmd;
1924 struct lpfc_iocbq *elsiocb;
1925 struct lpfc_sli_ring *pring;
1926 struct lpfc_sli *psli;
1927 uint8_t *pcmd;
1928 uint16_t cmdsize;
1929 int rc;
James Smart82d9a2a2006-04-15 11:53:05 -04001930 ELS_PKT *els_pkt_ptr;
dea31012005-04-17 16:05:31 -05001931
1932 psli = &phba->sli;
1933 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1934 oldcmd = &oldiocb->iocb;
1935
1936 switch (flag) {
1937 case ELS_CMD_ACC:
1938 cmdsize = sizeof (uint32_t);
James Smart488d1462006-03-07 15:02:37 -05001939 elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry,
1940 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
1941 if (!elsiocb) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001942 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001943 return 1;
dea31012005-04-17 16:05:31 -05001944 }
1945 icmd = &elsiocb->iocb;
1946 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
1947 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1948 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
1949 pcmd += sizeof (uint32_t);
1950 break;
1951 case ELS_CMD_PLOGI:
1952 cmdsize = (sizeof (struct serv_parm) + sizeof (uint32_t));
James Smart488d1462006-03-07 15:02:37 -05001953 elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry,
1954 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
1955 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001956 return 1;
James Smart488d1462006-03-07 15:02:37 -05001957
dea31012005-04-17 16:05:31 -05001958 icmd = &elsiocb->iocb;
1959 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
1960 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1961
1962 if (mbox)
1963 elsiocb->context_un.mbox = mbox;
1964
1965 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
1966 pcmd += sizeof (uint32_t);
1967 memcpy(pcmd, &phba->fc_sparam, sizeof (struct serv_parm));
1968 break;
James Smart82d9a2a2006-04-15 11:53:05 -04001969 case ELS_CMD_PRLO:
1970 cmdsize = sizeof (uint32_t) + sizeof (PRLO);
1971 elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry,
1972 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
1973 if (!elsiocb)
1974 return 1;
1975
1976 icmd = &elsiocb->iocb;
1977 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
1978 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1979
1980 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
1981 sizeof (uint32_t) + sizeof (PRLO));
1982 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
1983 els_pkt_ptr = (ELS_PKT *) pcmd;
1984 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
1985 break;
dea31012005-04-17 16:05:31 -05001986 default:
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001987 return 1;
dea31012005-04-17 16:05:31 -05001988 }
1989
James Smart329f9bc2007-04-25 09:53:01 -04001990 if (newnode) {
1991 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001992 elsiocb->context1 = NULL;
James Smart329f9bc2007-04-25 09:53:01 -04001993 }
dea31012005-04-17 16:05:31 -05001994
1995 /* Xmit ELS ACC response tag <ulpIoTag> */
1996 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
James Smart1dcb58e2007-04-25 09:51:30 -04001997 "%d:0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
1998 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n",
1999 phba->brd_no, elsiocb->iotag,
dea31012005-04-17 16:05:31 -05002000 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
2001 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
2002
2003 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002004 spin_lock_irq(phba->host->host_lock);
2005 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
2006 spin_unlock_irq(phba->host->host_lock);
dea31012005-04-17 16:05:31 -05002007 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
2008 } else {
2009 elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
2010 }
2011
2012 phba->fc_stat.elsXmitACC++;
2013 spin_lock_irq(phba->host->host_lock);
2014 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
2015 spin_unlock_irq(phba->host->host_lock);
2016 if (rc == IOCB_ERROR) {
2017 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002018 return 1;
dea31012005-04-17 16:05:31 -05002019 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002020 return 0;
dea31012005-04-17 16:05:31 -05002021}
2022
2023int
2024lpfc_els_rsp_reject(struct lpfc_hba * phba, uint32_t rejectError,
2025 struct lpfc_iocbq * oldiocb, struct lpfc_nodelist * ndlp)
2026{
2027 IOCB_t *icmd;
2028 IOCB_t *oldcmd;
2029 struct lpfc_iocbq *elsiocb;
2030 struct lpfc_sli_ring *pring;
2031 struct lpfc_sli *psli;
2032 uint8_t *pcmd;
2033 uint16_t cmdsize;
2034 int rc;
2035
2036 psli = &phba->sli;
2037 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2038
2039 cmdsize = 2 * sizeof (uint32_t);
James Smart488d1462006-03-07 15:02:37 -05002040 elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry,
2041 ndlp, ndlp->nlp_DID, ELS_CMD_LS_RJT);
2042 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002043 return 1;
dea31012005-04-17 16:05:31 -05002044
2045 icmd = &elsiocb->iocb;
2046 oldcmd = &oldiocb->iocb;
2047 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2048 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2049
2050 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
2051 pcmd += sizeof (uint32_t);
2052 *((uint32_t *) (pcmd)) = rejectError;
2053
2054 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
2055 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
James Smart5b8bd0c2007-04-25 09:52:49 -04002056 "%d:0129 Xmit ELS RJT x%x response tag x%x xri x%x, "
2057 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
2058 phba->brd_no, rejectError, elsiocb->iotag,
dea31012005-04-17 16:05:31 -05002059 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
2060 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
2061
2062 phba->fc_stat.elsXmitLSRJT++;
2063 elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
2064 spin_lock_irq(phba->host->host_lock);
2065 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
2066 spin_unlock_irq(phba->host->host_lock);
2067 if (rc == IOCB_ERROR) {
2068 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002069 return 1;
dea31012005-04-17 16:05:31 -05002070 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002071 return 0;
dea31012005-04-17 16:05:31 -05002072}
2073
2074int
2075lpfc_els_rsp_adisc_acc(struct lpfc_hba * phba,
2076 struct lpfc_iocbq * oldiocb, struct lpfc_nodelist * ndlp)
2077{
2078 ADISC *ap;
2079 IOCB_t *icmd;
2080 IOCB_t *oldcmd;
2081 struct lpfc_iocbq *elsiocb;
2082 struct lpfc_sli_ring *pring;
2083 struct lpfc_sli *psli;
2084 uint8_t *pcmd;
2085 uint16_t cmdsize;
2086 int rc;
2087
2088 psli = &phba->sli;
2089 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2090
2091 cmdsize = sizeof (uint32_t) + sizeof (ADISC);
James Smart488d1462006-03-07 15:02:37 -05002092 elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry,
2093 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
2094 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002095 return 1;
dea31012005-04-17 16:05:31 -05002096
dea31012005-04-17 16:05:31 -05002097 icmd = &elsiocb->iocb;
2098 oldcmd = &oldiocb->iocb;
2099 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04002100
2101 /* Xmit ADISC ACC response tag <ulpIoTag> */
2102 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
2103 "%d:0130 Xmit ADISC ACC response iotag x%x xri: "
2104 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
2105 phba->brd_no, elsiocb->iotag,
2106 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
2107 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
2108
dea31012005-04-17 16:05:31 -05002109 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2110
2111 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
2112 pcmd += sizeof (uint32_t);
2113
2114 ap = (ADISC *) (pcmd);
2115 ap->hardAL_PA = phba->fc_pref_ALPA;
2116 memcpy(&ap->portName, &phba->fc_portname, sizeof (struct lpfc_name));
2117 memcpy(&ap->nodeName, &phba->fc_nodename, sizeof (struct lpfc_name));
2118 ap->DID = be32_to_cpu(phba->fc_myDID);
2119
2120 phba->fc_stat.elsXmitACC++;
2121 elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
2122 spin_lock_irq(phba->host->host_lock);
2123 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
2124 spin_unlock_irq(phba->host->host_lock);
2125 if (rc == IOCB_ERROR) {
2126 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002127 return 1;
dea31012005-04-17 16:05:31 -05002128 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002129 return 0;
dea31012005-04-17 16:05:31 -05002130}
2131
2132int
James Smart5b8bd0c2007-04-25 09:52:49 -04002133lpfc_els_rsp_prli_acc(struct lpfc_hba *phba, struct lpfc_iocbq *oldiocb,
2134 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05002135{
2136 PRLI *npr;
2137 lpfc_vpd_t *vpd;
2138 IOCB_t *icmd;
2139 IOCB_t *oldcmd;
2140 struct lpfc_iocbq *elsiocb;
2141 struct lpfc_sli_ring *pring;
2142 struct lpfc_sli *psli;
2143 uint8_t *pcmd;
2144 uint16_t cmdsize;
2145 int rc;
2146
2147 psli = &phba->sli;
2148 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2149
2150 cmdsize = sizeof (uint32_t) + sizeof (PRLI);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002151 elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry, ndlp,
James Smart488d1462006-03-07 15:02:37 -05002152 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002153 if (!elsiocb)
2154 return 1;
dea31012005-04-17 16:05:31 -05002155
dea31012005-04-17 16:05:31 -05002156 icmd = &elsiocb->iocb;
2157 oldcmd = &oldiocb->iocb;
2158 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04002159
2160 /* Xmit PRLI ACC response tag <ulpIoTag> */
2161 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
2162 "%d:0131 Xmit PRLI ACC response tag x%x xri x%x, "
2163 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
2164 phba->brd_no, elsiocb->iotag,
2165 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
2166 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
2167
dea31012005-04-17 16:05:31 -05002168 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2169
2170 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
2171 pcmd += sizeof (uint32_t);
2172
2173 /* For PRLI, remainder of payload is PRLI parameter page */
2174 memset(pcmd, 0, sizeof (PRLI));
2175
2176 npr = (PRLI *) pcmd;
2177 vpd = &phba->vpd;
2178 /*
2179 * If our firmware version is 3.20 or later,
2180 * set the following bits for FC-TAPE support.
2181 */
2182 if (vpd->rev.feaLevelHigh >= 0x02) {
2183 npr->ConfmComplAllowed = 1;
2184 npr->Retry = 1;
2185 npr->TaskRetryIdReq = 1;
2186 }
2187
2188 npr->acceptRspCode = PRLI_REQ_EXECUTED;
2189 npr->estabImagePair = 1;
2190 npr->readXferRdyDis = 1;
2191 npr->ConfmComplAllowed = 1;
2192
2193 npr->prliType = PRLI_FCP_TYPE;
2194 npr->initiatorFunc = 1;
2195
2196 phba->fc_stat.elsXmitACC++;
2197 elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
2198
2199 spin_lock_irq(phba->host->host_lock);
2200 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
2201 spin_unlock_irq(phba->host->host_lock);
2202 if (rc == IOCB_ERROR) {
2203 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002204 return 1;
dea31012005-04-17 16:05:31 -05002205 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002206 return 0;
dea31012005-04-17 16:05:31 -05002207}
2208
2209static int
James Smart329f9bc2007-04-25 09:53:01 -04002210lpfc_els_rsp_rnid_acc(struct lpfc_hba *phba, uint8_t format,
2211 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05002212{
2213 RNID *rn;
2214 IOCB_t *icmd;
2215 IOCB_t *oldcmd;
2216 struct lpfc_iocbq *elsiocb;
2217 struct lpfc_sli_ring *pring;
2218 struct lpfc_sli *psli;
2219 uint8_t *pcmd;
2220 uint16_t cmdsize;
2221 int rc;
2222
2223 psli = &phba->sli;
2224 pring = &psli->ring[LPFC_ELS_RING];
2225
2226 cmdsize = sizeof (uint32_t) + sizeof (uint32_t)
2227 + (2 * sizeof (struct lpfc_name));
2228 if (format)
2229 cmdsize += sizeof (RNID_TOP_DISC);
2230
James Smart488d1462006-03-07 15:02:37 -05002231 elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry,
2232 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
2233 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002234 return 1;
dea31012005-04-17 16:05:31 -05002235
dea31012005-04-17 16:05:31 -05002236 icmd = &elsiocb->iocb;
2237 oldcmd = &oldiocb->iocb;
2238 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04002239
2240 /* Xmit RNID ACC response tag <ulpIoTag> */
2241 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
2242 "%d:0132 Xmit RNID ACC response tag x%x "
2243 "xri x%x\n",
2244 phba->brd_no, elsiocb->iotag,
2245 elsiocb->iocb.ulpContext);
2246
dea31012005-04-17 16:05:31 -05002247 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2248
2249 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
2250 pcmd += sizeof (uint32_t);
2251
2252 memset(pcmd, 0, sizeof (RNID));
2253 rn = (RNID *) (pcmd);
2254 rn->Format = format;
2255 rn->CommonLen = (2 * sizeof (struct lpfc_name));
2256 memcpy(&rn->portName, &phba->fc_portname, sizeof (struct lpfc_name));
2257 memcpy(&rn->nodeName, &phba->fc_nodename, sizeof (struct lpfc_name));
2258 switch (format) {
2259 case 0:
2260 rn->SpecificLen = 0;
2261 break;
2262 case RNID_TOPOLOGY_DISC:
2263 rn->SpecificLen = sizeof (RNID_TOP_DISC);
2264 memcpy(&rn->un.topologyDisc.portName,
2265 &phba->fc_portname, sizeof (struct lpfc_name));
2266 rn->un.topologyDisc.unitType = RNID_HBA;
2267 rn->un.topologyDisc.physPort = 0;
2268 rn->un.topologyDisc.attachedNodes = 0;
2269 break;
2270 default:
2271 rn->CommonLen = 0;
2272 rn->SpecificLen = 0;
2273 break;
2274 }
2275
2276 phba->fc_stat.elsXmitACC++;
2277 elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
James Smart329f9bc2007-04-25 09:53:01 -04002278 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002279 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
2280 * it could be freed */
2281
2282 spin_lock_irq(phba->host->host_lock);
2283 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
2284 spin_unlock_irq(phba->host->host_lock);
2285 if (rc == IOCB_ERROR) {
2286 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002287 return 1;
dea31012005-04-17 16:05:31 -05002288 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002289 return 0;
dea31012005-04-17 16:05:31 -05002290}
2291
2292int
James Smart685f0bf2007-04-25 09:53:08 -04002293lpfc_els_disc_adisc(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002294{
2295 int sentadisc;
2296 struct lpfc_nodelist *ndlp, *next_ndlp;
2297
2298 sentadisc = 0;
James Smart685f0bf2007-04-25 09:53:08 -04002299 /* go thru NPR nodes and issue any remaining ELS ADISCs */
2300 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_nodes, nlp_listp) {
2301 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
2302 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
2303 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
2304 spin_lock_irq(phba->host->host_lock);
2305 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2306 spin_unlock_irq(phba->host->host_lock);
2307 ndlp->nlp_prev_state = ndlp->nlp_state;
2308 lpfc_nlp_set_state(phba, ndlp, NLP_STE_ADISC_ISSUE);
2309 lpfc_issue_els_adisc(phba, ndlp, 0);
2310 sentadisc++;
2311 phba->num_disc_nodes++;
2312 if (phba->num_disc_nodes >=
2313 phba->cfg_discovery_threads) {
2314 spin_lock_irq(phba->host->host_lock);
2315 phba->fc_flag |= FC_NLP_MORE;
2316 spin_unlock_irq(phba->host->host_lock);
2317 break;
dea31012005-04-17 16:05:31 -05002318 }
2319 }
2320 }
2321 if (sentadisc == 0) {
2322 spin_lock_irq(phba->host->host_lock);
2323 phba->fc_flag &= ~FC_NLP_MORE;
2324 spin_unlock_irq(phba->host->host_lock);
2325 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002326 return sentadisc;
dea31012005-04-17 16:05:31 -05002327}
2328
2329int
2330lpfc_els_disc_plogi(struct lpfc_hba * phba)
2331{
2332 int sentplogi;
2333 struct lpfc_nodelist *ndlp, *next_ndlp;
2334
2335 sentplogi = 0;
2336 /* go thru NPR list and issue any remaining ELS PLOGIs */
James Smart685f0bf2007-04-25 09:53:08 -04002337 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_nodes, nlp_listp) {
2338 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
2339 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
2340 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
2341 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
2342 ndlp->nlp_prev_state = ndlp->nlp_state;
2343 lpfc_nlp_set_state(phba, ndlp, NLP_STE_PLOGI_ISSUE);
2344 lpfc_issue_els_plogi(phba, ndlp->nlp_DID, 0);
2345 sentplogi++;
2346 phba->num_disc_nodes++;
2347 if (phba->num_disc_nodes >=
2348 phba->cfg_discovery_threads) {
2349 spin_lock_irq(phba->host->host_lock);
2350 phba->fc_flag |= FC_NLP_MORE;
2351 spin_unlock_irq(phba->host->host_lock);
2352 break;
dea31012005-04-17 16:05:31 -05002353 }
2354 }
2355 }
2356 if (sentplogi == 0) {
2357 spin_lock_irq(phba->host->host_lock);
2358 phba->fc_flag &= ~FC_NLP_MORE;
2359 spin_unlock_irq(phba->host->host_lock);
2360 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002361 return sentplogi;
dea31012005-04-17 16:05:31 -05002362}
2363
2364int
2365lpfc_els_flush_rscn(struct lpfc_hba * phba)
2366{
2367 struct lpfc_dmabuf *mp;
2368 int i;
2369
2370 for (i = 0; i < phba->fc_rscn_id_cnt; i++) {
2371 mp = phba->fc_rscn_id_list[i];
2372 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2373 kfree(mp);
2374 phba->fc_rscn_id_list[i] = NULL;
2375 }
2376 phba->fc_rscn_id_cnt = 0;
2377 spin_lock_irq(phba->host->host_lock);
2378 phba->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
2379 spin_unlock_irq(phba->host->host_lock);
2380 lpfc_can_disctmo(phba);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002381 return 0;
dea31012005-04-17 16:05:31 -05002382}
2383
2384int
2385lpfc_rscn_payload_check(struct lpfc_hba * phba, uint32_t did)
2386{
2387 D_ID ns_did;
2388 D_ID rscn_did;
2389 struct lpfc_dmabuf *mp;
2390 uint32_t *lp;
2391 uint32_t payload_len, cmd, i, match;
2392
2393 ns_did.un.word = did;
2394 match = 0;
2395
2396 /* Never match fabric nodes for RSCNs */
2397 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
2398 return(0);
2399
2400 /* If we are doing a FULL RSCN rediscovery, match everything */
2401 if (phba->fc_flag & FC_RSCN_DISCOVERY) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002402 return did;
dea31012005-04-17 16:05:31 -05002403 }
2404
2405 for (i = 0; i < phba->fc_rscn_id_cnt; i++) {
2406 mp = phba->fc_rscn_id_list[i];
2407 lp = (uint32_t *) mp->virt;
2408 cmd = *lp++;
2409 payload_len = be32_to_cpu(cmd) & 0xffff; /* payload length */
2410 payload_len -= sizeof (uint32_t); /* take off word 0 */
2411 while (payload_len) {
2412 rscn_did.un.word = *lp++;
2413 rscn_did.un.word = be32_to_cpu(rscn_did.un.word);
2414 payload_len -= sizeof (uint32_t);
2415 switch (rscn_did.un.b.resv) {
2416 case 0: /* Single N_Port ID effected */
2417 if (ns_did.un.word == rscn_did.un.word) {
2418 match = did;
2419 }
2420 break;
2421 case 1: /* Whole N_Port Area effected */
2422 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
2423 && (ns_did.un.b.area == rscn_did.un.b.area))
2424 {
2425 match = did;
2426 }
2427 break;
2428 case 2: /* Whole N_Port Domain effected */
2429 if (ns_did.un.b.domain == rscn_did.un.b.domain)
2430 {
2431 match = did;
2432 }
2433 break;
2434 case 3: /* Whole Fabric effected */
2435 match = did;
2436 break;
2437 default:
2438 /* Unknown Identifier in RSCN list */
2439 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2440 "%d:0217 Unknown Identifier in "
2441 "RSCN payload Data: x%x\n",
2442 phba->brd_no, rscn_did.un.word);
2443 break;
2444 }
2445 if (match) {
2446 break;
2447 }
2448 }
2449 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002450 return match;
dea31012005-04-17 16:05:31 -05002451}
2452
2453static int
James Smart329f9bc2007-04-25 09:53:01 -04002454lpfc_rscn_recovery_check(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05002455{
James Smart685f0bf2007-04-25 09:53:08 -04002456 struct lpfc_nodelist *ndlp = NULL;
dea31012005-04-17 16:05:31 -05002457
2458 /* Look at all nodes effected by pending RSCNs and move
James Smart685f0bf2007-04-25 09:53:08 -04002459 * them to NPR state.
dea31012005-04-17 16:05:31 -05002460 */
James Smart685f0bf2007-04-25 09:53:08 -04002461
2462 list_for_each_entry(ndlp, &phba->fc_nodes, nlp_listp) {
2463 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE ||
2464 lpfc_rscn_payload_check(phba, ndlp->nlp_DID) == 0)
dea31012005-04-17 16:05:31 -05002465 continue;
2466
James Smart685f0bf2007-04-25 09:53:08 -04002467 lpfc_disc_state_machine(phba, ndlp, NULL,
dea31012005-04-17 16:05:31 -05002468 NLP_EVT_DEVICE_RECOVERY);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002469
James Smart685f0bf2007-04-25 09:53:08 -04002470 /*
2471 * Make sure NLP_DELAY_TMO is NOT running after a device
2472 * recovery event.
2473 */
2474 if (ndlp->nlp_flag & NLP_DELAY_TMO)
2475 lpfc_cancel_retry_delay_tmo(phba, ndlp);
dea31012005-04-17 16:05:31 -05002476 }
James Smart685f0bf2007-04-25 09:53:08 -04002477
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002478 return 0;
dea31012005-04-17 16:05:31 -05002479}
2480
2481static int
2482lpfc_els_rcv_rscn(struct lpfc_hba * phba,
2483 struct lpfc_iocbq * cmdiocb,
2484 struct lpfc_nodelist * ndlp, uint8_t newnode)
2485{
2486 struct lpfc_dmabuf *pcmd;
2487 uint32_t *lp;
2488 IOCB_t *icmd;
2489 uint32_t payload_len, cmd;
James Smartd2873e42006-08-18 17:46:43 -04002490 int i;
dea31012005-04-17 16:05:31 -05002491
2492 icmd = &cmdiocb->iocb;
2493 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2494 lp = (uint32_t *) pcmd->virt;
2495
2496 cmd = *lp++;
2497 payload_len = be32_to_cpu(cmd) & 0xffff; /* payload length */
2498 payload_len -= sizeof (uint32_t); /* take off word 0 */
2499 cmd &= ELS_CMD_MASK;
2500
2501 /* RSCN received */
2502 lpfc_printf_log(phba,
2503 KERN_INFO,
2504 LOG_DISCOVERY,
2505 "%d:0214 RSCN received Data: x%x x%x x%x x%x\n",
2506 phba->brd_no,
2507 phba->fc_flag, payload_len, *lp, phba->fc_rscn_id_cnt);
2508
James Smartd2873e42006-08-18 17:46:43 -04002509 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
2510 fc_host_post_event(phba->host, fc_get_event_number(),
2511 FCH_EVT_RSCN, lp[i]);
2512
dea31012005-04-17 16:05:31 -05002513 /* If we are about to begin discovery, just ACC the RSCN.
2514 * Discovery processing will satisfy it.
2515 */
James Smart071fbd3d2006-04-15 11:53:20 -04002516 if (phba->hba_state <= LPFC_NS_QRY) {
dea31012005-04-17 16:05:31 -05002517 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL,
2518 newnode);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002519 return 0;
dea31012005-04-17 16:05:31 -05002520 }
2521
2522 /* If we are already processing an RSCN, save the received
2523 * RSCN payload buffer, cmdiocb->context2 to process later.
2524 */
2525 if (phba->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
2526 if ((phba->fc_rscn_id_cnt < FC_MAX_HOLD_RSCN) &&
2527 !(phba->fc_flag & FC_RSCN_DISCOVERY)) {
2528 spin_lock_irq(phba->host->host_lock);
2529 phba->fc_flag |= FC_RSCN_MODE;
2530 spin_unlock_irq(phba->host->host_lock);
2531 phba->fc_rscn_id_list[phba->fc_rscn_id_cnt++] = pcmd;
2532
2533 /* If we zero, cmdiocb->context2, the calling
2534 * routine will not try to free it.
2535 */
2536 cmdiocb->context2 = NULL;
2537
2538 /* Deferred RSCN */
2539 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
2540 "%d:0235 Deferred RSCN "
2541 "Data: x%x x%x x%x\n",
2542 phba->brd_no, phba->fc_rscn_id_cnt,
2543 phba->fc_flag, phba->hba_state);
2544 } else {
2545 spin_lock_irq(phba->host->host_lock);
2546 phba->fc_flag |= FC_RSCN_DISCOVERY;
2547 spin_unlock_irq(phba->host->host_lock);
2548 /* ReDiscovery RSCN */
2549 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
2550 "%d:0234 ReDiscovery RSCN "
2551 "Data: x%x x%x x%x\n",
2552 phba->brd_no, phba->fc_rscn_id_cnt,
2553 phba->fc_flag, phba->hba_state);
2554 }
2555 /* Send back ACC */
2556 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL,
2557 newnode);
2558
2559 /* send RECOVERY event for ALL nodes that match RSCN payload */
2560 lpfc_rscn_recovery_check(phba);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002561 return 0;
dea31012005-04-17 16:05:31 -05002562 }
2563
2564 phba->fc_flag |= FC_RSCN_MODE;
2565 phba->fc_rscn_id_list[phba->fc_rscn_id_cnt++] = pcmd;
2566 /*
2567 * If we zero, cmdiocb->context2, the calling routine will
2568 * not try to free it.
2569 */
2570 cmdiocb->context2 = NULL;
2571
2572 lpfc_set_disctmo(phba);
2573
2574 /* Send back ACC */
2575 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, newnode);
2576
2577 /* send RECOVERY event for ALL nodes that match RSCN payload */
2578 lpfc_rscn_recovery_check(phba);
2579
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002580 return lpfc_els_handle_rscn(phba);
dea31012005-04-17 16:05:31 -05002581}
2582
2583int
2584lpfc_els_handle_rscn(struct lpfc_hba * phba)
2585{
2586 struct lpfc_nodelist *ndlp;
2587
2588 /* Start timer for RSCN processing */
2589 lpfc_set_disctmo(phba);
2590
2591 /* RSCN processed */
2592 lpfc_printf_log(phba,
2593 KERN_INFO,
2594 LOG_DISCOVERY,
2595 "%d:0215 RSCN processed Data: x%x x%x x%x x%x\n",
2596 phba->brd_no,
2597 phba->fc_flag, 0, phba->fc_rscn_id_cnt,
2598 phba->hba_state);
2599
2600 /* To process RSCN, first compare RSCN data with NameServer */
2601 phba->fc_ns_retry = 0;
James Smart685f0bf2007-04-25 09:53:08 -04002602 ndlp = lpfc_findnode_did(phba, NameServer_DID);
2603 if (ndlp && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
dea31012005-04-17 16:05:31 -05002604 /* Good ndlp, issue CT Request to NameServer */
2605 if (lpfc_ns_cmd(phba, ndlp, SLI_CTNS_GID_FT) == 0) {
2606 /* Wait for NameServer query cmpl before we can
2607 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002608 return 1;
dea31012005-04-17 16:05:31 -05002609 }
2610 } else {
2611 /* If login to NameServer does not exist, issue one */
2612 /* Good status, issue PLOGI to NameServer */
James Smart685f0bf2007-04-25 09:53:08 -04002613 ndlp = lpfc_findnode_did(phba, NameServer_DID);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002614 if (ndlp) {
dea31012005-04-17 16:05:31 -05002615 /* Wait for NameServer login cmpl before we can
2616 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002617 return 1;
dea31012005-04-17 16:05:31 -05002618 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002619 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2620 if (!ndlp) {
dea31012005-04-17 16:05:31 -05002621 lpfc_els_flush_rscn(phba);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002622 return 0;
dea31012005-04-17 16:05:31 -05002623 } else {
2624 lpfc_nlp_init(phba, ndlp, NameServer_DID);
2625 ndlp->nlp_type |= NLP_FABRIC;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002626 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smartde0c5b32007-04-25 09:52:27 -04002627 lpfc_nlp_set_state(phba, ndlp, NLP_STE_PLOGI_ISSUE);
James Smart488d1462006-03-07 15:02:37 -05002628 lpfc_issue_els_plogi(phba, NameServer_DID, 0);
dea31012005-04-17 16:05:31 -05002629 /* Wait for NameServer login cmpl before we can
2630 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002631 return 1;
dea31012005-04-17 16:05:31 -05002632 }
2633 }
2634
2635 lpfc_els_flush_rscn(phba);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002636 return 0;
dea31012005-04-17 16:05:31 -05002637}
2638
2639static int
2640lpfc_els_rcv_flogi(struct lpfc_hba * phba,
2641 struct lpfc_iocbq * cmdiocb,
2642 struct lpfc_nodelist * ndlp, uint8_t newnode)
2643{
2644 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2645 uint32_t *lp = (uint32_t *) pcmd->virt;
2646 IOCB_t *icmd = &cmdiocb->iocb;
2647 struct serv_parm *sp;
2648 LPFC_MBOXQ_t *mbox;
2649 struct ls_rjt stat;
2650 uint32_t cmd, did;
2651 int rc;
2652
2653 cmd = *lp++;
2654 sp = (struct serv_parm *) lp;
2655
2656 /* FLOGI received */
2657
2658 lpfc_set_disctmo(phba);
2659
2660 if (phba->fc_topology == TOPOLOGY_LOOP) {
2661 /* We should never receive a FLOGI in loop mode, ignore it */
2662 did = icmd->un.elsreq64.remoteID;
2663
2664 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
2665 Loop Mode */
2666 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
2667 "%d:0113 An FLOGI ELS command x%x was received "
2668 "from DID x%x in Loop Mode\n",
2669 phba->brd_no, cmd, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002670 return 1;
dea31012005-04-17 16:05:31 -05002671 }
2672
2673 did = Fabric_DID;
2674
2675 if ((lpfc_check_sparm(phba, ndlp, sp, CLASS3))) {
2676 /* For a FLOGI we accept, then if our portname is greater
2677 * then the remote portname we initiate Nport login.
2678 */
2679
2680 rc = memcmp(&phba->fc_portname, &sp->portName,
2681 sizeof (struct lpfc_name));
2682
2683 if (!rc) {
2684 if ((mbox = mempool_alloc(phba->mbox_mem_pool,
2685 GFP_KERNEL)) == 0) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002686 return 1;
dea31012005-04-17 16:05:31 -05002687 }
2688 lpfc_linkdown(phba);
2689 lpfc_init_link(phba, mbox,
2690 phba->cfg_topology,
2691 phba->cfg_link_speed);
2692 mbox->mb.un.varInitLnk.lipsr_AL_PA = 0;
2693 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
2694 rc = lpfc_sli_issue_mbox
2695 (phba, mbox, (MBX_NOWAIT | MBX_STOP_IOCB));
James Smart5b8bd0c2007-04-25 09:52:49 -04002696 lpfc_set_loopback_flag(phba);
dea31012005-04-17 16:05:31 -05002697 if (rc == MBX_NOT_FINISHED) {
James Smart329f9bc2007-04-25 09:53:01 -04002698 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05002699 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002700 return 1;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002701 } else if (rc > 0) { /* greater than */
dea31012005-04-17 16:05:31 -05002702 spin_lock_irq(phba->host->host_lock);
2703 phba->fc_flag |= FC_PT2PT_PLOGI;
2704 spin_unlock_irq(phba->host->host_lock);
2705 }
2706 phba->fc_flag |= FC_PT2PT;
2707 phba->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
2708 } else {
2709 /* Reject this request because invalid parameters */
2710 stat.un.b.lsRjtRsvd0 = 0;
2711 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2712 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
2713 stat.un.b.vendorUnique = 0;
2714 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002715 return 1;
dea31012005-04-17 16:05:31 -05002716 }
2717
2718 /* Send back ACC */
2719 lpfc_els_rsp_acc(phba, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL, newnode);
2720
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002721 return 0;
dea31012005-04-17 16:05:31 -05002722}
2723
2724static int
2725lpfc_els_rcv_rnid(struct lpfc_hba * phba,
2726 struct lpfc_iocbq * cmdiocb, struct lpfc_nodelist * ndlp)
2727{
2728 struct lpfc_dmabuf *pcmd;
2729 uint32_t *lp;
2730 IOCB_t *icmd;
2731 RNID *rn;
2732 struct ls_rjt stat;
2733 uint32_t cmd, did;
2734
2735 icmd = &cmdiocb->iocb;
2736 did = icmd->un.elsreq64.remoteID;
2737 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2738 lp = (uint32_t *) pcmd->virt;
2739
2740 cmd = *lp++;
2741 rn = (RNID *) lp;
2742
2743 /* RNID received */
2744
2745 switch (rn->Format) {
2746 case 0:
2747 case RNID_TOPOLOGY_DISC:
2748 /* Send back ACC */
2749 lpfc_els_rsp_rnid_acc(phba, rn->Format, cmdiocb, ndlp);
2750 break;
2751 default:
2752 /* Reject this request because format not supported */
2753 stat.un.b.lsRjtRsvd0 = 0;
2754 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2755 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
2756 stat.un.b.vendorUnique = 0;
2757 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
2758 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002759 return 0;
dea31012005-04-17 16:05:31 -05002760}
2761
2762static int
James Smart329f9bc2007-04-25 09:53:01 -04002763lpfc_els_rcv_lirr(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2764 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002765{
2766 struct ls_rjt stat;
2767
2768 /* For now, unconditionally reject this command */
2769 stat.un.b.lsRjtRsvd0 = 0;
2770 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2771 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
2772 stat.un.b.vendorUnique = 0;
2773 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
2774 return 0;
2775}
2776
Jamie Wellnitz082c0262006-02-28 19:25:30 -05002777static void
James Smart329f9bc2007-04-25 09:53:01 -04002778lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002779{
2780 struct lpfc_sli *psli;
2781 struct lpfc_sli_ring *pring;
2782 MAILBOX_t *mb;
2783 IOCB_t *icmd;
2784 RPS_RSP *rps_rsp;
2785 uint8_t *pcmd;
2786 struct lpfc_iocbq *elsiocb;
2787 struct lpfc_nodelist *ndlp;
2788 uint16_t xri, status;
2789 uint32_t cmdsize;
2790
2791 psli = &phba->sli;
2792 pring = &psli->ring[LPFC_ELS_RING];
2793 mb = &pmb->mb;
2794
2795 ndlp = (struct lpfc_nodelist *) pmb->context2;
2796 xri = (uint16_t) ((unsigned long)(pmb->context1));
Randy Dunlap041976f2006-06-25 01:58:51 -07002797 pmb->context1 = NULL;
2798 pmb->context2 = NULL;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002799
2800 if (mb->mbxStatus) {
James Smart329f9bc2007-04-25 09:53:01 -04002801 mempool_free(pmb, phba->mbox_mem_pool);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002802 return;
2803 }
2804
2805 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
James Smart329f9bc2007-04-25 09:53:01 -04002806 mempool_free(pmb, phba->mbox_mem_pool);
James Smart488d1462006-03-07 15:02:37 -05002807 elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, lpfc_max_els_tries, ndlp,
2808 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart329f9bc2007-04-25 09:53:01 -04002809 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002810 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002811 return;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002812
2813 icmd = &elsiocb->iocb;
2814 icmd->ulpContext = xri;
2815
2816 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2817 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
2818 pcmd += sizeof (uint32_t); /* Skip past command */
2819 rps_rsp = (RPS_RSP *)pcmd;
2820
2821 if (phba->fc_topology != TOPOLOGY_LOOP)
2822 status = 0x10;
2823 else
2824 status = 0x8;
2825 if (phba->fc_flag & FC_FABRIC)
2826 status |= 0x4;
2827
2828 rps_rsp->rsvd1 = 0;
2829 rps_rsp->portStatus = be16_to_cpu(status);
2830 rps_rsp->linkFailureCnt = be32_to_cpu(mb->un.varRdLnk.linkFailureCnt);
2831 rps_rsp->lossSyncCnt = be32_to_cpu(mb->un.varRdLnk.lossSyncCnt);
2832 rps_rsp->lossSignalCnt = be32_to_cpu(mb->un.varRdLnk.lossSignalCnt);
2833 rps_rsp->primSeqErrCnt = be32_to_cpu(mb->un.varRdLnk.primSeqErrCnt);
2834 rps_rsp->invalidXmitWord = be32_to_cpu(mb->un.varRdLnk.invalidXmitWord);
2835 rps_rsp->crcCnt = be32_to_cpu(mb->un.varRdLnk.crcCnt);
2836
2837 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
2838 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
James Smart5b8bd0c2007-04-25 09:52:49 -04002839 "%d:0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
2840 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
2841 phba->brd_no, elsiocb->iotag,
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002842 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
2843 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
2844
2845 elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
2846 phba->fc_stat.elsXmitACC++;
James Smart685f0bf2007-04-25 09:53:08 -04002847
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002848 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
2849 lpfc_els_free_iocb(phba, elsiocb);
2850 }
2851 return;
2852}
2853
2854static int
2855lpfc_els_rcv_rps(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
2856 struct lpfc_nodelist * ndlp)
2857{
2858 uint32_t *lp;
2859 uint8_t flag;
2860 LPFC_MBOXQ_t *mbox;
2861 struct lpfc_dmabuf *pcmd;
2862 RPS *rps;
2863 struct ls_rjt stat;
2864
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002865 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
2866 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002867 stat.un.b.lsRjtRsvd0 = 0;
2868 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2869 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
2870 stat.un.b.vendorUnique = 0;
2871 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
2872 }
2873
2874 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2875 lp = (uint32_t *) pcmd->virt;
2876 flag = (be32_to_cpu(*lp++) & 0xf);
2877 rps = (RPS *) lp;
2878
2879 if ((flag == 0) ||
2880 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
2881 ((flag == 2) && (memcmp(&rps->un.portName, &phba->fc_portname,
2882 sizeof (struct lpfc_name)) == 0))) {
2883 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC))) {
2884 lpfc_read_lnk_stat(phba, mbox);
2885 mbox->context1 =
2886 (void *)((unsigned long)cmdiocb->iocb.ulpContext);
James Smart329f9bc2007-04-25 09:53:01 -04002887 mbox->context2 = lpfc_nlp_get(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002888 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
2889 if (lpfc_sli_issue_mbox (phba, mbox,
2890 (MBX_NOWAIT | MBX_STOP_IOCB)) != MBX_NOT_FINISHED) {
2891 /* Mbox completion will send ELS Response */
2892 return 0;
2893 }
James Smart329f9bc2007-04-25 09:53:01 -04002894 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002895 mempool_free(mbox, phba->mbox_mem_pool);
2896 }
2897 }
2898 stat.un.b.lsRjtRsvd0 = 0;
2899 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2900 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
2901 stat.un.b.vendorUnique = 0;
2902 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
2903 return 0;
2904}
2905
Jamie Wellnitz082c0262006-02-28 19:25:30 -05002906static int
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002907lpfc_els_rsp_rpl_acc(struct lpfc_hba * phba, uint16_t cmdsize,
2908 struct lpfc_iocbq * oldiocb, struct lpfc_nodelist * ndlp)
2909{
2910 IOCB_t *icmd;
2911 IOCB_t *oldcmd;
2912 RPL_RSP rpl_rsp;
2913 struct lpfc_iocbq *elsiocb;
2914 struct lpfc_sli_ring *pring;
2915 struct lpfc_sli *psli;
2916 uint8_t *pcmd;
2917
2918 psli = &phba->sli;
2919 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2920
James Smart488d1462006-03-07 15:02:37 -05002921 elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry,
2922 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
2923 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002924 return 1;
James Smart488d1462006-03-07 15:02:37 -05002925
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002926 icmd = &elsiocb->iocb;
2927 oldcmd = &oldiocb->iocb;
2928 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2929
2930 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2931 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
2932 pcmd += sizeof (uint16_t);
2933 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
2934 pcmd += sizeof(uint16_t);
2935
2936 /* Setup the RPL ACC payload */
2937 rpl_rsp.listLen = be32_to_cpu(1);
2938 rpl_rsp.index = 0;
2939 rpl_rsp.port_num_blk.portNum = 0;
2940 rpl_rsp.port_num_blk.portID = be32_to_cpu(phba->fc_myDID);
2941 memcpy(&rpl_rsp.port_num_blk.portName, &phba->fc_portname,
2942 sizeof(struct lpfc_name));
2943
2944 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
2945
2946
2947 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
2948 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
James Smart5b8bd0c2007-04-25 09:52:49 -04002949 "%d:0120 Xmit ELS RPL ACC response tag x%x xri x%x, "
2950 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
2951 phba->brd_no, elsiocb->iotag,
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002952 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
2953 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
2954
2955 elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
2956
2957 phba->fc_stat.elsXmitACC++;
2958 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
2959 lpfc_els_free_iocb(phba, elsiocb);
2960 return 1;
2961 }
2962 return 0;
2963}
2964
2965static int
2966lpfc_els_rcv_rpl(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
dea31012005-04-17 16:05:31 -05002967 struct lpfc_nodelist * ndlp)
2968{
2969 struct lpfc_dmabuf *pcmd;
2970 uint32_t *lp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002971 uint32_t maxsize;
2972 uint16_t cmdsize;
2973 RPL *rpl;
2974 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05002975
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002976 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
2977 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002978 stat.un.b.lsRjtRsvd0 = 0;
2979 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2980 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
2981 stat.un.b.vendorUnique = 0;
2982 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05002983 }
2984
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002985 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2986 lp = (uint32_t *) pcmd->virt;
2987 rpl = (RPL *) (lp + 1);
2988
2989 maxsize = be32_to_cpu(rpl->maxsize);
2990
2991 /* We support only one port */
2992 if ((rpl->index == 0) &&
2993 ((maxsize == 0) ||
2994 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
2995 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002996 } else {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002997 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
2998 }
2999 lpfc_els_rsp_rpl_acc(phba, cmdsize, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05003000
3001 return 0;
3002}
3003
3004static int
3005lpfc_els_rcv_farp(struct lpfc_hba * phba,
3006 struct lpfc_iocbq * cmdiocb, struct lpfc_nodelist * ndlp)
3007{
3008 struct lpfc_dmabuf *pcmd;
3009 uint32_t *lp;
3010 IOCB_t *icmd;
3011 FARP *fp;
3012 uint32_t cmd, cnt, did;
3013
3014 icmd = &cmdiocb->iocb;
3015 did = icmd->un.elsreq64.remoteID;
3016 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3017 lp = (uint32_t *) pcmd->virt;
3018
3019 cmd = *lp++;
3020 fp = (FARP *) lp;
3021
3022 /* FARP-REQ received from DID <did> */
3023 lpfc_printf_log(phba,
3024 KERN_INFO,
James Smarta4bc3372006-12-02 13:34:16 -05003025 LOG_ELS,
dea31012005-04-17 16:05:31 -05003026 "%d:0601 FARP-REQ received from DID x%x\n",
3027 phba->brd_no, did);
3028
3029 /* We will only support match on WWPN or WWNN */
3030 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003031 return 0;
dea31012005-04-17 16:05:31 -05003032 }
3033
3034 cnt = 0;
3035 /* If this FARP command is searching for my portname */
3036 if (fp->Mflags & FARP_MATCH_PORT) {
3037 if (memcmp(&fp->RportName, &phba->fc_portname,
3038 sizeof (struct lpfc_name)) == 0)
3039 cnt = 1;
3040 }
3041
3042 /* If this FARP command is searching for my nodename */
3043 if (fp->Mflags & FARP_MATCH_NODE) {
3044 if (memcmp(&fp->RnodeName, &phba->fc_nodename,
3045 sizeof (struct lpfc_name)) == 0)
3046 cnt = 1;
3047 }
3048
3049 if (cnt) {
3050 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
3051 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
3052 /* Log back into the node before sending the FARP. */
3053 if (fp->Rflags & FARP_REQUEST_PLOGI) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003054 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smartde0c5b32007-04-25 09:52:27 -04003055 lpfc_nlp_set_state(phba, ndlp,
3056 NLP_STE_PLOGI_ISSUE);
James Smart488d1462006-03-07 15:02:37 -05003057 lpfc_issue_els_plogi(phba, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05003058 }
3059
3060 /* Send a FARP response to that node */
3061 if (fp->Rflags & FARP_REQUEST_FARPR) {
3062 lpfc_issue_els_farpr(phba, did, 0);
3063 }
3064 }
3065 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003066 return 0;
dea31012005-04-17 16:05:31 -05003067}
3068
3069static int
3070lpfc_els_rcv_farpr(struct lpfc_hba * phba,
3071 struct lpfc_iocbq * cmdiocb, struct lpfc_nodelist * ndlp)
3072{
3073 struct lpfc_dmabuf *pcmd;
3074 uint32_t *lp;
3075 IOCB_t *icmd;
3076 uint32_t cmd, did;
3077
3078 icmd = &cmdiocb->iocb;
3079 did = icmd->un.elsreq64.remoteID;
3080 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3081 lp = (uint32_t *) pcmd->virt;
3082
3083 cmd = *lp++;
3084 /* FARP-RSP received from DID <did> */
3085 lpfc_printf_log(phba,
3086 KERN_INFO,
James Smarta4bc3372006-12-02 13:34:16 -05003087 LOG_ELS,
dea31012005-04-17 16:05:31 -05003088 "%d:0600 FARP-RSP received from DID x%x\n",
3089 phba->brd_no, did);
3090
3091 /* ACCEPT the Farp resp request */
3092 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
3093
3094 return 0;
3095}
3096
3097static int
3098lpfc_els_rcv_fan(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003099 struct lpfc_nodelist * fan_ndlp)
dea31012005-04-17 16:05:31 -05003100{
3101 struct lpfc_dmabuf *pcmd;
3102 uint32_t *lp;
3103 IOCB_t *icmd;
dea31012005-04-17 16:05:31 -05003104 uint32_t cmd, did;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003105 FAN *fp;
3106 struct lpfc_nodelist *ndlp, *next_ndlp;
3107
3108 /* FAN received */
James Smartdca94792006-08-01 07:34:08 -04003109 lpfc_printf_log(phba, KERN_INFO, LOG_ELS, "%d:0265 FAN received\n",
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003110 phba->brd_no);
dea31012005-04-17 16:05:31 -05003111
3112 icmd = &cmdiocb->iocb;
3113 did = icmd->un.elsreq64.remoteID;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003114 pcmd = (struct lpfc_dmabuf *)cmdiocb->context2;
3115 lp = (uint32_t *)pcmd->virt;
dea31012005-04-17 16:05:31 -05003116
3117 cmd = *lp++;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003118 fp = (FAN *)lp;
dea31012005-04-17 16:05:31 -05003119
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003120 /* FAN received; Fan does not have a reply sequence */
dea31012005-04-17 16:05:31 -05003121
3122 if (phba->hba_state == LPFC_LOCAL_CFG_LINK) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003123 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
3124 sizeof(struct lpfc_name)) != 0) ||
3125 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
3126 sizeof(struct lpfc_name)) != 0)) {
3127 /*
3128 * This node has switched fabrics. FLOGI is required
3129 * Clean up the old rpi's
dea31012005-04-17 16:05:31 -05003130 */
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003131
3132 list_for_each_entry_safe(ndlp, next_ndlp,
James Smart685f0bf2007-04-25 09:53:08 -04003133 &phba->fc_nodes, nlp_listp) {
3134 if (ndlp->nlp_state != NLP_STE_NPR_NODE)
3135 continue;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003136 if (ndlp->nlp_type & NLP_FABRIC) {
3137 /*
3138 * Clean up old Fabric, Nameserver and
3139 * other NLP_FABRIC logins
3140 */
James Smartde0c5b32007-04-25 09:52:27 -04003141 lpfc_drop_node(phba, ndlp);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003142 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003143 /* Fail outstanding I/O now since this
3144 * device is marked for PLOGI
3145 */
3146 lpfc_unreg_rpi(phba, ndlp);
3147 }
3148 }
3149
3150 phba->hba_state = LPFC_FLOGI;
3151 lpfc_set_disctmo(phba);
3152 lpfc_initial_flogi(phba);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003153 return 0;
dea31012005-04-17 16:05:31 -05003154 }
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003155 /* Discovery not needed,
3156 * move the nodes to their original state.
3157 */
James Smart685f0bf2007-04-25 09:53:08 -04003158 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_nodes,
3159 nlp_listp) {
3160 if (ndlp->nlp_state != NLP_STE_NPR_NODE)
3161 continue;
dea31012005-04-17 16:05:31 -05003162
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003163 switch (ndlp->nlp_prev_state) {
3164 case NLP_STE_UNMAPPED_NODE:
3165 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smartde0c5b32007-04-25 09:52:27 -04003166 lpfc_nlp_set_state(phba, ndlp,
3167 NLP_STE_UNMAPPED_NODE);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003168 break;
3169
3170 case NLP_STE_MAPPED_NODE:
3171 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smartde0c5b32007-04-25 09:52:27 -04003172 lpfc_nlp_set_state(phba, ndlp,
3173 NLP_STE_MAPPED_NODE);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003174 break;
3175
3176 default:
3177 break;
3178 }
3179 }
3180
3181 /* Start discovery - this should just do CLEAR_LA */
dea31012005-04-17 16:05:31 -05003182 lpfc_disc_start(phba);
3183 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003184 return 0;
dea31012005-04-17 16:05:31 -05003185}
3186
3187void
3188lpfc_els_timeout(unsigned long ptr)
3189{
3190 struct lpfc_hba *phba;
3191 unsigned long iflag;
3192
3193 phba = (struct lpfc_hba *)ptr;
3194 if (phba == 0)
3195 return;
3196 spin_lock_irqsave(phba->host->host_lock, iflag);
3197 if (!(phba->work_hba_events & WORKER_ELS_TMO)) {
3198 phba->work_hba_events |= WORKER_ELS_TMO;
3199 if (phba->work_wait)
3200 wake_up(phba->work_wait);
3201 }
3202 spin_unlock_irqrestore(phba->host->host_lock, iflag);
3203 return;
3204}
3205
3206void
3207lpfc_els_timeout_handler(struct lpfc_hba *phba)
3208{
3209 struct lpfc_sli_ring *pring;
3210 struct lpfc_iocbq *tmp_iocb, *piocb;
3211 IOCB_t *cmd = NULL;
3212 struct lpfc_dmabuf *pcmd;
dea31012005-04-17 16:05:31 -05003213 uint32_t *elscmd;
James Smart7054a602007-04-25 09:52:34 -04003214 uint32_t els_command=0;
dea31012005-04-17 16:05:31 -05003215 uint32_t timeout;
3216 uint32_t remote_ID;
3217
3218 if (phba == 0)
3219 return;
3220 spin_lock_irq(phba->host->host_lock);
3221 /* If the timer is already canceled do nothing */
3222 if (!(phba->work_hba_events & WORKER_ELS_TMO)) {
3223 spin_unlock_irq(phba->host->host_lock);
3224 return;
3225 }
3226 timeout = (uint32_t)(phba->fc_ratov << 1);
3227
3228 pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05003229
3230 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
3231 cmd = &piocb->iocb;
3232
James Smart7054a602007-04-25 09:52:34 -04003233 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) ||
3234 (piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN) ||
3235 (piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)) {
dea31012005-04-17 16:05:31 -05003236 continue;
3237 }
3238 pcmd = (struct lpfc_dmabuf *) piocb->context2;
James Smart7054a602007-04-25 09:52:34 -04003239 if (pcmd) {
3240 elscmd = (uint32_t *) (pcmd->virt);
3241 els_command = *elscmd;
3242 }
dea31012005-04-17 16:05:31 -05003243
3244 if ((els_command == ELS_CMD_FARP)
3245 || (els_command == ELS_CMD_FARPR)) {
3246 continue;
3247 }
3248
3249 if (piocb->drvrTimeout > 0) {
3250 if (piocb->drvrTimeout >= timeout) {
3251 piocb->drvrTimeout -= timeout;
3252 } else {
3253 piocb->drvrTimeout = 0;
3254 }
3255 continue;
3256 }
3257
dea31012005-04-17 16:05:31 -05003258 if (cmd->ulpCommand == CMD_GEN_REQUEST64_CR) {
3259 struct lpfc_nodelist *ndlp;
James Smart2534ba72007-04-25 09:52:20 -04003260 ndlp = __lpfc_findnode_rpi(phba, cmd->ulpContext);
dea31012005-04-17 16:05:31 -05003261 remote_ID = ndlp->nlp_DID;
dea31012005-04-17 16:05:31 -05003262 } else {
3263 remote_ID = cmd->un.elsreq64.remoteID;
3264 }
3265
3266 lpfc_printf_log(phba,
3267 KERN_ERR,
3268 LOG_ELS,
3269 "%d:0127 ELS timeout Data: x%x x%x x%x x%x\n",
3270 phba->brd_no, els_command,
3271 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
3272
James Smart07951072007-04-25 09:51:38 -04003273 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05003274 }
James Smart5a0e3262006-07-06 15:49:16 -04003275 if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt)
3276 mod_timer(&phba->els_tmofunc, jiffies + HZ * timeout);
3277
dea31012005-04-17 16:05:31 -05003278 spin_unlock_irq(phba->host->host_lock);
3279}
3280
3281void
James Smart329f9bc2007-04-25 09:53:01 -04003282lpfc_els_flush_cmd(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -05003283{
James Smart2534ba72007-04-25 09:52:20 -04003284 LIST_HEAD(completions);
James Smart329f9bc2007-04-25 09:53:01 -04003285 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05003286 struct lpfc_iocbq *tmp_iocb, *piocb;
3287 IOCB_t *cmd = NULL;
dea31012005-04-17 16:05:31 -05003288
dea31012005-04-17 16:05:31 -05003289 spin_lock_irq(phba->host->host_lock);
3290 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
3291 cmd = &piocb->iocb;
3292
3293 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
3294 continue;
3295 }
3296
3297 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
James Smart329f9bc2007-04-25 09:53:01 -04003298 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
3299 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
3300 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
3301 cmd->ulpCommand == CMD_ABORT_XRI_CN)
dea31012005-04-17 16:05:31 -05003302 continue;
dea31012005-04-17 16:05:31 -05003303
James Smart2534ba72007-04-25 09:52:20 -04003304 list_move_tail(&piocb->list, &completions);
James Smart1dcb58e2007-04-25 09:51:30 -04003305 pring->txq_cnt--;
dea31012005-04-17 16:05:31 -05003306
dea31012005-04-17 16:05:31 -05003307 }
3308
3309 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
3310 cmd = &piocb->iocb;
3311
3312 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
3313 continue;
3314 }
dea31012005-04-17 16:05:31 -05003315
James Smart07951072007-04-25 09:51:38 -04003316 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05003317 }
3318 spin_unlock_irq(phba->host->host_lock);
James Smart2534ba72007-04-25 09:52:20 -04003319
3320 while(!list_empty(&completions)) {
3321 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
3322 cmd = &piocb->iocb;
3323 list_del(&piocb->list);
3324
3325 if (piocb->iocb_cmpl) {
3326 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
3327 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
3328 (piocb->iocb_cmpl) (phba, piocb, piocb);
3329 } else
3330 lpfc_sli_release_iocbq(phba, piocb);
3331 }
3332
dea31012005-04-17 16:05:31 -05003333 return;
3334}
3335
3336void
3337lpfc_els_unsol_event(struct lpfc_hba * phba,
3338 struct lpfc_sli_ring * pring, struct lpfc_iocbq * elsiocb)
3339{
3340 struct lpfc_sli *psli;
3341 struct lpfc_nodelist *ndlp;
3342 struct lpfc_dmabuf *mp;
3343 uint32_t *lp;
3344 IOCB_t *icmd;
3345 struct ls_rjt stat;
3346 uint32_t cmd;
3347 uint32_t did;
3348 uint32_t newnode;
3349 uint32_t drop_cmd = 0; /* by default do NOT drop received cmd */
3350 uint32_t rjt_err = 0;
3351
3352 psli = &phba->sli;
3353 icmd = &elsiocb->iocb;
3354
3355 if ((icmd->ulpStatus == IOSTAT_LOCAL_REJECT) &&
3356 ((icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING)) {
3357 /* Not enough posted buffers; Try posting more buffers */
3358 phba->fc_stat.NoRcvBuf++;
3359 lpfc_post_buffer(phba, pring, 0, 1);
3360 return;
3361 }
3362
3363 /* If there are no BDEs associated with this IOCB,
3364 * there is nothing to do.
3365 */
3366 if (icmd->ulpBdeCount == 0)
3367 return;
3368
3369 /* type of ELS cmd is first 32bit word in packet */
3370 mp = lpfc_sli_ringpostbuf_get(phba, pring, getPaddr(icmd->un.
3371 cont64[0].
3372 addrHigh,
3373 icmd->un.
3374 cont64[0].addrLow));
3375 if (mp == 0) {
3376 drop_cmd = 1;
3377 goto dropit;
3378 }
3379
3380 newnode = 0;
3381 lp = (uint32_t *) mp->virt;
3382 cmd = *lp++;
3383 lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], 1, 1);
3384
3385 if (icmd->ulpStatus) {
3386 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3387 kfree(mp);
3388 drop_cmd = 1;
3389 goto dropit;
3390 }
3391
3392 /* Check to see if link went down during discovery */
3393 if (lpfc_els_chk_latt(phba)) {
3394 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3395 kfree(mp);
3396 drop_cmd = 1;
3397 goto dropit;
3398 }
3399
3400 did = icmd->un.rcvels.remoteID;
James Smart685f0bf2007-04-25 09:53:08 -04003401 ndlp = lpfc_findnode_did(phba, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003402 if (!ndlp) {
dea31012005-04-17 16:05:31 -05003403 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003404 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
3405 if (!ndlp) {
dea31012005-04-17 16:05:31 -05003406 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3407 kfree(mp);
3408 drop_cmd = 1;
3409 goto dropit;
3410 }
3411
3412 lpfc_nlp_init(phba, ndlp, did);
3413 newnode = 1;
3414 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) {
3415 ndlp->nlp_type |= NLP_FABRIC;
3416 }
James Smartde0c5b32007-04-25 09:52:27 -04003417 lpfc_nlp_set_state(phba, ndlp, NLP_STE_UNUSED_NODE);
dea31012005-04-17 16:05:31 -05003418 }
3419
3420 phba->fc_stat.elsRcvFrame++;
James Smart329f9bc2007-04-25 09:53:01 -04003421 if (elsiocb->context1)
3422 lpfc_nlp_put(elsiocb->context1);
3423 elsiocb->context1 = lpfc_nlp_get(ndlp);
dea31012005-04-17 16:05:31 -05003424 elsiocb->context2 = mp;
3425
3426 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
3427 cmd &= ELS_CMD_MASK;
3428 }
3429 /* ELS command <elsCmd> received from NPORT <did> */
3430 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
3431 "%d:0112 ELS command x%x received from NPORT x%x "
3432 "Data: x%x\n", phba->brd_no, cmd, did, phba->hba_state);
3433
3434 switch (cmd) {
3435 case ELS_CMD_PLOGI:
3436 phba->fc_stat.elsRcvPLOGI++;
3437 if (phba->hba_state < LPFC_DISC_AUTH) {
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04003438 rjt_err = 1;
dea31012005-04-17 16:05:31 -05003439 break;
3440 }
James Smart92795652006-07-06 15:50:02 -04003441 ndlp = lpfc_plogi_confirm_nport(phba, mp, ndlp);
dea31012005-04-17 16:05:31 -05003442 lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_PLOGI);
3443 break;
3444 case ELS_CMD_FLOGI:
3445 phba->fc_stat.elsRcvFLOGI++;
3446 lpfc_els_rcv_flogi(phba, elsiocb, ndlp, newnode);
James Smartde0c5b32007-04-25 09:52:27 -04003447 if (newnode)
3448 lpfc_drop_node(phba, ndlp);
dea31012005-04-17 16:05:31 -05003449 break;
3450 case ELS_CMD_LOGO:
3451 phba->fc_stat.elsRcvLOGO++;
3452 if (phba->hba_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 }
3456 lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
3457 break;
3458 case ELS_CMD_PRLO:
3459 phba->fc_stat.elsRcvPRLO++;
3460 if (phba->hba_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 }
3464 lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
3465 break;
3466 case ELS_CMD_RSCN:
3467 phba->fc_stat.elsRcvRSCN++;
3468 lpfc_els_rcv_rscn(phba, elsiocb, ndlp, newnode);
James Smartde0c5b32007-04-25 09:52:27 -04003469 if (newnode)
3470 lpfc_drop_node(phba, ndlp);
dea31012005-04-17 16:05:31 -05003471 break;
3472 case ELS_CMD_ADISC:
3473 phba->fc_stat.elsRcvADISC++;
3474 if (phba->hba_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 }
3478 lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_ADISC);
3479 break;
3480 case ELS_CMD_PDISC:
3481 phba->fc_stat.elsRcvPDISC++;
3482 if (phba->hba_state < LPFC_DISC_AUTH) {
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04003483 rjt_err = 1;
dea31012005-04-17 16:05:31 -05003484 break;
3485 }
3486 lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_PDISC);
3487 break;
3488 case ELS_CMD_FARPR:
3489 phba->fc_stat.elsRcvFARPR++;
3490 lpfc_els_rcv_farpr(phba, elsiocb, ndlp);
3491 break;
3492 case ELS_CMD_FARP:
3493 phba->fc_stat.elsRcvFARP++;
3494 lpfc_els_rcv_farp(phba, elsiocb, ndlp);
3495 break;
3496 case ELS_CMD_FAN:
3497 phba->fc_stat.elsRcvFAN++;
3498 lpfc_els_rcv_fan(phba, elsiocb, ndlp);
3499 break;
dea31012005-04-17 16:05:31 -05003500 case ELS_CMD_PRLI:
3501 phba->fc_stat.elsRcvPRLI++;
3502 if (phba->hba_state < LPFC_DISC_AUTH) {
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04003503 rjt_err = 1;
dea31012005-04-17 16:05:31 -05003504 break;
3505 }
3506 lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
3507 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003508 case ELS_CMD_LIRR:
3509 phba->fc_stat.elsRcvLIRR++;
3510 lpfc_els_rcv_lirr(phba, elsiocb, ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04003511 if (newnode)
3512 lpfc_drop_node(phba, ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003513 break;
3514 case ELS_CMD_RPS:
3515 phba->fc_stat.elsRcvRPS++;
3516 lpfc_els_rcv_rps(phba, elsiocb, ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04003517 if (newnode)
3518 lpfc_drop_node(phba, ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003519 break;
3520 case ELS_CMD_RPL:
3521 phba->fc_stat.elsRcvRPL++;
3522 lpfc_els_rcv_rpl(phba, elsiocb, ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04003523 if (newnode)
3524 lpfc_drop_node(phba, ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003525 break;
dea31012005-04-17 16:05:31 -05003526 case ELS_CMD_RNID:
3527 phba->fc_stat.elsRcvRNID++;
3528 lpfc_els_rcv_rnid(phba, elsiocb, ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04003529 if (newnode)
3530 lpfc_drop_node(phba, ndlp);
dea31012005-04-17 16:05:31 -05003531 break;
3532 default:
3533 /* Unsupported ELS command, reject */
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04003534 rjt_err = 1;
dea31012005-04-17 16:05:31 -05003535
3536 /* Unknown ELS command <elsCmd> received from NPORT <did> */
3537 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
3538 "%d:0115 Unknown ELS command x%x received from "
3539 "NPORT x%x\n", phba->brd_no, cmd, did);
James Smartde0c5b32007-04-25 09:52:27 -04003540 if (newnode)
3541 lpfc_drop_node(phba, ndlp);
dea31012005-04-17 16:05:31 -05003542 break;
3543 }
3544
3545 /* check if need to LS_RJT received ELS cmd */
3546 if (rjt_err) {
3547 stat.un.b.lsRjtRsvd0 = 0;
3548 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04003549 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -05003550 stat.un.b.vendorUnique = 0;
3551 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, elsiocb, ndlp);
3552 }
3553
James Smart329f9bc2007-04-25 09:53:01 -04003554 lpfc_nlp_put(elsiocb->context1);
3555 elsiocb->context1 = NULL;
dea31012005-04-17 16:05:31 -05003556 if (elsiocb->context2) {
3557 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3558 kfree(mp);
3559 }
3560dropit:
3561 /* check if need to drop received ELS cmd */
3562 if (drop_cmd == 1) {
3563 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
3564 "%d:0111 Dropping received ELS cmd "
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003565 "Data: x%x x%x x%x\n", phba->brd_no,
3566 icmd->ulpStatus, icmd->un.ulpWord[4],
3567 icmd->ulpTimeout);
dea31012005-04-17 16:05:31 -05003568 phba->fc_stat.elsRcvDrop++;
3569 }
3570 return;
3571}