blob: 813eeca7ce1e26e07bf69b6c55d92d549bca5e7d [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 *);
45
dea31012005-04-17 16:05:31 -050046static int lpfc_max_els_tries = 3;
47
James Smart858c9f62007-06-17 19:56:39 -050048int
James Smart2e0fef82007-06-17 19:56:36 -050049lpfc_els_chk_latt(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -050050{
James Smart2e0fef82007-06-17 19:56:36 -050051 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
52 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -050053 uint32_t ha_copy;
dea31012005-04-17 16:05:31 -050054
James Smart2e0fef82007-06-17 19:56:36 -050055 if (vport->port_state >= LPFC_VPORT_READY ||
56 phba->link_state == LPFC_LINK_DOWN)
dea31012005-04-17 16:05:31 -050057 return 0;
58
59 /* Read the HBA Host Attention Register */
dea31012005-04-17 16:05:31 -050060 ha_copy = readl(phba->HAregaddr);
dea31012005-04-17 16:05:31 -050061
62 if (!(ha_copy & HA_LATT))
63 return 0;
64
65 /* Pending Link Event during Discovery */
James Smarte8b62012007-08-02 11:10:09 -040066 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
67 "0237 Pending Link Event during "
68 "Discovery: State x%x\n",
69 phba->pport->port_state);
dea31012005-04-17 16:05:31 -050070
71 /* CLEAR_LA should re-enable link attention events and
72 * we should then imediately take a LATT event. The
73 * LATT processing should call lpfc_linkdown() which
74 * will cleanup any left over in-progress discovery
75 * events.
76 */
James Smart2e0fef82007-06-17 19:56:36 -050077 spin_lock_irq(shost->host_lock);
78 vport->fc_flag |= FC_ABORT_DISCOVERY;
79 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -050080
James Smart92d7f7b2007-06-17 19:56:38 -050081 if (phba->link_state != LPFC_CLEAR_LA)
James Smarted957682007-06-17 19:56:37 -050082 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -050083
Jamie Wellnitzc9f87352006-02-28 19:25:23 -050084 return 1;
dea31012005-04-17 16:05:31 -050085}
86
87static struct lpfc_iocbq *
James Smart2e0fef82007-06-17 19:56:36 -050088lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp,
89 uint16_t cmdSize, uint8_t retry,
90 struct lpfc_nodelist *ndlp, uint32_t did,
91 uint32_t elscmd)
dea31012005-04-17 16:05:31 -050092{
James Smart2e0fef82007-06-17 19:56:36 -050093 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -040094 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -050095 struct lpfc_dmabuf *pcmd, *prsp, *pbuflist;
96 struct ulp_bde64 *bpl;
97 IOCB_t *icmd;
98
dea31012005-04-17 16:05:31 -050099
James Smart2e0fef82007-06-17 19:56:36 -0500100 if (!lpfc_is_link_up(phba))
101 return NULL;
dea31012005-04-17 16:05:31 -0500102
dea31012005-04-17 16:05:31 -0500103 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400104 elsiocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -0500105
106 if (elsiocb == NULL)
107 return NULL;
dea31012005-04-17 16:05:31 -0500108 icmd = &elsiocb->iocb;
109
110 /* fill in BDEs for command */
111 /* Allocate buffer for command payload */
James Smart98c9ea52007-10-27 13:37:33 -0400112 pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
113 if (pcmd)
114 pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys);
115 if (!pcmd || !pcmd->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -0800116 kfree(pcmd);
dea31012005-04-17 16:05:31 -0500117
James Bottomley604a3e32005-10-29 10:28:33 -0500118 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -0500119 return NULL;
120 }
121
122 INIT_LIST_HEAD(&pcmd->list);
123
124 /* Allocate buffer for response payload */
125 if (expectRsp) {
James Smart92d7f7b2007-06-17 19:56:38 -0500126 prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -0500127 if (prsp)
128 prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
129 &prsp->phys);
James Smart98c9ea52007-10-27 13:37:33 -0400130 if (!prsp || !prsp->virt) {
Jesper Juhlc9475cb2005-11-07 01:01:26 -0800131 kfree(prsp);
dea31012005-04-17 16:05:31 -0500132 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
133 kfree(pcmd);
James Bottomley604a3e32005-10-29 10:28:33 -0500134 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -0500135 return NULL;
136 }
137 INIT_LIST_HEAD(&prsp->list);
138 } else {
139 prsp = NULL;
140 }
141
142 /* Allocate buffer for Buffer ptr list */
James Smart92d7f7b2007-06-17 19:56:38 -0500143 pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -0500144 if (pbuflist)
James Smarted957682007-06-17 19:56:37 -0500145 pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
146 &pbuflist->phys);
James Smart98c9ea52007-10-27 13:37:33 -0400147 if (!pbuflist || !pbuflist->virt) {
James Bottomley604a3e32005-10-29 10:28:33 -0500148 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -0500149 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
150 lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
151 kfree(pcmd);
152 kfree(prsp);
Jesper Juhlc9475cb2005-11-07 01:01:26 -0800153 kfree(pbuflist);
dea31012005-04-17 16:05:31 -0500154 return NULL;
155 }
156
157 INIT_LIST_HEAD(&pbuflist->list);
158
159 icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
160 icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
161 icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BDL;
James Smart2e0fef82007-06-17 19:56:36 -0500162 icmd->un.elsreq64.remoteID = did; /* DID */
dea31012005-04-17 16:05:31 -0500163 if (expectRsp) {
James Smart92d7f7b2007-06-17 19:56:38 -0500164 icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
dea31012005-04-17 16:05:31 -0500165 icmd->ulpCommand = CMD_ELS_REQUEST64_CR;
James Smart2680eea2007-04-25 09:52:55 -0400166 icmd->ulpTimeout = phba->fc_ratov * 2;
dea31012005-04-17 16:05:31 -0500167 } else {
James Smart92d7f7b2007-06-17 19:56:38 -0500168 icmd->un.elsreq64.bdl.bdeSize = sizeof(struct ulp_bde64);
dea31012005-04-17 16:05:31 -0500169 icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
170 }
dea31012005-04-17 16:05:31 -0500171 icmd->ulpBdeCount = 1;
172 icmd->ulpLe = 1;
173 icmd->ulpClass = CLASS3;
174
James Smart92d7f7b2007-06-17 19:56:38 -0500175 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
176 icmd->un.elsreq64.myID = vport->fc_myDID;
177
178 /* For ELS_REQUEST64_CR, use the VPI by default */
179 icmd->ulpContext = vport->vpi;
180 icmd->ulpCt_h = 0;
181 icmd->ulpCt_l = 1;
182 }
183
dea31012005-04-17 16:05:31 -0500184 bpl = (struct ulp_bde64 *) pbuflist->virt;
185 bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys));
186 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys));
187 bpl->tus.f.bdeSize = cmdSize;
188 bpl->tus.f.bdeFlags = 0;
189 bpl->tus.w = le32_to_cpu(bpl->tus.w);
190
191 if (expectRsp) {
192 bpl++;
193 bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys));
194 bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys));
195 bpl->tus.f.bdeSize = FCELSSIZE;
196 bpl->tus.f.bdeFlags = BUFF_USE_RCV;
197 bpl->tus.w = le32_to_cpu(bpl->tus.w);
198 }
199
James Smart51ef4c22007-08-02 11:10:31 -0400200 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart329f9bc2007-04-25 09:53:01 -0400201 elsiocb->context2 = pcmd;
202 elsiocb->context3 = pbuflist;
dea31012005-04-17 16:05:31 -0500203 elsiocb->retry = retry;
James Smart2e0fef82007-06-17 19:56:36 -0500204 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -0500205 elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
206
207 if (prsp) {
208 list_add(&prsp->list, &pcmd->list);
209 }
dea31012005-04-17 16:05:31 -0500210 if (expectRsp) {
211 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400212 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
213 "0116 Xmit ELS command x%x to remote "
214 "NPORT x%x I/O tag: x%x, port state: x%x\n",
215 elscmd, did, elsiocb->iotag,
216 vport->port_state);
dea31012005-04-17 16:05:31 -0500217 } else {
218 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400219 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
220 "0117 Xmit ELS response x%x to remote "
221 "NPORT x%x I/O tag: x%x, size: x%x\n",
222 elscmd, ndlp->nlp_DID, elsiocb->iotag,
223 cmdSize);
dea31012005-04-17 16:05:31 -0500224 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500225 return elsiocb;
dea31012005-04-17 16:05:31 -0500226}
227
228
229static int
James Smart92d7f7b2007-06-17 19:56:38 -0500230lpfc_issue_fabric_reglogin(struct lpfc_vport *vport)
231{
232 struct lpfc_hba *phba = vport->phba;
233 LPFC_MBOXQ_t *mbox;
234 struct lpfc_dmabuf *mp;
235 struct lpfc_nodelist *ndlp;
236 struct serv_parm *sp;
237 int rc;
James Smart98c9ea52007-10-27 13:37:33 -0400238 int err = 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500239
240 sp = &phba->fc_fabparam;
241 ndlp = lpfc_findnode_did(vport, Fabric_DID);
James Smart98c9ea52007-10-27 13:37:33 -0400242 if (!ndlp) {
243 err = 1;
James Smart92d7f7b2007-06-17 19:56:38 -0500244 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400245 }
James Smart92d7f7b2007-06-17 19:56:38 -0500246
247 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart98c9ea52007-10-27 13:37:33 -0400248 if (!mbox) {
249 err = 2;
James Smart92d7f7b2007-06-17 19:56:38 -0500250 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400251 }
James Smart92d7f7b2007-06-17 19:56:38 -0500252
253 vport->port_state = LPFC_FABRIC_CFG_LINK;
254 lpfc_config_link(phba, mbox);
255 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
256 mbox->vport = vport;
257
James Smart0b727fe2007-10-27 13:37:25 -0400258 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart98c9ea52007-10-27 13:37:33 -0400259 if (rc == MBX_NOT_FINISHED) {
260 err = 3;
James Smart92d7f7b2007-06-17 19:56:38 -0500261 goto fail_free_mbox;
James Smart98c9ea52007-10-27 13:37:33 -0400262 }
James Smart92d7f7b2007-06-17 19:56:38 -0500263
264 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart98c9ea52007-10-27 13:37:33 -0400265 if (!mbox) {
266 err = 4;
James Smart92d7f7b2007-06-17 19:56:38 -0500267 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400268 }
James Smart92d7f7b2007-06-17 19:56:38 -0500269 rc = lpfc_reg_login(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox,
270 0);
James Smart98c9ea52007-10-27 13:37:33 -0400271 if (rc) {
272 err = 5;
James Smart92d7f7b2007-06-17 19:56:38 -0500273 goto fail_free_mbox;
James Smart98c9ea52007-10-27 13:37:33 -0400274 }
James Smart92d7f7b2007-06-17 19:56:38 -0500275
276 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
277 mbox->vport = vport;
278 mbox->context2 = lpfc_nlp_get(ndlp);
279
James Smart0b727fe2007-10-27 13:37:25 -0400280 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart98c9ea52007-10-27 13:37:33 -0400281 if (rc == MBX_NOT_FINISHED) {
282 err = 6;
James Smart92d7f7b2007-06-17 19:56:38 -0500283 goto fail_issue_reg_login;
James Smart98c9ea52007-10-27 13:37:33 -0400284 }
James Smart92d7f7b2007-06-17 19:56:38 -0500285
286 return 0;
287
288fail_issue_reg_login:
289 lpfc_nlp_put(ndlp);
290 mp = (struct lpfc_dmabuf *) mbox->context1;
291 lpfc_mbuf_free(phba, mp->virt, mp->phys);
292 kfree(mp);
293fail_free_mbox:
294 mempool_free(mbox, phba->mbox_mem_pool);
295
296fail:
297 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -0400298 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smart98c9ea52007-10-27 13:37:33 -0400299 "0249 Cannot issue Register Fabric login: Err %d\n", err);
James Smart92d7f7b2007-06-17 19:56:38 -0500300 return -ENXIO;
301}
302
303static int
James Smart2e0fef82007-06-17 19:56:36 -0500304lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
305 struct serv_parm *sp, IOCB_t *irsp)
dea31012005-04-17 16:05:31 -0500306{
James Smart2e0fef82007-06-17 19:56:36 -0500307 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
308 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -0500309 struct lpfc_nodelist *np;
310 struct lpfc_nodelist *next_np;
dea31012005-04-17 16:05:31 -0500311
James Smart2e0fef82007-06-17 19:56:36 -0500312 spin_lock_irq(shost->host_lock);
313 vport->fc_flag |= FC_FABRIC;
314 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500315
316 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
317 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
318 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
319
320 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
321
322 if (phba->fc_topology == TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500323 spin_lock_irq(shost->host_lock);
324 vport->fc_flag |= FC_PUBLIC_LOOP;
325 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500326 } else {
327 /*
328 * If we are a N-port connected to a Fabric, fixup sparam's so
329 * logins to devices on remote loops work.
330 */
James Smart2e0fef82007-06-17 19:56:36 -0500331 vport->fc_sparam.cmn.altBbCredit = 1;
dea31012005-04-17 16:05:31 -0500332 }
333
James Smart2e0fef82007-06-17 19:56:36 -0500334 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
dea31012005-04-17 16:05:31 -0500335 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
James Smart92d7f7b2007-06-17 19:56:38 -0500336 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500337 ndlp->nlp_class_sup = 0;
338 if (sp->cls1.classValid)
339 ndlp->nlp_class_sup |= FC_COS_CLASS1;
340 if (sp->cls2.classValid)
341 ndlp->nlp_class_sup |= FC_COS_CLASS2;
342 if (sp->cls3.classValid)
343 ndlp->nlp_class_sup |= FC_COS_CLASS3;
344 if (sp->cls4.classValid)
345 ndlp->nlp_class_sup |= FC_COS_CLASS4;
346 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
347 sp->cmn.bbRcvSizeLsb;
348 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
349
James Smart92d7f7b2007-06-17 19:56:38 -0500350 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
351 if (sp->cmn.response_multiple_NPort) {
James Smarte8b62012007-08-02 11:10:09 -0400352 lpfc_printf_vlog(vport, KERN_WARNING,
353 LOG_ELS | LOG_VPORT,
354 "1816 FLOGI NPIV supported, "
355 "response data 0x%x\n",
356 sp->cmn.response_multiple_NPort);
James Smart92d7f7b2007-06-17 19:56:38 -0500357 phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
James Smart92d7f7b2007-06-17 19:56:38 -0500358 } else {
359 /* Because we asked f/w for NPIV it still expects us
James Smarte8b62012007-08-02 11:10:09 -0400360 to call reg_vnpid atleast for the physcial host */
361 lpfc_printf_vlog(vport, KERN_WARNING,
362 LOG_ELS | LOG_VPORT,
363 "1817 Fabric does not support NPIV "
364 "- configuring single port mode.\n");
James Smart92d7f7b2007-06-17 19:56:38 -0500365 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
366 }
367 }
368
369 if ((vport->fc_prevDID != vport->fc_myDID) &&
370 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
371
372 /* If our NportID changed, we need to ensure all
373 * remaining NPORTs get unreg_login'ed.
374 */
375 list_for_each_entry_safe(np, next_np,
376 &vport->fc_nodes, nlp_listp) {
377 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
378 !(np->nlp_flag & NLP_NPR_ADISC))
379 continue;
380 spin_lock_irq(shost->host_lock);
381 np->nlp_flag &= ~NLP_NPR_ADISC;
382 spin_unlock_irq(shost->host_lock);
383 lpfc_unreg_rpi(vport, np);
384 }
385 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
386 lpfc_mbx_unreg_vpi(vport);
387 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
388 }
389 }
390
James Smart2e0fef82007-06-17 19:56:36 -0500391 ndlp->nlp_sid = irsp->un.ulpWord[4] & Mask_DID;
James Smart92d7f7b2007-06-17 19:56:38 -0500392 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -0500393
James Smart92d7f7b2007-06-17 19:56:38 -0500394 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
395 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) {
396 lpfc_register_new_vport(phba, vport, ndlp);
397 return 0;
398 }
399 lpfc_issue_fabric_reglogin(vport);
dea31012005-04-17 16:05:31 -0500400 return 0;
dea31012005-04-17 16:05:31 -0500401}
402
403/*
404 * We FLOGIed into an NPort, initiate pt2pt protocol
405 */
406static int
James Smart2e0fef82007-06-17 19:56:36 -0500407lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
408 struct serv_parm *sp)
dea31012005-04-17 16:05:31 -0500409{
James Smart2e0fef82007-06-17 19:56:36 -0500410 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
411 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500412 LPFC_MBOXQ_t *mbox;
413 int rc;
414
James Smart2e0fef82007-06-17 19:56:36 -0500415 spin_lock_irq(shost->host_lock);
416 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
417 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500418
419 phba->fc_edtov = FF_DEF_EDTOV;
420 phba->fc_ratov = FF_DEF_RATOV;
James Smart2e0fef82007-06-17 19:56:36 -0500421 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -0500422 sizeof(vport->fc_portname));
dea31012005-04-17 16:05:31 -0500423 if (rc >= 0) {
424 /* This side will initiate the PLOGI */
James Smart2e0fef82007-06-17 19:56:36 -0500425 spin_lock_irq(shost->host_lock);
426 vport->fc_flag |= FC_PT2PT_PLOGI;
427 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500428
429 /*
430 * N_Port ID cannot be 0, set our to LocalID the other
431 * side will be RemoteID.
432 */
433
434 /* not equal */
435 if (rc)
James Smart2e0fef82007-06-17 19:56:36 -0500436 vport->fc_myDID = PT2PT_LocalID;
dea31012005-04-17 16:05:31 -0500437
438 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
439 if (!mbox)
440 goto fail;
441
442 lpfc_config_link(phba, mbox);
443
444 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -0500445 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -0400446 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -0500447 if (rc == MBX_NOT_FINISHED) {
448 mempool_free(mbox, phba->mbox_mem_pool);
449 goto fail;
450 }
James Smart329f9bc2007-04-25 09:53:01 -0400451 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500452
James Smart2e0fef82007-06-17 19:56:36 -0500453 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
dea31012005-04-17 16:05:31 -0500454 if (!ndlp) {
455 /*
456 * Cannot find existing Fabric ndlp, so allocate a
457 * new one
458 */
459 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
460 if (!ndlp)
461 goto fail;
462
James Smart2e0fef82007-06-17 19:56:36 -0500463 lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID);
dea31012005-04-17 16:05:31 -0500464 }
465
466 memcpy(&ndlp->nlp_portname, &sp->portName,
James Smart2e0fef82007-06-17 19:56:36 -0500467 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500468 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
James Smart2e0fef82007-06-17 19:56:36 -0500469 sizeof(struct lpfc_name));
470 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
471 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500472 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500473 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500474 } else {
475 /* This side will wait for the PLOGI */
James Smart329f9bc2007-04-25 09:53:01 -0400476 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500477 }
478
James Smart2e0fef82007-06-17 19:56:36 -0500479 spin_lock_irq(shost->host_lock);
480 vport->fc_flag |= FC_PT2PT;
481 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500482
483 /* Start discovery - this should just do CLEAR_LA */
James Smart2e0fef82007-06-17 19:56:36 -0500484 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -0500485 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500486fail:
dea31012005-04-17 16:05:31 -0500487 return -ENXIO;
488}
489
490static void
James Smart329f9bc2007-04-25 09:53:01 -0400491lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
492 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500493{
James Smart2e0fef82007-06-17 19:56:36 -0500494 struct lpfc_vport *vport = cmdiocb->vport;
495 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500496 IOCB_t *irsp = &rspiocb->iocb;
497 struct lpfc_nodelist *ndlp = cmdiocb->context1;
498 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
499 struct serv_parm *sp;
500 int rc;
501
502 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500503 if (lpfc_els_chk_latt(vport)) {
James Smart329f9bc2007-04-25 09:53:01 -0400504 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500505 goto out;
506 }
507
James Smart858c9f62007-06-17 19:56:39 -0500508 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
509 "FLOGI cmpl: status:x%x/x%x state:x%x",
510 irsp->ulpStatus, irsp->un.ulpWord[4],
511 vport->port_state);
512
dea31012005-04-17 16:05:31 -0500513 if (irsp->ulpStatus) {
514 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -0500515 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -0500516 goto out;
James Smart2e0fef82007-06-17 19:56:36 -0500517
dea31012005-04-17 16:05:31 -0500518 /* FLOGI failed, so there is no fabric */
James Smart2e0fef82007-06-17 19:56:36 -0500519 spin_lock_irq(shost->host_lock);
520 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
521 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500522
James Smart329f9bc2007-04-25 09:53:01 -0400523 /* If private loop, then allow max outstanding els to be
dea31012005-04-17 16:05:31 -0500524 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
525 * alpa map would take too long otherwise.
526 */
527 if (phba->alpa_map[0] == 0) {
James Smart3de2a652007-08-02 11:09:59 -0400528 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
dea31012005-04-17 16:05:31 -0500529 }
530
531 /* FLOGI failure */
James Smarte8b62012007-08-02 11:10:09 -0400532 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
533 "0100 FLOGI failure Data: x%x x%x "
534 "x%x\n",
535 irsp->ulpStatus, irsp->un.ulpWord[4],
536 irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -0500537 goto flogifail;
538 }
539
540 /*
541 * The FLogI succeeded. Sync the data for the CPU before
542 * accessing it.
543 */
544 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
545
546 sp = prsp->virt + sizeof(uint32_t);
547
548 /* FLOGI completes successfully */
James Smarte8b62012007-08-02 11:10:09 -0400549 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
550 "0101 FLOGI completes sucessfully "
551 "Data: x%x x%x x%x x%x\n",
552 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
553 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution);
dea31012005-04-17 16:05:31 -0500554
James Smart2e0fef82007-06-17 19:56:36 -0500555 if (vport->port_state == LPFC_FLOGI) {
dea31012005-04-17 16:05:31 -0500556 /*
557 * If Common Service Parameters indicate Nport
558 * we are point to point, if Fport we are Fabric.
559 */
560 if (sp->cmn.fPort)
James Smart2e0fef82007-06-17 19:56:36 -0500561 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
dea31012005-04-17 16:05:31 -0500562 else
James Smart2e0fef82007-06-17 19:56:36 -0500563 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
dea31012005-04-17 16:05:31 -0500564
565 if (!rc)
566 goto out;
567 }
568
569flogifail:
James Smart329f9bc2007-04-25 09:53:01 -0400570 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500571
James Smart858c9f62007-06-17 19:56:39 -0500572 if (!lpfc_error_lost_link(irsp)) {
dea31012005-04-17 16:05:31 -0500573 /* FLOGI failed, so just use loop map to make discovery list */
James Smart2e0fef82007-06-17 19:56:36 -0500574 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -0500575
576 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500577 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -0500578 }
579
580out:
581 lpfc_els_free_iocb(phba, cmdiocb);
582}
583
584static int
James Smart2e0fef82007-06-17 19:56:36 -0500585lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -0500586 uint8_t retry)
587{
James Smart2e0fef82007-06-17 19:56:36 -0500588 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500589 struct serv_parm *sp;
590 IOCB_t *icmd;
591 struct lpfc_iocbq *elsiocb;
592 struct lpfc_sli_ring *pring;
593 uint8_t *pcmd;
594 uint16_t cmdsize;
595 uint32_t tmo;
596 int rc;
597
598 pring = &phba->sli.ring[LPFC_ELS_RING];
599
James Smart92d7f7b2007-06-17 19:56:38 -0500600 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart2e0fef82007-06-17 19:56:36 -0500601 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
602 ndlp->nlp_DID, ELS_CMD_FLOGI);
James Smart92d7f7b2007-06-17 19:56:38 -0500603
James Smart488d1462006-03-07 15:02:37 -0500604 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500605 return 1;
dea31012005-04-17 16:05:31 -0500606
607 icmd = &elsiocb->iocb;
608 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
609
610 /* For FLOGI request, remainder of payload is service parameters */
611 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -0500612 pcmd += sizeof(uint32_t);
613 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -0500614 sp = (struct serv_parm *) pcmd;
615
616 /* Setup CSPs accordingly for Fabric */
617 sp->cmn.e_d_tov = 0;
618 sp->cmn.w2.r_a_tov = 0;
619 sp->cls1.classValid = 0;
620 sp->cls2.seqDelivery = 1;
621 sp->cls3.seqDelivery = 1;
622 if (sp->cmn.fcphLow < FC_PH3)
623 sp->cmn.fcphLow = FC_PH3;
624 if (sp->cmn.fcphHigh < FC_PH3)
625 sp->cmn.fcphHigh = FC_PH3;
626
James Smart92d7f7b2007-06-17 19:56:38 -0500627 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
628 sp->cmn.request_multiple_Nport = 1;
629
630 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
631 icmd->ulpCt_h = 1;
632 icmd->ulpCt_l = 0;
633 }
634
James Smart858c9f62007-06-17 19:56:39 -0500635 if (phba->fc_topology != TOPOLOGY_LOOP) {
636 icmd->un.elsreq64.myID = 0;
637 icmd->un.elsreq64.fl = 1;
638 }
639
dea31012005-04-17 16:05:31 -0500640 tmo = phba->fc_ratov;
641 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
James Smart2e0fef82007-06-17 19:56:36 -0500642 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -0500643 phba->fc_ratov = tmo;
644
645 phba->fc_stat.elsXmitFLOGI++;
646 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
James Smart858c9f62007-06-17 19:56:39 -0500647
648 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
649 "Issue FLOGI: opt:x%x",
650 phba->sli3_options, 0, 0);
651
James Smart92d7f7b2007-06-17 19:56:38 -0500652 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
dea31012005-04-17 16:05:31 -0500653 if (rc == IOCB_ERROR) {
654 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500655 return 1;
dea31012005-04-17 16:05:31 -0500656 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500657 return 0;
dea31012005-04-17 16:05:31 -0500658}
659
660int
James Smart2e0fef82007-06-17 19:56:36 -0500661lpfc_els_abort_flogi(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500662{
663 struct lpfc_sli_ring *pring;
664 struct lpfc_iocbq *iocb, *next_iocb;
665 struct lpfc_nodelist *ndlp;
666 IOCB_t *icmd;
667
668 /* Abort outstanding I/O on NPort <nlp_DID> */
669 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -0400670 "0201 Abort outstanding I/O on NPort x%x\n",
671 Fabric_DID);
dea31012005-04-17 16:05:31 -0500672
673 pring = &phba->sli.ring[LPFC_ELS_RING];
674
675 /*
676 * Check the txcmplq for an iocb that matches the nport the driver is
677 * searching for.
678 */
James Smart2e0fef82007-06-17 19:56:36 -0500679 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500680 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
681 icmd = &iocb->iocb;
James Smart2e0fef82007-06-17 19:56:36 -0500682 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR &&
683 icmd->un.elsreq64.bdl.ulpIoTag32) {
dea31012005-04-17 16:05:31 -0500684 ndlp = (struct lpfc_nodelist *)(iocb->context1);
James Smart92d7f7b2007-06-17 19:56:38 -0500685 if (ndlp && (ndlp->nlp_DID == Fabric_DID)) {
James Smart07951072007-04-25 09:51:38 -0400686 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
James Smart92d7f7b2007-06-17 19:56:38 -0500687 }
dea31012005-04-17 16:05:31 -0500688 }
689 }
James Smart2e0fef82007-06-17 19:56:36 -0500690 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500691
692 return 0;
693}
694
695int
James Smart2e0fef82007-06-17 19:56:36 -0500696lpfc_initial_flogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -0500697{
James Smart2e0fef82007-06-17 19:56:36 -0500698 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500699 struct lpfc_nodelist *ndlp;
700
James Smart98c9ea52007-10-27 13:37:33 -0400701 vport->port_state = LPFC_FLOGI;
702 lpfc_set_disctmo(vport);
703
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500704 /* First look for the Fabric ndlp */
James Smart2e0fef82007-06-17 19:56:36 -0500705 ndlp = lpfc_findnode_did(vport, Fabric_DID);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500706 if (!ndlp) {
dea31012005-04-17 16:05:31 -0500707 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500708 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
709 if (!ndlp)
710 return 0;
James Smart2e0fef82007-06-17 19:56:36 -0500711 lpfc_nlp_init(vport, ndlp, Fabric_DID);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500712 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500713 lpfc_dequeue_node(vport, ndlp);
James Smart98c9ea52007-10-27 13:37:33 -0400714
715 /* If we go thru this path, Fabric_DID ndlp is in the process
716 * of being removed. We need to bump the reference count by 1
717 * so it stays around all through this link up period.
718 */
719 lpfc_nlp_get(ndlp);
dea31012005-04-17 16:05:31 -0500720 }
James Smart2e0fef82007-06-17 19:56:36 -0500721 if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
James Smart329f9bc2007-04-25 09:53:01 -0400722 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500723 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500724 return 1;
dea31012005-04-17 16:05:31 -0500725}
726
James Smart92d7f7b2007-06-17 19:56:38 -0500727int
728lpfc_initial_fdisc(struct lpfc_vport *vport)
729{
730 struct lpfc_hba *phba = vport->phba;
731 struct lpfc_nodelist *ndlp;
732
733 /* First look for the Fabric ndlp */
734 ndlp = lpfc_findnode_did(vport, Fabric_DID);
735 if (!ndlp) {
736 /* Cannot find existing Fabric ndlp, so allocate a new one */
737 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
738 if (!ndlp)
739 return 0;
740 lpfc_nlp_init(vport, ndlp, Fabric_DID);
741 } else {
742 lpfc_dequeue_node(vport, ndlp);
743 }
744 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
745 lpfc_nlp_put(ndlp);
746 }
747 return 1;
748}
dea31012005-04-17 16:05:31 -0500749static void
James Smart2e0fef82007-06-17 19:56:36 -0500750lpfc_more_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -0500751{
752 int sentplogi;
753
James Smart2e0fef82007-06-17 19:56:36 -0500754 if (vport->num_disc_nodes)
755 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -0500756
757 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
James Smarte8b62012007-08-02 11:10:09 -0400758 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
759 "0232 Continue discovery with %d PLOGIs to go "
760 "Data: x%x x%x x%x\n",
761 vport->num_disc_nodes, vport->fc_plogi_cnt,
762 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -0500763 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -0500764 if (vport->fc_flag & FC_NLP_MORE)
765 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
766 sentplogi = lpfc_els_disc_plogi(vport);
767
dea31012005-04-17 16:05:31 -0500768 return;
769}
770
James Smart488d1462006-03-07 15:02:37 -0500771static struct lpfc_nodelist *
James Smart92d7f7b2007-06-17 19:56:38 -0500772lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
James Smart488d1462006-03-07 15:02:37 -0500773 struct lpfc_nodelist *ndlp)
774{
James Smart2e0fef82007-06-17 19:56:36 -0500775 struct lpfc_vport *vport = ndlp->vport;
James Smart488d1462006-03-07 15:02:37 -0500776 struct lpfc_nodelist *new_ndlp;
James Smart488d1462006-03-07 15:02:37 -0500777 struct serv_parm *sp;
James Smart92d7f7b2007-06-17 19:56:38 -0500778 uint8_t name[sizeof(struct lpfc_name)];
James Smart488d1462006-03-07 15:02:37 -0500779 uint32_t rc;
780
James Smart2fb9bd82006-12-02 13:33:57 -0500781 /* Fabric nodes can have the same WWPN so we don't bother searching
782 * by WWPN. Just return the ndlp that was given to us.
783 */
784 if (ndlp->nlp_type & NLP_FABRIC)
785 return ndlp;
786
James Smart92d7f7b2007-06-17 19:56:38 -0500787 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
James Smart685f0bf2007-04-25 09:53:08 -0400788 memset(name, 0, sizeof(struct lpfc_name));
James Smart488d1462006-03-07 15:02:37 -0500789
James Smart685f0bf2007-04-25 09:53:08 -0400790 /* Now we find out if the NPort we are logging into, matches the WWPN
James Smart488d1462006-03-07 15:02:37 -0500791 * we have for that ndlp. If not, we have some work to do.
792 */
James Smart2e0fef82007-06-17 19:56:36 -0500793 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
James Smart488d1462006-03-07 15:02:37 -0500794
James Smart92795652006-07-06 15:50:02 -0400795 if (new_ndlp == ndlp)
James Smart488d1462006-03-07 15:02:37 -0500796 return ndlp;
James Smart488d1462006-03-07 15:02:37 -0500797
798 if (!new_ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -0500799 rc = memcmp(&ndlp->nlp_portname, name,
800 sizeof(struct lpfc_name));
James Smart92795652006-07-06 15:50:02 -0400801 if (!rc)
802 return ndlp;
James Smart488d1462006-03-07 15:02:37 -0500803 new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
804 if (!new_ndlp)
805 return ndlp;
806
James Smart2e0fef82007-06-17 19:56:36 -0500807 lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID);
James Smart488d1462006-03-07 15:02:37 -0500808 }
809
James Smart2e0fef82007-06-17 19:56:36 -0500810 lpfc_unreg_rpi(vport, new_ndlp);
James Smart488d1462006-03-07 15:02:37 -0500811 new_ndlp->nlp_DID = ndlp->nlp_DID;
James Smart92795652006-07-06 15:50:02 -0400812 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
James Smart2e0fef82007-06-17 19:56:36 -0500813 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
James Smart488d1462006-03-07 15:02:37 -0500814
James Smart2e0fef82007-06-17 19:56:36 -0500815 /* Move this back to NPR state */
James Smartde0c5b32007-04-25 09:52:27 -0400816 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0)
James Smart2e0fef82007-06-17 19:56:36 -0500817 lpfc_drop_node(vport, ndlp);
James Smart92795652006-07-06 15:50:02 -0400818 else {
James Smart2e0fef82007-06-17 19:56:36 -0500819 lpfc_unreg_rpi(vport, ndlp);
James Smart92795652006-07-06 15:50:02 -0400820 ndlp->nlp_DID = 0; /* Two ndlps cannot have the same did */
James Smart2e0fef82007-06-17 19:56:36 -0500821 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smart92795652006-07-06 15:50:02 -0400822 }
James Smart488d1462006-03-07 15:02:37 -0500823 return new_ndlp;
824}
825
dea31012005-04-17 16:05:31 -0500826static void
James Smart2e0fef82007-06-17 19:56:36 -0500827lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
828 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500829{
James Smart2e0fef82007-06-17 19:56:36 -0500830 struct lpfc_vport *vport = cmdiocb->vport;
831 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500832 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -0500833 struct lpfc_nodelist *ndlp;
James Smart92795652006-07-06 15:50:02 -0400834 struct lpfc_dmabuf *prsp;
dea31012005-04-17 16:05:31 -0500835 int disc, rc, did, type;
836
dea31012005-04-17 16:05:31 -0500837 /* we pass cmdiocb to state machine which needs rspiocb as well */
838 cmdiocb->context_un.rsp_iocb = rspiocb;
839
840 irsp = &rspiocb->iocb;
James Smart858c9f62007-06-17 19:56:39 -0500841 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
842 "PLOGI cmpl: status:x%x/x%x did:x%x",
843 irsp->ulpStatus, irsp->un.ulpWord[4],
844 irsp->un.elsreq64.remoteID);
845
James Smart2e0fef82007-06-17 19:56:36 -0500846 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
James Smarted957682007-06-17 19:56:37 -0500847 if (!ndlp) {
James Smarte8b62012007-08-02 11:10:09 -0400848 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
849 "0136 PLOGI completes to NPort x%x "
850 "with no ndlp. Data: x%x x%x x%x\n",
851 irsp->un.elsreq64.remoteID,
852 irsp->ulpStatus, irsp->un.ulpWord[4],
853 irsp->ulpIoTag);
James Smart488d1462006-03-07 15:02:37 -0500854 goto out;
James Smarted957682007-06-17 19:56:37 -0500855 }
dea31012005-04-17 16:05:31 -0500856
857 /* Since ndlp can be freed in the disc state machine, note if this node
858 * is being used during discovery.
859 */
James Smart2e0fef82007-06-17 19:56:36 -0500860 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500861 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
James Smart488d1462006-03-07 15:02:37 -0500862 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500863 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500864 rc = 0;
865
866 /* PLOGI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -0400867 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
868 "0102 PLOGI completes to NPort x%x "
869 "Data: x%x x%x x%x x%x x%x\n",
870 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
871 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -0500872 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500873 if (lpfc_els_chk_latt(vport)) {
874 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500875 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500876 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500877 goto out;
878 }
879
880 /* ndlp could be freed in DSM, save these values now */
881 type = ndlp->nlp_type;
882 did = ndlp->nlp_DID;
883
884 if (irsp->ulpStatus) {
885 /* Check for retry */
886 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
887 /* ELS command is being retried */
888 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -0500889 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500890 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500891 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500892 }
893 goto out;
894 }
dea31012005-04-17 16:05:31 -0500895 /* PLOGI failed */
James Smart92d7f7b2007-06-17 19:56:38 -0500896 if (ndlp->nlp_DID == NameServer_DID) {
897 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -0400898 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
899 "0250 Nameserver login error: "
900 "0x%x / 0x%x\n",
901 irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smart92d7f7b2007-06-17 19:56:38 -0500902 }
dea31012005-04-17 16:05:31 -0500903 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart858c9f62007-06-17 19:56:39 -0500904 if (lpfc_error_lost_link(irsp)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500905 rc = NLP_STE_FREED_NODE;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500906 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500907 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -0500908 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -0500909 }
910 } else {
911 /* Good status, call state machine */
James Smart92795652006-07-06 15:50:02 -0400912 prsp = list_entry(((struct lpfc_dmabuf *)
James Smart92d7f7b2007-06-17 19:56:38 -0500913 cmdiocb->context2)->list.next,
914 struct lpfc_dmabuf, list);
915 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -0500916 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -0500917 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -0500918 }
919
James Smart2e0fef82007-06-17 19:56:36 -0500920 if (disc && vport->num_disc_nodes) {
dea31012005-04-17 16:05:31 -0500921 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -0500922 lpfc_more_plogi(vport);
dea31012005-04-17 16:05:31 -0500923
James Smart2e0fef82007-06-17 19:56:36 -0500924 if (vport->num_disc_nodes == 0) {
925 spin_lock_irq(shost->host_lock);
926 vport->fc_flag &= ~FC_NDISC_ACTIVE;
927 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500928
James Smart2e0fef82007-06-17 19:56:36 -0500929 lpfc_can_disctmo(vport);
930 if (vport->fc_flag & FC_RSCN_MODE) {
James Smart10d4e952006-04-15 11:53:15 -0400931 /*
932 * Check to see if more RSCNs came in while
933 * we were processing this one.
934 */
James Smart2e0fef82007-06-17 19:56:36 -0500935 if ((vport->fc_rscn_id_cnt == 0) &&
936 (!(vport->fc_flag & FC_RSCN_DISCOVERY))) {
937 spin_lock_irq(shost->host_lock);
938 vport->fc_flag &= ~FC_RSCN_MODE;
939 spin_unlock_irq(shost->host_lock);
James Smart10d4e952006-04-15 11:53:15 -0400940 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500941 lpfc_els_handle_rscn(vport);
James Smart10d4e952006-04-15 11:53:15 -0400942 }
dea31012005-04-17 16:05:31 -0500943 }
944 }
945 }
946
947out:
948 lpfc_els_free_iocb(phba, cmdiocb);
949 return;
950}
951
952int
James Smart2e0fef82007-06-17 19:56:36 -0500953lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
dea31012005-04-17 16:05:31 -0500954{
James Smart2e0fef82007-06-17 19:56:36 -0500955 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500956 struct serv_parm *sp;
957 IOCB_t *icmd;
James Smart98c9ea52007-10-27 13:37:33 -0400958 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -0500959 struct lpfc_iocbq *elsiocb;
960 struct lpfc_sli_ring *pring;
961 struct lpfc_sli *psli;
962 uint8_t *pcmd;
963 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -0500964 int ret;
dea31012005-04-17 16:05:31 -0500965
966 psli = &phba->sli;
967 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
968
James Smart98c9ea52007-10-27 13:37:33 -0400969 ndlp = lpfc_findnode_did(vport, did);
970 /* If ndlp if not NULL, we will bump the reference count on it */
971
James Smart92d7f7b2007-06-17 19:56:38 -0500972 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart98c9ea52007-10-27 13:37:33 -0400973 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
James Smart2e0fef82007-06-17 19:56:36 -0500974 ELS_CMD_PLOGI);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500975 if (!elsiocb)
976 return 1;
dea31012005-04-17 16:05:31 -0500977
978 icmd = &elsiocb->iocb;
979 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
980
981 /* For PLOGI request, remainder of payload is service parameters */
982 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -0500983 pcmd += sizeof(uint32_t);
984 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -0500985 sp = (struct serv_parm *) pcmd;
986
987 if (sp->cmn.fcphLow < FC_PH_4_3)
988 sp->cmn.fcphLow = FC_PH_4_3;
989
990 if (sp->cmn.fcphHigh < FC_PH3)
991 sp->cmn.fcphHigh = FC_PH3;
992
James Smart858c9f62007-06-17 19:56:39 -0500993 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
994 "Issue PLOGI: did:x%x",
995 did, 0, 0);
996
dea31012005-04-17 16:05:31 -0500997 phba->fc_stat.elsXmitPLOGI++;
998 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
James Smart92d7f7b2007-06-17 19:56:38 -0500999 ret = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
1000
1001 if (ret == IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05001002 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001003 return 1;
dea31012005-04-17 16:05:31 -05001004 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001005 return 0;
dea31012005-04-17 16:05:31 -05001006}
1007
1008static void
James Smart2e0fef82007-06-17 19:56:36 -05001009lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1010 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001011{
James Smart2e0fef82007-06-17 19:56:36 -05001012 struct lpfc_vport *vport = cmdiocb->vport;
1013 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001014 IOCB_t *irsp;
1015 struct lpfc_sli *psli;
1016 struct lpfc_nodelist *ndlp;
1017
1018 psli = &phba->sli;
1019 /* we pass cmdiocb to state machine which needs rspiocb as well */
1020 cmdiocb->context_un.rsp_iocb = rspiocb;
1021
1022 irsp = &(rspiocb->iocb);
1023 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
James Smart2e0fef82007-06-17 19:56:36 -05001024 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001025 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001026 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001027
James Smart858c9f62007-06-17 19:56:39 -05001028 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1029 "PRLI cmpl: status:x%x/x%x did:x%x",
1030 irsp->ulpStatus, irsp->un.ulpWord[4],
1031 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05001032 /* PRLI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001033 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1034 "0103 PRLI completes to NPort x%x "
1035 "Data: x%x x%x x%x x%x\n",
1036 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1037 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001038
James Smart2e0fef82007-06-17 19:56:36 -05001039 vport->fc_prli_sent--;
dea31012005-04-17 16:05:31 -05001040 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001041 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05001042 goto out;
1043
1044 if (irsp->ulpStatus) {
1045 /* Check for retry */
1046 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1047 /* ELS command is being retried */
1048 goto out;
1049 }
1050 /* PRLI failed */
1051 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart858c9f62007-06-17 19:56:39 -05001052 if (lpfc_error_lost_link(irsp)) {
dea31012005-04-17 16:05:31 -05001053 goto out;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001054 } else {
James Smart2e0fef82007-06-17 19:56:36 -05001055 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001056 NLP_EVT_CMPL_PRLI);
dea31012005-04-17 16:05:31 -05001057 }
1058 } else {
1059 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05001060 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001061 NLP_EVT_CMPL_PRLI);
dea31012005-04-17 16:05:31 -05001062 }
1063
1064out:
1065 lpfc_els_free_iocb(phba, cmdiocb);
1066 return;
1067}
1068
1069int
James Smart2e0fef82007-06-17 19:56:36 -05001070lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001071 uint8_t retry)
1072{
James Smart2e0fef82007-06-17 19:56:36 -05001073 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1074 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001075 PRLI *npr;
1076 IOCB_t *icmd;
1077 struct lpfc_iocbq *elsiocb;
1078 struct lpfc_sli_ring *pring;
1079 struct lpfc_sli *psli;
1080 uint8_t *pcmd;
1081 uint16_t cmdsize;
1082
1083 psli = &phba->sli;
1084 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1085
James Smart92d7f7b2007-06-17 19:56:38 -05001086 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
James Smart2e0fef82007-06-17 19:56:36 -05001087 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1088 ndlp->nlp_DID, ELS_CMD_PRLI);
James Smart488d1462006-03-07 15:02:37 -05001089 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001090 return 1;
dea31012005-04-17 16:05:31 -05001091
1092 icmd = &elsiocb->iocb;
1093 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1094
1095 /* For PRLI request, remainder of payload is service parameters */
James Smart92d7f7b2007-06-17 19:56:38 -05001096 memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t)));
dea31012005-04-17 16:05:31 -05001097 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
James Smart92d7f7b2007-06-17 19:56:38 -05001098 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001099
1100 /* For PRLI, remainder of payload is PRLI parameter page */
1101 npr = (PRLI *) pcmd;
1102 /*
1103 * If our firmware version is 3.20 or later,
1104 * set the following bits for FC-TAPE support.
1105 */
1106 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
1107 npr->ConfmComplAllowed = 1;
1108 npr->Retry = 1;
1109 npr->TaskRetryIdReq = 1;
1110 }
1111 npr->estabImagePair = 1;
1112 npr->readXferRdyDis = 1;
1113
1114 /* For FCP support */
1115 npr->prliType = PRLI_FCP_TYPE;
1116 npr->initiatorFunc = 1;
1117
James Smart858c9f62007-06-17 19:56:39 -05001118 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1119 "Issue PRLI: did:x%x",
1120 ndlp->nlp_DID, 0, 0);
1121
dea31012005-04-17 16:05:31 -05001122 phba->fc_stat.elsXmitPRLI++;
1123 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
James Smart2e0fef82007-06-17 19:56:36 -05001124 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001125 ndlp->nlp_flag |= NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001126 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001127 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05001128 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001129 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001130 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001131 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001132 return 1;
dea31012005-04-17 16:05:31 -05001133 }
James Smart2e0fef82007-06-17 19:56:36 -05001134 vport->fc_prli_sent++;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001135 return 0;
dea31012005-04-17 16:05:31 -05001136}
1137
1138static void
James Smart2e0fef82007-06-17 19:56:36 -05001139lpfc_more_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001140{
1141 int sentadisc;
1142
James Smart2e0fef82007-06-17 19:56:36 -05001143 if (vport->num_disc_nodes)
1144 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001145 /* Continue discovery with <num_disc_nodes> ADISCs to go */
James Smarte8b62012007-08-02 11:10:09 -04001146 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1147 "0210 Continue discovery with %d ADISCs to go "
1148 "Data: x%x x%x x%x\n",
1149 vport->num_disc_nodes, vport->fc_adisc_cnt,
1150 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001151 /* Check to see if there are more ADISCs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001152 if (vport->fc_flag & FC_NLP_MORE) {
1153 lpfc_set_disctmo(vport);
1154 /* go thru NPR nodes and issue any remaining ELS ADISCs */
1155 sentadisc = lpfc_els_disc_adisc(vport);
dea31012005-04-17 16:05:31 -05001156 }
1157 return;
1158}
1159
1160static void
James Smart2e0fef82007-06-17 19:56:36 -05001161lpfc_rscn_disc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001162{
James Smart2e0fef82007-06-17 19:56:36 -05001163 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1164
James Smart858c9f62007-06-17 19:56:39 -05001165 lpfc_can_disctmo(vport);
1166
dea31012005-04-17 16:05:31 -05001167 /* RSCN discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001168 /* go thru NPR nodes and issue ELS PLOGIs */
1169 if (vport->fc_npr_cnt)
1170 if (lpfc_els_disc_plogi(vport))
dea31012005-04-17 16:05:31 -05001171 return;
James Smart2e0fef82007-06-17 19:56:36 -05001172
1173 if (vport->fc_flag & FC_RSCN_MODE) {
dea31012005-04-17 16:05:31 -05001174 /* Check to see if more RSCNs came in while we were
1175 * processing this one.
1176 */
James Smart2e0fef82007-06-17 19:56:36 -05001177 if ((vport->fc_rscn_id_cnt == 0) &&
1178 (!(vport->fc_flag & FC_RSCN_DISCOVERY))) {
1179 spin_lock_irq(shost->host_lock);
1180 vport->fc_flag &= ~FC_RSCN_MODE;
1181 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001182 } else {
James Smart2e0fef82007-06-17 19:56:36 -05001183 lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05001184 }
1185 }
1186}
1187
1188static void
James Smart2e0fef82007-06-17 19:56:36 -05001189lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1190 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001191{
James Smart2e0fef82007-06-17 19:56:36 -05001192 struct lpfc_vport *vport = cmdiocb->vport;
1193 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001194 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001195 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001196 int disc;
dea31012005-04-17 16:05:31 -05001197
1198 /* we pass cmdiocb to state machine which needs rspiocb as well */
1199 cmdiocb->context_un.rsp_iocb = rspiocb;
1200
1201 irsp = &(rspiocb->iocb);
1202 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
dea31012005-04-17 16:05:31 -05001203
James Smart858c9f62007-06-17 19:56:39 -05001204 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1205 "ADISC cmpl: status:x%x/x%x did:x%x",
1206 irsp->ulpStatus, irsp->un.ulpWord[4],
1207 ndlp->nlp_DID);
1208
dea31012005-04-17 16:05:31 -05001209 /* Since ndlp can be freed in the disc state machine, note if this node
1210 * is being used during discovery.
1211 */
James Smart2e0fef82007-06-17 19:56:36 -05001212 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001213 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001214 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001215 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001216 /* ADISC completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001217 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1218 "0104 ADISC completes to NPort x%x "
1219 "Data: x%x x%x x%x x%x x%x\n",
1220 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1221 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001222 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001223 if (lpfc_els_chk_latt(vport)) {
1224 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001225 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001226 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001227 goto out;
1228 }
1229
1230 if (irsp->ulpStatus) {
1231 /* Check for retry */
1232 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1233 /* ELS command is being retried */
1234 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05001235 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001236 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001237 spin_unlock_irq(shost->host_lock);
1238 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001239 }
1240 goto out;
1241 }
1242 /* ADISC failed */
1243 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart858c9f62007-06-17 19:56:39 -05001244 if (!lpfc_error_lost_link(irsp)) {
James Smart2e0fef82007-06-17 19:56:36 -05001245 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart858c9f62007-06-17 19:56:39 -05001246 NLP_EVT_CMPL_ADISC);
dea31012005-04-17 16:05:31 -05001247 }
1248 } else {
1249 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05001250 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
dea31012005-04-17 16:05:31 -05001251 NLP_EVT_CMPL_ADISC);
1252 }
1253
James Smart2e0fef82007-06-17 19:56:36 -05001254 if (disc && vport->num_disc_nodes) {
dea31012005-04-17 16:05:31 -05001255 /* Check to see if there are more ADISCs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001256 lpfc_more_adisc(vport);
dea31012005-04-17 16:05:31 -05001257
1258 /* Check to see if we are done with ADISC authentication */
James Smart2e0fef82007-06-17 19:56:36 -05001259 if (vport->num_disc_nodes == 0) {
James Smart92d7f7b2007-06-17 19:56:38 -05001260 /* If we get here, there is nothing left to ADISC */
1261 /*
1262 * For NPIV, cmpl_reg_vpi will set port_state to READY,
1263 * and continue discovery.
1264 */
1265 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
1266 !(vport->fc_flag & FC_RSCN_MODE)) {
1267 lpfc_issue_reg_vpi(phba, vport);
1268 goto out;
1269 }
1270 /*
1271 * For SLI2, we need to set port_state to READY
1272 * and continue discovery.
1273 */
1274 if (vport->port_state < LPFC_VPORT_READY) {
1275 /* If we get here, there is nothing to ADISC */
James Smarted957682007-06-17 19:56:37 -05001276 if (vport->port_type == LPFC_PHYSICAL_PORT)
James Smart2e0fef82007-06-17 19:56:36 -05001277 lpfc_issue_clear_la(phba, vport);
James Smart92d7f7b2007-06-17 19:56:38 -05001278
1279 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
1280 vport->num_disc_nodes = 0;
1281 /* go thru NPR list, issue ELS PLOGIs */
1282 if (vport->fc_npr_cnt)
1283 lpfc_els_disc_plogi(vport);
1284
1285 if (!vport->num_disc_nodes) {
1286 spin_lock_irq(shost->host_lock);
1287 vport->fc_flag &=
1288 ~FC_NDISC_ACTIVE;
1289 spin_unlock_irq(
1290 shost->host_lock);
1291 lpfc_can_disctmo(vport);
1292 }
1293 }
1294 vport->port_state = LPFC_VPORT_READY;
dea31012005-04-17 16:05:31 -05001295 } else {
James Smart2e0fef82007-06-17 19:56:36 -05001296 lpfc_rscn_disc(vport);
dea31012005-04-17 16:05:31 -05001297 }
1298 }
1299 }
dea31012005-04-17 16:05:31 -05001300out:
1301 lpfc_els_free_iocb(phba, cmdiocb);
1302 return;
1303}
1304
1305int
James Smart2e0fef82007-06-17 19:56:36 -05001306lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001307 uint8_t retry)
1308{
James Smart2e0fef82007-06-17 19:56:36 -05001309 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1310 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001311 ADISC *ap;
1312 IOCB_t *icmd;
1313 struct lpfc_iocbq *elsiocb;
James Smart2e0fef82007-06-17 19:56:36 -05001314 struct lpfc_sli *psli = &phba->sli;
1315 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05001316 uint8_t *pcmd;
1317 uint16_t cmdsize;
1318
James Smart92d7f7b2007-06-17 19:56:38 -05001319 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
James Smart2e0fef82007-06-17 19:56:36 -05001320 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1321 ndlp->nlp_DID, ELS_CMD_ADISC);
James Smart488d1462006-03-07 15:02:37 -05001322 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001323 return 1;
dea31012005-04-17 16:05:31 -05001324
1325 icmd = &elsiocb->iocb;
1326 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1327
1328 /* For ADISC request, remainder of payload is service parameters */
1329 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
James Smart92d7f7b2007-06-17 19:56:38 -05001330 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001331
1332 /* Fill in ADISC payload */
1333 ap = (ADISC *) pcmd;
1334 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05001335 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
1336 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05001337 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05001338
James Smart858c9f62007-06-17 19:56:39 -05001339 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1340 "Issue ADISC: did:x%x",
1341 ndlp->nlp_DID, 0, 0);
1342
dea31012005-04-17 16:05:31 -05001343 phba->fc_stat.elsXmitADISC++;
1344 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
James Smart2e0fef82007-06-17 19:56:36 -05001345 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001346 ndlp->nlp_flag |= NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001347 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001348 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05001349 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001350 ndlp->nlp_flag &= ~NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001351 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001352 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001353 return 1;
dea31012005-04-17 16:05:31 -05001354 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001355 return 0;
dea31012005-04-17 16:05:31 -05001356}
1357
1358static void
James Smart2e0fef82007-06-17 19:56:36 -05001359lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1360 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001361{
James Smart2e0fef82007-06-17 19:56:36 -05001362 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1363 struct lpfc_vport *vport = ndlp->vport;
1364 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001365 IOCB_t *irsp;
1366 struct lpfc_sli *psli;
dea31012005-04-17 16:05:31 -05001367
1368 psli = &phba->sli;
1369 /* we pass cmdiocb to state machine which needs rspiocb as well */
1370 cmdiocb->context_un.rsp_iocb = rspiocb;
1371
1372 irsp = &(rspiocb->iocb);
James Smart2e0fef82007-06-17 19:56:36 -05001373 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001374 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001375 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001376
James Smart858c9f62007-06-17 19:56:39 -05001377 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1378 "LOGO cmpl: status:x%x/x%x did:x%x",
1379 irsp->ulpStatus, irsp->un.ulpWord[4],
1380 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05001381 /* LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001382 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1383 "0105 LOGO completes to NPort x%x "
1384 "Data: x%x x%x x%x x%x\n",
1385 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1386 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001387 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001388 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05001389 goto out;
1390
James Smart92d7f7b2007-06-17 19:56:38 -05001391 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
1392 /* NLP_EVT_DEVICE_RM should unregister the RPI
1393 * which should abort all outstanding IOs.
1394 */
1395 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1396 NLP_EVT_DEVICE_RM);
1397 goto out;
1398 }
1399
dea31012005-04-17 16:05:31 -05001400 if (irsp->ulpStatus) {
1401 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -05001402 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -05001403 /* ELS command is being retried */
1404 goto out;
dea31012005-04-17 16:05:31 -05001405 /* LOGO failed */
1406 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart858c9f62007-06-17 19:56:39 -05001407 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05001408 goto out;
James Smart858c9f62007-06-17 19:56:39 -05001409 else
James Smart2e0fef82007-06-17 19:56:36 -05001410 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001411 NLP_EVT_CMPL_LOGO);
dea31012005-04-17 16:05:31 -05001412 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001413 /* Good status, call state machine.
1414 * This will unregister the rpi if needed.
1415 */
James Smart2e0fef82007-06-17 19:56:36 -05001416 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001417 NLP_EVT_CMPL_LOGO);
dea31012005-04-17 16:05:31 -05001418 }
1419
1420out:
1421 lpfc_els_free_iocb(phba, cmdiocb);
1422 return;
1423}
1424
1425int
James Smart2e0fef82007-06-17 19:56:36 -05001426lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001427 uint8_t retry)
1428{
James Smart2e0fef82007-06-17 19:56:36 -05001429 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1430 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001431 IOCB_t *icmd;
1432 struct lpfc_iocbq *elsiocb;
1433 struct lpfc_sli_ring *pring;
1434 struct lpfc_sli *psli;
1435 uint8_t *pcmd;
1436 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05001437 int rc;
dea31012005-04-17 16:05:31 -05001438
1439 psli = &phba->sli;
1440 pring = &psli->ring[LPFC_ELS_RING];
1441
James Smart98c9ea52007-10-27 13:37:33 -04001442 spin_lock_irq(shost->host_lock);
1443 if (ndlp->nlp_flag & NLP_LOGO_SND) {
1444 spin_unlock_irq(shost->host_lock);
1445 return 0;
1446 }
1447 spin_unlock_irq(shost->host_lock);
1448
James Smart92d7f7b2007-06-17 19:56:38 -05001449 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
James Smart2e0fef82007-06-17 19:56:36 -05001450 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1451 ndlp->nlp_DID, ELS_CMD_LOGO);
James Smart488d1462006-03-07 15:02:37 -05001452 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001453 return 1;
dea31012005-04-17 16:05:31 -05001454
1455 icmd = &elsiocb->iocb;
1456 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1457 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
James Smart92d7f7b2007-06-17 19:56:38 -05001458 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001459
1460 /* Fill in LOGO payload */
James Smart2e0fef82007-06-17 19:56:36 -05001461 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05001462 pcmd += sizeof(uint32_t);
1463 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05001464
James Smart858c9f62007-06-17 19:56:39 -05001465 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1466 "Issue LOGO: did:x%x",
1467 ndlp->nlp_DID, 0, 0);
1468
dea31012005-04-17 16:05:31 -05001469 phba->fc_stat.elsXmitLOGO++;
1470 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
James Smart2e0fef82007-06-17 19:56:36 -05001471 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001472 ndlp->nlp_flag |= NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001473 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05001474 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
1475
1476 if (rc == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05001477 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001478 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001479 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001480 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001481 return 1;
dea31012005-04-17 16:05:31 -05001482 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001483 return 0;
dea31012005-04-17 16:05:31 -05001484}
1485
1486static void
James Smart2e0fef82007-06-17 19:56:36 -05001487lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1488 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001489{
James Smart2e0fef82007-06-17 19:56:36 -05001490 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -05001491 IOCB_t *irsp;
1492
1493 irsp = &rspiocb->iocb;
1494
James Smart858c9f62007-06-17 19:56:39 -05001495 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1496 "ELS cmd cmpl: status:x%x/x%x did:x%x",
1497 irsp->ulpStatus, irsp->un.ulpWord[4],
1498 irsp->un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05001499 /* ELS cmd tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04001500 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1501 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
1502 irsp->ulpIoTag, irsp->ulpStatus,
1503 irsp->un.ulpWord[4], irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -05001504 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001505 lpfc_els_chk_latt(vport);
dea31012005-04-17 16:05:31 -05001506 lpfc_els_free_iocb(phba, cmdiocb);
1507 return;
1508}
1509
1510int
James Smart2e0fef82007-06-17 19:56:36 -05001511lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05001512{
James Smart2e0fef82007-06-17 19:56:36 -05001513 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001514 IOCB_t *icmd;
1515 struct lpfc_iocbq *elsiocb;
1516 struct lpfc_sli_ring *pring;
1517 struct lpfc_sli *psli;
1518 uint8_t *pcmd;
1519 uint16_t cmdsize;
1520 struct lpfc_nodelist *ndlp;
1521
1522 psli = &phba->sli;
1523 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
James Smart92d7f7b2007-06-17 19:56:38 -05001524 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001525 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1526 if (!ndlp)
1527 return 1;
dea31012005-04-17 16:05:31 -05001528
James Smart2e0fef82007-06-17 19:56:36 -05001529 lpfc_nlp_init(vport, ndlp, nportid);
dea31012005-04-17 16:05:31 -05001530
James Smart2e0fef82007-06-17 19:56:36 -05001531 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1532 ndlp->nlp_DID, ELS_CMD_SCR);
1533
James Smart488d1462006-03-07 15:02:37 -05001534 if (!elsiocb) {
James Smart329f9bc2007-04-25 09:53:01 -04001535 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001536 return 1;
dea31012005-04-17 16:05:31 -05001537 }
1538
1539 icmd = &elsiocb->iocb;
1540 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1541
1542 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
James Smart92d7f7b2007-06-17 19:56:38 -05001543 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001544
1545 /* For SCR, remainder of payload is SCR parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05001546 memset(pcmd, 0, sizeof(SCR));
dea31012005-04-17 16:05:31 -05001547 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
1548
James Smart858c9f62007-06-17 19:56:39 -05001549 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1550 "Issue SCR: did:x%x",
1551 ndlp->nlp_DID, 0, 0);
1552
dea31012005-04-17 16:05:31 -05001553 phba->fc_stat.elsXmitSCR++;
1554 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
dea31012005-04-17 16:05:31 -05001555 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
James Smart329f9bc2007-04-25 09:53:01 -04001556 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001557 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001558 return 1;
dea31012005-04-17 16:05:31 -05001559 }
James Smart329f9bc2007-04-25 09:53:01 -04001560 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001561 return 0;
dea31012005-04-17 16:05:31 -05001562}
1563
1564static int
James Smart2e0fef82007-06-17 19:56:36 -05001565lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05001566{
James Smart2e0fef82007-06-17 19:56:36 -05001567 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001568 IOCB_t *icmd;
1569 struct lpfc_iocbq *elsiocb;
1570 struct lpfc_sli_ring *pring;
1571 struct lpfc_sli *psli;
1572 FARP *fp;
1573 uint8_t *pcmd;
1574 uint32_t *lp;
1575 uint16_t cmdsize;
1576 struct lpfc_nodelist *ondlp;
1577 struct lpfc_nodelist *ndlp;
1578
1579 psli = &phba->sli;
1580 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
James Smart92d7f7b2007-06-17 19:56:38 -05001581 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001582 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1583 if (!ndlp)
1584 return 1;
dea31012005-04-17 16:05:31 -05001585
James Smart2e0fef82007-06-17 19:56:36 -05001586 lpfc_nlp_init(vport, ndlp, nportid);
1587
1588 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1589 ndlp->nlp_DID, ELS_CMD_RNID);
James Smart488d1462006-03-07 15:02:37 -05001590 if (!elsiocb) {
James Smart329f9bc2007-04-25 09:53:01 -04001591 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001592 return 1;
dea31012005-04-17 16:05:31 -05001593 }
1594
1595 icmd = &elsiocb->iocb;
1596 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1597
1598 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
James Smart92d7f7b2007-06-17 19:56:38 -05001599 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001600
1601 /* Fill in FARPR payload */
1602 fp = (FARP *) (pcmd);
James Smart92d7f7b2007-06-17 19:56:38 -05001603 memset(fp, 0, sizeof(FARP));
dea31012005-04-17 16:05:31 -05001604 lp = (uint32_t *) pcmd;
1605 *lp++ = be32_to_cpu(nportid);
James Smart2e0fef82007-06-17 19:56:36 -05001606 *lp++ = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05001607 fp->Rflags = 0;
1608 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
1609
James Smart92d7f7b2007-06-17 19:56:38 -05001610 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
1611 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05001612 ondlp = lpfc_findnode_did(vport, nportid);
1613 if (ondlp) {
dea31012005-04-17 16:05:31 -05001614 memcpy(&fp->OportName, &ondlp->nlp_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05001615 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05001616 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05001617 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05001618 }
1619
James Smart858c9f62007-06-17 19:56:39 -05001620 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1621 "Issue FARPR: did:x%x",
1622 ndlp->nlp_DID, 0, 0);
1623
dea31012005-04-17 16:05:31 -05001624 phba->fc_stat.elsXmitFARPR++;
1625 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
dea31012005-04-17 16:05:31 -05001626 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
James Smart329f9bc2007-04-25 09:53:01 -04001627 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001628 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001629 return 1;
dea31012005-04-17 16:05:31 -05001630 }
James Smart329f9bc2007-04-25 09:53:01 -04001631 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001632 return 0;
dea31012005-04-17 16:05:31 -05001633}
1634
James Smarted957682007-06-17 19:56:37 -05001635static void
1636lpfc_end_rscn(struct lpfc_vport *vport)
1637{
1638 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1639
1640 if (vport->fc_flag & FC_RSCN_MODE) {
1641 /*
1642 * Check to see if more RSCNs came in while we were
1643 * processing this one.
1644 */
1645 if (vport->fc_rscn_id_cnt ||
1646 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1647 lpfc_els_handle_rscn(vport);
1648 else {
1649 spin_lock_irq(shost->host_lock);
1650 vport->fc_flag &= ~FC_RSCN_MODE;
1651 spin_unlock_irq(shost->host_lock);
1652 }
1653 }
1654}
1655
dea31012005-04-17 16:05:31 -05001656void
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 Smart329f9bc2007-04-25 09:53:01 -04002072lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05002073{
2074 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
2075
James Smart329f9bc2007-04-25 09:53:01 -04002076 if (elsiocb->context1) {
2077 lpfc_nlp_put(elsiocb->context1);
2078 elsiocb->context1 = NULL;
2079 }
dea31012005-04-17 16:05:31 -05002080 /* context2 = cmd, context2->next = rsp, context3 = bpl */
2081 if (elsiocb->context2) {
2082 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
2083 /* Free the response before processing the command. */
2084 if (!list_empty(&buf_ptr1->list)) {
2085 list_remove_head(&buf_ptr1->list, buf_ptr,
2086 struct lpfc_dmabuf,
2087 list);
2088 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
2089 kfree(buf_ptr);
2090 }
2091 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
2092 kfree(buf_ptr1);
2093 }
2094
2095 if (elsiocb->context3) {
2096 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
2097 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
2098 kfree(buf_ptr);
2099 }
James Bottomley604a3e32005-10-29 10:28:33 -05002100 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -05002101 return 0;
2102}
2103
2104static void
James Smart2e0fef82007-06-17 19:56:36 -05002105lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2106 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002107{
James Smart2e0fef82007-06-17 19:56:36 -05002108 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2109 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05002110 IOCB_t *irsp;
2111
2112 irsp = &rspiocb->iocb;
2113 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2114 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
2115 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05002116 /* ACC to LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002117 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2118 "0109 ACC to LOGO completes to NPort x%x "
2119 "Data: x%x x%x x%x\n",
2120 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2121 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05002122 switch (ndlp->nlp_state) {
2123 case NLP_STE_UNUSED_NODE: /* node is just allocated */
James Smart2e0fef82007-06-17 19:56:36 -05002124 lpfc_drop_node(vport, ndlp);
dea31012005-04-17 16:05:31 -05002125 break;
2126 case NLP_STE_NPR_NODE: /* NPort Recovery mode */
James Smart2e0fef82007-06-17 19:56:36 -05002127 lpfc_unreg_rpi(vport, ndlp);
dea31012005-04-17 16:05:31 -05002128 break;
2129 default:
2130 break;
2131 }
2132 lpfc_els_free_iocb(phba, cmdiocb);
2133 return;
2134}
2135
James Smart858c9f62007-06-17 19:56:39 -05002136void
2137lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
2138{
2139 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
2140 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
2141
2142 pmb->context1 = NULL;
2143 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2144 kfree(mp);
2145 mempool_free(pmb, phba->mbox_mem_pool);
2146 lpfc_nlp_put(ndlp);
James Smart98c9ea52007-10-27 13:37:33 -04002147
2148 /* This is the end of the default RPI cleanup logic for this
2149 * ndlp. If no other discovery threads are using this ndlp.
2150 * we should free all resources associated with it.
2151 */
2152 lpfc_nlp_not_used(ndlp);
James Smart858c9f62007-06-17 19:56:39 -05002153 return;
2154}
2155
dea31012005-04-17 16:05:31 -05002156static void
James Smart858c9f62007-06-17 19:56:39 -05002157lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
James Smart329f9bc2007-04-25 09:53:01 -04002158 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002159{
James Smart2e0fef82007-06-17 19:56:36 -05002160 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2161 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
2162 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
James Smart33ccf8d2006-08-17 11:57:58 -04002163 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05002164 LPFC_MBOXQ_t *mbox = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05002165 struct lpfc_dmabuf *mp = NULL;
dea31012005-04-17 16:05:31 -05002166
James Smart33ccf8d2006-08-17 11:57:58 -04002167 irsp = &rspiocb->iocb;
2168
dea31012005-04-17 16:05:31 -05002169 if (cmdiocb->context_un.mbox)
2170 mbox = cmdiocb->context_un.mbox;
2171
dea31012005-04-17 16:05:31 -05002172 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002173 if (!ndlp || lpfc_els_chk_latt(vport)) {
dea31012005-04-17 16:05:31 -05002174 if (mbox) {
James Smart14691152006-12-02 13:34:28 -05002175 mp = (struct lpfc_dmabuf *) mbox->context1;
2176 if (mp) {
2177 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2178 kfree(mp);
2179 }
James Smart329f9bc2007-04-25 09:53:01 -04002180 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05002181 }
James Smart98c9ea52007-10-27 13:37:33 -04002182 if (ndlp && (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
2183 if (lpfc_nlp_not_used(ndlp))
2184 ndlp = NULL;
dea31012005-04-17 16:05:31 -05002185 goto out;
2186 }
2187
James Smart858c9f62007-06-17 19:56:39 -05002188 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smart51ef4c22007-08-02 11:10:31 -04002189 "ELS rsp cmpl: status:x%x/x%x did:x%x",
James Smart858c9f62007-06-17 19:56:39 -05002190 irsp->ulpStatus, irsp->un.ulpWord[4],
James Smart51ef4c22007-08-02 11:10:31 -04002191 cmdiocb->iocb.un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05002192 /* ELS response tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04002193 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2194 "0110 ELS response tag x%x completes "
2195 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
2196 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
2197 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
2198 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2199 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05002200 if (mbox) {
2201 if ((rspiocb->iocb.ulpStatus == 0)
2202 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
James Smart2e0fef82007-06-17 19:56:36 -05002203 lpfc_unreg_rpi(vport, ndlp);
James Smart329f9bc2007-04-25 09:53:01 -04002204 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05002205 mbox->vport = vport;
James Smart858c9f62007-06-17 19:56:39 -05002206 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
2207 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
2208 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
2209 }
2210 else {
2211 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
2212 ndlp->nlp_prev_state = ndlp->nlp_state;
2213 lpfc_nlp_set_state(vport, ndlp,
James Smart2e0fef82007-06-17 19:56:36 -05002214 NLP_STE_REG_LOGIN_ISSUE);
James Smart858c9f62007-06-17 19:56:39 -05002215 }
James Smart0b727fe2007-10-27 13:37:25 -04002216 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
dea31012005-04-17 16:05:31 -05002217 != MBX_NOT_FINISHED) {
2218 goto out;
2219 }
James Smart98c9ea52007-10-27 13:37:33 -04002220
2221 /* ELS rsp: Cannot issue reg_login for <NPortid> */
2222 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2223 "0138 ELS rsp: Cannot issue reg_login for x%x "
2224 "Data: x%x x%x x%x\n",
2225 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2226 ndlp->nlp_rpi);
2227
2228 if (lpfc_nlp_not_used(ndlp))
2229 ndlp = NULL;
dea31012005-04-17 16:05:31 -05002230 } else {
James Smart858c9f62007-06-17 19:56:39 -05002231 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
2232 if (!lpfc_error_lost_link(irsp) &&
2233 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
James Smart98c9ea52007-10-27 13:37:33 -04002234 if (lpfc_nlp_not_used(ndlp))
2235 ndlp = NULL;
dea31012005-04-17 16:05:31 -05002236 }
2237 }
James Smart14691152006-12-02 13:34:28 -05002238 mp = (struct lpfc_dmabuf *) mbox->context1;
2239 if (mp) {
2240 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2241 kfree(mp);
2242 }
2243 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05002244 }
2245out:
2246 if (ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05002247 spin_lock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05002248 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
James Smart2e0fef82007-06-17 19:56:36 -05002249 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002250 }
2251 lpfc_els_free_iocb(phba, cmdiocb);
2252 return;
2253}
2254
2255int
James Smart2e0fef82007-06-17 19:56:36 -05002256lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
2257 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
James Smart51ef4c22007-08-02 11:10:31 -04002258 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05002259{
James Smart2e0fef82007-06-17 19:56:36 -05002260 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2261 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002262 IOCB_t *icmd;
2263 IOCB_t *oldcmd;
2264 struct lpfc_iocbq *elsiocb;
2265 struct lpfc_sli_ring *pring;
2266 struct lpfc_sli *psli;
2267 uint8_t *pcmd;
2268 uint16_t cmdsize;
2269 int rc;
James Smart82d9a2a2006-04-15 11:53:05 -04002270 ELS_PKT *els_pkt_ptr;
dea31012005-04-17 16:05:31 -05002271
2272 psli = &phba->sli;
2273 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2274 oldcmd = &oldiocb->iocb;
2275
2276 switch (flag) {
2277 case ELS_CMD_ACC:
James Smart92d7f7b2007-06-17 19:56:38 -05002278 cmdsize = sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05002279 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
2280 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05002281 if (!elsiocb) {
James Smart2e0fef82007-06-17 19:56:36 -05002282 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002283 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05002284 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002285 return 1;
dea31012005-04-17 16:05:31 -05002286 }
James Smart2e0fef82007-06-17 19:56:36 -05002287
dea31012005-04-17 16:05:31 -05002288 icmd = &elsiocb->iocb;
2289 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2290 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2291 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05002292 pcmd += sizeof(uint32_t);
James Smart858c9f62007-06-17 19:56:39 -05002293
2294 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2295 "Issue ACC: did:x%x flg:x%x",
2296 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05002297 break;
2298 case ELS_CMD_PLOGI:
James Smart92d7f7b2007-06-17 19:56:38 -05002299 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
James Smart2e0fef82007-06-17 19:56:36 -05002300 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
2301 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05002302 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002303 return 1;
James Smart488d1462006-03-07 15:02:37 -05002304
dea31012005-04-17 16:05:31 -05002305 icmd = &elsiocb->iocb;
2306 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2307 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2308
2309 if (mbox)
2310 elsiocb->context_un.mbox = mbox;
2311
2312 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05002313 pcmd += sizeof(uint32_t);
2314 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
James Smart858c9f62007-06-17 19:56:39 -05002315
2316 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2317 "Issue ACC PLOGI: did:x%x flg:x%x",
2318 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05002319 break;
James Smart82d9a2a2006-04-15 11:53:05 -04002320 case ELS_CMD_PRLO:
James Smart92d7f7b2007-06-17 19:56:38 -05002321 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
James Smart2e0fef82007-06-17 19:56:36 -05002322 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
James Smart82d9a2a2006-04-15 11:53:05 -04002323 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
2324 if (!elsiocb)
2325 return 1;
2326
2327 icmd = &elsiocb->iocb;
2328 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2329 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2330
2331 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
James Smart92d7f7b2007-06-17 19:56:38 -05002332 sizeof(uint32_t) + sizeof(PRLO));
James Smart82d9a2a2006-04-15 11:53:05 -04002333 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
2334 els_pkt_ptr = (ELS_PKT *) pcmd;
2335 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
James Smart858c9f62007-06-17 19:56:39 -05002336
2337 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2338 "Issue ACC PRLO: did:x%x flg:x%x",
2339 ndlp->nlp_DID, ndlp->nlp_flag, 0);
James Smart82d9a2a2006-04-15 11:53:05 -04002340 break;
dea31012005-04-17 16:05:31 -05002341 default:
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002342 return 1;
dea31012005-04-17 16:05:31 -05002343 }
dea31012005-04-17 16:05:31 -05002344 /* Xmit ELS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04002345 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2346 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
2347 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n",
2348 elsiocb->iotag, elsiocb->iocb.ulpContext,
2349 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2350 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05002351 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
James Smart2e0fef82007-06-17 19:56:36 -05002352 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002353 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05002354 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002355 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
2356 } else {
James Smart858c9f62007-06-17 19:56:39 -05002357 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05002358 }
2359
2360 phba->fc_stat.elsXmitACC++;
dea31012005-04-17 16:05:31 -05002361 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
dea31012005-04-17 16:05:31 -05002362 if (rc == IOCB_ERROR) {
2363 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002364 return 1;
dea31012005-04-17 16:05:31 -05002365 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002366 return 0;
dea31012005-04-17 16:05:31 -05002367}
2368
2369int
James Smart2e0fef82007-06-17 19:56:36 -05002370lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
James Smart858c9f62007-06-17 19:56:39 -05002371 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
2372 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05002373{
James Smart2e0fef82007-06-17 19:56:36 -05002374 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002375 IOCB_t *icmd;
2376 IOCB_t *oldcmd;
2377 struct lpfc_iocbq *elsiocb;
2378 struct lpfc_sli_ring *pring;
2379 struct lpfc_sli *psli;
2380 uint8_t *pcmd;
2381 uint16_t cmdsize;
2382 int rc;
2383
2384 psli = &phba->sli;
2385 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2386
James Smart92d7f7b2007-06-17 19:56:38 -05002387 cmdsize = 2 * sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05002388 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
2389 ndlp->nlp_DID, ELS_CMD_LS_RJT);
James Smart488d1462006-03-07 15:02:37 -05002390 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002391 return 1;
dea31012005-04-17 16:05:31 -05002392
2393 icmd = &elsiocb->iocb;
2394 oldcmd = &oldiocb->iocb;
2395 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2396 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2397
2398 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
James Smart92d7f7b2007-06-17 19:56:38 -05002399 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002400 *((uint32_t *) (pcmd)) = rejectError;
2401
James Smart51ef4c22007-08-02 11:10:31 -04002402 if (mbox)
James Smart858c9f62007-06-17 19:56:39 -05002403 elsiocb->context_un.mbox = mbox;
James Smart858c9f62007-06-17 19:56:39 -05002404
dea31012005-04-17 16:05:31 -05002405 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04002406 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2407 "0129 Xmit ELS RJT x%x response tag x%x "
2408 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
2409 "rpi x%x\n",
2410 rejectError, elsiocb->iotag,
2411 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
2412 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05002413 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2414 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
2415 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
2416
dea31012005-04-17 16:05:31 -05002417 phba->fc_stat.elsXmitLSRJT++;
James Smart858c9f62007-06-17 19:56:39 -05002418 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05002419 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
James Smart51ef4c22007-08-02 11:10:31 -04002420
2421 /* If the node is in the UNUSED state, and we are sending
2422 * a reject, we are done with it. Release driver reference
2423 * count here. The outstanding els will release its reference on
James Smart98c9ea52007-10-27 13:37:33 -04002424 * completion, as long as the ndlp stays in the UNUSED list,
2425 * and the node can be freed then.
James Smart51ef4c22007-08-02 11:10:31 -04002426 */
James Smart98c9ea52007-10-27 13:37:33 -04002427 if ((ndlp->nlp_state == NLP_STE_UNUSED_NODE) &&
2428 !(ndlp->nlp_flag & NLP_DELAYED_RM)) {
2429 ndlp->nlp_flag |= NLP_DELAYED_RM;
James Smart51ef4c22007-08-02 11:10:31 -04002430 lpfc_nlp_put(ndlp);
James Smart98c9ea52007-10-27 13:37:33 -04002431 }
James Smart51ef4c22007-08-02 11:10:31 -04002432
dea31012005-04-17 16:05:31 -05002433 if (rc == IOCB_ERROR) {
2434 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002435 return 1;
dea31012005-04-17 16:05:31 -05002436 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002437 return 0;
dea31012005-04-17 16:05:31 -05002438}
2439
2440int
James Smart2e0fef82007-06-17 19:56:36 -05002441lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
2442 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05002443{
James Smart2e0fef82007-06-17 19:56:36 -05002444 struct lpfc_hba *phba = vport->phba;
2445 struct lpfc_sli *psli = &phba->sli;
2446 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05002447 ADISC *ap;
James Smart2e0fef82007-06-17 19:56:36 -05002448 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05002449 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002450 uint8_t *pcmd;
2451 uint16_t cmdsize;
2452 int rc;
2453
James Smart92d7f7b2007-06-17 19:56:38 -05002454 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
James Smart2e0fef82007-06-17 19:56:36 -05002455 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
2456 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05002457 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002458 return 1;
dea31012005-04-17 16:05:31 -05002459
dea31012005-04-17 16:05:31 -05002460 icmd = &elsiocb->iocb;
2461 oldcmd = &oldiocb->iocb;
2462 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04002463
2464 /* Xmit ADISC ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04002465 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2466 "0130 Xmit ADISC ACC response iotag x%x xri: "
2467 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
2468 elsiocb->iotag, elsiocb->iocb.ulpContext,
2469 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2470 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05002471 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2472
2473 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05002474 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002475
2476 ap = (ADISC *) (pcmd);
2477 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05002478 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2479 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002480 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002481
James Smart858c9f62007-06-17 19:56:39 -05002482 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2483 "Issue ACC ADISC: did:x%x flg:x%x",
2484 ndlp->nlp_DID, ndlp->nlp_flag, 0);
2485
dea31012005-04-17 16:05:31 -05002486 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05002487 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05002488 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
dea31012005-04-17 16:05:31 -05002489 if (rc == IOCB_ERROR) {
2490 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002491 return 1;
dea31012005-04-17 16:05:31 -05002492 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002493 return 0;
dea31012005-04-17 16:05:31 -05002494}
2495
2496int
James Smart2e0fef82007-06-17 19:56:36 -05002497lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
James Smart5b8bd0c2007-04-25 09:52:49 -04002498 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05002499{
James Smart2e0fef82007-06-17 19:56:36 -05002500 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002501 PRLI *npr;
2502 lpfc_vpd_t *vpd;
2503 IOCB_t *icmd;
2504 IOCB_t *oldcmd;
2505 struct lpfc_iocbq *elsiocb;
2506 struct lpfc_sli_ring *pring;
2507 struct lpfc_sli *psli;
2508 uint8_t *pcmd;
2509 uint16_t cmdsize;
2510 int rc;
2511
2512 psli = &phba->sli;
2513 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2514
James Smart92d7f7b2007-06-17 19:56:38 -05002515 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
James Smart2e0fef82007-06-17 19:56:36 -05002516 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
James Smart92d7f7b2007-06-17 19:56:38 -05002517 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002518 if (!elsiocb)
2519 return 1;
dea31012005-04-17 16:05:31 -05002520
dea31012005-04-17 16:05:31 -05002521 icmd = &elsiocb->iocb;
2522 oldcmd = &oldiocb->iocb;
2523 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04002524 /* Xmit PRLI ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04002525 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2526 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
2527 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
2528 elsiocb->iotag, elsiocb->iocb.ulpContext,
2529 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2530 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05002531 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2532
2533 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
James Smart92d7f7b2007-06-17 19:56:38 -05002534 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002535
2536 /* For PRLI, remainder of payload is PRLI parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05002537 memset(pcmd, 0, sizeof(PRLI));
dea31012005-04-17 16:05:31 -05002538
2539 npr = (PRLI *) pcmd;
2540 vpd = &phba->vpd;
2541 /*
2542 * If our firmware version is 3.20 or later,
2543 * set the following bits for FC-TAPE support.
2544 */
2545 if (vpd->rev.feaLevelHigh >= 0x02) {
2546 npr->ConfmComplAllowed = 1;
2547 npr->Retry = 1;
2548 npr->TaskRetryIdReq = 1;
2549 }
2550
2551 npr->acceptRspCode = PRLI_REQ_EXECUTED;
2552 npr->estabImagePair = 1;
2553 npr->readXferRdyDis = 1;
2554 npr->ConfmComplAllowed = 1;
2555
2556 npr->prliType = PRLI_FCP_TYPE;
2557 npr->initiatorFunc = 1;
2558
James Smart858c9f62007-06-17 19:56:39 -05002559 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2560 "Issue ACC PRLI: did:x%x flg:x%x",
2561 ndlp->nlp_DID, ndlp->nlp_flag, 0);
2562
dea31012005-04-17 16:05:31 -05002563 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05002564 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05002565
dea31012005-04-17 16:05:31 -05002566 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
dea31012005-04-17 16:05:31 -05002567 if (rc == IOCB_ERROR) {
2568 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002569 return 1;
dea31012005-04-17 16:05:31 -05002570 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002571 return 0;
dea31012005-04-17 16:05:31 -05002572}
2573
2574static int
James Smart2e0fef82007-06-17 19:56:36 -05002575lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
James Smart329f9bc2007-04-25 09:53:01 -04002576 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05002577{
James Smart2e0fef82007-06-17 19:56:36 -05002578 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002579 RNID *rn;
James Smart2e0fef82007-06-17 19:56:36 -05002580 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05002581 struct lpfc_iocbq *elsiocb;
2582 struct lpfc_sli_ring *pring;
2583 struct lpfc_sli *psli;
2584 uint8_t *pcmd;
2585 uint16_t cmdsize;
2586 int rc;
2587
2588 psli = &phba->sli;
2589 pring = &psli->ring[LPFC_ELS_RING];
2590
James Smart92d7f7b2007-06-17 19:56:38 -05002591 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
2592 + (2 * sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002593 if (format)
James Smart92d7f7b2007-06-17 19:56:38 -05002594 cmdsize += sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05002595
James Smart2e0fef82007-06-17 19:56:36 -05002596 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
2597 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05002598 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002599 return 1;
dea31012005-04-17 16:05:31 -05002600
dea31012005-04-17 16:05:31 -05002601 icmd = &elsiocb->iocb;
2602 oldcmd = &oldiocb->iocb;
2603 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04002604 /* Xmit RNID ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04002605 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2606 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
2607 elsiocb->iotag, elsiocb->iocb.ulpContext);
dea31012005-04-17 16:05:31 -05002608 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
dea31012005-04-17 16:05:31 -05002609 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05002610 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002611
James Smart92d7f7b2007-06-17 19:56:38 -05002612 memset(pcmd, 0, sizeof(RNID));
dea31012005-04-17 16:05:31 -05002613 rn = (RNID *) (pcmd);
2614 rn->Format = format;
James Smart92d7f7b2007-06-17 19:56:38 -05002615 rn->CommonLen = (2 * sizeof(struct lpfc_name));
2616 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2617 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002618 switch (format) {
2619 case 0:
2620 rn->SpecificLen = 0;
2621 break;
2622 case RNID_TOPOLOGY_DISC:
James Smart92d7f7b2007-06-17 19:56:38 -05002623 rn->SpecificLen = sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05002624 memcpy(&rn->un.topologyDisc.portName,
James Smart92d7f7b2007-06-17 19:56:38 -05002625 &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002626 rn->un.topologyDisc.unitType = RNID_HBA;
2627 rn->un.topologyDisc.physPort = 0;
2628 rn->un.topologyDisc.attachedNodes = 0;
2629 break;
2630 default:
2631 rn->CommonLen = 0;
2632 rn->SpecificLen = 0;
2633 break;
2634 }
2635
James Smart858c9f62007-06-17 19:56:39 -05002636 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2637 "Issue ACC RNID: did:x%x flg:x%x",
2638 ndlp->nlp_DID, ndlp->nlp_flag, 0);
2639
dea31012005-04-17 16:05:31 -05002640 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05002641 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart329f9bc2007-04-25 09:53:01 -04002642 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002643 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
2644 * it could be freed */
2645
dea31012005-04-17 16:05:31 -05002646 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
dea31012005-04-17 16:05:31 -05002647 if (rc == IOCB_ERROR) {
2648 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002649 return 1;
dea31012005-04-17 16:05:31 -05002650 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002651 return 0;
dea31012005-04-17 16:05:31 -05002652}
2653
2654int
James Smart2e0fef82007-06-17 19:56:36 -05002655lpfc_els_disc_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002656{
James Smart2e0fef82007-06-17 19:56:36 -05002657 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002658 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05002659 int sentadisc = 0;
dea31012005-04-17 16:05:31 -05002660
James Smart685f0bf2007-04-25 09:53:08 -04002661 /* go thru NPR nodes and issue any remaining ELS ADISCs */
James Smart2e0fef82007-06-17 19:56:36 -05002662 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smart685f0bf2007-04-25 09:53:08 -04002663 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
2664 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
2665 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
James Smart2e0fef82007-06-17 19:56:36 -05002666 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04002667 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05002668 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04002669 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002670 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2671 lpfc_issue_els_adisc(vport, ndlp, 0);
James Smart685f0bf2007-04-25 09:53:08 -04002672 sentadisc++;
James Smart2e0fef82007-06-17 19:56:36 -05002673 vport->num_disc_nodes++;
2674 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04002675 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05002676 spin_lock_irq(shost->host_lock);
2677 vport->fc_flag |= FC_NLP_MORE;
2678 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04002679 break;
dea31012005-04-17 16:05:31 -05002680 }
2681 }
2682 }
2683 if (sentadisc == 0) {
James Smart2e0fef82007-06-17 19:56:36 -05002684 spin_lock_irq(shost->host_lock);
2685 vport->fc_flag &= ~FC_NLP_MORE;
2686 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002687 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002688 return sentadisc;
dea31012005-04-17 16:05:31 -05002689}
2690
2691int
James Smart2e0fef82007-06-17 19:56:36 -05002692lpfc_els_disc_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002693{
James Smart2e0fef82007-06-17 19:56:36 -05002694 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002695 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05002696 int sentplogi = 0;
dea31012005-04-17 16:05:31 -05002697
James Smart2e0fef82007-06-17 19:56:36 -05002698 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
2699 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smart685f0bf2007-04-25 09:53:08 -04002700 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
2701 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
2702 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
2703 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
2704 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002705 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2706 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
James Smart685f0bf2007-04-25 09:53:08 -04002707 sentplogi++;
James Smart2e0fef82007-06-17 19:56:36 -05002708 vport->num_disc_nodes++;
2709 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04002710 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05002711 spin_lock_irq(shost->host_lock);
2712 vport->fc_flag |= FC_NLP_MORE;
2713 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04002714 break;
dea31012005-04-17 16:05:31 -05002715 }
2716 }
2717 }
2718 if (sentplogi == 0) {
James Smart2e0fef82007-06-17 19:56:36 -05002719 spin_lock_irq(shost->host_lock);
2720 vport->fc_flag &= ~FC_NLP_MORE;
2721 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002722 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002723 return sentplogi;
dea31012005-04-17 16:05:31 -05002724}
2725
James Smart92d7f7b2007-06-17 19:56:38 -05002726void
James Smart2e0fef82007-06-17 19:56:36 -05002727lpfc_els_flush_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002728{
James Smart2e0fef82007-06-17 19:56:36 -05002729 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2730 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002731 int i;
2732
James Smart2e0fef82007-06-17 19:56:36 -05002733 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05002734 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
James Smart2e0fef82007-06-17 19:56:36 -05002735 vport->fc_rscn_id_list[i] = NULL;
dea31012005-04-17 16:05:31 -05002736 }
James Smart2e0fef82007-06-17 19:56:36 -05002737 spin_lock_irq(shost->host_lock);
2738 vport->fc_rscn_id_cnt = 0;
2739 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
2740 spin_unlock_irq(shost->host_lock);
2741 lpfc_can_disctmo(vport);
dea31012005-04-17 16:05:31 -05002742}
2743
2744int
James Smart2e0fef82007-06-17 19:56:36 -05002745lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05002746{
2747 D_ID ns_did;
2748 D_ID rscn_did;
dea31012005-04-17 16:05:31 -05002749 uint32_t *lp;
James Smart92d7f7b2007-06-17 19:56:38 -05002750 uint32_t payload_len, i;
dea31012005-04-17 16:05:31 -05002751
2752 ns_did.un.word = did;
dea31012005-04-17 16:05:31 -05002753
2754 /* Never match fabric nodes for RSCNs */
2755 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
James Smart2e0fef82007-06-17 19:56:36 -05002756 return 0;
dea31012005-04-17 16:05:31 -05002757
2758 /* If we are doing a FULL RSCN rediscovery, match everything */
James Smart2e0fef82007-06-17 19:56:36 -05002759 if (vport->fc_flag & FC_RSCN_DISCOVERY)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002760 return did;
dea31012005-04-17 16:05:31 -05002761
James Smart2e0fef82007-06-17 19:56:36 -05002762 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05002763 lp = vport->fc_rscn_id_list[i]->virt;
2764 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
2765 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05002766 while (payload_len) {
James Smart92d7f7b2007-06-17 19:56:38 -05002767 rscn_did.un.word = be32_to_cpu(*lp++);
2768 payload_len -= sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002769 switch (rscn_did.un.b.resv) {
2770 case 0: /* Single N_Port ID effected */
James Smart2e0fef82007-06-17 19:56:36 -05002771 if (ns_did.un.word == rscn_did.un.word)
James Smart92d7f7b2007-06-17 19:56:38 -05002772 return did;
dea31012005-04-17 16:05:31 -05002773 break;
2774 case 1: /* Whole N_Port Area effected */
2775 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
2776 && (ns_did.un.b.area == rscn_did.un.b.area))
James Smart92d7f7b2007-06-17 19:56:38 -05002777 return did;
dea31012005-04-17 16:05:31 -05002778 break;
2779 case 2: /* Whole N_Port Domain effected */
2780 if (ns_did.un.b.domain == rscn_did.un.b.domain)
James Smart92d7f7b2007-06-17 19:56:38 -05002781 return did;
dea31012005-04-17 16:05:31 -05002782 break;
2783 default:
James Smart2e0fef82007-06-17 19:56:36 -05002784 /* Unknown Identifier in RSCN node */
James Smarte8b62012007-08-02 11:10:09 -04002785 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
2786 "0217 Unknown Identifier in "
2787 "RSCN payload Data: x%x\n",
2788 rscn_did.un.word);
James Smart92d7f7b2007-06-17 19:56:38 -05002789 case 3: /* Whole Fabric effected */
2790 return did;
dea31012005-04-17 16:05:31 -05002791 }
2792 }
James Smart92d7f7b2007-06-17 19:56:38 -05002793 }
2794 return 0;
dea31012005-04-17 16:05:31 -05002795}
2796
2797static int
James Smart2e0fef82007-06-17 19:56:36 -05002798lpfc_rscn_recovery_check(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002799{
James Smart685f0bf2007-04-25 09:53:08 -04002800 struct lpfc_nodelist *ndlp = NULL;
dea31012005-04-17 16:05:31 -05002801
2802 /* Look at all nodes effected by pending RSCNs and move
James Smart685f0bf2007-04-25 09:53:08 -04002803 * them to NPR state.
dea31012005-04-17 16:05:31 -05002804 */
James Smart685f0bf2007-04-25 09:53:08 -04002805
James Smart2e0fef82007-06-17 19:56:36 -05002806 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smart685f0bf2007-04-25 09:53:08 -04002807 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE ||
James Smart2e0fef82007-06-17 19:56:36 -05002808 lpfc_rscn_payload_check(vport, ndlp->nlp_DID) == 0)
dea31012005-04-17 16:05:31 -05002809 continue;
2810
James Smart2e0fef82007-06-17 19:56:36 -05002811 lpfc_disc_state_machine(vport, ndlp, NULL,
James Smart92d7f7b2007-06-17 19:56:38 -05002812 NLP_EVT_DEVICE_RECOVERY);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002813
James Smart685f0bf2007-04-25 09:53:08 -04002814 /*
2815 * Make sure NLP_DELAY_TMO is NOT running after a device
2816 * recovery event.
2817 */
2818 if (ndlp->nlp_flag & NLP_DELAY_TMO)
James Smart2e0fef82007-06-17 19:56:36 -05002819 lpfc_cancel_retry_delay_tmo(vport, ndlp);
dea31012005-04-17 16:05:31 -05002820 }
James Smart685f0bf2007-04-25 09:53:08 -04002821
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002822 return 0;
dea31012005-04-17 16:05:31 -05002823}
2824
2825static int
James Smart2e0fef82007-06-17 19:56:36 -05002826lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04002827 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05002828{
James Smart2e0fef82007-06-17 19:56:36 -05002829 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2830 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002831 struct lpfc_dmabuf *pcmd;
James Smart92d7f7b2007-06-17 19:56:38 -05002832 uint32_t *lp, *datap;
dea31012005-04-17 16:05:31 -05002833 IOCB_t *icmd;
James Smart92d7f7b2007-06-17 19:56:38 -05002834 uint32_t payload_len, length, nportid, *cmd;
2835 int rscn_cnt = vport->fc_rscn_id_cnt;
2836 int rscn_id = 0, hba_id = 0;
James Smartd2873e42006-08-18 17:46:43 -04002837 int i;
dea31012005-04-17 16:05:31 -05002838
2839 icmd = &cmdiocb->iocb;
2840 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2841 lp = (uint32_t *) pcmd->virt;
2842
James Smart92d7f7b2007-06-17 19:56:38 -05002843 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
2844 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05002845 /* RSCN received */
James Smarte8b62012007-08-02 11:10:09 -04002846 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2847 "0214 RSCN received Data: x%x x%x x%x x%x\n",
2848 vport->fc_flag, payload_len, *lp, rscn_cnt);
James Smartd2873e42006-08-18 17:46:43 -04002849 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
James Smart2e0fef82007-06-17 19:56:36 -05002850 fc_host_post_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04002851 FCH_EVT_RSCN, lp[i]);
2852
dea31012005-04-17 16:05:31 -05002853 /* If we are about to begin discovery, just ACC the RSCN.
2854 * Discovery processing will satisfy it.
2855 */
James Smart2e0fef82007-06-17 19:56:36 -05002856 if (vport->port_state <= LPFC_NS_QRY) {
James Smart858c9f62007-06-17 19:56:39 -05002857 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
2858 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
2859 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
2860
James Smart51ef4c22007-08-02 11:10:31 -04002861 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002862 return 0;
dea31012005-04-17 16:05:31 -05002863 }
2864
James Smart92d7f7b2007-06-17 19:56:38 -05002865 /* If this RSCN just contains NPortIDs for other vports on this HBA,
2866 * just ACC and ignore it.
2867 */
2868 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart3de2a652007-08-02 11:09:59 -04002869 !(vport->cfg_peer_port_login)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002870 i = payload_len;
2871 datap = lp;
2872 while (i > 0) {
2873 nportid = *datap++;
2874 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
2875 i -= sizeof(uint32_t);
2876 rscn_id++;
James Smart549e55c2007-08-02 11:09:51 -04002877 if (lpfc_find_vport_by_did(phba, nportid))
2878 hba_id++;
James Smart92d7f7b2007-06-17 19:56:38 -05002879 }
2880 if (rscn_id == hba_id) {
2881 /* ALL NPortIDs in RSCN are on HBA */
James Smarte8b62012007-08-02 11:10:09 -04002882 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2883 "0214 Ignore RSCN "
2884 "Data: x%x x%x x%x x%x\n",
2885 vport->fc_flag, payload_len,
2886 *lp, rscn_cnt);
James Smart858c9f62007-06-17 19:56:39 -05002887 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
2888 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
2889 ndlp->nlp_DID, vport->port_state,
2890 ndlp->nlp_flag);
2891
James Smart92d7f7b2007-06-17 19:56:38 -05002892 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04002893 ndlp, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05002894 return 0;
2895 }
2896 }
2897
dea31012005-04-17 16:05:31 -05002898 /* If we are already processing an RSCN, save the received
2899 * RSCN payload buffer, cmdiocb->context2 to process later.
2900 */
James Smart2e0fef82007-06-17 19:56:36 -05002901 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
James Smart858c9f62007-06-17 19:56:39 -05002902 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
2903 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
2904 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
2905
James Smart92d7f7b2007-06-17 19:56:38 -05002906 vport->fc_flag |= FC_RSCN_DEFERRED;
2907 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
James Smart2e0fef82007-06-17 19:56:36 -05002908 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
2909 spin_lock_irq(shost->host_lock);
2910 vport->fc_flag |= FC_RSCN_MODE;
2911 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05002912 if (rscn_cnt) {
2913 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
2914 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
2915 }
2916 if ((rscn_cnt) &&
2917 (payload_len + length <= LPFC_BPL_SIZE)) {
2918 *cmd &= ELS_CMD_MASK;
2919 *cmd |= be32_to_cpu(payload_len + length);
2920 memcpy(((uint8_t *)cmd) + length, lp,
2921 payload_len);
2922 } else {
2923 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
2924 vport->fc_rscn_id_cnt++;
2925 /* If we zero, cmdiocb->context2, the calling
2926 * routine will not try to free it.
2927 */
2928 cmdiocb->context2 = NULL;
2929 }
dea31012005-04-17 16:05:31 -05002930
2931 /* Deferred RSCN */
James Smarte8b62012007-08-02 11:10:09 -04002932 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2933 "0235 Deferred RSCN "
2934 "Data: x%x x%x x%x\n",
2935 vport->fc_rscn_id_cnt, vport->fc_flag,
2936 vport->port_state);
dea31012005-04-17 16:05:31 -05002937 } else {
James Smart2e0fef82007-06-17 19:56:36 -05002938 spin_lock_irq(shost->host_lock);
2939 vport->fc_flag |= FC_RSCN_DISCOVERY;
2940 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002941 /* ReDiscovery RSCN */
James Smarte8b62012007-08-02 11:10:09 -04002942 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2943 "0234 ReDiscovery RSCN "
2944 "Data: x%x x%x x%x\n",
2945 vport->fc_rscn_id_cnt, vport->fc_flag,
2946 vport->port_state);
dea31012005-04-17 16:05:31 -05002947 }
2948 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04002949 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05002950
2951 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05002952 lpfc_rscn_recovery_check(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05002953 vport->fc_flag &= ~FC_RSCN_DEFERRED;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002954 return 0;
dea31012005-04-17 16:05:31 -05002955 }
2956
James Smart858c9f62007-06-17 19:56:39 -05002957 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
2958 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
2959 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
2960
James Smart2e0fef82007-06-17 19:56:36 -05002961 spin_lock_irq(shost->host_lock);
2962 vport->fc_flag |= FC_RSCN_MODE;
2963 spin_unlock_irq(shost->host_lock);
2964 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
dea31012005-04-17 16:05:31 -05002965 /*
2966 * If we zero, cmdiocb->context2, the calling routine will
2967 * not try to free it.
2968 */
2969 cmdiocb->context2 = NULL;
2970
James Smart2e0fef82007-06-17 19:56:36 -05002971 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05002972
2973 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04002974 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05002975
2976 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05002977 lpfc_rscn_recovery_check(vport);
dea31012005-04-17 16:05:31 -05002978
James Smart2e0fef82007-06-17 19:56:36 -05002979 return lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05002980}
2981
2982int
James Smart2e0fef82007-06-17 19:56:36 -05002983lpfc_els_handle_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002984{
2985 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05002986 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002987
James Smart92d7f7b2007-06-17 19:56:38 -05002988 /* Ignore RSCN if the port is being torn down. */
2989 if (vport->load_flag & FC_UNLOADING) {
2990 lpfc_els_flush_rscn(vport);
2991 return 0;
2992 }
2993
dea31012005-04-17 16:05:31 -05002994 /* Start timer for RSCN processing */
James Smart2e0fef82007-06-17 19:56:36 -05002995 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05002996
2997 /* RSCN processed */
James Smarte8b62012007-08-02 11:10:09 -04002998 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2999 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
3000 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
3001 vport->port_state);
dea31012005-04-17 16:05:31 -05003002
3003 /* To process RSCN, first compare RSCN data with NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05003004 vport->fc_ns_retry = 0;
3005 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smart685f0bf2007-04-25 09:53:08 -04003006 if (ndlp && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
dea31012005-04-17 16:05:31 -05003007 /* Good ndlp, issue CT Request to NameServer */
James Smart92d7f7b2007-06-17 19:56:38 -05003008 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
dea31012005-04-17 16:05:31 -05003009 /* Wait for NameServer query cmpl before we can
3010 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003011 return 1;
dea31012005-04-17 16:05:31 -05003012 } else {
3013 /* If login to NameServer does not exist, issue one */
3014 /* Good status, issue PLOGI to NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05003015 ndlp = lpfc_findnode_did(vport, NameServer_DID);
3016 if (ndlp)
dea31012005-04-17 16:05:31 -05003017 /* Wait for NameServer login cmpl before we can
3018 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003019 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05003020
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003021 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
3022 if (!ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05003023 lpfc_els_flush_rscn(vport);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003024 return 0;
dea31012005-04-17 16:05:31 -05003025 } else {
James Smart2e0fef82007-06-17 19:56:36 -05003026 lpfc_nlp_init(vport, ndlp, NameServer_DID);
dea31012005-04-17 16:05:31 -05003027 ndlp->nlp_type |= NLP_FABRIC;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003028 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003029 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
3030 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
dea31012005-04-17 16:05:31 -05003031 /* Wait for NameServer login cmpl before we can
3032 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003033 return 1;
dea31012005-04-17 16:05:31 -05003034 }
3035 }
3036
James Smart2e0fef82007-06-17 19:56:36 -05003037 lpfc_els_flush_rscn(vport);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003038 return 0;
dea31012005-04-17 16:05:31 -05003039}
3040
3041static int
James Smart2e0fef82007-06-17 19:56:36 -05003042lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04003043 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003044{
James Smart2e0fef82007-06-17 19:56:36 -05003045 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3046 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003047 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3048 uint32_t *lp = (uint32_t *) pcmd->virt;
3049 IOCB_t *icmd = &cmdiocb->iocb;
3050 struct serv_parm *sp;
3051 LPFC_MBOXQ_t *mbox;
3052 struct ls_rjt stat;
3053 uint32_t cmd, did;
3054 int rc;
3055
3056 cmd = *lp++;
3057 sp = (struct serv_parm *) lp;
3058
3059 /* FLOGI received */
3060
James Smart2e0fef82007-06-17 19:56:36 -05003061 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05003062
3063 if (phba->fc_topology == TOPOLOGY_LOOP) {
3064 /* We should never receive a FLOGI in loop mode, ignore it */
3065 did = icmd->un.elsreq64.remoteID;
3066
3067 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
3068 Loop Mode */
James Smarte8b62012007-08-02 11:10:09 -04003069 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3070 "0113 An FLOGI ELS command x%x was "
3071 "received from DID x%x in Loop Mode\n",
3072 cmd, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003073 return 1;
dea31012005-04-17 16:05:31 -05003074 }
3075
3076 did = Fabric_DID;
3077
James Smart2e0fef82007-06-17 19:56:36 -05003078 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3))) {
dea31012005-04-17 16:05:31 -05003079 /* For a FLOGI we accept, then if our portname is greater
3080 * then the remote portname we initiate Nport login.
3081 */
3082
James Smart2e0fef82007-06-17 19:56:36 -05003083 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -05003084 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003085
3086 if (!rc) {
James Smart2e0fef82007-06-17 19:56:36 -05003087 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3088 if (!mbox)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003089 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05003090
dea31012005-04-17 16:05:31 -05003091 lpfc_linkdown(phba);
3092 lpfc_init_link(phba, mbox,
3093 phba->cfg_topology,
3094 phba->cfg_link_speed);
3095 mbox->mb.un.varInitLnk.lipsr_AL_PA = 0;
3096 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -05003097 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -04003098 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart5b8bd0c2007-04-25 09:52:49 -04003099 lpfc_set_loopback_flag(phba);
dea31012005-04-17 16:05:31 -05003100 if (rc == MBX_NOT_FINISHED) {
James Smart329f9bc2007-04-25 09:53:01 -04003101 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003102 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003103 return 1;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003104 } else if (rc > 0) { /* greater than */
James Smart2e0fef82007-06-17 19:56:36 -05003105 spin_lock_irq(shost->host_lock);
3106 vport->fc_flag |= FC_PT2PT_PLOGI;
3107 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003108 }
James Smart2e0fef82007-06-17 19:56:36 -05003109 spin_lock_irq(shost->host_lock);
3110 vport->fc_flag |= FC_PT2PT;
3111 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
3112 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003113 } else {
3114 /* Reject this request because invalid parameters */
3115 stat.un.b.lsRjtRsvd0 = 0;
3116 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3117 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
3118 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05003119 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
3120 NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003121 return 1;
dea31012005-04-17 16:05:31 -05003122 }
3123
3124 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04003125 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05003126
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003127 return 0;
dea31012005-04-17 16:05:31 -05003128}
3129
3130static int
James Smart2e0fef82007-06-17 19:56:36 -05003131lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3132 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003133{
3134 struct lpfc_dmabuf *pcmd;
3135 uint32_t *lp;
3136 IOCB_t *icmd;
3137 RNID *rn;
3138 struct ls_rjt stat;
3139 uint32_t cmd, did;
3140
3141 icmd = &cmdiocb->iocb;
3142 did = icmd->un.elsreq64.remoteID;
3143 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3144 lp = (uint32_t *) pcmd->virt;
3145
3146 cmd = *lp++;
3147 rn = (RNID *) lp;
3148
3149 /* RNID received */
3150
3151 switch (rn->Format) {
3152 case 0:
3153 case RNID_TOPOLOGY_DISC:
3154 /* Send back ACC */
James Smart2e0fef82007-06-17 19:56:36 -05003155 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05003156 break;
3157 default:
3158 /* Reject this request because format not supported */
3159 stat.un.b.lsRjtRsvd0 = 0;
3160 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3161 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
3162 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05003163 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
3164 NULL);
dea31012005-04-17 16:05:31 -05003165 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003166 return 0;
dea31012005-04-17 16:05:31 -05003167}
3168
3169static int
James Smart2e0fef82007-06-17 19:56:36 -05003170lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3171 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003172{
3173 struct ls_rjt stat;
3174
3175 /* For now, unconditionally reject this command */
3176 stat.un.b.lsRjtRsvd0 = 0;
3177 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3178 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
3179 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05003180 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003181 return 0;
3182}
3183
Jamie Wellnitz082c0262006-02-28 19:25:30 -05003184static void
James Smart329f9bc2007-04-25 09:53:01 -04003185lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003186{
James Smart2e0fef82007-06-17 19:56:36 -05003187 struct lpfc_sli *psli = &phba->sli;
3188 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003189 MAILBOX_t *mb;
3190 IOCB_t *icmd;
3191 RPS_RSP *rps_rsp;
3192 uint8_t *pcmd;
3193 struct lpfc_iocbq *elsiocb;
3194 struct lpfc_nodelist *ndlp;
3195 uint16_t xri, status;
3196 uint32_t cmdsize;
3197
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003198 mb = &pmb->mb;
3199
3200 ndlp = (struct lpfc_nodelist *) pmb->context2;
3201 xri = (uint16_t) ((unsigned long)(pmb->context1));
Randy Dunlap041976f2006-06-25 01:58:51 -07003202 pmb->context1 = NULL;
3203 pmb->context2 = NULL;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003204
3205 if (mb->mbxStatus) {
James Smart329f9bc2007-04-25 09:53:01 -04003206 mempool_free(pmb, phba->mbox_mem_pool);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003207 return;
3208 }
3209
3210 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
James Smart329f9bc2007-04-25 09:53:01 -04003211 mempool_free(pmb, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05003212 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
3213 lpfc_max_els_tries, ndlp,
3214 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart329f9bc2007-04-25 09:53:01 -04003215 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003216 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003217 return;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003218
3219 icmd = &elsiocb->iocb;
3220 icmd->ulpContext = xri;
3221
3222 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3223 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003224 pcmd += sizeof(uint32_t); /* Skip past command */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003225 rps_rsp = (RPS_RSP *)pcmd;
3226
3227 if (phba->fc_topology != TOPOLOGY_LOOP)
3228 status = 0x10;
3229 else
3230 status = 0x8;
James Smart2e0fef82007-06-17 19:56:36 -05003231 if (phba->pport->fc_flag & FC_FABRIC)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003232 status |= 0x4;
3233
3234 rps_rsp->rsvd1 = 0;
3235 rps_rsp->portStatus = be16_to_cpu(status);
3236 rps_rsp->linkFailureCnt = be32_to_cpu(mb->un.varRdLnk.linkFailureCnt);
3237 rps_rsp->lossSyncCnt = be32_to_cpu(mb->un.varRdLnk.lossSyncCnt);
3238 rps_rsp->lossSignalCnt = be32_to_cpu(mb->un.varRdLnk.lossSignalCnt);
3239 rps_rsp->primSeqErrCnt = be32_to_cpu(mb->un.varRdLnk.primSeqErrCnt);
3240 rps_rsp->invalidXmitWord = be32_to_cpu(mb->un.varRdLnk.invalidXmitWord);
3241 rps_rsp->crcCnt = be32_to_cpu(mb->un.varRdLnk.crcCnt);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003242 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003243 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
3244 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
3245 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
3246 elsiocb->iotag, elsiocb->iocb.ulpContext,
3247 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3248 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05003249 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003250 phba->fc_stat.elsXmitACC++;
James Smarted957682007-06-17 19:56:37 -05003251 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003252 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003253 return;
3254}
3255
3256static int
James Smart2e0fef82007-06-17 19:56:36 -05003257lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3258 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003259{
James Smart2e0fef82007-06-17 19:56:36 -05003260 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003261 uint32_t *lp;
3262 uint8_t flag;
3263 LPFC_MBOXQ_t *mbox;
3264 struct lpfc_dmabuf *pcmd;
3265 RPS *rps;
3266 struct ls_rjt stat;
3267
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003268 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
3269 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003270 stat.un.b.lsRjtRsvd0 = 0;
3271 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3272 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
3273 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05003274 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
3275 NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003276 }
3277
3278 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3279 lp = (uint32_t *) pcmd->virt;
3280 flag = (be32_to_cpu(*lp++) & 0xf);
3281 rps = (RPS *) lp;
3282
3283 if ((flag == 0) ||
3284 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
James Smart2e0fef82007-06-17 19:56:36 -05003285 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05003286 sizeof(struct lpfc_name)) == 0))) {
James Smart2e0fef82007-06-17 19:56:36 -05003287
James Smart92d7f7b2007-06-17 19:56:38 -05003288 printk("Fix me....\n");
3289 dump_stack();
James Smart2e0fef82007-06-17 19:56:36 -05003290 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
3291 if (mbox) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003292 lpfc_read_lnk_stat(phba, mbox);
3293 mbox->context1 =
James Smart92d7f7b2007-06-17 19:56:38 -05003294 (void *)((unsigned long) cmdiocb->iocb.ulpContext);
James Smart329f9bc2007-04-25 09:53:01 -04003295 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05003296 mbox->vport = vport;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003297 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
James Smart0b727fe2007-10-27 13:37:25 -04003298 if (lpfc_sli_issue_mbox (phba, mbox, MBX_NOWAIT)
3299 != MBX_NOT_FINISHED)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003300 /* Mbox completion will send ELS Response */
3301 return 0;
James Smart2e0fef82007-06-17 19:56:36 -05003302
James Smart329f9bc2007-04-25 09:53:01 -04003303 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003304 mempool_free(mbox, phba->mbox_mem_pool);
3305 }
3306 }
3307 stat.un.b.lsRjtRsvd0 = 0;
3308 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3309 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
3310 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05003311 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003312 return 0;
3313}
3314
Jamie Wellnitz082c0262006-02-28 19:25:30 -05003315static int
James Smart2e0fef82007-06-17 19:56:36 -05003316lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
3317 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003318{
James Smart2e0fef82007-06-17 19:56:36 -05003319 struct lpfc_hba *phba = vport->phba;
3320 IOCB_t *icmd, *oldcmd;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003321 RPL_RSP rpl_rsp;
3322 struct lpfc_iocbq *elsiocb;
James Smart2e0fef82007-06-17 19:56:36 -05003323 struct lpfc_sli *psli = &phba->sli;
3324 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003325 uint8_t *pcmd;
3326
James Smart2e0fef82007-06-17 19:56:36 -05003327 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3328 ndlp->nlp_DID, ELS_CMD_ACC);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003329
James Smart488d1462006-03-07 15:02:37 -05003330 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003331 return 1;
James Smart488d1462006-03-07 15:02:37 -05003332
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003333 icmd = &elsiocb->iocb;
3334 oldcmd = &oldiocb->iocb;
3335 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3336
3337 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3338 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003339 pcmd += sizeof(uint16_t);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003340 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
3341 pcmd += sizeof(uint16_t);
3342
3343 /* Setup the RPL ACC payload */
3344 rpl_rsp.listLen = be32_to_cpu(1);
3345 rpl_rsp.index = 0;
3346 rpl_rsp.port_num_blk.portNum = 0;
James Smart2e0fef82007-06-17 19:56:36 -05003347 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
3348 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003349 sizeof(struct lpfc_name));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003350 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003351 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003352 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3353 "0120 Xmit ELS RPL ACC response tag x%x "
3354 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
3355 "rpi x%x\n",
3356 elsiocb->iotag, elsiocb->iocb.ulpContext,
3357 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3358 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05003359 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003360 phba->fc_stat.elsXmitACC++;
3361 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
3362 lpfc_els_free_iocb(phba, elsiocb);
3363 return 1;
3364 }
3365 return 0;
3366}
3367
3368static int
James Smart2e0fef82007-06-17 19:56:36 -05003369lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3370 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003371{
3372 struct lpfc_dmabuf *pcmd;
3373 uint32_t *lp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003374 uint32_t maxsize;
3375 uint16_t cmdsize;
3376 RPL *rpl;
3377 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05003378
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003379 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
3380 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003381 stat.un.b.lsRjtRsvd0 = 0;
3382 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3383 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
3384 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05003385 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
3386 NULL);
dea31012005-04-17 16:05:31 -05003387 }
3388
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003389 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3390 lp = (uint32_t *) pcmd->virt;
3391 rpl = (RPL *) (lp + 1);
3392
3393 maxsize = be32_to_cpu(rpl->maxsize);
3394
3395 /* We support only one port */
3396 if ((rpl->index == 0) &&
3397 ((maxsize == 0) ||
3398 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
3399 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003400 } else {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003401 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
3402 }
James Smart2e0fef82007-06-17 19:56:36 -05003403 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05003404
3405 return 0;
3406}
3407
3408static int
James Smart2e0fef82007-06-17 19:56:36 -05003409lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3410 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003411{
3412 struct lpfc_dmabuf *pcmd;
3413 uint32_t *lp;
3414 IOCB_t *icmd;
3415 FARP *fp;
3416 uint32_t cmd, cnt, did;
3417
3418 icmd = &cmdiocb->iocb;
3419 did = icmd->un.elsreq64.remoteID;
3420 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3421 lp = (uint32_t *) pcmd->virt;
3422
3423 cmd = *lp++;
3424 fp = (FARP *) lp;
dea31012005-04-17 16:05:31 -05003425 /* FARP-REQ received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04003426 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3427 "0601 FARP-REQ received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05003428 /* We will only support match on WWPN or WWNN */
3429 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003430 return 0;
dea31012005-04-17 16:05:31 -05003431 }
3432
3433 cnt = 0;
3434 /* If this FARP command is searching for my portname */
3435 if (fp->Mflags & FARP_MATCH_PORT) {
James Smart2e0fef82007-06-17 19:56:36 -05003436 if (memcmp(&fp->RportName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05003437 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05003438 cnt = 1;
3439 }
3440
3441 /* If this FARP command is searching for my nodename */
3442 if (fp->Mflags & FARP_MATCH_NODE) {
James Smart2e0fef82007-06-17 19:56:36 -05003443 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05003444 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05003445 cnt = 1;
3446 }
3447
3448 if (cnt) {
3449 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
3450 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
3451 /* Log back into the node before sending the FARP. */
3452 if (fp->Rflags & FARP_REQUEST_PLOGI) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003453 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003454 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04003455 NLP_STE_PLOGI_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05003456 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05003457 }
3458
3459 /* Send a FARP response to that node */
James Smart2e0fef82007-06-17 19:56:36 -05003460 if (fp->Rflags & FARP_REQUEST_FARPR)
3461 lpfc_issue_els_farpr(vport, did, 0);
dea31012005-04-17 16:05:31 -05003462 }
3463 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003464 return 0;
dea31012005-04-17 16:05:31 -05003465}
3466
3467static int
James Smart2e0fef82007-06-17 19:56:36 -05003468lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3469 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003470{
3471 struct lpfc_dmabuf *pcmd;
3472 uint32_t *lp;
3473 IOCB_t *icmd;
3474 uint32_t cmd, did;
3475
3476 icmd = &cmdiocb->iocb;
3477 did = icmd->un.elsreq64.remoteID;
3478 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3479 lp = (uint32_t *) pcmd->virt;
3480
3481 cmd = *lp++;
3482 /* FARP-RSP received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04003483 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3484 "0600 FARP-RSP received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05003485 /* ACCEPT the Farp resp request */
James Smart51ef4c22007-08-02 11:10:31 -04003486 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05003487
3488 return 0;
3489}
3490
3491static int
James Smart2e0fef82007-06-17 19:56:36 -05003492lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3493 struct lpfc_nodelist *fan_ndlp)
dea31012005-04-17 16:05:31 -05003494{
3495 struct lpfc_dmabuf *pcmd;
3496 uint32_t *lp;
3497 IOCB_t *icmd;
dea31012005-04-17 16:05:31 -05003498 uint32_t cmd, did;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003499 FAN *fp;
3500 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05003501 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003502
3503 /* FAN received */
James Smarte8b62012007-08-02 11:10:09 -04003504 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3505 "0265 FAN received\n");
dea31012005-04-17 16:05:31 -05003506 icmd = &cmdiocb->iocb;
3507 did = icmd->un.elsreq64.remoteID;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003508 pcmd = (struct lpfc_dmabuf *)cmdiocb->context2;
3509 lp = (uint32_t *)pcmd->virt;
dea31012005-04-17 16:05:31 -05003510
3511 cmd = *lp++;
James Smart92d7f7b2007-06-17 19:56:38 -05003512 fp = (FAN *) lp;
dea31012005-04-17 16:05:31 -05003513
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003514 /* FAN received; Fan does not have a reply sequence */
dea31012005-04-17 16:05:31 -05003515
James Smart2e0fef82007-06-17 19:56:36 -05003516 if (phba->pport->port_state == LPFC_LOCAL_CFG_LINK) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003517 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
3518 sizeof(struct lpfc_name)) != 0) ||
3519 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
3520 sizeof(struct lpfc_name)) != 0)) {
3521 /*
3522 * This node has switched fabrics. FLOGI is required
3523 * Clean up the old rpi's
dea31012005-04-17 16:05:31 -05003524 */
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003525
3526 list_for_each_entry_safe(ndlp, next_ndlp,
James Smart2e0fef82007-06-17 19:56:36 -05003527 &vport->fc_nodes, nlp_listp) {
James Smart685f0bf2007-04-25 09:53:08 -04003528 if (ndlp->nlp_state != NLP_STE_NPR_NODE)
3529 continue;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003530 if (ndlp->nlp_type & NLP_FABRIC) {
3531 /*
3532 * Clean up old Fabric, Nameserver and
3533 * other NLP_FABRIC logins
3534 */
James Smart2e0fef82007-06-17 19:56:36 -05003535 lpfc_drop_node(vport, ndlp);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003536 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003537 /* Fail outstanding I/O now since this
3538 * device is marked for PLOGI
3539 */
James Smart2e0fef82007-06-17 19:56:36 -05003540 lpfc_unreg_rpi(vport, ndlp);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003541 }
3542 }
3543
James Smart2e0fef82007-06-17 19:56:36 -05003544 lpfc_initial_flogi(vport);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003545 return 0;
dea31012005-04-17 16:05:31 -05003546 }
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003547 /* Discovery not needed,
3548 * move the nodes to their original state.
3549 */
James Smart2e0fef82007-06-17 19:56:36 -05003550 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
James Smart685f0bf2007-04-25 09:53:08 -04003551 nlp_listp) {
3552 if (ndlp->nlp_state != NLP_STE_NPR_NODE)
3553 continue;
dea31012005-04-17 16:05:31 -05003554
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003555 switch (ndlp->nlp_prev_state) {
3556 case NLP_STE_UNMAPPED_NODE:
3557 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05003558 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04003559 NLP_STE_UNMAPPED_NODE);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003560 break;
3561
3562 case NLP_STE_MAPPED_NODE:
3563 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05003564 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04003565 NLP_STE_MAPPED_NODE);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003566 break;
3567
3568 default:
3569 break;
3570 }
3571 }
3572
3573 /* Start discovery - this should just do CLEAR_LA */
James Smart2e0fef82007-06-17 19:56:36 -05003574 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -05003575 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003576 return 0;
dea31012005-04-17 16:05:31 -05003577}
3578
3579void
3580lpfc_els_timeout(unsigned long ptr)
3581{
James Smart2e0fef82007-06-17 19:56:36 -05003582 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
3583 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003584 unsigned long iflag;
3585
James Smart2e0fef82007-06-17 19:56:36 -05003586 spin_lock_irqsave(&vport->work_port_lock, iflag);
3587 if ((vport->work_port_events & WORKER_ELS_TMO) == 0) {
3588 vport->work_port_events |= WORKER_ELS_TMO;
James Smart92d7f7b2007-06-17 19:56:38 -05003589 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
3590
3591 spin_lock_irqsave(&phba->hbalock, iflag);
dea31012005-04-17 16:05:31 -05003592 if (phba->work_wait)
James Smart92d7f7b2007-06-17 19:56:38 -05003593 lpfc_worker_wake_up(phba);
3594 spin_unlock_irqrestore(&phba->hbalock, iflag);
dea31012005-04-17 16:05:31 -05003595 }
James Smart92d7f7b2007-06-17 19:56:38 -05003596 else
3597 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
dea31012005-04-17 16:05:31 -05003598 return;
3599}
3600
3601void
James Smart2e0fef82007-06-17 19:56:36 -05003602lpfc_els_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003603{
James Smart2e0fef82007-06-17 19:56:36 -05003604 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003605 struct lpfc_sli_ring *pring;
3606 struct lpfc_iocbq *tmp_iocb, *piocb;
3607 IOCB_t *cmd = NULL;
3608 struct lpfc_dmabuf *pcmd;
James Smart2e0fef82007-06-17 19:56:36 -05003609 uint32_t els_command = 0;
dea31012005-04-17 16:05:31 -05003610 uint32_t timeout;
James Smart2e0fef82007-06-17 19:56:36 -05003611 uint32_t remote_ID = 0xffffffff;
dea31012005-04-17 16:05:31 -05003612
dea31012005-04-17 16:05:31 -05003613 /* If the timer is already canceled do nothing */
James Smart2e0fef82007-06-17 19:56:36 -05003614 if ((vport->work_port_events & WORKER_ELS_TMO) == 0) {
dea31012005-04-17 16:05:31 -05003615 return;
3616 }
James Smart2e0fef82007-06-17 19:56:36 -05003617 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003618 timeout = (uint32_t)(phba->fc_ratov << 1);
3619
3620 pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05003621
3622 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
3623 cmd = &piocb->iocb;
3624
James Smart2e0fef82007-06-17 19:56:36 -05003625 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
3626 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
3627 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
dea31012005-04-17 16:05:31 -05003628 continue;
James Smart2e0fef82007-06-17 19:56:36 -05003629
3630 if (piocb->vport != vport)
3631 continue;
3632
dea31012005-04-17 16:05:31 -05003633 pcmd = (struct lpfc_dmabuf *) piocb->context2;
James Smart2e0fef82007-06-17 19:56:36 -05003634 if (pcmd)
3635 els_command = *(uint32_t *) (pcmd->virt);
dea31012005-04-17 16:05:31 -05003636
James Smart92d7f7b2007-06-17 19:56:38 -05003637 if (els_command == ELS_CMD_FARP ||
3638 els_command == ELS_CMD_FARPR ||
3639 els_command == ELS_CMD_FDISC)
dea31012005-04-17 16:05:31 -05003640 continue;
James Smart92d7f7b2007-06-17 19:56:38 -05003641
3642 if (vport != piocb->vport)
3643 continue;
dea31012005-04-17 16:05:31 -05003644
3645 if (piocb->drvrTimeout > 0) {
James Smart92d7f7b2007-06-17 19:56:38 -05003646 if (piocb->drvrTimeout >= timeout)
dea31012005-04-17 16:05:31 -05003647 piocb->drvrTimeout -= timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05003648 else
dea31012005-04-17 16:05:31 -05003649 piocb->drvrTimeout = 0;
dea31012005-04-17 16:05:31 -05003650 continue;
3651 }
3652
James Smart2e0fef82007-06-17 19:56:36 -05003653 remote_ID = 0xffffffff;
3654 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
dea31012005-04-17 16:05:31 -05003655 remote_ID = cmd->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05003656 else {
3657 struct lpfc_nodelist *ndlp;
3658 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
3659 if (ndlp)
3660 remote_ID = ndlp->nlp_DID;
dea31012005-04-17 16:05:31 -05003661 }
James Smarte8b62012007-08-02 11:10:09 -04003662 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3663 "0127 ELS timeout Data: x%x x%x x%x "
3664 "x%x\n", els_command,
3665 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
James Smart07951072007-04-25 09:51:38 -04003666 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05003667 }
James Smart2e0fef82007-06-17 19:56:36 -05003668 spin_unlock_irq(&phba->hbalock);
James Smart5a0e3262006-07-06 15:49:16 -04003669
James Smart2e0fef82007-06-17 19:56:36 -05003670 if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt)
3671 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
dea31012005-04-17 16:05:31 -05003672}
3673
3674void
James Smart2e0fef82007-06-17 19:56:36 -05003675lpfc_els_flush_cmd(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003676{
James Smart2534ba72007-04-25 09:52:20 -04003677 LIST_HEAD(completions);
James Smart2e0fef82007-06-17 19:56:36 -05003678 struct lpfc_hba *phba = vport->phba;
James Smart329f9bc2007-04-25 09:53:01 -04003679 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05003680 struct lpfc_iocbq *tmp_iocb, *piocb;
3681 IOCB_t *cmd = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05003682
3683 lpfc_fabric_abort_vport(vport);
dea31012005-04-17 16:05:31 -05003684
James Smart2e0fef82007-06-17 19:56:36 -05003685 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003686 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
3687 cmd = &piocb->iocb;
3688
3689 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
3690 continue;
3691 }
3692
3693 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
James Smart329f9bc2007-04-25 09:53:01 -04003694 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
3695 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
3696 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
3697 cmd->ulpCommand == CMD_ABORT_XRI_CN)
dea31012005-04-17 16:05:31 -05003698 continue;
dea31012005-04-17 16:05:31 -05003699
James Smart2e0fef82007-06-17 19:56:36 -05003700 if (piocb->vport != vport)
3701 continue;
3702
James Smart2534ba72007-04-25 09:52:20 -04003703 list_move_tail(&piocb->list, &completions);
James Smart1dcb58e2007-04-25 09:51:30 -04003704 pring->txq_cnt--;
dea31012005-04-17 16:05:31 -05003705 }
3706
3707 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
dea31012005-04-17 16:05:31 -05003708 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
3709 continue;
3710 }
dea31012005-04-17 16:05:31 -05003711
James Smart2e0fef82007-06-17 19:56:36 -05003712 if (piocb->vport != vport)
3713 continue;
3714
James Smart07951072007-04-25 09:51:38 -04003715 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05003716 }
James Smart2e0fef82007-06-17 19:56:36 -05003717 spin_unlock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04003718
James Smart2e0fef82007-06-17 19:56:36 -05003719 while (!list_empty(&completions)) {
James Smart2534ba72007-04-25 09:52:20 -04003720 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
3721 cmd = &piocb->iocb;
James Smart92d7f7b2007-06-17 19:56:38 -05003722 list_del_init(&piocb->list);
James Smart2534ba72007-04-25 09:52:20 -04003723
James Smart2e0fef82007-06-17 19:56:36 -05003724 if (!piocb->iocb_cmpl)
3725 lpfc_sli_release_iocbq(phba, piocb);
3726 else {
James Smart2534ba72007-04-25 09:52:20 -04003727 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
3728 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
3729 (piocb->iocb_cmpl) (phba, piocb, piocb);
James Smart2e0fef82007-06-17 19:56:36 -05003730 }
James Smart2534ba72007-04-25 09:52:20 -04003731 }
3732
dea31012005-04-17 16:05:31 -05003733 return;
3734}
3735
James Smart549e55c2007-08-02 11:09:51 -04003736void
3737lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
3738{
3739 LIST_HEAD(completions);
3740 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
3741 struct lpfc_iocbq *tmp_iocb, *piocb;
3742 IOCB_t *cmd = NULL;
3743
3744 lpfc_fabric_abort_hba(phba);
3745 spin_lock_irq(&phba->hbalock);
3746 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
3747 cmd = &piocb->iocb;
3748 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
3749 continue;
3750 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
3751 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
3752 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
3753 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
3754 cmd->ulpCommand == CMD_ABORT_XRI_CN)
3755 continue;
3756 list_move_tail(&piocb->list, &completions);
3757 pring->txq_cnt--;
3758 }
3759 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
3760 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
3761 continue;
3762 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
3763 }
3764 spin_unlock_irq(&phba->hbalock);
3765 while (!list_empty(&completions)) {
3766 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
3767 cmd = &piocb->iocb;
3768 list_del_init(&piocb->list);
3769 if (!piocb->iocb_cmpl)
3770 lpfc_sli_release_iocbq(phba, piocb);
3771 else {
3772 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
3773 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
3774 (piocb->iocb_cmpl) (phba, piocb, piocb);
3775 }
3776 }
3777 return;
3778}
3779
James Smarted957682007-06-17 19:56:37 -05003780static void
3781lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
James Smart92d7f7b2007-06-17 19:56:38 -05003782 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05003783{
dea31012005-04-17 16:05:31 -05003784 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05003785 struct ls_rjt stat;
James Smart92d7f7b2007-06-17 19:56:38 -05003786 uint32_t *payload;
James Smart2e0fef82007-06-17 19:56:36 -05003787 uint32_t cmd, did, newnode, rjt_err = 0;
James Smarted957682007-06-17 19:56:37 -05003788 IOCB_t *icmd = &elsiocb->iocb;
dea31012005-04-17 16:05:31 -05003789
James Smart92d7f7b2007-06-17 19:56:38 -05003790 if (vport == NULL || elsiocb->context2 == NULL)
dea31012005-04-17 16:05:31 -05003791 goto dropit;
James Smart2e0fef82007-06-17 19:56:36 -05003792
dea31012005-04-17 16:05:31 -05003793 newnode = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05003794 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
3795 cmd = *payload;
James Smarted957682007-06-17 19:56:37 -05003796 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
3797 lpfc_post_buffer(phba, pring, 1, 1);
dea31012005-04-17 16:05:31 -05003798
James Smart858c9f62007-06-17 19:56:39 -05003799 did = icmd->un.rcvels.remoteID;
3800 if (icmd->ulpStatus) {
3801 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3802 "RCV Unsol ELS: status:x%x/x%x did:x%x",
3803 icmd->ulpStatus, icmd->un.ulpWord[4], did);
dea31012005-04-17 16:05:31 -05003804 goto dropit;
James Smart858c9f62007-06-17 19:56:39 -05003805 }
dea31012005-04-17 16:05:31 -05003806
3807 /* Check to see if link went down during discovery */
James Smarted957682007-06-17 19:56:37 -05003808 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05003809 goto dropit;
dea31012005-04-17 16:05:31 -05003810
James Smart92d7f7b2007-06-17 19:56:38 -05003811 /* Ignore traffic recevied during vport shutdown. */
3812 if (vport->load_flag & FC_UNLOADING)
3813 goto dropit;
3814
James Smart2e0fef82007-06-17 19:56:36 -05003815 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003816 if (!ndlp) {
dea31012005-04-17 16:05:31 -05003817 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003818 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
James Smarted957682007-06-17 19:56:37 -05003819 if (!ndlp)
dea31012005-04-17 16:05:31 -05003820 goto dropit;
dea31012005-04-17 16:05:31 -05003821
James Smart2e0fef82007-06-17 19:56:36 -05003822 lpfc_nlp_init(vport, ndlp, did);
James Smart98c9ea52007-10-27 13:37:33 -04003823 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05003824 newnode = 1;
3825 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) {
3826 ndlp->nlp_type |= NLP_FABRIC;
3827 }
3828 }
3829
3830 phba->fc_stat.elsRcvFrame++;
James Smart329f9bc2007-04-25 09:53:01 -04003831 if (elsiocb->context1)
3832 lpfc_nlp_put(elsiocb->context1);
3833 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05003834 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -05003835
3836 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
3837 cmd &= ELS_CMD_MASK;
3838 }
3839 /* ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04003840 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3841 "0112 ELS command x%x received from NPORT x%x "
3842 "Data: x%x\n", cmd, did, vport->port_state);
dea31012005-04-17 16:05:31 -05003843 switch (cmd) {
3844 case ELS_CMD_PLOGI:
James Smart858c9f62007-06-17 19:56:39 -05003845 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3846 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
3847 did, vport->port_state, ndlp->nlp_flag);
3848
dea31012005-04-17 16:05:31 -05003849 phba->fc_stat.elsRcvPLOGI++;
James Smart858c9f62007-06-17 19:56:39 -05003850 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
3851
3852 if (vport->port_state < LPFC_DISC_AUTH) {
3853 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05003854 break;
3855 }
James Smart2e0fef82007-06-17 19:56:36 -05003856 lpfc_disc_state_machine(vport, ndlp, elsiocb,
3857 NLP_EVT_RCV_PLOGI);
James Smart858c9f62007-06-17 19:56:39 -05003858
dea31012005-04-17 16:05:31 -05003859 break;
3860 case ELS_CMD_FLOGI:
James Smart858c9f62007-06-17 19:56:39 -05003861 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3862 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
3863 did, vport->port_state, ndlp->nlp_flag);
3864
dea31012005-04-17 16:05:31 -05003865 phba->fc_stat.elsRcvFLOGI++;
James Smart51ef4c22007-08-02 11:10:31 -04003866 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
James Smart98c9ea52007-10-27 13:37:33 -04003867 if (newnode && (!(ndlp->nlp_flag & NLP_DELAYED_RM)))
3868 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05003869 break;
3870 case ELS_CMD_LOGO:
James Smart858c9f62007-06-17 19:56:39 -05003871 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3872 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
3873 did, vport->port_state, ndlp->nlp_flag);
3874
dea31012005-04-17 16:05:31 -05003875 phba->fc_stat.elsRcvLOGO++;
James Smart2e0fef82007-06-17 19:56:36 -05003876 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05003877 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05003878 break;
3879 }
James Smart2e0fef82007-06-17 19:56:36 -05003880 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
dea31012005-04-17 16:05:31 -05003881 break;
3882 case ELS_CMD_PRLO:
James Smart858c9f62007-06-17 19:56:39 -05003883 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3884 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
3885 did, vport->port_state, ndlp->nlp_flag);
3886
dea31012005-04-17 16:05:31 -05003887 phba->fc_stat.elsRcvPRLO++;
James Smart2e0fef82007-06-17 19:56:36 -05003888 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05003889 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05003890 break;
3891 }
James Smart2e0fef82007-06-17 19:56:36 -05003892 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
dea31012005-04-17 16:05:31 -05003893 break;
3894 case ELS_CMD_RSCN:
3895 phba->fc_stat.elsRcvRSCN++;
James Smart51ef4c22007-08-02 11:10:31 -04003896 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
James Smart98c9ea52007-10-27 13:37:33 -04003897 if (newnode && (!(ndlp->nlp_flag & NLP_DELAYED_RM)))
3898 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05003899 break;
3900 case ELS_CMD_ADISC:
James Smart858c9f62007-06-17 19:56:39 -05003901 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3902 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
3903 did, vport->port_state, ndlp->nlp_flag);
3904
dea31012005-04-17 16:05:31 -05003905 phba->fc_stat.elsRcvADISC++;
James Smart2e0fef82007-06-17 19:56:36 -05003906 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05003907 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05003908 break;
3909 }
James Smart2e0fef82007-06-17 19:56:36 -05003910 lpfc_disc_state_machine(vport, ndlp, elsiocb,
3911 NLP_EVT_RCV_ADISC);
dea31012005-04-17 16:05:31 -05003912 break;
3913 case ELS_CMD_PDISC:
James Smart858c9f62007-06-17 19:56:39 -05003914 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3915 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
3916 did, vport->port_state, ndlp->nlp_flag);
3917
dea31012005-04-17 16:05:31 -05003918 phba->fc_stat.elsRcvPDISC++;
James Smart2e0fef82007-06-17 19:56:36 -05003919 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05003920 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05003921 break;
3922 }
James Smart2e0fef82007-06-17 19:56:36 -05003923 lpfc_disc_state_machine(vport, ndlp, elsiocb,
3924 NLP_EVT_RCV_PDISC);
dea31012005-04-17 16:05:31 -05003925 break;
3926 case ELS_CMD_FARPR:
James Smart858c9f62007-06-17 19:56:39 -05003927 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3928 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
3929 did, vport->port_state, ndlp->nlp_flag);
3930
dea31012005-04-17 16:05:31 -05003931 phba->fc_stat.elsRcvFARPR++;
James Smart2e0fef82007-06-17 19:56:36 -05003932 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05003933 break;
3934 case ELS_CMD_FARP:
James Smart858c9f62007-06-17 19:56:39 -05003935 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3936 "RCV FARP: did:x%x/ste:x%x flg:x%x",
3937 did, vport->port_state, ndlp->nlp_flag);
3938
dea31012005-04-17 16:05:31 -05003939 phba->fc_stat.elsRcvFARP++;
James Smart2e0fef82007-06-17 19:56:36 -05003940 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05003941 break;
3942 case ELS_CMD_FAN:
James Smart858c9f62007-06-17 19:56:39 -05003943 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3944 "RCV FAN: did:x%x/ste:x%x flg:x%x",
3945 did, vport->port_state, ndlp->nlp_flag);
3946
dea31012005-04-17 16:05:31 -05003947 phba->fc_stat.elsRcvFAN++;
James Smart2e0fef82007-06-17 19:56:36 -05003948 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05003949 break;
dea31012005-04-17 16:05:31 -05003950 case ELS_CMD_PRLI:
James Smart858c9f62007-06-17 19:56:39 -05003951 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3952 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
3953 did, vport->port_state, ndlp->nlp_flag);
3954
dea31012005-04-17 16:05:31 -05003955 phba->fc_stat.elsRcvPRLI++;
James Smart2e0fef82007-06-17 19:56:36 -05003956 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05003957 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05003958 break;
3959 }
James Smart2e0fef82007-06-17 19:56:36 -05003960 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
dea31012005-04-17 16:05:31 -05003961 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003962 case ELS_CMD_LIRR:
James Smart858c9f62007-06-17 19:56:39 -05003963 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3964 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
3965 did, vport->port_state, ndlp->nlp_flag);
3966
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003967 phba->fc_stat.elsRcvLIRR++;
James Smart2e0fef82007-06-17 19:56:36 -05003968 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
James Smart98c9ea52007-10-27 13:37:33 -04003969 if (newnode && (!(ndlp->nlp_flag & NLP_DELAYED_RM)))
3970 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003971 break;
3972 case ELS_CMD_RPS:
James Smart858c9f62007-06-17 19:56:39 -05003973 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3974 "RCV RPS: did:x%x/ste:x%x flg:x%x",
3975 did, vport->port_state, ndlp->nlp_flag);
3976
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003977 phba->fc_stat.elsRcvRPS++;
James Smart2e0fef82007-06-17 19:56:36 -05003978 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
James Smart98c9ea52007-10-27 13:37:33 -04003979 if (newnode && (!(ndlp->nlp_flag & NLP_DELAYED_RM)))
3980 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003981 break;
3982 case ELS_CMD_RPL:
James Smart858c9f62007-06-17 19:56:39 -05003983 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3984 "RCV RPL: did:x%x/ste:x%x flg:x%x",
3985 did, vport->port_state, ndlp->nlp_flag);
3986
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003987 phba->fc_stat.elsRcvRPL++;
James Smart2e0fef82007-06-17 19:56:36 -05003988 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
James Smart98c9ea52007-10-27 13:37:33 -04003989 if (newnode && (!(ndlp->nlp_flag & NLP_DELAYED_RM)))
3990 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003991 break;
dea31012005-04-17 16:05:31 -05003992 case ELS_CMD_RNID:
James Smart858c9f62007-06-17 19:56:39 -05003993 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3994 "RCV RNID: did:x%x/ste:x%x flg:x%x",
3995 did, vport->port_state, ndlp->nlp_flag);
3996
dea31012005-04-17 16:05:31 -05003997 phba->fc_stat.elsRcvRNID++;
James Smart2e0fef82007-06-17 19:56:36 -05003998 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
James Smart98c9ea52007-10-27 13:37:33 -04003999 if (newnode && (!(ndlp->nlp_flag & NLP_DELAYED_RM)))
4000 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05004001 break;
4002 default:
James Smart858c9f62007-06-17 19:56:39 -05004003 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4004 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
4005 cmd, did, vport->port_state);
4006
dea31012005-04-17 16:05:31 -05004007 /* Unsupported ELS command, reject */
James Smart858c9f62007-06-17 19:56:39 -05004008 rjt_err = LSRJT_INVALID_CMD;
dea31012005-04-17 16:05:31 -05004009
4010 /* Unknown ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04004011 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4012 "0115 Unknown ELS command x%x "
4013 "received from NPORT x%x\n", cmd, did);
James Smart98c9ea52007-10-27 13:37:33 -04004014 if (newnode && (!(ndlp->nlp_flag & NLP_DELAYED_RM)))
4015 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05004016 break;
4017 }
4018
4019 /* check if need to LS_RJT received ELS cmd */
4020 if (rjt_err) {
James Smart92d7f7b2007-06-17 19:56:38 -05004021 memset(&stat, 0, sizeof(stat));
James Smart858c9f62007-06-17 19:56:39 -05004022 stat.un.b.lsRjtRsnCode = rjt_err;
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04004023 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart858c9f62007-06-17 19:56:39 -05004024 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
4025 NULL);
dea31012005-04-17 16:05:31 -05004026 }
4027
James Smarted957682007-06-17 19:56:37 -05004028 return;
4029
4030dropit:
James Smart98c9ea52007-10-27 13:37:33 -04004031 if (vport && !(vport->load_flag & FC_UNLOADING))
4032 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
James Smarte8b62012007-08-02 11:10:09 -04004033 "(%d):0111 Dropping received ELS cmd "
James Smarted957682007-06-17 19:56:37 -05004034 "Data: x%x x%x x%x\n",
James Smart98c9ea52007-10-27 13:37:33 -04004035 vport->vpi, icmd->ulpStatus,
James Smarte8b62012007-08-02 11:10:09 -04004036 icmd->un.ulpWord[4], icmd->ulpTimeout);
James Smarted957682007-06-17 19:56:37 -05004037 phba->fc_stat.elsRcvDrop++;
4038}
4039
James Smart92d7f7b2007-06-17 19:56:38 -05004040static struct lpfc_vport *
4041lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
4042{
4043 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -04004044 unsigned long flags;
James Smart92d7f7b2007-06-17 19:56:38 -05004045
James Smart549e55c2007-08-02 11:09:51 -04004046 spin_lock_irqsave(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05004047 list_for_each_entry(vport, &phba->port_list, listentry) {
James Smart549e55c2007-08-02 11:09:51 -04004048 if (vport->vpi == vpi) {
4049 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05004050 return vport;
James Smart549e55c2007-08-02 11:09:51 -04004051 }
James Smart92d7f7b2007-06-17 19:56:38 -05004052 }
James Smart549e55c2007-08-02 11:09:51 -04004053 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05004054 return NULL;
4055}
James Smarted957682007-06-17 19:56:37 -05004056
4057void
4058lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
4059 struct lpfc_iocbq *elsiocb)
4060{
4061 struct lpfc_vport *vport = phba->pport;
James Smarted957682007-06-17 19:56:37 -05004062 IOCB_t *icmd = &elsiocb->iocb;
James Smarted957682007-06-17 19:56:37 -05004063 dma_addr_t paddr;
James Smart92d7f7b2007-06-17 19:56:38 -05004064 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
4065 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
James Smarted957682007-06-17 19:56:37 -05004066
James Smart92d7f7b2007-06-17 19:56:38 -05004067 elsiocb->context2 = NULL;
4068 elsiocb->context3 = NULL;
4069
4070 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
4071 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
4072 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
4073 (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) {
James Smarted957682007-06-17 19:56:37 -05004074 phba->fc_stat.NoRcvBuf++;
4075 /* Not enough posted buffers; Try posting more buffers */
James Smart92d7f7b2007-06-17 19:56:38 -05004076 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
James Smarted957682007-06-17 19:56:37 -05004077 lpfc_post_buffer(phba, pring, 0, 1);
4078 return;
4079 }
4080
James Smart92d7f7b2007-06-17 19:56:38 -05004081 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
4082 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
4083 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
4084 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
4085 vport = phba->pport;
4086 else {
4087 uint16_t vpi = icmd->unsli3.rcvsli3.vpi;
4088 vport = lpfc_find_vport_by_vpid(phba, vpi);
4089 }
4090 }
4091 /* If there are no BDEs associated
4092 * with this IOCB, there is nothing to do.
4093 */
James Smarted957682007-06-17 19:56:37 -05004094 if (icmd->ulpBdeCount == 0)
4095 return;
4096
James Smart92d7f7b2007-06-17 19:56:38 -05004097 /* type of ELS cmd is first 32bit word
4098 * in packet
4099 */
James Smarted957682007-06-17 19:56:37 -05004100 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05004101 elsiocb->context2 = bdeBuf1;
James Smarted957682007-06-17 19:56:37 -05004102 } else {
4103 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
4104 icmd->un.cont64[0].addrLow);
James Smart92d7f7b2007-06-17 19:56:38 -05004105 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
4106 paddr);
James Smarted957682007-06-17 19:56:37 -05004107 }
4108
James Smart92d7f7b2007-06-17 19:56:38 -05004109 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
4110 /*
4111 * The different unsolicited event handlers would tell us
4112 * if they are done with "mp" by setting context2 to NULL.
4113 */
James Smart329f9bc2007-04-25 09:53:01 -04004114 lpfc_nlp_put(elsiocb->context1);
4115 elsiocb->context1 = NULL;
dea31012005-04-17 16:05:31 -05004116 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05004117 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
4118 elsiocb->context2 = NULL;
dea31012005-04-17 16:05:31 -05004119 }
James Smarted957682007-06-17 19:56:37 -05004120
4121 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
James Smart92d7f7b2007-06-17 19:56:38 -05004122 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
James Smarted957682007-06-17 19:56:37 -05004123 icmd->ulpBdeCount == 2) {
James Smart92d7f7b2007-06-17 19:56:38 -05004124 elsiocb->context2 = bdeBuf2;
4125 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
James Smarted957682007-06-17 19:56:37 -05004126 /* free mp if we are done with it */
4127 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05004128 lpfc_in_buf_free(phba, elsiocb->context2);
4129 elsiocb->context2 = NULL;
James Smarted957682007-06-17 19:56:37 -05004130 }
dea31012005-04-17 16:05:31 -05004131 }
dea31012005-04-17 16:05:31 -05004132}
James Smart92d7f7b2007-06-17 19:56:38 -05004133
4134void
4135lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
4136{
4137 struct lpfc_nodelist *ndlp, *ndlp_fdmi;
4138
4139 ndlp = lpfc_findnode_did(vport, NameServer_DID);
4140 if (!ndlp) {
4141 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
4142 if (!ndlp) {
4143 if (phba->fc_topology == TOPOLOGY_LOOP) {
4144 lpfc_disc_start(vport);
4145 return;
4146 }
4147 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04004148 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4149 "0251 NameServer login: no memory\n");
James Smart92d7f7b2007-06-17 19:56:38 -05004150 return;
4151 }
4152 lpfc_nlp_init(vport, ndlp, NameServer_DID);
4153 ndlp->nlp_type |= NLP_FABRIC;
4154 }
4155
4156 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
4157
4158 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
4159 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04004160 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4161 "0252 Cannot issue NameServer login\n");
James Smart92d7f7b2007-06-17 19:56:38 -05004162 return;
4163 }
4164
James Smart3de2a652007-08-02 11:09:59 -04004165 if (vport->cfg_fdmi_on) {
James Smart92d7f7b2007-06-17 19:56:38 -05004166 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
4167 GFP_KERNEL);
4168 if (ndlp_fdmi) {
4169 lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
4170 ndlp_fdmi->nlp_type |= NLP_FABRIC;
4171 ndlp_fdmi->nlp_state =
4172 NLP_STE_PLOGI_ISSUE;
4173 lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID,
4174 0);
4175 }
4176 }
4177 return;
4178}
4179
4180static void
4181lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4182{
4183 struct lpfc_vport *vport = pmb->vport;
4184 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4185 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
4186 MAILBOX_t *mb = &pmb->mb;
4187
4188 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
4189 lpfc_nlp_put(ndlp);
4190
4191 if (mb->mbxStatus) {
James Smarte8b62012007-08-02 11:10:09 -04004192 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
4193 "0915 Register VPI failed: 0x%x\n",
4194 mb->mbxStatus);
James Smart92d7f7b2007-06-17 19:56:38 -05004195
4196 switch (mb->mbxStatus) {
4197 case 0x11: /* unsupported feature */
4198 case 0x9603: /* max_vpi exceeded */
4199 /* giving up on vport registration */
4200 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4201 spin_lock_irq(shost->host_lock);
4202 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
4203 spin_unlock_irq(shost->host_lock);
4204 lpfc_can_disctmo(vport);
4205 break;
4206 default:
4207 /* Try to recover from this error */
4208 lpfc_mbx_unreg_vpi(vport);
4209 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
4210 lpfc_initial_fdisc(vport);
4211 break;
4212 }
4213
4214 } else {
4215 if (vport == phba->pport)
4216 lpfc_issue_fabric_reglogin(vport);
4217 else
4218 lpfc_do_scr_ns_plogi(phba, vport);
4219 }
4220 mempool_free(pmb, phba->mbox_mem_pool);
4221 return;
4222}
4223
4224void
4225lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
4226 struct lpfc_nodelist *ndlp)
4227{
4228 LPFC_MBOXQ_t *mbox;
4229
4230 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4231 if (mbox) {
4232 lpfc_reg_vpi(phba, vport->vpi, vport->fc_myDID, mbox);
4233 mbox->vport = vport;
4234 mbox->context2 = lpfc_nlp_get(ndlp);
4235 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
James Smart0b727fe2007-10-27 13:37:25 -04004236 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart92d7f7b2007-06-17 19:56:38 -05004237 == MBX_NOT_FINISHED) {
4238 mempool_free(mbox, phba->mbox_mem_pool);
4239 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
4240
4241 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04004242 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
4243 "0253 Register VPI: Can't send mbox\n");
James Smart92d7f7b2007-06-17 19:56:38 -05004244 }
4245 } else {
4246 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4247
James Smarte8b62012007-08-02 11:10:09 -04004248 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
4249 "0254 Register VPI: no memory\n");
James Smart92d7f7b2007-06-17 19:56:38 -05004250
4251 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
4252 lpfc_nlp_put(ndlp);
4253 }
4254}
4255
4256static void
4257lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4258 struct lpfc_iocbq *rspiocb)
4259{
4260 struct lpfc_vport *vport = cmdiocb->vport;
4261 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4262 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
4263 struct lpfc_nodelist *np;
4264 struct lpfc_nodelist *next_np;
4265 IOCB_t *irsp = &rspiocb->iocb;
4266 struct lpfc_iocbq *piocb;
4267
James Smarte8b62012007-08-02 11:10:09 -04004268 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4269 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
4270 irsp->ulpStatus, irsp->un.ulpWord[4],
4271 vport->fc_prevDID);
James Smart92d7f7b2007-06-17 19:56:38 -05004272 /* Since all FDISCs are being single threaded, we
4273 * must reset the discovery timer for ALL vports
4274 * waiting to send FDISC when one completes.
4275 */
4276 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
4277 lpfc_set_disctmo(piocb->vport);
4278 }
4279
James Smart858c9f62007-06-17 19:56:39 -05004280 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4281 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
4282 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
4283
James Smart92d7f7b2007-06-17 19:56:38 -05004284 if (irsp->ulpStatus) {
4285 /* Check for retry */
4286 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
4287 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05004288 /* FDISC failed */
James Smarte8b62012007-08-02 11:10:09 -04004289 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4290 "0124 FDISC failed. (%d/%d)\n",
4291 irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smart92d7f7b2007-06-17 19:56:38 -05004292 if (vport->fc_vport->vport_state == FC_VPORT_INITIALIZING)
4293 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4294
4295 lpfc_nlp_put(ndlp);
4296 /* giving up on FDISC. Cancel discovery timer */
4297 lpfc_can_disctmo(vport);
4298 } else {
4299 spin_lock_irq(shost->host_lock);
4300 vport->fc_flag |= FC_FABRIC;
4301 if (vport->phba->fc_topology == TOPOLOGY_LOOP)
4302 vport->fc_flag |= FC_PUBLIC_LOOP;
4303 spin_unlock_irq(shost->host_lock);
4304
4305 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
4306 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
4307 if ((vport->fc_prevDID != vport->fc_myDID) &&
4308 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
4309 /* If our NportID changed, we need to ensure all
4310 * remaining NPORTs get unreg_login'ed so we can
4311 * issue unreg_vpi.
4312 */
4313 list_for_each_entry_safe(np, next_np,
4314 &vport->fc_nodes, nlp_listp) {
4315 if (np->nlp_state != NLP_STE_NPR_NODE
4316 || !(np->nlp_flag & NLP_NPR_ADISC))
4317 continue;
4318 spin_lock_irq(shost->host_lock);
4319 np->nlp_flag &= ~NLP_NPR_ADISC;
4320 spin_unlock_irq(shost->host_lock);
4321 lpfc_unreg_rpi(vport, np);
4322 }
4323 lpfc_mbx_unreg_vpi(vport);
4324 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
4325 }
4326
4327 if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
4328 lpfc_register_new_vport(phba, vport, ndlp);
4329 else
4330 lpfc_do_scr_ns_plogi(phba, vport);
4331
4332 lpfc_nlp_put(ndlp); /* Free Fabric ndlp for vports */
4333 }
4334
4335out:
4336 lpfc_els_free_iocb(phba, cmdiocb);
4337}
4338
4339int
4340lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4341 uint8_t retry)
4342{
4343 struct lpfc_hba *phba = vport->phba;
4344 IOCB_t *icmd;
4345 struct lpfc_iocbq *elsiocb;
4346 struct serv_parm *sp;
4347 uint8_t *pcmd;
4348 uint16_t cmdsize;
4349 int did = ndlp->nlp_DID;
4350 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05004351
4352 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
4353 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
4354 ELS_CMD_FDISC);
4355 if (!elsiocb) {
James Smart92d7f7b2007-06-17 19:56:38 -05004356 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04004357 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4358 "0255 Issue FDISC: no IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05004359 return 1;
4360 }
4361
4362 icmd = &elsiocb->iocb;
4363 icmd->un.elsreq64.myID = 0;
4364 icmd->un.elsreq64.fl = 1;
4365
4366 /* For FDISC, Let FDISC rsp set the NPortID for this VPI */
4367 icmd->ulpCt_h = 1;
4368 icmd->ulpCt_l = 0;
4369
4370 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4371 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
4372 pcmd += sizeof(uint32_t); /* CSP Word 1 */
4373 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
4374 sp = (struct serv_parm *) pcmd;
4375 /* Setup CSPs accordingly for Fabric */
4376 sp->cmn.e_d_tov = 0;
4377 sp->cmn.w2.r_a_tov = 0;
4378 sp->cls1.classValid = 0;
4379 sp->cls2.seqDelivery = 1;
4380 sp->cls3.seqDelivery = 1;
4381
4382 pcmd += sizeof(uint32_t); /* CSP Word 2 */
4383 pcmd += sizeof(uint32_t); /* CSP Word 3 */
4384 pcmd += sizeof(uint32_t); /* CSP Word 4 */
4385 pcmd += sizeof(uint32_t); /* Port Name */
4386 memcpy(pcmd, &vport->fc_portname, 8);
4387 pcmd += sizeof(uint32_t); /* Node Name */
4388 pcmd += sizeof(uint32_t); /* Node Name */
4389 memcpy(pcmd, &vport->fc_nodename, 8);
4390
4391 lpfc_set_disctmo(vport);
4392
4393 phba->fc_stat.elsXmitFDISC++;
4394 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
4395
James Smart858c9f62007-06-17 19:56:39 -05004396 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4397 "Issue FDISC: did:x%x",
4398 did, 0, 0);
4399
James Smart92d7f7b2007-06-17 19:56:38 -05004400 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
4401 if (rc == IOCB_ERROR) {
4402 lpfc_els_free_iocb(phba, elsiocb);
James Smart92d7f7b2007-06-17 19:56:38 -05004403 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04004404 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4405 "0256 Issue FDISC: Cannot send IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05004406 return 1;
4407 }
4408 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
4409 vport->port_state = LPFC_FDISC;
4410 return 0;
4411}
4412
4413static void
4414lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4415 struct lpfc_iocbq *rspiocb)
4416{
4417 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05004418 IOCB_t *irsp;
4419
4420 irsp = &rspiocb->iocb;
4421 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4422 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
4423 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
James Smart92d7f7b2007-06-17 19:56:38 -05004424
4425 lpfc_els_free_iocb(phba, cmdiocb);
4426 vport->unreg_vpi_cmpl = VPORT_ERROR;
4427}
4428
4429int
4430lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4431{
4432 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4433 struct lpfc_hba *phba = vport->phba;
4434 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
4435 IOCB_t *icmd;
4436 struct lpfc_iocbq *elsiocb;
4437 uint8_t *pcmd;
4438 uint16_t cmdsize;
4439
4440 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
4441 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
4442 ELS_CMD_LOGO);
4443 if (!elsiocb)
4444 return 1;
4445
4446 icmd = &elsiocb->iocb;
4447 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4448 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
4449 pcmd += sizeof(uint32_t);
4450
4451 /* Fill in LOGO payload */
4452 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
4453 pcmd += sizeof(uint32_t);
4454 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
4455
James Smart858c9f62007-06-17 19:56:39 -05004456 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4457 "Issue LOGO npiv did:x%x flg:x%x",
4458 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4459
James Smart92d7f7b2007-06-17 19:56:38 -05004460 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
4461 spin_lock_irq(shost->host_lock);
4462 ndlp->nlp_flag |= NLP_LOGO_SND;
4463 spin_unlock_irq(shost->host_lock);
4464 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
4465 spin_lock_irq(shost->host_lock);
4466 ndlp->nlp_flag &= ~NLP_LOGO_SND;
4467 spin_unlock_irq(shost->host_lock);
4468 lpfc_els_free_iocb(phba, elsiocb);
4469 return 1;
4470 }
4471 return 0;
4472}
4473
4474void
4475lpfc_fabric_block_timeout(unsigned long ptr)
4476{
4477 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
4478 unsigned long iflags;
4479 uint32_t tmo_posted;
4480 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
4481 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
4482 if (!tmo_posted)
4483 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
4484 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
4485
4486 if (!tmo_posted) {
4487 spin_lock_irqsave(&phba->hbalock, iflags);
4488 if (phba->work_wait)
4489 lpfc_worker_wake_up(phba);
4490 spin_unlock_irqrestore(&phba->hbalock, iflags);
4491 }
4492}
4493
4494static void
4495lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
4496{
4497 struct lpfc_iocbq *iocb;
4498 unsigned long iflags;
4499 int ret;
4500 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
4501 IOCB_t *cmd;
4502
4503repeat:
4504 iocb = NULL;
4505 spin_lock_irqsave(&phba->hbalock, iflags);
4506 /* Post any pending iocb to the SLI layer */
4507 if (atomic_read(&phba->fabric_iocb_count) == 0) {
4508 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
4509 list);
4510 if (iocb)
4511 atomic_inc(&phba->fabric_iocb_count);
4512 }
4513 spin_unlock_irqrestore(&phba->hbalock, iflags);
4514 if (iocb) {
4515 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
4516 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
4517 iocb->iocb_flag |= LPFC_IO_FABRIC;
4518
James Smart858c9f62007-06-17 19:56:39 -05004519 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
4520 "Fabric sched1: ste:x%x",
4521 iocb->vport->port_state, 0, 0);
4522
James Smart92d7f7b2007-06-17 19:56:38 -05004523 ret = lpfc_sli_issue_iocb(phba, pring, iocb, 0);
4524
4525 if (ret == IOCB_ERROR) {
4526 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
4527 iocb->fabric_iocb_cmpl = NULL;
4528 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
4529 cmd = &iocb->iocb;
4530 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
4531 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
4532 iocb->iocb_cmpl(phba, iocb, iocb);
4533
4534 atomic_dec(&phba->fabric_iocb_count);
4535 goto repeat;
4536 }
4537 }
4538
4539 return;
4540}
4541
4542void
4543lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
4544{
4545 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
4546
4547 lpfc_resume_fabric_iocbs(phba);
4548 return;
4549}
4550
4551static void
4552lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
4553{
4554 int blocked;
4555
4556 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
4557 /* Start a timer to unblock fabric
4558 * iocbs after 100ms
4559 */
4560 if (!blocked)
4561 mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 );
4562
4563 return;
4564}
4565
4566static void
4567lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4568 struct lpfc_iocbq *rspiocb)
4569{
4570 struct ls_rjt stat;
4571
4572 if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
4573 BUG();
4574
4575 switch (rspiocb->iocb.ulpStatus) {
4576 case IOSTAT_NPORT_RJT:
4577 case IOSTAT_FABRIC_RJT:
4578 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
4579 lpfc_block_fabric_iocbs(phba);
4580 }
4581 break;
4582
4583 case IOSTAT_NPORT_BSY:
4584 case IOSTAT_FABRIC_BSY:
4585 lpfc_block_fabric_iocbs(phba);
4586 break;
4587
4588 case IOSTAT_LS_RJT:
4589 stat.un.lsRjtError =
4590 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
4591 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
4592 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
4593 lpfc_block_fabric_iocbs(phba);
4594 break;
4595 }
4596
4597 if (atomic_read(&phba->fabric_iocb_count) == 0)
4598 BUG();
4599
4600 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
4601 cmdiocb->fabric_iocb_cmpl = NULL;
4602 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
4603 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
4604
4605 atomic_dec(&phba->fabric_iocb_count);
4606 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
4607 /* Post any pending iocbs to HBA */
4608 lpfc_resume_fabric_iocbs(phba);
4609 }
4610}
4611
4612int
4613lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
4614{
4615 unsigned long iflags;
4616 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
4617 int ready;
4618 int ret;
4619
4620 if (atomic_read(&phba->fabric_iocb_count) > 1)
4621 BUG();
4622
4623 spin_lock_irqsave(&phba->hbalock, iflags);
4624 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
4625 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
4626
4627 spin_unlock_irqrestore(&phba->hbalock, iflags);
4628 if (ready) {
4629 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
4630 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
4631 iocb->iocb_flag |= LPFC_IO_FABRIC;
4632
James Smart858c9f62007-06-17 19:56:39 -05004633 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
4634 "Fabric sched2: ste:x%x",
4635 iocb->vport->port_state, 0, 0);
4636
James Smart92d7f7b2007-06-17 19:56:38 -05004637 atomic_inc(&phba->fabric_iocb_count);
4638 ret = lpfc_sli_issue_iocb(phba, pring, iocb, 0);
4639
4640 if (ret == IOCB_ERROR) {
4641 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
4642 iocb->fabric_iocb_cmpl = NULL;
4643 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
4644 atomic_dec(&phba->fabric_iocb_count);
4645 }
4646 } else {
4647 spin_lock_irqsave(&phba->hbalock, iflags);
4648 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
4649 spin_unlock_irqrestore(&phba->hbalock, iflags);
4650 ret = IOCB_SUCCESS;
4651 }
4652 return ret;
4653}
4654
4655
4656void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
4657{
4658 LIST_HEAD(completions);
4659 struct lpfc_hba *phba = vport->phba;
4660 struct lpfc_iocbq *tmp_iocb, *piocb;
4661 IOCB_t *cmd;
4662
4663 spin_lock_irq(&phba->hbalock);
4664 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
4665 list) {
4666
4667 if (piocb->vport != vport)
4668 continue;
4669
4670 list_move_tail(&piocb->list, &completions);
4671 }
4672 spin_unlock_irq(&phba->hbalock);
4673
4674 while (!list_empty(&completions)) {
4675 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
4676 list_del_init(&piocb->list);
4677
4678 cmd = &piocb->iocb;
4679 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
4680 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
4681 (piocb->iocb_cmpl) (phba, piocb, piocb);
4682 }
4683}
4684
4685void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
4686{
4687 LIST_HEAD(completions);
4688 struct lpfc_hba *phba = ndlp->vport->phba;
4689 struct lpfc_iocbq *tmp_iocb, *piocb;
4690 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
4691 IOCB_t *cmd;
4692
4693 spin_lock_irq(&phba->hbalock);
4694 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
4695 list) {
4696 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
4697
4698 list_move_tail(&piocb->list, &completions);
4699 }
4700 }
4701 spin_unlock_irq(&phba->hbalock);
4702
4703 while (!list_empty(&completions)) {
4704 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
4705 list_del_init(&piocb->list);
4706
4707 cmd = &piocb->iocb;
4708 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
4709 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
4710 (piocb->iocb_cmpl) (phba, piocb, piocb);
4711 }
4712}
4713
4714void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
4715{
4716 LIST_HEAD(completions);
4717 struct lpfc_iocbq *piocb;
4718 IOCB_t *cmd;
4719
4720 spin_lock_irq(&phba->hbalock);
4721 list_splice_init(&phba->fabric_iocb_list, &completions);
4722 spin_unlock_irq(&phba->hbalock);
4723
4724 while (!list_empty(&completions)) {
4725 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
4726 list_del_init(&piocb->list);
4727
4728 cmd = &piocb->iocb;
4729 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
4730 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
4731 (piocb->iocb_cmpl) (phba, piocb, piocb);
4732 }
4733}
4734
4735
4736void lpfc_fabric_abort_flogi(struct lpfc_hba *phba)
4737{
4738 LIST_HEAD(completions);
4739 struct lpfc_iocbq *tmp_iocb, *piocb;
4740 IOCB_t *cmd;
4741 struct lpfc_nodelist *ndlp;
4742
4743 spin_lock_irq(&phba->hbalock);
4744 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
4745 list) {
4746
4747 cmd = &piocb->iocb;
4748 ndlp = (struct lpfc_nodelist *) piocb->context1;
4749 if (cmd->ulpCommand == CMD_ELS_REQUEST64_CR &&
4750 ndlp != NULL &&
4751 ndlp->nlp_DID == Fabric_DID)
4752 list_move_tail(&piocb->list, &completions);
4753 }
4754 spin_unlock_irq(&phba->hbalock);
4755
4756 while (!list_empty(&completions)) {
4757 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
4758 list_del_init(&piocb->list);
4759
4760 cmd = &piocb->iocb;
4761 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
4762 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
4763 (piocb->iocb_cmpl) (phba, piocb, piocb);
4764 }
4765}
4766
4767