blob: c6b739dc6bc32c695e9721e32a5e4df79daa7900 [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 *******************************************************************/
James Smart09372822008-01-11 01:52:54 -050021/* See Fibre Channel protocol T11 FC-LS for details */
dea31012005-04-17 16:05:31 -050022#include <linux/blkdev.h>
23#include <linux/pci.h>
24#include <linux/interrupt.h>
25
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040026#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050027#include <scsi/scsi_device.h>
28#include <scsi/scsi_host.h>
29#include <scsi/scsi_transport_fc.h>
30
31#include "lpfc_hw.h"
32#include "lpfc_sli.h"
33#include "lpfc_disc.h"
34#include "lpfc_scsi.h"
35#include "lpfc.h"
36#include "lpfc_logmsg.h"
37#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050038#include "lpfc_vport.h"
James Smart858c9f62007-06-17 19:56:39 -050039#include "lpfc_debugfs.h"
dea31012005-04-17 16:05:31 -050040
41static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *,
42 struct lpfc_iocbq *);
James Smart92d7f7b2007-06-17 19:56:38 -050043static void lpfc_cmpl_fabric_iocb(struct lpfc_hba *, struct lpfc_iocbq *,
44 struct lpfc_iocbq *);
Adrian Bunka6ababd2007-11-05 18:07:33 +010045static void lpfc_fabric_abort_vport(struct lpfc_vport *vport);
46static int lpfc_issue_els_fdisc(struct lpfc_vport *vport,
47 struct lpfc_nodelist *ndlp, uint8_t retry);
48static int lpfc_issue_fabric_iocb(struct lpfc_hba *phba,
49 struct lpfc_iocbq *iocb);
50static void lpfc_register_new_vport(struct lpfc_hba *phba,
51 struct lpfc_vport *vport,
52 struct lpfc_nodelist *ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -050053
dea31012005-04-17 16:05:31 -050054static int lpfc_max_els_tries = 3;
55
James Smart858c9f62007-06-17 19:56:39 -050056int
James Smart2e0fef82007-06-17 19:56:36 -050057lpfc_els_chk_latt(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -050058{
James Smart2e0fef82007-06-17 19:56:36 -050059 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
60 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -050061 uint32_t ha_copy;
dea31012005-04-17 16:05:31 -050062
James Smart2e0fef82007-06-17 19:56:36 -050063 if (vport->port_state >= LPFC_VPORT_READY ||
64 phba->link_state == LPFC_LINK_DOWN)
dea31012005-04-17 16:05:31 -050065 return 0;
66
67 /* Read the HBA Host Attention Register */
dea31012005-04-17 16:05:31 -050068 ha_copy = readl(phba->HAregaddr);
dea31012005-04-17 16:05:31 -050069
70 if (!(ha_copy & HA_LATT))
71 return 0;
72
73 /* Pending Link Event during Discovery */
James Smarte8b62012007-08-02 11:10:09 -040074 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
75 "0237 Pending Link Event during "
76 "Discovery: State x%x\n",
77 phba->pport->port_state);
dea31012005-04-17 16:05:31 -050078
79 /* CLEAR_LA should re-enable link attention events and
80 * we should then imediately take a LATT event. The
81 * LATT processing should call lpfc_linkdown() which
82 * will cleanup any left over in-progress discovery
83 * events.
84 */
James Smart2e0fef82007-06-17 19:56:36 -050085 spin_lock_irq(shost->host_lock);
86 vport->fc_flag |= FC_ABORT_DISCOVERY;
87 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -050088
James Smart92d7f7b2007-06-17 19:56:38 -050089 if (phba->link_state != LPFC_CLEAR_LA)
James Smarted957682007-06-17 19:56:37 -050090 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -050091
Jamie Wellnitzc9f87352006-02-28 19:25:23 -050092 return 1;
dea31012005-04-17 16:05:31 -050093}
94
95static struct lpfc_iocbq *
James Smart2e0fef82007-06-17 19:56:36 -050096lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp,
97 uint16_t cmdSize, uint8_t retry,
98 struct lpfc_nodelist *ndlp, uint32_t did,
99 uint32_t elscmd)
dea31012005-04-17 16:05:31 -0500100{
James Smart2e0fef82007-06-17 19:56:36 -0500101 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400102 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -0500103 struct lpfc_dmabuf *pcmd, *prsp, *pbuflist;
104 struct ulp_bde64 *bpl;
105 IOCB_t *icmd;
106
dea31012005-04-17 16:05:31 -0500107
James Smart2e0fef82007-06-17 19:56:36 -0500108 if (!lpfc_is_link_up(phba))
109 return NULL;
dea31012005-04-17 16:05:31 -0500110
dea31012005-04-17 16:05:31 -0500111 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400112 elsiocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -0500113
114 if (elsiocb == NULL)
115 return NULL;
dea31012005-04-17 16:05:31 -0500116 icmd = &elsiocb->iocb;
117
118 /* fill in BDEs for command */
119 /* Allocate buffer for command payload */
James Smart98c9ea52007-10-27 13:37:33 -0400120 pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
121 if (pcmd)
122 pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500123 if (!pcmd || !pcmd->virt)
124 goto els_iocb_free_pcmb_exit;
dea31012005-04-17 16:05:31 -0500125
126 INIT_LIST_HEAD(&pcmd->list);
127
128 /* Allocate buffer for response payload */
129 if (expectRsp) {
James Smart92d7f7b2007-06-17 19:56:38 -0500130 prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -0500131 if (prsp)
132 prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
133 &prsp->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500134 if (!prsp || !prsp->virt)
135 goto els_iocb_free_prsp_exit;
dea31012005-04-17 16:05:31 -0500136 INIT_LIST_HEAD(&prsp->list);
137 } else {
138 prsp = NULL;
139 }
140
141 /* Allocate buffer for Buffer ptr list */
James Smart92d7f7b2007-06-17 19:56:38 -0500142 pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -0500143 if (pbuflist)
James Smarted957682007-06-17 19:56:37 -0500144 pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
145 &pbuflist->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500146 if (!pbuflist || !pbuflist->virt)
147 goto els_iocb_free_pbuf_exit;
dea31012005-04-17 16:05:31 -0500148
149 INIT_LIST_HEAD(&pbuflist->list);
150
151 icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
152 icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
153 icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BDL;
James Smart2e0fef82007-06-17 19:56:36 -0500154 icmd->un.elsreq64.remoteID = did; /* DID */
dea31012005-04-17 16:05:31 -0500155 if (expectRsp) {
James Smart92d7f7b2007-06-17 19:56:38 -0500156 icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
dea31012005-04-17 16:05:31 -0500157 icmd->ulpCommand = CMD_ELS_REQUEST64_CR;
James Smart2680eea2007-04-25 09:52:55 -0400158 icmd->ulpTimeout = phba->fc_ratov * 2;
dea31012005-04-17 16:05:31 -0500159 } else {
James Smart92d7f7b2007-06-17 19:56:38 -0500160 icmd->un.elsreq64.bdl.bdeSize = sizeof(struct ulp_bde64);
dea31012005-04-17 16:05:31 -0500161 icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
162 }
dea31012005-04-17 16:05:31 -0500163 icmd->ulpBdeCount = 1;
164 icmd->ulpLe = 1;
165 icmd->ulpClass = CLASS3;
166
James Smart92d7f7b2007-06-17 19:56:38 -0500167 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
168 icmd->un.elsreq64.myID = vport->fc_myDID;
169
170 /* For ELS_REQUEST64_CR, use the VPI by default */
171 icmd->ulpContext = vport->vpi;
172 icmd->ulpCt_h = 0;
173 icmd->ulpCt_l = 1;
174 }
175
dea31012005-04-17 16:05:31 -0500176 bpl = (struct ulp_bde64 *) pbuflist->virt;
177 bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys));
178 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys));
179 bpl->tus.f.bdeSize = cmdSize;
180 bpl->tus.f.bdeFlags = 0;
181 bpl->tus.w = le32_to_cpu(bpl->tus.w);
182
183 if (expectRsp) {
184 bpl++;
185 bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys));
186 bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys));
187 bpl->tus.f.bdeSize = FCELSSIZE;
188 bpl->tus.f.bdeFlags = BUFF_USE_RCV;
189 bpl->tus.w = le32_to_cpu(bpl->tus.w);
190 }
191
James Smartfa4066b2008-01-11 01:53:27 -0500192 /* prevent preparing iocb with NULL ndlp reference */
James Smart51ef4c22007-08-02 11:10:31 -0400193 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -0500194 if (!elsiocb->context1)
195 goto els_iocb_free_pbuf_exit;
James Smart329f9bc2007-04-25 09:53:01 -0400196 elsiocb->context2 = pcmd;
197 elsiocb->context3 = pbuflist;
dea31012005-04-17 16:05:31 -0500198 elsiocb->retry = retry;
James Smart2e0fef82007-06-17 19:56:36 -0500199 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -0500200 elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
201
202 if (prsp) {
203 list_add(&prsp->list, &pcmd->list);
204 }
dea31012005-04-17 16:05:31 -0500205 if (expectRsp) {
206 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400207 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
208 "0116 Xmit ELS command x%x to remote "
209 "NPORT x%x I/O tag: x%x, port state: x%x\n",
210 elscmd, did, elsiocb->iotag,
211 vport->port_state);
dea31012005-04-17 16:05:31 -0500212 } else {
213 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400214 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
215 "0117 Xmit ELS response x%x to remote "
216 "NPORT x%x I/O tag: x%x, size: x%x\n",
217 elscmd, ndlp->nlp_DID, elsiocb->iotag,
218 cmdSize);
dea31012005-04-17 16:05:31 -0500219 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500220 return elsiocb;
dea31012005-04-17 16:05:31 -0500221
James Smartfa4066b2008-01-11 01:53:27 -0500222els_iocb_free_pbuf_exit:
223 lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
224 kfree(pbuflist);
225
226els_iocb_free_prsp_exit:
227 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
228 kfree(prsp);
229
230els_iocb_free_pcmb_exit:
231 kfree(pcmd);
232 lpfc_sli_release_iocbq(phba, elsiocb);
233 return NULL;
234}
dea31012005-04-17 16:05:31 -0500235
236static int
James Smart92d7f7b2007-06-17 19:56:38 -0500237lpfc_issue_fabric_reglogin(struct lpfc_vport *vport)
238{
239 struct lpfc_hba *phba = vport->phba;
240 LPFC_MBOXQ_t *mbox;
241 struct lpfc_dmabuf *mp;
242 struct lpfc_nodelist *ndlp;
243 struct serv_parm *sp;
244 int rc;
James Smart98c9ea52007-10-27 13:37:33 -0400245 int err = 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500246
247 sp = &phba->fc_fabparam;
248 ndlp = lpfc_findnode_did(vport, Fabric_DID);
James Smart98c9ea52007-10-27 13:37:33 -0400249 if (!ndlp) {
250 err = 1;
James Smart92d7f7b2007-06-17 19:56:38 -0500251 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400252 }
James Smart92d7f7b2007-06-17 19:56:38 -0500253
254 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart98c9ea52007-10-27 13:37:33 -0400255 if (!mbox) {
256 err = 2;
James Smart92d7f7b2007-06-17 19:56:38 -0500257 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400258 }
James Smart92d7f7b2007-06-17 19:56:38 -0500259
260 vport->port_state = LPFC_FABRIC_CFG_LINK;
261 lpfc_config_link(phba, mbox);
262 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
263 mbox->vport = vport;
264
James Smart0b727fe2007-10-27 13:37:25 -0400265 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart98c9ea52007-10-27 13:37:33 -0400266 if (rc == MBX_NOT_FINISHED) {
267 err = 3;
James Smart92d7f7b2007-06-17 19:56:38 -0500268 goto fail_free_mbox;
James Smart98c9ea52007-10-27 13:37:33 -0400269 }
James Smart92d7f7b2007-06-17 19:56:38 -0500270
271 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart98c9ea52007-10-27 13:37:33 -0400272 if (!mbox) {
273 err = 4;
James Smart92d7f7b2007-06-17 19:56:38 -0500274 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400275 }
James Smart92d7f7b2007-06-17 19:56:38 -0500276 rc = lpfc_reg_login(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox,
277 0);
James Smart98c9ea52007-10-27 13:37:33 -0400278 if (rc) {
279 err = 5;
James Smart92d7f7b2007-06-17 19:56:38 -0500280 goto fail_free_mbox;
James Smart98c9ea52007-10-27 13:37:33 -0400281 }
James Smart92d7f7b2007-06-17 19:56:38 -0500282
283 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
284 mbox->vport = vport;
285 mbox->context2 = lpfc_nlp_get(ndlp);
286
James Smart0b727fe2007-10-27 13:37:25 -0400287 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart98c9ea52007-10-27 13:37:33 -0400288 if (rc == MBX_NOT_FINISHED) {
289 err = 6;
James Smart92d7f7b2007-06-17 19:56:38 -0500290 goto fail_issue_reg_login;
James Smart98c9ea52007-10-27 13:37:33 -0400291 }
James Smart92d7f7b2007-06-17 19:56:38 -0500292
293 return 0;
294
295fail_issue_reg_login:
296 lpfc_nlp_put(ndlp);
297 mp = (struct lpfc_dmabuf *) mbox->context1;
298 lpfc_mbuf_free(phba, mp->virt, mp->phys);
299 kfree(mp);
300fail_free_mbox:
301 mempool_free(mbox, phba->mbox_mem_pool);
302
303fail:
304 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -0400305 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smart98c9ea52007-10-27 13:37:33 -0400306 "0249 Cannot issue Register Fabric login: Err %d\n", err);
James Smart92d7f7b2007-06-17 19:56:38 -0500307 return -ENXIO;
308}
309
310static int
James Smart2e0fef82007-06-17 19:56:36 -0500311lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
312 struct serv_parm *sp, IOCB_t *irsp)
dea31012005-04-17 16:05:31 -0500313{
James Smart2e0fef82007-06-17 19:56:36 -0500314 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
315 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -0500316 struct lpfc_nodelist *np;
317 struct lpfc_nodelist *next_np;
dea31012005-04-17 16:05:31 -0500318
James Smart2e0fef82007-06-17 19:56:36 -0500319 spin_lock_irq(shost->host_lock);
320 vport->fc_flag |= FC_FABRIC;
321 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500322
323 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
324 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
325 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
326
327 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
328
329 if (phba->fc_topology == TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500330 spin_lock_irq(shost->host_lock);
331 vport->fc_flag |= FC_PUBLIC_LOOP;
332 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500333 } else {
334 /*
335 * If we are a N-port connected to a Fabric, fixup sparam's so
336 * logins to devices on remote loops work.
337 */
James Smart2e0fef82007-06-17 19:56:36 -0500338 vport->fc_sparam.cmn.altBbCredit = 1;
dea31012005-04-17 16:05:31 -0500339 }
340
James Smart2e0fef82007-06-17 19:56:36 -0500341 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
dea31012005-04-17 16:05:31 -0500342 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
James Smart92d7f7b2007-06-17 19:56:38 -0500343 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500344 ndlp->nlp_class_sup = 0;
345 if (sp->cls1.classValid)
346 ndlp->nlp_class_sup |= FC_COS_CLASS1;
347 if (sp->cls2.classValid)
348 ndlp->nlp_class_sup |= FC_COS_CLASS2;
349 if (sp->cls3.classValid)
350 ndlp->nlp_class_sup |= FC_COS_CLASS3;
351 if (sp->cls4.classValid)
352 ndlp->nlp_class_sup |= FC_COS_CLASS4;
353 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
354 sp->cmn.bbRcvSizeLsb;
355 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
356
James Smart92d7f7b2007-06-17 19:56:38 -0500357 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
358 if (sp->cmn.response_multiple_NPort) {
James Smarte8b62012007-08-02 11:10:09 -0400359 lpfc_printf_vlog(vport, KERN_WARNING,
360 LOG_ELS | LOG_VPORT,
361 "1816 FLOGI NPIV supported, "
362 "response data 0x%x\n",
363 sp->cmn.response_multiple_NPort);
James Smart92d7f7b2007-06-17 19:56:38 -0500364 phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
James Smart92d7f7b2007-06-17 19:56:38 -0500365 } else {
366 /* Because we asked f/w for NPIV it still expects us
James Smarte8b62012007-08-02 11:10:09 -0400367 to call reg_vnpid atleast for the physcial host */
368 lpfc_printf_vlog(vport, KERN_WARNING,
369 LOG_ELS | LOG_VPORT,
370 "1817 Fabric does not support NPIV "
371 "- configuring single port mode.\n");
James Smart92d7f7b2007-06-17 19:56:38 -0500372 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
373 }
374 }
375
376 if ((vport->fc_prevDID != vport->fc_myDID) &&
377 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
378
379 /* If our NportID changed, we need to ensure all
380 * remaining NPORTs get unreg_login'ed.
381 */
382 list_for_each_entry_safe(np, next_np,
383 &vport->fc_nodes, nlp_listp) {
384 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
385 !(np->nlp_flag & NLP_NPR_ADISC))
386 continue;
387 spin_lock_irq(shost->host_lock);
388 np->nlp_flag &= ~NLP_NPR_ADISC;
389 spin_unlock_irq(shost->host_lock);
390 lpfc_unreg_rpi(vport, np);
391 }
392 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
393 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -0500394 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500395 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -0500396 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500397 }
398 }
399
James Smart92d7f7b2007-06-17 19:56:38 -0500400 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -0500401
James Smart92d7f7b2007-06-17 19:56:38 -0500402 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
403 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) {
404 lpfc_register_new_vport(phba, vport, ndlp);
405 return 0;
406 }
407 lpfc_issue_fabric_reglogin(vport);
dea31012005-04-17 16:05:31 -0500408 return 0;
dea31012005-04-17 16:05:31 -0500409}
410
411/*
412 * We FLOGIed into an NPort, initiate pt2pt protocol
413 */
414static int
James Smart2e0fef82007-06-17 19:56:36 -0500415lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
416 struct serv_parm *sp)
dea31012005-04-17 16:05:31 -0500417{
James Smart2e0fef82007-06-17 19:56:36 -0500418 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
419 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500420 LPFC_MBOXQ_t *mbox;
421 int rc;
422
James Smart2e0fef82007-06-17 19:56:36 -0500423 spin_lock_irq(shost->host_lock);
424 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
425 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500426
427 phba->fc_edtov = FF_DEF_EDTOV;
428 phba->fc_ratov = FF_DEF_RATOV;
James Smart2e0fef82007-06-17 19:56:36 -0500429 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -0500430 sizeof(vport->fc_portname));
dea31012005-04-17 16:05:31 -0500431 if (rc >= 0) {
432 /* This side will initiate the PLOGI */
James Smart2e0fef82007-06-17 19:56:36 -0500433 spin_lock_irq(shost->host_lock);
434 vport->fc_flag |= FC_PT2PT_PLOGI;
435 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500436
437 /*
438 * N_Port ID cannot be 0, set our to LocalID the other
439 * side will be RemoteID.
440 */
441
442 /* not equal */
443 if (rc)
James Smart2e0fef82007-06-17 19:56:36 -0500444 vport->fc_myDID = PT2PT_LocalID;
dea31012005-04-17 16:05:31 -0500445
446 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
447 if (!mbox)
448 goto fail;
449
450 lpfc_config_link(phba, mbox);
451
452 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -0500453 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -0400454 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -0500455 if (rc == MBX_NOT_FINISHED) {
456 mempool_free(mbox, phba->mbox_mem_pool);
457 goto fail;
458 }
James Smart329f9bc2007-04-25 09:53:01 -0400459 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500460
James Smart2e0fef82007-06-17 19:56:36 -0500461 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
dea31012005-04-17 16:05:31 -0500462 if (!ndlp) {
463 /*
464 * Cannot find existing Fabric ndlp, so allocate a
465 * new one
466 */
467 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
468 if (!ndlp)
469 goto fail;
470
James Smart2e0fef82007-06-17 19:56:36 -0500471 lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID);
dea31012005-04-17 16:05:31 -0500472 }
473
474 memcpy(&ndlp->nlp_portname, &sp->portName,
James Smart2e0fef82007-06-17 19:56:36 -0500475 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500476 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
James Smart2e0fef82007-06-17 19:56:36 -0500477 sizeof(struct lpfc_name));
478 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
479 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500480 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500481 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500482 } else {
483 /* This side will wait for the PLOGI */
James Smart329f9bc2007-04-25 09:53:01 -0400484 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500485 }
486
James Smart09372822008-01-11 01:52:54 -0500487 /* If we are pt2pt with another NPort, force NPIV off! */
488 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
489
James Smart2e0fef82007-06-17 19:56:36 -0500490 spin_lock_irq(shost->host_lock);
491 vport->fc_flag |= FC_PT2PT;
492 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500493
494 /* Start discovery - this should just do CLEAR_LA */
James Smart2e0fef82007-06-17 19:56:36 -0500495 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -0500496 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500497fail:
dea31012005-04-17 16:05:31 -0500498 return -ENXIO;
499}
500
501static void
James Smart329f9bc2007-04-25 09:53:01 -0400502lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
503 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500504{
James Smart2e0fef82007-06-17 19:56:36 -0500505 struct lpfc_vport *vport = cmdiocb->vport;
506 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500507 IOCB_t *irsp = &rspiocb->iocb;
508 struct lpfc_nodelist *ndlp = cmdiocb->context1;
509 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
510 struct serv_parm *sp;
511 int rc;
512
513 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500514 if (lpfc_els_chk_latt(vport)) {
James Smartfa4066b2008-01-11 01:53:27 -0500515 /* One additional decrement on node reference count to
516 * trigger the release of the node
517 */
James Smart329f9bc2007-04-25 09:53:01 -0400518 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500519 goto out;
520 }
521
James Smart858c9f62007-06-17 19:56:39 -0500522 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
523 "FLOGI cmpl: status:x%x/x%x state:x%x",
524 irsp->ulpStatus, irsp->un.ulpWord[4],
525 vport->port_state);
526
dea31012005-04-17 16:05:31 -0500527 if (irsp->ulpStatus) {
528 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -0500529 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -0500530 goto out;
James Smart2e0fef82007-06-17 19:56:36 -0500531
dea31012005-04-17 16:05:31 -0500532 /* FLOGI failed, so there is no fabric */
James Smart2e0fef82007-06-17 19:56:36 -0500533 spin_lock_irq(shost->host_lock);
534 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
535 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500536
James Smart329f9bc2007-04-25 09:53:01 -0400537 /* If private loop, then allow max outstanding els to be
dea31012005-04-17 16:05:31 -0500538 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
539 * alpa map would take too long otherwise.
540 */
541 if (phba->alpa_map[0] == 0) {
James Smart3de2a652007-08-02 11:09:59 -0400542 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
dea31012005-04-17 16:05:31 -0500543 }
544
545 /* FLOGI failure */
James Smarte8b62012007-08-02 11:10:09 -0400546 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
547 "0100 FLOGI failure Data: x%x x%x "
548 "x%x\n",
549 irsp->ulpStatus, irsp->un.ulpWord[4],
550 irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -0500551 goto flogifail;
552 }
553
554 /*
555 * The FLogI succeeded. Sync the data for the CPU before
556 * accessing it.
557 */
558 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
559
560 sp = prsp->virt + sizeof(uint32_t);
561
562 /* FLOGI completes successfully */
James Smarte8b62012007-08-02 11:10:09 -0400563 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
564 "0101 FLOGI completes sucessfully "
565 "Data: x%x x%x x%x x%x\n",
566 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
567 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution);
dea31012005-04-17 16:05:31 -0500568
James Smart2e0fef82007-06-17 19:56:36 -0500569 if (vport->port_state == LPFC_FLOGI) {
dea31012005-04-17 16:05:31 -0500570 /*
571 * If Common Service Parameters indicate Nport
572 * we are point to point, if Fport we are Fabric.
573 */
574 if (sp->cmn.fPort)
James Smart2e0fef82007-06-17 19:56:36 -0500575 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
dea31012005-04-17 16:05:31 -0500576 else
James Smart2e0fef82007-06-17 19:56:36 -0500577 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
dea31012005-04-17 16:05:31 -0500578
579 if (!rc)
580 goto out;
581 }
582
583flogifail:
James Smart329f9bc2007-04-25 09:53:01 -0400584 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500585
James Smart858c9f62007-06-17 19:56:39 -0500586 if (!lpfc_error_lost_link(irsp)) {
dea31012005-04-17 16:05:31 -0500587 /* FLOGI failed, so just use loop map to make discovery list */
James Smart2e0fef82007-06-17 19:56:36 -0500588 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -0500589
590 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500591 lpfc_disc_start(vport);
James Smart87af33f2007-10-27 13:37:43 -0400592 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
593 ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) &&
594 (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) &&
595 (phba->link_state != LPFC_CLEAR_LA)) {
596 /* If FLOGI failed enable link interrupt. */
597 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -0500598 }
dea31012005-04-17 16:05:31 -0500599out:
600 lpfc_els_free_iocb(phba, cmdiocb);
601}
602
603static int
James Smart2e0fef82007-06-17 19:56:36 -0500604lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -0500605 uint8_t retry)
606{
James Smart2e0fef82007-06-17 19:56:36 -0500607 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500608 struct serv_parm *sp;
609 IOCB_t *icmd;
610 struct lpfc_iocbq *elsiocb;
611 struct lpfc_sli_ring *pring;
612 uint8_t *pcmd;
613 uint16_t cmdsize;
614 uint32_t tmo;
615 int rc;
616
617 pring = &phba->sli.ring[LPFC_ELS_RING];
618
James Smart92d7f7b2007-06-17 19:56:38 -0500619 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart2e0fef82007-06-17 19:56:36 -0500620 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
621 ndlp->nlp_DID, ELS_CMD_FLOGI);
James Smart92d7f7b2007-06-17 19:56:38 -0500622
James Smart488d1462006-03-07 15:02:37 -0500623 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500624 return 1;
dea31012005-04-17 16:05:31 -0500625
626 icmd = &elsiocb->iocb;
627 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
628
629 /* For FLOGI request, remainder of payload is service parameters */
630 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -0500631 pcmd += sizeof(uint32_t);
632 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -0500633 sp = (struct serv_parm *) pcmd;
634
635 /* Setup CSPs accordingly for Fabric */
636 sp->cmn.e_d_tov = 0;
637 sp->cmn.w2.r_a_tov = 0;
638 sp->cls1.classValid = 0;
639 sp->cls2.seqDelivery = 1;
640 sp->cls3.seqDelivery = 1;
641 if (sp->cmn.fcphLow < FC_PH3)
642 sp->cmn.fcphLow = FC_PH3;
643 if (sp->cmn.fcphHigh < FC_PH3)
644 sp->cmn.fcphHigh = FC_PH3;
645
James Smart92d7f7b2007-06-17 19:56:38 -0500646 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
647 sp->cmn.request_multiple_Nport = 1;
648
649 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
650 icmd->ulpCt_h = 1;
651 icmd->ulpCt_l = 0;
652 }
653
James Smart858c9f62007-06-17 19:56:39 -0500654 if (phba->fc_topology != TOPOLOGY_LOOP) {
655 icmd->un.elsreq64.myID = 0;
656 icmd->un.elsreq64.fl = 1;
657 }
658
dea31012005-04-17 16:05:31 -0500659 tmo = phba->fc_ratov;
660 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
James Smart2e0fef82007-06-17 19:56:36 -0500661 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -0500662 phba->fc_ratov = tmo;
663
664 phba->fc_stat.elsXmitFLOGI++;
665 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
James Smart858c9f62007-06-17 19:56:39 -0500666
667 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
668 "Issue FLOGI: opt:x%x",
669 phba->sli3_options, 0, 0);
670
James Smart92d7f7b2007-06-17 19:56:38 -0500671 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
dea31012005-04-17 16:05:31 -0500672 if (rc == IOCB_ERROR) {
673 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500674 return 1;
dea31012005-04-17 16:05:31 -0500675 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500676 return 0;
dea31012005-04-17 16:05:31 -0500677}
678
679int
James Smart2e0fef82007-06-17 19:56:36 -0500680lpfc_els_abort_flogi(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500681{
682 struct lpfc_sli_ring *pring;
683 struct lpfc_iocbq *iocb, *next_iocb;
684 struct lpfc_nodelist *ndlp;
685 IOCB_t *icmd;
686
687 /* Abort outstanding I/O on NPort <nlp_DID> */
688 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -0400689 "0201 Abort outstanding I/O on NPort x%x\n",
690 Fabric_DID);
dea31012005-04-17 16:05:31 -0500691
692 pring = &phba->sli.ring[LPFC_ELS_RING];
693
694 /*
695 * Check the txcmplq for an iocb that matches the nport the driver is
696 * searching for.
697 */
James Smart2e0fef82007-06-17 19:56:36 -0500698 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500699 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
700 icmd = &iocb->iocb;
James Smart2e0fef82007-06-17 19:56:36 -0500701 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR &&
702 icmd->un.elsreq64.bdl.ulpIoTag32) {
dea31012005-04-17 16:05:31 -0500703 ndlp = (struct lpfc_nodelist *)(iocb->context1);
James Smart92d7f7b2007-06-17 19:56:38 -0500704 if (ndlp && (ndlp->nlp_DID == Fabric_DID)) {
James Smart07951072007-04-25 09:51:38 -0400705 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
James Smart92d7f7b2007-06-17 19:56:38 -0500706 }
dea31012005-04-17 16:05:31 -0500707 }
708 }
James Smart2e0fef82007-06-17 19:56:36 -0500709 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500710
711 return 0;
712}
713
714int
James Smart2e0fef82007-06-17 19:56:36 -0500715lpfc_initial_flogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -0500716{
James Smart2e0fef82007-06-17 19:56:36 -0500717 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500718 struct lpfc_nodelist *ndlp;
719
James Smart98c9ea52007-10-27 13:37:33 -0400720 vport->port_state = LPFC_FLOGI;
721 lpfc_set_disctmo(vport);
722
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500723 /* First look for the Fabric ndlp */
James Smart2e0fef82007-06-17 19:56:36 -0500724 ndlp = lpfc_findnode_did(vport, Fabric_DID);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500725 if (!ndlp) {
dea31012005-04-17 16:05:31 -0500726 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500727 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
728 if (!ndlp)
729 return 0;
James Smart2e0fef82007-06-17 19:56:36 -0500730 lpfc_nlp_init(vport, ndlp, Fabric_DID);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500731 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500732 lpfc_dequeue_node(vport, ndlp);
dea31012005-04-17 16:05:31 -0500733 }
James Smart87af33f2007-10-27 13:37:43 -0400734
James Smart2e0fef82007-06-17 19:56:36 -0500735 if (lpfc_issue_els_flogi(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -0500736 /* This decrement of reference count to node shall kick off
737 * the release of the node.
738 */
James Smart329f9bc2007-04-25 09:53:01 -0400739 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500740 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500741 return 1;
dea31012005-04-17 16:05:31 -0500742}
743
James Smart92d7f7b2007-06-17 19:56:38 -0500744int
745lpfc_initial_fdisc(struct lpfc_vport *vport)
746{
747 struct lpfc_hba *phba = vport->phba;
748 struct lpfc_nodelist *ndlp;
749
750 /* First look for the Fabric ndlp */
751 ndlp = lpfc_findnode_did(vport, Fabric_DID);
752 if (!ndlp) {
753 /* Cannot find existing Fabric ndlp, so allocate a new one */
754 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
755 if (!ndlp)
756 return 0;
757 lpfc_nlp_init(vport, ndlp, Fabric_DID);
758 } else {
759 lpfc_dequeue_node(vport, ndlp);
760 }
761 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -0500762 /* decrement node reference count to trigger the release of
763 * the node.
764 */
James Smart92d7f7b2007-06-17 19:56:38 -0500765 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -0500766 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500767 }
768 return 1;
769}
James Smart87af33f2007-10-27 13:37:43 -0400770
771void
James Smart2e0fef82007-06-17 19:56:36 -0500772lpfc_more_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -0500773{
774 int sentplogi;
775
James Smart2e0fef82007-06-17 19:56:36 -0500776 if (vport->num_disc_nodes)
777 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -0500778
779 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
James Smarte8b62012007-08-02 11:10:09 -0400780 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
781 "0232 Continue discovery with %d PLOGIs to go "
782 "Data: x%x x%x x%x\n",
783 vport->num_disc_nodes, vport->fc_plogi_cnt,
784 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -0500785 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -0500786 if (vport->fc_flag & FC_NLP_MORE)
787 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
788 sentplogi = lpfc_els_disc_plogi(vport);
789
dea31012005-04-17 16:05:31 -0500790 return;
791}
792
James Smart488d1462006-03-07 15:02:37 -0500793static struct lpfc_nodelist *
James Smart92d7f7b2007-06-17 19:56:38 -0500794lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
James Smart488d1462006-03-07 15:02:37 -0500795 struct lpfc_nodelist *ndlp)
796{
James Smart2e0fef82007-06-17 19:56:36 -0500797 struct lpfc_vport *vport = ndlp->vport;
James Smart488d1462006-03-07 15:02:37 -0500798 struct lpfc_nodelist *new_ndlp;
James Smart0ff10d42008-01-11 01:52:36 -0500799 struct lpfc_rport_data *rdata;
800 struct fc_rport *rport;
James Smart488d1462006-03-07 15:02:37 -0500801 struct serv_parm *sp;
James Smart92d7f7b2007-06-17 19:56:38 -0500802 uint8_t name[sizeof(struct lpfc_name)];
James Smart488d1462006-03-07 15:02:37 -0500803 uint32_t rc;
804
James Smart2fb9bd82006-12-02 13:33:57 -0500805 /* Fabric nodes can have the same WWPN so we don't bother searching
806 * by WWPN. Just return the ndlp that was given to us.
807 */
808 if (ndlp->nlp_type & NLP_FABRIC)
809 return ndlp;
810
James Smart92d7f7b2007-06-17 19:56:38 -0500811 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
James Smart685f0bf2007-04-25 09:53:08 -0400812 memset(name, 0, sizeof(struct lpfc_name));
James Smart488d1462006-03-07 15:02:37 -0500813
James Smart685f0bf2007-04-25 09:53:08 -0400814 /* Now we find out if the NPort we are logging into, matches the WWPN
James Smart488d1462006-03-07 15:02:37 -0500815 * we have for that ndlp. If not, we have some work to do.
816 */
James Smart2e0fef82007-06-17 19:56:36 -0500817 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
James Smart488d1462006-03-07 15:02:37 -0500818
James Smart92795652006-07-06 15:50:02 -0400819 if (new_ndlp == ndlp)
James Smart488d1462006-03-07 15:02:37 -0500820 return ndlp;
James Smart488d1462006-03-07 15:02:37 -0500821
822 if (!new_ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -0500823 rc = memcmp(&ndlp->nlp_portname, name,
824 sizeof(struct lpfc_name));
James Smart92795652006-07-06 15:50:02 -0400825 if (!rc)
826 return ndlp;
James Smart488d1462006-03-07 15:02:37 -0500827 new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
828 if (!new_ndlp)
829 return ndlp;
830
James Smart2e0fef82007-06-17 19:56:36 -0500831 lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID);
James Smart488d1462006-03-07 15:02:37 -0500832 }
833
James Smart2e0fef82007-06-17 19:56:36 -0500834 lpfc_unreg_rpi(vport, new_ndlp);
James Smart488d1462006-03-07 15:02:37 -0500835 new_ndlp->nlp_DID = ndlp->nlp_DID;
James Smart92795652006-07-06 15:50:02 -0400836 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
James Smart0ff10d42008-01-11 01:52:36 -0500837
838 if (ndlp->nlp_flag & NLP_NPR_2B_DISC)
839 new_ndlp->nlp_flag |= NLP_NPR_2B_DISC;
840 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
841
James Smart2e0fef82007-06-17 19:56:36 -0500842 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
James Smart488d1462006-03-07 15:02:37 -0500843
James Smart2e0fef82007-06-17 19:56:36 -0500844 /* Move this back to NPR state */
James Smart87af33f2007-10-27 13:37:43 -0400845 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
846 /* The new_ndlp is replacing ndlp totally, so we need
847 * to put ndlp on UNUSED list and try to free it.
848 */
James Smart0ff10d42008-01-11 01:52:36 -0500849
850 /* Fix up the rport accordingly */
851 rport = ndlp->rport;
852 if (rport) {
853 rdata = rport->dd_data;
854 if (rdata->pnode == ndlp) {
855 lpfc_nlp_put(ndlp);
856 ndlp->rport = NULL;
857 rdata->pnode = lpfc_nlp_get(new_ndlp);
858 new_ndlp->rport = rport;
859 }
860 new_ndlp->nlp_type = ndlp->nlp_type;
861 }
862
James Smart2e0fef82007-06-17 19:56:36 -0500863 lpfc_drop_node(vport, ndlp);
James Smart87af33f2007-10-27 13:37:43 -0400864 }
James Smart92795652006-07-06 15:50:02 -0400865 else {
James Smart2e0fef82007-06-17 19:56:36 -0500866 lpfc_unreg_rpi(vport, ndlp);
James Smart92795652006-07-06 15:50:02 -0400867 ndlp->nlp_DID = 0; /* Two ndlps cannot have the same did */
James Smart2e0fef82007-06-17 19:56:36 -0500868 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smart92795652006-07-06 15:50:02 -0400869 }
James Smart488d1462006-03-07 15:02:37 -0500870 return new_ndlp;
871}
872
James Smart87af33f2007-10-27 13:37:43 -0400873void
874lpfc_end_rscn(struct lpfc_vport *vport)
875{
876 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
877
878 if (vport->fc_flag & FC_RSCN_MODE) {
879 /*
880 * Check to see if more RSCNs came in while we were
881 * processing this one.
882 */
883 if (vport->fc_rscn_id_cnt ||
884 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
885 lpfc_els_handle_rscn(vport);
886 else {
887 spin_lock_irq(shost->host_lock);
888 vport->fc_flag &= ~FC_RSCN_MODE;
889 spin_unlock_irq(shost->host_lock);
890 }
891 }
892}
893
dea31012005-04-17 16:05:31 -0500894static void
James Smart2e0fef82007-06-17 19:56:36 -0500895lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
896 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500897{
James Smart2e0fef82007-06-17 19:56:36 -0500898 struct lpfc_vport *vport = cmdiocb->vport;
899 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500900 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -0500901 struct lpfc_nodelist *ndlp;
James Smart92795652006-07-06 15:50:02 -0400902 struct lpfc_dmabuf *prsp;
dea31012005-04-17 16:05:31 -0500903 int disc, rc, did, type;
904
dea31012005-04-17 16:05:31 -0500905 /* we pass cmdiocb to state machine which needs rspiocb as well */
906 cmdiocb->context_un.rsp_iocb = rspiocb;
907
908 irsp = &rspiocb->iocb;
James Smart858c9f62007-06-17 19:56:39 -0500909 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
910 "PLOGI cmpl: status:x%x/x%x did:x%x",
911 irsp->ulpStatus, irsp->un.ulpWord[4],
912 irsp->un.elsreq64.remoteID);
913
James Smart2e0fef82007-06-17 19:56:36 -0500914 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
James Smarted957682007-06-17 19:56:37 -0500915 if (!ndlp) {
James Smarte8b62012007-08-02 11:10:09 -0400916 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
917 "0136 PLOGI completes to NPort x%x "
918 "with no ndlp. Data: x%x x%x x%x\n",
919 irsp->un.elsreq64.remoteID,
920 irsp->ulpStatus, irsp->un.ulpWord[4],
921 irsp->ulpIoTag);
James Smart488d1462006-03-07 15:02:37 -0500922 goto out;
James Smarted957682007-06-17 19:56:37 -0500923 }
dea31012005-04-17 16:05:31 -0500924
925 /* Since ndlp can be freed in the disc state machine, note if this node
926 * is being used during discovery.
927 */
James Smart2e0fef82007-06-17 19:56:36 -0500928 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500929 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
James Smart488d1462006-03-07 15:02:37 -0500930 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500931 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500932 rc = 0;
933
934 /* PLOGI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -0400935 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
936 "0102 PLOGI completes to NPort x%x "
937 "Data: x%x x%x x%x x%x x%x\n",
938 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
939 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -0500940 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500941 if (lpfc_els_chk_latt(vport)) {
942 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500943 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500944 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500945 goto out;
946 }
947
948 /* ndlp could be freed in DSM, save these values now */
949 type = ndlp->nlp_type;
950 did = ndlp->nlp_DID;
951
952 if (irsp->ulpStatus) {
953 /* Check for retry */
954 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
955 /* ELS command is being retried */
956 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -0500957 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500958 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500959 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500960 }
961 goto out;
962 }
dea31012005-04-17 16:05:31 -0500963 /* PLOGI failed */
964 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart858c9f62007-06-17 19:56:39 -0500965 if (lpfc_error_lost_link(irsp)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500966 rc = NLP_STE_FREED_NODE;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500967 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500968 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -0500969 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -0500970 }
971 } else {
972 /* Good status, call state machine */
James Smart92795652006-07-06 15:50:02 -0400973 prsp = list_entry(((struct lpfc_dmabuf *)
James Smart92d7f7b2007-06-17 19:56:38 -0500974 cmdiocb->context2)->list.next,
975 struct lpfc_dmabuf, list);
976 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -0500977 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -0500978 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -0500979 }
980
James Smart2e0fef82007-06-17 19:56:36 -0500981 if (disc && vport->num_disc_nodes) {
dea31012005-04-17 16:05:31 -0500982 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -0500983 lpfc_more_plogi(vport);
dea31012005-04-17 16:05:31 -0500984
James Smart2e0fef82007-06-17 19:56:36 -0500985 if (vport->num_disc_nodes == 0) {
986 spin_lock_irq(shost->host_lock);
987 vport->fc_flag &= ~FC_NDISC_ACTIVE;
988 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500989
James Smart2e0fef82007-06-17 19:56:36 -0500990 lpfc_can_disctmo(vport);
James Smart87af33f2007-10-27 13:37:43 -0400991 lpfc_end_rscn(vport);
dea31012005-04-17 16:05:31 -0500992 }
993 }
994
995out:
996 lpfc_els_free_iocb(phba, cmdiocb);
997 return;
998}
999
1000int
James Smart2e0fef82007-06-17 19:56:36 -05001001lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
dea31012005-04-17 16:05:31 -05001002{
James Smart2e0fef82007-06-17 19:56:36 -05001003 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001004 struct serv_parm *sp;
1005 IOCB_t *icmd;
James Smart98c9ea52007-10-27 13:37:33 -04001006 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05001007 struct lpfc_iocbq *elsiocb;
1008 struct lpfc_sli_ring *pring;
1009 struct lpfc_sli *psli;
1010 uint8_t *pcmd;
1011 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05001012 int ret;
dea31012005-04-17 16:05:31 -05001013
1014 psli = &phba->sli;
1015 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1016
James Smart98c9ea52007-10-27 13:37:33 -04001017 ndlp = lpfc_findnode_did(vport, did);
1018 /* If ndlp if not NULL, we will bump the reference count on it */
1019
James Smart92d7f7b2007-06-17 19:56:38 -05001020 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart98c9ea52007-10-27 13:37:33 -04001021 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
James Smart2e0fef82007-06-17 19:56:36 -05001022 ELS_CMD_PLOGI);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001023 if (!elsiocb)
1024 return 1;
dea31012005-04-17 16:05:31 -05001025
1026 icmd = &elsiocb->iocb;
1027 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1028
1029 /* For PLOGI request, remainder of payload is service parameters */
1030 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001031 pcmd += sizeof(uint32_t);
1032 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001033 sp = (struct serv_parm *) pcmd;
1034
1035 if (sp->cmn.fcphLow < FC_PH_4_3)
1036 sp->cmn.fcphLow = FC_PH_4_3;
1037
1038 if (sp->cmn.fcphHigh < FC_PH3)
1039 sp->cmn.fcphHigh = FC_PH3;
1040
James Smart858c9f62007-06-17 19:56:39 -05001041 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1042 "Issue PLOGI: did:x%x",
1043 did, 0, 0);
1044
dea31012005-04-17 16:05:31 -05001045 phba->fc_stat.elsXmitPLOGI++;
1046 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
James Smart92d7f7b2007-06-17 19:56:38 -05001047 ret = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
1048
1049 if (ret == IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05001050 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001051 return 1;
dea31012005-04-17 16:05:31 -05001052 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001053 return 0;
dea31012005-04-17 16:05:31 -05001054}
1055
1056static void
James Smart2e0fef82007-06-17 19:56:36 -05001057lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1058 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001059{
James Smart2e0fef82007-06-17 19:56:36 -05001060 struct lpfc_vport *vport = cmdiocb->vport;
1061 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001062 IOCB_t *irsp;
1063 struct lpfc_sli *psli;
1064 struct lpfc_nodelist *ndlp;
1065
1066 psli = &phba->sli;
1067 /* we pass cmdiocb to state machine which needs rspiocb as well */
1068 cmdiocb->context_un.rsp_iocb = rspiocb;
1069
1070 irsp = &(rspiocb->iocb);
1071 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
James Smart2e0fef82007-06-17 19:56:36 -05001072 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001073 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001074 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001075
James Smart858c9f62007-06-17 19:56:39 -05001076 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1077 "PRLI cmpl: status:x%x/x%x did:x%x",
1078 irsp->ulpStatus, irsp->un.ulpWord[4],
1079 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05001080 /* PRLI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001081 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1082 "0103 PRLI completes to NPort x%x "
1083 "Data: x%x x%x x%x x%x\n",
1084 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1085 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001086
James Smart2e0fef82007-06-17 19:56:36 -05001087 vport->fc_prli_sent--;
dea31012005-04-17 16:05:31 -05001088 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001089 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05001090 goto out;
1091
1092 if (irsp->ulpStatus) {
1093 /* Check for retry */
1094 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1095 /* ELS command is being retried */
1096 goto out;
1097 }
1098 /* PRLI failed */
1099 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart858c9f62007-06-17 19:56:39 -05001100 if (lpfc_error_lost_link(irsp)) {
dea31012005-04-17 16:05:31 -05001101 goto out;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001102 } else {
James Smart2e0fef82007-06-17 19:56:36 -05001103 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001104 NLP_EVT_CMPL_PRLI);
dea31012005-04-17 16:05:31 -05001105 }
1106 } else {
1107 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05001108 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001109 NLP_EVT_CMPL_PRLI);
dea31012005-04-17 16:05:31 -05001110 }
1111
1112out:
1113 lpfc_els_free_iocb(phba, cmdiocb);
1114 return;
1115}
1116
1117int
James Smart2e0fef82007-06-17 19:56:36 -05001118lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001119 uint8_t retry)
1120{
James Smart2e0fef82007-06-17 19:56:36 -05001121 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1122 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001123 PRLI *npr;
1124 IOCB_t *icmd;
1125 struct lpfc_iocbq *elsiocb;
1126 struct lpfc_sli_ring *pring;
1127 struct lpfc_sli *psli;
1128 uint8_t *pcmd;
1129 uint16_t cmdsize;
1130
1131 psli = &phba->sli;
1132 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1133
James Smart92d7f7b2007-06-17 19:56:38 -05001134 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
James Smart2e0fef82007-06-17 19:56:36 -05001135 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1136 ndlp->nlp_DID, ELS_CMD_PRLI);
James Smart488d1462006-03-07 15:02:37 -05001137 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001138 return 1;
dea31012005-04-17 16:05:31 -05001139
1140 icmd = &elsiocb->iocb;
1141 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1142
1143 /* For PRLI request, remainder of payload is service parameters */
James Smart92d7f7b2007-06-17 19:56:38 -05001144 memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t)));
dea31012005-04-17 16:05:31 -05001145 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
James Smart92d7f7b2007-06-17 19:56:38 -05001146 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001147
1148 /* For PRLI, remainder of payload is PRLI parameter page */
1149 npr = (PRLI *) pcmd;
1150 /*
1151 * If our firmware version is 3.20 or later,
1152 * set the following bits for FC-TAPE support.
1153 */
1154 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
1155 npr->ConfmComplAllowed = 1;
1156 npr->Retry = 1;
1157 npr->TaskRetryIdReq = 1;
1158 }
1159 npr->estabImagePair = 1;
1160 npr->readXferRdyDis = 1;
1161
1162 /* For FCP support */
1163 npr->prliType = PRLI_FCP_TYPE;
1164 npr->initiatorFunc = 1;
1165
James Smart858c9f62007-06-17 19:56:39 -05001166 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1167 "Issue PRLI: did:x%x",
1168 ndlp->nlp_DID, 0, 0);
1169
dea31012005-04-17 16:05:31 -05001170 phba->fc_stat.elsXmitPRLI++;
1171 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
James Smart2e0fef82007-06-17 19:56:36 -05001172 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001173 ndlp->nlp_flag |= NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001174 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001175 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05001176 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001177 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001178 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001179 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001180 return 1;
dea31012005-04-17 16:05:31 -05001181 }
James Smart2e0fef82007-06-17 19:56:36 -05001182 vport->fc_prli_sent++;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001183 return 0;
dea31012005-04-17 16:05:31 -05001184}
1185
James Smart0ff10d42008-01-11 01:52:36 -05001186void
James Smart2e0fef82007-06-17 19:56:36 -05001187lpfc_more_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001188{
1189 int sentadisc;
1190
James Smart2e0fef82007-06-17 19:56:36 -05001191 if (vport->num_disc_nodes)
1192 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001193 /* Continue discovery with <num_disc_nodes> ADISCs to go */
James Smarte8b62012007-08-02 11:10:09 -04001194 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1195 "0210 Continue discovery with %d ADISCs to go "
1196 "Data: x%x x%x x%x\n",
1197 vport->num_disc_nodes, vport->fc_adisc_cnt,
1198 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001199 /* Check to see if there are more ADISCs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001200 if (vport->fc_flag & FC_NLP_MORE) {
1201 lpfc_set_disctmo(vport);
1202 /* go thru NPR nodes and issue any remaining ELS ADISCs */
1203 sentadisc = lpfc_els_disc_adisc(vport);
dea31012005-04-17 16:05:31 -05001204 }
1205 return;
1206}
1207
1208static void
James Smart2e0fef82007-06-17 19:56:36 -05001209lpfc_rscn_disc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001210{
James Smart858c9f62007-06-17 19:56:39 -05001211 lpfc_can_disctmo(vport);
1212
dea31012005-04-17 16:05:31 -05001213 /* RSCN discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001214 /* go thru NPR nodes and issue ELS PLOGIs */
1215 if (vport->fc_npr_cnt)
1216 if (lpfc_els_disc_plogi(vport))
dea31012005-04-17 16:05:31 -05001217 return;
James Smart2e0fef82007-06-17 19:56:36 -05001218
James Smart87af33f2007-10-27 13:37:43 -04001219 lpfc_end_rscn(vport);
dea31012005-04-17 16:05:31 -05001220}
1221
1222static void
James Smart2e0fef82007-06-17 19:56:36 -05001223lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1224 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001225{
James Smart2e0fef82007-06-17 19:56:36 -05001226 struct lpfc_vport *vport = cmdiocb->vport;
1227 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001228 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001229 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001230 int disc;
dea31012005-04-17 16:05:31 -05001231
1232 /* we pass cmdiocb to state machine which needs rspiocb as well */
1233 cmdiocb->context_un.rsp_iocb = rspiocb;
1234
1235 irsp = &(rspiocb->iocb);
1236 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
dea31012005-04-17 16:05:31 -05001237
James Smart858c9f62007-06-17 19:56:39 -05001238 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1239 "ADISC cmpl: status:x%x/x%x did:x%x",
1240 irsp->ulpStatus, irsp->un.ulpWord[4],
1241 ndlp->nlp_DID);
1242
dea31012005-04-17 16:05:31 -05001243 /* Since ndlp can be freed in the disc state machine, note if this node
1244 * is being used during discovery.
1245 */
James Smart2e0fef82007-06-17 19:56:36 -05001246 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001247 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001248 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001249 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001250 /* ADISC completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001251 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1252 "0104 ADISC completes to NPort x%x "
1253 "Data: x%x x%x x%x x%x x%x\n",
1254 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1255 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001256 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001257 if (lpfc_els_chk_latt(vport)) {
1258 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001259 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001260 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001261 goto out;
1262 }
1263
1264 if (irsp->ulpStatus) {
1265 /* Check for retry */
1266 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1267 /* ELS command is being retried */
1268 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05001269 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001270 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001271 spin_unlock_irq(shost->host_lock);
1272 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001273 }
1274 goto out;
1275 }
1276 /* ADISC failed */
1277 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart858c9f62007-06-17 19:56:39 -05001278 if (!lpfc_error_lost_link(irsp)) {
James Smart2e0fef82007-06-17 19:56:36 -05001279 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart858c9f62007-06-17 19:56:39 -05001280 NLP_EVT_CMPL_ADISC);
dea31012005-04-17 16:05:31 -05001281 }
1282 } else {
1283 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05001284 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
dea31012005-04-17 16:05:31 -05001285 NLP_EVT_CMPL_ADISC);
1286 }
1287
James Smart2e0fef82007-06-17 19:56:36 -05001288 if (disc && vport->num_disc_nodes) {
dea31012005-04-17 16:05:31 -05001289 /* Check to see if there are more ADISCs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001290 lpfc_more_adisc(vport);
dea31012005-04-17 16:05:31 -05001291
1292 /* Check to see if we are done with ADISC authentication */
James Smart2e0fef82007-06-17 19:56:36 -05001293 if (vport->num_disc_nodes == 0) {
James Smart92d7f7b2007-06-17 19:56:38 -05001294 /* If we get here, there is nothing left to ADISC */
1295 /*
1296 * For NPIV, cmpl_reg_vpi will set port_state to READY,
1297 * and continue discovery.
1298 */
1299 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
1300 !(vport->fc_flag & FC_RSCN_MODE)) {
1301 lpfc_issue_reg_vpi(phba, vport);
1302 goto out;
1303 }
1304 /*
1305 * For SLI2, we need to set port_state to READY
1306 * and continue discovery.
1307 */
1308 if (vport->port_state < LPFC_VPORT_READY) {
1309 /* If we get here, there is nothing to ADISC */
James Smarted957682007-06-17 19:56:37 -05001310 if (vport->port_type == LPFC_PHYSICAL_PORT)
James Smart2e0fef82007-06-17 19:56:36 -05001311 lpfc_issue_clear_la(phba, vport);
James Smart92d7f7b2007-06-17 19:56:38 -05001312
1313 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
1314 vport->num_disc_nodes = 0;
1315 /* go thru NPR list, issue ELS PLOGIs */
1316 if (vport->fc_npr_cnt)
1317 lpfc_els_disc_plogi(vport);
1318
1319 if (!vport->num_disc_nodes) {
1320 spin_lock_irq(shost->host_lock);
1321 vport->fc_flag &=
1322 ~FC_NDISC_ACTIVE;
1323 spin_unlock_irq(
1324 shost->host_lock);
1325 lpfc_can_disctmo(vport);
1326 }
1327 }
1328 vport->port_state = LPFC_VPORT_READY;
dea31012005-04-17 16:05:31 -05001329 } else {
James Smart2e0fef82007-06-17 19:56:36 -05001330 lpfc_rscn_disc(vport);
dea31012005-04-17 16:05:31 -05001331 }
1332 }
1333 }
dea31012005-04-17 16:05:31 -05001334out:
1335 lpfc_els_free_iocb(phba, cmdiocb);
1336 return;
1337}
1338
1339int
James Smart2e0fef82007-06-17 19:56:36 -05001340lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001341 uint8_t retry)
1342{
James Smart2e0fef82007-06-17 19:56:36 -05001343 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1344 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001345 ADISC *ap;
1346 IOCB_t *icmd;
1347 struct lpfc_iocbq *elsiocb;
James Smart2e0fef82007-06-17 19:56:36 -05001348 struct lpfc_sli *psli = &phba->sli;
1349 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05001350 uint8_t *pcmd;
1351 uint16_t cmdsize;
1352
James Smart92d7f7b2007-06-17 19:56:38 -05001353 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
James Smart2e0fef82007-06-17 19:56:36 -05001354 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1355 ndlp->nlp_DID, ELS_CMD_ADISC);
James Smart488d1462006-03-07 15:02:37 -05001356 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001357 return 1;
dea31012005-04-17 16:05:31 -05001358
1359 icmd = &elsiocb->iocb;
1360 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1361
1362 /* For ADISC request, remainder of payload is service parameters */
1363 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
James Smart92d7f7b2007-06-17 19:56:38 -05001364 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001365
1366 /* Fill in ADISC payload */
1367 ap = (ADISC *) pcmd;
1368 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05001369 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
1370 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05001371 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05001372
James Smart858c9f62007-06-17 19:56:39 -05001373 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1374 "Issue ADISC: did:x%x",
1375 ndlp->nlp_DID, 0, 0);
1376
dea31012005-04-17 16:05:31 -05001377 phba->fc_stat.elsXmitADISC++;
1378 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
James Smart2e0fef82007-06-17 19:56:36 -05001379 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001380 ndlp->nlp_flag |= NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001381 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001382 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05001383 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001384 ndlp->nlp_flag &= ~NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001385 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001386 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001387 return 1;
dea31012005-04-17 16:05:31 -05001388 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001389 return 0;
dea31012005-04-17 16:05:31 -05001390}
1391
1392static void
James Smart2e0fef82007-06-17 19:56:36 -05001393lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1394 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001395{
James Smart2e0fef82007-06-17 19:56:36 -05001396 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1397 struct lpfc_vport *vport = ndlp->vport;
1398 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001399 IOCB_t *irsp;
1400 struct lpfc_sli *psli;
dea31012005-04-17 16:05:31 -05001401
1402 psli = &phba->sli;
1403 /* we pass cmdiocb to state machine which needs rspiocb as well */
1404 cmdiocb->context_un.rsp_iocb = rspiocb;
1405
1406 irsp = &(rspiocb->iocb);
James Smart2e0fef82007-06-17 19:56:36 -05001407 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001408 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001409 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001410
James Smart858c9f62007-06-17 19:56:39 -05001411 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1412 "LOGO cmpl: status:x%x/x%x did:x%x",
1413 irsp->ulpStatus, irsp->un.ulpWord[4],
1414 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05001415 /* LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001416 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1417 "0105 LOGO completes to NPort x%x "
1418 "Data: x%x x%x x%x x%x\n",
1419 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1420 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001421 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001422 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05001423 goto out;
1424
James Smart92d7f7b2007-06-17 19:56:38 -05001425 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
1426 /* NLP_EVT_DEVICE_RM should unregister the RPI
1427 * which should abort all outstanding IOs.
1428 */
1429 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1430 NLP_EVT_DEVICE_RM);
1431 goto out;
1432 }
1433
dea31012005-04-17 16:05:31 -05001434 if (irsp->ulpStatus) {
1435 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -05001436 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -05001437 /* ELS command is being retried */
1438 goto out;
dea31012005-04-17 16:05:31 -05001439 /* LOGO failed */
1440 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart858c9f62007-06-17 19:56:39 -05001441 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05001442 goto out;
James Smart858c9f62007-06-17 19:56:39 -05001443 else
James Smart2e0fef82007-06-17 19:56:36 -05001444 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001445 NLP_EVT_CMPL_LOGO);
dea31012005-04-17 16:05:31 -05001446 } else {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001447 /* Good status, call state machine.
1448 * This will unregister the rpi if needed.
1449 */
James Smart2e0fef82007-06-17 19:56:36 -05001450 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001451 NLP_EVT_CMPL_LOGO);
dea31012005-04-17 16:05:31 -05001452 }
1453
1454out:
1455 lpfc_els_free_iocb(phba, cmdiocb);
1456 return;
1457}
1458
1459int
James Smart2e0fef82007-06-17 19:56:36 -05001460lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001461 uint8_t retry)
1462{
James Smart2e0fef82007-06-17 19:56:36 -05001463 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1464 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001465 IOCB_t *icmd;
1466 struct lpfc_iocbq *elsiocb;
1467 struct lpfc_sli_ring *pring;
1468 struct lpfc_sli *psli;
1469 uint8_t *pcmd;
1470 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05001471 int rc;
dea31012005-04-17 16:05:31 -05001472
1473 psli = &phba->sli;
1474 pring = &psli->ring[LPFC_ELS_RING];
1475
James Smart98c9ea52007-10-27 13:37:33 -04001476 spin_lock_irq(shost->host_lock);
1477 if (ndlp->nlp_flag & NLP_LOGO_SND) {
1478 spin_unlock_irq(shost->host_lock);
1479 return 0;
1480 }
1481 spin_unlock_irq(shost->host_lock);
1482
James Smart92d7f7b2007-06-17 19:56:38 -05001483 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
James Smart2e0fef82007-06-17 19:56:36 -05001484 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1485 ndlp->nlp_DID, ELS_CMD_LOGO);
James Smart488d1462006-03-07 15:02:37 -05001486 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001487 return 1;
dea31012005-04-17 16:05:31 -05001488
1489 icmd = &elsiocb->iocb;
1490 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1491 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
James Smart92d7f7b2007-06-17 19:56:38 -05001492 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001493
1494 /* Fill in LOGO payload */
James Smart2e0fef82007-06-17 19:56:36 -05001495 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05001496 pcmd += sizeof(uint32_t);
1497 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05001498
James Smart858c9f62007-06-17 19:56:39 -05001499 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1500 "Issue LOGO: did:x%x",
1501 ndlp->nlp_DID, 0, 0);
1502
dea31012005-04-17 16:05:31 -05001503 phba->fc_stat.elsXmitLOGO++;
1504 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
James Smart2e0fef82007-06-17 19:56:36 -05001505 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001506 ndlp->nlp_flag |= NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001507 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05001508 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
1509
1510 if (rc == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05001511 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001512 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001513 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001514 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001515 return 1;
dea31012005-04-17 16:05:31 -05001516 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001517 return 0;
dea31012005-04-17 16:05:31 -05001518}
1519
1520static void
James Smart2e0fef82007-06-17 19:56:36 -05001521lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1522 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001523{
James Smart2e0fef82007-06-17 19:56:36 -05001524 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -05001525 IOCB_t *irsp;
1526
1527 irsp = &rspiocb->iocb;
1528
James Smart858c9f62007-06-17 19:56:39 -05001529 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1530 "ELS cmd cmpl: status:x%x/x%x did:x%x",
1531 irsp->ulpStatus, irsp->un.ulpWord[4],
1532 irsp->un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05001533 /* ELS cmd tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04001534 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1535 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
1536 irsp->ulpIoTag, irsp->ulpStatus,
1537 irsp->un.ulpWord[4], irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -05001538 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001539 lpfc_els_chk_latt(vport);
dea31012005-04-17 16:05:31 -05001540 lpfc_els_free_iocb(phba, cmdiocb);
1541 return;
1542}
1543
1544int
James Smart2e0fef82007-06-17 19:56:36 -05001545lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05001546{
James Smart2e0fef82007-06-17 19:56:36 -05001547 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001548 IOCB_t *icmd;
1549 struct lpfc_iocbq *elsiocb;
1550 struct lpfc_sli_ring *pring;
1551 struct lpfc_sli *psli;
1552 uint8_t *pcmd;
1553 uint16_t cmdsize;
1554 struct lpfc_nodelist *ndlp;
1555
1556 psli = &phba->sli;
1557 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
James Smart92d7f7b2007-06-17 19:56:38 -05001558 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001559 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1560 if (!ndlp)
1561 return 1;
dea31012005-04-17 16:05:31 -05001562
James Smart2e0fef82007-06-17 19:56:36 -05001563 lpfc_nlp_init(vport, ndlp, nportid);
dea31012005-04-17 16:05:31 -05001564
James Smart2e0fef82007-06-17 19:56:36 -05001565 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1566 ndlp->nlp_DID, ELS_CMD_SCR);
1567
James Smart488d1462006-03-07 15:02:37 -05001568 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05001569 /* This will trigger the release of the node just
1570 * allocated
1571 */
James Smart329f9bc2007-04-25 09:53:01 -04001572 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001573 return 1;
dea31012005-04-17 16:05:31 -05001574 }
1575
1576 icmd = &elsiocb->iocb;
1577 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1578
1579 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
James Smart92d7f7b2007-06-17 19:56:38 -05001580 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001581
1582 /* For SCR, remainder of payload is SCR parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05001583 memset(pcmd, 0, sizeof(SCR));
dea31012005-04-17 16:05:31 -05001584 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
1585
James Smart858c9f62007-06-17 19:56:39 -05001586 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1587 "Issue SCR: did:x%x",
1588 ndlp->nlp_DID, 0, 0);
1589
dea31012005-04-17 16:05:31 -05001590 phba->fc_stat.elsXmitSCR++;
1591 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
dea31012005-04-17 16:05:31 -05001592 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05001593 /* The additional lpfc_nlp_put will cause the following
1594 * lpfc_els_free_iocb routine to trigger the rlease of
1595 * the node.
1596 */
James Smart329f9bc2007-04-25 09:53:01 -04001597 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001598 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001599 return 1;
dea31012005-04-17 16:05:31 -05001600 }
James Smartfa4066b2008-01-11 01:53:27 -05001601 /* This will cause the callback-function lpfc_cmpl_els_cmd to
1602 * trigger the release of node.
1603 */
James Smart329f9bc2007-04-25 09:53:01 -04001604 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001605 return 0;
dea31012005-04-17 16:05:31 -05001606}
1607
1608static int
James Smart2e0fef82007-06-17 19:56:36 -05001609lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05001610{
James Smart2e0fef82007-06-17 19:56:36 -05001611 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001612 IOCB_t *icmd;
1613 struct lpfc_iocbq *elsiocb;
1614 struct lpfc_sli_ring *pring;
1615 struct lpfc_sli *psli;
1616 FARP *fp;
1617 uint8_t *pcmd;
1618 uint32_t *lp;
1619 uint16_t cmdsize;
1620 struct lpfc_nodelist *ondlp;
1621 struct lpfc_nodelist *ndlp;
1622
1623 psli = &phba->sli;
1624 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
James Smart92d7f7b2007-06-17 19:56:38 -05001625 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001626 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1627 if (!ndlp)
1628 return 1;
dea31012005-04-17 16:05:31 -05001629
James Smart2e0fef82007-06-17 19:56:36 -05001630 lpfc_nlp_init(vport, ndlp, nportid);
1631
1632 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1633 ndlp->nlp_DID, ELS_CMD_RNID);
James Smart488d1462006-03-07 15:02:37 -05001634 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05001635 /* This will trigger the release of the node just
1636 * allocated
1637 */
James Smart329f9bc2007-04-25 09:53:01 -04001638 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001639 return 1;
dea31012005-04-17 16:05:31 -05001640 }
1641
1642 icmd = &elsiocb->iocb;
1643 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1644
1645 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
James Smart92d7f7b2007-06-17 19:56:38 -05001646 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001647
1648 /* Fill in FARPR payload */
1649 fp = (FARP *) (pcmd);
James Smart92d7f7b2007-06-17 19:56:38 -05001650 memset(fp, 0, sizeof(FARP));
dea31012005-04-17 16:05:31 -05001651 lp = (uint32_t *) pcmd;
1652 *lp++ = be32_to_cpu(nportid);
James Smart2e0fef82007-06-17 19:56:36 -05001653 *lp++ = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05001654 fp->Rflags = 0;
1655 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
1656
James Smart92d7f7b2007-06-17 19:56:38 -05001657 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
1658 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05001659 ondlp = lpfc_findnode_did(vport, nportid);
1660 if (ondlp) {
dea31012005-04-17 16:05:31 -05001661 memcpy(&fp->OportName, &ondlp->nlp_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05001662 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05001663 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05001664 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05001665 }
1666
James Smart858c9f62007-06-17 19:56:39 -05001667 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1668 "Issue FARPR: did:x%x",
1669 ndlp->nlp_DID, 0, 0);
1670
dea31012005-04-17 16:05:31 -05001671 phba->fc_stat.elsXmitFARPR++;
1672 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
dea31012005-04-17 16:05:31 -05001673 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05001674 /* The additional lpfc_nlp_put will cause the following
1675 * lpfc_els_free_iocb routine to trigger the release of
1676 * the node.
1677 */
James Smart329f9bc2007-04-25 09:53:01 -04001678 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001679 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001680 return 1;
dea31012005-04-17 16:05:31 -05001681 }
James Smartfa4066b2008-01-11 01:53:27 -05001682 /* This will cause the callback-function lpfc_cmpl_els_cmd to
1683 * trigger the release of the node.
1684 */
James Smart329f9bc2007-04-25 09:53:01 -04001685 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001686 return 0;
dea31012005-04-17 16:05:31 -05001687}
1688
1689void
James Smart2e0fef82007-06-17 19:56:36 -05001690lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
James Smartfdcebe22006-03-07 15:04:01 -05001691{
James Smart2e0fef82007-06-17 19:56:36 -05001692 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1693
1694 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05001695 nlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001696 spin_unlock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05001697 del_timer_sync(&nlp->nlp_delayfunc);
1698 nlp->nlp_last_elscmd = 0;
1699
1700 if (!list_empty(&nlp->els_retry_evt.evt_listp))
1701 list_del_init(&nlp->els_retry_evt.evt_listp);
1702
1703 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
James Smart2e0fef82007-06-17 19:56:36 -05001704 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05001705 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001706 spin_unlock_irq(shost->host_lock);
1707 if (vport->num_disc_nodes) {
James Smartfdcebe22006-03-07 15:04:01 -05001708 /* Check to see if there are more
1709 * PLOGIs to be sent
1710 */
James Smart2e0fef82007-06-17 19:56:36 -05001711 lpfc_more_plogi(vport);
James Smartfdcebe22006-03-07 15:04:01 -05001712
James Smart2e0fef82007-06-17 19:56:36 -05001713 if (vport->num_disc_nodes == 0) {
1714 spin_lock_irq(shost->host_lock);
1715 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1716 spin_unlock_irq(shost->host_lock);
1717 lpfc_can_disctmo(vport);
James Smarted957682007-06-17 19:56:37 -05001718 lpfc_end_rscn(vport);
James Smartfdcebe22006-03-07 15:04:01 -05001719 }
1720 }
1721 }
1722 return;
1723}
1724
1725void
dea31012005-04-17 16:05:31 -05001726lpfc_els_retry_delay(unsigned long ptr)
1727{
James Smart2e0fef82007-06-17 19:56:36 -05001728 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
1729 struct lpfc_vport *vport = ndlp->vport;
James Smart2e0fef82007-06-17 19:56:36 -05001730 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05001731 unsigned long flags;
James Smart2e0fef82007-06-17 19:56:36 -05001732 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
dea31012005-04-17 16:05:31 -05001733
James Smart2e0fef82007-06-17 19:56:36 -05001734 ndlp = (struct lpfc_nodelist *) ptr;
1735 phba = ndlp->vport->phba;
dea31012005-04-17 16:05:31 -05001736 evtp = &ndlp->els_retry_evt;
1737
James Smart92d7f7b2007-06-17 19:56:38 -05001738 spin_lock_irqsave(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05001739 if (!list_empty(&evtp->evt_listp)) {
James Smart92d7f7b2007-06-17 19:56:38 -05001740 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05001741 return;
1742 }
1743
James Smartfa4066b2008-01-11 01:53:27 -05001744 /* We need to hold the node by incrementing the reference
1745 * count until the queued work is done
1746 */
1747 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
dea31012005-04-17 16:05:31 -05001748 evtp->evt = LPFC_EVT_ELS_RETRY;
1749 list_add_tail(&evtp->evt_listp, &phba->work_list);
1750 if (phba->work_wait)
James Smart92d7f7b2007-06-17 19:56:38 -05001751 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05001752
James Smart92d7f7b2007-06-17 19:56:38 -05001753 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05001754 return;
1755}
1756
1757void
1758lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
1759{
James Smart2e0fef82007-06-17 19:56:36 -05001760 struct lpfc_vport *vport = ndlp->vport;
1761 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1762 uint32_t cmd, did, retry;
dea31012005-04-17 16:05:31 -05001763
James Smart2e0fef82007-06-17 19:56:36 -05001764 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001765 did = ndlp->nlp_DID;
1766 cmd = ndlp->nlp_last_elscmd;
1767 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05001768
1769 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
James Smart2e0fef82007-06-17 19:56:36 -05001770 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001771 return;
1772 }
1773
1774 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001775 spin_unlock_irq(shost->host_lock);
James Smart1a169682006-03-07 15:04:06 -05001776 /*
1777 * If a discovery event readded nlp_delayfunc after timer
1778 * firing and before processing the timer, cancel the
1779 * nlp_delayfunc.
1780 */
1781 del_timer_sync(&ndlp->nlp_delayfunc);
dea31012005-04-17 16:05:31 -05001782 retry = ndlp->nlp_retry;
1783
1784 switch (cmd) {
1785 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05001786 lpfc_issue_els_flogi(vport, ndlp, retry);
dea31012005-04-17 16:05:31 -05001787 break;
1788 case ELS_CMD_PLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05001789 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001790 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001791 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05001792 }
dea31012005-04-17 16:05:31 -05001793 break;
1794 case ELS_CMD_ADISC:
James Smart2e0fef82007-06-17 19:56:36 -05001795 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001796 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001797 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05001798 }
dea31012005-04-17 16:05:31 -05001799 break;
1800 case ELS_CMD_PRLI:
James Smart2e0fef82007-06-17 19:56:36 -05001801 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001802 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001803 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05001804 }
dea31012005-04-17 16:05:31 -05001805 break;
1806 case ELS_CMD_LOGO:
James Smart2e0fef82007-06-17 19:56:36 -05001807 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001808 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001809 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05001810 }
dea31012005-04-17 16:05:31 -05001811 break;
James Smart92d7f7b2007-06-17 19:56:38 -05001812 case ELS_CMD_FDISC:
1813 lpfc_issue_els_fdisc(vport, ndlp, retry);
1814 break;
dea31012005-04-17 16:05:31 -05001815 }
1816 return;
1817}
1818
1819static int
James Smart2e0fef82007-06-17 19:56:36 -05001820lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1821 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001822{
James Smart2e0fef82007-06-17 19:56:36 -05001823 struct lpfc_vport *vport = cmdiocb->vport;
1824 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1825 IOCB_t *irsp = &rspiocb->iocb;
1826 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1827 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
dea31012005-04-17 16:05:31 -05001828 uint32_t *elscmd;
1829 struct ls_rjt stat;
James Smart2e0fef82007-06-17 19:56:36 -05001830 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
James Smart98c9ea52007-10-27 13:37:33 -04001831 int logerr = 0;
James Smart2e0fef82007-06-17 19:56:36 -05001832 uint32_t cmd = 0;
James Smart488d1462006-03-07 15:02:37 -05001833 uint32_t did;
dea31012005-04-17 16:05:31 -05001834
James Smart488d1462006-03-07 15:02:37 -05001835
dea31012005-04-17 16:05:31 -05001836 /* Note: context2 may be 0 for internal driver abort
1837 * of delays ELS command.
1838 */
1839
1840 if (pcmd && pcmd->virt) {
1841 elscmd = (uint32_t *) (pcmd->virt);
1842 cmd = *elscmd++;
1843 }
1844
James Smart329f9bc2007-04-25 09:53:01 -04001845 if (ndlp)
James Smart488d1462006-03-07 15:02:37 -05001846 did = ndlp->nlp_DID;
1847 else {
1848 /* We should only hit this case for retrying PLOGI */
1849 did = irsp->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05001850 ndlp = lpfc_findnode_did(vport, did);
James Smart488d1462006-03-07 15:02:37 -05001851 if (!ndlp && (cmd != ELS_CMD_PLOGI))
1852 return 1;
1853 }
1854
James Smart858c9f62007-06-17 19:56:39 -05001855 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1856 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
1857 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
1858
dea31012005-04-17 16:05:31 -05001859 switch (irsp->ulpStatus) {
1860 case IOSTAT_FCP_RSP_ERROR:
1861 case IOSTAT_REMOTE_STOP:
1862 break;
1863
1864 case IOSTAT_LOCAL_REJECT:
1865 switch ((irsp->un.ulpWord[4] & 0xff)) {
1866 case IOERR_LOOP_OPEN_FAILURE:
James Smart2e0fef82007-06-17 19:56:36 -05001867 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05001868 delay = 1000;
dea31012005-04-17 16:05:31 -05001869 retry = 1;
1870 break;
1871
James Smart92d7f7b2007-06-17 19:56:38 -05001872 case IOERR_ILLEGAL_COMMAND:
1873 if ((phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) &&
1874 (cmd == ELS_CMD_FDISC)) {
James Smarte8b62012007-08-02 11:10:09 -04001875 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1876 "0124 FDISC failed (3/6) "
1877 "retrying...\n");
James Smart92d7f7b2007-06-17 19:56:38 -05001878 lpfc_mbx_unreg_vpi(vport);
1879 retry = 1;
James Smart51ef4c22007-08-02 11:10:31 -04001880 /* FDISC retry policy */
1881 maxretry = 48;
1882 if (cmdiocb->retry >= 32)
1883 delay = 1000;
James Smart92d7f7b2007-06-17 19:56:38 -05001884 }
1885 break;
1886
dea31012005-04-17 16:05:31 -05001887 case IOERR_NO_RESOURCES:
James Smart98c9ea52007-10-27 13:37:33 -04001888 logerr = 1; /* HBA out of resources */
James Smart858c9f62007-06-17 19:56:39 -05001889 retry = 1;
1890 if (cmdiocb->retry > 100)
1891 delay = 100;
1892 maxretry = 250;
1893 break;
1894
1895 case IOERR_ILLEGAL_FRAME:
James Smart92d7f7b2007-06-17 19:56:38 -05001896 delay = 100;
dea31012005-04-17 16:05:31 -05001897 retry = 1;
1898 break;
1899
James Smart858c9f62007-06-17 19:56:39 -05001900 case IOERR_SEQUENCE_TIMEOUT:
dea31012005-04-17 16:05:31 -05001901 case IOERR_INVALID_RPI:
1902 retry = 1;
1903 break;
1904 }
1905 break;
1906
1907 case IOSTAT_NPORT_RJT:
1908 case IOSTAT_FABRIC_RJT:
1909 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
1910 retry = 1;
1911 break;
1912 }
1913 break;
1914
1915 case IOSTAT_NPORT_BSY:
1916 case IOSTAT_FABRIC_BSY:
James Smart98c9ea52007-10-27 13:37:33 -04001917 logerr = 1; /* Fabric / Remote NPort out of resources */
dea31012005-04-17 16:05:31 -05001918 retry = 1;
1919 break;
1920
1921 case IOSTAT_LS_RJT:
1922 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
1923 /* Added for Vendor specifc support
1924 * Just keep retrying for these Rsn / Exp codes
1925 */
1926 switch (stat.un.b.lsRjtRsnCode) {
1927 case LSRJT_UNABLE_TPC:
1928 if (stat.un.b.lsRjtRsnCodeExp ==
1929 LSEXP_CMD_IN_PROGRESS) {
1930 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05001931 delay = 1000;
dea31012005-04-17 16:05:31 -05001932 maxretry = 48;
1933 }
1934 retry = 1;
1935 break;
1936 }
1937 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05001938 delay = 1000;
dea31012005-04-17 16:05:31 -05001939 maxretry = lpfc_max_els_tries + 1;
1940 retry = 1;
1941 break;
1942 }
James Smart92d7f7b2007-06-17 19:56:38 -05001943 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
1944 (cmd == ELS_CMD_FDISC) &&
1945 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
James Smarte8b62012007-08-02 11:10:09 -04001946 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1947 "0125 FDISC Failed (x%x). "
1948 "Fabric out of resources\n",
1949 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05001950 lpfc_vport_set_state(vport,
1951 FC_VPORT_NO_FABRIC_RSCS);
1952 }
dea31012005-04-17 16:05:31 -05001953 break;
1954
1955 case LSRJT_LOGICAL_BSY:
James Smart858c9f62007-06-17 19:56:39 -05001956 if ((cmd == ELS_CMD_PLOGI) ||
1957 (cmd == ELS_CMD_PRLI)) {
James Smart92d7f7b2007-06-17 19:56:38 -05001958 delay = 1000;
dea31012005-04-17 16:05:31 -05001959 maxretry = 48;
James Smart92d7f7b2007-06-17 19:56:38 -05001960 } else if (cmd == ELS_CMD_FDISC) {
James Smart51ef4c22007-08-02 11:10:31 -04001961 /* FDISC retry policy */
1962 maxretry = 48;
1963 if (cmdiocb->retry >= 32)
1964 delay = 1000;
dea31012005-04-17 16:05:31 -05001965 }
1966 retry = 1;
1967 break;
James Smart92d7f7b2007-06-17 19:56:38 -05001968
1969 case LSRJT_LOGICAL_ERR:
1970 case LSRJT_PROTOCOL_ERR:
1971 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
1972 (cmd == ELS_CMD_FDISC) &&
1973 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
1974 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
1975 ) {
James Smarte8b62012007-08-02 11:10:09 -04001976 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1977 "0123 FDISC Failed (x%x). "
1978 "Fabric Detected Bad WWN\n",
1979 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05001980 lpfc_vport_set_state(vport,
1981 FC_VPORT_FABRIC_REJ_WWN);
1982 }
1983 break;
dea31012005-04-17 16:05:31 -05001984 }
1985 break;
1986
1987 case IOSTAT_INTERMED_RSP:
1988 case IOSTAT_BA_RJT:
1989 break;
1990
1991 default:
1992 break;
1993 }
1994
James Smart488d1462006-03-07 15:02:37 -05001995 if (did == FDMI_DID)
dea31012005-04-17 16:05:31 -05001996 retry = 1;
dea31012005-04-17 16:05:31 -05001997
James Smart98c9ea52007-10-27 13:37:33 -04001998 if ((cmd == ELS_CMD_FLOGI) &&
1999 (phba->fc_topology != TOPOLOGY_LOOP)) {
2000 /* FLOGI retry policy */
2001 retry = 1;
2002 maxretry = 48;
2003 if (cmdiocb->retry >= 32)
2004 delay = 1000;
2005 }
2006
dea31012005-04-17 16:05:31 -05002007 if ((++cmdiocb->retry) >= maxretry) {
2008 phba->fc_stat.elsRetryExceeded++;
2009 retry = 0;
2010 }
2011
James Smarted957682007-06-17 19:56:37 -05002012 if ((vport->load_flag & FC_UNLOADING) != 0)
2013 retry = 0;
2014
dea31012005-04-17 16:05:31 -05002015 if (retry) {
2016
2017 /* Retry ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04002018 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2019 "0107 Retry ELS command x%x to remote "
2020 "NPORT x%x Data: x%x x%x\n",
2021 cmd, did, cmdiocb->retry, delay);
dea31012005-04-17 16:05:31 -05002022
James Smart858c9f62007-06-17 19:56:39 -05002023 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
2024 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
2025 ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) {
2026 /* Don't reset timer for no resources */
2027
dea31012005-04-17 16:05:31 -05002028 /* If discovery / RSCN timer is running, reset it */
James Smart2e0fef82007-06-17 19:56:36 -05002029 if (timer_pending(&vport->fc_disctmo) ||
James Smart92d7f7b2007-06-17 19:56:38 -05002030 (vport->fc_flag & FC_RSCN_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05002031 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05002032 }
2033
2034 phba->fc_stat.elsXmitRetry++;
James Smart488d1462006-03-07 15:02:37 -05002035 if (ndlp && delay) {
dea31012005-04-17 16:05:31 -05002036 phba->fc_stat.elsDelayRetry++;
2037 ndlp->nlp_retry = cmdiocb->retry;
2038
James Smart92d7f7b2007-06-17 19:56:38 -05002039 /* delay is specified in milliseconds */
2040 mod_timer(&ndlp->nlp_delayfunc,
2041 jiffies + msecs_to_jiffies(delay));
James Smart2e0fef82007-06-17 19:56:36 -05002042 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002043 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002044 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002045
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002046 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart858c9f62007-06-17 19:56:39 -05002047 if (cmd == ELS_CMD_PRLI)
2048 lpfc_nlp_set_state(vport, ndlp,
2049 NLP_STE_REG_LOGIN_ISSUE);
2050 else
2051 lpfc_nlp_set_state(vport, ndlp,
2052 NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05002053 ndlp->nlp_last_elscmd = cmd;
2054
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002055 return 1;
dea31012005-04-17 16:05:31 -05002056 }
2057 switch (cmd) {
2058 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002059 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002060 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -05002061 case ELS_CMD_FDISC:
2062 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
2063 return 1;
dea31012005-04-17 16:05:31 -05002064 case ELS_CMD_PLOGI:
James Smart488d1462006-03-07 15:02:37 -05002065 if (ndlp) {
2066 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002067 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04002068 NLP_STE_PLOGI_ISSUE);
James Smart488d1462006-03-07 15:02:37 -05002069 }
James Smart2e0fef82007-06-17 19:56:36 -05002070 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002071 return 1;
dea31012005-04-17 16:05:31 -05002072 case ELS_CMD_ADISC:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002073 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002074 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2075 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002076 return 1;
dea31012005-04-17 16:05:31 -05002077 case ELS_CMD_PRLI:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002078 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002079 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
2080 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002081 return 1;
dea31012005-04-17 16:05:31 -05002082 case ELS_CMD_LOGO:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002083 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002084 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2085 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002086 return 1;
dea31012005-04-17 16:05:31 -05002087 }
2088 }
dea31012005-04-17 16:05:31 -05002089 /* No retry ELS command <elsCmd> to remote NPORT <did> */
James Smart98c9ea52007-10-27 13:37:33 -04002090 if (logerr) {
2091 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2092 "0137 No retry ELS command x%x to remote "
2093 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
2094 cmd, did, irsp->ulpStatus,
2095 irsp->un.ulpWord[4]);
2096 }
2097 else {
2098 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smarta58cbd52007-08-02 11:09:43 -04002099 "0108 No retry ELS command x%x to remote "
2100 "NPORT x%x Retried:%d Error:x%x/%x\n",
2101 cmd, did, cmdiocb->retry, irsp->ulpStatus,
2102 irsp->un.ulpWord[4]);
James Smart98c9ea52007-10-27 13:37:33 -04002103 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002104 return 0;
dea31012005-04-17 16:05:31 -05002105}
2106
James Smart09372822008-01-11 01:52:54 -05002107static int
James Smart87af33f2007-10-27 13:37:43 -04002108lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
2109{
2110 struct lpfc_dmabuf *buf_ptr;
2111
2112 /* Free the response before processing the command. */
2113 if (!list_empty(&buf_ptr1->list)) {
2114 list_remove_head(&buf_ptr1->list, buf_ptr,
2115 struct lpfc_dmabuf,
2116 list);
2117 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
2118 kfree(buf_ptr);
2119 }
2120 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
2121 kfree(buf_ptr1);
2122 return 0;
2123}
2124
James Smart09372822008-01-11 01:52:54 -05002125static int
James Smart87af33f2007-10-27 13:37:43 -04002126lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
2127{
2128 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
2129 kfree(buf_ptr);
2130 return 0;
2131}
2132
2133int
James Smart329f9bc2007-04-25 09:53:01 -04002134lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05002135{
2136 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
James Smarta8adb832007-10-27 13:37:53 -04002137 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05002138
James Smarta8adb832007-10-27 13:37:53 -04002139 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
2140 if (ndlp) {
2141 if (ndlp->nlp_flag & NLP_DEFER_RM) {
2142 lpfc_nlp_put(ndlp);
2143
2144 /* If the ndlp is not being used by another discovery
2145 * thread, free it.
2146 */
2147 if (!lpfc_nlp_not_used(ndlp)) {
2148 /* If ndlp is being used by another discovery
2149 * thread, just clear NLP_DEFER_RM
2150 */
2151 ndlp->nlp_flag &= ~NLP_DEFER_RM;
2152 }
2153 }
2154 else
2155 lpfc_nlp_put(ndlp);
James Smart329f9bc2007-04-25 09:53:01 -04002156 elsiocb->context1 = NULL;
2157 }
dea31012005-04-17 16:05:31 -05002158 /* context2 = cmd, context2->next = rsp, context3 = bpl */
2159 if (elsiocb->context2) {
James Smart0ff10d42008-01-11 01:52:36 -05002160 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
2161 /* Firmware could still be in progress of DMAing
2162 * payload, so don't free data buffer till after
2163 * a hbeat.
2164 */
2165 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
2166 buf_ptr = elsiocb->context2;
2167 elsiocb->context2 = NULL;
2168 if (buf_ptr) {
2169 buf_ptr1 = NULL;
2170 spin_lock_irq(&phba->hbalock);
2171 if (!list_empty(&buf_ptr->list)) {
2172 list_remove_head(&buf_ptr->list,
2173 buf_ptr1, struct lpfc_dmabuf,
2174 list);
2175 INIT_LIST_HEAD(&buf_ptr1->list);
2176 list_add_tail(&buf_ptr1->list,
2177 &phba->elsbuf);
2178 phba->elsbuf_cnt++;
2179 }
2180 INIT_LIST_HEAD(&buf_ptr->list);
2181 list_add_tail(&buf_ptr->list, &phba->elsbuf);
2182 phba->elsbuf_cnt++;
2183 spin_unlock_irq(&phba->hbalock);
2184 }
2185 } else {
2186 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
2187 lpfc_els_free_data(phba, buf_ptr1);
2188 }
dea31012005-04-17 16:05:31 -05002189 }
2190
2191 if (elsiocb->context3) {
2192 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
James Smart87af33f2007-10-27 13:37:43 -04002193 lpfc_els_free_bpl(phba, buf_ptr);
dea31012005-04-17 16:05:31 -05002194 }
James Bottomley604a3e32005-10-29 10:28:33 -05002195 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -05002196 return 0;
2197}
2198
2199static void
James Smart2e0fef82007-06-17 19:56:36 -05002200lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2201 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002202{
James Smart2e0fef82007-06-17 19:56:36 -05002203 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2204 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05002205 IOCB_t *irsp;
2206
2207 irsp = &rspiocb->iocb;
2208 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2209 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
2210 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05002211 /* ACC to LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002212 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2213 "0109 ACC to LOGO completes to NPort x%x "
2214 "Data: x%x x%x x%x\n",
2215 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2216 ndlp->nlp_rpi);
James Smart87af33f2007-10-27 13:37:43 -04002217
2218 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
2219 /* NPort Recovery mode or node is just allocated */
2220 if (!lpfc_nlp_not_used(ndlp)) {
2221 /* If the ndlp is being used by another discovery
2222 * thread, just unregister the RPI.
2223 */
2224 lpfc_unreg_rpi(vport, ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05002225 } else {
2226 /* Indicate the node has already released, should
2227 * not reference to it from within lpfc_els_free_iocb.
2228 */
2229 cmdiocb->context1 = NULL;
James Smart87af33f2007-10-27 13:37:43 -04002230 }
dea31012005-04-17 16:05:31 -05002231 }
2232 lpfc_els_free_iocb(phba, cmdiocb);
2233 return;
2234}
2235
James Smart858c9f62007-06-17 19:56:39 -05002236void
2237lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
2238{
2239 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
2240 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
2241
2242 pmb->context1 = NULL;
2243 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2244 kfree(mp);
2245 mempool_free(pmb, phba->mbox_mem_pool);
James Smarta8adb832007-10-27 13:37:53 -04002246 if (ndlp) {
2247 lpfc_nlp_put(ndlp);
James Smarta8adb832007-10-27 13:37:53 -04002248 /* This is the end of the default RPI cleanup logic for this
2249 * ndlp. If no other discovery threads are using this ndlp.
2250 * we should free all resources associated with it.
2251 */
2252 lpfc_nlp_not_used(ndlp);
2253 }
James Smart858c9f62007-06-17 19:56:39 -05002254 return;
2255}
2256
dea31012005-04-17 16:05:31 -05002257static void
James Smart858c9f62007-06-17 19:56:39 -05002258lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
James Smart329f9bc2007-04-25 09:53:01 -04002259 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002260{
James Smart2e0fef82007-06-17 19:56:36 -05002261 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2262 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
2263 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
James Smart87af33f2007-10-27 13:37:43 -04002264 IOCB_t *irsp;
2265 uint8_t *pcmd;
dea31012005-04-17 16:05:31 -05002266 LPFC_MBOXQ_t *mbox = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05002267 struct lpfc_dmabuf *mp = NULL;
James Smart87af33f2007-10-27 13:37:43 -04002268 uint32_t ls_rjt = 0;
dea31012005-04-17 16:05:31 -05002269
James Smart33ccf8d2006-08-17 11:57:58 -04002270 irsp = &rspiocb->iocb;
2271
dea31012005-04-17 16:05:31 -05002272 if (cmdiocb->context_un.mbox)
2273 mbox = cmdiocb->context_un.mbox;
2274
James Smartfa4066b2008-01-11 01:53:27 -05002275 /* First determine if this is a LS_RJT cmpl. Note, this callback
2276 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
2277 */
James Smart87af33f2007-10-27 13:37:43 -04002278 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
James Smartfa4066b2008-01-11 01:53:27 -05002279 if (ndlp && (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
2280 /* A LS_RJT associated with Default RPI cleanup has its own
2281 * seperate code path.
James Smart87af33f2007-10-27 13:37:43 -04002282 */
2283 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
2284 ls_rjt = 1;
2285 }
2286
dea31012005-04-17 16:05:31 -05002287 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002288 if (!ndlp || lpfc_els_chk_latt(vport)) {
dea31012005-04-17 16:05:31 -05002289 if (mbox) {
James Smart14691152006-12-02 13:34:28 -05002290 mp = (struct lpfc_dmabuf *) mbox->context1;
2291 if (mp) {
2292 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2293 kfree(mp);
2294 }
James Smart329f9bc2007-04-25 09:53:01 -04002295 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05002296 }
James Smart98c9ea52007-10-27 13:37:33 -04002297 if (ndlp && (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
James Smartfa4066b2008-01-11 01:53:27 -05002298 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04002299 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05002300 /* Indicate the node has already released,
2301 * should not reference to it from within
2302 * the routine lpfc_els_free_iocb.
2303 */
2304 cmdiocb->context1 = NULL;
2305 }
dea31012005-04-17 16:05:31 -05002306 goto out;
2307 }
2308
James Smart858c9f62007-06-17 19:56:39 -05002309 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smart51ef4c22007-08-02 11:10:31 -04002310 "ELS rsp cmpl: status:x%x/x%x did:x%x",
James Smart858c9f62007-06-17 19:56:39 -05002311 irsp->ulpStatus, irsp->un.ulpWord[4],
James Smart51ef4c22007-08-02 11:10:31 -04002312 cmdiocb->iocb.un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05002313 /* ELS response tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04002314 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2315 "0110 ELS response tag x%x completes "
2316 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
2317 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
2318 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
2319 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2320 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05002321 if (mbox) {
2322 if ((rspiocb->iocb.ulpStatus == 0)
2323 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
James Smart2e0fef82007-06-17 19:56:36 -05002324 lpfc_unreg_rpi(vport, ndlp);
James Smart329f9bc2007-04-25 09:53:01 -04002325 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05002326 mbox->vport = vport;
James Smart858c9f62007-06-17 19:56:39 -05002327 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
2328 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
2329 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
2330 }
2331 else {
2332 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
2333 ndlp->nlp_prev_state = ndlp->nlp_state;
2334 lpfc_nlp_set_state(vport, ndlp,
James Smart2e0fef82007-06-17 19:56:36 -05002335 NLP_STE_REG_LOGIN_ISSUE);
James Smart858c9f62007-06-17 19:56:39 -05002336 }
James Smart0b727fe2007-10-27 13:37:25 -04002337 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
dea31012005-04-17 16:05:31 -05002338 != MBX_NOT_FINISHED) {
2339 goto out;
2340 }
James Smart98c9ea52007-10-27 13:37:33 -04002341
2342 /* ELS rsp: Cannot issue reg_login for <NPortid> */
2343 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2344 "0138 ELS rsp: Cannot issue reg_login for x%x "
2345 "Data: x%x x%x x%x\n",
2346 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2347 ndlp->nlp_rpi);
2348
James Smartfa4066b2008-01-11 01:53:27 -05002349 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04002350 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05002351 /* Indicate node has already been released,
2352 * should not reference to it from within
2353 * the routine lpfc_els_free_iocb.
2354 */
2355 cmdiocb->context1 = NULL;
2356 }
dea31012005-04-17 16:05:31 -05002357 } else {
James Smart858c9f62007-06-17 19:56:39 -05002358 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
2359 if (!lpfc_error_lost_link(irsp) &&
2360 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
James Smartfa4066b2008-01-11 01:53:27 -05002361 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04002362 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05002363 /* Indicate node has already been
2364 * released, should not reference
2365 * to it from within the routine
2366 * lpfc_els_free_iocb.
2367 */
2368 cmdiocb->context1 = NULL;
2369 }
dea31012005-04-17 16:05:31 -05002370 }
2371 }
James Smart14691152006-12-02 13:34:28 -05002372 mp = (struct lpfc_dmabuf *) mbox->context1;
2373 if (mp) {
2374 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2375 kfree(mp);
2376 }
2377 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05002378 }
2379out:
2380 if (ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05002381 spin_lock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05002382 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
James Smart2e0fef82007-06-17 19:56:36 -05002383 spin_unlock_irq(shost->host_lock);
James Smart87af33f2007-10-27 13:37:43 -04002384
2385 /* If the node is not being used by another discovery thread,
2386 * and we are sending a reject, we are done with it.
2387 * Release driver reference count here and free associated
2388 * resources.
2389 */
2390 if (ls_rjt)
James Smartfa4066b2008-01-11 01:53:27 -05002391 if (lpfc_nlp_not_used(ndlp))
2392 /* Indicate node has already been released,
2393 * should not reference to it from within
2394 * the routine lpfc_els_free_iocb.
2395 */
2396 cmdiocb->context1 = NULL;
dea31012005-04-17 16:05:31 -05002397 }
James Smart87af33f2007-10-27 13:37:43 -04002398
dea31012005-04-17 16:05:31 -05002399 lpfc_els_free_iocb(phba, cmdiocb);
2400 return;
2401}
2402
2403int
James Smart2e0fef82007-06-17 19:56:36 -05002404lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
2405 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
James Smart51ef4c22007-08-02 11:10:31 -04002406 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05002407{
James Smart2e0fef82007-06-17 19:56:36 -05002408 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2409 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002410 IOCB_t *icmd;
2411 IOCB_t *oldcmd;
2412 struct lpfc_iocbq *elsiocb;
2413 struct lpfc_sli_ring *pring;
2414 struct lpfc_sli *psli;
2415 uint8_t *pcmd;
2416 uint16_t cmdsize;
2417 int rc;
James Smart82d9a2a2006-04-15 11:53:05 -04002418 ELS_PKT *els_pkt_ptr;
dea31012005-04-17 16:05:31 -05002419
2420 psli = &phba->sli;
2421 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2422 oldcmd = &oldiocb->iocb;
2423
2424 switch (flag) {
2425 case ELS_CMD_ACC:
James Smart92d7f7b2007-06-17 19:56:38 -05002426 cmdsize = sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05002427 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
2428 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05002429 if (!elsiocb) {
James Smart2e0fef82007-06-17 19:56:36 -05002430 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002431 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05002432 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002433 return 1;
dea31012005-04-17 16:05:31 -05002434 }
James Smart2e0fef82007-06-17 19:56:36 -05002435
dea31012005-04-17 16:05:31 -05002436 icmd = &elsiocb->iocb;
2437 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2438 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2439 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05002440 pcmd += sizeof(uint32_t);
James Smart858c9f62007-06-17 19:56:39 -05002441
2442 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2443 "Issue ACC: did:x%x flg:x%x",
2444 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05002445 break;
2446 case ELS_CMD_PLOGI:
James Smart92d7f7b2007-06-17 19:56:38 -05002447 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
James Smart2e0fef82007-06-17 19:56:36 -05002448 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
2449 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05002450 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002451 return 1;
James Smart488d1462006-03-07 15:02:37 -05002452
dea31012005-04-17 16:05:31 -05002453 icmd = &elsiocb->iocb;
2454 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2455 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2456
2457 if (mbox)
2458 elsiocb->context_un.mbox = mbox;
2459
2460 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05002461 pcmd += sizeof(uint32_t);
2462 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
James Smart858c9f62007-06-17 19:56:39 -05002463
2464 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2465 "Issue ACC PLOGI: did:x%x flg:x%x",
2466 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05002467 break;
James Smart82d9a2a2006-04-15 11:53:05 -04002468 case ELS_CMD_PRLO:
James Smart92d7f7b2007-06-17 19:56:38 -05002469 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
James Smart2e0fef82007-06-17 19:56:36 -05002470 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
James Smart82d9a2a2006-04-15 11:53:05 -04002471 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
2472 if (!elsiocb)
2473 return 1;
2474
2475 icmd = &elsiocb->iocb;
2476 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2477 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2478
2479 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
James Smart92d7f7b2007-06-17 19:56:38 -05002480 sizeof(uint32_t) + sizeof(PRLO));
James Smart82d9a2a2006-04-15 11:53:05 -04002481 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
2482 els_pkt_ptr = (ELS_PKT *) pcmd;
2483 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
James Smart858c9f62007-06-17 19:56:39 -05002484
2485 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2486 "Issue ACC PRLO: did:x%x flg:x%x",
2487 ndlp->nlp_DID, ndlp->nlp_flag, 0);
James Smart82d9a2a2006-04-15 11:53:05 -04002488 break;
dea31012005-04-17 16:05:31 -05002489 default:
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002490 return 1;
dea31012005-04-17 16:05:31 -05002491 }
dea31012005-04-17 16:05:31 -05002492 /* Xmit ELS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04002493 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2494 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
2495 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n",
2496 elsiocb->iotag, elsiocb->iocb.ulpContext,
2497 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2498 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05002499 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
James Smart2e0fef82007-06-17 19:56:36 -05002500 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002501 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05002502 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002503 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
2504 } else {
James Smart858c9f62007-06-17 19:56:39 -05002505 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05002506 }
2507
2508 phba->fc_stat.elsXmitACC++;
dea31012005-04-17 16:05:31 -05002509 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
dea31012005-04-17 16:05:31 -05002510 if (rc == IOCB_ERROR) {
2511 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002512 return 1;
dea31012005-04-17 16:05:31 -05002513 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002514 return 0;
dea31012005-04-17 16:05:31 -05002515}
2516
2517int
James Smart2e0fef82007-06-17 19:56:36 -05002518lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
James Smart858c9f62007-06-17 19:56:39 -05002519 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
2520 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05002521{
James Smart2e0fef82007-06-17 19:56:36 -05002522 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002523 IOCB_t *icmd;
2524 IOCB_t *oldcmd;
2525 struct lpfc_iocbq *elsiocb;
2526 struct lpfc_sli_ring *pring;
2527 struct lpfc_sli *psli;
2528 uint8_t *pcmd;
2529 uint16_t cmdsize;
2530 int rc;
2531
2532 psli = &phba->sli;
2533 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2534
James Smart92d7f7b2007-06-17 19:56:38 -05002535 cmdsize = 2 * sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05002536 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
2537 ndlp->nlp_DID, ELS_CMD_LS_RJT);
James Smart488d1462006-03-07 15:02:37 -05002538 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002539 return 1;
dea31012005-04-17 16:05:31 -05002540
2541 icmd = &elsiocb->iocb;
2542 oldcmd = &oldiocb->iocb;
2543 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2544 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2545
2546 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
James Smart92d7f7b2007-06-17 19:56:38 -05002547 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002548 *((uint32_t *) (pcmd)) = rejectError;
2549
James Smart51ef4c22007-08-02 11:10:31 -04002550 if (mbox)
James Smart858c9f62007-06-17 19:56:39 -05002551 elsiocb->context_un.mbox = mbox;
James Smart858c9f62007-06-17 19:56:39 -05002552
dea31012005-04-17 16:05:31 -05002553 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04002554 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2555 "0129 Xmit ELS RJT x%x response tag x%x "
2556 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
2557 "rpi x%x\n",
2558 rejectError, elsiocb->iotag,
2559 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
2560 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05002561 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2562 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
2563 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
2564
dea31012005-04-17 16:05:31 -05002565 phba->fc_stat.elsXmitLSRJT++;
James Smart858c9f62007-06-17 19:56:39 -05002566 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05002567 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
James Smart51ef4c22007-08-02 11:10:31 -04002568
dea31012005-04-17 16:05:31 -05002569 if (rc == IOCB_ERROR) {
2570 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002571 return 1;
dea31012005-04-17 16:05:31 -05002572 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002573 return 0;
dea31012005-04-17 16:05:31 -05002574}
2575
2576int
James Smart2e0fef82007-06-17 19:56:36 -05002577lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
2578 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05002579{
James Smart2e0fef82007-06-17 19:56:36 -05002580 struct lpfc_hba *phba = vport->phba;
2581 struct lpfc_sli *psli = &phba->sli;
2582 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05002583 ADISC *ap;
James Smart2e0fef82007-06-17 19:56:36 -05002584 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05002585 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002586 uint8_t *pcmd;
2587 uint16_t cmdsize;
2588 int rc;
2589
James Smart92d7f7b2007-06-17 19:56:38 -05002590 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
James Smart2e0fef82007-06-17 19:56:36 -05002591 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
2592 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05002593 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002594 return 1;
dea31012005-04-17 16:05:31 -05002595
dea31012005-04-17 16:05:31 -05002596 icmd = &elsiocb->iocb;
2597 oldcmd = &oldiocb->iocb;
2598 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04002599
2600 /* Xmit ADISC ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04002601 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2602 "0130 Xmit ADISC ACC response iotag x%x xri: "
2603 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
2604 elsiocb->iotag, elsiocb->iocb.ulpContext,
2605 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2606 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05002607 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2608
2609 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05002610 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002611
2612 ap = (ADISC *) (pcmd);
2613 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05002614 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2615 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002616 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002617
James Smart858c9f62007-06-17 19:56:39 -05002618 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2619 "Issue ACC ADISC: did:x%x flg:x%x",
2620 ndlp->nlp_DID, ndlp->nlp_flag, 0);
2621
dea31012005-04-17 16:05:31 -05002622 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05002623 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05002624 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
dea31012005-04-17 16:05:31 -05002625 if (rc == IOCB_ERROR) {
2626 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002627 return 1;
dea31012005-04-17 16:05:31 -05002628 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002629 return 0;
dea31012005-04-17 16:05:31 -05002630}
2631
2632int
James Smart2e0fef82007-06-17 19:56:36 -05002633lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
James Smart5b8bd0c2007-04-25 09:52:49 -04002634 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05002635{
James Smart2e0fef82007-06-17 19:56:36 -05002636 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002637 PRLI *npr;
2638 lpfc_vpd_t *vpd;
2639 IOCB_t *icmd;
2640 IOCB_t *oldcmd;
2641 struct lpfc_iocbq *elsiocb;
2642 struct lpfc_sli_ring *pring;
2643 struct lpfc_sli *psli;
2644 uint8_t *pcmd;
2645 uint16_t cmdsize;
2646 int rc;
2647
2648 psli = &phba->sli;
2649 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2650
James Smart92d7f7b2007-06-17 19:56:38 -05002651 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
James Smart2e0fef82007-06-17 19:56:36 -05002652 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
James Smart92d7f7b2007-06-17 19:56:38 -05002653 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002654 if (!elsiocb)
2655 return 1;
dea31012005-04-17 16:05:31 -05002656
dea31012005-04-17 16:05:31 -05002657 icmd = &elsiocb->iocb;
2658 oldcmd = &oldiocb->iocb;
2659 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04002660 /* Xmit PRLI ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04002661 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2662 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
2663 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
2664 elsiocb->iotag, elsiocb->iocb.ulpContext,
2665 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2666 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05002667 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2668
2669 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
James Smart92d7f7b2007-06-17 19:56:38 -05002670 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002671
2672 /* For PRLI, remainder of payload is PRLI parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05002673 memset(pcmd, 0, sizeof(PRLI));
dea31012005-04-17 16:05:31 -05002674
2675 npr = (PRLI *) pcmd;
2676 vpd = &phba->vpd;
2677 /*
2678 * If our firmware version is 3.20 or later,
2679 * set the following bits for FC-TAPE support.
2680 */
2681 if (vpd->rev.feaLevelHigh >= 0x02) {
2682 npr->ConfmComplAllowed = 1;
2683 npr->Retry = 1;
2684 npr->TaskRetryIdReq = 1;
2685 }
2686
2687 npr->acceptRspCode = PRLI_REQ_EXECUTED;
2688 npr->estabImagePair = 1;
2689 npr->readXferRdyDis = 1;
2690 npr->ConfmComplAllowed = 1;
2691
2692 npr->prliType = PRLI_FCP_TYPE;
2693 npr->initiatorFunc = 1;
2694
James Smart858c9f62007-06-17 19:56:39 -05002695 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2696 "Issue ACC PRLI: did:x%x flg:x%x",
2697 ndlp->nlp_DID, ndlp->nlp_flag, 0);
2698
dea31012005-04-17 16:05:31 -05002699 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05002700 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05002701
dea31012005-04-17 16:05:31 -05002702 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
dea31012005-04-17 16:05:31 -05002703 if (rc == IOCB_ERROR) {
2704 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002705 return 1;
dea31012005-04-17 16:05:31 -05002706 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002707 return 0;
dea31012005-04-17 16:05:31 -05002708}
2709
2710static int
James Smart2e0fef82007-06-17 19:56:36 -05002711lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
James Smart329f9bc2007-04-25 09:53:01 -04002712 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05002713{
James Smart2e0fef82007-06-17 19:56:36 -05002714 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002715 RNID *rn;
James Smart2e0fef82007-06-17 19:56:36 -05002716 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05002717 struct lpfc_iocbq *elsiocb;
2718 struct lpfc_sli_ring *pring;
2719 struct lpfc_sli *psli;
2720 uint8_t *pcmd;
2721 uint16_t cmdsize;
2722 int rc;
2723
2724 psli = &phba->sli;
2725 pring = &psli->ring[LPFC_ELS_RING];
2726
James Smart92d7f7b2007-06-17 19:56:38 -05002727 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
2728 + (2 * sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002729 if (format)
James Smart92d7f7b2007-06-17 19:56:38 -05002730 cmdsize += sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05002731
James Smart2e0fef82007-06-17 19:56:36 -05002732 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
2733 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05002734 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002735 return 1;
dea31012005-04-17 16:05:31 -05002736
dea31012005-04-17 16:05:31 -05002737 icmd = &elsiocb->iocb;
2738 oldcmd = &oldiocb->iocb;
2739 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04002740 /* Xmit RNID ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04002741 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2742 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
2743 elsiocb->iotag, elsiocb->iocb.ulpContext);
dea31012005-04-17 16:05:31 -05002744 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
dea31012005-04-17 16:05:31 -05002745 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05002746 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002747
James Smart92d7f7b2007-06-17 19:56:38 -05002748 memset(pcmd, 0, sizeof(RNID));
dea31012005-04-17 16:05:31 -05002749 rn = (RNID *) (pcmd);
2750 rn->Format = format;
James Smart92d7f7b2007-06-17 19:56:38 -05002751 rn->CommonLen = (2 * sizeof(struct lpfc_name));
2752 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2753 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002754 switch (format) {
2755 case 0:
2756 rn->SpecificLen = 0;
2757 break;
2758 case RNID_TOPOLOGY_DISC:
James Smart92d7f7b2007-06-17 19:56:38 -05002759 rn->SpecificLen = sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05002760 memcpy(&rn->un.topologyDisc.portName,
James Smart92d7f7b2007-06-17 19:56:38 -05002761 &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002762 rn->un.topologyDisc.unitType = RNID_HBA;
2763 rn->un.topologyDisc.physPort = 0;
2764 rn->un.topologyDisc.attachedNodes = 0;
2765 break;
2766 default:
2767 rn->CommonLen = 0;
2768 rn->SpecificLen = 0;
2769 break;
2770 }
2771
James Smart858c9f62007-06-17 19:56:39 -05002772 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2773 "Issue ACC RNID: did:x%x flg:x%x",
2774 ndlp->nlp_DID, ndlp->nlp_flag, 0);
2775
dea31012005-04-17 16:05:31 -05002776 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05002777 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart329f9bc2007-04-25 09:53:01 -04002778 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002779 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
2780 * it could be freed */
2781
dea31012005-04-17 16:05:31 -05002782 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
dea31012005-04-17 16:05:31 -05002783 if (rc == IOCB_ERROR) {
2784 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002785 return 1;
dea31012005-04-17 16:05:31 -05002786 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002787 return 0;
dea31012005-04-17 16:05:31 -05002788}
2789
2790int
James Smart2e0fef82007-06-17 19:56:36 -05002791lpfc_els_disc_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002792{
James Smart2e0fef82007-06-17 19:56:36 -05002793 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002794 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05002795 int sentadisc = 0;
dea31012005-04-17 16:05:31 -05002796
James Smart685f0bf2007-04-25 09:53:08 -04002797 /* go thru NPR nodes and issue any remaining ELS ADISCs */
James Smart2e0fef82007-06-17 19:56:36 -05002798 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smart685f0bf2007-04-25 09:53:08 -04002799 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
2800 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
2801 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
James Smart2e0fef82007-06-17 19:56:36 -05002802 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04002803 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05002804 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04002805 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002806 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2807 lpfc_issue_els_adisc(vport, ndlp, 0);
James Smart685f0bf2007-04-25 09:53:08 -04002808 sentadisc++;
James Smart2e0fef82007-06-17 19:56:36 -05002809 vport->num_disc_nodes++;
2810 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04002811 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05002812 spin_lock_irq(shost->host_lock);
2813 vport->fc_flag |= FC_NLP_MORE;
2814 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04002815 break;
dea31012005-04-17 16:05:31 -05002816 }
2817 }
2818 }
2819 if (sentadisc == 0) {
James Smart2e0fef82007-06-17 19:56:36 -05002820 spin_lock_irq(shost->host_lock);
2821 vport->fc_flag &= ~FC_NLP_MORE;
2822 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002823 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002824 return sentadisc;
dea31012005-04-17 16:05:31 -05002825}
2826
2827int
James Smart2e0fef82007-06-17 19:56:36 -05002828lpfc_els_disc_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002829{
James Smart2e0fef82007-06-17 19:56:36 -05002830 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002831 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05002832 int sentplogi = 0;
dea31012005-04-17 16:05:31 -05002833
James Smart2e0fef82007-06-17 19:56:36 -05002834 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
2835 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smart685f0bf2007-04-25 09:53:08 -04002836 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
2837 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
2838 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
2839 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
2840 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002841 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2842 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
James Smart685f0bf2007-04-25 09:53:08 -04002843 sentplogi++;
James Smart2e0fef82007-06-17 19:56:36 -05002844 vport->num_disc_nodes++;
2845 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04002846 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05002847 spin_lock_irq(shost->host_lock);
2848 vport->fc_flag |= FC_NLP_MORE;
2849 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04002850 break;
dea31012005-04-17 16:05:31 -05002851 }
2852 }
2853 }
James Smart87af33f2007-10-27 13:37:43 -04002854 if (sentplogi) {
2855 lpfc_set_disctmo(vport);
2856 }
2857 else {
James Smart2e0fef82007-06-17 19:56:36 -05002858 spin_lock_irq(shost->host_lock);
2859 vport->fc_flag &= ~FC_NLP_MORE;
2860 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002861 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002862 return sentplogi;
dea31012005-04-17 16:05:31 -05002863}
2864
James Smart92d7f7b2007-06-17 19:56:38 -05002865void
James Smart2e0fef82007-06-17 19:56:36 -05002866lpfc_els_flush_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002867{
James Smart2e0fef82007-06-17 19:56:36 -05002868 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2869 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002870 int i;
2871
James Smart2e0fef82007-06-17 19:56:36 -05002872 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05002873 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
James Smart2e0fef82007-06-17 19:56:36 -05002874 vport->fc_rscn_id_list[i] = NULL;
dea31012005-04-17 16:05:31 -05002875 }
James Smart2e0fef82007-06-17 19:56:36 -05002876 spin_lock_irq(shost->host_lock);
2877 vport->fc_rscn_id_cnt = 0;
2878 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
2879 spin_unlock_irq(shost->host_lock);
2880 lpfc_can_disctmo(vport);
dea31012005-04-17 16:05:31 -05002881}
2882
2883int
James Smart2e0fef82007-06-17 19:56:36 -05002884lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05002885{
2886 D_ID ns_did;
2887 D_ID rscn_did;
dea31012005-04-17 16:05:31 -05002888 uint32_t *lp;
James Smart92d7f7b2007-06-17 19:56:38 -05002889 uint32_t payload_len, i;
dea31012005-04-17 16:05:31 -05002890
2891 ns_did.un.word = did;
dea31012005-04-17 16:05:31 -05002892
2893 /* Never match fabric nodes for RSCNs */
2894 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
James Smart2e0fef82007-06-17 19:56:36 -05002895 return 0;
dea31012005-04-17 16:05:31 -05002896
2897 /* If we are doing a FULL RSCN rediscovery, match everything */
James Smart2e0fef82007-06-17 19:56:36 -05002898 if (vport->fc_flag & FC_RSCN_DISCOVERY)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002899 return did;
dea31012005-04-17 16:05:31 -05002900
James Smart2e0fef82007-06-17 19:56:36 -05002901 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05002902 lp = vport->fc_rscn_id_list[i]->virt;
2903 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
2904 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05002905 while (payload_len) {
James Smart92d7f7b2007-06-17 19:56:38 -05002906 rscn_did.un.word = be32_to_cpu(*lp++);
2907 payload_len -= sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002908 switch (rscn_did.un.b.resv) {
2909 case 0: /* Single N_Port ID effected */
James Smart2e0fef82007-06-17 19:56:36 -05002910 if (ns_did.un.word == rscn_did.un.word)
James Smart92d7f7b2007-06-17 19:56:38 -05002911 return did;
dea31012005-04-17 16:05:31 -05002912 break;
2913 case 1: /* Whole N_Port Area effected */
2914 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
2915 && (ns_did.un.b.area == rscn_did.un.b.area))
James Smart92d7f7b2007-06-17 19:56:38 -05002916 return did;
dea31012005-04-17 16:05:31 -05002917 break;
2918 case 2: /* Whole N_Port Domain effected */
2919 if (ns_did.un.b.domain == rscn_did.un.b.domain)
James Smart92d7f7b2007-06-17 19:56:38 -05002920 return did;
dea31012005-04-17 16:05:31 -05002921 break;
2922 default:
James Smart2e0fef82007-06-17 19:56:36 -05002923 /* Unknown Identifier in RSCN node */
James Smarte8b62012007-08-02 11:10:09 -04002924 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
2925 "0217 Unknown Identifier in "
2926 "RSCN payload Data: x%x\n",
2927 rscn_did.un.word);
James Smart92d7f7b2007-06-17 19:56:38 -05002928 case 3: /* Whole Fabric effected */
2929 return did;
dea31012005-04-17 16:05:31 -05002930 }
2931 }
James Smart92d7f7b2007-06-17 19:56:38 -05002932 }
2933 return 0;
dea31012005-04-17 16:05:31 -05002934}
2935
2936static int
James Smart2e0fef82007-06-17 19:56:36 -05002937lpfc_rscn_recovery_check(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002938{
James Smart685f0bf2007-04-25 09:53:08 -04002939 struct lpfc_nodelist *ndlp = NULL;
dea31012005-04-17 16:05:31 -05002940
2941 /* Look at all nodes effected by pending RSCNs and move
James Smart685f0bf2007-04-25 09:53:08 -04002942 * them to NPR state.
dea31012005-04-17 16:05:31 -05002943 */
James Smart685f0bf2007-04-25 09:53:08 -04002944
James Smart2e0fef82007-06-17 19:56:36 -05002945 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smart685f0bf2007-04-25 09:53:08 -04002946 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE ||
James Smart2e0fef82007-06-17 19:56:36 -05002947 lpfc_rscn_payload_check(vport, ndlp->nlp_DID) == 0)
dea31012005-04-17 16:05:31 -05002948 continue;
2949
James Smart2e0fef82007-06-17 19:56:36 -05002950 lpfc_disc_state_machine(vport, ndlp, NULL,
James Smart92d7f7b2007-06-17 19:56:38 -05002951 NLP_EVT_DEVICE_RECOVERY);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002952
James Smart685f0bf2007-04-25 09:53:08 -04002953 /*
2954 * Make sure NLP_DELAY_TMO is NOT running after a device
2955 * recovery event.
2956 */
2957 if (ndlp->nlp_flag & NLP_DELAY_TMO)
James Smart2e0fef82007-06-17 19:56:36 -05002958 lpfc_cancel_retry_delay_tmo(vport, ndlp);
dea31012005-04-17 16:05:31 -05002959 }
James Smart685f0bf2007-04-25 09:53:08 -04002960
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002961 return 0;
dea31012005-04-17 16:05:31 -05002962}
2963
2964static int
James Smart2e0fef82007-06-17 19:56:36 -05002965lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04002966 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05002967{
James Smart2e0fef82007-06-17 19:56:36 -05002968 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2969 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002970 struct lpfc_dmabuf *pcmd;
James Smart92d7f7b2007-06-17 19:56:38 -05002971 uint32_t *lp, *datap;
dea31012005-04-17 16:05:31 -05002972 IOCB_t *icmd;
James Smart92d7f7b2007-06-17 19:56:38 -05002973 uint32_t payload_len, length, nportid, *cmd;
2974 int rscn_cnt = vport->fc_rscn_id_cnt;
2975 int rscn_id = 0, hba_id = 0;
James Smartd2873e42006-08-18 17:46:43 -04002976 int i;
dea31012005-04-17 16:05:31 -05002977
2978 icmd = &cmdiocb->iocb;
2979 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
2980 lp = (uint32_t *) pcmd->virt;
2981
James Smart92d7f7b2007-06-17 19:56:38 -05002982 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
2983 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05002984 /* RSCN received */
James Smarte8b62012007-08-02 11:10:09 -04002985 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2986 "0214 RSCN received Data: x%x x%x x%x x%x\n",
2987 vport->fc_flag, payload_len, *lp, rscn_cnt);
James Smartd2873e42006-08-18 17:46:43 -04002988 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
James Smart2e0fef82007-06-17 19:56:36 -05002989 fc_host_post_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04002990 FCH_EVT_RSCN, lp[i]);
2991
dea31012005-04-17 16:05:31 -05002992 /* If we are about to begin discovery, just ACC the RSCN.
2993 * Discovery processing will satisfy it.
2994 */
James Smart2e0fef82007-06-17 19:56:36 -05002995 if (vport->port_state <= LPFC_NS_QRY) {
James Smart858c9f62007-06-17 19:56:39 -05002996 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
2997 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
2998 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
2999
James Smart51ef4c22007-08-02 11:10:31 -04003000 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003001 return 0;
dea31012005-04-17 16:05:31 -05003002 }
3003
James Smart92d7f7b2007-06-17 19:56:38 -05003004 /* If this RSCN just contains NPortIDs for other vports on this HBA,
3005 * just ACC and ignore it.
3006 */
3007 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart3de2a652007-08-02 11:09:59 -04003008 !(vport->cfg_peer_port_login)) {
James Smart92d7f7b2007-06-17 19:56:38 -05003009 i = payload_len;
3010 datap = lp;
3011 while (i > 0) {
3012 nportid = *datap++;
3013 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
3014 i -= sizeof(uint32_t);
3015 rscn_id++;
James Smart549e55c2007-08-02 11:09:51 -04003016 if (lpfc_find_vport_by_did(phba, nportid))
3017 hba_id++;
James Smart92d7f7b2007-06-17 19:56:38 -05003018 }
3019 if (rscn_id == hba_id) {
3020 /* ALL NPortIDs in RSCN are on HBA */
James Smarte8b62012007-08-02 11:10:09 -04003021 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3022 "0214 Ignore RSCN "
3023 "Data: x%x x%x x%x x%x\n",
3024 vport->fc_flag, payload_len,
3025 *lp, rscn_cnt);
James Smart858c9f62007-06-17 19:56:39 -05003026 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3027 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
3028 ndlp->nlp_DID, vport->port_state,
3029 ndlp->nlp_flag);
3030
James Smart92d7f7b2007-06-17 19:56:38 -05003031 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04003032 ndlp, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05003033 return 0;
3034 }
3035 }
3036
dea31012005-04-17 16:05:31 -05003037 /* If we are already processing an RSCN, save the received
3038 * RSCN payload buffer, cmdiocb->context2 to process later.
3039 */
James Smart2e0fef82007-06-17 19:56:36 -05003040 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
James Smart858c9f62007-06-17 19:56:39 -05003041 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3042 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
3043 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
3044
James Smart09372822008-01-11 01:52:54 -05003045 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05003046 vport->fc_flag |= FC_RSCN_DEFERRED;
3047 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
James Smart2e0fef82007-06-17 19:56:36 -05003048 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
James Smart2e0fef82007-06-17 19:56:36 -05003049 vport->fc_flag |= FC_RSCN_MODE;
3050 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05003051 if (rscn_cnt) {
3052 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
3053 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
3054 }
3055 if ((rscn_cnt) &&
3056 (payload_len + length <= LPFC_BPL_SIZE)) {
3057 *cmd &= ELS_CMD_MASK;
3058 *cmd |= be32_to_cpu(payload_len + length);
3059 memcpy(((uint8_t *)cmd) + length, lp,
3060 payload_len);
3061 } else {
3062 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
3063 vport->fc_rscn_id_cnt++;
3064 /* If we zero, cmdiocb->context2, the calling
3065 * routine will not try to free it.
3066 */
3067 cmdiocb->context2 = NULL;
3068 }
dea31012005-04-17 16:05:31 -05003069
3070 /* Deferred RSCN */
James Smarte8b62012007-08-02 11:10:09 -04003071 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3072 "0235 Deferred RSCN "
3073 "Data: x%x x%x x%x\n",
3074 vport->fc_rscn_id_cnt, vport->fc_flag,
3075 vport->port_state);
dea31012005-04-17 16:05:31 -05003076 } else {
James Smart2e0fef82007-06-17 19:56:36 -05003077 vport->fc_flag |= FC_RSCN_DISCOVERY;
3078 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003079 /* ReDiscovery RSCN */
James Smarte8b62012007-08-02 11:10:09 -04003080 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3081 "0234 ReDiscovery RSCN "
3082 "Data: x%x x%x x%x\n",
3083 vport->fc_rscn_id_cnt, vport->fc_flag,
3084 vport->port_state);
dea31012005-04-17 16:05:31 -05003085 }
3086 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04003087 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05003088
3089 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05003090 lpfc_rscn_recovery_check(vport);
James Smart09372822008-01-11 01:52:54 -05003091 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05003092 vport->fc_flag &= ~FC_RSCN_DEFERRED;
James Smart09372822008-01-11 01:52:54 -05003093 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003094 return 0;
dea31012005-04-17 16:05:31 -05003095 }
3096
James Smart858c9f62007-06-17 19:56:39 -05003097 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3098 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
3099 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
3100
James Smart2e0fef82007-06-17 19:56:36 -05003101 spin_lock_irq(shost->host_lock);
3102 vport->fc_flag |= FC_RSCN_MODE;
3103 spin_unlock_irq(shost->host_lock);
3104 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
dea31012005-04-17 16:05:31 -05003105 /*
3106 * If we zero, cmdiocb->context2, the calling routine will
3107 * not try to free it.
3108 */
3109 cmdiocb->context2 = NULL;
3110
James Smart2e0fef82007-06-17 19:56:36 -05003111 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05003112
3113 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04003114 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05003115
3116 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05003117 lpfc_rscn_recovery_check(vport);
dea31012005-04-17 16:05:31 -05003118
James Smart2e0fef82007-06-17 19:56:36 -05003119 return lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05003120}
3121
3122int
James Smart2e0fef82007-06-17 19:56:36 -05003123lpfc_els_handle_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003124{
3125 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05003126 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003127
James Smart92d7f7b2007-06-17 19:56:38 -05003128 /* Ignore RSCN if the port is being torn down. */
3129 if (vport->load_flag & FC_UNLOADING) {
3130 lpfc_els_flush_rscn(vport);
3131 return 0;
3132 }
3133
dea31012005-04-17 16:05:31 -05003134 /* Start timer for RSCN processing */
James Smart2e0fef82007-06-17 19:56:36 -05003135 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05003136
3137 /* RSCN processed */
James Smarte8b62012007-08-02 11:10:09 -04003138 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3139 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
3140 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
3141 vport->port_state);
dea31012005-04-17 16:05:31 -05003142
3143 /* To process RSCN, first compare RSCN data with NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05003144 vport->fc_ns_retry = 0;
James Smart0ff10d42008-01-11 01:52:36 -05003145 vport->num_disc_nodes = 0;
3146
James Smart2e0fef82007-06-17 19:56:36 -05003147 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smart685f0bf2007-04-25 09:53:08 -04003148 if (ndlp && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
dea31012005-04-17 16:05:31 -05003149 /* Good ndlp, issue CT Request to NameServer */
James Smart92d7f7b2007-06-17 19:56:38 -05003150 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
dea31012005-04-17 16:05:31 -05003151 /* Wait for NameServer query cmpl before we can
3152 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003153 return 1;
dea31012005-04-17 16:05:31 -05003154 } else {
3155 /* If login to NameServer does not exist, issue one */
3156 /* Good status, issue PLOGI to NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05003157 ndlp = lpfc_findnode_did(vport, NameServer_DID);
3158 if (ndlp)
dea31012005-04-17 16:05:31 -05003159 /* Wait for NameServer login cmpl before we can
3160 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003161 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05003162
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003163 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
3164 if (!ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05003165 lpfc_els_flush_rscn(vport);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003166 return 0;
dea31012005-04-17 16:05:31 -05003167 } else {
James Smart2e0fef82007-06-17 19:56:36 -05003168 lpfc_nlp_init(vport, ndlp, NameServer_DID);
dea31012005-04-17 16:05:31 -05003169 ndlp->nlp_type |= NLP_FABRIC;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003170 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003171 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
3172 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
dea31012005-04-17 16:05:31 -05003173 /* Wait for NameServer login cmpl before we can
3174 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003175 return 1;
dea31012005-04-17 16:05:31 -05003176 }
3177 }
3178
James Smart2e0fef82007-06-17 19:56:36 -05003179 lpfc_els_flush_rscn(vport);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003180 return 0;
dea31012005-04-17 16:05:31 -05003181}
3182
3183static int
James Smart2e0fef82007-06-17 19:56:36 -05003184lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04003185 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003186{
James Smart2e0fef82007-06-17 19:56:36 -05003187 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3188 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003189 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3190 uint32_t *lp = (uint32_t *) pcmd->virt;
3191 IOCB_t *icmd = &cmdiocb->iocb;
3192 struct serv_parm *sp;
3193 LPFC_MBOXQ_t *mbox;
3194 struct ls_rjt stat;
3195 uint32_t cmd, did;
3196 int rc;
3197
3198 cmd = *lp++;
3199 sp = (struct serv_parm *) lp;
3200
3201 /* FLOGI received */
3202
James Smart2e0fef82007-06-17 19:56:36 -05003203 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05003204
3205 if (phba->fc_topology == TOPOLOGY_LOOP) {
3206 /* We should never receive a FLOGI in loop mode, ignore it */
3207 did = icmd->un.elsreq64.remoteID;
3208
3209 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
3210 Loop Mode */
James Smarte8b62012007-08-02 11:10:09 -04003211 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3212 "0113 An FLOGI ELS command x%x was "
3213 "received from DID x%x in Loop Mode\n",
3214 cmd, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003215 return 1;
dea31012005-04-17 16:05:31 -05003216 }
3217
3218 did = Fabric_DID;
3219
James Smart2e0fef82007-06-17 19:56:36 -05003220 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3))) {
dea31012005-04-17 16:05:31 -05003221 /* For a FLOGI we accept, then if our portname is greater
3222 * then the remote portname we initiate Nport login.
3223 */
3224
James Smart2e0fef82007-06-17 19:56:36 -05003225 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -05003226 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003227
3228 if (!rc) {
James Smart2e0fef82007-06-17 19:56:36 -05003229 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3230 if (!mbox)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003231 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05003232
dea31012005-04-17 16:05:31 -05003233 lpfc_linkdown(phba);
3234 lpfc_init_link(phba, mbox,
3235 phba->cfg_topology,
3236 phba->cfg_link_speed);
3237 mbox->mb.un.varInitLnk.lipsr_AL_PA = 0;
3238 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -05003239 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -04003240 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart5b8bd0c2007-04-25 09:52:49 -04003241 lpfc_set_loopback_flag(phba);
dea31012005-04-17 16:05:31 -05003242 if (rc == MBX_NOT_FINISHED) {
James Smart329f9bc2007-04-25 09:53:01 -04003243 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003244 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003245 return 1;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003246 } else if (rc > 0) { /* greater than */
James Smart2e0fef82007-06-17 19:56:36 -05003247 spin_lock_irq(shost->host_lock);
3248 vport->fc_flag |= FC_PT2PT_PLOGI;
3249 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003250 }
James Smart2e0fef82007-06-17 19:56:36 -05003251 spin_lock_irq(shost->host_lock);
3252 vport->fc_flag |= FC_PT2PT;
3253 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
3254 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003255 } else {
3256 /* Reject this request because invalid parameters */
3257 stat.un.b.lsRjtRsvd0 = 0;
3258 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3259 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
3260 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05003261 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
3262 NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003263 return 1;
dea31012005-04-17 16:05:31 -05003264 }
3265
3266 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04003267 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05003268
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003269 return 0;
dea31012005-04-17 16:05:31 -05003270}
3271
3272static int
James Smart2e0fef82007-06-17 19:56:36 -05003273lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3274 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003275{
3276 struct lpfc_dmabuf *pcmd;
3277 uint32_t *lp;
3278 IOCB_t *icmd;
3279 RNID *rn;
3280 struct ls_rjt stat;
3281 uint32_t cmd, did;
3282
3283 icmd = &cmdiocb->iocb;
3284 did = icmd->un.elsreq64.remoteID;
3285 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3286 lp = (uint32_t *) pcmd->virt;
3287
3288 cmd = *lp++;
3289 rn = (RNID *) lp;
3290
3291 /* RNID received */
3292
3293 switch (rn->Format) {
3294 case 0:
3295 case RNID_TOPOLOGY_DISC:
3296 /* Send back ACC */
James Smart2e0fef82007-06-17 19:56:36 -05003297 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05003298 break;
3299 default:
3300 /* Reject this request because format not supported */
3301 stat.un.b.lsRjtRsvd0 = 0;
3302 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3303 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
3304 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05003305 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
3306 NULL);
dea31012005-04-17 16:05:31 -05003307 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003308 return 0;
dea31012005-04-17 16:05:31 -05003309}
3310
3311static int
James Smart2e0fef82007-06-17 19:56:36 -05003312lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3313 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003314{
3315 struct ls_rjt stat;
3316
3317 /* For now, unconditionally reject this command */
3318 stat.un.b.lsRjtRsvd0 = 0;
3319 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3320 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
3321 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05003322 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003323 return 0;
3324}
3325
Jamie Wellnitz082c0262006-02-28 19:25:30 -05003326static void
James Smart329f9bc2007-04-25 09:53:01 -04003327lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003328{
James Smart2e0fef82007-06-17 19:56:36 -05003329 struct lpfc_sli *psli = &phba->sli;
3330 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003331 MAILBOX_t *mb;
3332 IOCB_t *icmd;
3333 RPS_RSP *rps_rsp;
3334 uint8_t *pcmd;
3335 struct lpfc_iocbq *elsiocb;
3336 struct lpfc_nodelist *ndlp;
3337 uint16_t xri, status;
3338 uint32_t cmdsize;
3339
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003340 mb = &pmb->mb;
3341
3342 ndlp = (struct lpfc_nodelist *) pmb->context2;
3343 xri = (uint16_t) ((unsigned long)(pmb->context1));
Randy Dunlap041976f2006-06-25 01:58:51 -07003344 pmb->context1 = NULL;
3345 pmb->context2 = NULL;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003346
3347 if (mb->mbxStatus) {
James Smart329f9bc2007-04-25 09:53:01 -04003348 mempool_free(pmb, phba->mbox_mem_pool);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003349 return;
3350 }
3351
3352 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
James Smart329f9bc2007-04-25 09:53:01 -04003353 mempool_free(pmb, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05003354 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
3355 lpfc_max_els_tries, ndlp,
3356 ndlp->nlp_DID, ELS_CMD_ACC);
James Smartfa4066b2008-01-11 01:53:27 -05003357
3358 /* Decrement the ndlp reference count from previous mbox command */
James Smart329f9bc2007-04-25 09:53:01 -04003359 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05003360
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003361 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003362 return;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003363
3364 icmd = &elsiocb->iocb;
3365 icmd->ulpContext = xri;
3366
3367 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3368 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003369 pcmd += sizeof(uint32_t); /* Skip past command */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003370 rps_rsp = (RPS_RSP *)pcmd;
3371
3372 if (phba->fc_topology != TOPOLOGY_LOOP)
3373 status = 0x10;
3374 else
3375 status = 0x8;
James Smart2e0fef82007-06-17 19:56:36 -05003376 if (phba->pport->fc_flag & FC_FABRIC)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003377 status |= 0x4;
3378
3379 rps_rsp->rsvd1 = 0;
James Smart09372822008-01-11 01:52:54 -05003380 rps_rsp->portStatus = cpu_to_be16(status);
3381 rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
3382 rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
3383 rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
3384 rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
3385 rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
3386 rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003387 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003388 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
3389 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
3390 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
3391 elsiocb->iotag, elsiocb->iocb.ulpContext,
3392 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3393 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05003394 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003395 phba->fc_stat.elsXmitACC++;
James Smarted957682007-06-17 19:56:37 -05003396 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003397 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003398 return;
3399}
3400
3401static int
James Smart2e0fef82007-06-17 19:56:36 -05003402lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3403 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003404{
James Smart2e0fef82007-06-17 19:56:36 -05003405 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003406 uint32_t *lp;
3407 uint8_t flag;
3408 LPFC_MBOXQ_t *mbox;
3409 struct lpfc_dmabuf *pcmd;
3410 RPS *rps;
3411 struct ls_rjt stat;
3412
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003413 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
3414 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003415 stat.un.b.lsRjtRsvd0 = 0;
3416 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3417 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
3418 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05003419 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
3420 NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003421 }
3422
3423 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3424 lp = (uint32_t *) pcmd->virt;
3425 flag = (be32_to_cpu(*lp++) & 0xf);
3426 rps = (RPS *) lp;
3427
3428 if ((flag == 0) ||
3429 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
James Smart2e0fef82007-06-17 19:56:36 -05003430 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05003431 sizeof(struct lpfc_name)) == 0))) {
James Smart2e0fef82007-06-17 19:56:36 -05003432
James Smart92d7f7b2007-06-17 19:56:38 -05003433 printk("Fix me....\n");
3434 dump_stack();
James Smart2e0fef82007-06-17 19:56:36 -05003435 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
3436 if (mbox) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003437 lpfc_read_lnk_stat(phba, mbox);
3438 mbox->context1 =
James Smart92d7f7b2007-06-17 19:56:38 -05003439 (void *)((unsigned long) cmdiocb->iocb.ulpContext);
James Smart329f9bc2007-04-25 09:53:01 -04003440 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05003441 mbox->vport = vport;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003442 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
James Smartfa4066b2008-01-11 01:53:27 -05003443 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart0b727fe2007-10-27 13:37:25 -04003444 != MBX_NOT_FINISHED)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003445 /* Mbox completion will send ELS Response */
3446 return 0;
James Smartfa4066b2008-01-11 01:53:27 -05003447 /* Decrement reference count used for the failed mbox
3448 * command.
3449 */
James Smart329f9bc2007-04-25 09:53:01 -04003450 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003451 mempool_free(mbox, phba->mbox_mem_pool);
3452 }
3453 }
3454 stat.un.b.lsRjtRsvd0 = 0;
3455 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3456 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
3457 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05003458 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003459 return 0;
3460}
3461
Jamie Wellnitz082c0262006-02-28 19:25:30 -05003462static int
James Smart2e0fef82007-06-17 19:56:36 -05003463lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
3464 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003465{
James Smart2e0fef82007-06-17 19:56:36 -05003466 struct lpfc_hba *phba = vport->phba;
3467 IOCB_t *icmd, *oldcmd;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003468 RPL_RSP rpl_rsp;
3469 struct lpfc_iocbq *elsiocb;
James Smart2e0fef82007-06-17 19:56:36 -05003470 struct lpfc_sli *psli = &phba->sli;
3471 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003472 uint8_t *pcmd;
3473
James Smart2e0fef82007-06-17 19:56:36 -05003474 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3475 ndlp->nlp_DID, ELS_CMD_ACC);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003476
James Smart488d1462006-03-07 15:02:37 -05003477 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003478 return 1;
James Smart488d1462006-03-07 15:02:37 -05003479
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003480 icmd = &elsiocb->iocb;
3481 oldcmd = &oldiocb->iocb;
3482 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3483
3484 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3485 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003486 pcmd += sizeof(uint16_t);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003487 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
3488 pcmd += sizeof(uint16_t);
3489
3490 /* Setup the RPL ACC payload */
3491 rpl_rsp.listLen = be32_to_cpu(1);
3492 rpl_rsp.index = 0;
3493 rpl_rsp.port_num_blk.portNum = 0;
James Smart2e0fef82007-06-17 19:56:36 -05003494 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
3495 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003496 sizeof(struct lpfc_name));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003497 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003498 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003499 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3500 "0120 Xmit ELS RPL ACC response tag x%x "
3501 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
3502 "rpi x%x\n",
3503 elsiocb->iotag, elsiocb->iocb.ulpContext,
3504 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3505 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05003506 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003507 phba->fc_stat.elsXmitACC++;
3508 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
3509 lpfc_els_free_iocb(phba, elsiocb);
3510 return 1;
3511 }
3512 return 0;
3513}
3514
3515static int
James Smart2e0fef82007-06-17 19:56:36 -05003516lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3517 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003518{
3519 struct lpfc_dmabuf *pcmd;
3520 uint32_t *lp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003521 uint32_t maxsize;
3522 uint16_t cmdsize;
3523 RPL *rpl;
3524 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05003525
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003526 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
3527 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003528 stat.un.b.lsRjtRsvd0 = 0;
3529 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3530 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
3531 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05003532 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
3533 NULL);
dea31012005-04-17 16:05:31 -05003534 }
3535
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003536 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3537 lp = (uint32_t *) pcmd->virt;
3538 rpl = (RPL *) (lp + 1);
3539
3540 maxsize = be32_to_cpu(rpl->maxsize);
3541
3542 /* We support only one port */
3543 if ((rpl->index == 0) &&
3544 ((maxsize == 0) ||
3545 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
3546 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003547 } else {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003548 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
3549 }
James Smart2e0fef82007-06-17 19:56:36 -05003550 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05003551
3552 return 0;
3553}
3554
3555static int
James Smart2e0fef82007-06-17 19:56:36 -05003556lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3557 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003558{
3559 struct lpfc_dmabuf *pcmd;
3560 uint32_t *lp;
3561 IOCB_t *icmd;
3562 FARP *fp;
3563 uint32_t cmd, cnt, did;
3564
3565 icmd = &cmdiocb->iocb;
3566 did = icmd->un.elsreq64.remoteID;
3567 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3568 lp = (uint32_t *) pcmd->virt;
3569
3570 cmd = *lp++;
3571 fp = (FARP *) lp;
dea31012005-04-17 16:05:31 -05003572 /* FARP-REQ received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04003573 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3574 "0601 FARP-REQ received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05003575 /* We will only support match on WWPN or WWNN */
3576 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003577 return 0;
dea31012005-04-17 16:05:31 -05003578 }
3579
3580 cnt = 0;
3581 /* If this FARP command is searching for my portname */
3582 if (fp->Mflags & FARP_MATCH_PORT) {
James Smart2e0fef82007-06-17 19:56:36 -05003583 if (memcmp(&fp->RportName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05003584 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05003585 cnt = 1;
3586 }
3587
3588 /* If this FARP command is searching for my nodename */
3589 if (fp->Mflags & FARP_MATCH_NODE) {
James Smart2e0fef82007-06-17 19:56:36 -05003590 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05003591 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05003592 cnt = 1;
3593 }
3594
3595 if (cnt) {
3596 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
3597 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
3598 /* Log back into the node before sending the FARP. */
3599 if (fp->Rflags & FARP_REQUEST_PLOGI) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003600 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003601 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04003602 NLP_STE_PLOGI_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05003603 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05003604 }
3605
3606 /* Send a FARP response to that node */
James Smart2e0fef82007-06-17 19:56:36 -05003607 if (fp->Rflags & FARP_REQUEST_FARPR)
3608 lpfc_issue_els_farpr(vport, did, 0);
dea31012005-04-17 16:05:31 -05003609 }
3610 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003611 return 0;
dea31012005-04-17 16:05:31 -05003612}
3613
3614static int
James Smart2e0fef82007-06-17 19:56:36 -05003615lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3616 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003617{
3618 struct lpfc_dmabuf *pcmd;
3619 uint32_t *lp;
3620 IOCB_t *icmd;
3621 uint32_t cmd, did;
3622
3623 icmd = &cmdiocb->iocb;
3624 did = icmd->un.elsreq64.remoteID;
3625 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3626 lp = (uint32_t *) pcmd->virt;
3627
3628 cmd = *lp++;
3629 /* FARP-RSP received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04003630 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3631 "0600 FARP-RSP received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05003632 /* ACCEPT the Farp resp request */
James Smart51ef4c22007-08-02 11:10:31 -04003633 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05003634
3635 return 0;
3636}
3637
3638static int
James Smart2e0fef82007-06-17 19:56:36 -05003639lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3640 struct lpfc_nodelist *fan_ndlp)
dea31012005-04-17 16:05:31 -05003641{
3642 struct lpfc_dmabuf *pcmd;
3643 uint32_t *lp;
3644 IOCB_t *icmd;
dea31012005-04-17 16:05:31 -05003645 uint32_t cmd, did;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003646 FAN *fp;
3647 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05003648 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003649
3650 /* FAN received */
James Smarte8b62012007-08-02 11:10:09 -04003651 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3652 "0265 FAN received\n");
dea31012005-04-17 16:05:31 -05003653 icmd = &cmdiocb->iocb;
3654 did = icmd->un.elsreq64.remoteID;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003655 pcmd = (struct lpfc_dmabuf *)cmdiocb->context2;
3656 lp = (uint32_t *)pcmd->virt;
dea31012005-04-17 16:05:31 -05003657
3658 cmd = *lp++;
James Smart92d7f7b2007-06-17 19:56:38 -05003659 fp = (FAN *) lp;
dea31012005-04-17 16:05:31 -05003660
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003661 /* FAN received; Fan does not have a reply sequence */
dea31012005-04-17 16:05:31 -05003662
James Smart2e0fef82007-06-17 19:56:36 -05003663 if (phba->pport->port_state == LPFC_LOCAL_CFG_LINK) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003664 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
3665 sizeof(struct lpfc_name)) != 0) ||
3666 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
3667 sizeof(struct lpfc_name)) != 0)) {
3668 /*
3669 * This node has switched fabrics. FLOGI is required
3670 * Clean up the old rpi's
dea31012005-04-17 16:05:31 -05003671 */
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003672
3673 list_for_each_entry_safe(ndlp, next_ndlp,
James Smart2e0fef82007-06-17 19:56:36 -05003674 &vport->fc_nodes, nlp_listp) {
James Smart685f0bf2007-04-25 09:53:08 -04003675 if (ndlp->nlp_state != NLP_STE_NPR_NODE)
3676 continue;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003677 if (ndlp->nlp_type & NLP_FABRIC) {
3678 /*
3679 * Clean up old Fabric, Nameserver and
3680 * other NLP_FABRIC logins
3681 */
James Smart2e0fef82007-06-17 19:56:36 -05003682 lpfc_drop_node(vport, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04003683
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003684 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003685 /* Fail outstanding I/O now since this
3686 * device is marked for PLOGI
3687 */
James Smart2e0fef82007-06-17 19:56:36 -05003688 lpfc_unreg_rpi(vport, ndlp);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003689 }
3690 }
3691
James Smart2e0fef82007-06-17 19:56:36 -05003692 lpfc_initial_flogi(vport);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003693 return 0;
dea31012005-04-17 16:05:31 -05003694 }
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003695 /* Discovery not needed,
3696 * move the nodes to their original state.
3697 */
James Smart2e0fef82007-06-17 19:56:36 -05003698 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
James Smart685f0bf2007-04-25 09:53:08 -04003699 nlp_listp) {
3700 if (ndlp->nlp_state != NLP_STE_NPR_NODE)
3701 continue;
dea31012005-04-17 16:05:31 -05003702
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003703 switch (ndlp->nlp_prev_state) {
3704 case NLP_STE_UNMAPPED_NODE:
3705 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05003706 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04003707 NLP_STE_UNMAPPED_NODE);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003708 break;
3709
3710 case NLP_STE_MAPPED_NODE:
3711 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05003712 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04003713 NLP_STE_MAPPED_NODE);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003714 break;
3715
3716 default:
3717 break;
3718 }
3719 }
3720
3721 /* Start discovery - this should just do CLEAR_LA */
James Smart2e0fef82007-06-17 19:56:36 -05003722 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -05003723 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003724 return 0;
dea31012005-04-17 16:05:31 -05003725}
3726
3727void
3728lpfc_els_timeout(unsigned long ptr)
3729{
James Smart2e0fef82007-06-17 19:56:36 -05003730 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
3731 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003732 unsigned long iflag;
3733
James Smart2e0fef82007-06-17 19:56:36 -05003734 spin_lock_irqsave(&vport->work_port_lock, iflag);
3735 if ((vport->work_port_events & WORKER_ELS_TMO) == 0) {
3736 vport->work_port_events |= WORKER_ELS_TMO;
James Smart92d7f7b2007-06-17 19:56:38 -05003737 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
3738
3739 spin_lock_irqsave(&phba->hbalock, iflag);
dea31012005-04-17 16:05:31 -05003740 if (phba->work_wait)
James Smart92d7f7b2007-06-17 19:56:38 -05003741 lpfc_worker_wake_up(phba);
3742 spin_unlock_irqrestore(&phba->hbalock, iflag);
dea31012005-04-17 16:05:31 -05003743 }
James Smart92d7f7b2007-06-17 19:56:38 -05003744 else
3745 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
dea31012005-04-17 16:05:31 -05003746 return;
3747}
3748
3749void
James Smart2e0fef82007-06-17 19:56:36 -05003750lpfc_els_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003751{
James Smart2e0fef82007-06-17 19:56:36 -05003752 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003753 struct lpfc_sli_ring *pring;
3754 struct lpfc_iocbq *tmp_iocb, *piocb;
3755 IOCB_t *cmd = NULL;
3756 struct lpfc_dmabuf *pcmd;
James Smart2e0fef82007-06-17 19:56:36 -05003757 uint32_t els_command = 0;
dea31012005-04-17 16:05:31 -05003758 uint32_t timeout;
James Smart2e0fef82007-06-17 19:56:36 -05003759 uint32_t remote_ID = 0xffffffff;
dea31012005-04-17 16:05:31 -05003760
dea31012005-04-17 16:05:31 -05003761 /* If the timer is already canceled do nothing */
James Smart2e0fef82007-06-17 19:56:36 -05003762 if ((vport->work_port_events & WORKER_ELS_TMO) == 0) {
dea31012005-04-17 16:05:31 -05003763 return;
3764 }
James Smart2e0fef82007-06-17 19:56:36 -05003765 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003766 timeout = (uint32_t)(phba->fc_ratov << 1);
3767
3768 pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05003769
3770 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
3771 cmd = &piocb->iocb;
3772
James Smart2e0fef82007-06-17 19:56:36 -05003773 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
3774 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
3775 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
dea31012005-04-17 16:05:31 -05003776 continue;
James Smart2e0fef82007-06-17 19:56:36 -05003777
3778 if (piocb->vport != vport)
3779 continue;
3780
dea31012005-04-17 16:05:31 -05003781 pcmd = (struct lpfc_dmabuf *) piocb->context2;
James Smart2e0fef82007-06-17 19:56:36 -05003782 if (pcmd)
3783 els_command = *(uint32_t *) (pcmd->virt);
dea31012005-04-17 16:05:31 -05003784
James Smart92d7f7b2007-06-17 19:56:38 -05003785 if (els_command == ELS_CMD_FARP ||
3786 els_command == ELS_CMD_FARPR ||
3787 els_command == ELS_CMD_FDISC)
dea31012005-04-17 16:05:31 -05003788 continue;
James Smart92d7f7b2007-06-17 19:56:38 -05003789
3790 if (vport != piocb->vport)
3791 continue;
dea31012005-04-17 16:05:31 -05003792
3793 if (piocb->drvrTimeout > 0) {
James Smart92d7f7b2007-06-17 19:56:38 -05003794 if (piocb->drvrTimeout >= timeout)
dea31012005-04-17 16:05:31 -05003795 piocb->drvrTimeout -= timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05003796 else
dea31012005-04-17 16:05:31 -05003797 piocb->drvrTimeout = 0;
dea31012005-04-17 16:05:31 -05003798 continue;
3799 }
3800
James Smart2e0fef82007-06-17 19:56:36 -05003801 remote_ID = 0xffffffff;
3802 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
dea31012005-04-17 16:05:31 -05003803 remote_ID = cmd->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05003804 else {
3805 struct lpfc_nodelist *ndlp;
3806 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
3807 if (ndlp)
3808 remote_ID = ndlp->nlp_DID;
dea31012005-04-17 16:05:31 -05003809 }
James Smarte8b62012007-08-02 11:10:09 -04003810 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3811 "0127 ELS timeout Data: x%x x%x x%x "
3812 "x%x\n", els_command,
3813 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
James Smart07951072007-04-25 09:51:38 -04003814 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05003815 }
James Smart2e0fef82007-06-17 19:56:36 -05003816 spin_unlock_irq(&phba->hbalock);
James Smart5a0e3262006-07-06 15:49:16 -04003817
James Smart2e0fef82007-06-17 19:56:36 -05003818 if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt)
3819 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
dea31012005-04-17 16:05:31 -05003820}
3821
3822void
James Smart2e0fef82007-06-17 19:56:36 -05003823lpfc_els_flush_cmd(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003824{
James Smart2534ba72007-04-25 09:52:20 -04003825 LIST_HEAD(completions);
James Smart2e0fef82007-06-17 19:56:36 -05003826 struct lpfc_hba *phba = vport->phba;
James Smart329f9bc2007-04-25 09:53:01 -04003827 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05003828 struct lpfc_iocbq *tmp_iocb, *piocb;
3829 IOCB_t *cmd = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05003830
3831 lpfc_fabric_abort_vport(vport);
dea31012005-04-17 16:05:31 -05003832
James Smart2e0fef82007-06-17 19:56:36 -05003833 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003834 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
3835 cmd = &piocb->iocb;
3836
3837 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
3838 continue;
3839 }
3840
3841 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
James Smart329f9bc2007-04-25 09:53:01 -04003842 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
3843 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
3844 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
3845 cmd->ulpCommand == CMD_ABORT_XRI_CN)
dea31012005-04-17 16:05:31 -05003846 continue;
dea31012005-04-17 16:05:31 -05003847
James Smart2e0fef82007-06-17 19:56:36 -05003848 if (piocb->vport != vport)
3849 continue;
3850
James Smart2534ba72007-04-25 09:52:20 -04003851 list_move_tail(&piocb->list, &completions);
James Smart1dcb58e2007-04-25 09:51:30 -04003852 pring->txq_cnt--;
dea31012005-04-17 16:05:31 -05003853 }
3854
3855 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
dea31012005-04-17 16:05:31 -05003856 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
3857 continue;
3858 }
dea31012005-04-17 16:05:31 -05003859
James Smart2e0fef82007-06-17 19:56:36 -05003860 if (piocb->vport != vport)
3861 continue;
3862
James Smart07951072007-04-25 09:51:38 -04003863 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05003864 }
James Smart2e0fef82007-06-17 19:56:36 -05003865 spin_unlock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04003866
James Smart2e0fef82007-06-17 19:56:36 -05003867 while (!list_empty(&completions)) {
James Smart2534ba72007-04-25 09:52:20 -04003868 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
3869 cmd = &piocb->iocb;
James Smart92d7f7b2007-06-17 19:56:38 -05003870 list_del_init(&piocb->list);
James Smart2534ba72007-04-25 09:52:20 -04003871
James Smart2e0fef82007-06-17 19:56:36 -05003872 if (!piocb->iocb_cmpl)
3873 lpfc_sli_release_iocbq(phba, piocb);
3874 else {
James Smart2534ba72007-04-25 09:52:20 -04003875 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
3876 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
3877 (piocb->iocb_cmpl) (phba, piocb, piocb);
James Smart2e0fef82007-06-17 19:56:36 -05003878 }
James Smart2534ba72007-04-25 09:52:20 -04003879 }
3880
dea31012005-04-17 16:05:31 -05003881 return;
3882}
3883
James Smart549e55c2007-08-02 11:09:51 -04003884void
3885lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
3886{
3887 LIST_HEAD(completions);
3888 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
3889 struct lpfc_iocbq *tmp_iocb, *piocb;
3890 IOCB_t *cmd = NULL;
3891
3892 lpfc_fabric_abort_hba(phba);
3893 spin_lock_irq(&phba->hbalock);
3894 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
3895 cmd = &piocb->iocb;
3896 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
3897 continue;
3898 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
3899 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
3900 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
3901 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
3902 cmd->ulpCommand == CMD_ABORT_XRI_CN)
3903 continue;
3904 list_move_tail(&piocb->list, &completions);
3905 pring->txq_cnt--;
3906 }
3907 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
3908 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
3909 continue;
3910 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
3911 }
3912 spin_unlock_irq(&phba->hbalock);
3913 while (!list_empty(&completions)) {
3914 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
3915 cmd = &piocb->iocb;
3916 list_del_init(&piocb->list);
3917 if (!piocb->iocb_cmpl)
3918 lpfc_sli_release_iocbq(phba, piocb);
3919 else {
3920 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
3921 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
3922 (piocb->iocb_cmpl) (phba, piocb, piocb);
3923 }
3924 }
3925 return;
3926}
3927
James Smarted957682007-06-17 19:56:37 -05003928static void
3929lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
James Smart92d7f7b2007-06-17 19:56:38 -05003930 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05003931{
James Smart87af33f2007-10-27 13:37:43 -04003932 struct Scsi_Host *shost;
dea31012005-04-17 16:05:31 -05003933 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05003934 struct ls_rjt stat;
James Smart92d7f7b2007-06-17 19:56:38 -05003935 uint32_t *payload;
James Smart2e0fef82007-06-17 19:56:36 -05003936 uint32_t cmd, did, newnode, rjt_err = 0;
James Smarted957682007-06-17 19:56:37 -05003937 IOCB_t *icmd = &elsiocb->iocb;
dea31012005-04-17 16:05:31 -05003938
James Smart92d7f7b2007-06-17 19:56:38 -05003939 if (vport == NULL || elsiocb->context2 == NULL)
dea31012005-04-17 16:05:31 -05003940 goto dropit;
James Smart2e0fef82007-06-17 19:56:36 -05003941
dea31012005-04-17 16:05:31 -05003942 newnode = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05003943 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
3944 cmd = *payload;
James Smarted957682007-06-17 19:56:37 -05003945 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
3946 lpfc_post_buffer(phba, pring, 1, 1);
dea31012005-04-17 16:05:31 -05003947
James Smart858c9f62007-06-17 19:56:39 -05003948 did = icmd->un.rcvels.remoteID;
3949 if (icmd->ulpStatus) {
3950 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3951 "RCV Unsol ELS: status:x%x/x%x did:x%x",
3952 icmd->ulpStatus, icmd->un.ulpWord[4], did);
dea31012005-04-17 16:05:31 -05003953 goto dropit;
James Smart858c9f62007-06-17 19:56:39 -05003954 }
dea31012005-04-17 16:05:31 -05003955
3956 /* Check to see if link went down during discovery */
James Smarted957682007-06-17 19:56:37 -05003957 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05003958 goto dropit;
dea31012005-04-17 16:05:31 -05003959
James Smart92d7f7b2007-06-17 19:56:38 -05003960 /* Ignore traffic recevied during vport shutdown. */
3961 if (vport->load_flag & FC_UNLOADING)
3962 goto dropit;
3963
James Smart2e0fef82007-06-17 19:56:36 -05003964 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003965 if (!ndlp) {
dea31012005-04-17 16:05:31 -05003966 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003967 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
James Smarted957682007-06-17 19:56:37 -05003968 if (!ndlp)
dea31012005-04-17 16:05:31 -05003969 goto dropit;
dea31012005-04-17 16:05:31 -05003970
James Smart2e0fef82007-06-17 19:56:36 -05003971 lpfc_nlp_init(vport, ndlp, did);
James Smart98c9ea52007-10-27 13:37:33 -04003972 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05003973 newnode = 1;
3974 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK) {
3975 ndlp->nlp_type |= NLP_FABRIC;
3976 }
3977 }
James Smart87af33f2007-10-27 13:37:43 -04003978 else {
3979 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
3980 /* This is simular to the new node path */
3981 lpfc_nlp_get(ndlp);
3982 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
3983 newnode = 1;
3984 }
3985 }
dea31012005-04-17 16:05:31 -05003986
3987 phba->fc_stat.elsRcvFrame++;
James Smart329f9bc2007-04-25 09:53:01 -04003988 if (elsiocb->context1)
3989 lpfc_nlp_put(elsiocb->context1);
3990 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05003991 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -05003992
3993 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
3994 cmd &= ELS_CMD_MASK;
3995 }
3996 /* ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04003997 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3998 "0112 ELS command x%x received from NPORT x%x "
3999 "Data: x%x\n", cmd, did, vport->port_state);
dea31012005-04-17 16:05:31 -05004000 switch (cmd) {
4001 case ELS_CMD_PLOGI:
James Smart858c9f62007-06-17 19:56:39 -05004002 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4003 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
4004 did, vport->port_state, ndlp->nlp_flag);
4005
dea31012005-04-17 16:05:31 -05004006 phba->fc_stat.elsRcvPLOGI++;
James Smart858c9f62007-06-17 19:56:39 -05004007 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
4008
4009 if (vport->port_state < LPFC_DISC_AUTH) {
4010 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05004011 break;
4012 }
James Smart87af33f2007-10-27 13:37:43 -04004013
4014 shost = lpfc_shost_from_vport(vport);
4015 spin_lock_irq(shost->host_lock);
4016 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
4017 spin_unlock_irq(shost->host_lock);
4018
James Smart2e0fef82007-06-17 19:56:36 -05004019 lpfc_disc_state_machine(vport, ndlp, elsiocb,
4020 NLP_EVT_RCV_PLOGI);
James Smart858c9f62007-06-17 19:56:39 -05004021
dea31012005-04-17 16:05:31 -05004022 break;
4023 case ELS_CMD_FLOGI:
James Smart858c9f62007-06-17 19:56:39 -05004024 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4025 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
4026 did, vport->port_state, ndlp->nlp_flag);
4027
dea31012005-04-17 16:05:31 -05004028 phba->fc_stat.elsRcvFLOGI++;
James Smart51ef4c22007-08-02 11:10:31 -04004029 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04004030 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04004031 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05004032 break;
4033 case ELS_CMD_LOGO:
James Smart858c9f62007-06-17 19:56:39 -05004034 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4035 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
4036 did, vport->port_state, ndlp->nlp_flag);
4037
dea31012005-04-17 16:05:31 -05004038 phba->fc_stat.elsRcvLOGO++;
James Smart2e0fef82007-06-17 19:56:36 -05004039 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05004040 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05004041 break;
4042 }
James Smart2e0fef82007-06-17 19:56:36 -05004043 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
dea31012005-04-17 16:05:31 -05004044 break;
4045 case ELS_CMD_PRLO:
James Smart858c9f62007-06-17 19:56:39 -05004046 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4047 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
4048 did, vport->port_state, ndlp->nlp_flag);
4049
dea31012005-04-17 16:05:31 -05004050 phba->fc_stat.elsRcvPRLO++;
James Smart2e0fef82007-06-17 19:56:36 -05004051 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05004052 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05004053 break;
4054 }
James Smart2e0fef82007-06-17 19:56:36 -05004055 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
dea31012005-04-17 16:05:31 -05004056 break;
4057 case ELS_CMD_RSCN:
4058 phba->fc_stat.elsRcvRSCN++;
James Smart51ef4c22007-08-02 11:10:31 -04004059 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04004060 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04004061 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05004062 break;
4063 case ELS_CMD_ADISC:
James Smart858c9f62007-06-17 19:56:39 -05004064 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4065 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
4066 did, vport->port_state, ndlp->nlp_flag);
4067
dea31012005-04-17 16:05:31 -05004068 phba->fc_stat.elsRcvADISC++;
James Smart2e0fef82007-06-17 19:56:36 -05004069 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05004070 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05004071 break;
4072 }
James Smart2e0fef82007-06-17 19:56:36 -05004073 lpfc_disc_state_machine(vport, ndlp, elsiocb,
4074 NLP_EVT_RCV_ADISC);
dea31012005-04-17 16:05:31 -05004075 break;
4076 case ELS_CMD_PDISC:
James Smart858c9f62007-06-17 19:56:39 -05004077 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4078 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
4079 did, vport->port_state, ndlp->nlp_flag);
4080
dea31012005-04-17 16:05:31 -05004081 phba->fc_stat.elsRcvPDISC++;
James Smart2e0fef82007-06-17 19:56:36 -05004082 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05004083 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05004084 break;
4085 }
James Smart2e0fef82007-06-17 19:56:36 -05004086 lpfc_disc_state_machine(vport, ndlp, elsiocb,
4087 NLP_EVT_RCV_PDISC);
dea31012005-04-17 16:05:31 -05004088 break;
4089 case ELS_CMD_FARPR:
James Smart858c9f62007-06-17 19:56:39 -05004090 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4091 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
4092 did, vport->port_state, ndlp->nlp_flag);
4093
dea31012005-04-17 16:05:31 -05004094 phba->fc_stat.elsRcvFARPR++;
James Smart2e0fef82007-06-17 19:56:36 -05004095 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05004096 break;
4097 case ELS_CMD_FARP:
James Smart858c9f62007-06-17 19:56:39 -05004098 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4099 "RCV FARP: did:x%x/ste:x%x flg:x%x",
4100 did, vport->port_state, ndlp->nlp_flag);
4101
dea31012005-04-17 16:05:31 -05004102 phba->fc_stat.elsRcvFARP++;
James Smart2e0fef82007-06-17 19:56:36 -05004103 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05004104 break;
4105 case ELS_CMD_FAN:
James Smart858c9f62007-06-17 19:56:39 -05004106 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4107 "RCV FAN: did:x%x/ste:x%x flg:x%x",
4108 did, vport->port_state, ndlp->nlp_flag);
4109
dea31012005-04-17 16:05:31 -05004110 phba->fc_stat.elsRcvFAN++;
James Smart2e0fef82007-06-17 19:56:36 -05004111 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05004112 break;
dea31012005-04-17 16:05:31 -05004113 case ELS_CMD_PRLI:
James Smart858c9f62007-06-17 19:56:39 -05004114 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4115 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
4116 did, vport->port_state, ndlp->nlp_flag);
4117
dea31012005-04-17 16:05:31 -05004118 phba->fc_stat.elsRcvPRLI++;
James Smart2e0fef82007-06-17 19:56:36 -05004119 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05004120 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05004121 break;
4122 }
James Smart2e0fef82007-06-17 19:56:36 -05004123 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
dea31012005-04-17 16:05:31 -05004124 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004125 case ELS_CMD_LIRR:
James Smart858c9f62007-06-17 19:56:39 -05004126 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4127 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
4128 did, vport->port_state, ndlp->nlp_flag);
4129
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004130 phba->fc_stat.elsRcvLIRR++;
James Smart2e0fef82007-06-17 19:56:36 -05004131 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04004132 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04004133 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004134 break;
4135 case ELS_CMD_RPS:
James Smart858c9f62007-06-17 19:56:39 -05004136 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4137 "RCV RPS: did:x%x/ste:x%x flg:x%x",
4138 did, vport->port_state, ndlp->nlp_flag);
4139
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004140 phba->fc_stat.elsRcvRPS++;
James Smart2e0fef82007-06-17 19:56:36 -05004141 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04004142 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04004143 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004144 break;
4145 case ELS_CMD_RPL:
James Smart858c9f62007-06-17 19:56:39 -05004146 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4147 "RCV RPL: did:x%x/ste:x%x flg:x%x",
4148 did, vport->port_state, ndlp->nlp_flag);
4149
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004150 phba->fc_stat.elsRcvRPL++;
James Smart2e0fef82007-06-17 19:56:36 -05004151 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04004152 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04004153 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004154 break;
dea31012005-04-17 16:05:31 -05004155 case ELS_CMD_RNID:
James Smart858c9f62007-06-17 19:56:39 -05004156 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4157 "RCV RNID: did:x%x/ste:x%x flg:x%x",
4158 did, vport->port_state, ndlp->nlp_flag);
4159
dea31012005-04-17 16:05:31 -05004160 phba->fc_stat.elsRcvRNID++;
James Smart2e0fef82007-06-17 19:56:36 -05004161 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04004162 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04004163 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05004164 break;
4165 default:
James Smart858c9f62007-06-17 19:56:39 -05004166 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4167 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
4168 cmd, did, vport->port_state);
4169
dea31012005-04-17 16:05:31 -05004170 /* Unsupported ELS command, reject */
James Smart858c9f62007-06-17 19:56:39 -05004171 rjt_err = LSRJT_INVALID_CMD;
dea31012005-04-17 16:05:31 -05004172
4173 /* Unknown ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04004174 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4175 "0115 Unknown ELS command x%x "
4176 "received from NPORT x%x\n", cmd, did);
James Smart87af33f2007-10-27 13:37:43 -04004177 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04004178 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05004179 break;
4180 }
4181
4182 /* check if need to LS_RJT received ELS cmd */
4183 if (rjt_err) {
James Smart92d7f7b2007-06-17 19:56:38 -05004184 memset(&stat, 0, sizeof(stat));
James Smart858c9f62007-06-17 19:56:39 -05004185 stat.un.b.lsRjtRsnCode = rjt_err;
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04004186 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart858c9f62007-06-17 19:56:39 -05004187 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
4188 NULL);
dea31012005-04-17 16:05:31 -05004189 }
4190
James Smarted957682007-06-17 19:56:37 -05004191 return;
4192
4193dropit:
James Smart98c9ea52007-10-27 13:37:33 -04004194 if (vport && !(vport->load_flag & FC_UNLOADING))
4195 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
James Smarte8b62012007-08-02 11:10:09 -04004196 "(%d):0111 Dropping received ELS cmd "
James Smarted957682007-06-17 19:56:37 -05004197 "Data: x%x x%x x%x\n",
James Smart98c9ea52007-10-27 13:37:33 -04004198 vport->vpi, icmd->ulpStatus,
James Smarte8b62012007-08-02 11:10:09 -04004199 icmd->un.ulpWord[4], icmd->ulpTimeout);
James Smarted957682007-06-17 19:56:37 -05004200 phba->fc_stat.elsRcvDrop++;
4201}
4202
James Smart92d7f7b2007-06-17 19:56:38 -05004203static struct lpfc_vport *
4204lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
4205{
4206 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -04004207 unsigned long flags;
James Smart92d7f7b2007-06-17 19:56:38 -05004208
James Smart549e55c2007-08-02 11:09:51 -04004209 spin_lock_irqsave(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05004210 list_for_each_entry(vport, &phba->port_list, listentry) {
James Smart549e55c2007-08-02 11:09:51 -04004211 if (vport->vpi == vpi) {
4212 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05004213 return vport;
James Smart549e55c2007-08-02 11:09:51 -04004214 }
James Smart92d7f7b2007-06-17 19:56:38 -05004215 }
James Smart549e55c2007-08-02 11:09:51 -04004216 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05004217 return NULL;
4218}
James Smarted957682007-06-17 19:56:37 -05004219
4220void
4221lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
4222 struct lpfc_iocbq *elsiocb)
4223{
4224 struct lpfc_vport *vport = phba->pport;
James Smarted957682007-06-17 19:56:37 -05004225 IOCB_t *icmd = &elsiocb->iocb;
James Smarted957682007-06-17 19:56:37 -05004226 dma_addr_t paddr;
James Smart92d7f7b2007-06-17 19:56:38 -05004227 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
4228 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
James Smarted957682007-06-17 19:56:37 -05004229
James Smart92d7f7b2007-06-17 19:56:38 -05004230 elsiocb->context2 = NULL;
4231 elsiocb->context3 = NULL;
4232
4233 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
4234 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
4235 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
4236 (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) {
James Smarted957682007-06-17 19:56:37 -05004237 phba->fc_stat.NoRcvBuf++;
4238 /* Not enough posted buffers; Try posting more buffers */
James Smart92d7f7b2007-06-17 19:56:38 -05004239 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
James Smarted957682007-06-17 19:56:37 -05004240 lpfc_post_buffer(phba, pring, 0, 1);
4241 return;
4242 }
4243
James Smart92d7f7b2007-06-17 19:56:38 -05004244 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
4245 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
4246 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
4247 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
4248 vport = phba->pport;
4249 else {
4250 uint16_t vpi = icmd->unsli3.rcvsli3.vpi;
4251 vport = lpfc_find_vport_by_vpid(phba, vpi);
4252 }
4253 }
4254 /* If there are no BDEs associated
4255 * with this IOCB, there is nothing to do.
4256 */
James Smarted957682007-06-17 19:56:37 -05004257 if (icmd->ulpBdeCount == 0)
4258 return;
4259
James Smart92d7f7b2007-06-17 19:56:38 -05004260 /* type of ELS cmd is first 32bit word
4261 * in packet
4262 */
James Smarted957682007-06-17 19:56:37 -05004263 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05004264 elsiocb->context2 = bdeBuf1;
James Smarted957682007-06-17 19:56:37 -05004265 } else {
4266 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
4267 icmd->un.cont64[0].addrLow);
James Smart92d7f7b2007-06-17 19:56:38 -05004268 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
4269 paddr);
James Smarted957682007-06-17 19:56:37 -05004270 }
4271
James Smart92d7f7b2007-06-17 19:56:38 -05004272 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
4273 /*
4274 * The different unsolicited event handlers would tell us
4275 * if they are done with "mp" by setting context2 to NULL.
4276 */
James Smart329f9bc2007-04-25 09:53:01 -04004277 lpfc_nlp_put(elsiocb->context1);
4278 elsiocb->context1 = NULL;
dea31012005-04-17 16:05:31 -05004279 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05004280 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
4281 elsiocb->context2 = NULL;
dea31012005-04-17 16:05:31 -05004282 }
James Smarted957682007-06-17 19:56:37 -05004283
4284 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
James Smart92d7f7b2007-06-17 19:56:38 -05004285 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
James Smarted957682007-06-17 19:56:37 -05004286 icmd->ulpBdeCount == 2) {
James Smart92d7f7b2007-06-17 19:56:38 -05004287 elsiocb->context2 = bdeBuf2;
4288 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
James Smarted957682007-06-17 19:56:37 -05004289 /* free mp if we are done with it */
4290 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05004291 lpfc_in_buf_free(phba, elsiocb->context2);
4292 elsiocb->context2 = NULL;
James Smarted957682007-06-17 19:56:37 -05004293 }
dea31012005-04-17 16:05:31 -05004294 }
dea31012005-04-17 16:05:31 -05004295}
James Smart92d7f7b2007-06-17 19:56:38 -05004296
4297void
4298lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
4299{
4300 struct lpfc_nodelist *ndlp, *ndlp_fdmi;
4301
4302 ndlp = lpfc_findnode_did(vport, NameServer_DID);
4303 if (!ndlp) {
4304 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
4305 if (!ndlp) {
4306 if (phba->fc_topology == TOPOLOGY_LOOP) {
4307 lpfc_disc_start(vport);
4308 return;
4309 }
4310 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04004311 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4312 "0251 NameServer login: no memory\n");
James Smart92d7f7b2007-06-17 19:56:38 -05004313 return;
4314 }
4315 lpfc_nlp_init(vport, ndlp, NameServer_DID);
4316 ndlp->nlp_type |= NLP_FABRIC;
4317 }
4318
4319 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
4320
4321 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
4322 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04004323 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4324 "0252 Cannot issue NameServer login\n");
James Smart92d7f7b2007-06-17 19:56:38 -05004325 return;
4326 }
4327
James Smart3de2a652007-08-02 11:09:59 -04004328 if (vport->cfg_fdmi_on) {
James Smart92d7f7b2007-06-17 19:56:38 -05004329 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
4330 GFP_KERNEL);
4331 if (ndlp_fdmi) {
4332 lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
4333 ndlp_fdmi->nlp_type |= NLP_FABRIC;
4334 ndlp_fdmi->nlp_state =
4335 NLP_STE_PLOGI_ISSUE;
4336 lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID,
4337 0);
4338 }
4339 }
4340 return;
4341}
4342
4343static void
4344lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4345{
4346 struct lpfc_vport *vport = pmb->vport;
4347 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4348 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
4349 MAILBOX_t *mb = &pmb->mb;
4350
James Smart09372822008-01-11 01:52:54 -05004351 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004352 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05004353 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004354
4355 if (mb->mbxStatus) {
James Smarte8b62012007-08-02 11:10:09 -04004356 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
4357 "0915 Register VPI failed: 0x%x\n",
4358 mb->mbxStatus);
James Smart92d7f7b2007-06-17 19:56:38 -05004359
4360 switch (mb->mbxStatus) {
4361 case 0x11: /* unsupported feature */
4362 case 0x9603: /* max_vpi exceeded */
4363 /* giving up on vport registration */
4364 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4365 spin_lock_irq(shost->host_lock);
4366 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
4367 spin_unlock_irq(shost->host_lock);
4368 lpfc_can_disctmo(vport);
4369 break;
4370 default:
4371 /* Try to recover from this error */
4372 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -05004373 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004374 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05004375 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004376 lpfc_initial_fdisc(vport);
4377 break;
4378 }
4379
4380 } else {
4381 if (vport == phba->pport)
4382 lpfc_issue_fabric_reglogin(vport);
4383 else
4384 lpfc_do_scr_ns_plogi(phba, vport);
4385 }
James Smartfa4066b2008-01-11 01:53:27 -05004386
4387 /* Now, we decrement the ndlp reference count held for this
4388 * callback function
4389 */
4390 lpfc_nlp_put(ndlp);
4391
James Smart92d7f7b2007-06-17 19:56:38 -05004392 mempool_free(pmb, phba->mbox_mem_pool);
4393 return;
4394}
4395
Adrian Bunka6ababd2007-11-05 18:07:33 +01004396static void
James Smart92d7f7b2007-06-17 19:56:38 -05004397lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
4398 struct lpfc_nodelist *ndlp)
4399{
James Smart09372822008-01-11 01:52:54 -05004400 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05004401 LPFC_MBOXQ_t *mbox;
4402
4403 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4404 if (mbox) {
4405 lpfc_reg_vpi(phba, vport->vpi, vport->fc_myDID, mbox);
4406 mbox->vport = vport;
4407 mbox->context2 = lpfc_nlp_get(ndlp);
4408 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
James Smart0b727fe2007-10-27 13:37:25 -04004409 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart92d7f7b2007-06-17 19:56:38 -05004410 == MBX_NOT_FINISHED) {
James Smartfa4066b2008-01-11 01:53:27 -05004411 /* mailbox command not success, decrement ndlp
4412 * reference count for this command
4413 */
4414 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05004415 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05004416
James Smarte8b62012007-08-02 11:10:09 -04004417 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
4418 "0253 Register VPI: Can't send mbox\n");
James Smartfa4066b2008-01-11 01:53:27 -05004419 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05004420 }
4421 } else {
James Smarte8b62012007-08-02 11:10:09 -04004422 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
4423 "0254 Register VPI: no memory\n");
James Smartfa4066b2008-01-11 01:53:27 -05004424 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05004425 }
James Smartfa4066b2008-01-11 01:53:27 -05004426 return;
4427
4428mbox_err_exit:
4429 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4430 spin_lock_irq(shost->host_lock);
4431 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
4432 spin_unlock_irq(shost->host_lock);
4433 return;
James Smart92d7f7b2007-06-17 19:56:38 -05004434}
4435
4436static void
4437lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4438 struct lpfc_iocbq *rspiocb)
4439{
4440 struct lpfc_vport *vport = cmdiocb->vport;
4441 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4442 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
4443 struct lpfc_nodelist *np;
4444 struct lpfc_nodelist *next_np;
4445 IOCB_t *irsp = &rspiocb->iocb;
4446 struct lpfc_iocbq *piocb;
4447
James Smarte8b62012007-08-02 11:10:09 -04004448 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4449 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
4450 irsp->ulpStatus, irsp->un.ulpWord[4],
4451 vport->fc_prevDID);
James Smart92d7f7b2007-06-17 19:56:38 -05004452 /* Since all FDISCs are being single threaded, we
4453 * must reset the discovery timer for ALL vports
4454 * waiting to send FDISC when one completes.
4455 */
4456 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
4457 lpfc_set_disctmo(piocb->vport);
4458 }
4459
James Smart858c9f62007-06-17 19:56:39 -05004460 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4461 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
4462 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
4463
James Smart92d7f7b2007-06-17 19:56:38 -05004464 if (irsp->ulpStatus) {
4465 /* Check for retry */
4466 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
4467 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05004468 /* FDISC failed */
James Smarte8b62012007-08-02 11:10:09 -04004469 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4470 "0124 FDISC failed. (%d/%d)\n",
4471 irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smart92d7f7b2007-06-17 19:56:38 -05004472 if (vport->fc_vport->vport_state == FC_VPORT_INITIALIZING)
4473 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4474
4475 lpfc_nlp_put(ndlp);
4476 /* giving up on FDISC. Cancel discovery timer */
4477 lpfc_can_disctmo(vport);
4478 } else {
4479 spin_lock_irq(shost->host_lock);
4480 vport->fc_flag |= FC_FABRIC;
4481 if (vport->phba->fc_topology == TOPOLOGY_LOOP)
4482 vport->fc_flag |= FC_PUBLIC_LOOP;
4483 spin_unlock_irq(shost->host_lock);
4484
4485 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
4486 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
4487 if ((vport->fc_prevDID != vport->fc_myDID) &&
4488 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
4489 /* If our NportID changed, we need to ensure all
4490 * remaining NPORTs get unreg_login'ed so we can
4491 * issue unreg_vpi.
4492 */
4493 list_for_each_entry_safe(np, next_np,
4494 &vport->fc_nodes, nlp_listp) {
4495 if (np->nlp_state != NLP_STE_NPR_NODE
4496 || !(np->nlp_flag & NLP_NPR_ADISC))
4497 continue;
4498 spin_lock_irq(shost->host_lock);
4499 np->nlp_flag &= ~NLP_NPR_ADISC;
4500 spin_unlock_irq(shost->host_lock);
4501 lpfc_unreg_rpi(vport, np);
4502 }
4503 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -05004504 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004505 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05004506 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004507 }
4508
4509 if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
4510 lpfc_register_new_vport(phba, vport, ndlp);
4511 else
4512 lpfc_do_scr_ns_plogi(phba, vport);
4513
James Smartfa4066b2008-01-11 01:53:27 -05004514 /* Unconditionaly kick off releasing fabric node for vports */
4515 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05004516 }
4517
4518out:
4519 lpfc_els_free_iocb(phba, cmdiocb);
4520}
4521
Adrian Bunka6ababd2007-11-05 18:07:33 +01004522static int
James Smart92d7f7b2007-06-17 19:56:38 -05004523lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4524 uint8_t retry)
4525{
4526 struct lpfc_hba *phba = vport->phba;
4527 IOCB_t *icmd;
4528 struct lpfc_iocbq *elsiocb;
4529 struct serv_parm *sp;
4530 uint8_t *pcmd;
4531 uint16_t cmdsize;
4532 int did = ndlp->nlp_DID;
4533 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05004534
4535 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
4536 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
4537 ELS_CMD_FDISC);
4538 if (!elsiocb) {
James Smart92d7f7b2007-06-17 19:56:38 -05004539 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04004540 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4541 "0255 Issue FDISC: no IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05004542 return 1;
4543 }
4544
4545 icmd = &elsiocb->iocb;
4546 icmd->un.elsreq64.myID = 0;
4547 icmd->un.elsreq64.fl = 1;
4548
4549 /* For FDISC, Let FDISC rsp set the NPortID for this VPI */
4550 icmd->ulpCt_h = 1;
4551 icmd->ulpCt_l = 0;
4552
4553 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4554 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
4555 pcmd += sizeof(uint32_t); /* CSP Word 1 */
4556 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
4557 sp = (struct serv_parm *) pcmd;
4558 /* Setup CSPs accordingly for Fabric */
4559 sp->cmn.e_d_tov = 0;
4560 sp->cmn.w2.r_a_tov = 0;
4561 sp->cls1.classValid = 0;
4562 sp->cls2.seqDelivery = 1;
4563 sp->cls3.seqDelivery = 1;
4564
4565 pcmd += sizeof(uint32_t); /* CSP Word 2 */
4566 pcmd += sizeof(uint32_t); /* CSP Word 3 */
4567 pcmd += sizeof(uint32_t); /* CSP Word 4 */
4568 pcmd += sizeof(uint32_t); /* Port Name */
4569 memcpy(pcmd, &vport->fc_portname, 8);
4570 pcmd += sizeof(uint32_t); /* Node Name */
4571 pcmd += sizeof(uint32_t); /* Node Name */
4572 memcpy(pcmd, &vport->fc_nodename, 8);
4573
4574 lpfc_set_disctmo(vport);
4575
4576 phba->fc_stat.elsXmitFDISC++;
4577 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
4578
James Smart858c9f62007-06-17 19:56:39 -05004579 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4580 "Issue FDISC: did:x%x",
4581 did, 0, 0);
4582
James Smart92d7f7b2007-06-17 19:56:38 -05004583 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
4584 if (rc == IOCB_ERROR) {
4585 lpfc_els_free_iocb(phba, elsiocb);
James Smart92d7f7b2007-06-17 19:56:38 -05004586 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04004587 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4588 "0256 Issue FDISC: Cannot send IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05004589 return 1;
4590 }
4591 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
4592 vport->port_state = LPFC_FDISC;
4593 return 0;
4594}
4595
4596static void
4597lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4598 struct lpfc_iocbq *rspiocb)
4599{
4600 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05004601 IOCB_t *irsp;
4602
4603 irsp = &rspiocb->iocb;
4604 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4605 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
4606 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
James Smart92d7f7b2007-06-17 19:56:38 -05004607
4608 lpfc_els_free_iocb(phba, cmdiocb);
4609 vport->unreg_vpi_cmpl = VPORT_ERROR;
4610}
4611
4612int
4613lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4614{
4615 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4616 struct lpfc_hba *phba = vport->phba;
4617 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
4618 IOCB_t *icmd;
4619 struct lpfc_iocbq *elsiocb;
4620 uint8_t *pcmd;
4621 uint16_t cmdsize;
4622
4623 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
4624 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
4625 ELS_CMD_LOGO);
4626 if (!elsiocb)
4627 return 1;
4628
4629 icmd = &elsiocb->iocb;
4630 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4631 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
4632 pcmd += sizeof(uint32_t);
4633
4634 /* Fill in LOGO payload */
4635 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
4636 pcmd += sizeof(uint32_t);
4637 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
4638
James Smart858c9f62007-06-17 19:56:39 -05004639 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4640 "Issue LOGO npiv did:x%x flg:x%x",
4641 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4642
James Smart92d7f7b2007-06-17 19:56:38 -05004643 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
4644 spin_lock_irq(shost->host_lock);
4645 ndlp->nlp_flag |= NLP_LOGO_SND;
4646 spin_unlock_irq(shost->host_lock);
4647 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
4648 spin_lock_irq(shost->host_lock);
4649 ndlp->nlp_flag &= ~NLP_LOGO_SND;
4650 spin_unlock_irq(shost->host_lock);
4651 lpfc_els_free_iocb(phba, elsiocb);
4652 return 1;
4653 }
4654 return 0;
4655}
4656
4657void
4658lpfc_fabric_block_timeout(unsigned long ptr)
4659{
4660 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
4661 unsigned long iflags;
4662 uint32_t tmo_posted;
4663 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
4664 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
4665 if (!tmo_posted)
4666 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
4667 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
4668
4669 if (!tmo_posted) {
4670 spin_lock_irqsave(&phba->hbalock, iflags);
4671 if (phba->work_wait)
4672 lpfc_worker_wake_up(phba);
4673 spin_unlock_irqrestore(&phba->hbalock, iflags);
4674 }
4675}
4676
4677static void
4678lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
4679{
4680 struct lpfc_iocbq *iocb;
4681 unsigned long iflags;
4682 int ret;
4683 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
4684 IOCB_t *cmd;
4685
4686repeat:
4687 iocb = NULL;
4688 spin_lock_irqsave(&phba->hbalock, iflags);
4689 /* Post any pending iocb to the SLI layer */
4690 if (atomic_read(&phba->fabric_iocb_count) == 0) {
4691 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
4692 list);
4693 if (iocb)
4694 atomic_inc(&phba->fabric_iocb_count);
4695 }
4696 spin_unlock_irqrestore(&phba->hbalock, iflags);
4697 if (iocb) {
4698 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
4699 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
4700 iocb->iocb_flag |= LPFC_IO_FABRIC;
4701
James Smart858c9f62007-06-17 19:56:39 -05004702 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
4703 "Fabric sched1: ste:x%x",
4704 iocb->vport->port_state, 0, 0);
4705
James Smart92d7f7b2007-06-17 19:56:38 -05004706 ret = lpfc_sli_issue_iocb(phba, pring, iocb, 0);
4707
4708 if (ret == IOCB_ERROR) {
4709 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
4710 iocb->fabric_iocb_cmpl = NULL;
4711 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
4712 cmd = &iocb->iocb;
4713 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
4714 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
4715 iocb->iocb_cmpl(phba, iocb, iocb);
4716
4717 atomic_dec(&phba->fabric_iocb_count);
4718 goto repeat;
4719 }
4720 }
4721
4722 return;
4723}
4724
4725void
4726lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
4727{
4728 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
4729
4730 lpfc_resume_fabric_iocbs(phba);
4731 return;
4732}
4733
4734static void
4735lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
4736{
4737 int blocked;
4738
4739 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
4740 /* Start a timer to unblock fabric
4741 * iocbs after 100ms
4742 */
4743 if (!blocked)
4744 mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 );
4745
4746 return;
4747}
4748
4749static void
4750lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4751 struct lpfc_iocbq *rspiocb)
4752{
4753 struct ls_rjt stat;
4754
4755 if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
4756 BUG();
4757
4758 switch (rspiocb->iocb.ulpStatus) {
4759 case IOSTAT_NPORT_RJT:
4760 case IOSTAT_FABRIC_RJT:
4761 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
4762 lpfc_block_fabric_iocbs(phba);
4763 }
4764 break;
4765
4766 case IOSTAT_NPORT_BSY:
4767 case IOSTAT_FABRIC_BSY:
4768 lpfc_block_fabric_iocbs(phba);
4769 break;
4770
4771 case IOSTAT_LS_RJT:
4772 stat.un.lsRjtError =
4773 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
4774 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
4775 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
4776 lpfc_block_fabric_iocbs(phba);
4777 break;
4778 }
4779
4780 if (atomic_read(&phba->fabric_iocb_count) == 0)
4781 BUG();
4782
4783 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
4784 cmdiocb->fabric_iocb_cmpl = NULL;
4785 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
4786 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
4787
4788 atomic_dec(&phba->fabric_iocb_count);
4789 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
4790 /* Post any pending iocbs to HBA */
4791 lpfc_resume_fabric_iocbs(phba);
4792 }
4793}
4794
Adrian Bunka6ababd2007-11-05 18:07:33 +01004795static int
James Smart92d7f7b2007-06-17 19:56:38 -05004796lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
4797{
4798 unsigned long iflags;
4799 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
4800 int ready;
4801 int ret;
4802
4803 if (atomic_read(&phba->fabric_iocb_count) > 1)
4804 BUG();
4805
4806 spin_lock_irqsave(&phba->hbalock, iflags);
4807 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
4808 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
4809
4810 spin_unlock_irqrestore(&phba->hbalock, iflags);
4811 if (ready) {
4812 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
4813 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
4814 iocb->iocb_flag |= LPFC_IO_FABRIC;
4815
James Smart858c9f62007-06-17 19:56:39 -05004816 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
4817 "Fabric sched2: ste:x%x",
4818 iocb->vport->port_state, 0, 0);
4819
James Smart92d7f7b2007-06-17 19:56:38 -05004820 atomic_inc(&phba->fabric_iocb_count);
4821 ret = lpfc_sli_issue_iocb(phba, pring, iocb, 0);
4822
4823 if (ret == IOCB_ERROR) {
4824 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
4825 iocb->fabric_iocb_cmpl = NULL;
4826 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
4827 atomic_dec(&phba->fabric_iocb_count);
4828 }
4829 } else {
4830 spin_lock_irqsave(&phba->hbalock, iflags);
4831 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
4832 spin_unlock_irqrestore(&phba->hbalock, iflags);
4833 ret = IOCB_SUCCESS;
4834 }
4835 return ret;
4836}
4837
4838
Adrian Bunka6ababd2007-11-05 18:07:33 +01004839static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
James Smart92d7f7b2007-06-17 19:56:38 -05004840{
4841 LIST_HEAD(completions);
4842 struct lpfc_hba *phba = vport->phba;
4843 struct lpfc_iocbq *tmp_iocb, *piocb;
4844 IOCB_t *cmd;
4845
4846 spin_lock_irq(&phba->hbalock);
4847 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
4848 list) {
4849
4850 if (piocb->vport != vport)
4851 continue;
4852
4853 list_move_tail(&piocb->list, &completions);
4854 }
4855 spin_unlock_irq(&phba->hbalock);
4856
4857 while (!list_empty(&completions)) {
4858 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
4859 list_del_init(&piocb->list);
4860
4861 cmd = &piocb->iocb;
4862 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
4863 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
4864 (piocb->iocb_cmpl) (phba, piocb, piocb);
4865 }
4866}
4867
4868void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
4869{
4870 LIST_HEAD(completions);
4871 struct lpfc_hba *phba = ndlp->vport->phba;
4872 struct lpfc_iocbq *tmp_iocb, *piocb;
4873 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
4874 IOCB_t *cmd;
4875
4876 spin_lock_irq(&phba->hbalock);
4877 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
4878 list) {
4879 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
4880
4881 list_move_tail(&piocb->list, &completions);
4882 }
4883 }
4884 spin_unlock_irq(&phba->hbalock);
4885
4886 while (!list_empty(&completions)) {
4887 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
4888 list_del_init(&piocb->list);
4889
4890 cmd = &piocb->iocb;
4891 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
4892 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
4893 (piocb->iocb_cmpl) (phba, piocb, piocb);
4894 }
4895}
4896
4897void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
4898{
4899 LIST_HEAD(completions);
4900 struct lpfc_iocbq *piocb;
4901 IOCB_t *cmd;
4902
4903 spin_lock_irq(&phba->hbalock);
4904 list_splice_init(&phba->fabric_iocb_list, &completions);
4905 spin_unlock_irq(&phba->hbalock);
4906
4907 while (!list_empty(&completions)) {
4908 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
4909 list_del_init(&piocb->list);
4910
4911 cmd = &piocb->iocb;
4912 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
4913 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
4914 (piocb->iocb_cmpl) (phba, piocb, piocb);
4915 }
4916}
4917
4918
Adrian Bunka6ababd2007-11-05 18:07:33 +01004919#if 0
James Smart92d7f7b2007-06-17 19:56:38 -05004920void lpfc_fabric_abort_flogi(struct lpfc_hba *phba)
4921{
4922 LIST_HEAD(completions);
4923 struct lpfc_iocbq *tmp_iocb, *piocb;
4924 IOCB_t *cmd;
4925 struct lpfc_nodelist *ndlp;
4926
4927 spin_lock_irq(&phba->hbalock);
4928 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
4929 list) {
4930
4931 cmd = &piocb->iocb;
4932 ndlp = (struct lpfc_nodelist *) piocb->context1;
4933 if (cmd->ulpCommand == CMD_ELS_REQUEST64_CR &&
4934 ndlp != NULL &&
4935 ndlp->nlp_DID == Fabric_DID)
4936 list_move_tail(&piocb->list, &completions);
4937 }
4938 spin_unlock_irq(&phba->hbalock);
4939
4940 while (!list_empty(&completions)) {
4941 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
4942 list_del_init(&piocb->list);
4943
4944 cmd = &piocb->iocb;
4945 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
4946 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
4947 (piocb->iocb_cmpl) (phba, piocb, piocb);
4948 }
4949}
Adrian Bunka6ababd2007-11-05 18:07:33 +01004950#endif /* 0 */
James Smart92d7f7b2007-06-17 19:56:38 -05004951
4952