blob: 45abc76ff898987905767a70ac23b9f7e7ea3cc7 [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 Wellnitzc9f8735b2006-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;
185 } else {
186 icmd->un.elsreq64.bdl.bdeSize = sizeof (struct ulp_bde64);
187 icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
188 }
189
190 icmd->ulpBdeCount = 1;
191 icmd->ulpLe = 1;
192 icmd->ulpClass = CLASS3;
193
194 bpl = (struct ulp_bde64 *) pbuflist->virt;
195 bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys));
196 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys));
197 bpl->tus.f.bdeSize = cmdSize;
198 bpl->tus.f.bdeFlags = 0;
199 bpl->tus.w = le32_to_cpu(bpl->tus.w);
200
201 if (expectRsp) {
202 bpl++;
203 bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys));
204 bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys));
205 bpl->tus.f.bdeSize = FCELSSIZE;
206 bpl->tus.f.bdeFlags = BUFF_USE_RCV;
207 bpl->tus.w = le32_to_cpu(bpl->tus.w);
208 }
209
210 /* Save for completion so we can release these resources */
211 elsiocb->context1 = (uint8_t *) ndlp;
212 elsiocb->context2 = (uint8_t *) pcmd;
213 elsiocb->context3 = (uint8_t *) pbuflist;
214 elsiocb->retry = retry;
215 elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
216
217 if (prsp) {
218 list_add(&prsp->list, &pcmd->list);
219 }
220
221 if (expectRsp) {
222 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
223 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
224 "%d:0116 Xmit ELS command x%x to remote "
225 "NPORT x%x Data: x%x x%x\n",
226 phba->brd_no, elscmd,
James Smart488d1462006-03-07 15:02:37 -0500227 did, icmd->ulpIoTag, phba->hba_state);
dea31012005-04-17 16:05:31 -0500228 } else {
229 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
230 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
231 "%d:0117 Xmit ELS response x%x to remote "
232 "NPORT x%x Data: x%x x%x\n",
233 phba->brd_no, elscmd,
234 ndlp->nlp_DID, icmd->ulpIoTag, cmdSize);
235 }
236
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500237 return elsiocb;
dea31012005-04-17 16:05:31 -0500238}
239
240
241static int
242lpfc_cmpl_els_flogi_fabric(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
243 struct serv_parm *sp, IOCB_t *irsp)
244{
245 LPFC_MBOXQ_t *mbox;
246 int rc;
247
248 spin_lock_irq(phba->host->host_lock);
249 phba->fc_flag |= FC_FABRIC;
250 spin_unlock_irq(phba->host->host_lock);
251
252 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
253 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
254 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
255
256 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
257
258 if (phba->fc_topology == TOPOLOGY_LOOP) {
259 spin_lock_irq(phba->host->host_lock);
260 phba->fc_flag |= FC_PUBLIC_LOOP;
261 spin_unlock_irq(phba->host->host_lock);
262 } else {
263 /*
264 * If we are a N-port connected to a Fabric, fixup sparam's so
265 * logins to devices on remote loops work.
266 */
267 phba->fc_sparam.cmn.altBbCredit = 1;
268 }
269
270 phba->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
271 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
272 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof (struct lpfc_name));
273 ndlp->nlp_class_sup = 0;
274 if (sp->cls1.classValid)
275 ndlp->nlp_class_sup |= FC_COS_CLASS1;
276 if (sp->cls2.classValid)
277 ndlp->nlp_class_sup |= FC_COS_CLASS2;
278 if (sp->cls3.classValid)
279 ndlp->nlp_class_sup |= FC_COS_CLASS3;
280 if (sp->cls4.classValid)
281 ndlp->nlp_class_sup |= FC_COS_CLASS4;
282 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
283 sp->cmn.bbRcvSizeLsb;
284 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
285
286 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
287 if (!mbox)
288 goto fail;
289
290 phba->hba_state = LPFC_FABRIC_CFG_LINK;
291 lpfc_config_link(phba, mbox);
292 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
293
294 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT | MBX_STOP_IOCB);
295 if (rc == MBX_NOT_FINISHED)
296 goto fail_free_mbox;
297
298 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
299 if (!mbox)
300 goto fail;
301
302 if (lpfc_reg_login(phba, Fabric_DID, (uint8_t *) sp, mbox, 0))
303 goto fail_free_mbox;
304
dea31012005-04-17 16:05:31 -0500305 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
306 mbox->context2 = ndlp;
307
308 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT | MBX_STOP_IOCB);
309 if (rc == MBX_NOT_FINISHED)
310 goto fail_free_mbox;
311
312 return 0;
313
314 fail_free_mbox:
315 mempool_free(mbox, phba->mbox_mem_pool);
316 fail:
317 return -ENXIO;
318}
319
320/*
321 * We FLOGIed into an NPort, initiate pt2pt protocol
322 */
323static int
324lpfc_cmpl_els_flogi_nport(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
325 struct serv_parm *sp)
326{
327 LPFC_MBOXQ_t *mbox;
328 int rc;
329
330 spin_lock_irq(phba->host->host_lock);
331 phba->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
332 spin_unlock_irq(phba->host->host_lock);
333
334 phba->fc_edtov = FF_DEF_EDTOV;
335 phba->fc_ratov = FF_DEF_RATOV;
336 rc = memcmp(&phba->fc_portname, &sp->portName,
337 sizeof(struct lpfc_name));
338 if (rc >= 0) {
339 /* This side will initiate the PLOGI */
340 spin_lock_irq(phba->host->host_lock);
341 phba->fc_flag |= FC_PT2PT_PLOGI;
342 spin_unlock_irq(phba->host->host_lock);
343
344 /*
345 * N_Port ID cannot be 0, set our to LocalID the other
346 * side will be RemoteID.
347 */
348
349 /* not equal */
350 if (rc)
351 phba->fc_myDID = PT2PT_LocalID;
352
353 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
354 if (!mbox)
355 goto fail;
356
357 lpfc_config_link(phba, mbox);
358
359 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
360 rc = lpfc_sli_issue_mbox(phba, mbox,
361 MBX_NOWAIT | MBX_STOP_IOCB);
362 if (rc == MBX_NOT_FINISHED) {
363 mempool_free(mbox, phba->mbox_mem_pool);
364 goto fail;
365 }
366 mempool_free(ndlp, phba->nlp_mem_pool);
367
368 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, PT2PT_RemoteID);
369 if (!ndlp) {
370 /*
371 * Cannot find existing Fabric ndlp, so allocate a
372 * new one
373 */
374 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
375 if (!ndlp)
376 goto fail;
377
378 lpfc_nlp_init(phba, ndlp, PT2PT_RemoteID);
379 }
380
381 memcpy(&ndlp->nlp_portname, &sp->portName,
382 sizeof(struct lpfc_name));
383 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
384 sizeof(struct lpfc_name));
385 ndlp->nlp_state = NLP_STE_NPR_NODE;
386 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
387 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
388 } else {
389 /* This side will wait for the PLOGI */
390 mempool_free( ndlp, phba->nlp_mem_pool);
391 }
392
393 spin_lock_irq(phba->host->host_lock);
394 phba->fc_flag |= FC_PT2PT;
395 spin_unlock_irq(phba->host->host_lock);
396
397 /* Start discovery - this should just do CLEAR_LA */
398 lpfc_disc_start(phba);
399 return 0;
400 fail:
401 return -ENXIO;
402}
403
404static void
405lpfc_cmpl_els_flogi(struct lpfc_hba * phba,
406 struct lpfc_iocbq * cmdiocb, struct lpfc_iocbq * rspiocb)
407{
408 IOCB_t *irsp = &rspiocb->iocb;
409 struct lpfc_nodelist *ndlp = cmdiocb->context1;
410 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
411 struct serv_parm *sp;
412 int rc;
413
414 /* Check to see if link went down during discovery */
415 if (lpfc_els_chk_latt(phba)) {
416 lpfc_nlp_remove(phba, ndlp);
417 goto out;
418 }
419
420 if (irsp->ulpStatus) {
421 /* Check for retry */
422 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
423 /* ELS command is being retried */
424 goto out;
425 }
426 /* FLOGI failed, so there is no fabric */
427 spin_lock_irq(phba->host->host_lock);
428 phba->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
429 spin_unlock_irq(phba->host->host_lock);
430
431 /* If private loop, then allow max outstandting els to be
432 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
433 * alpa map would take too long otherwise.
434 */
435 if (phba->alpa_map[0] == 0) {
436 phba->cfg_discovery_threads =
437 LPFC_MAX_DISC_THREADS;
438 }
439
440 /* FLOGI failure */
441 lpfc_printf_log(phba,
442 KERN_INFO,
443 LOG_ELS,
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500444 "%d:0100 FLOGI failure Data: x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -0500445 phba->brd_no,
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500446 irsp->ulpStatus, irsp->un.ulpWord[4],
447 irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -0500448 goto flogifail;
449 }
450
451 /*
452 * The FLogI succeeded. Sync the data for the CPU before
453 * accessing it.
454 */
455 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
456
457 sp = prsp->virt + sizeof(uint32_t);
458
459 /* FLOGI completes successfully */
460 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
461 "%d:0101 FLOGI completes sucessfully "
462 "Data: x%x x%x x%x x%x\n",
463 phba->brd_no,
464 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
465 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution);
466
467 if (phba->hba_state == LPFC_FLOGI) {
468 /*
469 * If Common Service Parameters indicate Nport
470 * we are point to point, if Fport we are Fabric.
471 */
472 if (sp->cmn.fPort)
473 rc = lpfc_cmpl_els_flogi_fabric(phba, ndlp, sp, irsp);
474 else
475 rc = lpfc_cmpl_els_flogi_nport(phba, ndlp, sp);
476
477 if (!rc)
478 goto out;
479 }
480
481flogifail:
482 lpfc_nlp_remove(phba, ndlp);
483
484 if (irsp->ulpStatus != IOSTAT_LOCAL_REJECT ||
485 (irsp->un.ulpWord[4] != IOERR_SLI_ABORTED &&
486 irsp->un.ulpWord[4] != IOERR_SLI_DOWN)) {
487 /* FLOGI failed, so just use loop map to make discovery list */
488 lpfc_disc_list_loopmap(phba);
489
490 /* Start discovery */
491 lpfc_disc_start(phba);
492 }
493
494out:
495 lpfc_els_free_iocb(phba, cmdiocb);
496}
497
498static int
499lpfc_issue_els_flogi(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
500 uint8_t retry)
501{
502 struct serv_parm *sp;
503 IOCB_t *icmd;
504 struct lpfc_iocbq *elsiocb;
505 struct lpfc_sli_ring *pring;
506 uint8_t *pcmd;
507 uint16_t cmdsize;
508 uint32_t tmo;
509 int rc;
510
511 pring = &phba->sli.ring[LPFC_ELS_RING];
512
513 cmdsize = (sizeof (uint32_t) + sizeof (struct serv_parm));
James Smart488d1462006-03-07 15:02:37 -0500514 elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry, ndlp,
515 ndlp->nlp_DID, ELS_CMD_FLOGI);
516 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500517 return 1;
dea31012005-04-17 16:05:31 -0500518
519 icmd = &elsiocb->iocb;
520 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
521
522 /* For FLOGI request, remainder of payload is service parameters */
523 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
524 pcmd += sizeof (uint32_t);
525 memcpy(pcmd, &phba->fc_sparam, sizeof (struct serv_parm));
526 sp = (struct serv_parm *) pcmd;
527
528 /* Setup CSPs accordingly for Fabric */
529 sp->cmn.e_d_tov = 0;
530 sp->cmn.w2.r_a_tov = 0;
531 sp->cls1.classValid = 0;
532 sp->cls2.seqDelivery = 1;
533 sp->cls3.seqDelivery = 1;
534 if (sp->cmn.fcphLow < FC_PH3)
535 sp->cmn.fcphLow = FC_PH3;
536 if (sp->cmn.fcphHigh < FC_PH3)
537 sp->cmn.fcphHigh = FC_PH3;
538
539 tmo = phba->fc_ratov;
540 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
541 lpfc_set_disctmo(phba);
542 phba->fc_ratov = tmo;
543
544 phba->fc_stat.elsXmitFLOGI++;
545 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
546 spin_lock_irq(phba->host->host_lock);
547 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
548 spin_unlock_irq(phba->host->host_lock);
549 if (rc == IOCB_ERROR) {
550 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500551 return 1;
dea31012005-04-17 16:05:31 -0500552 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500553 return 0;
dea31012005-04-17 16:05:31 -0500554}
555
556int
557lpfc_els_abort_flogi(struct lpfc_hba * phba)
558{
559 struct lpfc_sli_ring *pring;
560 struct lpfc_iocbq *iocb, *next_iocb;
561 struct lpfc_nodelist *ndlp;
562 IOCB_t *icmd;
563
564 /* Abort outstanding I/O on NPort <nlp_DID> */
565 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
566 "%d:0201 Abort outstanding I/O on NPort x%x\n",
567 phba->brd_no, Fabric_DID);
568
569 pring = &phba->sli.ring[LPFC_ELS_RING];
570
571 /*
572 * Check the txcmplq for an iocb that matches the nport the driver is
573 * searching for.
574 */
575 spin_lock_irq(phba->host->host_lock);
576 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
577 icmd = &iocb->iocb;
578 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) {
579 ndlp = (struct lpfc_nodelist *)(iocb->context1);
580 if (ndlp && (ndlp->nlp_DID == Fabric_DID)) {
581 list_del(&iocb->list);
582 pring->txcmplq_cnt--;
583
584 if ((icmd->un.elsreq64.bdl.ulpIoTag32)) {
585 lpfc_sli_issue_abort_iotag32
586 (phba, pring, iocb);
587 }
588 if (iocb->iocb_cmpl) {
589 icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
590 icmd->un.ulpWord[4] =
591 IOERR_SLI_ABORTED;
592 spin_unlock_irq(phba->host->host_lock);
593 (iocb->iocb_cmpl) (phba, iocb, iocb);
594 spin_lock_irq(phba->host->host_lock);
James Bottomley604a3e32005-10-29 10:28:33 -0500595 } else
596 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -0500597 }
598 }
599 }
600 spin_unlock_irq(phba->host->host_lock);
601
602 return 0;
603}
604
605int
606lpfc_initial_flogi(struct lpfc_hba * phba)
607{
608 struct lpfc_nodelist *ndlp;
609
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500610 /* First look for the Fabric ndlp */
611 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, Fabric_DID);
612 if (!ndlp) {
dea31012005-04-17 16:05:31 -0500613 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500614 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
615 if (!ndlp)
616 return 0;
dea31012005-04-17 16:05:31 -0500617 lpfc_nlp_init(phba, ndlp, Fabric_DID);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500618 } else {
619 lpfc_nlp_list(phba, ndlp, NLP_JUST_DQ);
dea31012005-04-17 16:05:31 -0500620 }
621 if (lpfc_issue_els_flogi(phba, ndlp, 0)) {
622 mempool_free( ndlp, phba->nlp_mem_pool);
623 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500624 return 1;
dea31012005-04-17 16:05:31 -0500625}
626
627static void
628lpfc_more_plogi(struct lpfc_hba * phba)
629{
630 int sentplogi;
631
632 if (phba->num_disc_nodes)
633 phba->num_disc_nodes--;
634
635 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
636 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
637 "%d:0232 Continue discovery with %d PLOGIs to go "
638 "Data: x%x x%x x%x\n",
639 phba->brd_no, phba->num_disc_nodes, phba->fc_plogi_cnt,
640 phba->fc_flag, phba->hba_state);
641
642 /* Check to see if there are more PLOGIs to be sent */
643 if (phba->fc_flag & FC_NLP_MORE) {
644 /* go thru NPR list and issue any remaining ELS PLOGIs */
645 sentplogi = lpfc_els_disc_plogi(phba);
646 }
647 return;
648}
649
James Smart488d1462006-03-07 15:02:37 -0500650static struct lpfc_nodelist *
651lpfc_plogi_confirm_nport(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
652 struct lpfc_nodelist *ndlp)
653{
654 struct lpfc_nodelist *new_ndlp;
655 struct lpfc_dmabuf *pcmd, *prsp;
656 uint32_t *lp;
657 struct serv_parm *sp;
658 uint8_t name[sizeof (struct lpfc_name)];
659 uint32_t rc;
660
661 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
662 prsp = (struct lpfc_dmabuf *) pcmd->list.next;
663 lp = (uint32_t *) prsp->virt;
664 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
665
666 /* Now we to find out if the NPort we are logging into, matches the WWPN
667 * we have for that ndlp. If not, we have some work to do.
668 */
669 new_ndlp = lpfc_findnode_wwpn(phba, NLP_SEARCH_ALL, &sp->portName);
670
671 memset(name, 0, sizeof (struct lpfc_name));
672 rc = memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name));
673 if (!rc || (new_ndlp == ndlp)) {
674 return ndlp;
675 }
676
677 if (!new_ndlp) {
678 new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
679 if (!new_ndlp)
680 return ndlp;
681
682 lpfc_nlp_init(phba, new_ndlp, ndlp->nlp_DID);
683 }
684
685 lpfc_unreg_rpi(phba, new_ndlp);
686 new_ndlp->nlp_prev_state = ndlp->nlp_state;
687 new_ndlp->nlp_DID = ndlp->nlp_DID;
688 new_ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
689 lpfc_nlp_list(phba, new_ndlp, NLP_PLOGI_LIST);
690
691 /* Move this back to NPR list */
692 lpfc_unreg_rpi(phba, ndlp);
693 ndlp->nlp_DID = 0; /* Two ndlps cannot have the same did */
694 ndlp->nlp_state = NLP_STE_NPR_NODE;
695 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
696
697 return new_ndlp;
698}
699
dea31012005-04-17 16:05:31 -0500700static void
701lpfc_cmpl_els_plogi(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
702 struct lpfc_iocbq * rspiocb)
703{
704 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -0500705 struct lpfc_nodelist *ndlp;
706 int disc, rc, did, type;
707
dea31012005-04-17 16:05:31 -0500708
709 /* we pass cmdiocb to state machine which needs rspiocb as well */
710 cmdiocb->context_un.rsp_iocb = rspiocb;
711
712 irsp = &rspiocb->iocb;
James Smart488d1462006-03-07 15:02:37 -0500713 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL,
714 irsp->un.elsreq64.remoteID);
715 if (!ndlp)
716 goto out;
dea31012005-04-17 16:05:31 -0500717
718 /* Since ndlp can be freed in the disc state machine, note if this node
719 * is being used during discovery.
720 */
721 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500722 spin_lock_irq(phba->host->host_lock);
James Smart488d1462006-03-07 15:02:37 -0500723 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500724 spin_unlock_irq(phba->host->host_lock);
dea31012005-04-17 16:05:31 -0500725 rc = 0;
726
727 /* PLOGI completes to NPort <nlp_DID> */
728 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
729 "%d:0102 PLOGI completes to NPort x%x "
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500730 "Data: x%x x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -0500731 phba->brd_no, ndlp->nlp_DID, irsp->ulpStatus,
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500732 irsp->un.ulpWord[4], irsp->ulpTimeout, disc,
733 phba->num_disc_nodes);
dea31012005-04-17 16:05:31 -0500734
735 /* Check to see if link went down during discovery */
736 if (lpfc_els_chk_latt(phba)) {
737 spin_lock_irq(phba->host->host_lock);
738 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
739 spin_unlock_irq(phba->host->host_lock);
740 goto out;
741 }
742
743 /* ndlp could be freed in DSM, save these values now */
744 type = ndlp->nlp_type;
745 did = ndlp->nlp_DID;
746
747 if (irsp->ulpStatus) {
748 /* Check for retry */
749 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
750 /* ELS command is being retried */
751 if (disc) {
752 spin_lock_irq(phba->host->host_lock);
753 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
754 spin_unlock_irq(phba->host->host_lock);
755 }
756 goto out;
757 }
758
759 /* PLOGI failed */
760 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
761 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
762 ((irsp->un.ulpWord[4] == IOERR_SLI_ABORTED) ||
James.Smart@Emulex.Com6281bfe2005-11-28 11:41:33 -0500763 (irsp->un.ulpWord[4] == IOERR_LINK_DOWN) ||
dea31012005-04-17 16:05:31 -0500764 (irsp->un.ulpWord[4] == IOERR_SLI_DOWN))) {
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500765 rc = NLP_STE_FREED_NODE;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500766 } else {
dea31012005-04-17 16:05:31 -0500767 rc = lpfc_disc_state_machine(phba, ndlp, cmdiocb,
768 NLP_EVT_CMPL_PLOGI);
769 }
770 } else {
771 /* Good status, call state machine */
James Smart488d1462006-03-07 15:02:37 -0500772 ndlp = lpfc_plogi_confirm_nport(phba, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -0500773 rc = lpfc_disc_state_machine(phba, ndlp, cmdiocb,
774 NLP_EVT_CMPL_PLOGI);
775 }
776
dea31012005-04-17 16:05:31 -0500777 if (disc && phba->num_disc_nodes) {
778 /* Check to see if there are more PLOGIs to be sent */
779 lpfc_more_plogi(phba);
780 }
781
dea31012005-04-17 16:05:31 -0500782 if (phba->num_disc_nodes == 0) {
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500783 spin_lock_irq(phba->host->host_lock);
784 phba->fc_flag &= ~FC_NDISC_ACTIVE;
785 spin_unlock_irq(phba->host->host_lock);
786
dea31012005-04-17 16:05:31 -0500787 lpfc_can_disctmo(phba);
788 if (phba->fc_flag & FC_RSCN_MODE) {
789 /* Check to see if more RSCNs came in while we were
790 * processing this one.
791 */
792 if ((phba->fc_rscn_id_cnt == 0) &&
793 (!(phba->fc_flag & FC_RSCN_DISCOVERY))) {
794 spin_lock_irq(phba->host->host_lock);
795 phba->fc_flag &= ~FC_RSCN_MODE;
796 spin_unlock_irq(phba->host->host_lock);
797 } else {
798 lpfc_els_handle_rscn(phba);
799 }
800 }
801 }
802
803out:
804 lpfc_els_free_iocb(phba, cmdiocb);
805 return;
806}
807
808int
James Smart488d1462006-03-07 15:02:37 -0500809lpfc_issue_els_plogi(struct lpfc_hba * phba, uint32_t did, uint8_t retry)
dea31012005-04-17 16:05:31 -0500810{
811 struct serv_parm *sp;
812 IOCB_t *icmd;
813 struct lpfc_iocbq *elsiocb;
814 struct lpfc_sli_ring *pring;
815 struct lpfc_sli *psli;
816 uint8_t *pcmd;
817 uint16_t cmdsize;
818
819 psli = &phba->sli;
820 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
821
822 cmdsize = (sizeof (uint32_t) + sizeof (struct serv_parm));
James Smart488d1462006-03-07 15:02:37 -0500823 elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry, 0, did,
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500824 ELS_CMD_PLOGI);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500825 if (!elsiocb)
826 return 1;
dea31012005-04-17 16:05:31 -0500827
828 icmd = &elsiocb->iocb;
829 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
830
831 /* For PLOGI request, remainder of payload is service parameters */
832 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
833 pcmd += sizeof (uint32_t);
834 memcpy(pcmd, &phba->fc_sparam, sizeof (struct serv_parm));
835 sp = (struct serv_parm *) pcmd;
836
837 if (sp->cmn.fcphLow < FC_PH_4_3)
838 sp->cmn.fcphLow = FC_PH_4_3;
839
840 if (sp->cmn.fcphHigh < FC_PH3)
841 sp->cmn.fcphHigh = FC_PH3;
842
843 phba->fc_stat.elsXmitPLOGI++;
844 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
845 spin_lock_irq(phba->host->host_lock);
dea31012005-04-17 16:05:31 -0500846 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
dea31012005-04-17 16:05:31 -0500847 spin_unlock_irq(phba->host->host_lock);
848 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500849 return 1;
dea31012005-04-17 16:05:31 -0500850 }
851 spin_unlock_irq(phba->host->host_lock);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500852 return 0;
dea31012005-04-17 16:05:31 -0500853}
854
855static void
856lpfc_cmpl_els_prli(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
857 struct lpfc_iocbq * rspiocb)
858{
859 IOCB_t *irsp;
860 struct lpfc_sli *psli;
861 struct lpfc_nodelist *ndlp;
862
863 psli = &phba->sli;
864 /* we pass cmdiocb to state machine which needs rspiocb as well */
865 cmdiocb->context_un.rsp_iocb = rspiocb;
866
867 irsp = &(rspiocb->iocb);
868 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
869 spin_lock_irq(phba->host->host_lock);
870 ndlp->nlp_flag &= ~NLP_PRLI_SND;
871 spin_unlock_irq(phba->host->host_lock);
872
873 /* PRLI completes to NPort <nlp_DID> */
874 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
875 "%d:0103 PRLI completes to NPort x%x "
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500876 "Data: x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -0500877 phba->brd_no, ndlp->nlp_DID, irsp->ulpStatus,
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500878 irsp->un.ulpWord[4], irsp->ulpTimeout,
879 phba->num_disc_nodes);
dea31012005-04-17 16:05:31 -0500880
881 phba->fc_prli_sent--;
882 /* Check to see if link went down during discovery */
883 if (lpfc_els_chk_latt(phba))
884 goto out;
885
886 if (irsp->ulpStatus) {
887 /* Check for retry */
888 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
889 /* ELS command is being retried */
890 goto out;
891 }
892 /* PRLI failed */
893 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
894 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
895 ((irsp->un.ulpWord[4] == IOERR_SLI_ABORTED) ||
James.Smart@Emulex.Com6281bfe2005-11-28 11:41:33 -0500896 (irsp->un.ulpWord[4] == IOERR_LINK_DOWN) ||
dea31012005-04-17 16:05:31 -0500897 (irsp->un.ulpWord[4] == IOERR_SLI_DOWN))) {
898 goto out;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500899 } else {
dea31012005-04-17 16:05:31 -0500900 lpfc_disc_state_machine(phba, ndlp, cmdiocb,
901 NLP_EVT_CMPL_PRLI);
902 }
903 } else {
904 /* Good status, call state machine */
905 lpfc_disc_state_machine(phba, ndlp, cmdiocb, NLP_EVT_CMPL_PRLI);
906 }
907
908out:
909 lpfc_els_free_iocb(phba, cmdiocb);
910 return;
911}
912
913int
914lpfc_issue_els_prli(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
915 uint8_t retry)
916{
917 PRLI *npr;
918 IOCB_t *icmd;
919 struct lpfc_iocbq *elsiocb;
920 struct lpfc_sli_ring *pring;
921 struct lpfc_sli *psli;
922 uint8_t *pcmd;
923 uint16_t cmdsize;
924
925 psli = &phba->sli;
926 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
927
928 cmdsize = (sizeof (uint32_t) + sizeof (PRLI));
James Smart488d1462006-03-07 15:02:37 -0500929 elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry, ndlp,
930 ndlp->nlp_DID, ELS_CMD_PRLI);
931 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500932 return 1;
dea31012005-04-17 16:05:31 -0500933
934 icmd = &elsiocb->iocb;
935 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
936
937 /* For PRLI request, remainder of payload is service parameters */
938 memset(pcmd, 0, (sizeof (PRLI) + sizeof (uint32_t)));
939 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
940 pcmd += sizeof (uint32_t);
941
942 /* For PRLI, remainder of payload is PRLI parameter page */
943 npr = (PRLI *) pcmd;
944 /*
945 * If our firmware version is 3.20 or later,
946 * set the following bits for FC-TAPE support.
947 */
948 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
949 npr->ConfmComplAllowed = 1;
950 npr->Retry = 1;
951 npr->TaskRetryIdReq = 1;
952 }
953 npr->estabImagePair = 1;
954 npr->readXferRdyDis = 1;
955
956 /* For FCP support */
957 npr->prliType = PRLI_FCP_TYPE;
958 npr->initiatorFunc = 1;
959
960 phba->fc_stat.elsXmitPRLI++;
961 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
962 spin_lock_irq(phba->host->host_lock);
963 ndlp->nlp_flag |= NLP_PRLI_SND;
964 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
965 ndlp->nlp_flag &= ~NLP_PRLI_SND;
966 spin_unlock_irq(phba->host->host_lock);
967 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500968 return 1;
dea31012005-04-17 16:05:31 -0500969 }
970 spin_unlock_irq(phba->host->host_lock);
971 phba->fc_prli_sent++;
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500972 return 0;
dea31012005-04-17 16:05:31 -0500973}
974
975static void
976lpfc_more_adisc(struct lpfc_hba * phba)
977{
978 int sentadisc;
979
980 if (phba->num_disc_nodes)
981 phba->num_disc_nodes--;
982
983 /* Continue discovery with <num_disc_nodes> ADISCs to go */
984 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
985 "%d:0210 Continue discovery with %d ADISCs to go "
986 "Data: x%x x%x x%x\n",
987 phba->brd_no, phba->num_disc_nodes, phba->fc_adisc_cnt,
988 phba->fc_flag, phba->hba_state);
989
990 /* Check to see if there are more ADISCs to be sent */
991 if (phba->fc_flag & FC_NLP_MORE) {
992 lpfc_set_disctmo(phba);
993
994 /* go thru NPR list and issue any remaining ELS ADISCs */
995 sentadisc = lpfc_els_disc_adisc(phba);
996 }
997 return;
998}
999
1000static void
1001lpfc_rscn_disc(struct lpfc_hba * phba)
1002{
1003 /* RSCN discovery */
1004 /* go thru NPR list and issue ELS PLOGIs */
1005 if (phba->fc_npr_cnt) {
1006 if (lpfc_els_disc_plogi(phba))
1007 return;
1008 }
1009 if (phba->fc_flag & FC_RSCN_MODE) {
1010 /* Check to see if more RSCNs came in while we were
1011 * processing this one.
1012 */
1013 if ((phba->fc_rscn_id_cnt == 0) &&
1014 (!(phba->fc_flag & FC_RSCN_DISCOVERY))) {
1015 spin_lock_irq(phba->host->host_lock);
1016 phba->fc_flag &= ~FC_RSCN_MODE;
1017 spin_unlock_irq(phba->host->host_lock);
1018 } else {
1019 lpfc_els_handle_rscn(phba);
1020 }
1021 }
1022}
1023
1024static void
1025lpfc_cmpl_els_adisc(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
1026 struct lpfc_iocbq * rspiocb)
1027{
1028 IOCB_t *irsp;
1029 struct lpfc_sli *psli;
1030 struct lpfc_nodelist *ndlp;
1031 LPFC_MBOXQ_t *mbox;
1032 int disc, rc;
1033
1034 psli = &phba->sli;
1035
1036 /* we pass cmdiocb to state machine which needs rspiocb as well */
1037 cmdiocb->context_un.rsp_iocb = rspiocb;
1038
1039 irsp = &(rspiocb->iocb);
1040 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
dea31012005-04-17 16:05:31 -05001041
1042 /* Since ndlp can be freed in the disc state machine, note if this node
1043 * is being used during discovery.
1044 */
1045 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001046 spin_lock_irq(phba->host->host_lock);
1047 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
1048 spin_unlock_irq(phba->host->host_lock);
dea31012005-04-17 16:05:31 -05001049
1050 /* ADISC completes to NPort <nlp_DID> */
1051 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1052 "%d:0104 ADISC completes to NPort x%x "
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001053 "Data: x%x x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -05001054 phba->brd_no, ndlp->nlp_DID, irsp->ulpStatus,
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001055 irsp->un.ulpWord[4], irsp->ulpTimeout, disc,
1056 phba->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001057
1058 /* Check to see if link went down during discovery */
1059 if (lpfc_els_chk_latt(phba)) {
1060 spin_lock_irq(phba->host->host_lock);
1061 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1062 spin_unlock_irq(phba->host->host_lock);
1063 goto out;
1064 }
1065
1066 if (irsp->ulpStatus) {
1067 /* Check for retry */
1068 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1069 /* ELS command is being retried */
1070 if (disc) {
1071 spin_lock_irq(phba->host->host_lock);
1072 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1073 spin_unlock_irq(phba->host->host_lock);
1074 lpfc_set_disctmo(phba);
1075 }
1076 goto out;
1077 }
1078 /* ADISC failed */
1079 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001080 if ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
1081 ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) &&
1082 (irsp->un.ulpWord[4] != IOERR_LINK_DOWN) &&
1083 (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) {
dea31012005-04-17 16:05:31 -05001084 lpfc_disc_state_machine(phba, ndlp, cmdiocb,
1085 NLP_EVT_CMPL_ADISC);
1086 }
1087 } else {
1088 /* Good status, call state machine */
1089 lpfc_disc_state_machine(phba, ndlp, cmdiocb,
1090 NLP_EVT_CMPL_ADISC);
1091 }
1092
1093 if (disc && phba->num_disc_nodes) {
1094 /* Check to see if there are more ADISCs to be sent */
1095 lpfc_more_adisc(phba);
1096
1097 /* Check to see if we are done with ADISC authentication */
1098 if (phba->num_disc_nodes == 0) {
1099 lpfc_can_disctmo(phba);
1100 /* If we get here, there is nothing left to wait for */
1101 if ((phba->hba_state < LPFC_HBA_READY) &&
1102 (phba->hba_state != LPFC_CLEAR_LA)) {
1103 /* Link up discovery */
1104 if ((mbox = mempool_alloc(phba->mbox_mem_pool,
1105 GFP_KERNEL))) {
1106 phba->hba_state = LPFC_CLEAR_LA;
1107 lpfc_clear_la(phba, mbox);
1108 mbox->mbox_cmpl =
1109 lpfc_mbx_cmpl_clear_la;
1110 rc = lpfc_sli_issue_mbox
1111 (phba, mbox,
1112 (MBX_NOWAIT | MBX_STOP_IOCB));
1113 if (rc == MBX_NOT_FINISHED) {
1114 mempool_free(mbox,
1115 phba->mbox_mem_pool);
1116 lpfc_disc_flush_list(phba);
1117 psli->ring[(psli->ip_ring)].
1118 flag &=
1119 ~LPFC_STOP_IOCB_EVENT;
1120 psli->ring[(psli->fcp_ring)].
1121 flag &=
1122 ~LPFC_STOP_IOCB_EVENT;
1123 psli->ring[(psli->next_ring)].
1124 flag &=
1125 ~LPFC_STOP_IOCB_EVENT;
1126 phba->hba_state =
1127 LPFC_HBA_READY;
1128 }
1129 }
1130 } else {
1131 lpfc_rscn_disc(phba);
1132 }
1133 }
1134 }
dea31012005-04-17 16:05:31 -05001135out:
1136 lpfc_els_free_iocb(phba, cmdiocb);
1137 return;
1138}
1139
1140int
1141lpfc_issue_els_adisc(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
1142 uint8_t retry)
1143{
1144 ADISC *ap;
1145 IOCB_t *icmd;
1146 struct lpfc_iocbq *elsiocb;
1147 struct lpfc_sli_ring *pring;
1148 struct lpfc_sli *psli;
1149 uint8_t *pcmd;
1150 uint16_t cmdsize;
1151
1152 psli = &phba->sli;
1153 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1154
1155 cmdsize = (sizeof (uint32_t) + sizeof (ADISC));
James Smart488d1462006-03-07 15:02:37 -05001156 elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry, ndlp,
1157 ndlp->nlp_DID, ELS_CMD_ADISC);
1158 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001159 return 1;
dea31012005-04-17 16:05:31 -05001160
1161 icmd = &elsiocb->iocb;
1162 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1163
1164 /* For ADISC request, remainder of payload is service parameters */
1165 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
1166 pcmd += sizeof (uint32_t);
1167
1168 /* Fill in ADISC payload */
1169 ap = (ADISC *) pcmd;
1170 ap->hardAL_PA = phba->fc_pref_ALPA;
1171 memcpy(&ap->portName, &phba->fc_portname, sizeof (struct lpfc_name));
1172 memcpy(&ap->nodeName, &phba->fc_nodename, sizeof (struct lpfc_name));
1173 ap->DID = be32_to_cpu(phba->fc_myDID);
1174
1175 phba->fc_stat.elsXmitADISC++;
1176 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
1177 spin_lock_irq(phba->host->host_lock);
1178 ndlp->nlp_flag |= NLP_ADISC_SND;
1179 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
1180 ndlp->nlp_flag &= ~NLP_ADISC_SND;
1181 spin_unlock_irq(phba->host->host_lock);
1182 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001183 return 1;
dea31012005-04-17 16:05:31 -05001184 }
1185 spin_unlock_irq(phba->host->host_lock);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001186 return 0;
dea31012005-04-17 16:05:31 -05001187}
1188
1189static void
1190lpfc_cmpl_els_logo(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
1191 struct lpfc_iocbq * rspiocb)
1192{
1193 IOCB_t *irsp;
1194 struct lpfc_sli *psli;
1195 struct lpfc_nodelist *ndlp;
1196
1197 psli = &phba->sli;
1198 /* we pass cmdiocb to state machine which needs rspiocb as well */
1199 cmdiocb->context_un.rsp_iocb = rspiocb;
1200
1201 irsp = &(rspiocb->iocb);
1202 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1203 spin_lock_irq(phba->host->host_lock);
1204 ndlp->nlp_flag &= ~NLP_LOGO_SND;
1205 spin_unlock_irq(phba->host->host_lock);
1206
1207 /* LOGO completes to NPort <nlp_DID> */
1208 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1209 "%d:0105 LOGO completes to NPort x%x "
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001210 "Data: x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -05001211 phba->brd_no, ndlp->nlp_DID, irsp->ulpStatus,
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001212 irsp->un.ulpWord[4], irsp->ulpTimeout,
1213 phba->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001214
1215 /* Check to see if link went down during discovery */
1216 if (lpfc_els_chk_latt(phba))
1217 goto out;
1218
1219 if (irsp->ulpStatus) {
1220 /* Check for retry */
1221 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1222 /* ELS command is being retried */
1223 goto out;
1224 }
1225 /* LOGO failed */
1226 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1227 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
1228 ((irsp->un.ulpWord[4] == IOERR_SLI_ABORTED) ||
James.Smart@Emulex.Com6281bfe2005-11-28 11:41:33 -05001229 (irsp->un.ulpWord[4] == IOERR_LINK_DOWN) ||
dea31012005-04-17 16:05:31 -05001230 (irsp->un.ulpWord[4] == IOERR_SLI_DOWN))) {
1231 goto out;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001232 } else {
dea31012005-04-17 16:05:31 -05001233 lpfc_disc_state_machine(phba, ndlp, cmdiocb,
1234 NLP_EVT_CMPL_LOGO);
1235 }
1236 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001237 /* Good status, call state machine.
1238 * This will unregister the rpi if needed.
1239 */
dea31012005-04-17 16:05:31 -05001240 lpfc_disc_state_machine(phba, ndlp, cmdiocb, NLP_EVT_CMPL_LOGO);
dea31012005-04-17 16:05:31 -05001241 }
1242
1243out:
1244 lpfc_els_free_iocb(phba, cmdiocb);
1245 return;
1246}
1247
1248int
1249lpfc_issue_els_logo(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
1250 uint8_t retry)
1251{
1252 IOCB_t *icmd;
1253 struct lpfc_iocbq *elsiocb;
1254 struct lpfc_sli_ring *pring;
1255 struct lpfc_sli *psli;
1256 uint8_t *pcmd;
1257 uint16_t cmdsize;
1258
1259 psli = &phba->sli;
1260 pring = &psli->ring[LPFC_ELS_RING];
1261
1262 cmdsize = 2 * (sizeof (uint32_t) + sizeof (struct lpfc_name));
James Smart488d1462006-03-07 15:02:37 -05001263 elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry, ndlp,
1264 ndlp->nlp_DID, ELS_CMD_LOGO);
1265 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001266 return 1;
dea31012005-04-17 16:05:31 -05001267
1268 icmd = &elsiocb->iocb;
1269 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1270 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
1271 pcmd += sizeof (uint32_t);
1272
1273 /* Fill in LOGO payload */
1274 *((uint32_t *) (pcmd)) = be32_to_cpu(phba->fc_myDID);
1275 pcmd += sizeof (uint32_t);
1276 memcpy(pcmd, &phba->fc_portname, sizeof (struct lpfc_name));
1277
1278 phba->fc_stat.elsXmitLOGO++;
1279 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
1280 spin_lock_irq(phba->host->host_lock);
1281 ndlp->nlp_flag |= NLP_LOGO_SND;
1282 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
1283 ndlp->nlp_flag &= ~NLP_LOGO_SND;
1284 spin_unlock_irq(phba->host->host_lock);
1285 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001286 return 1;
dea31012005-04-17 16:05:31 -05001287 }
1288 spin_unlock_irq(phba->host->host_lock);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001289 return 0;
dea31012005-04-17 16:05:31 -05001290}
1291
1292static void
1293lpfc_cmpl_els_cmd(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
1294 struct lpfc_iocbq * rspiocb)
1295{
1296 IOCB_t *irsp;
1297
1298 irsp = &rspiocb->iocb;
1299
1300 /* ELS cmd tag <ulpIoTag> completes */
1301 lpfc_printf_log(phba,
1302 KERN_INFO,
1303 LOG_ELS,
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001304 "%d:0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -05001305 phba->brd_no,
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001306 irsp->ulpIoTag, irsp->ulpStatus,
1307 irsp->un.ulpWord[4], irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -05001308
1309 /* Check to see if link went down during discovery */
1310 lpfc_els_chk_latt(phba);
1311 lpfc_els_free_iocb(phba, cmdiocb);
1312 return;
1313}
1314
1315int
1316lpfc_issue_els_scr(struct lpfc_hba * phba, uint32_t nportid, uint8_t retry)
1317{
1318 IOCB_t *icmd;
1319 struct lpfc_iocbq *elsiocb;
1320 struct lpfc_sli_ring *pring;
1321 struct lpfc_sli *psli;
1322 uint8_t *pcmd;
1323 uint16_t cmdsize;
1324 struct lpfc_nodelist *ndlp;
1325
1326 psli = &phba->sli;
1327 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1328 cmdsize = (sizeof (uint32_t) + sizeof (SCR));
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001329 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1330 if (!ndlp)
1331 return 1;
dea31012005-04-17 16:05:31 -05001332
1333 lpfc_nlp_init(phba, ndlp, nportid);
1334
James Smart488d1462006-03-07 15:02:37 -05001335 elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry, ndlp,
1336 ndlp->nlp_DID, ELS_CMD_SCR);
1337 if (!elsiocb) {
dea31012005-04-17 16:05:31 -05001338 mempool_free( ndlp, phba->nlp_mem_pool);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001339 return 1;
dea31012005-04-17 16:05:31 -05001340 }
1341
1342 icmd = &elsiocb->iocb;
1343 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1344
1345 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
1346 pcmd += sizeof (uint32_t);
1347
1348 /* For SCR, remainder of payload is SCR parameter page */
1349 memset(pcmd, 0, sizeof (SCR));
1350 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
1351
1352 phba->fc_stat.elsXmitSCR++;
1353 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
1354 spin_lock_irq(phba->host->host_lock);
1355 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
1356 spin_unlock_irq(phba->host->host_lock);
1357 mempool_free( ndlp, phba->nlp_mem_pool);
1358 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001359 return 1;
dea31012005-04-17 16:05:31 -05001360 }
1361 spin_unlock_irq(phba->host->host_lock);
1362 mempool_free( ndlp, phba->nlp_mem_pool);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001363 return 0;
dea31012005-04-17 16:05:31 -05001364}
1365
1366static int
1367lpfc_issue_els_farpr(struct lpfc_hba * phba, uint32_t nportid, uint8_t retry)
1368{
1369 IOCB_t *icmd;
1370 struct lpfc_iocbq *elsiocb;
1371 struct lpfc_sli_ring *pring;
1372 struct lpfc_sli *psli;
1373 FARP *fp;
1374 uint8_t *pcmd;
1375 uint32_t *lp;
1376 uint16_t cmdsize;
1377 struct lpfc_nodelist *ondlp;
1378 struct lpfc_nodelist *ndlp;
1379
1380 psli = &phba->sli;
1381 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1382 cmdsize = (sizeof (uint32_t) + sizeof (FARP));
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001383 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1384 if (!ndlp)
1385 return 1;
dea31012005-04-17 16:05:31 -05001386 lpfc_nlp_init(phba, ndlp, nportid);
1387
James Smart488d1462006-03-07 15:02:37 -05001388 elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry, ndlp,
1389 ndlp->nlp_DID, ELS_CMD_RNID);
1390 if (!elsiocb) {
dea31012005-04-17 16:05:31 -05001391 mempool_free( ndlp, phba->nlp_mem_pool);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001392 return 1;
dea31012005-04-17 16:05:31 -05001393 }
1394
1395 icmd = &elsiocb->iocb;
1396 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1397
1398 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
1399 pcmd += sizeof (uint32_t);
1400
1401 /* Fill in FARPR payload */
1402 fp = (FARP *) (pcmd);
1403 memset(fp, 0, sizeof (FARP));
1404 lp = (uint32_t *) pcmd;
1405 *lp++ = be32_to_cpu(nportid);
1406 *lp++ = be32_to_cpu(phba->fc_myDID);
1407 fp->Rflags = 0;
1408 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
1409
1410 memcpy(&fp->RportName, &phba->fc_portname, sizeof (struct lpfc_name));
1411 memcpy(&fp->RnodeName, &phba->fc_nodename, sizeof (struct lpfc_name));
1412 if ((ondlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, nportid))) {
1413 memcpy(&fp->OportName, &ondlp->nlp_portname,
1414 sizeof (struct lpfc_name));
1415 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
1416 sizeof (struct lpfc_name));
1417 }
1418
1419 phba->fc_stat.elsXmitFARPR++;
1420 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
1421 spin_lock_irq(phba->host->host_lock);
1422 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
1423 spin_unlock_irq(phba->host->host_lock);
1424 mempool_free( ndlp, phba->nlp_mem_pool);
1425 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001426 return 1;
dea31012005-04-17 16:05:31 -05001427 }
1428 spin_unlock_irq(phba->host->host_lock);
1429 mempool_free( ndlp, phba->nlp_mem_pool);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001430 return 0;
dea31012005-04-17 16:05:31 -05001431}
1432
1433void
James Smartfdcebe22006-03-07 15:04:01 -05001434lpfc_cancel_retry_delay_tmo(struct lpfc_hba *phba, struct lpfc_nodelist * nlp)
1435{
1436 nlp->nlp_flag &= ~NLP_DELAY_TMO;
1437 del_timer_sync(&nlp->nlp_delayfunc);
1438 nlp->nlp_last_elscmd = 0;
1439
1440 if (!list_empty(&nlp->els_retry_evt.evt_listp))
1441 list_del_init(&nlp->els_retry_evt.evt_listp);
1442
1443 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
1444 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1445 if (phba->num_disc_nodes) {
1446 /* Check to see if there are more
1447 * PLOGIs to be sent
1448 */
1449 lpfc_more_plogi(phba);
1450 }
1451
1452 if (phba->num_disc_nodes == 0) {
1453 phba->fc_flag &= ~FC_NDISC_ACTIVE;
1454 lpfc_can_disctmo(phba);
1455 if (phba->fc_flag & FC_RSCN_MODE) {
1456 /* Check to see if more RSCNs
1457 * came in while we were
1458 * processing this one.
1459 */
1460 if((phba->fc_rscn_id_cnt==0) &&
1461 (!(phba->fc_flag & FC_RSCN_DISCOVERY))) {
1462 phba->fc_flag &= ~FC_RSCN_MODE;
1463 }
1464 else {
1465 lpfc_els_handle_rscn(phba);
1466 }
1467 }
1468 }
1469 }
1470 return;
1471}
1472
1473void
dea31012005-04-17 16:05:31 -05001474lpfc_els_retry_delay(unsigned long ptr)
1475{
1476 struct lpfc_nodelist *ndlp;
1477 struct lpfc_hba *phba;
1478 unsigned long iflag;
1479 struct lpfc_work_evt *evtp;
1480
1481 ndlp = (struct lpfc_nodelist *)ptr;
1482 phba = ndlp->nlp_phba;
1483 evtp = &ndlp->els_retry_evt;
1484
1485 spin_lock_irqsave(phba->host->host_lock, iflag);
1486 if (!list_empty(&evtp->evt_listp)) {
1487 spin_unlock_irqrestore(phba->host->host_lock, iflag);
1488 return;
1489 }
1490
1491 evtp->evt_arg1 = ndlp;
1492 evtp->evt = LPFC_EVT_ELS_RETRY;
1493 list_add_tail(&evtp->evt_listp, &phba->work_list);
1494 if (phba->work_wait)
1495 wake_up(phba->work_wait);
1496
1497 spin_unlock_irqrestore(phba->host->host_lock, iflag);
1498 return;
1499}
1500
1501void
1502lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
1503{
1504 struct lpfc_hba *phba;
1505 uint32_t cmd;
1506 uint32_t did;
1507 uint8_t retry;
1508
1509 phba = ndlp->nlp_phba;
1510 spin_lock_irq(phba->host->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001511 did = ndlp->nlp_DID;
1512 cmd = ndlp->nlp_last_elscmd;
1513 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05001514
1515 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
1516 spin_unlock_irq(phba->host->host_lock);
1517 return;
1518 }
1519
1520 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
1521 spin_unlock_irq(phba->host->host_lock);
James Smart1a169682006-03-07 15:04:06 -05001522 /*
1523 * If a discovery event readded nlp_delayfunc after timer
1524 * firing and before processing the timer, cancel the
1525 * nlp_delayfunc.
1526 */
1527 del_timer_sync(&ndlp->nlp_delayfunc);
dea31012005-04-17 16:05:31 -05001528 retry = ndlp->nlp_retry;
1529
1530 switch (cmd) {
1531 case ELS_CMD_FLOGI:
1532 lpfc_issue_els_flogi(phba, ndlp, retry);
1533 break;
1534 case ELS_CMD_PLOGI:
James Smart488d1462006-03-07 15:02:37 -05001535 if(!lpfc_issue_els_plogi(phba, ndlp->nlp_DID, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001536 ndlp->nlp_prev_state = ndlp->nlp_state;
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05001537 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
1538 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
1539 }
dea31012005-04-17 16:05:31 -05001540 break;
1541 case ELS_CMD_ADISC:
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05001542 if (!lpfc_issue_els_adisc(phba, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001543 ndlp->nlp_prev_state = ndlp->nlp_state;
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05001544 ndlp->nlp_state = NLP_STE_ADISC_ISSUE;
1545 lpfc_nlp_list(phba, ndlp, NLP_ADISC_LIST);
1546 }
dea31012005-04-17 16:05:31 -05001547 break;
1548 case ELS_CMD_PRLI:
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05001549 if (!lpfc_issue_els_prli(phba, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001550 ndlp->nlp_prev_state = ndlp->nlp_state;
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05001551 ndlp->nlp_state = NLP_STE_PRLI_ISSUE;
1552 lpfc_nlp_list(phba, ndlp, NLP_PRLI_LIST);
1553 }
dea31012005-04-17 16:05:31 -05001554 break;
1555 case ELS_CMD_LOGO:
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05001556 if (!lpfc_issue_els_logo(phba, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001557 ndlp->nlp_prev_state = ndlp->nlp_state;
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05001558 ndlp->nlp_state = NLP_STE_NPR_NODE;
1559 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1560 }
dea31012005-04-17 16:05:31 -05001561 break;
1562 }
1563 return;
1564}
1565
1566static int
1567lpfc_els_retry(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
1568 struct lpfc_iocbq * rspiocb)
1569{
1570 IOCB_t *irsp;
1571 struct lpfc_dmabuf *pcmd;
1572 struct lpfc_nodelist *ndlp;
1573 uint32_t *elscmd;
1574 struct ls_rjt stat;
1575 int retry, maxretry;
1576 int delay;
1577 uint32_t cmd;
James Smart488d1462006-03-07 15:02:37 -05001578 uint32_t did;
dea31012005-04-17 16:05:31 -05001579
1580 retry = 0;
1581 delay = 0;
1582 maxretry = lpfc_max_els_tries;
1583 irsp = &rspiocb->iocb;
1584 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1585 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
1586 cmd = 0;
James Smart488d1462006-03-07 15:02:37 -05001587
dea31012005-04-17 16:05:31 -05001588 /* Note: context2 may be 0 for internal driver abort
1589 * of delays ELS command.
1590 */
1591
1592 if (pcmd && pcmd->virt) {
1593 elscmd = (uint32_t *) (pcmd->virt);
1594 cmd = *elscmd++;
1595 }
1596
James Smart488d1462006-03-07 15:02:37 -05001597 if(ndlp)
1598 did = ndlp->nlp_DID;
1599 else {
1600 /* We should only hit this case for retrying PLOGI */
1601 did = irsp->un.elsreq64.remoteID;
1602 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, did);
1603 if (!ndlp && (cmd != ELS_CMD_PLOGI))
1604 return 1;
1605 }
1606
dea31012005-04-17 16:05:31 -05001607 switch (irsp->ulpStatus) {
1608 case IOSTAT_FCP_RSP_ERROR:
1609 case IOSTAT_REMOTE_STOP:
1610 break;
1611
1612 case IOSTAT_LOCAL_REJECT:
1613 switch ((irsp->un.ulpWord[4] & 0xff)) {
1614 case IOERR_LOOP_OPEN_FAILURE:
1615 if (cmd == ELS_CMD_PLOGI) {
1616 if (cmdiocb->retry == 0) {
1617 delay = 1;
1618 }
1619 }
1620 retry = 1;
1621 break;
1622
1623 case IOERR_SEQUENCE_TIMEOUT:
1624 retry = 1;
dea31012005-04-17 16:05:31 -05001625 break;
1626
1627 case IOERR_NO_RESOURCES:
1628 if (cmd == ELS_CMD_PLOGI) {
1629 delay = 1;
1630 }
1631 retry = 1;
1632 break;
1633
1634 case IOERR_INVALID_RPI:
1635 retry = 1;
1636 break;
1637 }
1638 break;
1639
1640 case IOSTAT_NPORT_RJT:
1641 case IOSTAT_FABRIC_RJT:
1642 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
1643 retry = 1;
1644 break;
1645 }
1646 break;
1647
1648 case IOSTAT_NPORT_BSY:
1649 case IOSTAT_FABRIC_BSY:
1650 retry = 1;
1651 break;
1652
1653 case IOSTAT_LS_RJT:
1654 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
1655 /* Added for Vendor specifc support
1656 * Just keep retrying for these Rsn / Exp codes
1657 */
1658 switch (stat.un.b.lsRjtRsnCode) {
1659 case LSRJT_UNABLE_TPC:
1660 if (stat.un.b.lsRjtRsnCodeExp ==
1661 LSEXP_CMD_IN_PROGRESS) {
1662 if (cmd == ELS_CMD_PLOGI) {
1663 delay = 1;
1664 maxretry = 48;
1665 }
1666 retry = 1;
1667 break;
1668 }
1669 if (cmd == ELS_CMD_PLOGI) {
1670 delay = 1;
1671 maxretry = lpfc_max_els_tries + 1;
1672 retry = 1;
1673 break;
1674 }
1675 break;
1676
1677 case LSRJT_LOGICAL_BSY:
1678 if (cmd == ELS_CMD_PLOGI) {
1679 delay = 1;
1680 maxretry = 48;
1681 }
1682 retry = 1;
1683 break;
1684 }
1685 break;
1686
1687 case IOSTAT_INTERMED_RSP:
1688 case IOSTAT_BA_RJT:
1689 break;
1690
1691 default:
1692 break;
1693 }
1694
James Smart488d1462006-03-07 15:02:37 -05001695 if (did == FDMI_DID)
dea31012005-04-17 16:05:31 -05001696 retry = 1;
dea31012005-04-17 16:05:31 -05001697
1698 if ((++cmdiocb->retry) >= maxretry) {
1699 phba->fc_stat.elsRetryExceeded++;
1700 retry = 0;
1701 }
1702
1703 if (retry) {
1704
1705 /* Retry ELS command <elsCmd> to remote NPORT <did> */
1706 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1707 "%d:0107 Retry ELS command x%x to remote "
1708 "NPORT x%x Data: x%x x%x\n",
1709 phba->brd_no,
James Smart488d1462006-03-07 15:02:37 -05001710 cmd, did, cmdiocb->retry, delay);
dea31012005-04-17 16:05:31 -05001711
1712 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) {
1713 /* If discovery / RSCN timer is running, reset it */
1714 if (timer_pending(&phba->fc_disctmo) ||
1715 (phba->fc_flag & FC_RSCN_MODE)) {
1716 lpfc_set_disctmo(phba);
1717 }
1718 }
1719
1720 phba->fc_stat.elsXmitRetry++;
James Smart488d1462006-03-07 15:02:37 -05001721 if (ndlp && delay) {
dea31012005-04-17 16:05:31 -05001722 phba->fc_stat.elsDelayRetry++;
1723 ndlp->nlp_retry = cmdiocb->retry;
1724
1725 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
1726 ndlp->nlp_flag |= NLP_DELAY_TMO;
1727
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001728 ndlp->nlp_prev_state = ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001729 ndlp->nlp_state = NLP_STE_NPR_NODE;
1730 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1731 ndlp->nlp_last_elscmd = cmd;
1732
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001733 return 1;
dea31012005-04-17 16:05:31 -05001734 }
1735 switch (cmd) {
1736 case ELS_CMD_FLOGI:
1737 lpfc_issue_els_flogi(phba, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001738 return 1;
dea31012005-04-17 16:05:31 -05001739 case ELS_CMD_PLOGI:
James Smart488d1462006-03-07 15:02:37 -05001740 if (ndlp) {
1741 ndlp->nlp_prev_state = ndlp->nlp_state;
1742 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
1743 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
1744 }
1745 lpfc_issue_els_plogi(phba, did, cmdiocb->retry);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001746 return 1;
dea31012005-04-17 16:05:31 -05001747 case ELS_CMD_ADISC:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001748 ndlp->nlp_prev_state = ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001749 ndlp->nlp_state = NLP_STE_ADISC_ISSUE;
1750 lpfc_nlp_list(phba, ndlp, NLP_ADISC_LIST);
1751 lpfc_issue_els_adisc(phba, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001752 return 1;
dea31012005-04-17 16:05:31 -05001753 case ELS_CMD_PRLI:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001754 ndlp->nlp_prev_state = ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001755 ndlp->nlp_state = NLP_STE_PRLI_ISSUE;
1756 lpfc_nlp_list(phba, ndlp, NLP_PRLI_LIST);
1757 lpfc_issue_els_prli(phba, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001758 return 1;
dea31012005-04-17 16:05:31 -05001759 case ELS_CMD_LOGO:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001760 ndlp->nlp_prev_state = ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001761 ndlp->nlp_state = NLP_STE_NPR_NODE;
1762 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1763 lpfc_issue_els_logo(phba, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001764 return 1;
dea31012005-04-17 16:05:31 -05001765 }
1766 }
1767
1768 /* No retry ELS command <elsCmd> to remote NPORT <did> */
1769 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1770 "%d:0108 No retry ELS command x%x to remote NPORT x%x "
James Smart488d1462006-03-07 15:02:37 -05001771 "Data: x%x\n",
dea31012005-04-17 16:05:31 -05001772 phba->brd_no,
James Smart488d1462006-03-07 15:02:37 -05001773 cmd, did, cmdiocb->retry);
dea31012005-04-17 16:05:31 -05001774
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001775 return 0;
dea31012005-04-17 16:05:31 -05001776}
1777
1778int
1779lpfc_els_free_iocb(struct lpfc_hba * phba, struct lpfc_iocbq * elsiocb)
1780{
1781 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
1782
1783 /* context2 = cmd, context2->next = rsp, context3 = bpl */
1784 if (elsiocb->context2) {
1785 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
1786 /* Free the response before processing the command. */
1787 if (!list_empty(&buf_ptr1->list)) {
1788 list_remove_head(&buf_ptr1->list, buf_ptr,
1789 struct lpfc_dmabuf,
1790 list);
1791 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
1792 kfree(buf_ptr);
1793 }
1794 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
1795 kfree(buf_ptr1);
1796 }
1797
1798 if (elsiocb->context3) {
1799 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
1800 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
1801 kfree(buf_ptr);
1802 }
1803 spin_lock_irq(phba->host->host_lock);
James Bottomley604a3e32005-10-29 10:28:33 -05001804 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -05001805 spin_unlock_irq(phba->host->host_lock);
1806 return 0;
1807}
1808
1809static void
1810lpfc_cmpl_els_logo_acc(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
1811 struct lpfc_iocbq * rspiocb)
1812{
1813 struct lpfc_nodelist *ndlp;
1814
1815 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1816
1817 /* ACC to LOGO completes to NPort <nlp_DID> */
1818 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1819 "%d:0109 ACC to LOGO completes to NPort x%x "
1820 "Data: x%x x%x x%x\n",
1821 phba->brd_no, ndlp->nlp_DID, ndlp->nlp_flag,
1822 ndlp->nlp_state, ndlp->nlp_rpi);
1823
dea31012005-04-17 16:05:31 -05001824 switch (ndlp->nlp_state) {
1825 case NLP_STE_UNUSED_NODE: /* node is just allocated */
1826 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
1827 break;
1828 case NLP_STE_NPR_NODE: /* NPort Recovery mode */
1829 lpfc_unreg_rpi(phba, ndlp);
1830 break;
1831 default:
1832 break;
1833 }
1834 lpfc_els_free_iocb(phba, cmdiocb);
1835 return;
1836}
1837
1838static void
1839lpfc_cmpl_els_acc(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
1840 struct lpfc_iocbq * rspiocb)
1841{
1842 struct lpfc_nodelist *ndlp;
1843 LPFC_MBOXQ_t *mbox = NULL;
1844
1845 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1846 if (cmdiocb->context_un.mbox)
1847 mbox = cmdiocb->context_un.mbox;
1848
1849
1850 /* Check to see if link went down during discovery */
1851 if ((lpfc_els_chk_latt(phba)) || !ndlp) {
1852 if (mbox) {
1853 mempool_free( mbox, phba->mbox_mem_pool);
1854 }
1855 goto out;
1856 }
1857
1858 /* ELS response tag <ulpIoTag> completes */
1859 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1860 "%d:0110 ELS response tag x%x completes "
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001861 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -05001862 phba->brd_no,
1863 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001864 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
1865 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
1866 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05001867
1868 if (mbox) {
1869 if ((rspiocb->iocb.ulpStatus == 0)
1870 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
dea31012005-04-17 16:05:31 -05001871 lpfc_unreg_rpi(phba, ndlp);
1872 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
1873 mbox->context2 = ndlp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001874 ndlp->nlp_prev_state = ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001875 ndlp->nlp_state = NLP_STE_REG_LOGIN_ISSUE;
1876 lpfc_nlp_list(phba, ndlp, NLP_REGLOGIN_LIST);
1877 if (lpfc_sli_issue_mbox(phba, mbox,
1878 (MBX_NOWAIT | MBX_STOP_IOCB))
1879 != MBX_NOT_FINISHED) {
1880 goto out;
1881 }
1882 /* NOTE: we should have messages for unsuccessful
1883 reglogin */
1884 mempool_free( mbox, phba->mbox_mem_pool);
1885 } else {
1886 mempool_free( mbox, phba->mbox_mem_pool);
1887 if (ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
1888 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001889 ndlp = NULL;
dea31012005-04-17 16:05:31 -05001890 }
1891 }
1892 }
1893out:
1894 if (ndlp) {
1895 spin_lock_irq(phba->host->host_lock);
1896 ndlp->nlp_flag &= ~NLP_ACC_REGLOGIN;
1897 spin_unlock_irq(phba->host->host_lock);
1898 }
1899 lpfc_els_free_iocb(phba, cmdiocb);
1900 return;
1901}
1902
1903int
1904lpfc_els_rsp_acc(struct lpfc_hba * phba, uint32_t flag,
1905 struct lpfc_iocbq * oldiocb, struct lpfc_nodelist * ndlp,
1906 LPFC_MBOXQ_t * mbox, uint8_t newnode)
1907{
1908 IOCB_t *icmd;
1909 IOCB_t *oldcmd;
1910 struct lpfc_iocbq *elsiocb;
1911 struct lpfc_sli_ring *pring;
1912 struct lpfc_sli *psli;
1913 uint8_t *pcmd;
1914 uint16_t cmdsize;
1915 int rc;
1916
1917 psli = &phba->sli;
1918 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1919 oldcmd = &oldiocb->iocb;
1920
1921 switch (flag) {
1922 case ELS_CMD_ACC:
1923 cmdsize = sizeof (uint32_t);
James Smart488d1462006-03-07 15:02:37 -05001924 elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry,
1925 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
1926 if (!elsiocb) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001927 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001928 return 1;
dea31012005-04-17 16:05:31 -05001929 }
1930 icmd = &elsiocb->iocb;
1931 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
1932 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1933 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
1934 pcmd += sizeof (uint32_t);
1935 break;
1936 case ELS_CMD_PLOGI:
1937 cmdsize = (sizeof (struct serv_parm) + sizeof (uint32_t));
James Smart488d1462006-03-07 15:02:37 -05001938 elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry,
1939 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
1940 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001941 return 1;
James Smart488d1462006-03-07 15:02:37 -05001942
dea31012005-04-17 16:05:31 -05001943 icmd = &elsiocb->iocb;
1944 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
1945 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1946
1947 if (mbox)
1948 elsiocb->context_un.mbox = mbox;
1949
1950 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
1951 pcmd += sizeof (uint32_t);
1952 memcpy(pcmd, &phba->fc_sparam, sizeof (struct serv_parm));
1953 break;
1954 default:
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001955 return 1;
dea31012005-04-17 16:05:31 -05001956 }
1957
1958 if (newnode)
1959 elsiocb->context1 = NULL;
1960
1961 /* Xmit ELS ACC response tag <ulpIoTag> */
1962 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1963 "%d:0128 Xmit ELS ACC response tag x%x "
1964 "Data: x%x x%x x%x x%x x%x\n",
1965 phba->brd_no,
1966 elsiocb->iocb.ulpIoTag,
1967 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
1968 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
1969
1970 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001971 spin_lock_irq(phba->host->host_lock);
1972 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
1973 spin_unlock_irq(phba->host->host_lock);
dea31012005-04-17 16:05:31 -05001974 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
1975 } else {
1976 elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
1977 }
1978
1979 phba->fc_stat.elsXmitACC++;
1980 spin_lock_irq(phba->host->host_lock);
1981 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
1982 spin_unlock_irq(phba->host->host_lock);
1983 if (rc == IOCB_ERROR) {
1984 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001985 return 1;
dea31012005-04-17 16:05:31 -05001986 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001987 return 0;
dea31012005-04-17 16:05:31 -05001988}
1989
1990int
1991lpfc_els_rsp_reject(struct lpfc_hba * phba, uint32_t rejectError,
1992 struct lpfc_iocbq * oldiocb, struct lpfc_nodelist * ndlp)
1993{
1994 IOCB_t *icmd;
1995 IOCB_t *oldcmd;
1996 struct lpfc_iocbq *elsiocb;
1997 struct lpfc_sli_ring *pring;
1998 struct lpfc_sli *psli;
1999 uint8_t *pcmd;
2000 uint16_t cmdsize;
2001 int rc;
2002
2003 psli = &phba->sli;
2004 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2005
2006 cmdsize = 2 * sizeof (uint32_t);
James Smart488d1462006-03-07 15:02:37 -05002007 elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry,
2008 ndlp, ndlp->nlp_DID, ELS_CMD_LS_RJT);
2009 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002010 return 1;
dea31012005-04-17 16:05:31 -05002011
2012 icmd = &elsiocb->iocb;
2013 oldcmd = &oldiocb->iocb;
2014 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2015 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2016
2017 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
2018 pcmd += sizeof (uint32_t);
2019 *((uint32_t *) (pcmd)) = rejectError;
2020
2021 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
2022 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
2023 "%d:0129 Xmit ELS RJT x%x response tag x%x "
2024 "Data: x%x x%x x%x x%x x%x\n",
2025 phba->brd_no,
2026 rejectError, elsiocb->iocb.ulpIoTag,
2027 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
2028 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
2029
2030 phba->fc_stat.elsXmitLSRJT++;
2031 elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
2032 spin_lock_irq(phba->host->host_lock);
2033 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
2034 spin_unlock_irq(phba->host->host_lock);
2035 if (rc == IOCB_ERROR) {
2036 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002037 return 1;
dea31012005-04-17 16:05:31 -05002038 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002039 return 0;
dea31012005-04-17 16:05:31 -05002040}
2041
2042int
2043lpfc_els_rsp_adisc_acc(struct lpfc_hba * phba,
2044 struct lpfc_iocbq * oldiocb, struct lpfc_nodelist * ndlp)
2045{
2046 ADISC *ap;
2047 IOCB_t *icmd;
2048 IOCB_t *oldcmd;
2049 struct lpfc_iocbq *elsiocb;
2050 struct lpfc_sli_ring *pring;
2051 struct lpfc_sli *psli;
2052 uint8_t *pcmd;
2053 uint16_t cmdsize;
2054 int rc;
2055
2056 psli = &phba->sli;
2057 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2058
2059 cmdsize = sizeof (uint32_t) + sizeof (ADISC);
James Smart488d1462006-03-07 15:02:37 -05002060 elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry,
2061 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
2062 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002063 return 1;
dea31012005-04-17 16:05:31 -05002064
2065 /* Xmit ADISC ACC response tag <ulpIoTag> */
2066 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
2067 "%d:0130 Xmit ADISC ACC response tag x%x "
2068 "Data: x%x x%x x%x x%x x%x\n",
2069 phba->brd_no,
2070 elsiocb->iocb.ulpIoTag,
2071 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
2072 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
2073
2074 icmd = &elsiocb->iocb;
2075 oldcmd = &oldiocb->iocb;
2076 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2077 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2078
2079 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
2080 pcmd += sizeof (uint32_t);
2081
2082 ap = (ADISC *) (pcmd);
2083 ap->hardAL_PA = phba->fc_pref_ALPA;
2084 memcpy(&ap->portName, &phba->fc_portname, sizeof (struct lpfc_name));
2085 memcpy(&ap->nodeName, &phba->fc_nodename, sizeof (struct lpfc_name));
2086 ap->DID = be32_to_cpu(phba->fc_myDID);
2087
2088 phba->fc_stat.elsXmitACC++;
2089 elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
2090 spin_lock_irq(phba->host->host_lock);
2091 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
2092 spin_unlock_irq(phba->host->host_lock);
2093 if (rc == IOCB_ERROR) {
2094 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002095 return 1;
dea31012005-04-17 16:05:31 -05002096 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002097 return 0;
dea31012005-04-17 16:05:31 -05002098}
2099
2100int
2101lpfc_els_rsp_prli_acc(struct lpfc_hba * phba,
2102 struct lpfc_iocbq * oldiocb, struct lpfc_nodelist * ndlp)
2103{
2104 PRLI *npr;
2105 lpfc_vpd_t *vpd;
2106 IOCB_t *icmd;
2107 IOCB_t *oldcmd;
2108 struct lpfc_iocbq *elsiocb;
2109 struct lpfc_sli_ring *pring;
2110 struct lpfc_sli *psli;
2111 uint8_t *pcmd;
2112 uint16_t cmdsize;
2113 int rc;
2114
2115 psli = &phba->sli;
2116 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2117
2118 cmdsize = sizeof (uint32_t) + sizeof (PRLI);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002119 elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry, ndlp,
James Smart488d1462006-03-07 15:02:37 -05002120 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002121 if (!elsiocb)
2122 return 1;
dea31012005-04-17 16:05:31 -05002123
2124 /* Xmit PRLI ACC response tag <ulpIoTag> */
2125 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
2126 "%d:0131 Xmit PRLI ACC response tag x%x "
2127 "Data: x%x x%x x%x x%x x%x\n",
2128 phba->brd_no,
2129 elsiocb->iocb.ulpIoTag,
2130 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
2131 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
2132
2133 icmd = &elsiocb->iocb;
2134 oldcmd = &oldiocb->iocb;
2135 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2136 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2137
2138 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
2139 pcmd += sizeof (uint32_t);
2140
2141 /* For PRLI, remainder of payload is PRLI parameter page */
2142 memset(pcmd, 0, sizeof (PRLI));
2143
2144 npr = (PRLI *) pcmd;
2145 vpd = &phba->vpd;
2146 /*
2147 * If our firmware version is 3.20 or later,
2148 * set the following bits for FC-TAPE support.
2149 */
2150 if (vpd->rev.feaLevelHigh >= 0x02) {
2151 npr->ConfmComplAllowed = 1;
2152 npr->Retry = 1;
2153 npr->TaskRetryIdReq = 1;
2154 }
2155
2156 npr->acceptRspCode = PRLI_REQ_EXECUTED;
2157 npr->estabImagePair = 1;
2158 npr->readXferRdyDis = 1;
2159 npr->ConfmComplAllowed = 1;
2160
2161 npr->prliType = PRLI_FCP_TYPE;
2162 npr->initiatorFunc = 1;
2163
2164 phba->fc_stat.elsXmitACC++;
2165 elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
2166
2167 spin_lock_irq(phba->host->host_lock);
2168 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
2169 spin_unlock_irq(phba->host->host_lock);
2170 if (rc == IOCB_ERROR) {
2171 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002172 return 1;
dea31012005-04-17 16:05:31 -05002173 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002174 return 0;
dea31012005-04-17 16:05:31 -05002175}
2176
2177static int
2178lpfc_els_rsp_rnid_acc(struct lpfc_hba * phba,
2179 uint8_t format,
2180 struct lpfc_iocbq * oldiocb, struct lpfc_nodelist * ndlp)
2181{
2182 RNID *rn;
2183 IOCB_t *icmd;
2184 IOCB_t *oldcmd;
2185 struct lpfc_iocbq *elsiocb;
2186 struct lpfc_sli_ring *pring;
2187 struct lpfc_sli *psli;
2188 uint8_t *pcmd;
2189 uint16_t cmdsize;
2190 int rc;
2191
2192 psli = &phba->sli;
2193 pring = &psli->ring[LPFC_ELS_RING];
2194
2195 cmdsize = sizeof (uint32_t) + sizeof (uint32_t)
2196 + (2 * sizeof (struct lpfc_name));
2197 if (format)
2198 cmdsize += sizeof (RNID_TOP_DISC);
2199
James Smart488d1462006-03-07 15:02:37 -05002200 elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry,
2201 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
2202 if (!elsiocb)
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002203 return 1;
dea31012005-04-17 16:05:31 -05002204
2205 /* Xmit RNID ACC response tag <ulpIoTag> */
2206 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
2207 "%d:0132 Xmit RNID ACC response tag x%x "
2208 "Data: x%x\n",
2209 phba->brd_no,
2210 elsiocb->iocb.ulpIoTag,
2211 elsiocb->iocb.ulpContext);
2212
2213 icmd = &elsiocb->iocb;
2214 oldcmd = &oldiocb->iocb;
2215 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2216 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2217
2218 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
2219 pcmd += sizeof (uint32_t);
2220
2221 memset(pcmd, 0, sizeof (RNID));
2222 rn = (RNID *) (pcmd);
2223 rn->Format = format;
2224 rn->CommonLen = (2 * sizeof (struct lpfc_name));
2225 memcpy(&rn->portName, &phba->fc_portname, sizeof (struct lpfc_name));
2226 memcpy(&rn->nodeName, &phba->fc_nodename, sizeof (struct lpfc_name));
2227 switch (format) {
2228 case 0:
2229 rn->SpecificLen = 0;
2230 break;
2231 case RNID_TOPOLOGY_DISC:
2232 rn->SpecificLen = sizeof (RNID_TOP_DISC);
2233 memcpy(&rn->un.topologyDisc.portName,
2234 &phba->fc_portname, sizeof (struct lpfc_name));
2235 rn->un.topologyDisc.unitType = RNID_HBA;
2236 rn->un.topologyDisc.physPort = 0;
2237 rn->un.topologyDisc.attachedNodes = 0;
2238 break;
2239 default:
2240 rn->CommonLen = 0;
2241 rn->SpecificLen = 0;
2242 break;
2243 }
2244
2245 phba->fc_stat.elsXmitACC++;
2246 elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
2247 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
2248 * it could be freed */
2249
2250 spin_lock_irq(phba->host->host_lock);
2251 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
2252 spin_unlock_irq(phba->host->host_lock);
2253 if (rc == IOCB_ERROR) {
2254 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002255 return 1;
dea31012005-04-17 16:05:31 -05002256 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002257 return 0;
dea31012005-04-17 16:05:31 -05002258}
2259
2260int
2261lpfc_els_disc_adisc(struct lpfc_hba * phba)
2262{
2263 int sentadisc;
2264 struct lpfc_nodelist *ndlp, *next_ndlp;
2265
2266 sentadisc = 0;
2267 /* go thru NPR list and issue any remaining ELS ADISCs */
2268 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
2269 nlp_listp) {
2270 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
2271 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
2272 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002273 ndlp->nlp_prev_state = ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05002274 ndlp->nlp_state = NLP_STE_ADISC_ISSUE;
2275 lpfc_nlp_list(phba, ndlp,
2276 NLP_ADISC_LIST);
2277 lpfc_issue_els_adisc(phba, ndlp, 0);
2278 sentadisc++;
2279 phba->num_disc_nodes++;
2280 if (phba->num_disc_nodes >=
2281 phba->cfg_discovery_threads) {
2282 spin_lock_irq(phba->host->host_lock);
2283 phba->fc_flag |= FC_NLP_MORE;
2284 spin_unlock_irq(phba->host->host_lock);
2285 break;
2286 }
2287 }
2288 }
2289 }
2290 if (sentadisc == 0) {
2291 spin_lock_irq(phba->host->host_lock);
2292 phba->fc_flag &= ~FC_NLP_MORE;
2293 spin_unlock_irq(phba->host->host_lock);
2294 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002295 return sentadisc;
dea31012005-04-17 16:05:31 -05002296}
2297
2298int
2299lpfc_els_disc_plogi(struct lpfc_hba * phba)
2300{
2301 int sentplogi;
2302 struct lpfc_nodelist *ndlp, *next_ndlp;
2303
2304 sentplogi = 0;
2305 /* go thru NPR list and issue any remaining ELS PLOGIs */
2306 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
2307 nlp_listp) {
2308 if ((ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
2309 (!(ndlp->nlp_flag & NLP_DELAY_TMO))) {
2310 if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002311 ndlp->nlp_prev_state = ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05002312 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
2313 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
James Smart488d1462006-03-07 15:02:37 -05002314 lpfc_issue_els_plogi(phba, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05002315 sentplogi++;
2316 phba->num_disc_nodes++;
2317 if (phba->num_disc_nodes >=
2318 phba->cfg_discovery_threads) {
2319 spin_lock_irq(phba->host->host_lock);
2320 phba->fc_flag |= FC_NLP_MORE;
2321 spin_unlock_irq(phba->host->host_lock);
2322 break;
2323 }
2324 }
2325 }
2326 }
2327 if (sentplogi == 0) {
2328 spin_lock_irq(phba->host->host_lock);
2329 phba->fc_flag &= ~FC_NLP_MORE;
2330 spin_unlock_irq(phba->host->host_lock);
2331 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002332 return sentplogi;
dea31012005-04-17 16:05:31 -05002333}
2334
2335int
2336lpfc_els_flush_rscn(struct lpfc_hba * phba)
2337{
2338 struct lpfc_dmabuf *mp;
2339 int i;
2340
2341 for (i = 0; i < phba->fc_rscn_id_cnt; i++) {
2342 mp = phba->fc_rscn_id_list[i];
2343 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2344 kfree(mp);
2345 phba->fc_rscn_id_list[i] = NULL;
2346 }
2347 phba->fc_rscn_id_cnt = 0;
2348 spin_lock_irq(phba->host->host_lock);
2349 phba->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
2350 spin_unlock_irq(phba->host->host_lock);
2351 lpfc_can_disctmo(phba);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002352 return 0;
dea31012005-04-17 16:05:31 -05002353}
2354
2355int
2356lpfc_rscn_payload_check(struct lpfc_hba * phba, uint32_t did)
2357{
2358 D_ID ns_did;
2359 D_ID rscn_did;
2360 struct lpfc_dmabuf *mp;
2361 uint32_t *lp;
2362 uint32_t payload_len, cmd, i, match;
2363
2364 ns_did.un.word = did;
2365 match = 0;
2366
2367 /* Never match fabric nodes for RSCNs */
2368 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
2369 return(0);
2370
2371 /* If we are doing a FULL RSCN rediscovery, match everything */
2372 if (phba->fc_flag & FC_RSCN_DISCOVERY) {
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002373 return did;
dea31012005-04-17 16:05:31 -05002374 }
2375
2376 for (i = 0; i < phba->fc_rscn_id_cnt; i++) {
2377 mp = phba->fc_rscn_id_list[i];
2378 lp = (uint32_t *) mp->virt;
2379 cmd = *lp++;
2380 payload_len = be32_to_cpu(cmd) & 0xffff; /* payload length */
2381 payload_len -= sizeof (uint32_t); /* take off word 0 */
2382 while (payload_len) {
2383 rscn_did.un.word = *lp++;
2384 rscn_did.un.word = be32_to_cpu(rscn_did.un.word);
2385 payload_len -= sizeof (uint32_t);
2386 switch (rscn_did.un.b.resv) {
2387 case 0: /* Single N_Port ID effected */
2388 if (ns_did.un.word == rscn_did.un.word) {
2389 match = did;
2390 }
2391 break;
2392 case 1: /* Whole N_Port Area effected */
2393 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
2394 && (ns_did.un.b.area == rscn_did.un.b.area))
2395 {
2396 match = did;
2397 }
2398 break;
2399 case 2: /* Whole N_Port Domain effected */
2400 if (ns_did.un.b.domain == rscn_did.un.b.domain)
2401 {
2402 match = did;
2403 }
2404 break;
2405 case 3: /* Whole Fabric effected */
2406 match = did;
2407 break;
2408 default:
2409 /* Unknown Identifier in RSCN list */
2410 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2411 "%d:0217 Unknown Identifier in "
2412 "RSCN payload Data: x%x\n",
2413 phba->brd_no, rscn_did.un.word);
2414 break;
2415 }
2416 if (match) {
2417 break;
2418 }
2419 }
2420 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002421 return match;
dea31012005-04-17 16:05:31 -05002422}
2423
2424static int
2425lpfc_rscn_recovery_check(struct lpfc_hba * phba)
2426{
2427 struct lpfc_nodelist *ndlp = NULL, *next_ndlp;
2428 struct list_head *listp;
2429 struct list_head *node_list[7];
2430 int i;
2431
2432 /* Look at all nodes effected by pending RSCNs and move
2433 * them to NPR list.
2434 */
2435 node_list[0] = &phba->fc_npr_list; /* MUST do this list first */
2436 node_list[1] = &phba->fc_nlpmap_list;
2437 node_list[2] = &phba->fc_nlpunmap_list;
2438 node_list[3] = &phba->fc_prli_list;
2439 node_list[4] = &phba->fc_reglogin_list;
2440 node_list[5] = &phba->fc_adisc_list;
2441 node_list[6] = &phba->fc_plogi_list;
2442 for (i = 0; i < 7; i++) {
2443 listp = node_list[i];
2444 if (list_empty(listp))
2445 continue;
2446
2447 list_for_each_entry_safe(ndlp, next_ndlp, listp, nlp_listp) {
2448 if (!(lpfc_rscn_payload_check(phba, ndlp->nlp_DID)))
2449 continue;
2450
2451 lpfc_disc_state_machine(phba, ndlp, NULL,
2452 NLP_EVT_DEVICE_RECOVERY);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002453
2454 /* Make sure NLP_DELAY_TMO is NOT running
2455 * after a device recovery event.
2456 */
James Smartfdcebe22006-03-07 15:04:01 -05002457 if (ndlp->nlp_flag & NLP_DELAY_TMO)
2458 lpfc_cancel_retry_delay_tmo(phba, ndlp);
dea31012005-04-17 16:05:31 -05002459 }
2460 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002461 return 0;
dea31012005-04-17 16:05:31 -05002462}
2463
2464static int
2465lpfc_els_rcv_rscn(struct lpfc_hba * phba,
2466 struct lpfc_iocbq * cmdiocb,
2467 struct lpfc_nodelist * ndlp, uint8_t newnode)
2468{
2469 struct lpfc_dmabuf *pcmd;
2470 uint32_t *lp;
2471 IOCB_t *icmd;
2472 uint32_t payload_len, cmd;
2473
2474 icmd = &cmdiocb->iocb;
2475 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2476 lp = (uint32_t *) pcmd->virt;
2477
2478 cmd = *lp++;
2479 payload_len = be32_to_cpu(cmd) & 0xffff; /* payload length */
2480 payload_len -= sizeof (uint32_t); /* take off word 0 */
2481 cmd &= ELS_CMD_MASK;
2482
2483 /* RSCN received */
2484 lpfc_printf_log(phba,
2485 KERN_INFO,
2486 LOG_DISCOVERY,
2487 "%d:0214 RSCN received Data: x%x x%x x%x x%x\n",
2488 phba->brd_no,
2489 phba->fc_flag, payload_len, *lp, phba->fc_rscn_id_cnt);
2490
2491 /* If we are about to begin discovery, just ACC the RSCN.
2492 * Discovery processing will satisfy it.
2493 */
2494 if (phba->hba_state < LPFC_NS_QRY) {
2495 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL,
2496 newnode);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002497 return 0;
dea31012005-04-17 16:05:31 -05002498 }
2499
2500 /* If we are already processing an RSCN, save the received
2501 * RSCN payload buffer, cmdiocb->context2 to process later.
2502 */
2503 if (phba->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
2504 if ((phba->fc_rscn_id_cnt < FC_MAX_HOLD_RSCN) &&
2505 !(phba->fc_flag & FC_RSCN_DISCOVERY)) {
2506 spin_lock_irq(phba->host->host_lock);
2507 phba->fc_flag |= FC_RSCN_MODE;
2508 spin_unlock_irq(phba->host->host_lock);
2509 phba->fc_rscn_id_list[phba->fc_rscn_id_cnt++] = pcmd;
2510
2511 /* If we zero, cmdiocb->context2, the calling
2512 * routine will not try to free it.
2513 */
2514 cmdiocb->context2 = NULL;
2515
2516 /* Deferred RSCN */
2517 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
2518 "%d:0235 Deferred RSCN "
2519 "Data: x%x x%x x%x\n",
2520 phba->brd_no, phba->fc_rscn_id_cnt,
2521 phba->fc_flag, phba->hba_state);
2522 } else {
2523 spin_lock_irq(phba->host->host_lock);
2524 phba->fc_flag |= FC_RSCN_DISCOVERY;
2525 spin_unlock_irq(phba->host->host_lock);
2526 /* ReDiscovery RSCN */
2527 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
2528 "%d:0234 ReDiscovery RSCN "
2529 "Data: x%x x%x x%x\n",
2530 phba->brd_no, phba->fc_rscn_id_cnt,
2531 phba->fc_flag, phba->hba_state);
2532 }
2533 /* Send back ACC */
2534 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL,
2535 newnode);
2536
2537 /* send RECOVERY event for ALL nodes that match RSCN payload */
2538 lpfc_rscn_recovery_check(phba);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002539 return 0;
dea31012005-04-17 16:05:31 -05002540 }
2541
2542 phba->fc_flag |= FC_RSCN_MODE;
2543 phba->fc_rscn_id_list[phba->fc_rscn_id_cnt++] = pcmd;
2544 /*
2545 * If we zero, cmdiocb->context2, the calling routine will
2546 * not try to free it.
2547 */
2548 cmdiocb->context2 = NULL;
2549
2550 lpfc_set_disctmo(phba);
2551
2552 /* Send back ACC */
2553 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, newnode);
2554
2555 /* send RECOVERY event for ALL nodes that match RSCN payload */
2556 lpfc_rscn_recovery_check(phba);
2557
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002558 return lpfc_els_handle_rscn(phba);
dea31012005-04-17 16:05:31 -05002559}
2560
2561int
2562lpfc_els_handle_rscn(struct lpfc_hba * phba)
2563{
2564 struct lpfc_nodelist *ndlp;
2565
2566 /* Start timer for RSCN processing */
2567 lpfc_set_disctmo(phba);
2568
2569 /* RSCN processed */
2570 lpfc_printf_log(phba,
2571 KERN_INFO,
2572 LOG_DISCOVERY,
2573 "%d:0215 RSCN processed Data: x%x x%x x%x x%x\n",
2574 phba->brd_no,
2575 phba->fc_flag, 0, phba->fc_rscn_id_cnt,
2576 phba->hba_state);
2577
2578 /* To process RSCN, first compare RSCN data with NameServer */
2579 phba->fc_ns_retry = 0;
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002580 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_UNMAPPED, NameServer_DID);
2581 if (ndlp) {
dea31012005-04-17 16:05:31 -05002582 /* Good ndlp, issue CT Request to NameServer */
2583 if (lpfc_ns_cmd(phba, ndlp, SLI_CTNS_GID_FT) == 0) {
2584 /* Wait for NameServer query cmpl before we can
2585 continue */
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002586 return 1;
dea31012005-04-17 16:05:31 -05002587 }
2588 } else {
2589 /* If login to NameServer does not exist, issue one */
2590 /* Good status, issue PLOGI to NameServer */
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002591 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, NameServer_DID);
2592 if (ndlp) {
dea31012005-04-17 16:05:31 -05002593 /* Wait for NameServer login cmpl before we can
2594 continue */
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002595 return 1;
dea31012005-04-17 16:05:31 -05002596 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002597 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2598 if (!ndlp) {
dea31012005-04-17 16:05:31 -05002599 lpfc_els_flush_rscn(phba);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002600 return 0;
dea31012005-04-17 16:05:31 -05002601 } else {
2602 lpfc_nlp_init(phba, ndlp, NameServer_DID);
2603 ndlp->nlp_type |= NLP_FABRIC;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002604 ndlp->nlp_prev_state = ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05002605 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
James Smart488d1462006-03-07 15:02:37 -05002606 lpfc_issue_els_plogi(phba, NameServer_DID, 0);
dea31012005-04-17 16:05:31 -05002607 /* Wait for NameServer login cmpl before we can
2608 continue */
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002609 return 1;
dea31012005-04-17 16:05:31 -05002610 }
2611 }
2612
2613 lpfc_els_flush_rscn(phba);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002614 return 0;
dea31012005-04-17 16:05:31 -05002615}
2616
2617static int
2618lpfc_els_rcv_flogi(struct lpfc_hba * phba,
2619 struct lpfc_iocbq * cmdiocb,
2620 struct lpfc_nodelist * ndlp, uint8_t newnode)
2621{
2622 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2623 uint32_t *lp = (uint32_t *) pcmd->virt;
2624 IOCB_t *icmd = &cmdiocb->iocb;
2625 struct serv_parm *sp;
2626 LPFC_MBOXQ_t *mbox;
2627 struct ls_rjt stat;
2628 uint32_t cmd, did;
2629 int rc;
2630
2631 cmd = *lp++;
2632 sp = (struct serv_parm *) lp;
2633
2634 /* FLOGI received */
2635
2636 lpfc_set_disctmo(phba);
2637
2638 if (phba->fc_topology == TOPOLOGY_LOOP) {
2639 /* We should never receive a FLOGI in loop mode, ignore it */
2640 did = icmd->un.elsreq64.remoteID;
2641
2642 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
2643 Loop Mode */
2644 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
2645 "%d:0113 An FLOGI ELS command x%x was received "
2646 "from DID x%x in Loop Mode\n",
2647 phba->brd_no, cmd, did);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002648 return 1;
dea31012005-04-17 16:05:31 -05002649 }
2650
2651 did = Fabric_DID;
2652
2653 if ((lpfc_check_sparm(phba, ndlp, sp, CLASS3))) {
2654 /* For a FLOGI we accept, then if our portname is greater
2655 * then the remote portname we initiate Nport login.
2656 */
2657
2658 rc = memcmp(&phba->fc_portname, &sp->portName,
2659 sizeof (struct lpfc_name));
2660
2661 if (!rc) {
2662 if ((mbox = mempool_alloc(phba->mbox_mem_pool,
2663 GFP_KERNEL)) == 0) {
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002664 return 1;
dea31012005-04-17 16:05:31 -05002665 }
2666 lpfc_linkdown(phba);
2667 lpfc_init_link(phba, mbox,
2668 phba->cfg_topology,
2669 phba->cfg_link_speed);
2670 mbox->mb.un.varInitLnk.lipsr_AL_PA = 0;
2671 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
2672 rc = lpfc_sli_issue_mbox
2673 (phba, mbox, (MBX_NOWAIT | MBX_STOP_IOCB));
2674 if (rc == MBX_NOT_FINISHED) {
2675 mempool_free( mbox, phba->mbox_mem_pool);
2676 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002677 return 1;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002678 } else if (rc > 0) { /* greater than */
dea31012005-04-17 16:05:31 -05002679 spin_lock_irq(phba->host->host_lock);
2680 phba->fc_flag |= FC_PT2PT_PLOGI;
2681 spin_unlock_irq(phba->host->host_lock);
2682 }
2683 phba->fc_flag |= FC_PT2PT;
2684 phba->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
2685 } else {
2686 /* Reject this request because invalid parameters */
2687 stat.un.b.lsRjtRsvd0 = 0;
2688 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2689 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
2690 stat.un.b.vendorUnique = 0;
2691 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002692 return 1;
dea31012005-04-17 16:05:31 -05002693 }
2694
2695 /* Send back ACC */
2696 lpfc_els_rsp_acc(phba, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL, newnode);
2697
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002698 return 0;
dea31012005-04-17 16:05:31 -05002699}
2700
2701static int
2702lpfc_els_rcv_rnid(struct lpfc_hba * phba,
2703 struct lpfc_iocbq * cmdiocb, struct lpfc_nodelist * ndlp)
2704{
2705 struct lpfc_dmabuf *pcmd;
2706 uint32_t *lp;
2707 IOCB_t *icmd;
2708 RNID *rn;
2709 struct ls_rjt stat;
2710 uint32_t cmd, did;
2711
2712 icmd = &cmdiocb->iocb;
2713 did = icmd->un.elsreq64.remoteID;
2714 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2715 lp = (uint32_t *) pcmd->virt;
2716
2717 cmd = *lp++;
2718 rn = (RNID *) lp;
2719
2720 /* RNID received */
2721
2722 switch (rn->Format) {
2723 case 0:
2724 case RNID_TOPOLOGY_DISC:
2725 /* Send back ACC */
2726 lpfc_els_rsp_rnid_acc(phba, rn->Format, cmdiocb, ndlp);
2727 break;
2728 default:
2729 /* Reject this request because format not supported */
2730 stat.un.b.lsRjtRsvd0 = 0;
2731 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2732 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
2733 stat.un.b.vendorUnique = 0;
2734 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
2735 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002736 return 0;
dea31012005-04-17 16:05:31 -05002737}
2738
2739static int
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002740lpfc_els_rcv_lirr(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
2741 struct lpfc_nodelist * ndlp)
2742{
2743 struct ls_rjt stat;
2744
2745 /* For now, unconditionally reject this command */
2746 stat.un.b.lsRjtRsvd0 = 0;
2747 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2748 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
2749 stat.un.b.vendorUnique = 0;
2750 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
2751 return 0;
2752}
2753
Jamie Wellnitz082c0262006-02-28 19:25:30 -05002754static void
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002755lpfc_els_rsp_rps_acc(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
2756{
2757 struct lpfc_sli *psli;
2758 struct lpfc_sli_ring *pring;
2759 MAILBOX_t *mb;
2760 IOCB_t *icmd;
2761 RPS_RSP *rps_rsp;
2762 uint8_t *pcmd;
2763 struct lpfc_iocbq *elsiocb;
2764 struct lpfc_nodelist *ndlp;
2765 uint16_t xri, status;
2766 uint32_t cmdsize;
2767
2768 psli = &phba->sli;
2769 pring = &psli->ring[LPFC_ELS_RING];
2770 mb = &pmb->mb;
2771
2772 ndlp = (struct lpfc_nodelist *) pmb->context2;
2773 xri = (uint16_t) ((unsigned long)(pmb->context1));
2774 pmb->context1 = 0;
2775 pmb->context2 = 0;
2776
2777 if (mb->mbxStatus) {
2778 mempool_free( pmb, phba->mbox_mem_pool);
2779 return;
2780 }
2781
2782 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
2783 mempool_free( pmb, phba->mbox_mem_pool);
James Smart488d1462006-03-07 15:02:37 -05002784 elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, lpfc_max_els_tries, ndlp,
2785 ndlp->nlp_DID, ELS_CMD_ACC);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002786 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002787 return;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002788
2789 icmd = &elsiocb->iocb;
2790 icmd->ulpContext = xri;
2791
2792 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2793 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
2794 pcmd += sizeof (uint32_t); /* Skip past command */
2795 rps_rsp = (RPS_RSP *)pcmd;
2796
2797 if (phba->fc_topology != TOPOLOGY_LOOP)
2798 status = 0x10;
2799 else
2800 status = 0x8;
2801 if (phba->fc_flag & FC_FABRIC)
2802 status |= 0x4;
2803
2804 rps_rsp->rsvd1 = 0;
2805 rps_rsp->portStatus = be16_to_cpu(status);
2806 rps_rsp->linkFailureCnt = be32_to_cpu(mb->un.varRdLnk.linkFailureCnt);
2807 rps_rsp->lossSyncCnt = be32_to_cpu(mb->un.varRdLnk.lossSyncCnt);
2808 rps_rsp->lossSignalCnt = be32_to_cpu(mb->un.varRdLnk.lossSignalCnt);
2809 rps_rsp->primSeqErrCnt = be32_to_cpu(mb->un.varRdLnk.primSeqErrCnt);
2810 rps_rsp->invalidXmitWord = be32_to_cpu(mb->un.varRdLnk.invalidXmitWord);
2811 rps_rsp->crcCnt = be32_to_cpu(mb->un.varRdLnk.crcCnt);
2812
2813 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
2814 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
2815 "%d:0128 Xmit ELS RPS ACC response tag x%x "
2816 "Data: x%x x%x x%x x%x x%x\n",
2817 phba->brd_no,
2818 elsiocb->iocb.ulpIoTag,
2819 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
2820 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
2821
2822 elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
2823 phba->fc_stat.elsXmitACC++;
2824 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
2825 lpfc_els_free_iocb(phba, elsiocb);
2826 }
2827 return;
2828}
2829
2830static int
2831lpfc_els_rcv_rps(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
2832 struct lpfc_nodelist * ndlp)
2833{
2834 uint32_t *lp;
2835 uint8_t flag;
2836 LPFC_MBOXQ_t *mbox;
2837 struct lpfc_dmabuf *pcmd;
2838 RPS *rps;
2839 struct ls_rjt stat;
2840
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002841 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
2842 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002843 stat.un.b.lsRjtRsvd0 = 0;
2844 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2845 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
2846 stat.un.b.vendorUnique = 0;
2847 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
2848 }
2849
2850 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2851 lp = (uint32_t *) pcmd->virt;
2852 flag = (be32_to_cpu(*lp++) & 0xf);
2853 rps = (RPS *) lp;
2854
2855 if ((flag == 0) ||
2856 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
2857 ((flag == 2) && (memcmp(&rps->un.portName, &phba->fc_portname,
2858 sizeof (struct lpfc_name)) == 0))) {
2859 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC))) {
2860 lpfc_read_lnk_stat(phba, mbox);
2861 mbox->context1 =
2862 (void *)((unsigned long)cmdiocb->iocb.ulpContext);
2863 mbox->context2 = ndlp;
2864 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
2865 if (lpfc_sli_issue_mbox (phba, mbox,
2866 (MBX_NOWAIT | MBX_STOP_IOCB)) != MBX_NOT_FINISHED) {
2867 /* Mbox completion will send ELS Response */
2868 return 0;
2869 }
2870 mempool_free(mbox, phba->mbox_mem_pool);
2871 }
2872 }
2873 stat.un.b.lsRjtRsvd0 = 0;
2874 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2875 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
2876 stat.un.b.vendorUnique = 0;
2877 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
2878 return 0;
2879}
2880
Jamie Wellnitz082c0262006-02-28 19:25:30 -05002881static int
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002882lpfc_els_rsp_rpl_acc(struct lpfc_hba * phba, uint16_t cmdsize,
2883 struct lpfc_iocbq * oldiocb, struct lpfc_nodelist * ndlp)
2884{
2885 IOCB_t *icmd;
2886 IOCB_t *oldcmd;
2887 RPL_RSP rpl_rsp;
2888 struct lpfc_iocbq *elsiocb;
2889 struct lpfc_sli_ring *pring;
2890 struct lpfc_sli *psli;
2891 uint8_t *pcmd;
2892
2893 psli = &phba->sli;
2894 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2895
James Smart488d1462006-03-07 15:02:37 -05002896 elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry,
2897 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
2898 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002899 return 1;
James Smart488d1462006-03-07 15:02:37 -05002900
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002901 icmd = &elsiocb->iocb;
2902 oldcmd = &oldiocb->iocb;
2903 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2904
2905 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2906 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
2907 pcmd += sizeof (uint16_t);
2908 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
2909 pcmd += sizeof(uint16_t);
2910
2911 /* Setup the RPL ACC payload */
2912 rpl_rsp.listLen = be32_to_cpu(1);
2913 rpl_rsp.index = 0;
2914 rpl_rsp.port_num_blk.portNum = 0;
2915 rpl_rsp.port_num_blk.portID = be32_to_cpu(phba->fc_myDID);
2916 memcpy(&rpl_rsp.port_num_blk.portName, &phba->fc_portname,
2917 sizeof(struct lpfc_name));
2918
2919 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
2920
2921
2922 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
2923 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
2924 "%d:0128 Xmit ELS RPL ACC response tag x%x "
2925 "Data: x%x x%x x%x x%x x%x\n",
2926 phba->brd_no,
2927 elsiocb->iocb.ulpIoTag,
2928 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
2929 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
2930
2931 elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
2932
2933 phba->fc_stat.elsXmitACC++;
2934 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
2935 lpfc_els_free_iocb(phba, elsiocb);
2936 return 1;
2937 }
2938 return 0;
2939}
2940
2941static int
2942lpfc_els_rcv_rpl(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
dea31012005-04-17 16:05:31 -05002943 struct lpfc_nodelist * ndlp)
2944{
2945 struct lpfc_dmabuf *pcmd;
2946 uint32_t *lp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002947 uint32_t maxsize;
2948 uint16_t cmdsize;
2949 RPL *rpl;
2950 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05002951
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002952 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
2953 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002954 stat.un.b.lsRjtRsvd0 = 0;
2955 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2956 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
2957 stat.un.b.vendorUnique = 0;
2958 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05002959 }
2960
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002961 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2962 lp = (uint32_t *) pcmd->virt;
2963 rpl = (RPL *) (lp + 1);
2964
2965 maxsize = be32_to_cpu(rpl->maxsize);
2966
2967 /* We support only one port */
2968 if ((rpl->index == 0) &&
2969 ((maxsize == 0) ||
2970 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
2971 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002972 } else {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002973 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
2974 }
2975 lpfc_els_rsp_rpl_acc(phba, cmdsize, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05002976
2977 return 0;
2978}
2979
2980static int
2981lpfc_els_rcv_farp(struct lpfc_hba * phba,
2982 struct lpfc_iocbq * cmdiocb, struct lpfc_nodelist * ndlp)
2983{
2984 struct lpfc_dmabuf *pcmd;
2985 uint32_t *lp;
2986 IOCB_t *icmd;
2987 FARP *fp;
2988 uint32_t cmd, cnt, did;
2989
2990 icmd = &cmdiocb->iocb;
2991 did = icmd->un.elsreq64.remoteID;
2992 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2993 lp = (uint32_t *) pcmd->virt;
2994
2995 cmd = *lp++;
2996 fp = (FARP *) lp;
2997
2998 /* FARP-REQ received from DID <did> */
2999 lpfc_printf_log(phba,
3000 KERN_INFO,
3001 LOG_IP,
3002 "%d:0601 FARP-REQ received from DID x%x\n",
3003 phba->brd_no, did);
3004
3005 /* We will only support match on WWPN or WWNN */
3006 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003007 return 0;
dea31012005-04-17 16:05:31 -05003008 }
3009
3010 cnt = 0;
3011 /* If this FARP command is searching for my portname */
3012 if (fp->Mflags & FARP_MATCH_PORT) {
3013 if (memcmp(&fp->RportName, &phba->fc_portname,
3014 sizeof (struct lpfc_name)) == 0)
3015 cnt = 1;
3016 }
3017
3018 /* If this FARP command is searching for my nodename */
3019 if (fp->Mflags & FARP_MATCH_NODE) {
3020 if (memcmp(&fp->RnodeName, &phba->fc_nodename,
3021 sizeof (struct lpfc_name)) == 0)
3022 cnt = 1;
3023 }
3024
3025 if (cnt) {
3026 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
3027 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
3028 /* Log back into the node before sending the FARP. */
3029 if (fp->Rflags & FARP_REQUEST_PLOGI) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003030 ndlp->nlp_prev_state = ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05003031 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
3032 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
James Smart488d1462006-03-07 15:02:37 -05003033 lpfc_issue_els_plogi(phba, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05003034 }
3035
3036 /* Send a FARP response to that node */
3037 if (fp->Rflags & FARP_REQUEST_FARPR) {
3038 lpfc_issue_els_farpr(phba, did, 0);
3039 }
3040 }
3041 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003042 return 0;
dea31012005-04-17 16:05:31 -05003043}
3044
3045static int
3046lpfc_els_rcv_farpr(struct lpfc_hba * phba,
3047 struct lpfc_iocbq * cmdiocb, struct lpfc_nodelist * ndlp)
3048{
3049 struct lpfc_dmabuf *pcmd;
3050 uint32_t *lp;
3051 IOCB_t *icmd;
3052 uint32_t cmd, did;
3053
3054 icmd = &cmdiocb->iocb;
3055 did = icmd->un.elsreq64.remoteID;
3056 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3057 lp = (uint32_t *) pcmd->virt;
3058
3059 cmd = *lp++;
3060 /* FARP-RSP received from DID <did> */
3061 lpfc_printf_log(phba,
3062 KERN_INFO,
3063 LOG_IP,
3064 "%d:0600 FARP-RSP received from DID x%x\n",
3065 phba->brd_no, did);
3066
3067 /* ACCEPT the Farp resp request */
3068 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
3069
3070 return 0;
3071}
3072
3073static int
3074lpfc_els_rcv_fan(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003075 struct lpfc_nodelist * fan_ndlp)
dea31012005-04-17 16:05:31 -05003076{
3077 struct lpfc_dmabuf *pcmd;
3078 uint32_t *lp;
3079 IOCB_t *icmd;
dea31012005-04-17 16:05:31 -05003080 uint32_t cmd, did;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003081 FAN *fp;
3082 struct lpfc_nodelist *ndlp, *next_ndlp;
3083
3084 /* FAN received */
3085 lpfc_printf_log(phba, KERN_INFO, LOG_ELS, "%d:265 FAN received\n",
3086 phba->brd_no);
dea31012005-04-17 16:05:31 -05003087
3088 icmd = &cmdiocb->iocb;
3089 did = icmd->un.elsreq64.remoteID;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003090 pcmd = (struct lpfc_dmabuf *)cmdiocb->context2;
3091 lp = (uint32_t *)pcmd->virt;
dea31012005-04-17 16:05:31 -05003092
3093 cmd = *lp++;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003094 fp = (FAN *)lp;
dea31012005-04-17 16:05:31 -05003095
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003096 /* FAN received; Fan does not have a reply sequence */
dea31012005-04-17 16:05:31 -05003097
3098 if (phba->hba_state == LPFC_LOCAL_CFG_LINK) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003099 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
3100 sizeof(struct lpfc_name)) != 0) ||
3101 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
3102 sizeof(struct lpfc_name)) != 0)) {
3103 /*
3104 * This node has switched fabrics. FLOGI is required
3105 * Clean up the old rpi's
dea31012005-04-17 16:05:31 -05003106 */
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003107
3108 list_for_each_entry_safe(ndlp, next_ndlp,
3109 &phba->fc_npr_list, nlp_listp) {
3110
3111 if (ndlp->nlp_type & NLP_FABRIC) {
3112 /*
3113 * Clean up old Fabric, Nameserver and
3114 * other NLP_FABRIC logins
3115 */
3116 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003117 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003118 /* Fail outstanding I/O now since this
3119 * device is marked for PLOGI
3120 */
3121 lpfc_unreg_rpi(phba, ndlp);
3122 }
3123 }
3124
3125 phba->hba_state = LPFC_FLOGI;
3126 lpfc_set_disctmo(phba);
3127 lpfc_initial_flogi(phba);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003128 return 0;
dea31012005-04-17 16:05:31 -05003129 }
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003130 /* Discovery not needed,
3131 * move the nodes to their original state.
3132 */
3133 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
3134 nlp_listp) {
dea31012005-04-17 16:05:31 -05003135
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003136 switch (ndlp->nlp_prev_state) {
3137 case NLP_STE_UNMAPPED_NODE:
3138 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
3139 ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
3140 lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
3141 break;
3142
3143 case NLP_STE_MAPPED_NODE:
3144 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
3145 ndlp->nlp_state = NLP_STE_MAPPED_NODE;
3146 lpfc_nlp_list(phba, ndlp, NLP_MAPPED_LIST);
3147 break;
3148
3149 default:
3150 break;
3151 }
3152 }
3153
3154 /* Start discovery - this should just do CLEAR_LA */
dea31012005-04-17 16:05:31 -05003155 lpfc_disc_start(phba);
3156 }
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003157 return 0;
dea31012005-04-17 16:05:31 -05003158}
3159
3160void
3161lpfc_els_timeout(unsigned long ptr)
3162{
3163 struct lpfc_hba *phba;
3164 unsigned long iflag;
3165
3166 phba = (struct lpfc_hba *)ptr;
3167 if (phba == 0)
3168 return;
3169 spin_lock_irqsave(phba->host->host_lock, iflag);
3170 if (!(phba->work_hba_events & WORKER_ELS_TMO)) {
3171 phba->work_hba_events |= WORKER_ELS_TMO;
3172 if (phba->work_wait)
3173 wake_up(phba->work_wait);
3174 }
3175 spin_unlock_irqrestore(phba->host->host_lock, iflag);
3176 return;
3177}
3178
3179void
3180lpfc_els_timeout_handler(struct lpfc_hba *phba)
3181{
3182 struct lpfc_sli_ring *pring;
3183 struct lpfc_iocbq *tmp_iocb, *piocb;
3184 IOCB_t *cmd = NULL;
3185 struct lpfc_dmabuf *pcmd;
3186 struct list_head *dlp;
3187 uint32_t *elscmd;
3188 uint32_t els_command;
3189 uint32_t timeout;
3190 uint32_t remote_ID;
3191
3192 if (phba == 0)
3193 return;
3194 spin_lock_irq(phba->host->host_lock);
3195 /* If the timer is already canceled do nothing */
3196 if (!(phba->work_hba_events & WORKER_ELS_TMO)) {
3197 spin_unlock_irq(phba->host->host_lock);
3198 return;
3199 }
3200 timeout = (uint32_t)(phba->fc_ratov << 1);
3201
3202 pring = &phba->sli.ring[LPFC_ELS_RING];
3203 dlp = &pring->txcmplq;
3204
3205 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
3206 cmd = &piocb->iocb;
3207
3208 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
3209 continue;
3210 }
3211 pcmd = (struct lpfc_dmabuf *) piocb->context2;
3212 elscmd = (uint32_t *) (pcmd->virt);
3213 els_command = *elscmd;
3214
3215 if ((els_command == ELS_CMD_FARP)
3216 || (els_command == ELS_CMD_FARPR)) {
3217 continue;
3218 }
3219
3220 if (piocb->drvrTimeout > 0) {
3221 if (piocb->drvrTimeout >= timeout) {
3222 piocb->drvrTimeout -= timeout;
3223 } else {
3224 piocb->drvrTimeout = 0;
3225 }
3226 continue;
3227 }
3228
3229 list_del(&piocb->list);
3230 pring->txcmplq_cnt--;
3231
3232 if (cmd->ulpCommand == CMD_GEN_REQUEST64_CR) {
3233 struct lpfc_nodelist *ndlp;
Jamie Wellnitz66a9ed62006-02-28 22:33:10 -05003234 spin_unlock_irq(phba->host->host_lock);
dea31012005-04-17 16:05:31 -05003235 ndlp = lpfc_findnode_rpi(phba, cmd->ulpContext);
Jamie Wellnitz66a9ed62006-02-28 22:33:10 -05003236 spin_lock_irq(phba->host->host_lock);
dea31012005-04-17 16:05:31 -05003237 remote_ID = ndlp->nlp_DID;
3238 if (cmd->un.elsreq64.bdl.ulpIoTag32) {
3239 lpfc_sli_issue_abort_iotag32(phba,
3240 pring, piocb);
3241 }
3242 } else {
3243 remote_ID = cmd->un.elsreq64.remoteID;
3244 }
3245
3246 lpfc_printf_log(phba,
3247 KERN_ERR,
3248 LOG_ELS,
3249 "%d:0127 ELS timeout Data: x%x x%x x%x x%x\n",
3250 phba->brd_no, els_command,
3251 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
3252
3253 /*
3254 * The iocb has timed out; abort it.
3255 */
3256 if (piocb->iocb_cmpl) {
3257 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
3258 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
3259 spin_unlock_irq(phba->host->host_lock);
3260 (piocb->iocb_cmpl) (phba, piocb, piocb);
3261 spin_lock_irq(phba->host->host_lock);
James Bottomley604a3e32005-10-29 10:28:33 -05003262 } else
3263 lpfc_sli_release_iocbq(phba, piocb);
dea31012005-04-17 16:05:31 -05003264 }
3265 if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt) {
3266 phba->els_tmofunc.expires = jiffies + HZ * timeout;
3267 add_timer(&phba->els_tmofunc);
3268 }
3269 spin_unlock_irq(phba->host->host_lock);
3270}
3271
3272void
3273lpfc_els_flush_cmd(struct lpfc_hba * phba)
3274{
3275 struct lpfc_sli_ring *pring;
3276 struct lpfc_iocbq *tmp_iocb, *piocb;
3277 IOCB_t *cmd = NULL;
3278 struct lpfc_dmabuf *pcmd;
3279 uint32_t *elscmd;
3280 uint32_t els_command;
dea31012005-04-17 16:05:31 -05003281
3282 pring = &phba->sli.ring[LPFC_ELS_RING];
3283 spin_lock_irq(phba->host->host_lock);
3284 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
3285 cmd = &piocb->iocb;
3286
3287 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
3288 continue;
3289 }
3290
3291 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
3292 if ((cmd->ulpCommand == CMD_QUE_RING_BUF_CN) ||
3293 (cmd->ulpCommand == CMD_QUE_RING_BUF64_CN) ||
3294 (cmd->ulpCommand == CMD_CLOSE_XRI_CN) ||
3295 (cmd->ulpCommand == CMD_ABORT_XRI_CN)) {
3296 continue;
3297 }
3298
3299 pcmd = (struct lpfc_dmabuf *) piocb->context2;
3300 elscmd = (uint32_t *) (pcmd->virt);
3301 els_command = *elscmd;
3302
dea31012005-04-17 16:05:31 -05003303 list_del(&piocb->list);
3304 pring->txcmplq_cnt--;
3305
3306 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
3307 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
3308
3309 if (piocb->iocb_cmpl) {
3310 spin_unlock_irq(phba->host->host_lock);
3311 (piocb->iocb_cmpl) (phba, piocb, piocb);
3312 spin_lock_irq(phba->host->host_lock);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003313 } else
James Bottomley604a3e32005-10-29 10:28:33 -05003314 lpfc_sli_release_iocbq(phba, piocb);
dea31012005-04-17 16:05:31 -05003315 }
3316
3317 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
3318 cmd = &piocb->iocb;
3319
3320 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
3321 continue;
3322 }
3323 pcmd = (struct lpfc_dmabuf *) piocb->context2;
3324 elscmd = (uint32_t *) (pcmd->virt);
3325 els_command = *elscmd;
3326
dea31012005-04-17 16:05:31 -05003327 list_del(&piocb->list);
3328 pring->txcmplq_cnt--;
3329
3330 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
3331 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
3332
3333 if (piocb->iocb_cmpl) {
3334 spin_unlock_irq(phba->host->host_lock);
3335 (piocb->iocb_cmpl) (phba, piocb, piocb);
3336 spin_lock_irq(phba->host->host_lock);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003337 } else
James Bottomley604a3e32005-10-29 10:28:33 -05003338 lpfc_sli_release_iocbq(phba, piocb);
dea31012005-04-17 16:05:31 -05003339 }
3340 spin_unlock_irq(phba->host->host_lock);
3341 return;
3342}
3343
3344void
3345lpfc_els_unsol_event(struct lpfc_hba * phba,
3346 struct lpfc_sli_ring * pring, struct lpfc_iocbq * elsiocb)
3347{
3348 struct lpfc_sli *psli;
3349 struct lpfc_nodelist *ndlp;
3350 struct lpfc_dmabuf *mp;
3351 uint32_t *lp;
3352 IOCB_t *icmd;
3353 struct ls_rjt stat;
3354 uint32_t cmd;
3355 uint32_t did;
3356 uint32_t newnode;
3357 uint32_t drop_cmd = 0; /* by default do NOT drop received cmd */
3358 uint32_t rjt_err = 0;
3359
3360 psli = &phba->sli;
3361 icmd = &elsiocb->iocb;
3362
3363 if ((icmd->ulpStatus == IOSTAT_LOCAL_REJECT) &&
3364 ((icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING)) {
3365 /* Not enough posted buffers; Try posting more buffers */
3366 phba->fc_stat.NoRcvBuf++;
3367 lpfc_post_buffer(phba, pring, 0, 1);
3368 return;
3369 }
3370
3371 /* If there are no BDEs associated with this IOCB,
3372 * there is nothing to do.
3373 */
3374 if (icmd->ulpBdeCount == 0)
3375 return;
3376
3377 /* type of ELS cmd is first 32bit word in packet */
3378 mp = lpfc_sli_ringpostbuf_get(phba, pring, getPaddr(icmd->un.
3379 cont64[0].
3380 addrHigh,
3381 icmd->un.
3382 cont64[0].addrLow));
3383 if (mp == 0) {
3384 drop_cmd = 1;
3385 goto dropit;
3386 }
3387
3388 newnode = 0;
3389 lp = (uint32_t *) mp->virt;
3390 cmd = *lp++;
3391 lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], 1, 1);
3392
3393 if (icmd->ulpStatus) {
3394 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3395 kfree(mp);
3396 drop_cmd = 1;
3397 goto dropit;
3398 }
3399
3400 /* Check to see if link went down during discovery */
3401 if (lpfc_els_chk_latt(phba)) {
3402 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3403 kfree(mp);
3404 drop_cmd = 1;
3405 goto dropit;
3406 }
3407
3408 did = icmd->un.rcvels.remoteID;
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003409 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, did);
3410 if (!ndlp) {
dea31012005-04-17 16:05:31 -05003411 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003412 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
3413 if (!ndlp) {
dea31012005-04-17 16:05:31 -05003414 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3415 kfree(mp);
3416 drop_cmd = 1;
3417 goto dropit;
3418 }
3419
3420 lpfc_nlp_init(phba, ndlp, did);
3421 newnode = 1;
3422 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) {
3423 ndlp->nlp_type |= NLP_FABRIC;
3424 }
3425 }
3426
3427 phba->fc_stat.elsRcvFrame++;
3428 elsiocb->context1 = ndlp;
3429 elsiocb->context2 = mp;
3430
3431 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
3432 cmd &= ELS_CMD_MASK;
3433 }
3434 /* ELS command <elsCmd> received from NPORT <did> */
3435 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
3436 "%d:0112 ELS command x%x received from NPORT x%x "
3437 "Data: x%x\n", phba->brd_no, cmd, did, phba->hba_state);
3438
3439 switch (cmd) {
3440 case ELS_CMD_PLOGI:
3441 phba->fc_stat.elsRcvPLOGI++;
3442 if (phba->hba_state < LPFC_DISC_AUTH) {
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04003443 rjt_err = 1;
dea31012005-04-17 16:05:31 -05003444 break;
3445 }
3446 lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_PLOGI);
3447 break;
3448 case ELS_CMD_FLOGI:
3449 phba->fc_stat.elsRcvFLOGI++;
3450 lpfc_els_rcv_flogi(phba, elsiocb, ndlp, newnode);
3451 if (newnode) {
3452 mempool_free( ndlp, phba->nlp_mem_pool);
3453 }
3454 break;
3455 case ELS_CMD_LOGO:
3456 phba->fc_stat.elsRcvLOGO++;
3457 if (phba->hba_state < LPFC_DISC_AUTH) {
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04003458 rjt_err = 1;
dea31012005-04-17 16:05:31 -05003459 break;
3460 }
3461 lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
3462 break;
3463 case ELS_CMD_PRLO:
3464 phba->fc_stat.elsRcvPRLO++;
3465 if (phba->hba_state < LPFC_DISC_AUTH) {
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04003466 rjt_err = 1;
dea31012005-04-17 16:05:31 -05003467 break;
3468 }
3469 lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
3470 break;
3471 case ELS_CMD_RSCN:
3472 phba->fc_stat.elsRcvRSCN++;
3473 lpfc_els_rcv_rscn(phba, elsiocb, ndlp, newnode);
3474 if (newnode) {
3475 mempool_free( ndlp, phba->nlp_mem_pool);
3476 }
3477 break;
3478 case ELS_CMD_ADISC:
3479 phba->fc_stat.elsRcvADISC++;
3480 if (phba->hba_state < LPFC_DISC_AUTH) {
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04003481 rjt_err = 1;
dea31012005-04-17 16:05:31 -05003482 break;
3483 }
3484 lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_ADISC);
3485 break;
3486 case ELS_CMD_PDISC:
3487 phba->fc_stat.elsRcvPDISC++;
3488 if (phba->hba_state < LPFC_DISC_AUTH) {
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04003489 rjt_err = 1;
dea31012005-04-17 16:05:31 -05003490 break;
3491 }
3492 lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_PDISC);
3493 break;
3494 case ELS_CMD_FARPR:
3495 phba->fc_stat.elsRcvFARPR++;
3496 lpfc_els_rcv_farpr(phba, elsiocb, ndlp);
3497 break;
3498 case ELS_CMD_FARP:
3499 phba->fc_stat.elsRcvFARP++;
3500 lpfc_els_rcv_farp(phba, elsiocb, ndlp);
3501 break;
3502 case ELS_CMD_FAN:
3503 phba->fc_stat.elsRcvFAN++;
3504 lpfc_els_rcv_fan(phba, elsiocb, ndlp);
3505 break;
dea31012005-04-17 16:05:31 -05003506 case ELS_CMD_PRLI:
3507 phba->fc_stat.elsRcvPRLI++;
3508 if (phba->hba_state < LPFC_DISC_AUTH) {
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04003509 rjt_err = 1;
dea31012005-04-17 16:05:31 -05003510 break;
3511 }
3512 lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
3513 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003514 case ELS_CMD_LIRR:
3515 phba->fc_stat.elsRcvLIRR++;
3516 lpfc_els_rcv_lirr(phba, elsiocb, ndlp);
3517 if (newnode) {
3518 mempool_free( ndlp, phba->nlp_mem_pool);
3519 }
3520 break;
3521 case ELS_CMD_RPS:
3522 phba->fc_stat.elsRcvRPS++;
3523 lpfc_els_rcv_rps(phba, elsiocb, ndlp);
3524 if (newnode) {
3525 mempool_free( ndlp, phba->nlp_mem_pool);
3526 }
3527 break;
3528 case ELS_CMD_RPL:
3529 phba->fc_stat.elsRcvRPL++;
3530 lpfc_els_rcv_rpl(phba, elsiocb, ndlp);
3531 if (newnode) {
3532 mempool_free( ndlp, phba->nlp_mem_pool);
3533 }
3534 break;
dea31012005-04-17 16:05:31 -05003535 case ELS_CMD_RNID:
3536 phba->fc_stat.elsRcvRNID++;
3537 lpfc_els_rcv_rnid(phba, elsiocb, ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003538 if (newnode) {
3539 mempool_free( ndlp, phba->nlp_mem_pool);
3540 }
dea31012005-04-17 16:05:31 -05003541 break;
3542 default:
3543 /* Unsupported ELS command, reject */
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04003544 rjt_err = 1;
dea31012005-04-17 16:05:31 -05003545
3546 /* Unknown ELS command <elsCmd> received from NPORT <did> */
3547 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
3548 "%d:0115 Unknown ELS command x%x received from "
3549 "NPORT x%x\n", phba->brd_no, cmd, did);
3550 if (newnode) {
3551 mempool_free( ndlp, phba->nlp_mem_pool);
3552 }
3553 break;
3554 }
3555
3556 /* check if need to LS_RJT received ELS cmd */
3557 if (rjt_err) {
3558 stat.un.b.lsRjtRsvd0 = 0;
3559 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04003560 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -05003561 stat.un.b.vendorUnique = 0;
3562 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, elsiocb, ndlp);
3563 }
3564
3565 if (elsiocb->context2) {
3566 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3567 kfree(mp);
3568 }
3569dropit:
3570 /* check if need to drop received ELS cmd */
3571 if (drop_cmd == 1) {
3572 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
3573 "%d:0111 Dropping received ELS cmd "
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05003574 "Data: x%x x%x x%x\n", phba->brd_no,
3575 icmd->ulpStatus, icmd->un.ulpWord[4],
3576 icmd->ulpTimeout);
dea31012005-04-17 16:05:31 -05003577 phba->fc_stat.elsRcvDrop++;
3578 }
3579 return;
3580}