blob: 08b6634cb994a14ca93bfde822a19d9b61332ee8 [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 Smartd8e93df2009-05-22 14:53:05 -04004 * Copyright (C) 2004-2009 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
James Smartda0436e2009-05-22 14:51:39 -040031#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050032#include "lpfc_hw.h"
33#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040034#include "lpfc_sli4.h"
James Smartea2151b2008-09-07 11:52:10 -040035#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050036#include "lpfc_disc.h"
37#include "lpfc_scsi.h"
38#include "lpfc.h"
39#include "lpfc_logmsg.h"
40#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050041#include "lpfc_vport.h"
James Smart858c9f62007-06-17 19:56:39 -050042#include "lpfc_debugfs.h"
dea31012005-04-17 16:05:31 -050043
44static int lpfc_els_retry(struct lpfc_hba *, struct lpfc_iocbq *,
45 struct lpfc_iocbq *);
James Smart92d7f7b2007-06-17 19:56:38 -050046static void lpfc_cmpl_fabric_iocb(struct lpfc_hba *, struct lpfc_iocbq *,
47 struct lpfc_iocbq *);
Adrian Bunka6ababd2007-11-05 18:07:33 +010048static void lpfc_fabric_abort_vport(struct lpfc_vport *vport);
49static int lpfc_issue_els_fdisc(struct lpfc_vport *vport,
50 struct lpfc_nodelist *ndlp, uint8_t retry);
51static int lpfc_issue_fabric_iocb(struct lpfc_hba *phba,
52 struct lpfc_iocbq *iocb);
James Smart92d7f7b2007-06-17 19:56:38 -050053
dea31012005-04-17 16:05:31 -050054static int lpfc_max_els_tries = 3;
55
James Smarte59058c2008-08-24 21:49:00 -040056/**
James Smart3621a712009-04-06 18:47:14 -040057 * lpfc_els_chk_latt - Check host link attention event for a vport
James Smarte59058c2008-08-24 21:49:00 -040058 * @vport: pointer to a host virtual N_Port data structure.
59 *
60 * This routine checks whether there is an outstanding host link
61 * attention event during the discovery process with the @vport. It is done
62 * by reading the HBA's Host Attention (HA) register. If there is any host
63 * link attention events during this @vport's discovery process, the @vport
64 * shall be marked as FC_ABORT_DISCOVERY, a host link attention clear shall
65 * be issued if the link state is not already in host link cleared state,
66 * and a return code shall indicate whether the host link attention event
67 * had happened.
68 *
69 * Note that, if either the host link is in state LPFC_LINK_DOWN or @vport
70 * state in LPFC_VPORT_READY, the request for checking host link attention
71 * event will be ignored and a return code shall indicate no host link
72 * attention event had happened.
73 *
74 * Return codes
75 * 0 - no host link attention event happened
76 * 1 - host link attention event happened
77 **/
James Smart858c9f62007-06-17 19:56:39 -050078int
James Smart2e0fef82007-06-17 19:56:36 -050079lpfc_els_chk_latt(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -050080{
James Smart2e0fef82007-06-17 19:56:36 -050081 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
82 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -050083 uint32_t ha_copy;
dea31012005-04-17 16:05:31 -050084
James Smart2e0fef82007-06-17 19:56:36 -050085 if (vport->port_state >= LPFC_VPORT_READY ||
James Smart3772a992009-05-22 14:50:54 -040086 phba->link_state == LPFC_LINK_DOWN ||
87 phba->sli_rev > LPFC_SLI_REV3)
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/**
James Smart3621a712009-04-06 18:47:14 -0400119 * lpfc_prep_els_iocb - Allocate and prepare a lpfc iocb data structure
James Smarte59058c2008-08-24 21:49:00 -0400120 * @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 **/
James Smartf1c3b0f2009-07-19 10:01:32 -0400146struct 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
James Smart0c287582009-06-10 17:22:56 -0400168 /*
169 * If this command is for fabric controller and HBA running
170 * in FIP mode send FLOGI, FDISC and LOGO as FIP frames.
171 */
172 if ((did == Fabric_DID) &&
James Smart45ed1192009-10-02 15:17:02 -0400173 (phba->hba_flag & HBA_FIP_SUPPORT) &&
James Smart0c287582009-06-10 17:22:56 -0400174 ((elscmd == ELS_CMD_FLOGI) ||
175 (elscmd == ELS_CMD_FDISC) ||
176 (elscmd == ELS_CMD_LOGO)))
James Smartc8685952009-11-18 15:39:16 -0500177 switch (elscmd) {
178 case ELS_CMD_FLOGI:
179 elsiocb->iocb_flag |= ((ELS_ID_FLOGI << LPFC_FIP_ELS_ID_SHIFT)
180 & LPFC_FIP_ELS_ID_MASK);
181 break;
182 case ELS_CMD_FDISC:
183 elsiocb->iocb_flag |= ((ELS_ID_FDISC << LPFC_FIP_ELS_ID_SHIFT)
184 & LPFC_FIP_ELS_ID_MASK);
185 break;
186 case ELS_CMD_LOGO:
187 elsiocb->iocb_flag |= ((ELS_ID_LOGO << LPFC_FIP_ELS_ID_SHIFT)
188 & LPFC_FIP_ELS_ID_MASK);
189 break;
190 }
James Smart0c287582009-06-10 17:22:56 -0400191 else
James Smartc8685952009-11-18 15:39:16 -0500192 elsiocb->iocb_flag &= ~LPFC_FIP_ELS_ID_MASK;
James Smart0c287582009-06-10 17:22:56 -0400193
dea31012005-04-17 16:05:31 -0500194 icmd = &elsiocb->iocb;
195
196 /* fill in BDEs for command */
197 /* Allocate buffer for command payload */
James Smart98c9ea52007-10-27 13:37:33 -0400198 pcmd = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
199 if (pcmd)
200 pcmd->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &pcmd->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500201 if (!pcmd || !pcmd->virt)
202 goto els_iocb_free_pcmb_exit;
dea31012005-04-17 16:05:31 -0500203
204 INIT_LIST_HEAD(&pcmd->list);
205
206 /* Allocate buffer for response payload */
207 if (expectRsp) {
James Smart92d7f7b2007-06-17 19:56:38 -0500208 prsp = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -0500209 if (prsp)
210 prsp->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
211 &prsp->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500212 if (!prsp || !prsp->virt)
213 goto els_iocb_free_prsp_exit;
dea31012005-04-17 16:05:31 -0500214 INIT_LIST_HEAD(&prsp->list);
James Smarte47c9092008-02-08 18:49:26 -0500215 } else
dea31012005-04-17 16:05:31 -0500216 prsp = NULL;
dea31012005-04-17 16:05:31 -0500217
218 /* Allocate buffer for Buffer ptr list */
James Smart92d7f7b2007-06-17 19:56:38 -0500219 pbuflist = kmalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
dea31012005-04-17 16:05:31 -0500220 if (pbuflist)
James Smarted957682007-06-17 19:56:37 -0500221 pbuflist->virt = lpfc_mbuf_alloc(phba, MEM_PRI,
222 &pbuflist->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500223 if (!pbuflist || !pbuflist->virt)
224 goto els_iocb_free_pbuf_exit;
dea31012005-04-17 16:05:31 -0500225
226 INIT_LIST_HEAD(&pbuflist->list);
227
228 icmd->un.elsreq64.bdl.addrHigh = putPaddrHigh(pbuflist->phys);
229 icmd->un.elsreq64.bdl.addrLow = putPaddrLow(pbuflist->phys);
James Smart34b02dc2008-08-24 21:49:55 -0400230 icmd->un.elsreq64.bdl.bdeFlags = BUFF_TYPE_BLP_64;
James Smart2e0fef82007-06-17 19:56:36 -0500231 icmd->un.elsreq64.remoteID = did; /* DID */
dea31012005-04-17 16:05:31 -0500232 if (expectRsp) {
James Smart92d7f7b2007-06-17 19:56:38 -0500233 icmd->un.elsreq64.bdl.bdeSize = (2 * sizeof(struct ulp_bde64));
dea31012005-04-17 16:05:31 -0500234 icmd->ulpCommand = CMD_ELS_REQUEST64_CR;
James Smart2680eea2007-04-25 09:52:55 -0400235 icmd->ulpTimeout = phba->fc_ratov * 2;
dea31012005-04-17 16:05:31 -0500236 } else {
James Smart92d7f7b2007-06-17 19:56:38 -0500237 icmd->un.elsreq64.bdl.bdeSize = sizeof(struct ulp_bde64);
dea31012005-04-17 16:05:31 -0500238 icmd->ulpCommand = CMD_XMIT_ELS_RSP64_CX;
239 }
dea31012005-04-17 16:05:31 -0500240 icmd->ulpBdeCount = 1;
241 icmd->ulpLe = 1;
242 icmd->ulpClass = CLASS3;
243
James Smart92d7f7b2007-06-17 19:56:38 -0500244 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
245 icmd->un.elsreq64.myID = vport->fc_myDID;
246
247 /* For ELS_REQUEST64_CR, use the VPI by default */
James Smartda0436e2009-05-22 14:51:39 -0400248 icmd->ulpContext = vport->vpi + phba->vpi_base;
James Smart92d7f7b2007-06-17 19:56:38 -0500249 icmd->ulpCt_h = 0;
James Smarteada2722008-12-04 22:39:13 -0500250 /* The CT field must be 0=INVALID_RPI for the ECHO cmd */
251 if (elscmd == ELS_CMD_ECHO)
252 icmd->ulpCt_l = 0; /* context = invalid RPI */
253 else
254 icmd->ulpCt_l = 1; /* context = VPI */
James Smart92d7f7b2007-06-17 19:56:38 -0500255 }
256
dea31012005-04-17 16:05:31 -0500257 bpl = (struct ulp_bde64 *) pbuflist->virt;
258 bpl->addrLow = le32_to_cpu(putPaddrLow(pcmd->phys));
259 bpl->addrHigh = le32_to_cpu(putPaddrHigh(pcmd->phys));
260 bpl->tus.f.bdeSize = cmdSize;
261 bpl->tus.f.bdeFlags = 0;
262 bpl->tus.w = le32_to_cpu(bpl->tus.w);
263
264 if (expectRsp) {
265 bpl++;
266 bpl->addrLow = le32_to_cpu(putPaddrLow(prsp->phys));
267 bpl->addrHigh = le32_to_cpu(putPaddrHigh(prsp->phys));
268 bpl->tus.f.bdeSize = FCELSSIZE;
James Smart34b02dc2008-08-24 21:49:55 -0400269 bpl->tus.f.bdeFlags = BUFF_TYPE_BDE_64;
dea31012005-04-17 16:05:31 -0500270 bpl->tus.w = le32_to_cpu(bpl->tus.w);
271 }
272
James Smartfa4066b2008-01-11 01:53:27 -0500273 /* prevent preparing iocb with NULL ndlp reference */
James Smart51ef4c22007-08-02 11:10:31 -0400274 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -0500275 if (!elsiocb->context1)
276 goto els_iocb_free_pbuf_exit;
James Smart329f9bc2007-04-25 09:53:01 -0400277 elsiocb->context2 = pcmd;
278 elsiocb->context3 = pbuflist;
dea31012005-04-17 16:05:31 -0500279 elsiocb->retry = retry;
James Smart2e0fef82007-06-17 19:56:36 -0500280 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -0500281 elsiocb->drvrTimeout = (phba->fc_ratov << 1) + LPFC_DRVR_TIMEOUT;
282
283 if (prsp) {
284 list_add(&prsp->list, &pcmd->list);
285 }
dea31012005-04-17 16:05:31 -0500286 if (expectRsp) {
287 /* Xmit ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400288 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
289 "0116 Xmit ELS command x%x to remote "
290 "NPORT x%x I/O tag: x%x, port state: x%x\n",
291 elscmd, did, elsiocb->iotag,
292 vport->port_state);
dea31012005-04-17 16:05:31 -0500293 } else {
294 /* Xmit ELS response <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -0400295 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
296 "0117 Xmit ELS response x%x to remote "
297 "NPORT x%x I/O tag: x%x, size: x%x\n",
298 elscmd, ndlp->nlp_DID, elsiocb->iotag,
299 cmdSize);
dea31012005-04-17 16:05:31 -0500300 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500301 return elsiocb;
dea31012005-04-17 16:05:31 -0500302
James Smartfa4066b2008-01-11 01:53:27 -0500303els_iocb_free_pbuf_exit:
James Smarteaf15d52008-12-04 22:39:29 -0500304 if (expectRsp)
305 lpfc_mbuf_free(phba, prsp->virt, prsp->phys);
James Smartfa4066b2008-01-11 01:53:27 -0500306 kfree(pbuflist);
307
308els_iocb_free_prsp_exit:
309 lpfc_mbuf_free(phba, pcmd->virt, pcmd->phys);
310 kfree(prsp);
311
312els_iocb_free_pcmb_exit:
313 kfree(pcmd);
314 lpfc_sli_release_iocbq(phba, elsiocb);
315 return NULL;
316}
dea31012005-04-17 16:05:31 -0500317
James Smarte59058c2008-08-24 21:49:00 -0400318/**
James Smart3621a712009-04-06 18:47:14 -0400319 * lpfc_issue_fabric_reglogin - Issue fabric registration login for a vport
James Smarte59058c2008-08-24 21:49:00 -0400320 * @vport: pointer to a host virtual N_Port data structure.
321 *
322 * This routine issues a fabric registration login for a @vport. An
323 * active ndlp node with Fabric_DID must already exist for this @vport.
324 * The routine invokes two mailbox commands to carry out fabric registration
325 * login through the HBA firmware: the first mailbox command requests the
326 * HBA to perform link configuration for the @vport; and the second mailbox
327 * command requests the HBA to perform the actual fabric registration login
328 * with the @vport.
329 *
330 * Return code
331 * 0 - successfully issued fabric registration login for @vport
332 * -ENXIO -- failed to issue fabric registration login for @vport
333 **/
James Smart3772a992009-05-22 14:50:54 -0400334int
James Smart92d7f7b2007-06-17 19:56:38 -0500335lpfc_issue_fabric_reglogin(struct lpfc_vport *vport)
336{
337 struct lpfc_hba *phba = vport->phba;
338 LPFC_MBOXQ_t *mbox;
339 struct lpfc_dmabuf *mp;
340 struct lpfc_nodelist *ndlp;
341 struct serv_parm *sp;
342 int rc;
James Smart98c9ea52007-10-27 13:37:33 -0400343 int err = 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500344
345 sp = &phba->fc_fabparam;
346 ndlp = lpfc_findnode_did(vport, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -0500347 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -0400348 err = 1;
James Smart92d7f7b2007-06-17 19:56:38 -0500349 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400350 }
James Smart92d7f7b2007-06-17 19:56:38 -0500351
352 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart98c9ea52007-10-27 13:37:33 -0400353 if (!mbox) {
354 err = 2;
James Smart92d7f7b2007-06-17 19:56:38 -0500355 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400356 }
James Smart92d7f7b2007-06-17 19:56:38 -0500357
358 vport->port_state = LPFC_FABRIC_CFG_LINK;
359 lpfc_config_link(phba, mbox);
360 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
361 mbox->vport = vport;
362
James Smart0b727fe2007-10-27 13:37:25 -0400363 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart98c9ea52007-10-27 13:37:33 -0400364 if (rc == MBX_NOT_FINISHED) {
365 err = 3;
James Smart92d7f7b2007-06-17 19:56:38 -0500366 goto fail_free_mbox;
James Smart98c9ea52007-10-27 13:37:33 -0400367 }
James Smart92d7f7b2007-06-17 19:56:38 -0500368
369 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart98c9ea52007-10-27 13:37:33 -0400370 if (!mbox) {
371 err = 4;
James Smart92d7f7b2007-06-17 19:56:38 -0500372 goto fail;
James Smart98c9ea52007-10-27 13:37:33 -0400373 }
James Smart3772a992009-05-22 14:50:54 -0400374 rc = lpfc_reg_rpi(phba, vport->vpi, Fabric_DID, (uint8_t *)sp, mbox, 0);
James Smart98c9ea52007-10-27 13:37:33 -0400375 if (rc) {
376 err = 5;
James Smart92d7f7b2007-06-17 19:56:38 -0500377 goto fail_free_mbox;
James Smart98c9ea52007-10-27 13:37:33 -0400378 }
James Smart92d7f7b2007-06-17 19:56:38 -0500379
380 mbox->mbox_cmpl = lpfc_mbx_cmpl_fabric_reg_login;
381 mbox->vport = vport;
James Smarte47c9092008-02-08 18:49:26 -0500382 /* increment the reference count on ndlp to hold reference
383 * for the callback routine.
384 */
James Smart92d7f7b2007-06-17 19:56:38 -0500385 mbox->context2 = lpfc_nlp_get(ndlp);
386
James Smart0b727fe2007-10-27 13:37:25 -0400387 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart98c9ea52007-10-27 13:37:33 -0400388 if (rc == MBX_NOT_FINISHED) {
389 err = 6;
James Smart92d7f7b2007-06-17 19:56:38 -0500390 goto fail_issue_reg_login;
James Smart98c9ea52007-10-27 13:37:33 -0400391 }
James Smart92d7f7b2007-06-17 19:56:38 -0500392
393 return 0;
394
395fail_issue_reg_login:
James Smarte47c9092008-02-08 18:49:26 -0500396 /* decrement the reference count on ndlp just incremented
397 * for the failed mbox command.
398 */
James Smart92d7f7b2007-06-17 19:56:38 -0500399 lpfc_nlp_put(ndlp);
400 mp = (struct lpfc_dmabuf *) mbox->context1;
401 lpfc_mbuf_free(phba, mp->virt, mp->phys);
402 kfree(mp);
403fail_free_mbox:
404 mempool_free(mbox, phba->mbox_mem_pool);
405
406fail:
407 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -0400408 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smart98c9ea52007-10-27 13:37:33 -0400409 "0249 Cannot issue Register Fabric login: Err %d\n", err);
James Smart92d7f7b2007-06-17 19:56:38 -0500410 return -ENXIO;
411}
412
James Smarte59058c2008-08-24 21:49:00 -0400413/**
James Smart6fb120a2009-05-22 14:52:59 -0400414 * lpfc_issue_reg_vfi - Register VFI for this vport's fabric login
415 * @vport: pointer to a host virtual N_Port data structure.
416 *
417 * This routine issues a REG_VFI mailbox for the vfi, vpi, fcfi triplet for
418 * the @vport. This mailbox command is necessary for FCoE only.
419 *
420 * Return code
421 * 0 - successfully issued REG_VFI for @vport
422 * A failure code otherwise.
423 **/
424static int
425lpfc_issue_reg_vfi(struct lpfc_vport *vport)
426{
427 struct lpfc_hba *phba = vport->phba;
428 LPFC_MBOXQ_t *mboxq;
429 struct lpfc_nodelist *ndlp;
430 struct serv_parm *sp;
431 struct lpfc_dmabuf *dmabuf;
432 int rc = 0;
433
434 sp = &phba->fc_fabparam;
435 ndlp = lpfc_findnode_did(vport, Fabric_DID);
436 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
437 rc = -ENODEV;
438 goto fail;
439 }
440
441 dmabuf = kzalloc(sizeof(struct lpfc_dmabuf), GFP_KERNEL);
442 if (!dmabuf) {
443 rc = -ENOMEM;
444 goto fail;
445 }
446 dmabuf->virt = lpfc_mbuf_alloc(phba, MEM_PRI, &dmabuf->phys);
447 if (!dmabuf->virt) {
448 rc = -ENOMEM;
449 goto fail_free_dmabuf;
450 }
451 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
452 if (!mboxq) {
453 rc = -ENOMEM;
454 goto fail_free_coherent;
455 }
456 vport->port_state = LPFC_FABRIC_CFG_LINK;
457 memcpy(dmabuf->virt, &phba->fc_fabparam, sizeof(vport->fc_sparam));
458 lpfc_reg_vfi(mboxq, vport, dmabuf->phys);
459 mboxq->mbox_cmpl = lpfc_mbx_cmpl_reg_vfi;
460 mboxq->vport = vport;
461 mboxq->context1 = dmabuf;
462 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
463 if (rc == MBX_NOT_FINISHED) {
464 rc = -ENXIO;
465 goto fail_free_mbox;
466 }
467 return 0;
468
469fail_free_mbox:
470 mempool_free(mboxq, phba->mbox_mem_pool);
471fail_free_coherent:
472 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
473fail_free_dmabuf:
474 kfree(dmabuf);
475fail:
476 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
477 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
478 "0289 Issue Register VFI failed: Err %d\n", rc);
479 return rc;
480}
481
482/**
James Smart3621a712009-04-06 18:47:14 -0400483 * lpfc_cmpl_els_flogi_fabric - Completion function for flogi to a fabric port
James Smarte59058c2008-08-24 21:49:00 -0400484 * @vport: pointer to a host virtual N_Port data structure.
485 * @ndlp: pointer to a node-list data structure.
486 * @sp: pointer to service parameter data structure.
487 * @irsp: pointer to the IOCB within the lpfc response IOCB.
488 *
489 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
490 * function to handle the completion of a Fabric Login (FLOGI) into a fabric
491 * port in a fabric topology. It properly sets up the parameters to the @ndlp
492 * from the IOCB response. It also check the newly assigned N_Port ID to the
493 * @vport against the previously assigned N_Port ID. If it is different from
494 * the previously assigned Destination ID (DID), the lpfc_unreg_rpi() routine
495 * is invoked on all the remaining nodes with the @vport to unregister the
496 * Remote Port Indicators (RPIs). Finally, the lpfc_issue_fabric_reglogin()
497 * is invoked to register login to the fabric.
498 *
499 * Return code
500 * 0 - Success (currently, always return 0)
501 **/
James Smart92d7f7b2007-06-17 19:56:38 -0500502static int
James Smart2e0fef82007-06-17 19:56:36 -0500503lpfc_cmpl_els_flogi_fabric(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
504 struct serv_parm *sp, IOCB_t *irsp)
dea31012005-04-17 16:05:31 -0500505{
James Smart2e0fef82007-06-17 19:56:36 -0500506 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
507 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -0500508 struct lpfc_nodelist *np;
509 struct lpfc_nodelist *next_np;
dea31012005-04-17 16:05:31 -0500510
James Smart2e0fef82007-06-17 19:56:36 -0500511 spin_lock_irq(shost->host_lock);
512 vport->fc_flag |= FC_FABRIC;
513 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500514
515 phba->fc_edtov = be32_to_cpu(sp->cmn.e_d_tov);
516 if (sp->cmn.edtovResolution) /* E_D_TOV ticks are in nanoseconds */
517 phba->fc_edtov = (phba->fc_edtov + 999999) / 1000000;
518
519 phba->fc_ratov = (be32_to_cpu(sp->cmn.w2.r_a_tov) + 999) / 1000;
520
521 if (phba->fc_topology == TOPOLOGY_LOOP) {
James Smart2e0fef82007-06-17 19:56:36 -0500522 spin_lock_irq(shost->host_lock);
523 vport->fc_flag |= FC_PUBLIC_LOOP;
524 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500525 } else {
526 /*
527 * If we are a N-port connected to a Fabric, fixup sparam's so
528 * logins to devices on remote loops work.
529 */
James Smart2e0fef82007-06-17 19:56:36 -0500530 vport->fc_sparam.cmn.altBbCredit = 1;
dea31012005-04-17 16:05:31 -0500531 }
532
James Smart2e0fef82007-06-17 19:56:36 -0500533 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
dea31012005-04-17 16:05:31 -0500534 memcpy(&ndlp->nlp_portname, &sp->portName, sizeof(struct lpfc_name));
James Smart92d7f7b2007-06-17 19:56:38 -0500535 memcpy(&ndlp->nlp_nodename, &sp->nodeName, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500536 ndlp->nlp_class_sup = 0;
537 if (sp->cls1.classValid)
538 ndlp->nlp_class_sup |= FC_COS_CLASS1;
539 if (sp->cls2.classValid)
540 ndlp->nlp_class_sup |= FC_COS_CLASS2;
541 if (sp->cls3.classValid)
542 ndlp->nlp_class_sup |= FC_COS_CLASS3;
543 if (sp->cls4.classValid)
544 ndlp->nlp_class_sup |= FC_COS_CLASS4;
545 ndlp->nlp_maxframe = ((sp->cmn.bbRcvSizeMsb & 0x0F) << 8) |
546 sp->cmn.bbRcvSizeLsb;
547 memcpy(&phba->fc_fabparam, sp, sizeof(struct serv_parm));
548
James Smart92d7f7b2007-06-17 19:56:38 -0500549 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
550 if (sp->cmn.response_multiple_NPort) {
James Smarte8b62012007-08-02 11:10:09 -0400551 lpfc_printf_vlog(vport, KERN_WARNING,
552 LOG_ELS | LOG_VPORT,
553 "1816 FLOGI NPIV supported, "
554 "response data 0x%x\n",
555 sp->cmn.response_multiple_NPort);
James Smart92d7f7b2007-06-17 19:56:38 -0500556 phba->link_flag |= LS_NPIV_FAB_SUPPORTED;
James Smart92d7f7b2007-06-17 19:56:38 -0500557 } else {
558 /* Because we asked f/w for NPIV it still expects us
James Smarte8b62012007-08-02 11:10:09 -0400559 to call reg_vnpid atleast for the physcial host */
560 lpfc_printf_vlog(vport, KERN_WARNING,
561 LOG_ELS | LOG_VPORT,
562 "1817 Fabric does not support NPIV "
563 "- configuring single port mode.\n");
James Smart92d7f7b2007-06-17 19:56:38 -0500564 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
565 }
566 }
567
568 if ((vport->fc_prevDID != vport->fc_myDID) &&
569 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
570
571 /* If our NportID changed, we need to ensure all
572 * remaining NPORTs get unreg_login'ed.
573 */
574 list_for_each_entry_safe(np, next_np,
575 &vport->fc_nodes, nlp_listp) {
James Smartd7c255b2008-08-24 21:50:00 -0400576 if (!NLP_CHK_NODE_ACT(np))
James Smarte47c9092008-02-08 18:49:26 -0500577 continue;
James Smart92d7f7b2007-06-17 19:56:38 -0500578 if ((np->nlp_state != NLP_STE_NPR_NODE) ||
579 !(np->nlp_flag & NLP_NPR_ADISC))
580 continue;
581 spin_lock_irq(shost->host_lock);
582 np->nlp_flag &= ~NLP_NPR_ADISC;
583 spin_unlock_irq(shost->host_lock);
584 lpfc_unreg_rpi(vport, np);
585 }
586 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
587 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -0500588 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500589 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -0500590 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500591 }
James Smartecfd03c2010-02-12 14:41:27 -0500592 /*
593 * If VPI is unreged, driver need to do INIT_VPI
594 * before re-registering
595 */
596 if (phba->sli_rev == LPFC_SLI_REV4) {
597 spin_lock_irq(shost->host_lock);
598 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
599 spin_unlock_irq(shost->host_lock);
600 }
James Smart92d7f7b2007-06-17 19:56:38 -0500601 }
602
James Smart6fb120a2009-05-22 14:52:59 -0400603 if (phba->sli_rev < LPFC_SLI_REV4) {
604 lpfc_nlp_set_state(vport, ndlp, NLP_STE_REG_LOGIN_ISSUE);
605 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED &&
606 vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
607 lpfc_register_new_vport(phba, vport, ndlp);
608 else
609 lpfc_issue_fabric_reglogin(vport);
610 } else {
611 ndlp->nlp_type |= NLP_FABRIC;
612 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
James Smart695a8142010-01-26 23:08:03 -0500613 if ((!(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) &&
614 (vport->vpi_state & LPFC_VPI_REGISTERED)) {
James Smart6fb120a2009-05-22 14:52:59 -0400615 lpfc_start_fdiscs(phba);
616 lpfc_do_scr_ns_plogi(phba, vport);
James Smart695a8142010-01-26 23:08:03 -0500617 } else if (vport->fc_flag & FC_VFI_REGISTERED)
James Smartecfd03c2010-02-12 14:41:27 -0500618 lpfc_issue_init_vpi(vport);
James Smart695a8142010-01-26 23:08:03 -0500619 else
James Smart6fb120a2009-05-22 14:52:59 -0400620 lpfc_issue_reg_vfi(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500621 }
dea31012005-04-17 16:05:31 -0500622 return 0;
dea31012005-04-17 16:05:31 -0500623}
James Smarte59058c2008-08-24 21:49:00 -0400624/**
James Smart3621a712009-04-06 18:47:14 -0400625 * lpfc_cmpl_els_flogi_nport - Completion function for flogi to an N_Port
James Smarte59058c2008-08-24 21:49:00 -0400626 * @vport: pointer to a host virtual N_Port data structure.
627 * @ndlp: pointer to a node-list data structure.
628 * @sp: pointer to service parameter data structure.
629 *
630 * This routine is invoked by the lpfc_cmpl_els_flogi() completion callback
631 * function to handle the completion of a Fabric Login (FLOGI) into an N_Port
632 * in a point-to-point topology. First, the @vport's N_Port Name is compared
633 * with the received N_Port Name: if the @vport's N_Port Name is greater than
634 * the received N_Port Name lexicographically, this node shall assign local
635 * N_Port ID (PT2PT_LocalID: 1) and remote N_Port ID (PT2PT_RemoteID: 2) and
636 * will send out Port Login (PLOGI) with the N_Port IDs assigned. Otherwise,
637 * this node shall just wait for the remote node to issue PLOGI and assign
638 * N_Port IDs.
639 *
640 * Return code
641 * 0 - Success
642 * -ENXIO - Fail
643 **/
dea31012005-04-17 16:05:31 -0500644static int
James Smart2e0fef82007-06-17 19:56:36 -0500645lpfc_cmpl_els_flogi_nport(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
646 struct serv_parm *sp)
dea31012005-04-17 16:05:31 -0500647{
James Smart2e0fef82007-06-17 19:56:36 -0500648 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
649 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500650 LPFC_MBOXQ_t *mbox;
651 int rc;
652
James Smart2e0fef82007-06-17 19:56:36 -0500653 spin_lock_irq(shost->host_lock);
654 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
655 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500656
657 phba->fc_edtov = FF_DEF_EDTOV;
658 phba->fc_ratov = FF_DEF_RATOV;
James Smart2e0fef82007-06-17 19:56:36 -0500659 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -0500660 sizeof(vport->fc_portname));
dea31012005-04-17 16:05:31 -0500661 if (rc >= 0) {
662 /* This side will initiate the PLOGI */
James Smart2e0fef82007-06-17 19:56:36 -0500663 spin_lock_irq(shost->host_lock);
664 vport->fc_flag |= FC_PT2PT_PLOGI;
665 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500666
667 /*
668 * N_Port ID cannot be 0, set our to LocalID the other
669 * side will be RemoteID.
670 */
671
672 /* not equal */
673 if (rc)
James Smart2e0fef82007-06-17 19:56:36 -0500674 vport->fc_myDID = PT2PT_LocalID;
dea31012005-04-17 16:05:31 -0500675
676 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
677 if (!mbox)
678 goto fail;
679
680 lpfc_config_link(phba, mbox);
681
682 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -0500683 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -0400684 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -0500685 if (rc == MBX_NOT_FINISHED) {
686 mempool_free(mbox, phba->mbox_mem_pool);
687 goto fail;
688 }
James Smarte47c9092008-02-08 18:49:26 -0500689 /* Decrement ndlp reference count indicating that ndlp can be
690 * safely released when other references to it are done.
691 */
James Smart329f9bc2007-04-25 09:53:01 -0400692 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500693
James Smart2e0fef82007-06-17 19:56:36 -0500694 ndlp = lpfc_findnode_did(vport, PT2PT_RemoteID);
dea31012005-04-17 16:05:31 -0500695 if (!ndlp) {
696 /*
697 * Cannot find existing Fabric ndlp, so allocate a
698 * new one
699 */
700 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
701 if (!ndlp)
702 goto fail;
James Smart2e0fef82007-06-17 19:56:36 -0500703 lpfc_nlp_init(vport, ndlp, PT2PT_RemoteID);
James Smarte47c9092008-02-08 18:49:26 -0500704 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
705 ndlp = lpfc_enable_node(vport, ndlp,
706 NLP_STE_UNUSED_NODE);
707 if(!ndlp)
708 goto fail;
dea31012005-04-17 16:05:31 -0500709 }
710
711 memcpy(&ndlp->nlp_portname, &sp->portName,
James Smart2e0fef82007-06-17 19:56:36 -0500712 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -0500713 memcpy(&ndlp->nlp_nodename, &sp->nodeName,
James Smart2e0fef82007-06-17 19:56:36 -0500714 sizeof(struct lpfc_name));
James Smarte47c9092008-02-08 18:49:26 -0500715 /* Set state will put ndlp onto node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -0500716 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
717 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500718 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -0500719 spin_unlock_irq(shost->host_lock);
James Smarte47c9092008-02-08 18:49:26 -0500720 } else
721 /* This side will wait for the PLOGI, decrement ndlp reference
722 * count indicating that ndlp can be released when other
723 * references to it are done.
724 */
James Smart329f9bc2007-04-25 09:53:01 -0400725 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500726
James Smart09372822008-01-11 01:52:54 -0500727 /* If we are pt2pt with another NPort, force NPIV off! */
728 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
729
James Smart2e0fef82007-06-17 19:56:36 -0500730 spin_lock_irq(shost->host_lock);
731 vport->fc_flag |= FC_PT2PT;
732 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500733
734 /* Start discovery - this should just do CLEAR_LA */
James Smart2e0fef82007-06-17 19:56:36 -0500735 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -0500736 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -0500737fail:
dea31012005-04-17 16:05:31 -0500738 return -ENXIO;
739}
740
James Smarte59058c2008-08-24 21:49:00 -0400741/**
James Smart3621a712009-04-06 18:47:14 -0400742 * lpfc_cmpl_els_flogi - Completion callback function for flogi
James Smarte59058c2008-08-24 21:49:00 -0400743 * @phba: pointer to lpfc hba data structure.
744 * @cmdiocb: pointer to lpfc command iocb data structure.
745 * @rspiocb: pointer to lpfc response iocb data structure.
746 *
747 * This routine is the top-level completion callback function for issuing
748 * a Fabric Login (FLOGI) command. If the response IOCB reported error,
749 * the lpfc_els_retry() routine shall be invoked to retry the FLOGI. If
750 * retry has been made (either immediately or delayed with lpfc_els_retry()
751 * returning 1), the command IOCB will be released and function returned.
752 * If the retry attempt has been given up (possibly reach the maximum
753 * number of retries), one additional decrement of ndlp reference shall be
754 * invoked before going out after releasing the command IOCB. This will
755 * actually release the remote node (Note, lpfc_els_free_iocb() will also
756 * invoke one decrement of ndlp reference count). If no error reported in
757 * the IOCB status, the command Port ID field is used to determine whether
758 * this is a point-to-point topology or a fabric topology: if the Port ID
759 * field is assigned, it is a fabric topology; otherwise, it is a
760 * point-to-point topology. The routine lpfc_cmpl_els_flogi_fabric() or
761 * lpfc_cmpl_els_flogi_nport() shall be invoked accordingly to handle the
762 * specific topology completion conditions.
763 **/
dea31012005-04-17 16:05:31 -0500764static void
James Smart329f9bc2007-04-25 09:53:01 -0400765lpfc_cmpl_els_flogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
766 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -0500767{
James Smart2e0fef82007-06-17 19:56:36 -0500768 struct lpfc_vport *vport = cmdiocb->vport;
769 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500770 IOCB_t *irsp = &rspiocb->iocb;
771 struct lpfc_nodelist *ndlp = cmdiocb->context1;
772 struct lpfc_dmabuf *pcmd = cmdiocb->context2, *prsp;
773 struct serv_parm *sp;
774 int rc;
775
776 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500777 if (lpfc_els_chk_latt(vport)) {
James Smartfa4066b2008-01-11 01:53:27 -0500778 /* One additional decrement on node reference count to
779 * trigger the release of the node
780 */
James Smart329f9bc2007-04-25 09:53:01 -0400781 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500782 goto out;
783 }
784
James Smart858c9f62007-06-17 19:56:39 -0500785 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
786 "FLOGI cmpl: status:x%x/x%x state:x%x",
787 irsp->ulpStatus, irsp->un.ulpWord[4],
788 vport->port_state);
789
dea31012005-04-17 16:05:31 -0500790 if (irsp->ulpStatus) {
791 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -0500792 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -0500793 goto out;
James Smart2e0fef82007-06-17 19:56:36 -0500794
dea31012005-04-17 16:05:31 -0500795 /* FLOGI failed, so there is no fabric */
James Smart2e0fef82007-06-17 19:56:36 -0500796 spin_lock_irq(shost->host_lock);
797 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
798 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500799
James Smart329f9bc2007-04-25 09:53:01 -0400800 /* If private loop, then allow max outstanding els to be
dea31012005-04-17 16:05:31 -0500801 * LPFC_MAX_DISC_THREADS (32). Scanning in the case of no
802 * alpa map would take too long otherwise.
803 */
804 if (phba->alpa_map[0] == 0) {
James Smart3de2a652007-08-02 11:09:59 -0400805 vport->cfg_discovery_threads = LPFC_MAX_DISC_THREADS;
dea31012005-04-17 16:05:31 -0500806 }
807
808 /* FLOGI failure */
James Smarte8b62012007-08-02 11:10:09 -0400809 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
810 "0100 FLOGI failure Data: x%x x%x "
811 "x%x\n",
812 irsp->ulpStatus, irsp->un.ulpWord[4],
813 irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -0500814 goto flogifail;
815 }
James Smart695a8142010-01-26 23:08:03 -0500816 spin_lock_irq(shost->host_lock);
817 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
818 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500819
820 /*
821 * The FLogI succeeded. Sync the data for the CPU before
822 * accessing it.
823 */
824 prsp = list_get_first(&pcmd->list, struct lpfc_dmabuf, list);
825
826 sp = prsp->virt + sizeof(uint32_t);
827
828 /* FLOGI completes successfully */
James Smarte8b62012007-08-02 11:10:09 -0400829 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
André Goddard Rosaaf901ca2009-11-14 13:09:05 -0200830 "0101 FLOGI completes successfully "
James Smarte8b62012007-08-02 11:10:09 -0400831 "Data: x%x x%x x%x x%x\n",
832 irsp->un.ulpWord[4], sp->cmn.e_d_tov,
833 sp->cmn.w2.r_a_tov, sp->cmn.edtovResolution);
dea31012005-04-17 16:05:31 -0500834
James Smart2e0fef82007-06-17 19:56:36 -0500835 if (vport->port_state == LPFC_FLOGI) {
dea31012005-04-17 16:05:31 -0500836 /*
837 * If Common Service Parameters indicate Nport
838 * we are point to point, if Fport we are Fabric.
839 */
840 if (sp->cmn.fPort)
James Smart2e0fef82007-06-17 19:56:36 -0500841 rc = lpfc_cmpl_els_flogi_fabric(vport, ndlp, sp, irsp);
dea31012005-04-17 16:05:31 -0500842 else
James Smart2e0fef82007-06-17 19:56:36 -0500843 rc = lpfc_cmpl_els_flogi_nport(vport, ndlp, sp);
dea31012005-04-17 16:05:31 -0500844
845 if (!rc)
846 goto out;
847 }
848
849flogifail:
James Smart329f9bc2007-04-25 09:53:01 -0400850 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500851
James Smart858c9f62007-06-17 19:56:39 -0500852 if (!lpfc_error_lost_link(irsp)) {
dea31012005-04-17 16:05:31 -0500853 /* FLOGI failed, so just use loop map to make discovery list */
James Smart2e0fef82007-06-17 19:56:36 -0500854 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -0500855
856 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500857 lpfc_disc_start(vport);
James Smart87af33f2007-10-27 13:37:43 -0400858 } else if (((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
859 ((irsp->un.ulpWord[4] != IOERR_SLI_ABORTED) &&
860 (irsp->un.ulpWord[4] != IOERR_SLI_DOWN))) &&
861 (phba->link_state != LPFC_CLEAR_LA)) {
862 /* If FLOGI failed enable link interrupt. */
863 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -0500864 }
dea31012005-04-17 16:05:31 -0500865out:
866 lpfc_els_free_iocb(phba, cmdiocb);
867}
868
James Smarte59058c2008-08-24 21:49:00 -0400869/**
James Smart3621a712009-04-06 18:47:14 -0400870 * lpfc_issue_els_flogi - Issue an flogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -0400871 * @vport: pointer to a host virtual N_Port data structure.
872 * @ndlp: pointer to a node-list data structure.
873 * @retry: number of retries to the command IOCB.
874 *
875 * This routine issues a Fabric Login (FLOGI) Request ELS command
876 * for a @vport. The initiator service parameters are put into the payload
877 * of the FLOGI Request IOCB and the top-level callback function pointer
878 * to lpfc_cmpl_els_flogi() routine is put to the IOCB completion callback
879 * function field. The lpfc_issue_fabric_iocb routine is invoked to send
880 * out FLOGI ELS command with one outstanding fabric IOCB at a time.
881 *
882 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
883 * will be incremented by 1 for holding the ndlp and the reference to ndlp
884 * will be stored into the context1 field of the IOCB for the completion
885 * callback function to the FLOGI ELS command.
886 *
887 * Return code
888 * 0 - successfully issued flogi iocb for @vport
889 * 1 - failed to issue flogi iocb for @vport
890 **/
dea31012005-04-17 16:05:31 -0500891static int
James Smart2e0fef82007-06-17 19:56:36 -0500892lpfc_issue_els_flogi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -0500893 uint8_t retry)
894{
James Smart2e0fef82007-06-17 19:56:36 -0500895 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500896 struct serv_parm *sp;
897 IOCB_t *icmd;
898 struct lpfc_iocbq *elsiocb;
899 struct lpfc_sli_ring *pring;
900 uint8_t *pcmd;
901 uint16_t cmdsize;
902 uint32_t tmo;
903 int rc;
904
905 pring = &phba->sli.ring[LPFC_ELS_RING];
906
James Smart92d7f7b2007-06-17 19:56:38 -0500907 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart2e0fef82007-06-17 19:56:36 -0500908 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
909 ndlp->nlp_DID, ELS_CMD_FLOGI);
James Smart92d7f7b2007-06-17 19:56:38 -0500910
James Smart488d1462006-03-07 15:02:37 -0500911 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500912 return 1;
dea31012005-04-17 16:05:31 -0500913
914 icmd = &elsiocb->iocb;
915 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
916
917 /* For FLOGI request, remainder of payload is service parameters */
918 *((uint32_t *) (pcmd)) = ELS_CMD_FLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -0500919 pcmd += sizeof(uint32_t);
920 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -0500921 sp = (struct serv_parm *) pcmd;
922
923 /* Setup CSPs accordingly for Fabric */
924 sp->cmn.e_d_tov = 0;
925 sp->cmn.w2.r_a_tov = 0;
926 sp->cls1.classValid = 0;
927 sp->cls2.seqDelivery = 1;
928 sp->cls3.seqDelivery = 1;
929 if (sp->cmn.fcphLow < FC_PH3)
930 sp->cmn.fcphLow = FC_PH3;
931 if (sp->cmn.fcphHigh < FC_PH3)
932 sp->cmn.fcphHigh = FC_PH3;
933
James Smart6fb120a2009-05-22 14:52:59 -0400934 if (phba->sli_rev == LPFC_SLI_REV4) {
935 elsiocb->iocb.ulpCt_h = ((SLI4_CT_FCFI >> 1) & 1);
936 elsiocb->iocb.ulpCt_l = (SLI4_CT_FCFI & 1);
937 /* FLOGI needs to be 3 for WQE FCFI */
938 /* Set the fcfi to the fcfi we registered with */
939 elsiocb->iocb.ulpContext = phba->fcf.fcfi;
940 } else if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -0500941 sp->cmn.request_multiple_Nport = 1;
James Smart92d7f7b2007-06-17 19:56:38 -0500942 /* For FLOGI, Let FLOGI rsp set the NPortID for VPI 0 */
943 icmd->ulpCt_h = 1;
944 icmd->ulpCt_l = 0;
945 }
946
James Smart858c9f62007-06-17 19:56:39 -0500947 if (phba->fc_topology != TOPOLOGY_LOOP) {
948 icmd->un.elsreq64.myID = 0;
949 icmd->un.elsreq64.fl = 1;
950 }
951
dea31012005-04-17 16:05:31 -0500952 tmo = phba->fc_ratov;
953 phba->fc_ratov = LPFC_DISC_FLOGI_TMO;
James Smart2e0fef82007-06-17 19:56:36 -0500954 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -0500955 phba->fc_ratov = tmo;
956
957 phba->fc_stat.elsXmitFLOGI++;
958 elsiocb->iocb_cmpl = lpfc_cmpl_els_flogi;
James Smart858c9f62007-06-17 19:56:39 -0500959
960 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
961 "Issue FLOGI: opt:x%x",
962 phba->sli3_options, 0, 0);
963
James Smart92d7f7b2007-06-17 19:56:38 -0500964 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
dea31012005-04-17 16:05:31 -0500965 if (rc == IOCB_ERROR) {
966 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500967 return 1;
dea31012005-04-17 16:05:31 -0500968 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500969 return 0;
dea31012005-04-17 16:05:31 -0500970}
971
James Smarte59058c2008-08-24 21:49:00 -0400972/**
James Smart3621a712009-04-06 18:47:14 -0400973 * lpfc_els_abort_flogi - Abort all outstanding flogi iocbs
James Smarte59058c2008-08-24 21:49:00 -0400974 * @phba: pointer to lpfc hba data structure.
975 *
976 * This routine aborts all the outstanding Fabric Login (FLOGI) IOCBs
977 * with a @phba. This routine walks all the outstanding IOCBs on the txcmplq
978 * list and issues an abort IOCB commond on each outstanding IOCB that
979 * contains a active Fabric_DID ndlp. Note that this function is to issue
980 * the abort IOCB command on all the outstanding IOCBs, thus when this
981 * function returns, it does not guarantee all the IOCBs are actually aborted.
982 *
983 * Return code
984 * 0 - Sucessfully issued abort iocb on all outstanding flogis (Always 0)
985 **/
dea31012005-04-17 16:05:31 -0500986int
James Smart2e0fef82007-06-17 19:56:36 -0500987lpfc_els_abort_flogi(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500988{
989 struct lpfc_sli_ring *pring;
990 struct lpfc_iocbq *iocb, *next_iocb;
991 struct lpfc_nodelist *ndlp;
992 IOCB_t *icmd;
993
994 /* Abort outstanding I/O on NPort <nlp_DID> */
995 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smarte8b62012007-08-02 11:10:09 -0400996 "0201 Abort outstanding I/O on NPort x%x\n",
997 Fabric_DID);
dea31012005-04-17 16:05:31 -0500998
999 pring = &phba->sli.ring[LPFC_ELS_RING];
1000
1001 /*
1002 * Check the txcmplq for an iocb that matches the nport the driver is
1003 * searching for.
1004 */
James Smart2e0fef82007-06-17 19:56:36 -05001005 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001006 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
1007 icmd = &iocb->iocb;
James Smart2e0fef82007-06-17 19:56:36 -05001008 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR &&
1009 icmd->un.elsreq64.bdl.ulpIoTag32) {
dea31012005-04-17 16:05:31 -05001010 ndlp = (struct lpfc_nodelist *)(iocb->context1);
James Smart58da1ff2008-04-07 10:15:56 -04001011 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
1012 (ndlp->nlp_DID == Fabric_DID))
James Smart07951072007-04-25 09:51:38 -04001013 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
dea31012005-04-17 16:05:31 -05001014 }
1015 }
James Smart2e0fef82007-06-17 19:56:36 -05001016 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001017
1018 return 0;
1019}
1020
James Smarte59058c2008-08-24 21:49:00 -04001021/**
James Smart3621a712009-04-06 18:47:14 -04001022 * lpfc_initial_flogi - Issue an initial fabric login for a vport
James Smarte59058c2008-08-24 21:49:00 -04001023 * @vport: pointer to a host virtual N_Port data structure.
1024 *
1025 * This routine issues an initial Fabric Login (FLOGI) for the @vport
1026 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1027 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1028 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1029 * it will just be enabled and made active. The lpfc_issue_els_flogi() routine
1030 * is then invoked with the @vport and the ndlp to perform the FLOGI for the
1031 * @vport.
1032 *
1033 * Return code
1034 * 0 - failed to issue initial flogi for @vport
1035 * 1 - successfully issued initial flogi for @vport
1036 **/
dea31012005-04-17 16:05:31 -05001037int
James Smart2e0fef82007-06-17 19:56:36 -05001038lpfc_initial_flogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001039{
James Smart2e0fef82007-06-17 19:56:36 -05001040 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001041 struct lpfc_nodelist *ndlp;
1042
James Smart98c9ea52007-10-27 13:37:33 -04001043 vport->port_state = LPFC_FLOGI;
1044 lpfc_set_disctmo(vport);
1045
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001046 /* First look for the Fabric ndlp */
James Smart2e0fef82007-06-17 19:56:36 -05001047 ndlp = lpfc_findnode_did(vport, Fabric_DID);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001048 if (!ndlp) {
dea31012005-04-17 16:05:31 -05001049 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001050 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1051 if (!ndlp)
1052 return 0;
James Smart2e0fef82007-06-17 19:56:36 -05001053 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smart6fb120a2009-05-22 14:52:59 -04001054 /* Set the node type */
1055 ndlp->nlp_type |= NLP_FABRIC;
James Smarte47c9092008-02-08 18:49:26 -05001056 /* Put ndlp onto node list */
1057 lpfc_enqueue_node(vport, ndlp);
1058 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1059 /* re-setup ndlp without removing from node list */
1060 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1061 if (!ndlp)
1062 return 0;
dea31012005-04-17 16:05:31 -05001063 }
James Smart87af33f2007-10-27 13:37:43 -04001064
James Smarte47c9092008-02-08 18:49:26 -05001065 if (lpfc_issue_els_flogi(vport, ndlp, 0))
James Smartfa4066b2008-01-11 01:53:27 -05001066 /* This decrement of reference count to node shall kick off
1067 * the release of the node.
1068 */
James Smart329f9bc2007-04-25 09:53:01 -04001069 lpfc_nlp_put(ndlp);
James Smarte47c9092008-02-08 18:49:26 -05001070
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001071 return 1;
dea31012005-04-17 16:05:31 -05001072}
1073
James Smarte59058c2008-08-24 21:49:00 -04001074/**
James Smart3621a712009-04-06 18:47:14 -04001075 * lpfc_initial_fdisc - Issue an initial fabric discovery for a vport
James Smarte59058c2008-08-24 21:49:00 -04001076 * @vport: pointer to a host virtual N_Port data structure.
1077 *
1078 * This routine issues an initial Fabric Discover (FDISC) for the @vport
1079 * specified. It first searches the ndlp with the Fabric_DID (0xfffffe) from
1080 * the @vport's ndlp list. If no such ndlp found, it will create an ndlp and
1081 * put it into the @vport's ndlp list. If an inactive ndlp found on the list,
1082 * it will just be enabled and made active. The lpfc_issue_els_fdisc() routine
1083 * is then invoked with the @vport and the ndlp to perform the FDISC for the
1084 * @vport.
1085 *
1086 * Return code
1087 * 0 - failed to issue initial fdisc for @vport
1088 * 1 - successfully issued initial fdisc for @vport
1089 **/
James Smart92d7f7b2007-06-17 19:56:38 -05001090int
1091lpfc_initial_fdisc(struct lpfc_vport *vport)
1092{
1093 struct lpfc_hba *phba = vport->phba;
1094 struct lpfc_nodelist *ndlp;
1095
1096 /* First look for the Fabric ndlp */
1097 ndlp = lpfc_findnode_did(vport, Fabric_DID);
1098 if (!ndlp) {
1099 /* Cannot find existing Fabric ndlp, so allocate a new one */
1100 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1101 if (!ndlp)
1102 return 0;
1103 lpfc_nlp_init(vport, ndlp, Fabric_DID);
James Smarte47c9092008-02-08 18:49:26 -05001104 /* Put ndlp onto node list */
1105 lpfc_enqueue_node(vport, ndlp);
1106 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
1107 /* re-setup ndlp without removing from node list */
1108 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
1109 if (!ndlp)
1110 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001111 }
James Smarte47c9092008-02-08 18:49:26 -05001112
James Smart92d7f7b2007-06-17 19:56:38 -05001113 if (lpfc_issue_els_fdisc(vport, ndlp, 0)) {
James Smartfa4066b2008-01-11 01:53:27 -05001114 /* decrement node reference count to trigger the release of
1115 * the node.
1116 */
James Smart92d7f7b2007-06-17 19:56:38 -05001117 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05001118 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05001119 }
1120 return 1;
1121}
James Smart87af33f2007-10-27 13:37:43 -04001122
James Smarte59058c2008-08-24 21:49:00 -04001123/**
James Smart3621a712009-04-06 18:47:14 -04001124 * lpfc_more_plogi - Check and issue remaining plogis for a vport
James Smarte59058c2008-08-24 21:49:00 -04001125 * @vport: pointer to a host virtual N_Port data structure.
1126 *
1127 * This routine checks whether there are more remaining Port Logins
1128 * (PLOGI) to be issued for the @vport. If so, it will invoke the routine
1129 * lpfc_els_disc_plogi() to go through the Node Port Recovery (NPR) nodes
1130 * to issue ELS PLOGIs up to the configured discover threads with the
1131 * @vport (@vport->cfg_discovery_threads). The function also decrement
1132 * the @vport's num_disc_node by 1 if it is not already 0.
1133 **/
James Smart87af33f2007-10-27 13:37:43 -04001134void
James Smart2e0fef82007-06-17 19:56:36 -05001135lpfc_more_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001136{
1137 int sentplogi;
1138
James Smart2e0fef82007-06-17 19:56:36 -05001139 if (vport->num_disc_nodes)
1140 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001141
1142 /* Continue discovery with <num_disc_nodes> PLOGIs to go */
James Smarte8b62012007-08-02 11:10:09 -04001143 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1144 "0232 Continue discovery with %d PLOGIs to go "
1145 "Data: x%x x%x x%x\n",
1146 vport->num_disc_nodes, vport->fc_plogi_cnt,
1147 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001148 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001149 if (vport->fc_flag & FC_NLP_MORE)
1150 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
1151 sentplogi = lpfc_els_disc_plogi(vport);
1152
dea31012005-04-17 16:05:31 -05001153 return;
1154}
1155
James Smarte59058c2008-08-24 21:49:00 -04001156/**
James Smart3621a712009-04-06 18:47:14 -04001157 * lpfc_plogi_confirm_nport - Confirm pologi wwpn matches stored ndlp
James Smarte59058c2008-08-24 21:49:00 -04001158 * @phba: pointer to lpfc hba data structure.
1159 * @prsp: pointer to response IOCB payload.
1160 * @ndlp: pointer to a node-list data structure.
1161 *
1162 * This routine checks and indicates whether the WWPN of an N_Port, retrieved
1163 * from a PLOGI, matches the WWPN that is stored in the @ndlp for that N_POrt.
1164 * The following cases are considered N_Port confirmed:
1165 * 1) The N_Port is a Fabric ndlp; 2) The @ndlp is on vport list and matches
1166 * the WWPN of the N_Port logged into; 3) The @ndlp is not on vport list but
1167 * it does not have WWPN assigned either. If the WWPN is confirmed, the
1168 * pointer to the @ndlp will be returned. If the WWPN is not confirmed:
1169 * 1) if there is a node on vport list other than the @ndlp with the same
1170 * WWPN of the N_Port PLOGI logged into, the lpfc_unreg_rpi() will be invoked
1171 * on that node to release the RPI associated with the node; 2) if there is
1172 * no node found on vport list with the same WWPN of the N_Port PLOGI logged
1173 * into, a new node shall be allocated (or activated). In either case, the
1174 * parameters of the @ndlp shall be copied to the new_ndlp, the @ndlp shall
1175 * be released and the new_ndlp shall be put on to the vport node list and
1176 * its pointer returned as the confirmed node.
1177 *
1178 * Note that before the @ndlp got "released", the keepDID from not-matching
1179 * or inactive "new_ndlp" on the vport node list is assigned to the nlp_DID
1180 * of the @ndlp. This is because the release of @ndlp is actually to put it
1181 * into an inactive state on the vport node list and the vport node list
1182 * management algorithm does not allow two node with a same DID.
1183 *
1184 * Return code
1185 * pointer to the PLOGI N_Port @ndlp
1186 **/
James Smart488d1462006-03-07 15:02:37 -05001187static struct lpfc_nodelist *
James Smart92d7f7b2007-06-17 19:56:38 -05001188lpfc_plogi_confirm_nport(struct lpfc_hba *phba, uint32_t *prsp,
James Smart488d1462006-03-07 15:02:37 -05001189 struct lpfc_nodelist *ndlp)
1190{
James Smart2e0fef82007-06-17 19:56:36 -05001191 struct lpfc_vport *vport = ndlp->vport;
James Smart488d1462006-03-07 15:02:37 -05001192 struct lpfc_nodelist *new_ndlp;
James Smart0ff10d42008-01-11 01:52:36 -05001193 struct lpfc_rport_data *rdata;
1194 struct fc_rport *rport;
James Smart488d1462006-03-07 15:02:37 -05001195 struct serv_parm *sp;
James Smart92d7f7b2007-06-17 19:56:38 -05001196 uint8_t name[sizeof(struct lpfc_name)];
James Smart58da1ff2008-04-07 10:15:56 -04001197 uint32_t rc, keepDID = 0;
James Smart488d1462006-03-07 15:02:37 -05001198
James Smart2fb9bd82006-12-02 13:33:57 -05001199 /* Fabric nodes can have the same WWPN so we don't bother searching
1200 * by WWPN. Just return the ndlp that was given to us.
1201 */
1202 if (ndlp->nlp_type & NLP_FABRIC)
1203 return ndlp;
1204
James Smart92d7f7b2007-06-17 19:56:38 -05001205 sp = (struct serv_parm *) ((uint8_t *) prsp + sizeof(uint32_t));
James Smart685f0bf2007-04-25 09:53:08 -04001206 memset(name, 0, sizeof(struct lpfc_name));
James Smart488d1462006-03-07 15:02:37 -05001207
James Smart685f0bf2007-04-25 09:53:08 -04001208 /* Now we find out if the NPort we are logging into, matches the WWPN
James Smart488d1462006-03-07 15:02:37 -05001209 * we have for that ndlp. If not, we have some work to do.
1210 */
James Smart2e0fef82007-06-17 19:56:36 -05001211 new_ndlp = lpfc_findnode_wwpn(vport, &sp->portName);
James Smart488d1462006-03-07 15:02:37 -05001212
James Smarte47c9092008-02-08 18:49:26 -05001213 if (new_ndlp == ndlp && NLP_CHK_NODE_ACT(new_ndlp))
James Smart488d1462006-03-07 15:02:37 -05001214 return ndlp;
James Smart488d1462006-03-07 15:02:37 -05001215
1216 if (!new_ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05001217 rc = memcmp(&ndlp->nlp_portname, name,
1218 sizeof(struct lpfc_name));
James Smart92795652006-07-06 15:50:02 -04001219 if (!rc)
1220 return ndlp;
James Smart488d1462006-03-07 15:02:37 -05001221 new_ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
1222 if (!new_ndlp)
1223 return ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001224 lpfc_nlp_init(vport, new_ndlp, ndlp->nlp_DID);
James Smarte47c9092008-02-08 18:49:26 -05001225 } else if (!NLP_CHK_NODE_ACT(new_ndlp)) {
James Smart58da1ff2008-04-07 10:15:56 -04001226 rc = memcmp(&ndlp->nlp_portname, name,
1227 sizeof(struct lpfc_name));
1228 if (!rc)
1229 return ndlp;
James Smarte47c9092008-02-08 18:49:26 -05001230 new_ndlp = lpfc_enable_node(vport, new_ndlp,
1231 NLP_STE_UNUSED_NODE);
1232 if (!new_ndlp)
1233 return ndlp;
James Smart58da1ff2008-04-07 10:15:56 -04001234 keepDID = new_ndlp->nlp_DID;
1235 } else
1236 keepDID = new_ndlp->nlp_DID;
James Smart488d1462006-03-07 15:02:37 -05001237
James Smart2e0fef82007-06-17 19:56:36 -05001238 lpfc_unreg_rpi(vport, new_ndlp);
James Smart488d1462006-03-07 15:02:37 -05001239 new_ndlp->nlp_DID = ndlp->nlp_DID;
James Smart92795652006-07-06 15:50:02 -04001240 new_ndlp->nlp_prev_state = ndlp->nlp_prev_state;
James Smart0ff10d42008-01-11 01:52:36 -05001241
1242 if (ndlp->nlp_flag & NLP_NPR_2B_DISC)
1243 new_ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1244 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1245
James Smarte47c9092008-02-08 18:49:26 -05001246 /* Set state will put new_ndlp on to node list if not already done */
James Smart2e0fef82007-06-17 19:56:36 -05001247 lpfc_nlp_set_state(vport, new_ndlp, ndlp->nlp_state);
James Smart488d1462006-03-07 15:02:37 -05001248
James Smart2e0fef82007-06-17 19:56:36 -05001249 /* Move this back to NPR state */
James Smart87af33f2007-10-27 13:37:43 -04001250 if (memcmp(&ndlp->nlp_portname, name, sizeof(struct lpfc_name)) == 0) {
1251 /* The new_ndlp is replacing ndlp totally, so we need
1252 * to put ndlp on UNUSED list and try to free it.
1253 */
James Smart0ff10d42008-01-11 01:52:36 -05001254
1255 /* Fix up the rport accordingly */
1256 rport = ndlp->rport;
1257 if (rport) {
1258 rdata = rport->dd_data;
1259 if (rdata->pnode == ndlp) {
1260 lpfc_nlp_put(ndlp);
1261 ndlp->rport = NULL;
1262 rdata->pnode = lpfc_nlp_get(new_ndlp);
1263 new_ndlp->rport = rport;
1264 }
1265 new_ndlp->nlp_type = ndlp->nlp_type;
1266 }
James Smart58da1ff2008-04-07 10:15:56 -04001267 /* We shall actually free the ndlp with both nlp_DID and
1268 * nlp_portname fields equals 0 to avoid any ndlp on the
1269 * nodelist never to be used.
1270 */
1271 if (ndlp->nlp_DID == 0) {
1272 spin_lock_irq(&phba->ndlp_lock);
1273 NLP_SET_FREE_REQ(ndlp);
1274 spin_unlock_irq(&phba->ndlp_lock);
1275 }
James Smart0ff10d42008-01-11 01:52:36 -05001276
James Smart58da1ff2008-04-07 10:15:56 -04001277 /* Two ndlps cannot have the same did on the nodelist */
1278 ndlp->nlp_DID = keepDID;
James Smart2e0fef82007-06-17 19:56:36 -05001279 lpfc_drop_node(vport, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04001280 }
James Smart92795652006-07-06 15:50:02 -04001281 else {
James Smart2e0fef82007-06-17 19:56:36 -05001282 lpfc_unreg_rpi(vport, ndlp);
James Smart58da1ff2008-04-07 10:15:56 -04001283 /* Two ndlps cannot have the same did */
1284 ndlp->nlp_DID = keepDID;
James Smart2e0fef82007-06-17 19:56:36 -05001285 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
James Smart92795652006-07-06 15:50:02 -04001286 }
James Smart488d1462006-03-07 15:02:37 -05001287 return new_ndlp;
1288}
1289
James Smarte59058c2008-08-24 21:49:00 -04001290/**
James Smart3621a712009-04-06 18:47:14 -04001291 * lpfc_end_rscn - Check and handle more rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04001292 * @vport: pointer to a host virtual N_Port data structure.
1293 *
1294 * This routine checks whether more Registration State Change
1295 * Notifications (RSCNs) came in while the discovery state machine was in
1296 * the FC_RSCN_MODE. If so, the lpfc_els_handle_rscn() routine will be
1297 * invoked to handle the additional RSCNs for the @vport. Otherwise, the
1298 * FC_RSCN_MODE bit will be cleared with the @vport to mark as the end of
1299 * handling the RSCNs.
1300 **/
James Smart87af33f2007-10-27 13:37:43 -04001301void
1302lpfc_end_rscn(struct lpfc_vport *vport)
1303{
1304 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1305
1306 if (vport->fc_flag & FC_RSCN_MODE) {
1307 /*
1308 * Check to see if more RSCNs came in while we were
1309 * processing this one.
1310 */
1311 if (vport->fc_rscn_id_cnt ||
1312 (vport->fc_flag & FC_RSCN_DISCOVERY) != 0)
1313 lpfc_els_handle_rscn(vport);
1314 else {
1315 spin_lock_irq(shost->host_lock);
1316 vport->fc_flag &= ~FC_RSCN_MODE;
1317 spin_unlock_irq(shost->host_lock);
1318 }
1319 }
1320}
1321
James Smarte59058c2008-08-24 21:49:00 -04001322/**
James Smart3621a712009-04-06 18:47:14 -04001323 * lpfc_cmpl_els_plogi - Completion callback function for plogi
James Smarte59058c2008-08-24 21:49:00 -04001324 * @phba: pointer to lpfc hba data structure.
1325 * @cmdiocb: pointer to lpfc command iocb data structure.
1326 * @rspiocb: pointer to lpfc response iocb data structure.
1327 *
1328 * This routine is the completion callback function for issuing the Port
1329 * Login (PLOGI) command. For PLOGI completion, there must be an active
1330 * ndlp on the vport node list that matches the remote node ID from the
1331 * PLOGI reponse IOCB. If such ndlp does not exist, the PLOGI is simply
1332 * ignored and command IOCB released. The PLOGI response IOCB status is
1333 * checked for error conditons. If there is error status reported, PLOGI
1334 * retry shall be attempted by invoking the lpfc_els_retry() routine.
1335 * Otherwise, the lpfc_plogi_confirm_nport() routine shall be invoked on
1336 * the ndlp and the NLP_EVT_CMPL_PLOGI state to the Discover State Machine
1337 * (DSM) is set for this PLOGI completion. Finally, it checks whether
1338 * there are additional N_Port nodes with the vport that need to perform
1339 * PLOGI. If so, the lpfc_more_plogi() routine is invoked to issue addition
1340 * PLOGIs.
1341 **/
dea31012005-04-17 16:05:31 -05001342static void
James Smart2e0fef82007-06-17 19:56:36 -05001343lpfc_cmpl_els_plogi(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1344 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001345{
James Smart2e0fef82007-06-17 19:56:36 -05001346 struct lpfc_vport *vport = cmdiocb->vport;
1347 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001348 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001349 struct lpfc_nodelist *ndlp;
James Smart92795652006-07-06 15:50:02 -04001350 struct lpfc_dmabuf *prsp;
dea31012005-04-17 16:05:31 -05001351 int disc, rc, did, type;
1352
dea31012005-04-17 16:05:31 -05001353 /* we pass cmdiocb to state machine which needs rspiocb as well */
1354 cmdiocb->context_un.rsp_iocb = rspiocb;
1355
1356 irsp = &rspiocb->iocb;
James Smart858c9f62007-06-17 19:56:39 -05001357 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1358 "PLOGI cmpl: status:x%x/x%x did:x%x",
1359 irsp->ulpStatus, irsp->un.ulpWord[4],
1360 irsp->un.elsreq64.remoteID);
1361
James Smart2e0fef82007-06-17 19:56:36 -05001362 ndlp = lpfc_findnode_did(vport, irsp->un.elsreq64.remoteID);
James Smarte47c9092008-02-08 18:49:26 -05001363 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smarte8b62012007-08-02 11:10:09 -04001364 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1365 "0136 PLOGI completes to NPort x%x "
1366 "with no ndlp. Data: x%x x%x x%x\n",
1367 irsp->un.elsreq64.remoteID,
1368 irsp->ulpStatus, irsp->un.ulpWord[4],
1369 irsp->ulpIoTag);
James Smart488d1462006-03-07 15:02:37 -05001370 goto out;
James Smarted957682007-06-17 19:56:37 -05001371 }
dea31012005-04-17 16:05:31 -05001372
1373 /* Since ndlp can be freed in the disc state machine, note if this node
1374 * is being used during discovery.
1375 */
James Smart2e0fef82007-06-17 19:56:36 -05001376 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001377 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
James Smart488d1462006-03-07 15:02:37 -05001378 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001379 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001380 rc = 0;
1381
1382 /* PLOGI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001383 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1384 "0102 PLOGI completes to NPort x%x "
1385 "Data: x%x x%x x%x x%x x%x\n",
1386 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1387 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001388 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001389 if (lpfc_els_chk_latt(vport)) {
1390 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001391 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001392 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001393 goto out;
1394 }
1395
1396 /* ndlp could be freed in DSM, save these values now */
1397 type = ndlp->nlp_type;
1398 did = ndlp->nlp_DID;
1399
1400 if (irsp->ulpStatus) {
1401 /* Check for retry */
1402 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1403 /* ELS command is being retried */
1404 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05001405 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001406 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001407 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001408 }
1409 goto out;
1410 }
dea31012005-04-17 16:05:31 -05001411 /* PLOGI failed */
1412 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001413 if (lpfc_error_lost_link(irsp))
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001414 rc = NLP_STE_FREED_NODE;
James Smarte47c9092008-02-08 18:49:26 -05001415 else
James Smart2e0fef82007-06-17 19:56:36 -05001416 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001417 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001418 } else {
1419 /* Good status, call state machine */
James Smart92795652006-07-06 15:50:02 -04001420 prsp = list_entry(((struct lpfc_dmabuf *)
James Smart92d7f7b2007-06-17 19:56:38 -05001421 cmdiocb->context2)->list.next,
1422 struct lpfc_dmabuf, list);
1423 ndlp = lpfc_plogi_confirm_nport(phba, prsp->virt, ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05001424 rc = lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001425 NLP_EVT_CMPL_PLOGI);
dea31012005-04-17 16:05:31 -05001426 }
1427
James Smart2e0fef82007-06-17 19:56:36 -05001428 if (disc && vport->num_disc_nodes) {
dea31012005-04-17 16:05:31 -05001429 /* Check to see if there are more PLOGIs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001430 lpfc_more_plogi(vport);
dea31012005-04-17 16:05:31 -05001431
James Smart2e0fef82007-06-17 19:56:36 -05001432 if (vport->num_disc_nodes == 0) {
1433 spin_lock_irq(shost->host_lock);
1434 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1435 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001436
James Smart2e0fef82007-06-17 19:56:36 -05001437 lpfc_can_disctmo(vport);
James Smart87af33f2007-10-27 13:37:43 -04001438 lpfc_end_rscn(vport);
dea31012005-04-17 16:05:31 -05001439 }
1440 }
1441
1442out:
1443 lpfc_els_free_iocb(phba, cmdiocb);
1444 return;
1445}
1446
James Smarte59058c2008-08-24 21:49:00 -04001447/**
James Smart3621a712009-04-06 18:47:14 -04001448 * lpfc_issue_els_plogi - Issue an plogi iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001449 * @vport: pointer to a host virtual N_Port data structure.
1450 * @did: destination port identifier.
1451 * @retry: number of retries to the command IOCB.
1452 *
1453 * This routine issues a Port Login (PLOGI) command to a remote N_Port
1454 * (with the @did) for a @vport. Before issuing a PLOGI to a remote N_Port,
1455 * the ndlp with the remote N_Port DID must exist on the @vport's ndlp list.
1456 * This routine constructs the proper feilds of the PLOGI IOCB and invokes
1457 * the lpfc_sli_issue_iocb() routine to send out PLOGI ELS command.
1458 *
1459 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1460 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1461 * will be stored into the context1 field of the IOCB for the completion
1462 * callback function to the PLOGI ELS command.
1463 *
1464 * Return code
1465 * 0 - Successfully issued a plogi for @vport
1466 * 1 - failed to issue a plogi for @vport
1467 **/
dea31012005-04-17 16:05:31 -05001468int
James Smart2e0fef82007-06-17 19:56:36 -05001469lpfc_issue_els_plogi(struct lpfc_vport *vport, uint32_t did, uint8_t retry)
dea31012005-04-17 16:05:31 -05001470{
James Smart2e0fef82007-06-17 19:56:36 -05001471 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001472 struct serv_parm *sp;
1473 IOCB_t *icmd;
James Smart98c9ea52007-10-27 13:37:33 -04001474 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05001475 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001476 struct lpfc_sli *psli;
1477 uint8_t *pcmd;
1478 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05001479 int ret;
dea31012005-04-17 16:05:31 -05001480
1481 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05001482
James Smart98c9ea52007-10-27 13:37:33 -04001483 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05001484 if (ndlp && !NLP_CHK_NODE_ACT(ndlp))
1485 ndlp = NULL;
James Smart98c9ea52007-10-27 13:37:33 -04001486
James Smarte47c9092008-02-08 18:49:26 -05001487 /* If ndlp is not NULL, we will bump the reference count on it */
James Smart92d7f7b2007-06-17 19:56:38 -05001488 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
James Smart98c9ea52007-10-27 13:37:33 -04001489 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
James Smart2e0fef82007-06-17 19:56:36 -05001490 ELS_CMD_PLOGI);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001491 if (!elsiocb)
1492 return 1;
dea31012005-04-17 16:05:31 -05001493
1494 icmd = &elsiocb->iocb;
1495 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1496
1497 /* For PLOGI request, remainder of payload is service parameters */
1498 *((uint32_t *) (pcmd)) = ELS_CMD_PLOGI;
James Smart92d7f7b2007-06-17 19:56:38 -05001499 pcmd += sizeof(uint32_t);
1500 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
dea31012005-04-17 16:05:31 -05001501 sp = (struct serv_parm *) pcmd;
1502
1503 if (sp->cmn.fcphLow < FC_PH_4_3)
1504 sp->cmn.fcphLow = FC_PH_4_3;
1505
1506 if (sp->cmn.fcphHigh < FC_PH3)
1507 sp->cmn.fcphHigh = FC_PH3;
1508
James Smart858c9f62007-06-17 19:56:39 -05001509 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1510 "Issue PLOGI: did:x%x",
1511 did, 0, 0);
1512
dea31012005-04-17 16:05:31 -05001513 phba->fc_stat.elsXmitPLOGI++;
1514 elsiocb->iocb_cmpl = lpfc_cmpl_els_plogi;
James Smart3772a992009-05-22 14:50:54 -04001515 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05001516
1517 if (ret == IOCB_ERROR) {
dea31012005-04-17 16:05:31 -05001518 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001519 return 1;
dea31012005-04-17 16:05:31 -05001520 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001521 return 0;
dea31012005-04-17 16:05:31 -05001522}
1523
James Smarte59058c2008-08-24 21:49:00 -04001524/**
James Smart3621a712009-04-06 18:47:14 -04001525 * lpfc_cmpl_els_prli - Completion callback function for prli
James Smarte59058c2008-08-24 21:49:00 -04001526 * @phba: pointer to lpfc hba data structure.
1527 * @cmdiocb: pointer to lpfc command iocb data structure.
1528 * @rspiocb: pointer to lpfc response iocb data structure.
1529 *
1530 * This routine is the completion callback function for a Process Login
1531 * (PRLI) ELS command. The PRLI response IOCB status is checked for error
1532 * status. If there is error status reported, PRLI retry shall be attempted
1533 * by invoking the lpfc_els_retry() routine. Otherwise, the state
1534 * NLP_EVT_CMPL_PRLI is sent to the Discover State Machine (DSM) for this
1535 * ndlp to mark the PRLI completion.
1536 **/
dea31012005-04-17 16:05:31 -05001537static void
James Smart2e0fef82007-06-17 19:56:36 -05001538lpfc_cmpl_els_prli(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1539 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001540{
James Smart2e0fef82007-06-17 19:56:36 -05001541 struct lpfc_vport *vport = cmdiocb->vport;
1542 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001543 IOCB_t *irsp;
1544 struct lpfc_sli *psli;
1545 struct lpfc_nodelist *ndlp;
1546
1547 psli = &phba->sli;
1548 /* we pass cmdiocb to state machine which needs rspiocb as well */
1549 cmdiocb->context_un.rsp_iocb = rspiocb;
1550
1551 irsp = &(rspiocb->iocb);
1552 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
James Smart2e0fef82007-06-17 19:56:36 -05001553 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001554 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001555 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001556
James Smart858c9f62007-06-17 19:56:39 -05001557 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1558 "PRLI cmpl: status:x%x/x%x did:x%x",
1559 irsp->ulpStatus, irsp->un.ulpWord[4],
1560 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05001561 /* PRLI completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001562 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1563 "0103 PRLI completes to NPort x%x "
1564 "Data: x%x x%x x%x x%x\n",
1565 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1566 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001567
James Smart2e0fef82007-06-17 19:56:36 -05001568 vport->fc_prli_sent--;
dea31012005-04-17 16:05:31 -05001569 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001570 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05001571 goto out;
1572
1573 if (irsp->ulpStatus) {
1574 /* Check for retry */
1575 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1576 /* ELS command is being retried */
1577 goto out;
1578 }
1579 /* PRLI failed */
1580 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001581 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05001582 goto out;
James Smarte47c9092008-02-08 18:49:26 -05001583 else
James Smart2e0fef82007-06-17 19:56:36 -05001584 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001585 NLP_EVT_CMPL_PRLI);
James Smarte47c9092008-02-08 18:49:26 -05001586 } else
dea31012005-04-17 16:05:31 -05001587 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05001588 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05001589 NLP_EVT_CMPL_PRLI);
dea31012005-04-17 16:05:31 -05001590out:
1591 lpfc_els_free_iocb(phba, cmdiocb);
1592 return;
1593}
1594
James Smarte59058c2008-08-24 21:49:00 -04001595/**
James Smart3621a712009-04-06 18:47:14 -04001596 * lpfc_issue_els_prli - Issue a prli iocb command for a vport
James Smarte59058c2008-08-24 21:49:00 -04001597 * @vport: pointer to a host virtual N_Port data structure.
1598 * @ndlp: pointer to a node-list data structure.
1599 * @retry: number of retries to the command IOCB.
1600 *
1601 * This routine issues a Process Login (PRLI) ELS command for the
1602 * @vport. The PRLI service parameters are set up in the payload of the
1603 * PRLI Request command and the pointer to lpfc_cmpl_els_prli() routine
1604 * is put to the IOCB completion callback func field before invoking the
1605 * routine lpfc_sli_issue_iocb() to send out PRLI command.
1606 *
1607 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1608 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1609 * will be stored into the context1 field of the IOCB for the completion
1610 * callback function to the PRLI ELS command.
1611 *
1612 * Return code
1613 * 0 - successfully issued prli iocb command for @vport
1614 * 1 - failed to issue prli iocb command for @vport
1615 **/
dea31012005-04-17 16:05:31 -05001616int
James Smart2e0fef82007-06-17 19:56:36 -05001617lpfc_issue_els_prli(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001618 uint8_t retry)
1619{
James Smart2e0fef82007-06-17 19:56:36 -05001620 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1621 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001622 PRLI *npr;
1623 IOCB_t *icmd;
1624 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001625 uint8_t *pcmd;
1626 uint16_t cmdsize;
1627
James Smart92d7f7b2007-06-17 19:56:38 -05001628 cmdsize = (sizeof(uint32_t) + sizeof(PRLI));
James Smart2e0fef82007-06-17 19:56:36 -05001629 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1630 ndlp->nlp_DID, ELS_CMD_PRLI);
James Smart488d1462006-03-07 15:02:37 -05001631 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001632 return 1;
dea31012005-04-17 16:05:31 -05001633
1634 icmd = &elsiocb->iocb;
1635 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1636
1637 /* For PRLI request, remainder of payload is service parameters */
James Smart92d7f7b2007-06-17 19:56:38 -05001638 memset(pcmd, 0, (sizeof(PRLI) + sizeof(uint32_t)));
dea31012005-04-17 16:05:31 -05001639 *((uint32_t *) (pcmd)) = ELS_CMD_PRLI;
James Smart92d7f7b2007-06-17 19:56:38 -05001640 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001641
1642 /* For PRLI, remainder of payload is PRLI parameter page */
1643 npr = (PRLI *) pcmd;
1644 /*
1645 * If our firmware version is 3.20 or later,
1646 * set the following bits for FC-TAPE support.
1647 */
1648 if (phba->vpd.rev.feaLevelHigh >= 0x02) {
1649 npr->ConfmComplAllowed = 1;
1650 npr->Retry = 1;
1651 npr->TaskRetryIdReq = 1;
1652 }
1653 npr->estabImagePair = 1;
1654 npr->readXferRdyDis = 1;
1655
1656 /* For FCP support */
1657 npr->prliType = PRLI_FCP_TYPE;
1658 npr->initiatorFunc = 1;
1659
James Smart858c9f62007-06-17 19:56:39 -05001660 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1661 "Issue PRLI: did:x%x",
1662 ndlp->nlp_DID, 0, 0);
1663
dea31012005-04-17 16:05:31 -05001664 phba->fc_stat.elsXmitPRLI++;
1665 elsiocb->iocb_cmpl = lpfc_cmpl_els_prli;
James Smart2e0fef82007-06-17 19:56:36 -05001666 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001667 ndlp->nlp_flag |= NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001668 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04001669 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
1670 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05001671 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001672 ndlp->nlp_flag &= ~NLP_PRLI_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001673 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001674 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001675 return 1;
dea31012005-04-17 16:05:31 -05001676 }
James Smart2e0fef82007-06-17 19:56:36 -05001677 vport->fc_prli_sent++;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001678 return 0;
dea31012005-04-17 16:05:31 -05001679}
1680
James Smarte59058c2008-08-24 21:49:00 -04001681/**
James Smart3621a712009-04-06 18:47:14 -04001682 * lpfc_rscn_disc - Perform rscn discovery for a vport
James Smart90160e02008-08-24 21:49:45 -04001683 * @vport: pointer to a host virtual N_Port data structure.
1684 *
1685 * This routine performs Registration State Change Notification (RSCN)
1686 * discovery for a @vport. If the @vport's node port recovery count is not
1687 * zero, it will invoke the lpfc_els_disc_plogi() to perform PLOGI for all
1688 * the nodes that need recovery. If none of the PLOGI were needed through
1689 * the lpfc_els_disc_plogi() routine, the lpfc_end_rscn() routine shall be
1690 * invoked to check and handle possible more RSCN came in during the period
1691 * of processing the current ones.
1692 **/
1693static void
1694lpfc_rscn_disc(struct lpfc_vport *vport)
1695{
1696 lpfc_can_disctmo(vport);
1697
1698 /* RSCN discovery */
1699 /* go thru NPR nodes and issue ELS PLOGIs */
1700 if (vport->fc_npr_cnt)
1701 if (lpfc_els_disc_plogi(vport))
1702 return;
1703
1704 lpfc_end_rscn(vport);
1705}
1706
1707/**
James Smart3621a712009-04-06 18:47:14 -04001708 * lpfc_adisc_done - Complete the adisc phase of discovery
James Smart90160e02008-08-24 21:49:45 -04001709 * @vport: pointer to lpfc_vport hba data structure that finished all ADISCs.
1710 *
1711 * This function is called when the final ADISC is completed during discovery.
1712 * This function handles clearing link attention or issuing reg_vpi depending
1713 * on whether npiv is enabled. This function also kicks off the PLOGI phase of
1714 * discovery.
1715 * This function is called with no locks held.
1716 **/
1717static void
1718lpfc_adisc_done(struct lpfc_vport *vport)
1719{
1720 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1721 struct lpfc_hba *phba = vport->phba;
1722
1723 /*
1724 * For NPIV, cmpl_reg_vpi will set port_state to READY,
1725 * and continue discovery.
1726 */
1727 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart6fb120a2009-05-22 14:52:59 -04001728 !(vport->fc_flag & FC_RSCN_MODE) &&
1729 (phba->sli_rev < LPFC_SLI_REV4)) {
James Smart90160e02008-08-24 21:49:45 -04001730 lpfc_issue_reg_vpi(phba, vport);
1731 return;
1732 }
1733 /*
1734 * For SLI2, we need to set port_state to READY
1735 * and continue discovery.
1736 */
1737 if (vport->port_state < LPFC_VPORT_READY) {
1738 /* If we get here, there is nothing to ADISC */
1739 if (vport->port_type == LPFC_PHYSICAL_PORT)
1740 lpfc_issue_clear_la(phba, vport);
1741 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
1742 vport->num_disc_nodes = 0;
1743 /* go thru NPR list, issue ELS PLOGIs */
1744 if (vport->fc_npr_cnt)
1745 lpfc_els_disc_plogi(vport);
1746 if (!vport->num_disc_nodes) {
1747 spin_lock_irq(shost->host_lock);
1748 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1749 spin_unlock_irq(shost->host_lock);
1750 lpfc_can_disctmo(vport);
1751 lpfc_end_rscn(vport);
1752 }
1753 }
1754 vport->port_state = LPFC_VPORT_READY;
1755 } else
1756 lpfc_rscn_disc(vport);
1757}
1758
1759/**
James Smart3621a712009-04-06 18:47:14 -04001760 * lpfc_more_adisc - Issue more adisc as needed
James Smarte59058c2008-08-24 21:49:00 -04001761 * @vport: pointer to a host virtual N_Port data structure.
1762 *
1763 * This routine determines whether there are more ndlps on a @vport
1764 * node list need to have Address Discover (ADISC) issued. If so, it will
1765 * invoke the lpfc_els_disc_adisc() routine to issue ADISC on the @vport's
1766 * remaining nodes which need to have ADISC sent.
1767 **/
James Smart0ff10d42008-01-11 01:52:36 -05001768void
James Smart2e0fef82007-06-17 19:56:36 -05001769lpfc_more_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001770{
1771 int sentadisc;
1772
James Smart2e0fef82007-06-17 19:56:36 -05001773 if (vport->num_disc_nodes)
1774 vport->num_disc_nodes--;
dea31012005-04-17 16:05:31 -05001775 /* Continue discovery with <num_disc_nodes> ADISCs to go */
James Smarte8b62012007-08-02 11:10:09 -04001776 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1777 "0210 Continue discovery with %d ADISCs to go "
1778 "Data: x%x x%x x%x\n",
1779 vport->num_disc_nodes, vport->fc_adisc_cnt,
1780 vport->fc_flag, vport->port_state);
dea31012005-04-17 16:05:31 -05001781 /* Check to see if there are more ADISCs to be sent */
James Smart2e0fef82007-06-17 19:56:36 -05001782 if (vport->fc_flag & FC_NLP_MORE) {
1783 lpfc_set_disctmo(vport);
1784 /* go thru NPR nodes and issue any remaining ELS ADISCs */
1785 sentadisc = lpfc_els_disc_adisc(vport);
dea31012005-04-17 16:05:31 -05001786 }
James Smart90160e02008-08-24 21:49:45 -04001787 if (!vport->num_disc_nodes)
1788 lpfc_adisc_done(vport);
dea31012005-04-17 16:05:31 -05001789 return;
1790}
1791
James Smarte59058c2008-08-24 21:49:00 -04001792/**
James Smart3621a712009-04-06 18:47:14 -04001793 * lpfc_cmpl_els_adisc - Completion callback function for adisc
James Smarte59058c2008-08-24 21:49:00 -04001794 * @phba: pointer to lpfc hba data structure.
1795 * @cmdiocb: pointer to lpfc command iocb data structure.
1796 * @rspiocb: pointer to lpfc response iocb data structure.
1797 *
1798 * This routine is the completion function for issuing the Address Discover
1799 * (ADISC) command. It first checks to see whether link went down during
1800 * the discovery process. If so, the node will be marked as node port
1801 * recovery for issuing discover IOCB by the link attention handler and
1802 * exit. Otherwise, the response status is checked. If error was reported
1803 * in the response status, the ADISC command shall be retried by invoking
1804 * the lpfc_els_retry() routine. Otherwise, if no error was reported in
1805 * the response status, the state machine is invoked to set transition
1806 * with respect to NLP_EVT_CMPL_ADISC event.
1807 **/
dea31012005-04-17 16:05:31 -05001808static void
James Smart2e0fef82007-06-17 19:56:36 -05001809lpfc_cmpl_els_adisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1810 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001811{
James Smart2e0fef82007-06-17 19:56:36 -05001812 struct lpfc_vport *vport = cmdiocb->vport;
1813 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001814 IOCB_t *irsp;
dea31012005-04-17 16:05:31 -05001815 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05001816 int disc;
dea31012005-04-17 16:05:31 -05001817
1818 /* we pass cmdiocb to state machine which needs rspiocb as well */
1819 cmdiocb->context_un.rsp_iocb = rspiocb;
1820
1821 irsp = &(rspiocb->iocb);
1822 ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
dea31012005-04-17 16:05:31 -05001823
James Smart858c9f62007-06-17 19:56:39 -05001824 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1825 "ADISC cmpl: status:x%x/x%x did:x%x",
1826 irsp->ulpStatus, irsp->un.ulpWord[4],
1827 ndlp->nlp_DID);
1828
dea31012005-04-17 16:05:31 -05001829 /* Since ndlp can be freed in the disc state machine, note if this node
1830 * is being used during discovery.
1831 */
James Smart2e0fef82007-06-17 19:56:36 -05001832 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001833 disc = (ndlp->nlp_flag & NLP_NPR_2B_DISC);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001834 ndlp->nlp_flag &= ~(NLP_ADISC_SND | NLP_NPR_2B_DISC);
James Smart2e0fef82007-06-17 19:56:36 -05001835 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001836 /* ADISC completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001837 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1838 "0104 ADISC completes to NPort x%x "
1839 "Data: x%x x%x x%x x%x x%x\n",
1840 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1841 irsp->ulpTimeout, disc, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001842 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001843 if (lpfc_els_chk_latt(vport)) {
1844 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001845 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001846 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001847 goto out;
1848 }
1849
1850 if (irsp->ulpStatus) {
1851 /* Check for retry */
1852 if (lpfc_els_retry(phba, cmdiocb, rspiocb)) {
1853 /* ELS command is being retried */
1854 if (disc) {
James Smart2e0fef82007-06-17 19:56:36 -05001855 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001856 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001857 spin_unlock_irq(shost->host_lock);
1858 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05001859 }
1860 goto out;
1861 }
1862 /* ADISC failed */
1863 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smarte47c9092008-02-08 18:49:26 -05001864 if (!lpfc_error_lost_link(irsp))
James Smart2e0fef82007-06-17 19:56:36 -05001865 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart858c9f62007-06-17 19:56:39 -05001866 NLP_EVT_CMPL_ADISC);
James Smarte47c9092008-02-08 18:49:26 -05001867 } else
dea31012005-04-17 16:05:31 -05001868 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05001869 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
dea31012005-04-17 16:05:31 -05001870 NLP_EVT_CMPL_ADISC);
dea31012005-04-17 16:05:31 -05001871
James Smart90160e02008-08-24 21:49:45 -04001872 /* Check to see if there are more ADISCs to be sent */
1873 if (disc && vport->num_disc_nodes)
James Smart2e0fef82007-06-17 19:56:36 -05001874 lpfc_more_adisc(vport);
dea31012005-04-17 16:05:31 -05001875out:
1876 lpfc_els_free_iocb(phba, cmdiocb);
1877 return;
1878}
1879
James Smarte59058c2008-08-24 21:49:00 -04001880/**
James Smart3621a712009-04-06 18:47:14 -04001881 * lpfc_issue_els_adisc - Issue an address discover iocb to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04001882 * @vport: pointer to a virtual N_Port data structure.
1883 * @ndlp: pointer to a node-list data structure.
1884 * @retry: number of retries to the command IOCB.
1885 *
1886 * This routine issues an Address Discover (ADISC) for an @ndlp on a
1887 * @vport. It prepares the payload of the ADISC ELS command, updates the
1888 * and states of the ndlp, and invokes the lpfc_sli_issue_iocb() routine
1889 * to issue the ADISC ELS command.
1890 *
1891 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
1892 * will be incremented by 1 for holding the ndlp and the reference to ndlp
1893 * will be stored into the context1 field of the IOCB for the completion
1894 * callback function to the ADISC ELS command.
1895 *
1896 * Return code
1897 * 0 - successfully issued adisc
1898 * 1 - failed to issue adisc
1899 **/
dea31012005-04-17 16:05:31 -05001900int
James Smart2e0fef82007-06-17 19:56:36 -05001901lpfc_issue_els_adisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05001902 uint8_t retry)
1903{
James Smart2e0fef82007-06-17 19:56:36 -05001904 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1905 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001906 ADISC *ap;
1907 IOCB_t *icmd;
1908 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05001909 uint8_t *pcmd;
1910 uint16_t cmdsize;
1911
James Smart92d7f7b2007-06-17 19:56:38 -05001912 cmdsize = (sizeof(uint32_t) + sizeof(ADISC));
James Smart2e0fef82007-06-17 19:56:36 -05001913 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
1914 ndlp->nlp_DID, ELS_CMD_ADISC);
James Smart488d1462006-03-07 15:02:37 -05001915 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001916 return 1;
dea31012005-04-17 16:05:31 -05001917
1918 icmd = &elsiocb->iocb;
1919 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
1920
1921 /* For ADISC request, remainder of payload is service parameters */
1922 *((uint32_t *) (pcmd)) = ELS_CMD_ADISC;
James Smart92d7f7b2007-06-17 19:56:38 -05001923 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05001924
1925 /* Fill in ADISC payload */
1926 ap = (ADISC *) pcmd;
1927 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05001928 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
1929 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05001930 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05001931
James Smart858c9f62007-06-17 19:56:39 -05001932 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1933 "Issue ADISC: did:x%x",
1934 ndlp->nlp_DID, 0, 0);
1935
dea31012005-04-17 16:05:31 -05001936 phba->fc_stat.elsXmitADISC++;
1937 elsiocb->iocb_cmpl = lpfc_cmpl_els_adisc;
James Smart2e0fef82007-06-17 19:56:36 -05001938 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001939 ndlp->nlp_flag |= NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001940 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04001941 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
1942 IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05001943 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001944 ndlp->nlp_flag &= ~NLP_ADISC_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001945 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001946 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001947 return 1;
dea31012005-04-17 16:05:31 -05001948 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001949 return 0;
dea31012005-04-17 16:05:31 -05001950}
1951
James Smarte59058c2008-08-24 21:49:00 -04001952/**
James Smart3621a712009-04-06 18:47:14 -04001953 * lpfc_cmpl_els_logo - Completion callback function for logo
James Smarte59058c2008-08-24 21:49:00 -04001954 * @phba: pointer to lpfc hba data structure.
1955 * @cmdiocb: pointer to lpfc command iocb data structure.
1956 * @rspiocb: pointer to lpfc response iocb data structure.
1957 *
1958 * This routine is the completion function for issuing the ELS Logout (LOGO)
1959 * command. If no error status was reported from the LOGO response, the
1960 * state machine of the associated ndlp shall be invoked for transition with
1961 * respect to NLP_EVT_CMPL_LOGO event. Otherwise, if error status was reported,
1962 * the lpfc_els_retry() routine will be invoked to retry the LOGO command.
1963 **/
dea31012005-04-17 16:05:31 -05001964static void
James Smart2e0fef82007-06-17 19:56:36 -05001965lpfc_cmpl_els_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
1966 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05001967{
James Smart2e0fef82007-06-17 19:56:36 -05001968 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
1969 struct lpfc_vport *vport = ndlp->vport;
1970 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001971 IOCB_t *irsp;
1972 struct lpfc_sli *psli;
dea31012005-04-17 16:05:31 -05001973
1974 psli = &phba->sli;
1975 /* we pass cmdiocb to state machine which needs rspiocb as well */
1976 cmdiocb->context_un.rsp_iocb = rspiocb;
1977
1978 irsp = &(rspiocb->iocb);
James Smart2e0fef82007-06-17 19:56:36 -05001979 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001980 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05001981 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001982
James Smart858c9f62007-06-17 19:56:39 -05001983 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1984 "LOGO cmpl: status:x%x/x%x did:x%x",
1985 irsp->ulpStatus, irsp->un.ulpWord[4],
1986 ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05001987 /* LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04001988 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
1989 "0105 LOGO completes to NPort x%x "
1990 "Data: x%x x%x x%x x%x\n",
1991 ndlp->nlp_DID, irsp->ulpStatus, irsp->un.ulpWord[4],
1992 irsp->ulpTimeout, vport->num_disc_nodes);
dea31012005-04-17 16:05:31 -05001993 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001994 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05001995 goto out;
1996
James Smart92d7f7b2007-06-17 19:56:38 -05001997 if (ndlp->nlp_flag & NLP_TARGET_REMOVE) {
1998 /* NLP_EVT_DEVICE_RM should unregister the RPI
1999 * which should abort all outstanding IOs.
2000 */
2001 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
2002 NLP_EVT_DEVICE_RM);
2003 goto out;
2004 }
2005
dea31012005-04-17 16:05:31 -05002006 if (irsp->ulpStatus) {
2007 /* Check for retry */
James Smart2e0fef82007-06-17 19:56:36 -05002008 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
dea31012005-04-17 16:05:31 -05002009 /* ELS command is being retried */
2010 goto out;
dea31012005-04-17 16:05:31 -05002011 /* LOGO failed */
2012 /* Do not call DSM for lpfc_els_abort'ed ELS cmds */
James Smart858c9f62007-06-17 19:56:39 -05002013 if (lpfc_error_lost_link(irsp))
dea31012005-04-17 16:05:31 -05002014 goto out;
James Smart858c9f62007-06-17 19:56:39 -05002015 else
James Smart2e0fef82007-06-17 19:56:36 -05002016 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002017 NLP_EVT_CMPL_LOGO);
James Smarte47c9092008-02-08 18:49:26 -05002018 } else
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002019 /* Good status, call state machine.
2020 * This will unregister the rpi if needed.
2021 */
James Smart2e0fef82007-06-17 19:56:36 -05002022 lpfc_disc_state_machine(vport, ndlp, cmdiocb,
James Smart92d7f7b2007-06-17 19:56:38 -05002023 NLP_EVT_CMPL_LOGO);
dea31012005-04-17 16:05:31 -05002024out:
2025 lpfc_els_free_iocb(phba, cmdiocb);
2026 return;
2027}
2028
James Smarte59058c2008-08-24 21:49:00 -04002029/**
James Smart3621a712009-04-06 18:47:14 -04002030 * lpfc_issue_els_logo - Issue a logo to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002031 * @vport: pointer to a virtual N_Port data structure.
2032 * @ndlp: pointer to a node-list data structure.
2033 * @retry: number of retries to the command IOCB.
2034 *
2035 * This routine constructs and issues an ELS Logout (LOGO) iocb command
2036 * to a remote node, referred by an @ndlp on a @vport. It constructs the
2037 * payload of the IOCB, properly sets up the @ndlp state, and invokes the
2038 * lpfc_sli_issue_iocb() routine to send out the LOGO ELS command.
2039 *
2040 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2041 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2042 * will be stored into the context1 field of the IOCB for the completion
2043 * callback function to the LOGO ELS command.
2044 *
2045 * Return code
2046 * 0 - successfully issued logo
2047 * 1 - failed to issue logo
2048 **/
dea31012005-04-17 16:05:31 -05002049int
James Smart2e0fef82007-06-17 19:56:36 -05002050lpfc_issue_els_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
dea31012005-04-17 16:05:31 -05002051 uint8_t retry)
2052{
James Smart2e0fef82007-06-17 19:56:36 -05002053 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2054 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002055 IOCB_t *icmd;
2056 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002057 uint8_t *pcmd;
2058 uint16_t cmdsize;
James Smart92d7f7b2007-06-17 19:56:38 -05002059 int rc;
dea31012005-04-17 16:05:31 -05002060
James Smart98c9ea52007-10-27 13:37:33 -04002061 spin_lock_irq(shost->host_lock);
2062 if (ndlp->nlp_flag & NLP_LOGO_SND) {
2063 spin_unlock_irq(shost->host_lock);
2064 return 0;
2065 }
2066 spin_unlock_irq(shost->host_lock);
2067
James Smart92d7f7b2007-06-17 19:56:38 -05002068 cmdsize = (2 * sizeof(uint32_t)) + sizeof(struct lpfc_name);
James Smart2e0fef82007-06-17 19:56:36 -05002069 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2070 ndlp->nlp_DID, ELS_CMD_LOGO);
James Smart488d1462006-03-07 15:02:37 -05002071 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002072 return 1;
dea31012005-04-17 16:05:31 -05002073
2074 icmd = &elsiocb->iocb;
2075 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2076 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
James Smart92d7f7b2007-06-17 19:56:38 -05002077 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002078
2079 /* Fill in LOGO payload */
James Smart2e0fef82007-06-17 19:56:36 -05002080 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
James Smart92d7f7b2007-06-17 19:56:38 -05002081 pcmd += sizeof(uint32_t);
2082 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002083
James Smart858c9f62007-06-17 19:56:39 -05002084 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2085 "Issue LOGO: did:x%x",
2086 ndlp->nlp_DID, 0, 0);
2087
dea31012005-04-17 16:05:31 -05002088 phba->fc_stat.elsXmitLOGO++;
2089 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo;
James Smart2e0fef82007-06-17 19:56:36 -05002090 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002091 ndlp->nlp_flag |= NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002092 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04002093 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05002094
2095 if (rc == IOCB_ERROR) {
James Smart2e0fef82007-06-17 19:56:36 -05002096 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002097 ndlp->nlp_flag &= ~NLP_LOGO_SND;
James Smart2e0fef82007-06-17 19:56:36 -05002098 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002099 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002100 return 1;
dea31012005-04-17 16:05:31 -05002101 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002102 return 0;
dea31012005-04-17 16:05:31 -05002103}
2104
James Smarte59058c2008-08-24 21:49:00 -04002105/**
James Smart3621a712009-04-06 18:47:14 -04002106 * lpfc_cmpl_els_cmd - Completion callback function for generic els command
James Smarte59058c2008-08-24 21:49:00 -04002107 * @phba: pointer to lpfc hba data structure.
2108 * @cmdiocb: pointer to lpfc command iocb data structure.
2109 * @rspiocb: pointer to lpfc response iocb data structure.
2110 *
2111 * This routine is a generic completion callback function for ELS commands.
2112 * Specifically, it is the callback function which does not need to perform
2113 * any command specific operations. It is currently used by the ELS command
2114 * issuing routines for the ELS State Change Request (SCR),
2115 * lpfc_issue_els_scr(), and the ELS Fibre Channel Address Resolution
2116 * Protocol Response (FARPR) routine, lpfc_issue_els_farpr(). Other than
2117 * certain debug loggings, this callback function simply invokes the
2118 * lpfc_els_chk_latt() routine to check whether link went down during the
2119 * discovery process.
2120 **/
dea31012005-04-17 16:05:31 -05002121static void
James Smart2e0fef82007-06-17 19:56:36 -05002122lpfc_cmpl_els_cmd(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2123 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002124{
James Smart2e0fef82007-06-17 19:56:36 -05002125 struct lpfc_vport *vport = cmdiocb->vport;
dea31012005-04-17 16:05:31 -05002126 IOCB_t *irsp;
2127
2128 irsp = &rspiocb->iocb;
2129
James Smart858c9f62007-06-17 19:56:39 -05002130 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2131 "ELS cmd cmpl: status:x%x/x%x did:x%x",
2132 irsp->ulpStatus, irsp->un.ulpWord[4],
2133 irsp->un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05002134 /* ELS cmd tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04002135 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2136 "0106 ELS cmd tag x%x completes Data: x%x x%x x%x\n",
2137 irsp->ulpIoTag, irsp->ulpStatus,
2138 irsp->un.ulpWord[4], irsp->ulpTimeout);
dea31012005-04-17 16:05:31 -05002139 /* Check to see if link went down during discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002140 lpfc_els_chk_latt(vport);
dea31012005-04-17 16:05:31 -05002141 lpfc_els_free_iocb(phba, cmdiocb);
2142 return;
2143}
2144
James Smarte59058c2008-08-24 21:49:00 -04002145/**
James Smart3621a712009-04-06 18:47:14 -04002146 * lpfc_issue_els_scr - Issue a scr to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002147 * @vport: pointer to a host virtual N_Port data structure.
2148 * @nportid: N_Port identifier to the remote node.
2149 * @retry: number of retries to the command IOCB.
2150 *
2151 * This routine issues a State Change Request (SCR) to a fabric node
2152 * on a @vport. The remote node @nportid is passed into the function. It
2153 * first search the @vport node list to find the matching ndlp. If no such
2154 * ndlp is found, a new ndlp shall be created for this (SCR) purpose. An
2155 * IOCB is allocated, payload prepared, and the lpfc_sli_issue_iocb()
2156 * routine is invoked to send the SCR IOCB.
2157 *
2158 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2159 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2160 * will be stored into the context1 field of the IOCB for the completion
2161 * callback function to the SCR ELS command.
2162 *
2163 * Return code
2164 * 0 - Successfully issued scr command
2165 * 1 - Failed to issue scr command
2166 **/
dea31012005-04-17 16:05:31 -05002167int
James Smart2e0fef82007-06-17 19:56:36 -05002168lpfc_issue_els_scr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002169{
James Smart2e0fef82007-06-17 19:56:36 -05002170 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002171 IOCB_t *icmd;
2172 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002173 struct lpfc_sli *psli;
2174 uint8_t *pcmd;
2175 uint16_t cmdsize;
2176 struct lpfc_nodelist *ndlp;
2177
2178 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002179 cmdsize = (sizeof(uint32_t) + sizeof(SCR));
dea31012005-04-17 16:05:31 -05002180
James Smarte47c9092008-02-08 18:49:26 -05002181 ndlp = lpfc_findnode_did(vport, nportid);
2182 if (!ndlp) {
2183 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2184 if (!ndlp)
2185 return 1;
2186 lpfc_nlp_init(vport, ndlp, nportid);
2187 lpfc_enqueue_node(vport, ndlp);
2188 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2189 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2190 if (!ndlp)
2191 return 1;
2192 }
dea31012005-04-17 16:05:31 -05002193
James Smart2e0fef82007-06-17 19:56:36 -05002194 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2195 ndlp->nlp_DID, ELS_CMD_SCR);
2196
James Smart488d1462006-03-07 15:02:37 -05002197 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002198 /* This will trigger the release of the node just
2199 * allocated
2200 */
James Smart329f9bc2007-04-25 09:53:01 -04002201 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002202 return 1;
dea31012005-04-17 16:05:31 -05002203 }
2204
2205 icmd = &elsiocb->iocb;
2206 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2207
2208 *((uint32_t *) (pcmd)) = ELS_CMD_SCR;
James Smart92d7f7b2007-06-17 19:56:38 -05002209 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002210
2211 /* For SCR, remainder of payload is SCR parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05002212 memset(pcmd, 0, sizeof(SCR));
dea31012005-04-17 16:05:31 -05002213 ((SCR *) pcmd)->Function = SCR_FUNC_FULL;
2214
James Smart858c9f62007-06-17 19:56:39 -05002215 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2216 "Issue SCR: did:x%x",
2217 ndlp->nlp_DID, 0, 0);
2218
dea31012005-04-17 16:05:31 -05002219 phba->fc_stat.elsXmitSCR++;
2220 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002221 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2222 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 rlease 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 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/**
James Smart3621a712009-04-06 18:47:14 -04002239 * lpfc_issue_els_farpr - Issue a farp to an node on a vport
James Smarte59058c2008-08-24 21:49:00 -04002240 * @vport: pointer to a host virtual N_Port data structure.
2241 * @nportid: N_Port identifier to the remote node.
2242 * @retry: number of retries to the command IOCB.
2243 *
2244 * This routine issues a Fibre Channel Address Resolution Response
2245 * (FARPR) to a node on a vport. The remote node N_Port identifier (@nportid)
2246 * is passed into the function. It first search the @vport node list to find
2247 * the matching ndlp. If no such ndlp is found, a new ndlp shall be created
2248 * for this (FARPR) purpose. An IOCB is allocated, payload prepared, and the
2249 * lpfc_sli_issue_iocb() routine is invoked to send the FARPR ELS command.
2250 *
2251 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
2252 * will be incremented by 1 for holding the ndlp and the reference to ndlp
2253 * will be stored into the context1 field of the IOCB for the completion
2254 * callback function to the PARPR ELS command.
2255 *
2256 * Return code
2257 * 0 - Successfully issued farpr command
2258 * 1 - Failed to issue farpr command
2259 **/
dea31012005-04-17 16:05:31 -05002260static int
James Smart2e0fef82007-06-17 19:56:36 -05002261lpfc_issue_els_farpr(struct lpfc_vport *vport, uint32_t nportid, uint8_t retry)
dea31012005-04-17 16:05:31 -05002262{
James Smart2e0fef82007-06-17 19:56:36 -05002263 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002264 IOCB_t *icmd;
2265 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05002266 struct lpfc_sli *psli;
2267 FARP *fp;
2268 uint8_t *pcmd;
2269 uint32_t *lp;
2270 uint16_t cmdsize;
2271 struct lpfc_nodelist *ondlp;
2272 struct lpfc_nodelist *ndlp;
2273
2274 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05002275 cmdsize = (sizeof(uint32_t) + sizeof(FARP));
dea31012005-04-17 16:05:31 -05002276
James Smarte47c9092008-02-08 18:49:26 -05002277 ndlp = lpfc_findnode_did(vport, nportid);
2278 if (!ndlp) {
2279 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
2280 if (!ndlp)
2281 return 1;
2282 lpfc_nlp_init(vport, ndlp, nportid);
2283 lpfc_enqueue_node(vport, ndlp);
2284 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2285 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
2286 if (!ndlp)
2287 return 1;
2288 }
James Smart2e0fef82007-06-17 19:56:36 -05002289
2290 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp,
2291 ndlp->nlp_DID, ELS_CMD_RNID);
James Smart488d1462006-03-07 15:02:37 -05002292 if (!elsiocb) {
James Smartfa4066b2008-01-11 01:53:27 -05002293 /* This will trigger the release of the node just
2294 * allocated
2295 */
James Smart329f9bc2007-04-25 09:53:01 -04002296 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002297 return 1;
dea31012005-04-17 16:05:31 -05002298 }
2299
2300 icmd = &elsiocb->iocb;
2301 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
2302
2303 *((uint32_t *) (pcmd)) = ELS_CMD_FARPR;
James Smart92d7f7b2007-06-17 19:56:38 -05002304 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05002305
2306 /* Fill in FARPR payload */
2307 fp = (FARP *) (pcmd);
James Smart92d7f7b2007-06-17 19:56:38 -05002308 memset(fp, 0, sizeof(FARP));
dea31012005-04-17 16:05:31 -05002309 lp = (uint32_t *) pcmd;
2310 *lp++ = be32_to_cpu(nportid);
James Smart2e0fef82007-06-17 19:56:36 -05002311 *lp++ = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05002312 fp->Rflags = 0;
2313 fp->Mflags = (FARP_MATCH_PORT | FARP_MATCH_NODE);
2314
James Smart92d7f7b2007-06-17 19:56:38 -05002315 memcpy(&fp->RportName, &vport->fc_portname, sizeof(struct lpfc_name));
2316 memcpy(&fp->RnodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05002317 ondlp = lpfc_findnode_did(vport, nportid);
James Smarte47c9092008-02-08 18:49:26 -05002318 if (ondlp && NLP_CHK_NODE_ACT(ondlp)) {
dea31012005-04-17 16:05:31 -05002319 memcpy(&fp->OportName, &ondlp->nlp_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05002320 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002321 memcpy(&fp->OnodeName, &ondlp->nlp_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05002322 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05002323 }
2324
James Smart858c9f62007-06-17 19:56:39 -05002325 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2326 "Issue FARPR: did:x%x",
2327 ndlp->nlp_DID, 0, 0);
2328
dea31012005-04-17 16:05:31 -05002329 phba->fc_stat.elsXmitFARPR++;
2330 elsiocb->iocb_cmpl = lpfc_cmpl_els_cmd;
James Smart3772a992009-05-22 14:50:54 -04002331 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
2332 IOCB_ERROR) {
James Smartfa4066b2008-01-11 01:53:27 -05002333 /* The additional lpfc_nlp_put will cause the following
2334 * lpfc_els_free_iocb routine to trigger the release of
2335 * the node.
2336 */
James Smart329f9bc2007-04-25 09:53:01 -04002337 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002338 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002339 return 1;
dea31012005-04-17 16:05:31 -05002340 }
James Smartfa4066b2008-01-11 01:53:27 -05002341 /* This will cause the callback-function lpfc_cmpl_els_cmd to
2342 * trigger the release of the node.
2343 */
James Smart329f9bc2007-04-25 09:53:01 -04002344 lpfc_nlp_put(ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002345 return 0;
dea31012005-04-17 16:05:31 -05002346}
2347
James Smarte59058c2008-08-24 21:49:00 -04002348/**
James Smart3621a712009-04-06 18:47:14 -04002349 * lpfc_cancel_retry_delay_tmo - Cancel the timer with delayed iocb-cmd retry
James Smarte59058c2008-08-24 21:49:00 -04002350 * @vport: pointer to a host virtual N_Port data structure.
2351 * @nlp: pointer to a node-list data structure.
2352 *
2353 * This routine cancels the timer with a delayed IOCB-command retry for
2354 * a @vport's @ndlp. It stops the timer for the delayed function retrial and
2355 * removes the ELS retry event if it presents. In addition, if the
2356 * NLP_NPR_2B_DISC bit is set in the @nlp's nlp_flag bitmap, ADISC IOCB
2357 * commands are sent for the @vport's nodes that require issuing discovery
2358 * ADISC.
2359 **/
dea31012005-04-17 16:05:31 -05002360void
James Smart2e0fef82007-06-17 19:56:36 -05002361lpfc_cancel_retry_delay_tmo(struct lpfc_vport *vport, struct lpfc_nodelist *nlp)
James Smartfdcebe22006-03-07 15:04:01 -05002362{
James Smart2e0fef82007-06-17 19:56:36 -05002363 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smarte47c9092008-02-08 18:49:26 -05002364 struct lpfc_work_evt *evtp;
James Smart2e0fef82007-06-17 19:56:36 -05002365
James Smart0d2b6b82008-06-14 22:52:47 -04002366 if (!(nlp->nlp_flag & NLP_DELAY_TMO))
2367 return;
James Smart2e0fef82007-06-17 19:56:36 -05002368 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002369 nlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002370 spin_unlock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002371 del_timer_sync(&nlp->nlp_delayfunc);
2372 nlp->nlp_last_elscmd = 0;
James Smarte47c9092008-02-08 18:49:26 -05002373 if (!list_empty(&nlp->els_retry_evt.evt_listp)) {
James Smartfdcebe22006-03-07 15:04:01 -05002374 list_del_init(&nlp->els_retry_evt.evt_listp);
James Smarte47c9092008-02-08 18:49:26 -05002375 /* Decrement nlp reference count held for the delayed retry */
2376 evtp = &nlp->els_retry_evt;
2377 lpfc_nlp_put((struct lpfc_nodelist *)evtp->evt_arg1);
2378 }
James Smartfdcebe22006-03-07 15:04:01 -05002379 if (nlp->nlp_flag & NLP_NPR_2B_DISC) {
James Smart2e0fef82007-06-17 19:56:36 -05002380 spin_lock_irq(shost->host_lock);
James Smartfdcebe22006-03-07 15:04:01 -05002381 nlp->nlp_flag &= ~NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002382 spin_unlock_irq(shost->host_lock);
2383 if (vport->num_disc_nodes) {
James Smart0d2b6b82008-06-14 22:52:47 -04002384 if (vport->port_state < LPFC_VPORT_READY) {
2385 /* Check if there are more ADISCs to be sent */
2386 lpfc_more_adisc(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04002387 } else {
2388 /* Check if there are more PLOGIs to be sent */
2389 lpfc_more_plogi(vport);
James Smart90160e02008-08-24 21:49:45 -04002390 if (vport->num_disc_nodes == 0) {
2391 spin_lock_irq(shost->host_lock);
2392 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2393 spin_unlock_irq(shost->host_lock);
2394 lpfc_can_disctmo(vport);
2395 lpfc_end_rscn(vport);
2396 }
James Smartfdcebe22006-03-07 15:04:01 -05002397 }
2398 }
2399 }
2400 return;
2401}
2402
James Smarte59058c2008-08-24 21:49:00 -04002403/**
James Smart3621a712009-04-06 18:47:14 -04002404 * lpfc_els_retry_delay - Timer function with a ndlp delayed function timer
James Smarte59058c2008-08-24 21:49:00 -04002405 * @ptr: holder for the pointer to the timer function associated data (ndlp).
2406 *
2407 * This routine is invoked by the ndlp delayed-function timer to check
2408 * whether there is any pending ELS retry event(s) with the node. If not, it
2409 * simply returns. Otherwise, if there is at least one ELS delayed event, it
2410 * adds the delayed events to the HBA work list and invokes the
2411 * lpfc_worker_wake_up() routine to wake up worker thread to process the
2412 * event. Note that lpfc_nlp_get() is called before posting the event to
2413 * the work list to hold reference count of ndlp so that it guarantees the
2414 * reference to ndlp will still be available when the worker thread gets
2415 * to the event associated with the ndlp.
2416 **/
James Smartfdcebe22006-03-07 15:04:01 -05002417void
dea31012005-04-17 16:05:31 -05002418lpfc_els_retry_delay(unsigned long ptr)
2419{
James Smart2e0fef82007-06-17 19:56:36 -05002420 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
2421 struct lpfc_vport *vport = ndlp->vport;
James Smart2e0fef82007-06-17 19:56:36 -05002422 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05002423 unsigned long flags;
James Smart2e0fef82007-06-17 19:56:36 -05002424 struct lpfc_work_evt *evtp = &ndlp->els_retry_evt;
dea31012005-04-17 16:05:31 -05002425
James Smart92d7f7b2007-06-17 19:56:38 -05002426 spin_lock_irqsave(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002427 if (!list_empty(&evtp->evt_listp)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002428 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002429 return;
2430 }
2431
James Smartfa4066b2008-01-11 01:53:27 -05002432 /* We need to hold the node by incrementing the reference
2433 * count until the queued work is done
2434 */
2435 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
James Smart5e9d9b82008-06-14 22:52:53 -04002436 if (evtp->evt_arg1) {
2437 evtp->evt = LPFC_EVT_ELS_RETRY;
2438 list_add_tail(&evtp->evt_listp, &phba->work_list);
James Smart92d7f7b2007-06-17 19:56:38 -05002439 lpfc_worker_wake_up(phba);
James Smart5e9d9b82008-06-14 22:52:53 -04002440 }
James Smart92d7f7b2007-06-17 19:56:38 -05002441 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002442 return;
2443}
2444
James Smarte59058c2008-08-24 21:49:00 -04002445/**
James Smart3621a712009-04-06 18:47:14 -04002446 * lpfc_els_retry_delay_handler - Work thread handler for ndlp delayed function
James Smarte59058c2008-08-24 21:49:00 -04002447 * @ndlp: pointer to a node-list data structure.
2448 *
2449 * This routine is the worker-thread handler for processing the @ndlp delayed
2450 * event(s), posted by the lpfc_els_retry_delay() routine. It simply retrieves
2451 * the last ELS command from the associated ndlp and invokes the proper ELS
2452 * function according to the delayed ELS command to retry the command.
2453 **/
dea31012005-04-17 16:05:31 -05002454void
2455lpfc_els_retry_delay_handler(struct lpfc_nodelist *ndlp)
2456{
James Smart2e0fef82007-06-17 19:56:36 -05002457 struct lpfc_vport *vport = ndlp->vport;
2458 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2459 uint32_t cmd, did, retry;
dea31012005-04-17 16:05:31 -05002460
James Smart2e0fef82007-06-17 19:56:36 -05002461 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002462 did = ndlp->nlp_DID;
2463 cmd = ndlp->nlp_last_elscmd;
2464 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05002465
2466 if (!(ndlp->nlp_flag & NLP_DELAY_TMO)) {
James Smart2e0fef82007-06-17 19:56:36 -05002467 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002468 return;
2469 }
2470
2471 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002472 spin_unlock_irq(shost->host_lock);
James Smart1a169682006-03-07 15:04:06 -05002473 /*
2474 * If a discovery event readded nlp_delayfunc after timer
2475 * firing and before processing the timer, cancel the
2476 * nlp_delayfunc.
2477 */
2478 del_timer_sync(&ndlp->nlp_delayfunc);
dea31012005-04-17 16:05:31 -05002479 retry = ndlp->nlp_retry;
James Smart4d9ab992009-10-02 15:16:39 -04002480 ndlp->nlp_retry = 0;
dea31012005-04-17 16:05:31 -05002481
2482 switch (cmd) {
2483 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002484 lpfc_issue_els_flogi(vport, ndlp, retry);
dea31012005-04-17 16:05:31 -05002485 break;
2486 case ELS_CMD_PLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002487 if (!lpfc_issue_els_plogi(vport, ndlp->nlp_DID, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002488 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002489 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002490 }
dea31012005-04-17 16:05:31 -05002491 break;
2492 case ELS_CMD_ADISC:
James Smart2e0fef82007-06-17 19:56:36 -05002493 if (!lpfc_issue_els_adisc(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002494 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002495 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002496 }
dea31012005-04-17 16:05:31 -05002497 break;
2498 case ELS_CMD_PRLI:
James Smart2e0fef82007-06-17 19:56:36 -05002499 if (!lpfc_issue_els_prli(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002500 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002501 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002502 }
dea31012005-04-17 16:05:31 -05002503 break;
2504 case ELS_CMD_LOGO:
James Smart2e0fef82007-06-17 19:56:36 -05002505 if (!lpfc_issue_els_logo(vport, ndlp, retry)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002506 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002507 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
Jamie Wellnitz6ad42532006-02-28 19:25:16 -05002508 }
dea31012005-04-17 16:05:31 -05002509 break;
James Smart92d7f7b2007-06-17 19:56:38 -05002510 case ELS_CMD_FDISC:
2511 lpfc_issue_els_fdisc(vport, ndlp, retry);
2512 break;
dea31012005-04-17 16:05:31 -05002513 }
2514 return;
2515}
2516
James Smarte59058c2008-08-24 21:49:00 -04002517/**
James Smart3621a712009-04-06 18:47:14 -04002518 * lpfc_els_retry - Make retry decision on an els command iocb
James Smarte59058c2008-08-24 21:49:00 -04002519 * @phba: pointer to lpfc hba data structure.
2520 * @cmdiocb: pointer to lpfc command iocb data structure.
2521 * @rspiocb: pointer to lpfc response iocb data structure.
2522 *
2523 * This routine makes a retry decision on an ELS command IOCB, which has
2524 * failed. The following ELS IOCBs use this function for retrying the command
2525 * when previously issued command responsed with error status: FLOGI, PLOGI,
2526 * PRLI, ADISC, LOGO, and FDISC. Based on the ELS command type and the
2527 * returned error status, it makes the decision whether a retry shall be
2528 * issued for the command, and whether a retry shall be made immediately or
2529 * delayed. In the former case, the corresponding ELS command issuing-function
2530 * is called to retry the command. In the later case, the ELS command shall
2531 * be posted to the ndlp delayed event and delayed function timer set to the
2532 * ndlp for the delayed command issusing.
2533 *
2534 * Return code
2535 * 0 - No retry of els command is made
2536 * 1 - Immediate or delayed retry of els command is made
2537 **/
dea31012005-04-17 16:05:31 -05002538static int
James Smart2e0fef82007-06-17 19:56:36 -05002539lpfc_els_retry(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
2540 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05002541{
James Smart2e0fef82007-06-17 19:56:36 -05002542 struct lpfc_vport *vport = cmdiocb->vport;
2543 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2544 IOCB_t *irsp = &rspiocb->iocb;
2545 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
2546 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
dea31012005-04-17 16:05:31 -05002547 uint32_t *elscmd;
2548 struct ls_rjt stat;
James Smart2e0fef82007-06-17 19:56:36 -05002549 int retry = 0, maxretry = lpfc_max_els_tries, delay = 0;
James Smart98c9ea52007-10-27 13:37:33 -04002550 int logerr = 0;
James Smart2e0fef82007-06-17 19:56:36 -05002551 uint32_t cmd = 0;
James Smart488d1462006-03-07 15:02:37 -05002552 uint32_t did;
dea31012005-04-17 16:05:31 -05002553
James Smart488d1462006-03-07 15:02:37 -05002554
dea31012005-04-17 16:05:31 -05002555 /* Note: context2 may be 0 for internal driver abort
2556 * of delays ELS command.
2557 */
2558
2559 if (pcmd && pcmd->virt) {
2560 elscmd = (uint32_t *) (pcmd->virt);
2561 cmd = *elscmd++;
2562 }
2563
James Smarte47c9092008-02-08 18:49:26 -05002564 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart488d1462006-03-07 15:02:37 -05002565 did = ndlp->nlp_DID;
2566 else {
2567 /* We should only hit this case for retrying PLOGI */
2568 did = irsp->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05002569 ndlp = lpfc_findnode_did(vport, did);
James Smarte47c9092008-02-08 18:49:26 -05002570 if ((!ndlp || !NLP_CHK_NODE_ACT(ndlp))
2571 && (cmd != ELS_CMD_PLOGI))
James Smart488d1462006-03-07 15:02:37 -05002572 return 1;
2573 }
2574
James Smart858c9f62007-06-17 19:56:39 -05002575 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2576 "Retry ELS: wd7:x%x wd4:x%x did:x%x",
2577 *(((uint32_t *) irsp) + 7), irsp->un.ulpWord[4], ndlp->nlp_DID);
2578
dea31012005-04-17 16:05:31 -05002579 switch (irsp->ulpStatus) {
2580 case IOSTAT_FCP_RSP_ERROR:
2581 case IOSTAT_REMOTE_STOP:
2582 break;
2583
2584 case IOSTAT_LOCAL_REJECT:
2585 switch ((irsp->un.ulpWord[4] & 0xff)) {
2586 case IOERR_LOOP_OPEN_FAILURE:
James Smarteaf15d52008-12-04 22:39:29 -05002587 if (cmd == ELS_CMD_FLOGI) {
2588 if (PCI_DEVICE_ID_HORNET ==
2589 phba->pcidev->device) {
2590 phba->fc_topology = TOPOLOGY_LOOP;
2591 phba->pport->fc_myDID = 0;
2592 phba->alpa_map[0] = 0;
2593 phba->alpa_map[1] = 0;
2594 }
2595 }
James Smart2e0fef82007-06-17 19:56:36 -05002596 if (cmd == ELS_CMD_PLOGI && cmdiocb->retry == 0)
James Smart92d7f7b2007-06-17 19:56:38 -05002597 delay = 1000;
dea31012005-04-17 16:05:31 -05002598 retry = 1;
2599 break;
2600
James Smart92d7f7b2007-06-17 19:56:38 -05002601 case IOERR_ILLEGAL_COMMAND:
James Smart7f5f3d02008-02-08 18:50:14 -05002602 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2603 "0124 Retry illegal cmd x%x "
2604 "retry:x%x delay:x%x\n",
2605 cmd, cmdiocb->retry, delay);
2606 retry = 1;
2607 /* All command's retry policy */
2608 maxretry = 8;
2609 if (cmdiocb->retry > 2)
2610 delay = 1000;
James Smart92d7f7b2007-06-17 19:56:38 -05002611 break;
2612
dea31012005-04-17 16:05:31 -05002613 case IOERR_NO_RESOURCES:
James Smart98c9ea52007-10-27 13:37:33 -04002614 logerr = 1; /* HBA out of resources */
James Smart858c9f62007-06-17 19:56:39 -05002615 retry = 1;
2616 if (cmdiocb->retry > 100)
2617 delay = 100;
2618 maxretry = 250;
2619 break;
2620
2621 case IOERR_ILLEGAL_FRAME:
James Smart92d7f7b2007-06-17 19:56:38 -05002622 delay = 100;
dea31012005-04-17 16:05:31 -05002623 retry = 1;
2624 break;
2625
James Smart858c9f62007-06-17 19:56:39 -05002626 case IOERR_SEQUENCE_TIMEOUT:
dea31012005-04-17 16:05:31 -05002627 case IOERR_INVALID_RPI:
2628 retry = 1;
2629 break;
2630 }
2631 break;
2632
2633 case IOSTAT_NPORT_RJT:
2634 case IOSTAT_FABRIC_RJT:
2635 if (irsp->un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
2636 retry = 1;
2637 break;
2638 }
2639 break;
2640
2641 case IOSTAT_NPORT_BSY:
2642 case IOSTAT_FABRIC_BSY:
James Smart98c9ea52007-10-27 13:37:33 -04002643 logerr = 1; /* Fabric / Remote NPort out of resources */
dea31012005-04-17 16:05:31 -05002644 retry = 1;
2645 break;
2646
2647 case IOSTAT_LS_RJT:
2648 stat.un.lsRjtError = be32_to_cpu(irsp->un.ulpWord[4]);
2649 /* Added for Vendor specifc support
2650 * Just keep retrying for these Rsn / Exp codes
2651 */
2652 switch (stat.un.b.lsRjtRsnCode) {
2653 case LSRJT_UNABLE_TPC:
2654 if (stat.un.b.lsRjtRsnCodeExp ==
2655 LSEXP_CMD_IN_PROGRESS) {
2656 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05002657 delay = 1000;
dea31012005-04-17 16:05:31 -05002658 maxretry = 48;
2659 }
2660 retry = 1;
2661 break;
2662 }
2663 if (cmd == ELS_CMD_PLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05002664 delay = 1000;
dea31012005-04-17 16:05:31 -05002665 maxretry = lpfc_max_els_tries + 1;
2666 retry = 1;
2667 break;
2668 }
James Smart92d7f7b2007-06-17 19:56:38 -05002669 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2670 (cmd == ELS_CMD_FDISC) &&
2671 (stat.un.b.lsRjtRsnCodeExp == LSEXP_OUT_OF_RESOURCE)){
James Smarte8b62012007-08-02 11:10:09 -04002672 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2673 "0125 FDISC Failed (x%x). "
2674 "Fabric out of resources\n",
2675 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05002676 lpfc_vport_set_state(vport,
2677 FC_VPORT_NO_FABRIC_RSCS);
2678 }
dea31012005-04-17 16:05:31 -05002679 break;
2680
2681 case LSRJT_LOGICAL_BSY:
James Smart858c9f62007-06-17 19:56:39 -05002682 if ((cmd == ELS_CMD_PLOGI) ||
2683 (cmd == ELS_CMD_PRLI)) {
James Smart92d7f7b2007-06-17 19:56:38 -05002684 delay = 1000;
dea31012005-04-17 16:05:31 -05002685 maxretry = 48;
James Smart92d7f7b2007-06-17 19:56:38 -05002686 } else if (cmd == ELS_CMD_FDISC) {
James Smart51ef4c22007-08-02 11:10:31 -04002687 /* FDISC retry policy */
2688 maxretry = 48;
2689 if (cmdiocb->retry >= 32)
2690 delay = 1000;
dea31012005-04-17 16:05:31 -05002691 }
2692 retry = 1;
2693 break;
James Smart92d7f7b2007-06-17 19:56:38 -05002694
2695 case LSRJT_LOGICAL_ERR:
James Smart7f5f3d02008-02-08 18:50:14 -05002696 /* There are some cases where switches return this
2697 * error when they are not ready and should be returning
2698 * Logical Busy. We should delay every time.
2699 */
2700 if (cmd == ELS_CMD_FDISC &&
2701 stat.un.b.lsRjtRsnCodeExp == LSEXP_PORT_LOGIN_REQ) {
2702 maxretry = 3;
2703 delay = 1000;
2704 retry = 1;
2705 break;
2706 }
James Smart92d7f7b2007-06-17 19:56:38 -05002707 case LSRJT_PROTOCOL_ERR:
2708 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2709 (cmd == ELS_CMD_FDISC) &&
2710 ((stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_PNAME) ||
2711 (stat.un.b.lsRjtRsnCodeExp == LSEXP_INVALID_NPORT_ID))
2712 ) {
James Smarte8b62012007-08-02 11:10:09 -04002713 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smartd7c255b2008-08-24 21:50:00 -04002714 "0122 FDISC Failed (x%x). "
James Smarte8b62012007-08-02 11:10:09 -04002715 "Fabric Detected Bad WWN\n",
2716 stat.un.lsRjtError);
James Smart92d7f7b2007-06-17 19:56:38 -05002717 lpfc_vport_set_state(vport,
2718 FC_VPORT_FABRIC_REJ_WWN);
2719 }
2720 break;
dea31012005-04-17 16:05:31 -05002721 }
2722 break;
2723
2724 case IOSTAT_INTERMED_RSP:
2725 case IOSTAT_BA_RJT:
2726 break;
2727
2728 default:
2729 break;
2730 }
2731
James Smart488d1462006-03-07 15:02:37 -05002732 if (did == FDMI_DID)
dea31012005-04-17 16:05:31 -05002733 retry = 1;
dea31012005-04-17 16:05:31 -05002734
James Smart695a8142010-01-26 23:08:03 -05002735 if (((cmd == ELS_CMD_FLOGI) || (cmd == ELS_CMD_FDISC)) &&
James Smart1b32f6a2008-02-08 18:49:39 -05002736 (phba->fc_topology != TOPOLOGY_LOOP) &&
2737 !lpfc_error_lost_link(irsp)) {
James Smart98c9ea52007-10-27 13:37:33 -04002738 /* FLOGI retry policy */
2739 retry = 1;
James Smart6669f9b2009-10-02 15:16:45 -04002740 /* retry forever */
2741 maxretry = 0;
2742 if (cmdiocb->retry >= 100)
2743 delay = 5000;
2744 else if (cmdiocb->retry >= 32)
James Smart98c9ea52007-10-27 13:37:33 -04002745 delay = 1000;
2746 }
2747
James Smart6669f9b2009-10-02 15:16:45 -04002748 cmdiocb->retry++;
2749 if (maxretry && (cmdiocb->retry >= maxretry)) {
dea31012005-04-17 16:05:31 -05002750 phba->fc_stat.elsRetryExceeded++;
2751 retry = 0;
2752 }
2753
James Smarted957682007-06-17 19:56:37 -05002754 if ((vport->load_flag & FC_UNLOADING) != 0)
2755 retry = 0;
2756
dea31012005-04-17 16:05:31 -05002757 if (retry) {
2758
2759 /* Retry ELS command <elsCmd> to remote NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04002760 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
2761 "0107 Retry ELS command x%x to remote "
2762 "NPORT x%x Data: x%x x%x\n",
2763 cmd, did, cmdiocb->retry, delay);
dea31012005-04-17 16:05:31 -05002764
James Smart858c9f62007-06-17 19:56:39 -05002765 if (((cmd == ELS_CMD_PLOGI) || (cmd == ELS_CMD_ADISC)) &&
2766 ((irsp->ulpStatus != IOSTAT_LOCAL_REJECT) ||
2767 ((irsp->un.ulpWord[4] & 0xff) != IOERR_NO_RESOURCES))) {
2768 /* Don't reset timer for no resources */
2769
dea31012005-04-17 16:05:31 -05002770 /* If discovery / RSCN timer is running, reset it */
James Smart2e0fef82007-06-17 19:56:36 -05002771 if (timer_pending(&vport->fc_disctmo) ||
James Smart92d7f7b2007-06-17 19:56:38 -05002772 (vport->fc_flag & FC_RSCN_MODE))
James Smart2e0fef82007-06-17 19:56:36 -05002773 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05002774 }
2775
2776 phba->fc_stat.elsXmitRetry++;
James Smart58da1ff2008-04-07 10:15:56 -04002777 if (ndlp && NLP_CHK_NODE_ACT(ndlp) && delay) {
dea31012005-04-17 16:05:31 -05002778 phba->fc_stat.elsDelayRetry++;
2779 ndlp->nlp_retry = cmdiocb->retry;
2780
James Smart92d7f7b2007-06-17 19:56:38 -05002781 /* delay is specified in milliseconds */
2782 mod_timer(&ndlp->nlp_delayfunc,
2783 jiffies + msecs_to_jiffies(delay));
James Smart2e0fef82007-06-17 19:56:36 -05002784 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002785 ndlp->nlp_flag |= NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002786 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002787
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002788 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart858c9f62007-06-17 19:56:39 -05002789 if (cmd == ELS_CMD_PRLI)
2790 lpfc_nlp_set_state(vport, ndlp,
2791 NLP_STE_REG_LOGIN_ISSUE);
2792 else
2793 lpfc_nlp_set_state(vport, ndlp,
2794 NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05002795 ndlp->nlp_last_elscmd = cmd;
2796
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002797 return 1;
dea31012005-04-17 16:05:31 -05002798 }
2799 switch (cmd) {
2800 case ELS_CMD_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002801 lpfc_issue_els_flogi(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002802 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -05002803 case ELS_CMD_FDISC:
2804 lpfc_issue_els_fdisc(vport, ndlp, cmdiocb->retry);
2805 return 1;
dea31012005-04-17 16:05:31 -05002806 case ELS_CMD_PLOGI:
James Smart58da1ff2008-04-07 10:15:56 -04002807 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart488d1462006-03-07 15:02:37 -05002808 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002809 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04002810 NLP_STE_PLOGI_ISSUE);
James Smart488d1462006-03-07 15:02:37 -05002811 }
James Smart2e0fef82007-06-17 19:56:36 -05002812 lpfc_issue_els_plogi(vport, did, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002813 return 1;
dea31012005-04-17 16:05:31 -05002814 case ELS_CMD_ADISC:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002815 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002816 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
2817 lpfc_issue_els_adisc(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002818 return 1;
dea31012005-04-17 16:05:31 -05002819 case ELS_CMD_PRLI:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002820 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002821 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PRLI_ISSUE);
2822 lpfc_issue_els_prli(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002823 return 1;
dea31012005-04-17 16:05:31 -05002824 case ELS_CMD_LOGO:
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002825 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05002826 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2827 lpfc_issue_els_logo(vport, ndlp, cmdiocb->retry);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002828 return 1;
dea31012005-04-17 16:05:31 -05002829 }
2830 }
dea31012005-04-17 16:05:31 -05002831 /* No retry ELS command <elsCmd> to remote NPORT <did> */
James Smart98c9ea52007-10-27 13:37:33 -04002832 if (logerr) {
2833 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2834 "0137 No retry ELS command x%x to remote "
2835 "NPORT x%x: Out of Resources: Error:x%x/%x\n",
2836 cmd, did, irsp->ulpStatus,
2837 irsp->un.ulpWord[4]);
2838 }
2839 else {
2840 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
James Smarta58cbd52007-08-02 11:09:43 -04002841 "0108 No retry ELS command x%x to remote "
2842 "NPORT x%x Retried:%d Error:x%x/%x\n",
2843 cmd, did, cmdiocb->retry, irsp->ulpStatus,
2844 irsp->un.ulpWord[4]);
James Smart98c9ea52007-10-27 13:37:33 -04002845 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002846 return 0;
dea31012005-04-17 16:05:31 -05002847}
2848
James Smarte59058c2008-08-24 21:49:00 -04002849/**
James Smart3621a712009-04-06 18:47:14 -04002850 * lpfc_els_free_data - Free lpfc dma buffer and data structure with an iocb
James Smarte59058c2008-08-24 21:49:00 -04002851 * @phba: pointer to lpfc hba data structure.
2852 * @buf_ptr1: pointer to the lpfc DMA buffer data structure.
2853 *
2854 * This routine releases the lpfc DMA (Direct Memory Access) buffer(s)
2855 * associated with a command IOCB back to the lpfc DMA buffer pool. It first
2856 * checks to see whether there is a lpfc DMA buffer associated with the
2857 * response of the command IOCB. If so, it will be released before releasing
2858 * the lpfc DMA buffer associated with the IOCB itself.
2859 *
2860 * Return code
2861 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
2862 **/
James Smart09372822008-01-11 01:52:54 -05002863static int
James Smart87af33f2007-10-27 13:37:43 -04002864lpfc_els_free_data(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr1)
2865{
2866 struct lpfc_dmabuf *buf_ptr;
2867
James Smarte59058c2008-08-24 21:49:00 -04002868 /* Free the response before processing the command. */
James Smart87af33f2007-10-27 13:37:43 -04002869 if (!list_empty(&buf_ptr1->list)) {
2870 list_remove_head(&buf_ptr1->list, buf_ptr,
2871 struct lpfc_dmabuf,
2872 list);
2873 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
2874 kfree(buf_ptr);
2875 }
2876 lpfc_mbuf_free(phba, buf_ptr1->virt, buf_ptr1->phys);
2877 kfree(buf_ptr1);
2878 return 0;
2879}
2880
James Smarte59058c2008-08-24 21:49:00 -04002881/**
James Smart3621a712009-04-06 18:47:14 -04002882 * lpfc_els_free_bpl - Free lpfc dma buffer and data structure with bpl
James Smarte59058c2008-08-24 21:49:00 -04002883 * @phba: pointer to lpfc hba data structure.
2884 * @buf_ptr: pointer to the lpfc dma buffer data structure.
2885 *
2886 * This routine releases the lpfc Direct Memory Access (DMA) buffer
2887 * associated with a Buffer Pointer List (BPL) back to the lpfc DMA buffer
2888 * pool.
2889 *
2890 * Return code
2891 * 0 - Successfully released lpfc DMA buffer (currently, always return 0)
2892 **/
James Smart09372822008-01-11 01:52:54 -05002893static int
James Smart87af33f2007-10-27 13:37:43 -04002894lpfc_els_free_bpl(struct lpfc_hba *phba, struct lpfc_dmabuf *buf_ptr)
2895{
2896 lpfc_mbuf_free(phba, buf_ptr->virt, buf_ptr->phys);
2897 kfree(buf_ptr);
2898 return 0;
2899}
2900
James Smarte59058c2008-08-24 21:49:00 -04002901/**
James Smart3621a712009-04-06 18:47:14 -04002902 * lpfc_els_free_iocb - Free a command iocb and its associated resources
James Smarte59058c2008-08-24 21:49:00 -04002903 * @phba: pointer to lpfc hba data structure.
2904 * @elsiocb: pointer to lpfc els command iocb data structure.
2905 *
2906 * This routine frees a command IOCB and its associated resources. The
2907 * command IOCB data structure contains the reference to various associated
2908 * resources, these fields must be set to NULL if the associated reference
2909 * not present:
2910 * context1 - reference to ndlp
2911 * context2 - reference to cmd
2912 * context2->next - reference to rsp
2913 * context3 - reference to bpl
2914 *
2915 * It first properly decrements the reference count held on ndlp for the
2916 * IOCB completion callback function. If LPFC_DELAY_MEM_FREE flag is not
2917 * set, it invokes the lpfc_els_free_data() routine to release the Direct
2918 * Memory Access (DMA) buffers associated with the IOCB. Otherwise, it
2919 * adds the DMA buffer the @phba data structure for the delayed release.
2920 * If reference to the Buffer Pointer List (BPL) is present, the
2921 * lpfc_els_free_bpl() routine is invoked to release the DMA memory
2922 * associated with BPL. Finally, the lpfc_sli_release_iocbq() routine is
2923 * invoked to release the IOCB data structure back to @phba IOCBQ list.
2924 *
2925 * Return code
2926 * 0 - Success (currently, always return 0)
2927 **/
James Smart87af33f2007-10-27 13:37:43 -04002928int
James Smart329f9bc2007-04-25 09:53:01 -04002929lpfc_els_free_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05002930{
2931 struct lpfc_dmabuf *buf_ptr, *buf_ptr1;
James Smarta8adb832007-10-27 13:37:53 -04002932 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05002933
James Smarta8adb832007-10-27 13:37:53 -04002934 ndlp = (struct lpfc_nodelist *)elsiocb->context1;
2935 if (ndlp) {
2936 if (ndlp->nlp_flag & NLP_DEFER_RM) {
2937 lpfc_nlp_put(ndlp);
2938
2939 /* If the ndlp is not being used by another discovery
2940 * thread, free it.
2941 */
2942 if (!lpfc_nlp_not_used(ndlp)) {
2943 /* If ndlp is being used by another discovery
2944 * thread, just clear NLP_DEFER_RM
2945 */
2946 ndlp->nlp_flag &= ~NLP_DEFER_RM;
2947 }
2948 }
2949 else
2950 lpfc_nlp_put(ndlp);
James Smart329f9bc2007-04-25 09:53:01 -04002951 elsiocb->context1 = NULL;
2952 }
dea31012005-04-17 16:05:31 -05002953 /* context2 = cmd, context2->next = rsp, context3 = bpl */
2954 if (elsiocb->context2) {
James Smart0ff10d42008-01-11 01:52:36 -05002955 if (elsiocb->iocb_flag & LPFC_DELAY_MEM_FREE) {
2956 /* Firmware could still be in progress of DMAing
2957 * payload, so don't free data buffer till after
2958 * a hbeat.
2959 */
2960 elsiocb->iocb_flag &= ~LPFC_DELAY_MEM_FREE;
2961 buf_ptr = elsiocb->context2;
2962 elsiocb->context2 = NULL;
2963 if (buf_ptr) {
2964 buf_ptr1 = NULL;
2965 spin_lock_irq(&phba->hbalock);
2966 if (!list_empty(&buf_ptr->list)) {
2967 list_remove_head(&buf_ptr->list,
2968 buf_ptr1, struct lpfc_dmabuf,
2969 list);
2970 INIT_LIST_HEAD(&buf_ptr1->list);
2971 list_add_tail(&buf_ptr1->list,
2972 &phba->elsbuf);
2973 phba->elsbuf_cnt++;
2974 }
2975 INIT_LIST_HEAD(&buf_ptr->list);
2976 list_add_tail(&buf_ptr->list, &phba->elsbuf);
2977 phba->elsbuf_cnt++;
2978 spin_unlock_irq(&phba->hbalock);
2979 }
2980 } else {
2981 buf_ptr1 = (struct lpfc_dmabuf *) elsiocb->context2;
2982 lpfc_els_free_data(phba, buf_ptr1);
2983 }
dea31012005-04-17 16:05:31 -05002984 }
2985
2986 if (elsiocb->context3) {
2987 buf_ptr = (struct lpfc_dmabuf *) elsiocb->context3;
James Smart87af33f2007-10-27 13:37:43 -04002988 lpfc_els_free_bpl(phba, buf_ptr);
dea31012005-04-17 16:05:31 -05002989 }
James Bottomley604a3e32005-10-29 10:28:33 -05002990 lpfc_sli_release_iocbq(phba, elsiocb);
dea31012005-04-17 16:05:31 -05002991 return 0;
2992}
2993
James Smarte59058c2008-08-24 21:49:00 -04002994/**
James Smart3621a712009-04-06 18:47:14 -04002995 * lpfc_cmpl_els_logo_acc - Completion callback function to logo acc response
James Smarte59058c2008-08-24 21:49:00 -04002996 * @phba: pointer to lpfc hba data structure.
2997 * @cmdiocb: pointer to lpfc command iocb data structure.
2998 * @rspiocb: pointer to lpfc response iocb data structure.
2999 *
3000 * This routine is the completion callback function to the Logout (LOGO)
3001 * Accept (ACC) Response ELS command. This routine is invoked to indicate
3002 * the completion of the LOGO process. It invokes the lpfc_nlp_not_used() to
3003 * release the ndlp if it has the last reference remaining (reference count
3004 * is 1). If succeeded (meaning ndlp released), it sets the IOCB context1
3005 * field to NULL to inform the following lpfc_els_free_iocb() routine no
3006 * ndlp reference count needs to be decremented. Otherwise, the ndlp
3007 * reference use-count shall be decremented by the lpfc_els_free_iocb()
3008 * routine. Finally, the lpfc_els_free_iocb() is invoked to release the
3009 * IOCB data structure.
3010 **/
dea31012005-04-17 16:05:31 -05003011static void
James Smart2e0fef82007-06-17 19:56:36 -05003012lpfc_cmpl_els_logo_acc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
3013 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003014{
James Smart2e0fef82007-06-17 19:56:36 -05003015 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3016 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05003017 IOCB_t *irsp;
3018
3019 irsp = &rspiocb->iocb;
3020 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3021 "ACC LOGO cmpl: status:x%x/x%x did:x%x",
3022 irsp->ulpStatus, irsp->un.ulpWord[4], ndlp->nlp_DID);
dea31012005-04-17 16:05:31 -05003023 /* ACC to LOGO completes to NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04003024 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3025 "0109 ACC to LOGO completes to NPort x%x "
3026 "Data: x%x x%x x%x\n",
3027 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3028 ndlp->nlp_rpi);
James Smart87af33f2007-10-27 13:37:43 -04003029
3030 if (ndlp->nlp_state == NLP_STE_NPR_NODE) {
3031 /* NPort Recovery mode or node is just allocated */
3032 if (!lpfc_nlp_not_used(ndlp)) {
3033 /* If the ndlp is being used by another discovery
3034 * thread, just unregister the RPI.
3035 */
3036 lpfc_unreg_rpi(vport, ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05003037 } else {
3038 /* Indicate the node has already released, should
3039 * not reference to it from within lpfc_els_free_iocb.
3040 */
3041 cmdiocb->context1 = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003042 }
dea31012005-04-17 16:05:31 -05003043 }
3044 lpfc_els_free_iocb(phba, cmdiocb);
3045 return;
3046}
3047
James Smarte59058c2008-08-24 21:49:00 -04003048/**
James Smart3621a712009-04-06 18:47:14 -04003049 * lpfc_mbx_cmpl_dflt_rpi - Completion callbk func for unreg dflt rpi mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04003050 * @phba: pointer to lpfc hba data structure.
3051 * @pmb: pointer to the driver internal queue element for mailbox command.
3052 *
3053 * This routine is the completion callback function for unregister default
3054 * RPI (Remote Port Index) mailbox command to the @phba. It simply releases
3055 * the associated lpfc Direct Memory Access (DMA) buffer back to the pool and
3056 * decrements the ndlp reference count held for this completion callback
3057 * function. After that, it invokes the lpfc_nlp_not_used() to check
3058 * whether there is only one reference left on the ndlp. If so, it will
3059 * perform one more decrement and trigger the release of the ndlp.
3060 **/
James Smart858c9f62007-06-17 19:56:39 -05003061void
3062lpfc_mbx_cmpl_dflt_rpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3063{
3064 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3065 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
3066
James Smart6fb120a2009-05-22 14:52:59 -04003067 /*
3068 * This routine is used to register and unregister in previous SLI
3069 * modes.
3070 */
3071 if ((pmb->u.mb.mbxCommand == MBX_UNREG_LOGIN) &&
3072 (phba->sli_rev == LPFC_SLI_REV4))
3073 lpfc_sli4_free_rpi(phba, pmb->u.mb.un.varUnregLogin.rpi);
3074
James Smart858c9f62007-06-17 19:56:39 -05003075 pmb->context1 = NULL;
3076 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3077 kfree(mp);
3078 mempool_free(pmb, phba->mbox_mem_pool);
James Smart58da1ff2008-04-07 10:15:56 -04003079 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smarta8adb832007-10-27 13:37:53 -04003080 lpfc_nlp_put(ndlp);
James Smarta8adb832007-10-27 13:37:53 -04003081 /* This is the end of the default RPI cleanup logic for this
3082 * ndlp. If no other discovery threads are using this ndlp.
3083 * we should free all resources associated with it.
3084 */
3085 lpfc_nlp_not_used(ndlp);
3086 }
James Smart3772a992009-05-22 14:50:54 -04003087
James Smart858c9f62007-06-17 19:56:39 -05003088 return;
3089}
3090
James Smarte59058c2008-08-24 21:49:00 -04003091/**
James Smart3621a712009-04-06 18:47:14 -04003092 * lpfc_cmpl_els_rsp - Completion callback function for els response iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003093 * @phba: pointer to lpfc hba data structure.
3094 * @cmdiocb: pointer to lpfc command iocb data structure.
3095 * @rspiocb: pointer to lpfc response iocb data structure.
3096 *
3097 * This routine is the completion callback function for ELS Response IOCB
3098 * command. In normal case, this callback function just properly sets the
3099 * nlp_flag bitmap in the ndlp data structure, if the mbox command reference
3100 * field in the command IOCB is not NULL, the referred mailbox command will
3101 * be send out, and then invokes the lpfc_els_free_iocb() routine to release
3102 * the IOCB. Under error conditions, such as when a LS_RJT is returned or a
3103 * link down event occurred during the discovery, the lpfc_nlp_not_used()
3104 * routine shall be invoked trying to release the ndlp if no other threads
3105 * are currently referring it.
3106 **/
dea31012005-04-17 16:05:31 -05003107static void
James Smart858c9f62007-06-17 19:56:39 -05003108lpfc_cmpl_els_rsp(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
James Smart329f9bc2007-04-25 09:53:01 -04003109 struct lpfc_iocbq *rspiocb)
dea31012005-04-17 16:05:31 -05003110{
James Smart2e0fef82007-06-17 19:56:36 -05003111 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
3112 struct lpfc_vport *vport = ndlp ? ndlp->vport : NULL;
3113 struct Scsi_Host *shost = vport ? lpfc_shost_from_vport(vport) : NULL;
James Smart87af33f2007-10-27 13:37:43 -04003114 IOCB_t *irsp;
3115 uint8_t *pcmd;
dea31012005-04-17 16:05:31 -05003116 LPFC_MBOXQ_t *mbox = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05003117 struct lpfc_dmabuf *mp = NULL;
James Smart87af33f2007-10-27 13:37:43 -04003118 uint32_t ls_rjt = 0;
dea31012005-04-17 16:05:31 -05003119
James Smart33ccf8d2006-08-17 11:57:58 -04003120 irsp = &rspiocb->iocb;
3121
dea31012005-04-17 16:05:31 -05003122 if (cmdiocb->context_un.mbox)
3123 mbox = cmdiocb->context_un.mbox;
3124
James Smartfa4066b2008-01-11 01:53:27 -05003125 /* First determine if this is a LS_RJT cmpl. Note, this callback
3126 * function can have cmdiocb->contest1 (ndlp) field set to NULL.
3127 */
James Smart87af33f2007-10-27 13:37:43 -04003128 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) cmdiocb->context2)->virt);
James Smart58da1ff2008-04-07 10:15:56 -04003129 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3130 (*((uint32_t *) (pcmd)) == ELS_CMD_LS_RJT)) {
James Smartfa4066b2008-01-11 01:53:27 -05003131 /* A LS_RJT associated with Default RPI cleanup has its own
3132 * seperate code path.
James Smart87af33f2007-10-27 13:37:43 -04003133 */
3134 if (!(ndlp->nlp_flag & NLP_RM_DFLT_RPI))
3135 ls_rjt = 1;
3136 }
3137
dea31012005-04-17 16:05:31 -05003138 /* Check to see if link went down during discovery */
James Smart58da1ff2008-04-07 10:15:56 -04003139 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp) || lpfc_els_chk_latt(vport)) {
dea31012005-04-17 16:05:31 -05003140 if (mbox) {
James Smart14691152006-12-02 13:34:28 -05003141 mp = (struct lpfc_dmabuf *) mbox->context1;
3142 if (mp) {
3143 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3144 kfree(mp);
3145 }
James Smart329f9bc2007-04-25 09:53:01 -04003146 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003147 }
James Smart58da1ff2008-04-07 10:15:56 -04003148 if (ndlp && NLP_CHK_NODE_ACT(ndlp) &&
3149 (ndlp->nlp_flag & NLP_RM_DFLT_RPI))
James Smartfa4066b2008-01-11 01:53:27 -05003150 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003151 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003152 /* Indicate the node has already released,
3153 * should not reference to it from within
3154 * the routine lpfc_els_free_iocb.
3155 */
3156 cmdiocb->context1 = NULL;
3157 }
dea31012005-04-17 16:05:31 -05003158 goto out;
3159 }
3160
James Smart858c9f62007-06-17 19:56:39 -05003161 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
James Smart51ef4c22007-08-02 11:10:31 -04003162 "ELS rsp cmpl: status:x%x/x%x did:x%x",
James Smart858c9f62007-06-17 19:56:39 -05003163 irsp->ulpStatus, irsp->un.ulpWord[4],
James Smart51ef4c22007-08-02 11:10:31 -04003164 cmdiocb->iocb.un.elsreq64.remoteID);
dea31012005-04-17 16:05:31 -05003165 /* ELS response tag <ulpIoTag> completes */
James Smarte8b62012007-08-02 11:10:09 -04003166 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3167 "0110 ELS response tag x%x completes "
3168 "Data: x%x x%x x%x x%x x%x x%x x%x\n",
3169 cmdiocb->iocb.ulpIoTag, rspiocb->iocb.ulpStatus,
3170 rspiocb->iocb.un.ulpWord[4], rspiocb->iocb.ulpTimeout,
3171 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3172 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003173 if (mbox) {
3174 if ((rspiocb->iocb.ulpStatus == 0)
3175 && (ndlp->nlp_flag & NLP_ACC_REGLOGIN)) {
James Smart2e0fef82007-06-17 19:56:36 -05003176 lpfc_unreg_rpi(vport, ndlp);
James Smarte47c9092008-02-08 18:49:26 -05003177 /* Increment reference count to ndlp to hold the
3178 * reference to ndlp for the callback function.
3179 */
James Smart329f9bc2007-04-25 09:53:01 -04003180 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05003181 mbox->vport = vport;
James Smart858c9f62007-06-17 19:56:39 -05003182 if (ndlp->nlp_flag & NLP_RM_DFLT_RPI) {
3183 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
3184 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
3185 }
3186 else {
3187 mbox->mbox_cmpl = lpfc_mbx_cmpl_reg_login;
3188 ndlp->nlp_prev_state = ndlp->nlp_state;
3189 lpfc_nlp_set_state(vport, ndlp,
James Smart2e0fef82007-06-17 19:56:36 -05003190 NLP_STE_REG_LOGIN_ISSUE);
James Smart858c9f62007-06-17 19:56:39 -05003191 }
James Smart0b727fe2007-10-27 13:37:25 -04003192 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smarte47c9092008-02-08 18:49:26 -05003193 != MBX_NOT_FINISHED)
dea31012005-04-17 16:05:31 -05003194 goto out;
James Smarte47c9092008-02-08 18:49:26 -05003195 else
3196 /* Decrement the ndlp reference count we
3197 * set for this failed mailbox command.
3198 */
3199 lpfc_nlp_put(ndlp);
James Smart98c9ea52007-10-27 13:37:33 -04003200
3201 /* ELS rsp: Cannot issue reg_login for <NPortid> */
3202 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3203 "0138 ELS rsp: Cannot issue reg_login for x%x "
3204 "Data: x%x x%x x%x\n",
3205 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3206 ndlp->nlp_rpi);
3207
James Smartfa4066b2008-01-11 01:53:27 -05003208 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003209 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003210 /* Indicate node has already been released,
3211 * should not reference to it from within
3212 * the routine lpfc_els_free_iocb.
3213 */
3214 cmdiocb->context1 = NULL;
3215 }
dea31012005-04-17 16:05:31 -05003216 } else {
James Smart858c9f62007-06-17 19:56:39 -05003217 /* Do not drop node for lpfc_els_abort'ed ELS cmds */
3218 if (!lpfc_error_lost_link(irsp) &&
3219 ndlp->nlp_flag & NLP_ACC_REGLOGIN) {
James Smartfa4066b2008-01-11 01:53:27 -05003220 if (lpfc_nlp_not_used(ndlp)) {
James Smart98c9ea52007-10-27 13:37:33 -04003221 ndlp = NULL;
James Smartfa4066b2008-01-11 01:53:27 -05003222 /* Indicate node has already been
3223 * released, should not reference
3224 * to it from within the routine
3225 * lpfc_els_free_iocb.
3226 */
3227 cmdiocb->context1 = NULL;
3228 }
dea31012005-04-17 16:05:31 -05003229 }
3230 }
James Smart14691152006-12-02 13:34:28 -05003231 mp = (struct lpfc_dmabuf *) mbox->context1;
3232 if (mp) {
3233 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3234 kfree(mp);
3235 }
3236 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003237 }
3238out:
James Smart58da1ff2008-04-07 10:15:56 -04003239 if (ndlp && NLP_CHK_NODE_ACT(ndlp)) {
James Smart2e0fef82007-06-17 19:56:36 -05003240 spin_lock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05003241 ndlp->nlp_flag &= ~(NLP_ACC_REGLOGIN | NLP_RM_DFLT_RPI);
James Smart2e0fef82007-06-17 19:56:36 -05003242 spin_unlock_irq(shost->host_lock);
James Smart87af33f2007-10-27 13:37:43 -04003243
3244 /* If the node is not being used by another discovery thread,
3245 * and we are sending a reject, we are done with it.
3246 * Release driver reference count here and free associated
3247 * resources.
3248 */
3249 if (ls_rjt)
James Smartfa4066b2008-01-11 01:53:27 -05003250 if (lpfc_nlp_not_used(ndlp))
3251 /* Indicate node has already been released,
3252 * should not reference to it from within
3253 * the routine lpfc_els_free_iocb.
3254 */
3255 cmdiocb->context1 = NULL;
dea31012005-04-17 16:05:31 -05003256 }
James Smart87af33f2007-10-27 13:37:43 -04003257
dea31012005-04-17 16:05:31 -05003258 lpfc_els_free_iocb(phba, cmdiocb);
3259 return;
3260}
3261
James Smarte59058c2008-08-24 21:49:00 -04003262/**
James Smart3621a712009-04-06 18:47:14 -04003263 * lpfc_els_rsp_acc - Prepare and issue an acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003264 * @vport: pointer to a host virtual N_Port data structure.
3265 * @flag: the els command code to be accepted.
3266 * @oldiocb: pointer to the original lpfc command iocb data structure.
3267 * @ndlp: pointer to a node-list data structure.
3268 * @mbox: pointer to the driver internal queue element for mailbox command.
3269 *
3270 * This routine prepares and issues an Accept (ACC) response IOCB
3271 * command. It uses the @flag to properly set up the IOCB field for the
3272 * specific ACC response command to be issued and invokes the
3273 * lpfc_sli_issue_iocb() routine to send out ACC response IOCB. If a
3274 * @mbox pointer is passed in, it will be put into the context_un.mbox
3275 * field of the IOCB for the completion callback function to issue the
3276 * mailbox command to the HBA later when callback is invoked.
3277 *
3278 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3279 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3280 * will be stored into the context1 field of the IOCB for the completion
3281 * callback function to the corresponding response ELS IOCB command.
3282 *
3283 * Return code
3284 * 0 - Successfully issued acc response
3285 * 1 - Failed to issue acc response
3286 **/
dea31012005-04-17 16:05:31 -05003287int
James Smart2e0fef82007-06-17 19:56:36 -05003288lpfc_els_rsp_acc(struct lpfc_vport *vport, uint32_t flag,
3289 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
James Smart51ef4c22007-08-02 11:10:31 -04003290 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003291{
James Smart2e0fef82007-06-17 19:56:36 -05003292 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3293 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003294 IOCB_t *icmd;
3295 IOCB_t *oldcmd;
3296 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003297 struct lpfc_sli *psli;
3298 uint8_t *pcmd;
3299 uint16_t cmdsize;
3300 int rc;
James Smart82d9a2a2006-04-15 11:53:05 -04003301 ELS_PKT *els_pkt_ptr;
dea31012005-04-17 16:05:31 -05003302
3303 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05003304 oldcmd = &oldiocb->iocb;
3305
3306 switch (flag) {
3307 case ELS_CMD_ACC:
James Smart92d7f7b2007-06-17 19:56:38 -05003308 cmdsize = sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003309 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3310 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003311 if (!elsiocb) {
James Smart2e0fef82007-06-17 19:56:36 -05003312 spin_lock_irq(shost->host_lock);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05003313 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003314 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003315 return 1;
dea31012005-04-17 16:05:31 -05003316 }
James Smart2e0fef82007-06-17 19:56:36 -05003317
dea31012005-04-17 16:05:31 -05003318 icmd = &elsiocb->iocb;
3319 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3320 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3321 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003322 pcmd += sizeof(uint32_t);
James Smart858c9f62007-06-17 19:56:39 -05003323
3324 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3325 "Issue ACC: did:x%x flg:x%x",
3326 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003327 break;
3328 case ELS_CMD_PLOGI:
James Smart92d7f7b2007-06-17 19:56:38 -05003329 cmdsize = (sizeof(struct serv_parm) + sizeof(uint32_t));
James Smart2e0fef82007-06-17 19:56:36 -05003330 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
3331 ndlp, ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003332 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003333 return 1;
James Smart488d1462006-03-07 15:02:37 -05003334
dea31012005-04-17 16:05:31 -05003335 icmd = &elsiocb->iocb;
3336 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3337 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3338
3339 if (mbox)
3340 elsiocb->context_un.mbox = mbox;
3341
3342 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003343 pcmd += sizeof(uint32_t);
3344 memcpy(pcmd, &vport->fc_sparam, sizeof(struct serv_parm));
James Smart858c9f62007-06-17 19:56:39 -05003345
3346 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3347 "Issue ACC PLOGI: did:x%x flg:x%x",
3348 ndlp->nlp_DID, ndlp->nlp_flag, 0);
dea31012005-04-17 16:05:31 -05003349 break;
James Smart82d9a2a2006-04-15 11:53:05 -04003350 case ELS_CMD_PRLO:
James Smart92d7f7b2007-06-17 19:56:38 -05003351 cmdsize = sizeof(uint32_t) + sizeof(PRLO);
James Smart2e0fef82007-06-17 19:56:36 -05003352 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry,
James Smart82d9a2a2006-04-15 11:53:05 -04003353 ndlp, ndlp->nlp_DID, ELS_CMD_PRLO);
3354 if (!elsiocb)
3355 return 1;
3356
3357 icmd = &elsiocb->iocb;
3358 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3359 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3360
3361 memcpy(pcmd, ((struct lpfc_dmabuf *) oldiocb->context2)->virt,
James Smart92d7f7b2007-06-17 19:56:38 -05003362 sizeof(uint32_t) + sizeof(PRLO));
James Smart82d9a2a2006-04-15 11:53:05 -04003363 *((uint32_t *) (pcmd)) = ELS_CMD_PRLO_ACC;
3364 els_pkt_ptr = (ELS_PKT *) pcmd;
3365 els_pkt_ptr->un.prlo.acceptRspCode = PRLO_REQ_EXECUTED;
James Smart858c9f62007-06-17 19:56:39 -05003366
3367 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3368 "Issue ACC PRLO: did:x%x flg:x%x",
3369 ndlp->nlp_DID, ndlp->nlp_flag, 0);
James Smart82d9a2a2006-04-15 11:53:05 -04003370 break;
dea31012005-04-17 16:05:31 -05003371 default:
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003372 return 1;
dea31012005-04-17 16:05:31 -05003373 }
dea31012005-04-17 16:05:31 -05003374 /* Xmit ELS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003375 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3376 "0128 Xmit ELS ACC response tag x%x, XRI: x%x, "
3377 "DID: x%x, nlp_flag: x%x nlp_state: x%x RPI: x%x\n",
3378 elsiocb->iotag, elsiocb->iocb.ulpContext,
3379 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3380 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003381 if (ndlp->nlp_flag & NLP_LOGO_ACC) {
James Smart2e0fef82007-06-17 19:56:36 -05003382 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003383 ndlp->nlp_flag &= ~NLP_LOGO_ACC;
James Smart2e0fef82007-06-17 19:56:36 -05003384 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003385 elsiocb->iocb_cmpl = lpfc_cmpl_els_logo_acc;
3386 } else {
James Smart858c9f62007-06-17 19:56:39 -05003387 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05003388 }
3389
3390 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04003391 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003392 if (rc == IOCB_ERROR) {
3393 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003394 return 1;
dea31012005-04-17 16:05:31 -05003395 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003396 return 0;
dea31012005-04-17 16:05:31 -05003397}
3398
James Smarte59058c2008-08-24 21:49:00 -04003399/**
James Smart3621a712009-04-06 18:47:14 -04003400 * lpfc_els_rsp_reject - Propare and issue a rjt response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003401 * @vport: pointer to a virtual N_Port data structure.
3402 * @rejectError:
3403 * @oldiocb: pointer to the original lpfc command iocb data structure.
3404 * @ndlp: pointer to a node-list data structure.
3405 * @mbox: pointer to the driver internal queue element for mailbox command.
3406 *
3407 * This routine prepares and issue an Reject (RJT) response IOCB
3408 * command. If a @mbox pointer is passed in, it will be put into the
3409 * context_un.mbox field of the IOCB for the completion callback function
3410 * to issue to the HBA later.
3411 *
3412 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3413 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3414 * will be stored into the context1 field of the IOCB for the completion
3415 * callback function to the reject response ELS IOCB command.
3416 *
3417 * Return code
3418 * 0 - Successfully issued reject response
3419 * 1 - Failed to issue reject response
3420 **/
dea31012005-04-17 16:05:31 -05003421int
James Smart2e0fef82007-06-17 19:56:36 -05003422lpfc_els_rsp_reject(struct lpfc_vport *vport, uint32_t rejectError,
James Smart858c9f62007-06-17 19:56:39 -05003423 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp,
3424 LPFC_MBOXQ_t *mbox)
dea31012005-04-17 16:05:31 -05003425{
James Smart2e0fef82007-06-17 19:56:36 -05003426 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003427 IOCB_t *icmd;
3428 IOCB_t *oldcmd;
3429 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003430 struct lpfc_sli *psli;
3431 uint8_t *pcmd;
3432 uint16_t cmdsize;
3433 int rc;
3434
3435 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05003436 cmdsize = 2 * sizeof(uint32_t);
James Smart2e0fef82007-06-17 19:56:36 -05003437 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3438 ndlp->nlp_DID, ELS_CMD_LS_RJT);
James Smart488d1462006-03-07 15:02:37 -05003439 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003440 return 1;
dea31012005-04-17 16:05:31 -05003441
3442 icmd = &elsiocb->iocb;
3443 oldcmd = &oldiocb->iocb;
3444 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
3445 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3446
3447 *((uint32_t *) (pcmd)) = ELS_CMD_LS_RJT;
James Smart92d7f7b2007-06-17 19:56:38 -05003448 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003449 *((uint32_t *) (pcmd)) = rejectError;
3450
James Smart51ef4c22007-08-02 11:10:31 -04003451 if (mbox)
James Smart858c9f62007-06-17 19:56:39 -05003452 elsiocb->context_un.mbox = mbox;
James Smart858c9f62007-06-17 19:56:39 -05003453
dea31012005-04-17 16:05:31 -05003454 /* Xmit ELS RJT <err> response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003455 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3456 "0129 Xmit ELS RJT x%x response tag x%x "
3457 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
3458 "rpi x%x\n",
3459 rejectError, elsiocb->iotag,
3460 elsiocb->iocb.ulpContext, ndlp->nlp_DID,
3461 ndlp->nlp_flag, ndlp->nlp_state, ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05003462 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3463 "Issue LS_RJT: did:x%x flg:x%x err:x%x",
3464 ndlp->nlp_DID, ndlp->nlp_flag, rejectError);
3465
dea31012005-04-17 16:05:31 -05003466 phba->fc_stat.elsXmitLSRJT++;
James Smart858c9f62007-06-17 19:56:39 -05003467 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04003468 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
James Smart51ef4c22007-08-02 11:10:31 -04003469
dea31012005-04-17 16:05:31 -05003470 if (rc == IOCB_ERROR) {
3471 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003472 return 1;
dea31012005-04-17 16:05:31 -05003473 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003474 return 0;
dea31012005-04-17 16:05:31 -05003475}
3476
James Smarte59058c2008-08-24 21:49:00 -04003477/**
James Smart3621a712009-04-06 18:47:14 -04003478 * lpfc_els_rsp_adisc_acc - Prepare and issue acc response to adisc iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003479 * @vport: pointer to a virtual N_Port data structure.
3480 * @oldiocb: pointer to the original lpfc command iocb data structure.
3481 * @ndlp: pointer to a node-list data structure.
3482 *
3483 * This routine prepares and issues an Accept (ACC) response to Address
3484 * Discover (ADISC) ELS command. It simply prepares the payload of the IOCB
3485 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3486 *
3487 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3488 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3489 * will be stored into the context1 field of the IOCB for the completion
3490 * callback function to the ADISC Accept response ELS IOCB command.
3491 *
3492 * Return code
3493 * 0 - Successfully issued acc adisc response
3494 * 1 - Failed to issue adisc acc response
3495 **/
dea31012005-04-17 16:05:31 -05003496int
James Smart2e0fef82007-06-17 19:56:36 -05003497lpfc_els_rsp_adisc_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
3498 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003499{
James Smart2e0fef82007-06-17 19:56:36 -05003500 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003501 ADISC *ap;
James Smart2e0fef82007-06-17 19:56:36 -05003502 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05003503 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003504 uint8_t *pcmd;
3505 uint16_t cmdsize;
3506 int rc;
3507
James Smart92d7f7b2007-06-17 19:56:38 -05003508 cmdsize = sizeof(uint32_t) + sizeof(ADISC);
James Smart2e0fef82007-06-17 19:56:36 -05003509 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3510 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003511 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003512 return 1;
dea31012005-04-17 16:05:31 -05003513
dea31012005-04-17 16:05:31 -05003514 icmd = &elsiocb->iocb;
3515 oldcmd = &oldiocb->iocb;
3516 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04003517
3518 /* Xmit ADISC ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003519 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3520 "0130 Xmit ADISC ACC response iotag x%x xri: "
3521 "x%x, did x%x, nlp_flag x%x, nlp_state x%x rpi x%x\n",
3522 elsiocb->iotag, elsiocb->iocb.ulpContext,
3523 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3524 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003525 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3526
3527 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003528 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003529
3530 ap = (ADISC *) (pcmd);
3531 ap->hardAL_PA = phba->fc_pref_ALPA;
James Smart92d7f7b2007-06-17 19:56:38 -05003532 memcpy(&ap->portName, &vport->fc_portname, sizeof(struct lpfc_name));
3533 memcpy(&ap->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -05003534 ap->DID = be32_to_cpu(vport->fc_myDID);
dea31012005-04-17 16:05:31 -05003535
James Smart858c9f62007-06-17 19:56:39 -05003536 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3537 "Issue ACC ADISC: did:x%x flg:x%x",
3538 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3539
dea31012005-04-17 16:05:31 -05003540 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003541 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart3772a992009-05-22 14:50:54 -04003542 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003543 if (rc == IOCB_ERROR) {
3544 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003545 return 1;
dea31012005-04-17 16:05:31 -05003546 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003547 return 0;
dea31012005-04-17 16:05:31 -05003548}
3549
James Smarte59058c2008-08-24 21:49:00 -04003550/**
James Smart3621a712009-04-06 18:47:14 -04003551 * lpfc_els_rsp_prli_acc - Prepare and issue acc response to prli iocb cmd
James Smarte59058c2008-08-24 21:49:00 -04003552 * @vport: pointer to a virtual N_Port data structure.
3553 * @oldiocb: pointer to the original lpfc command iocb data structure.
3554 * @ndlp: pointer to a node-list data structure.
3555 *
3556 * This routine prepares and issues an Accept (ACC) response to Process
3557 * Login (PRLI) ELS command. It simply prepares the payload of the IOCB
3558 * and invokes the lpfc_sli_issue_iocb() routine to send out the command.
3559 *
3560 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3561 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3562 * will be stored into the context1 field of the IOCB for the completion
3563 * callback function to the PRLI Accept response ELS IOCB command.
3564 *
3565 * Return code
3566 * 0 - Successfully issued acc prli response
3567 * 1 - Failed to issue acc prli response
3568 **/
dea31012005-04-17 16:05:31 -05003569int
James Smart2e0fef82007-06-17 19:56:36 -05003570lpfc_els_rsp_prli_acc(struct lpfc_vport *vport, struct lpfc_iocbq *oldiocb,
James Smart5b8bd0c2007-04-25 09:52:49 -04003571 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003572{
James Smart2e0fef82007-06-17 19:56:36 -05003573 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003574 PRLI *npr;
3575 lpfc_vpd_t *vpd;
3576 IOCB_t *icmd;
3577 IOCB_t *oldcmd;
3578 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003579 struct lpfc_sli *psli;
3580 uint8_t *pcmd;
3581 uint16_t cmdsize;
3582 int rc;
3583
3584 psli = &phba->sli;
dea31012005-04-17 16:05:31 -05003585
James Smart92d7f7b2007-06-17 19:56:38 -05003586 cmdsize = sizeof(uint32_t) + sizeof(PRLI);
James Smart2e0fef82007-06-17 19:56:36 -05003587 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
James Smart92d7f7b2007-06-17 19:56:38 -05003588 ndlp->nlp_DID, (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK)));
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003589 if (!elsiocb)
3590 return 1;
dea31012005-04-17 16:05:31 -05003591
dea31012005-04-17 16:05:31 -05003592 icmd = &elsiocb->iocb;
3593 oldcmd = &oldiocb->iocb;
3594 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04003595 /* Xmit PRLI ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003596 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3597 "0131 Xmit PRLI ACC response tag x%x xri x%x, "
3598 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
3599 elsiocb->iotag, elsiocb->iocb.ulpContext,
3600 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
3601 ndlp->nlp_rpi);
dea31012005-04-17 16:05:31 -05003602 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
3603
3604 *((uint32_t *) (pcmd)) = (ELS_CMD_ACC | (ELS_CMD_PRLI & ~ELS_RSP_MASK));
James Smart92d7f7b2007-06-17 19:56:38 -05003605 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003606
3607 /* For PRLI, remainder of payload is PRLI parameter page */
James Smart92d7f7b2007-06-17 19:56:38 -05003608 memset(pcmd, 0, sizeof(PRLI));
dea31012005-04-17 16:05:31 -05003609
3610 npr = (PRLI *) pcmd;
3611 vpd = &phba->vpd;
3612 /*
James Smart0d2b6b82008-06-14 22:52:47 -04003613 * If the remote port is a target and our firmware version is 3.20 or
3614 * later, set the following bits for FC-TAPE support.
dea31012005-04-17 16:05:31 -05003615 */
James Smart0d2b6b82008-06-14 22:52:47 -04003616 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
3617 (vpd->rev.feaLevelHigh >= 0x02)) {
dea31012005-04-17 16:05:31 -05003618 npr->ConfmComplAllowed = 1;
3619 npr->Retry = 1;
3620 npr->TaskRetryIdReq = 1;
3621 }
3622
3623 npr->acceptRspCode = PRLI_REQ_EXECUTED;
3624 npr->estabImagePair = 1;
3625 npr->readXferRdyDis = 1;
3626 npr->ConfmComplAllowed = 1;
3627
3628 npr->prliType = PRLI_FCP_TYPE;
3629 npr->initiatorFunc = 1;
3630
James Smart858c9f62007-06-17 19:56:39 -05003631 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3632 "Issue ACC PRLI: did:x%x flg:x%x",
3633 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3634
dea31012005-04-17 16:05:31 -05003635 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003636 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
dea31012005-04-17 16:05:31 -05003637
James Smart3772a992009-05-22 14:50:54 -04003638 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003639 if (rc == IOCB_ERROR) {
3640 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003641 return 1;
dea31012005-04-17 16:05:31 -05003642 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003643 return 0;
dea31012005-04-17 16:05:31 -05003644}
3645
James Smarte59058c2008-08-24 21:49:00 -04003646/**
James Smart3621a712009-04-06 18:47:14 -04003647 * lpfc_els_rsp_rnid_acc - Issue rnid acc response iocb command
James Smarte59058c2008-08-24 21:49:00 -04003648 * @vport: pointer to a virtual N_Port data structure.
3649 * @format: rnid command format.
3650 * @oldiocb: pointer to the original lpfc command iocb data structure.
3651 * @ndlp: pointer to a node-list data structure.
3652 *
3653 * This routine issues a Request Node Identification Data (RNID) Accept
3654 * (ACC) response. It constructs the RNID ACC response command according to
3655 * the proper @format and then calls the lpfc_sli_issue_iocb() routine to
3656 * issue the response. Note that this command does not need to hold the ndlp
3657 * reference count for the callback. So, the ndlp reference count taken by
3658 * the lpfc_prep_els_iocb() routine is put back and the context1 field of
3659 * IOCB is set to NULL to indicate to the lpfc_els_free_iocb() routine that
3660 * there is no ndlp reference available.
3661 *
3662 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
3663 * will be incremented by 1 for holding the ndlp and the reference to ndlp
3664 * will be stored into the context1 field of the IOCB for the completion
3665 * callback function. However, for the RNID Accept Response ELS command,
3666 * this is undone later by this routine after the IOCB is allocated.
3667 *
3668 * Return code
3669 * 0 - Successfully issued acc rnid response
3670 * 1 - Failed to issue acc rnid response
3671 **/
dea31012005-04-17 16:05:31 -05003672static int
James Smart2e0fef82007-06-17 19:56:36 -05003673lpfc_els_rsp_rnid_acc(struct lpfc_vport *vport, uint8_t format,
James Smart329f9bc2007-04-25 09:53:01 -04003674 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003675{
James Smart2e0fef82007-06-17 19:56:36 -05003676 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003677 RNID *rn;
James Smart2e0fef82007-06-17 19:56:36 -05003678 IOCB_t *icmd, *oldcmd;
dea31012005-04-17 16:05:31 -05003679 struct lpfc_iocbq *elsiocb;
dea31012005-04-17 16:05:31 -05003680 struct lpfc_sli *psli;
3681 uint8_t *pcmd;
3682 uint16_t cmdsize;
3683 int rc;
3684
3685 psli = &phba->sli;
James Smart92d7f7b2007-06-17 19:56:38 -05003686 cmdsize = sizeof(uint32_t) + sizeof(uint32_t)
3687 + (2 * sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003688 if (format)
James Smart92d7f7b2007-06-17 19:56:38 -05003689 cmdsize += sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05003690
James Smart2e0fef82007-06-17 19:56:36 -05003691 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
3692 ndlp->nlp_DID, ELS_CMD_ACC);
James Smart488d1462006-03-07 15:02:37 -05003693 if (!elsiocb)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003694 return 1;
dea31012005-04-17 16:05:31 -05003695
dea31012005-04-17 16:05:31 -05003696 icmd = &elsiocb->iocb;
3697 oldcmd = &oldiocb->iocb;
3698 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
James Smart5b8bd0c2007-04-25 09:52:49 -04003699 /* Xmit RNID ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04003700 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
3701 "0132 Xmit RNID ACC response tag x%x xri x%x\n",
3702 elsiocb->iotag, elsiocb->iocb.ulpContext);
dea31012005-04-17 16:05:31 -05003703 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
dea31012005-04-17 16:05:31 -05003704 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05003705 pcmd += sizeof(uint32_t);
dea31012005-04-17 16:05:31 -05003706
James Smart92d7f7b2007-06-17 19:56:38 -05003707 memset(pcmd, 0, sizeof(RNID));
dea31012005-04-17 16:05:31 -05003708 rn = (RNID *) (pcmd);
3709 rn->Format = format;
James Smart92d7f7b2007-06-17 19:56:38 -05003710 rn->CommonLen = (2 * sizeof(struct lpfc_name));
3711 memcpy(&rn->portName, &vport->fc_portname, sizeof(struct lpfc_name));
3712 memcpy(&rn->nodeName, &vport->fc_nodename, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003713 switch (format) {
3714 case 0:
3715 rn->SpecificLen = 0;
3716 break;
3717 case RNID_TOPOLOGY_DISC:
James Smart92d7f7b2007-06-17 19:56:38 -05003718 rn->SpecificLen = sizeof(RNID_TOP_DISC);
dea31012005-04-17 16:05:31 -05003719 memcpy(&rn->un.topologyDisc.portName,
James Smart92d7f7b2007-06-17 19:56:38 -05003720 &vport->fc_portname, sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05003721 rn->un.topologyDisc.unitType = RNID_HBA;
3722 rn->un.topologyDisc.physPort = 0;
3723 rn->un.topologyDisc.attachedNodes = 0;
3724 break;
3725 default:
3726 rn->CommonLen = 0;
3727 rn->SpecificLen = 0;
3728 break;
3729 }
3730
James Smart858c9f62007-06-17 19:56:39 -05003731 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_RSP,
3732 "Issue ACC RNID: did:x%x flg:x%x",
3733 ndlp->nlp_DID, ndlp->nlp_flag, 0);
3734
dea31012005-04-17 16:05:31 -05003735 phba->fc_stat.elsXmitACC++;
James Smart858c9f62007-06-17 19:56:39 -05003736 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
James Smart329f9bc2007-04-25 09:53:01 -04003737 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05003738 elsiocb->context1 = NULL; /* Don't need ndlp for cmpl,
3739 * it could be freed */
3740
James Smart3772a992009-05-22 14:50:54 -04003741 rc = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0);
dea31012005-04-17 16:05:31 -05003742 if (rc == IOCB_ERROR) {
3743 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003744 return 1;
dea31012005-04-17 16:05:31 -05003745 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003746 return 0;
dea31012005-04-17 16:05:31 -05003747}
3748
James Smarte59058c2008-08-24 21:49:00 -04003749/**
James Smart3621a712009-04-06 18:47:14 -04003750 * lpfc_els_disc_adisc - Issue remaining adisc iocbs to npr nodes of a vport
James Smarte59058c2008-08-24 21:49:00 -04003751 * @vport: pointer to a host virtual N_Port data structure.
3752 *
3753 * This routine issues Address Discover (ADISC) ELS commands to those
3754 * N_Ports which are in node port recovery state and ADISC has not been issued
3755 * for the @vport. Each time an ELS ADISC IOCB is issued by invoking the
3756 * lpfc_issue_els_adisc() routine, the per @vport number of discover count
3757 * (num_disc_nodes) shall be incremented. If the num_disc_nodes reaches a
3758 * pre-configured threshold (cfg_discovery_threads), the @vport fc_flag will
3759 * be marked with FC_NLP_MORE bit and the process of issuing remaining ADISC
3760 * IOCBs quit for later pick up. On the other hand, after walking through
3761 * all the ndlps with the @vport and there is none ADISC IOCB issued, the
3762 * @vport fc_flag shall be cleared with FC_NLP_MORE bit indicating there is
3763 * no more ADISC need to be sent.
3764 *
3765 * Return code
3766 * The number of N_Ports with adisc issued.
3767 **/
dea31012005-04-17 16:05:31 -05003768int
James Smart2e0fef82007-06-17 19:56:36 -05003769lpfc_els_disc_adisc(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003770{
James Smart2e0fef82007-06-17 19:56:36 -05003771 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05003772 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05003773 int sentadisc = 0;
dea31012005-04-17 16:05:31 -05003774
James Smart685f0bf2007-04-25 09:53:08 -04003775 /* go thru NPR nodes and issue any remaining ELS ADISCs */
James Smart2e0fef82007-06-17 19:56:36 -05003776 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05003777 if (!NLP_CHK_NODE_ACT(ndlp))
3778 continue;
James Smart685f0bf2007-04-25 09:53:08 -04003779 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
3780 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
3781 (ndlp->nlp_flag & NLP_NPR_ADISC) != 0) {
James Smart2e0fef82007-06-17 19:56:36 -05003782 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003783 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05003784 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003785 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003786 lpfc_nlp_set_state(vport, ndlp, NLP_STE_ADISC_ISSUE);
3787 lpfc_issue_els_adisc(vport, ndlp, 0);
James Smart685f0bf2007-04-25 09:53:08 -04003788 sentadisc++;
James Smart2e0fef82007-06-17 19:56:36 -05003789 vport->num_disc_nodes++;
3790 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04003791 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05003792 spin_lock_irq(shost->host_lock);
3793 vport->fc_flag |= FC_NLP_MORE;
3794 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003795 break;
dea31012005-04-17 16:05:31 -05003796 }
3797 }
3798 }
3799 if (sentadisc == 0) {
James Smart2e0fef82007-06-17 19:56:36 -05003800 spin_lock_irq(shost->host_lock);
3801 vport->fc_flag &= ~FC_NLP_MORE;
3802 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003803 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003804 return sentadisc;
dea31012005-04-17 16:05:31 -05003805}
3806
James Smarte59058c2008-08-24 21:49:00 -04003807/**
James Smart3621a712009-04-06 18:47:14 -04003808 * lpfc_els_disc_plogi - Issue plogi for all npr nodes of a vport before adisc
James Smarte59058c2008-08-24 21:49:00 -04003809 * @vport: pointer to a host virtual N_Port data structure.
3810 *
3811 * This routine issues Port Login (PLOGI) ELS commands to all the N_Ports
3812 * which are in node port recovery state, with a @vport. Each time an ELS
3813 * ADISC PLOGI IOCB is issued by invoking the lpfc_issue_els_plogi() routine,
3814 * the per @vport number of discover count (num_disc_nodes) shall be
3815 * incremented. If the num_disc_nodes reaches a pre-configured threshold
3816 * (cfg_discovery_threads), the @vport fc_flag will be marked with FC_NLP_MORE
3817 * bit set and quit the process of issuing remaining ADISC PLOGIN IOCBs for
3818 * later pick up. On the other hand, after walking through all the ndlps with
3819 * the @vport and there is none ADISC PLOGI IOCB issued, the @vport fc_flag
3820 * shall be cleared with the FC_NLP_MORE bit indicating there is no more ADISC
3821 * PLOGI need to be sent.
3822 *
3823 * Return code
3824 * The number of N_Ports with plogi issued.
3825 **/
dea31012005-04-17 16:05:31 -05003826int
James Smart2e0fef82007-06-17 19:56:36 -05003827lpfc_els_disc_plogi(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003828{
James Smart2e0fef82007-06-17 19:56:36 -05003829 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05003830 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05003831 int sentplogi = 0;
dea31012005-04-17 16:05:31 -05003832
James Smart2e0fef82007-06-17 19:56:36 -05003833 /* go thru NPR nodes and issue any remaining ELS PLOGIs */
3834 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05003835 if (!NLP_CHK_NODE_ACT(ndlp))
3836 continue;
James Smart685f0bf2007-04-25 09:53:08 -04003837 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
3838 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
3839 (ndlp->nlp_flag & NLP_DELAY_TMO) == 0 &&
3840 (ndlp->nlp_flag & NLP_NPR_ADISC) == 0) {
3841 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05003842 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
3843 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
James Smart685f0bf2007-04-25 09:53:08 -04003844 sentplogi++;
James Smart2e0fef82007-06-17 19:56:36 -05003845 vport->num_disc_nodes++;
3846 if (vport->num_disc_nodes >=
James Smart3de2a652007-08-02 11:09:59 -04003847 vport->cfg_discovery_threads) {
James Smart2e0fef82007-06-17 19:56:36 -05003848 spin_lock_irq(shost->host_lock);
3849 vport->fc_flag |= FC_NLP_MORE;
3850 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003851 break;
dea31012005-04-17 16:05:31 -05003852 }
3853 }
3854 }
James Smart87af33f2007-10-27 13:37:43 -04003855 if (sentplogi) {
3856 lpfc_set_disctmo(vport);
3857 }
3858 else {
James Smart2e0fef82007-06-17 19:56:36 -05003859 spin_lock_irq(shost->host_lock);
3860 vport->fc_flag &= ~FC_NLP_MORE;
3861 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003862 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003863 return sentplogi;
dea31012005-04-17 16:05:31 -05003864}
3865
James Smarte59058c2008-08-24 21:49:00 -04003866/**
James Smart3621a712009-04-06 18:47:14 -04003867 * lpfc_els_flush_rscn - Clean up any rscn activities with a vport
James Smarte59058c2008-08-24 21:49:00 -04003868 * @vport: pointer to a host virtual N_Port data structure.
3869 *
3870 * This routine cleans up any Registration State Change Notification
3871 * (RSCN) activity with a @vport. Note that the fc_rscn_flush flag of the
3872 * @vport together with the host_lock is used to prevent multiple thread
3873 * trying to access the RSCN array on a same @vport at the same time.
3874 **/
James Smart92d7f7b2007-06-17 19:56:38 -05003875void
James Smart2e0fef82007-06-17 19:56:36 -05003876lpfc_els_flush_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003877{
James Smart2e0fef82007-06-17 19:56:36 -05003878 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3879 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003880 int i;
3881
James Smart7f5f3d02008-02-08 18:50:14 -05003882 spin_lock_irq(shost->host_lock);
3883 if (vport->fc_rscn_flush) {
3884 /* Another thread is walking fc_rscn_id_list on this vport */
3885 spin_unlock_irq(shost->host_lock);
3886 return;
3887 }
3888 /* Indicate we are walking lpfc_els_flush_rscn on this vport */
3889 vport->fc_rscn_flush = 1;
3890 spin_unlock_irq(shost->host_lock);
3891
James Smart2e0fef82007-06-17 19:56:36 -05003892 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05003893 lpfc_in_buf_free(phba, vport->fc_rscn_id_list[i]);
James Smart2e0fef82007-06-17 19:56:36 -05003894 vport->fc_rscn_id_list[i] = NULL;
dea31012005-04-17 16:05:31 -05003895 }
James Smart2e0fef82007-06-17 19:56:36 -05003896 spin_lock_irq(shost->host_lock);
3897 vport->fc_rscn_id_cnt = 0;
3898 vport->fc_flag &= ~(FC_RSCN_MODE | FC_RSCN_DISCOVERY);
3899 spin_unlock_irq(shost->host_lock);
3900 lpfc_can_disctmo(vport);
James Smart7f5f3d02008-02-08 18:50:14 -05003901 /* Indicate we are done walking this fc_rscn_id_list */
3902 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05003903}
3904
James Smarte59058c2008-08-24 21:49:00 -04003905/**
James Smart3621a712009-04-06 18:47:14 -04003906 * lpfc_rscn_payload_check - Check whether there is a pending rscn to a did
James Smarte59058c2008-08-24 21:49:00 -04003907 * @vport: pointer to a host virtual N_Port data structure.
3908 * @did: remote destination port identifier.
3909 *
3910 * This routine checks whether there is any pending Registration State
3911 * Configuration Notification (RSCN) to a @did on @vport.
3912 *
3913 * Return code
3914 * None zero - The @did matched with a pending rscn
3915 * 0 - not able to match @did with a pending rscn
3916 **/
dea31012005-04-17 16:05:31 -05003917int
James Smart2e0fef82007-06-17 19:56:36 -05003918lpfc_rscn_payload_check(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05003919{
3920 D_ID ns_did;
3921 D_ID rscn_did;
dea31012005-04-17 16:05:31 -05003922 uint32_t *lp;
James Smart92d7f7b2007-06-17 19:56:38 -05003923 uint32_t payload_len, i;
James Smart7f5f3d02008-02-08 18:50:14 -05003924 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05003925
3926 ns_did.un.word = did;
dea31012005-04-17 16:05:31 -05003927
3928 /* Never match fabric nodes for RSCNs */
3929 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
James Smart2e0fef82007-06-17 19:56:36 -05003930 return 0;
dea31012005-04-17 16:05:31 -05003931
3932 /* If we are doing a FULL RSCN rediscovery, match everything */
James Smart2e0fef82007-06-17 19:56:36 -05003933 if (vport->fc_flag & FC_RSCN_DISCOVERY)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003934 return did;
dea31012005-04-17 16:05:31 -05003935
James Smart7f5f3d02008-02-08 18:50:14 -05003936 spin_lock_irq(shost->host_lock);
3937 if (vport->fc_rscn_flush) {
3938 /* Another thread is walking fc_rscn_id_list on this vport */
3939 spin_unlock_irq(shost->host_lock);
3940 return 0;
3941 }
3942 /* Indicate we are walking fc_rscn_id_list on this vport */
3943 vport->fc_rscn_flush = 1;
3944 spin_unlock_irq(shost->host_lock);
James Smart2e0fef82007-06-17 19:56:36 -05003945 for (i = 0; i < vport->fc_rscn_id_cnt; i++) {
James Smart92d7f7b2007-06-17 19:56:38 -05003946 lp = vport->fc_rscn_id_list[i]->virt;
3947 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
3948 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05003949 while (payload_len) {
James Smart92d7f7b2007-06-17 19:56:38 -05003950 rscn_did.un.word = be32_to_cpu(*lp++);
3951 payload_len -= sizeof(uint32_t);
James Smarteaf15d52008-12-04 22:39:29 -05003952 switch (rscn_did.un.b.resv & RSCN_ADDRESS_FORMAT_MASK) {
3953 case RSCN_ADDRESS_FORMAT_PORT:
James Smart6fb120a2009-05-22 14:52:59 -04003954 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
3955 && (ns_did.un.b.area == rscn_did.un.b.area)
3956 && (ns_did.un.b.id == rscn_did.un.b.id))
James Smart7f5f3d02008-02-08 18:50:14 -05003957 goto return_did_out;
dea31012005-04-17 16:05:31 -05003958 break;
James Smarteaf15d52008-12-04 22:39:29 -05003959 case RSCN_ADDRESS_FORMAT_AREA:
dea31012005-04-17 16:05:31 -05003960 if ((ns_did.un.b.domain == rscn_did.un.b.domain)
3961 && (ns_did.un.b.area == rscn_did.un.b.area))
James Smart7f5f3d02008-02-08 18:50:14 -05003962 goto return_did_out;
dea31012005-04-17 16:05:31 -05003963 break;
James Smarteaf15d52008-12-04 22:39:29 -05003964 case RSCN_ADDRESS_FORMAT_DOMAIN:
dea31012005-04-17 16:05:31 -05003965 if (ns_did.un.b.domain == rscn_did.un.b.domain)
James Smart7f5f3d02008-02-08 18:50:14 -05003966 goto return_did_out;
dea31012005-04-17 16:05:31 -05003967 break;
James Smarteaf15d52008-12-04 22:39:29 -05003968 case RSCN_ADDRESS_FORMAT_FABRIC:
James Smart7f5f3d02008-02-08 18:50:14 -05003969 goto return_did_out;
dea31012005-04-17 16:05:31 -05003970 }
3971 }
James Smart92d7f7b2007-06-17 19:56:38 -05003972 }
James Smart7f5f3d02008-02-08 18:50:14 -05003973 /* Indicate we are done with walking fc_rscn_id_list on this vport */
3974 vport->fc_rscn_flush = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05003975 return 0;
James Smart7f5f3d02008-02-08 18:50:14 -05003976return_did_out:
3977 /* Indicate we are done with walking fc_rscn_id_list on this vport */
3978 vport->fc_rscn_flush = 0;
3979 return did;
dea31012005-04-17 16:05:31 -05003980}
3981
James Smarte59058c2008-08-24 21:49:00 -04003982/**
James Smart3621a712009-04-06 18:47:14 -04003983 * lpfc_rscn_recovery_check - Send recovery event to vport nodes matching rscn
James Smarte59058c2008-08-24 21:49:00 -04003984 * @vport: pointer to a host virtual N_Port data structure.
3985 *
3986 * This routine sends recovery (NLP_EVT_DEVICE_RECOVERY) event to the
3987 * state machine for a @vport's nodes that are with pending RSCN (Registration
3988 * State Change Notification).
3989 *
3990 * Return code
3991 * 0 - Successful (currently alway return 0)
3992 **/
dea31012005-04-17 16:05:31 -05003993static int
James Smart2e0fef82007-06-17 19:56:36 -05003994lpfc_rscn_recovery_check(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003995{
James Smart685f0bf2007-04-25 09:53:08 -04003996 struct lpfc_nodelist *ndlp = NULL;
dea31012005-04-17 16:05:31 -05003997
James Smart0d2b6b82008-06-14 22:52:47 -04003998 /* Move all affected nodes by pending RSCNs to NPR state. */
James Smart2e0fef82007-06-17 19:56:36 -05003999 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004000 if (!NLP_CHK_NODE_ACT(ndlp) ||
James Smart0d2b6b82008-06-14 22:52:47 -04004001 (ndlp->nlp_state == NLP_STE_UNUSED_NODE) ||
4002 !lpfc_rscn_payload_check(vport, ndlp->nlp_DID))
dea31012005-04-17 16:05:31 -05004003 continue;
James Smart2e0fef82007-06-17 19:56:36 -05004004 lpfc_disc_state_machine(vport, ndlp, NULL,
James Smart0d2b6b82008-06-14 22:52:47 -04004005 NLP_EVT_DEVICE_RECOVERY);
4006 lpfc_cancel_retry_delay_tmo(vport, ndlp);
dea31012005-04-17 16:05:31 -05004007 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004008 return 0;
dea31012005-04-17 16:05:31 -05004009}
4010
James Smarte59058c2008-08-24 21:49:00 -04004011/**
James Smart3621a712009-04-06 18:47:14 -04004012 * lpfc_send_rscn_event - Send an RSCN event to management application
James Smartddcc50f2008-12-04 22:38:46 -05004013 * @vport: pointer to a host virtual N_Port data structure.
4014 * @cmdiocb: pointer to lpfc command iocb data structure.
4015 *
4016 * lpfc_send_rscn_event sends an RSCN netlink event to management
4017 * applications.
4018 */
4019static void
4020lpfc_send_rscn_event(struct lpfc_vport *vport,
4021 struct lpfc_iocbq *cmdiocb)
4022{
4023 struct lpfc_dmabuf *pcmd;
4024 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4025 uint32_t *payload_ptr;
4026 uint32_t payload_len;
4027 struct lpfc_rscn_event_header *rscn_event_data;
4028
4029 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4030 payload_ptr = (uint32_t *) pcmd->virt;
4031 payload_len = be32_to_cpu(*payload_ptr & ~ELS_CMD_MASK);
4032
4033 rscn_event_data = kmalloc(sizeof(struct lpfc_rscn_event_header) +
4034 payload_len, GFP_KERNEL);
4035 if (!rscn_event_data) {
4036 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4037 "0147 Failed to allocate memory for RSCN event\n");
4038 return;
4039 }
4040 rscn_event_data->event_type = FC_REG_RSCN_EVENT;
4041 rscn_event_data->payload_length = payload_len;
4042 memcpy(rscn_event_data->rscn_payload, payload_ptr,
4043 payload_len);
4044
4045 fc_host_post_vendor_event(shost,
4046 fc_get_event_number(),
4047 sizeof(struct lpfc_els_event_header) + payload_len,
4048 (char *)rscn_event_data,
4049 LPFC_NL_VENDOR_ID);
4050
4051 kfree(rscn_event_data);
4052}
4053
4054/**
James Smart3621a712009-04-06 18:47:14 -04004055 * lpfc_els_rcv_rscn - Process an unsolicited rscn iocb
James Smarte59058c2008-08-24 21:49:00 -04004056 * @vport: pointer to a host virtual N_Port data structure.
4057 * @cmdiocb: pointer to lpfc command iocb data structure.
4058 * @ndlp: pointer to a node-list data structure.
4059 *
4060 * This routine processes an unsolicited RSCN (Registration State Change
4061 * Notification) IOCB. First, the payload of the unsolicited RSCN is walked
4062 * to invoke fc_host_post_event() routine to the FC transport layer. If the
4063 * discover state machine is about to begin discovery, it just accepts the
4064 * RSCN and the discovery process will satisfy the RSCN. If this RSCN only
4065 * contains N_Port IDs for other vports on this HBA, it just accepts the
4066 * RSCN and ignore processing it. If the state machine is in the recovery
4067 * state, the fc_rscn_id_list of this @vport is walked and the
4068 * lpfc_rscn_recovery_check() routine is invoked to send recovery event for
4069 * all nodes that match RSCN payload. Otherwise, the lpfc_els_handle_rscn()
4070 * routine is invoked to handle the RSCN event.
4071 *
4072 * Return code
4073 * 0 - Just sent the acc response
4074 * 1 - Sent the acc response and waited for name server completion
4075 **/
dea31012005-04-17 16:05:31 -05004076static int
James Smart2e0fef82007-06-17 19:56:36 -05004077lpfc_els_rcv_rscn(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004078 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004079{
James Smart2e0fef82007-06-17 19:56:36 -05004080 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4081 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004082 struct lpfc_dmabuf *pcmd;
James Smart92d7f7b2007-06-17 19:56:38 -05004083 uint32_t *lp, *datap;
dea31012005-04-17 16:05:31 -05004084 IOCB_t *icmd;
James Smart92d7f7b2007-06-17 19:56:38 -05004085 uint32_t payload_len, length, nportid, *cmd;
James Smart7f5f3d02008-02-08 18:50:14 -05004086 int rscn_cnt;
James Smart92d7f7b2007-06-17 19:56:38 -05004087 int rscn_id = 0, hba_id = 0;
James Smartd2873e42006-08-18 17:46:43 -04004088 int i;
dea31012005-04-17 16:05:31 -05004089
4090 icmd = &cmdiocb->iocb;
4091 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4092 lp = (uint32_t *) pcmd->virt;
4093
James Smart92d7f7b2007-06-17 19:56:38 -05004094 payload_len = be32_to_cpu(*lp++ & ~ELS_CMD_MASK);
4095 payload_len -= sizeof(uint32_t); /* take off word 0 */
dea31012005-04-17 16:05:31 -05004096 /* RSCN received */
James Smarte8b62012007-08-02 11:10:09 -04004097 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4098 "0214 RSCN received Data: x%x x%x x%x x%x\n",
James Smart7f5f3d02008-02-08 18:50:14 -05004099 vport->fc_flag, payload_len, *lp,
4100 vport->fc_rscn_id_cnt);
James Smartddcc50f2008-12-04 22:38:46 -05004101
4102 /* Send an RSCN event to the management application */
4103 lpfc_send_rscn_event(vport, cmdiocb);
4104
James Smartd2873e42006-08-18 17:46:43 -04004105 for (i = 0; i < payload_len/sizeof(uint32_t); i++)
James Smart2e0fef82007-06-17 19:56:36 -05004106 fc_host_post_event(shost, fc_get_event_number(),
James Smartd2873e42006-08-18 17:46:43 -04004107 FCH_EVT_RSCN, lp[i]);
4108
dea31012005-04-17 16:05:31 -05004109 /* If we are about to begin discovery, just ACC the RSCN.
4110 * Discovery processing will satisfy it.
4111 */
James Smart2e0fef82007-06-17 19:56:36 -05004112 if (vport->port_state <= LPFC_NS_QRY) {
James Smart858c9f62007-06-17 19:56:39 -05004113 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4114 "RCV RSCN ignore: did:x%x/ste:x%x flg:x%x",
4115 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4116
James Smart51ef4c22007-08-02 11:10:31 -04004117 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004118 return 0;
dea31012005-04-17 16:05:31 -05004119 }
4120
James Smart92d7f7b2007-06-17 19:56:38 -05004121 /* If this RSCN just contains NPortIDs for other vports on this HBA,
4122 * just ACC and ignore it.
4123 */
4124 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart3de2a652007-08-02 11:09:59 -04004125 !(vport->cfg_peer_port_login)) {
James Smart92d7f7b2007-06-17 19:56:38 -05004126 i = payload_len;
4127 datap = lp;
4128 while (i > 0) {
4129 nportid = *datap++;
4130 nportid = ((be32_to_cpu(nportid)) & Mask_DID);
4131 i -= sizeof(uint32_t);
4132 rscn_id++;
James Smart549e55c2007-08-02 11:09:51 -04004133 if (lpfc_find_vport_by_did(phba, nportid))
4134 hba_id++;
James Smart92d7f7b2007-06-17 19:56:38 -05004135 }
4136 if (rscn_id == hba_id) {
4137 /* ALL NPortIDs in RSCN are on HBA */
James Smarte8b62012007-08-02 11:10:09 -04004138 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -04004139 "0219 Ignore RSCN "
James Smarte8b62012007-08-02 11:10:09 -04004140 "Data: x%x x%x x%x x%x\n",
4141 vport->fc_flag, payload_len,
James Smart7f5f3d02008-02-08 18:50:14 -05004142 *lp, vport->fc_rscn_id_cnt);
James Smart858c9f62007-06-17 19:56:39 -05004143 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4144 "RCV RSCN vport: did:x%x/ste:x%x flg:x%x",
4145 ndlp->nlp_DID, vport->port_state,
4146 ndlp->nlp_flag);
4147
James Smart92d7f7b2007-06-17 19:56:38 -05004148 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004149 ndlp, NULL);
James Smart92d7f7b2007-06-17 19:56:38 -05004150 return 0;
4151 }
4152 }
4153
James Smart7f5f3d02008-02-08 18:50:14 -05004154 spin_lock_irq(shost->host_lock);
4155 if (vport->fc_rscn_flush) {
4156 /* Another thread is walking fc_rscn_id_list on this vport */
James Smart7f5f3d02008-02-08 18:50:14 -05004157 vport->fc_flag |= FC_RSCN_DISCOVERY;
James Smart97957242009-12-21 17:03:15 -05004158 spin_unlock_irq(shost->host_lock);
James Smart58da1ff2008-04-07 10:15:56 -04004159 /* Send back ACC */
4160 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
James Smart7f5f3d02008-02-08 18:50:14 -05004161 return 0;
4162 }
4163 /* Indicate we are walking fc_rscn_id_list on this vport */
4164 vport->fc_rscn_flush = 1;
4165 spin_unlock_irq(shost->host_lock);
André Goddard Rosaaf901ca2009-11-14 13:09:05 -02004166 /* Get the array count after successfully have the token */
James Smart7f5f3d02008-02-08 18:50:14 -05004167 rscn_cnt = vport->fc_rscn_id_cnt;
dea31012005-04-17 16:05:31 -05004168 /* If we are already processing an RSCN, save the received
4169 * RSCN payload buffer, cmdiocb->context2 to process later.
4170 */
James Smart2e0fef82007-06-17 19:56:36 -05004171 if (vport->fc_flag & (FC_RSCN_MODE | FC_NDISC_ACTIVE)) {
James Smart858c9f62007-06-17 19:56:39 -05004172 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4173 "RCV RSCN defer: did:x%x/ste:x%x flg:x%x",
4174 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4175
James Smart09372822008-01-11 01:52:54 -05004176 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004177 vport->fc_flag |= FC_RSCN_DEFERRED;
4178 if ((rscn_cnt < FC_MAX_HOLD_RSCN) &&
James Smart2e0fef82007-06-17 19:56:36 -05004179 !(vport->fc_flag & FC_RSCN_DISCOVERY)) {
James Smart2e0fef82007-06-17 19:56:36 -05004180 vport->fc_flag |= FC_RSCN_MODE;
4181 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004182 if (rscn_cnt) {
4183 cmd = vport->fc_rscn_id_list[rscn_cnt-1]->virt;
4184 length = be32_to_cpu(*cmd & ~ELS_CMD_MASK);
4185 }
4186 if ((rscn_cnt) &&
4187 (payload_len + length <= LPFC_BPL_SIZE)) {
4188 *cmd &= ELS_CMD_MASK;
James Smart7f5f3d02008-02-08 18:50:14 -05004189 *cmd |= cpu_to_be32(payload_len + length);
James Smart92d7f7b2007-06-17 19:56:38 -05004190 memcpy(((uint8_t *)cmd) + length, lp,
4191 payload_len);
4192 } else {
4193 vport->fc_rscn_id_list[rscn_cnt] = pcmd;
4194 vport->fc_rscn_id_cnt++;
4195 /* If we zero, cmdiocb->context2, the calling
4196 * routine will not try to free it.
4197 */
4198 cmdiocb->context2 = NULL;
4199 }
dea31012005-04-17 16:05:31 -05004200 /* Deferred RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004201 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4202 "0235 Deferred RSCN "
4203 "Data: x%x x%x x%x\n",
4204 vport->fc_rscn_id_cnt, vport->fc_flag,
4205 vport->port_state);
dea31012005-04-17 16:05:31 -05004206 } else {
James Smart2e0fef82007-06-17 19:56:36 -05004207 vport->fc_flag |= FC_RSCN_DISCOVERY;
4208 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004209 /* ReDiscovery RSCN */
James Smarte8b62012007-08-02 11:10:09 -04004210 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4211 "0234 ReDiscovery RSCN "
4212 "Data: x%x x%x x%x\n",
4213 vport->fc_rscn_id_cnt, vport->fc_flag,
4214 vport->port_state);
dea31012005-04-17 16:05:31 -05004215 }
James Smart7f5f3d02008-02-08 18:50:14 -05004216 /* Indicate we are done walking fc_rscn_id_list on this vport */
4217 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004218 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004219 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004220 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004221 lpfc_rscn_recovery_check(vport);
James Smart09372822008-01-11 01:52:54 -05004222 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004223 vport->fc_flag &= ~FC_RSCN_DEFERRED;
James Smart09372822008-01-11 01:52:54 -05004224 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004225 return 0;
dea31012005-04-17 16:05:31 -05004226 }
James Smart858c9f62007-06-17 19:56:39 -05004227 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
4228 "RCV RSCN: did:x%x/ste:x%x flg:x%x",
4229 ndlp->nlp_DID, vport->port_state, ndlp->nlp_flag);
4230
James Smart2e0fef82007-06-17 19:56:36 -05004231 spin_lock_irq(shost->host_lock);
4232 vport->fc_flag |= FC_RSCN_MODE;
4233 spin_unlock_irq(shost->host_lock);
4234 vport->fc_rscn_id_list[vport->fc_rscn_id_cnt++] = pcmd;
James Smart7f5f3d02008-02-08 18:50:14 -05004235 /* Indicate we are done walking fc_rscn_id_list on this vport */
4236 vport->fc_rscn_flush = 0;
dea31012005-04-17 16:05:31 -05004237 /*
4238 * If we zero, cmdiocb->context2, the calling routine will
4239 * not try to free it.
4240 */
4241 cmdiocb->context2 = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05004242 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004243 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004244 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004245 /* send RECOVERY event for ALL nodes that match RSCN payload */
James Smart2e0fef82007-06-17 19:56:36 -05004246 lpfc_rscn_recovery_check(vport);
James Smart2e0fef82007-06-17 19:56:36 -05004247 return lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05004248}
4249
James Smarte59058c2008-08-24 21:49:00 -04004250/**
James Smart3621a712009-04-06 18:47:14 -04004251 * lpfc_els_handle_rscn - Handle rscn for a vport
James Smarte59058c2008-08-24 21:49:00 -04004252 * @vport: pointer to a host virtual N_Port data structure.
4253 *
4254 * This routine handles the Registration State Configuration Notification
4255 * (RSCN) for a @vport. If login to NameServer does not exist, a new ndlp shall
4256 * be created and a Port Login (PLOGI) to the NameServer is issued. Otherwise,
4257 * if the ndlp to NameServer exists, a Common Transport (CT) command to the
4258 * NameServer shall be issued. If CT command to the NameServer fails to be
4259 * issued, the lpfc_els_flush_rscn() routine shall be invoked to clean up any
4260 * RSCN activities with the @vport.
4261 *
4262 * Return code
4263 * 0 - Cleaned up rscn on the @vport
4264 * 1 - Wait for plogi to name server before proceed
4265 **/
dea31012005-04-17 16:05:31 -05004266int
James Smart2e0fef82007-06-17 19:56:36 -05004267lpfc_els_handle_rscn(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004268{
4269 struct lpfc_nodelist *ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004270 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004271
James Smart92d7f7b2007-06-17 19:56:38 -05004272 /* Ignore RSCN if the port is being torn down. */
4273 if (vport->load_flag & FC_UNLOADING) {
4274 lpfc_els_flush_rscn(vport);
4275 return 0;
4276 }
4277
dea31012005-04-17 16:05:31 -05004278 /* Start timer for RSCN processing */
James Smart2e0fef82007-06-17 19:56:36 -05004279 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004280
4281 /* RSCN processed */
James Smarte8b62012007-08-02 11:10:09 -04004282 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4283 "0215 RSCN processed Data: x%x x%x x%x x%x\n",
4284 vport->fc_flag, 0, vport->fc_rscn_id_cnt,
4285 vport->port_state);
dea31012005-04-17 16:05:31 -05004286
4287 /* To process RSCN, first compare RSCN data with NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004288 vport->fc_ns_retry = 0;
James Smart0ff10d42008-01-11 01:52:36 -05004289 vport->num_disc_nodes = 0;
4290
James Smart2e0fef82007-06-17 19:56:36 -05004291 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004292 if (ndlp && NLP_CHK_NODE_ACT(ndlp)
4293 && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
dea31012005-04-17 16:05:31 -05004294 /* Good ndlp, issue CT Request to NameServer */
James Smart92d7f7b2007-06-17 19:56:38 -05004295 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0) == 0)
dea31012005-04-17 16:05:31 -05004296 /* Wait for NameServer query cmpl before we can
4297 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004298 return 1;
dea31012005-04-17 16:05:31 -05004299 } else {
4300 /* If login to NameServer does not exist, issue one */
4301 /* Good status, issue PLOGI to NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05004302 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004303 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
dea31012005-04-17 16:05:31 -05004304 /* Wait for NameServer login cmpl before we can
4305 continue */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004306 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05004307
James Smarte47c9092008-02-08 18:49:26 -05004308 if (ndlp) {
4309 ndlp = lpfc_enable_node(vport, ndlp,
4310 NLP_STE_PLOGI_ISSUE);
4311 if (!ndlp) {
4312 lpfc_els_flush_rscn(vport);
4313 return 0;
4314 }
4315 ndlp->nlp_prev_state = NLP_STE_UNUSED_NODE;
dea31012005-04-17 16:05:31 -05004316 } else {
James Smarte47c9092008-02-08 18:49:26 -05004317 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
4318 if (!ndlp) {
4319 lpfc_els_flush_rscn(vport);
4320 return 0;
4321 }
James Smart2e0fef82007-06-17 19:56:36 -05004322 lpfc_nlp_init(vport, ndlp, NameServer_DID);
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004323 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004324 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
dea31012005-04-17 16:05:31 -05004325 }
James Smarte47c9092008-02-08 18:49:26 -05004326 ndlp->nlp_type |= NLP_FABRIC;
4327 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
4328 /* Wait for NameServer login cmpl before we can
4329 * continue
4330 */
4331 return 1;
dea31012005-04-17 16:05:31 -05004332 }
4333
James Smart2e0fef82007-06-17 19:56:36 -05004334 lpfc_els_flush_rscn(vport);
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/**
James Smart3621a712009-04-06 18:47:14 -04004339 * lpfc_els_rcv_flogi - Process an unsolicited flogi iocb
James Smarte59058c2008-08-24 21:49:00 -04004340 * @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 Fabric Login (FLOGI) IOCB received as an ELS
4345 * unsolicited event. An unsolicited FLOGI can be received in a point-to-
4346 * point topology. As an unsolicited FLOGI should not be received in a loop
4347 * mode, any unsolicited FLOGI received in loop mode shall be ignored. The
4348 * lpfc_check_sparm() routine is invoked to check the parameters in the
4349 * unsolicited FLOGI. If parameters validation failed, the routine
4350 * lpfc_els_rsp_reject() shall be called with reject reason code set to
4351 * LSEXP_SPARM_OPTIONS to reject the FLOGI. Otherwise, the Port WWN in the
4352 * FLOGI shall be compared with the Port WWN of the @vport to determine who
4353 * will initiate PLOGI. The higher lexicographical value party shall has
4354 * higher priority (as the winning port) and will initiate PLOGI and
4355 * communicate Port_IDs (Addresses) for both nodes in PLOGI. The result
4356 * of this will be marked in the @vport fc_flag field with FC_PT2PT_PLOGI
4357 * and then the lpfc_els_rsp_acc() routine is invoked to accept the FLOGI.
4358 *
4359 * Return code
4360 * 0 - Successfully processed the unsolicited flogi
4361 * 1 - Failed to process the unsolicited flogi
4362 **/
dea31012005-04-17 16:05:31 -05004363static int
James Smart2e0fef82007-06-17 19:56:36 -05004364lpfc_els_rcv_flogi(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
James Smart51ef4c22007-08-02 11:10:31 -04004365 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004366{
James Smart2e0fef82007-06-17 19:56:36 -05004367 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4368 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004369 struct lpfc_dmabuf *pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4370 uint32_t *lp = (uint32_t *) pcmd->virt;
4371 IOCB_t *icmd = &cmdiocb->iocb;
4372 struct serv_parm *sp;
4373 LPFC_MBOXQ_t *mbox;
4374 struct ls_rjt stat;
4375 uint32_t cmd, did;
4376 int rc;
4377
4378 cmd = *lp++;
4379 sp = (struct serv_parm *) lp;
4380
4381 /* FLOGI received */
4382
James Smart2e0fef82007-06-17 19:56:36 -05004383 lpfc_set_disctmo(vport);
dea31012005-04-17 16:05:31 -05004384
4385 if (phba->fc_topology == TOPOLOGY_LOOP) {
4386 /* We should never receive a FLOGI in loop mode, ignore it */
4387 did = icmd->un.elsreq64.remoteID;
4388
4389 /* An FLOGI ELS command <elsCmd> was received from DID <did> in
4390 Loop Mode */
James Smarte8b62012007-08-02 11:10:09 -04004391 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
4392 "0113 An FLOGI ELS command x%x was "
4393 "received from DID x%x in Loop Mode\n",
4394 cmd, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004395 return 1;
dea31012005-04-17 16:05:31 -05004396 }
4397
4398 did = Fabric_DID;
4399
James Smart341af102010-01-26 23:07:37 -05004400 if ((lpfc_check_sparm(vport, ndlp, sp, CLASS3, 1))) {
dea31012005-04-17 16:05:31 -05004401 /* For a FLOGI we accept, then if our portname is greater
4402 * then the remote portname we initiate Nport login.
4403 */
4404
James Smart2e0fef82007-06-17 19:56:36 -05004405 rc = memcmp(&vport->fc_portname, &sp->portName,
James Smart92d7f7b2007-06-17 19:56:38 -05004406 sizeof(struct lpfc_name));
dea31012005-04-17 16:05:31 -05004407
4408 if (!rc) {
James Smart2e0fef82007-06-17 19:56:36 -05004409 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4410 if (!mbox)
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004411 return 1;
James Smart2e0fef82007-06-17 19:56:36 -05004412
dea31012005-04-17 16:05:31 -05004413 lpfc_linkdown(phba);
4414 lpfc_init_link(phba, mbox,
4415 phba->cfg_topology,
4416 phba->cfg_link_speed);
James Smart04c68492009-05-22 14:52:52 -04004417 mbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
dea31012005-04-17 16:05:31 -05004418 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -05004419 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -04004420 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart5b8bd0c2007-04-25 09:52:49 -04004421 lpfc_set_loopback_flag(phba);
dea31012005-04-17 16:05:31 -05004422 if (rc == MBX_NOT_FINISHED) {
James Smart329f9bc2007-04-25 09:53:01 -04004423 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004424 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004425 return 1;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004426 } else if (rc > 0) { /* greater than */
James Smart2e0fef82007-06-17 19:56:36 -05004427 spin_lock_irq(shost->host_lock);
4428 vport->fc_flag |= FC_PT2PT_PLOGI;
4429 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004430 }
James Smart2e0fef82007-06-17 19:56:36 -05004431 spin_lock_irq(shost->host_lock);
4432 vport->fc_flag |= FC_PT2PT;
4433 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
4434 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004435 } else {
4436 /* Reject this request because invalid parameters */
4437 stat.un.b.lsRjtRsvd0 = 0;
4438 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4439 stat.un.b.lsRjtRsnCodeExp = LSEXP_SPARM_OPTIONS;
4440 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004441 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4442 NULL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004443 return 1;
dea31012005-04-17 16:05:31 -05004444 }
4445
4446 /* Send back ACC */
James Smart51ef4c22007-08-02 11:10:31 -04004447 lpfc_els_rsp_acc(vport, ELS_CMD_PLOGI, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004448
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004449 return 0;
dea31012005-04-17 16:05:31 -05004450}
4451
James Smarte59058c2008-08-24 21:49:00 -04004452/**
James Smart3621a712009-04-06 18:47:14 -04004453 * lpfc_els_rcv_rnid - Process an unsolicited rnid iocb
James Smarte59058c2008-08-24 21:49:00 -04004454 * @vport: pointer to a host virtual N_Port data structure.
4455 * @cmdiocb: pointer to lpfc command iocb data structure.
4456 * @ndlp: pointer to a node-list data structure.
4457 *
4458 * This routine processes Request Node Identification Data (RNID) IOCB
4459 * received as an ELS unsolicited event. Only when the RNID specified format
4460 * 0x0 or 0xDF (Topology Discovery Specific Node Identification Data)
4461 * present, this routine will invoke the lpfc_els_rsp_rnid_acc() routine to
4462 * Accept (ACC) the RNID ELS command. All the other RNID formats are
4463 * rejected by invoking the lpfc_els_rsp_reject() routine.
4464 *
4465 * Return code
4466 * 0 - Successfully processed rnid iocb (currently always return 0)
4467 **/
dea31012005-04-17 16:05:31 -05004468static int
James Smart2e0fef82007-06-17 19:56:36 -05004469lpfc_els_rcv_rnid(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4470 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004471{
4472 struct lpfc_dmabuf *pcmd;
4473 uint32_t *lp;
4474 IOCB_t *icmd;
4475 RNID *rn;
4476 struct ls_rjt stat;
4477 uint32_t cmd, did;
4478
4479 icmd = &cmdiocb->iocb;
4480 did = icmd->un.elsreq64.remoteID;
4481 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4482 lp = (uint32_t *) pcmd->virt;
4483
4484 cmd = *lp++;
4485 rn = (RNID *) lp;
4486
4487 /* RNID received */
4488
4489 switch (rn->Format) {
4490 case 0:
4491 case RNID_TOPOLOGY_DISC:
4492 /* Send back ACC */
James Smart2e0fef82007-06-17 19:56:36 -05004493 lpfc_els_rsp_rnid_acc(vport, rn->Format, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05004494 break;
4495 default:
4496 /* Reject this request because format not supported */
4497 stat.un.b.lsRjtRsvd0 = 0;
4498 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4499 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4500 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004501 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4502 NULL);
dea31012005-04-17 16:05:31 -05004503 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004504 return 0;
dea31012005-04-17 16:05:31 -05004505}
4506
James Smarte59058c2008-08-24 21:49:00 -04004507/**
James Smart3621a712009-04-06 18:47:14 -04004508 * lpfc_els_rcv_lirr - Process an unsolicited lirr iocb
James Smarte59058c2008-08-24 21:49:00 -04004509 * @vport: pointer to a host virtual N_Port data structure.
4510 * @cmdiocb: pointer to lpfc command iocb data structure.
4511 * @ndlp: pointer to a node-list data structure.
4512 *
4513 * This routine processes a Link Incident Report Registration(LIRR) IOCB
4514 * received as an ELS unsolicited event. Currently, this function just invokes
4515 * the lpfc_els_rsp_reject() routine to reject the LIRR IOCB unconditionally.
4516 *
4517 * Return code
4518 * 0 - Successfully processed lirr iocb (currently always return 0)
4519 **/
dea31012005-04-17 16:05:31 -05004520static int
James Smart2e0fef82007-06-17 19:56:36 -05004521lpfc_els_rcv_lirr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4522 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004523{
4524 struct ls_rjt stat;
4525
4526 /* For now, unconditionally reject this command */
4527 stat.un.b.lsRjtRsvd0 = 0;
4528 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4529 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4530 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004531 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004532 return 0;
4533}
4534
James Smarte59058c2008-08-24 21:49:00 -04004535/**
James Smart5ffc2662009-11-18 15:39:44 -05004536 * lpfc_els_rcv_rrq - Process an unsolicited rrq iocb
4537 * @vport: pointer to a host virtual N_Port data structure.
4538 * @cmdiocb: pointer to lpfc command iocb data structure.
4539 * @ndlp: pointer to a node-list data structure.
4540 *
4541 * This routine processes a Reinstate Recovery Qualifier (RRQ) IOCB
4542 * received as an ELS unsolicited event. A request to RRQ shall only
4543 * be accepted if the Originator Nx_Port N_Port_ID or the Responder
4544 * Nx_Port N_Port_ID of the target Exchange is the same as the
4545 * N_Port_ID of the Nx_Port that makes the request. If the RRQ is
4546 * not accepted, an LS_RJT with reason code "Unable to perform
4547 * command request" and reason code explanation "Invalid Originator
4548 * S_ID" shall be returned. For now, we just unconditionally accept
4549 * RRQ from the target.
4550 **/
4551static void
4552lpfc_els_rcv_rrq(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4553 struct lpfc_nodelist *ndlp)
4554{
4555 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
4556}
4557
4558/**
James Smart3621a712009-04-06 18:47:14 -04004559 * lpfc_els_rsp_rps_acc - Completion callbk func for MBX_READ_LNK_STAT mbox cmd
James Smarte59058c2008-08-24 21:49:00 -04004560 * @phba: pointer to lpfc hba data structure.
4561 * @pmb: pointer to the driver internal queue element for mailbox command.
4562 *
4563 * This routine is the completion callback function for the MBX_READ_LNK_STAT
4564 * mailbox command. This callback function is to actually send the Accept
4565 * (ACC) response to a Read Port Status (RPS) unsolicited IOCB event. It
4566 * collects the link statistics from the completion of the MBX_READ_LNK_STAT
4567 * mailbox command, constructs the RPS response with the link statistics
4568 * collected, and then invokes the lpfc_sli_issue_iocb() routine to send ACC
4569 * response to the RPS.
4570 *
4571 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4572 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4573 * will be stored into the context1 field of the IOCB for the completion
4574 * callback function to the RPS Accept Response ELS IOCB command.
4575 *
4576 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05004577static void
James Smart329f9bc2007-04-25 09:53:01 -04004578lpfc_els_rsp_rps_acc(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004579{
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004580 MAILBOX_t *mb;
4581 IOCB_t *icmd;
4582 RPS_RSP *rps_rsp;
4583 uint8_t *pcmd;
4584 struct lpfc_iocbq *elsiocb;
4585 struct lpfc_nodelist *ndlp;
4586 uint16_t xri, status;
4587 uint32_t cmdsize;
4588
James Smart04c68492009-05-22 14:52:52 -04004589 mb = &pmb->u.mb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004590
4591 ndlp = (struct lpfc_nodelist *) pmb->context2;
4592 xri = (uint16_t) ((unsigned long)(pmb->context1));
Randy Dunlap041976f2006-06-25 01:58:51 -07004593 pmb->context1 = NULL;
4594 pmb->context2 = NULL;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004595
4596 if (mb->mbxStatus) {
James Smart329f9bc2007-04-25 09:53:01 -04004597 mempool_free(pmb, phba->mbox_mem_pool);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004598 return;
4599 }
4600
4601 cmdsize = sizeof(RPS_RSP) + sizeof(uint32_t);
James Smart329f9bc2007-04-25 09:53:01 -04004602 mempool_free(pmb, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05004603 elsiocb = lpfc_prep_els_iocb(phba->pport, 0, cmdsize,
4604 lpfc_max_els_tries, ndlp,
4605 ndlp->nlp_DID, ELS_CMD_ACC);
James Smartfa4066b2008-01-11 01:53:27 -05004606
4607 /* Decrement the ndlp reference count from previous mbox command */
James Smart329f9bc2007-04-25 09:53:01 -04004608 lpfc_nlp_put(ndlp);
James Smartfa4066b2008-01-11 01:53:27 -05004609
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004610 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004611 return;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004612
4613 icmd = &elsiocb->iocb;
4614 icmd->ulpContext = xri;
4615
4616 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4617 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004618 pcmd += sizeof(uint32_t); /* Skip past command */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004619 rps_rsp = (RPS_RSP *)pcmd;
4620
4621 if (phba->fc_topology != TOPOLOGY_LOOP)
4622 status = 0x10;
4623 else
4624 status = 0x8;
James Smart2e0fef82007-06-17 19:56:36 -05004625 if (phba->pport->fc_flag & FC_FABRIC)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004626 status |= 0x4;
4627
4628 rps_rsp->rsvd1 = 0;
James Smart09372822008-01-11 01:52:54 -05004629 rps_rsp->portStatus = cpu_to_be16(status);
4630 rps_rsp->linkFailureCnt = cpu_to_be32(mb->un.varRdLnk.linkFailureCnt);
4631 rps_rsp->lossSyncCnt = cpu_to_be32(mb->un.varRdLnk.lossSyncCnt);
4632 rps_rsp->lossSignalCnt = cpu_to_be32(mb->un.varRdLnk.lossSignalCnt);
4633 rps_rsp->primSeqErrCnt = cpu_to_be32(mb->un.varRdLnk.primSeqErrCnt);
4634 rps_rsp->invalidXmitWord = cpu_to_be32(mb->un.varRdLnk.invalidXmitWord);
4635 rps_rsp->crcCnt = cpu_to_be32(mb->un.varRdLnk.crcCnt);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004636 /* Xmit ELS RPS ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004637 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_ELS,
4638 "0118 Xmit ELS RPS ACC response tag x%x xri x%x, "
4639 "did x%x, nlp_flag x%x, nlp_state x%x, rpi x%x\n",
4640 elsiocb->iotag, elsiocb->iocb.ulpContext,
4641 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4642 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05004643 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004644 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04004645 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) == IOCB_ERROR)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004646 lpfc_els_free_iocb(phba, elsiocb);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004647 return;
4648}
4649
James Smarte59058c2008-08-24 21:49:00 -04004650/**
James Smart3621a712009-04-06 18:47:14 -04004651 * lpfc_els_rcv_rps - Process an unsolicited rps iocb
James Smarte59058c2008-08-24 21:49:00 -04004652 * @vport: pointer to a host virtual N_Port data structure.
4653 * @cmdiocb: pointer to lpfc command iocb data structure.
4654 * @ndlp: pointer to a node-list data structure.
4655 *
4656 * This routine processes Read Port Status (RPS) IOCB received as an
4657 * ELS unsolicited event. It first checks the remote port state. If the
4658 * remote port is not in NLP_STE_UNMAPPED_NODE state or NLP_STE_MAPPED_NODE
4659 * state, it invokes the lpfc_els_rsp_reject() routine to send the reject
4660 * response. Otherwise, it issue the MBX_READ_LNK_STAT mailbox command
4661 * for reading the HBA link statistics. It is for the callback function,
4662 * lpfc_els_rsp_rps_acc(), set to the MBX_READ_LNK_STAT mailbox command
4663 * to actually sending out RPS Accept (ACC) response.
4664 *
4665 * Return codes
4666 * 0 - Successfully processed rps iocb (currently always return 0)
4667 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004668static int
James Smart2e0fef82007-06-17 19:56:36 -05004669lpfc_els_rcv_rps(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4670 struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004671{
James Smart2e0fef82007-06-17 19:56:36 -05004672 struct lpfc_hba *phba = vport->phba;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004673 uint32_t *lp;
4674 uint8_t flag;
4675 LPFC_MBOXQ_t *mbox;
4676 struct lpfc_dmabuf *pcmd;
4677 RPS *rps;
4678 struct ls_rjt stat;
4679
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004680 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
James Smart90160e02008-08-24 21:49:45 -04004681 (ndlp->nlp_state != NLP_STE_MAPPED_NODE))
4682 /* reject the unsolicited RPS request and done with it */
4683 goto reject_out;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004684
4685 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4686 lp = (uint32_t *) pcmd->virt;
4687 flag = (be32_to_cpu(*lp++) & 0xf);
4688 rps = (RPS *) lp;
4689
4690 if ((flag == 0) ||
4691 ((flag == 1) && (be32_to_cpu(rps->un.portNum) == 0)) ||
James Smart2e0fef82007-06-17 19:56:36 -05004692 ((flag == 2) && (memcmp(&rps->un.portName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05004693 sizeof(struct lpfc_name)) == 0))) {
James Smart2e0fef82007-06-17 19:56:36 -05004694
James Smart92d7f7b2007-06-17 19:56:38 -05004695 printk("Fix me....\n");
4696 dump_stack();
James Smart2e0fef82007-06-17 19:56:36 -05004697 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_ATOMIC);
4698 if (mbox) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004699 lpfc_read_lnk_stat(phba, mbox);
4700 mbox->context1 =
James Smart92d7f7b2007-06-17 19:56:38 -05004701 (void *)((unsigned long) cmdiocb->iocb.ulpContext);
James Smart329f9bc2007-04-25 09:53:01 -04004702 mbox->context2 = lpfc_nlp_get(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05004703 mbox->vport = vport;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004704 mbox->mbox_cmpl = lpfc_els_rsp_rps_acc;
James Smartfa4066b2008-01-11 01:53:27 -05004705 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart0b727fe2007-10-27 13:37:25 -04004706 != MBX_NOT_FINISHED)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004707 /* Mbox completion will send ELS Response */
4708 return 0;
James Smartfa4066b2008-01-11 01:53:27 -05004709 /* Decrement reference count used for the failed mbox
4710 * command.
4711 */
James Smart329f9bc2007-04-25 09:53:01 -04004712 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004713 mempool_free(mbox, phba->mbox_mem_pool);
4714 }
4715 }
James Smart90160e02008-08-24 21:49:45 -04004716
4717reject_out:
4718 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004719 stat.un.b.lsRjtRsvd0 = 0;
4720 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4721 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4722 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004723 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp, NULL);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004724 return 0;
4725}
4726
James Smarte59058c2008-08-24 21:49:00 -04004727/**
James Smart3621a712009-04-06 18:47:14 -04004728 * lpfc_els_rsp_rpl_acc - Issue an accept rpl els command
James Smarte59058c2008-08-24 21:49:00 -04004729 * @vport: pointer to a host virtual N_Port data structure.
4730 * @cmdsize: size of the ELS command.
4731 * @oldiocb: pointer to the original lpfc command iocb data structure.
4732 * @ndlp: pointer to a node-list data structure.
4733 *
4734 * This routine issuees an Accept (ACC) Read Port List (RPL) ELS command.
4735 * It is to be called by the lpfc_els_rcv_rpl() routine to accept the RPL.
4736 *
4737 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
4738 * will be incremented by 1 for holding the ndlp and the reference to ndlp
4739 * will be stored into the context1 field of the IOCB for the completion
4740 * callback function to the RPL Accept Response ELS command.
4741 *
4742 * Return code
4743 * 0 - Successfully issued ACC RPL ELS command
4744 * 1 - Failed to issue ACC RPL ELS command
4745 **/
Jamie Wellnitz082c0262006-02-28 19:25:30 -05004746static int
James Smart2e0fef82007-06-17 19:56:36 -05004747lpfc_els_rsp_rpl_acc(struct lpfc_vport *vport, uint16_t cmdsize,
4748 struct lpfc_iocbq *oldiocb, struct lpfc_nodelist *ndlp)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004749{
James Smart2e0fef82007-06-17 19:56:36 -05004750 struct lpfc_hba *phba = vport->phba;
4751 IOCB_t *icmd, *oldcmd;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004752 RPL_RSP rpl_rsp;
4753 struct lpfc_iocbq *elsiocb;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004754 uint8_t *pcmd;
4755
James Smart2e0fef82007-06-17 19:56:36 -05004756 elsiocb = lpfc_prep_els_iocb(vport, 0, cmdsize, oldiocb->retry, ndlp,
4757 ndlp->nlp_DID, ELS_CMD_ACC);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004758
James Smart488d1462006-03-07 15:02:37 -05004759 if (!elsiocb)
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004760 return 1;
James Smart488d1462006-03-07 15:02:37 -05004761
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004762 icmd = &elsiocb->iocb;
4763 oldcmd = &oldiocb->iocb;
4764 icmd->ulpContext = oldcmd->ulpContext; /* Xri */
4765
4766 pcmd = (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
4767 *((uint32_t *) (pcmd)) = ELS_CMD_ACC;
James Smart92d7f7b2007-06-17 19:56:38 -05004768 pcmd += sizeof(uint16_t);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004769 *((uint16_t *)(pcmd)) = be16_to_cpu(cmdsize);
4770 pcmd += sizeof(uint16_t);
4771
4772 /* Setup the RPL ACC payload */
4773 rpl_rsp.listLen = be32_to_cpu(1);
4774 rpl_rsp.index = 0;
4775 rpl_rsp.port_num_blk.portNum = 0;
James Smart2e0fef82007-06-17 19:56:36 -05004776 rpl_rsp.port_num_blk.portID = be32_to_cpu(vport->fc_myDID);
4777 memcpy(&rpl_rsp.port_num_blk.portName, &vport->fc_portname,
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004778 sizeof(struct lpfc_name));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004779 memcpy(pcmd, &rpl_rsp, cmdsize - sizeof(uint32_t));
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004780 /* Xmit ELS RPL ACC response tag <ulpIoTag> */
James Smarte8b62012007-08-02 11:10:09 -04004781 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4782 "0120 Xmit ELS RPL ACC response tag x%x "
4783 "xri x%x, did x%x, nlp_flag x%x, nlp_state x%x, "
4784 "rpi x%x\n",
4785 elsiocb->iotag, elsiocb->iocb.ulpContext,
4786 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_state,
4787 ndlp->nlp_rpi);
James Smart858c9f62007-06-17 19:56:39 -05004788 elsiocb->iocb_cmpl = lpfc_cmpl_els_rsp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004789 phba->fc_stat.elsXmitACC++;
James Smart3772a992009-05-22 14:50:54 -04004790 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
4791 IOCB_ERROR) {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004792 lpfc_els_free_iocb(phba, elsiocb);
4793 return 1;
4794 }
4795 return 0;
4796}
4797
James Smarte59058c2008-08-24 21:49:00 -04004798/**
James Smart3621a712009-04-06 18:47:14 -04004799 * lpfc_els_rcv_rpl - Process an unsolicited rpl iocb
James Smarte59058c2008-08-24 21:49:00 -04004800 * @vport: pointer to a host virtual N_Port data structure.
4801 * @cmdiocb: pointer to lpfc command iocb data structure.
4802 * @ndlp: pointer to a node-list data structure.
4803 *
4804 * This routine processes Read Port List (RPL) IOCB received as an ELS
4805 * unsolicited event. It first checks the remote port state. If the remote
4806 * port is not in NLP_STE_UNMAPPED_NODE and NLP_STE_MAPPED_NODE states, it
4807 * invokes the lpfc_els_rsp_reject() routine to send reject response.
4808 * Otherwise, this routine then invokes the lpfc_els_rsp_rpl_acc() routine
4809 * to accept the RPL.
4810 *
4811 * Return code
4812 * 0 - Successfully processed rpl iocb (currently always return 0)
4813 **/
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004814static int
James Smart2e0fef82007-06-17 19:56:36 -05004815lpfc_els_rcv_rpl(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4816 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004817{
4818 struct lpfc_dmabuf *pcmd;
4819 uint32_t *lp;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004820 uint32_t maxsize;
4821 uint16_t cmdsize;
4822 RPL *rpl;
4823 struct ls_rjt stat;
dea31012005-04-17 16:05:31 -05004824
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004825 if ((ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
4826 (ndlp->nlp_state != NLP_STE_MAPPED_NODE)) {
James Smart90160e02008-08-24 21:49:45 -04004827 /* issue rejection response */
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004828 stat.un.b.lsRjtRsvd0 = 0;
4829 stat.un.b.lsRjtRsnCode = LSRJT_UNABLE_TPC;
4830 stat.un.b.lsRjtRsnCodeExp = LSEXP_CANT_GIVE_DATA;
4831 stat.un.b.vendorUnique = 0;
James Smart858c9f62007-06-17 19:56:39 -05004832 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, cmdiocb, ndlp,
4833 NULL);
James Smart90160e02008-08-24 21:49:45 -04004834 /* rejected the unsolicited RPL request and done with it */
4835 return 0;
dea31012005-04-17 16:05:31 -05004836 }
4837
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004838 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4839 lp = (uint32_t *) pcmd->virt;
4840 rpl = (RPL *) (lp + 1);
4841
4842 maxsize = be32_to_cpu(rpl->maxsize);
4843
4844 /* We support only one port */
4845 if ((rpl->index == 0) &&
4846 ((maxsize == 0) ||
4847 ((maxsize * sizeof(uint32_t)) >= sizeof(RPL_RSP)))) {
4848 cmdsize = sizeof(uint32_t) + sizeof(RPL_RSP);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004849 } else {
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05004850 cmdsize = sizeof(uint32_t) + maxsize * sizeof(uint32_t);
4851 }
James Smart2e0fef82007-06-17 19:56:36 -05004852 lpfc_els_rsp_rpl_acc(vport, cmdsize, cmdiocb, ndlp);
dea31012005-04-17 16:05:31 -05004853
4854 return 0;
4855}
4856
James Smarte59058c2008-08-24 21:49:00 -04004857/**
James Smart3621a712009-04-06 18:47:14 -04004858 * lpfc_els_rcv_farp - Process an unsolicited farp request els command
James Smarte59058c2008-08-24 21:49:00 -04004859 * @vport: pointer to a virtual N_Port data structure.
4860 * @cmdiocb: pointer to lpfc command iocb data structure.
4861 * @ndlp: pointer to a node-list data structure.
4862 *
4863 * This routine processes Fibre Channel Address Resolution Protocol
4864 * (FARP) Request IOCB received as an ELS unsolicited event. Currently,
4865 * the lpfc driver only supports matching on WWPN or WWNN for FARP. As such,
4866 * FARP_MATCH_PORT flag and FARP_MATCH_NODE flag are checked against the
4867 * Match Flag in the FARP request IOCB: if FARP_MATCH_PORT flag is set, the
4868 * remote PortName is compared against the FC PortName stored in the @vport
4869 * data structure; if FARP_MATCH_NODE flag is set, the remote NodeName is
4870 * compared against the FC NodeName stored in the @vport data structure.
4871 * If any of these matches and the FARP_REQUEST_FARPR flag is set in the
4872 * FARP request IOCB Response Flag, the lpfc_issue_els_farpr() routine is
4873 * invoked to send out FARP Response to the remote node. Before sending the
4874 * FARP Response, however, the FARP_REQUEST_PLOGI flag is check in the FARP
4875 * request IOCB Response Flag and, if it is set, the lpfc_issue_els_plogi()
4876 * routine is invoked to log into the remote port first.
4877 *
4878 * Return code
4879 * 0 - Either the FARP Match Mode not supported or successfully processed
4880 **/
dea31012005-04-17 16:05:31 -05004881static int
James Smart2e0fef82007-06-17 19:56:36 -05004882lpfc_els_rcv_farp(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4883 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004884{
4885 struct lpfc_dmabuf *pcmd;
4886 uint32_t *lp;
4887 IOCB_t *icmd;
4888 FARP *fp;
4889 uint32_t cmd, cnt, did;
4890
4891 icmd = &cmdiocb->iocb;
4892 did = icmd->un.elsreq64.remoteID;
4893 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4894 lp = (uint32_t *) pcmd->virt;
4895
4896 cmd = *lp++;
4897 fp = (FARP *) lp;
dea31012005-04-17 16:05:31 -05004898 /* FARP-REQ received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04004899 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4900 "0601 FARP-REQ received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05004901 /* We will only support match on WWPN or WWNN */
4902 if (fp->Mflags & ~(FARP_MATCH_NODE | FARP_MATCH_PORT)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004903 return 0;
dea31012005-04-17 16:05:31 -05004904 }
4905
4906 cnt = 0;
4907 /* If this FARP command is searching for my portname */
4908 if (fp->Mflags & FARP_MATCH_PORT) {
James Smart2e0fef82007-06-17 19:56:36 -05004909 if (memcmp(&fp->RportName, &vport->fc_portname,
James Smart92d7f7b2007-06-17 19:56:38 -05004910 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05004911 cnt = 1;
4912 }
4913
4914 /* If this FARP command is searching for my nodename */
4915 if (fp->Mflags & FARP_MATCH_NODE) {
James Smart2e0fef82007-06-17 19:56:36 -05004916 if (memcmp(&fp->RnodeName, &vport->fc_nodename,
James Smart92d7f7b2007-06-17 19:56:38 -05004917 sizeof(struct lpfc_name)) == 0)
dea31012005-04-17 16:05:31 -05004918 cnt = 1;
4919 }
4920
4921 if (cnt) {
4922 if ((ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) ||
4923 (ndlp->nlp_state == NLP_STE_MAPPED_NODE)) {
4924 /* Log back into the node before sending the FARP. */
4925 if (fp->Rflags & FARP_REQUEST_PLOGI) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004926 ndlp->nlp_prev_state = ndlp->nlp_state;
James Smart2e0fef82007-06-17 19:56:36 -05004927 lpfc_nlp_set_state(vport, ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04004928 NLP_STE_PLOGI_ISSUE);
James Smart2e0fef82007-06-17 19:56:36 -05004929 lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0);
dea31012005-04-17 16:05:31 -05004930 }
4931
4932 /* Send a FARP response to that node */
James Smart2e0fef82007-06-17 19:56:36 -05004933 if (fp->Rflags & FARP_REQUEST_FARPR)
4934 lpfc_issue_els_farpr(vport, did, 0);
dea31012005-04-17 16:05:31 -05004935 }
4936 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004937 return 0;
dea31012005-04-17 16:05:31 -05004938}
4939
James Smarte59058c2008-08-24 21:49:00 -04004940/**
James Smart3621a712009-04-06 18:47:14 -04004941 * lpfc_els_rcv_farpr - Process an unsolicited farp response iocb
James Smarte59058c2008-08-24 21:49:00 -04004942 * @vport: pointer to a host virtual N_Port data structure.
4943 * @cmdiocb: pointer to lpfc command iocb data structure.
4944 * @ndlp: pointer to a node-list data structure.
4945 *
4946 * This routine processes Fibre Channel Address Resolution Protocol
4947 * Response (FARPR) IOCB received as an ELS unsolicited event. It simply
4948 * invokes the lpfc_els_rsp_acc() routine to the remote node to accept
4949 * the FARP response request.
4950 *
4951 * Return code
4952 * 0 - Successfully processed FARPR IOCB (currently always return 0)
4953 **/
dea31012005-04-17 16:05:31 -05004954static int
James Smart2e0fef82007-06-17 19:56:36 -05004955lpfc_els_rcv_farpr(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4956 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004957{
4958 struct lpfc_dmabuf *pcmd;
4959 uint32_t *lp;
4960 IOCB_t *icmd;
4961 uint32_t cmd, did;
4962
4963 icmd = &cmdiocb->iocb;
4964 did = icmd->un.elsreq64.remoteID;
4965 pcmd = (struct lpfc_dmabuf *) cmdiocb->context2;
4966 lp = (uint32_t *) pcmd->virt;
4967
4968 cmd = *lp++;
4969 /* FARP-RSP received from DID <did> */
James Smarte8b62012007-08-02 11:10:09 -04004970 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
4971 "0600 FARP-RSP received from DID x%x\n", did);
dea31012005-04-17 16:05:31 -05004972 /* ACCEPT the Farp resp request */
James Smart51ef4c22007-08-02 11:10:31 -04004973 lpfc_els_rsp_acc(vport, ELS_CMD_ACC, cmdiocb, ndlp, NULL);
dea31012005-04-17 16:05:31 -05004974
4975 return 0;
4976}
4977
James Smarte59058c2008-08-24 21:49:00 -04004978/**
James Smart3621a712009-04-06 18:47:14 -04004979 * lpfc_els_rcv_fan - Process an unsolicited fan iocb command
James Smarte59058c2008-08-24 21:49:00 -04004980 * @vport: pointer to a host virtual N_Port data structure.
4981 * @cmdiocb: pointer to lpfc command iocb data structure.
4982 * @fan_ndlp: pointer to a node-list data structure.
4983 *
4984 * This routine processes a Fabric Address Notification (FAN) IOCB
4985 * command received as an ELS unsolicited event. The FAN ELS command will
4986 * only be processed on a physical port (i.e., the @vport represents the
4987 * physical port). The fabric NodeName and PortName from the FAN IOCB are
4988 * compared against those in the phba data structure. If any of those is
4989 * different, the lpfc_initial_flogi() routine is invoked to initialize
4990 * Fabric Login (FLOGI) to the fabric to start the discover over. Otherwise,
4991 * if both of those are identical, the lpfc_issue_fabric_reglogin() routine
4992 * is invoked to register login to the fabric.
4993 *
4994 * Return code
4995 * 0 - Successfully processed fan iocb (currently always return 0).
4996 **/
dea31012005-04-17 16:05:31 -05004997static int
James Smart2e0fef82007-06-17 19:56:36 -05004998lpfc_els_rcv_fan(struct lpfc_vport *vport, struct lpfc_iocbq *cmdiocb,
4999 struct lpfc_nodelist *fan_ndlp)
dea31012005-04-17 16:05:31 -05005000{
James Smart2e0fef82007-06-17 19:56:36 -05005001 struct lpfc_hba *phba = vport->phba;
James Smart0d2b6b82008-06-14 22:52:47 -04005002 uint32_t *lp;
5003 FAN *fp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005004
James Smart0d2b6b82008-06-14 22:52:47 -04005005 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS, "0265 FAN received\n");
5006 lp = (uint32_t *)((struct lpfc_dmabuf *)cmdiocb->context2)->virt;
5007 fp = (FAN *) ++lp;
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005008 /* FAN received; Fan does not have a reply sequence */
James Smart0d2b6b82008-06-14 22:52:47 -04005009 if ((vport == phba->pport) &&
5010 (vport->port_state == LPFC_LOCAL_CFG_LINK)) {
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005011 if ((memcmp(&phba->fc_fabparam.nodeName, &fp->FnodeName,
James Smart0d2b6b82008-06-14 22:52:47 -04005012 sizeof(struct lpfc_name))) ||
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05005013 (memcmp(&phba->fc_fabparam.portName, &fp->FportName,
James Smart0d2b6b82008-06-14 22:52:47 -04005014 sizeof(struct lpfc_name)))) {
5015 /* This port has switched fabrics. FLOGI is required */
James Smart2e0fef82007-06-17 19:56:36 -05005016 lpfc_initial_flogi(vport);
James Smart0d2b6b82008-06-14 22:52:47 -04005017 } else {
5018 /* FAN verified - skip FLOGI */
5019 vport->fc_myDID = vport->fc_prevDID;
James Smart6fb120a2009-05-22 14:52:59 -04005020 if (phba->sli_rev < LPFC_SLI_REV4)
5021 lpfc_issue_fabric_reglogin(vport);
5022 else
5023 lpfc_issue_reg_vfi(vport);
dea31012005-04-17 16:05:31 -05005024 }
dea31012005-04-17 16:05:31 -05005025 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005026 return 0;
dea31012005-04-17 16:05:31 -05005027}
5028
James Smarte59058c2008-08-24 21:49:00 -04005029/**
James Smart3621a712009-04-06 18:47:14 -04005030 * lpfc_els_timeout - Handler funciton to the els timer
James Smarte59058c2008-08-24 21:49:00 -04005031 * @ptr: holder for the timer function associated data.
5032 *
5033 * This routine is invoked by the ELS timer after timeout. It posts the ELS
5034 * timer timeout event by setting the WORKER_ELS_TMO bit to the work port
5035 * event bitmap and then invokes the lpfc_worker_wake_up() routine to wake
5036 * up the worker thread. It is for the worker thread to invoke the routine
5037 * lpfc_els_timeout_handler() to work on the posted event WORKER_ELS_TMO.
5038 **/
dea31012005-04-17 16:05:31 -05005039void
5040lpfc_els_timeout(unsigned long ptr)
5041{
James Smart2e0fef82007-06-17 19:56:36 -05005042 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
5043 struct lpfc_hba *phba = vport->phba;
James Smart5e9d9b82008-06-14 22:52:53 -04005044 uint32_t tmo_posted;
dea31012005-04-17 16:05:31 -05005045 unsigned long iflag;
5046
James Smart2e0fef82007-06-17 19:56:36 -05005047 spin_lock_irqsave(&vport->work_port_lock, iflag);
James Smart5e9d9b82008-06-14 22:52:53 -04005048 tmo_posted = vport->work_port_events & WORKER_ELS_TMO;
5049 if (!tmo_posted)
James Smart2e0fef82007-06-17 19:56:36 -05005050 vport->work_port_events |= WORKER_ELS_TMO;
James Smart5e9d9b82008-06-14 22:52:53 -04005051 spin_unlock_irqrestore(&vport->work_port_lock, iflag);
James Smart92d7f7b2007-06-17 19:56:38 -05005052
James Smart5e9d9b82008-06-14 22:52:53 -04005053 if (!tmo_posted)
5054 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05005055 return;
5056}
5057
James Smarte59058c2008-08-24 21:49:00 -04005058/**
James Smart3621a712009-04-06 18:47:14 -04005059 * lpfc_els_timeout_handler - Process an els timeout event
James Smarte59058c2008-08-24 21:49:00 -04005060 * @vport: pointer to a virtual N_Port data structure.
5061 *
5062 * This routine is the actual handler function that processes an ELS timeout
5063 * event. It walks the ELS ring to get and abort all the IOCBs (except the
5064 * ABORT/CLOSE/FARP/FARPR/FDISC), which are associated with the @vport by
5065 * invoking the lpfc_sli_issue_abort_iotag() routine.
5066 **/
dea31012005-04-17 16:05:31 -05005067void
James Smart2e0fef82007-06-17 19:56:36 -05005068lpfc_els_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005069{
James Smart2e0fef82007-06-17 19:56:36 -05005070 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05005071 struct lpfc_sli_ring *pring;
5072 struct lpfc_iocbq *tmp_iocb, *piocb;
5073 IOCB_t *cmd = NULL;
5074 struct lpfc_dmabuf *pcmd;
James Smart2e0fef82007-06-17 19:56:36 -05005075 uint32_t els_command = 0;
dea31012005-04-17 16:05:31 -05005076 uint32_t timeout;
James Smart2e0fef82007-06-17 19:56:36 -05005077 uint32_t remote_ID = 0xffffffff;
dea31012005-04-17 16:05:31 -05005078
James Smart2e0fef82007-06-17 19:56:36 -05005079 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005080 timeout = (uint32_t)(phba->fc_ratov << 1);
5081
5082 pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05005083
5084 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
5085 cmd = &piocb->iocb;
5086
James Smart2e0fef82007-06-17 19:56:36 -05005087 if ((piocb->iocb_flag & LPFC_IO_LIBDFC) != 0 ||
5088 piocb->iocb.ulpCommand == CMD_ABORT_XRI_CN ||
5089 piocb->iocb.ulpCommand == CMD_CLOSE_XRI_CN)
dea31012005-04-17 16:05:31 -05005090 continue;
James Smart2e0fef82007-06-17 19:56:36 -05005091
5092 if (piocb->vport != vport)
5093 continue;
5094
dea31012005-04-17 16:05:31 -05005095 pcmd = (struct lpfc_dmabuf *) piocb->context2;
James Smart2e0fef82007-06-17 19:56:36 -05005096 if (pcmd)
5097 els_command = *(uint32_t *) (pcmd->virt);
dea31012005-04-17 16:05:31 -05005098
James Smart92d7f7b2007-06-17 19:56:38 -05005099 if (els_command == ELS_CMD_FARP ||
5100 els_command == ELS_CMD_FARPR ||
5101 els_command == ELS_CMD_FDISC)
dea31012005-04-17 16:05:31 -05005102 continue;
James Smart92d7f7b2007-06-17 19:56:38 -05005103
dea31012005-04-17 16:05:31 -05005104 if (piocb->drvrTimeout > 0) {
James Smart92d7f7b2007-06-17 19:56:38 -05005105 if (piocb->drvrTimeout >= timeout)
dea31012005-04-17 16:05:31 -05005106 piocb->drvrTimeout -= timeout;
James Smart92d7f7b2007-06-17 19:56:38 -05005107 else
dea31012005-04-17 16:05:31 -05005108 piocb->drvrTimeout = 0;
dea31012005-04-17 16:05:31 -05005109 continue;
5110 }
5111
James Smart2e0fef82007-06-17 19:56:36 -05005112 remote_ID = 0xffffffff;
5113 if (cmd->ulpCommand != CMD_GEN_REQUEST64_CR)
dea31012005-04-17 16:05:31 -05005114 remote_ID = cmd->un.elsreq64.remoteID;
James Smart2e0fef82007-06-17 19:56:36 -05005115 else {
5116 struct lpfc_nodelist *ndlp;
5117 ndlp = __lpfc_findnode_rpi(vport, cmd->ulpContext);
James Smart58da1ff2008-04-07 10:15:56 -04005118 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart2e0fef82007-06-17 19:56:36 -05005119 remote_ID = ndlp->nlp_DID;
dea31012005-04-17 16:05:31 -05005120 }
James Smarte8b62012007-08-02 11:10:09 -04005121 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5122 "0127 ELS timeout Data: x%x x%x x%x "
5123 "x%x\n", els_command,
5124 remote_ID, cmd->ulpCommand, cmd->ulpIoTag);
James Smart07951072007-04-25 09:51:38 -04005125 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05005126 }
James Smart2e0fef82007-06-17 19:56:36 -05005127 spin_unlock_irq(&phba->hbalock);
James Smart5a0e3262006-07-06 15:49:16 -04005128
James Smart2e0fef82007-06-17 19:56:36 -05005129 if (phba->sli.ring[LPFC_ELS_RING].txcmplq_cnt)
5130 mod_timer(&vport->els_tmofunc, jiffies + HZ * timeout);
dea31012005-04-17 16:05:31 -05005131}
5132
James Smarte59058c2008-08-24 21:49:00 -04005133/**
James Smart3621a712009-04-06 18:47:14 -04005134 * lpfc_els_flush_cmd - Clean up the outstanding els commands to a vport
James Smarte59058c2008-08-24 21:49:00 -04005135 * @vport: pointer to a host virtual N_Port data structure.
5136 *
5137 * This routine is used to clean up all the outstanding ELS commands on a
5138 * @vport. It first aborts the @vport by invoking lpfc_fabric_abort_vport()
5139 * routine. After that, it walks the ELS transmit queue to remove all the
5140 * IOCBs with the @vport other than the QUE_RING and ABORT/CLOSE IOCBs. For
5141 * the IOCBs with a non-NULL completion callback function, the callback
5142 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
5143 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs with a NULL completion
5144 * callback function, the IOCB will simply be released. Finally, it walks
5145 * the ELS transmit completion queue to issue an abort IOCB to any transmit
5146 * completion queue IOCB that is associated with the @vport and is not
5147 * an IOCB from libdfc (i.e., the management plane IOCBs that are not
5148 * part of the discovery state machine) out to HBA by invoking the
5149 * lpfc_sli_issue_abort_iotag() routine. Note that this function issues the
5150 * abort IOCB to any transmit completion queueed IOCB, it does not guarantee
5151 * the IOCBs are aborted when this function returns.
5152 **/
dea31012005-04-17 16:05:31 -05005153void
James Smart2e0fef82007-06-17 19:56:36 -05005154lpfc_els_flush_cmd(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05005155{
James Smart2534ba72007-04-25 09:52:20 -04005156 LIST_HEAD(completions);
James Smart2e0fef82007-06-17 19:56:36 -05005157 struct lpfc_hba *phba = vport->phba;
James Smart329f9bc2007-04-25 09:53:01 -04005158 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
dea31012005-04-17 16:05:31 -05005159 struct lpfc_iocbq *tmp_iocb, *piocb;
5160 IOCB_t *cmd = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005161
5162 lpfc_fabric_abort_vport(vport);
dea31012005-04-17 16:05:31 -05005163
James Smart2e0fef82007-06-17 19:56:36 -05005164 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05005165 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
5166 cmd = &piocb->iocb;
5167
5168 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
5169 continue;
5170 }
5171
5172 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
James Smart329f9bc2007-04-25 09:53:01 -04005173 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
5174 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
5175 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
5176 cmd->ulpCommand == CMD_ABORT_XRI_CN)
dea31012005-04-17 16:05:31 -05005177 continue;
dea31012005-04-17 16:05:31 -05005178
James Smart2e0fef82007-06-17 19:56:36 -05005179 if (piocb->vport != vport)
5180 continue;
5181
James Smart2534ba72007-04-25 09:52:20 -04005182 list_move_tail(&piocb->list, &completions);
James Smart1dcb58e2007-04-25 09:51:30 -04005183 pring->txq_cnt--;
dea31012005-04-17 16:05:31 -05005184 }
5185
5186 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
dea31012005-04-17 16:05:31 -05005187 if (piocb->iocb_flag & LPFC_IO_LIBDFC) {
5188 continue;
5189 }
dea31012005-04-17 16:05:31 -05005190
James Smart2e0fef82007-06-17 19:56:36 -05005191 if (piocb->vport != vport)
5192 continue;
5193
James Smart07951072007-04-25 09:51:38 -04005194 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
dea31012005-04-17 16:05:31 -05005195 }
James Smart2e0fef82007-06-17 19:56:36 -05005196 spin_unlock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04005197
James Smarta257bf92009-04-06 18:48:10 -04005198 /* Cancell all the IOCBs from the completions list */
5199 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
5200 IOERR_SLI_ABORTED);
James Smart2534ba72007-04-25 09:52:20 -04005201
dea31012005-04-17 16:05:31 -05005202 return;
5203}
5204
James Smarte59058c2008-08-24 21:49:00 -04005205/**
James Smart3621a712009-04-06 18:47:14 -04005206 * lpfc_els_flush_all_cmd - Clean up all the outstanding els commands to a HBA
James Smarte59058c2008-08-24 21:49:00 -04005207 * @phba: pointer to lpfc hba data structure.
5208 *
5209 * This routine is used to clean up all the outstanding ELS commands on a
5210 * @phba. It first aborts the @phba by invoking the lpfc_fabric_abort_hba()
5211 * routine. After that, it walks the ELS transmit queue to remove all the
5212 * IOCBs to the @phba other than the QUE_RING and ABORT/CLOSE IOCBs. For
5213 * the IOCBs with the completion callback function associated, the callback
5214 * function will be invoked with the status set to IOSTAT_LOCAL_REJECT and
5215 * un.ulpWord[4] set to IOERR_SLI_ABORTED. For IOCBs without the completion
5216 * callback function associated, the IOCB will simply be released. Finally,
5217 * it walks the ELS transmit completion queue to issue an abort IOCB to any
5218 * transmit completion queue IOCB that is not an IOCB from libdfc (i.e., the
5219 * management plane IOCBs that are not part of the discovery state machine)
5220 * out to HBA by invoking the lpfc_sli_issue_abort_iotag() routine.
5221 **/
James Smart549e55c2007-08-02 11:09:51 -04005222void
5223lpfc_els_flush_all_cmd(struct lpfc_hba *phba)
5224{
5225 LIST_HEAD(completions);
5226 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
5227 struct lpfc_iocbq *tmp_iocb, *piocb;
5228 IOCB_t *cmd = NULL;
5229
5230 lpfc_fabric_abort_hba(phba);
5231 spin_lock_irq(&phba->hbalock);
5232 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txq, list) {
5233 cmd = &piocb->iocb;
5234 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
5235 continue;
5236 /* Do not flush out the QUE_RING and ABORT/CLOSE iocbs */
5237 if (cmd->ulpCommand == CMD_QUE_RING_BUF_CN ||
5238 cmd->ulpCommand == CMD_QUE_RING_BUF64_CN ||
5239 cmd->ulpCommand == CMD_CLOSE_XRI_CN ||
5240 cmd->ulpCommand == CMD_ABORT_XRI_CN)
5241 continue;
5242 list_move_tail(&piocb->list, &completions);
5243 pring->txq_cnt--;
5244 }
5245 list_for_each_entry_safe(piocb, tmp_iocb, &pring->txcmplq, list) {
5246 if (piocb->iocb_flag & LPFC_IO_LIBDFC)
5247 continue;
5248 lpfc_sli_issue_abort_iotag(phba, pring, piocb);
5249 }
5250 spin_unlock_irq(&phba->hbalock);
James Smarta257bf92009-04-06 18:48:10 -04005251
5252 /* Cancel all the IOCBs from the completions list */
5253 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
5254 IOERR_SLI_ABORTED);
5255
James Smart549e55c2007-08-02 11:09:51 -04005256 return;
5257}
5258
James Smarte59058c2008-08-24 21:49:00 -04005259/**
James Smart3621a712009-04-06 18:47:14 -04005260 * lpfc_send_els_failure_event - Posts an ELS command failure event
James Smartea2151b2008-09-07 11:52:10 -04005261 * @phba: Pointer to hba context object.
5262 * @cmdiocbp: Pointer to command iocb which reported error.
5263 * @rspiocbp: Pointer to response iocb which reported error.
5264 *
5265 * This function sends an event when there is an ELS command
5266 * failure.
5267 **/
5268void
5269lpfc_send_els_failure_event(struct lpfc_hba *phba,
5270 struct lpfc_iocbq *cmdiocbp,
5271 struct lpfc_iocbq *rspiocbp)
5272{
5273 struct lpfc_vport *vport = cmdiocbp->vport;
5274 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5275 struct lpfc_lsrjt_event lsrjt_event;
5276 struct lpfc_fabric_event_header fabric_event;
5277 struct ls_rjt stat;
5278 struct lpfc_nodelist *ndlp;
5279 uint32_t *pcmd;
5280
5281 ndlp = cmdiocbp->context1;
5282 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
5283 return;
5284
5285 if (rspiocbp->iocb.ulpStatus == IOSTAT_LS_RJT) {
5286 lsrjt_event.header.event_type = FC_REG_ELS_EVENT;
5287 lsrjt_event.header.subcategory = LPFC_EVENT_LSRJT_RCV;
5288 memcpy(lsrjt_event.header.wwpn, &ndlp->nlp_portname,
5289 sizeof(struct lpfc_name));
5290 memcpy(lsrjt_event.header.wwnn, &ndlp->nlp_nodename,
5291 sizeof(struct lpfc_name));
5292 pcmd = (uint32_t *) (((struct lpfc_dmabuf *)
5293 cmdiocbp->context2)->virt);
5294 lsrjt_event.command = *pcmd;
5295 stat.un.lsRjtError = be32_to_cpu(rspiocbp->iocb.un.ulpWord[4]);
5296 lsrjt_event.reason_code = stat.un.b.lsRjtRsnCode;
5297 lsrjt_event.explanation = stat.un.b.lsRjtRsnCodeExp;
5298 fc_host_post_vendor_event(shost,
5299 fc_get_event_number(),
5300 sizeof(lsrjt_event),
5301 (char *)&lsrjt_event,
James Smartddcc50f2008-12-04 22:38:46 -05005302 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04005303 return;
5304 }
5305 if ((rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY) ||
5306 (rspiocbp->iocb.ulpStatus == IOSTAT_FABRIC_BSY)) {
5307 fabric_event.event_type = FC_REG_FABRIC_EVENT;
5308 if (rspiocbp->iocb.ulpStatus == IOSTAT_NPORT_BSY)
5309 fabric_event.subcategory = LPFC_EVENT_PORT_BUSY;
5310 else
5311 fabric_event.subcategory = LPFC_EVENT_FABRIC_BUSY;
5312 memcpy(fabric_event.wwpn, &ndlp->nlp_portname,
5313 sizeof(struct lpfc_name));
5314 memcpy(fabric_event.wwnn, &ndlp->nlp_nodename,
5315 sizeof(struct lpfc_name));
5316 fc_host_post_vendor_event(shost,
5317 fc_get_event_number(),
5318 sizeof(fabric_event),
5319 (char *)&fabric_event,
James Smartddcc50f2008-12-04 22:38:46 -05005320 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -04005321 return;
5322 }
5323
5324}
5325
5326/**
James Smart3621a712009-04-06 18:47:14 -04005327 * lpfc_send_els_event - Posts unsolicited els event
James Smartea2151b2008-09-07 11:52:10 -04005328 * @vport: Pointer to vport object.
5329 * @ndlp: Pointer FC node object.
5330 * @cmd: ELS command code.
5331 *
5332 * This function posts an event when there is an incoming
5333 * unsolicited ELS command.
5334 **/
5335static void
5336lpfc_send_els_event(struct lpfc_vport *vport,
5337 struct lpfc_nodelist *ndlp,
James Smartddcc50f2008-12-04 22:38:46 -05005338 uint32_t *payload)
James Smartea2151b2008-09-07 11:52:10 -04005339{
James Smartddcc50f2008-12-04 22:38:46 -05005340 struct lpfc_els_event_header *els_data = NULL;
5341 struct lpfc_logo_event *logo_data = NULL;
James Smartea2151b2008-09-07 11:52:10 -04005342 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5343
James Smartddcc50f2008-12-04 22:38:46 -05005344 if (*payload == ELS_CMD_LOGO) {
5345 logo_data = kmalloc(sizeof(struct lpfc_logo_event), GFP_KERNEL);
5346 if (!logo_data) {
5347 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5348 "0148 Failed to allocate memory "
5349 "for LOGO event\n");
5350 return;
5351 }
5352 els_data = &logo_data->header;
5353 } else {
5354 els_data = kmalloc(sizeof(struct lpfc_els_event_header),
5355 GFP_KERNEL);
5356 if (!els_data) {
5357 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5358 "0149 Failed to allocate memory "
5359 "for ELS event\n");
5360 return;
5361 }
5362 }
5363 els_data->event_type = FC_REG_ELS_EVENT;
5364 switch (*payload) {
James Smartea2151b2008-09-07 11:52:10 -04005365 case ELS_CMD_PLOGI:
James Smartddcc50f2008-12-04 22:38:46 -05005366 els_data->subcategory = LPFC_EVENT_PLOGI_RCV;
James Smartea2151b2008-09-07 11:52:10 -04005367 break;
5368 case ELS_CMD_PRLO:
James Smartddcc50f2008-12-04 22:38:46 -05005369 els_data->subcategory = LPFC_EVENT_PRLO_RCV;
James Smartea2151b2008-09-07 11:52:10 -04005370 break;
5371 case ELS_CMD_ADISC:
James Smartddcc50f2008-12-04 22:38:46 -05005372 els_data->subcategory = LPFC_EVENT_ADISC_RCV;
5373 break;
5374 case ELS_CMD_LOGO:
5375 els_data->subcategory = LPFC_EVENT_LOGO_RCV;
5376 /* Copy the WWPN in the LOGO payload */
5377 memcpy(logo_data->logo_wwpn, &payload[2],
5378 sizeof(struct lpfc_name));
James Smartea2151b2008-09-07 11:52:10 -04005379 break;
5380 default:
Julia Lawalle9161412009-02-08 22:43:19 +01005381 kfree(els_data);
James Smartea2151b2008-09-07 11:52:10 -04005382 return;
5383 }
James Smartddcc50f2008-12-04 22:38:46 -05005384 memcpy(els_data->wwpn, &ndlp->nlp_portname, sizeof(struct lpfc_name));
5385 memcpy(els_data->wwnn, &ndlp->nlp_nodename, sizeof(struct lpfc_name));
5386 if (*payload == ELS_CMD_LOGO) {
5387 fc_host_post_vendor_event(shost,
5388 fc_get_event_number(),
5389 sizeof(struct lpfc_logo_event),
5390 (char *)logo_data,
5391 LPFC_NL_VENDOR_ID);
5392 kfree(logo_data);
5393 } else {
5394 fc_host_post_vendor_event(shost,
5395 fc_get_event_number(),
5396 sizeof(struct lpfc_els_event_header),
5397 (char *)els_data,
5398 LPFC_NL_VENDOR_ID);
5399 kfree(els_data);
5400 }
James Smartea2151b2008-09-07 11:52:10 -04005401
5402 return;
5403}
5404
5405
5406/**
James Smart3621a712009-04-06 18:47:14 -04005407 * lpfc_els_unsol_buffer - Process an unsolicited event data buffer
James Smarte59058c2008-08-24 21:49:00 -04005408 * @phba: pointer to lpfc hba data structure.
5409 * @pring: pointer to a SLI ring.
5410 * @vport: pointer to a host virtual N_Port data structure.
5411 * @elsiocb: pointer to lpfc els command iocb data structure.
5412 *
5413 * This routine is used for processing the IOCB associated with a unsolicited
5414 * event. It first determines whether there is an existing ndlp that matches
5415 * the DID from the unsolicited IOCB. If not, it will create a new one with
5416 * the DID from the unsolicited IOCB. The ELS command from the unsolicited
5417 * IOCB is then used to invoke the proper routine and to set up proper state
5418 * of the discovery state machine.
5419 **/
James Smarted957682007-06-17 19:56:37 -05005420static void
5421lpfc_els_unsol_buffer(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
James Smart92d7f7b2007-06-17 19:56:38 -05005422 struct lpfc_vport *vport, struct lpfc_iocbq *elsiocb)
dea31012005-04-17 16:05:31 -05005423{
James Smart87af33f2007-10-27 13:37:43 -04005424 struct Scsi_Host *shost;
dea31012005-04-17 16:05:31 -05005425 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05005426 struct ls_rjt stat;
James Smart92d7f7b2007-06-17 19:56:38 -05005427 uint32_t *payload;
James Smart2e0fef82007-06-17 19:56:36 -05005428 uint32_t cmd, did, newnode, rjt_err = 0;
James Smarted957682007-06-17 19:56:37 -05005429 IOCB_t *icmd = &elsiocb->iocb;
dea31012005-04-17 16:05:31 -05005430
James Smarte47c9092008-02-08 18:49:26 -05005431 if (!vport || !(elsiocb->context2))
dea31012005-04-17 16:05:31 -05005432 goto dropit;
James Smart2e0fef82007-06-17 19:56:36 -05005433
dea31012005-04-17 16:05:31 -05005434 newnode = 0;
James Smart92d7f7b2007-06-17 19:56:38 -05005435 payload = ((struct lpfc_dmabuf *)elsiocb->context2)->virt;
5436 cmd = *payload;
James Smarted957682007-06-17 19:56:37 -05005437 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) == 0)
James Smart495a7142008-06-14 22:52:59 -04005438 lpfc_post_buffer(phba, pring, 1);
dea31012005-04-17 16:05:31 -05005439
James Smart858c9f62007-06-17 19:56:39 -05005440 did = icmd->un.rcvels.remoteID;
5441 if (icmd->ulpStatus) {
5442 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5443 "RCV Unsol ELS: status:x%x/x%x did:x%x",
5444 icmd->ulpStatus, icmd->un.ulpWord[4], did);
dea31012005-04-17 16:05:31 -05005445 goto dropit;
James Smart858c9f62007-06-17 19:56:39 -05005446 }
dea31012005-04-17 16:05:31 -05005447
5448 /* Check to see if link went down during discovery */
James Smarted957682007-06-17 19:56:37 -05005449 if (lpfc_els_chk_latt(vport))
dea31012005-04-17 16:05:31 -05005450 goto dropit;
dea31012005-04-17 16:05:31 -05005451
James Smartc8685952009-11-18 15:39:16 -05005452 /* Ignore traffic received during vport shutdown. */
James Smart92d7f7b2007-06-17 19:56:38 -05005453 if (vport->load_flag & FC_UNLOADING)
5454 goto dropit;
5455
James Smart2e0fef82007-06-17 19:56:36 -05005456 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005457 if (!ndlp) {
dea31012005-04-17 16:05:31 -05005458 /* Cannot find existing Fabric ndlp, so allocate a new one */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05005459 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
James Smarted957682007-06-17 19:56:37 -05005460 if (!ndlp)
dea31012005-04-17 16:05:31 -05005461 goto dropit;
dea31012005-04-17 16:05:31 -05005462
James Smart2e0fef82007-06-17 19:56:36 -05005463 lpfc_nlp_init(vport, ndlp, did);
James Smart98c9ea52007-10-27 13:37:33 -04005464 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
dea31012005-04-17 16:05:31 -05005465 newnode = 1;
James Smarte47c9092008-02-08 18:49:26 -05005466 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
dea31012005-04-17 16:05:31 -05005467 ndlp->nlp_type |= NLP_FABRIC;
James Smart58da1ff2008-04-07 10:15:56 -04005468 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
5469 ndlp = lpfc_enable_node(vport, ndlp,
5470 NLP_STE_UNUSED_NODE);
5471 if (!ndlp)
5472 goto dropit;
5473 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5474 newnode = 1;
5475 if ((did & Fabric_DID_MASK) == Fabric_DID_MASK)
5476 ndlp->nlp_type |= NLP_FABRIC;
5477 } else if (ndlp->nlp_state == NLP_STE_UNUSED_NODE) {
5478 /* This is similar to the new node path */
5479 ndlp = lpfc_nlp_get(ndlp);
5480 if (!ndlp)
5481 goto dropit;
5482 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
5483 newnode = 1;
James Smart87af33f2007-10-27 13:37:43 -04005484 }
dea31012005-04-17 16:05:31 -05005485
5486 phba->fc_stat.elsRcvFrame++;
James Smarte47c9092008-02-08 18:49:26 -05005487
James Smart329f9bc2007-04-25 09:53:01 -04005488 elsiocb->context1 = lpfc_nlp_get(ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05005489 elsiocb->vport = vport;
dea31012005-04-17 16:05:31 -05005490
5491 if ((cmd & ELS_CMD_MASK) == ELS_CMD_RSCN) {
5492 cmd &= ELS_CMD_MASK;
5493 }
5494 /* ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04005495 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
5496 "0112 ELS command x%x received from NPORT x%x "
5497 "Data: x%x\n", cmd, did, vport->port_state);
dea31012005-04-17 16:05:31 -05005498 switch (cmd) {
5499 case ELS_CMD_PLOGI:
James Smart858c9f62007-06-17 19:56:39 -05005500 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5501 "RCV PLOGI: did:x%x/ste:x%x flg:x%x",
5502 did, vport->port_state, ndlp->nlp_flag);
5503
dea31012005-04-17 16:05:31 -05005504 phba->fc_stat.elsRcvPLOGI++;
James Smart858c9f62007-06-17 19:56:39 -05005505 ndlp = lpfc_plogi_confirm_nport(phba, payload, ndlp);
5506
James Smartddcc50f2008-12-04 22:38:46 -05005507 lpfc_send_els_event(vport, ndlp, payload);
James Smart858c9f62007-06-17 19:56:39 -05005508 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart1b32f6a2008-02-08 18:49:39 -05005509 if (!(phba->pport->fc_flag & FC_PT2PT) ||
5510 (phba->pport->fc_flag & FC_PT2PT_PLOGI)) {
5511 rjt_err = LSRJT_UNABLE_TPC;
5512 break;
5513 }
5514 /* We get here, and drop thru, if we are PT2PT with
5515 * another NPort and the other side has initiated
5516 * the PLOGI before responding to our FLOGI.
5517 */
dea31012005-04-17 16:05:31 -05005518 }
James Smart87af33f2007-10-27 13:37:43 -04005519
5520 shost = lpfc_shost_from_vport(vport);
5521 spin_lock_irq(shost->host_lock);
5522 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
5523 spin_unlock_irq(shost->host_lock);
5524
James Smart2e0fef82007-06-17 19:56:36 -05005525 lpfc_disc_state_machine(vport, ndlp, elsiocb,
5526 NLP_EVT_RCV_PLOGI);
James Smart858c9f62007-06-17 19:56:39 -05005527
dea31012005-04-17 16:05:31 -05005528 break;
5529 case ELS_CMD_FLOGI:
James Smart858c9f62007-06-17 19:56:39 -05005530 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5531 "RCV FLOGI: did:x%x/ste:x%x flg:x%x",
5532 did, vport->port_state, ndlp->nlp_flag);
5533
dea31012005-04-17 16:05:31 -05005534 phba->fc_stat.elsRcvFLOGI++;
James Smart51ef4c22007-08-02 11:10:31 -04005535 lpfc_els_rcv_flogi(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005536 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005537 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05005538 break;
5539 case ELS_CMD_LOGO:
James Smart858c9f62007-06-17 19:56:39 -05005540 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5541 "RCV LOGO: did:x%x/ste:x%x flg:x%x",
5542 did, vport->port_state, ndlp->nlp_flag);
5543
dea31012005-04-17 16:05:31 -05005544 phba->fc_stat.elsRcvLOGO++;
James Smartddcc50f2008-12-04 22:38:46 -05005545 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05005546 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005547 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005548 break;
5549 }
James Smart2e0fef82007-06-17 19:56:36 -05005550 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_LOGO);
dea31012005-04-17 16:05:31 -05005551 break;
5552 case ELS_CMD_PRLO:
James Smart858c9f62007-06-17 19:56:39 -05005553 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5554 "RCV PRLO: did:x%x/ste:x%x flg:x%x",
5555 did, vport->port_state, ndlp->nlp_flag);
5556
dea31012005-04-17 16:05:31 -05005557 phba->fc_stat.elsRcvPRLO++;
James Smartddcc50f2008-12-04 22:38:46 -05005558 lpfc_send_els_event(vport, ndlp, payload);
James Smart2e0fef82007-06-17 19:56:36 -05005559 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005560 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005561 break;
5562 }
James Smart2e0fef82007-06-17 19:56:36 -05005563 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLO);
dea31012005-04-17 16:05:31 -05005564 break;
5565 case ELS_CMD_RSCN:
5566 phba->fc_stat.elsRcvRSCN++;
James Smart51ef4c22007-08-02 11:10:31 -04005567 lpfc_els_rcv_rscn(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005568 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005569 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05005570 break;
5571 case ELS_CMD_ADISC:
James Smart858c9f62007-06-17 19:56:39 -05005572 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5573 "RCV ADISC: did:x%x/ste:x%x flg:x%x",
5574 did, vport->port_state, ndlp->nlp_flag);
5575
James Smartddcc50f2008-12-04 22:38:46 -05005576 lpfc_send_els_event(vport, ndlp, payload);
dea31012005-04-17 16:05:31 -05005577 phba->fc_stat.elsRcvADISC++;
James Smart2e0fef82007-06-17 19:56:36 -05005578 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005579 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005580 break;
5581 }
James Smart2e0fef82007-06-17 19:56:36 -05005582 lpfc_disc_state_machine(vport, ndlp, elsiocb,
5583 NLP_EVT_RCV_ADISC);
dea31012005-04-17 16:05:31 -05005584 break;
5585 case ELS_CMD_PDISC:
James Smart858c9f62007-06-17 19:56:39 -05005586 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5587 "RCV PDISC: did:x%x/ste:x%x flg:x%x",
5588 did, vport->port_state, ndlp->nlp_flag);
5589
dea31012005-04-17 16:05:31 -05005590 phba->fc_stat.elsRcvPDISC++;
James Smart2e0fef82007-06-17 19:56:36 -05005591 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005592 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005593 break;
5594 }
James Smart2e0fef82007-06-17 19:56:36 -05005595 lpfc_disc_state_machine(vport, ndlp, elsiocb,
5596 NLP_EVT_RCV_PDISC);
dea31012005-04-17 16:05:31 -05005597 break;
5598 case ELS_CMD_FARPR:
James Smart858c9f62007-06-17 19:56:39 -05005599 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5600 "RCV FARPR: did:x%x/ste:x%x flg:x%x",
5601 did, vport->port_state, ndlp->nlp_flag);
5602
dea31012005-04-17 16:05:31 -05005603 phba->fc_stat.elsRcvFARPR++;
James Smart2e0fef82007-06-17 19:56:36 -05005604 lpfc_els_rcv_farpr(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05005605 break;
5606 case ELS_CMD_FARP:
James Smart858c9f62007-06-17 19:56:39 -05005607 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5608 "RCV FARP: did:x%x/ste:x%x flg:x%x",
5609 did, vport->port_state, ndlp->nlp_flag);
5610
dea31012005-04-17 16:05:31 -05005611 phba->fc_stat.elsRcvFARP++;
James Smart2e0fef82007-06-17 19:56:36 -05005612 lpfc_els_rcv_farp(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05005613 break;
5614 case ELS_CMD_FAN:
James Smart858c9f62007-06-17 19:56:39 -05005615 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5616 "RCV FAN: did:x%x/ste:x%x flg:x%x",
5617 did, vport->port_state, ndlp->nlp_flag);
5618
dea31012005-04-17 16:05:31 -05005619 phba->fc_stat.elsRcvFAN++;
James Smart2e0fef82007-06-17 19:56:36 -05005620 lpfc_els_rcv_fan(vport, elsiocb, ndlp);
dea31012005-04-17 16:05:31 -05005621 break;
dea31012005-04-17 16:05:31 -05005622 case ELS_CMD_PRLI:
James Smart858c9f62007-06-17 19:56:39 -05005623 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5624 "RCV PRLI: did:x%x/ste:x%x flg:x%x",
5625 did, vport->port_state, ndlp->nlp_flag);
5626
dea31012005-04-17 16:05:31 -05005627 phba->fc_stat.elsRcvPRLI++;
James Smart2e0fef82007-06-17 19:56:36 -05005628 if (vport->port_state < LPFC_DISC_AUTH) {
James Smart858c9f62007-06-17 19:56:39 -05005629 rjt_err = LSRJT_UNABLE_TPC;
dea31012005-04-17 16:05:31 -05005630 break;
5631 }
James Smart2e0fef82007-06-17 19:56:36 -05005632 lpfc_disc_state_machine(vport, ndlp, elsiocb, NLP_EVT_RCV_PRLI);
dea31012005-04-17 16:05:31 -05005633 break;
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005634 case ELS_CMD_LIRR:
James Smart858c9f62007-06-17 19:56:39 -05005635 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5636 "RCV LIRR: did:x%x/ste:x%x flg:x%x",
5637 did, vport->port_state, ndlp->nlp_flag);
5638
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005639 phba->fc_stat.elsRcvLIRR++;
James Smart2e0fef82007-06-17 19:56:36 -05005640 lpfc_els_rcv_lirr(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005641 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005642 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005643 break;
5644 case ELS_CMD_RPS:
James Smart858c9f62007-06-17 19:56:39 -05005645 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5646 "RCV RPS: did:x%x/ste:x%x flg:x%x",
5647 did, vport->port_state, ndlp->nlp_flag);
5648
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005649 phba->fc_stat.elsRcvRPS++;
James Smart2e0fef82007-06-17 19:56:36 -05005650 lpfc_els_rcv_rps(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005651 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005652 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005653 break;
5654 case ELS_CMD_RPL:
James Smart858c9f62007-06-17 19:56:39 -05005655 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5656 "RCV RPL: did:x%x/ste:x%x flg:x%x",
5657 did, vport->port_state, ndlp->nlp_flag);
5658
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005659 phba->fc_stat.elsRcvRPL++;
James Smart2e0fef82007-06-17 19:56:36 -05005660 lpfc_els_rcv_rpl(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005661 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005662 lpfc_nlp_put(ndlp);
Jamie Wellnitz7bb3b132006-02-28 19:25:15 -05005663 break;
dea31012005-04-17 16:05:31 -05005664 case ELS_CMD_RNID:
James Smart858c9f62007-06-17 19:56:39 -05005665 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5666 "RCV RNID: did:x%x/ste:x%x flg:x%x",
5667 did, vport->port_state, ndlp->nlp_flag);
5668
dea31012005-04-17 16:05:31 -05005669 phba->fc_stat.elsRcvRNID++;
James Smart2e0fef82007-06-17 19:56:36 -05005670 lpfc_els_rcv_rnid(vport, elsiocb, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04005671 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005672 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05005673 break;
James Smart5ffc2662009-11-18 15:39:44 -05005674 case ELS_CMD_RRQ:
5675 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5676 "RCV RRQ: did:x%x/ste:x%x flg:x%x",
5677 did, vport->port_state, ndlp->nlp_flag);
5678
5679 phba->fc_stat.elsRcvRRQ++;
5680 lpfc_els_rcv_rrq(vport, elsiocb, ndlp);
5681 if (newnode)
5682 lpfc_nlp_put(ndlp);
5683 break;
dea31012005-04-17 16:05:31 -05005684 default:
James Smart858c9f62007-06-17 19:56:39 -05005685 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_UNSOL,
5686 "RCV ELS cmd: cmd:x%x did:x%x/ste:x%x",
5687 cmd, did, vport->port_state);
5688
dea31012005-04-17 16:05:31 -05005689 /* Unsupported ELS command, reject */
James Smart858c9f62007-06-17 19:56:39 -05005690 rjt_err = LSRJT_INVALID_CMD;
dea31012005-04-17 16:05:31 -05005691
5692 /* Unknown ELS command <elsCmd> received from NPORT <did> */
James Smarte8b62012007-08-02 11:10:09 -04005693 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5694 "0115 Unknown ELS command x%x "
5695 "received from NPORT x%x\n", cmd, did);
James Smart87af33f2007-10-27 13:37:43 -04005696 if (newnode)
James Smart98c9ea52007-10-27 13:37:33 -04005697 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05005698 break;
5699 }
5700
5701 /* check if need to LS_RJT received ELS cmd */
5702 if (rjt_err) {
James Smart92d7f7b2007-06-17 19:56:38 -05005703 memset(&stat, 0, sizeof(stat));
James Smart858c9f62007-06-17 19:56:39 -05005704 stat.un.b.lsRjtRsnCode = rjt_err;
James.Smart@Emulex.Com1f679ca2005-06-25 10:34:27 -04005705 stat.un.b.lsRjtRsnCodeExp = LSEXP_NOTHING_MORE;
James Smart858c9f62007-06-17 19:56:39 -05005706 lpfc_els_rsp_reject(vport, stat.un.lsRjtError, elsiocb, ndlp,
5707 NULL);
dea31012005-04-17 16:05:31 -05005708 }
5709
James Smartd7c255b2008-08-24 21:50:00 -04005710 lpfc_nlp_put(elsiocb->context1);
5711 elsiocb->context1 = NULL;
James Smarted957682007-06-17 19:56:37 -05005712 return;
5713
5714dropit:
James Smart98c9ea52007-10-27 13:37:33 -04005715 if (vport && !(vport->load_flag & FC_UNLOADING))
James Smart6fb120a2009-05-22 14:52:59 -04005716 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5717 "0111 Dropping received ELS cmd "
James Smarted957682007-06-17 19:56:37 -05005718 "Data: x%x x%x x%x\n",
James Smart6fb120a2009-05-22 14:52:59 -04005719 icmd->ulpStatus, icmd->un.ulpWord[4], icmd->ulpTimeout);
James Smarted957682007-06-17 19:56:37 -05005720 phba->fc_stat.elsRcvDrop++;
5721}
5722
James Smarte59058c2008-08-24 21:49:00 -04005723/**
James Smart3621a712009-04-06 18:47:14 -04005724 * lpfc_find_vport_by_vpid - Find a vport on a HBA through vport identifier
James Smarte59058c2008-08-24 21:49:00 -04005725 * @phba: pointer to lpfc hba data structure.
5726 * @vpi: host virtual N_Port identifier.
5727 *
5728 * This routine finds a vport on a HBA (referred by @phba) through a
5729 * @vpi. The function walks the HBA's vport list and returns the address
5730 * of the vport with the matching @vpi.
5731 *
5732 * Return code
5733 * NULL - No vport with the matching @vpi found
5734 * Otherwise - Address to the vport with the matching @vpi.
5735 **/
James Smart6669f9b2009-10-02 15:16:45 -04005736struct lpfc_vport *
James Smart92d7f7b2007-06-17 19:56:38 -05005737lpfc_find_vport_by_vpid(struct lpfc_hba *phba, uint16_t vpi)
5738{
5739 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -04005740 unsigned long flags;
James Smart92d7f7b2007-06-17 19:56:38 -05005741
James Smart549e55c2007-08-02 11:09:51 -04005742 spin_lock_irqsave(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05005743 list_for_each_entry(vport, &phba->port_list, listentry) {
James Smart549e55c2007-08-02 11:09:51 -04005744 if (vport->vpi == vpi) {
5745 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05005746 return vport;
James Smart549e55c2007-08-02 11:09:51 -04005747 }
James Smart92d7f7b2007-06-17 19:56:38 -05005748 }
James Smart549e55c2007-08-02 11:09:51 -04005749 spin_unlock_irqrestore(&phba->hbalock, flags);
James Smart92d7f7b2007-06-17 19:56:38 -05005750 return NULL;
5751}
James Smarted957682007-06-17 19:56:37 -05005752
James Smarte59058c2008-08-24 21:49:00 -04005753/**
James Smart3621a712009-04-06 18:47:14 -04005754 * lpfc_els_unsol_event - Process an unsolicited event from an els sli ring
James Smarte59058c2008-08-24 21:49:00 -04005755 * @phba: pointer to lpfc hba data structure.
5756 * @pring: pointer to a SLI ring.
5757 * @elsiocb: pointer to lpfc els iocb data structure.
5758 *
5759 * This routine is used to process an unsolicited event received from a SLI
5760 * (Service Level Interface) ring. The actual processing of the data buffer
5761 * associated with the unsolicited event is done by invoking the routine
5762 * lpfc_els_unsol_buffer() after properly set up the iocb buffer from the
5763 * SLI ring on which the unsolicited event was received.
5764 **/
James Smarted957682007-06-17 19:56:37 -05005765void
5766lpfc_els_unsol_event(struct lpfc_hba *phba, struct lpfc_sli_ring *pring,
5767 struct lpfc_iocbq *elsiocb)
5768{
5769 struct lpfc_vport *vport = phba->pport;
James Smarted957682007-06-17 19:56:37 -05005770 IOCB_t *icmd = &elsiocb->iocb;
James Smarted957682007-06-17 19:56:37 -05005771 dma_addr_t paddr;
James Smart92d7f7b2007-06-17 19:56:38 -05005772 struct lpfc_dmabuf *bdeBuf1 = elsiocb->context2;
5773 struct lpfc_dmabuf *bdeBuf2 = elsiocb->context3;
James Smarted957682007-06-17 19:56:37 -05005774
James Smartd7c255b2008-08-24 21:50:00 -04005775 elsiocb->context1 = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -05005776 elsiocb->context2 = NULL;
5777 elsiocb->context3 = NULL;
5778
5779 if (icmd->ulpStatus == IOSTAT_NEED_BUFFER) {
5780 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
5781 } else if (icmd->ulpStatus == IOSTAT_LOCAL_REJECT &&
5782 (icmd->un.ulpWord[4] & 0xff) == IOERR_RCV_BUFFER_WAITING) {
James Smarted957682007-06-17 19:56:37 -05005783 phba->fc_stat.NoRcvBuf++;
5784 /* Not enough posted buffers; Try posting more buffers */
James Smart92d7f7b2007-06-17 19:56:38 -05005785 if (!(phba->sli3_options & LPFC_SLI3_HBQ_ENABLED))
James Smart495a7142008-06-14 22:52:59 -04005786 lpfc_post_buffer(phba, pring, 0);
James Smarted957682007-06-17 19:56:37 -05005787 return;
5788 }
5789
James Smart92d7f7b2007-06-17 19:56:38 -05005790 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
5791 (icmd->ulpCommand == CMD_IOCB_RCV_ELS64_CX ||
5792 icmd->ulpCommand == CMD_IOCB_RCV_SEQ64_CX)) {
5793 if (icmd->unsli3.rcvsli3.vpi == 0xffff)
5794 vport = phba->pport;
James Smart6fb120a2009-05-22 14:52:59 -04005795 else
5796 vport = lpfc_find_vport_by_vpid(phba,
5797 icmd->unsli3.rcvsli3.vpi - phba->vpi_base);
James Smart92d7f7b2007-06-17 19:56:38 -05005798 }
James Smart7f5f3d02008-02-08 18:50:14 -05005799 /* If there are no BDEs associated
5800 * with this IOCB, there is nothing to do.
5801 */
James Smarted957682007-06-17 19:56:37 -05005802 if (icmd->ulpBdeCount == 0)
5803 return;
5804
James Smart7f5f3d02008-02-08 18:50:14 -05005805 /* type of ELS cmd is first 32bit word
5806 * in packet
5807 */
James Smarted957682007-06-17 19:56:37 -05005808 if (phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) {
James Smart92d7f7b2007-06-17 19:56:38 -05005809 elsiocb->context2 = bdeBuf1;
James Smarted957682007-06-17 19:56:37 -05005810 } else {
5811 paddr = getPaddr(icmd->un.cont64[0].addrHigh,
5812 icmd->un.cont64[0].addrLow);
James Smart92d7f7b2007-06-17 19:56:38 -05005813 elsiocb->context2 = lpfc_sli_ringpostbuf_get(phba, pring,
5814 paddr);
James Smarted957682007-06-17 19:56:37 -05005815 }
5816
James Smart92d7f7b2007-06-17 19:56:38 -05005817 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
5818 /*
5819 * The different unsolicited event handlers would tell us
5820 * if they are done with "mp" by setting context2 to NULL.
5821 */
dea31012005-04-17 16:05:31 -05005822 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05005823 lpfc_in_buf_free(phba, (struct lpfc_dmabuf *)elsiocb->context2);
5824 elsiocb->context2 = NULL;
dea31012005-04-17 16:05:31 -05005825 }
James Smarted957682007-06-17 19:56:37 -05005826
5827 /* RCV_ELS64_CX provide for 2 BDEs - process 2nd if included */
James Smart92d7f7b2007-06-17 19:56:38 -05005828 if ((phba->sli3_options & LPFC_SLI3_HBQ_ENABLED) &&
James Smarted957682007-06-17 19:56:37 -05005829 icmd->ulpBdeCount == 2) {
James Smart92d7f7b2007-06-17 19:56:38 -05005830 elsiocb->context2 = bdeBuf2;
5831 lpfc_els_unsol_buffer(phba, pring, vport, elsiocb);
James Smarted957682007-06-17 19:56:37 -05005832 /* free mp if we are done with it */
5833 if (elsiocb->context2) {
James Smart92d7f7b2007-06-17 19:56:38 -05005834 lpfc_in_buf_free(phba, elsiocb->context2);
5835 elsiocb->context2 = NULL;
James Smarted957682007-06-17 19:56:37 -05005836 }
dea31012005-04-17 16:05:31 -05005837 }
dea31012005-04-17 16:05:31 -05005838}
James Smart92d7f7b2007-06-17 19:56:38 -05005839
James Smarte59058c2008-08-24 21:49:00 -04005840/**
James Smart3621a712009-04-06 18:47:14 -04005841 * lpfc_do_scr_ns_plogi - Issue a plogi to the name server for scr
James Smarte59058c2008-08-24 21:49:00 -04005842 * @phba: pointer to lpfc hba data structure.
5843 * @vport: pointer to a virtual N_Port data structure.
5844 *
5845 * This routine issues a Port Login (PLOGI) to the Name Server with
5846 * State Change Request (SCR) for a @vport. This routine will create an
5847 * ndlp for the Name Server associated to the @vport if such node does
5848 * not already exist. The PLOGI to Name Server is issued by invoking the
5849 * lpfc_issue_els_plogi() routine. If Fabric-Device Management Interface
5850 * (FDMI) is configured to the @vport, a FDMI node will be created and
5851 * the PLOGI to FDMI is issued by invoking lpfc_issue_els_plogi() routine.
5852 **/
James Smart92d7f7b2007-06-17 19:56:38 -05005853void
5854lpfc_do_scr_ns_plogi(struct lpfc_hba *phba, struct lpfc_vport *vport)
5855{
5856 struct lpfc_nodelist *ndlp, *ndlp_fdmi;
5857
5858 ndlp = lpfc_findnode_did(vport, NameServer_DID);
5859 if (!ndlp) {
5860 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
5861 if (!ndlp) {
5862 if (phba->fc_topology == TOPOLOGY_LOOP) {
5863 lpfc_disc_start(vport);
5864 return;
5865 }
5866 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04005867 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5868 "0251 NameServer login: no memory\n");
James Smart92d7f7b2007-06-17 19:56:38 -05005869 return;
5870 }
5871 lpfc_nlp_init(vport, ndlp, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05005872 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
5873 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_UNUSED_NODE);
5874 if (!ndlp) {
5875 if (phba->fc_topology == TOPOLOGY_LOOP) {
5876 lpfc_disc_start(vport);
5877 return;
5878 }
5879 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
5880 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5881 "0348 NameServer login: node freed\n");
5882 return;
5883 }
James Smart92d7f7b2007-06-17 19:56:38 -05005884 }
James Smart58da1ff2008-04-07 10:15:56 -04005885 ndlp->nlp_type |= NLP_FABRIC;
James Smart92d7f7b2007-06-17 19:56:38 -05005886
5887 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
5888
5889 if (lpfc_issue_els_plogi(vport, ndlp->nlp_DID, 0)) {
5890 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04005891 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
5892 "0252 Cannot issue NameServer login\n");
James Smart92d7f7b2007-06-17 19:56:38 -05005893 return;
5894 }
5895
James Smart3de2a652007-08-02 11:09:59 -04005896 if (vport->cfg_fdmi_on) {
James Smart92d7f7b2007-06-17 19:56:38 -05005897 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
5898 GFP_KERNEL);
5899 if (ndlp_fdmi) {
5900 lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
5901 ndlp_fdmi->nlp_type |= NLP_FABRIC;
James Smart58da1ff2008-04-07 10:15:56 -04005902 lpfc_nlp_set_state(vport, ndlp_fdmi,
5903 NLP_STE_PLOGI_ISSUE);
James Smart92d7f7b2007-06-17 19:56:38 -05005904 lpfc_issue_els_plogi(vport, ndlp_fdmi->nlp_DID,
5905 0);
5906 }
5907 }
5908 return;
5909}
5910
James Smarte59058c2008-08-24 21:49:00 -04005911/**
James Smart3621a712009-04-06 18:47:14 -04005912 * lpfc_cmpl_reg_new_vport - Completion callback function to register new vport
James Smarte59058c2008-08-24 21:49:00 -04005913 * @phba: pointer to lpfc hba data structure.
5914 * @pmb: pointer to the driver internal queue element for mailbox command.
5915 *
5916 * This routine is the completion callback function to register new vport
5917 * mailbox command. If the new vport mailbox command completes successfully,
5918 * the fabric registration login shall be performed on physical port (the
5919 * new vport created is actually a physical port, with VPI 0) or the port
5920 * login to Name Server for State Change Request (SCR) will be performed
5921 * on virtual port (real virtual port, with VPI greater than 0).
5922 **/
James Smart92d7f7b2007-06-17 19:56:38 -05005923static void
5924lpfc_cmpl_reg_new_vport(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
5925{
5926 struct lpfc_vport *vport = pmb->vport;
5927 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
5928 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart04c68492009-05-22 14:52:52 -04005929 MAILBOX_t *mb = &pmb->u.mb;
James Smart695a8142010-01-26 23:08:03 -05005930 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05005931
James Smart09372822008-01-11 01:52:54 -05005932 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05005933 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05005934 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05005935
5936 if (mb->mbxStatus) {
James Smarte8b62012007-08-02 11:10:09 -04005937 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
5938 "0915 Register VPI failed: 0x%x\n",
5939 mb->mbxStatus);
James Smart92d7f7b2007-06-17 19:56:38 -05005940
5941 switch (mb->mbxStatus) {
5942 case 0x11: /* unsupported feature */
5943 case 0x9603: /* max_vpi exceeded */
James Smart7f5f3d02008-02-08 18:50:14 -05005944 case 0x9602: /* Link event since CLEAR_LA */
James Smart92d7f7b2007-06-17 19:56:38 -05005945 /* giving up on vport registration */
5946 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
5947 spin_lock_irq(shost->host_lock);
5948 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
5949 spin_unlock_irq(shost->host_lock);
5950 lpfc_can_disctmo(vport);
5951 break;
James Smart695a8142010-01-26 23:08:03 -05005952 /* If reg_vpi fail with invalid VPI status, re-init VPI */
5953 case 0x20:
5954 spin_lock_irq(shost->host_lock);
5955 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
5956 spin_unlock_irq(shost->host_lock);
5957 lpfc_init_vpi(phba, pmb, vport->vpi);
5958 pmb->vport = vport;
5959 pmb->mbox_cmpl = lpfc_init_vpi_cmpl;
5960 rc = lpfc_sli_issue_mbox(phba, pmb,
5961 MBX_NOWAIT);
5962 if (rc == MBX_NOT_FINISHED) {
5963 lpfc_printf_vlog(vport,
5964 KERN_ERR, LOG_MBOX,
5965 "2732 Failed to issue INIT_VPI"
5966 " mailbox command\n");
5967 } else {
5968 lpfc_nlp_put(ndlp);
5969 return;
5970 }
5971
James Smart92d7f7b2007-06-17 19:56:38 -05005972 default:
5973 /* Try to recover from this error */
5974 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -05005975 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05005976 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -05005977 spin_unlock_irq(shost->host_lock);
James Smart7f5f3d02008-02-08 18:50:14 -05005978 if (vport->port_type == LPFC_PHYSICAL_PORT)
5979 lpfc_initial_flogi(vport);
5980 else
5981 lpfc_initial_fdisc(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05005982 break;
5983 }
James Smart92d7f7b2007-06-17 19:56:38 -05005984 } else {
James Smart695a8142010-01-26 23:08:03 -05005985 spin_lock_irq(shost->host_lock);
James Smart19878072009-12-21 17:02:00 -05005986 vport->vpi_state |= LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05005987 spin_unlock_irq(shost->host_lock);
5988 if (vport == phba->pport) {
James Smart6fb120a2009-05-22 14:52:59 -04005989 if (phba->sli_rev < LPFC_SLI_REV4)
5990 lpfc_issue_fabric_reglogin(vport);
James Smart695a8142010-01-26 23:08:03 -05005991 else {
5992 lpfc_start_fdiscs(phba);
5993 lpfc_do_scr_ns_plogi(phba, vport);
5994 }
5995 } else
James Smart92d7f7b2007-06-17 19:56:38 -05005996 lpfc_do_scr_ns_plogi(phba, vport);
5997 }
James Smartfa4066b2008-01-11 01:53:27 -05005998
5999 /* Now, we decrement the ndlp reference count held for this
6000 * callback function
6001 */
6002 lpfc_nlp_put(ndlp);
6003
James Smart92d7f7b2007-06-17 19:56:38 -05006004 mempool_free(pmb, phba->mbox_mem_pool);
6005 return;
6006}
6007
James Smarte59058c2008-08-24 21:49:00 -04006008/**
James Smart3621a712009-04-06 18:47:14 -04006009 * lpfc_register_new_vport - Register a new vport with a HBA
James Smarte59058c2008-08-24 21:49:00 -04006010 * @phba: pointer to lpfc hba data structure.
6011 * @vport: pointer to a host virtual N_Port data structure.
6012 * @ndlp: pointer to a node-list data structure.
6013 *
6014 * This routine registers the @vport as a new virtual port with a HBA.
6015 * It is done through a registering vpi mailbox command.
6016 **/
James Smart695a8142010-01-26 23:08:03 -05006017void
James Smart92d7f7b2007-06-17 19:56:38 -05006018lpfc_register_new_vport(struct lpfc_hba *phba, struct lpfc_vport *vport,
6019 struct lpfc_nodelist *ndlp)
6020{
James Smart09372822008-01-11 01:52:54 -05006021 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -05006022 LPFC_MBOXQ_t *mbox;
6023
6024 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
6025 if (mbox) {
James Smart6fb120a2009-05-22 14:52:59 -04006026 lpfc_reg_vpi(vport, mbox);
James Smart92d7f7b2007-06-17 19:56:38 -05006027 mbox->vport = vport;
6028 mbox->context2 = lpfc_nlp_get(ndlp);
6029 mbox->mbox_cmpl = lpfc_cmpl_reg_new_vport;
James Smart0b727fe2007-10-27 13:37:25 -04006030 if (lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT)
James Smart92d7f7b2007-06-17 19:56:38 -05006031 == MBX_NOT_FINISHED) {
James Smartfa4066b2008-01-11 01:53:27 -05006032 /* mailbox command not success, decrement ndlp
6033 * reference count for this command
6034 */
6035 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05006036 mempool_free(mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05006037
James Smarte8b62012007-08-02 11:10:09 -04006038 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
6039 "0253 Register VPI: Can't send mbox\n");
James Smartfa4066b2008-01-11 01:53:27 -05006040 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05006041 }
6042 } else {
James Smarte8b62012007-08-02 11:10:09 -04006043 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
6044 "0254 Register VPI: no memory\n");
James Smartfa4066b2008-01-11 01:53:27 -05006045 goto mbox_err_exit;
James Smart92d7f7b2007-06-17 19:56:38 -05006046 }
James Smartfa4066b2008-01-11 01:53:27 -05006047 return;
6048
6049mbox_err_exit:
6050 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6051 spin_lock_irq(shost->host_lock);
6052 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
6053 spin_unlock_irq(shost->host_lock);
6054 return;
James Smart92d7f7b2007-06-17 19:56:38 -05006055}
6056
James Smarte59058c2008-08-24 21:49:00 -04006057/**
James Smart695a8142010-01-26 23:08:03 -05006058 * lpfc_retry_pport_discovery - Start timer to retry FLOGI.
6059 * @phba: pointer to lpfc hba data structure.
6060 *
6061 * This routine abort all pending discovery commands and
6062 * start a timer to retry FLOGI for the physical port
6063 * discovery.
6064 **/
6065void
6066lpfc_retry_pport_discovery(struct lpfc_hba *phba)
6067{
6068 struct lpfc_vport **vports;
6069 struct lpfc_nodelist *ndlp;
6070 struct Scsi_Host *shost;
6071 int i;
6072 uint32_t link_state;
6073
6074 /* Treat this failure as linkdown for all vports */
6075 link_state = phba->link_state;
6076 lpfc_linkdown(phba);
6077 phba->link_state = link_state;
6078
6079 vports = lpfc_create_vport_work_array(phba);
6080
6081 if (vports) {
6082 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
6083 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
6084 if (ndlp)
6085 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
6086 lpfc_els_flush_cmd(vports[i]);
6087 }
6088 lpfc_destroy_vport_work_array(phba, vports);
6089 }
6090
6091 /* If fabric require FLOGI, then re-instantiate physical login */
6092 ndlp = lpfc_findnode_did(phba->pport, Fabric_DID);
6093 if (!ndlp)
6094 return;
6095
6096
6097 shost = lpfc_shost_from_vport(phba->pport);
6098 mod_timer(&ndlp->nlp_delayfunc, jiffies + HZ);
6099 spin_lock_irq(shost->host_lock);
6100 ndlp->nlp_flag |= NLP_DELAY_TMO;
6101 spin_unlock_irq(shost->host_lock);
6102 ndlp->nlp_last_elscmd = ELS_CMD_FLOGI;
6103 phba->pport->port_state = LPFC_FLOGI;
6104 return;
6105}
6106
6107/**
6108 * lpfc_fabric_login_reqd - Check if FLOGI required.
6109 * @phba: pointer to lpfc hba data structure.
6110 * @cmdiocb: pointer to FDISC command iocb.
6111 * @rspiocb: pointer to FDISC response iocb.
6112 *
6113 * This routine checks if a FLOGI is reguired for FDISC
6114 * to succeed.
6115 **/
6116static int
6117lpfc_fabric_login_reqd(struct lpfc_hba *phba,
6118 struct lpfc_iocbq *cmdiocb,
6119 struct lpfc_iocbq *rspiocb)
6120{
6121
6122 if ((rspiocb->iocb.ulpStatus != IOSTAT_FABRIC_RJT) ||
6123 (rspiocb->iocb.un.ulpWord[4] != RJT_LOGIN_REQUIRED))
6124 return 0;
6125 else
6126 return 1;
6127}
6128
6129/**
James Smart3621a712009-04-06 18:47:14 -04006130 * lpfc_cmpl_els_fdisc - Completion function for fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04006131 * @phba: pointer to lpfc hba data structure.
6132 * @cmdiocb: pointer to lpfc command iocb data structure.
6133 * @rspiocb: pointer to lpfc response iocb data structure.
6134 *
6135 * This routine is the completion callback function to a Fabric Discover
6136 * (FDISC) ELS command. Since all the FDISC ELS commands are issued
6137 * single threaded, each FDISC completion callback function will reset
6138 * the discovery timer for all vports such that the timers will not get
6139 * unnecessary timeout. The function checks the FDISC IOCB status. If error
6140 * detected, the vport will be set to FC_VPORT_FAILED state. Otherwise,the
6141 * vport will set to FC_VPORT_ACTIVE state. It then checks whether the DID
6142 * assigned to the vport has been changed with the completion of the FDISC
6143 * command. If so, both RPI (Remote Port Index) and VPI (Virtual Port Index)
6144 * are unregistered from the HBA, and then the lpfc_register_new_vport()
6145 * routine is invoked to register new vport with the HBA. Otherwise, the
6146 * lpfc_do_scr_ns_plogi() routine is invoked to issue a PLOGI to the Name
6147 * Server for State Change Request (SCR).
6148 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006149static void
6150lpfc_cmpl_els_fdisc(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6151 struct lpfc_iocbq *rspiocb)
6152{
6153 struct lpfc_vport *vport = cmdiocb->vport;
6154 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6155 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) cmdiocb->context1;
6156 struct lpfc_nodelist *np;
6157 struct lpfc_nodelist *next_np;
6158 IOCB_t *irsp = &rspiocb->iocb;
6159 struct lpfc_iocbq *piocb;
6160
James Smarte8b62012007-08-02 11:10:09 -04006161 lpfc_printf_vlog(vport, KERN_INFO, LOG_ELS,
6162 "0123 FDISC completes. x%x/x%x prevDID: x%x\n",
6163 irsp->ulpStatus, irsp->un.ulpWord[4],
6164 vport->fc_prevDID);
James Smart92d7f7b2007-06-17 19:56:38 -05006165 /* Since all FDISCs are being single threaded, we
6166 * must reset the discovery timer for ALL vports
6167 * waiting to send FDISC when one completes.
6168 */
6169 list_for_each_entry(piocb, &phba->fabric_iocb_list, list) {
6170 lpfc_set_disctmo(piocb->vport);
6171 }
6172
James Smart858c9f62007-06-17 19:56:39 -05006173 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6174 "FDISC cmpl: status:x%x/x%x prevdid:x%x",
6175 irsp->ulpStatus, irsp->un.ulpWord[4], vport->fc_prevDID);
6176
James Smart92d7f7b2007-06-17 19:56:38 -05006177 if (irsp->ulpStatus) {
James Smart695a8142010-01-26 23:08:03 -05006178
6179 if (lpfc_fabric_login_reqd(phba, cmdiocb, rspiocb)) {
6180 lpfc_retry_pport_discovery(phba);
6181 goto out;
6182 }
6183
James Smart92d7f7b2007-06-17 19:56:38 -05006184 /* Check for retry */
6185 if (lpfc_els_retry(phba, cmdiocb, rspiocb))
6186 goto out;
James Smart92d7f7b2007-06-17 19:56:38 -05006187 /* FDISC failed */
James Smarte8b62012007-08-02 11:10:09 -04006188 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
James Smartd7c255b2008-08-24 21:50:00 -04006189 "0126 FDISC failed. (%d/%d)\n",
James Smarte8b62012007-08-02 11:10:09 -04006190 irsp->ulpStatus, irsp->un.ulpWord[4]);
James Smartd7c255b2008-08-24 21:50:00 -04006191 goto fdisc_failed;
6192 }
James Smartd7c255b2008-08-24 21:50:00 -04006193 spin_lock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05006194 vport->fc_flag &= ~FC_VPORT_CVL_RCVD;
James Smartd7c255b2008-08-24 21:50:00 -04006195 vport->fc_flag |= FC_FABRIC;
6196 if (vport->phba->fc_topology == TOPOLOGY_LOOP)
6197 vport->fc_flag |= FC_PUBLIC_LOOP;
6198 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006199
James Smartd7c255b2008-08-24 21:50:00 -04006200 vport->fc_myDID = irsp->un.ulpWord[4] & Mask_DID;
6201 lpfc_vport_set_state(vport, FC_VPORT_ACTIVE);
6202 if ((vport->fc_prevDID != vport->fc_myDID) &&
6203 !(vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)) {
6204 /* If our NportID changed, we need to ensure all
6205 * remaining NPORTs get unreg_login'ed so we can
6206 * issue unreg_vpi.
6207 */
6208 list_for_each_entry_safe(np, next_np,
6209 &vport->fc_nodes, nlp_listp) {
6210 if (!NLP_CHK_NODE_ACT(ndlp) ||
6211 (np->nlp_state != NLP_STE_NPR_NODE) ||
6212 !(np->nlp_flag & NLP_NPR_ADISC))
6213 continue;
James Smart09372822008-01-11 01:52:54 -05006214 spin_lock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04006215 np->nlp_flag &= ~NLP_NPR_ADISC;
James Smart09372822008-01-11 01:52:54 -05006216 spin_unlock_irq(shost->host_lock);
James Smartd7c255b2008-08-24 21:50:00 -04006217 lpfc_unreg_rpi(vport, np);
James Smart92d7f7b2007-06-17 19:56:38 -05006218 }
James Smartd7c255b2008-08-24 21:50:00 -04006219 lpfc_mbx_unreg_vpi(vport);
6220 spin_lock_irq(shost->host_lock);
6221 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smartecfd03c2010-02-12 14:41:27 -05006222 vport->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smartd7c255b2008-08-24 21:50:00 -04006223 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05006224 }
6225
James Smartecfd03c2010-02-12 14:41:27 -05006226 if (vport->fc_flag & FC_VPORT_NEEDS_INIT_VPI)
6227 lpfc_issue_init_vpi(vport);
6228 else if (vport->fc_flag & FC_VPORT_NEEDS_REG_VPI)
James Smartd7c255b2008-08-24 21:50:00 -04006229 lpfc_register_new_vport(phba, vport, ndlp);
6230 else
6231 lpfc_do_scr_ns_plogi(phba, vport);
6232 goto out;
6233fdisc_failed:
6234 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
6235 /* Cancel discovery timer */
6236 lpfc_can_disctmo(vport);
6237 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05006238out:
6239 lpfc_els_free_iocb(phba, cmdiocb);
6240}
6241
James Smarte59058c2008-08-24 21:49:00 -04006242/**
James Smart3621a712009-04-06 18:47:14 -04006243 * lpfc_issue_els_fdisc - Issue a fdisc iocb command
James Smarte59058c2008-08-24 21:49:00 -04006244 * @vport: pointer to a virtual N_Port data structure.
6245 * @ndlp: pointer to a node-list data structure.
6246 * @retry: number of retries to the command IOCB.
6247 *
6248 * This routine prepares and issues a Fabric Discover (FDISC) IOCB to
6249 * a remote node (@ndlp) off a @vport. It uses the lpfc_issue_fabric_iocb()
6250 * routine to issue the IOCB, which makes sure only one outstanding fabric
6251 * IOCB will be sent off HBA at any given time.
6252 *
6253 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6254 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6255 * will be stored into the context1 field of the IOCB for the completion
6256 * callback function to the FDISC ELS command.
6257 *
6258 * Return code
6259 * 0 - Successfully issued fdisc iocb command
6260 * 1 - Failed to issue fdisc iocb command
6261 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01006262static int
James Smart92d7f7b2007-06-17 19:56:38 -05006263lpfc_issue_els_fdisc(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
6264 uint8_t retry)
6265{
6266 struct lpfc_hba *phba = vport->phba;
6267 IOCB_t *icmd;
6268 struct lpfc_iocbq *elsiocb;
6269 struct serv_parm *sp;
6270 uint8_t *pcmd;
6271 uint16_t cmdsize;
6272 int did = ndlp->nlp_DID;
6273 int rc;
James Smart92d7f7b2007-06-17 19:56:38 -05006274
James Smart5ffc2662009-11-18 15:39:44 -05006275 vport->port_state = LPFC_FDISC;
James Smart92d7f7b2007-06-17 19:56:38 -05006276 cmdsize = (sizeof(uint32_t) + sizeof(struct serv_parm));
6277 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, retry, ndlp, did,
6278 ELS_CMD_FDISC);
6279 if (!elsiocb) {
James Smart92d7f7b2007-06-17 19:56:38 -05006280 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006281 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6282 "0255 Issue FDISC: no IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006283 return 1;
6284 }
6285
6286 icmd = &elsiocb->iocb;
6287 icmd->un.elsreq64.myID = 0;
6288 icmd->un.elsreq64.fl = 1;
6289
James Smartf1126682009-06-10 17:22:44 -04006290 if (phba->sli_rev == LPFC_SLI_REV4) {
6291 /* FDISC needs to be 1 for WQE VPI */
6292 elsiocb->iocb.ulpCt_h = (SLI4_CT_VPI >> 1) & 1;
6293 elsiocb->iocb.ulpCt_l = SLI4_CT_VPI & 1 ;
6294 /* Set the ulpContext to the vpi */
6295 elsiocb->iocb.ulpContext = vport->vpi + phba->vpi_base;
6296 } else {
6297 /* For FDISC, Let FDISC rsp set the NPortID for this VPI */
6298 icmd->ulpCt_h = 1;
6299 icmd->ulpCt_l = 0;
6300 }
James Smart92d7f7b2007-06-17 19:56:38 -05006301
6302 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6303 *((uint32_t *) (pcmd)) = ELS_CMD_FDISC;
6304 pcmd += sizeof(uint32_t); /* CSP Word 1 */
6305 memcpy(pcmd, &vport->phba->pport->fc_sparam, sizeof(struct serv_parm));
6306 sp = (struct serv_parm *) pcmd;
6307 /* Setup CSPs accordingly for Fabric */
6308 sp->cmn.e_d_tov = 0;
6309 sp->cmn.w2.r_a_tov = 0;
6310 sp->cls1.classValid = 0;
6311 sp->cls2.seqDelivery = 1;
6312 sp->cls3.seqDelivery = 1;
6313
6314 pcmd += sizeof(uint32_t); /* CSP Word 2 */
6315 pcmd += sizeof(uint32_t); /* CSP Word 3 */
6316 pcmd += sizeof(uint32_t); /* CSP Word 4 */
6317 pcmd += sizeof(uint32_t); /* Port Name */
6318 memcpy(pcmd, &vport->fc_portname, 8);
6319 pcmd += sizeof(uint32_t); /* Node Name */
6320 pcmd += sizeof(uint32_t); /* Node Name */
6321 memcpy(pcmd, &vport->fc_nodename, 8);
6322
6323 lpfc_set_disctmo(vport);
6324
6325 phba->fc_stat.elsXmitFDISC++;
6326 elsiocb->iocb_cmpl = lpfc_cmpl_els_fdisc;
6327
James Smart858c9f62007-06-17 19:56:39 -05006328 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6329 "Issue FDISC: did:x%x",
6330 did, 0, 0);
6331
James Smart92d7f7b2007-06-17 19:56:38 -05006332 rc = lpfc_issue_fabric_iocb(phba, elsiocb);
6333 if (rc == IOCB_ERROR) {
6334 lpfc_els_free_iocb(phba, elsiocb);
James Smart92d7f7b2007-06-17 19:56:38 -05006335 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04006336 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
6337 "0256 Issue FDISC: Cannot send IOCB\n");
James Smart92d7f7b2007-06-17 19:56:38 -05006338 return 1;
6339 }
6340 lpfc_vport_set_state(vport, FC_VPORT_INITIALIZING);
James Smart92d7f7b2007-06-17 19:56:38 -05006341 return 0;
6342}
6343
James Smarte59058c2008-08-24 21:49:00 -04006344/**
James Smart3621a712009-04-06 18:47:14 -04006345 * lpfc_cmpl_els_npiv_logo - Completion function with vport logo
James Smarte59058c2008-08-24 21:49:00 -04006346 * @phba: pointer to lpfc hba data structure.
6347 * @cmdiocb: pointer to lpfc command iocb data structure.
6348 * @rspiocb: pointer to lpfc response iocb data structure.
6349 *
6350 * This routine is the completion callback function to the issuing of a LOGO
6351 * ELS command off a vport. It frees the command IOCB and then decrement the
6352 * reference count held on ndlp for this completion function, indicating that
6353 * the reference to the ndlp is no long needed. Note that the
6354 * lpfc_els_free_iocb() routine decrements the ndlp reference held for this
6355 * callback function and an additional explicit ndlp reference decrementation
6356 * will trigger the actual release of the ndlp.
6357 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006358static void
6359lpfc_cmpl_els_npiv_logo(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6360 struct lpfc_iocbq *rspiocb)
6361{
6362 struct lpfc_vport *vport = cmdiocb->vport;
James Smart858c9f62007-06-17 19:56:39 -05006363 IOCB_t *irsp;
James Smarte47c9092008-02-08 18:49:26 -05006364 struct lpfc_nodelist *ndlp;
6365 ndlp = (struct lpfc_nodelist *)cmdiocb->context1;
James Smart858c9f62007-06-17 19:56:39 -05006366
6367 irsp = &rspiocb->iocb;
6368 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6369 "LOGO npiv cmpl: status:x%x/x%x did:x%x",
6370 irsp->ulpStatus, irsp->un.ulpWord[4], irsp->un.rcvels.remoteID);
James Smart92d7f7b2007-06-17 19:56:38 -05006371
6372 lpfc_els_free_iocb(phba, cmdiocb);
6373 vport->unreg_vpi_cmpl = VPORT_ERROR;
James Smarte47c9092008-02-08 18:49:26 -05006374
6375 /* Trigger the release of the ndlp after logo */
6376 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05006377}
6378
James Smarte59058c2008-08-24 21:49:00 -04006379/**
James Smart3621a712009-04-06 18:47:14 -04006380 * lpfc_issue_els_npiv_logo - Issue a logo off a vport
James Smarte59058c2008-08-24 21:49:00 -04006381 * @vport: pointer to a virtual N_Port data structure.
6382 * @ndlp: pointer to a node-list data structure.
6383 *
6384 * This routine issues a LOGO ELS command to an @ndlp off a @vport.
6385 *
6386 * Note that, in lpfc_prep_els_iocb() routine, the reference count of ndlp
6387 * will be incremented by 1 for holding the ndlp and the reference to ndlp
6388 * will be stored into the context1 field of the IOCB for the completion
6389 * callback function to the LOGO ELS command.
6390 *
6391 * Return codes
6392 * 0 - Successfully issued logo off the @vport
6393 * 1 - Failed to issue logo off the @vport
6394 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006395int
6396lpfc_issue_els_npiv_logo(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
6397{
6398 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
6399 struct lpfc_hba *phba = vport->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05006400 IOCB_t *icmd;
6401 struct lpfc_iocbq *elsiocb;
6402 uint8_t *pcmd;
6403 uint16_t cmdsize;
6404
6405 cmdsize = 2 * sizeof(uint32_t) + sizeof(struct lpfc_name);
6406 elsiocb = lpfc_prep_els_iocb(vport, 1, cmdsize, 0, ndlp, ndlp->nlp_DID,
6407 ELS_CMD_LOGO);
6408 if (!elsiocb)
6409 return 1;
6410
6411 icmd = &elsiocb->iocb;
6412 pcmd = (uint8_t *) (((struct lpfc_dmabuf *) elsiocb->context2)->virt);
6413 *((uint32_t *) (pcmd)) = ELS_CMD_LOGO;
6414 pcmd += sizeof(uint32_t);
6415
6416 /* Fill in LOGO payload */
6417 *((uint32_t *) (pcmd)) = be32_to_cpu(vport->fc_myDID);
6418 pcmd += sizeof(uint32_t);
6419 memcpy(pcmd, &vport->fc_portname, sizeof(struct lpfc_name));
6420
James Smart858c9f62007-06-17 19:56:39 -05006421 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
6422 "Issue LOGO npiv did:x%x flg:x%x",
6423 ndlp->nlp_DID, ndlp->nlp_flag, 0);
6424
James Smart92d7f7b2007-06-17 19:56:38 -05006425 elsiocb->iocb_cmpl = lpfc_cmpl_els_npiv_logo;
6426 spin_lock_irq(shost->host_lock);
6427 ndlp->nlp_flag |= NLP_LOGO_SND;
6428 spin_unlock_irq(shost->host_lock);
James Smart3772a992009-05-22 14:50:54 -04006429 if (lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, elsiocb, 0) ==
6430 IOCB_ERROR) {
James Smart92d7f7b2007-06-17 19:56:38 -05006431 spin_lock_irq(shost->host_lock);
6432 ndlp->nlp_flag &= ~NLP_LOGO_SND;
6433 spin_unlock_irq(shost->host_lock);
6434 lpfc_els_free_iocb(phba, elsiocb);
6435 return 1;
6436 }
6437 return 0;
6438}
6439
James Smarte59058c2008-08-24 21:49:00 -04006440/**
James Smart3621a712009-04-06 18:47:14 -04006441 * lpfc_fabric_block_timeout - Handler function to the fabric block timer
James Smarte59058c2008-08-24 21:49:00 -04006442 * @ptr: holder for the timer function associated data.
6443 *
6444 * This routine is invoked by the fabric iocb block timer after
6445 * timeout. It posts the fabric iocb block timeout event by setting the
6446 * WORKER_FABRIC_BLOCK_TMO bit to work port event bitmap and then invokes
6447 * lpfc_worker_wake_up() routine to wake up the worker thread. It is for
6448 * the worker thread to invoke the lpfc_unblock_fabric_iocbs() on the
6449 * posted event WORKER_FABRIC_BLOCK_TMO.
6450 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006451void
6452lpfc_fabric_block_timeout(unsigned long ptr)
6453{
6454 struct lpfc_hba *phba = (struct lpfc_hba *) ptr;
6455 unsigned long iflags;
6456 uint32_t tmo_posted;
James Smart5e9d9b82008-06-14 22:52:53 -04006457
James Smart92d7f7b2007-06-17 19:56:38 -05006458 spin_lock_irqsave(&phba->pport->work_port_lock, iflags);
6459 tmo_posted = phba->pport->work_port_events & WORKER_FABRIC_BLOCK_TMO;
6460 if (!tmo_posted)
6461 phba->pport->work_port_events |= WORKER_FABRIC_BLOCK_TMO;
6462 spin_unlock_irqrestore(&phba->pport->work_port_lock, iflags);
6463
James Smart5e9d9b82008-06-14 22:52:53 -04006464 if (!tmo_posted)
6465 lpfc_worker_wake_up(phba);
6466 return;
James Smart92d7f7b2007-06-17 19:56:38 -05006467}
6468
James Smarte59058c2008-08-24 21:49:00 -04006469/**
James Smart3621a712009-04-06 18:47:14 -04006470 * lpfc_resume_fabric_iocbs - Issue a fabric iocb from driver internal list
James Smarte59058c2008-08-24 21:49:00 -04006471 * @phba: pointer to lpfc hba data structure.
6472 *
6473 * This routine issues one fabric iocb from the driver internal list to
6474 * the HBA. It first checks whether it's ready to issue one fabric iocb to
6475 * the HBA (whether there is no outstanding fabric iocb). If so, it shall
6476 * remove one pending fabric iocb from the driver internal list and invokes
6477 * lpfc_sli_issue_iocb() routine to send the fabric iocb to the HBA.
6478 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006479static void
6480lpfc_resume_fabric_iocbs(struct lpfc_hba *phba)
6481{
6482 struct lpfc_iocbq *iocb;
6483 unsigned long iflags;
6484 int ret;
James Smart92d7f7b2007-06-17 19:56:38 -05006485 IOCB_t *cmd;
6486
6487repeat:
6488 iocb = NULL;
6489 spin_lock_irqsave(&phba->hbalock, iflags);
James Smart7f5f3d02008-02-08 18:50:14 -05006490 /* Post any pending iocb to the SLI layer */
James Smart92d7f7b2007-06-17 19:56:38 -05006491 if (atomic_read(&phba->fabric_iocb_count) == 0) {
6492 list_remove_head(&phba->fabric_iocb_list, iocb, typeof(*iocb),
6493 list);
6494 if (iocb)
James Smart7f5f3d02008-02-08 18:50:14 -05006495 /* Increment fabric iocb count to hold the position */
James Smart92d7f7b2007-06-17 19:56:38 -05006496 atomic_inc(&phba->fabric_iocb_count);
6497 }
6498 spin_unlock_irqrestore(&phba->hbalock, iflags);
6499 if (iocb) {
6500 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
6501 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
6502 iocb->iocb_flag |= LPFC_IO_FABRIC;
6503
James Smart858c9f62007-06-17 19:56:39 -05006504 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
6505 "Fabric sched1: ste:x%x",
6506 iocb->vport->port_state, 0, 0);
6507
James Smart3772a992009-05-22 14:50:54 -04006508 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05006509
6510 if (ret == IOCB_ERROR) {
6511 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
6512 iocb->fabric_iocb_cmpl = NULL;
6513 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
6514 cmd = &iocb->iocb;
6515 cmd->ulpStatus = IOSTAT_LOCAL_REJECT;
6516 cmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
6517 iocb->iocb_cmpl(phba, iocb, iocb);
6518
6519 atomic_dec(&phba->fabric_iocb_count);
6520 goto repeat;
6521 }
6522 }
6523
6524 return;
6525}
6526
James Smarte59058c2008-08-24 21:49:00 -04006527/**
James Smart3621a712009-04-06 18:47:14 -04006528 * lpfc_unblock_fabric_iocbs - Unblock issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04006529 * @phba: pointer to lpfc hba data structure.
6530 *
6531 * This routine unblocks the issuing fabric iocb command. The function
6532 * will clear the fabric iocb block bit and then invoke the routine
6533 * lpfc_resume_fabric_iocbs() to issue one of the pending fabric iocb
6534 * from the driver internal fabric iocb list.
6535 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006536void
6537lpfc_unblock_fabric_iocbs(struct lpfc_hba *phba)
6538{
6539 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
6540
6541 lpfc_resume_fabric_iocbs(phba);
6542 return;
6543}
6544
James Smarte59058c2008-08-24 21:49:00 -04006545/**
James Smart3621a712009-04-06 18:47:14 -04006546 * lpfc_block_fabric_iocbs - Block issuing fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04006547 * @phba: pointer to lpfc hba data structure.
6548 *
6549 * This routine blocks the issuing fabric iocb for a specified amount of
6550 * time (currently 100 ms). This is done by set the fabric iocb block bit
6551 * and set up a timeout timer for 100ms. When the block bit is set, no more
6552 * fabric iocb will be issued out of the HBA.
6553 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006554static void
6555lpfc_block_fabric_iocbs(struct lpfc_hba *phba)
6556{
6557 int blocked;
6558
6559 blocked = test_and_set_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
James Smart7f5f3d02008-02-08 18:50:14 -05006560 /* Start a timer to unblock fabric iocbs after 100ms */
James Smart92d7f7b2007-06-17 19:56:38 -05006561 if (!blocked)
6562 mod_timer(&phba->fabric_block_timer, jiffies + HZ/10 );
6563
6564 return;
6565}
6566
James Smarte59058c2008-08-24 21:49:00 -04006567/**
James Smart3621a712009-04-06 18:47:14 -04006568 * lpfc_cmpl_fabric_iocb - Completion callback function for fabric iocb
James Smarte59058c2008-08-24 21:49:00 -04006569 * @phba: pointer to lpfc hba data structure.
6570 * @cmdiocb: pointer to lpfc command iocb data structure.
6571 * @rspiocb: pointer to lpfc response iocb data structure.
6572 *
6573 * This routine is the callback function that is put to the fabric iocb's
6574 * callback function pointer (iocb->iocb_cmpl). The original iocb's callback
6575 * function pointer has been stored in iocb->fabric_iocb_cmpl. This callback
6576 * function first restores and invokes the original iocb's callback function
6577 * and then invokes the lpfc_resume_fabric_iocbs() routine to issue the next
6578 * fabric bound iocb from the driver internal fabric iocb list onto the wire.
6579 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006580static void
6581lpfc_cmpl_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *cmdiocb,
6582 struct lpfc_iocbq *rspiocb)
6583{
6584 struct ls_rjt stat;
6585
6586 if ((cmdiocb->iocb_flag & LPFC_IO_FABRIC) != LPFC_IO_FABRIC)
6587 BUG();
6588
6589 switch (rspiocb->iocb.ulpStatus) {
6590 case IOSTAT_NPORT_RJT:
6591 case IOSTAT_FABRIC_RJT:
6592 if (rspiocb->iocb.un.ulpWord[4] & RJT_UNAVAIL_TEMP) {
6593 lpfc_block_fabric_iocbs(phba);
6594 }
6595 break;
6596
6597 case IOSTAT_NPORT_BSY:
6598 case IOSTAT_FABRIC_BSY:
6599 lpfc_block_fabric_iocbs(phba);
6600 break;
6601
6602 case IOSTAT_LS_RJT:
6603 stat.un.lsRjtError =
6604 be32_to_cpu(rspiocb->iocb.un.ulpWord[4]);
6605 if ((stat.un.b.lsRjtRsnCode == LSRJT_UNABLE_TPC) ||
6606 (stat.un.b.lsRjtRsnCode == LSRJT_LOGICAL_BSY))
6607 lpfc_block_fabric_iocbs(phba);
6608 break;
6609 }
6610
6611 if (atomic_read(&phba->fabric_iocb_count) == 0)
6612 BUG();
6613
6614 cmdiocb->iocb_cmpl = cmdiocb->fabric_iocb_cmpl;
6615 cmdiocb->fabric_iocb_cmpl = NULL;
6616 cmdiocb->iocb_flag &= ~LPFC_IO_FABRIC;
6617 cmdiocb->iocb_cmpl(phba, cmdiocb, rspiocb);
6618
6619 atomic_dec(&phba->fabric_iocb_count);
6620 if (!test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags)) {
James Smart7f5f3d02008-02-08 18:50:14 -05006621 /* Post any pending iocbs to HBA */
6622 lpfc_resume_fabric_iocbs(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05006623 }
6624}
6625
James Smarte59058c2008-08-24 21:49:00 -04006626/**
James Smart3621a712009-04-06 18:47:14 -04006627 * lpfc_issue_fabric_iocb - Issue a fabric iocb command
James Smarte59058c2008-08-24 21:49:00 -04006628 * @phba: pointer to lpfc hba data structure.
6629 * @iocb: pointer to lpfc command iocb data structure.
6630 *
6631 * This routine is used as the top-level API for issuing a fabric iocb command
6632 * such as FLOGI and FDISC. To accommodate certain switch fabric, this driver
6633 * function makes sure that only one fabric bound iocb will be outstanding at
6634 * any given time. As such, this function will first check to see whether there
6635 * is already an outstanding fabric iocb on the wire. If so, it will put the
6636 * newly issued iocb onto the driver internal fabric iocb list, waiting to be
6637 * issued later. Otherwise, it will issue the iocb on the wire and update the
6638 * fabric iocb count it indicate that there is one fabric iocb on the wire.
6639 *
6640 * Note, this implementation has a potential sending out fabric IOCBs out of
6641 * order. The problem is caused by the construction of the "ready" boolen does
6642 * not include the condition that the internal fabric IOCB list is empty. As
6643 * such, it is possible a fabric IOCB issued by this routine might be "jump"
6644 * ahead of the fabric IOCBs in the internal list.
6645 *
6646 * Return code
6647 * IOCB_SUCCESS - either fabric iocb put on the list or issued successfully
6648 * IOCB_ERROR - failed to issue fabric iocb
6649 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01006650static int
James Smart92d7f7b2007-06-17 19:56:38 -05006651lpfc_issue_fabric_iocb(struct lpfc_hba *phba, struct lpfc_iocbq *iocb)
6652{
6653 unsigned long iflags;
James Smart92d7f7b2007-06-17 19:56:38 -05006654 int ready;
6655 int ret;
6656
6657 if (atomic_read(&phba->fabric_iocb_count) > 1)
6658 BUG();
6659
6660 spin_lock_irqsave(&phba->hbalock, iflags);
6661 ready = atomic_read(&phba->fabric_iocb_count) == 0 &&
6662 !test_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
6663
James Smart7f5f3d02008-02-08 18:50:14 -05006664 if (ready)
6665 /* Increment fabric iocb count to hold the position */
6666 atomic_inc(&phba->fabric_iocb_count);
James Smart92d7f7b2007-06-17 19:56:38 -05006667 spin_unlock_irqrestore(&phba->hbalock, iflags);
6668 if (ready) {
6669 iocb->fabric_iocb_cmpl = iocb->iocb_cmpl;
6670 iocb->iocb_cmpl = lpfc_cmpl_fabric_iocb;
6671 iocb->iocb_flag |= LPFC_IO_FABRIC;
6672
James Smart858c9f62007-06-17 19:56:39 -05006673 lpfc_debugfs_disc_trc(iocb->vport, LPFC_DISC_TRC_ELS_CMD,
6674 "Fabric sched2: ste:x%x",
6675 iocb->vport->port_state, 0, 0);
6676
James Smart3772a992009-05-22 14:50:54 -04006677 ret = lpfc_sli_issue_iocb(phba, LPFC_ELS_RING, iocb, 0);
James Smart92d7f7b2007-06-17 19:56:38 -05006678
6679 if (ret == IOCB_ERROR) {
6680 iocb->iocb_cmpl = iocb->fabric_iocb_cmpl;
6681 iocb->fabric_iocb_cmpl = NULL;
6682 iocb->iocb_flag &= ~LPFC_IO_FABRIC;
6683 atomic_dec(&phba->fabric_iocb_count);
6684 }
6685 } else {
6686 spin_lock_irqsave(&phba->hbalock, iflags);
6687 list_add_tail(&iocb->list, &phba->fabric_iocb_list);
6688 spin_unlock_irqrestore(&phba->hbalock, iflags);
6689 ret = IOCB_SUCCESS;
6690 }
6691 return ret;
6692}
6693
James Smarte59058c2008-08-24 21:49:00 -04006694/**
James Smart3621a712009-04-06 18:47:14 -04006695 * lpfc_fabric_abort_vport - Abort a vport's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04006696 * @vport: pointer to a virtual N_Port data structure.
6697 *
6698 * This routine aborts all the IOCBs associated with a @vport from the
6699 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
6700 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
6701 * list, removes each IOCB associated with the @vport off the list, set the
6702 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
6703 * associated with the IOCB.
6704 **/
Adrian Bunka6ababd2007-11-05 18:07:33 +01006705static void lpfc_fabric_abort_vport(struct lpfc_vport *vport)
James Smart92d7f7b2007-06-17 19:56:38 -05006706{
6707 LIST_HEAD(completions);
6708 struct lpfc_hba *phba = vport->phba;
6709 struct lpfc_iocbq *tmp_iocb, *piocb;
James Smart92d7f7b2007-06-17 19:56:38 -05006710
6711 spin_lock_irq(&phba->hbalock);
6712 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
6713 list) {
6714
6715 if (piocb->vport != vport)
6716 continue;
6717
6718 list_move_tail(&piocb->list, &completions);
6719 }
6720 spin_unlock_irq(&phba->hbalock);
6721
James Smarta257bf92009-04-06 18:48:10 -04006722 /* Cancel all the IOCBs from the completions list */
6723 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6724 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05006725}
6726
James Smarte59058c2008-08-24 21:49:00 -04006727/**
James Smart3621a712009-04-06 18:47:14 -04006728 * lpfc_fabric_abort_nport - Abort a ndlp's iocbs from driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04006729 * @ndlp: pointer to a node-list data structure.
6730 *
6731 * This routine aborts all the IOCBs associated with an @ndlp from the
6732 * driver internal fabric IOCB list. The list contains fabric IOCBs to be
6733 * issued to the ELS IOCB ring. This abort function walks the fabric IOCB
6734 * list, removes each IOCB associated with the @ndlp off the list, set the
6735 * status feild to IOSTAT_LOCAL_REJECT, and invokes the callback function
6736 * associated with the IOCB.
6737 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006738void lpfc_fabric_abort_nport(struct lpfc_nodelist *ndlp)
6739{
6740 LIST_HEAD(completions);
James Smarta257bf92009-04-06 18:48:10 -04006741 struct lpfc_hba *phba = ndlp->phba;
James Smart92d7f7b2007-06-17 19:56:38 -05006742 struct lpfc_iocbq *tmp_iocb, *piocb;
6743 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart92d7f7b2007-06-17 19:56:38 -05006744
6745 spin_lock_irq(&phba->hbalock);
6746 list_for_each_entry_safe(piocb, tmp_iocb, &phba->fabric_iocb_list,
6747 list) {
6748 if ((lpfc_check_sli_ndlp(phba, pring, piocb, ndlp))) {
6749
6750 list_move_tail(&piocb->list, &completions);
6751 }
6752 }
6753 spin_unlock_irq(&phba->hbalock);
6754
James Smarta257bf92009-04-06 18:48:10 -04006755 /* Cancel all the IOCBs from the completions list */
6756 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6757 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05006758}
6759
James Smarte59058c2008-08-24 21:49:00 -04006760/**
James Smart3621a712009-04-06 18:47:14 -04006761 * lpfc_fabric_abort_hba - Abort all iocbs on driver fabric iocb list
James Smarte59058c2008-08-24 21:49:00 -04006762 * @phba: pointer to lpfc hba data structure.
6763 *
6764 * This routine aborts all the IOCBs currently on the driver internal
6765 * fabric IOCB list. The list contains fabric IOCBs to be issued to the ELS
6766 * IOCB ring. This function takes the entire IOCB list off the fabric IOCB
6767 * list, removes IOCBs off the list, set the status feild to
6768 * IOSTAT_LOCAL_REJECT, and invokes the callback function associated with
6769 * the IOCB.
6770 **/
James Smart92d7f7b2007-06-17 19:56:38 -05006771void lpfc_fabric_abort_hba(struct lpfc_hba *phba)
6772{
6773 LIST_HEAD(completions);
James Smart92d7f7b2007-06-17 19:56:38 -05006774
6775 spin_lock_irq(&phba->hbalock);
6776 list_splice_init(&phba->fabric_iocb_list, &completions);
6777 spin_unlock_irq(&phba->hbalock);
6778
James Smarta257bf92009-04-06 18:48:10 -04006779 /* Cancel all the IOCBs from the completions list */
6780 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
6781 IOERR_SLI_ABORTED);
James Smart92d7f7b2007-06-17 19:56:38 -05006782}
James Smart6fb120a2009-05-22 14:52:59 -04006783
6784/**
6785 * lpfc_sli4_els_xri_aborted - Slow-path process of els xri abort
6786 * @phba: pointer to lpfc hba data structure.
6787 * @axri: pointer to the els xri abort wcqe structure.
6788 *
6789 * This routine is invoked by the worker thread to process a SLI4 slow-path
6790 * ELS aborted xri.
6791 **/
6792void
6793lpfc_sli4_els_xri_aborted(struct lpfc_hba *phba,
6794 struct sli4_wcqe_xri_aborted *axri)
6795{
6796 uint16_t xri = bf_get(lpfc_wcqe_xa_xri, axri);
6797 struct lpfc_sglq *sglq_entry = NULL, *sglq_next = NULL;
6798 unsigned long iflag = 0;
6799
6800 spin_lock_irqsave(&phba->sli4_hba.abts_sgl_list_lock, iflag);
6801 list_for_each_entry_safe(sglq_entry, sglq_next,
6802 &phba->sli4_hba.lpfc_abts_els_sgl_list, list) {
6803 if (sglq_entry->sli4_xritag == xri) {
6804 list_del(&sglq_entry->list);
6805 spin_unlock_irqrestore(
6806 &phba->sli4_hba.abts_sgl_list_lock,
6807 iflag);
6808 spin_lock_irqsave(&phba->hbalock, iflag);
6809
6810 list_add_tail(&sglq_entry->list,
6811 &phba->sli4_hba.lpfc_sgl_list);
6812 spin_unlock_irqrestore(&phba->hbalock, iflag);
6813 return;
6814 }
6815 }
6816 spin_unlock_irqrestore(&phba->sli4_hba.abts_sgl_list_lock, iflag);
6817}