blob: f5e002435972173dd37ab9ec975d11c95ab89e9d [file] [log] [blame]
dea31012005-04-17 16:05:31 -05001/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04003 * Fibre Channel Host Bus Adapters. *
James Smart9413aff2007-04-25 09:53:35 -04004 * Copyright (C) 2004-2007 Emulex. All rights reserved. *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04005 * EMULEX and SLI are trademarks of Emulex. *
dea31012005-04-17 16:05:31 -05006 * www.emulex.com *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04007 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea31012005-04-17 16:05:31 -05008 * *
9 * This program is free software; you can redistribute it and/or *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040010 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
dea31012005-04-17 16:05:31 -050020 *******************************************************************/
21
dea31012005-04-17 16:05:31 -050022#include <linux/blkdev.h>
23#include <linux/pci.h>
24#include <linux/interrupt.h>
25
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040026#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050027#include <scsi/scsi_device.h>
28#include <scsi/scsi_host.h>
29#include <scsi/scsi_transport_fc.h>
30
31#include "lpfc_hw.h"
32#include "lpfc_sli.h"
33#include "lpfc_disc.h"
34#include "lpfc_scsi.h"
35#include "lpfc.h"
36#include "lpfc_logmsg.h"
37#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050038#include "lpfc_vport.h"
James Smart858c9f62007-06-17 19:56:39 -050039#include "lpfc_debugfs.h"
dea31012005-04-17 16:05:31 -050040
41static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *,
42 struct lpfc_iocbq *);
James Smart92d7f7b2007-06-17 19:56:38 -050043static void lpfc_cmpl_fabric_iocb(struct lpfc_hba *, struct lpfc_iocbq *,
44 struct lpfc_iocbq *);
Adrian Bunka6ababd2007-11-05 18:07:33 +010045static void lpfc_fabric_abort_vport(struct lpfc_vport *vport);
46static int lpfc_issue_els_fdisc(struct lpfc_vport *vport,
47 struct lpfc_nodelist *ndlp, uint8_t retry);
48static int lpfc_issue_fabric_iocb(struct lpfc_hba *phba,
49 struct lpfc_iocbq *iocb);
50static void lpfc_register_new_vport(struct lpfc_hba *phba,
51 struct lpfc_vport *vport,
52 struct lpfc_nodelist *ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -050053
dea31012005-04-17 16:05:31 -050054static int lpfc_max_els_tries = 3;
55
James Smart858c9f62007-06-17 19:56:39 -050056int
James Smart2e0fef82007-06-17 19:56:36 -050057lpfc_els_chk_latt(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -050058{
James Smart2e0fef82007-06-17 19:56:36 -050059 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
60 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -050061 uint32_t ha_copy;
dea31012005-04-17 16:05:31 -050062
James Smart2e0fef82007-06-17 19:56:36 -050063 if (vport->port_state >= LPFC_VPORT_READY ||
64 phba->link_state == LPFC_LINK_DOWN)
dea31012005-04-17 16:05:31 -050065 return 0;
66
67 /* Read the HBA Host Attention Register */
dea31012005-04-17 16:05:31 -050068 ha_copy = readl(phba->HAregaddr);
dea31012005-04-17 16:05:31 -050069
70 if (!(ha_copy & HA_LATT))
71 return 0;
72
73 /* Pending Link Event during Discovery */
James Smarte8b62012007-08-02 11:10:09 -040074 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
75 "0237 Pending Link Event during "
76 "Discovery: State x%x\n",
77 phba->pport->port_state);
dea31012005-04-17 16:05:31 -050078
79 /* CLEAR_LA should re-enable link attention events and
80 * we should then imediately take a LATT event. The
81 * LATT processing should call lpfc_linkdown() which
82 * will cleanup any left over in-progress discovery
83 * events.
84 */
James Smart2e0fef82007-06-17 19:56:36 -050085 spin_lock_irq(shost->host_lock);
86 vport->fc_flag |= FC_ABORT_DISCOVERY;
87 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -050088
James Smart92d7f7b2007-06-17 19:56:38 -050089 if (phba->link_state != LPFC_CLEAR_LA)
James Smarted957682007-06-17 19:56:37 -050090 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -050091
Jamie Wellnitzc9f87352006-02-28 19:25:23 -050092 return 1;
dea31012005-04-17 16:05:31 -050093}
94
95static struct lpfc_iocbq *
James Smart2e0fef82007-06-17 19:56:36 -050096lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp,
97 uint16_t cmdSize, uint8_t retry,
98 struct lpfc_nodelist *ndlp, uint32_t did,
99 uint32_t elscmd)
dea31012005-04-17 16:05:31 -0500100{
James Smart2e0fef82007-06-17 19:56:36 -0500101 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400102 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -0500103 struct lpfc_dmabuf *pcmd, *prsp, *pbuflist;
104 struct ulp_bde64 *bpl;
105 IOCB_t *icmd;
106
dea31012005-04-17 16:05:31 -0500107
James Smart2e0fef82007-06-17 19:56:36 -0500108 if (!lpfc_is_link_up(phba))
109 return NULL;
dea31012005-04-17 16:05:31 -0500110
dea31012005-04-17 16:05:31 -0500111 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400112 elsiocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -0500113
114 if (elsiocb == NULL)
115 return NULL;
dea31012005-04-17 16:05:31 -0500116 icmd = &elsiocb->iocb;
117
118 /* fill in BDEs for command */
119 /* Allocate buffer for command payload */
James Smart98c9ea52007-10-27 13:37:33 -0400120 pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
121 if (pcmd)
122 pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys);
123 if (!pcmd || !pcmd->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -0800124 kfree(pcmd);
dea31012005-04-17 16:05:31 -0500125
James Bottomley604a3e32005-10-29 10:28:33 -0500126 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -0500127 return NULL;
128 }
129
130 INIT_LIST_HEAD(&pcmd->list);
131
132 /* Allocate buffer for response payload */
133 if (expectRsp) {
James Smart92d7f7b2007-06-17 19:56:38 -0500134 prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -0500135 if (prsp)
136 prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
137 &prsp->phys);
James Smart98c9ea52007-10-27 13:37:33 -0400138 if (!prsp || !prsp->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -0800139 kfree(prsp);
dea31012005-04-17 16:05:31 -0500140 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
141 kfree(pcmd);
James Bottomley604a3e32005-10-29 10:28:33 -0500142 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -0500143 return NULL;
144 }
145 INIT_LIST_HEAD(&prsp->list);
146 } else {
147 prsp = NULL;
148 }
149
150 /* Allocate buffer for Buffer ptr list */
James Smart92d7f7b2007-06-17 19:56:38 -0500151 pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -0500152 if (pbuflist)
James Smarted957682007-06-17 19:56:37 -0500153 pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
154 &pbuflist->phys);
James Smart98c9ea52007-10-27 13:37:33 -0400155 if (!pbuflist || !pbuflist->virt) {
James Bottomley604a3e32005-10-29 10:28:33 -0500156 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -0500157 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
158 lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
159 kfree(pcmd);
160 kfree(prsp);
Jesper Juhlc9475cb2005-11-07 01:01:26 -0800161 kfree(pbuflist);
dea31012005-04-17 16:05:31 -0500162 return NULL;
163 }
164
165 INIT_LIST_HEAD(&pbuflist->list);
166
167 icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
168 icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
169 icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BDL;
James Smart2e0fef82007-06-17 19:56:36 -0500170 icmd->un.elsreq64.remoteID = did; /* DID */
dea31012005-04-17 16:05:31 -0500171 if (expectRsp) {
James Smart92d7f7b2007-06-17 19:56:38 -0500172 icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
dea31012005-04-17 16:05:31 -0500173 icmd->ulpCommand = CMD_ELS_REQUEST64_CR;
James Smart2680eea2007-04-25 09:52:55 -0400174 icmd->ulpTimeout = phba->fc_ratov * 2;
dea31012005-04-17 16:05:31 -0500175 } else {
James Smart92d7f7b2007-06-17 19:56:38 -0500176 icmd->un.elsreq64.bdl.bdeSize = sizeof(struct ulp_bde64);
dea31012005-04-17 16:05:31 -0500177 icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
178 }
dea31012005-04-17 16:05:31 -0500179 icmd->ulpBdeCount = 1;
180 icmd->ulpLe = 1;
181 icmd->ulpClass = CLASS3;
182
James Smart92d7f7b2007-06-17 19:56:38 -0500183 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
184 icmd->un.elsreq64.myID = vport->fc_myDID;
185
186 /* For ELS_REQUEST64_CR, use the VPI by default */
187 icmd->ulpContext = vport->vpi;
188 icmd->ulpCt_h = 0;
189 icmd->ulpCt_l = 1;
190 }
191
dea31012005-04-17 16:05:31 -0500192 bpl = (struct ulp_bde64 *) pbuflist->virt;
193 bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys));
194 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys));
195 bpl->tus.f.bdeSize = cmdSize;
196 bpl->tus.f.bdeFlags = 0;
197 bpl->tus.w = le32_to_cpu(bpl->tus.w);
198
199 if (expectRsp) {
200 bpl++;
201 bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys));
202 bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys));
203 bpl->tus.f.bdeSize = FCELSSIZE;
204 bpl->tus.f.bdeFlags = BUFF_USE_RCV;
205 bpl->tus.w = le32_to_cpu(bpl->tus.w);
206 }
207
James Smart51ef4c22007-08-02 11:10:31 -0400208 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart329f9bc2007-04-25 09:53:01 -0400209 elsiocb->context2 = pcmd;
210 elsiocb->context3 = pbuflist;
dea31012005-04-17 16:05:31 -0500211 elsiocb->retry = retry;
James Smart2e0fef82007-06-17 19:56:36 -0500212 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -0500213 elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
214
215 if (prsp) {
216 list_add(&prsp->list, &pcmd->list);
217 }
dea31012005-04-17 16:05:31 -0500218 if (expectRsp) {
219 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400220 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
221 "0116 Xmit ELS command x%x to remote "
222 "NPORT x%x I/O tag: x%x, port state: x%x\n",
223 elscmd, did, elsiocb->iotag,
224 vport->port_state);
dea31012005-04-17 16:05:31 -0500225 } else {
226 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400227 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
228 "0117 Xmit ELS response x%x to remote "
229 "NPORT x%x I/O tag: x%x, size: x%x\n",
230 elscmd, ndlp->nlp_DID, elsiocb->iotag,
231 cmdSize);
dea31012005-04-17 16:05:31 -0500232 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500233 return elsiocb;
dea31012005-04-17 16:05:31 -0500234}
235
236
237static int
James Smart92d7f7b2007-06-17 19:56:38 -0500238lpfc_issue_fabric_reglogin(struct lpfc_vport *vport)
239{
240 struct lpfc_hba *phba = vport->phba;
241 LPFC_MBOXQ_t *mbox;
242 struct lpfc_dmabuf *mp;
243 struct lpfc_nodelist *ndlp;
244 struct serv_parm *sp;
245 int rc;
James Smart98c9ea52007-10-27 13:37:33 -0400246 int err = 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500247
248 sp = &phba->fc_fabparam;
249 ndlp = lpfc_findnode_did(vport, Fabric_DID);
James Smart98c9ea52007-10-27 13:37:33 -0400250 if (!ndlp) {
251 err = 1;
James Smart92d7f7b2007-06-17 19:56:38 -0500252 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400253 }
James Smart92d7f7b2007-06-17 19:56:38 -0500254
255 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart98c9ea52007-10-27 13:37:33 -0400256 if (!mbox) {
257 err = 2;
James Smart92d7f7b2007-06-17 19:56:38 -0500258 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400259 }
James Smart92d7f7b2007-06-17 19:56:38 -0500260
261 vport->port_state = LPFC_FABRIC_CFG_LINK;
262 lpfc_config_link(phba, mbox);
263 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
264 mbox->vport = vport;
265
James Smart0b727fe2007-10-27 13:37:25 -0400266 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart98c9ea52007-10-27 13:37:33 -0400267 if (rc == MBX_NOT_FINISHED) {
268 err = 3;
James Smart92d7f7b2007-06-17 19:56:38 -0500269 goto fail_free_mbox;
James Smart98c9ea52007-10-27 13:37:33 -0400270 }
James Smart92d7f7b2007-06-17 19:56:38 -0500271
272 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart98c9ea52007-10-27 13:37:33 -0400273 if (!mbox) {
274 err = 4;
James Smart92d7f7b2007-06-17 19:56:38 -0500275 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400276 }
James Smart92d7f7b2007-06-17 19:56:38 -0500277 rc = lpfc_reg_login(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox,
278 0);
James Smart98c9ea52007-10-27 13:37:33 -0400279 if (rc) {
280 err = 5;
James Smart92d7f7b2007-06-17 19:56:38 -0500281 goto fail_free_mbox;
James Smart98c9ea52007-10-27 13:37:33 -0400282 }
James Smart92d7f7b2007-06-17 19:56:38 -0500283
284 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
285 mbox->vport = vport;
286 mbox->context2 = lpfc_nlp_get(ndlp);
287
James Smart0b727fe2007-10-27 13:37:25 -0400288 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart98c9ea52007-10-27 13:37:33 -0400289 if (rc == MBX_NOT_FINISHED) {
290 err = 6;
James Smart92d7f7b2007-06-17 19:56:38 -0500291 goto fail_issue_reg_login;
James Smart98c9ea52007-10-27 13:37:33 -0400292 }
James Smart92d7f7b2007-06-17 19:56:38 -0500293
294 return 0;
295
296fail_issue_reg_login:
297 lpfc_nlp_put(ndlp);
298 mp = (struct lpfc_dmabuf *) mbox->context1;
299 lpfc_mbuf_free(phba, mp->virt, mp->phys);
300 kfree(mp);
301fail_free_mbox:
302 mempool_free(mbox, phba->mbox_mem_pool);
303
304fail:
305 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -0400306 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smart98c9ea52007-10-27 13:37:33 -0400307 "0249 Cannot issue Register Fabric login: Err %d\n", err);
James Smart92d7f7b2007-06-17 19:56:38 -0500308 return -ENXIO;
309}
310
311static int
James Smart2e0fef82007-06-17 19:56:36 -0500312lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
313 struct serv_parm *sp, IOCB_t *irsp)
dea31012005-04-17 16:05:31 -0500314{
James Smart2e0fef82007-06-17 19:56:36 -0500315 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
316 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -0500317 struct lpfc_nodelist *np;
318 struct lpfc_nodelist *next_np;
dea31012005-04-17 16:05:31 -0500319
James Smart2e0fef82007-06-17 19:56:36 -0500320 spin_lock_irq(shost->host_lock);
321 vport->fc_flag |= FC_FABRIC;
322 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500323
324 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
325 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
326 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
327
328 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
329
330 if (phba->fc_topology == TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500331 spin_lock_irq(shost->host_lock);
332 vport->fc_flag |= FC_PUBLIC_LOOP;
333 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500334 } else {
335 /*
336 * If we are a N-port connected to a Fabric, fixup sparam's so
337 * logins to devices on remote loops work.
338 */
James Smart2e0fef82007-06-17 19:56:36 -0500339 vport->fc_sparam.cmn.altBbCredit = 1;
dea31012005-04-17 16:05:31 -0500340 }
341
James Smart2e0fef82007-06-17 19:56:36 -0500342 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
dea31012005-04-17 16:05:31 -0500343 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
James Smart92d7f7b2007-06-17 19:56:38 -0500344 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500345 ndlp->nlp_class_sup = 0;
346 if (sp->cls1.classValid)
347 ndlp->nlp_class_sup |= FC_COS_CLASS1;
348 if (sp->cls2.classValid)
349 ndlp->nlp_class_sup |= FC_COS_CLASS2;
350 if (sp->cls3.classValid)
351 ndlp->nlp_class_sup |= FC_COS_CLASS3;
352 if (sp->cls4.classValid)
353 ndlp->nlp_class_sup |= FC_COS_CLASS4;
354 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
355 sp->cmn.bbRcvSizeLsb;
356 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
357
James Smart92d7f7b2007-06-17 19:56:38 -0500358 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
359 if (sp->cmn.response_multiple_NPort) {
James Smarte8b62012007-08-02 11:10:09 -0400360 lpfc_printf_vlog(vport, KERN_WARNING,
361 LOG_ELS | LOG_VPORT,
362 "1816 FLOGI NPIV supported, "
363 "response data 0x%x\n",
364 sp->cmn.response_multiple_NPort);
James Smart92d7f7b2007-06-17 19:56:38 -0500365 phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
James Smart92d7f7b2007-06-17 19:56:38 -0500366 } else {
367 /* Because we asked f/w for NPIV it still expects us
James Smarte8b62012007-08-02 11:10:09 -0400368 to call reg_vnpid atleast for the physcial host */
369 lpfc_printf_vlog(vport, KERN_WARNING,
370 LOG_ELS | LOG_VPORT,
371 "1817 Fabric does not support NPIV "
372 "- configuring single port mode.\n");
James Smart92d7f7b2007-06-17 19:56:38 -0500373 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
374 }
375 }
376
377 if ((vport->fc_prevDID != vport->fc_myDID) &&
378 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
379
380 /* If our NportID changed, we need to ensure all
381 * remaining NPORTs get unreg_login'ed.
382 */
383 list_for_each_entry_safe(np, next_np,
384 &vport->fc_nodes, nlp_listp) {
385 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
386 !(np->nlp_flag & NLP_NPR_ADISC))
387 continue;
388 spin_lock_irq(shost->host_lock);
389 np->nlp_flag &= ~NLP_NPR_ADISC;
390 spin_unlock_irq(shost->host_lock);
391 lpfc_unreg_rpi(vport, np);
392 }
393 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
394 lpfc_mbx_unreg_vpi(vport);
395 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
396 }
397 }
398
James Smart2e0fef82007-06-17 19:56:36 -0500399 ndlp->nlp_sid = irsp->un.ulpWord[4] & Mask_DID;
James Smart92d7f7b2007-06-17 19:56:38 -0500400 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -0500401
James Smart92d7f7b2007-06-17 19:56:38 -0500402 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
403 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) {
404 lpfc_register_new_vport(phba, vport, ndlp);
405 return 0;
406 }
407 lpfc_issue_fabric_reglogin(vport);
dea31012005-04-17 16:05:31 -0500408 return 0;
dea31012005-04-17 16:05:31 -0500409}
410
411/*
412 * We FLOGIed into an NPort, initiate pt2pt protocol
413 */
414static int
James Smart2e0fef82007-06-17 19:56:36 -0500415lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
416 struct serv_parm *sp)
dea31012005-04-17 16:05:31 -0500417{
James Smart2e0fef82007-06-17 19:56:36 -0500418 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
419 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500420 LPFC_MBOXQ_t *mbox;
421 int rc;
422
James Smart2e0fef82007-06-17 19:56:36 -0500423 spin_lock_irq(shost->host_lock);
424 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
425 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500426
427 phba->fc_edtov = FF_DEF_EDTOV;
428 phba->fc_ratov = FF_DEF_RATOV;
James Smart2e0fef82007-06-17 19:56:36 -0500429 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -0500430 sizeof(vport->fc_portname));
dea31012005-04-17 16:05:31 -0500431 if (rc >= 0) {
432 /* This side will initiate the PLOGI */
James Smart2e0fef82007-06-17 19:56:36 -0500433 spin_lock_irq(shost->host_lock);
434 vport->fc_flag |= FC_PT2PT_PLOGI;
435 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500436
437 /*
438 * N_Port ID cannot be 0, set our to LocalID the other
439 * side will be RemoteID.
440 */
441
442 /* not equal */
443 if (rc)
James Smart2e0fef82007-06-17 19:56:36 -0500444 vport->fc_myDID = PT2PT_LocalID;
dea31012005-04-17 16:05:31 -0500445
446 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
447 if (!mbox)
448 goto fail;
449
450 lpfc_config_link(phba, mbox);
451
452 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -0500453 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -0400454 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -0500455 if (rc == MBX_NOT_FINISHED) {
456 mempool_free(mbox, phba->mbox_mem_pool);
457 goto fail;
458 }
James Smart329f9bc2007-04-25 09:53:01 -0400459 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500460
James Smart2e0fef82007-06-17 19:56:36 -0500461 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
dea31012005-04-17 16:05:31 -0500462 if (!ndlp) {
463 /*
464 * Cannot find existing Fabric ndlp, so allocate a
465 * new one
466 */
467 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
468 if (!ndlp)
469 goto fail;
470
James Smart2e0fef82007-06-17 19:56:36 -0500471 lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID);
dea31012005-04-17 16:05:31 -0500472 }
473
474 memcpy(&ndlp->nlp_portname, &sp->portName,
James Smart2e0fef82007-06-17 19:56:36 -0500475 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500476 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
James Smart2e0fef82007-06-17 19:56:36 -0500477 sizeof(struct lpfc_name));
478 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
479 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500480 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500481 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500482 } else {
483 /* This side will wait for the PLOGI */
James Smart329f9bc2007-04-25 09:53:01 -0400484 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500485 }
486
James Smart2e0fef82007-06-17 19:56:36 -0500487 spin_lock_irq(shost->host_lock);
488 vport->fc_flag |= FC_PT2PT;
489 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500490
491 /* Start discovery - this should just do CLEAR_LA */
James Smart2e0fef82007-06-17 19:56:36 -0500492 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -0500493 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500494fail:
dea31012005-04-17 16:05:31 -0500495 return -ENXIO;
496}
497
498static void
James Smart329f9bc2007-04-25 09:53:01 -0400499lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
500 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500501{
James Smart2e0fef82007-06-17 19:56:36 -0500502 struct lpfc_vport *vport = cmdiocb->vport;
503 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500504 IOCB_t *irsp = &rspiocb->iocb;
505 struct lpfc_nodelist *ndlp = cmdiocb->context1;
506 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
507 struct serv_parm *sp;
508 int rc;
509
510 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500511 if (lpfc_els_chk_latt(vport)) {
James Smart329f9bc2007-04-25 09:53:01 -0400512 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500513 goto out;
514 }
515
James Smart858c9f62007-06-17 19:56:39 -0500516 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
517 "FLOGI cmpl: status:x%x/x%x state:x%x",
518 irsp->ulpStatus, irsp->un.ulpWord[4],
519 vport->port_state);
520
dea31012005-04-17 16:05:31 -0500521 if (irsp->ulpStatus) {
522 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -0500523 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -0500524 goto out;
James Smart2e0fef82007-06-17 19:56:36 -0500525
dea31012005-04-17 16:05:31 -0500526 /* FLOGI failed, so there is no fabric */
James Smart2e0fef82007-06-17 19:56:36 -0500527 spin_lock_irq(shost->host_lock);
528 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
529 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500530
James Smart329f9bc2007-04-25 09:53:01 -0400531 /* If private loop, then allow max outstanding els to be
dea31012005-04-17 16:05:31 -0500532 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
533 * alpa map would take too long otherwise.
534 */
535 if (phba->alpa_map[0] == 0) {
James Smart3de2a652007-08-02 11:09:59 -0400536 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
dea31012005-04-17 16:05:31 -0500537 }
538
539 /* FLOGI failure */
James Smarte8b62012007-08-02 11:10:09 -0400540 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
541 "0100 FLOGI failure Data: x%x x%x "
542 "x%x\n",
543 irsp->ulpStatus, irsp->un.ulpWord[4],
544 irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -0500545 goto flogifail;
546 }
547
548 /*
549 * The FLogI succeeded. Sync the data for the CPU before
550 * accessing it.
551 */
552 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
553
554 sp = prsp->virt + sizeof(uint32_t);
555
556 /* FLOGI completes successfully */
James Smarte8b62012007-08-02 11:10:09 -0400557 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
558 "0101 FLOGI completes sucessfully "
559 "Data: x%x x%x x%x x%x\n",
560 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
561 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution);
dea31012005-04-17 16:05:31 -0500562
James Smart2e0fef82007-06-17 19:56:36 -0500563 if (vport->port_state == LPFC_FLOGI) {
dea31012005-04-17 16:05:31 -0500564 /*
565 * If Common Service Parameters indicate Nport
566 * we are point to point, if Fport we are Fabric.
567 */
568 if (sp->cmn.fPort)
James Smart2e0fef82007-06-17 19:56:36 -0500569 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
dea31012005-04-17 16:05:31 -0500570 else
James Smart2e0fef82007-06-17 19:56:36 -0500571 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
dea31012005-04-17 16:05:31 -0500572
573 if (!rc)
574 goto out;
575 }
576
577flogifail:
James Smart329f9bc2007-04-25 09:53:01 -0400578 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500579
James Smart858c9f62007-06-17 19:56:39 -0500580 if (!lpfc_error_lost_link(irsp)) {
dea31012005-04-17 16:05:31 -0500581 /* FLOGI failed, so just use loop map to make discovery list */
James Smart2e0fef82007-06-17 19:56:36 -0500582 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -0500583
584 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500585 lpfc_disc_start(vport);
James Smart87af33f2007-10-27 13:37:43 -0400586 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
587 ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) &&
588 (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) &&
589 (phba->link_state != LPFC_CLEAR_LA)) {
590 /* If FLOGI failed enable link interrupt. */
591 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -0500592 }
dea31012005-04-17 16:05:31 -0500593out:
594 lpfc_els_free_iocb(phba, cmdiocb);
595}
596
597static int
James Smart2e0fef82007-06-17 19:56:36 -0500598lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -0500599 uint8_t retry)
600{
James Smart2e0fef82007-06-17 19:56:36 -0500601 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500602 struct serv_parm *sp;
603 IOCB_t *icmd;
604 struct lpfc_iocbq *elsiocb;
605 struct lpfc_sli_ring *pring;
606 uint8_t *pcmd;
607 uint16_t cmdsize;
608 uint32_t tmo;
609 int rc;
610
611 pring = &phba->sli.ring[LPFC_ELS_RING];
612
James Smart92d7f7b2007-06-17 19:56:38 -0500613 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart2e0fef82007-06-17 19:56:36 -0500614 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
615 ndlp->nlp_DID, ELS_CMD_FLOGI);
James Smart92d7f7b2007-06-17 19:56:38 -0500616
James Smart488d1462006-03-07 15:02:37 -0500617 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500618 return 1;
dea31012005-04-17 16:05:31 -0500619
620 icmd = &elsiocb->iocb;
621 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
622
623 /* For FLOGI request, remainder of payload is service parameters */
624 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -0500625 pcmd += sizeof(uint32_t);
626 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -0500627 sp = (struct serv_parm *) pcmd;
628
629 /* Setup CSPs accordingly for Fabric */
630 sp->cmn.e_d_tov = 0;
631 sp->cmn.w2.r_a_tov = 0;
632 sp->cls1.classValid = 0;
633 sp->cls2.seqDelivery = 1;
634 sp->cls3.seqDelivery = 1;
635 if (sp->cmn.fcphLow < FC_PH3)
636 sp->cmn.fcphLow = FC_PH3;
637 if (sp->cmn.fcphHigh < FC_PH3)
638 sp->cmn.fcphHigh = FC_PH3;
639
James Smart92d7f7b2007-06-17 19:56:38 -0500640 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
641 sp->cmn.request_multiple_Nport = 1;
642
643 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
644 icmd->ulpCt_h = 1;
645 icmd->ulpCt_l = 0;
646 }
647
James Smart858c9f62007-06-17 19:56:39 -0500648 if (phba->fc_topology != TOPOLOGY_LOOP) {
649 icmd->un.elsreq64.myID = 0;
650 icmd->un.elsreq64.fl = 1;
651 }
652
dea31012005-04-17 16:05:31 -0500653 tmo = phba->fc_ratov;
654 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
James Smart2e0fef82007-06-17 19:56:36 -0500655 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -0500656 phba->fc_ratov = tmo;
657
658 phba->fc_stat.elsXmitFLOGI++;
659 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
James Smart858c9f62007-06-17 19:56:39 -0500660
661 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
662 "Issue FLOGI: opt:x%x",
663 phba->sli3_options, 0, 0);
664
James Smart92d7f7b2007-06-17 19:56:38 -0500665 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
dea31012005-04-17 16:05:31 -0500666 if (rc == IOCB_ERROR) {
667 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500668 return 1;
dea31012005-04-17 16:05:31 -0500669 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500670 return 0;
dea31012005-04-17 16:05:31 -0500671}
672
673int
James Smart2e0fef82007-06-17 19:56:36 -0500674lpfc_els_abort_flogi(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500675{
676 struct lpfc_sli_ring *pring;
677 struct lpfc_iocbq *iocb, *next_iocb;
678 struct lpfc_nodelist *ndlp;
679 IOCB_t *icmd;
680
681 /* Abort outstanding I/O on NPort <nlp_DID> */
682 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -0400683 "0201 Abort outstanding I/O on NPort x%x\n",
684 Fabric_DID);
dea31012005-04-17 16:05:31 -0500685
686 pring = &phba->sli.ring[LPFC_ELS_RING];
687
688 /*
689 * Check the txcmplq for an iocb that matches the nport the driver is
690 * searching for.
691 */
James Smart2e0fef82007-06-17 19:56:36 -0500692 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500693 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
694 icmd = &iocb->iocb;
James Smart2e0fef82007-06-17 19:56:36 -0500695 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR &&
696 icmd->un.elsreq64.bdl.ulpIoTag32) {
dea31012005-04-17 16:05:31 -0500697 ndlp = (struct lpfc_nodelist *)(iocb->context1);
James Smart92d7f7b2007-06-17 19:56:38 -0500698 if (ndlp && (ndlp->nlp_DID == Fabric_DID)) {
James Smart07951072007-04-25 09:51:38 -0400699 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
James Smart92d7f7b2007-06-17 19:56:38 -0500700 }
dea31012005-04-17 16:05:31 -0500701 }
702 }
James Smart2e0fef82007-06-17 19:56:36 -0500703 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500704
705 return 0;
706}
707
708int
James Smart2e0fef82007-06-17 19:56:36 -0500709lpfc_initial_flogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -0500710{
James Smart2e0fef82007-06-17 19:56:36 -0500711 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500712 struct lpfc_nodelist *ndlp;
713
James Smart98c9ea52007-10-27 13:37:33 -0400714 vport->port_state = LPFC_FLOGI;
715 lpfc_set_disctmo(vport);
716
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500717 /* First look for the Fabric ndlp */
James Smart2e0fef82007-06-17 19:56:36 -0500718 ndlp = lpfc_findnode_did(vport, Fabric_DID);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500719 if (!ndlp) {
dea31012005-04-17 16:05:31 -0500720 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500721 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
722 if (!ndlp)
723 return 0;
James Smart2e0fef82007-06-17 19:56:36 -0500724 lpfc_nlp_init(vport, ndlp, Fabric_DID);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500725 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500726 lpfc_dequeue_node(vport, ndlp);
dea31012005-04-17 16:05:31 -0500727 }
James Smart87af33f2007-10-27 13:37:43 -0400728
James Smart2e0fef82007-06-17 19:56:36 -0500729 if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
James Smart329f9bc2007-04-25 09:53:01 -0400730 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500731 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500732 return 1;
dea31012005-04-17 16:05:31 -0500733}
734
James Smart92d7f7b2007-06-17 19:56:38 -0500735int
736lpfc_initial_fdisc(struct lpfc_vport *vport)
737{
738 struct lpfc_hba *phba = vport->phba;
739 struct lpfc_nodelist *ndlp;
740
741 /* First look for the Fabric ndlp */
742 ndlp = lpfc_findnode_did(vport, Fabric_DID);
743 if (!ndlp) {
744 /* Cannot find existing Fabric ndlp, so allocate a new one */
745 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
746 if (!ndlp)
747 return 0;
748 lpfc_nlp_init(vport, ndlp, Fabric_DID);
749 } else {
750 lpfc_dequeue_node(vport, ndlp);
751 }
752 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
753 lpfc_nlp_put(ndlp);
754 }
755 return 1;
756}
James Smart87af33f2007-10-27 13:37:43 -0400757
758void
James Smart2e0fef82007-06-17 19:56:36 -0500759lpfc_more_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -0500760{
761 int sentplogi;
762
James Smart2e0fef82007-06-17 19:56:36 -0500763 if (vport->num_disc_nodes)
764 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -0500765
766 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
James Smarte8b62012007-08-02 11:10:09 -0400767 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
768 "0232 Continue discovery with %d PLOGIs to go "
769 "Data: x%x x%x x%x\n",
770 vport->num_disc_nodes, vport->fc_plogi_cnt,
771 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -0500772 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -0500773 if (vport->fc_flag & FC_NLP_MORE)
774 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
775 sentplogi = lpfc_els_disc_plogi(vport);
776
dea31012005-04-17 16:05:31 -0500777 return;
778}
779
James Smart488d1462006-03-07 15:02:37 -0500780static struct lpfc_nodelist *
James Smart92d7f7b2007-06-17 19:56:38 -0500781lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
James Smart488d1462006-03-07 15:02:37 -0500782 struct lpfc_nodelist *ndlp)
783{
James Smart2e0fef82007-06-17 19:56:36 -0500784 struct lpfc_vport *vport = ndlp->vport;
James Smart488d1462006-03-07 15:02:37 -0500785 struct lpfc_nodelist *new_ndlp;
James Smart0ff10d42008-01-11 01:52:36 -0500786 struct lpfc_rport_data *rdata;
787 struct fc_rport *rport;
James Smart488d1462006-03-07 15:02:37 -0500788 struct serv_parm *sp;
James Smart92d7f7b2007-06-17 19:56:38 -0500789 uint8_t name[sizeof(struct lpfc_name)];
James Smart488d1462006-03-07 15:02:37 -0500790 uint32_t rc;
791
James Smart2fb9bd82006-12-02 13:33:57 -0500792 /* Fabric nodes can have the same WWPN so we don't bother searching
793 * by WWPN. Just return the ndlp that was given to us.
794 */
795 if (ndlp->nlp_type & NLP_FABRIC)
796 return ndlp;
797
James Smart92d7f7b2007-06-17 19:56:38 -0500798 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
James Smart685f0bf2007-04-25 09:53:08 -0400799 memset(name, 0, sizeof(struct lpfc_name));
James Smart488d1462006-03-07 15:02:37 -0500800
James Smart685f0bf2007-04-25 09:53:08 -0400801 /* Now we find out if the NPort we are logging into, matches the WWPN
James Smart488d1462006-03-07 15:02:37 -0500802 * we have for that ndlp. If not, we have some work to do.
803 */
James Smart2e0fef82007-06-17 19:56:36 -0500804 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
James Smart488d1462006-03-07 15:02:37 -0500805
James Smart92795652006-07-06 15:50:02 -0400806 if (new_ndlp == ndlp)
James Smart488d1462006-03-07 15:02:37 -0500807 return ndlp;
James Smart488d1462006-03-07 15:02:37 -0500808
809 if (!new_ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -0500810 rc = memcmp(&ndlp->nlp_portname, name,
811 sizeof(struct lpfc_name));
James Smart92795652006-07-06 15:50:02 -0400812 if (!rc)
813 return ndlp;
James Smart488d1462006-03-07 15:02:37 -0500814 new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
815 if (!new_ndlp)
816 return ndlp;
817
James Smart2e0fef82007-06-17 19:56:36 -0500818 lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID);
James Smart488d1462006-03-07 15:02:37 -0500819 }
820
James Smart2e0fef82007-06-17 19:56:36 -0500821 lpfc_unreg_rpi(vport, new_ndlp);
James Smart488d1462006-03-07 15:02:37 -0500822 new_ndlp->nlp_DID = ndlp->nlp_DID;
James Smart92795652006-07-06 15:50:02 -0400823 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
James Smart0ff10d42008-01-11 01:52:36 -0500824
825 if (ndlp->nlp_flag & NLP_NPR_2B_DISC)
826 new_ndlp->nlp_flag |= NLP_NPR_2B_DISC;
827 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
828
James Smart2e0fef82007-06-17 19:56:36 -0500829 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
James Smart488d1462006-03-07 15:02:37 -0500830
James Smart2e0fef82007-06-17 19:56:36 -0500831 /* Move this back to NPR state */
James Smart87af33f2007-10-27 13:37:43 -0400832 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
833 /* The new_ndlp is replacing ndlp totally, so we need
834 * to put ndlp on UNUSED list and try to free it.
835 */
James Smart0ff10d42008-01-11 01:52:36 -0500836
837 /* Fix up the rport accordingly */
838 rport = ndlp->rport;
839 if (rport) {
840 rdata = rport->dd_data;
841 if (rdata->pnode == ndlp) {
842 lpfc_nlp_put(ndlp);
843 ndlp->rport = NULL;
844 rdata->pnode = lpfc_nlp_get(new_ndlp);
845 new_ndlp->rport = rport;
846 }
847 new_ndlp->nlp_type = ndlp->nlp_type;
848 }
849
James Smart2e0fef82007-06-17 19:56:36 -0500850 lpfc_drop_node(vport, ndlp);
James Smart87af33f2007-10-27 13:37:43 -0400851 }
James Smart92795652006-07-06 15:50:02 -0400852 else {
James Smart2e0fef82007-06-17 19:56:36 -0500853 lpfc_unreg_rpi(vport, ndlp);
James Smart92795652006-07-06 15:50:02 -0400854 ndlp->nlp_DID = 0; /* Two ndlps cannot have the same did */
James Smart2e0fef82007-06-17 19:56:36 -0500855 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smart92795652006-07-06 15:50:02 -0400856 }
James Smart488d1462006-03-07 15:02:37 -0500857 return new_ndlp;
858}
859
James Smart87af33f2007-10-27 13:37:43 -0400860void
861lpfc_end_rscn(struct lpfc_vport *vport)
862{
863 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
864
865 if (vport->fc_flag & FC_RSCN_MODE) {
866 /*
867 * Check to see if more RSCNs came in while we were
868 * processing this one.
869 */
870 if (vport->fc_rscn_id_cnt ||
871 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
872 lpfc_els_handle_rscn(vport);
873 else {
874 spin_lock_irq(shost->host_lock);
875 vport->fc_flag &= ~FC_RSCN_MODE;
876 spin_unlock_irq(shost->host_lock);
877 }
878 }
879}
880
dea31012005-04-17 16:05:31 -0500881static void
James Smart2e0fef82007-06-17 19:56:36 -0500882lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
883 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500884{
James Smart2e0fef82007-06-17 19:56:36 -0500885 struct lpfc_vport *vport = cmdiocb->vport;
886 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500887 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -0500888 struct lpfc_nodelist *ndlp;
James Smart92795652006-07-06 15:50:02 -0400889 struct lpfc_dmabuf *prsp;
dea31012005-04-17 16:05:31 -0500890 int disc, rc, did, type;
891
dea31012005-04-17 16:05:31 -0500892 /* we pass cmdiocb to state machine which needs rspiocb as well */
893 cmdiocb->context_un.rsp_iocb = rspiocb;
894
895 irsp = &rspiocb->iocb;
James Smart858c9f62007-06-17 19:56:39 -0500896 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
897 "PLOGI cmpl: status:x%x/x%x did:x%x",
898 irsp->ulpStatus, irsp->un.ulpWord[4],
899 irsp->un.elsreq64.remoteID);
900
James Smart2e0fef82007-06-17 19:56:36 -0500901 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
James Smarted957682007-06-17 19:56:37 -0500902 if (!ndlp) {
James Smarte8b62012007-08-02 11:10:09 -0400903 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
904 "0136 PLOGI completes to NPort x%x "
905 "with no ndlp. Data: x%x x%x x%x\n",
906 irsp->un.elsreq64.remoteID,
907 irsp->ulpStatus, irsp->un.ulpWord[4],
908 irsp->ulpIoTag);
James Smart488d1462006-03-07 15:02:37 -0500909 goto out;
James Smarted957682007-06-17 19:56:37 -0500910 }
dea31012005-04-17 16:05:31 -0500911
912 /* Since ndlp can be freed in the disc state machine, note if this node
913 * is being used during discovery.
914 */
James Smart2e0fef82007-06-17 19:56:36 -0500915 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500916 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
James Smart488d1462006-03-07 15:02:37 -0500917 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500918 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500919 rc = 0;
920
921 /* PLOGI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -0400922 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
923 "0102 PLOGI completes to NPort x%x "
924 "Data: x%x x%x x%x x%x x%x\n",
925 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
926 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -0500927 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500928 if (lpfc_els_chk_latt(vport)) {
929 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500930 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500931 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500932 goto out;
933 }
934
935 /* ndlp could be freed in DSM, save these values now */
936 type = ndlp->nlp_type;
937 did = ndlp->nlp_DID;
938
939 if (irsp->ulpStatus) {
940 /* Check for retry */
941 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
942 /* ELS command is being retried */
943 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -0500944 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500945 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500946 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500947 }
948 goto out;
949 }
dea31012005-04-17 16:05:31 -0500950 /* PLOGI failed */
951 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart858c9f62007-06-17 19:56:39 -0500952 if (lpfc_error_lost_link(irsp)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500953 rc = NLP_STE_FREED_NODE;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500954 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500955 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -0500956 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -0500957 }
958 } else {
959 /* Good status, call state machine */
James Smart92795652006-07-06 15:50:02 -0400960 prsp = list_entry(((struct lpfc_dmabuf *)
James Smart92d7f7b2007-06-17 19:56:38 -0500961 cmdiocb->context2)->list.next,
962 struct lpfc_dmabuf, list);
963 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -0500964 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -0500965 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -0500966 }
967
James Smart2e0fef82007-06-17 19:56:36 -0500968 if (disc && vport->num_disc_nodes) {
dea31012005-04-17 16:05:31 -0500969 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -0500970 lpfc_more_plogi(vport);
dea31012005-04-17 16:05:31 -0500971
James Smart2e0fef82007-06-17 19:56:36 -0500972 if (vport->num_disc_nodes == 0) {
973 spin_lock_irq(shost->host_lock);
974 vport->fc_flag &= ~FC_NDISC_ACTIVE;
975 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500976
James Smart2e0fef82007-06-17 19:56:36 -0500977 lpfc_can_disctmo(vport);
James Smart87af33f2007-10-27 13:37:43 -0400978 lpfc_end_rscn(vport);
dea31012005-04-17 16:05:31 -0500979 }
980 }
981
982out:
983 lpfc_els_free_iocb(phba, cmdiocb);
984 return;
985}
986
987int
James Smart2e0fef82007-06-17 19:56:36 -0500988lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
dea31012005-04-17 16:05:31 -0500989{
James Smart2e0fef82007-06-17 19:56:36 -0500990 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500991 struct serv_parm *sp;
992 IOCB_t *icmd;
James Smart98c9ea52007-10-27 13:37:33 -0400993 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -0500994 struct lpfc_iocbq *elsiocb;
995 struct lpfc_sli_ring *pring;
996 struct lpfc_sli *psli;
997 uint8_t *pcmd;
998 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -0500999 int ret;
dea31012005-04-17 16:05:31 -05001000
1001 psli = &phba->sli;
1002 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1003
James Smart98c9ea52007-10-27 13:37:33 -04001004 ndlp = lpfc_findnode_did(vport, did);
1005 /* If ndlp if not NULL, we will bump the reference count on it */
1006
James Smart92d7f7b2007-06-17 19:56:38 -05001007 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart98c9ea52007-10-27 13:37:33 -04001008 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
James Smart2e0fef82007-06-17 19:56:36 -05001009 ELS_CMD_PLOGI);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001010 if (!elsiocb)
1011 return 1;
dea31012005-04-17 16:05:31 -05001012
1013 icmd = &elsiocb->iocb;
1014 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1015
1016 /* For PLOGI request, remainder of payload is service parameters */
1017 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001018 pcmd += sizeof(uint32_t);
1019 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001020 sp = (struct serv_parm *) pcmd;
1021
1022 if (sp->cmn.fcphLow < FC_PH_4_3)
1023 sp->cmn.fcphLow = FC_PH_4_3;
1024
1025 if (sp->cmn.fcphHigh < FC_PH3)
1026 sp->cmn.fcphHigh = FC_PH3;
1027
James Smart858c9f62007-06-17 19:56:39 -05001028 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1029 "Issue PLOGI: did:x%x",
1030 did, 0, 0);
1031
dea31012005-04-17 16:05:31 -05001032 phba->fc_stat.elsXmitPLOGI++;
1033 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
James Smart92d7f7b2007-06-17 19:56:38 -05001034 ret = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
1035
1036 if (ret == IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05001037 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001038 return 1;
dea31012005-04-17 16:05:31 -05001039 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001040 return 0;
dea31012005-04-17 16:05:31 -05001041}
1042
1043static void
James Smart2e0fef82007-06-17 19:56:36 -05001044lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1045 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001046{
James Smart2e0fef82007-06-17 19:56:36 -05001047 struct lpfc_vport *vport = cmdiocb->vport;
1048 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001049 IOCB_t *irsp;
1050 struct lpfc_sli *psli;
1051 struct lpfc_nodelist *ndlp;
1052
1053 psli = &phba->sli;
1054 /* we pass cmdiocb to state machine which needs rspiocb as well */
1055 cmdiocb->context_un.rsp_iocb = rspiocb;
1056
1057 irsp = &(rspiocb->iocb);
1058 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
James Smart2e0fef82007-06-17 19:56:36 -05001059 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001060 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001061 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001062
James Smart858c9f62007-06-17 19:56:39 -05001063 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1064 "PRLI cmpl: status:x%x/x%x did:x%x",
1065 irsp->ulpStatus, irsp->un.ulpWord[4],
1066 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05001067 /* PRLI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001068 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1069 "0103 PRLI completes to NPort x%x "
1070 "Data: x%x x%x x%x x%x\n",
1071 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1072 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001073
James Smart2e0fef82007-06-17 19:56:36 -05001074 vport->fc_prli_sent--;
dea31012005-04-17 16:05:31 -05001075 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001076 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05001077 goto out;
1078
1079 if (irsp->ulpStatus) {
1080 /* Check for retry */
1081 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1082 /* ELS command is being retried */
1083 goto out;
1084 }
1085 /* PRLI failed */
1086 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart858c9f62007-06-17 19:56:39 -05001087 if (lpfc_error_lost_link(irsp)) {
dea31012005-04-17 16:05:31 -05001088 goto out;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001089 } else {
James Smart2e0fef82007-06-17 19:56:36 -05001090 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001091 NLP_EVT_CMPL_PRLI);
dea31012005-04-17 16:05:31 -05001092 }
1093 } else {
1094 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05001095 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001096 NLP_EVT_CMPL_PRLI);
dea31012005-04-17 16:05:31 -05001097 }
1098
1099out:
1100 lpfc_els_free_iocb(phba, cmdiocb);
1101 return;
1102}
1103
1104int
James Smart2e0fef82007-06-17 19:56:36 -05001105lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001106 uint8_t retry)
1107{
James Smart2e0fef82007-06-17 19:56:36 -05001108 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1109 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001110 PRLI *npr;
1111 IOCB_t *icmd;
1112 struct lpfc_iocbq *elsiocb;
1113 struct lpfc_sli_ring *pring;
1114 struct lpfc_sli *psli;
1115 uint8_t *pcmd;
1116 uint16_t cmdsize;
1117
1118 psli = &phba->sli;
1119 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1120
James Smart92d7f7b2007-06-17 19:56:38 -05001121 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
James Smart2e0fef82007-06-17 19:56:36 -05001122 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1123 ndlp->nlp_DID, ELS_CMD_PRLI);
James Smart488d1462006-03-07 15:02:37 -05001124 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001125 return 1;
dea31012005-04-17 16:05:31 -05001126
1127 icmd = &elsiocb->iocb;
1128 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1129
1130 /* For PRLI request, remainder of payload is service parameters */
James Smart92d7f7b2007-06-17 19:56:38 -05001131 memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t)));
dea31012005-04-17 16:05:31 -05001132 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
James Smart92d7f7b2007-06-17 19:56:38 -05001133 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001134
1135 /* For PRLI, remainder of payload is PRLI parameter page */
1136 npr = (PRLI *) pcmd;
1137 /*
1138 * If our firmware version is 3.20 or later,
1139 * set the following bits for FC-TAPE support.
1140 */
1141 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
1142 npr->ConfmComplAllowed = 1;
1143 npr->Retry = 1;
1144 npr->TaskRetryIdReq = 1;
1145 }
1146 npr->estabImagePair = 1;
1147 npr->readXferRdyDis = 1;
1148
1149 /* For FCP support */
1150 npr->prliType = PRLI_FCP_TYPE;
1151 npr->initiatorFunc = 1;
1152
James Smart858c9f62007-06-17 19:56:39 -05001153 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1154 "Issue PRLI: did:x%x",
1155 ndlp->nlp_DID, 0, 0);
1156
dea31012005-04-17 16:05:31 -05001157 phba->fc_stat.elsXmitPRLI++;
1158 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
James Smart2e0fef82007-06-17 19:56:36 -05001159 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001160 ndlp->nlp_flag |= NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001161 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001162 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05001163 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001164 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001165 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001166 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001167 return 1;
dea31012005-04-17 16:05:31 -05001168 }
James Smart2e0fef82007-06-17 19:56:36 -05001169 vport->fc_prli_sent++;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001170 return 0;
dea31012005-04-17 16:05:31 -05001171}
1172
James Smart0ff10d42008-01-11 01:52:36 -05001173void
James Smart2e0fef82007-06-17 19:56:36 -05001174lpfc_more_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001175{
1176 int sentadisc;
1177
James Smart2e0fef82007-06-17 19:56:36 -05001178 if (vport->num_disc_nodes)
1179 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001180 /* Continue discovery with <num_disc_nodes> ADISCs to go */
James Smarte8b62012007-08-02 11:10:09 -04001181 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1182 "0210 Continue discovery with %d ADISCs to go "
1183 "Data: x%x x%x x%x\n",
1184 vport->num_disc_nodes, vport->fc_adisc_cnt,
1185 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001186 /* Check to see if there are more ADISCs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001187 if (vport->fc_flag & FC_NLP_MORE) {
1188 lpfc_set_disctmo(vport);
1189 /* go thru NPR nodes and issue any remaining ELS ADISCs */
1190 sentadisc = lpfc_els_disc_adisc(vport);
dea31012005-04-17 16:05:31 -05001191 }
1192 return;
1193}
1194
1195static void
James Smart2e0fef82007-06-17 19:56:36 -05001196lpfc_rscn_disc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001197{
James Smart858c9f62007-06-17 19:56:39 -05001198 lpfc_can_disctmo(vport);
1199
dea31012005-04-17 16:05:31 -05001200 /* RSCN discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001201 /* go thru NPR nodes and issue ELS PLOGIs */
1202 if (vport->fc_npr_cnt)
1203 if (lpfc_els_disc_plogi(vport))
dea31012005-04-17 16:05:31 -05001204 return;
James Smart2e0fef82007-06-17 19:56:36 -05001205
James Smart87af33f2007-10-27 13:37:43 -04001206 lpfc_end_rscn(vport);
dea31012005-04-17 16:05:31 -05001207}
1208
1209static void
James Smart2e0fef82007-06-17 19:56:36 -05001210lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1211 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001212{
James Smart2e0fef82007-06-17 19:56:36 -05001213 struct lpfc_vport *vport = cmdiocb->vport;
1214 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001215 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001216 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001217 int disc;
dea31012005-04-17 16:05:31 -05001218
1219 /* we pass cmdiocb to state machine which needs rspiocb as well */
1220 cmdiocb->context_un.rsp_iocb = rspiocb;
1221
1222 irsp = &(rspiocb->iocb);
1223 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
dea31012005-04-17 16:05:31 -05001224
James Smart858c9f62007-06-17 19:56:39 -05001225 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1226 "ADISC cmpl: status:x%x/x%x did:x%x",
1227 irsp->ulpStatus, irsp->un.ulpWord[4],
1228 ndlp->nlp_DID);
1229
dea31012005-04-17 16:05:31 -05001230 /* Since ndlp can be freed in the disc state machine, note if this node
1231 * is being used during discovery.
1232 */
James Smart2e0fef82007-06-17 19:56:36 -05001233 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001234 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001235 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001236 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001237 /* ADISC completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001238 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1239 "0104 ADISC completes to NPort x%x "
1240 "Data: x%x x%x x%x x%x x%x\n",
1241 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1242 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001243 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001244 if (lpfc_els_chk_latt(vport)) {
1245 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001246 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001247 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001248 goto out;
1249 }
1250
1251 if (irsp->ulpStatus) {
1252 /* Check for retry */
1253 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1254 /* ELS command is being retried */
1255 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05001256 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001257 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001258 spin_unlock_irq(shost->host_lock);
1259 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001260 }
1261 goto out;
1262 }
1263 /* ADISC failed */
1264 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart858c9f62007-06-17 19:56:39 -05001265 if (!lpfc_error_lost_link(irsp)) {
James Smart2e0fef82007-06-17 19:56:36 -05001266 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart858c9f62007-06-17 19:56:39 -05001267 NLP_EVT_CMPL_ADISC);
dea31012005-04-17 16:05:31 -05001268 }
1269 } else {
1270 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05001271 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
dea31012005-04-17 16:05:31 -05001272 NLP_EVT_CMPL_ADISC);
1273 }
1274
James Smart2e0fef82007-06-17 19:56:36 -05001275 if (disc && vport->num_disc_nodes) {
dea31012005-04-17 16:05:31 -05001276 /* Check to see if there are more ADISCs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001277 lpfc_more_adisc(vport);
dea31012005-04-17 16:05:31 -05001278
1279 /* Check to see if we are done with ADISC authentication */
James Smart2e0fef82007-06-17 19:56:36 -05001280 if (vport->num_disc_nodes == 0) {
James Smart92d7f7b2007-06-17 19:56:38 -05001281 /* If we get here, there is nothing left to ADISC */
1282 /*
1283 * For NPIV, cmpl_reg_vpi will set port_state to READY,
1284 * and continue discovery.
1285 */
1286 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
1287 !(vport->fc_flag & FC_RSCN_MODE)) {
1288 lpfc_issue_reg_vpi(phba, vport);
1289 goto out;
1290 }
1291 /*
1292 * For SLI2, we need to set port_state to READY
1293 * and continue discovery.
1294 */
1295 if (vport->port_state < LPFC_VPORT_READY) {
1296 /* If we get here, there is nothing to ADISC */
James Smarted957682007-06-17 19:56:37 -05001297 if (vport->port_type == LPFC_PHYSICAL_PORT)
James Smart2e0fef82007-06-17 19:56:36 -05001298 lpfc_issue_clear_la(phba, vport);
James Smart92d7f7b2007-06-17 19:56:38 -05001299
1300 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
1301 vport->num_disc_nodes = 0;
1302 /* go thru NPR list, issue ELS PLOGIs */
1303 if (vport->fc_npr_cnt)
1304 lpfc_els_disc_plogi(vport);
1305
1306 if (!vport->num_disc_nodes) {
1307 spin_lock_irq(shost->host_lock);
1308 vport->fc_flag &=
1309 ~FC_NDISC_ACTIVE;
1310 spin_unlock_irq(
1311 shost->host_lock);
1312 lpfc_can_disctmo(vport);
1313 }
1314 }
1315 vport->port_state = LPFC_VPORT_READY;
dea31012005-04-17 16:05:31 -05001316 } else {
James Smart2e0fef82007-06-17 19:56:36 -05001317 lpfc_rscn_disc(vport);
dea31012005-04-17 16:05:31 -05001318 }
1319 }
1320 }
dea31012005-04-17 16:05:31 -05001321out:
1322 lpfc_els_free_iocb(phba, cmdiocb);
1323 return;
1324}
1325
1326int
James Smart2e0fef82007-06-17 19:56:36 -05001327lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001328 uint8_t retry)
1329{
James Smart2e0fef82007-06-17 19:56:36 -05001330 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1331 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001332 ADISC *ap;
1333 IOCB_t *icmd;
1334 struct lpfc_iocbq *elsiocb;
James Smart2e0fef82007-06-17 19:56:36 -05001335 struct lpfc_sli *psli = &phba->sli;
1336 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05001337 uint8_t *pcmd;
1338 uint16_t cmdsize;
1339
James Smart92d7f7b2007-06-17 19:56:38 -05001340 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
James Smart2e0fef82007-06-17 19:56:36 -05001341 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1342 ndlp->nlp_DID, ELS_CMD_ADISC);
James Smart488d1462006-03-07 15:02:37 -05001343 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001344 return 1;
dea31012005-04-17 16:05:31 -05001345
1346 icmd = &elsiocb->iocb;
1347 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1348
1349 /* For ADISC request, remainder of payload is service parameters */
1350 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
James Smart92d7f7b2007-06-17 19:56:38 -05001351 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001352
1353 /* Fill in ADISC payload */
1354 ap = (ADISC *) pcmd;
1355 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05001356 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
1357 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05001358 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05001359
James Smart858c9f62007-06-17 19:56:39 -05001360 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1361 "Issue ADISC: did:x%x",
1362 ndlp->nlp_DID, 0, 0);
1363
dea31012005-04-17 16:05:31 -05001364 phba->fc_stat.elsXmitADISC++;
1365 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
James Smart2e0fef82007-06-17 19:56:36 -05001366 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001367 ndlp->nlp_flag |= NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001368 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001369 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05001370 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001371 ndlp->nlp_flag &= ~NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001372 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001373 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001374 return 1;
dea31012005-04-17 16:05:31 -05001375 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001376 return 0;
dea31012005-04-17 16:05:31 -05001377}
1378
1379static void
James Smart2e0fef82007-06-17 19:56:36 -05001380lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1381 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001382{
James Smart2e0fef82007-06-17 19:56:36 -05001383 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1384 struct lpfc_vport *vport = ndlp->vport;
1385 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001386 IOCB_t *irsp;
1387 struct lpfc_sli *psli;
dea31012005-04-17 16:05:31 -05001388
1389 psli = &phba->sli;
1390 /* we pass cmdiocb to state machine which needs rspiocb as well */
1391 cmdiocb->context_un.rsp_iocb = rspiocb;
1392
1393 irsp = &(rspiocb->iocb);
James Smart2e0fef82007-06-17 19:56:36 -05001394 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001395 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001396 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001397
James Smart858c9f62007-06-17 19:56:39 -05001398 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1399 "LOGO cmpl: status:x%x/x%x did:x%x",
1400 irsp->ulpStatus, irsp->un.ulpWord[4],
1401 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05001402 /* LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001403 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1404 "0105 LOGO completes to NPort x%x "
1405 "Data: x%x x%x x%x x%x\n",
1406 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1407 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001408 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001409 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05001410 goto out;
1411
James Smart92d7f7b2007-06-17 19:56:38 -05001412 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
1413 /* NLP_EVT_DEVICE_RM should unregister the RPI
1414 * which should abort all outstanding IOs.
1415 */
1416 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1417 NLP_EVT_DEVICE_RM);
1418 goto out;
1419 }
1420
dea31012005-04-17 16:05:31 -05001421 if (irsp->ulpStatus) {
1422 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -05001423 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -05001424 /* ELS command is being retried */
1425 goto out;
dea31012005-04-17 16:05:31 -05001426 /* LOGO failed */
1427 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart858c9f62007-06-17 19:56:39 -05001428 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05001429 goto out;
James Smart858c9f62007-06-17 19:56:39 -05001430 else
James Smart2e0fef82007-06-17 19:56:36 -05001431 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001432 NLP_EVT_CMPL_LOGO);
dea31012005-04-17 16:05:31 -05001433 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001434 /* Good status, call state machine.
1435 * This will unregister the rpi if needed.
1436 */
James Smart2e0fef82007-06-17 19:56:36 -05001437 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001438 NLP_EVT_CMPL_LOGO);
dea31012005-04-17 16:05:31 -05001439 }
1440
1441out:
1442 lpfc_els_free_iocb(phba, cmdiocb);
1443 return;
1444}
1445
1446int
James Smart2e0fef82007-06-17 19:56:36 -05001447lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001448 uint8_t retry)
1449{
James Smart2e0fef82007-06-17 19:56:36 -05001450 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1451 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001452 IOCB_t *icmd;
1453 struct lpfc_iocbq *elsiocb;
1454 struct lpfc_sli_ring *pring;
1455 struct lpfc_sli *psli;
1456 uint8_t *pcmd;
1457 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05001458 int rc;
dea31012005-04-17 16:05:31 -05001459
1460 psli = &phba->sli;
1461 pring = &psli->ring[LPFC_ELS_RING];
1462
James Smart98c9ea52007-10-27 13:37:33 -04001463 spin_lock_irq(shost->host_lock);
1464 if (ndlp->nlp_flag & NLP_LOGO_SND) {
1465 spin_unlock_irq(shost->host_lock);
1466 return 0;
1467 }
1468 spin_unlock_irq(shost->host_lock);
1469
James Smart92d7f7b2007-06-17 19:56:38 -05001470 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
James Smart2e0fef82007-06-17 19:56:36 -05001471 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1472 ndlp->nlp_DID, ELS_CMD_LOGO);
James Smart488d1462006-03-07 15:02:37 -05001473 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001474 return 1;
dea31012005-04-17 16:05:31 -05001475
1476 icmd = &elsiocb->iocb;
1477 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1478 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
James Smart92d7f7b2007-06-17 19:56:38 -05001479 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001480
1481 /* Fill in LOGO payload */
James Smart2e0fef82007-06-17 19:56:36 -05001482 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05001483 pcmd += sizeof(uint32_t);
1484 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05001485
James Smart858c9f62007-06-17 19:56:39 -05001486 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1487 "Issue LOGO: did:x%x",
1488 ndlp->nlp_DID, 0, 0);
1489
dea31012005-04-17 16:05:31 -05001490 phba->fc_stat.elsXmitLOGO++;
1491 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
James Smart2e0fef82007-06-17 19:56:36 -05001492 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001493 ndlp->nlp_flag |= NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001494 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05001495 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
1496
1497 if (rc == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05001498 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001499 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001500 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001501 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001502 return 1;
dea31012005-04-17 16:05:31 -05001503 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001504 return 0;
dea31012005-04-17 16:05:31 -05001505}
1506
1507static void
James Smart2e0fef82007-06-17 19:56:36 -05001508lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1509 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001510{
James Smart2e0fef82007-06-17 19:56:36 -05001511 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -05001512 IOCB_t *irsp;
1513
1514 irsp = &rspiocb->iocb;
1515
James Smart858c9f62007-06-17 19:56:39 -05001516 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1517 "ELS cmd cmpl: status:x%x/x%x did:x%x",
1518 irsp->ulpStatus, irsp->un.ulpWord[4],
1519 irsp->un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05001520 /* ELS cmd tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04001521 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1522 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
1523 irsp->ulpIoTag, irsp->ulpStatus,
1524 irsp->un.ulpWord[4], irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -05001525 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001526 lpfc_els_chk_latt(vport);
dea31012005-04-17 16:05:31 -05001527 lpfc_els_free_iocb(phba, cmdiocb);
1528 return;
1529}
1530
1531int
James Smart2e0fef82007-06-17 19:56:36 -05001532lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05001533{
James Smart2e0fef82007-06-17 19:56:36 -05001534 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001535 IOCB_t *icmd;
1536 struct lpfc_iocbq *elsiocb;
1537 struct lpfc_sli_ring *pring;
1538 struct lpfc_sli *psli;
1539 uint8_t *pcmd;
1540 uint16_t cmdsize;
1541 struct lpfc_nodelist *ndlp;
1542
1543 psli = &phba->sli;
1544 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
James Smart92d7f7b2007-06-17 19:56:38 -05001545 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001546 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1547 if (!ndlp)
1548 return 1;
dea31012005-04-17 16:05:31 -05001549
James Smart2e0fef82007-06-17 19:56:36 -05001550 lpfc_nlp_init(vport, ndlp, nportid);
dea31012005-04-17 16:05:31 -05001551
James Smart2e0fef82007-06-17 19:56:36 -05001552 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1553 ndlp->nlp_DID, ELS_CMD_SCR);
1554
James Smart488d1462006-03-07 15:02:37 -05001555 if (!elsiocb) {
James Smart329f9bc2007-04-25 09:53:01 -04001556 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001557 return 1;
dea31012005-04-17 16:05:31 -05001558 }
1559
1560 icmd = &elsiocb->iocb;
1561 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1562
1563 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
James Smart92d7f7b2007-06-17 19:56:38 -05001564 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001565
1566 /* For SCR, remainder of payload is SCR parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05001567 memset(pcmd, 0, sizeof(SCR));
dea31012005-04-17 16:05:31 -05001568 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
1569
James Smart858c9f62007-06-17 19:56:39 -05001570 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1571 "Issue SCR: did:x%x",
1572 ndlp->nlp_DID, 0, 0);
1573
dea31012005-04-17 16:05:31 -05001574 phba->fc_stat.elsXmitSCR++;
1575 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
dea31012005-04-17 16:05:31 -05001576 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
James Smart329f9bc2007-04-25 09:53:01 -04001577 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001578 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001579 return 1;
dea31012005-04-17 16:05:31 -05001580 }
James Smart329f9bc2007-04-25 09:53:01 -04001581 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001582 return 0;
dea31012005-04-17 16:05:31 -05001583}
1584
1585static int
James Smart2e0fef82007-06-17 19:56:36 -05001586lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05001587{
James Smart2e0fef82007-06-17 19:56:36 -05001588 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001589 IOCB_t *icmd;
1590 struct lpfc_iocbq *elsiocb;
1591 struct lpfc_sli_ring *pring;
1592 struct lpfc_sli *psli;
1593 FARP *fp;
1594 uint8_t *pcmd;
1595 uint32_t *lp;
1596 uint16_t cmdsize;
1597 struct lpfc_nodelist *ondlp;
1598 struct lpfc_nodelist *ndlp;
1599
1600 psli = &phba->sli;
1601 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
James Smart92d7f7b2007-06-17 19:56:38 -05001602 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001603 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1604 if (!ndlp)
1605 return 1;
dea31012005-04-17 16:05:31 -05001606
James Smart2e0fef82007-06-17 19:56:36 -05001607 lpfc_nlp_init(vport, ndlp, nportid);
1608
1609 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1610 ndlp->nlp_DID, ELS_CMD_RNID);
James Smart488d1462006-03-07 15:02:37 -05001611 if (!elsiocb) {
James Smart329f9bc2007-04-25 09:53:01 -04001612 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001613 return 1;
dea31012005-04-17 16:05:31 -05001614 }
1615
1616 icmd = &elsiocb->iocb;
1617 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1618
1619 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
James Smart92d7f7b2007-06-17 19:56:38 -05001620 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001621
1622 /* Fill in FARPR payload */
1623 fp = (FARP *) (pcmd);
James Smart92d7f7b2007-06-17 19:56:38 -05001624 memset(fp, 0, sizeof(FARP));
dea31012005-04-17 16:05:31 -05001625 lp = (uint32_t *) pcmd;
1626 *lp++ = be32_to_cpu(nportid);
James Smart2e0fef82007-06-17 19:56:36 -05001627 *lp++ = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05001628 fp->Rflags = 0;
1629 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
1630
James Smart92d7f7b2007-06-17 19:56:38 -05001631 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
1632 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05001633 ondlp = lpfc_findnode_did(vport, nportid);
1634 if (ondlp) {
dea31012005-04-17 16:05:31 -05001635 memcpy(&fp->OportName, &ondlp->nlp_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05001636 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05001637 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05001638 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05001639 }
1640
James Smart858c9f62007-06-17 19:56:39 -05001641 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1642 "Issue FARPR: did:x%x",
1643 ndlp->nlp_DID, 0, 0);
1644
dea31012005-04-17 16:05:31 -05001645 phba->fc_stat.elsXmitFARPR++;
1646 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
dea31012005-04-17 16:05:31 -05001647 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
James Smart329f9bc2007-04-25 09:53:01 -04001648 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001649 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001650 return 1;
dea31012005-04-17 16:05:31 -05001651 }
James Smart329f9bc2007-04-25 09:53:01 -04001652 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001653 return 0;
dea31012005-04-17 16:05:31 -05001654}
1655
1656void
James Smart2e0fef82007-06-17 19:56:36 -05001657lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
James Smartfdcebe22006-03-07 15:04:01 -05001658{
James Smart2e0fef82007-06-17 19:56:36 -05001659 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1660
1661 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05001662 nlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001663 spin_unlock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05001664 del_timer_sync(&nlp->nlp_delayfunc);
1665 nlp->nlp_last_elscmd = 0;
1666
1667 if (!list_empty(&nlp->els_retry_evt.evt_listp))
1668 list_del_init(&nlp->els_retry_evt.evt_listp);
1669
1670 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
James Smart2e0fef82007-06-17 19:56:36 -05001671 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05001672 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001673 spin_unlock_irq(shost->host_lock);
1674 if (vport->num_disc_nodes) {
James Smartfdcebe22006-03-07 15:04:01 -05001675 /* Check to see if there are more
1676 * PLOGIs to be sent
1677 */
James Smart2e0fef82007-06-17 19:56:36 -05001678 lpfc_more_plogi(vport);
James Smartfdcebe22006-03-07 15:04:01 -05001679
James Smart2e0fef82007-06-17 19:56:36 -05001680 if (vport->num_disc_nodes == 0) {
1681 spin_lock_irq(shost->host_lock);
1682 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1683 spin_unlock_irq(shost->host_lock);
1684 lpfc_can_disctmo(vport);
James Smarted957682007-06-17 19:56:37 -05001685 lpfc_end_rscn(vport);
James Smartfdcebe22006-03-07 15:04:01 -05001686 }
1687 }
1688 }
1689 return;
1690}
1691
1692void
dea31012005-04-17 16:05:31 -05001693lpfc_els_retry_delay(unsigned long ptr)
1694{
James Smart2e0fef82007-06-17 19:56:36 -05001695 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
1696 struct lpfc_vport *vport = ndlp->vport;
James Smart2e0fef82007-06-17 19:56:36 -05001697 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05001698 unsigned long flags;
James Smart2e0fef82007-06-17 19:56:36 -05001699 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
dea31012005-04-17 16:05:31 -05001700
James Smart2e0fef82007-06-17 19:56:36 -05001701 ndlp = (struct lpfc_nodelist *) ptr;
1702 phba = ndlp->vport->phba;
dea31012005-04-17 16:05:31 -05001703 evtp = &ndlp->els_retry_evt;
1704
James Smart92d7f7b2007-06-17 19:56:38 -05001705 spin_lock_irqsave(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05001706 if (!list_empty(&evtp->evt_listp)) {
James Smart92d7f7b2007-06-17 19:56:38 -05001707 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05001708 return;
1709 }
1710
1711 evtp->evt_arg1 = ndlp;
1712 evtp->evt = LPFC_EVT_ELS_RETRY;
1713 list_add_tail(&evtp->evt_listp, &phba->work_list);
1714 if (phba->work_wait)
James Smart92d7f7b2007-06-17 19:56:38 -05001715 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05001716
James Smart92d7f7b2007-06-17 19:56:38 -05001717 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05001718 return;
1719}
1720
1721void
1722lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
1723{
James Smart2e0fef82007-06-17 19:56:36 -05001724 struct lpfc_vport *vport = ndlp->vport;
1725 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1726 uint32_t cmd, did, retry;
dea31012005-04-17 16:05:31 -05001727
James Smart2e0fef82007-06-17 19:56:36 -05001728 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001729 did = ndlp->nlp_DID;
1730 cmd = ndlp->nlp_last_elscmd;
1731 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05001732
1733 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
James Smart2e0fef82007-06-17 19:56:36 -05001734 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001735 return;
1736 }
1737
1738 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001739 spin_unlock_irq(shost->host_lock);
James Smart1a169682006-03-07 15:04:06 -05001740 /*
1741 * If a discovery event readded nlp_delayfunc after timer
1742 * firing and before processing the timer, cancel the
1743 * nlp_delayfunc.
1744 */
1745 del_timer_sync(&ndlp->nlp_delayfunc);
dea31012005-04-17 16:05:31 -05001746 retry = ndlp->nlp_retry;
1747
1748 switch (cmd) {
1749 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05001750 lpfc_issue_els_flogi(vport, ndlp, retry);
dea31012005-04-17 16:05:31 -05001751 break;
1752 case ELS_CMD_PLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05001753 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001754 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001755 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05001756 }
dea31012005-04-17 16:05:31 -05001757 break;
1758 case ELS_CMD_ADISC:
James Smart2e0fef82007-06-17 19:56:36 -05001759 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001760 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001761 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05001762 }
dea31012005-04-17 16:05:31 -05001763 break;
1764 case ELS_CMD_PRLI:
James Smart2e0fef82007-06-17 19:56:36 -05001765 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001766 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001767 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05001768 }
dea31012005-04-17 16:05:31 -05001769 break;
1770 case ELS_CMD_LOGO:
James Smart2e0fef82007-06-17 19:56:36 -05001771 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001772 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001773 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05001774 }
dea31012005-04-17 16:05:31 -05001775 break;
James Smart92d7f7b2007-06-17 19:56:38 -05001776 case ELS_CMD_FDISC:
1777 lpfc_issue_els_fdisc(vport, ndlp, retry);
1778 break;
dea31012005-04-17 16:05:31 -05001779 }
1780 return;
1781}
1782
1783static int
James Smart2e0fef82007-06-17 19:56:36 -05001784lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1785 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001786{
James Smart2e0fef82007-06-17 19:56:36 -05001787 struct lpfc_vport *vport = cmdiocb->vport;
1788 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1789 IOCB_t *irsp = &rspiocb->iocb;
1790 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1791 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
dea31012005-04-17 16:05:31 -05001792 uint32_t *elscmd;
1793 struct ls_rjt stat;
James Smart2e0fef82007-06-17 19:56:36 -05001794 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
James Smart98c9ea52007-10-27 13:37:33 -04001795 int logerr = 0;
James Smart2e0fef82007-06-17 19:56:36 -05001796 uint32_t cmd = 0;
James Smart488d1462006-03-07 15:02:37 -05001797 uint32_t did;
dea31012005-04-17 16:05:31 -05001798
James Smart488d1462006-03-07 15:02:37 -05001799
dea31012005-04-17 16:05:31 -05001800 /* Note: context2 may be 0 for internal driver abort
1801 * of delays ELS command.
1802 */
1803
1804 if (pcmd && pcmd->virt) {
1805 elscmd = (uint32_t *) (pcmd->virt);
1806 cmd = *elscmd++;
1807 }
1808
James Smart329f9bc2007-04-25 09:53:01 -04001809 if (ndlp)
James Smart488d1462006-03-07 15:02:37 -05001810 did = ndlp->nlp_DID;
1811 else {
1812 /* We should only hit this case for retrying PLOGI */
1813 did = irsp->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05001814 ndlp = lpfc_findnode_did(vport, did);
James Smart488d1462006-03-07 15:02:37 -05001815 if (!ndlp && (cmd != ELS_CMD_PLOGI))
1816 return 1;
1817 }
1818
James Smart858c9f62007-06-17 19:56:39 -05001819 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1820 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
1821 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
1822
dea31012005-04-17 16:05:31 -05001823 switch (irsp->ulpStatus) {
1824 case IOSTAT_FCP_RSP_ERROR:
1825 case IOSTAT_REMOTE_STOP:
1826 break;
1827
1828 case IOSTAT_LOCAL_REJECT:
1829 switch ((irsp->un.ulpWord[4] & 0xff)) {
1830 case IOERR_LOOP_OPEN_FAILURE:
James Smart2e0fef82007-06-17 19:56:36 -05001831 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05001832 delay = 1000;
dea31012005-04-17 16:05:31 -05001833 retry = 1;
1834 break;
1835
James Smart92d7f7b2007-06-17 19:56:38 -05001836 case IOERR_ILLEGAL_COMMAND:
1837 if ((phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) &&
1838 (cmd == ELS_CMD_FDISC)) {
James Smarte8b62012007-08-02 11:10:09 -04001839 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1840 "0124 FDISC failed (3/6) "
1841 "retrying...\n");
James Smart92d7f7b2007-06-17 19:56:38 -05001842 lpfc_mbx_unreg_vpi(vport);
1843 retry = 1;
James Smart51ef4c22007-08-02 11:10:31 -04001844 /* FDISC retry policy */
1845 maxretry = 48;
1846 if (cmdiocb->retry >= 32)
1847 delay = 1000;
James Smart92d7f7b2007-06-17 19:56:38 -05001848 }
1849 break;
1850
dea31012005-04-17 16:05:31 -05001851 case IOERR_NO_RESOURCES:
James Smart98c9ea52007-10-27 13:37:33 -04001852 logerr = 1; /* HBA out of resources */
James Smart858c9f62007-06-17 19:56:39 -05001853 retry = 1;
1854 if (cmdiocb->retry > 100)
1855 delay = 100;
1856 maxretry = 250;
1857 break;
1858
1859 case IOERR_ILLEGAL_FRAME:
James Smart92d7f7b2007-06-17 19:56:38 -05001860 delay = 100;
dea31012005-04-17 16:05:31 -05001861 retry = 1;
1862 break;
1863
James Smart858c9f62007-06-17 19:56:39 -05001864 case IOERR_SEQUENCE_TIMEOUT:
dea31012005-04-17 16:05:31 -05001865 case IOERR_INVALID_RPI:
1866 retry = 1;
1867 break;
1868 }
1869 break;
1870
1871 case IOSTAT_NPORT_RJT:
1872 case IOSTAT_FABRIC_RJT:
1873 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
1874 retry = 1;
1875 break;
1876 }
1877 break;
1878
1879 case IOSTAT_NPORT_BSY:
1880 case IOSTAT_FABRIC_BSY:
James Smart98c9ea52007-10-27 13:37:33 -04001881 logerr = 1; /* Fabric / Remote NPort out of resources */
dea31012005-04-17 16:05:31 -05001882 retry = 1;
1883 break;
1884
1885 case IOSTAT_LS_RJT:
1886 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
1887 /* Added for Vendor specifc support
1888 * Just keep retrying for these Rsn / Exp codes
1889 */
1890 switch (stat.un.b.lsRjtRsnCode) {
1891 case LSRJT_UNABLE_TPC:
1892 if (stat.un.b.lsRjtRsnCodeExp ==
1893 LSEXP_CMD_IN_PROGRESS) {
1894 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05001895 delay = 1000;
dea31012005-04-17 16:05:31 -05001896 maxretry = 48;
1897 }
1898 retry = 1;
1899 break;
1900 }
1901 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05001902 delay = 1000;
dea31012005-04-17 16:05:31 -05001903 maxretry = lpfc_max_els_tries + 1;
1904 retry = 1;
1905 break;
1906 }
James Smart92d7f7b2007-06-17 19:56:38 -05001907 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
1908 (cmd == ELS_CMD_FDISC) &&
1909 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
James Smarte8b62012007-08-02 11:10:09 -04001910 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1911 "0125 FDISC Failed (x%x). "
1912 "Fabric out of resources\n",
1913 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05001914 lpfc_vport_set_state(vport,
1915 FC_VPORT_NO_FABRIC_RSCS);
1916 }
dea31012005-04-17 16:05:31 -05001917 break;
1918
1919 case LSRJT_LOGICAL_BSY:
James Smart858c9f62007-06-17 19:56:39 -05001920 if ((cmd == ELS_CMD_PLOGI) ||
1921 (cmd == ELS_CMD_PRLI)) {
James Smart92d7f7b2007-06-17 19:56:38 -05001922 delay = 1000;
dea31012005-04-17 16:05:31 -05001923 maxretry = 48;
James Smart92d7f7b2007-06-17 19:56:38 -05001924 } else if (cmd == ELS_CMD_FDISC) {
James Smart51ef4c22007-08-02 11:10:31 -04001925 /* FDISC retry policy */
1926 maxretry = 48;
1927 if (cmdiocb->retry >= 32)
1928 delay = 1000;
dea31012005-04-17 16:05:31 -05001929 }
1930 retry = 1;
1931 break;
James Smart92d7f7b2007-06-17 19:56:38 -05001932
1933 case LSRJT_LOGICAL_ERR:
1934 case LSRJT_PROTOCOL_ERR:
1935 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
1936 (cmd == ELS_CMD_FDISC) &&
1937 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
1938 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
1939 ) {
James Smarte8b62012007-08-02 11:10:09 -04001940 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1941 "0123 FDISC Failed (x%x). "
1942 "Fabric Detected Bad WWN\n",
1943 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05001944 lpfc_vport_set_state(vport,
1945 FC_VPORT_FABRIC_REJ_WWN);
1946 }
1947 break;
dea31012005-04-17 16:05:31 -05001948 }
1949 break;
1950
1951 case IOSTAT_INTERMED_RSP:
1952 case IOSTAT_BA_RJT:
1953 break;
1954
1955 default:
1956 break;
1957 }
1958
James Smart488d1462006-03-07 15:02:37 -05001959 if (did == FDMI_DID)
dea31012005-04-17 16:05:31 -05001960 retry = 1;
dea31012005-04-17 16:05:31 -05001961
James Smart98c9ea52007-10-27 13:37:33 -04001962 if ((cmd == ELS_CMD_FLOGI) &&
1963 (phba->fc_topology != TOPOLOGY_LOOP)) {
1964 /* FLOGI retry policy */
1965 retry = 1;
1966 maxretry = 48;
1967 if (cmdiocb->retry >= 32)
1968 delay = 1000;
1969 }
1970
dea31012005-04-17 16:05:31 -05001971 if ((++cmdiocb->retry) >= maxretry) {
1972 phba->fc_stat.elsRetryExceeded++;
1973 retry = 0;
1974 }
1975
James Smarted957682007-06-17 19:56:37 -05001976 if ((vport->load_flag & FC_UNLOADING) != 0)
1977 retry = 0;
1978
dea31012005-04-17 16:05:31 -05001979 if (retry) {
1980
1981 /* Retry ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04001982 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1983 "0107 Retry ELS command x%x to remote "
1984 "NPORT x%x Data: x%x x%x\n",
1985 cmd, did, cmdiocb->retry, delay);
dea31012005-04-17 16:05:31 -05001986
James Smart858c9f62007-06-17 19:56:39 -05001987 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
1988 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
1989 ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) {
1990 /* Don't reset timer for no resources */
1991
dea31012005-04-17 16:05:31 -05001992 /* If discovery / RSCN timer is running, reset it */
James Smart2e0fef82007-06-17 19:56:36 -05001993 if (timer_pending(&vport->fc_disctmo) ||
James Smart92d7f7b2007-06-17 19:56:38 -05001994 (vport->fc_flag & FC_RSCN_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05001995 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001996 }
1997
1998 phba->fc_stat.elsXmitRetry++;
James Smart488d1462006-03-07 15:02:37 -05001999 if (ndlp && delay) {
dea31012005-04-17 16:05:31 -05002000 phba->fc_stat.elsDelayRetry++;
2001 ndlp->nlp_retry = cmdiocb->retry;
2002
James Smart92d7f7b2007-06-17 19:56:38 -05002003 /* delay is specified in milliseconds */
2004 mod_timer(&ndlp->nlp_delayfunc,
2005 jiffies + msecs_to_jiffies(delay));
James Smart2e0fef82007-06-17 19:56:36 -05002006 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002007 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002008 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002009
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002010 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart858c9f62007-06-17 19:56:39 -05002011 if (cmd == ELS_CMD_PRLI)
2012 lpfc_nlp_set_state(vport, ndlp,
2013 NLP_STE_REG_LOGIN_ISSUE);
2014 else
2015 lpfc_nlp_set_state(vport, ndlp,
2016 NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05002017 ndlp->nlp_last_elscmd = cmd;
2018
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002019 return 1;
dea31012005-04-17 16:05:31 -05002020 }
2021 switch (cmd) {
2022 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002023 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002024 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -05002025 case ELS_CMD_FDISC:
2026 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
2027 return 1;
dea31012005-04-17 16:05:31 -05002028 case ELS_CMD_PLOGI:
James Smart488d1462006-03-07 15:02:37 -05002029 if (ndlp) {
2030 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002031 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04002032 NLP_STE_PLOGI_ISSUE);
James Smart488d1462006-03-07 15:02:37 -05002033 }
James Smart2e0fef82007-06-17 19:56:36 -05002034 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002035 return 1;
dea31012005-04-17 16:05:31 -05002036 case ELS_CMD_ADISC:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002037 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002038 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2039 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002040 return 1;
dea31012005-04-17 16:05:31 -05002041 case ELS_CMD_PRLI:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002042 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002043 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
2044 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002045 return 1;
dea31012005-04-17 16:05:31 -05002046 case ELS_CMD_LOGO:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002047 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002048 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2049 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002050 return 1;
dea31012005-04-17 16:05:31 -05002051 }
2052 }
dea31012005-04-17 16:05:31 -05002053 /* No retry ELS command <elsCmd> to remote NPORT <did> */
James Smart98c9ea52007-10-27 13:37:33 -04002054 if (logerr) {
2055 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2056 "0137 No retry ELS command x%x to remote "
2057 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
2058 cmd, did, irsp->ulpStatus,
2059 irsp->un.ulpWord[4]);
2060 }
2061 else {
2062 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smarta58cbd52007-08-02 11:09:43 -04002063 "0108 No retry ELS command x%x to remote "
2064 "NPORT x%x Retried:%d Error:x%x/%x\n",
2065 cmd, did, cmdiocb->retry, irsp->ulpStatus,
2066 irsp->un.ulpWord[4]);
James Smart98c9ea52007-10-27 13:37:33 -04002067 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002068 return 0;
dea31012005-04-17 16:05:31 -05002069}
2070
2071int
James Smart87af33f2007-10-27 13:37:43 -04002072lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
2073{
2074 struct lpfc_dmabuf *buf_ptr;
2075
2076 /* Free the response before processing the command. */
2077 if (!list_empty(&buf_ptr1->list)) {
2078 list_remove_head(&buf_ptr1->list, buf_ptr,
2079 struct lpfc_dmabuf,
2080 list);
2081 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
2082 kfree(buf_ptr);
2083 }
2084 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
2085 kfree(buf_ptr1);
2086 return 0;
2087}
2088
2089int
2090lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
2091{
2092 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
2093 kfree(buf_ptr);
2094 return 0;
2095}
2096
2097int
James Smart329f9bc2007-04-25 09:53:01 -04002098lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05002099{
2100 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
James Smarta8adb832007-10-27 13:37:53 -04002101 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05002102
James Smarta8adb832007-10-27 13:37:53 -04002103 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
2104 if (ndlp) {
2105 if (ndlp->nlp_flag & NLP_DEFER_RM) {
2106 lpfc_nlp_put(ndlp);
2107
2108 /* If the ndlp is not being used by another discovery
2109 * thread, free it.
2110 */
2111 if (!lpfc_nlp_not_used(ndlp)) {
2112 /* If ndlp is being used by another discovery
2113 * thread, just clear NLP_DEFER_RM
2114 */
2115 ndlp->nlp_flag &= ~NLP_DEFER_RM;
2116 }
2117 }
2118 else
2119 lpfc_nlp_put(ndlp);
James Smart329f9bc2007-04-25 09:53:01 -04002120 elsiocb->context1 = NULL;
2121 }
dea31012005-04-17 16:05:31 -05002122 /* context2 = cmd, context2->next = rsp, context3 = bpl */
2123 if (elsiocb->context2) {
James Smart0ff10d42008-01-11 01:52:36 -05002124 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
2125 /* Firmware could still be in progress of DMAing
2126 * payload, so don't free data buffer till after
2127 * a hbeat.
2128 */
2129 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
2130 buf_ptr = elsiocb->context2;
2131 elsiocb->context2 = NULL;
2132 if (buf_ptr) {
2133 buf_ptr1 = NULL;
2134 spin_lock_irq(&phba->hbalock);
2135 if (!list_empty(&buf_ptr->list)) {
2136 list_remove_head(&buf_ptr->list,
2137 buf_ptr1, struct lpfc_dmabuf,
2138 list);
2139 INIT_LIST_HEAD(&buf_ptr1->list);
2140 list_add_tail(&buf_ptr1->list,
2141 &phba->elsbuf);
2142 phba->elsbuf_cnt++;
2143 }
2144 INIT_LIST_HEAD(&buf_ptr->list);
2145 list_add_tail(&buf_ptr->list, &phba->elsbuf);
2146 phba->elsbuf_cnt++;
2147 spin_unlock_irq(&phba->hbalock);
2148 }
2149 } else {
2150 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
2151 lpfc_els_free_data(phba, buf_ptr1);
2152 }
dea31012005-04-17 16:05:31 -05002153 }
2154
2155 if (elsiocb->context3) {
2156 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
James Smart87af33f2007-10-27 13:37:43 -04002157 lpfc_els_free_bpl(phba, buf_ptr);
dea31012005-04-17 16:05:31 -05002158 }
James Bottomley604a3e32005-10-29 10:28:33 -05002159 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -05002160 return 0;
2161}
2162
2163static void
James Smart2e0fef82007-06-17 19:56:36 -05002164lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2165 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002166{
James Smart2e0fef82007-06-17 19:56:36 -05002167 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2168 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05002169 IOCB_t *irsp;
2170
2171 irsp = &rspiocb->iocb;
2172 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2173 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
2174 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05002175 /* ACC to LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002176 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2177 "0109 ACC to LOGO completes to NPort x%x "
2178 "Data: x%x x%x x%x\n",
2179 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2180 ndlp->nlp_rpi);
James Smart87af33f2007-10-27 13:37:43 -04002181
2182 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
2183 /* NPort Recovery mode or node is just allocated */
2184 if (!lpfc_nlp_not_used(ndlp)) {
2185 /* If the ndlp is being used by another discovery
2186 * thread, just unregister the RPI.
2187 */
2188 lpfc_unreg_rpi(vport, ndlp);
2189 }
dea31012005-04-17 16:05:31 -05002190 }
2191 lpfc_els_free_iocb(phba, cmdiocb);
2192 return;
2193}
2194
James Smart858c9f62007-06-17 19:56:39 -05002195void
2196lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
2197{
2198 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
2199 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
2200
2201 pmb->context1 = NULL;
2202 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2203 kfree(mp);
2204 mempool_free(pmb, phba->mbox_mem_pool);
James Smarta8adb832007-10-27 13:37:53 -04002205 if (ndlp) {
2206 lpfc_nlp_put(ndlp);
James Smart98c9ea52007-10-27 13:37:33 -04002207
James Smarta8adb832007-10-27 13:37:53 -04002208 /* This is the end of the default RPI cleanup logic for this
2209 * ndlp. If no other discovery threads are using this ndlp.
2210 * we should free all resources associated with it.
2211 */
2212 lpfc_nlp_not_used(ndlp);
2213 }
James Smart858c9f62007-06-17 19:56:39 -05002214 return;
2215}
2216
dea31012005-04-17 16:05:31 -05002217static void
James Smart858c9f62007-06-17 19:56:39 -05002218lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
James Smart329f9bc2007-04-25 09:53:01 -04002219 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002220{
James Smart2e0fef82007-06-17 19:56:36 -05002221 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2222 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
2223 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
James Smart87af33f2007-10-27 13:37:43 -04002224 IOCB_t *irsp;
2225 uint8_t *pcmd;
dea31012005-04-17 16:05:31 -05002226 LPFC_MBOXQ_t *mbox = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05002227 struct lpfc_dmabuf *mp = NULL;
James Smart87af33f2007-10-27 13:37:43 -04002228 uint32_t ls_rjt = 0;
dea31012005-04-17 16:05:31 -05002229
James Smart33ccf8d2006-08-17 11:57:58 -04002230 irsp = &rspiocb->iocb;
2231
dea31012005-04-17 16:05:31 -05002232 if (cmdiocb->context_un.mbox)
2233 mbox = cmdiocb->context_un.mbox;
2234
James Smart87af33f2007-10-27 13:37:43 -04002235 /* First determine if this is a LS_RJT cmpl */
2236 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
2237 if (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT) {
2238 /* A LS_RJT associated with Default RPI cleanup
2239 * has its own seperate code path.
2240 */
2241 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
2242 ls_rjt = 1;
2243 }
2244
dea31012005-04-17 16:05:31 -05002245 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002246 if (!ndlp || lpfc_els_chk_latt(vport)) {
dea31012005-04-17 16:05:31 -05002247 if (mbox) {
James Smart14691152006-12-02 13:34:28 -05002248 mp = (struct lpfc_dmabuf *) mbox->context1;
2249 if (mp) {
2250 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2251 kfree(mp);
2252 }
James Smart329f9bc2007-04-25 09:53:01 -04002253 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05002254 }
James Smart98c9ea52007-10-27 13:37:33 -04002255 if (ndlp && (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
2256 if (lpfc_nlp_not_used(ndlp))
2257 ndlp = NULL;
dea31012005-04-17 16:05:31 -05002258 goto out;
2259 }
2260
James Smart858c9f62007-06-17 19:56:39 -05002261 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smart51ef4c22007-08-02 11:10:31 -04002262 "ELS rsp cmpl: status:x%x/x%x did:x%x",
James Smart858c9f62007-06-17 19:56:39 -05002263 irsp->ulpStatus, irsp->un.ulpWord[4],
James Smart51ef4c22007-08-02 11:10:31 -04002264 cmdiocb->iocb.un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05002265 /* ELS response tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04002266 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2267 "0110 ELS response tag x%x completes "
2268 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
2269 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
2270 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
2271 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2272 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05002273 if (mbox) {
2274 if ((rspiocb->iocb.ulpStatus == 0)
2275 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
James Smart2e0fef82007-06-17 19:56:36 -05002276 lpfc_unreg_rpi(vport, ndlp);
James Smart329f9bc2007-04-25 09:53:01 -04002277 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05002278 mbox->vport = vport;
James Smart858c9f62007-06-17 19:56:39 -05002279 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
2280 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
2281 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
2282 }
2283 else {
2284 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
2285 ndlp->nlp_prev_state = ndlp->nlp_state;
2286 lpfc_nlp_set_state(vport, ndlp,
James Smart2e0fef82007-06-17 19:56:36 -05002287 NLP_STE_REG_LOGIN_ISSUE);
James Smart858c9f62007-06-17 19:56:39 -05002288 }
James Smart0b727fe2007-10-27 13:37:25 -04002289 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
dea31012005-04-17 16:05:31 -05002290 != MBX_NOT_FINISHED) {
2291 goto out;
2292 }
James Smart98c9ea52007-10-27 13:37:33 -04002293
2294 /* ELS rsp: Cannot issue reg_login for <NPortid> */
2295 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2296 "0138 ELS rsp: Cannot issue reg_login for x%x "
2297 "Data: x%x x%x x%x\n",
2298 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2299 ndlp->nlp_rpi);
2300
2301 if (lpfc_nlp_not_used(ndlp))
2302 ndlp = NULL;
dea31012005-04-17 16:05:31 -05002303 } else {
James Smart858c9f62007-06-17 19:56:39 -05002304 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
2305 if (!lpfc_error_lost_link(irsp) &&
2306 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
James Smart98c9ea52007-10-27 13:37:33 -04002307 if (lpfc_nlp_not_used(ndlp))
2308 ndlp = NULL;
dea31012005-04-17 16:05:31 -05002309 }
2310 }
James Smart14691152006-12-02 13:34:28 -05002311 mp = (struct lpfc_dmabuf *) mbox->context1;
2312 if (mp) {
2313 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2314 kfree(mp);
2315 }
2316 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05002317 }
2318out:
2319 if (ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05002320 spin_lock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05002321 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
James Smart2e0fef82007-06-17 19:56:36 -05002322 spin_unlock_irq(shost->host_lock);
James Smart87af33f2007-10-27 13:37:43 -04002323
2324 /* If the node is not being used by another discovery thread,
2325 * and we are sending a reject, we are done with it.
2326 * Release driver reference count here and free associated
2327 * resources.
2328 */
2329 if (ls_rjt)
2330 lpfc_nlp_not_used(ndlp);
dea31012005-04-17 16:05:31 -05002331 }
James Smart87af33f2007-10-27 13:37:43 -04002332
dea31012005-04-17 16:05:31 -05002333 lpfc_els_free_iocb(phba, cmdiocb);
2334 return;
2335}
2336
2337int
James Smart2e0fef82007-06-17 19:56:36 -05002338lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
2339 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
James Smart51ef4c22007-08-02 11:10:31 -04002340 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05002341{
James Smart2e0fef82007-06-17 19:56:36 -05002342 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2343 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002344 IOCB_t *icmd;
2345 IOCB_t *oldcmd;
2346 struct lpfc_iocbq *elsiocb;
2347 struct lpfc_sli_ring *pring;
2348 struct lpfc_sli *psli;
2349 uint8_t *pcmd;
2350 uint16_t cmdsize;
2351 int rc;
James Smart82d9a2a2006-04-15 11:53:05 -04002352 ELS_PKT *els_pkt_ptr;
dea31012005-04-17 16:05:31 -05002353
2354 psli = &phba->sli;
2355 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2356 oldcmd = &oldiocb->iocb;
2357
2358 switch (flag) {
2359 case ELS_CMD_ACC:
James Smart92d7f7b2007-06-17 19:56:38 -05002360 cmdsize = sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05002361 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
2362 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05002363 if (!elsiocb) {
James Smart2e0fef82007-06-17 19:56:36 -05002364 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002365 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05002366 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002367 return 1;
dea31012005-04-17 16:05:31 -05002368 }
James Smart2e0fef82007-06-17 19:56:36 -05002369
dea31012005-04-17 16:05:31 -05002370 icmd = &elsiocb->iocb;
2371 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2372 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2373 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05002374 pcmd += sizeof(uint32_t);
James Smart858c9f62007-06-17 19:56:39 -05002375
2376 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2377 "Issue ACC: did:x%x flg:x%x",
2378 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05002379 break;
2380 case ELS_CMD_PLOGI:
James Smart92d7f7b2007-06-17 19:56:38 -05002381 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
James Smart2e0fef82007-06-17 19:56:36 -05002382 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
2383 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05002384 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002385 return 1;
James Smart488d1462006-03-07 15:02:37 -05002386
dea31012005-04-17 16:05:31 -05002387 icmd = &elsiocb->iocb;
2388 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2389 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2390
2391 if (mbox)
2392 elsiocb->context_un.mbox = mbox;
2393
2394 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05002395 pcmd += sizeof(uint32_t);
2396 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
James Smart858c9f62007-06-17 19:56:39 -05002397
2398 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2399 "Issue ACC PLOGI: did:x%x flg:x%x",
2400 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05002401 break;
James Smart82d9a2a2006-04-15 11:53:05 -04002402 case ELS_CMD_PRLO:
James Smart92d7f7b2007-06-17 19:56:38 -05002403 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
James Smart2e0fef82007-06-17 19:56:36 -05002404 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
James Smart82d9a2a2006-04-15 11:53:05 -04002405 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
2406 if (!elsiocb)
2407 return 1;
2408
2409 icmd = &elsiocb->iocb;
2410 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2411 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2412
2413 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
James Smart92d7f7b2007-06-17 19:56:38 -05002414 sizeof(uint32_t) + sizeof(PRLO));
James Smart82d9a2a2006-04-15 11:53:05 -04002415 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
2416 els_pkt_ptr = (ELS_PKT *) pcmd;
2417 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
James Smart858c9f62007-06-17 19:56:39 -05002418
2419 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2420 "Issue ACC PRLO: did:x%x flg:x%x",
2421 ndlp->nlp_DID, ndlp->nlp_flag, 0);
James Smart82d9a2a2006-04-15 11:53:05 -04002422 break;
dea31012005-04-17 16:05:31 -05002423 default:
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002424 return 1;
dea31012005-04-17 16:05:31 -05002425 }
dea31012005-04-17 16:05:31 -05002426 /* Xmit ELS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04002427 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2428 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
2429 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n",
2430 elsiocb->iotag, elsiocb->iocb.ulpContext,
2431 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2432 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05002433 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
James Smart2e0fef82007-06-17 19:56:36 -05002434 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002435 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05002436 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002437 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
2438 } else {
James Smart858c9f62007-06-17 19:56:39 -05002439 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05002440 }
2441
2442 phba->fc_stat.elsXmitACC++;
dea31012005-04-17 16:05:31 -05002443 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
dea31012005-04-17 16:05:31 -05002444 if (rc == IOCB_ERROR) {
2445 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002446 return 1;
dea31012005-04-17 16:05:31 -05002447 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002448 return 0;
dea31012005-04-17 16:05:31 -05002449}
2450
2451int
James Smart2e0fef82007-06-17 19:56:36 -05002452lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
James Smart858c9f62007-06-17 19:56:39 -05002453 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
2454 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05002455{
James Smart2e0fef82007-06-17 19:56:36 -05002456 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002457 IOCB_t *icmd;
2458 IOCB_t *oldcmd;
2459 struct lpfc_iocbq *elsiocb;
2460 struct lpfc_sli_ring *pring;
2461 struct lpfc_sli *psli;
2462 uint8_t *pcmd;
2463 uint16_t cmdsize;
2464 int rc;
2465
2466 psli = &phba->sli;
2467 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2468
James Smart92d7f7b2007-06-17 19:56:38 -05002469 cmdsize = 2 * sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05002470 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
2471 ndlp->nlp_DID, ELS_CMD_LS_RJT);
James Smart488d1462006-03-07 15:02:37 -05002472 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002473 return 1;
dea31012005-04-17 16:05:31 -05002474
2475 icmd = &elsiocb->iocb;
2476 oldcmd = &oldiocb->iocb;
2477 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2478 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2479
2480 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
James Smart92d7f7b2007-06-17 19:56:38 -05002481 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002482 *((uint32_t *) (pcmd)) = rejectError;
2483
James Smart51ef4c22007-08-02 11:10:31 -04002484 if (mbox)
James Smart858c9f62007-06-17 19:56:39 -05002485 elsiocb->context_un.mbox = mbox;
James Smart858c9f62007-06-17 19:56:39 -05002486
dea31012005-04-17 16:05:31 -05002487 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04002488 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2489 "0129 Xmit ELS RJT x%x response tag x%x "
2490 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
2491 "rpi x%x\n",
2492 rejectError, elsiocb->iotag,
2493 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
2494 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05002495 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2496 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
2497 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
2498
dea31012005-04-17 16:05:31 -05002499 phba->fc_stat.elsXmitLSRJT++;
James Smart858c9f62007-06-17 19:56:39 -05002500 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05002501 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
James Smart51ef4c22007-08-02 11:10:31 -04002502
dea31012005-04-17 16:05:31 -05002503 if (rc == IOCB_ERROR) {
2504 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002505 return 1;
dea31012005-04-17 16:05:31 -05002506 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002507 return 0;
dea31012005-04-17 16:05:31 -05002508}
2509
2510int
James Smart2e0fef82007-06-17 19:56:36 -05002511lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
2512 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05002513{
James Smart2e0fef82007-06-17 19:56:36 -05002514 struct lpfc_hba *phba = vport->phba;
2515 struct lpfc_sli *psli = &phba->sli;
2516 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05002517 ADISC *ap;
James Smart2e0fef82007-06-17 19:56:36 -05002518 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05002519 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002520 uint8_t *pcmd;
2521 uint16_t cmdsize;
2522 int rc;
2523
James Smart92d7f7b2007-06-17 19:56:38 -05002524 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
James Smart2e0fef82007-06-17 19:56:36 -05002525 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
2526 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05002527 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002528 return 1;
dea31012005-04-17 16:05:31 -05002529
dea31012005-04-17 16:05:31 -05002530 icmd = &elsiocb->iocb;
2531 oldcmd = &oldiocb->iocb;
2532 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04002533
2534 /* Xmit ADISC ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04002535 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2536 "0130 Xmit ADISC ACC response iotag x%x xri: "
2537 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
2538 elsiocb->iotag, elsiocb->iocb.ulpContext,
2539 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2540 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05002541 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2542
2543 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05002544 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002545
2546 ap = (ADISC *) (pcmd);
2547 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05002548 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2549 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002550 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002551
James Smart858c9f62007-06-17 19:56:39 -05002552 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2553 "Issue ACC ADISC: did:x%x flg:x%x",
2554 ndlp->nlp_DID, ndlp->nlp_flag, 0);
2555
dea31012005-04-17 16:05:31 -05002556 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05002557 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05002558 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
dea31012005-04-17 16:05:31 -05002559 if (rc == IOCB_ERROR) {
2560 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002561 return 1;
dea31012005-04-17 16:05:31 -05002562 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002563 return 0;
dea31012005-04-17 16:05:31 -05002564}
2565
2566int
James Smart2e0fef82007-06-17 19:56:36 -05002567lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
James Smart5b8bd0c2007-04-25 09:52:49 -04002568 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05002569{
James Smart2e0fef82007-06-17 19:56:36 -05002570 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002571 PRLI *npr;
2572 lpfc_vpd_t *vpd;
2573 IOCB_t *icmd;
2574 IOCB_t *oldcmd;
2575 struct lpfc_iocbq *elsiocb;
2576 struct lpfc_sli_ring *pring;
2577 struct lpfc_sli *psli;
2578 uint8_t *pcmd;
2579 uint16_t cmdsize;
2580 int rc;
2581
2582 psli = &phba->sli;
2583 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2584
James Smart92d7f7b2007-06-17 19:56:38 -05002585 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
James Smart2e0fef82007-06-17 19:56:36 -05002586 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
James Smart92d7f7b2007-06-17 19:56:38 -05002587 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002588 if (!elsiocb)
2589 return 1;
dea31012005-04-17 16:05:31 -05002590
dea31012005-04-17 16:05:31 -05002591 icmd = &elsiocb->iocb;
2592 oldcmd = &oldiocb->iocb;
2593 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04002594 /* Xmit PRLI ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04002595 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2596 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
2597 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
2598 elsiocb->iotag, elsiocb->iocb.ulpContext,
2599 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2600 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05002601 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2602
2603 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
James Smart92d7f7b2007-06-17 19:56:38 -05002604 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002605
2606 /* For PRLI, remainder of payload is PRLI parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05002607 memset(pcmd, 0, sizeof(PRLI));
dea31012005-04-17 16:05:31 -05002608
2609 npr = (PRLI *) pcmd;
2610 vpd = &phba->vpd;
2611 /*
2612 * If our firmware version is 3.20 or later,
2613 * set the following bits for FC-TAPE support.
2614 */
2615 if (vpd->rev.feaLevelHigh >= 0x02) {
2616 npr->ConfmComplAllowed = 1;
2617 npr->Retry = 1;
2618 npr->TaskRetryIdReq = 1;
2619 }
2620
2621 npr->acceptRspCode = PRLI_REQ_EXECUTED;
2622 npr->estabImagePair = 1;
2623 npr->readXferRdyDis = 1;
2624 npr->ConfmComplAllowed = 1;
2625
2626 npr->prliType = PRLI_FCP_TYPE;
2627 npr->initiatorFunc = 1;
2628
James Smart858c9f62007-06-17 19:56:39 -05002629 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2630 "Issue ACC PRLI: did:x%x flg:x%x",
2631 ndlp->nlp_DID, ndlp->nlp_flag, 0);
2632
dea31012005-04-17 16:05:31 -05002633 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05002634 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05002635
dea31012005-04-17 16:05:31 -05002636 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
dea31012005-04-17 16:05:31 -05002637 if (rc == IOCB_ERROR) {
2638 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002639 return 1;
dea31012005-04-17 16:05:31 -05002640 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002641 return 0;
dea31012005-04-17 16:05:31 -05002642}
2643
2644static int
James Smart2e0fef82007-06-17 19:56:36 -05002645lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
James Smart329f9bc2007-04-25 09:53:01 -04002646 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05002647{
James Smart2e0fef82007-06-17 19:56:36 -05002648 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002649 RNID *rn;
James Smart2e0fef82007-06-17 19:56:36 -05002650 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05002651 struct lpfc_iocbq *elsiocb;
2652 struct lpfc_sli_ring *pring;
2653 struct lpfc_sli *psli;
2654 uint8_t *pcmd;
2655 uint16_t cmdsize;
2656 int rc;
2657
2658 psli = &phba->sli;
2659 pring = &psli->ring[LPFC_ELS_RING];
2660
James Smart92d7f7b2007-06-17 19:56:38 -05002661 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
2662 + (2 * sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002663 if (format)
James Smart92d7f7b2007-06-17 19:56:38 -05002664 cmdsize += sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05002665
James Smart2e0fef82007-06-17 19:56:36 -05002666 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
2667 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05002668 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002669 return 1;
dea31012005-04-17 16:05:31 -05002670
dea31012005-04-17 16:05:31 -05002671 icmd = &elsiocb->iocb;
2672 oldcmd = &oldiocb->iocb;
2673 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04002674 /* Xmit RNID ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04002675 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2676 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
2677 elsiocb->iotag, elsiocb->iocb.ulpContext);
dea31012005-04-17 16:05:31 -05002678 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
dea31012005-04-17 16:05:31 -05002679 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05002680 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002681
James Smart92d7f7b2007-06-17 19:56:38 -05002682 memset(pcmd, 0, sizeof(RNID));
dea31012005-04-17 16:05:31 -05002683 rn = (RNID *) (pcmd);
2684 rn->Format = format;
James Smart92d7f7b2007-06-17 19:56:38 -05002685 rn->CommonLen = (2 * sizeof(struct lpfc_name));
2686 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2687 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002688 switch (format) {
2689 case 0:
2690 rn->SpecificLen = 0;
2691 break;
2692 case RNID_TOPOLOGY_DISC:
James Smart92d7f7b2007-06-17 19:56:38 -05002693 rn->SpecificLen = sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05002694 memcpy(&rn->un.topologyDisc.portName,
James Smart92d7f7b2007-06-17 19:56:38 -05002695 &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002696 rn->un.topologyDisc.unitType = RNID_HBA;
2697 rn->un.topologyDisc.physPort = 0;
2698 rn->un.topologyDisc.attachedNodes = 0;
2699 break;
2700 default:
2701 rn->CommonLen = 0;
2702 rn->SpecificLen = 0;
2703 break;
2704 }
2705
James Smart858c9f62007-06-17 19:56:39 -05002706 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2707 "Issue ACC RNID: did:x%x flg:x%x",
2708 ndlp->nlp_DID, ndlp->nlp_flag, 0);
2709
dea31012005-04-17 16:05:31 -05002710 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05002711 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart329f9bc2007-04-25 09:53:01 -04002712 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002713 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
2714 * it could be freed */
2715
dea31012005-04-17 16:05:31 -05002716 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
dea31012005-04-17 16:05:31 -05002717 if (rc == IOCB_ERROR) {
2718 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002719 return 1;
dea31012005-04-17 16:05:31 -05002720 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002721 return 0;
dea31012005-04-17 16:05:31 -05002722}
2723
2724int
James Smart2e0fef82007-06-17 19:56:36 -05002725lpfc_els_disc_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002726{
James Smart2e0fef82007-06-17 19:56:36 -05002727 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002728 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05002729 int sentadisc = 0;
dea31012005-04-17 16:05:31 -05002730
James Smart685f0bf2007-04-25 09:53:08 -04002731 /* go thru NPR nodes and issue any remaining ELS ADISCs */
James Smart2e0fef82007-06-17 19:56:36 -05002732 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smart685f0bf2007-04-25 09:53:08 -04002733 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
2734 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
2735 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
James Smart2e0fef82007-06-17 19:56:36 -05002736 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04002737 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05002738 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04002739 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002740 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2741 lpfc_issue_els_adisc(vport, ndlp, 0);
James Smart685f0bf2007-04-25 09:53:08 -04002742 sentadisc++;
James Smart2e0fef82007-06-17 19:56:36 -05002743 vport->num_disc_nodes++;
2744 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04002745 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05002746 spin_lock_irq(shost->host_lock);
2747 vport->fc_flag |= FC_NLP_MORE;
2748 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04002749 break;
dea31012005-04-17 16:05:31 -05002750 }
2751 }
2752 }
2753 if (sentadisc == 0) {
James Smart2e0fef82007-06-17 19:56:36 -05002754 spin_lock_irq(shost->host_lock);
2755 vport->fc_flag &= ~FC_NLP_MORE;
2756 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002757 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002758 return sentadisc;
dea31012005-04-17 16:05:31 -05002759}
2760
2761int
James Smart2e0fef82007-06-17 19:56:36 -05002762lpfc_els_disc_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002763{
James Smart2e0fef82007-06-17 19:56:36 -05002764 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002765 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05002766 int sentplogi = 0;
dea31012005-04-17 16:05:31 -05002767
James Smart2e0fef82007-06-17 19:56:36 -05002768 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
2769 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smart685f0bf2007-04-25 09:53:08 -04002770 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
2771 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
2772 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
2773 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
2774 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002775 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2776 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
James Smart685f0bf2007-04-25 09:53:08 -04002777 sentplogi++;
James Smart2e0fef82007-06-17 19:56:36 -05002778 vport->num_disc_nodes++;
2779 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04002780 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05002781 spin_lock_irq(shost->host_lock);
2782 vport->fc_flag |= FC_NLP_MORE;
2783 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04002784 break;
dea31012005-04-17 16:05:31 -05002785 }
2786 }
2787 }
James Smart87af33f2007-10-27 13:37:43 -04002788 if (sentplogi) {
2789 lpfc_set_disctmo(vport);
2790 }
2791 else {
James Smart2e0fef82007-06-17 19:56:36 -05002792 spin_lock_irq(shost->host_lock);
2793 vport->fc_flag &= ~FC_NLP_MORE;
2794 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002795 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002796 return sentplogi;
dea31012005-04-17 16:05:31 -05002797}
2798
James Smart92d7f7b2007-06-17 19:56:38 -05002799void
James Smart2e0fef82007-06-17 19:56:36 -05002800lpfc_els_flush_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002801{
James Smart2e0fef82007-06-17 19:56:36 -05002802 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2803 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002804 int i;
2805
James Smart2e0fef82007-06-17 19:56:36 -05002806 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05002807 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
James Smart2e0fef82007-06-17 19:56:36 -05002808 vport->fc_rscn_id_list[i] = NULL;
dea31012005-04-17 16:05:31 -05002809 }
James Smart2e0fef82007-06-17 19:56:36 -05002810 spin_lock_irq(shost->host_lock);
2811 vport->fc_rscn_id_cnt = 0;
2812 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
2813 spin_unlock_irq(shost->host_lock);
2814 lpfc_can_disctmo(vport);
dea31012005-04-17 16:05:31 -05002815}
2816
2817int
James Smart2e0fef82007-06-17 19:56:36 -05002818lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05002819{
2820 D_ID ns_did;
2821 D_ID rscn_did;
dea31012005-04-17 16:05:31 -05002822 uint32_t *lp;
James Smart92d7f7b2007-06-17 19:56:38 -05002823 uint32_t payload_len, i;
dea31012005-04-17 16:05:31 -05002824
2825 ns_did.un.word = did;
dea31012005-04-17 16:05:31 -05002826
2827 /* Never match fabric nodes for RSCNs */
2828 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
James Smart2e0fef82007-06-17 19:56:36 -05002829 return 0;
dea31012005-04-17 16:05:31 -05002830
2831 /* If we are doing a FULL RSCN rediscovery, match everything */
James Smart2e0fef82007-06-17 19:56:36 -05002832 if (vport->fc_flag & FC_RSCN_DISCOVERY)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002833 return did;
dea31012005-04-17 16:05:31 -05002834
James Smart2e0fef82007-06-17 19:56:36 -05002835 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05002836 lp = vport->fc_rscn_id_list[i]->virt;
2837 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
2838 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05002839 while (payload_len) {
James Smart92d7f7b2007-06-17 19:56:38 -05002840 rscn_did.un.word = be32_to_cpu(*lp++);
2841 payload_len -= sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002842 switch (rscn_did.un.b.resv) {
2843 case 0: /* Single N_Port ID effected */
James Smart2e0fef82007-06-17 19:56:36 -05002844 if (ns_did.un.word == rscn_did.un.word)
James Smart92d7f7b2007-06-17 19:56:38 -05002845 return did;
dea31012005-04-17 16:05:31 -05002846 break;
2847 case 1: /* Whole N_Port Area effected */
2848 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
2849 && (ns_did.un.b.area == rscn_did.un.b.area))
James Smart92d7f7b2007-06-17 19:56:38 -05002850 return did;
dea31012005-04-17 16:05:31 -05002851 break;
2852 case 2: /* Whole N_Port Domain effected */
2853 if (ns_did.un.b.domain == rscn_did.un.b.domain)
James Smart92d7f7b2007-06-17 19:56:38 -05002854 return did;
dea31012005-04-17 16:05:31 -05002855 break;
2856 default:
James Smart2e0fef82007-06-17 19:56:36 -05002857 /* Unknown Identifier in RSCN node */
James Smarte8b62012007-08-02 11:10:09 -04002858 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
2859 "0217 Unknown Identifier in "
2860 "RSCN payload Data: x%x\n",
2861 rscn_did.un.word);
James Smart92d7f7b2007-06-17 19:56:38 -05002862 case 3: /* Whole Fabric effected */
2863 return did;
dea31012005-04-17 16:05:31 -05002864 }
2865 }
James Smart92d7f7b2007-06-17 19:56:38 -05002866 }
2867 return 0;
dea31012005-04-17 16:05:31 -05002868}
2869
2870static int
James Smart2e0fef82007-06-17 19:56:36 -05002871lpfc_rscn_recovery_check(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002872{
James Smart685f0bf2007-04-25 09:53:08 -04002873 struct lpfc_nodelist *ndlp = NULL;
dea31012005-04-17 16:05:31 -05002874
2875 /* Look at all nodes effected by pending RSCNs and move
James Smart685f0bf2007-04-25 09:53:08 -04002876 * them to NPR state.
dea31012005-04-17 16:05:31 -05002877 */
James Smart685f0bf2007-04-25 09:53:08 -04002878
James Smart2e0fef82007-06-17 19:56:36 -05002879 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smart685f0bf2007-04-25 09:53:08 -04002880 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE ||
James Smart2e0fef82007-06-17 19:56:36 -05002881 lpfc_rscn_payload_check(vport, ndlp->nlp_DID) == 0)
dea31012005-04-17 16:05:31 -05002882 continue;
2883
James Smart2e0fef82007-06-17 19:56:36 -05002884 lpfc_disc_state_machine(vport, ndlp, NULL,
James Smart92d7f7b2007-06-17 19:56:38 -05002885 NLP_EVT_DEVICE_RECOVERY);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002886
James Smart685f0bf2007-04-25 09:53:08 -04002887 /*
2888 * Make sure NLP_DELAY_TMO is NOT running after a device
2889 * recovery event.
2890 */
2891 if (ndlp->nlp_flag & NLP_DELAY_TMO)
James Smart2e0fef82007-06-17 19:56:36 -05002892 lpfc_cancel_retry_delay_tmo(vport, ndlp);
dea31012005-04-17 16:05:31 -05002893 }
James Smart685f0bf2007-04-25 09:53:08 -04002894
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002895 return 0;
dea31012005-04-17 16:05:31 -05002896}
2897
2898static int
James Smart2e0fef82007-06-17 19:56:36 -05002899lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04002900 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05002901{
James Smart2e0fef82007-06-17 19:56:36 -05002902 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2903 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002904 struct lpfc_dmabuf *pcmd;
James Smart92d7f7b2007-06-17 19:56:38 -05002905 uint32_t *lp, *datap;
dea31012005-04-17 16:05:31 -05002906 IOCB_t *icmd;
James Smart92d7f7b2007-06-17 19:56:38 -05002907 uint32_t payload_len, length, nportid, *cmd;
2908 int rscn_cnt = vport->fc_rscn_id_cnt;
2909 int rscn_id = 0, hba_id = 0;
James Smartd2873e42006-08-18 17:46:43 -04002910 int i;
dea31012005-04-17 16:05:31 -05002911
2912 icmd = &cmdiocb->iocb;
2913 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2914 lp = (uint32_t *) pcmd->virt;
2915
James Smart92d7f7b2007-06-17 19:56:38 -05002916 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
2917 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05002918 /* RSCN received */
James Smarte8b62012007-08-02 11:10:09 -04002919 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2920 "0214 RSCN received Data: x%x x%x x%x x%x\n",
2921 vport->fc_flag, payload_len, *lp, rscn_cnt);
James Smartd2873e42006-08-18 17:46:43 -04002922 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
James Smart2e0fef82007-06-17 19:56:36 -05002923 fc_host_post_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04002924 FCH_EVT_RSCN, lp[i]);
2925
dea31012005-04-17 16:05:31 -05002926 /* If we are about to begin discovery, just ACC the RSCN.
2927 * Discovery processing will satisfy it.
2928 */
James Smart2e0fef82007-06-17 19:56:36 -05002929 if (vport->port_state <= LPFC_NS_QRY) {
James Smart858c9f62007-06-17 19:56:39 -05002930 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
2931 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
2932 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
2933
James Smart51ef4c22007-08-02 11:10:31 -04002934 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002935 return 0;
dea31012005-04-17 16:05:31 -05002936 }
2937
James Smart92d7f7b2007-06-17 19:56:38 -05002938 /* If this RSCN just contains NPortIDs for other vports on this HBA,
2939 * just ACC and ignore it.
2940 */
2941 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart3de2a652007-08-02 11:09:59 -04002942 !(vport->cfg_peer_port_login)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002943 i = payload_len;
2944 datap = lp;
2945 while (i > 0) {
2946 nportid = *datap++;
2947 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
2948 i -= sizeof(uint32_t);
2949 rscn_id++;
James Smart549e55c2007-08-02 11:09:51 -04002950 if (lpfc_find_vport_by_did(phba, nportid))
2951 hba_id++;
James Smart92d7f7b2007-06-17 19:56:38 -05002952 }
2953 if (rscn_id == hba_id) {
2954 /* ALL NPortIDs in RSCN are on HBA */
James Smarte8b62012007-08-02 11:10:09 -04002955 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2956 "0214 Ignore RSCN "
2957 "Data: x%x x%x x%x x%x\n",
2958 vport->fc_flag, payload_len,
2959 *lp, rscn_cnt);
James Smart858c9f62007-06-17 19:56:39 -05002960 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
2961 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
2962 ndlp->nlp_DID, vport->port_state,
2963 ndlp->nlp_flag);
2964
James Smart92d7f7b2007-06-17 19:56:38 -05002965 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04002966 ndlp, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05002967 return 0;
2968 }
2969 }
2970
dea31012005-04-17 16:05:31 -05002971 /* If we are already processing an RSCN, save the received
2972 * RSCN payload buffer, cmdiocb->context2 to process later.
2973 */
James Smart2e0fef82007-06-17 19:56:36 -05002974 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
James Smart858c9f62007-06-17 19:56:39 -05002975 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
2976 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
2977 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
2978
James Smart92d7f7b2007-06-17 19:56:38 -05002979 vport->fc_flag |= FC_RSCN_DEFERRED;
2980 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
James Smart2e0fef82007-06-17 19:56:36 -05002981 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
2982 spin_lock_irq(shost->host_lock);
2983 vport->fc_flag |= FC_RSCN_MODE;
2984 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05002985 if (rscn_cnt) {
2986 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
2987 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
2988 }
2989 if ((rscn_cnt) &&
2990 (payload_len + length <= LPFC_BPL_SIZE)) {
2991 *cmd &= ELS_CMD_MASK;
2992 *cmd |= be32_to_cpu(payload_len + length);
2993 memcpy(((uint8_t *)cmd) + length, lp,
2994 payload_len);
2995 } else {
2996 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
2997 vport->fc_rscn_id_cnt++;
2998 /* If we zero, cmdiocb->context2, the calling
2999 * routine will not try to free it.
3000 */
3001 cmdiocb->context2 = NULL;
3002 }
dea31012005-04-17 16:05:31 -05003003
3004 /* Deferred RSCN */
James Smarte8b62012007-08-02 11:10:09 -04003005 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3006 "0235 Deferred RSCN "
3007 "Data: x%x x%x x%x\n",
3008 vport->fc_rscn_id_cnt, vport->fc_flag,
3009 vport->port_state);
dea31012005-04-17 16:05:31 -05003010 } else {
James Smart2e0fef82007-06-17 19:56:36 -05003011 spin_lock_irq(shost->host_lock);
3012 vport->fc_flag |= FC_RSCN_DISCOVERY;
3013 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003014 /* ReDiscovery RSCN */
James Smarte8b62012007-08-02 11:10:09 -04003015 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3016 "0234 ReDiscovery RSCN "
3017 "Data: x%x x%x x%x\n",
3018 vport->fc_rscn_id_cnt, vport->fc_flag,
3019 vport->port_state);
dea31012005-04-17 16:05:31 -05003020 }
3021 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04003022 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05003023
3024 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05003025 lpfc_rscn_recovery_check(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05003026 vport->fc_flag &= ~FC_RSCN_DEFERRED;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003027 return 0;
dea31012005-04-17 16:05:31 -05003028 }
3029
James Smart858c9f62007-06-17 19:56:39 -05003030 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3031 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
3032 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
3033
James Smart2e0fef82007-06-17 19:56:36 -05003034 spin_lock_irq(shost->host_lock);
3035 vport->fc_flag |= FC_RSCN_MODE;
3036 spin_unlock_irq(shost->host_lock);
3037 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
dea31012005-04-17 16:05:31 -05003038 /*
3039 * If we zero, cmdiocb->context2, the calling routine will
3040 * not try to free it.
3041 */
3042 cmdiocb->context2 = NULL;
3043
James Smart2e0fef82007-06-17 19:56:36 -05003044 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05003045
3046 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04003047 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05003048
3049 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05003050 lpfc_rscn_recovery_check(vport);
dea31012005-04-17 16:05:31 -05003051
James Smart2e0fef82007-06-17 19:56:36 -05003052 return lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05003053}
3054
3055int
James Smart2e0fef82007-06-17 19:56:36 -05003056lpfc_els_handle_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003057{
3058 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05003059 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003060
James Smart92d7f7b2007-06-17 19:56:38 -05003061 /* Ignore RSCN if the port is being torn down. */
3062 if (vport->load_flag & FC_UNLOADING) {
3063 lpfc_els_flush_rscn(vport);
3064 return 0;
3065 }
3066
dea31012005-04-17 16:05:31 -05003067 /* Start timer for RSCN processing */
James Smart2e0fef82007-06-17 19:56:36 -05003068 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05003069
3070 /* RSCN processed */
James Smarte8b62012007-08-02 11:10:09 -04003071 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3072 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
3073 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
3074 vport->port_state);
dea31012005-04-17 16:05:31 -05003075
3076 /* To process RSCN, first compare RSCN data with NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05003077 vport->fc_ns_retry = 0;
James Smart0ff10d42008-01-11 01:52:36 -05003078 vport->num_disc_nodes = 0;
3079
James Smart2e0fef82007-06-17 19:56:36 -05003080 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smart685f0bf2007-04-25 09:53:08 -04003081 if (ndlp && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
dea31012005-04-17 16:05:31 -05003082 /* Good ndlp, issue CT Request to NameServer */
James Smart92d7f7b2007-06-17 19:56:38 -05003083 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
dea31012005-04-17 16:05:31 -05003084 /* Wait for NameServer query cmpl before we can
3085 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003086 return 1;
dea31012005-04-17 16:05:31 -05003087 } else {
3088 /* If login to NameServer does not exist, issue one */
3089 /* Good status, issue PLOGI to NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05003090 ndlp = lpfc_findnode_did(vport, NameServer_DID);
3091 if (ndlp)
dea31012005-04-17 16:05:31 -05003092 /* Wait for NameServer login cmpl before we can
3093 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003094 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05003095
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003096 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
3097 if (!ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05003098 lpfc_els_flush_rscn(vport);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003099 return 0;
dea31012005-04-17 16:05:31 -05003100 } else {
James Smart2e0fef82007-06-17 19:56:36 -05003101 lpfc_nlp_init(vport, ndlp, NameServer_DID);
dea31012005-04-17 16:05:31 -05003102 ndlp->nlp_type |= NLP_FABRIC;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003103 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003104 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
3105 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
dea31012005-04-17 16:05:31 -05003106 /* Wait for NameServer login cmpl before we can
3107 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003108 return 1;
dea31012005-04-17 16:05:31 -05003109 }
3110 }
3111
James Smart2e0fef82007-06-17 19:56:36 -05003112 lpfc_els_flush_rscn(vport);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003113 return 0;
dea31012005-04-17 16:05:31 -05003114}
3115
3116static int
James Smart2e0fef82007-06-17 19:56:36 -05003117lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04003118 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003119{
James Smart2e0fef82007-06-17 19:56:36 -05003120 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3121 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003122 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3123 uint32_t *lp = (uint32_t *) pcmd->virt;
3124 IOCB_t *icmd = &cmdiocb->iocb;
3125 struct serv_parm *sp;
3126 LPFC_MBOXQ_t *mbox;
3127 struct ls_rjt stat;
3128 uint32_t cmd, did;
3129 int rc;
3130
3131 cmd = *lp++;
3132 sp = (struct serv_parm *) lp;
3133
3134 /* FLOGI received */
3135
James Smart2e0fef82007-06-17 19:56:36 -05003136 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05003137
3138 if (phba->fc_topology == TOPOLOGY_LOOP) {
3139 /* We should never receive a FLOGI in loop mode, ignore it */
3140 did = icmd->un.elsreq64.remoteID;
3141
3142 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
3143 Loop Mode */
James Smarte8b62012007-08-02 11:10:09 -04003144 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3145 "0113 An FLOGI ELS command x%x was "
3146 "received from DID x%x in Loop Mode\n",
3147 cmd, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003148 return 1;
dea31012005-04-17 16:05:31 -05003149 }
3150
3151 did = Fabric_DID;
3152
James Smart2e0fef82007-06-17 19:56:36 -05003153 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3))) {
dea31012005-04-17 16:05:31 -05003154 /* For a FLOGI we accept, then if our portname is greater
3155 * then the remote portname we initiate Nport login.
3156 */
3157
James Smart2e0fef82007-06-17 19:56:36 -05003158 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -05003159 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003160
3161 if (!rc) {
James Smart2e0fef82007-06-17 19:56:36 -05003162 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3163 if (!mbox)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003164 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05003165
dea31012005-04-17 16:05:31 -05003166 lpfc_linkdown(phba);
3167 lpfc_init_link(phba, mbox,
3168 phba->cfg_topology,
3169 phba->cfg_link_speed);
3170 mbox->mb.un.varInitLnk.lipsr_AL_PA = 0;
3171 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -05003172 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -04003173 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart5b8bd0c2007-04-25 09:52:49 -04003174 lpfc_set_loopback_flag(phba);
dea31012005-04-17 16:05:31 -05003175 if (rc == MBX_NOT_FINISHED) {
James Smart329f9bc2007-04-25 09:53:01 -04003176 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003177 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003178 return 1;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003179 } else if (rc > 0) { /* greater than */
James Smart2e0fef82007-06-17 19:56:36 -05003180 spin_lock_irq(shost->host_lock);
3181 vport->fc_flag |= FC_PT2PT_PLOGI;
3182 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003183 }
James Smart2e0fef82007-06-17 19:56:36 -05003184 spin_lock_irq(shost->host_lock);
3185 vport->fc_flag |= FC_PT2PT;
3186 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
3187 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003188 } else {
3189 /* Reject this request because invalid parameters */
3190 stat.un.b.lsRjtRsvd0 = 0;
3191 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3192 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
3193 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05003194 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
3195 NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003196 return 1;
dea31012005-04-17 16:05:31 -05003197 }
3198
3199 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04003200 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05003201
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003202 return 0;
dea31012005-04-17 16:05:31 -05003203}
3204
3205static int
James Smart2e0fef82007-06-17 19:56:36 -05003206lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3207 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003208{
3209 struct lpfc_dmabuf *pcmd;
3210 uint32_t *lp;
3211 IOCB_t *icmd;
3212 RNID *rn;
3213 struct ls_rjt stat;
3214 uint32_t cmd, did;
3215
3216 icmd = &cmdiocb->iocb;
3217 did = icmd->un.elsreq64.remoteID;
3218 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3219 lp = (uint32_t *) pcmd->virt;
3220
3221 cmd = *lp++;
3222 rn = (RNID *) lp;
3223
3224 /* RNID received */
3225
3226 switch (rn->Format) {
3227 case 0:
3228 case RNID_TOPOLOGY_DISC:
3229 /* Send back ACC */
James Smart2e0fef82007-06-17 19:56:36 -05003230 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05003231 break;
3232 default:
3233 /* Reject this request because format not supported */
3234 stat.un.b.lsRjtRsvd0 = 0;
3235 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3236 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
3237 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05003238 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
3239 NULL);
dea31012005-04-17 16:05:31 -05003240 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003241 return 0;
dea31012005-04-17 16:05:31 -05003242}
3243
3244static int
James Smart2e0fef82007-06-17 19:56:36 -05003245lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3246 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003247{
3248 struct ls_rjt stat;
3249
3250 /* For now, unconditionally reject this command */
3251 stat.un.b.lsRjtRsvd0 = 0;
3252 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3253 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
3254 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05003255 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003256 return 0;
3257}
3258
Jamie Wellnitz082c0262006-02-28 19:25:30 -05003259static void
James Smart329f9bc2007-04-25 09:53:01 -04003260lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003261{
James Smart2e0fef82007-06-17 19:56:36 -05003262 struct lpfc_sli *psli = &phba->sli;
3263 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003264 MAILBOX_t *mb;
3265 IOCB_t *icmd;
3266 RPS_RSP *rps_rsp;
3267 uint8_t *pcmd;
3268 struct lpfc_iocbq *elsiocb;
3269 struct lpfc_nodelist *ndlp;
3270 uint16_t xri, status;
3271 uint32_t cmdsize;
3272
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003273 mb = &pmb->mb;
3274
3275 ndlp = (struct lpfc_nodelist *) pmb->context2;
3276 xri = (uint16_t) ((unsigned long)(pmb->context1));
Randy Dunlap041976f2006-06-25 01:58:51 -07003277 pmb->context1 = NULL;
3278 pmb->context2 = NULL;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003279
3280 if (mb->mbxStatus) {
James Smart329f9bc2007-04-25 09:53:01 -04003281 mempool_free(pmb, phba->mbox_mem_pool);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003282 return;
3283 }
3284
3285 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
James Smart329f9bc2007-04-25 09:53:01 -04003286 mempool_free(pmb, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05003287 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
3288 lpfc_max_els_tries, ndlp,
3289 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart329f9bc2007-04-25 09:53:01 -04003290 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003291 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003292 return;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003293
3294 icmd = &elsiocb->iocb;
3295 icmd->ulpContext = xri;
3296
3297 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3298 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003299 pcmd += sizeof(uint32_t); /* Skip past command */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003300 rps_rsp = (RPS_RSP *)pcmd;
3301
3302 if (phba->fc_topology != TOPOLOGY_LOOP)
3303 status = 0x10;
3304 else
3305 status = 0x8;
James Smart2e0fef82007-06-17 19:56:36 -05003306 if (phba->pport->fc_flag & FC_FABRIC)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003307 status |= 0x4;
3308
3309 rps_rsp->rsvd1 = 0;
3310 rps_rsp->portStatus = be16_to_cpu(status);
3311 rps_rsp->linkFailureCnt = be32_to_cpu(mb->un.varRdLnk.linkFailureCnt);
3312 rps_rsp->lossSyncCnt = be32_to_cpu(mb->un.varRdLnk.lossSyncCnt);
3313 rps_rsp->lossSignalCnt = be32_to_cpu(mb->un.varRdLnk.lossSignalCnt);
3314 rps_rsp->primSeqErrCnt = be32_to_cpu(mb->un.varRdLnk.primSeqErrCnt);
3315 rps_rsp->invalidXmitWord = be32_to_cpu(mb->un.varRdLnk.invalidXmitWord);
3316 rps_rsp->crcCnt = be32_to_cpu(mb->un.varRdLnk.crcCnt);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003317 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003318 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
3319 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
3320 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
3321 elsiocb->iotag, elsiocb->iocb.ulpContext,
3322 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3323 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05003324 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003325 phba->fc_stat.elsXmitACC++;
James Smarted957682007-06-17 19:56:37 -05003326 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003327 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003328 return;
3329}
3330
3331static int
James Smart2e0fef82007-06-17 19:56:36 -05003332lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3333 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003334{
James Smart2e0fef82007-06-17 19:56:36 -05003335 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003336 uint32_t *lp;
3337 uint8_t flag;
3338 LPFC_MBOXQ_t *mbox;
3339 struct lpfc_dmabuf *pcmd;
3340 RPS *rps;
3341 struct ls_rjt stat;
3342
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003343 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
3344 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003345 stat.un.b.lsRjtRsvd0 = 0;
3346 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3347 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
3348 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05003349 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
3350 NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003351 }
3352
3353 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3354 lp = (uint32_t *) pcmd->virt;
3355 flag = (be32_to_cpu(*lp++) & 0xf);
3356 rps = (RPS *) lp;
3357
3358 if ((flag == 0) ||
3359 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
James Smart2e0fef82007-06-17 19:56:36 -05003360 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05003361 sizeof(struct lpfc_name)) == 0))) {
James Smart2e0fef82007-06-17 19:56:36 -05003362
James Smart92d7f7b2007-06-17 19:56:38 -05003363 printk("Fix me....\n");
3364 dump_stack();
James Smart2e0fef82007-06-17 19:56:36 -05003365 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
3366 if (mbox) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003367 lpfc_read_lnk_stat(phba, mbox);
3368 mbox->context1 =
James Smart92d7f7b2007-06-17 19:56:38 -05003369 (void *)((unsigned long) cmdiocb->iocb.ulpContext);
James Smart329f9bc2007-04-25 09:53:01 -04003370 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05003371 mbox->vport = vport;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003372 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
James Smart0b727fe2007-10-27 13:37:25 -04003373 if (lpfc_sli_issue_mbox (phba, mbox, MBX_NOWAIT)
3374 != MBX_NOT_FINISHED)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003375 /* Mbox completion will send ELS Response */
3376 return 0;
James Smart2e0fef82007-06-17 19:56:36 -05003377
James Smart329f9bc2007-04-25 09:53:01 -04003378 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003379 mempool_free(mbox, phba->mbox_mem_pool);
3380 }
3381 }
3382 stat.un.b.lsRjtRsvd0 = 0;
3383 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3384 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
3385 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05003386 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003387 return 0;
3388}
3389
Jamie Wellnitz082c0262006-02-28 19:25:30 -05003390static int
James Smart2e0fef82007-06-17 19:56:36 -05003391lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
3392 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003393{
James Smart2e0fef82007-06-17 19:56:36 -05003394 struct lpfc_hba *phba = vport->phba;
3395 IOCB_t *icmd, *oldcmd;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003396 RPL_RSP rpl_rsp;
3397 struct lpfc_iocbq *elsiocb;
James Smart2e0fef82007-06-17 19:56:36 -05003398 struct lpfc_sli *psli = &phba->sli;
3399 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003400 uint8_t *pcmd;
3401
James Smart2e0fef82007-06-17 19:56:36 -05003402 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3403 ndlp->nlp_DID, ELS_CMD_ACC);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003404
James Smart488d1462006-03-07 15:02:37 -05003405 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003406 return 1;
James Smart488d1462006-03-07 15:02:37 -05003407
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003408 icmd = &elsiocb->iocb;
3409 oldcmd = &oldiocb->iocb;
3410 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3411
3412 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3413 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003414 pcmd += sizeof(uint16_t);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003415 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
3416 pcmd += sizeof(uint16_t);
3417
3418 /* Setup the RPL ACC payload */
3419 rpl_rsp.listLen = be32_to_cpu(1);
3420 rpl_rsp.index = 0;
3421 rpl_rsp.port_num_blk.portNum = 0;
James Smart2e0fef82007-06-17 19:56:36 -05003422 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
3423 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003424 sizeof(struct lpfc_name));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003425 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003426 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003427 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3428 "0120 Xmit ELS RPL ACC response tag x%x "
3429 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
3430 "rpi x%x\n",
3431 elsiocb->iotag, elsiocb->iocb.ulpContext,
3432 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3433 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05003434 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003435 phba->fc_stat.elsXmitACC++;
3436 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
3437 lpfc_els_free_iocb(phba, elsiocb);
3438 return 1;
3439 }
3440 return 0;
3441}
3442
3443static int
James Smart2e0fef82007-06-17 19:56:36 -05003444lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3445 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003446{
3447 struct lpfc_dmabuf *pcmd;
3448 uint32_t *lp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003449 uint32_t maxsize;
3450 uint16_t cmdsize;
3451 RPL *rpl;
3452 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05003453
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003454 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
3455 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003456 stat.un.b.lsRjtRsvd0 = 0;
3457 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3458 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
3459 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05003460 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
3461 NULL);
dea31012005-04-17 16:05:31 -05003462 }
3463
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003464 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3465 lp = (uint32_t *) pcmd->virt;
3466 rpl = (RPL *) (lp + 1);
3467
3468 maxsize = be32_to_cpu(rpl->maxsize);
3469
3470 /* We support only one port */
3471 if ((rpl->index == 0) &&
3472 ((maxsize == 0) ||
3473 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
3474 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003475 } else {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003476 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
3477 }
James Smart2e0fef82007-06-17 19:56:36 -05003478 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05003479
3480 return 0;
3481}
3482
3483static int
James Smart2e0fef82007-06-17 19:56:36 -05003484lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3485 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003486{
3487 struct lpfc_dmabuf *pcmd;
3488 uint32_t *lp;
3489 IOCB_t *icmd;
3490 FARP *fp;
3491 uint32_t cmd, cnt, did;
3492
3493 icmd = &cmdiocb->iocb;
3494 did = icmd->un.elsreq64.remoteID;
3495 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3496 lp = (uint32_t *) pcmd->virt;
3497
3498 cmd = *lp++;
3499 fp = (FARP *) lp;
dea31012005-04-17 16:05:31 -05003500 /* FARP-REQ received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04003501 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3502 "0601 FARP-REQ received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05003503 /* We will only support match on WWPN or WWNN */
3504 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003505 return 0;
dea31012005-04-17 16:05:31 -05003506 }
3507
3508 cnt = 0;
3509 /* If this FARP command is searching for my portname */
3510 if (fp->Mflags & FARP_MATCH_PORT) {
James Smart2e0fef82007-06-17 19:56:36 -05003511 if (memcmp(&fp->RportName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05003512 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05003513 cnt = 1;
3514 }
3515
3516 /* If this FARP command is searching for my nodename */
3517 if (fp->Mflags & FARP_MATCH_NODE) {
James Smart2e0fef82007-06-17 19:56:36 -05003518 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05003519 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05003520 cnt = 1;
3521 }
3522
3523 if (cnt) {
3524 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
3525 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
3526 /* Log back into the node before sending the FARP. */
3527 if (fp->Rflags & FARP_REQUEST_PLOGI) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003528 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003529 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04003530 NLP_STE_PLOGI_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05003531 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05003532 }
3533
3534 /* Send a FARP response to that node */
James Smart2e0fef82007-06-17 19:56:36 -05003535 if (fp->Rflags & FARP_REQUEST_FARPR)
3536 lpfc_issue_els_farpr(vport, did, 0);
dea31012005-04-17 16:05:31 -05003537 }
3538 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003539 return 0;
dea31012005-04-17 16:05:31 -05003540}
3541
3542static int
James Smart2e0fef82007-06-17 19:56:36 -05003543lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3544 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003545{
3546 struct lpfc_dmabuf *pcmd;
3547 uint32_t *lp;
3548 IOCB_t *icmd;
3549 uint32_t cmd, did;
3550
3551 icmd = &cmdiocb->iocb;
3552 did = icmd->un.elsreq64.remoteID;
3553 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3554 lp = (uint32_t *) pcmd->virt;
3555
3556 cmd = *lp++;
3557 /* FARP-RSP received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04003558 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3559 "0600 FARP-RSP received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05003560 /* ACCEPT the Farp resp request */
James Smart51ef4c22007-08-02 11:10:31 -04003561 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05003562
3563 return 0;
3564}
3565
3566static int
James Smart2e0fef82007-06-17 19:56:36 -05003567lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3568 struct lpfc_nodelist *fan_ndlp)
dea31012005-04-17 16:05:31 -05003569{
3570 struct lpfc_dmabuf *pcmd;
3571 uint32_t *lp;
3572 IOCB_t *icmd;
dea31012005-04-17 16:05:31 -05003573 uint32_t cmd, did;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003574 FAN *fp;
3575 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05003576 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003577
3578 /* FAN received */
James Smarte8b62012007-08-02 11:10:09 -04003579 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3580 "0265 FAN received\n");
dea31012005-04-17 16:05:31 -05003581 icmd = &cmdiocb->iocb;
3582 did = icmd->un.elsreq64.remoteID;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003583 pcmd = (struct lpfc_dmabuf *)cmdiocb->context2;
3584 lp = (uint32_t *)pcmd->virt;
dea31012005-04-17 16:05:31 -05003585
3586 cmd = *lp++;
James Smart92d7f7b2007-06-17 19:56:38 -05003587 fp = (FAN *) lp;
dea31012005-04-17 16:05:31 -05003588
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003589 /* FAN received; Fan does not have a reply sequence */
dea31012005-04-17 16:05:31 -05003590
James Smart2e0fef82007-06-17 19:56:36 -05003591 if (phba->pport->port_state == LPFC_LOCAL_CFG_LINK) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003592 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
3593 sizeof(struct lpfc_name)) != 0) ||
3594 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
3595 sizeof(struct lpfc_name)) != 0)) {
3596 /*
3597 * This node has switched fabrics. FLOGI is required
3598 * Clean up the old rpi's
dea31012005-04-17 16:05:31 -05003599 */
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003600
3601 list_for_each_entry_safe(ndlp, next_ndlp,
James Smart2e0fef82007-06-17 19:56:36 -05003602 &vport->fc_nodes, nlp_listp) {
James Smart685f0bf2007-04-25 09:53:08 -04003603 if (ndlp->nlp_state != NLP_STE_NPR_NODE)
3604 continue;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003605 if (ndlp->nlp_type & NLP_FABRIC) {
3606 /*
3607 * Clean up old Fabric, Nameserver and
3608 * other NLP_FABRIC logins
3609 */
James Smart2e0fef82007-06-17 19:56:36 -05003610 lpfc_drop_node(vport, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04003611
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003612 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003613 /* Fail outstanding I/O now since this
3614 * device is marked for PLOGI
3615 */
James Smart2e0fef82007-06-17 19:56:36 -05003616 lpfc_unreg_rpi(vport, ndlp);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003617 }
3618 }
3619
James Smart2e0fef82007-06-17 19:56:36 -05003620 lpfc_initial_flogi(vport);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003621 return 0;
dea31012005-04-17 16:05:31 -05003622 }
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003623 /* Discovery not needed,
3624 * move the nodes to their original state.
3625 */
James Smart2e0fef82007-06-17 19:56:36 -05003626 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
James Smart685f0bf2007-04-25 09:53:08 -04003627 nlp_listp) {
3628 if (ndlp->nlp_state != NLP_STE_NPR_NODE)
3629 continue;
dea31012005-04-17 16:05:31 -05003630
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003631 switch (ndlp->nlp_prev_state) {
3632 case NLP_STE_UNMAPPED_NODE:
3633 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05003634 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04003635 NLP_STE_UNMAPPED_NODE);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003636 break;
3637
3638 case NLP_STE_MAPPED_NODE:
3639 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05003640 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04003641 NLP_STE_MAPPED_NODE);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003642 break;
3643
3644 default:
3645 break;
3646 }
3647 }
3648
3649 /* Start discovery - this should just do CLEAR_LA */
James Smart2e0fef82007-06-17 19:56:36 -05003650 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -05003651 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003652 return 0;
dea31012005-04-17 16:05:31 -05003653}
3654
3655void
3656lpfc_els_timeout(unsigned long ptr)
3657{
James Smart2e0fef82007-06-17 19:56:36 -05003658 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
3659 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003660 unsigned long iflag;
3661
James Smart2e0fef82007-06-17 19:56:36 -05003662 spin_lock_irqsave(&vport->work_port_lock, iflag);
3663 if ((vport->work_port_events & WORKER_ELS_TMO) == 0) {
3664 vport->work_port_events |= WORKER_ELS_TMO;
James Smart92d7f7b2007-06-17 19:56:38 -05003665 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
3666
3667 spin_lock_irqsave(&phba->hbalock, iflag);
dea31012005-04-17 16:05:31 -05003668 if (phba->work_wait)
James Smart92d7f7b2007-06-17 19:56:38 -05003669 lpfc_worker_wake_up(phba);
3670 spin_unlock_irqrestore(&phba->hbalock, iflag);
dea31012005-04-17 16:05:31 -05003671 }
James Smart92d7f7b2007-06-17 19:56:38 -05003672 else
3673 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
dea31012005-04-17 16:05:31 -05003674 return;
3675}
3676
3677void
James Smart2e0fef82007-06-17 19:56:36 -05003678lpfc_els_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003679{
James Smart2e0fef82007-06-17 19:56:36 -05003680 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003681 struct lpfc_sli_ring *pring;
3682 struct lpfc_iocbq *tmp_iocb, *piocb;
3683 IOCB_t *cmd = NULL;
3684 struct lpfc_dmabuf *pcmd;
James Smart2e0fef82007-06-17 19:56:36 -05003685 uint32_t els_command = 0;
dea31012005-04-17 16:05:31 -05003686 uint32_t timeout;
James Smart2e0fef82007-06-17 19:56:36 -05003687 uint32_t remote_ID = 0xffffffff;
dea31012005-04-17 16:05:31 -05003688
dea31012005-04-17 16:05:31 -05003689 /* If the timer is already canceled do nothing */
James Smart2e0fef82007-06-17 19:56:36 -05003690 if ((vport->work_port_events & WORKER_ELS_TMO) == 0) {
dea31012005-04-17 16:05:31 -05003691 return;
3692 }
James Smart2e0fef82007-06-17 19:56:36 -05003693 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003694 timeout = (uint32_t)(phba->fc_ratov << 1);
3695
3696 pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05003697
3698 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
3699 cmd = &piocb->iocb;
3700
James Smart2e0fef82007-06-17 19:56:36 -05003701 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
3702 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
3703 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
dea31012005-04-17 16:05:31 -05003704 continue;
James Smart2e0fef82007-06-17 19:56:36 -05003705
3706 if (piocb->vport != vport)
3707 continue;
3708
dea31012005-04-17 16:05:31 -05003709 pcmd = (struct lpfc_dmabuf *) piocb->context2;
James Smart2e0fef82007-06-17 19:56:36 -05003710 if (pcmd)
3711 els_command = *(uint32_t *) (pcmd->virt);
dea31012005-04-17 16:05:31 -05003712
James Smart92d7f7b2007-06-17 19:56:38 -05003713 if (els_command == ELS_CMD_FARP ||
3714 els_command == ELS_CMD_FARPR ||
3715 els_command == ELS_CMD_FDISC)
dea31012005-04-17 16:05:31 -05003716 continue;
James Smart92d7f7b2007-06-17 19:56:38 -05003717
3718 if (vport != piocb->vport)
3719 continue;
dea31012005-04-17 16:05:31 -05003720
3721 if (piocb->drvrTimeout > 0) {
James Smart92d7f7b2007-06-17 19:56:38 -05003722 if (piocb->drvrTimeout >= timeout)
dea31012005-04-17 16:05:31 -05003723 piocb->drvrTimeout -= timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05003724 else
dea31012005-04-17 16:05:31 -05003725 piocb->drvrTimeout = 0;
dea31012005-04-17 16:05:31 -05003726 continue;
3727 }
3728
James Smart2e0fef82007-06-17 19:56:36 -05003729 remote_ID = 0xffffffff;
3730 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
dea31012005-04-17 16:05:31 -05003731 remote_ID = cmd->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05003732 else {
3733 struct lpfc_nodelist *ndlp;
3734 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
3735 if (ndlp)
3736 remote_ID = ndlp->nlp_DID;
dea31012005-04-17 16:05:31 -05003737 }
James Smarte8b62012007-08-02 11:10:09 -04003738 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3739 "0127 ELS timeout Data: x%x x%x x%x "
3740 "x%x\n", els_command,
3741 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
James Smart07951072007-04-25 09:51:38 -04003742 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05003743 }
James Smart2e0fef82007-06-17 19:56:36 -05003744 spin_unlock_irq(&phba->hbalock);
James Smart5a0e3262006-07-06 15:49:16 -04003745
James Smart2e0fef82007-06-17 19:56:36 -05003746 if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt)
3747 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
dea31012005-04-17 16:05:31 -05003748}
3749
3750void
James Smart2e0fef82007-06-17 19:56:36 -05003751lpfc_els_flush_cmd(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003752{
James Smart2534ba72007-04-25 09:52:20 -04003753 LIST_HEAD(completions);
James Smart2e0fef82007-06-17 19:56:36 -05003754 struct lpfc_hba *phba = vport->phba;
James Smart329f9bc2007-04-25 09:53:01 -04003755 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05003756 struct lpfc_iocbq *tmp_iocb, *piocb;
3757 IOCB_t *cmd = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05003758
3759 lpfc_fabric_abort_vport(vport);
dea31012005-04-17 16:05:31 -05003760
James Smart2e0fef82007-06-17 19:56:36 -05003761 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003762 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
3763 cmd = &piocb->iocb;
3764
3765 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
3766 continue;
3767 }
3768
3769 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
James Smart329f9bc2007-04-25 09:53:01 -04003770 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
3771 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
3772 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
3773 cmd->ulpCommand == CMD_ABORT_XRI_CN)
dea31012005-04-17 16:05:31 -05003774 continue;
dea31012005-04-17 16:05:31 -05003775
James Smart2e0fef82007-06-17 19:56:36 -05003776 if (piocb->vport != vport)
3777 continue;
3778
James Smart2534ba72007-04-25 09:52:20 -04003779 list_move_tail(&piocb->list, &completions);
James Smart1dcb58e2007-04-25 09:51:30 -04003780 pring->txq_cnt--;
dea31012005-04-17 16:05:31 -05003781 }
3782
3783 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
dea31012005-04-17 16:05:31 -05003784 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
3785 continue;
3786 }
dea31012005-04-17 16:05:31 -05003787
James Smart2e0fef82007-06-17 19:56:36 -05003788 if (piocb->vport != vport)
3789 continue;
3790
James Smart07951072007-04-25 09:51:38 -04003791 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05003792 }
James Smart2e0fef82007-06-17 19:56:36 -05003793 spin_unlock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04003794
James Smart2e0fef82007-06-17 19:56:36 -05003795 while (!list_empty(&completions)) {
James Smart2534ba72007-04-25 09:52:20 -04003796 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
3797 cmd = &piocb->iocb;
James Smart92d7f7b2007-06-17 19:56:38 -05003798 list_del_init(&piocb->list);
James Smart2534ba72007-04-25 09:52:20 -04003799
James Smart2e0fef82007-06-17 19:56:36 -05003800 if (!piocb->iocb_cmpl)
3801 lpfc_sli_release_iocbq(phba, piocb);
3802 else {
James Smart2534ba72007-04-25 09:52:20 -04003803 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
3804 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
3805 (piocb->iocb_cmpl) (phba, piocb, piocb);
James Smart2e0fef82007-06-17 19:56:36 -05003806 }
James Smart2534ba72007-04-25 09:52:20 -04003807 }
3808
dea31012005-04-17 16:05:31 -05003809 return;
3810}
3811
James Smart549e55c2007-08-02 11:09:51 -04003812void
3813lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
3814{
3815 LIST_HEAD(completions);
3816 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
3817 struct lpfc_iocbq *tmp_iocb, *piocb;
3818 IOCB_t *cmd = NULL;
3819
3820 lpfc_fabric_abort_hba(phba);
3821 spin_lock_irq(&phba->hbalock);
3822 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
3823 cmd = &piocb->iocb;
3824 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
3825 continue;
3826 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
3827 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
3828 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
3829 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
3830 cmd->ulpCommand == CMD_ABORT_XRI_CN)
3831 continue;
3832 list_move_tail(&piocb->list, &completions);
3833 pring->txq_cnt--;
3834 }
3835 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
3836 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
3837 continue;
3838 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
3839 }
3840 spin_unlock_irq(&phba->hbalock);
3841 while (!list_empty(&completions)) {
3842 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
3843 cmd = &piocb->iocb;
3844 list_del_init(&piocb->list);
3845 if (!piocb->iocb_cmpl)
3846 lpfc_sli_release_iocbq(phba, piocb);
3847 else {
3848 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
3849 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
3850 (piocb->iocb_cmpl) (phba, piocb, piocb);
3851 }
3852 }
3853 return;
3854}
3855
James Smarted957682007-06-17 19:56:37 -05003856static void
3857lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
James Smart92d7f7b2007-06-17 19:56:38 -05003858 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05003859{
James Smart87af33f2007-10-27 13:37:43 -04003860 struct Scsi_Host *shost;
dea31012005-04-17 16:05:31 -05003861 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05003862 struct ls_rjt stat;
James Smart92d7f7b2007-06-17 19:56:38 -05003863 uint32_t *payload;
James Smart2e0fef82007-06-17 19:56:36 -05003864 uint32_t cmd, did, newnode, rjt_err = 0;
James Smarted957682007-06-17 19:56:37 -05003865 IOCB_t *icmd = &elsiocb->iocb;
dea31012005-04-17 16:05:31 -05003866
James Smart92d7f7b2007-06-17 19:56:38 -05003867 if (vport == NULL || elsiocb->context2 == NULL)
dea31012005-04-17 16:05:31 -05003868 goto dropit;
James Smart2e0fef82007-06-17 19:56:36 -05003869
dea31012005-04-17 16:05:31 -05003870 newnode = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05003871 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
3872 cmd = *payload;
James Smarted957682007-06-17 19:56:37 -05003873 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
3874 lpfc_post_buffer(phba, pring, 1, 1);
dea31012005-04-17 16:05:31 -05003875
James Smart858c9f62007-06-17 19:56:39 -05003876 did = icmd->un.rcvels.remoteID;
3877 if (icmd->ulpStatus) {
3878 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3879 "RCV Unsol ELS: status:x%x/x%x did:x%x",
3880 icmd->ulpStatus, icmd->un.ulpWord[4], did);
dea31012005-04-17 16:05:31 -05003881 goto dropit;
James Smart858c9f62007-06-17 19:56:39 -05003882 }
dea31012005-04-17 16:05:31 -05003883
3884 /* Check to see if link went down during discovery */
James Smarted957682007-06-17 19:56:37 -05003885 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05003886 goto dropit;
dea31012005-04-17 16:05:31 -05003887
James Smart92d7f7b2007-06-17 19:56:38 -05003888 /* Ignore traffic recevied during vport shutdown. */
3889 if (vport->load_flag & FC_UNLOADING)
3890 goto dropit;
3891
James Smart2e0fef82007-06-17 19:56:36 -05003892 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003893 if (!ndlp) {
dea31012005-04-17 16:05:31 -05003894 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003895 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
James Smarted957682007-06-17 19:56:37 -05003896 if (!ndlp)
dea31012005-04-17 16:05:31 -05003897 goto dropit;
dea31012005-04-17 16:05:31 -05003898
James Smart2e0fef82007-06-17 19:56:36 -05003899 lpfc_nlp_init(vport, ndlp, did);
James Smart98c9ea52007-10-27 13:37:33 -04003900 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05003901 newnode = 1;
3902 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) {
3903 ndlp->nlp_type |= NLP_FABRIC;
3904 }
3905 }
James Smart87af33f2007-10-27 13:37:43 -04003906 else {
3907 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
3908 /* This is simular to the new node path */
3909 lpfc_nlp_get(ndlp);
3910 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
3911 newnode = 1;
3912 }
3913 }
dea31012005-04-17 16:05:31 -05003914
3915 phba->fc_stat.elsRcvFrame++;
James Smart329f9bc2007-04-25 09:53:01 -04003916 if (elsiocb->context1)
3917 lpfc_nlp_put(elsiocb->context1);
3918 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05003919 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -05003920
3921 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
3922 cmd &= ELS_CMD_MASK;
3923 }
3924 /* ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04003925 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3926 "0112 ELS command x%x received from NPORT x%x "
3927 "Data: x%x\n", cmd, did, vport->port_state);
dea31012005-04-17 16:05:31 -05003928 switch (cmd) {
3929 case ELS_CMD_PLOGI:
James Smart858c9f62007-06-17 19:56:39 -05003930 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3931 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
3932 did, vport->port_state, ndlp->nlp_flag);
3933
dea31012005-04-17 16:05:31 -05003934 phba->fc_stat.elsRcvPLOGI++;
James Smart858c9f62007-06-17 19:56:39 -05003935 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
3936
3937 if (vport->port_state < LPFC_DISC_AUTH) {
3938 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05003939 break;
3940 }
James Smart87af33f2007-10-27 13:37:43 -04003941
3942 shost = lpfc_shost_from_vport(vport);
3943 spin_lock_irq(shost->host_lock);
3944 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
3945 spin_unlock_irq(shost->host_lock);
3946
James Smart2e0fef82007-06-17 19:56:36 -05003947 lpfc_disc_state_machine(vport, ndlp, elsiocb,
3948 NLP_EVT_RCV_PLOGI);
James Smart858c9f62007-06-17 19:56:39 -05003949
dea31012005-04-17 16:05:31 -05003950 break;
3951 case ELS_CMD_FLOGI:
James Smart858c9f62007-06-17 19:56:39 -05003952 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3953 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
3954 did, vport->port_state, ndlp->nlp_flag);
3955
dea31012005-04-17 16:05:31 -05003956 phba->fc_stat.elsRcvFLOGI++;
James Smart51ef4c22007-08-02 11:10:31 -04003957 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04003958 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04003959 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05003960 break;
3961 case ELS_CMD_LOGO:
James Smart858c9f62007-06-17 19:56:39 -05003962 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3963 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
3964 did, vport->port_state, ndlp->nlp_flag);
3965
dea31012005-04-17 16:05:31 -05003966 phba->fc_stat.elsRcvLOGO++;
James Smart2e0fef82007-06-17 19:56:36 -05003967 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05003968 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05003969 break;
3970 }
James Smart2e0fef82007-06-17 19:56:36 -05003971 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
dea31012005-04-17 16:05:31 -05003972 break;
3973 case ELS_CMD_PRLO:
James Smart858c9f62007-06-17 19:56:39 -05003974 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3975 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
3976 did, vport->port_state, ndlp->nlp_flag);
3977
dea31012005-04-17 16:05:31 -05003978 phba->fc_stat.elsRcvPRLO++;
James Smart2e0fef82007-06-17 19:56:36 -05003979 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05003980 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05003981 break;
3982 }
James Smart2e0fef82007-06-17 19:56:36 -05003983 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
dea31012005-04-17 16:05:31 -05003984 break;
3985 case ELS_CMD_RSCN:
3986 phba->fc_stat.elsRcvRSCN++;
James Smart51ef4c22007-08-02 11:10:31 -04003987 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04003988 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04003989 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05003990 break;
3991 case ELS_CMD_ADISC:
James Smart858c9f62007-06-17 19:56:39 -05003992 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3993 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
3994 did, vport->port_state, ndlp->nlp_flag);
3995
dea31012005-04-17 16:05:31 -05003996 phba->fc_stat.elsRcvADISC++;
James Smart2e0fef82007-06-17 19:56:36 -05003997 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05003998 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05003999 break;
4000 }
James Smart2e0fef82007-06-17 19:56:36 -05004001 lpfc_disc_state_machine(vport, ndlp, elsiocb,
4002 NLP_EVT_RCV_ADISC);
dea31012005-04-17 16:05:31 -05004003 break;
4004 case ELS_CMD_PDISC:
James Smart858c9f62007-06-17 19:56:39 -05004005 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4006 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
4007 did, vport->port_state, ndlp->nlp_flag);
4008
dea31012005-04-17 16:05:31 -05004009 phba->fc_stat.elsRcvPDISC++;
James Smart2e0fef82007-06-17 19:56:36 -05004010 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05004011 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05004012 break;
4013 }
James Smart2e0fef82007-06-17 19:56:36 -05004014 lpfc_disc_state_machine(vport, ndlp, elsiocb,
4015 NLP_EVT_RCV_PDISC);
dea31012005-04-17 16:05:31 -05004016 break;
4017 case ELS_CMD_FARPR:
James Smart858c9f62007-06-17 19:56:39 -05004018 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4019 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
4020 did, vport->port_state, ndlp->nlp_flag);
4021
dea31012005-04-17 16:05:31 -05004022 phba->fc_stat.elsRcvFARPR++;
James Smart2e0fef82007-06-17 19:56:36 -05004023 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05004024 break;
4025 case ELS_CMD_FARP:
James Smart858c9f62007-06-17 19:56:39 -05004026 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4027 "RCV FARP: did:x%x/ste:x%x flg:x%x",
4028 did, vport->port_state, ndlp->nlp_flag);
4029
dea31012005-04-17 16:05:31 -05004030 phba->fc_stat.elsRcvFARP++;
James Smart2e0fef82007-06-17 19:56:36 -05004031 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05004032 break;
4033 case ELS_CMD_FAN:
James Smart858c9f62007-06-17 19:56:39 -05004034 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4035 "RCV FAN: did:x%x/ste:x%x flg:x%x",
4036 did, vport->port_state, ndlp->nlp_flag);
4037
dea31012005-04-17 16:05:31 -05004038 phba->fc_stat.elsRcvFAN++;
James Smart2e0fef82007-06-17 19:56:36 -05004039 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05004040 break;
dea31012005-04-17 16:05:31 -05004041 case ELS_CMD_PRLI:
James Smart858c9f62007-06-17 19:56:39 -05004042 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4043 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
4044 did, vport->port_state, ndlp->nlp_flag);
4045
dea31012005-04-17 16:05:31 -05004046 phba->fc_stat.elsRcvPRLI++;
James Smart2e0fef82007-06-17 19:56:36 -05004047 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05004048 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05004049 break;
4050 }
James Smart2e0fef82007-06-17 19:56:36 -05004051 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
dea31012005-04-17 16:05:31 -05004052 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004053 case ELS_CMD_LIRR:
James Smart858c9f62007-06-17 19:56:39 -05004054 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4055 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
4056 did, vport->port_state, ndlp->nlp_flag);
4057
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004058 phba->fc_stat.elsRcvLIRR++;
James Smart2e0fef82007-06-17 19:56:36 -05004059 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04004060 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04004061 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004062 break;
4063 case ELS_CMD_RPS:
James Smart858c9f62007-06-17 19:56:39 -05004064 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4065 "RCV RPS: did:x%x/ste:x%x flg:x%x",
4066 did, vport->port_state, ndlp->nlp_flag);
4067
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004068 phba->fc_stat.elsRcvRPS++;
James Smart2e0fef82007-06-17 19:56:36 -05004069 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04004070 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04004071 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004072 break;
4073 case ELS_CMD_RPL:
James Smart858c9f62007-06-17 19:56:39 -05004074 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4075 "RCV RPL: did:x%x/ste:x%x flg:x%x",
4076 did, vport->port_state, ndlp->nlp_flag);
4077
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004078 phba->fc_stat.elsRcvRPL++;
James Smart2e0fef82007-06-17 19:56:36 -05004079 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04004080 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04004081 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004082 break;
dea31012005-04-17 16:05:31 -05004083 case ELS_CMD_RNID:
James Smart858c9f62007-06-17 19:56:39 -05004084 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4085 "RCV RNID: did:x%x/ste:x%x flg:x%x",
4086 did, vport->port_state, ndlp->nlp_flag);
4087
dea31012005-04-17 16:05:31 -05004088 phba->fc_stat.elsRcvRNID++;
James Smart2e0fef82007-06-17 19:56:36 -05004089 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04004090 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04004091 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05004092 break;
4093 default:
James Smart858c9f62007-06-17 19:56:39 -05004094 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4095 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
4096 cmd, did, vport->port_state);
4097
dea31012005-04-17 16:05:31 -05004098 /* Unsupported ELS command, reject */
James Smart858c9f62007-06-17 19:56:39 -05004099 rjt_err = LSRJT_INVALID_CMD;
dea31012005-04-17 16:05:31 -05004100
4101 /* Unknown ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04004102 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4103 "0115 Unknown ELS command x%x "
4104 "received from NPORT x%x\n", cmd, did);
James Smart87af33f2007-10-27 13:37:43 -04004105 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04004106 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05004107 break;
4108 }
4109
4110 /* check if need to LS_RJT received ELS cmd */
4111 if (rjt_err) {
James Smart92d7f7b2007-06-17 19:56:38 -05004112 memset(&stat, 0, sizeof(stat));
James Smart858c9f62007-06-17 19:56:39 -05004113 stat.un.b.lsRjtRsnCode = rjt_err;
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04004114 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart858c9f62007-06-17 19:56:39 -05004115 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
4116 NULL);
dea31012005-04-17 16:05:31 -05004117 }
4118
James Smarted957682007-06-17 19:56:37 -05004119 return;
4120
4121dropit:
James Smart98c9ea52007-10-27 13:37:33 -04004122 if (vport && !(vport->load_flag & FC_UNLOADING))
4123 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
James Smarte8b62012007-08-02 11:10:09 -04004124 "(%d):0111 Dropping received ELS cmd "
James Smarted957682007-06-17 19:56:37 -05004125 "Data: x%x x%x x%x\n",
James Smart98c9ea52007-10-27 13:37:33 -04004126 vport->vpi, icmd->ulpStatus,
James Smarte8b62012007-08-02 11:10:09 -04004127 icmd->un.ulpWord[4], icmd->ulpTimeout);
James Smarted957682007-06-17 19:56:37 -05004128 phba->fc_stat.elsRcvDrop++;
4129}
4130
James Smart92d7f7b2007-06-17 19:56:38 -05004131static struct lpfc_vport *
4132lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
4133{
4134 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -04004135 unsigned long flags;
James Smart92d7f7b2007-06-17 19:56:38 -05004136
James Smart549e55c2007-08-02 11:09:51 -04004137 spin_lock_irqsave(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05004138 list_for_each_entry(vport, &phba->port_list, listentry) {
James Smart549e55c2007-08-02 11:09:51 -04004139 if (vport->vpi == vpi) {
4140 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05004141 return vport;
James Smart549e55c2007-08-02 11:09:51 -04004142 }
James Smart92d7f7b2007-06-17 19:56:38 -05004143 }
James Smart549e55c2007-08-02 11:09:51 -04004144 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05004145 return NULL;
4146}
James Smarted957682007-06-17 19:56:37 -05004147
4148void
4149lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
4150 struct lpfc_iocbq *elsiocb)
4151{
4152 struct lpfc_vport *vport = phba->pport;
James Smarted957682007-06-17 19:56:37 -05004153 IOCB_t *icmd = &elsiocb->iocb;
James Smarted957682007-06-17 19:56:37 -05004154 dma_addr_t paddr;
James Smart92d7f7b2007-06-17 19:56:38 -05004155 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
4156 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
James Smarted957682007-06-17 19:56:37 -05004157
James Smart92d7f7b2007-06-17 19:56:38 -05004158 elsiocb->context2 = NULL;
4159 elsiocb->context3 = NULL;
4160
4161 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
4162 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
4163 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
4164 (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) {
James Smarted957682007-06-17 19:56:37 -05004165 phba->fc_stat.NoRcvBuf++;
4166 /* Not enough posted buffers; Try posting more buffers */
James Smart92d7f7b2007-06-17 19:56:38 -05004167 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
James Smarted957682007-06-17 19:56:37 -05004168 lpfc_post_buffer(phba, pring, 0, 1);
4169 return;
4170 }
4171
James Smart92d7f7b2007-06-17 19:56:38 -05004172 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
4173 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
4174 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
4175 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
4176 vport = phba->pport;
4177 else {
4178 uint16_t vpi = icmd->unsli3.rcvsli3.vpi;
4179 vport = lpfc_find_vport_by_vpid(phba, vpi);
4180 }
4181 }
4182 /* If there are no BDEs associated
4183 * with this IOCB, there is nothing to do.
4184 */
James Smarted957682007-06-17 19:56:37 -05004185 if (icmd->ulpBdeCount == 0)
4186 return;
4187
James Smart92d7f7b2007-06-17 19:56:38 -05004188 /* type of ELS cmd is first 32bit word
4189 * in packet
4190 */
James Smarted957682007-06-17 19:56:37 -05004191 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05004192 elsiocb->context2 = bdeBuf1;
James Smarted957682007-06-17 19:56:37 -05004193 } else {
4194 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
4195 icmd->un.cont64[0].addrLow);
James Smart92d7f7b2007-06-17 19:56:38 -05004196 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
4197 paddr);
James Smarted957682007-06-17 19:56:37 -05004198 }
4199
James Smart92d7f7b2007-06-17 19:56:38 -05004200 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
4201 /*
4202 * The different unsolicited event handlers would tell us
4203 * if they are done with "mp" by setting context2 to NULL.
4204 */
James Smart329f9bc2007-04-25 09:53:01 -04004205 lpfc_nlp_put(elsiocb->context1);
4206 elsiocb->context1 = NULL;
dea31012005-04-17 16:05:31 -05004207 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05004208 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
4209 elsiocb->context2 = NULL;
dea31012005-04-17 16:05:31 -05004210 }
James Smarted957682007-06-17 19:56:37 -05004211
4212 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
James Smart92d7f7b2007-06-17 19:56:38 -05004213 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
James Smarted957682007-06-17 19:56:37 -05004214 icmd->ulpBdeCount == 2) {
James Smart92d7f7b2007-06-17 19:56:38 -05004215 elsiocb->context2 = bdeBuf2;
4216 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
James Smarted957682007-06-17 19:56:37 -05004217 /* free mp if we are done with it */
4218 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05004219 lpfc_in_buf_free(phba, elsiocb->context2);
4220 elsiocb->context2 = NULL;
James Smarted957682007-06-17 19:56:37 -05004221 }
dea31012005-04-17 16:05:31 -05004222 }
dea31012005-04-17 16:05:31 -05004223}
James Smart92d7f7b2007-06-17 19:56:38 -05004224
4225void
4226lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
4227{
4228 struct lpfc_nodelist *ndlp, *ndlp_fdmi;
4229
4230 ndlp = lpfc_findnode_did(vport, NameServer_DID);
4231 if (!ndlp) {
4232 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
4233 if (!ndlp) {
4234 if (phba->fc_topology == TOPOLOGY_LOOP) {
4235 lpfc_disc_start(vport);
4236 return;
4237 }
4238 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04004239 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4240 "0251 NameServer login: no memory\n");
James Smart92d7f7b2007-06-17 19:56:38 -05004241 return;
4242 }
4243 lpfc_nlp_init(vport, ndlp, NameServer_DID);
4244 ndlp->nlp_type |= NLP_FABRIC;
4245 }
4246
4247 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
4248
4249 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
4250 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04004251 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4252 "0252 Cannot issue NameServer login\n");
James Smart92d7f7b2007-06-17 19:56:38 -05004253 return;
4254 }
4255
James Smart3de2a652007-08-02 11:09:59 -04004256 if (vport->cfg_fdmi_on) {
James Smart92d7f7b2007-06-17 19:56:38 -05004257 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
4258 GFP_KERNEL);
4259 if (ndlp_fdmi) {
4260 lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
4261 ndlp_fdmi->nlp_type |= NLP_FABRIC;
4262 ndlp_fdmi->nlp_state =
4263 NLP_STE_PLOGI_ISSUE;
4264 lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID,
4265 0);
4266 }
4267 }
4268 return;
4269}
4270
4271static void
4272lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4273{
4274 struct lpfc_vport *vport = pmb->vport;
4275 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4276 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
4277 MAILBOX_t *mb = &pmb->mb;
4278
4279 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
4280 lpfc_nlp_put(ndlp);
4281
4282 if (mb->mbxStatus) {
James Smarte8b62012007-08-02 11:10:09 -04004283 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
4284 "0915 Register VPI failed: 0x%x\n",
4285 mb->mbxStatus);
James Smart92d7f7b2007-06-17 19:56:38 -05004286
4287 switch (mb->mbxStatus) {
4288 case 0x11: /* unsupported feature */
4289 case 0x9603: /* max_vpi exceeded */
4290 /* giving up on vport registration */
4291 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4292 spin_lock_irq(shost->host_lock);
4293 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
4294 spin_unlock_irq(shost->host_lock);
4295 lpfc_can_disctmo(vport);
4296 break;
4297 default:
4298 /* Try to recover from this error */
4299 lpfc_mbx_unreg_vpi(vport);
4300 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
4301 lpfc_initial_fdisc(vport);
4302 break;
4303 }
4304
4305 } else {
4306 if (vport == phba->pport)
4307 lpfc_issue_fabric_reglogin(vport);
4308 else
4309 lpfc_do_scr_ns_plogi(phba, vport);
4310 }
4311 mempool_free(pmb, phba->mbox_mem_pool);
4312 return;
4313}
4314
Adrian Bunka6ababd2007-11-05 18:07:33 +01004315static void
James Smart92d7f7b2007-06-17 19:56:38 -05004316lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
4317 struct lpfc_nodelist *ndlp)
4318{
4319 LPFC_MBOXQ_t *mbox;
4320
4321 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4322 if (mbox) {
4323 lpfc_reg_vpi(phba, vport->vpi, vport->fc_myDID, mbox);
4324 mbox->vport = vport;
4325 mbox->context2 = lpfc_nlp_get(ndlp);
4326 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
James Smart0b727fe2007-10-27 13:37:25 -04004327 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart92d7f7b2007-06-17 19:56:38 -05004328 == MBX_NOT_FINISHED) {
4329 mempool_free(mbox, phba->mbox_mem_pool);
4330 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
4331
4332 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04004333 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
4334 "0253 Register VPI: Can't send mbox\n");
James Smart92d7f7b2007-06-17 19:56:38 -05004335 }
4336 } else {
4337 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4338
James Smarte8b62012007-08-02 11:10:09 -04004339 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
4340 "0254 Register VPI: no memory\n");
James Smart92d7f7b2007-06-17 19:56:38 -05004341
4342 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
4343 lpfc_nlp_put(ndlp);
4344 }
4345}
4346
4347static void
4348lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4349 struct lpfc_iocbq *rspiocb)
4350{
4351 struct lpfc_vport *vport = cmdiocb->vport;
4352 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4353 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
4354 struct lpfc_nodelist *np;
4355 struct lpfc_nodelist *next_np;
4356 IOCB_t *irsp = &rspiocb->iocb;
4357 struct lpfc_iocbq *piocb;
4358
James Smarte8b62012007-08-02 11:10:09 -04004359 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4360 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
4361 irsp->ulpStatus, irsp->un.ulpWord[4],
4362 vport->fc_prevDID);
James Smart92d7f7b2007-06-17 19:56:38 -05004363 /* Since all FDISCs are being single threaded, we
4364 * must reset the discovery timer for ALL vports
4365 * waiting to send FDISC when one completes.
4366 */
4367 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
4368 lpfc_set_disctmo(piocb->vport);
4369 }
4370
James Smart858c9f62007-06-17 19:56:39 -05004371 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4372 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
4373 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
4374
James Smart92d7f7b2007-06-17 19:56:38 -05004375 if (irsp->ulpStatus) {
4376 /* Check for retry */
4377 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
4378 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05004379 /* FDISC failed */
James Smarte8b62012007-08-02 11:10:09 -04004380 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4381 "0124 FDISC failed. (%d/%d)\n",
4382 irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smart92d7f7b2007-06-17 19:56:38 -05004383 if (vport->fc_vport->vport_state == FC_VPORT_INITIALIZING)
4384 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4385
4386 lpfc_nlp_put(ndlp);
4387 /* giving up on FDISC. Cancel discovery timer */
4388 lpfc_can_disctmo(vport);
4389 } else {
4390 spin_lock_irq(shost->host_lock);
4391 vport->fc_flag |= FC_FABRIC;
4392 if (vport->phba->fc_topology == TOPOLOGY_LOOP)
4393 vport->fc_flag |= FC_PUBLIC_LOOP;
4394 spin_unlock_irq(shost->host_lock);
4395
4396 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
4397 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
4398 if ((vport->fc_prevDID != vport->fc_myDID) &&
4399 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
4400 /* If our NportID changed, we need to ensure all
4401 * remaining NPORTs get unreg_login'ed so we can
4402 * issue unreg_vpi.
4403 */
4404 list_for_each_entry_safe(np, next_np,
4405 &vport->fc_nodes, nlp_listp) {
4406 if (np->nlp_state != NLP_STE_NPR_NODE
4407 || !(np->nlp_flag & NLP_NPR_ADISC))
4408 continue;
4409 spin_lock_irq(shost->host_lock);
4410 np->nlp_flag &= ~NLP_NPR_ADISC;
4411 spin_unlock_irq(shost->host_lock);
4412 lpfc_unreg_rpi(vport, np);
4413 }
4414 lpfc_mbx_unreg_vpi(vport);
4415 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
4416 }
4417
4418 if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
4419 lpfc_register_new_vport(phba, vport, ndlp);
4420 else
4421 lpfc_do_scr_ns_plogi(phba, vport);
4422
4423 lpfc_nlp_put(ndlp); /* Free Fabric ndlp for vports */
4424 }
4425
4426out:
4427 lpfc_els_free_iocb(phba, cmdiocb);
4428}
4429
Adrian Bunka6ababd2007-11-05 18:07:33 +01004430static int
James Smart92d7f7b2007-06-17 19:56:38 -05004431lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4432 uint8_t retry)
4433{
4434 struct lpfc_hba *phba = vport->phba;
4435 IOCB_t *icmd;
4436 struct lpfc_iocbq *elsiocb;
4437 struct serv_parm *sp;
4438 uint8_t *pcmd;
4439 uint16_t cmdsize;
4440 int did = ndlp->nlp_DID;
4441 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05004442
4443 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
4444 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
4445 ELS_CMD_FDISC);
4446 if (!elsiocb) {
James Smart92d7f7b2007-06-17 19:56:38 -05004447 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04004448 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4449 "0255 Issue FDISC: no IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05004450 return 1;
4451 }
4452
4453 icmd = &elsiocb->iocb;
4454 icmd->un.elsreq64.myID = 0;
4455 icmd->un.elsreq64.fl = 1;
4456
4457 /* For FDISC, Let FDISC rsp set the NPortID for this VPI */
4458 icmd->ulpCt_h = 1;
4459 icmd->ulpCt_l = 0;
4460
4461 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4462 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
4463 pcmd += sizeof(uint32_t); /* CSP Word 1 */
4464 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
4465 sp = (struct serv_parm *) pcmd;
4466 /* Setup CSPs accordingly for Fabric */
4467 sp->cmn.e_d_tov = 0;
4468 sp->cmn.w2.r_a_tov = 0;
4469 sp->cls1.classValid = 0;
4470 sp->cls2.seqDelivery = 1;
4471 sp->cls3.seqDelivery = 1;
4472
4473 pcmd += sizeof(uint32_t); /* CSP Word 2 */
4474 pcmd += sizeof(uint32_t); /* CSP Word 3 */
4475 pcmd += sizeof(uint32_t); /* CSP Word 4 */
4476 pcmd += sizeof(uint32_t); /* Port Name */
4477 memcpy(pcmd, &vport->fc_portname, 8);
4478 pcmd += sizeof(uint32_t); /* Node Name */
4479 pcmd += sizeof(uint32_t); /* Node Name */
4480 memcpy(pcmd, &vport->fc_nodename, 8);
4481
4482 lpfc_set_disctmo(vport);
4483
4484 phba->fc_stat.elsXmitFDISC++;
4485 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
4486
James Smart858c9f62007-06-17 19:56:39 -05004487 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4488 "Issue FDISC: did:x%x",
4489 did, 0, 0);
4490
James Smart92d7f7b2007-06-17 19:56:38 -05004491 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
4492 if (rc == IOCB_ERROR) {
4493 lpfc_els_free_iocb(phba, elsiocb);
James Smart92d7f7b2007-06-17 19:56:38 -05004494 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04004495 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4496 "0256 Issue FDISC: Cannot send IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05004497 return 1;
4498 }
4499 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
4500 vport->port_state = LPFC_FDISC;
4501 return 0;
4502}
4503
4504static void
4505lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4506 struct lpfc_iocbq *rspiocb)
4507{
4508 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05004509 IOCB_t *irsp;
4510
4511 irsp = &rspiocb->iocb;
4512 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4513 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
4514 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
James Smart92d7f7b2007-06-17 19:56:38 -05004515
4516 lpfc_els_free_iocb(phba, cmdiocb);
4517 vport->unreg_vpi_cmpl = VPORT_ERROR;
4518}
4519
4520int
4521lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4522{
4523 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4524 struct lpfc_hba *phba = vport->phba;
4525 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
4526 IOCB_t *icmd;
4527 struct lpfc_iocbq *elsiocb;
4528 uint8_t *pcmd;
4529 uint16_t cmdsize;
4530
4531 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
4532 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
4533 ELS_CMD_LOGO);
4534 if (!elsiocb)
4535 return 1;
4536
4537 icmd = &elsiocb->iocb;
4538 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4539 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
4540 pcmd += sizeof(uint32_t);
4541
4542 /* Fill in LOGO payload */
4543 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
4544 pcmd += sizeof(uint32_t);
4545 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
4546
James Smart858c9f62007-06-17 19:56:39 -05004547 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4548 "Issue LOGO npiv did:x%x flg:x%x",
4549 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4550
James Smart92d7f7b2007-06-17 19:56:38 -05004551 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
4552 spin_lock_irq(shost->host_lock);
4553 ndlp->nlp_flag |= NLP_LOGO_SND;
4554 spin_unlock_irq(shost->host_lock);
4555 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
4556 spin_lock_irq(shost->host_lock);
4557 ndlp->nlp_flag &= ~NLP_LOGO_SND;
4558 spin_unlock_irq(shost->host_lock);
4559 lpfc_els_free_iocb(phba, elsiocb);
4560 return 1;
4561 }
4562 return 0;
4563}
4564
4565void
4566lpfc_fabric_block_timeout(unsigned long ptr)
4567{
4568 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
4569 unsigned long iflags;
4570 uint32_t tmo_posted;
4571 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
4572 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
4573 if (!tmo_posted)
4574 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
4575 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
4576
4577 if (!tmo_posted) {
4578 spin_lock_irqsave(&phba->hbalock, iflags);
4579 if (phba->work_wait)
4580 lpfc_worker_wake_up(phba);
4581 spin_unlock_irqrestore(&phba->hbalock, iflags);
4582 }
4583}
4584
4585static void
4586lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
4587{
4588 struct lpfc_iocbq *iocb;
4589 unsigned long iflags;
4590 int ret;
4591 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
4592 IOCB_t *cmd;
4593
4594repeat:
4595 iocb = NULL;
4596 spin_lock_irqsave(&phba->hbalock, iflags);
4597 /* Post any pending iocb to the SLI layer */
4598 if (atomic_read(&phba->fabric_iocb_count) == 0) {
4599 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
4600 list);
4601 if (iocb)
4602 atomic_inc(&phba->fabric_iocb_count);
4603 }
4604 spin_unlock_irqrestore(&phba->hbalock, iflags);
4605 if (iocb) {
4606 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
4607 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
4608 iocb->iocb_flag |= LPFC_IO_FABRIC;
4609
James Smart858c9f62007-06-17 19:56:39 -05004610 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
4611 "Fabric sched1: ste:x%x",
4612 iocb->vport->port_state, 0, 0);
4613
James Smart92d7f7b2007-06-17 19:56:38 -05004614 ret = lpfc_sli_issue_iocb(phba, pring, iocb, 0);
4615
4616 if (ret == IOCB_ERROR) {
4617 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
4618 iocb->fabric_iocb_cmpl = NULL;
4619 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
4620 cmd = &iocb->iocb;
4621 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
4622 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
4623 iocb->iocb_cmpl(phba, iocb, iocb);
4624
4625 atomic_dec(&phba->fabric_iocb_count);
4626 goto repeat;
4627 }
4628 }
4629
4630 return;
4631}
4632
4633void
4634lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
4635{
4636 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
4637
4638 lpfc_resume_fabric_iocbs(phba);
4639 return;
4640}
4641
4642static void
4643lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
4644{
4645 int blocked;
4646
4647 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
4648 /* Start a timer to unblock fabric
4649 * iocbs after 100ms
4650 */
4651 if (!blocked)
4652 mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 );
4653
4654 return;
4655}
4656
4657static void
4658lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4659 struct lpfc_iocbq *rspiocb)
4660{
4661 struct ls_rjt stat;
4662
4663 if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
4664 BUG();
4665
4666 switch (rspiocb->iocb.ulpStatus) {
4667 case IOSTAT_NPORT_RJT:
4668 case IOSTAT_FABRIC_RJT:
4669 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
4670 lpfc_block_fabric_iocbs(phba);
4671 }
4672 break;
4673
4674 case IOSTAT_NPORT_BSY:
4675 case IOSTAT_FABRIC_BSY:
4676 lpfc_block_fabric_iocbs(phba);
4677 break;
4678
4679 case IOSTAT_LS_RJT:
4680 stat.un.lsRjtError =
4681 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
4682 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
4683 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
4684 lpfc_block_fabric_iocbs(phba);
4685 break;
4686 }
4687
4688 if (atomic_read(&phba->fabric_iocb_count) == 0)
4689 BUG();
4690
4691 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
4692 cmdiocb->fabric_iocb_cmpl = NULL;
4693 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
4694 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
4695
4696 atomic_dec(&phba->fabric_iocb_count);
4697 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
4698 /* Post any pending iocbs to HBA */
4699 lpfc_resume_fabric_iocbs(phba);
4700 }
4701}
4702
Adrian Bunka6ababd2007-11-05 18:07:33 +01004703static int
James Smart92d7f7b2007-06-17 19:56:38 -05004704lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
4705{
4706 unsigned long iflags;
4707 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
4708 int ready;
4709 int ret;
4710
4711 if (atomic_read(&phba->fabric_iocb_count) > 1)
4712 BUG();
4713
4714 spin_lock_irqsave(&phba->hbalock, iflags);
4715 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
4716 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
4717
4718 spin_unlock_irqrestore(&phba->hbalock, iflags);
4719 if (ready) {
4720 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
4721 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
4722 iocb->iocb_flag |= LPFC_IO_FABRIC;
4723
James Smart858c9f62007-06-17 19:56:39 -05004724 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
4725 "Fabric sched2: ste:x%x",
4726 iocb->vport->port_state, 0, 0);
4727
James Smart92d7f7b2007-06-17 19:56:38 -05004728 atomic_inc(&phba->fabric_iocb_count);
4729 ret = lpfc_sli_issue_iocb(phba, pring, iocb, 0);
4730
4731 if (ret == IOCB_ERROR) {
4732 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
4733 iocb->fabric_iocb_cmpl = NULL;
4734 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
4735 atomic_dec(&phba->fabric_iocb_count);
4736 }
4737 } else {
4738 spin_lock_irqsave(&phba->hbalock, iflags);
4739 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
4740 spin_unlock_irqrestore(&phba->hbalock, iflags);
4741 ret = IOCB_SUCCESS;
4742 }
4743 return ret;
4744}
4745
4746
Adrian Bunka6ababd2007-11-05 18:07:33 +01004747static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
James Smart92d7f7b2007-06-17 19:56:38 -05004748{
4749 LIST_HEAD(completions);
4750 struct lpfc_hba *phba = vport->phba;
4751 struct lpfc_iocbq *tmp_iocb, *piocb;
4752 IOCB_t *cmd;
4753
4754 spin_lock_irq(&phba->hbalock);
4755 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
4756 list) {
4757
4758 if (piocb->vport != vport)
4759 continue;
4760
4761 list_move_tail(&piocb->list, &completions);
4762 }
4763 spin_unlock_irq(&phba->hbalock);
4764
4765 while (!list_empty(&completions)) {
4766 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
4767 list_del_init(&piocb->list);
4768
4769 cmd = &piocb->iocb;
4770 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
4771 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
4772 (piocb->iocb_cmpl) (phba, piocb, piocb);
4773 }
4774}
4775
4776void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
4777{
4778 LIST_HEAD(completions);
4779 struct lpfc_hba *phba = ndlp->vport->phba;
4780 struct lpfc_iocbq *tmp_iocb, *piocb;
4781 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
4782 IOCB_t *cmd;
4783
4784 spin_lock_irq(&phba->hbalock);
4785 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
4786 list) {
4787 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
4788
4789 list_move_tail(&piocb->list, &completions);
4790 }
4791 }
4792 spin_unlock_irq(&phba->hbalock);
4793
4794 while (!list_empty(&completions)) {
4795 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
4796 list_del_init(&piocb->list);
4797
4798 cmd = &piocb->iocb;
4799 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
4800 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
4801 (piocb->iocb_cmpl) (phba, piocb, piocb);
4802 }
4803}
4804
4805void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
4806{
4807 LIST_HEAD(completions);
4808 struct lpfc_iocbq *piocb;
4809 IOCB_t *cmd;
4810
4811 spin_lock_irq(&phba->hbalock);
4812 list_splice_init(&phba->fabric_iocb_list, &completions);
4813 spin_unlock_irq(&phba->hbalock);
4814
4815 while (!list_empty(&completions)) {
4816 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
4817 list_del_init(&piocb->list);
4818
4819 cmd = &piocb->iocb;
4820 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
4821 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
4822 (piocb->iocb_cmpl) (phba, piocb, piocb);
4823 }
4824}
4825
4826
Adrian Bunka6ababd2007-11-05 18:07:33 +01004827#if 0
James Smart92d7f7b2007-06-17 19:56:38 -05004828void lpfc_fabric_abort_flogi(struct lpfc_hba *phba)
4829{
4830 LIST_HEAD(completions);
4831 struct lpfc_iocbq *tmp_iocb, *piocb;
4832 IOCB_t *cmd;
4833 struct lpfc_nodelist *ndlp;
4834
4835 spin_lock_irq(&phba->hbalock);
4836 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
4837 list) {
4838
4839 cmd = &piocb->iocb;
4840 ndlp = (struct lpfc_nodelist *) piocb->context1;
4841 if (cmd->ulpCommand == CMD_ELS_REQUEST64_CR &&
4842 ndlp != NULL &&
4843 ndlp->nlp_DID == Fabric_DID)
4844 list_move_tail(&piocb->list, &completions);
4845 }
4846 spin_unlock_irq(&phba->hbalock);
4847
4848 while (!list_empty(&completions)) {
4849 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
4850 list_del_init(&piocb->list);
4851
4852 cmd = &piocb->iocb;
4853 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
4854 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
4855 (piocb->iocb_cmpl) (phba, piocb, piocb);
4856 }
4857}
Adrian Bunka6ababd2007-11-05 18:07:33 +01004858#endif /* 0 */
James Smart92d7f7b2007-06-17 19:56:38 -05004859
4860