blob: 71864cdc6c71a432803a1ed9183489223e362eb7 [file] [log] [blame]
dea31012005-04-17 16:05:31 -05001/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04003 * Fibre Channel Host Bus Adapters. *
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004 * Copyright (C) 2004-2006 Emulex. All rights reserved. *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04005 * EMULEX and SLI are trademarks of Emulex. *
dea31012005-04-17 16:05:31 -05006 * www.emulex.com *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04007 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea31012005-04-17 16:05:31 -05008 * *
9 * This program is free software; you can redistribute it and/or *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040010 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
dea31012005-04-17 16:05:31 -050020 *******************************************************************/
21
dea31012005-04-17 16:05:31 -050022#include <linux/blkdev.h>
23#include <linux/pci.h>
24#include <linux/interrupt.h>
25
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040026#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050027#include <scsi/scsi_device.h>
28#include <scsi/scsi_host.h>
29#include <scsi/scsi_transport_fc.h>
30
31#include "lpfc_hw.h"
32#include "lpfc_sli.h"
33#include "lpfc_disc.h"
34#include "lpfc_scsi.h"
35#include "lpfc.h"
36#include "lpfc_logmsg.h"
37#include "lpfc_crtn.h"
38
39static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *,
40 struct lpfc_iocbq *);
41static int lpfc_max_els_tries = 3;
42
43static int
44lpfc_els_chk_latt(struct lpfc_hba * phba)
45{
46 struct lpfc_sli *psli;
47 LPFC_MBOXQ_t *mbox;
48 uint32_t ha_copy;
49 int rc;
50
51 psli = &phba->sli;
52
53 if ((phba->hba_state >= LPFC_HBA_READY) ||
54 (phba->hba_state == LPFC_LINK_DOWN))
55 return 0;
56
57 /* Read the HBA Host Attention Register */
58 spin_lock_irq(phba->host->host_lock);
59 ha_copy = readl(phba->HAregaddr);
60 spin_unlock_irq(phba->host->host_lock);
61
62 if (!(ha_copy & HA_LATT))
63 return 0;
64
65 /* Pending Link Event during Discovery */
66 lpfc_printf_log(phba, KERN_WARNING, LOG_DISCOVERY,
67 "%d:0237 Pending Link Event during "
68 "Discovery: State x%x\n",
69 phba->brd_no, phba->hba_state);
70
71 /* CLEAR_LA should re-enable link attention events and
72 * we should then imediately take a LATT event. The
73 * LATT processing should call lpfc_linkdown() which
74 * will cleanup any left over in-progress discovery
75 * events.
76 */
77 spin_lock_irq(phba->host->host_lock);
78 phba->fc_flag |= FC_ABORT_DISCOVERY;
79 spin_unlock_irq(phba->host->host_lock);
80
81 if (phba->hba_state != LPFC_CLEAR_LA) {
82 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) {
83 phba->hba_state = LPFC_CLEAR_LA;
84 lpfc_clear_la(phba, mbox);
85 mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
86 rc = lpfc_sli_issue_mbox (phba, mbox,
87 (MBX_NOWAIT | MBX_STOP_IOCB));
88 if (rc == MBX_NOT_FINISHED) {
89 mempool_free(mbox, phba->mbox_mem_pool);
90 phba->hba_state = LPFC_HBA_ERROR;
91 }
92 }
93 }
94
Jamie Wellnitzc9f87352006-02-28 19:25:23 -050095 return 1;
dea31012005-04-17 16:05:31 -050096
97}
98
99static struct lpfc_iocbq *
James Smart488d1462006-03-07 15:02:37 -0500100lpfc_prep_els_iocb(struct lpfc_hba * phba, uint8_t expectRsp,
101 uint16_t cmdSize, uint8_t retry, struct lpfc_nodelist * ndlp,
102 uint32_t did, uint32_t elscmd)
dea31012005-04-17 16:05:31 -0500103{
dea31012005-04-17 16:05:31 -0500104 struct lpfc_sli_ring *pring;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400105 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -0500106 struct lpfc_dmabuf *pcmd, *prsp, *pbuflist;
107 struct ulp_bde64 *bpl;
108 IOCB_t *icmd;
109
110 pring = &phba->sli.ring[LPFC_ELS_RING];
111
112 if (phba->hba_state < LPFC_LINK_UP)
113 return NULL;
114
dea31012005-04-17 16:05:31 -0500115 /* Allocate buffer for command iocb */
116 spin_lock_irq(phba->host->host_lock);
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400117 elsiocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -0500118 spin_unlock_irq(phba->host->host_lock);
119
120 if (elsiocb == NULL)
121 return NULL;
dea31012005-04-17 16:05:31 -0500122 icmd = &elsiocb->iocb;
123
124 /* fill in BDEs for command */
125 /* Allocate buffer for command payload */
126 if (((pcmd = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL)) == 0) ||
127 ((pcmd->virt = lpfc_mbuf_alloc(phba,
128 MEM_PRI, &(pcmd->phys))) == 0)) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -0800129 kfree(pcmd);
dea31012005-04-17 16:05:31 -0500130
James Bottomley604a3e32005-10-29 10:28:33 -0500131 spin_lock_irq(phba->host->host_lock);
132 lpfc_sli_release_iocbq(phba, elsiocb);
133 spin_unlock_irq(phba->host->host_lock);
dea31012005-04-17 16:05:31 -0500134 return NULL;
135 }
136
137 INIT_LIST_HEAD(&pcmd->list);
138
139 /* Allocate buffer for response payload */
140 if (expectRsp) {
141 prsp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
142 if (prsp)
143 prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
144 &prsp->phys);
145 if (prsp == 0 || prsp->virt == 0) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -0800146 kfree(prsp);
dea31012005-04-17 16:05:31 -0500147 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
148 kfree(pcmd);
James Bottomley604a3e32005-10-29 10:28:33 -0500149 spin_lock_irq(phba->host->host_lock);
150 lpfc_sli_release_iocbq(phba, elsiocb);
151 spin_unlock_irq(phba->host->host_lock);
dea31012005-04-17 16:05:31 -0500152 return NULL;
153 }
154 INIT_LIST_HEAD(&prsp->list);
155 } else {
156 prsp = NULL;
157 }
158
159 /* Allocate buffer for Buffer ptr list */
160 pbuflist = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
161 if (pbuflist)
162 pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
163 &pbuflist->phys);
164 if (pbuflist == 0 || pbuflist->virt == 0) {
James Bottomley604a3e32005-10-29 10:28:33 -0500165 spin_lock_irq(phba->host->host_lock);
166 lpfc_sli_release_iocbq(phba, elsiocb);
167 spin_unlock_irq(phba->host->host_lock);
dea31012005-04-17 16:05:31 -0500168 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
169 lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
170 kfree(pcmd);
171 kfree(prsp);
Jesper Juhlc9475cb2005-11-07 01:01:26 -0800172 kfree(pbuflist);
dea31012005-04-17 16:05:31 -0500173 return NULL;
174 }
175
176 INIT_LIST_HEAD(&pbuflist->list);
177
178 icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
179 icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
180 icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BDL;
181 if (expectRsp) {
182 icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof (struct ulp_bde64));
James Smart488d1462006-03-07 15:02:37 -0500183 icmd->un.elsreq64.remoteID = did; /* DID */
dea31012005-04-17 16:05:31 -0500184 icmd->ulpCommand = CMD_ELS_REQUEST64_CR;
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 Wellnitzc9f87352006-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 Wellnitzc9f87352006-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 Wellnitzc9f87352006-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 Wellnitzc9f87352006-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 Wellnitzc9f87352006-02-28 19:25:23 -0500551 return 1;
dea31012005-04-17 16:05:31 -0500552 }
Jamie Wellnitzc9f87352006-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 Wellnitzc9f87352006-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 Wellnitzc9f87352006-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 Wellnitzc9f87352006-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 Wellnitzc9f87352006-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 *
James Smart92795652006-07-06 15:50:02 -0400651lpfc_plogi_confirm_nport(struct lpfc_hba * phba, struct lpfc_dmabuf *prsp,
James Smart488d1462006-03-07 15:02:37 -0500652 struct lpfc_nodelist *ndlp)
653{
654 struct lpfc_nodelist *new_ndlp;
James Smart488d1462006-03-07 15:02:37 -0500655 uint32_t *lp;
656 struct serv_parm *sp;
657 uint8_t name[sizeof (struct lpfc_name)];
658 uint32_t rc;
659
James Smart488d1462006-03-07 15:02:37 -0500660 lp = (uint32_t *) prsp->virt;
661 sp = (struct serv_parm *) ((uint8_t *) lp + sizeof (uint32_t));
James Smart92795652006-07-06 15:50:02 -0400662 memset(name, 0, sizeof (struct lpfc_name));
James Smart488d1462006-03-07 15:02:37 -0500663
664 /* Now we to find out if the NPort we are logging into, matches the WWPN
665 * we have for that ndlp. If not, we have some work to do.
666 */
667 new_ndlp = lpfc_findnode_wwpn(phba, NLP_SEARCH_ALL, &sp->portName);
668
James Smart92795652006-07-06 15:50:02 -0400669 if (new_ndlp == ndlp)
James Smart488d1462006-03-07 15:02:37 -0500670 return ndlp;
James Smart488d1462006-03-07 15:02:37 -0500671
672 if (!new_ndlp) {
James Smart92795652006-07-06 15:50:02 -0400673 rc =
674 memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name));
675 if (!rc)
676 return ndlp;
James Smart488d1462006-03-07 15:02:37 -0500677 new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
678 if (!new_ndlp)
679 return ndlp;
680
681 lpfc_nlp_init(phba, new_ndlp, ndlp->nlp_DID);
682 }
683
684 lpfc_unreg_rpi(phba, new_ndlp);
James Smart488d1462006-03-07 15:02:37 -0500685 new_ndlp->nlp_DID = ndlp->nlp_DID;
James Smart92795652006-07-06 15:50:02 -0400686 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
687 new_ndlp->nlp_state = ndlp->nlp_state;
688 lpfc_nlp_list(phba, new_ndlp, ndlp->nlp_flag & NLP_LIST_MASK);
James Smart488d1462006-03-07 15:02:37 -0500689
690 /* Move this back to NPR list */
James Smart92795652006-07-06 15:50:02 -0400691 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
692 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
693 }
694 else {
695 lpfc_unreg_rpi(phba, ndlp);
696 ndlp->nlp_DID = 0; /* Two ndlps cannot have the same did */
697 ndlp->nlp_state = NLP_STE_NPR_NODE;
698 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
699 }
James Smart488d1462006-03-07 15:02:37 -0500700 return new_ndlp;
701}
702
dea31012005-04-17 16:05:31 -0500703static void
704lpfc_cmpl_els_plogi(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
705 struct lpfc_iocbq * rspiocb)
706{
707 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -0500708 struct lpfc_nodelist *ndlp;
James Smart92795652006-07-06 15:50:02 -0400709 struct lpfc_dmabuf *prsp;
dea31012005-04-17 16:05:31 -0500710 int disc, rc, did, type;
711
dea31012005-04-17 16:05:31 -0500712
713 /* we pass cmdiocb to state machine which needs rspiocb as well */
714 cmdiocb->context_un.rsp_iocb = rspiocb;
715
716 irsp = &rspiocb->iocb;
James Smart488d1462006-03-07 15:02:37 -0500717 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL,
718 irsp->un.elsreq64.remoteID);
719 if (!ndlp)
720 goto out;
dea31012005-04-17 16:05:31 -0500721
722 /* Since ndlp can be freed in the disc state machine, note if this node
723 * is being used during discovery.
724 */
725 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500726 spin_lock_irq(phba->host->host_lock);
James Smart488d1462006-03-07 15:02:37 -0500727 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500728 spin_unlock_irq(phba->host->host_lock);
dea31012005-04-17 16:05:31 -0500729 rc = 0;
730
731 /* PLOGI completes to NPort <nlp_DID> */
732 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
733 "%d:0102 PLOGI completes to NPort x%x "
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500734 "Data: x%x x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -0500735 phba->brd_no, ndlp->nlp_DID, irsp->ulpStatus,
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500736 irsp->un.ulpWord[4], irsp->ulpTimeout, disc,
737 phba->num_disc_nodes);
dea31012005-04-17 16:05:31 -0500738
739 /* Check to see if link went down during discovery */
740 if (lpfc_els_chk_latt(phba)) {
741 spin_lock_irq(phba->host->host_lock);
742 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
743 spin_unlock_irq(phba->host->host_lock);
744 goto out;
745 }
746
747 /* ndlp could be freed in DSM, save these values now */
748 type = ndlp->nlp_type;
749 did = ndlp->nlp_DID;
750
751 if (irsp->ulpStatus) {
752 /* Check for retry */
753 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
754 /* ELS command is being retried */
755 if (disc) {
756 spin_lock_irq(phba->host->host_lock);
757 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
758 spin_unlock_irq(phba->host->host_lock);
759 }
760 goto out;
761 }
762
763 /* PLOGI failed */
764 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
765 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
766 ((irsp->un.ulpWord[4] == IOERR_SLI_ABORTED) ||
James.Smart@Emulex.Com6281bfe2005-11-28 11:41:33 -0500767 (irsp->un.ulpWord[4] == IOERR_LINK_DOWN) ||
dea31012005-04-17 16:05:31 -0500768 (irsp->un.ulpWord[4] == IOERR_SLI_DOWN))) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500769 rc = NLP_STE_FREED_NODE;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500770 } else {
dea31012005-04-17 16:05:31 -0500771 rc = lpfc_disc_state_machine(phba, ndlp, cmdiocb,
772 NLP_EVT_CMPL_PLOGI);
773 }
774 } else {
775 /* Good status, call state machine */
James Smart92795652006-07-06 15:50:02 -0400776 prsp = list_entry(((struct lpfc_dmabuf *)
777 cmdiocb->context2)->list.next,
778 struct lpfc_dmabuf, list);
779 ndlp = lpfc_plogi_confirm_nport(phba, prsp, ndlp);
dea31012005-04-17 16:05:31 -0500780 rc = lpfc_disc_state_machine(phba, ndlp, cmdiocb,
781 NLP_EVT_CMPL_PLOGI);
782 }
783
dea31012005-04-17 16:05:31 -0500784 if (disc && phba->num_disc_nodes) {
785 /* Check to see if there are more PLOGIs to be sent */
786 lpfc_more_plogi(phba);
dea31012005-04-17 16:05:31 -0500787
James Smart10d4e952006-04-15 11:53:15 -0400788 if (phba->num_disc_nodes == 0) {
789 spin_lock_irq(phba->host->host_lock);
790 phba->fc_flag &= ~FC_NDISC_ACTIVE;
791 spin_unlock_irq(phba->host->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500792
James Smart10d4e952006-04-15 11:53:15 -0400793 lpfc_can_disctmo(phba);
794 if (phba->fc_flag & FC_RSCN_MODE) {
795 /*
796 * Check to see if more RSCNs came in while
797 * we were processing this one.
798 */
799 if ((phba->fc_rscn_id_cnt == 0) &&
800 (!(phba->fc_flag & FC_RSCN_DISCOVERY))) {
801 spin_lock_irq(phba->host->host_lock);
802 phba->fc_flag &= ~FC_RSCN_MODE;
803 spin_unlock_irq(phba->host->host_lock);
804 } else {
805 lpfc_els_handle_rscn(phba);
806 }
dea31012005-04-17 16:05:31 -0500807 }
808 }
809 }
810
811out:
812 lpfc_els_free_iocb(phba, cmdiocb);
813 return;
814}
815
816int
James Smart488d1462006-03-07 15:02:37 -0500817lpfc_issue_els_plogi(struct lpfc_hba * phba, uint32_t did, uint8_t retry)
dea31012005-04-17 16:05:31 -0500818{
819 struct serv_parm *sp;
820 IOCB_t *icmd;
821 struct lpfc_iocbq *elsiocb;
822 struct lpfc_sli_ring *pring;
823 struct lpfc_sli *psli;
824 uint8_t *pcmd;
825 uint16_t cmdsize;
826
827 psli = &phba->sli;
828 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
829
830 cmdsize = (sizeof (uint32_t) + sizeof (struct serv_parm));
Randy Dunlap041976f2006-06-25 01:58:51 -0700831 elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry, NULL, did,
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500832 ELS_CMD_PLOGI);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500833 if (!elsiocb)
834 return 1;
dea31012005-04-17 16:05:31 -0500835
836 icmd = &elsiocb->iocb;
837 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
838
839 /* For PLOGI request, remainder of payload is service parameters */
840 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
841 pcmd += sizeof (uint32_t);
842 memcpy(pcmd, &phba->fc_sparam, sizeof (struct serv_parm));
843 sp = (struct serv_parm *) pcmd;
844
845 if (sp->cmn.fcphLow < FC_PH_4_3)
846 sp->cmn.fcphLow = FC_PH_4_3;
847
848 if (sp->cmn.fcphHigh < FC_PH3)
849 sp->cmn.fcphHigh = FC_PH3;
850
851 phba->fc_stat.elsXmitPLOGI++;
852 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
853 spin_lock_irq(phba->host->host_lock);
dea31012005-04-17 16:05:31 -0500854 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
dea31012005-04-17 16:05:31 -0500855 spin_unlock_irq(phba->host->host_lock);
856 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500857 return 1;
dea31012005-04-17 16:05:31 -0500858 }
859 spin_unlock_irq(phba->host->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500860 return 0;
dea31012005-04-17 16:05:31 -0500861}
862
863static void
864lpfc_cmpl_els_prli(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
865 struct lpfc_iocbq * rspiocb)
866{
867 IOCB_t *irsp;
868 struct lpfc_sli *psli;
869 struct lpfc_nodelist *ndlp;
870
871 psli = &phba->sli;
872 /* we pass cmdiocb to state machine which needs rspiocb as well */
873 cmdiocb->context_un.rsp_iocb = rspiocb;
874
875 irsp = &(rspiocb->iocb);
876 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
877 spin_lock_irq(phba->host->host_lock);
878 ndlp->nlp_flag &= ~NLP_PRLI_SND;
879 spin_unlock_irq(phba->host->host_lock);
880
881 /* PRLI completes to NPort <nlp_DID> */
882 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
883 "%d:0103 PRLI completes to NPort x%x "
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500884 "Data: x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -0500885 phba->brd_no, ndlp->nlp_DID, irsp->ulpStatus,
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500886 irsp->un.ulpWord[4], irsp->ulpTimeout,
887 phba->num_disc_nodes);
dea31012005-04-17 16:05:31 -0500888
889 phba->fc_prli_sent--;
890 /* Check to see if link went down during discovery */
891 if (lpfc_els_chk_latt(phba))
892 goto out;
893
894 if (irsp->ulpStatus) {
895 /* Check for retry */
896 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
897 /* ELS command is being retried */
898 goto out;
899 }
900 /* PRLI failed */
901 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
902 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
903 ((irsp->un.ulpWord[4] == IOERR_SLI_ABORTED) ||
James.Smart@Emulex.Com6281bfe2005-11-28 11:41:33 -0500904 (irsp->un.ulpWord[4] == IOERR_LINK_DOWN) ||
dea31012005-04-17 16:05:31 -0500905 (irsp->un.ulpWord[4] == IOERR_SLI_DOWN))) {
906 goto out;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500907 } else {
dea31012005-04-17 16:05:31 -0500908 lpfc_disc_state_machine(phba, ndlp, cmdiocb,
909 NLP_EVT_CMPL_PRLI);
910 }
911 } else {
912 /* Good status, call state machine */
913 lpfc_disc_state_machine(phba, ndlp, cmdiocb, NLP_EVT_CMPL_PRLI);
914 }
915
916out:
917 lpfc_els_free_iocb(phba, cmdiocb);
918 return;
919}
920
921int
922lpfc_issue_els_prli(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
923 uint8_t retry)
924{
925 PRLI *npr;
926 IOCB_t *icmd;
927 struct lpfc_iocbq *elsiocb;
928 struct lpfc_sli_ring *pring;
929 struct lpfc_sli *psli;
930 uint8_t *pcmd;
931 uint16_t cmdsize;
932
933 psli = &phba->sli;
934 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
935
936 cmdsize = (sizeof (uint32_t) + sizeof (PRLI));
James Smart488d1462006-03-07 15:02:37 -0500937 elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry, ndlp,
938 ndlp->nlp_DID, ELS_CMD_PRLI);
939 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500940 return 1;
dea31012005-04-17 16:05:31 -0500941
942 icmd = &elsiocb->iocb;
943 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
944
945 /* For PRLI request, remainder of payload is service parameters */
946 memset(pcmd, 0, (sizeof (PRLI) + sizeof (uint32_t)));
947 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
948 pcmd += sizeof (uint32_t);
949
950 /* For PRLI, remainder of payload is PRLI parameter page */
951 npr = (PRLI *) pcmd;
952 /*
953 * If our firmware version is 3.20 or later,
954 * set the following bits for FC-TAPE support.
955 */
956 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
957 npr->ConfmComplAllowed = 1;
958 npr->Retry = 1;
959 npr->TaskRetryIdReq = 1;
960 }
961 npr->estabImagePair = 1;
962 npr->readXferRdyDis = 1;
963
964 /* For FCP support */
965 npr->prliType = PRLI_FCP_TYPE;
966 npr->initiatorFunc = 1;
967
968 phba->fc_stat.elsXmitPRLI++;
969 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
970 spin_lock_irq(phba->host->host_lock);
971 ndlp->nlp_flag |= NLP_PRLI_SND;
972 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
973 ndlp->nlp_flag &= ~NLP_PRLI_SND;
974 spin_unlock_irq(phba->host->host_lock);
975 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500976 return 1;
dea31012005-04-17 16:05:31 -0500977 }
978 spin_unlock_irq(phba->host->host_lock);
979 phba->fc_prli_sent++;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500980 return 0;
dea31012005-04-17 16:05:31 -0500981}
982
983static void
984lpfc_more_adisc(struct lpfc_hba * phba)
985{
986 int sentadisc;
987
988 if (phba->num_disc_nodes)
989 phba->num_disc_nodes--;
990
991 /* Continue discovery with <num_disc_nodes> ADISCs to go */
992 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
993 "%d:0210 Continue discovery with %d ADISCs to go "
994 "Data: x%x x%x x%x\n",
995 phba->brd_no, phba->num_disc_nodes, phba->fc_adisc_cnt,
996 phba->fc_flag, phba->hba_state);
997
998 /* Check to see if there are more ADISCs to be sent */
999 if (phba->fc_flag & FC_NLP_MORE) {
1000 lpfc_set_disctmo(phba);
1001
1002 /* go thru NPR list and issue any remaining ELS ADISCs */
1003 sentadisc = lpfc_els_disc_adisc(phba);
1004 }
1005 return;
1006}
1007
1008static void
1009lpfc_rscn_disc(struct lpfc_hba * phba)
1010{
1011 /* RSCN discovery */
1012 /* go thru NPR list and issue ELS PLOGIs */
1013 if (phba->fc_npr_cnt) {
1014 if (lpfc_els_disc_plogi(phba))
1015 return;
1016 }
1017 if (phba->fc_flag & FC_RSCN_MODE) {
1018 /* Check to see if more RSCNs came in while we were
1019 * processing this one.
1020 */
1021 if ((phba->fc_rscn_id_cnt == 0) &&
1022 (!(phba->fc_flag & FC_RSCN_DISCOVERY))) {
1023 spin_lock_irq(phba->host->host_lock);
1024 phba->fc_flag &= ~FC_RSCN_MODE;
1025 spin_unlock_irq(phba->host->host_lock);
1026 } else {
1027 lpfc_els_handle_rscn(phba);
1028 }
1029 }
1030}
1031
1032static void
1033lpfc_cmpl_els_adisc(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
1034 struct lpfc_iocbq * rspiocb)
1035{
1036 IOCB_t *irsp;
1037 struct lpfc_sli *psli;
1038 struct lpfc_nodelist *ndlp;
1039 LPFC_MBOXQ_t *mbox;
1040 int disc, rc;
1041
1042 psli = &phba->sli;
1043
1044 /* we pass cmdiocb to state machine which needs rspiocb as well */
1045 cmdiocb->context_un.rsp_iocb = rspiocb;
1046
1047 irsp = &(rspiocb->iocb);
1048 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
dea31012005-04-17 16:05:31 -05001049
1050 /* Since ndlp can be freed in the disc state machine, note if this node
1051 * is being used during discovery.
1052 */
1053 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001054 spin_lock_irq(phba->host->host_lock);
1055 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
1056 spin_unlock_irq(phba->host->host_lock);
dea31012005-04-17 16:05:31 -05001057
1058 /* ADISC completes to NPort <nlp_DID> */
1059 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1060 "%d:0104 ADISC completes to NPort x%x "
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001061 "Data: x%x x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -05001062 phba->brd_no, ndlp->nlp_DID, irsp->ulpStatus,
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001063 irsp->un.ulpWord[4], irsp->ulpTimeout, disc,
1064 phba->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001065
1066 /* Check to see if link went down during discovery */
1067 if (lpfc_els_chk_latt(phba)) {
1068 spin_lock_irq(phba->host->host_lock);
1069 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1070 spin_unlock_irq(phba->host->host_lock);
1071 goto out;
1072 }
1073
1074 if (irsp->ulpStatus) {
1075 /* Check for retry */
1076 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1077 /* ELS command is being retried */
1078 if (disc) {
1079 spin_lock_irq(phba->host->host_lock);
1080 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1081 spin_unlock_irq(phba->host->host_lock);
1082 lpfc_set_disctmo(phba);
1083 }
1084 goto out;
1085 }
1086 /* ADISC failed */
1087 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001088 if ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
1089 ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) &&
1090 (irsp->un.ulpWord[4] != IOERR_LINK_DOWN) &&
1091 (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) {
dea31012005-04-17 16:05:31 -05001092 lpfc_disc_state_machine(phba, ndlp, cmdiocb,
1093 NLP_EVT_CMPL_ADISC);
1094 }
1095 } else {
1096 /* Good status, call state machine */
1097 lpfc_disc_state_machine(phba, ndlp, cmdiocb,
1098 NLP_EVT_CMPL_ADISC);
1099 }
1100
1101 if (disc && phba->num_disc_nodes) {
1102 /* Check to see if there are more ADISCs to be sent */
1103 lpfc_more_adisc(phba);
1104
1105 /* Check to see if we are done with ADISC authentication */
1106 if (phba->num_disc_nodes == 0) {
1107 lpfc_can_disctmo(phba);
1108 /* If we get here, there is nothing left to wait for */
1109 if ((phba->hba_state < LPFC_HBA_READY) &&
1110 (phba->hba_state != LPFC_CLEAR_LA)) {
1111 /* Link up discovery */
1112 if ((mbox = mempool_alloc(phba->mbox_mem_pool,
1113 GFP_KERNEL))) {
1114 phba->hba_state = LPFC_CLEAR_LA;
1115 lpfc_clear_la(phba, mbox);
1116 mbox->mbox_cmpl =
1117 lpfc_mbx_cmpl_clear_la;
1118 rc = lpfc_sli_issue_mbox
1119 (phba, mbox,
1120 (MBX_NOWAIT | MBX_STOP_IOCB));
1121 if (rc == MBX_NOT_FINISHED) {
1122 mempool_free(mbox,
1123 phba->mbox_mem_pool);
1124 lpfc_disc_flush_list(phba);
1125 psli->ring[(psli->ip_ring)].
1126 flag &=
1127 ~LPFC_STOP_IOCB_EVENT;
1128 psli->ring[(psli->fcp_ring)].
1129 flag &=
1130 ~LPFC_STOP_IOCB_EVENT;
1131 psli->ring[(psli->next_ring)].
1132 flag &=
1133 ~LPFC_STOP_IOCB_EVENT;
1134 phba->hba_state =
1135 LPFC_HBA_READY;
1136 }
1137 }
1138 } else {
1139 lpfc_rscn_disc(phba);
1140 }
1141 }
1142 }
dea31012005-04-17 16:05:31 -05001143out:
1144 lpfc_els_free_iocb(phba, cmdiocb);
1145 return;
1146}
1147
1148int
1149lpfc_issue_els_adisc(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
1150 uint8_t retry)
1151{
1152 ADISC *ap;
1153 IOCB_t *icmd;
1154 struct lpfc_iocbq *elsiocb;
1155 struct lpfc_sli_ring *pring;
1156 struct lpfc_sli *psli;
1157 uint8_t *pcmd;
1158 uint16_t cmdsize;
1159
1160 psli = &phba->sli;
1161 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1162
1163 cmdsize = (sizeof (uint32_t) + sizeof (ADISC));
James Smart488d1462006-03-07 15:02:37 -05001164 elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry, ndlp,
1165 ndlp->nlp_DID, ELS_CMD_ADISC);
1166 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001167 return 1;
dea31012005-04-17 16:05:31 -05001168
1169 icmd = &elsiocb->iocb;
1170 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1171
1172 /* For ADISC request, remainder of payload is service parameters */
1173 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
1174 pcmd += sizeof (uint32_t);
1175
1176 /* Fill in ADISC payload */
1177 ap = (ADISC *) pcmd;
1178 ap->hardAL_PA = phba->fc_pref_ALPA;
1179 memcpy(&ap->portName, &phba->fc_portname, sizeof (struct lpfc_name));
1180 memcpy(&ap->nodeName, &phba->fc_nodename, sizeof (struct lpfc_name));
1181 ap->DID = be32_to_cpu(phba->fc_myDID);
1182
1183 phba->fc_stat.elsXmitADISC++;
1184 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
1185 spin_lock_irq(phba->host->host_lock);
1186 ndlp->nlp_flag |= NLP_ADISC_SND;
1187 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
1188 ndlp->nlp_flag &= ~NLP_ADISC_SND;
1189 spin_unlock_irq(phba->host->host_lock);
1190 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001191 return 1;
dea31012005-04-17 16:05:31 -05001192 }
1193 spin_unlock_irq(phba->host->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001194 return 0;
dea31012005-04-17 16:05:31 -05001195}
1196
1197static void
1198lpfc_cmpl_els_logo(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
1199 struct lpfc_iocbq * rspiocb)
1200{
1201 IOCB_t *irsp;
1202 struct lpfc_sli *psli;
1203 struct lpfc_nodelist *ndlp;
1204
1205 psli = &phba->sli;
1206 /* we pass cmdiocb to state machine which needs rspiocb as well */
1207 cmdiocb->context_un.rsp_iocb = rspiocb;
1208
1209 irsp = &(rspiocb->iocb);
1210 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1211 spin_lock_irq(phba->host->host_lock);
1212 ndlp->nlp_flag &= ~NLP_LOGO_SND;
1213 spin_unlock_irq(phba->host->host_lock);
1214
1215 /* LOGO completes to NPort <nlp_DID> */
1216 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1217 "%d:0105 LOGO completes to NPort x%x "
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001218 "Data: x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -05001219 phba->brd_no, ndlp->nlp_DID, irsp->ulpStatus,
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001220 irsp->un.ulpWord[4], irsp->ulpTimeout,
1221 phba->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001222
1223 /* Check to see if link went down during discovery */
1224 if (lpfc_els_chk_latt(phba))
1225 goto out;
1226
1227 if (irsp->ulpStatus) {
1228 /* Check for retry */
1229 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1230 /* ELS command is being retried */
1231 goto out;
1232 }
1233 /* LOGO failed */
1234 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1235 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
1236 ((irsp->un.ulpWord[4] == IOERR_SLI_ABORTED) ||
James.Smart@Emulex.Com6281bfe2005-11-28 11:41:33 -05001237 (irsp->un.ulpWord[4] == IOERR_LINK_DOWN) ||
dea31012005-04-17 16:05:31 -05001238 (irsp->un.ulpWord[4] == IOERR_SLI_DOWN))) {
1239 goto out;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001240 } else {
dea31012005-04-17 16:05:31 -05001241 lpfc_disc_state_machine(phba, ndlp, cmdiocb,
1242 NLP_EVT_CMPL_LOGO);
1243 }
1244 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001245 /* Good status, call state machine.
1246 * This will unregister the rpi if needed.
1247 */
dea31012005-04-17 16:05:31 -05001248 lpfc_disc_state_machine(phba, ndlp, cmdiocb, NLP_EVT_CMPL_LOGO);
dea31012005-04-17 16:05:31 -05001249 }
1250
1251out:
1252 lpfc_els_free_iocb(phba, cmdiocb);
1253 return;
1254}
1255
1256int
1257lpfc_issue_els_logo(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
1258 uint8_t retry)
1259{
1260 IOCB_t *icmd;
1261 struct lpfc_iocbq *elsiocb;
1262 struct lpfc_sli_ring *pring;
1263 struct lpfc_sli *psli;
1264 uint8_t *pcmd;
1265 uint16_t cmdsize;
1266
1267 psli = &phba->sli;
1268 pring = &psli->ring[LPFC_ELS_RING];
1269
James Smart10d4e952006-04-15 11:53:15 -04001270 cmdsize = (2 * sizeof (uint32_t)) + sizeof (struct lpfc_name);
James Smart488d1462006-03-07 15:02:37 -05001271 elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry, ndlp,
1272 ndlp->nlp_DID, ELS_CMD_LOGO);
1273 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001274 return 1;
dea31012005-04-17 16:05:31 -05001275
1276 icmd = &elsiocb->iocb;
1277 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1278 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
1279 pcmd += sizeof (uint32_t);
1280
1281 /* Fill in LOGO payload */
1282 *((uint32_t *) (pcmd)) = be32_to_cpu(phba->fc_myDID);
1283 pcmd += sizeof (uint32_t);
1284 memcpy(pcmd, &phba->fc_portname, sizeof (struct lpfc_name));
1285
1286 phba->fc_stat.elsXmitLOGO++;
1287 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
1288 spin_lock_irq(phba->host->host_lock);
1289 ndlp->nlp_flag |= NLP_LOGO_SND;
1290 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
1291 ndlp->nlp_flag &= ~NLP_LOGO_SND;
1292 spin_unlock_irq(phba->host->host_lock);
1293 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001294 return 1;
dea31012005-04-17 16:05:31 -05001295 }
1296 spin_unlock_irq(phba->host->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001297 return 0;
dea31012005-04-17 16:05:31 -05001298}
1299
1300static void
1301lpfc_cmpl_els_cmd(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
1302 struct lpfc_iocbq * rspiocb)
1303{
1304 IOCB_t *irsp;
1305
1306 irsp = &rspiocb->iocb;
1307
1308 /* ELS cmd tag <ulpIoTag> completes */
1309 lpfc_printf_log(phba,
1310 KERN_INFO,
1311 LOG_ELS,
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001312 "%d:0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -05001313 phba->brd_no,
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001314 irsp->ulpIoTag, irsp->ulpStatus,
1315 irsp->un.ulpWord[4], irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -05001316
1317 /* Check to see if link went down during discovery */
1318 lpfc_els_chk_latt(phba);
1319 lpfc_els_free_iocb(phba, cmdiocb);
1320 return;
1321}
1322
1323int
1324lpfc_issue_els_scr(struct lpfc_hba * phba, uint32_t nportid, uint8_t retry)
1325{
1326 IOCB_t *icmd;
1327 struct lpfc_iocbq *elsiocb;
1328 struct lpfc_sli_ring *pring;
1329 struct lpfc_sli *psli;
1330 uint8_t *pcmd;
1331 uint16_t cmdsize;
1332 struct lpfc_nodelist *ndlp;
1333
1334 psli = &phba->sli;
1335 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1336 cmdsize = (sizeof (uint32_t) + sizeof (SCR));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001337 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1338 if (!ndlp)
1339 return 1;
dea31012005-04-17 16:05:31 -05001340
1341 lpfc_nlp_init(phba, ndlp, nportid);
1342
James Smart488d1462006-03-07 15:02:37 -05001343 elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry, ndlp,
1344 ndlp->nlp_DID, ELS_CMD_SCR);
1345 if (!elsiocb) {
dea31012005-04-17 16:05:31 -05001346 mempool_free( ndlp, phba->nlp_mem_pool);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001347 return 1;
dea31012005-04-17 16:05:31 -05001348 }
1349
1350 icmd = &elsiocb->iocb;
1351 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1352
1353 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
1354 pcmd += sizeof (uint32_t);
1355
1356 /* For SCR, remainder of payload is SCR parameter page */
1357 memset(pcmd, 0, sizeof (SCR));
1358 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
1359
1360 phba->fc_stat.elsXmitSCR++;
1361 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
1362 spin_lock_irq(phba->host->host_lock);
1363 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
1364 spin_unlock_irq(phba->host->host_lock);
1365 mempool_free( ndlp, phba->nlp_mem_pool);
1366 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001367 return 1;
dea31012005-04-17 16:05:31 -05001368 }
1369 spin_unlock_irq(phba->host->host_lock);
1370 mempool_free( ndlp, phba->nlp_mem_pool);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001371 return 0;
dea31012005-04-17 16:05:31 -05001372}
1373
1374static int
1375lpfc_issue_els_farpr(struct lpfc_hba * phba, uint32_t nportid, uint8_t retry)
1376{
1377 IOCB_t *icmd;
1378 struct lpfc_iocbq *elsiocb;
1379 struct lpfc_sli_ring *pring;
1380 struct lpfc_sli *psli;
1381 FARP *fp;
1382 uint8_t *pcmd;
1383 uint32_t *lp;
1384 uint16_t cmdsize;
1385 struct lpfc_nodelist *ondlp;
1386 struct lpfc_nodelist *ndlp;
1387
1388 psli = &phba->sli;
1389 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1390 cmdsize = (sizeof (uint32_t) + sizeof (FARP));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001391 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1392 if (!ndlp)
1393 return 1;
dea31012005-04-17 16:05:31 -05001394 lpfc_nlp_init(phba, ndlp, nportid);
1395
James Smart488d1462006-03-07 15:02:37 -05001396 elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry, ndlp,
1397 ndlp->nlp_DID, ELS_CMD_RNID);
1398 if (!elsiocb) {
dea31012005-04-17 16:05:31 -05001399 mempool_free( ndlp, phba->nlp_mem_pool);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001400 return 1;
dea31012005-04-17 16:05:31 -05001401 }
1402
1403 icmd = &elsiocb->iocb;
1404 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1405
1406 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
1407 pcmd += sizeof (uint32_t);
1408
1409 /* Fill in FARPR payload */
1410 fp = (FARP *) (pcmd);
1411 memset(fp, 0, sizeof (FARP));
1412 lp = (uint32_t *) pcmd;
1413 *lp++ = be32_to_cpu(nportid);
1414 *lp++ = be32_to_cpu(phba->fc_myDID);
1415 fp->Rflags = 0;
1416 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
1417
1418 memcpy(&fp->RportName, &phba->fc_portname, sizeof (struct lpfc_name));
1419 memcpy(&fp->RnodeName, &phba->fc_nodename, sizeof (struct lpfc_name));
1420 if ((ondlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, nportid))) {
1421 memcpy(&fp->OportName, &ondlp->nlp_portname,
1422 sizeof (struct lpfc_name));
1423 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
1424 sizeof (struct lpfc_name));
1425 }
1426
1427 phba->fc_stat.elsXmitFARPR++;
1428 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
1429 spin_lock_irq(phba->host->host_lock);
1430 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
1431 spin_unlock_irq(phba->host->host_lock);
1432 mempool_free( ndlp, phba->nlp_mem_pool);
1433 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001434 return 1;
dea31012005-04-17 16:05:31 -05001435 }
1436 spin_unlock_irq(phba->host->host_lock);
1437 mempool_free( ndlp, phba->nlp_mem_pool);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001438 return 0;
dea31012005-04-17 16:05:31 -05001439}
1440
1441void
James Smartfdcebe22006-03-07 15:04:01 -05001442lpfc_cancel_retry_delay_tmo(struct lpfc_hba *phba, struct lpfc_nodelist * nlp)
1443{
1444 nlp->nlp_flag &= ~NLP_DELAY_TMO;
1445 del_timer_sync(&nlp->nlp_delayfunc);
1446 nlp->nlp_last_elscmd = 0;
1447
1448 if (!list_empty(&nlp->els_retry_evt.evt_listp))
1449 list_del_init(&nlp->els_retry_evt.evt_listp);
1450
1451 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
1452 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1453 if (phba->num_disc_nodes) {
1454 /* Check to see if there are more
1455 * PLOGIs to be sent
1456 */
1457 lpfc_more_plogi(phba);
James Smartfdcebe22006-03-07 15:04:01 -05001458
James Smart10d4e952006-04-15 11:53:15 -04001459 if (phba->num_disc_nodes == 0) {
1460 phba->fc_flag &= ~FC_NDISC_ACTIVE;
1461 lpfc_can_disctmo(phba);
1462 if (phba->fc_flag & FC_RSCN_MODE) {
1463 /*
1464 * Check to see if more RSCNs
1465 * came in while we were
1466 * processing this one.
1467 */
1468 if((phba->fc_rscn_id_cnt==0) &&
1469 !(phba->fc_flag & FC_RSCN_DISCOVERY)) {
1470 phba->fc_flag &= ~FC_RSCN_MODE;
1471 }
1472 else {
1473 lpfc_els_handle_rscn(phba);
1474 }
James Smartfdcebe22006-03-07 15:04:01 -05001475 }
1476 }
1477 }
1478 }
1479 return;
1480}
1481
1482void
dea31012005-04-17 16:05:31 -05001483lpfc_els_retry_delay(unsigned long ptr)
1484{
1485 struct lpfc_nodelist *ndlp;
1486 struct lpfc_hba *phba;
1487 unsigned long iflag;
1488 struct lpfc_work_evt *evtp;
1489
1490 ndlp = (struct lpfc_nodelist *)ptr;
1491 phba = ndlp->nlp_phba;
1492 evtp = &ndlp->els_retry_evt;
1493
1494 spin_lock_irqsave(phba->host->host_lock, iflag);
1495 if (!list_empty(&evtp->evt_listp)) {
1496 spin_unlock_irqrestore(phba->host->host_lock, iflag);
1497 return;
1498 }
1499
1500 evtp->evt_arg1 = ndlp;
1501 evtp->evt = LPFC_EVT_ELS_RETRY;
1502 list_add_tail(&evtp->evt_listp, &phba->work_list);
1503 if (phba->work_wait)
1504 wake_up(phba->work_wait);
1505
1506 spin_unlock_irqrestore(phba->host->host_lock, iflag);
1507 return;
1508}
1509
1510void
1511lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
1512{
1513 struct lpfc_hba *phba;
1514 uint32_t cmd;
1515 uint32_t did;
1516 uint8_t retry;
1517
1518 phba = ndlp->nlp_phba;
1519 spin_lock_irq(phba->host->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001520 did = ndlp->nlp_DID;
1521 cmd = ndlp->nlp_last_elscmd;
1522 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05001523
1524 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
1525 spin_unlock_irq(phba->host->host_lock);
1526 return;
1527 }
1528
1529 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
1530 spin_unlock_irq(phba->host->host_lock);
James Smart1a169682006-03-07 15:04:06 -05001531 /*
1532 * If a discovery event readded nlp_delayfunc after timer
1533 * firing and before processing the timer, cancel the
1534 * nlp_delayfunc.
1535 */
1536 del_timer_sync(&ndlp->nlp_delayfunc);
dea31012005-04-17 16:05:31 -05001537 retry = ndlp->nlp_retry;
1538
1539 switch (cmd) {
1540 case ELS_CMD_FLOGI:
1541 lpfc_issue_els_flogi(phba, ndlp, retry);
1542 break;
1543 case ELS_CMD_PLOGI:
James Smart488d1462006-03-07 15:02:37 -05001544 if(!lpfc_issue_els_plogi(phba, ndlp->nlp_DID, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001545 ndlp->nlp_prev_state = ndlp->nlp_state;
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05001546 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
1547 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
1548 }
dea31012005-04-17 16:05:31 -05001549 break;
1550 case ELS_CMD_ADISC:
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05001551 if (!lpfc_issue_els_adisc(phba, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001552 ndlp->nlp_prev_state = ndlp->nlp_state;
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05001553 ndlp->nlp_state = NLP_STE_ADISC_ISSUE;
1554 lpfc_nlp_list(phba, ndlp, NLP_ADISC_LIST);
1555 }
dea31012005-04-17 16:05:31 -05001556 break;
1557 case ELS_CMD_PRLI:
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05001558 if (!lpfc_issue_els_prli(phba, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001559 ndlp->nlp_prev_state = ndlp->nlp_state;
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05001560 ndlp->nlp_state = NLP_STE_PRLI_ISSUE;
1561 lpfc_nlp_list(phba, ndlp, NLP_PRLI_LIST);
1562 }
dea31012005-04-17 16:05:31 -05001563 break;
1564 case ELS_CMD_LOGO:
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05001565 if (!lpfc_issue_els_logo(phba, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001566 ndlp->nlp_prev_state = ndlp->nlp_state;
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05001567 ndlp->nlp_state = NLP_STE_NPR_NODE;
1568 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1569 }
dea31012005-04-17 16:05:31 -05001570 break;
1571 }
1572 return;
1573}
1574
1575static int
1576lpfc_els_retry(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
1577 struct lpfc_iocbq * rspiocb)
1578{
1579 IOCB_t *irsp;
1580 struct lpfc_dmabuf *pcmd;
1581 struct lpfc_nodelist *ndlp;
1582 uint32_t *elscmd;
1583 struct ls_rjt stat;
1584 int retry, maxretry;
1585 int delay;
1586 uint32_t cmd;
James Smart488d1462006-03-07 15:02:37 -05001587 uint32_t did;
dea31012005-04-17 16:05:31 -05001588
1589 retry = 0;
1590 delay = 0;
1591 maxretry = lpfc_max_els_tries;
1592 irsp = &rspiocb->iocb;
1593 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1594 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
1595 cmd = 0;
James Smart488d1462006-03-07 15:02:37 -05001596
dea31012005-04-17 16:05:31 -05001597 /* Note: context2 may be 0 for internal driver abort
1598 * of delays ELS command.
1599 */
1600
1601 if (pcmd && pcmd->virt) {
1602 elscmd = (uint32_t *) (pcmd->virt);
1603 cmd = *elscmd++;
1604 }
1605
James Smart488d1462006-03-07 15:02:37 -05001606 if(ndlp)
1607 did = ndlp->nlp_DID;
1608 else {
1609 /* We should only hit this case for retrying PLOGI */
1610 did = irsp->un.elsreq64.remoteID;
1611 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, did);
1612 if (!ndlp && (cmd != ELS_CMD_PLOGI))
1613 return 1;
1614 }
1615
dea31012005-04-17 16:05:31 -05001616 switch (irsp->ulpStatus) {
1617 case IOSTAT_FCP_RSP_ERROR:
1618 case IOSTAT_REMOTE_STOP:
1619 break;
1620
1621 case IOSTAT_LOCAL_REJECT:
1622 switch ((irsp->un.ulpWord[4] & 0xff)) {
1623 case IOERR_LOOP_OPEN_FAILURE:
1624 if (cmd == ELS_CMD_PLOGI) {
1625 if (cmdiocb->retry == 0) {
1626 delay = 1;
1627 }
1628 }
1629 retry = 1;
1630 break;
1631
1632 case IOERR_SEQUENCE_TIMEOUT:
1633 retry = 1;
dea31012005-04-17 16:05:31 -05001634 break;
1635
1636 case IOERR_NO_RESOURCES:
1637 if (cmd == ELS_CMD_PLOGI) {
1638 delay = 1;
1639 }
1640 retry = 1;
1641 break;
1642
1643 case IOERR_INVALID_RPI:
1644 retry = 1;
1645 break;
1646 }
1647 break;
1648
1649 case IOSTAT_NPORT_RJT:
1650 case IOSTAT_FABRIC_RJT:
1651 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
1652 retry = 1;
1653 break;
1654 }
1655 break;
1656
1657 case IOSTAT_NPORT_BSY:
1658 case IOSTAT_FABRIC_BSY:
1659 retry = 1;
1660 break;
1661
1662 case IOSTAT_LS_RJT:
1663 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
1664 /* Added for Vendor specifc support
1665 * Just keep retrying for these Rsn / Exp codes
1666 */
1667 switch (stat.un.b.lsRjtRsnCode) {
1668 case LSRJT_UNABLE_TPC:
1669 if (stat.un.b.lsRjtRsnCodeExp ==
1670 LSEXP_CMD_IN_PROGRESS) {
1671 if (cmd == ELS_CMD_PLOGI) {
1672 delay = 1;
1673 maxretry = 48;
1674 }
1675 retry = 1;
1676 break;
1677 }
1678 if (cmd == ELS_CMD_PLOGI) {
1679 delay = 1;
1680 maxretry = lpfc_max_els_tries + 1;
1681 retry = 1;
1682 break;
1683 }
1684 break;
1685
1686 case LSRJT_LOGICAL_BSY:
1687 if (cmd == ELS_CMD_PLOGI) {
1688 delay = 1;
1689 maxretry = 48;
1690 }
1691 retry = 1;
1692 break;
1693 }
1694 break;
1695
1696 case IOSTAT_INTERMED_RSP:
1697 case IOSTAT_BA_RJT:
1698 break;
1699
1700 default:
1701 break;
1702 }
1703
James Smart488d1462006-03-07 15:02:37 -05001704 if (did == FDMI_DID)
dea31012005-04-17 16:05:31 -05001705 retry = 1;
dea31012005-04-17 16:05:31 -05001706
1707 if ((++cmdiocb->retry) >= maxretry) {
1708 phba->fc_stat.elsRetryExceeded++;
1709 retry = 0;
1710 }
1711
1712 if (retry) {
1713
1714 /* Retry ELS command <elsCmd> to remote NPORT <did> */
1715 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1716 "%d:0107 Retry ELS command x%x to remote "
1717 "NPORT x%x Data: x%x x%x\n",
1718 phba->brd_no,
James Smart488d1462006-03-07 15:02:37 -05001719 cmd, did, cmdiocb->retry, delay);
dea31012005-04-17 16:05:31 -05001720
1721 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) {
1722 /* If discovery / RSCN timer is running, reset it */
1723 if (timer_pending(&phba->fc_disctmo) ||
1724 (phba->fc_flag & FC_RSCN_MODE)) {
1725 lpfc_set_disctmo(phba);
1726 }
1727 }
1728
1729 phba->fc_stat.elsXmitRetry++;
James Smart488d1462006-03-07 15:02:37 -05001730 if (ndlp && delay) {
dea31012005-04-17 16:05:31 -05001731 phba->fc_stat.elsDelayRetry++;
1732 ndlp->nlp_retry = cmdiocb->retry;
1733
1734 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
1735 ndlp->nlp_flag |= NLP_DELAY_TMO;
1736
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001737 ndlp->nlp_prev_state = ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001738 ndlp->nlp_state = NLP_STE_NPR_NODE;
1739 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1740 ndlp->nlp_last_elscmd = cmd;
1741
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001742 return 1;
dea31012005-04-17 16:05:31 -05001743 }
1744 switch (cmd) {
1745 case ELS_CMD_FLOGI:
1746 lpfc_issue_els_flogi(phba, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001747 return 1;
dea31012005-04-17 16:05:31 -05001748 case ELS_CMD_PLOGI:
James Smart488d1462006-03-07 15:02:37 -05001749 if (ndlp) {
1750 ndlp->nlp_prev_state = ndlp->nlp_state;
1751 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
1752 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
1753 }
1754 lpfc_issue_els_plogi(phba, did, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001755 return 1;
dea31012005-04-17 16:05:31 -05001756 case ELS_CMD_ADISC:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001757 ndlp->nlp_prev_state = ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001758 ndlp->nlp_state = NLP_STE_ADISC_ISSUE;
1759 lpfc_nlp_list(phba, ndlp, NLP_ADISC_LIST);
1760 lpfc_issue_els_adisc(phba, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001761 return 1;
dea31012005-04-17 16:05:31 -05001762 case ELS_CMD_PRLI:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001763 ndlp->nlp_prev_state = ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001764 ndlp->nlp_state = NLP_STE_PRLI_ISSUE;
1765 lpfc_nlp_list(phba, ndlp, NLP_PRLI_LIST);
1766 lpfc_issue_els_prli(phba, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001767 return 1;
dea31012005-04-17 16:05:31 -05001768 case ELS_CMD_LOGO:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001769 ndlp->nlp_prev_state = ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001770 ndlp->nlp_state = NLP_STE_NPR_NODE;
1771 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1772 lpfc_issue_els_logo(phba, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001773 return 1;
dea31012005-04-17 16:05:31 -05001774 }
1775 }
1776
1777 /* No retry ELS command <elsCmd> to remote NPORT <did> */
1778 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1779 "%d:0108 No retry ELS command x%x to remote NPORT x%x "
James Smart488d1462006-03-07 15:02:37 -05001780 "Data: x%x\n",
dea31012005-04-17 16:05:31 -05001781 phba->brd_no,
James Smart488d1462006-03-07 15:02:37 -05001782 cmd, did, cmdiocb->retry);
dea31012005-04-17 16:05:31 -05001783
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001784 return 0;
dea31012005-04-17 16:05:31 -05001785}
1786
1787int
1788lpfc_els_free_iocb(struct lpfc_hba * phba, struct lpfc_iocbq * elsiocb)
1789{
1790 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
1791
1792 /* context2 = cmd, context2->next = rsp, context3 = bpl */
1793 if (elsiocb->context2) {
1794 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
1795 /* Free the response before processing the command. */
1796 if (!list_empty(&buf_ptr1->list)) {
1797 list_remove_head(&buf_ptr1->list, buf_ptr,
1798 struct lpfc_dmabuf,
1799 list);
1800 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
1801 kfree(buf_ptr);
1802 }
1803 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
1804 kfree(buf_ptr1);
1805 }
1806
1807 if (elsiocb->context3) {
1808 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
1809 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
1810 kfree(buf_ptr);
1811 }
1812 spin_lock_irq(phba->host->host_lock);
James Bottomley604a3e32005-10-29 10:28:33 -05001813 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -05001814 spin_unlock_irq(phba->host->host_lock);
1815 return 0;
1816}
1817
1818static void
1819lpfc_cmpl_els_logo_acc(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
1820 struct lpfc_iocbq * rspiocb)
1821{
1822 struct lpfc_nodelist *ndlp;
1823
1824 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1825
1826 /* ACC to LOGO completes to NPort <nlp_DID> */
1827 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1828 "%d:0109 ACC to LOGO completes to NPort x%x "
1829 "Data: x%x x%x x%x\n",
1830 phba->brd_no, ndlp->nlp_DID, ndlp->nlp_flag,
1831 ndlp->nlp_state, ndlp->nlp_rpi);
1832
dea31012005-04-17 16:05:31 -05001833 switch (ndlp->nlp_state) {
1834 case NLP_STE_UNUSED_NODE: /* node is just allocated */
1835 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
1836 break;
1837 case NLP_STE_NPR_NODE: /* NPort Recovery mode */
1838 lpfc_unreg_rpi(phba, ndlp);
1839 break;
1840 default:
1841 break;
1842 }
1843 lpfc_els_free_iocb(phba, cmdiocb);
1844 return;
1845}
1846
1847static void
1848lpfc_cmpl_els_acc(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
1849 struct lpfc_iocbq * rspiocb)
1850{
James Smart33ccf8d2006-08-17 11:57:58 -04001851 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001852 struct lpfc_nodelist *ndlp;
1853 LPFC_MBOXQ_t *mbox = NULL;
1854
James Smart33ccf8d2006-08-17 11:57:58 -04001855 irsp = &rspiocb->iocb;
1856
dea31012005-04-17 16:05:31 -05001857 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1858 if (cmdiocb->context_un.mbox)
1859 mbox = cmdiocb->context_un.mbox;
1860
1861
1862 /* Check to see if link went down during discovery */
1863 if ((lpfc_els_chk_latt(phba)) || !ndlp) {
1864 if (mbox) {
1865 mempool_free( mbox, phba->mbox_mem_pool);
1866 }
1867 goto out;
1868 }
1869
1870 /* ELS response tag <ulpIoTag> completes */
1871 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1872 "%d:0110 ELS response tag x%x completes "
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001873 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -05001874 phba->brd_no,
1875 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001876 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
1877 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
1878 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05001879
1880 if (mbox) {
1881 if ((rspiocb->iocb.ulpStatus == 0)
1882 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
dea31012005-04-17 16:05:31 -05001883 lpfc_unreg_rpi(phba, ndlp);
1884 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
1885 mbox->context2 = ndlp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001886 ndlp->nlp_prev_state = ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001887 ndlp->nlp_state = NLP_STE_REG_LOGIN_ISSUE;
1888 lpfc_nlp_list(phba, ndlp, NLP_REGLOGIN_LIST);
1889 if (lpfc_sli_issue_mbox(phba, mbox,
1890 (MBX_NOWAIT | MBX_STOP_IOCB))
1891 != MBX_NOT_FINISHED) {
1892 goto out;
1893 }
1894 /* NOTE: we should have messages for unsuccessful
1895 reglogin */
1896 mempool_free( mbox, phba->mbox_mem_pool);
1897 } else {
1898 mempool_free( mbox, phba->mbox_mem_pool);
James Smart33ccf8d2006-08-17 11:57:58 -04001899 /* Do not call NO_LIST for lpfc_els_abort'ed ELS cmds */
1900 if (!((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
1901 ((irsp->un.ulpWord[4] == IOERR_SLI_ABORTED) ||
1902 (irsp->un.ulpWord[4] == IOERR_LINK_DOWN) ||
1903 (irsp->un.ulpWord[4] == IOERR_SLI_DOWN)))) {
1904 if (ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
1905 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
1906 ndlp = NULL;
1907 }
dea31012005-04-17 16:05:31 -05001908 }
1909 }
1910 }
1911out:
1912 if (ndlp) {
1913 spin_lock_irq(phba->host->host_lock);
1914 ndlp->nlp_flag &= ~NLP_ACC_REGLOGIN;
1915 spin_unlock_irq(phba->host->host_lock);
1916 }
1917 lpfc_els_free_iocb(phba, cmdiocb);
1918 return;
1919}
1920
1921int
1922lpfc_els_rsp_acc(struct lpfc_hba * phba, uint32_t flag,
1923 struct lpfc_iocbq * oldiocb, struct lpfc_nodelist * ndlp,
1924 LPFC_MBOXQ_t * mbox, uint8_t newnode)
1925{
1926 IOCB_t *icmd;
1927 IOCB_t *oldcmd;
1928 struct lpfc_iocbq *elsiocb;
1929 struct lpfc_sli_ring *pring;
1930 struct lpfc_sli *psli;
1931 uint8_t *pcmd;
1932 uint16_t cmdsize;
1933 int rc;
James Smart82d9a2a2006-04-15 11:53:05 -04001934 ELS_PKT *els_pkt_ptr;
dea31012005-04-17 16:05:31 -05001935
1936 psli = &phba->sli;
1937 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1938 oldcmd = &oldiocb->iocb;
1939
1940 switch (flag) {
1941 case ELS_CMD_ACC:
1942 cmdsize = sizeof (uint32_t);
James Smart488d1462006-03-07 15:02:37 -05001943 elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry,
1944 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
1945 if (!elsiocb) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001946 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001947 return 1;
dea31012005-04-17 16:05:31 -05001948 }
1949 icmd = &elsiocb->iocb;
1950 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
1951 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1952 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
1953 pcmd += sizeof (uint32_t);
1954 break;
1955 case ELS_CMD_PLOGI:
1956 cmdsize = (sizeof (struct serv_parm) + sizeof (uint32_t));
James Smart488d1462006-03-07 15:02:37 -05001957 elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry,
1958 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
1959 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001960 return 1;
James Smart488d1462006-03-07 15:02:37 -05001961
dea31012005-04-17 16:05:31 -05001962 icmd = &elsiocb->iocb;
1963 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
1964 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1965
1966 if (mbox)
1967 elsiocb->context_un.mbox = mbox;
1968
1969 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
1970 pcmd += sizeof (uint32_t);
1971 memcpy(pcmd, &phba->fc_sparam, sizeof (struct serv_parm));
1972 break;
James Smart82d9a2a2006-04-15 11:53:05 -04001973 case ELS_CMD_PRLO:
1974 cmdsize = sizeof (uint32_t) + sizeof (PRLO);
1975 elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry,
1976 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
1977 if (!elsiocb)
1978 return 1;
1979
1980 icmd = &elsiocb->iocb;
1981 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
1982 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1983
1984 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
1985 sizeof (uint32_t) + sizeof (PRLO));
1986 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
1987 els_pkt_ptr = (ELS_PKT *) pcmd;
1988 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
1989 break;
dea31012005-04-17 16:05:31 -05001990 default:
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001991 return 1;
dea31012005-04-17 16:05:31 -05001992 }
1993
1994 if (newnode)
1995 elsiocb->context1 = NULL;
1996
1997 /* Xmit ELS ACC response tag <ulpIoTag> */
1998 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1999 "%d:0128 Xmit ELS ACC response tag x%x "
2000 "Data: x%x x%x x%x x%x x%x\n",
2001 phba->brd_no,
2002 elsiocb->iocb.ulpIoTag,
2003 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
2004 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
2005
2006 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002007 spin_lock_irq(phba->host->host_lock);
2008 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
2009 spin_unlock_irq(phba->host->host_lock);
dea31012005-04-17 16:05:31 -05002010 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
2011 } else {
2012 elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
2013 }
2014
2015 phba->fc_stat.elsXmitACC++;
2016 spin_lock_irq(phba->host->host_lock);
2017 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
2018 spin_unlock_irq(phba->host->host_lock);
2019 if (rc == IOCB_ERROR) {
2020 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002021 return 1;
dea31012005-04-17 16:05:31 -05002022 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002023 return 0;
dea31012005-04-17 16:05:31 -05002024}
2025
2026int
2027lpfc_els_rsp_reject(struct lpfc_hba * phba, uint32_t rejectError,
2028 struct lpfc_iocbq * oldiocb, struct lpfc_nodelist * ndlp)
2029{
2030 IOCB_t *icmd;
2031 IOCB_t *oldcmd;
2032 struct lpfc_iocbq *elsiocb;
2033 struct lpfc_sli_ring *pring;
2034 struct lpfc_sli *psli;
2035 uint8_t *pcmd;
2036 uint16_t cmdsize;
2037 int rc;
2038
2039 psli = &phba->sli;
2040 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2041
2042 cmdsize = 2 * sizeof (uint32_t);
James Smart488d1462006-03-07 15:02:37 -05002043 elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry,
2044 ndlp, ndlp->nlp_DID, ELS_CMD_LS_RJT);
2045 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002046 return 1;
dea31012005-04-17 16:05:31 -05002047
2048 icmd = &elsiocb->iocb;
2049 oldcmd = &oldiocb->iocb;
2050 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2051 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2052
2053 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
2054 pcmd += sizeof (uint32_t);
2055 *((uint32_t *) (pcmd)) = rejectError;
2056
2057 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
2058 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
2059 "%d:0129 Xmit ELS RJT x%x response tag x%x "
2060 "Data: x%x x%x x%x x%x x%x\n",
2061 phba->brd_no,
2062 rejectError, elsiocb->iocb.ulpIoTag,
2063 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
2064 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
2065
2066 phba->fc_stat.elsXmitLSRJT++;
2067 elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
2068 spin_lock_irq(phba->host->host_lock);
2069 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
2070 spin_unlock_irq(phba->host->host_lock);
2071 if (rc == IOCB_ERROR) {
2072 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002073 return 1;
dea31012005-04-17 16:05:31 -05002074 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002075 return 0;
dea31012005-04-17 16:05:31 -05002076}
2077
2078int
2079lpfc_els_rsp_adisc_acc(struct lpfc_hba * phba,
2080 struct lpfc_iocbq * oldiocb, struct lpfc_nodelist * ndlp)
2081{
2082 ADISC *ap;
2083 IOCB_t *icmd;
2084 IOCB_t *oldcmd;
2085 struct lpfc_iocbq *elsiocb;
2086 struct lpfc_sli_ring *pring;
2087 struct lpfc_sli *psli;
2088 uint8_t *pcmd;
2089 uint16_t cmdsize;
2090 int rc;
2091
2092 psli = &phba->sli;
2093 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2094
2095 cmdsize = sizeof (uint32_t) + sizeof (ADISC);
James Smart488d1462006-03-07 15:02:37 -05002096 elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry,
2097 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
2098 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002099 return 1;
dea31012005-04-17 16:05:31 -05002100
2101 /* Xmit ADISC ACC response tag <ulpIoTag> */
2102 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
2103 "%d:0130 Xmit ADISC ACC response tag x%x "
2104 "Data: x%x x%x x%x x%x x%x\n",
2105 phba->brd_no,
2106 elsiocb->iocb.ulpIoTag,
2107 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
2108 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
2109
2110 icmd = &elsiocb->iocb;
2111 oldcmd = &oldiocb->iocb;
2112 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2113 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2114
2115 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
2116 pcmd += sizeof (uint32_t);
2117
2118 ap = (ADISC *) (pcmd);
2119 ap->hardAL_PA = phba->fc_pref_ALPA;
2120 memcpy(&ap->portName, &phba->fc_portname, sizeof (struct lpfc_name));
2121 memcpy(&ap->nodeName, &phba->fc_nodename, sizeof (struct lpfc_name));
2122 ap->DID = be32_to_cpu(phba->fc_myDID);
2123
2124 phba->fc_stat.elsXmitACC++;
2125 elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
2126 spin_lock_irq(phba->host->host_lock);
2127 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
2128 spin_unlock_irq(phba->host->host_lock);
2129 if (rc == IOCB_ERROR) {
2130 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002131 return 1;
dea31012005-04-17 16:05:31 -05002132 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002133 return 0;
dea31012005-04-17 16:05:31 -05002134}
2135
2136int
2137lpfc_els_rsp_prli_acc(struct lpfc_hba * phba,
2138 struct lpfc_iocbq * oldiocb, struct lpfc_nodelist * ndlp)
2139{
2140 PRLI *npr;
2141 lpfc_vpd_t *vpd;
2142 IOCB_t *icmd;
2143 IOCB_t *oldcmd;
2144 struct lpfc_iocbq *elsiocb;
2145 struct lpfc_sli_ring *pring;
2146 struct lpfc_sli *psli;
2147 uint8_t *pcmd;
2148 uint16_t cmdsize;
2149 int rc;
2150
2151 psli = &phba->sli;
2152 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2153
2154 cmdsize = sizeof (uint32_t) + sizeof (PRLI);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002155 elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry, ndlp,
James Smart488d1462006-03-07 15:02:37 -05002156 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002157 if (!elsiocb)
2158 return 1;
dea31012005-04-17 16:05:31 -05002159
2160 /* Xmit PRLI ACC response tag <ulpIoTag> */
2161 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
2162 "%d:0131 Xmit PRLI ACC response tag x%x "
2163 "Data: x%x x%x x%x x%x x%x\n",
2164 phba->brd_no,
2165 elsiocb->iocb.ulpIoTag,
2166 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
2167 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
2168
2169 icmd = &elsiocb->iocb;
2170 oldcmd = &oldiocb->iocb;
2171 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2172 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2173
2174 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
2175 pcmd += sizeof (uint32_t);
2176
2177 /* For PRLI, remainder of payload is PRLI parameter page */
2178 memset(pcmd, 0, sizeof (PRLI));
2179
2180 npr = (PRLI *) pcmd;
2181 vpd = &phba->vpd;
2182 /*
2183 * If our firmware version is 3.20 or later,
2184 * set the following bits for FC-TAPE support.
2185 */
2186 if (vpd->rev.feaLevelHigh >= 0x02) {
2187 npr->ConfmComplAllowed = 1;
2188 npr->Retry = 1;
2189 npr->TaskRetryIdReq = 1;
2190 }
2191
2192 npr->acceptRspCode = PRLI_REQ_EXECUTED;
2193 npr->estabImagePair = 1;
2194 npr->readXferRdyDis = 1;
2195 npr->ConfmComplAllowed = 1;
2196
2197 npr->prliType = PRLI_FCP_TYPE;
2198 npr->initiatorFunc = 1;
2199
2200 phba->fc_stat.elsXmitACC++;
2201 elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
2202
2203 spin_lock_irq(phba->host->host_lock);
2204 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
2205 spin_unlock_irq(phba->host->host_lock);
2206 if (rc == IOCB_ERROR) {
2207 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002208 return 1;
dea31012005-04-17 16:05:31 -05002209 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002210 return 0;
dea31012005-04-17 16:05:31 -05002211}
2212
2213static int
2214lpfc_els_rsp_rnid_acc(struct lpfc_hba * phba,
2215 uint8_t format,
2216 struct lpfc_iocbq * oldiocb, struct lpfc_nodelist * ndlp)
2217{
2218 RNID *rn;
2219 IOCB_t *icmd;
2220 IOCB_t *oldcmd;
2221 struct lpfc_iocbq *elsiocb;
2222 struct lpfc_sli_ring *pring;
2223 struct lpfc_sli *psli;
2224 uint8_t *pcmd;
2225 uint16_t cmdsize;
2226 int rc;
2227
2228 psli = &phba->sli;
2229 pring = &psli->ring[LPFC_ELS_RING];
2230
2231 cmdsize = sizeof (uint32_t) + sizeof (uint32_t)
2232 + (2 * sizeof (struct lpfc_name));
2233 if (format)
2234 cmdsize += sizeof (RNID_TOP_DISC);
2235
James Smart488d1462006-03-07 15:02:37 -05002236 elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry,
2237 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
2238 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002239 return 1;
dea31012005-04-17 16:05:31 -05002240
2241 /* Xmit RNID ACC response tag <ulpIoTag> */
2242 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
2243 "%d:0132 Xmit RNID ACC response tag x%x "
2244 "Data: x%x\n",
2245 phba->brd_no,
2246 elsiocb->iocb.ulpIoTag,
2247 elsiocb->iocb.ulpContext);
2248
2249 icmd = &elsiocb->iocb;
2250 oldcmd = &oldiocb->iocb;
2251 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2252 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2253
2254 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
2255 pcmd += sizeof (uint32_t);
2256
2257 memset(pcmd, 0, sizeof (RNID));
2258 rn = (RNID *) (pcmd);
2259 rn->Format = format;
2260 rn->CommonLen = (2 * sizeof (struct lpfc_name));
2261 memcpy(&rn->portName, &phba->fc_portname, sizeof (struct lpfc_name));
2262 memcpy(&rn->nodeName, &phba->fc_nodename, sizeof (struct lpfc_name));
2263 switch (format) {
2264 case 0:
2265 rn->SpecificLen = 0;
2266 break;
2267 case RNID_TOPOLOGY_DISC:
2268 rn->SpecificLen = sizeof (RNID_TOP_DISC);
2269 memcpy(&rn->un.topologyDisc.portName,
2270 &phba->fc_portname, sizeof (struct lpfc_name));
2271 rn->un.topologyDisc.unitType = RNID_HBA;
2272 rn->un.topologyDisc.physPort = 0;
2273 rn->un.topologyDisc.attachedNodes = 0;
2274 break;
2275 default:
2276 rn->CommonLen = 0;
2277 rn->SpecificLen = 0;
2278 break;
2279 }
2280
2281 phba->fc_stat.elsXmitACC++;
2282 elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
2283 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
2284 * it could be freed */
2285
2286 spin_lock_irq(phba->host->host_lock);
2287 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
2288 spin_unlock_irq(phba->host->host_lock);
2289 if (rc == IOCB_ERROR) {
2290 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002291 return 1;
dea31012005-04-17 16:05:31 -05002292 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002293 return 0;
dea31012005-04-17 16:05:31 -05002294}
2295
2296int
2297lpfc_els_disc_adisc(struct lpfc_hba * phba)
2298{
2299 int sentadisc;
2300 struct lpfc_nodelist *ndlp, *next_ndlp;
2301
2302 sentadisc = 0;
2303 /* go thru NPR list and issue any remaining ELS ADISCs */
2304 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
2305 nlp_listp) {
2306 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
2307 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
2308 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002309 ndlp->nlp_prev_state = ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05002310 ndlp->nlp_state = NLP_STE_ADISC_ISSUE;
2311 lpfc_nlp_list(phba, ndlp,
2312 NLP_ADISC_LIST);
2313 lpfc_issue_els_adisc(phba, ndlp, 0);
2314 sentadisc++;
2315 phba->num_disc_nodes++;
2316 if (phba->num_disc_nodes >=
2317 phba->cfg_discovery_threads) {
2318 spin_lock_irq(phba->host->host_lock);
2319 phba->fc_flag |= FC_NLP_MORE;
2320 spin_unlock_irq(phba->host->host_lock);
2321 break;
2322 }
2323 }
2324 }
2325 }
2326 if (sentadisc == 0) {
2327 spin_lock_irq(phba->host->host_lock);
2328 phba->fc_flag &= ~FC_NLP_MORE;
2329 spin_unlock_irq(phba->host->host_lock);
2330 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002331 return sentadisc;
dea31012005-04-17 16:05:31 -05002332}
2333
2334int
2335lpfc_els_disc_plogi(struct lpfc_hba * phba)
2336{
2337 int sentplogi;
2338 struct lpfc_nodelist *ndlp, *next_ndlp;
2339
2340 sentplogi = 0;
2341 /* go thru NPR list and issue any remaining ELS PLOGIs */
2342 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
2343 nlp_listp) {
2344 if ((ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
2345 (!(ndlp->nlp_flag & NLP_DELAY_TMO))) {
2346 if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002347 ndlp->nlp_prev_state = ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05002348 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
2349 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
James Smart488d1462006-03-07 15:02:37 -05002350 lpfc_issue_els_plogi(phba, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05002351 sentplogi++;
2352 phba->num_disc_nodes++;
2353 if (phba->num_disc_nodes >=
2354 phba->cfg_discovery_threads) {
2355 spin_lock_irq(phba->host->host_lock);
2356 phba->fc_flag |= FC_NLP_MORE;
2357 spin_unlock_irq(phba->host->host_lock);
2358 break;
2359 }
2360 }
2361 }
2362 }
2363 if (sentplogi == 0) {
2364 spin_lock_irq(phba->host->host_lock);
2365 phba->fc_flag &= ~FC_NLP_MORE;
2366 spin_unlock_irq(phba->host->host_lock);
2367 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002368 return sentplogi;
dea31012005-04-17 16:05:31 -05002369}
2370
2371int
2372lpfc_els_flush_rscn(struct lpfc_hba * phba)
2373{
2374 struct lpfc_dmabuf *mp;
2375 int i;
2376
2377 for (i = 0; i < phba->fc_rscn_id_cnt; i++) {
2378 mp = phba->fc_rscn_id_list[i];
2379 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2380 kfree(mp);
2381 phba->fc_rscn_id_list[i] = NULL;
2382 }
2383 phba->fc_rscn_id_cnt = 0;
2384 spin_lock_irq(phba->host->host_lock);
2385 phba->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
2386 spin_unlock_irq(phba->host->host_lock);
2387 lpfc_can_disctmo(phba);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002388 return 0;
dea31012005-04-17 16:05:31 -05002389}
2390
2391int
2392lpfc_rscn_payload_check(struct lpfc_hba * phba, uint32_t did)
2393{
2394 D_ID ns_did;
2395 D_ID rscn_did;
2396 struct lpfc_dmabuf *mp;
2397 uint32_t *lp;
2398 uint32_t payload_len, cmd, i, match;
2399
2400 ns_did.un.word = did;
2401 match = 0;
2402
2403 /* Never match fabric nodes for RSCNs */
2404 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
2405 return(0);
2406
2407 /* If we are doing a FULL RSCN rediscovery, match everything */
2408 if (phba->fc_flag & FC_RSCN_DISCOVERY) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002409 return did;
dea31012005-04-17 16:05:31 -05002410 }
2411
2412 for (i = 0; i < phba->fc_rscn_id_cnt; i++) {
2413 mp = phba->fc_rscn_id_list[i];
2414 lp = (uint32_t *) mp->virt;
2415 cmd = *lp++;
2416 payload_len = be32_to_cpu(cmd) & 0xffff; /* payload length */
2417 payload_len -= sizeof (uint32_t); /* take off word 0 */
2418 while (payload_len) {
2419 rscn_did.un.word = *lp++;
2420 rscn_did.un.word = be32_to_cpu(rscn_did.un.word);
2421 payload_len -= sizeof (uint32_t);
2422 switch (rscn_did.un.b.resv) {
2423 case 0: /* Single N_Port ID effected */
2424 if (ns_did.un.word == rscn_did.un.word) {
2425 match = did;
2426 }
2427 break;
2428 case 1: /* Whole N_Port Area effected */
2429 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
2430 && (ns_did.un.b.area == rscn_did.un.b.area))
2431 {
2432 match = did;
2433 }
2434 break;
2435 case 2: /* Whole N_Port Domain effected */
2436 if (ns_did.un.b.domain == rscn_did.un.b.domain)
2437 {
2438 match = did;
2439 }
2440 break;
2441 case 3: /* Whole Fabric effected */
2442 match = did;
2443 break;
2444 default:
2445 /* Unknown Identifier in RSCN list */
2446 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2447 "%d:0217 Unknown Identifier in "
2448 "RSCN payload Data: x%x\n",
2449 phba->brd_no, rscn_did.un.word);
2450 break;
2451 }
2452 if (match) {
2453 break;
2454 }
2455 }
2456 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002457 return match;
dea31012005-04-17 16:05:31 -05002458}
2459
2460static int
2461lpfc_rscn_recovery_check(struct lpfc_hba * phba)
2462{
2463 struct lpfc_nodelist *ndlp = NULL, *next_ndlp;
2464 struct list_head *listp;
2465 struct list_head *node_list[7];
2466 int i;
2467
2468 /* Look at all nodes effected by pending RSCNs and move
2469 * them to NPR list.
2470 */
2471 node_list[0] = &phba->fc_npr_list; /* MUST do this list first */
2472 node_list[1] = &phba->fc_nlpmap_list;
2473 node_list[2] = &phba->fc_nlpunmap_list;
2474 node_list[3] = &phba->fc_prli_list;
2475 node_list[4] = &phba->fc_reglogin_list;
2476 node_list[5] = &phba->fc_adisc_list;
2477 node_list[6] = &phba->fc_plogi_list;
2478 for (i = 0; i < 7; i++) {
2479 listp = node_list[i];
2480 if (list_empty(listp))
2481 continue;
2482
2483 list_for_each_entry_safe(ndlp, next_ndlp, listp, nlp_listp) {
2484 if (!(lpfc_rscn_payload_check(phba, ndlp->nlp_DID)))
2485 continue;
2486
2487 lpfc_disc_state_machine(phba, ndlp, NULL,
2488 NLP_EVT_DEVICE_RECOVERY);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002489
2490 /* Make sure NLP_DELAY_TMO is NOT running
2491 * after a device recovery event.
2492 */
James Smartfdcebe22006-03-07 15:04:01 -05002493 if (ndlp->nlp_flag & NLP_DELAY_TMO)
2494 lpfc_cancel_retry_delay_tmo(phba, ndlp);
dea31012005-04-17 16:05:31 -05002495 }
2496 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002497 return 0;
dea31012005-04-17 16:05:31 -05002498}
2499
2500static int
2501lpfc_els_rcv_rscn(struct lpfc_hba * phba,
2502 struct lpfc_iocbq * cmdiocb,
2503 struct lpfc_nodelist * ndlp, uint8_t newnode)
2504{
2505 struct lpfc_dmabuf *pcmd;
2506 uint32_t *lp;
2507 IOCB_t *icmd;
2508 uint32_t payload_len, cmd;
James Smartd2873e42006-08-18 17:46:43 -04002509 int i;
dea31012005-04-17 16:05:31 -05002510
2511 icmd = &cmdiocb->iocb;
2512 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2513 lp = (uint32_t *) pcmd->virt;
2514
2515 cmd = *lp++;
2516 payload_len = be32_to_cpu(cmd) & 0xffff; /* payload length */
2517 payload_len -= sizeof (uint32_t); /* take off word 0 */
2518 cmd &= ELS_CMD_MASK;
2519
2520 /* RSCN received */
2521 lpfc_printf_log(phba,
2522 KERN_INFO,
2523 LOG_DISCOVERY,
2524 "%d:0214 RSCN received Data: x%x x%x x%x x%x\n",
2525 phba->brd_no,
2526 phba->fc_flag, payload_len, *lp, phba->fc_rscn_id_cnt);
2527
James Smartd2873e42006-08-18 17:46:43 -04002528 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
2529 fc_host_post_event(phba->host, fc_get_event_number(),
2530 FCH_EVT_RSCN, lp[i]);
2531
dea31012005-04-17 16:05:31 -05002532 /* If we are about to begin discovery, just ACC the RSCN.
2533 * Discovery processing will satisfy it.
2534 */
James Smart071fbd3d2006-04-15 11:53:20 -04002535 if (phba->hba_state <= LPFC_NS_QRY) {
dea31012005-04-17 16:05:31 -05002536 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL,
2537 newnode);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002538 return 0;
dea31012005-04-17 16:05:31 -05002539 }
2540
2541 /* If we are already processing an RSCN, save the received
2542 * RSCN payload buffer, cmdiocb->context2 to process later.
2543 */
2544 if (phba->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
2545 if ((phba->fc_rscn_id_cnt < FC_MAX_HOLD_RSCN) &&
2546 !(phba->fc_flag & FC_RSCN_DISCOVERY)) {
2547 spin_lock_irq(phba->host->host_lock);
2548 phba->fc_flag |= FC_RSCN_MODE;
2549 spin_unlock_irq(phba->host->host_lock);
2550 phba->fc_rscn_id_list[phba->fc_rscn_id_cnt++] = pcmd;
2551
2552 /* If we zero, cmdiocb->context2, the calling
2553 * routine will not try to free it.
2554 */
2555 cmdiocb->context2 = NULL;
2556
2557 /* Deferred RSCN */
2558 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
2559 "%d:0235 Deferred RSCN "
2560 "Data: x%x x%x x%x\n",
2561 phba->brd_no, phba->fc_rscn_id_cnt,
2562 phba->fc_flag, phba->hba_state);
2563 } else {
2564 spin_lock_irq(phba->host->host_lock);
2565 phba->fc_flag |= FC_RSCN_DISCOVERY;
2566 spin_unlock_irq(phba->host->host_lock);
2567 /* ReDiscovery RSCN */
2568 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
2569 "%d:0234 ReDiscovery RSCN "
2570 "Data: x%x x%x x%x\n",
2571 phba->brd_no, phba->fc_rscn_id_cnt,
2572 phba->fc_flag, phba->hba_state);
2573 }
2574 /* Send back ACC */
2575 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL,
2576 newnode);
2577
2578 /* send RECOVERY event for ALL nodes that match RSCN payload */
2579 lpfc_rscn_recovery_check(phba);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002580 return 0;
dea31012005-04-17 16:05:31 -05002581 }
2582
2583 phba->fc_flag |= FC_RSCN_MODE;
2584 phba->fc_rscn_id_list[phba->fc_rscn_id_cnt++] = pcmd;
2585 /*
2586 * If we zero, cmdiocb->context2, the calling routine will
2587 * not try to free it.
2588 */
2589 cmdiocb->context2 = NULL;
2590
2591 lpfc_set_disctmo(phba);
2592
2593 /* Send back ACC */
2594 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, newnode);
2595
2596 /* send RECOVERY event for ALL nodes that match RSCN payload */
2597 lpfc_rscn_recovery_check(phba);
2598
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002599 return lpfc_els_handle_rscn(phba);
dea31012005-04-17 16:05:31 -05002600}
2601
2602int
2603lpfc_els_handle_rscn(struct lpfc_hba * phba)
2604{
2605 struct lpfc_nodelist *ndlp;
2606
2607 /* Start timer for RSCN processing */
2608 lpfc_set_disctmo(phba);
2609
2610 /* RSCN processed */
2611 lpfc_printf_log(phba,
2612 KERN_INFO,
2613 LOG_DISCOVERY,
2614 "%d:0215 RSCN processed Data: x%x x%x x%x x%x\n",
2615 phba->brd_no,
2616 phba->fc_flag, 0, phba->fc_rscn_id_cnt,
2617 phba->hba_state);
2618
2619 /* To process RSCN, first compare RSCN data with NameServer */
2620 phba->fc_ns_retry = 0;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002621 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_UNMAPPED, NameServer_DID);
2622 if (ndlp) {
dea31012005-04-17 16:05:31 -05002623 /* Good ndlp, issue CT Request to NameServer */
2624 if (lpfc_ns_cmd(phba, ndlp, SLI_CTNS_GID_FT) == 0) {
2625 /* Wait for NameServer query cmpl before we can
2626 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002627 return 1;
dea31012005-04-17 16:05:31 -05002628 }
2629 } else {
2630 /* If login to NameServer does not exist, issue one */
2631 /* Good status, issue PLOGI to NameServer */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002632 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, NameServer_DID);
2633 if (ndlp) {
dea31012005-04-17 16:05:31 -05002634 /* Wait for NameServer login cmpl before we can
2635 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002636 return 1;
dea31012005-04-17 16:05:31 -05002637 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002638 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2639 if (!ndlp) {
dea31012005-04-17 16:05:31 -05002640 lpfc_els_flush_rscn(phba);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002641 return 0;
dea31012005-04-17 16:05:31 -05002642 } else {
2643 lpfc_nlp_init(phba, ndlp, NameServer_DID);
2644 ndlp->nlp_type |= NLP_FABRIC;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002645 ndlp->nlp_prev_state = ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05002646 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
James Smart488d1462006-03-07 15:02:37 -05002647 lpfc_issue_els_plogi(phba, NameServer_DID, 0);
dea31012005-04-17 16:05:31 -05002648 /* Wait for NameServer login cmpl before we can
2649 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002650 return 1;
dea31012005-04-17 16:05:31 -05002651 }
2652 }
2653
2654 lpfc_els_flush_rscn(phba);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002655 return 0;
dea31012005-04-17 16:05:31 -05002656}
2657
2658static int
2659lpfc_els_rcv_flogi(struct lpfc_hba * phba,
2660 struct lpfc_iocbq * cmdiocb,
2661 struct lpfc_nodelist * ndlp, uint8_t newnode)
2662{
2663 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2664 uint32_t *lp = (uint32_t *) pcmd->virt;
2665 IOCB_t *icmd = &cmdiocb->iocb;
2666 struct serv_parm *sp;
2667 LPFC_MBOXQ_t *mbox;
2668 struct ls_rjt stat;
2669 uint32_t cmd, did;
2670 int rc;
2671
2672 cmd = *lp++;
2673 sp = (struct serv_parm *) lp;
2674
2675 /* FLOGI received */
2676
2677 lpfc_set_disctmo(phba);
2678
2679 if (phba->fc_topology == TOPOLOGY_LOOP) {
2680 /* We should never receive a FLOGI in loop mode, ignore it */
2681 did = icmd->un.elsreq64.remoteID;
2682
2683 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
2684 Loop Mode */
2685 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
2686 "%d:0113 An FLOGI ELS command x%x was received "
2687 "from DID x%x in Loop Mode\n",
2688 phba->brd_no, cmd, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002689 return 1;
dea31012005-04-17 16:05:31 -05002690 }
2691
2692 did = Fabric_DID;
2693
2694 if ((lpfc_check_sparm(phba, ndlp, sp, CLASS3))) {
2695 /* For a FLOGI we accept, then if our portname is greater
2696 * then the remote portname we initiate Nport login.
2697 */
2698
2699 rc = memcmp(&phba->fc_portname, &sp->portName,
2700 sizeof (struct lpfc_name));
2701
2702 if (!rc) {
2703 if ((mbox = mempool_alloc(phba->mbox_mem_pool,
2704 GFP_KERNEL)) == 0) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002705 return 1;
dea31012005-04-17 16:05:31 -05002706 }
2707 lpfc_linkdown(phba);
2708 lpfc_init_link(phba, mbox,
2709 phba->cfg_topology,
2710 phba->cfg_link_speed);
2711 mbox->mb.un.varInitLnk.lipsr_AL_PA = 0;
2712 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
2713 rc = lpfc_sli_issue_mbox
2714 (phba, mbox, (MBX_NOWAIT | MBX_STOP_IOCB));
2715 if (rc == MBX_NOT_FINISHED) {
2716 mempool_free( mbox, phba->mbox_mem_pool);
2717 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002718 return 1;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002719 } else if (rc > 0) { /* greater than */
dea31012005-04-17 16:05:31 -05002720 spin_lock_irq(phba->host->host_lock);
2721 phba->fc_flag |= FC_PT2PT_PLOGI;
2722 spin_unlock_irq(phba->host->host_lock);
2723 }
2724 phba->fc_flag |= FC_PT2PT;
2725 phba->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
2726 } else {
2727 /* Reject this request because invalid parameters */
2728 stat.un.b.lsRjtRsvd0 = 0;
2729 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2730 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
2731 stat.un.b.vendorUnique = 0;
2732 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002733 return 1;
dea31012005-04-17 16:05:31 -05002734 }
2735
2736 /* Send back ACC */
2737 lpfc_els_rsp_acc(phba, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL, newnode);
2738
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002739 return 0;
dea31012005-04-17 16:05:31 -05002740}
2741
2742static int
2743lpfc_els_rcv_rnid(struct lpfc_hba * phba,
2744 struct lpfc_iocbq * cmdiocb, struct lpfc_nodelist * ndlp)
2745{
2746 struct lpfc_dmabuf *pcmd;
2747 uint32_t *lp;
2748 IOCB_t *icmd;
2749 RNID *rn;
2750 struct ls_rjt stat;
2751 uint32_t cmd, did;
2752
2753 icmd = &cmdiocb->iocb;
2754 did = icmd->un.elsreq64.remoteID;
2755 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2756 lp = (uint32_t *) pcmd->virt;
2757
2758 cmd = *lp++;
2759 rn = (RNID *) lp;
2760
2761 /* RNID received */
2762
2763 switch (rn->Format) {
2764 case 0:
2765 case RNID_TOPOLOGY_DISC:
2766 /* Send back ACC */
2767 lpfc_els_rsp_rnid_acc(phba, rn->Format, cmdiocb, ndlp);
2768 break;
2769 default:
2770 /* Reject this request because format not supported */
2771 stat.un.b.lsRjtRsvd0 = 0;
2772 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2773 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
2774 stat.un.b.vendorUnique = 0;
2775 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
2776 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002777 return 0;
dea31012005-04-17 16:05:31 -05002778}
2779
2780static int
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002781lpfc_els_rcv_lirr(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
2782 struct lpfc_nodelist * ndlp)
2783{
2784 struct ls_rjt stat;
2785
2786 /* For now, unconditionally reject this command */
2787 stat.un.b.lsRjtRsvd0 = 0;
2788 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2789 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
2790 stat.un.b.vendorUnique = 0;
2791 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
2792 return 0;
2793}
2794
Jamie Wellnitz082c0262006-02-28 19:25:30 -05002795static void
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002796lpfc_els_rsp_rps_acc(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
2797{
2798 struct lpfc_sli *psli;
2799 struct lpfc_sli_ring *pring;
2800 MAILBOX_t *mb;
2801 IOCB_t *icmd;
2802 RPS_RSP *rps_rsp;
2803 uint8_t *pcmd;
2804 struct lpfc_iocbq *elsiocb;
2805 struct lpfc_nodelist *ndlp;
2806 uint16_t xri, status;
2807 uint32_t cmdsize;
2808
2809 psli = &phba->sli;
2810 pring = &psli->ring[LPFC_ELS_RING];
2811 mb = &pmb->mb;
2812
2813 ndlp = (struct lpfc_nodelist *) pmb->context2;
2814 xri = (uint16_t) ((unsigned long)(pmb->context1));
Randy Dunlap041976f2006-06-25 01:58:51 -07002815 pmb->context1 = NULL;
2816 pmb->context2 = NULL;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002817
2818 if (mb->mbxStatus) {
2819 mempool_free( pmb, phba->mbox_mem_pool);
2820 return;
2821 }
2822
2823 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
2824 mempool_free( pmb, phba->mbox_mem_pool);
James Smart488d1462006-03-07 15:02:37 -05002825 elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, lpfc_max_els_tries, ndlp,
2826 ndlp->nlp_DID, ELS_CMD_ACC);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002827 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002828 return;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002829
2830 icmd = &elsiocb->iocb;
2831 icmd->ulpContext = xri;
2832
2833 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2834 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
2835 pcmd += sizeof (uint32_t); /* Skip past command */
2836 rps_rsp = (RPS_RSP *)pcmd;
2837
2838 if (phba->fc_topology != TOPOLOGY_LOOP)
2839 status = 0x10;
2840 else
2841 status = 0x8;
2842 if (phba->fc_flag & FC_FABRIC)
2843 status |= 0x4;
2844
2845 rps_rsp->rsvd1 = 0;
2846 rps_rsp->portStatus = be16_to_cpu(status);
2847 rps_rsp->linkFailureCnt = be32_to_cpu(mb->un.varRdLnk.linkFailureCnt);
2848 rps_rsp->lossSyncCnt = be32_to_cpu(mb->un.varRdLnk.lossSyncCnt);
2849 rps_rsp->lossSignalCnt = be32_to_cpu(mb->un.varRdLnk.lossSignalCnt);
2850 rps_rsp->primSeqErrCnt = be32_to_cpu(mb->un.varRdLnk.primSeqErrCnt);
2851 rps_rsp->invalidXmitWord = be32_to_cpu(mb->un.varRdLnk.invalidXmitWord);
2852 rps_rsp->crcCnt = be32_to_cpu(mb->un.varRdLnk.crcCnt);
2853
2854 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
2855 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
James Smartdca94792006-08-01 07:34:08 -04002856 "%d:0118 Xmit ELS RPS ACC response tag x%x "
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002857 "Data: x%x x%x x%x x%x x%x\n",
2858 phba->brd_no,
2859 elsiocb->iocb.ulpIoTag,
2860 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
2861 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
2862
2863 elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
2864 phba->fc_stat.elsXmitACC++;
2865 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
2866 lpfc_els_free_iocb(phba, elsiocb);
2867 }
2868 return;
2869}
2870
2871static int
2872lpfc_els_rcv_rps(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
2873 struct lpfc_nodelist * ndlp)
2874{
2875 uint32_t *lp;
2876 uint8_t flag;
2877 LPFC_MBOXQ_t *mbox;
2878 struct lpfc_dmabuf *pcmd;
2879 RPS *rps;
2880 struct ls_rjt stat;
2881
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002882 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
2883 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002884 stat.un.b.lsRjtRsvd0 = 0;
2885 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2886 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
2887 stat.un.b.vendorUnique = 0;
2888 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
2889 }
2890
2891 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2892 lp = (uint32_t *) pcmd->virt;
2893 flag = (be32_to_cpu(*lp++) & 0xf);
2894 rps = (RPS *) lp;
2895
2896 if ((flag == 0) ||
2897 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
2898 ((flag == 2) && (memcmp(&rps->un.portName, &phba->fc_portname,
2899 sizeof (struct lpfc_name)) == 0))) {
2900 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC))) {
2901 lpfc_read_lnk_stat(phba, mbox);
2902 mbox->context1 =
2903 (void *)((unsigned long)cmdiocb->iocb.ulpContext);
2904 mbox->context2 = ndlp;
2905 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
2906 if (lpfc_sli_issue_mbox (phba, mbox,
2907 (MBX_NOWAIT | MBX_STOP_IOCB)) != MBX_NOT_FINISHED) {
2908 /* Mbox completion will send ELS Response */
2909 return 0;
2910 }
2911 mempool_free(mbox, phba->mbox_mem_pool);
2912 }
2913 }
2914 stat.un.b.lsRjtRsvd0 = 0;
2915 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2916 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
2917 stat.un.b.vendorUnique = 0;
2918 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
2919 return 0;
2920}
2921
Jamie Wellnitz082c0262006-02-28 19:25:30 -05002922static int
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002923lpfc_els_rsp_rpl_acc(struct lpfc_hba * phba, uint16_t cmdsize,
2924 struct lpfc_iocbq * oldiocb, struct lpfc_nodelist * ndlp)
2925{
2926 IOCB_t *icmd;
2927 IOCB_t *oldcmd;
2928 RPL_RSP rpl_rsp;
2929 struct lpfc_iocbq *elsiocb;
2930 struct lpfc_sli_ring *pring;
2931 struct lpfc_sli *psli;
2932 uint8_t *pcmd;
2933
2934 psli = &phba->sli;
2935 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2936
James Smart488d1462006-03-07 15:02:37 -05002937 elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry,
2938 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
2939 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002940 return 1;
James Smart488d1462006-03-07 15:02:37 -05002941
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002942 icmd = &elsiocb->iocb;
2943 oldcmd = &oldiocb->iocb;
2944 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2945
2946 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2947 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
2948 pcmd += sizeof (uint16_t);
2949 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
2950 pcmd += sizeof(uint16_t);
2951
2952 /* Setup the RPL ACC payload */
2953 rpl_rsp.listLen = be32_to_cpu(1);
2954 rpl_rsp.index = 0;
2955 rpl_rsp.port_num_blk.portNum = 0;
2956 rpl_rsp.port_num_blk.portID = be32_to_cpu(phba->fc_myDID);
2957 memcpy(&rpl_rsp.port_num_blk.portName, &phba->fc_portname,
2958 sizeof(struct lpfc_name));
2959
2960 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
2961
2962
2963 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
2964 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
James Smartdca94792006-08-01 07:34:08 -04002965 "%d:0120 Xmit ELS RPL ACC response tag x%x "
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002966 "Data: x%x x%x x%x x%x x%x\n",
2967 phba->brd_no,
2968 elsiocb->iocb.ulpIoTag,
2969 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
2970 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
2971
2972 elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
2973
2974 phba->fc_stat.elsXmitACC++;
2975 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
2976 lpfc_els_free_iocb(phba, elsiocb);
2977 return 1;
2978 }
2979 return 0;
2980}
2981
2982static int
2983lpfc_els_rcv_rpl(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
dea31012005-04-17 16:05:31 -05002984 struct lpfc_nodelist * ndlp)
2985{
2986 struct lpfc_dmabuf *pcmd;
2987 uint32_t *lp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002988 uint32_t maxsize;
2989 uint16_t cmdsize;
2990 RPL *rpl;
2991 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05002992
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002993 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
2994 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002995 stat.un.b.lsRjtRsvd0 = 0;
2996 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2997 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
2998 stat.un.b.vendorUnique = 0;
2999 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05003000 }
3001
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003002 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3003 lp = (uint32_t *) pcmd->virt;
3004 rpl = (RPL *) (lp + 1);
3005
3006 maxsize = be32_to_cpu(rpl->maxsize);
3007
3008 /* We support only one port */
3009 if ((rpl->index == 0) &&
3010 ((maxsize == 0) ||
3011 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
3012 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003013 } else {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003014 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
3015 }
3016 lpfc_els_rsp_rpl_acc(phba, cmdsize, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05003017
3018 return 0;
3019}
3020
3021static int
3022lpfc_els_rcv_farp(struct lpfc_hba * phba,
3023 struct lpfc_iocbq * cmdiocb, struct lpfc_nodelist * ndlp)
3024{
3025 struct lpfc_dmabuf *pcmd;
3026 uint32_t *lp;
3027 IOCB_t *icmd;
3028 FARP *fp;
3029 uint32_t cmd, cnt, did;
3030
3031 icmd = &cmdiocb->iocb;
3032 did = icmd->un.elsreq64.remoteID;
3033 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3034 lp = (uint32_t *) pcmd->virt;
3035
3036 cmd = *lp++;
3037 fp = (FARP *) lp;
3038
3039 /* FARP-REQ received from DID <did> */
3040 lpfc_printf_log(phba,
3041 KERN_INFO,
3042 LOG_IP,
3043 "%d:0601 FARP-REQ received from DID x%x\n",
3044 phba->brd_no, did);
3045
3046 /* We will only support match on WWPN or WWNN */
3047 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003048 return 0;
dea31012005-04-17 16:05:31 -05003049 }
3050
3051 cnt = 0;
3052 /* If this FARP command is searching for my portname */
3053 if (fp->Mflags & FARP_MATCH_PORT) {
3054 if (memcmp(&fp->RportName, &phba->fc_portname,
3055 sizeof (struct lpfc_name)) == 0)
3056 cnt = 1;
3057 }
3058
3059 /* If this FARP command is searching for my nodename */
3060 if (fp->Mflags & FARP_MATCH_NODE) {
3061 if (memcmp(&fp->RnodeName, &phba->fc_nodename,
3062 sizeof (struct lpfc_name)) == 0)
3063 cnt = 1;
3064 }
3065
3066 if (cnt) {
3067 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
3068 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
3069 /* Log back into the node before sending the FARP. */
3070 if (fp->Rflags & FARP_REQUEST_PLOGI) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003071 ndlp->nlp_prev_state = ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05003072 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
3073 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
James Smart488d1462006-03-07 15:02:37 -05003074 lpfc_issue_els_plogi(phba, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05003075 }
3076
3077 /* Send a FARP response to that node */
3078 if (fp->Rflags & FARP_REQUEST_FARPR) {
3079 lpfc_issue_els_farpr(phba, did, 0);
3080 }
3081 }
3082 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003083 return 0;
dea31012005-04-17 16:05:31 -05003084}
3085
3086static int
3087lpfc_els_rcv_farpr(struct lpfc_hba * phba,
3088 struct lpfc_iocbq * cmdiocb, struct lpfc_nodelist * ndlp)
3089{
3090 struct lpfc_dmabuf *pcmd;
3091 uint32_t *lp;
3092 IOCB_t *icmd;
3093 uint32_t cmd, did;
3094
3095 icmd = &cmdiocb->iocb;
3096 did = icmd->un.elsreq64.remoteID;
3097 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3098 lp = (uint32_t *) pcmd->virt;
3099
3100 cmd = *lp++;
3101 /* FARP-RSP received from DID <did> */
3102 lpfc_printf_log(phba,
3103 KERN_INFO,
3104 LOG_IP,
3105 "%d:0600 FARP-RSP received from DID x%x\n",
3106 phba->brd_no, did);
3107
3108 /* ACCEPT the Farp resp request */
3109 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
3110
3111 return 0;
3112}
3113
3114static int
3115lpfc_els_rcv_fan(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003116 struct lpfc_nodelist * fan_ndlp)
dea31012005-04-17 16:05:31 -05003117{
3118 struct lpfc_dmabuf *pcmd;
3119 uint32_t *lp;
3120 IOCB_t *icmd;
dea31012005-04-17 16:05:31 -05003121 uint32_t cmd, did;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003122 FAN *fp;
3123 struct lpfc_nodelist *ndlp, *next_ndlp;
3124
3125 /* FAN received */
James Smartdca94792006-08-01 07:34:08 -04003126 lpfc_printf_log(phba, KERN_INFO, LOG_ELS, "%d:0265 FAN received\n",
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003127 phba->brd_no);
dea31012005-04-17 16:05:31 -05003128
3129 icmd = &cmdiocb->iocb;
3130 did = icmd->un.elsreq64.remoteID;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003131 pcmd = (struct lpfc_dmabuf *)cmdiocb->context2;
3132 lp = (uint32_t *)pcmd->virt;
dea31012005-04-17 16:05:31 -05003133
3134 cmd = *lp++;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003135 fp = (FAN *)lp;
dea31012005-04-17 16:05:31 -05003136
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003137 /* FAN received; Fan does not have a reply sequence */
dea31012005-04-17 16:05:31 -05003138
3139 if (phba->hba_state == LPFC_LOCAL_CFG_LINK) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003140 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
3141 sizeof(struct lpfc_name)) != 0) ||
3142 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
3143 sizeof(struct lpfc_name)) != 0)) {
3144 /*
3145 * This node has switched fabrics. FLOGI is required
3146 * Clean up the old rpi's
dea31012005-04-17 16:05:31 -05003147 */
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003148
3149 list_for_each_entry_safe(ndlp, next_ndlp,
3150 &phba->fc_npr_list, nlp_listp) {
3151
3152 if (ndlp->nlp_type & NLP_FABRIC) {
3153 /*
3154 * Clean up old Fabric, Nameserver and
3155 * other NLP_FABRIC logins
3156 */
3157 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003158 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003159 /* Fail outstanding I/O now since this
3160 * device is marked for PLOGI
3161 */
3162 lpfc_unreg_rpi(phba, ndlp);
3163 }
3164 }
3165
3166 phba->hba_state = LPFC_FLOGI;
3167 lpfc_set_disctmo(phba);
3168 lpfc_initial_flogi(phba);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003169 return 0;
dea31012005-04-17 16:05:31 -05003170 }
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003171 /* Discovery not needed,
3172 * move the nodes to their original state.
3173 */
3174 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
3175 nlp_listp) {
dea31012005-04-17 16:05:31 -05003176
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003177 switch (ndlp->nlp_prev_state) {
3178 case NLP_STE_UNMAPPED_NODE:
3179 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
3180 ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
3181 lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
3182 break;
3183
3184 case NLP_STE_MAPPED_NODE:
3185 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
3186 ndlp->nlp_state = NLP_STE_MAPPED_NODE;
3187 lpfc_nlp_list(phba, ndlp, NLP_MAPPED_LIST);
3188 break;
3189
3190 default:
3191 break;
3192 }
3193 }
3194
3195 /* Start discovery - this should just do CLEAR_LA */
dea31012005-04-17 16:05:31 -05003196 lpfc_disc_start(phba);
3197 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003198 return 0;
dea31012005-04-17 16:05:31 -05003199}
3200
3201void
3202lpfc_els_timeout(unsigned long ptr)
3203{
3204 struct lpfc_hba *phba;
3205 unsigned long iflag;
3206
3207 phba = (struct lpfc_hba *)ptr;
3208 if (phba == 0)
3209 return;
3210 spin_lock_irqsave(phba->host->host_lock, iflag);
3211 if (!(phba->work_hba_events & WORKER_ELS_TMO)) {
3212 phba->work_hba_events |= WORKER_ELS_TMO;
3213 if (phba->work_wait)
3214 wake_up(phba->work_wait);
3215 }
3216 spin_unlock_irqrestore(phba->host->host_lock, iflag);
3217 return;
3218}
3219
3220void
3221lpfc_els_timeout_handler(struct lpfc_hba *phba)
3222{
3223 struct lpfc_sli_ring *pring;
3224 struct lpfc_iocbq *tmp_iocb, *piocb;
3225 IOCB_t *cmd = NULL;
3226 struct lpfc_dmabuf *pcmd;
3227 struct list_head *dlp;
3228 uint32_t *elscmd;
3229 uint32_t els_command;
3230 uint32_t timeout;
3231 uint32_t remote_ID;
3232
3233 if (phba == 0)
3234 return;
3235 spin_lock_irq(phba->host->host_lock);
3236 /* If the timer is already canceled do nothing */
3237 if (!(phba->work_hba_events & WORKER_ELS_TMO)) {
3238 spin_unlock_irq(phba->host->host_lock);
3239 return;
3240 }
3241 timeout = (uint32_t)(phba->fc_ratov << 1);
3242
3243 pring = &phba->sli.ring[LPFC_ELS_RING];
3244 dlp = &pring->txcmplq;
3245
3246 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
3247 cmd = &piocb->iocb;
3248
3249 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
3250 continue;
3251 }
3252 pcmd = (struct lpfc_dmabuf *) piocb->context2;
3253 elscmd = (uint32_t *) (pcmd->virt);
3254 els_command = *elscmd;
3255
3256 if ((els_command == ELS_CMD_FARP)
3257 || (els_command == ELS_CMD_FARPR)) {
3258 continue;
3259 }
3260
3261 if (piocb->drvrTimeout > 0) {
3262 if (piocb->drvrTimeout >= timeout) {
3263 piocb->drvrTimeout -= timeout;
3264 } else {
3265 piocb->drvrTimeout = 0;
3266 }
3267 continue;
3268 }
3269
3270 list_del(&piocb->list);
3271 pring->txcmplq_cnt--;
3272
3273 if (cmd->ulpCommand == CMD_GEN_REQUEST64_CR) {
3274 struct lpfc_nodelist *ndlp;
Jamie Wellnitz66a9ed62006-02-28 22:33:10 -05003275 spin_unlock_irq(phba->host->host_lock);
dea31012005-04-17 16:05:31 -05003276 ndlp = lpfc_findnode_rpi(phba, cmd->ulpContext);
Jamie Wellnitz66a9ed62006-02-28 22:33:10 -05003277 spin_lock_irq(phba->host->host_lock);
dea31012005-04-17 16:05:31 -05003278 remote_ID = ndlp->nlp_DID;
3279 if (cmd->un.elsreq64.bdl.ulpIoTag32) {
3280 lpfc_sli_issue_abort_iotag32(phba,
3281 pring, piocb);
3282 }
3283 } else {
3284 remote_ID = cmd->un.elsreq64.remoteID;
3285 }
3286
3287 lpfc_printf_log(phba,
3288 KERN_ERR,
3289 LOG_ELS,
3290 "%d:0127 ELS timeout Data: x%x x%x x%x x%x\n",
3291 phba->brd_no, els_command,
3292 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
3293
3294 /*
3295 * The iocb has timed out; abort it.
3296 */
3297 if (piocb->iocb_cmpl) {
3298 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
3299 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
3300 spin_unlock_irq(phba->host->host_lock);
3301 (piocb->iocb_cmpl) (phba, piocb, piocb);
3302 spin_lock_irq(phba->host->host_lock);
James Bottomley604a3e32005-10-29 10:28:33 -05003303 } else
3304 lpfc_sli_release_iocbq(phba, piocb);
dea31012005-04-17 16:05:31 -05003305 }
James Smart5a0e3262006-07-06 15:49:16 -04003306 if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt)
3307 mod_timer(&phba->els_tmofunc, jiffies + HZ * timeout);
3308
dea31012005-04-17 16:05:31 -05003309 spin_unlock_irq(phba->host->host_lock);
3310}
3311
3312void
3313lpfc_els_flush_cmd(struct lpfc_hba * phba)
3314{
3315 struct lpfc_sli_ring *pring;
3316 struct lpfc_iocbq *tmp_iocb, *piocb;
3317 IOCB_t *cmd = NULL;
3318 struct lpfc_dmabuf *pcmd;
3319 uint32_t *elscmd;
3320 uint32_t els_command;
dea31012005-04-17 16:05:31 -05003321
3322 pring = &phba->sli.ring[LPFC_ELS_RING];
3323 spin_lock_irq(phba->host->host_lock);
3324 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
3325 cmd = &piocb->iocb;
3326
3327 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
3328 continue;
3329 }
3330
3331 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
3332 if ((cmd->ulpCommand == CMD_QUE_RING_BUF_CN) ||
3333 (cmd->ulpCommand == CMD_QUE_RING_BUF64_CN) ||
3334 (cmd->ulpCommand == CMD_CLOSE_XRI_CN) ||
3335 (cmd->ulpCommand == CMD_ABORT_XRI_CN)) {
3336 continue;
3337 }
3338
3339 pcmd = (struct lpfc_dmabuf *) piocb->context2;
3340 elscmd = (uint32_t *) (pcmd->virt);
3341 els_command = *elscmd;
3342
dea31012005-04-17 16:05:31 -05003343 list_del(&piocb->list);
3344 pring->txcmplq_cnt--;
3345
3346 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
3347 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
3348
3349 if (piocb->iocb_cmpl) {
3350 spin_unlock_irq(phba->host->host_lock);
3351 (piocb->iocb_cmpl) (phba, piocb, piocb);
3352 spin_lock_irq(phba->host->host_lock);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003353 } else
James Bottomley604a3e32005-10-29 10:28:33 -05003354 lpfc_sli_release_iocbq(phba, piocb);
dea31012005-04-17 16:05:31 -05003355 }
3356
3357 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
3358 cmd = &piocb->iocb;
3359
3360 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
3361 continue;
3362 }
3363 pcmd = (struct lpfc_dmabuf *) piocb->context2;
3364 elscmd = (uint32_t *) (pcmd->virt);
3365 els_command = *elscmd;
3366
dea31012005-04-17 16:05:31 -05003367 list_del(&piocb->list);
3368 pring->txcmplq_cnt--;
3369
3370 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
3371 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
3372
3373 if (piocb->iocb_cmpl) {
3374 spin_unlock_irq(phba->host->host_lock);
3375 (piocb->iocb_cmpl) (phba, piocb, piocb);
3376 spin_lock_irq(phba->host->host_lock);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003377 } else
James Bottomley604a3e32005-10-29 10:28:33 -05003378 lpfc_sli_release_iocbq(phba, piocb);
dea31012005-04-17 16:05:31 -05003379 }
3380 spin_unlock_irq(phba->host->host_lock);
3381 return;
3382}
3383
3384void
3385lpfc_els_unsol_event(struct lpfc_hba * phba,
3386 struct lpfc_sli_ring * pring, struct lpfc_iocbq * elsiocb)
3387{
3388 struct lpfc_sli *psli;
3389 struct lpfc_nodelist *ndlp;
3390 struct lpfc_dmabuf *mp;
3391 uint32_t *lp;
3392 IOCB_t *icmd;
3393 struct ls_rjt stat;
3394 uint32_t cmd;
3395 uint32_t did;
3396 uint32_t newnode;
3397 uint32_t drop_cmd = 0; /* by default do NOT drop received cmd */
3398 uint32_t rjt_err = 0;
3399
3400 psli = &phba->sli;
3401 icmd = &elsiocb->iocb;
3402
3403 if ((icmd->ulpStatus == IOSTAT_LOCAL_REJECT) &&
3404 ((icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING)) {
3405 /* Not enough posted buffers; Try posting more buffers */
3406 phba->fc_stat.NoRcvBuf++;
3407 lpfc_post_buffer(phba, pring, 0, 1);
3408 return;
3409 }
3410
3411 /* If there are no BDEs associated with this IOCB,
3412 * there is nothing to do.
3413 */
3414 if (icmd->ulpBdeCount == 0)
3415 return;
3416
3417 /* type of ELS cmd is first 32bit word in packet */
3418 mp = lpfc_sli_ringpostbuf_get(phba, pring, getPaddr(icmd->un.
3419 cont64[0].
3420 addrHigh,
3421 icmd->un.
3422 cont64[0].addrLow));
3423 if (mp == 0) {
3424 drop_cmd = 1;
3425 goto dropit;
3426 }
3427
3428 newnode = 0;
3429 lp = (uint32_t *) mp->virt;
3430 cmd = *lp++;
3431 lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], 1, 1);
3432
3433 if (icmd->ulpStatus) {
3434 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3435 kfree(mp);
3436 drop_cmd = 1;
3437 goto dropit;
3438 }
3439
3440 /* Check to see if link went down during discovery */
3441 if (lpfc_els_chk_latt(phba)) {
3442 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3443 kfree(mp);
3444 drop_cmd = 1;
3445 goto dropit;
3446 }
3447
3448 did = icmd->un.rcvels.remoteID;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003449 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, did);
3450 if (!ndlp) {
dea31012005-04-17 16:05:31 -05003451 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003452 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
3453 if (!ndlp) {
dea31012005-04-17 16:05:31 -05003454 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3455 kfree(mp);
3456 drop_cmd = 1;
3457 goto dropit;
3458 }
3459
3460 lpfc_nlp_init(phba, ndlp, did);
3461 newnode = 1;
3462 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) {
3463 ndlp->nlp_type |= NLP_FABRIC;
3464 }
James Smart92795652006-07-06 15:50:02 -04003465 ndlp->nlp_state = NLP_STE_UNUSED_NODE;
3466 lpfc_nlp_list(phba, ndlp, NLP_UNUSED_LIST);
dea31012005-04-17 16:05:31 -05003467 }
3468
3469 phba->fc_stat.elsRcvFrame++;
3470 elsiocb->context1 = ndlp;
3471 elsiocb->context2 = mp;
3472
3473 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
3474 cmd &= ELS_CMD_MASK;
3475 }
3476 /* ELS command <elsCmd> received from NPORT <did> */
3477 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
3478 "%d:0112 ELS command x%x received from NPORT x%x "
3479 "Data: x%x\n", phba->brd_no, cmd, did, phba->hba_state);
3480
3481 switch (cmd) {
3482 case ELS_CMD_PLOGI:
3483 phba->fc_stat.elsRcvPLOGI++;
3484 if (phba->hba_state < LPFC_DISC_AUTH) {
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04003485 rjt_err = 1;
dea31012005-04-17 16:05:31 -05003486 break;
3487 }
James Smart92795652006-07-06 15:50:02 -04003488 ndlp = lpfc_plogi_confirm_nport(phba, mp, ndlp);
dea31012005-04-17 16:05:31 -05003489 lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_PLOGI);
3490 break;
3491 case ELS_CMD_FLOGI:
3492 phba->fc_stat.elsRcvFLOGI++;
3493 lpfc_els_rcv_flogi(phba, elsiocb, ndlp, newnode);
3494 if (newnode) {
James Smart92795652006-07-06 15:50:02 -04003495 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
dea31012005-04-17 16:05:31 -05003496 }
3497 break;
3498 case ELS_CMD_LOGO:
3499 phba->fc_stat.elsRcvLOGO++;
3500 if (phba->hba_state < LPFC_DISC_AUTH) {
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04003501 rjt_err = 1;
dea31012005-04-17 16:05:31 -05003502 break;
3503 }
3504 lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
3505 break;
3506 case ELS_CMD_PRLO:
3507 phba->fc_stat.elsRcvPRLO++;
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_PRLO);
3513 break;
3514 case ELS_CMD_RSCN:
3515 phba->fc_stat.elsRcvRSCN++;
3516 lpfc_els_rcv_rscn(phba, elsiocb, ndlp, newnode);
3517 if (newnode) {
James Smart92795652006-07-06 15:50:02 -04003518 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
dea31012005-04-17 16:05:31 -05003519 }
3520 break;
3521 case ELS_CMD_ADISC:
3522 phba->fc_stat.elsRcvADISC++;
3523 if (phba->hba_state < LPFC_DISC_AUTH) {
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04003524 rjt_err = 1;
dea31012005-04-17 16:05:31 -05003525 break;
3526 }
3527 lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_ADISC);
3528 break;
3529 case ELS_CMD_PDISC:
3530 phba->fc_stat.elsRcvPDISC++;
3531 if (phba->hba_state < LPFC_DISC_AUTH) {
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04003532 rjt_err = 1;
dea31012005-04-17 16:05:31 -05003533 break;
3534 }
3535 lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_PDISC);
3536 break;
3537 case ELS_CMD_FARPR:
3538 phba->fc_stat.elsRcvFARPR++;
3539 lpfc_els_rcv_farpr(phba, elsiocb, ndlp);
3540 break;
3541 case ELS_CMD_FARP:
3542 phba->fc_stat.elsRcvFARP++;
3543 lpfc_els_rcv_farp(phba, elsiocb, ndlp);
3544 break;
3545 case ELS_CMD_FAN:
3546 phba->fc_stat.elsRcvFAN++;
3547 lpfc_els_rcv_fan(phba, elsiocb, ndlp);
3548 break;
dea31012005-04-17 16:05:31 -05003549 case ELS_CMD_PRLI:
3550 phba->fc_stat.elsRcvPRLI++;
3551 if (phba->hba_state < LPFC_DISC_AUTH) {
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04003552 rjt_err = 1;
dea31012005-04-17 16:05:31 -05003553 break;
3554 }
3555 lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
3556 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003557 case ELS_CMD_LIRR:
3558 phba->fc_stat.elsRcvLIRR++;
3559 lpfc_els_rcv_lirr(phba, elsiocb, ndlp);
3560 if (newnode) {
James Smart92795652006-07-06 15:50:02 -04003561 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003562 }
3563 break;
3564 case ELS_CMD_RPS:
3565 phba->fc_stat.elsRcvRPS++;
3566 lpfc_els_rcv_rps(phba, elsiocb, ndlp);
3567 if (newnode) {
James Smart92795652006-07-06 15:50:02 -04003568 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003569 }
3570 break;
3571 case ELS_CMD_RPL:
3572 phba->fc_stat.elsRcvRPL++;
3573 lpfc_els_rcv_rpl(phba, elsiocb, ndlp);
3574 if (newnode) {
James Smart92795652006-07-06 15:50:02 -04003575 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003576 }
3577 break;
dea31012005-04-17 16:05:31 -05003578 case ELS_CMD_RNID:
3579 phba->fc_stat.elsRcvRNID++;
3580 lpfc_els_rcv_rnid(phba, elsiocb, ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003581 if (newnode) {
James Smart92795652006-07-06 15:50:02 -04003582 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003583 }
dea31012005-04-17 16:05:31 -05003584 break;
3585 default:
3586 /* Unsupported ELS command, reject */
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04003587 rjt_err = 1;
dea31012005-04-17 16:05:31 -05003588
3589 /* Unknown ELS command <elsCmd> received from NPORT <did> */
3590 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
3591 "%d:0115 Unknown ELS command x%x received from "
3592 "NPORT x%x\n", phba->brd_no, cmd, did);
3593 if (newnode) {
James Smart92795652006-07-06 15:50:02 -04003594 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
dea31012005-04-17 16:05:31 -05003595 }
3596 break;
3597 }
3598
3599 /* check if need to LS_RJT received ELS cmd */
3600 if (rjt_err) {
3601 stat.un.b.lsRjtRsvd0 = 0;
3602 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04003603 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -05003604 stat.un.b.vendorUnique = 0;
3605 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, elsiocb, ndlp);
3606 }
3607
3608 if (elsiocb->context2) {
3609 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3610 kfree(mp);
3611 }
3612dropit:
3613 /* check if need to drop received ELS cmd */
3614 if (drop_cmd == 1) {
3615 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
3616 "%d:0111 Dropping received ELS cmd "
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003617 "Data: x%x x%x x%x\n", phba->brd_no,
3618 icmd->ulpStatus, icmd->un.ulpWord[4],
3619 icmd->ulpTimeout);
dea31012005-04-17 16:05:31 -05003620 phba->fc_stat.elsRcvDrop++;
3621 }
3622 return;
3623}