blob: d418c7c1251ee541b2d7a211282d9046d3813f33 [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 Smart58da1ff2008-04-07 10:15:56 -0400722 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
723 (ndlp->nlp_DID == Fabric_DID))
James Smart07951072007-04-25 09:51:38 -0400724 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
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 Smart58da1ff2008-04-07 10:15:56 -0400832 uint32_t rc, keepDID = 0;
James Smart488d1462006-03-07 15:02:37 -0500833
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)) {
James Smart58da1ff2008-04-07 10:15:56 -0400861 rc = memcmp(&ndlp->nlp_portname, name,
862 sizeof(struct lpfc_name));
863 if (!rc)
864 return ndlp;
James Smarte47c9092008-02-08 18:49:26 -0500865 new_ndlp = lpfc_enable_node(vport, new_ndlp,
866 NLP_STE_UNUSED_NODE);
867 if (!new_ndlp)
868 return ndlp;
James Smart58da1ff2008-04-07 10:15:56 -0400869 keepDID = new_ndlp->nlp_DID;
870 } else
871 keepDID = new_ndlp->nlp_DID;
James Smart488d1462006-03-07 15:02:37 -0500872
James Smart2e0fef82007-06-17 19:56:36 -0500873 lpfc_unreg_rpi(vport, new_ndlp);
James Smart488d1462006-03-07 15:02:37 -0500874 new_ndlp->nlp_DID = ndlp->nlp_DID;
James Smart92795652006-07-06 15:50:02 -0400875 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
James Smart0ff10d42008-01-11 01:52:36 -0500876
877 if (ndlp->nlp_flag & NLP_NPR_2B_DISC)
878 new_ndlp->nlp_flag |= NLP_NPR_2B_DISC;
879 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
880
James Smarte47c9092008-02-08 18:49:26 -0500881 /* Set state will put new_ndlp on to node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -0500882 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
James Smart488d1462006-03-07 15:02:37 -0500883
James Smart2e0fef82007-06-17 19:56:36 -0500884 /* Move this back to NPR state */
James Smart87af33f2007-10-27 13:37:43 -0400885 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
886 /* The new_ndlp is replacing ndlp totally, so we need
887 * to put ndlp on UNUSED list and try to free it.
888 */
James Smart0ff10d42008-01-11 01:52:36 -0500889
890 /* Fix up the rport accordingly */
891 rport = ndlp->rport;
892 if (rport) {
893 rdata = rport->dd_data;
894 if (rdata->pnode == ndlp) {
895 lpfc_nlp_put(ndlp);
896 ndlp->rport = NULL;
897 rdata->pnode = lpfc_nlp_get(new_ndlp);
898 new_ndlp->rport = rport;
899 }
900 new_ndlp->nlp_type = ndlp->nlp_type;
901 }
James Smart58da1ff2008-04-07 10:15:56 -0400902 /* We shall actually free the ndlp with both nlp_DID and
903 * nlp_portname fields equals 0 to avoid any ndlp on the
904 * nodelist never to be used.
905 */
906 if (ndlp->nlp_DID == 0) {
907 spin_lock_irq(&phba->ndlp_lock);
908 NLP_SET_FREE_REQ(ndlp);
909 spin_unlock_irq(&phba->ndlp_lock);
910 }
James Smart0ff10d42008-01-11 01:52:36 -0500911
James Smart58da1ff2008-04-07 10:15:56 -0400912 /* Two ndlps cannot have the same did on the nodelist */
913 ndlp->nlp_DID = keepDID;
James Smart2e0fef82007-06-17 19:56:36 -0500914 lpfc_drop_node(vport, ndlp);
James Smart87af33f2007-10-27 13:37:43 -0400915 }
James Smart92795652006-07-06 15:50:02 -0400916 else {
James Smart2e0fef82007-06-17 19:56:36 -0500917 lpfc_unreg_rpi(vport, ndlp);
James Smart58da1ff2008-04-07 10:15:56 -0400918 /* Two ndlps cannot have the same did */
919 ndlp->nlp_DID = keepDID;
James Smart2e0fef82007-06-17 19:56:36 -0500920 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smart92795652006-07-06 15:50:02 -0400921 }
James Smart488d1462006-03-07 15:02:37 -0500922 return new_ndlp;
923}
924
James Smart87af33f2007-10-27 13:37:43 -0400925void
926lpfc_end_rscn(struct lpfc_vport *vport)
927{
928 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
929
930 if (vport->fc_flag & FC_RSCN_MODE) {
931 /*
932 * Check to see if more RSCNs came in while we were
933 * processing this one.
934 */
935 if (vport->fc_rscn_id_cnt ||
936 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
937 lpfc_els_handle_rscn(vport);
938 else {
939 spin_lock_irq(shost->host_lock);
940 vport->fc_flag &= ~FC_RSCN_MODE;
941 spin_unlock_irq(shost->host_lock);
942 }
943 }
944}
945
dea31012005-04-17 16:05:31 -0500946static void
James Smart2e0fef82007-06-17 19:56:36 -0500947lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
948 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500949{
James Smart2e0fef82007-06-17 19:56:36 -0500950 struct lpfc_vport *vport = cmdiocb->vport;
951 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500952 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -0500953 struct lpfc_nodelist *ndlp;
James Smart92795652006-07-06 15:50:02 -0400954 struct lpfc_dmabuf *prsp;
dea31012005-04-17 16:05:31 -0500955 int disc, rc, did, type;
956
dea31012005-04-17 16:05:31 -0500957 /* we pass cmdiocb to state machine which needs rspiocb as well */
958 cmdiocb->context_un.rsp_iocb = rspiocb;
959
960 irsp = &rspiocb->iocb;
James Smart858c9f62007-06-17 19:56:39 -0500961 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
962 "PLOGI cmpl: status:x%x/x%x did:x%x",
963 irsp->ulpStatus, irsp->un.ulpWord[4],
964 irsp->un.elsreq64.remoteID);
965
James Smart2e0fef82007-06-17 19:56:36 -0500966 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
James Smarte47c9092008-02-08 18:49:26 -0500967 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smarte8b62012007-08-02 11:10:09 -0400968 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
969 "0136 PLOGI completes to NPort x%x "
970 "with no ndlp. Data: x%x x%x x%x\n",
971 irsp->un.elsreq64.remoteID,
972 irsp->ulpStatus, irsp->un.ulpWord[4],
973 irsp->ulpIoTag);
James Smart488d1462006-03-07 15:02:37 -0500974 goto out;
James Smarted957682007-06-17 19:56:37 -0500975 }
dea31012005-04-17 16:05:31 -0500976
977 /* Since ndlp can be freed in the disc state machine, note if this node
978 * is being used during discovery.
979 */
James Smart2e0fef82007-06-17 19:56:36 -0500980 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500981 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
James Smart488d1462006-03-07 15:02:37 -0500982 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500983 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500984 rc = 0;
985
986 /* PLOGI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -0400987 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
988 "0102 PLOGI completes to NPort x%x "
989 "Data: x%x x%x x%x x%x x%x\n",
990 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
991 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -0500992 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500993 if (lpfc_els_chk_latt(vport)) {
994 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500995 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500996 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500997 goto out;
998 }
999
1000 /* ndlp could be freed in DSM, save these values now */
1001 type = ndlp->nlp_type;
1002 did = ndlp->nlp_DID;
1003
1004 if (irsp->ulpStatus) {
1005 /* Check for retry */
1006 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1007 /* ELS command is being retried */
1008 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05001009 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001010 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001011 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001012 }
1013 goto out;
1014 }
dea31012005-04-17 16:05:31 -05001015 /* PLOGI failed */
1016 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001017 if (lpfc_error_lost_link(irsp))
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001018 rc = NLP_STE_FREED_NODE;
James Smarte47c9092008-02-08 18:49:26 -05001019 else
James Smart2e0fef82007-06-17 19:56:36 -05001020 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001021 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001022 } else {
1023 /* Good status, call state machine */
James Smart92795652006-07-06 15:50:02 -04001024 prsp = list_entry(((struct lpfc_dmabuf *)
James Smart92d7f7b2007-06-17 19:56:38 -05001025 cmdiocb->context2)->list.next,
1026 struct lpfc_dmabuf, list);
1027 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05001028 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001029 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001030 }
1031
James Smart2e0fef82007-06-17 19:56:36 -05001032 if (disc && vport->num_disc_nodes) {
dea31012005-04-17 16:05:31 -05001033 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001034 lpfc_more_plogi(vport);
dea31012005-04-17 16:05:31 -05001035
James Smart2e0fef82007-06-17 19:56:36 -05001036 if (vport->num_disc_nodes == 0) {
1037 spin_lock_irq(shost->host_lock);
1038 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1039 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001040
James Smart2e0fef82007-06-17 19:56:36 -05001041 lpfc_can_disctmo(vport);
James Smart87af33f2007-10-27 13:37:43 -04001042 lpfc_end_rscn(vport);
dea31012005-04-17 16:05:31 -05001043 }
1044 }
1045
1046out:
1047 lpfc_els_free_iocb(phba, cmdiocb);
1048 return;
1049}
1050
1051int
James Smart2e0fef82007-06-17 19:56:36 -05001052lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
dea31012005-04-17 16:05:31 -05001053{
James Smart2e0fef82007-06-17 19:56:36 -05001054 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001055 struct serv_parm *sp;
1056 IOCB_t *icmd;
James Smart98c9ea52007-10-27 13:37:33 -04001057 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05001058 struct lpfc_iocbq *elsiocb;
1059 struct lpfc_sli_ring *pring;
1060 struct lpfc_sli *psli;
1061 uint8_t *pcmd;
1062 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05001063 int ret;
dea31012005-04-17 16:05:31 -05001064
1065 psli = &phba->sli;
1066 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1067
James Smart98c9ea52007-10-27 13:37:33 -04001068 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05001069 if (ndlp && !NLP_CHK_NODE_ACT(ndlp))
1070 ndlp = NULL;
James Smart98c9ea52007-10-27 13:37:33 -04001071
James Smarte47c9092008-02-08 18:49:26 -05001072 /* If ndlp is not NULL, we will bump the reference count on it */
James Smart92d7f7b2007-06-17 19:56:38 -05001073 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart98c9ea52007-10-27 13:37:33 -04001074 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
James Smart2e0fef82007-06-17 19:56:36 -05001075 ELS_CMD_PLOGI);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001076 if (!elsiocb)
1077 return 1;
dea31012005-04-17 16:05:31 -05001078
1079 icmd = &elsiocb->iocb;
1080 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1081
1082 /* For PLOGI request, remainder of payload is service parameters */
1083 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001084 pcmd += sizeof(uint32_t);
1085 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001086 sp = (struct serv_parm *) pcmd;
1087
1088 if (sp->cmn.fcphLow < FC_PH_4_3)
1089 sp->cmn.fcphLow = FC_PH_4_3;
1090
1091 if (sp->cmn.fcphHigh < FC_PH3)
1092 sp->cmn.fcphHigh = FC_PH3;
1093
James Smart858c9f62007-06-17 19:56:39 -05001094 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1095 "Issue PLOGI: did:x%x",
1096 did, 0, 0);
1097
dea31012005-04-17 16:05:31 -05001098 phba->fc_stat.elsXmitPLOGI++;
1099 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
James Smart92d7f7b2007-06-17 19:56:38 -05001100 ret = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
1101
1102 if (ret == IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05001103 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001104 return 1;
dea31012005-04-17 16:05:31 -05001105 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001106 return 0;
dea31012005-04-17 16:05:31 -05001107}
1108
1109static void
James Smart2e0fef82007-06-17 19:56:36 -05001110lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1111 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001112{
James Smart2e0fef82007-06-17 19:56:36 -05001113 struct lpfc_vport *vport = cmdiocb->vport;
1114 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001115 IOCB_t *irsp;
1116 struct lpfc_sli *psli;
1117 struct lpfc_nodelist *ndlp;
1118
1119 psli = &phba->sli;
1120 /* we pass cmdiocb to state machine which needs rspiocb as well */
1121 cmdiocb->context_un.rsp_iocb = rspiocb;
1122
1123 irsp = &(rspiocb->iocb);
1124 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
James Smart2e0fef82007-06-17 19:56:36 -05001125 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001126 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001127 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001128
James Smart858c9f62007-06-17 19:56:39 -05001129 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1130 "PRLI cmpl: status:x%x/x%x did:x%x",
1131 irsp->ulpStatus, irsp->un.ulpWord[4],
1132 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05001133 /* PRLI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001134 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1135 "0103 PRLI completes to NPort x%x "
1136 "Data: x%x x%x x%x x%x\n",
1137 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1138 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001139
James Smart2e0fef82007-06-17 19:56:36 -05001140 vport->fc_prli_sent--;
dea31012005-04-17 16:05:31 -05001141 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001142 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05001143 goto out;
1144
1145 if (irsp->ulpStatus) {
1146 /* Check for retry */
1147 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1148 /* ELS command is being retried */
1149 goto out;
1150 }
1151 /* PRLI failed */
1152 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001153 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05001154 goto out;
James Smarte47c9092008-02-08 18:49:26 -05001155 else
James Smart2e0fef82007-06-17 19:56:36 -05001156 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001157 NLP_EVT_CMPL_PRLI);
James Smarte47c9092008-02-08 18:49:26 -05001158 } else
dea31012005-04-17 16:05:31 -05001159 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05001160 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001161 NLP_EVT_CMPL_PRLI);
dea31012005-04-17 16:05:31 -05001162out:
1163 lpfc_els_free_iocb(phba, cmdiocb);
1164 return;
1165}
1166
1167int
James Smart2e0fef82007-06-17 19:56:36 -05001168lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001169 uint8_t retry)
1170{
James Smart2e0fef82007-06-17 19:56:36 -05001171 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1172 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001173 PRLI *npr;
1174 IOCB_t *icmd;
1175 struct lpfc_iocbq *elsiocb;
1176 struct lpfc_sli_ring *pring;
1177 struct lpfc_sli *psli;
1178 uint8_t *pcmd;
1179 uint16_t cmdsize;
1180
1181 psli = &phba->sli;
1182 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1183
James Smart92d7f7b2007-06-17 19:56:38 -05001184 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
James Smart2e0fef82007-06-17 19:56:36 -05001185 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1186 ndlp->nlp_DID, ELS_CMD_PRLI);
James Smart488d1462006-03-07 15:02:37 -05001187 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001188 return 1;
dea31012005-04-17 16:05:31 -05001189
1190 icmd = &elsiocb->iocb;
1191 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1192
1193 /* For PRLI request, remainder of payload is service parameters */
James Smart92d7f7b2007-06-17 19:56:38 -05001194 memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t)));
dea31012005-04-17 16:05:31 -05001195 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
James Smart92d7f7b2007-06-17 19:56:38 -05001196 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001197
1198 /* For PRLI, remainder of payload is PRLI parameter page */
1199 npr = (PRLI *) pcmd;
1200 /*
1201 * If our firmware version is 3.20 or later,
1202 * set the following bits for FC-TAPE support.
1203 */
1204 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
1205 npr->ConfmComplAllowed = 1;
1206 npr->Retry = 1;
1207 npr->TaskRetryIdReq = 1;
1208 }
1209 npr->estabImagePair = 1;
1210 npr->readXferRdyDis = 1;
1211
1212 /* For FCP support */
1213 npr->prliType = PRLI_FCP_TYPE;
1214 npr->initiatorFunc = 1;
1215
James Smart858c9f62007-06-17 19:56:39 -05001216 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1217 "Issue PRLI: did:x%x",
1218 ndlp->nlp_DID, 0, 0);
1219
dea31012005-04-17 16:05:31 -05001220 phba->fc_stat.elsXmitPRLI++;
1221 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
James Smart2e0fef82007-06-17 19:56:36 -05001222 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001223 ndlp->nlp_flag |= NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001224 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001225 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05001226 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001227 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001228 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001229 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001230 return 1;
dea31012005-04-17 16:05:31 -05001231 }
James Smart2e0fef82007-06-17 19:56:36 -05001232 vport->fc_prli_sent++;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001233 return 0;
dea31012005-04-17 16:05:31 -05001234}
1235
James Smart0ff10d42008-01-11 01:52:36 -05001236void
James Smart2e0fef82007-06-17 19:56:36 -05001237lpfc_more_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001238{
1239 int sentadisc;
1240
James Smart2e0fef82007-06-17 19:56:36 -05001241 if (vport->num_disc_nodes)
1242 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001243 /* Continue discovery with <num_disc_nodes> ADISCs to go */
James Smarte8b62012007-08-02 11:10:09 -04001244 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1245 "0210 Continue discovery with %d ADISCs to go "
1246 "Data: x%x x%x x%x\n",
1247 vport->num_disc_nodes, vport->fc_adisc_cnt,
1248 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001249 /* Check to see if there are more ADISCs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001250 if (vport->fc_flag & FC_NLP_MORE) {
1251 lpfc_set_disctmo(vport);
1252 /* go thru NPR nodes and issue any remaining ELS ADISCs */
1253 sentadisc = lpfc_els_disc_adisc(vport);
dea31012005-04-17 16:05:31 -05001254 }
1255 return;
1256}
1257
1258static void
James Smart2e0fef82007-06-17 19:56:36 -05001259lpfc_rscn_disc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001260{
James Smart858c9f62007-06-17 19:56:39 -05001261 lpfc_can_disctmo(vport);
1262
dea31012005-04-17 16:05:31 -05001263 /* RSCN discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001264 /* go thru NPR nodes and issue ELS PLOGIs */
1265 if (vport->fc_npr_cnt)
1266 if (lpfc_els_disc_plogi(vport))
dea31012005-04-17 16:05:31 -05001267 return;
James Smart2e0fef82007-06-17 19:56:36 -05001268
James Smart87af33f2007-10-27 13:37:43 -04001269 lpfc_end_rscn(vport);
dea31012005-04-17 16:05:31 -05001270}
1271
1272static void
James Smart2e0fef82007-06-17 19:56:36 -05001273lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1274 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001275{
James Smart2e0fef82007-06-17 19:56:36 -05001276 struct lpfc_vport *vport = cmdiocb->vport;
1277 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001278 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001279 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001280 int disc;
dea31012005-04-17 16:05:31 -05001281
1282 /* we pass cmdiocb to state machine which needs rspiocb as well */
1283 cmdiocb->context_un.rsp_iocb = rspiocb;
1284
1285 irsp = &(rspiocb->iocb);
1286 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
dea31012005-04-17 16:05:31 -05001287
James Smart858c9f62007-06-17 19:56:39 -05001288 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1289 "ADISC cmpl: status:x%x/x%x did:x%x",
1290 irsp->ulpStatus, irsp->un.ulpWord[4],
1291 ndlp->nlp_DID);
1292
dea31012005-04-17 16:05:31 -05001293 /* Since ndlp can be freed in the disc state machine, note if this node
1294 * is being used during discovery.
1295 */
James Smart2e0fef82007-06-17 19:56:36 -05001296 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001297 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001298 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001299 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001300 /* ADISC completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001301 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1302 "0104 ADISC completes to NPort x%x "
1303 "Data: x%x x%x x%x x%x x%x\n",
1304 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1305 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001306 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001307 if (lpfc_els_chk_latt(vport)) {
1308 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001309 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001310 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001311 goto out;
1312 }
1313
1314 if (irsp->ulpStatus) {
1315 /* Check for retry */
1316 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1317 /* ELS command is being retried */
1318 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05001319 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001320 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001321 spin_unlock_irq(shost->host_lock);
1322 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001323 }
1324 goto out;
1325 }
1326 /* ADISC failed */
1327 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001328 if (!lpfc_error_lost_link(irsp))
James Smart2e0fef82007-06-17 19:56:36 -05001329 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart858c9f62007-06-17 19:56:39 -05001330 NLP_EVT_CMPL_ADISC);
James Smarte47c9092008-02-08 18:49:26 -05001331 } else
dea31012005-04-17 16:05:31 -05001332 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05001333 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
dea31012005-04-17 16:05:31 -05001334 NLP_EVT_CMPL_ADISC);
dea31012005-04-17 16:05:31 -05001335
James Smart2e0fef82007-06-17 19:56:36 -05001336 if (disc && vport->num_disc_nodes) {
dea31012005-04-17 16:05:31 -05001337 /* Check to see if there are more ADISCs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001338 lpfc_more_adisc(vport);
dea31012005-04-17 16:05:31 -05001339
1340 /* Check to see if we are done with ADISC authentication */
James Smart2e0fef82007-06-17 19:56:36 -05001341 if (vport->num_disc_nodes == 0) {
James Smart92d7f7b2007-06-17 19:56:38 -05001342 /* If we get here, there is nothing left to ADISC */
1343 /*
1344 * For NPIV, cmpl_reg_vpi will set port_state to READY,
1345 * and continue discovery.
1346 */
1347 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
1348 !(vport->fc_flag & FC_RSCN_MODE)) {
1349 lpfc_issue_reg_vpi(phba, vport);
1350 goto out;
1351 }
1352 /*
1353 * For SLI2, we need to set port_state to READY
1354 * and continue discovery.
1355 */
1356 if (vport->port_state < LPFC_VPORT_READY) {
1357 /* If we get here, there is nothing to ADISC */
James Smarted957682007-06-17 19:56:37 -05001358 if (vport->port_type == LPFC_PHYSICAL_PORT)
James Smart2e0fef82007-06-17 19:56:36 -05001359 lpfc_issue_clear_la(phba, vport);
James Smart92d7f7b2007-06-17 19:56:38 -05001360
1361 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
1362 vport->num_disc_nodes = 0;
1363 /* go thru NPR list, issue ELS PLOGIs */
1364 if (vport->fc_npr_cnt)
1365 lpfc_els_disc_plogi(vport);
1366
1367 if (!vport->num_disc_nodes) {
1368 spin_lock_irq(shost->host_lock);
1369 vport->fc_flag &=
1370 ~FC_NDISC_ACTIVE;
1371 spin_unlock_irq(
1372 shost->host_lock);
1373 lpfc_can_disctmo(vport);
1374 }
1375 }
1376 vport->port_state = LPFC_VPORT_READY;
dea31012005-04-17 16:05:31 -05001377 } else {
James Smart2e0fef82007-06-17 19:56:36 -05001378 lpfc_rscn_disc(vport);
dea31012005-04-17 16:05:31 -05001379 }
1380 }
1381 }
dea31012005-04-17 16:05:31 -05001382out:
1383 lpfc_els_free_iocb(phba, cmdiocb);
1384 return;
1385}
1386
1387int
James Smart2e0fef82007-06-17 19:56:36 -05001388lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001389 uint8_t retry)
1390{
James Smart2e0fef82007-06-17 19:56:36 -05001391 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1392 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001393 ADISC *ap;
1394 IOCB_t *icmd;
1395 struct lpfc_iocbq *elsiocb;
James Smart2e0fef82007-06-17 19:56:36 -05001396 struct lpfc_sli *psli = &phba->sli;
1397 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05001398 uint8_t *pcmd;
1399 uint16_t cmdsize;
1400
James Smart92d7f7b2007-06-17 19:56:38 -05001401 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
James Smart2e0fef82007-06-17 19:56:36 -05001402 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1403 ndlp->nlp_DID, ELS_CMD_ADISC);
James Smart488d1462006-03-07 15:02:37 -05001404 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001405 return 1;
dea31012005-04-17 16:05:31 -05001406
1407 icmd = &elsiocb->iocb;
1408 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1409
1410 /* For ADISC request, remainder of payload is service parameters */
1411 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
James Smart92d7f7b2007-06-17 19:56:38 -05001412 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001413
1414 /* Fill in ADISC payload */
1415 ap = (ADISC *) pcmd;
1416 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05001417 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
1418 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05001419 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05001420
James Smart858c9f62007-06-17 19:56:39 -05001421 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1422 "Issue ADISC: did:x%x",
1423 ndlp->nlp_DID, 0, 0);
1424
dea31012005-04-17 16:05:31 -05001425 phba->fc_stat.elsXmitADISC++;
1426 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
James Smart2e0fef82007-06-17 19:56:36 -05001427 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001428 ndlp->nlp_flag |= NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001429 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001430 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05001431 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001432 ndlp->nlp_flag &= ~NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001433 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001434 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001435 return 1;
dea31012005-04-17 16:05:31 -05001436 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001437 return 0;
dea31012005-04-17 16:05:31 -05001438}
1439
1440static void
James Smart2e0fef82007-06-17 19:56:36 -05001441lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1442 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001443{
James Smart2e0fef82007-06-17 19:56:36 -05001444 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1445 struct lpfc_vport *vport = ndlp->vport;
1446 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001447 IOCB_t *irsp;
1448 struct lpfc_sli *psli;
dea31012005-04-17 16:05:31 -05001449
1450 psli = &phba->sli;
1451 /* we pass cmdiocb to state machine which needs rspiocb as well */
1452 cmdiocb->context_un.rsp_iocb = rspiocb;
1453
1454 irsp = &(rspiocb->iocb);
James Smart2e0fef82007-06-17 19:56:36 -05001455 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001456 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001457 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001458
James Smart858c9f62007-06-17 19:56:39 -05001459 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1460 "LOGO cmpl: status:x%x/x%x did:x%x",
1461 irsp->ulpStatus, irsp->un.ulpWord[4],
1462 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05001463 /* LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001464 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1465 "0105 LOGO completes to NPort x%x "
1466 "Data: x%x x%x x%x x%x\n",
1467 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1468 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001469 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001470 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05001471 goto out;
1472
James Smart92d7f7b2007-06-17 19:56:38 -05001473 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
1474 /* NLP_EVT_DEVICE_RM should unregister the RPI
1475 * which should abort all outstanding IOs.
1476 */
1477 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1478 NLP_EVT_DEVICE_RM);
1479 goto out;
1480 }
1481
dea31012005-04-17 16:05:31 -05001482 if (irsp->ulpStatus) {
1483 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -05001484 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -05001485 /* ELS command is being retried */
1486 goto out;
dea31012005-04-17 16:05:31 -05001487 /* LOGO failed */
1488 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart858c9f62007-06-17 19:56:39 -05001489 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05001490 goto out;
James Smart858c9f62007-06-17 19:56:39 -05001491 else
James Smart2e0fef82007-06-17 19:56:36 -05001492 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001493 NLP_EVT_CMPL_LOGO);
James Smarte47c9092008-02-08 18:49:26 -05001494 } else
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001495 /* Good status, call state machine.
1496 * This will unregister the rpi if needed.
1497 */
James Smart2e0fef82007-06-17 19:56:36 -05001498 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001499 NLP_EVT_CMPL_LOGO);
dea31012005-04-17 16:05:31 -05001500out:
1501 lpfc_els_free_iocb(phba, cmdiocb);
1502 return;
1503}
1504
1505int
James Smart2e0fef82007-06-17 19:56:36 -05001506lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001507 uint8_t retry)
1508{
James Smart2e0fef82007-06-17 19:56:36 -05001509 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1510 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001511 IOCB_t *icmd;
1512 struct lpfc_iocbq *elsiocb;
1513 struct lpfc_sli_ring *pring;
1514 struct lpfc_sli *psli;
1515 uint8_t *pcmd;
1516 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05001517 int rc;
dea31012005-04-17 16:05:31 -05001518
1519 psli = &phba->sli;
1520 pring = &psli->ring[LPFC_ELS_RING];
1521
James Smart98c9ea52007-10-27 13:37:33 -04001522 spin_lock_irq(shost->host_lock);
1523 if (ndlp->nlp_flag & NLP_LOGO_SND) {
1524 spin_unlock_irq(shost->host_lock);
1525 return 0;
1526 }
1527 spin_unlock_irq(shost->host_lock);
1528
James Smart92d7f7b2007-06-17 19:56:38 -05001529 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
James Smart2e0fef82007-06-17 19:56:36 -05001530 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1531 ndlp->nlp_DID, ELS_CMD_LOGO);
James Smart488d1462006-03-07 15:02:37 -05001532 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001533 return 1;
dea31012005-04-17 16:05:31 -05001534
1535 icmd = &elsiocb->iocb;
1536 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1537 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
James Smart92d7f7b2007-06-17 19:56:38 -05001538 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001539
1540 /* Fill in LOGO payload */
James Smart2e0fef82007-06-17 19:56:36 -05001541 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05001542 pcmd += sizeof(uint32_t);
1543 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05001544
James Smart858c9f62007-06-17 19:56:39 -05001545 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1546 "Issue LOGO: did:x%x",
1547 ndlp->nlp_DID, 0, 0);
1548
dea31012005-04-17 16:05:31 -05001549 phba->fc_stat.elsXmitLOGO++;
1550 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
James Smart2e0fef82007-06-17 19:56:36 -05001551 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001552 ndlp->nlp_flag |= NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001553 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05001554 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
1555
1556 if (rc == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05001557 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001558 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001559 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001560 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001561 return 1;
dea31012005-04-17 16:05:31 -05001562 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001563 return 0;
dea31012005-04-17 16:05:31 -05001564}
1565
1566static void
James Smart2e0fef82007-06-17 19:56:36 -05001567lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1568 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001569{
James Smart2e0fef82007-06-17 19:56:36 -05001570 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -05001571 IOCB_t *irsp;
1572
1573 irsp = &rspiocb->iocb;
1574
James Smart858c9f62007-06-17 19:56:39 -05001575 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1576 "ELS cmd cmpl: status:x%x/x%x did:x%x",
1577 irsp->ulpStatus, irsp->un.ulpWord[4],
1578 irsp->un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05001579 /* ELS cmd tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04001580 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1581 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
1582 irsp->ulpIoTag, irsp->ulpStatus,
1583 irsp->un.ulpWord[4], irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -05001584 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001585 lpfc_els_chk_latt(vport);
dea31012005-04-17 16:05:31 -05001586 lpfc_els_free_iocb(phba, cmdiocb);
1587 return;
1588}
1589
1590int
James Smart2e0fef82007-06-17 19:56:36 -05001591lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05001592{
James Smart2e0fef82007-06-17 19:56:36 -05001593 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001594 IOCB_t *icmd;
1595 struct lpfc_iocbq *elsiocb;
1596 struct lpfc_sli_ring *pring;
1597 struct lpfc_sli *psli;
1598 uint8_t *pcmd;
1599 uint16_t cmdsize;
1600 struct lpfc_nodelist *ndlp;
1601
1602 psli = &phba->sli;
1603 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
James Smart92d7f7b2007-06-17 19:56:38 -05001604 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
dea31012005-04-17 16:05:31 -05001605
James Smarte47c9092008-02-08 18:49:26 -05001606 ndlp = lpfc_findnode_did(vport, nportid);
1607 if (!ndlp) {
1608 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1609 if (!ndlp)
1610 return 1;
1611 lpfc_nlp_init(vport, ndlp, nportid);
1612 lpfc_enqueue_node(vport, ndlp);
1613 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1614 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1615 if (!ndlp)
1616 return 1;
1617 }
dea31012005-04-17 16:05:31 -05001618
James Smart2e0fef82007-06-17 19:56:36 -05001619 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1620 ndlp->nlp_DID, ELS_CMD_SCR);
1621
James Smart488d1462006-03-07 15:02:37 -05001622 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05001623 /* This will trigger the release of the node just
1624 * allocated
1625 */
James Smart329f9bc2007-04-25 09:53:01 -04001626 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001627 return 1;
dea31012005-04-17 16:05:31 -05001628 }
1629
1630 icmd = &elsiocb->iocb;
1631 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1632
1633 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
James Smart92d7f7b2007-06-17 19:56:38 -05001634 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001635
1636 /* For SCR, remainder of payload is SCR parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05001637 memset(pcmd, 0, sizeof(SCR));
dea31012005-04-17 16:05:31 -05001638 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
1639
James Smart858c9f62007-06-17 19:56:39 -05001640 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1641 "Issue SCR: did:x%x",
1642 ndlp->nlp_DID, 0, 0);
1643
dea31012005-04-17 16:05:31 -05001644 phba->fc_stat.elsXmitSCR++;
1645 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
dea31012005-04-17 16:05:31 -05001646 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05001647 /* The additional lpfc_nlp_put will cause the following
1648 * lpfc_els_free_iocb routine to trigger the rlease of
1649 * the node.
1650 */
James Smart329f9bc2007-04-25 09:53:01 -04001651 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001652 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001653 return 1;
dea31012005-04-17 16:05:31 -05001654 }
James Smartfa4066b2008-01-11 01:53:27 -05001655 /* This will cause the callback-function lpfc_cmpl_els_cmd to
1656 * trigger the release of node.
1657 */
James Smart329f9bc2007-04-25 09:53:01 -04001658 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001659 return 0;
dea31012005-04-17 16:05:31 -05001660}
1661
1662static int
James Smart2e0fef82007-06-17 19:56:36 -05001663lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05001664{
James Smart2e0fef82007-06-17 19:56:36 -05001665 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001666 IOCB_t *icmd;
1667 struct lpfc_iocbq *elsiocb;
1668 struct lpfc_sli_ring *pring;
1669 struct lpfc_sli *psli;
1670 FARP *fp;
1671 uint8_t *pcmd;
1672 uint32_t *lp;
1673 uint16_t cmdsize;
1674 struct lpfc_nodelist *ondlp;
1675 struct lpfc_nodelist *ndlp;
1676
1677 psli = &phba->sli;
1678 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
James Smart92d7f7b2007-06-17 19:56:38 -05001679 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
dea31012005-04-17 16:05:31 -05001680
James Smarte47c9092008-02-08 18:49:26 -05001681 ndlp = lpfc_findnode_did(vport, nportid);
1682 if (!ndlp) {
1683 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1684 if (!ndlp)
1685 return 1;
1686 lpfc_nlp_init(vport, ndlp, nportid);
1687 lpfc_enqueue_node(vport, ndlp);
1688 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1689 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1690 if (!ndlp)
1691 return 1;
1692 }
James Smart2e0fef82007-06-17 19:56:36 -05001693
1694 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1695 ndlp->nlp_DID, ELS_CMD_RNID);
James Smart488d1462006-03-07 15:02:37 -05001696 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05001697 /* This will trigger the release of the node just
1698 * allocated
1699 */
James Smart329f9bc2007-04-25 09:53:01 -04001700 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001701 return 1;
dea31012005-04-17 16:05:31 -05001702 }
1703
1704 icmd = &elsiocb->iocb;
1705 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1706
1707 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
James Smart92d7f7b2007-06-17 19:56:38 -05001708 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001709
1710 /* Fill in FARPR payload */
1711 fp = (FARP *) (pcmd);
James Smart92d7f7b2007-06-17 19:56:38 -05001712 memset(fp, 0, sizeof(FARP));
dea31012005-04-17 16:05:31 -05001713 lp = (uint32_t *) pcmd;
1714 *lp++ = be32_to_cpu(nportid);
James Smart2e0fef82007-06-17 19:56:36 -05001715 *lp++ = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05001716 fp->Rflags = 0;
1717 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
1718
James Smart92d7f7b2007-06-17 19:56:38 -05001719 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
1720 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05001721 ondlp = lpfc_findnode_did(vport, nportid);
James Smarte47c9092008-02-08 18:49:26 -05001722 if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
dea31012005-04-17 16:05:31 -05001723 memcpy(&fp->OportName, &ondlp->nlp_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05001724 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05001725 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05001726 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05001727 }
1728
James Smart858c9f62007-06-17 19:56:39 -05001729 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1730 "Issue FARPR: did:x%x",
1731 ndlp->nlp_DID, 0, 0);
1732
dea31012005-04-17 16:05:31 -05001733 phba->fc_stat.elsXmitFARPR++;
1734 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
dea31012005-04-17 16:05:31 -05001735 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05001736 /* The additional lpfc_nlp_put will cause the following
1737 * lpfc_els_free_iocb routine to trigger the release of
1738 * the node.
1739 */
James Smart329f9bc2007-04-25 09:53:01 -04001740 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001741 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001742 return 1;
dea31012005-04-17 16:05:31 -05001743 }
James Smartfa4066b2008-01-11 01:53:27 -05001744 /* This will cause the callback-function lpfc_cmpl_els_cmd to
1745 * trigger the release of the node.
1746 */
James Smart329f9bc2007-04-25 09:53:01 -04001747 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001748 return 0;
dea31012005-04-17 16:05:31 -05001749}
1750
1751void
James Smart2e0fef82007-06-17 19:56:36 -05001752lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
James Smartfdcebe22006-03-07 15:04:01 -05001753{
James Smart2e0fef82007-06-17 19:56:36 -05001754 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smarte47c9092008-02-08 18:49:26 -05001755 struct lpfc_work_evt *evtp;
James Smart2e0fef82007-06-17 19:56:36 -05001756
James Smart0d2b6b82008-06-14 22:52:47 -04001757 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
1758 return;
James Smart2e0fef82007-06-17 19:56:36 -05001759 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05001760 nlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001761 spin_unlock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05001762 del_timer_sync(&nlp->nlp_delayfunc);
1763 nlp->nlp_last_elscmd = 0;
James Smarte47c9092008-02-08 18:49:26 -05001764 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
James Smartfdcebe22006-03-07 15:04:01 -05001765 list_del_init(&nlp->els_retry_evt.evt_listp);
James Smarte47c9092008-02-08 18:49:26 -05001766 /* Decrement nlp reference count held for the delayed retry */
1767 evtp = &nlp->els_retry_evt;
1768 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
1769 }
James Smartfdcebe22006-03-07 15:04:01 -05001770 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
James Smart2e0fef82007-06-17 19:56:36 -05001771 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05001772 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001773 spin_unlock_irq(shost->host_lock);
1774 if (vport->num_disc_nodes) {
James Smart0d2b6b82008-06-14 22:52:47 -04001775 if (vport->port_state < LPFC_VPORT_READY) {
1776 /* Check if there are more ADISCs to be sent */
1777 lpfc_more_adisc(vport);
1778 if ((vport->num_disc_nodes == 0) &&
1779 (vport->fc_npr_cnt))
1780 lpfc_els_disc_plogi(vport);
1781 } else {
1782 /* Check if there are more PLOGIs to be sent */
1783 lpfc_more_plogi(vport);
1784 }
James Smart2e0fef82007-06-17 19:56:36 -05001785 if (vport->num_disc_nodes == 0) {
1786 spin_lock_irq(shost->host_lock);
1787 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1788 spin_unlock_irq(shost->host_lock);
1789 lpfc_can_disctmo(vport);
James Smarted957682007-06-17 19:56:37 -05001790 lpfc_end_rscn(vport);
James Smartfdcebe22006-03-07 15:04:01 -05001791 }
1792 }
1793 }
1794 return;
1795}
1796
1797void
dea31012005-04-17 16:05:31 -05001798lpfc_els_retry_delay(unsigned long ptr)
1799{
James Smart2e0fef82007-06-17 19:56:36 -05001800 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
1801 struct lpfc_vport *vport = ndlp->vport;
James Smart2e0fef82007-06-17 19:56:36 -05001802 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05001803 unsigned long flags;
James Smart2e0fef82007-06-17 19:56:36 -05001804 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
dea31012005-04-17 16:05:31 -05001805
James Smart92d7f7b2007-06-17 19:56:38 -05001806 spin_lock_irqsave(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05001807 if (!list_empty(&evtp->evt_listp)) {
James Smart92d7f7b2007-06-17 19:56:38 -05001808 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05001809 return;
1810 }
1811
James Smartfa4066b2008-01-11 01:53:27 -05001812 /* We need to hold the node by incrementing the reference
1813 * count until the queued work is done
1814 */
1815 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
dea31012005-04-17 16:05:31 -05001816 evtp->evt = LPFC_EVT_ELS_RETRY;
1817 list_add_tail(&evtp->evt_listp, &phba->work_list);
1818 if (phba->work_wait)
James Smart92d7f7b2007-06-17 19:56:38 -05001819 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05001820
James Smart92d7f7b2007-06-17 19:56:38 -05001821 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05001822 return;
1823}
1824
1825void
1826lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
1827{
James Smart2e0fef82007-06-17 19:56:36 -05001828 struct lpfc_vport *vport = ndlp->vport;
1829 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1830 uint32_t cmd, did, retry;
dea31012005-04-17 16:05:31 -05001831
James Smart2e0fef82007-06-17 19:56:36 -05001832 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001833 did = ndlp->nlp_DID;
1834 cmd = ndlp->nlp_last_elscmd;
1835 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05001836
1837 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
James Smart2e0fef82007-06-17 19:56:36 -05001838 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001839 return;
1840 }
1841
1842 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001843 spin_unlock_irq(shost->host_lock);
James Smart1a169682006-03-07 15:04:06 -05001844 /*
1845 * If a discovery event readded nlp_delayfunc after timer
1846 * firing and before processing the timer, cancel the
1847 * nlp_delayfunc.
1848 */
1849 del_timer_sync(&ndlp->nlp_delayfunc);
dea31012005-04-17 16:05:31 -05001850 retry = ndlp->nlp_retry;
1851
1852 switch (cmd) {
1853 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05001854 lpfc_issue_els_flogi(vport, ndlp, retry);
dea31012005-04-17 16:05:31 -05001855 break;
1856 case ELS_CMD_PLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05001857 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001858 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001859 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05001860 }
dea31012005-04-17 16:05:31 -05001861 break;
1862 case ELS_CMD_ADISC:
James Smart2e0fef82007-06-17 19:56:36 -05001863 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001864 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001865 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05001866 }
dea31012005-04-17 16:05:31 -05001867 break;
1868 case ELS_CMD_PRLI:
James Smart2e0fef82007-06-17 19:56:36 -05001869 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001870 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001871 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05001872 }
dea31012005-04-17 16:05:31 -05001873 break;
1874 case ELS_CMD_LOGO:
James Smart2e0fef82007-06-17 19:56:36 -05001875 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001876 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001877 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05001878 }
dea31012005-04-17 16:05:31 -05001879 break;
James Smart92d7f7b2007-06-17 19:56:38 -05001880 case ELS_CMD_FDISC:
1881 lpfc_issue_els_fdisc(vport, ndlp, retry);
1882 break;
dea31012005-04-17 16:05:31 -05001883 }
1884 return;
1885}
1886
1887static int
James Smart2e0fef82007-06-17 19:56:36 -05001888lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1889 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001890{
James Smart2e0fef82007-06-17 19:56:36 -05001891 struct lpfc_vport *vport = cmdiocb->vport;
1892 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1893 IOCB_t *irsp = &rspiocb->iocb;
1894 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1895 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
dea31012005-04-17 16:05:31 -05001896 uint32_t *elscmd;
1897 struct ls_rjt stat;
James Smart2e0fef82007-06-17 19:56:36 -05001898 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
James Smart98c9ea52007-10-27 13:37:33 -04001899 int logerr = 0;
James Smart2e0fef82007-06-17 19:56:36 -05001900 uint32_t cmd = 0;
James Smart488d1462006-03-07 15:02:37 -05001901 uint32_t did;
dea31012005-04-17 16:05:31 -05001902
James Smart488d1462006-03-07 15:02:37 -05001903
dea31012005-04-17 16:05:31 -05001904 /* Note: context2 may be 0 for internal driver abort
1905 * of delays ELS command.
1906 */
1907
1908 if (pcmd && pcmd->virt) {
1909 elscmd = (uint32_t *) (pcmd->virt);
1910 cmd = *elscmd++;
1911 }
1912
James Smarte47c9092008-02-08 18:49:26 -05001913 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart488d1462006-03-07 15:02:37 -05001914 did = ndlp->nlp_DID;
1915 else {
1916 /* We should only hit this case for retrying PLOGI */
1917 did = irsp->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05001918 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05001919 if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
1920 && (cmd != ELS_CMD_PLOGI))
James Smart488d1462006-03-07 15:02:37 -05001921 return 1;
1922 }
1923
James Smart858c9f62007-06-17 19:56:39 -05001924 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1925 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
1926 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
1927
dea31012005-04-17 16:05:31 -05001928 switch (irsp->ulpStatus) {
1929 case IOSTAT_FCP_RSP_ERROR:
1930 case IOSTAT_REMOTE_STOP:
1931 break;
1932
1933 case IOSTAT_LOCAL_REJECT:
1934 switch ((irsp->un.ulpWord[4] & 0xff)) {
1935 case IOERR_LOOP_OPEN_FAILURE:
James Smart2e0fef82007-06-17 19:56:36 -05001936 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05001937 delay = 1000;
dea31012005-04-17 16:05:31 -05001938 retry = 1;
1939 break;
1940
James Smart92d7f7b2007-06-17 19:56:38 -05001941 case IOERR_ILLEGAL_COMMAND:
James Smart7f5f3d02008-02-08 18:50:14 -05001942 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1943 "0124 Retry illegal cmd x%x "
1944 "retry:x%x delay:x%x\n",
1945 cmd, cmdiocb->retry, delay);
1946 retry = 1;
1947 /* All command's retry policy */
1948 maxretry = 8;
1949 if (cmdiocb->retry > 2)
1950 delay = 1000;
James Smart92d7f7b2007-06-17 19:56:38 -05001951 break;
1952
dea31012005-04-17 16:05:31 -05001953 case IOERR_NO_RESOURCES:
James Smart98c9ea52007-10-27 13:37:33 -04001954 logerr = 1; /* HBA out of resources */
James Smart858c9f62007-06-17 19:56:39 -05001955 retry = 1;
1956 if (cmdiocb->retry > 100)
1957 delay = 100;
1958 maxretry = 250;
1959 break;
1960
1961 case IOERR_ILLEGAL_FRAME:
James Smart92d7f7b2007-06-17 19:56:38 -05001962 delay = 100;
dea31012005-04-17 16:05:31 -05001963 retry = 1;
1964 break;
1965
James Smart858c9f62007-06-17 19:56:39 -05001966 case IOERR_SEQUENCE_TIMEOUT:
dea31012005-04-17 16:05:31 -05001967 case IOERR_INVALID_RPI:
1968 retry = 1;
1969 break;
1970 }
1971 break;
1972
1973 case IOSTAT_NPORT_RJT:
1974 case IOSTAT_FABRIC_RJT:
1975 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
1976 retry = 1;
1977 break;
1978 }
1979 break;
1980
1981 case IOSTAT_NPORT_BSY:
1982 case IOSTAT_FABRIC_BSY:
James Smart98c9ea52007-10-27 13:37:33 -04001983 logerr = 1; /* Fabric / Remote NPort out of resources */
dea31012005-04-17 16:05:31 -05001984 retry = 1;
1985 break;
1986
1987 case IOSTAT_LS_RJT:
1988 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
1989 /* Added for Vendor specifc support
1990 * Just keep retrying for these Rsn / Exp codes
1991 */
1992 switch (stat.un.b.lsRjtRsnCode) {
1993 case LSRJT_UNABLE_TPC:
1994 if (stat.un.b.lsRjtRsnCodeExp ==
1995 LSEXP_CMD_IN_PROGRESS) {
1996 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05001997 delay = 1000;
dea31012005-04-17 16:05:31 -05001998 maxretry = 48;
1999 }
2000 retry = 1;
2001 break;
2002 }
2003 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05002004 delay = 1000;
dea31012005-04-17 16:05:31 -05002005 maxretry = lpfc_max_els_tries + 1;
2006 retry = 1;
2007 break;
2008 }
James Smart92d7f7b2007-06-17 19:56:38 -05002009 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2010 (cmd == ELS_CMD_FDISC) &&
2011 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
James Smarte8b62012007-08-02 11:10:09 -04002012 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2013 "0125 FDISC Failed (x%x). "
2014 "Fabric out of resources\n",
2015 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05002016 lpfc_vport_set_state(vport,
2017 FC_VPORT_NO_FABRIC_RSCS);
2018 }
dea31012005-04-17 16:05:31 -05002019 break;
2020
2021 case LSRJT_LOGICAL_BSY:
James Smart858c9f62007-06-17 19:56:39 -05002022 if ((cmd == ELS_CMD_PLOGI) ||
2023 (cmd == ELS_CMD_PRLI)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002024 delay = 1000;
dea31012005-04-17 16:05:31 -05002025 maxretry = 48;
James Smart92d7f7b2007-06-17 19:56:38 -05002026 } else if (cmd == ELS_CMD_FDISC) {
James Smart51ef4c22007-08-02 11:10:31 -04002027 /* FDISC retry policy */
2028 maxretry = 48;
2029 if (cmdiocb->retry >= 32)
2030 delay = 1000;
dea31012005-04-17 16:05:31 -05002031 }
2032 retry = 1;
2033 break;
James Smart92d7f7b2007-06-17 19:56:38 -05002034
2035 case LSRJT_LOGICAL_ERR:
James Smart7f5f3d02008-02-08 18:50:14 -05002036 /* There are some cases where switches return this
2037 * error when they are not ready and should be returning
2038 * Logical Busy. We should delay every time.
2039 */
2040 if (cmd == ELS_CMD_FDISC &&
2041 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
2042 maxretry = 3;
2043 delay = 1000;
2044 retry = 1;
2045 break;
2046 }
James Smart92d7f7b2007-06-17 19:56:38 -05002047 case LSRJT_PROTOCOL_ERR:
2048 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2049 (cmd == ELS_CMD_FDISC) &&
2050 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
2051 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
2052 ) {
James Smarte8b62012007-08-02 11:10:09 -04002053 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2054 "0123 FDISC Failed (x%x). "
2055 "Fabric Detected Bad WWN\n",
2056 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05002057 lpfc_vport_set_state(vport,
2058 FC_VPORT_FABRIC_REJ_WWN);
2059 }
2060 break;
dea31012005-04-17 16:05:31 -05002061 }
2062 break;
2063
2064 case IOSTAT_INTERMED_RSP:
2065 case IOSTAT_BA_RJT:
2066 break;
2067
2068 default:
2069 break;
2070 }
2071
James Smart488d1462006-03-07 15:02:37 -05002072 if (did == FDMI_DID)
dea31012005-04-17 16:05:31 -05002073 retry = 1;
dea31012005-04-17 16:05:31 -05002074
James Smart98c9ea52007-10-27 13:37:33 -04002075 if ((cmd == ELS_CMD_FLOGI) &&
James Smart1b32f6a2008-02-08 18:49:39 -05002076 (phba->fc_topology != TOPOLOGY_LOOP) &&
2077 !lpfc_error_lost_link(irsp)) {
James Smart98c9ea52007-10-27 13:37:33 -04002078 /* FLOGI retry policy */
2079 retry = 1;
2080 maxretry = 48;
2081 if (cmdiocb->retry >= 32)
2082 delay = 1000;
2083 }
2084
dea31012005-04-17 16:05:31 -05002085 if ((++cmdiocb->retry) >= maxretry) {
2086 phba->fc_stat.elsRetryExceeded++;
2087 retry = 0;
2088 }
2089
James Smarted957682007-06-17 19:56:37 -05002090 if ((vport->load_flag & FC_UNLOADING) != 0)
2091 retry = 0;
2092
dea31012005-04-17 16:05:31 -05002093 if (retry) {
2094
2095 /* Retry ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04002096 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2097 "0107 Retry ELS command x%x to remote "
2098 "NPORT x%x Data: x%x x%x\n",
2099 cmd, did, cmdiocb->retry, delay);
dea31012005-04-17 16:05:31 -05002100
James Smart858c9f62007-06-17 19:56:39 -05002101 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
2102 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
2103 ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) {
2104 /* Don't reset timer for no resources */
2105
dea31012005-04-17 16:05:31 -05002106 /* If discovery / RSCN timer is running, reset it */
James Smart2e0fef82007-06-17 19:56:36 -05002107 if (timer_pending(&vport->fc_disctmo) ||
James Smart92d7f7b2007-06-17 19:56:38 -05002108 (vport->fc_flag & FC_RSCN_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05002109 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05002110 }
2111
2112 phba->fc_stat.elsXmitRetry++;
James Smart58da1ff2008-04-07 10:15:56 -04002113 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
dea31012005-04-17 16:05:31 -05002114 phba->fc_stat.elsDelayRetry++;
2115 ndlp->nlp_retry = cmdiocb->retry;
2116
James Smart92d7f7b2007-06-17 19:56:38 -05002117 /* delay is specified in milliseconds */
2118 mod_timer(&ndlp->nlp_delayfunc,
2119 jiffies + msecs_to_jiffies(delay));
James Smart2e0fef82007-06-17 19:56:36 -05002120 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002121 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002122 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002123
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002124 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart858c9f62007-06-17 19:56:39 -05002125 if (cmd == ELS_CMD_PRLI)
2126 lpfc_nlp_set_state(vport, ndlp,
2127 NLP_STE_REG_LOGIN_ISSUE);
2128 else
2129 lpfc_nlp_set_state(vport, ndlp,
2130 NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05002131 ndlp->nlp_last_elscmd = cmd;
2132
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002133 return 1;
dea31012005-04-17 16:05:31 -05002134 }
2135 switch (cmd) {
2136 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002137 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002138 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -05002139 case ELS_CMD_FDISC:
2140 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
2141 return 1;
dea31012005-04-17 16:05:31 -05002142 case ELS_CMD_PLOGI:
James Smart58da1ff2008-04-07 10:15:56 -04002143 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart488d1462006-03-07 15:02:37 -05002144 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002145 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04002146 NLP_STE_PLOGI_ISSUE);
James Smart488d1462006-03-07 15:02:37 -05002147 }
James Smart2e0fef82007-06-17 19:56:36 -05002148 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002149 return 1;
dea31012005-04-17 16:05:31 -05002150 case ELS_CMD_ADISC:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002151 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002152 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2153 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002154 return 1;
dea31012005-04-17 16:05:31 -05002155 case ELS_CMD_PRLI:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002156 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002157 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
2158 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002159 return 1;
dea31012005-04-17 16:05:31 -05002160 case ELS_CMD_LOGO:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002161 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002162 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2163 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002164 return 1;
dea31012005-04-17 16:05:31 -05002165 }
2166 }
dea31012005-04-17 16:05:31 -05002167 /* No retry ELS command <elsCmd> to remote NPORT <did> */
James Smart98c9ea52007-10-27 13:37:33 -04002168 if (logerr) {
2169 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2170 "0137 No retry ELS command x%x to remote "
2171 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
2172 cmd, did, irsp->ulpStatus,
2173 irsp->un.ulpWord[4]);
2174 }
2175 else {
2176 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smarta58cbd52007-08-02 11:09:43 -04002177 "0108 No retry ELS command x%x to remote "
2178 "NPORT x%x Retried:%d Error:x%x/%x\n",
2179 cmd, did, cmdiocb->retry, irsp->ulpStatus,
2180 irsp->un.ulpWord[4]);
James Smart98c9ea52007-10-27 13:37:33 -04002181 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002182 return 0;
dea31012005-04-17 16:05:31 -05002183}
2184
James Smart09372822008-01-11 01:52:54 -05002185static int
James Smart87af33f2007-10-27 13:37:43 -04002186lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
2187{
2188 struct lpfc_dmabuf *buf_ptr;
2189
2190 /* Free the response before processing the command. */
2191 if (!list_empty(&buf_ptr1->list)) {
2192 list_remove_head(&buf_ptr1->list, buf_ptr,
2193 struct lpfc_dmabuf,
2194 list);
2195 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
2196 kfree(buf_ptr);
2197 }
2198 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
2199 kfree(buf_ptr1);
2200 return 0;
2201}
2202
James Smart09372822008-01-11 01:52:54 -05002203static int
James Smart87af33f2007-10-27 13:37:43 -04002204lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
2205{
2206 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
2207 kfree(buf_ptr);
2208 return 0;
2209}
2210
2211int
James Smart329f9bc2007-04-25 09:53:01 -04002212lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05002213{
2214 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
James Smarta8adb832007-10-27 13:37:53 -04002215 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05002216
James Smarta8adb832007-10-27 13:37:53 -04002217 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
2218 if (ndlp) {
2219 if (ndlp->nlp_flag & NLP_DEFER_RM) {
2220 lpfc_nlp_put(ndlp);
2221
2222 /* If the ndlp is not being used by another discovery
2223 * thread, free it.
2224 */
2225 if (!lpfc_nlp_not_used(ndlp)) {
2226 /* If ndlp is being used by another discovery
2227 * thread, just clear NLP_DEFER_RM
2228 */
2229 ndlp->nlp_flag &= ~NLP_DEFER_RM;
2230 }
2231 }
2232 else
2233 lpfc_nlp_put(ndlp);
James Smart329f9bc2007-04-25 09:53:01 -04002234 elsiocb->context1 = NULL;
2235 }
dea31012005-04-17 16:05:31 -05002236 /* context2 = cmd, context2->next = rsp, context3 = bpl */
2237 if (elsiocb->context2) {
James Smart0ff10d42008-01-11 01:52:36 -05002238 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
2239 /* Firmware could still be in progress of DMAing
2240 * payload, so don't free data buffer till after
2241 * a hbeat.
2242 */
2243 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
2244 buf_ptr = elsiocb->context2;
2245 elsiocb->context2 = NULL;
2246 if (buf_ptr) {
2247 buf_ptr1 = NULL;
2248 spin_lock_irq(&phba->hbalock);
2249 if (!list_empty(&buf_ptr->list)) {
2250 list_remove_head(&buf_ptr->list,
2251 buf_ptr1, struct lpfc_dmabuf,
2252 list);
2253 INIT_LIST_HEAD(&buf_ptr1->list);
2254 list_add_tail(&buf_ptr1->list,
2255 &phba->elsbuf);
2256 phba->elsbuf_cnt++;
2257 }
2258 INIT_LIST_HEAD(&buf_ptr->list);
2259 list_add_tail(&buf_ptr->list, &phba->elsbuf);
2260 phba->elsbuf_cnt++;
2261 spin_unlock_irq(&phba->hbalock);
2262 }
2263 } else {
2264 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
2265 lpfc_els_free_data(phba, buf_ptr1);
2266 }
dea31012005-04-17 16:05:31 -05002267 }
2268
2269 if (elsiocb->context3) {
2270 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
James Smart87af33f2007-10-27 13:37:43 -04002271 lpfc_els_free_bpl(phba, buf_ptr);
dea31012005-04-17 16:05:31 -05002272 }
James Bottomley604a3e32005-10-29 10:28:33 -05002273 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -05002274 return 0;
2275}
2276
2277static void
James Smart2e0fef82007-06-17 19:56:36 -05002278lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2279 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002280{
James Smart2e0fef82007-06-17 19:56:36 -05002281 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2282 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05002283 IOCB_t *irsp;
2284
2285 irsp = &rspiocb->iocb;
2286 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2287 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
2288 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05002289 /* ACC to LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002290 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2291 "0109 ACC to LOGO completes to NPort x%x "
2292 "Data: x%x x%x x%x\n",
2293 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2294 ndlp->nlp_rpi);
James Smart87af33f2007-10-27 13:37:43 -04002295
2296 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
2297 /* NPort Recovery mode or node is just allocated */
2298 if (!lpfc_nlp_not_used(ndlp)) {
2299 /* If the ndlp is being used by another discovery
2300 * thread, just unregister the RPI.
2301 */
2302 lpfc_unreg_rpi(vport, ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05002303 } else {
2304 /* Indicate the node has already released, should
2305 * not reference to it from within lpfc_els_free_iocb.
2306 */
2307 cmdiocb->context1 = NULL;
James Smart87af33f2007-10-27 13:37:43 -04002308 }
dea31012005-04-17 16:05:31 -05002309 }
2310 lpfc_els_free_iocb(phba, cmdiocb);
2311 return;
2312}
2313
James Smart858c9f62007-06-17 19:56:39 -05002314void
2315lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
2316{
2317 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
2318 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
2319
2320 pmb->context1 = NULL;
2321 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2322 kfree(mp);
2323 mempool_free(pmb, phba->mbox_mem_pool);
James Smart58da1ff2008-04-07 10:15:56 -04002324 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smarta8adb832007-10-27 13:37:53 -04002325 lpfc_nlp_put(ndlp);
James Smarta8adb832007-10-27 13:37:53 -04002326 /* This is the end of the default RPI cleanup logic for this
2327 * ndlp. If no other discovery threads are using this ndlp.
2328 * we should free all resources associated with it.
2329 */
2330 lpfc_nlp_not_used(ndlp);
2331 }
James Smart858c9f62007-06-17 19:56:39 -05002332 return;
2333}
2334
dea31012005-04-17 16:05:31 -05002335static void
James Smart858c9f62007-06-17 19:56:39 -05002336lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
James Smart329f9bc2007-04-25 09:53:01 -04002337 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002338{
James Smart2e0fef82007-06-17 19:56:36 -05002339 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2340 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
2341 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
James Smart87af33f2007-10-27 13:37:43 -04002342 IOCB_t *irsp;
2343 uint8_t *pcmd;
dea31012005-04-17 16:05:31 -05002344 LPFC_MBOXQ_t *mbox = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05002345 struct lpfc_dmabuf *mp = NULL;
James Smart87af33f2007-10-27 13:37:43 -04002346 uint32_t ls_rjt = 0;
dea31012005-04-17 16:05:31 -05002347
James Smart33ccf8d2006-08-17 11:57:58 -04002348 irsp = &rspiocb->iocb;
2349
dea31012005-04-17 16:05:31 -05002350 if (cmdiocb->context_un.mbox)
2351 mbox = cmdiocb->context_un.mbox;
2352
James Smartfa4066b2008-01-11 01:53:27 -05002353 /* First determine if this is a LS_RJT cmpl. Note, this callback
2354 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
2355 */
James Smart87af33f2007-10-27 13:37:43 -04002356 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
James Smart58da1ff2008-04-07 10:15:56 -04002357 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
2358 (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
James Smartfa4066b2008-01-11 01:53:27 -05002359 /* A LS_RJT associated with Default RPI cleanup has its own
2360 * seperate code path.
James Smart87af33f2007-10-27 13:37:43 -04002361 */
2362 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
2363 ls_rjt = 1;
2364 }
2365
dea31012005-04-17 16:05:31 -05002366 /* Check to see if link went down during discovery */
James Smart58da1ff2008-04-07 10:15:56 -04002367 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
dea31012005-04-17 16:05:31 -05002368 if (mbox) {
James Smart14691152006-12-02 13:34:28 -05002369 mp = (struct lpfc_dmabuf *) mbox->context1;
2370 if (mp) {
2371 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2372 kfree(mp);
2373 }
James Smart329f9bc2007-04-25 09:53:01 -04002374 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05002375 }
James Smart58da1ff2008-04-07 10:15:56 -04002376 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
2377 (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
James Smartfa4066b2008-01-11 01:53:27 -05002378 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04002379 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05002380 /* Indicate the node has already released,
2381 * should not reference to it from within
2382 * the routine lpfc_els_free_iocb.
2383 */
2384 cmdiocb->context1 = NULL;
2385 }
dea31012005-04-17 16:05:31 -05002386 goto out;
2387 }
2388
James Smart858c9f62007-06-17 19:56:39 -05002389 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smart51ef4c22007-08-02 11:10:31 -04002390 "ELS rsp cmpl: status:x%x/x%x did:x%x",
James Smart858c9f62007-06-17 19:56:39 -05002391 irsp->ulpStatus, irsp->un.ulpWord[4],
James Smart51ef4c22007-08-02 11:10:31 -04002392 cmdiocb->iocb.un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05002393 /* ELS response tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04002394 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2395 "0110 ELS response tag x%x completes "
2396 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
2397 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
2398 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
2399 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2400 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05002401 if (mbox) {
2402 if ((rspiocb->iocb.ulpStatus == 0)
2403 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
James Smart2e0fef82007-06-17 19:56:36 -05002404 lpfc_unreg_rpi(vport, ndlp);
James Smarte47c9092008-02-08 18:49:26 -05002405 /* Increment reference count to ndlp to hold the
2406 * reference to ndlp for the callback function.
2407 */
James Smart329f9bc2007-04-25 09:53:01 -04002408 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05002409 mbox->vport = vport;
James Smart858c9f62007-06-17 19:56:39 -05002410 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
2411 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
2412 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
2413 }
2414 else {
2415 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
2416 ndlp->nlp_prev_state = ndlp->nlp_state;
2417 lpfc_nlp_set_state(vport, ndlp,
James Smart2e0fef82007-06-17 19:56:36 -05002418 NLP_STE_REG_LOGIN_ISSUE);
James Smart858c9f62007-06-17 19:56:39 -05002419 }
James Smart0b727fe2007-10-27 13:37:25 -04002420 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smarte47c9092008-02-08 18:49:26 -05002421 != MBX_NOT_FINISHED)
dea31012005-04-17 16:05:31 -05002422 goto out;
James Smarte47c9092008-02-08 18:49:26 -05002423 else
2424 /* Decrement the ndlp reference count we
2425 * set for this failed mailbox command.
2426 */
2427 lpfc_nlp_put(ndlp);
James Smart98c9ea52007-10-27 13:37:33 -04002428
2429 /* ELS rsp: Cannot issue reg_login for <NPortid> */
2430 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2431 "0138 ELS rsp: Cannot issue reg_login for x%x "
2432 "Data: x%x x%x x%x\n",
2433 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2434 ndlp->nlp_rpi);
2435
James Smartfa4066b2008-01-11 01:53:27 -05002436 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04002437 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05002438 /* Indicate node has already been released,
2439 * should not reference to it from within
2440 * the routine lpfc_els_free_iocb.
2441 */
2442 cmdiocb->context1 = NULL;
2443 }
dea31012005-04-17 16:05:31 -05002444 } else {
James Smart858c9f62007-06-17 19:56:39 -05002445 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
2446 if (!lpfc_error_lost_link(irsp) &&
2447 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
James Smartfa4066b2008-01-11 01:53:27 -05002448 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04002449 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05002450 /* Indicate node has already been
2451 * released, should not reference
2452 * to it from within the routine
2453 * lpfc_els_free_iocb.
2454 */
2455 cmdiocb->context1 = NULL;
2456 }
dea31012005-04-17 16:05:31 -05002457 }
2458 }
James Smart14691152006-12-02 13:34:28 -05002459 mp = (struct lpfc_dmabuf *) mbox->context1;
2460 if (mp) {
2461 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2462 kfree(mp);
2463 }
2464 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05002465 }
2466out:
James Smart58da1ff2008-04-07 10:15:56 -04002467 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart2e0fef82007-06-17 19:56:36 -05002468 spin_lock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05002469 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
James Smart2e0fef82007-06-17 19:56:36 -05002470 spin_unlock_irq(shost->host_lock);
James Smart87af33f2007-10-27 13:37:43 -04002471
2472 /* If the node is not being used by another discovery thread,
2473 * and we are sending a reject, we are done with it.
2474 * Release driver reference count here and free associated
2475 * resources.
2476 */
2477 if (ls_rjt)
James Smartfa4066b2008-01-11 01:53:27 -05002478 if (lpfc_nlp_not_used(ndlp))
2479 /* Indicate node has already been released,
2480 * should not reference to it from within
2481 * the routine lpfc_els_free_iocb.
2482 */
2483 cmdiocb->context1 = NULL;
dea31012005-04-17 16:05:31 -05002484 }
James Smart87af33f2007-10-27 13:37:43 -04002485
dea31012005-04-17 16:05:31 -05002486 lpfc_els_free_iocb(phba, cmdiocb);
2487 return;
2488}
2489
2490int
James Smart2e0fef82007-06-17 19:56:36 -05002491lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
2492 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
James Smart51ef4c22007-08-02 11:10:31 -04002493 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05002494{
James Smart2e0fef82007-06-17 19:56:36 -05002495 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2496 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002497 IOCB_t *icmd;
2498 IOCB_t *oldcmd;
2499 struct lpfc_iocbq *elsiocb;
2500 struct lpfc_sli_ring *pring;
2501 struct lpfc_sli *psli;
2502 uint8_t *pcmd;
2503 uint16_t cmdsize;
2504 int rc;
James Smart82d9a2a2006-04-15 11:53:05 -04002505 ELS_PKT *els_pkt_ptr;
dea31012005-04-17 16:05:31 -05002506
2507 psli = &phba->sli;
2508 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2509 oldcmd = &oldiocb->iocb;
2510
2511 switch (flag) {
2512 case ELS_CMD_ACC:
James Smart92d7f7b2007-06-17 19:56:38 -05002513 cmdsize = sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05002514 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
2515 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05002516 if (!elsiocb) {
James Smart2e0fef82007-06-17 19:56:36 -05002517 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002518 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05002519 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002520 return 1;
dea31012005-04-17 16:05:31 -05002521 }
James Smart2e0fef82007-06-17 19:56:36 -05002522
dea31012005-04-17 16:05:31 -05002523 icmd = &elsiocb->iocb;
2524 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2525 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2526 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05002527 pcmd += sizeof(uint32_t);
James Smart858c9f62007-06-17 19:56:39 -05002528
2529 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2530 "Issue ACC: did:x%x flg:x%x",
2531 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05002532 break;
2533 case ELS_CMD_PLOGI:
James Smart92d7f7b2007-06-17 19:56:38 -05002534 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
James Smart2e0fef82007-06-17 19:56:36 -05002535 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
2536 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05002537 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002538 return 1;
James Smart488d1462006-03-07 15:02:37 -05002539
dea31012005-04-17 16:05:31 -05002540 icmd = &elsiocb->iocb;
2541 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2542 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2543
2544 if (mbox)
2545 elsiocb->context_un.mbox = mbox;
2546
2547 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05002548 pcmd += sizeof(uint32_t);
2549 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
James Smart858c9f62007-06-17 19:56:39 -05002550
2551 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2552 "Issue ACC PLOGI: did:x%x flg:x%x",
2553 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05002554 break;
James Smart82d9a2a2006-04-15 11:53:05 -04002555 case ELS_CMD_PRLO:
James Smart92d7f7b2007-06-17 19:56:38 -05002556 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
James Smart2e0fef82007-06-17 19:56:36 -05002557 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
James Smart82d9a2a2006-04-15 11:53:05 -04002558 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
2559 if (!elsiocb)
2560 return 1;
2561
2562 icmd = &elsiocb->iocb;
2563 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2564 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2565
2566 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
James Smart92d7f7b2007-06-17 19:56:38 -05002567 sizeof(uint32_t) + sizeof(PRLO));
James Smart82d9a2a2006-04-15 11:53:05 -04002568 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
2569 els_pkt_ptr = (ELS_PKT *) pcmd;
2570 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
James Smart858c9f62007-06-17 19:56:39 -05002571
2572 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2573 "Issue ACC PRLO: did:x%x flg:x%x",
2574 ndlp->nlp_DID, ndlp->nlp_flag, 0);
James Smart82d9a2a2006-04-15 11:53:05 -04002575 break;
dea31012005-04-17 16:05:31 -05002576 default:
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002577 return 1;
dea31012005-04-17 16:05:31 -05002578 }
dea31012005-04-17 16:05:31 -05002579 /* Xmit ELS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04002580 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2581 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
2582 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n",
2583 elsiocb->iotag, elsiocb->iocb.ulpContext,
2584 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2585 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05002586 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
James Smart2e0fef82007-06-17 19:56:36 -05002587 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002588 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05002589 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002590 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
2591 } else {
James Smart858c9f62007-06-17 19:56:39 -05002592 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05002593 }
2594
2595 phba->fc_stat.elsXmitACC++;
dea31012005-04-17 16:05:31 -05002596 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
dea31012005-04-17 16:05:31 -05002597 if (rc == IOCB_ERROR) {
2598 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002599 return 1;
dea31012005-04-17 16:05:31 -05002600 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002601 return 0;
dea31012005-04-17 16:05:31 -05002602}
2603
2604int
James Smart2e0fef82007-06-17 19:56:36 -05002605lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
James Smart858c9f62007-06-17 19:56:39 -05002606 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
2607 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05002608{
James Smart2e0fef82007-06-17 19:56:36 -05002609 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002610 IOCB_t *icmd;
2611 IOCB_t *oldcmd;
2612 struct lpfc_iocbq *elsiocb;
2613 struct lpfc_sli_ring *pring;
2614 struct lpfc_sli *psli;
2615 uint8_t *pcmd;
2616 uint16_t cmdsize;
2617 int rc;
2618
2619 psli = &phba->sli;
2620 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2621
James Smart92d7f7b2007-06-17 19:56:38 -05002622 cmdsize = 2 * sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05002623 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
2624 ndlp->nlp_DID, ELS_CMD_LS_RJT);
James Smart488d1462006-03-07 15:02:37 -05002625 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002626 return 1;
dea31012005-04-17 16:05:31 -05002627
2628 icmd = &elsiocb->iocb;
2629 oldcmd = &oldiocb->iocb;
2630 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2631 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2632
2633 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
James Smart92d7f7b2007-06-17 19:56:38 -05002634 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002635 *((uint32_t *) (pcmd)) = rejectError;
2636
James Smart51ef4c22007-08-02 11:10:31 -04002637 if (mbox)
James Smart858c9f62007-06-17 19:56:39 -05002638 elsiocb->context_un.mbox = mbox;
James Smart858c9f62007-06-17 19:56:39 -05002639
dea31012005-04-17 16:05:31 -05002640 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04002641 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2642 "0129 Xmit ELS RJT x%x response tag x%x "
2643 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
2644 "rpi x%x\n",
2645 rejectError, elsiocb->iotag,
2646 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
2647 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05002648 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2649 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
2650 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
2651
dea31012005-04-17 16:05:31 -05002652 phba->fc_stat.elsXmitLSRJT++;
James Smart858c9f62007-06-17 19:56:39 -05002653 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05002654 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
James Smart51ef4c22007-08-02 11:10:31 -04002655
dea31012005-04-17 16:05:31 -05002656 if (rc == IOCB_ERROR) {
2657 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002658 return 1;
dea31012005-04-17 16:05:31 -05002659 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002660 return 0;
dea31012005-04-17 16:05:31 -05002661}
2662
2663int
James Smart2e0fef82007-06-17 19:56:36 -05002664lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
2665 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05002666{
James Smart2e0fef82007-06-17 19:56:36 -05002667 struct lpfc_hba *phba = vport->phba;
2668 struct lpfc_sli *psli = &phba->sli;
2669 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05002670 ADISC *ap;
James Smart2e0fef82007-06-17 19:56:36 -05002671 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05002672 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002673 uint8_t *pcmd;
2674 uint16_t cmdsize;
2675 int rc;
2676
James Smart92d7f7b2007-06-17 19:56:38 -05002677 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
James Smart2e0fef82007-06-17 19:56:36 -05002678 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
2679 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05002680 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002681 return 1;
dea31012005-04-17 16:05:31 -05002682
dea31012005-04-17 16:05:31 -05002683 icmd = &elsiocb->iocb;
2684 oldcmd = &oldiocb->iocb;
2685 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04002686
2687 /* Xmit ADISC ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04002688 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2689 "0130 Xmit ADISC ACC response iotag x%x xri: "
2690 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
2691 elsiocb->iotag, elsiocb->iocb.ulpContext,
2692 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2693 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05002694 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2695
2696 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05002697 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002698
2699 ap = (ADISC *) (pcmd);
2700 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05002701 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2702 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002703 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002704
James Smart858c9f62007-06-17 19:56:39 -05002705 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2706 "Issue ACC ADISC: did:x%x flg:x%x",
2707 ndlp->nlp_DID, ndlp->nlp_flag, 0);
2708
dea31012005-04-17 16:05:31 -05002709 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05002710 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05002711 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
dea31012005-04-17 16:05:31 -05002712 if (rc == IOCB_ERROR) {
2713 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002714 return 1;
dea31012005-04-17 16:05:31 -05002715 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002716 return 0;
dea31012005-04-17 16:05:31 -05002717}
2718
2719int
James Smart2e0fef82007-06-17 19:56:36 -05002720lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
James Smart5b8bd0c2007-04-25 09:52:49 -04002721 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05002722{
James Smart2e0fef82007-06-17 19:56:36 -05002723 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002724 PRLI *npr;
2725 lpfc_vpd_t *vpd;
2726 IOCB_t *icmd;
2727 IOCB_t *oldcmd;
2728 struct lpfc_iocbq *elsiocb;
2729 struct lpfc_sli_ring *pring;
2730 struct lpfc_sli *psli;
2731 uint8_t *pcmd;
2732 uint16_t cmdsize;
2733 int rc;
2734
2735 psli = &phba->sli;
2736 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2737
James Smart92d7f7b2007-06-17 19:56:38 -05002738 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
James Smart2e0fef82007-06-17 19:56:36 -05002739 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
James Smart92d7f7b2007-06-17 19:56:38 -05002740 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002741 if (!elsiocb)
2742 return 1;
dea31012005-04-17 16:05:31 -05002743
dea31012005-04-17 16:05:31 -05002744 icmd = &elsiocb->iocb;
2745 oldcmd = &oldiocb->iocb;
2746 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04002747 /* Xmit PRLI ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04002748 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2749 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
2750 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
2751 elsiocb->iotag, elsiocb->iocb.ulpContext,
2752 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2753 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05002754 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2755
2756 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
James Smart92d7f7b2007-06-17 19:56:38 -05002757 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002758
2759 /* For PRLI, remainder of payload is PRLI parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05002760 memset(pcmd, 0, sizeof(PRLI));
dea31012005-04-17 16:05:31 -05002761
2762 npr = (PRLI *) pcmd;
2763 vpd = &phba->vpd;
2764 /*
James Smart0d2b6b82008-06-14 22:52:47 -04002765 * If the remote port is a target and our firmware version is 3.20 or
2766 * later, set the following bits for FC-TAPE support.
dea31012005-04-17 16:05:31 -05002767 */
James Smart0d2b6b82008-06-14 22:52:47 -04002768 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
2769 (vpd->rev.feaLevelHigh >= 0x02)) {
dea31012005-04-17 16:05:31 -05002770 npr->ConfmComplAllowed = 1;
2771 npr->Retry = 1;
2772 npr->TaskRetryIdReq = 1;
2773 }
2774
2775 npr->acceptRspCode = PRLI_REQ_EXECUTED;
2776 npr->estabImagePair = 1;
2777 npr->readXferRdyDis = 1;
2778 npr->ConfmComplAllowed = 1;
2779
2780 npr->prliType = PRLI_FCP_TYPE;
2781 npr->initiatorFunc = 1;
2782
James Smart858c9f62007-06-17 19:56:39 -05002783 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2784 "Issue ACC PRLI: did:x%x flg:x%x",
2785 ndlp->nlp_DID, ndlp->nlp_flag, 0);
2786
dea31012005-04-17 16:05:31 -05002787 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05002788 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05002789
dea31012005-04-17 16:05:31 -05002790 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
dea31012005-04-17 16:05:31 -05002791 if (rc == IOCB_ERROR) {
2792 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002793 return 1;
dea31012005-04-17 16:05:31 -05002794 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002795 return 0;
dea31012005-04-17 16:05:31 -05002796}
2797
2798static int
James Smart2e0fef82007-06-17 19:56:36 -05002799lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
James Smart329f9bc2007-04-25 09:53:01 -04002800 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05002801{
James Smart2e0fef82007-06-17 19:56:36 -05002802 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002803 RNID *rn;
James Smart2e0fef82007-06-17 19:56:36 -05002804 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05002805 struct lpfc_iocbq *elsiocb;
2806 struct lpfc_sli_ring *pring;
2807 struct lpfc_sli *psli;
2808 uint8_t *pcmd;
2809 uint16_t cmdsize;
2810 int rc;
2811
2812 psli = &phba->sli;
2813 pring = &psli->ring[LPFC_ELS_RING];
2814
James Smart92d7f7b2007-06-17 19:56:38 -05002815 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
2816 + (2 * sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002817 if (format)
James Smart92d7f7b2007-06-17 19:56:38 -05002818 cmdsize += sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05002819
James Smart2e0fef82007-06-17 19:56:36 -05002820 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
2821 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05002822 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002823 return 1;
dea31012005-04-17 16:05:31 -05002824
dea31012005-04-17 16:05:31 -05002825 icmd = &elsiocb->iocb;
2826 oldcmd = &oldiocb->iocb;
2827 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04002828 /* Xmit RNID ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04002829 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2830 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
2831 elsiocb->iotag, elsiocb->iocb.ulpContext);
dea31012005-04-17 16:05:31 -05002832 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
dea31012005-04-17 16:05:31 -05002833 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05002834 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002835
James Smart92d7f7b2007-06-17 19:56:38 -05002836 memset(pcmd, 0, sizeof(RNID));
dea31012005-04-17 16:05:31 -05002837 rn = (RNID *) (pcmd);
2838 rn->Format = format;
James Smart92d7f7b2007-06-17 19:56:38 -05002839 rn->CommonLen = (2 * sizeof(struct lpfc_name));
2840 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2841 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002842 switch (format) {
2843 case 0:
2844 rn->SpecificLen = 0;
2845 break;
2846 case RNID_TOPOLOGY_DISC:
James Smart92d7f7b2007-06-17 19:56:38 -05002847 rn->SpecificLen = sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05002848 memcpy(&rn->un.topologyDisc.portName,
James Smart92d7f7b2007-06-17 19:56:38 -05002849 &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002850 rn->un.topologyDisc.unitType = RNID_HBA;
2851 rn->un.topologyDisc.physPort = 0;
2852 rn->un.topologyDisc.attachedNodes = 0;
2853 break;
2854 default:
2855 rn->CommonLen = 0;
2856 rn->SpecificLen = 0;
2857 break;
2858 }
2859
James Smart858c9f62007-06-17 19:56:39 -05002860 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2861 "Issue ACC RNID: did:x%x flg:x%x",
2862 ndlp->nlp_DID, ndlp->nlp_flag, 0);
2863
dea31012005-04-17 16:05:31 -05002864 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05002865 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart329f9bc2007-04-25 09:53:01 -04002866 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002867 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
2868 * it could be freed */
2869
dea31012005-04-17 16:05:31 -05002870 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
dea31012005-04-17 16:05:31 -05002871 if (rc == IOCB_ERROR) {
2872 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002873 return 1;
dea31012005-04-17 16:05:31 -05002874 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002875 return 0;
dea31012005-04-17 16:05:31 -05002876}
2877
2878int
James Smart2e0fef82007-06-17 19:56:36 -05002879lpfc_els_disc_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002880{
James Smart2e0fef82007-06-17 19:56:36 -05002881 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002882 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05002883 int sentadisc = 0;
dea31012005-04-17 16:05:31 -05002884
James Smart685f0bf2007-04-25 09:53:08 -04002885 /* go thru NPR nodes and issue any remaining ELS ADISCs */
James Smart2e0fef82007-06-17 19:56:36 -05002886 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05002887 if (!NLP_CHK_NODE_ACT(ndlp))
2888 continue;
James Smart685f0bf2007-04-25 09:53:08 -04002889 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
2890 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
2891 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
James Smart2e0fef82007-06-17 19:56:36 -05002892 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04002893 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05002894 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04002895 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002896 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2897 lpfc_issue_els_adisc(vport, ndlp, 0);
James Smart685f0bf2007-04-25 09:53:08 -04002898 sentadisc++;
James Smart2e0fef82007-06-17 19:56:36 -05002899 vport->num_disc_nodes++;
2900 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04002901 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05002902 spin_lock_irq(shost->host_lock);
2903 vport->fc_flag |= FC_NLP_MORE;
2904 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04002905 break;
dea31012005-04-17 16:05:31 -05002906 }
2907 }
2908 }
2909 if (sentadisc == 0) {
James Smart2e0fef82007-06-17 19:56:36 -05002910 spin_lock_irq(shost->host_lock);
2911 vport->fc_flag &= ~FC_NLP_MORE;
2912 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002913 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002914 return sentadisc;
dea31012005-04-17 16:05:31 -05002915}
2916
2917int
James Smart2e0fef82007-06-17 19:56:36 -05002918lpfc_els_disc_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002919{
James Smart2e0fef82007-06-17 19:56:36 -05002920 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002921 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05002922 int sentplogi = 0;
dea31012005-04-17 16:05:31 -05002923
James Smart2e0fef82007-06-17 19:56:36 -05002924 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
2925 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05002926 if (!NLP_CHK_NODE_ACT(ndlp))
2927 continue;
James Smart685f0bf2007-04-25 09:53:08 -04002928 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
2929 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
2930 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
2931 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
2932 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002933 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2934 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
James Smart685f0bf2007-04-25 09:53:08 -04002935 sentplogi++;
James Smart2e0fef82007-06-17 19:56:36 -05002936 vport->num_disc_nodes++;
2937 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04002938 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05002939 spin_lock_irq(shost->host_lock);
2940 vport->fc_flag |= FC_NLP_MORE;
2941 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04002942 break;
dea31012005-04-17 16:05:31 -05002943 }
2944 }
2945 }
James Smart87af33f2007-10-27 13:37:43 -04002946 if (sentplogi) {
2947 lpfc_set_disctmo(vport);
2948 }
2949 else {
James Smart2e0fef82007-06-17 19:56:36 -05002950 spin_lock_irq(shost->host_lock);
2951 vport->fc_flag &= ~FC_NLP_MORE;
2952 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002953 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002954 return sentplogi;
dea31012005-04-17 16:05:31 -05002955}
2956
James Smart92d7f7b2007-06-17 19:56:38 -05002957void
James Smart2e0fef82007-06-17 19:56:36 -05002958lpfc_els_flush_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002959{
James Smart2e0fef82007-06-17 19:56:36 -05002960 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2961 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002962 int i;
2963
James Smart7f5f3d02008-02-08 18:50:14 -05002964 spin_lock_irq(shost->host_lock);
2965 if (vport->fc_rscn_flush) {
2966 /* Another thread is walking fc_rscn_id_list on this vport */
2967 spin_unlock_irq(shost->host_lock);
2968 return;
2969 }
2970 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
2971 vport->fc_rscn_flush = 1;
2972 spin_unlock_irq(shost->host_lock);
2973
James Smart2e0fef82007-06-17 19:56:36 -05002974 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05002975 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
James Smart2e0fef82007-06-17 19:56:36 -05002976 vport->fc_rscn_id_list[i] = NULL;
dea31012005-04-17 16:05:31 -05002977 }
James Smart2e0fef82007-06-17 19:56:36 -05002978 spin_lock_irq(shost->host_lock);
2979 vport->fc_rscn_id_cnt = 0;
2980 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
2981 spin_unlock_irq(shost->host_lock);
2982 lpfc_can_disctmo(vport);
James Smart7f5f3d02008-02-08 18:50:14 -05002983 /* Indicate we are done walking this fc_rscn_id_list */
2984 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05002985}
2986
2987int
James Smart2e0fef82007-06-17 19:56:36 -05002988lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05002989{
2990 D_ID ns_did;
2991 D_ID rscn_did;
dea31012005-04-17 16:05:31 -05002992 uint32_t *lp;
James Smart92d7f7b2007-06-17 19:56:38 -05002993 uint32_t payload_len, i;
James Smart7f5f3d02008-02-08 18:50:14 -05002994 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002995
2996 ns_did.un.word = did;
dea31012005-04-17 16:05:31 -05002997
2998 /* Never match fabric nodes for RSCNs */
2999 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
James Smart2e0fef82007-06-17 19:56:36 -05003000 return 0;
dea31012005-04-17 16:05:31 -05003001
3002 /* If we are doing a FULL RSCN rediscovery, match everything */
James Smart2e0fef82007-06-17 19:56:36 -05003003 if (vport->fc_flag & FC_RSCN_DISCOVERY)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003004 return did;
dea31012005-04-17 16:05:31 -05003005
James Smart7f5f3d02008-02-08 18:50:14 -05003006 spin_lock_irq(shost->host_lock);
3007 if (vport->fc_rscn_flush) {
3008 /* Another thread is walking fc_rscn_id_list on this vport */
3009 spin_unlock_irq(shost->host_lock);
3010 return 0;
3011 }
3012 /* Indicate we are walking fc_rscn_id_list on this vport */
3013 vport->fc_rscn_flush = 1;
3014 spin_unlock_irq(shost->host_lock);
James Smart2e0fef82007-06-17 19:56:36 -05003015 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05003016 lp = vport->fc_rscn_id_list[i]->virt;
3017 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
3018 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05003019 while (payload_len) {
James Smart92d7f7b2007-06-17 19:56:38 -05003020 rscn_did.un.word = be32_to_cpu(*lp++);
3021 payload_len -= sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003022 switch (rscn_did.un.b.resv) {
3023 case 0: /* Single N_Port ID effected */
James Smart2e0fef82007-06-17 19:56:36 -05003024 if (ns_did.un.word == rscn_did.un.word)
James Smart7f5f3d02008-02-08 18:50:14 -05003025 goto return_did_out;
dea31012005-04-17 16:05:31 -05003026 break;
3027 case 1: /* Whole N_Port Area effected */
3028 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
3029 && (ns_did.un.b.area == rscn_did.un.b.area))
James Smart7f5f3d02008-02-08 18:50:14 -05003030 goto return_did_out;
dea31012005-04-17 16:05:31 -05003031 break;
3032 case 2: /* Whole N_Port Domain effected */
3033 if (ns_did.un.b.domain == rscn_did.un.b.domain)
James Smart7f5f3d02008-02-08 18:50:14 -05003034 goto return_did_out;
dea31012005-04-17 16:05:31 -05003035 break;
3036 default:
James Smart2e0fef82007-06-17 19:56:36 -05003037 /* Unknown Identifier in RSCN node */
James Smarte8b62012007-08-02 11:10:09 -04003038 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
3039 "0217 Unknown Identifier in "
3040 "RSCN payload Data: x%x\n",
3041 rscn_did.un.word);
James Smart92d7f7b2007-06-17 19:56:38 -05003042 case 3: /* Whole Fabric effected */
James Smart7f5f3d02008-02-08 18:50:14 -05003043 goto return_did_out;
dea31012005-04-17 16:05:31 -05003044 }
3045 }
James Smart92d7f7b2007-06-17 19:56:38 -05003046 }
James Smart7f5f3d02008-02-08 18:50:14 -05003047 /* Indicate we are done with walking fc_rscn_id_list on this vport */
3048 vport->fc_rscn_flush = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05003049 return 0;
James Smart7f5f3d02008-02-08 18:50:14 -05003050return_did_out:
3051 /* Indicate we are done with walking fc_rscn_id_list on this vport */
3052 vport->fc_rscn_flush = 0;
3053 return did;
dea31012005-04-17 16:05:31 -05003054}
3055
3056static int
James Smart2e0fef82007-06-17 19:56:36 -05003057lpfc_rscn_recovery_check(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003058{
James Smart685f0bf2007-04-25 09:53:08 -04003059 struct lpfc_nodelist *ndlp = NULL;
dea31012005-04-17 16:05:31 -05003060
James Smart0d2b6b82008-06-14 22:52:47 -04003061 /* Move all affected nodes by pending RSCNs to NPR state. */
James Smart2e0fef82007-06-17 19:56:36 -05003062 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05003063 if (!NLP_CHK_NODE_ACT(ndlp) ||
James Smart0d2b6b82008-06-14 22:52:47 -04003064 (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
3065 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
dea31012005-04-17 16:05:31 -05003066 continue;
James Smart2e0fef82007-06-17 19:56:36 -05003067 lpfc_disc_state_machine(vport, ndlp, NULL,
James Smart0d2b6b82008-06-14 22:52:47 -04003068 NLP_EVT_DEVICE_RECOVERY);
3069 lpfc_cancel_retry_delay_tmo(vport, ndlp);
dea31012005-04-17 16:05:31 -05003070 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003071 return 0;
dea31012005-04-17 16:05:31 -05003072}
3073
3074static int
James Smart2e0fef82007-06-17 19:56:36 -05003075lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04003076 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003077{
James Smart2e0fef82007-06-17 19:56:36 -05003078 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3079 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003080 struct lpfc_dmabuf *pcmd;
James Smart92d7f7b2007-06-17 19:56:38 -05003081 uint32_t *lp, *datap;
dea31012005-04-17 16:05:31 -05003082 IOCB_t *icmd;
James Smart92d7f7b2007-06-17 19:56:38 -05003083 uint32_t payload_len, length, nportid, *cmd;
James Smart7f5f3d02008-02-08 18:50:14 -05003084 int rscn_cnt;
James Smart92d7f7b2007-06-17 19:56:38 -05003085 int rscn_id = 0, hba_id = 0;
James Smartd2873e42006-08-18 17:46:43 -04003086 int i;
dea31012005-04-17 16:05:31 -05003087
3088 icmd = &cmdiocb->iocb;
3089 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3090 lp = (uint32_t *) pcmd->virt;
3091
James Smart92d7f7b2007-06-17 19:56:38 -05003092 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
3093 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05003094 /* RSCN received */
James Smarte8b62012007-08-02 11:10:09 -04003095 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3096 "0214 RSCN received Data: x%x x%x x%x x%x\n",
James Smart7f5f3d02008-02-08 18:50:14 -05003097 vport->fc_flag, payload_len, *lp,
3098 vport->fc_rscn_id_cnt);
James Smartd2873e42006-08-18 17:46:43 -04003099 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
James Smart2e0fef82007-06-17 19:56:36 -05003100 fc_host_post_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04003101 FCH_EVT_RSCN, lp[i]);
3102
dea31012005-04-17 16:05:31 -05003103 /* If we are about to begin discovery, just ACC the RSCN.
3104 * Discovery processing will satisfy it.
3105 */
James Smart2e0fef82007-06-17 19:56:36 -05003106 if (vport->port_state <= LPFC_NS_QRY) {
James Smart858c9f62007-06-17 19:56:39 -05003107 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3108 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
3109 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
3110
James Smart51ef4c22007-08-02 11:10:31 -04003111 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003112 return 0;
dea31012005-04-17 16:05:31 -05003113 }
3114
James Smart92d7f7b2007-06-17 19:56:38 -05003115 /* If this RSCN just contains NPortIDs for other vports on this HBA,
3116 * just ACC and ignore it.
3117 */
3118 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart3de2a652007-08-02 11:09:59 -04003119 !(vport->cfg_peer_port_login)) {
James Smart92d7f7b2007-06-17 19:56:38 -05003120 i = payload_len;
3121 datap = lp;
3122 while (i > 0) {
3123 nportid = *datap++;
3124 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
3125 i -= sizeof(uint32_t);
3126 rscn_id++;
James Smart549e55c2007-08-02 11:09:51 -04003127 if (lpfc_find_vport_by_did(phba, nportid))
3128 hba_id++;
James Smart92d7f7b2007-06-17 19:56:38 -05003129 }
3130 if (rscn_id == hba_id) {
3131 /* ALL NPortIDs in RSCN are on HBA */
James Smarte8b62012007-08-02 11:10:09 -04003132 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3133 "0214 Ignore RSCN "
3134 "Data: x%x x%x x%x x%x\n",
3135 vport->fc_flag, payload_len,
James Smart7f5f3d02008-02-08 18:50:14 -05003136 *lp, vport->fc_rscn_id_cnt);
James Smart858c9f62007-06-17 19:56:39 -05003137 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3138 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
3139 ndlp->nlp_DID, vport->port_state,
3140 ndlp->nlp_flag);
3141
James Smart92d7f7b2007-06-17 19:56:38 -05003142 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04003143 ndlp, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05003144 return 0;
3145 }
3146 }
3147
James Smart7f5f3d02008-02-08 18:50:14 -05003148 spin_lock_irq(shost->host_lock);
3149 if (vport->fc_rscn_flush) {
3150 /* Another thread is walking fc_rscn_id_list on this vport */
3151 spin_unlock_irq(shost->host_lock);
3152 vport->fc_flag |= FC_RSCN_DISCOVERY;
James Smart58da1ff2008-04-07 10:15:56 -04003153 /* Send back ACC */
3154 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart7f5f3d02008-02-08 18:50:14 -05003155 return 0;
3156 }
3157 /* Indicate we are walking fc_rscn_id_list on this vport */
3158 vport->fc_rscn_flush = 1;
3159 spin_unlock_irq(shost->host_lock);
3160 /* Get the array count after sucessfully have the token */
3161 rscn_cnt = vport->fc_rscn_id_cnt;
dea31012005-04-17 16:05:31 -05003162 /* If we are already processing an RSCN, save the received
3163 * RSCN payload buffer, cmdiocb->context2 to process later.
3164 */
James Smart2e0fef82007-06-17 19:56:36 -05003165 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
James Smart858c9f62007-06-17 19:56:39 -05003166 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3167 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
3168 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
3169
James Smart09372822008-01-11 01:52:54 -05003170 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05003171 vport->fc_flag |= FC_RSCN_DEFERRED;
3172 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
James Smart2e0fef82007-06-17 19:56:36 -05003173 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
James Smart2e0fef82007-06-17 19:56:36 -05003174 vport->fc_flag |= FC_RSCN_MODE;
3175 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05003176 if (rscn_cnt) {
3177 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
3178 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
3179 }
3180 if ((rscn_cnt) &&
3181 (payload_len + length <= LPFC_BPL_SIZE)) {
3182 *cmd &= ELS_CMD_MASK;
James Smart7f5f3d02008-02-08 18:50:14 -05003183 *cmd |= cpu_to_be32(payload_len + length);
James Smart92d7f7b2007-06-17 19:56:38 -05003184 memcpy(((uint8_t *)cmd) + length, lp,
3185 payload_len);
3186 } else {
3187 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
3188 vport->fc_rscn_id_cnt++;
3189 /* If we zero, cmdiocb->context2, the calling
3190 * routine will not try to free it.
3191 */
3192 cmdiocb->context2 = NULL;
3193 }
dea31012005-04-17 16:05:31 -05003194 /* Deferred RSCN */
James Smarte8b62012007-08-02 11:10:09 -04003195 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3196 "0235 Deferred RSCN "
3197 "Data: x%x x%x x%x\n",
3198 vport->fc_rscn_id_cnt, vport->fc_flag,
3199 vport->port_state);
dea31012005-04-17 16:05:31 -05003200 } else {
James Smart2e0fef82007-06-17 19:56:36 -05003201 vport->fc_flag |= FC_RSCN_DISCOVERY;
3202 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003203 /* ReDiscovery RSCN */
James Smarte8b62012007-08-02 11:10:09 -04003204 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3205 "0234 ReDiscovery RSCN "
3206 "Data: x%x x%x x%x\n",
3207 vport->fc_rscn_id_cnt, vport->fc_flag,
3208 vport->port_state);
dea31012005-04-17 16:05:31 -05003209 }
James Smart7f5f3d02008-02-08 18:50:14 -05003210 /* Indicate we are done walking fc_rscn_id_list on this vport */
3211 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05003212 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04003213 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05003214 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05003215 lpfc_rscn_recovery_check(vport);
James Smart09372822008-01-11 01:52:54 -05003216 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05003217 vport->fc_flag &= ~FC_RSCN_DEFERRED;
James Smart09372822008-01-11 01:52:54 -05003218 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003219 return 0;
dea31012005-04-17 16:05:31 -05003220 }
James Smart858c9f62007-06-17 19:56:39 -05003221 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3222 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
3223 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
3224
James Smart2e0fef82007-06-17 19:56:36 -05003225 spin_lock_irq(shost->host_lock);
3226 vport->fc_flag |= FC_RSCN_MODE;
3227 spin_unlock_irq(shost->host_lock);
3228 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
James Smart7f5f3d02008-02-08 18:50:14 -05003229 /* Indicate we are done walking fc_rscn_id_list on this vport */
3230 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05003231 /*
3232 * If we zero, cmdiocb->context2, the calling routine will
3233 * not try to free it.
3234 */
3235 cmdiocb->context2 = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05003236 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05003237 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04003238 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05003239 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05003240 lpfc_rscn_recovery_check(vport);
James Smart2e0fef82007-06-17 19:56:36 -05003241 return lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05003242}
3243
3244int
James Smart2e0fef82007-06-17 19:56:36 -05003245lpfc_els_handle_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003246{
3247 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05003248 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003249
James Smart92d7f7b2007-06-17 19:56:38 -05003250 /* Ignore RSCN if the port is being torn down. */
3251 if (vport->load_flag & FC_UNLOADING) {
3252 lpfc_els_flush_rscn(vport);
3253 return 0;
3254 }
3255
dea31012005-04-17 16:05:31 -05003256 /* Start timer for RSCN processing */
James Smart2e0fef82007-06-17 19:56:36 -05003257 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05003258
3259 /* RSCN processed */
James Smarte8b62012007-08-02 11:10:09 -04003260 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3261 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
3262 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
3263 vport->port_state);
dea31012005-04-17 16:05:31 -05003264
3265 /* To process RSCN, first compare RSCN data with NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05003266 vport->fc_ns_retry = 0;
James Smart0ff10d42008-01-11 01:52:36 -05003267 vport->num_disc_nodes = 0;
3268
James Smart2e0fef82007-06-17 19:56:36 -05003269 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05003270 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
3271 && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
dea31012005-04-17 16:05:31 -05003272 /* Good ndlp, issue CT Request to NameServer */
James Smart92d7f7b2007-06-17 19:56:38 -05003273 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
dea31012005-04-17 16:05:31 -05003274 /* Wait for NameServer query cmpl before we can
3275 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003276 return 1;
dea31012005-04-17 16:05:31 -05003277 } else {
3278 /* If login to NameServer does not exist, issue one */
3279 /* Good status, issue PLOGI to NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05003280 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05003281 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
dea31012005-04-17 16:05:31 -05003282 /* Wait for NameServer login cmpl before we can
3283 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003284 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05003285
James Smarte47c9092008-02-08 18:49:26 -05003286 if (ndlp) {
3287 ndlp = lpfc_enable_node(vport, ndlp,
3288 NLP_STE_PLOGI_ISSUE);
3289 if (!ndlp) {
3290 lpfc_els_flush_rscn(vport);
3291 return 0;
3292 }
3293 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
dea31012005-04-17 16:05:31 -05003294 } else {
James Smarte47c9092008-02-08 18:49:26 -05003295 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
3296 if (!ndlp) {
3297 lpfc_els_flush_rscn(vport);
3298 return 0;
3299 }
James Smart2e0fef82007-06-17 19:56:36 -05003300 lpfc_nlp_init(vport, ndlp, NameServer_DID);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003301 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003302 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
dea31012005-04-17 16:05:31 -05003303 }
James Smarte47c9092008-02-08 18:49:26 -05003304 ndlp->nlp_type |= NLP_FABRIC;
3305 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
3306 /* Wait for NameServer login cmpl before we can
3307 * continue
3308 */
3309 return 1;
dea31012005-04-17 16:05:31 -05003310 }
3311
James Smart2e0fef82007-06-17 19:56:36 -05003312 lpfc_els_flush_rscn(vport);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003313 return 0;
dea31012005-04-17 16:05:31 -05003314}
3315
3316static int
James Smart2e0fef82007-06-17 19:56:36 -05003317lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04003318 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003319{
James Smart2e0fef82007-06-17 19:56:36 -05003320 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3321 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003322 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3323 uint32_t *lp = (uint32_t *) pcmd->virt;
3324 IOCB_t *icmd = &cmdiocb->iocb;
3325 struct serv_parm *sp;
3326 LPFC_MBOXQ_t *mbox;
3327 struct ls_rjt stat;
3328 uint32_t cmd, did;
3329 int rc;
3330
3331 cmd = *lp++;
3332 sp = (struct serv_parm *) lp;
3333
3334 /* FLOGI received */
3335
James Smart2e0fef82007-06-17 19:56:36 -05003336 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05003337
3338 if (phba->fc_topology == TOPOLOGY_LOOP) {
3339 /* We should never receive a FLOGI in loop mode, ignore it */
3340 did = icmd->un.elsreq64.remoteID;
3341
3342 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
3343 Loop Mode */
James Smarte8b62012007-08-02 11:10:09 -04003344 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3345 "0113 An FLOGI ELS command x%x was "
3346 "received from DID x%x in Loop Mode\n",
3347 cmd, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003348 return 1;
dea31012005-04-17 16:05:31 -05003349 }
3350
3351 did = Fabric_DID;
3352
James Smart2e0fef82007-06-17 19:56:36 -05003353 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3))) {
dea31012005-04-17 16:05:31 -05003354 /* For a FLOGI we accept, then if our portname is greater
3355 * then the remote portname we initiate Nport login.
3356 */
3357
James Smart2e0fef82007-06-17 19:56:36 -05003358 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -05003359 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003360
3361 if (!rc) {
James Smart2e0fef82007-06-17 19:56:36 -05003362 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3363 if (!mbox)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003364 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05003365
dea31012005-04-17 16:05:31 -05003366 lpfc_linkdown(phba);
3367 lpfc_init_link(phba, mbox,
3368 phba->cfg_topology,
3369 phba->cfg_link_speed);
3370 mbox->mb.un.varInitLnk.lipsr_AL_PA = 0;
3371 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -05003372 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -04003373 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart5b8bd0c2007-04-25 09:52:49 -04003374 lpfc_set_loopback_flag(phba);
dea31012005-04-17 16:05:31 -05003375 if (rc == MBX_NOT_FINISHED) {
James Smart329f9bc2007-04-25 09:53:01 -04003376 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003377 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003378 return 1;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003379 } else if (rc > 0) { /* greater than */
James Smart2e0fef82007-06-17 19:56:36 -05003380 spin_lock_irq(shost->host_lock);
3381 vport->fc_flag |= FC_PT2PT_PLOGI;
3382 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003383 }
James Smart2e0fef82007-06-17 19:56:36 -05003384 spin_lock_irq(shost->host_lock);
3385 vport->fc_flag |= FC_PT2PT;
3386 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
3387 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003388 } else {
3389 /* Reject this request because invalid parameters */
3390 stat.un.b.lsRjtRsvd0 = 0;
3391 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3392 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
3393 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05003394 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
3395 NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003396 return 1;
dea31012005-04-17 16:05:31 -05003397 }
3398
3399 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04003400 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05003401
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003402 return 0;
dea31012005-04-17 16:05:31 -05003403}
3404
3405static int
James Smart2e0fef82007-06-17 19:56:36 -05003406lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3407 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003408{
3409 struct lpfc_dmabuf *pcmd;
3410 uint32_t *lp;
3411 IOCB_t *icmd;
3412 RNID *rn;
3413 struct ls_rjt stat;
3414 uint32_t cmd, did;
3415
3416 icmd = &cmdiocb->iocb;
3417 did = icmd->un.elsreq64.remoteID;
3418 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3419 lp = (uint32_t *) pcmd->virt;
3420
3421 cmd = *lp++;
3422 rn = (RNID *) lp;
3423
3424 /* RNID received */
3425
3426 switch (rn->Format) {
3427 case 0:
3428 case RNID_TOPOLOGY_DISC:
3429 /* Send back ACC */
James Smart2e0fef82007-06-17 19:56:36 -05003430 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05003431 break;
3432 default:
3433 /* Reject this request because format not supported */
3434 stat.un.b.lsRjtRsvd0 = 0;
3435 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3436 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
3437 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05003438 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
3439 NULL);
dea31012005-04-17 16:05:31 -05003440 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003441 return 0;
dea31012005-04-17 16:05:31 -05003442}
3443
3444static int
James Smart2e0fef82007-06-17 19:56:36 -05003445lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3446 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003447{
3448 struct ls_rjt stat;
3449
3450 /* For now, unconditionally reject this command */
3451 stat.un.b.lsRjtRsvd0 = 0;
3452 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3453 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
3454 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05003455 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003456 return 0;
3457}
3458
Jamie Wellnitz082c0262006-02-28 19:25:30 -05003459static void
James Smart329f9bc2007-04-25 09:53:01 -04003460lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003461{
James Smart2e0fef82007-06-17 19:56:36 -05003462 struct lpfc_sli *psli = &phba->sli;
3463 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003464 MAILBOX_t *mb;
3465 IOCB_t *icmd;
3466 RPS_RSP *rps_rsp;
3467 uint8_t *pcmd;
3468 struct lpfc_iocbq *elsiocb;
3469 struct lpfc_nodelist *ndlp;
3470 uint16_t xri, status;
3471 uint32_t cmdsize;
3472
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003473 mb = &pmb->mb;
3474
3475 ndlp = (struct lpfc_nodelist *) pmb->context2;
3476 xri = (uint16_t) ((unsigned long)(pmb->context1));
Randy Dunlap041976f2006-06-25 01:58:51 -07003477 pmb->context1 = NULL;
3478 pmb->context2 = NULL;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003479
3480 if (mb->mbxStatus) {
James Smart329f9bc2007-04-25 09:53:01 -04003481 mempool_free(pmb, phba->mbox_mem_pool);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003482 return;
3483 }
3484
3485 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
James Smart329f9bc2007-04-25 09:53:01 -04003486 mempool_free(pmb, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05003487 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
3488 lpfc_max_els_tries, ndlp,
3489 ndlp->nlp_DID, ELS_CMD_ACC);
James Smartfa4066b2008-01-11 01:53:27 -05003490
3491 /* Decrement the ndlp reference count from previous mbox command */
James Smart329f9bc2007-04-25 09:53:01 -04003492 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05003493
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003494 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003495 return;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003496
3497 icmd = &elsiocb->iocb;
3498 icmd->ulpContext = xri;
3499
3500 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3501 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003502 pcmd += sizeof(uint32_t); /* Skip past command */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003503 rps_rsp = (RPS_RSP *)pcmd;
3504
3505 if (phba->fc_topology != TOPOLOGY_LOOP)
3506 status = 0x10;
3507 else
3508 status = 0x8;
James Smart2e0fef82007-06-17 19:56:36 -05003509 if (phba->pport->fc_flag & FC_FABRIC)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003510 status |= 0x4;
3511
3512 rps_rsp->rsvd1 = 0;
James Smart09372822008-01-11 01:52:54 -05003513 rps_rsp->portStatus = cpu_to_be16(status);
3514 rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
3515 rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
3516 rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
3517 rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
3518 rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
3519 rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003520 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003521 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
3522 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
3523 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
3524 elsiocb->iotag, elsiocb->iocb.ulpContext,
3525 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3526 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05003527 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003528 phba->fc_stat.elsXmitACC++;
James Smarted957682007-06-17 19:56:37 -05003529 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003530 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003531 return;
3532}
3533
3534static int
James Smart2e0fef82007-06-17 19:56:36 -05003535lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3536 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003537{
James Smart2e0fef82007-06-17 19:56:36 -05003538 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003539 uint32_t *lp;
3540 uint8_t flag;
3541 LPFC_MBOXQ_t *mbox;
3542 struct lpfc_dmabuf *pcmd;
3543 RPS *rps;
3544 struct ls_rjt stat;
3545
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003546 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
3547 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003548 stat.un.b.lsRjtRsvd0 = 0;
3549 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3550 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
3551 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05003552 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
3553 NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003554 }
3555
3556 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3557 lp = (uint32_t *) pcmd->virt;
3558 flag = (be32_to_cpu(*lp++) & 0xf);
3559 rps = (RPS *) lp;
3560
3561 if ((flag == 0) ||
3562 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
James Smart2e0fef82007-06-17 19:56:36 -05003563 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05003564 sizeof(struct lpfc_name)) == 0))) {
James Smart2e0fef82007-06-17 19:56:36 -05003565
James Smart92d7f7b2007-06-17 19:56:38 -05003566 printk("Fix me....\n");
3567 dump_stack();
James Smart2e0fef82007-06-17 19:56:36 -05003568 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
3569 if (mbox) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003570 lpfc_read_lnk_stat(phba, mbox);
3571 mbox->context1 =
James Smart92d7f7b2007-06-17 19:56:38 -05003572 (void *)((unsigned long) cmdiocb->iocb.ulpContext);
James Smart329f9bc2007-04-25 09:53:01 -04003573 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05003574 mbox->vport = vport;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003575 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
James Smartfa4066b2008-01-11 01:53:27 -05003576 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart0b727fe2007-10-27 13:37:25 -04003577 != MBX_NOT_FINISHED)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003578 /* Mbox completion will send ELS Response */
3579 return 0;
James Smartfa4066b2008-01-11 01:53:27 -05003580 /* Decrement reference count used for the failed mbox
3581 * command.
3582 */
James Smart329f9bc2007-04-25 09:53:01 -04003583 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003584 mempool_free(mbox, phba->mbox_mem_pool);
3585 }
3586 }
3587 stat.un.b.lsRjtRsvd0 = 0;
3588 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3589 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
3590 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05003591 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003592 return 0;
3593}
3594
Jamie Wellnitz082c0262006-02-28 19:25:30 -05003595static int
James Smart2e0fef82007-06-17 19:56:36 -05003596lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
3597 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003598{
James Smart2e0fef82007-06-17 19:56:36 -05003599 struct lpfc_hba *phba = vport->phba;
3600 IOCB_t *icmd, *oldcmd;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003601 RPL_RSP rpl_rsp;
3602 struct lpfc_iocbq *elsiocb;
James Smart2e0fef82007-06-17 19:56:36 -05003603 struct lpfc_sli *psli = &phba->sli;
3604 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003605 uint8_t *pcmd;
3606
James Smart2e0fef82007-06-17 19:56:36 -05003607 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3608 ndlp->nlp_DID, ELS_CMD_ACC);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003609
James Smart488d1462006-03-07 15:02:37 -05003610 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003611 return 1;
James Smart488d1462006-03-07 15:02:37 -05003612
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003613 icmd = &elsiocb->iocb;
3614 oldcmd = &oldiocb->iocb;
3615 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3616
3617 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3618 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003619 pcmd += sizeof(uint16_t);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003620 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
3621 pcmd += sizeof(uint16_t);
3622
3623 /* Setup the RPL ACC payload */
3624 rpl_rsp.listLen = be32_to_cpu(1);
3625 rpl_rsp.index = 0;
3626 rpl_rsp.port_num_blk.portNum = 0;
James Smart2e0fef82007-06-17 19:56:36 -05003627 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
3628 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003629 sizeof(struct lpfc_name));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003630 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003631 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003632 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3633 "0120 Xmit ELS RPL ACC response tag x%x "
3634 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
3635 "rpi x%x\n",
3636 elsiocb->iotag, elsiocb->iocb.ulpContext,
3637 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3638 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05003639 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003640 phba->fc_stat.elsXmitACC++;
3641 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
3642 lpfc_els_free_iocb(phba, elsiocb);
3643 return 1;
3644 }
3645 return 0;
3646}
3647
3648static int
James Smart2e0fef82007-06-17 19:56:36 -05003649lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3650 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003651{
3652 struct lpfc_dmabuf *pcmd;
3653 uint32_t *lp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003654 uint32_t maxsize;
3655 uint16_t cmdsize;
3656 RPL *rpl;
3657 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05003658
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003659 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
3660 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003661 stat.un.b.lsRjtRsvd0 = 0;
3662 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3663 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
3664 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05003665 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
3666 NULL);
dea31012005-04-17 16:05:31 -05003667 }
3668
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003669 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3670 lp = (uint32_t *) pcmd->virt;
3671 rpl = (RPL *) (lp + 1);
3672
3673 maxsize = be32_to_cpu(rpl->maxsize);
3674
3675 /* We support only one port */
3676 if ((rpl->index == 0) &&
3677 ((maxsize == 0) ||
3678 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
3679 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003680 } else {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003681 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
3682 }
James Smart2e0fef82007-06-17 19:56:36 -05003683 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05003684
3685 return 0;
3686}
3687
3688static int
James Smart2e0fef82007-06-17 19:56:36 -05003689lpfc_els_rcv_farp(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 FARP *fp;
3696 uint32_t cmd, cnt, did;
3697
3698 icmd = &cmdiocb->iocb;
3699 did = icmd->un.elsreq64.remoteID;
3700 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3701 lp = (uint32_t *) pcmd->virt;
3702
3703 cmd = *lp++;
3704 fp = (FARP *) lp;
dea31012005-04-17 16:05:31 -05003705 /* FARP-REQ received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04003706 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3707 "0601 FARP-REQ received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05003708 /* We will only support match on WWPN or WWNN */
3709 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003710 return 0;
dea31012005-04-17 16:05:31 -05003711 }
3712
3713 cnt = 0;
3714 /* If this FARP command is searching for my portname */
3715 if (fp->Mflags & FARP_MATCH_PORT) {
James Smart2e0fef82007-06-17 19:56:36 -05003716 if (memcmp(&fp->RportName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05003717 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05003718 cnt = 1;
3719 }
3720
3721 /* If this FARP command is searching for my nodename */
3722 if (fp->Mflags & FARP_MATCH_NODE) {
James Smart2e0fef82007-06-17 19:56:36 -05003723 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05003724 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05003725 cnt = 1;
3726 }
3727
3728 if (cnt) {
3729 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
3730 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
3731 /* Log back into the node before sending the FARP. */
3732 if (fp->Rflags & FARP_REQUEST_PLOGI) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003733 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003734 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04003735 NLP_STE_PLOGI_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05003736 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05003737 }
3738
3739 /* Send a FARP response to that node */
James Smart2e0fef82007-06-17 19:56:36 -05003740 if (fp->Rflags & FARP_REQUEST_FARPR)
3741 lpfc_issue_els_farpr(vport, did, 0);
dea31012005-04-17 16:05:31 -05003742 }
3743 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003744 return 0;
dea31012005-04-17 16:05:31 -05003745}
3746
3747static int
James Smart2e0fef82007-06-17 19:56:36 -05003748lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3749 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003750{
3751 struct lpfc_dmabuf *pcmd;
3752 uint32_t *lp;
3753 IOCB_t *icmd;
3754 uint32_t cmd, did;
3755
3756 icmd = &cmdiocb->iocb;
3757 did = icmd->un.elsreq64.remoteID;
3758 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3759 lp = (uint32_t *) pcmd->virt;
3760
3761 cmd = *lp++;
3762 /* FARP-RSP received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04003763 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3764 "0600 FARP-RSP received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05003765 /* ACCEPT the Farp resp request */
James Smart51ef4c22007-08-02 11:10:31 -04003766 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05003767
3768 return 0;
3769}
3770
3771static int
James Smart2e0fef82007-06-17 19:56:36 -05003772lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3773 struct lpfc_nodelist *fan_ndlp)
dea31012005-04-17 16:05:31 -05003774{
James Smart2e0fef82007-06-17 19:56:36 -05003775 struct lpfc_hba *phba = vport->phba;
James Smart0d2b6b82008-06-14 22:52:47 -04003776 uint32_t *lp;
3777 FAN *fp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003778
James Smart0d2b6b82008-06-14 22:52:47 -04003779 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
3780 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
3781 fp = (FAN *) ++lp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003782 /* FAN received; Fan does not have a reply sequence */
James Smart0d2b6b82008-06-14 22:52:47 -04003783 if ((vport == phba->pport) &&
3784 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003785 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
James Smart0d2b6b82008-06-14 22:52:47 -04003786 sizeof(struct lpfc_name))) ||
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003787 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
James Smart0d2b6b82008-06-14 22:52:47 -04003788 sizeof(struct lpfc_name)))) {
3789 /* This port has switched fabrics. FLOGI is required */
James Smart2e0fef82007-06-17 19:56:36 -05003790 lpfc_initial_flogi(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04003791 } else {
3792 /* FAN verified - skip FLOGI */
3793 vport->fc_myDID = vport->fc_prevDID;
3794 lpfc_issue_fabric_reglogin(vport);
dea31012005-04-17 16:05:31 -05003795 }
dea31012005-04-17 16:05:31 -05003796 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003797 return 0;
dea31012005-04-17 16:05:31 -05003798}
3799
3800void
3801lpfc_els_timeout(unsigned long ptr)
3802{
James Smart2e0fef82007-06-17 19:56:36 -05003803 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
3804 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003805 unsigned long iflag;
3806
James Smart2e0fef82007-06-17 19:56:36 -05003807 spin_lock_irqsave(&vport->work_port_lock, iflag);
3808 if ((vport->work_port_events & WORKER_ELS_TMO) == 0) {
3809 vport->work_port_events |= WORKER_ELS_TMO;
James Smart92d7f7b2007-06-17 19:56:38 -05003810 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
3811
3812 spin_lock_irqsave(&phba->hbalock, iflag);
dea31012005-04-17 16:05:31 -05003813 if (phba->work_wait)
James Smart92d7f7b2007-06-17 19:56:38 -05003814 lpfc_worker_wake_up(phba);
3815 spin_unlock_irqrestore(&phba->hbalock, iflag);
dea31012005-04-17 16:05:31 -05003816 }
James Smart92d7f7b2007-06-17 19:56:38 -05003817 else
3818 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
dea31012005-04-17 16:05:31 -05003819 return;
3820}
3821
3822void
James Smart2e0fef82007-06-17 19:56:36 -05003823lpfc_els_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003824{
James Smart2e0fef82007-06-17 19:56:36 -05003825 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003826 struct lpfc_sli_ring *pring;
3827 struct lpfc_iocbq *tmp_iocb, *piocb;
3828 IOCB_t *cmd = NULL;
3829 struct lpfc_dmabuf *pcmd;
James Smart2e0fef82007-06-17 19:56:36 -05003830 uint32_t els_command = 0;
dea31012005-04-17 16:05:31 -05003831 uint32_t timeout;
James Smart2e0fef82007-06-17 19:56:36 -05003832 uint32_t remote_ID = 0xffffffff;
dea31012005-04-17 16:05:31 -05003833
dea31012005-04-17 16:05:31 -05003834 /* If the timer is already canceled do nothing */
James Smart2e0fef82007-06-17 19:56:36 -05003835 if ((vport->work_port_events & WORKER_ELS_TMO) == 0) {
dea31012005-04-17 16:05:31 -05003836 return;
3837 }
James Smart2e0fef82007-06-17 19:56:36 -05003838 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003839 timeout = (uint32_t)(phba->fc_ratov << 1);
3840
3841 pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05003842
3843 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
3844 cmd = &piocb->iocb;
3845
James Smart2e0fef82007-06-17 19:56:36 -05003846 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
3847 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
3848 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
dea31012005-04-17 16:05:31 -05003849 continue;
James Smart2e0fef82007-06-17 19:56:36 -05003850
3851 if (piocb->vport != vport)
3852 continue;
3853
dea31012005-04-17 16:05:31 -05003854 pcmd = (struct lpfc_dmabuf *) piocb->context2;
James Smart2e0fef82007-06-17 19:56:36 -05003855 if (pcmd)
3856 els_command = *(uint32_t *) (pcmd->virt);
dea31012005-04-17 16:05:31 -05003857
James Smart92d7f7b2007-06-17 19:56:38 -05003858 if (els_command == ELS_CMD_FARP ||
3859 els_command == ELS_CMD_FARPR ||
3860 els_command == ELS_CMD_FDISC)
dea31012005-04-17 16:05:31 -05003861 continue;
James Smart92d7f7b2007-06-17 19:56:38 -05003862
3863 if (vport != piocb->vport)
3864 continue;
dea31012005-04-17 16:05:31 -05003865
3866 if (piocb->drvrTimeout > 0) {
James Smart92d7f7b2007-06-17 19:56:38 -05003867 if (piocb->drvrTimeout >= timeout)
dea31012005-04-17 16:05:31 -05003868 piocb->drvrTimeout -= timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05003869 else
dea31012005-04-17 16:05:31 -05003870 piocb->drvrTimeout = 0;
dea31012005-04-17 16:05:31 -05003871 continue;
3872 }
3873
James Smart2e0fef82007-06-17 19:56:36 -05003874 remote_ID = 0xffffffff;
3875 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
dea31012005-04-17 16:05:31 -05003876 remote_ID = cmd->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05003877 else {
3878 struct lpfc_nodelist *ndlp;
3879 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
James Smart58da1ff2008-04-07 10:15:56 -04003880 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart2e0fef82007-06-17 19:56:36 -05003881 remote_ID = ndlp->nlp_DID;
dea31012005-04-17 16:05:31 -05003882 }
James Smarte8b62012007-08-02 11:10:09 -04003883 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3884 "0127 ELS timeout Data: x%x x%x x%x "
3885 "x%x\n", els_command,
3886 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
James Smart07951072007-04-25 09:51:38 -04003887 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05003888 }
James Smart2e0fef82007-06-17 19:56:36 -05003889 spin_unlock_irq(&phba->hbalock);
James Smart5a0e3262006-07-06 15:49:16 -04003890
James Smart2e0fef82007-06-17 19:56:36 -05003891 if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt)
3892 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
dea31012005-04-17 16:05:31 -05003893}
3894
3895void
James Smart2e0fef82007-06-17 19:56:36 -05003896lpfc_els_flush_cmd(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003897{
James Smart2534ba72007-04-25 09:52:20 -04003898 LIST_HEAD(completions);
James Smart2e0fef82007-06-17 19:56:36 -05003899 struct lpfc_hba *phba = vport->phba;
James Smart329f9bc2007-04-25 09:53:01 -04003900 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05003901 struct lpfc_iocbq *tmp_iocb, *piocb;
3902 IOCB_t *cmd = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05003903
3904 lpfc_fabric_abort_vport(vport);
dea31012005-04-17 16:05:31 -05003905
James Smart2e0fef82007-06-17 19:56:36 -05003906 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003907 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
3908 cmd = &piocb->iocb;
3909
3910 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
3911 continue;
3912 }
3913
3914 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
James Smart329f9bc2007-04-25 09:53:01 -04003915 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
3916 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
3917 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
3918 cmd->ulpCommand == CMD_ABORT_XRI_CN)
dea31012005-04-17 16:05:31 -05003919 continue;
dea31012005-04-17 16:05:31 -05003920
James Smart2e0fef82007-06-17 19:56:36 -05003921 if (piocb->vport != vport)
3922 continue;
3923
James Smart2534ba72007-04-25 09:52:20 -04003924 list_move_tail(&piocb->list, &completions);
James Smart1dcb58e2007-04-25 09:51:30 -04003925 pring->txq_cnt--;
dea31012005-04-17 16:05:31 -05003926 }
3927
3928 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
dea31012005-04-17 16:05:31 -05003929 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
3930 continue;
3931 }
dea31012005-04-17 16:05:31 -05003932
James Smart2e0fef82007-06-17 19:56:36 -05003933 if (piocb->vport != vport)
3934 continue;
3935
James Smart07951072007-04-25 09:51:38 -04003936 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05003937 }
James Smart2e0fef82007-06-17 19:56:36 -05003938 spin_unlock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04003939
James Smart2e0fef82007-06-17 19:56:36 -05003940 while (!list_empty(&completions)) {
James Smart2534ba72007-04-25 09:52:20 -04003941 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
3942 cmd = &piocb->iocb;
James Smart92d7f7b2007-06-17 19:56:38 -05003943 list_del_init(&piocb->list);
James Smart2534ba72007-04-25 09:52:20 -04003944
James Smart2e0fef82007-06-17 19:56:36 -05003945 if (!piocb->iocb_cmpl)
3946 lpfc_sli_release_iocbq(phba, piocb);
3947 else {
James Smart2534ba72007-04-25 09:52:20 -04003948 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
3949 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
3950 (piocb->iocb_cmpl) (phba, piocb, piocb);
James Smart2e0fef82007-06-17 19:56:36 -05003951 }
James Smart2534ba72007-04-25 09:52:20 -04003952 }
3953
dea31012005-04-17 16:05:31 -05003954 return;
3955}
3956
James Smart549e55c2007-08-02 11:09:51 -04003957void
3958lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
3959{
3960 LIST_HEAD(completions);
3961 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
3962 struct lpfc_iocbq *tmp_iocb, *piocb;
3963 IOCB_t *cmd = NULL;
3964
3965 lpfc_fabric_abort_hba(phba);
3966 spin_lock_irq(&phba->hbalock);
3967 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
3968 cmd = &piocb->iocb;
3969 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
3970 continue;
3971 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
3972 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
3973 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
3974 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
3975 cmd->ulpCommand == CMD_ABORT_XRI_CN)
3976 continue;
3977 list_move_tail(&piocb->list, &completions);
3978 pring->txq_cnt--;
3979 }
3980 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
3981 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
3982 continue;
3983 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
3984 }
3985 spin_unlock_irq(&phba->hbalock);
3986 while (!list_empty(&completions)) {
3987 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
3988 cmd = &piocb->iocb;
3989 list_del_init(&piocb->list);
3990 if (!piocb->iocb_cmpl)
3991 lpfc_sli_release_iocbq(phba, piocb);
3992 else {
3993 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
3994 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
3995 (piocb->iocb_cmpl) (phba, piocb, piocb);
3996 }
3997 }
3998 return;
3999}
4000
James Smarted957682007-06-17 19:56:37 -05004001static void
4002lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
James Smart92d7f7b2007-06-17 19:56:38 -05004003 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05004004{
James Smart87af33f2007-10-27 13:37:43 -04004005 struct Scsi_Host *shost;
dea31012005-04-17 16:05:31 -05004006 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05004007 struct ls_rjt stat;
James Smart92d7f7b2007-06-17 19:56:38 -05004008 uint32_t *payload;
James Smart2e0fef82007-06-17 19:56:36 -05004009 uint32_t cmd, did, newnode, rjt_err = 0;
James Smarted957682007-06-17 19:56:37 -05004010 IOCB_t *icmd = &elsiocb->iocb;
dea31012005-04-17 16:05:31 -05004011
James Smarte47c9092008-02-08 18:49:26 -05004012 if (!vport || !(elsiocb->context2))
dea31012005-04-17 16:05:31 -05004013 goto dropit;
James Smart2e0fef82007-06-17 19:56:36 -05004014
dea31012005-04-17 16:05:31 -05004015 newnode = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05004016 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
4017 cmd = *payload;
James Smarted957682007-06-17 19:56:37 -05004018 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
4019 lpfc_post_buffer(phba, pring, 1, 1);
dea31012005-04-17 16:05:31 -05004020
James Smart858c9f62007-06-17 19:56:39 -05004021 did = icmd->un.rcvels.remoteID;
4022 if (icmd->ulpStatus) {
4023 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4024 "RCV Unsol ELS: status:x%x/x%x did:x%x",
4025 icmd->ulpStatus, icmd->un.ulpWord[4], did);
dea31012005-04-17 16:05:31 -05004026 goto dropit;
James Smart858c9f62007-06-17 19:56:39 -05004027 }
dea31012005-04-17 16:05:31 -05004028
4029 /* Check to see if link went down during discovery */
James Smarted957682007-06-17 19:56:37 -05004030 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05004031 goto dropit;
dea31012005-04-17 16:05:31 -05004032
James Smart92d7f7b2007-06-17 19:56:38 -05004033 /* Ignore traffic recevied during vport shutdown. */
4034 if (vport->load_flag & FC_UNLOADING)
4035 goto dropit;
4036
James Smart2e0fef82007-06-17 19:56:36 -05004037 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004038 if (!ndlp) {
dea31012005-04-17 16:05:31 -05004039 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004040 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
James Smarted957682007-06-17 19:56:37 -05004041 if (!ndlp)
dea31012005-04-17 16:05:31 -05004042 goto dropit;
dea31012005-04-17 16:05:31 -05004043
James Smart2e0fef82007-06-17 19:56:36 -05004044 lpfc_nlp_init(vport, ndlp, did);
James Smart98c9ea52007-10-27 13:37:33 -04004045 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05004046 newnode = 1;
James Smarte47c9092008-02-08 18:49:26 -05004047 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
dea31012005-04-17 16:05:31 -05004048 ndlp->nlp_type |= NLP_FABRIC;
James Smart58da1ff2008-04-07 10:15:56 -04004049 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
4050 ndlp = lpfc_enable_node(vport, ndlp,
4051 NLP_STE_UNUSED_NODE);
4052 if (!ndlp)
4053 goto dropit;
4054 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
4055 newnode = 1;
4056 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
4057 ndlp->nlp_type |= NLP_FABRIC;
4058 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
4059 /* This is similar to the new node path */
4060 ndlp = lpfc_nlp_get(ndlp);
4061 if (!ndlp)
4062 goto dropit;
4063 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
4064 newnode = 1;
James Smart87af33f2007-10-27 13:37:43 -04004065 }
dea31012005-04-17 16:05:31 -05004066
4067 phba->fc_stat.elsRcvFrame++;
James Smart329f9bc2007-04-25 09:53:01 -04004068 if (elsiocb->context1)
4069 lpfc_nlp_put(elsiocb->context1);
James Smarte47c9092008-02-08 18:49:26 -05004070
James Smart329f9bc2007-04-25 09:53:01 -04004071 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05004072 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -05004073
4074 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
4075 cmd &= ELS_CMD_MASK;
4076 }
4077 /* ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04004078 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4079 "0112 ELS command x%x received from NPORT x%x "
4080 "Data: x%x\n", cmd, did, vport->port_state);
dea31012005-04-17 16:05:31 -05004081 switch (cmd) {
4082 case ELS_CMD_PLOGI:
James Smart858c9f62007-06-17 19:56:39 -05004083 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4084 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
4085 did, vport->port_state, ndlp->nlp_flag);
4086
dea31012005-04-17 16:05:31 -05004087 phba->fc_stat.elsRcvPLOGI++;
James Smart858c9f62007-06-17 19:56:39 -05004088 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
4089
4090 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart1b32f6a2008-02-08 18:49:39 -05004091 if (!(phba->pport->fc_flag & FC_PT2PT) ||
4092 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
4093 rjt_err = LSRJT_UNABLE_TPC;
4094 break;
4095 }
4096 /* We get here, and drop thru, if we are PT2PT with
4097 * another NPort and the other side has initiated
4098 * the PLOGI before responding to our FLOGI.
4099 */
dea31012005-04-17 16:05:31 -05004100 }
James Smart87af33f2007-10-27 13:37:43 -04004101
4102 shost = lpfc_shost_from_vport(vport);
4103 spin_lock_irq(shost->host_lock);
4104 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
4105 spin_unlock_irq(shost->host_lock);
4106
James Smart2e0fef82007-06-17 19:56:36 -05004107 lpfc_disc_state_machine(vport, ndlp, elsiocb,
4108 NLP_EVT_RCV_PLOGI);
James Smart858c9f62007-06-17 19:56:39 -05004109
dea31012005-04-17 16:05:31 -05004110 break;
4111 case ELS_CMD_FLOGI:
James Smart858c9f62007-06-17 19:56:39 -05004112 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4113 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
4114 did, vport->port_state, ndlp->nlp_flag);
4115
dea31012005-04-17 16:05:31 -05004116 phba->fc_stat.elsRcvFLOGI++;
James Smart51ef4c22007-08-02 11:10:31 -04004117 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04004118 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04004119 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05004120 break;
4121 case ELS_CMD_LOGO:
James Smart858c9f62007-06-17 19:56:39 -05004122 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4123 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
4124 did, vport->port_state, ndlp->nlp_flag);
4125
dea31012005-04-17 16:05:31 -05004126 phba->fc_stat.elsRcvLOGO++;
James Smart2e0fef82007-06-17 19:56:36 -05004127 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05004128 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05004129 break;
4130 }
James Smart2e0fef82007-06-17 19:56:36 -05004131 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
dea31012005-04-17 16:05:31 -05004132 break;
4133 case ELS_CMD_PRLO:
James Smart858c9f62007-06-17 19:56:39 -05004134 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4135 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
4136 did, vport->port_state, ndlp->nlp_flag);
4137
dea31012005-04-17 16:05:31 -05004138 phba->fc_stat.elsRcvPRLO++;
James Smart2e0fef82007-06-17 19:56:36 -05004139 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05004140 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05004141 break;
4142 }
James Smart2e0fef82007-06-17 19:56:36 -05004143 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
dea31012005-04-17 16:05:31 -05004144 break;
4145 case ELS_CMD_RSCN:
4146 phba->fc_stat.elsRcvRSCN++;
James Smart51ef4c22007-08-02 11:10:31 -04004147 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04004148 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04004149 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05004150 break;
4151 case ELS_CMD_ADISC:
James Smart858c9f62007-06-17 19:56:39 -05004152 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4153 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
4154 did, vport->port_state, ndlp->nlp_flag);
4155
dea31012005-04-17 16:05:31 -05004156 phba->fc_stat.elsRcvADISC++;
James Smart2e0fef82007-06-17 19:56:36 -05004157 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05004158 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05004159 break;
4160 }
James Smart2e0fef82007-06-17 19:56:36 -05004161 lpfc_disc_state_machine(vport, ndlp, elsiocb,
4162 NLP_EVT_RCV_ADISC);
dea31012005-04-17 16:05:31 -05004163 break;
4164 case ELS_CMD_PDISC:
James Smart858c9f62007-06-17 19:56:39 -05004165 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4166 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
4167 did, vport->port_state, ndlp->nlp_flag);
4168
dea31012005-04-17 16:05:31 -05004169 phba->fc_stat.elsRcvPDISC++;
James Smart2e0fef82007-06-17 19:56:36 -05004170 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05004171 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05004172 break;
4173 }
James Smart2e0fef82007-06-17 19:56:36 -05004174 lpfc_disc_state_machine(vport, ndlp, elsiocb,
4175 NLP_EVT_RCV_PDISC);
dea31012005-04-17 16:05:31 -05004176 break;
4177 case ELS_CMD_FARPR:
James Smart858c9f62007-06-17 19:56:39 -05004178 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4179 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
4180 did, vport->port_state, ndlp->nlp_flag);
4181
dea31012005-04-17 16:05:31 -05004182 phba->fc_stat.elsRcvFARPR++;
James Smart2e0fef82007-06-17 19:56:36 -05004183 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05004184 break;
4185 case ELS_CMD_FARP:
James Smart858c9f62007-06-17 19:56:39 -05004186 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4187 "RCV FARP: did:x%x/ste:x%x flg:x%x",
4188 did, vport->port_state, ndlp->nlp_flag);
4189
dea31012005-04-17 16:05:31 -05004190 phba->fc_stat.elsRcvFARP++;
James Smart2e0fef82007-06-17 19:56:36 -05004191 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05004192 break;
4193 case ELS_CMD_FAN:
James Smart858c9f62007-06-17 19:56:39 -05004194 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4195 "RCV FAN: did:x%x/ste:x%x flg:x%x",
4196 did, vport->port_state, ndlp->nlp_flag);
4197
dea31012005-04-17 16:05:31 -05004198 phba->fc_stat.elsRcvFAN++;
James Smart2e0fef82007-06-17 19:56:36 -05004199 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05004200 break;
dea31012005-04-17 16:05:31 -05004201 case ELS_CMD_PRLI:
James Smart858c9f62007-06-17 19:56:39 -05004202 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4203 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
4204 did, vport->port_state, ndlp->nlp_flag);
4205
dea31012005-04-17 16:05:31 -05004206 phba->fc_stat.elsRcvPRLI++;
James Smart2e0fef82007-06-17 19:56:36 -05004207 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05004208 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05004209 break;
4210 }
James Smart2e0fef82007-06-17 19:56:36 -05004211 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
dea31012005-04-17 16:05:31 -05004212 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004213 case ELS_CMD_LIRR:
James Smart858c9f62007-06-17 19:56:39 -05004214 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4215 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
4216 did, vport->port_state, ndlp->nlp_flag);
4217
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004218 phba->fc_stat.elsRcvLIRR++;
James Smart2e0fef82007-06-17 19:56:36 -05004219 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04004220 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04004221 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004222 break;
4223 case ELS_CMD_RPS:
James Smart858c9f62007-06-17 19:56:39 -05004224 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4225 "RCV RPS: did:x%x/ste:x%x flg:x%x",
4226 did, vport->port_state, ndlp->nlp_flag);
4227
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004228 phba->fc_stat.elsRcvRPS++;
James Smart2e0fef82007-06-17 19:56:36 -05004229 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04004230 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04004231 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004232 break;
4233 case ELS_CMD_RPL:
James Smart858c9f62007-06-17 19:56:39 -05004234 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4235 "RCV RPL: did:x%x/ste:x%x flg:x%x",
4236 did, vport->port_state, ndlp->nlp_flag);
4237
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004238 phba->fc_stat.elsRcvRPL++;
James Smart2e0fef82007-06-17 19:56:36 -05004239 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04004240 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04004241 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004242 break;
dea31012005-04-17 16:05:31 -05004243 case ELS_CMD_RNID:
James Smart858c9f62007-06-17 19:56:39 -05004244 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4245 "RCV RNID: did:x%x/ste:x%x flg:x%x",
4246 did, vport->port_state, ndlp->nlp_flag);
4247
dea31012005-04-17 16:05:31 -05004248 phba->fc_stat.elsRcvRNID++;
James Smart2e0fef82007-06-17 19:56:36 -05004249 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04004250 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04004251 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05004252 break;
4253 default:
James Smart858c9f62007-06-17 19:56:39 -05004254 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4255 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
4256 cmd, did, vport->port_state);
4257
dea31012005-04-17 16:05:31 -05004258 /* Unsupported ELS command, reject */
James Smart858c9f62007-06-17 19:56:39 -05004259 rjt_err = LSRJT_INVALID_CMD;
dea31012005-04-17 16:05:31 -05004260
4261 /* Unknown ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04004262 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4263 "0115 Unknown ELS command x%x "
4264 "received from NPORT x%x\n", cmd, did);
James Smart87af33f2007-10-27 13:37:43 -04004265 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04004266 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05004267 break;
4268 }
4269
4270 /* check if need to LS_RJT received ELS cmd */
4271 if (rjt_err) {
James Smart92d7f7b2007-06-17 19:56:38 -05004272 memset(&stat, 0, sizeof(stat));
James Smart858c9f62007-06-17 19:56:39 -05004273 stat.un.b.lsRjtRsnCode = rjt_err;
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04004274 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart858c9f62007-06-17 19:56:39 -05004275 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
4276 NULL);
dea31012005-04-17 16:05:31 -05004277 }
4278
James Smarted957682007-06-17 19:56:37 -05004279 return;
4280
4281dropit:
James Smart98c9ea52007-10-27 13:37:33 -04004282 if (vport && !(vport->load_flag & FC_UNLOADING))
4283 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
James Smarte8b62012007-08-02 11:10:09 -04004284 "(%d):0111 Dropping received ELS cmd "
James Smarted957682007-06-17 19:56:37 -05004285 "Data: x%x x%x x%x\n",
James Smart98c9ea52007-10-27 13:37:33 -04004286 vport->vpi, icmd->ulpStatus,
James Smarte8b62012007-08-02 11:10:09 -04004287 icmd->un.ulpWord[4], icmd->ulpTimeout);
James Smarted957682007-06-17 19:56:37 -05004288 phba->fc_stat.elsRcvDrop++;
4289}
4290
James Smart92d7f7b2007-06-17 19:56:38 -05004291static struct lpfc_vport *
4292lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
4293{
4294 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -04004295 unsigned long flags;
James Smart92d7f7b2007-06-17 19:56:38 -05004296
James Smart549e55c2007-08-02 11:09:51 -04004297 spin_lock_irqsave(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05004298 list_for_each_entry(vport, &phba->port_list, listentry) {
James Smart549e55c2007-08-02 11:09:51 -04004299 if (vport->vpi == vpi) {
4300 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05004301 return vport;
James Smart549e55c2007-08-02 11:09:51 -04004302 }
James Smart92d7f7b2007-06-17 19:56:38 -05004303 }
James Smart549e55c2007-08-02 11:09:51 -04004304 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05004305 return NULL;
4306}
James Smarted957682007-06-17 19:56:37 -05004307
4308void
4309lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
4310 struct lpfc_iocbq *elsiocb)
4311{
4312 struct lpfc_vport *vport = phba->pport;
James Smarted957682007-06-17 19:56:37 -05004313 IOCB_t *icmd = &elsiocb->iocb;
James Smarted957682007-06-17 19:56:37 -05004314 dma_addr_t paddr;
James Smart92d7f7b2007-06-17 19:56:38 -05004315 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
4316 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
James Smarted957682007-06-17 19:56:37 -05004317
James Smart92d7f7b2007-06-17 19:56:38 -05004318 elsiocb->context2 = NULL;
4319 elsiocb->context3 = NULL;
4320
4321 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
4322 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
4323 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
4324 (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) {
James Smarted957682007-06-17 19:56:37 -05004325 phba->fc_stat.NoRcvBuf++;
4326 /* Not enough posted buffers; Try posting more buffers */
James Smart92d7f7b2007-06-17 19:56:38 -05004327 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
James Smarted957682007-06-17 19:56:37 -05004328 lpfc_post_buffer(phba, pring, 0, 1);
4329 return;
4330 }
4331
James Smart92d7f7b2007-06-17 19:56:38 -05004332 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
4333 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
4334 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
4335 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
4336 vport = phba->pport;
4337 else {
4338 uint16_t vpi = icmd->unsli3.rcvsli3.vpi;
4339 vport = lpfc_find_vport_by_vpid(phba, vpi);
4340 }
4341 }
James Smart7f5f3d02008-02-08 18:50:14 -05004342 /* If there are no BDEs associated
4343 * with this IOCB, there is nothing to do.
4344 */
James Smarted957682007-06-17 19:56:37 -05004345 if (icmd->ulpBdeCount == 0)
4346 return;
4347
James Smart7f5f3d02008-02-08 18:50:14 -05004348 /* type of ELS cmd is first 32bit word
4349 * in packet
4350 */
James Smarted957682007-06-17 19:56:37 -05004351 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05004352 elsiocb->context2 = bdeBuf1;
James Smarted957682007-06-17 19:56:37 -05004353 } else {
4354 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
4355 icmd->un.cont64[0].addrLow);
James Smart92d7f7b2007-06-17 19:56:38 -05004356 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
4357 paddr);
James Smarted957682007-06-17 19:56:37 -05004358 }
4359
James Smart92d7f7b2007-06-17 19:56:38 -05004360 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
4361 /*
4362 * The different unsolicited event handlers would tell us
4363 * if they are done with "mp" by setting context2 to NULL.
4364 */
James Smart329f9bc2007-04-25 09:53:01 -04004365 lpfc_nlp_put(elsiocb->context1);
4366 elsiocb->context1 = NULL;
dea31012005-04-17 16:05:31 -05004367 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05004368 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
4369 elsiocb->context2 = NULL;
dea31012005-04-17 16:05:31 -05004370 }
James Smarted957682007-06-17 19:56:37 -05004371
4372 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
James Smart92d7f7b2007-06-17 19:56:38 -05004373 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
James Smarted957682007-06-17 19:56:37 -05004374 icmd->ulpBdeCount == 2) {
James Smart92d7f7b2007-06-17 19:56:38 -05004375 elsiocb->context2 = bdeBuf2;
4376 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
James Smarted957682007-06-17 19:56:37 -05004377 /* free mp if we are done with it */
4378 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05004379 lpfc_in_buf_free(phba, elsiocb->context2);
4380 elsiocb->context2 = NULL;
James Smarted957682007-06-17 19:56:37 -05004381 }
dea31012005-04-17 16:05:31 -05004382 }
dea31012005-04-17 16:05:31 -05004383}
James Smart92d7f7b2007-06-17 19:56:38 -05004384
4385void
4386lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
4387{
4388 struct lpfc_nodelist *ndlp, *ndlp_fdmi;
4389
4390 ndlp = lpfc_findnode_did(vport, NameServer_DID);
4391 if (!ndlp) {
4392 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
4393 if (!ndlp) {
4394 if (phba->fc_topology == TOPOLOGY_LOOP) {
4395 lpfc_disc_start(vport);
4396 return;
4397 }
4398 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04004399 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4400 "0251 NameServer login: no memory\n");
James Smart92d7f7b2007-06-17 19:56:38 -05004401 return;
4402 }
4403 lpfc_nlp_init(vport, ndlp, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004404 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
4405 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
4406 if (!ndlp) {
4407 if (phba->fc_topology == TOPOLOGY_LOOP) {
4408 lpfc_disc_start(vport);
4409 return;
4410 }
4411 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4412 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4413 "0348 NameServer login: node freed\n");
4414 return;
4415 }
James Smart92d7f7b2007-06-17 19:56:38 -05004416 }
James Smart58da1ff2008-04-07 10:15:56 -04004417 ndlp->nlp_type |= NLP_FABRIC;
James Smart92d7f7b2007-06-17 19:56:38 -05004418
4419 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
4420
4421 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
4422 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04004423 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4424 "0252 Cannot issue NameServer login\n");
James Smart92d7f7b2007-06-17 19:56:38 -05004425 return;
4426 }
4427
James Smart3de2a652007-08-02 11:09:59 -04004428 if (vport->cfg_fdmi_on) {
James Smart92d7f7b2007-06-17 19:56:38 -05004429 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
4430 GFP_KERNEL);
4431 if (ndlp_fdmi) {
4432 lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
4433 ndlp_fdmi->nlp_type |= NLP_FABRIC;
James Smart58da1ff2008-04-07 10:15:56 -04004434 lpfc_nlp_set_state(vport, ndlp_fdmi,
4435 NLP_STE_PLOGI_ISSUE);
James Smart92d7f7b2007-06-17 19:56:38 -05004436 lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID,
4437 0);
4438 }
4439 }
4440 return;
4441}
4442
4443static void
4444lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4445{
4446 struct lpfc_vport *vport = pmb->vport;
4447 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4448 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
4449 MAILBOX_t *mb = &pmb->mb;
4450
James Smart09372822008-01-11 01:52:54 -05004451 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004452 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05004453 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004454
4455 if (mb->mbxStatus) {
James Smarte8b62012007-08-02 11:10:09 -04004456 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
4457 "0915 Register VPI failed: 0x%x\n",
4458 mb->mbxStatus);
James Smart92d7f7b2007-06-17 19:56:38 -05004459
4460 switch (mb->mbxStatus) {
4461 case 0x11: /* unsupported feature */
4462 case 0x9603: /* max_vpi exceeded */
James Smart7f5f3d02008-02-08 18:50:14 -05004463 case 0x9602: /* Link event since CLEAR_LA */
James Smart92d7f7b2007-06-17 19:56:38 -05004464 /* giving up on vport registration */
4465 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4466 spin_lock_irq(shost->host_lock);
4467 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
4468 spin_unlock_irq(shost->host_lock);
4469 lpfc_can_disctmo(vport);
4470 break;
4471 default:
4472 /* Try to recover from this error */
4473 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -05004474 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004475 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05004476 spin_unlock_irq(shost->host_lock);
James Smart7f5f3d02008-02-08 18:50:14 -05004477 if (vport->port_type == LPFC_PHYSICAL_PORT)
4478 lpfc_initial_flogi(vport);
4479 else
4480 lpfc_initial_fdisc(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05004481 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);
James Smart7f5f3d02008-02-08 18:50:14 -05004798 /* Post any pending iocb to the SLI layer */
James Smart92d7f7b2007-06-17 19:56:38 -05004799 if (atomic_read(&phba->fabric_iocb_count) == 0) {
4800 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
4801 list);
4802 if (iocb)
James Smart7f5f3d02008-02-08 18:50:14 -05004803 /* Increment fabric iocb count to hold the position */
James Smart92d7f7b2007-06-17 19:56:38 -05004804 atomic_inc(&phba->fabric_iocb_count);
4805 }
4806 spin_unlock_irqrestore(&phba->hbalock, iflags);
4807 if (iocb) {
4808 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
4809 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
4810 iocb->iocb_flag |= LPFC_IO_FABRIC;
4811
James Smart858c9f62007-06-17 19:56:39 -05004812 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
4813 "Fabric sched1: ste:x%x",
4814 iocb->vport->port_state, 0, 0);
4815
James Smart92d7f7b2007-06-17 19:56:38 -05004816 ret = lpfc_sli_issue_iocb(phba, pring, iocb, 0);
4817
4818 if (ret == IOCB_ERROR) {
4819 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
4820 iocb->fabric_iocb_cmpl = NULL;
4821 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
4822 cmd = &iocb->iocb;
4823 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
4824 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
4825 iocb->iocb_cmpl(phba, iocb, iocb);
4826
4827 atomic_dec(&phba->fabric_iocb_count);
4828 goto repeat;
4829 }
4830 }
4831
4832 return;
4833}
4834
4835void
4836lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
4837{
4838 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
4839
4840 lpfc_resume_fabric_iocbs(phba);
4841 return;
4842}
4843
4844static void
4845lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
4846{
4847 int blocked;
4848
4849 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
James Smart7f5f3d02008-02-08 18:50:14 -05004850 /* Start a timer to unblock fabric iocbs after 100ms */
James Smart92d7f7b2007-06-17 19:56:38 -05004851 if (!blocked)
4852 mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 );
4853
4854 return;
4855}
4856
4857static void
4858lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4859 struct lpfc_iocbq *rspiocb)
4860{
4861 struct ls_rjt stat;
4862
4863 if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
4864 BUG();
4865
4866 switch (rspiocb->iocb.ulpStatus) {
4867 case IOSTAT_NPORT_RJT:
4868 case IOSTAT_FABRIC_RJT:
4869 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
4870 lpfc_block_fabric_iocbs(phba);
4871 }
4872 break;
4873
4874 case IOSTAT_NPORT_BSY:
4875 case IOSTAT_FABRIC_BSY:
4876 lpfc_block_fabric_iocbs(phba);
4877 break;
4878
4879 case IOSTAT_LS_RJT:
4880 stat.un.lsRjtError =
4881 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
4882 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
4883 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
4884 lpfc_block_fabric_iocbs(phba);
4885 break;
4886 }
4887
4888 if (atomic_read(&phba->fabric_iocb_count) == 0)
4889 BUG();
4890
4891 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
4892 cmdiocb->fabric_iocb_cmpl = NULL;
4893 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
4894 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
4895
4896 atomic_dec(&phba->fabric_iocb_count);
4897 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
James Smart7f5f3d02008-02-08 18:50:14 -05004898 /* Post any pending iocbs to HBA */
4899 lpfc_resume_fabric_iocbs(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05004900 }
4901}
4902
Adrian Bunka6ababd2007-11-05 18:07:33 +01004903static int
James Smart92d7f7b2007-06-17 19:56:38 -05004904lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
4905{
4906 unsigned long iflags;
4907 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
4908 int ready;
4909 int ret;
4910
4911 if (atomic_read(&phba->fabric_iocb_count) > 1)
4912 BUG();
4913
4914 spin_lock_irqsave(&phba->hbalock, iflags);
4915 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
4916 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
4917
James Smart7f5f3d02008-02-08 18:50:14 -05004918 if (ready)
4919 /* Increment fabric iocb count to hold the position */
4920 atomic_inc(&phba->fabric_iocb_count);
James Smart92d7f7b2007-06-17 19:56:38 -05004921 spin_unlock_irqrestore(&phba->hbalock, iflags);
4922 if (ready) {
4923 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
4924 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
4925 iocb->iocb_flag |= LPFC_IO_FABRIC;
4926
James Smart858c9f62007-06-17 19:56:39 -05004927 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
4928 "Fabric sched2: ste:x%x",
4929 iocb->vport->port_state, 0, 0);
4930
James Smart92d7f7b2007-06-17 19:56:38 -05004931 ret = lpfc_sli_issue_iocb(phba, pring, iocb, 0);
4932
4933 if (ret == IOCB_ERROR) {
4934 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
4935 iocb->fabric_iocb_cmpl = NULL;
4936 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
4937 atomic_dec(&phba->fabric_iocb_count);
4938 }
4939 } else {
4940 spin_lock_irqsave(&phba->hbalock, iflags);
4941 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
4942 spin_unlock_irqrestore(&phba->hbalock, iflags);
4943 ret = IOCB_SUCCESS;
4944 }
4945 return ret;
4946}
4947
4948
Adrian Bunka6ababd2007-11-05 18:07:33 +01004949static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
James Smart92d7f7b2007-06-17 19:56:38 -05004950{
4951 LIST_HEAD(completions);
4952 struct lpfc_hba *phba = vport->phba;
4953 struct lpfc_iocbq *tmp_iocb, *piocb;
4954 IOCB_t *cmd;
4955
4956 spin_lock_irq(&phba->hbalock);
4957 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
4958 list) {
4959
4960 if (piocb->vport != vport)
4961 continue;
4962
4963 list_move_tail(&piocb->list, &completions);
4964 }
4965 spin_unlock_irq(&phba->hbalock);
4966
4967 while (!list_empty(&completions)) {
4968 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
4969 list_del_init(&piocb->list);
4970
4971 cmd = &piocb->iocb;
4972 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
4973 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
4974 (piocb->iocb_cmpl) (phba, piocb, piocb);
4975 }
4976}
4977
4978void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
4979{
4980 LIST_HEAD(completions);
4981 struct lpfc_hba *phba = ndlp->vport->phba;
4982 struct lpfc_iocbq *tmp_iocb, *piocb;
4983 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
4984 IOCB_t *cmd;
4985
4986 spin_lock_irq(&phba->hbalock);
4987 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
4988 list) {
4989 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
4990
4991 list_move_tail(&piocb->list, &completions);
4992 }
4993 }
4994 spin_unlock_irq(&phba->hbalock);
4995
4996 while (!list_empty(&completions)) {
4997 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
4998 list_del_init(&piocb->list);
4999
5000 cmd = &piocb->iocb;
5001 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
5002 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
5003 (piocb->iocb_cmpl) (phba, piocb, piocb);
5004 }
5005}
5006
5007void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
5008{
5009 LIST_HEAD(completions);
5010 struct lpfc_iocbq *piocb;
5011 IOCB_t *cmd;
5012
5013 spin_lock_irq(&phba->hbalock);
5014 list_splice_init(&phba->fabric_iocb_list, &completions);
5015 spin_unlock_irq(&phba->hbalock);
5016
5017 while (!list_empty(&completions)) {
5018 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
5019 list_del_init(&piocb->list);
5020
5021 cmd = &piocb->iocb;
5022 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
5023 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
5024 (piocb->iocb_cmpl) (phba, piocb, piocb);
5025 }
5026}