blob: a7302480bc4a7fb3605f6317631de89e5a9303d4 [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"
James Smartea2151b2008-09-07 11:52:10 -040033#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050034#include "lpfc_disc.h"
35#include "lpfc_scsi.h"
36#include "lpfc.h"
37#include "lpfc_logmsg.h"
38#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050039#include "lpfc_vport.h"
James Smart858c9f62007-06-17 19:56:39 -050040#include "lpfc_debugfs.h"
dea31012005-04-17 16:05:31 -050041
42static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *,
43 struct lpfc_iocbq *);
James Smart92d7f7b2007-06-17 19:56:38 -050044static void lpfc_cmpl_fabric_iocb(struct lpfc_hba *, struct lpfc_iocbq *,
45 struct lpfc_iocbq *);
Adrian Bunka6ababd2007-11-05 18:07:33 +010046static void lpfc_fabric_abort_vport(struct lpfc_vport *vport);
47static int lpfc_issue_els_fdisc(struct lpfc_vport *vport,
48 struct lpfc_nodelist *ndlp, uint8_t retry);
49static int lpfc_issue_fabric_iocb(struct lpfc_hba *phba,
50 struct lpfc_iocbq *iocb);
51static void lpfc_register_new_vport(struct lpfc_hba *phba,
52 struct lpfc_vport *vport,
53 struct lpfc_nodelist *ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -050054
dea31012005-04-17 16:05:31 -050055static int lpfc_max_els_tries = 3;
56
James Smarte59058c2008-08-24 21:49:00 -040057/**
58 * lpfc_els_chk_latt: Check host link attention event for a vport.
59 * @vport: pointer to a host virtual N_Port data structure.
60 *
61 * This routine checks whether there is an outstanding host link
62 * attention event during the discovery process with the @vport. It is done
63 * by reading the HBA's Host Attention (HA) register. If there is any host
64 * link attention events during this @vport's discovery process, the @vport
65 * shall be marked as FC_ABORT_DISCOVERY, a host link attention clear shall
66 * be issued if the link state is not already in host link cleared state,
67 * and a return code shall indicate whether the host link attention event
68 * had happened.
69 *
70 * Note that, if either the host link is in state LPFC_LINK_DOWN or @vport
71 * state in LPFC_VPORT_READY, the request for checking host link attention
72 * event will be ignored and a return code shall indicate no host link
73 * attention event had happened.
74 *
75 * Return codes
76 * 0 - no host link attention event happened
77 * 1 - host link attention event happened
78 **/
James Smart858c9f62007-06-17 19:56:39 -050079int
James Smart2e0fef82007-06-17 19:56:36 -050080lpfc_els_chk_latt(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -050081{
James Smart2e0fef82007-06-17 19:56:36 -050082 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
83 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -050084 uint32_t ha_copy;
dea31012005-04-17 16:05:31 -050085
James Smart2e0fef82007-06-17 19:56:36 -050086 if (vport->port_state >= LPFC_VPORT_READY ||
87 phba->link_state == LPFC_LINK_DOWN)
dea31012005-04-17 16:05:31 -050088 return 0;
89
90 /* Read the HBA Host Attention Register */
dea31012005-04-17 16:05:31 -050091 ha_copy = readl(phba->HAregaddr);
dea31012005-04-17 16:05:31 -050092
93 if (!(ha_copy & HA_LATT))
94 return 0;
95
96 /* Pending Link Event during Discovery */
James Smarte8b62012007-08-02 11:10:09 -040097 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
98 "0237 Pending Link Event during "
99 "Discovery: State x%x\n",
100 phba->pport->port_state);
dea31012005-04-17 16:05:31 -0500101
102 /* CLEAR_LA should re-enable link attention events and
103 * we should then imediately take a LATT event. The
104 * LATT processing should call lpfc_linkdown() which
105 * will cleanup any left over in-progress discovery
106 * events.
107 */
James Smart2e0fef82007-06-17 19:56:36 -0500108 spin_lock_irq(shost->host_lock);
109 vport->fc_flag |= FC_ABORT_DISCOVERY;
110 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500111
James Smart92d7f7b2007-06-17 19:56:38 -0500112 if (phba->link_state != LPFC_CLEAR_LA)
James Smarted957682007-06-17 19:56:37 -0500113 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -0500114
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500115 return 1;
dea31012005-04-17 16:05:31 -0500116}
117
James Smarte59058c2008-08-24 21:49:00 -0400118/**
119 * lpfc_prep_els_iocb: Allocate and prepare a lpfc iocb data structure.
120 * @vport: pointer to a host virtual N_Port data structure.
121 * @expectRsp: flag indicating whether response is expected.
122 * @cmdSize: size of the ELS command.
123 * @retry: number of retries to the command IOCB when it fails.
124 * @ndlp: pointer to a node-list data structure.
125 * @did: destination identifier.
126 * @elscmd: the ELS command code.
127 *
128 * This routine is used for allocating a lpfc-IOCB data structure from
129 * the driver lpfc-IOCB free-list and prepare the IOCB with the parameters
130 * passed into the routine for discovery state machine to issue an Extended
131 * Link Service (ELS) commands. It is a generic lpfc-IOCB allocation
132 * and preparation routine that is used by all the discovery state machine
133 * routines and the ELS command-specific fields will be later set up by
134 * the individual discovery machine routines after calling this routine
135 * allocating and preparing a generic IOCB data structure. It fills in the
136 * Buffer Descriptor Entries (BDEs), allocates buffers for both command
137 * payload and response payload (if expected). The reference count on the
138 * ndlp is incremented by 1 and the reference to the ndlp is put into
139 * context1 of the IOCB data structure for this IOCB to hold the ndlp
140 * reference for the command's callback function to access later.
141 *
142 * Return code
143 * Pointer to the newly allocated/prepared els iocb data structure
144 * NULL - when els iocb data structure allocation/preparation failed
145 **/
dea31012005-04-17 16:05:31 -0500146static struct lpfc_iocbq *
James Smart2e0fef82007-06-17 19:56:36 -0500147lpfc_prep_els_iocb(struct lpfc_vport *vport, uint8_t expectRsp,
148 uint16_t cmdSize, uint8_t retry,
149 struct lpfc_nodelist *ndlp, uint32_t did,
150 uint32_t elscmd)
dea31012005-04-17 16:05:31 -0500151{
James Smart2e0fef82007-06-17 19:56:36 -0500152 struct lpfc_hba *phba = vport->phba;
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400153 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -0500154 struct lpfc_dmabuf *pcmd, *prsp, *pbuflist;
155 struct ulp_bde64 *bpl;
156 IOCB_t *icmd;
157
dea31012005-04-17 16:05:31 -0500158
James Smart2e0fef82007-06-17 19:56:36 -0500159 if (!lpfc_is_link_up(phba))
160 return NULL;
dea31012005-04-17 16:05:31 -0500161
dea31012005-04-17 16:05:31 -0500162 /* Allocate buffer for command iocb */
James.Smart@Emulex.Com0bd4ca22005-10-28 20:30:02 -0400163 elsiocb = lpfc_sli_get_iocbq(phba);
dea31012005-04-17 16:05:31 -0500164
165 if (elsiocb == NULL)
166 return NULL;
James Smarte47c9092008-02-08 18:49:26 -0500167
dea31012005-04-17 16:05:31 -0500168 icmd = &elsiocb->iocb;
169
170 /* fill in BDEs for command */
171 /* Allocate buffer for command payload */
James Smart98c9ea52007-10-27 13:37:33 -0400172 pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
173 if (pcmd)
174 pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500175 if (!pcmd || !pcmd->virt)
176 goto els_iocb_free_pcmb_exit;
dea31012005-04-17 16:05:31 -0500177
178 INIT_LIST_HEAD(&pcmd->list);
179
180 /* Allocate buffer for response payload */
181 if (expectRsp) {
James Smart92d7f7b2007-06-17 19:56:38 -0500182 prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -0500183 if (prsp)
184 prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
185 &prsp->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500186 if (!prsp || !prsp->virt)
187 goto els_iocb_free_prsp_exit;
dea31012005-04-17 16:05:31 -0500188 INIT_LIST_HEAD(&prsp->list);
James Smarte47c9092008-02-08 18:49:26 -0500189 } else
dea31012005-04-17 16:05:31 -0500190 prsp = NULL;
dea31012005-04-17 16:05:31 -0500191
192 /* Allocate buffer for Buffer ptr list */
James Smart92d7f7b2007-06-17 19:56:38 -0500193 pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -0500194 if (pbuflist)
James Smarted957682007-06-17 19:56:37 -0500195 pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
196 &pbuflist->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500197 if (!pbuflist || !pbuflist->virt)
198 goto els_iocb_free_pbuf_exit;
dea31012005-04-17 16:05:31 -0500199
200 INIT_LIST_HEAD(&pbuflist->list);
201
202 icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
203 icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
James Smart34b02dc2008-08-24 21:49:55 -0400204 icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
James Smart2e0fef82007-06-17 19:56:36 -0500205 icmd->un.elsreq64.remoteID = did; /* DID */
dea31012005-04-17 16:05:31 -0500206 if (expectRsp) {
James Smart92d7f7b2007-06-17 19:56:38 -0500207 icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
dea31012005-04-17 16:05:31 -0500208 icmd->ulpCommand = CMD_ELS_REQUEST64_CR;
James Smart2680eea2007-04-25 09:52:55 -0400209 icmd->ulpTimeout = phba->fc_ratov * 2;
dea31012005-04-17 16:05:31 -0500210 } else {
James Smart92d7f7b2007-06-17 19:56:38 -0500211 icmd->un.elsreq64.bdl.bdeSize = sizeof(struct ulp_bde64);
dea31012005-04-17 16:05:31 -0500212 icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
213 }
dea31012005-04-17 16:05:31 -0500214 icmd->ulpBdeCount = 1;
215 icmd->ulpLe = 1;
216 icmd->ulpClass = CLASS3;
217
James Smart92d7f7b2007-06-17 19:56:38 -0500218 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
219 icmd->un.elsreq64.myID = vport->fc_myDID;
220
221 /* For ELS_REQUEST64_CR, use the VPI by default */
222 icmd->ulpContext = vport->vpi;
223 icmd->ulpCt_h = 0;
James Smarteada2722008-12-04 22:39:13 -0500224 /* The CT field must be 0=INVALID_RPI for the ECHO cmd */
225 if (elscmd == ELS_CMD_ECHO)
226 icmd->ulpCt_l = 0; /* context = invalid RPI */
227 else
228 icmd->ulpCt_l = 1; /* context = VPI */
James Smart92d7f7b2007-06-17 19:56:38 -0500229 }
230
dea31012005-04-17 16:05:31 -0500231 bpl = (struct ulp_bde64 *) pbuflist->virt;
232 bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys));
233 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys));
234 bpl->tus.f.bdeSize = cmdSize;
235 bpl->tus.f.bdeFlags = 0;
236 bpl->tus.w = le32_to_cpu(bpl->tus.w);
237
238 if (expectRsp) {
239 bpl++;
240 bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys));
241 bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys));
242 bpl->tus.f.bdeSize = FCELSSIZE;
James Smart34b02dc2008-08-24 21:49:55 -0400243 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
dea31012005-04-17 16:05:31 -0500244 bpl->tus.w = le32_to_cpu(bpl->tus.w);
245 }
246
James Smartfa4066b2008-01-11 01:53:27 -0500247 /* prevent preparing iocb with NULL ndlp reference */
James Smart51ef4c22007-08-02 11:10:31 -0400248 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -0500249 if (!elsiocb->context1)
250 goto els_iocb_free_pbuf_exit;
James Smart329f9bc2007-04-25 09:53:01 -0400251 elsiocb->context2 = pcmd;
252 elsiocb->context3 = pbuflist;
dea31012005-04-17 16:05:31 -0500253 elsiocb->retry = retry;
James Smart2e0fef82007-06-17 19:56:36 -0500254 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -0500255 elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
256
257 if (prsp) {
258 list_add(&prsp->list, &pcmd->list);
259 }
dea31012005-04-17 16:05:31 -0500260 if (expectRsp) {
261 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400262 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
263 "0116 Xmit ELS command x%x to remote "
264 "NPORT x%x I/O tag: x%x, port state: x%x\n",
265 elscmd, did, elsiocb->iotag,
266 vport->port_state);
dea31012005-04-17 16:05:31 -0500267 } else {
268 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400269 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
270 "0117 Xmit ELS response x%x to remote "
271 "NPORT x%x I/O tag: x%x, size: x%x\n",
272 elscmd, ndlp->nlp_DID, elsiocb->iotag,
273 cmdSize);
dea31012005-04-17 16:05:31 -0500274 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500275 return elsiocb;
dea31012005-04-17 16:05:31 -0500276
James Smartfa4066b2008-01-11 01:53:27 -0500277els_iocb_free_pbuf_exit:
James Smarteaf15d52008-12-04 22:39:29 -0500278 if (expectRsp)
279 lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500280 kfree(pbuflist);
281
282els_iocb_free_prsp_exit:
283 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
284 kfree(prsp);
285
286els_iocb_free_pcmb_exit:
287 kfree(pcmd);
288 lpfc_sli_release_iocbq(phba, elsiocb);
289 return NULL;
290}
dea31012005-04-17 16:05:31 -0500291
James Smarte59058c2008-08-24 21:49:00 -0400292/**
293 * lpfc_issue_fabric_reglogin: Issue fabric registration login for a vport.
294 * @vport: pointer to a host virtual N_Port data structure.
295 *
296 * This routine issues a fabric registration login for a @vport. An
297 * active ndlp node with Fabric_DID must already exist for this @vport.
298 * The routine invokes two mailbox commands to carry out fabric registration
299 * login through the HBA firmware: the first mailbox command requests the
300 * HBA to perform link configuration for the @vport; and the second mailbox
301 * command requests the HBA to perform the actual fabric registration login
302 * with the @vport.
303 *
304 * Return code
305 * 0 - successfully issued fabric registration login for @vport
306 * -ENXIO -- failed to issue fabric registration login for @vport
307 **/
dea31012005-04-17 16:05:31 -0500308static int
James Smart92d7f7b2007-06-17 19:56:38 -0500309lpfc_issue_fabric_reglogin(struct lpfc_vport *vport)
310{
311 struct lpfc_hba *phba = vport->phba;
312 LPFC_MBOXQ_t *mbox;
313 struct lpfc_dmabuf *mp;
314 struct lpfc_nodelist *ndlp;
315 struct serv_parm *sp;
316 int rc;
James Smart98c9ea52007-10-27 13:37:33 -0400317 int err = 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500318
319 sp = &phba->fc_fabparam;
320 ndlp = lpfc_findnode_did(vport, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -0500321 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -0400322 err = 1;
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 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart98c9ea52007-10-27 13:37:33 -0400327 if (!mbox) {
328 err = 2;
James Smart92d7f7b2007-06-17 19:56:38 -0500329 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400330 }
James Smart92d7f7b2007-06-17 19:56:38 -0500331
332 vport->port_state = LPFC_FABRIC_CFG_LINK;
333 lpfc_config_link(phba, mbox);
334 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
335 mbox->vport = vport;
336
James Smart0b727fe2007-10-27 13:37:25 -0400337 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart98c9ea52007-10-27 13:37:33 -0400338 if (rc == MBX_NOT_FINISHED) {
339 err = 3;
James Smart92d7f7b2007-06-17 19:56:38 -0500340 goto fail_free_mbox;
James Smart98c9ea52007-10-27 13:37:33 -0400341 }
James Smart92d7f7b2007-06-17 19:56:38 -0500342
343 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart98c9ea52007-10-27 13:37:33 -0400344 if (!mbox) {
345 err = 4;
James Smart92d7f7b2007-06-17 19:56:38 -0500346 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400347 }
James Smart92d7f7b2007-06-17 19:56:38 -0500348 rc = lpfc_reg_login(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox,
349 0);
James Smart98c9ea52007-10-27 13:37:33 -0400350 if (rc) {
351 err = 5;
James Smart92d7f7b2007-06-17 19:56:38 -0500352 goto fail_free_mbox;
James Smart98c9ea52007-10-27 13:37:33 -0400353 }
James Smart92d7f7b2007-06-17 19:56:38 -0500354
355 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
356 mbox->vport = vport;
James Smarte47c9092008-02-08 18:49:26 -0500357 /* increment the reference count on ndlp to hold reference
358 * for the callback routine.
359 */
James Smart92d7f7b2007-06-17 19:56:38 -0500360 mbox->context2 = lpfc_nlp_get(ndlp);
361
James Smart0b727fe2007-10-27 13:37:25 -0400362 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart98c9ea52007-10-27 13:37:33 -0400363 if (rc == MBX_NOT_FINISHED) {
364 err = 6;
James Smart92d7f7b2007-06-17 19:56:38 -0500365 goto fail_issue_reg_login;
James Smart98c9ea52007-10-27 13:37:33 -0400366 }
James Smart92d7f7b2007-06-17 19:56:38 -0500367
368 return 0;
369
370fail_issue_reg_login:
James Smarte47c9092008-02-08 18:49:26 -0500371 /* decrement the reference count on ndlp just incremented
372 * for the failed mbox command.
373 */
James Smart92d7f7b2007-06-17 19:56:38 -0500374 lpfc_nlp_put(ndlp);
375 mp = (struct lpfc_dmabuf *) mbox->context1;
376 lpfc_mbuf_free(phba, mp->virt, mp->phys);
377 kfree(mp);
378fail_free_mbox:
379 mempool_free(mbox, phba->mbox_mem_pool);
380
381fail:
382 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -0400383 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smart98c9ea52007-10-27 13:37:33 -0400384 "0249 Cannot issue Register Fabric login: Err %d\n", err);
James Smart92d7f7b2007-06-17 19:56:38 -0500385 return -ENXIO;
386}
387
James Smarte59058c2008-08-24 21:49:00 -0400388/**
389 * lpfc_cmpl_els_flogi_fabric: Completion function for flogi to a fabric port.
390 * @vport: pointer to a host virtual N_Port data structure.
391 * @ndlp: pointer to a node-list data structure.
392 * @sp: pointer to service parameter data structure.
393 * @irsp: pointer to the IOCB within the lpfc response IOCB.
394 *
395 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
396 * function to handle the completion of a Fabric Login (FLOGI) into a fabric
397 * port in a fabric topology. It properly sets up the parameters to the @ndlp
398 * from the IOCB response. It also check the newly assigned N_Port ID to the
399 * @vport against the previously assigned N_Port ID. If it is different from
400 * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
401 * is invoked on all the remaining nodes with the @vport to unregister the
402 * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
403 * is invoked to register login to the fabric.
404 *
405 * Return code
406 * 0 - Success (currently, always return 0)
407 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500408static int
James Smart2e0fef82007-06-17 19:56:36 -0500409lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
410 struct serv_parm *sp, IOCB_t *irsp)
dea31012005-04-17 16:05:31 -0500411{
James Smart2e0fef82007-06-17 19:56:36 -0500412 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
413 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -0500414 struct lpfc_nodelist *np;
415 struct lpfc_nodelist *next_np;
dea31012005-04-17 16:05:31 -0500416
James Smart2e0fef82007-06-17 19:56:36 -0500417 spin_lock_irq(shost->host_lock);
418 vport->fc_flag |= FC_FABRIC;
419 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500420
421 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
422 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
423 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
424
425 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
426
427 if (phba->fc_topology == TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500428 spin_lock_irq(shost->host_lock);
429 vport->fc_flag |= FC_PUBLIC_LOOP;
430 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500431 } else {
432 /*
433 * If we are a N-port connected to a Fabric, fixup sparam's so
434 * logins to devices on remote loops work.
435 */
James Smart2e0fef82007-06-17 19:56:36 -0500436 vport->fc_sparam.cmn.altBbCredit = 1;
dea31012005-04-17 16:05:31 -0500437 }
438
James Smart2e0fef82007-06-17 19:56:36 -0500439 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
dea31012005-04-17 16:05:31 -0500440 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
James Smart92d7f7b2007-06-17 19:56:38 -0500441 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500442 ndlp->nlp_class_sup = 0;
443 if (sp->cls1.classValid)
444 ndlp->nlp_class_sup |= FC_COS_CLASS1;
445 if (sp->cls2.classValid)
446 ndlp->nlp_class_sup |= FC_COS_CLASS2;
447 if (sp->cls3.classValid)
448 ndlp->nlp_class_sup |= FC_COS_CLASS3;
449 if (sp->cls4.classValid)
450 ndlp->nlp_class_sup |= FC_COS_CLASS4;
451 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
452 sp->cmn.bbRcvSizeLsb;
453 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
454
James Smart92d7f7b2007-06-17 19:56:38 -0500455 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
456 if (sp->cmn.response_multiple_NPort) {
James Smarte8b62012007-08-02 11:10:09 -0400457 lpfc_printf_vlog(vport, KERN_WARNING,
458 LOG_ELS | LOG_VPORT,
459 "1816 FLOGI NPIV supported, "
460 "response data 0x%x\n",
461 sp->cmn.response_multiple_NPort);
James Smart92d7f7b2007-06-17 19:56:38 -0500462 phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
James Smart92d7f7b2007-06-17 19:56:38 -0500463 } else {
464 /* Because we asked f/w for NPIV it still expects us
James Smarte8b62012007-08-02 11:10:09 -0400465 to call reg_vnpid atleast for the physcial host */
466 lpfc_printf_vlog(vport, KERN_WARNING,
467 LOG_ELS | LOG_VPORT,
468 "1817 Fabric does not support NPIV "
469 "- configuring single port mode.\n");
James Smart92d7f7b2007-06-17 19:56:38 -0500470 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
471 }
472 }
473
474 if ((vport->fc_prevDID != vport->fc_myDID) &&
475 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
476
477 /* If our NportID changed, we need to ensure all
478 * remaining NPORTs get unreg_login'ed.
479 */
480 list_for_each_entry_safe(np, next_np,
481 &vport->fc_nodes, nlp_listp) {
James Smartd7c255b2008-08-24 21:50:00 -0400482 if (!NLP_CHK_NODE_ACT(np))
James Smarte47c9092008-02-08 18:49:26 -0500483 continue;
James Smart92d7f7b2007-06-17 19:56:38 -0500484 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
485 !(np->nlp_flag & NLP_NPR_ADISC))
486 continue;
487 spin_lock_irq(shost->host_lock);
488 np->nlp_flag &= ~NLP_NPR_ADISC;
489 spin_unlock_irq(shost->host_lock);
490 lpfc_unreg_rpi(vport, np);
491 }
492 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
493 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -0500494 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500495 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -0500496 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500497 }
498 }
499
James Smart92d7f7b2007-06-17 19:56:38 -0500500 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -0500501
James Smart92d7f7b2007-06-17 19:56:38 -0500502 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
503 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI) {
504 lpfc_register_new_vport(phba, vport, ndlp);
505 return 0;
506 }
507 lpfc_issue_fabric_reglogin(vport);
dea31012005-04-17 16:05:31 -0500508 return 0;
dea31012005-04-17 16:05:31 -0500509}
510
James Smarte59058c2008-08-24 21:49:00 -0400511/**
512 * lpfc_cmpl_els_flogi_nport: Completion function for flogi to an N_Port.
513 * @vport: pointer to a host virtual N_Port data structure.
514 * @ndlp: pointer to a node-list data structure.
515 * @sp: pointer to service parameter data structure.
516 *
517 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
518 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
519 * in a point-to-point topology. First, the @vport's N_Port Name is compared
520 * with the received N_Port Name: if the @vport's N_Port Name is greater than
521 * the received N_Port Name lexicographically, this node shall assign local
522 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
523 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
524 * this node shall just wait for the remote node to issue PLOGI and assign
525 * N_Port IDs.
526 *
527 * Return code
528 * 0 - Success
529 * -ENXIO - Fail
530 **/
dea31012005-04-17 16:05:31 -0500531static int
James Smart2e0fef82007-06-17 19:56:36 -0500532lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
533 struct serv_parm *sp)
dea31012005-04-17 16:05:31 -0500534{
James Smart2e0fef82007-06-17 19:56:36 -0500535 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
536 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500537 LPFC_MBOXQ_t *mbox;
538 int rc;
539
James Smart2e0fef82007-06-17 19:56:36 -0500540 spin_lock_irq(shost->host_lock);
541 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
542 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500543
544 phba->fc_edtov = FF_DEF_EDTOV;
545 phba->fc_ratov = FF_DEF_RATOV;
James Smart2e0fef82007-06-17 19:56:36 -0500546 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -0500547 sizeof(vport->fc_portname));
dea31012005-04-17 16:05:31 -0500548 if (rc >= 0) {
549 /* This side will initiate the PLOGI */
James Smart2e0fef82007-06-17 19:56:36 -0500550 spin_lock_irq(shost->host_lock);
551 vport->fc_flag |= FC_PT2PT_PLOGI;
552 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500553
554 /*
555 * N_Port ID cannot be 0, set our to LocalID the other
556 * side will be RemoteID.
557 */
558
559 /* not equal */
560 if (rc)
James Smart2e0fef82007-06-17 19:56:36 -0500561 vport->fc_myDID = PT2PT_LocalID;
dea31012005-04-17 16:05:31 -0500562
563 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
564 if (!mbox)
565 goto fail;
566
567 lpfc_config_link(phba, mbox);
568
569 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -0500570 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -0400571 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -0500572 if (rc == MBX_NOT_FINISHED) {
573 mempool_free(mbox, phba->mbox_mem_pool);
574 goto fail;
575 }
James Smarte47c9092008-02-08 18:49:26 -0500576 /* Decrement ndlp reference count indicating that ndlp can be
577 * safely released when other references to it are done.
578 */
James Smart329f9bc2007-04-25 09:53:01 -0400579 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500580
James Smart2e0fef82007-06-17 19:56:36 -0500581 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
dea31012005-04-17 16:05:31 -0500582 if (!ndlp) {
583 /*
584 * Cannot find existing Fabric ndlp, so allocate a
585 * new one
586 */
587 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
588 if (!ndlp)
589 goto fail;
James Smart2e0fef82007-06-17 19:56:36 -0500590 lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID);
James Smarte47c9092008-02-08 18:49:26 -0500591 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
592 ndlp = lpfc_enable_node(vport, ndlp,
593 NLP_STE_UNUSED_NODE);
594 if(!ndlp)
595 goto fail;
dea31012005-04-17 16:05:31 -0500596 }
597
598 memcpy(&ndlp->nlp_portname, &sp->portName,
James Smart2e0fef82007-06-17 19:56:36 -0500599 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500600 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
James Smart2e0fef82007-06-17 19:56:36 -0500601 sizeof(struct lpfc_name));
James Smarte47c9092008-02-08 18:49:26 -0500602 /* Set state will put ndlp onto node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -0500603 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
604 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500605 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500606 spin_unlock_irq(shost->host_lock);
James Smarte47c9092008-02-08 18:49:26 -0500607 } else
608 /* This side will wait for the PLOGI, decrement ndlp reference
609 * count indicating that ndlp can be released when other
610 * references to it are done.
611 */
James Smart329f9bc2007-04-25 09:53:01 -0400612 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500613
James Smart09372822008-01-11 01:52:54 -0500614 /* If we are pt2pt with another NPort, force NPIV off! */
615 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
616
James Smart2e0fef82007-06-17 19:56:36 -0500617 spin_lock_irq(shost->host_lock);
618 vport->fc_flag |= FC_PT2PT;
619 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500620
621 /* Start discovery - this should just do CLEAR_LA */
James Smart2e0fef82007-06-17 19:56:36 -0500622 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -0500623 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500624fail:
dea31012005-04-17 16:05:31 -0500625 return -ENXIO;
626}
627
James Smarte59058c2008-08-24 21:49:00 -0400628/**
629 * lpfc_cmpl_els_flogi: Completion callback function for flogi.
630 * @phba: pointer to lpfc hba data structure.
631 * @cmdiocb: pointer to lpfc command iocb data structure.
632 * @rspiocb: pointer to lpfc response iocb data structure.
633 *
634 * This routine is the top-level completion callback function for issuing
635 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
636 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
637 * retry has been made (either immediately or delayed with lpfc_els_retry()
638 * returning 1), the command IOCB will be released and function returned.
639 * If the retry attempt has been given up (possibly reach the maximum
640 * number of retries), one additional decrement of ndlp reference shall be
641 * invoked before going out after releasing the command IOCB. This will
642 * actually release the remote node (Note, lpfc_els_free_iocb() will also
643 * invoke one decrement of ndlp reference count). If no error reported in
644 * the IOCB status, the command Port ID field is used to determine whether
645 * this is a point-to-point topology or a fabric topology: if the Port ID
646 * field is assigned, it is a fabric topology; otherwise, it is a
647 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
648 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
649 * specific topology completion conditions.
650 **/
dea31012005-04-17 16:05:31 -0500651static void
James Smart329f9bc2007-04-25 09:53:01 -0400652lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
653 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500654{
James Smart2e0fef82007-06-17 19:56:36 -0500655 struct lpfc_vport *vport = cmdiocb->vport;
656 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500657 IOCB_t *irsp = &rspiocb->iocb;
658 struct lpfc_nodelist *ndlp = cmdiocb->context1;
659 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
660 struct serv_parm *sp;
661 int rc;
662
663 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500664 if (lpfc_els_chk_latt(vport)) {
James Smartfa4066b2008-01-11 01:53:27 -0500665 /* One additional decrement on node reference count to
666 * trigger the release of the node
667 */
James Smart329f9bc2007-04-25 09:53:01 -0400668 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500669 goto out;
670 }
671
James Smart858c9f62007-06-17 19:56:39 -0500672 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
673 "FLOGI cmpl: status:x%x/x%x state:x%x",
674 irsp->ulpStatus, irsp->un.ulpWord[4],
675 vport->port_state);
676
dea31012005-04-17 16:05:31 -0500677 if (irsp->ulpStatus) {
678 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -0500679 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -0500680 goto out;
James Smart2e0fef82007-06-17 19:56:36 -0500681
dea31012005-04-17 16:05:31 -0500682 /* FLOGI failed, so there is no fabric */
James Smart2e0fef82007-06-17 19:56:36 -0500683 spin_lock_irq(shost->host_lock);
684 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
685 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500686
James Smart329f9bc2007-04-25 09:53:01 -0400687 /* If private loop, then allow max outstanding els to be
dea31012005-04-17 16:05:31 -0500688 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
689 * alpa map would take too long otherwise.
690 */
691 if (phba->alpa_map[0] == 0) {
James Smart3de2a652007-08-02 11:09:59 -0400692 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
dea31012005-04-17 16:05:31 -0500693 }
694
695 /* FLOGI failure */
James Smarte8b62012007-08-02 11:10:09 -0400696 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
697 "0100 FLOGI failure Data: x%x x%x "
698 "x%x\n",
699 irsp->ulpStatus, irsp->un.ulpWord[4],
700 irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -0500701 goto flogifail;
702 }
703
704 /*
705 * The FLogI succeeded. Sync the data for the CPU before
706 * accessing it.
707 */
708 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
709
710 sp = prsp->virt + sizeof(uint32_t);
711
712 /* FLOGI completes successfully */
James Smarte8b62012007-08-02 11:10:09 -0400713 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
714 "0101 FLOGI completes sucessfully "
715 "Data: x%x x%x x%x x%x\n",
716 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
717 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution);
dea31012005-04-17 16:05:31 -0500718
James Smart2e0fef82007-06-17 19:56:36 -0500719 if (vport->port_state == LPFC_FLOGI) {
dea31012005-04-17 16:05:31 -0500720 /*
721 * If Common Service Parameters indicate Nport
722 * we are point to point, if Fport we are Fabric.
723 */
724 if (sp->cmn.fPort)
James Smart2e0fef82007-06-17 19:56:36 -0500725 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
dea31012005-04-17 16:05:31 -0500726 else
James Smart2e0fef82007-06-17 19:56:36 -0500727 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
dea31012005-04-17 16:05:31 -0500728
729 if (!rc)
730 goto out;
731 }
732
733flogifail:
James Smart329f9bc2007-04-25 09:53:01 -0400734 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500735
James Smart858c9f62007-06-17 19:56:39 -0500736 if (!lpfc_error_lost_link(irsp)) {
dea31012005-04-17 16:05:31 -0500737 /* FLOGI failed, so just use loop map to make discovery list */
James Smart2e0fef82007-06-17 19:56:36 -0500738 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -0500739
740 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500741 lpfc_disc_start(vport);
James Smart87af33f2007-10-27 13:37:43 -0400742 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
743 ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) &&
744 (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) &&
745 (phba->link_state != LPFC_CLEAR_LA)) {
746 /* If FLOGI failed enable link interrupt. */
747 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -0500748 }
dea31012005-04-17 16:05:31 -0500749out:
750 lpfc_els_free_iocb(phba, cmdiocb);
751}
752
James Smarte59058c2008-08-24 21:49:00 -0400753/**
754 * lpfc_issue_els_flogi: Issue an flogi iocb command for a vport.
755 * @vport: pointer to a host virtual N_Port data structure.
756 * @ndlp: pointer to a node-list data structure.
757 * @retry: number of retries to the command IOCB.
758 *
759 * This routine issues a Fabric Login (FLOGI) Request ELS command
760 * for a @vport. The initiator service parameters are put into the payload
761 * of the FLOGI Request IOCB and the top-level callback function pointer
762 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
763 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
764 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
765 *
766 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
767 * will be incremented by 1 for holding the ndlp and the reference to ndlp
768 * will be stored into the context1 field of the IOCB for the completion
769 * callback function to the FLOGI ELS command.
770 *
771 * Return code
772 * 0 - successfully issued flogi iocb for @vport
773 * 1 - failed to issue flogi iocb for @vport
774 **/
dea31012005-04-17 16:05:31 -0500775static int
James Smart2e0fef82007-06-17 19:56:36 -0500776lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -0500777 uint8_t retry)
778{
James Smart2e0fef82007-06-17 19:56:36 -0500779 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500780 struct serv_parm *sp;
781 IOCB_t *icmd;
782 struct lpfc_iocbq *elsiocb;
783 struct lpfc_sli_ring *pring;
784 uint8_t *pcmd;
785 uint16_t cmdsize;
786 uint32_t tmo;
787 int rc;
788
789 pring = &phba->sli.ring[LPFC_ELS_RING];
790
James Smart92d7f7b2007-06-17 19:56:38 -0500791 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart2e0fef82007-06-17 19:56:36 -0500792 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
793 ndlp->nlp_DID, ELS_CMD_FLOGI);
James Smart92d7f7b2007-06-17 19:56:38 -0500794
James Smart488d1462006-03-07 15:02:37 -0500795 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500796 return 1;
dea31012005-04-17 16:05:31 -0500797
798 icmd = &elsiocb->iocb;
799 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
800
801 /* For FLOGI request, remainder of payload is service parameters */
802 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -0500803 pcmd += sizeof(uint32_t);
804 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -0500805 sp = (struct serv_parm *) pcmd;
806
807 /* Setup CSPs accordingly for Fabric */
808 sp->cmn.e_d_tov = 0;
809 sp->cmn.w2.r_a_tov = 0;
810 sp->cls1.classValid = 0;
811 sp->cls2.seqDelivery = 1;
812 sp->cls3.seqDelivery = 1;
813 if (sp->cmn.fcphLow < FC_PH3)
814 sp->cmn.fcphLow = FC_PH3;
815 if (sp->cmn.fcphHigh < FC_PH3)
816 sp->cmn.fcphHigh = FC_PH3;
817
James Smart92d7f7b2007-06-17 19:56:38 -0500818 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
819 sp->cmn.request_multiple_Nport = 1;
820
821 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
822 icmd->ulpCt_h = 1;
823 icmd->ulpCt_l = 0;
824 }
825
James Smart858c9f62007-06-17 19:56:39 -0500826 if (phba->fc_topology != TOPOLOGY_LOOP) {
827 icmd->un.elsreq64.myID = 0;
828 icmd->un.elsreq64.fl = 1;
829 }
830
dea31012005-04-17 16:05:31 -0500831 tmo = phba->fc_ratov;
832 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
James Smart2e0fef82007-06-17 19:56:36 -0500833 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -0500834 phba->fc_ratov = tmo;
835
836 phba->fc_stat.elsXmitFLOGI++;
837 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
James Smart858c9f62007-06-17 19:56:39 -0500838
839 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
840 "Issue FLOGI: opt:x%x",
841 phba->sli3_options, 0, 0);
842
James Smart92d7f7b2007-06-17 19:56:38 -0500843 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
dea31012005-04-17 16:05:31 -0500844 if (rc == IOCB_ERROR) {
845 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500846 return 1;
dea31012005-04-17 16:05:31 -0500847 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500848 return 0;
dea31012005-04-17 16:05:31 -0500849}
850
James Smarte59058c2008-08-24 21:49:00 -0400851/**
852 * lpfc_els_abort_flogi: Abort all outstanding flogi iocbs.
853 * @phba: pointer to lpfc hba data structure.
854 *
855 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
856 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
857 * list and issues an abort IOCB commond on each outstanding IOCB that
858 * contains a active Fabric_DID ndlp. Note that this function is to issue
859 * the abort IOCB command on all the outstanding IOCBs, thus when this
860 * function returns, it does not guarantee all the IOCBs are actually aborted.
861 *
862 * Return code
863 * 0 - Sucessfully issued abort iocb on all outstanding flogis (Always 0)
864 **/
dea31012005-04-17 16:05:31 -0500865int
James Smart2e0fef82007-06-17 19:56:36 -0500866lpfc_els_abort_flogi(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500867{
868 struct lpfc_sli_ring *pring;
869 struct lpfc_iocbq *iocb, *next_iocb;
870 struct lpfc_nodelist *ndlp;
871 IOCB_t *icmd;
872
873 /* Abort outstanding I/O on NPort <nlp_DID> */
874 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -0400875 "0201 Abort outstanding I/O on NPort x%x\n",
876 Fabric_DID);
dea31012005-04-17 16:05:31 -0500877
878 pring = &phba->sli.ring[LPFC_ELS_RING];
879
880 /*
881 * Check the txcmplq for an iocb that matches the nport the driver is
882 * searching for.
883 */
James Smart2e0fef82007-06-17 19:56:36 -0500884 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500885 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
886 icmd = &iocb->iocb;
James Smart2e0fef82007-06-17 19:56:36 -0500887 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR &&
888 icmd->un.elsreq64.bdl.ulpIoTag32) {
dea31012005-04-17 16:05:31 -0500889 ndlp = (struct lpfc_nodelist *)(iocb->context1);
James Smart58da1ff2008-04-07 10:15:56 -0400890 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
891 (ndlp->nlp_DID == Fabric_DID))
James Smart07951072007-04-25 09:51:38 -0400892 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
dea31012005-04-17 16:05:31 -0500893 }
894 }
James Smart2e0fef82007-06-17 19:56:36 -0500895 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500896
897 return 0;
898}
899
James Smarte59058c2008-08-24 21:49:00 -0400900/**
901 * lpfc_initial_flogi: Issue an initial fabric login for a vport.
902 * @vport: pointer to a host virtual N_Port data structure.
903 *
904 * This routine issues an initial Fabric Login (FLOGI) for the @vport
905 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
906 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
907 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
908 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
909 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
910 * @vport.
911 *
912 * Return code
913 * 0 - failed to issue initial flogi for @vport
914 * 1 - successfully issued initial flogi for @vport
915 **/
dea31012005-04-17 16:05:31 -0500916int
James Smart2e0fef82007-06-17 19:56:36 -0500917lpfc_initial_flogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -0500918{
James Smart2e0fef82007-06-17 19:56:36 -0500919 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500920 struct lpfc_nodelist *ndlp;
921
James Smart98c9ea52007-10-27 13:37:33 -0400922 vport->port_state = LPFC_FLOGI;
923 lpfc_set_disctmo(vport);
924
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500925 /* First look for the Fabric ndlp */
James Smart2e0fef82007-06-17 19:56:36 -0500926 ndlp = lpfc_findnode_did(vport, Fabric_DID);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500927 if (!ndlp) {
dea31012005-04-17 16:05:31 -0500928 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500929 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
930 if (!ndlp)
931 return 0;
James Smart2e0fef82007-06-17 19:56:36 -0500932 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -0500933 /* Put ndlp onto node list */
934 lpfc_enqueue_node(vport, ndlp);
935 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
936 /* re-setup ndlp without removing from node list */
937 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
938 if (!ndlp)
939 return 0;
dea31012005-04-17 16:05:31 -0500940 }
James Smart87af33f2007-10-27 13:37:43 -0400941
James Smarte47c9092008-02-08 18:49:26 -0500942 if (lpfc_issue_els_flogi(vport, ndlp, 0))
James Smartfa4066b2008-01-11 01:53:27 -0500943 /* This decrement of reference count to node shall kick off
944 * the release of the node.
945 */
James Smart329f9bc2007-04-25 09:53:01 -0400946 lpfc_nlp_put(ndlp);
James Smarte47c9092008-02-08 18:49:26 -0500947
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500948 return 1;
dea31012005-04-17 16:05:31 -0500949}
950
James Smarte59058c2008-08-24 21:49:00 -0400951/**
952 * lpfc_initial_fdisc: Issue an initial fabric discovery for a vport.
953 * @vport: pointer to a host virtual N_Port data structure.
954 *
955 * This routine issues an initial Fabric Discover (FDISC) for the @vport
956 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
957 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
958 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
959 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
960 * is then invoked with the @vport and the ndlp to perform the FDISC for the
961 * @vport.
962 *
963 * Return code
964 * 0 - failed to issue initial fdisc for @vport
965 * 1 - successfully issued initial fdisc for @vport
966 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500967int
968lpfc_initial_fdisc(struct lpfc_vport *vport)
969{
970 struct lpfc_hba *phba = vport->phba;
971 struct lpfc_nodelist *ndlp;
972
973 /* First look for the Fabric ndlp */
974 ndlp = lpfc_findnode_did(vport, Fabric_DID);
975 if (!ndlp) {
976 /* Cannot find existing Fabric ndlp, so allocate a new one */
977 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
978 if (!ndlp)
979 return 0;
980 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -0500981 /* Put ndlp onto node list */
982 lpfc_enqueue_node(vport, ndlp);
983 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
984 /* re-setup ndlp without removing from node list */
985 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
986 if (!ndlp)
987 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500988 }
James Smarte47c9092008-02-08 18:49:26 -0500989
James Smart92d7f7b2007-06-17 19:56:38 -0500990 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -0500991 /* decrement node reference count to trigger the release of
992 * the node.
993 */
James Smart92d7f7b2007-06-17 19:56:38 -0500994 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -0500995 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500996 }
997 return 1;
998}
James Smart87af33f2007-10-27 13:37:43 -0400999
James Smarte59058c2008-08-24 21:49:00 -04001000/**
1001 * lpfc_more_plogi: Check and issue remaining plogis for a vport.
1002 * @vport: pointer to a host virtual N_Port data structure.
1003 *
1004 * This routine checks whether there are more remaining Port Logins
1005 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1006 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1007 * to issue ELS PLOGIs up to the configured discover threads with the
1008 * @vport (@vport->cfg_discovery_threads). The function also decrement
1009 * the @vport's num_disc_node by 1 if it is not already 0.
1010 **/
James Smart87af33f2007-10-27 13:37:43 -04001011void
James Smart2e0fef82007-06-17 19:56:36 -05001012lpfc_more_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001013{
1014 int sentplogi;
1015
James Smart2e0fef82007-06-17 19:56:36 -05001016 if (vport->num_disc_nodes)
1017 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001018
1019 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
James Smarte8b62012007-08-02 11:10:09 -04001020 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1021 "0232 Continue discovery with %d PLOGIs to go "
1022 "Data: x%x x%x x%x\n",
1023 vport->num_disc_nodes, vport->fc_plogi_cnt,
1024 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001025 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001026 if (vport->fc_flag & FC_NLP_MORE)
1027 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1028 sentplogi = lpfc_els_disc_plogi(vport);
1029
dea31012005-04-17 16:05:31 -05001030 return;
1031}
1032
James Smarte59058c2008-08-24 21:49:00 -04001033/**
1034 * lpfc_plogi_confirm_nport: Confirm pologi wwpn matches stored ndlp.
1035 * @phba: pointer to lpfc hba data structure.
1036 * @prsp: pointer to response IOCB payload.
1037 * @ndlp: pointer to a node-list data structure.
1038 *
1039 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1040 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1041 * The following cases are considered N_Port confirmed:
1042 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1043 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1044 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1045 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1046 * 1) if there is a node on vport list other than the @ndlp with the same
1047 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1048 * on that node to release the RPI associated with the node; 2) if there is
1049 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1050 * into, a new node shall be allocated (or activated). In either case, the
1051 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1052 * be released and the new_ndlp shall be put on to the vport node list and
1053 * its pointer returned as the confirmed node.
1054 *
1055 * Note that before the @ndlp got "released", the keepDID from not-matching
1056 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1057 * of the @ndlp. This is because the release of @ndlp is actually to put it
1058 * into an inactive state on the vport node list and the vport node list
1059 * management algorithm does not allow two node with a same DID.
1060 *
1061 * Return code
1062 * pointer to the PLOGI N_Port @ndlp
1063 **/
James Smart488d1462006-03-07 15:02:37 -05001064static struct lpfc_nodelist *
James Smart92d7f7b2007-06-17 19:56:38 -05001065lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
James Smart488d1462006-03-07 15:02:37 -05001066 struct lpfc_nodelist *ndlp)
1067{
James Smart2e0fef82007-06-17 19:56:36 -05001068 struct lpfc_vport *vport = ndlp->vport;
James Smart488d1462006-03-07 15:02:37 -05001069 struct lpfc_nodelist *new_ndlp;
James Smart0ff10d42008-01-11 01:52:36 -05001070 struct lpfc_rport_data *rdata;
1071 struct fc_rport *rport;
James Smart488d1462006-03-07 15:02:37 -05001072 struct serv_parm *sp;
James Smart92d7f7b2007-06-17 19:56:38 -05001073 uint8_t name[sizeof(struct lpfc_name)];
James Smart58da1ff2008-04-07 10:15:56 -04001074 uint32_t rc, keepDID = 0;
James Smart488d1462006-03-07 15:02:37 -05001075
James Smart2fb9bd82006-12-02 13:33:57 -05001076 /* Fabric nodes can have the same WWPN so we don't bother searching
1077 * by WWPN. Just return the ndlp that was given to us.
1078 */
1079 if (ndlp->nlp_type & NLP_FABRIC)
1080 return ndlp;
1081
James Smart92d7f7b2007-06-17 19:56:38 -05001082 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
James Smart685f0bf2007-04-25 09:53:08 -04001083 memset(name, 0, sizeof(struct lpfc_name));
James Smart488d1462006-03-07 15:02:37 -05001084
James Smart685f0bf2007-04-25 09:53:08 -04001085 /* Now we find out if the NPort we are logging into, matches the WWPN
James Smart488d1462006-03-07 15:02:37 -05001086 * we have for that ndlp. If not, we have some work to do.
1087 */
James Smart2e0fef82007-06-17 19:56:36 -05001088 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
James Smart488d1462006-03-07 15:02:37 -05001089
James Smarte47c9092008-02-08 18:49:26 -05001090 if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
James Smart488d1462006-03-07 15:02:37 -05001091 return ndlp;
James Smart488d1462006-03-07 15:02:37 -05001092
1093 if (!new_ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05001094 rc = memcmp(&ndlp->nlp_portname, name,
1095 sizeof(struct lpfc_name));
James Smart92795652006-07-06 15:50:02 -04001096 if (!rc)
1097 return ndlp;
James Smart488d1462006-03-07 15:02:37 -05001098 new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
1099 if (!new_ndlp)
1100 return ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001101 lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID);
James Smarte47c9092008-02-08 18:49:26 -05001102 } else if (!NLP_CHK_NODE_ACT(new_ndlp)) {
James Smart58da1ff2008-04-07 10:15:56 -04001103 rc = memcmp(&ndlp->nlp_portname, name,
1104 sizeof(struct lpfc_name));
1105 if (!rc)
1106 return ndlp;
James Smarte47c9092008-02-08 18:49:26 -05001107 new_ndlp = lpfc_enable_node(vport, new_ndlp,
1108 NLP_STE_UNUSED_NODE);
1109 if (!new_ndlp)
1110 return ndlp;
James Smart58da1ff2008-04-07 10:15:56 -04001111 keepDID = new_ndlp->nlp_DID;
1112 } else
1113 keepDID = new_ndlp->nlp_DID;
James Smart488d1462006-03-07 15:02:37 -05001114
James Smart2e0fef82007-06-17 19:56:36 -05001115 lpfc_unreg_rpi(vport, new_ndlp);
James Smart488d1462006-03-07 15:02:37 -05001116 new_ndlp->nlp_DID = ndlp->nlp_DID;
James Smart92795652006-07-06 15:50:02 -04001117 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
James Smart0ff10d42008-01-11 01:52:36 -05001118
1119 if (ndlp->nlp_flag & NLP_NPR_2B_DISC)
1120 new_ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1121 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1122
James Smarte47c9092008-02-08 18:49:26 -05001123 /* Set state will put new_ndlp on to node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -05001124 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
James Smart488d1462006-03-07 15:02:37 -05001125
James Smart2e0fef82007-06-17 19:56:36 -05001126 /* Move this back to NPR state */
James Smart87af33f2007-10-27 13:37:43 -04001127 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1128 /* The new_ndlp is replacing ndlp totally, so we need
1129 * to put ndlp on UNUSED list and try to free it.
1130 */
James Smart0ff10d42008-01-11 01:52:36 -05001131
1132 /* Fix up the rport accordingly */
1133 rport = ndlp->rport;
1134 if (rport) {
1135 rdata = rport->dd_data;
1136 if (rdata->pnode == ndlp) {
1137 lpfc_nlp_put(ndlp);
1138 ndlp->rport = NULL;
1139 rdata->pnode = lpfc_nlp_get(new_ndlp);
1140 new_ndlp->rport = rport;
1141 }
1142 new_ndlp->nlp_type = ndlp->nlp_type;
1143 }
James Smart58da1ff2008-04-07 10:15:56 -04001144 /* We shall actually free the ndlp with both nlp_DID and
1145 * nlp_portname fields equals 0 to avoid any ndlp on the
1146 * nodelist never to be used.
1147 */
1148 if (ndlp->nlp_DID == 0) {
1149 spin_lock_irq(&phba->ndlp_lock);
1150 NLP_SET_FREE_REQ(ndlp);
1151 spin_unlock_irq(&phba->ndlp_lock);
1152 }
James Smart0ff10d42008-01-11 01:52:36 -05001153
James Smart58da1ff2008-04-07 10:15:56 -04001154 /* Two ndlps cannot have the same did on the nodelist */
1155 ndlp->nlp_DID = keepDID;
James Smart2e0fef82007-06-17 19:56:36 -05001156 lpfc_drop_node(vport, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04001157 }
James Smart92795652006-07-06 15:50:02 -04001158 else {
James Smart2e0fef82007-06-17 19:56:36 -05001159 lpfc_unreg_rpi(vport, ndlp);
James Smart58da1ff2008-04-07 10:15:56 -04001160 /* Two ndlps cannot have the same did */
1161 ndlp->nlp_DID = keepDID;
James Smart2e0fef82007-06-17 19:56:36 -05001162 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smart92795652006-07-06 15:50:02 -04001163 }
James Smart488d1462006-03-07 15:02:37 -05001164 return new_ndlp;
1165}
1166
James Smarte59058c2008-08-24 21:49:00 -04001167/**
1168 * lpfc_end_rscn: Check and handle more rscn for a vport.
1169 * @vport: pointer to a host virtual N_Port data structure.
1170 *
1171 * This routine checks whether more Registration State Change
1172 * Notifications (RSCNs) came in while the discovery state machine was in
1173 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1174 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1175 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1176 * handling the RSCNs.
1177 **/
James Smart87af33f2007-10-27 13:37:43 -04001178void
1179lpfc_end_rscn(struct lpfc_vport *vport)
1180{
1181 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1182
1183 if (vport->fc_flag & FC_RSCN_MODE) {
1184 /*
1185 * Check to see if more RSCNs came in while we were
1186 * processing this one.
1187 */
1188 if (vport->fc_rscn_id_cnt ||
1189 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1190 lpfc_els_handle_rscn(vport);
1191 else {
1192 spin_lock_irq(shost->host_lock);
1193 vport->fc_flag &= ~FC_RSCN_MODE;
1194 spin_unlock_irq(shost->host_lock);
1195 }
1196 }
1197}
1198
James Smarte59058c2008-08-24 21:49:00 -04001199/**
1200 * lpfc_cmpl_els_plogi: Completion callback function for plogi.
1201 * @phba: pointer to lpfc hba data structure.
1202 * @cmdiocb: pointer to lpfc command iocb data structure.
1203 * @rspiocb: pointer to lpfc response iocb data structure.
1204 *
1205 * This routine is the completion callback function for issuing the Port
1206 * Login (PLOGI) command. For PLOGI completion, there must be an active
1207 * ndlp on the vport node list that matches the remote node ID from the
1208 * PLOGI reponse IOCB. If such ndlp does not exist, the PLOGI is simply
1209 * ignored and command IOCB released. The PLOGI response IOCB status is
1210 * checked for error conditons. If there is error status reported, PLOGI
1211 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1212 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1213 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1214 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1215 * there are additional N_Port nodes with the vport that need to perform
1216 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1217 * PLOGIs.
1218 **/
dea31012005-04-17 16:05:31 -05001219static void
James Smart2e0fef82007-06-17 19:56:36 -05001220lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1221 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001222{
James Smart2e0fef82007-06-17 19:56:36 -05001223 struct lpfc_vport *vport = cmdiocb->vport;
1224 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001225 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001226 struct lpfc_nodelist *ndlp;
James Smart92795652006-07-06 15:50:02 -04001227 struct lpfc_dmabuf *prsp;
dea31012005-04-17 16:05:31 -05001228 int disc, rc, did, type;
1229
dea31012005-04-17 16:05:31 -05001230 /* we pass cmdiocb to state machine which needs rspiocb as well */
1231 cmdiocb->context_un.rsp_iocb = rspiocb;
1232
1233 irsp = &rspiocb->iocb;
James Smart858c9f62007-06-17 19:56:39 -05001234 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1235 "PLOGI cmpl: status:x%x/x%x did:x%x",
1236 irsp->ulpStatus, irsp->un.ulpWord[4],
1237 irsp->un.elsreq64.remoteID);
1238
James Smart2e0fef82007-06-17 19:56:36 -05001239 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
James Smarte47c9092008-02-08 18:49:26 -05001240 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smarte8b62012007-08-02 11:10:09 -04001241 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1242 "0136 PLOGI completes to NPort x%x "
1243 "with no ndlp. Data: x%x x%x x%x\n",
1244 irsp->un.elsreq64.remoteID,
1245 irsp->ulpStatus, irsp->un.ulpWord[4],
1246 irsp->ulpIoTag);
James Smart488d1462006-03-07 15:02:37 -05001247 goto out;
James Smarted957682007-06-17 19:56:37 -05001248 }
dea31012005-04-17 16:05:31 -05001249
1250 /* Since ndlp can be freed in the disc state machine, note if this node
1251 * is being used during discovery.
1252 */
James Smart2e0fef82007-06-17 19:56:36 -05001253 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001254 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
James Smart488d1462006-03-07 15:02:37 -05001255 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001256 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001257 rc = 0;
1258
1259 /* PLOGI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001260 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1261 "0102 PLOGI completes to NPort x%x "
1262 "Data: x%x x%x x%x x%x x%x\n",
1263 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1264 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001265 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001266 if (lpfc_els_chk_latt(vport)) {
1267 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001268 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001269 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001270 goto out;
1271 }
1272
1273 /* ndlp could be freed in DSM, save these values now */
1274 type = ndlp->nlp_type;
1275 did = ndlp->nlp_DID;
1276
1277 if (irsp->ulpStatus) {
1278 /* Check for retry */
1279 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1280 /* ELS command is being retried */
1281 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05001282 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001283 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001284 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001285 }
1286 goto out;
1287 }
dea31012005-04-17 16:05:31 -05001288 /* PLOGI failed */
1289 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001290 if (lpfc_error_lost_link(irsp))
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001291 rc = NLP_STE_FREED_NODE;
James Smarte47c9092008-02-08 18:49:26 -05001292 else
James Smart2e0fef82007-06-17 19:56:36 -05001293 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001294 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001295 } else {
1296 /* Good status, call state machine */
James Smart92795652006-07-06 15:50:02 -04001297 prsp = list_entry(((struct lpfc_dmabuf *)
James Smart92d7f7b2007-06-17 19:56:38 -05001298 cmdiocb->context2)->list.next,
1299 struct lpfc_dmabuf, list);
1300 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05001301 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001302 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001303 }
1304
James Smart2e0fef82007-06-17 19:56:36 -05001305 if (disc && vport->num_disc_nodes) {
dea31012005-04-17 16:05:31 -05001306 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001307 lpfc_more_plogi(vport);
dea31012005-04-17 16:05:31 -05001308
James Smart2e0fef82007-06-17 19:56:36 -05001309 if (vport->num_disc_nodes == 0) {
1310 spin_lock_irq(shost->host_lock);
1311 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1312 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001313
James Smart2e0fef82007-06-17 19:56:36 -05001314 lpfc_can_disctmo(vport);
James Smart87af33f2007-10-27 13:37:43 -04001315 lpfc_end_rscn(vport);
dea31012005-04-17 16:05:31 -05001316 }
1317 }
1318
1319out:
1320 lpfc_els_free_iocb(phba, cmdiocb);
1321 return;
1322}
1323
James Smarte59058c2008-08-24 21:49:00 -04001324/**
1325 * lpfc_issue_els_plogi: Issue an plogi iocb command for a vport.
1326 * @vport: pointer to a host virtual N_Port data structure.
1327 * @did: destination port identifier.
1328 * @retry: number of retries to the command IOCB.
1329 *
1330 * This routine issues a Port Login (PLOGI) command to a remote N_Port
1331 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
1332 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
1333 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
1334 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
1335 *
1336 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1337 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1338 * will be stored into the context1 field of the IOCB for the completion
1339 * callback function to the PLOGI ELS command.
1340 *
1341 * Return code
1342 * 0 - Successfully issued a plogi for @vport
1343 * 1 - failed to issue a plogi for @vport
1344 **/
dea31012005-04-17 16:05:31 -05001345int
James Smart2e0fef82007-06-17 19:56:36 -05001346lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
dea31012005-04-17 16:05:31 -05001347{
James Smart2e0fef82007-06-17 19:56:36 -05001348 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001349 struct serv_parm *sp;
1350 IOCB_t *icmd;
James Smart98c9ea52007-10-27 13:37:33 -04001351 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05001352 struct lpfc_iocbq *elsiocb;
1353 struct lpfc_sli_ring *pring;
1354 struct lpfc_sli *psli;
1355 uint8_t *pcmd;
1356 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05001357 int ret;
dea31012005-04-17 16:05:31 -05001358
1359 psli = &phba->sli;
1360 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1361
James Smart98c9ea52007-10-27 13:37:33 -04001362 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05001363 if (ndlp && !NLP_CHK_NODE_ACT(ndlp))
1364 ndlp = NULL;
James Smart98c9ea52007-10-27 13:37:33 -04001365
James Smarte47c9092008-02-08 18:49:26 -05001366 /* If ndlp is not NULL, we will bump the reference count on it */
James Smart92d7f7b2007-06-17 19:56:38 -05001367 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart98c9ea52007-10-27 13:37:33 -04001368 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
James Smart2e0fef82007-06-17 19:56:36 -05001369 ELS_CMD_PLOGI);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001370 if (!elsiocb)
1371 return 1;
dea31012005-04-17 16:05:31 -05001372
1373 icmd = &elsiocb->iocb;
1374 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1375
1376 /* For PLOGI request, remainder of payload is service parameters */
1377 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001378 pcmd += sizeof(uint32_t);
1379 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001380 sp = (struct serv_parm *) pcmd;
1381
1382 if (sp->cmn.fcphLow < FC_PH_4_3)
1383 sp->cmn.fcphLow = FC_PH_4_3;
1384
1385 if (sp->cmn.fcphHigh < FC_PH3)
1386 sp->cmn.fcphHigh = FC_PH3;
1387
James Smart858c9f62007-06-17 19:56:39 -05001388 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1389 "Issue PLOGI: did:x%x",
1390 did, 0, 0);
1391
dea31012005-04-17 16:05:31 -05001392 phba->fc_stat.elsXmitPLOGI++;
1393 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
James Smart92d7f7b2007-06-17 19:56:38 -05001394 ret = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
1395
1396 if (ret == IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05001397 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001398 return 1;
dea31012005-04-17 16:05:31 -05001399 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001400 return 0;
dea31012005-04-17 16:05:31 -05001401}
1402
James Smarte59058c2008-08-24 21:49:00 -04001403/**
1404 * lpfc_cmpl_els_prli: Completion callback function for prli.
1405 * @phba: pointer to lpfc hba data structure.
1406 * @cmdiocb: pointer to lpfc command iocb data structure.
1407 * @rspiocb: pointer to lpfc response iocb data structure.
1408 *
1409 * This routine is the completion callback function for a Process Login
1410 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
1411 * status. If there is error status reported, PRLI retry shall be attempted
1412 * by invoking the lpfc_els_retry() routine. Otherwise, the state
1413 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
1414 * ndlp to mark the PRLI completion.
1415 **/
dea31012005-04-17 16:05:31 -05001416static void
James Smart2e0fef82007-06-17 19:56:36 -05001417lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1418 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001419{
James Smart2e0fef82007-06-17 19:56:36 -05001420 struct lpfc_vport *vport = cmdiocb->vport;
1421 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001422 IOCB_t *irsp;
1423 struct lpfc_sli *psli;
1424 struct lpfc_nodelist *ndlp;
1425
1426 psli = &phba->sli;
1427 /* we pass cmdiocb to state machine which needs rspiocb as well */
1428 cmdiocb->context_un.rsp_iocb = rspiocb;
1429
1430 irsp = &(rspiocb->iocb);
1431 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
James Smart2e0fef82007-06-17 19:56:36 -05001432 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001433 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001434 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001435
James Smart858c9f62007-06-17 19:56:39 -05001436 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1437 "PRLI cmpl: status:x%x/x%x did:x%x",
1438 irsp->ulpStatus, irsp->un.ulpWord[4],
1439 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05001440 /* PRLI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001441 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1442 "0103 PRLI completes to NPort x%x "
1443 "Data: x%x x%x x%x x%x\n",
1444 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1445 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001446
James Smart2e0fef82007-06-17 19:56:36 -05001447 vport->fc_prli_sent--;
dea31012005-04-17 16:05:31 -05001448 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001449 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05001450 goto out;
1451
1452 if (irsp->ulpStatus) {
1453 /* Check for retry */
1454 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1455 /* ELS command is being retried */
1456 goto out;
1457 }
1458 /* PRLI failed */
1459 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001460 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05001461 goto out;
James Smarte47c9092008-02-08 18:49:26 -05001462 else
James Smart2e0fef82007-06-17 19:56:36 -05001463 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001464 NLP_EVT_CMPL_PRLI);
James Smarte47c9092008-02-08 18:49:26 -05001465 } else
dea31012005-04-17 16:05:31 -05001466 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05001467 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001468 NLP_EVT_CMPL_PRLI);
dea31012005-04-17 16:05:31 -05001469out:
1470 lpfc_els_free_iocb(phba, cmdiocb);
1471 return;
1472}
1473
James Smarte59058c2008-08-24 21:49:00 -04001474/**
1475 * lpfc_issue_els_prli: Issue a prli iocb command for a vport.
1476 * @vport: pointer to a host virtual N_Port data structure.
1477 * @ndlp: pointer to a node-list data structure.
1478 * @retry: number of retries to the command IOCB.
1479 *
1480 * This routine issues a Process Login (PRLI) ELS command for the
1481 * @vport. The PRLI service parameters are set up in the payload of the
1482 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
1483 * is put to the IOCB completion callback func field before invoking the
1484 * routine lpfc_sli_issue_iocb() to send out PRLI command.
1485 *
1486 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1487 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1488 * will be stored into the context1 field of the IOCB for the completion
1489 * callback function to the PRLI ELS command.
1490 *
1491 * Return code
1492 * 0 - successfully issued prli iocb command for @vport
1493 * 1 - failed to issue prli iocb command for @vport
1494 **/
dea31012005-04-17 16:05:31 -05001495int
James Smart2e0fef82007-06-17 19:56:36 -05001496lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001497 uint8_t retry)
1498{
James Smart2e0fef82007-06-17 19:56:36 -05001499 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1500 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001501 PRLI *npr;
1502 IOCB_t *icmd;
1503 struct lpfc_iocbq *elsiocb;
1504 struct lpfc_sli_ring *pring;
1505 struct lpfc_sli *psli;
1506 uint8_t *pcmd;
1507 uint16_t cmdsize;
1508
1509 psli = &phba->sli;
1510 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
1511
James Smart92d7f7b2007-06-17 19:56:38 -05001512 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
James Smart2e0fef82007-06-17 19:56:36 -05001513 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1514 ndlp->nlp_DID, ELS_CMD_PRLI);
James Smart488d1462006-03-07 15:02:37 -05001515 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001516 return 1;
dea31012005-04-17 16:05:31 -05001517
1518 icmd = &elsiocb->iocb;
1519 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1520
1521 /* For PRLI request, remainder of payload is service parameters */
James Smart92d7f7b2007-06-17 19:56:38 -05001522 memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t)));
dea31012005-04-17 16:05:31 -05001523 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
James Smart92d7f7b2007-06-17 19:56:38 -05001524 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001525
1526 /* For PRLI, remainder of payload is PRLI parameter page */
1527 npr = (PRLI *) pcmd;
1528 /*
1529 * If our firmware version is 3.20 or later,
1530 * set the following bits for FC-TAPE support.
1531 */
1532 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
1533 npr->ConfmComplAllowed = 1;
1534 npr->Retry = 1;
1535 npr->TaskRetryIdReq = 1;
1536 }
1537 npr->estabImagePair = 1;
1538 npr->readXferRdyDis = 1;
1539
1540 /* For FCP support */
1541 npr->prliType = PRLI_FCP_TYPE;
1542 npr->initiatorFunc = 1;
1543
James Smart858c9f62007-06-17 19:56:39 -05001544 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1545 "Issue PRLI: did:x%x",
1546 ndlp->nlp_DID, 0, 0);
1547
dea31012005-04-17 16:05:31 -05001548 phba->fc_stat.elsXmitPRLI++;
1549 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
James Smart2e0fef82007-06-17 19:56:36 -05001550 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001551 ndlp->nlp_flag |= NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001552 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001553 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05001554 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001555 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001556 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001557 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001558 return 1;
dea31012005-04-17 16:05:31 -05001559 }
James Smart2e0fef82007-06-17 19:56:36 -05001560 vport->fc_prli_sent++;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001561 return 0;
dea31012005-04-17 16:05:31 -05001562}
1563
James Smarte59058c2008-08-24 21:49:00 -04001564/**
James Smart90160e02008-08-24 21:49:45 -04001565 * lpfc_rscn_disc: Perform rscn discovery for a vport.
1566 * @vport: pointer to a host virtual N_Port data structure.
1567 *
1568 * This routine performs Registration State Change Notification (RSCN)
1569 * discovery for a @vport. If the @vport's node port recovery count is not
1570 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
1571 * the nodes that need recovery. If none of the PLOGI were needed through
1572 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
1573 * invoked to check and handle possible more RSCN came in during the period
1574 * of processing the current ones.
1575 **/
1576static void
1577lpfc_rscn_disc(struct lpfc_vport *vport)
1578{
1579 lpfc_can_disctmo(vport);
1580
1581 /* RSCN discovery */
1582 /* go thru NPR nodes and issue ELS PLOGIs */
1583 if (vport->fc_npr_cnt)
1584 if (lpfc_els_disc_plogi(vport))
1585 return;
1586
1587 lpfc_end_rscn(vport);
1588}
1589
1590/**
1591 * lpfc_adisc_done: Complete the adisc phase of discovery.
1592 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
1593 *
1594 * This function is called when the final ADISC is completed during discovery.
1595 * This function handles clearing link attention or issuing reg_vpi depending
1596 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
1597 * discovery.
1598 * This function is called with no locks held.
1599 **/
1600static void
1601lpfc_adisc_done(struct lpfc_vport *vport)
1602{
1603 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1604 struct lpfc_hba *phba = vport->phba;
1605
1606 /*
1607 * For NPIV, cmpl_reg_vpi will set port_state to READY,
1608 * and continue discovery.
1609 */
1610 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
1611 !(vport->fc_flag & FC_RSCN_MODE)) {
1612 lpfc_issue_reg_vpi(phba, vport);
1613 return;
1614 }
1615 /*
1616 * For SLI2, we need to set port_state to READY
1617 * and continue discovery.
1618 */
1619 if (vport->port_state < LPFC_VPORT_READY) {
1620 /* If we get here, there is nothing to ADISC */
1621 if (vport->port_type == LPFC_PHYSICAL_PORT)
1622 lpfc_issue_clear_la(phba, vport);
1623 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
1624 vport->num_disc_nodes = 0;
1625 /* go thru NPR list, issue ELS PLOGIs */
1626 if (vport->fc_npr_cnt)
1627 lpfc_els_disc_plogi(vport);
1628 if (!vport->num_disc_nodes) {
1629 spin_lock_irq(shost->host_lock);
1630 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1631 spin_unlock_irq(shost->host_lock);
1632 lpfc_can_disctmo(vport);
1633 lpfc_end_rscn(vport);
1634 }
1635 }
1636 vport->port_state = LPFC_VPORT_READY;
1637 } else
1638 lpfc_rscn_disc(vport);
1639}
1640
1641/**
James Smarte59058c2008-08-24 21:49:00 -04001642 * lpfc_more_adisc: Issue more adisc as needed.
1643 * @vport: pointer to a host virtual N_Port data structure.
1644 *
1645 * This routine determines whether there are more ndlps on a @vport
1646 * node list need to have Address Discover (ADISC) issued. If so, it will
1647 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
1648 * remaining nodes which need to have ADISC sent.
1649 **/
James Smart0ff10d42008-01-11 01:52:36 -05001650void
James Smart2e0fef82007-06-17 19:56:36 -05001651lpfc_more_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001652{
1653 int sentadisc;
1654
James Smart2e0fef82007-06-17 19:56:36 -05001655 if (vport->num_disc_nodes)
1656 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001657 /* Continue discovery with <num_disc_nodes> ADISCs to go */
James Smarte8b62012007-08-02 11:10:09 -04001658 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1659 "0210 Continue discovery with %d ADISCs to go "
1660 "Data: x%x x%x x%x\n",
1661 vport->num_disc_nodes, vport->fc_adisc_cnt,
1662 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001663 /* Check to see if there are more ADISCs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001664 if (vport->fc_flag & FC_NLP_MORE) {
1665 lpfc_set_disctmo(vport);
1666 /* go thru NPR nodes and issue any remaining ELS ADISCs */
1667 sentadisc = lpfc_els_disc_adisc(vport);
dea31012005-04-17 16:05:31 -05001668 }
James Smart90160e02008-08-24 21:49:45 -04001669 if (!vport->num_disc_nodes)
1670 lpfc_adisc_done(vport);
dea31012005-04-17 16:05:31 -05001671 return;
1672}
1673
James Smarte59058c2008-08-24 21:49:00 -04001674/**
James Smarte59058c2008-08-24 21:49:00 -04001675 * lpfc_cmpl_els_adisc: Completion callback function for adisc.
1676 * @phba: pointer to lpfc hba data structure.
1677 * @cmdiocb: pointer to lpfc command iocb data structure.
1678 * @rspiocb: pointer to lpfc response iocb data structure.
1679 *
1680 * This routine is the completion function for issuing the Address Discover
1681 * (ADISC) command. It first checks to see whether link went down during
1682 * the discovery process. If so, the node will be marked as node port
1683 * recovery for issuing discover IOCB by the link attention handler and
1684 * exit. Otherwise, the response status is checked. If error was reported
1685 * in the response status, the ADISC command shall be retried by invoking
1686 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
1687 * the response status, the state machine is invoked to set transition
1688 * with respect to NLP_EVT_CMPL_ADISC event.
1689 **/
dea31012005-04-17 16:05:31 -05001690static void
James Smart2e0fef82007-06-17 19:56:36 -05001691lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1692 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001693{
James Smart2e0fef82007-06-17 19:56:36 -05001694 struct lpfc_vport *vport = cmdiocb->vport;
1695 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001696 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001697 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001698 int disc;
dea31012005-04-17 16:05:31 -05001699
1700 /* we pass cmdiocb to state machine which needs rspiocb as well */
1701 cmdiocb->context_un.rsp_iocb = rspiocb;
1702
1703 irsp = &(rspiocb->iocb);
1704 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
dea31012005-04-17 16:05:31 -05001705
James Smart858c9f62007-06-17 19:56:39 -05001706 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1707 "ADISC cmpl: status:x%x/x%x did:x%x",
1708 irsp->ulpStatus, irsp->un.ulpWord[4],
1709 ndlp->nlp_DID);
1710
dea31012005-04-17 16:05:31 -05001711 /* Since ndlp can be freed in the disc state machine, note if this node
1712 * is being used during discovery.
1713 */
James Smart2e0fef82007-06-17 19:56:36 -05001714 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001715 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001716 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001717 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001718 /* ADISC completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001719 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1720 "0104 ADISC completes to NPort x%x "
1721 "Data: x%x x%x x%x x%x x%x\n",
1722 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1723 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001724 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001725 if (lpfc_els_chk_latt(vport)) {
1726 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001727 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001728 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001729 goto out;
1730 }
1731
1732 if (irsp->ulpStatus) {
1733 /* Check for retry */
1734 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1735 /* ELS command is being retried */
1736 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05001737 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001738 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001739 spin_unlock_irq(shost->host_lock);
1740 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001741 }
1742 goto out;
1743 }
1744 /* ADISC failed */
1745 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001746 if (!lpfc_error_lost_link(irsp))
James Smart2e0fef82007-06-17 19:56:36 -05001747 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart858c9f62007-06-17 19:56:39 -05001748 NLP_EVT_CMPL_ADISC);
James Smarte47c9092008-02-08 18:49:26 -05001749 } else
dea31012005-04-17 16:05:31 -05001750 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05001751 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
dea31012005-04-17 16:05:31 -05001752 NLP_EVT_CMPL_ADISC);
dea31012005-04-17 16:05:31 -05001753
James Smart90160e02008-08-24 21:49:45 -04001754 /* Check to see if there are more ADISCs to be sent */
1755 if (disc && vport->num_disc_nodes)
James Smart2e0fef82007-06-17 19:56:36 -05001756 lpfc_more_adisc(vport);
dea31012005-04-17 16:05:31 -05001757out:
1758 lpfc_els_free_iocb(phba, cmdiocb);
1759 return;
1760}
1761
James Smarte59058c2008-08-24 21:49:00 -04001762/**
1763 * lpfc_issue_els_adisc: Issue an address discover iocb to an node on a vport.
1764 * @vport: pointer to a virtual N_Port data structure.
1765 * @ndlp: pointer to a node-list data structure.
1766 * @retry: number of retries to the command IOCB.
1767 *
1768 * This routine issues an Address Discover (ADISC) for an @ndlp on a
1769 * @vport. It prepares the payload of the ADISC ELS command, updates the
1770 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
1771 * to issue the ADISC ELS command.
1772 *
1773 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1774 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1775 * will be stored into the context1 field of the IOCB for the completion
1776 * callback function to the ADISC ELS command.
1777 *
1778 * Return code
1779 * 0 - successfully issued adisc
1780 * 1 - failed to issue adisc
1781 **/
dea31012005-04-17 16:05:31 -05001782int
James Smart2e0fef82007-06-17 19:56:36 -05001783lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001784 uint8_t retry)
1785{
James Smart2e0fef82007-06-17 19:56:36 -05001786 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1787 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001788 ADISC *ap;
1789 IOCB_t *icmd;
1790 struct lpfc_iocbq *elsiocb;
James Smart2e0fef82007-06-17 19:56:36 -05001791 struct lpfc_sli *psli = &phba->sli;
1792 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05001793 uint8_t *pcmd;
1794 uint16_t cmdsize;
1795
James Smart92d7f7b2007-06-17 19:56:38 -05001796 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
James Smart2e0fef82007-06-17 19:56:36 -05001797 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1798 ndlp->nlp_DID, ELS_CMD_ADISC);
James Smart488d1462006-03-07 15:02:37 -05001799 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001800 return 1;
dea31012005-04-17 16:05:31 -05001801
1802 icmd = &elsiocb->iocb;
1803 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1804
1805 /* For ADISC request, remainder of payload is service parameters */
1806 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
James Smart92d7f7b2007-06-17 19:56:38 -05001807 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001808
1809 /* Fill in ADISC payload */
1810 ap = (ADISC *) pcmd;
1811 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05001812 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
1813 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05001814 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05001815
James Smart858c9f62007-06-17 19:56:39 -05001816 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1817 "Issue ADISC: did:x%x",
1818 ndlp->nlp_DID, 0, 0);
1819
dea31012005-04-17 16:05:31 -05001820 phba->fc_stat.elsXmitADISC++;
1821 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
James Smart2e0fef82007-06-17 19:56:36 -05001822 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001823 ndlp->nlp_flag |= NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001824 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001825 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05001826 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001827 ndlp->nlp_flag &= ~NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001828 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001829 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001830 return 1;
dea31012005-04-17 16:05:31 -05001831 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001832 return 0;
dea31012005-04-17 16:05:31 -05001833}
1834
James Smarte59058c2008-08-24 21:49:00 -04001835/**
1836 * lpfc_cmpl_els_logo: Completion callback function for logo.
1837 * @phba: pointer to lpfc hba data structure.
1838 * @cmdiocb: pointer to lpfc command iocb data structure.
1839 * @rspiocb: pointer to lpfc response iocb data structure.
1840 *
1841 * This routine is the completion function for issuing the ELS Logout (LOGO)
1842 * command. If no error status was reported from the LOGO response, the
1843 * state machine of the associated ndlp shall be invoked for transition with
1844 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
1845 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
1846 **/
dea31012005-04-17 16:05:31 -05001847static void
James Smart2e0fef82007-06-17 19:56:36 -05001848lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1849 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001850{
James Smart2e0fef82007-06-17 19:56:36 -05001851 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1852 struct lpfc_vport *vport = ndlp->vport;
1853 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001854 IOCB_t *irsp;
1855 struct lpfc_sli *psli;
dea31012005-04-17 16:05:31 -05001856
1857 psli = &phba->sli;
1858 /* we pass cmdiocb to state machine which needs rspiocb as well */
1859 cmdiocb->context_un.rsp_iocb = rspiocb;
1860
1861 irsp = &(rspiocb->iocb);
James Smart2e0fef82007-06-17 19:56:36 -05001862 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001863 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001864 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001865
James Smart858c9f62007-06-17 19:56:39 -05001866 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1867 "LOGO cmpl: status:x%x/x%x did:x%x",
1868 irsp->ulpStatus, irsp->un.ulpWord[4],
1869 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05001870 /* LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001871 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1872 "0105 LOGO completes to NPort x%x "
1873 "Data: x%x x%x x%x x%x\n",
1874 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1875 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001876 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001877 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05001878 goto out;
1879
James Smart92d7f7b2007-06-17 19:56:38 -05001880 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
1881 /* NLP_EVT_DEVICE_RM should unregister the RPI
1882 * which should abort all outstanding IOs.
1883 */
1884 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
1885 NLP_EVT_DEVICE_RM);
1886 goto out;
1887 }
1888
dea31012005-04-17 16:05:31 -05001889 if (irsp->ulpStatus) {
1890 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -05001891 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -05001892 /* ELS command is being retried */
1893 goto out;
dea31012005-04-17 16:05:31 -05001894 /* LOGO failed */
1895 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart858c9f62007-06-17 19:56:39 -05001896 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05001897 goto out;
James Smart858c9f62007-06-17 19:56:39 -05001898 else
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);
James Smarte47c9092008-02-08 18:49:26 -05001901 } else
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001902 /* Good status, call state machine.
1903 * This will unregister the rpi if needed.
1904 */
James Smart2e0fef82007-06-17 19:56:36 -05001905 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001906 NLP_EVT_CMPL_LOGO);
dea31012005-04-17 16:05:31 -05001907out:
1908 lpfc_els_free_iocb(phba, cmdiocb);
1909 return;
1910}
1911
James Smarte59058c2008-08-24 21:49:00 -04001912/**
1913 * lpfc_issue_els_logo: Issue a logo to an node on a vport.
1914 * @vport: pointer to a virtual N_Port data structure.
1915 * @ndlp: pointer to a node-list data structure.
1916 * @retry: number of retries to the command IOCB.
1917 *
1918 * This routine constructs and issues an ELS Logout (LOGO) iocb command
1919 * to a remote node, referred by an @ndlp on a @vport. It constructs the
1920 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
1921 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
1922 *
1923 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1924 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1925 * will be stored into the context1 field of the IOCB for the completion
1926 * callback function to the LOGO ELS command.
1927 *
1928 * Return code
1929 * 0 - successfully issued logo
1930 * 1 - failed to issue logo
1931 **/
dea31012005-04-17 16:05:31 -05001932int
James Smart2e0fef82007-06-17 19:56:36 -05001933lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001934 uint8_t retry)
1935{
James Smart2e0fef82007-06-17 19:56:36 -05001936 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1937 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001938 IOCB_t *icmd;
1939 struct lpfc_iocbq *elsiocb;
1940 struct lpfc_sli_ring *pring;
1941 struct lpfc_sli *psli;
1942 uint8_t *pcmd;
1943 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05001944 int rc;
dea31012005-04-17 16:05:31 -05001945
1946 psli = &phba->sli;
1947 pring = &psli->ring[LPFC_ELS_RING];
1948
James Smart98c9ea52007-10-27 13:37:33 -04001949 spin_lock_irq(shost->host_lock);
1950 if (ndlp->nlp_flag & NLP_LOGO_SND) {
1951 spin_unlock_irq(shost->host_lock);
1952 return 0;
1953 }
1954 spin_unlock_irq(shost->host_lock);
1955
James Smart92d7f7b2007-06-17 19:56:38 -05001956 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
James Smart2e0fef82007-06-17 19:56:36 -05001957 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1958 ndlp->nlp_DID, ELS_CMD_LOGO);
James Smart488d1462006-03-07 15:02:37 -05001959 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001960 return 1;
dea31012005-04-17 16:05:31 -05001961
1962 icmd = &elsiocb->iocb;
1963 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1964 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
James Smart92d7f7b2007-06-17 19:56:38 -05001965 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001966
1967 /* Fill in LOGO payload */
James Smart2e0fef82007-06-17 19:56:36 -05001968 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05001969 pcmd += sizeof(uint32_t);
1970 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05001971
James Smart858c9f62007-06-17 19:56:39 -05001972 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1973 "Issue LOGO: did:x%x",
1974 ndlp->nlp_DID, 0, 0);
1975
dea31012005-04-17 16:05:31 -05001976 phba->fc_stat.elsXmitLOGO++;
1977 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
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);
James Smart92d7f7b2007-06-17 19:56:38 -05001981 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
1982
1983 if (rc == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05001984 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001985 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001986 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001987 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001988 return 1;
dea31012005-04-17 16:05:31 -05001989 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001990 return 0;
dea31012005-04-17 16:05:31 -05001991}
1992
James Smarte59058c2008-08-24 21:49:00 -04001993/**
1994 * lpfc_cmpl_els_cmd: Completion callback function for generic els command.
1995 * @phba: pointer to lpfc hba data structure.
1996 * @cmdiocb: pointer to lpfc command iocb data structure.
1997 * @rspiocb: pointer to lpfc response iocb data structure.
1998 *
1999 * This routine is a generic completion callback function for ELS commands.
2000 * Specifically, it is the callback function which does not need to perform
2001 * any command specific operations. It is currently used by the ELS command
2002 * issuing routines for the ELS State Change Request (SCR),
2003 * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
2004 * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
2005 * certain debug loggings, this callback function simply invokes the
2006 * lpfc_els_chk_latt() routine to check whether link went down during the
2007 * discovery process.
2008 **/
dea31012005-04-17 16:05:31 -05002009static void
James Smart2e0fef82007-06-17 19:56:36 -05002010lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2011 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002012{
James Smart2e0fef82007-06-17 19:56:36 -05002013 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -05002014 IOCB_t *irsp;
2015
2016 irsp = &rspiocb->iocb;
2017
James Smart858c9f62007-06-17 19:56:39 -05002018 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2019 "ELS cmd cmpl: status:x%x/x%x did:x%x",
2020 irsp->ulpStatus, irsp->un.ulpWord[4],
2021 irsp->un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05002022 /* ELS cmd tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04002023 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2024 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
2025 irsp->ulpIoTag, irsp->ulpStatus,
2026 irsp->un.ulpWord[4], irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -05002027 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002028 lpfc_els_chk_latt(vport);
dea31012005-04-17 16:05:31 -05002029 lpfc_els_free_iocb(phba, cmdiocb);
2030 return;
2031}
2032
James Smarte59058c2008-08-24 21:49:00 -04002033/**
2034 * lpfc_issue_els_scr: Issue a scr to an node on a vport.
2035 * @vport: pointer to a host virtual N_Port data structure.
2036 * @nportid: N_Port identifier to the remote node.
2037 * @retry: number of retries to the command IOCB.
2038 *
2039 * This routine issues a State Change Request (SCR) to a fabric node
2040 * on a @vport. The remote node @nportid is passed into the function. It
2041 * first search the @vport node list to find the matching ndlp. If no such
2042 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
2043 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
2044 * routine is invoked to send the SCR IOCB.
2045 *
2046 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2047 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2048 * will be stored into the context1 field of the IOCB for the completion
2049 * callback function to the SCR ELS command.
2050 *
2051 * Return code
2052 * 0 - Successfully issued scr command
2053 * 1 - Failed to issue scr command
2054 **/
dea31012005-04-17 16:05:31 -05002055int
James Smart2e0fef82007-06-17 19:56:36 -05002056lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002057{
James Smart2e0fef82007-06-17 19:56:36 -05002058 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002059 IOCB_t *icmd;
2060 struct lpfc_iocbq *elsiocb;
2061 struct lpfc_sli_ring *pring;
2062 struct lpfc_sli *psli;
2063 uint8_t *pcmd;
2064 uint16_t cmdsize;
2065 struct lpfc_nodelist *ndlp;
2066
2067 psli = &phba->sli;
2068 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
James Smart92d7f7b2007-06-17 19:56:38 -05002069 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
dea31012005-04-17 16:05:31 -05002070
James Smarte47c9092008-02-08 18:49:26 -05002071 ndlp = lpfc_findnode_did(vport, nportid);
2072 if (!ndlp) {
2073 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2074 if (!ndlp)
2075 return 1;
2076 lpfc_nlp_init(vport, ndlp, nportid);
2077 lpfc_enqueue_node(vport, ndlp);
2078 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2079 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2080 if (!ndlp)
2081 return 1;
2082 }
dea31012005-04-17 16:05:31 -05002083
James Smart2e0fef82007-06-17 19:56:36 -05002084 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2085 ndlp->nlp_DID, ELS_CMD_SCR);
2086
James Smart488d1462006-03-07 15:02:37 -05002087 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002088 /* This will trigger the release of the node just
2089 * allocated
2090 */
James Smart329f9bc2007-04-25 09:53:01 -04002091 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002092 return 1;
dea31012005-04-17 16:05:31 -05002093 }
2094
2095 icmd = &elsiocb->iocb;
2096 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2097
2098 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
James Smart92d7f7b2007-06-17 19:56:38 -05002099 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002100
2101 /* For SCR, remainder of payload is SCR parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05002102 memset(pcmd, 0, sizeof(SCR));
dea31012005-04-17 16:05:31 -05002103 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
2104
James Smart858c9f62007-06-17 19:56:39 -05002105 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2106 "Issue SCR: did:x%x",
2107 ndlp->nlp_DID, 0, 0);
2108
dea31012005-04-17 16:05:31 -05002109 phba->fc_stat.elsXmitSCR++;
2110 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
dea31012005-04-17 16:05:31 -05002111 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002112 /* The additional lpfc_nlp_put will cause the following
2113 * lpfc_els_free_iocb routine to trigger the rlease of
2114 * the node.
2115 */
James Smart329f9bc2007-04-25 09:53:01 -04002116 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002117 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002118 return 1;
dea31012005-04-17 16:05:31 -05002119 }
James Smartfa4066b2008-01-11 01:53:27 -05002120 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2121 * trigger the release of node.
2122 */
James Smart329f9bc2007-04-25 09:53:01 -04002123 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002124 return 0;
dea31012005-04-17 16:05:31 -05002125}
2126
James Smarte59058c2008-08-24 21:49:00 -04002127/**
2128 * lpfc_issue_els_farpr: Issue a farp to an node on a vport.
2129 * @vport: pointer to a host virtual N_Port data structure.
2130 * @nportid: N_Port identifier to the remote node.
2131 * @retry: number of retries to the command IOCB.
2132 *
2133 * This routine issues a Fibre Channel Address Resolution Response
2134 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
2135 * is passed into the function. It first search the @vport node list to find
2136 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
2137 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
2138 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
2139 *
2140 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2141 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2142 * will be stored into the context1 field of the IOCB for the completion
2143 * callback function to the PARPR ELS command.
2144 *
2145 * Return code
2146 * 0 - Successfully issued farpr command
2147 * 1 - Failed to issue farpr command
2148 **/
dea31012005-04-17 16:05:31 -05002149static int
James Smart2e0fef82007-06-17 19:56:36 -05002150lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002151{
James Smart2e0fef82007-06-17 19:56:36 -05002152 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002153 IOCB_t *icmd;
2154 struct lpfc_iocbq *elsiocb;
2155 struct lpfc_sli_ring *pring;
2156 struct lpfc_sli *psli;
2157 FARP *fp;
2158 uint8_t *pcmd;
2159 uint32_t *lp;
2160 uint16_t cmdsize;
2161 struct lpfc_nodelist *ondlp;
2162 struct lpfc_nodelist *ndlp;
2163
2164 psli = &phba->sli;
2165 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
James Smart92d7f7b2007-06-17 19:56:38 -05002166 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
dea31012005-04-17 16:05:31 -05002167
James Smarte47c9092008-02-08 18:49:26 -05002168 ndlp = lpfc_findnode_did(vport, nportid);
2169 if (!ndlp) {
2170 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2171 if (!ndlp)
2172 return 1;
2173 lpfc_nlp_init(vport, ndlp, nportid);
2174 lpfc_enqueue_node(vport, ndlp);
2175 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2176 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2177 if (!ndlp)
2178 return 1;
2179 }
James Smart2e0fef82007-06-17 19:56:36 -05002180
2181 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2182 ndlp->nlp_DID, ELS_CMD_RNID);
James Smart488d1462006-03-07 15:02:37 -05002183 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002184 /* This will trigger the release of the node just
2185 * allocated
2186 */
James Smart329f9bc2007-04-25 09:53:01 -04002187 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002188 return 1;
dea31012005-04-17 16:05:31 -05002189 }
2190
2191 icmd = &elsiocb->iocb;
2192 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2193
2194 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
James Smart92d7f7b2007-06-17 19:56:38 -05002195 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002196
2197 /* Fill in FARPR payload */
2198 fp = (FARP *) (pcmd);
James Smart92d7f7b2007-06-17 19:56:38 -05002199 memset(fp, 0, sizeof(FARP));
dea31012005-04-17 16:05:31 -05002200 lp = (uint32_t *) pcmd;
2201 *lp++ = be32_to_cpu(nportid);
James Smart2e0fef82007-06-17 19:56:36 -05002202 *lp++ = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002203 fp->Rflags = 0;
2204 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
2205
James Smart92d7f7b2007-06-17 19:56:38 -05002206 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
2207 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002208 ondlp = lpfc_findnode_did(vport, nportid);
James Smarte47c9092008-02-08 18:49:26 -05002209 if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
dea31012005-04-17 16:05:31 -05002210 memcpy(&fp->OportName, &ondlp->nlp_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05002211 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002212 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05002213 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002214 }
2215
James Smart858c9f62007-06-17 19:56:39 -05002216 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2217 "Issue FARPR: did:x%x",
2218 ndlp->nlp_DID, 0, 0);
2219
dea31012005-04-17 16:05:31 -05002220 phba->fc_stat.elsXmitFARPR++;
2221 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
dea31012005-04-17 16:05:31 -05002222 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002223 /* The additional lpfc_nlp_put will cause the following
2224 * lpfc_els_free_iocb routine to trigger the release of
2225 * the node.
2226 */
James Smart329f9bc2007-04-25 09:53:01 -04002227 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002228 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002229 return 1;
dea31012005-04-17 16:05:31 -05002230 }
James Smartfa4066b2008-01-11 01:53:27 -05002231 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2232 * trigger the release of the node.
2233 */
James Smart329f9bc2007-04-25 09:53:01 -04002234 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002235 return 0;
dea31012005-04-17 16:05:31 -05002236}
2237
James Smarte59058c2008-08-24 21:49:00 -04002238/**
2239 * lpfc_cancel_retry_delay_tmo: Cancel the timer with delayed iocb-cmd retry.
2240 * @vport: pointer to a host virtual N_Port data structure.
2241 * @nlp: pointer to a node-list data structure.
2242 *
2243 * This routine cancels the timer with a delayed IOCB-command retry for
2244 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
2245 * removes the ELS retry event if it presents. In addition, if the
2246 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
2247 * commands are sent for the @vport's nodes that require issuing discovery
2248 * ADISC.
2249 **/
dea31012005-04-17 16:05:31 -05002250void
James Smart2e0fef82007-06-17 19:56:36 -05002251lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
James Smartfdcebe22006-03-07 15:04:01 -05002252{
James Smart2e0fef82007-06-17 19:56:36 -05002253 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smarte47c9092008-02-08 18:49:26 -05002254 struct lpfc_work_evt *evtp;
James Smart2e0fef82007-06-17 19:56:36 -05002255
James Smart0d2b6b82008-06-14 22:52:47 -04002256 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
2257 return;
James Smart2e0fef82007-06-17 19:56:36 -05002258 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002259 nlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002260 spin_unlock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002261 del_timer_sync(&nlp->nlp_delayfunc);
2262 nlp->nlp_last_elscmd = 0;
James Smarte47c9092008-02-08 18:49:26 -05002263 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
James Smartfdcebe22006-03-07 15:04:01 -05002264 list_del_init(&nlp->els_retry_evt.evt_listp);
James Smarte47c9092008-02-08 18:49:26 -05002265 /* Decrement nlp reference count held for the delayed retry */
2266 evtp = &nlp->els_retry_evt;
2267 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
2268 }
James Smartfdcebe22006-03-07 15:04:01 -05002269 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
James Smart2e0fef82007-06-17 19:56:36 -05002270 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002271 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002272 spin_unlock_irq(shost->host_lock);
2273 if (vport->num_disc_nodes) {
James Smart0d2b6b82008-06-14 22:52:47 -04002274 if (vport->port_state < LPFC_VPORT_READY) {
2275 /* Check if there are more ADISCs to be sent */
2276 lpfc_more_adisc(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04002277 } else {
2278 /* Check if there are more PLOGIs to be sent */
2279 lpfc_more_plogi(vport);
James Smart90160e02008-08-24 21:49:45 -04002280 if (vport->num_disc_nodes == 0) {
2281 spin_lock_irq(shost->host_lock);
2282 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2283 spin_unlock_irq(shost->host_lock);
2284 lpfc_can_disctmo(vport);
2285 lpfc_end_rscn(vport);
2286 }
James Smartfdcebe22006-03-07 15:04:01 -05002287 }
2288 }
2289 }
2290 return;
2291}
2292
James Smarte59058c2008-08-24 21:49:00 -04002293/**
2294 * lpfc_els_retry_delay: Timer function with a ndlp delayed function timer.
2295 * @ptr: holder for the pointer to the timer function associated data (ndlp).
2296 *
2297 * This routine is invoked by the ndlp delayed-function timer to check
2298 * whether there is any pending ELS retry event(s) with the node. If not, it
2299 * simply returns. Otherwise, if there is at least one ELS delayed event, it
2300 * adds the delayed events to the HBA work list and invokes the
2301 * lpfc_worker_wake_up() routine to wake up worker thread to process the
2302 * event. Note that lpfc_nlp_get() is called before posting the event to
2303 * the work list to hold reference count of ndlp so that it guarantees the
2304 * reference to ndlp will still be available when the worker thread gets
2305 * to the event associated with the ndlp.
2306 **/
James Smartfdcebe22006-03-07 15:04:01 -05002307void
dea31012005-04-17 16:05:31 -05002308lpfc_els_retry_delay(unsigned long ptr)
2309{
James Smart2e0fef82007-06-17 19:56:36 -05002310 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
2311 struct lpfc_vport *vport = ndlp->vport;
James Smart2e0fef82007-06-17 19:56:36 -05002312 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05002313 unsigned long flags;
James Smart2e0fef82007-06-17 19:56:36 -05002314 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
dea31012005-04-17 16:05:31 -05002315
James Smart92d7f7b2007-06-17 19:56:38 -05002316 spin_lock_irqsave(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002317 if (!list_empty(&evtp->evt_listp)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002318 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002319 return;
2320 }
2321
James Smartfa4066b2008-01-11 01:53:27 -05002322 /* We need to hold the node by incrementing the reference
2323 * count until the queued work is done
2324 */
2325 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
James Smart5e9d9b82008-06-14 22:52:53 -04002326 if (evtp->evt_arg1) {
2327 evtp->evt = LPFC_EVT_ELS_RETRY;
2328 list_add_tail(&evtp->evt_listp, &phba->work_list);
James Smart92d7f7b2007-06-17 19:56:38 -05002329 lpfc_worker_wake_up(phba);
James Smart5e9d9b82008-06-14 22:52:53 -04002330 }
James Smart92d7f7b2007-06-17 19:56:38 -05002331 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002332 return;
2333}
2334
James Smarte59058c2008-08-24 21:49:00 -04002335/**
2336 * lpfc_els_retry_delay_handler: Work thread handler for ndlp delayed function.
2337 * @ndlp: pointer to a node-list data structure.
2338 *
2339 * This routine is the worker-thread handler for processing the @ndlp delayed
2340 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
2341 * the last ELS command from the associated ndlp and invokes the proper ELS
2342 * function according to the delayed ELS command to retry the command.
2343 **/
dea31012005-04-17 16:05:31 -05002344void
2345lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
2346{
James Smart2e0fef82007-06-17 19:56:36 -05002347 struct lpfc_vport *vport = ndlp->vport;
2348 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2349 uint32_t cmd, did, retry;
dea31012005-04-17 16:05:31 -05002350
James Smart2e0fef82007-06-17 19:56:36 -05002351 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002352 did = ndlp->nlp_DID;
2353 cmd = ndlp->nlp_last_elscmd;
2354 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05002355
2356 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
James Smart2e0fef82007-06-17 19:56:36 -05002357 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002358 return;
2359 }
2360
2361 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002362 spin_unlock_irq(shost->host_lock);
James Smart1a169682006-03-07 15:04:06 -05002363 /*
2364 * If a discovery event readded nlp_delayfunc after timer
2365 * firing and before processing the timer, cancel the
2366 * nlp_delayfunc.
2367 */
2368 del_timer_sync(&ndlp->nlp_delayfunc);
dea31012005-04-17 16:05:31 -05002369 retry = ndlp->nlp_retry;
2370
2371 switch (cmd) {
2372 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002373 lpfc_issue_els_flogi(vport, ndlp, retry);
dea31012005-04-17 16:05:31 -05002374 break;
2375 case ELS_CMD_PLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002376 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 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_PLOGI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002379 }
dea31012005-04-17 16:05:31 -05002380 break;
2381 case ELS_CMD_ADISC:
James Smart2e0fef82007-06-17 19:56:36 -05002382 if (!lpfc_issue_els_adisc(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_ADISC_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002385 }
dea31012005-04-17 16:05:31 -05002386 break;
2387 case ELS_CMD_PRLI:
James Smart2e0fef82007-06-17 19:56:36 -05002388 if (!lpfc_issue_els_prli(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_PRLI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002391 }
dea31012005-04-17 16:05:31 -05002392 break;
2393 case ELS_CMD_LOGO:
James Smart2e0fef82007-06-17 19:56:36 -05002394 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002395 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002396 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002397 }
dea31012005-04-17 16:05:31 -05002398 break;
James Smart92d7f7b2007-06-17 19:56:38 -05002399 case ELS_CMD_FDISC:
2400 lpfc_issue_els_fdisc(vport, ndlp, retry);
2401 break;
dea31012005-04-17 16:05:31 -05002402 }
2403 return;
2404}
2405
James Smarte59058c2008-08-24 21:49:00 -04002406/**
2407 * lpfc_els_retry: Make retry decision on an els command iocb.
2408 * @phba: pointer to lpfc hba data structure.
2409 * @cmdiocb: pointer to lpfc command iocb data structure.
2410 * @rspiocb: pointer to lpfc response iocb data structure.
2411 *
2412 * This routine makes a retry decision on an ELS command IOCB, which has
2413 * failed. The following ELS IOCBs use this function for retrying the command
2414 * when previously issued command responsed with error status: FLOGI, PLOGI,
2415 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
2416 * returned error status, it makes the decision whether a retry shall be
2417 * issued for the command, and whether a retry shall be made immediately or
2418 * delayed. In the former case, the corresponding ELS command issuing-function
2419 * is called to retry the command. In the later case, the ELS command shall
2420 * be posted to the ndlp delayed event and delayed function timer set to the
2421 * ndlp for the delayed command issusing.
2422 *
2423 * Return code
2424 * 0 - No retry of els command is made
2425 * 1 - Immediate or delayed retry of els command is made
2426 **/
dea31012005-04-17 16:05:31 -05002427static int
James Smart2e0fef82007-06-17 19:56:36 -05002428lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2429 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002430{
James Smart2e0fef82007-06-17 19:56:36 -05002431 struct lpfc_vport *vport = cmdiocb->vport;
2432 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2433 IOCB_t *irsp = &rspiocb->iocb;
2434 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2435 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
dea31012005-04-17 16:05:31 -05002436 uint32_t *elscmd;
2437 struct ls_rjt stat;
James Smart2e0fef82007-06-17 19:56:36 -05002438 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
James Smart98c9ea52007-10-27 13:37:33 -04002439 int logerr = 0;
James Smart2e0fef82007-06-17 19:56:36 -05002440 uint32_t cmd = 0;
James Smart488d1462006-03-07 15:02:37 -05002441 uint32_t did;
dea31012005-04-17 16:05:31 -05002442
James Smart488d1462006-03-07 15:02:37 -05002443
dea31012005-04-17 16:05:31 -05002444 /* Note: context2 may be 0 for internal driver abort
2445 * of delays ELS command.
2446 */
2447
2448 if (pcmd && pcmd->virt) {
2449 elscmd = (uint32_t *) (pcmd->virt);
2450 cmd = *elscmd++;
2451 }
2452
James Smarte47c9092008-02-08 18:49:26 -05002453 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart488d1462006-03-07 15:02:37 -05002454 did = ndlp->nlp_DID;
2455 else {
2456 /* We should only hit this case for retrying PLOGI */
2457 did = irsp->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05002458 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05002459 if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
2460 && (cmd != ELS_CMD_PLOGI))
James Smart488d1462006-03-07 15:02:37 -05002461 return 1;
2462 }
2463
James Smart858c9f62007-06-17 19:56:39 -05002464 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2465 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
2466 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
2467
dea31012005-04-17 16:05:31 -05002468 switch (irsp->ulpStatus) {
2469 case IOSTAT_FCP_RSP_ERROR:
2470 case IOSTAT_REMOTE_STOP:
2471 break;
2472
2473 case IOSTAT_LOCAL_REJECT:
2474 switch ((irsp->un.ulpWord[4] & 0xff)) {
2475 case IOERR_LOOP_OPEN_FAILURE:
James Smarteaf15d52008-12-04 22:39:29 -05002476 if (cmd == ELS_CMD_FLOGI) {
2477 if (PCI_DEVICE_ID_HORNET ==
2478 phba->pcidev->device) {
2479 phba->fc_topology = TOPOLOGY_LOOP;
2480 phba->pport->fc_myDID = 0;
2481 phba->alpa_map[0] = 0;
2482 phba->alpa_map[1] = 0;
2483 }
2484 }
James Smart2e0fef82007-06-17 19:56:36 -05002485 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05002486 delay = 1000;
dea31012005-04-17 16:05:31 -05002487 retry = 1;
2488 break;
2489
James Smart92d7f7b2007-06-17 19:56:38 -05002490 case IOERR_ILLEGAL_COMMAND:
James Smart7f5f3d02008-02-08 18:50:14 -05002491 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2492 "0124 Retry illegal cmd x%x "
2493 "retry:x%x delay:x%x\n",
2494 cmd, cmdiocb->retry, delay);
2495 retry = 1;
2496 /* All command's retry policy */
2497 maxretry = 8;
2498 if (cmdiocb->retry > 2)
2499 delay = 1000;
James Smart92d7f7b2007-06-17 19:56:38 -05002500 break;
2501
dea31012005-04-17 16:05:31 -05002502 case IOERR_NO_RESOURCES:
James Smart98c9ea52007-10-27 13:37:33 -04002503 logerr = 1; /* HBA out of resources */
James Smart858c9f62007-06-17 19:56:39 -05002504 retry = 1;
2505 if (cmdiocb->retry > 100)
2506 delay = 100;
2507 maxretry = 250;
2508 break;
2509
2510 case IOERR_ILLEGAL_FRAME:
James Smart92d7f7b2007-06-17 19:56:38 -05002511 delay = 100;
dea31012005-04-17 16:05:31 -05002512 retry = 1;
2513 break;
2514
James Smart858c9f62007-06-17 19:56:39 -05002515 case IOERR_SEQUENCE_TIMEOUT:
dea31012005-04-17 16:05:31 -05002516 case IOERR_INVALID_RPI:
2517 retry = 1;
2518 break;
2519 }
2520 break;
2521
2522 case IOSTAT_NPORT_RJT:
2523 case IOSTAT_FABRIC_RJT:
2524 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
2525 retry = 1;
2526 break;
2527 }
2528 break;
2529
2530 case IOSTAT_NPORT_BSY:
2531 case IOSTAT_FABRIC_BSY:
James Smart98c9ea52007-10-27 13:37:33 -04002532 logerr = 1; /* Fabric / Remote NPort out of resources */
dea31012005-04-17 16:05:31 -05002533 retry = 1;
2534 break;
2535
2536 case IOSTAT_LS_RJT:
2537 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
2538 /* Added for Vendor specifc support
2539 * Just keep retrying for these Rsn / Exp codes
2540 */
2541 switch (stat.un.b.lsRjtRsnCode) {
2542 case LSRJT_UNABLE_TPC:
2543 if (stat.un.b.lsRjtRsnCodeExp ==
2544 LSEXP_CMD_IN_PROGRESS) {
2545 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05002546 delay = 1000;
dea31012005-04-17 16:05:31 -05002547 maxretry = 48;
2548 }
2549 retry = 1;
2550 break;
2551 }
2552 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05002553 delay = 1000;
dea31012005-04-17 16:05:31 -05002554 maxretry = lpfc_max_els_tries + 1;
2555 retry = 1;
2556 break;
2557 }
James Smart92d7f7b2007-06-17 19:56:38 -05002558 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2559 (cmd == ELS_CMD_FDISC) &&
2560 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
James Smarte8b62012007-08-02 11:10:09 -04002561 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2562 "0125 FDISC Failed (x%x). "
2563 "Fabric out of resources\n",
2564 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05002565 lpfc_vport_set_state(vport,
2566 FC_VPORT_NO_FABRIC_RSCS);
2567 }
dea31012005-04-17 16:05:31 -05002568 break;
2569
2570 case LSRJT_LOGICAL_BSY:
James Smart858c9f62007-06-17 19:56:39 -05002571 if ((cmd == ELS_CMD_PLOGI) ||
2572 (cmd == ELS_CMD_PRLI)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002573 delay = 1000;
dea31012005-04-17 16:05:31 -05002574 maxretry = 48;
James Smart92d7f7b2007-06-17 19:56:38 -05002575 } else if (cmd == ELS_CMD_FDISC) {
James Smart51ef4c22007-08-02 11:10:31 -04002576 /* FDISC retry policy */
2577 maxretry = 48;
2578 if (cmdiocb->retry >= 32)
2579 delay = 1000;
dea31012005-04-17 16:05:31 -05002580 }
2581 retry = 1;
2582 break;
James Smart92d7f7b2007-06-17 19:56:38 -05002583
2584 case LSRJT_LOGICAL_ERR:
James Smart7f5f3d02008-02-08 18:50:14 -05002585 /* There are some cases where switches return this
2586 * error when they are not ready and should be returning
2587 * Logical Busy. We should delay every time.
2588 */
2589 if (cmd == ELS_CMD_FDISC &&
2590 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
2591 maxretry = 3;
2592 delay = 1000;
2593 retry = 1;
2594 break;
2595 }
James Smart92d7f7b2007-06-17 19:56:38 -05002596 case LSRJT_PROTOCOL_ERR:
2597 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2598 (cmd == ELS_CMD_FDISC) &&
2599 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
2600 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
2601 ) {
James Smarte8b62012007-08-02 11:10:09 -04002602 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smartd7c255b2008-08-24 21:50:00 -04002603 "0122 FDISC Failed (x%x). "
James Smarte8b62012007-08-02 11:10:09 -04002604 "Fabric Detected Bad WWN\n",
2605 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05002606 lpfc_vport_set_state(vport,
2607 FC_VPORT_FABRIC_REJ_WWN);
2608 }
2609 break;
dea31012005-04-17 16:05:31 -05002610 }
2611 break;
2612
2613 case IOSTAT_INTERMED_RSP:
2614 case IOSTAT_BA_RJT:
2615 break;
2616
2617 default:
2618 break;
2619 }
2620
James Smart488d1462006-03-07 15:02:37 -05002621 if (did == FDMI_DID)
dea31012005-04-17 16:05:31 -05002622 retry = 1;
dea31012005-04-17 16:05:31 -05002623
James Smart98c9ea52007-10-27 13:37:33 -04002624 if ((cmd == ELS_CMD_FLOGI) &&
James Smart1b32f6a2008-02-08 18:49:39 -05002625 (phba->fc_topology != TOPOLOGY_LOOP) &&
2626 !lpfc_error_lost_link(irsp)) {
James Smart98c9ea52007-10-27 13:37:33 -04002627 /* FLOGI retry policy */
2628 retry = 1;
2629 maxretry = 48;
2630 if (cmdiocb->retry >= 32)
2631 delay = 1000;
2632 }
2633
dea31012005-04-17 16:05:31 -05002634 if ((++cmdiocb->retry) >= maxretry) {
2635 phba->fc_stat.elsRetryExceeded++;
2636 retry = 0;
2637 }
2638
James Smarted957682007-06-17 19:56:37 -05002639 if ((vport->load_flag & FC_UNLOADING) != 0)
2640 retry = 0;
2641
dea31012005-04-17 16:05:31 -05002642 if (retry) {
2643
2644 /* Retry ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04002645 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2646 "0107 Retry ELS command x%x to remote "
2647 "NPORT x%x Data: x%x x%x\n",
2648 cmd, did, cmdiocb->retry, delay);
dea31012005-04-17 16:05:31 -05002649
James Smart858c9f62007-06-17 19:56:39 -05002650 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
2651 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
2652 ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) {
2653 /* Don't reset timer for no resources */
2654
dea31012005-04-17 16:05:31 -05002655 /* If discovery / RSCN timer is running, reset it */
James Smart2e0fef82007-06-17 19:56:36 -05002656 if (timer_pending(&vport->fc_disctmo) ||
James Smart92d7f7b2007-06-17 19:56:38 -05002657 (vport->fc_flag & FC_RSCN_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05002658 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05002659 }
2660
2661 phba->fc_stat.elsXmitRetry++;
James Smart58da1ff2008-04-07 10:15:56 -04002662 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
dea31012005-04-17 16:05:31 -05002663 phba->fc_stat.elsDelayRetry++;
2664 ndlp->nlp_retry = cmdiocb->retry;
2665
James Smart92d7f7b2007-06-17 19:56:38 -05002666 /* delay is specified in milliseconds */
2667 mod_timer(&ndlp->nlp_delayfunc,
2668 jiffies + msecs_to_jiffies(delay));
James Smart2e0fef82007-06-17 19:56:36 -05002669 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002670 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002671 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002672
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002673 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart858c9f62007-06-17 19:56:39 -05002674 if (cmd == ELS_CMD_PRLI)
2675 lpfc_nlp_set_state(vport, ndlp,
2676 NLP_STE_REG_LOGIN_ISSUE);
2677 else
2678 lpfc_nlp_set_state(vport, ndlp,
2679 NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05002680 ndlp->nlp_last_elscmd = cmd;
2681
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002682 return 1;
dea31012005-04-17 16:05:31 -05002683 }
2684 switch (cmd) {
2685 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002686 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002687 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -05002688 case ELS_CMD_FDISC:
2689 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
2690 return 1;
dea31012005-04-17 16:05:31 -05002691 case ELS_CMD_PLOGI:
James Smart58da1ff2008-04-07 10:15:56 -04002692 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart488d1462006-03-07 15:02:37 -05002693 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002694 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04002695 NLP_STE_PLOGI_ISSUE);
James Smart488d1462006-03-07 15:02:37 -05002696 }
James Smart2e0fef82007-06-17 19:56:36 -05002697 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002698 return 1;
dea31012005-04-17 16:05:31 -05002699 case ELS_CMD_ADISC:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002700 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002701 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2702 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002703 return 1;
dea31012005-04-17 16:05:31 -05002704 case ELS_CMD_PRLI:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002705 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002706 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
2707 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002708 return 1;
dea31012005-04-17 16:05:31 -05002709 case ELS_CMD_LOGO:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002710 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002711 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2712 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002713 return 1;
dea31012005-04-17 16:05:31 -05002714 }
2715 }
dea31012005-04-17 16:05:31 -05002716 /* No retry ELS command <elsCmd> to remote NPORT <did> */
James Smart98c9ea52007-10-27 13:37:33 -04002717 if (logerr) {
2718 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2719 "0137 No retry ELS command x%x to remote "
2720 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
2721 cmd, did, irsp->ulpStatus,
2722 irsp->un.ulpWord[4]);
2723 }
2724 else {
2725 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smarta58cbd52007-08-02 11:09:43 -04002726 "0108 No retry ELS command x%x to remote "
2727 "NPORT x%x Retried:%d Error:x%x/%x\n",
2728 cmd, did, cmdiocb->retry, irsp->ulpStatus,
2729 irsp->un.ulpWord[4]);
James Smart98c9ea52007-10-27 13:37:33 -04002730 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002731 return 0;
dea31012005-04-17 16:05:31 -05002732}
2733
James Smarte59058c2008-08-24 21:49:00 -04002734/**
2735 * lpfc_els_free_data: Free lpfc dma buffer and data structure with an iocb.
2736 * @phba: pointer to lpfc hba data structure.
2737 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
2738 *
2739 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
2740 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
2741 * checks to see whether there is a lpfc DMA buffer associated with the
2742 * response of the command IOCB. If so, it will be released before releasing
2743 * the lpfc DMA buffer associated with the IOCB itself.
2744 *
2745 * Return code
2746 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
2747 **/
James Smart09372822008-01-11 01:52:54 -05002748static int
James Smart87af33f2007-10-27 13:37:43 -04002749lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
2750{
2751 struct lpfc_dmabuf *buf_ptr;
2752
James Smarte59058c2008-08-24 21:49:00 -04002753 /* Free the response before processing the command. */
James Smart87af33f2007-10-27 13:37:43 -04002754 if (!list_empty(&buf_ptr1->list)) {
2755 list_remove_head(&buf_ptr1->list, buf_ptr,
2756 struct lpfc_dmabuf,
2757 list);
2758 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
2759 kfree(buf_ptr);
2760 }
2761 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
2762 kfree(buf_ptr1);
2763 return 0;
2764}
2765
James Smarte59058c2008-08-24 21:49:00 -04002766/**
2767 * lpfc_els_free_bpl: Free lpfc dma buffer and data structure with bpl.
2768 * @phba: pointer to lpfc hba data structure.
2769 * @buf_ptr: pointer to the lpfc dma buffer data structure.
2770 *
2771 * This routine releases the lpfc Direct Memory Access (DMA) buffer
2772 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
2773 * pool.
2774 *
2775 * Return code
2776 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
2777 **/
James Smart09372822008-01-11 01:52:54 -05002778static int
James Smart87af33f2007-10-27 13:37:43 -04002779lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
2780{
2781 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
2782 kfree(buf_ptr);
2783 return 0;
2784}
2785
James Smarte59058c2008-08-24 21:49:00 -04002786/**
2787 * lpfc_els_free_iocb: Free a command iocb and its associated resources.
2788 * @phba: pointer to lpfc hba data structure.
2789 * @elsiocb: pointer to lpfc els command iocb data structure.
2790 *
2791 * This routine frees a command IOCB and its associated resources. The
2792 * command IOCB data structure contains the reference to various associated
2793 * resources, these fields must be set to NULL if the associated reference
2794 * not present:
2795 * context1 - reference to ndlp
2796 * context2 - reference to cmd
2797 * context2->next - reference to rsp
2798 * context3 - reference to bpl
2799 *
2800 * It first properly decrements the reference count held on ndlp for the
2801 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
2802 * set, it invokes the lpfc_els_free_data() routine to release the Direct
2803 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
2804 * adds the DMA buffer the @phba data structure for the delayed release.
2805 * If reference to the Buffer Pointer List (BPL) is present, the
2806 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
2807 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
2808 * invoked to release the IOCB data structure back to @phba IOCBQ list.
2809 *
2810 * Return code
2811 * 0 - Success (currently, always return 0)
2812 **/
James Smart87af33f2007-10-27 13:37:43 -04002813int
James Smart329f9bc2007-04-25 09:53:01 -04002814lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05002815{
2816 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
James Smarta8adb832007-10-27 13:37:53 -04002817 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05002818
James Smarta8adb832007-10-27 13:37:53 -04002819 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
2820 if (ndlp) {
2821 if (ndlp->nlp_flag & NLP_DEFER_RM) {
2822 lpfc_nlp_put(ndlp);
2823
2824 /* If the ndlp is not being used by another discovery
2825 * thread, free it.
2826 */
2827 if (!lpfc_nlp_not_used(ndlp)) {
2828 /* If ndlp is being used by another discovery
2829 * thread, just clear NLP_DEFER_RM
2830 */
2831 ndlp->nlp_flag &= ~NLP_DEFER_RM;
2832 }
2833 }
2834 else
2835 lpfc_nlp_put(ndlp);
James Smart329f9bc2007-04-25 09:53:01 -04002836 elsiocb->context1 = NULL;
2837 }
dea31012005-04-17 16:05:31 -05002838 /* context2 = cmd, context2->next = rsp, context3 = bpl */
2839 if (elsiocb->context2) {
James Smart0ff10d42008-01-11 01:52:36 -05002840 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
2841 /* Firmware could still be in progress of DMAing
2842 * payload, so don't free data buffer till after
2843 * a hbeat.
2844 */
2845 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
2846 buf_ptr = elsiocb->context2;
2847 elsiocb->context2 = NULL;
2848 if (buf_ptr) {
2849 buf_ptr1 = NULL;
2850 spin_lock_irq(&phba->hbalock);
2851 if (!list_empty(&buf_ptr->list)) {
2852 list_remove_head(&buf_ptr->list,
2853 buf_ptr1, struct lpfc_dmabuf,
2854 list);
2855 INIT_LIST_HEAD(&buf_ptr1->list);
2856 list_add_tail(&buf_ptr1->list,
2857 &phba->elsbuf);
2858 phba->elsbuf_cnt++;
2859 }
2860 INIT_LIST_HEAD(&buf_ptr->list);
2861 list_add_tail(&buf_ptr->list, &phba->elsbuf);
2862 phba->elsbuf_cnt++;
2863 spin_unlock_irq(&phba->hbalock);
2864 }
2865 } else {
2866 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
2867 lpfc_els_free_data(phba, buf_ptr1);
2868 }
dea31012005-04-17 16:05:31 -05002869 }
2870
2871 if (elsiocb->context3) {
2872 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
James Smart87af33f2007-10-27 13:37:43 -04002873 lpfc_els_free_bpl(phba, buf_ptr);
dea31012005-04-17 16:05:31 -05002874 }
James Bottomley604a3e32005-10-29 10:28:33 -05002875 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -05002876 return 0;
2877}
2878
James Smarte59058c2008-08-24 21:49:00 -04002879/**
2880 * lpfc_cmpl_els_logo_acc: Completion callback function to logo acc response.
2881 * @phba: pointer to lpfc hba data structure.
2882 * @cmdiocb: pointer to lpfc command iocb data structure.
2883 * @rspiocb: pointer to lpfc response iocb data structure.
2884 *
2885 * This routine is the completion callback function to the Logout (LOGO)
2886 * Accept (ACC) Response ELS command. This routine is invoked to indicate
2887 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
2888 * release the ndlp if it has the last reference remaining (reference count
2889 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
2890 * field to NULL to inform the following lpfc_els_free_iocb() routine no
2891 * ndlp reference count needs to be decremented. Otherwise, the ndlp
2892 * reference use-count shall be decremented by the lpfc_els_free_iocb()
2893 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
2894 * IOCB data structure.
2895 **/
dea31012005-04-17 16:05:31 -05002896static void
James Smart2e0fef82007-06-17 19:56:36 -05002897lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2898 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002899{
James Smart2e0fef82007-06-17 19:56:36 -05002900 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2901 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05002902 IOCB_t *irsp;
2903
2904 irsp = &rspiocb->iocb;
2905 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
2906 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
2907 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05002908 /* ACC to LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002909 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2910 "0109 ACC to LOGO completes to NPort x%x "
2911 "Data: x%x x%x x%x\n",
2912 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
2913 ndlp->nlp_rpi);
James Smart87af33f2007-10-27 13:37:43 -04002914
2915 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
2916 /* NPort Recovery mode or node is just allocated */
2917 if (!lpfc_nlp_not_used(ndlp)) {
2918 /* If the ndlp is being used by another discovery
2919 * thread, just unregister the RPI.
2920 */
2921 lpfc_unreg_rpi(vport, ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05002922 } else {
2923 /* Indicate the node has already released, should
2924 * not reference to it from within lpfc_els_free_iocb.
2925 */
2926 cmdiocb->context1 = NULL;
James Smart87af33f2007-10-27 13:37:43 -04002927 }
dea31012005-04-17 16:05:31 -05002928 }
2929 lpfc_els_free_iocb(phba, cmdiocb);
2930 return;
2931}
2932
James Smarte59058c2008-08-24 21:49:00 -04002933/**
2934 * lpfc_mbx_cmpl_dflt_rpi: Completion callbk func for unreg dflt rpi mbox cmd.
2935 * @phba: pointer to lpfc hba data structure.
2936 * @pmb: pointer to the driver internal queue element for mailbox command.
2937 *
2938 * This routine is the completion callback function for unregister default
2939 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
2940 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
2941 * decrements the ndlp reference count held for this completion callback
2942 * function. After that, it invokes the lpfc_nlp_not_used() to check
2943 * whether there is only one reference left on the ndlp. If so, it will
2944 * perform one more decrement and trigger the release of the ndlp.
2945 **/
James Smart858c9f62007-06-17 19:56:39 -05002946void
2947lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
2948{
2949 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
2950 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
2951
2952 pmb->context1 = NULL;
2953 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2954 kfree(mp);
2955 mempool_free(pmb, phba->mbox_mem_pool);
James Smart58da1ff2008-04-07 10:15:56 -04002956 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smarta8adb832007-10-27 13:37:53 -04002957 lpfc_nlp_put(ndlp);
James Smarta8adb832007-10-27 13:37:53 -04002958 /* This is the end of the default RPI cleanup logic for this
2959 * ndlp. If no other discovery threads are using this ndlp.
2960 * we should free all resources associated with it.
2961 */
2962 lpfc_nlp_not_used(ndlp);
2963 }
James Smart858c9f62007-06-17 19:56:39 -05002964 return;
2965}
2966
James Smarte59058c2008-08-24 21:49:00 -04002967/**
2968 * lpfc_cmpl_els_rsp: Completion callback function for els response iocb cmd.
2969 * @phba: pointer to lpfc hba data structure.
2970 * @cmdiocb: pointer to lpfc command iocb data structure.
2971 * @rspiocb: pointer to lpfc response iocb data structure.
2972 *
2973 * This routine is the completion callback function for ELS Response IOCB
2974 * command. In normal case, this callback function just properly sets the
2975 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
2976 * field in the command IOCB is not NULL, the referred mailbox command will
2977 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
2978 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
2979 * link down event occurred during the discovery, the lpfc_nlp_not_used()
2980 * routine shall be invoked trying to release the ndlp if no other threads
2981 * are currently referring it.
2982 **/
dea31012005-04-17 16:05:31 -05002983static void
James Smart858c9f62007-06-17 19:56:39 -05002984lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
James Smart329f9bc2007-04-25 09:53:01 -04002985 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002986{
James Smart2e0fef82007-06-17 19:56:36 -05002987 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2988 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
2989 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
James Smart87af33f2007-10-27 13:37:43 -04002990 IOCB_t *irsp;
2991 uint8_t *pcmd;
dea31012005-04-17 16:05:31 -05002992 LPFC_MBOXQ_t *mbox = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05002993 struct lpfc_dmabuf *mp = NULL;
James Smart87af33f2007-10-27 13:37:43 -04002994 uint32_t ls_rjt = 0;
dea31012005-04-17 16:05:31 -05002995
James Smart33ccf8d2006-08-17 11:57:58 -04002996 irsp = &rspiocb->iocb;
2997
dea31012005-04-17 16:05:31 -05002998 if (cmdiocb->context_un.mbox)
2999 mbox = cmdiocb->context_un.mbox;
3000
James Smartfa4066b2008-01-11 01:53:27 -05003001 /* First determine if this is a LS_RJT cmpl. Note, this callback
3002 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
3003 */
James Smart87af33f2007-10-27 13:37:43 -04003004 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
James Smart58da1ff2008-04-07 10:15:56 -04003005 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3006 (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
James Smartfa4066b2008-01-11 01:53:27 -05003007 /* A LS_RJT associated with Default RPI cleanup has its own
3008 * seperate code path.
James Smart87af33f2007-10-27 13:37:43 -04003009 */
3010 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
3011 ls_rjt = 1;
3012 }
3013
dea31012005-04-17 16:05:31 -05003014 /* Check to see if link went down during discovery */
James Smart58da1ff2008-04-07 10:15:56 -04003015 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
dea31012005-04-17 16:05:31 -05003016 if (mbox) {
James Smart14691152006-12-02 13:34:28 -05003017 mp = (struct lpfc_dmabuf *) mbox->context1;
3018 if (mp) {
3019 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3020 kfree(mp);
3021 }
James Smart329f9bc2007-04-25 09:53:01 -04003022 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003023 }
James Smart58da1ff2008-04-07 10:15:56 -04003024 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3025 (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
James Smartfa4066b2008-01-11 01:53:27 -05003026 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003027 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003028 /* Indicate the node has already released,
3029 * should not reference to it from within
3030 * the routine lpfc_els_free_iocb.
3031 */
3032 cmdiocb->context1 = NULL;
3033 }
dea31012005-04-17 16:05:31 -05003034 goto out;
3035 }
3036
James Smart858c9f62007-06-17 19:56:39 -05003037 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smart51ef4c22007-08-02 11:10:31 -04003038 "ELS rsp cmpl: status:x%x/x%x did:x%x",
James Smart858c9f62007-06-17 19:56:39 -05003039 irsp->ulpStatus, irsp->un.ulpWord[4],
James Smart51ef4c22007-08-02 11:10:31 -04003040 cmdiocb->iocb.un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05003041 /* ELS response tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04003042 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3043 "0110 ELS response tag x%x completes "
3044 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
3045 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
3046 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
3047 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3048 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003049 if (mbox) {
3050 if ((rspiocb->iocb.ulpStatus == 0)
3051 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
James Smart2e0fef82007-06-17 19:56:36 -05003052 lpfc_unreg_rpi(vport, ndlp);
James Smarte47c9092008-02-08 18:49:26 -05003053 /* Increment reference count to ndlp to hold the
3054 * reference to ndlp for the callback function.
3055 */
James Smart329f9bc2007-04-25 09:53:01 -04003056 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05003057 mbox->vport = vport;
James Smart858c9f62007-06-17 19:56:39 -05003058 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
3059 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
3060 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
3061 }
3062 else {
3063 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
3064 ndlp->nlp_prev_state = ndlp->nlp_state;
3065 lpfc_nlp_set_state(vport, ndlp,
James Smart2e0fef82007-06-17 19:56:36 -05003066 NLP_STE_REG_LOGIN_ISSUE);
James Smart858c9f62007-06-17 19:56:39 -05003067 }
James Smart0b727fe2007-10-27 13:37:25 -04003068 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smarte47c9092008-02-08 18:49:26 -05003069 != MBX_NOT_FINISHED)
dea31012005-04-17 16:05:31 -05003070 goto out;
James Smarte47c9092008-02-08 18:49:26 -05003071 else
3072 /* Decrement the ndlp reference count we
3073 * set for this failed mailbox command.
3074 */
3075 lpfc_nlp_put(ndlp);
James Smart98c9ea52007-10-27 13:37:33 -04003076
3077 /* ELS rsp: Cannot issue reg_login for <NPortid> */
3078 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3079 "0138 ELS rsp: Cannot issue reg_login for x%x "
3080 "Data: x%x x%x x%x\n",
3081 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3082 ndlp->nlp_rpi);
3083
James Smartfa4066b2008-01-11 01:53:27 -05003084 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003085 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003086 /* Indicate node has already been released,
3087 * should not reference to it from within
3088 * the routine lpfc_els_free_iocb.
3089 */
3090 cmdiocb->context1 = NULL;
3091 }
dea31012005-04-17 16:05:31 -05003092 } else {
James Smart858c9f62007-06-17 19:56:39 -05003093 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
3094 if (!lpfc_error_lost_link(irsp) &&
3095 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
James Smartfa4066b2008-01-11 01:53:27 -05003096 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003097 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003098 /* Indicate node has already been
3099 * released, should not reference
3100 * to it from within the routine
3101 * lpfc_els_free_iocb.
3102 */
3103 cmdiocb->context1 = NULL;
3104 }
dea31012005-04-17 16:05:31 -05003105 }
3106 }
James Smart14691152006-12-02 13:34:28 -05003107 mp = (struct lpfc_dmabuf *) mbox->context1;
3108 if (mp) {
3109 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3110 kfree(mp);
3111 }
3112 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003113 }
3114out:
James Smart58da1ff2008-04-07 10:15:56 -04003115 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart2e0fef82007-06-17 19:56:36 -05003116 spin_lock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05003117 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
James Smart2e0fef82007-06-17 19:56:36 -05003118 spin_unlock_irq(shost->host_lock);
James Smart87af33f2007-10-27 13:37:43 -04003119
3120 /* If the node is not being used by another discovery thread,
3121 * and we are sending a reject, we are done with it.
3122 * Release driver reference count here and free associated
3123 * resources.
3124 */
3125 if (ls_rjt)
James Smartfa4066b2008-01-11 01:53:27 -05003126 if (lpfc_nlp_not_used(ndlp))
3127 /* Indicate node has already been released,
3128 * should not reference to it from within
3129 * the routine lpfc_els_free_iocb.
3130 */
3131 cmdiocb->context1 = NULL;
dea31012005-04-17 16:05:31 -05003132 }
James Smart87af33f2007-10-27 13:37:43 -04003133
dea31012005-04-17 16:05:31 -05003134 lpfc_els_free_iocb(phba, cmdiocb);
3135 return;
3136}
3137
James Smarte59058c2008-08-24 21:49:00 -04003138/**
3139 * lpfc_els_rsp_acc: Prepare and issue an acc response iocb command.
3140 * @vport: pointer to a host virtual N_Port data structure.
3141 * @flag: the els command code to be accepted.
3142 * @oldiocb: pointer to the original lpfc command iocb data structure.
3143 * @ndlp: pointer to a node-list data structure.
3144 * @mbox: pointer to the driver internal queue element for mailbox command.
3145 *
3146 * This routine prepares and issues an Accept (ACC) response IOCB
3147 * command. It uses the @flag to properly set up the IOCB field for the
3148 * specific ACC response command to be issued and invokes the
3149 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
3150 * @mbox pointer is passed in, it will be put into the context_un.mbox
3151 * field of the IOCB for the completion callback function to issue the
3152 * mailbox command to the HBA later when callback is invoked.
3153 *
3154 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3155 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3156 * will be stored into the context1 field of the IOCB for the completion
3157 * callback function to the corresponding response ELS IOCB command.
3158 *
3159 * Return code
3160 * 0 - Successfully issued acc response
3161 * 1 - Failed to issue acc response
3162 **/
dea31012005-04-17 16:05:31 -05003163int
James Smart2e0fef82007-06-17 19:56:36 -05003164lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
3165 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
James Smart51ef4c22007-08-02 11:10:31 -04003166 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003167{
James Smart2e0fef82007-06-17 19:56:36 -05003168 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3169 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003170 IOCB_t *icmd;
3171 IOCB_t *oldcmd;
3172 struct lpfc_iocbq *elsiocb;
3173 struct lpfc_sli_ring *pring;
3174 struct lpfc_sli *psli;
3175 uint8_t *pcmd;
3176 uint16_t cmdsize;
3177 int rc;
James Smart82d9a2a2006-04-15 11:53:05 -04003178 ELS_PKT *els_pkt_ptr;
dea31012005-04-17 16:05:31 -05003179
3180 psli = &phba->sli;
3181 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
3182 oldcmd = &oldiocb->iocb;
3183
3184 switch (flag) {
3185 case ELS_CMD_ACC:
James Smart92d7f7b2007-06-17 19:56:38 -05003186 cmdsize = sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003187 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3188 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003189 if (!elsiocb) {
James Smart2e0fef82007-06-17 19:56:36 -05003190 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003191 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003192 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003193 return 1;
dea31012005-04-17 16:05:31 -05003194 }
James Smart2e0fef82007-06-17 19:56:36 -05003195
dea31012005-04-17 16:05:31 -05003196 icmd = &elsiocb->iocb;
3197 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3198 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3199 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003200 pcmd += sizeof(uint32_t);
James Smart858c9f62007-06-17 19:56:39 -05003201
3202 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3203 "Issue ACC: did:x%x flg:x%x",
3204 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003205 break;
3206 case ELS_CMD_PLOGI:
James Smart92d7f7b2007-06-17 19:56:38 -05003207 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
James Smart2e0fef82007-06-17 19:56:36 -05003208 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3209 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003210 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003211 return 1;
James Smart488d1462006-03-07 15:02:37 -05003212
dea31012005-04-17 16:05:31 -05003213 icmd = &elsiocb->iocb;
3214 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3215 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3216
3217 if (mbox)
3218 elsiocb->context_un.mbox = mbox;
3219
3220 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003221 pcmd += sizeof(uint32_t);
3222 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
James Smart858c9f62007-06-17 19:56:39 -05003223
3224 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3225 "Issue ACC PLOGI: did:x%x flg:x%x",
3226 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003227 break;
James Smart82d9a2a2006-04-15 11:53:05 -04003228 case ELS_CMD_PRLO:
James Smart92d7f7b2007-06-17 19:56:38 -05003229 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
James Smart2e0fef82007-06-17 19:56:36 -05003230 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
James Smart82d9a2a2006-04-15 11:53:05 -04003231 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
3232 if (!elsiocb)
3233 return 1;
3234
3235 icmd = &elsiocb->iocb;
3236 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3237 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3238
3239 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
James Smart92d7f7b2007-06-17 19:56:38 -05003240 sizeof(uint32_t) + sizeof(PRLO));
James Smart82d9a2a2006-04-15 11:53:05 -04003241 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
3242 els_pkt_ptr = (ELS_PKT *) pcmd;
3243 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
James Smart858c9f62007-06-17 19:56:39 -05003244
3245 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3246 "Issue ACC PRLO: did:x%x flg:x%x",
3247 ndlp->nlp_DID, ndlp->nlp_flag, 0);
James Smart82d9a2a2006-04-15 11:53:05 -04003248 break;
dea31012005-04-17 16:05:31 -05003249 default:
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003250 return 1;
dea31012005-04-17 16:05:31 -05003251 }
dea31012005-04-17 16:05:31 -05003252 /* Xmit ELS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003253 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3254 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
3255 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n",
3256 elsiocb->iotag, elsiocb->iocb.ulpContext,
3257 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3258 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003259 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
James Smart2e0fef82007-06-17 19:56:36 -05003260 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003261 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003262 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003263 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
3264 } else {
James Smart858c9f62007-06-17 19:56:39 -05003265 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05003266 }
3267
3268 phba->fc_stat.elsXmitACC++;
dea31012005-04-17 16:05:31 -05003269 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003270 if (rc == IOCB_ERROR) {
3271 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003272 return 1;
dea31012005-04-17 16:05:31 -05003273 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003274 return 0;
dea31012005-04-17 16:05:31 -05003275}
3276
James Smarte59058c2008-08-24 21:49:00 -04003277/**
3278 * lpfc_els_rsp_reject: Propare and issue a rjt response iocb command.
3279 * @vport: pointer to a virtual N_Port data structure.
3280 * @rejectError:
3281 * @oldiocb: pointer to the original lpfc command iocb data structure.
3282 * @ndlp: pointer to a node-list data structure.
3283 * @mbox: pointer to the driver internal queue element for mailbox command.
3284 *
3285 * This routine prepares and issue an Reject (RJT) response IOCB
3286 * command. If a @mbox pointer is passed in, it will be put into the
3287 * context_un.mbox field of the IOCB for the completion callback function
3288 * to issue to the HBA later.
3289 *
3290 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3291 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3292 * will be stored into the context1 field of the IOCB for the completion
3293 * callback function to the reject response ELS IOCB command.
3294 *
3295 * Return code
3296 * 0 - Successfully issued reject response
3297 * 1 - Failed to issue reject response
3298 **/
dea31012005-04-17 16:05:31 -05003299int
James Smart2e0fef82007-06-17 19:56:36 -05003300lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
James Smart858c9f62007-06-17 19:56:39 -05003301 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
3302 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003303{
James Smart2e0fef82007-06-17 19:56:36 -05003304 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003305 IOCB_t *icmd;
3306 IOCB_t *oldcmd;
3307 struct lpfc_iocbq *elsiocb;
3308 struct lpfc_sli_ring *pring;
3309 struct lpfc_sli *psli;
3310 uint8_t *pcmd;
3311 uint16_t cmdsize;
3312 int rc;
3313
3314 psli = &phba->sli;
3315 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
3316
James Smart92d7f7b2007-06-17 19:56:38 -05003317 cmdsize = 2 * sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003318 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3319 ndlp->nlp_DID, ELS_CMD_LS_RJT);
James Smart488d1462006-03-07 15:02:37 -05003320 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003321 return 1;
dea31012005-04-17 16:05:31 -05003322
3323 icmd = &elsiocb->iocb;
3324 oldcmd = &oldiocb->iocb;
3325 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3326 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3327
3328 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
James Smart92d7f7b2007-06-17 19:56:38 -05003329 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003330 *((uint32_t *) (pcmd)) = rejectError;
3331
James Smart51ef4c22007-08-02 11:10:31 -04003332 if (mbox)
James Smart858c9f62007-06-17 19:56:39 -05003333 elsiocb->context_un.mbox = mbox;
James Smart858c9f62007-06-17 19:56:39 -05003334
dea31012005-04-17 16:05:31 -05003335 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003336 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3337 "0129 Xmit ELS RJT x%x response tag x%x "
3338 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
3339 "rpi x%x\n",
3340 rejectError, elsiocb->iotag,
3341 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
3342 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05003343 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3344 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
3345 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
3346
dea31012005-04-17 16:05:31 -05003347 phba->fc_stat.elsXmitLSRJT++;
James Smart858c9f62007-06-17 19:56:39 -05003348 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05003349 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
James Smart51ef4c22007-08-02 11:10:31 -04003350
dea31012005-04-17 16:05:31 -05003351 if (rc == IOCB_ERROR) {
3352 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003353 return 1;
dea31012005-04-17 16:05:31 -05003354 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003355 return 0;
dea31012005-04-17 16:05:31 -05003356}
3357
James Smarte59058c2008-08-24 21:49:00 -04003358/**
3359 * lpfc_els_rsp_adisc_acc: Prepare and issue acc response to adisc iocb cmd.
3360 * @vport: pointer to a virtual N_Port data structure.
3361 * @oldiocb: pointer to the original lpfc command iocb data structure.
3362 * @ndlp: pointer to a node-list data structure.
3363 *
3364 * This routine prepares and issues an Accept (ACC) response to Address
3365 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
3366 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3367 *
3368 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3369 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3370 * will be stored into the context1 field of the IOCB for the completion
3371 * callback function to the ADISC Accept response ELS IOCB command.
3372 *
3373 * Return code
3374 * 0 - Successfully issued acc adisc response
3375 * 1 - Failed to issue adisc acc response
3376 **/
dea31012005-04-17 16:05:31 -05003377int
James Smart2e0fef82007-06-17 19:56:36 -05003378lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
3379 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003380{
James Smart2e0fef82007-06-17 19:56:36 -05003381 struct lpfc_hba *phba = vport->phba;
3382 struct lpfc_sli *psli = &phba->sli;
3383 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05003384 ADISC *ap;
James Smart2e0fef82007-06-17 19:56:36 -05003385 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05003386 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003387 uint8_t *pcmd;
3388 uint16_t cmdsize;
3389 int rc;
3390
James Smart92d7f7b2007-06-17 19:56:38 -05003391 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
James Smart2e0fef82007-06-17 19:56:36 -05003392 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3393 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003394 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003395 return 1;
dea31012005-04-17 16:05:31 -05003396
dea31012005-04-17 16:05:31 -05003397 icmd = &elsiocb->iocb;
3398 oldcmd = &oldiocb->iocb;
3399 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04003400
3401 /* Xmit ADISC ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003402 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3403 "0130 Xmit ADISC ACC response iotag x%x xri: "
3404 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
3405 elsiocb->iotag, elsiocb->iocb.ulpContext,
3406 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3407 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003408 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3409
3410 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003411 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003412
3413 ap = (ADISC *) (pcmd);
3414 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05003415 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
3416 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05003417 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05003418
James Smart858c9f62007-06-17 19:56:39 -05003419 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3420 "Issue ACC ADISC: did:x%x flg:x%x",
3421 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3422
dea31012005-04-17 16:05:31 -05003423 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003424 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05003425 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003426 if (rc == IOCB_ERROR) {
3427 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003428 return 1;
dea31012005-04-17 16:05:31 -05003429 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003430 return 0;
dea31012005-04-17 16:05:31 -05003431}
3432
James Smarte59058c2008-08-24 21:49:00 -04003433/**
3434 * lpfc_els_rsp_prli_acc: Prepare and issue acc response to prli iocb cmd.
3435 * @vport: pointer to a virtual N_Port data structure.
3436 * @oldiocb: pointer to the original lpfc command iocb data structure.
3437 * @ndlp: pointer to a node-list data structure.
3438 *
3439 * This routine prepares and issues an Accept (ACC) response to Process
3440 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
3441 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3442 *
3443 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3444 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3445 * will be stored into the context1 field of the IOCB for the completion
3446 * callback function to the PRLI Accept response ELS IOCB command.
3447 *
3448 * Return code
3449 * 0 - Successfully issued acc prli response
3450 * 1 - Failed to issue acc prli response
3451 **/
dea31012005-04-17 16:05:31 -05003452int
James Smart2e0fef82007-06-17 19:56:36 -05003453lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
James Smart5b8bd0c2007-04-25 09:52:49 -04003454 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003455{
James Smart2e0fef82007-06-17 19:56:36 -05003456 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003457 PRLI *npr;
3458 lpfc_vpd_t *vpd;
3459 IOCB_t *icmd;
3460 IOCB_t *oldcmd;
3461 struct lpfc_iocbq *elsiocb;
3462 struct lpfc_sli_ring *pring;
3463 struct lpfc_sli *psli;
3464 uint8_t *pcmd;
3465 uint16_t cmdsize;
3466 int rc;
3467
3468 psli = &phba->sli;
3469 pring = &psli->ring[LPFC_ELS_RING]; /* ELS ring */
3470
James Smart92d7f7b2007-06-17 19:56:38 -05003471 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
James Smart2e0fef82007-06-17 19:56:36 -05003472 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
James Smart92d7f7b2007-06-17 19:56:38 -05003473 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003474 if (!elsiocb)
3475 return 1;
dea31012005-04-17 16:05:31 -05003476
dea31012005-04-17 16:05:31 -05003477 icmd = &elsiocb->iocb;
3478 oldcmd = &oldiocb->iocb;
3479 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04003480 /* Xmit PRLI ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003481 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3482 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
3483 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
3484 elsiocb->iotag, elsiocb->iocb.ulpContext,
3485 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3486 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003487 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3488
3489 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
James Smart92d7f7b2007-06-17 19:56:38 -05003490 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003491
3492 /* For PRLI, remainder of payload is PRLI parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05003493 memset(pcmd, 0, sizeof(PRLI));
dea31012005-04-17 16:05:31 -05003494
3495 npr = (PRLI *) pcmd;
3496 vpd = &phba->vpd;
3497 /*
James Smart0d2b6b82008-06-14 22:52:47 -04003498 * If the remote port is a target and our firmware version is 3.20 or
3499 * later, set the following bits for FC-TAPE support.
dea31012005-04-17 16:05:31 -05003500 */
James Smart0d2b6b82008-06-14 22:52:47 -04003501 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
3502 (vpd->rev.feaLevelHigh >= 0x02)) {
dea31012005-04-17 16:05:31 -05003503 npr->ConfmComplAllowed = 1;
3504 npr->Retry = 1;
3505 npr->TaskRetryIdReq = 1;
3506 }
3507
3508 npr->acceptRspCode = PRLI_REQ_EXECUTED;
3509 npr->estabImagePair = 1;
3510 npr->readXferRdyDis = 1;
3511 npr->ConfmComplAllowed = 1;
3512
3513 npr->prliType = PRLI_FCP_TYPE;
3514 npr->initiatorFunc = 1;
3515
James Smart858c9f62007-06-17 19:56:39 -05003516 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3517 "Issue ACC PRLI: did:x%x flg:x%x",
3518 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3519
dea31012005-04-17 16:05:31 -05003520 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003521 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05003522
dea31012005-04-17 16:05:31 -05003523 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003524 if (rc == IOCB_ERROR) {
3525 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003526 return 1;
dea31012005-04-17 16:05:31 -05003527 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003528 return 0;
dea31012005-04-17 16:05:31 -05003529}
3530
James Smarte59058c2008-08-24 21:49:00 -04003531/**
3532 * lpfc_els_rsp_rnid_acc: Issue rnid acc response iocb command.
3533 * @vport: pointer to a virtual N_Port data structure.
3534 * @format: rnid command format.
3535 * @oldiocb: pointer to the original lpfc command iocb data structure.
3536 * @ndlp: pointer to a node-list data structure.
3537 *
3538 * This routine issues a Request Node Identification Data (RNID) Accept
3539 * (ACC) response. It constructs the RNID ACC response command according to
3540 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
3541 * issue the response. Note that this command does not need to hold the ndlp
3542 * reference count for the callback. So, the ndlp reference count taken by
3543 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
3544 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
3545 * there is no ndlp reference available.
3546 *
3547 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3548 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3549 * will be stored into the context1 field of the IOCB for the completion
3550 * callback function. However, for the RNID Accept Response ELS command,
3551 * this is undone later by this routine after the IOCB is allocated.
3552 *
3553 * Return code
3554 * 0 - Successfully issued acc rnid response
3555 * 1 - Failed to issue acc rnid response
3556 **/
dea31012005-04-17 16:05:31 -05003557static int
James Smart2e0fef82007-06-17 19:56:36 -05003558lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
James Smart329f9bc2007-04-25 09:53:01 -04003559 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003560{
James Smart2e0fef82007-06-17 19:56:36 -05003561 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003562 RNID *rn;
James Smart2e0fef82007-06-17 19:56:36 -05003563 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05003564 struct lpfc_iocbq *elsiocb;
3565 struct lpfc_sli_ring *pring;
3566 struct lpfc_sli *psli;
3567 uint8_t *pcmd;
3568 uint16_t cmdsize;
3569 int rc;
3570
3571 psli = &phba->sli;
3572 pring = &psli->ring[LPFC_ELS_RING];
3573
James Smart92d7f7b2007-06-17 19:56:38 -05003574 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
3575 + (2 * sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003576 if (format)
James Smart92d7f7b2007-06-17 19:56:38 -05003577 cmdsize += sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05003578
James Smart2e0fef82007-06-17 19:56:36 -05003579 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3580 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003581 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003582 return 1;
dea31012005-04-17 16:05:31 -05003583
dea31012005-04-17 16:05:31 -05003584 icmd = &elsiocb->iocb;
3585 oldcmd = &oldiocb->iocb;
3586 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04003587 /* Xmit RNID ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003588 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3589 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
3590 elsiocb->iotag, elsiocb->iocb.ulpContext);
dea31012005-04-17 16:05:31 -05003591 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
dea31012005-04-17 16:05:31 -05003592 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003593 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003594
James Smart92d7f7b2007-06-17 19:56:38 -05003595 memset(pcmd, 0, sizeof(RNID));
dea31012005-04-17 16:05:31 -05003596 rn = (RNID *) (pcmd);
3597 rn->Format = format;
James Smart92d7f7b2007-06-17 19:56:38 -05003598 rn->CommonLen = (2 * sizeof(struct lpfc_name));
3599 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
3600 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003601 switch (format) {
3602 case 0:
3603 rn->SpecificLen = 0;
3604 break;
3605 case RNID_TOPOLOGY_DISC:
James Smart92d7f7b2007-06-17 19:56:38 -05003606 rn->SpecificLen = sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05003607 memcpy(&rn->un.topologyDisc.portName,
James Smart92d7f7b2007-06-17 19:56:38 -05003608 &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003609 rn->un.topologyDisc.unitType = RNID_HBA;
3610 rn->un.topologyDisc.physPort = 0;
3611 rn->un.topologyDisc.attachedNodes = 0;
3612 break;
3613 default:
3614 rn->CommonLen = 0;
3615 rn->SpecificLen = 0;
3616 break;
3617 }
3618
James Smart858c9f62007-06-17 19:56:39 -05003619 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3620 "Issue ACC RNID: did:x%x flg:x%x",
3621 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3622
dea31012005-04-17 16:05:31 -05003623 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003624 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart329f9bc2007-04-25 09:53:01 -04003625 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05003626 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
3627 * it could be freed */
3628
dea31012005-04-17 16:05:31 -05003629 rc = lpfc_sli_issue_iocb(phba, pring, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003630 if (rc == IOCB_ERROR) {
3631 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003632 return 1;
dea31012005-04-17 16:05:31 -05003633 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003634 return 0;
dea31012005-04-17 16:05:31 -05003635}
3636
James Smarte59058c2008-08-24 21:49:00 -04003637/**
3638 * lpfc_els_disc_adisc: Issue remaining adisc iocbs to npr nodes of a vport.
3639 * @vport: pointer to a host virtual N_Port data structure.
3640 *
3641 * This routine issues Address Discover (ADISC) ELS commands to those
3642 * N_Ports which are in node port recovery state and ADISC has not been issued
3643 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
3644 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
3645 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
3646 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
3647 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
3648 * IOCBs quit for later pick up. On the other hand, after walking through
3649 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
3650 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
3651 * no more ADISC need to be sent.
3652 *
3653 * Return code
3654 * The number of N_Ports with adisc issued.
3655 **/
dea31012005-04-17 16:05:31 -05003656int
James Smart2e0fef82007-06-17 19:56:36 -05003657lpfc_els_disc_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003658{
James Smart2e0fef82007-06-17 19:56:36 -05003659 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05003660 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05003661 int sentadisc = 0;
dea31012005-04-17 16:05:31 -05003662
James Smart685f0bf2007-04-25 09:53:08 -04003663 /* go thru NPR nodes and issue any remaining ELS ADISCs */
James Smart2e0fef82007-06-17 19:56:36 -05003664 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05003665 if (!NLP_CHK_NODE_ACT(ndlp))
3666 continue;
James Smart685f0bf2007-04-25 09:53:08 -04003667 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
3668 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
3669 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
James Smart2e0fef82007-06-17 19:56:36 -05003670 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003671 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05003672 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003673 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003674 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3675 lpfc_issue_els_adisc(vport, ndlp, 0);
James Smart685f0bf2007-04-25 09:53:08 -04003676 sentadisc++;
James Smart2e0fef82007-06-17 19:56:36 -05003677 vport->num_disc_nodes++;
3678 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04003679 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05003680 spin_lock_irq(shost->host_lock);
3681 vport->fc_flag |= FC_NLP_MORE;
3682 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003683 break;
dea31012005-04-17 16:05:31 -05003684 }
3685 }
3686 }
3687 if (sentadisc == 0) {
James Smart2e0fef82007-06-17 19:56:36 -05003688 spin_lock_irq(shost->host_lock);
3689 vport->fc_flag &= ~FC_NLP_MORE;
3690 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003691 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003692 return sentadisc;
dea31012005-04-17 16:05:31 -05003693}
3694
James Smarte59058c2008-08-24 21:49:00 -04003695/**
3696 * lpfc_els_disc_plogi: Issue plogi for all npr nodes of a vport before adisc.
3697 * @vport: pointer to a host virtual N_Port data structure.
3698 *
3699 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
3700 * which are in node port recovery state, with a @vport. Each time an ELS
3701 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
3702 * the per @vport number of discover count (num_disc_nodes) shall be
3703 * incremented. If the num_disc_nodes reaches a pre-configured threshold
3704 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
3705 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
3706 * later pick up. On the other hand, after walking through all the ndlps with
3707 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
3708 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
3709 * PLOGI need to be sent.
3710 *
3711 * Return code
3712 * The number of N_Ports with plogi issued.
3713 **/
dea31012005-04-17 16:05:31 -05003714int
James Smart2e0fef82007-06-17 19:56:36 -05003715lpfc_els_disc_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003716{
James Smart2e0fef82007-06-17 19:56:36 -05003717 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05003718 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05003719 int sentplogi = 0;
dea31012005-04-17 16:05:31 -05003720
James Smart2e0fef82007-06-17 19:56:36 -05003721 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
3722 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05003723 if (!NLP_CHK_NODE_ACT(ndlp))
3724 continue;
James Smart685f0bf2007-04-25 09:53:08 -04003725 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
3726 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
3727 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
3728 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
3729 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003730 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
3731 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
James Smart685f0bf2007-04-25 09:53:08 -04003732 sentplogi++;
James Smart2e0fef82007-06-17 19:56:36 -05003733 vport->num_disc_nodes++;
3734 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04003735 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05003736 spin_lock_irq(shost->host_lock);
3737 vport->fc_flag |= FC_NLP_MORE;
3738 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003739 break;
dea31012005-04-17 16:05:31 -05003740 }
3741 }
3742 }
James Smart87af33f2007-10-27 13:37:43 -04003743 if (sentplogi) {
3744 lpfc_set_disctmo(vport);
3745 }
3746 else {
James Smart2e0fef82007-06-17 19:56:36 -05003747 spin_lock_irq(shost->host_lock);
3748 vport->fc_flag &= ~FC_NLP_MORE;
3749 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003750 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003751 return sentplogi;
dea31012005-04-17 16:05:31 -05003752}
3753
James Smarte59058c2008-08-24 21:49:00 -04003754/**
3755 * lpfc_els_flush_rscn: Clean up any rscn activities with a vport.
3756 * @vport: pointer to a host virtual N_Port data structure.
3757 *
3758 * This routine cleans up any Registration State Change Notification
3759 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
3760 * @vport together with the host_lock is used to prevent multiple thread
3761 * trying to access the RSCN array on a same @vport at the same time.
3762 **/
James Smart92d7f7b2007-06-17 19:56:38 -05003763void
James Smart2e0fef82007-06-17 19:56:36 -05003764lpfc_els_flush_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003765{
James Smart2e0fef82007-06-17 19:56:36 -05003766 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3767 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003768 int i;
3769
James Smart7f5f3d02008-02-08 18:50:14 -05003770 spin_lock_irq(shost->host_lock);
3771 if (vport->fc_rscn_flush) {
3772 /* Another thread is walking fc_rscn_id_list on this vport */
3773 spin_unlock_irq(shost->host_lock);
3774 return;
3775 }
3776 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
3777 vport->fc_rscn_flush = 1;
3778 spin_unlock_irq(shost->host_lock);
3779
James Smart2e0fef82007-06-17 19:56:36 -05003780 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05003781 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
James Smart2e0fef82007-06-17 19:56:36 -05003782 vport->fc_rscn_id_list[i] = NULL;
dea31012005-04-17 16:05:31 -05003783 }
James Smart2e0fef82007-06-17 19:56:36 -05003784 spin_lock_irq(shost->host_lock);
3785 vport->fc_rscn_id_cnt = 0;
3786 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
3787 spin_unlock_irq(shost->host_lock);
3788 lpfc_can_disctmo(vport);
James Smart7f5f3d02008-02-08 18:50:14 -05003789 /* Indicate we are done walking this fc_rscn_id_list */
3790 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05003791}
3792
James Smarte59058c2008-08-24 21:49:00 -04003793/**
3794 * lpfc_rscn_payload_check: Check whether there is a pending rscn to a did.
3795 * @vport: pointer to a host virtual N_Port data structure.
3796 * @did: remote destination port identifier.
3797 *
3798 * This routine checks whether there is any pending Registration State
3799 * Configuration Notification (RSCN) to a @did on @vport.
3800 *
3801 * Return code
3802 * None zero - The @did matched with a pending rscn
3803 * 0 - not able to match @did with a pending rscn
3804 **/
dea31012005-04-17 16:05:31 -05003805int
James Smart2e0fef82007-06-17 19:56:36 -05003806lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05003807{
3808 D_ID ns_did;
3809 D_ID rscn_did;
dea31012005-04-17 16:05:31 -05003810 uint32_t *lp;
James Smart92d7f7b2007-06-17 19:56:38 -05003811 uint32_t payload_len, i;
James Smart7f5f3d02008-02-08 18:50:14 -05003812 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05003813
3814 ns_did.un.word = did;
dea31012005-04-17 16:05:31 -05003815
3816 /* Never match fabric nodes for RSCNs */
3817 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
James Smart2e0fef82007-06-17 19:56:36 -05003818 return 0;
dea31012005-04-17 16:05:31 -05003819
3820 /* If we are doing a FULL RSCN rediscovery, match everything */
James Smart2e0fef82007-06-17 19:56:36 -05003821 if (vport->fc_flag & FC_RSCN_DISCOVERY)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003822 return did;
dea31012005-04-17 16:05:31 -05003823
James Smart7f5f3d02008-02-08 18:50:14 -05003824 spin_lock_irq(shost->host_lock);
3825 if (vport->fc_rscn_flush) {
3826 /* Another thread is walking fc_rscn_id_list on this vport */
3827 spin_unlock_irq(shost->host_lock);
3828 return 0;
3829 }
3830 /* Indicate we are walking fc_rscn_id_list on this vport */
3831 vport->fc_rscn_flush = 1;
3832 spin_unlock_irq(shost->host_lock);
James Smart2e0fef82007-06-17 19:56:36 -05003833 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05003834 lp = vport->fc_rscn_id_list[i]->virt;
3835 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
3836 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05003837 while (payload_len) {
James Smart92d7f7b2007-06-17 19:56:38 -05003838 rscn_did.un.word = be32_to_cpu(*lp++);
3839 payload_len -= sizeof(uint32_t);
James Smarteaf15d52008-12-04 22:39:29 -05003840 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
3841 case RSCN_ADDRESS_FORMAT_PORT:
James Smart2e0fef82007-06-17 19:56:36 -05003842 if (ns_did.un.word == rscn_did.un.word)
James Smart7f5f3d02008-02-08 18:50:14 -05003843 goto return_did_out;
dea31012005-04-17 16:05:31 -05003844 break;
James Smarteaf15d52008-12-04 22:39:29 -05003845 case RSCN_ADDRESS_FORMAT_AREA:
dea31012005-04-17 16:05:31 -05003846 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
3847 && (ns_did.un.b.area == rscn_did.un.b.area))
James Smart7f5f3d02008-02-08 18:50:14 -05003848 goto return_did_out;
dea31012005-04-17 16:05:31 -05003849 break;
James Smarteaf15d52008-12-04 22:39:29 -05003850 case RSCN_ADDRESS_FORMAT_DOMAIN:
dea31012005-04-17 16:05:31 -05003851 if (ns_did.un.b.domain == rscn_did.un.b.domain)
James Smart7f5f3d02008-02-08 18:50:14 -05003852 goto return_did_out;
dea31012005-04-17 16:05:31 -05003853 break;
James Smarteaf15d52008-12-04 22:39:29 -05003854 case RSCN_ADDRESS_FORMAT_FABRIC:
James Smart7f5f3d02008-02-08 18:50:14 -05003855 goto return_did_out;
dea31012005-04-17 16:05:31 -05003856 }
3857 }
James Smart92d7f7b2007-06-17 19:56:38 -05003858 }
James Smart7f5f3d02008-02-08 18:50:14 -05003859 /* Indicate we are done with walking fc_rscn_id_list on this vport */
3860 vport->fc_rscn_flush = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05003861 return 0;
James Smart7f5f3d02008-02-08 18:50:14 -05003862return_did_out:
3863 /* Indicate we are done with walking fc_rscn_id_list on this vport */
3864 vport->fc_rscn_flush = 0;
3865 return did;
dea31012005-04-17 16:05:31 -05003866}
3867
James Smarte59058c2008-08-24 21:49:00 -04003868/**
3869 * lpfc_rscn_recovery_check: Send recovery event to vport nodes matching rscn
3870 * @vport: pointer to a host virtual N_Port data structure.
3871 *
3872 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
3873 * state machine for a @vport's nodes that are with pending RSCN (Registration
3874 * State Change Notification).
3875 *
3876 * Return code
3877 * 0 - Successful (currently alway return 0)
3878 **/
dea31012005-04-17 16:05:31 -05003879static int
James Smart2e0fef82007-06-17 19:56:36 -05003880lpfc_rscn_recovery_check(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003881{
James Smart685f0bf2007-04-25 09:53:08 -04003882 struct lpfc_nodelist *ndlp = NULL;
dea31012005-04-17 16:05:31 -05003883
James Smart0d2b6b82008-06-14 22:52:47 -04003884 /* Move all affected nodes by pending RSCNs to NPR state. */
James Smart2e0fef82007-06-17 19:56:36 -05003885 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05003886 if (!NLP_CHK_NODE_ACT(ndlp) ||
James Smart0d2b6b82008-06-14 22:52:47 -04003887 (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
3888 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
dea31012005-04-17 16:05:31 -05003889 continue;
James Smart2e0fef82007-06-17 19:56:36 -05003890 lpfc_disc_state_machine(vport, ndlp, NULL,
James Smart0d2b6b82008-06-14 22:52:47 -04003891 NLP_EVT_DEVICE_RECOVERY);
3892 lpfc_cancel_retry_delay_tmo(vport, ndlp);
dea31012005-04-17 16:05:31 -05003893 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003894 return 0;
dea31012005-04-17 16:05:31 -05003895}
3896
James Smarte59058c2008-08-24 21:49:00 -04003897/**
James Smartddcc50f2008-12-04 22:38:46 -05003898 * lpfc_send_rscn_event: Send an RSCN event to management application.
3899 * @vport: pointer to a host virtual N_Port data structure.
3900 * @cmdiocb: pointer to lpfc command iocb data structure.
3901 *
3902 * lpfc_send_rscn_event sends an RSCN netlink event to management
3903 * applications.
3904 */
3905static void
3906lpfc_send_rscn_event(struct lpfc_vport *vport,
3907 struct lpfc_iocbq *cmdiocb)
3908{
3909 struct lpfc_dmabuf *pcmd;
3910 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3911 uint32_t *payload_ptr;
3912 uint32_t payload_len;
3913 struct lpfc_rscn_event_header *rscn_event_data;
3914
3915 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3916 payload_ptr = (uint32_t *) pcmd->virt;
3917 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
3918
3919 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
3920 payload_len, GFP_KERNEL);
3921 if (!rscn_event_data) {
3922 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3923 "0147 Failed to allocate memory for RSCN event\n");
3924 return;
3925 }
3926 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
3927 rscn_event_data->payload_length = payload_len;
3928 memcpy(rscn_event_data->rscn_payload, payload_ptr,
3929 payload_len);
3930
3931 fc_host_post_vendor_event(shost,
3932 fc_get_event_number(),
3933 sizeof(struct lpfc_els_event_header) + payload_len,
3934 (char *)rscn_event_data,
3935 LPFC_NL_VENDOR_ID);
3936
3937 kfree(rscn_event_data);
3938}
3939
3940/**
James Smarte59058c2008-08-24 21:49:00 -04003941 * lpfc_els_rcv_rscn: Process an unsolicited rscn iocb.
3942 * @vport: pointer to a host virtual N_Port data structure.
3943 * @cmdiocb: pointer to lpfc command iocb data structure.
3944 * @ndlp: pointer to a node-list data structure.
3945 *
3946 * This routine processes an unsolicited RSCN (Registration State Change
3947 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
3948 * to invoke fc_host_post_event() routine to the FC transport layer. If the
3949 * discover state machine is about to begin discovery, it just accepts the
3950 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
3951 * contains N_Port IDs for other vports on this HBA, it just accepts the
3952 * RSCN and ignore processing it. If the state machine is in the recovery
3953 * state, the fc_rscn_id_list of this @vport is walked and the
3954 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
3955 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
3956 * routine is invoked to handle the RSCN event.
3957 *
3958 * Return code
3959 * 0 - Just sent the acc response
3960 * 1 - Sent the acc response and waited for name server completion
3961 **/
dea31012005-04-17 16:05:31 -05003962static int
James Smart2e0fef82007-06-17 19:56:36 -05003963lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04003964 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003965{
James Smart2e0fef82007-06-17 19:56:36 -05003966 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3967 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003968 struct lpfc_dmabuf *pcmd;
James Smart92d7f7b2007-06-17 19:56:38 -05003969 uint32_t *lp, *datap;
dea31012005-04-17 16:05:31 -05003970 IOCB_t *icmd;
James Smart92d7f7b2007-06-17 19:56:38 -05003971 uint32_t payload_len, length, nportid, *cmd;
James Smart7f5f3d02008-02-08 18:50:14 -05003972 int rscn_cnt;
James Smart92d7f7b2007-06-17 19:56:38 -05003973 int rscn_id = 0, hba_id = 0;
James Smartd2873e42006-08-18 17:46:43 -04003974 int i;
dea31012005-04-17 16:05:31 -05003975
3976 icmd = &cmdiocb->iocb;
3977 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
3978 lp = (uint32_t *) pcmd->virt;
3979
James Smart92d7f7b2007-06-17 19:56:38 -05003980 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
3981 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05003982 /* RSCN received */
James Smarte8b62012007-08-02 11:10:09 -04003983 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3984 "0214 RSCN received Data: x%x x%x x%x x%x\n",
James Smart7f5f3d02008-02-08 18:50:14 -05003985 vport->fc_flag, payload_len, *lp,
3986 vport->fc_rscn_id_cnt);
James Smartddcc50f2008-12-04 22:38:46 -05003987
3988 /* Send an RSCN event to the management application */
3989 lpfc_send_rscn_event(vport, cmdiocb);
3990
James Smartd2873e42006-08-18 17:46:43 -04003991 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
James Smart2e0fef82007-06-17 19:56:36 -05003992 fc_host_post_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04003993 FCH_EVT_RSCN, lp[i]);
3994
dea31012005-04-17 16:05:31 -05003995 /* If we are about to begin discovery, just ACC the RSCN.
3996 * Discovery processing will satisfy it.
3997 */
James Smart2e0fef82007-06-17 19:56:36 -05003998 if (vport->port_state <= LPFC_NS_QRY) {
James Smart858c9f62007-06-17 19:56:39 -05003999 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4000 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
4001 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4002
James Smart51ef4c22007-08-02 11:10:31 -04004003 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004004 return 0;
dea31012005-04-17 16:05:31 -05004005 }
4006
James Smart92d7f7b2007-06-17 19:56:38 -05004007 /* If this RSCN just contains NPortIDs for other vports on this HBA,
4008 * just ACC and ignore it.
4009 */
4010 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart3de2a652007-08-02 11:09:59 -04004011 !(vport->cfg_peer_port_login)) {
James Smart92d7f7b2007-06-17 19:56:38 -05004012 i = payload_len;
4013 datap = lp;
4014 while (i > 0) {
4015 nportid = *datap++;
4016 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
4017 i -= sizeof(uint32_t);
4018 rscn_id++;
James Smart549e55c2007-08-02 11:09:51 -04004019 if (lpfc_find_vport_by_did(phba, nportid))
4020 hba_id++;
James Smart92d7f7b2007-06-17 19:56:38 -05004021 }
4022 if (rscn_id == hba_id) {
4023 /* ALL NPortIDs in RSCN are on HBA */
James Smarte8b62012007-08-02 11:10:09 -04004024 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -04004025 "0219 Ignore RSCN "
James Smarte8b62012007-08-02 11:10:09 -04004026 "Data: x%x x%x x%x x%x\n",
4027 vport->fc_flag, payload_len,
James Smart7f5f3d02008-02-08 18:50:14 -05004028 *lp, vport->fc_rscn_id_cnt);
James Smart858c9f62007-06-17 19:56:39 -05004029 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4030 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
4031 ndlp->nlp_DID, vport->port_state,
4032 ndlp->nlp_flag);
4033
James Smart92d7f7b2007-06-17 19:56:38 -05004034 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004035 ndlp, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05004036 return 0;
4037 }
4038 }
4039
James Smart7f5f3d02008-02-08 18:50:14 -05004040 spin_lock_irq(shost->host_lock);
4041 if (vport->fc_rscn_flush) {
4042 /* Another thread is walking fc_rscn_id_list on this vport */
4043 spin_unlock_irq(shost->host_lock);
4044 vport->fc_flag |= FC_RSCN_DISCOVERY;
James Smart58da1ff2008-04-07 10:15:56 -04004045 /* Send back ACC */
4046 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart7f5f3d02008-02-08 18:50:14 -05004047 return 0;
4048 }
4049 /* Indicate we are walking fc_rscn_id_list on this vport */
4050 vport->fc_rscn_flush = 1;
4051 spin_unlock_irq(shost->host_lock);
4052 /* Get the array count after sucessfully have the token */
4053 rscn_cnt = vport->fc_rscn_id_cnt;
dea31012005-04-17 16:05:31 -05004054 /* If we are already processing an RSCN, save the received
4055 * RSCN payload buffer, cmdiocb->context2 to process later.
4056 */
James Smart2e0fef82007-06-17 19:56:36 -05004057 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
James Smart858c9f62007-06-17 19:56:39 -05004058 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4059 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
4060 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4061
James Smart09372822008-01-11 01:52:54 -05004062 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004063 vport->fc_flag |= FC_RSCN_DEFERRED;
4064 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
James Smart2e0fef82007-06-17 19:56:36 -05004065 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
James Smart2e0fef82007-06-17 19:56:36 -05004066 vport->fc_flag |= FC_RSCN_MODE;
4067 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004068 if (rscn_cnt) {
4069 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
4070 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
4071 }
4072 if ((rscn_cnt) &&
4073 (payload_len + length <= LPFC_BPL_SIZE)) {
4074 *cmd &= ELS_CMD_MASK;
James Smart7f5f3d02008-02-08 18:50:14 -05004075 *cmd |= cpu_to_be32(payload_len + length);
James Smart92d7f7b2007-06-17 19:56:38 -05004076 memcpy(((uint8_t *)cmd) + length, lp,
4077 payload_len);
4078 } else {
4079 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
4080 vport->fc_rscn_id_cnt++;
4081 /* If we zero, cmdiocb->context2, the calling
4082 * routine will not try to free it.
4083 */
4084 cmdiocb->context2 = NULL;
4085 }
dea31012005-04-17 16:05:31 -05004086 /* Deferred RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004087 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4088 "0235 Deferred RSCN "
4089 "Data: x%x x%x x%x\n",
4090 vport->fc_rscn_id_cnt, vport->fc_flag,
4091 vport->port_state);
dea31012005-04-17 16:05:31 -05004092 } else {
James Smart2e0fef82007-06-17 19:56:36 -05004093 vport->fc_flag |= FC_RSCN_DISCOVERY;
4094 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004095 /* ReDiscovery RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004096 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4097 "0234 ReDiscovery RSCN "
4098 "Data: x%x x%x x%x\n",
4099 vport->fc_rscn_id_cnt, vport->fc_flag,
4100 vport->port_state);
dea31012005-04-17 16:05:31 -05004101 }
James Smart7f5f3d02008-02-08 18:50:14 -05004102 /* Indicate we are done walking fc_rscn_id_list on this vport */
4103 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004104 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004105 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004106 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004107 lpfc_rscn_recovery_check(vport);
James Smart09372822008-01-11 01:52:54 -05004108 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004109 vport->fc_flag &= ~FC_RSCN_DEFERRED;
James Smart09372822008-01-11 01:52:54 -05004110 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004111 return 0;
dea31012005-04-17 16:05:31 -05004112 }
James Smart858c9f62007-06-17 19:56:39 -05004113 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4114 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
4115 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4116
James Smart2e0fef82007-06-17 19:56:36 -05004117 spin_lock_irq(shost->host_lock);
4118 vport->fc_flag |= FC_RSCN_MODE;
4119 spin_unlock_irq(shost->host_lock);
4120 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
James Smart7f5f3d02008-02-08 18:50:14 -05004121 /* Indicate we are done walking fc_rscn_id_list on this vport */
4122 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004123 /*
4124 * If we zero, cmdiocb->context2, the calling routine will
4125 * not try to free it.
4126 */
4127 cmdiocb->context2 = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05004128 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004129 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004130 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004131 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004132 lpfc_rscn_recovery_check(vport);
James Smart2e0fef82007-06-17 19:56:36 -05004133 return lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05004134}
4135
James Smarte59058c2008-08-24 21:49:00 -04004136/**
4137 * lpfc_els_handle_rscn: Handle rscn for a vport.
4138 * @vport: pointer to a host virtual N_Port data structure.
4139 *
4140 * This routine handles the Registration State Configuration Notification
4141 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
4142 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
4143 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
4144 * NameServer shall be issued. If CT command to the NameServer fails to be
4145 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
4146 * RSCN activities with the @vport.
4147 *
4148 * Return code
4149 * 0 - Cleaned up rscn on the @vport
4150 * 1 - Wait for plogi to name server before proceed
4151 **/
dea31012005-04-17 16:05:31 -05004152int
James Smart2e0fef82007-06-17 19:56:36 -05004153lpfc_els_handle_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004154{
4155 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004156 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004157
James Smart92d7f7b2007-06-17 19:56:38 -05004158 /* Ignore RSCN if the port is being torn down. */
4159 if (vport->load_flag & FC_UNLOADING) {
4160 lpfc_els_flush_rscn(vport);
4161 return 0;
4162 }
4163
dea31012005-04-17 16:05:31 -05004164 /* Start timer for RSCN processing */
James Smart2e0fef82007-06-17 19:56:36 -05004165 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004166
4167 /* RSCN processed */
James Smarte8b62012007-08-02 11:10:09 -04004168 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4169 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
4170 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
4171 vport->port_state);
dea31012005-04-17 16:05:31 -05004172
4173 /* To process RSCN, first compare RSCN data with NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004174 vport->fc_ns_retry = 0;
James Smart0ff10d42008-01-11 01:52:36 -05004175 vport->num_disc_nodes = 0;
4176
James Smart2e0fef82007-06-17 19:56:36 -05004177 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004178 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
4179 && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
dea31012005-04-17 16:05:31 -05004180 /* Good ndlp, issue CT Request to NameServer */
James Smart92d7f7b2007-06-17 19:56:38 -05004181 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
dea31012005-04-17 16:05:31 -05004182 /* Wait for NameServer query cmpl before we can
4183 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004184 return 1;
dea31012005-04-17 16:05:31 -05004185 } else {
4186 /* If login to NameServer does not exist, issue one */
4187 /* Good status, issue PLOGI to NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004188 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004189 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
dea31012005-04-17 16:05:31 -05004190 /* Wait for NameServer login cmpl before we can
4191 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004192 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05004193
James Smarte47c9092008-02-08 18:49:26 -05004194 if (ndlp) {
4195 ndlp = lpfc_enable_node(vport, ndlp,
4196 NLP_STE_PLOGI_ISSUE);
4197 if (!ndlp) {
4198 lpfc_els_flush_rscn(vport);
4199 return 0;
4200 }
4201 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
dea31012005-04-17 16:05:31 -05004202 } else {
James Smarte47c9092008-02-08 18:49:26 -05004203 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
4204 if (!ndlp) {
4205 lpfc_els_flush_rscn(vport);
4206 return 0;
4207 }
James Smart2e0fef82007-06-17 19:56:36 -05004208 lpfc_nlp_init(vport, ndlp, NameServer_DID);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004209 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004210 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
dea31012005-04-17 16:05:31 -05004211 }
James Smarte47c9092008-02-08 18:49:26 -05004212 ndlp->nlp_type |= NLP_FABRIC;
4213 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
4214 /* Wait for NameServer login cmpl before we can
4215 * continue
4216 */
4217 return 1;
dea31012005-04-17 16:05:31 -05004218 }
4219
James Smart2e0fef82007-06-17 19:56:36 -05004220 lpfc_els_flush_rscn(vport);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004221 return 0;
dea31012005-04-17 16:05:31 -05004222}
4223
James Smarte59058c2008-08-24 21:49:00 -04004224/**
4225 * lpfc_els_rcv_flogi: Process an unsolicited flogi iocb.
4226 * @vport: pointer to a host virtual N_Port data structure.
4227 * @cmdiocb: pointer to lpfc command iocb data structure.
4228 * @ndlp: pointer to a node-list data structure.
4229 *
4230 * This routine processes Fabric Login (FLOGI) IOCB received as an ELS
4231 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
4232 * point topology. As an unsolicited FLOGI should not be received in a loop
4233 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
4234 * lpfc_check_sparm() routine is invoked to check the parameters in the
4235 * unsolicited FLOGI. If parameters validation failed, the routine
4236 * lpfc_els_rsp_reject() shall be called with reject reason code set to
4237 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
4238 * FLOGI shall be compared with the Port WWN of the @vport to determine who
4239 * will initiate PLOGI. The higher lexicographical value party shall has
4240 * higher priority (as the winning port) and will initiate PLOGI and
4241 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
4242 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
4243 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
4244 *
4245 * Return code
4246 * 0 - Successfully processed the unsolicited flogi
4247 * 1 - Failed to process the unsolicited flogi
4248 **/
dea31012005-04-17 16:05:31 -05004249static int
James Smart2e0fef82007-06-17 19:56:36 -05004250lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004251 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004252{
James Smart2e0fef82007-06-17 19:56:36 -05004253 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4254 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004255 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4256 uint32_t *lp = (uint32_t *) pcmd->virt;
4257 IOCB_t *icmd = &cmdiocb->iocb;
4258 struct serv_parm *sp;
4259 LPFC_MBOXQ_t *mbox;
4260 struct ls_rjt stat;
4261 uint32_t cmd, did;
4262 int rc;
4263
4264 cmd = *lp++;
4265 sp = (struct serv_parm *) lp;
4266
4267 /* FLOGI received */
4268
James Smart2e0fef82007-06-17 19:56:36 -05004269 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004270
4271 if (phba->fc_topology == TOPOLOGY_LOOP) {
4272 /* We should never receive a FLOGI in loop mode, ignore it */
4273 did = icmd->un.elsreq64.remoteID;
4274
4275 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
4276 Loop Mode */
James Smarte8b62012007-08-02 11:10:09 -04004277 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4278 "0113 An FLOGI ELS command x%x was "
4279 "received from DID x%x in Loop Mode\n",
4280 cmd, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004281 return 1;
dea31012005-04-17 16:05:31 -05004282 }
4283
4284 did = Fabric_DID;
4285
James Smart2e0fef82007-06-17 19:56:36 -05004286 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3))) {
dea31012005-04-17 16:05:31 -05004287 /* For a FLOGI we accept, then if our portname is greater
4288 * then the remote portname we initiate Nport login.
4289 */
4290
James Smart2e0fef82007-06-17 19:56:36 -05004291 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -05004292 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004293
4294 if (!rc) {
James Smart2e0fef82007-06-17 19:56:36 -05004295 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4296 if (!mbox)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004297 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05004298
dea31012005-04-17 16:05:31 -05004299 lpfc_linkdown(phba);
4300 lpfc_init_link(phba, mbox,
4301 phba->cfg_topology,
4302 phba->cfg_link_speed);
4303 mbox->mb.un.varInitLnk.lipsr_AL_PA = 0;
4304 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -05004305 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -04004306 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart5b8bd0c2007-04-25 09:52:49 -04004307 lpfc_set_loopback_flag(phba);
dea31012005-04-17 16:05:31 -05004308 if (rc == MBX_NOT_FINISHED) {
James Smart329f9bc2007-04-25 09:53:01 -04004309 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004310 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004311 return 1;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004312 } else if (rc > 0) { /* greater than */
James Smart2e0fef82007-06-17 19:56:36 -05004313 spin_lock_irq(shost->host_lock);
4314 vport->fc_flag |= FC_PT2PT_PLOGI;
4315 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004316 }
James Smart2e0fef82007-06-17 19:56:36 -05004317 spin_lock_irq(shost->host_lock);
4318 vport->fc_flag |= FC_PT2PT;
4319 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
4320 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004321 } else {
4322 /* Reject this request because invalid parameters */
4323 stat.un.b.lsRjtRsvd0 = 0;
4324 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4325 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
4326 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004327 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4328 NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004329 return 1;
dea31012005-04-17 16:05:31 -05004330 }
4331
4332 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004333 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004334
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004335 return 0;
dea31012005-04-17 16:05:31 -05004336}
4337
James Smarte59058c2008-08-24 21:49:00 -04004338/**
4339 * lpfc_els_rcv_rnid: Process an unsolicited rnid iocb.
4340 * @vport: pointer to a host virtual N_Port data structure.
4341 * @cmdiocb: pointer to lpfc command iocb data structure.
4342 * @ndlp: pointer to a node-list data structure.
4343 *
4344 * This routine processes Request Node Identification Data (RNID) IOCB
4345 * received as an ELS unsolicited event. Only when the RNID specified format
4346 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
4347 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
4348 * Accept (ACC) the RNID ELS command. All the other RNID formats are
4349 * rejected by invoking the lpfc_els_rsp_reject() routine.
4350 *
4351 * Return code
4352 * 0 - Successfully processed rnid iocb (currently always return 0)
4353 **/
dea31012005-04-17 16:05:31 -05004354static int
James Smart2e0fef82007-06-17 19:56:36 -05004355lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4356 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004357{
4358 struct lpfc_dmabuf *pcmd;
4359 uint32_t *lp;
4360 IOCB_t *icmd;
4361 RNID *rn;
4362 struct ls_rjt stat;
4363 uint32_t cmd, did;
4364
4365 icmd = &cmdiocb->iocb;
4366 did = icmd->un.elsreq64.remoteID;
4367 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4368 lp = (uint32_t *) pcmd->virt;
4369
4370 cmd = *lp++;
4371 rn = (RNID *) lp;
4372
4373 /* RNID received */
4374
4375 switch (rn->Format) {
4376 case 0:
4377 case RNID_TOPOLOGY_DISC:
4378 /* Send back ACC */
James Smart2e0fef82007-06-17 19:56:36 -05004379 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05004380 break;
4381 default:
4382 /* Reject this request because format not supported */
4383 stat.un.b.lsRjtRsvd0 = 0;
4384 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4385 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4386 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004387 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4388 NULL);
dea31012005-04-17 16:05:31 -05004389 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004390 return 0;
dea31012005-04-17 16:05:31 -05004391}
4392
James Smarte59058c2008-08-24 21:49:00 -04004393/**
4394 * lpfc_els_rcv_lirr: Process an unsolicited lirr iocb.
4395 * @vport: pointer to a host virtual N_Port data structure.
4396 * @cmdiocb: pointer to lpfc command iocb data structure.
4397 * @ndlp: pointer to a node-list data structure.
4398 *
4399 * This routine processes a Link Incident Report Registration(LIRR) IOCB
4400 * received as an ELS unsolicited event. Currently, this function just invokes
4401 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
4402 *
4403 * Return code
4404 * 0 - Successfully processed lirr iocb (currently always return 0)
4405 **/
dea31012005-04-17 16:05:31 -05004406static int
James Smart2e0fef82007-06-17 19:56:36 -05004407lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4408 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004409{
4410 struct ls_rjt stat;
4411
4412 /* For now, unconditionally reject this command */
4413 stat.un.b.lsRjtRsvd0 = 0;
4414 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4415 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4416 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004417 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004418 return 0;
4419}
4420
James Smarte59058c2008-08-24 21:49:00 -04004421/**
4422 * lpfc_els_rsp_rps_acc: Completion callbk func for MBX_READ_LNK_STAT mbox cmd.
4423 * @phba: pointer to lpfc hba data structure.
4424 * @pmb: pointer to the driver internal queue element for mailbox command.
4425 *
4426 * This routine is the completion callback function for the MBX_READ_LNK_STAT
4427 * mailbox command. This callback function is to actually send the Accept
4428 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
4429 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
4430 * mailbox command, constructs the RPS response with the link statistics
4431 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
4432 * response to the RPS.
4433 *
4434 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4435 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4436 * will be stored into the context1 field of the IOCB for the completion
4437 * callback function to the RPS Accept Response ELS IOCB command.
4438 *
4439 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05004440static void
James Smart329f9bc2007-04-25 09:53:01 -04004441lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004442{
James Smart2e0fef82007-06-17 19:56:36 -05004443 struct lpfc_sli *psli = &phba->sli;
4444 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004445 MAILBOX_t *mb;
4446 IOCB_t *icmd;
4447 RPS_RSP *rps_rsp;
4448 uint8_t *pcmd;
4449 struct lpfc_iocbq *elsiocb;
4450 struct lpfc_nodelist *ndlp;
4451 uint16_t xri, status;
4452 uint32_t cmdsize;
4453
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004454 mb = &pmb->mb;
4455
4456 ndlp = (struct lpfc_nodelist *) pmb->context2;
4457 xri = (uint16_t) ((unsigned long)(pmb->context1));
Randy Dunlap041976f2006-06-25 01:58:51 -07004458 pmb->context1 = NULL;
4459 pmb->context2 = NULL;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004460
4461 if (mb->mbxStatus) {
James Smart329f9bc2007-04-25 09:53:01 -04004462 mempool_free(pmb, phba->mbox_mem_pool);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004463 return;
4464 }
4465
4466 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
James Smart329f9bc2007-04-25 09:53:01 -04004467 mempool_free(pmb, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05004468 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
4469 lpfc_max_els_tries, ndlp,
4470 ndlp->nlp_DID, ELS_CMD_ACC);
James Smartfa4066b2008-01-11 01:53:27 -05004471
4472 /* Decrement the ndlp reference count from previous mbox command */
James Smart329f9bc2007-04-25 09:53:01 -04004473 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05004474
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004475 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004476 return;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004477
4478 icmd = &elsiocb->iocb;
4479 icmd->ulpContext = xri;
4480
4481 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4482 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004483 pcmd += sizeof(uint32_t); /* Skip past command */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004484 rps_rsp = (RPS_RSP *)pcmd;
4485
4486 if (phba->fc_topology != TOPOLOGY_LOOP)
4487 status = 0x10;
4488 else
4489 status = 0x8;
James Smart2e0fef82007-06-17 19:56:36 -05004490 if (phba->pport->fc_flag & FC_FABRIC)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004491 status |= 0x4;
4492
4493 rps_rsp->rsvd1 = 0;
James Smart09372822008-01-11 01:52:54 -05004494 rps_rsp->portStatus = cpu_to_be16(status);
4495 rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
4496 rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
4497 rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
4498 rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
4499 rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
4500 rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004501 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004502 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
4503 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
4504 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
4505 elsiocb->iotag, elsiocb->iocb.ulpContext,
4506 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4507 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05004508 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004509 phba->fc_stat.elsXmitACC++;
James Smarted957682007-06-17 19:56:37 -05004510 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004511 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004512 return;
4513}
4514
James Smarte59058c2008-08-24 21:49:00 -04004515/**
4516 * lpfc_els_rcv_rps: Process an unsolicited rps iocb.
4517 * @vport: pointer to a host virtual N_Port data structure.
4518 * @cmdiocb: pointer to lpfc command iocb data structure.
4519 * @ndlp: pointer to a node-list data structure.
4520 *
4521 * This routine processes Read Port Status (RPS) IOCB received as an
4522 * ELS unsolicited event. It first checks the remote port state. If the
4523 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
4524 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
4525 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
4526 * for reading the HBA link statistics. It is for the callback function,
4527 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
4528 * to actually sending out RPS Accept (ACC) response.
4529 *
4530 * Return codes
4531 * 0 - Successfully processed rps iocb (currently always return 0)
4532 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004533static int
James Smart2e0fef82007-06-17 19:56:36 -05004534lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4535 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004536{
James Smart2e0fef82007-06-17 19:56:36 -05004537 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004538 uint32_t *lp;
4539 uint8_t flag;
4540 LPFC_MBOXQ_t *mbox;
4541 struct lpfc_dmabuf *pcmd;
4542 RPS *rps;
4543 struct ls_rjt stat;
4544
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004545 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
James Smart90160e02008-08-24 21:49:45 -04004546 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
4547 /* reject the unsolicited RPS request and done with it */
4548 goto reject_out;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004549
4550 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4551 lp = (uint32_t *) pcmd->virt;
4552 flag = (be32_to_cpu(*lp++) & 0xf);
4553 rps = (RPS *) lp;
4554
4555 if ((flag == 0) ||
4556 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
James Smart2e0fef82007-06-17 19:56:36 -05004557 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05004558 sizeof(struct lpfc_name)) == 0))) {
James Smart2e0fef82007-06-17 19:56:36 -05004559
James Smart92d7f7b2007-06-17 19:56:38 -05004560 printk("Fix me....\n");
4561 dump_stack();
James Smart2e0fef82007-06-17 19:56:36 -05004562 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
4563 if (mbox) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004564 lpfc_read_lnk_stat(phba, mbox);
4565 mbox->context1 =
James Smart92d7f7b2007-06-17 19:56:38 -05004566 (void *)((unsigned long) cmdiocb->iocb.ulpContext);
James Smart329f9bc2007-04-25 09:53:01 -04004567 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05004568 mbox->vport = vport;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004569 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
James Smartfa4066b2008-01-11 01:53:27 -05004570 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart0b727fe2007-10-27 13:37:25 -04004571 != MBX_NOT_FINISHED)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004572 /* Mbox completion will send ELS Response */
4573 return 0;
James Smartfa4066b2008-01-11 01:53:27 -05004574 /* Decrement reference count used for the failed mbox
4575 * command.
4576 */
James Smart329f9bc2007-04-25 09:53:01 -04004577 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004578 mempool_free(mbox, phba->mbox_mem_pool);
4579 }
4580 }
James Smart90160e02008-08-24 21:49:45 -04004581
4582reject_out:
4583 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004584 stat.un.b.lsRjtRsvd0 = 0;
4585 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4586 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4587 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004588 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004589 return 0;
4590}
4591
James Smarte59058c2008-08-24 21:49:00 -04004592/**
4593 * lpfc_els_rsp_rpl_acc: Issue an accept rpl els command.
4594 * @vport: pointer to a host virtual N_Port data structure.
4595 * @cmdsize: size of the ELS command.
4596 * @oldiocb: pointer to the original lpfc command iocb data structure.
4597 * @ndlp: pointer to a node-list data structure.
4598 *
4599 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
4600 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
4601 *
4602 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4603 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4604 * will be stored into the context1 field of the IOCB for the completion
4605 * callback function to the RPL Accept Response ELS command.
4606 *
4607 * Return code
4608 * 0 - Successfully issued ACC RPL ELS command
4609 * 1 - Failed to issue ACC RPL ELS command
4610 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05004611static int
James Smart2e0fef82007-06-17 19:56:36 -05004612lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
4613 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004614{
James Smart2e0fef82007-06-17 19:56:36 -05004615 struct lpfc_hba *phba = vport->phba;
4616 IOCB_t *icmd, *oldcmd;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004617 RPL_RSP rpl_rsp;
4618 struct lpfc_iocbq *elsiocb;
James Smart2e0fef82007-06-17 19:56:36 -05004619 struct lpfc_sli *psli = &phba->sli;
4620 struct lpfc_sli_ring *pring = &psli->ring[LPFC_ELS_RING];
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004621 uint8_t *pcmd;
4622
James Smart2e0fef82007-06-17 19:56:36 -05004623 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4624 ndlp->nlp_DID, ELS_CMD_ACC);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004625
James Smart488d1462006-03-07 15:02:37 -05004626 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004627 return 1;
James Smart488d1462006-03-07 15:02:37 -05004628
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004629 icmd = &elsiocb->iocb;
4630 oldcmd = &oldiocb->iocb;
4631 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
4632
4633 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4634 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004635 pcmd += sizeof(uint16_t);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004636 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
4637 pcmd += sizeof(uint16_t);
4638
4639 /* Setup the RPL ACC payload */
4640 rpl_rsp.listLen = be32_to_cpu(1);
4641 rpl_rsp.index = 0;
4642 rpl_rsp.port_num_blk.portNum = 0;
James Smart2e0fef82007-06-17 19:56:36 -05004643 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
4644 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004645 sizeof(struct lpfc_name));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004646 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004647 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004648 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4649 "0120 Xmit ELS RPL ACC response tag x%x "
4650 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
4651 "rpi x%x\n",
4652 elsiocb->iotag, elsiocb->iocb.ulpContext,
4653 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4654 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05004655 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004656 phba->fc_stat.elsXmitACC++;
4657 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
4658 lpfc_els_free_iocb(phba, elsiocb);
4659 return 1;
4660 }
4661 return 0;
4662}
4663
James Smarte59058c2008-08-24 21:49:00 -04004664/**
4665 * lpfc_els_rcv_rpl: Process an unsolicited rpl iocb.
4666 * @vport: pointer to a host virtual N_Port data structure.
4667 * @cmdiocb: pointer to lpfc command iocb data structure.
4668 * @ndlp: pointer to a node-list data structure.
4669 *
4670 * This routine processes Read Port List (RPL) IOCB received as an ELS
4671 * unsolicited event. It first checks the remote port state. If the remote
4672 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
4673 * invokes the lpfc_els_rsp_reject() routine to send reject response.
4674 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
4675 * to accept the RPL.
4676 *
4677 * Return code
4678 * 0 - Successfully processed rpl iocb (currently always return 0)
4679 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004680static int
James Smart2e0fef82007-06-17 19:56:36 -05004681lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4682 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004683{
4684 struct lpfc_dmabuf *pcmd;
4685 uint32_t *lp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004686 uint32_t maxsize;
4687 uint16_t cmdsize;
4688 RPL *rpl;
4689 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05004690
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004691 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
4692 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
James Smart90160e02008-08-24 21:49:45 -04004693 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004694 stat.un.b.lsRjtRsvd0 = 0;
4695 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4696 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4697 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004698 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4699 NULL);
James Smart90160e02008-08-24 21:49:45 -04004700 /* rejected the unsolicited RPL request and done with it */
4701 return 0;
dea31012005-04-17 16:05:31 -05004702 }
4703
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004704 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4705 lp = (uint32_t *) pcmd->virt;
4706 rpl = (RPL *) (lp + 1);
4707
4708 maxsize = be32_to_cpu(rpl->maxsize);
4709
4710 /* We support only one port */
4711 if ((rpl->index == 0) &&
4712 ((maxsize == 0) ||
4713 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
4714 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004715 } else {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004716 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
4717 }
James Smart2e0fef82007-06-17 19:56:36 -05004718 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05004719
4720 return 0;
4721}
4722
James Smarte59058c2008-08-24 21:49:00 -04004723/**
4724 * lpfc_els_rcv_farp: Process an unsolicited farp request els command.
4725 * @vport: pointer to a virtual N_Port data structure.
4726 * @cmdiocb: pointer to lpfc command iocb data structure.
4727 * @ndlp: pointer to a node-list data structure.
4728 *
4729 * This routine processes Fibre Channel Address Resolution Protocol
4730 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
4731 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
4732 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
4733 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
4734 * remote PortName is compared against the FC PortName stored in the @vport
4735 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
4736 * compared against the FC NodeName stored in the @vport data structure.
4737 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
4738 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
4739 * invoked to send out FARP Response to the remote node. Before sending the
4740 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
4741 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
4742 * routine is invoked to log into the remote port first.
4743 *
4744 * Return code
4745 * 0 - Either the FARP Match Mode not supported or successfully processed
4746 **/
dea31012005-04-17 16:05:31 -05004747static int
James Smart2e0fef82007-06-17 19:56:36 -05004748lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4749 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004750{
4751 struct lpfc_dmabuf *pcmd;
4752 uint32_t *lp;
4753 IOCB_t *icmd;
4754 FARP *fp;
4755 uint32_t cmd, cnt, did;
4756
4757 icmd = &cmdiocb->iocb;
4758 did = icmd->un.elsreq64.remoteID;
4759 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4760 lp = (uint32_t *) pcmd->virt;
4761
4762 cmd = *lp++;
4763 fp = (FARP *) lp;
dea31012005-04-17 16:05:31 -05004764 /* FARP-REQ received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04004765 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4766 "0601 FARP-REQ received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05004767 /* We will only support match on WWPN or WWNN */
4768 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004769 return 0;
dea31012005-04-17 16:05:31 -05004770 }
4771
4772 cnt = 0;
4773 /* If this FARP command is searching for my portname */
4774 if (fp->Mflags & FARP_MATCH_PORT) {
James Smart2e0fef82007-06-17 19:56:36 -05004775 if (memcmp(&fp->RportName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05004776 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05004777 cnt = 1;
4778 }
4779
4780 /* If this FARP command is searching for my nodename */
4781 if (fp->Mflags & FARP_MATCH_NODE) {
James Smart2e0fef82007-06-17 19:56:36 -05004782 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05004783 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05004784 cnt = 1;
4785 }
4786
4787 if (cnt) {
4788 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
4789 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
4790 /* Log back into the node before sending the FARP. */
4791 if (fp->Rflags & FARP_REQUEST_PLOGI) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004792 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004793 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04004794 NLP_STE_PLOGI_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05004795 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05004796 }
4797
4798 /* Send a FARP response to that node */
James Smart2e0fef82007-06-17 19:56:36 -05004799 if (fp->Rflags & FARP_REQUEST_FARPR)
4800 lpfc_issue_els_farpr(vport, did, 0);
dea31012005-04-17 16:05:31 -05004801 }
4802 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004803 return 0;
dea31012005-04-17 16:05:31 -05004804}
4805
James Smarte59058c2008-08-24 21:49:00 -04004806/**
4807 * lpfc_els_rcv_farpr: Process an unsolicited farp response iocb.
4808 * @vport: pointer to a host virtual N_Port data structure.
4809 * @cmdiocb: pointer to lpfc command iocb data structure.
4810 * @ndlp: pointer to a node-list data structure.
4811 *
4812 * This routine processes Fibre Channel Address Resolution Protocol
4813 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
4814 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
4815 * the FARP response request.
4816 *
4817 * Return code
4818 * 0 - Successfully processed FARPR IOCB (currently always return 0)
4819 **/
dea31012005-04-17 16:05:31 -05004820static int
James Smart2e0fef82007-06-17 19:56:36 -05004821lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4822 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004823{
4824 struct lpfc_dmabuf *pcmd;
4825 uint32_t *lp;
4826 IOCB_t *icmd;
4827 uint32_t cmd, did;
4828
4829 icmd = &cmdiocb->iocb;
4830 did = icmd->un.elsreq64.remoteID;
4831 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4832 lp = (uint32_t *) pcmd->virt;
4833
4834 cmd = *lp++;
4835 /* FARP-RSP received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04004836 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4837 "0600 FARP-RSP received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05004838 /* ACCEPT the Farp resp request */
James Smart51ef4c22007-08-02 11:10:31 -04004839 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004840
4841 return 0;
4842}
4843
James Smarte59058c2008-08-24 21:49:00 -04004844/**
4845 * lpfc_els_rcv_fan: Process an unsolicited fan iocb command.
4846 * @vport: pointer to a host virtual N_Port data structure.
4847 * @cmdiocb: pointer to lpfc command iocb data structure.
4848 * @fan_ndlp: pointer to a node-list data structure.
4849 *
4850 * This routine processes a Fabric Address Notification (FAN) IOCB
4851 * command received as an ELS unsolicited event. The FAN ELS command will
4852 * only be processed on a physical port (i.e., the @vport represents the
4853 * physical port). The fabric NodeName and PortName from the FAN IOCB are
4854 * compared against those in the phba data structure. If any of those is
4855 * different, the lpfc_initial_flogi() routine is invoked to initialize
4856 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
4857 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
4858 * is invoked to register login to the fabric.
4859 *
4860 * Return code
4861 * 0 - Successfully processed fan iocb (currently always return 0).
4862 **/
dea31012005-04-17 16:05:31 -05004863static int
James Smart2e0fef82007-06-17 19:56:36 -05004864lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4865 struct lpfc_nodelist *fan_ndlp)
dea31012005-04-17 16:05:31 -05004866{
James Smart2e0fef82007-06-17 19:56:36 -05004867 struct lpfc_hba *phba = vport->phba;
James Smart0d2b6b82008-06-14 22:52:47 -04004868 uint32_t *lp;
4869 FAN *fp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004870
James Smart0d2b6b82008-06-14 22:52:47 -04004871 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
4872 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
4873 fp = (FAN *) ++lp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004874 /* FAN received; Fan does not have a reply sequence */
James Smart0d2b6b82008-06-14 22:52:47 -04004875 if ((vport == phba->pport) &&
4876 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004877 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
James Smart0d2b6b82008-06-14 22:52:47 -04004878 sizeof(struct lpfc_name))) ||
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004879 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
James Smart0d2b6b82008-06-14 22:52:47 -04004880 sizeof(struct lpfc_name)))) {
4881 /* This port has switched fabrics. FLOGI is required */
James Smart2e0fef82007-06-17 19:56:36 -05004882 lpfc_initial_flogi(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04004883 } else {
4884 /* FAN verified - skip FLOGI */
4885 vport->fc_myDID = vport->fc_prevDID;
4886 lpfc_issue_fabric_reglogin(vport);
dea31012005-04-17 16:05:31 -05004887 }
dea31012005-04-17 16:05:31 -05004888 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004889 return 0;
dea31012005-04-17 16:05:31 -05004890}
4891
James Smarte59058c2008-08-24 21:49:00 -04004892/**
4893 * lpfc_els_timeout: Handler funciton to the els timer.
4894 * @ptr: holder for the timer function associated data.
4895 *
4896 * This routine is invoked by the ELS timer after timeout. It posts the ELS
4897 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
4898 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
4899 * up the worker thread. It is for the worker thread to invoke the routine
4900 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
4901 **/
dea31012005-04-17 16:05:31 -05004902void
4903lpfc_els_timeout(unsigned long ptr)
4904{
James Smart2e0fef82007-06-17 19:56:36 -05004905 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
4906 struct lpfc_hba *phba = vport->phba;
James Smart5e9d9b82008-06-14 22:52:53 -04004907 uint32_t tmo_posted;
dea31012005-04-17 16:05:31 -05004908 unsigned long iflag;
4909
James Smart2e0fef82007-06-17 19:56:36 -05004910 spin_lock_irqsave(&vport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -04004911 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
4912 if (!tmo_posted)
James Smart2e0fef82007-06-17 19:56:36 -05004913 vport->work_port_events |= WORKER_ELS_TMO;
James Smart5e9d9b82008-06-14 22:52:53 -04004914 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
James Smart92d7f7b2007-06-17 19:56:38 -05004915
James Smart5e9d9b82008-06-14 22:52:53 -04004916 if (!tmo_posted)
4917 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05004918 return;
4919}
4920
James Smarte59058c2008-08-24 21:49:00 -04004921/**
4922 * lpfc_els_timeout_handler: Process an els timeout event.
4923 * @vport: pointer to a virtual N_Port data structure.
4924 *
4925 * This routine is the actual handler function that processes an ELS timeout
4926 * event. It walks the ELS ring to get and abort all the IOCBs (except the
4927 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
4928 * invoking the lpfc_sli_issue_abort_iotag() routine.
4929 **/
dea31012005-04-17 16:05:31 -05004930void
James Smart2e0fef82007-06-17 19:56:36 -05004931lpfc_els_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004932{
James Smart2e0fef82007-06-17 19:56:36 -05004933 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004934 struct lpfc_sli_ring *pring;
4935 struct lpfc_iocbq *tmp_iocb, *piocb;
4936 IOCB_t *cmd = NULL;
4937 struct lpfc_dmabuf *pcmd;
James Smart2e0fef82007-06-17 19:56:36 -05004938 uint32_t els_command = 0;
dea31012005-04-17 16:05:31 -05004939 uint32_t timeout;
James Smart2e0fef82007-06-17 19:56:36 -05004940 uint32_t remote_ID = 0xffffffff;
dea31012005-04-17 16:05:31 -05004941
James Smart2e0fef82007-06-17 19:56:36 -05004942 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004943 timeout = (uint32_t)(phba->fc_ratov << 1);
4944
4945 pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05004946
4947 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
4948 cmd = &piocb->iocb;
4949
James Smart2e0fef82007-06-17 19:56:36 -05004950 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
4951 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
4952 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
dea31012005-04-17 16:05:31 -05004953 continue;
James Smart2e0fef82007-06-17 19:56:36 -05004954
4955 if (piocb->vport != vport)
4956 continue;
4957
dea31012005-04-17 16:05:31 -05004958 pcmd = (struct lpfc_dmabuf *) piocb->context2;
James Smart2e0fef82007-06-17 19:56:36 -05004959 if (pcmd)
4960 els_command = *(uint32_t *) (pcmd->virt);
dea31012005-04-17 16:05:31 -05004961
James Smart92d7f7b2007-06-17 19:56:38 -05004962 if (els_command == ELS_CMD_FARP ||
4963 els_command == ELS_CMD_FARPR ||
4964 els_command == ELS_CMD_FDISC)
dea31012005-04-17 16:05:31 -05004965 continue;
James Smart92d7f7b2007-06-17 19:56:38 -05004966
dea31012005-04-17 16:05:31 -05004967 if (piocb->drvrTimeout > 0) {
James Smart92d7f7b2007-06-17 19:56:38 -05004968 if (piocb->drvrTimeout >= timeout)
dea31012005-04-17 16:05:31 -05004969 piocb->drvrTimeout -= timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05004970 else
dea31012005-04-17 16:05:31 -05004971 piocb->drvrTimeout = 0;
dea31012005-04-17 16:05:31 -05004972 continue;
4973 }
4974
James Smart2e0fef82007-06-17 19:56:36 -05004975 remote_ID = 0xffffffff;
4976 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
dea31012005-04-17 16:05:31 -05004977 remote_ID = cmd->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05004978 else {
4979 struct lpfc_nodelist *ndlp;
4980 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
James Smart58da1ff2008-04-07 10:15:56 -04004981 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart2e0fef82007-06-17 19:56:36 -05004982 remote_ID = ndlp->nlp_DID;
dea31012005-04-17 16:05:31 -05004983 }
James Smarte8b62012007-08-02 11:10:09 -04004984 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4985 "0127 ELS timeout Data: x%x x%x x%x "
4986 "x%x\n", els_command,
4987 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
James Smart07951072007-04-25 09:51:38 -04004988 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05004989 }
James Smart2e0fef82007-06-17 19:56:36 -05004990 spin_unlock_irq(&phba->hbalock);
James Smart5a0e3262006-07-06 15:49:16 -04004991
James Smart2e0fef82007-06-17 19:56:36 -05004992 if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt)
4993 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
dea31012005-04-17 16:05:31 -05004994}
4995
James Smarte59058c2008-08-24 21:49:00 -04004996/**
4997 * lpfc_els_flush_cmd: Clean up the outstanding els commands to a vport.
4998 * @vport: pointer to a host virtual N_Port data structure.
4999 *
5000 * This routine is used to clean up all the outstanding ELS commands on a
5001 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
5002 * routine. After that, it walks the ELS transmit queue to remove all the
5003 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
5004 * the IOCBs with a non-NULL completion callback function, the callback
5005 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
5006 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
5007 * callback function, the IOCB will simply be released. Finally, it walks
5008 * the ELS transmit completion queue to issue an abort IOCB to any transmit
5009 * completion queue IOCB that is associated with the @vport and is not
5010 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
5011 * part of the discovery state machine) out to HBA by invoking the
5012 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
5013 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
5014 * the IOCBs are aborted when this function returns.
5015 **/
dea31012005-04-17 16:05:31 -05005016void
James Smart2e0fef82007-06-17 19:56:36 -05005017lpfc_els_flush_cmd(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005018{
James Smart2534ba72007-04-25 09:52:20 -04005019 LIST_HEAD(completions);
James Smart2e0fef82007-06-17 19:56:36 -05005020 struct lpfc_hba *phba = vport->phba;
James Smart329f9bc2007-04-25 09:53:01 -04005021 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05005022 struct lpfc_iocbq *tmp_iocb, *piocb;
5023 IOCB_t *cmd = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005024
5025 lpfc_fabric_abort_vport(vport);
dea31012005-04-17 16:05:31 -05005026
James Smart2e0fef82007-06-17 19:56:36 -05005027 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005028 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
5029 cmd = &piocb->iocb;
5030
5031 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
5032 continue;
5033 }
5034
5035 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
James Smart329f9bc2007-04-25 09:53:01 -04005036 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
5037 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
5038 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
5039 cmd->ulpCommand == CMD_ABORT_XRI_CN)
dea31012005-04-17 16:05:31 -05005040 continue;
dea31012005-04-17 16:05:31 -05005041
James Smart2e0fef82007-06-17 19:56:36 -05005042 if (piocb->vport != vport)
5043 continue;
5044
James Smart2534ba72007-04-25 09:52:20 -04005045 list_move_tail(&piocb->list, &completions);
James Smart1dcb58e2007-04-25 09:51:30 -04005046 pring->txq_cnt--;
dea31012005-04-17 16:05:31 -05005047 }
5048
5049 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
dea31012005-04-17 16:05:31 -05005050 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
5051 continue;
5052 }
dea31012005-04-17 16:05:31 -05005053
James Smart2e0fef82007-06-17 19:56:36 -05005054 if (piocb->vport != vport)
5055 continue;
5056
James Smart07951072007-04-25 09:51:38 -04005057 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05005058 }
James Smart2e0fef82007-06-17 19:56:36 -05005059 spin_unlock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04005060
James Smart2e0fef82007-06-17 19:56:36 -05005061 while (!list_empty(&completions)) {
James Smart2534ba72007-04-25 09:52:20 -04005062 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
5063 cmd = &piocb->iocb;
James Smart92d7f7b2007-06-17 19:56:38 -05005064 list_del_init(&piocb->list);
James Smart2534ba72007-04-25 09:52:20 -04005065
James Smart2e0fef82007-06-17 19:56:36 -05005066 if (!piocb->iocb_cmpl)
5067 lpfc_sli_release_iocbq(phba, piocb);
5068 else {
James Smart2534ba72007-04-25 09:52:20 -04005069 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
5070 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
5071 (piocb->iocb_cmpl) (phba, piocb, piocb);
James Smart2e0fef82007-06-17 19:56:36 -05005072 }
James Smart2534ba72007-04-25 09:52:20 -04005073 }
5074
dea31012005-04-17 16:05:31 -05005075 return;
5076}
5077
James Smarte59058c2008-08-24 21:49:00 -04005078/**
5079 * lpfc_els_flush_all_cmd: Clean up all the outstanding els commands to a HBA.
5080 * @phba: pointer to lpfc hba data structure.
5081 *
5082 * This routine is used to clean up all the outstanding ELS commands on a
5083 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
5084 * routine. After that, it walks the ELS transmit queue to remove all the
5085 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
5086 * the IOCBs with the completion callback function associated, the callback
5087 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
5088 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
5089 * callback function associated, the IOCB will simply be released. Finally,
5090 * it walks the ELS transmit completion queue to issue an abort IOCB to any
5091 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
5092 * management plane IOCBs that are not part of the discovery state machine)
5093 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
5094 **/
James Smart549e55c2007-08-02 11:09:51 -04005095void
5096lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
5097{
5098 LIST_HEAD(completions);
5099 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
5100 struct lpfc_iocbq *tmp_iocb, *piocb;
5101 IOCB_t *cmd = NULL;
5102
5103 lpfc_fabric_abort_hba(phba);
5104 spin_lock_irq(&phba->hbalock);
5105 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
5106 cmd = &piocb->iocb;
5107 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
5108 continue;
5109 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
5110 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
5111 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
5112 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
5113 cmd->ulpCommand == CMD_ABORT_XRI_CN)
5114 continue;
5115 list_move_tail(&piocb->list, &completions);
5116 pring->txq_cnt--;
5117 }
5118 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
5119 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
5120 continue;
5121 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
5122 }
5123 spin_unlock_irq(&phba->hbalock);
5124 while (!list_empty(&completions)) {
5125 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
5126 cmd = &piocb->iocb;
5127 list_del_init(&piocb->list);
5128 if (!piocb->iocb_cmpl)
5129 lpfc_sli_release_iocbq(phba, piocb);
5130 else {
5131 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
5132 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
5133 (piocb->iocb_cmpl) (phba, piocb, piocb);
5134 }
5135 }
5136 return;
5137}
5138
James Smarte59058c2008-08-24 21:49:00 -04005139/**
James Smartea2151b2008-09-07 11:52:10 -04005140 * lpfc_send_els_failure_event: Posts an ELS command failure event.
5141 * @phba: Pointer to hba context object.
5142 * @cmdiocbp: Pointer to command iocb which reported error.
5143 * @rspiocbp: Pointer to response iocb which reported error.
5144 *
5145 * This function sends an event when there is an ELS command
5146 * failure.
5147 **/
5148void
5149lpfc_send_els_failure_event(struct lpfc_hba *phba,
5150 struct lpfc_iocbq *cmdiocbp,
5151 struct lpfc_iocbq *rspiocbp)
5152{
5153 struct lpfc_vport *vport = cmdiocbp->vport;
5154 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5155 struct lpfc_lsrjt_event lsrjt_event;
5156 struct lpfc_fabric_event_header fabric_event;
5157 struct ls_rjt stat;
5158 struct lpfc_nodelist *ndlp;
5159 uint32_t *pcmd;
5160
5161 ndlp = cmdiocbp->context1;
5162 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
5163 return;
5164
5165 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
5166 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
5167 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
5168 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
5169 sizeof(struct lpfc_name));
5170 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
5171 sizeof(struct lpfc_name));
5172 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
5173 cmdiocbp->context2)->virt);
5174 lsrjt_event.command = *pcmd;
5175 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
5176 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
5177 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
5178 fc_host_post_vendor_event(shost,
5179 fc_get_event_number(),
5180 sizeof(lsrjt_event),
5181 (char *)&lsrjt_event,
James Smartddcc50f2008-12-04 22:38:46 -05005182 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04005183 return;
5184 }
5185 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
5186 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
5187 fabric_event.event_type = FC_REG_FABRIC_EVENT;
5188 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
5189 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
5190 else
5191 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
5192 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
5193 sizeof(struct lpfc_name));
5194 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
5195 sizeof(struct lpfc_name));
5196 fc_host_post_vendor_event(shost,
5197 fc_get_event_number(),
5198 sizeof(fabric_event),
5199 (char *)&fabric_event,
James Smartddcc50f2008-12-04 22:38:46 -05005200 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04005201 return;
5202 }
5203
5204}
5205
5206/**
5207 * lpfc_send_els_event: Posts unsolicited els event.
5208 * @vport: Pointer to vport object.
5209 * @ndlp: Pointer FC node object.
5210 * @cmd: ELS command code.
5211 *
5212 * This function posts an event when there is an incoming
5213 * unsolicited ELS command.
5214 **/
5215static void
5216lpfc_send_els_event(struct lpfc_vport *vport,
5217 struct lpfc_nodelist *ndlp,
James Smartddcc50f2008-12-04 22:38:46 -05005218 uint32_t *payload)
James Smartea2151b2008-09-07 11:52:10 -04005219{
James Smartddcc50f2008-12-04 22:38:46 -05005220 struct lpfc_els_event_header *els_data = NULL;
5221 struct lpfc_logo_event *logo_data = NULL;
James Smartea2151b2008-09-07 11:52:10 -04005222 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5223
James Smartddcc50f2008-12-04 22:38:46 -05005224 if (*payload == ELS_CMD_LOGO) {
5225 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
5226 if (!logo_data) {
5227 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5228 "0148 Failed to allocate memory "
5229 "for LOGO event\n");
5230 return;
5231 }
5232 els_data = &logo_data->header;
5233 } else {
5234 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
5235 GFP_KERNEL);
5236 if (!els_data) {
5237 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5238 "0149 Failed to allocate memory "
5239 "for ELS event\n");
5240 return;
5241 }
5242 }
5243 els_data->event_type = FC_REG_ELS_EVENT;
5244 switch (*payload) {
James Smartea2151b2008-09-07 11:52:10 -04005245 case ELS_CMD_PLOGI:
James Smartddcc50f2008-12-04 22:38:46 -05005246 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
James Smartea2151b2008-09-07 11:52:10 -04005247 break;
5248 case ELS_CMD_PRLO:
James Smartddcc50f2008-12-04 22:38:46 -05005249 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
James Smartea2151b2008-09-07 11:52:10 -04005250 break;
5251 case ELS_CMD_ADISC:
James Smartddcc50f2008-12-04 22:38:46 -05005252 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
5253 break;
5254 case ELS_CMD_LOGO:
5255 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
5256 /* Copy the WWPN in the LOGO payload */
5257 memcpy(logo_data->logo_wwpn, &payload[2],
5258 sizeof(struct lpfc_name));
James Smartea2151b2008-09-07 11:52:10 -04005259 break;
5260 default:
Julia Lawalle9161412009-02-08 22:43:19 +01005261 kfree(els_data);
James Smartea2151b2008-09-07 11:52:10 -04005262 return;
5263 }
James Smartddcc50f2008-12-04 22:38:46 -05005264 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
5265 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
5266 if (*payload == ELS_CMD_LOGO) {
5267 fc_host_post_vendor_event(shost,
5268 fc_get_event_number(),
5269 sizeof(struct lpfc_logo_event),
5270 (char *)logo_data,
5271 LPFC_NL_VENDOR_ID);
5272 kfree(logo_data);
5273 } else {
5274 fc_host_post_vendor_event(shost,
5275 fc_get_event_number(),
5276 sizeof(struct lpfc_els_event_header),
5277 (char *)els_data,
5278 LPFC_NL_VENDOR_ID);
5279 kfree(els_data);
5280 }
James Smartea2151b2008-09-07 11:52:10 -04005281
5282 return;
5283}
5284
5285
5286/**
James Smarte59058c2008-08-24 21:49:00 -04005287 * lpfc_els_unsol_buffer: Process an unsolicited event data buffer.
5288 * @phba: pointer to lpfc hba data structure.
5289 * @pring: pointer to a SLI ring.
5290 * @vport: pointer to a host virtual N_Port data structure.
5291 * @elsiocb: pointer to lpfc els command iocb data structure.
5292 *
5293 * This routine is used for processing the IOCB associated with a unsolicited
5294 * event. It first determines whether there is an existing ndlp that matches
5295 * the DID from the unsolicited IOCB. If not, it will create a new one with
5296 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
5297 * IOCB is then used to invoke the proper routine and to set up proper state
5298 * of the discovery state machine.
5299 **/
James Smarted957682007-06-17 19:56:37 -05005300static void
5301lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
James Smart92d7f7b2007-06-17 19:56:38 -05005302 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05005303{
James Smart87af33f2007-10-27 13:37:43 -04005304 struct Scsi_Host *shost;
dea31012005-04-17 16:05:31 -05005305 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05005306 struct ls_rjt stat;
James Smart92d7f7b2007-06-17 19:56:38 -05005307 uint32_t *payload;
James Smart2e0fef82007-06-17 19:56:36 -05005308 uint32_t cmd, did, newnode, rjt_err = 0;
James Smarted957682007-06-17 19:56:37 -05005309 IOCB_t *icmd = &elsiocb->iocb;
dea31012005-04-17 16:05:31 -05005310
James Smarte47c9092008-02-08 18:49:26 -05005311 if (!vport || !(elsiocb->context2))
dea31012005-04-17 16:05:31 -05005312 goto dropit;
James Smart2e0fef82007-06-17 19:56:36 -05005313
dea31012005-04-17 16:05:31 -05005314 newnode = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05005315 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
5316 cmd = *payload;
James Smarted957682007-06-17 19:56:37 -05005317 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
James Smart495a7142008-06-14 22:52:59 -04005318 lpfc_post_buffer(phba, pring, 1);
dea31012005-04-17 16:05:31 -05005319
James Smart858c9f62007-06-17 19:56:39 -05005320 did = icmd->un.rcvels.remoteID;
5321 if (icmd->ulpStatus) {
5322 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5323 "RCV Unsol ELS: status:x%x/x%x did:x%x",
5324 icmd->ulpStatus, icmd->un.ulpWord[4], did);
dea31012005-04-17 16:05:31 -05005325 goto dropit;
James Smart858c9f62007-06-17 19:56:39 -05005326 }
dea31012005-04-17 16:05:31 -05005327
5328 /* Check to see if link went down during discovery */
James Smarted957682007-06-17 19:56:37 -05005329 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05005330 goto dropit;
dea31012005-04-17 16:05:31 -05005331
James Smart92d7f7b2007-06-17 19:56:38 -05005332 /* Ignore traffic recevied during vport shutdown. */
5333 if (vport->load_flag & FC_UNLOADING)
5334 goto dropit;
5335
James Smart2e0fef82007-06-17 19:56:36 -05005336 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005337 if (!ndlp) {
dea31012005-04-17 16:05:31 -05005338 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005339 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
James Smarted957682007-06-17 19:56:37 -05005340 if (!ndlp)
dea31012005-04-17 16:05:31 -05005341 goto dropit;
dea31012005-04-17 16:05:31 -05005342
James Smart2e0fef82007-06-17 19:56:36 -05005343 lpfc_nlp_init(vport, ndlp, did);
James Smart98c9ea52007-10-27 13:37:33 -04005344 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05005345 newnode = 1;
James Smarte47c9092008-02-08 18:49:26 -05005346 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
dea31012005-04-17 16:05:31 -05005347 ndlp->nlp_type |= NLP_FABRIC;
James Smart58da1ff2008-04-07 10:15:56 -04005348 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
5349 ndlp = lpfc_enable_node(vport, ndlp,
5350 NLP_STE_UNUSED_NODE);
5351 if (!ndlp)
5352 goto dropit;
5353 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5354 newnode = 1;
5355 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
5356 ndlp->nlp_type |= NLP_FABRIC;
5357 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
5358 /* This is similar to the new node path */
5359 ndlp = lpfc_nlp_get(ndlp);
5360 if (!ndlp)
5361 goto dropit;
5362 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5363 newnode = 1;
James Smart87af33f2007-10-27 13:37:43 -04005364 }
dea31012005-04-17 16:05:31 -05005365
5366 phba->fc_stat.elsRcvFrame++;
James Smarte47c9092008-02-08 18:49:26 -05005367
James Smart329f9bc2007-04-25 09:53:01 -04005368 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05005369 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -05005370
5371 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
5372 cmd &= ELS_CMD_MASK;
5373 }
5374 /* ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04005375 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5376 "0112 ELS command x%x received from NPORT x%x "
5377 "Data: x%x\n", cmd, did, vport->port_state);
dea31012005-04-17 16:05:31 -05005378 switch (cmd) {
5379 case ELS_CMD_PLOGI:
James Smart858c9f62007-06-17 19:56:39 -05005380 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5381 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
5382 did, vport->port_state, ndlp->nlp_flag);
5383
dea31012005-04-17 16:05:31 -05005384 phba->fc_stat.elsRcvPLOGI++;
James Smart858c9f62007-06-17 19:56:39 -05005385 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
5386
James Smartddcc50f2008-12-04 22:38:46 -05005387 lpfc_send_els_event(vport, ndlp, payload);
James Smart858c9f62007-06-17 19:56:39 -05005388 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart1b32f6a2008-02-08 18:49:39 -05005389 if (!(phba->pport->fc_flag & FC_PT2PT) ||
5390 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
5391 rjt_err = LSRJT_UNABLE_TPC;
5392 break;
5393 }
5394 /* We get here, and drop thru, if we are PT2PT with
5395 * another NPort and the other side has initiated
5396 * the PLOGI before responding to our FLOGI.
5397 */
dea31012005-04-17 16:05:31 -05005398 }
James Smart87af33f2007-10-27 13:37:43 -04005399
5400 shost = lpfc_shost_from_vport(vport);
5401 spin_lock_irq(shost->host_lock);
5402 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
5403 spin_unlock_irq(shost->host_lock);
5404
James Smart2e0fef82007-06-17 19:56:36 -05005405 lpfc_disc_state_machine(vport, ndlp, elsiocb,
5406 NLP_EVT_RCV_PLOGI);
James Smart858c9f62007-06-17 19:56:39 -05005407
dea31012005-04-17 16:05:31 -05005408 break;
5409 case ELS_CMD_FLOGI:
James Smart858c9f62007-06-17 19:56:39 -05005410 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5411 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
5412 did, vport->port_state, ndlp->nlp_flag);
5413
dea31012005-04-17 16:05:31 -05005414 phba->fc_stat.elsRcvFLOGI++;
James Smart51ef4c22007-08-02 11:10:31 -04005415 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005416 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005417 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05005418 break;
5419 case ELS_CMD_LOGO:
James Smart858c9f62007-06-17 19:56:39 -05005420 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5421 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
5422 did, vport->port_state, ndlp->nlp_flag);
5423
dea31012005-04-17 16:05:31 -05005424 phba->fc_stat.elsRcvLOGO++;
James Smartddcc50f2008-12-04 22:38:46 -05005425 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05005426 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005427 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005428 break;
5429 }
James Smart2e0fef82007-06-17 19:56:36 -05005430 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
dea31012005-04-17 16:05:31 -05005431 break;
5432 case ELS_CMD_PRLO:
James Smart858c9f62007-06-17 19:56:39 -05005433 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5434 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
5435 did, vport->port_state, ndlp->nlp_flag);
5436
dea31012005-04-17 16:05:31 -05005437 phba->fc_stat.elsRcvPRLO++;
James Smartddcc50f2008-12-04 22:38:46 -05005438 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05005439 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005440 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005441 break;
5442 }
James Smart2e0fef82007-06-17 19:56:36 -05005443 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
dea31012005-04-17 16:05:31 -05005444 break;
5445 case ELS_CMD_RSCN:
5446 phba->fc_stat.elsRcvRSCN++;
James Smart51ef4c22007-08-02 11:10:31 -04005447 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005448 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005449 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05005450 break;
5451 case ELS_CMD_ADISC:
James Smart858c9f62007-06-17 19:56:39 -05005452 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5453 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
5454 did, vport->port_state, ndlp->nlp_flag);
5455
James Smartddcc50f2008-12-04 22:38:46 -05005456 lpfc_send_els_event(vport, ndlp, payload);
dea31012005-04-17 16:05:31 -05005457 phba->fc_stat.elsRcvADISC++;
James Smart2e0fef82007-06-17 19:56:36 -05005458 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005459 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005460 break;
5461 }
James Smart2e0fef82007-06-17 19:56:36 -05005462 lpfc_disc_state_machine(vport, ndlp, elsiocb,
5463 NLP_EVT_RCV_ADISC);
dea31012005-04-17 16:05:31 -05005464 break;
5465 case ELS_CMD_PDISC:
James Smart858c9f62007-06-17 19:56:39 -05005466 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5467 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
5468 did, vport->port_state, ndlp->nlp_flag);
5469
dea31012005-04-17 16:05:31 -05005470 phba->fc_stat.elsRcvPDISC++;
James Smart2e0fef82007-06-17 19:56:36 -05005471 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005472 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005473 break;
5474 }
James Smart2e0fef82007-06-17 19:56:36 -05005475 lpfc_disc_state_machine(vport, ndlp, elsiocb,
5476 NLP_EVT_RCV_PDISC);
dea31012005-04-17 16:05:31 -05005477 break;
5478 case ELS_CMD_FARPR:
James Smart858c9f62007-06-17 19:56:39 -05005479 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5480 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
5481 did, vport->port_state, ndlp->nlp_flag);
5482
dea31012005-04-17 16:05:31 -05005483 phba->fc_stat.elsRcvFARPR++;
James Smart2e0fef82007-06-17 19:56:36 -05005484 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05005485 break;
5486 case ELS_CMD_FARP:
James Smart858c9f62007-06-17 19:56:39 -05005487 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5488 "RCV FARP: did:x%x/ste:x%x flg:x%x",
5489 did, vport->port_state, ndlp->nlp_flag);
5490
dea31012005-04-17 16:05:31 -05005491 phba->fc_stat.elsRcvFARP++;
James Smart2e0fef82007-06-17 19:56:36 -05005492 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05005493 break;
5494 case ELS_CMD_FAN:
James Smart858c9f62007-06-17 19:56:39 -05005495 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5496 "RCV FAN: did:x%x/ste:x%x flg:x%x",
5497 did, vport->port_state, ndlp->nlp_flag);
5498
dea31012005-04-17 16:05:31 -05005499 phba->fc_stat.elsRcvFAN++;
James Smart2e0fef82007-06-17 19:56:36 -05005500 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05005501 break;
dea31012005-04-17 16:05:31 -05005502 case ELS_CMD_PRLI:
James Smart858c9f62007-06-17 19:56:39 -05005503 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5504 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
5505 did, vport->port_state, ndlp->nlp_flag);
5506
dea31012005-04-17 16:05:31 -05005507 phba->fc_stat.elsRcvPRLI++;
James Smart2e0fef82007-06-17 19:56:36 -05005508 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005509 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005510 break;
5511 }
James Smart2e0fef82007-06-17 19:56:36 -05005512 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
dea31012005-04-17 16:05:31 -05005513 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005514 case ELS_CMD_LIRR:
James Smart858c9f62007-06-17 19:56:39 -05005515 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5516 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
5517 did, vport->port_state, ndlp->nlp_flag);
5518
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005519 phba->fc_stat.elsRcvLIRR++;
James Smart2e0fef82007-06-17 19:56:36 -05005520 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005521 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005522 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005523 break;
5524 case ELS_CMD_RPS:
James Smart858c9f62007-06-17 19:56:39 -05005525 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5526 "RCV RPS: did:x%x/ste:x%x flg:x%x",
5527 did, vport->port_state, ndlp->nlp_flag);
5528
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005529 phba->fc_stat.elsRcvRPS++;
James Smart2e0fef82007-06-17 19:56:36 -05005530 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005531 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005532 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005533 break;
5534 case ELS_CMD_RPL:
James Smart858c9f62007-06-17 19:56:39 -05005535 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5536 "RCV RPL: did:x%x/ste:x%x flg:x%x",
5537 did, vport->port_state, ndlp->nlp_flag);
5538
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005539 phba->fc_stat.elsRcvRPL++;
James Smart2e0fef82007-06-17 19:56:36 -05005540 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005541 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005542 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005543 break;
dea31012005-04-17 16:05:31 -05005544 case ELS_CMD_RNID:
James Smart858c9f62007-06-17 19:56:39 -05005545 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5546 "RCV RNID: did:x%x/ste:x%x flg:x%x",
5547 did, vport->port_state, ndlp->nlp_flag);
5548
dea31012005-04-17 16:05:31 -05005549 phba->fc_stat.elsRcvRNID++;
James Smart2e0fef82007-06-17 19:56:36 -05005550 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005551 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005552 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05005553 break;
5554 default:
James Smart858c9f62007-06-17 19:56:39 -05005555 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5556 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
5557 cmd, did, vport->port_state);
5558
dea31012005-04-17 16:05:31 -05005559 /* Unsupported ELS command, reject */
James Smart858c9f62007-06-17 19:56:39 -05005560 rjt_err = LSRJT_INVALID_CMD;
dea31012005-04-17 16:05:31 -05005561
5562 /* Unknown ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04005563 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5564 "0115 Unknown ELS command x%x "
5565 "received from NPORT x%x\n", cmd, did);
James Smart87af33f2007-10-27 13:37:43 -04005566 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005567 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05005568 break;
5569 }
5570
5571 /* check if need to LS_RJT received ELS cmd */
5572 if (rjt_err) {
James Smart92d7f7b2007-06-17 19:56:38 -05005573 memset(&stat, 0, sizeof(stat));
James Smart858c9f62007-06-17 19:56:39 -05005574 stat.un.b.lsRjtRsnCode = rjt_err;
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04005575 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart858c9f62007-06-17 19:56:39 -05005576 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
5577 NULL);
dea31012005-04-17 16:05:31 -05005578 }
5579
James Smartd7c255b2008-08-24 21:50:00 -04005580 lpfc_nlp_put(elsiocb->context1);
5581 elsiocb->context1 = NULL;
James Smarted957682007-06-17 19:56:37 -05005582 return;
5583
5584dropit:
James Smart98c9ea52007-10-27 13:37:33 -04005585 if (vport && !(vport->load_flag & FC_UNLOADING))
5586 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
James Smarte8b62012007-08-02 11:10:09 -04005587 "(%d):0111 Dropping received ELS cmd "
James Smarted957682007-06-17 19:56:37 -05005588 "Data: x%x x%x x%x\n",
James Smart98c9ea52007-10-27 13:37:33 -04005589 vport->vpi, icmd->ulpStatus,
James Smarte8b62012007-08-02 11:10:09 -04005590 icmd->un.ulpWord[4], icmd->ulpTimeout);
James Smarted957682007-06-17 19:56:37 -05005591 phba->fc_stat.elsRcvDrop++;
5592}
5593
James Smarte59058c2008-08-24 21:49:00 -04005594/**
5595 * lpfc_find_vport_by_vpid: Find a vport on a HBA through vport identifier.
5596 * @phba: pointer to lpfc hba data structure.
5597 * @vpi: host virtual N_Port identifier.
5598 *
5599 * This routine finds a vport on a HBA (referred by @phba) through a
5600 * @vpi. The function walks the HBA's vport list and returns the address
5601 * of the vport with the matching @vpi.
5602 *
5603 * Return code
5604 * NULL - No vport with the matching @vpi found
5605 * Otherwise - Address to the vport with the matching @vpi.
5606 **/
James Smart92d7f7b2007-06-17 19:56:38 -05005607static struct lpfc_vport *
5608lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
5609{
5610 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -04005611 unsigned long flags;
James Smart92d7f7b2007-06-17 19:56:38 -05005612
James Smart549e55c2007-08-02 11:09:51 -04005613 spin_lock_irqsave(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05005614 list_for_each_entry(vport, &phba->port_list, listentry) {
James Smart549e55c2007-08-02 11:09:51 -04005615 if (vport->vpi == vpi) {
5616 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05005617 return vport;
James Smart549e55c2007-08-02 11:09:51 -04005618 }
James Smart92d7f7b2007-06-17 19:56:38 -05005619 }
James Smart549e55c2007-08-02 11:09:51 -04005620 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05005621 return NULL;
5622}
James Smarted957682007-06-17 19:56:37 -05005623
James Smarte59058c2008-08-24 21:49:00 -04005624/**
5625 * lpfc_els_unsol_event: Process an unsolicited event from an els sli ring.
5626 * @phba: pointer to lpfc hba data structure.
5627 * @pring: pointer to a SLI ring.
5628 * @elsiocb: pointer to lpfc els iocb data structure.
5629 *
5630 * This routine is used to process an unsolicited event received from a SLI
5631 * (Service Level Interface) ring. The actual processing of the data buffer
5632 * associated with the unsolicited event is done by invoking the routine
5633 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
5634 * SLI ring on which the unsolicited event was received.
5635 **/
James Smarted957682007-06-17 19:56:37 -05005636void
5637lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
5638 struct lpfc_iocbq *elsiocb)
5639{
5640 struct lpfc_vport *vport = phba->pport;
James Smarted957682007-06-17 19:56:37 -05005641 IOCB_t *icmd = &elsiocb->iocb;
James Smarted957682007-06-17 19:56:37 -05005642 dma_addr_t paddr;
James Smart92d7f7b2007-06-17 19:56:38 -05005643 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
5644 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
James Smarted957682007-06-17 19:56:37 -05005645
James Smartd7c255b2008-08-24 21:50:00 -04005646 elsiocb->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005647 elsiocb->context2 = NULL;
5648 elsiocb->context3 = NULL;
5649
5650 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
5651 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
5652 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
5653 (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) {
James Smarted957682007-06-17 19:56:37 -05005654 phba->fc_stat.NoRcvBuf++;
5655 /* Not enough posted buffers; Try posting more buffers */
James Smart92d7f7b2007-06-17 19:56:38 -05005656 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
James Smart495a7142008-06-14 22:52:59 -04005657 lpfc_post_buffer(phba, pring, 0);
James Smarted957682007-06-17 19:56:37 -05005658 return;
5659 }
5660
James Smart92d7f7b2007-06-17 19:56:38 -05005661 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
5662 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
5663 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
5664 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
5665 vport = phba->pport;
5666 else {
5667 uint16_t vpi = icmd->unsli3.rcvsli3.vpi;
5668 vport = lpfc_find_vport_by_vpid(phba, vpi);
5669 }
5670 }
James Smart7f5f3d02008-02-08 18:50:14 -05005671 /* If there are no BDEs associated
5672 * with this IOCB, there is nothing to do.
5673 */
James Smarted957682007-06-17 19:56:37 -05005674 if (icmd->ulpBdeCount == 0)
5675 return;
5676
James Smart7f5f3d02008-02-08 18:50:14 -05005677 /* type of ELS cmd is first 32bit word
5678 * in packet
5679 */
James Smarted957682007-06-17 19:56:37 -05005680 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05005681 elsiocb->context2 = bdeBuf1;
James Smarted957682007-06-17 19:56:37 -05005682 } else {
5683 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
5684 icmd->un.cont64[0].addrLow);
James Smart92d7f7b2007-06-17 19:56:38 -05005685 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
5686 paddr);
James Smarted957682007-06-17 19:56:37 -05005687 }
5688
James Smart92d7f7b2007-06-17 19:56:38 -05005689 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
5690 /*
5691 * The different unsolicited event handlers would tell us
5692 * if they are done with "mp" by setting context2 to NULL.
5693 */
dea31012005-04-17 16:05:31 -05005694 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05005695 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
5696 elsiocb->context2 = NULL;
dea31012005-04-17 16:05:31 -05005697 }
James Smarted957682007-06-17 19:56:37 -05005698
5699 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
James Smart92d7f7b2007-06-17 19:56:38 -05005700 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
James Smarted957682007-06-17 19:56:37 -05005701 icmd->ulpBdeCount == 2) {
James Smart92d7f7b2007-06-17 19:56:38 -05005702 elsiocb->context2 = bdeBuf2;
5703 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
James Smarted957682007-06-17 19:56:37 -05005704 /* free mp if we are done with it */
5705 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05005706 lpfc_in_buf_free(phba, elsiocb->context2);
5707 elsiocb->context2 = NULL;
James Smarted957682007-06-17 19:56:37 -05005708 }
dea31012005-04-17 16:05:31 -05005709 }
dea31012005-04-17 16:05:31 -05005710}
James Smart92d7f7b2007-06-17 19:56:38 -05005711
James Smarte59058c2008-08-24 21:49:00 -04005712/**
5713 * lpfc_do_scr_ns_plogi: Issue a plogi to the name server for scr.
5714 * @phba: pointer to lpfc hba data structure.
5715 * @vport: pointer to a virtual N_Port data structure.
5716 *
5717 * This routine issues a Port Login (PLOGI) to the Name Server with
5718 * State Change Request (SCR) for a @vport. This routine will create an
5719 * ndlp for the Name Server associated to the @vport if such node does
5720 * not already exist. The PLOGI to Name Server is issued by invoking the
5721 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
5722 * (FDMI) is configured to the @vport, a FDMI node will be created and
5723 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
5724 **/
James Smart92d7f7b2007-06-17 19:56:38 -05005725void
5726lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
5727{
5728 struct lpfc_nodelist *ndlp, *ndlp_fdmi;
5729
5730 ndlp = lpfc_findnode_did(vport, NameServer_DID);
5731 if (!ndlp) {
5732 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
5733 if (!ndlp) {
5734 if (phba->fc_topology == TOPOLOGY_LOOP) {
5735 lpfc_disc_start(vport);
5736 return;
5737 }
5738 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04005739 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5740 "0251 NameServer login: no memory\n");
James Smart92d7f7b2007-06-17 19:56:38 -05005741 return;
5742 }
5743 lpfc_nlp_init(vport, ndlp, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05005744 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
5745 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
5746 if (!ndlp) {
5747 if (phba->fc_topology == TOPOLOGY_LOOP) {
5748 lpfc_disc_start(vport);
5749 return;
5750 }
5751 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
5752 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5753 "0348 NameServer login: node freed\n");
5754 return;
5755 }
James Smart92d7f7b2007-06-17 19:56:38 -05005756 }
James Smart58da1ff2008-04-07 10:15:56 -04005757 ndlp->nlp_type |= NLP_FABRIC;
James Smart92d7f7b2007-06-17 19:56:38 -05005758
5759 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
5760
5761 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
5762 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04005763 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5764 "0252 Cannot issue NameServer login\n");
James Smart92d7f7b2007-06-17 19:56:38 -05005765 return;
5766 }
5767
James Smart3de2a652007-08-02 11:09:59 -04005768 if (vport->cfg_fdmi_on) {
James Smart92d7f7b2007-06-17 19:56:38 -05005769 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
5770 GFP_KERNEL);
5771 if (ndlp_fdmi) {
5772 lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
5773 ndlp_fdmi->nlp_type |= NLP_FABRIC;
James Smart58da1ff2008-04-07 10:15:56 -04005774 lpfc_nlp_set_state(vport, ndlp_fdmi,
5775 NLP_STE_PLOGI_ISSUE);
James Smart92d7f7b2007-06-17 19:56:38 -05005776 lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID,
5777 0);
5778 }
5779 }
5780 return;
5781}
5782
James Smarte59058c2008-08-24 21:49:00 -04005783/**
5784 * lpfc_cmpl_reg_new_vport: Completion callback function to register new vport.
5785 * @phba: pointer to lpfc hba data structure.
5786 * @pmb: pointer to the driver internal queue element for mailbox command.
5787 *
5788 * This routine is the completion callback function to register new vport
5789 * mailbox command. If the new vport mailbox command completes successfully,
5790 * the fabric registration login shall be performed on physical port (the
5791 * new vport created is actually a physical port, with VPI 0) or the port
5792 * login to Name Server for State Change Request (SCR) will be performed
5793 * on virtual port (real virtual port, with VPI greater than 0).
5794 **/
James Smart92d7f7b2007-06-17 19:56:38 -05005795static void
5796lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
5797{
5798 struct lpfc_vport *vport = pmb->vport;
5799 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5800 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
5801 MAILBOX_t *mb = &pmb->mb;
5802
James Smart09372822008-01-11 01:52:54 -05005803 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05005804 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05005805 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05005806
5807 if (mb->mbxStatus) {
James Smarte8b62012007-08-02 11:10:09 -04005808 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
5809 "0915 Register VPI failed: 0x%x\n",
5810 mb->mbxStatus);
James Smart92d7f7b2007-06-17 19:56:38 -05005811
5812 switch (mb->mbxStatus) {
5813 case 0x11: /* unsupported feature */
5814 case 0x9603: /* max_vpi exceeded */
James Smart7f5f3d02008-02-08 18:50:14 -05005815 case 0x9602: /* Link event since CLEAR_LA */
James Smart92d7f7b2007-06-17 19:56:38 -05005816 /* giving up on vport registration */
5817 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
5818 spin_lock_irq(shost->host_lock);
5819 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
5820 spin_unlock_irq(shost->host_lock);
5821 lpfc_can_disctmo(vport);
5822 break;
5823 default:
5824 /* Try to recover from this error */
5825 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -05005826 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05005827 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05005828 spin_unlock_irq(shost->host_lock);
James Smart7f5f3d02008-02-08 18:50:14 -05005829 if (vport->port_type == LPFC_PHYSICAL_PORT)
5830 lpfc_initial_flogi(vport);
5831 else
5832 lpfc_initial_fdisc(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05005833 break;
5834 }
5835
5836 } else {
5837 if (vport == phba->pport)
5838 lpfc_issue_fabric_reglogin(vport);
5839 else
5840 lpfc_do_scr_ns_plogi(phba, vport);
5841 }
James Smartfa4066b2008-01-11 01:53:27 -05005842
5843 /* Now, we decrement the ndlp reference count held for this
5844 * callback function
5845 */
5846 lpfc_nlp_put(ndlp);
5847
James Smart92d7f7b2007-06-17 19:56:38 -05005848 mempool_free(pmb, phba->mbox_mem_pool);
5849 return;
5850}
5851
James Smarte59058c2008-08-24 21:49:00 -04005852/**
5853 * lpfc_register_new_vport: Register a new vport with a HBA.
5854 * @phba: pointer to lpfc hba data structure.
5855 * @vport: pointer to a host virtual N_Port data structure.
5856 * @ndlp: pointer to a node-list data structure.
5857 *
5858 * This routine registers the @vport as a new virtual port with a HBA.
5859 * It is done through a registering vpi mailbox command.
5860 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01005861static void
James Smart92d7f7b2007-06-17 19:56:38 -05005862lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
5863 struct lpfc_nodelist *ndlp)
5864{
James Smart09372822008-01-11 01:52:54 -05005865 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05005866 LPFC_MBOXQ_t *mbox;
5867
5868 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5869 if (mbox) {
5870 lpfc_reg_vpi(phba, vport->vpi, vport->fc_myDID, mbox);
5871 mbox->vport = vport;
5872 mbox->context2 = lpfc_nlp_get(ndlp);
5873 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
James Smart0b727fe2007-10-27 13:37:25 -04005874 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart92d7f7b2007-06-17 19:56:38 -05005875 == MBX_NOT_FINISHED) {
James Smartfa4066b2008-01-11 01:53:27 -05005876 /* mailbox command not success, decrement ndlp
5877 * reference count for this command
5878 */
5879 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05005880 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05005881
James Smarte8b62012007-08-02 11:10:09 -04005882 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
5883 "0253 Register VPI: Can't send mbox\n");
James Smartfa4066b2008-01-11 01:53:27 -05005884 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05005885 }
5886 } else {
James Smarte8b62012007-08-02 11:10:09 -04005887 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
5888 "0254 Register VPI: no memory\n");
James Smartfa4066b2008-01-11 01:53:27 -05005889 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05005890 }
James Smartfa4066b2008-01-11 01:53:27 -05005891 return;
5892
5893mbox_err_exit:
5894 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
5895 spin_lock_irq(shost->host_lock);
5896 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
5897 spin_unlock_irq(shost->host_lock);
5898 return;
James Smart92d7f7b2007-06-17 19:56:38 -05005899}
5900
James Smarte59058c2008-08-24 21:49:00 -04005901/**
5902 * lpfc_cmpl_els_fdisc: Completion function for fdisc iocb command.
5903 * @phba: pointer to lpfc hba data structure.
5904 * @cmdiocb: pointer to lpfc command iocb data structure.
5905 * @rspiocb: pointer to lpfc response iocb data structure.
5906 *
5907 * This routine is the completion callback function to a Fabric Discover
5908 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
5909 * single threaded, each FDISC completion callback function will reset
5910 * the discovery timer for all vports such that the timers will not get
5911 * unnecessary timeout. The function checks the FDISC IOCB status. If error
5912 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
5913 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
5914 * assigned to the vport has been changed with the completion of the FDISC
5915 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
5916 * are unregistered from the HBA, and then the lpfc_register_new_vport()
5917 * routine is invoked to register new vport with the HBA. Otherwise, the
5918 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
5919 * Server for State Change Request (SCR).
5920 **/
James Smart92d7f7b2007-06-17 19:56:38 -05005921static void
5922lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
5923 struct lpfc_iocbq *rspiocb)
5924{
5925 struct lpfc_vport *vport = cmdiocb->vport;
5926 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5927 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
5928 struct lpfc_nodelist *np;
5929 struct lpfc_nodelist *next_np;
5930 IOCB_t *irsp = &rspiocb->iocb;
5931 struct lpfc_iocbq *piocb;
5932
James Smarte8b62012007-08-02 11:10:09 -04005933 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5934 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
5935 irsp->ulpStatus, irsp->un.ulpWord[4],
5936 vport->fc_prevDID);
James Smart92d7f7b2007-06-17 19:56:38 -05005937 /* Since all FDISCs are being single threaded, we
5938 * must reset the discovery timer for ALL vports
5939 * waiting to send FDISC when one completes.
5940 */
5941 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
5942 lpfc_set_disctmo(piocb->vport);
5943 }
5944
James Smart858c9f62007-06-17 19:56:39 -05005945 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
5946 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
5947 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
5948
James Smart92d7f7b2007-06-17 19:56:38 -05005949 if (irsp->ulpStatus) {
5950 /* Check for retry */
5951 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
5952 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05005953 /* FDISC failed */
James Smarte8b62012007-08-02 11:10:09 -04005954 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smartd7c255b2008-08-24 21:50:00 -04005955 "0126 FDISC failed. (%d/%d)\n",
James Smarte8b62012007-08-02 11:10:09 -04005956 irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smartd7c255b2008-08-24 21:50:00 -04005957 goto fdisc_failed;
5958 }
James Smart92d7f7b2007-06-17 19:56:38 -05005959 if (vport->fc_vport->vport_state == FC_VPORT_INITIALIZING)
5960 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smart92d7f7b2007-06-17 19:56:38 -05005961 lpfc_nlp_put(ndlp);
5962 /* giving up on FDISC. Cancel discovery timer */
5963 lpfc_can_disctmo(vport);
James Smartd7c255b2008-08-24 21:50:00 -04005964 spin_lock_irq(shost->host_lock);
5965 vport->fc_flag |= FC_FABRIC;
5966 if (vport->phba->fc_topology == TOPOLOGY_LOOP)
5967 vport->fc_flag |= FC_PUBLIC_LOOP;
5968 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05005969
James Smartd7c255b2008-08-24 21:50:00 -04005970 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
5971 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
5972 if ((vport->fc_prevDID != vport->fc_myDID) &&
5973 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
5974 /* If our NportID changed, we need to ensure all
5975 * remaining NPORTs get unreg_login'ed so we can
5976 * issue unreg_vpi.
5977 */
5978 list_for_each_entry_safe(np, next_np,
5979 &vport->fc_nodes, nlp_listp) {
5980 if (!NLP_CHK_NODE_ACT(ndlp) ||
5981 (np->nlp_state != NLP_STE_NPR_NODE) ||
5982 !(np->nlp_flag & NLP_NPR_ADISC))
5983 continue;
James Smart09372822008-01-11 01:52:54 -05005984 spin_lock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04005985 np->nlp_flag &= ~NLP_NPR_ADISC;
James Smart09372822008-01-11 01:52:54 -05005986 spin_unlock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04005987 lpfc_unreg_rpi(vport, np);
James Smart92d7f7b2007-06-17 19:56:38 -05005988 }
James Smartd7c255b2008-08-24 21:50:00 -04005989 lpfc_mbx_unreg_vpi(vport);
5990 spin_lock_irq(shost->host_lock);
5991 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
5992 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05005993 }
5994
James Smartd7c255b2008-08-24 21:50:00 -04005995 if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
5996 lpfc_register_new_vport(phba, vport, ndlp);
5997 else
5998 lpfc_do_scr_ns_plogi(phba, vport);
5999 goto out;
6000fdisc_failed:
6001 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6002 /* Cancel discovery timer */
6003 lpfc_can_disctmo(vport);
6004 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05006005out:
6006 lpfc_els_free_iocb(phba, cmdiocb);
6007}
6008
James Smarte59058c2008-08-24 21:49:00 -04006009/**
6010 * lpfc_issue_els_fdisc: Issue a fdisc iocb command.
6011 * @vport: pointer to a virtual N_Port data structure.
6012 * @ndlp: pointer to a node-list data structure.
6013 * @retry: number of retries to the command IOCB.
6014 *
6015 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
6016 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
6017 * routine to issue the IOCB, which makes sure only one outstanding fabric
6018 * IOCB will be sent off HBA at any given time.
6019 *
6020 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6021 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6022 * will be stored into the context1 field of the IOCB for the completion
6023 * callback function to the FDISC ELS command.
6024 *
6025 * Return code
6026 * 0 - Successfully issued fdisc iocb command
6027 * 1 - Failed to issue fdisc iocb command
6028 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01006029static int
James Smart92d7f7b2007-06-17 19:56:38 -05006030lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
6031 uint8_t retry)
6032{
6033 struct lpfc_hba *phba = vport->phba;
6034 IOCB_t *icmd;
6035 struct lpfc_iocbq *elsiocb;
6036 struct serv_parm *sp;
6037 uint8_t *pcmd;
6038 uint16_t cmdsize;
6039 int did = ndlp->nlp_DID;
6040 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05006041
6042 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
6043 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
6044 ELS_CMD_FDISC);
6045 if (!elsiocb) {
James Smart92d7f7b2007-06-17 19:56:38 -05006046 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006047 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6048 "0255 Issue FDISC: no IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006049 return 1;
6050 }
6051
6052 icmd = &elsiocb->iocb;
6053 icmd->un.elsreq64.myID = 0;
6054 icmd->un.elsreq64.fl = 1;
6055
6056 /* For FDISC, Let FDISC rsp set the NPortID for this VPI */
6057 icmd->ulpCt_h = 1;
6058 icmd->ulpCt_l = 0;
6059
6060 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6061 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
6062 pcmd += sizeof(uint32_t); /* CSP Word 1 */
6063 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
6064 sp = (struct serv_parm *) pcmd;
6065 /* Setup CSPs accordingly for Fabric */
6066 sp->cmn.e_d_tov = 0;
6067 sp->cmn.w2.r_a_tov = 0;
6068 sp->cls1.classValid = 0;
6069 sp->cls2.seqDelivery = 1;
6070 sp->cls3.seqDelivery = 1;
6071
6072 pcmd += sizeof(uint32_t); /* CSP Word 2 */
6073 pcmd += sizeof(uint32_t); /* CSP Word 3 */
6074 pcmd += sizeof(uint32_t); /* CSP Word 4 */
6075 pcmd += sizeof(uint32_t); /* Port Name */
6076 memcpy(pcmd, &vport->fc_portname, 8);
6077 pcmd += sizeof(uint32_t); /* Node Name */
6078 pcmd += sizeof(uint32_t); /* Node Name */
6079 memcpy(pcmd, &vport->fc_nodename, 8);
6080
6081 lpfc_set_disctmo(vport);
6082
6083 phba->fc_stat.elsXmitFDISC++;
6084 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
6085
James Smart858c9f62007-06-17 19:56:39 -05006086 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6087 "Issue FDISC: did:x%x",
6088 did, 0, 0);
6089
James Smart92d7f7b2007-06-17 19:56:38 -05006090 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
6091 if (rc == IOCB_ERROR) {
6092 lpfc_els_free_iocb(phba, elsiocb);
James Smart92d7f7b2007-06-17 19:56:38 -05006093 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006094 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6095 "0256 Issue FDISC: Cannot send IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006096 return 1;
6097 }
6098 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
6099 vport->port_state = LPFC_FDISC;
6100 return 0;
6101}
6102
James Smarte59058c2008-08-24 21:49:00 -04006103/**
6104 * lpfc_cmpl_els_npiv_logo: Completion function with vport logo.
6105 * @phba: pointer to lpfc hba data structure.
6106 * @cmdiocb: pointer to lpfc command iocb data structure.
6107 * @rspiocb: pointer to lpfc response iocb data structure.
6108 *
6109 * This routine is the completion callback function to the issuing of a LOGO
6110 * ELS command off a vport. It frees the command IOCB and then decrement the
6111 * reference count held on ndlp for this completion function, indicating that
6112 * the reference to the ndlp is no long needed. Note that the
6113 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
6114 * callback function and an additional explicit ndlp reference decrementation
6115 * will trigger the actual release of the ndlp.
6116 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006117static void
6118lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6119 struct lpfc_iocbq *rspiocb)
6120{
6121 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05006122 IOCB_t *irsp;
James Smarte47c9092008-02-08 18:49:26 -05006123 struct lpfc_nodelist *ndlp;
6124 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
James Smart858c9f62007-06-17 19:56:39 -05006125
6126 irsp = &rspiocb->iocb;
6127 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6128 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
6129 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
James Smart92d7f7b2007-06-17 19:56:38 -05006130
6131 lpfc_els_free_iocb(phba, cmdiocb);
6132 vport->unreg_vpi_cmpl = VPORT_ERROR;
James Smarte47c9092008-02-08 18:49:26 -05006133
6134 /* Trigger the release of the ndlp after logo */
6135 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05006136}
6137
James Smarte59058c2008-08-24 21:49:00 -04006138/**
6139 * lpfc_issue_els_npiv_logo: Issue a logo off a vport.
6140 * @vport: pointer to a virtual N_Port data structure.
6141 * @ndlp: pointer to a node-list data structure.
6142 *
6143 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
6144 *
6145 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6146 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6147 * will be stored into the context1 field of the IOCB for the completion
6148 * callback function to the LOGO ELS command.
6149 *
6150 * Return codes
6151 * 0 - Successfully issued logo off the @vport
6152 * 1 - Failed to issue logo off the @vport
6153 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006154int
6155lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
6156{
6157 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6158 struct lpfc_hba *phba = vport->phba;
6159 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
6160 IOCB_t *icmd;
6161 struct lpfc_iocbq *elsiocb;
6162 uint8_t *pcmd;
6163 uint16_t cmdsize;
6164
6165 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
6166 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
6167 ELS_CMD_LOGO);
6168 if (!elsiocb)
6169 return 1;
6170
6171 icmd = &elsiocb->iocb;
6172 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6173 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
6174 pcmd += sizeof(uint32_t);
6175
6176 /* Fill in LOGO payload */
6177 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
6178 pcmd += sizeof(uint32_t);
6179 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
6180
James Smart858c9f62007-06-17 19:56:39 -05006181 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6182 "Issue LOGO npiv did:x%x flg:x%x",
6183 ndlp->nlp_DID, ndlp->nlp_flag, 0);
6184
James Smart92d7f7b2007-06-17 19:56:38 -05006185 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
6186 spin_lock_irq(shost->host_lock);
6187 ndlp->nlp_flag |= NLP_LOGO_SND;
6188 spin_unlock_irq(shost->host_lock);
6189 if (lpfc_sli_issue_iocb(phba, pring, elsiocb, 0) == IOCB_ERROR) {
6190 spin_lock_irq(shost->host_lock);
6191 ndlp->nlp_flag &= ~NLP_LOGO_SND;
6192 spin_unlock_irq(shost->host_lock);
6193 lpfc_els_free_iocb(phba, elsiocb);
6194 return 1;
6195 }
6196 return 0;
6197}
6198
James Smarte59058c2008-08-24 21:49:00 -04006199/**
6200 * lpfc_fabric_block_timeout: Handler function to the fabric block timer.
6201 * @ptr: holder for the timer function associated data.
6202 *
6203 * This routine is invoked by the fabric iocb block timer after
6204 * timeout. It posts the fabric iocb block timeout event by setting the
6205 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
6206 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
6207 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
6208 * posted event WORKER_FABRIC_BLOCK_TMO.
6209 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006210void
6211lpfc_fabric_block_timeout(unsigned long ptr)
6212{
6213 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
6214 unsigned long iflags;
6215 uint32_t tmo_posted;
James Smart5e9d9b82008-06-14 22:52:53 -04006216
James Smart92d7f7b2007-06-17 19:56:38 -05006217 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
6218 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
6219 if (!tmo_posted)
6220 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
6221 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
6222
James Smart5e9d9b82008-06-14 22:52:53 -04006223 if (!tmo_posted)
6224 lpfc_worker_wake_up(phba);
6225 return;
James Smart92d7f7b2007-06-17 19:56:38 -05006226}
6227
James Smarte59058c2008-08-24 21:49:00 -04006228/**
6229 * lpfc_resume_fabric_iocbs: Issue a fabric iocb from driver internal list.
6230 * @phba: pointer to lpfc hba data structure.
6231 *
6232 * This routine issues one fabric iocb from the driver internal list to
6233 * the HBA. It first checks whether it's ready to issue one fabric iocb to
6234 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
6235 * remove one pending fabric iocb from the driver internal list and invokes
6236 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
6237 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006238static void
6239lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
6240{
6241 struct lpfc_iocbq *iocb;
6242 unsigned long iflags;
6243 int ret;
6244 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
6245 IOCB_t *cmd;
6246
6247repeat:
6248 iocb = NULL;
6249 spin_lock_irqsave(&phba->hbalock, iflags);
James Smart7f5f3d02008-02-08 18:50:14 -05006250 /* Post any pending iocb to the SLI layer */
James Smart92d7f7b2007-06-17 19:56:38 -05006251 if (atomic_read(&phba->fabric_iocb_count) == 0) {
6252 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
6253 list);
6254 if (iocb)
James Smart7f5f3d02008-02-08 18:50:14 -05006255 /* Increment fabric iocb count to hold the position */
James Smart92d7f7b2007-06-17 19:56:38 -05006256 atomic_inc(&phba->fabric_iocb_count);
6257 }
6258 spin_unlock_irqrestore(&phba->hbalock, iflags);
6259 if (iocb) {
6260 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
6261 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
6262 iocb->iocb_flag |= LPFC_IO_FABRIC;
6263
James Smart858c9f62007-06-17 19:56:39 -05006264 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
6265 "Fabric sched1: ste:x%x",
6266 iocb->vport->port_state, 0, 0);
6267
James Smart92d7f7b2007-06-17 19:56:38 -05006268 ret = lpfc_sli_issue_iocb(phba, pring, iocb, 0);
6269
6270 if (ret == IOCB_ERROR) {
6271 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
6272 iocb->fabric_iocb_cmpl = NULL;
6273 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
6274 cmd = &iocb->iocb;
6275 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
6276 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
6277 iocb->iocb_cmpl(phba, iocb, iocb);
6278
6279 atomic_dec(&phba->fabric_iocb_count);
6280 goto repeat;
6281 }
6282 }
6283
6284 return;
6285}
6286
James Smarte59058c2008-08-24 21:49:00 -04006287/**
6288 * lpfc_unblock_fabric_iocbs: Unblock issuing fabric iocb command.
6289 * @phba: pointer to lpfc hba data structure.
6290 *
6291 * This routine unblocks the issuing fabric iocb command. The function
6292 * will clear the fabric iocb block bit and then invoke the routine
6293 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
6294 * from the driver internal fabric iocb list.
6295 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006296void
6297lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
6298{
6299 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
6300
6301 lpfc_resume_fabric_iocbs(phba);
6302 return;
6303}
6304
James Smarte59058c2008-08-24 21:49:00 -04006305/**
6306 * lpfc_block_fabric_iocbs: Block issuing fabric iocb command.
6307 * @phba: pointer to lpfc hba data structure.
6308 *
6309 * This routine blocks the issuing fabric iocb for a specified amount of
6310 * time (currently 100 ms). This is done by set the fabric iocb block bit
6311 * and set up a timeout timer for 100ms. When the block bit is set, no more
6312 * fabric iocb will be issued out of the HBA.
6313 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006314static void
6315lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
6316{
6317 int blocked;
6318
6319 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
James Smart7f5f3d02008-02-08 18:50:14 -05006320 /* Start a timer to unblock fabric iocbs after 100ms */
James Smart92d7f7b2007-06-17 19:56:38 -05006321 if (!blocked)
6322 mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 );
6323
6324 return;
6325}
6326
James Smarte59058c2008-08-24 21:49:00 -04006327/**
6328 * lpfc_cmpl_fabric_iocb: Completion callback function for fabric iocb.
6329 * @phba: pointer to lpfc hba data structure.
6330 * @cmdiocb: pointer to lpfc command iocb data structure.
6331 * @rspiocb: pointer to lpfc response iocb data structure.
6332 *
6333 * This routine is the callback function that is put to the fabric iocb's
6334 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
6335 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
6336 * function first restores and invokes the original iocb's callback function
6337 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
6338 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
6339 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006340static void
6341lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6342 struct lpfc_iocbq *rspiocb)
6343{
6344 struct ls_rjt stat;
6345
6346 if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
6347 BUG();
6348
6349 switch (rspiocb->iocb.ulpStatus) {
6350 case IOSTAT_NPORT_RJT:
6351 case IOSTAT_FABRIC_RJT:
6352 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
6353 lpfc_block_fabric_iocbs(phba);
6354 }
6355 break;
6356
6357 case IOSTAT_NPORT_BSY:
6358 case IOSTAT_FABRIC_BSY:
6359 lpfc_block_fabric_iocbs(phba);
6360 break;
6361
6362 case IOSTAT_LS_RJT:
6363 stat.un.lsRjtError =
6364 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
6365 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
6366 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
6367 lpfc_block_fabric_iocbs(phba);
6368 break;
6369 }
6370
6371 if (atomic_read(&phba->fabric_iocb_count) == 0)
6372 BUG();
6373
6374 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
6375 cmdiocb->fabric_iocb_cmpl = NULL;
6376 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
6377 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
6378
6379 atomic_dec(&phba->fabric_iocb_count);
6380 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
James Smart7f5f3d02008-02-08 18:50:14 -05006381 /* Post any pending iocbs to HBA */
6382 lpfc_resume_fabric_iocbs(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05006383 }
6384}
6385
James Smarte59058c2008-08-24 21:49:00 -04006386/**
6387 * lpfc_issue_fabric_iocb: Issue a fabric iocb command.
6388 * @phba: pointer to lpfc hba data structure.
6389 * @iocb: pointer to lpfc command iocb data structure.
6390 *
6391 * This routine is used as the top-level API for issuing a fabric iocb command
6392 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
6393 * function makes sure that only one fabric bound iocb will be outstanding at
6394 * any given time. As such, this function will first check to see whether there
6395 * is already an outstanding fabric iocb on the wire. If so, it will put the
6396 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
6397 * issued later. Otherwise, it will issue the iocb on the wire and update the
6398 * fabric iocb count it indicate that there is one fabric iocb on the wire.
6399 *
6400 * Note, this implementation has a potential sending out fabric IOCBs out of
6401 * order. The problem is caused by the construction of the "ready" boolen does
6402 * not include the condition that the internal fabric IOCB list is empty. As
6403 * such, it is possible a fabric IOCB issued by this routine might be "jump"
6404 * ahead of the fabric IOCBs in the internal list.
6405 *
6406 * Return code
6407 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
6408 * IOCB_ERROR - failed to issue fabric iocb
6409 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01006410static int
James Smart92d7f7b2007-06-17 19:56:38 -05006411lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
6412{
6413 unsigned long iflags;
6414 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
6415 int ready;
6416 int ret;
6417
6418 if (atomic_read(&phba->fabric_iocb_count) > 1)
6419 BUG();
6420
6421 spin_lock_irqsave(&phba->hbalock, iflags);
6422 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
6423 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
6424
James Smart7f5f3d02008-02-08 18:50:14 -05006425 if (ready)
6426 /* Increment fabric iocb count to hold the position */
6427 atomic_inc(&phba->fabric_iocb_count);
James Smart92d7f7b2007-06-17 19:56:38 -05006428 spin_unlock_irqrestore(&phba->hbalock, iflags);
6429 if (ready) {
6430 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
6431 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
6432 iocb->iocb_flag |= LPFC_IO_FABRIC;
6433
James Smart858c9f62007-06-17 19:56:39 -05006434 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
6435 "Fabric sched2: ste:x%x",
6436 iocb->vport->port_state, 0, 0);
6437
James Smart92d7f7b2007-06-17 19:56:38 -05006438 ret = lpfc_sli_issue_iocb(phba, pring, iocb, 0);
6439
6440 if (ret == IOCB_ERROR) {
6441 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
6442 iocb->fabric_iocb_cmpl = NULL;
6443 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
6444 atomic_dec(&phba->fabric_iocb_count);
6445 }
6446 } else {
6447 spin_lock_irqsave(&phba->hbalock, iflags);
6448 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
6449 spin_unlock_irqrestore(&phba->hbalock, iflags);
6450 ret = IOCB_SUCCESS;
6451 }
6452 return ret;
6453}
6454
James Smarte59058c2008-08-24 21:49:00 -04006455/**
6456 * lpfc_fabric_abort_vport: Abort a vport's iocbs from driver fabric iocb list.
6457 * @vport: pointer to a virtual N_Port data structure.
6458 *
6459 * This routine aborts all the IOCBs associated with a @vport from the
6460 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
6461 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
6462 * list, removes each IOCB associated with the @vport off the list, set the
6463 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
6464 * associated with the IOCB.
6465 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01006466static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
James Smart92d7f7b2007-06-17 19:56:38 -05006467{
6468 LIST_HEAD(completions);
6469 struct lpfc_hba *phba = vport->phba;
6470 struct lpfc_iocbq *tmp_iocb, *piocb;
6471 IOCB_t *cmd;
6472
6473 spin_lock_irq(&phba->hbalock);
6474 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
6475 list) {
6476
6477 if (piocb->vport != vport)
6478 continue;
6479
6480 list_move_tail(&piocb->list, &completions);
6481 }
6482 spin_unlock_irq(&phba->hbalock);
6483
6484 while (!list_empty(&completions)) {
6485 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
6486 list_del_init(&piocb->list);
6487
6488 cmd = &piocb->iocb;
6489 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
6490 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
6491 (piocb->iocb_cmpl) (phba, piocb, piocb);
6492 }
6493}
6494
James Smarte59058c2008-08-24 21:49:00 -04006495/**
6496 * lpfc_fabric_abort_nport: Abort a ndlp's iocbs from driver fabric iocb list.
6497 * @ndlp: pointer to a node-list data structure.
6498 *
6499 * This routine aborts all the IOCBs associated with an @ndlp from the
6500 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
6501 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
6502 * list, removes each IOCB associated with the @ndlp off the list, set the
6503 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
6504 * associated with the IOCB.
6505 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006506void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
6507{
6508 LIST_HEAD(completions);
6509 struct lpfc_hba *phba = ndlp->vport->phba;
6510 struct lpfc_iocbq *tmp_iocb, *piocb;
6511 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
6512 IOCB_t *cmd;
6513
6514 spin_lock_irq(&phba->hbalock);
6515 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
6516 list) {
6517 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
6518
6519 list_move_tail(&piocb->list, &completions);
6520 }
6521 }
6522 spin_unlock_irq(&phba->hbalock);
6523
6524 while (!list_empty(&completions)) {
6525 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
6526 list_del_init(&piocb->list);
6527
6528 cmd = &piocb->iocb;
6529 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
6530 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
6531 (piocb->iocb_cmpl) (phba, piocb, piocb);
6532 }
6533}
6534
James Smarte59058c2008-08-24 21:49:00 -04006535/**
6536 * lpfc_fabric_abort_hba: Abort all iocbs on driver fabric iocb list.
6537 * @phba: pointer to lpfc hba data structure.
6538 *
6539 * This routine aborts all the IOCBs currently on the driver internal
6540 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
6541 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
6542 * list, removes IOCBs off the list, set the status feild to
6543 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
6544 * the IOCB.
6545 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006546void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
6547{
6548 LIST_HEAD(completions);
6549 struct lpfc_iocbq *piocb;
6550 IOCB_t *cmd;
6551
6552 spin_lock_irq(&phba->hbalock);
6553 list_splice_init(&phba->fabric_iocb_list, &completions);
6554 spin_unlock_irq(&phba->hbalock);
6555
6556 while (!list_empty(&completions)) {
6557 piocb = list_get_first(&completions, struct lpfc_iocbq, list);
6558 list_del_init(&piocb->list);
6559
6560 cmd = &piocb->iocb;
6561 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
6562 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
6563 (piocb->iocb_cmpl) (phba, piocb, piocb);
6564 }
6565}