blob: cbb68a9422554524f33ba7bc6bdfe29c61678f24 [file] [log] [blame]
dea31012005-04-17 16:05:31 -05001/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04003 * Fibre Channel Host Bus Adapters. *
James Smarte47c9092008-02-08 18:49:26 -05004 * Copyright (C) 2004-2008 Emulex. All rights reserved. *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04005 * EMULEX and SLI are trademarks of Emulex. *
dea31012005-04-17 16:05:31 -05006 * www.emulex.com *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04007 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea31012005-04-17 16:05:31 -05008 * *
9 * This program is free software; you can redistribute it and/or *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040010 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
dea31012005-04-17 16:05:31 -050020 *******************************************************************/
James Smart09372822008-01-11 01:52:54 -050021/* See Fibre Channel protocol T11 FC-LS for details */
dea31012005-04-17 16:05:31 -050022#include <linux/blkdev.h>
23#include <linux/pci.h>
24#include <linux/interrupt.h>
25
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040026#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050027#include <scsi/scsi_device.h>
28#include <scsi/scsi_host.h>
29#include <scsi/scsi_transport_fc.h>
30
31#include "lpfc_hw.h"
32#include "lpfc_sli.h"
33#include "lpfc_disc.h"
34#include "lpfc_scsi.h"
35#include "lpfc.h"
36#include "lpfc_logmsg.h"
37#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050038#include "lpfc_vport.h"
James Smart858c9f62007-06-17 19:56:39 -050039#include "lpfc_debugfs.h"
dea31012005-04-17 16:05:31 -050040
41static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *,
42 struct lpfc_iocbq *);
James Smart92d7f7b2007-06-17 19:56:38 -050043static void lpfc_cmpl_fabric_iocb(struct lpfc_hba *, struct lpfc_iocbq *,
44 struct lpfc_iocbq *);
Adrian Bunka6ababd2007-11-05 18:07:33 +010045static void lpfc_fabric_abort_vport(struct lpfc_vport *vport);
46static int lpfc_issue_els_fdisc(struct lpfc_vport *vport,
47 struct lpfc_nodelist *ndlp, uint8_t retry);
48static int lpfc_issue_fabric_iocb(struct lpfc_hba *phba,
49 struct lpfc_iocbq *iocb);
50static void lpfc_register_new_vport(struct lpfc_hba *phba,
51 struct lpfc_vport *vport,
52 struct lpfc_nodelist *ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -050053
dea31012005-04-17 16:05:31 -050054static int lpfc_max_els_tries = 3;
55
James Smart858c9f62007-06-17 19:56:39 -050056int
James Smart2e0fef82007-06-17 19:56:36 -050057lpfc_els_chk_latt(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -050058{
James Smart2e0fef82007-06-17 19:56:36 -050059 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
60 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -050061 uint32_t ha_copy;
dea31012005-04-17 16:05:31 -050062
James Smart2e0fef82007-06-17 19:56:36 -050063 if (vport->port_state >= LPFC_VPORT_READY ||
64 phba->link_state == LPFC_LINK_DOWN)
dea31012005-04-17 16:05:31 -050065 return 0;
66
67 /* Read the HBA Host Attention Register */
dea31012005-04-17 16:05:31 -050068 ha_copy = readl(phba->HAregaddr);
dea31012005-04-17 16:05:31 -050069
70 if (!(ha_copy & HA_LATT))
71 return 0;
72
73 /* Pending Link Event during Discovery */
James Smarte8b62012007-08-02 11:10:09 -040074 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
75 "0237 Pending Link Event during "
76 "Discovery: State x%x\n",
77 phba->pport->port_state);
dea31012005-04-17 16:05:31 -050078
79 /* CLEAR_LA should re-enable link attention events and
80 * we should then imediately take a LATT event. The
81 * LATT processing should call lpfc_linkdown() which
82 * will cleanup any left over in-progress discovery
83 * events.
84 */
James Smart2e0fef82007-06-17 19:56:36 -050085 spin_lock_irq(shost->host_lock);
86 vport->fc_flag |= FC_ABORT_DISCOVERY;
87 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -050088
James Smart92d7f7b2007-06-17 19:56:38 -050089 if (phba->link_state != LPFC_CLEAR_LA)
James Smarted957682007-06-17 19:56:37 -050090 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -050091
Jamie Wellnitzc9f87352006-02-28 19:25:23 -050092 return 1;
dea31012005-04-17 16:05:31 -050093}
94
95static struct lpfc_iocbq *
James Smart2e0fef82007-06-17 19:56:36 -050096lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp,
97 uint16_t cmdSize, uint8_t retry,
98 struct lpfc_nodelist *ndlp, uint32_t did,
99 uint32_t elscmd)
dea31012005-04-17 16:05:31 -0500100{
James Smart2e0fef82007-06-17 19:56:36 -0500101 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400102 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -0500103 struct lpfc_dmabuf *pcmd, *prsp, *pbuflist;
104 struct ulp_bde64 *bpl;
105 IOCB_t *icmd;
106
dea31012005-04-17 16:05:31 -0500107
James Smart2e0fef82007-06-17 19:56:36 -0500108 if (!lpfc_is_link_up(phba))
109 return NULL;
dea31012005-04-17 16:05:31 -0500110
dea31012005-04-17 16:05:31 -0500111 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400112 elsiocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -0500113
114 if (elsiocb == NULL)
115 return NULL;
James Smarte47c9092008-02-08 18:49:26 -0500116
dea31012005-04-17 16:05:31 -0500117 icmd = &elsiocb->iocb;
118
119 /* fill in BDEs for command */
120 /* Allocate buffer for command payload */
James Smart98c9ea52007-10-27 13:37:33 -0400121 pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
122 if (pcmd)
123 pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500124 if (!pcmd || !pcmd->virt)
125 goto els_iocb_free_pcmb_exit;
dea31012005-04-17 16:05:31 -0500126
127 INIT_LIST_HEAD(&pcmd->list);
128
129 /* Allocate buffer for response payload */
130 if (expectRsp) {
James Smart92d7f7b2007-06-17 19:56:38 -0500131 prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -0500132 if (prsp)
133 prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
134 &prsp->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500135 if (!prsp || !prsp->virt)
136 goto els_iocb_free_prsp_exit;
dea31012005-04-17 16:05:31 -0500137 INIT_LIST_HEAD(&prsp->list);
James Smarte47c9092008-02-08 18:49:26 -0500138 } else
dea31012005-04-17 16:05:31 -0500139 prsp = NULL;
dea31012005-04-17 16:05:31 -0500140
141 /* Allocate buffer for Buffer ptr list */
James Smart92d7f7b2007-06-17 19:56:38 -0500142 pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -0500143 if (pbuflist)
James Smarted957682007-06-17 19:56:37 -0500144 pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
145 &pbuflist->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500146 if (!pbuflist || !pbuflist->virt)
147 goto els_iocb_free_pbuf_exit;
dea31012005-04-17 16:05:31 -0500148
149 INIT_LIST_HEAD(&pbuflist->list);
150
151 icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
152 icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
153 icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BDL;
James Smart2e0fef82007-06-17 19:56:36 -0500154 icmd->un.elsreq64.remoteID = did; /* DID */
dea31012005-04-17 16:05:31 -0500155 if (expectRsp) {
James Smart92d7f7b2007-06-17 19:56:38 -0500156 icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
dea31012005-04-17 16:05:31 -0500157 icmd->ulpCommand = CMD_ELS_REQUEST64_CR;
James Smart2680eea2007-04-25 09:52:55 -0400158 icmd->ulpTimeout = phba->fc_ratov * 2;
dea31012005-04-17 16:05:31 -0500159 } else {
James Smart92d7f7b2007-06-17 19:56:38 -0500160 icmd->un.elsreq64.bdl.bdeSize = sizeof(struct ulp_bde64);
dea31012005-04-17 16:05:31 -0500161 icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
162 }
dea31012005-04-17 16:05:31 -0500163 icmd->ulpBdeCount = 1;
164 icmd->ulpLe = 1;
165 icmd->ulpClass = CLASS3;
166
James Smart92d7f7b2007-06-17 19:56:38 -0500167 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
168 icmd->un.elsreq64.myID = vport->fc_myDID;
169
170 /* For ELS_REQUEST64_CR, use the VPI by default */
171 icmd->ulpContext = vport->vpi;
172 icmd->ulpCt_h = 0;
173 icmd->ulpCt_l = 1;
174 }
175
dea31012005-04-17 16:05:31 -0500176 bpl = (struct ulp_bde64 *) pbuflist->virt;
177 bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys));
178 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys));
179 bpl->tus.f.bdeSize = cmdSize;
180 bpl->tus.f.bdeFlags = 0;
181 bpl->tus.w = le32_to_cpu(bpl->tus.w);
182
183 if (expectRsp) {
184 bpl++;
185 bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys));
186 bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys));
187 bpl->tus.f.bdeSize = FCELSSIZE;
188 bpl->tus.f.bdeFlags = BUFF_USE_RCV;
189 bpl->tus.w = le32_to_cpu(bpl->tus.w);
190 }
191
James Smartfa4066b2008-01-11 01:53:27 -0500192 /* prevent preparing iocb with NULL ndlp reference */
James Smart51ef4c22007-08-02 11:10:31 -0400193 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -0500194 if (!elsiocb->context1)
195 goto els_iocb_free_pbuf_exit;
James Smart329f9bc2007-04-25 09:53:01 -0400196 elsiocb->context2 = pcmd;
197 elsiocb->context3 = pbuflist;
dea31012005-04-17 16:05:31 -0500198 elsiocb->retry = retry;
James Smart2e0fef82007-06-17 19:56:36 -0500199 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -0500200 elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
201
202 if (prsp) {
203 list_add(&prsp->list, &pcmd->list);
204 }
dea31012005-04-17 16:05:31 -0500205 if (expectRsp) {
206 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400207 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
208 "0116 Xmit ELS command x%x to remote "
209 "NPORT x%x I/O tag: x%x, port state: x%x\n",
210 elscmd, did, elsiocb->iotag,
211 vport->port_state);
dea31012005-04-17 16:05:31 -0500212 } else {
213 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400214 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
215 "0117 Xmit ELS response x%x to remote "
216 "NPORT x%x I/O tag: x%x, size: x%x\n",
217 elscmd, ndlp->nlp_DID, elsiocb->iotag,
218 cmdSize);
dea31012005-04-17 16:05:31 -0500219 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500220 return elsiocb;
dea31012005-04-17 16:05:31 -0500221
James Smartfa4066b2008-01-11 01:53:27 -0500222els_iocb_free_pbuf_exit:
223 lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
224 kfree(pbuflist);
225
226els_iocb_free_prsp_exit:
227 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
228 kfree(prsp);
229
230els_iocb_free_pcmb_exit:
231 kfree(pcmd);
232 lpfc_sli_release_iocbq(phba, elsiocb);
233 return NULL;
234}
dea31012005-04-17 16:05:31 -0500235
236static int
James Smart92d7f7b2007-06-17 19:56:38 -0500237lpfc_issue_fabric_reglogin(struct lpfc_vport *vport)
238{
239 struct lpfc_hba *phba = vport->phba;
240 LPFC_MBOXQ_t *mbox;
241 struct lpfc_dmabuf *mp;
242 struct lpfc_nodelist *ndlp;
243 struct serv_parm *sp;
244 int rc;
James Smart98c9ea52007-10-27 13:37:33 -0400245 int err = 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500246
247 sp = &phba->fc_fabparam;
248 ndlp = lpfc_findnode_did(vport, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -0500249 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -0400250 err = 1;
James Smart92d7f7b2007-06-17 19:56:38 -0500251 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400252 }
James Smart92d7f7b2007-06-17 19:56:38 -0500253
254 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart98c9ea52007-10-27 13:37:33 -0400255 if (!mbox) {
256 err = 2;
James Smart92d7f7b2007-06-17 19:56:38 -0500257 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400258 }
James Smart92d7f7b2007-06-17 19:56:38 -0500259
260 vport->port_state = LPFC_FABRIC_CFG_LINK;
261 lpfc_config_link(phba, mbox);
262 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
263 mbox->vport = vport;
264
James Smart0b727fe2007-10-27 13:37:25 -0400265 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart98c9ea52007-10-27 13:37:33 -0400266 if (rc == MBX_NOT_FINISHED) {
267 err = 3;
James Smart92d7f7b2007-06-17 19:56:38 -0500268 goto fail_free_mbox;
James Smart98c9ea52007-10-27 13:37:33 -0400269 }
James Smart92d7f7b2007-06-17 19:56:38 -0500270
271 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart98c9ea52007-10-27 13:37:33 -0400272 if (!mbox) {
273 err = 4;
James Smart92d7f7b2007-06-17 19:56:38 -0500274 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400275 }
James Smart92d7f7b2007-06-17 19:56:38 -0500276 rc = lpfc_reg_login(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox,
277 0);
James Smart98c9ea52007-10-27 13:37:33 -0400278 if (rc) {
279 err = 5;
James Smart92d7f7b2007-06-17 19:56:38 -0500280 goto fail_free_mbox;
James Smart98c9ea52007-10-27 13:37:33 -0400281 }
James Smart92d7f7b2007-06-17 19:56:38 -0500282
283 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
284 mbox->vport = vport;
James Smarte47c9092008-02-08 18:49:26 -0500285 /* increment the reference count on ndlp to hold reference
286 * for the callback routine.
287 */
James Smart92d7f7b2007-06-17 19:56:38 -0500288 mbox->context2 = lpfc_nlp_get(ndlp);
289
James Smart0b727fe2007-10-27 13:37:25 -0400290 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart98c9ea52007-10-27 13:37:33 -0400291 if (rc == MBX_NOT_FINISHED) {
292 err = 6;
James Smart92d7f7b2007-06-17 19:56:38 -0500293 goto fail_issue_reg_login;
James Smart98c9ea52007-10-27 13:37:33 -0400294 }
James Smart92d7f7b2007-06-17 19:56:38 -0500295
296 return 0;
297
298fail_issue_reg_login:
James Smarte47c9092008-02-08 18:49:26 -0500299 /* decrement the reference count on ndlp just incremented
300 * for the failed mbox command.
301 */
James Smart92d7f7b2007-06-17 19:56:38 -0500302 lpfc_nlp_put(ndlp);
303 mp = (struct lpfc_dmabuf *) mbox->context1;
304 lpfc_mbuf_free(phba, mp->virt, mp->phys);
305 kfree(mp);
306fail_free_mbox:
307 mempool_free(mbox, phba->mbox_mem_pool);
308
309fail:
310 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -0400311 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smart98c9ea52007-10-27 13:37:33 -0400312 "0249 Cannot issue Register Fabric login: Err %d\n", err);
James Smart92d7f7b2007-06-17 19:56:38 -0500313 return -ENXIO;
314}
315
316static int
James Smart2e0fef82007-06-17 19:56:36 -0500317lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
318 struct serv_parm *sp, IOCB_t *irsp)
dea31012005-04-17 16:05:31 -0500319{
James Smart2e0fef82007-06-17 19:56:36 -0500320 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
321 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -0500322 struct lpfc_nodelist *np;
323 struct lpfc_nodelist *next_np;
dea31012005-04-17 16:05:31 -0500324
James Smart2e0fef82007-06-17 19:56:36 -0500325 spin_lock_irq(shost->host_lock);
326 vport->fc_flag |= FC_FABRIC;
327 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500328
329 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
330 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
331 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
332
333 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
334
335 if (phba->fc_topology == TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500336 spin_lock_irq(shost->host_lock);
337 vport->fc_flag |= FC_PUBLIC_LOOP;
338 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500339 } else {
340 /*
341 * If we are a N-port connected to a Fabric, fixup sparam's so
342 * logins to devices on remote loops work.
343 */
James Smart2e0fef82007-06-17 19:56:36 -0500344 vport->fc_sparam.cmn.altBbCredit = 1;
dea31012005-04-17 16:05:31 -0500345 }
346
James Smart2e0fef82007-06-17 19:56:36 -0500347 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
dea31012005-04-17 16:05:31 -0500348 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
James Smart92d7f7b2007-06-17 19:56:38 -0500349 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500350 ndlp->nlp_class_sup = 0;
351 if (sp->cls1.classValid)
352 ndlp->nlp_class_sup |= FC_COS_CLASS1;
353 if (sp->cls2.classValid)
354 ndlp->nlp_class_sup |= FC_COS_CLASS2;
355 if (sp->cls3.classValid)
356 ndlp->nlp_class_sup |= FC_COS_CLASS3;
357 if (sp->cls4.classValid)
358 ndlp->nlp_class_sup |= FC_COS_CLASS4;
359 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
360 sp->cmn.bbRcvSizeLsb;
361 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
362
James Smart92d7f7b2007-06-17 19:56:38 -0500363 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
364 if (sp->cmn.response_multiple_NPort) {
James Smarte8b62012007-08-02 11:10:09 -0400365 lpfc_printf_vlog(vport, KERN_WARNING,
366 LOG_ELS | LOG_VPORT,
367 "1816 FLOGI NPIV supported, "
368 "response data 0x%x\n",
369 sp->cmn.response_multiple_NPort);
James Smart92d7f7b2007-06-17 19:56:38 -0500370 phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
James Smart92d7f7b2007-06-17 19:56:38 -0500371 } else {
372 /* Because we asked f/w for NPIV it still expects us
James Smarte8b62012007-08-02 11:10:09 -0400373 to call reg_vnpid atleast for the physcial host */
374 lpfc_printf_vlog(vport, KERN_WARNING,
375 LOG_ELS | LOG_VPORT,
376 "1817 Fabric does not support NPIV "
377 "- configuring single port mode.\n");
James Smart92d7f7b2007-06-17 19:56:38 -0500378 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
379 }
380 }
381
382 if ((vport->fc_prevDID != vport->fc_myDID) &&
383 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
384
385 /* If our NportID changed, we need to ensure all
386 * remaining NPORTs get unreg_login'ed.
387 */
388 list_for_each_entry_safe(np, next_np,
389 &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -0500390 if (!NLP_CHK_NODE_ACT(ndlp))
391 continue;
James Smart92d7f7b2007-06-17 19:56:38 -0500392 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
393 !(np->nlp_flag & NLP_NPR_ADISC))
394 continue;
395 spin_lock_irq(shost->host_lock);
396 np->nlp_flag &= ~NLP_NPR_ADISC;
397 spin_unlock_irq(shost->host_lock);
398 lpfc_unreg_rpi(vport, np);
399 }
400 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
401 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -0500402 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500403 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -0500404 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500405 }
406 }
407
James Smart92d7f7b2007-06-17 19:56:38 -0500408 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -0500409
James Smart92d7f7b2007-06-17 19:56:38 -0500410 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
411 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) {
412 lpfc_register_new_vport(phba, vport, ndlp);
413 return 0;
414 }
415 lpfc_issue_fabric_reglogin(vport);
dea31012005-04-17 16:05:31 -0500416 return 0;
dea31012005-04-17 16:05:31 -0500417}
418
419/*
420 * We FLOGIed into an NPort, initiate pt2pt protocol
421 */
422static int
James Smart2e0fef82007-06-17 19:56:36 -0500423lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
424 struct serv_parm *sp)
dea31012005-04-17 16:05:31 -0500425{
James Smart2e0fef82007-06-17 19:56:36 -0500426 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
427 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500428 LPFC_MBOXQ_t *mbox;
429 int rc;
430
James Smart2e0fef82007-06-17 19:56:36 -0500431 spin_lock_irq(shost->host_lock);
432 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
433 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500434
435 phba->fc_edtov = FF_DEF_EDTOV;
436 phba->fc_ratov = FF_DEF_RATOV;
James Smart2e0fef82007-06-17 19:56:36 -0500437 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -0500438 sizeof(vport->fc_portname));
dea31012005-04-17 16:05:31 -0500439 if (rc >= 0) {
440 /* This side will initiate the PLOGI */
James Smart2e0fef82007-06-17 19:56:36 -0500441 spin_lock_irq(shost->host_lock);
442 vport->fc_flag |= FC_PT2PT_PLOGI;
443 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500444
445 /*
446 * N_Port ID cannot be 0, set our to LocalID the other
447 * side will be RemoteID.
448 */
449
450 /* not equal */
451 if (rc)
James Smart2e0fef82007-06-17 19:56:36 -0500452 vport->fc_myDID = PT2PT_LocalID;
dea31012005-04-17 16:05:31 -0500453
454 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
455 if (!mbox)
456 goto fail;
457
458 lpfc_config_link(phba, mbox);
459
460 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -0500461 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -0400462 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -0500463 if (rc == MBX_NOT_FINISHED) {
464 mempool_free(mbox, phba->mbox_mem_pool);
465 goto fail;
466 }
James Smarte47c9092008-02-08 18:49:26 -0500467 /* Decrement ndlp reference count indicating that ndlp can be
468 * safely released when other references to it are done.
469 */
James Smart329f9bc2007-04-25 09:53:01 -0400470 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500471
James Smart2e0fef82007-06-17 19:56:36 -0500472 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
dea31012005-04-17 16:05:31 -0500473 if (!ndlp) {
474 /*
475 * Cannot find existing Fabric ndlp, so allocate a
476 * new one
477 */
478 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
479 if (!ndlp)
480 goto fail;
James Smart2e0fef82007-06-17 19:56:36 -0500481 lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID);
James Smarte47c9092008-02-08 18:49:26 -0500482 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
483 ndlp = lpfc_enable_node(vport, ndlp,
484 NLP_STE_UNUSED_NODE);
485 if(!ndlp)
486 goto fail;
dea31012005-04-17 16:05:31 -0500487 }
488
489 memcpy(&ndlp->nlp_portname, &sp->portName,
James Smart2e0fef82007-06-17 19:56:36 -0500490 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500491 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
James Smart2e0fef82007-06-17 19:56:36 -0500492 sizeof(struct lpfc_name));
James Smarte47c9092008-02-08 18:49:26 -0500493 /* Set state will put ndlp onto node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -0500494 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
495 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500496 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500497 spin_unlock_irq(shost->host_lock);
James Smarte47c9092008-02-08 18:49:26 -0500498 } else
499 /* This side will wait for the PLOGI, decrement ndlp reference
500 * count indicating that ndlp can be released when other
501 * references to it are done.
502 */
James Smart329f9bc2007-04-25 09:53:01 -0400503 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500504
James Smart09372822008-01-11 01:52:54 -0500505 /* If we are pt2pt with another NPort, force NPIV off! */
506 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
507
James Smart2e0fef82007-06-17 19:56:36 -0500508 spin_lock_irq(shost->host_lock);
509 vport->fc_flag |= FC_PT2PT;
510 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500511
512 /* Start discovery - this should just do CLEAR_LA */
James Smart2e0fef82007-06-17 19:56:36 -0500513 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -0500514 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500515fail:
dea31012005-04-17 16:05:31 -0500516 return -ENXIO;
517}
518
519static void
James Smart329f9bc2007-04-25 09:53:01 -0400520lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
521 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500522{
James Smart2e0fef82007-06-17 19:56:36 -0500523 struct lpfc_vport *vport = cmdiocb->vport;
524 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500525 IOCB_t *irsp = &rspiocb->iocb;
526 struct lpfc_nodelist *ndlp = cmdiocb->context1;
527 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
528 struct serv_parm *sp;
529 int rc;
530
531 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500532 if (lpfc_els_chk_latt(vport)) {
James Smartfa4066b2008-01-11 01:53:27 -0500533 /* One additional decrement on node reference count to
534 * trigger the release of the node
535 */
James Smart329f9bc2007-04-25 09:53:01 -0400536 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500537 goto out;
538 }
539
James Smart858c9f62007-06-17 19:56:39 -0500540 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
541 "FLOGI cmpl: status:x%x/x%x state:x%x",
542 irsp->ulpStatus, irsp->un.ulpWord[4],
543 vport->port_state);
544
dea31012005-04-17 16:05:31 -0500545 if (irsp->ulpStatus) {
546 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -0500547 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -0500548 goto out;
James Smart2e0fef82007-06-17 19:56:36 -0500549
dea31012005-04-17 16:05:31 -0500550 /* FLOGI failed, so there is no fabric */
James Smart2e0fef82007-06-17 19:56:36 -0500551 spin_lock_irq(shost->host_lock);
552 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
553 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500554
James Smart329f9bc2007-04-25 09:53:01 -0400555 /* If private loop, then allow max outstanding els to be
dea31012005-04-17 16:05:31 -0500556 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
557 * alpa map would take too long otherwise.
558 */
559 if (phba->alpa_map[0] == 0) {
James Smart3de2a652007-08-02 11:09:59 -0400560 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
dea31012005-04-17 16:05:31 -0500561 }
562
563 /* FLOGI failure */
James Smarte8b62012007-08-02 11:10:09 -0400564 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
565 "0100 FLOGI failure Data: x%x x%x "
566 "x%x\n",
567 irsp->ulpStatus, irsp->un.ulpWord[4],
568 irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -0500569 goto flogifail;
570 }
571
572 /*
573 * The FLogI succeeded. Sync the data for the CPU before
574 * accessing it.
575 */
576 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
577
578 sp = prsp->virt + sizeof(uint32_t);
579
580 /* FLOGI completes successfully */
James Smarte8b62012007-08-02 11:10:09 -0400581 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
582 "0101 FLOGI completes sucessfully "
583 "Data: x%x x%x x%x x%x\n",
584 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
585 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution);
dea31012005-04-17 16:05:31 -0500586
James Smart2e0fef82007-06-17 19:56:36 -0500587 if (vport->port_state == LPFC_FLOGI) {
dea31012005-04-17 16:05:31 -0500588 /*
589 * If Common Service Parameters indicate Nport
590 * we are point to point, if Fport we are Fabric.
591 */
592 if (sp->cmn.fPort)
James Smart2e0fef82007-06-17 19:56:36 -0500593 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
dea31012005-04-17 16:05:31 -0500594 else
James Smart2e0fef82007-06-17 19:56:36 -0500595 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
dea31012005-04-17 16:05:31 -0500596
597 if (!rc)
598 goto out;
599 }
600
601flogifail:
James Smart329f9bc2007-04-25 09:53:01 -0400602 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500603
James Smart858c9f62007-06-17 19:56:39 -0500604 if (!lpfc_error_lost_link(irsp)) {
dea31012005-04-17 16:05:31 -0500605 /* FLOGI failed, so just use loop map to make discovery list */
James Smart2e0fef82007-06-17 19:56:36 -0500606 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -0500607
608 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500609 lpfc_disc_start(vport);
James Smart87af33f2007-10-27 13:37:43 -0400610 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
611 ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) &&
612 (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) &&
613 (phba->link_state != LPFC_CLEAR_LA)) {
614 /* If FLOGI failed enable link interrupt. */
615 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -0500616 }
dea31012005-04-17 16:05:31 -0500617out:
618 lpfc_els_free_iocb(phba, cmdiocb);
619}
620
621static int
James Smart2e0fef82007-06-17 19:56:36 -0500622lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -0500623 uint8_t retry)
624{
James Smart2e0fef82007-06-17 19:56:36 -0500625 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500626 struct serv_parm *sp;
627 IOCB_t *icmd;
628 struct lpfc_iocbq *elsiocb;
629 struct lpfc_sli_ring *pring;
630 uint8_t *pcmd;
631 uint16_t cmdsize;
632 uint32_t tmo;
633 int rc;
634
635 pring = &phba->sli.ring[LPFC_ELS_RING];
636
James Smart92d7f7b2007-06-17 19:56:38 -0500637 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart2e0fef82007-06-17 19:56:36 -0500638 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
639 ndlp->nlp_DID, ELS_CMD_FLOGI);
James Smart92d7f7b2007-06-17 19:56:38 -0500640
James Smart488d1462006-03-07 15:02:37 -0500641 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500642 return 1;
dea31012005-04-17 16:05:31 -0500643
644 icmd = &elsiocb->iocb;
645 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
646
647 /* For FLOGI request, remainder of payload is service parameters */
648 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -0500649 pcmd += sizeof(uint32_t);
650 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -0500651 sp = (struct serv_parm *) pcmd;
652
653 /* Setup CSPs accordingly for Fabric */
654 sp->cmn.e_d_tov = 0;
655 sp->cmn.w2.r_a_tov = 0;
656 sp->cls1.classValid = 0;
657 sp->cls2.seqDelivery = 1;
658 sp->cls3.seqDelivery = 1;
659 if (sp->cmn.fcphLow < FC_PH3)
660 sp->cmn.fcphLow = FC_PH3;
661 if (sp->cmn.fcphHigh < FC_PH3)
662 sp->cmn.fcphHigh = FC_PH3;
663
James Smart92d7f7b2007-06-17 19:56:38 -0500664 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
665 sp->cmn.request_multiple_Nport = 1;
666
667 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
668 icmd->ulpCt_h = 1;
669 icmd->ulpCt_l = 0;
670 }
671
James Smart858c9f62007-06-17 19:56:39 -0500672 if (phba->fc_topology != TOPOLOGY_LOOP) {
673 icmd->un.elsreq64.myID = 0;
674 icmd->un.elsreq64.fl = 1;
675 }
676
dea31012005-04-17 16:05:31 -0500677 tmo = phba->fc_ratov;
678 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
James Smart2e0fef82007-06-17 19:56:36 -0500679 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -0500680 phba->fc_ratov = tmo;
681
682 phba->fc_stat.elsXmitFLOGI++;
683 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
James Smart858c9f62007-06-17 19:56:39 -0500684
685 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
686 "Issue FLOGI: opt:x%x",
687 phba->sli3_options, 0, 0);
688
James Smart92d7f7b2007-06-17 19:56:38 -0500689 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
dea31012005-04-17 16:05:31 -0500690 if (rc == IOCB_ERROR) {
691 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500692 return 1;
dea31012005-04-17 16:05:31 -0500693 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500694 return 0;
dea31012005-04-17 16:05:31 -0500695}
696
697int
James Smart2e0fef82007-06-17 19:56:36 -0500698lpfc_els_abort_flogi(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500699{
700 struct lpfc_sli_ring *pring;
701 struct lpfc_iocbq *iocb, *next_iocb;
702 struct lpfc_nodelist *ndlp;
703 IOCB_t *icmd;
704
705 /* Abort outstanding I/O on NPort <nlp_DID> */
706 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -0400707 "0201 Abort outstanding I/O on NPort x%x\n",
708 Fabric_DID);
dea31012005-04-17 16:05:31 -0500709
710 pring = &phba->sli.ring[LPFC_ELS_RING];
711
712 /*
713 * Check the txcmplq for an iocb that matches the nport the driver is
714 * searching for.
715 */
James Smart2e0fef82007-06-17 19:56:36 -0500716 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500717 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
718 icmd = &iocb->iocb;
James Smart2e0fef82007-06-17 19:56:36 -0500719 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR &&
720 icmd->un.elsreq64.bdl.ulpIoTag32) {
dea31012005-04-17 16:05:31 -0500721 ndlp = (struct lpfc_nodelist *)(iocb->context1);
James Smart92d7f7b2007-06-17 19:56:38 -0500722 if (ndlp && (ndlp->nlp_DID == Fabric_DID)) {
James Smart07951072007-04-25 09:51:38 -0400723 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
James Smart92d7f7b2007-06-17 19:56:38 -0500724 }
dea31012005-04-17 16:05:31 -0500725 }
726 }
James Smart2e0fef82007-06-17 19:56:36 -0500727 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500728
729 return 0;
730}
731
732int
James Smart2e0fef82007-06-17 19:56:36 -0500733lpfc_initial_flogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -0500734{
James Smart2e0fef82007-06-17 19:56:36 -0500735 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500736 struct lpfc_nodelist *ndlp;
737
James Smart98c9ea52007-10-27 13:37:33 -0400738 vport->port_state = LPFC_FLOGI;
739 lpfc_set_disctmo(vport);
740
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500741 /* First look for the Fabric ndlp */
James Smart2e0fef82007-06-17 19:56:36 -0500742 ndlp = lpfc_findnode_did(vport, Fabric_DID);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500743 if (!ndlp) {
dea31012005-04-17 16:05:31 -0500744 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500745 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
746 if (!ndlp)
747 return 0;
James Smart2e0fef82007-06-17 19:56:36 -0500748 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -0500749 /* Put ndlp onto node list */
750 lpfc_enqueue_node(vport, ndlp);
751 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
752 /* re-setup ndlp without removing from node list */
753 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
754 if (!ndlp)
755 return 0;
dea31012005-04-17 16:05:31 -0500756 }
James Smart87af33f2007-10-27 13:37:43 -0400757
James Smarte47c9092008-02-08 18:49:26 -0500758 if (lpfc_issue_els_flogi(vport, ndlp, 0))
James Smartfa4066b2008-01-11 01:53:27 -0500759 /* This decrement of reference count to node shall kick off
760 * the release of the node.
761 */
James Smart329f9bc2007-04-25 09:53:01 -0400762 lpfc_nlp_put(ndlp);
James Smarte47c9092008-02-08 18:49:26 -0500763
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500764 return 1;
dea31012005-04-17 16:05:31 -0500765}
766
James Smart92d7f7b2007-06-17 19:56:38 -0500767int
768lpfc_initial_fdisc(struct lpfc_vport *vport)
769{
770 struct lpfc_hba *phba = vport->phba;
771 struct lpfc_nodelist *ndlp;
772
773 /* First look for the Fabric ndlp */
774 ndlp = lpfc_findnode_did(vport, Fabric_DID);
775 if (!ndlp) {
776 /* Cannot find existing Fabric ndlp, so allocate a new one */
777 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
778 if (!ndlp)
779 return 0;
780 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -0500781 /* Put ndlp onto node list */
782 lpfc_enqueue_node(vport, ndlp);
783 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
784 /* re-setup ndlp without removing from node list */
785 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
786 if (!ndlp)
787 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500788 }
James Smarte47c9092008-02-08 18:49:26 -0500789
James Smart92d7f7b2007-06-17 19:56:38 -0500790 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -0500791 /* decrement node reference count to trigger the release of
792 * the node.
793 */
James Smart92d7f7b2007-06-17 19:56:38 -0500794 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -0500795 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500796 }
797 return 1;
798}
James Smart87af33f2007-10-27 13:37:43 -0400799
800void
James Smart2e0fef82007-06-17 19:56:36 -0500801lpfc_more_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -0500802{
803 int sentplogi;
804
James Smart2e0fef82007-06-17 19:56:36 -0500805 if (vport->num_disc_nodes)
806 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -0500807
808 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
James Smarte8b62012007-08-02 11:10:09 -0400809 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
810 "0232 Continue discovery with %d PLOGIs to go "
811 "Data: x%x x%x x%x\n",
812 vport->num_disc_nodes, vport->fc_plogi_cnt,
813 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -0500814 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -0500815 if (vport->fc_flag & FC_NLP_MORE)
816 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
817 sentplogi = lpfc_els_disc_plogi(vport);
818
dea31012005-04-17 16:05:31 -0500819 return;
820}
821
James Smart488d1462006-03-07 15:02:37 -0500822static struct lpfc_nodelist *
James Smart92d7f7b2007-06-17 19:56:38 -0500823lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
James Smart488d1462006-03-07 15:02:37 -0500824 struct lpfc_nodelist *ndlp)
825{
James Smart2e0fef82007-06-17 19:56:36 -0500826 struct lpfc_vport *vport = ndlp->vport;
James Smart488d1462006-03-07 15:02:37 -0500827 struct lpfc_nodelist *new_ndlp;
James Smart0ff10d42008-01-11 01:52:36 -0500828 struct lpfc_rport_data *rdata;
829 struct fc_rport *rport;
James Smart488d1462006-03-07 15:02:37 -0500830 struct serv_parm *sp;
James Smart92d7f7b2007-06-17 19:56:38 -0500831 uint8_t name[sizeof(struct lpfc_name)];
James Smart488d1462006-03-07 15:02:37 -0500832 uint32_t rc;
833
James Smart2fb9bd82006-12-02 13:33:57 -0500834 /* Fabric nodes can have the same WWPN so we don't bother searching
835 * by WWPN. Just return the ndlp that was given to us.
836 */
837 if (ndlp->nlp_type & NLP_FABRIC)
838 return ndlp;
839
James Smart92d7f7b2007-06-17 19:56:38 -0500840 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
James Smart685f0bf2007-04-25 09:53:08 -0400841 memset(name, 0, sizeof(struct lpfc_name));
James Smart488d1462006-03-07 15:02:37 -0500842
James Smart685f0bf2007-04-25 09:53:08 -0400843 /* Now we find out if the NPort we are logging into, matches the WWPN
James Smart488d1462006-03-07 15:02:37 -0500844 * we have for that ndlp. If not, we have some work to do.
845 */
James Smart2e0fef82007-06-17 19:56:36 -0500846 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
James Smart488d1462006-03-07 15:02:37 -0500847
James Smarte47c9092008-02-08 18:49:26 -0500848 if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
James Smart488d1462006-03-07 15:02:37 -0500849 return ndlp;
James Smart488d1462006-03-07 15:02:37 -0500850
851 if (!new_ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -0500852 rc = memcmp(&ndlp->nlp_portname, name,
853 sizeof(struct lpfc_name));
James Smart92795652006-07-06 15:50:02 -0400854 if (!rc)
855 return ndlp;
James Smart488d1462006-03-07 15:02:37 -0500856 new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
857 if (!new_ndlp)
858 return ndlp;
James Smart2e0fef82007-06-17 19:56:36 -0500859 lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID);
James Smarte47c9092008-02-08 18:49:26 -0500860 } else if (!NLP_CHK_NODE_ACT(new_ndlp)) {
861 new_ndlp = lpfc_enable_node(vport, new_ndlp,
862 NLP_STE_UNUSED_NODE);
863 if (!new_ndlp)
864 return ndlp;
James Smart488d1462006-03-07 15:02:37 -0500865 }
866
James Smart2e0fef82007-06-17 19:56:36 -0500867 lpfc_unreg_rpi(vport, new_ndlp);
James Smart488d1462006-03-07 15:02:37 -0500868 new_ndlp->nlp_DID = ndlp->nlp_DID;
James Smart92795652006-07-06 15:50:02 -0400869 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
James Smart0ff10d42008-01-11 01:52:36 -0500870
871 if (ndlp->nlp_flag & NLP_NPR_2B_DISC)
872 new_ndlp->nlp_flag |= NLP_NPR_2B_DISC;
873 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
874
James Smarte47c9092008-02-08 18:49:26 -0500875 /* Set state will put new_ndlp on to node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -0500876 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
James Smart488d1462006-03-07 15:02:37 -0500877
James Smart2e0fef82007-06-17 19:56:36 -0500878 /* Move this back to NPR state */
James Smart87af33f2007-10-27 13:37:43 -0400879 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
880 /* The new_ndlp is replacing ndlp totally, so we need
881 * to put ndlp on UNUSED list and try to free it.
882 */
James Smart0ff10d42008-01-11 01:52:36 -0500883
884 /* Fix up the rport accordingly */
885 rport = ndlp->rport;
886 if (rport) {
887 rdata = rport->dd_data;
888 if (rdata->pnode == ndlp) {
889 lpfc_nlp_put(ndlp);
890 ndlp->rport = NULL;
891 rdata->pnode = lpfc_nlp_get(new_ndlp);
892 new_ndlp->rport = rport;
893 }
894 new_ndlp->nlp_type = ndlp->nlp_type;
895 }
896
James Smart2e0fef82007-06-17 19:56:36 -0500897 lpfc_drop_node(vport, ndlp);
James Smart87af33f2007-10-27 13:37:43 -0400898 }
James Smart92795652006-07-06 15:50:02 -0400899 else {
James Smart2e0fef82007-06-17 19:56:36 -0500900 lpfc_unreg_rpi(vport, ndlp);
James Smart92795652006-07-06 15:50:02 -0400901 ndlp->nlp_DID = 0; /* Two ndlps cannot have the same did */
James Smart2e0fef82007-06-17 19:56:36 -0500902 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smart92795652006-07-06 15:50:02 -0400903 }
James Smart488d1462006-03-07 15:02:37 -0500904 return new_ndlp;
905}
906
James Smart87af33f2007-10-27 13:37:43 -0400907void
908lpfc_end_rscn(struct lpfc_vport *vport)
909{
910 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
911
912 if (vport->fc_flag & FC_RSCN_MODE) {
913 /*
914 * Check to see if more RSCNs came in while we were
915 * processing this one.
916 */
917 if (vport->fc_rscn_id_cnt ||
918 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
919 lpfc_els_handle_rscn(vport);
920 else {
921 spin_lock_irq(shost->host_lock);
922 vport->fc_flag &= ~FC_RSCN_MODE;
923 spin_unlock_irq(shost->host_lock);
924 }
925 }
926}
927
dea31012005-04-17 16:05:31 -0500928static void
James Smart2e0fef82007-06-17 19:56:36 -0500929lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
930 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500931{
James Smart2e0fef82007-06-17 19:56:36 -0500932 struct lpfc_vport *vport = cmdiocb->vport;
933 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500934 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -0500935 struct lpfc_nodelist *ndlp;
James Smart92795652006-07-06 15:50:02 -0400936 struct lpfc_dmabuf *prsp;
dea31012005-04-17 16:05:31 -0500937 int disc, rc, did, type;
938
dea31012005-04-17 16:05:31 -0500939 /* we pass cmdiocb to state machine which needs rspiocb as well */
940 cmdiocb->context_un.rsp_iocb = rspiocb;
941
942 irsp = &rspiocb->iocb;
James Smart858c9f62007-06-17 19:56:39 -0500943 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
944 "PLOGI cmpl: status:x%x/x%x did:x%x",
945 irsp->ulpStatus, irsp->un.ulpWord[4],
946 irsp->un.elsreq64.remoteID);
947
James Smart2e0fef82007-06-17 19:56:36 -0500948 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
James Smarte47c9092008-02-08 18:49:26 -0500949 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smarte8b62012007-08-02 11:10:09 -0400950 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
951 "0136 PLOGI completes to NPort x%x "
952 "with no ndlp. Data: x%x x%x x%x\n",
953 irsp->un.elsreq64.remoteID,
954 irsp->ulpStatus, irsp->un.ulpWord[4],
955 irsp->ulpIoTag);
James Smart488d1462006-03-07 15:02:37 -0500956 goto out;
James Smarted957682007-06-17 19:56:37 -0500957 }
dea31012005-04-17 16:05:31 -0500958
959 /* Since ndlp can be freed in the disc state machine, note if this node
960 * is being used during discovery.
961 */
James Smart2e0fef82007-06-17 19:56:36 -0500962 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500963 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
James Smart488d1462006-03-07 15:02:37 -0500964 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500965 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500966 rc = 0;
967
968 /* PLOGI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -0400969 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
970 "0102 PLOGI completes to NPort x%x "
971 "Data: x%x x%x x%x x%x x%x\n",
972 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
973 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -0500974 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500975 if (lpfc_els_chk_latt(vport)) {
976 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500977 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500978 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500979 goto out;
980 }
981
982 /* ndlp could be freed in DSM, save these values now */
983 type = ndlp->nlp_type;
984 did = ndlp->nlp_DID;
985
986 if (irsp->ulpStatus) {
987 /* Check for retry */
988 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
989 /* ELS command is being retried */
990 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -0500991 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500992 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500993 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500994 }
995 goto out;
996 }
dea31012005-04-17 16:05:31 -0500997 /* PLOGI failed */
998 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -0500999 if (lpfc_error_lost_link(irsp))
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001000 rc = NLP_STE_FREED_NODE;
James Smarte47c9092008-02-08 18:49:26 -05001001 else
James Smart2e0fef82007-06-17 19:56:36 -05001002 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001003 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001004 } else {
1005 /* Good status, call state machine */
James Smart92795652006-07-06 15:50:02 -04001006 prsp = list_entry(((struct lpfc_dmabuf *)
James Smart92d7f7b2007-06-17 19:56:38 -05001007 cmdiocb->context2)->list.next,
1008 struct lpfc_dmabuf, list);
1009 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05001010 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001011 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001012 }
1013
James Smart2e0fef82007-06-17 19:56:36 -05001014 if (disc && vport->num_disc_nodes) {
dea31012005-04-17 16:05:31 -05001015 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001016 lpfc_more_plogi(vport);
dea31012005-04-17 16:05:31 -05001017
James Smart2e0fef82007-06-17 19:56:36 -05001018 if (vport->num_disc_nodes == 0) {
1019 spin_lock_irq(shost->host_lock);
1020 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1021 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001022
James Smart2e0fef82007-06-17 19:56:36 -05001023 lpfc_can_disctmo(vport);
James Smart87af33f2007-10-27 13:37:43 -04001024 lpfc_end_rscn(vport);
dea31012005-04-17 16:05:31 -05001025 }
1026 }
1027
1028out:
1029 lpfc_els_free_iocb(phba, cmdiocb);
1030 return;
1031}
1032
1033int
James Smart2e0fef82007-06-17 19:56:36 -05001034lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
dea31012005-04-17 16:05:31 -05001035{
James Smart2e0fef82007-06-17 19:56:36 -05001036 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001037 struct serv_parm *sp;
1038 IOCB_t *icmd;
James Smart98c9ea52007-10-27 13:37:33 -04001039 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05001040 struct lpfc_iocbq *elsiocb;
1041 struct lpfc_sli_ring *pring;
1042 struct lpfc_sli *psli;
1043 uint8_t *pcmd;
1044 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05001045 int ret;
dea31012005-04-17 16:05:31 -05001046
1047 psli = &phba->sli;
1048 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1049
James Smart98c9ea52007-10-27 13:37:33 -04001050 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05001051 if (ndlp && !NLP_CHK_NODE_ACT(ndlp))
1052 ndlp = NULL;
James Smart98c9ea52007-10-27 13:37:33 -04001053
James Smarte47c9092008-02-08 18:49:26 -05001054 /* If ndlp is not NULL, we will bump the reference count on it */
James Smart92d7f7b2007-06-17 19:56:38 -05001055 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart98c9ea52007-10-27 13:37:33 -04001056 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
James Smart2e0fef82007-06-17 19:56:36 -05001057 ELS_CMD_PLOGI);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001058 if (!elsiocb)
1059 return 1;
dea31012005-04-17 16:05:31 -05001060
1061 icmd = &elsiocb->iocb;
1062 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1063
1064 /* For PLOGI request, remainder of payload is service parameters */
1065 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001066 pcmd += sizeof(uint32_t);
1067 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001068 sp = (struct serv_parm *) pcmd;
1069
1070 if (sp->cmn.fcphLow < FC_PH_4_3)
1071 sp->cmn.fcphLow = FC_PH_4_3;
1072
1073 if (sp->cmn.fcphHigh < FC_PH3)
1074 sp->cmn.fcphHigh = FC_PH3;
1075
James Smart858c9f62007-06-17 19:56:39 -05001076 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1077 "Issue PLOGI: did:x%x",
1078 did, 0, 0);
1079
dea31012005-04-17 16:05:31 -05001080 phba->fc_stat.elsXmitPLOGI++;
1081 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
James Smart92d7f7b2007-06-17 19:56:38 -05001082 ret = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
1083
1084 if (ret == IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05001085 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001086 return 1;
dea31012005-04-17 16:05:31 -05001087 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001088 return 0;
dea31012005-04-17 16:05:31 -05001089}
1090
1091static void
James Smart2e0fef82007-06-17 19:56:36 -05001092lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1093 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001094{
James Smart2e0fef82007-06-17 19:56:36 -05001095 struct lpfc_vport *vport = cmdiocb->vport;
1096 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001097 IOCB_t *irsp;
1098 struct lpfc_sli *psli;
1099 struct lpfc_nodelist *ndlp;
1100
1101 psli = &phba->sli;
1102 /* we pass cmdiocb to state machine which needs rspiocb as well */
1103 cmdiocb->context_un.rsp_iocb = rspiocb;
1104
1105 irsp = &(rspiocb->iocb);
1106 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
James Smart2e0fef82007-06-17 19:56:36 -05001107 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001108 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001109 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001110
James Smart858c9f62007-06-17 19:56:39 -05001111 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1112 "PRLI cmpl: status:x%x/x%x did:x%x",
1113 irsp->ulpStatus, irsp->un.ulpWord[4],
1114 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05001115 /* PRLI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001116 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1117 "0103 PRLI completes to NPort x%x "
1118 "Data: x%x x%x x%x x%x\n",
1119 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1120 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001121
James Smart2e0fef82007-06-17 19:56:36 -05001122 vport->fc_prli_sent--;
dea31012005-04-17 16:05:31 -05001123 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001124 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05001125 goto out;
1126
1127 if (irsp->ulpStatus) {
1128 /* Check for retry */
1129 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1130 /* ELS command is being retried */
1131 goto out;
1132 }
1133 /* PRLI failed */
1134 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001135 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05001136 goto out;
James Smarte47c9092008-02-08 18:49:26 -05001137 else
James Smart2e0fef82007-06-17 19:56:36 -05001138 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001139 NLP_EVT_CMPL_PRLI);
James Smarte47c9092008-02-08 18:49:26 -05001140 } else
dea31012005-04-17 16:05:31 -05001141 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05001142 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001143 NLP_EVT_CMPL_PRLI);
dea31012005-04-17 16:05:31 -05001144out:
1145 lpfc_els_free_iocb(phba, cmdiocb);
1146 return;
1147}
1148
1149int
James Smart2e0fef82007-06-17 19:56:36 -05001150lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001151 uint8_t retry)
1152{
James Smart2e0fef82007-06-17 19:56:36 -05001153 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1154 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001155 PRLI *npr;
1156 IOCB_t *icmd;
1157 struct lpfc_iocbq *elsiocb;
1158 struct lpfc_sli_ring *pring;
1159 struct lpfc_sli *psli;
1160 uint8_t *pcmd;
1161 uint16_t cmdsize;
1162
1163 psli = &phba->sli;
1164 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1165
James Smart92d7f7b2007-06-17 19:56:38 -05001166 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
James Smart2e0fef82007-06-17 19:56:36 -05001167 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1168 ndlp->nlp_DID, ELS_CMD_PRLI);
James Smart488d1462006-03-07 15:02:37 -05001169 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001170 return 1;
dea31012005-04-17 16:05:31 -05001171
1172 icmd = &elsiocb->iocb;
1173 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1174
1175 /* For PRLI request, remainder of payload is service parameters */
James Smart92d7f7b2007-06-17 19:56:38 -05001176 memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t)));
dea31012005-04-17 16:05:31 -05001177 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
James Smart92d7f7b2007-06-17 19:56:38 -05001178 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001179
1180 /* For PRLI, remainder of payload is PRLI parameter page */
1181 npr = (PRLI *) pcmd;
1182 /*
1183 * If our firmware version is 3.20 or later,
1184 * set the following bits for FC-TAPE support.
1185 */
1186 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
1187 npr->ConfmComplAllowed = 1;
1188 npr->Retry = 1;
1189 npr->TaskRetryIdReq = 1;
1190 }
1191 npr->estabImagePair = 1;
1192 npr->readXferRdyDis = 1;
1193
1194 /* For FCP support */
1195 npr->prliType = PRLI_FCP_TYPE;
1196 npr->initiatorFunc = 1;
1197
James Smart858c9f62007-06-17 19:56:39 -05001198 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1199 "Issue PRLI: did:x%x",
1200 ndlp->nlp_DID, 0, 0);
1201
dea31012005-04-17 16:05:31 -05001202 phba->fc_stat.elsXmitPRLI++;
1203 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
James Smart2e0fef82007-06-17 19:56:36 -05001204 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001205 ndlp->nlp_flag |= NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001206 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001207 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05001208 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001209 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001210 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001211 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001212 return 1;
dea31012005-04-17 16:05:31 -05001213 }
James Smart2e0fef82007-06-17 19:56:36 -05001214 vport->fc_prli_sent++;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001215 return 0;
dea31012005-04-17 16:05:31 -05001216}
1217
James Smart0ff10d42008-01-11 01:52:36 -05001218void
James Smart2e0fef82007-06-17 19:56:36 -05001219lpfc_more_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001220{
1221 int sentadisc;
1222
James Smart2e0fef82007-06-17 19:56:36 -05001223 if (vport->num_disc_nodes)
1224 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001225 /* Continue discovery with <num_disc_nodes> ADISCs to go */
James Smarte8b62012007-08-02 11:10:09 -04001226 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1227 "0210 Continue discovery with %d ADISCs to go "
1228 "Data: x%x x%x x%x\n",
1229 vport->num_disc_nodes, vport->fc_adisc_cnt,
1230 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001231 /* Check to see if there are more ADISCs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001232 if (vport->fc_flag & FC_NLP_MORE) {
1233 lpfc_set_disctmo(vport);
1234 /* go thru NPR nodes and issue any remaining ELS ADISCs */
1235 sentadisc = lpfc_els_disc_adisc(vport);
dea31012005-04-17 16:05:31 -05001236 }
1237 return;
1238}
1239
1240static void
James Smart2e0fef82007-06-17 19:56:36 -05001241lpfc_rscn_disc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001242{
James Smart858c9f62007-06-17 19:56:39 -05001243 lpfc_can_disctmo(vport);
1244
dea31012005-04-17 16:05:31 -05001245 /* RSCN discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001246 /* go thru NPR nodes and issue ELS PLOGIs */
1247 if (vport->fc_npr_cnt)
1248 if (lpfc_els_disc_plogi(vport))
dea31012005-04-17 16:05:31 -05001249 return;
James Smart2e0fef82007-06-17 19:56:36 -05001250
James Smart87af33f2007-10-27 13:37:43 -04001251 lpfc_end_rscn(vport);
dea31012005-04-17 16:05:31 -05001252}
1253
1254static void
James Smart2e0fef82007-06-17 19:56:36 -05001255lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1256 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001257{
James Smart2e0fef82007-06-17 19:56:36 -05001258 struct lpfc_vport *vport = cmdiocb->vport;
1259 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001260 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001261 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001262 int disc;
dea31012005-04-17 16:05:31 -05001263
1264 /* we pass cmdiocb to state machine which needs rspiocb as well */
1265 cmdiocb->context_un.rsp_iocb = rspiocb;
1266
1267 irsp = &(rspiocb->iocb);
1268 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
dea31012005-04-17 16:05:31 -05001269
James Smart858c9f62007-06-17 19:56:39 -05001270 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1271 "ADISC cmpl: status:x%x/x%x did:x%x",
1272 irsp->ulpStatus, irsp->un.ulpWord[4],
1273 ndlp->nlp_DID);
1274
dea31012005-04-17 16:05:31 -05001275 /* Since ndlp can be freed in the disc state machine, note if this node
1276 * is being used during discovery.
1277 */
James Smart2e0fef82007-06-17 19:56:36 -05001278 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001279 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001280 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001281 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001282 /* ADISC completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001283 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1284 "0104 ADISC completes to NPort x%x "
1285 "Data: x%x x%x x%x x%x x%x\n",
1286 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1287 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001288 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001289 if (lpfc_els_chk_latt(vport)) {
1290 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001291 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001292 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001293 goto out;
1294 }
1295
1296 if (irsp->ulpStatus) {
1297 /* Check for retry */
1298 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1299 /* ELS command is being retried */
1300 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05001301 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001302 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001303 spin_unlock_irq(shost->host_lock);
1304 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001305 }
1306 goto out;
1307 }
1308 /* ADISC failed */
1309 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001310 if (!lpfc_error_lost_link(irsp))
James Smart2e0fef82007-06-17 19:56:36 -05001311 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart858c9f62007-06-17 19:56:39 -05001312 NLP_EVT_CMPL_ADISC);
James Smarte47c9092008-02-08 18:49:26 -05001313 } else
dea31012005-04-17 16:05:31 -05001314 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05001315 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
dea31012005-04-17 16:05:31 -05001316 NLP_EVT_CMPL_ADISC);
dea31012005-04-17 16:05:31 -05001317
James Smart2e0fef82007-06-17 19:56:36 -05001318 if (disc && vport->num_disc_nodes) {
dea31012005-04-17 16:05:31 -05001319 /* Check to see if there are more ADISCs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001320 lpfc_more_adisc(vport);
dea31012005-04-17 16:05:31 -05001321
1322 /* Check to see if we are done with ADISC authentication */
James Smart2e0fef82007-06-17 19:56:36 -05001323 if (vport->num_disc_nodes == 0) {
James Smart92d7f7b2007-06-17 19:56:38 -05001324 /* If we get here, there is nothing left to ADISC */
1325 /*
1326 * For NPIV, cmpl_reg_vpi will set port_state to READY,
1327 * and continue discovery.
1328 */
1329 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
1330 !(vport->fc_flag & FC_RSCN_MODE)) {
1331 lpfc_issue_reg_vpi(phba, vport);
1332 goto out;
1333 }
1334 /*
1335 * For SLI2, we need to set port_state to READY
1336 * and continue discovery.
1337 */
1338 if (vport->port_state < LPFC_VPORT_READY) {
1339 /* If we get here, there is nothing to ADISC */
James Smarted957682007-06-17 19:56:37 -05001340 if (vport->port_type == LPFC_PHYSICAL_PORT)
James Smart2e0fef82007-06-17 19:56:36 -05001341 lpfc_issue_clear_la(phba, vport);
James Smart92d7f7b2007-06-17 19:56:38 -05001342
1343 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
1344 vport->num_disc_nodes = 0;
1345 /* go thru NPR list, issue ELS PLOGIs */
1346 if (vport->fc_npr_cnt)
1347 lpfc_els_disc_plogi(vport);
1348
1349 if (!vport->num_disc_nodes) {
1350 spin_lock_irq(shost->host_lock);
1351 vport->fc_flag &=
1352 ~FC_NDISC_ACTIVE;
1353 spin_unlock_irq(
1354 shost->host_lock);
1355 lpfc_can_disctmo(vport);
1356 }
1357 }
1358 vport->port_state = LPFC_VPORT_READY;
dea31012005-04-17 16:05:31 -05001359 } else {
James Smart2e0fef82007-06-17 19:56:36 -05001360 lpfc_rscn_disc(vport);
dea31012005-04-17 16:05:31 -05001361 }
1362 }
1363 }
dea31012005-04-17 16:05:31 -05001364out:
1365 lpfc_els_free_iocb(phba, cmdiocb);
1366 return;
1367}
1368
1369int
James Smart2e0fef82007-06-17 19:56:36 -05001370lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001371 uint8_t retry)
1372{
James Smart2e0fef82007-06-17 19:56:36 -05001373 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1374 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001375 ADISC *ap;
1376 IOCB_t *icmd;
1377 struct lpfc_iocbq *elsiocb;
James Smart2e0fef82007-06-17 19:56:36 -05001378 struct lpfc_sli *psli = &phba->sli;
1379 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05001380 uint8_t *pcmd;
1381 uint16_t cmdsize;
1382
James Smart92d7f7b2007-06-17 19:56:38 -05001383 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
James Smart2e0fef82007-06-17 19:56:36 -05001384 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1385 ndlp->nlp_DID, ELS_CMD_ADISC);
James Smart488d1462006-03-07 15:02:37 -05001386 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001387 return 1;
dea31012005-04-17 16:05:31 -05001388
1389 icmd = &elsiocb->iocb;
1390 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1391
1392 /* For ADISC request, remainder of payload is service parameters */
1393 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
James Smart92d7f7b2007-06-17 19:56:38 -05001394 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001395
1396 /* Fill in ADISC payload */
1397 ap = (ADISC *) pcmd;
1398 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05001399 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
1400 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05001401 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05001402
James Smart858c9f62007-06-17 19:56:39 -05001403 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1404 "Issue ADISC: did:x%x",
1405 ndlp->nlp_DID, 0, 0);
1406
dea31012005-04-17 16:05:31 -05001407 phba->fc_stat.elsXmitADISC++;
1408 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
James Smart2e0fef82007-06-17 19:56:36 -05001409 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001410 ndlp->nlp_flag |= NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001411 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001412 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05001413 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001414 ndlp->nlp_flag &= ~NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001415 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001416 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001417 return 1;
dea31012005-04-17 16:05:31 -05001418 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001419 return 0;
dea31012005-04-17 16:05:31 -05001420}
1421
1422static void
James Smart2e0fef82007-06-17 19:56:36 -05001423lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1424 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001425{
James Smart2e0fef82007-06-17 19:56:36 -05001426 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1427 struct lpfc_vport *vport = ndlp->vport;
1428 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001429 IOCB_t *irsp;
1430 struct lpfc_sli *psli;
dea31012005-04-17 16:05:31 -05001431
1432 psli = &phba->sli;
1433 /* we pass cmdiocb to state machine which needs rspiocb as well */
1434 cmdiocb->context_un.rsp_iocb = rspiocb;
1435
1436 irsp = &(rspiocb->iocb);
James Smart2e0fef82007-06-17 19:56:36 -05001437 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001438 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001439 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001440
James Smart858c9f62007-06-17 19:56:39 -05001441 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1442 "LOGO cmpl: status:x%x/x%x did:x%x",
1443 irsp->ulpStatus, irsp->un.ulpWord[4],
1444 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05001445 /* LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001446 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1447 "0105 LOGO completes to NPort x%x "
1448 "Data: x%x x%x x%x x%x\n",
1449 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1450 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001451 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001452 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05001453 goto out;
1454
James Smart92d7f7b2007-06-17 19:56:38 -05001455 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
1456 /* NLP_EVT_DEVICE_RM should unregister the RPI
1457 * which should abort all outstanding IOs.
1458 */
1459 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1460 NLP_EVT_DEVICE_RM);
1461 goto out;
1462 }
1463
dea31012005-04-17 16:05:31 -05001464 if (irsp->ulpStatus) {
1465 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -05001466 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -05001467 /* ELS command is being retried */
1468 goto out;
dea31012005-04-17 16:05:31 -05001469 /* LOGO failed */
1470 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart858c9f62007-06-17 19:56:39 -05001471 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05001472 goto out;
James Smart858c9f62007-06-17 19:56:39 -05001473 else
James Smart2e0fef82007-06-17 19:56:36 -05001474 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001475 NLP_EVT_CMPL_LOGO);
James Smarte47c9092008-02-08 18:49:26 -05001476 } else
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001477 /* Good status, call state machine.
1478 * This will unregister the rpi if needed.
1479 */
James Smart2e0fef82007-06-17 19:56:36 -05001480 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001481 NLP_EVT_CMPL_LOGO);
dea31012005-04-17 16:05:31 -05001482out:
1483 lpfc_els_free_iocb(phba, cmdiocb);
1484 return;
1485}
1486
1487int
James Smart2e0fef82007-06-17 19:56:36 -05001488lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001489 uint8_t retry)
1490{
James Smart2e0fef82007-06-17 19:56:36 -05001491 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1492 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001493 IOCB_t *icmd;
1494 struct lpfc_iocbq *elsiocb;
1495 struct lpfc_sli_ring *pring;
1496 struct lpfc_sli *psli;
1497 uint8_t *pcmd;
1498 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05001499 int rc;
dea31012005-04-17 16:05:31 -05001500
1501 psli = &phba->sli;
1502 pring = &psli->ring[LPFC_ELS_RING];
1503
James Smart98c9ea52007-10-27 13:37:33 -04001504 spin_lock_irq(shost->host_lock);
1505 if (ndlp->nlp_flag & NLP_LOGO_SND) {
1506 spin_unlock_irq(shost->host_lock);
1507 return 0;
1508 }
1509 spin_unlock_irq(shost->host_lock);
1510
James Smart92d7f7b2007-06-17 19:56:38 -05001511 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
James Smart2e0fef82007-06-17 19:56:36 -05001512 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1513 ndlp->nlp_DID, ELS_CMD_LOGO);
James Smart488d1462006-03-07 15:02:37 -05001514 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001515 return 1;
dea31012005-04-17 16:05:31 -05001516
1517 icmd = &elsiocb->iocb;
1518 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1519 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
James Smart92d7f7b2007-06-17 19:56:38 -05001520 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001521
1522 /* Fill in LOGO payload */
James Smart2e0fef82007-06-17 19:56:36 -05001523 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05001524 pcmd += sizeof(uint32_t);
1525 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05001526
James Smart858c9f62007-06-17 19:56:39 -05001527 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1528 "Issue LOGO: did:x%x",
1529 ndlp->nlp_DID, 0, 0);
1530
dea31012005-04-17 16:05:31 -05001531 phba->fc_stat.elsXmitLOGO++;
1532 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
James Smart2e0fef82007-06-17 19:56:36 -05001533 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001534 ndlp->nlp_flag |= NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001535 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05001536 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
1537
1538 if (rc == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05001539 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001540 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001541 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001542 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001543 return 1;
dea31012005-04-17 16:05:31 -05001544 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001545 return 0;
dea31012005-04-17 16:05:31 -05001546}
1547
1548static void
James Smart2e0fef82007-06-17 19:56:36 -05001549lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1550 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001551{
James Smart2e0fef82007-06-17 19:56:36 -05001552 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -05001553 IOCB_t *irsp;
1554
1555 irsp = &rspiocb->iocb;
1556
James Smart858c9f62007-06-17 19:56:39 -05001557 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1558 "ELS cmd cmpl: status:x%x/x%x did:x%x",
1559 irsp->ulpStatus, irsp->un.ulpWord[4],
1560 irsp->un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05001561 /* ELS cmd tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04001562 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1563 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
1564 irsp->ulpIoTag, irsp->ulpStatus,
1565 irsp->un.ulpWord[4], irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -05001566 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001567 lpfc_els_chk_latt(vport);
dea31012005-04-17 16:05:31 -05001568 lpfc_els_free_iocb(phba, cmdiocb);
1569 return;
1570}
1571
1572int
James Smart2e0fef82007-06-17 19:56:36 -05001573lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05001574{
James Smart2e0fef82007-06-17 19:56:36 -05001575 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001576 IOCB_t *icmd;
1577 struct lpfc_iocbq *elsiocb;
1578 struct lpfc_sli_ring *pring;
1579 struct lpfc_sli *psli;
1580 uint8_t *pcmd;
1581 uint16_t cmdsize;
1582 struct lpfc_nodelist *ndlp;
1583
1584 psli = &phba->sli;
1585 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
James Smart92d7f7b2007-06-17 19:56:38 -05001586 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
dea31012005-04-17 16:05:31 -05001587
James Smarte47c9092008-02-08 18:49:26 -05001588 ndlp = lpfc_findnode_did(vport, nportid);
1589 if (!ndlp) {
1590 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1591 if (!ndlp)
1592 return 1;
1593 lpfc_nlp_init(vport, ndlp, nportid);
1594 lpfc_enqueue_node(vport, ndlp);
1595 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1596 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1597 if (!ndlp)
1598 return 1;
1599 }
dea31012005-04-17 16:05:31 -05001600
James Smart2e0fef82007-06-17 19:56:36 -05001601 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1602 ndlp->nlp_DID, ELS_CMD_SCR);
1603
James Smart488d1462006-03-07 15:02:37 -05001604 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05001605 /* This will trigger the release of the node just
1606 * allocated
1607 */
James Smart329f9bc2007-04-25 09:53:01 -04001608 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001609 return 1;
dea31012005-04-17 16:05:31 -05001610 }
1611
1612 icmd = &elsiocb->iocb;
1613 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1614
1615 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
James Smart92d7f7b2007-06-17 19:56:38 -05001616 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001617
1618 /* For SCR, remainder of payload is SCR parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05001619 memset(pcmd, 0, sizeof(SCR));
dea31012005-04-17 16:05:31 -05001620 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
1621
James Smart858c9f62007-06-17 19:56:39 -05001622 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1623 "Issue SCR: did:x%x",
1624 ndlp->nlp_DID, 0, 0);
1625
dea31012005-04-17 16:05:31 -05001626 phba->fc_stat.elsXmitSCR++;
1627 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
dea31012005-04-17 16:05:31 -05001628 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05001629 /* The additional lpfc_nlp_put will cause the following
1630 * lpfc_els_free_iocb routine to trigger the rlease of
1631 * the node.
1632 */
James Smart329f9bc2007-04-25 09:53:01 -04001633 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001634 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001635 return 1;
dea31012005-04-17 16:05:31 -05001636 }
James Smartfa4066b2008-01-11 01:53:27 -05001637 /* This will cause the callback-function lpfc_cmpl_els_cmd to
1638 * trigger the release of node.
1639 */
James Smart329f9bc2007-04-25 09:53:01 -04001640 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001641 return 0;
dea31012005-04-17 16:05:31 -05001642}
1643
1644static int
James Smart2e0fef82007-06-17 19:56:36 -05001645lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05001646{
James Smart2e0fef82007-06-17 19:56:36 -05001647 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001648 IOCB_t *icmd;
1649 struct lpfc_iocbq *elsiocb;
1650 struct lpfc_sli_ring *pring;
1651 struct lpfc_sli *psli;
1652 FARP *fp;
1653 uint8_t *pcmd;
1654 uint32_t *lp;
1655 uint16_t cmdsize;
1656 struct lpfc_nodelist *ondlp;
1657 struct lpfc_nodelist *ndlp;
1658
1659 psli = &phba->sli;
1660 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
James Smart92d7f7b2007-06-17 19:56:38 -05001661 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
dea31012005-04-17 16:05:31 -05001662
James Smarte47c9092008-02-08 18:49:26 -05001663 ndlp = lpfc_findnode_did(vport, nportid);
1664 if (!ndlp) {
1665 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1666 if (!ndlp)
1667 return 1;
1668 lpfc_nlp_init(vport, ndlp, nportid);
1669 lpfc_enqueue_node(vport, ndlp);
1670 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1671 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1672 if (!ndlp)
1673 return 1;
1674 }
James Smart2e0fef82007-06-17 19:56:36 -05001675
1676 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1677 ndlp->nlp_DID, ELS_CMD_RNID);
James Smart488d1462006-03-07 15:02:37 -05001678 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05001679 /* This will trigger the release of the node just
1680 * allocated
1681 */
James Smart329f9bc2007-04-25 09:53:01 -04001682 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001683 return 1;
dea31012005-04-17 16:05:31 -05001684 }
1685
1686 icmd = &elsiocb->iocb;
1687 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1688
1689 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
James Smart92d7f7b2007-06-17 19:56:38 -05001690 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001691
1692 /* Fill in FARPR payload */
1693 fp = (FARP *) (pcmd);
James Smart92d7f7b2007-06-17 19:56:38 -05001694 memset(fp, 0, sizeof(FARP));
dea31012005-04-17 16:05:31 -05001695 lp = (uint32_t *) pcmd;
1696 *lp++ = be32_to_cpu(nportid);
James Smart2e0fef82007-06-17 19:56:36 -05001697 *lp++ = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05001698 fp->Rflags = 0;
1699 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
1700
James Smart92d7f7b2007-06-17 19:56:38 -05001701 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
1702 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05001703 ondlp = lpfc_findnode_did(vport, nportid);
James Smarte47c9092008-02-08 18:49:26 -05001704 if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
dea31012005-04-17 16:05:31 -05001705 memcpy(&fp->OportName, &ondlp->nlp_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05001706 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05001707 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05001708 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05001709 }
1710
James Smart858c9f62007-06-17 19:56:39 -05001711 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1712 "Issue FARPR: did:x%x",
1713 ndlp->nlp_DID, 0, 0);
1714
dea31012005-04-17 16:05:31 -05001715 phba->fc_stat.elsXmitFARPR++;
1716 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
dea31012005-04-17 16:05:31 -05001717 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05001718 /* The additional lpfc_nlp_put will cause the following
1719 * lpfc_els_free_iocb routine to trigger the release of
1720 * the node.
1721 */
James Smart329f9bc2007-04-25 09:53:01 -04001722 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001723 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001724 return 1;
dea31012005-04-17 16:05:31 -05001725 }
James Smartfa4066b2008-01-11 01:53:27 -05001726 /* This will cause the callback-function lpfc_cmpl_els_cmd to
1727 * trigger the release of the node.
1728 */
James Smart329f9bc2007-04-25 09:53:01 -04001729 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001730 return 0;
dea31012005-04-17 16:05:31 -05001731}
1732
1733void
James Smart2e0fef82007-06-17 19:56:36 -05001734lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
James Smartfdcebe22006-03-07 15:04:01 -05001735{
James Smart2e0fef82007-06-17 19:56:36 -05001736 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smarte47c9092008-02-08 18:49:26 -05001737 struct lpfc_work_evt *evtp;
James Smart2e0fef82007-06-17 19:56:36 -05001738
1739 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05001740 nlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001741 spin_unlock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05001742 del_timer_sync(&nlp->nlp_delayfunc);
1743 nlp->nlp_last_elscmd = 0;
1744
James Smarte47c9092008-02-08 18:49:26 -05001745 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
James Smartfdcebe22006-03-07 15:04:01 -05001746 list_del_init(&nlp->els_retry_evt.evt_listp);
James Smarte47c9092008-02-08 18:49:26 -05001747 /* Decrement nlp reference count held for the delayed retry */
1748 evtp = &nlp->els_retry_evt;
1749 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
1750 }
James Smartfdcebe22006-03-07 15:04:01 -05001751
1752 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
James Smart2e0fef82007-06-17 19:56:36 -05001753 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05001754 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001755 spin_unlock_irq(shost->host_lock);
1756 if (vport->num_disc_nodes) {
James Smartfdcebe22006-03-07 15:04:01 -05001757 /* Check to see if there are more
1758 * PLOGIs to be sent
1759 */
James Smart2e0fef82007-06-17 19:56:36 -05001760 lpfc_more_plogi(vport);
James Smartfdcebe22006-03-07 15:04:01 -05001761
James Smart2e0fef82007-06-17 19:56:36 -05001762 if (vport->num_disc_nodes == 0) {
1763 spin_lock_irq(shost->host_lock);
1764 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1765 spin_unlock_irq(shost->host_lock);
1766 lpfc_can_disctmo(vport);
James Smarted957682007-06-17 19:56:37 -05001767 lpfc_end_rscn(vport);
James Smartfdcebe22006-03-07 15:04:01 -05001768 }
1769 }
1770 }
1771 return;
1772}
1773
1774void
dea31012005-04-17 16:05:31 -05001775lpfc_els_retry_delay(unsigned long ptr)
1776{
James Smart2e0fef82007-06-17 19:56:36 -05001777 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
1778 struct lpfc_vport *vport = ndlp->vport;
James Smart2e0fef82007-06-17 19:56:36 -05001779 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05001780 unsigned long flags;
James Smart2e0fef82007-06-17 19:56:36 -05001781 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
dea31012005-04-17 16:05:31 -05001782
James Smart2e0fef82007-06-17 19:56:36 -05001783 ndlp = (struct lpfc_nodelist *) ptr;
1784 phba = ndlp->vport->phba;
dea31012005-04-17 16:05:31 -05001785 evtp = &ndlp->els_retry_evt;
1786
James Smart92d7f7b2007-06-17 19:56:38 -05001787 spin_lock_irqsave(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05001788 if (!list_empty(&evtp->evt_listp)) {
James Smart92d7f7b2007-06-17 19:56:38 -05001789 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05001790 return;
1791 }
1792
James Smartfa4066b2008-01-11 01:53:27 -05001793 /* We need to hold the node by incrementing the reference
1794 * count until the queued work is done
1795 */
1796 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
dea31012005-04-17 16:05:31 -05001797 evtp->evt = LPFC_EVT_ELS_RETRY;
1798 list_add_tail(&evtp->evt_listp, &phba->work_list);
1799 if (phba->work_wait)
James Smart92d7f7b2007-06-17 19:56:38 -05001800 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05001801
James Smart92d7f7b2007-06-17 19:56:38 -05001802 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05001803 return;
1804}
1805
1806void
1807lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
1808{
James Smart2e0fef82007-06-17 19:56:36 -05001809 struct lpfc_vport *vport = ndlp->vport;
1810 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1811 uint32_t cmd, did, retry;
dea31012005-04-17 16:05:31 -05001812
James Smart2e0fef82007-06-17 19:56:36 -05001813 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001814 did = ndlp->nlp_DID;
1815 cmd = ndlp->nlp_last_elscmd;
1816 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05001817
1818 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
James Smart2e0fef82007-06-17 19:56:36 -05001819 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001820 return;
1821 }
1822
1823 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001824 spin_unlock_irq(shost->host_lock);
James Smart1a169682006-03-07 15:04:06 -05001825 /*
1826 * If a discovery event readded nlp_delayfunc after timer
1827 * firing and before processing the timer, cancel the
1828 * nlp_delayfunc.
1829 */
1830 del_timer_sync(&ndlp->nlp_delayfunc);
dea31012005-04-17 16:05:31 -05001831 retry = ndlp->nlp_retry;
1832
1833 switch (cmd) {
1834 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05001835 lpfc_issue_els_flogi(vport, ndlp, retry);
dea31012005-04-17 16:05:31 -05001836 break;
1837 case ELS_CMD_PLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05001838 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001839 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001840 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05001841 }
dea31012005-04-17 16:05:31 -05001842 break;
1843 case ELS_CMD_ADISC:
James Smart2e0fef82007-06-17 19:56:36 -05001844 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001845 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001846 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05001847 }
dea31012005-04-17 16:05:31 -05001848 break;
1849 case ELS_CMD_PRLI:
James Smart2e0fef82007-06-17 19:56:36 -05001850 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001851 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001852 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05001853 }
dea31012005-04-17 16:05:31 -05001854 break;
1855 case ELS_CMD_LOGO:
James Smart2e0fef82007-06-17 19:56:36 -05001856 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001857 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05001858 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05001859 }
dea31012005-04-17 16:05:31 -05001860 break;
James Smart92d7f7b2007-06-17 19:56:38 -05001861 case ELS_CMD_FDISC:
1862 lpfc_issue_els_fdisc(vport, ndlp, retry);
1863 break;
dea31012005-04-17 16:05:31 -05001864 }
1865 return;
1866}
1867
1868static int
James Smart2e0fef82007-06-17 19:56:36 -05001869lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1870 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001871{
James Smart2e0fef82007-06-17 19:56:36 -05001872 struct lpfc_vport *vport = cmdiocb->vport;
1873 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1874 IOCB_t *irsp = &rspiocb->iocb;
1875 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1876 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
dea31012005-04-17 16:05:31 -05001877 uint32_t *elscmd;
1878 struct ls_rjt stat;
James Smart2e0fef82007-06-17 19:56:36 -05001879 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
James Smart98c9ea52007-10-27 13:37:33 -04001880 int logerr = 0;
James Smart2e0fef82007-06-17 19:56:36 -05001881 uint32_t cmd = 0;
James Smart488d1462006-03-07 15:02:37 -05001882 uint32_t did;
dea31012005-04-17 16:05:31 -05001883
James Smart488d1462006-03-07 15:02:37 -05001884
dea31012005-04-17 16:05:31 -05001885 /* Note: context2 may be 0 for internal driver abort
1886 * of delays ELS command.
1887 */
1888
1889 if (pcmd && pcmd->virt) {
1890 elscmd = (uint32_t *) (pcmd->virt);
1891 cmd = *elscmd++;
1892 }
1893
James Smarte47c9092008-02-08 18:49:26 -05001894 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart488d1462006-03-07 15:02:37 -05001895 did = ndlp->nlp_DID;
1896 else {
1897 /* We should only hit this case for retrying PLOGI */
1898 did = irsp->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05001899 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05001900 if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
1901 && (cmd != ELS_CMD_PLOGI))
James Smart488d1462006-03-07 15:02:37 -05001902 return 1;
1903 }
1904
James Smart858c9f62007-06-17 19:56:39 -05001905 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1906 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
1907 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
1908
dea31012005-04-17 16:05:31 -05001909 switch (irsp->ulpStatus) {
1910 case IOSTAT_FCP_RSP_ERROR:
1911 case IOSTAT_REMOTE_STOP:
1912 break;
1913
1914 case IOSTAT_LOCAL_REJECT:
1915 switch ((irsp->un.ulpWord[4] & 0xff)) {
1916 case IOERR_LOOP_OPEN_FAILURE:
James Smart2e0fef82007-06-17 19:56:36 -05001917 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05001918 delay = 1000;
dea31012005-04-17 16:05:31 -05001919 retry = 1;
1920 break;
1921
James Smart92d7f7b2007-06-17 19:56:38 -05001922 case IOERR_ILLEGAL_COMMAND:
James Smart7f5f3d02008-02-08 18:50:14 -05001923 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1924 "0124 Retry illegal cmd x%x "
1925 "retry:x%x delay:x%x\n",
1926 cmd, cmdiocb->retry, delay);
1927 retry = 1;
1928 /* All command's retry policy */
1929 maxretry = 8;
1930 if (cmdiocb->retry > 2)
1931 delay = 1000;
James Smart92d7f7b2007-06-17 19:56:38 -05001932 break;
1933
dea31012005-04-17 16:05:31 -05001934 case IOERR_NO_RESOURCES:
James Smart98c9ea52007-10-27 13:37:33 -04001935 logerr = 1; /* HBA out of resources */
James Smart858c9f62007-06-17 19:56:39 -05001936 retry = 1;
1937 if (cmdiocb->retry > 100)
1938 delay = 100;
1939 maxretry = 250;
1940 break;
1941
1942 case IOERR_ILLEGAL_FRAME:
James Smart92d7f7b2007-06-17 19:56:38 -05001943 delay = 100;
dea31012005-04-17 16:05:31 -05001944 retry = 1;
1945 break;
1946
James Smart858c9f62007-06-17 19:56:39 -05001947 case IOERR_SEQUENCE_TIMEOUT:
dea31012005-04-17 16:05:31 -05001948 case IOERR_INVALID_RPI:
1949 retry = 1;
1950 break;
1951 }
1952 break;
1953
1954 case IOSTAT_NPORT_RJT:
1955 case IOSTAT_FABRIC_RJT:
1956 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
1957 retry = 1;
1958 break;
1959 }
1960 break;
1961
1962 case IOSTAT_NPORT_BSY:
1963 case IOSTAT_FABRIC_BSY:
James Smart98c9ea52007-10-27 13:37:33 -04001964 logerr = 1; /* Fabric / Remote NPort out of resources */
dea31012005-04-17 16:05:31 -05001965 retry = 1;
1966 break;
1967
1968 case IOSTAT_LS_RJT:
1969 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
1970 /* Added for Vendor specifc support
1971 * Just keep retrying for these Rsn / Exp codes
1972 */
1973 switch (stat.un.b.lsRjtRsnCode) {
1974 case LSRJT_UNABLE_TPC:
1975 if (stat.un.b.lsRjtRsnCodeExp ==
1976 LSEXP_CMD_IN_PROGRESS) {
1977 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05001978 delay = 1000;
dea31012005-04-17 16:05:31 -05001979 maxretry = 48;
1980 }
1981 retry = 1;
1982 break;
1983 }
1984 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05001985 delay = 1000;
dea31012005-04-17 16:05:31 -05001986 maxretry = lpfc_max_els_tries + 1;
1987 retry = 1;
1988 break;
1989 }
James Smart92d7f7b2007-06-17 19:56:38 -05001990 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
1991 (cmd == ELS_CMD_FDISC) &&
1992 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
James Smarte8b62012007-08-02 11:10:09 -04001993 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1994 "0125 FDISC Failed (x%x). "
1995 "Fabric out of resources\n",
1996 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05001997 lpfc_vport_set_state(vport,
1998 FC_VPORT_NO_FABRIC_RSCS);
1999 }
dea31012005-04-17 16:05:31 -05002000 break;
2001
2002 case LSRJT_LOGICAL_BSY:
James Smart858c9f62007-06-17 19:56:39 -05002003 if ((cmd == ELS_CMD_PLOGI) ||
2004 (cmd == ELS_CMD_PRLI)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002005 delay = 1000;
dea31012005-04-17 16:05:31 -05002006 maxretry = 48;
James Smart92d7f7b2007-06-17 19:56:38 -05002007 } else if (cmd == ELS_CMD_FDISC) {
James Smart51ef4c22007-08-02 11:10:31 -04002008 /* FDISC retry policy */
2009 maxretry = 48;
2010 if (cmdiocb->retry >= 32)
2011 delay = 1000;
dea31012005-04-17 16:05:31 -05002012 }
2013 retry = 1;
2014 break;
James Smart92d7f7b2007-06-17 19:56:38 -05002015
2016 case LSRJT_LOGICAL_ERR:
James Smart7f5f3d02008-02-08 18:50:14 -05002017 /* There are some cases where switches return this
2018 * error when they are not ready and should be returning
2019 * Logical Busy. We should delay every time.
2020 */
2021 if (cmd == ELS_CMD_FDISC &&
2022 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
2023 maxretry = 3;
2024 delay = 1000;
2025 retry = 1;
2026 break;
2027 }
James Smart92d7f7b2007-06-17 19:56:38 -05002028 case LSRJT_PROTOCOL_ERR:
2029 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2030 (cmd == ELS_CMD_FDISC) &&
2031 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
2032 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
2033 ) {
James Smarte8b62012007-08-02 11:10:09 -04002034 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2035 "0123 FDISC Failed (x%x). "
2036 "Fabric Detected Bad WWN\n",
2037 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05002038 lpfc_vport_set_state(vport,
2039 FC_VPORT_FABRIC_REJ_WWN);
2040 }
2041 break;
dea31012005-04-17 16:05:31 -05002042 }
2043 break;
2044
2045 case IOSTAT_INTERMED_RSP:
2046 case IOSTAT_BA_RJT:
2047 break;
2048
2049 default:
2050 break;
2051 }
2052
James Smart488d1462006-03-07 15:02:37 -05002053 if (did == FDMI_DID)
dea31012005-04-17 16:05:31 -05002054 retry = 1;
dea31012005-04-17 16:05:31 -05002055
James Smart98c9ea52007-10-27 13:37:33 -04002056 if ((cmd == ELS_CMD_FLOGI) &&
James Smart1b32f6a2008-02-08 18:49:39 -05002057 (phba->fc_topology != TOPOLOGY_LOOP) &&
2058 !lpfc_error_lost_link(irsp)) {
James Smart98c9ea52007-10-27 13:37:33 -04002059 /* FLOGI retry policy */
2060 retry = 1;
2061 maxretry = 48;
2062 if (cmdiocb->retry >= 32)
2063 delay = 1000;
2064 }
2065
dea31012005-04-17 16:05:31 -05002066 if ((++cmdiocb->retry) >= maxretry) {
2067 phba->fc_stat.elsRetryExceeded++;
2068 retry = 0;
2069 }
2070
James Smarted957682007-06-17 19:56:37 -05002071 if ((vport->load_flag & FC_UNLOADING) != 0)
2072 retry = 0;
2073
dea31012005-04-17 16:05:31 -05002074 if (retry) {
2075
2076 /* Retry ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04002077 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2078 "0107 Retry ELS command x%x to remote "
2079 "NPORT x%x Data: x%x x%x\n",
2080 cmd, did, cmdiocb->retry, delay);
dea31012005-04-17 16:05:31 -05002081
James Smart858c9f62007-06-17 19:56:39 -05002082 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
2083 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
2084 ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) {
2085 /* Don't reset timer for no resources */
2086
dea31012005-04-17 16:05:31 -05002087 /* If discovery / RSCN timer is running, reset it */
James Smart2e0fef82007-06-17 19:56:36 -05002088 if (timer_pending(&vport->fc_disctmo) ||
James Smart92d7f7b2007-06-17 19:56:38 -05002089 (vport->fc_flag & FC_RSCN_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05002090 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05002091 }
2092
2093 phba->fc_stat.elsXmitRetry++;
James Smart488d1462006-03-07 15:02:37 -05002094 if (ndlp && delay) {
dea31012005-04-17 16:05:31 -05002095 phba->fc_stat.elsDelayRetry++;
2096 ndlp->nlp_retry = cmdiocb->retry;
2097
James Smart92d7f7b2007-06-17 19:56:38 -05002098 /* delay is specified in milliseconds */
2099 mod_timer(&ndlp->nlp_delayfunc,
2100 jiffies + msecs_to_jiffies(delay));
James Smart2e0fef82007-06-17 19:56:36 -05002101 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002102 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002103 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002104
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002105 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart858c9f62007-06-17 19:56:39 -05002106 if (cmd == ELS_CMD_PRLI)
2107 lpfc_nlp_set_state(vport, ndlp,
2108 NLP_STE_REG_LOGIN_ISSUE);
2109 else
2110 lpfc_nlp_set_state(vport, ndlp,
2111 NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05002112 ndlp->nlp_last_elscmd = cmd;
2113
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002114 return 1;
dea31012005-04-17 16:05:31 -05002115 }
2116 switch (cmd) {
2117 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002118 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002119 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -05002120 case ELS_CMD_FDISC:
2121 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
2122 return 1;
dea31012005-04-17 16:05:31 -05002123 case ELS_CMD_PLOGI:
James Smart488d1462006-03-07 15:02:37 -05002124 if (ndlp) {
2125 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002126 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04002127 NLP_STE_PLOGI_ISSUE);
James Smart488d1462006-03-07 15:02:37 -05002128 }
James Smart2e0fef82007-06-17 19:56:36 -05002129 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002130 return 1;
dea31012005-04-17 16:05:31 -05002131 case ELS_CMD_ADISC:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002132 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002133 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2134 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002135 return 1;
dea31012005-04-17 16:05:31 -05002136 case ELS_CMD_PRLI:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002137 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002138 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
2139 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002140 return 1;
dea31012005-04-17 16:05:31 -05002141 case ELS_CMD_LOGO:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002142 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002143 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2144 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002145 return 1;
dea31012005-04-17 16:05:31 -05002146 }
2147 }
dea31012005-04-17 16:05:31 -05002148 /* No retry ELS command <elsCmd> to remote NPORT <did> */
James Smart98c9ea52007-10-27 13:37:33 -04002149 if (logerr) {
2150 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2151 "0137 No retry ELS command x%x to remote "
2152 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
2153 cmd, did, irsp->ulpStatus,
2154 irsp->un.ulpWord[4]);
2155 }
2156 else {
2157 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smarta58cbd52007-08-02 11:09:43 -04002158 "0108 No retry ELS command x%x to remote "
2159 "NPORT x%x Retried:%d Error:x%x/%x\n",
2160 cmd, did, cmdiocb->retry, irsp->ulpStatus,
2161 irsp->un.ulpWord[4]);
James Smart98c9ea52007-10-27 13:37:33 -04002162 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002163 return 0;
dea31012005-04-17 16:05:31 -05002164}
2165
James Smart09372822008-01-11 01:52:54 -05002166static int
James Smart87af33f2007-10-27 13:37:43 -04002167lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
2168{
2169 struct lpfc_dmabuf *buf_ptr;
2170
2171 /* Free the response before processing the command. */
2172 if (!list_empty(&buf_ptr1->list)) {
2173 list_remove_head(&buf_ptr1->list, buf_ptr,
2174 struct lpfc_dmabuf,
2175 list);
2176 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
2177 kfree(buf_ptr);
2178 }
2179 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
2180 kfree(buf_ptr1);
2181 return 0;
2182}
2183
James Smart09372822008-01-11 01:52:54 -05002184static int
James Smart87af33f2007-10-27 13:37:43 -04002185lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
2186{
2187 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
2188 kfree(buf_ptr);
2189 return 0;
2190}
2191
2192int
James Smart329f9bc2007-04-25 09:53:01 -04002193lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05002194{
2195 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
James Smarta8adb832007-10-27 13:37:53 -04002196 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05002197
James Smarta8adb832007-10-27 13:37:53 -04002198 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
2199 if (ndlp) {
2200 if (ndlp->nlp_flag & NLP_DEFER_RM) {
2201 lpfc_nlp_put(ndlp);
2202
2203 /* If the ndlp is not being used by another discovery
2204 * thread, free it.
2205 */
2206 if (!lpfc_nlp_not_used(ndlp)) {
2207 /* If ndlp is being used by another discovery
2208 * thread, just clear NLP_DEFER_RM
2209 */
2210 ndlp->nlp_flag &= ~NLP_DEFER_RM;
2211 }
2212 }
2213 else
2214 lpfc_nlp_put(ndlp);
James Smart329f9bc2007-04-25 09:53:01 -04002215 elsiocb->context1 = NULL;
2216 }
dea31012005-04-17 16:05:31 -05002217 /* context2 = cmd, context2->next = rsp, context3 = bpl */
2218 if (elsiocb->context2) {
James Smart0ff10d42008-01-11 01:52:36 -05002219 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
2220 /* Firmware could still be in progress of DMAing
2221 * payload, so don't free data buffer till after
2222 * a hbeat.
2223 */
2224 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
2225 buf_ptr = elsiocb->context2;
2226 elsiocb->context2 = NULL;
2227 if (buf_ptr) {
2228 buf_ptr1 = NULL;
2229 spin_lock_irq(&phba->hbalock);
2230 if (!list_empty(&buf_ptr->list)) {
2231 list_remove_head(&buf_ptr->list,
2232 buf_ptr1, struct lpfc_dmabuf,
2233 list);
2234 INIT_LIST_HEAD(&buf_ptr1->list);
2235 list_add_tail(&buf_ptr1->list,
2236 &phba->elsbuf);
2237 phba->elsbuf_cnt++;
2238 }
2239 INIT_LIST_HEAD(&buf_ptr->list);
2240 list_add_tail(&buf_ptr->list, &phba->elsbuf);
2241 phba->elsbuf_cnt++;
2242 spin_unlock_irq(&phba->hbalock);
2243 }
2244 } else {
2245 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
2246 lpfc_els_free_data(phba, buf_ptr1);
2247 }
dea31012005-04-17 16:05:31 -05002248 }
2249
2250 if (elsiocb->context3) {
2251 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
James Smart87af33f2007-10-27 13:37:43 -04002252 lpfc_els_free_bpl(phba, buf_ptr);
dea31012005-04-17 16:05:31 -05002253 }
James Bottomley604a3e32005-10-29 10:28:33 -05002254 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -05002255 return 0;
2256}
2257
2258static void
James Smart2e0fef82007-06-17 19:56:36 -05002259lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2260 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002261{
James Smart2e0fef82007-06-17 19:56:36 -05002262 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2263 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05002264 IOCB_t *irsp;
2265
2266 irsp = &rspiocb->iocb;
2267 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2268 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
2269 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05002270 /* ACC to LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002271 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2272 "0109 ACC to LOGO completes to NPort x%x "
2273 "Data: x%x x%x x%x\n",
2274 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2275 ndlp->nlp_rpi);
James Smart87af33f2007-10-27 13:37:43 -04002276
2277 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
2278 /* NPort Recovery mode or node is just allocated */
2279 if (!lpfc_nlp_not_used(ndlp)) {
2280 /* If the ndlp is being used by another discovery
2281 * thread, just unregister the RPI.
2282 */
2283 lpfc_unreg_rpi(vport, ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05002284 } else {
2285 /* Indicate the node has already released, should
2286 * not reference to it from within lpfc_els_free_iocb.
2287 */
2288 cmdiocb->context1 = NULL;
James Smart87af33f2007-10-27 13:37:43 -04002289 }
dea31012005-04-17 16:05:31 -05002290 }
2291 lpfc_els_free_iocb(phba, cmdiocb);
2292 return;
2293}
2294
James Smart858c9f62007-06-17 19:56:39 -05002295void
2296lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
2297{
2298 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
2299 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
2300
2301 pmb->context1 = NULL;
2302 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2303 kfree(mp);
2304 mempool_free(pmb, phba->mbox_mem_pool);
James Smarta8adb832007-10-27 13:37:53 -04002305 if (ndlp) {
2306 lpfc_nlp_put(ndlp);
James Smarta8adb832007-10-27 13:37:53 -04002307 /* This is the end of the default RPI cleanup logic for this
2308 * ndlp. If no other discovery threads are using this ndlp.
2309 * we should free all resources associated with it.
2310 */
2311 lpfc_nlp_not_used(ndlp);
2312 }
James Smart858c9f62007-06-17 19:56:39 -05002313 return;
2314}
2315
dea31012005-04-17 16:05:31 -05002316static void
James Smart858c9f62007-06-17 19:56:39 -05002317lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
James Smart329f9bc2007-04-25 09:53:01 -04002318 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002319{
James Smart2e0fef82007-06-17 19:56:36 -05002320 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2321 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
2322 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
James Smart87af33f2007-10-27 13:37:43 -04002323 IOCB_t *irsp;
2324 uint8_t *pcmd;
dea31012005-04-17 16:05:31 -05002325 LPFC_MBOXQ_t *mbox = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05002326 struct lpfc_dmabuf *mp = NULL;
James Smart87af33f2007-10-27 13:37:43 -04002327 uint32_t ls_rjt = 0;
dea31012005-04-17 16:05:31 -05002328
James Smart33ccf8d2006-08-17 11:57:58 -04002329 irsp = &rspiocb->iocb;
2330
dea31012005-04-17 16:05:31 -05002331 if (cmdiocb->context_un.mbox)
2332 mbox = cmdiocb->context_un.mbox;
2333
James Smartfa4066b2008-01-11 01:53:27 -05002334 /* First determine if this is a LS_RJT cmpl. Note, this callback
2335 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
2336 */
James Smart87af33f2007-10-27 13:37:43 -04002337 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
James Smartfa4066b2008-01-11 01:53:27 -05002338 if (ndlp && (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
2339 /* A LS_RJT associated with Default RPI cleanup has its own
2340 * seperate code path.
James Smart87af33f2007-10-27 13:37:43 -04002341 */
2342 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
2343 ls_rjt = 1;
2344 }
2345
dea31012005-04-17 16:05:31 -05002346 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002347 if (!ndlp || lpfc_els_chk_latt(vport)) {
dea31012005-04-17 16:05:31 -05002348 if (mbox) {
James Smart14691152006-12-02 13:34:28 -05002349 mp = (struct lpfc_dmabuf *) mbox->context1;
2350 if (mp) {
2351 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2352 kfree(mp);
2353 }
James Smart329f9bc2007-04-25 09:53:01 -04002354 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05002355 }
James Smart98c9ea52007-10-27 13:37:33 -04002356 if (ndlp && (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
James Smartfa4066b2008-01-11 01:53:27 -05002357 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04002358 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05002359 /* Indicate the node has already released,
2360 * should not reference to it from within
2361 * the routine lpfc_els_free_iocb.
2362 */
2363 cmdiocb->context1 = NULL;
2364 }
dea31012005-04-17 16:05:31 -05002365 goto out;
2366 }
2367
James Smart858c9f62007-06-17 19:56:39 -05002368 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smart51ef4c22007-08-02 11:10:31 -04002369 "ELS rsp cmpl: status:x%x/x%x did:x%x",
James Smart858c9f62007-06-17 19:56:39 -05002370 irsp->ulpStatus, irsp->un.ulpWord[4],
James Smart51ef4c22007-08-02 11:10:31 -04002371 cmdiocb->iocb.un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05002372 /* ELS response tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04002373 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2374 "0110 ELS response tag x%x completes "
2375 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
2376 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
2377 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
2378 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2379 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05002380 if (mbox) {
2381 if ((rspiocb->iocb.ulpStatus == 0)
2382 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
James Smart2e0fef82007-06-17 19:56:36 -05002383 lpfc_unreg_rpi(vport, ndlp);
James Smarte47c9092008-02-08 18:49:26 -05002384 /* Increment reference count to ndlp to hold the
2385 * reference to ndlp for the callback function.
2386 */
James Smart329f9bc2007-04-25 09:53:01 -04002387 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05002388 mbox->vport = vport;
James Smart858c9f62007-06-17 19:56:39 -05002389 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
2390 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
2391 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
2392 }
2393 else {
2394 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
2395 ndlp->nlp_prev_state = ndlp->nlp_state;
2396 lpfc_nlp_set_state(vport, ndlp,
James Smart2e0fef82007-06-17 19:56:36 -05002397 NLP_STE_REG_LOGIN_ISSUE);
James Smart858c9f62007-06-17 19:56:39 -05002398 }
James Smart0b727fe2007-10-27 13:37:25 -04002399 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smarte47c9092008-02-08 18:49:26 -05002400 != MBX_NOT_FINISHED)
dea31012005-04-17 16:05:31 -05002401 goto out;
James Smarte47c9092008-02-08 18:49:26 -05002402 else
2403 /* Decrement the ndlp reference count we
2404 * set for this failed mailbox command.
2405 */
2406 lpfc_nlp_put(ndlp);
James Smart98c9ea52007-10-27 13:37:33 -04002407
2408 /* ELS rsp: Cannot issue reg_login for <NPortid> */
2409 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2410 "0138 ELS rsp: Cannot issue reg_login for x%x "
2411 "Data: x%x x%x x%x\n",
2412 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2413 ndlp->nlp_rpi);
2414
James Smartfa4066b2008-01-11 01:53:27 -05002415 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04002416 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05002417 /* Indicate node has already been released,
2418 * should not reference to it from within
2419 * the routine lpfc_els_free_iocb.
2420 */
2421 cmdiocb->context1 = NULL;
2422 }
dea31012005-04-17 16:05:31 -05002423 } else {
James Smart858c9f62007-06-17 19:56:39 -05002424 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
2425 if (!lpfc_error_lost_link(irsp) &&
2426 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
James Smartfa4066b2008-01-11 01:53:27 -05002427 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04002428 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05002429 /* Indicate node has already been
2430 * released, should not reference
2431 * to it from within the routine
2432 * lpfc_els_free_iocb.
2433 */
2434 cmdiocb->context1 = NULL;
2435 }
dea31012005-04-17 16:05:31 -05002436 }
2437 }
James Smart14691152006-12-02 13:34:28 -05002438 mp = (struct lpfc_dmabuf *) mbox->context1;
2439 if (mp) {
2440 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2441 kfree(mp);
2442 }
2443 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05002444 }
2445out:
2446 if (ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05002447 spin_lock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05002448 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
James Smart2e0fef82007-06-17 19:56:36 -05002449 spin_unlock_irq(shost->host_lock);
James Smart87af33f2007-10-27 13:37:43 -04002450
2451 /* If the node is not being used by another discovery thread,
2452 * and we are sending a reject, we are done with it.
2453 * Release driver reference count here and free associated
2454 * resources.
2455 */
2456 if (ls_rjt)
James Smartfa4066b2008-01-11 01:53:27 -05002457 if (lpfc_nlp_not_used(ndlp))
2458 /* Indicate node has already been released,
2459 * should not reference to it from within
2460 * the routine lpfc_els_free_iocb.
2461 */
2462 cmdiocb->context1 = NULL;
dea31012005-04-17 16:05:31 -05002463 }
James Smart87af33f2007-10-27 13:37:43 -04002464
dea31012005-04-17 16:05:31 -05002465 lpfc_els_free_iocb(phba, cmdiocb);
2466 return;
2467}
2468
2469int
James Smart2e0fef82007-06-17 19:56:36 -05002470lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
2471 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
James Smart51ef4c22007-08-02 11:10:31 -04002472 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05002473{
James Smart2e0fef82007-06-17 19:56:36 -05002474 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2475 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002476 IOCB_t *icmd;
2477 IOCB_t *oldcmd;
2478 struct lpfc_iocbq *elsiocb;
2479 struct lpfc_sli_ring *pring;
2480 struct lpfc_sli *psli;
2481 uint8_t *pcmd;
2482 uint16_t cmdsize;
2483 int rc;
James Smart82d9a2a2006-04-15 11:53:05 -04002484 ELS_PKT *els_pkt_ptr;
dea31012005-04-17 16:05:31 -05002485
2486 psli = &phba->sli;
2487 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2488 oldcmd = &oldiocb->iocb;
2489
2490 switch (flag) {
2491 case ELS_CMD_ACC:
James Smart92d7f7b2007-06-17 19:56:38 -05002492 cmdsize = sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05002493 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
2494 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05002495 if (!elsiocb) {
James Smart2e0fef82007-06-17 19:56:36 -05002496 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002497 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05002498 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002499 return 1;
dea31012005-04-17 16:05:31 -05002500 }
James Smart2e0fef82007-06-17 19:56:36 -05002501
dea31012005-04-17 16:05:31 -05002502 icmd = &elsiocb->iocb;
2503 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2504 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2505 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05002506 pcmd += sizeof(uint32_t);
James Smart858c9f62007-06-17 19:56:39 -05002507
2508 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2509 "Issue ACC: did:x%x flg:x%x",
2510 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05002511 break;
2512 case ELS_CMD_PLOGI:
James Smart92d7f7b2007-06-17 19:56:38 -05002513 cmdsize = (sizeof(struct serv_parm) + 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)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002517 return 1;
James Smart488d1462006-03-07 15:02:37 -05002518
dea31012005-04-17 16:05:31 -05002519 icmd = &elsiocb->iocb;
2520 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2521 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2522
2523 if (mbox)
2524 elsiocb->context_un.mbox = mbox;
2525
2526 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05002527 pcmd += sizeof(uint32_t);
2528 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
James Smart858c9f62007-06-17 19:56:39 -05002529
2530 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2531 "Issue ACC PLOGI: did:x%x flg:x%x",
2532 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05002533 break;
James Smart82d9a2a2006-04-15 11:53:05 -04002534 case ELS_CMD_PRLO:
James Smart92d7f7b2007-06-17 19:56:38 -05002535 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
James Smart2e0fef82007-06-17 19:56:36 -05002536 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
James Smart82d9a2a2006-04-15 11:53:05 -04002537 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
2538 if (!elsiocb)
2539 return 1;
2540
2541 icmd = &elsiocb->iocb;
2542 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2543 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2544
2545 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
James Smart92d7f7b2007-06-17 19:56:38 -05002546 sizeof(uint32_t) + sizeof(PRLO));
James Smart82d9a2a2006-04-15 11:53:05 -04002547 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
2548 els_pkt_ptr = (ELS_PKT *) pcmd;
2549 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
James Smart858c9f62007-06-17 19:56:39 -05002550
2551 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2552 "Issue ACC PRLO: did:x%x flg:x%x",
2553 ndlp->nlp_DID, ndlp->nlp_flag, 0);
James Smart82d9a2a2006-04-15 11:53:05 -04002554 break;
dea31012005-04-17 16:05:31 -05002555 default:
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002556 return 1;
dea31012005-04-17 16:05:31 -05002557 }
dea31012005-04-17 16:05:31 -05002558 /* Xmit ELS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04002559 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2560 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
2561 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n",
2562 elsiocb->iotag, elsiocb->iocb.ulpContext,
2563 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2564 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05002565 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
James Smart2e0fef82007-06-17 19:56:36 -05002566 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002567 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05002568 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002569 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
2570 } else {
James Smart858c9f62007-06-17 19:56:39 -05002571 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05002572 }
2573
2574 phba->fc_stat.elsXmitACC++;
dea31012005-04-17 16:05:31 -05002575 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
dea31012005-04-17 16:05:31 -05002576 if (rc == IOCB_ERROR) {
2577 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002578 return 1;
dea31012005-04-17 16:05:31 -05002579 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002580 return 0;
dea31012005-04-17 16:05:31 -05002581}
2582
2583int
James Smart2e0fef82007-06-17 19:56:36 -05002584lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
James Smart858c9f62007-06-17 19:56:39 -05002585 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
2586 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05002587{
James Smart2e0fef82007-06-17 19:56:36 -05002588 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002589 IOCB_t *icmd;
2590 IOCB_t *oldcmd;
2591 struct lpfc_iocbq *elsiocb;
2592 struct lpfc_sli_ring *pring;
2593 struct lpfc_sli *psli;
2594 uint8_t *pcmd;
2595 uint16_t cmdsize;
2596 int rc;
2597
2598 psli = &phba->sli;
2599 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2600
James Smart92d7f7b2007-06-17 19:56:38 -05002601 cmdsize = 2 * sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05002602 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
2603 ndlp->nlp_DID, ELS_CMD_LS_RJT);
James Smart488d1462006-03-07 15:02:37 -05002604 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002605 return 1;
dea31012005-04-17 16:05:31 -05002606
2607 icmd = &elsiocb->iocb;
2608 oldcmd = &oldiocb->iocb;
2609 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
2610 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2611
2612 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
James Smart92d7f7b2007-06-17 19:56:38 -05002613 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002614 *((uint32_t *) (pcmd)) = rejectError;
2615
James Smart51ef4c22007-08-02 11:10:31 -04002616 if (mbox)
James Smart858c9f62007-06-17 19:56:39 -05002617 elsiocb->context_un.mbox = mbox;
James Smart858c9f62007-06-17 19:56:39 -05002618
dea31012005-04-17 16:05:31 -05002619 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04002620 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2621 "0129 Xmit ELS RJT x%x response tag x%x "
2622 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
2623 "rpi x%x\n",
2624 rejectError, elsiocb->iotag,
2625 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
2626 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05002627 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2628 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
2629 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
2630
dea31012005-04-17 16:05:31 -05002631 phba->fc_stat.elsXmitLSRJT++;
James Smart858c9f62007-06-17 19:56:39 -05002632 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05002633 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
James Smart51ef4c22007-08-02 11:10:31 -04002634
dea31012005-04-17 16:05:31 -05002635 if (rc == IOCB_ERROR) {
2636 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002637 return 1;
dea31012005-04-17 16:05:31 -05002638 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002639 return 0;
dea31012005-04-17 16:05:31 -05002640}
2641
2642int
James Smart2e0fef82007-06-17 19:56:36 -05002643lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
2644 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05002645{
James Smart2e0fef82007-06-17 19:56:36 -05002646 struct lpfc_hba *phba = vport->phba;
2647 struct lpfc_sli *psli = &phba->sli;
2648 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05002649 ADISC *ap;
James Smart2e0fef82007-06-17 19:56:36 -05002650 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05002651 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002652 uint8_t *pcmd;
2653 uint16_t cmdsize;
2654 int rc;
2655
James Smart92d7f7b2007-06-17 19:56:38 -05002656 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
James Smart2e0fef82007-06-17 19:56:36 -05002657 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
2658 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05002659 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002660 return 1;
dea31012005-04-17 16:05:31 -05002661
dea31012005-04-17 16:05:31 -05002662 icmd = &elsiocb->iocb;
2663 oldcmd = &oldiocb->iocb;
2664 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04002665
2666 /* Xmit ADISC ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04002667 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2668 "0130 Xmit ADISC ACC response iotag x%x xri: "
2669 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
2670 elsiocb->iotag, elsiocb->iocb.ulpContext,
2671 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2672 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05002673 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2674
2675 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05002676 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002677
2678 ap = (ADISC *) (pcmd);
2679 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05002680 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2681 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002682 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002683
James Smart858c9f62007-06-17 19:56:39 -05002684 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2685 "Issue ACC ADISC: did:x%x flg:x%x",
2686 ndlp->nlp_DID, ndlp->nlp_flag, 0);
2687
dea31012005-04-17 16:05:31 -05002688 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05002689 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05002690 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
dea31012005-04-17 16:05:31 -05002691 if (rc == IOCB_ERROR) {
2692 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002693 return 1;
dea31012005-04-17 16:05:31 -05002694 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002695 return 0;
dea31012005-04-17 16:05:31 -05002696}
2697
2698int
James Smart2e0fef82007-06-17 19:56:36 -05002699lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
James Smart5b8bd0c2007-04-25 09:52:49 -04002700 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05002701{
James Smart2e0fef82007-06-17 19:56:36 -05002702 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002703 PRLI *npr;
2704 lpfc_vpd_t *vpd;
2705 IOCB_t *icmd;
2706 IOCB_t *oldcmd;
2707 struct lpfc_iocbq *elsiocb;
2708 struct lpfc_sli_ring *pring;
2709 struct lpfc_sli *psli;
2710 uint8_t *pcmd;
2711 uint16_t cmdsize;
2712 int rc;
2713
2714 psli = &phba->sli;
2715 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
2716
James Smart92d7f7b2007-06-17 19:56:38 -05002717 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
James Smart2e0fef82007-06-17 19:56:36 -05002718 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
James Smart92d7f7b2007-06-17 19:56:38 -05002719 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002720 if (!elsiocb)
2721 return 1;
dea31012005-04-17 16:05:31 -05002722
dea31012005-04-17 16:05:31 -05002723 icmd = &elsiocb->iocb;
2724 oldcmd = &oldiocb->iocb;
2725 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04002726 /* Xmit PRLI ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04002727 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2728 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
2729 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
2730 elsiocb->iotag, elsiocb->iocb.ulpContext,
2731 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2732 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05002733 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2734
2735 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
James Smart92d7f7b2007-06-17 19:56:38 -05002736 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002737
2738 /* For PRLI, remainder of payload is PRLI parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05002739 memset(pcmd, 0, sizeof(PRLI));
dea31012005-04-17 16:05:31 -05002740
2741 npr = (PRLI *) pcmd;
2742 vpd = &phba->vpd;
2743 /*
2744 * If our firmware version is 3.20 or later,
2745 * set the following bits for FC-TAPE support.
2746 */
2747 if (vpd->rev.feaLevelHigh >= 0x02) {
2748 npr->ConfmComplAllowed = 1;
2749 npr->Retry = 1;
2750 npr->TaskRetryIdReq = 1;
2751 }
2752
2753 npr->acceptRspCode = PRLI_REQ_EXECUTED;
2754 npr->estabImagePair = 1;
2755 npr->readXferRdyDis = 1;
2756 npr->ConfmComplAllowed = 1;
2757
2758 npr->prliType = PRLI_FCP_TYPE;
2759 npr->initiatorFunc = 1;
2760
James Smart858c9f62007-06-17 19:56:39 -05002761 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2762 "Issue ACC PRLI: did:x%x flg:x%x",
2763 ndlp->nlp_DID, ndlp->nlp_flag, 0);
2764
dea31012005-04-17 16:05:31 -05002765 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05002766 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05002767
dea31012005-04-17 16:05:31 -05002768 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
dea31012005-04-17 16:05:31 -05002769 if (rc == IOCB_ERROR) {
2770 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002771 return 1;
dea31012005-04-17 16:05:31 -05002772 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002773 return 0;
dea31012005-04-17 16:05:31 -05002774}
2775
2776static int
James Smart2e0fef82007-06-17 19:56:36 -05002777lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
James Smart329f9bc2007-04-25 09:53:01 -04002778 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05002779{
James Smart2e0fef82007-06-17 19:56:36 -05002780 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002781 RNID *rn;
James Smart2e0fef82007-06-17 19:56:36 -05002782 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05002783 struct lpfc_iocbq *elsiocb;
2784 struct lpfc_sli_ring *pring;
2785 struct lpfc_sli *psli;
2786 uint8_t *pcmd;
2787 uint16_t cmdsize;
2788 int rc;
2789
2790 psli = &phba->sli;
2791 pring = &psli->ring[LPFC_ELS_RING];
2792
James Smart92d7f7b2007-06-17 19:56:38 -05002793 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
2794 + (2 * sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002795 if (format)
James Smart92d7f7b2007-06-17 19:56:38 -05002796 cmdsize += sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05002797
James Smart2e0fef82007-06-17 19:56:36 -05002798 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
2799 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05002800 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002801 return 1;
dea31012005-04-17 16:05:31 -05002802
dea31012005-04-17 16:05:31 -05002803 icmd = &elsiocb->iocb;
2804 oldcmd = &oldiocb->iocb;
2805 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04002806 /* Xmit RNID ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04002807 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2808 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
2809 elsiocb->iotag, elsiocb->iocb.ulpContext);
dea31012005-04-17 16:05:31 -05002810 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
dea31012005-04-17 16:05:31 -05002811 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05002812 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002813
James Smart92d7f7b2007-06-17 19:56:38 -05002814 memset(pcmd, 0, sizeof(RNID));
dea31012005-04-17 16:05:31 -05002815 rn = (RNID *) (pcmd);
2816 rn->Format = format;
James Smart92d7f7b2007-06-17 19:56:38 -05002817 rn->CommonLen = (2 * sizeof(struct lpfc_name));
2818 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
2819 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002820 switch (format) {
2821 case 0:
2822 rn->SpecificLen = 0;
2823 break;
2824 case RNID_TOPOLOGY_DISC:
James Smart92d7f7b2007-06-17 19:56:38 -05002825 rn->SpecificLen = sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05002826 memcpy(&rn->un.topologyDisc.portName,
James Smart92d7f7b2007-06-17 19:56:38 -05002827 &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002828 rn->un.topologyDisc.unitType = RNID_HBA;
2829 rn->un.topologyDisc.physPort = 0;
2830 rn->un.topologyDisc.attachedNodes = 0;
2831 break;
2832 default:
2833 rn->CommonLen = 0;
2834 rn->SpecificLen = 0;
2835 break;
2836 }
2837
James Smart858c9f62007-06-17 19:56:39 -05002838 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2839 "Issue ACC RNID: did:x%x flg:x%x",
2840 ndlp->nlp_DID, ndlp->nlp_flag, 0);
2841
dea31012005-04-17 16:05:31 -05002842 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05002843 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart329f9bc2007-04-25 09:53:01 -04002844 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002845 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
2846 * it could be freed */
2847
dea31012005-04-17 16:05:31 -05002848 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
dea31012005-04-17 16:05:31 -05002849 if (rc == IOCB_ERROR) {
2850 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002851 return 1;
dea31012005-04-17 16:05:31 -05002852 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002853 return 0;
dea31012005-04-17 16:05:31 -05002854}
2855
2856int
James Smart2e0fef82007-06-17 19:56:36 -05002857lpfc_els_disc_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002858{
James Smart2e0fef82007-06-17 19:56:36 -05002859 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002860 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05002861 int sentadisc = 0;
dea31012005-04-17 16:05:31 -05002862
James Smart685f0bf2007-04-25 09:53:08 -04002863 /* go thru NPR nodes and issue any remaining ELS ADISCs */
James Smart2e0fef82007-06-17 19:56:36 -05002864 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05002865 if (!NLP_CHK_NODE_ACT(ndlp))
2866 continue;
James Smart685f0bf2007-04-25 09:53:08 -04002867 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
2868 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
2869 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
James Smart2e0fef82007-06-17 19:56:36 -05002870 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04002871 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05002872 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04002873 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002874 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2875 lpfc_issue_els_adisc(vport, ndlp, 0);
James Smart685f0bf2007-04-25 09:53:08 -04002876 sentadisc++;
James Smart2e0fef82007-06-17 19:56:36 -05002877 vport->num_disc_nodes++;
2878 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04002879 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05002880 spin_lock_irq(shost->host_lock);
2881 vport->fc_flag |= FC_NLP_MORE;
2882 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04002883 break;
dea31012005-04-17 16:05:31 -05002884 }
2885 }
2886 }
2887 if (sentadisc == 0) {
James Smart2e0fef82007-06-17 19:56:36 -05002888 spin_lock_irq(shost->host_lock);
2889 vport->fc_flag &= ~FC_NLP_MORE;
2890 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002891 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002892 return sentadisc;
dea31012005-04-17 16:05:31 -05002893}
2894
2895int
James Smart2e0fef82007-06-17 19:56:36 -05002896lpfc_els_disc_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002897{
James Smart2e0fef82007-06-17 19:56:36 -05002898 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002899 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05002900 int sentplogi = 0;
dea31012005-04-17 16:05:31 -05002901
James Smart2e0fef82007-06-17 19:56:36 -05002902 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
2903 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05002904 if (!NLP_CHK_NODE_ACT(ndlp))
2905 continue;
James Smart685f0bf2007-04-25 09:53:08 -04002906 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
2907 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
2908 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
2909 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
2910 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002911 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
2912 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
James Smart685f0bf2007-04-25 09:53:08 -04002913 sentplogi++;
James Smart2e0fef82007-06-17 19:56:36 -05002914 vport->num_disc_nodes++;
2915 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04002916 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05002917 spin_lock_irq(shost->host_lock);
2918 vport->fc_flag |= FC_NLP_MORE;
2919 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04002920 break;
dea31012005-04-17 16:05:31 -05002921 }
2922 }
2923 }
James Smart87af33f2007-10-27 13:37:43 -04002924 if (sentplogi) {
2925 lpfc_set_disctmo(vport);
2926 }
2927 else {
James Smart2e0fef82007-06-17 19:56:36 -05002928 spin_lock_irq(shost->host_lock);
2929 vport->fc_flag &= ~FC_NLP_MORE;
2930 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002931 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002932 return sentplogi;
dea31012005-04-17 16:05:31 -05002933}
2934
James Smart92d7f7b2007-06-17 19:56:38 -05002935void
James Smart2e0fef82007-06-17 19:56:36 -05002936lpfc_els_flush_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002937{
James Smart2e0fef82007-06-17 19:56:36 -05002938 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2939 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002940 int i;
2941
James Smart7f5f3d02008-02-08 18:50:14 -05002942 spin_lock_irq(shost->host_lock);
2943 if (vport->fc_rscn_flush) {
2944 /* Another thread is walking fc_rscn_id_list on this vport */
2945 spin_unlock_irq(shost->host_lock);
2946 return;
2947 }
2948 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
2949 vport->fc_rscn_flush = 1;
2950 spin_unlock_irq(shost->host_lock);
2951
James Smart2e0fef82007-06-17 19:56:36 -05002952 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05002953 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
James Smart2e0fef82007-06-17 19:56:36 -05002954 vport->fc_rscn_id_list[i] = NULL;
dea31012005-04-17 16:05:31 -05002955 }
James Smart2e0fef82007-06-17 19:56:36 -05002956 spin_lock_irq(shost->host_lock);
2957 vport->fc_rscn_id_cnt = 0;
2958 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
2959 spin_unlock_irq(shost->host_lock);
2960 lpfc_can_disctmo(vport);
James Smart7f5f3d02008-02-08 18:50:14 -05002961 /* Indicate we are done walking this fc_rscn_id_list */
2962 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05002963}
2964
2965int
James Smart2e0fef82007-06-17 19:56:36 -05002966lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05002967{
2968 D_ID ns_did;
2969 D_ID rscn_did;
dea31012005-04-17 16:05:31 -05002970 uint32_t *lp;
James Smart92d7f7b2007-06-17 19:56:38 -05002971 uint32_t payload_len, i;
James Smart7f5f3d02008-02-08 18:50:14 -05002972 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002973
2974 ns_did.un.word = did;
dea31012005-04-17 16:05:31 -05002975
2976 /* Never match fabric nodes for RSCNs */
2977 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
James Smart2e0fef82007-06-17 19:56:36 -05002978 return 0;
dea31012005-04-17 16:05:31 -05002979
2980 /* If we are doing a FULL RSCN rediscovery, match everything */
James Smart2e0fef82007-06-17 19:56:36 -05002981 if (vport->fc_flag & FC_RSCN_DISCOVERY)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002982 return did;
dea31012005-04-17 16:05:31 -05002983
James Smart7f5f3d02008-02-08 18:50:14 -05002984 spin_lock_irq(shost->host_lock);
2985 if (vport->fc_rscn_flush) {
2986 /* Another thread is walking fc_rscn_id_list on this vport */
2987 spin_unlock_irq(shost->host_lock);
2988 return 0;
2989 }
2990 /* Indicate we are walking fc_rscn_id_list on this vport */
2991 vport->fc_rscn_flush = 1;
2992 spin_unlock_irq(shost->host_lock);
James Smart2e0fef82007-06-17 19:56:36 -05002993 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05002994 lp = vport->fc_rscn_id_list[i]->virt;
2995 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
2996 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05002997 while (payload_len) {
James Smart92d7f7b2007-06-17 19:56:38 -05002998 rscn_did.un.word = be32_to_cpu(*lp++);
2999 payload_len -= sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003000 switch (rscn_did.un.b.resv) {
3001 case 0: /* Single N_Port ID effected */
James Smart2e0fef82007-06-17 19:56:36 -05003002 if (ns_did.un.word == rscn_did.un.word)
James Smart7f5f3d02008-02-08 18:50:14 -05003003 goto return_did_out;
dea31012005-04-17 16:05:31 -05003004 break;
3005 case 1: /* Whole N_Port Area effected */
3006 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
3007 && (ns_did.un.b.area == rscn_did.un.b.area))
James Smart7f5f3d02008-02-08 18:50:14 -05003008 goto return_did_out;
dea31012005-04-17 16:05:31 -05003009 break;
3010 case 2: /* Whole N_Port Domain effected */
3011 if (ns_did.un.b.domain == rscn_did.un.b.domain)
James Smart7f5f3d02008-02-08 18:50:14 -05003012 goto return_did_out;
dea31012005-04-17 16:05:31 -05003013 break;
3014 default:
James Smart2e0fef82007-06-17 19:56:36 -05003015 /* Unknown Identifier in RSCN node */
James Smarte8b62012007-08-02 11:10:09 -04003016 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
3017 "0217 Unknown Identifier in "
3018 "RSCN payload Data: x%x\n",
3019 rscn_did.un.word);
James Smart92d7f7b2007-06-17 19:56:38 -05003020 case 3: /* Whole Fabric effected */
James Smart7f5f3d02008-02-08 18:50:14 -05003021 goto return_did_out;
dea31012005-04-17 16:05:31 -05003022 }
3023 }
James Smart92d7f7b2007-06-17 19:56:38 -05003024 }
James Smart7f5f3d02008-02-08 18:50:14 -05003025 /* Indicate we are done with walking fc_rscn_id_list on this vport */
3026 vport->fc_rscn_flush = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05003027 return 0;
James Smart7f5f3d02008-02-08 18:50:14 -05003028return_did_out:
3029 /* Indicate we are done with walking fc_rscn_id_list on this vport */
3030 vport->fc_rscn_flush = 0;
3031 return did;
dea31012005-04-17 16:05:31 -05003032}
3033
3034static int
James Smart2e0fef82007-06-17 19:56:36 -05003035lpfc_rscn_recovery_check(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003036{
James Smart685f0bf2007-04-25 09:53:08 -04003037 struct lpfc_nodelist *ndlp = NULL;
dea31012005-04-17 16:05:31 -05003038
3039 /* Look at all nodes effected by pending RSCNs and move
James Smart685f0bf2007-04-25 09:53:08 -04003040 * them to NPR state.
dea31012005-04-17 16:05:31 -05003041 */
James Smart685f0bf2007-04-25 09:53:08 -04003042
James Smart2e0fef82007-06-17 19:56:36 -05003043 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05003044 if (!NLP_CHK_NODE_ACT(ndlp) ||
3045 ndlp->nlp_state == NLP_STE_UNUSED_NODE ||
James Smart2e0fef82007-06-17 19:56:36 -05003046 lpfc_rscn_payload_check(vport, ndlp->nlp_DID) == 0)
dea31012005-04-17 16:05:31 -05003047 continue;
3048
James Smart2e0fef82007-06-17 19:56:36 -05003049 lpfc_disc_state_machine(vport, ndlp, NULL,
James Smart92d7f7b2007-06-17 19:56:38 -05003050 NLP_EVT_DEVICE_RECOVERY);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003051
James Smart685f0bf2007-04-25 09:53:08 -04003052 /*
3053 * Make sure NLP_DELAY_TMO is NOT running after a device
3054 * recovery event.
3055 */
3056 if (ndlp->nlp_flag & NLP_DELAY_TMO)
James Smart2e0fef82007-06-17 19:56:36 -05003057 lpfc_cancel_retry_delay_tmo(vport, ndlp);
dea31012005-04-17 16:05:31 -05003058 }
James Smart685f0bf2007-04-25 09:53:08 -04003059
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003060 return 0;
dea31012005-04-17 16:05:31 -05003061}
3062
3063static int
James Smart2e0fef82007-06-17 19:56:36 -05003064lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04003065 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003066{
James Smart2e0fef82007-06-17 19:56:36 -05003067 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3068 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003069 struct lpfc_dmabuf *pcmd;
James Smart92d7f7b2007-06-17 19:56:38 -05003070 uint32_t *lp, *datap;
dea31012005-04-17 16:05:31 -05003071 IOCB_t *icmd;
James Smart92d7f7b2007-06-17 19:56:38 -05003072 uint32_t payload_len, length, nportid, *cmd;
James Smart7f5f3d02008-02-08 18:50:14 -05003073 int rscn_cnt;
James Smart92d7f7b2007-06-17 19:56:38 -05003074 int rscn_id = 0, hba_id = 0;
James Smartd2873e42006-08-18 17:46:43 -04003075 int i;
dea31012005-04-17 16:05:31 -05003076
3077 icmd = &cmdiocb->iocb;
3078 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3079 lp = (uint32_t *) pcmd->virt;
3080
James Smart92d7f7b2007-06-17 19:56:38 -05003081 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
3082 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05003083 /* RSCN received */
James Smarte8b62012007-08-02 11:10:09 -04003084 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3085 "0214 RSCN received Data: x%x x%x x%x x%x\n",
James Smart7f5f3d02008-02-08 18:50:14 -05003086 vport->fc_flag, payload_len, *lp,
3087 vport->fc_rscn_id_cnt);
James Smartd2873e42006-08-18 17:46:43 -04003088 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
James Smart2e0fef82007-06-17 19:56:36 -05003089 fc_host_post_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04003090 FCH_EVT_RSCN, lp[i]);
3091
dea31012005-04-17 16:05:31 -05003092 /* If we are about to begin discovery, just ACC the RSCN.
3093 * Discovery processing will satisfy it.
3094 */
James Smart2e0fef82007-06-17 19:56:36 -05003095 if (vport->port_state <= LPFC_NS_QRY) {
James Smart858c9f62007-06-17 19:56:39 -05003096 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3097 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
3098 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
3099
James Smart51ef4c22007-08-02 11:10:31 -04003100 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003101 return 0;
dea31012005-04-17 16:05:31 -05003102 }
3103
James Smart92d7f7b2007-06-17 19:56:38 -05003104 /* If this RSCN just contains NPortIDs for other vports on this HBA,
3105 * just ACC and ignore it.
3106 */
3107 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart3de2a652007-08-02 11:09:59 -04003108 !(vport->cfg_peer_port_login)) {
James Smart92d7f7b2007-06-17 19:56:38 -05003109 i = payload_len;
3110 datap = lp;
3111 while (i > 0) {
3112 nportid = *datap++;
3113 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
3114 i -= sizeof(uint32_t);
3115 rscn_id++;
James Smart549e55c2007-08-02 11:09:51 -04003116 if (lpfc_find_vport_by_did(phba, nportid))
3117 hba_id++;
James Smart92d7f7b2007-06-17 19:56:38 -05003118 }
3119 if (rscn_id == hba_id) {
3120 /* ALL NPortIDs in RSCN are on HBA */
James Smarte8b62012007-08-02 11:10:09 -04003121 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3122 "0214 Ignore RSCN "
3123 "Data: x%x x%x x%x x%x\n",
3124 vport->fc_flag, payload_len,
James Smart7f5f3d02008-02-08 18:50:14 -05003125 *lp, vport->fc_rscn_id_cnt);
James Smart858c9f62007-06-17 19:56:39 -05003126 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3127 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
3128 ndlp->nlp_DID, vport->port_state,
3129 ndlp->nlp_flag);
3130
James Smart92d7f7b2007-06-17 19:56:38 -05003131 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04003132 ndlp, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05003133 return 0;
3134 }
3135 }
3136
James Smart7f5f3d02008-02-08 18:50:14 -05003137 spin_lock_irq(shost->host_lock);
3138 if (vport->fc_rscn_flush) {
3139 /* Another thread is walking fc_rscn_id_list on this vport */
3140 spin_unlock_irq(shost->host_lock);
3141 vport->fc_flag |= FC_RSCN_DISCOVERY;
3142 return 0;
3143 }
3144 /* Indicate we are walking fc_rscn_id_list on this vport */
3145 vport->fc_rscn_flush = 1;
3146 spin_unlock_irq(shost->host_lock);
3147 /* Get the array count after sucessfully have the token */
3148 rscn_cnt = vport->fc_rscn_id_cnt;
dea31012005-04-17 16:05:31 -05003149 /* If we are already processing an RSCN, save the received
3150 * RSCN payload buffer, cmdiocb->context2 to process later.
3151 */
James Smart2e0fef82007-06-17 19:56:36 -05003152 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
James Smart858c9f62007-06-17 19:56:39 -05003153 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3154 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
3155 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
3156
James Smart09372822008-01-11 01:52:54 -05003157 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05003158 vport->fc_flag |= FC_RSCN_DEFERRED;
3159 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
James Smart2e0fef82007-06-17 19:56:36 -05003160 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
James Smart2e0fef82007-06-17 19:56:36 -05003161 vport->fc_flag |= FC_RSCN_MODE;
3162 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05003163 if (rscn_cnt) {
3164 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
3165 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
3166 }
3167 if ((rscn_cnt) &&
3168 (payload_len + length <= LPFC_BPL_SIZE)) {
3169 *cmd &= ELS_CMD_MASK;
James Smart7f5f3d02008-02-08 18:50:14 -05003170 *cmd |= cpu_to_be32(payload_len + length);
James Smart92d7f7b2007-06-17 19:56:38 -05003171 memcpy(((uint8_t *)cmd) + length, lp,
3172 payload_len);
3173 } else {
3174 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
3175 vport->fc_rscn_id_cnt++;
3176 /* If we zero, cmdiocb->context2, the calling
3177 * routine will not try to free it.
3178 */
3179 cmdiocb->context2 = NULL;
3180 }
dea31012005-04-17 16:05:31 -05003181 /* Deferred RSCN */
James Smarte8b62012007-08-02 11:10:09 -04003182 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3183 "0235 Deferred RSCN "
3184 "Data: x%x x%x x%x\n",
3185 vport->fc_rscn_id_cnt, vport->fc_flag,
3186 vport->port_state);
dea31012005-04-17 16:05:31 -05003187 } else {
James Smart2e0fef82007-06-17 19:56:36 -05003188 vport->fc_flag |= FC_RSCN_DISCOVERY;
3189 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003190 /* ReDiscovery RSCN */
James Smarte8b62012007-08-02 11:10:09 -04003191 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3192 "0234 ReDiscovery RSCN "
3193 "Data: x%x x%x x%x\n",
3194 vport->fc_rscn_id_cnt, vport->fc_flag,
3195 vport->port_state);
dea31012005-04-17 16:05:31 -05003196 }
James Smart7f5f3d02008-02-08 18:50:14 -05003197 /* Indicate we are done walking fc_rscn_id_list on this vport */
3198 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05003199 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04003200 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05003201 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05003202 lpfc_rscn_recovery_check(vport);
James Smart09372822008-01-11 01:52:54 -05003203 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05003204 vport->fc_flag &= ~FC_RSCN_DEFERRED;
James Smart09372822008-01-11 01:52:54 -05003205 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003206 return 0;
dea31012005-04-17 16:05:31 -05003207 }
James Smart858c9f62007-06-17 19:56:39 -05003208 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3209 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
3210 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
3211
James Smart2e0fef82007-06-17 19:56:36 -05003212 spin_lock_irq(shost->host_lock);
3213 vport->fc_flag |= FC_RSCN_MODE;
3214 spin_unlock_irq(shost->host_lock);
3215 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
James Smart7f5f3d02008-02-08 18:50:14 -05003216 /* Indicate we are done walking fc_rscn_id_list on this vport */
3217 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05003218 /*
3219 * If we zero, cmdiocb->context2, the calling routine will
3220 * not try to free it.
3221 */
3222 cmdiocb->context2 = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05003223 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05003224 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04003225 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05003226 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05003227 lpfc_rscn_recovery_check(vport);
James Smart2e0fef82007-06-17 19:56:36 -05003228 return lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05003229}
3230
3231int
James Smart2e0fef82007-06-17 19:56:36 -05003232lpfc_els_handle_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003233{
3234 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05003235 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003236
James Smart92d7f7b2007-06-17 19:56:38 -05003237 /* Ignore RSCN if the port is being torn down. */
3238 if (vport->load_flag & FC_UNLOADING) {
3239 lpfc_els_flush_rscn(vport);
3240 return 0;
3241 }
3242
dea31012005-04-17 16:05:31 -05003243 /* Start timer for RSCN processing */
James Smart2e0fef82007-06-17 19:56:36 -05003244 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05003245
3246 /* RSCN processed */
James Smarte8b62012007-08-02 11:10:09 -04003247 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3248 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
3249 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
3250 vport->port_state);
dea31012005-04-17 16:05:31 -05003251
3252 /* To process RSCN, first compare RSCN data with NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05003253 vport->fc_ns_retry = 0;
James Smart0ff10d42008-01-11 01:52:36 -05003254 vport->num_disc_nodes = 0;
3255
James Smart2e0fef82007-06-17 19:56:36 -05003256 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05003257 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
3258 && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
dea31012005-04-17 16:05:31 -05003259 /* Good ndlp, issue CT Request to NameServer */
James Smart92d7f7b2007-06-17 19:56:38 -05003260 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
dea31012005-04-17 16:05:31 -05003261 /* Wait for NameServer query cmpl before we can
3262 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003263 return 1;
dea31012005-04-17 16:05:31 -05003264 } else {
3265 /* If login to NameServer does not exist, issue one */
3266 /* Good status, issue PLOGI to NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05003267 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05003268 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
dea31012005-04-17 16:05:31 -05003269 /* Wait for NameServer login cmpl before we can
3270 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003271 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05003272
James Smarte47c9092008-02-08 18:49:26 -05003273 if (ndlp) {
3274 ndlp = lpfc_enable_node(vport, ndlp,
3275 NLP_STE_PLOGI_ISSUE);
3276 if (!ndlp) {
3277 lpfc_els_flush_rscn(vport);
3278 return 0;
3279 }
3280 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
dea31012005-04-17 16:05:31 -05003281 } else {
James Smarte47c9092008-02-08 18:49:26 -05003282 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
3283 if (!ndlp) {
3284 lpfc_els_flush_rscn(vport);
3285 return 0;
3286 }
James Smart2e0fef82007-06-17 19:56:36 -05003287 lpfc_nlp_init(vport, ndlp, NameServer_DID);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003288 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003289 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
dea31012005-04-17 16:05:31 -05003290 }
James Smarte47c9092008-02-08 18:49:26 -05003291 ndlp->nlp_type |= NLP_FABRIC;
3292 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
3293 /* Wait for NameServer login cmpl before we can
3294 * continue
3295 */
3296 return 1;
dea31012005-04-17 16:05:31 -05003297 }
3298
James Smart2e0fef82007-06-17 19:56:36 -05003299 lpfc_els_flush_rscn(vport);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003300 return 0;
dea31012005-04-17 16:05:31 -05003301}
3302
3303static int
James Smart2e0fef82007-06-17 19:56:36 -05003304lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04003305 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003306{
James Smart2e0fef82007-06-17 19:56:36 -05003307 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3308 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003309 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3310 uint32_t *lp = (uint32_t *) pcmd->virt;
3311 IOCB_t *icmd = &cmdiocb->iocb;
3312 struct serv_parm *sp;
3313 LPFC_MBOXQ_t *mbox;
3314 struct ls_rjt stat;
3315 uint32_t cmd, did;
3316 int rc;
3317
3318 cmd = *lp++;
3319 sp = (struct serv_parm *) lp;
3320
3321 /* FLOGI received */
3322
James Smart2e0fef82007-06-17 19:56:36 -05003323 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05003324
3325 if (phba->fc_topology == TOPOLOGY_LOOP) {
3326 /* We should never receive a FLOGI in loop mode, ignore it */
3327 did = icmd->un.elsreq64.remoteID;
3328
3329 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
3330 Loop Mode */
James Smarte8b62012007-08-02 11:10:09 -04003331 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3332 "0113 An FLOGI ELS command x%x was "
3333 "received from DID x%x in Loop Mode\n",
3334 cmd, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003335 return 1;
dea31012005-04-17 16:05:31 -05003336 }
3337
3338 did = Fabric_DID;
3339
James Smart2e0fef82007-06-17 19:56:36 -05003340 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3))) {
dea31012005-04-17 16:05:31 -05003341 /* For a FLOGI we accept, then if our portname is greater
3342 * then the remote portname we initiate Nport login.
3343 */
3344
James Smart2e0fef82007-06-17 19:56:36 -05003345 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -05003346 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003347
3348 if (!rc) {
James Smart2e0fef82007-06-17 19:56:36 -05003349 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3350 if (!mbox)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003351 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05003352
dea31012005-04-17 16:05:31 -05003353 lpfc_linkdown(phba);
3354 lpfc_init_link(phba, mbox,
3355 phba->cfg_topology,
3356 phba->cfg_link_speed);
3357 mbox->mb.un.varInitLnk.lipsr_AL_PA = 0;
3358 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -05003359 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -04003360 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart5b8bd0c2007-04-25 09:52:49 -04003361 lpfc_set_loopback_flag(phba);
dea31012005-04-17 16:05:31 -05003362 if (rc == MBX_NOT_FINISHED) {
James Smart329f9bc2007-04-25 09:53:01 -04003363 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003364 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003365 return 1;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003366 } else if (rc > 0) { /* greater than */
James Smart2e0fef82007-06-17 19:56:36 -05003367 spin_lock_irq(shost->host_lock);
3368 vport->fc_flag |= FC_PT2PT_PLOGI;
3369 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003370 }
James Smart2e0fef82007-06-17 19:56:36 -05003371 spin_lock_irq(shost->host_lock);
3372 vport->fc_flag |= FC_PT2PT;
3373 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
3374 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003375 } else {
3376 /* Reject this request because invalid parameters */
3377 stat.un.b.lsRjtRsvd0 = 0;
3378 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3379 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
3380 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05003381 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
3382 NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003383 return 1;
dea31012005-04-17 16:05:31 -05003384 }
3385
3386 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04003387 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05003388
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003389 return 0;
dea31012005-04-17 16:05:31 -05003390}
3391
3392static int
James Smart2e0fef82007-06-17 19:56:36 -05003393lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3394 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003395{
3396 struct lpfc_dmabuf *pcmd;
3397 uint32_t *lp;
3398 IOCB_t *icmd;
3399 RNID *rn;
3400 struct ls_rjt stat;
3401 uint32_t cmd, did;
3402
3403 icmd = &cmdiocb->iocb;
3404 did = icmd->un.elsreq64.remoteID;
3405 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3406 lp = (uint32_t *) pcmd->virt;
3407
3408 cmd = *lp++;
3409 rn = (RNID *) lp;
3410
3411 /* RNID received */
3412
3413 switch (rn->Format) {
3414 case 0:
3415 case RNID_TOPOLOGY_DISC:
3416 /* Send back ACC */
James Smart2e0fef82007-06-17 19:56:36 -05003417 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05003418 break;
3419 default:
3420 /* Reject this request because format not supported */
3421 stat.un.b.lsRjtRsvd0 = 0;
3422 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3423 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
3424 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05003425 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
3426 NULL);
dea31012005-04-17 16:05:31 -05003427 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003428 return 0;
dea31012005-04-17 16:05:31 -05003429}
3430
3431static int
James Smart2e0fef82007-06-17 19:56:36 -05003432lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3433 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003434{
3435 struct ls_rjt stat;
3436
3437 /* For now, unconditionally reject this command */
3438 stat.un.b.lsRjtRsvd0 = 0;
3439 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3440 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
3441 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05003442 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003443 return 0;
3444}
3445
Jamie Wellnitz082c0262006-02-28 19:25:30 -05003446static void
James Smart329f9bc2007-04-25 09:53:01 -04003447lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003448{
James Smart2e0fef82007-06-17 19:56:36 -05003449 struct lpfc_sli *psli = &phba->sli;
3450 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003451 MAILBOX_t *mb;
3452 IOCB_t *icmd;
3453 RPS_RSP *rps_rsp;
3454 uint8_t *pcmd;
3455 struct lpfc_iocbq *elsiocb;
3456 struct lpfc_nodelist *ndlp;
3457 uint16_t xri, status;
3458 uint32_t cmdsize;
3459
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003460 mb = &pmb->mb;
3461
3462 ndlp = (struct lpfc_nodelist *) pmb->context2;
3463 xri = (uint16_t) ((unsigned long)(pmb->context1));
Randy Dunlap041976f2006-06-25 01:58:51 -07003464 pmb->context1 = NULL;
3465 pmb->context2 = NULL;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003466
3467 if (mb->mbxStatus) {
James Smart329f9bc2007-04-25 09:53:01 -04003468 mempool_free(pmb, phba->mbox_mem_pool);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003469 return;
3470 }
3471
3472 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
James Smart329f9bc2007-04-25 09:53:01 -04003473 mempool_free(pmb, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05003474 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
3475 lpfc_max_els_tries, ndlp,
3476 ndlp->nlp_DID, ELS_CMD_ACC);
James Smartfa4066b2008-01-11 01:53:27 -05003477
3478 /* Decrement the ndlp reference count from previous mbox command */
James Smart329f9bc2007-04-25 09:53:01 -04003479 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05003480
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003481 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003482 return;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003483
3484 icmd = &elsiocb->iocb;
3485 icmd->ulpContext = xri;
3486
3487 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3488 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003489 pcmd += sizeof(uint32_t); /* Skip past command */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003490 rps_rsp = (RPS_RSP *)pcmd;
3491
3492 if (phba->fc_topology != TOPOLOGY_LOOP)
3493 status = 0x10;
3494 else
3495 status = 0x8;
James Smart2e0fef82007-06-17 19:56:36 -05003496 if (phba->pport->fc_flag & FC_FABRIC)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003497 status |= 0x4;
3498
3499 rps_rsp->rsvd1 = 0;
James Smart09372822008-01-11 01:52:54 -05003500 rps_rsp->portStatus = cpu_to_be16(status);
3501 rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
3502 rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
3503 rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
3504 rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
3505 rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
3506 rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003507 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003508 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
3509 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
3510 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
3511 elsiocb->iotag, elsiocb->iocb.ulpContext,
3512 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3513 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05003514 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003515 phba->fc_stat.elsXmitACC++;
James Smarted957682007-06-17 19:56:37 -05003516 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003517 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003518 return;
3519}
3520
3521static int
James Smart2e0fef82007-06-17 19:56:36 -05003522lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3523 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003524{
James Smart2e0fef82007-06-17 19:56:36 -05003525 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003526 uint32_t *lp;
3527 uint8_t flag;
3528 LPFC_MBOXQ_t *mbox;
3529 struct lpfc_dmabuf *pcmd;
3530 RPS *rps;
3531 struct ls_rjt stat;
3532
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003533 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
3534 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003535 stat.un.b.lsRjtRsvd0 = 0;
3536 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3537 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
3538 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05003539 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
3540 NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003541 }
3542
3543 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3544 lp = (uint32_t *) pcmd->virt;
3545 flag = (be32_to_cpu(*lp++) & 0xf);
3546 rps = (RPS *) lp;
3547
3548 if ((flag == 0) ||
3549 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
James Smart2e0fef82007-06-17 19:56:36 -05003550 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05003551 sizeof(struct lpfc_name)) == 0))) {
James Smart2e0fef82007-06-17 19:56:36 -05003552
James Smart92d7f7b2007-06-17 19:56:38 -05003553 printk("Fix me....\n");
3554 dump_stack();
James Smart2e0fef82007-06-17 19:56:36 -05003555 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
3556 if (mbox) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003557 lpfc_read_lnk_stat(phba, mbox);
3558 mbox->context1 =
James Smart92d7f7b2007-06-17 19:56:38 -05003559 (void *)((unsigned long) cmdiocb->iocb.ulpContext);
James Smart329f9bc2007-04-25 09:53:01 -04003560 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05003561 mbox->vport = vport;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003562 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
James Smartfa4066b2008-01-11 01:53:27 -05003563 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart0b727fe2007-10-27 13:37:25 -04003564 != MBX_NOT_FINISHED)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003565 /* Mbox completion will send ELS Response */
3566 return 0;
James Smartfa4066b2008-01-11 01:53:27 -05003567 /* Decrement reference count used for the failed mbox
3568 * command.
3569 */
James Smart329f9bc2007-04-25 09:53:01 -04003570 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003571 mempool_free(mbox, phba->mbox_mem_pool);
3572 }
3573 }
3574 stat.un.b.lsRjtRsvd0 = 0;
3575 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3576 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
3577 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05003578 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003579 return 0;
3580}
3581
Jamie Wellnitz082c0262006-02-28 19:25:30 -05003582static int
James Smart2e0fef82007-06-17 19:56:36 -05003583lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
3584 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003585{
James Smart2e0fef82007-06-17 19:56:36 -05003586 struct lpfc_hba *phba = vport->phba;
3587 IOCB_t *icmd, *oldcmd;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003588 RPL_RSP rpl_rsp;
3589 struct lpfc_iocbq *elsiocb;
James Smart2e0fef82007-06-17 19:56:36 -05003590 struct lpfc_sli *psli = &phba->sli;
3591 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003592 uint8_t *pcmd;
3593
James Smart2e0fef82007-06-17 19:56:36 -05003594 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3595 ndlp->nlp_DID, ELS_CMD_ACC);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003596
James Smart488d1462006-03-07 15:02:37 -05003597 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003598 return 1;
James Smart488d1462006-03-07 15:02:37 -05003599
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003600 icmd = &elsiocb->iocb;
3601 oldcmd = &oldiocb->iocb;
3602 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3603
3604 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3605 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003606 pcmd += sizeof(uint16_t);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003607 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
3608 pcmd += sizeof(uint16_t);
3609
3610 /* Setup the RPL ACC payload */
3611 rpl_rsp.listLen = be32_to_cpu(1);
3612 rpl_rsp.index = 0;
3613 rpl_rsp.port_num_blk.portNum = 0;
James Smart2e0fef82007-06-17 19:56:36 -05003614 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
3615 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003616 sizeof(struct lpfc_name));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003617 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003618 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003619 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3620 "0120 Xmit ELS RPL ACC response tag x%x "
3621 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
3622 "rpi x%x\n",
3623 elsiocb->iotag, elsiocb->iocb.ulpContext,
3624 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3625 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05003626 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003627 phba->fc_stat.elsXmitACC++;
3628 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
3629 lpfc_els_free_iocb(phba, elsiocb);
3630 return 1;
3631 }
3632 return 0;
3633}
3634
3635static int
James Smart2e0fef82007-06-17 19:56:36 -05003636lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3637 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003638{
3639 struct lpfc_dmabuf *pcmd;
3640 uint32_t *lp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003641 uint32_t maxsize;
3642 uint16_t cmdsize;
3643 RPL *rpl;
3644 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05003645
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003646 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
3647 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003648 stat.un.b.lsRjtRsvd0 = 0;
3649 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
3650 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
3651 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05003652 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
3653 NULL);
dea31012005-04-17 16:05:31 -05003654 }
3655
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003656 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3657 lp = (uint32_t *) pcmd->virt;
3658 rpl = (RPL *) (lp + 1);
3659
3660 maxsize = be32_to_cpu(rpl->maxsize);
3661
3662 /* We support only one port */
3663 if ((rpl->index == 0) &&
3664 ((maxsize == 0) ||
3665 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
3666 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003667 } else {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05003668 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
3669 }
James Smart2e0fef82007-06-17 19:56:36 -05003670 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05003671
3672 return 0;
3673}
3674
3675static int
James Smart2e0fef82007-06-17 19:56:36 -05003676lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3677 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003678{
3679 struct lpfc_dmabuf *pcmd;
3680 uint32_t *lp;
3681 IOCB_t *icmd;
3682 FARP *fp;
3683 uint32_t cmd, cnt, did;
3684
3685 icmd = &cmdiocb->iocb;
3686 did = icmd->un.elsreq64.remoteID;
3687 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3688 lp = (uint32_t *) pcmd->virt;
3689
3690 cmd = *lp++;
3691 fp = (FARP *) lp;
dea31012005-04-17 16:05:31 -05003692 /* FARP-REQ received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04003693 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3694 "0601 FARP-REQ received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05003695 /* We will only support match on WWPN or WWNN */
3696 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003697 return 0;
dea31012005-04-17 16:05:31 -05003698 }
3699
3700 cnt = 0;
3701 /* If this FARP command is searching for my portname */
3702 if (fp->Mflags & FARP_MATCH_PORT) {
James Smart2e0fef82007-06-17 19:56:36 -05003703 if (memcmp(&fp->RportName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05003704 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05003705 cnt = 1;
3706 }
3707
3708 /* If this FARP command is searching for my nodename */
3709 if (fp->Mflags & FARP_MATCH_NODE) {
James Smart2e0fef82007-06-17 19:56:36 -05003710 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05003711 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05003712 cnt = 1;
3713 }
3714
3715 if (cnt) {
3716 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
3717 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
3718 /* Log back into the node before sending the FARP. */
3719 if (fp->Rflags & FARP_REQUEST_PLOGI) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003720 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003721 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04003722 NLP_STE_PLOGI_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05003723 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05003724 }
3725
3726 /* Send a FARP response to that node */
James Smart2e0fef82007-06-17 19:56:36 -05003727 if (fp->Rflags & FARP_REQUEST_FARPR)
3728 lpfc_issue_els_farpr(vport, did, 0);
dea31012005-04-17 16:05:31 -05003729 }
3730 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003731 return 0;
dea31012005-04-17 16:05:31 -05003732}
3733
3734static int
James Smart2e0fef82007-06-17 19:56:36 -05003735lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3736 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003737{
3738 struct lpfc_dmabuf *pcmd;
3739 uint32_t *lp;
3740 IOCB_t *icmd;
3741 uint32_t cmd, did;
3742
3743 icmd = &cmdiocb->iocb;
3744 did = icmd->un.elsreq64.remoteID;
3745 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3746 lp = (uint32_t *) pcmd->virt;
3747
3748 cmd = *lp++;
3749 /* FARP-RSP received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04003750 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3751 "0600 FARP-RSP received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05003752 /* ACCEPT the Farp resp request */
James Smart51ef4c22007-08-02 11:10:31 -04003753 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05003754
3755 return 0;
3756}
3757
3758static int
James Smart2e0fef82007-06-17 19:56:36 -05003759lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
3760 struct lpfc_nodelist *fan_ndlp)
dea31012005-04-17 16:05:31 -05003761{
3762 struct lpfc_dmabuf *pcmd;
3763 uint32_t *lp;
3764 IOCB_t *icmd;
dea31012005-04-17 16:05:31 -05003765 uint32_t cmd, did;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003766 FAN *fp;
3767 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05003768 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003769
3770 /* FAN received */
James Smarte8b62012007-08-02 11:10:09 -04003771 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3772 "0265 FAN received\n");
dea31012005-04-17 16:05:31 -05003773 icmd = &cmdiocb->iocb;
3774 did = icmd->un.elsreq64.remoteID;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003775 pcmd = (struct lpfc_dmabuf *)cmdiocb->context2;
3776 lp = (uint32_t *)pcmd->virt;
dea31012005-04-17 16:05:31 -05003777
3778 cmd = *lp++;
James Smart92d7f7b2007-06-17 19:56:38 -05003779 fp = (FAN *) lp;
dea31012005-04-17 16:05:31 -05003780
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003781 /* FAN received; Fan does not have a reply sequence */
dea31012005-04-17 16:05:31 -05003782
James Smart2e0fef82007-06-17 19:56:36 -05003783 if (phba->pport->port_state == LPFC_LOCAL_CFG_LINK) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003784 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
3785 sizeof(struct lpfc_name)) != 0) ||
3786 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
3787 sizeof(struct lpfc_name)) != 0)) {
3788 /*
3789 * This node has switched fabrics. FLOGI is required
3790 * Clean up the old rpi's
dea31012005-04-17 16:05:31 -05003791 */
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003792
3793 list_for_each_entry_safe(ndlp, next_ndlp,
James Smart2e0fef82007-06-17 19:56:36 -05003794 &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05003795 if (!NLP_CHK_NODE_ACT(ndlp))
3796 continue;
James Smart685f0bf2007-04-25 09:53:08 -04003797 if (ndlp->nlp_state != NLP_STE_NPR_NODE)
3798 continue;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003799 if (ndlp->nlp_type & NLP_FABRIC) {
3800 /*
3801 * Clean up old Fabric, Nameserver and
3802 * other NLP_FABRIC logins
3803 */
James Smart2e0fef82007-06-17 19:56:36 -05003804 lpfc_drop_node(vport, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04003805
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003806 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003807 /* Fail outstanding I/O now since this
3808 * device is marked for PLOGI
3809 */
James Smart2e0fef82007-06-17 19:56:36 -05003810 lpfc_unreg_rpi(vport, ndlp);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003811 }
3812 }
3813
James Smart2e0fef82007-06-17 19:56:36 -05003814 lpfc_initial_flogi(vport);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003815 return 0;
dea31012005-04-17 16:05:31 -05003816 }
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003817 /* Discovery not needed,
3818 * move the nodes to their original state.
3819 */
James Smart2e0fef82007-06-17 19:56:36 -05003820 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
James Smart685f0bf2007-04-25 09:53:08 -04003821 nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05003822 if (!NLP_CHK_NODE_ACT(ndlp))
3823 continue;
James Smart685f0bf2007-04-25 09:53:08 -04003824 if (ndlp->nlp_state != NLP_STE_NPR_NODE)
3825 continue;
dea31012005-04-17 16:05:31 -05003826
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003827 switch (ndlp->nlp_prev_state) {
3828 case NLP_STE_UNMAPPED_NODE:
3829 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05003830 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04003831 NLP_STE_UNMAPPED_NODE);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003832 break;
3833
3834 case NLP_STE_MAPPED_NODE:
3835 ndlp->nlp_prev_state = NLP_STE_NPR_NODE;
James Smart2e0fef82007-06-17 19:56:36 -05003836 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04003837 NLP_STE_MAPPED_NODE);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003838 break;
3839
3840 default:
3841 break;
3842 }
3843 }
3844
3845 /* Start discovery - this should just do CLEAR_LA */
James Smart2e0fef82007-06-17 19:56:36 -05003846 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -05003847 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003848 return 0;
dea31012005-04-17 16:05:31 -05003849}
3850
3851void
3852lpfc_els_timeout(unsigned long ptr)
3853{
James Smart2e0fef82007-06-17 19:56:36 -05003854 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
3855 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003856 unsigned long iflag;
3857
James Smart2e0fef82007-06-17 19:56:36 -05003858 spin_lock_irqsave(&vport->work_port_lock, iflag);
3859 if ((vport->work_port_events & WORKER_ELS_TMO) == 0) {
3860 vport->work_port_events |= WORKER_ELS_TMO;
James Smart92d7f7b2007-06-17 19:56:38 -05003861 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
3862
3863 spin_lock_irqsave(&phba->hbalock, iflag);
dea31012005-04-17 16:05:31 -05003864 if (phba->work_wait)
James Smart92d7f7b2007-06-17 19:56:38 -05003865 lpfc_worker_wake_up(phba);
3866 spin_unlock_irqrestore(&phba->hbalock, iflag);
dea31012005-04-17 16:05:31 -05003867 }
James Smart92d7f7b2007-06-17 19:56:38 -05003868 else
3869 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
dea31012005-04-17 16:05:31 -05003870 return;
3871}
3872
3873void
James Smart2e0fef82007-06-17 19:56:36 -05003874lpfc_els_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003875{
James Smart2e0fef82007-06-17 19:56:36 -05003876 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003877 struct lpfc_sli_ring *pring;
3878 struct lpfc_iocbq *tmp_iocb, *piocb;
3879 IOCB_t *cmd = NULL;
3880 struct lpfc_dmabuf *pcmd;
James Smart2e0fef82007-06-17 19:56:36 -05003881 uint32_t els_command = 0;
dea31012005-04-17 16:05:31 -05003882 uint32_t timeout;
James Smart2e0fef82007-06-17 19:56:36 -05003883 uint32_t remote_ID = 0xffffffff;
dea31012005-04-17 16:05:31 -05003884
dea31012005-04-17 16:05:31 -05003885 /* If the timer is already canceled do nothing */
James Smart2e0fef82007-06-17 19:56:36 -05003886 if ((vport->work_port_events & WORKER_ELS_TMO) == 0) {
dea31012005-04-17 16:05:31 -05003887 return;
3888 }
James Smart2e0fef82007-06-17 19:56:36 -05003889 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003890 timeout = (uint32_t)(phba->fc_ratov << 1);
3891
3892 pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05003893
3894 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
3895 cmd = &piocb->iocb;
3896
James Smart2e0fef82007-06-17 19:56:36 -05003897 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
3898 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
3899 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
dea31012005-04-17 16:05:31 -05003900 continue;
James Smart2e0fef82007-06-17 19:56:36 -05003901
3902 if (piocb->vport != vport)
3903 continue;
3904
dea31012005-04-17 16:05:31 -05003905 pcmd = (struct lpfc_dmabuf *) piocb->context2;
James Smart2e0fef82007-06-17 19:56:36 -05003906 if (pcmd)
3907 els_command = *(uint32_t *) (pcmd->virt);
dea31012005-04-17 16:05:31 -05003908
James Smart92d7f7b2007-06-17 19:56:38 -05003909 if (els_command == ELS_CMD_FARP ||
3910 els_command == ELS_CMD_FARPR ||
3911 els_command == ELS_CMD_FDISC)
dea31012005-04-17 16:05:31 -05003912 continue;
James Smart92d7f7b2007-06-17 19:56:38 -05003913
3914 if (vport != piocb->vport)
3915 continue;
dea31012005-04-17 16:05:31 -05003916
3917 if (piocb->drvrTimeout > 0) {
James Smart92d7f7b2007-06-17 19:56:38 -05003918 if (piocb->drvrTimeout >= timeout)
dea31012005-04-17 16:05:31 -05003919 piocb->drvrTimeout -= timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05003920 else
dea31012005-04-17 16:05:31 -05003921 piocb->drvrTimeout = 0;
dea31012005-04-17 16:05:31 -05003922 continue;
3923 }
3924
James Smart2e0fef82007-06-17 19:56:36 -05003925 remote_ID = 0xffffffff;
3926 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
dea31012005-04-17 16:05:31 -05003927 remote_ID = cmd->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05003928 else {
3929 struct lpfc_nodelist *ndlp;
3930 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
3931 if (ndlp)
3932 remote_ID = ndlp->nlp_DID;
dea31012005-04-17 16:05:31 -05003933 }
James Smarte8b62012007-08-02 11:10:09 -04003934 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3935 "0127 ELS timeout Data: x%x x%x x%x "
3936 "x%x\n", els_command,
3937 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
James Smart07951072007-04-25 09:51:38 -04003938 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05003939 }
James Smart2e0fef82007-06-17 19:56:36 -05003940 spin_unlock_irq(&phba->hbalock);
James Smart5a0e3262006-07-06 15:49:16 -04003941
James Smart2e0fef82007-06-17 19:56:36 -05003942 if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt)
3943 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
dea31012005-04-17 16:05:31 -05003944}
3945
3946void
James Smart2e0fef82007-06-17 19:56:36 -05003947lpfc_els_flush_cmd(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003948{
James Smart2534ba72007-04-25 09:52:20 -04003949 LIST_HEAD(completions);
James Smart2e0fef82007-06-17 19:56:36 -05003950 struct lpfc_hba *phba = vport->phba;
James Smart329f9bc2007-04-25 09:53:01 -04003951 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05003952 struct lpfc_iocbq *tmp_iocb, *piocb;
3953 IOCB_t *cmd = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05003954
3955 lpfc_fabric_abort_vport(vport);
dea31012005-04-17 16:05:31 -05003956
James Smart2e0fef82007-06-17 19:56:36 -05003957 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003958 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
3959 cmd = &piocb->iocb;
3960
3961 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
3962 continue;
3963 }
3964
3965 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
James Smart329f9bc2007-04-25 09:53:01 -04003966 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
3967 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
3968 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
3969 cmd->ulpCommand == CMD_ABORT_XRI_CN)
dea31012005-04-17 16:05:31 -05003970 continue;
dea31012005-04-17 16:05:31 -05003971
James Smart2e0fef82007-06-17 19:56:36 -05003972 if (piocb->vport != vport)
3973 continue;
3974
James Smart2534ba72007-04-25 09:52:20 -04003975 list_move_tail(&piocb->list, &completions);
James Smart1dcb58e2007-04-25 09:51:30 -04003976 pring->txq_cnt--;
dea31012005-04-17 16:05:31 -05003977 }
3978
3979 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
dea31012005-04-17 16:05:31 -05003980 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
3981 continue;
3982 }
dea31012005-04-17 16:05:31 -05003983
James Smart2e0fef82007-06-17 19:56:36 -05003984 if (piocb->vport != vport)
3985 continue;
3986
James Smart07951072007-04-25 09:51:38 -04003987 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05003988 }
James Smart2e0fef82007-06-17 19:56:36 -05003989 spin_unlock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04003990
James Smart2e0fef82007-06-17 19:56:36 -05003991 while (!list_empty(&completions)) {
James Smart2534ba72007-04-25 09:52:20 -04003992 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
3993 cmd = &piocb->iocb;
James Smart92d7f7b2007-06-17 19:56:38 -05003994 list_del_init(&piocb->list);
James Smart2534ba72007-04-25 09:52:20 -04003995
James Smart2e0fef82007-06-17 19:56:36 -05003996 if (!piocb->iocb_cmpl)
3997 lpfc_sli_release_iocbq(phba, piocb);
3998 else {
James Smart2534ba72007-04-25 09:52:20 -04003999 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
4000 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
4001 (piocb->iocb_cmpl) (phba, piocb, piocb);
James Smart2e0fef82007-06-17 19:56:36 -05004002 }
James Smart2534ba72007-04-25 09:52:20 -04004003 }
4004
dea31012005-04-17 16:05:31 -05004005 return;
4006}
4007
James Smart549e55c2007-08-02 11:09:51 -04004008void
4009lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
4010{
4011 LIST_HEAD(completions);
4012 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
4013 struct lpfc_iocbq *tmp_iocb, *piocb;
4014 IOCB_t *cmd = NULL;
4015
4016 lpfc_fabric_abort_hba(phba);
4017 spin_lock_irq(&phba->hbalock);
4018 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
4019 cmd = &piocb->iocb;
4020 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
4021 continue;
4022 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
4023 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
4024 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
4025 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
4026 cmd->ulpCommand == CMD_ABORT_XRI_CN)
4027 continue;
4028 list_move_tail(&piocb->list, &completions);
4029 pring->txq_cnt--;
4030 }
4031 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
4032 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
4033 continue;
4034 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
4035 }
4036 spin_unlock_irq(&phba->hbalock);
4037 while (!list_empty(&completions)) {
4038 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
4039 cmd = &piocb->iocb;
4040 list_del_init(&piocb->list);
4041 if (!piocb->iocb_cmpl)
4042 lpfc_sli_release_iocbq(phba, piocb);
4043 else {
4044 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
4045 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
4046 (piocb->iocb_cmpl) (phba, piocb, piocb);
4047 }
4048 }
4049 return;
4050}
4051
James Smarted957682007-06-17 19:56:37 -05004052static void
4053lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
James Smart92d7f7b2007-06-17 19:56:38 -05004054 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05004055{
James Smart87af33f2007-10-27 13:37:43 -04004056 struct Scsi_Host *shost;
dea31012005-04-17 16:05:31 -05004057 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05004058 struct ls_rjt stat;
James Smart92d7f7b2007-06-17 19:56:38 -05004059 uint32_t *payload;
James Smart2e0fef82007-06-17 19:56:36 -05004060 uint32_t cmd, did, newnode, rjt_err = 0;
James Smarted957682007-06-17 19:56:37 -05004061 IOCB_t *icmd = &elsiocb->iocb;
dea31012005-04-17 16:05:31 -05004062
James Smarte47c9092008-02-08 18:49:26 -05004063 if (!vport || !(elsiocb->context2))
dea31012005-04-17 16:05:31 -05004064 goto dropit;
James Smart2e0fef82007-06-17 19:56:36 -05004065
dea31012005-04-17 16:05:31 -05004066 newnode = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05004067 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
4068 cmd = *payload;
James Smarted957682007-06-17 19:56:37 -05004069 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
4070 lpfc_post_buffer(phba, pring, 1, 1);
dea31012005-04-17 16:05:31 -05004071
James Smart858c9f62007-06-17 19:56:39 -05004072 did = icmd->un.rcvels.remoteID;
4073 if (icmd->ulpStatus) {
4074 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4075 "RCV Unsol ELS: status:x%x/x%x did:x%x",
4076 icmd->ulpStatus, icmd->un.ulpWord[4], did);
dea31012005-04-17 16:05:31 -05004077 goto dropit;
James Smart858c9f62007-06-17 19:56:39 -05004078 }
dea31012005-04-17 16:05:31 -05004079
4080 /* Check to see if link went down during discovery */
James Smarted957682007-06-17 19:56:37 -05004081 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05004082 goto dropit;
dea31012005-04-17 16:05:31 -05004083
James Smart92d7f7b2007-06-17 19:56:38 -05004084 /* Ignore traffic recevied during vport shutdown. */
4085 if (vport->load_flag & FC_UNLOADING)
4086 goto dropit;
4087
James Smart2e0fef82007-06-17 19:56:36 -05004088 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004089 if (!ndlp) {
dea31012005-04-17 16:05:31 -05004090 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004091 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
James Smarted957682007-06-17 19:56:37 -05004092 if (!ndlp)
dea31012005-04-17 16:05:31 -05004093 goto dropit;
dea31012005-04-17 16:05:31 -05004094
James Smart2e0fef82007-06-17 19:56:36 -05004095 lpfc_nlp_init(vport, ndlp, did);
James Smart98c9ea52007-10-27 13:37:33 -04004096 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05004097 newnode = 1;
James Smarte47c9092008-02-08 18:49:26 -05004098 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
dea31012005-04-17 16:05:31 -05004099 ndlp->nlp_type |= NLP_FABRIC;
James Smarte47c9092008-02-08 18:49:26 -05004100 } else {
4101 if (!NLP_CHK_NODE_ACT(ndlp)) {
4102 ndlp = lpfc_enable_node(vport, ndlp,
4103 NLP_STE_UNUSED_NODE);
4104 if (!ndlp)
4105 goto dropit;
dea31012005-04-17 16:05:31 -05004106 }
James Smart87af33f2007-10-27 13:37:43 -04004107 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
4108 /* This is simular to the new node path */
James Smarte47c9092008-02-08 18:49:26 -05004109 ndlp = lpfc_nlp_get(ndlp);
4110 if (!ndlp)
4111 goto dropit;
James Smart87af33f2007-10-27 13:37:43 -04004112 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
4113 newnode = 1;
4114 }
4115 }
dea31012005-04-17 16:05:31 -05004116
4117 phba->fc_stat.elsRcvFrame++;
James Smart329f9bc2007-04-25 09:53:01 -04004118 if (elsiocb->context1)
4119 lpfc_nlp_put(elsiocb->context1);
James Smarte47c9092008-02-08 18:49:26 -05004120
James Smart329f9bc2007-04-25 09:53:01 -04004121 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05004122 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -05004123
4124 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
4125 cmd &= ELS_CMD_MASK;
4126 }
4127 /* ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04004128 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4129 "0112 ELS command x%x received from NPORT x%x "
4130 "Data: x%x\n", cmd, did, vport->port_state);
dea31012005-04-17 16:05:31 -05004131 switch (cmd) {
4132 case ELS_CMD_PLOGI:
James Smart858c9f62007-06-17 19:56:39 -05004133 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4134 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
4135 did, vport->port_state, ndlp->nlp_flag);
4136
dea31012005-04-17 16:05:31 -05004137 phba->fc_stat.elsRcvPLOGI++;
James Smart858c9f62007-06-17 19:56:39 -05004138 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
4139
4140 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart1b32f6a2008-02-08 18:49:39 -05004141 if (!(phba->pport->fc_flag & FC_PT2PT) ||
4142 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
4143 rjt_err = LSRJT_UNABLE_TPC;
4144 break;
4145 }
4146 /* We get here, and drop thru, if we are PT2PT with
4147 * another NPort and the other side has initiated
4148 * the PLOGI before responding to our FLOGI.
4149 */
dea31012005-04-17 16:05:31 -05004150 }
James Smart87af33f2007-10-27 13:37:43 -04004151
4152 shost = lpfc_shost_from_vport(vport);
4153 spin_lock_irq(shost->host_lock);
4154 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
4155 spin_unlock_irq(shost->host_lock);
4156
James Smart2e0fef82007-06-17 19:56:36 -05004157 lpfc_disc_state_machine(vport, ndlp, elsiocb,
4158 NLP_EVT_RCV_PLOGI);
James Smart858c9f62007-06-17 19:56:39 -05004159
dea31012005-04-17 16:05:31 -05004160 break;
4161 case ELS_CMD_FLOGI:
James Smart858c9f62007-06-17 19:56:39 -05004162 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4163 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
4164 did, vport->port_state, ndlp->nlp_flag);
4165
dea31012005-04-17 16:05:31 -05004166 phba->fc_stat.elsRcvFLOGI++;
James Smart51ef4c22007-08-02 11:10:31 -04004167 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04004168 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04004169 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05004170 break;
4171 case ELS_CMD_LOGO:
James Smart858c9f62007-06-17 19:56:39 -05004172 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4173 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
4174 did, vport->port_state, ndlp->nlp_flag);
4175
dea31012005-04-17 16:05:31 -05004176 phba->fc_stat.elsRcvLOGO++;
James Smart2e0fef82007-06-17 19:56:36 -05004177 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05004178 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05004179 break;
4180 }
James Smart2e0fef82007-06-17 19:56:36 -05004181 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
dea31012005-04-17 16:05:31 -05004182 break;
4183 case ELS_CMD_PRLO:
James Smart858c9f62007-06-17 19:56:39 -05004184 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4185 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
4186 did, vport->port_state, ndlp->nlp_flag);
4187
dea31012005-04-17 16:05:31 -05004188 phba->fc_stat.elsRcvPRLO++;
James Smart2e0fef82007-06-17 19:56:36 -05004189 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05004190 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05004191 break;
4192 }
James Smart2e0fef82007-06-17 19:56:36 -05004193 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
dea31012005-04-17 16:05:31 -05004194 break;
4195 case ELS_CMD_RSCN:
4196 phba->fc_stat.elsRcvRSCN++;
James Smart51ef4c22007-08-02 11:10:31 -04004197 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04004198 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04004199 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05004200 break;
4201 case ELS_CMD_ADISC:
James Smart858c9f62007-06-17 19:56:39 -05004202 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4203 "RCV ADISC: 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.elsRcvADISC++;
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,
4212 NLP_EVT_RCV_ADISC);
dea31012005-04-17 16:05:31 -05004213 break;
4214 case ELS_CMD_PDISC:
James Smart858c9f62007-06-17 19:56:39 -05004215 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4216 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
4217 did, vport->port_state, ndlp->nlp_flag);
4218
dea31012005-04-17 16:05:31 -05004219 phba->fc_stat.elsRcvPDISC++;
James Smart2e0fef82007-06-17 19:56:36 -05004220 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05004221 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05004222 break;
4223 }
James Smart2e0fef82007-06-17 19:56:36 -05004224 lpfc_disc_state_machine(vport, ndlp, elsiocb,
4225 NLP_EVT_RCV_PDISC);
dea31012005-04-17 16:05:31 -05004226 break;
4227 case ELS_CMD_FARPR:
James Smart858c9f62007-06-17 19:56:39 -05004228 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4229 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
4230 did, vport->port_state, ndlp->nlp_flag);
4231
dea31012005-04-17 16:05:31 -05004232 phba->fc_stat.elsRcvFARPR++;
James Smart2e0fef82007-06-17 19:56:36 -05004233 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05004234 break;
4235 case ELS_CMD_FARP:
James Smart858c9f62007-06-17 19:56:39 -05004236 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4237 "RCV FARP: did:x%x/ste:x%x flg:x%x",
4238 did, vport->port_state, ndlp->nlp_flag);
4239
dea31012005-04-17 16:05:31 -05004240 phba->fc_stat.elsRcvFARP++;
James Smart2e0fef82007-06-17 19:56:36 -05004241 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05004242 break;
4243 case ELS_CMD_FAN:
James Smart858c9f62007-06-17 19:56:39 -05004244 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4245 "RCV FAN: 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.elsRcvFAN++;
James Smart2e0fef82007-06-17 19:56:36 -05004249 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05004250 break;
dea31012005-04-17 16:05:31 -05004251 case ELS_CMD_PRLI:
James Smart858c9f62007-06-17 19:56:39 -05004252 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4253 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
4254 did, vport->port_state, ndlp->nlp_flag);
4255
dea31012005-04-17 16:05:31 -05004256 phba->fc_stat.elsRcvPRLI++;
James Smart2e0fef82007-06-17 19:56:36 -05004257 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05004258 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05004259 break;
4260 }
James Smart2e0fef82007-06-17 19:56:36 -05004261 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
dea31012005-04-17 16:05:31 -05004262 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004263 case ELS_CMD_LIRR:
James Smart858c9f62007-06-17 19:56:39 -05004264 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4265 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
4266 did, vport->port_state, ndlp->nlp_flag);
4267
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004268 phba->fc_stat.elsRcvLIRR++;
James Smart2e0fef82007-06-17 19:56:36 -05004269 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04004270 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04004271 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004272 break;
4273 case ELS_CMD_RPS:
James Smart858c9f62007-06-17 19:56:39 -05004274 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4275 "RCV RPS: did:x%x/ste:x%x flg:x%x",
4276 did, vport->port_state, ndlp->nlp_flag);
4277
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004278 phba->fc_stat.elsRcvRPS++;
James Smart2e0fef82007-06-17 19:56:36 -05004279 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04004280 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04004281 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004282 break;
4283 case ELS_CMD_RPL:
James Smart858c9f62007-06-17 19:56:39 -05004284 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4285 "RCV RPL: did:x%x/ste:x%x flg:x%x",
4286 did, vport->port_state, ndlp->nlp_flag);
4287
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004288 phba->fc_stat.elsRcvRPL++;
James Smart2e0fef82007-06-17 19:56:36 -05004289 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04004290 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04004291 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004292 break;
dea31012005-04-17 16:05:31 -05004293 case ELS_CMD_RNID:
James Smart858c9f62007-06-17 19:56:39 -05004294 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4295 "RCV RNID: did:x%x/ste:x%x flg:x%x",
4296 did, vport->port_state, ndlp->nlp_flag);
4297
dea31012005-04-17 16:05:31 -05004298 phba->fc_stat.elsRcvRNID++;
James Smart2e0fef82007-06-17 19:56:36 -05004299 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04004300 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04004301 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05004302 break;
4303 default:
James Smart858c9f62007-06-17 19:56:39 -05004304 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4305 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
4306 cmd, did, vport->port_state);
4307
dea31012005-04-17 16:05:31 -05004308 /* Unsupported ELS command, reject */
James Smart858c9f62007-06-17 19:56:39 -05004309 rjt_err = LSRJT_INVALID_CMD;
dea31012005-04-17 16:05:31 -05004310
4311 /* Unknown ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04004312 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4313 "0115 Unknown ELS command x%x "
4314 "received from NPORT x%x\n", cmd, did);
James Smart87af33f2007-10-27 13:37:43 -04004315 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04004316 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05004317 break;
4318 }
4319
4320 /* check if need to LS_RJT received ELS cmd */
4321 if (rjt_err) {
James Smart92d7f7b2007-06-17 19:56:38 -05004322 memset(&stat, 0, sizeof(stat));
James Smart858c9f62007-06-17 19:56:39 -05004323 stat.un.b.lsRjtRsnCode = rjt_err;
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04004324 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart858c9f62007-06-17 19:56:39 -05004325 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
4326 NULL);
dea31012005-04-17 16:05:31 -05004327 }
4328
James Smarted957682007-06-17 19:56:37 -05004329 return;
4330
4331dropit:
James Smart98c9ea52007-10-27 13:37:33 -04004332 if (vport && !(vport->load_flag & FC_UNLOADING))
4333 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
James Smarte8b62012007-08-02 11:10:09 -04004334 "(%d):0111 Dropping received ELS cmd "
James Smarted957682007-06-17 19:56:37 -05004335 "Data: x%x x%x x%x\n",
James Smart98c9ea52007-10-27 13:37:33 -04004336 vport->vpi, icmd->ulpStatus,
James Smarte8b62012007-08-02 11:10:09 -04004337 icmd->un.ulpWord[4], icmd->ulpTimeout);
James Smarted957682007-06-17 19:56:37 -05004338 phba->fc_stat.elsRcvDrop++;
4339}
4340
James Smart92d7f7b2007-06-17 19:56:38 -05004341static struct lpfc_vport *
4342lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
4343{
4344 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -04004345 unsigned long flags;
James Smart92d7f7b2007-06-17 19:56:38 -05004346
James Smart549e55c2007-08-02 11:09:51 -04004347 spin_lock_irqsave(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05004348 list_for_each_entry(vport, &phba->port_list, listentry) {
James Smart549e55c2007-08-02 11:09:51 -04004349 if (vport->vpi == vpi) {
4350 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05004351 return vport;
James Smart549e55c2007-08-02 11:09:51 -04004352 }
James Smart92d7f7b2007-06-17 19:56:38 -05004353 }
James Smart549e55c2007-08-02 11:09:51 -04004354 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05004355 return NULL;
4356}
James Smarted957682007-06-17 19:56:37 -05004357
4358void
4359lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
4360 struct lpfc_iocbq *elsiocb)
4361{
4362 struct lpfc_vport *vport = phba->pport;
James Smarted957682007-06-17 19:56:37 -05004363 IOCB_t *icmd = &elsiocb->iocb;
James Smarted957682007-06-17 19:56:37 -05004364 dma_addr_t paddr;
James Smart92d7f7b2007-06-17 19:56:38 -05004365 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
4366 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
James Smarted957682007-06-17 19:56:37 -05004367
James Smart92d7f7b2007-06-17 19:56:38 -05004368 elsiocb->context2 = NULL;
4369 elsiocb->context3 = NULL;
4370
4371 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
4372 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
4373 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
4374 (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) {
James Smarted957682007-06-17 19:56:37 -05004375 phba->fc_stat.NoRcvBuf++;
4376 /* Not enough posted buffers; Try posting more buffers */
James Smart92d7f7b2007-06-17 19:56:38 -05004377 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
James Smarted957682007-06-17 19:56:37 -05004378 lpfc_post_buffer(phba, pring, 0, 1);
4379 return;
4380 }
4381
James Smart92d7f7b2007-06-17 19:56:38 -05004382 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
4383 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
4384 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
4385 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
4386 vport = phba->pport;
4387 else {
4388 uint16_t vpi = icmd->unsli3.rcvsli3.vpi;
4389 vport = lpfc_find_vport_by_vpid(phba, vpi);
4390 }
4391 }
James Smart7f5f3d02008-02-08 18:50:14 -05004392 /* If there are no BDEs associated
4393 * with this IOCB, there is nothing to do.
4394 */
James Smarted957682007-06-17 19:56:37 -05004395 if (icmd->ulpBdeCount == 0)
4396 return;
4397
James Smart7f5f3d02008-02-08 18:50:14 -05004398 /* type of ELS cmd is first 32bit word
4399 * in packet
4400 */
James Smarted957682007-06-17 19:56:37 -05004401 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05004402 elsiocb->context2 = bdeBuf1;
James Smarted957682007-06-17 19:56:37 -05004403 } else {
4404 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
4405 icmd->un.cont64[0].addrLow);
James Smart92d7f7b2007-06-17 19:56:38 -05004406 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
4407 paddr);
James Smarted957682007-06-17 19:56:37 -05004408 }
4409
James Smart92d7f7b2007-06-17 19:56:38 -05004410 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
4411 /*
4412 * The different unsolicited event handlers would tell us
4413 * if they are done with "mp" by setting context2 to NULL.
4414 */
James Smart329f9bc2007-04-25 09:53:01 -04004415 lpfc_nlp_put(elsiocb->context1);
4416 elsiocb->context1 = NULL;
dea31012005-04-17 16:05:31 -05004417 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05004418 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
4419 elsiocb->context2 = NULL;
dea31012005-04-17 16:05:31 -05004420 }
James Smarted957682007-06-17 19:56:37 -05004421
4422 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
James Smart92d7f7b2007-06-17 19:56:38 -05004423 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
James Smarted957682007-06-17 19:56:37 -05004424 icmd->ulpBdeCount == 2) {
James Smart92d7f7b2007-06-17 19:56:38 -05004425 elsiocb->context2 = bdeBuf2;
4426 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
James Smarted957682007-06-17 19:56:37 -05004427 /* free mp if we are done with it */
4428 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05004429 lpfc_in_buf_free(phba, elsiocb->context2);
4430 elsiocb->context2 = NULL;
James Smarted957682007-06-17 19:56:37 -05004431 }
dea31012005-04-17 16:05:31 -05004432 }
dea31012005-04-17 16:05:31 -05004433}
James Smart92d7f7b2007-06-17 19:56:38 -05004434
4435void
4436lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
4437{
4438 struct lpfc_nodelist *ndlp, *ndlp_fdmi;
4439
4440 ndlp = lpfc_findnode_did(vport, NameServer_DID);
4441 if (!ndlp) {
4442 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
4443 if (!ndlp) {
4444 if (phba->fc_topology == TOPOLOGY_LOOP) {
4445 lpfc_disc_start(vport);
4446 return;
4447 }
4448 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04004449 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4450 "0251 NameServer login: no memory\n");
James Smart92d7f7b2007-06-17 19:56:38 -05004451 return;
4452 }
4453 lpfc_nlp_init(vport, ndlp, NameServer_DID);
4454 ndlp->nlp_type |= NLP_FABRIC;
James Smarte47c9092008-02-08 18:49:26 -05004455 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
4456 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
4457 if (!ndlp) {
4458 if (phba->fc_topology == TOPOLOGY_LOOP) {
4459 lpfc_disc_start(vport);
4460 return;
4461 }
4462 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4463 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4464 "0348 NameServer login: node freed\n");
4465 return;
4466 }
James Smart92d7f7b2007-06-17 19:56:38 -05004467 }
4468
4469 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
4470
4471 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
4472 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04004473 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4474 "0252 Cannot issue NameServer login\n");
James Smart92d7f7b2007-06-17 19:56:38 -05004475 return;
4476 }
4477
James Smart3de2a652007-08-02 11:09:59 -04004478 if (vport->cfg_fdmi_on) {
James Smart92d7f7b2007-06-17 19:56:38 -05004479 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
4480 GFP_KERNEL);
4481 if (ndlp_fdmi) {
4482 lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
4483 ndlp_fdmi->nlp_type |= NLP_FABRIC;
4484 ndlp_fdmi->nlp_state =
4485 NLP_STE_PLOGI_ISSUE;
4486 lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID,
4487 0);
4488 }
4489 }
4490 return;
4491}
4492
4493static void
4494lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
4495{
4496 struct lpfc_vport *vport = pmb->vport;
4497 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4498 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
4499 MAILBOX_t *mb = &pmb->mb;
4500
James Smart09372822008-01-11 01:52:54 -05004501 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004502 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05004503 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004504
4505 if (mb->mbxStatus) {
James Smarte8b62012007-08-02 11:10:09 -04004506 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
4507 "0915 Register VPI failed: 0x%x\n",
4508 mb->mbxStatus);
James Smart92d7f7b2007-06-17 19:56:38 -05004509
4510 switch (mb->mbxStatus) {
4511 case 0x11: /* unsupported feature */
4512 case 0x9603: /* max_vpi exceeded */
James Smart7f5f3d02008-02-08 18:50:14 -05004513 case 0x9602: /* Link event since CLEAR_LA */
James Smart92d7f7b2007-06-17 19:56:38 -05004514 /* giving up on vport registration */
4515 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4516 spin_lock_irq(shost->host_lock);
4517 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
4518 spin_unlock_irq(shost->host_lock);
4519 lpfc_can_disctmo(vport);
4520 break;
4521 default:
4522 /* Try to recover from this error */
4523 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -05004524 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004525 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05004526 spin_unlock_irq(shost->host_lock);
James Smart7f5f3d02008-02-08 18:50:14 -05004527 if (vport->port_type == LPFC_PHYSICAL_PORT)
4528 lpfc_initial_flogi(vport);
4529 else
4530 lpfc_initial_fdisc(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05004531 break;
4532 }
4533
4534 } else {
4535 if (vport == phba->pport)
4536 lpfc_issue_fabric_reglogin(vport);
4537 else
4538 lpfc_do_scr_ns_plogi(phba, vport);
4539 }
James Smartfa4066b2008-01-11 01:53:27 -05004540
4541 /* Now, we decrement the ndlp reference count held for this
4542 * callback function
4543 */
4544 lpfc_nlp_put(ndlp);
4545
James Smart92d7f7b2007-06-17 19:56:38 -05004546 mempool_free(pmb, phba->mbox_mem_pool);
4547 return;
4548}
4549
Adrian Bunka6ababd2007-11-05 18:07:33 +01004550static void
James Smart92d7f7b2007-06-17 19:56:38 -05004551lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
4552 struct lpfc_nodelist *ndlp)
4553{
James Smart09372822008-01-11 01:52:54 -05004554 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05004555 LPFC_MBOXQ_t *mbox;
4556
4557 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4558 if (mbox) {
4559 lpfc_reg_vpi(phba, vport->vpi, vport->fc_myDID, mbox);
4560 mbox->vport = vport;
4561 mbox->context2 = lpfc_nlp_get(ndlp);
4562 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
James Smart0b727fe2007-10-27 13:37:25 -04004563 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart92d7f7b2007-06-17 19:56:38 -05004564 == MBX_NOT_FINISHED) {
James Smartfa4066b2008-01-11 01:53:27 -05004565 /* mailbox command not success, decrement ndlp
4566 * reference count for this command
4567 */
4568 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05004569 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05004570
James Smarte8b62012007-08-02 11:10:09 -04004571 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
4572 "0253 Register VPI: Can't send mbox\n");
James Smartfa4066b2008-01-11 01:53:27 -05004573 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05004574 }
4575 } else {
James Smarte8b62012007-08-02 11:10:09 -04004576 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
4577 "0254 Register VPI: no memory\n");
James Smartfa4066b2008-01-11 01:53:27 -05004578 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05004579 }
James Smartfa4066b2008-01-11 01:53:27 -05004580 return;
4581
4582mbox_err_exit:
4583 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
4584 spin_lock_irq(shost->host_lock);
4585 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
4586 spin_unlock_irq(shost->host_lock);
4587 return;
James Smart92d7f7b2007-06-17 19:56:38 -05004588}
4589
4590static void
4591lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4592 struct lpfc_iocbq *rspiocb)
4593{
4594 struct lpfc_vport *vport = cmdiocb->vport;
4595 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4596 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
4597 struct lpfc_nodelist *np;
4598 struct lpfc_nodelist *next_np;
4599 IOCB_t *irsp = &rspiocb->iocb;
4600 struct lpfc_iocbq *piocb;
4601
James Smarte8b62012007-08-02 11:10:09 -04004602 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4603 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
4604 irsp->ulpStatus, irsp->un.ulpWord[4],
4605 vport->fc_prevDID);
James Smart92d7f7b2007-06-17 19:56:38 -05004606 /* Since all FDISCs are being single threaded, we
4607 * must reset the discovery timer for ALL vports
4608 * waiting to send FDISC when one completes.
4609 */
4610 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
4611 lpfc_set_disctmo(piocb->vport);
4612 }
4613
James Smart858c9f62007-06-17 19:56:39 -05004614 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4615 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
4616 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
4617
James Smart92d7f7b2007-06-17 19:56:38 -05004618 if (irsp->ulpStatus) {
4619 /* Check for retry */
4620 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
4621 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05004622 /* FDISC failed */
James Smarte8b62012007-08-02 11:10:09 -04004623 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4624 "0124 FDISC failed. (%d/%d)\n",
4625 irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smart92d7f7b2007-06-17 19:56:38 -05004626 if (vport->fc_vport->vport_state == FC_VPORT_INITIALIZING)
4627 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smart92d7f7b2007-06-17 19:56:38 -05004628 lpfc_nlp_put(ndlp);
4629 /* giving up on FDISC. Cancel discovery timer */
4630 lpfc_can_disctmo(vport);
4631 } else {
4632 spin_lock_irq(shost->host_lock);
4633 vport->fc_flag |= FC_FABRIC;
4634 if (vport->phba->fc_topology == TOPOLOGY_LOOP)
4635 vport->fc_flag |= FC_PUBLIC_LOOP;
4636 spin_unlock_irq(shost->host_lock);
4637
4638 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
4639 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
4640 if ((vport->fc_prevDID != vport->fc_myDID) &&
4641 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
4642 /* If our NportID changed, we need to ensure all
4643 * remaining NPORTs get unreg_login'ed so we can
4644 * issue unreg_vpi.
4645 */
4646 list_for_each_entry_safe(np, next_np,
4647 &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004648 if (!NLP_CHK_NODE_ACT(ndlp) ||
4649 (np->nlp_state != NLP_STE_NPR_NODE) ||
4650 !(np->nlp_flag & NLP_NPR_ADISC))
James Smart92d7f7b2007-06-17 19:56:38 -05004651 continue;
4652 spin_lock_irq(shost->host_lock);
4653 np->nlp_flag &= ~NLP_NPR_ADISC;
4654 spin_unlock_irq(shost->host_lock);
4655 lpfc_unreg_rpi(vport, np);
4656 }
4657 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -05004658 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004659 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05004660 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004661 }
4662
4663 if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
4664 lpfc_register_new_vport(phba, vport, ndlp);
4665 else
4666 lpfc_do_scr_ns_plogi(phba, vport);
4667
James Smartfa4066b2008-01-11 01:53:27 -05004668 /* Unconditionaly kick off releasing fabric node for vports */
4669 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05004670 }
4671
4672out:
4673 lpfc_els_free_iocb(phba, cmdiocb);
4674}
4675
Adrian Bunka6ababd2007-11-05 18:07:33 +01004676static int
James Smart92d7f7b2007-06-17 19:56:38 -05004677lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4678 uint8_t retry)
4679{
4680 struct lpfc_hba *phba = vport->phba;
4681 IOCB_t *icmd;
4682 struct lpfc_iocbq *elsiocb;
4683 struct serv_parm *sp;
4684 uint8_t *pcmd;
4685 uint16_t cmdsize;
4686 int did = ndlp->nlp_DID;
4687 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05004688
4689 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
4690 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
4691 ELS_CMD_FDISC);
4692 if (!elsiocb) {
James Smart92d7f7b2007-06-17 19:56:38 -05004693 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04004694 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4695 "0255 Issue FDISC: no IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05004696 return 1;
4697 }
4698
4699 icmd = &elsiocb->iocb;
4700 icmd->un.elsreq64.myID = 0;
4701 icmd->un.elsreq64.fl = 1;
4702
4703 /* For FDISC, Let FDISC rsp set the NPortID for this VPI */
4704 icmd->ulpCt_h = 1;
4705 icmd->ulpCt_l = 0;
4706
4707 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4708 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
4709 pcmd += sizeof(uint32_t); /* CSP Word 1 */
4710 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
4711 sp = (struct serv_parm *) pcmd;
4712 /* Setup CSPs accordingly for Fabric */
4713 sp->cmn.e_d_tov = 0;
4714 sp->cmn.w2.r_a_tov = 0;
4715 sp->cls1.classValid = 0;
4716 sp->cls2.seqDelivery = 1;
4717 sp->cls3.seqDelivery = 1;
4718
4719 pcmd += sizeof(uint32_t); /* CSP Word 2 */
4720 pcmd += sizeof(uint32_t); /* CSP Word 3 */
4721 pcmd += sizeof(uint32_t); /* CSP Word 4 */
4722 pcmd += sizeof(uint32_t); /* Port Name */
4723 memcpy(pcmd, &vport->fc_portname, 8);
4724 pcmd += sizeof(uint32_t); /* Node Name */
4725 pcmd += sizeof(uint32_t); /* Node Name */
4726 memcpy(pcmd, &vport->fc_nodename, 8);
4727
4728 lpfc_set_disctmo(vport);
4729
4730 phba->fc_stat.elsXmitFDISC++;
4731 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
4732
James Smart858c9f62007-06-17 19:56:39 -05004733 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4734 "Issue FDISC: did:x%x",
4735 did, 0, 0);
4736
James Smart92d7f7b2007-06-17 19:56:38 -05004737 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
4738 if (rc == IOCB_ERROR) {
4739 lpfc_els_free_iocb(phba, elsiocb);
James Smart92d7f7b2007-06-17 19:56:38 -05004740 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04004741 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4742 "0256 Issue FDISC: Cannot send IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05004743 return 1;
4744 }
4745 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
4746 vport->port_state = LPFC_FDISC;
4747 return 0;
4748}
4749
4750static void
4751lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4752 struct lpfc_iocbq *rspiocb)
4753{
4754 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05004755 IOCB_t *irsp;
James Smarte47c9092008-02-08 18:49:26 -05004756 struct lpfc_nodelist *ndlp;
4757 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
James Smart858c9f62007-06-17 19:56:39 -05004758
4759 irsp = &rspiocb->iocb;
4760 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4761 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
4762 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
James Smart92d7f7b2007-06-17 19:56:38 -05004763
4764 lpfc_els_free_iocb(phba, cmdiocb);
4765 vport->unreg_vpi_cmpl = VPORT_ERROR;
James Smarte47c9092008-02-08 18:49:26 -05004766
4767 /* Trigger the release of the ndlp after logo */
4768 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05004769}
4770
4771int
4772lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
4773{
4774 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4775 struct lpfc_hba *phba = vport->phba;
4776 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
4777 IOCB_t *icmd;
4778 struct lpfc_iocbq *elsiocb;
4779 uint8_t *pcmd;
4780 uint16_t cmdsize;
4781
4782 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
4783 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
4784 ELS_CMD_LOGO);
4785 if (!elsiocb)
4786 return 1;
4787
4788 icmd = &elsiocb->iocb;
4789 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4790 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
4791 pcmd += sizeof(uint32_t);
4792
4793 /* Fill in LOGO payload */
4794 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
4795 pcmd += sizeof(uint32_t);
4796 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
4797
James Smart858c9f62007-06-17 19:56:39 -05004798 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4799 "Issue LOGO npiv did:x%x flg:x%x",
4800 ndlp->nlp_DID, ndlp->nlp_flag, 0);
4801
James Smart92d7f7b2007-06-17 19:56:38 -05004802 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
4803 spin_lock_irq(shost->host_lock);
4804 ndlp->nlp_flag |= NLP_LOGO_SND;
4805 spin_unlock_irq(shost->host_lock);
4806 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
4807 spin_lock_irq(shost->host_lock);
4808 ndlp->nlp_flag &= ~NLP_LOGO_SND;
4809 spin_unlock_irq(shost->host_lock);
4810 lpfc_els_free_iocb(phba, elsiocb);
4811 return 1;
4812 }
4813 return 0;
4814}
4815
4816void
4817lpfc_fabric_block_timeout(unsigned long ptr)
4818{
4819 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
4820 unsigned long iflags;
4821 uint32_t tmo_posted;
4822 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
4823 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
4824 if (!tmo_posted)
4825 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
4826 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
4827
4828 if (!tmo_posted) {
4829 spin_lock_irqsave(&phba->hbalock, iflags);
4830 if (phba->work_wait)
4831 lpfc_worker_wake_up(phba);
4832 spin_unlock_irqrestore(&phba->hbalock, iflags);
4833 }
4834}
4835
4836static void
4837lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
4838{
4839 struct lpfc_iocbq *iocb;
4840 unsigned long iflags;
4841 int ret;
4842 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
4843 IOCB_t *cmd;
4844
4845repeat:
4846 iocb = NULL;
4847 spin_lock_irqsave(&phba->hbalock, iflags);
James Smart7f5f3d02008-02-08 18:50:14 -05004848 /* Post any pending iocb to the SLI layer */
James Smart92d7f7b2007-06-17 19:56:38 -05004849 if (atomic_read(&phba->fabric_iocb_count) == 0) {
4850 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
4851 list);
4852 if (iocb)
James Smart7f5f3d02008-02-08 18:50:14 -05004853 /* Increment fabric iocb count to hold the position */
James Smart92d7f7b2007-06-17 19:56:38 -05004854 atomic_inc(&phba->fabric_iocb_count);
4855 }
4856 spin_unlock_irqrestore(&phba->hbalock, iflags);
4857 if (iocb) {
4858 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
4859 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
4860 iocb->iocb_flag |= LPFC_IO_FABRIC;
4861
James Smart858c9f62007-06-17 19:56:39 -05004862 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
4863 "Fabric sched1: ste:x%x",
4864 iocb->vport->port_state, 0, 0);
4865
James Smart92d7f7b2007-06-17 19:56:38 -05004866 ret = lpfc_sli_issue_iocb(phba, pring, iocb, 0);
4867
4868 if (ret == IOCB_ERROR) {
4869 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
4870 iocb->fabric_iocb_cmpl = NULL;
4871 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
4872 cmd = &iocb->iocb;
4873 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
4874 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
4875 iocb->iocb_cmpl(phba, iocb, iocb);
4876
4877 atomic_dec(&phba->fabric_iocb_count);
4878 goto repeat;
4879 }
4880 }
4881
4882 return;
4883}
4884
4885void
4886lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
4887{
4888 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
4889
4890 lpfc_resume_fabric_iocbs(phba);
4891 return;
4892}
4893
4894static void
4895lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
4896{
4897 int blocked;
4898
4899 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
James Smart7f5f3d02008-02-08 18:50:14 -05004900 /* Start a timer to unblock fabric iocbs after 100ms */
James Smart92d7f7b2007-06-17 19:56:38 -05004901 if (!blocked)
4902 mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 );
4903
4904 return;
4905}
4906
4907static void
4908lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
4909 struct lpfc_iocbq *rspiocb)
4910{
4911 struct ls_rjt stat;
4912
4913 if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
4914 BUG();
4915
4916 switch (rspiocb->iocb.ulpStatus) {
4917 case IOSTAT_NPORT_RJT:
4918 case IOSTAT_FABRIC_RJT:
4919 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
4920 lpfc_block_fabric_iocbs(phba);
4921 }
4922 break;
4923
4924 case IOSTAT_NPORT_BSY:
4925 case IOSTAT_FABRIC_BSY:
4926 lpfc_block_fabric_iocbs(phba);
4927 break;
4928
4929 case IOSTAT_LS_RJT:
4930 stat.un.lsRjtError =
4931 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
4932 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
4933 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
4934 lpfc_block_fabric_iocbs(phba);
4935 break;
4936 }
4937
4938 if (atomic_read(&phba->fabric_iocb_count) == 0)
4939 BUG();
4940
4941 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
4942 cmdiocb->fabric_iocb_cmpl = NULL;
4943 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
4944 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
4945
4946 atomic_dec(&phba->fabric_iocb_count);
4947 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
James Smart7f5f3d02008-02-08 18:50:14 -05004948 /* Post any pending iocbs to HBA */
4949 lpfc_resume_fabric_iocbs(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05004950 }
4951}
4952
Adrian Bunka6ababd2007-11-05 18:07:33 +01004953static int
James Smart92d7f7b2007-06-17 19:56:38 -05004954lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
4955{
4956 unsigned long iflags;
4957 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
4958 int ready;
4959 int ret;
4960
4961 if (atomic_read(&phba->fabric_iocb_count) > 1)
4962 BUG();
4963
4964 spin_lock_irqsave(&phba->hbalock, iflags);
4965 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
4966 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
4967
James Smart7f5f3d02008-02-08 18:50:14 -05004968 if (ready)
4969 /* Increment fabric iocb count to hold the position */
4970 atomic_inc(&phba->fabric_iocb_count);
James Smart92d7f7b2007-06-17 19:56:38 -05004971 spin_unlock_irqrestore(&phba->hbalock, iflags);
4972 if (ready) {
4973 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
4974 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
4975 iocb->iocb_flag |= LPFC_IO_FABRIC;
4976
James Smart858c9f62007-06-17 19:56:39 -05004977 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
4978 "Fabric sched2: ste:x%x",
4979 iocb->vport->port_state, 0, 0);
4980
James Smart92d7f7b2007-06-17 19:56:38 -05004981 ret = lpfc_sli_issue_iocb(phba, pring, iocb, 0);
4982
4983 if (ret == IOCB_ERROR) {
4984 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
4985 iocb->fabric_iocb_cmpl = NULL;
4986 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
4987 atomic_dec(&phba->fabric_iocb_count);
4988 }
4989 } else {
4990 spin_lock_irqsave(&phba->hbalock, iflags);
4991 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
4992 spin_unlock_irqrestore(&phba->hbalock, iflags);
4993 ret = IOCB_SUCCESS;
4994 }
4995 return ret;
4996}
4997
4998
Adrian Bunka6ababd2007-11-05 18:07:33 +01004999static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
James Smart92d7f7b2007-06-17 19:56:38 -05005000{
5001 LIST_HEAD(completions);
5002 struct lpfc_hba *phba = vport->phba;
5003 struct lpfc_iocbq *tmp_iocb, *piocb;
5004 IOCB_t *cmd;
5005
5006 spin_lock_irq(&phba->hbalock);
5007 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
5008 list) {
5009
5010 if (piocb->vport != vport)
5011 continue;
5012
5013 list_move_tail(&piocb->list, &completions);
5014 }
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}
5027
5028void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
5029{
5030 LIST_HEAD(completions);
5031 struct lpfc_hba *phba = ndlp->vport->phba;
5032 struct lpfc_iocbq *tmp_iocb, *piocb;
5033 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
5034 IOCB_t *cmd;
5035
5036 spin_lock_irq(&phba->hbalock);
5037 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
5038 list) {
5039 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
5040
5041 list_move_tail(&piocb->list, &completions);
5042 }
5043 }
5044 spin_unlock_irq(&phba->hbalock);
5045
5046 while (!list_empty(&completions)) {
5047 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
5048 list_del_init(&piocb->list);
5049
5050 cmd = &piocb->iocb;
5051 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
5052 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
5053 (piocb->iocb_cmpl) (phba, piocb, piocb);
5054 }
5055}
5056
5057void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
5058{
5059 LIST_HEAD(completions);
5060 struct lpfc_iocbq *piocb;
5061 IOCB_t *cmd;
5062
5063 spin_lock_irq(&phba->hbalock);
5064 list_splice_init(&phba->fabric_iocb_list, &completions);
5065 spin_unlock_irq(&phba->hbalock);
5066
5067 while (!list_empty(&completions)) {
5068 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
5069 list_del_init(&piocb->list);
5070
5071 cmd = &piocb->iocb;
5072 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
5073 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
5074 (piocb->iocb_cmpl) (phba, piocb, piocb);
5075 }
5076}
5077
5078
Adrian Bunka6ababd2007-11-05 18:07:33 +01005079#if 0
James Smart92d7f7b2007-06-17 19:56:38 -05005080void lpfc_fabric_abort_flogi(struct lpfc_hba *phba)
5081{
5082 LIST_HEAD(completions);
5083 struct lpfc_iocbq *tmp_iocb, *piocb;
5084 IOCB_t *cmd;
5085 struct lpfc_nodelist *ndlp;
5086
5087 spin_lock_irq(&phba->hbalock);
5088 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
5089 list) {
5090
5091 cmd = &piocb->iocb;
5092 ndlp = (struct lpfc_nodelist *) piocb->context1;
5093 if (cmd->ulpCommand == CMD_ELS_REQUEST64_CR &&
5094 ndlp != NULL &&
5095 ndlp->nlp_DID == Fabric_DID)
5096 list_move_tail(&piocb->list, &completions);
5097 }
5098 spin_unlock_irq(&phba->hbalock);
5099
5100 while (!list_empty(&completions)) {
5101 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
5102 list_del_init(&piocb->list);
5103
5104 cmd = &piocb->iocb;
5105 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
5106 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
5107 (piocb->iocb_cmpl) (phba, piocb, piocb);
5108 }
5109}
Adrian Bunka6ababd2007-11-05 18:07:33 +01005110#endif /* 0 */
James Smart92d7f7b2007-06-17 19:56:38 -05005111
5112