blob: 60afc8028ff5a4f39e773667f3034f2bd23f459a [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 Smarte47c9092008-02-08 18:49:26 -05004 * Copyright (C) 2004-2008 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;
James Smarte47c9092008-02-08 18:49:26 -0500116
dea31012005-04-17 16:05:31 -0500117 icmd = &elsiocb->iocb;
118
119 /* fill in BDEs for command */
120 /* Allocate buffer for command payload */
James Smart98c9ea52007-10-27 13:37:33 -0400121 pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
122 if (pcmd)
123 pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500124 if (!pcmd || !pcmd->virt)
125 goto els_iocb_free_pcmb_exit;
dea31012005-04-17 16:05:31 -0500126
127 INIT_LIST_HEAD(&pcmd->list);
128
129 /* Allocate buffer for response payload */
130 if (expectRsp) {
James Smart92d7f7b2007-06-17 19:56:38 -0500131 prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -0500132 if (prsp)
133 prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
134 &prsp->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500135 if (!prsp || !prsp->virt)
136 goto els_iocb_free_prsp_exit;
dea31012005-04-17 16:05:31 -0500137 INIT_LIST_HEAD(&prsp->list);
James Smarte47c9092008-02-08 18:49:26 -0500138 } else
dea31012005-04-17 16:05:31 -0500139 prsp = NULL;
dea31012005-04-17 16:05:31 -0500140
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 Smarte47c9092008-02-08 18:49:26 -0500249 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -0400250 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;
James Smarte47c9092008-02-08 18:49:26 -0500285 /* increment the reference count on ndlp to hold reference
286 * for the callback routine.
287 */
James Smart92d7f7b2007-06-17 19:56:38 -0500288 mbox->context2 = lpfc_nlp_get(ndlp);
289
James Smart0b727fe2007-10-27 13:37:25 -0400290 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart98c9ea52007-10-27 13:37:33 -0400291 if (rc == MBX_NOT_FINISHED) {
292 err = 6;
James Smart92d7f7b2007-06-17 19:56:38 -0500293 goto fail_issue_reg_login;
James Smart98c9ea52007-10-27 13:37:33 -0400294 }
James Smart92d7f7b2007-06-17 19:56:38 -0500295
296 return 0;
297
298fail_issue_reg_login:
James Smarte47c9092008-02-08 18:49:26 -0500299 /* decrement the reference count on ndlp just incremented
300 * for the failed mbox command.
301 */
James Smart92d7f7b2007-06-17 19:56:38 -0500302 lpfc_nlp_put(ndlp);
303 mp = (struct lpfc_dmabuf *) mbox->context1;
304 lpfc_mbuf_free(phba, mp->virt, mp->phys);
305 kfree(mp);
306fail_free_mbox:
307 mempool_free(mbox, phba->mbox_mem_pool);
308
309fail:
310 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -0400311 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smart98c9ea52007-10-27 13:37:33 -0400312 "0249 Cannot issue Register Fabric login: Err %d\n", err);
James Smart92d7f7b2007-06-17 19:56:38 -0500313 return -ENXIO;
314}
315
316static int
James Smart2e0fef82007-06-17 19:56:36 -0500317lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
318 struct serv_parm *sp, IOCB_t *irsp)
dea31012005-04-17 16:05:31 -0500319{
James Smart2e0fef82007-06-17 19:56:36 -0500320 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
321 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -0500322 struct lpfc_nodelist *np;
323 struct lpfc_nodelist *next_np;
dea31012005-04-17 16:05:31 -0500324
James Smart2e0fef82007-06-17 19:56:36 -0500325 spin_lock_irq(shost->host_lock);
326 vport->fc_flag |= FC_FABRIC;
327 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500328
329 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
330 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
331 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
332
333 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
334
335 if (phba->fc_topology == TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500336 spin_lock_irq(shost->host_lock);
337 vport->fc_flag |= FC_PUBLIC_LOOP;
338 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500339 } else {
340 /*
341 * If we are a N-port connected to a Fabric, fixup sparam's so
342 * logins to devices on remote loops work.
343 */
James Smart2e0fef82007-06-17 19:56:36 -0500344 vport->fc_sparam.cmn.altBbCredit = 1;
dea31012005-04-17 16:05:31 -0500345 }
346
James Smart2e0fef82007-06-17 19:56:36 -0500347 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
dea31012005-04-17 16:05:31 -0500348 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
James Smart92d7f7b2007-06-17 19:56:38 -0500349 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500350 ndlp->nlp_class_sup = 0;
351 if (sp->cls1.classValid)
352 ndlp->nlp_class_sup |= FC_COS_CLASS1;
353 if (sp->cls2.classValid)
354 ndlp->nlp_class_sup |= FC_COS_CLASS2;
355 if (sp->cls3.classValid)
356 ndlp->nlp_class_sup |= FC_COS_CLASS3;
357 if (sp->cls4.classValid)
358 ndlp->nlp_class_sup |= FC_COS_CLASS4;
359 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
360 sp->cmn.bbRcvSizeLsb;
361 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
362
James Smart92d7f7b2007-06-17 19:56:38 -0500363 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
364 if (sp->cmn.response_multiple_NPort) {
James Smarte8b62012007-08-02 11:10:09 -0400365 lpfc_printf_vlog(vport, KERN_WARNING,
366 LOG_ELS | LOG_VPORT,
367 "1816 FLOGI NPIV supported, "
368 "response data 0x%x\n",
369 sp->cmn.response_multiple_NPort);
James Smart92d7f7b2007-06-17 19:56:38 -0500370 phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
James Smart92d7f7b2007-06-17 19:56:38 -0500371 } else {
372 /* Because we asked f/w for NPIV it still expects us
James Smarte8b62012007-08-02 11:10:09 -0400373 to call reg_vnpid atleast for the physcial host */
374 lpfc_printf_vlog(vport, KERN_WARNING,
375 LOG_ELS | LOG_VPORT,
376 "1817 Fabric does not support NPIV "
377 "- configuring single port mode.\n");
James Smart92d7f7b2007-06-17 19:56:38 -0500378 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
379 }
380 }
381
382 if ((vport->fc_prevDID != vport->fc_myDID) &&
383 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
384
385 /* If our NportID changed, we need to ensure all
386 * remaining NPORTs get unreg_login'ed.
387 */
388 list_for_each_entry_safe(np, next_np,
389 &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -0500390 if (!NLP_CHK_NODE_ACT(ndlp))
391 continue;
James Smart92d7f7b2007-06-17 19:56:38 -0500392 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
393 !(np->nlp_flag & NLP_NPR_ADISC))
394 continue;
395 spin_lock_irq(shost->host_lock);
396 np->nlp_flag &= ~NLP_NPR_ADISC;
397 spin_unlock_irq(shost->host_lock);
398 lpfc_unreg_rpi(vport, np);
399 }
400 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
401 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -0500402 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500403 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -0500404 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500405 }
406 }
407
James Smart92d7f7b2007-06-17 19:56:38 -0500408 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -0500409
James Smart92d7f7b2007-06-17 19:56:38 -0500410 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
411 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) {
412 lpfc_register_new_vport(phba, vport, ndlp);
413 return 0;
414 }
415 lpfc_issue_fabric_reglogin(vport);
dea31012005-04-17 16:05:31 -0500416 return 0;
dea31012005-04-17 16:05:31 -0500417}
418
419/*
420 * We FLOGIed into an NPort, initiate pt2pt protocol
421 */
422static int
James Smart2e0fef82007-06-17 19:56:36 -0500423lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
424 struct serv_parm *sp)
dea31012005-04-17 16:05:31 -0500425{
James Smart2e0fef82007-06-17 19:56:36 -0500426 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
427 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500428 LPFC_MBOXQ_t *mbox;
429 int rc;
430
James Smart2e0fef82007-06-17 19:56:36 -0500431 spin_lock_irq(shost->host_lock);
432 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
433 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500434
435 phba->fc_edtov = FF_DEF_EDTOV;
436 phba->fc_ratov = FF_DEF_RATOV;
James Smart2e0fef82007-06-17 19:56:36 -0500437 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -0500438 sizeof(vport->fc_portname));
dea31012005-04-17 16:05:31 -0500439 if (rc >= 0) {
440 /* This side will initiate the PLOGI */
James Smart2e0fef82007-06-17 19:56:36 -0500441 spin_lock_irq(shost->host_lock);
442 vport->fc_flag |= FC_PT2PT_PLOGI;
443 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500444
445 /*
446 * N_Port ID cannot be 0, set our to LocalID the other
447 * side will be RemoteID.
448 */
449
450 /* not equal */
451 if (rc)
James Smart2e0fef82007-06-17 19:56:36 -0500452 vport->fc_myDID = PT2PT_LocalID;
dea31012005-04-17 16:05:31 -0500453
454 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
455 if (!mbox)
456 goto fail;
457
458 lpfc_config_link(phba, mbox);
459
460 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -0500461 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -0400462 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -0500463 if (rc == MBX_NOT_FINISHED) {
464 mempool_free(mbox, phba->mbox_mem_pool);
465 goto fail;
466 }
James Smarte47c9092008-02-08 18:49:26 -0500467 /* Decrement ndlp reference count indicating that ndlp can be
468 * safely released when other references to it are done.
469 */
James Smart329f9bc2007-04-25 09:53:01 -0400470 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500471
James Smart2e0fef82007-06-17 19:56:36 -0500472 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
dea31012005-04-17 16:05:31 -0500473 if (!ndlp) {
474 /*
475 * Cannot find existing Fabric ndlp, so allocate a
476 * new one
477 */
478 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
479 if (!ndlp)
480 goto fail;
James Smart2e0fef82007-06-17 19:56:36 -0500481 lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID);
James Smarte47c9092008-02-08 18:49:26 -0500482 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
483 ndlp = lpfc_enable_node(vport, ndlp,
484 NLP_STE_UNUSED_NODE);
485 if(!ndlp)
486 goto fail;
dea31012005-04-17 16:05:31 -0500487 }
488
489 memcpy(&ndlp->nlp_portname, &sp->portName,
James Smart2e0fef82007-06-17 19:56:36 -0500490 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500491 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
James Smart2e0fef82007-06-17 19:56:36 -0500492 sizeof(struct lpfc_name));
James Smarte47c9092008-02-08 18:49:26 -0500493 /* Set state will put ndlp onto node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -0500494 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
495 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500496 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500497 spin_unlock_irq(shost->host_lock);
James Smarte47c9092008-02-08 18:49:26 -0500498 } else
499 /* This side will wait for the PLOGI, decrement ndlp reference
500 * count indicating that ndlp can be released when other
501 * references to it are done.
502 */
James Smart329f9bc2007-04-25 09:53:01 -0400503 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500504
James Smart09372822008-01-11 01:52:54 -0500505 /* If we are pt2pt with another NPort, force NPIV off! */
506 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
507
James Smart2e0fef82007-06-17 19:56:36 -0500508 spin_lock_irq(shost->host_lock);
509 vport->fc_flag |= FC_PT2PT;
510 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500511
512 /* Start discovery - this should just do CLEAR_LA */
James Smart2e0fef82007-06-17 19:56:36 -0500513 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -0500514 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500515fail:
dea31012005-04-17 16:05:31 -0500516 return -ENXIO;
517}
518
519static void
James Smart329f9bc2007-04-25 09:53:01 -0400520lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
521 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500522{
James Smart2e0fef82007-06-17 19:56:36 -0500523 struct lpfc_vport *vport = cmdiocb->vport;
524 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500525 IOCB_t *irsp = &rspiocb->iocb;
526 struct lpfc_nodelist *ndlp = cmdiocb->context1;
527 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
528 struct serv_parm *sp;
529 int rc;
530
531 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500532 if (lpfc_els_chk_latt(vport)) {
James Smartfa4066b2008-01-11 01:53:27 -0500533 /* One additional decrement on node reference count to
534 * trigger the release of the node
535 */
James Smart329f9bc2007-04-25 09:53:01 -0400536 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500537 goto out;
538 }
539
James Smart858c9f62007-06-17 19:56:39 -0500540 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
541 "FLOGI cmpl: status:x%x/x%x state:x%x",
542 irsp->ulpStatus, irsp->un.ulpWord[4],
543 vport->port_state);
544
dea31012005-04-17 16:05:31 -0500545 if (irsp->ulpStatus) {
546 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -0500547 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -0500548 goto out;
James Smart2e0fef82007-06-17 19:56:36 -0500549
dea31012005-04-17 16:05:31 -0500550 /* FLOGI failed, so there is no fabric */
James Smart2e0fef82007-06-17 19:56:36 -0500551 spin_lock_irq(shost->host_lock);
552 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
553 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500554
James Smart329f9bc2007-04-25 09:53:01 -0400555 /* If private loop, then allow max outstanding els to be
dea31012005-04-17 16:05:31 -0500556 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
557 * alpa map would take too long otherwise.
558 */
559 if (phba->alpa_map[0] == 0) {
James Smart3de2a652007-08-02 11:09:59 -0400560 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
dea31012005-04-17 16:05:31 -0500561 }
562
563 /* FLOGI failure */
James Smarte8b62012007-08-02 11:10:09 -0400564 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
565 "0100 FLOGI failure Data: x%x x%x "
566 "x%x\n",
567 irsp->ulpStatus, irsp->un.ulpWord[4],
568 irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -0500569 goto flogifail;
570 }
571
572 /*
573 * The FLogI succeeded. Sync the data for the CPU before
574 * accessing it.
575 */
576 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
577
578 sp = prsp->virt + sizeof(uint32_t);
579
580 /* FLOGI completes successfully */
James Smarte8b62012007-08-02 11:10:09 -0400581 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
582 "0101 FLOGI completes sucessfully "
583 "Data: x%x x%x x%x x%x\n",
584 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
585 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution);
dea31012005-04-17 16:05:31 -0500586
James Smart2e0fef82007-06-17 19:56:36 -0500587 if (vport->port_state == LPFC_FLOGI) {
dea31012005-04-17 16:05:31 -0500588 /*
589 * If Common Service Parameters indicate Nport
590 * we are point to point, if Fport we are Fabric.
591 */
592 if (sp->cmn.fPort)
James Smart2e0fef82007-06-17 19:56:36 -0500593 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
dea31012005-04-17 16:05:31 -0500594 else
James Smart2e0fef82007-06-17 19:56:36 -0500595 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
dea31012005-04-17 16:05:31 -0500596
597 if (!rc)
598 goto out;
599 }
600
601flogifail:
James Smart329f9bc2007-04-25 09:53:01 -0400602 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500603
James Smart858c9f62007-06-17 19:56:39 -0500604 if (!lpfc_error_lost_link(irsp)) {
dea31012005-04-17 16:05:31 -0500605 /* FLOGI failed, so just use loop map to make discovery list */
James Smart2e0fef82007-06-17 19:56:36 -0500606 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -0500607
608 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500609 lpfc_disc_start(vport);
James Smart87af33f2007-10-27 13:37:43 -0400610 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
611 ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) &&
612 (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) &&
613 (phba->link_state != LPFC_CLEAR_LA)) {
614 /* If FLOGI failed enable link interrupt. */
615 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -0500616 }
dea31012005-04-17 16:05:31 -0500617out:
618 lpfc_els_free_iocb(phba, cmdiocb);
619}
620
621static int
James Smart2e0fef82007-06-17 19:56:36 -0500622lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -0500623 uint8_t retry)
624{
James Smart2e0fef82007-06-17 19:56:36 -0500625 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500626 struct serv_parm *sp;
627 IOCB_t *icmd;
628 struct lpfc_iocbq *elsiocb;
629 struct lpfc_sli_ring *pring;
630 uint8_t *pcmd;
631 uint16_t cmdsize;
632 uint32_t tmo;
633 int rc;
634
635 pring = &phba->sli.ring[LPFC_ELS_RING];
636
James Smart92d7f7b2007-06-17 19:56:38 -0500637 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart2e0fef82007-06-17 19:56:36 -0500638 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
639 ndlp->nlp_DID, ELS_CMD_FLOGI);
James Smart92d7f7b2007-06-17 19:56:38 -0500640
James Smart488d1462006-03-07 15:02:37 -0500641 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500642 return 1;
dea31012005-04-17 16:05:31 -0500643
644 icmd = &elsiocb->iocb;
645 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
646
647 /* For FLOGI request, remainder of payload is service parameters */
648 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -0500649 pcmd += sizeof(uint32_t);
650 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -0500651 sp = (struct serv_parm *) pcmd;
652
653 /* Setup CSPs accordingly for Fabric */
654 sp->cmn.e_d_tov = 0;
655 sp->cmn.w2.r_a_tov = 0;
656 sp->cls1.classValid = 0;
657 sp->cls2.seqDelivery = 1;
658 sp->cls3.seqDelivery = 1;
659 if (sp->cmn.fcphLow < FC_PH3)
660 sp->cmn.fcphLow = FC_PH3;
661 if (sp->cmn.fcphHigh < FC_PH3)
662 sp->cmn.fcphHigh = FC_PH3;
663
James Smart92d7f7b2007-06-17 19:56:38 -0500664 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
665 sp->cmn.request_multiple_Nport = 1;
666
667 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
668 icmd->ulpCt_h = 1;
669 icmd->ulpCt_l = 0;
670 }
671
James Smart858c9f62007-06-17 19:56:39 -0500672 if (phba->fc_topology != TOPOLOGY_LOOP) {
673 icmd->un.elsreq64.myID = 0;
674 icmd->un.elsreq64.fl = 1;
675 }
676
dea31012005-04-17 16:05:31 -0500677 tmo = phba->fc_ratov;
678 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
James Smart2e0fef82007-06-17 19:56:36 -0500679 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -0500680 phba->fc_ratov = tmo;
681
682 phba->fc_stat.elsXmitFLOGI++;
683 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
James Smart858c9f62007-06-17 19:56:39 -0500684
685 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
686 "Issue FLOGI: opt:x%x",
687 phba->sli3_options, 0, 0);
688
James Smart92d7f7b2007-06-17 19:56:38 -0500689 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
dea31012005-04-17 16:05:31 -0500690 if (rc == IOCB_ERROR) {
691 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500692 return 1;
dea31012005-04-17 16:05:31 -0500693 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500694 return 0;
dea31012005-04-17 16:05:31 -0500695}
696
697int
James Smart2e0fef82007-06-17 19:56:36 -0500698lpfc_els_abort_flogi(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500699{
700 struct lpfc_sli_ring *pring;
701 struct lpfc_iocbq *iocb, *next_iocb;
702 struct lpfc_nodelist *ndlp;
703 IOCB_t *icmd;
704
705 /* Abort outstanding I/O on NPort <nlp_DID> */
706 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -0400707 "0201 Abort outstanding I/O on NPort x%x\n",
708 Fabric_DID);
dea31012005-04-17 16:05:31 -0500709
710 pring = &phba->sli.ring[LPFC_ELS_RING];
711
712 /*
713 * Check the txcmplq for an iocb that matches the nport the driver is
714 * searching for.
715 */
James Smart2e0fef82007-06-17 19:56:36 -0500716 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500717 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
718 icmd = &iocb->iocb;
James Smart2e0fef82007-06-17 19:56:36 -0500719 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR &&
720 icmd->un.elsreq64.bdl.ulpIoTag32) {
dea31012005-04-17 16:05:31 -0500721 ndlp = (struct lpfc_nodelist *)(iocb->context1);
James Smart92d7f7b2007-06-17 19:56:38 -0500722 if (ndlp && (ndlp->nlp_DID == Fabric_DID)) {
James Smart07951072007-04-25 09:51:38 -0400723 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
James Smart92d7f7b2007-06-17 19:56:38 -0500724 }
dea31012005-04-17 16:05:31 -0500725 }
726 }
James Smart2e0fef82007-06-17 19:56:36 -0500727 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500728
729 return 0;
730}
731
732int
James Smart2e0fef82007-06-17 19:56:36 -0500733lpfc_initial_flogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -0500734{
James Smart2e0fef82007-06-17 19:56:36 -0500735 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500736 struct lpfc_nodelist *ndlp;
737
James Smart98c9ea52007-10-27 13:37:33 -0400738 vport->port_state = LPFC_FLOGI;
739 lpfc_set_disctmo(vport);
740
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500741 /* First look for the Fabric ndlp */
James Smart2e0fef82007-06-17 19:56:36 -0500742 ndlp = lpfc_findnode_did(vport, Fabric_DID);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500743 if (!ndlp) {
dea31012005-04-17 16:05:31 -0500744 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500745 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
746 if (!ndlp)
747 return 0;
James Smart2e0fef82007-06-17 19:56:36 -0500748 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -0500749 /* Put ndlp onto node list */
750 lpfc_enqueue_node(vport, ndlp);
751 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
752 /* re-setup ndlp without removing from node list */
753 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
754 if (!ndlp)
755 return 0;
dea31012005-04-17 16:05:31 -0500756 }
James Smart87af33f2007-10-27 13:37:43 -0400757
James Smarte47c9092008-02-08 18:49:26 -0500758 if (lpfc_issue_els_flogi(vport, ndlp, 0))
James Smartfa4066b2008-01-11 01:53:27 -0500759 /* This decrement of reference count to node shall kick off
760 * the release of the node.
761 */
James Smart329f9bc2007-04-25 09:53:01 -0400762 lpfc_nlp_put(ndlp);
James Smarte47c9092008-02-08 18:49:26 -0500763
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500764 return 1;
dea31012005-04-17 16:05:31 -0500765}
766
James Smart92d7f7b2007-06-17 19:56:38 -0500767int
768lpfc_initial_fdisc(struct lpfc_vport *vport)
769{
770 struct lpfc_hba *phba = vport->phba;
771 struct lpfc_nodelist *ndlp;
772
773 /* First look for the Fabric ndlp */
774 ndlp = lpfc_findnode_did(vport, Fabric_DID);
775 if (!ndlp) {
776 /* Cannot find existing Fabric ndlp, so allocate a new one */
777 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
778 if (!ndlp)
779 return 0;
780 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -0500781 /* Put ndlp onto node list */
782 lpfc_enqueue_node(vport, ndlp);
783 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
784 /* re-setup ndlp without removing from node list */
785 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
786 if (!ndlp)
787 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500788 }
James Smarte47c9092008-02-08 18:49:26 -0500789
James Smart92d7f7b2007-06-17 19:56:38 -0500790 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -0500791 /* decrement node reference count to trigger the release of
792 * the node.
793 */
James Smart92d7f7b2007-06-17 19:56:38 -0500794 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -0500795 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500796 }
797 return 1;
798}
James Smart87af33f2007-10-27 13:37:43 -0400799
800void
James Smart2e0fef82007-06-17 19:56:36 -0500801lpfc_more_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -0500802{
803 int sentplogi;
804
James Smart2e0fef82007-06-17 19:56:36 -0500805 if (vport->num_disc_nodes)
806 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -0500807
808 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
James Smarte8b62012007-08-02 11:10:09 -0400809 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
810 "0232 Continue discovery with %d PLOGIs to go "
811 "Data: x%x x%x x%x\n",
812 vport->num_disc_nodes, vport->fc_plogi_cnt,
813 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -0500814 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -0500815 if (vport->fc_flag & FC_NLP_MORE)
816 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
817 sentplogi = lpfc_els_disc_plogi(vport);
818
dea31012005-04-17 16:05:31 -0500819 return;
820}
821
James Smart488d1462006-03-07 15:02:37 -0500822static struct lpfc_nodelist *
James Smart92d7f7b2007-06-17 19:56:38 -0500823lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
James Smart488d1462006-03-07 15:02:37 -0500824 struct lpfc_nodelist *ndlp)
825{
James Smart2e0fef82007-06-17 19:56:36 -0500826 struct lpfc_vport *vport = ndlp->vport;
James Smart488d1462006-03-07 15:02:37 -0500827 struct lpfc_nodelist *new_ndlp;
James Smart0ff10d42008-01-11 01:52:36 -0500828 struct lpfc_rport_data *rdata;
829 struct fc_rport *rport;
James Smart488d1462006-03-07 15:02:37 -0500830 struct serv_parm *sp;
James Smart92d7f7b2007-06-17 19:56:38 -0500831 uint8_t name[sizeof(struct lpfc_name)];
James Smart488d1462006-03-07 15:02:37 -0500832 uint32_t rc;
833
James Smart2fb9bd82006-12-02 13:33:57 -0500834 /* Fabric nodes can have the same WWPN so we don't bother searching
835 * by WWPN. Just return the ndlp that was given to us.
836 */
837 if (ndlp->nlp_type & NLP_FABRIC)
838 return ndlp;
839
James Smart92d7f7b2007-06-17 19:56:38 -0500840 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
James Smart685f0bf2007-04-25 09:53:08 -0400841 memset(name, 0, sizeof(struct lpfc_name));
James Smart488d1462006-03-07 15:02:37 -0500842
James Smart685f0bf2007-04-25 09:53:08 -0400843 /* Now we find out if the NPort we are logging into, matches the WWPN
James Smart488d1462006-03-07 15:02:37 -0500844 * we have for that ndlp. If not, we have some work to do.
845 */
James Smart2e0fef82007-06-17 19:56:36 -0500846 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
James Smart488d1462006-03-07 15:02:37 -0500847
James Smarte47c9092008-02-08 18:49:26 -0500848 if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
James Smart488d1462006-03-07 15:02:37 -0500849 return ndlp;
James Smart488d1462006-03-07 15:02:37 -0500850
851 if (!new_ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -0500852 rc = memcmp(&ndlp->nlp_portname, name,
853 sizeof(struct lpfc_name));
James Smart92795652006-07-06 15:50:02 -0400854 if (!rc)
855 return ndlp;
James Smart488d1462006-03-07 15:02:37 -0500856 new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
857 if (!new_ndlp)
858 return ndlp;
James Smart2e0fef82007-06-17 19:56:36 -0500859 lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID);
James Smarte47c9092008-02-08 18:49:26 -0500860 } else if (!NLP_CHK_NODE_ACT(new_ndlp)) {
861 new_ndlp = lpfc_enable_node(vport, new_ndlp,
862 NLP_STE_UNUSED_NODE);
863 if (!new_ndlp)
864 return ndlp;
James Smart488d1462006-03-07 15:02:37 -0500865 }
866
James Smart2e0fef82007-06-17 19:56:36 -0500867 lpfc_unreg_rpi(vport, new_ndlp);
James Smart488d1462006-03-07 15:02:37 -0500868 new_ndlp->nlp_DID = ndlp->nlp_DID;
James Smart92795652006-07-06 15:50:02 -0400869 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
James Smart0ff10d42008-01-11 01:52:36 -0500870
871 if (ndlp->nlp_flag & NLP_NPR_2B_DISC)
872 new_ndlp->nlp_flag |= NLP_NPR_2B_DISC;
873 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
874
James Smarte47c9092008-02-08 18:49:26 -0500875 /* Set state will put new_ndlp on to node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -0500876 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
James Smart488d1462006-03-07 15:02:37 -0500877
James Smart2e0fef82007-06-17 19:56:36 -0500878 /* Move this back to NPR state */
James Smart87af33f2007-10-27 13:37:43 -0400879 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
880 /* The new_ndlp is replacing ndlp totally, so we need
881 * to put ndlp on UNUSED list and try to free it.
882 */
James Smart0ff10d42008-01-11 01:52:36 -0500883
884 /* Fix up the rport accordingly */
885 rport = ndlp->rport;
886 if (rport) {
887 rdata = rport->dd_data;
888 if (rdata->pnode == ndlp) {
889 lpfc_nlp_put(ndlp);
890 ndlp->rport = NULL;
891 rdata->pnode = lpfc_nlp_get(new_ndlp);
892 new_ndlp->rport = rport;
893 }
894 new_ndlp->nlp_type = ndlp->nlp_type;
895 }
896
James Smart2e0fef82007-06-17 19:56:36 -0500897 lpfc_drop_node(vport, ndlp);
James Smart87af33f2007-10-27 13:37:43 -0400898 }
James Smart92795652006-07-06 15:50:02 -0400899 else {
James Smart2e0fef82007-06-17 19:56:36 -0500900 lpfc_unreg_rpi(vport, ndlp);
James Smart92795652006-07-06 15:50:02 -0400901 ndlp->nlp_DID = 0; /* Two ndlps cannot have the same did */
James Smart2e0fef82007-06-17 19:56:36 -0500902 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smart92795652006-07-06 15:50:02 -0400903 }
James Smart488d1462006-03-07 15:02:37 -0500904 return new_ndlp;
905}
906
James Smart87af33f2007-10-27 13:37:43 -0400907void
908lpfc_end_rscn(struct lpfc_vport *vport)
909{
910 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
911
912 if (vport->fc_flag & FC_RSCN_MODE) {
913 /*
914 * Check to see if more RSCNs came in while we were
915 * processing this one.
916 */
917 if (vport->fc_rscn_id_cnt ||
918 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
919 lpfc_els_handle_rscn(vport);
920 else {
921 spin_lock_irq(shost->host_lock);
922 vport->fc_flag &= ~FC_RSCN_MODE;
923 spin_unlock_irq(shost->host_lock);
924 }
925 }
926}
927
dea31012005-04-17 16:05:31 -0500928static void
James Smart2e0fef82007-06-17 19:56:36 -0500929lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
930 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500931{
James Smart2e0fef82007-06-17 19:56:36 -0500932 struct lpfc_vport *vport = cmdiocb->vport;
933 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500934 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -0500935 struct lpfc_nodelist *ndlp;
James Smart92795652006-07-06 15:50:02 -0400936 struct lpfc_dmabuf *prsp;
dea31012005-04-17 16:05:31 -0500937 int disc, rc, did, type;
938
dea31012005-04-17 16:05:31 -0500939 /* we pass cmdiocb to state machine which needs rspiocb as well */
940 cmdiocb->context_un.rsp_iocb = rspiocb;
941
942 irsp = &rspiocb->iocb;
James Smart858c9f62007-06-17 19:56:39 -0500943 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
944 "PLOGI cmpl: status:x%x/x%x did:x%x",
945 irsp->ulpStatus, irsp->un.ulpWord[4],
946 irsp->un.elsreq64.remoteID);
947
James Smart2e0fef82007-06-17 19:56:36 -0500948 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
James Smarte47c9092008-02-08 18:49:26 -0500949 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smarte8b62012007-08-02 11:10:09 -0400950 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
951 "0136 PLOGI completes to NPort x%x "
952 "with no ndlp. Data: x%x x%x x%x\n",
953 irsp->un.elsreq64.remoteID,
954 irsp->ulpStatus, irsp->un.ulpWord[4],
955 irsp->ulpIoTag);
James Smart488d1462006-03-07 15:02:37 -0500956 goto out;
James Smarted957682007-06-17 19:56:37 -0500957 }
dea31012005-04-17 16:05:31 -0500958
959 /* Since ndlp can be freed in the disc state machine, note if this node
960 * is being used during discovery.
961 */
James Smart2e0fef82007-06-17 19:56:36 -0500962 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500963 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
James Smart488d1462006-03-07 15:02:37 -0500964 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500965 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500966 rc = 0;
967
968 /* PLOGI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -0400969 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
970 "0102 PLOGI completes to NPort x%x "
971 "Data: x%x x%x x%x x%x x%x\n",
972 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
973 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -0500974 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500975 if (lpfc_els_chk_latt(vport)) {
976 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500977 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500978 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500979 goto out;
980 }
981
982 /* ndlp could be freed in DSM, save these values now */
983 type = ndlp->nlp_type;
984 did = ndlp->nlp_DID;
985
986 if (irsp->ulpStatus) {
987 /* Check for retry */
988 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
989 /* ELS command is being retried */
990 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -0500991 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500992 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500993 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500994 }
995 goto out;
996 }
dea31012005-04-17 16:05:31 -0500997 /* PLOGI failed */
998 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -0500999 if (lpfc_error_lost_link(irsp))
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001000 rc = NLP_STE_FREED_NODE;
James Smarte47c9092008-02-08 18:49:26 -05001001 else
James Smart2e0fef82007-06-17 19:56:36 -05001002 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001003 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001004 } else {
1005 /* Good status, call state machine */
James Smart92795652006-07-06 15:50:02 -04001006 prsp = list_entry(((struct lpfc_dmabuf *)
James Smart92d7f7b2007-06-17 19:56:38 -05001007 cmdiocb->context2)->list.next,
1008 struct lpfc_dmabuf, list);
1009 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05001010 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001011 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001012 }
1013
James Smart2e0fef82007-06-17 19:56:36 -05001014 if (disc && vport->num_disc_nodes) {
dea31012005-04-17 16:05:31 -05001015 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001016 lpfc_more_plogi(vport);
dea31012005-04-17 16:05:31 -05001017
James Smart2e0fef82007-06-17 19:56:36 -05001018 if (vport->num_disc_nodes == 0) {
1019 spin_lock_irq(shost->host_lock);
1020 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1021 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001022
James Smart2e0fef82007-06-17 19:56:36 -05001023 lpfc_can_disctmo(vport);
James Smart87af33f2007-10-27 13:37:43 -04001024 lpfc_end_rscn(vport);
dea31012005-04-17 16:05:31 -05001025 }
1026 }
1027
1028out:
1029 lpfc_els_free_iocb(phba, cmdiocb);
1030 return;
1031}
1032
1033int
James Smart2e0fef82007-06-17 19:56:36 -05001034lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
dea31012005-04-17 16:05:31 -05001035{
James Smart2e0fef82007-06-17 19:56:36 -05001036 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001037 struct serv_parm *sp;
1038 IOCB_t *icmd;
James Smart98c9ea52007-10-27 13:37:33 -04001039 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05001040 struct lpfc_iocbq *elsiocb;
1041 struct lpfc_sli_ring *pring;
1042 struct lpfc_sli *psli;
1043 uint8_t *pcmd;
1044 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05001045 int ret;
dea31012005-04-17 16:05:31 -05001046
1047 psli = &phba->sli;
1048 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1049
James Smart98c9ea52007-10-27 13:37:33 -04001050 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05001051 if (ndlp && !NLP_CHK_NODE_ACT(ndlp))
1052 ndlp = NULL;
James Smart98c9ea52007-10-27 13:37:33 -04001053
James Smarte47c9092008-02-08 18:49:26 -05001054 /* If ndlp is not NULL, we will bump the reference count on it */
James Smart92d7f7b2007-06-17 19:56:38 -05001055 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart98c9ea52007-10-27 13:37:33 -04001056 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
James Smart2e0fef82007-06-17 19:56:36 -05001057 ELS_CMD_PLOGI);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001058 if (!elsiocb)
1059 return 1;
dea31012005-04-17 16:05:31 -05001060
1061 icmd = &elsiocb->iocb;
1062 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1063
1064 /* For PLOGI request, remainder of payload is service parameters */
1065 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001066 pcmd += sizeof(uint32_t);
1067 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001068 sp = (struct serv_parm *) pcmd;
1069
1070 if (sp->cmn.fcphLow < FC_PH_4_3)
1071 sp->cmn.fcphLow = FC_PH_4_3;
1072
1073 if (sp->cmn.fcphHigh < FC_PH3)
1074 sp->cmn.fcphHigh = FC_PH3;
1075
James Smart858c9f62007-06-17 19:56:39 -05001076 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1077 "Issue PLOGI: did:x%x",
1078 did, 0, 0);
1079
dea31012005-04-17 16:05:31 -05001080 phba->fc_stat.elsXmitPLOGI++;
1081 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
James Smart92d7f7b2007-06-17 19:56:38 -05001082 ret = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
1083
1084 if (ret == IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05001085 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001086 return 1;
dea31012005-04-17 16:05:31 -05001087 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001088 return 0;
dea31012005-04-17 16:05:31 -05001089}
1090
1091static void
James Smart2e0fef82007-06-17 19:56:36 -05001092lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1093 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001094{
James Smart2e0fef82007-06-17 19:56:36 -05001095 struct lpfc_vport *vport = cmdiocb->vport;
1096 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001097 IOCB_t *irsp;
1098 struct lpfc_sli *psli;
1099 struct lpfc_nodelist *ndlp;
1100
1101 psli = &phba->sli;
1102 /* we pass cmdiocb to state machine which needs rspiocb as well */
1103 cmdiocb->context_un.rsp_iocb = rspiocb;
1104
1105 irsp = &(rspiocb->iocb);
1106 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
James Smart2e0fef82007-06-17 19:56:36 -05001107 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001108 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001109 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001110
James Smart858c9f62007-06-17 19:56:39 -05001111 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1112 "PRLI cmpl: status:x%x/x%x did:x%x",
1113 irsp->ulpStatus, irsp->un.ulpWord[4],
1114 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05001115 /* PRLI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001116 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1117 "0103 PRLI completes to NPort x%x "
1118 "Data: x%x x%x x%x x%x\n",
1119 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1120 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001121
James Smart2e0fef82007-06-17 19:56:36 -05001122 vport->fc_prli_sent--;
dea31012005-04-17 16:05:31 -05001123 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001124 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05001125 goto out;
1126
1127 if (irsp->ulpStatus) {
1128 /* Check for retry */
1129 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1130 /* ELS command is being retried */
1131 goto out;
1132 }
1133 /* PRLI failed */
1134 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001135 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05001136 goto out;
James Smarte47c9092008-02-08 18:49:26 -05001137 else
James Smart2e0fef82007-06-17 19:56:36 -05001138 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001139 NLP_EVT_CMPL_PRLI);
James Smarte47c9092008-02-08 18:49:26 -05001140 } else
dea31012005-04-17 16:05:31 -05001141 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05001142 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001143 NLP_EVT_CMPL_PRLI);
dea31012005-04-17 16:05:31 -05001144out:
1145 lpfc_els_free_iocb(phba, cmdiocb);
1146 return;
1147}
1148
1149int
James Smart2e0fef82007-06-17 19:56:36 -05001150lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001151 uint8_t retry)
1152{
James Smart2e0fef82007-06-17 19:56:36 -05001153 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1154 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001155 PRLI *npr;
1156 IOCB_t *icmd;
1157 struct lpfc_iocbq *elsiocb;
1158 struct lpfc_sli_ring *pring;
1159 struct lpfc_sli *psli;
1160 uint8_t *pcmd;
1161 uint16_t cmdsize;
1162
1163 psli = &phba->sli;
1164 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1165
James Smart92d7f7b2007-06-17 19:56:38 -05001166 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
James Smart2e0fef82007-06-17 19:56:36 -05001167 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1168 ndlp->nlp_DID, ELS_CMD_PRLI);
James Smart488d1462006-03-07 15:02:37 -05001169 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001170 return 1;
dea31012005-04-17 16:05:31 -05001171
1172 icmd = &elsiocb->iocb;
1173 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1174
1175 /* For PRLI request, remainder of payload is service parameters */
James Smart92d7f7b2007-06-17 19:56:38 -05001176 memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t)));
dea31012005-04-17 16:05:31 -05001177 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
James Smart92d7f7b2007-06-17 19:56:38 -05001178 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001179
1180 /* For PRLI, remainder of payload is PRLI parameter page */
1181 npr = (PRLI *) pcmd;
1182 /*
1183 * If our firmware version is 3.20 or later,
1184 * set the following bits for FC-TAPE support.
1185 */
1186 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
1187 npr->ConfmComplAllowed = 1;
1188 npr->Retry = 1;
1189 npr->TaskRetryIdReq = 1;
1190 }
1191 npr->estabImagePair = 1;
1192 npr->readXferRdyDis = 1;
1193
1194 /* For FCP support */
1195 npr->prliType = PRLI_FCP_TYPE;
1196 npr->initiatorFunc = 1;
1197
James Smart858c9f62007-06-17 19:56:39 -05001198 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1199 "Issue PRLI: did:x%x",
1200 ndlp->nlp_DID, 0, 0);
1201
dea31012005-04-17 16:05:31 -05001202 phba->fc_stat.elsXmitPRLI++;
1203 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
James Smart2e0fef82007-06-17 19:56:36 -05001204 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001205 ndlp->nlp_flag |= NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001206 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001207 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05001208 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001209 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001210 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001211 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001212 return 1;
dea31012005-04-17 16:05:31 -05001213 }
James Smart2e0fef82007-06-17 19:56:36 -05001214 vport->fc_prli_sent++;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001215 return 0;
dea31012005-04-17 16:05:31 -05001216}
1217
James Smart0ff10d42008-01-11 01:52:36 -05001218void
James Smart2e0fef82007-06-17 19:56:36 -05001219lpfc_more_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001220{
1221 int sentadisc;
1222
James Smart2e0fef82007-06-17 19:56:36 -05001223 if (vport->num_disc_nodes)
1224 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001225 /* Continue discovery with <num_disc_nodes> ADISCs to go */
James Smarte8b62012007-08-02 11:10:09 -04001226 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1227 "0210 Continue discovery with %d ADISCs to go "
1228 "Data: x%x x%x x%x\n",
1229 vport->num_disc_nodes, vport->fc_adisc_cnt,
1230 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001231 /* Check to see if there are more ADISCs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001232 if (vport->fc_flag & FC_NLP_MORE) {
1233 lpfc_set_disctmo(vport);
1234 /* go thru NPR nodes and issue any remaining ELS ADISCs */
1235 sentadisc = lpfc_els_disc_adisc(vport);
dea31012005-04-17 16:05:31 -05001236 }
1237 return;
1238}
1239
1240static void
James Smart2e0fef82007-06-17 19:56:36 -05001241lpfc_rscn_disc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001242{
James Smart858c9f62007-06-17 19:56:39 -05001243 lpfc_can_disctmo(vport);
1244
dea31012005-04-17 16:05:31 -05001245 /* RSCN discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001246 /* go thru NPR nodes and issue ELS PLOGIs */
1247 if (vport->fc_npr_cnt)
1248 if (lpfc_els_disc_plogi(vport))
dea31012005-04-17 16:05:31 -05001249 return;
James Smart2e0fef82007-06-17 19:56:36 -05001250
James Smart87af33f2007-10-27 13:37:43 -04001251 lpfc_end_rscn(vport);
dea31012005-04-17 16:05:31 -05001252}
1253
1254static void
James Smart2e0fef82007-06-17 19:56:36 -05001255lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1256 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001257{
James Smart2e0fef82007-06-17 19:56:36 -05001258 struct lpfc_vport *vport = cmdiocb->vport;
1259 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001260 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001261 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001262 int disc;
dea31012005-04-17 16:05:31 -05001263
1264 /* we pass cmdiocb to state machine which needs rspiocb as well */
1265 cmdiocb->context_un.rsp_iocb = rspiocb;
1266
1267 irsp = &(rspiocb->iocb);
1268 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
dea31012005-04-17 16:05:31 -05001269
James Smart858c9f62007-06-17 19:56:39 -05001270 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1271 "ADISC cmpl: status:x%x/x%x did:x%x",
1272 irsp->ulpStatus, irsp->un.ulpWord[4],
1273 ndlp->nlp_DID);
1274
dea31012005-04-17 16:05:31 -05001275 /* Since ndlp can be freed in the disc state machine, note if this node
1276 * is being used during discovery.
1277 */
James Smart2e0fef82007-06-17 19:56:36 -05001278 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001279 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001280 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001281 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001282 /* ADISC completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001283 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1284 "0104 ADISC completes to NPort x%x "
1285 "Data: x%x x%x x%x x%x x%x\n",
1286 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1287 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001288 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001289 if (lpfc_els_chk_latt(vport)) {
1290 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001291 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001292 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001293 goto out;
1294 }
1295
1296 if (irsp->ulpStatus) {
1297 /* Check for retry */
1298 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1299 /* ELS command is being retried */
1300 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05001301 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001302 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001303 spin_unlock_irq(shost->host_lock);
1304 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001305 }
1306 goto out;
1307 }
1308 /* ADISC failed */
1309 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001310 if (!lpfc_error_lost_link(irsp))
James Smart2e0fef82007-06-17 19:56:36 -05001311 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart858c9f62007-06-17 19:56:39 -05001312 NLP_EVT_CMPL_ADISC);
James Smarte47c9092008-02-08 18:49:26 -05001313 } else
dea31012005-04-17 16:05:31 -05001314 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05001315 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
dea31012005-04-17 16:05:31 -05001316 NLP_EVT_CMPL_ADISC);
dea31012005-04-17 16:05:31 -05001317
James Smart2e0fef82007-06-17 19:56:36 -05001318 if (disc && vport->num_disc_nodes) {
dea31012005-04-17 16:05:31 -05001319 /* Check to see if there are more ADISCs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001320 lpfc_more_adisc(vport);
dea31012005-04-17 16:05:31 -05001321
1322 /* Check to see if we are done with ADISC authentication */
James Smart2e0fef82007-06-17 19:56:36 -05001323 if (vport->num_disc_nodes == 0) {
James Smart92d7f7b2007-06-17 19:56:38 -05001324 /* If we get here, there is nothing left to ADISC */
1325 /*
1326 * For NPIV, cmpl_reg_vpi will set port_state to READY,
1327 * and continue discovery.
1328 */
1329 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
1330 !(vport->fc_flag & FC_RSCN_MODE)) {
1331 lpfc_issue_reg_vpi(phba, vport);
1332 goto out;
1333 }
1334 /*
1335 * For SLI2, we need to set port_state to READY
1336 * and continue discovery.
1337 */
1338 if (vport->port_state < LPFC_VPORT_READY) {
1339 /* If we get here, there is nothing to ADISC */
James Smarted957682007-06-17 19:56:37 -05001340 if (vport->port_type == LPFC_PHYSICAL_PORT)
James Smart2e0fef82007-06-17 19:56:36 -05001341 lpfc_issue_clear_la(phba, vport);
James Smart92d7f7b2007-06-17 19:56:38 -05001342
1343 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
1344 vport->num_disc_nodes = 0;
1345 /* go thru NPR list, issue ELS PLOGIs */
1346 if (vport->fc_npr_cnt)
1347 lpfc_els_disc_plogi(vport);
1348
1349 if (!vport->num_disc_nodes) {
1350 spin_lock_irq(shost->host_lock);
1351 vport->fc_flag &=
1352 ~FC_NDISC_ACTIVE;
1353 spin_unlock_irq(
1354 shost->host_lock);
1355 lpfc_can_disctmo(vport);
1356 }
1357 }
1358 vport->port_state = LPFC_VPORT_READY;
dea31012005-04-17 16:05:31 -05001359 } else {
James Smart2e0fef82007-06-17 19:56:36 -05001360 lpfc_rscn_disc(vport);
dea31012005-04-17 16:05:31 -05001361 }
1362 }
1363 }
dea31012005-04-17 16:05:31 -05001364out:
1365 lpfc_els_free_iocb(phba, cmdiocb);
1366 return;
1367}
1368
1369int
James Smart2e0fef82007-06-17 19:56:36 -05001370lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001371 uint8_t retry)
1372{
James Smart2e0fef82007-06-17 19:56:36 -05001373 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1374 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001375 ADISC *ap;
1376 IOCB_t *icmd;
1377 struct lpfc_iocbq *elsiocb;
James Smart2e0fef82007-06-17 19:56:36 -05001378 struct lpfc_sli *psli = &phba->sli;
1379 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05001380 uint8_t *pcmd;
1381 uint16_t cmdsize;
1382
James Smart92d7f7b2007-06-17 19:56:38 -05001383 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
James Smart2e0fef82007-06-17 19:56:36 -05001384 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1385 ndlp->nlp_DID, ELS_CMD_ADISC);
James Smart488d1462006-03-07 15:02:37 -05001386 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001387 return 1;
dea31012005-04-17 16:05:31 -05001388
1389 icmd = &elsiocb->iocb;
1390 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1391
1392 /* For ADISC request, remainder of payload is service parameters */
1393 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
James Smart92d7f7b2007-06-17 19:56:38 -05001394 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001395
1396 /* Fill in ADISC payload */
1397 ap = (ADISC *) pcmd;
1398 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05001399 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
1400 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05001401 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05001402
James Smart858c9f62007-06-17 19:56:39 -05001403 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1404 "Issue ADISC: did:x%x",
1405 ndlp->nlp_DID, 0, 0);
1406
dea31012005-04-17 16:05:31 -05001407 phba->fc_stat.elsXmitADISC++;
1408 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
James Smart2e0fef82007-06-17 19:56:36 -05001409 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001410 ndlp->nlp_flag |= NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001411 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001412 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05001413 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001414 ndlp->nlp_flag &= ~NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001415 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001416 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001417 return 1;
dea31012005-04-17 16:05:31 -05001418 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001419 return 0;
dea31012005-04-17 16:05:31 -05001420}
1421
1422static void
James Smart2e0fef82007-06-17 19:56:36 -05001423lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1424 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001425{
James Smart2e0fef82007-06-17 19:56:36 -05001426 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1427 struct lpfc_vport *vport = ndlp->vport;
1428 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001429 IOCB_t *irsp;
1430 struct lpfc_sli *psli;
dea31012005-04-17 16:05:31 -05001431
1432 psli = &phba->sli;
1433 /* we pass cmdiocb to state machine which needs rspiocb as well */
1434 cmdiocb->context_un.rsp_iocb = rspiocb;
1435
1436 irsp = &(rspiocb->iocb);
James Smart2e0fef82007-06-17 19:56:36 -05001437 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001438 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001439 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001440
James Smart858c9f62007-06-17 19:56:39 -05001441 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1442 "LOGO cmpl: status:x%x/x%x did:x%x",
1443 irsp->ulpStatus, irsp->un.ulpWord[4],
1444 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05001445 /* LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001446 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1447 "0105 LOGO completes to NPort x%x "
1448 "Data: x%x x%x x%x x%x\n",
1449 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1450 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001451 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001452 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05001453 goto out;
1454
James Smart92d7f7b2007-06-17 19:56:38 -05001455 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
1456 /* NLP_EVT_DEVICE_RM should unregister the RPI
1457 * which should abort all outstanding IOs.
1458 */
1459 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1460 NLP_EVT_DEVICE_RM);
1461 goto out;
1462 }
1463
dea31012005-04-17 16:05:31 -05001464 if (irsp->ulpStatus) {
1465 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -05001466 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -05001467 /* ELS command is being retried */
1468 goto out;
dea31012005-04-17 16:05:31 -05001469 /* LOGO failed */
1470 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart858c9f62007-06-17 19:56:39 -05001471 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05001472 goto out;
James Smart858c9f62007-06-17 19:56:39 -05001473 else
James Smart2e0fef82007-06-17 19:56:36 -05001474 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001475 NLP_EVT_CMPL_LOGO);
James Smarte47c9092008-02-08 18:49:26 -05001476 } else
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001477 /* Good status, call state machine.
1478 * This will unregister the rpi if needed.
1479 */
James Smart2e0fef82007-06-17 19:56:36 -05001480 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001481 NLP_EVT_CMPL_LOGO);
dea31012005-04-17 16:05:31 -05001482out:
1483 lpfc_els_free_iocb(phba, cmdiocb);
1484 return;
1485}
1486
1487int
James Smart2e0fef82007-06-17 19:56:36 -05001488lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001489 uint8_t retry)
1490{
James Smart2e0fef82007-06-17 19:56:36 -05001491 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1492 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001493 IOCB_t *icmd;
1494 struct lpfc_iocbq *elsiocb;
1495 struct lpfc_sli_ring *pring;
1496 struct lpfc_sli *psli;
1497 uint8_t *pcmd;
1498 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05001499 int rc;
dea31012005-04-17 16:05:31 -05001500
1501 psli = &phba->sli;
1502 pring = &psli->ring[LPFC_ELS_RING];
1503
James Smart98c9ea52007-10-27 13:37:33 -04001504 spin_lock_irq(shost->host_lock);
1505 if (ndlp->nlp_flag & NLP_LOGO_SND) {
1506 spin_unlock_irq(shost->host_lock);
1507 return 0;
1508 }
1509 spin_unlock_irq(shost->host_lock);
1510
James Smart92d7f7b2007-06-17 19:56:38 -05001511 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
James Smart2e0fef82007-06-17 19:56:36 -05001512 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1513 ndlp->nlp_DID, ELS_CMD_LOGO);
James Smart488d1462006-03-07 15:02:37 -05001514 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001515 return 1;
dea31012005-04-17 16:05:31 -05001516
1517 icmd = &elsiocb->iocb;
1518 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1519 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
James Smart92d7f7b2007-06-17 19:56:38 -05001520 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001521
1522 /* Fill in LOGO payload */
James Smart2e0fef82007-06-17 19:56:36 -05001523 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05001524 pcmd += sizeof(uint32_t);
1525 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05001526
James Smart858c9f62007-06-17 19:56:39 -05001527 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1528 "Issue LOGO: did:x%x",
1529 ndlp->nlp_DID, 0, 0);
1530
dea31012005-04-17 16:05:31 -05001531 phba->fc_stat.elsXmitLOGO++;
1532 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
James Smart2e0fef82007-06-17 19:56:36 -05001533 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001534 ndlp->nlp_flag |= NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001535 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05001536 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
1537
1538 if (rc == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05001539 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001540 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001541 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001542 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001543 return 1;
dea31012005-04-17 16:05:31 -05001544 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001545 return 0;
dea31012005-04-17 16:05:31 -05001546}
1547
1548static void
James Smart2e0fef82007-06-17 19:56:36 -05001549lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1550 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001551{
James Smart2e0fef82007-06-17 19:56:36 -05001552 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -05001553 IOCB_t *irsp;
1554
1555 irsp = &rspiocb->iocb;
1556
James Smart858c9f62007-06-17 19:56:39 -05001557 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1558 "ELS cmd cmpl: status:x%x/x%x did:x%x",
1559 irsp->ulpStatus, irsp->un.ulpWord[4],
1560 irsp->un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05001561 /* ELS cmd tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04001562 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1563 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
1564 irsp->ulpIoTag, irsp->ulpStatus,
1565 irsp->un.ulpWord[4], irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -05001566 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001567 lpfc_els_chk_latt(vport);
dea31012005-04-17 16:05:31 -05001568 lpfc_els_free_iocb(phba, cmdiocb);
1569 return;
1570}
1571
1572int
James Smart2e0fef82007-06-17 19:56:36 -05001573lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05001574{
James Smart2e0fef82007-06-17 19:56:36 -05001575 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001576 IOCB_t *icmd;
1577 struct lpfc_iocbq *elsiocb;
1578 struct lpfc_sli_ring *pring;
1579 struct lpfc_sli *psli;
1580 uint8_t *pcmd;
1581 uint16_t cmdsize;
1582 struct lpfc_nodelist *ndlp;
1583
1584 psli = &phba->sli;
1585 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
James Smart92d7f7b2007-06-17 19:56:38 -05001586 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
dea31012005-04-17 16:05:31 -05001587
James Smarte47c9092008-02-08 18:49:26 -05001588 ndlp = lpfc_findnode_did(vport, nportid);
1589 if (!ndlp) {
1590 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1591 if (!ndlp)
1592 return 1;
1593 lpfc_nlp_init(vport, ndlp, nportid);
1594 lpfc_enqueue_node(vport, ndlp);
1595 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1596 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1597 if (!ndlp)
1598 return 1;
1599 }
dea31012005-04-17 16:05:31 -05001600
James Smart2e0fef82007-06-17 19:56:36 -05001601 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1602 ndlp->nlp_DID, ELS_CMD_SCR);
1603
James Smart488d1462006-03-07 15:02:37 -05001604 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05001605 /* This will trigger the release of the node just
1606 * allocated
1607 */
James Smart329f9bc2007-04-25 09:53:01 -04001608 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001609 return 1;
dea31012005-04-17 16:05:31 -05001610 }
1611
1612 icmd = &elsiocb->iocb;
1613 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1614
1615 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
James Smart92d7f7b2007-06-17 19:56:38 -05001616 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001617
1618 /* For SCR, remainder of payload is SCR parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05001619 memset(pcmd, 0, sizeof(SCR));
dea31012005-04-17 16:05:31 -05001620 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
1621
James Smart858c9f62007-06-17 19:56:39 -05001622 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1623 "Issue SCR: did:x%x",
1624 ndlp->nlp_DID, 0, 0);
1625
dea31012005-04-17 16:05:31 -05001626 phba->fc_stat.elsXmitSCR++;
1627 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
dea31012005-04-17 16:05:31 -05001628 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05001629 /* The additional lpfc_nlp_put will cause the following
1630 * lpfc_els_free_iocb routine to trigger the rlease of
1631 * the node.
1632 */
James Smart329f9bc2007-04-25 09:53:01 -04001633 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001634 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001635 return 1;
dea31012005-04-17 16:05:31 -05001636 }
James Smartfa4066b2008-01-11 01:53:27 -05001637 /* This will cause the callback-function lpfc_cmpl_els_cmd to
1638 * trigger the release of node.
1639 */
James Smart329f9bc2007-04-25 09:53:01 -04001640 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001641 return 0;
dea31012005-04-17 16:05:31 -05001642}
1643
1644static int
James Smart2e0fef82007-06-17 19:56:36 -05001645lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05001646{
James Smart2e0fef82007-06-17 19:56:36 -05001647 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001648 IOCB_t *icmd;
1649 struct lpfc_iocbq *elsiocb;
1650 struct lpfc_sli_ring *pring;
1651 struct lpfc_sli *psli;
1652 FARP *fp;
1653 uint8_t *pcmd;
1654 uint32_t *lp;
1655 uint16_t cmdsize;
1656 struct lpfc_nodelist *ondlp;
1657 struct lpfc_nodelist *ndlp;
1658
1659 psli = &phba->sli;
1660 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
James Smart92d7f7b2007-06-17 19:56:38 -05001661 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
dea31012005-04-17 16:05:31 -05001662
James Smarte47c9092008-02-08 18:49:26 -05001663 ndlp = lpfc_findnode_did(vport, nportid);
1664 if (!ndlp) {
1665 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1666 if (!ndlp)
1667 return 1;
1668 lpfc_nlp_init(vport, ndlp, nportid);
1669 lpfc_enqueue_node(vport, ndlp);
1670 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1671 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1672 if (!ndlp)
1673 return 1;
1674 }
James Smart2e0fef82007-06-17 19:56:36 -05001675
1676 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1677 ndlp->nlp_DID, ELS_CMD_RNID);
James Smart488d1462006-03-07 15:02:37 -05001678 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05001679 /* This will trigger the release of the node just
1680 * allocated
1681 */
James Smart329f9bc2007-04-25 09:53:01 -04001682 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001683 return 1;
dea31012005-04-17 16:05:31 -05001684 }
1685
1686 icmd = &elsiocb->iocb;
1687 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1688
1689 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
James Smart92d7f7b2007-06-17 19:56:38 -05001690 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001691
1692 /* Fill in FARPR payload */
1693 fp = (FARP *) (pcmd);
James Smart92d7f7b2007-06-17 19:56:38 -05001694 memset(fp, 0, sizeof(FARP));
dea31012005-04-17 16:05:31 -05001695 lp = (uint32_t *) pcmd;
1696 *lp++ = be32_to_cpu(nportid);
James Smart2e0fef82007-06-17 19:56:36 -05001697 *lp++ = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05001698 fp->Rflags = 0;
1699 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
1700
James Smart92d7f7b2007-06-17 19:56:38 -05001701 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
1702 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05001703 ondlp = lpfc_findnode_did(vport, nportid);
James Smarte47c9092008-02-08 18:49:26 -05001704 if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
dea31012005-04-17 16:05:31 -05001705 memcpy(&fp->OportName, &ondlp->nlp_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05001706 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05001707 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05001708 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05001709 }
1710
James Smart858c9f62007-06-17 19:56:39 -05001711 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1712 "Issue FARPR: did:x%x",
1713 ndlp->nlp_DID, 0, 0);
1714
dea31012005-04-17 16:05:31 -05001715 phba->fc_stat.elsXmitFARPR++;
1716 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
dea31012005-04-17 16:05:31 -05001717 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05001718 /* The additional lpfc_nlp_put will cause the following
1719 * lpfc_els_free_iocb routine to trigger the release of
1720 * the node.
1721 */
James Smart329f9bc2007-04-25 09:53:01 -04001722 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001723 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001724 return 1;
dea31012005-04-17 16:05:31 -05001725 }
James Smartfa4066b2008-01-11 01:53:27 -05001726 /* This will cause the callback-function lpfc_cmpl_els_cmd to
1727 * trigger the release of the node.
1728 */
James Smart329f9bc2007-04-25 09:53:01 -04001729 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001730 return 0;
dea31012005-04-17 16:05:31 -05001731}
1732
1733void
James Smart2e0fef82007-06-17 19:56:36 -05001734lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
James Smartfdcebe22006-03-07 15:04:01 -05001735{
James Smart2e0fef82007-06-17 19:56:36 -05001736 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smarte47c9092008-02-08 18:49:26 -05001737 struct lpfc_work_evt *evtp;
James Smart2e0fef82007-06-17 19:56:36 -05001738
1739 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05001740 nlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001741 spin_unlock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05001742 del_timer_sync(&nlp->nlp_delayfunc);
1743 nlp->nlp_last_elscmd = 0;
1744
James Smarte47c9092008-02-08 18:49:26 -05001745 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
James Smartfdcebe22006-03-07 15:04:01 -05001746 list_del_init(&nlp->els_retry_evt.evt_listp);
James Smarte47c9092008-02-08 18:49:26 -05001747 /* Decrement nlp reference count held for the delayed retry */
1748 evtp = &nlp->els_retry_evt;
1749 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
1750 }
James Smartfdcebe22006-03-07 15:04:01 -05001751
1752 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
James Smart2e0fef82007-06-17 19:56:36 -05001753 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05001754 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001755 spin_unlock_irq(shost->host_lock);
1756 if (vport->num_disc_nodes) {
James Smartfdcebe22006-03-07 15:04:01 -05001757 /* Check to see if there are more
1758 * PLOGIs to be sent
1759 */
James Smart2e0fef82007-06-17 19:56:36 -05001760 lpfc_more_plogi(vport);
James Smartfdcebe22006-03-07 15:04:01 -05001761
James Smart2e0fef82007-06-17 19:56:36 -05001762 if (vport->num_disc_nodes == 0) {
1763 spin_lock_irq(shost->host_lock);
1764 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1765 spin_unlock_irq(shost->host_lock);
1766 lpfc_can_disctmo(vport);
James Smarted957682007-06-17 19:56:37 -05001767 lpfc_end_rscn(vport);
James Smartfdcebe22006-03-07 15:04:01 -05001768 }
1769 }
1770 }
1771 return;
1772}
1773
1774void
dea31012005-04-17 16:05:31 -05001775lpfc_els_retry_delay(unsigned long ptr)
1776{
James Smart2e0fef82007-06-17 19:56:36 -05001777 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
1778 struct lpfc_vport *vport = ndlp->vport;
James Smart2e0fef82007-06-17 19:56:36 -05001779 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05001780 unsigned long flags;
James Smart2e0fef82007-06-17 19:56:36 -05001781 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
dea31012005-04-17 16:05:31 -05001782
James Smart2e0fef82007-06-17 19:56:36 -05001783 ndlp = (struct lpfc_nodelist *) ptr;
1784 phba = ndlp->vport->phba;
dea31012005-04-17 16:05:31 -05001785 evtp = &ndlp->els_retry_evt;
1786
James Smart92d7f7b2007-06-17 19:56:38 -05001787 spin_lock_irqsave(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05001788 if (!list_empty(&evtp->evt_listp)) {
James Smart92d7f7b2007-06-17 19:56:38 -05001789 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05001790 return;
1791 }
1792
James Smartfa4066b2008-01-11 01:53:27 -05001793 /* We need to hold the node by incrementing the reference
1794 * count until the queued work is done
1795 */
1796 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
dea31012005-04-17 16:05:31 -05001797 evtp->evt = LPFC_EVT_ELS_RETRY;
1798 list_add_tail(&evtp->evt_listp, &phba->work_list);
1799 if (phba->work_wait)
James Smart92d7f7b2007-06-17 19:56:38 -05001800 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05001801
James Smart92d7f7b2007-06-17 19:56:38 -05001802 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05001803 return;
1804}
1805
1806void
1807lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
1808{
James Smart2e0fef82007-06-17 19:56:36 -05001809 struct lpfc_vport *vport = ndlp->vport;
1810 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1811 uint32_t cmd, did, retry;
dea31012005-04-17 16:05:31 -05001812
James Smart2e0fef82007-06-17 19:56:36 -05001813 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001814 did = ndlp->nlp_DID;
1815 cmd = ndlp->nlp_last_elscmd;
1816 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05001817
1818 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
James Smart2e0fef82007-06-17 19:56:36 -05001819 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001820 return;
1821 }
1822
1823 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001824 spin_unlock_irq(shost->host_lock);
James Smart1a169682006-03-07 15:04:06 -05001825 /*
1826 * If a discovery event readded nlp_delayfunc after timer
1827 * firing and before processing the timer, cancel the
1828 * nlp_delayfunc.
1829 */
1830 del_timer_sync(&ndlp->nlp_delayfunc);
dea31012005-04-17 16:05:31 -05001831 retry = ndlp->nlp_retry;
1832
1833 switch (cmd) {
1834 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05001835 lpfc_issue_els_flogi(vport, ndlp, retry);
dea31012005-04-17 16:05:31 -05001836 break;
1837 case ELS_CMD_PLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05001838 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001839 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001840 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05001841 }
dea31012005-04-17 16:05:31 -05001842 break;
1843 case ELS_CMD_ADISC:
James Smart2e0fef82007-06-17 19:56:36 -05001844 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001845 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001846 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05001847 }
dea31012005-04-17 16:05:31 -05001848 break;
1849 case ELS_CMD_PRLI:
James Smart2e0fef82007-06-17 19:56:36 -05001850 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001851 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001852 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05001853 }
dea31012005-04-17 16:05:31 -05001854 break;
1855 case ELS_CMD_LOGO:
James Smart2e0fef82007-06-17 19:56:36 -05001856 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001857 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001858 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05001859 }
dea31012005-04-17 16:05:31 -05001860 break;
James Smart92d7f7b2007-06-17 19:56:38 -05001861 case ELS_CMD_FDISC:
1862 lpfc_issue_els_fdisc(vport, ndlp, retry);
1863 break;
dea31012005-04-17 16:05:31 -05001864 }
1865 return;
1866}
1867
1868static int
James Smart2e0fef82007-06-17 19:56:36 -05001869lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1870 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001871{
James Smart2e0fef82007-06-17 19:56:36 -05001872 struct lpfc_vport *vport = cmdiocb->vport;
1873 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1874 IOCB_t *irsp = &rspiocb->iocb;
1875 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1876 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
dea31012005-04-17 16:05:31 -05001877 uint32_t *elscmd;
1878 struct ls_rjt stat;
James Smart2e0fef82007-06-17 19:56:36 -05001879 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
James Smart98c9ea52007-10-27 13:37:33 -04001880 int logerr = 0;
James Smart2e0fef82007-06-17 19:56:36 -05001881 uint32_t cmd = 0;
James Smart488d1462006-03-07 15:02:37 -05001882 uint32_t did;
dea31012005-04-17 16:05:31 -05001883
James Smart488d1462006-03-07 15:02:37 -05001884
dea31012005-04-17 16:05:31 -05001885 /* Note: context2 may be 0 for internal driver abort
1886 * of delays ELS command.
1887 */
1888
1889 if (pcmd && pcmd->virt) {
1890 elscmd = (uint32_t *) (pcmd->virt);
1891 cmd = *elscmd++;
1892 }
1893
James Smarte47c9092008-02-08 18:49:26 -05001894 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart488d1462006-03-07 15:02:37 -05001895 did = ndlp->nlp_DID;
1896 else {
1897 /* We should only hit this case for retrying PLOGI */
1898 did = irsp->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05001899 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05001900 if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
1901 && (cmd != ELS_CMD_PLOGI))
James Smart488d1462006-03-07 15:02:37 -05001902 return 1;
1903 }
1904
James Smart858c9f62007-06-17 19:56:39 -05001905 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1906 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
1907 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
1908
dea31012005-04-17 16:05:31 -05001909 switch (irsp->ulpStatus) {
1910 case IOSTAT_FCP_RSP_ERROR:
1911 case IOSTAT_REMOTE_STOP:
1912 break;
1913
1914 case IOSTAT_LOCAL_REJECT:
1915 switch ((irsp->un.ulpWord[4] & 0xff)) {
1916 case IOERR_LOOP_OPEN_FAILURE:
James Smart2e0fef82007-06-17 19:56:36 -05001917 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05001918 delay = 1000;
dea31012005-04-17 16:05:31 -05001919 retry = 1;
1920 break;
1921
James Smart92d7f7b2007-06-17 19:56:38 -05001922 case IOERR_ILLEGAL_COMMAND:
1923 if ((phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) &&
1924 (cmd == ELS_CMD_FDISC)) {
James Smarte8b62012007-08-02 11:10:09 -04001925 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1926 "0124 FDISC failed (3/6) "
1927 "retrying...\n");
James Smart92d7f7b2007-06-17 19:56:38 -05001928 lpfc_mbx_unreg_vpi(vport);
1929 retry = 1;
James Smart51ef4c22007-08-02 11:10:31 -04001930 /* FDISC retry policy */
1931 maxretry = 48;
1932 if (cmdiocb->retry >= 32)
1933 delay = 1000;
James Smart92d7f7b2007-06-17 19:56:38 -05001934 }
1935 break;
1936
dea31012005-04-17 16:05:31 -05001937 case IOERR_NO_RESOURCES:
James Smart98c9ea52007-10-27 13:37:33 -04001938 logerr = 1; /* HBA out of resources */
James Smart858c9f62007-06-17 19:56:39 -05001939 retry = 1;
1940 if (cmdiocb->retry > 100)
1941 delay = 100;
1942 maxretry = 250;
1943 break;
1944
1945 case IOERR_ILLEGAL_FRAME:
James Smart92d7f7b2007-06-17 19:56:38 -05001946 delay = 100;
dea31012005-04-17 16:05:31 -05001947 retry = 1;
1948 break;
1949
James Smart858c9f62007-06-17 19:56:39 -05001950 case IOERR_SEQUENCE_TIMEOUT:
dea31012005-04-17 16:05:31 -05001951 case IOERR_INVALID_RPI:
1952 retry = 1;
1953 break;
1954 }
1955 break;
1956
1957 case IOSTAT_NPORT_RJT:
1958 case IOSTAT_FABRIC_RJT:
1959 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
1960 retry = 1;
1961 break;
1962 }
1963 break;
1964
1965 case IOSTAT_NPORT_BSY:
1966 case IOSTAT_FABRIC_BSY:
James Smart98c9ea52007-10-27 13:37:33 -04001967 logerr = 1; /* Fabric / Remote NPort out of resources */
dea31012005-04-17 16:05:31 -05001968 retry = 1;
1969 break;
1970
1971 case IOSTAT_LS_RJT:
1972 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
1973 /* Added for Vendor specifc support
1974 * Just keep retrying for these Rsn / Exp codes
1975 */
1976 switch (stat.un.b.lsRjtRsnCode) {
1977 case LSRJT_UNABLE_TPC:
1978 if (stat.un.b.lsRjtRsnCodeExp ==
1979 LSEXP_CMD_IN_PROGRESS) {
1980 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05001981 delay = 1000;
dea31012005-04-17 16:05:31 -05001982 maxretry = 48;
1983 }
1984 retry = 1;
1985 break;
1986 }
1987 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05001988 delay = 1000;
dea31012005-04-17 16:05:31 -05001989 maxretry = lpfc_max_els_tries + 1;
1990 retry = 1;
1991 break;
1992 }
James Smart92d7f7b2007-06-17 19:56:38 -05001993 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
1994 (cmd == ELS_CMD_FDISC) &&
1995 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
James Smarte8b62012007-08-02 11:10:09 -04001996 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1997 "0125 FDISC Failed (x%x). "
1998 "Fabric out of resources\n",
1999 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05002000 lpfc_vport_set_state(vport,
2001 FC_VPORT_NO_FABRIC_RSCS);
2002 }
dea31012005-04-17 16:05:31 -05002003 break;
2004
2005 case LSRJT_LOGICAL_BSY:
James Smart858c9f62007-06-17 19:56:39 -05002006 if ((cmd == ELS_CMD_PLOGI) ||
2007 (cmd == ELS_CMD_PRLI)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002008 delay = 1000;
dea31012005-04-17 16:05:31 -05002009 maxretry = 48;
James Smart92d7f7b2007-06-17 19:56:38 -05002010 } else if (cmd == ELS_CMD_FDISC) {
James Smart51ef4c22007-08-02 11:10:31 -04002011 /* FDISC retry policy */
2012 maxretry = 48;
2013 if (cmdiocb->retry >= 32)
2014 delay = 1000;
dea31012005-04-17 16:05:31 -05002015 }
2016 retry = 1;
2017 break;
James Smart92d7f7b2007-06-17 19:56:38 -05002018
2019 case LSRJT_LOGICAL_ERR:
2020 case LSRJT_PROTOCOL_ERR:
2021 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2022 (cmd == ELS_CMD_FDISC) &&
2023 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
2024 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
2025 ) {
James Smarte8b62012007-08-02 11:10:09 -04002026 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2027 "0123 FDISC Failed (x%x). "
2028 "Fabric Detected Bad WWN\n",
2029 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05002030 lpfc_vport_set_state(vport,
2031 FC_VPORT_FABRIC_REJ_WWN);
2032 }
2033 break;
dea31012005-04-17 16:05:31 -05002034 }
2035 break;
2036
2037 case IOSTAT_INTERMED_RSP:
2038 case IOSTAT_BA_RJT:
2039 break;
2040
2041 default:
2042 break;
2043 }
2044
James Smart488d1462006-03-07 15:02:37 -05002045 if (did == FDMI_DID)
dea31012005-04-17 16:05:31 -05002046 retry = 1;
dea31012005-04-17 16:05:31 -05002047
James Smart98c9ea52007-10-27 13:37:33 -04002048 if ((cmd == ELS_CMD_FLOGI) &&
James Smart1b32f6a2008-02-08 18:49:39 -05002049 (phba->fc_topology != TOPOLOGY_LOOP) &&
2050 !lpfc_error_lost_link(irsp)) {
James Smart98c9ea52007-10-27 13:37:33 -04002051 /* FLOGI retry policy */
2052 retry = 1;
2053 maxretry = 48;
2054 if (cmdiocb->retry >= 32)
2055 delay = 1000;
2056 }
2057
dea31012005-04-17 16:05:31 -05002058 if ((++cmdiocb->retry) >= maxretry) {
2059 phba->fc_stat.elsRetryExceeded++;
2060 retry = 0;
2061 }
2062
James Smarted957682007-06-17 19:56:37 -05002063 if ((vport->load_flag & FC_UNLOADING) != 0)
2064 retry = 0;
2065
dea31012005-04-17 16:05:31 -05002066 if (retry) {
2067
2068 /* Retry ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04002069 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2070 "0107 Retry ELS command x%x to remote "
2071 "NPORT x%x Data: x%x x%x\n",
2072 cmd, did, cmdiocb->retry, delay);
dea31012005-04-17 16:05:31 -05002073
James Smart858c9f62007-06-17 19:56:39 -05002074 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
2075 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
2076 ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) {
2077 /* Don't reset timer for no resources */
2078
dea31012005-04-17 16:05:31 -05002079 /* If discovery / RSCN timer is running, reset it */
James Smart2e0fef82007-06-17 19:56:36 -05002080 if (timer_pending(&vport->fc_disctmo) ||
James Smart92d7f7b2007-06-17 19:56:38 -05002081 (vport->fc_flag & FC_RSCN_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05002082 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05002083 }
2084
2085 phba->fc_stat.elsXmitRetry++;
James Smart488d1462006-03-07 15:02:37 -05002086 if (ndlp && delay) {
dea31012005-04-17 16:05:31 -05002087 phba->fc_stat.elsDelayRetry++;
2088 ndlp->nlp_retry = cmdiocb->retry;
2089
James Smart92d7f7b2007-06-17 19:56:38 -05002090 /* delay is specified in milliseconds */
2091 mod_timer(&ndlp->nlp_delayfunc,
2092 jiffies + msecs_to_jiffies(delay));
James Smart2e0fef82007-06-17 19:56:36 -05002093 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002094 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002095 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002096
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002097 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart858c9f62007-06-17 19:56:39 -05002098 if (cmd == ELS_CMD_PRLI)
2099 lpfc_nlp_set_state(vport, ndlp,
2100 NLP_STE_REG_LOGIN_ISSUE);
2101 else
2102 lpfc_nlp_set_state(vport, ndlp,
2103 NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05002104 ndlp->nlp_last_elscmd = cmd;
2105
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002106 return 1;
dea31012005-04-17 16:05:31 -05002107 }
2108 switch (cmd) {
2109 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002110 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002111 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -05002112 case ELS_CMD_FDISC:
2113 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
2114 return 1;
dea31012005-04-17 16:05:31 -05002115 case ELS_CMD_PLOGI:
James Smart488d1462006-03-07 15:02:37 -05002116 if (ndlp) {
2117 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002118 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04002119 NLP_STE_PLOGI_ISSUE);
James Smart488d1462006-03-07 15:02:37 -05002120 }
James Smart2e0fef82007-06-17 19:56:36 -05002121 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002122 return 1;
dea31012005-04-17 16:05:31 -05002123 case ELS_CMD_ADISC:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002124 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002125 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2126 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002127 return 1;
dea31012005-04-17 16:05:31 -05002128 case ELS_CMD_PRLI:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002129 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002130 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
2131 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002132 return 1;
dea31012005-04-17 16:05:31 -05002133 case ELS_CMD_LOGO:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002134 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002135 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2136 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002137 return 1;
dea31012005-04-17 16:05:31 -05002138 }
2139 }
dea31012005-04-17 16:05:31 -05002140 /* No retry ELS command <elsCmd> to remote NPORT <did> */
James Smart98c9ea52007-10-27 13:37:33 -04002141 if (logerr) {
2142 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2143 "0137 No retry ELS command x%x to remote "
2144 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
2145 cmd, did, irsp->ulpStatus,
2146 irsp->un.ulpWord[4]);
2147 }
2148 else {
2149 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smarta58cbd52007-08-02 11:09:43 -04002150 "0108 No retry ELS command x%x to remote "
2151 "NPORT x%x Retried:%d Error:x%x/%x\n",
2152 cmd, did, cmdiocb->retry, irsp->ulpStatus,
2153 irsp->un.ulpWord[4]);
James Smart98c9ea52007-10-27 13:37:33 -04002154 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002155 return 0;
dea31012005-04-17 16:05:31 -05002156}
2157
James Smart09372822008-01-11 01:52:54 -05002158static int
James Smart87af33f2007-10-27 13:37:43 -04002159lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
2160{
2161 struct lpfc_dmabuf *buf_ptr;
2162
2163 /* Free the response before processing the command. */
2164 if (!list_empty(&buf_ptr1->list)) {
2165 list_remove_head(&buf_ptr1->list, buf_ptr,
2166 struct lpfc_dmabuf,
2167 list);
2168 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
2169 kfree(buf_ptr);
2170 }
2171 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
2172 kfree(buf_ptr1);
2173 return 0;
2174}
2175
James Smart09372822008-01-11 01:52:54 -05002176static int
James Smart87af33f2007-10-27 13:37:43 -04002177lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
2178{
2179 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
2180 kfree(buf_ptr);
2181 return 0;
2182}
2183
2184int
James Smart329f9bc2007-04-25 09:53:01 -04002185lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05002186{
2187 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
James Smarta8adb832007-10-27 13:37:53 -04002188 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05002189
James Smarta8adb832007-10-27 13:37:53 -04002190 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
2191 if (ndlp) {
2192 if (ndlp->nlp_flag & NLP_DEFER_RM) {
2193 lpfc_nlp_put(ndlp);
2194
2195 /* If the ndlp is not being used by another discovery
2196 * thread, free it.
2197 */
2198 if (!lpfc_nlp_not_used(ndlp)) {
2199 /* If ndlp is being used by another discovery
2200 * thread, just clear NLP_DEFER_RM
2201 */
2202 ndlp->nlp_flag &= ~NLP_DEFER_RM;
2203 }
2204 }
2205 else
2206 lpfc_nlp_put(ndlp);
James Smart329f9bc2007-04-25 09:53:01 -04002207 elsiocb->context1 = NULL;
2208 }
dea31012005-04-17 16:05:31 -05002209 /* context2 = cmd, context2->next = rsp, context3 = bpl */
2210 if (elsiocb->context2) {
James Smart0ff10d42008-01-11 01:52:36 -05002211 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
2212 /* Firmware could still be in progress of DMAing
2213 * payload, so don't free data buffer till after
2214 * a hbeat.
2215 */
2216 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
2217 buf_ptr = elsiocb->context2;
2218 elsiocb->context2 = NULL;
2219 if (buf_ptr) {
2220 buf_ptr1 = NULL;
2221 spin_lock_irq(&phba->hbalock);
2222 if (!list_empty(&buf_ptr->list)) {
2223 list_remove_head(&buf_ptr->list,
2224 buf_ptr1, struct lpfc_dmabuf,
2225 list);
2226 INIT_LIST_HEAD(&buf_ptr1->list);
2227 list_add_tail(&buf_ptr1->list,
2228 &phba->elsbuf);
2229 phba->elsbuf_cnt++;
2230 }
2231 INIT_LIST_HEAD(&buf_ptr->list);
2232 list_add_tail(&buf_ptr->list, &phba->elsbuf);
2233 phba->elsbuf_cnt++;
2234 spin_unlock_irq(&phba->hbalock);
2235 }
2236 } else {
2237 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
2238 lpfc_els_free_data(phba, buf_ptr1);
2239 }
dea31012005-04-17 16:05:31 -05002240 }
2241
2242 if (elsiocb->context3) {
2243 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
James Smart87af33f2007-10-27 13:37:43 -04002244 lpfc_els_free_bpl(phba, buf_ptr);
dea31012005-04-17 16:05:31 -05002245 }
James Bottomley604a3e32005-10-29 10:28:33 -05002246 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -05002247 return 0;
2248}
2249
2250static void
James Smart2e0fef82007-06-17 19:56:36 -05002251lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2252 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002253{
James Smart2e0fef82007-06-17 19:56:36 -05002254 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2255 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05002256 IOCB_t *irsp;
2257
2258 irsp = &rspiocb->iocb;
2259 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2260 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
2261 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05002262 /* ACC to LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002263 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2264 "0109 ACC to LOGO completes to NPort x%x "
2265 "Data: x%x x%x x%x\n",
2266 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2267 ndlp->nlp_rpi);
James Smart87af33f2007-10-27 13:37:43 -04002268
2269 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
2270 /* NPort Recovery mode or node is just allocated */
2271 if (!lpfc_nlp_not_used(ndlp)) {
2272 /* If the ndlp is being used by another discovery
2273 * thread, just unregister the RPI.
2274 */
2275 lpfc_unreg_rpi(vport, ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05002276 } else {
2277 /* Indicate the node has already released, should
2278 * not reference to it from within lpfc_els_free_iocb.
2279 */
2280 cmdiocb->context1 = NULL;
James Smart87af33f2007-10-27 13:37:43 -04002281 }
dea31012005-04-17 16:05:31 -05002282 }
2283 lpfc_els_free_iocb(phba, cmdiocb);
2284 return;
2285}
2286
James Smart858c9f62007-06-17 19:56:39 -05002287void
2288lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
2289{
2290 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
2291 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
2292
2293 pmb->context1 = NULL;
2294 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2295 kfree(mp);
2296 mempool_free(pmb, phba->mbox_mem_pool);
James Smarta8adb832007-10-27 13:37:53 -04002297 if (ndlp) {
2298 lpfc_nlp_put(ndlp);
James Smarta8adb832007-10-27 13:37:53 -04002299 /* This is the end of the default RPI cleanup logic for this
2300 * ndlp. If no other discovery threads are using this ndlp.
2301 * we should free all resources associated with it.
2302 */
2303 lpfc_nlp_not_used(ndlp);
2304 }
James Smart858c9f62007-06-17 19:56:39 -05002305 return;
2306}
2307
dea31012005-04-17 16:05:31 -05002308static void
James Smart858c9f62007-06-17 19:56:39 -05002309lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
James Smart329f9bc2007-04-25 09:53:01 -04002310 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002311{
James Smart2e0fef82007-06-17 19:56:36 -05002312 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2313 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
2314 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
James Smart87af33f2007-10-27 13:37:43 -04002315 IOCB_t *irsp;
2316 uint8_t *pcmd;
dea31012005-04-17 16:05:31 -05002317 LPFC_MBOXQ_t *mbox = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05002318 struct lpfc_dmabuf *mp = NULL;
James Smart87af33f2007-10-27 13:37:43 -04002319 uint32_t ls_rjt = 0;
dea31012005-04-17 16:05:31 -05002320
James Smart33ccf8d2006-08-17 11:57:58 -04002321 irsp = &rspiocb->iocb;
2322
dea31012005-04-17 16:05:31 -05002323 if (cmdiocb->context_un.mbox)
2324 mbox = cmdiocb->context_un.mbox;
2325
James Smartfa4066b2008-01-11 01:53:27 -05002326 /* First determine if this is a LS_RJT cmpl. Note, this callback
2327 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
2328 */
James Smart87af33f2007-10-27 13:37:43 -04002329 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
James Smartfa4066b2008-01-11 01:53:27 -05002330 if (ndlp && (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
2331 /* A LS_RJT associated with Default RPI cleanup has its own
2332 * seperate code path.
James Smart87af33f2007-10-27 13:37:43 -04002333 */
2334 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
2335 ls_rjt = 1;
2336 }
2337
dea31012005-04-17 16:05:31 -05002338 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002339 if (!ndlp || lpfc_els_chk_latt(vport)) {
dea31012005-04-17 16:05:31 -05002340 if (mbox) {
James Smart14691152006-12-02 13:34:28 -05002341 mp = (struct lpfc_dmabuf *) mbox->context1;
2342 if (mp) {
2343 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2344 kfree(mp);
2345 }
James Smart329f9bc2007-04-25 09:53:01 -04002346 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05002347 }
James Smart98c9ea52007-10-27 13:37:33 -04002348 if (ndlp && (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
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 the node has already 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 goto out;
2358 }
2359
James Smart858c9f62007-06-17 19:56:39 -05002360 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smart51ef4c22007-08-02 11:10:31 -04002361 "ELS rsp cmpl: status:x%x/x%x did:x%x",
James Smart858c9f62007-06-17 19:56:39 -05002362 irsp->ulpStatus, irsp->un.ulpWord[4],
James Smart51ef4c22007-08-02 11:10:31 -04002363 cmdiocb->iocb.un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05002364 /* ELS response tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04002365 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2366 "0110 ELS response tag x%x completes "
2367 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
2368 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
2369 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
2370 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2371 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05002372 if (mbox) {
2373 if ((rspiocb->iocb.ulpStatus == 0)
2374 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
James Smart2e0fef82007-06-17 19:56:36 -05002375 lpfc_unreg_rpi(vport, ndlp);
James Smarte47c9092008-02-08 18:49:26 -05002376 /* Increment reference count to ndlp to hold the
2377 * reference to ndlp for the callback function.
2378 */
James Smart329f9bc2007-04-25 09:53:01 -04002379 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05002380 mbox->vport = vport;
James Smart858c9f62007-06-17 19:56:39 -05002381 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
2382 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
2383 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
2384 }
2385 else {
2386 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
2387 ndlp->nlp_prev_state = ndlp->nlp_state;
2388 lpfc_nlp_set_state(vport, ndlp,
James Smart2e0fef82007-06-17 19:56:36 -05002389 NLP_STE_REG_LOGIN_ISSUE);
James Smart858c9f62007-06-17 19:56:39 -05002390 }
James Smart0b727fe2007-10-27 13:37:25 -04002391 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smarte47c9092008-02-08 18:49:26 -05002392 != MBX_NOT_FINISHED)
dea31012005-04-17 16:05:31 -05002393 goto out;
James Smarte47c9092008-02-08 18:49:26 -05002394 else
2395 /* Decrement the ndlp reference count we
2396 * set for this failed mailbox command.
2397 */
2398 lpfc_nlp_put(ndlp);
James Smart98c9ea52007-10-27 13:37:33 -04002399
2400 /* ELS rsp: Cannot issue reg_login for <NPortid> */
2401 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2402 "0138 ELS rsp: Cannot issue reg_login for x%x "
2403 "Data: x%x x%x x%x\n",
2404 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2405 ndlp->nlp_rpi);
2406
James Smartfa4066b2008-01-11 01:53:27 -05002407 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04002408 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05002409 /* Indicate node has already been released,
2410 * should not reference to it from within
2411 * the routine lpfc_els_free_iocb.
2412 */
2413 cmdiocb->context1 = NULL;
2414 }
dea31012005-04-17 16:05:31 -05002415 } else {
James Smart858c9f62007-06-17 19:56:39 -05002416 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
2417 if (!lpfc_error_lost_link(irsp) &&
2418 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
James Smartfa4066b2008-01-11 01:53:27 -05002419 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04002420 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05002421 /* Indicate node has already been
2422 * released, should not reference
2423 * to it from within the routine
2424 * lpfc_els_free_iocb.
2425 */
2426 cmdiocb->context1 = NULL;
2427 }
dea31012005-04-17 16:05:31 -05002428 }
2429 }
James Smart14691152006-12-02 13:34:28 -05002430 mp = (struct lpfc_dmabuf *) mbox->context1;
2431 if (mp) {
2432 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2433 kfree(mp);
2434 }
2435 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05002436 }
2437out:
2438 if (ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05002439 spin_lock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05002440 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
James Smart2e0fef82007-06-17 19:56:36 -05002441 spin_unlock_irq(shost->host_lock);
James Smart87af33f2007-10-27 13:37:43 -04002442
2443 /* If the node is not being used by another discovery thread,
2444 * and we are sending a reject, we are done with it.
2445 * Release driver reference count here and free associated
2446 * resources.
2447 */
2448 if (ls_rjt)
James Smartfa4066b2008-01-11 01:53:27 -05002449 if (lpfc_nlp_not_used(ndlp))
2450 /* Indicate node has already been released,
2451 * should not reference to it from within
2452 * the routine lpfc_els_free_iocb.
2453 */
2454 cmdiocb->context1 = NULL;
dea31012005-04-17 16:05:31 -05002455 }
James Smart87af33f2007-10-27 13:37:43 -04002456
dea31012005-04-17 16:05:31 -05002457 lpfc_els_free_iocb(phba, cmdiocb);
2458 return;
2459}
2460
2461int
James Smart2e0fef82007-06-17 19:56:36 -05002462lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
2463 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
James Smart51ef4c22007-08-02 11:10:31 -04002464 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05002465{
James Smart2e0fef82007-06-17 19:56:36 -05002466 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2467 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002468 IOCB_t *icmd;
2469 IOCB_t *oldcmd;
2470 struct lpfc_iocbq *elsiocb;
2471 struct lpfc_sli_ring *pring;
2472 struct lpfc_sli *psli;
2473 uint8_t *pcmd;
2474 uint16_t cmdsize;
2475 int rc;
James Smart82d9a2a2006-04-15 11:53:05 -04002476 ELS_PKT *els_pkt_ptr;
dea31012005-04-17 16:05:31 -05002477
2478 psli = &phba->sli;
2479 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2480 oldcmd = &oldiocb->iocb;
2481
2482 switch (flag) {
2483 case ELS_CMD_ACC:
James Smart92d7f7b2007-06-17 19:56:38 -05002484 cmdsize = sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05002485 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
2486 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05002487 if (!elsiocb) {
James Smart2e0fef82007-06-17 19:56:36 -05002488 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002489 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05002490 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002491 return 1;
dea31012005-04-17 16:05:31 -05002492 }
James Smart2e0fef82007-06-17 19:56:36 -05002493
dea31012005-04-17 16:05:31 -05002494 icmd = &elsiocb->iocb;
2495 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2496 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2497 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05002498 pcmd += sizeof(uint32_t);
James Smart858c9f62007-06-17 19:56:39 -05002499
2500 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2501 "Issue ACC: did:x%x flg:x%x",
2502 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05002503 break;
2504 case ELS_CMD_PLOGI:
James Smart92d7f7b2007-06-17 19:56:38 -05002505 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
James Smart2e0fef82007-06-17 19:56:36 -05002506 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
2507 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05002508 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002509 return 1;
James Smart488d1462006-03-07 15:02:37 -05002510
dea31012005-04-17 16:05:31 -05002511 icmd = &elsiocb->iocb;
2512 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2513 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2514
2515 if (mbox)
2516 elsiocb->context_un.mbox = mbox;
2517
2518 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05002519 pcmd += sizeof(uint32_t);
2520 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
James Smart858c9f62007-06-17 19:56:39 -05002521
2522 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2523 "Issue ACC PLOGI: did:x%x flg:x%x",
2524 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05002525 break;
James Smart82d9a2a2006-04-15 11:53:05 -04002526 case ELS_CMD_PRLO:
James Smart92d7f7b2007-06-17 19:56:38 -05002527 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
James Smart2e0fef82007-06-17 19:56:36 -05002528 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
James Smart82d9a2a2006-04-15 11:53:05 -04002529 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
2530 if (!elsiocb)
2531 return 1;
2532
2533 icmd = &elsiocb->iocb;
2534 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2535 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2536
2537 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
James Smart92d7f7b2007-06-17 19:56:38 -05002538 sizeof(uint32_t) + sizeof(PRLO));
James Smart82d9a2a2006-04-15 11:53:05 -04002539 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
2540 els_pkt_ptr = (ELS_PKT *) pcmd;
2541 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
James Smart858c9f62007-06-17 19:56:39 -05002542
2543 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2544 "Issue ACC PRLO: did:x%x flg:x%x",
2545 ndlp->nlp_DID, ndlp->nlp_flag, 0);
James Smart82d9a2a2006-04-15 11:53:05 -04002546 break;
dea31012005-04-17 16:05:31 -05002547 default:
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002548 return 1;
dea31012005-04-17 16:05:31 -05002549 }
dea31012005-04-17 16:05:31 -05002550 /* Xmit ELS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04002551 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2552 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
2553 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n",
2554 elsiocb->iotag, elsiocb->iocb.ulpContext,
2555 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2556 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05002557 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
James Smart2e0fef82007-06-17 19:56:36 -05002558 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002559 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05002560 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002561 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
2562 } else {
James Smart858c9f62007-06-17 19:56:39 -05002563 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05002564 }
2565
2566 phba->fc_stat.elsXmitACC++;
dea31012005-04-17 16:05:31 -05002567 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
dea31012005-04-17 16:05:31 -05002568 if (rc == IOCB_ERROR) {
2569 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002570 return 1;
dea31012005-04-17 16:05:31 -05002571 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002572 return 0;
dea31012005-04-17 16:05:31 -05002573}
2574
2575int
James Smart2e0fef82007-06-17 19:56:36 -05002576lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
James Smart858c9f62007-06-17 19:56:39 -05002577 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
2578 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05002579{
James Smart2e0fef82007-06-17 19:56:36 -05002580 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002581 IOCB_t *icmd;
2582 IOCB_t *oldcmd;
2583 struct lpfc_iocbq *elsiocb;
2584 struct lpfc_sli_ring *pring;
2585 struct lpfc_sli *psli;
2586 uint8_t *pcmd;
2587 uint16_t cmdsize;
2588 int rc;
2589
2590 psli = &phba->sli;
2591 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2592
James Smart92d7f7b2007-06-17 19:56:38 -05002593 cmdsize = 2 * sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05002594 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
2595 ndlp->nlp_DID, ELS_CMD_LS_RJT);
James Smart488d1462006-03-07 15:02:37 -05002596 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002597 return 1;
dea31012005-04-17 16:05:31 -05002598
2599 icmd = &elsiocb->iocb;
2600 oldcmd = &oldiocb->iocb;
2601 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2602 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2603
2604 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
James Smart92d7f7b2007-06-17 19:56:38 -05002605 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002606 *((uint32_t *) (pcmd)) = rejectError;
2607
James Smart51ef4c22007-08-02 11:10:31 -04002608 if (mbox)
James Smart858c9f62007-06-17 19:56:39 -05002609 elsiocb->context_un.mbox = mbox;
James Smart858c9f62007-06-17 19:56:39 -05002610
dea31012005-04-17 16:05:31 -05002611 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04002612 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2613 "0129 Xmit ELS RJT x%x response tag x%x "
2614 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
2615 "rpi x%x\n",
2616 rejectError, elsiocb->iotag,
2617 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
2618 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05002619 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2620 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
2621 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
2622
dea31012005-04-17 16:05:31 -05002623 phba->fc_stat.elsXmitLSRJT++;
James Smart858c9f62007-06-17 19:56:39 -05002624 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05002625 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
James Smart51ef4c22007-08-02 11:10:31 -04002626
dea31012005-04-17 16:05:31 -05002627 if (rc == IOCB_ERROR) {
2628 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002629 return 1;
dea31012005-04-17 16:05:31 -05002630 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002631 return 0;
dea31012005-04-17 16:05:31 -05002632}
2633
2634int
James Smart2e0fef82007-06-17 19:56:36 -05002635lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
2636 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05002637{
James Smart2e0fef82007-06-17 19:56:36 -05002638 struct lpfc_hba *phba = vport->phba;
2639 struct lpfc_sli *psli = &phba->sli;
2640 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05002641 ADISC *ap;
James Smart2e0fef82007-06-17 19:56:36 -05002642 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05002643 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002644 uint8_t *pcmd;
2645 uint16_t cmdsize;
2646 int rc;
2647
James Smart92d7f7b2007-06-17 19:56:38 -05002648 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
James Smart2e0fef82007-06-17 19:56:36 -05002649 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
2650 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05002651 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002652 return 1;
dea31012005-04-17 16:05:31 -05002653
dea31012005-04-17 16:05:31 -05002654 icmd = &elsiocb->iocb;
2655 oldcmd = &oldiocb->iocb;
2656 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04002657
2658 /* Xmit ADISC ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04002659 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2660 "0130 Xmit ADISC ACC response iotag x%x xri: "
2661 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
2662 elsiocb->iotag, elsiocb->iocb.ulpContext,
2663 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2664 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05002665 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2666
2667 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05002668 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002669
2670 ap = (ADISC *) (pcmd);
2671 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05002672 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2673 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002674 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002675
James Smart858c9f62007-06-17 19:56:39 -05002676 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2677 "Issue ACC ADISC: did:x%x flg:x%x",
2678 ndlp->nlp_DID, ndlp->nlp_flag, 0);
2679
dea31012005-04-17 16:05:31 -05002680 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05002681 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05002682 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
dea31012005-04-17 16:05:31 -05002683 if (rc == IOCB_ERROR) {
2684 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002685 return 1;
dea31012005-04-17 16:05:31 -05002686 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002687 return 0;
dea31012005-04-17 16:05:31 -05002688}
2689
2690int
James Smart2e0fef82007-06-17 19:56:36 -05002691lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
James Smart5b8bd0c2007-04-25 09:52:49 -04002692 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05002693{
James Smart2e0fef82007-06-17 19:56:36 -05002694 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002695 PRLI *npr;
2696 lpfc_vpd_t *vpd;
2697 IOCB_t *icmd;
2698 IOCB_t *oldcmd;
2699 struct lpfc_iocbq *elsiocb;
2700 struct lpfc_sli_ring *pring;
2701 struct lpfc_sli *psli;
2702 uint8_t *pcmd;
2703 uint16_t cmdsize;
2704 int rc;
2705
2706 psli = &phba->sli;
2707 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2708
James Smart92d7f7b2007-06-17 19:56:38 -05002709 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
James Smart2e0fef82007-06-17 19:56:36 -05002710 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
James Smart92d7f7b2007-06-17 19:56:38 -05002711 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002712 if (!elsiocb)
2713 return 1;
dea31012005-04-17 16:05:31 -05002714
dea31012005-04-17 16:05:31 -05002715 icmd = &elsiocb->iocb;
2716 oldcmd = &oldiocb->iocb;
2717 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04002718 /* Xmit PRLI ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04002719 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2720 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
2721 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
2722 elsiocb->iotag, elsiocb->iocb.ulpContext,
2723 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2724 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05002725 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2726
2727 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
James Smart92d7f7b2007-06-17 19:56:38 -05002728 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002729
2730 /* For PRLI, remainder of payload is PRLI parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05002731 memset(pcmd, 0, sizeof(PRLI));
dea31012005-04-17 16:05:31 -05002732
2733 npr = (PRLI *) pcmd;
2734 vpd = &phba->vpd;
2735 /*
2736 * If our firmware version is 3.20 or later,
2737 * set the following bits for FC-TAPE support.
2738 */
2739 if (vpd->rev.feaLevelHigh >= 0x02) {
2740 npr->ConfmComplAllowed = 1;
2741 npr->Retry = 1;
2742 npr->TaskRetryIdReq = 1;
2743 }
2744
2745 npr->acceptRspCode = PRLI_REQ_EXECUTED;
2746 npr->estabImagePair = 1;
2747 npr->readXferRdyDis = 1;
2748 npr->ConfmComplAllowed = 1;
2749
2750 npr->prliType = PRLI_FCP_TYPE;
2751 npr->initiatorFunc = 1;
2752
James Smart858c9f62007-06-17 19:56:39 -05002753 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2754 "Issue ACC PRLI: did:x%x flg:x%x",
2755 ndlp->nlp_DID, ndlp->nlp_flag, 0);
2756
dea31012005-04-17 16:05:31 -05002757 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05002758 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05002759
dea31012005-04-17 16:05:31 -05002760 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
dea31012005-04-17 16:05:31 -05002761 if (rc == IOCB_ERROR) {
2762 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002763 return 1;
dea31012005-04-17 16:05:31 -05002764 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002765 return 0;
dea31012005-04-17 16:05:31 -05002766}
2767
2768static int
James Smart2e0fef82007-06-17 19:56:36 -05002769lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
James Smart329f9bc2007-04-25 09:53:01 -04002770 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05002771{
James Smart2e0fef82007-06-17 19:56:36 -05002772 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002773 RNID *rn;
James Smart2e0fef82007-06-17 19:56:36 -05002774 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05002775 struct lpfc_iocbq *elsiocb;
2776 struct lpfc_sli_ring *pring;
2777 struct lpfc_sli *psli;
2778 uint8_t *pcmd;
2779 uint16_t cmdsize;
2780 int rc;
2781
2782 psli = &phba->sli;
2783 pring = &psli->ring[LPFC_ELS_RING];
2784
James Smart92d7f7b2007-06-17 19:56:38 -05002785 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
2786 + (2 * sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002787 if (format)
James Smart92d7f7b2007-06-17 19:56:38 -05002788 cmdsize += sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05002789
James Smart2e0fef82007-06-17 19:56:36 -05002790 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
2791 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05002792 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002793 return 1;
dea31012005-04-17 16:05:31 -05002794
dea31012005-04-17 16:05:31 -05002795 icmd = &elsiocb->iocb;
2796 oldcmd = &oldiocb->iocb;
2797 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04002798 /* Xmit RNID ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04002799 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2800 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
2801 elsiocb->iotag, elsiocb->iocb.ulpContext);
dea31012005-04-17 16:05:31 -05002802 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
dea31012005-04-17 16:05:31 -05002803 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05002804 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002805
James Smart92d7f7b2007-06-17 19:56:38 -05002806 memset(pcmd, 0, sizeof(RNID));
dea31012005-04-17 16:05:31 -05002807 rn = (RNID *) (pcmd);
2808 rn->Format = format;
James Smart92d7f7b2007-06-17 19:56:38 -05002809 rn->CommonLen = (2 * sizeof(struct lpfc_name));
2810 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2811 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002812 switch (format) {
2813 case 0:
2814 rn->SpecificLen = 0;
2815 break;
2816 case RNID_TOPOLOGY_DISC:
James Smart92d7f7b2007-06-17 19:56:38 -05002817 rn->SpecificLen = sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05002818 memcpy(&rn->un.topologyDisc.portName,
James Smart92d7f7b2007-06-17 19:56:38 -05002819 &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002820 rn->un.topologyDisc.unitType = RNID_HBA;
2821 rn->un.topologyDisc.physPort = 0;
2822 rn->un.topologyDisc.attachedNodes = 0;
2823 break;
2824 default:
2825 rn->CommonLen = 0;
2826 rn->SpecificLen = 0;
2827 break;
2828 }
2829
James Smart858c9f62007-06-17 19:56:39 -05002830 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2831 "Issue ACC RNID: did:x%x flg:x%x",
2832 ndlp->nlp_DID, ndlp->nlp_flag, 0);
2833
dea31012005-04-17 16:05:31 -05002834 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05002835 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart329f9bc2007-04-25 09:53:01 -04002836 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002837 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
2838 * it could be freed */
2839
dea31012005-04-17 16:05:31 -05002840 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
dea31012005-04-17 16:05:31 -05002841 if (rc == IOCB_ERROR) {
2842 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002843 return 1;
dea31012005-04-17 16:05:31 -05002844 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002845 return 0;
dea31012005-04-17 16:05:31 -05002846}
2847
2848int
James Smart2e0fef82007-06-17 19:56:36 -05002849lpfc_els_disc_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002850{
James Smart2e0fef82007-06-17 19:56:36 -05002851 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002852 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05002853 int sentadisc = 0;
dea31012005-04-17 16:05:31 -05002854
James Smart685f0bf2007-04-25 09:53:08 -04002855 /* go thru NPR nodes and issue any remaining ELS ADISCs */
James Smart2e0fef82007-06-17 19:56:36 -05002856 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05002857 if (!NLP_CHK_NODE_ACT(ndlp))
2858 continue;
James Smart685f0bf2007-04-25 09:53:08 -04002859 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
2860 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
2861 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
James Smart2e0fef82007-06-17 19:56:36 -05002862 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04002863 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05002864 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04002865 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002866 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2867 lpfc_issue_els_adisc(vport, ndlp, 0);
James Smart685f0bf2007-04-25 09:53:08 -04002868 sentadisc++;
James Smart2e0fef82007-06-17 19:56:36 -05002869 vport->num_disc_nodes++;
2870 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04002871 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05002872 spin_lock_irq(shost->host_lock);
2873 vport->fc_flag |= FC_NLP_MORE;
2874 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04002875 break;
dea31012005-04-17 16:05:31 -05002876 }
2877 }
2878 }
2879 if (sentadisc == 0) {
James Smart2e0fef82007-06-17 19:56:36 -05002880 spin_lock_irq(shost->host_lock);
2881 vport->fc_flag &= ~FC_NLP_MORE;
2882 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002883 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002884 return sentadisc;
dea31012005-04-17 16:05:31 -05002885}
2886
2887int
James Smart2e0fef82007-06-17 19:56:36 -05002888lpfc_els_disc_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002889{
James Smart2e0fef82007-06-17 19:56:36 -05002890 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002891 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05002892 int sentplogi = 0;
dea31012005-04-17 16:05:31 -05002893
James Smart2e0fef82007-06-17 19:56:36 -05002894 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
2895 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05002896 if (!NLP_CHK_NODE_ACT(ndlp))
2897 continue;
James Smart685f0bf2007-04-25 09:53:08 -04002898 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
2899 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
2900 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
2901 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
2902 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002903 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2904 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
James Smart685f0bf2007-04-25 09:53:08 -04002905 sentplogi++;
James Smart2e0fef82007-06-17 19:56:36 -05002906 vport->num_disc_nodes++;
2907 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04002908 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05002909 spin_lock_irq(shost->host_lock);
2910 vport->fc_flag |= FC_NLP_MORE;
2911 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04002912 break;
dea31012005-04-17 16:05:31 -05002913 }
2914 }
2915 }
James Smart87af33f2007-10-27 13:37:43 -04002916 if (sentplogi) {
2917 lpfc_set_disctmo(vport);
2918 }
2919 else {
James Smart2e0fef82007-06-17 19:56:36 -05002920 spin_lock_irq(shost->host_lock);
2921 vport->fc_flag &= ~FC_NLP_MORE;
2922 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002923 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002924 return sentplogi;
dea31012005-04-17 16:05:31 -05002925}
2926
James Smart92d7f7b2007-06-17 19:56:38 -05002927void
James Smart2e0fef82007-06-17 19:56:36 -05002928lpfc_els_flush_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002929{
James Smart2e0fef82007-06-17 19:56:36 -05002930 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2931 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002932 int i;
2933
James Smart2e0fef82007-06-17 19:56:36 -05002934 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05002935 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
James Smart2e0fef82007-06-17 19:56:36 -05002936 vport->fc_rscn_id_list[i] = NULL;
dea31012005-04-17 16:05:31 -05002937 }
James Smart2e0fef82007-06-17 19:56:36 -05002938 spin_lock_irq(shost->host_lock);
2939 vport->fc_rscn_id_cnt = 0;
2940 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
2941 spin_unlock_irq(shost->host_lock);
2942 lpfc_can_disctmo(vport);
dea31012005-04-17 16:05:31 -05002943}
2944
2945int
James Smart2e0fef82007-06-17 19:56:36 -05002946lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05002947{
2948 D_ID ns_did;
2949 D_ID rscn_did;
dea31012005-04-17 16:05:31 -05002950 uint32_t *lp;
James Smart92d7f7b2007-06-17 19:56:38 -05002951 uint32_t payload_len, i;
dea31012005-04-17 16:05:31 -05002952
2953 ns_did.un.word = did;
dea31012005-04-17 16:05:31 -05002954
2955 /* Never match fabric nodes for RSCNs */
2956 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
James Smart2e0fef82007-06-17 19:56:36 -05002957 return 0;
dea31012005-04-17 16:05:31 -05002958
2959 /* If we are doing a FULL RSCN rediscovery, match everything */
James Smart2e0fef82007-06-17 19:56:36 -05002960 if (vport->fc_flag & FC_RSCN_DISCOVERY)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002961 return did;
dea31012005-04-17 16:05:31 -05002962
James Smart2e0fef82007-06-17 19:56:36 -05002963 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05002964 lp = vport->fc_rscn_id_list[i]->virt;
2965 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
2966 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05002967 while (payload_len) {
James Smart92d7f7b2007-06-17 19:56:38 -05002968 rscn_did.un.word = be32_to_cpu(*lp++);
2969 payload_len -= sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002970 switch (rscn_did.un.b.resv) {
2971 case 0: /* Single N_Port ID effected */
James Smart2e0fef82007-06-17 19:56:36 -05002972 if (ns_did.un.word == rscn_did.un.word)
James Smart92d7f7b2007-06-17 19:56:38 -05002973 return did;
dea31012005-04-17 16:05:31 -05002974 break;
2975 case 1: /* Whole N_Port Area effected */
2976 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
2977 && (ns_did.un.b.area == rscn_did.un.b.area))
James Smart92d7f7b2007-06-17 19:56:38 -05002978 return did;
dea31012005-04-17 16:05:31 -05002979 break;
2980 case 2: /* Whole N_Port Domain effected */
2981 if (ns_did.un.b.domain == rscn_did.un.b.domain)
James Smart92d7f7b2007-06-17 19:56:38 -05002982 return did;
dea31012005-04-17 16:05:31 -05002983 break;
2984 default:
James Smart2e0fef82007-06-17 19:56:36 -05002985 /* Unknown Identifier in RSCN node */
James Smarte8b62012007-08-02 11:10:09 -04002986 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
2987 "0217 Unknown Identifier in "
2988 "RSCN payload Data: x%x\n",
2989 rscn_did.un.word);
James Smart92d7f7b2007-06-17 19:56:38 -05002990 case 3: /* Whole Fabric effected */
2991 return did;
dea31012005-04-17 16:05:31 -05002992 }
2993 }
James Smart92d7f7b2007-06-17 19:56:38 -05002994 }
2995 return 0;
dea31012005-04-17 16:05:31 -05002996}
2997
2998static int
James Smart2e0fef82007-06-17 19:56:36 -05002999lpfc_rscn_recovery_check(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003000{
James Smart685f0bf2007-04-25 09:53:08 -04003001 struct lpfc_nodelist *ndlp = NULL;
dea31012005-04-17 16:05:31 -05003002
3003 /* Look at all nodes effected by pending RSCNs and move
James Smart685f0bf2007-04-25 09:53:08 -04003004 * them to NPR state.
dea31012005-04-17 16:05:31 -05003005 */
James Smart685f0bf2007-04-25 09:53:08 -04003006
James Smart2e0fef82007-06-17 19:56:36 -05003007 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05003008 if (!NLP_CHK_NODE_ACT(ndlp) ||
3009 ndlp->nlp_state == NLP_STE_UNUSED_NODE ||
James Smart2e0fef82007-06-17 19:56:36 -05003010 lpfc_rscn_payload_check(vport, ndlp->nlp_DID) == 0)
dea31012005-04-17 16:05:31 -05003011 continue;
3012
James Smart2e0fef82007-06-17 19:56:36 -05003013 lpfc_disc_state_machine(vport, ndlp, NULL,
James Smart92d7f7b2007-06-17 19:56:38 -05003014 NLP_EVT_DEVICE_RECOVERY);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003015
James Smart685f0bf2007-04-25 09:53:08 -04003016 /*
3017 * Make sure NLP_DELAY_TMO is NOT running after a device
3018 * recovery event.
3019 */
3020 if (ndlp->nlp_flag & NLP_DELAY_TMO)
James Smart2e0fef82007-06-17 19:56:36 -05003021 lpfc_cancel_retry_delay_tmo(vport, ndlp);
dea31012005-04-17 16:05:31 -05003022 }
James Smart685f0bf2007-04-25 09:53:08 -04003023
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003024 return 0;
dea31012005-04-17 16:05:31 -05003025}
3026
3027static int
James Smart2e0fef82007-06-17 19:56:36 -05003028lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04003029 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003030{
James Smart2e0fef82007-06-17 19:56:36 -05003031 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3032 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003033 struct lpfc_dmabuf *pcmd;
James Smart92d7f7b2007-06-17 19:56:38 -05003034 uint32_t *lp, *datap;
dea31012005-04-17 16:05:31 -05003035 IOCB_t *icmd;
James Smart92d7f7b2007-06-17 19:56:38 -05003036 uint32_t payload_len, length, nportid, *cmd;
3037 int rscn_cnt = vport->fc_rscn_id_cnt;
3038 int rscn_id = 0, hba_id = 0;
James Smartd2873e42006-08-18 17:46:43 -04003039 int i;
dea31012005-04-17 16:05:31 -05003040
3041 icmd = &cmdiocb->iocb;
3042 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3043 lp = (uint32_t *) pcmd->virt;
3044
James Smart92d7f7b2007-06-17 19:56:38 -05003045 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
3046 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05003047 /* RSCN received */
James Smarte8b62012007-08-02 11:10:09 -04003048 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3049 "0214 RSCN received Data: x%x x%x x%x x%x\n",
3050 vport->fc_flag, payload_len, *lp, rscn_cnt);
James Smartd2873e42006-08-18 17:46:43 -04003051 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
James Smart2e0fef82007-06-17 19:56:36 -05003052 fc_host_post_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04003053 FCH_EVT_RSCN, lp[i]);
3054
dea31012005-04-17 16:05:31 -05003055 /* If we are about to begin discovery, just ACC the RSCN.
3056 * Discovery processing will satisfy it.
3057 */
James Smart2e0fef82007-06-17 19:56:36 -05003058 if (vport->port_state <= LPFC_NS_QRY) {
James Smart858c9f62007-06-17 19:56:39 -05003059 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3060 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
3061 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
3062
James Smart51ef4c22007-08-02 11:10:31 -04003063 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003064 return 0;
dea31012005-04-17 16:05:31 -05003065 }
3066
James Smart92d7f7b2007-06-17 19:56:38 -05003067 /* If this RSCN just contains NPortIDs for other vports on this HBA,
3068 * just ACC and ignore it.
3069 */
3070 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart3de2a652007-08-02 11:09:59 -04003071 !(vport->cfg_peer_port_login)) {
James Smart92d7f7b2007-06-17 19:56:38 -05003072 i = payload_len;
3073 datap = lp;
3074 while (i > 0) {
3075 nportid = *datap++;
3076 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
3077 i -= sizeof(uint32_t);
3078 rscn_id++;
James Smart549e55c2007-08-02 11:09:51 -04003079 if (lpfc_find_vport_by_did(phba, nportid))
3080 hba_id++;
James Smart92d7f7b2007-06-17 19:56:38 -05003081 }
3082 if (rscn_id == hba_id) {
3083 /* ALL NPortIDs in RSCN are on HBA */
James Smarte8b62012007-08-02 11:10:09 -04003084 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3085 "0214 Ignore RSCN "
3086 "Data: x%x x%x x%x x%x\n",
3087 vport->fc_flag, payload_len,
3088 *lp, rscn_cnt);
James Smart858c9f62007-06-17 19:56:39 -05003089 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3090 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
3091 ndlp->nlp_DID, vport->port_state,
3092 ndlp->nlp_flag);
3093
James Smart92d7f7b2007-06-17 19:56:38 -05003094 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04003095 ndlp, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05003096 return 0;
3097 }
3098 }
3099
dea31012005-04-17 16:05:31 -05003100 /* If we are already processing an RSCN, save the received
3101 * RSCN payload buffer, cmdiocb->context2 to process later.
3102 */
James Smart2e0fef82007-06-17 19:56:36 -05003103 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
James Smart858c9f62007-06-17 19:56:39 -05003104 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3105 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
3106 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
3107
James Smart09372822008-01-11 01:52:54 -05003108 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05003109 vport->fc_flag |= FC_RSCN_DEFERRED;
3110 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
James Smart2e0fef82007-06-17 19:56:36 -05003111 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
James Smart2e0fef82007-06-17 19:56:36 -05003112 vport->fc_flag |= FC_RSCN_MODE;
3113 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05003114 if (rscn_cnt) {
3115 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
3116 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
3117 }
3118 if ((rscn_cnt) &&
3119 (payload_len + length <= LPFC_BPL_SIZE)) {
3120 *cmd &= ELS_CMD_MASK;
3121 *cmd |= be32_to_cpu(payload_len + length);
3122 memcpy(((uint8_t *)cmd) + length, lp,
3123 payload_len);
3124 } else {
3125 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
3126 vport->fc_rscn_id_cnt++;
3127 /* If we zero, cmdiocb->context2, the calling
3128 * routine will not try to free it.
3129 */
3130 cmdiocb->context2 = NULL;
3131 }
dea31012005-04-17 16:05:31 -05003132
3133 /* Deferred RSCN */
James Smarte8b62012007-08-02 11:10:09 -04003134 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3135 "0235 Deferred RSCN "
3136 "Data: x%x x%x x%x\n",
3137 vport->fc_rscn_id_cnt, vport->fc_flag,
3138 vport->port_state);
dea31012005-04-17 16:05:31 -05003139 } else {
James Smart2e0fef82007-06-17 19:56:36 -05003140 vport->fc_flag |= FC_RSCN_DISCOVERY;
3141 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003142 /* ReDiscovery RSCN */
James Smarte8b62012007-08-02 11:10:09 -04003143 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3144 "0234 ReDiscovery RSCN "
3145 "Data: x%x x%x x%x\n",
3146 vport->fc_rscn_id_cnt, vport->fc_flag,
3147 vport->port_state);
dea31012005-04-17 16:05:31 -05003148 }
3149 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04003150 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05003151
3152 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05003153 lpfc_rscn_recovery_check(vport);
James Smart09372822008-01-11 01:52:54 -05003154 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05003155 vport->fc_flag &= ~FC_RSCN_DEFERRED;
James Smart09372822008-01-11 01:52:54 -05003156 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003157 return 0;
dea31012005-04-17 16:05:31 -05003158 }
3159
James Smart858c9f62007-06-17 19:56:39 -05003160 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3161 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
3162 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
3163
James Smart2e0fef82007-06-17 19:56:36 -05003164 spin_lock_irq(shost->host_lock);
3165 vport->fc_flag |= FC_RSCN_MODE;
3166 spin_unlock_irq(shost->host_lock);
3167 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
dea31012005-04-17 16:05:31 -05003168 /*
3169 * If we zero, cmdiocb->context2, the calling routine will
3170 * not try to free it.
3171 */
3172 cmdiocb->context2 = NULL;
3173
James Smart2e0fef82007-06-17 19:56:36 -05003174 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05003175
3176 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04003177 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05003178
3179 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05003180 lpfc_rscn_recovery_check(vport);
dea31012005-04-17 16:05:31 -05003181
James Smart2e0fef82007-06-17 19:56:36 -05003182 return lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05003183}
3184
3185int
James Smart2e0fef82007-06-17 19:56:36 -05003186lpfc_els_handle_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003187{
3188 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05003189 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003190
James Smart92d7f7b2007-06-17 19:56:38 -05003191 /* Ignore RSCN if the port is being torn down. */
3192 if (vport->load_flag & FC_UNLOADING) {
3193 lpfc_els_flush_rscn(vport);
3194 return 0;
3195 }
3196
dea31012005-04-17 16:05:31 -05003197 /* Start timer for RSCN processing */
James Smart2e0fef82007-06-17 19:56:36 -05003198 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05003199
3200 /* RSCN processed */
James Smarte8b62012007-08-02 11:10:09 -04003201 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3202 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
3203 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
3204 vport->port_state);
dea31012005-04-17 16:05:31 -05003205
3206 /* To process RSCN, first compare RSCN data with NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05003207 vport->fc_ns_retry = 0;
James Smart0ff10d42008-01-11 01:52:36 -05003208 vport->num_disc_nodes = 0;
3209
James Smart2e0fef82007-06-17 19:56:36 -05003210 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05003211 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
3212 && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
dea31012005-04-17 16:05:31 -05003213 /* Good ndlp, issue CT Request to NameServer */
James Smart92d7f7b2007-06-17 19:56:38 -05003214 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
dea31012005-04-17 16:05:31 -05003215 /* Wait for NameServer query cmpl before we can
3216 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003217 return 1;
dea31012005-04-17 16:05:31 -05003218 } else {
3219 /* If login to NameServer does not exist, issue one */
3220 /* Good status, issue PLOGI to NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05003221 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05003222 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
dea31012005-04-17 16:05:31 -05003223 /* Wait for NameServer login cmpl before we can
3224 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003225 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05003226
James Smarte47c9092008-02-08 18:49:26 -05003227 if (ndlp) {
3228 ndlp = lpfc_enable_node(vport, ndlp,
3229 NLP_STE_PLOGI_ISSUE);
3230 if (!ndlp) {
3231 lpfc_els_flush_rscn(vport);
3232 return 0;
3233 }
3234 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
dea31012005-04-17 16:05:31 -05003235 } else {
James Smarte47c9092008-02-08 18:49:26 -05003236 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
3237 if (!ndlp) {
3238 lpfc_els_flush_rscn(vport);
3239 return 0;
3240 }
James Smart2e0fef82007-06-17 19:56:36 -05003241 lpfc_nlp_init(vport, ndlp, NameServer_DID);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003242 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003243 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
dea31012005-04-17 16:05:31 -05003244 }
James Smarte47c9092008-02-08 18:49:26 -05003245 ndlp->nlp_type |= NLP_FABRIC;
3246 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
3247 /* Wait for NameServer login cmpl before we can
3248 * continue
3249 */
3250 return 1;
dea31012005-04-17 16:05:31 -05003251 }
3252
James Smart2e0fef82007-06-17 19:56:36 -05003253 lpfc_els_flush_rscn(vport);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003254 return 0;
dea31012005-04-17 16:05:31 -05003255}
3256
3257static int
James Smart2e0fef82007-06-17 19:56:36 -05003258lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04003259 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003260{
James Smart2e0fef82007-06-17 19:56:36 -05003261 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3262 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003263 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3264 uint32_t *lp = (uint32_t *) pcmd->virt;
3265 IOCB_t *icmd = &cmdiocb->iocb;
3266 struct serv_parm *sp;
3267 LPFC_MBOXQ_t *mbox;
3268 struct ls_rjt stat;
3269 uint32_t cmd, did;
3270 int rc;
3271
3272 cmd = *lp++;
3273 sp = (struct serv_parm *) lp;
3274
3275 /* FLOGI received */
3276
James Smart2e0fef82007-06-17 19:56:36 -05003277 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05003278
3279 if (phba->fc_topology == TOPOLOGY_LOOP) {
3280 /* We should never receive a FLOGI in loop mode, ignore it */
3281 did = icmd->un.elsreq64.remoteID;
3282
3283 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
3284 Loop Mode */
James Smarte8b62012007-08-02 11:10:09 -04003285 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3286 "0113 An FLOGI ELS command x%x was "
3287 "received from DID x%x in Loop Mode\n",
3288 cmd, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003289 return 1;
dea31012005-04-17 16:05:31 -05003290 }
3291
3292 did = Fabric_DID;
3293
James Smart2e0fef82007-06-17 19:56:36 -05003294 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3))) {
dea31012005-04-17 16:05:31 -05003295 /* For a FLOGI we accept, then if our portname is greater
3296 * then the remote portname we initiate Nport login.
3297 */
3298
James Smart2e0fef82007-06-17 19:56:36 -05003299 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -05003300 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003301
3302 if (!rc) {
James Smart2e0fef82007-06-17 19:56:36 -05003303 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3304 if (!mbox)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003305 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05003306
dea31012005-04-17 16:05:31 -05003307 lpfc_linkdown(phba);
3308 lpfc_init_link(phba, mbox,
3309 phba->cfg_topology,
3310 phba->cfg_link_speed);
3311 mbox->mb.un.varInitLnk.lipsr_AL_PA = 0;
3312 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -05003313 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -04003314 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart5b8bd0c2007-04-25 09:52:49 -04003315 lpfc_set_loopback_flag(phba);
dea31012005-04-17 16:05:31 -05003316 if (rc == MBX_NOT_FINISHED) {
James Smart329f9bc2007-04-25 09:53:01 -04003317 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003318 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003319 return 1;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003320 } else if (rc > 0) { /* greater than */
James Smart2e0fef82007-06-17 19:56:36 -05003321 spin_lock_irq(shost->host_lock);
3322 vport->fc_flag |= FC_PT2PT_PLOGI;
3323 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003324 }
James Smart2e0fef82007-06-17 19:56:36 -05003325 spin_lock_irq(shost->host_lock);
3326 vport->fc_flag |= FC_PT2PT;
3327 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
3328 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003329 } else {
3330 /* Reject this request because invalid parameters */
3331 stat.un.b.lsRjtRsvd0 = 0;
3332 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3333 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
3334 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05003335 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
3336 NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003337 return 1;
dea31012005-04-17 16:05:31 -05003338 }
3339
3340 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04003341 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05003342
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003343 return 0;
dea31012005-04-17 16:05:31 -05003344}
3345
3346static int
James Smart2e0fef82007-06-17 19:56:36 -05003347lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3348 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003349{
3350 struct lpfc_dmabuf *pcmd;
3351 uint32_t *lp;
3352 IOCB_t *icmd;
3353 RNID *rn;
3354 struct ls_rjt stat;
3355 uint32_t cmd, did;
3356
3357 icmd = &cmdiocb->iocb;
3358 did = icmd->un.elsreq64.remoteID;
3359 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3360 lp = (uint32_t *) pcmd->virt;
3361
3362 cmd = *lp++;
3363 rn = (RNID *) lp;
3364
3365 /* RNID received */
3366
3367 switch (rn->Format) {
3368 case 0:
3369 case RNID_TOPOLOGY_DISC:
3370 /* Send back ACC */
James Smart2e0fef82007-06-17 19:56:36 -05003371 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05003372 break;
3373 default:
3374 /* Reject this request because format not supported */
3375 stat.un.b.lsRjtRsvd0 = 0;
3376 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3377 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
3378 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05003379 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
3380 NULL);
dea31012005-04-17 16:05:31 -05003381 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003382 return 0;
dea31012005-04-17 16:05:31 -05003383}
3384
3385static int
James Smart2e0fef82007-06-17 19:56:36 -05003386lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3387 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003388{
3389 struct ls_rjt stat;
3390
3391 /* For now, unconditionally reject this command */
3392 stat.un.b.lsRjtRsvd0 = 0;
3393 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3394 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
3395 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05003396 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003397 return 0;
3398}
3399
Jamie Wellnitz082c0262006-02-28 19:25:30 -05003400static void
James Smart329f9bc2007-04-25 09:53:01 -04003401lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003402{
James Smart2e0fef82007-06-17 19:56:36 -05003403 struct lpfc_sli *psli = &phba->sli;
3404 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003405 MAILBOX_t *mb;
3406 IOCB_t *icmd;
3407 RPS_RSP *rps_rsp;
3408 uint8_t *pcmd;
3409 struct lpfc_iocbq *elsiocb;
3410 struct lpfc_nodelist *ndlp;
3411 uint16_t xri, status;
3412 uint32_t cmdsize;
3413
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003414 mb = &pmb->mb;
3415
3416 ndlp = (struct lpfc_nodelist *) pmb->context2;
3417 xri = (uint16_t) ((unsigned long)(pmb->context1));
Randy Dunlap041976f2006-06-25 01:58:51 -07003418 pmb->context1 = NULL;
3419 pmb->context2 = NULL;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003420
3421 if (mb->mbxStatus) {
James Smart329f9bc2007-04-25 09:53:01 -04003422 mempool_free(pmb, phba->mbox_mem_pool);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003423 return;
3424 }
3425
3426 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
James Smart329f9bc2007-04-25 09:53:01 -04003427 mempool_free(pmb, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05003428 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
3429 lpfc_max_els_tries, ndlp,
3430 ndlp->nlp_DID, ELS_CMD_ACC);
James Smartfa4066b2008-01-11 01:53:27 -05003431
3432 /* Decrement the ndlp reference count from previous mbox command */
James Smart329f9bc2007-04-25 09:53:01 -04003433 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05003434
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003435 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003436 return;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003437
3438 icmd = &elsiocb->iocb;
3439 icmd->ulpContext = xri;
3440
3441 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3442 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003443 pcmd += sizeof(uint32_t); /* Skip past command */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003444 rps_rsp = (RPS_RSP *)pcmd;
3445
3446 if (phba->fc_topology != TOPOLOGY_LOOP)
3447 status = 0x10;
3448 else
3449 status = 0x8;
James Smart2e0fef82007-06-17 19:56:36 -05003450 if (phba->pport->fc_flag & FC_FABRIC)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003451 status |= 0x4;
3452
3453 rps_rsp->rsvd1 = 0;
James Smart09372822008-01-11 01:52:54 -05003454 rps_rsp->portStatus = cpu_to_be16(status);
3455 rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
3456 rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
3457 rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
3458 rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
3459 rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
3460 rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003461 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003462 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
3463 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
3464 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
3465 elsiocb->iotag, elsiocb->iocb.ulpContext,
3466 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3467 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05003468 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003469 phba->fc_stat.elsXmitACC++;
James Smarted957682007-06-17 19:56:37 -05003470 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003471 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003472 return;
3473}
3474
3475static int
James Smart2e0fef82007-06-17 19:56:36 -05003476lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3477 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003478{
James Smart2e0fef82007-06-17 19:56:36 -05003479 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003480 uint32_t *lp;
3481 uint8_t flag;
3482 LPFC_MBOXQ_t *mbox;
3483 struct lpfc_dmabuf *pcmd;
3484 RPS *rps;
3485 struct ls_rjt stat;
3486
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003487 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
3488 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003489 stat.un.b.lsRjtRsvd0 = 0;
3490 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3491 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
3492 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05003493 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
3494 NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003495 }
3496
3497 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3498 lp = (uint32_t *) pcmd->virt;
3499 flag = (be32_to_cpu(*lp++) & 0xf);
3500 rps = (RPS *) lp;
3501
3502 if ((flag == 0) ||
3503 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
James Smart2e0fef82007-06-17 19:56:36 -05003504 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05003505 sizeof(struct lpfc_name)) == 0))) {
James Smart2e0fef82007-06-17 19:56:36 -05003506
James Smart92d7f7b2007-06-17 19:56:38 -05003507 printk("Fix me....\n");
3508 dump_stack();
James Smart2e0fef82007-06-17 19:56:36 -05003509 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
3510 if (mbox) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003511 lpfc_read_lnk_stat(phba, mbox);
3512 mbox->context1 =
James Smart92d7f7b2007-06-17 19:56:38 -05003513 (void *)((unsigned long) cmdiocb->iocb.ulpContext);
James Smart329f9bc2007-04-25 09:53:01 -04003514 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05003515 mbox->vport = vport;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003516 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
James Smartfa4066b2008-01-11 01:53:27 -05003517 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart0b727fe2007-10-27 13:37:25 -04003518 != MBX_NOT_FINISHED)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003519 /* Mbox completion will send ELS Response */
3520 return 0;
James Smartfa4066b2008-01-11 01:53:27 -05003521 /* Decrement reference count used for the failed mbox
3522 * command.
3523 */
James Smart329f9bc2007-04-25 09:53:01 -04003524 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003525 mempool_free(mbox, phba->mbox_mem_pool);
3526 }
3527 }
3528 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, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003533 return 0;
3534}
3535
Jamie Wellnitz082c0262006-02-28 19:25:30 -05003536static int
James Smart2e0fef82007-06-17 19:56:36 -05003537lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
3538 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003539{
James Smart2e0fef82007-06-17 19:56:36 -05003540 struct lpfc_hba *phba = vport->phba;
3541 IOCB_t *icmd, *oldcmd;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003542 RPL_RSP rpl_rsp;
3543 struct lpfc_iocbq *elsiocb;
James Smart2e0fef82007-06-17 19:56:36 -05003544 struct lpfc_sli *psli = &phba->sli;
3545 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003546 uint8_t *pcmd;
3547
James Smart2e0fef82007-06-17 19:56:36 -05003548 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3549 ndlp->nlp_DID, ELS_CMD_ACC);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003550
James Smart488d1462006-03-07 15:02:37 -05003551 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003552 return 1;
James Smart488d1462006-03-07 15:02:37 -05003553
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003554 icmd = &elsiocb->iocb;
3555 oldcmd = &oldiocb->iocb;
3556 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3557
3558 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3559 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003560 pcmd += sizeof(uint16_t);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003561 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
3562 pcmd += sizeof(uint16_t);
3563
3564 /* Setup the RPL ACC payload */
3565 rpl_rsp.listLen = be32_to_cpu(1);
3566 rpl_rsp.index = 0;
3567 rpl_rsp.port_num_blk.portNum = 0;
James Smart2e0fef82007-06-17 19:56:36 -05003568 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
3569 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003570 sizeof(struct lpfc_name));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003571 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003572 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003573 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3574 "0120 Xmit ELS RPL ACC response tag x%x "
3575 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
3576 "rpi x%x\n",
3577 elsiocb->iotag, elsiocb->iocb.ulpContext,
3578 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3579 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05003580 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003581 phba->fc_stat.elsXmitACC++;
3582 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
3583 lpfc_els_free_iocb(phba, elsiocb);
3584 return 1;
3585 }
3586 return 0;
3587}
3588
3589static int
James Smart2e0fef82007-06-17 19:56:36 -05003590lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3591 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003592{
3593 struct lpfc_dmabuf *pcmd;
3594 uint32_t *lp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003595 uint32_t maxsize;
3596 uint16_t cmdsize;
3597 RPL *rpl;
3598 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05003599
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003600 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
3601 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003602 stat.un.b.lsRjtRsvd0 = 0;
3603 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3604 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
3605 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05003606 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
3607 NULL);
dea31012005-04-17 16:05:31 -05003608 }
3609
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003610 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3611 lp = (uint32_t *) pcmd->virt;
3612 rpl = (RPL *) (lp + 1);
3613
3614 maxsize = be32_to_cpu(rpl->maxsize);
3615
3616 /* We support only one port */
3617 if ((rpl->index == 0) &&
3618 ((maxsize == 0) ||
3619 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
3620 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003621 } else {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003622 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
3623 }
James Smart2e0fef82007-06-17 19:56:36 -05003624 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05003625
3626 return 0;
3627}
3628
3629static int
James Smart2e0fef82007-06-17 19:56:36 -05003630lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3631 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003632{
3633 struct lpfc_dmabuf *pcmd;
3634 uint32_t *lp;
3635 IOCB_t *icmd;
3636 FARP *fp;
3637 uint32_t cmd, cnt, did;
3638
3639 icmd = &cmdiocb->iocb;
3640 did = icmd->un.elsreq64.remoteID;
3641 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3642 lp = (uint32_t *) pcmd->virt;
3643
3644 cmd = *lp++;
3645 fp = (FARP *) lp;
dea31012005-04-17 16:05:31 -05003646 /* FARP-REQ received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04003647 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3648 "0601 FARP-REQ received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05003649 /* We will only support match on WWPN or WWNN */
3650 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003651 return 0;
dea31012005-04-17 16:05:31 -05003652 }
3653
3654 cnt = 0;
3655 /* If this FARP command is searching for my portname */
3656 if (fp->Mflags & FARP_MATCH_PORT) {
James Smart2e0fef82007-06-17 19:56:36 -05003657 if (memcmp(&fp->RportName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05003658 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05003659 cnt = 1;
3660 }
3661
3662 /* If this FARP command is searching for my nodename */
3663 if (fp->Mflags & FARP_MATCH_NODE) {
James Smart2e0fef82007-06-17 19:56:36 -05003664 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05003665 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05003666 cnt = 1;
3667 }
3668
3669 if (cnt) {
3670 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
3671 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
3672 /* Log back into the node before sending the FARP. */
3673 if (fp->Rflags & FARP_REQUEST_PLOGI) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003674 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003675 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04003676 NLP_STE_PLOGI_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05003677 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05003678 }
3679
3680 /* Send a FARP response to that node */
James Smart2e0fef82007-06-17 19:56:36 -05003681 if (fp->Rflags & FARP_REQUEST_FARPR)
3682 lpfc_issue_els_farpr(vport, did, 0);
dea31012005-04-17 16:05:31 -05003683 }
3684 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003685 return 0;
dea31012005-04-17 16:05:31 -05003686}
3687
3688static int
James Smart2e0fef82007-06-17 19:56:36 -05003689lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3690 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003691{
3692 struct lpfc_dmabuf *pcmd;
3693 uint32_t *lp;
3694 IOCB_t *icmd;
3695 uint32_t cmd, did;
3696
3697 icmd = &cmdiocb->iocb;
3698 did = icmd->un.elsreq64.remoteID;
3699 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3700 lp = (uint32_t *) pcmd->virt;
3701
3702 cmd = *lp++;
3703 /* FARP-RSP received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04003704 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3705 "0600 FARP-RSP received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05003706 /* ACCEPT the Farp resp request */
James Smart51ef4c22007-08-02 11:10:31 -04003707 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05003708
3709 return 0;
3710}
3711
3712static int
James Smart2e0fef82007-06-17 19:56:36 -05003713lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3714 struct lpfc_nodelist *fan_ndlp)
dea31012005-04-17 16:05:31 -05003715{
3716 struct lpfc_dmabuf *pcmd;
3717 uint32_t *lp;
3718 IOCB_t *icmd;
dea31012005-04-17 16:05:31 -05003719 uint32_t cmd, did;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003720 FAN *fp;
3721 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05003722 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003723
3724 /* FAN received */
James Smarte8b62012007-08-02 11:10:09 -04003725 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3726 "0265 FAN received\n");
dea31012005-04-17 16:05:31 -05003727 icmd = &cmdiocb->iocb;
3728 did = icmd->un.elsreq64.remoteID;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003729 pcmd = (struct lpfc_dmabuf *)cmdiocb->context2;
3730 lp = (uint32_t *)pcmd->virt;
dea31012005-04-17 16:05:31 -05003731
3732 cmd = *lp++;
James Smart92d7f7b2007-06-17 19:56:38 -05003733 fp = (FAN *) lp;
dea31012005-04-17 16:05:31 -05003734
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003735 /* FAN received; Fan does not have a reply sequence */
dea31012005-04-17 16:05:31 -05003736
James Smart2e0fef82007-06-17 19:56:36 -05003737 if (phba->pport->port_state == LPFC_LOCAL_CFG_LINK) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003738 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
3739 sizeof(struct lpfc_name)) != 0) ||
3740 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
3741 sizeof(struct lpfc_name)) != 0)) {
3742 /*
3743 * This node has switched fabrics. FLOGI is required
3744 * Clean up the old rpi's
dea31012005-04-17 16:05:31 -05003745 */
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003746
3747 list_for_each_entry_safe(ndlp, next_ndlp,
James Smart2e0fef82007-06-17 19:56:36 -05003748 &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05003749 if (!NLP_CHK_NODE_ACT(ndlp))
3750 continue;
James Smart685f0bf2007-04-25 09:53:08 -04003751 if (ndlp->nlp_state != NLP_STE_NPR_NODE)
3752 continue;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003753 if (ndlp->nlp_type & NLP_FABRIC) {
3754 /*
3755 * Clean up old Fabric, Nameserver and
3756 * other NLP_FABRIC logins
3757 */
James Smart2e0fef82007-06-17 19:56:36 -05003758 lpfc_drop_node(vport, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04003759
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003760 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003761 /* Fail outstanding I/O now since this
3762 * device is marked for PLOGI
3763 */
James Smart2e0fef82007-06-17 19:56:36 -05003764 lpfc_unreg_rpi(vport, ndlp);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003765 }
3766 }
3767
James Smart2e0fef82007-06-17 19:56:36 -05003768 lpfc_initial_flogi(vport);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003769 return 0;
dea31012005-04-17 16:05:31 -05003770 }
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003771 /* Discovery not needed,
3772 * move the nodes to their original state.
3773 */
James Smart2e0fef82007-06-17 19:56:36 -05003774 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
James Smart685f0bf2007-04-25 09:53:08 -04003775 nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05003776 if (!NLP_CHK_NODE_ACT(ndlp))
3777 continue;
James Smart685f0bf2007-04-25 09:53:08 -04003778 if (ndlp->nlp_state != NLP_STE_NPR_NODE)
3779 continue;
dea31012005-04-17 16:05:31 -05003780
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003781 switch (ndlp->nlp_prev_state) {
3782 case NLP_STE_UNMAPPED_NODE:
3783 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05003784 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04003785 NLP_STE_UNMAPPED_NODE);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003786 break;
3787
3788 case NLP_STE_MAPPED_NODE:
3789 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05003790 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04003791 NLP_STE_MAPPED_NODE);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003792 break;
3793
3794 default:
3795 break;
3796 }
3797 }
3798
3799 /* Start discovery - this should just do CLEAR_LA */
James Smart2e0fef82007-06-17 19:56:36 -05003800 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -05003801 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003802 return 0;
dea31012005-04-17 16:05:31 -05003803}
3804
3805void
3806lpfc_els_timeout(unsigned long ptr)
3807{
James Smart2e0fef82007-06-17 19:56:36 -05003808 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
3809 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003810 unsigned long iflag;
3811
James Smart2e0fef82007-06-17 19:56:36 -05003812 spin_lock_irqsave(&vport->work_port_lock, iflag);
3813 if ((vport->work_port_events & WORKER_ELS_TMO) == 0) {
3814 vport->work_port_events |= WORKER_ELS_TMO;
James Smart92d7f7b2007-06-17 19:56:38 -05003815 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
3816
3817 spin_lock_irqsave(&phba->hbalock, iflag);
dea31012005-04-17 16:05:31 -05003818 if (phba->work_wait)
James Smart92d7f7b2007-06-17 19:56:38 -05003819 lpfc_worker_wake_up(phba);
3820 spin_unlock_irqrestore(&phba->hbalock, iflag);
dea31012005-04-17 16:05:31 -05003821 }
James Smart92d7f7b2007-06-17 19:56:38 -05003822 else
3823 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
dea31012005-04-17 16:05:31 -05003824 return;
3825}
3826
3827void
James Smart2e0fef82007-06-17 19:56:36 -05003828lpfc_els_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003829{
James Smart2e0fef82007-06-17 19:56:36 -05003830 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003831 struct lpfc_sli_ring *pring;
3832 struct lpfc_iocbq *tmp_iocb, *piocb;
3833 IOCB_t *cmd = NULL;
3834 struct lpfc_dmabuf *pcmd;
James Smart2e0fef82007-06-17 19:56:36 -05003835 uint32_t els_command = 0;
dea31012005-04-17 16:05:31 -05003836 uint32_t timeout;
James Smart2e0fef82007-06-17 19:56:36 -05003837 uint32_t remote_ID = 0xffffffff;
dea31012005-04-17 16:05:31 -05003838
dea31012005-04-17 16:05:31 -05003839 /* If the timer is already canceled do nothing */
James Smart2e0fef82007-06-17 19:56:36 -05003840 if ((vport->work_port_events & WORKER_ELS_TMO) == 0) {
dea31012005-04-17 16:05:31 -05003841 return;
3842 }
James Smart2e0fef82007-06-17 19:56:36 -05003843 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003844 timeout = (uint32_t)(phba->fc_ratov << 1);
3845
3846 pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05003847
3848 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
3849 cmd = &piocb->iocb;
3850
James Smart2e0fef82007-06-17 19:56:36 -05003851 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
3852 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
3853 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
dea31012005-04-17 16:05:31 -05003854 continue;
James Smart2e0fef82007-06-17 19:56:36 -05003855
3856 if (piocb->vport != vport)
3857 continue;
3858
dea31012005-04-17 16:05:31 -05003859 pcmd = (struct lpfc_dmabuf *) piocb->context2;
James Smart2e0fef82007-06-17 19:56:36 -05003860 if (pcmd)
3861 els_command = *(uint32_t *) (pcmd->virt);
dea31012005-04-17 16:05:31 -05003862
James Smart92d7f7b2007-06-17 19:56:38 -05003863 if (els_command == ELS_CMD_FARP ||
3864 els_command == ELS_CMD_FARPR ||
3865 els_command == ELS_CMD_FDISC)
dea31012005-04-17 16:05:31 -05003866 continue;
James Smart92d7f7b2007-06-17 19:56:38 -05003867
3868 if (vport != piocb->vport)
3869 continue;
dea31012005-04-17 16:05:31 -05003870
3871 if (piocb->drvrTimeout > 0) {
James Smart92d7f7b2007-06-17 19:56:38 -05003872 if (piocb->drvrTimeout >= timeout)
dea31012005-04-17 16:05:31 -05003873 piocb->drvrTimeout -= timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05003874 else
dea31012005-04-17 16:05:31 -05003875 piocb->drvrTimeout = 0;
dea31012005-04-17 16:05:31 -05003876 continue;
3877 }
3878
James Smart2e0fef82007-06-17 19:56:36 -05003879 remote_ID = 0xffffffff;
3880 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
dea31012005-04-17 16:05:31 -05003881 remote_ID = cmd->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05003882 else {
3883 struct lpfc_nodelist *ndlp;
3884 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
3885 if (ndlp)
3886 remote_ID = ndlp->nlp_DID;
dea31012005-04-17 16:05:31 -05003887 }
James Smarte8b62012007-08-02 11:10:09 -04003888 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3889 "0127 ELS timeout Data: x%x x%x x%x "
3890 "x%x\n", els_command,
3891 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
James Smart07951072007-04-25 09:51:38 -04003892 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05003893 }
James Smart2e0fef82007-06-17 19:56:36 -05003894 spin_unlock_irq(&phba->hbalock);
James Smart5a0e3262006-07-06 15:49:16 -04003895
James Smart2e0fef82007-06-17 19:56:36 -05003896 if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt)
3897 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
dea31012005-04-17 16:05:31 -05003898}
3899
3900void
James Smart2e0fef82007-06-17 19:56:36 -05003901lpfc_els_flush_cmd(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003902{
James Smart2534ba72007-04-25 09:52:20 -04003903 LIST_HEAD(completions);
James Smart2e0fef82007-06-17 19:56:36 -05003904 struct lpfc_hba *phba = vport->phba;
James Smart329f9bc2007-04-25 09:53:01 -04003905 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05003906 struct lpfc_iocbq *tmp_iocb, *piocb;
3907 IOCB_t *cmd = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05003908
3909 lpfc_fabric_abort_vport(vport);
dea31012005-04-17 16:05:31 -05003910
James Smart2e0fef82007-06-17 19:56:36 -05003911 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003912 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
3913 cmd = &piocb->iocb;
3914
3915 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
3916 continue;
3917 }
3918
3919 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
James Smart329f9bc2007-04-25 09:53:01 -04003920 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
3921 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
3922 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
3923 cmd->ulpCommand == CMD_ABORT_XRI_CN)
dea31012005-04-17 16:05:31 -05003924 continue;
dea31012005-04-17 16:05:31 -05003925
James Smart2e0fef82007-06-17 19:56:36 -05003926 if (piocb->vport != vport)
3927 continue;
3928
James Smart2534ba72007-04-25 09:52:20 -04003929 list_move_tail(&piocb->list, &completions);
James Smart1dcb58e2007-04-25 09:51:30 -04003930 pring->txq_cnt--;
dea31012005-04-17 16:05:31 -05003931 }
3932
3933 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
dea31012005-04-17 16:05:31 -05003934 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
3935 continue;
3936 }
dea31012005-04-17 16:05:31 -05003937
James Smart2e0fef82007-06-17 19:56:36 -05003938 if (piocb->vport != vport)
3939 continue;
3940
James Smart07951072007-04-25 09:51:38 -04003941 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05003942 }
James Smart2e0fef82007-06-17 19:56:36 -05003943 spin_unlock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04003944
James Smart2e0fef82007-06-17 19:56:36 -05003945 while (!list_empty(&completions)) {
James Smart2534ba72007-04-25 09:52:20 -04003946 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
3947 cmd = &piocb->iocb;
James Smart92d7f7b2007-06-17 19:56:38 -05003948 list_del_init(&piocb->list);
James Smart2534ba72007-04-25 09:52:20 -04003949
James Smart2e0fef82007-06-17 19:56:36 -05003950 if (!piocb->iocb_cmpl)
3951 lpfc_sli_release_iocbq(phba, piocb);
3952 else {
James Smart2534ba72007-04-25 09:52:20 -04003953 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
3954 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
3955 (piocb->iocb_cmpl) (phba, piocb, piocb);
James Smart2e0fef82007-06-17 19:56:36 -05003956 }
James Smart2534ba72007-04-25 09:52:20 -04003957 }
3958
dea31012005-04-17 16:05:31 -05003959 return;
3960}
3961
James Smart549e55c2007-08-02 11:09:51 -04003962void
3963lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
3964{
3965 LIST_HEAD(completions);
3966 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
3967 struct lpfc_iocbq *tmp_iocb, *piocb;
3968 IOCB_t *cmd = NULL;
3969
3970 lpfc_fabric_abort_hba(phba);
3971 spin_lock_irq(&phba->hbalock);
3972 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
3973 cmd = &piocb->iocb;
3974 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
3975 continue;
3976 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
3977 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
3978 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
3979 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
3980 cmd->ulpCommand == CMD_ABORT_XRI_CN)
3981 continue;
3982 list_move_tail(&piocb->list, &completions);
3983 pring->txq_cnt--;
3984 }
3985 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
3986 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
3987 continue;
3988 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
3989 }
3990 spin_unlock_irq(&phba->hbalock);
3991 while (!list_empty(&completions)) {
3992 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
3993 cmd = &piocb->iocb;
3994 list_del_init(&piocb->list);
3995 if (!piocb->iocb_cmpl)
3996 lpfc_sli_release_iocbq(phba, piocb);
3997 else {
3998 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
3999 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
4000 (piocb->iocb_cmpl) (phba, piocb, piocb);
4001 }
4002 }
4003 return;
4004}
4005
James Smarted957682007-06-17 19:56:37 -05004006static void
4007lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
James Smart92d7f7b2007-06-17 19:56:38 -05004008 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05004009{
James Smart87af33f2007-10-27 13:37:43 -04004010 struct Scsi_Host *shost;
dea31012005-04-17 16:05:31 -05004011 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05004012 struct ls_rjt stat;
James Smart92d7f7b2007-06-17 19:56:38 -05004013 uint32_t *payload;
James Smart2e0fef82007-06-17 19:56:36 -05004014 uint32_t cmd, did, newnode, rjt_err = 0;
James Smarted957682007-06-17 19:56:37 -05004015 IOCB_t *icmd = &elsiocb->iocb;
dea31012005-04-17 16:05:31 -05004016
James Smarte47c9092008-02-08 18:49:26 -05004017 if (!vport || !(elsiocb->context2))
dea31012005-04-17 16:05:31 -05004018 goto dropit;
James Smart2e0fef82007-06-17 19:56:36 -05004019
dea31012005-04-17 16:05:31 -05004020 newnode = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05004021 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
4022 cmd = *payload;
James Smarted957682007-06-17 19:56:37 -05004023 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
4024 lpfc_post_buffer(phba, pring, 1, 1);
dea31012005-04-17 16:05:31 -05004025
James Smart858c9f62007-06-17 19:56:39 -05004026 did = icmd->un.rcvels.remoteID;
4027 if (icmd->ulpStatus) {
4028 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4029 "RCV Unsol ELS: status:x%x/x%x did:x%x",
4030 icmd->ulpStatus, icmd->un.ulpWord[4], did);
dea31012005-04-17 16:05:31 -05004031 goto dropit;
James Smart858c9f62007-06-17 19:56:39 -05004032 }
dea31012005-04-17 16:05:31 -05004033
4034 /* Check to see if link went down during discovery */
James Smarted957682007-06-17 19:56:37 -05004035 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05004036 goto dropit;
dea31012005-04-17 16:05:31 -05004037
James Smart92d7f7b2007-06-17 19:56:38 -05004038 /* Ignore traffic recevied during vport shutdown. */
4039 if (vport->load_flag & FC_UNLOADING)
4040 goto dropit;
4041
James Smart2e0fef82007-06-17 19:56:36 -05004042 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004043 if (!ndlp) {
dea31012005-04-17 16:05:31 -05004044 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004045 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
James Smarted957682007-06-17 19:56:37 -05004046 if (!ndlp)
dea31012005-04-17 16:05:31 -05004047 goto dropit;
dea31012005-04-17 16:05:31 -05004048
James Smart2e0fef82007-06-17 19:56:36 -05004049 lpfc_nlp_init(vport, ndlp, did);
James Smart98c9ea52007-10-27 13:37:33 -04004050 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05004051 newnode = 1;
James Smarte47c9092008-02-08 18:49:26 -05004052 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
dea31012005-04-17 16:05:31 -05004053 ndlp->nlp_type |= NLP_FABRIC;
James Smarte47c9092008-02-08 18:49:26 -05004054 } else {
4055 if (!NLP_CHK_NODE_ACT(ndlp)) {
4056 ndlp = lpfc_enable_node(vport, ndlp,
4057 NLP_STE_UNUSED_NODE);
4058 if (!ndlp)
4059 goto dropit;
dea31012005-04-17 16:05:31 -05004060 }
James Smart87af33f2007-10-27 13:37:43 -04004061 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
4062 /* This is simular to the new node path */
James Smarte47c9092008-02-08 18:49:26 -05004063 ndlp = lpfc_nlp_get(ndlp);
4064 if (!ndlp)
4065 goto dropit;
James Smart87af33f2007-10-27 13:37:43 -04004066 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
4067 newnode = 1;
4068 }
4069 }
dea31012005-04-17 16:05:31 -05004070
4071 phba->fc_stat.elsRcvFrame++;
James Smart329f9bc2007-04-25 09:53:01 -04004072 if (elsiocb->context1)
4073 lpfc_nlp_put(elsiocb->context1);
James Smarte47c9092008-02-08 18:49:26 -05004074
James Smart329f9bc2007-04-25 09:53:01 -04004075 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05004076 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -05004077
4078 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
4079 cmd &= ELS_CMD_MASK;
4080 }
4081 /* ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04004082 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4083 "0112 ELS command x%x received from NPORT x%x "
4084 "Data: x%x\n", cmd, did, vport->port_state);
dea31012005-04-17 16:05:31 -05004085 switch (cmd) {
4086 case ELS_CMD_PLOGI:
James Smart858c9f62007-06-17 19:56:39 -05004087 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4088 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
4089 did, vport->port_state, ndlp->nlp_flag);
4090
dea31012005-04-17 16:05:31 -05004091 phba->fc_stat.elsRcvPLOGI++;
James Smart858c9f62007-06-17 19:56:39 -05004092 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
4093
4094 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart1b32f6a2008-02-08 18:49:39 -05004095 if (!(phba->pport->fc_flag & FC_PT2PT) ||
4096 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
4097 rjt_err = LSRJT_UNABLE_TPC;
4098 break;
4099 }
4100 /* We get here, and drop thru, if we are PT2PT with
4101 * another NPort and the other side has initiated
4102 * the PLOGI before responding to our FLOGI.
4103 */
dea31012005-04-17 16:05:31 -05004104 }
James Smart87af33f2007-10-27 13:37:43 -04004105
4106 shost = lpfc_shost_from_vport(vport);
4107 spin_lock_irq(shost->host_lock);
4108 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
4109 spin_unlock_irq(shost->host_lock);
4110
James Smart2e0fef82007-06-17 19:56:36 -05004111 lpfc_disc_state_machine(vport, ndlp, elsiocb,
4112 NLP_EVT_RCV_PLOGI);
James Smart858c9f62007-06-17 19:56:39 -05004113
dea31012005-04-17 16:05:31 -05004114 break;
4115 case ELS_CMD_FLOGI:
James Smart858c9f62007-06-17 19:56:39 -05004116 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4117 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
4118 did, vport->port_state, ndlp->nlp_flag);
4119
dea31012005-04-17 16:05:31 -05004120 phba->fc_stat.elsRcvFLOGI++;
James Smart51ef4c22007-08-02 11:10:31 -04004121 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04004122 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04004123 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05004124 break;
4125 case ELS_CMD_LOGO:
James Smart858c9f62007-06-17 19:56:39 -05004126 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4127 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
4128 did, vport->port_state, ndlp->nlp_flag);
4129
dea31012005-04-17 16:05:31 -05004130 phba->fc_stat.elsRcvLOGO++;
James Smart2e0fef82007-06-17 19:56:36 -05004131 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05004132 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05004133 break;
4134 }
James Smart2e0fef82007-06-17 19:56:36 -05004135 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
dea31012005-04-17 16:05:31 -05004136 break;
4137 case ELS_CMD_PRLO:
James Smart858c9f62007-06-17 19:56:39 -05004138 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4139 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
4140 did, vport->port_state, ndlp->nlp_flag);
4141
dea31012005-04-17 16:05:31 -05004142 phba->fc_stat.elsRcvPRLO++;
James Smart2e0fef82007-06-17 19:56:36 -05004143 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05004144 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05004145 break;
4146 }
James Smart2e0fef82007-06-17 19:56:36 -05004147 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
dea31012005-04-17 16:05:31 -05004148 break;
4149 case ELS_CMD_RSCN:
4150 phba->fc_stat.elsRcvRSCN++;
James Smart51ef4c22007-08-02 11:10:31 -04004151 lpfc_els_rcv_rscn(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);
dea31012005-04-17 16:05:31 -05004154 break;
4155 case ELS_CMD_ADISC:
James Smart858c9f62007-06-17 19:56:39 -05004156 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4157 "RCV ADISC: 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.elsRcvADISC++;
James Smart2e0fef82007-06-17 19:56:36 -05004161 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05004162 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05004163 break;
4164 }
James Smart2e0fef82007-06-17 19:56:36 -05004165 lpfc_disc_state_machine(vport, ndlp, elsiocb,
4166 NLP_EVT_RCV_ADISC);
dea31012005-04-17 16:05:31 -05004167 break;
4168 case ELS_CMD_PDISC:
James Smart858c9f62007-06-17 19:56:39 -05004169 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4170 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
4171 did, vport->port_state, ndlp->nlp_flag);
4172
dea31012005-04-17 16:05:31 -05004173 phba->fc_stat.elsRcvPDISC++;
James Smart2e0fef82007-06-17 19:56:36 -05004174 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05004175 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05004176 break;
4177 }
James Smart2e0fef82007-06-17 19:56:36 -05004178 lpfc_disc_state_machine(vport, ndlp, elsiocb,
4179 NLP_EVT_RCV_PDISC);
dea31012005-04-17 16:05:31 -05004180 break;
4181 case ELS_CMD_FARPR:
James Smart858c9f62007-06-17 19:56:39 -05004182 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4183 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
4184 did, vport->port_state, ndlp->nlp_flag);
4185
dea31012005-04-17 16:05:31 -05004186 phba->fc_stat.elsRcvFARPR++;
James Smart2e0fef82007-06-17 19:56:36 -05004187 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05004188 break;
4189 case ELS_CMD_FARP:
James Smart858c9f62007-06-17 19:56:39 -05004190 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4191 "RCV FARP: did:x%x/ste:x%x flg:x%x",
4192 did, vport->port_state, ndlp->nlp_flag);
4193
dea31012005-04-17 16:05:31 -05004194 phba->fc_stat.elsRcvFARP++;
James Smart2e0fef82007-06-17 19:56:36 -05004195 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05004196 break;
4197 case ELS_CMD_FAN:
James Smart858c9f62007-06-17 19:56:39 -05004198 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4199 "RCV FAN: did:x%x/ste:x%x flg:x%x",
4200 did, vport->port_state, ndlp->nlp_flag);
4201
dea31012005-04-17 16:05:31 -05004202 phba->fc_stat.elsRcvFAN++;
James Smart2e0fef82007-06-17 19:56:36 -05004203 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05004204 break;
dea31012005-04-17 16:05:31 -05004205 case ELS_CMD_PRLI:
James Smart858c9f62007-06-17 19:56:39 -05004206 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4207 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
4208 did, vport->port_state, ndlp->nlp_flag);
4209
dea31012005-04-17 16:05:31 -05004210 phba->fc_stat.elsRcvPRLI++;
James Smart2e0fef82007-06-17 19:56:36 -05004211 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05004212 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05004213 break;
4214 }
James Smart2e0fef82007-06-17 19:56:36 -05004215 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
dea31012005-04-17 16:05:31 -05004216 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004217 case ELS_CMD_LIRR:
James Smart858c9f62007-06-17 19:56:39 -05004218 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4219 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
4220 did, vport->port_state, ndlp->nlp_flag);
4221
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004222 phba->fc_stat.elsRcvLIRR++;
James Smart2e0fef82007-06-17 19:56:36 -05004223 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04004224 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04004225 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004226 break;
4227 case ELS_CMD_RPS:
James Smart858c9f62007-06-17 19:56:39 -05004228 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4229 "RCV RPS: did:x%x/ste:x%x flg:x%x",
4230 did, vport->port_state, ndlp->nlp_flag);
4231
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004232 phba->fc_stat.elsRcvRPS++;
James Smart2e0fef82007-06-17 19:56:36 -05004233 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04004234 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04004235 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004236 break;
4237 case ELS_CMD_RPL:
James Smart858c9f62007-06-17 19:56:39 -05004238 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4239 "RCV RPL: did:x%x/ste:x%x flg:x%x",
4240 did, vport->port_state, ndlp->nlp_flag);
4241
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004242 phba->fc_stat.elsRcvRPL++;
James Smart2e0fef82007-06-17 19:56:36 -05004243 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04004244 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04004245 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004246 break;
dea31012005-04-17 16:05:31 -05004247 case ELS_CMD_RNID:
James Smart858c9f62007-06-17 19:56:39 -05004248 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4249 "RCV RNID: did:x%x/ste:x%x flg:x%x",
4250 did, vport->port_state, ndlp->nlp_flag);
4251
dea31012005-04-17 16:05:31 -05004252 phba->fc_stat.elsRcvRNID++;
James Smart2e0fef82007-06-17 19:56:36 -05004253 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04004254 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04004255 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05004256 break;
4257 default:
James Smart858c9f62007-06-17 19:56:39 -05004258 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4259 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
4260 cmd, did, vport->port_state);
4261
dea31012005-04-17 16:05:31 -05004262 /* Unsupported ELS command, reject */
James Smart858c9f62007-06-17 19:56:39 -05004263 rjt_err = LSRJT_INVALID_CMD;
dea31012005-04-17 16:05:31 -05004264
4265 /* Unknown ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04004266 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4267 "0115 Unknown ELS command x%x "
4268 "received from NPORT x%x\n", cmd, did);
James Smart87af33f2007-10-27 13:37:43 -04004269 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04004270 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05004271 break;
4272 }
4273
4274 /* check if need to LS_RJT received ELS cmd */
4275 if (rjt_err) {
James Smart92d7f7b2007-06-17 19:56:38 -05004276 memset(&stat, 0, sizeof(stat));
James Smart858c9f62007-06-17 19:56:39 -05004277 stat.un.b.lsRjtRsnCode = rjt_err;
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04004278 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart858c9f62007-06-17 19:56:39 -05004279 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
4280 NULL);
dea31012005-04-17 16:05:31 -05004281 }
4282
James Smarted957682007-06-17 19:56:37 -05004283 return;
4284
4285dropit:
James Smart98c9ea52007-10-27 13:37:33 -04004286 if (vport && !(vport->load_flag & FC_UNLOADING))
4287 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
James Smarte8b62012007-08-02 11:10:09 -04004288 "(%d):0111 Dropping received ELS cmd "
James Smarted957682007-06-17 19:56:37 -05004289 "Data: x%x x%x x%x\n",
James Smart98c9ea52007-10-27 13:37:33 -04004290 vport->vpi, icmd->ulpStatus,
James Smarte8b62012007-08-02 11:10:09 -04004291 icmd->un.ulpWord[4], icmd->ulpTimeout);
James Smarted957682007-06-17 19:56:37 -05004292 phba->fc_stat.elsRcvDrop++;
4293}
4294
James Smart92d7f7b2007-06-17 19:56:38 -05004295static struct lpfc_vport *
4296lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
4297{
4298 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -04004299 unsigned long flags;
James Smart92d7f7b2007-06-17 19:56:38 -05004300
James Smart549e55c2007-08-02 11:09:51 -04004301 spin_lock_irqsave(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05004302 list_for_each_entry(vport, &phba->port_list, listentry) {
James Smart549e55c2007-08-02 11:09:51 -04004303 if (vport->vpi == vpi) {
4304 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05004305 return vport;
James Smart549e55c2007-08-02 11:09:51 -04004306 }
James Smart92d7f7b2007-06-17 19:56:38 -05004307 }
James Smart549e55c2007-08-02 11:09:51 -04004308 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05004309 return NULL;
4310}
James Smarted957682007-06-17 19:56:37 -05004311
4312void
4313lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
4314 struct lpfc_iocbq *elsiocb)
4315{
4316 struct lpfc_vport *vport = phba->pport;
James Smarted957682007-06-17 19:56:37 -05004317 IOCB_t *icmd = &elsiocb->iocb;
James Smarted957682007-06-17 19:56:37 -05004318 dma_addr_t paddr;
James Smart92d7f7b2007-06-17 19:56:38 -05004319 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
4320 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
James Smarted957682007-06-17 19:56:37 -05004321
James Smart92d7f7b2007-06-17 19:56:38 -05004322 elsiocb->context2 = NULL;
4323 elsiocb->context3 = NULL;
4324
4325 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
4326 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
4327 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
4328 (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) {
James Smarted957682007-06-17 19:56:37 -05004329 phba->fc_stat.NoRcvBuf++;
4330 /* Not enough posted buffers; Try posting more buffers */
James Smart92d7f7b2007-06-17 19:56:38 -05004331 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
James Smarted957682007-06-17 19:56:37 -05004332 lpfc_post_buffer(phba, pring, 0, 1);
4333 return;
4334 }
4335
James Smart92d7f7b2007-06-17 19:56:38 -05004336 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
4337 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
4338 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
4339 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
4340 vport = phba->pport;
4341 else {
4342 uint16_t vpi = icmd->unsli3.rcvsli3.vpi;
4343 vport = lpfc_find_vport_by_vpid(phba, vpi);
4344 }
4345 }
4346 /* If there are no BDEs associated
4347 * with this IOCB, there is nothing to do.
4348 */
James Smarted957682007-06-17 19:56:37 -05004349 if (icmd->ulpBdeCount == 0)
4350 return;
4351
James Smart92d7f7b2007-06-17 19:56:38 -05004352 /* type of ELS cmd is first 32bit word
4353 * in packet
4354 */
James Smarted957682007-06-17 19:56:37 -05004355 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05004356 elsiocb->context2 = bdeBuf1;
James Smarted957682007-06-17 19:56:37 -05004357 } else {
4358 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
4359 icmd->un.cont64[0].addrLow);
James Smart92d7f7b2007-06-17 19:56:38 -05004360 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
4361 paddr);
James Smarted957682007-06-17 19:56:37 -05004362 }
4363
James Smart92d7f7b2007-06-17 19:56:38 -05004364 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
4365 /*
4366 * The different unsolicited event handlers would tell us
4367 * if they are done with "mp" by setting context2 to NULL.
4368 */
James Smart329f9bc2007-04-25 09:53:01 -04004369 lpfc_nlp_put(elsiocb->context1);
4370 elsiocb->context1 = NULL;
dea31012005-04-17 16:05:31 -05004371 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05004372 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
4373 elsiocb->context2 = NULL;
dea31012005-04-17 16:05:31 -05004374 }
James Smarted957682007-06-17 19:56:37 -05004375
4376 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
James Smart92d7f7b2007-06-17 19:56:38 -05004377 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
James Smarted957682007-06-17 19:56:37 -05004378 icmd->ulpBdeCount == 2) {
James Smart92d7f7b2007-06-17 19:56:38 -05004379 elsiocb->context2 = bdeBuf2;
4380 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
James Smarted957682007-06-17 19:56:37 -05004381 /* free mp if we are done with it */
4382 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05004383 lpfc_in_buf_free(phba, elsiocb->context2);
4384 elsiocb->context2 = NULL;
James Smarted957682007-06-17 19:56:37 -05004385 }
dea31012005-04-17 16:05:31 -05004386 }
dea31012005-04-17 16:05:31 -05004387}
James Smart92d7f7b2007-06-17 19:56:38 -05004388
4389void
4390lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
4391{
4392 struct lpfc_nodelist *ndlp, *ndlp_fdmi;
4393
4394 ndlp = lpfc_findnode_did(vport, NameServer_DID);
4395 if (!ndlp) {
4396 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
4397 if (!ndlp) {
4398 if (phba->fc_topology == TOPOLOGY_LOOP) {
4399 lpfc_disc_start(vport);
4400 return;
4401 }
4402 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04004403 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4404 "0251 NameServer login: no memory\n");
James Smart92d7f7b2007-06-17 19:56:38 -05004405 return;
4406 }
4407 lpfc_nlp_init(vport, ndlp, NameServer_DID);
4408 ndlp->nlp_type |= NLP_FABRIC;
James Smarte47c9092008-02-08 18:49:26 -05004409 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
4410 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
4411 if (!ndlp) {
4412 if (phba->fc_topology == TOPOLOGY_LOOP) {
4413 lpfc_disc_start(vport);
4414 return;
4415 }
4416 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4417 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4418 "0348 NameServer login: node freed\n");
4419 return;
4420 }
James Smart92d7f7b2007-06-17 19:56:38 -05004421 }
4422
4423 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
4424
4425 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
4426 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04004427 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4428 "0252 Cannot issue NameServer login\n");
James Smart92d7f7b2007-06-17 19:56:38 -05004429 return;
4430 }
4431
James Smart3de2a652007-08-02 11:09:59 -04004432 if (vport->cfg_fdmi_on) {
James Smart92d7f7b2007-06-17 19:56:38 -05004433 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
4434 GFP_KERNEL);
4435 if (ndlp_fdmi) {
4436 lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
4437 ndlp_fdmi->nlp_type |= NLP_FABRIC;
4438 ndlp_fdmi->nlp_state =
4439 NLP_STE_PLOGI_ISSUE;
4440 lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID,
4441 0);
4442 }
4443 }
4444 return;
4445}
4446
4447static void
4448lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4449{
4450 struct lpfc_vport *vport = pmb->vport;
4451 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4452 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
4453 MAILBOX_t *mb = &pmb->mb;
4454
James Smart09372822008-01-11 01:52:54 -05004455 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004456 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05004457 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004458
4459 if (mb->mbxStatus) {
James Smarte8b62012007-08-02 11:10:09 -04004460 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
4461 "0915 Register VPI failed: 0x%x\n",
4462 mb->mbxStatus);
James Smart92d7f7b2007-06-17 19:56:38 -05004463
4464 switch (mb->mbxStatus) {
4465 case 0x11: /* unsupported feature */
4466 case 0x9603: /* max_vpi exceeded */
4467 /* giving up on vport registration */
4468 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4469 spin_lock_irq(shost->host_lock);
4470 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
4471 spin_unlock_irq(shost->host_lock);
4472 lpfc_can_disctmo(vport);
4473 break;
4474 default:
4475 /* Try to recover from this error */
4476 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -05004477 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004478 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05004479 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004480 lpfc_initial_fdisc(vport);
4481 break;
4482 }
4483
4484 } else {
4485 if (vport == phba->pport)
4486 lpfc_issue_fabric_reglogin(vport);
4487 else
4488 lpfc_do_scr_ns_plogi(phba, vport);
4489 }
James Smartfa4066b2008-01-11 01:53:27 -05004490
4491 /* Now, we decrement the ndlp reference count held for this
4492 * callback function
4493 */
4494 lpfc_nlp_put(ndlp);
4495
James Smart92d7f7b2007-06-17 19:56:38 -05004496 mempool_free(pmb, phba->mbox_mem_pool);
4497 return;
4498}
4499
Adrian Bunka6ababd2007-11-05 18:07:33 +01004500static void
James Smart92d7f7b2007-06-17 19:56:38 -05004501lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
4502 struct lpfc_nodelist *ndlp)
4503{
James Smart09372822008-01-11 01:52:54 -05004504 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05004505 LPFC_MBOXQ_t *mbox;
4506
4507 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4508 if (mbox) {
4509 lpfc_reg_vpi(phba, vport->vpi, vport->fc_myDID, mbox);
4510 mbox->vport = vport;
4511 mbox->context2 = lpfc_nlp_get(ndlp);
4512 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
James Smart0b727fe2007-10-27 13:37:25 -04004513 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart92d7f7b2007-06-17 19:56:38 -05004514 == MBX_NOT_FINISHED) {
James Smartfa4066b2008-01-11 01:53:27 -05004515 /* mailbox command not success, decrement ndlp
4516 * reference count for this command
4517 */
4518 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05004519 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05004520
James Smarte8b62012007-08-02 11:10:09 -04004521 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
4522 "0253 Register VPI: Can't send mbox\n");
James Smartfa4066b2008-01-11 01:53:27 -05004523 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05004524 }
4525 } else {
James Smarte8b62012007-08-02 11:10:09 -04004526 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
4527 "0254 Register VPI: no memory\n");
James Smartfa4066b2008-01-11 01:53:27 -05004528 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05004529 }
James Smartfa4066b2008-01-11 01:53:27 -05004530 return;
4531
4532mbox_err_exit:
4533 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4534 spin_lock_irq(shost->host_lock);
4535 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
4536 spin_unlock_irq(shost->host_lock);
4537 return;
James Smart92d7f7b2007-06-17 19:56:38 -05004538}
4539
4540static void
4541lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4542 struct lpfc_iocbq *rspiocb)
4543{
4544 struct lpfc_vport *vport = cmdiocb->vport;
4545 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4546 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
4547 struct lpfc_nodelist *np;
4548 struct lpfc_nodelist *next_np;
4549 IOCB_t *irsp = &rspiocb->iocb;
4550 struct lpfc_iocbq *piocb;
4551
James Smarte8b62012007-08-02 11:10:09 -04004552 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4553 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
4554 irsp->ulpStatus, irsp->un.ulpWord[4],
4555 vport->fc_prevDID);
James Smart92d7f7b2007-06-17 19:56:38 -05004556 /* Since all FDISCs are being single threaded, we
4557 * must reset the discovery timer for ALL vports
4558 * waiting to send FDISC when one completes.
4559 */
4560 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
4561 lpfc_set_disctmo(piocb->vport);
4562 }
4563
James Smart858c9f62007-06-17 19:56:39 -05004564 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4565 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
4566 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
4567
James Smart92d7f7b2007-06-17 19:56:38 -05004568 if (irsp->ulpStatus) {
4569 /* Check for retry */
4570 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
4571 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05004572 /* FDISC failed */
James Smarte8b62012007-08-02 11:10:09 -04004573 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4574 "0124 FDISC failed. (%d/%d)\n",
4575 irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smart92d7f7b2007-06-17 19:56:38 -05004576 if (vport->fc_vport->vport_state == FC_VPORT_INITIALIZING)
4577 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smart92d7f7b2007-06-17 19:56:38 -05004578 lpfc_nlp_put(ndlp);
4579 /* giving up on FDISC. Cancel discovery timer */
4580 lpfc_can_disctmo(vport);
4581 } else {
4582 spin_lock_irq(shost->host_lock);
4583 vport->fc_flag |= FC_FABRIC;
4584 if (vport->phba->fc_topology == TOPOLOGY_LOOP)
4585 vport->fc_flag |= FC_PUBLIC_LOOP;
4586 spin_unlock_irq(shost->host_lock);
4587
4588 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
4589 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
4590 if ((vport->fc_prevDID != vport->fc_myDID) &&
4591 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
4592 /* If our NportID changed, we need to ensure all
4593 * remaining NPORTs get unreg_login'ed so we can
4594 * issue unreg_vpi.
4595 */
4596 list_for_each_entry_safe(np, next_np,
4597 &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004598 if (!NLP_CHK_NODE_ACT(ndlp) ||
4599 (np->nlp_state != NLP_STE_NPR_NODE) ||
4600 !(np->nlp_flag & NLP_NPR_ADISC))
James Smart92d7f7b2007-06-17 19:56:38 -05004601 continue;
4602 spin_lock_irq(shost->host_lock);
4603 np->nlp_flag &= ~NLP_NPR_ADISC;
4604 spin_unlock_irq(shost->host_lock);
4605 lpfc_unreg_rpi(vport, np);
4606 }
4607 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -05004608 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004609 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05004610 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004611 }
4612
4613 if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
4614 lpfc_register_new_vport(phba, vport, ndlp);
4615 else
4616 lpfc_do_scr_ns_plogi(phba, vport);
4617
James Smartfa4066b2008-01-11 01:53:27 -05004618 /* Unconditionaly kick off releasing fabric node for vports */
4619 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05004620 }
4621
4622out:
4623 lpfc_els_free_iocb(phba, cmdiocb);
4624}
4625
Adrian Bunka6ababd2007-11-05 18:07:33 +01004626static int
James Smart92d7f7b2007-06-17 19:56:38 -05004627lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4628 uint8_t retry)
4629{
4630 struct lpfc_hba *phba = vport->phba;
4631 IOCB_t *icmd;
4632 struct lpfc_iocbq *elsiocb;
4633 struct serv_parm *sp;
4634 uint8_t *pcmd;
4635 uint16_t cmdsize;
4636 int did = ndlp->nlp_DID;
4637 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05004638
4639 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
4640 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
4641 ELS_CMD_FDISC);
4642 if (!elsiocb) {
James Smart92d7f7b2007-06-17 19:56:38 -05004643 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04004644 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4645 "0255 Issue FDISC: no IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05004646 return 1;
4647 }
4648
4649 icmd = &elsiocb->iocb;
4650 icmd->un.elsreq64.myID = 0;
4651 icmd->un.elsreq64.fl = 1;
4652
4653 /* For FDISC, Let FDISC rsp set the NPortID for this VPI */
4654 icmd->ulpCt_h = 1;
4655 icmd->ulpCt_l = 0;
4656
4657 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4658 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
4659 pcmd += sizeof(uint32_t); /* CSP Word 1 */
4660 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
4661 sp = (struct serv_parm *) pcmd;
4662 /* Setup CSPs accordingly for Fabric */
4663 sp->cmn.e_d_tov = 0;
4664 sp->cmn.w2.r_a_tov = 0;
4665 sp->cls1.classValid = 0;
4666 sp->cls2.seqDelivery = 1;
4667 sp->cls3.seqDelivery = 1;
4668
4669 pcmd += sizeof(uint32_t); /* CSP Word 2 */
4670 pcmd += sizeof(uint32_t); /* CSP Word 3 */
4671 pcmd += sizeof(uint32_t); /* CSP Word 4 */
4672 pcmd += sizeof(uint32_t); /* Port Name */
4673 memcpy(pcmd, &vport->fc_portname, 8);
4674 pcmd += sizeof(uint32_t); /* Node Name */
4675 pcmd += sizeof(uint32_t); /* Node Name */
4676 memcpy(pcmd, &vport->fc_nodename, 8);
4677
4678 lpfc_set_disctmo(vport);
4679
4680 phba->fc_stat.elsXmitFDISC++;
4681 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
4682
James Smart858c9f62007-06-17 19:56:39 -05004683 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4684 "Issue FDISC: did:x%x",
4685 did, 0, 0);
4686
James Smart92d7f7b2007-06-17 19:56:38 -05004687 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
4688 if (rc == IOCB_ERROR) {
4689 lpfc_els_free_iocb(phba, elsiocb);
James Smart92d7f7b2007-06-17 19:56:38 -05004690 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04004691 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4692 "0256 Issue FDISC: Cannot send IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05004693 return 1;
4694 }
4695 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
4696 vport->port_state = LPFC_FDISC;
4697 return 0;
4698}
4699
4700static void
4701lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4702 struct lpfc_iocbq *rspiocb)
4703{
4704 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05004705 IOCB_t *irsp;
James Smarte47c9092008-02-08 18:49:26 -05004706 struct lpfc_nodelist *ndlp;
4707 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
James Smart858c9f62007-06-17 19:56:39 -05004708
4709 irsp = &rspiocb->iocb;
4710 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4711 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
4712 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
James Smart92d7f7b2007-06-17 19:56:38 -05004713
4714 lpfc_els_free_iocb(phba, cmdiocb);
4715 vport->unreg_vpi_cmpl = VPORT_ERROR;
James Smarte47c9092008-02-08 18:49:26 -05004716
4717 /* Trigger the release of the ndlp after logo */
4718 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05004719}
4720
4721int
4722lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4723{
4724 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4725 struct lpfc_hba *phba = vport->phba;
4726 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
4727 IOCB_t *icmd;
4728 struct lpfc_iocbq *elsiocb;
4729 uint8_t *pcmd;
4730 uint16_t cmdsize;
4731
4732 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
4733 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
4734 ELS_CMD_LOGO);
4735 if (!elsiocb)
4736 return 1;
4737
4738 icmd = &elsiocb->iocb;
4739 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4740 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
4741 pcmd += sizeof(uint32_t);
4742
4743 /* Fill in LOGO payload */
4744 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
4745 pcmd += sizeof(uint32_t);
4746 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
4747
James Smart858c9f62007-06-17 19:56:39 -05004748 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4749 "Issue LOGO npiv did:x%x flg:x%x",
4750 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4751
James Smart92d7f7b2007-06-17 19:56:38 -05004752 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
4753 spin_lock_irq(shost->host_lock);
4754 ndlp->nlp_flag |= NLP_LOGO_SND;
4755 spin_unlock_irq(shost->host_lock);
4756 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
4757 spin_lock_irq(shost->host_lock);
4758 ndlp->nlp_flag &= ~NLP_LOGO_SND;
4759 spin_unlock_irq(shost->host_lock);
4760 lpfc_els_free_iocb(phba, elsiocb);
4761 return 1;
4762 }
4763 return 0;
4764}
4765
4766void
4767lpfc_fabric_block_timeout(unsigned long ptr)
4768{
4769 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
4770 unsigned long iflags;
4771 uint32_t tmo_posted;
4772 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
4773 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
4774 if (!tmo_posted)
4775 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
4776 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
4777
4778 if (!tmo_posted) {
4779 spin_lock_irqsave(&phba->hbalock, iflags);
4780 if (phba->work_wait)
4781 lpfc_worker_wake_up(phba);
4782 spin_unlock_irqrestore(&phba->hbalock, iflags);
4783 }
4784}
4785
4786static void
4787lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
4788{
4789 struct lpfc_iocbq *iocb;
4790 unsigned long iflags;
4791 int ret;
4792 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
4793 IOCB_t *cmd;
4794
4795repeat:
4796 iocb = NULL;
4797 spin_lock_irqsave(&phba->hbalock, iflags);
4798 /* Post any pending iocb to the SLI layer */
4799 if (atomic_read(&phba->fabric_iocb_count) == 0) {
4800 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
4801 list);
4802 if (iocb)
4803 atomic_inc(&phba->fabric_iocb_count);
4804 }
4805 spin_unlock_irqrestore(&phba->hbalock, iflags);
4806 if (iocb) {
4807 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
4808 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
4809 iocb->iocb_flag |= LPFC_IO_FABRIC;
4810
James Smart858c9f62007-06-17 19:56:39 -05004811 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
4812 "Fabric sched1: ste:x%x",
4813 iocb->vport->port_state, 0, 0);
4814
James Smart92d7f7b2007-06-17 19:56:38 -05004815 ret = lpfc_sli_issue_iocb(phba, pring, iocb, 0);
4816
4817 if (ret == IOCB_ERROR) {
4818 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
4819 iocb->fabric_iocb_cmpl = NULL;
4820 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
4821 cmd = &iocb->iocb;
4822 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
4823 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
4824 iocb->iocb_cmpl(phba, iocb, iocb);
4825
4826 atomic_dec(&phba->fabric_iocb_count);
4827 goto repeat;
4828 }
4829 }
4830
4831 return;
4832}
4833
4834void
4835lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
4836{
4837 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
4838
4839 lpfc_resume_fabric_iocbs(phba);
4840 return;
4841}
4842
4843static void
4844lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
4845{
4846 int blocked;
4847
4848 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
4849 /* Start a timer to unblock fabric
4850 * iocbs after 100ms
4851 */
4852 if (!blocked)
4853 mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 );
4854
4855 return;
4856}
4857
4858static void
4859lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4860 struct lpfc_iocbq *rspiocb)
4861{
4862 struct ls_rjt stat;
4863
4864 if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
4865 BUG();
4866
4867 switch (rspiocb->iocb.ulpStatus) {
4868 case IOSTAT_NPORT_RJT:
4869 case IOSTAT_FABRIC_RJT:
4870 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
4871 lpfc_block_fabric_iocbs(phba);
4872 }
4873 break;
4874
4875 case IOSTAT_NPORT_BSY:
4876 case IOSTAT_FABRIC_BSY:
4877 lpfc_block_fabric_iocbs(phba);
4878 break;
4879
4880 case IOSTAT_LS_RJT:
4881 stat.un.lsRjtError =
4882 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
4883 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
4884 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
4885 lpfc_block_fabric_iocbs(phba);
4886 break;
4887 }
4888
4889 if (atomic_read(&phba->fabric_iocb_count) == 0)
4890 BUG();
4891
4892 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
4893 cmdiocb->fabric_iocb_cmpl = NULL;
4894 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
4895 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
4896
4897 atomic_dec(&phba->fabric_iocb_count);
4898 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
4899 /* Post any pending iocbs to HBA */
4900 lpfc_resume_fabric_iocbs(phba);
4901 }
4902}
4903
Adrian Bunka6ababd2007-11-05 18:07:33 +01004904static int
James Smart92d7f7b2007-06-17 19:56:38 -05004905lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
4906{
4907 unsigned long iflags;
4908 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
4909 int ready;
4910 int ret;
4911
4912 if (atomic_read(&phba->fabric_iocb_count) > 1)
4913 BUG();
4914
4915 spin_lock_irqsave(&phba->hbalock, iflags);
4916 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
4917 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
4918
4919 spin_unlock_irqrestore(&phba->hbalock, iflags);
4920 if (ready) {
4921 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
4922 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
4923 iocb->iocb_flag |= LPFC_IO_FABRIC;
4924
James Smart858c9f62007-06-17 19:56:39 -05004925 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
4926 "Fabric sched2: ste:x%x",
4927 iocb->vport->port_state, 0, 0);
4928
James Smart92d7f7b2007-06-17 19:56:38 -05004929 atomic_inc(&phba->fabric_iocb_count);
4930 ret = lpfc_sli_issue_iocb(phba, pring, iocb, 0);
4931
4932 if (ret == IOCB_ERROR) {
4933 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
4934 iocb->fabric_iocb_cmpl = NULL;
4935 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
4936 atomic_dec(&phba->fabric_iocb_count);
4937 }
4938 } else {
4939 spin_lock_irqsave(&phba->hbalock, iflags);
4940 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
4941 spin_unlock_irqrestore(&phba->hbalock, iflags);
4942 ret = IOCB_SUCCESS;
4943 }
4944 return ret;
4945}
4946
4947
Adrian Bunka6ababd2007-11-05 18:07:33 +01004948static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
James Smart92d7f7b2007-06-17 19:56:38 -05004949{
4950 LIST_HEAD(completions);
4951 struct lpfc_hba *phba = vport->phba;
4952 struct lpfc_iocbq *tmp_iocb, *piocb;
4953 IOCB_t *cmd;
4954
4955 spin_lock_irq(&phba->hbalock);
4956 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
4957 list) {
4958
4959 if (piocb->vport != vport)
4960 continue;
4961
4962 list_move_tail(&piocb->list, &completions);
4963 }
4964 spin_unlock_irq(&phba->hbalock);
4965
4966 while (!list_empty(&completions)) {
4967 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
4968 list_del_init(&piocb->list);
4969
4970 cmd = &piocb->iocb;
4971 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
4972 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
4973 (piocb->iocb_cmpl) (phba, piocb, piocb);
4974 }
4975}
4976
4977void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
4978{
4979 LIST_HEAD(completions);
4980 struct lpfc_hba *phba = ndlp->vport->phba;
4981 struct lpfc_iocbq *tmp_iocb, *piocb;
4982 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
4983 IOCB_t *cmd;
4984
4985 spin_lock_irq(&phba->hbalock);
4986 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
4987 list) {
4988 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
4989
4990 list_move_tail(&piocb->list, &completions);
4991 }
4992 }
4993 spin_unlock_irq(&phba->hbalock);
4994
4995 while (!list_empty(&completions)) {
4996 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
4997 list_del_init(&piocb->list);
4998
4999 cmd = &piocb->iocb;
5000 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
5001 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
5002 (piocb->iocb_cmpl) (phba, piocb, piocb);
5003 }
5004}
5005
5006void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
5007{
5008 LIST_HEAD(completions);
5009 struct lpfc_iocbq *piocb;
5010 IOCB_t *cmd;
5011
5012 spin_lock_irq(&phba->hbalock);
5013 list_splice_init(&phba->fabric_iocb_list, &completions);
5014 spin_unlock_irq(&phba->hbalock);
5015
5016 while (!list_empty(&completions)) {
5017 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
5018 list_del_init(&piocb->list);
5019
5020 cmd = &piocb->iocb;
5021 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
5022 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
5023 (piocb->iocb_cmpl) (phba, piocb, piocb);
5024 }
5025}
5026
5027
Adrian Bunka6ababd2007-11-05 18:07:33 +01005028#if 0
James Smart92d7f7b2007-06-17 19:56:38 -05005029void lpfc_fabric_abort_flogi(struct lpfc_hba *phba)
5030{
5031 LIST_HEAD(completions);
5032 struct lpfc_iocbq *tmp_iocb, *piocb;
5033 IOCB_t *cmd;
5034 struct lpfc_nodelist *ndlp;
5035
5036 spin_lock_irq(&phba->hbalock);
5037 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
5038 list) {
5039
5040 cmd = &piocb->iocb;
5041 ndlp = (struct lpfc_nodelist *) piocb->context1;
5042 if (cmd->ulpCommand == CMD_ELS_REQUEST64_CR &&
5043 ndlp != NULL &&
5044 ndlp->nlp_DID == Fabric_DID)
5045 list_move_tail(&piocb->list, &completions);
5046 }
5047 spin_unlock_irq(&phba->hbalock);
5048
5049 while (!list_empty(&completions)) {
5050 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
5051 list_del_init(&piocb->list);
5052
5053 cmd = &piocb->iocb;
5054 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
5055 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
5056 (piocb->iocb_cmpl) (phba, piocb, piocb);
5057 }
5058}
Adrian Bunka6ababd2007-11-05 18:07:33 +01005059#endif /* 0 */
James Smart92d7f7b2007-06-17 19:56:38 -05005060
5061