blob: 090f4609d2af636f3eeae6c7b62f7a87f165311c [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 *
100lpfc_prep_els_iocb(struct lpfc_hba * phba,
101 uint8_t expectRsp,
102 uint16_t cmdSize,
103 uint8_t retry, struct lpfc_nodelist * ndlp, uint32_t elscmd)
104{
dea31012005-04-17 16:05:31 -0500105 struct lpfc_sli_ring *pring;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400106 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -0500107 struct lpfc_dmabuf *pcmd, *prsp, *pbuflist;
108 struct ulp_bde64 *bpl;
109 IOCB_t *icmd;
110
111 pring = &phba->sli.ring[LPFC_ELS_RING];
112
113 if (phba->hba_state < LPFC_LINK_UP)
114 return NULL;
115
dea31012005-04-17 16:05:31 -0500116 /* Allocate buffer for command iocb */
117 spin_lock_irq(phba->host->host_lock);
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400118 elsiocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -0500119 spin_unlock_irq(phba->host->host_lock);
120
121 if (elsiocb == NULL)
122 return NULL;
dea31012005-04-17 16:05:31 -0500123 icmd = &elsiocb->iocb;
124
125 /* fill in BDEs for command */
126 /* Allocate buffer for command payload */
127 if (((pcmd = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL)) == 0) ||
128 ((pcmd->virt = lpfc_mbuf_alloc(phba,
129 MEM_PRI, &(pcmd->phys))) == 0)) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -0800130 kfree(pcmd);
dea31012005-04-17 16:05:31 -0500131
James Bottomley604a3e32005-10-29 10:28:33 -0500132 spin_lock_irq(phba->host->host_lock);
133 lpfc_sli_release_iocbq(phba, elsiocb);
134 spin_unlock_irq(phba->host->host_lock);
dea31012005-04-17 16:05:31 -0500135 return NULL;
136 }
137
138 INIT_LIST_HEAD(&pcmd->list);
139
140 /* Allocate buffer for response payload */
141 if (expectRsp) {
142 prsp = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
143 if (prsp)
144 prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
145 &prsp->phys);
146 if (prsp == 0 || prsp->virt == 0) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -0800147 kfree(prsp);
dea31012005-04-17 16:05:31 -0500148 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
149 kfree(pcmd);
James Bottomley604a3e32005-10-29 10:28:33 -0500150 spin_lock_irq(phba->host->host_lock);
151 lpfc_sli_release_iocbq(phba, elsiocb);
152 spin_unlock_irq(phba->host->host_lock);
dea31012005-04-17 16:05:31 -0500153 return NULL;
154 }
155 INIT_LIST_HEAD(&prsp->list);
156 } else {
157 prsp = NULL;
158 }
159
160 /* Allocate buffer for Buffer ptr list */
161 pbuflist = kmalloc(sizeof (struct lpfc_dmabuf), GFP_KERNEL);
162 if (pbuflist)
163 pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
164 &pbuflist->phys);
165 if (pbuflist == 0 || pbuflist->virt == 0) {
James Bottomley604a3e32005-10-29 10:28:33 -0500166 spin_lock_irq(phba->host->host_lock);
167 lpfc_sli_release_iocbq(phba, elsiocb);
168 spin_unlock_irq(phba->host->host_lock);
dea31012005-04-17 16:05:31 -0500169 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
170 lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
171 kfree(pcmd);
172 kfree(prsp);
Jesper Juhlc9475cb2005-11-07 01:01:26 -0800173 kfree(pbuflist);
dea31012005-04-17 16:05:31 -0500174 return NULL;
175 }
176
177 INIT_LIST_HEAD(&pbuflist->list);
178
179 icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
180 icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
181 icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BDL;
182 if (expectRsp) {
183 icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof (struct ulp_bde64));
184 icmd->un.elsreq64.remoteID = ndlp->nlp_DID; /* DID */
185 icmd->ulpCommand = CMD_ELS_REQUEST64_CR;
186 } else {
187 icmd->un.elsreq64.bdl.bdeSize = sizeof (struct ulp_bde64);
188 icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
189 }
190
191 icmd->ulpBdeCount = 1;
192 icmd->ulpLe = 1;
193 icmd->ulpClass = CLASS3;
194
195 bpl = (struct ulp_bde64 *) pbuflist->virt;
196 bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys));
197 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys));
198 bpl->tus.f.bdeSize = cmdSize;
199 bpl->tus.f.bdeFlags = 0;
200 bpl->tus.w = le32_to_cpu(bpl->tus.w);
201
202 if (expectRsp) {
203 bpl++;
204 bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys));
205 bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys));
206 bpl->tus.f.bdeSize = FCELSSIZE;
207 bpl->tus.f.bdeFlags = BUFF_USE_RCV;
208 bpl->tus.w = le32_to_cpu(bpl->tus.w);
209 }
210
211 /* Save for completion so we can release these resources */
212 elsiocb->context1 = (uint8_t *) ndlp;
213 elsiocb->context2 = (uint8_t *) pcmd;
214 elsiocb->context3 = (uint8_t *) pbuflist;
215 elsiocb->retry = retry;
216 elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
217
218 if (prsp) {
219 list_add(&prsp->list, &pcmd->list);
220 }
221
222 if (expectRsp) {
223 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
224 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
225 "%d:0116 Xmit ELS command x%x to remote "
226 "NPORT x%x Data: x%x x%x\n",
227 phba->brd_no, elscmd,
228 ndlp->nlp_DID, icmd->ulpIoTag, phba->hba_state);
229 } else {
230 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
231 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
232 "%d:0117 Xmit ELS response x%x to remote "
233 "NPORT x%x Data: x%x x%x\n",
234 phba->brd_no, elscmd,
235 ndlp->nlp_DID, icmd->ulpIoTag, cmdSize);
236 }
237
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500238 return elsiocb;
dea31012005-04-17 16:05:31 -0500239}
240
241
242static int
243lpfc_cmpl_els_flogi_fabric(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
244 struct serv_parm *sp, IOCB_t *irsp)
245{
246 LPFC_MBOXQ_t *mbox;
247 int rc;
248
249 spin_lock_irq(phba->host->host_lock);
250 phba->fc_flag |= FC_FABRIC;
251 spin_unlock_irq(phba->host->host_lock);
252
253 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
254 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
255 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
256
257 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
258
259 if (phba->fc_topology == TOPOLOGY_LOOP) {
260 spin_lock_irq(phba->host->host_lock);
261 phba->fc_flag |= FC_PUBLIC_LOOP;
262 spin_unlock_irq(phba->host->host_lock);
263 } else {
264 /*
265 * If we are a N-port connected to a Fabric, fixup sparam's so
266 * logins to devices on remote loops work.
267 */
268 phba->fc_sparam.cmn.altBbCredit = 1;
269 }
270
271 phba->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
272 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
273 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof (struct lpfc_name));
274 ndlp->nlp_class_sup = 0;
275 if (sp->cls1.classValid)
276 ndlp->nlp_class_sup |= FC_COS_CLASS1;
277 if (sp->cls2.classValid)
278 ndlp->nlp_class_sup |= FC_COS_CLASS2;
279 if (sp->cls3.classValid)
280 ndlp->nlp_class_sup |= FC_COS_CLASS3;
281 if (sp->cls4.classValid)
282 ndlp->nlp_class_sup |= FC_COS_CLASS4;
283 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
284 sp->cmn.bbRcvSizeLsb;
285 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
286
287 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
288 if (!mbox)
289 goto fail;
290
291 phba->hba_state = LPFC_FABRIC_CFG_LINK;
292 lpfc_config_link(phba, mbox);
293 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
294
295 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT | MBX_STOP_IOCB);
296 if (rc == MBX_NOT_FINISHED)
297 goto fail_free_mbox;
298
299 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
300 if (!mbox)
301 goto fail;
302
303 if (lpfc_reg_login(phba, Fabric_DID, (uint8_t *) sp, mbox, 0))
304 goto fail_free_mbox;
305
306 /*
307 * set_slim mailbox command needs to execute first,
308 * queue this command to be processed later.
309 */
310 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
311 mbox->context2 = ndlp;
312
313 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT | MBX_STOP_IOCB);
314 if (rc == MBX_NOT_FINISHED)
315 goto fail_free_mbox;
316
317 return 0;
318
319 fail_free_mbox:
320 mempool_free(mbox, phba->mbox_mem_pool);
321 fail:
322 return -ENXIO;
323}
324
325/*
326 * We FLOGIed into an NPort, initiate pt2pt protocol
327 */
328static int
329lpfc_cmpl_els_flogi_nport(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp,
330 struct serv_parm *sp)
331{
332 LPFC_MBOXQ_t *mbox;
333 int rc;
334
335 spin_lock_irq(phba->host->host_lock);
336 phba->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
337 spin_unlock_irq(phba->host->host_lock);
338
339 phba->fc_edtov = FF_DEF_EDTOV;
340 phba->fc_ratov = FF_DEF_RATOV;
341 rc = memcmp(&phba->fc_portname, &sp->portName,
342 sizeof(struct lpfc_name));
343 if (rc >= 0) {
344 /* This side will initiate the PLOGI */
345 spin_lock_irq(phba->host->host_lock);
346 phba->fc_flag |= FC_PT2PT_PLOGI;
347 spin_unlock_irq(phba->host->host_lock);
348
349 /*
350 * N_Port ID cannot be 0, set our to LocalID the other
351 * side will be RemoteID.
352 */
353
354 /* not equal */
355 if (rc)
356 phba->fc_myDID = PT2PT_LocalID;
357
358 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
359 if (!mbox)
360 goto fail;
361
362 lpfc_config_link(phba, mbox);
363
364 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
365 rc = lpfc_sli_issue_mbox(phba, mbox,
366 MBX_NOWAIT | MBX_STOP_IOCB);
367 if (rc == MBX_NOT_FINISHED) {
368 mempool_free(mbox, phba->mbox_mem_pool);
369 goto fail;
370 }
371 mempool_free(ndlp, phba->nlp_mem_pool);
372
373 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, PT2PT_RemoteID);
374 if (!ndlp) {
375 /*
376 * Cannot find existing Fabric ndlp, so allocate a
377 * new one
378 */
379 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
380 if (!ndlp)
381 goto fail;
382
383 lpfc_nlp_init(phba, ndlp, PT2PT_RemoteID);
384 }
385
386 memcpy(&ndlp->nlp_portname, &sp->portName,
387 sizeof(struct lpfc_name));
388 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
389 sizeof(struct lpfc_name));
390 ndlp->nlp_state = NLP_STE_NPR_NODE;
391 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
392 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
393 } else {
394 /* This side will wait for the PLOGI */
395 mempool_free( ndlp, phba->nlp_mem_pool);
396 }
397
398 spin_lock_irq(phba->host->host_lock);
399 phba->fc_flag |= FC_PT2PT;
400 spin_unlock_irq(phba->host->host_lock);
401
402 /* Start discovery - this should just do CLEAR_LA */
403 lpfc_disc_start(phba);
404 return 0;
405 fail:
406 return -ENXIO;
407}
408
409static void
410lpfc_cmpl_els_flogi(struct lpfc_hba * phba,
411 struct lpfc_iocbq * cmdiocb, struct lpfc_iocbq * rspiocb)
412{
413 IOCB_t *irsp = &rspiocb->iocb;
414 struct lpfc_nodelist *ndlp = cmdiocb->context1;
415 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
416 struct serv_parm *sp;
417 int rc;
418
419 /* Check to see if link went down during discovery */
420 if (lpfc_els_chk_latt(phba)) {
421 lpfc_nlp_remove(phba, ndlp);
422 goto out;
423 }
424
425 if (irsp->ulpStatus) {
426 /* Check for retry */
427 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
428 /* ELS command is being retried */
429 goto out;
430 }
431 /* FLOGI failed, so there is no fabric */
432 spin_lock_irq(phba->host->host_lock);
433 phba->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
434 spin_unlock_irq(phba->host->host_lock);
435
436 /* If private loop, then allow max outstandting els to be
437 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
438 * alpa map would take too long otherwise.
439 */
440 if (phba->alpa_map[0] == 0) {
441 phba->cfg_discovery_threads =
442 LPFC_MAX_DISC_THREADS;
443 }
444
445 /* FLOGI failure */
446 lpfc_printf_log(phba,
447 KERN_INFO,
448 LOG_ELS,
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500449 "%d:0100 FLOGI failure Data: x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -0500450 phba->brd_no,
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500451 irsp->ulpStatus, irsp->un.ulpWord[4],
452 irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -0500453 goto flogifail;
454 }
455
456 /*
457 * The FLogI succeeded. Sync the data for the CPU before
458 * accessing it.
459 */
460 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
461
462 sp = prsp->virt + sizeof(uint32_t);
463
464 /* FLOGI completes successfully */
465 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
466 "%d:0101 FLOGI completes sucessfully "
467 "Data: x%x x%x x%x x%x\n",
468 phba->brd_no,
469 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
470 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution);
471
472 if (phba->hba_state == LPFC_FLOGI) {
473 /*
474 * If Common Service Parameters indicate Nport
475 * we are point to point, if Fport we are Fabric.
476 */
477 if (sp->cmn.fPort)
478 rc = lpfc_cmpl_els_flogi_fabric(phba, ndlp, sp, irsp);
479 else
480 rc = lpfc_cmpl_els_flogi_nport(phba, ndlp, sp);
481
482 if (!rc)
483 goto out;
484 }
485
486flogifail:
487 lpfc_nlp_remove(phba, ndlp);
488
489 if (irsp->ulpStatus != IOSTAT_LOCAL_REJECT ||
490 (irsp->un.ulpWord[4] != IOERR_SLI_ABORTED &&
491 irsp->un.ulpWord[4] != IOERR_SLI_DOWN)) {
492 /* FLOGI failed, so just use loop map to make discovery list */
493 lpfc_disc_list_loopmap(phba);
494
495 /* Start discovery */
496 lpfc_disc_start(phba);
497 }
498
499out:
500 lpfc_els_free_iocb(phba, cmdiocb);
501}
502
503static int
504lpfc_issue_els_flogi(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
505 uint8_t retry)
506{
507 struct serv_parm *sp;
508 IOCB_t *icmd;
509 struct lpfc_iocbq *elsiocb;
510 struct lpfc_sli_ring *pring;
511 uint8_t *pcmd;
512 uint16_t cmdsize;
513 uint32_t tmo;
514 int rc;
515
516 pring = &phba->sli.ring[LPFC_ELS_RING];
517
518 cmdsize = (sizeof (uint32_t) + sizeof (struct serv_parm));
519 if ((elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry,
520 ndlp, ELS_CMD_FLOGI)) == 0) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500521 return 1;
dea31012005-04-17 16:05:31 -0500522 }
523
524 icmd = &elsiocb->iocb;
525 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
526
527 /* For FLOGI request, remainder of payload is service parameters */
528 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
529 pcmd += sizeof (uint32_t);
530 memcpy(pcmd, &phba->fc_sparam, sizeof (struct serv_parm));
531 sp = (struct serv_parm *) pcmd;
532
533 /* Setup CSPs accordingly for Fabric */
534 sp->cmn.e_d_tov = 0;
535 sp->cmn.w2.r_a_tov = 0;
536 sp->cls1.classValid = 0;
537 sp->cls2.seqDelivery = 1;
538 sp->cls3.seqDelivery = 1;
539 if (sp->cmn.fcphLow < FC_PH3)
540 sp->cmn.fcphLow = FC_PH3;
541 if (sp->cmn.fcphHigh < FC_PH3)
542 sp->cmn.fcphHigh = FC_PH3;
543
544 tmo = phba->fc_ratov;
545 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
546 lpfc_set_disctmo(phba);
547 phba->fc_ratov = tmo;
548
549 phba->fc_stat.elsXmitFLOGI++;
550 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
551 spin_lock_irq(phba->host->host_lock);
552 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
553 spin_unlock_irq(phba->host->host_lock);
554 if (rc == IOCB_ERROR) {
555 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500556 return 1;
dea31012005-04-17 16:05:31 -0500557 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500558 return 0;
dea31012005-04-17 16:05:31 -0500559}
560
561int
562lpfc_els_abort_flogi(struct lpfc_hba * phba)
563{
564 struct lpfc_sli_ring *pring;
565 struct lpfc_iocbq *iocb, *next_iocb;
566 struct lpfc_nodelist *ndlp;
567 IOCB_t *icmd;
568
569 /* Abort outstanding I/O on NPort <nlp_DID> */
570 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
571 "%d:0201 Abort outstanding I/O on NPort x%x\n",
572 phba->brd_no, Fabric_DID);
573
574 pring = &phba->sli.ring[LPFC_ELS_RING];
575
576 /*
577 * Check the txcmplq for an iocb that matches the nport the driver is
578 * searching for.
579 */
580 spin_lock_irq(phba->host->host_lock);
581 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
582 icmd = &iocb->iocb;
583 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR) {
584 ndlp = (struct lpfc_nodelist *)(iocb->context1);
585 if (ndlp && (ndlp->nlp_DID == Fabric_DID)) {
586 list_del(&iocb->list);
587 pring->txcmplq_cnt--;
588
589 if ((icmd->un.elsreq64.bdl.ulpIoTag32)) {
590 lpfc_sli_issue_abort_iotag32
591 (phba, pring, iocb);
592 }
593 if (iocb->iocb_cmpl) {
594 icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
595 icmd->un.ulpWord[4] =
596 IOERR_SLI_ABORTED;
597 spin_unlock_irq(phba->host->host_lock);
598 (iocb->iocb_cmpl) (phba, iocb, iocb);
599 spin_lock_irq(phba->host->host_lock);
James Bottomley604a3e32005-10-29 10:28:33 -0500600 } else
601 lpfc_sli_release_iocbq(phba, iocb);
dea31012005-04-17 16:05:31 -0500602 }
603 }
604 }
605 spin_unlock_irq(phba->host->host_lock);
606
607 return 0;
608}
609
610int
611lpfc_initial_flogi(struct lpfc_hba * phba)
612{
613 struct lpfc_nodelist *ndlp;
614
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500615 /* First look for the Fabric ndlp */
616 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, Fabric_DID);
617 if (!ndlp) {
dea31012005-04-17 16:05:31 -0500618 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500619 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
620 if (!ndlp)
621 return 0;
dea31012005-04-17 16:05:31 -0500622 lpfc_nlp_init(phba, ndlp, Fabric_DID);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500623 } else {
624 lpfc_nlp_list(phba, ndlp, NLP_JUST_DQ);
dea31012005-04-17 16:05:31 -0500625 }
626 if (lpfc_issue_els_flogi(phba, ndlp, 0)) {
627 mempool_free( ndlp, phba->nlp_mem_pool);
628 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500629 return 1;
dea31012005-04-17 16:05:31 -0500630}
631
632static void
633lpfc_more_plogi(struct lpfc_hba * phba)
634{
635 int sentplogi;
636
637 if (phba->num_disc_nodes)
638 phba->num_disc_nodes--;
639
640 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
641 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
642 "%d:0232 Continue discovery with %d PLOGIs to go "
643 "Data: x%x x%x x%x\n",
644 phba->brd_no, phba->num_disc_nodes, phba->fc_plogi_cnt,
645 phba->fc_flag, phba->hba_state);
646
647 /* Check to see if there are more PLOGIs to be sent */
648 if (phba->fc_flag & FC_NLP_MORE) {
649 /* go thru NPR list and issue any remaining ELS PLOGIs */
650 sentplogi = lpfc_els_disc_plogi(phba);
651 }
652 return;
653}
654
655static void
656lpfc_cmpl_els_plogi(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
657 struct lpfc_iocbq * rspiocb)
658{
659 IOCB_t *irsp;
660 struct lpfc_sli *psli;
661 struct lpfc_nodelist *ndlp;
662 int disc, rc, did, type;
663
664 psli = &phba->sli;
665
666 /* we pass cmdiocb to state machine which needs rspiocb as well */
667 cmdiocb->context_un.rsp_iocb = rspiocb;
668
669 irsp = &rspiocb->iocb;
670 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
dea31012005-04-17 16:05:31 -0500671
672 /* Since ndlp can be freed in the disc state machine, note if this node
673 * is being used during discovery.
674 */
675 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500676 spin_lock_irq(phba->host->host_lock);
677 ndlp->nlp_flag &= ~(NLP_PLOGI_SND | NLP_NPR_2B_DISC);
678 spin_unlock_irq(phba->host->host_lock);
dea31012005-04-17 16:05:31 -0500679 rc = 0;
680
681 /* PLOGI completes to NPort <nlp_DID> */
682 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
683 "%d:0102 PLOGI completes to NPort x%x "
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500684 "Data: x%x x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -0500685 phba->brd_no, ndlp->nlp_DID, irsp->ulpStatus,
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500686 irsp->un.ulpWord[4], irsp->ulpTimeout, disc,
687 phba->num_disc_nodes);
dea31012005-04-17 16:05:31 -0500688
689 /* Check to see if link went down during discovery */
690 if (lpfc_els_chk_latt(phba)) {
691 spin_lock_irq(phba->host->host_lock);
692 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
693 spin_unlock_irq(phba->host->host_lock);
694 goto out;
695 }
696
697 /* ndlp could be freed in DSM, save these values now */
698 type = ndlp->nlp_type;
699 did = ndlp->nlp_DID;
700
701 if (irsp->ulpStatus) {
702 /* Check for retry */
703 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
704 /* ELS command is being retried */
705 if (disc) {
706 spin_lock_irq(phba->host->host_lock);
707 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
708 spin_unlock_irq(phba->host->host_lock);
709 }
710 goto out;
711 }
712
713 /* PLOGI failed */
714 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
715 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
716 ((irsp->un.ulpWord[4] == IOERR_SLI_ABORTED) ||
James.Smart@Emulex.Com6281bfe2005-11-28 11:41:33 -0500717 (irsp->un.ulpWord[4] == IOERR_LINK_DOWN) ||
dea31012005-04-17 16:05:31 -0500718 (irsp->un.ulpWord[4] == IOERR_SLI_DOWN))) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500719 rc = NLP_STE_FREED_NODE;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500720 } else {
dea31012005-04-17 16:05:31 -0500721 rc = lpfc_disc_state_machine(phba, ndlp, cmdiocb,
722 NLP_EVT_CMPL_PLOGI);
723 }
724 } else {
725 /* Good status, call state machine */
726 rc = lpfc_disc_state_machine(phba, ndlp, cmdiocb,
727 NLP_EVT_CMPL_PLOGI);
728 }
729
730 if (type & NLP_FABRIC) {
731 /* If we cannot login to Nameserver, kick off discovery now */
732 if ((did == NameServer_DID) && (rc == NLP_STE_FREED_NODE)) {
733 lpfc_disc_start(phba);
734 }
735 goto out;
736 }
737
738 if (disc && phba->num_disc_nodes) {
739 /* Check to see if there are more PLOGIs to be sent */
740 lpfc_more_plogi(phba);
741 }
742
dea31012005-04-17 16:05:31 -0500743 if (phba->num_disc_nodes == 0) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500744 spin_lock_irq(phba->host->host_lock);
745 phba->fc_flag &= ~FC_NDISC_ACTIVE;
746 spin_unlock_irq(phba->host->host_lock);
747
dea31012005-04-17 16:05:31 -0500748 lpfc_can_disctmo(phba);
749 if (phba->fc_flag & FC_RSCN_MODE) {
750 /* Check to see if more RSCNs came in while we were
751 * processing this one.
752 */
753 if ((phba->fc_rscn_id_cnt == 0) &&
754 (!(phba->fc_flag & FC_RSCN_DISCOVERY))) {
755 spin_lock_irq(phba->host->host_lock);
756 phba->fc_flag &= ~FC_RSCN_MODE;
757 spin_unlock_irq(phba->host->host_lock);
758 } else {
759 lpfc_els_handle_rscn(phba);
760 }
761 }
762 }
763
764out:
765 lpfc_els_free_iocb(phba, cmdiocb);
766 return;
767}
768
769int
770lpfc_issue_els_plogi(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
771 uint8_t retry)
772{
773 struct serv_parm *sp;
774 IOCB_t *icmd;
775 struct lpfc_iocbq *elsiocb;
776 struct lpfc_sli_ring *pring;
777 struct lpfc_sli *psli;
778 uint8_t *pcmd;
779 uint16_t cmdsize;
780
781 psli = &phba->sli;
782 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
783
784 cmdsize = (sizeof (uint32_t) + sizeof (struct serv_parm));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500785 elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry, ndlp,
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500786 ELS_CMD_PLOGI);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500787 if (!elsiocb)
788 return 1;
dea31012005-04-17 16:05:31 -0500789
790 icmd = &elsiocb->iocb;
791 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
792
793 /* For PLOGI request, remainder of payload is service parameters */
794 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
795 pcmd += sizeof (uint32_t);
796 memcpy(pcmd, &phba->fc_sparam, sizeof (struct serv_parm));
797 sp = (struct serv_parm *) pcmd;
798
799 if (sp->cmn.fcphLow < FC_PH_4_3)
800 sp->cmn.fcphLow = FC_PH_4_3;
801
802 if (sp->cmn.fcphHigh < FC_PH3)
803 sp->cmn.fcphHigh = FC_PH3;
804
805 phba->fc_stat.elsXmitPLOGI++;
806 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
807 spin_lock_irq(phba->host->host_lock);
808 ndlp->nlp_flag |= NLP_PLOGI_SND;
809 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
810 ndlp->nlp_flag &= ~NLP_PLOGI_SND;
811 spin_unlock_irq(phba->host->host_lock);
812 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500813 return 1;
dea31012005-04-17 16:05:31 -0500814 }
815 spin_unlock_irq(phba->host->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500816 return 0;
dea31012005-04-17 16:05:31 -0500817}
818
819static void
820lpfc_cmpl_els_prli(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
821 struct lpfc_iocbq * rspiocb)
822{
823 IOCB_t *irsp;
824 struct lpfc_sli *psli;
825 struct lpfc_nodelist *ndlp;
826
827 psli = &phba->sli;
828 /* we pass cmdiocb to state machine which needs rspiocb as well */
829 cmdiocb->context_un.rsp_iocb = rspiocb;
830
831 irsp = &(rspiocb->iocb);
832 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
833 spin_lock_irq(phba->host->host_lock);
834 ndlp->nlp_flag &= ~NLP_PRLI_SND;
835 spin_unlock_irq(phba->host->host_lock);
836
837 /* PRLI completes to NPort <nlp_DID> */
838 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
839 "%d:0103 PRLI completes to NPort x%x "
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500840 "Data: x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -0500841 phba->brd_no, ndlp->nlp_DID, irsp->ulpStatus,
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500842 irsp->un.ulpWord[4], irsp->ulpTimeout,
843 phba->num_disc_nodes);
dea31012005-04-17 16:05:31 -0500844
845 phba->fc_prli_sent--;
846 /* Check to see if link went down during discovery */
847 if (lpfc_els_chk_latt(phba))
848 goto out;
849
850 if (irsp->ulpStatus) {
851 /* Check for retry */
852 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
853 /* ELS command is being retried */
854 goto out;
855 }
856 /* PRLI failed */
857 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
858 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
859 ((irsp->un.ulpWord[4] == IOERR_SLI_ABORTED) ||
James.Smart@Emulex.Com6281bfe2005-11-28 11:41:33 -0500860 (irsp->un.ulpWord[4] == IOERR_LINK_DOWN) ||
dea31012005-04-17 16:05:31 -0500861 (irsp->un.ulpWord[4] == IOERR_SLI_DOWN))) {
862 goto out;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500863 } else {
dea31012005-04-17 16:05:31 -0500864 lpfc_disc_state_machine(phba, ndlp, cmdiocb,
865 NLP_EVT_CMPL_PRLI);
866 }
867 } else {
868 /* Good status, call state machine */
869 lpfc_disc_state_machine(phba, ndlp, cmdiocb, NLP_EVT_CMPL_PRLI);
870 }
871
872out:
873 lpfc_els_free_iocb(phba, cmdiocb);
874 return;
875}
876
877int
878lpfc_issue_els_prli(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
879 uint8_t retry)
880{
881 PRLI *npr;
882 IOCB_t *icmd;
883 struct lpfc_iocbq *elsiocb;
884 struct lpfc_sli_ring *pring;
885 struct lpfc_sli *psli;
886 uint8_t *pcmd;
887 uint16_t cmdsize;
888
889 psli = &phba->sli;
890 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
891
892 cmdsize = (sizeof (uint32_t) + sizeof (PRLI));
893 if ((elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry,
894 ndlp, ELS_CMD_PRLI)) == 0) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500895 return 1;
dea31012005-04-17 16:05:31 -0500896 }
897
898 icmd = &elsiocb->iocb;
899 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
900
901 /* For PRLI request, remainder of payload is service parameters */
902 memset(pcmd, 0, (sizeof (PRLI) + sizeof (uint32_t)));
903 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
904 pcmd += sizeof (uint32_t);
905
906 /* For PRLI, remainder of payload is PRLI parameter page */
907 npr = (PRLI *) pcmd;
908 /*
909 * If our firmware version is 3.20 or later,
910 * set the following bits for FC-TAPE support.
911 */
912 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
913 npr->ConfmComplAllowed = 1;
914 npr->Retry = 1;
915 npr->TaskRetryIdReq = 1;
916 }
917 npr->estabImagePair = 1;
918 npr->readXferRdyDis = 1;
919
920 /* For FCP support */
921 npr->prliType = PRLI_FCP_TYPE;
922 npr->initiatorFunc = 1;
923
924 phba->fc_stat.elsXmitPRLI++;
925 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
926 spin_lock_irq(phba->host->host_lock);
927 ndlp->nlp_flag |= NLP_PRLI_SND;
928 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
929 ndlp->nlp_flag &= ~NLP_PRLI_SND;
930 spin_unlock_irq(phba->host->host_lock);
931 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500932 return 1;
dea31012005-04-17 16:05:31 -0500933 }
934 spin_unlock_irq(phba->host->host_lock);
935 phba->fc_prli_sent++;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500936 return 0;
dea31012005-04-17 16:05:31 -0500937}
938
939static void
940lpfc_more_adisc(struct lpfc_hba * phba)
941{
942 int sentadisc;
943
944 if (phba->num_disc_nodes)
945 phba->num_disc_nodes--;
946
947 /* Continue discovery with <num_disc_nodes> ADISCs to go */
948 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
949 "%d:0210 Continue discovery with %d ADISCs to go "
950 "Data: x%x x%x x%x\n",
951 phba->brd_no, phba->num_disc_nodes, phba->fc_adisc_cnt,
952 phba->fc_flag, phba->hba_state);
953
954 /* Check to see if there are more ADISCs to be sent */
955 if (phba->fc_flag & FC_NLP_MORE) {
956 lpfc_set_disctmo(phba);
957
958 /* go thru NPR list and issue any remaining ELS ADISCs */
959 sentadisc = lpfc_els_disc_adisc(phba);
960 }
961 return;
962}
963
964static void
965lpfc_rscn_disc(struct lpfc_hba * phba)
966{
967 /* RSCN discovery */
968 /* go thru NPR list and issue ELS PLOGIs */
969 if (phba->fc_npr_cnt) {
970 if (lpfc_els_disc_plogi(phba))
971 return;
972 }
973 if (phba->fc_flag & FC_RSCN_MODE) {
974 /* Check to see if more RSCNs came in while we were
975 * processing this one.
976 */
977 if ((phba->fc_rscn_id_cnt == 0) &&
978 (!(phba->fc_flag & FC_RSCN_DISCOVERY))) {
979 spin_lock_irq(phba->host->host_lock);
980 phba->fc_flag &= ~FC_RSCN_MODE;
981 spin_unlock_irq(phba->host->host_lock);
982 } else {
983 lpfc_els_handle_rscn(phba);
984 }
985 }
986}
987
988static void
989lpfc_cmpl_els_adisc(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
990 struct lpfc_iocbq * rspiocb)
991{
992 IOCB_t *irsp;
993 struct lpfc_sli *psli;
994 struct lpfc_nodelist *ndlp;
995 LPFC_MBOXQ_t *mbox;
996 int disc, rc;
997
998 psli = &phba->sli;
999
1000 /* we pass cmdiocb to state machine which needs rspiocb as well */
1001 cmdiocb->context_un.rsp_iocb = rspiocb;
1002
1003 irsp = &(rspiocb->iocb);
1004 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
dea31012005-04-17 16:05:31 -05001005
1006 /* Since ndlp can be freed in the disc state machine, note if this node
1007 * is being used during discovery.
1008 */
1009 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001010 spin_lock_irq(phba->host->host_lock);
1011 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
1012 spin_unlock_irq(phba->host->host_lock);
dea31012005-04-17 16:05:31 -05001013
1014 /* ADISC completes to NPort <nlp_DID> */
1015 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1016 "%d:0104 ADISC completes to NPort x%x "
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001017 "Data: x%x x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -05001018 phba->brd_no, ndlp->nlp_DID, irsp->ulpStatus,
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001019 irsp->un.ulpWord[4], irsp->ulpTimeout, disc,
1020 phba->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001021
1022 /* Check to see if link went down during discovery */
1023 if (lpfc_els_chk_latt(phba)) {
1024 spin_lock_irq(phba->host->host_lock);
1025 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1026 spin_unlock_irq(phba->host->host_lock);
1027 goto out;
1028 }
1029
1030 if (irsp->ulpStatus) {
1031 /* Check for retry */
1032 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1033 /* ELS command is being retried */
1034 if (disc) {
1035 spin_lock_irq(phba->host->host_lock);
1036 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1037 spin_unlock_irq(phba->host->host_lock);
1038 lpfc_set_disctmo(phba);
1039 }
1040 goto out;
1041 }
1042 /* ADISC failed */
1043 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001044 if ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
1045 ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) &&
1046 (irsp->un.ulpWord[4] != IOERR_LINK_DOWN) &&
1047 (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) {
dea31012005-04-17 16:05:31 -05001048 lpfc_disc_state_machine(phba, ndlp, cmdiocb,
1049 NLP_EVT_CMPL_ADISC);
1050 }
1051 } else {
1052 /* Good status, call state machine */
1053 lpfc_disc_state_machine(phba, ndlp, cmdiocb,
1054 NLP_EVT_CMPL_ADISC);
1055 }
1056
1057 if (disc && phba->num_disc_nodes) {
1058 /* Check to see if there are more ADISCs to be sent */
1059 lpfc_more_adisc(phba);
1060
1061 /* Check to see if we are done with ADISC authentication */
1062 if (phba->num_disc_nodes == 0) {
1063 lpfc_can_disctmo(phba);
1064 /* If we get here, there is nothing left to wait for */
1065 if ((phba->hba_state < LPFC_HBA_READY) &&
1066 (phba->hba_state != LPFC_CLEAR_LA)) {
1067 /* Link up discovery */
1068 if ((mbox = mempool_alloc(phba->mbox_mem_pool,
1069 GFP_KERNEL))) {
1070 phba->hba_state = LPFC_CLEAR_LA;
1071 lpfc_clear_la(phba, mbox);
1072 mbox->mbox_cmpl =
1073 lpfc_mbx_cmpl_clear_la;
1074 rc = lpfc_sli_issue_mbox
1075 (phba, mbox,
1076 (MBX_NOWAIT | MBX_STOP_IOCB));
1077 if (rc == MBX_NOT_FINISHED) {
1078 mempool_free(mbox,
1079 phba->mbox_mem_pool);
1080 lpfc_disc_flush_list(phba);
1081 psli->ring[(psli->ip_ring)].
1082 flag &=
1083 ~LPFC_STOP_IOCB_EVENT;
1084 psli->ring[(psli->fcp_ring)].
1085 flag &=
1086 ~LPFC_STOP_IOCB_EVENT;
1087 psli->ring[(psli->next_ring)].
1088 flag &=
1089 ~LPFC_STOP_IOCB_EVENT;
1090 phba->hba_state =
1091 LPFC_HBA_READY;
1092 }
1093 }
1094 } else {
1095 lpfc_rscn_disc(phba);
1096 }
1097 }
1098 }
dea31012005-04-17 16:05:31 -05001099out:
1100 lpfc_els_free_iocb(phba, cmdiocb);
1101 return;
1102}
1103
1104int
1105lpfc_issue_els_adisc(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
1106 uint8_t retry)
1107{
1108 ADISC *ap;
1109 IOCB_t *icmd;
1110 struct lpfc_iocbq *elsiocb;
1111 struct lpfc_sli_ring *pring;
1112 struct lpfc_sli *psli;
1113 uint8_t *pcmd;
1114 uint16_t cmdsize;
1115
1116 psli = &phba->sli;
1117 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1118
1119 cmdsize = (sizeof (uint32_t) + sizeof (ADISC));
1120 if ((elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry,
1121 ndlp, ELS_CMD_ADISC)) == 0) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001122 return 1;
dea31012005-04-17 16:05:31 -05001123 }
1124
1125 icmd = &elsiocb->iocb;
1126 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1127
1128 /* For ADISC request, remainder of payload is service parameters */
1129 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
1130 pcmd += sizeof (uint32_t);
1131
1132 /* Fill in ADISC payload */
1133 ap = (ADISC *) pcmd;
1134 ap->hardAL_PA = phba->fc_pref_ALPA;
1135 memcpy(&ap->portName, &phba->fc_portname, sizeof (struct lpfc_name));
1136 memcpy(&ap->nodeName, &phba->fc_nodename, sizeof (struct lpfc_name));
1137 ap->DID = be32_to_cpu(phba->fc_myDID);
1138
1139 phba->fc_stat.elsXmitADISC++;
1140 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
1141 spin_lock_irq(phba->host->host_lock);
1142 ndlp->nlp_flag |= NLP_ADISC_SND;
1143 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
1144 ndlp->nlp_flag &= ~NLP_ADISC_SND;
1145 spin_unlock_irq(phba->host->host_lock);
1146 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001147 return 1;
dea31012005-04-17 16:05:31 -05001148 }
1149 spin_unlock_irq(phba->host->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001150 return 0;
dea31012005-04-17 16:05:31 -05001151}
1152
1153static void
1154lpfc_cmpl_els_logo(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
1155 struct lpfc_iocbq * rspiocb)
1156{
1157 IOCB_t *irsp;
1158 struct lpfc_sli *psli;
1159 struct lpfc_nodelist *ndlp;
1160
1161 psli = &phba->sli;
1162 /* we pass cmdiocb to state machine which needs rspiocb as well */
1163 cmdiocb->context_un.rsp_iocb = rspiocb;
1164
1165 irsp = &(rspiocb->iocb);
1166 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1167 spin_lock_irq(phba->host->host_lock);
1168 ndlp->nlp_flag &= ~NLP_LOGO_SND;
1169 spin_unlock_irq(phba->host->host_lock);
1170
1171 /* LOGO completes to NPort <nlp_DID> */
1172 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1173 "%d:0105 LOGO completes to NPort x%x "
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001174 "Data: x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -05001175 phba->brd_no, ndlp->nlp_DID, irsp->ulpStatus,
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001176 irsp->un.ulpWord[4], irsp->ulpTimeout,
1177 phba->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001178
1179 /* Check to see if link went down during discovery */
1180 if (lpfc_els_chk_latt(phba))
1181 goto out;
1182
1183 if (irsp->ulpStatus) {
1184 /* Check for retry */
1185 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1186 /* ELS command is being retried */
1187 goto out;
1188 }
1189 /* LOGO failed */
1190 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
1191 if ((irsp->ulpStatus == IOSTAT_LOCAL_REJECT) &&
1192 ((irsp->un.ulpWord[4] == IOERR_SLI_ABORTED) ||
James.Smart@Emulex.Com6281bfe2005-11-28 11:41:33 -05001193 (irsp->un.ulpWord[4] == IOERR_LINK_DOWN) ||
dea31012005-04-17 16:05:31 -05001194 (irsp->un.ulpWord[4] == IOERR_SLI_DOWN))) {
1195 goto out;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001196 } else {
dea31012005-04-17 16:05:31 -05001197 lpfc_disc_state_machine(phba, ndlp, cmdiocb,
1198 NLP_EVT_CMPL_LOGO);
1199 }
1200 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001201 /* Good status, call state machine.
1202 * This will unregister the rpi if needed.
1203 */
dea31012005-04-17 16:05:31 -05001204 lpfc_disc_state_machine(phba, ndlp, cmdiocb, NLP_EVT_CMPL_LOGO);
dea31012005-04-17 16:05:31 -05001205 }
1206
1207out:
1208 lpfc_els_free_iocb(phba, cmdiocb);
1209 return;
1210}
1211
1212int
1213lpfc_issue_els_logo(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
1214 uint8_t retry)
1215{
1216 IOCB_t *icmd;
1217 struct lpfc_iocbq *elsiocb;
1218 struct lpfc_sli_ring *pring;
1219 struct lpfc_sli *psli;
1220 uint8_t *pcmd;
1221 uint16_t cmdsize;
1222
1223 psli = &phba->sli;
1224 pring = &psli->ring[LPFC_ELS_RING];
1225
1226 cmdsize = 2 * (sizeof (uint32_t) + sizeof (struct lpfc_name));
1227 if ((elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry,
1228 ndlp, ELS_CMD_LOGO)) == 0) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001229 return 1;
dea31012005-04-17 16:05:31 -05001230 }
1231
1232 icmd = &elsiocb->iocb;
1233 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1234 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
1235 pcmd += sizeof (uint32_t);
1236
1237 /* Fill in LOGO payload */
1238 *((uint32_t *) (pcmd)) = be32_to_cpu(phba->fc_myDID);
1239 pcmd += sizeof (uint32_t);
1240 memcpy(pcmd, &phba->fc_portname, sizeof (struct lpfc_name));
1241
1242 phba->fc_stat.elsXmitLOGO++;
1243 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
1244 spin_lock_irq(phba->host->host_lock);
1245 ndlp->nlp_flag |= NLP_LOGO_SND;
1246 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
1247 ndlp->nlp_flag &= ~NLP_LOGO_SND;
1248 spin_unlock_irq(phba->host->host_lock);
1249 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001250 return 1;
dea31012005-04-17 16:05:31 -05001251 }
1252 spin_unlock_irq(phba->host->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001253 return 0;
dea31012005-04-17 16:05:31 -05001254}
1255
1256static void
1257lpfc_cmpl_els_cmd(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
1258 struct lpfc_iocbq * rspiocb)
1259{
1260 IOCB_t *irsp;
1261
1262 irsp = &rspiocb->iocb;
1263
1264 /* ELS cmd tag <ulpIoTag> completes */
1265 lpfc_printf_log(phba,
1266 KERN_INFO,
1267 LOG_ELS,
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001268 "%d:0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -05001269 phba->brd_no,
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001270 irsp->ulpIoTag, irsp->ulpStatus,
1271 irsp->un.ulpWord[4], irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -05001272
1273 /* Check to see if link went down during discovery */
1274 lpfc_els_chk_latt(phba);
1275 lpfc_els_free_iocb(phba, cmdiocb);
1276 return;
1277}
1278
1279int
1280lpfc_issue_els_scr(struct lpfc_hba * phba, uint32_t nportid, uint8_t retry)
1281{
1282 IOCB_t *icmd;
1283 struct lpfc_iocbq *elsiocb;
1284 struct lpfc_sli_ring *pring;
1285 struct lpfc_sli *psli;
1286 uint8_t *pcmd;
1287 uint16_t cmdsize;
1288 struct lpfc_nodelist *ndlp;
1289
1290 psli = &phba->sli;
1291 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1292 cmdsize = (sizeof (uint32_t) + sizeof (SCR));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001293 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1294 if (!ndlp)
1295 return 1;
dea31012005-04-17 16:05:31 -05001296
1297 lpfc_nlp_init(phba, ndlp, nportid);
1298
1299 if ((elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry,
1300 ndlp, ELS_CMD_SCR)) == 0) {
1301 mempool_free( ndlp, phba->nlp_mem_pool);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001302 return 1;
dea31012005-04-17 16:05:31 -05001303 }
1304
1305 icmd = &elsiocb->iocb;
1306 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1307
1308 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
1309 pcmd += sizeof (uint32_t);
1310
1311 /* For SCR, remainder of payload is SCR parameter page */
1312 memset(pcmd, 0, sizeof (SCR));
1313 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
1314
1315 phba->fc_stat.elsXmitSCR++;
1316 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
1317 spin_lock_irq(phba->host->host_lock);
1318 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
1319 spin_unlock_irq(phba->host->host_lock);
1320 mempool_free( ndlp, phba->nlp_mem_pool);
1321 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001322 return 1;
dea31012005-04-17 16:05:31 -05001323 }
1324 spin_unlock_irq(phba->host->host_lock);
1325 mempool_free( ndlp, phba->nlp_mem_pool);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001326 return 0;
dea31012005-04-17 16:05:31 -05001327}
1328
1329static int
1330lpfc_issue_els_farpr(struct lpfc_hba * phba, uint32_t nportid, uint8_t retry)
1331{
1332 IOCB_t *icmd;
1333 struct lpfc_iocbq *elsiocb;
1334 struct lpfc_sli_ring *pring;
1335 struct lpfc_sli *psli;
1336 FARP *fp;
1337 uint8_t *pcmd;
1338 uint32_t *lp;
1339 uint16_t cmdsize;
1340 struct lpfc_nodelist *ondlp;
1341 struct lpfc_nodelist *ndlp;
1342
1343 psli = &phba->sli;
1344 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1345 cmdsize = (sizeof (uint32_t) + sizeof (FARP));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001346 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1347 if (!ndlp)
1348 return 1;
dea31012005-04-17 16:05:31 -05001349 lpfc_nlp_init(phba, ndlp, nportid);
1350
1351 if ((elsiocb = lpfc_prep_els_iocb(phba, 1, cmdsize, retry,
1352 ndlp, ELS_CMD_RNID)) == 0) {
1353 mempool_free( ndlp, phba->nlp_mem_pool);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001354 return 1;
dea31012005-04-17 16:05:31 -05001355 }
1356
1357 icmd = &elsiocb->iocb;
1358 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1359
1360 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
1361 pcmd += sizeof (uint32_t);
1362
1363 /* Fill in FARPR payload */
1364 fp = (FARP *) (pcmd);
1365 memset(fp, 0, sizeof (FARP));
1366 lp = (uint32_t *) pcmd;
1367 *lp++ = be32_to_cpu(nportid);
1368 *lp++ = be32_to_cpu(phba->fc_myDID);
1369 fp->Rflags = 0;
1370 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
1371
1372 memcpy(&fp->RportName, &phba->fc_portname, sizeof (struct lpfc_name));
1373 memcpy(&fp->RnodeName, &phba->fc_nodename, sizeof (struct lpfc_name));
1374 if ((ondlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, nportid))) {
1375 memcpy(&fp->OportName, &ondlp->nlp_portname,
1376 sizeof (struct lpfc_name));
1377 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
1378 sizeof (struct lpfc_name));
1379 }
1380
1381 phba->fc_stat.elsXmitFARPR++;
1382 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
1383 spin_lock_irq(phba->host->host_lock);
1384 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
1385 spin_unlock_irq(phba->host->host_lock);
1386 mempool_free( ndlp, phba->nlp_mem_pool);
1387 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001388 return 1;
dea31012005-04-17 16:05:31 -05001389 }
1390 spin_unlock_irq(phba->host->host_lock);
1391 mempool_free( ndlp, phba->nlp_mem_pool);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001392 return 0;
dea31012005-04-17 16:05:31 -05001393}
1394
1395void
1396lpfc_els_retry_delay(unsigned long ptr)
1397{
1398 struct lpfc_nodelist *ndlp;
1399 struct lpfc_hba *phba;
1400 unsigned long iflag;
1401 struct lpfc_work_evt *evtp;
1402
1403 ndlp = (struct lpfc_nodelist *)ptr;
1404 phba = ndlp->nlp_phba;
1405 evtp = &ndlp->els_retry_evt;
1406
1407 spin_lock_irqsave(phba->host->host_lock, iflag);
1408 if (!list_empty(&evtp->evt_listp)) {
1409 spin_unlock_irqrestore(phba->host->host_lock, iflag);
1410 return;
1411 }
1412
1413 evtp->evt_arg1 = ndlp;
1414 evtp->evt = LPFC_EVT_ELS_RETRY;
1415 list_add_tail(&evtp->evt_listp, &phba->work_list);
1416 if (phba->work_wait)
1417 wake_up(phba->work_wait);
1418
1419 spin_unlock_irqrestore(phba->host->host_lock, iflag);
1420 return;
1421}
1422
1423void
1424lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
1425{
1426 struct lpfc_hba *phba;
1427 uint32_t cmd;
1428 uint32_t did;
1429 uint8_t retry;
1430
1431 phba = ndlp->nlp_phba;
1432 spin_lock_irq(phba->host->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001433 did = ndlp->nlp_DID;
1434 cmd = ndlp->nlp_last_elscmd;
1435 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05001436
1437 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
1438 spin_unlock_irq(phba->host->host_lock);
1439 return;
1440 }
1441
1442 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
1443 spin_unlock_irq(phba->host->host_lock);
1444 retry = ndlp->nlp_retry;
1445
1446 switch (cmd) {
1447 case ELS_CMD_FLOGI:
1448 lpfc_issue_els_flogi(phba, ndlp, retry);
1449 break;
1450 case ELS_CMD_PLOGI:
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05001451 if (!lpfc_issue_els_plogi(phba, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001452 ndlp->nlp_prev_state = ndlp->nlp_state;
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05001453 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
1454 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
1455 }
dea31012005-04-17 16:05:31 -05001456 break;
1457 case ELS_CMD_ADISC:
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05001458 if (!lpfc_issue_els_adisc(phba, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001459 ndlp->nlp_prev_state = ndlp->nlp_state;
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05001460 ndlp->nlp_state = NLP_STE_ADISC_ISSUE;
1461 lpfc_nlp_list(phba, ndlp, NLP_ADISC_LIST);
1462 }
dea31012005-04-17 16:05:31 -05001463 break;
1464 case ELS_CMD_PRLI:
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05001465 if (!lpfc_issue_els_prli(phba, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001466 ndlp->nlp_prev_state = ndlp->nlp_state;
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05001467 ndlp->nlp_state = NLP_STE_PRLI_ISSUE;
1468 lpfc_nlp_list(phba, ndlp, NLP_PRLI_LIST);
1469 }
dea31012005-04-17 16:05:31 -05001470 break;
1471 case ELS_CMD_LOGO:
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05001472 if (!lpfc_issue_els_logo(phba, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001473 ndlp->nlp_prev_state = ndlp->nlp_state;
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05001474 ndlp->nlp_state = NLP_STE_NPR_NODE;
1475 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1476 }
dea31012005-04-17 16:05:31 -05001477 break;
1478 }
1479 return;
1480}
1481
1482static int
1483lpfc_els_retry(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
1484 struct lpfc_iocbq * rspiocb)
1485{
1486 IOCB_t *irsp;
1487 struct lpfc_dmabuf *pcmd;
1488 struct lpfc_nodelist *ndlp;
1489 uint32_t *elscmd;
1490 struct ls_rjt stat;
1491 int retry, maxretry;
1492 int delay;
1493 uint32_t cmd;
1494
1495 retry = 0;
1496 delay = 0;
1497 maxretry = lpfc_max_els_tries;
1498 irsp = &rspiocb->iocb;
1499 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1500 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
1501 cmd = 0;
1502 /* Note: context2 may be 0 for internal driver abort
1503 * of delays ELS command.
1504 */
1505
1506 if (pcmd && pcmd->virt) {
1507 elscmd = (uint32_t *) (pcmd->virt);
1508 cmd = *elscmd++;
1509 }
1510
1511 switch (irsp->ulpStatus) {
1512 case IOSTAT_FCP_RSP_ERROR:
1513 case IOSTAT_REMOTE_STOP:
1514 break;
1515
1516 case IOSTAT_LOCAL_REJECT:
1517 switch ((irsp->un.ulpWord[4] & 0xff)) {
1518 case IOERR_LOOP_OPEN_FAILURE:
1519 if (cmd == ELS_CMD_PLOGI) {
1520 if (cmdiocb->retry == 0) {
1521 delay = 1;
1522 }
1523 }
1524 retry = 1;
1525 break;
1526
1527 case IOERR_SEQUENCE_TIMEOUT:
1528 retry = 1;
dea31012005-04-17 16:05:31 -05001529 break;
1530
1531 case IOERR_NO_RESOURCES:
1532 if (cmd == ELS_CMD_PLOGI) {
1533 delay = 1;
1534 }
1535 retry = 1;
1536 break;
1537
1538 case IOERR_INVALID_RPI:
1539 retry = 1;
1540 break;
1541 }
1542 break;
1543
1544 case IOSTAT_NPORT_RJT:
1545 case IOSTAT_FABRIC_RJT:
1546 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
1547 retry = 1;
1548 break;
1549 }
1550 break;
1551
1552 case IOSTAT_NPORT_BSY:
1553 case IOSTAT_FABRIC_BSY:
1554 retry = 1;
1555 break;
1556
1557 case IOSTAT_LS_RJT:
1558 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
1559 /* Added for Vendor specifc support
1560 * Just keep retrying for these Rsn / Exp codes
1561 */
1562 switch (stat.un.b.lsRjtRsnCode) {
1563 case LSRJT_UNABLE_TPC:
1564 if (stat.un.b.lsRjtRsnCodeExp ==
1565 LSEXP_CMD_IN_PROGRESS) {
1566 if (cmd == ELS_CMD_PLOGI) {
1567 delay = 1;
1568 maxretry = 48;
1569 }
1570 retry = 1;
1571 break;
1572 }
1573 if (cmd == ELS_CMD_PLOGI) {
1574 delay = 1;
1575 maxretry = lpfc_max_els_tries + 1;
1576 retry = 1;
1577 break;
1578 }
1579 break;
1580
1581 case LSRJT_LOGICAL_BSY:
1582 if (cmd == ELS_CMD_PLOGI) {
1583 delay = 1;
1584 maxretry = 48;
1585 }
1586 retry = 1;
1587 break;
1588 }
1589 break;
1590
1591 case IOSTAT_INTERMED_RSP:
1592 case IOSTAT_BA_RJT:
1593 break;
1594
1595 default:
1596 break;
1597 }
1598
1599 if (ndlp->nlp_DID == FDMI_DID) {
1600 retry = 1;
1601 }
1602
1603 if ((++cmdiocb->retry) >= maxretry) {
1604 phba->fc_stat.elsRetryExceeded++;
1605 retry = 0;
1606 }
1607
1608 if (retry) {
1609
1610 /* Retry ELS command <elsCmd> to remote NPORT <did> */
1611 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1612 "%d:0107 Retry ELS command x%x to remote "
1613 "NPORT x%x Data: x%x x%x\n",
1614 phba->brd_no,
1615 cmd, ndlp->nlp_DID, cmdiocb->retry, delay);
1616
1617 if ((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) {
1618 /* If discovery / RSCN timer is running, reset it */
1619 if (timer_pending(&phba->fc_disctmo) ||
1620 (phba->fc_flag & FC_RSCN_MODE)) {
1621 lpfc_set_disctmo(phba);
1622 }
1623 }
1624
1625 phba->fc_stat.elsXmitRetry++;
1626 if (delay) {
1627 phba->fc_stat.elsDelayRetry++;
1628 ndlp->nlp_retry = cmdiocb->retry;
1629
1630 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
1631 ndlp->nlp_flag |= NLP_DELAY_TMO;
1632
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001633 ndlp->nlp_prev_state = ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001634 ndlp->nlp_state = NLP_STE_NPR_NODE;
1635 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1636 ndlp->nlp_last_elscmd = cmd;
1637
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001638 return 1;
dea31012005-04-17 16:05:31 -05001639 }
1640 switch (cmd) {
1641 case ELS_CMD_FLOGI:
1642 lpfc_issue_els_flogi(phba, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001643 return 1;
dea31012005-04-17 16:05:31 -05001644 case ELS_CMD_PLOGI:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001645 ndlp->nlp_prev_state = ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001646 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
1647 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
1648 lpfc_issue_els_plogi(phba, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001649 return 1;
dea31012005-04-17 16:05:31 -05001650 case ELS_CMD_ADISC:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001651 ndlp->nlp_prev_state = ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001652 ndlp->nlp_state = NLP_STE_ADISC_ISSUE;
1653 lpfc_nlp_list(phba, ndlp, NLP_ADISC_LIST);
1654 lpfc_issue_els_adisc(phba, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001655 return 1;
dea31012005-04-17 16:05:31 -05001656 case ELS_CMD_PRLI:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001657 ndlp->nlp_prev_state = ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001658 ndlp->nlp_state = NLP_STE_PRLI_ISSUE;
1659 lpfc_nlp_list(phba, ndlp, NLP_PRLI_LIST);
1660 lpfc_issue_els_prli(phba, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001661 return 1;
dea31012005-04-17 16:05:31 -05001662 case ELS_CMD_LOGO:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001663 ndlp->nlp_prev_state = ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001664 ndlp->nlp_state = NLP_STE_NPR_NODE;
1665 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1666 lpfc_issue_els_logo(phba, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001667 return 1;
dea31012005-04-17 16:05:31 -05001668 }
1669 }
1670
1671 /* No retry ELS command <elsCmd> to remote NPORT <did> */
1672 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1673 "%d:0108 No retry ELS command x%x to remote NPORT x%x "
1674 "Data: x%x x%x\n",
1675 phba->brd_no,
1676 cmd, ndlp->nlp_DID, cmdiocb->retry, ndlp->nlp_flag);
1677
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001678 return 0;
dea31012005-04-17 16:05:31 -05001679}
1680
1681int
1682lpfc_els_free_iocb(struct lpfc_hba * phba, struct lpfc_iocbq * elsiocb)
1683{
1684 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
1685
1686 /* context2 = cmd, context2->next = rsp, context3 = bpl */
1687 if (elsiocb->context2) {
1688 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
1689 /* Free the response before processing the command. */
1690 if (!list_empty(&buf_ptr1->list)) {
1691 list_remove_head(&buf_ptr1->list, buf_ptr,
1692 struct lpfc_dmabuf,
1693 list);
1694 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
1695 kfree(buf_ptr);
1696 }
1697 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
1698 kfree(buf_ptr1);
1699 }
1700
1701 if (elsiocb->context3) {
1702 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
1703 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
1704 kfree(buf_ptr);
1705 }
1706 spin_lock_irq(phba->host->host_lock);
James Bottomley604a3e32005-10-29 10:28:33 -05001707 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -05001708 spin_unlock_irq(phba->host->host_lock);
1709 return 0;
1710}
1711
1712static void
1713lpfc_cmpl_els_logo_acc(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
1714 struct lpfc_iocbq * rspiocb)
1715{
1716 struct lpfc_nodelist *ndlp;
1717
1718 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1719
1720 /* ACC to LOGO completes to NPort <nlp_DID> */
1721 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1722 "%d:0109 ACC to LOGO completes to NPort x%x "
1723 "Data: x%x x%x x%x\n",
1724 phba->brd_no, ndlp->nlp_DID, ndlp->nlp_flag,
1725 ndlp->nlp_state, ndlp->nlp_rpi);
1726
dea31012005-04-17 16:05:31 -05001727 switch (ndlp->nlp_state) {
1728 case NLP_STE_UNUSED_NODE: /* node is just allocated */
1729 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
1730 break;
1731 case NLP_STE_NPR_NODE: /* NPort Recovery mode */
1732 lpfc_unreg_rpi(phba, ndlp);
1733 break;
1734 default:
1735 break;
1736 }
1737 lpfc_els_free_iocb(phba, cmdiocb);
1738 return;
1739}
1740
1741static void
1742lpfc_cmpl_els_acc(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
1743 struct lpfc_iocbq * rspiocb)
1744{
1745 struct lpfc_nodelist *ndlp;
1746 LPFC_MBOXQ_t *mbox = NULL;
1747
1748 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1749 if (cmdiocb->context_un.mbox)
1750 mbox = cmdiocb->context_un.mbox;
1751
1752
1753 /* Check to see if link went down during discovery */
1754 if ((lpfc_els_chk_latt(phba)) || !ndlp) {
1755 if (mbox) {
1756 mempool_free( mbox, phba->mbox_mem_pool);
1757 }
1758 goto out;
1759 }
1760
1761 /* ELS response tag <ulpIoTag> completes */
1762 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1763 "%d:0110 ELS response tag x%x completes "
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001764 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
dea31012005-04-17 16:05:31 -05001765 phba->brd_no,
1766 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001767 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
1768 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
1769 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05001770
1771 if (mbox) {
1772 if ((rspiocb->iocb.ulpStatus == 0)
1773 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
1774 /* set_slim mailbox command needs to execute first,
1775 * queue this command to be processed later.
1776 */
1777 lpfc_unreg_rpi(phba, ndlp);
1778 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
1779 mbox->context2 = ndlp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001780 ndlp->nlp_prev_state = ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05001781 ndlp->nlp_state = NLP_STE_REG_LOGIN_ISSUE;
1782 lpfc_nlp_list(phba, ndlp, NLP_REGLOGIN_LIST);
1783 if (lpfc_sli_issue_mbox(phba, mbox,
1784 (MBX_NOWAIT | MBX_STOP_IOCB))
1785 != MBX_NOT_FINISHED) {
1786 goto out;
1787 }
1788 /* NOTE: we should have messages for unsuccessful
1789 reglogin */
1790 mempool_free( mbox, phba->mbox_mem_pool);
1791 } else {
1792 mempool_free( mbox, phba->mbox_mem_pool);
1793 if (ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
1794 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001795 ndlp = NULL;
dea31012005-04-17 16:05:31 -05001796 }
1797 }
1798 }
1799out:
1800 if (ndlp) {
1801 spin_lock_irq(phba->host->host_lock);
1802 ndlp->nlp_flag &= ~NLP_ACC_REGLOGIN;
1803 spin_unlock_irq(phba->host->host_lock);
1804 }
1805 lpfc_els_free_iocb(phba, cmdiocb);
1806 return;
1807}
1808
1809int
1810lpfc_els_rsp_acc(struct lpfc_hba * phba, uint32_t flag,
1811 struct lpfc_iocbq * oldiocb, struct lpfc_nodelist * ndlp,
1812 LPFC_MBOXQ_t * mbox, uint8_t newnode)
1813{
1814 IOCB_t *icmd;
1815 IOCB_t *oldcmd;
1816 struct lpfc_iocbq *elsiocb;
1817 struct lpfc_sli_ring *pring;
1818 struct lpfc_sli *psli;
1819 uint8_t *pcmd;
1820 uint16_t cmdsize;
1821 int rc;
1822
1823 psli = &phba->sli;
1824 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1825 oldcmd = &oldiocb->iocb;
1826
1827 switch (flag) {
1828 case ELS_CMD_ACC:
1829 cmdsize = sizeof (uint32_t);
1830 if ((elsiocb =
1831 lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry,
1832 ndlp, ELS_CMD_ACC)) == 0) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001833 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001834 return 1;
dea31012005-04-17 16:05:31 -05001835 }
1836 icmd = &elsiocb->iocb;
1837 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
1838 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1839 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
1840 pcmd += sizeof (uint32_t);
1841 break;
1842 case ELS_CMD_PLOGI:
1843 cmdsize = (sizeof (struct serv_parm) + sizeof (uint32_t));
1844 if ((elsiocb =
1845 lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry,
1846 ndlp, ELS_CMD_ACC)) == 0) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001847 return 1;
dea31012005-04-17 16:05:31 -05001848 }
1849 icmd = &elsiocb->iocb;
1850 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
1851 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1852
1853 if (mbox)
1854 elsiocb->context_un.mbox = mbox;
1855
1856 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
1857 pcmd += sizeof (uint32_t);
1858 memcpy(pcmd, &phba->fc_sparam, sizeof (struct serv_parm));
1859 break;
1860 default:
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001861 return 1;
dea31012005-04-17 16:05:31 -05001862 }
1863
1864 if (newnode)
1865 elsiocb->context1 = NULL;
1866
1867 /* Xmit ELS ACC response tag <ulpIoTag> */
1868 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1869 "%d:0128 Xmit ELS ACC response tag x%x "
1870 "Data: x%x x%x x%x x%x x%x\n",
1871 phba->brd_no,
1872 elsiocb->iocb.ulpIoTag,
1873 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
1874 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
1875
1876 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001877 spin_lock_irq(phba->host->host_lock);
1878 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
1879 spin_unlock_irq(phba->host->host_lock);
dea31012005-04-17 16:05:31 -05001880 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
1881 } else {
1882 elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
1883 }
1884
1885 phba->fc_stat.elsXmitACC++;
1886 spin_lock_irq(phba->host->host_lock);
1887 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
1888 spin_unlock_irq(phba->host->host_lock);
1889 if (rc == IOCB_ERROR) {
1890 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001891 return 1;
dea31012005-04-17 16:05:31 -05001892 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001893 return 0;
dea31012005-04-17 16:05:31 -05001894}
1895
1896int
1897lpfc_els_rsp_reject(struct lpfc_hba * phba, uint32_t rejectError,
1898 struct lpfc_iocbq * oldiocb, struct lpfc_nodelist * ndlp)
1899{
1900 IOCB_t *icmd;
1901 IOCB_t *oldcmd;
1902 struct lpfc_iocbq *elsiocb;
1903 struct lpfc_sli_ring *pring;
1904 struct lpfc_sli *psli;
1905 uint8_t *pcmd;
1906 uint16_t cmdsize;
1907 int rc;
1908
1909 psli = &phba->sli;
1910 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1911
1912 cmdsize = 2 * sizeof (uint32_t);
1913 if ((elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry,
1914 ndlp, ELS_CMD_LS_RJT)) == 0) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001915 return 1;
dea31012005-04-17 16:05:31 -05001916 }
1917
1918 icmd = &elsiocb->iocb;
1919 oldcmd = &oldiocb->iocb;
1920 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
1921 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1922
1923 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
1924 pcmd += sizeof (uint32_t);
1925 *((uint32_t *) (pcmd)) = rejectError;
1926
1927 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
1928 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1929 "%d:0129 Xmit ELS RJT x%x response tag x%x "
1930 "Data: x%x x%x x%x x%x x%x\n",
1931 phba->brd_no,
1932 rejectError, elsiocb->iocb.ulpIoTag,
1933 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
1934 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
1935
1936 phba->fc_stat.elsXmitLSRJT++;
1937 elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
1938 spin_lock_irq(phba->host->host_lock);
1939 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
1940 spin_unlock_irq(phba->host->host_lock);
1941 if (rc == IOCB_ERROR) {
1942 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001943 return 1;
dea31012005-04-17 16:05:31 -05001944 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001945 return 0;
dea31012005-04-17 16:05:31 -05001946}
1947
1948int
1949lpfc_els_rsp_adisc_acc(struct lpfc_hba * phba,
1950 struct lpfc_iocbq * oldiocb, struct lpfc_nodelist * ndlp)
1951{
1952 ADISC *ap;
1953 IOCB_t *icmd;
1954 IOCB_t *oldcmd;
1955 struct lpfc_iocbq *elsiocb;
1956 struct lpfc_sli_ring *pring;
1957 struct lpfc_sli *psli;
1958 uint8_t *pcmd;
1959 uint16_t cmdsize;
1960 int rc;
1961
1962 psli = &phba->sli;
1963 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1964
1965 cmdsize = sizeof (uint32_t) + sizeof (ADISC);
1966 if ((elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry,
1967 ndlp, ELS_CMD_ACC)) == 0) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001968 return 1;
dea31012005-04-17 16:05:31 -05001969 }
1970
1971 /* Xmit ADISC ACC response tag <ulpIoTag> */
1972 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
1973 "%d:0130 Xmit ADISC ACC response tag x%x "
1974 "Data: x%x x%x x%x x%x x%x\n",
1975 phba->brd_no,
1976 elsiocb->iocb.ulpIoTag,
1977 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
1978 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
1979
1980 icmd = &elsiocb->iocb;
1981 oldcmd = &oldiocb->iocb;
1982 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
1983 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1984
1985 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
1986 pcmd += sizeof (uint32_t);
1987
1988 ap = (ADISC *) (pcmd);
1989 ap->hardAL_PA = phba->fc_pref_ALPA;
1990 memcpy(&ap->portName, &phba->fc_portname, sizeof (struct lpfc_name));
1991 memcpy(&ap->nodeName, &phba->fc_nodename, sizeof (struct lpfc_name));
1992 ap->DID = be32_to_cpu(phba->fc_myDID);
1993
1994 phba->fc_stat.elsXmitACC++;
1995 elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
1996 spin_lock_irq(phba->host->host_lock);
1997 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
1998 spin_unlock_irq(phba->host->host_lock);
1999 if (rc == IOCB_ERROR) {
2000 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002001 return 1;
dea31012005-04-17 16:05:31 -05002002 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002003 return 0;
dea31012005-04-17 16:05:31 -05002004}
2005
2006int
2007lpfc_els_rsp_prli_acc(struct lpfc_hba * phba,
2008 struct lpfc_iocbq * oldiocb, struct lpfc_nodelist * ndlp)
2009{
2010 PRLI *npr;
2011 lpfc_vpd_t *vpd;
2012 IOCB_t *icmd;
2013 IOCB_t *oldcmd;
2014 struct lpfc_iocbq *elsiocb;
2015 struct lpfc_sli_ring *pring;
2016 struct lpfc_sli *psli;
2017 uint8_t *pcmd;
2018 uint16_t cmdsize;
2019 int rc;
2020
2021 psli = &phba->sli;
2022 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2023
2024 cmdsize = sizeof (uint32_t) + sizeof (PRLI);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002025 elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry, ndlp,
2026 (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
2027 if (!elsiocb)
2028 return 1;
dea31012005-04-17 16:05:31 -05002029
2030 /* Xmit PRLI ACC response tag <ulpIoTag> */
2031 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
2032 "%d:0131 Xmit PRLI ACC response tag x%x "
2033 "Data: x%x x%x x%x x%x x%x\n",
2034 phba->brd_no,
2035 elsiocb->iocb.ulpIoTag,
2036 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
2037 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
2038
2039 icmd = &elsiocb->iocb;
2040 oldcmd = &oldiocb->iocb;
2041 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2042 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2043
2044 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
2045 pcmd += sizeof (uint32_t);
2046
2047 /* For PRLI, remainder of payload is PRLI parameter page */
2048 memset(pcmd, 0, sizeof (PRLI));
2049
2050 npr = (PRLI *) pcmd;
2051 vpd = &phba->vpd;
2052 /*
2053 * If our firmware version is 3.20 or later,
2054 * set the following bits for FC-TAPE support.
2055 */
2056 if (vpd->rev.feaLevelHigh >= 0x02) {
2057 npr->ConfmComplAllowed = 1;
2058 npr->Retry = 1;
2059 npr->TaskRetryIdReq = 1;
2060 }
2061
2062 npr->acceptRspCode = PRLI_REQ_EXECUTED;
2063 npr->estabImagePair = 1;
2064 npr->readXferRdyDis = 1;
2065 npr->ConfmComplAllowed = 1;
2066
2067 npr->prliType = PRLI_FCP_TYPE;
2068 npr->initiatorFunc = 1;
2069
2070 phba->fc_stat.elsXmitACC++;
2071 elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
2072
2073 spin_lock_irq(phba->host->host_lock);
2074 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
2075 spin_unlock_irq(phba->host->host_lock);
2076 if (rc == IOCB_ERROR) {
2077 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002078 return 1;
dea31012005-04-17 16:05:31 -05002079 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002080 return 0;
dea31012005-04-17 16:05:31 -05002081}
2082
2083static int
2084lpfc_els_rsp_rnid_acc(struct lpfc_hba * phba,
2085 uint8_t format,
2086 struct lpfc_iocbq * oldiocb, struct lpfc_nodelist * ndlp)
2087{
2088 RNID *rn;
2089 IOCB_t *icmd;
2090 IOCB_t *oldcmd;
2091 struct lpfc_iocbq *elsiocb;
2092 struct lpfc_sli_ring *pring;
2093 struct lpfc_sli *psli;
2094 uint8_t *pcmd;
2095 uint16_t cmdsize;
2096 int rc;
2097
2098 psli = &phba->sli;
2099 pring = &psli->ring[LPFC_ELS_RING];
2100
2101 cmdsize = sizeof (uint32_t) + sizeof (uint32_t)
2102 + (2 * sizeof (struct lpfc_name));
2103 if (format)
2104 cmdsize += sizeof (RNID_TOP_DISC);
2105
2106 if ((elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry,
2107 ndlp, ELS_CMD_ACC)) == 0) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002108 return 1;
dea31012005-04-17 16:05:31 -05002109 }
2110
2111 /* Xmit RNID ACC response tag <ulpIoTag> */
2112 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
2113 "%d:0132 Xmit RNID ACC response tag x%x "
2114 "Data: x%x\n",
2115 phba->brd_no,
2116 elsiocb->iocb.ulpIoTag,
2117 elsiocb->iocb.ulpContext);
2118
2119 icmd = &elsiocb->iocb;
2120 oldcmd = &oldiocb->iocb;
2121 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2122 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2123
2124 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
2125 pcmd += sizeof (uint32_t);
2126
2127 memset(pcmd, 0, sizeof (RNID));
2128 rn = (RNID *) (pcmd);
2129 rn->Format = format;
2130 rn->CommonLen = (2 * sizeof (struct lpfc_name));
2131 memcpy(&rn->portName, &phba->fc_portname, sizeof (struct lpfc_name));
2132 memcpy(&rn->nodeName, &phba->fc_nodename, sizeof (struct lpfc_name));
2133 switch (format) {
2134 case 0:
2135 rn->SpecificLen = 0;
2136 break;
2137 case RNID_TOPOLOGY_DISC:
2138 rn->SpecificLen = sizeof (RNID_TOP_DISC);
2139 memcpy(&rn->un.topologyDisc.portName,
2140 &phba->fc_portname, sizeof (struct lpfc_name));
2141 rn->un.topologyDisc.unitType = RNID_HBA;
2142 rn->un.topologyDisc.physPort = 0;
2143 rn->un.topologyDisc.attachedNodes = 0;
2144 break;
2145 default:
2146 rn->CommonLen = 0;
2147 rn->SpecificLen = 0;
2148 break;
2149 }
2150
2151 phba->fc_stat.elsXmitACC++;
2152 elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
2153 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
2154 * it could be freed */
2155
2156 spin_lock_irq(phba->host->host_lock);
2157 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
2158 spin_unlock_irq(phba->host->host_lock);
2159 if (rc == IOCB_ERROR) {
2160 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002161 return 1;
dea31012005-04-17 16:05:31 -05002162 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002163 return 0;
dea31012005-04-17 16:05:31 -05002164}
2165
2166int
2167lpfc_els_disc_adisc(struct lpfc_hba * phba)
2168{
2169 int sentadisc;
2170 struct lpfc_nodelist *ndlp, *next_ndlp;
2171
2172 sentadisc = 0;
2173 /* go thru NPR list and issue any remaining ELS ADISCs */
2174 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
2175 nlp_listp) {
2176 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
2177 if (ndlp->nlp_flag & NLP_NPR_ADISC) {
2178 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002179 ndlp->nlp_prev_state = ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05002180 ndlp->nlp_state = NLP_STE_ADISC_ISSUE;
2181 lpfc_nlp_list(phba, ndlp,
2182 NLP_ADISC_LIST);
2183 lpfc_issue_els_adisc(phba, ndlp, 0);
2184 sentadisc++;
2185 phba->num_disc_nodes++;
2186 if (phba->num_disc_nodes >=
2187 phba->cfg_discovery_threads) {
2188 spin_lock_irq(phba->host->host_lock);
2189 phba->fc_flag |= FC_NLP_MORE;
2190 spin_unlock_irq(phba->host->host_lock);
2191 break;
2192 }
2193 }
2194 }
2195 }
2196 if (sentadisc == 0) {
2197 spin_lock_irq(phba->host->host_lock);
2198 phba->fc_flag &= ~FC_NLP_MORE;
2199 spin_unlock_irq(phba->host->host_lock);
2200 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002201 return sentadisc;
dea31012005-04-17 16:05:31 -05002202}
2203
2204int
2205lpfc_els_disc_plogi(struct lpfc_hba * phba)
2206{
2207 int sentplogi;
2208 struct lpfc_nodelist *ndlp, *next_ndlp;
2209
2210 sentplogi = 0;
2211 /* go thru NPR list and issue any remaining ELS PLOGIs */
2212 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
2213 nlp_listp) {
2214 if ((ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
2215 (!(ndlp->nlp_flag & NLP_DELAY_TMO))) {
2216 if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002217 ndlp->nlp_prev_state = ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05002218 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
2219 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
2220 lpfc_issue_els_plogi(phba, ndlp, 0);
2221 sentplogi++;
2222 phba->num_disc_nodes++;
2223 if (phba->num_disc_nodes >=
2224 phba->cfg_discovery_threads) {
2225 spin_lock_irq(phba->host->host_lock);
2226 phba->fc_flag |= FC_NLP_MORE;
2227 spin_unlock_irq(phba->host->host_lock);
2228 break;
2229 }
2230 }
2231 }
2232 }
2233 if (sentplogi == 0) {
2234 spin_lock_irq(phba->host->host_lock);
2235 phba->fc_flag &= ~FC_NLP_MORE;
2236 spin_unlock_irq(phba->host->host_lock);
2237 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002238 return sentplogi;
dea31012005-04-17 16:05:31 -05002239}
2240
2241int
2242lpfc_els_flush_rscn(struct lpfc_hba * phba)
2243{
2244 struct lpfc_dmabuf *mp;
2245 int i;
2246
2247 for (i = 0; i < phba->fc_rscn_id_cnt; i++) {
2248 mp = phba->fc_rscn_id_list[i];
2249 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2250 kfree(mp);
2251 phba->fc_rscn_id_list[i] = NULL;
2252 }
2253 phba->fc_rscn_id_cnt = 0;
2254 spin_lock_irq(phba->host->host_lock);
2255 phba->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
2256 spin_unlock_irq(phba->host->host_lock);
2257 lpfc_can_disctmo(phba);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002258 return 0;
dea31012005-04-17 16:05:31 -05002259}
2260
2261int
2262lpfc_rscn_payload_check(struct lpfc_hba * phba, uint32_t did)
2263{
2264 D_ID ns_did;
2265 D_ID rscn_did;
2266 struct lpfc_dmabuf *mp;
2267 uint32_t *lp;
2268 uint32_t payload_len, cmd, i, match;
2269
2270 ns_did.un.word = did;
2271 match = 0;
2272
2273 /* Never match fabric nodes for RSCNs */
2274 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
2275 return(0);
2276
2277 /* If we are doing a FULL RSCN rediscovery, match everything */
2278 if (phba->fc_flag & FC_RSCN_DISCOVERY) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002279 return did;
dea31012005-04-17 16:05:31 -05002280 }
2281
2282 for (i = 0; i < phba->fc_rscn_id_cnt; i++) {
2283 mp = phba->fc_rscn_id_list[i];
2284 lp = (uint32_t *) mp->virt;
2285 cmd = *lp++;
2286 payload_len = be32_to_cpu(cmd) & 0xffff; /* payload length */
2287 payload_len -= sizeof (uint32_t); /* take off word 0 */
2288 while (payload_len) {
2289 rscn_did.un.word = *lp++;
2290 rscn_did.un.word = be32_to_cpu(rscn_did.un.word);
2291 payload_len -= sizeof (uint32_t);
2292 switch (rscn_did.un.b.resv) {
2293 case 0: /* Single N_Port ID effected */
2294 if (ns_did.un.word == rscn_did.un.word) {
2295 match = did;
2296 }
2297 break;
2298 case 1: /* Whole N_Port Area effected */
2299 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
2300 && (ns_did.un.b.area == rscn_did.un.b.area))
2301 {
2302 match = did;
2303 }
2304 break;
2305 case 2: /* Whole N_Port Domain effected */
2306 if (ns_did.un.b.domain == rscn_did.un.b.domain)
2307 {
2308 match = did;
2309 }
2310 break;
2311 case 3: /* Whole Fabric effected */
2312 match = did;
2313 break;
2314 default:
2315 /* Unknown Identifier in RSCN list */
2316 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2317 "%d:0217 Unknown Identifier in "
2318 "RSCN payload Data: x%x\n",
2319 phba->brd_no, rscn_did.un.word);
2320 break;
2321 }
2322 if (match) {
2323 break;
2324 }
2325 }
2326 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002327 return match;
dea31012005-04-17 16:05:31 -05002328}
2329
2330static int
2331lpfc_rscn_recovery_check(struct lpfc_hba * phba)
2332{
2333 struct lpfc_nodelist *ndlp = NULL, *next_ndlp;
2334 struct list_head *listp;
2335 struct list_head *node_list[7];
2336 int i;
2337
2338 /* Look at all nodes effected by pending RSCNs and move
2339 * them to NPR list.
2340 */
2341 node_list[0] = &phba->fc_npr_list; /* MUST do this list first */
2342 node_list[1] = &phba->fc_nlpmap_list;
2343 node_list[2] = &phba->fc_nlpunmap_list;
2344 node_list[3] = &phba->fc_prli_list;
2345 node_list[4] = &phba->fc_reglogin_list;
2346 node_list[5] = &phba->fc_adisc_list;
2347 node_list[6] = &phba->fc_plogi_list;
2348 for (i = 0; i < 7; i++) {
2349 listp = node_list[i];
2350 if (list_empty(listp))
2351 continue;
2352
2353 list_for_each_entry_safe(ndlp, next_ndlp, listp, nlp_listp) {
2354 if (!(lpfc_rscn_payload_check(phba, ndlp->nlp_DID)))
2355 continue;
2356
2357 lpfc_disc_state_machine(phba, ndlp, NULL,
2358 NLP_EVT_DEVICE_RECOVERY);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002359
2360 /* Make sure NLP_DELAY_TMO is NOT running
2361 * after a device recovery event.
2362 */
dea31012005-04-17 16:05:31 -05002363 if (ndlp->nlp_flag & NLP_DELAY_TMO) {
2364 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002365 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05002366 del_timer_sync(&ndlp->nlp_delayfunc);
2367 if (!list_empty(&ndlp->
2368 els_retry_evt.evt_listp))
2369 list_del_init(&ndlp->
2370 els_retry_evt.evt_listp);
2371 }
2372 }
2373 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002374 return 0;
dea31012005-04-17 16:05:31 -05002375}
2376
2377static int
2378lpfc_els_rcv_rscn(struct lpfc_hba * phba,
2379 struct lpfc_iocbq * cmdiocb,
2380 struct lpfc_nodelist * ndlp, uint8_t newnode)
2381{
2382 struct lpfc_dmabuf *pcmd;
2383 uint32_t *lp;
2384 IOCB_t *icmd;
2385 uint32_t payload_len, cmd;
2386
2387 icmd = &cmdiocb->iocb;
2388 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2389 lp = (uint32_t *) pcmd->virt;
2390
2391 cmd = *lp++;
2392 payload_len = be32_to_cpu(cmd) & 0xffff; /* payload length */
2393 payload_len -= sizeof (uint32_t); /* take off word 0 */
2394 cmd &= ELS_CMD_MASK;
2395
2396 /* RSCN received */
2397 lpfc_printf_log(phba,
2398 KERN_INFO,
2399 LOG_DISCOVERY,
2400 "%d:0214 RSCN received Data: x%x x%x x%x x%x\n",
2401 phba->brd_no,
2402 phba->fc_flag, payload_len, *lp, phba->fc_rscn_id_cnt);
2403
2404 /* If we are about to begin discovery, just ACC the RSCN.
2405 * Discovery processing will satisfy it.
2406 */
2407 if (phba->hba_state < LPFC_NS_QRY) {
2408 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL,
2409 newnode);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002410 return 0;
dea31012005-04-17 16:05:31 -05002411 }
2412
2413 /* If we are already processing an RSCN, save the received
2414 * RSCN payload buffer, cmdiocb->context2 to process later.
2415 */
2416 if (phba->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
2417 if ((phba->fc_rscn_id_cnt < FC_MAX_HOLD_RSCN) &&
2418 !(phba->fc_flag & FC_RSCN_DISCOVERY)) {
2419 spin_lock_irq(phba->host->host_lock);
2420 phba->fc_flag |= FC_RSCN_MODE;
2421 spin_unlock_irq(phba->host->host_lock);
2422 phba->fc_rscn_id_list[phba->fc_rscn_id_cnt++] = pcmd;
2423
2424 /* If we zero, cmdiocb->context2, the calling
2425 * routine will not try to free it.
2426 */
2427 cmdiocb->context2 = NULL;
2428
2429 /* Deferred RSCN */
2430 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
2431 "%d:0235 Deferred RSCN "
2432 "Data: x%x x%x x%x\n",
2433 phba->brd_no, phba->fc_rscn_id_cnt,
2434 phba->fc_flag, phba->hba_state);
2435 } else {
2436 spin_lock_irq(phba->host->host_lock);
2437 phba->fc_flag |= FC_RSCN_DISCOVERY;
2438 spin_unlock_irq(phba->host->host_lock);
2439 /* ReDiscovery RSCN */
2440 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
2441 "%d:0234 ReDiscovery RSCN "
2442 "Data: x%x x%x x%x\n",
2443 phba->brd_no, phba->fc_rscn_id_cnt,
2444 phba->fc_flag, phba->hba_state);
2445 }
2446 /* Send back ACC */
2447 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL,
2448 newnode);
2449
2450 /* send RECOVERY event for ALL nodes that match RSCN payload */
2451 lpfc_rscn_recovery_check(phba);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002452 return 0;
dea31012005-04-17 16:05:31 -05002453 }
2454
2455 phba->fc_flag |= FC_RSCN_MODE;
2456 phba->fc_rscn_id_list[phba->fc_rscn_id_cnt++] = pcmd;
2457 /*
2458 * If we zero, cmdiocb->context2, the calling routine will
2459 * not try to free it.
2460 */
2461 cmdiocb->context2 = NULL;
2462
2463 lpfc_set_disctmo(phba);
2464
2465 /* Send back ACC */
2466 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, newnode);
2467
2468 /* send RECOVERY event for ALL nodes that match RSCN payload */
2469 lpfc_rscn_recovery_check(phba);
2470
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002471 return lpfc_els_handle_rscn(phba);
dea31012005-04-17 16:05:31 -05002472}
2473
2474int
2475lpfc_els_handle_rscn(struct lpfc_hba * phba)
2476{
2477 struct lpfc_nodelist *ndlp;
2478
2479 /* Start timer for RSCN processing */
2480 lpfc_set_disctmo(phba);
2481
2482 /* RSCN processed */
2483 lpfc_printf_log(phba,
2484 KERN_INFO,
2485 LOG_DISCOVERY,
2486 "%d:0215 RSCN processed Data: x%x x%x x%x x%x\n",
2487 phba->brd_no,
2488 phba->fc_flag, 0, phba->fc_rscn_id_cnt,
2489 phba->hba_state);
2490
2491 /* To process RSCN, first compare RSCN data with NameServer */
2492 phba->fc_ns_retry = 0;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002493 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_UNMAPPED, NameServer_DID);
2494 if (ndlp) {
dea31012005-04-17 16:05:31 -05002495 /* Good ndlp, issue CT Request to NameServer */
2496 if (lpfc_ns_cmd(phba, ndlp, SLI_CTNS_GID_FT) == 0) {
2497 /* Wait for NameServer query cmpl before we can
2498 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002499 return 1;
dea31012005-04-17 16:05:31 -05002500 }
2501 } else {
2502 /* If login to NameServer does not exist, issue one */
2503 /* Good status, issue PLOGI to NameServer */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002504 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, NameServer_DID);
2505 if (ndlp) {
dea31012005-04-17 16:05:31 -05002506 /* Wait for NameServer login cmpl before we can
2507 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002508 return 1;
dea31012005-04-17 16:05:31 -05002509 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002510 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2511 if (!ndlp) {
dea31012005-04-17 16:05:31 -05002512 lpfc_els_flush_rscn(phba);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002513 return 0;
dea31012005-04-17 16:05:31 -05002514 } else {
2515 lpfc_nlp_init(phba, ndlp, NameServer_DID);
2516 ndlp->nlp_type |= NLP_FABRIC;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002517 ndlp->nlp_prev_state = ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05002518 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
2519 lpfc_issue_els_plogi(phba, ndlp, 0);
2520 /* Wait for NameServer login cmpl before we can
2521 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002522 return 1;
dea31012005-04-17 16:05:31 -05002523 }
2524 }
2525
2526 lpfc_els_flush_rscn(phba);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002527 return 0;
dea31012005-04-17 16:05:31 -05002528}
2529
2530static int
2531lpfc_els_rcv_flogi(struct lpfc_hba * phba,
2532 struct lpfc_iocbq * cmdiocb,
2533 struct lpfc_nodelist * ndlp, uint8_t newnode)
2534{
2535 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2536 uint32_t *lp = (uint32_t *) pcmd->virt;
2537 IOCB_t *icmd = &cmdiocb->iocb;
2538 struct serv_parm *sp;
2539 LPFC_MBOXQ_t *mbox;
2540 struct ls_rjt stat;
2541 uint32_t cmd, did;
2542 int rc;
2543
2544 cmd = *lp++;
2545 sp = (struct serv_parm *) lp;
2546
2547 /* FLOGI received */
2548
2549 lpfc_set_disctmo(phba);
2550
2551 if (phba->fc_topology == TOPOLOGY_LOOP) {
2552 /* We should never receive a FLOGI in loop mode, ignore it */
2553 did = icmd->un.elsreq64.remoteID;
2554
2555 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
2556 Loop Mode */
2557 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
2558 "%d:0113 An FLOGI ELS command x%x was received "
2559 "from DID x%x in Loop Mode\n",
2560 phba->brd_no, cmd, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002561 return 1;
dea31012005-04-17 16:05:31 -05002562 }
2563
2564 did = Fabric_DID;
2565
2566 if ((lpfc_check_sparm(phba, ndlp, sp, CLASS3))) {
2567 /* For a FLOGI we accept, then if our portname is greater
2568 * then the remote portname we initiate Nport login.
2569 */
2570
2571 rc = memcmp(&phba->fc_portname, &sp->portName,
2572 sizeof (struct lpfc_name));
2573
2574 if (!rc) {
2575 if ((mbox = mempool_alloc(phba->mbox_mem_pool,
2576 GFP_KERNEL)) == 0) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002577 return 1;
dea31012005-04-17 16:05:31 -05002578 }
2579 lpfc_linkdown(phba);
2580 lpfc_init_link(phba, mbox,
2581 phba->cfg_topology,
2582 phba->cfg_link_speed);
2583 mbox->mb.un.varInitLnk.lipsr_AL_PA = 0;
2584 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
2585 rc = lpfc_sli_issue_mbox
2586 (phba, mbox, (MBX_NOWAIT | MBX_STOP_IOCB));
2587 if (rc == MBX_NOT_FINISHED) {
2588 mempool_free( mbox, phba->mbox_mem_pool);
2589 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002590 return 1;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002591 } else if (rc > 0) { /* greater than */
dea31012005-04-17 16:05:31 -05002592 spin_lock_irq(phba->host->host_lock);
2593 phba->fc_flag |= FC_PT2PT_PLOGI;
2594 spin_unlock_irq(phba->host->host_lock);
2595 }
2596 phba->fc_flag |= FC_PT2PT;
2597 phba->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
2598 } else {
2599 /* Reject this request because invalid parameters */
2600 stat.un.b.lsRjtRsvd0 = 0;
2601 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2602 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
2603 stat.un.b.vendorUnique = 0;
2604 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002605 return 1;
dea31012005-04-17 16:05:31 -05002606 }
2607
2608 /* Send back ACC */
2609 lpfc_els_rsp_acc(phba, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL, newnode);
2610
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002611 return 0;
dea31012005-04-17 16:05:31 -05002612}
2613
2614static int
2615lpfc_els_rcv_rnid(struct lpfc_hba * phba,
2616 struct lpfc_iocbq * cmdiocb, struct lpfc_nodelist * ndlp)
2617{
2618 struct lpfc_dmabuf *pcmd;
2619 uint32_t *lp;
2620 IOCB_t *icmd;
2621 RNID *rn;
2622 struct ls_rjt stat;
2623 uint32_t cmd, did;
2624
2625 icmd = &cmdiocb->iocb;
2626 did = icmd->un.elsreq64.remoteID;
2627 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2628 lp = (uint32_t *) pcmd->virt;
2629
2630 cmd = *lp++;
2631 rn = (RNID *) lp;
2632
2633 /* RNID received */
2634
2635 switch (rn->Format) {
2636 case 0:
2637 case RNID_TOPOLOGY_DISC:
2638 /* Send back ACC */
2639 lpfc_els_rsp_rnid_acc(phba, rn->Format, cmdiocb, ndlp);
2640 break;
2641 default:
2642 /* Reject this request because format not supported */
2643 stat.un.b.lsRjtRsvd0 = 0;
2644 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2645 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
2646 stat.un.b.vendorUnique = 0;
2647 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
2648 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002649 return 0;
dea31012005-04-17 16:05:31 -05002650}
2651
2652static int
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002653lpfc_els_rcv_lirr(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
2654 struct lpfc_nodelist * ndlp)
2655{
2656 struct ls_rjt stat;
2657
2658 /* For now, unconditionally reject this command */
2659 stat.un.b.lsRjtRsvd0 = 0;
2660 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2661 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
2662 stat.un.b.vendorUnique = 0;
2663 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
2664 return 0;
2665}
2666
Jamie Wellnitz082c0262006-02-28 19:25:30 -05002667static void
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002668lpfc_els_rsp_rps_acc(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
2669{
2670 struct lpfc_sli *psli;
2671 struct lpfc_sli_ring *pring;
2672 MAILBOX_t *mb;
2673 IOCB_t *icmd;
2674 RPS_RSP *rps_rsp;
2675 uint8_t *pcmd;
2676 struct lpfc_iocbq *elsiocb;
2677 struct lpfc_nodelist *ndlp;
2678 uint16_t xri, status;
2679 uint32_t cmdsize;
2680
2681 psli = &phba->sli;
2682 pring = &psli->ring[LPFC_ELS_RING];
2683 mb = &pmb->mb;
2684
2685 ndlp = (struct lpfc_nodelist *) pmb->context2;
2686 xri = (uint16_t) ((unsigned long)(pmb->context1));
2687 pmb->context1 = 0;
2688 pmb->context2 = 0;
2689
2690 if (mb->mbxStatus) {
2691 mempool_free( pmb, phba->mbox_mem_pool);
2692 return;
2693 }
2694
2695 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
2696 mempool_free( pmb, phba->mbox_mem_pool);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002697 elsiocb = lpfc_prep_els_iocb(phba, 0, cmdsize, lpfc_max_els_tries,
2698 ndlp, ELS_CMD_ACC);
2699 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002700 return;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002701
2702 icmd = &elsiocb->iocb;
2703 icmd->ulpContext = xri;
2704
2705 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2706 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
2707 pcmd += sizeof (uint32_t); /* Skip past command */
2708 rps_rsp = (RPS_RSP *)pcmd;
2709
2710 if (phba->fc_topology != TOPOLOGY_LOOP)
2711 status = 0x10;
2712 else
2713 status = 0x8;
2714 if (phba->fc_flag & FC_FABRIC)
2715 status |= 0x4;
2716
2717 rps_rsp->rsvd1 = 0;
2718 rps_rsp->portStatus = be16_to_cpu(status);
2719 rps_rsp->linkFailureCnt = be32_to_cpu(mb->un.varRdLnk.linkFailureCnt);
2720 rps_rsp->lossSyncCnt = be32_to_cpu(mb->un.varRdLnk.lossSyncCnt);
2721 rps_rsp->lossSignalCnt = be32_to_cpu(mb->un.varRdLnk.lossSignalCnt);
2722 rps_rsp->primSeqErrCnt = be32_to_cpu(mb->un.varRdLnk.primSeqErrCnt);
2723 rps_rsp->invalidXmitWord = be32_to_cpu(mb->un.varRdLnk.invalidXmitWord);
2724 rps_rsp->crcCnt = be32_to_cpu(mb->un.varRdLnk.crcCnt);
2725
2726 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
2727 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
2728 "%d:0128 Xmit ELS RPS ACC response tag x%x "
2729 "Data: x%x x%x x%x x%x x%x\n",
2730 phba->brd_no,
2731 elsiocb->iocb.ulpIoTag,
2732 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
2733 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
2734
2735 elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
2736 phba->fc_stat.elsXmitACC++;
2737 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
2738 lpfc_els_free_iocb(phba, elsiocb);
2739 }
2740 return;
2741}
2742
2743static int
2744lpfc_els_rcv_rps(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
2745 struct lpfc_nodelist * ndlp)
2746{
2747 uint32_t *lp;
2748 uint8_t flag;
2749 LPFC_MBOXQ_t *mbox;
2750 struct lpfc_dmabuf *pcmd;
2751 RPS *rps;
2752 struct ls_rjt stat;
2753
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002754 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
2755 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002756 stat.un.b.lsRjtRsvd0 = 0;
2757 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2758 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
2759 stat.un.b.vendorUnique = 0;
2760 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
2761 }
2762
2763 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2764 lp = (uint32_t *) pcmd->virt;
2765 flag = (be32_to_cpu(*lp++) & 0xf);
2766 rps = (RPS *) lp;
2767
2768 if ((flag == 0) ||
2769 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
2770 ((flag == 2) && (memcmp(&rps->un.portName, &phba->fc_portname,
2771 sizeof (struct lpfc_name)) == 0))) {
2772 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC))) {
2773 lpfc_read_lnk_stat(phba, mbox);
2774 mbox->context1 =
2775 (void *)((unsigned long)cmdiocb->iocb.ulpContext);
2776 mbox->context2 = ndlp;
2777 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
2778 if (lpfc_sli_issue_mbox (phba, mbox,
2779 (MBX_NOWAIT | MBX_STOP_IOCB)) != MBX_NOT_FINISHED) {
2780 /* Mbox completion will send ELS Response */
2781 return 0;
2782 }
2783 mempool_free(mbox, phba->mbox_mem_pool);
2784 }
2785 }
2786 stat.un.b.lsRjtRsvd0 = 0;
2787 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2788 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
2789 stat.un.b.vendorUnique = 0;
2790 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
2791 return 0;
2792}
2793
Jamie Wellnitz082c0262006-02-28 19:25:30 -05002794static int
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002795lpfc_els_rsp_rpl_acc(struct lpfc_hba * phba, uint16_t cmdsize,
2796 struct lpfc_iocbq * oldiocb, struct lpfc_nodelist * ndlp)
2797{
2798 IOCB_t *icmd;
2799 IOCB_t *oldcmd;
2800 RPL_RSP rpl_rsp;
2801 struct lpfc_iocbq *elsiocb;
2802 struct lpfc_sli_ring *pring;
2803 struct lpfc_sli *psli;
2804 uint8_t *pcmd;
2805
2806 psli = &phba->sli;
2807 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2808
2809 if ((elsiocb =
2810 lpfc_prep_els_iocb(phba, 0, cmdsize, oldiocb->retry,
2811 ndlp, ELS_CMD_ACC)) == 0) {
2812 return 1;
2813 }
2814 icmd = &elsiocb->iocb;
2815 oldcmd = &oldiocb->iocb;
2816 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2817
2818 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2819 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
2820 pcmd += sizeof (uint16_t);
2821 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
2822 pcmd += sizeof(uint16_t);
2823
2824 /* Setup the RPL ACC payload */
2825 rpl_rsp.listLen = be32_to_cpu(1);
2826 rpl_rsp.index = 0;
2827 rpl_rsp.port_num_blk.portNum = 0;
2828 rpl_rsp.port_num_blk.portID = be32_to_cpu(phba->fc_myDID);
2829 memcpy(&rpl_rsp.port_num_blk.portName, &phba->fc_portname,
2830 sizeof(struct lpfc_name));
2831
2832 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
2833
2834
2835 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
2836 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
2837 "%d:0128 Xmit ELS RPL ACC response tag x%x "
2838 "Data: x%x x%x x%x x%x x%x\n",
2839 phba->brd_no,
2840 elsiocb->iocb.ulpIoTag,
2841 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
2842 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
2843
2844 elsiocb->iocb_cmpl = lpfc_cmpl_els_acc;
2845
2846 phba->fc_stat.elsXmitACC++;
2847 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
2848 lpfc_els_free_iocb(phba, elsiocb);
2849 return 1;
2850 }
2851 return 0;
2852}
2853
2854static int
2855lpfc_els_rcv_rpl(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
dea31012005-04-17 16:05:31 -05002856 struct lpfc_nodelist * ndlp)
2857{
2858 struct lpfc_dmabuf *pcmd;
2859 uint32_t *lp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002860 uint32_t maxsize;
2861 uint16_t cmdsize;
2862 RPL *rpl;
2863 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05002864
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002865 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
2866 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002867 stat.un.b.lsRjtRsvd0 = 0;
2868 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
2869 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
2870 stat.un.b.vendorUnique = 0;
2871 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05002872 }
2873
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002874 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2875 lp = (uint32_t *) pcmd->virt;
2876 rpl = (RPL *) (lp + 1);
2877
2878 maxsize = be32_to_cpu(rpl->maxsize);
2879
2880 /* We support only one port */
2881 if ((rpl->index == 0) &&
2882 ((maxsize == 0) ||
2883 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
2884 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002885 } else {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05002886 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
2887 }
2888 lpfc_els_rsp_rpl_acc(phba, cmdsize, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05002889
2890 return 0;
2891}
2892
2893static int
2894lpfc_els_rcv_farp(struct lpfc_hba * phba,
2895 struct lpfc_iocbq * cmdiocb, struct lpfc_nodelist * ndlp)
2896{
2897 struct lpfc_dmabuf *pcmd;
2898 uint32_t *lp;
2899 IOCB_t *icmd;
2900 FARP *fp;
2901 uint32_t cmd, cnt, did;
2902
2903 icmd = &cmdiocb->iocb;
2904 did = icmd->un.elsreq64.remoteID;
2905 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2906 lp = (uint32_t *) pcmd->virt;
2907
2908 cmd = *lp++;
2909 fp = (FARP *) lp;
2910
2911 /* FARP-REQ received from DID <did> */
2912 lpfc_printf_log(phba,
2913 KERN_INFO,
2914 LOG_IP,
2915 "%d:0601 FARP-REQ received from DID x%x\n",
2916 phba->brd_no, did);
2917
2918 /* We will only support match on WWPN or WWNN */
2919 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002920 return 0;
dea31012005-04-17 16:05:31 -05002921 }
2922
2923 cnt = 0;
2924 /* If this FARP command is searching for my portname */
2925 if (fp->Mflags & FARP_MATCH_PORT) {
2926 if (memcmp(&fp->RportName, &phba->fc_portname,
2927 sizeof (struct lpfc_name)) == 0)
2928 cnt = 1;
2929 }
2930
2931 /* If this FARP command is searching for my nodename */
2932 if (fp->Mflags & FARP_MATCH_NODE) {
2933 if (memcmp(&fp->RnodeName, &phba->fc_nodename,
2934 sizeof (struct lpfc_name)) == 0)
2935 cnt = 1;
2936 }
2937
2938 if (cnt) {
2939 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
2940 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
2941 /* Log back into the node before sending the FARP. */
2942 if (fp->Rflags & FARP_REQUEST_PLOGI) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002943 ndlp->nlp_prev_state = ndlp->nlp_state;
dea31012005-04-17 16:05:31 -05002944 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
2945 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
2946 lpfc_issue_els_plogi(phba, ndlp, 0);
2947 }
2948
2949 /* Send a FARP response to that node */
2950 if (fp->Rflags & FARP_REQUEST_FARPR) {
2951 lpfc_issue_els_farpr(phba, did, 0);
2952 }
2953 }
2954 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002955 return 0;
dea31012005-04-17 16:05:31 -05002956}
2957
2958static int
2959lpfc_els_rcv_farpr(struct lpfc_hba * phba,
2960 struct lpfc_iocbq * cmdiocb, struct lpfc_nodelist * ndlp)
2961{
2962 struct lpfc_dmabuf *pcmd;
2963 uint32_t *lp;
2964 IOCB_t *icmd;
2965 uint32_t cmd, did;
2966
2967 icmd = &cmdiocb->iocb;
2968 did = icmd->un.elsreq64.remoteID;
2969 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2970 lp = (uint32_t *) pcmd->virt;
2971
2972 cmd = *lp++;
2973 /* FARP-RSP received from DID <did> */
2974 lpfc_printf_log(phba,
2975 KERN_INFO,
2976 LOG_IP,
2977 "%d:0600 FARP-RSP received from DID x%x\n",
2978 phba->brd_no, did);
2979
2980 /* ACCEPT the Farp resp request */
2981 lpfc_els_rsp_acc(phba, ELS_CMD_ACC, cmdiocb, ndlp, NULL, 0);
2982
2983 return 0;
2984}
2985
2986static int
2987lpfc_els_rcv_fan(struct lpfc_hba * phba, struct lpfc_iocbq * cmdiocb,
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002988 struct lpfc_nodelist * fan_ndlp)
dea31012005-04-17 16:05:31 -05002989{
2990 struct lpfc_dmabuf *pcmd;
2991 uint32_t *lp;
2992 IOCB_t *icmd;
dea31012005-04-17 16:05:31 -05002993 uint32_t cmd, did;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002994 FAN *fp;
2995 struct lpfc_nodelist *ndlp, *next_ndlp;
2996
2997 /* FAN received */
2998 lpfc_printf_log(phba, KERN_INFO, LOG_ELS, "%d:265 FAN received\n",
2999 phba->brd_no);
dea31012005-04-17 16:05:31 -05003000
3001 icmd = &cmdiocb->iocb;
3002 did = icmd->un.elsreq64.remoteID;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003003 pcmd = (struct lpfc_dmabuf *)cmdiocb->context2;
3004 lp = (uint32_t *)pcmd->virt;
dea31012005-04-17 16:05:31 -05003005
3006 cmd = *lp++;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003007 fp = (FAN *)lp;
dea31012005-04-17 16:05:31 -05003008
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003009 /* FAN received; Fan does not have a reply sequence */
dea31012005-04-17 16:05:31 -05003010
3011 if (phba->hba_state == LPFC_LOCAL_CFG_LINK) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003012 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
3013 sizeof(struct lpfc_name)) != 0) ||
3014 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
3015 sizeof(struct lpfc_name)) != 0)) {
3016 /*
3017 * This node has switched fabrics. FLOGI is required
3018 * Clean up the old rpi's
dea31012005-04-17 16:05:31 -05003019 */
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003020
3021 list_for_each_entry_safe(ndlp, next_ndlp,
3022 &phba->fc_npr_list, nlp_listp) {
3023
3024 if (ndlp->nlp_type & NLP_FABRIC) {
3025 /*
3026 * Clean up old Fabric, Nameserver and
3027 * other NLP_FABRIC logins
3028 */
3029 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003030 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003031 /* Fail outstanding I/O now since this
3032 * device is marked for PLOGI
3033 */
3034 lpfc_unreg_rpi(phba, ndlp);
3035 }
3036 }
3037
3038 phba->hba_state = LPFC_FLOGI;
3039 lpfc_set_disctmo(phba);
3040 lpfc_initial_flogi(phba);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003041 return 0;
dea31012005-04-17 16:05:31 -05003042 }
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003043 /* Discovery not needed,
3044 * move the nodes to their original state.
3045 */
3046 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
3047 nlp_listp) {
dea31012005-04-17 16:05:31 -05003048
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003049 switch (ndlp->nlp_prev_state) {
3050 case NLP_STE_UNMAPPED_NODE:
3051 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
3052 ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
3053 lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
3054 break;
3055
3056 case NLP_STE_MAPPED_NODE:
3057 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
3058 ndlp->nlp_state = NLP_STE_MAPPED_NODE;
3059 lpfc_nlp_list(phba, ndlp, NLP_MAPPED_LIST);
3060 break;
3061
3062 default:
3063 break;
3064 }
3065 }
3066
3067 /* Start discovery - this should just do CLEAR_LA */
dea31012005-04-17 16:05:31 -05003068 lpfc_disc_start(phba);
3069 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003070 return 0;
dea31012005-04-17 16:05:31 -05003071}
3072
3073void
3074lpfc_els_timeout(unsigned long ptr)
3075{
3076 struct lpfc_hba *phba;
3077 unsigned long iflag;
3078
3079 phba = (struct lpfc_hba *)ptr;
3080 if (phba == 0)
3081 return;
3082 spin_lock_irqsave(phba->host->host_lock, iflag);
3083 if (!(phba->work_hba_events & WORKER_ELS_TMO)) {
3084 phba->work_hba_events |= WORKER_ELS_TMO;
3085 if (phba->work_wait)
3086 wake_up(phba->work_wait);
3087 }
3088 spin_unlock_irqrestore(phba->host->host_lock, iflag);
3089 return;
3090}
3091
3092void
3093lpfc_els_timeout_handler(struct lpfc_hba *phba)
3094{
3095 struct lpfc_sli_ring *pring;
3096 struct lpfc_iocbq *tmp_iocb, *piocb;
3097 IOCB_t *cmd = NULL;
3098 struct lpfc_dmabuf *pcmd;
3099 struct list_head *dlp;
3100 uint32_t *elscmd;
3101 uint32_t els_command;
3102 uint32_t timeout;
3103 uint32_t remote_ID;
3104
3105 if (phba == 0)
3106 return;
3107 spin_lock_irq(phba->host->host_lock);
3108 /* If the timer is already canceled do nothing */
3109 if (!(phba->work_hba_events & WORKER_ELS_TMO)) {
3110 spin_unlock_irq(phba->host->host_lock);
3111 return;
3112 }
3113 timeout = (uint32_t)(phba->fc_ratov << 1);
3114
3115 pring = &phba->sli.ring[LPFC_ELS_RING];
3116 dlp = &pring->txcmplq;
3117
3118 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
3119 cmd = &piocb->iocb;
3120
3121 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
3122 continue;
3123 }
3124 pcmd = (struct lpfc_dmabuf *) piocb->context2;
3125 elscmd = (uint32_t *) (pcmd->virt);
3126 els_command = *elscmd;
3127
3128 if ((els_command == ELS_CMD_FARP)
3129 || (els_command == ELS_CMD_FARPR)) {
3130 continue;
3131 }
3132
3133 if (piocb->drvrTimeout > 0) {
3134 if (piocb->drvrTimeout >= timeout) {
3135 piocb->drvrTimeout -= timeout;
3136 } else {
3137 piocb->drvrTimeout = 0;
3138 }
3139 continue;
3140 }
3141
3142 list_del(&piocb->list);
3143 pring->txcmplq_cnt--;
3144
3145 if (cmd->ulpCommand == CMD_GEN_REQUEST64_CR) {
3146 struct lpfc_nodelist *ndlp;
Jamie Wellnitz66a9ed62006-02-28 22:33:10 -05003147 spin_unlock_irq(phba->host->host_lock);
dea31012005-04-17 16:05:31 -05003148 ndlp = lpfc_findnode_rpi(phba, cmd->ulpContext);
Jamie Wellnitz66a9ed62006-02-28 22:33:10 -05003149 spin_lock_irq(phba->host->host_lock);
dea31012005-04-17 16:05:31 -05003150 remote_ID = ndlp->nlp_DID;
3151 if (cmd->un.elsreq64.bdl.ulpIoTag32) {
3152 lpfc_sli_issue_abort_iotag32(phba,
3153 pring, piocb);
3154 }
3155 } else {
3156 remote_ID = cmd->un.elsreq64.remoteID;
3157 }
3158
3159 lpfc_printf_log(phba,
3160 KERN_ERR,
3161 LOG_ELS,
3162 "%d:0127 ELS timeout Data: x%x x%x x%x x%x\n",
3163 phba->brd_no, els_command,
3164 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
3165
3166 /*
3167 * The iocb has timed out; abort it.
3168 */
3169 if (piocb->iocb_cmpl) {
3170 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
3171 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
3172 spin_unlock_irq(phba->host->host_lock);
3173 (piocb->iocb_cmpl) (phba, piocb, piocb);
3174 spin_lock_irq(phba->host->host_lock);
James Bottomley604a3e32005-10-29 10:28:33 -05003175 } else
3176 lpfc_sli_release_iocbq(phba, piocb);
dea31012005-04-17 16:05:31 -05003177 }
3178 if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt) {
3179 phba->els_tmofunc.expires = jiffies + HZ * timeout;
3180 add_timer(&phba->els_tmofunc);
3181 }
3182 spin_unlock_irq(phba->host->host_lock);
3183}
3184
3185void
3186lpfc_els_flush_cmd(struct lpfc_hba * phba)
3187{
3188 struct lpfc_sli_ring *pring;
3189 struct lpfc_iocbq *tmp_iocb, *piocb;
3190 IOCB_t *cmd = NULL;
3191 struct lpfc_dmabuf *pcmd;
3192 uint32_t *elscmd;
3193 uint32_t els_command;
dea31012005-04-17 16:05:31 -05003194
3195 pring = &phba->sli.ring[LPFC_ELS_RING];
3196 spin_lock_irq(phba->host->host_lock);
3197 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
3198 cmd = &piocb->iocb;
3199
3200 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
3201 continue;
3202 }
3203
3204 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
3205 if ((cmd->ulpCommand == CMD_QUE_RING_BUF_CN) ||
3206 (cmd->ulpCommand == CMD_QUE_RING_BUF64_CN) ||
3207 (cmd->ulpCommand == CMD_CLOSE_XRI_CN) ||
3208 (cmd->ulpCommand == CMD_ABORT_XRI_CN)) {
3209 continue;
3210 }
3211
3212 pcmd = (struct lpfc_dmabuf *) piocb->context2;
3213 elscmd = (uint32_t *) (pcmd->virt);
3214 els_command = *elscmd;
3215
dea31012005-04-17 16:05:31 -05003216 list_del(&piocb->list);
3217 pring->txcmplq_cnt--;
3218
3219 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
3220 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
3221
3222 if (piocb->iocb_cmpl) {
3223 spin_unlock_irq(phba->host->host_lock);
3224 (piocb->iocb_cmpl) (phba, piocb, piocb);
3225 spin_lock_irq(phba->host->host_lock);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003226 } else
James Bottomley604a3e32005-10-29 10:28:33 -05003227 lpfc_sli_release_iocbq(phba, piocb);
dea31012005-04-17 16:05:31 -05003228 }
3229
3230 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
3231 cmd = &piocb->iocb;
3232
3233 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
3234 continue;
3235 }
3236 pcmd = (struct lpfc_dmabuf *) piocb->context2;
3237 elscmd = (uint32_t *) (pcmd->virt);
3238 els_command = *elscmd;
3239
dea31012005-04-17 16:05:31 -05003240 list_del(&piocb->list);
3241 pring->txcmplq_cnt--;
3242
3243 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
3244 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
3245
3246 if (piocb->iocb_cmpl) {
3247 spin_unlock_irq(phba->host->host_lock);
3248 (piocb->iocb_cmpl) (phba, piocb, piocb);
3249 spin_lock_irq(phba->host->host_lock);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003250 } else
James Bottomley604a3e32005-10-29 10:28:33 -05003251 lpfc_sli_release_iocbq(phba, piocb);
dea31012005-04-17 16:05:31 -05003252 }
3253 spin_unlock_irq(phba->host->host_lock);
3254 return;
3255}
3256
3257void
3258lpfc_els_unsol_event(struct lpfc_hba * phba,
3259 struct lpfc_sli_ring * pring, struct lpfc_iocbq * elsiocb)
3260{
3261 struct lpfc_sli *psli;
3262 struct lpfc_nodelist *ndlp;
3263 struct lpfc_dmabuf *mp;
3264 uint32_t *lp;
3265 IOCB_t *icmd;
3266 struct ls_rjt stat;
3267 uint32_t cmd;
3268 uint32_t did;
3269 uint32_t newnode;
3270 uint32_t drop_cmd = 0; /* by default do NOT drop received cmd */
3271 uint32_t rjt_err = 0;
3272
3273 psli = &phba->sli;
3274 icmd = &elsiocb->iocb;
3275
3276 if ((icmd->ulpStatus == IOSTAT_LOCAL_REJECT) &&
3277 ((icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING)) {
3278 /* Not enough posted buffers; Try posting more buffers */
3279 phba->fc_stat.NoRcvBuf++;
3280 lpfc_post_buffer(phba, pring, 0, 1);
3281 return;
3282 }
3283
3284 /* If there are no BDEs associated with this IOCB,
3285 * there is nothing to do.
3286 */
3287 if (icmd->ulpBdeCount == 0)
3288 return;
3289
3290 /* type of ELS cmd is first 32bit word in packet */
3291 mp = lpfc_sli_ringpostbuf_get(phba, pring, getPaddr(icmd->un.
3292 cont64[0].
3293 addrHigh,
3294 icmd->un.
3295 cont64[0].addrLow));
3296 if (mp == 0) {
3297 drop_cmd = 1;
3298 goto dropit;
3299 }
3300
3301 newnode = 0;
3302 lp = (uint32_t *) mp->virt;
3303 cmd = *lp++;
3304 lpfc_post_buffer(phba, &psli->ring[LPFC_ELS_RING], 1, 1);
3305
3306 if (icmd->ulpStatus) {
3307 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3308 kfree(mp);
3309 drop_cmd = 1;
3310 goto dropit;
3311 }
3312
3313 /* Check to see if link went down during discovery */
3314 if (lpfc_els_chk_latt(phba)) {
3315 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3316 kfree(mp);
3317 drop_cmd = 1;
3318 goto dropit;
3319 }
3320
3321 did = icmd->un.rcvels.remoteID;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003322 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, did);
3323 if (!ndlp) {
dea31012005-04-17 16:05:31 -05003324 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003325 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
3326 if (!ndlp) {
dea31012005-04-17 16:05:31 -05003327 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3328 kfree(mp);
3329 drop_cmd = 1;
3330 goto dropit;
3331 }
3332
3333 lpfc_nlp_init(phba, ndlp, did);
3334 newnode = 1;
3335 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) {
3336 ndlp->nlp_type |= NLP_FABRIC;
3337 }
3338 }
3339
3340 phba->fc_stat.elsRcvFrame++;
3341 elsiocb->context1 = ndlp;
3342 elsiocb->context2 = mp;
3343
3344 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
3345 cmd &= ELS_CMD_MASK;
3346 }
3347 /* ELS command <elsCmd> received from NPORT <did> */
3348 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
3349 "%d:0112 ELS command x%x received from NPORT x%x "
3350 "Data: x%x\n", phba->brd_no, cmd, did, phba->hba_state);
3351
3352 switch (cmd) {
3353 case ELS_CMD_PLOGI:
3354 phba->fc_stat.elsRcvPLOGI++;
3355 if (phba->hba_state < LPFC_DISC_AUTH) {
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04003356 rjt_err = 1;
dea31012005-04-17 16:05:31 -05003357 break;
3358 }
3359 lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_PLOGI);
3360 break;
3361 case ELS_CMD_FLOGI:
3362 phba->fc_stat.elsRcvFLOGI++;
3363 lpfc_els_rcv_flogi(phba, elsiocb, ndlp, newnode);
3364 if (newnode) {
3365 mempool_free( ndlp, phba->nlp_mem_pool);
3366 }
3367 break;
3368 case ELS_CMD_LOGO:
3369 phba->fc_stat.elsRcvLOGO++;
3370 if (phba->hba_state < LPFC_DISC_AUTH) {
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04003371 rjt_err = 1;
dea31012005-04-17 16:05:31 -05003372 break;
3373 }
3374 lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
3375 break;
3376 case ELS_CMD_PRLO:
3377 phba->fc_stat.elsRcvPRLO++;
3378 if (phba->hba_state < LPFC_DISC_AUTH) {
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04003379 rjt_err = 1;
dea31012005-04-17 16:05:31 -05003380 break;
3381 }
3382 lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
3383 break;
3384 case ELS_CMD_RSCN:
3385 phba->fc_stat.elsRcvRSCN++;
3386 lpfc_els_rcv_rscn(phba, elsiocb, ndlp, newnode);
3387 if (newnode) {
3388 mempool_free( ndlp, phba->nlp_mem_pool);
3389 }
3390 break;
3391 case ELS_CMD_ADISC:
3392 phba->fc_stat.elsRcvADISC++;
3393 if (phba->hba_state < LPFC_DISC_AUTH) {
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04003394 rjt_err = 1;
dea31012005-04-17 16:05:31 -05003395 break;
3396 }
3397 lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_ADISC);
3398 break;
3399 case ELS_CMD_PDISC:
3400 phba->fc_stat.elsRcvPDISC++;
3401 if (phba->hba_state < LPFC_DISC_AUTH) {
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04003402 rjt_err = 1;
dea31012005-04-17 16:05:31 -05003403 break;
3404 }
3405 lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_PDISC);
3406 break;
3407 case ELS_CMD_FARPR:
3408 phba->fc_stat.elsRcvFARPR++;
3409 lpfc_els_rcv_farpr(phba, elsiocb, ndlp);
3410 break;
3411 case ELS_CMD_FARP:
3412 phba->fc_stat.elsRcvFARP++;
3413 lpfc_els_rcv_farp(phba, elsiocb, ndlp);
3414 break;
3415 case ELS_CMD_FAN:
3416 phba->fc_stat.elsRcvFAN++;
3417 lpfc_els_rcv_fan(phba, elsiocb, ndlp);
3418 break;
dea31012005-04-17 16:05:31 -05003419 case ELS_CMD_PRLI:
3420 phba->fc_stat.elsRcvPRLI++;
3421 if (phba->hba_state < LPFC_DISC_AUTH) {
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04003422 rjt_err = 1;
dea31012005-04-17 16:05:31 -05003423 break;
3424 }
3425 lpfc_disc_state_machine(phba, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
3426 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003427 case ELS_CMD_LIRR:
3428 phba->fc_stat.elsRcvLIRR++;
3429 lpfc_els_rcv_lirr(phba, elsiocb, ndlp);
3430 if (newnode) {
3431 mempool_free( ndlp, phba->nlp_mem_pool);
3432 }
3433 break;
3434 case ELS_CMD_RPS:
3435 phba->fc_stat.elsRcvRPS++;
3436 lpfc_els_rcv_rps(phba, elsiocb, ndlp);
3437 if (newnode) {
3438 mempool_free( ndlp, phba->nlp_mem_pool);
3439 }
3440 break;
3441 case ELS_CMD_RPL:
3442 phba->fc_stat.elsRcvRPL++;
3443 lpfc_els_rcv_rpl(phba, elsiocb, ndlp);
3444 if (newnode) {
3445 mempool_free( ndlp, phba->nlp_mem_pool);
3446 }
3447 break;
dea31012005-04-17 16:05:31 -05003448 case ELS_CMD_RNID:
3449 phba->fc_stat.elsRcvRNID++;
3450 lpfc_els_rcv_rnid(phba, elsiocb, ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003451 if (newnode) {
3452 mempool_free( ndlp, phba->nlp_mem_pool);
3453 }
dea31012005-04-17 16:05:31 -05003454 break;
3455 default:
3456 /* Unsupported ELS command, reject */
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04003457 rjt_err = 1;
dea31012005-04-17 16:05:31 -05003458
3459 /* Unknown ELS command <elsCmd> received from NPORT <did> */
3460 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
3461 "%d:0115 Unknown ELS command x%x received from "
3462 "NPORT x%x\n", phba->brd_no, cmd, did);
3463 if (newnode) {
3464 mempool_free( ndlp, phba->nlp_mem_pool);
3465 }
3466 break;
3467 }
3468
3469 /* check if need to LS_RJT received ELS cmd */
3470 if (rjt_err) {
3471 stat.un.b.lsRjtRsvd0 = 0;
3472 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04003473 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
dea31012005-04-17 16:05:31 -05003474 stat.un.b.vendorUnique = 0;
3475 lpfc_els_rsp_reject(phba, stat.un.lsRjtError, elsiocb, ndlp);
3476 }
3477
3478 if (elsiocb->context2) {
3479 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3480 kfree(mp);
3481 }
3482dropit:
3483 /* check if need to drop received ELS cmd */
3484 if (drop_cmd == 1) {
3485 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
3486 "%d:0111 Dropping received ELS cmd "
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003487 "Data: x%x x%x x%x\n", phba->brd_no,
3488 icmd->ulpStatus, icmd->un.ulpWord[4],
3489 icmd->ulpTimeout);
dea31012005-04-17 16:05:31 -05003490 phba->fc_stat.elsRcvDrop++;
3491 }
3492 return;
3493}