blob: 0a5006ea99099ba0c6c20ca60144f0b359af26dd [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);
James Smart87af33f2007-10-27 13:37:43 -0400578 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
579 ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) &&
580 (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) &&
581 (phba->link_state != LPFC_CLEAR_LA)) {
582 /* If FLOGI failed enable link interrupt. */
583 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -0500584 }
dea31012005-04-17 16:05:31 -0500585out:
586 lpfc_els_free_iocb(phba, cmdiocb);
587}
588
589static int
James Smart2e0fef82007-06-17 19:56:36 -0500590lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -0500591 uint8_t retry)
592{
James Smart2e0fef82007-06-17 19:56:36 -0500593 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500594 struct serv_parm *sp;
595 IOCB_t *icmd;
596 struct lpfc_iocbq *elsiocb;
597 struct lpfc_sli_ring *pring;
598 uint8_t *pcmd;
599 uint16_t cmdsize;
600 uint32_t tmo;
601 int rc;
602
603 pring = &phba->sli.ring[LPFC_ELS_RING];
604
James Smart92d7f7b2007-06-17 19:56:38 -0500605 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart2e0fef82007-06-17 19:56:36 -0500606 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
607 ndlp->nlp_DID, ELS_CMD_FLOGI);
James Smart92d7f7b2007-06-17 19:56:38 -0500608
James Smart488d1462006-03-07 15:02:37 -0500609 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500610 return 1;
dea31012005-04-17 16:05:31 -0500611
612 icmd = &elsiocb->iocb;
613 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
614
615 /* For FLOGI request, remainder of payload is service parameters */
616 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -0500617 pcmd += sizeof(uint32_t);
618 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -0500619 sp = (struct serv_parm *) pcmd;
620
621 /* Setup CSPs accordingly for Fabric */
622 sp->cmn.e_d_tov = 0;
623 sp->cmn.w2.r_a_tov = 0;
624 sp->cls1.classValid = 0;
625 sp->cls2.seqDelivery = 1;
626 sp->cls3.seqDelivery = 1;
627 if (sp->cmn.fcphLow < FC_PH3)
628 sp->cmn.fcphLow = FC_PH3;
629 if (sp->cmn.fcphHigh < FC_PH3)
630 sp->cmn.fcphHigh = FC_PH3;
631
James Smart92d7f7b2007-06-17 19:56:38 -0500632 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
633 sp->cmn.request_multiple_Nport = 1;
634
635 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
636 icmd->ulpCt_h = 1;
637 icmd->ulpCt_l = 0;
638 }
639
James Smart858c9f62007-06-17 19:56:39 -0500640 if (phba->fc_topology != TOPOLOGY_LOOP) {
641 icmd->un.elsreq64.myID = 0;
642 icmd->un.elsreq64.fl = 1;
643 }
644
dea31012005-04-17 16:05:31 -0500645 tmo = phba->fc_ratov;
646 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
James Smart2e0fef82007-06-17 19:56:36 -0500647 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -0500648 phba->fc_ratov = tmo;
649
650 phba->fc_stat.elsXmitFLOGI++;
651 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
James Smart858c9f62007-06-17 19:56:39 -0500652
653 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
654 "Issue FLOGI: opt:x%x",
655 phba->sli3_options, 0, 0);
656
James Smart92d7f7b2007-06-17 19:56:38 -0500657 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
dea31012005-04-17 16:05:31 -0500658 if (rc == IOCB_ERROR) {
659 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500660 return 1;
dea31012005-04-17 16:05:31 -0500661 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500662 return 0;
dea31012005-04-17 16:05:31 -0500663}
664
665int
James Smart2e0fef82007-06-17 19:56:36 -0500666lpfc_els_abort_flogi(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500667{
668 struct lpfc_sli_ring *pring;
669 struct lpfc_iocbq *iocb, *next_iocb;
670 struct lpfc_nodelist *ndlp;
671 IOCB_t *icmd;
672
673 /* Abort outstanding I/O on NPort <nlp_DID> */
674 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -0400675 "0201 Abort outstanding I/O on NPort x%x\n",
676 Fabric_DID);
dea31012005-04-17 16:05:31 -0500677
678 pring = &phba->sli.ring[LPFC_ELS_RING];
679
680 /*
681 * Check the txcmplq for an iocb that matches the nport the driver is
682 * searching for.
683 */
James Smart2e0fef82007-06-17 19:56:36 -0500684 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500685 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
686 icmd = &iocb->iocb;
James Smart2e0fef82007-06-17 19:56:36 -0500687 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR &&
688 icmd->un.elsreq64.bdl.ulpIoTag32) {
dea31012005-04-17 16:05:31 -0500689 ndlp = (struct lpfc_nodelist *)(iocb->context1);
James Smart92d7f7b2007-06-17 19:56:38 -0500690 if (ndlp && (ndlp->nlp_DID == Fabric_DID)) {
James Smart07951072007-04-25 09:51:38 -0400691 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
James Smart92d7f7b2007-06-17 19:56:38 -0500692 }
dea31012005-04-17 16:05:31 -0500693 }
694 }
James Smart2e0fef82007-06-17 19:56:36 -0500695 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500696
697 return 0;
698}
699
700int
James Smart2e0fef82007-06-17 19:56:36 -0500701lpfc_initial_flogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -0500702{
James Smart2e0fef82007-06-17 19:56:36 -0500703 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500704 struct lpfc_nodelist *ndlp;
705
James Smart98c9ea52007-10-27 13:37:33 -0400706 vport->port_state = LPFC_FLOGI;
707 lpfc_set_disctmo(vport);
708
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500709 /* First look for the Fabric ndlp */
James Smart2e0fef82007-06-17 19:56:36 -0500710 ndlp = lpfc_findnode_did(vport, Fabric_DID);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500711 if (!ndlp) {
dea31012005-04-17 16:05:31 -0500712 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500713 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
714 if (!ndlp)
715 return 0;
James Smart2e0fef82007-06-17 19:56:36 -0500716 lpfc_nlp_init(vport, ndlp, Fabric_DID);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500717 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500718 lpfc_dequeue_node(vport, ndlp);
dea31012005-04-17 16:05:31 -0500719 }
James Smart87af33f2007-10-27 13:37:43 -0400720
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}
James Smart87af33f2007-10-27 13:37:43 -0400749
750void
James Smart2e0fef82007-06-17 19:56:36 -0500751lpfc_more_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -0500752{
753 int sentplogi;
754
James Smart2e0fef82007-06-17 19:56:36 -0500755 if (vport->num_disc_nodes)
756 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -0500757
758 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
James Smarte8b62012007-08-02 11:10:09 -0400759 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
760 "0232 Continue discovery with %d PLOGIs to go "
761 "Data: x%x x%x x%x\n",
762 vport->num_disc_nodes, vport->fc_plogi_cnt,
763 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -0500764 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -0500765 if (vport->fc_flag & FC_NLP_MORE)
766 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
767 sentplogi = lpfc_els_disc_plogi(vport);
768
dea31012005-04-17 16:05:31 -0500769 return;
770}
771
James Smart488d1462006-03-07 15:02:37 -0500772static struct lpfc_nodelist *
James Smart92d7f7b2007-06-17 19:56:38 -0500773lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
James Smart488d1462006-03-07 15:02:37 -0500774 struct lpfc_nodelist *ndlp)
775{
James Smart2e0fef82007-06-17 19:56:36 -0500776 struct lpfc_vport *vport = ndlp->vport;
James Smart488d1462006-03-07 15:02:37 -0500777 struct lpfc_nodelist *new_ndlp;
James Smart488d1462006-03-07 15:02:37 -0500778 struct serv_parm *sp;
James Smart92d7f7b2007-06-17 19:56:38 -0500779 uint8_t name[sizeof(struct lpfc_name)];
James Smart488d1462006-03-07 15:02:37 -0500780 uint32_t rc;
781
James Smart2fb9bd82006-12-02 13:33:57 -0500782 /* Fabric nodes can have the same WWPN so we don't bother searching
783 * by WWPN. Just return the ndlp that was given to us.
784 */
785 if (ndlp->nlp_type & NLP_FABRIC)
786 return ndlp;
787
James Smart92d7f7b2007-06-17 19:56:38 -0500788 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
James Smart685f0bf2007-04-25 09:53:08 -0400789 memset(name, 0, sizeof(struct lpfc_name));
James Smart488d1462006-03-07 15:02:37 -0500790
James Smart685f0bf2007-04-25 09:53:08 -0400791 /* Now we find out if the NPort we are logging into, matches the WWPN
James Smart488d1462006-03-07 15:02:37 -0500792 * we have for that ndlp. If not, we have some work to do.
793 */
James Smart2e0fef82007-06-17 19:56:36 -0500794 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
James Smart488d1462006-03-07 15:02:37 -0500795
James Smart92795652006-07-06 15:50:02 -0400796 if (new_ndlp == ndlp)
James Smart488d1462006-03-07 15:02:37 -0500797 return ndlp;
James Smart488d1462006-03-07 15:02:37 -0500798
799 if (!new_ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -0500800 rc = memcmp(&ndlp->nlp_portname, name,
801 sizeof(struct lpfc_name));
James Smart92795652006-07-06 15:50:02 -0400802 if (!rc)
803 return ndlp;
James Smart488d1462006-03-07 15:02:37 -0500804 new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
805 if (!new_ndlp)
806 return ndlp;
807
James Smart2e0fef82007-06-17 19:56:36 -0500808 lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID);
James Smart488d1462006-03-07 15:02:37 -0500809 }
810
James Smart2e0fef82007-06-17 19:56:36 -0500811 lpfc_unreg_rpi(vport, new_ndlp);
James Smart488d1462006-03-07 15:02:37 -0500812 new_ndlp->nlp_DID = ndlp->nlp_DID;
James Smart92795652006-07-06 15:50:02 -0400813 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
James Smart2e0fef82007-06-17 19:56:36 -0500814 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
James Smart488d1462006-03-07 15:02:37 -0500815
James Smart2e0fef82007-06-17 19:56:36 -0500816 /* Move this back to NPR state */
James Smart87af33f2007-10-27 13:37:43 -0400817 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
818 /* The new_ndlp is replacing ndlp totally, so we need
819 * to put ndlp on UNUSED list and try to free it.
820 */
James Smart2e0fef82007-06-17 19:56:36 -0500821 lpfc_drop_node(vport, ndlp);
James Smart87af33f2007-10-27 13:37:43 -0400822 }
James Smart92795652006-07-06 15:50:02 -0400823 else {
James Smart2e0fef82007-06-17 19:56:36 -0500824 lpfc_unreg_rpi(vport, ndlp);
James Smart92795652006-07-06 15:50:02 -0400825 ndlp->nlp_DID = 0; /* Two ndlps cannot have the same did */
James Smart2e0fef82007-06-17 19:56:36 -0500826 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smart92795652006-07-06 15:50:02 -0400827 }
James Smart488d1462006-03-07 15:02:37 -0500828 return new_ndlp;
829}
830
James Smart87af33f2007-10-27 13:37:43 -0400831void
832lpfc_end_rscn(struct lpfc_vport *vport)
833{
834 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
835
836 if (vport->fc_flag & FC_RSCN_MODE) {
837 /*
838 * Check to see if more RSCNs came in while we were
839 * processing this one.
840 */
841 if (vport->fc_rscn_id_cnt ||
842 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
843 lpfc_els_handle_rscn(vport);
844 else {
845 spin_lock_irq(shost->host_lock);
846 vport->fc_flag &= ~FC_RSCN_MODE;
847 spin_unlock_irq(shost->host_lock);
848 }
849 }
850}
851
dea31012005-04-17 16:05:31 -0500852static void
James Smart2e0fef82007-06-17 19:56:36 -0500853lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
854 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500855{
James Smart2e0fef82007-06-17 19:56:36 -0500856 struct lpfc_vport *vport = cmdiocb->vport;
857 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500858 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -0500859 struct lpfc_nodelist *ndlp;
James Smart92795652006-07-06 15:50:02 -0400860 struct lpfc_dmabuf *prsp;
dea31012005-04-17 16:05:31 -0500861 int disc, rc, did, type;
862
dea31012005-04-17 16:05:31 -0500863 /* we pass cmdiocb to state machine which needs rspiocb as well */
864 cmdiocb->context_un.rsp_iocb = rspiocb;
865
866 irsp = &rspiocb->iocb;
James Smart858c9f62007-06-17 19:56:39 -0500867 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
868 "PLOGI cmpl: status:x%x/x%x did:x%x",
869 irsp->ulpStatus, irsp->un.ulpWord[4],
870 irsp->un.elsreq64.remoteID);
871
James Smart2e0fef82007-06-17 19:56:36 -0500872 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
James Smarted957682007-06-17 19:56:37 -0500873 if (!ndlp) {
James Smarte8b62012007-08-02 11:10:09 -0400874 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
875 "0136 PLOGI completes to NPort x%x "
876 "with no ndlp. Data: x%x x%x x%x\n",
877 irsp->un.elsreq64.remoteID,
878 irsp->ulpStatus, irsp->un.ulpWord[4],
879 irsp->ulpIoTag);
James Smart488d1462006-03-07 15:02:37 -0500880 goto out;
James Smarted957682007-06-17 19:56:37 -0500881 }
dea31012005-04-17 16:05:31 -0500882
883 /* Since ndlp can be freed in the disc state machine, note if this node
884 * is being used during discovery.
885 */
James Smart2e0fef82007-06-17 19:56:36 -0500886 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500887 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
James Smart488d1462006-03-07 15:02:37 -0500888 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500889 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500890 rc = 0;
891
892 /* PLOGI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -0400893 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
894 "0102 PLOGI completes to NPort x%x "
895 "Data: x%x x%x x%x x%x x%x\n",
896 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
897 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -0500898 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500899 if (lpfc_els_chk_latt(vport)) {
900 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500901 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500902 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500903 goto out;
904 }
905
906 /* ndlp could be freed in DSM, save these values now */
907 type = ndlp->nlp_type;
908 did = ndlp->nlp_DID;
909
910 if (irsp->ulpStatus) {
911 /* Check for retry */
912 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
913 /* ELS command is being retried */
914 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -0500915 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500916 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500917 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500918 }
919 goto out;
920 }
dea31012005-04-17 16:05:31 -0500921 /* PLOGI failed */
922 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart858c9f62007-06-17 19:56:39 -0500923 if (lpfc_error_lost_link(irsp)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500924 rc = NLP_STE_FREED_NODE;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500925 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500926 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -0500927 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -0500928 }
929 } else {
930 /* Good status, call state machine */
James Smart92795652006-07-06 15:50:02 -0400931 prsp = list_entry(((struct lpfc_dmabuf *)
James Smart92d7f7b2007-06-17 19:56:38 -0500932 cmdiocb->context2)->list.next,
933 struct lpfc_dmabuf, list);
934 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -0500935 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -0500936 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -0500937 }
938
James Smart2e0fef82007-06-17 19:56:36 -0500939 if (disc && vport->num_disc_nodes) {
dea31012005-04-17 16:05:31 -0500940 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -0500941 lpfc_more_plogi(vport);
dea31012005-04-17 16:05:31 -0500942
James Smart2e0fef82007-06-17 19:56:36 -0500943 if (vport->num_disc_nodes == 0) {
944 spin_lock_irq(shost->host_lock);
945 vport->fc_flag &= ~FC_NDISC_ACTIVE;
946 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500947
James Smart2e0fef82007-06-17 19:56:36 -0500948 lpfc_can_disctmo(vport);
James Smart87af33f2007-10-27 13:37:43 -0400949 lpfc_end_rscn(vport);
dea31012005-04-17 16:05:31 -0500950 }
951 }
952
953out:
954 lpfc_els_free_iocb(phba, cmdiocb);
955 return;
956}
957
958int
James Smart2e0fef82007-06-17 19:56:36 -0500959lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
dea31012005-04-17 16:05:31 -0500960{
James Smart2e0fef82007-06-17 19:56:36 -0500961 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500962 struct serv_parm *sp;
963 IOCB_t *icmd;
James Smart98c9ea52007-10-27 13:37:33 -0400964 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -0500965 struct lpfc_iocbq *elsiocb;
966 struct lpfc_sli_ring *pring;
967 struct lpfc_sli *psli;
968 uint8_t *pcmd;
969 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -0500970 int ret;
dea31012005-04-17 16:05:31 -0500971
972 psli = &phba->sli;
973 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
974
James Smart98c9ea52007-10-27 13:37:33 -0400975 ndlp = lpfc_findnode_did(vport, did);
976 /* If ndlp if not NULL, we will bump the reference count on it */
977
James Smart92d7f7b2007-06-17 19:56:38 -0500978 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart98c9ea52007-10-27 13:37:33 -0400979 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
James Smart2e0fef82007-06-17 19:56:36 -0500980 ELS_CMD_PLOGI);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500981 if (!elsiocb)
982 return 1;
dea31012005-04-17 16:05:31 -0500983
984 icmd = &elsiocb->iocb;
985 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
986
987 /* For PLOGI request, remainder of payload is service parameters */
988 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -0500989 pcmd += sizeof(uint32_t);
990 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -0500991 sp = (struct serv_parm *) pcmd;
992
993 if (sp->cmn.fcphLow < FC_PH_4_3)
994 sp->cmn.fcphLow = FC_PH_4_3;
995
996 if (sp->cmn.fcphHigh < FC_PH3)
997 sp->cmn.fcphHigh = FC_PH3;
998
James Smart858c9f62007-06-17 19:56:39 -0500999 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1000 "Issue PLOGI: did:x%x",
1001 did, 0, 0);
1002
dea31012005-04-17 16:05:31 -05001003 phba->fc_stat.elsXmitPLOGI++;
1004 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
James Smart92d7f7b2007-06-17 19:56:38 -05001005 ret = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
1006
1007 if (ret == IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05001008 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001009 return 1;
dea31012005-04-17 16:05:31 -05001010 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001011 return 0;
dea31012005-04-17 16:05:31 -05001012}
1013
1014static void
James Smart2e0fef82007-06-17 19:56:36 -05001015lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1016 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001017{
James Smart2e0fef82007-06-17 19:56:36 -05001018 struct lpfc_vport *vport = cmdiocb->vport;
1019 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001020 IOCB_t *irsp;
1021 struct lpfc_sli *psli;
1022 struct lpfc_nodelist *ndlp;
1023
1024 psli = &phba->sli;
1025 /* we pass cmdiocb to state machine which needs rspiocb as well */
1026 cmdiocb->context_un.rsp_iocb = rspiocb;
1027
1028 irsp = &(rspiocb->iocb);
1029 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
James Smart2e0fef82007-06-17 19:56:36 -05001030 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001031 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001032 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001033
James Smart858c9f62007-06-17 19:56:39 -05001034 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1035 "PRLI cmpl: status:x%x/x%x did:x%x",
1036 irsp->ulpStatus, irsp->un.ulpWord[4],
1037 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05001038 /* PRLI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001039 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1040 "0103 PRLI completes to NPort x%x "
1041 "Data: x%x x%x x%x x%x\n",
1042 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1043 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001044
James Smart2e0fef82007-06-17 19:56:36 -05001045 vport->fc_prli_sent--;
dea31012005-04-17 16:05:31 -05001046 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001047 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05001048 goto out;
1049
1050 if (irsp->ulpStatus) {
1051 /* Check for retry */
1052 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1053 /* ELS command is being retried */
1054 goto out;
1055 }
1056 /* PRLI failed */
1057 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart858c9f62007-06-17 19:56:39 -05001058 if (lpfc_error_lost_link(irsp)) {
dea31012005-04-17 16:05:31 -05001059 goto out;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001060 } else {
James Smart2e0fef82007-06-17 19:56:36 -05001061 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001062 NLP_EVT_CMPL_PRLI);
dea31012005-04-17 16:05:31 -05001063 }
1064 } else {
1065 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05001066 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001067 NLP_EVT_CMPL_PRLI);
dea31012005-04-17 16:05:31 -05001068 }
1069
1070out:
1071 lpfc_els_free_iocb(phba, cmdiocb);
1072 return;
1073}
1074
1075int
James Smart2e0fef82007-06-17 19:56:36 -05001076lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001077 uint8_t retry)
1078{
James Smart2e0fef82007-06-17 19:56:36 -05001079 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1080 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001081 PRLI *npr;
1082 IOCB_t *icmd;
1083 struct lpfc_iocbq *elsiocb;
1084 struct lpfc_sli_ring *pring;
1085 struct lpfc_sli *psli;
1086 uint8_t *pcmd;
1087 uint16_t cmdsize;
1088
1089 psli = &phba->sli;
1090 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1091
James Smart92d7f7b2007-06-17 19:56:38 -05001092 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
James Smart2e0fef82007-06-17 19:56:36 -05001093 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1094 ndlp->nlp_DID, ELS_CMD_PRLI);
James Smart488d1462006-03-07 15:02:37 -05001095 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001096 return 1;
dea31012005-04-17 16:05:31 -05001097
1098 icmd = &elsiocb->iocb;
1099 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1100
1101 /* For PRLI request, remainder of payload is service parameters */
James Smart92d7f7b2007-06-17 19:56:38 -05001102 memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t)));
dea31012005-04-17 16:05:31 -05001103 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
James Smart92d7f7b2007-06-17 19:56:38 -05001104 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001105
1106 /* For PRLI, remainder of payload is PRLI parameter page */
1107 npr = (PRLI *) pcmd;
1108 /*
1109 * If our firmware version is 3.20 or later,
1110 * set the following bits for FC-TAPE support.
1111 */
1112 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
1113 npr->ConfmComplAllowed = 1;
1114 npr->Retry = 1;
1115 npr->TaskRetryIdReq = 1;
1116 }
1117 npr->estabImagePair = 1;
1118 npr->readXferRdyDis = 1;
1119
1120 /* For FCP support */
1121 npr->prliType = PRLI_FCP_TYPE;
1122 npr->initiatorFunc = 1;
1123
James Smart858c9f62007-06-17 19:56:39 -05001124 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1125 "Issue PRLI: did:x%x",
1126 ndlp->nlp_DID, 0, 0);
1127
dea31012005-04-17 16:05:31 -05001128 phba->fc_stat.elsXmitPRLI++;
1129 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
James Smart2e0fef82007-06-17 19:56:36 -05001130 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001131 ndlp->nlp_flag |= NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001132 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001133 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05001134 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001135 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001136 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001137 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001138 return 1;
dea31012005-04-17 16:05:31 -05001139 }
James Smart2e0fef82007-06-17 19:56:36 -05001140 vport->fc_prli_sent++;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001141 return 0;
dea31012005-04-17 16:05:31 -05001142}
1143
1144static void
James Smart2e0fef82007-06-17 19:56:36 -05001145lpfc_more_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001146{
1147 int sentadisc;
1148
James Smart2e0fef82007-06-17 19:56:36 -05001149 if (vport->num_disc_nodes)
1150 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001151 /* Continue discovery with <num_disc_nodes> ADISCs to go */
James Smarte8b62012007-08-02 11:10:09 -04001152 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1153 "0210 Continue discovery with %d ADISCs to go "
1154 "Data: x%x x%x x%x\n",
1155 vport->num_disc_nodes, vport->fc_adisc_cnt,
1156 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001157 /* Check to see if there are more ADISCs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001158 if (vport->fc_flag & FC_NLP_MORE) {
1159 lpfc_set_disctmo(vport);
1160 /* go thru NPR nodes and issue any remaining ELS ADISCs */
1161 sentadisc = lpfc_els_disc_adisc(vport);
dea31012005-04-17 16:05:31 -05001162 }
1163 return;
1164}
1165
1166static void
James Smart2e0fef82007-06-17 19:56:36 -05001167lpfc_rscn_disc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001168{
James Smart858c9f62007-06-17 19:56:39 -05001169 lpfc_can_disctmo(vport);
1170
dea31012005-04-17 16:05:31 -05001171 /* RSCN discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001172 /* go thru NPR nodes and issue ELS PLOGIs */
1173 if (vport->fc_npr_cnt)
1174 if (lpfc_els_disc_plogi(vport))
dea31012005-04-17 16:05:31 -05001175 return;
James Smart2e0fef82007-06-17 19:56:36 -05001176
James Smart87af33f2007-10-27 13:37:43 -04001177 lpfc_end_rscn(vport);
dea31012005-04-17 16:05:31 -05001178}
1179
1180static void
James Smart2e0fef82007-06-17 19:56:36 -05001181lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1182 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001183{
James Smart2e0fef82007-06-17 19:56:36 -05001184 struct lpfc_vport *vport = cmdiocb->vport;
1185 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001186 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001187 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001188 int disc;
dea31012005-04-17 16:05:31 -05001189
1190 /* we pass cmdiocb to state machine which needs rspiocb as well */
1191 cmdiocb->context_un.rsp_iocb = rspiocb;
1192
1193 irsp = &(rspiocb->iocb);
1194 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
dea31012005-04-17 16:05:31 -05001195
James Smart858c9f62007-06-17 19:56:39 -05001196 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1197 "ADISC cmpl: status:x%x/x%x did:x%x",
1198 irsp->ulpStatus, irsp->un.ulpWord[4],
1199 ndlp->nlp_DID);
1200
dea31012005-04-17 16:05:31 -05001201 /* Since ndlp can be freed in the disc state machine, note if this node
1202 * is being used during discovery.
1203 */
James Smart2e0fef82007-06-17 19:56:36 -05001204 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001205 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001206 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001207 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001208 /* ADISC completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001209 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1210 "0104 ADISC completes to NPort x%x "
1211 "Data: x%x x%x x%x x%x x%x\n",
1212 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1213 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001214 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001215 if (lpfc_els_chk_latt(vport)) {
1216 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001217 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001218 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001219 goto out;
1220 }
1221
1222 if (irsp->ulpStatus) {
1223 /* Check for retry */
1224 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1225 /* ELS command is being retried */
1226 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05001227 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001228 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001229 spin_unlock_irq(shost->host_lock);
1230 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001231 }
1232 goto out;
1233 }
1234 /* ADISC failed */
1235 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart858c9f62007-06-17 19:56:39 -05001236 if (!lpfc_error_lost_link(irsp)) {
James Smart2e0fef82007-06-17 19:56:36 -05001237 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart858c9f62007-06-17 19:56:39 -05001238 NLP_EVT_CMPL_ADISC);
dea31012005-04-17 16:05:31 -05001239 }
1240 } else {
1241 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05001242 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
dea31012005-04-17 16:05:31 -05001243 NLP_EVT_CMPL_ADISC);
1244 }
1245
James Smart2e0fef82007-06-17 19:56:36 -05001246 if (disc && vport->num_disc_nodes) {
dea31012005-04-17 16:05:31 -05001247 /* Check to see if there are more ADISCs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001248 lpfc_more_adisc(vport);
dea31012005-04-17 16:05:31 -05001249
1250 /* Check to see if we are done with ADISC authentication */
James Smart2e0fef82007-06-17 19:56:36 -05001251 if (vport->num_disc_nodes == 0) {
James Smart92d7f7b2007-06-17 19:56:38 -05001252 /* If we get here, there is nothing left to ADISC */
1253 /*
1254 * For NPIV, cmpl_reg_vpi will set port_state to READY,
1255 * and continue discovery.
1256 */
1257 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
1258 !(vport->fc_flag & FC_RSCN_MODE)) {
1259 lpfc_issue_reg_vpi(phba, vport);
1260 goto out;
1261 }
1262 /*
1263 * For SLI2, we need to set port_state to READY
1264 * and continue discovery.
1265 */
1266 if (vport->port_state < LPFC_VPORT_READY) {
1267 /* If we get here, there is nothing to ADISC */
James Smarted957682007-06-17 19:56:37 -05001268 if (vport->port_type == LPFC_PHYSICAL_PORT)
James Smart2e0fef82007-06-17 19:56:36 -05001269 lpfc_issue_clear_la(phba, vport);
James Smart92d7f7b2007-06-17 19:56:38 -05001270
1271 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
1272 vport->num_disc_nodes = 0;
1273 /* go thru NPR list, issue ELS PLOGIs */
1274 if (vport->fc_npr_cnt)
1275 lpfc_els_disc_plogi(vport);
1276
1277 if (!vport->num_disc_nodes) {
1278 spin_lock_irq(shost->host_lock);
1279 vport->fc_flag &=
1280 ~FC_NDISC_ACTIVE;
1281 spin_unlock_irq(
1282 shost->host_lock);
1283 lpfc_can_disctmo(vport);
1284 }
1285 }
1286 vport->port_state = LPFC_VPORT_READY;
dea31012005-04-17 16:05:31 -05001287 } else {
James Smart2e0fef82007-06-17 19:56:36 -05001288 lpfc_rscn_disc(vport);
dea31012005-04-17 16:05:31 -05001289 }
1290 }
1291 }
dea31012005-04-17 16:05:31 -05001292out:
1293 lpfc_els_free_iocb(phba, cmdiocb);
1294 return;
1295}
1296
1297int
James Smart2e0fef82007-06-17 19:56:36 -05001298lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001299 uint8_t retry)
1300{
James Smart2e0fef82007-06-17 19:56:36 -05001301 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1302 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001303 ADISC *ap;
1304 IOCB_t *icmd;
1305 struct lpfc_iocbq *elsiocb;
James Smart2e0fef82007-06-17 19:56:36 -05001306 struct lpfc_sli *psli = &phba->sli;
1307 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05001308 uint8_t *pcmd;
1309 uint16_t cmdsize;
1310
James Smart92d7f7b2007-06-17 19:56:38 -05001311 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
James Smart2e0fef82007-06-17 19:56:36 -05001312 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1313 ndlp->nlp_DID, ELS_CMD_ADISC);
James Smart488d1462006-03-07 15:02:37 -05001314 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001315 return 1;
dea31012005-04-17 16:05:31 -05001316
1317 icmd = &elsiocb->iocb;
1318 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1319
1320 /* For ADISC request, remainder of payload is service parameters */
1321 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
James Smart92d7f7b2007-06-17 19:56:38 -05001322 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001323
1324 /* Fill in ADISC payload */
1325 ap = (ADISC *) pcmd;
1326 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05001327 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
1328 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05001329 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05001330
James Smart858c9f62007-06-17 19:56:39 -05001331 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1332 "Issue ADISC: did:x%x",
1333 ndlp->nlp_DID, 0, 0);
1334
dea31012005-04-17 16:05:31 -05001335 phba->fc_stat.elsXmitADISC++;
1336 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
James Smart2e0fef82007-06-17 19:56:36 -05001337 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001338 ndlp->nlp_flag |= NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001339 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001340 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05001341 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001342 ndlp->nlp_flag &= ~NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001343 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001344 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001345 return 1;
dea31012005-04-17 16:05:31 -05001346 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001347 return 0;
dea31012005-04-17 16:05:31 -05001348}
1349
1350static void
James Smart2e0fef82007-06-17 19:56:36 -05001351lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1352 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001353{
James Smart2e0fef82007-06-17 19:56:36 -05001354 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1355 struct lpfc_vport *vport = ndlp->vport;
1356 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001357 IOCB_t *irsp;
1358 struct lpfc_sli *psli;
dea31012005-04-17 16:05:31 -05001359
1360 psli = &phba->sli;
1361 /* we pass cmdiocb to state machine which needs rspiocb as well */
1362 cmdiocb->context_un.rsp_iocb = rspiocb;
1363
1364 irsp = &(rspiocb->iocb);
James Smart2e0fef82007-06-17 19:56:36 -05001365 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001366 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001367 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001368
James Smart858c9f62007-06-17 19:56:39 -05001369 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1370 "LOGO cmpl: status:x%x/x%x did:x%x",
1371 irsp->ulpStatus, irsp->un.ulpWord[4],
1372 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05001373 /* LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001374 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1375 "0105 LOGO completes to NPort x%x "
1376 "Data: x%x x%x x%x x%x\n",
1377 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1378 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001379 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001380 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05001381 goto out;
1382
James Smart92d7f7b2007-06-17 19:56:38 -05001383 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
1384 /* NLP_EVT_DEVICE_RM should unregister the RPI
1385 * which should abort all outstanding IOs.
1386 */
1387 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1388 NLP_EVT_DEVICE_RM);
1389 goto out;
1390 }
1391
dea31012005-04-17 16:05:31 -05001392 if (irsp->ulpStatus) {
1393 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -05001394 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -05001395 /* ELS command is being retried */
1396 goto out;
dea31012005-04-17 16:05:31 -05001397 /* LOGO failed */
1398 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart858c9f62007-06-17 19:56:39 -05001399 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05001400 goto out;
James Smart858c9f62007-06-17 19:56:39 -05001401 else
James Smart2e0fef82007-06-17 19:56:36 -05001402 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001403 NLP_EVT_CMPL_LOGO);
dea31012005-04-17 16:05:31 -05001404 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001405 /* Good status, call state machine.
1406 * This will unregister the rpi if needed.
1407 */
James Smart2e0fef82007-06-17 19:56:36 -05001408 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001409 NLP_EVT_CMPL_LOGO);
dea31012005-04-17 16:05:31 -05001410 }
1411
1412out:
1413 lpfc_els_free_iocb(phba, cmdiocb);
1414 return;
1415}
1416
1417int
James Smart2e0fef82007-06-17 19:56:36 -05001418lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001419 uint8_t retry)
1420{
James Smart2e0fef82007-06-17 19:56:36 -05001421 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1422 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001423 IOCB_t *icmd;
1424 struct lpfc_iocbq *elsiocb;
1425 struct lpfc_sli_ring *pring;
1426 struct lpfc_sli *psli;
1427 uint8_t *pcmd;
1428 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05001429 int rc;
dea31012005-04-17 16:05:31 -05001430
1431 psli = &phba->sli;
1432 pring = &psli->ring[LPFC_ELS_RING];
1433
James Smart98c9ea52007-10-27 13:37:33 -04001434 spin_lock_irq(shost->host_lock);
1435 if (ndlp->nlp_flag & NLP_LOGO_SND) {
1436 spin_unlock_irq(shost->host_lock);
1437 return 0;
1438 }
1439 spin_unlock_irq(shost->host_lock);
1440
James Smart92d7f7b2007-06-17 19:56:38 -05001441 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
James Smart2e0fef82007-06-17 19:56:36 -05001442 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1443 ndlp->nlp_DID, ELS_CMD_LOGO);
James Smart488d1462006-03-07 15:02:37 -05001444 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001445 return 1;
dea31012005-04-17 16:05:31 -05001446
1447 icmd = &elsiocb->iocb;
1448 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1449 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
James Smart92d7f7b2007-06-17 19:56:38 -05001450 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001451
1452 /* Fill in LOGO payload */
James Smart2e0fef82007-06-17 19:56:36 -05001453 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05001454 pcmd += sizeof(uint32_t);
1455 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05001456
James Smart858c9f62007-06-17 19:56:39 -05001457 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1458 "Issue LOGO: did:x%x",
1459 ndlp->nlp_DID, 0, 0);
1460
dea31012005-04-17 16:05:31 -05001461 phba->fc_stat.elsXmitLOGO++;
1462 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
James Smart2e0fef82007-06-17 19:56:36 -05001463 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001464 ndlp->nlp_flag |= NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001465 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05001466 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
1467
1468 if (rc == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05001469 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001470 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001471 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001472 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001473 return 1;
dea31012005-04-17 16:05:31 -05001474 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001475 return 0;
dea31012005-04-17 16:05:31 -05001476}
1477
1478static void
James Smart2e0fef82007-06-17 19:56:36 -05001479lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1480 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001481{
James Smart2e0fef82007-06-17 19:56:36 -05001482 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -05001483 IOCB_t *irsp;
1484
1485 irsp = &rspiocb->iocb;
1486
James Smart858c9f62007-06-17 19:56:39 -05001487 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1488 "ELS cmd cmpl: status:x%x/x%x did:x%x",
1489 irsp->ulpStatus, irsp->un.ulpWord[4],
1490 irsp->un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05001491 /* ELS cmd tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04001492 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1493 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
1494 irsp->ulpIoTag, irsp->ulpStatus,
1495 irsp->un.ulpWord[4], irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -05001496 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001497 lpfc_els_chk_latt(vport);
dea31012005-04-17 16:05:31 -05001498 lpfc_els_free_iocb(phba, cmdiocb);
1499 return;
1500}
1501
1502int
James Smart2e0fef82007-06-17 19:56:36 -05001503lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05001504{
James Smart2e0fef82007-06-17 19:56:36 -05001505 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001506 IOCB_t *icmd;
1507 struct lpfc_iocbq *elsiocb;
1508 struct lpfc_sli_ring *pring;
1509 struct lpfc_sli *psli;
1510 uint8_t *pcmd;
1511 uint16_t cmdsize;
1512 struct lpfc_nodelist *ndlp;
1513
1514 psli = &phba->sli;
1515 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
James Smart92d7f7b2007-06-17 19:56:38 -05001516 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001517 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1518 if (!ndlp)
1519 return 1;
dea31012005-04-17 16:05:31 -05001520
James Smart2e0fef82007-06-17 19:56:36 -05001521 lpfc_nlp_init(vport, ndlp, nportid);
dea31012005-04-17 16:05:31 -05001522
James Smart2e0fef82007-06-17 19:56:36 -05001523 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1524 ndlp->nlp_DID, ELS_CMD_SCR);
1525
James Smart488d1462006-03-07 15:02:37 -05001526 if (!elsiocb) {
James Smart329f9bc2007-04-25 09:53:01 -04001527 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001528 return 1;
dea31012005-04-17 16:05:31 -05001529 }
1530
1531 icmd = &elsiocb->iocb;
1532 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1533
1534 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
James Smart92d7f7b2007-06-17 19:56:38 -05001535 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001536
1537 /* For SCR, remainder of payload is SCR parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05001538 memset(pcmd, 0, sizeof(SCR));
dea31012005-04-17 16:05:31 -05001539 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
1540
James Smart858c9f62007-06-17 19:56:39 -05001541 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1542 "Issue SCR: did:x%x",
1543 ndlp->nlp_DID, 0, 0);
1544
dea31012005-04-17 16:05:31 -05001545 phba->fc_stat.elsXmitSCR++;
1546 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
dea31012005-04-17 16:05:31 -05001547 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
James Smart329f9bc2007-04-25 09:53:01 -04001548 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001549 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001550 return 1;
dea31012005-04-17 16:05:31 -05001551 }
James Smart329f9bc2007-04-25 09:53:01 -04001552 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001553 return 0;
dea31012005-04-17 16:05:31 -05001554}
1555
1556static int
James Smart2e0fef82007-06-17 19:56:36 -05001557lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05001558{
James Smart2e0fef82007-06-17 19:56:36 -05001559 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001560 IOCB_t *icmd;
1561 struct lpfc_iocbq *elsiocb;
1562 struct lpfc_sli_ring *pring;
1563 struct lpfc_sli *psli;
1564 FARP *fp;
1565 uint8_t *pcmd;
1566 uint32_t *lp;
1567 uint16_t cmdsize;
1568 struct lpfc_nodelist *ondlp;
1569 struct lpfc_nodelist *ndlp;
1570
1571 psli = &phba->sli;
1572 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
James Smart92d7f7b2007-06-17 19:56:38 -05001573 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001574 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1575 if (!ndlp)
1576 return 1;
dea31012005-04-17 16:05:31 -05001577
James Smart2e0fef82007-06-17 19:56:36 -05001578 lpfc_nlp_init(vport, ndlp, nportid);
1579
1580 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1581 ndlp->nlp_DID, ELS_CMD_RNID);
James Smart488d1462006-03-07 15:02:37 -05001582 if (!elsiocb) {
James Smart329f9bc2007-04-25 09:53:01 -04001583 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001584 return 1;
dea31012005-04-17 16:05:31 -05001585 }
1586
1587 icmd = &elsiocb->iocb;
1588 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1589
1590 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
James Smart92d7f7b2007-06-17 19:56:38 -05001591 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001592
1593 /* Fill in FARPR payload */
1594 fp = (FARP *) (pcmd);
James Smart92d7f7b2007-06-17 19:56:38 -05001595 memset(fp, 0, sizeof(FARP));
dea31012005-04-17 16:05:31 -05001596 lp = (uint32_t *) pcmd;
1597 *lp++ = be32_to_cpu(nportid);
James Smart2e0fef82007-06-17 19:56:36 -05001598 *lp++ = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05001599 fp->Rflags = 0;
1600 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
1601
James Smart92d7f7b2007-06-17 19:56:38 -05001602 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
1603 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05001604 ondlp = lpfc_findnode_did(vport, nportid);
1605 if (ondlp) {
dea31012005-04-17 16:05:31 -05001606 memcpy(&fp->OportName, &ondlp->nlp_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05001607 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05001608 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05001609 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05001610 }
1611
James Smart858c9f62007-06-17 19:56:39 -05001612 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1613 "Issue FARPR: did:x%x",
1614 ndlp->nlp_DID, 0, 0);
1615
dea31012005-04-17 16:05:31 -05001616 phba->fc_stat.elsXmitFARPR++;
1617 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
dea31012005-04-17 16:05:31 -05001618 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
James Smart329f9bc2007-04-25 09:53:01 -04001619 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001620 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001621 return 1;
dea31012005-04-17 16:05:31 -05001622 }
James Smart329f9bc2007-04-25 09:53:01 -04001623 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001624 return 0;
dea31012005-04-17 16:05:31 -05001625}
1626
1627void
James Smart2e0fef82007-06-17 19:56:36 -05001628lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
James Smartfdcebe22006-03-07 15:04:01 -05001629{
James Smart2e0fef82007-06-17 19:56:36 -05001630 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1631
1632 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05001633 nlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001634 spin_unlock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05001635 del_timer_sync(&nlp->nlp_delayfunc);
1636 nlp->nlp_last_elscmd = 0;
1637
1638 if (!list_empty(&nlp->els_retry_evt.evt_listp))
1639 list_del_init(&nlp->els_retry_evt.evt_listp);
1640
1641 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
James Smart2e0fef82007-06-17 19:56:36 -05001642 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05001643 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001644 spin_unlock_irq(shost->host_lock);
1645 if (vport->num_disc_nodes) {
James Smartfdcebe22006-03-07 15:04:01 -05001646 /* Check to see if there are more
1647 * PLOGIs to be sent
1648 */
James Smart2e0fef82007-06-17 19:56:36 -05001649 lpfc_more_plogi(vport);
James Smartfdcebe22006-03-07 15:04:01 -05001650
James Smart2e0fef82007-06-17 19:56:36 -05001651 if (vport->num_disc_nodes == 0) {
1652 spin_lock_irq(shost->host_lock);
1653 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1654 spin_unlock_irq(shost->host_lock);
1655 lpfc_can_disctmo(vport);
James Smarted957682007-06-17 19:56:37 -05001656 lpfc_end_rscn(vport);
James Smartfdcebe22006-03-07 15:04:01 -05001657 }
1658 }
1659 }
1660 return;
1661}
1662
1663void
dea31012005-04-17 16:05:31 -05001664lpfc_els_retry_delay(unsigned long ptr)
1665{
James Smart2e0fef82007-06-17 19:56:36 -05001666 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
1667 struct lpfc_vport *vport = ndlp->vport;
James Smart2e0fef82007-06-17 19:56:36 -05001668 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05001669 unsigned long flags;
James Smart2e0fef82007-06-17 19:56:36 -05001670 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
dea31012005-04-17 16:05:31 -05001671
James Smart2e0fef82007-06-17 19:56:36 -05001672 ndlp = (struct lpfc_nodelist *) ptr;
1673 phba = ndlp->vport->phba;
dea31012005-04-17 16:05:31 -05001674 evtp = &ndlp->els_retry_evt;
1675
James Smart92d7f7b2007-06-17 19:56:38 -05001676 spin_lock_irqsave(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05001677 if (!list_empty(&evtp->evt_listp)) {
James Smart92d7f7b2007-06-17 19:56:38 -05001678 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05001679 return;
1680 }
1681
1682 evtp->evt_arg1 = ndlp;
1683 evtp->evt = LPFC_EVT_ELS_RETRY;
1684 list_add_tail(&evtp->evt_listp, &phba->work_list);
1685 if (phba->work_wait)
James Smart92d7f7b2007-06-17 19:56:38 -05001686 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05001687
James Smart92d7f7b2007-06-17 19:56:38 -05001688 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05001689 return;
1690}
1691
1692void
1693lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
1694{
James Smart2e0fef82007-06-17 19:56:36 -05001695 struct lpfc_vport *vport = ndlp->vport;
1696 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1697 uint32_t cmd, did, retry;
dea31012005-04-17 16:05:31 -05001698
James Smart2e0fef82007-06-17 19:56:36 -05001699 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001700 did = ndlp->nlp_DID;
1701 cmd = ndlp->nlp_last_elscmd;
1702 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05001703
1704 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
James Smart2e0fef82007-06-17 19:56:36 -05001705 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001706 return;
1707 }
1708
1709 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001710 spin_unlock_irq(shost->host_lock);
James Smart1a169682006-03-07 15:04:06 -05001711 /*
1712 * If a discovery event readded nlp_delayfunc after timer
1713 * firing and before processing the timer, cancel the
1714 * nlp_delayfunc.
1715 */
1716 del_timer_sync(&ndlp->nlp_delayfunc);
dea31012005-04-17 16:05:31 -05001717 retry = ndlp->nlp_retry;
1718
1719 switch (cmd) {
1720 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05001721 lpfc_issue_els_flogi(vport, ndlp, retry);
dea31012005-04-17 16:05:31 -05001722 break;
1723 case ELS_CMD_PLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05001724 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001725 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001726 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05001727 }
dea31012005-04-17 16:05:31 -05001728 break;
1729 case ELS_CMD_ADISC:
James Smart2e0fef82007-06-17 19:56:36 -05001730 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001731 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001732 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05001733 }
dea31012005-04-17 16:05:31 -05001734 break;
1735 case ELS_CMD_PRLI:
James Smart2e0fef82007-06-17 19:56:36 -05001736 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001737 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001738 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05001739 }
dea31012005-04-17 16:05:31 -05001740 break;
1741 case ELS_CMD_LOGO:
James Smart2e0fef82007-06-17 19:56:36 -05001742 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001743 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001744 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05001745 }
dea31012005-04-17 16:05:31 -05001746 break;
James Smart92d7f7b2007-06-17 19:56:38 -05001747 case ELS_CMD_FDISC:
1748 lpfc_issue_els_fdisc(vport, ndlp, retry);
1749 break;
dea31012005-04-17 16:05:31 -05001750 }
1751 return;
1752}
1753
1754static int
James Smart2e0fef82007-06-17 19:56:36 -05001755lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1756 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001757{
James Smart2e0fef82007-06-17 19:56:36 -05001758 struct lpfc_vport *vport = cmdiocb->vport;
1759 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1760 IOCB_t *irsp = &rspiocb->iocb;
1761 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1762 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
dea31012005-04-17 16:05:31 -05001763 uint32_t *elscmd;
1764 struct ls_rjt stat;
James Smart2e0fef82007-06-17 19:56:36 -05001765 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
James Smart98c9ea52007-10-27 13:37:33 -04001766 int logerr = 0;
James Smart2e0fef82007-06-17 19:56:36 -05001767 uint32_t cmd = 0;
James Smart488d1462006-03-07 15:02:37 -05001768 uint32_t did;
dea31012005-04-17 16:05:31 -05001769
James Smart488d1462006-03-07 15:02:37 -05001770
dea31012005-04-17 16:05:31 -05001771 /* Note: context2 may be 0 for internal driver abort
1772 * of delays ELS command.
1773 */
1774
1775 if (pcmd && pcmd->virt) {
1776 elscmd = (uint32_t *) (pcmd->virt);
1777 cmd = *elscmd++;
1778 }
1779
James Smart329f9bc2007-04-25 09:53:01 -04001780 if (ndlp)
James Smart488d1462006-03-07 15:02:37 -05001781 did = ndlp->nlp_DID;
1782 else {
1783 /* We should only hit this case for retrying PLOGI */
1784 did = irsp->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05001785 ndlp = lpfc_findnode_did(vport, did);
James Smart488d1462006-03-07 15:02:37 -05001786 if (!ndlp && (cmd != ELS_CMD_PLOGI))
1787 return 1;
1788 }
1789
James Smart858c9f62007-06-17 19:56:39 -05001790 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1791 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
1792 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
1793
dea31012005-04-17 16:05:31 -05001794 switch (irsp->ulpStatus) {
1795 case IOSTAT_FCP_RSP_ERROR:
1796 case IOSTAT_REMOTE_STOP:
1797 break;
1798
1799 case IOSTAT_LOCAL_REJECT:
1800 switch ((irsp->un.ulpWord[4] & 0xff)) {
1801 case IOERR_LOOP_OPEN_FAILURE:
James Smart2e0fef82007-06-17 19:56:36 -05001802 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05001803 delay = 1000;
dea31012005-04-17 16:05:31 -05001804 retry = 1;
1805 break;
1806
James Smart92d7f7b2007-06-17 19:56:38 -05001807 case IOERR_ILLEGAL_COMMAND:
1808 if ((phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) &&
1809 (cmd == ELS_CMD_FDISC)) {
James Smarte8b62012007-08-02 11:10:09 -04001810 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1811 "0124 FDISC failed (3/6) "
1812 "retrying...\n");
James Smart92d7f7b2007-06-17 19:56:38 -05001813 lpfc_mbx_unreg_vpi(vport);
1814 retry = 1;
James Smart51ef4c22007-08-02 11:10:31 -04001815 /* FDISC retry policy */
1816 maxretry = 48;
1817 if (cmdiocb->retry >= 32)
1818 delay = 1000;
James Smart92d7f7b2007-06-17 19:56:38 -05001819 }
1820 break;
1821
dea31012005-04-17 16:05:31 -05001822 case IOERR_NO_RESOURCES:
James Smart98c9ea52007-10-27 13:37:33 -04001823 logerr = 1; /* HBA out of resources */
James Smart858c9f62007-06-17 19:56:39 -05001824 retry = 1;
1825 if (cmdiocb->retry > 100)
1826 delay = 100;
1827 maxretry = 250;
1828 break;
1829
1830 case IOERR_ILLEGAL_FRAME:
James Smart92d7f7b2007-06-17 19:56:38 -05001831 delay = 100;
dea31012005-04-17 16:05:31 -05001832 retry = 1;
1833 break;
1834
James Smart858c9f62007-06-17 19:56:39 -05001835 case IOERR_SEQUENCE_TIMEOUT:
dea31012005-04-17 16:05:31 -05001836 case IOERR_INVALID_RPI:
1837 retry = 1;
1838 break;
1839 }
1840 break;
1841
1842 case IOSTAT_NPORT_RJT:
1843 case IOSTAT_FABRIC_RJT:
1844 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
1845 retry = 1;
1846 break;
1847 }
1848 break;
1849
1850 case IOSTAT_NPORT_BSY:
1851 case IOSTAT_FABRIC_BSY:
James Smart98c9ea52007-10-27 13:37:33 -04001852 logerr = 1; /* Fabric / Remote NPort out of resources */
dea31012005-04-17 16:05:31 -05001853 retry = 1;
1854 break;
1855
1856 case IOSTAT_LS_RJT:
1857 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
1858 /* Added for Vendor specifc support
1859 * Just keep retrying for these Rsn / Exp codes
1860 */
1861 switch (stat.un.b.lsRjtRsnCode) {
1862 case LSRJT_UNABLE_TPC:
1863 if (stat.un.b.lsRjtRsnCodeExp ==
1864 LSEXP_CMD_IN_PROGRESS) {
1865 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05001866 delay = 1000;
dea31012005-04-17 16:05:31 -05001867 maxretry = 48;
1868 }
1869 retry = 1;
1870 break;
1871 }
1872 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05001873 delay = 1000;
dea31012005-04-17 16:05:31 -05001874 maxretry = lpfc_max_els_tries + 1;
1875 retry = 1;
1876 break;
1877 }
James Smart92d7f7b2007-06-17 19:56:38 -05001878 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
1879 (cmd == ELS_CMD_FDISC) &&
1880 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
James Smarte8b62012007-08-02 11:10:09 -04001881 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1882 "0125 FDISC Failed (x%x). "
1883 "Fabric out of resources\n",
1884 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05001885 lpfc_vport_set_state(vport,
1886 FC_VPORT_NO_FABRIC_RSCS);
1887 }
dea31012005-04-17 16:05:31 -05001888 break;
1889
1890 case LSRJT_LOGICAL_BSY:
James Smart858c9f62007-06-17 19:56:39 -05001891 if ((cmd == ELS_CMD_PLOGI) ||
1892 (cmd == ELS_CMD_PRLI)) {
James Smart92d7f7b2007-06-17 19:56:38 -05001893 delay = 1000;
dea31012005-04-17 16:05:31 -05001894 maxretry = 48;
James Smart92d7f7b2007-06-17 19:56:38 -05001895 } else if (cmd == ELS_CMD_FDISC) {
James Smart51ef4c22007-08-02 11:10:31 -04001896 /* FDISC retry policy */
1897 maxretry = 48;
1898 if (cmdiocb->retry >= 32)
1899 delay = 1000;
dea31012005-04-17 16:05:31 -05001900 }
1901 retry = 1;
1902 break;
James Smart92d7f7b2007-06-17 19:56:38 -05001903
1904 case LSRJT_LOGICAL_ERR:
1905 case LSRJT_PROTOCOL_ERR:
1906 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
1907 (cmd == ELS_CMD_FDISC) &&
1908 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
1909 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
1910 ) {
James Smarte8b62012007-08-02 11:10:09 -04001911 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1912 "0123 FDISC Failed (x%x). "
1913 "Fabric Detected Bad WWN\n",
1914 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05001915 lpfc_vport_set_state(vport,
1916 FC_VPORT_FABRIC_REJ_WWN);
1917 }
1918 break;
dea31012005-04-17 16:05:31 -05001919 }
1920 break;
1921
1922 case IOSTAT_INTERMED_RSP:
1923 case IOSTAT_BA_RJT:
1924 break;
1925
1926 default:
1927 break;
1928 }
1929
James Smart488d1462006-03-07 15:02:37 -05001930 if (did == FDMI_DID)
dea31012005-04-17 16:05:31 -05001931 retry = 1;
dea31012005-04-17 16:05:31 -05001932
James Smart98c9ea52007-10-27 13:37:33 -04001933 if ((cmd == ELS_CMD_FLOGI) &&
1934 (phba->fc_topology != TOPOLOGY_LOOP)) {
1935 /* FLOGI retry policy */
1936 retry = 1;
1937 maxretry = 48;
1938 if (cmdiocb->retry >= 32)
1939 delay = 1000;
1940 }
1941
dea31012005-04-17 16:05:31 -05001942 if ((++cmdiocb->retry) >= maxretry) {
1943 phba->fc_stat.elsRetryExceeded++;
1944 retry = 0;
1945 }
1946
James Smarted957682007-06-17 19:56:37 -05001947 if ((vport->load_flag & FC_UNLOADING) != 0)
1948 retry = 0;
1949
dea31012005-04-17 16:05:31 -05001950 if (retry) {
1951
1952 /* Retry ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04001953 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1954 "0107 Retry ELS command x%x to remote "
1955 "NPORT x%x Data: x%x x%x\n",
1956 cmd, did, cmdiocb->retry, delay);
dea31012005-04-17 16:05:31 -05001957
James Smart858c9f62007-06-17 19:56:39 -05001958 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
1959 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
1960 ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) {
1961 /* Don't reset timer for no resources */
1962
dea31012005-04-17 16:05:31 -05001963 /* If discovery / RSCN timer is running, reset it */
James Smart2e0fef82007-06-17 19:56:36 -05001964 if (timer_pending(&vport->fc_disctmo) ||
James Smart92d7f7b2007-06-17 19:56:38 -05001965 (vport->fc_flag & FC_RSCN_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05001966 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001967 }
1968
1969 phba->fc_stat.elsXmitRetry++;
James Smart488d1462006-03-07 15:02:37 -05001970 if (ndlp && delay) {
dea31012005-04-17 16:05:31 -05001971 phba->fc_stat.elsDelayRetry++;
1972 ndlp->nlp_retry = cmdiocb->retry;
1973
James Smart92d7f7b2007-06-17 19:56:38 -05001974 /* delay is specified in milliseconds */
1975 mod_timer(&ndlp->nlp_delayfunc,
1976 jiffies + msecs_to_jiffies(delay));
James Smart2e0fef82007-06-17 19:56:36 -05001977 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001978 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001979 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001980
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001981 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart858c9f62007-06-17 19:56:39 -05001982 if (cmd == ELS_CMD_PRLI)
1983 lpfc_nlp_set_state(vport, ndlp,
1984 NLP_STE_REG_LOGIN_ISSUE);
1985 else
1986 lpfc_nlp_set_state(vport, ndlp,
1987 NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05001988 ndlp->nlp_last_elscmd = cmd;
1989
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001990 return 1;
dea31012005-04-17 16:05:31 -05001991 }
1992 switch (cmd) {
1993 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05001994 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001995 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -05001996 case ELS_CMD_FDISC:
1997 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
1998 return 1;
dea31012005-04-17 16:05:31 -05001999 case ELS_CMD_PLOGI:
James Smart488d1462006-03-07 15:02:37 -05002000 if (ndlp) {
2001 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002002 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04002003 NLP_STE_PLOGI_ISSUE);
James Smart488d1462006-03-07 15:02:37 -05002004 }
James Smart2e0fef82007-06-17 19:56:36 -05002005 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002006 return 1;
dea31012005-04-17 16:05:31 -05002007 case ELS_CMD_ADISC:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002008 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002009 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2010 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002011 return 1;
dea31012005-04-17 16:05:31 -05002012 case ELS_CMD_PRLI:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002013 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002014 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
2015 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002016 return 1;
dea31012005-04-17 16:05:31 -05002017 case ELS_CMD_LOGO:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002018 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002019 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2020 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002021 return 1;
dea31012005-04-17 16:05:31 -05002022 }
2023 }
dea31012005-04-17 16:05:31 -05002024 /* No retry ELS command <elsCmd> to remote NPORT <did> */
James Smart98c9ea52007-10-27 13:37:33 -04002025 if (logerr) {
2026 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2027 "0137 No retry ELS command x%x to remote "
2028 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
2029 cmd, did, irsp->ulpStatus,
2030 irsp->un.ulpWord[4]);
2031 }
2032 else {
2033 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smarta58cbd52007-08-02 11:09:43 -04002034 "0108 No retry ELS command x%x to remote "
2035 "NPORT x%x Retried:%d Error:x%x/%x\n",
2036 cmd, did, cmdiocb->retry, irsp->ulpStatus,
2037 irsp->un.ulpWord[4]);
James Smart98c9ea52007-10-27 13:37:33 -04002038 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002039 return 0;
dea31012005-04-17 16:05:31 -05002040}
2041
2042int
James Smart87af33f2007-10-27 13:37:43 -04002043lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
2044{
2045 struct lpfc_dmabuf *buf_ptr;
2046
2047 /* Free the response before processing the command. */
2048 if (!list_empty(&buf_ptr1->list)) {
2049 list_remove_head(&buf_ptr1->list, buf_ptr,
2050 struct lpfc_dmabuf,
2051 list);
2052 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
2053 kfree(buf_ptr);
2054 }
2055 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
2056 kfree(buf_ptr1);
2057 return 0;
2058}
2059
2060int
2061lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
2062{
2063 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
2064 kfree(buf_ptr);
2065 return 0;
2066}
2067
2068int
James Smart329f9bc2007-04-25 09:53:01 -04002069lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05002070{
2071 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
2072
James Smart329f9bc2007-04-25 09:53:01 -04002073 if (elsiocb->context1) {
2074 lpfc_nlp_put(elsiocb->context1);
2075 elsiocb->context1 = NULL;
2076 }
dea31012005-04-17 16:05:31 -05002077 /* context2 = cmd, context2->next = rsp, context3 = bpl */
2078 if (elsiocb->context2) {
2079 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
James Smart87af33f2007-10-27 13:37:43 -04002080 lpfc_els_free_data(phba, buf_ptr1);
dea31012005-04-17 16:05:31 -05002081 }
2082
2083 if (elsiocb->context3) {
2084 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
James Smart87af33f2007-10-27 13:37:43 -04002085 lpfc_els_free_bpl(phba, buf_ptr);
dea31012005-04-17 16:05:31 -05002086 }
James Bottomley604a3e32005-10-29 10:28:33 -05002087 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -05002088 return 0;
2089}
2090
2091static void
James Smart2e0fef82007-06-17 19:56:36 -05002092lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2093 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002094{
James Smart2e0fef82007-06-17 19:56:36 -05002095 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2096 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05002097 IOCB_t *irsp;
2098
2099 irsp = &rspiocb->iocb;
2100 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2101 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
2102 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05002103 /* ACC to LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002104 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2105 "0109 ACC to LOGO completes to NPort x%x "
2106 "Data: x%x x%x x%x\n",
2107 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2108 ndlp->nlp_rpi);
James Smart87af33f2007-10-27 13:37:43 -04002109
2110 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
2111 /* NPort Recovery mode or node is just allocated */
2112 if (!lpfc_nlp_not_used(ndlp)) {
2113 /* If the ndlp is being used by another discovery
2114 * thread, just unregister the RPI.
2115 */
2116 lpfc_unreg_rpi(vport, ndlp);
2117 }
dea31012005-04-17 16:05:31 -05002118 }
2119 lpfc_els_free_iocb(phba, cmdiocb);
2120 return;
2121}
2122
James Smart858c9f62007-06-17 19:56:39 -05002123void
2124lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
2125{
2126 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
2127 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
2128
2129 pmb->context1 = NULL;
2130 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2131 kfree(mp);
2132 mempool_free(pmb, phba->mbox_mem_pool);
2133 lpfc_nlp_put(ndlp);
James Smart98c9ea52007-10-27 13:37:33 -04002134
2135 /* This is the end of the default RPI cleanup logic for this
2136 * ndlp. If no other discovery threads are using this ndlp.
2137 * we should free all resources associated with it.
2138 */
2139 lpfc_nlp_not_used(ndlp);
James Smart858c9f62007-06-17 19:56:39 -05002140 return;
2141}
2142
dea31012005-04-17 16:05:31 -05002143static void
James Smart858c9f62007-06-17 19:56:39 -05002144lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
James Smart329f9bc2007-04-25 09:53:01 -04002145 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002146{
James Smart2e0fef82007-06-17 19:56:36 -05002147 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2148 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
2149 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
James Smart87af33f2007-10-27 13:37:43 -04002150 IOCB_t *irsp;
2151 uint8_t *pcmd;
dea31012005-04-17 16:05:31 -05002152 LPFC_MBOXQ_t *mbox = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05002153 struct lpfc_dmabuf *mp = NULL;
James Smart87af33f2007-10-27 13:37:43 -04002154 uint32_t ls_rjt = 0;
dea31012005-04-17 16:05:31 -05002155
James Smart33ccf8d2006-08-17 11:57:58 -04002156 irsp = &rspiocb->iocb;
2157
dea31012005-04-17 16:05:31 -05002158 if (cmdiocb->context_un.mbox)
2159 mbox = cmdiocb->context_un.mbox;
2160
James Smart87af33f2007-10-27 13:37:43 -04002161 /* First determine if this is a LS_RJT cmpl */
2162 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
2163 if (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT) {
2164 /* A LS_RJT associated with Default RPI cleanup
2165 * has its own seperate code path.
2166 */
2167 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
2168 ls_rjt = 1;
2169 }
2170
dea31012005-04-17 16:05:31 -05002171 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002172 if (!ndlp || lpfc_els_chk_latt(vport)) {
dea31012005-04-17 16:05:31 -05002173 if (mbox) {
James Smart14691152006-12-02 13:34:28 -05002174 mp = (struct lpfc_dmabuf *) mbox->context1;
2175 if (mp) {
2176 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2177 kfree(mp);
2178 }
James Smart329f9bc2007-04-25 09:53:01 -04002179 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05002180 }
James Smart98c9ea52007-10-27 13:37:33 -04002181 if (ndlp && (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
2182 if (lpfc_nlp_not_used(ndlp))
2183 ndlp = NULL;
dea31012005-04-17 16:05:31 -05002184 goto out;
2185 }
2186
James Smart858c9f62007-06-17 19:56:39 -05002187 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smart51ef4c22007-08-02 11:10:31 -04002188 "ELS rsp cmpl: status:x%x/x%x did:x%x",
James Smart858c9f62007-06-17 19:56:39 -05002189 irsp->ulpStatus, irsp->un.ulpWord[4],
James Smart51ef4c22007-08-02 11:10:31 -04002190 cmdiocb->iocb.un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05002191 /* ELS response tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04002192 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2193 "0110 ELS response tag x%x completes "
2194 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
2195 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
2196 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
2197 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2198 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05002199 if (mbox) {
2200 if ((rspiocb->iocb.ulpStatus == 0)
2201 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
James Smart2e0fef82007-06-17 19:56:36 -05002202 lpfc_unreg_rpi(vport, ndlp);
James Smart329f9bc2007-04-25 09:53:01 -04002203 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05002204 mbox->vport = vport;
James Smart858c9f62007-06-17 19:56:39 -05002205 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
2206 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
2207 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
2208 }
2209 else {
2210 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
2211 ndlp->nlp_prev_state = ndlp->nlp_state;
2212 lpfc_nlp_set_state(vport, ndlp,
James Smart2e0fef82007-06-17 19:56:36 -05002213 NLP_STE_REG_LOGIN_ISSUE);
James Smart858c9f62007-06-17 19:56:39 -05002214 }
James Smart0b727fe2007-10-27 13:37:25 -04002215 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
dea31012005-04-17 16:05:31 -05002216 != MBX_NOT_FINISHED) {
2217 goto out;
2218 }
James Smart98c9ea52007-10-27 13:37:33 -04002219
2220 /* ELS rsp: Cannot issue reg_login for <NPortid> */
2221 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2222 "0138 ELS rsp: Cannot issue reg_login for x%x "
2223 "Data: x%x x%x x%x\n",
2224 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2225 ndlp->nlp_rpi);
2226
2227 if (lpfc_nlp_not_used(ndlp))
2228 ndlp = NULL;
dea31012005-04-17 16:05:31 -05002229 } else {
James Smart858c9f62007-06-17 19:56:39 -05002230 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
2231 if (!lpfc_error_lost_link(irsp) &&
2232 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
James Smart98c9ea52007-10-27 13:37:33 -04002233 if (lpfc_nlp_not_used(ndlp))
2234 ndlp = NULL;
dea31012005-04-17 16:05:31 -05002235 }
2236 }
James Smart14691152006-12-02 13:34:28 -05002237 mp = (struct lpfc_dmabuf *) mbox->context1;
2238 if (mp) {
2239 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2240 kfree(mp);
2241 }
2242 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05002243 }
2244out:
2245 if (ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05002246 spin_lock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05002247 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
James Smart2e0fef82007-06-17 19:56:36 -05002248 spin_unlock_irq(shost->host_lock);
James Smart87af33f2007-10-27 13:37:43 -04002249
2250 /* If the node is not being used by another discovery thread,
2251 * and we are sending a reject, we are done with it.
2252 * Release driver reference count here and free associated
2253 * resources.
2254 */
2255 if (ls_rjt)
2256 lpfc_nlp_not_used(ndlp);
dea31012005-04-17 16:05:31 -05002257 }
James Smart87af33f2007-10-27 13:37:43 -04002258
dea31012005-04-17 16:05:31 -05002259 lpfc_els_free_iocb(phba, cmdiocb);
2260 return;
2261}
2262
2263int
James Smart2e0fef82007-06-17 19:56:36 -05002264lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
2265 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
James Smart51ef4c22007-08-02 11:10:31 -04002266 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05002267{
James Smart2e0fef82007-06-17 19:56:36 -05002268 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2269 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002270 IOCB_t *icmd;
2271 IOCB_t *oldcmd;
2272 struct lpfc_iocbq *elsiocb;
2273 struct lpfc_sli_ring *pring;
2274 struct lpfc_sli *psli;
2275 uint8_t *pcmd;
2276 uint16_t cmdsize;
2277 int rc;
James Smart82d9a2a2006-04-15 11:53:05 -04002278 ELS_PKT *els_pkt_ptr;
dea31012005-04-17 16:05:31 -05002279
2280 psli = &phba->sli;
2281 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2282 oldcmd = &oldiocb->iocb;
2283
2284 switch (flag) {
2285 case ELS_CMD_ACC:
James Smart92d7f7b2007-06-17 19:56:38 -05002286 cmdsize = sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05002287 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
2288 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05002289 if (!elsiocb) {
James Smart2e0fef82007-06-17 19:56:36 -05002290 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002291 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05002292 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002293 return 1;
dea31012005-04-17 16:05:31 -05002294 }
James Smart2e0fef82007-06-17 19:56:36 -05002295
dea31012005-04-17 16:05:31 -05002296 icmd = &elsiocb->iocb;
2297 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2298 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2299 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05002300 pcmd += sizeof(uint32_t);
James Smart858c9f62007-06-17 19:56:39 -05002301
2302 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2303 "Issue ACC: did:x%x flg:x%x",
2304 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05002305 break;
2306 case ELS_CMD_PLOGI:
James Smart92d7f7b2007-06-17 19:56:38 -05002307 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
James Smart2e0fef82007-06-17 19:56:36 -05002308 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
2309 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05002310 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002311 return 1;
James Smart488d1462006-03-07 15:02:37 -05002312
dea31012005-04-17 16:05:31 -05002313 icmd = &elsiocb->iocb;
2314 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2315 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2316
2317 if (mbox)
2318 elsiocb->context_un.mbox = mbox;
2319
2320 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05002321 pcmd += sizeof(uint32_t);
2322 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
James Smart858c9f62007-06-17 19:56:39 -05002323
2324 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2325 "Issue ACC PLOGI: did:x%x flg:x%x",
2326 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05002327 break;
James Smart82d9a2a2006-04-15 11:53:05 -04002328 case ELS_CMD_PRLO:
James Smart92d7f7b2007-06-17 19:56:38 -05002329 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
James Smart2e0fef82007-06-17 19:56:36 -05002330 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
James Smart82d9a2a2006-04-15 11:53:05 -04002331 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
2332 if (!elsiocb)
2333 return 1;
2334
2335 icmd = &elsiocb->iocb;
2336 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2337 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2338
2339 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
James Smart92d7f7b2007-06-17 19:56:38 -05002340 sizeof(uint32_t) + sizeof(PRLO));
James Smart82d9a2a2006-04-15 11:53:05 -04002341 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
2342 els_pkt_ptr = (ELS_PKT *) pcmd;
2343 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
James Smart858c9f62007-06-17 19:56:39 -05002344
2345 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2346 "Issue ACC PRLO: did:x%x flg:x%x",
2347 ndlp->nlp_DID, ndlp->nlp_flag, 0);
James Smart82d9a2a2006-04-15 11:53:05 -04002348 break;
dea31012005-04-17 16:05:31 -05002349 default:
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002350 return 1;
dea31012005-04-17 16:05:31 -05002351 }
dea31012005-04-17 16:05:31 -05002352 /* Xmit ELS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04002353 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2354 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
2355 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n",
2356 elsiocb->iotag, elsiocb->iocb.ulpContext,
2357 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2358 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05002359 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
James Smart2e0fef82007-06-17 19:56:36 -05002360 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002361 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05002362 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002363 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
2364 } else {
James Smart858c9f62007-06-17 19:56:39 -05002365 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05002366 }
2367
2368 phba->fc_stat.elsXmitACC++;
dea31012005-04-17 16:05:31 -05002369 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
dea31012005-04-17 16:05:31 -05002370 if (rc == IOCB_ERROR) {
2371 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002372 return 1;
dea31012005-04-17 16:05:31 -05002373 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002374 return 0;
dea31012005-04-17 16:05:31 -05002375}
2376
2377int
James Smart2e0fef82007-06-17 19:56:36 -05002378lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
James Smart858c9f62007-06-17 19:56:39 -05002379 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
2380 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05002381{
James Smart2e0fef82007-06-17 19:56:36 -05002382 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002383 IOCB_t *icmd;
2384 IOCB_t *oldcmd;
2385 struct lpfc_iocbq *elsiocb;
2386 struct lpfc_sli_ring *pring;
2387 struct lpfc_sli *psli;
2388 uint8_t *pcmd;
2389 uint16_t cmdsize;
2390 int rc;
2391
2392 psli = &phba->sli;
2393 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2394
James Smart92d7f7b2007-06-17 19:56:38 -05002395 cmdsize = 2 * sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05002396 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
2397 ndlp->nlp_DID, ELS_CMD_LS_RJT);
James Smart488d1462006-03-07 15:02:37 -05002398 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002399 return 1;
dea31012005-04-17 16:05:31 -05002400
2401 icmd = &elsiocb->iocb;
2402 oldcmd = &oldiocb->iocb;
2403 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2404 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2405
2406 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
James Smart92d7f7b2007-06-17 19:56:38 -05002407 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002408 *((uint32_t *) (pcmd)) = rejectError;
2409
James Smart51ef4c22007-08-02 11:10:31 -04002410 if (mbox)
James Smart858c9f62007-06-17 19:56:39 -05002411 elsiocb->context_un.mbox = mbox;
James Smart858c9f62007-06-17 19:56:39 -05002412
dea31012005-04-17 16:05:31 -05002413 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04002414 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2415 "0129 Xmit ELS RJT x%x response tag x%x "
2416 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
2417 "rpi x%x\n",
2418 rejectError, elsiocb->iotag,
2419 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
2420 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05002421 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2422 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
2423 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
2424
dea31012005-04-17 16:05:31 -05002425 phba->fc_stat.elsXmitLSRJT++;
James Smart858c9f62007-06-17 19:56:39 -05002426 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05002427 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
James Smart51ef4c22007-08-02 11:10:31 -04002428
dea31012005-04-17 16:05:31 -05002429 if (rc == IOCB_ERROR) {
2430 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002431 return 1;
dea31012005-04-17 16:05:31 -05002432 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002433 return 0;
dea31012005-04-17 16:05:31 -05002434}
2435
2436int
James Smart2e0fef82007-06-17 19:56:36 -05002437lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
2438 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05002439{
James Smart2e0fef82007-06-17 19:56:36 -05002440 struct lpfc_hba *phba = vport->phba;
2441 struct lpfc_sli *psli = &phba->sli;
2442 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05002443 ADISC *ap;
James Smart2e0fef82007-06-17 19:56:36 -05002444 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05002445 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002446 uint8_t *pcmd;
2447 uint16_t cmdsize;
2448 int rc;
2449
James Smart92d7f7b2007-06-17 19:56:38 -05002450 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
James Smart2e0fef82007-06-17 19:56:36 -05002451 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
2452 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05002453 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002454 return 1;
dea31012005-04-17 16:05:31 -05002455
dea31012005-04-17 16:05:31 -05002456 icmd = &elsiocb->iocb;
2457 oldcmd = &oldiocb->iocb;
2458 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04002459
2460 /* Xmit ADISC ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04002461 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2462 "0130 Xmit ADISC ACC response iotag x%x xri: "
2463 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
2464 elsiocb->iotag, elsiocb->iocb.ulpContext,
2465 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2466 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05002467 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2468
2469 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05002470 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002471
2472 ap = (ADISC *) (pcmd);
2473 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05002474 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2475 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002476 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002477
James Smart858c9f62007-06-17 19:56:39 -05002478 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2479 "Issue ACC ADISC: did:x%x flg:x%x",
2480 ndlp->nlp_DID, ndlp->nlp_flag, 0);
2481
dea31012005-04-17 16:05:31 -05002482 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05002483 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05002484 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
dea31012005-04-17 16:05:31 -05002485 if (rc == IOCB_ERROR) {
2486 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002487 return 1;
dea31012005-04-17 16:05:31 -05002488 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002489 return 0;
dea31012005-04-17 16:05:31 -05002490}
2491
2492int
James Smart2e0fef82007-06-17 19:56:36 -05002493lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
James Smart5b8bd0c2007-04-25 09:52:49 -04002494 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05002495{
James Smart2e0fef82007-06-17 19:56:36 -05002496 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002497 PRLI *npr;
2498 lpfc_vpd_t *vpd;
2499 IOCB_t *icmd;
2500 IOCB_t *oldcmd;
2501 struct lpfc_iocbq *elsiocb;
2502 struct lpfc_sli_ring *pring;
2503 struct lpfc_sli *psli;
2504 uint8_t *pcmd;
2505 uint16_t cmdsize;
2506 int rc;
2507
2508 psli = &phba->sli;
2509 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2510
James Smart92d7f7b2007-06-17 19:56:38 -05002511 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
James Smart2e0fef82007-06-17 19:56:36 -05002512 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
James Smart92d7f7b2007-06-17 19:56:38 -05002513 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002514 if (!elsiocb)
2515 return 1;
dea31012005-04-17 16:05:31 -05002516
dea31012005-04-17 16:05:31 -05002517 icmd = &elsiocb->iocb;
2518 oldcmd = &oldiocb->iocb;
2519 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04002520 /* Xmit PRLI ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04002521 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2522 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
2523 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
2524 elsiocb->iotag, elsiocb->iocb.ulpContext,
2525 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2526 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05002527 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2528
2529 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
James Smart92d7f7b2007-06-17 19:56:38 -05002530 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002531
2532 /* For PRLI, remainder of payload is PRLI parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05002533 memset(pcmd, 0, sizeof(PRLI));
dea31012005-04-17 16:05:31 -05002534
2535 npr = (PRLI *) pcmd;
2536 vpd = &phba->vpd;
2537 /*
2538 * If our firmware version is 3.20 or later,
2539 * set the following bits for FC-TAPE support.
2540 */
2541 if (vpd->rev.feaLevelHigh >= 0x02) {
2542 npr->ConfmComplAllowed = 1;
2543 npr->Retry = 1;
2544 npr->TaskRetryIdReq = 1;
2545 }
2546
2547 npr->acceptRspCode = PRLI_REQ_EXECUTED;
2548 npr->estabImagePair = 1;
2549 npr->readXferRdyDis = 1;
2550 npr->ConfmComplAllowed = 1;
2551
2552 npr->prliType = PRLI_FCP_TYPE;
2553 npr->initiatorFunc = 1;
2554
James Smart858c9f62007-06-17 19:56:39 -05002555 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2556 "Issue ACC PRLI: did:x%x flg:x%x",
2557 ndlp->nlp_DID, ndlp->nlp_flag, 0);
2558
dea31012005-04-17 16:05:31 -05002559 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05002560 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05002561
dea31012005-04-17 16:05:31 -05002562 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
dea31012005-04-17 16:05:31 -05002563 if (rc == IOCB_ERROR) {
2564 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002565 return 1;
dea31012005-04-17 16:05:31 -05002566 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002567 return 0;
dea31012005-04-17 16:05:31 -05002568}
2569
2570static int
James Smart2e0fef82007-06-17 19:56:36 -05002571lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
James Smart329f9bc2007-04-25 09:53:01 -04002572 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05002573{
James Smart2e0fef82007-06-17 19:56:36 -05002574 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002575 RNID *rn;
James Smart2e0fef82007-06-17 19:56:36 -05002576 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05002577 struct lpfc_iocbq *elsiocb;
2578 struct lpfc_sli_ring *pring;
2579 struct lpfc_sli *psli;
2580 uint8_t *pcmd;
2581 uint16_t cmdsize;
2582 int rc;
2583
2584 psli = &phba->sli;
2585 pring = &psli->ring[LPFC_ELS_RING];
2586
James Smart92d7f7b2007-06-17 19:56:38 -05002587 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
2588 + (2 * sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002589 if (format)
James Smart92d7f7b2007-06-17 19:56:38 -05002590 cmdsize += sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05002591
James Smart2e0fef82007-06-17 19:56:36 -05002592 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
2593 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05002594 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002595 return 1;
dea31012005-04-17 16:05:31 -05002596
dea31012005-04-17 16:05:31 -05002597 icmd = &elsiocb->iocb;
2598 oldcmd = &oldiocb->iocb;
2599 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04002600 /* Xmit RNID ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04002601 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2602 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
2603 elsiocb->iotag, elsiocb->iocb.ulpContext);
dea31012005-04-17 16:05:31 -05002604 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
dea31012005-04-17 16:05:31 -05002605 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05002606 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002607
James Smart92d7f7b2007-06-17 19:56:38 -05002608 memset(pcmd, 0, sizeof(RNID));
dea31012005-04-17 16:05:31 -05002609 rn = (RNID *) (pcmd);
2610 rn->Format = format;
James Smart92d7f7b2007-06-17 19:56:38 -05002611 rn->CommonLen = (2 * sizeof(struct lpfc_name));
2612 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2613 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002614 switch (format) {
2615 case 0:
2616 rn->SpecificLen = 0;
2617 break;
2618 case RNID_TOPOLOGY_DISC:
James Smart92d7f7b2007-06-17 19:56:38 -05002619 rn->SpecificLen = sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05002620 memcpy(&rn->un.topologyDisc.portName,
James Smart92d7f7b2007-06-17 19:56:38 -05002621 &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002622 rn->un.topologyDisc.unitType = RNID_HBA;
2623 rn->un.topologyDisc.physPort = 0;
2624 rn->un.topologyDisc.attachedNodes = 0;
2625 break;
2626 default:
2627 rn->CommonLen = 0;
2628 rn->SpecificLen = 0;
2629 break;
2630 }
2631
James Smart858c9f62007-06-17 19:56:39 -05002632 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2633 "Issue ACC RNID: did:x%x flg:x%x",
2634 ndlp->nlp_DID, ndlp->nlp_flag, 0);
2635
dea31012005-04-17 16:05:31 -05002636 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05002637 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart329f9bc2007-04-25 09:53:01 -04002638 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002639 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
2640 * it could be freed */
2641
dea31012005-04-17 16:05:31 -05002642 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
dea31012005-04-17 16:05:31 -05002643 if (rc == IOCB_ERROR) {
2644 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002645 return 1;
dea31012005-04-17 16:05:31 -05002646 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002647 return 0;
dea31012005-04-17 16:05:31 -05002648}
2649
2650int
James Smart2e0fef82007-06-17 19:56:36 -05002651lpfc_els_disc_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002652{
James Smart2e0fef82007-06-17 19:56:36 -05002653 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002654 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05002655 int sentadisc = 0;
dea31012005-04-17 16:05:31 -05002656
James Smart685f0bf2007-04-25 09:53:08 -04002657 /* go thru NPR nodes and issue any remaining ELS ADISCs */
James Smart2e0fef82007-06-17 19:56:36 -05002658 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smart685f0bf2007-04-25 09:53:08 -04002659 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
2660 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
2661 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
James Smart2e0fef82007-06-17 19:56:36 -05002662 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04002663 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05002664 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04002665 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002666 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2667 lpfc_issue_els_adisc(vport, ndlp, 0);
James Smart685f0bf2007-04-25 09:53:08 -04002668 sentadisc++;
James Smart2e0fef82007-06-17 19:56:36 -05002669 vport->num_disc_nodes++;
2670 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04002671 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05002672 spin_lock_irq(shost->host_lock);
2673 vport->fc_flag |= FC_NLP_MORE;
2674 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04002675 break;
dea31012005-04-17 16:05:31 -05002676 }
2677 }
2678 }
2679 if (sentadisc == 0) {
James Smart2e0fef82007-06-17 19:56:36 -05002680 spin_lock_irq(shost->host_lock);
2681 vport->fc_flag &= ~FC_NLP_MORE;
2682 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002683 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002684 return sentadisc;
dea31012005-04-17 16:05:31 -05002685}
2686
2687int
James Smart2e0fef82007-06-17 19:56:36 -05002688lpfc_els_disc_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002689{
James Smart2e0fef82007-06-17 19:56:36 -05002690 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002691 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05002692 int sentplogi = 0;
dea31012005-04-17 16:05:31 -05002693
James Smart2e0fef82007-06-17 19:56:36 -05002694 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
2695 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smart685f0bf2007-04-25 09:53:08 -04002696 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
2697 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
2698 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
2699 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
2700 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002701 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2702 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
James Smart685f0bf2007-04-25 09:53:08 -04002703 sentplogi++;
James Smart2e0fef82007-06-17 19:56:36 -05002704 vport->num_disc_nodes++;
2705 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04002706 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05002707 spin_lock_irq(shost->host_lock);
2708 vport->fc_flag |= FC_NLP_MORE;
2709 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04002710 break;
dea31012005-04-17 16:05:31 -05002711 }
2712 }
2713 }
James Smart87af33f2007-10-27 13:37:43 -04002714 if (sentplogi) {
2715 lpfc_set_disctmo(vport);
2716 }
2717 else {
James Smart2e0fef82007-06-17 19:56:36 -05002718 spin_lock_irq(shost->host_lock);
2719 vport->fc_flag &= ~FC_NLP_MORE;
2720 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002721 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002722 return sentplogi;
dea31012005-04-17 16:05:31 -05002723}
2724
James Smart92d7f7b2007-06-17 19:56:38 -05002725void
James Smart2e0fef82007-06-17 19:56:36 -05002726lpfc_els_flush_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002727{
James Smart2e0fef82007-06-17 19:56:36 -05002728 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2729 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002730 int i;
2731
James Smart2e0fef82007-06-17 19:56:36 -05002732 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05002733 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
James Smart2e0fef82007-06-17 19:56:36 -05002734 vport->fc_rscn_id_list[i] = NULL;
dea31012005-04-17 16:05:31 -05002735 }
James Smart2e0fef82007-06-17 19:56:36 -05002736 spin_lock_irq(shost->host_lock);
2737 vport->fc_rscn_id_cnt = 0;
2738 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
2739 spin_unlock_irq(shost->host_lock);
2740 lpfc_can_disctmo(vport);
dea31012005-04-17 16:05:31 -05002741}
2742
2743int
James Smart2e0fef82007-06-17 19:56:36 -05002744lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05002745{
2746 D_ID ns_did;
2747 D_ID rscn_did;
dea31012005-04-17 16:05:31 -05002748 uint32_t *lp;
James Smart92d7f7b2007-06-17 19:56:38 -05002749 uint32_t payload_len, i;
dea31012005-04-17 16:05:31 -05002750
2751 ns_did.un.word = did;
dea31012005-04-17 16:05:31 -05002752
2753 /* Never match fabric nodes for RSCNs */
2754 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
James Smart2e0fef82007-06-17 19:56:36 -05002755 return 0;
dea31012005-04-17 16:05:31 -05002756
2757 /* If we are doing a FULL RSCN rediscovery, match everything */
James Smart2e0fef82007-06-17 19:56:36 -05002758 if (vport->fc_flag & FC_RSCN_DISCOVERY)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002759 return did;
dea31012005-04-17 16:05:31 -05002760
James Smart2e0fef82007-06-17 19:56:36 -05002761 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05002762 lp = vport->fc_rscn_id_list[i]->virt;
2763 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
2764 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05002765 while (payload_len) {
James Smart92d7f7b2007-06-17 19:56:38 -05002766 rscn_did.un.word = be32_to_cpu(*lp++);
2767 payload_len -= sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002768 switch (rscn_did.un.b.resv) {
2769 case 0: /* Single N_Port ID effected */
James Smart2e0fef82007-06-17 19:56:36 -05002770 if (ns_did.un.word == rscn_did.un.word)
James Smart92d7f7b2007-06-17 19:56:38 -05002771 return did;
dea31012005-04-17 16:05:31 -05002772 break;
2773 case 1: /* Whole N_Port Area effected */
2774 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
2775 && (ns_did.un.b.area == rscn_did.un.b.area))
James Smart92d7f7b2007-06-17 19:56:38 -05002776 return did;
dea31012005-04-17 16:05:31 -05002777 break;
2778 case 2: /* Whole N_Port Domain effected */
2779 if (ns_did.un.b.domain == rscn_did.un.b.domain)
James Smart92d7f7b2007-06-17 19:56:38 -05002780 return did;
dea31012005-04-17 16:05:31 -05002781 break;
2782 default:
James Smart2e0fef82007-06-17 19:56:36 -05002783 /* Unknown Identifier in RSCN node */
James Smarte8b62012007-08-02 11:10:09 -04002784 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
2785 "0217 Unknown Identifier in "
2786 "RSCN payload Data: x%x\n",
2787 rscn_did.un.word);
James Smart92d7f7b2007-06-17 19:56:38 -05002788 case 3: /* Whole Fabric effected */
2789 return did;
dea31012005-04-17 16:05:31 -05002790 }
2791 }
James Smart92d7f7b2007-06-17 19:56:38 -05002792 }
2793 return 0;
dea31012005-04-17 16:05:31 -05002794}
2795
2796static int
James Smart2e0fef82007-06-17 19:56:36 -05002797lpfc_rscn_recovery_check(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002798{
James Smart685f0bf2007-04-25 09:53:08 -04002799 struct lpfc_nodelist *ndlp = NULL;
dea31012005-04-17 16:05:31 -05002800
2801 /* Look at all nodes effected by pending RSCNs and move
James Smart685f0bf2007-04-25 09:53:08 -04002802 * them to NPR state.
dea31012005-04-17 16:05:31 -05002803 */
James Smart685f0bf2007-04-25 09:53:08 -04002804
James Smart2e0fef82007-06-17 19:56:36 -05002805 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smart685f0bf2007-04-25 09:53:08 -04002806 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE ||
James Smart2e0fef82007-06-17 19:56:36 -05002807 lpfc_rscn_payload_check(vport, ndlp->nlp_DID) == 0)
dea31012005-04-17 16:05:31 -05002808 continue;
2809
James Smart2e0fef82007-06-17 19:56:36 -05002810 lpfc_disc_state_machine(vport, ndlp, NULL,
James Smart92d7f7b2007-06-17 19:56:38 -05002811 NLP_EVT_DEVICE_RECOVERY);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002812
James Smart685f0bf2007-04-25 09:53:08 -04002813 /*
2814 * Make sure NLP_DELAY_TMO is NOT running after a device
2815 * recovery event.
2816 */
2817 if (ndlp->nlp_flag & NLP_DELAY_TMO)
James Smart2e0fef82007-06-17 19:56:36 -05002818 lpfc_cancel_retry_delay_tmo(vport, ndlp);
dea31012005-04-17 16:05:31 -05002819 }
James Smart685f0bf2007-04-25 09:53:08 -04002820
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002821 return 0;
dea31012005-04-17 16:05:31 -05002822}
2823
2824static int
James Smart2e0fef82007-06-17 19:56:36 -05002825lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04002826 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05002827{
James Smart2e0fef82007-06-17 19:56:36 -05002828 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2829 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002830 struct lpfc_dmabuf *pcmd;
James Smart92d7f7b2007-06-17 19:56:38 -05002831 uint32_t *lp, *datap;
dea31012005-04-17 16:05:31 -05002832 IOCB_t *icmd;
James Smart92d7f7b2007-06-17 19:56:38 -05002833 uint32_t payload_len, length, nportid, *cmd;
2834 int rscn_cnt = vport->fc_rscn_id_cnt;
2835 int rscn_id = 0, hba_id = 0;
James Smartd2873e42006-08-18 17:46:43 -04002836 int i;
dea31012005-04-17 16:05:31 -05002837
2838 icmd = &cmdiocb->iocb;
2839 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2840 lp = (uint32_t *) pcmd->virt;
2841
James Smart92d7f7b2007-06-17 19:56:38 -05002842 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
2843 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05002844 /* RSCN received */
James Smarte8b62012007-08-02 11:10:09 -04002845 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2846 "0214 RSCN received Data: x%x x%x x%x x%x\n",
2847 vport->fc_flag, payload_len, *lp, rscn_cnt);
James Smartd2873e42006-08-18 17:46:43 -04002848 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
James Smart2e0fef82007-06-17 19:56:36 -05002849 fc_host_post_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04002850 FCH_EVT_RSCN, lp[i]);
2851
dea31012005-04-17 16:05:31 -05002852 /* If we are about to begin discovery, just ACC the RSCN.
2853 * Discovery processing will satisfy it.
2854 */
James Smart2e0fef82007-06-17 19:56:36 -05002855 if (vport->port_state <= LPFC_NS_QRY) {
James Smart858c9f62007-06-17 19:56:39 -05002856 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
2857 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
2858 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
2859
James Smart51ef4c22007-08-02 11:10:31 -04002860 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002861 return 0;
dea31012005-04-17 16:05:31 -05002862 }
2863
James Smart92d7f7b2007-06-17 19:56:38 -05002864 /* If this RSCN just contains NPortIDs for other vports on this HBA,
2865 * just ACC and ignore it.
2866 */
2867 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart3de2a652007-08-02 11:09:59 -04002868 !(vport->cfg_peer_port_login)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002869 i = payload_len;
2870 datap = lp;
2871 while (i > 0) {
2872 nportid = *datap++;
2873 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
2874 i -= sizeof(uint32_t);
2875 rscn_id++;
James Smart549e55c2007-08-02 11:09:51 -04002876 if (lpfc_find_vport_by_did(phba, nportid))
2877 hba_id++;
James Smart92d7f7b2007-06-17 19:56:38 -05002878 }
2879 if (rscn_id == hba_id) {
2880 /* ALL NPortIDs in RSCN are on HBA */
James Smarte8b62012007-08-02 11:10:09 -04002881 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2882 "0214 Ignore RSCN "
2883 "Data: x%x x%x x%x x%x\n",
2884 vport->fc_flag, payload_len,
2885 *lp, rscn_cnt);
James Smart858c9f62007-06-17 19:56:39 -05002886 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
2887 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
2888 ndlp->nlp_DID, vport->port_state,
2889 ndlp->nlp_flag);
2890
James Smart92d7f7b2007-06-17 19:56:38 -05002891 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04002892 ndlp, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05002893 return 0;
2894 }
2895 }
2896
dea31012005-04-17 16:05:31 -05002897 /* If we are already processing an RSCN, save the received
2898 * RSCN payload buffer, cmdiocb->context2 to process later.
2899 */
James Smart2e0fef82007-06-17 19:56:36 -05002900 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
James Smart858c9f62007-06-17 19:56:39 -05002901 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
2902 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
2903 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
2904
James Smart92d7f7b2007-06-17 19:56:38 -05002905 vport->fc_flag |= FC_RSCN_DEFERRED;
2906 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
James Smart2e0fef82007-06-17 19:56:36 -05002907 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
2908 spin_lock_irq(shost->host_lock);
2909 vport->fc_flag |= FC_RSCN_MODE;
2910 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05002911 if (rscn_cnt) {
2912 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
2913 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
2914 }
2915 if ((rscn_cnt) &&
2916 (payload_len + length <= LPFC_BPL_SIZE)) {
2917 *cmd &= ELS_CMD_MASK;
2918 *cmd |= be32_to_cpu(payload_len + length);
2919 memcpy(((uint8_t *)cmd) + length, lp,
2920 payload_len);
2921 } else {
2922 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
2923 vport->fc_rscn_id_cnt++;
2924 /* If we zero, cmdiocb->context2, the calling
2925 * routine will not try to free it.
2926 */
2927 cmdiocb->context2 = NULL;
2928 }
dea31012005-04-17 16:05:31 -05002929
2930 /* Deferred RSCN */
James Smarte8b62012007-08-02 11:10:09 -04002931 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2932 "0235 Deferred RSCN "
2933 "Data: x%x x%x x%x\n",
2934 vport->fc_rscn_id_cnt, vport->fc_flag,
2935 vport->port_state);
dea31012005-04-17 16:05:31 -05002936 } else {
James Smart2e0fef82007-06-17 19:56:36 -05002937 spin_lock_irq(shost->host_lock);
2938 vport->fc_flag |= FC_RSCN_DISCOVERY;
2939 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002940 /* ReDiscovery RSCN */
James Smarte8b62012007-08-02 11:10:09 -04002941 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2942 "0234 ReDiscovery RSCN "
2943 "Data: x%x x%x x%x\n",
2944 vport->fc_rscn_id_cnt, vport->fc_flag,
2945 vport->port_state);
dea31012005-04-17 16:05:31 -05002946 }
2947 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04002948 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05002949
2950 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05002951 lpfc_rscn_recovery_check(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05002952 vport->fc_flag &= ~FC_RSCN_DEFERRED;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002953 return 0;
dea31012005-04-17 16:05:31 -05002954 }
2955
James Smart858c9f62007-06-17 19:56:39 -05002956 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
2957 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
2958 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
2959
James Smart2e0fef82007-06-17 19:56:36 -05002960 spin_lock_irq(shost->host_lock);
2961 vport->fc_flag |= FC_RSCN_MODE;
2962 spin_unlock_irq(shost->host_lock);
2963 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
dea31012005-04-17 16:05:31 -05002964 /*
2965 * If we zero, cmdiocb->context2, the calling routine will
2966 * not try to free it.
2967 */
2968 cmdiocb->context2 = NULL;
2969
James Smart2e0fef82007-06-17 19:56:36 -05002970 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05002971
2972 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04002973 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05002974
2975 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05002976 lpfc_rscn_recovery_check(vport);
dea31012005-04-17 16:05:31 -05002977
James Smart2e0fef82007-06-17 19:56:36 -05002978 return lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05002979}
2980
2981int
James Smart2e0fef82007-06-17 19:56:36 -05002982lpfc_els_handle_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002983{
2984 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05002985 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002986
James Smart92d7f7b2007-06-17 19:56:38 -05002987 /* Ignore RSCN if the port is being torn down. */
2988 if (vport->load_flag & FC_UNLOADING) {
2989 lpfc_els_flush_rscn(vport);
2990 return 0;
2991 }
2992
dea31012005-04-17 16:05:31 -05002993 /* Start timer for RSCN processing */
James Smart2e0fef82007-06-17 19:56:36 -05002994 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05002995
2996 /* RSCN processed */
James Smarte8b62012007-08-02 11:10:09 -04002997 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2998 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
2999 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
3000 vport->port_state);
dea31012005-04-17 16:05:31 -05003001
3002 /* To process RSCN, first compare RSCN data with NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05003003 vport->fc_ns_retry = 0;
3004 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smart685f0bf2007-04-25 09:53:08 -04003005 if (ndlp && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
dea31012005-04-17 16:05:31 -05003006 /* Good ndlp, issue CT Request to NameServer */
James Smart92d7f7b2007-06-17 19:56:38 -05003007 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
dea31012005-04-17 16:05:31 -05003008 /* Wait for NameServer query cmpl before we can
3009 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003010 return 1;
dea31012005-04-17 16:05:31 -05003011 } else {
3012 /* If login to NameServer does not exist, issue one */
3013 /* Good status, issue PLOGI to NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05003014 ndlp = lpfc_findnode_did(vport, NameServer_DID);
3015 if (ndlp)
dea31012005-04-17 16:05:31 -05003016 /* Wait for NameServer login cmpl before we can
3017 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003018 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05003019
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003020 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
3021 if (!ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05003022 lpfc_els_flush_rscn(vport);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003023 return 0;
dea31012005-04-17 16:05:31 -05003024 } else {
James Smart2e0fef82007-06-17 19:56:36 -05003025 lpfc_nlp_init(vport, ndlp, NameServer_DID);
dea31012005-04-17 16:05:31 -05003026 ndlp->nlp_type |= NLP_FABRIC;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003027 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003028 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
3029 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
dea31012005-04-17 16:05:31 -05003030 /* Wait for NameServer login cmpl before we can
3031 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003032 return 1;
dea31012005-04-17 16:05:31 -05003033 }
3034 }
3035
James Smart2e0fef82007-06-17 19:56:36 -05003036 lpfc_els_flush_rscn(vport);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003037 return 0;
dea31012005-04-17 16:05:31 -05003038}
3039
3040static int
James Smart2e0fef82007-06-17 19:56:36 -05003041lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04003042 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003043{
James Smart2e0fef82007-06-17 19:56:36 -05003044 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3045 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003046 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3047 uint32_t *lp = (uint32_t *) pcmd->virt;
3048 IOCB_t *icmd = &cmdiocb->iocb;
3049 struct serv_parm *sp;
3050 LPFC_MBOXQ_t *mbox;
3051 struct ls_rjt stat;
3052 uint32_t cmd, did;
3053 int rc;
3054
3055 cmd = *lp++;
3056 sp = (struct serv_parm *) lp;
3057
3058 /* FLOGI received */
3059
James Smart2e0fef82007-06-17 19:56:36 -05003060 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05003061
3062 if (phba->fc_topology == TOPOLOGY_LOOP) {
3063 /* We should never receive a FLOGI in loop mode, ignore it */
3064 did = icmd->un.elsreq64.remoteID;
3065
3066 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
3067 Loop Mode */
James Smarte8b62012007-08-02 11:10:09 -04003068 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3069 "0113 An FLOGI ELS command x%x was "
3070 "received from DID x%x in Loop Mode\n",
3071 cmd, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003072 return 1;
dea31012005-04-17 16:05:31 -05003073 }
3074
3075 did = Fabric_DID;
3076
James Smart2e0fef82007-06-17 19:56:36 -05003077 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3))) {
dea31012005-04-17 16:05:31 -05003078 /* For a FLOGI we accept, then if our portname is greater
3079 * then the remote portname we initiate Nport login.
3080 */
3081
James Smart2e0fef82007-06-17 19:56:36 -05003082 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -05003083 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003084
3085 if (!rc) {
James Smart2e0fef82007-06-17 19:56:36 -05003086 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3087 if (!mbox)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003088 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05003089
dea31012005-04-17 16:05:31 -05003090 lpfc_linkdown(phba);
3091 lpfc_init_link(phba, mbox,
3092 phba->cfg_topology,
3093 phba->cfg_link_speed);
3094 mbox->mb.un.varInitLnk.lipsr_AL_PA = 0;
3095 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -05003096 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -04003097 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart5b8bd0c2007-04-25 09:52:49 -04003098 lpfc_set_loopback_flag(phba);
dea31012005-04-17 16:05:31 -05003099 if (rc == MBX_NOT_FINISHED) {
James Smart329f9bc2007-04-25 09:53:01 -04003100 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003101 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003102 return 1;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003103 } else if (rc > 0) { /* greater than */
James Smart2e0fef82007-06-17 19:56:36 -05003104 spin_lock_irq(shost->host_lock);
3105 vport->fc_flag |= FC_PT2PT_PLOGI;
3106 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003107 }
James Smart2e0fef82007-06-17 19:56:36 -05003108 spin_lock_irq(shost->host_lock);
3109 vport->fc_flag |= FC_PT2PT;
3110 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
3111 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003112 } else {
3113 /* Reject this request because invalid parameters */
3114 stat.un.b.lsRjtRsvd0 = 0;
3115 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3116 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
3117 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05003118 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
3119 NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003120 return 1;
dea31012005-04-17 16:05:31 -05003121 }
3122
3123 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04003124 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05003125
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003126 return 0;
dea31012005-04-17 16:05:31 -05003127}
3128
3129static int
James Smart2e0fef82007-06-17 19:56:36 -05003130lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3131 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003132{
3133 struct lpfc_dmabuf *pcmd;
3134 uint32_t *lp;
3135 IOCB_t *icmd;
3136 RNID *rn;
3137 struct ls_rjt stat;
3138 uint32_t cmd, did;
3139
3140 icmd = &cmdiocb->iocb;
3141 did = icmd->un.elsreq64.remoteID;
3142 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3143 lp = (uint32_t *) pcmd->virt;
3144
3145 cmd = *lp++;
3146 rn = (RNID *) lp;
3147
3148 /* RNID received */
3149
3150 switch (rn->Format) {
3151 case 0:
3152 case RNID_TOPOLOGY_DISC:
3153 /* Send back ACC */
James Smart2e0fef82007-06-17 19:56:36 -05003154 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05003155 break;
3156 default:
3157 /* Reject this request because format not supported */
3158 stat.un.b.lsRjtRsvd0 = 0;
3159 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3160 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
3161 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05003162 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
3163 NULL);
dea31012005-04-17 16:05:31 -05003164 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003165 return 0;
dea31012005-04-17 16:05:31 -05003166}
3167
3168static int
James Smart2e0fef82007-06-17 19:56:36 -05003169lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3170 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003171{
3172 struct ls_rjt stat;
3173
3174 /* For now, unconditionally reject this command */
3175 stat.un.b.lsRjtRsvd0 = 0;
3176 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3177 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
3178 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05003179 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003180 return 0;
3181}
3182
Jamie Wellnitz082c0262006-02-28 19:25:30 -05003183static void
James Smart329f9bc2007-04-25 09:53:01 -04003184lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003185{
James Smart2e0fef82007-06-17 19:56:36 -05003186 struct lpfc_sli *psli = &phba->sli;
3187 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003188 MAILBOX_t *mb;
3189 IOCB_t *icmd;
3190 RPS_RSP *rps_rsp;
3191 uint8_t *pcmd;
3192 struct lpfc_iocbq *elsiocb;
3193 struct lpfc_nodelist *ndlp;
3194 uint16_t xri, status;
3195 uint32_t cmdsize;
3196
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003197 mb = &pmb->mb;
3198
3199 ndlp = (struct lpfc_nodelist *) pmb->context2;
3200 xri = (uint16_t) ((unsigned long)(pmb->context1));
Randy Dunlap041976f2006-06-25 01:58:51 -07003201 pmb->context1 = NULL;
3202 pmb->context2 = NULL;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003203
3204 if (mb->mbxStatus) {
James Smart329f9bc2007-04-25 09:53:01 -04003205 mempool_free(pmb, phba->mbox_mem_pool);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003206 return;
3207 }
3208
3209 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
James Smart329f9bc2007-04-25 09:53:01 -04003210 mempool_free(pmb, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05003211 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
3212 lpfc_max_els_tries, ndlp,
3213 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart329f9bc2007-04-25 09:53:01 -04003214 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003215 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003216 return;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003217
3218 icmd = &elsiocb->iocb;
3219 icmd->ulpContext = xri;
3220
3221 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3222 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003223 pcmd += sizeof(uint32_t); /* Skip past command */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003224 rps_rsp = (RPS_RSP *)pcmd;
3225
3226 if (phba->fc_topology != TOPOLOGY_LOOP)
3227 status = 0x10;
3228 else
3229 status = 0x8;
James Smart2e0fef82007-06-17 19:56:36 -05003230 if (phba->pport->fc_flag & FC_FABRIC)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003231 status |= 0x4;
3232
3233 rps_rsp->rsvd1 = 0;
3234 rps_rsp->portStatus = be16_to_cpu(status);
3235 rps_rsp->linkFailureCnt = be32_to_cpu(mb->un.varRdLnk.linkFailureCnt);
3236 rps_rsp->lossSyncCnt = be32_to_cpu(mb->un.varRdLnk.lossSyncCnt);
3237 rps_rsp->lossSignalCnt = be32_to_cpu(mb->un.varRdLnk.lossSignalCnt);
3238 rps_rsp->primSeqErrCnt = be32_to_cpu(mb->un.varRdLnk.primSeqErrCnt);
3239 rps_rsp->invalidXmitWord = be32_to_cpu(mb->un.varRdLnk.invalidXmitWord);
3240 rps_rsp->crcCnt = be32_to_cpu(mb->un.varRdLnk.crcCnt);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003241 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003242 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
3243 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
3244 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
3245 elsiocb->iotag, elsiocb->iocb.ulpContext,
3246 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3247 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05003248 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003249 phba->fc_stat.elsXmitACC++;
James Smarted957682007-06-17 19:56:37 -05003250 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003251 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003252 return;
3253}
3254
3255static int
James Smart2e0fef82007-06-17 19:56:36 -05003256lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3257 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003258{
James Smart2e0fef82007-06-17 19:56:36 -05003259 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003260 uint32_t *lp;
3261 uint8_t flag;
3262 LPFC_MBOXQ_t *mbox;
3263 struct lpfc_dmabuf *pcmd;
3264 RPS *rps;
3265 struct ls_rjt stat;
3266
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003267 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
3268 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003269 stat.un.b.lsRjtRsvd0 = 0;
3270 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3271 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
3272 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05003273 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
3274 NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003275 }
3276
3277 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3278 lp = (uint32_t *) pcmd->virt;
3279 flag = (be32_to_cpu(*lp++) & 0xf);
3280 rps = (RPS *) lp;
3281
3282 if ((flag == 0) ||
3283 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
James Smart2e0fef82007-06-17 19:56:36 -05003284 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05003285 sizeof(struct lpfc_name)) == 0))) {
James Smart2e0fef82007-06-17 19:56:36 -05003286
James Smart92d7f7b2007-06-17 19:56:38 -05003287 printk("Fix me....\n");
3288 dump_stack();
James Smart2e0fef82007-06-17 19:56:36 -05003289 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
3290 if (mbox) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003291 lpfc_read_lnk_stat(phba, mbox);
3292 mbox->context1 =
James Smart92d7f7b2007-06-17 19:56:38 -05003293 (void *)((unsigned long) cmdiocb->iocb.ulpContext);
James Smart329f9bc2007-04-25 09:53:01 -04003294 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05003295 mbox->vport = vport;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003296 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
James Smart0b727fe2007-10-27 13:37:25 -04003297 if (lpfc_sli_issue_mbox (phba, mbox, MBX_NOWAIT)
3298 != MBX_NOT_FINISHED)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003299 /* Mbox completion will send ELS Response */
3300 return 0;
James Smart2e0fef82007-06-17 19:56:36 -05003301
James Smart329f9bc2007-04-25 09:53:01 -04003302 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003303 mempool_free(mbox, phba->mbox_mem_pool);
3304 }
3305 }
3306 stat.un.b.lsRjtRsvd0 = 0;
3307 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3308 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
3309 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05003310 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003311 return 0;
3312}
3313
Jamie Wellnitz082c0262006-02-28 19:25:30 -05003314static int
James Smart2e0fef82007-06-17 19:56:36 -05003315lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
3316 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003317{
James Smart2e0fef82007-06-17 19:56:36 -05003318 struct lpfc_hba *phba = vport->phba;
3319 IOCB_t *icmd, *oldcmd;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003320 RPL_RSP rpl_rsp;
3321 struct lpfc_iocbq *elsiocb;
James Smart2e0fef82007-06-17 19:56:36 -05003322 struct lpfc_sli *psli = &phba->sli;
3323 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003324 uint8_t *pcmd;
3325
James Smart2e0fef82007-06-17 19:56:36 -05003326 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3327 ndlp->nlp_DID, ELS_CMD_ACC);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003328
James Smart488d1462006-03-07 15:02:37 -05003329 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003330 return 1;
James Smart488d1462006-03-07 15:02:37 -05003331
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003332 icmd = &elsiocb->iocb;
3333 oldcmd = &oldiocb->iocb;
3334 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3335
3336 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3337 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003338 pcmd += sizeof(uint16_t);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003339 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
3340 pcmd += sizeof(uint16_t);
3341
3342 /* Setup the RPL ACC payload */
3343 rpl_rsp.listLen = be32_to_cpu(1);
3344 rpl_rsp.index = 0;
3345 rpl_rsp.port_num_blk.portNum = 0;
James Smart2e0fef82007-06-17 19:56:36 -05003346 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
3347 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003348 sizeof(struct lpfc_name));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003349 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003350 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003351 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3352 "0120 Xmit ELS RPL ACC response tag x%x "
3353 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
3354 "rpi x%x\n",
3355 elsiocb->iotag, elsiocb->iocb.ulpContext,
3356 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3357 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05003358 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003359 phba->fc_stat.elsXmitACC++;
3360 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
3361 lpfc_els_free_iocb(phba, elsiocb);
3362 return 1;
3363 }
3364 return 0;
3365}
3366
3367static int
James Smart2e0fef82007-06-17 19:56:36 -05003368lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3369 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003370{
3371 struct lpfc_dmabuf *pcmd;
3372 uint32_t *lp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003373 uint32_t maxsize;
3374 uint16_t cmdsize;
3375 RPL *rpl;
3376 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05003377
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003378 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
3379 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003380 stat.un.b.lsRjtRsvd0 = 0;
3381 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3382 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
3383 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05003384 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
3385 NULL);
dea31012005-04-17 16:05:31 -05003386 }
3387
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003388 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3389 lp = (uint32_t *) pcmd->virt;
3390 rpl = (RPL *) (lp + 1);
3391
3392 maxsize = be32_to_cpu(rpl->maxsize);
3393
3394 /* We support only one port */
3395 if ((rpl->index == 0) &&
3396 ((maxsize == 0) ||
3397 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
3398 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003399 } else {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003400 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
3401 }
James Smart2e0fef82007-06-17 19:56:36 -05003402 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05003403
3404 return 0;
3405}
3406
3407static int
James Smart2e0fef82007-06-17 19:56:36 -05003408lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3409 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003410{
3411 struct lpfc_dmabuf *pcmd;
3412 uint32_t *lp;
3413 IOCB_t *icmd;
3414 FARP *fp;
3415 uint32_t cmd, cnt, did;
3416
3417 icmd = &cmdiocb->iocb;
3418 did = icmd->un.elsreq64.remoteID;
3419 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3420 lp = (uint32_t *) pcmd->virt;
3421
3422 cmd = *lp++;
3423 fp = (FARP *) lp;
dea31012005-04-17 16:05:31 -05003424 /* FARP-REQ received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04003425 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3426 "0601 FARP-REQ received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05003427 /* We will only support match on WWPN or WWNN */
3428 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003429 return 0;
dea31012005-04-17 16:05:31 -05003430 }
3431
3432 cnt = 0;
3433 /* If this FARP command is searching for my portname */
3434 if (fp->Mflags & FARP_MATCH_PORT) {
James Smart2e0fef82007-06-17 19:56:36 -05003435 if (memcmp(&fp->RportName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05003436 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05003437 cnt = 1;
3438 }
3439
3440 /* If this FARP command is searching for my nodename */
3441 if (fp->Mflags & FARP_MATCH_NODE) {
James Smart2e0fef82007-06-17 19:56:36 -05003442 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05003443 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05003444 cnt = 1;
3445 }
3446
3447 if (cnt) {
3448 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
3449 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
3450 /* Log back into the node before sending the FARP. */
3451 if (fp->Rflags & FARP_REQUEST_PLOGI) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003452 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003453 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04003454 NLP_STE_PLOGI_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05003455 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05003456 }
3457
3458 /* Send a FARP response to that node */
James Smart2e0fef82007-06-17 19:56:36 -05003459 if (fp->Rflags & FARP_REQUEST_FARPR)
3460 lpfc_issue_els_farpr(vport, did, 0);
dea31012005-04-17 16:05:31 -05003461 }
3462 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003463 return 0;
dea31012005-04-17 16:05:31 -05003464}
3465
3466static int
James Smart2e0fef82007-06-17 19:56:36 -05003467lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3468 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003469{
3470 struct lpfc_dmabuf *pcmd;
3471 uint32_t *lp;
3472 IOCB_t *icmd;
3473 uint32_t cmd, did;
3474
3475 icmd = &cmdiocb->iocb;
3476 did = icmd->un.elsreq64.remoteID;
3477 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3478 lp = (uint32_t *) pcmd->virt;
3479
3480 cmd = *lp++;
3481 /* FARP-RSP received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04003482 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3483 "0600 FARP-RSP received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05003484 /* ACCEPT the Farp resp request */
James Smart51ef4c22007-08-02 11:10:31 -04003485 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05003486
3487 return 0;
3488}
3489
3490static int
James Smart2e0fef82007-06-17 19:56:36 -05003491lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3492 struct lpfc_nodelist *fan_ndlp)
dea31012005-04-17 16:05:31 -05003493{
3494 struct lpfc_dmabuf *pcmd;
3495 uint32_t *lp;
3496 IOCB_t *icmd;
dea31012005-04-17 16:05:31 -05003497 uint32_t cmd, did;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003498 FAN *fp;
3499 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05003500 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003501
3502 /* FAN received */
James Smarte8b62012007-08-02 11:10:09 -04003503 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3504 "0265 FAN received\n");
dea31012005-04-17 16:05:31 -05003505 icmd = &cmdiocb->iocb;
3506 did = icmd->un.elsreq64.remoteID;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003507 pcmd = (struct lpfc_dmabuf *)cmdiocb->context2;
3508 lp = (uint32_t *)pcmd->virt;
dea31012005-04-17 16:05:31 -05003509
3510 cmd = *lp++;
James Smart92d7f7b2007-06-17 19:56:38 -05003511 fp = (FAN *) lp;
dea31012005-04-17 16:05:31 -05003512
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003513 /* FAN received; Fan does not have a reply sequence */
dea31012005-04-17 16:05:31 -05003514
James Smart2e0fef82007-06-17 19:56:36 -05003515 if (phba->pport->port_state == LPFC_LOCAL_CFG_LINK) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003516 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
3517 sizeof(struct lpfc_name)) != 0) ||
3518 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
3519 sizeof(struct lpfc_name)) != 0)) {
3520 /*
3521 * This node has switched fabrics. FLOGI is required
3522 * Clean up the old rpi's
dea31012005-04-17 16:05:31 -05003523 */
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003524
3525 list_for_each_entry_safe(ndlp, next_ndlp,
James Smart2e0fef82007-06-17 19:56:36 -05003526 &vport->fc_nodes, nlp_listp) {
James Smart685f0bf2007-04-25 09:53:08 -04003527 if (ndlp->nlp_state != NLP_STE_NPR_NODE)
3528 continue;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003529 if (ndlp->nlp_type & NLP_FABRIC) {
3530 /*
3531 * Clean up old Fabric, Nameserver and
3532 * other NLP_FABRIC logins
3533 */
James Smart2e0fef82007-06-17 19:56:36 -05003534 lpfc_drop_node(vport, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04003535
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{
James Smart87af33f2007-10-27 13:37:43 -04003784 struct Scsi_Host *shost;
dea31012005-04-17 16:05:31 -05003785 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05003786 struct ls_rjt stat;
James Smart92d7f7b2007-06-17 19:56:38 -05003787 uint32_t *payload;
James Smart2e0fef82007-06-17 19:56:36 -05003788 uint32_t cmd, did, newnode, rjt_err = 0;
James Smarted957682007-06-17 19:56:37 -05003789 IOCB_t *icmd = &elsiocb->iocb;
dea31012005-04-17 16:05:31 -05003790
James Smart92d7f7b2007-06-17 19:56:38 -05003791 if (vport == NULL || elsiocb->context2 == NULL)
dea31012005-04-17 16:05:31 -05003792 goto dropit;
James Smart2e0fef82007-06-17 19:56:36 -05003793
dea31012005-04-17 16:05:31 -05003794 newnode = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05003795 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
3796 cmd = *payload;
James Smarted957682007-06-17 19:56:37 -05003797 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
3798 lpfc_post_buffer(phba, pring, 1, 1);
dea31012005-04-17 16:05:31 -05003799
James Smart858c9f62007-06-17 19:56:39 -05003800 did = icmd->un.rcvels.remoteID;
3801 if (icmd->ulpStatus) {
3802 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3803 "RCV Unsol ELS: status:x%x/x%x did:x%x",
3804 icmd->ulpStatus, icmd->un.ulpWord[4], did);
dea31012005-04-17 16:05:31 -05003805 goto dropit;
James Smart858c9f62007-06-17 19:56:39 -05003806 }
dea31012005-04-17 16:05:31 -05003807
3808 /* Check to see if link went down during discovery */
James Smarted957682007-06-17 19:56:37 -05003809 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05003810 goto dropit;
dea31012005-04-17 16:05:31 -05003811
James Smart92d7f7b2007-06-17 19:56:38 -05003812 /* Ignore traffic recevied during vport shutdown. */
3813 if (vport->load_flag & FC_UNLOADING)
3814 goto dropit;
3815
James Smart2e0fef82007-06-17 19:56:36 -05003816 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003817 if (!ndlp) {
dea31012005-04-17 16:05:31 -05003818 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003819 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
James Smarted957682007-06-17 19:56:37 -05003820 if (!ndlp)
dea31012005-04-17 16:05:31 -05003821 goto dropit;
dea31012005-04-17 16:05:31 -05003822
James Smart2e0fef82007-06-17 19:56:36 -05003823 lpfc_nlp_init(vport, ndlp, did);
James Smart98c9ea52007-10-27 13:37:33 -04003824 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05003825 newnode = 1;
3826 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) {
3827 ndlp->nlp_type |= NLP_FABRIC;
3828 }
3829 }
James Smart87af33f2007-10-27 13:37:43 -04003830 else {
3831 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
3832 /* This is simular to the new node path */
3833 lpfc_nlp_get(ndlp);
3834 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
3835 newnode = 1;
3836 }
3837 }
dea31012005-04-17 16:05:31 -05003838
3839 phba->fc_stat.elsRcvFrame++;
James Smart329f9bc2007-04-25 09:53:01 -04003840 if (elsiocb->context1)
3841 lpfc_nlp_put(elsiocb->context1);
3842 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05003843 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -05003844
3845 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
3846 cmd &= ELS_CMD_MASK;
3847 }
3848 /* ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04003849 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3850 "0112 ELS command x%x received from NPORT x%x "
3851 "Data: x%x\n", cmd, did, vport->port_state);
dea31012005-04-17 16:05:31 -05003852 switch (cmd) {
3853 case ELS_CMD_PLOGI:
James Smart858c9f62007-06-17 19:56:39 -05003854 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3855 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
3856 did, vport->port_state, ndlp->nlp_flag);
3857
dea31012005-04-17 16:05:31 -05003858 phba->fc_stat.elsRcvPLOGI++;
James Smart858c9f62007-06-17 19:56:39 -05003859 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
3860
3861 if (vport->port_state < LPFC_DISC_AUTH) {
3862 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05003863 break;
3864 }
James Smart87af33f2007-10-27 13:37:43 -04003865
3866 shost = lpfc_shost_from_vport(vport);
3867 spin_lock_irq(shost->host_lock);
3868 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
3869 spin_unlock_irq(shost->host_lock);
3870
James Smart2e0fef82007-06-17 19:56:36 -05003871 lpfc_disc_state_machine(vport, ndlp, elsiocb,
3872 NLP_EVT_RCV_PLOGI);
James Smart858c9f62007-06-17 19:56:39 -05003873
dea31012005-04-17 16:05:31 -05003874 break;
3875 case ELS_CMD_FLOGI:
James Smart858c9f62007-06-17 19:56:39 -05003876 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3877 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
3878 did, vport->port_state, ndlp->nlp_flag);
3879
dea31012005-04-17 16:05:31 -05003880 phba->fc_stat.elsRcvFLOGI++;
James Smart51ef4c22007-08-02 11:10:31 -04003881 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04003882 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04003883 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05003884 break;
3885 case ELS_CMD_LOGO:
James Smart858c9f62007-06-17 19:56:39 -05003886 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3887 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
3888 did, vport->port_state, ndlp->nlp_flag);
3889
dea31012005-04-17 16:05:31 -05003890 phba->fc_stat.elsRcvLOGO++;
James Smart2e0fef82007-06-17 19:56:36 -05003891 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05003892 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05003893 break;
3894 }
James Smart2e0fef82007-06-17 19:56:36 -05003895 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
dea31012005-04-17 16:05:31 -05003896 break;
3897 case ELS_CMD_PRLO:
James Smart858c9f62007-06-17 19:56:39 -05003898 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3899 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
3900 did, vport->port_state, ndlp->nlp_flag);
3901
dea31012005-04-17 16:05:31 -05003902 phba->fc_stat.elsRcvPRLO++;
James Smart2e0fef82007-06-17 19:56:36 -05003903 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05003904 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05003905 break;
3906 }
James Smart2e0fef82007-06-17 19:56:36 -05003907 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
dea31012005-04-17 16:05:31 -05003908 break;
3909 case ELS_CMD_RSCN:
3910 phba->fc_stat.elsRcvRSCN++;
James Smart51ef4c22007-08-02 11:10:31 -04003911 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04003912 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04003913 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05003914 break;
3915 case ELS_CMD_ADISC:
James Smart858c9f62007-06-17 19:56:39 -05003916 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3917 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
3918 did, vport->port_state, ndlp->nlp_flag);
3919
dea31012005-04-17 16:05:31 -05003920 phba->fc_stat.elsRcvADISC++;
James Smart2e0fef82007-06-17 19:56:36 -05003921 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05003922 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05003923 break;
3924 }
James Smart2e0fef82007-06-17 19:56:36 -05003925 lpfc_disc_state_machine(vport, ndlp, elsiocb,
3926 NLP_EVT_RCV_ADISC);
dea31012005-04-17 16:05:31 -05003927 break;
3928 case ELS_CMD_PDISC:
James Smart858c9f62007-06-17 19:56:39 -05003929 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3930 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
3931 did, vport->port_state, ndlp->nlp_flag);
3932
dea31012005-04-17 16:05:31 -05003933 phba->fc_stat.elsRcvPDISC++;
James Smart2e0fef82007-06-17 19:56:36 -05003934 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05003935 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05003936 break;
3937 }
James Smart2e0fef82007-06-17 19:56:36 -05003938 lpfc_disc_state_machine(vport, ndlp, elsiocb,
3939 NLP_EVT_RCV_PDISC);
dea31012005-04-17 16:05:31 -05003940 break;
3941 case ELS_CMD_FARPR:
James Smart858c9f62007-06-17 19:56:39 -05003942 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3943 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
3944 did, vport->port_state, ndlp->nlp_flag);
3945
dea31012005-04-17 16:05:31 -05003946 phba->fc_stat.elsRcvFARPR++;
James Smart2e0fef82007-06-17 19:56:36 -05003947 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05003948 break;
3949 case ELS_CMD_FARP:
James Smart858c9f62007-06-17 19:56:39 -05003950 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3951 "RCV FARP: did:x%x/ste:x%x flg:x%x",
3952 did, vport->port_state, ndlp->nlp_flag);
3953
dea31012005-04-17 16:05:31 -05003954 phba->fc_stat.elsRcvFARP++;
James Smart2e0fef82007-06-17 19:56:36 -05003955 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05003956 break;
3957 case ELS_CMD_FAN:
James Smart858c9f62007-06-17 19:56:39 -05003958 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3959 "RCV FAN: did:x%x/ste:x%x flg:x%x",
3960 did, vport->port_state, ndlp->nlp_flag);
3961
dea31012005-04-17 16:05:31 -05003962 phba->fc_stat.elsRcvFAN++;
James Smart2e0fef82007-06-17 19:56:36 -05003963 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05003964 break;
dea31012005-04-17 16:05:31 -05003965 case ELS_CMD_PRLI:
James Smart858c9f62007-06-17 19:56:39 -05003966 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3967 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
3968 did, vport->port_state, ndlp->nlp_flag);
3969
dea31012005-04-17 16:05:31 -05003970 phba->fc_stat.elsRcvPRLI++;
James Smart2e0fef82007-06-17 19:56:36 -05003971 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05003972 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05003973 break;
3974 }
James Smart2e0fef82007-06-17 19:56:36 -05003975 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
dea31012005-04-17 16:05:31 -05003976 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003977 case ELS_CMD_LIRR:
James Smart858c9f62007-06-17 19:56:39 -05003978 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3979 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
3980 did, vport->port_state, ndlp->nlp_flag);
3981
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003982 phba->fc_stat.elsRcvLIRR++;
James Smart2e0fef82007-06-17 19:56:36 -05003983 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04003984 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04003985 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003986 break;
3987 case ELS_CMD_RPS:
James Smart858c9f62007-06-17 19:56:39 -05003988 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3989 "RCV RPS: did:x%x/ste:x%x flg:x%x",
3990 did, vport->port_state, ndlp->nlp_flag);
3991
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003992 phba->fc_stat.elsRcvRPS++;
James Smart2e0fef82007-06-17 19:56:36 -05003993 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04003994 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04003995 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003996 break;
3997 case ELS_CMD_RPL:
James Smart858c9f62007-06-17 19:56:39 -05003998 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3999 "RCV RPL: did:x%x/ste:x%x flg:x%x",
4000 did, vport->port_state, ndlp->nlp_flag);
4001
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004002 phba->fc_stat.elsRcvRPL++;
James Smart2e0fef82007-06-17 19:56:36 -05004003 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04004004 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04004005 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004006 break;
dea31012005-04-17 16:05:31 -05004007 case ELS_CMD_RNID:
James Smart858c9f62007-06-17 19:56:39 -05004008 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4009 "RCV RNID: did:x%x/ste:x%x flg:x%x",
4010 did, vport->port_state, ndlp->nlp_flag);
4011
dea31012005-04-17 16:05:31 -05004012 phba->fc_stat.elsRcvRNID++;
James Smart2e0fef82007-06-17 19:56:36 -05004013 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04004014 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04004015 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05004016 break;
4017 default:
James Smart858c9f62007-06-17 19:56:39 -05004018 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4019 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
4020 cmd, did, vport->port_state);
4021
dea31012005-04-17 16:05:31 -05004022 /* Unsupported ELS command, reject */
James Smart858c9f62007-06-17 19:56:39 -05004023 rjt_err = LSRJT_INVALID_CMD;
dea31012005-04-17 16:05:31 -05004024
4025 /* Unknown ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04004026 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4027 "0115 Unknown ELS command x%x "
4028 "received from NPORT x%x\n", cmd, did);
James Smart87af33f2007-10-27 13:37:43 -04004029 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04004030 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05004031 break;
4032 }
4033
4034 /* check if need to LS_RJT received ELS cmd */
4035 if (rjt_err) {
James Smart92d7f7b2007-06-17 19:56:38 -05004036 memset(&stat, 0, sizeof(stat));
James Smart858c9f62007-06-17 19:56:39 -05004037 stat.un.b.lsRjtRsnCode = rjt_err;
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04004038 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart858c9f62007-06-17 19:56:39 -05004039 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
4040 NULL);
dea31012005-04-17 16:05:31 -05004041 }
4042
James Smarted957682007-06-17 19:56:37 -05004043 return;
4044
4045dropit:
James Smart98c9ea52007-10-27 13:37:33 -04004046 if (vport && !(vport->load_flag & FC_UNLOADING))
4047 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
James Smarte8b62012007-08-02 11:10:09 -04004048 "(%d):0111 Dropping received ELS cmd "
James Smarted957682007-06-17 19:56:37 -05004049 "Data: x%x x%x x%x\n",
James Smart98c9ea52007-10-27 13:37:33 -04004050 vport->vpi, icmd->ulpStatus,
James Smarte8b62012007-08-02 11:10:09 -04004051 icmd->un.ulpWord[4], icmd->ulpTimeout);
James Smarted957682007-06-17 19:56:37 -05004052 phba->fc_stat.elsRcvDrop++;
4053}
4054
James Smart92d7f7b2007-06-17 19:56:38 -05004055static struct lpfc_vport *
4056lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
4057{
4058 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -04004059 unsigned long flags;
James Smart92d7f7b2007-06-17 19:56:38 -05004060
James Smart549e55c2007-08-02 11:09:51 -04004061 spin_lock_irqsave(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05004062 list_for_each_entry(vport, &phba->port_list, listentry) {
James Smart549e55c2007-08-02 11:09:51 -04004063 if (vport->vpi == vpi) {
4064 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05004065 return vport;
James Smart549e55c2007-08-02 11:09:51 -04004066 }
James Smart92d7f7b2007-06-17 19:56:38 -05004067 }
James Smart549e55c2007-08-02 11:09:51 -04004068 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05004069 return NULL;
4070}
James Smarted957682007-06-17 19:56:37 -05004071
4072void
4073lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
4074 struct lpfc_iocbq *elsiocb)
4075{
4076 struct lpfc_vport *vport = phba->pport;
James Smarted957682007-06-17 19:56:37 -05004077 IOCB_t *icmd = &elsiocb->iocb;
James Smarted957682007-06-17 19:56:37 -05004078 dma_addr_t paddr;
James Smart92d7f7b2007-06-17 19:56:38 -05004079 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
4080 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
James Smarted957682007-06-17 19:56:37 -05004081
James Smart92d7f7b2007-06-17 19:56:38 -05004082 elsiocb->context2 = NULL;
4083 elsiocb->context3 = NULL;
4084
4085 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
4086 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
4087 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
4088 (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) {
James Smarted957682007-06-17 19:56:37 -05004089 phba->fc_stat.NoRcvBuf++;
4090 /* Not enough posted buffers; Try posting more buffers */
James Smart92d7f7b2007-06-17 19:56:38 -05004091 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
James Smarted957682007-06-17 19:56:37 -05004092 lpfc_post_buffer(phba, pring, 0, 1);
4093 return;
4094 }
4095
James Smart92d7f7b2007-06-17 19:56:38 -05004096 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
4097 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
4098 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
4099 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
4100 vport = phba->pport;
4101 else {
4102 uint16_t vpi = icmd->unsli3.rcvsli3.vpi;
4103 vport = lpfc_find_vport_by_vpid(phba, vpi);
4104 }
4105 }
4106 /* If there are no BDEs associated
4107 * with this IOCB, there is nothing to do.
4108 */
James Smarted957682007-06-17 19:56:37 -05004109 if (icmd->ulpBdeCount == 0)
4110 return;
4111
James Smart92d7f7b2007-06-17 19:56:38 -05004112 /* type of ELS cmd is first 32bit word
4113 * in packet
4114 */
James Smarted957682007-06-17 19:56:37 -05004115 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05004116 elsiocb->context2 = bdeBuf1;
James Smarted957682007-06-17 19:56:37 -05004117 } else {
4118 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
4119 icmd->un.cont64[0].addrLow);
James Smart92d7f7b2007-06-17 19:56:38 -05004120 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
4121 paddr);
James Smarted957682007-06-17 19:56:37 -05004122 }
4123
James Smart92d7f7b2007-06-17 19:56:38 -05004124 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
4125 /*
4126 * The different unsolicited event handlers would tell us
4127 * if they are done with "mp" by setting context2 to NULL.
4128 */
James Smart329f9bc2007-04-25 09:53:01 -04004129 lpfc_nlp_put(elsiocb->context1);
4130 elsiocb->context1 = NULL;
dea31012005-04-17 16:05:31 -05004131 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05004132 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
4133 elsiocb->context2 = NULL;
dea31012005-04-17 16:05:31 -05004134 }
James Smarted957682007-06-17 19:56:37 -05004135
4136 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
James Smart92d7f7b2007-06-17 19:56:38 -05004137 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
James Smarted957682007-06-17 19:56:37 -05004138 icmd->ulpBdeCount == 2) {
James Smart92d7f7b2007-06-17 19:56:38 -05004139 elsiocb->context2 = bdeBuf2;
4140 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
James Smarted957682007-06-17 19:56:37 -05004141 /* free mp if we are done with it */
4142 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05004143 lpfc_in_buf_free(phba, elsiocb->context2);
4144 elsiocb->context2 = NULL;
James Smarted957682007-06-17 19:56:37 -05004145 }
dea31012005-04-17 16:05:31 -05004146 }
dea31012005-04-17 16:05:31 -05004147}
James Smart92d7f7b2007-06-17 19:56:38 -05004148
4149void
4150lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
4151{
4152 struct lpfc_nodelist *ndlp, *ndlp_fdmi;
4153
4154 ndlp = lpfc_findnode_did(vport, NameServer_DID);
4155 if (!ndlp) {
4156 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
4157 if (!ndlp) {
4158 if (phba->fc_topology == TOPOLOGY_LOOP) {
4159 lpfc_disc_start(vport);
4160 return;
4161 }
4162 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04004163 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4164 "0251 NameServer login: no memory\n");
James Smart92d7f7b2007-06-17 19:56:38 -05004165 return;
4166 }
4167 lpfc_nlp_init(vport, ndlp, NameServer_DID);
4168 ndlp->nlp_type |= NLP_FABRIC;
4169 }
4170
4171 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
4172
4173 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
4174 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04004175 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4176 "0252 Cannot issue NameServer login\n");
James Smart92d7f7b2007-06-17 19:56:38 -05004177 return;
4178 }
4179
James Smart3de2a652007-08-02 11:09:59 -04004180 if (vport->cfg_fdmi_on) {
James Smart92d7f7b2007-06-17 19:56:38 -05004181 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
4182 GFP_KERNEL);
4183 if (ndlp_fdmi) {
4184 lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
4185 ndlp_fdmi->nlp_type |= NLP_FABRIC;
4186 ndlp_fdmi->nlp_state =
4187 NLP_STE_PLOGI_ISSUE;
4188 lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID,
4189 0);
4190 }
4191 }
4192 return;
4193}
4194
4195static void
4196lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4197{
4198 struct lpfc_vport *vport = pmb->vport;
4199 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4200 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
4201 MAILBOX_t *mb = &pmb->mb;
4202
4203 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
4204 lpfc_nlp_put(ndlp);
4205
4206 if (mb->mbxStatus) {
James Smarte8b62012007-08-02 11:10:09 -04004207 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
4208 "0915 Register VPI failed: 0x%x\n",
4209 mb->mbxStatus);
James Smart92d7f7b2007-06-17 19:56:38 -05004210
4211 switch (mb->mbxStatus) {
4212 case 0x11: /* unsupported feature */
4213 case 0x9603: /* max_vpi exceeded */
4214 /* giving up on vport registration */
4215 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4216 spin_lock_irq(shost->host_lock);
4217 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
4218 spin_unlock_irq(shost->host_lock);
4219 lpfc_can_disctmo(vport);
4220 break;
4221 default:
4222 /* Try to recover from this error */
4223 lpfc_mbx_unreg_vpi(vport);
4224 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
4225 lpfc_initial_fdisc(vport);
4226 break;
4227 }
4228
4229 } else {
4230 if (vport == phba->pport)
4231 lpfc_issue_fabric_reglogin(vport);
4232 else
4233 lpfc_do_scr_ns_plogi(phba, vport);
4234 }
4235 mempool_free(pmb, phba->mbox_mem_pool);
4236 return;
4237}
4238
4239void
4240lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
4241 struct lpfc_nodelist *ndlp)
4242{
4243 LPFC_MBOXQ_t *mbox;
4244
4245 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4246 if (mbox) {
4247 lpfc_reg_vpi(phba, vport->vpi, vport->fc_myDID, mbox);
4248 mbox->vport = vport;
4249 mbox->context2 = lpfc_nlp_get(ndlp);
4250 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
James Smart0b727fe2007-10-27 13:37:25 -04004251 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart92d7f7b2007-06-17 19:56:38 -05004252 == MBX_NOT_FINISHED) {
4253 mempool_free(mbox, phba->mbox_mem_pool);
4254 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
4255
4256 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04004257 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
4258 "0253 Register VPI: Can't send mbox\n");
James Smart92d7f7b2007-06-17 19:56:38 -05004259 }
4260 } else {
4261 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4262
James Smarte8b62012007-08-02 11:10:09 -04004263 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
4264 "0254 Register VPI: no memory\n");
James Smart92d7f7b2007-06-17 19:56:38 -05004265
4266 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
4267 lpfc_nlp_put(ndlp);
4268 }
4269}
4270
4271static void
4272lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4273 struct lpfc_iocbq *rspiocb)
4274{
4275 struct lpfc_vport *vport = cmdiocb->vport;
4276 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4277 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
4278 struct lpfc_nodelist *np;
4279 struct lpfc_nodelist *next_np;
4280 IOCB_t *irsp = &rspiocb->iocb;
4281 struct lpfc_iocbq *piocb;
4282
James Smarte8b62012007-08-02 11:10:09 -04004283 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4284 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
4285 irsp->ulpStatus, irsp->un.ulpWord[4],
4286 vport->fc_prevDID);
James Smart92d7f7b2007-06-17 19:56:38 -05004287 /* Since all FDISCs are being single threaded, we
4288 * must reset the discovery timer for ALL vports
4289 * waiting to send FDISC when one completes.
4290 */
4291 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
4292 lpfc_set_disctmo(piocb->vport);
4293 }
4294
James Smart858c9f62007-06-17 19:56:39 -05004295 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4296 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
4297 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
4298
James Smart92d7f7b2007-06-17 19:56:38 -05004299 if (irsp->ulpStatus) {
4300 /* Check for retry */
4301 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
4302 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05004303 /* FDISC failed */
James Smarte8b62012007-08-02 11:10:09 -04004304 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4305 "0124 FDISC failed. (%d/%d)\n",
4306 irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smart92d7f7b2007-06-17 19:56:38 -05004307 if (vport->fc_vport->vport_state == FC_VPORT_INITIALIZING)
4308 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4309
4310 lpfc_nlp_put(ndlp);
4311 /* giving up on FDISC. Cancel discovery timer */
4312 lpfc_can_disctmo(vport);
4313 } else {
4314 spin_lock_irq(shost->host_lock);
4315 vport->fc_flag |= FC_FABRIC;
4316 if (vport->phba->fc_topology == TOPOLOGY_LOOP)
4317 vport->fc_flag |= FC_PUBLIC_LOOP;
4318 spin_unlock_irq(shost->host_lock);
4319
4320 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
4321 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
4322 if ((vport->fc_prevDID != vport->fc_myDID) &&
4323 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
4324 /* If our NportID changed, we need to ensure all
4325 * remaining NPORTs get unreg_login'ed so we can
4326 * issue unreg_vpi.
4327 */
4328 list_for_each_entry_safe(np, next_np,
4329 &vport->fc_nodes, nlp_listp) {
4330 if (np->nlp_state != NLP_STE_NPR_NODE
4331 || !(np->nlp_flag & NLP_NPR_ADISC))
4332 continue;
4333 spin_lock_irq(shost->host_lock);
4334 np->nlp_flag &= ~NLP_NPR_ADISC;
4335 spin_unlock_irq(shost->host_lock);
4336 lpfc_unreg_rpi(vport, np);
4337 }
4338 lpfc_mbx_unreg_vpi(vport);
4339 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
4340 }
4341
4342 if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
4343 lpfc_register_new_vport(phba, vport, ndlp);
4344 else
4345 lpfc_do_scr_ns_plogi(phba, vport);
4346
4347 lpfc_nlp_put(ndlp); /* Free Fabric ndlp for vports */
4348 }
4349
4350out:
4351 lpfc_els_free_iocb(phba, cmdiocb);
4352}
4353
4354int
4355lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4356 uint8_t retry)
4357{
4358 struct lpfc_hba *phba = vport->phba;
4359 IOCB_t *icmd;
4360 struct lpfc_iocbq *elsiocb;
4361 struct serv_parm *sp;
4362 uint8_t *pcmd;
4363 uint16_t cmdsize;
4364 int did = ndlp->nlp_DID;
4365 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05004366
4367 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
4368 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
4369 ELS_CMD_FDISC);
4370 if (!elsiocb) {
James Smart92d7f7b2007-06-17 19:56:38 -05004371 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04004372 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4373 "0255 Issue FDISC: no IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05004374 return 1;
4375 }
4376
4377 icmd = &elsiocb->iocb;
4378 icmd->un.elsreq64.myID = 0;
4379 icmd->un.elsreq64.fl = 1;
4380
4381 /* For FDISC, Let FDISC rsp set the NPortID for this VPI */
4382 icmd->ulpCt_h = 1;
4383 icmd->ulpCt_l = 0;
4384
4385 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4386 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
4387 pcmd += sizeof(uint32_t); /* CSP Word 1 */
4388 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
4389 sp = (struct serv_parm *) pcmd;
4390 /* Setup CSPs accordingly for Fabric */
4391 sp->cmn.e_d_tov = 0;
4392 sp->cmn.w2.r_a_tov = 0;
4393 sp->cls1.classValid = 0;
4394 sp->cls2.seqDelivery = 1;
4395 sp->cls3.seqDelivery = 1;
4396
4397 pcmd += sizeof(uint32_t); /* CSP Word 2 */
4398 pcmd += sizeof(uint32_t); /* CSP Word 3 */
4399 pcmd += sizeof(uint32_t); /* CSP Word 4 */
4400 pcmd += sizeof(uint32_t); /* Port Name */
4401 memcpy(pcmd, &vport->fc_portname, 8);
4402 pcmd += sizeof(uint32_t); /* Node Name */
4403 pcmd += sizeof(uint32_t); /* Node Name */
4404 memcpy(pcmd, &vport->fc_nodename, 8);
4405
4406 lpfc_set_disctmo(vport);
4407
4408 phba->fc_stat.elsXmitFDISC++;
4409 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
4410
James Smart858c9f62007-06-17 19:56:39 -05004411 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4412 "Issue FDISC: did:x%x",
4413 did, 0, 0);
4414
James Smart92d7f7b2007-06-17 19:56:38 -05004415 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
4416 if (rc == IOCB_ERROR) {
4417 lpfc_els_free_iocb(phba, elsiocb);
James Smart92d7f7b2007-06-17 19:56:38 -05004418 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04004419 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4420 "0256 Issue FDISC: Cannot send IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05004421 return 1;
4422 }
4423 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
4424 vport->port_state = LPFC_FDISC;
4425 return 0;
4426}
4427
4428static void
4429lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4430 struct lpfc_iocbq *rspiocb)
4431{
4432 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05004433 IOCB_t *irsp;
4434
4435 irsp = &rspiocb->iocb;
4436 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4437 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
4438 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
James Smart92d7f7b2007-06-17 19:56:38 -05004439
4440 lpfc_els_free_iocb(phba, cmdiocb);
4441 vport->unreg_vpi_cmpl = VPORT_ERROR;
4442}
4443
4444int
4445lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4446{
4447 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4448 struct lpfc_hba *phba = vport->phba;
4449 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
4450 IOCB_t *icmd;
4451 struct lpfc_iocbq *elsiocb;
4452 uint8_t *pcmd;
4453 uint16_t cmdsize;
4454
4455 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
4456 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
4457 ELS_CMD_LOGO);
4458 if (!elsiocb)
4459 return 1;
4460
4461 icmd = &elsiocb->iocb;
4462 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4463 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
4464 pcmd += sizeof(uint32_t);
4465
4466 /* Fill in LOGO payload */
4467 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
4468 pcmd += sizeof(uint32_t);
4469 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
4470
James Smart858c9f62007-06-17 19:56:39 -05004471 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4472 "Issue LOGO npiv did:x%x flg:x%x",
4473 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4474
James Smart92d7f7b2007-06-17 19:56:38 -05004475 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
4476 spin_lock_irq(shost->host_lock);
4477 ndlp->nlp_flag |= NLP_LOGO_SND;
4478 spin_unlock_irq(shost->host_lock);
4479 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
4480 spin_lock_irq(shost->host_lock);
4481 ndlp->nlp_flag &= ~NLP_LOGO_SND;
4482 spin_unlock_irq(shost->host_lock);
4483 lpfc_els_free_iocb(phba, elsiocb);
4484 return 1;
4485 }
4486 return 0;
4487}
4488
4489void
4490lpfc_fabric_block_timeout(unsigned long ptr)
4491{
4492 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
4493 unsigned long iflags;
4494 uint32_t tmo_posted;
4495 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
4496 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
4497 if (!tmo_posted)
4498 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
4499 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
4500
4501 if (!tmo_posted) {
4502 spin_lock_irqsave(&phba->hbalock, iflags);
4503 if (phba->work_wait)
4504 lpfc_worker_wake_up(phba);
4505 spin_unlock_irqrestore(&phba->hbalock, iflags);
4506 }
4507}
4508
4509static void
4510lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
4511{
4512 struct lpfc_iocbq *iocb;
4513 unsigned long iflags;
4514 int ret;
4515 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
4516 IOCB_t *cmd;
4517
4518repeat:
4519 iocb = NULL;
4520 spin_lock_irqsave(&phba->hbalock, iflags);
4521 /* Post any pending iocb to the SLI layer */
4522 if (atomic_read(&phba->fabric_iocb_count) == 0) {
4523 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
4524 list);
4525 if (iocb)
4526 atomic_inc(&phba->fabric_iocb_count);
4527 }
4528 spin_unlock_irqrestore(&phba->hbalock, iflags);
4529 if (iocb) {
4530 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
4531 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
4532 iocb->iocb_flag |= LPFC_IO_FABRIC;
4533
James Smart858c9f62007-06-17 19:56:39 -05004534 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
4535 "Fabric sched1: ste:x%x",
4536 iocb->vport->port_state, 0, 0);
4537
James Smart92d7f7b2007-06-17 19:56:38 -05004538 ret = lpfc_sli_issue_iocb(phba, pring, iocb, 0);
4539
4540 if (ret == IOCB_ERROR) {
4541 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
4542 iocb->fabric_iocb_cmpl = NULL;
4543 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
4544 cmd = &iocb->iocb;
4545 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
4546 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
4547 iocb->iocb_cmpl(phba, iocb, iocb);
4548
4549 atomic_dec(&phba->fabric_iocb_count);
4550 goto repeat;
4551 }
4552 }
4553
4554 return;
4555}
4556
4557void
4558lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
4559{
4560 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
4561
4562 lpfc_resume_fabric_iocbs(phba);
4563 return;
4564}
4565
4566static void
4567lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
4568{
4569 int blocked;
4570
4571 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
4572 /* Start a timer to unblock fabric
4573 * iocbs after 100ms
4574 */
4575 if (!blocked)
4576 mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 );
4577
4578 return;
4579}
4580
4581static void
4582lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4583 struct lpfc_iocbq *rspiocb)
4584{
4585 struct ls_rjt stat;
4586
4587 if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
4588 BUG();
4589
4590 switch (rspiocb->iocb.ulpStatus) {
4591 case IOSTAT_NPORT_RJT:
4592 case IOSTAT_FABRIC_RJT:
4593 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
4594 lpfc_block_fabric_iocbs(phba);
4595 }
4596 break;
4597
4598 case IOSTAT_NPORT_BSY:
4599 case IOSTAT_FABRIC_BSY:
4600 lpfc_block_fabric_iocbs(phba);
4601 break;
4602
4603 case IOSTAT_LS_RJT:
4604 stat.un.lsRjtError =
4605 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
4606 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
4607 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
4608 lpfc_block_fabric_iocbs(phba);
4609 break;
4610 }
4611
4612 if (atomic_read(&phba->fabric_iocb_count) == 0)
4613 BUG();
4614
4615 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
4616 cmdiocb->fabric_iocb_cmpl = NULL;
4617 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
4618 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
4619
4620 atomic_dec(&phba->fabric_iocb_count);
4621 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
4622 /* Post any pending iocbs to HBA */
4623 lpfc_resume_fabric_iocbs(phba);
4624 }
4625}
4626
4627int
4628lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
4629{
4630 unsigned long iflags;
4631 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
4632 int ready;
4633 int ret;
4634
4635 if (atomic_read(&phba->fabric_iocb_count) > 1)
4636 BUG();
4637
4638 spin_lock_irqsave(&phba->hbalock, iflags);
4639 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
4640 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
4641
4642 spin_unlock_irqrestore(&phba->hbalock, iflags);
4643 if (ready) {
4644 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
4645 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
4646 iocb->iocb_flag |= LPFC_IO_FABRIC;
4647
James Smart858c9f62007-06-17 19:56:39 -05004648 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
4649 "Fabric sched2: ste:x%x",
4650 iocb->vport->port_state, 0, 0);
4651
James Smart92d7f7b2007-06-17 19:56:38 -05004652 atomic_inc(&phba->fabric_iocb_count);
4653 ret = lpfc_sli_issue_iocb(phba, pring, iocb, 0);
4654
4655 if (ret == IOCB_ERROR) {
4656 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
4657 iocb->fabric_iocb_cmpl = NULL;
4658 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
4659 atomic_dec(&phba->fabric_iocb_count);
4660 }
4661 } else {
4662 spin_lock_irqsave(&phba->hbalock, iflags);
4663 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
4664 spin_unlock_irqrestore(&phba->hbalock, iflags);
4665 ret = IOCB_SUCCESS;
4666 }
4667 return ret;
4668}
4669
4670
4671void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
4672{
4673 LIST_HEAD(completions);
4674 struct lpfc_hba *phba = vport->phba;
4675 struct lpfc_iocbq *tmp_iocb, *piocb;
4676 IOCB_t *cmd;
4677
4678 spin_lock_irq(&phba->hbalock);
4679 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
4680 list) {
4681
4682 if (piocb->vport != vport)
4683 continue;
4684
4685 list_move_tail(&piocb->list, &completions);
4686 }
4687 spin_unlock_irq(&phba->hbalock);
4688
4689 while (!list_empty(&completions)) {
4690 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
4691 list_del_init(&piocb->list);
4692
4693 cmd = &piocb->iocb;
4694 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
4695 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
4696 (piocb->iocb_cmpl) (phba, piocb, piocb);
4697 }
4698}
4699
4700void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
4701{
4702 LIST_HEAD(completions);
4703 struct lpfc_hba *phba = ndlp->vport->phba;
4704 struct lpfc_iocbq *tmp_iocb, *piocb;
4705 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
4706 IOCB_t *cmd;
4707
4708 spin_lock_irq(&phba->hbalock);
4709 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
4710 list) {
4711 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
4712
4713 list_move_tail(&piocb->list, &completions);
4714 }
4715 }
4716 spin_unlock_irq(&phba->hbalock);
4717
4718 while (!list_empty(&completions)) {
4719 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
4720 list_del_init(&piocb->list);
4721
4722 cmd = &piocb->iocb;
4723 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
4724 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
4725 (piocb->iocb_cmpl) (phba, piocb, piocb);
4726 }
4727}
4728
4729void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
4730{
4731 LIST_HEAD(completions);
4732 struct lpfc_iocbq *piocb;
4733 IOCB_t *cmd;
4734
4735 spin_lock_irq(&phba->hbalock);
4736 list_splice_init(&phba->fabric_iocb_list, &completions);
4737 spin_unlock_irq(&phba->hbalock);
4738
4739 while (!list_empty(&completions)) {
4740 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
4741 list_del_init(&piocb->list);
4742
4743 cmd = &piocb->iocb;
4744 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
4745 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
4746 (piocb->iocb_cmpl) (phba, piocb, piocb);
4747 }
4748}
4749
4750
4751void lpfc_fabric_abort_flogi(struct lpfc_hba *phba)
4752{
4753 LIST_HEAD(completions);
4754 struct lpfc_iocbq *tmp_iocb, *piocb;
4755 IOCB_t *cmd;
4756 struct lpfc_nodelist *ndlp;
4757
4758 spin_lock_irq(&phba->hbalock);
4759 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
4760 list) {
4761
4762 cmd = &piocb->iocb;
4763 ndlp = (struct lpfc_nodelist *) piocb->context1;
4764 if (cmd->ulpCommand == CMD_ELS_REQUEST64_CR &&
4765 ndlp != NULL &&
4766 ndlp->nlp_DID == Fabric_DID)
4767 list_move_tail(&piocb->list, &completions);
4768 }
4769 spin_unlock_irq(&phba->hbalock);
4770
4771 while (!list_empty(&completions)) {
4772 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
4773 list_del_init(&piocb->list);
4774
4775 cmd = &piocb->iocb;
4776 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
4777 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
4778 (piocb->iocb_cmpl) (phba, piocb, piocb);
4779 }
4780}
4781
4782