blob: 2e24b4fe2be546936e4e3795fb5d25efd855618a [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 Smarte59058c2008-08-24 21:49:00 -040056/**
57 * lpfc_els_chk_latt: Check host link attention event for a vport.
58 * @vport: pointer to a host virtual N_Port data structure.
59 *
60 * This routine checks whether there is an outstanding host link
61 * attention event during the discovery process with the @vport. It is done
62 * by reading the HBA's Host Attention (HA) register. If there is any host
63 * link attention events during this @vport's discovery process, the @vport
64 * shall be marked as FC_ABORT_DISCOVERY, a host link attention clear shall
65 * be issued if the link state is not already in host link cleared state,
66 * and a return code shall indicate whether the host link attention event
67 * had happened.
68 *
69 * Note that, if either the host link is in state LPFC_LINK_DOWN or @vport
70 * state in LPFC_VPORT_READY, the request for checking host link attention
71 * event will be ignored and a return code shall indicate no host link
72 * attention event had happened.
73 *
74 * Return codes
75 * 0 - no host link attention event happened
76 * 1 - host link attention event happened
77 **/
James Smart858c9f62007-06-17 19:56:39 -050078int
James Smart2e0fef82007-06-17 19:56:36 -050079lpfc_els_chk_latt(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -050080{
James Smart2e0fef82007-06-17 19:56:36 -050081 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
82 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -050083 uint32_t ha_copy;
dea31012005-04-17 16:05:31 -050084
James Smart2e0fef82007-06-17 19:56:36 -050085 if (vport->port_state >= LPFC_VPORT_READY ||
86 phba->link_state == LPFC_LINK_DOWN)
dea31012005-04-17 16:05:31 -050087 return 0;
88
89 /* Read the HBA Host Attention Register */
dea31012005-04-17 16:05:31 -050090 ha_copy = readl(phba->HAregaddr);
dea31012005-04-17 16:05:31 -050091
92 if (!(ha_copy & HA_LATT))
93 return 0;
94
95 /* Pending Link Event during Discovery */
James Smarte8b62012007-08-02 11:10:09 -040096 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
97 "0237 Pending Link Event during "
98 "Discovery: State x%x\n",
99 phba->pport->port_state);
dea31012005-04-17 16:05:31 -0500100
101 /* CLEAR_LA should re-enable link attention events and
102 * we should then imediately take a LATT event. The
103 * LATT processing should call lpfc_linkdown() which
104 * will cleanup any left over in-progress discovery
105 * events.
106 */
James Smart2e0fef82007-06-17 19:56:36 -0500107 spin_lock_irq(shost->host_lock);
108 vport->fc_flag |= FC_ABORT_DISCOVERY;
109 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500110
James Smart92d7f7b2007-06-17 19:56:38 -0500111 if (phba->link_state != LPFC_CLEAR_LA)
James Smarted957682007-06-17 19:56:37 -0500112 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -0500113
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500114 return 1;
dea31012005-04-17 16:05:31 -0500115}
116
James Smarte59058c2008-08-24 21:49:00 -0400117/**
118 * lpfc_prep_els_iocb: Allocate and prepare a lpfc iocb data structure.
119 * @vport: pointer to a host virtual N_Port data structure.
120 * @expectRsp: flag indicating whether response is expected.
121 * @cmdSize: size of the ELS command.
122 * @retry: number of retries to the command IOCB when it fails.
123 * @ndlp: pointer to a node-list data structure.
124 * @did: destination identifier.
125 * @elscmd: the ELS command code.
126 *
127 * This routine is used for allocating a lpfc-IOCB data structure from
128 * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters
129 * passed into the routine for discovery state machine to issue an Extended
130 * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation
131 * and preparation routine that is used by all the discovery state machine
132 * routines and the ELS command-specific fields will be later set up by
133 * the individual discovery machine routines after calling this routine
134 * allocating and preparing a generic IOCB data structure. It fills in the
135 * Buffer Descriptor Entries (BDEs), allocates buffers for both command
136 * payload and response payload (if expected). The reference count on the
137 * ndlp is incremented by 1 and the reference to the ndlp is put into
138 * context1 of the IOCB data structure for this IOCB to hold the ndlp
139 * reference for the command's callback function to access later.
140 *
141 * Return code
142 * Pointer to the newly allocated/prepared els iocb data structure
143 * NULL - when els iocb data structure allocation/preparation failed
144 **/
dea31012005-04-17 16:05:31 -0500145static struct lpfc_iocbq *
James Smart2e0fef82007-06-17 19:56:36 -0500146lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp,
147 uint16_t cmdSize, uint8_t retry,
148 struct lpfc_nodelist *ndlp, uint32_t did,
149 uint32_t elscmd)
dea31012005-04-17 16:05:31 -0500150{
James Smart2e0fef82007-06-17 19:56:36 -0500151 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400152 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -0500153 struct lpfc_dmabuf *pcmd, *prsp, *pbuflist;
154 struct ulp_bde64 *bpl;
155 IOCB_t *icmd;
156
dea31012005-04-17 16:05:31 -0500157
James Smart2e0fef82007-06-17 19:56:36 -0500158 if (!lpfc_is_link_up(phba))
159 return NULL;
dea31012005-04-17 16:05:31 -0500160
dea31012005-04-17 16:05:31 -0500161 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400162 elsiocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -0500163
164 if (elsiocb == NULL)
165 return NULL;
James Smarte47c9092008-02-08 18:49:26 -0500166
dea31012005-04-17 16:05:31 -0500167 icmd = &elsiocb->iocb;
168
169 /* fill in BDEs for command */
170 /* Allocate buffer for command payload */
James Smart98c9ea52007-10-27 13:37:33 -0400171 pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
172 if (pcmd)
173 pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500174 if (!pcmd || !pcmd->virt)
175 goto els_iocb_free_pcmb_exit;
dea31012005-04-17 16:05:31 -0500176
177 INIT_LIST_HEAD(&pcmd->list);
178
179 /* Allocate buffer for response payload */
180 if (expectRsp) {
James Smart92d7f7b2007-06-17 19:56:38 -0500181 prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -0500182 if (prsp)
183 prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
184 &prsp->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500185 if (!prsp || !prsp->virt)
186 goto els_iocb_free_prsp_exit;
dea31012005-04-17 16:05:31 -0500187 INIT_LIST_HEAD(&prsp->list);
James Smarte47c9092008-02-08 18:49:26 -0500188 } else
dea31012005-04-17 16:05:31 -0500189 prsp = NULL;
dea31012005-04-17 16:05:31 -0500190
191 /* Allocate buffer for Buffer ptr list */
James Smart92d7f7b2007-06-17 19:56:38 -0500192 pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -0500193 if (pbuflist)
James Smarted957682007-06-17 19:56:37 -0500194 pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
195 &pbuflist->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500196 if (!pbuflist || !pbuflist->virt)
197 goto els_iocb_free_pbuf_exit;
dea31012005-04-17 16:05:31 -0500198
199 INIT_LIST_HEAD(&pbuflist->list);
200
201 icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
202 icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
203 icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BDL;
James Smart2e0fef82007-06-17 19:56:36 -0500204 icmd->un.elsreq64.remoteID = did; /* DID */
dea31012005-04-17 16:05:31 -0500205 if (expectRsp) {
James Smart92d7f7b2007-06-17 19:56:38 -0500206 icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
dea31012005-04-17 16:05:31 -0500207 icmd->ulpCommand = CMD_ELS_REQUEST64_CR;
James Smart2680eea2007-04-25 09:52:55 -0400208 icmd->ulpTimeout = phba->fc_ratov * 2;
dea31012005-04-17 16:05:31 -0500209 } else {
James Smart92d7f7b2007-06-17 19:56:38 -0500210 icmd->un.elsreq64.bdl.bdeSize = sizeof(struct ulp_bde64);
dea31012005-04-17 16:05:31 -0500211 icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
212 }
dea31012005-04-17 16:05:31 -0500213 icmd->ulpBdeCount = 1;
214 icmd->ulpLe = 1;
215 icmd->ulpClass = CLASS3;
216
James Smart92d7f7b2007-06-17 19:56:38 -0500217 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
218 icmd->un.elsreq64.myID = vport->fc_myDID;
219
220 /* For ELS_REQUEST64_CR, use the VPI by default */
221 icmd->ulpContext = vport->vpi;
222 icmd->ulpCt_h = 0;
223 icmd->ulpCt_l = 1;
224 }
225
dea31012005-04-17 16:05:31 -0500226 bpl = (struct ulp_bde64 *) pbuflist->virt;
227 bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys));
228 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys));
229 bpl->tus.f.bdeSize = cmdSize;
230 bpl->tus.f.bdeFlags = 0;
231 bpl->tus.w = le32_to_cpu(bpl->tus.w);
232
233 if (expectRsp) {
234 bpl++;
235 bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys));
236 bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys));
237 bpl->tus.f.bdeSize = FCELSSIZE;
238 bpl->tus.f.bdeFlags = BUFF_USE_RCV;
239 bpl->tus.w = le32_to_cpu(bpl->tus.w);
240 }
241
James Smartfa4066b2008-01-11 01:53:27 -0500242 /* prevent preparing iocb with NULL ndlp reference */
James Smart51ef4c22007-08-02 11:10:31 -0400243 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -0500244 if (!elsiocb->context1)
245 goto els_iocb_free_pbuf_exit;
James Smart329f9bc2007-04-25 09:53:01 -0400246 elsiocb->context2 = pcmd;
247 elsiocb->context3 = pbuflist;
dea31012005-04-17 16:05:31 -0500248 elsiocb->retry = retry;
James Smart2e0fef82007-06-17 19:56:36 -0500249 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -0500250 elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
251
252 if (prsp) {
253 list_add(&prsp->list, &pcmd->list);
254 }
dea31012005-04-17 16:05:31 -0500255 if (expectRsp) {
256 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400257 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
258 "0116 Xmit ELS command x%x to remote "
259 "NPORT x%x I/O tag: x%x, port state: x%x\n",
260 elscmd, did, elsiocb->iotag,
261 vport->port_state);
dea31012005-04-17 16:05:31 -0500262 } else {
263 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400264 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
265 "0117 Xmit ELS response x%x to remote "
266 "NPORT x%x I/O tag: x%x, size: x%x\n",
267 elscmd, ndlp->nlp_DID, elsiocb->iotag,
268 cmdSize);
dea31012005-04-17 16:05:31 -0500269 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500270 return elsiocb;
dea31012005-04-17 16:05:31 -0500271
James Smartfa4066b2008-01-11 01:53:27 -0500272els_iocb_free_pbuf_exit:
273 lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
274 kfree(pbuflist);
275
276els_iocb_free_prsp_exit:
277 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
278 kfree(prsp);
279
280els_iocb_free_pcmb_exit:
281 kfree(pcmd);
282 lpfc_sli_release_iocbq(phba, elsiocb);
283 return NULL;
284}
dea31012005-04-17 16:05:31 -0500285
James Smarte59058c2008-08-24 21:49:00 -0400286/**
287 * lpfc_issue_fabric_reglogin: Issue fabric registration login for a vport.
288 * @vport: pointer to a host virtual N_Port data structure.
289 *
290 * This routine issues a fabric registration login for a @vport. An
291 * active ndlp node with Fabric_DID must already exist for this @vport.
292 * The routine invokes two mailbox commands to carry out fabric registration
293 * login through the HBA firmware: the first mailbox command requests the
294 * HBA to perform link configuration for the @vport; and the second mailbox
295 * command requests the HBA to perform the actual fabric registration login
296 * with the @vport.
297 *
298 * Return code
299 * 0 - successfully issued fabric registration login for @vport
300 * -ENXIO -- failed to issue fabric registration login for @vport
301 **/
dea31012005-04-17 16:05:31 -0500302static int
James Smart92d7f7b2007-06-17 19:56:38 -0500303lpfc_issue_fabric_reglogin(struct lpfc_vport *vport)
304{
305 struct lpfc_hba *phba = vport->phba;
306 LPFC_MBOXQ_t *mbox;
307 struct lpfc_dmabuf *mp;
308 struct lpfc_nodelist *ndlp;
309 struct serv_parm *sp;
310 int rc;
James Smart98c9ea52007-10-27 13:37:33 -0400311 int err = 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500312
313 sp = &phba->fc_fabparam;
314 ndlp = lpfc_findnode_did(vport, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -0500315 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -0400316 err = 1;
James Smart92d7f7b2007-06-17 19:56:38 -0500317 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400318 }
James Smart92d7f7b2007-06-17 19:56:38 -0500319
320 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart98c9ea52007-10-27 13:37:33 -0400321 if (!mbox) {
322 err = 2;
James Smart92d7f7b2007-06-17 19:56:38 -0500323 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400324 }
James Smart92d7f7b2007-06-17 19:56:38 -0500325
326 vport->port_state = LPFC_FABRIC_CFG_LINK;
327 lpfc_config_link(phba, mbox);
328 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
329 mbox->vport = vport;
330
James Smart0b727fe2007-10-27 13:37:25 -0400331 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart98c9ea52007-10-27 13:37:33 -0400332 if (rc == MBX_NOT_FINISHED) {
333 err = 3;
James Smart92d7f7b2007-06-17 19:56:38 -0500334 goto fail_free_mbox;
James Smart98c9ea52007-10-27 13:37:33 -0400335 }
James Smart92d7f7b2007-06-17 19:56:38 -0500336
337 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart98c9ea52007-10-27 13:37:33 -0400338 if (!mbox) {
339 err = 4;
James Smart92d7f7b2007-06-17 19:56:38 -0500340 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400341 }
James Smart92d7f7b2007-06-17 19:56:38 -0500342 rc = lpfc_reg_login(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox,
343 0);
James Smart98c9ea52007-10-27 13:37:33 -0400344 if (rc) {
345 err = 5;
James Smart92d7f7b2007-06-17 19:56:38 -0500346 goto fail_free_mbox;
James Smart98c9ea52007-10-27 13:37:33 -0400347 }
James Smart92d7f7b2007-06-17 19:56:38 -0500348
349 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
350 mbox->vport = vport;
James Smarte47c9092008-02-08 18:49:26 -0500351 /* increment the reference count on ndlp to hold reference
352 * for the callback routine.
353 */
James Smart92d7f7b2007-06-17 19:56:38 -0500354 mbox->context2 = lpfc_nlp_get(ndlp);
355
James Smart0b727fe2007-10-27 13:37:25 -0400356 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart98c9ea52007-10-27 13:37:33 -0400357 if (rc == MBX_NOT_FINISHED) {
358 err = 6;
James Smart92d7f7b2007-06-17 19:56:38 -0500359 goto fail_issue_reg_login;
James Smart98c9ea52007-10-27 13:37:33 -0400360 }
James Smart92d7f7b2007-06-17 19:56:38 -0500361
362 return 0;
363
364fail_issue_reg_login:
James Smarte47c9092008-02-08 18:49:26 -0500365 /* decrement the reference count on ndlp just incremented
366 * for the failed mbox command.
367 */
James Smart92d7f7b2007-06-17 19:56:38 -0500368 lpfc_nlp_put(ndlp);
369 mp = (struct lpfc_dmabuf *) mbox->context1;
370 lpfc_mbuf_free(phba, mp->virt, mp->phys);
371 kfree(mp);
372fail_free_mbox:
373 mempool_free(mbox, phba->mbox_mem_pool);
374
375fail:
376 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -0400377 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smart98c9ea52007-10-27 13:37:33 -0400378 "0249 Cannot issue Register Fabric login: Err %d\n", err);
James Smart92d7f7b2007-06-17 19:56:38 -0500379 return -ENXIO;
380}
381
James Smarte59058c2008-08-24 21:49:00 -0400382/**
383 * lpfc_cmpl_els_flogi_fabric: Completion function for flogi to a fabric port.
384 * @vport: pointer to a host virtual N_Port data structure.
385 * @ndlp: pointer to a node-list data structure.
386 * @sp: pointer to service parameter data structure.
387 * @irsp: pointer to the IOCB within the lpfc response IOCB.
388 *
389 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
390 * function to handle the completion of a Fabric Login (FLOGI) into a fabric
391 * port in a fabric topology. It properly sets up the parameters to the @ndlp
392 * from the IOCB response. It also check the newly assigned N_Port ID to the
393 * @vport against the previously assigned N_Port ID. If it is different from
394 * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
395 * is invoked on all the remaining nodes with the @vport to unregister the
396 * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
397 * is invoked to register login to the fabric.
398 *
399 * Return code
400 * 0 - Success (currently, always return 0)
401 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500402static int
James Smart2e0fef82007-06-17 19:56:36 -0500403lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
404 struct serv_parm *sp, IOCB_t *irsp)
dea31012005-04-17 16:05:31 -0500405{
James Smart2e0fef82007-06-17 19:56:36 -0500406 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
407 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -0500408 struct lpfc_nodelist *np;
409 struct lpfc_nodelist *next_np;
dea31012005-04-17 16:05:31 -0500410
James Smart2e0fef82007-06-17 19:56:36 -0500411 spin_lock_irq(shost->host_lock);
412 vport->fc_flag |= FC_FABRIC;
413 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500414
415 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
416 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
417 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
418
419 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
420
421 if (phba->fc_topology == TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500422 spin_lock_irq(shost->host_lock);
423 vport->fc_flag |= FC_PUBLIC_LOOP;
424 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500425 } else {
426 /*
427 * If we are a N-port connected to a Fabric, fixup sparam's so
428 * logins to devices on remote loops work.
429 */
James Smart2e0fef82007-06-17 19:56:36 -0500430 vport->fc_sparam.cmn.altBbCredit = 1;
dea31012005-04-17 16:05:31 -0500431 }
432
James Smart2e0fef82007-06-17 19:56:36 -0500433 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
dea31012005-04-17 16:05:31 -0500434 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
James Smart92d7f7b2007-06-17 19:56:38 -0500435 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500436 ndlp->nlp_class_sup = 0;
437 if (sp->cls1.classValid)
438 ndlp->nlp_class_sup |= FC_COS_CLASS1;
439 if (sp->cls2.classValid)
440 ndlp->nlp_class_sup |= FC_COS_CLASS2;
441 if (sp->cls3.classValid)
442 ndlp->nlp_class_sup |= FC_COS_CLASS3;
443 if (sp->cls4.classValid)
444 ndlp->nlp_class_sup |= FC_COS_CLASS4;
445 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
446 sp->cmn.bbRcvSizeLsb;
447 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
448
James Smart92d7f7b2007-06-17 19:56:38 -0500449 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
450 if (sp->cmn.response_multiple_NPort) {
James Smarte8b62012007-08-02 11:10:09 -0400451 lpfc_printf_vlog(vport, KERN_WARNING,
452 LOG_ELS | LOG_VPORT,
453 "1816 FLOGI NPIV supported, "
454 "response data 0x%x\n",
455 sp->cmn.response_multiple_NPort);
James Smart92d7f7b2007-06-17 19:56:38 -0500456 phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
James Smart92d7f7b2007-06-17 19:56:38 -0500457 } else {
458 /* Because we asked f/w for NPIV it still expects us
James Smarte8b62012007-08-02 11:10:09 -0400459 to call reg_vnpid atleast for the physcial host */
460 lpfc_printf_vlog(vport, KERN_WARNING,
461 LOG_ELS | LOG_VPORT,
462 "1817 Fabric does not support NPIV "
463 "- configuring single port mode.\n");
James Smart92d7f7b2007-06-17 19:56:38 -0500464 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
465 }
466 }
467
468 if ((vport->fc_prevDID != vport->fc_myDID) &&
469 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
470
471 /* If our NportID changed, we need to ensure all
472 * remaining NPORTs get unreg_login'ed.
473 */
474 list_for_each_entry_safe(np, next_np,
475 &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -0500476 if (!NLP_CHK_NODE_ACT(ndlp))
477 continue;
James Smart92d7f7b2007-06-17 19:56:38 -0500478 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
479 !(np->nlp_flag & NLP_NPR_ADISC))
480 continue;
481 spin_lock_irq(shost->host_lock);
482 np->nlp_flag &= ~NLP_NPR_ADISC;
483 spin_unlock_irq(shost->host_lock);
484 lpfc_unreg_rpi(vport, np);
485 }
486 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
487 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -0500488 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500489 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -0500490 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500491 }
492 }
493
James Smart92d7f7b2007-06-17 19:56:38 -0500494 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -0500495
James Smart92d7f7b2007-06-17 19:56:38 -0500496 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
497 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) {
498 lpfc_register_new_vport(phba, vport, ndlp);
499 return 0;
500 }
501 lpfc_issue_fabric_reglogin(vport);
dea31012005-04-17 16:05:31 -0500502 return 0;
dea31012005-04-17 16:05:31 -0500503}
504
James Smarte59058c2008-08-24 21:49:00 -0400505/**
506 * lpfc_cmpl_els_flogi_nport: Completion function for flogi to an N_Port.
507 * @vport: pointer to a host virtual N_Port data structure.
508 * @ndlp: pointer to a node-list data structure.
509 * @sp: pointer to service parameter data structure.
510 *
511 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
512 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
513 * in a point-to-point topology. First, the @vport's N_Port Name is compared
514 * with the received N_Port Name: if the @vport's N_Port Name is greater than
515 * the received N_Port Name lexicographically, this node shall assign local
516 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
517 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
518 * this node shall just wait for the remote node to issue PLOGI and assign
519 * N_Port IDs.
520 *
521 * Return code
522 * 0 - Success
523 * -ENXIO - Fail
524 **/
dea31012005-04-17 16:05:31 -0500525static int
James Smart2e0fef82007-06-17 19:56:36 -0500526lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
527 struct serv_parm *sp)
dea31012005-04-17 16:05:31 -0500528{
James Smart2e0fef82007-06-17 19:56:36 -0500529 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
530 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500531 LPFC_MBOXQ_t *mbox;
532 int rc;
533
James Smart2e0fef82007-06-17 19:56:36 -0500534 spin_lock_irq(shost->host_lock);
535 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
536 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500537
538 phba->fc_edtov = FF_DEF_EDTOV;
539 phba->fc_ratov = FF_DEF_RATOV;
James Smart2e0fef82007-06-17 19:56:36 -0500540 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -0500541 sizeof(vport->fc_portname));
dea31012005-04-17 16:05:31 -0500542 if (rc >= 0) {
543 /* This side will initiate the PLOGI */
James Smart2e0fef82007-06-17 19:56:36 -0500544 spin_lock_irq(shost->host_lock);
545 vport->fc_flag |= FC_PT2PT_PLOGI;
546 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500547
548 /*
549 * N_Port ID cannot be 0, set our to LocalID the other
550 * side will be RemoteID.
551 */
552
553 /* not equal */
554 if (rc)
James Smart2e0fef82007-06-17 19:56:36 -0500555 vport->fc_myDID = PT2PT_LocalID;
dea31012005-04-17 16:05:31 -0500556
557 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
558 if (!mbox)
559 goto fail;
560
561 lpfc_config_link(phba, mbox);
562
563 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -0500564 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -0400565 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -0500566 if (rc == MBX_NOT_FINISHED) {
567 mempool_free(mbox, phba->mbox_mem_pool);
568 goto fail;
569 }
James Smarte47c9092008-02-08 18:49:26 -0500570 /* Decrement ndlp reference count indicating that ndlp can be
571 * safely released when other references to it are done.
572 */
James Smart329f9bc2007-04-25 09:53:01 -0400573 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500574
James Smart2e0fef82007-06-17 19:56:36 -0500575 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
dea31012005-04-17 16:05:31 -0500576 if (!ndlp) {
577 /*
578 * Cannot find existing Fabric ndlp, so allocate a
579 * new one
580 */
581 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
582 if (!ndlp)
583 goto fail;
James Smart2e0fef82007-06-17 19:56:36 -0500584 lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID);
James Smarte47c9092008-02-08 18:49:26 -0500585 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
586 ndlp = lpfc_enable_node(vport, ndlp,
587 NLP_STE_UNUSED_NODE);
588 if(!ndlp)
589 goto fail;
dea31012005-04-17 16:05:31 -0500590 }
591
592 memcpy(&ndlp->nlp_portname, &sp->portName,
James Smart2e0fef82007-06-17 19:56:36 -0500593 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500594 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
James Smart2e0fef82007-06-17 19:56:36 -0500595 sizeof(struct lpfc_name));
James Smarte47c9092008-02-08 18:49:26 -0500596 /* Set state will put ndlp onto node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -0500597 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
598 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500599 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500600 spin_unlock_irq(shost->host_lock);
James Smarte47c9092008-02-08 18:49:26 -0500601 } else
602 /* This side will wait for the PLOGI, decrement ndlp reference
603 * count indicating that ndlp can be released when other
604 * references to it are done.
605 */
James Smart329f9bc2007-04-25 09:53:01 -0400606 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500607
James Smart09372822008-01-11 01:52:54 -0500608 /* If we are pt2pt with another NPort, force NPIV off! */
609 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
610
James Smart2e0fef82007-06-17 19:56:36 -0500611 spin_lock_irq(shost->host_lock);
612 vport->fc_flag |= FC_PT2PT;
613 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500614
615 /* Start discovery - this should just do CLEAR_LA */
James Smart2e0fef82007-06-17 19:56:36 -0500616 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -0500617 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500618fail:
dea31012005-04-17 16:05:31 -0500619 return -ENXIO;
620}
621
James Smarte59058c2008-08-24 21:49:00 -0400622/**
623 * lpfc_cmpl_els_flogi: Completion callback function for flogi.
624 * @phba: pointer to lpfc hba data structure.
625 * @cmdiocb: pointer to lpfc command iocb data structure.
626 * @rspiocb: pointer to lpfc response iocb data structure.
627 *
628 * This routine is the top-level completion callback function for issuing
629 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
630 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
631 * retry has been made (either immediately or delayed with lpfc_els_retry()
632 * returning 1), the command IOCB will be released and function returned.
633 * If the retry attempt has been given up (possibly reach the maximum
634 * number of retries), one additional decrement of ndlp reference shall be
635 * invoked before going out after releasing the command IOCB. This will
636 * actually release the remote node (Note, lpfc_els_free_iocb() will also
637 * invoke one decrement of ndlp reference count). If no error reported in
638 * the IOCB status, the command Port ID field is used to determine whether
639 * this is a point-to-point topology or a fabric topology: if the Port ID
640 * field is assigned, it is a fabric topology; otherwise, it is a
641 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
642 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
643 * specific topology completion conditions.
644 **/
dea31012005-04-17 16:05:31 -0500645static void
James Smart329f9bc2007-04-25 09:53:01 -0400646lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
647 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500648{
James Smart2e0fef82007-06-17 19:56:36 -0500649 struct lpfc_vport *vport = cmdiocb->vport;
650 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500651 IOCB_t *irsp = &rspiocb->iocb;
652 struct lpfc_nodelist *ndlp = cmdiocb->context1;
653 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
654 struct serv_parm *sp;
655 int rc;
656
657 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500658 if (lpfc_els_chk_latt(vport)) {
James Smartfa4066b2008-01-11 01:53:27 -0500659 /* One additional decrement on node reference count to
660 * trigger the release of the node
661 */
James Smart329f9bc2007-04-25 09:53:01 -0400662 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500663 goto out;
664 }
665
James Smart858c9f62007-06-17 19:56:39 -0500666 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
667 "FLOGI cmpl: status:x%x/x%x state:x%x",
668 irsp->ulpStatus, irsp->un.ulpWord[4],
669 vport->port_state);
670
dea31012005-04-17 16:05:31 -0500671 if (irsp->ulpStatus) {
672 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -0500673 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -0500674 goto out;
James Smart2e0fef82007-06-17 19:56:36 -0500675
dea31012005-04-17 16:05:31 -0500676 /* FLOGI failed, so there is no fabric */
James Smart2e0fef82007-06-17 19:56:36 -0500677 spin_lock_irq(shost->host_lock);
678 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
679 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500680
James Smart329f9bc2007-04-25 09:53:01 -0400681 /* If private loop, then allow max outstanding els to be
dea31012005-04-17 16:05:31 -0500682 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
683 * alpa map would take too long otherwise.
684 */
685 if (phba->alpa_map[0] == 0) {
James Smart3de2a652007-08-02 11:09:59 -0400686 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
dea31012005-04-17 16:05:31 -0500687 }
688
689 /* FLOGI failure */
James Smarte8b62012007-08-02 11:10:09 -0400690 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
691 "0100 FLOGI failure Data: x%x x%x "
692 "x%x\n",
693 irsp->ulpStatus, irsp->un.ulpWord[4],
694 irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -0500695 goto flogifail;
696 }
697
698 /*
699 * The FLogI succeeded. Sync the data for the CPU before
700 * accessing it.
701 */
702 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
703
704 sp = prsp->virt + sizeof(uint32_t);
705
706 /* FLOGI completes successfully */
James Smarte8b62012007-08-02 11:10:09 -0400707 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
708 "0101 FLOGI completes sucessfully "
709 "Data: x%x x%x x%x x%x\n",
710 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
711 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution);
dea31012005-04-17 16:05:31 -0500712
James Smart2e0fef82007-06-17 19:56:36 -0500713 if (vport->port_state == LPFC_FLOGI) {
dea31012005-04-17 16:05:31 -0500714 /*
715 * If Common Service Parameters indicate Nport
716 * we are point to point, if Fport we are Fabric.
717 */
718 if (sp->cmn.fPort)
James Smart2e0fef82007-06-17 19:56:36 -0500719 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
dea31012005-04-17 16:05:31 -0500720 else
James Smart2e0fef82007-06-17 19:56:36 -0500721 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
dea31012005-04-17 16:05:31 -0500722
723 if (!rc)
724 goto out;
725 }
726
727flogifail:
James Smart329f9bc2007-04-25 09:53:01 -0400728 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500729
James Smart858c9f62007-06-17 19:56:39 -0500730 if (!lpfc_error_lost_link(irsp)) {
dea31012005-04-17 16:05:31 -0500731 /* FLOGI failed, so just use loop map to make discovery list */
James Smart2e0fef82007-06-17 19:56:36 -0500732 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -0500733
734 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500735 lpfc_disc_start(vport);
James Smart87af33f2007-10-27 13:37:43 -0400736 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
737 ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) &&
738 (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) &&
739 (phba->link_state != LPFC_CLEAR_LA)) {
740 /* If FLOGI failed enable link interrupt. */
741 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -0500742 }
dea31012005-04-17 16:05:31 -0500743out:
744 lpfc_els_free_iocb(phba, cmdiocb);
745}
746
James Smarte59058c2008-08-24 21:49:00 -0400747/**
748 * lpfc_issue_els_flogi: Issue an flogi iocb command for a vport.
749 * @vport: pointer to a host virtual N_Port data structure.
750 * @ndlp: pointer to a node-list data structure.
751 * @retry: number of retries to the command IOCB.
752 *
753 * This routine issues a Fabric Login (FLOGI) Request ELS command
754 * for a @vport. The initiator service parameters are put into the payload
755 * of the FLOGI Request IOCB and the top-level callback function pointer
756 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
757 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
758 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
759 *
760 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
761 * will be incremented by 1 for holding the ndlp and the reference to ndlp
762 * will be stored into the context1 field of the IOCB for the completion
763 * callback function to the FLOGI ELS command.
764 *
765 * Return code
766 * 0 - successfully issued flogi iocb for @vport
767 * 1 - failed to issue flogi iocb for @vport
768 **/
dea31012005-04-17 16:05:31 -0500769static int
James Smart2e0fef82007-06-17 19:56:36 -0500770lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -0500771 uint8_t retry)
772{
James Smart2e0fef82007-06-17 19:56:36 -0500773 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500774 struct serv_parm *sp;
775 IOCB_t *icmd;
776 struct lpfc_iocbq *elsiocb;
777 struct lpfc_sli_ring *pring;
778 uint8_t *pcmd;
779 uint16_t cmdsize;
780 uint32_t tmo;
781 int rc;
782
783 pring = &phba->sli.ring[LPFC_ELS_RING];
784
James Smart92d7f7b2007-06-17 19:56:38 -0500785 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart2e0fef82007-06-17 19:56:36 -0500786 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
787 ndlp->nlp_DID, ELS_CMD_FLOGI);
James Smart92d7f7b2007-06-17 19:56:38 -0500788
James Smart488d1462006-03-07 15:02:37 -0500789 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500790 return 1;
dea31012005-04-17 16:05:31 -0500791
792 icmd = &elsiocb->iocb;
793 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
794
795 /* For FLOGI request, remainder of payload is service parameters */
796 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -0500797 pcmd += sizeof(uint32_t);
798 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -0500799 sp = (struct serv_parm *) pcmd;
800
801 /* Setup CSPs accordingly for Fabric */
802 sp->cmn.e_d_tov = 0;
803 sp->cmn.w2.r_a_tov = 0;
804 sp->cls1.classValid = 0;
805 sp->cls2.seqDelivery = 1;
806 sp->cls3.seqDelivery = 1;
807 if (sp->cmn.fcphLow < FC_PH3)
808 sp->cmn.fcphLow = FC_PH3;
809 if (sp->cmn.fcphHigh < FC_PH3)
810 sp->cmn.fcphHigh = FC_PH3;
811
James Smart92d7f7b2007-06-17 19:56:38 -0500812 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
813 sp->cmn.request_multiple_Nport = 1;
814
815 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
816 icmd->ulpCt_h = 1;
817 icmd->ulpCt_l = 0;
818 }
819
James Smart858c9f62007-06-17 19:56:39 -0500820 if (phba->fc_topology != TOPOLOGY_LOOP) {
821 icmd->un.elsreq64.myID = 0;
822 icmd->un.elsreq64.fl = 1;
823 }
824
dea31012005-04-17 16:05:31 -0500825 tmo = phba->fc_ratov;
826 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
James Smart2e0fef82007-06-17 19:56:36 -0500827 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -0500828 phba->fc_ratov = tmo;
829
830 phba->fc_stat.elsXmitFLOGI++;
831 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
James Smart858c9f62007-06-17 19:56:39 -0500832
833 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
834 "Issue FLOGI: opt:x%x",
835 phba->sli3_options, 0, 0);
836
James Smart92d7f7b2007-06-17 19:56:38 -0500837 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
dea31012005-04-17 16:05:31 -0500838 if (rc == IOCB_ERROR) {
839 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500840 return 1;
dea31012005-04-17 16:05:31 -0500841 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500842 return 0;
dea31012005-04-17 16:05:31 -0500843}
844
James Smarte59058c2008-08-24 21:49:00 -0400845/**
846 * lpfc_els_abort_flogi: Abort all outstanding flogi iocbs.
847 * @phba: pointer to lpfc hba data structure.
848 *
849 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
850 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
851 * list and issues an abort IOCB commond on each outstanding IOCB that
852 * contains a active Fabric_DID ndlp. Note that this function is to issue
853 * the abort IOCB command on all the outstanding IOCBs, thus when this
854 * function returns, it does not guarantee all the IOCBs are actually aborted.
855 *
856 * Return code
857 * 0 - Sucessfully issued abort iocb on all outstanding flogis (Always 0)
858 **/
dea31012005-04-17 16:05:31 -0500859int
James Smart2e0fef82007-06-17 19:56:36 -0500860lpfc_els_abort_flogi(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500861{
862 struct lpfc_sli_ring *pring;
863 struct lpfc_iocbq *iocb, *next_iocb;
864 struct lpfc_nodelist *ndlp;
865 IOCB_t *icmd;
866
867 /* Abort outstanding I/O on NPort <nlp_DID> */
868 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -0400869 "0201 Abort outstanding I/O on NPort x%x\n",
870 Fabric_DID);
dea31012005-04-17 16:05:31 -0500871
872 pring = &phba->sli.ring[LPFC_ELS_RING];
873
874 /*
875 * Check the txcmplq for an iocb that matches the nport the driver is
876 * searching for.
877 */
James Smart2e0fef82007-06-17 19:56:36 -0500878 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500879 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
880 icmd = &iocb->iocb;
James Smart2e0fef82007-06-17 19:56:36 -0500881 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR &&
882 icmd->un.elsreq64.bdl.ulpIoTag32) {
dea31012005-04-17 16:05:31 -0500883 ndlp = (struct lpfc_nodelist *)(iocb->context1);
James Smart58da1ff2008-04-07 10:15:56 -0400884 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
885 (ndlp->nlp_DID == Fabric_DID))
James Smart07951072007-04-25 09:51:38 -0400886 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
dea31012005-04-17 16:05:31 -0500887 }
888 }
James Smart2e0fef82007-06-17 19:56:36 -0500889 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500890
891 return 0;
892}
893
James Smarte59058c2008-08-24 21:49:00 -0400894/**
895 * lpfc_initial_flogi: Issue an initial fabric login for a vport.
896 * @vport: pointer to a host virtual N_Port data structure.
897 *
898 * This routine issues an initial Fabric Login (FLOGI) for the @vport
899 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
900 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
901 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
902 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
903 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
904 * @vport.
905 *
906 * Return code
907 * 0 - failed to issue initial flogi for @vport
908 * 1 - successfully issued initial flogi for @vport
909 **/
dea31012005-04-17 16:05:31 -0500910int
James Smart2e0fef82007-06-17 19:56:36 -0500911lpfc_initial_flogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -0500912{
James Smart2e0fef82007-06-17 19:56:36 -0500913 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500914 struct lpfc_nodelist *ndlp;
915
James Smart98c9ea52007-10-27 13:37:33 -0400916 vport->port_state = LPFC_FLOGI;
917 lpfc_set_disctmo(vport);
918
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500919 /* First look for the Fabric ndlp */
James Smart2e0fef82007-06-17 19:56:36 -0500920 ndlp = lpfc_findnode_did(vport, Fabric_DID);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500921 if (!ndlp) {
dea31012005-04-17 16:05:31 -0500922 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500923 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
924 if (!ndlp)
925 return 0;
James Smart2e0fef82007-06-17 19:56:36 -0500926 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -0500927 /* Put ndlp onto node list */
928 lpfc_enqueue_node(vport, ndlp);
929 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
930 /* re-setup ndlp without removing from node list */
931 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
932 if (!ndlp)
933 return 0;
dea31012005-04-17 16:05:31 -0500934 }
James Smart87af33f2007-10-27 13:37:43 -0400935
James Smarte47c9092008-02-08 18:49:26 -0500936 if (lpfc_issue_els_flogi(vport, ndlp, 0))
James Smartfa4066b2008-01-11 01:53:27 -0500937 /* This decrement of reference count to node shall kick off
938 * the release of the node.
939 */
James Smart329f9bc2007-04-25 09:53:01 -0400940 lpfc_nlp_put(ndlp);
James Smarte47c9092008-02-08 18:49:26 -0500941
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500942 return 1;
dea31012005-04-17 16:05:31 -0500943}
944
James Smarte59058c2008-08-24 21:49:00 -0400945/**
946 * lpfc_initial_fdisc: Issue an initial fabric discovery for a vport.
947 * @vport: pointer to a host virtual N_Port data structure.
948 *
949 * This routine issues an initial Fabric Discover (FDISC) for the @vport
950 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
951 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
952 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
953 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
954 * is then invoked with the @vport and the ndlp to perform the FDISC for the
955 * @vport.
956 *
957 * Return code
958 * 0 - failed to issue initial fdisc for @vport
959 * 1 - successfully issued initial fdisc for @vport
960 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500961int
962lpfc_initial_fdisc(struct lpfc_vport *vport)
963{
964 struct lpfc_hba *phba = vport->phba;
965 struct lpfc_nodelist *ndlp;
966
967 /* First look for the Fabric ndlp */
968 ndlp = lpfc_findnode_did(vport, Fabric_DID);
969 if (!ndlp) {
970 /* Cannot find existing Fabric ndlp, so allocate a new one */
971 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
972 if (!ndlp)
973 return 0;
974 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -0500975 /* Put ndlp onto node list */
976 lpfc_enqueue_node(vport, ndlp);
977 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
978 /* re-setup ndlp without removing from node list */
979 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
980 if (!ndlp)
981 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500982 }
James Smarte47c9092008-02-08 18:49:26 -0500983
James Smart92d7f7b2007-06-17 19:56:38 -0500984 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -0500985 /* decrement node reference count to trigger the release of
986 * the node.
987 */
James Smart92d7f7b2007-06-17 19:56:38 -0500988 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -0500989 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500990 }
991 return 1;
992}
James Smart87af33f2007-10-27 13:37:43 -0400993
James Smarte59058c2008-08-24 21:49:00 -0400994/**
995 * lpfc_more_plogi: Check and issue remaining plogis for a vport.
996 * @vport: pointer to a host virtual N_Port data structure.
997 *
998 * This routine checks whether there are more remaining Port Logins
999 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1000 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1001 * to issue ELS PLOGIs up to the configured discover threads with the
1002 * @vport (@vport->cfg_discovery_threads). The function also decrement
1003 * the @vport's num_disc_node by 1 if it is not already 0.
1004 **/
James Smart87af33f2007-10-27 13:37:43 -04001005void
James Smart2e0fef82007-06-17 19:56:36 -05001006lpfc_more_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001007{
1008 int sentplogi;
1009
James Smart2e0fef82007-06-17 19:56:36 -05001010 if (vport->num_disc_nodes)
1011 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001012
1013 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
James Smarte8b62012007-08-02 11:10:09 -04001014 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1015 "0232 Continue discovery with %d PLOGIs to go "
1016 "Data: x%x x%x x%x\n",
1017 vport->num_disc_nodes, vport->fc_plogi_cnt,
1018 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001019 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001020 if (vport->fc_flag & FC_NLP_MORE)
1021 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1022 sentplogi = lpfc_els_disc_plogi(vport);
1023
dea31012005-04-17 16:05:31 -05001024 return;
1025}
1026
James Smarte59058c2008-08-24 21:49:00 -04001027/**
1028 * lpfc_plogi_confirm_nport: Confirm pologi wwpn matches stored ndlp.
1029 * @phba: pointer to lpfc hba data structure.
1030 * @prsp: pointer to response IOCB payload.
1031 * @ndlp: pointer to a node-list data structure.
1032 *
1033 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1034 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1035 * The following cases are considered N_Port confirmed:
1036 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1037 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1038 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1039 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1040 * 1) if there is a node on vport list other than the @ndlp with the same
1041 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1042 * on that node to release the RPI associated with the node; 2) if there is
1043 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1044 * into, a new node shall be allocated (or activated). In either case, the
1045 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1046 * be released and the new_ndlp shall be put on to the vport node list and
1047 * its pointer returned as the confirmed node.
1048 *
1049 * Note that before the @ndlp got "released", the keepDID from not-matching
1050 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1051 * of the @ndlp. This is because the release of @ndlp is actually to put it
1052 * into an inactive state on the vport node list and the vport node list
1053 * management algorithm does not allow two node with a same DID.
1054 *
1055 * Return code
1056 * pointer to the PLOGI N_Port @ndlp
1057 **/
James Smart488d1462006-03-07 15:02:37 -05001058static struct lpfc_nodelist *
James Smart92d7f7b2007-06-17 19:56:38 -05001059lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
James Smart488d1462006-03-07 15:02:37 -05001060 struct lpfc_nodelist *ndlp)
1061{
James Smart2e0fef82007-06-17 19:56:36 -05001062 struct lpfc_vport *vport = ndlp->vport;
James Smart488d1462006-03-07 15:02:37 -05001063 struct lpfc_nodelist *new_ndlp;
James Smart0ff10d42008-01-11 01:52:36 -05001064 struct lpfc_rport_data *rdata;
1065 struct fc_rport *rport;
James Smart488d1462006-03-07 15:02:37 -05001066 struct serv_parm *sp;
James Smart92d7f7b2007-06-17 19:56:38 -05001067 uint8_t name[sizeof(struct lpfc_name)];
James Smart58da1ff2008-04-07 10:15:56 -04001068 uint32_t rc, keepDID = 0;
James Smart488d1462006-03-07 15:02:37 -05001069
James Smart2fb9bd82006-12-02 13:33:57 -05001070 /* Fabric nodes can have the same WWPN so we don't bother searching
1071 * by WWPN. Just return the ndlp that was given to us.
1072 */
1073 if (ndlp->nlp_type & NLP_FABRIC)
1074 return ndlp;
1075
James Smart92d7f7b2007-06-17 19:56:38 -05001076 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
James Smart685f0bf2007-04-25 09:53:08 -04001077 memset(name, 0, sizeof(struct lpfc_name));
James Smart488d1462006-03-07 15:02:37 -05001078
James Smart685f0bf2007-04-25 09:53:08 -04001079 /* Now we find out if the NPort we are logging into, matches the WWPN
James Smart488d1462006-03-07 15:02:37 -05001080 * we have for that ndlp. If not, we have some work to do.
1081 */
James Smart2e0fef82007-06-17 19:56:36 -05001082 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
James Smart488d1462006-03-07 15:02:37 -05001083
James Smarte47c9092008-02-08 18:49:26 -05001084 if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
James Smart488d1462006-03-07 15:02:37 -05001085 return ndlp;
James Smart488d1462006-03-07 15:02:37 -05001086
1087 if (!new_ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05001088 rc = memcmp(&ndlp->nlp_portname, name,
1089 sizeof(struct lpfc_name));
James Smart92795652006-07-06 15:50:02 -04001090 if (!rc)
1091 return ndlp;
James Smart488d1462006-03-07 15:02:37 -05001092 new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
1093 if (!new_ndlp)
1094 return ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001095 lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID);
James Smarte47c9092008-02-08 18:49:26 -05001096 } else if (!NLP_CHK_NODE_ACT(new_ndlp)) {
James Smart58da1ff2008-04-07 10:15:56 -04001097 rc = memcmp(&ndlp->nlp_portname, name,
1098 sizeof(struct lpfc_name));
1099 if (!rc)
1100 return ndlp;
James Smarte47c9092008-02-08 18:49:26 -05001101 new_ndlp = lpfc_enable_node(vport, new_ndlp,
1102 NLP_STE_UNUSED_NODE);
1103 if (!new_ndlp)
1104 return ndlp;
James Smart58da1ff2008-04-07 10:15:56 -04001105 keepDID = new_ndlp->nlp_DID;
1106 } else
1107 keepDID = new_ndlp->nlp_DID;
James Smart488d1462006-03-07 15:02:37 -05001108
James Smart2e0fef82007-06-17 19:56:36 -05001109 lpfc_unreg_rpi(vport, new_ndlp);
James Smart488d1462006-03-07 15:02:37 -05001110 new_ndlp->nlp_DID = ndlp->nlp_DID;
James Smart92795652006-07-06 15:50:02 -04001111 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
James Smart0ff10d42008-01-11 01:52:36 -05001112
1113 if (ndlp->nlp_flag & NLP_NPR_2B_DISC)
1114 new_ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1115 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1116
James Smarte47c9092008-02-08 18:49:26 -05001117 /* Set state will put new_ndlp on to node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -05001118 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
James Smart488d1462006-03-07 15:02:37 -05001119
James Smart2e0fef82007-06-17 19:56:36 -05001120 /* Move this back to NPR state */
James Smart87af33f2007-10-27 13:37:43 -04001121 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1122 /* The new_ndlp is replacing ndlp totally, so we need
1123 * to put ndlp on UNUSED list and try to free it.
1124 */
James Smart0ff10d42008-01-11 01:52:36 -05001125
1126 /* Fix up the rport accordingly */
1127 rport = ndlp->rport;
1128 if (rport) {
1129 rdata = rport->dd_data;
1130 if (rdata->pnode == ndlp) {
1131 lpfc_nlp_put(ndlp);
1132 ndlp->rport = NULL;
1133 rdata->pnode = lpfc_nlp_get(new_ndlp);
1134 new_ndlp->rport = rport;
1135 }
1136 new_ndlp->nlp_type = ndlp->nlp_type;
1137 }
James Smart58da1ff2008-04-07 10:15:56 -04001138 /* We shall actually free the ndlp with both nlp_DID and
1139 * nlp_portname fields equals 0 to avoid any ndlp on the
1140 * nodelist never to be used.
1141 */
1142 if (ndlp->nlp_DID == 0) {
1143 spin_lock_irq(&phba->ndlp_lock);
1144 NLP_SET_FREE_REQ(ndlp);
1145 spin_unlock_irq(&phba->ndlp_lock);
1146 }
James Smart0ff10d42008-01-11 01:52:36 -05001147
James Smart58da1ff2008-04-07 10:15:56 -04001148 /* Two ndlps cannot have the same did on the nodelist */
1149 ndlp->nlp_DID = keepDID;
James Smart2e0fef82007-06-17 19:56:36 -05001150 lpfc_drop_node(vport, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04001151 }
James Smart92795652006-07-06 15:50:02 -04001152 else {
James Smart2e0fef82007-06-17 19:56:36 -05001153 lpfc_unreg_rpi(vport, ndlp);
James Smart58da1ff2008-04-07 10:15:56 -04001154 /* Two ndlps cannot have the same did */
1155 ndlp->nlp_DID = keepDID;
James Smart2e0fef82007-06-17 19:56:36 -05001156 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smart92795652006-07-06 15:50:02 -04001157 }
James Smart488d1462006-03-07 15:02:37 -05001158 return new_ndlp;
1159}
1160
James Smarte59058c2008-08-24 21:49:00 -04001161/**
1162 * lpfc_end_rscn: Check and handle more rscn for a vport.
1163 * @vport: pointer to a host virtual N_Port data structure.
1164 *
1165 * This routine checks whether more Registration State Change
1166 * Notifications (RSCNs) came in while the discovery state machine was in
1167 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1168 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1169 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1170 * handling the RSCNs.
1171 **/
James Smart87af33f2007-10-27 13:37:43 -04001172void
1173lpfc_end_rscn(struct lpfc_vport *vport)
1174{
1175 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1176
1177 if (vport->fc_flag & FC_RSCN_MODE) {
1178 /*
1179 * Check to see if more RSCNs came in while we were
1180 * processing this one.
1181 */
1182 if (vport->fc_rscn_id_cnt ||
1183 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1184 lpfc_els_handle_rscn(vport);
1185 else {
1186 spin_lock_irq(shost->host_lock);
1187 vport->fc_flag &= ~FC_RSCN_MODE;
1188 spin_unlock_irq(shost->host_lock);
1189 }
1190 }
1191}
1192
James Smarte59058c2008-08-24 21:49:00 -04001193/**
1194 * lpfc_cmpl_els_plogi: Completion callback function for plogi.
1195 * @phba: pointer to lpfc hba data structure.
1196 * @cmdiocb: pointer to lpfc command iocb data structure.
1197 * @rspiocb: pointer to lpfc response iocb data structure.
1198 *
1199 * This routine is the completion callback function for issuing the Port
1200 * Login (PLOGI) command. For PLOGI completion, there must be an active
1201 * ndlp on the vport node list that matches the remote node ID from the
1202 * PLOGI reponse IOCB. If such ndlp does not exist, the PLOGI is simply
1203 * ignored and command IOCB released. The PLOGI response IOCB status is
1204 * checked for error conditons. If there is error status reported, PLOGI
1205 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1206 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1207 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1208 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1209 * there are additional N_Port nodes with the vport that need to perform
1210 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1211 * PLOGIs.
1212 **/
dea31012005-04-17 16:05:31 -05001213static void
James Smart2e0fef82007-06-17 19:56:36 -05001214lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1215 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001216{
James Smart2e0fef82007-06-17 19:56:36 -05001217 struct lpfc_vport *vport = cmdiocb->vport;
1218 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001219 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001220 struct lpfc_nodelist *ndlp;
James Smart92795652006-07-06 15:50:02 -04001221 struct lpfc_dmabuf *prsp;
dea31012005-04-17 16:05:31 -05001222 int disc, rc, did, type;
1223
dea31012005-04-17 16:05:31 -05001224 /* we pass cmdiocb to state machine which needs rspiocb as well */
1225 cmdiocb->context_un.rsp_iocb = rspiocb;
1226
1227 irsp = &rspiocb->iocb;
James Smart858c9f62007-06-17 19:56:39 -05001228 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1229 "PLOGI cmpl: status:x%x/x%x did:x%x",
1230 irsp->ulpStatus, irsp->un.ulpWord[4],
1231 irsp->un.elsreq64.remoteID);
1232
James Smart2e0fef82007-06-17 19:56:36 -05001233 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
James Smarte47c9092008-02-08 18:49:26 -05001234 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smarte8b62012007-08-02 11:10:09 -04001235 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1236 "0136 PLOGI completes to NPort x%x "
1237 "with no ndlp. Data: x%x x%x x%x\n",
1238 irsp->un.elsreq64.remoteID,
1239 irsp->ulpStatus, irsp->un.ulpWord[4],
1240 irsp->ulpIoTag);
James Smart488d1462006-03-07 15:02:37 -05001241 goto out;
James Smarted957682007-06-17 19:56:37 -05001242 }
dea31012005-04-17 16:05:31 -05001243
1244 /* Since ndlp can be freed in the disc state machine, note if this node
1245 * is being used during discovery.
1246 */
James Smart2e0fef82007-06-17 19:56:36 -05001247 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001248 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
James Smart488d1462006-03-07 15:02:37 -05001249 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001250 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001251 rc = 0;
1252
1253 /* PLOGI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001254 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1255 "0102 PLOGI completes to NPort x%x "
1256 "Data: x%x x%x x%x x%x x%x\n",
1257 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1258 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001259 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001260 if (lpfc_els_chk_latt(vport)) {
1261 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001262 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001263 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001264 goto out;
1265 }
1266
1267 /* ndlp could be freed in DSM, save these values now */
1268 type = ndlp->nlp_type;
1269 did = ndlp->nlp_DID;
1270
1271 if (irsp->ulpStatus) {
1272 /* Check for retry */
1273 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1274 /* ELS command is being retried */
1275 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05001276 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001277 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001278 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001279 }
1280 goto out;
1281 }
dea31012005-04-17 16:05:31 -05001282 /* PLOGI failed */
1283 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001284 if (lpfc_error_lost_link(irsp))
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001285 rc = NLP_STE_FREED_NODE;
James Smarte47c9092008-02-08 18:49:26 -05001286 else
James Smart2e0fef82007-06-17 19:56:36 -05001287 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001288 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001289 } else {
1290 /* Good status, call state machine */
James Smart92795652006-07-06 15:50:02 -04001291 prsp = list_entry(((struct lpfc_dmabuf *)
James Smart92d7f7b2007-06-17 19:56:38 -05001292 cmdiocb->context2)->list.next,
1293 struct lpfc_dmabuf, list);
1294 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05001295 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001296 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001297 }
1298
James Smart2e0fef82007-06-17 19:56:36 -05001299 if (disc && vport->num_disc_nodes) {
dea31012005-04-17 16:05:31 -05001300 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001301 lpfc_more_plogi(vport);
dea31012005-04-17 16:05:31 -05001302
James Smart2e0fef82007-06-17 19:56:36 -05001303 if (vport->num_disc_nodes == 0) {
1304 spin_lock_irq(shost->host_lock);
1305 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1306 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001307
James Smart2e0fef82007-06-17 19:56:36 -05001308 lpfc_can_disctmo(vport);
James Smart87af33f2007-10-27 13:37:43 -04001309 lpfc_end_rscn(vport);
dea31012005-04-17 16:05:31 -05001310 }
1311 }
1312
1313out:
1314 lpfc_els_free_iocb(phba, cmdiocb);
1315 return;
1316}
1317
James Smarte59058c2008-08-24 21:49:00 -04001318/**
1319 * lpfc_issue_els_plogi: Issue an plogi iocb command for a vport.
1320 * @vport: pointer to a host virtual N_Port data structure.
1321 * @did: destination port identifier.
1322 * @retry: number of retries to the command IOCB.
1323 *
1324 * This routine issues a Port Login (PLOGI) command to a remote N_Port
1325 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
1326 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
1327 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
1328 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
1329 *
1330 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1331 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1332 * will be stored into the context1 field of the IOCB for the completion
1333 * callback function to the PLOGI ELS command.
1334 *
1335 * Return code
1336 * 0 - Successfully issued a plogi for @vport
1337 * 1 - failed to issue a plogi for @vport
1338 **/
dea31012005-04-17 16:05:31 -05001339int
James Smart2e0fef82007-06-17 19:56:36 -05001340lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
dea31012005-04-17 16:05:31 -05001341{
James Smart2e0fef82007-06-17 19:56:36 -05001342 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001343 struct serv_parm *sp;
1344 IOCB_t *icmd;
James Smart98c9ea52007-10-27 13:37:33 -04001345 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05001346 struct lpfc_iocbq *elsiocb;
1347 struct lpfc_sli_ring *pring;
1348 struct lpfc_sli *psli;
1349 uint8_t *pcmd;
1350 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05001351 int ret;
dea31012005-04-17 16:05:31 -05001352
1353 psli = &phba->sli;
1354 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1355
James Smart98c9ea52007-10-27 13:37:33 -04001356 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05001357 if (ndlp && !NLP_CHK_NODE_ACT(ndlp))
1358 ndlp = NULL;
James Smart98c9ea52007-10-27 13:37:33 -04001359
James Smarte47c9092008-02-08 18:49:26 -05001360 /* If ndlp is not NULL, we will bump the reference count on it */
James Smart92d7f7b2007-06-17 19:56:38 -05001361 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart98c9ea52007-10-27 13:37:33 -04001362 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
James Smart2e0fef82007-06-17 19:56:36 -05001363 ELS_CMD_PLOGI);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001364 if (!elsiocb)
1365 return 1;
dea31012005-04-17 16:05:31 -05001366
1367 icmd = &elsiocb->iocb;
1368 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1369
1370 /* For PLOGI request, remainder of payload is service parameters */
1371 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001372 pcmd += sizeof(uint32_t);
1373 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001374 sp = (struct serv_parm *) pcmd;
1375
1376 if (sp->cmn.fcphLow < FC_PH_4_3)
1377 sp->cmn.fcphLow = FC_PH_4_3;
1378
1379 if (sp->cmn.fcphHigh < FC_PH3)
1380 sp->cmn.fcphHigh = FC_PH3;
1381
James Smart858c9f62007-06-17 19:56:39 -05001382 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1383 "Issue PLOGI: did:x%x",
1384 did, 0, 0);
1385
dea31012005-04-17 16:05:31 -05001386 phba->fc_stat.elsXmitPLOGI++;
1387 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
James Smart92d7f7b2007-06-17 19:56:38 -05001388 ret = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
1389
1390 if (ret == IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05001391 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001392 return 1;
dea31012005-04-17 16:05:31 -05001393 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001394 return 0;
dea31012005-04-17 16:05:31 -05001395}
1396
James Smarte59058c2008-08-24 21:49:00 -04001397/**
1398 * lpfc_cmpl_els_prli: Completion callback function for prli.
1399 * @phba: pointer to lpfc hba data structure.
1400 * @cmdiocb: pointer to lpfc command iocb data structure.
1401 * @rspiocb: pointer to lpfc response iocb data structure.
1402 *
1403 * This routine is the completion callback function for a Process Login
1404 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
1405 * status. If there is error status reported, PRLI retry shall be attempted
1406 * by invoking the lpfc_els_retry() routine. Otherwise, the state
1407 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
1408 * ndlp to mark the PRLI completion.
1409 **/
dea31012005-04-17 16:05:31 -05001410static void
James Smart2e0fef82007-06-17 19:56:36 -05001411lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1412 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001413{
James Smart2e0fef82007-06-17 19:56:36 -05001414 struct lpfc_vport *vport = cmdiocb->vport;
1415 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001416 IOCB_t *irsp;
1417 struct lpfc_sli *psli;
1418 struct lpfc_nodelist *ndlp;
1419
1420 psli = &phba->sli;
1421 /* we pass cmdiocb to state machine which needs rspiocb as well */
1422 cmdiocb->context_un.rsp_iocb = rspiocb;
1423
1424 irsp = &(rspiocb->iocb);
1425 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
James Smart2e0fef82007-06-17 19:56:36 -05001426 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001427 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001428 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001429
James Smart858c9f62007-06-17 19:56:39 -05001430 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1431 "PRLI cmpl: status:x%x/x%x did:x%x",
1432 irsp->ulpStatus, irsp->un.ulpWord[4],
1433 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05001434 /* PRLI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001435 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1436 "0103 PRLI completes to NPort x%x "
1437 "Data: x%x x%x x%x x%x\n",
1438 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1439 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001440
James Smart2e0fef82007-06-17 19:56:36 -05001441 vport->fc_prli_sent--;
dea31012005-04-17 16:05:31 -05001442 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001443 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05001444 goto out;
1445
1446 if (irsp->ulpStatus) {
1447 /* Check for retry */
1448 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1449 /* ELS command is being retried */
1450 goto out;
1451 }
1452 /* PRLI failed */
1453 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001454 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05001455 goto out;
James Smarte47c9092008-02-08 18:49:26 -05001456 else
James Smart2e0fef82007-06-17 19:56:36 -05001457 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001458 NLP_EVT_CMPL_PRLI);
James Smarte47c9092008-02-08 18:49:26 -05001459 } else
dea31012005-04-17 16:05:31 -05001460 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05001461 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001462 NLP_EVT_CMPL_PRLI);
dea31012005-04-17 16:05:31 -05001463out:
1464 lpfc_els_free_iocb(phba, cmdiocb);
1465 return;
1466}
1467
James Smarte59058c2008-08-24 21:49:00 -04001468/**
1469 * lpfc_issue_els_prli: Issue a prli iocb command for a vport.
1470 * @vport: pointer to a host virtual N_Port data structure.
1471 * @ndlp: pointer to a node-list data structure.
1472 * @retry: number of retries to the command IOCB.
1473 *
1474 * This routine issues a Process Login (PRLI) ELS command for the
1475 * @vport. The PRLI service parameters are set up in the payload of the
1476 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
1477 * is put to the IOCB completion callback func field before invoking the
1478 * routine lpfc_sli_issue_iocb() to send out PRLI command.
1479 *
1480 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1481 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1482 * will be stored into the context1 field of the IOCB for the completion
1483 * callback function to the PRLI ELS command.
1484 *
1485 * Return code
1486 * 0 - successfully issued prli iocb command for @vport
1487 * 1 - failed to issue prli iocb command for @vport
1488 **/
dea31012005-04-17 16:05:31 -05001489int
James Smart2e0fef82007-06-17 19:56:36 -05001490lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001491 uint8_t retry)
1492{
James Smart2e0fef82007-06-17 19:56:36 -05001493 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1494 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001495 PRLI *npr;
1496 IOCB_t *icmd;
1497 struct lpfc_iocbq *elsiocb;
1498 struct lpfc_sli_ring *pring;
1499 struct lpfc_sli *psli;
1500 uint8_t *pcmd;
1501 uint16_t cmdsize;
1502
1503 psli = &phba->sli;
1504 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1505
James Smart92d7f7b2007-06-17 19:56:38 -05001506 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
James Smart2e0fef82007-06-17 19:56:36 -05001507 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1508 ndlp->nlp_DID, ELS_CMD_PRLI);
James Smart488d1462006-03-07 15:02:37 -05001509 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001510 return 1;
dea31012005-04-17 16:05:31 -05001511
1512 icmd = &elsiocb->iocb;
1513 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1514
1515 /* For PRLI request, remainder of payload is service parameters */
James Smart92d7f7b2007-06-17 19:56:38 -05001516 memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t)));
dea31012005-04-17 16:05:31 -05001517 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
James Smart92d7f7b2007-06-17 19:56:38 -05001518 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001519
1520 /* For PRLI, remainder of payload is PRLI parameter page */
1521 npr = (PRLI *) pcmd;
1522 /*
1523 * If our firmware version is 3.20 or later,
1524 * set the following bits for FC-TAPE support.
1525 */
1526 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
1527 npr->ConfmComplAllowed = 1;
1528 npr->Retry = 1;
1529 npr->TaskRetryIdReq = 1;
1530 }
1531 npr->estabImagePair = 1;
1532 npr->readXferRdyDis = 1;
1533
1534 /* For FCP support */
1535 npr->prliType = PRLI_FCP_TYPE;
1536 npr->initiatorFunc = 1;
1537
James Smart858c9f62007-06-17 19:56:39 -05001538 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1539 "Issue PRLI: did:x%x",
1540 ndlp->nlp_DID, 0, 0);
1541
dea31012005-04-17 16:05:31 -05001542 phba->fc_stat.elsXmitPRLI++;
1543 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
James Smart2e0fef82007-06-17 19:56:36 -05001544 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001545 ndlp->nlp_flag |= NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001546 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001547 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05001548 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001549 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001550 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001551 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001552 return 1;
dea31012005-04-17 16:05:31 -05001553 }
James Smart2e0fef82007-06-17 19:56:36 -05001554 vport->fc_prli_sent++;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001555 return 0;
dea31012005-04-17 16:05:31 -05001556}
1557
James Smarte59058c2008-08-24 21:49:00 -04001558/**
James Smart90160e02008-08-24 21:49:45 -04001559 * lpfc_rscn_disc: Perform rscn discovery for a vport.
1560 * @vport: pointer to a host virtual N_Port data structure.
1561 *
1562 * This routine performs Registration State Change Notification (RSCN)
1563 * discovery for a @vport. If the @vport's node port recovery count is not
1564 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
1565 * the nodes that need recovery. If none of the PLOGI were needed through
1566 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
1567 * invoked to check and handle possible more RSCN came in during the period
1568 * of processing the current ones.
1569 **/
1570static void
1571lpfc_rscn_disc(struct lpfc_vport *vport)
1572{
1573 lpfc_can_disctmo(vport);
1574
1575 /* RSCN discovery */
1576 /* go thru NPR nodes and issue ELS PLOGIs */
1577 if (vport->fc_npr_cnt)
1578 if (lpfc_els_disc_plogi(vport))
1579 return;
1580
1581 lpfc_end_rscn(vport);
1582}
1583
1584/**
1585 * lpfc_adisc_done: Complete the adisc phase of discovery.
1586 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
1587 *
1588 * This function is called when the final ADISC is completed during discovery.
1589 * This function handles clearing link attention or issuing reg_vpi depending
1590 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
1591 * discovery.
1592 * This function is called with no locks held.
1593 **/
1594static void
1595lpfc_adisc_done(struct lpfc_vport *vport)
1596{
1597 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1598 struct lpfc_hba *phba = vport->phba;
1599
1600 /*
1601 * For NPIV, cmpl_reg_vpi will set port_state to READY,
1602 * and continue discovery.
1603 */
1604 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
1605 !(vport->fc_flag & FC_RSCN_MODE)) {
1606 lpfc_issue_reg_vpi(phba, vport);
1607 return;
1608 }
1609 /*
1610 * For SLI2, we need to set port_state to READY
1611 * and continue discovery.
1612 */
1613 if (vport->port_state < LPFC_VPORT_READY) {
1614 /* If we get here, there is nothing to ADISC */
1615 if (vport->port_type == LPFC_PHYSICAL_PORT)
1616 lpfc_issue_clear_la(phba, vport);
1617 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
1618 vport->num_disc_nodes = 0;
1619 /* go thru NPR list, issue ELS PLOGIs */
1620 if (vport->fc_npr_cnt)
1621 lpfc_els_disc_plogi(vport);
1622 if (!vport->num_disc_nodes) {
1623 spin_lock_irq(shost->host_lock);
1624 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1625 spin_unlock_irq(shost->host_lock);
1626 lpfc_can_disctmo(vport);
1627 lpfc_end_rscn(vport);
1628 }
1629 }
1630 vport->port_state = LPFC_VPORT_READY;
1631 } else
1632 lpfc_rscn_disc(vport);
1633}
1634
1635/**
James Smarte59058c2008-08-24 21:49:00 -04001636 * lpfc_more_adisc: Issue more adisc as needed.
1637 * @vport: pointer to a host virtual N_Port data structure.
1638 *
1639 * This routine determines whether there are more ndlps on a @vport
1640 * node list need to have Address Discover (ADISC) issued. If so, it will
1641 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
1642 * remaining nodes which need to have ADISC sent.
1643 **/
James Smart0ff10d42008-01-11 01:52:36 -05001644void
James Smart2e0fef82007-06-17 19:56:36 -05001645lpfc_more_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001646{
1647 int sentadisc;
1648
James Smart2e0fef82007-06-17 19:56:36 -05001649 if (vport->num_disc_nodes)
1650 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001651 /* Continue discovery with <num_disc_nodes> ADISCs to go */
James Smarte8b62012007-08-02 11:10:09 -04001652 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1653 "0210 Continue discovery with %d ADISCs to go "
1654 "Data: x%x x%x x%x\n",
1655 vport->num_disc_nodes, vport->fc_adisc_cnt,
1656 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001657 /* Check to see if there are more ADISCs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001658 if (vport->fc_flag & FC_NLP_MORE) {
1659 lpfc_set_disctmo(vport);
1660 /* go thru NPR nodes and issue any remaining ELS ADISCs */
1661 sentadisc = lpfc_els_disc_adisc(vport);
dea31012005-04-17 16:05:31 -05001662 }
James Smart90160e02008-08-24 21:49:45 -04001663 if (!vport->num_disc_nodes)
1664 lpfc_adisc_done(vport);
dea31012005-04-17 16:05:31 -05001665 return;
1666}
1667
James Smarte59058c2008-08-24 21:49:00 -04001668/**
James Smarte59058c2008-08-24 21:49:00 -04001669 * lpfc_cmpl_els_adisc: Completion callback function for adisc.
1670 * @phba: pointer to lpfc hba data structure.
1671 * @cmdiocb: pointer to lpfc command iocb data structure.
1672 * @rspiocb: pointer to lpfc response iocb data structure.
1673 *
1674 * This routine is the completion function for issuing the Address Discover
1675 * (ADISC) command. It first checks to see whether link went down during
1676 * the discovery process. If so, the node will be marked as node port
1677 * recovery for issuing discover IOCB by the link attention handler and
1678 * exit. Otherwise, the response status is checked. If error was reported
1679 * in the response status, the ADISC command shall be retried by invoking
1680 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
1681 * the response status, the state machine is invoked to set transition
1682 * with respect to NLP_EVT_CMPL_ADISC event.
1683 **/
dea31012005-04-17 16:05:31 -05001684static void
James Smart2e0fef82007-06-17 19:56:36 -05001685lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1686 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001687{
James Smart2e0fef82007-06-17 19:56:36 -05001688 struct lpfc_vport *vport = cmdiocb->vport;
1689 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001690 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001691 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001692 int disc;
dea31012005-04-17 16:05:31 -05001693
1694 /* we pass cmdiocb to state machine which needs rspiocb as well */
1695 cmdiocb->context_un.rsp_iocb = rspiocb;
1696
1697 irsp = &(rspiocb->iocb);
1698 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
dea31012005-04-17 16:05:31 -05001699
James Smart858c9f62007-06-17 19:56:39 -05001700 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1701 "ADISC cmpl: status:x%x/x%x did:x%x",
1702 irsp->ulpStatus, irsp->un.ulpWord[4],
1703 ndlp->nlp_DID);
1704
dea31012005-04-17 16:05:31 -05001705 /* Since ndlp can be freed in the disc state machine, note if this node
1706 * is being used during discovery.
1707 */
James Smart2e0fef82007-06-17 19:56:36 -05001708 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001709 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001710 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001711 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001712 /* ADISC completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001713 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1714 "0104 ADISC completes to NPort x%x "
1715 "Data: x%x x%x x%x x%x x%x\n",
1716 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1717 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001718 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001719 if (lpfc_els_chk_latt(vport)) {
1720 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001721 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001722 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001723 goto out;
1724 }
1725
1726 if (irsp->ulpStatus) {
1727 /* Check for retry */
1728 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1729 /* ELS command is being retried */
1730 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05001731 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001732 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001733 spin_unlock_irq(shost->host_lock);
1734 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001735 }
1736 goto out;
1737 }
1738 /* ADISC failed */
1739 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001740 if (!lpfc_error_lost_link(irsp))
James Smart2e0fef82007-06-17 19:56:36 -05001741 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart858c9f62007-06-17 19:56:39 -05001742 NLP_EVT_CMPL_ADISC);
James Smarte47c9092008-02-08 18:49:26 -05001743 } else
dea31012005-04-17 16:05:31 -05001744 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05001745 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
dea31012005-04-17 16:05:31 -05001746 NLP_EVT_CMPL_ADISC);
dea31012005-04-17 16:05:31 -05001747
James Smart90160e02008-08-24 21:49:45 -04001748 /* Check to see if there are more ADISCs to be sent */
1749 if (disc && vport->num_disc_nodes)
James Smart2e0fef82007-06-17 19:56:36 -05001750 lpfc_more_adisc(vport);
dea31012005-04-17 16:05:31 -05001751out:
1752 lpfc_els_free_iocb(phba, cmdiocb);
1753 return;
1754}
1755
James Smarte59058c2008-08-24 21:49:00 -04001756/**
1757 * lpfc_issue_els_adisc: Issue an address discover iocb to an node on a vport.
1758 * @vport: pointer to a virtual N_Port data structure.
1759 * @ndlp: pointer to a node-list data structure.
1760 * @retry: number of retries to the command IOCB.
1761 *
1762 * This routine issues an Address Discover (ADISC) for an @ndlp on a
1763 * @vport. It prepares the payload of the ADISC ELS command, updates the
1764 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
1765 * to issue the ADISC ELS command.
1766 *
1767 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1768 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1769 * will be stored into the context1 field of the IOCB for the completion
1770 * callback function to the ADISC ELS command.
1771 *
1772 * Return code
1773 * 0 - successfully issued adisc
1774 * 1 - failed to issue adisc
1775 **/
dea31012005-04-17 16:05:31 -05001776int
James Smart2e0fef82007-06-17 19:56:36 -05001777lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001778 uint8_t retry)
1779{
James Smart2e0fef82007-06-17 19:56:36 -05001780 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1781 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001782 ADISC *ap;
1783 IOCB_t *icmd;
1784 struct lpfc_iocbq *elsiocb;
James Smart2e0fef82007-06-17 19:56:36 -05001785 struct lpfc_sli *psli = &phba->sli;
1786 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05001787 uint8_t *pcmd;
1788 uint16_t cmdsize;
1789
James Smart92d7f7b2007-06-17 19:56:38 -05001790 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
James Smart2e0fef82007-06-17 19:56:36 -05001791 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1792 ndlp->nlp_DID, ELS_CMD_ADISC);
James Smart488d1462006-03-07 15:02:37 -05001793 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001794 return 1;
dea31012005-04-17 16:05:31 -05001795
1796 icmd = &elsiocb->iocb;
1797 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1798
1799 /* For ADISC request, remainder of payload is service parameters */
1800 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
James Smart92d7f7b2007-06-17 19:56:38 -05001801 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001802
1803 /* Fill in ADISC payload */
1804 ap = (ADISC *) pcmd;
1805 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05001806 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
1807 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05001808 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05001809
James Smart858c9f62007-06-17 19:56:39 -05001810 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1811 "Issue ADISC: did:x%x",
1812 ndlp->nlp_DID, 0, 0);
1813
dea31012005-04-17 16:05:31 -05001814 phba->fc_stat.elsXmitADISC++;
1815 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
James Smart2e0fef82007-06-17 19:56:36 -05001816 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001817 ndlp->nlp_flag |= NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001818 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001819 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05001820 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001821 ndlp->nlp_flag &= ~NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001822 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001823 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001824 return 1;
dea31012005-04-17 16:05:31 -05001825 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001826 return 0;
dea31012005-04-17 16:05:31 -05001827}
1828
James Smarte59058c2008-08-24 21:49:00 -04001829/**
1830 * lpfc_cmpl_els_logo: Completion callback function for logo.
1831 * @phba: pointer to lpfc hba data structure.
1832 * @cmdiocb: pointer to lpfc command iocb data structure.
1833 * @rspiocb: pointer to lpfc response iocb data structure.
1834 *
1835 * This routine is the completion function for issuing the ELS Logout (LOGO)
1836 * command. If no error status was reported from the LOGO response, the
1837 * state machine of the associated ndlp shall be invoked for transition with
1838 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
1839 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
1840 **/
dea31012005-04-17 16:05:31 -05001841static void
James Smart2e0fef82007-06-17 19:56:36 -05001842lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1843 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001844{
James Smart2e0fef82007-06-17 19:56:36 -05001845 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1846 struct lpfc_vport *vport = ndlp->vport;
1847 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001848 IOCB_t *irsp;
1849 struct lpfc_sli *psli;
dea31012005-04-17 16:05:31 -05001850
1851 psli = &phba->sli;
1852 /* we pass cmdiocb to state machine which needs rspiocb as well */
1853 cmdiocb->context_un.rsp_iocb = rspiocb;
1854
1855 irsp = &(rspiocb->iocb);
James Smart2e0fef82007-06-17 19:56:36 -05001856 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001857 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001858 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001859
James Smart858c9f62007-06-17 19:56:39 -05001860 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1861 "LOGO cmpl: status:x%x/x%x did:x%x",
1862 irsp->ulpStatus, irsp->un.ulpWord[4],
1863 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05001864 /* LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001865 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1866 "0105 LOGO completes to NPort x%x "
1867 "Data: x%x x%x x%x x%x\n",
1868 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1869 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001870 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001871 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05001872 goto out;
1873
James Smart92d7f7b2007-06-17 19:56:38 -05001874 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
1875 /* NLP_EVT_DEVICE_RM should unregister the RPI
1876 * which should abort all outstanding IOs.
1877 */
1878 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1879 NLP_EVT_DEVICE_RM);
1880 goto out;
1881 }
1882
dea31012005-04-17 16:05:31 -05001883 if (irsp->ulpStatus) {
1884 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -05001885 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -05001886 /* ELS command is being retried */
1887 goto out;
dea31012005-04-17 16:05:31 -05001888 /* LOGO failed */
1889 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart858c9f62007-06-17 19:56:39 -05001890 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05001891 goto out;
James Smart858c9f62007-06-17 19:56:39 -05001892 else
James Smart2e0fef82007-06-17 19:56:36 -05001893 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001894 NLP_EVT_CMPL_LOGO);
James Smarte47c9092008-02-08 18:49:26 -05001895 } else
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001896 /* Good status, call state machine.
1897 * This will unregister the rpi if needed.
1898 */
James Smart2e0fef82007-06-17 19:56:36 -05001899 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001900 NLP_EVT_CMPL_LOGO);
dea31012005-04-17 16:05:31 -05001901out:
1902 lpfc_els_free_iocb(phba, cmdiocb);
1903 return;
1904}
1905
James Smarte59058c2008-08-24 21:49:00 -04001906/**
1907 * lpfc_issue_els_logo: Issue a logo to an node on a vport.
1908 * @vport: pointer to a virtual N_Port data structure.
1909 * @ndlp: pointer to a node-list data structure.
1910 * @retry: number of retries to the command IOCB.
1911 *
1912 * This routine constructs and issues an ELS Logout (LOGO) iocb command
1913 * to a remote node, referred by an @ndlp on a @vport. It constructs the
1914 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
1915 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
1916 *
1917 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1918 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1919 * will be stored into the context1 field of the IOCB for the completion
1920 * callback function to the LOGO ELS command.
1921 *
1922 * Return code
1923 * 0 - successfully issued logo
1924 * 1 - failed to issue logo
1925 **/
dea31012005-04-17 16:05:31 -05001926int
James Smart2e0fef82007-06-17 19:56:36 -05001927lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001928 uint8_t retry)
1929{
James Smart2e0fef82007-06-17 19:56:36 -05001930 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1931 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001932 IOCB_t *icmd;
1933 struct lpfc_iocbq *elsiocb;
1934 struct lpfc_sli_ring *pring;
1935 struct lpfc_sli *psli;
1936 uint8_t *pcmd;
1937 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05001938 int rc;
dea31012005-04-17 16:05:31 -05001939
1940 psli = &phba->sli;
1941 pring = &psli->ring[LPFC_ELS_RING];
1942
James Smart98c9ea52007-10-27 13:37:33 -04001943 spin_lock_irq(shost->host_lock);
1944 if (ndlp->nlp_flag & NLP_LOGO_SND) {
1945 spin_unlock_irq(shost->host_lock);
1946 return 0;
1947 }
1948 spin_unlock_irq(shost->host_lock);
1949
James Smart92d7f7b2007-06-17 19:56:38 -05001950 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
James Smart2e0fef82007-06-17 19:56:36 -05001951 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1952 ndlp->nlp_DID, ELS_CMD_LOGO);
James Smart488d1462006-03-07 15:02:37 -05001953 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001954 return 1;
dea31012005-04-17 16:05:31 -05001955
1956 icmd = &elsiocb->iocb;
1957 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1958 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
James Smart92d7f7b2007-06-17 19:56:38 -05001959 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001960
1961 /* Fill in LOGO payload */
James Smart2e0fef82007-06-17 19:56:36 -05001962 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05001963 pcmd += sizeof(uint32_t);
1964 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05001965
James Smart858c9f62007-06-17 19:56:39 -05001966 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1967 "Issue LOGO: did:x%x",
1968 ndlp->nlp_DID, 0, 0);
1969
dea31012005-04-17 16:05:31 -05001970 phba->fc_stat.elsXmitLOGO++;
1971 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
James Smart2e0fef82007-06-17 19:56:36 -05001972 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001973 ndlp->nlp_flag |= NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001974 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05001975 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
1976
1977 if (rc == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05001978 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001979 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001980 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001981 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001982 return 1;
dea31012005-04-17 16:05:31 -05001983 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001984 return 0;
dea31012005-04-17 16:05:31 -05001985}
1986
James Smarte59058c2008-08-24 21:49:00 -04001987/**
1988 * lpfc_cmpl_els_cmd: Completion callback function for generic els command.
1989 * @phba: pointer to lpfc hba data structure.
1990 * @cmdiocb: pointer to lpfc command iocb data structure.
1991 * @rspiocb: pointer to lpfc response iocb data structure.
1992 *
1993 * This routine is a generic completion callback function for ELS commands.
1994 * Specifically, it is the callback function which does not need to perform
1995 * any command specific operations. It is currently used by the ELS command
1996 * issuing routines for the ELS State Change Request (SCR),
1997 * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
1998 * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
1999 * certain debug loggings, this callback function simply invokes the
2000 * lpfc_els_chk_latt() routine to check whether link went down during the
2001 * discovery process.
2002 **/
dea31012005-04-17 16:05:31 -05002003static void
James Smart2e0fef82007-06-17 19:56:36 -05002004lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2005 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002006{
James Smart2e0fef82007-06-17 19:56:36 -05002007 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -05002008 IOCB_t *irsp;
2009
2010 irsp = &rspiocb->iocb;
2011
James Smart858c9f62007-06-17 19:56:39 -05002012 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2013 "ELS cmd cmpl: status:x%x/x%x did:x%x",
2014 irsp->ulpStatus, irsp->un.ulpWord[4],
2015 irsp->un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05002016 /* ELS cmd tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04002017 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2018 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
2019 irsp->ulpIoTag, irsp->ulpStatus,
2020 irsp->un.ulpWord[4], irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -05002021 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002022 lpfc_els_chk_latt(vport);
dea31012005-04-17 16:05:31 -05002023 lpfc_els_free_iocb(phba, cmdiocb);
2024 return;
2025}
2026
James Smarte59058c2008-08-24 21:49:00 -04002027/**
2028 * lpfc_issue_els_scr: Issue a scr to an node on a vport.
2029 * @vport: pointer to a host virtual N_Port data structure.
2030 * @nportid: N_Port identifier to the remote node.
2031 * @retry: number of retries to the command IOCB.
2032 *
2033 * This routine issues a State Change Request (SCR) to a fabric node
2034 * on a @vport. The remote node @nportid is passed into the function. It
2035 * first search the @vport node list to find the matching ndlp. If no such
2036 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
2037 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
2038 * routine is invoked to send the SCR IOCB.
2039 *
2040 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2041 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2042 * will be stored into the context1 field of the IOCB for the completion
2043 * callback function to the SCR ELS command.
2044 *
2045 * Return code
2046 * 0 - Successfully issued scr command
2047 * 1 - Failed to issue scr command
2048 **/
dea31012005-04-17 16:05:31 -05002049int
James Smart2e0fef82007-06-17 19:56:36 -05002050lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002051{
James Smart2e0fef82007-06-17 19:56:36 -05002052 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002053 IOCB_t *icmd;
2054 struct lpfc_iocbq *elsiocb;
2055 struct lpfc_sli_ring *pring;
2056 struct lpfc_sli *psli;
2057 uint8_t *pcmd;
2058 uint16_t cmdsize;
2059 struct lpfc_nodelist *ndlp;
2060
2061 psli = &phba->sli;
2062 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
James Smart92d7f7b2007-06-17 19:56:38 -05002063 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
dea31012005-04-17 16:05:31 -05002064
James Smarte47c9092008-02-08 18:49:26 -05002065 ndlp = lpfc_findnode_did(vport, nportid);
2066 if (!ndlp) {
2067 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2068 if (!ndlp)
2069 return 1;
2070 lpfc_nlp_init(vport, ndlp, nportid);
2071 lpfc_enqueue_node(vport, ndlp);
2072 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2073 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2074 if (!ndlp)
2075 return 1;
2076 }
dea31012005-04-17 16:05:31 -05002077
James Smart2e0fef82007-06-17 19:56:36 -05002078 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2079 ndlp->nlp_DID, ELS_CMD_SCR);
2080
James Smart488d1462006-03-07 15:02:37 -05002081 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002082 /* This will trigger the release of the node just
2083 * allocated
2084 */
James Smart329f9bc2007-04-25 09:53:01 -04002085 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002086 return 1;
dea31012005-04-17 16:05:31 -05002087 }
2088
2089 icmd = &elsiocb->iocb;
2090 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2091
2092 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
James Smart92d7f7b2007-06-17 19:56:38 -05002093 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002094
2095 /* For SCR, remainder of payload is SCR parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05002096 memset(pcmd, 0, sizeof(SCR));
dea31012005-04-17 16:05:31 -05002097 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
2098
James Smart858c9f62007-06-17 19:56:39 -05002099 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2100 "Issue SCR: did:x%x",
2101 ndlp->nlp_DID, 0, 0);
2102
dea31012005-04-17 16:05:31 -05002103 phba->fc_stat.elsXmitSCR++;
2104 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
dea31012005-04-17 16:05:31 -05002105 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002106 /* The additional lpfc_nlp_put will cause the following
2107 * lpfc_els_free_iocb routine to trigger the rlease of
2108 * the node.
2109 */
James Smart329f9bc2007-04-25 09:53:01 -04002110 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002111 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002112 return 1;
dea31012005-04-17 16:05:31 -05002113 }
James Smartfa4066b2008-01-11 01:53:27 -05002114 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2115 * trigger the release of node.
2116 */
James Smart329f9bc2007-04-25 09:53:01 -04002117 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002118 return 0;
dea31012005-04-17 16:05:31 -05002119}
2120
James Smarte59058c2008-08-24 21:49:00 -04002121/**
2122 * lpfc_issue_els_farpr: Issue a farp to an node on a vport.
2123 * @vport: pointer to a host virtual N_Port data structure.
2124 * @nportid: N_Port identifier to the remote node.
2125 * @retry: number of retries to the command IOCB.
2126 *
2127 * This routine issues a Fibre Channel Address Resolution Response
2128 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
2129 * is passed into the function. It first search the @vport node list to find
2130 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
2131 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
2132 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
2133 *
2134 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2135 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2136 * will be stored into the context1 field of the IOCB for the completion
2137 * callback function to the PARPR ELS command.
2138 *
2139 * Return code
2140 * 0 - Successfully issued farpr command
2141 * 1 - Failed to issue farpr command
2142 **/
dea31012005-04-17 16:05:31 -05002143static int
James Smart2e0fef82007-06-17 19:56:36 -05002144lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002145{
James Smart2e0fef82007-06-17 19:56:36 -05002146 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002147 IOCB_t *icmd;
2148 struct lpfc_iocbq *elsiocb;
2149 struct lpfc_sli_ring *pring;
2150 struct lpfc_sli *psli;
2151 FARP *fp;
2152 uint8_t *pcmd;
2153 uint32_t *lp;
2154 uint16_t cmdsize;
2155 struct lpfc_nodelist *ondlp;
2156 struct lpfc_nodelist *ndlp;
2157
2158 psli = &phba->sli;
2159 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
James Smart92d7f7b2007-06-17 19:56:38 -05002160 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
dea31012005-04-17 16:05:31 -05002161
James Smarte47c9092008-02-08 18:49:26 -05002162 ndlp = lpfc_findnode_did(vport, nportid);
2163 if (!ndlp) {
2164 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2165 if (!ndlp)
2166 return 1;
2167 lpfc_nlp_init(vport, ndlp, nportid);
2168 lpfc_enqueue_node(vport, ndlp);
2169 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2170 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2171 if (!ndlp)
2172 return 1;
2173 }
James Smart2e0fef82007-06-17 19:56:36 -05002174
2175 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2176 ndlp->nlp_DID, ELS_CMD_RNID);
James Smart488d1462006-03-07 15:02:37 -05002177 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002178 /* This will trigger the release of the node just
2179 * allocated
2180 */
James Smart329f9bc2007-04-25 09:53:01 -04002181 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002182 return 1;
dea31012005-04-17 16:05:31 -05002183 }
2184
2185 icmd = &elsiocb->iocb;
2186 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2187
2188 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
James Smart92d7f7b2007-06-17 19:56:38 -05002189 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002190
2191 /* Fill in FARPR payload */
2192 fp = (FARP *) (pcmd);
James Smart92d7f7b2007-06-17 19:56:38 -05002193 memset(fp, 0, sizeof(FARP));
dea31012005-04-17 16:05:31 -05002194 lp = (uint32_t *) pcmd;
2195 *lp++ = be32_to_cpu(nportid);
James Smart2e0fef82007-06-17 19:56:36 -05002196 *lp++ = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002197 fp->Rflags = 0;
2198 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
2199
James Smart92d7f7b2007-06-17 19:56:38 -05002200 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
2201 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002202 ondlp = lpfc_findnode_did(vport, nportid);
James Smarte47c9092008-02-08 18:49:26 -05002203 if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
dea31012005-04-17 16:05:31 -05002204 memcpy(&fp->OportName, &ondlp->nlp_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05002205 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002206 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05002207 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002208 }
2209
James Smart858c9f62007-06-17 19:56:39 -05002210 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2211 "Issue FARPR: did:x%x",
2212 ndlp->nlp_DID, 0, 0);
2213
dea31012005-04-17 16:05:31 -05002214 phba->fc_stat.elsXmitFARPR++;
2215 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
dea31012005-04-17 16:05:31 -05002216 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002217 /* The additional lpfc_nlp_put will cause the following
2218 * lpfc_els_free_iocb routine to trigger the release of
2219 * the node.
2220 */
James Smart329f9bc2007-04-25 09:53:01 -04002221 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002222 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002223 return 1;
dea31012005-04-17 16:05:31 -05002224 }
James Smartfa4066b2008-01-11 01:53:27 -05002225 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2226 * trigger the release of the node.
2227 */
James Smart329f9bc2007-04-25 09:53:01 -04002228 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002229 return 0;
dea31012005-04-17 16:05:31 -05002230}
2231
James Smarte59058c2008-08-24 21:49:00 -04002232/**
2233 * lpfc_cancel_retry_delay_tmo: Cancel the timer with delayed iocb-cmd retry.
2234 * @vport: pointer to a host virtual N_Port data structure.
2235 * @nlp: pointer to a node-list data structure.
2236 *
2237 * This routine cancels the timer with a delayed IOCB-command retry for
2238 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
2239 * removes the ELS retry event if it presents. In addition, if the
2240 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
2241 * commands are sent for the @vport's nodes that require issuing discovery
2242 * ADISC.
2243 **/
dea31012005-04-17 16:05:31 -05002244void
James Smart2e0fef82007-06-17 19:56:36 -05002245lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
James Smartfdcebe22006-03-07 15:04:01 -05002246{
James Smart2e0fef82007-06-17 19:56:36 -05002247 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smarte47c9092008-02-08 18:49:26 -05002248 struct lpfc_work_evt *evtp;
James Smart2e0fef82007-06-17 19:56:36 -05002249
James Smart0d2b6b82008-06-14 22:52:47 -04002250 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
2251 return;
James Smart2e0fef82007-06-17 19:56:36 -05002252 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002253 nlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002254 spin_unlock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002255 del_timer_sync(&nlp->nlp_delayfunc);
2256 nlp->nlp_last_elscmd = 0;
James Smarte47c9092008-02-08 18:49:26 -05002257 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
James Smartfdcebe22006-03-07 15:04:01 -05002258 list_del_init(&nlp->els_retry_evt.evt_listp);
James Smarte47c9092008-02-08 18:49:26 -05002259 /* Decrement nlp reference count held for the delayed retry */
2260 evtp = &nlp->els_retry_evt;
2261 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
2262 }
James Smartfdcebe22006-03-07 15:04:01 -05002263 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
James Smart2e0fef82007-06-17 19:56:36 -05002264 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002265 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002266 spin_unlock_irq(shost->host_lock);
2267 if (vport->num_disc_nodes) {
James Smart0d2b6b82008-06-14 22:52:47 -04002268 if (vport->port_state < LPFC_VPORT_READY) {
2269 /* Check if there are more ADISCs to be sent */
2270 lpfc_more_adisc(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04002271 } else {
2272 /* Check if there are more PLOGIs to be sent */
2273 lpfc_more_plogi(vport);
James Smart90160e02008-08-24 21:49:45 -04002274 if (vport->num_disc_nodes == 0) {
2275 spin_lock_irq(shost->host_lock);
2276 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2277 spin_unlock_irq(shost->host_lock);
2278 lpfc_can_disctmo(vport);
2279 lpfc_end_rscn(vport);
2280 }
James Smartfdcebe22006-03-07 15:04:01 -05002281 }
2282 }
2283 }
2284 return;
2285}
2286
James Smarte59058c2008-08-24 21:49:00 -04002287/**
2288 * lpfc_els_retry_delay: Timer function with a ndlp delayed function timer.
2289 * @ptr: holder for the pointer to the timer function associated data (ndlp).
2290 *
2291 * This routine is invoked by the ndlp delayed-function timer to check
2292 * whether there is any pending ELS retry event(s) with the node. If not, it
2293 * simply returns. Otherwise, if there is at least one ELS delayed event, it
2294 * adds the delayed events to the HBA work list and invokes the
2295 * lpfc_worker_wake_up() routine to wake up worker thread to process the
2296 * event. Note that lpfc_nlp_get() is called before posting the event to
2297 * the work list to hold reference count of ndlp so that it guarantees the
2298 * reference to ndlp will still be available when the worker thread gets
2299 * to the event associated with the ndlp.
2300 **/
James Smartfdcebe22006-03-07 15:04:01 -05002301void
dea31012005-04-17 16:05:31 -05002302lpfc_els_retry_delay(unsigned long ptr)
2303{
James Smart2e0fef82007-06-17 19:56:36 -05002304 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
2305 struct lpfc_vport *vport = ndlp->vport;
James Smart2e0fef82007-06-17 19:56:36 -05002306 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05002307 unsigned long flags;
James Smart2e0fef82007-06-17 19:56:36 -05002308 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
dea31012005-04-17 16:05:31 -05002309
James Smart92d7f7b2007-06-17 19:56:38 -05002310 spin_lock_irqsave(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002311 if (!list_empty(&evtp->evt_listp)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002312 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002313 return;
2314 }
2315
James Smartfa4066b2008-01-11 01:53:27 -05002316 /* We need to hold the node by incrementing the reference
2317 * count until the queued work is done
2318 */
2319 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
James Smart5e9d9b82008-06-14 22:52:53 -04002320 if (evtp->evt_arg1) {
2321 evtp->evt = LPFC_EVT_ELS_RETRY;
2322 list_add_tail(&evtp->evt_listp, &phba->work_list);
James Smart92d7f7b2007-06-17 19:56:38 -05002323 lpfc_worker_wake_up(phba);
James Smart5e9d9b82008-06-14 22:52:53 -04002324 }
James Smart92d7f7b2007-06-17 19:56:38 -05002325 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002326 return;
2327}
2328
James Smarte59058c2008-08-24 21:49:00 -04002329/**
2330 * lpfc_els_retry_delay_handler: Work thread handler for ndlp delayed function.
2331 * @ndlp: pointer to a node-list data structure.
2332 *
2333 * This routine is the worker-thread handler for processing the @ndlp delayed
2334 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
2335 * the last ELS command from the associated ndlp and invokes the proper ELS
2336 * function according to the delayed ELS command to retry the command.
2337 **/
dea31012005-04-17 16:05:31 -05002338void
2339lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
2340{
James Smart2e0fef82007-06-17 19:56:36 -05002341 struct lpfc_vport *vport = ndlp->vport;
2342 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2343 uint32_t cmd, did, retry;
dea31012005-04-17 16:05:31 -05002344
James Smart2e0fef82007-06-17 19:56:36 -05002345 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002346 did = ndlp->nlp_DID;
2347 cmd = ndlp->nlp_last_elscmd;
2348 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05002349
2350 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
James Smart2e0fef82007-06-17 19:56:36 -05002351 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002352 return;
2353 }
2354
2355 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002356 spin_unlock_irq(shost->host_lock);
James Smart1a169682006-03-07 15:04:06 -05002357 /*
2358 * If a discovery event readded nlp_delayfunc after timer
2359 * firing and before processing the timer, cancel the
2360 * nlp_delayfunc.
2361 */
2362 del_timer_sync(&ndlp->nlp_delayfunc);
dea31012005-04-17 16:05:31 -05002363 retry = ndlp->nlp_retry;
2364
2365 switch (cmd) {
2366 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002367 lpfc_issue_els_flogi(vport, ndlp, retry);
dea31012005-04-17 16:05:31 -05002368 break;
2369 case ELS_CMD_PLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002370 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002371 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002372 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002373 }
dea31012005-04-17 16:05:31 -05002374 break;
2375 case ELS_CMD_ADISC:
James Smart2e0fef82007-06-17 19:56:36 -05002376 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002377 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002378 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002379 }
dea31012005-04-17 16:05:31 -05002380 break;
2381 case ELS_CMD_PRLI:
James Smart2e0fef82007-06-17 19:56:36 -05002382 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002383 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002384 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002385 }
dea31012005-04-17 16:05:31 -05002386 break;
2387 case ELS_CMD_LOGO:
James Smart2e0fef82007-06-17 19:56:36 -05002388 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002389 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002390 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002391 }
dea31012005-04-17 16:05:31 -05002392 break;
James Smart92d7f7b2007-06-17 19:56:38 -05002393 case ELS_CMD_FDISC:
2394 lpfc_issue_els_fdisc(vport, ndlp, retry);
2395 break;
dea31012005-04-17 16:05:31 -05002396 }
2397 return;
2398}
2399
James Smarte59058c2008-08-24 21:49:00 -04002400/**
2401 * lpfc_els_retry: Make retry decision on an els command iocb.
2402 * @phba: pointer to lpfc hba data structure.
2403 * @cmdiocb: pointer to lpfc command iocb data structure.
2404 * @rspiocb: pointer to lpfc response iocb data structure.
2405 *
2406 * This routine makes a retry decision on an ELS command IOCB, which has
2407 * failed. The following ELS IOCBs use this function for retrying the command
2408 * when previously issued command responsed with error status: FLOGI, PLOGI,
2409 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
2410 * returned error status, it makes the decision whether a retry shall be
2411 * issued for the command, and whether a retry shall be made immediately or
2412 * delayed. In the former case, the corresponding ELS command issuing-function
2413 * is called to retry the command. In the later case, the ELS command shall
2414 * be posted to the ndlp delayed event and delayed function timer set to the
2415 * ndlp for the delayed command issusing.
2416 *
2417 * Return code
2418 * 0 - No retry of els command is made
2419 * 1 - Immediate or delayed retry of els command is made
2420 **/
dea31012005-04-17 16:05:31 -05002421static int
James Smart2e0fef82007-06-17 19:56:36 -05002422lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2423 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002424{
James Smart2e0fef82007-06-17 19:56:36 -05002425 struct lpfc_vport *vport = cmdiocb->vport;
2426 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2427 IOCB_t *irsp = &rspiocb->iocb;
2428 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2429 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
dea31012005-04-17 16:05:31 -05002430 uint32_t *elscmd;
2431 struct ls_rjt stat;
James Smart2e0fef82007-06-17 19:56:36 -05002432 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
James Smart98c9ea52007-10-27 13:37:33 -04002433 int logerr = 0;
James Smart2e0fef82007-06-17 19:56:36 -05002434 uint32_t cmd = 0;
James Smart488d1462006-03-07 15:02:37 -05002435 uint32_t did;
dea31012005-04-17 16:05:31 -05002436
James Smart488d1462006-03-07 15:02:37 -05002437
dea31012005-04-17 16:05:31 -05002438 /* Note: context2 may be 0 for internal driver abort
2439 * of delays ELS command.
2440 */
2441
2442 if (pcmd && pcmd->virt) {
2443 elscmd = (uint32_t *) (pcmd->virt);
2444 cmd = *elscmd++;
2445 }
2446
James Smarte47c9092008-02-08 18:49:26 -05002447 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart488d1462006-03-07 15:02:37 -05002448 did = ndlp->nlp_DID;
2449 else {
2450 /* We should only hit this case for retrying PLOGI */
2451 did = irsp->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05002452 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05002453 if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
2454 && (cmd != ELS_CMD_PLOGI))
James Smart488d1462006-03-07 15:02:37 -05002455 return 1;
2456 }
2457
James Smart858c9f62007-06-17 19:56:39 -05002458 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2459 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
2460 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
2461
dea31012005-04-17 16:05:31 -05002462 switch (irsp->ulpStatus) {
2463 case IOSTAT_FCP_RSP_ERROR:
2464 case IOSTAT_REMOTE_STOP:
2465 break;
2466
2467 case IOSTAT_LOCAL_REJECT:
2468 switch ((irsp->un.ulpWord[4] & 0xff)) {
2469 case IOERR_LOOP_OPEN_FAILURE:
James Smart2e0fef82007-06-17 19:56:36 -05002470 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05002471 delay = 1000;
dea31012005-04-17 16:05:31 -05002472 retry = 1;
2473 break;
2474
James Smart92d7f7b2007-06-17 19:56:38 -05002475 case IOERR_ILLEGAL_COMMAND:
James Smart7f5f3d02008-02-08 18:50:14 -05002476 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2477 "0124 Retry illegal cmd x%x "
2478 "retry:x%x delay:x%x\n",
2479 cmd, cmdiocb->retry, delay);
2480 retry = 1;
2481 /* All command's retry policy */
2482 maxretry = 8;
2483 if (cmdiocb->retry > 2)
2484 delay = 1000;
James Smart92d7f7b2007-06-17 19:56:38 -05002485 break;
2486
dea31012005-04-17 16:05:31 -05002487 case IOERR_NO_RESOURCES:
James Smart98c9ea52007-10-27 13:37:33 -04002488 logerr = 1; /* HBA out of resources */
James Smart858c9f62007-06-17 19:56:39 -05002489 retry = 1;
2490 if (cmdiocb->retry > 100)
2491 delay = 100;
2492 maxretry = 250;
2493 break;
2494
2495 case IOERR_ILLEGAL_FRAME:
James Smart92d7f7b2007-06-17 19:56:38 -05002496 delay = 100;
dea31012005-04-17 16:05:31 -05002497 retry = 1;
2498 break;
2499
James Smart858c9f62007-06-17 19:56:39 -05002500 case IOERR_SEQUENCE_TIMEOUT:
dea31012005-04-17 16:05:31 -05002501 case IOERR_INVALID_RPI:
2502 retry = 1;
2503 break;
2504 }
2505 break;
2506
2507 case IOSTAT_NPORT_RJT:
2508 case IOSTAT_FABRIC_RJT:
2509 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
2510 retry = 1;
2511 break;
2512 }
2513 break;
2514
2515 case IOSTAT_NPORT_BSY:
2516 case IOSTAT_FABRIC_BSY:
James Smart98c9ea52007-10-27 13:37:33 -04002517 logerr = 1; /* Fabric / Remote NPort out of resources */
dea31012005-04-17 16:05:31 -05002518 retry = 1;
2519 break;
2520
2521 case IOSTAT_LS_RJT:
2522 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
2523 /* Added for Vendor specifc support
2524 * Just keep retrying for these Rsn / Exp codes
2525 */
2526 switch (stat.un.b.lsRjtRsnCode) {
2527 case LSRJT_UNABLE_TPC:
2528 if (stat.un.b.lsRjtRsnCodeExp ==
2529 LSEXP_CMD_IN_PROGRESS) {
2530 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05002531 delay = 1000;
dea31012005-04-17 16:05:31 -05002532 maxretry = 48;
2533 }
2534 retry = 1;
2535 break;
2536 }
2537 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05002538 delay = 1000;
dea31012005-04-17 16:05:31 -05002539 maxretry = lpfc_max_els_tries + 1;
2540 retry = 1;
2541 break;
2542 }
James Smart92d7f7b2007-06-17 19:56:38 -05002543 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2544 (cmd == ELS_CMD_FDISC) &&
2545 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
James Smarte8b62012007-08-02 11:10:09 -04002546 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2547 "0125 FDISC Failed (x%x). "
2548 "Fabric out of resources\n",
2549 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05002550 lpfc_vport_set_state(vport,
2551 FC_VPORT_NO_FABRIC_RSCS);
2552 }
dea31012005-04-17 16:05:31 -05002553 break;
2554
2555 case LSRJT_LOGICAL_BSY:
James Smart858c9f62007-06-17 19:56:39 -05002556 if ((cmd == ELS_CMD_PLOGI) ||
2557 (cmd == ELS_CMD_PRLI)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002558 delay = 1000;
dea31012005-04-17 16:05:31 -05002559 maxretry = 48;
James Smart92d7f7b2007-06-17 19:56:38 -05002560 } else if (cmd == ELS_CMD_FDISC) {
James Smart51ef4c22007-08-02 11:10:31 -04002561 /* FDISC retry policy */
2562 maxretry = 48;
2563 if (cmdiocb->retry >= 32)
2564 delay = 1000;
dea31012005-04-17 16:05:31 -05002565 }
2566 retry = 1;
2567 break;
James Smart92d7f7b2007-06-17 19:56:38 -05002568
2569 case LSRJT_LOGICAL_ERR:
James Smart7f5f3d02008-02-08 18:50:14 -05002570 /* There are some cases where switches return this
2571 * error when they are not ready and should be returning
2572 * Logical Busy. We should delay every time.
2573 */
2574 if (cmd == ELS_CMD_FDISC &&
2575 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
2576 maxretry = 3;
2577 delay = 1000;
2578 retry = 1;
2579 break;
2580 }
James Smart92d7f7b2007-06-17 19:56:38 -05002581 case LSRJT_PROTOCOL_ERR:
2582 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2583 (cmd == ELS_CMD_FDISC) &&
2584 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
2585 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
2586 ) {
James Smarte8b62012007-08-02 11:10:09 -04002587 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2588 "0123 FDISC Failed (x%x). "
2589 "Fabric Detected Bad WWN\n",
2590 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05002591 lpfc_vport_set_state(vport,
2592 FC_VPORT_FABRIC_REJ_WWN);
2593 }
2594 break;
dea31012005-04-17 16:05:31 -05002595 }
2596 break;
2597
2598 case IOSTAT_INTERMED_RSP:
2599 case IOSTAT_BA_RJT:
2600 break;
2601
2602 default:
2603 break;
2604 }
2605
James Smart488d1462006-03-07 15:02:37 -05002606 if (did == FDMI_DID)
dea31012005-04-17 16:05:31 -05002607 retry = 1;
dea31012005-04-17 16:05:31 -05002608
James Smart98c9ea52007-10-27 13:37:33 -04002609 if ((cmd == ELS_CMD_FLOGI) &&
James Smart1b32f6a2008-02-08 18:49:39 -05002610 (phba->fc_topology != TOPOLOGY_LOOP) &&
2611 !lpfc_error_lost_link(irsp)) {
James Smart98c9ea52007-10-27 13:37:33 -04002612 /* FLOGI retry policy */
2613 retry = 1;
2614 maxretry = 48;
2615 if (cmdiocb->retry >= 32)
2616 delay = 1000;
2617 }
2618
dea31012005-04-17 16:05:31 -05002619 if ((++cmdiocb->retry) >= maxretry) {
2620 phba->fc_stat.elsRetryExceeded++;
2621 retry = 0;
2622 }
2623
James Smarted957682007-06-17 19:56:37 -05002624 if ((vport->load_flag & FC_UNLOADING) != 0)
2625 retry = 0;
2626
dea31012005-04-17 16:05:31 -05002627 if (retry) {
2628
2629 /* Retry ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04002630 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2631 "0107 Retry ELS command x%x to remote "
2632 "NPORT x%x Data: x%x x%x\n",
2633 cmd, did, cmdiocb->retry, delay);
dea31012005-04-17 16:05:31 -05002634
James Smart858c9f62007-06-17 19:56:39 -05002635 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
2636 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
2637 ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) {
2638 /* Don't reset timer for no resources */
2639
dea31012005-04-17 16:05:31 -05002640 /* If discovery / RSCN timer is running, reset it */
James Smart2e0fef82007-06-17 19:56:36 -05002641 if (timer_pending(&vport->fc_disctmo) ||
James Smart92d7f7b2007-06-17 19:56:38 -05002642 (vport->fc_flag & FC_RSCN_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05002643 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05002644 }
2645
2646 phba->fc_stat.elsXmitRetry++;
James Smart58da1ff2008-04-07 10:15:56 -04002647 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
dea31012005-04-17 16:05:31 -05002648 phba->fc_stat.elsDelayRetry++;
2649 ndlp->nlp_retry = cmdiocb->retry;
2650
James Smart92d7f7b2007-06-17 19:56:38 -05002651 /* delay is specified in milliseconds */
2652 mod_timer(&ndlp->nlp_delayfunc,
2653 jiffies + msecs_to_jiffies(delay));
James Smart2e0fef82007-06-17 19:56:36 -05002654 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002655 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002656 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002657
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002658 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart858c9f62007-06-17 19:56:39 -05002659 if (cmd == ELS_CMD_PRLI)
2660 lpfc_nlp_set_state(vport, ndlp,
2661 NLP_STE_REG_LOGIN_ISSUE);
2662 else
2663 lpfc_nlp_set_state(vport, ndlp,
2664 NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05002665 ndlp->nlp_last_elscmd = cmd;
2666
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002667 return 1;
dea31012005-04-17 16:05:31 -05002668 }
2669 switch (cmd) {
2670 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002671 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002672 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -05002673 case ELS_CMD_FDISC:
2674 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
2675 return 1;
dea31012005-04-17 16:05:31 -05002676 case ELS_CMD_PLOGI:
James Smart58da1ff2008-04-07 10:15:56 -04002677 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart488d1462006-03-07 15:02:37 -05002678 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002679 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04002680 NLP_STE_PLOGI_ISSUE);
James Smart488d1462006-03-07 15:02:37 -05002681 }
James Smart2e0fef82007-06-17 19:56:36 -05002682 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002683 return 1;
dea31012005-04-17 16:05:31 -05002684 case ELS_CMD_ADISC:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002685 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002686 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2687 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002688 return 1;
dea31012005-04-17 16:05:31 -05002689 case ELS_CMD_PRLI:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002690 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002691 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
2692 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002693 return 1;
dea31012005-04-17 16:05:31 -05002694 case ELS_CMD_LOGO:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002695 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002696 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2697 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002698 return 1;
dea31012005-04-17 16:05:31 -05002699 }
2700 }
dea31012005-04-17 16:05:31 -05002701 /* No retry ELS command <elsCmd> to remote NPORT <did> */
James Smart98c9ea52007-10-27 13:37:33 -04002702 if (logerr) {
2703 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2704 "0137 No retry ELS command x%x to remote "
2705 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
2706 cmd, did, irsp->ulpStatus,
2707 irsp->un.ulpWord[4]);
2708 }
2709 else {
2710 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smarta58cbd52007-08-02 11:09:43 -04002711 "0108 No retry ELS command x%x to remote "
2712 "NPORT x%x Retried:%d Error:x%x/%x\n",
2713 cmd, did, cmdiocb->retry, irsp->ulpStatus,
2714 irsp->un.ulpWord[4]);
James Smart98c9ea52007-10-27 13:37:33 -04002715 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002716 return 0;
dea31012005-04-17 16:05:31 -05002717}
2718
James Smarte59058c2008-08-24 21:49:00 -04002719/**
2720 * lpfc_els_free_data: Free lpfc dma buffer and data structure with an iocb.
2721 * @phba: pointer to lpfc hba data structure.
2722 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
2723 *
2724 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
2725 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
2726 * checks to see whether there is a lpfc DMA buffer associated with the
2727 * response of the command IOCB. If so, it will be released before releasing
2728 * the lpfc DMA buffer associated with the IOCB itself.
2729 *
2730 * Return code
2731 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
2732 **/
James Smart09372822008-01-11 01:52:54 -05002733static int
James Smart87af33f2007-10-27 13:37:43 -04002734lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
2735{
2736 struct lpfc_dmabuf *buf_ptr;
2737
James Smarte59058c2008-08-24 21:49:00 -04002738 /* Free the response before processing the command. */
James Smart87af33f2007-10-27 13:37:43 -04002739 if (!list_empty(&buf_ptr1->list)) {
2740 list_remove_head(&buf_ptr1->list, buf_ptr,
2741 struct lpfc_dmabuf,
2742 list);
2743 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
2744 kfree(buf_ptr);
2745 }
2746 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
2747 kfree(buf_ptr1);
2748 return 0;
2749}
2750
James Smarte59058c2008-08-24 21:49:00 -04002751/**
2752 * lpfc_els_free_bpl: Free lpfc dma buffer and data structure with bpl.
2753 * @phba: pointer to lpfc hba data structure.
2754 * @buf_ptr: pointer to the lpfc dma buffer data structure.
2755 *
2756 * This routine releases the lpfc Direct Memory Access (DMA) buffer
2757 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
2758 * pool.
2759 *
2760 * Return code
2761 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
2762 **/
James Smart09372822008-01-11 01:52:54 -05002763static int
James Smart87af33f2007-10-27 13:37:43 -04002764lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
2765{
2766 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
2767 kfree(buf_ptr);
2768 return 0;
2769}
2770
James Smarte59058c2008-08-24 21:49:00 -04002771/**
2772 * lpfc_els_free_iocb: Free a command iocb and its associated resources.
2773 * @phba: pointer to lpfc hba data structure.
2774 * @elsiocb: pointer to lpfc els command iocb data structure.
2775 *
2776 * This routine frees a command IOCB and its associated resources. The
2777 * command IOCB data structure contains the reference to various associated
2778 * resources, these fields must be set to NULL if the associated reference
2779 * not present:
2780 * context1 - reference to ndlp
2781 * context2 - reference to cmd
2782 * context2->next - reference to rsp
2783 * context3 - reference to bpl
2784 *
2785 * It first properly decrements the reference count held on ndlp for the
2786 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
2787 * set, it invokes the lpfc_els_free_data() routine to release the Direct
2788 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
2789 * adds the DMA buffer the @phba data structure for the delayed release.
2790 * If reference to the Buffer Pointer List (BPL) is present, the
2791 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
2792 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
2793 * invoked to release the IOCB data structure back to @phba IOCBQ list.
2794 *
2795 * Return code
2796 * 0 - Success (currently, always return 0)
2797 **/
James Smart87af33f2007-10-27 13:37:43 -04002798int
James Smart329f9bc2007-04-25 09:53:01 -04002799lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05002800{
2801 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
James Smarta8adb832007-10-27 13:37:53 -04002802 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05002803
James Smarta8adb832007-10-27 13:37:53 -04002804 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
2805 if (ndlp) {
2806 if (ndlp->nlp_flag & NLP_DEFER_RM) {
2807 lpfc_nlp_put(ndlp);
2808
2809 /* If the ndlp is not being used by another discovery
2810 * thread, free it.
2811 */
2812 if (!lpfc_nlp_not_used(ndlp)) {
2813 /* If ndlp is being used by another discovery
2814 * thread, just clear NLP_DEFER_RM
2815 */
2816 ndlp->nlp_flag &= ~NLP_DEFER_RM;
2817 }
2818 }
2819 else
2820 lpfc_nlp_put(ndlp);
James Smart329f9bc2007-04-25 09:53:01 -04002821 elsiocb->context1 = NULL;
2822 }
dea31012005-04-17 16:05:31 -05002823 /* context2 = cmd, context2->next = rsp, context3 = bpl */
2824 if (elsiocb->context2) {
James Smart0ff10d42008-01-11 01:52:36 -05002825 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
2826 /* Firmware could still be in progress of DMAing
2827 * payload, so don't free data buffer till after
2828 * a hbeat.
2829 */
2830 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
2831 buf_ptr = elsiocb->context2;
2832 elsiocb->context2 = NULL;
2833 if (buf_ptr) {
2834 buf_ptr1 = NULL;
2835 spin_lock_irq(&phba->hbalock);
2836 if (!list_empty(&buf_ptr->list)) {
2837 list_remove_head(&buf_ptr->list,
2838 buf_ptr1, struct lpfc_dmabuf,
2839 list);
2840 INIT_LIST_HEAD(&buf_ptr1->list);
2841 list_add_tail(&buf_ptr1->list,
2842 &phba->elsbuf);
2843 phba->elsbuf_cnt++;
2844 }
2845 INIT_LIST_HEAD(&buf_ptr->list);
2846 list_add_tail(&buf_ptr->list, &phba->elsbuf);
2847 phba->elsbuf_cnt++;
2848 spin_unlock_irq(&phba->hbalock);
2849 }
2850 } else {
2851 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
2852 lpfc_els_free_data(phba, buf_ptr1);
2853 }
dea31012005-04-17 16:05:31 -05002854 }
2855
2856 if (elsiocb->context3) {
2857 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
James Smart87af33f2007-10-27 13:37:43 -04002858 lpfc_els_free_bpl(phba, buf_ptr);
dea31012005-04-17 16:05:31 -05002859 }
James Bottomley604a3e32005-10-29 10:28:33 -05002860 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -05002861 return 0;
2862}
2863
James Smarte59058c2008-08-24 21:49:00 -04002864/**
2865 * lpfc_cmpl_els_logo_acc: Completion callback function to logo acc response.
2866 * @phba: pointer to lpfc hba data structure.
2867 * @cmdiocb: pointer to lpfc command iocb data structure.
2868 * @rspiocb: pointer to lpfc response iocb data structure.
2869 *
2870 * This routine is the completion callback function to the Logout (LOGO)
2871 * Accept (ACC) Response ELS command. This routine is invoked to indicate
2872 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
2873 * release the ndlp if it has the last reference remaining (reference count
2874 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
2875 * field to NULL to inform the following lpfc_els_free_iocb() routine no
2876 * ndlp reference count needs to be decremented. Otherwise, the ndlp
2877 * reference use-count shall be decremented by the lpfc_els_free_iocb()
2878 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
2879 * IOCB data structure.
2880 **/
dea31012005-04-17 16:05:31 -05002881static void
James Smart2e0fef82007-06-17 19:56:36 -05002882lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2883 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002884{
James Smart2e0fef82007-06-17 19:56:36 -05002885 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2886 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05002887 IOCB_t *irsp;
2888
2889 irsp = &rspiocb->iocb;
2890 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2891 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
2892 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05002893 /* ACC to LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002894 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2895 "0109 ACC to LOGO completes to NPort x%x "
2896 "Data: x%x x%x x%x\n",
2897 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2898 ndlp->nlp_rpi);
James Smart87af33f2007-10-27 13:37:43 -04002899
2900 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
2901 /* NPort Recovery mode or node is just allocated */
2902 if (!lpfc_nlp_not_used(ndlp)) {
2903 /* If the ndlp is being used by another discovery
2904 * thread, just unregister the RPI.
2905 */
2906 lpfc_unreg_rpi(vport, ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05002907 } else {
2908 /* Indicate the node has already released, should
2909 * not reference to it from within lpfc_els_free_iocb.
2910 */
2911 cmdiocb->context1 = NULL;
James Smart87af33f2007-10-27 13:37:43 -04002912 }
dea31012005-04-17 16:05:31 -05002913 }
2914 lpfc_els_free_iocb(phba, cmdiocb);
2915 return;
2916}
2917
James Smarte59058c2008-08-24 21:49:00 -04002918/**
2919 * lpfc_mbx_cmpl_dflt_rpi: Completion callbk func for unreg dflt rpi mbox cmd.
2920 * @phba: pointer to lpfc hba data structure.
2921 * @pmb: pointer to the driver internal queue element for mailbox command.
2922 *
2923 * This routine is the completion callback function for unregister default
2924 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
2925 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
2926 * decrements the ndlp reference count held for this completion callback
2927 * function. After that, it invokes the lpfc_nlp_not_used() to check
2928 * whether there is only one reference left on the ndlp. If so, it will
2929 * perform one more decrement and trigger the release of the ndlp.
2930 **/
James Smart858c9f62007-06-17 19:56:39 -05002931void
2932lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
2933{
2934 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
2935 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
2936
2937 pmb->context1 = NULL;
2938 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2939 kfree(mp);
2940 mempool_free(pmb, phba->mbox_mem_pool);
James Smart58da1ff2008-04-07 10:15:56 -04002941 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smarta8adb832007-10-27 13:37:53 -04002942 lpfc_nlp_put(ndlp);
James Smarta8adb832007-10-27 13:37:53 -04002943 /* This is the end of the default RPI cleanup logic for this
2944 * ndlp. If no other discovery threads are using this ndlp.
2945 * we should free all resources associated with it.
2946 */
2947 lpfc_nlp_not_used(ndlp);
2948 }
James Smart858c9f62007-06-17 19:56:39 -05002949 return;
2950}
2951
James Smarte59058c2008-08-24 21:49:00 -04002952/**
2953 * lpfc_cmpl_els_rsp: Completion callback function for els response iocb cmd.
2954 * @phba: pointer to lpfc hba data structure.
2955 * @cmdiocb: pointer to lpfc command iocb data structure.
2956 * @rspiocb: pointer to lpfc response iocb data structure.
2957 *
2958 * This routine is the completion callback function for ELS Response IOCB
2959 * command. In normal case, this callback function just properly sets the
2960 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
2961 * field in the command IOCB is not NULL, the referred mailbox command will
2962 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
2963 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
2964 * link down event occurred during the discovery, the lpfc_nlp_not_used()
2965 * routine shall be invoked trying to release the ndlp if no other threads
2966 * are currently referring it.
2967 **/
dea31012005-04-17 16:05:31 -05002968static void
James Smart858c9f62007-06-17 19:56:39 -05002969lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
James Smart329f9bc2007-04-25 09:53:01 -04002970 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002971{
James Smart2e0fef82007-06-17 19:56:36 -05002972 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2973 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
2974 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
James Smart87af33f2007-10-27 13:37:43 -04002975 IOCB_t *irsp;
2976 uint8_t *pcmd;
dea31012005-04-17 16:05:31 -05002977 LPFC_MBOXQ_t *mbox = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05002978 struct lpfc_dmabuf *mp = NULL;
James Smart87af33f2007-10-27 13:37:43 -04002979 uint32_t ls_rjt = 0;
dea31012005-04-17 16:05:31 -05002980
James Smart33ccf8d2006-08-17 11:57:58 -04002981 irsp = &rspiocb->iocb;
2982
dea31012005-04-17 16:05:31 -05002983 if (cmdiocb->context_un.mbox)
2984 mbox = cmdiocb->context_un.mbox;
2985
James Smartfa4066b2008-01-11 01:53:27 -05002986 /* First determine if this is a LS_RJT cmpl. Note, this callback
2987 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
2988 */
James Smart87af33f2007-10-27 13:37:43 -04002989 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
James Smart58da1ff2008-04-07 10:15:56 -04002990 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
2991 (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
James Smartfa4066b2008-01-11 01:53:27 -05002992 /* A LS_RJT associated with Default RPI cleanup has its own
2993 * seperate code path.
James Smart87af33f2007-10-27 13:37:43 -04002994 */
2995 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
2996 ls_rjt = 1;
2997 }
2998
dea31012005-04-17 16:05:31 -05002999 /* Check to see if link went down during discovery */
James Smart58da1ff2008-04-07 10:15:56 -04003000 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
dea31012005-04-17 16:05:31 -05003001 if (mbox) {
James Smart14691152006-12-02 13:34:28 -05003002 mp = (struct lpfc_dmabuf *) mbox->context1;
3003 if (mp) {
3004 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3005 kfree(mp);
3006 }
James Smart329f9bc2007-04-25 09:53:01 -04003007 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003008 }
James Smart58da1ff2008-04-07 10:15:56 -04003009 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3010 (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
James Smartfa4066b2008-01-11 01:53:27 -05003011 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003012 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003013 /* Indicate the node has already released,
3014 * should not reference to it from within
3015 * the routine lpfc_els_free_iocb.
3016 */
3017 cmdiocb->context1 = NULL;
3018 }
dea31012005-04-17 16:05:31 -05003019 goto out;
3020 }
3021
James Smart858c9f62007-06-17 19:56:39 -05003022 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smart51ef4c22007-08-02 11:10:31 -04003023 "ELS rsp cmpl: status:x%x/x%x did:x%x",
James Smart858c9f62007-06-17 19:56:39 -05003024 irsp->ulpStatus, irsp->un.ulpWord[4],
James Smart51ef4c22007-08-02 11:10:31 -04003025 cmdiocb->iocb.un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05003026 /* ELS response tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04003027 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3028 "0110 ELS response tag x%x completes "
3029 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
3030 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
3031 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
3032 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3033 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003034 if (mbox) {
3035 if ((rspiocb->iocb.ulpStatus == 0)
3036 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
James Smart2e0fef82007-06-17 19:56:36 -05003037 lpfc_unreg_rpi(vport, ndlp);
James Smarte47c9092008-02-08 18:49:26 -05003038 /* Increment reference count to ndlp to hold the
3039 * reference to ndlp for the callback function.
3040 */
James Smart329f9bc2007-04-25 09:53:01 -04003041 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05003042 mbox->vport = vport;
James Smart858c9f62007-06-17 19:56:39 -05003043 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
3044 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
3045 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
3046 }
3047 else {
3048 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
3049 ndlp->nlp_prev_state = ndlp->nlp_state;
3050 lpfc_nlp_set_state(vport, ndlp,
James Smart2e0fef82007-06-17 19:56:36 -05003051 NLP_STE_REG_LOGIN_ISSUE);
James Smart858c9f62007-06-17 19:56:39 -05003052 }
James Smart0b727fe2007-10-27 13:37:25 -04003053 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smarte47c9092008-02-08 18:49:26 -05003054 != MBX_NOT_FINISHED)
dea31012005-04-17 16:05:31 -05003055 goto out;
James Smarte47c9092008-02-08 18:49:26 -05003056 else
3057 /* Decrement the ndlp reference count we
3058 * set for this failed mailbox command.
3059 */
3060 lpfc_nlp_put(ndlp);
James Smart98c9ea52007-10-27 13:37:33 -04003061
3062 /* ELS rsp: Cannot issue reg_login for <NPortid> */
3063 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3064 "0138 ELS rsp: Cannot issue reg_login for x%x "
3065 "Data: x%x x%x x%x\n",
3066 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3067 ndlp->nlp_rpi);
3068
James Smartfa4066b2008-01-11 01:53:27 -05003069 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003070 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003071 /* Indicate node has already been released,
3072 * should not reference to it from within
3073 * the routine lpfc_els_free_iocb.
3074 */
3075 cmdiocb->context1 = NULL;
3076 }
dea31012005-04-17 16:05:31 -05003077 } else {
James Smart858c9f62007-06-17 19:56:39 -05003078 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
3079 if (!lpfc_error_lost_link(irsp) &&
3080 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
James Smartfa4066b2008-01-11 01:53:27 -05003081 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003082 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003083 /* Indicate node has already been
3084 * released, should not reference
3085 * to it from within the routine
3086 * lpfc_els_free_iocb.
3087 */
3088 cmdiocb->context1 = NULL;
3089 }
dea31012005-04-17 16:05:31 -05003090 }
3091 }
James Smart14691152006-12-02 13:34:28 -05003092 mp = (struct lpfc_dmabuf *) mbox->context1;
3093 if (mp) {
3094 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3095 kfree(mp);
3096 }
3097 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003098 }
3099out:
James Smart58da1ff2008-04-07 10:15:56 -04003100 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart2e0fef82007-06-17 19:56:36 -05003101 spin_lock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05003102 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
James Smart2e0fef82007-06-17 19:56:36 -05003103 spin_unlock_irq(shost->host_lock);
James Smart87af33f2007-10-27 13:37:43 -04003104
3105 /* If the node is not being used by another discovery thread,
3106 * and we are sending a reject, we are done with it.
3107 * Release driver reference count here and free associated
3108 * resources.
3109 */
3110 if (ls_rjt)
James Smartfa4066b2008-01-11 01:53:27 -05003111 if (lpfc_nlp_not_used(ndlp))
3112 /* Indicate node has already been released,
3113 * should not reference to it from within
3114 * the routine lpfc_els_free_iocb.
3115 */
3116 cmdiocb->context1 = NULL;
dea31012005-04-17 16:05:31 -05003117 }
James Smart87af33f2007-10-27 13:37:43 -04003118
dea31012005-04-17 16:05:31 -05003119 lpfc_els_free_iocb(phba, cmdiocb);
3120 return;
3121}
3122
James Smarte59058c2008-08-24 21:49:00 -04003123/**
3124 * lpfc_els_rsp_acc: Prepare and issue an acc response iocb command.
3125 * @vport: pointer to a host virtual N_Port data structure.
3126 * @flag: the els command code to be accepted.
3127 * @oldiocb: pointer to the original lpfc command iocb data structure.
3128 * @ndlp: pointer to a node-list data structure.
3129 * @mbox: pointer to the driver internal queue element for mailbox command.
3130 *
3131 * This routine prepares and issues an Accept (ACC) response IOCB
3132 * command. It uses the @flag to properly set up the IOCB field for the
3133 * specific ACC response command to be issued and invokes the
3134 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
3135 * @mbox pointer is passed in, it will be put into the context_un.mbox
3136 * field of the IOCB for the completion callback function to issue the
3137 * mailbox command to the HBA later when callback is invoked.
3138 *
3139 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3140 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3141 * will be stored into the context1 field of the IOCB for the completion
3142 * callback function to the corresponding response ELS IOCB command.
3143 *
3144 * Return code
3145 * 0 - Successfully issued acc response
3146 * 1 - Failed to issue acc response
3147 **/
dea31012005-04-17 16:05:31 -05003148int
James Smart2e0fef82007-06-17 19:56:36 -05003149lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
3150 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
James Smart51ef4c22007-08-02 11:10:31 -04003151 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003152{
James Smart2e0fef82007-06-17 19:56:36 -05003153 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3154 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003155 IOCB_t *icmd;
3156 IOCB_t *oldcmd;
3157 struct lpfc_iocbq *elsiocb;
3158 struct lpfc_sli_ring *pring;
3159 struct lpfc_sli *psli;
3160 uint8_t *pcmd;
3161 uint16_t cmdsize;
3162 int rc;
James Smart82d9a2a2006-04-15 11:53:05 -04003163 ELS_PKT *els_pkt_ptr;
dea31012005-04-17 16:05:31 -05003164
3165 psli = &phba->sli;
3166 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
3167 oldcmd = &oldiocb->iocb;
3168
3169 switch (flag) {
3170 case ELS_CMD_ACC:
James Smart92d7f7b2007-06-17 19:56:38 -05003171 cmdsize = sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003172 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3173 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003174 if (!elsiocb) {
James Smart2e0fef82007-06-17 19:56:36 -05003175 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003176 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003177 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003178 return 1;
dea31012005-04-17 16:05:31 -05003179 }
James Smart2e0fef82007-06-17 19:56:36 -05003180
dea31012005-04-17 16:05:31 -05003181 icmd = &elsiocb->iocb;
3182 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3183 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3184 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003185 pcmd += sizeof(uint32_t);
James Smart858c9f62007-06-17 19:56:39 -05003186
3187 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3188 "Issue ACC: did:x%x flg:x%x",
3189 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003190 break;
3191 case ELS_CMD_PLOGI:
James Smart92d7f7b2007-06-17 19:56:38 -05003192 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
James Smart2e0fef82007-06-17 19:56:36 -05003193 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3194 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003195 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003196 return 1;
James Smart488d1462006-03-07 15:02:37 -05003197
dea31012005-04-17 16:05:31 -05003198 icmd = &elsiocb->iocb;
3199 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3200 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3201
3202 if (mbox)
3203 elsiocb->context_un.mbox = mbox;
3204
3205 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003206 pcmd += sizeof(uint32_t);
3207 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
James Smart858c9f62007-06-17 19:56:39 -05003208
3209 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3210 "Issue ACC PLOGI: did:x%x flg:x%x",
3211 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003212 break;
James Smart82d9a2a2006-04-15 11:53:05 -04003213 case ELS_CMD_PRLO:
James Smart92d7f7b2007-06-17 19:56:38 -05003214 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
James Smart2e0fef82007-06-17 19:56:36 -05003215 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
James Smart82d9a2a2006-04-15 11:53:05 -04003216 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
3217 if (!elsiocb)
3218 return 1;
3219
3220 icmd = &elsiocb->iocb;
3221 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3222 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3223
3224 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
James Smart92d7f7b2007-06-17 19:56:38 -05003225 sizeof(uint32_t) + sizeof(PRLO));
James Smart82d9a2a2006-04-15 11:53:05 -04003226 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
3227 els_pkt_ptr = (ELS_PKT *) pcmd;
3228 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
James Smart858c9f62007-06-17 19:56:39 -05003229
3230 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3231 "Issue ACC PRLO: did:x%x flg:x%x",
3232 ndlp->nlp_DID, ndlp->nlp_flag, 0);
James Smart82d9a2a2006-04-15 11:53:05 -04003233 break;
dea31012005-04-17 16:05:31 -05003234 default:
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003235 return 1;
dea31012005-04-17 16:05:31 -05003236 }
dea31012005-04-17 16:05:31 -05003237 /* Xmit ELS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003238 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3239 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
3240 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n",
3241 elsiocb->iotag, elsiocb->iocb.ulpContext,
3242 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3243 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003244 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
James Smart2e0fef82007-06-17 19:56:36 -05003245 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003246 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003247 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003248 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
3249 } else {
James Smart858c9f62007-06-17 19:56:39 -05003250 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05003251 }
3252
3253 phba->fc_stat.elsXmitACC++;
dea31012005-04-17 16:05:31 -05003254 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003255 if (rc == IOCB_ERROR) {
3256 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003257 return 1;
dea31012005-04-17 16:05:31 -05003258 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003259 return 0;
dea31012005-04-17 16:05:31 -05003260}
3261
James Smarte59058c2008-08-24 21:49:00 -04003262/**
3263 * lpfc_els_rsp_reject: Propare and issue a rjt response iocb command.
3264 * @vport: pointer to a virtual N_Port data structure.
3265 * @rejectError:
3266 * @oldiocb: pointer to the original lpfc command iocb data structure.
3267 * @ndlp: pointer to a node-list data structure.
3268 * @mbox: pointer to the driver internal queue element for mailbox command.
3269 *
3270 * This routine prepares and issue an Reject (RJT) response IOCB
3271 * command. If a @mbox pointer is passed in, it will be put into the
3272 * context_un.mbox field of the IOCB for the completion callback function
3273 * to issue to the HBA later.
3274 *
3275 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3276 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3277 * will be stored into the context1 field of the IOCB for the completion
3278 * callback function to the reject response ELS IOCB command.
3279 *
3280 * Return code
3281 * 0 - Successfully issued reject response
3282 * 1 - Failed to issue reject response
3283 **/
dea31012005-04-17 16:05:31 -05003284int
James Smart2e0fef82007-06-17 19:56:36 -05003285lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
James Smart858c9f62007-06-17 19:56:39 -05003286 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
3287 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003288{
James Smart2e0fef82007-06-17 19:56:36 -05003289 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003290 IOCB_t *icmd;
3291 IOCB_t *oldcmd;
3292 struct lpfc_iocbq *elsiocb;
3293 struct lpfc_sli_ring *pring;
3294 struct lpfc_sli *psli;
3295 uint8_t *pcmd;
3296 uint16_t cmdsize;
3297 int rc;
3298
3299 psli = &phba->sli;
3300 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
3301
James Smart92d7f7b2007-06-17 19:56:38 -05003302 cmdsize = 2 * sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003303 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3304 ndlp->nlp_DID, ELS_CMD_LS_RJT);
James Smart488d1462006-03-07 15:02:37 -05003305 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003306 return 1;
dea31012005-04-17 16:05:31 -05003307
3308 icmd = &elsiocb->iocb;
3309 oldcmd = &oldiocb->iocb;
3310 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3311 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3312
3313 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
James Smart92d7f7b2007-06-17 19:56:38 -05003314 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003315 *((uint32_t *) (pcmd)) = rejectError;
3316
James Smart51ef4c22007-08-02 11:10:31 -04003317 if (mbox)
James Smart858c9f62007-06-17 19:56:39 -05003318 elsiocb->context_un.mbox = mbox;
James Smart858c9f62007-06-17 19:56:39 -05003319
dea31012005-04-17 16:05:31 -05003320 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003321 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3322 "0129 Xmit ELS RJT x%x response tag x%x "
3323 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
3324 "rpi x%x\n",
3325 rejectError, elsiocb->iotag,
3326 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
3327 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05003328 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3329 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
3330 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
3331
dea31012005-04-17 16:05:31 -05003332 phba->fc_stat.elsXmitLSRJT++;
James Smart858c9f62007-06-17 19:56:39 -05003333 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05003334 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
James Smart51ef4c22007-08-02 11:10:31 -04003335
dea31012005-04-17 16:05:31 -05003336 if (rc == IOCB_ERROR) {
3337 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003338 return 1;
dea31012005-04-17 16:05:31 -05003339 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003340 return 0;
dea31012005-04-17 16:05:31 -05003341}
3342
James Smarte59058c2008-08-24 21:49:00 -04003343/**
3344 * lpfc_els_rsp_adisc_acc: Prepare and issue acc response to adisc iocb cmd.
3345 * @vport: pointer to a virtual N_Port data structure.
3346 * @oldiocb: pointer to the original lpfc command iocb data structure.
3347 * @ndlp: pointer to a node-list data structure.
3348 *
3349 * This routine prepares and issues an Accept (ACC) response to Address
3350 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
3351 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3352 *
3353 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3354 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3355 * will be stored into the context1 field of the IOCB for the completion
3356 * callback function to the ADISC Accept response ELS IOCB command.
3357 *
3358 * Return code
3359 * 0 - Successfully issued acc adisc response
3360 * 1 - Failed to issue adisc acc response
3361 **/
dea31012005-04-17 16:05:31 -05003362int
James Smart2e0fef82007-06-17 19:56:36 -05003363lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
3364 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003365{
James Smart2e0fef82007-06-17 19:56:36 -05003366 struct lpfc_hba *phba = vport->phba;
3367 struct lpfc_sli *psli = &phba->sli;
3368 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05003369 ADISC *ap;
James Smart2e0fef82007-06-17 19:56:36 -05003370 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05003371 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003372 uint8_t *pcmd;
3373 uint16_t cmdsize;
3374 int rc;
3375
James Smart92d7f7b2007-06-17 19:56:38 -05003376 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
James Smart2e0fef82007-06-17 19:56:36 -05003377 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3378 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003379 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003380 return 1;
dea31012005-04-17 16:05:31 -05003381
dea31012005-04-17 16:05:31 -05003382 icmd = &elsiocb->iocb;
3383 oldcmd = &oldiocb->iocb;
3384 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04003385
3386 /* Xmit ADISC ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003387 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3388 "0130 Xmit ADISC ACC response iotag x%x xri: "
3389 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
3390 elsiocb->iotag, elsiocb->iocb.ulpContext,
3391 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3392 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003393 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3394
3395 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003396 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003397
3398 ap = (ADISC *) (pcmd);
3399 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05003400 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
3401 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05003402 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05003403
James Smart858c9f62007-06-17 19:56:39 -05003404 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3405 "Issue ACC ADISC: did:x%x flg:x%x",
3406 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3407
dea31012005-04-17 16:05:31 -05003408 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003409 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05003410 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003411 if (rc == IOCB_ERROR) {
3412 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003413 return 1;
dea31012005-04-17 16:05:31 -05003414 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003415 return 0;
dea31012005-04-17 16:05:31 -05003416}
3417
James Smarte59058c2008-08-24 21:49:00 -04003418/**
3419 * lpfc_els_rsp_prli_acc: Prepare and issue acc response to prli iocb cmd.
3420 * @vport: pointer to a virtual N_Port data structure.
3421 * @oldiocb: pointer to the original lpfc command iocb data structure.
3422 * @ndlp: pointer to a node-list data structure.
3423 *
3424 * This routine prepares and issues an Accept (ACC) response to Process
3425 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
3426 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3427 *
3428 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3429 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3430 * will be stored into the context1 field of the IOCB for the completion
3431 * callback function to the PRLI Accept response ELS IOCB command.
3432 *
3433 * Return code
3434 * 0 - Successfully issued acc prli response
3435 * 1 - Failed to issue acc prli response
3436 **/
dea31012005-04-17 16:05:31 -05003437int
James Smart2e0fef82007-06-17 19:56:36 -05003438lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
James Smart5b8bd0c2007-04-25 09:52:49 -04003439 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003440{
James Smart2e0fef82007-06-17 19:56:36 -05003441 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003442 PRLI *npr;
3443 lpfc_vpd_t *vpd;
3444 IOCB_t *icmd;
3445 IOCB_t *oldcmd;
3446 struct lpfc_iocbq *elsiocb;
3447 struct lpfc_sli_ring *pring;
3448 struct lpfc_sli *psli;
3449 uint8_t *pcmd;
3450 uint16_t cmdsize;
3451 int rc;
3452
3453 psli = &phba->sli;
3454 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
3455
James Smart92d7f7b2007-06-17 19:56:38 -05003456 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
James Smart2e0fef82007-06-17 19:56:36 -05003457 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
James Smart92d7f7b2007-06-17 19:56:38 -05003458 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003459 if (!elsiocb)
3460 return 1;
dea31012005-04-17 16:05:31 -05003461
dea31012005-04-17 16:05:31 -05003462 icmd = &elsiocb->iocb;
3463 oldcmd = &oldiocb->iocb;
3464 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04003465 /* Xmit PRLI ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003466 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3467 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
3468 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
3469 elsiocb->iotag, elsiocb->iocb.ulpContext,
3470 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3471 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003472 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3473
3474 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
James Smart92d7f7b2007-06-17 19:56:38 -05003475 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003476
3477 /* For PRLI, remainder of payload is PRLI parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05003478 memset(pcmd, 0, sizeof(PRLI));
dea31012005-04-17 16:05:31 -05003479
3480 npr = (PRLI *) pcmd;
3481 vpd = &phba->vpd;
3482 /*
James Smart0d2b6b82008-06-14 22:52:47 -04003483 * If the remote port is a target and our firmware version is 3.20 or
3484 * later, set the following bits for FC-TAPE support.
dea31012005-04-17 16:05:31 -05003485 */
James Smart0d2b6b82008-06-14 22:52:47 -04003486 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
3487 (vpd->rev.feaLevelHigh >= 0x02)) {
dea31012005-04-17 16:05:31 -05003488 npr->ConfmComplAllowed = 1;
3489 npr->Retry = 1;
3490 npr->TaskRetryIdReq = 1;
3491 }
3492
3493 npr->acceptRspCode = PRLI_REQ_EXECUTED;
3494 npr->estabImagePair = 1;
3495 npr->readXferRdyDis = 1;
3496 npr->ConfmComplAllowed = 1;
3497
3498 npr->prliType = PRLI_FCP_TYPE;
3499 npr->initiatorFunc = 1;
3500
James Smart858c9f62007-06-17 19:56:39 -05003501 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3502 "Issue ACC PRLI: did:x%x flg:x%x",
3503 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3504
dea31012005-04-17 16:05:31 -05003505 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003506 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05003507
dea31012005-04-17 16:05:31 -05003508 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003509 if (rc == IOCB_ERROR) {
3510 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003511 return 1;
dea31012005-04-17 16:05:31 -05003512 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003513 return 0;
dea31012005-04-17 16:05:31 -05003514}
3515
James Smarte59058c2008-08-24 21:49:00 -04003516/**
3517 * lpfc_els_rsp_rnid_acc: Issue rnid acc response iocb command.
3518 * @vport: pointer to a virtual N_Port data structure.
3519 * @format: rnid command format.
3520 * @oldiocb: pointer to the original lpfc command iocb data structure.
3521 * @ndlp: pointer to a node-list data structure.
3522 *
3523 * This routine issues a Request Node Identification Data (RNID) Accept
3524 * (ACC) response. It constructs the RNID ACC response command according to
3525 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
3526 * issue the response. Note that this command does not need to hold the ndlp
3527 * reference count for the callback. So, the ndlp reference count taken by
3528 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
3529 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
3530 * there is no ndlp reference available.
3531 *
3532 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3533 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3534 * will be stored into the context1 field of the IOCB for the completion
3535 * callback function. However, for the RNID Accept Response ELS command,
3536 * this is undone later by this routine after the IOCB is allocated.
3537 *
3538 * Return code
3539 * 0 - Successfully issued acc rnid response
3540 * 1 - Failed to issue acc rnid response
3541 **/
dea31012005-04-17 16:05:31 -05003542static int
James Smart2e0fef82007-06-17 19:56:36 -05003543lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
James Smart329f9bc2007-04-25 09:53:01 -04003544 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003545{
James Smart2e0fef82007-06-17 19:56:36 -05003546 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003547 RNID *rn;
James Smart2e0fef82007-06-17 19:56:36 -05003548 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05003549 struct lpfc_iocbq *elsiocb;
3550 struct lpfc_sli_ring *pring;
3551 struct lpfc_sli *psli;
3552 uint8_t *pcmd;
3553 uint16_t cmdsize;
3554 int rc;
3555
3556 psli = &phba->sli;
3557 pring = &psli->ring[LPFC_ELS_RING];
3558
James Smart92d7f7b2007-06-17 19:56:38 -05003559 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
3560 + (2 * sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003561 if (format)
James Smart92d7f7b2007-06-17 19:56:38 -05003562 cmdsize += sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05003563
James Smart2e0fef82007-06-17 19:56:36 -05003564 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3565 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003566 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003567 return 1;
dea31012005-04-17 16:05:31 -05003568
dea31012005-04-17 16:05:31 -05003569 icmd = &elsiocb->iocb;
3570 oldcmd = &oldiocb->iocb;
3571 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04003572 /* Xmit RNID ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003573 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3574 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
3575 elsiocb->iotag, elsiocb->iocb.ulpContext);
dea31012005-04-17 16:05:31 -05003576 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
dea31012005-04-17 16:05:31 -05003577 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003578 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003579
James Smart92d7f7b2007-06-17 19:56:38 -05003580 memset(pcmd, 0, sizeof(RNID));
dea31012005-04-17 16:05:31 -05003581 rn = (RNID *) (pcmd);
3582 rn->Format = format;
James Smart92d7f7b2007-06-17 19:56:38 -05003583 rn->CommonLen = (2 * sizeof(struct lpfc_name));
3584 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
3585 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003586 switch (format) {
3587 case 0:
3588 rn->SpecificLen = 0;
3589 break;
3590 case RNID_TOPOLOGY_DISC:
James Smart92d7f7b2007-06-17 19:56:38 -05003591 rn->SpecificLen = sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05003592 memcpy(&rn->un.topologyDisc.portName,
James Smart92d7f7b2007-06-17 19:56:38 -05003593 &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003594 rn->un.topologyDisc.unitType = RNID_HBA;
3595 rn->un.topologyDisc.physPort = 0;
3596 rn->un.topologyDisc.attachedNodes = 0;
3597 break;
3598 default:
3599 rn->CommonLen = 0;
3600 rn->SpecificLen = 0;
3601 break;
3602 }
3603
James Smart858c9f62007-06-17 19:56:39 -05003604 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3605 "Issue ACC RNID: did:x%x flg:x%x",
3606 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3607
dea31012005-04-17 16:05:31 -05003608 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003609 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart329f9bc2007-04-25 09:53:01 -04003610 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05003611 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
3612 * it could be freed */
3613
dea31012005-04-17 16:05:31 -05003614 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003615 if (rc == IOCB_ERROR) {
3616 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003617 return 1;
dea31012005-04-17 16:05:31 -05003618 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003619 return 0;
dea31012005-04-17 16:05:31 -05003620}
3621
James Smarte59058c2008-08-24 21:49:00 -04003622/**
3623 * lpfc_els_disc_adisc: Issue remaining adisc iocbs to npr nodes of a vport.
3624 * @vport: pointer to a host virtual N_Port data structure.
3625 *
3626 * This routine issues Address Discover (ADISC) ELS commands to those
3627 * N_Ports which are in node port recovery state and ADISC has not been issued
3628 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
3629 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
3630 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
3631 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
3632 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
3633 * IOCBs quit for later pick up. On the other hand, after walking through
3634 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
3635 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
3636 * no more ADISC need to be sent.
3637 *
3638 * Return code
3639 * The number of N_Ports with adisc issued.
3640 **/
dea31012005-04-17 16:05:31 -05003641int
James Smart2e0fef82007-06-17 19:56:36 -05003642lpfc_els_disc_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003643{
James Smart2e0fef82007-06-17 19:56:36 -05003644 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05003645 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05003646 int sentadisc = 0;
dea31012005-04-17 16:05:31 -05003647
James Smart685f0bf2007-04-25 09:53:08 -04003648 /* go thru NPR nodes and issue any remaining ELS ADISCs */
James Smart2e0fef82007-06-17 19:56:36 -05003649 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05003650 if (!NLP_CHK_NODE_ACT(ndlp))
3651 continue;
James Smart685f0bf2007-04-25 09:53:08 -04003652 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
3653 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
3654 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
James Smart2e0fef82007-06-17 19:56:36 -05003655 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003656 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05003657 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003658 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003659 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3660 lpfc_issue_els_adisc(vport, ndlp, 0);
James Smart685f0bf2007-04-25 09:53:08 -04003661 sentadisc++;
James Smart2e0fef82007-06-17 19:56:36 -05003662 vport->num_disc_nodes++;
3663 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04003664 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05003665 spin_lock_irq(shost->host_lock);
3666 vport->fc_flag |= FC_NLP_MORE;
3667 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003668 break;
dea31012005-04-17 16:05:31 -05003669 }
3670 }
3671 }
3672 if (sentadisc == 0) {
James Smart2e0fef82007-06-17 19:56:36 -05003673 spin_lock_irq(shost->host_lock);
3674 vport->fc_flag &= ~FC_NLP_MORE;
3675 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003676 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003677 return sentadisc;
dea31012005-04-17 16:05:31 -05003678}
3679
James Smarte59058c2008-08-24 21:49:00 -04003680/**
3681 * lpfc_els_disc_plogi: Issue plogi for all npr nodes of a vport before adisc.
3682 * @vport: pointer to a host virtual N_Port data structure.
3683 *
3684 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
3685 * which are in node port recovery state, with a @vport. Each time an ELS
3686 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
3687 * the per @vport number of discover count (num_disc_nodes) shall be
3688 * incremented. If the num_disc_nodes reaches a pre-configured threshold
3689 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
3690 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
3691 * later pick up. On the other hand, after walking through all the ndlps with
3692 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
3693 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
3694 * PLOGI need to be sent.
3695 *
3696 * Return code
3697 * The number of N_Ports with plogi issued.
3698 **/
dea31012005-04-17 16:05:31 -05003699int
James Smart2e0fef82007-06-17 19:56:36 -05003700lpfc_els_disc_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003701{
James Smart2e0fef82007-06-17 19:56:36 -05003702 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05003703 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05003704 int sentplogi = 0;
dea31012005-04-17 16:05:31 -05003705
James Smart2e0fef82007-06-17 19:56:36 -05003706 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
3707 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05003708 if (!NLP_CHK_NODE_ACT(ndlp))
3709 continue;
James Smart685f0bf2007-04-25 09:53:08 -04003710 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
3711 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
3712 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
3713 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
3714 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003715 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
3716 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
James Smart685f0bf2007-04-25 09:53:08 -04003717 sentplogi++;
James Smart2e0fef82007-06-17 19:56:36 -05003718 vport->num_disc_nodes++;
3719 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04003720 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05003721 spin_lock_irq(shost->host_lock);
3722 vport->fc_flag |= FC_NLP_MORE;
3723 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003724 break;
dea31012005-04-17 16:05:31 -05003725 }
3726 }
3727 }
James Smart87af33f2007-10-27 13:37:43 -04003728 if (sentplogi) {
3729 lpfc_set_disctmo(vport);
3730 }
3731 else {
James Smart2e0fef82007-06-17 19:56:36 -05003732 spin_lock_irq(shost->host_lock);
3733 vport->fc_flag &= ~FC_NLP_MORE;
3734 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003735 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003736 return sentplogi;
dea31012005-04-17 16:05:31 -05003737}
3738
James Smarte59058c2008-08-24 21:49:00 -04003739/**
3740 * lpfc_els_flush_rscn: Clean up any rscn activities with a vport.
3741 * @vport: pointer to a host virtual N_Port data structure.
3742 *
3743 * This routine cleans up any Registration State Change Notification
3744 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
3745 * @vport together with the host_lock is used to prevent multiple thread
3746 * trying to access the RSCN array on a same @vport at the same time.
3747 **/
James Smart92d7f7b2007-06-17 19:56:38 -05003748void
James Smart2e0fef82007-06-17 19:56:36 -05003749lpfc_els_flush_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003750{
James Smart2e0fef82007-06-17 19:56:36 -05003751 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3752 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003753 int i;
3754
James Smart7f5f3d02008-02-08 18:50:14 -05003755 spin_lock_irq(shost->host_lock);
3756 if (vport->fc_rscn_flush) {
3757 /* Another thread is walking fc_rscn_id_list on this vport */
3758 spin_unlock_irq(shost->host_lock);
3759 return;
3760 }
3761 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
3762 vport->fc_rscn_flush = 1;
3763 spin_unlock_irq(shost->host_lock);
3764
James Smart2e0fef82007-06-17 19:56:36 -05003765 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05003766 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
James Smart2e0fef82007-06-17 19:56:36 -05003767 vport->fc_rscn_id_list[i] = NULL;
dea31012005-04-17 16:05:31 -05003768 }
James Smart2e0fef82007-06-17 19:56:36 -05003769 spin_lock_irq(shost->host_lock);
3770 vport->fc_rscn_id_cnt = 0;
3771 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
3772 spin_unlock_irq(shost->host_lock);
3773 lpfc_can_disctmo(vport);
James Smart7f5f3d02008-02-08 18:50:14 -05003774 /* Indicate we are done walking this fc_rscn_id_list */
3775 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05003776}
3777
James Smarte59058c2008-08-24 21:49:00 -04003778/**
3779 * lpfc_rscn_payload_check: Check whether there is a pending rscn to a did.
3780 * @vport: pointer to a host virtual N_Port data structure.
3781 * @did: remote destination port identifier.
3782 *
3783 * This routine checks whether there is any pending Registration State
3784 * Configuration Notification (RSCN) to a @did on @vport.
3785 *
3786 * Return code
3787 * None zero - The @did matched with a pending rscn
3788 * 0 - not able to match @did with a pending rscn
3789 **/
dea31012005-04-17 16:05:31 -05003790int
James Smart2e0fef82007-06-17 19:56:36 -05003791lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05003792{
3793 D_ID ns_did;
3794 D_ID rscn_did;
dea31012005-04-17 16:05:31 -05003795 uint32_t *lp;
James Smart92d7f7b2007-06-17 19:56:38 -05003796 uint32_t payload_len, i;
James Smart7f5f3d02008-02-08 18:50:14 -05003797 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05003798
3799 ns_did.un.word = did;
dea31012005-04-17 16:05:31 -05003800
3801 /* Never match fabric nodes for RSCNs */
3802 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
James Smart2e0fef82007-06-17 19:56:36 -05003803 return 0;
dea31012005-04-17 16:05:31 -05003804
3805 /* If we are doing a FULL RSCN rediscovery, match everything */
James Smart2e0fef82007-06-17 19:56:36 -05003806 if (vport->fc_flag & FC_RSCN_DISCOVERY)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003807 return did;
dea31012005-04-17 16:05:31 -05003808
James Smart7f5f3d02008-02-08 18:50:14 -05003809 spin_lock_irq(shost->host_lock);
3810 if (vport->fc_rscn_flush) {
3811 /* Another thread is walking fc_rscn_id_list on this vport */
3812 spin_unlock_irq(shost->host_lock);
3813 return 0;
3814 }
3815 /* Indicate we are walking fc_rscn_id_list on this vport */
3816 vport->fc_rscn_flush = 1;
3817 spin_unlock_irq(shost->host_lock);
James Smart2e0fef82007-06-17 19:56:36 -05003818 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05003819 lp = vport->fc_rscn_id_list[i]->virt;
3820 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
3821 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05003822 while (payload_len) {
James Smart92d7f7b2007-06-17 19:56:38 -05003823 rscn_did.un.word = be32_to_cpu(*lp++);
3824 payload_len -= sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003825 switch (rscn_did.un.b.resv) {
3826 case 0: /* Single N_Port ID effected */
James Smart2e0fef82007-06-17 19:56:36 -05003827 if (ns_did.un.word == rscn_did.un.word)
James Smart7f5f3d02008-02-08 18:50:14 -05003828 goto return_did_out;
dea31012005-04-17 16:05:31 -05003829 break;
3830 case 1: /* Whole N_Port Area effected */
3831 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
3832 && (ns_did.un.b.area == rscn_did.un.b.area))
James Smart7f5f3d02008-02-08 18:50:14 -05003833 goto return_did_out;
dea31012005-04-17 16:05:31 -05003834 break;
3835 case 2: /* Whole N_Port Domain effected */
3836 if (ns_did.un.b.domain == rscn_did.un.b.domain)
James Smart7f5f3d02008-02-08 18:50:14 -05003837 goto return_did_out;
dea31012005-04-17 16:05:31 -05003838 break;
3839 default:
James Smart2e0fef82007-06-17 19:56:36 -05003840 /* Unknown Identifier in RSCN node */
James Smarte8b62012007-08-02 11:10:09 -04003841 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
3842 "0217 Unknown Identifier in "
3843 "RSCN payload Data: x%x\n",
3844 rscn_did.un.word);
James Smart92d7f7b2007-06-17 19:56:38 -05003845 case 3: /* Whole Fabric effected */
James Smart7f5f3d02008-02-08 18:50:14 -05003846 goto return_did_out;
dea31012005-04-17 16:05:31 -05003847 }
3848 }
James Smart92d7f7b2007-06-17 19:56:38 -05003849 }
James Smart7f5f3d02008-02-08 18:50:14 -05003850 /* Indicate we are done with walking fc_rscn_id_list on this vport */
3851 vport->fc_rscn_flush = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05003852 return 0;
James Smart7f5f3d02008-02-08 18:50:14 -05003853return_did_out:
3854 /* Indicate we are done with walking fc_rscn_id_list on this vport */
3855 vport->fc_rscn_flush = 0;
3856 return did;
dea31012005-04-17 16:05:31 -05003857}
3858
James Smarte59058c2008-08-24 21:49:00 -04003859/**
3860 * lpfc_rscn_recovery_check: Send recovery event to vport nodes matching rscn
3861 * @vport: pointer to a host virtual N_Port data structure.
3862 *
3863 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
3864 * state machine for a @vport's nodes that are with pending RSCN (Registration
3865 * State Change Notification).
3866 *
3867 * Return code
3868 * 0 - Successful (currently alway return 0)
3869 **/
dea31012005-04-17 16:05:31 -05003870static int
James Smart2e0fef82007-06-17 19:56:36 -05003871lpfc_rscn_recovery_check(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003872{
James Smart685f0bf2007-04-25 09:53:08 -04003873 struct lpfc_nodelist *ndlp = NULL;
dea31012005-04-17 16:05:31 -05003874
James Smart0d2b6b82008-06-14 22:52:47 -04003875 /* Move all affected nodes by pending RSCNs to NPR state. */
James Smart2e0fef82007-06-17 19:56:36 -05003876 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05003877 if (!NLP_CHK_NODE_ACT(ndlp) ||
James Smart0d2b6b82008-06-14 22:52:47 -04003878 (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
3879 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
dea31012005-04-17 16:05:31 -05003880 continue;
James Smart2e0fef82007-06-17 19:56:36 -05003881 lpfc_disc_state_machine(vport, ndlp, NULL,
James Smart0d2b6b82008-06-14 22:52:47 -04003882 NLP_EVT_DEVICE_RECOVERY);
3883 lpfc_cancel_retry_delay_tmo(vport, ndlp);
dea31012005-04-17 16:05:31 -05003884 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003885 return 0;
dea31012005-04-17 16:05:31 -05003886}
3887
James Smarte59058c2008-08-24 21:49:00 -04003888/**
3889 * lpfc_els_rcv_rscn: Process an unsolicited rscn iocb.
3890 * @vport: pointer to a host virtual N_Port data structure.
3891 * @cmdiocb: pointer to lpfc command iocb data structure.
3892 * @ndlp: pointer to a node-list data structure.
3893 *
3894 * This routine processes an unsolicited RSCN (Registration State Change
3895 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
3896 * to invoke fc_host_post_event() routine to the FC transport layer. If the
3897 * discover state machine is about to begin discovery, it just accepts the
3898 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
3899 * contains N_Port IDs for other vports on this HBA, it just accepts the
3900 * RSCN and ignore processing it. If the state machine is in the recovery
3901 * state, the fc_rscn_id_list of this @vport is walked and the
3902 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
3903 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
3904 * routine is invoked to handle the RSCN event.
3905 *
3906 * Return code
3907 * 0 - Just sent the acc response
3908 * 1 - Sent the acc response and waited for name server completion
3909 **/
dea31012005-04-17 16:05:31 -05003910static int
James Smart2e0fef82007-06-17 19:56:36 -05003911lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04003912 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003913{
James Smart2e0fef82007-06-17 19:56:36 -05003914 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3915 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003916 struct lpfc_dmabuf *pcmd;
James Smart92d7f7b2007-06-17 19:56:38 -05003917 uint32_t *lp, *datap;
dea31012005-04-17 16:05:31 -05003918 IOCB_t *icmd;
James Smart92d7f7b2007-06-17 19:56:38 -05003919 uint32_t payload_len, length, nportid, *cmd;
James Smart7f5f3d02008-02-08 18:50:14 -05003920 int rscn_cnt;
James Smart92d7f7b2007-06-17 19:56:38 -05003921 int rscn_id = 0, hba_id = 0;
James Smartd2873e42006-08-18 17:46:43 -04003922 int i;
dea31012005-04-17 16:05:31 -05003923
3924 icmd = &cmdiocb->iocb;
3925 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3926 lp = (uint32_t *) pcmd->virt;
3927
James Smart92d7f7b2007-06-17 19:56:38 -05003928 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
3929 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05003930 /* RSCN received */
James Smarte8b62012007-08-02 11:10:09 -04003931 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3932 "0214 RSCN received Data: x%x x%x x%x x%x\n",
James Smart7f5f3d02008-02-08 18:50:14 -05003933 vport->fc_flag, payload_len, *lp,
3934 vport->fc_rscn_id_cnt);
James Smartd2873e42006-08-18 17:46:43 -04003935 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
James Smart2e0fef82007-06-17 19:56:36 -05003936 fc_host_post_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04003937 FCH_EVT_RSCN, lp[i]);
3938
dea31012005-04-17 16:05:31 -05003939 /* If we are about to begin discovery, just ACC the RSCN.
3940 * Discovery processing will satisfy it.
3941 */
James Smart2e0fef82007-06-17 19:56:36 -05003942 if (vport->port_state <= LPFC_NS_QRY) {
James Smart858c9f62007-06-17 19:56:39 -05003943 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3944 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
3945 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
3946
James Smart51ef4c22007-08-02 11:10:31 -04003947 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003948 return 0;
dea31012005-04-17 16:05:31 -05003949 }
3950
James Smart92d7f7b2007-06-17 19:56:38 -05003951 /* If this RSCN just contains NPortIDs for other vports on this HBA,
3952 * just ACC and ignore it.
3953 */
3954 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart3de2a652007-08-02 11:09:59 -04003955 !(vport->cfg_peer_port_login)) {
James Smart92d7f7b2007-06-17 19:56:38 -05003956 i = payload_len;
3957 datap = lp;
3958 while (i > 0) {
3959 nportid = *datap++;
3960 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
3961 i -= sizeof(uint32_t);
3962 rscn_id++;
James Smart549e55c2007-08-02 11:09:51 -04003963 if (lpfc_find_vport_by_did(phba, nportid))
3964 hba_id++;
James Smart92d7f7b2007-06-17 19:56:38 -05003965 }
3966 if (rscn_id == hba_id) {
3967 /* ALL NPortIDs in RSCN are on HBA */
James Smarte8b62012007-08-02 11:10:09 -04003968 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3969 "0214 Ignore RSCN "
3970 "Data: x%x x%x x%x x%x\n",
3971 vport->fc_flag, payload_len,
James Smart7f5f3d02008-02-08 18:50:14 -05003972 *lp, vport->fc_rscn_id_cnt);
James Smart858c9f62007-06-17 19:56:39 -05003973 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
3974 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
3975 ndlp->nlp_DID, vport->port_state,
3976 ndlp->nlp_flag);
3977
James Smart92d7f7b2007-06-17 19:56:38 -05003978 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04003979 ndlp, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05003980 return 0;
3981 }
3982 }
3983
James Smart7f5f3d02008-02-08 18:50:14 -05003984 spin_lock_irq(shost->host_lock);
3985 if (vport->fc_rscn_flush) {
3986 /* Another thread is walking fc_rscn_id_list on this vport */
3987 spin_unlock_irq(shost->host_lock);
3988 vport->fc_flag |= FC_RSCN_DISCOVERY;
James Smart58da1ff2008-04-07 10:15:56 -04003989 /* Send back ACC */
3990 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart7f5f3d02008-02-08 18:50:14 -05003991 return 0;
3992 }
3993 /* Indicate we are walking fc_rscn_id_list on this vport */
3994 vport->fc_rscn_flush = 1;
3995 spin_unlock_irq(shost->host_lock);
3996 /* Get the array count after sucessfully have the token */
3997 rscn_cnt = vport->fc_rscn_id_cnt;
dea31012005-04-17 16:05:31 -05003998 /* If we are already processing an RSCN, save the received
3999 * RSCN payload buffer, cmdiocb->context2 to process later.
4000 */
James Smart2e0fef82007-06-17 19:56:36 -05004001 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
James Smart858c9f62007-06-17 19:56:39 -05004002 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4003 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
4004 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4005
James Smart09372822008-01-11 01:52:54 -05004006 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004007 vport->fc_flag |= FC_RSCN_DEFERRED;
4008 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
James Smart2e0fef82007-06-17 19:56:36 -05004009 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
James Smart2e0fef82007-06-17 19:56:36 -05004010 vport->fc_flag |= FC_RSCN_MODE;
4011 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004012 if (rscn_cnt) {
4013 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
4014 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
4015 }
4016 if ((rscn_cnt) &&
4017 (payload_len + length <= LPFC_BPL_SIZE)) {
4018 *cmd &= ELS_CMD_MASK;
James Smart7f5f3d02008-02-08 18:50:14 -05004019 *cmd |= cpu_to_be32(payload_len + length);
James Smart92d7f7b2007-06-17 19:56:38 -05004020 memcpy(((uint8_t *)cmd) + length, lp,
4021 payload_len);
4022 } else {
4023 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
4024 vport->fc_rscn_id_cnt++;
4025 /* If we zero, cmdiocb->context2, the calling
4026 * routine will not try to free it.
4027 */
4028 cmdiocb->context2 = NULL;
4029 }
dea31012005-04-17 16:05:31 -05004030 /* Deferred RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004031 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4032 "0235 Deferred RSCN "
4033 "Data: x%x x%x x%x\n",
4034 vport->fc_rscn_id_cnt, vport->fc_flag,
4035 vport->port_state);
dea31012005-04-17 16:05:31 -05004036 } else {
James Smart2e0fef82007-06-17 19:56:36 -05004037 vport->fc_flag |= FC_RSCN_DISCOVERY;
4038 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004039 /* ReDiscovery RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004040 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4041 "0234 ReDiscovery RSCN "
4042 "Data: x%x x%x x%x\n",
4043 vport->fc_rscn_id_cnt, vport->fc_flag,
4044 vport->port_state);
dea31012005-04-17 16:05:31 -05004045 }
James Smart7f5f3d02008-02-08 18:50:14 -05004046 /* Indicate we are done walking fc_rscn_id_list on this vport */
4047 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004048 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004049 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004050 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004051 lpfc_rscn_recovery_check(vport);
James Smart09372822008-01-11 01:52:54 -05004052 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004053 vport->fc_flag &= ~FC_RSCN_DEFERRED;
James Smart09372822008-01-11 01:52:54 -05004054 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004055 return 0;
dea31012005-04-17 16:05:31 -05004056 }
James Smart858c9f62007-06-17 19:56:39 -05004057 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4058 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
4059 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4060
James Smart2e0fef82007-06-17 19:56:36 -05004061 spin_lock_irq(shost->host_lock);
4062 vport->fc_flag |= FC_RSCN_MODE;
4063 spin_unlock_irq(shost->host_lock);
4064 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
James Smart7f5f3d02008-02-08 18:50:14 -05004065 /* Indicate we are done walking fc_rscn_id_list on this vport */
4066 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004067 /*
4068 * If we zero, cmdiocb->context2, the calling routine will
4069 * not try to free it.
4070 */
4071 cmdiocb->context2 = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05004072 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004073 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004074 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004075 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004076 lpfc_rscn_recovery_check(vport);
James Smart2e0fef82007-06-17 19:56:36 -05004077 return lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05004078}
4079
James Smarte59058c2008-08-24 21:49:00 -04004080/**
4081 * lpfc_els_handle_rscn: Handle rscn for a vport.
4082 * @vport: pointer to a host virtual N_Port data structure.
4083 *
4084 * This routine handles the Registration State Configuration Notification
4085 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
4086 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
4087 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
4088 * NameServer shall be issued. If CT command to the NameServer fails to be
4089 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
4090 * RSCN activities with the @vport.
4091 *
4092 * Return code
4093 * 0 - Cleaned up rscn on the @vport
4094 * 1 - Wait for plogi to name server before proceed
4095 **/
dea31012005-04-17 16:05:31 -05004096int
James Smart2e0fef82007-06-17 19:56:36 -05004097lpfc_els_handle_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004098{
4099 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004100 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004101
James Smart92d7f7b2007-06-17 19:56:38 -05004102 /* Ignore RSCN if the port is being torn down. */
4103 if (vport->load_flag & FC_UNLOADING) {
4104 lpfc_els_flush_rscn(vport);
4105 return 0;
4106 }
4107
dea31012005-04-17 16:05:31 -05004108 /* Start timer for RSCN processing */
James Smart2e0fef82007-06-17 19:56:36 -05004109 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004110
4111 /* RSCN processed */
James Smarte8b62012007-08-02 11:10:09 -04004112 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4113 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
4114 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
4115 vport->port_state);
dea31012005-04-17 16:05:31 -05004116
4117 /* To process RSCN, first compare RSCN data with NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004118 vport->fc_ns_retry = 0;
James Smart0ff10d42008-01-11 01:52:36 -05004119 vport->num_disc_nodes = 0;
4120
James Smart2e0fef82007-06-17 19:56:36 -05004121 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004122 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
4123 && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
dea31012005-04-17 16:05:31 -05004124 /* Good ndlp, issue CT Request to NameServer */
James Smart92d7f7b2007-06-17 19:56:38 -05004125 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
dea31012005-04-17 16:05:31 -05004126 /* Wait for NameServer query cmpl before we can
4127 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004128 return 1;
dea31012005-04-17 16:05:31 -05004129 } else {
4130 /* If login to NameServer does not exist, issue one */
4131 /* Good status, issue PLOGI to NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004132 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004133 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
dea31012005-04-17 16:05:31 -05004134 /* Wait for NameServer login cmpl before we can
4135 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004136 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05004137
James Smarte47c9092008-02-08 18:49:26 -05004138 if (ndlp) {
4139 ndlp = lpfc_enable_node(vport, ndlp,
4140 NLP_STE_PLOGI_ISSUE);
4141 if (!ndlp) {
4142 lpfc_els_flush_rscn(vport);
4143 return 0;
4144 }
4145 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
dea31012005-04-17 16:05:31 -05004146 } else {
James Smarte47c9092008-02-08 18:49:26 -05004147 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
4148 if (!ndlp) {
4149 lpfc_els_flush_rscn(vport);
4150 return 0;
4151 }
James Smart2e0fef82007-06-17 19:56:36 -05004152 lpfc_nlp_init(vport, ndlp, NameServer_DID);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004153 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004154 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
dea31012005-04-17 16:05:31 -05004155 }
James Smarte47c9092008-02-08 18:49:26 -05004156 ndlp->nlp_type |= NLP_FABRIC;
4157 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
4158 /* Wait for NameServer login cmpl before we can
4159 * continue
4160 */
4161 return 1;
dea31012005-04-17 16:05:31 -05004162 }
4163
James Smart2e0fef82007-06-17 19:56:36 -05004164 lpfc_els_flush_rscn(vport);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004165 return 0;
dea31012005-04-17 16:05:31 -05004166}
4167
James Smarte59058c2008-08-24 21:49:00 -04004168/**
4169 * lpfc_els_rcv_flogi: Process an unsolicited flogi iocb.
4170 * @vport: pointer to a host virtual N_Port data structure.
4171 * @cmdiocb: pointer to lpfc command iocb data structure.
4172 * @ndlp: pointer to a node-list data structure.
4173 *
4174 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
4175 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
4176 * point topology. As an unsolicited FLOGI should not be received in a loop
4177 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
4178 * lpfc_check_sparm() routine is invoked to check the parameters in the
4179 * unsolicited FLOGI. If parameters validation failed, the routine
4180 * lpfc_els_rsp_reject() shall be called with reject reason code set to
4181 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
4182 * FLOGI shall be compared with the Port WWN of the @vport to determine who
4183 * will initiate PLOGI. The higher lexicographical value party shall has
4184 * higher priority (as the winning port) and will initiate PLOGI and
4185 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
4186 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
4187 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
4188 *
4189 * Return code
4190 * 0 - Successfully processed the unsolicited flogi
4191 * 1 - Failed to process the unsolicited flogi
4192 **/
dea31012005-04-17 16:05:31 -05004193static int
James Smart2e0fef82007-06-17 19:56:36 -05004194lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004195 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004196{
James Smart2e0fef82007-06-17 19:56:36 -05004197 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4198 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004199 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4200 uint32_t *lp = (uint32_t *) pcmd->virt;
4201 IOCB_t *icmd = &cmdiocb->iocb;
4202 struct serv_parm *sp;
4203 LPFC_MBOXQ_t *mbox;
4204 struct ls_rjt stat;
4205 uint32_t cmd, did;
4206 int rc;
4207
4208 cmd = *lp++;
4209 sp = (struct serv_parm *) lp;
4210
4211 /* FLOGI received */
4212
James Smart2e0fef82007-06-17 19:56:36 -05004213 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004214
4215 if (phba->fc_topology == TOPOLOGY_LOOP) {
4216 /* We should never receive a FLOGI in loop mode, ignore it */
4217 did = icmd->un.elsreq64.remoteID;
4218
4219 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
4220 Loop Mode */
James Smarte8b62012007-08-02 11:10:09 -04004221 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4222 "0113 An FLOGI ELS command x%x was "
4223 "received from DID x%x in Loop Mode\n",
4224 cmd, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004225 return 1;
dea31012005-04-17 16:05:31 -05004226 }
4227
4228 did = Fabric_DID;
4229
James Smart2e0fef82007-06-17 19:56:36 -05004230 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3))) {
dea31012005-04-17 16:05:31 -05004231 /* For a FLOGI we accept, then if our portname is greater
4232 * then the remote portname we initiate Nport login.
4233 */
4234
James Smart2e0fef82007-06-17 19:56:36 -05004235 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -05004236 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004237
4238 if (!rc) {
James Smart2e0fef82007-06-17 19:56:36 -05004239 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4240 if (!mbox)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004241 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05004242
dea31012005-04-17 16:05:31 -05004243 lpfc_linkdown(phba);
4244 lpfc_init_link(phba, mbox,
4245 phba->cfg_topology,
4246 phba->cfg_link_speed);
4247 mbox->mb.un.varInitLnk.lipsr_AL_PA = 0;
4248 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -05004249 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -04004250 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart5b8bd0c2007-04-25 09:52:49 -04004251 lpfc_set_loopback_flag(phba);
dea31012005-04-17 16:05:31 -05004252 if (rc == MBX_NOT_FINISHED) {
James Smart329f9bc2007-04-25 09:53:01 -04004253 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004254 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004255 return 1;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004256 } else if (rc > 0) { /* greater than */
James Smart2e0fef82007-06-17 19:56:36 -05004257 spin_lock_irq(shost->host_lock);
4258 vport->fc_flag |= FC_PT2PT_PLOGI;
4259 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004260 }
James Smart2e0fef82007-06-17 19:56:36 -05004261 spin_lock_irq(shost->host_lock);
4262 vport->fc_flag |= FC_PT2PT;
4263 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
4264 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004265 } else {
4266 /* Reject this request because invalid parameters */
4267 stat.un.b.lsRjtRsvd0 = 0;
4268 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4269 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
4270 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004271 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4272 NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004273 return 1;
dea31012005-04-17 16:05:31 -05004274 }
4275
4276 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004277 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004278
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004279 return 0;
dea31012005-04-17 16:05:31 -05004280}
4281
James Smarte59058c2008-08-24 21:49:00 -04004282/**
4283 * lpfc_els_rcv_rnid: Process an unsolicited rnid iocb.
4284 * @vport: pointer to a host virtual N_Port data structure.
4285 * @cmdiocb: pointer to lpfc command iocb data structure.
4286 * @ndlp: pointer to a node-list data structure.
4287 *
4288 * This routine processes Request Node Identification Data (RNID) IOCB
4289 * received as an ELS unsolicited event. Only when the RNID specified format
4290 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
4291 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
4292 * Accept (ACC) the RNID ELS command. All the other RNID formats are
4293 * rejected by invoking the lpfc_els_rsp_reject() routine.
4294 *
4295 * Return code
4296 * 0 - Successfully processed rnid iocb (currently always return 0)
4297 **/
dea31012005-04-17 16:05:31 -05004298static int
James Smart2e0fef82007-06-17 19:56:36 -05004299lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4300 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004301{
4302 struct lpfc_dmabuf *pcmd;
4303 uint32_t *lp;
4304 IOCB_t *icmd;
4305 RNID *rn;
4306 struct ls_rjt stat;
4307 uint32_t cmd, did;
4308
4309 icmd = &cmdiocb->iocb;
4310 did = icmd->un.elsreq64.remoteID;
4311 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4312 lp = (uint32_t *) pcmd->virt;
4313
4314 cmd = *lp++;
4315 rn = (RNID *) lp;
4316
4317 /* RNID received */
4318
4319 switch (rn->Format) {
4320 case 0:
4321 case RNID_TOPOLOGY_DISC:
4322 /* Send back ACC */
James Smart2e0fef82007-06-17 19:56:36 -05004323 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05004324 break;
4325 default:
4326 /* Reject this request because format not supported */
4327 stat.un.b.lsRjtRsvd0 = 0;
4328 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4329 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4330 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004331 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4332 NULL);
dea31012005-04-17 16:05:31 -05004333 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004334 return 0;
dea31012005-04-17 16:05:31 -05004335}
4336
James Smarte59058c2008-08-24 21:49:00 -04004337/**
4338 * lpfc_els_rcv_lirr: Process an unsolicited lirr iocb.
4339 * @vport: pointer to a host virtual N_Port data structure.
4340 * @cmdiocb: pointer to lpfc command iocb data structure.
4341 * @ndlp: pointer to a node-list data structure.
4342 *
4343 * This routine processes a Link Incident Report Registration(LIRR) IOCB
4344 * received as an ELS unsolicited event. Currently, this function just invokes
4345 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
4346 *
4347 * Return code
4348 * 0 - Successfully processed lirr iocb (currently always return 0)
4349 **/
dea31012005-04-17 16:05:31 -05004350static int
James Smart2e0fef82007-06-17 19:56:36 -05004351lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4352 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004353{
4354 struct ls_rjt stat;
4355
4356 /* For now, unconditionally reject this command */
4357 stat.un.b.lsRjtRsvd0 = 0;
4358 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4359 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4360 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004361 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004362 return 0;
4363}
4364
James Smarte59058c2008-08-24 21:49:00 -04004365/**
4366 * lpfc_els_rsp_rps_acc: Completion callbk func for MBX_READ_LNK_STAT mbox cmd.
4367 * @phba: pointer to lpfc hba data structure.
4368 * @pmb: pointer to the driver internal queue element for mailbox command.
4369 *
4370 * This routine is the completion callback function for the MBX_READ_LNK_STAT
4371 * mailbox command. This callback function is to actually send the Accept
4372 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
4373 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
4374 * mailbox command, constructs the RPS response with the link statistics
4375 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
4376 * response to the RPS.
4377 *
4378 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4379 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4380 * will be stored into the context1 field of the IOCB for the completion
4381 * callback function to the RPS Accept Response ELS IOCB command.
4382 *
4383 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05004384static void
James Smart329f9bc2007-04-25 09:53:01 -04004385lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004386{
James Smart2e0fef82007-06-17 19:56:36 -05004387 struct lpfc_sli *psli = &phba->sli;
4388 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004389 MAILBOX_t *mb;
4390 IOCB_t *icmd;
4391 RPS_RSP *rps_rsp;
4392 uint8_t *pcmd;
4393 struct lpfc_iocbq *elsiocb;
4394 struct lpfc_nodelist *ndlp;
4395 uint16_t xri, status;
4396 uint32_t cmdsize;
4397
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004398 mb = &pmb->mb;
4399
4400 ndlp = (struct lpfc_nodelist *) pmb->context2;
4401 xri = (uint16_t) ((unsigned long)(pmb->context1));
Randy Dunlap041976f2006-06-25 01:58:51 -07004402 pmb->context1 = NULL;
4403 pmb->context2 = NULL;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004404
4405 if (mb->mbxStatus) {
James Smart329f9bc2007-04-25 09:53:01 -04004406 mempool_free(pmb, phba->mbox_mem_pool);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004407 return;
4408 }
4409
4410 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
James Smart329f9bc2007-04-25 09:53:01 -04004411 mempool_free(pmb, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05004412 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
4413 lpfc_max_els_tries, ndlp,
4414 ndlp->nlp_DID, ELS_CMD_ACC);
James Smartfa4066b2008-01-11 01:53:27 -05004415
4416 /* Decrement the ndlp reference count from previous mbox command */
James Smart329f9bc2007-04-25 09:53:01 -04004417 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05004418
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004419 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004420 return;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004421
4422 icmd = &elsiocb->iocb;
4423 icmd->ulpContext = xri;
4424
4425 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4426 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004427 pcmd += sizeof(uint32_t); /* Skip past command */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004428 rps_rsp = (RPS_RSP *)pcmd;
4429
4430 if (phba->fc_topology != TOPOLOGY_LOOP)
4431 status = 0x10;
4432 else
4433 status = 0x8;
James Smart2e0fef82007-06-17 19:56:36 -05004434 if (phba->pport->fc_flag & FC_FABRIC)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004435 status |= 0x4;
4436
4437 rps_rsp->rsvd1 = 0;
James Smart09372822008-01-11 01:52:54 -05004438 rps_rsp->portStatus = cpu_to_be16(status);
4439 rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
4440 rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
4441 rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
4442 rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
4443 rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
4444 rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004445 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004446 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
4447 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
4448 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
4449 elsiocb->iotag, elsiocb->iocb.ulpContext,
4450 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4451 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05004452 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004453 phba->fc_stat.elsXmitACC++;
James Smarted957682007-06-17 19:56:37 -05004454 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004455 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004456 return;
4457}
4458
James Smarte59058c2008-08-24 21:49:00 -04004459/**
4460 * lpfc_els_rcv_rps: Process an unsolicited rps iocb.
4461 * @vport: pointer to a host virtual N_Port data structure.
4462 * @cmdiocb: pointer to lpfc command iocb data structure.
4463 * @ndlp: pointer to a node-list data structure.
4464 *
4465 * This routine processes Read Port Status (RPS) IOCB received as an
4466 * ELS unsolicited event. It first checks the remote port state. If the
4467 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
4468 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
4469 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
4470 * for reading the HBA link statistics. It is for the callback function,
4471 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
4472 * to actually sending out RPS Accept (ACC) response.
4473 *
4474 * Return codes
4475 * 0 - Successfully processed rps iocb (currently always return 0)
4476 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004477static int
James Smart2e0fef82007-06-17 19:56:36 -05004478lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4479 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004480{
James Smart2e0fef82007-06-17 19:56:36 -05004481 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004482 uint32_t *lp;
4483 uint8_t flag;
4484 LPFC_MBOXQ_t *mbox;
4485 struct lpfc_dmabuf *pcmd;
4486 RPS *rps;
4487 struct ls_rjt stat;
4488
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004489 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
James Smart90160e02008-08-24 21:49:45 -04004490 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
4491 /* reject the unsolicited RPS request and done with it */
4492 goto reject_out;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004493
4494 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4495 lp = (uint32_t *) pcmd->virt;
4496 flag = (be32_to_cpu(*lp++) & 0xf);
4497 rps = (RPS *) lp;
4498
4499 if ((flag == 0) ||
4500 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
James Smart2e0fef82007-06-17 19:56:36 -05004501 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05004502 sizeof(struct lpfc_name)) == 0))) {
James Smart2e0fef82007-06-17 19:56:36 -05004503
James Smart92d7f7b2007-06-17 19:56:38 -05004504 printk("Fix me....\n");
4505 dump_stack();
James Smart2e0fef82007-06-17 19:56:36 -05004506 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
4507 if (mbox) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004508 lpfc_read_lnk_stat(phba, mbox);
4509 mbox->context1 =
James Smart92d7f7b2007-06-17 19:56:38 -05004510 (void *)((unsigned long) cmdiocb->iocb.ulpContext);
James Smart329f9bc2007-04-25 09:53:01 -04004511 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05004512 mbox->vport = vport;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004513 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
James Smartfa4066b2008-01-11 01:53:27 -05004514 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart0b727fe2007-10-27 13:37:25 -04004515 != MBX_NOT_FINISHED)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004516 /* Mbox completion will send ELS Response */
4517 return 0;
James Smartfa4066b2008-01-11 01:53:27 -05004518 /* Decrement reference count used for the failed mbox
4519 * command.
4520 */
James Smart329f9bc2007-04-25 09:53:01 -04004521 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004522 mempool_free(mbox, phba->mbox_mem_pool);
4523 }
4524 }
James Smart90160e02008-08-24 21:49:45 -04004525
4526reject_out:
4527 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004528 stat.un.b.lsRjtRsvd0 = 0;
4529 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4530 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4531 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004532 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004533 return 0;
4534}
4535
James Smarte59058c2008-08-24 21:49:00 -04004536/**
4537 * lpfc_els_rsp_rpl_acc: Issue an accept rpl els command.
4538 * @vport: pointer to a host virtual N_Port data structure.
4539 * @cmdsize: size of the ELS command.
4540 * @oldiocb: pointer to the original lpfc command iocb data structure.
4541 * @ndlp: pointer to a node-list data structure.
4542 *
4543 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
4544 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
4545 *
4546 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4547 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4548 * will be stored into the context1 field of the IOCB for the completion
4549 * callback function to the RPL Accept Response ELS command.
4550 *
4551 * Return code
4552 * 0 - Successfully issued ACC RPL ELS command
4553 * 1 - Failed to issue ACC RPL ELS command
4554 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05004555static int
James Smart2e0fef82007-06-17 19:56:36 -05004556lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
4557 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004558{
James Smart2e0fef82007-06-17 19:56:36 -05004559 struct lpfc_hba *phba = vport->phba;
4560 IOCB_t *icmd, *oldcmd;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004561 RPL_RSP rpl_rsp;
4562 struct lpfc_iocbq *elsiocb;
James Smart2e0fef82007-06-17 19:56:36 -05004563 struct lpfc_sli *psli = &phba->sli;
4564 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004565 uint8_t *pcmd;
4566
James Smart2e0fef82007-06-17 19:56:36 -05004567 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4568 ndlp->nlp_DID, ELS_CMD_ACC);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004569
James Smart488d1462006-03-07 15:02:37 -05004570 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004571 return 1;
James Smart488d1462006-03-07 15:02:37 -05004572
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004573 icmd = &elsiocb->iocb;
4574 oldcmd = &oldiocb->iocb;
4575 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
4576
4577 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4578 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004579 pcmd += sizeof(uint16_t);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004580 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
4581 pcmd += sizeof(uint16_t);
4582
4583 /* Setup the RPL ACC payload */
4584 rpl_rsp.listLen = be32_to_cpu(1);
4585 rpl_rsp.index = 0;
4586 rpl_rsp.port_num_blk.portNum = 0;
James Smart2e0fef82007-06-17 19:56:36 -05004587 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
4588 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004589 sizeof(struct lpfc_name));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004590 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004591 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004592 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4593 "0120 Xmit ELS RPL ACC response tag x%x "
4594 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
4595 "rpi x%x\n",
4596 elsiocb->iotag, elsiocb->iocb.ulpContext,
4597 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4598 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05004599 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004600 phba->fc_stat.elsXmitACC++;
4601 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
4602 lpfc_els_free_iocb(phba, elsiocb);
4603 return 1;
4604 }
4605 return 0;
4606}
4607
James Smarte59058c2008-08-24 21:49:00 -04004608/**
4609 * lpfc_els_rcv_rpl: Process an unsolicited rpl iocb.
4610 * @vport: pointer to a host virtual N_Port data structure.
4611 * @cmdiocb: pointer to lpfc command iocb data structure.
4612 * @ndlp: pointer to a node-list data structure.
4613 *
4614 * This routine processes Read Port List (RPL) IOCB received as an ELS
4615 * unsolicited event. It first checks the remote port state. If the remote
4616 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
4617 * invokes the lpfc_els_rsp_reject() routine to send reject response.
4618 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
4619 * to accept the RPL.
4620 *
4621 * Return code
4622 * 0 - Successfully processed rpl iocb (currently always return 0)
4623 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004624static int
James Smart2e0fef82007-06-17 19:56:36 -05004625lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4626 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004627{
4628 struct lpfc_dmabuf *pcmd;
4629 uint32_t *lp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004630 uint32_t maxsize;
4631 uint16_t cmdsize;
4632 RPL *rpl;
4633 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05004634
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004635 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
4636 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
James Smart90160e02008-08-24 21:49:45 -04004637 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004638 stat.un.b.lsRjtRsvd0 = 0;
4639 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4640 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4641 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004642 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4643 NULL);
James Smart90160e02008-08-24 21:49:45 -04004644 /* rejected the unsolicited RPL request and done with it */
4645 return 0;
dea31012005-04-17 16:05:31 -05004646 }
4647
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004648 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4649 lp = (uint32_t *) pcmd->virt;
4650 rpl = (RPL *) (lp + 1);
4651
4652 maxsize = be32_to_cpu(rpl->maxsize);
4653
4654 /* We support only one port */
4655 if ((rpl->index == 0) &&
4656 ((maxsize == 0) ||
4657 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
4658 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004659 } else {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004660 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
4661 }
James Smart2e0fef82007-06-17 19:56:36 -05004662 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05004663
4664 return 0;
4665}
4666
James Smarte59058c2008-08-24 21:49:00 -04004667/**
4668 * lpfc_els_rcv_farp: Process an unsolicited farp request els command.
4669 * @vport: pointer to a virtual N_Port data structure.
4670 * @cmdiocb: pointer to lpfc command iocb data structure.
4671 * @ndlp: pointer to a node-list data structure.
4672 *
4673 * This routine processes Fibre Channel Address Resolution Protocol
4674 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
4675 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
4676 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
4677 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
4678 * remote PortName is compared against the FC PortName stored in the @vport
4679 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
4680 * compared against the FC NodeName stored in the @vport data structure.
4681 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
4682 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
4683 * invoked to send out FARP Response to the remote node. Before sending the
4684 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
4685 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
4686 * routine is invoked to log into the remote port first.
4687 *
4688 * Return code
4689 * 0 - Either the FARP Match Mode not supported or successfully processed
4690 **/
dea31012005-04-17 16:05:31 -05004691static int
James Smart2e0fef82007-06-17 19:56:36 -05004692lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4693 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004694{
4695 struct lpfc_dmabuf *pcmd;
4696 uint32_t *lp;
4697 IOCB_t *icmd;
4698 FARP *fp;
4699 uint32_t cmd, cnt, did;
4700
4701 icmd = &cmdiocb->iocb;
4702 did = icmd->un.elsreq64.remoteID;
4703 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4704 lp = (uint32_t *) pcmd->virt;
4705
4706 cmd = *lp++;
4707 fp = (FARP *) lp;
dea31012005-04-17 16:05:31 -05004708 /* FARP-REQ received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04004709 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4710 "0601 FARP-REQ received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05004711 /* We will only support match on WWPN or WWNN */
4712 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004713 return 0;
dea31012005-04-17 16:05:31 -05004714 }
4715
4716 cnt = 0;
4717 /* If this FARP command is searching for my portname */
4718 if (fp->Mflags & FARP_MATCH_PORT) {
James Smart2e0fef82007-06-17 19:56:36 -05004719 if (memcmp(&fp->RportName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05004720 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05004721 cnt = 1;
4722 }
4723
4724 /* If this FARP command is searching for my nodename */
4725 if (fp->Mflags & FARP_MATCH_NODE) {
James Smart2e0fef82007-06-17 19:56:36 -05004726 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05004727 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05004728 cnt = 1;
4729 }
4730
4731 if (cnt) {
4732 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
4733 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
4734 /* Log back into the node before sending the FARP. */
4735 if (fp->Rflags & FARP_REQUEST_PLOGI) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004736 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004737 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04004738 NLP_STE_PLOGI_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05004739 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05004740 }
4741
4742 /* Send a FARP response to that node */
James Smart2e0fef82007-06-17 19:56:36 -05004743 if (fp->Rflags & FARP_REQUEST_FARPR)
4744 lpfc_issue_els_farpr(vport, did, 0);
dea31012005-04-17 16:05:31 -05004745 }
4746 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004747 return 0;
dea31012005-04-17 16:05:31 -05004748}
4749
James Smarte59058c2008-08-24 21:49:00 -04004750/**
4751 * lpfc_els_rcv_farpr: Process an unsolicited farp response iocb.
4752 * @vport: pointer to a host virtual N_Port data structure.
4753 * @cmdiocb: pointer to lpfc command iocb data structure.
4754 * @ndlp: pointer to a node-list data structure.
4755 *
4756 * This routine processes Fibre Channel Address Resolution Protocol
4757 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
4758 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
4759 * the FARP response request.
4760 *
4761 * Return code
4762 * 0 - Successfully processed FARPR IOCB (currently always return 0)
4763 **/
dea31012005-04-17 16:05:31 -05004764static int
James Smart2e0fef82007-06-17 19:56:36 -05004765lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4766 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004767{
4768 struct lpfc_dmabuf *pcmd;
4769 uint32_t *lp;
4770 IOCB_t *icmd;
4771 uint32_t cmd, did;
4772
4773 icmd = &cmdiocb->iocb;
4774 did = icmd->un.elsreq64.remoteID;
4775 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4776 lp = (uint32_t *) pcmd->virt;
4777
4778 cmd = *lp++;
4779 /* FARP-RSP received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04004780 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4781 "0600 FARP-RSP received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05004782 /* ACCEPT the Farp resp request */
James Smart51ef4c22007-08-02 11:10:31 -04004783 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004784
4785 return 0;
4786}
4787
James Smarte59058c2008-08-24 21:49:00 -04004788/**
4789 * lpfc_els_rcv_fan: Process an unsolicited fan iocb command.
4790 * @vport: pointer to a host virtual N_Port data structure.
4791 * @cmdiocb: pointer to lpfc command iocb data structure.
4792 * @fan_ndlp: pointer to a node-list data structure.
4793 *
4794 * This routine processes a Fabric Address Notification (FAN) IOCB
4795 * command received as an ELS unsolicited event. The FAN ELS command will
4796 * only be processed on a physical port (i.e., the @vport represents the
4797 * physical port). The fabric NodeName and PortName from the FAN IOCB are
4798 * compared against those in the phba data structure. If any of those is
4799 * different, the lpfc_initial_flogi() routine is invoked to initialize
4800 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
4801 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
4802 * is invoked to register login to the fabric.
4803 *
4804 * Return code
4805 * 0 - Successfully processed fan iocb (currently always return 0).
4806 **/
dea31012005-04-17 16:05:31 -05004807static int
James Smart2e0fef82007-06-17 19:56:36 -05004808lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4809 struct lpfc_nodelist *fan_ndlp)
dea31012005-04-17 16:05:31 -05004810{
James Smart2e0fef82007-06-17 19:56:36 -05004811 struct lpfc_hba *phba = vport->phba;
James Smart0d2b6b82008-06-14 22:52:47 -04004812 uint32_t *lp;
4813 FAN *fp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004814
James Smart0d2b6b82008-06-14 22:52:47 -04004815 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
4816 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
4817 fp = (FAN *) ++lp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004818 /* FAN received; Fan does not have a reply sequence */
James Smart0d2b6b82008-06-14 22:52:47 -04004819 if ((vport == phba->pport) &&
4820 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004821 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
James Smart0d2b6b82008-06-14 22:52:47 -04004822 sizeof(struct lpfc_name))) ||
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004823 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
James Smart0d2b6b82008-06-14 22:52:47 -04004824 sizeof(struct lpfc_name)))) {
4825 /* This port has switched fabrics. FLOGI is required */
James Smart2e0fef82007-06-17 19:56:36 -05004826 lpfc_initial_flogi(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04004827 } else {
4828 /* FAN verified - skip FLOGI */
4829 vport->fc_myDID = vport->fc_prevDID;
4830 lpfc_issue_fabric_reglogin(vport);
dea31012005-04-17 16:05:31 -05004831 }
dea31012005-04-17 16:05:31 -05004832 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004833 return 0;
dea31012005-04-17 16:05:31 -05004834}
4835
James Smarte59058c2008-08-24 21:49:00 -04004836/**
4837 * lpfc_els_timeout: Handler funciton to the els timer.
4838 * @ptr: holder for the timer function associated data.
4839 *
4840 * This routine is invoked by the ELS timer after timeout. It posts the ELS
4841 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
4842 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
4843 * up the worker thread. It is for the worker thread to invoke the routine
4844 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
4845 **/
dea31012005-04-17 16:05:31 -05004846void
4847lpfc_els_timeout(unsigned long ptr)
4848{
James Smart2e0fef82007-06-17 19:56:36 -05004849 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
4850 struct lpfc_hba *phba = vport->phba;
James Smart5e9d9b82008-06-14 22:52:53 -04004851 uint32_t tmo_posted;
dea31012005-04-17 16:05:31 -05004852 unsigned long iflag;
4853
James Smart2e0fef82007-06-17 19:56:36 -05004854 spin_lock_irqsave(&vport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -04004855 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
4856 if (!tmo_posted)
James Smart2e0fef82007-06-17 19:56:36 -05004857 vport->work_port_events |= WORKER_ELS_TMO;
James Smart5e9d9b82008-06-14 22:52:53 -04004858 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
James Smart92d7f7b2007-06-17 19:56:38 -05004859
James Smart5e9d9b82008-06-14 22:52:53 -04004860 if (!tmo_posted)
4861 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05004862 return;
4863}
4864
James Smarte59058c2008-08-24 21:49:00 -04004865/**
4866 * lpfc_els_timeout_handler: Process an els timeout event.
4867 * @vport: pointer to a virtual N_Port data structure.
4868 *
4869 * This routine is the actual handler function that processes an ELS timeout
4870 * event. It walks the ELS ring to get and abort all the IOCBs (except the
4871 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
4872 * invoking the lpfc_sli_issue_abort_iotag() routine.
4873 **/
dea31012005-04-17 16:05:31 -05004874void
James Smart2e0fef82007-06-17 19:56:36 -05004875lpfc_els_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004876{
James Smart2e0fef82007-06-17 19:56:36 -05004877 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004878 struct lpfc_sli_ring *pring;
4879 struct lpfc_iocbq *tmp_iocb, *piocb;
4880 IOCB_t *cmd = NULL;
4881 struct lpfc_dmabuf *pcmd;
James Smart2e0fef82007-06-17 19:56:36 -05004882 uint32_t els_command = 0;
dea31012005-04-17 16:05:31 -05004883 uint32_t timeout;
James Smart2e0fef82007-06-17 19:56:36 -05004884 uint32_t remote_ID = 0xffffffff;
dea31012005-04-17 16:05:31 -05004885
dea31012005-04-17 16:05:31 -05004886 /* If the timer is already canceled do nothing */
James Smart2e0fef82007-06-17 19:56:36 -05004887 if ((vport->work_port_events & WORKER_ELS_TMO) == 0) {
dea31012005-04-17 16:05:31 -05004888 return;
4889 }
James Smart2e0fef82007-06-17 19:56:36 -05004890 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004891 timeout = (uint32_t)(phba->fc_ratov << 1);
4892
4893 pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05004894
4895 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
4896 cmd = &piocb->iocb;
4897
James Smart2e0fef82007-06-17 19:56:36 -05004898 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
4899 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
4900 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
dea31012005-04-17 16:05:31 -05004901 continue;
James Smart2e0fef82007-06-17 19:56:36 -05004902
4903 if (piocb->vport != vport)
4904 continue;
4905
dea31012005-04-17 16:05:31 -05004906 pcmd = (struct lpfc_dmabuf *) piocb->context2;
James Smart2e0fef82007-06-17 19:56:36 -05004907 if (pcmd)
4908 els_command = *(uint32_t *) (pcmd->virt);
dea31012005-04-17 16:05:31 -05004909
James Smart92d7f7b2007-06-17 19:56:38 -05004910 if (els_command == ELS_CMD_FARP ||
4911 els_command == ELS_CMD_FARPR ||
4912 els_command == ELS_CMD_FDISC)
dea31012005-04-17 16:05:31 -05004913 continue;
James Smart92d7f7b2007-06-17 19:56:38 -05004914
dea31012005-04-17 16:05:31 -05004915 if (piocb->drvrTimeout > 0) {
James Smart92d7f7b2007-06-17 19:56:38 -05004916 if (piocb->drvrTimeout >= timeout)
dea31012005-04-17 16:05:31 -05004917 piocb->drvrTimeout -= timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05004918 else
dea31012005-04-17 16:05:31 -05004919 piocb->drvrTimeout = 0;
dea31012005-04-17 16:05:31 -05004920 continue;
4921 }
4922
James Smart2e0fef82007-06-17 19:56:36 -05004923 remote_ID = 0xffffffff;
4924 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
dea31012005-04-17 16:05:31 -05004925 remote_ID = cmd->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05004926 else {
4927 struct lpfc_nodelist *ndlp;
4928 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
James Smart58da1ff2008-04-07 10:15:56 -04004929 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart2e0fef82007-06-17 19:56:36 -05004930 remote_ID = ndlp->nlp_DID;
dea31012005-04-17 16:05:31 -05004931 }
James Smarte8b62012007-08-02 11:10:09 -04004932 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4933 "0127 ELS timeout Data: x%x x%x x%x "
4934 "x%x\n", els_command,
4935 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
James Smart07951072007-04-25 09:51:38 -04004936 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05004937 }
James Smart2e0fef82007-06-17 19:56:36 -05004938 spin_unlock_irq(&phba->hbalock);
James Smart5a0e3262006-07-06 15:49:16 -04004939
James Smart2e0fef82007-06-17 19:56:36 -05004940 if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt)
4941 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
dea31012005-04-17 16:05:31 -05004942}
4943
James Smarte59058c2008-08-24 21:49:00 -04004944/**
4945 * lpfc_els_flush_cmd: Clean up the outstanding els commands to a vport.
4946 * @vport: pointer to a host virtual N_Port data structure.
4947 *
4948 * This routine is used to clean up all the outstanding ELS commands on a
4949 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
4950 * routine. After that, it walks the ELS transmit queue to remove all the
4951 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
4952 * the IOCBs with a non-NULL completion callback function, the callback
4953 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
4954 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
4955 * callback function, the IOCB will simply be released. Finally, it walks
4956 * the ELS transmit completion queue to issue an abort IOCB to any transmit
4957 * completion queue IOCB that is associated with the @vport and is not
4958 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
4959 * part of the discovery state machine) out to HBA by invoking the
4960 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
4961 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
4962 * the IOCBs are aborted when this function returns.
4963 **/
dea31012005-04-17 16:05:31 -05004964void
James Smart2e0fef82007-06-17 19:56:36 -05004965lpfc_els_flush_cmd(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004966{
James Smart2534ba72007-04-25 09:52:20 -04004967 LIST_HEAD(completions);
James Smart2e0fef82007-06-17 19:56:36 -05004968 struct lpfc_hba *phba = vport->phba;
James Smart329f9bc2007-04-25 09:53:01 -04004969 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05004970 struct lpfc_iocbq *tmp_iocb, *piocb;
4971 IOCB_t *cmd = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05004972
4973 lpfc_fabric_abort_vport(vport);
dea31012005-04-17 16:05:31 -05004974
James Smart2e0fef82007-06-17 19:56:36 -05004975 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004976 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
4977 cmd = &piocb->iocb;
4978
4979 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
4980 continue;
4981 }
4982
4983 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
James Smart329f9bc2007-04-25 09:53:01 -04004984 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
4985 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
4986 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
4987 cmd->ulpCommand == CMD_ABORT_XRI_CN)
dea31012005-04-17 16:05:31 -05004988 continue;
dea31012005-04-17 16:05:31 -05004989
James Smart2e0fef82007-06-17 19:56:36 -05004990 if (piocb->vport != vport)
4991 continue;
4992
James Smart2534ba72007-04-25 09:52:20 -04004993 list_move_tail(&piocb->list, &completions);
James Smart1dcb58e2007-04-25 09:51:30 -04004994 pring->txq_cnt--;
dea31012005-04-17 16:05:31 -05004995 }
4996
4997 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
dea31012005-04-17 16:05:31 -05004998 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
4999 continue;
5000 }
dea31012005-04-17 16:05:31 -05005001
James Smart2e0fef82007-06-17 19:56:36 -05005002 if (piocb->vport != vport)
5003 continue;
5004
James Smart07951072007-04-25 09:51:38 -04005005 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05005006 }
James Smart2e0fef82007-06-17 19:56:36 -05005007 spin_unlock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04005008
James Smart2e0fef82007-06-17 19:56:36 -05005009 while (!list_empty(&completions)) {
James Smart2534ba72007-04-25 09:52:20 -04005010 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
5011 cmd = &piocb->iocb;
James Smart92d7f7b2007-06-17 19:56:38 -05005012 list_del_init(&piocb->list);
James Smart2534ba72007-04-25 09:52:20 -04005013
James Smart2e0fef82007-06-17 19:56:36 -05005014 if (!piocb->iocb_cmpl)
5015 lpfc_sli_release_iocbq(phba, piocb);
5016 else {
James Smart2534ba72007-04-25 09:52:20 -04005017 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
5018 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
5019 (piocb->iocb_cmpl) (phba, piocb, piocb);
James Smart2e0fef82007-06-17 19:56:36 -05005020 }
James Smart2534ba72007-04-25 09:52:20 -04005021 }
5022
dea31012005-04-17 16:05:31 -05005023 return;
5024}
5025
James Smarte59058c2008-08-24 21:49:00 -04005026/**
5027 * lpfc_els_flush_all_cmd: Clean up all the outstanding els commands to a HBA.
5028 * @phba: pointer to lpfc hba data structure.
5029 *
5030 * This routine is used to clean up all the outstanding ELS commands on a
5031 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
5032 * routine. After that, it walks the ELS transmit queue to remove all the
5033 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
5034 * the IOCBs with the completion callback function associated, the callback
5035 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
5036 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
5037 * callback function associated, the IOCB will simply be released. Finally,
5038 * it walks the ELS transmit completion queue to issue an abort IOCB to any
5039 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
5040 * management plane IOCBs that are not part of the discovery state machine)
5041 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
5042 **/
James Smart549e55c2007-08-02 11:09:51 -04005043void
5044lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
5045{
5046 LIST_HEAD(completions);
5047 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
5048 struct lpfc_iocbq *tmp_iocb, *piocb;
5049 IOCB_t *cmd = NULL;
5050
5051 lpfc_fabric_abort_hba(phba);
5052 spin_lock_irq(&phba->hbalock);
5053 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
5054 cmd = &piocb->iocb;
5055 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
5056 continue;
5057 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
5058 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
5059 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
5060 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
5061 cmd->ulpCommand == CMD_ABORT_XRI_CN)
5062 continue;
5063 list_move_tail(&piocb->list, &completions);
5064 pring->txq_cnt--;
5065 }
5066 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
5067 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
5068 continue;
5069 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
5070 }
5071 spin_unlock_irq(&phba->hbalock);
5072 while (!list_empty(&completions)) {
5073 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
5074 cmd = &piocb->iocb;
5075 list_del_init(&piocb->list);
5076 if (!piocb->iocb_cmpl)
5077 lpfc_sli_release_iocbq(phba, piocb);
5078 else {
5079 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
5080 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
5081 (piocb->iocb_cmpl) (phba, piocb, piocb);
5082 }
5083 }
5084 return;
5085}
5086
James Smarte59058c2008-08-24 21:49:00 -04005087/**
5088 * lpfc_els_unsol_buffer: Process an unsolicited event data buffer.
5089 * @phba: pointer to lpfc hba data structure.
5090 * @pring: pointer to a SLI ring.
5091 * @vport: pointer to a host virtual N_Port data structure.
5092 * @elsiocb: pointer to lpfc els command iocb data structure.
5093 *
5094 * This routine is used for processing the IOCB associated with a unsolicited
5095 * event. It first determines whether there is an existing ndlp that matches
5096 * the DID from the unsolicited IOCB. If not, it will create a new one with
5097 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
5098 * IOCB is then used to invoke the proper routine and to set up proper state
5099 * of the discovery state machine.
5100 **/
James Smarted957682007-06-17 19:56:37 -05005101static void
5102lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
James Smart92d7f7b2007-06-17 19:56:38 -05005103 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05005104{
James Smart87af33f2007-10-27 13:37:43 -04005105 struct Scsi_Host *shost;
dea31012005-04-17 16:05:31 -05005106 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05005107 struct ls_rjt stat;
James Smart92d7f7b2007-06-17 19:56:38 -05005108 uint32_t *payload;
James Smart2e0fef82007-06-17 19:56:36 -05005109 uint32_t cmd, did, newnode, rjt_err = 0;
James Smarted957682007-06-17 19:56:37 -05005110 IOCB_t *icmd = &elsiocb->iocb;
dea31012005-04-17 16:05:31 -05005111
James Smarte47c9092008-02-08 18:49:26 -05005112 if (!vport || !(elsiocb->context2))
dea31012005-04-17 16:05:31 -05005113 goto dropit;
James Smart2e0fef82007-06-17 19:56:36 -05005114
dea31012005-04-17 16:05:31 -05005115 newnode = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05005116 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
5117 cmd = *payload;
James Smarted957682007-06-17 19:56:37 -05005118 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
James Smart495a7142008-06-14 22:52:59 -04005119 lpfc_post_buffer(phba, pring, 1);
dea31012005-04-17 16:05:31 -05005120
James Smart858c9f62007-06-17 19:56:39 -05005121 did = icmd->un.rcvels.remoteID;
5122 if (icmd->ulpStatus) {
5123 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5124 "RCV Unsol ELS: status:x%x/x%x did:x%x",
5125 icmd->ulpStatus, icmd->un.ulpWord[4], did);
dea31012005-04-17 16:05:31 -05005126 goto dropit;
James Smart858c9f62007-06-17 19:56:39 -05005127 }
dea31012005-04-17 16:05:31 -05005128
5129 /* Check to see if link went down during discovery */
James Smarted957682007-06-17 19:56:37 -05005130 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05005131 goto dropit;
dea31012005-04-17 16:05:31 -05005132
James Smart92d7f7b2007-06-17 19:56:38 -05005133 /* Ignore traffic recevied during vport shutdown. */
5134 if (vport->load_flag & FC_UNLOADING)
5135 goto dropit;
5136
James Smart2e0fef82007-06-17 19:56:36 -05005137 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005138 if (!ndlp) {
dea31012005-04-17 16:05:31 -05005139 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005140 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
James Smarted957682007-06-17 19:56:37 -05005141 if (!ndlp)
dea31012005-04-17 16:05:31 -05005142 goto dropit;
dea31012005-04-17 16:05:31 -05005143
James Smart2e0fef82007-06-17 19:56:36 -05005144 lpfc_nlp_init(vport, ndlp, did);
James Smart98c9ea52007-10-27 13:37:33 -04005145 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05005146 newnode = 1;
James Smarte47c9092008-02-08 18:49:26 -05005147 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
dea31012005-04-17 16:05:31 -05005148 ndlp->nlp_type |= NLP_FABRIC;
James Smart58da1ff2008-04-07 10:15:56 -04005149 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
5150 ndlp = lpfc_enable_node(vport, ndlp,
5151 NLP_STE_UNUSED_NODE);
5152 if (!ndlp)
5153 goto dropit;
5154 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5155 newnode = 1;
5156 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
5157 ndlp->nlp_type |= NLP_FABRIC;
5158 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
5159 /* This is similar to the new node path */
5160 ndlp = lpfc_nlp_get(ndlp);
5161 if (!ndlp)
5162 goto dropit;
5163 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5164 newnode = 1;
James Smart87af33f2007-10-27 13:37:43 -04005165 }
dea31012005-04-17 16:05:31 -05005166
5167 phba->fc_stat.elsRcvFrame++;
James Smart329f9bc2007-04-25 09:53:01 -04005168 if (elsiocb->context1)
5169 lpfc_nlp_put(elsiocb->context1);
James Smarte47c9092008-02-08 18:49:26 -05005170
James Smart329f9bc2007-04-25 09:53:01 -04005171 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05005172 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -05005173
5174 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
5175 cmd &= ELS_CMD_MASK;
5176 }
5177 /* ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04005178 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5179 "0112 ELS command x%x received from NPORT x%x "
5180 "Data: x%x\n", cmd, did, vport->port_state);
dea31012005-04-17 16:05:31 -05005181 switch (cmd) {
5182 case ELS_CMD_PLOGI:
James Smart858c9f62007-06-17 19:56:39 -05005183 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5184 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
5185 did, vport->port_state, ndlp->nlp_flag);
5186
dea31012005-04-17 16:05:31 -05005187 phba->fc_stat.elsRcvPLOGI++;
James Smart858c9f62007-06-17 19:56:39 -05005188 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
5189
5190 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart1b32f6a2008-02-08 18:49:39 -05005191 if (!(phba->pport->fc_flag & FC_PT2PT) ||
5192 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
5193 rjt_err = LSRJT_UNABLE_TPC;
5194 break;
5195 }
5196 /* We get here, and drop thru, if we are PT2PT with
5197 * another NPort and the other side has initiated
5198 * the PLOGI before responding to our FLOGI.
5199 */
dea31012005-04-17 16:05:31 -05005200 }
James Smart87af33f2007-10-27 13:37:43 -04005201
5202 shost = lpfc_shost_from_vport(vport);
5203 spin_lock_irq(shost->host_lock);
5204 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
5205 spin_unlock_irq(shost->host_lock);
5206
James Smart2e0fef82007-06-17 19:56:36 -05005207 lpfc_disc_state_machine(vport, ndlp, elsiocb,
5208 NLP_EVT_RCV_PLOGI);
James Smart858c9f62007-06-17 19:56:39 -05005209
dea31012005-04-17 16:05:31 -05005210 break;
5211 case ELS_CMD_FLOGI:
James Smart858c9f62007-06-17 19:56:39 -05005212 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5213 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
5214 did, vport->port_state, ndlp->nlp_flag);
5215
dea31012005-04-17 16:05:31 -05005216 phba->fc_stat.elsRcvFLOGI++;
James Smart51ef4c22007-08-02 11:10:31 -04005217 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005218 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005219 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05005220 break;
5221 case ELS_CMD_LOGO:
James Smart858c9f62007-06-17 19:56:39 -05005222 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5223 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
5224 did, vport->port_state, ndlp->nlp_flag);
5225
dea31012005-04-17 16:05:31 -05005226 phba->fc_stat.elsRcvLOGO++;
James Smart2e0fef82007-06-17 19:56:36 -05005227 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005228 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005229 break;
5230 }
James Smart2e0fef82007-06-17 19:56:36 -05005231 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
dea31012005-04-17 16:05:31 -05005232 break;
5233 case ELS_CMD_PRLO:
James Smart858c9f62007-06-17 19:56:39 -05005234 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5235 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
5236 did, vport->port_state, ndlp->nlp_flag);
5237
dea31012005-04-17 16:05:31 -05005238 phba->fc_stat.elsRcvPRLO++;
James Smart2e0fef82007-06-17 19:56:36 -05005239 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005240 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005241 break;
5242 }
James Smart2e0fef82007-06-17 19:56:36 -05005243 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
dea31012005-04-17 16:05:31 -05005244 break;
5245 case ELS_CMD_RSCN:
5246 phba->fc_stat.elsRcvRSCN++;
James Smart51ef4c22007-08-02 11:10:31 -04005247 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005248 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005249 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05005250 break;
5251 case ELS_CMD_ADISC:
James Smart858c9f62007-06-17 19:56:39 -05005252 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5253 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
5254 did, vport->port_state, ndlp->nlp_flag);
5255
dea31012005-04-17 16:05:31 -05005256 phba->fc_stat.elsRcvADISC++;
James Smart2e0fef82007-06-17 19:56:36 -05005257 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005258 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005259 break;
5260 }
James Smart2e0fef82007-06-17 19:56:36 -05005261 lpfc_disc_state_machine(vport, ndlp, elsiocb,
5262 NLP_EVT_RCV_ADISC);
dea31012005-04-17 16:05:31 -05005263 break;
5264 case ELS_CMD_PDISC:
James Smart858c9f62007-06-17 19:56:39 -05005265 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5266 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
5267 did, vport->port_state, ndlp->nlp_flag);
5268
dea31012005-04-17 16:05:31 -05005269 phba->fc_stat.elsRcvPDISC++;
James Smart2e0fef82007-06-17 19:56:36 -05005270 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005271 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005272 break;
5273 }
James Smart2e0fef82007-06-17 19:56:36 -05005274 lpfc_disc_state_machine(vport, ndlp, elsiocb,
5275 NLP_EVT_RCV_PDISC);
dea31012005-04-17 16:05:31 -05005276 break;
5277 case ELS_CMD_FARPR:
James Smart858c9f62007-06-17 19:56:39 -05005278 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5279 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
5280 did, vport->port_state, ndlp->nlp_flag);
5281
dea31012005-04-17 16:05:31 -05005282 phba->fc_stat.elsRcvFARPR++;
James Smart2e0fef82007-06-17 19:56:36 -05005283 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05005284 break;
5285 case ELS_CMD_FARP:
James Smart858c9f62007-06-17 19:56:39 -05005286 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5287 "RCV FARP: did:x%x/ste:x%x flg:x%x",
5288 did, vport->port_state, ndlp->nlp_flag);
5289
dea31012005-04-17 16:05:31 -05005290 phba->fc_stat.elsRcvFARP++;
James Smart2e0fef82007-06-17 19:56:36 -05005291 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05005292 break;
5293 case ELS_CMD_FAN:
James Smart858c9f62007-06-17 19:56:39 -05005294 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5295 "RCV FAN: did:x%x/ste:x%x flg:x%x",
5296 did, vport->port_state, ndlp->nlp_flag);
5297
dea31012005-04-17 16:05:31 -05005298 phba->fc_stat.elsRcvFAN++;
James Smart2e0fef82007-06-17 19:56:36 -05005299 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05005300 break;
dea31012005-04-17 16:05:31 -05005301 case ELS_CMD_PRLI:
James Smart858c9f62007-06-17 19:56:39 -05005302 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5303 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
5304 did, vport->port_state, ndlp->nlp_flag);
5305
dea31012005-04-17 16:05:31 -05005306 phba->fc_stat.elsRcvPRLI++;
James Smart2e0fef82007-06-17 19:56:36 -05005307 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005308 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005309 break;
5310 }
James Smart2e0fef82007-06-17 19:56:36 -05005311 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
dea31012005-04-17 16:05:31 -05005312 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005313 case ELS_CMD_LIRR:
James Smart858c9f62007-06-17 19:56:39 -05005314 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5315 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
5316 did, vport->port_state, ndlp->nlp_flag);
5317
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005318 phba->fc_stat.elsRcvLIRR++;
James Smart2e0fef82007-06-17 19:56:36 -05005319 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005320 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005321 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005322 break;
5323 case ELS_CMD_RPS:
James Smart858c9f62007-06-17 19:56:39 -05005324 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5325 "RCV RPS: did:x%x/ste:x%x flg:x%x",
5326 did, vport->port_state, ndlp->nlp_flag);
5327
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005328 phba->fc_stat.elsRcvRPS++;
James Smart2e0fef82007-06-17 19:56:36 -05005329 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005330 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005331 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005332 break;
5333 case ELS_CMD_RPL:
James Smart858c9f62007-06-17 19:56:39 -05005334 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5335 "RCV RPL: did:x%x/ste:x%x flg:x%x",
5336 did, vport->port_state, ndlp->nlp_flag);
5337
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005338 phba->fc_stat.elsRcvRPL++;
James Smart2e0fef82007-06-17 19:56:36 -05005339 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005340 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005341 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005342 break;
dea31012005-04-17 16:05:31 -05005343 case ELS_CMD_RNID:
James Smart858c9f62007-06-17 19:56:39 -05005344 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5345 "RCV RNID: did:x%x/ste:x%x flg:x%x",
5346 did, vport->port_state, ndlp->nlp_flag);
5347
dea31012005-04-17 16:05:31 -05005348 phba->fc_stat.elsRcvRNID++;
James Smart2e0fef82007-06-17 19:56:36 -05005349 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005350 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005351 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05005352 break;
5353 default:
James Smart858c9f62007-06-17 19:56:39 -05005354 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5355 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
5356 cmd, did, vport->port_state);
5357
dea31012005-04-17 16:05:31 -05005358 /* Unsupported ELS command, reject */
James Smart858c9f62007-06-17 19:56:39 -05005359 rjt_err = LSRJT_INVALID_CMD;
dea31012005-04-17 16:05:31 -05005360
5361 /* Unknown ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04005362 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5363 "0115 Unknown ELS command x%x "
5364 "received from NPORT x%x\n", cmd, did);
James Smart87af33f2007-10-27 13:37:43 -04005365 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005366 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05005367 break;
5368 }
5369
5370 /* check if need to LS_RJT received ELS cmd */
5371 if (rjt_err) {
James Smart92d7f7b2007-06-17 19:56:38 -05005372 memset(&stat, 0, sizeof(stat));
James Smart858c9f62007-06-17 19:56:39 -05005373 stat.un.b.lsRjtRsnCode = rjt_err;
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04005374 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart858c9f62007-06-17 19:56:39 -05005375 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
5376 NULL);
dea31012005-04-17 16:05:31 -05005377 }
5378
James Smarted957682007-06-17 19:56:37 -05005379 return;
5380
5381dropit:
James Smart98c9ea52007-10-27 13:37:33 -04005382 if (vport && !(vport->load_flag & FC_UNLOADING))
5383 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
James Smarte8b62012007-08-02 11:10:09 -04005384 "(%d):0111 Dropping received ELS cmd "
James Smarted957682007-06-17 19:56:37 -05005385 "Data: x%x x%x x%x\n",
James Smart98c9ea52007-10-27 13:37:33 -04005386 vport->vpi, icmd->ulpStatus,
James Smarte8b62012007-08-02 11:10:09 -04005387 icmd->un.ulpWord[4], icmd->ulpTimeout);
James Smarted957682007-06-17 19:56:37 -05005388 phba->fc_stat.elsRcvDrop++;
5389}
5390
James Smarte59058c2008-08-24 21:49:00 -04005391/**
5392 * lpfc_find_vport_by_vpid: Find a vport on a HBA through vport identifier.
5393 * @phba: pointer to lpfc hba data structure.
5394 * @vpi: host virtual N_Port identifier.
5395 *
5396 * This routine finds a vport on a HBA (referred by @phba) through a
5397 * @vpi. The function walks the HBA's vport list and returns the address
5398 * of the vport with the matching @vpi.
5399 *
5400 * Return code
5401 * NULL - No vport with the matching @vpi found
5402 * Otherwise - Address to the vport with the matching @vpi.
5403 **/
James Smart92d7f7b2007-06-17 19:56:38 -05005404static struct lpfc_vport *
5405lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
5406{
5407 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -04005408 unsigned long flags;
James Smart92d7f7b2007-06-17 19:56:38 -05005409
James Smart549e55c2007-08-02 11:09:51 -04005410 spin_lock_irqsave(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05005411 list_for_each_entry(vport, &phba->port_list, listentry) {
James Smart549e55c2007-08-02 11:09:51 -04005412 if (vport->vpi == vpi) {
5413 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05005414 return vport;
James Smart549e55c2007-08-02 11:09:51 -04005415 }
James Smart92d7f7b2007-06-17 19:56:38 -05005416 }
James Smart549e55c2007-08-02 11:09:51 -04005417 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05005418 return NULL;
5419}
James Smarted957682007-06-17 19:56:37 -05005420
James Smarte59058c2008-08-24 21:49:00 -04005421/**
5422 * lpfc_els_unsol_event: Process an unsolicited event from an els sli ring.
5423 * @phba: pointer to lpfc hba data structure.
5424 * @pring: pointer to a SLI ring.
5425 * @elsiocb: pointer to lpfc els iocb data structure.
5426 *
5427 * This routine is used to process an unsolicited event received from a SLI
5428 * (Service Level Interface) ring. The actual processing of the data buffer
5429 * associated with the unsolicited event is done by invoking the routine
5430 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
5431 * SLI ring on which the unsolicited event was received.
5432 **/
James Smarted957682007-06-17 19:56:37 -05005433void
5434lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
5435 struct lpfc_iocbq *elsiocb)
5436{
5437 struct lpfc_vport *vport = phba->pport;
James Smarted957682007-06-17 19:56:37 -05005438 IOCB_t *icmd = &elsiocb->iocb;
James Smarted957682007-06-17 19:56:37 -05005439 dma_addr_t paddr;
James Smart92d7f7b2007-06-17 19:56:38 -05005440 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
5441 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
James Smarted957682007-06-17 19:56:37 -05005442
James Smart92d7f7b2007-06-17 19:56:38 -05005443 elsiocb->context2 = NULL;
5444 elsiocb->context3 = NULL;
5445
5446 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
5447 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
5448 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
5449 (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) {
James Smarted957682007-06-17 19:56:37 -05005450 phba->fc_stat.NoRcvBuf++;
5451 /* Not enough posted buffers; Try posting more buffers */
James Smart92d7f7b2007-06-17 19:56:38 -05005452 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
James Smart495a7142008-06-14 22:52:59 -04005453 lpfc_post_buffer(phba, pring, 0);
James Smarted957682007-06-17 19:56:37 -05005454 return;
5455 }
5456
James Smart92d7f7b2007-06-17 19:56:38 -05005457 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
5458 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
5459 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
5460 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
5461 vport = phba->pport;
5462 else {
5463 uint16_t vpi = icmd->unsli3.rcvsli3.vpi;
5464 vport = lpfc_find_vport_by_vpid(phba, vpi);
5465 }
5466 }
James Smart7f5f3d02008-02-08 18:50:14 -05005467 /* If there are no BDEs associated
5468 * with this IOCB, there is nothing to do.
5469 */
James Smarted957682007-06-17 19:56:37 -05005470 if (icmd->ulpBdeCount == 0)
5471 return;
5472
James Smart7f5f3d02008-02-08 18:50:14 -05005473 /* type of ELS cmd is first 32bit word
5474 * in packet
5475 */
James Smarted957682007-06-17 19:56:37 -05005476 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05005477 elsiocb->context2 = bdeBuf1;
James Smarted957682007-06-17 19:56:37 -05005478 } else {
5479 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
5480 icmd->un.cont64[0].addrLow);
James Smart92d7f7b2007-06-17 19:56:38 -05005481 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
5482 paddr);
James Smarted957682007-06-17 19:56:37 -05005483 }
5484
James Smart92d7f7b2007-06-17 19:56:38 -05005485 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
5486 /*
5487 * The different unsolicited event handlers would tell us
5488 * if they are done with "mp" by setting context2 to NULL.
5489 */
James Smart329f9bc2007-04-25 09:53:01 -04005490 lpfc_nlp_put(elsiocb->context1);
5491 elsiocb->context1 = NULL;
dea31012005-04-17 16:05:31 -05005492 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05005493 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
5494 elsiocb->context2 = NULL;
dea31012005-04-17 16:05:31 -05005495 }
James Smarted957682007-06-17 19:56:37 -05005496
5497 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
James Smart92d7f7b2007-06-17 19:56:38 -05005498 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
James Smarted957682007-06-17 19:56:37 -05005499 icmd->ulpBdeCount == 2) {
James Smart92d7f7b2007-06-17 19:56:38 -05005500 elsiocb->context2 = bdeBuf2;
5501 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
James Smarted957682007-06-17 19:56:37 -05005502 /* free mp if we are done with it */
5503 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05005504 lpfc_in_buf_free(phba, elsiocb->context2);
5505 elsiocb->context2 = NULL;
James Smarted957682007-06-17 19:56:37 -05005506 }
dea31012005-04-17 16:05:31 -05005507 }
dea31012005-04-17 16:05:31 -05005508}
James Smart92d7f7b2007-06-17 19:56:38 -05005509
James Smarte59058c2008-08-24 21:49:00 -04005510/**
5511 * lpfc_do_scr_ns_plogi: Issue a plogi to the name server for scr.
5512 * @phba: pointer to lpfc hba data structure.
5513 * @vport: pointer to a virtual N_Port data structure.
5514 *
5515 * This routine issues a Port Login (PLOGI) to the Name Server with
5516 * State Change Request (SCR) for a @vport. This routine will create an
5517 * ndlp for the Name Server associated to the @vport if such node does
5518 * not already exist. The PLOGI to Name Server is issued by invoking the
5519 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
5520 * (FDMI) is configured to the @vport, a FDMI node will be created and
5521 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
5522 **/
James Smart92d7f7b2007-06-17 19:56:38 -05005523void
5524lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
5525{
5526 struct lpfc_nodelist *ndlp, *ndlp_fdmi;
5527
5528 ndlp = lpfc_findnode_did(vport, NameServer_DID);
5529 if (!ndlp) {
5530 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
5531 if (!ndlp) {
5532 if (phba->fc_topology == TOPOLOGY_LOOP) {
5533 lpfc_disc_start(vport);
5534 return;
5535 }
5536 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04005537 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5538 "0251 NameServer login: no memory\n");
James Smart92d7f7b2007-06-17 19:56:38 -05005539 return;
5540 }
5541 lpfc_nlp_init(vport, ndlp, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05005542 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
5543 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
5544 if (!ndlp) {
5545 if (phba->fc_topology == TOPOLOGY_LOOP) {
5546 lpfc_disc_start(vport);
5547 return;
5548 }
5549 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
5550 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5551 "0348 NameServer login: node freed\n");
5552 return;
5553 }
James Smart92d7f7b2007-06-17 19:56:38 -05005554 }
James Smart58da1ff2008-04-07 10:15:56 -04005555 ndlp->nlp_type |= NLP_FABRIC;
James Smart92d7f7b2007-06-17 19:56:38 -05005556
5557 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
5558
5559 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
5560 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04005561 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5562 "0252 Cannot issue NameServer login\n");
James Smart92d7f7b2007-06-17 19:56:38 -05005563 return;
5564 }
5565
James Smart3de2a652007-08-02 11:09:59 -04005566 if (vport->cfg_fdmi_on) {
James Smart92d7f7b2007-06-17 19:56:38 -05005567 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
5568 GFP_KERNEL);
5569 if (ndlp_fdmi) {
5570 lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
5571 ndlp_fdmi->nlp_type |= NLP_FABRIC;
James Smart58da1ff2008-04-07 10:15:56 -04005572 lpfc_nlp_set_state(vport, ndlp_fdmi,
5573 NLP_STE_PLOGI_ISSUE);
James Smart92d7f7b2007-06-17 19:56:38 -05005574 lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID,
5575 0);
5576 }
5577 }
5578 return;
5579}
5580
James Smarte59058c2008-08-24 21:49:00 -04005581/**
5582 * lpfc_cmpl_reg_new_vport: Completion callback function to register new vport.
5583 * @phba: pointer to lpfc hba data structure.
5584 * @pmb: pointer to the driver internal queue element for mailbox command.
5585 *
5586 * This routine is the completion callback function to register new vport
5587 * mailbox command. If the new vport mailbox command completes successfully,
5588 * the fabric registration login shall be performed on physical port (the
5589 * new vport created is actually a physical port, with VPI 0) or the port
5590 * login to Name Server for State Change Request (SCR) will be performed
5591 * on virtual port (real virtual port, with VPI greater than 0).
5592 **/
James Smart92d7f7b2007-06-17 19:56:38 -05005593static void
5594lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
5595{
5596 struct lpfc_vport *vport = pmb->vport;
5597 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5598 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
5599 MAILBOX_t *mb = &pmb->mb;
5600
James Smart09372822008-01-11 01:52:54 -05005601 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05005602 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05005603 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05005604
5605 if (mb->mbxStatus) {
James Smarte8b62012007-08-02 11:10:09 -04005606 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
5607 "0915 Register VPI failed: 0x%x\n",
5608 mb->mbxStatus);
James Smart92d7f7b2007-06-17 19:56:38 -05005609
5610 switch (mb->mbxStatus) {
5611 case 0x11: /* unsupported feature */
5612 case 0x9603: /* max_vpi exceeded */
James Smart7f5f3d02008-02-08 18:50:14 -05005613 case 0x9602: /* Link event since CLEAR_LA */
James Smart92d7f7b2007-06-17 19:56:38 -05005614 /* giving up on vport registration */
5615 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
5616 spin_lock_irq(shost->host_lock);
5617 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
5618 spin_unlock_irq(shost->host_lock);
5619 lpfc_can_disctmo(vport);
5620 break;
5621 default:
5622 /* Try to recover from this error */
5623 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -05005624 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05005625 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05005626 spin_unlock_irq(shost->host_lock);
James Smart7f5f3d02008-02-08 18:50:14 -05005627 if (vport->port_type == LPFC_PHYSICAL_PORT)
5628 lpfc_initial_flogi(vport);
5629 else
5630 lpfc_initial_fdisc(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05005631 break;
5632 }
5633
5634 } else {
5635 if (vport == phba->pport)
5636 lpfc_issue_fabric_reglogin(vport);
5637 else
5638 lpfc_do_scr_ns_plogi(phba, vport);
5639 }
James Smartfa4066b2008-01-11 01:53:27 -05005640
5641 /* Now, we decrement the ndlp reference count held for this
5642 * callback function
5643 */
5644 lpfc_nlp_put(ndlp);
5645
James Smart92d7f7b2007-06-17 19:56:38 -05005646 mempool_free(pmb, phba->mbox_mem_pool);
5647 return;
5648}
5649
James Smarte59058c2008-08-24 21:49:00 -04005650/**
5651 * lpfc_register_new_vport: Register a new vport with a HBA.
5652 * @phba: pointer to lpfc hba data structure.
5653 * @vport: pointer to a host virtual N_Port data structure.
5654 * @ndlp: pointer to a node-list data structure.
5655 *
5656 * This routine registers the @vport as a new virtual port with a HBA.
5657 * It is done through a registering vpi mailbox command.
5658 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01005659static void
James Smart92d7f7b2007-06-17 19:56:38 -05005660lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
5661 struct lpfc_nodelist *ndlp)
5662{
James Smart09372822008-01-11 01:52:54 -05005663 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05005664 LPFC_MBOXQ_t *mbox;
5665
5666 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5667 if (mbox) {
5668 lpfc_reg_vpi(phba, vport->vpi, vport->fc_myDID, mbox);
5669 mbox->vport = vport;
5670 mbox->context2 = lpfc_nlp_get(ndlp);
5671 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
James Smart0b727fe2007-10-27 13:37:25 -04005672 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart92d7f7b2007-06-17 19:56:38 -05005673 == MBX_NOT_FINISHED) {
James Smartfa4066b2008-01-11 01:53:27 -05005674 /* mailbox command not success, decrement ndlp
5675 * reference count for this command
5676 */
5677 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05005678 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05005679
James Smarte8b62012007-08-02 11:10:09 -04005680 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
5681 "0253 Register VPI: Can't send mbox\n");
James Smartfa4066b2008-01-11 01:53:27 -05005682 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05005683 }
5684 } else {
James Smarte8b62012007-08-02 11:10:09 -04005685 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
5686 "0254 Register VPI: no memory\n");
James Smartfa4066b2008-01-11 01:53:27 -05005687 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05005688 }
James Smartfa4066b2008-01-11 01:53:27 -05005689 return;
5690
5691mbox_err_exit:
5692 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
5693 spin_lock_irq(shost->host_lock);
5694 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
5695 spin_unlock_irq(shost->host_lock);
5696 return;
James Smart92d7f7b2007-06-17 19:56:38 -05005697}
5698
James Smarte59058c2008-08-24 21:49:00 -04005699/**
5700 * lpfc_cmpl_els_fdisc: Completion function for fdisc iocb command.
5701 * @phba: pointer to lpfc hba data structure.
5702 * @cmdiocb: pointer to lpfc command iocb data structure.
5703 * @rspiocb: pointer to lpfc response iocb data structure.
5704 *
5705 * This routine is the completion callback function to a Fabric Discover
5706 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
5707 * single threaded, each FDISC completion callback function will reset
5708 * the discovery timer for all vports such that the timers will not get
5709 * unnecessary timeout. The function checks the FDISC IOCB status. If error
5710 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
5711 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
5712 * assigned to the vport has been changed with the completion of the FDISC
5713 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
5714 * are unregistered from the HBA, and then the lpfc_register_new_vport()
5715 * routine is invoked to register new vport with the HBA. Otherwise, the
5716 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
5717 * Server for State Change Request (SCR).
5718 **/
James Smart92d7f7b2007-06-17 19:56:38 -05005719static void
5720lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
5721 struct lpfc_iocbq *rspiocb)
5722{
5723 struct lpfc_vport *vport = cmdiocb->vport;
5724 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5725 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
5726 struct lpfc_nodelist *np;
5727 struct lpfc_nodelist *next_np;
5728 IOCB_t *irsp = &rspiocb->iocb;
5729 struct lpfc_iocbq *piocb;
5730
James Smarte8b62012007-08-02 11:10:09 -04005731 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5732 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
5733 irsp->ulpStatus, irsp->un.ulpWord[4],
5734 vport->fc_prevDID);
James Smart92d7f7b2007-06-17 19:56:38 -05005735 /* Since all FDISCs are being single threaded, we
5736 * must reset the discovery timer for ALL vports
5737 * waiting to send FDISC when one completes.
5738 */
5739 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
5740 lpfc_set_disctmo(piocb->vport);
5741 }
5742
James Smart858c9f62007-06-17 19:56:39 -05005743 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
5744 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
5745 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
5746
James Smart92d7f7b2007-06-17 19:56:38 -05005747 if (irsp->ulpStatus) {
5748 /* Check for retry */
5749 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
5750 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05005751 /* FDISC failed */
James Smarte8b62012007-08-02 11:10:09 -04005752 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5753 "0124 FDISC failed. (%d/%d)\n",
5754 irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smart92d7f7b2007-06-17 19:56:38 -05005755 if (vport->fc_vport->vport_state == FC_VPORT_INITIALIZING)
5756 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smart92d7f7b2007-06-17 19:56:38 -05005757 lpfc_nlp_put(ndlp);
5758 /* giving up on FDISC. Cancel discovery timer */
5759 lpfc_can_disctmo(vport);
5760 } else {
5761 spin_lock_irq(shost->host_lock);
5762 vport->fc_flag |= FC_FABRIC;
5763 if (vport->phba->fc_topology == TOPOLOGY_LOOP)
5764 vport->fc_flag |= FC_PUBLIC_LOOP;
5765 spin_unlock_irq(shost->host_lock);
5766
5767 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
5768 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
5769 if ((vport->fc_prevDID != vport->fc_myDID) &&
5770 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
5771 /* If our NportID changed, we need to ensure all
5772 * remaining NPORTs get unreg_login'ed so we can
5773 * issue unreg_vpi.
5774 */
5775 list_for_each_entry_safe(np, next_np,
5776 &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05005777 if (!NLP_CHK_NODE_ACT(ndlp) ||
5778 (np->nlp_state != NLP_STE_NPR_NODE) ||
5779 !(np->nlp_flag & NLP_NPR_ADISC))
James Smart92d7f7b2007-06-17 19:56:38 -05005780 continue;
5781 spin_lock_irq(shost->host_lock);
5782 np->nlp_flag &= ~NLP_NPR_ADISC;
5783 spin_unlock_irq(shost->host_lock);
5784 lpfc_unreg_rpi(vport, np);
5785 }
5786 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -05005787 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05005788 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05005789 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05005790 }
5791
5792 if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
5793 lpfc_register_new_vport(phba, vport, ndlp);
5794 else
5795 lpfc_do_scr_ns_plogi(phba, vport);
5796
James Smartfa4066b2008-01-11 01:53:27 -05005797 /* Unconditionaly kick off releasing fabric node for vports */
5798 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05005799 }
5800
5801out:
5802 lpfc_els_free_iocb(phba, cmdiocb);
5803}
5804
James Smarte59058c2008-08-24 21:49:00 -04005805/**
5806 * lpfc_issue_els_fdisc: Issue a fdisc iocb command.
5807 * @vport: pointer to a virtual N_Port data structure.
5808 * @ndlp: pointer to a node-list data structure.
5809 * @retry: number of retries to the command IOCB.
5810 *
5811 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
5812 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
5813 * routine to issue the IOCB, which makes sure only one outstanding fabric
5814 * IOCB will be sent off HBA at any given time.
5815 *
5816 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5817 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5818 * will be stored into the context1 field of the IOCB for the completion
5819 * callback function to the FDISC ELS command.
5820 *
5821 * Return code
5822 * 0 - Successfully issued fdisc iocb command
5823 * 1 - Failed to issue fdisc iocb command
5824 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01005825static int
James Smart92d7f7b2007-06-17 19:56:38 -05005826lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
5827 uint8_t retry)
5828{
5829 struct lpfc_hba *phba = vport->phba;
5830 IOCB_t *icmd;
5831 struct lpfc_iocbq *elsiocb;
5832 struct serv_parm *sp;
5833 uint8_t *pcmd;
5834 uint16_t cmdsize;
5835 int did = ndlp->nlp_DID;
5836 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05005837
5838 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
5839 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
5840 ELS_CMD_FDISC);
5841 if (!elsiocb) {
James Smart92d7f7b2007-06-17 19:56:38 -05005842 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04005843 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5844 "0255 Issue FDISC: no IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05005845 return 1;
5846 }
5847
5848 icmd = &elsiocb->iocb;
5849 icmd->un.elsreq64.myID = 0;
5850 icmd->un.elsreq64.fl = 1;
5851
5852 /* For FDISC, Let FDISC rsp set the NPortID for this VPI */
5853 icmd->ulpCt_h = 1;
5854 icmd->ulpCt_l = 0;
5855
5856 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5857 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
5858 pcmd += sizeof(uint32_t); /* CSP Word 1 */
5859 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
5860 sp = (struct serv_parm *) pcmd;
5861 /* Setup CSPs accordingly for Fabric */
5862 sp->cmn.e_d_tov = 0;
5863 sp->cmn.w2.r_a_tov = 0;
5864 sp->cls1.classValid = 0;
5865 sp->cls2.seqDelivery = 1;
5866 sp->cls3.seqDelivery = 1;
5867
5868 pcmd += sizeof(uint32_t); /* CSP Word 2 */
5869 pcmd += sizeof(uint32_t); /* CSP Word 3 */
5870 pcmd += sizeof(uint32_t); /* CSP Word 4 */
5871 pcmd += sizeof(uint32_t); /* Port Name */
5872 memcpy(pcmd, &vport->fc_portname, 8);
5873 pcmd += sizeof(uint32_t); /* Node Name */
5874 pcmd += sizeof(uint32_t); /* Node Name */
5875 memcpy(pcmd, &vport->fc_nodename, 8);
5876
5877 lpfc_set_disctmo(vport);
5878
5879 phba->fc_stat.elsXmitFDISC++;
5880 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
5881
James Smart858c9f62007-06-17 19:56:39 -05005882 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
5883 "Issue FDISC: did:x%x",
5884 did, 0, 0);
5885
James Smart92d7f7b2007-06-17 19:56:38 -05005886 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
5887 if (rc == IOCB_ERROR) {
5888 lpfc_els_free_iocb(phba, elsiocb);
James Smart92d7f7b2007-06-17 19:56:38 -05005889 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04005890 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5891 "0256 Issue FDISC: Cannot send IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05005892 return 1;
5893 }
5894 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
5895 vport->port_state = LPFC_FDISC;
5896 return 0;
5897}
5898
James Smarte59058c2008-08-24 21:49:00 -04005899/**
5900 * lpfc_cmpl_els_npiv_logo: Completion function with vport logo.
5901 * @phba: pointer to lpfc hba data structure.
5902 * @cmdiocb: pointer to lpfc command iocb data structure.
5903 * @rspiocb: pointer to lpfc response iocb data structure.
5904 *
5905 * This routine is the completion callback function to the issuing of a LOGO
5906 * ELS command off a vport. It frees the command IOCB and then decrement the
5907 * reference count held on ndlp for this completion function, indicating that
5908 * the reference to the ndlp is no long needed. Note that the
5909 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
5910 * callback function and an additional explicit ndlp reference decrementation
5911 * will trigger the actual release of the ndlp.
5912 **/
James Smart92d7f7b2007-06-17 19:56:38 -05005913static void
5914lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
5915 struct lpfc_iocbq *rspiocb)
5916{
5917 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05005918 IOCB_t *irsp;
James Smarte47c9092008-02-08 18:49:26 -05005919 struct lpfc_nodelist *ndlp;
5920 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
James Smart858c9f62007-06-17 19:56:39 -05005921
5922 irsp = &rspiocb->iocb;
5923 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
5924 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
5925 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
James Smart92d7f7b2007-06-17 19:56:38 -05005926
5927 lpfc_els_free_iocb(phba, cmdiocb);
5928 vport->unreg_vpi_cmpl = VPORT_ERROR;
James Smarte47c9092008-02-08 18:49:26 -05005929
5930 /* Trigger the release of the ndlp after logo */
5931 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05005932}
5933
James Smarte59058c2008-08-24 21:49:00 -04005934/**
5935 * lpfc_issue_els_npiv_logo: Issue a logo off a vport.
5936 * @vport: pointer to a virtual N_Port data structure.
5937 * @ndlp: pointer to a node-list data structure.
5938 *
5939 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
5940 *
5941 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
5942 * will be incremented by 1 for holding the ndlp and the reference to ndlp
5943 * will be stored into the context1 field of the IOCB for the completion
5944 * callback function to the LOGO ELS command.
5945 *
5946 * Return codes
5947 * 0 - Successfully issued logo off the @vport
5948 * 1 - Failed to issue logo off the @vport
5949 **/
James Smart92d7f7b2007-06-17 19:56:38 -05005950int
5951lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
5952{
5953 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5954 struct lpfc_hba *phba = vport->phba;
5955 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
5956 IOCB_t *icmd;
5957 struct lpfc_iocbq *elsiocb;
5958 uint8_t *pcmd;
5959 uint16_t cmdsize;
5960
5961 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
5962 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
5963 ELS_CMD_LOGO);
5964 if (!elsiocb)
5965 return 1;
5966
5967 icmd = &elsiocb->iocb;
5968 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
5969 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
5970 pcmd += sizeof(uint32_t);
5971
5972 /* Fill in LOGO payload */
5973 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
5974 pcmd += sizeof(uint32_t);
5975 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
5976
James Smart858c9f62007-06-17 19:56:39 -05005977 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
5978 "Issue LOGO npiv did:x%x flg:x%x",
5979 ndlp->nlp_DID, ndlp->nlp_flag, 0);
5980
James Smart92d7f7b2007-06-17 19:56:38 -05005981 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
5982 spin_lock_irq(shost->host_lock);
5983 ndlp->nlp_flag |= NLP_LOGO_SND;
5984 spin_unlock_irq(shost->host_lock);
5985 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
5986 spin_lock_irq(shost->host_lock);
5987 ndlp->nlp_flag &= ~NLP_LOGO_SND;
5988 spin_unlock_irq(shost->host_lock);
5989 lpfc_els_free_iocb(phba, elsiocb);
5990 return 1;
5991 }
5992 return 0;
5993}
5994
James Smarte59058c2008-08-24 21:49:00 -04005995/**
5996 * lpfc_fabric_block_timeout: Handler function to the fabric block timer.
5997 * @ptr: holder for the timer function associated data.
5998 *
5999 * This routine is invoked by the fabric iocb block timer after
6000 * timeout. It posts the fabric iocb block timeout event by setting the
6001 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
6002 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
6003 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
6004 * posted event WORKER_FABRIC_BLOCK_TMO.
6005 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006006void
6007lpfc_fabric_block_timeout(unsigned long ptr)
6008{
6009 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
6010 unsigned long iflags;
6011 uint32_t tmo_posted;
James Smart5e9d9b82008-06-14 22:52:53 -04006012
James Smart92d7f7b2007-06-17 19:56:38 -05006013 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
6014 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
6015 if (!tmo_posted)
6016 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
6017 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
6018
James Smart5e9d9b82008-06-14 22:52:53 -04006019 if (!tmo_posted)
6020 lpfc_worker_wake_up(phba);
6021 return;
James Smart92d7f7b2007-06-17 19:56:38 -05006022}
6023
James Smarte59058c2008-08-24 21:49:00 -04006024/**
6025 * lpfc_resume_fabric_iocbs: Issue a fabric iocb from driver internal list.
6026 * @phba: pointer to lpfc hba data structure.
6027 *
6028 * This routine issues one fabric iocb from the driver internal list to
6029 * the HBA. It first checks whether it's ready to issue one fabric iocb to
6030 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
6031 * remove one pending fabric iocb from the driver internal list and invokes
6032 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
6033 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006034static void
6035lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
6036{
6037 struct lpfc_iocbq *iocb;
6038 unsigned long iflags;
6039 int ret;
6040 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
6041 IOCB_t *cmd;
6042
6043repeat:
6044 iocb = NULL;
6045 spin_lock_irqsave(&phba->hbalock, iflags);
James Smart7f5f3d02008-02-08 18:50:14 -05006046 /* Post any pending iocb to the SLI layer */
James Smart92d7f7b2007-06-17 19:56:38 -05006047 if (atomic_read(&phba->fabric_iocb_count) == 0) {
6048 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
6049 list);
6050 if (iocb)
James Smart7f5f3d02008-02-08 18:50:14 -05006051 /* Increment fabric iocb count to hold the position */
James Smart92d7f7b2007-06-17 19:56:38 -05006052 atomic_inc(&phba->fabric_iocb_count);
6053 }
6054 spin_unlock_irqrestore(&phba->hbalock, iflags);
6055 if (iocb) {
6056 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
6057 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
6058 iocb->iocb_flag |= LPFC_IO_FABRIC;
6059
James Smart858c9f62007-06-17 19:56:39 -05006060 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
6061 "Fabric sched1: ste:x%x",
6062 iocb->vport->port_state, 0, 0);
6063
James Smart92d7f7b2007-06-17 19:56:38 -05006064 ret = lpfc_sli_issue_iocb(phba, pring, iocb, 0);
6065
6066 if (ret == IOCB_ERROR) {
6067 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
6068 iocb->fabric_iocb_cmpl = NULL;
6069 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
6070 cmd = &iocb->iocb;
6071 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
6072 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
6073 iocb->iocb_cmpl(phba, iocb, iocb);
6074
6075 atomic_dec(&phba->fabric_iocb_count);
6076 goto repeat;
6077 }
6078 }
6079
6080 return;
6081}
6082
James Smarte59058c2008-08-24 21:49:00 -04006083/**
6084 * lpfc_unblock_fabric_iocbs: Unblock issuing fabric iocb command.
6085 * @phba: pointer to lpfc hba data structure.
6086 *
6087 * This routine unblocks the issuing fabric iocb command. The function
6088 * will clear the fabric iocb block bit and then invoke the routine
6089 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
6090 * from the driver internal fabric iocb list.
6091 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006092void
6093lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
6094{
6095 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
6096
6097 lpfc_resume_fabric_iocbs(phba);
6098 return;
6099}
6100
James Smarte59058c2008-08-24 21:49:00 -04006101/**
6102 * lpfc_block_fabric_iocbs: Block issuing fabric iocb command.
6103 * @phba: pointer to lpfc hba data structure.
6104 *
6105 * This routine blocks the issuing fabric iocb for a specified amount of
6106 * time (currently 100 ms). This is done by set the fabric iocb block bit
6107 * and set up a timeout timer for 100ms. When the block bit is set, no more
6108 * fabric iocb will be issued out of the HBA.
6109 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006110static void
6111lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
6112{
6113 int blocked;
6114
6115 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
James Smart7f5f3d02008-02-08 18:50:14 -05006116 /* Start a timer to unblock fabric iocbs after 100ms */
James Smart92d7f7b2007-06-17 19:56:38 -05006117 if (!blocked)
6118 mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 );
6119
6120 return;
6121}
6122
James Smarte59058c2008-08-24 21:49:00 -04006123/**
6124 * lpfc_cmpl_fabric_iocb: Completion callback function for fabric iocb.
6125 * @phba: pointer to lpfc hba data structure.
6126 * @cmdiocb: pointer to lpfc command iocb data structure.
6127 * @rspiocb: pointer to lpfc response iocb data structure.
6128 *
6129 * This routine is the callback function that is put to the fabric iocb's
6130 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
6131 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
6132 * function first restores and invokes the original iocb's callback function
6133 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
6134 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
6135 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006136static void
6137lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6138 struct lpfc_iocbq *rspiocb)
6139{
6140 struct ls_rjt stat;
6141
6142 if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
6143 BUG();
6144
6145 switch (rspiocb->iocb.ulpStatus) {
6146 case IOSTAT_NPORT_RJT:
6147 case IOSTAT_FABRIC_RJT:
6148 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
6149 lpfc_block_fabric_iocbs(phba);
6150 }
6151 break;
6152
6153 case IOSTAT_NPORT_BSY:
6154 case IOSTAT_FABRIC_BSY:
6155 lpfc_block_fabric_iocbs(phba);
6156 break;
6157
6158 case IOSTAT_LS_RJT:
6159 stat.un.lsRjtError =
6160 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
6161 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
6162 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
6163 lpfc_block_fabric_iocbs(phba);
6164 break;
6165 }
6166
6167 if (atomic_read(&phba->fabric_iocb_count) == 0)
6168 BUG();
6169
6170 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
6171 cmdiocb->fabric_iocb_cmpl = NULL;
6172 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
6173 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
6174
6175 atomic_dec(&phba->fabric_iocb_count);
6176 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
James Smart7f5f3d02008-02-08 18:50:14 -05006177 /* Post any pending iocbs to HBA */
6178 lpfc_resume_fabric_iocbs(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05006179 }
6180}
6181
James Smarte59058c2008-08-24 21:49:00 -04006182/**
6183 * lpfc_issue_fabric_iocb: Issue a fabric iocb command.
6184 * @phba: pointer to lpfc hba data structure.
6185 * @iocb: pointer to lpfc command iocb data structure.
6186 *
6187 * This routine is used as the top-level API for issuing a fabric iocb command
6188 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
6189 * function makes sure that only one fabric bound iocb will be outstanding at
6190 * any given time. As such, this function will first check to see whether there
6191 * is already an outstanding fabric iocb on the wire. If so, it will put the
6192 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
6193 * issued later. Otherwise, it will issue the iocb on the wire and update the
6194 * fabric iocb count it indicate that there is one fabric iocb on the wire.
6195 *
6196 * Note, this implementation has a potential sending out fabric IOCBs out of
6197 * order. The problem is caused by the construction of the "ready" boolen does
6198 * not include the condition that the internal fabric IOCB list is empty. As
6199 * such, it is possible a fabric IOCB issued by this routine might be "jump"
6200 * ahead of the fabric IOCBs in the internal list.
6201 *
6202 * Return code
6203 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
6204 * IOCB_ERROR - failed to issue fabric iocb
6205 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01006206static int
James Smart92d7f7b2007-06-17 19:56:38 -05006207lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
6208{
6209 unsigned long iflags;
6210 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
6211 int ready;
6212 int ret;
6213
6214 if (atomic_read(&phba->fabric_iocb_count) > 1)
6215 BUG();
6216
6217 spin_lock_irqsave(&phba->hbalock, iflags);
6218 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
6219 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
6220
James Smart7f5f3d02008-02-08 18:50:14 -05006221 if (ready)
6222 /* Increment fabric iocb count to hold the position */
6223 atomic_inc(&phba->fabric_iocb_count);
James Smart92d7f7b2007-06-17 19:56:38 -05006224 spin_unlock_irqrestore(&phba->hbalock, iflags);
6225 if (ready) {
6226 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
6227 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
6228 iocb->iocb_flag |= LPFC_IO_FABRIC;
6229
James Smart858c9f62007-06-17 19:56:39 -05006230 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
6231 "Fabric sched2: ste:x%x",
6232 iocb->vport->port_state, 0, 0);
6233
James Smart92d7f7b2007-06-17 19:56:38 -05006234 ret = lpfc_sli_issue_iocb(phba, pring, iocb, 0);
6235
6236 if (ret == IOCB_ERROR) {
6237 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
6238 iocb->fabric_iocb_cmpl = NULL;
6239 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
6240 atomic_dec(&phba->fabric_iocb_count);
6241 }
6242 } else {
6243 spin_lock_irqsave(&phba->hbalock, iflags);
6244 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
6245 spin_unlock_irqrestore(&phba->hbalock, iflags);
6246 ret = IOCB_SUCCESS;
6247 }
6248 return ret;
6249}
6250
James Smarte59058c2008-08-24 21:49:00 -04006251/**
6252 * lpfc_fabric_abort_vport: Abort a vport's iocbs from driver fabric iocb list.
6253 * @vport: pointer to a virtual N_Port data structure.
6254 *
6255 * This routine aborts all the IOCBs associated with a @vport from the
6256 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
6257 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
6258 * list, removes each IOCB associated with the @vport off the list, set the
6259 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
6260 * associated with the IOCB.
6261 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01006262static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
James Smart92d7f7b2007-06-17 19:56:38 -05006263{
6264 LIST_HEAD(completions);
6265 struct lpfc_hba *phba = vport->phba;
6266 struct lpfc_iocbq *tmp_iocb, *piocb;
6267 IOCB_t *cmd;
6268
6269 spin_lock_irq(&phba->hbalock);
6270 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
6271 list) {
6272
6273 if (piocb->vport != vport)
6274 continue;
6275
6276 list_move_tail(&piocb->list, &completions);
6277 }
6278 spin_unlock_irq(&phba->hbalock);
6279
6280 while (!list_empty(&completions)) {
6281 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
6282 list_del_init(&piocb->list);
6283
6284 cmd = &piocb->iocb;
6285 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
6286 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
6287 (piocb->iocb_cmpl) (phba, piocb, piocb);
6288 }
6289}
6290
James Smarte59058c2008-08-24 21:49:00 -04006291/**
6292 * lpfc_fabric_abort_nport: Abort a ndlp's iocbs from driver fabric iocb list.
6293 * @ndlp: pointer to a node-list data structure.
6294 *
6295 * This routine aborts all the IOCBs associated with an @ndlp from the
6296 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
6297 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
6298 * list, removes each IOCB associated with the @ndlp off the list, set the
6299 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
6300 * associated with the IOCB.
6301 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006302void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
6303{
6304 LIST_HEAD(completions);
6305 struct lpfc_hba *phba = ndlp->vport->phba;
6306 struct lpfc_iocbq *tmp_iocb, *piocb;
6307 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
6308 IOCB_t *cmd;
6309
6310 spin_lock_irq(&phba->hbalock);
6311 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
6312 list) {
6313 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
6314
6315 list_move_tail(&piocb->list, &completions);
6316 }
6317 }
6318 spin_unlock_irq(&phba->hbalock);
6319
6320 while (!list_empty(&completions)) {
6321 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
6322 list_del_init(&piocb->list);
6323
6324 cmd = &piocb->iocb;
6325 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
6326 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
6327 (piocb->iocb_cmpl) (phba, piocb, piocb);
6328 }
6329}
6330
James Smarte59058c2008-08-24 21:49:00 -04006331/**
6332 * lpfc_fabric_abort_hba: Abort all iocbs on driver fabric iocb list.
6333 * @phba: pointer to lpfc hba data structure.
6334 *
6335 * This routine aborts all the IOCBs currently on the driver internal
6336 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
6337 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
6338 * list, removes IOCBs off the list, set the status feild to
6339 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
6340 * the IOCB.
6341 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006342void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
6343{
6344 LIST_HEAD(completions);
6345 struct lpfc_iocbq *piocb;
6346 IOCB_t *cmd;
6347
6348 spin_lock_irq(&phba->hbalock);
6349 list_splice_init(&phba->fabric_iocb_list, &completions);
6350 spin_unlock_irq(&phba->hbalock);
6351
6352 while (!list_empty(&completions)) {
6353 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
6354 list_del_init(&piocb->list);
6355
6356 cmd = &piocb->iocb;
6357 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
6358 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
6359 (piocb->iocb_cmpl) (phba, piocb, piocb);
6360 }
6361}