blob: e8d27c9585100812b49ef1169315e5752ae4ec1d [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 *******************************************************************/
21
dea31012005-04-17 16:05:31 -050022#include <linux/blkdev.h>
James Smarta93ff372010-10-22 11:06:08 -040023#include <linux/delay.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090024#include <linux/slab.h>
dea31012005-04-17 16:05:31 -050025#include <linux/pci.h>
26#include <linux/kthread.h>
27#include <linux/interrupt.h>
28
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040029#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050030#include <scsi/scsi_device.h>
31#include <scsi/scsi_host.h>
32#include <scsi/scsi_transport_fc.h>
33
James Smartda0436e2009-05-22 14:51:39 -040034#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050035#include "lpfc_hw.h"
James Smartea2151b2008-09-07 11:52:10 -040036#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050037#include "lpfc_disc.h"
38#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040039#include "lpfc_sli4.h"
dea31012005-04-17 16:05:31 -050040#include "lpfc_scsi.h"
41#include "lpfc.h"
42#include "lpfc_logmsg.h"
43#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050044#include "lpfc_vport.h"
James Smart858c9f62007-06-17 19:56:39 -050045#include "lpfc_debugfs.h"
dea31012005-04-17 16:05:31 -050046
47/* AlpaArray for assignment of scsid for scan-down and bind_method */
48static uint8_t lpfcAlpaArray[] = {
49 0xEF, 0xE8, 0xE4, 0xE2, 0xE1, 0xE0, 0xDC, 0xDA, 0xD9, 0xD6,
50 0xD5, 0xD4, 0xD3, 0xD2, 0xD1, 0xCE, 0xCD, 0xCC, 0xCB, 0xCA,
51 0xC9, 0xC7, 0xC6, 0xC5, 0xC3, 0xBC, 0xBA, 0xB9, 0xB6, 0xB5,
52 0xB4, 0xB3, 0xB2, 0xB1, 0xAE, 0xAD, 0xAC, 0xAB, 0xAA, 0xA9,
53 0xA7, 0xA6, 0xA5, 0xA3, 0x9F, 0x9E, 0x9D, 0x9B, 0x98, 0x97,
54 0x90, 0x8F, 0x88, 0x84, 0x82, 0x81, 0x80, 0x7C, 0x7A, 0x79,
55 0x76, 0x75, 0x74, 0x73, 0x72, 0x71, 0x6E, 0x6D, 0x6C, 0x6B,
56 0x6A, 0x69, 0x67, 0x66, 0x65, 0x63, 0x5C, 0x5A, 0x59, 0x56,
57 0x55, 0x54, 0x53, 0x52, 0x51, 0x4E, 0x4D, 0x4C, 0x4B, 0x4A,
58 0x49, 0x47, 0x46, 0x45, 0x43, 0x3C, 0x3A, 0x39, 0x36, 0x35,
59 0x34, 0x33, 0x32, 0x31, 0x2E, 0x2D, 0x2C, 0x2B, 0x2A, 0x29,
60 0x27, 0x26, 0x25, 0x23, 0x1F, 0x1E, 0x1D, 0x1B, 0x18, 0x17,
61 0x10, 0x0F, 0x08, 0x04, 0x02, 0x01
62};
63
James Smart2e0fef82007-06-17 19:56:36 -050064static void lpfc_disc_timeout_handler(struct lpfc_vport *);
Adrian Bunka6ababd2007-11-05 18:07:33 +010065static void lpfc_disc_flush_list(struct lpfc_vport *vport);
James Smart32b97932009-07-19 10:01:21 -040066static void lpfc_unregister_fcfi_cmpl(struct lpfc_hba *, LPFC_MBOXQ_t *);
James Smarta93ff372010-10-22 11:06:08 -040067static int lpfc_fcf_inuse(struct lpfc_hba *);
dea31012005-04-17 16:05:31 -050068
James Smartc01f3202006-08-18 17:47:08 -040069void
70lpfc_terminate_rport_io(struct fc_rport *rport)
dea31012005-04-17 16:05:31 -050071{
James Smartc01f3202006-08-18 17:47:08 -040072 struct lpfc_rport_data *rdata;
73 struct lpfc_nodelist * ndlp;
74 struct lpfc_hba *phba;
dea31012005-04-17 16:05:31 -050075
James Smartc01f3202006-08-18 17:47:08 -040076 rdata = rport->dd_data;
77 ndlp = rdata->pnode;
78
James Smart58da1ff2008-04-07 10:15:56 -040079 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smartc01f3202006-08-18 17:47:08 -040080 if (rport->roles & FC_RPORT_ROLE_FCP_TARGET)
81 printk(KERN_ERR "Cannot find remote node"
82 " to terminate I/O Data x%x\n",
83 rport->port_id);
dea31012005-04-17 16:05:31 -050084 return;
85 }
86
James Smarta257bf92009-04-06 18:48:10 -040087 phba = ndlp->phba;
James Smart1a169682006-03-07 15:04:06 -050088
James Smart858c9f62007-06-17 19:56:39 -050089 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_RPORT,
90 "rport terminate: sid:x%x did:x%x flg:x%x",
91 ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag);
92
James Smartc01f3202006-08-18 17:47:08 -040093 if (ndlp->nlp_sid != NLP_NO_SID) {
James Smart51ef4c22007-08-02 11:10:31 -040094 lpfc_sli_abort_iocb(ndlp->vport,
95 &phba->sli.ring[phba->sli.fcp_ring],
96 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
James Smartc01f3202006-08-18 17:47:08 -040097 }
James Smartc01f3202006-08-18 17:47:08 -040098}
99
100/*
101 * This function will be called when dev_loss_tmo fire.
102 */
103void
104lpfc_dev_loss_tmo_callbk(struct fc_rport *rport)
105{
106 struct lpfc_rport_data *rdata;
107 struct lpfc_nodelist * ndlp;
James Smart2e0fef82007-06-17 19:56:36 -0500108 struct lpfc_vport *vport;
James Smart858c9f62007-06-17 19:56:39 -0500109 struct lpfc_hba *phba;
James Smart858c9f62007-06-17 19:56:39 -0500110 struct lpfc_work_evt *evtp;
James Smarta8adb832007-10-27 13:37:53 -0400111 int put_node;
112 int put_rport;
James Smartc01f3202006-08-18 17:47:08 -0400113
114 rdata = rport->dd_data;
115 ndlp = rdata->pnode;
James Smart58da1ff2008-04-07 10:15:56 -0400116 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
James Smartc01f3202006-08-18 17:47:08 -0400117 return;
James Smartc01f3202006-08-18 17:47:08 -0400118
James Smart858c9f62007-06-17 19:56:39 -0500119 vport = ndlp->vport;
120 phba = vport->phba;
121
122 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
123 "rport devlosscb: sid:x%x did:x%x flg:x%x",
124 ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag);
125
James Smarta8adb832007-10-27 13:37:53 -0400126 /* Don't defer this if we are in the process of deleting the vport
127 * or unloading the driver. The unload will cleanup the node
128 * appropriately we just need to cleanup the ndlp rport info here.
129 */
130 if (vport->load_flag & FC_UNLOADING) {
131 put_node = rdata->pnode != NULL;
132 put_rport = ndlp->rport != NULL;
133 rdata->pnode = NULL;
134 ndlp->rport = NULL;
135 if (put_node)
136 lpfc_nlp_put(ndlp);
137 if (put_rport)
138 put_device(&rport->dev);
139 return;
140 }
141
142 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE)
143 return;
144
James Smart858c9f62007-06-17 19:56:39 -0500145 evtp = &ndlp->dev_loss_evt;
146
147 if (!list_empty(&evtp->evt_listp))
148 return;
149
150 spin_lock_irq(&phba->hbalock);
James Smartfa4066b2008-01-11 01:53:27 -0500151 /* We need to hold the node by incrementing the reference
152 * count until this queued work is done
153 */
154 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
James Smart5e9d9b82008-06-14 22:52:53 -0400155 if (evtp->evt_arg1) {
156 evtp->evt = LPFC_EVT_DEV_LOSS;
157 list_add_tail(&evtp->evt_listp, &phba->work_list);
158 lpfc_worker_wake_up(phba);
159 }
James Smart858c9f62007-06-17 19:56:39 -0500160 spin_unlock_irq(&phba->hbalock);
161
James Smart858c9f62007-06-17 19:56:39 -0500162 return;
163}
164
James Smarta93ff372010-10-22 11:06:08 -0400165/**
166 * lpfc_dev_loss_tmo_handler - Remote node devloss timeout handler
167 * @ndlp: Pointer to remote node object.
168 *
169 * This function is called from the worker thread when devloss timeout timer
170 * expires. For SLI4 host, this routine shall return 1 when at lease one
171 * remote node, including this @ndlp, is still in use of FCF; otherwise, this
172 * routine shall return 0 when there is no remote node is still in use of FCF
173 * when devloss timeout happened to this @ndlp.
174 **/
175static int
James Smart858c9f62007-06-17 19:56:39 -0500176lpfc_dev_loss_tmo_handler(struct lpfc_nodelist *ndlp)
177{
178 struct lpfc_rport_data *rdata;
179 struct fc_rport *rport;
180 struct lpfc_vport *vport;
181 struct lpfc_hba *phba;
182 uint8_t *name;
James Smart87af33f2007-10-27 13:37:43 -0400183 int put_node;
184 int put_rport;
James Smart858c9f62007-06-17 19:56:39 -0500185 int warn_on = 0;
James Smarta93ff372010-10-22 11:06:08 -0400186 int fcf_inuse = 0;
James Smart858c9f62007-06-17 19:56:39 -0500187
188 rport = ndlp->rport;
189
190 if (!rport)
James Smarta93ff372010-10-22 11:06:08 -0400191 return fcf_inuse;
James Smart858c9f62007-06-17 19:56:39 -0500192
193 rdata = rport->dd_data;
194 name = (uint8_t *) &ndlp->nlp_portname;
195 vport = ndlp->vport;
196 phba = vport->phba;
197
James Smarta93ff372010-10-22 11:06:08 -0400198 if (phba->sli_rev == LPFC_SLI_REV4)
199 fcf_inuse = lpfc_fcf_inuse(phba);
200
James Smart858c9f62007-06-17 19:56:39 -0500201 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
202 "rport devlosstmo:did:x%x type:x%x id:x%x",
203 ndlp->nlp_DID, ndlp->nlp_type, rport->scsi_target_id);
204
James Smarta8adb832007-10-27 13:37:53 -0400205 /* Don't defer this if we are in the process of deleting the vport
206 * or unloading the driver. The unload will cleanup the node
207 * appropriately we just need to cleanup the ndlp rport info here.
208 */
209 if (vport->load_flag & FC_UNLOADING) {
James Smart09372822008-01-11 01:52:54 -0500210 if (ndlp->nlp_sid != NLP_NO_SID) {
211 /* flush the target */
212 lpfc_sli_abort_iocb(vport,
213 &phba->sli.ring[phba->sli.fcp_ring],
214 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
215 }
James Smarta8adb832007-10-27 13:37:53 -0400216 put_node = rdata->pnode != NULL;
217 put_rport = ndlp->rport != NULL;
218 rdata->pnode = NULL;
219 ndlp->rport = NULL;
220 if (put_node)
221 lpfc_nlp_put(ndlp);
222 if (put_rport)
223 put_device(&rport->dev);
James Smarta93ff372010-10-22 11:06:08 -0400224 return fcf_inuse;
James Smarta8adb832007-10-27 13:37:53 -0400225 }
226
James Smartd7c255b2008-08-24 21:50:00 -0400227 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE) {
228 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
229 "0284 Devloss timeout Ignored on "
230 "WWPN %x:%x:%x:%x:%x:%x:%x:%x "
231 "NPort x%x\n",
232 *name, *(name+1), *(name+2), *(name+3),
233 *(name+4), *(name+5), *(name+6), *(name+7),
234 ndlp->nlp_DID);
James Smarta93ff372010-10-22 11:06:08 -0400235 return fcf_inuse;
James Smartd7c255b2008-08-24 21:50:00 -0400236 }
James Smart858c9f62007-06-17 19:56:39 -0500237
James Smart92d7f7b2007-06-17 19:56:38 -0500238 if (ndlp->nlp_type & NLP_FABRIC) {
239 /* We will clean up these Nodes in linkup */
240 put_node = rdata->pnode != NULL;
241 put_rport = ndlp->rport != NULL;
242 rdata->pnode = NULL;
243 ndlp->rport = NULL;
244 if (put_node)
245 lpfc_nlp_put(ndlp);
246 if (put_rport)
247 put_device(&rport->dev);
James Smarta93ff372010-10-22 11:06:08 -0400248 return fcf_inuse;
James Smart92d7f7b2007-06-17 19:56:38 -0500249 }
James Smart82085712007-04-25 09:52:41 -0400250
dea31012005-04-17 16:05:31 -0500251 if (ndlp->nlp_sid != NLP_NO_SID) {
James.Smart@Emulex.Com6e8215e2005-06-25 10:34:04 -0400252 warn_on = 1;
dea31012005-04-17 16:05:31 -0500253 /* flush the target */
James Smart51ef4c22007-08-02 11:10:31 -0400254 lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring],
255 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
dea31012005-04-17 16:05:31 -0500256 }
James Smartc01f3202006-08-18 17:47:08 -0400257
James.Smart@Emulex.Com6e8215e2005-06-25 10:34:04 -0400258 if (warn_on) {
James Smarte8b62012007-08-02 11:10:09 -0400259 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
260 "0203 Devloss timeout on "
James Smart58da1ff2008-04-07 10:15:56 -0400261 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x "
262 "NPort x%06x Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400263 *name, *(name+1), *(name+2), *(name+3),
264 *(name+4), *(name+5), *(name+6), *(name+7),
265 ndlp->nlp_DID, ndlp->nlp_flag,
266 ndlp->nlp_state, ndlp->nlp_rpi);
James.Smart@Emulex.Com6e8215e2005-06-25 10:34:04 -0400267 } else {
James Smarte8b62012007-08-02 11:10:09 -0400268 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
269 "0204 Devloss timeout on "
James Smart58da1ff2008-04-07 10:15:56 -0400270 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x "
271 "NPort x%06x Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400272 *name, *(name+1), *(name+2), *(name+3),
273 *(name+4), *(name+5), *(name+6), *(name+7),
274 ndlp->nlp_DID, ndlp->nlp_flag,
275 ndlp->nlp_state, ndlp->nlp_rpi);
James.Smart@Emulex.Com6e8215e2005-06-25 10:34:04 -0400276 }
277
James Smart87af33f2007-10-27 13:37:43 -0400278 put_node = rdata->pnode != NULL;
279 put_rport = ndlp->rport != NULL;
280 rdata->pnode = NULL;
281 ndlp->rport = NULL;
282 if (put_node)
283 lpfc_nlp_put(ndlp);
284 if (put_rport)
285 put_device(&rport->dev);
286
James Smart2e0fef82007-06-17 19:56:36 -0500287 if (!(vport->load_flag & FC_UNLOADING) &&
James Smart1dcb58e2007-04-25 09:51:30 -0400288 !(ndlp->nlp_flag & NLP_DELAY_TMO) &&
James Smart82085712007-04-25 09:52:41 -0400289 !(ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
James Smartffc95492010-06-07 15:23:17 -0400290 (ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
James Smart589a52d2010-07-14 15:30:54 -0400291 (ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE) &&
292 (ndlp->nlp_state != NLP_STE_PRLI_ISSUE))
James Smart2e0fef82007-06-17 19:56:36 -0500293 lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
James Smart6fb120a2009-05-22 14:52:59 -0400294
James Smarta93ff372010-10-22 11:06:08 -0400295 return fcf_inuse;
296}
297
298/**
299 * lpfc_sli4_post_dev_loss_tmo_handler - SLI4 post devloss timeout handler
300 * @phba: Pointer to hba context object.
301 * @fcf_inuse: SLI4 FCF in-use state reported from devloss timeout handler.
302 * @nlp_did: remote node identifer with devloss timeout.
303 *
304 * This function is called from the worker thread after invoking devloss
305 * timeout handler and releasing the reference count for the ndlp with
306 * which the devloss timeout was handled for SLI4 host. For the devloss
307 * timeout of the last remote node which had been in use of FCF, when this
308 * routine is invoked, it shall be guaranteed that none of the remote are
309 * in-use of FCF. When devloss timeout to the last remote using the FCF,
310 * if the FIP engine is neither in FCF table scan process nor roundrobin
311 * failover process, the in-use FCF shall be unregistered. If the FIP
312 * engine is in FCF discovery process, the devloss timeout state shall
313 * be set for either the FCF table scan process or roundrobin failover
314 * process to unregister the in-use FCF.
315 **/
316static void
317lpfc_sli4_post_dev_loss_tmo_handler(struct lpfc_hba *phba, int fcf_inuse,
318 uint32_t nlp_did)
319{
320 /* If devloss timeout happened to a remote node when FCF had no
321 * longer been in-use, do nothing.
322 */
323 if (!fcf_inuse)
324 return;
325
326 if ((phba->hba_flag & HBA_FIP_SUPPORT) && !lpfc_fcf_inuse(phba)) {
327 spin_lock_irq(&phba->hbalock);
328 if (phba->fcf.fcf_flag & FCF_DISCOVERY) {
329 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
330 spin_unlock_irq(&phba->hbalock);
331 return;
332 }
333 phba->hba_flag |= HBA_DEVLOSS_TMO;
334 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
335 "2847 Last remote node (x%x) using "
336 "FCF devloss tmo\n", nlp_did);
337 }
338 if (phba->fcf.fcf_flag & FCF_REDISC_PROG) {
339 spin_unlock_irq(&phba->hbalock);
340 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
341 "2868 Devloss tmo to FCF rediscovery "
342 "in progress\n");
343 return;
344 }
345 if (!(phba->hba_flag & (FCF_TS_INPROG | FCF_RR_INPROG))) {
346 spin_unlock_irq(&phba->hbalock);
347 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
348 "2869 Devloss tmo to idle FIP engine, "
349 "unreg in-use FCF and rescan.\n");
350 /* Unregister in-use FCF and rescan */
351 lpfc_unregister_fcf_rescan(phba);
352 return;
353 }
354 spin_unlock_irq(&phba->hbalock);
355 if (phba->hba_flag & FCF_TS_INPROG)
356 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
357 "2870 FCF table scan in progress\n");
358 if (phba->hba_flag & FCF_RR_INPROG)
359 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
360 "2871 FLOGI roundrobin FCF failover "
361 "in progress\n");
362 }
James Smart6fb120a2009-05-22 14:52:59 -0400363 lpfc_unregister_unused_fcf(phba);
James Smart92d7f7b2007-06-17 19:56:38 -0500364}
James Smartc01f3202006-08-18 17:47:08 -0400365
James Smartea2151b2008-09-07 11:52:10 -0400366/**
James Smart3621a712009-04-06 18:47:14 -0400367 * lpfc_alloc_fast_evt - Allocates data structure for posting event
James Smartea2151b2008-09-07 11:52:10 -0400368 * @phba: Pointer to hba context object.
369 *
370 * This function is called from the functions which need to post
371 * events from interrupt context. This function allocates data
372 * structure required for posting event. It also keeps track of
373 * number of events pending and prevent event storm when there are
374 * too many events.
375 **/
376struct lpfc_fast_path_event *
377lpfc_alloc_fast_evt(struct lpfc_hba *phba) {
378 struct lpfc_fast_path_event *ret;
379
380 /* If there are lot of fast event do not exhaust memory due to this */
381 if (atomic_read(&phba->fast_event_count) > LPFC_MAX_EVT_COUNT)
382 return NULL;
383
384 ret = kzalloc(sizeof(struct lpfc_fast_path_event),
385 GFP_ATOMIC);
James Smart6fb120a2009-05-22 14:52:59 -0400386 if (ret) {
James Smartea2151b2008-09-07 11:52:10 -0400387 atomic_inc(&phba->fast_event_count);
James Smart6fb120a2009-05-22 14:52:59 -0400388 INIT_LIST_HEAD(&ret->work_evt.evt_listp);
389 ret->work_evt.evt = LPFC_EVT_FASTPATH_MGMT_EVT;
390 }
James Smartea2151b2008-09-07 11:52:10 -0400391 return ret;
392}
393
394/**
James Smart3621a712009-04-06 18:47:14 -0400395 * lpfc_free_fast_evt - Frees event data structure
James Smartea2151b2008-09-07 11:52:10 -0400396 * @phba: Pointer to hba context object.
397 * @evt: Event object which need to be freed.
398 *
399 * This function frees the data structure required for posting
400 * events.
401 **/
402void
403lpfc_free_fast_evt(struct lpfc_hba *phba,
404 struct lpfc_fast_path_event *evt) {
405
406 atomic_dec(&phba->fast_event_count);
407 kfree(evt);
408}
409
410/**
James Smart3621a712009-04-06 18:47:14 -0400411 * lpfc_send_fastpath_evt - Posts events generated from fast path
James Smartea2151b2008-09-07 11:52:10 -0400412 * @phba: Pointer to hba context object.
413 * @evtp: Event data structure.
414 *
415 * This function is called from worker thread, when the interrupt
416 * context need to post an event. This function posts the event
417 * to fc transport netlink interface.
418 **/
419static void
420lpfc_send_fastpath_evt(struct lpfc_hba *phba,
421 struct lpfc_work_evt *evtp)
422{
423 unsigned long evt_category, evt_sub_category;
424 struct lpfc_fast_path_event *fast_evt_data;
425 char *evt_data;
426 uint32_t evt_data_size;
427 struct Scsi_Host *shost;
428
429 fast_evt_data = container_of(evtp, struct lpfc_fast_path_event,
430 work_evt);
431
432 evt_category = (unsigned long) fast_evt_data->un.fabric_evt.event_type;
433 evt_sub_category = (unsigned long) fast_evt_data->un.
434 fabric_evt.subcategory;
435 shost = lpfc_shost_from_vport(fast_evt_data->vport);
436 if (evt_category == FC_REG_FABRIC_EVENT) {
437 if (evt_sub_category == LPFC_EVENT_FCPRDCHKERR) {
438 evt_data = (char *) &fast_evt_data->un.read_check_error;
439 evt_data_size = sizeof(fast_evt_data->un.
440 read_check_error);
441 } else if ((evt_sub_category == LPFC_EVENT_FABRIC_BUSY) ||
James Smarteaf15d52008-12-04 22:39:29 -0500442 (evt_sub_category == LPFC_EVENT_PORT_BUSY)) {
James Smartea2151b2008-09-07 11:52:10 -0400443 evt_data = (char *) &fast_evt_data->un.fabric_evt;
444 evt_data_size = sizeof(fast_evt_data->un.fabric_evt);
445 } else {
446 lpfc_free_fast_evt(phba, fast_evt_data);
447 return;
448 }
449 } else if (evt_category == FC_REG_SCSI_EVENT) {
450 switch (evt_sub_category) {
451 case LPFC_EVENT_QFULL:
452 case LPFC_EVENT_DEVBSY:
453 evt_data = (char *) &fast_evt_data->un.scsi_evt;
454 evt_data_size = sizeof(fast_evt_data->un.scsi_evt);
455 break;
456 case LPFC_EVENT_CHECK_COND:
457 evt_data = (char *) &fast_evt_data->un.check_cond_evt;
458 evt_data_size = sizeof(fast_evt_data->un.
459 check_cond_evt);
460 break;
461 case LPFC_EVENT_VARQUEDEPTH:
462 evt_data = (char *) &fast_evt_data->un.queue_depth_evt;
463 evt_data_size = sizeof(fast_evt_data->un.
464 queue_depth_evt);
465 break;
466 default:
467 lpfc_free_fast_evt(phba, fast_evt_data);
468 return;
469 }
470 } else {
471 lpfc_free_fast_evt(phba, fast_evt_data);
472 return;
473 }
474
475 fc_host_post_vendor_event(shost,
476 fc_get_event_number(),
477 evt_data_size,
478 evt_data,
James Smartddcc50f2008-12-04 22:38:46 -0500479 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -0400480
481 lpfc_free_fast_evt(phba, fast_evt_data);
482 return;
483}
484
dea31012005-04-17 16:05:31 -0500485static void
James Smart2e0fef82007-06-17 19:56:36 -0500486lpfc_work_list_done(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500487{
488 struct lpfc_work_evt *evtp = NULL;
489 struct lpfc_nodelist *ndlp;
490 int free_evt;
James Smarta93ff372010-10-22 11:06:08 -0400491 int fcf_inuse;
492 uint32_t nlp_did;
dea31012005-04-17 16:05:31 -0500493
James Smart2e0fef82007-06-17 19:56:36 -0500494 spin_lock_irq(&phba->hbalock);
495 while (!list_empty(&phba->work_list)) {
dea31012005-04-17 16:05:31 -0500496 list_remove_head((&phba->work_list), evtp, typeof(*evtp),
497 evt_listp);
James Smart2e0fef82007-06-17 19:56:36 -0500498 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500499 free_evt = 1;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500500 switch (evtp->evt) {
dea31012005-04-17 16:05:31 -0500501 case LPFC_EVT_ELS_RETRY:
James Smart2e0fef82007-06-17 19:56:36 -0500502 ndlp = (struct lpfc_nodelist *) (evtp->evt_arg1);
dea31012005-04-17 16:05:31 -0500503 lpfc_els_retry_delay_handler(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -0500504 free_evt = 0; /* evt is part of ndlp */
James Smartfa4066b2008-01-11 01:53:27 -0500505 /* decrement the node reference count held
506 * for this queued work
507 */
508 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500509 break;
James Smart858c9f62007-06-17 19:56:39 -0500510 case LPFC_EVT_DEV_LOSS:
511 ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1);
James Smarta93ff372010-10-22 11:06:08 -0400512 fcf_inuse = lpfc_dev_loss_tmo_handler(ndlp);
James Smart858c9f62007-06-17 19:56:39 -0500513 free_evt = 0;
James Smartfa4066b2008-01-11 01:53:27 -0500514 /* decrement the node reference count held for
515 * this queued work
516 */
James Smarta93ff372010-10-22 11:06:08 -0400517 nlp_did = ndlp->nlp_DID;
James Smart858c9f62007-06-17 19:56:39 -0500518 lpfc_nlp_put(ndlp);
James Smarta93ff372010-10-22 11:06:08 -0400519 if (phba->sli_rev == LPFC_SLI_REV4)
520 lpfc_sli4_post_dev_loss_tmo_handler(phba,
521 fcf_inuse,
522 nlp_did);
James Smart858c9f62007-06-17 19:56:39 -0500523 break;
dea31012005-04-17 16:05:31 -0500524 case LPFC_EVT_ONLINE:
James Smart2e0fef82007-06-17 19:56:36 -0500525 if (phba->link_state < LPFC_LINK_DOWN)
526 *(int *) (evtp->evt_arg1) = lpfc_online(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500527 else
James Smart2e0fef82007-06-17 19:56:36 -0500528 *(int *) (evtp->evt_arg1) = 0;
dea31012005-04-17 16:05:31 -0500529 complete((struct completion *)(evtp->evt_arg2));
530 break;
James Smart46fa3112007-04-25 09:51:45 -0400531 case LPFC_EVT_OFFLINE_PREP:
James Smart2e0fef82007-06-17 19:56:36 -0500532 if (phba->link_state >= LPFC_LINK_DOWN)
James Smart46fa3112007-04-25 09:51:45 -0400533 lpfc_offline_prep(phba);
534 *(int *)(evtp->evt_arg1) = 0;
535 complete((struct completion *)(evtp->evt_arg2));
536 break;
537 case LPFC_EVT_OFFLINE:
538 lpfc_offline(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500539 lpfc_sli_brdrestart(phba);
540 *(int *)(evtp->evt_arg1) =
James Smart46fa3112007-04-25 09:51:45 -0400541 lpfc_sli_brdready(phba, HS_FFRDY | HS_MBRDY);
542 lpfc_unblock_mgmt_io(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500543 complete((struct completion *)(evtp->evt_arg2));
544 break;
545 case LPFC_EVT_WARM_START:
James Smart46fa3112007-04-25 09:51:45 -0400546 lpfc_offline(phba);
James Smart92908312006-03-07 15:04:13 -0500547 lpfc_reset_barrier(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500548 lpfc_sli_brdreset(phba);
549 lpfc_hba_down_post(phba);
550 *(int *)(evtp->evt_arg1) =
551 lpfc_sli_brdready(phba, HS_MBRDY);
James Smart46fa3112007-04-25 09:51:45 -0400552 lpfc_unblock_mgmt_io(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500553 complete((struct completion *)(evtp->evt_arg2));
554 break;
555 case LPFC_EVT_KILL:
James Smart46fa3112007-04-25 09:51:45 -0400556 lpfc_offline(phba);
James Smart92908312006-03-07 15:04:13 -0500557 *(int *)(evtp->evt_arg1)
James Smart2e0fef82007-06-17 19:56:36 -0500558 = (phba->pport->stopped)
559 ? 0 : lpfc_sli_brdkill(phba);
James Smart46fa3112007-04-25 09:51:45 -0400560 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -0500561 complete((struct completion *)(evtp->evt_arg2));
562 break;
James Smartea2151b2008-09-07 11:52:10 -0400563 case LPFC_EVT_FASTPATH_MGMT_EVT:
564 lpfc_send_fastpath_evt(phba, evtp);
565 free_evt = 0;
566 break;
James Smart78730cf2010-04-06 15:06:30 -0400567 case LPFC_EVT_RESET_HBA:
568 if (!(phba->pport->load_flag & FC_UNLOADING))
569 lpfc_reset_hba(phba);
570 break;
dea31012005-04-17 16:05:31 -0500571 }
572 if (free_evt)
573 kfree(evtp);
James Smart2e0fef82007-06-17 19:56:36 -0500574 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500575 }
James Smart2e0fef82007-06-17 19:56:36 -0500576 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500577
578}
579
James Smart311464e2007-08-02 11:10:37 -0400580static void
James Smart2e0fef82007-06-17 19:56:36 -0500581lpfc_work_done(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500582{
583 struct lpfc_sli_ring *pring;
James Smart858c9f62007-06-17 19:56:39 -0500584 uint32_t ha_copy, status, control, work_port_events;
James Smart549e55c2007-08-02 11:09:51 -0400585 struct lpfc_vport **vports;
James Smart51ef4c22007-08-02 11:10:31 -0400586 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -0400587 int i;
dea31012005-04-17 16:05:31 -0500588
James Smart2e0fef82007-06-17 19:56:36 -0500589 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500590 ha_copy = phba->work_ha;
591 phba->work_ha = 0;
James Smart2e0fef82007-06-17 19:56:36 -0500592 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500593
James Smartda0436e2009-05-22 14:51:39 -0400594 /* First, try to post the next mailbox command to SLI4 device */
595 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC)
596 lpfc_sli4_post_async_mbox(phba);
597
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500598 if (ha_copy & HA_ERATT)
James Smart93996272008-08-24 21:50:30 -0400599 /* Handle the error attention event */
dea31012005-04-17 16:05:31 -0500600 lpfc_handle_eratt(phba);
601
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500602 if (ha_copy & HA_MBATT)
dea31012005-04-17 16:05:31 -0500603 lpfc_sli_handle_mb_event(phba);
604
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500605 if (ha_copy & HA_LATT)
dea31012005-04-17 16:05:31 -0500606 lpfc_handle_latt(phba);
James Smart93996272008-08-24 21:50:30 -0400607
James Smartda0436e2009-05-22 14:51:39 -0400608 /* Process SLI4 events */
609 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) {
610 if (phba->hba_flag & FCP_XRI_ABORT_EVENT)
611 lpfc_sli4_fcp_xri_abort_event_proc(phba);
612 if (phba->hba_flag & ELS_XRI_ABORT_EVENT)
613 lpfc_sli4_els_xri_abort_event_proc(phba);
614 if (phba->hba_flag & ASYNC_EVENT)
615 lpfc_sli4_async_event_proc(phba);
616 if (phba->hba_flag & HBA_POST_RECEIVE_BUFFER) {
617 spin_lock_irq(&phba->hbalock);
618 phba->hba_flag &= ~HBA_POST_RECEIVE_BUFFER;
619 spin_unlock_irq(&phba->hbalock);
620 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
621 }
James Smartecfd03c2010-02-12 14:41:27 -0500622 if (phba->fcf.fcf_flag & FCF_REDISC_EVT)
623 lpfc_sli4_fcf_redisc_event_proc(phba);
James Smartda0436e2009-05-22 14:51:39 -0400624 }
625
James Smart549e55c2007-08-02 11:09:51 -0400626 vports = lpfc_create_vport_work_array(phba);
627 if (vports != NULL)
James Smartda0436e2009-05-22 14:51:39 -0400628 for (i = 0; i <= phba->max_vports; i++) {
James Smart51ef4c22007-08-02 11:10:31 -0400629 /*
630 * We could have no vports in array if unloading, so if
631 * this happens then just use the pport
632 */
633 if (vports[i] == NULL && i == 0)
634 vport = phba->pport;
635 else
636 vport = vports[i];
637 if (vport == NULL)
638 break;
James Smart58da1ff2008-04-07 10:15:56 -0400639 spin_lock_irq(&vport->work_port_lock);
James Smart51ef4c22007-08-02 11:10:31 -0400640 work_port_events = vport->work_port_events;
James Smart58da1ff2008-04-07 10:15:56 -0400641 vport->work_port_events &= ~work_port_events;
642 spin_unlock_irq(&vport->work_port_lock);
James Smart549e55c2007-08-02 11:09:51 -0400643 if (work_port_events & WORKER_DISC_TMO)
James Smart51ef4c22007-08-02 11:10:31 -0400644 lpfc_disc_timeout_handler(vport);
James Smart549e55c2007-08-02 11:09:51 -0400645 if (work_port_events & WORKER_ELS_TMO)
James Smart51ef4c22007-08-02 11:10:31 -0400646 lpfc_els_timeout_handler(vport);
James Smart549e55c2007-08-02 11:09:51 -0400647 if (work_port_events & WORKER_HB_TMO)
648 lpfc_hb_timeout_handler(phba);
649 if (work_port_events & WORKER_MBOX_TMO)
650 lpfc_mbox_timeout_handler(phba);
651 if (work_port_events & WORKER_FABRIC_BLOCK_TMO)
652 lpfc_unblock_fabric_iocbs(phba);
653 if (work_port_events & WORKER_FDMI_TMO)
James Smart51ef4c22007-08-02 11:10:31 -0400654 lpfc_fdmi_timeout_handler(vport);
James Smart549e55c2007-08-02 11:09:51 -0400655 if (work_port_events & WORKER_RAMP_DOWN_QUEUE)
656 lpfc_ramp_down_queue_handler(phba);
657 if (work_port_events & WORKER_RAMP_UP_QUEUE)
658 lpfc_ramp_up_queue_handler(phba);
James Smart92d7f7b2007-06-17 19:56:38 -0500659 }
James Smart09372822008-01-11 01:52:54 -0500660 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -0500661
James Smart858c9f62007-06-17 19:56:39 -0500662 pring = &phba->sli.ring[LPFC_ELS_RING];
663 status = (ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
664 status >>= (4*LPFC_ELS_RING);
James Smart4d9ab992009-10-02 15:16:39 -0400665 if ((status & HA_RXMASK) ||
666 (pring->flag & LPFC_DEFERRED_RING_EVENT) ||
James Smart45ed1192009-10-02 15:17:02 -0400667 (phba->hba_flag & HBA_SP_QUEUE_EVT)) {
James Smart0b727fe2007-10-27 13:37:25 -0400668 if (pring->flag & LPFC_STOP_IOCB_EVENT) {
James Smart858c9f62007-06-17 19:56:39 -0500669 pring->flag |= LPFC_DEFERRED_RING_EVENT;
James Smart5e9d9b82008-06-14 22:52:53 -0400670 /* Set the lpfc data pending flag */
671 set_bit(LPFC_DATA_READY, &phba->data_flags);
James Smart858c9f62007-06-17 19:56:39 -0500672 } else {
James Smart58da1ff2008-04-07 10:15:56 -0400673 pring->flag &= ~LPFC_DEFERRED_RING_EVENT;
James Smart858c9f62007-06-17 19:56:39 -0500674 lpfc_sli_handle_slow_ring_event(phba, pring,
675 (status &
676 HA_RXMASK));
James Smart858c9f62007-06-17 19:56:39 -0500677 }
James Smartbc739052010-08-04 16:11:18 -0400678 if ((phba->sli_rev == LPFC_SLI_REV4) && pring->txq_cnt)
James Smart2a9bf3d2010-06-07 15:24:45 -0400679 lpfc_drain_txq(phba);
James Smart858c9f62007-06-17 19:56:39 -0500680 /*
681 * Turn on Ring interrupts
682 */
James Smart3772a992009-05-22 14:50:54 -0400683 if (phba->sli_rev <= LPFC_SLI_REV3) {
684 spin_lock_irq(&phba->hbalock);
685 control = readl(phba->HCregaddr);
686 if (!(control & (HC_R0INT_ENA << LPFC_ELS_RING))) {
687 lpfc_debugfs_slow_ring_trc(phba,
688 "WRK Enable ring: cntl:x%x hacopy:x%x",
689 control, ha_copy, 0);
James Smarta58cbd52007-08-02 11:09:43 -0400690
James Smart3772a992009-05-22 14:50:54 -0400691 control |= (HC_R0INT_ENA << LPFC_ELS_RING);
692 writel(control, phba->HCregaddr);
693 readl(phba->HCregaddr); /* flush */
694 } else {
695 lpfc_debugfs_slow_ring_trc(phba,
696 "WRK Ring ok: cntl:x%x hacopy:x%x",
697 control, ha_copy, 0);
698 }
699 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500700 }
701 }
James Smart2e0fef82007-06-17 19:56:36 -0500702 lpfc_work_list_done(phba);
dea31012005-04-17 16:05:31 -0500703}
704
dea31012005-04-17 16:05:31 -0500705int
706lpfc_do_work(void *p)
707{
708 struct lpfc_hba *phba = p;
709 int rc;
dea31012005-04-17 16:05:31 -0500710
711 set_user_nice(current, -20);
James Smart5e9d9b82008-06-14 22:52:53 -0400712 phba->data_flags = 0;
dea31012005-04-17 16:05:31 -0500713
James Smart3a55b532008-12-04 22:38:54 -0500714 while (!kthread_should_stop()) {
James Smart5e9d9b82008-06-14 22:52:53 -0400715 /* wait and check worker queue activities */
716 rc = wait_event_interruptible(phba->work_waitq,
717 (test_and_clear_bit(LPFC_DATA_READY,
718 &phba->data_flags)
719 || kthread_should_stop()));
James Smart3a55b532008-12-04 22:38:54 -0500720 /* Signal wakeup shall terminate the worker thread */
721 if (rc) {
722 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
723 "0433 Wakeup on signal: rc=x%x\n", rc);
dea31012005-04-17 16:05:31 -0500724 break;
James Smart3a55b532008-12-04 22:38:54 -0500725 }
dea31012005-04-17 16:05:31 -0500726
James Smart5e9d9b82008-06-14 22:52:53 -0400727 /* Attend pending lpfc data processing */
dea31012005-04-17 16:05:31 -0500728 lpfc_work_done(phba);
dea31012005-04-17 16:05:31 -0500729 }
James Smart3a55b532008-12-04 22:38:54 -0500730 phba->worker_thread = NULL;
731 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
732 "0432 Worker thread stopped.\n");
dea31012005-04-17 16:05:31 -0500733 return 0;
734}
735
736/*
737 * This is only called to handle FC worker events. Since this a rare
738 * occurance, we allocate a struct lpfc_work_evt structure here instead of
739 * embedding it in the IOCB.
740 */
741int
James Smart2e0fef82007-06-17 19:56:36 -0500742lpfc_workq_post_event(struct lpfc_hba *phba, void *arg1, void *arg2,
dea31012005-04-17 16:05:31 -0500743 uint32_t evt)
744{
745 struct lpfc_work_evt *evtp;
James Smarted957682007-06-17 19:56:37 -0500746 unsigned long flags;
dea31012005-04-17 16:05:31 -0500747
748 /*
749 * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will
750 * be queued to worker thread for processing
751 */
James Smart92d7f7b2007-06-17 19:56:38 -0500752 evtp = kmalloc(sizeof(struct lpfc_work_evt), GFP_ATOMIC);
dea31012005-04-17 16:05:31 -0500753 if (!evtp)
754 return 0;
755
756 evtp->evt_arg1 = arg1;
757 evtp->evt_arg2 = arg2;
758 evtp->evt = evt;
759
James Smarted957682007-06-17 19:56:37 -0500760 spin_lock_irqsave(&phba->hbalock, flags);
James Smart071fbd3d2006-04-15 11:53:20 -0400761 list_add_tail(&evtp->evt_listp, &phba->work_list);
James Smarted957682007-06-17 19:56:37 -0500762 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -0500763
James Smart5e9d9b82008-06-14 22:52:53 -0400764 lpfc_worker_wake_up(phba);
765
dea31012005-04-17 16:05:31 -0500766 return 1;
767}
768
James Smart92d7f7b2007-06-17 19:56:38 -0500769void
770lpfc_cleanup_rpis(struct lpfc_vport *vport, int remove)
771{
James Smart09372822008-01-11 01:52:54 -0500772 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500773 struct lpfc_hba *phba = vport->phba;
774 struct lpfc_nodelist *ndlp, *next_ndlp;
775 int rc;
776
777 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -0500778 if (!NLP_CHK_NODE_ACT(ndlp))
779 continue;
James Smart92d7f7b2007-06-17 19:56:38 -0500780 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
781 continue;
James Smart98c9ea52007-10-27 13:37:33 -0400782 if ((phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) ||
783 ((vport->port_type == LPFC_NPIV_PORT) &&
784 (ndlp->nlp_DID == NameServer_DID)))
James Smart92d7f7b2007-06-17 19:56:38 -0500785 lpfc_unreg_rpi(vport, ndlp);
786
787 /* Leave Fabric nodes alone on link down */
James Smart4d9ab992009-10-02 15:16:39 -0400788 if ((phba->sli_rev < LPFC_SLI_REV4) &&
789 (!remove && ndlp->nlp_type & NLP_FABRIC))
James Smart92d7f7b2007-06-17 19:56:38 -0500790 continue;
791 rc = lpfc_disc_state_machine(vport, ndlp, NULL,
792 remove
793 ? NLP_EVT_DEVICE_RM
794 : NLP_EVT_DEVICE_RECOVERY);
795 }
796 if (phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) {
James Smart5af5eee2010-10-22 11:06:38 -0400797 if (phba->sli_rev == LPFC_SLI_REV4)
798 lpfc_sli4_unreg_all_rpis(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500799 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -0500800 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500801 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -0500802 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500803 }
804}
805
James Smart87af33f2007-10-27 13:37:43 -0400806void
James Smart98c9ea52007-10-27 13:37:33 -0400807lpfc_port_link_failure(struct lpfc_vport *vport)
James Smart92d7f7b2007-06-17 19:56:38 -0500808{
James Smart695a8142010-01-26 23:08:03 -0500809 lpfc_vport_set_state(vport, FC_VPORT_LINKDOWN);
810
James Smart45ed1192009-10-02 15:17:02 -0400811 /* Cleanup any outstanding received buffers */
812 lpfc_cleanup_rcv_buffers(vport);
813
James Smart92d7f7b2007-06-17 19:56:38 -0500814 /* Cleanup any outstanding RSCN activity */
815 lpfc_els_flush_rscn(vport);
816
817 /* Cleanup any outstanding ELS commands */
818 lpfc_els_flush_cmd(vport);
819
820 lpfc_cleanup_rpis(vport, 0);
821
James Smart92d7f7b2007-06-17 19:56:38 -0500822 /* Turn off discovery timer if its running */
823 lpfc_can_disctmo(vport);
824}
825
James Smart3772a992009-05-22 14:50:54 -0400826void
James Smart98c9ea52007-10-27 13:37:33 -0400827lpfc_linkdown_port(struct lpfc_vport *vport)
828{
829 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
830
831 fc_host_post_event(shost, fc_get_event_number(), FCH_EVT_LINKDOWN, 0);
832
833 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
834 "Link Down: state:x%x rtry:x%x flg:x%x",
835 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
836
837 lpfc_port_link_failure(vport);
838
839}
840
dea31012005-04-17 16:05:31 -0500841int
James Smart685f0bf2007-04-25 09:53:08 -0400842lpfc_linkdown(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500843{
James Smart2e0fef82007-06-17 19:56:36 -0500844 struct lpfc_vport *vport = phba->pport;
845 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart549e55c2007-08-02 11:09:51 -0400846 struct lpfc_vport **vports;
James Smart685f0bf2007-04-25 09:53:08 -0400847 LPFC_MBOXQ_t *mb;
James Smart549e55c2007-08-02 11:09:51 -0400848 int i;
dea31012005-04-17 16:05:31 -0500849
James Smart3163f722008-02-08 18:50:25 -0500850 if (phba->link_state == LPFC_LINK_DOWN)
James Smart2e0fef82007-06-17 19:56:36 -0500851 return 0;
James Smartaacc20e2009-12-21 17:02:51 -0500852
853 /* Block all SCSI stack I/Os */
854 lpfc_scsi_dev_block(phba);
855
James Smart2e0fef82007-06-17 19:56:36 -0500856 spin_lock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -0500857 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
James Smart72100cc2010-02-12 14:43:01 -0500858 spin_unlock_irq(&phba->hbalock);
James Smart92d7f7b2007-06-17 19:56:38 -0500859 if (phba->link_state > LPFC_LINK_DOWN) {
James Smart2e0fef82007-06-17 19:56:36 -0500860 phba->link_state = LPFC_LINK_DOWN;
James Smart72100cc2010-02-12 14:43:01 -0500861 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500862 phba->pport->fc_flag &= ~FC_LBIT;
James Smart72100cc2010-02-12 14:43:01 -0500863 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500864 }
James Smart549e55c2007-08-02 11:09:51 -0400865 vports = lpfc_create_vport_work_array(phba);
866 if (vports != NULL)
James Smart6fb120a2009-05-22 14:52:59 -0400867 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -0400868 /* Issue a LINK DOWN event to all nodes */
869 lpfc_linkdown_port(vports[i]);
870 }
James Smart09372822008-01-11 01:52:54 -0500871 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -0500872 /* Clean up any firmware default rpi's */
James Smart2e0fef82007-06-17 19:56:36 -0500873 mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
874 if (mb) {
James Smart92d7f7b2007-06-17 19:56:38 -0500875 lpfc_unreg_did(phba, 0xffff, 0xffffffff, mb);
James Smarted957682007-06-17 19:56:37 -0500876 mb->vport = vport;
James Smart2e0fef82007-06-17 19:56:36 -0500877 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart0b727fe2007-10-27 13:37:25 -0400878 if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT)
dea31012005-04-17 16:05:31 -0500879 == MBX_NOT_FINISHED) {
James Smart2e0fef82007-06-17 19:56:36 -0500880 mempool_free(mb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500881 }
882 }
883
dea31012005-04-17 16:05:31 -0500884 /* Setup myDID for link up if we are in pt2pt mode */
James Smart92d7f7b2007-06-17 19:56:38 -0500885 if (phba->pport->fc_flag & FC_PT2PT) {
886 phba->pport->fc_myDID = 0;
James Smart2e0fef82007-06-17 19:56:36 -0500887 mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
888 if (mb) {
dea31012005-04-17 16:05:31 -0500889 lpfc_config_link(phba, mb);
James Smart92d7f7b2007-06-17 19:56:38 -0500890 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -0500891 mb->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -0400892 if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT)
dea31012005-04-17 16:05:31 -0500893 == MBX_NOT_FINISHED) {
James Smart2e0fef82007-06-17 19:56:36 -0500894 mempool_free(mb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500895 }
896 }
James Smart2e0fef82007-06-17 19:56:36 -0500897 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500898 phba->pport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI);
James Smart2e0fef82007-06-17 19:56:36 -0500899 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500900 }
James Smart2e0fef82007-06-17 19:56:36 -0500901
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500902 return 0;
dea31012005-04-17 16:05:31 -0500903}
904
James Smart92d7f7b2007-06-17 19:56:38 -0500905static void
906lpfc_linkup_cleanup_nodes(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -0500907{
James Smart92d7f7b2007-06-17 19:56:38 -0500908 struct lpfc_nodelist *ndlp;
909
910 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -0500911 if (!NLP_CHK_NODE_ACT(ndlp))
912 continue;
James Smart92d7f7b2007-06-17 19:56:38 -0500913 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
914 continue;
James Smart92d7f7b2007-06-17 19:56:38 -0500915 if (ndlp->nlp_type & NLP_FABRIC) {
James Smarte47c9092008-02-08 18:49:26 -0500916 /* On Linkup its safe to clean up the ndlp
917 * from Fabric connections.
918 */
James Smart92d7f7b2007-06-17 19:56:38 -0500919 if (ndlp->nlp_DID != Fabric_DID)
920 lpfc_unreg_rpi(vport, ndlp);
921 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
922 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
James Smarte47c9092008-02-08 18:49:26 -0500923 /* Fail outstanding IO now since device is
924 * marked for PLOGI.
925 */
James Smart92d7f7b2007-06-17 19:56:38 -0500926 lpfc_unreg_rpi(vport, ndlp);
927 }
928 }
929}
930
931static void
932lpfc_linkup_port(struct lpfc_vport *vport)
933{
934 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500935 struct lpfc_hba *phba = vport->phba;
936
937 if ((vport->load_flag & FC_UNLOADING) != 0)
938 return;
939
James Smart858c9f62007-06-17 19:56:39 -0500940 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
941 "Link Up: top:x%x speed:x%x flg:x%x",
942 phba->fc_topology, phba->fc_linkspeed, phba->link_flag);
943
James Smart92d7f7b2007-06-17 19:56:38 -0500944 /* If NPIV is not enabled, only bring the physical port up */
945 if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
946 (vport != phba->pport))
947 return;
dea31012005-04-17 16:05:31 -0500948
James Smart2e0fef82007-06-17 19:56:36 -0500949 fc_host_post_event(shost, fc_get_event_number(), FCH_EVT_LINKUP, 0);
James Smartd2873e42006-08-18 17:46:43 -0400950
James Smart2e0fef82007-06-17 19:56:36 -0500951 spin_lock_irq(shost->host_lock);
James Smart2e0fef82007-06-17 19:56:36 -0500952 vport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI | FC_ABORT_DISCOVERY |
953 FC_RSCN_MODE | FC_NLP_MORE | FC_RSCN_DISCOVERY);
954 vport->fc_flag |= FC_NDISC_ACTIVE;
955 vport->fc_ns_retry = 0;
956 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500957
James Smart92d7f7b2007-06-17 19:56:38 -0500958 if (vport->fc_flag & FC_LBIT)
959 lpfc_linkup_cleanup_nodes(vport);
dea31012005-04-17 16:05:31 -0500960
James Smart92d7f7b2007-06-17 19:56:38 -0500961}
962
963static int
964lpfc_linkup(struct lpfc_hba *phba)
965{
James Smart549e55c2007-08-02 11:09:51 -0400966 struct lpfc_vport **vports;
967 int i;
James Smart92d7f7b2007-06-17 19:56:38 -0500968
969 phba->link_state = LPFC_LINK_UP;
970
971 /* Unblock fabric iocbs if they are blocked */
972 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
973 del_timer_sync(&phba->fabric_block_timer);
974
James Smart549e55c2007-08-02 11:09:51 -0400975 vports = lpfc_create_vport_work_array(phba);
976 if (vports != NULL)
James Smart6fb120a2009-05-22 14:52:59 -0400977 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
James Smart549e55c2007-08-02 11:09:51 -0400978 lpfc_linkup_port(vports[i]);
James Smart09372822008-01-11 01:52:54 -0500979 lpfc_destroy_vport_work_array(phba, vports);
James Smart6fb120a2009-05-22 14:52:59 -0400980 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
981 (phba->sli_rev < LPFC_SLI_REV4))
James Smart92d7f7b2007-06-17 19:56:38 -0500982 lpfc_issue_clear_la(phba, phba->pport);
dea31012005-04-17 16:05:31 -0500983
984 return 0;
985}
986
987/*
988 * This routine handles processing a CLEAR_LA mailbox
989 * command upon completion. It is setup in the LPFC_MBOXQ
990 * as the completion routine when the command is
991 * handed off to the SLI layer.
992 */
Adrian Bunka6ababd2007-11-05 18:07:33 +0100993static void
James Smart2e0fef82007-06-17 19:56:36 -0500994lpfc_mbx_cmpl_clear_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -0500995{
James Smart2e0fef82007-06-17 19:56:36 -0500996 struct lpfc_vport *vport = pmb->vport;
997 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
998 struct lpfc_sli *psli = &phba->sli;
James Smart04c68492009-05-22 14:52:52 -0400999 MAILBOX_t *mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -05001000 uint32_t control;
1001
dea31012005-04-17 16:05:31 -05001002 /* Since we don't do discovery right now, turn these off here */
James Smarta4bc3372006-12-02 13:34:16 -05001003 psli->ring[psli->extra_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
dea31012005-04-17 16:05:31 -05001004 psli->ring[psli->fcp_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
1005 psli->ring[psli->next_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
1006
1007 /* Check for error */
1008 if ((mb->mbxStatus) && (mb->mbxStatus != 0x1601)) {
James Smart92d7f7b2007-06-17 19:56:38 -05001009 /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */
James Smarte8b62012007-08-02 11:10:09 -04001010 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
1011 "0320 CLEAR_LA mbxStatus error x%x hba "
1012 "state x%x\n",
1013 mb->mbxStatus, vport->port_state);
James Smart2e0fef82007-06-17 19:56:36 -05001014 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05001015 goto out;
1016 }
1017
James Smart92d7f7b2007-06-17 19:56:38 -05001018 if (vport->port_type == LPFC_PHYSICAL_PORT)
1019 phba->link_state = LPFC_HBA_READY;
1020
1021 spin_lock_irq(&phba->hbalock);
1022 psli->sli_flag |= LPFC_PROCESS_LA;
1023 control = readl(phba->HCregaddr);
1024 control |= HC_LAINT_ENA;
1025 writel(control, phba->HCregaddr);
1026 readl(phba->HCregaddr); /* flush */
1027 spin_unlock_irq(&phba->hbalock);
James Smart1b32f6a2008-02-08 18:49:39 -05001028 mempool_free(pmb, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05001029 return;
dea31012005-04-17 16:05:31 -05001030
dea31012005-04-17 16:05:31 -05001031out:
1032 /* Device Discovery completes */
James Smarte8b62012007-08-02 11:10:09 -04001033 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1034 "0225 Device Discovery completes\n");
James Smart2e0fef82007-06-17 19:56:36 -05001035 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05001036
James Smart2e0fef82007-06-17 19:56:36 -05001037 spin_lock_irq(shost->host_lock);
James Smart58da1ff2008-04-07 10:15:56 -04001038 vport->fc_flag &= ~FC_ABORT_DISCOVERY;
James Smart2e0fef82007-06-17 19:56:36 -05001039 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001040
James Smart2e0fef82007-06-17 19:56:36 -05001041 lpfc_can_disctmo(vport);
dea31012005-04-17 16:05:31 -05001042
1043 /* turn on Link Attention interrupts */
James Smart2e0fef82007-06-17 19:56:36 -05001044
1045 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001046 psli->sli_flag |= LPFC_PROCESS_LA;
1047 control = readl(phba->HCregaddr);
1048 control |= HC_LAINT_ENA;
1049 writel(control, phba->HCregaddr);
1050 readl(phba->HCregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05001051 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001052
1053 return;
1054}
1055
James Smart2e0fef82007-06-17 19:56:36 -05001056
dea31012005-04-17 16:05:31 -05001057static void
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001058lpfc_mbx_cmpl_local_config_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05001059{
James Smart2e0fef82007-06-17 19:56:36 -05001060 struct lpfc_vport *vport = pmb->vport;
dea31012005-04-17 16:05:31 -05001061
James Smart04c68492009-05-22 14:52:52 -04001062 if (pmb->u.mb.mbxStatus)
dea31012005-04-17 16:05:31 -05001063 goto out;
dea31012005-04-17 16:05:31 -05001064
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001065 mempool_free(pmb, phba->mbox_mem_pool);
1066
James Smart76a95d72010-11-20 23:11:48 -05001067 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP &&
James Smart2e0fef82007-06-17 19:56:36 -05001068 vport->fc_flag & FC_PUBLIC_LOOP &&
1069 !(vport->fc_flag & FC_LBIT)) {
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001070 /* Need to wait for FAN - use discovery timer
James Smart2e0fef82007-06-17 19:56:36 -05001071 * for timeout. port_state is identically
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001072 * LPFC_LOCAL_CFG_LINK while waiting for FAN
1073 */
James Smart2e0fef82007-06-17 19:56:36 -05001074 lpfc_set_disctmo(vport);
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001075 return;
James Smart92d7f7b2007-06-17 19:56:38 -05001076 }
dea31012005-04-17 16:05:31 -05001077
James Smart2e0fef82007-06-17 19:56:36 -05001078 /* Start discovery by sending a FLOGI. port_state is identically
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001079 * LPFC_FLOGI while waiting for FLOGI cmpl
1080 */
James Smart76a95d72010-11-20 23:11:48 -05001081 if (vport->port_state != LPFC_FLOGI)
James Smart92d7f7b2007-06-17 19:56:38 -05001082 lpfc_initial_flogi(vport);
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001083 return;
dea31012005-04-17 16:05:31 -05001084
1085out:
James Smarte8b62012007-08-02 11:10:09 -04001086 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
1087 "0306 CONFIG_LINK mbxStatus error x%x "
1088 "HBA state x%x\n",
James Smart04c68492009-05-22 14:52:52 -04001089 pmb->u.mb.mbxStatus, vport->port_state);
James Smart92d7f7b2007-06-17 19:56:38 -05001090 mempool_free(pmb, phba->mbox_mem_pool);
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001091
1092 lpfc_linkdown(phba);
1093
James Smarte8b62012007-08-02 11:10:09 -04001094 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1095 "0200 CONFIG_LINK bad hba state x%x\n",
1096 vport->port_state);
dea31012005-04-17 16:05:31 -05001097
James Smart92d7f7b2007-06-17 19:56:38 -05001098 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -05001099 return;
1100}
1101
1102static void
James Smart6fb120a2009-05-22 14:52:59 -04001103lpfc_mbx_cmpl_reg_fcfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
1104{
1105 struct lpfc_vport *vport = mboxq->vport;
James Smart6fb120a2009-05-22 14:52:59 -04001106
1107 if (mboxq->u.mb.mbxStatus) {
1108 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
1109 "2017 REG_FCFI mbxStatus error x%x "
1110 "HBA state x%x\n",
1111 mboxq->u.mb.mbxStatus, vport->port_state);
James Smarta93ff372010-10-22 11:06:08 -04001112 goto fail_out;
James Smart6fb120a2009-05-22 14:52:59 -04001113 }
1114
1115 /* Start FCoE discovery by sending a FLOGI. */
1116 phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, &mboxq->u.mqe.un.reg_fcfi);
1117 /* Set the FCFI registered flag */
James Smartd439d282010-09-29 11:18:45 -04001118 spin_lock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04001119 phba->fcf.fcf_flag |= FCF_REGISTERED;
James Smartd439d282010-09-29 11:18:45 -04001120 spin_unlock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04001121
James Smart32b97932009-07-19 10:01:21 -04001122 /* If there is a pending FCoE event, restart FCF table scan. */
James Smarta93ff372010-10-22 11:06:08 -04001123 if (lpfc_check_pending_fcoe_event(phba, LPFC_UNREG_FCF))
1124 goto fail_out;
1125
1126 /* Mark successful completion of FCF table scan */
James Smartd439d282010-09-29 11:18:45 -04001127 spin_lock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -05001128 phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE);
James Smarta93ff372010-10-22 11:06:08 -04001129 phba->hba_flag &= ~FCF_TS_INPROG;
1130 if (vport->port_state != LPFC_FLOGI) {
1131 phba->hba_flag |= FCF_RR_INPROG;
1132 spin_unlock_irq(&phba->hbalock);
James Smart76a95d72010-11-20 23:11:48 -05001133 lpfc_issue_init_vfi(vport);
James Smarta93ff372010-10-22 11:06:08 -04001134 goto out;
1135 }
1136 spin_unlock_irq(&phba->hbalock);
1137 goto out;
James Smart6fb120a2009-05-22 14:52:59 -04001138
James Smarta93ff372010-10-22 11:06:08 -04001139fail_out:
1140 spin_lock_irq(&phba->hbalock);
1141 phba->hba_flag &= ~FCF_RR_INPROG;
1142 spin_unlock_irq(&phba->hbalock);
1143out:
James Smart6fb120a2009-05-22 14:52:59 -04001144 mempool_free(mboxq, phba->mbox_mem_pool);
James Smart6fb120a2009-05-22 14:52:59 -04001145}
1146
1147/**
1148 * lpfc_fab_name_match - Check if the fcf fabric name match.
1149 * @fab_name: pointer to fabric name.
1150 * @new_fcf_record: pointer to fcf record.
1151 *
1152 * This routine compare the fcf record's fabric name with provided
1153 * fabric name. If the fabric name are identical this function
1154 * returns 1 else return 0.
1155 **/
1156static uint32_t
1157lpfc_fab_name_match(uint8_t *fab_name, struct fcf_record *new_fcf_record)
1158{
James Smartecfd03c2010-02-12 14:41:27 -05001159 if (fab_name[0] != bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record))
James Smart6fb120a2009-05-22 14:52:59 -04001160 return 0;
James Smartecfd03c2010-02-12 14:41:27 -05001161 if (fab_name[1] != bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record))
1162 return 0;
1163 if (fab_name[2] != bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record))
1164 return 0;
1165 if (fab_name[3] != bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record))
1166 return 0;
1167 if (fab_name[4] != bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record))
1168 return 0;
1169 if (fab_name[5] != bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record))
1170 return 0;
1171 if (fab_name[6] != bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record))
1172 return 0;
1173 if (fab_name[7] != bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record))
1174 return 0;
1175 return 1;
James Smart6fb120a2009-05-22 14:52:59 -04001176}
1177
1178/**
James Smart8fa38512009-07-19 10:01:03 -04001179 * lpfc_sw_name_match - Check if the fcf switch name match.
1180 * @fab_name: pointer to fabric name.
1181 * @new_fcf_record: pointer to fcf record.
1182 *
1183 * This routine compare the fcf record's switch name with provided
1184 * switch name. If the switch name are identical this function
1185 * returns 1 else return 0.
1186 **/
1187static uint32_t
1188lpfc_sw_name_match(uint8_t *sw_name, struct fcf_record *new_fcf_record)
1189{
James Smartecfd03c2010-02-12 14:41:27 -05001190 if (sw_name[0] != bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record))
James Smart8fa38512009-07-19 10:01:03 -04001191 return 0;
James Smartecfd03c2010-02-12 14:41:27 -05001192 if (sw_name[1] != bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record))
1193 return 0;
1194 if (sw_name[2] != bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record))
1195 return 0;
1196 if (sw_name[3] != bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record))
1197 return 0;
1198 if (sw_name[4] != bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record))
1199 return 0;
1200 if (sw_name[5] != bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record))
1201 return 0;
1202 if (sw_name[6] != bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record))
1203 return 0;
1204 if (sw_name[7] != bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record))
1205 return 0;
1206 return 1;
James Smart8fa38512009-07-19 10:01:03 -04001207}
1208
1209/**
James Smart6fb120a2009-05-22 14:52:59 -04001210 * lpfc_mac_addr_match - Check if the fcf mac address match.
James Smartecfd03c2010-02-12 14:41:27 -05001211 * @mac_addr: pointer to mac address.
James Smart6fb120a2009-05-22 14:52:59 -04001212 * @new_fcf_record: pointer to fcf record.
1213 *
1214 * This routine compare the fcf record's mac address with HBA's
1215 * FCF mac address. If the mac addresses are identical this function
1216 * returns 1 else return 0.
1217 **/
1218static uint32_t
James Smartecfd03c2010-02-12 14:41:27 -05001219lpfc_mac_addr_match(uint8_t *mac_addr, struct fcf_record *new_fcf_record)
James Smart6fb120a2009-05-22 14:52:59 -04001220{
James Smartecfd03c2010-02-12 14:41:27 -05001221 if (mac_addr[0] != bf_get(lpfc_fcf_record_mac_0, new_fcf_record))
James Smart6fb120a2009-05-22 14:52:59 -04001222 return 0;
James Smartecfd03c2010-02-12 14:41:27 -05001223 if (mac_addr[1] != bf_get(lpfc_fcf_record_mac_1, new_fcf_record))
1224 return 0;
1225 if (mac_addr[2] != bf_get(lpfc_fcf_record_mac_2, new_fcf_record))
1226 return 0;
1227 if (mac_addr[3] != bf_get(lpfc_fcf_record_mac_3, new_fcf_record))
1228 return 0;
1229 if (mac_addr[4] != bf_get(lpfc_fcf_record_mac_4, new_fcf_record))
1230 return 0;
1231 if (mac_addr[5] != bf_get(lpfc_fcf_record_mac_5, new_fcf_record))
1232 return 0;
1233 return 1;
1234}
1235
1236static bool
1237lpfc_vlan_id_match(uint16_t curr_vlan_id, uint16_t new_vlan_id)
1238{
1239 return (curr_vlan_id == new_vlan_id);
James Smart6fb120a2009-05-22 14:52:59 -04001240}
1241
1242/**
1243 * lpfc_copy_fcf_record - Copy fcf information to lpfc_hba.
James Smartecfd03c2010-02-12 14:41:27 -05001244 * @fcf: pointer to driver fcf record.
James Smart6fb120a2009-05-22 14:52:59 -04001245 * @new_fcf_record: pointer to fcf record.
1246 *
1247 * This routine copies the FCF information from the FCF
1248 * record to lpfc_hba data structure.
1249 **/
1250static void
James Smartecfd03c2010-02-12 14:41:27 -05001251lpfc_copy_fcf_record(struct lpfc_fcf_rec *fcf_rec,
1252 struct fcf_record *new_fcf_record)
James Smart6fb120a2009-05-22 14:52:59 -04001253{
James Smartecfd03c2010-02-12 14:41:27 -05001254 /* Fabric name */
1255 fcf_rec->fabric_name[0] =
James Smart6fb120a2009-05-22 14:52:59 -04001256 bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001257 fcf_rec->fabric_name[1] =
James Smart6fb120a2009-05-22 14:52:59 -04001258 bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001259 fcf_rec->fabric_name[2] =
James Smart6fb120a2009-05-22 14:52:59 -04001260 bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001261 fcf_rec->fabric_name[3] =
James Smart6fb120a2009-05-22 14:52:59 -04001262 bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001263 fcf_rec->fabric_name[4] =
James Smart6fb120a2009-05-22 14:52:59 -04001264 bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001265 fcf_rec->fabric_name[5] =
James Smart6fb120a2009-05-22 14:52:59 -04001266 bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001267 fcf_rec->fabric_name[6] =
James Smart6fb120a2009-05-22 14:52:59 -04001268 bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001269 fcf_rec->fabric_name[7] =
James Smart6fb120a2009-05-22 14:52:59 -04001270 bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001271 /* Mac address */
1272 fcf_rec->mac_addr[0] = bf_get(lpfc_fcf_record_mac_0, new_fcf_record);
1273 fcf_rec->mac_addr[1] = bf_get(lpfc_fcf_record_mac_1, new_fcf_record);
1274 fcf_rec->mac_addr[2] = bf_get(lpfc_fcf_record_mac_2, new_fcf_record);
1275 fcf_rec->mac_addr[3] = bf_get(lpfc_fcf_record_mac_3, new_fcf_record);
1276 fcf_rec->mac_addr[4] = bf_get(lpfc_fcf_record_mac_4, new_fcf_record);
1277 fcf_rec->mac_addr[5] = bf_get(lpfc_fcf_record_mac_5, new_fcf_record);
1278 /* FCF record index */
1279 fcf_rec->fcf_indx = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
1280 /* FCF record priority */
1281 fcf_rec->priority = new_fcf_record->fip_priority;
1282 /* Switch name */
1283 fcf_rec->switch_name[0] =
James Smart8fa38512009-07-19 10:01:03 -04001284 bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001285 fcf_rec->switch_name[1] =
James Smart8fa38512009-07-19 10:01:03 -04001286 bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001287 fcf_rec->switch_name[2] =
James Smart8fa38512009-07-19 10:01:03 -04001288 bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001289 fcf_rec->switch_name[3] =
James Smart8fa38512009-07-19 10:01:03 -04001290 bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001291 fcf_rec->switch_name[4] =
James Smart8fa38512009-07-19 10:01:03 -04001292 bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001293 fcf_rec->switch_name[5] =
James Smart8fa38512009-07-19 10:01:03 -04001294 bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001295 fcf_rec->switch_name[6] =
James Smart8fa38512009-07-19 10:01:03 -04001296 bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001297 fcf_rec->switch_name[7] =
James Smart8fa38512009-07-19 10:01:03 -04001298 bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record);
James Smart6fb120a2009-05-22 14:52:59 -04001299}
1300
1301/**
James Smartecfd03c2010-02-12 14:41:27 -05001302 * lpfc_update_fcf_record - Update driver fcf record
1303 * @phba: pointer to lpfc hba data structure.
1304 * @fcf_rec: pointer to driver fcf record.
1305 * @new_fcf_record: pointer to hba fcf record.
1306 * @addr_mode: address mode to be set to the driver fcf record.
1307 * @vlan_id: vlan tag to be set to the driver fcf record.
1308 * @flag: flag bits to be set to the driver fcf record.
1309 *
1310 * This routine updates the driver FCF record from the new HBA FCF record
1311 * together with the address mode, vlan_id, and other informations. This
1312 * routine is called with the host lock held.
1313 **/
1314static void
1315__lpfc_update_fcf_record(struct lpfc_hba *phba, struct lpfc_fcf_rec *fcf_rec,
1316 struct fcf_record *new_fcf_record, uint32_t addr_mode,
1317 uint16_t vlan_id, uint32_t flag)
1318{
1319 /* Copy the fields from the HBA's FCF record */
1320 lpfc_copy_fcf_record(fcf_rec, new_fcf_record);
1321 /* Update other fields of driver FCF record */
1322 fcf_rec->addr_mode = addr_mode;
1323 fcf_rec->vlan_id = vlan_id;
1324 fcf_rec->flag |= (flag | RECORD_VALID);
1325}
1326
1327/**
James Smart6fb120a2009-05-22 14:52:59 -04001328 * lpfc_register_fcf - Register the FCF with hba.
1329 * @phba: pointer to lpfc hba data structure.
1330 *
1331 * This routine issues a register fcfi mailbox command to register
1332 * the fcf with HBA.
1333 **/
1334static void
1335lpfc_register_fcf(struct lpfc_hba *phba)
1336{
1337 LPFC_MBOXQ_t *fcf_mbxq;
1338 int rc;
James Smart6fb120a2009-05-22 14:52:59 -04001339
James Smartd439d282010-09-29 11:18:45 -04001340 spin_lock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04001341 /* If the FCF is not availabe do nothing. */
1342 if (!(phba->fcf.fcf_flag & FCF_AVAILABLE)) {
James Smarta93ff372010-10-22 11:06:08 -04001343 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
James Smartd439d282010-09-29 11:18:45 -04001344 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04001345 return;
1346 }
1347
1348 /* The FCF is already registered, start discovery */
1349 if (phba->fcf.fcf_flag & FCF_REGISTERED) {
James Smartecfd03c2010-02-12 14:41:27 -05001350 phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE);
James Smarta93ff372010-10-22 11:06:08 -04001351 phba->hba_flag &= ~FCF_TS_INPROG;
1352 if (phba->pport->port_state != LPFC_FLOGI) {
1353 phba->hba_flag |= FCF_RR_INPROG;
1354 spin_unlock_irq(&phba->hbalock);
James Smart76a95d72010-11-20 23:11:48 -05001355 lpfc_issue_init_vfi(phba->pport);
James Smarta93ff372010-10-22 11:06:08 -04001356 return;
1357 }
1358 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04001359 return;
1360 }
James Smartd439d282010-09-29 11:18:45 -04001361 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04001362
James Smarta93ff372010-10-22 11:06:08 -04001363 fcf_mbxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
James Smart4d9ab992009-10-02 15:16:39 -04001364 if (!fcf_mbxq) {
James Smartd439d282010-09-29 11:18:45 -04001365 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04001366 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
James Smartd439d282010-09-29 11:18:45 -04001367 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04001368 return;
James Smart4d9ab992009-10-02 15:16:39 -04001369 }
James Smart6fb120a2009-05-22 14:52:59 -04001370
1371 lpfc_reg_fcfi(phba, fcf_mbxq);
1372 fcf_mbxq->vport = phba->pport;
1373 fcf_mbxq->mbox_cmpl = lpfc_mbx_cmpl_reg_fcfi;
1374 rc = lpfc_sli_issue_mbox(phba, fcf_mbxq, MBX_NOWAIT);
James Smart4d9ab992009-10-02 15:16:39 -04001375 if (rc == MBX_NOT_FINISHED) {
James Smartd439d282010-09-29 11:18:45 -04001376 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04001377 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
James Smartd439d282010-09-29 11:18:45 -04001378 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04001379 mempool_free(fcf_mbxq, phba->mbox_mem_pool);
James Smart4d9ab992009-10-02 15:16:39 -04001380 }
James Smart6fb120a2009-05-22 14:52:59 -04001381
1382 return;
1383}
1384
1385/**
1386 * lpfc_match_fcf_conn_list - Check if the FCF record can be used for discovery.
1387 * @phba: pointer to lpfc hba data structure.
1388 * @new_fcf_record: pointer to fcf record.
1389 * @boot_flag: Indicates if this record used by boot bios.
1390 * @addr_mode: The address mode to be used by this FCF
James Smartecfd03c2010-02-12 14:41:27 -05001391 * @vlan_id: The vlan id to be used as vlan tagging by this FCF.
James Smart6fb120a2009-05-22 14:52:59 -04001392 *
1393 * This routine compare the fcf record with connect list obtained from the
1394 * config region to decide if this FCF can be used for SAN discovery. It returns
1395 * 1 if this record can be used for SAN discovery else return zero. If this FCF
1396 * record can be used for SAN discovery, the boot_flag will indicate if this FCF
1397 * is used by boot bios and addr_mode will indicate the addressing mode to be
1398 * used for this FCF when the function returns.
1399 * If the FCF record need to be used with a particular vlan id, the vlan is
1400 * set in the vlan_id on return of the function. If not VLAN tagging need to
James Smartdbb6b3a2010-06-08 18:31:37 -04001401 * be used with the FCF vlan_id will be set to LPFC_FCOE_NULL_VID;
James Smart6fb120a2009-05-22 14:52:59 -04001402 **/
1403static int
1404lpfc_match_fcf_conn_list(struct lpfc_hba *phba,
1405 struct fcf_record *new_fcf_record,
1406 uint32_t *boot_flag, uint32_t *addr_mode,
1407 uint16_t *vlan_id)
1408{
1409 struct lpfc_fcf_conn_entry *conn_entry;
James Smart4d9ab992009-10-02 15:16:39 -04001410 int i, j, fcf_vlan_id = 0;
1411
1412 /* Find the lowest VLAN id in the FCF record */
1413 for (i = 0; i < 512; i++) {
1414 if (new_fcf_record->vlan_bitmap[i]) {
1415 fcf_vlan_id = i * 8;
1416 j = 0;
1417 while (!((new_fcf_record->vlan_bitmap[i] >> j) & 1)) {
1418 j++;
1419 fcf_vlan_id++;
1420 }
1421 break;
1422 }
1423 }
James Smart6fb120a2009-05-22 14:52:59 -04001424
James Smart0c287582009-06-10 17:22:56 -04001425 /* If FCF not available return 0 */
1426 if (!bf_get(lpfc_fcf_record_fcf_avail, new_fcf_record) ||
1427 !bf_get(lpfc_fcf_record_fcf_valid, new_fcf_record))
1428 return 0;
1429
James Smart45ed1192009-10-02 15:17:02 -04001430 if (!(phba->hba_flag & HBA_FIP_SUPPORT)) {
James Smart6fb120a2009-05-22 14:52:59 -04001431 *boot_flag = 0;
1432 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1433 new_fcf_record);
1434 if (phba->valid_vlan)
1435 *vlan_id = phba->vlan_id;
1436 else
James Smartdbb6b3a2010-06-08 18:31:37 -04001437 *vlan_id = LPFC_FCOE_NULL_VID;
James Smart6fb120a2009-05-22 14:52:59 -04001438 return 1;
1439 }
1440
1441 /*
1442 * If there are no FCF connection table entry, driver connect to all
1443 * FCFs.
1444 */
1445 if (list_empty(&phba->fcf_conn_rec_list)) {
1446 *boot_flag = 0;
1447 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1448 new_fcf_record);
James Smart0c287582009-06-10 17:22:56 -04001449
1450 /*
1451 * When there are no FCF connect entries, use driver's default
1452 * addressing mode - FPMA.
1453 */
1454 if (*addr_mode & LPFC_FCF_FPMA)
1455 *addr_mode = LPFC_FCF_FPMA;
1456
James Smart4d9ab992009-10-02 15:16:39 -04001457 /* If FCF record report a vlan id use that vlan id */
1458 if (fcf_vlan_id)
1459 *vlan_id = fcf_vlan_id;
1460 else
James Smartdbb6b3a2010-06-08 18:31:37 -04001461 *vlan_id = LPFC_FCOE_NULL_VID;
James Smart6fb120a2009-05-22 14:52:59 -04001462 return 1;
1463 }
1464
James Smartecfd03c2010-02-12 14:41:27 -05001465 list_for_each_entry(conn_entry,
1466 &phba->fcf_conn_rec_list, list) {
James Smart6fb120a2009-05-22 14:52:59 -04001467 if (!(conn_entry->conn_rec.flags & FCFCNCT_VALID))
1468 continue;
1469
1470 if ((conn_entry->conn_rec.flags & FCFCNCT_FBNM_VALID) &&
1471 !lpfc_fab_name_match(conn_entry->conn_rec.fabric_name,
James Smart8fa38512009-07-19 10:01:03 -04001472 new_fcf_record))
James Smart6fb120a2009-05-22 14:52:59 -04001473 continue;
James Smart8fa38512009-07-19 10:01:03 -04001474 if ((conn_entry->conn_rec.flags & FCFCNCT_SWNM_VALID) &&
1475 !lpfc_sw_name_match(conn_entry->conn_rec.switch_name,
1476 new_fcf_record))
1477 continue;
James Smart6fb120a2009-05-22 14:52:59 -04001478 if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID) {
1479 /*
1480 * If the vlan bit map does not have the bit set for the
1481 * vlan id to be used, then it is not a match.
1482 */
1483 if (!(new_fcf_record->vlan_bitmap
1484 [conn_entry->conn_rec.vlan_tag / 8] &
1485 (1 << (conn_entry->conn_rec.vlan_tag % 8))))
1486 continue;
1487 }
1488
1489 /*
James Smart0c287582009-06-10 17:22:56 -04001490 * If connection record does not support any addressing mode,
1491 * skip the FCF record.
1492 */
1493 if (!(bf_get(lpfc_fcf_record_mac_addr_prov, new_fcf_record)
1494 & (LPFC_FCF_FPMA | LPFC_FCF_SPMA)))
1495 continue;
1496
1497 /*
James Smart6fb120a2009-05-22 14:52:59 -04001498 * Check if the connection record specifies a required
1499 * addressing mode.
1500 */
1501 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1502 !(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)) {
1503
1504 /*
1505 * If SPMA required but FCF not support this continue.
1506 */
1507 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1508 !(bf_get(lpfc_fcf_record_mac_addr_prov,
1509 new_fcf_record) & LPFC_FCF_SPMA))
1510 continue;
1511
1512 /*
1513 * If FPMA required but FCF not support this continue.
1514 */
1515 if (!(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1516 !(bf_get(lpfc_fcf_record_mac_addr_prov,
1517 new_fcf_record) & LPFC_FCF_FPMA))
1518 continue;
1519 }
1520
1521 /*
1522 * This fcf record matches filtering criteria.
1523 */
1524 if (conn_entry->conn_rec.flags & FCFCNCT_BOOT)
1525 *boot_flag = 1;
1526 else
1527 *boot_flag = 0;
1528
James Smart0c287582009-06-10 17:22:56 -04001529 /*
1530 * If user did not specify any addressing mode, or if the
1531 * prefered addressing mode specified by user is not supported
1532 * by FCF, allow fabric to pick the addressing mode.
1533 */
James Smart6fb120a2009-05-22 14:52:59 -04001534 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1535 new_fcf_record);
1536 /*
1537 * If the user specified a required address mode, assign that
1538 * address mode
1539 */
1540 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1541 (!(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)))
1542 *addr_mode = (conn_entry->conn_rec.flags &
1543 FCFCNCT_AM_SPMA) ?
1544 LPFC_FCF_SPMA : LPFC_FCF_FPMA;
1545 /*
1546 * If the user specified a prefered address mode, use the
1547 * addr mode only if FCF support the addr_mode.
1548 */
1549 else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1550 (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) &&
1551 (conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1552 (*addr_mode & LPFC_FCF_SPMA))
1553 *addr_mode = LPFC_FCF_SPMA;
1554 else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1555 (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) &&
1556 !(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1557 (*addr_mode & LPFC_FCF_FPMA))
1558 *addr_mode = LPFC_FCF_FPMA;
James Smart6fb120a2009-05-22 14:52:59 -04001559
James Smart4d9ab992009-10-02 15:16:39 -04001560 /* If matching connect list has a vlan id, use it */
James Smart6fb120a2009-05-22 14:52:59 -04001561 if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID)
1562 *vlan_id = conn_entry->conn_rec.vlan_tag;
James Smart4d9ab992009-10-02 15:16:39 -04001563 /*
1564 * If no vlan id is specified in connect list, use the vlan id
1565 * in the FCF record
1566 */
1567 else if (fcf_vlan_id)
1568 *vlan_id = fcf_vlan_id;
James Smart6fb120a2009-05-22 14:52:59 -04001569 else
James Smartdbb6b3a2010-06-08 18:31:37 -04001570 *vlan_id = LPFC_FCOE_NULL_VID;
James Smart6fb120a2009-05-22 14:52:59 -04001571
1572 return 1;
1573 }
1574
1575 return 0;
1576}
1577
1578/**
James Smart32b97932009-07-19 10:01:21 -04001579 * lpfc_check_pending_fcoe_event - Check if there is pending fcoe event.
1580 * @phba: pointer to lpfc hba data structure.
1581 * @unreg_fcf: Unregister FCF if FCF table need to be re-scaned.
1582 *
1583 * This function check if there is any fcoe event pending while driver
1584 * scan FCF entries. If there is any pending event, it will restart the
1585 * FCF saning and return 1 else return 0.
1586 */
1587int
1588lpfc_check_pending_fcoe_event(struct lpfc_hba *phba, uint8_t unreg_fcf)
1589{
James Smart32b97932009-07-19 10:01:21 -04001590 /*
1591 * If the Link is up and no FCoE events while in the
1592 * FCF discovery, no need to restart FCF discovery.
1593 */
1594 if ((phba->link_state >= LPFC_LINK_UP) &&
James Smarta93ff372010-10-22 11:06:08 -04001595 (phba->fcoe_eventtag == phba->fcoe_eventtag_at_fcf_scan))
James Smart32b97932009-07-19 10:01:21 -04001596 return 0;
1597
James Smart0c9ab6f2010-02-26 14:15:57 -05001598 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
1599 "2768 Pending link or FCF event during current "
1600 "handling of the previous event: link_state:x%x, "
1601 "evt_tag_at_scan:x%x, evt_tag_current:x%x\n",
1602 phba->link_state, phba->fcoe_eventtag_at_fcf_scan,
1603 phba->fcoe_eventtag);
1604
James Smart32b97932009-07-19 10:01:21 -04001605 spin_lock_irq(&phba->hbalock);
1606 phba->fcf.fcf_flag &= ~FCF_AVAILABLE;
1607 spin_unlock_irq(&phba->hbalock);
1608
James Smart0c9ab6f2010-02-26 14:15:57 -05001609 if (phba->link_state >= LPFC_LINK_UP) {
1610 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
1611 "2780 Restart FCF table scan due to "
1612 "pending FCF event:evt_tag_at_scan:x%x, "
1613 "evt_tag_current:x%x\n",
1614 phba->fcoe_eventtag_at_fcf_scan,
1615 phba->fcoe_eventtag);
1616 lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
1617 } else {
James Smart4d9ab992009-10-02 15:16:39 -04001618 /*
James Smarta93ff372010-10-22 11:06:08 -04001619 * Do not continue FCF discovery and clear FCF_TS_INPROG
James Smart4d9ab992009-10-02 15:16:39 -04001620 * flag
1621 */
James Smartdbb6b3a2010-06-08 18:31:37 -04001622 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
1623 "2833 Stop FCF discovery process due to link "
1624 "state change (x%x)\n", phba->link_state);
James Smart1c6f4ef52009-11-18 15:40:49 -05001625 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04001626 phba->hba_flag &= ~(FCF_TS_INPROG | FCF_RR_INPROG);
James Smart0c9ab6f2010-02-26 14:15:57 -05001627 phba->fcf.fcf_flag &= ~(FCF_REDISC_FOV | FCF_DISCOVERY);
James Smart1c6f4ef52009-11-18 15:40:49 -05001628 spin_unlock_irq(&phba->hbalock);
1629 }
James Smart32b97932009-07-19 10:01:21 -04001630
James Smart0c9ab6f2010-02-26 14:15:57 -05001631 /* Unregister the currently registered FCF if required */
James Smart32b97932009-07-19 10:01:21 -04001632 if (unreg_fcf) {
1633 spin_lock_irq(&phba->hbalock);
1634 phba->fcf.fcf_flag &= ~FCF_REGISTERED;
1635 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05001636 lpfc_sli4_unregister_fcf(phba);
James Smart32b97932009-07-19 10:01:21 -04001637 }
James Smart32b97932009-07-19 10:01:21 -04001638 return 1;
1639}
1640
1641/**
James Smart999d8132010-03-15 11:24:56 -04001642 * lpfc_sli4_new_fcf_random_select - Randomly select an eligible new fcf record
1643 * @phba: pointer to lpfc hba data structure.
1644 * @fcf_cnt: number of eligible fcf record seen so far.
1645 *
1646 * This function makes an running random selection decision on FCF record to
1647 * use through a sequence of @fcf_cnt eligible FCF records with equal
1648 * probability. To perform integer manunipulation of random numbers with
1649 * size unit32_t, the lower 16 bits of the 32-bit random number returned
1650 * from random32() are taken as the random random number generated.
1651 *
1652 * Returns true when outcome is for the newly read FCF record should be
1653 * chosen; otherwise, return false when outcome is for keeping the previously
1654 * chosen FCF record.
1655 **/
1656static bool
1657lpfc_sli4_new_fcf_random_select(struct lpfc_hba *phba, uint32_t fcf_cnt)
1658{
1659 uint32_t rand_num;
1660
1661 /* Get 16-bit uniform random number */
1662 rand_num = (0xFFFF & random32());
1663
1664 /* Decision with probability 1/fcf_cnt */
1665 if ((fcf_cnt * rand_num) < 0xFFFF)
1666 return true;
1667 else
1668 return false;
1669}
1670
1671/**
James Smart3804dc82010-07-14 15:31:37 -04001672 * lpfc_sli4_fcf_rec_mbox_parse - Parse read_fcf mbox command.
James Smart6fb120a2009-05-22 14:52:59 -04001673 * @phba: pointer to lpfc hba data structure.
1674 * @mboxq: pointer to mailbox object.
James Smart0c9ab6f2010-02-26 14:15:57 -05001675 * @next_fcf_index: pointer to holder of next fcf index.
James Smart6fb120a2009-05-22 14:52:59 -04001676 *
James Smart0c9ab6f2010-02-26 14:15:57 -05001677 * This routine parses the non-embedded fcf mailbox command by performing the
1678 * necessarily error checking, non-embedded read FCF record mailbox command
1679 * SGE parsing, and endianness swapping.
1680 *
1681 * Returns the pointer to the new FCF record in the non-embedded mailbox
1682 * command DMA memory if successfully, other NULL.
James Smart6fb120a2009-05-22 14:52:59 -04001683 */
James Smart0c9ab6f2010-02-26 14:15:57 -05001684static struct fcf_record *
1685lpfc_sli4_fcf_rec_mbox_parse(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
1686 uint16_t *next_fcf_index)
James Smart6fb120a2009-05-22 14:52:59 -04001687{
1688 void *virt_addr;
1689 dma_addr_t phys_addr;
James Smart6fb120a2009-05-22 14:52:59 -04001690 struct lpfc_mbx_sge sge;
1691 struct lpfc_mbx_read_fcf_tbl *read_fcf;
1692 uint32_t shdr_status, shdr_add_status;
1693 union lpfc_sli4_cfg_shdr *shdr;
1694 struct fcf_record *new_fcf_record;
James Smart32b97932009-07-19 10:01:21 -04001695
James Smart6fb120a2009-05-22 14:52:59 -04001696 /* Get the first SGE entry from the non-embedded DMA memory. This
1697 * routine only uses a single SGE.
1698 */
1699 lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
1700 phys_addr = getPaddr(sge.pa_hi, sge.pa_lo);
1701 if (unlikely(!mboxq->sge_array)) {
1702 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1703 "2524 Failed to get the non-embedded SGE "
1704 "virtual address\n");
James Smart0c9ab6f2010-02-26 14:15:57 -05001705 return NULL;
James Smart6fb120a2009-05-22 14:52:59 -04001706 }
1707 virt_addr = mboxq->sge_array->addr[0];
1708
1709 shdr = (union lpfc_sli4_cfg_shdr *)virt_addr;
1710 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
James Smart0c9ab6f2010-02-26 14:15:57 -05001711 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
James Smart6fb120a2009-05-22 14:52:59 -04001712 if (shdr_status || shdr_add_status) {
James Smart0c9ab6f2010-02-26 14:15:57 -05001713 if (shdr_status == STATUS_FCF_TABLE_EMPTY)
1714 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
James Smartdef9c7a2009-12-21 17:02:28 -05001715 "2726 READ_FCF_RECORD Indicates empty "
1716 "FCF table.\n");
James Smart0c9ab6f2010-02-26 14:15:57 -05001717 else
1718 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
James Smartdef9c7a2009-12-21 17:02:28 -05001719 "2521 READ_FCF_RECORD mailbox failed "
James Smart0c9ab6f2010-02-26 14:15:57 -05001720 "with status x%x add_status x%x, "
1721 "mbx\n", shdr_status, shdr_add_status);
1722 return NULL;
James Smart6fb120a2009-05-22 14:52:59 -04001723 }
James Smart0c9ab6f2010-02-26 14:15:57 -05001724
1725 /* Interpreting the returned information of the FCF record */
James Smart6fb120a2009-05-22 14:52:59 -04001726 read_fcf = (struct lpfc_mbx_read_fcf_tbl *)virt_addr;
1727 lpfc_sli_pcimem_bcopy(read_fcf, read_fcf,
1728 sizeof(struct lpfc_mbx_read_fcf_tbl));
James Smart0c9ab6f2010-02-26 14:15:57 -05001729 *next_fcf_index = bf_get(lpfc_mbx_read_fcf_tbl_nxt_vindx, read_fcf);
James Smart6fb120a2009-05-22 14:52:59 -04001730 new_fcf_record = (struct fcf_record *)(virt_addr +
1731 sizeof(struct lpfc_mbx_read_fcf_tbl));
1732 lpfc_sli_pcimem_bcopy(new_fcf_record, new_fcf_record,
James Smartcb5172e2010-03-15 11:25:07 -04001733 offsetof(struct fcf_record, vlan_bitmap));
1734 new_fcf_record->word137 = le32_to_cpu(new_fcf_record->word137);
1735 new_fcf_record->word138 = le32_to_cpu(new_fcf_record->word138);
James Smart6fb120a2009-05-22 14:52:59 -04001736
James Smart0c9ab6f2010-02-26 14:15:57 -05001737 return new_fcf_record;
1738}
1739
1740/**
1741 * lpfc_sli4_log_fcf_record_info - Log the information of a fcf record
1742 * @phba: pointer to lpfc hba data structure.
1743 * @fcf_record: pointer to the fcf record.
1744 * @vlan_id: the lowest vlan identifier associated to this fcf record.
1745 * @next_fcf_index: the index to the next fcf record in hba's fcf table.
1746 *
1747 * This routine logs the detailed FCF record if the LOG_FIP loggin is
1748 * enabled.
1749 **/
1750static void
1751lpfc_sli4_log_fcf_record_info(struct lpfc_hba *phba,
1752 struct fcf_record *fcf_record,
1753 uint16_t vlan_id,
1754 uint16_t next_fcf_index)
1755{
1756 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
1757 "2764 READ_FCF_RECORD:\n"
1758 "\tFCF_Index : x%x\n"
1759 "\tFCF_Avail : x%x\n"
1760 "\tFCF_Valid : x%x\n"
1761 "\tFIP_Priority : x%x\n"
1762 "\tMAC_Provider : x%x\n"
1763 "\tLowest VLANID : x%x\n"
1764 "\tFCF_MAC Addr : x%x:%x:%x:%x:%x:%x\n"
1765 "\tFabric_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n"
1766 "\tSwitch_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n"
1767 "\tNext_FCF_Index: x%x\n",
1768 bf_get(lpfc_fcf_record_fcf_index, fcf_record),
1769 bf_get(lpfc_fcf_record_fcf_avail, fcf_record),
1770 bf_get(lpfc_fcf_record_fcf_valid, fcf_record),
1771 fcf_record->fip_priority,
1772 bf_get(lpfc_fcf_record_mac_addr_prov, fcf_record),
1773 vlan_id,
1774 bf_get(lpfc_fcf_record_mac_0, fcf_record),
1775 bf_get(lpfc_fcf_record_mac_1, fcf_record),
1776 bf_get(lpfc_fcf_record_mac_2, fcf_record),
1777 bf_get(lpfc_fcf_record_mac_3, fcf_record),
1778 bf_get(lpfc_fcf_record_mac_4, fcf_record),
1779 bf_get(lpfc_fcf_record_mac_5, fcf_record),
1780 bf_get(lpfc_fcf_record_fab_name_0, fcf_record),
1781 bf_get(lpfc_fcf_record_fab_name_1, fcf_record),
1782 bf_get(lpfc_fcf_record_fab_name_2, fcf_record),
1783 bf_get(lpfc_fcf_record_fab_name_3, fcf_record),
1784 bf_get(lpfc_fcf_record_fab_name_4, fcf_record),
1785 bf_get(lpfc_fcf_record_fab_name_5, fcf_record),
1786 bf_get(lpfc_fcf_record_fab_name_6, fcf_record),
1787 bf_get(lpfc_fcf_record_fab_name_7, fcf_record),
1788 bf_get(lpfc_fcf_record_switch_name_0, fcf_record),
1789 bf_get(lpfc_fcf_record_switch_name_1, fcf_record),
1790 bf_get(lpfc_fcf_record_switch_name_2, fcf_record),
1791 bf_get(lpfc_fcf_record_switch_name_3, fcf_record),
1792 bf_get(lpfc_fcf_record_switch_name_4, fcf_record),
1793 bf_get(lpfc_fcf_record_switch_name_5, fcf_record),
1794 bf_get(lpfc_fcf_record_switch_name_6, fcf_record),
1795 bf_get(lpfc_fcf_record_switch_name_7, fcf_record),
1796 next_fcf_index);
1797}
1798
1799/**
James Smartdbb6b3a2010-06-08 18:31:37 -04001800 lpfc_sli4_fcf_record_match - testing new FCF record for matching existing FCF
1801 * @phba: pointer to lpfc hba data structure.
1802 * @fcf_rec: pointer to an existing FCF record.
1803 * @new_fcf_record: pointer to a new FCF record.
1804 * @new_vlan_id: vlan id from the new FCF record.
1805 *
1806 * This function performs matching test of a new FCF record against an existing
1807 * FCF record. If the new_vlan_id passed in is LPFC_FCOE_IGNORE_VID, vlan id
1808 * will not be used as part of the FCF record matching criteria.
1809 *
1810 * Returns true if all the fields matching, otherwise returns false.
1811 */
1812static bool
1813lpfc_sli4_fcf_record_match(struct lpfc_hba *phba,
1814 struct lpfc_fcf_rec *fcf_rec,
1815 struct fcf_record *new_fcf_record,
1816 uint16_t new_vlan_id)
1817{
1818 if (new_vlan_id != LPFC_FCOE_IGNORE_VID)
1819 if (!lpfc_vlan_id_match(fcf_rec->vlan_id, new_vlan_id))
1820 return false;
1821 if (!lpfc_mac_addr_match(fcf_rec->mac_addr, new_fcf_record))
1822 return false;
1823 if (!lpfc_sw_name_match(fcf_rec->switch_name, new_fcf_record))
1824 return false;
1825 if (!lpfc_fab_name_match(fcf_rec->fabric_name, new_fcf_record))
1826 return false;
1827 return true;
1828}
1829
1830/**
James Smarta93ff372010-10-22 11:06:08 -04001831 * lpfc_sli4_fcf_rr_next_proc - processing next roundrobin fcf
1832 * @vport: Pointer to vport object.
1833 * @fcf_index: index to next fcf.
1834 *
1835 * This function processing the roundrobin fcf failover to next fcf index.
1836 * When this function is invoked, there will be a current fcf registered
1837 * for flogi.
1838 * Return: 0 for continue retrying flogi on currently registered fcf;
1839 * 1 for stop flogi on currently registered fcf;
1840 */
1841int lpfc_sli4_fcf_rr_next_proc(struct lpfc_vport *vport, uint16_t fcf_index)
1842{
1843 struct lpfc_hba *phba = vport->phba;
1844 int rc;
1845
1846 if (fcf_index == LPFC_FCOE_FCF_NEXT_NONE) {
1847 spin_lock_irq(&phba->hbalock);
1848 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
1849 spin_unlock_irq(&phba->hbalock);
1850 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
1851 "2872 Devloss tmo with no eligible "
1852 "FCF, unregister in-use FCF (x%x) "
1853 "and rescan FCF table\n",
1854 phba->fcf.current_rec.fcf_indx);
1855 lpfc_unregister_fcf_rescan(phba);
1856 goto stop_flogi_current_fcf;
1857 }
1858 /* Mark the end to FLOGI roundrobin failover */
1859 phba->hba_flag &= ~FCF_RR_INPROG;
1860 /* Allow action to new fcf asynchronous event */
1861 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
1862 spin_unlock_irq(&phba->hbalock);
1863 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
1864 "2865 No FCF available, stop roundrobin FCF "
1865 "failover and change port state:x%x/x%x\n",
1866 phba->pport->port_state, LPFC_VPORT_UNKNOWN);
1867 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
1868 goto stop_flogi_current_fcf;
1869 } else {
1870 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_ELS,
1871 "2794 Try FLOGI roundrobin FCF failover to "
1872 "(x%x)\n", fcf_index);
1873 rc = lpfc_sli4_fcf_rr_read_fcf_rec(phba, fcf_index);
1874 if (rc)
1875 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP | LOG_ELS,
1876 "2761 FLOGI roundrobin FCF failover "
1877 "failed (rc:x%x) to read FCF (x%x)\n",
1878 rc, phba->fcf.current_rec.fcf_indx);
1879 else
1880 goto stop_flogi_current_fcf;
1881 }
1882 return 0;
1883
1884stop_flogi_current_fcf:
1885 lpfc_can_disctmo(vport);
1886 return 1;
1887}
1888
1889/**
James Smart0c9ab6f2010-02-26 14:15:57 -05001890 * lpfc_mbx_cmpl_fcf_scan_read_fcf_rec - fcf scan read_fcf mbox cmpl handler.
1891 * @phba: pointer to lpfc hba data structure.
1892 * @mboxq: pointer to mailbox object.
1893 *
1894 * This function iterates through all the fcf records available in
1895 * HBA and chooses the optimal FCF record for discovery. After finding
1896 * the FCF for discovery it registers the FCF record and kicks start
1897 * discovery.
1898 * If FCF_IN_USE flag is set in currently used FCF, the routine tries to
1899 * use an FCF record which matches fabric name and mac address of the
1900 * currently used FCF record.
1901 * If the driver supports only one FCF, it will try to use the FCF record
1902 * used by BOOT_BIOS.
1903 */
1904void
1905lpfc_mbx_cmpl_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
1906{
1907 struct fcf_record *new_fcf_record;
1908 uint32_t boot_flag, addr_mode;
1909 uint16_t fcf_index, next_fcf_index;
1910 struct lpfc_fcf_rec *fcf_rec = NULL;
1911 uint16_t vlan_id;
James Smart999d8132010-03-15 11:24:56 -04001912 uint32_t seed;
1913 bool select_new_fcf;
James Smart0c9ab6f2010-02-26 14:15:57 -05001914 int rc;
1915
1916 /* If there is pending FCoE event restart FCF table scan */
James Smarta93ff372010-10-22 11:06:08 -04001917 if (lpfc_check_pending_fcoe_event(phba, LPFC_SKIP_UNREG_FCF)) {
James Smart0c9ab6f2010-02-26 14:15:57 -05001918 lpfc_sli4_mbox_cmd_free(phba, mboxq);
1919 return;
1920 }
1921
1922 /* Parse the FCF record from the non-embedded mailbox command */
1923 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
1924 &next_fcf_index);
1925 if (!new_fcf_record) {
James Smarta93ff372010-10-22 11:06:08 -04001926 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
James Smart0c9ab6f2010-02-26 14:15:57 -05001927 "2765 Mailbox command READ_FCF_RECORD "
1928 "failed to retrieve a FCF record.\n");
1929 /* Let next new FCF event trigger fast failover */
1930 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04001931 phba->hba_flag &= ~FCF_TS_INPROG;
James Smart0c9ab6f2010-02-26 14:15:57 -05001932 spin_unlock_irq(&phba->hbalock);
1933 lpfc_sli4_mbox_cmd_free(phba, mboxq);
1934 return;
1935 }
1936
1937 /* Check the FCF record against the connection list */
James Smartecfd03c2010-02-12 14:41:27 -05001938 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
1939 &addr_mode, &vlan_id);
James Smart0c9ab6f2010-02-26 14:15:57 -05001940
1941 /* Log the FCF record information if turned on */
1942 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
1943 next_fcf_index);
1944
James Smart6fb120a2009-05-22 14:52:59 -04001945 /*
1946 * If the fcf record does not match with connect list entries
James Smart0c9ab6f2010-02-26 14:15:57 -05001947 * read the next entry; otherwise, this is an eligible FCF
James Smarta93ff372010-10-22 11:06:08 -04001948 * record for roundrobin FCF failover.
James Smart6fb120a2009-05-22 14:52:59 -04001949 */
James Smart0c9ab6f2010-02-26 14:15:57 -05001950 if (!rc) {
1951 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04001952 "2781 FCF (x%x) failed connection "
1953 "list check: (x%x/x%x)\n",
James Smart0c9ab6f2010-02-26 14:15:57 -05001954 bf_get(lpfc_fcf_record_fcf_index,
1955 new_fcf_record),
1956 bf_get(lpfc_fcf_record_fcf_avail,
1957 new_fcf_record),
1958 bf_get(lpfc_fcf_record_fcf_valid,
1959 new_fcf_record));
James Smartdbb6b3a2010-06-08 18:31:37 -04001960 if ((phba->fcf.fcf_flag & FCF_IN_USE) &&
1961 lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec,
1962 new_fcf_record, LPFC_FCOE_IGNORE_VID)) {
James Smart5ac6b302010-10-22 11:05:36 -04001963 if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) !=
1964 phba->fcf.current_rec.fcf_indx) {
1965 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
1966 "2862 FCF (x%x) matches property "
1967 "of in-use FCF (x%x)\n",
1968 bf_get(lpfc_fcf_record_fcf_index,
1969 new_fcf_record),
1970 phba->fcf.current_rec.fcf_indx);
1971 goto read_next_fcf;
1972 }
James Smartdbb6b3a2010-06-08 18:31:37 -04001973 /*
1974 * In case the current in-use FCF record becomes
1975 * invalid/unavailable during FCF discovery that
1976 * was not triggered by fast FCF failover process,
1977 * treat it as fast FCF failover.
1978 */
1979 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND) &&
1980 !(phba->fcf.fcf_flag & FCF_REDISC_FOV)) {
1981 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
1982 "2835 Invalid in-use FCF "
James Smarta93ff372010-10-22 11:06:08 -04001983 "(x%x), enter FCF failover "
1984 "table scan.\n",
James Smartdbb6b3a2010-06-08 18:31:37 -04001985 phba->fcf.current_rec.fcf_indx);
1986 spin_lock_irq(&phba->hbalock);
1987 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
1988 spin_unlock_irq(&phba->hbalock);
1989 lpfc_sli4_mbox_cmd_free(phba, mboxq);
1990 lpfc_sli4_fcf_scan_read_fcf_rec(phba,
1991 LPFC_FCOE_FCF_GET_FIRST);
1992 return;
1993 }
1994 }
James Smart6fb120a2009-05-22 14:52:59 -04001995 goto read_next_fcf;
James Smart0c9ab6f2010-02-26 14:15:57 -05001996 } else {
1997 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
1998 rc = lpfc_sli4_fcf_rr_index_set(phba, fcf_index);
1999 if (rc)
2000 goto read_next_fcf;
2001 }
2002
James Smart6fb120a2009-05-22 14:52:59 -04002003 /*
2004 * If this is not the first FCF discovery of the HBA, use last
James Smartecfd03c2010-02-12 14:41:27 -05002005 * FCF record for the discovery. The condition that a rescan
2006 * matches the in-use FCF record: fabric name, switch name, mac
2007 * address, and vlan_id.
James Smart6fb120a2009-05-22 14:52:59 -04002008 */
James Smart0c9ab6f2010-02-26 14:15:57 -05002009 spin_lock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04002010 if (phba->fcf.fcf_flag & FCF_IN_USE) {
James Smartdbb6b3a2010-06-08 18:31:37 -04002011 if (lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec,
2012 new_fcf_record, vlan_id)) {
James Smart5ac6b302010-10-22 11:05:36 -04002013 if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) ==
2014 phba->fcf.current_rec.fcf_indx) {
2015 phba->fcf.fcf_flag |= FCF_AVAILABLE;
2016 if (phba->fcf.fcf_flag & FCF_REDISC_PEND)
2017 /* Stop FCF redisc wait timer */
2018 __lpfc_sli4_stop_fcf_redisc_wait_timer(
2019 phba);
2020 else if (phba->fcf.fcf_flag & FCF_REDISC_FOV)
2021 /* Fast failover, mark completed */
2022 phba->fcf.fcf_flag &= ~FCF_REDISC_FOV;
2023 spin_unlock_irq(&phba->hbalock);
2024 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2025 "2836 New FCF matches in-use "
2026 "FCF (x%x)\n",
2027 phba->fcf.current_rec.fcf_indx);
2028 goto out;
2029 } else
2030 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
2031 "2863 New FCF (x%x) matches "
2032 "property of in-use FCF (x%x)\n",
James Smartdbb6b3a2010-06-08 18:31:37 -04002033 bf_get(lpfc_fcf_record_fcf_index,
James Smart5ac6b302010-10-22 11:05:36 -04002034 new_fcf_record),
2035 phba->fcf.current_rec.fcf_indx);
James Smart6fb120a2009-05-22 14:52:59 -04002036 }
James Smartecfd03c2010-02-12 14:41:27 -05002037 /*
2038 * Read next FCF record from HBA searching for the matching
2039 * with in-use record only if not during the fast failover
2040 * period. In case of fast failover period, it shall try to
2041 * determine whether the FCF record just read should be the
2042 * next candidate.
2043 */
2044 if (!(phba->fcf.fcf_flag & FCF_REDISC_FOV)) {
James Smart0c9ab6f2010-02-26 14:15:57 -05002045 spin_unlock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -05002046 goto read_next_fcf;
2047 }
James Smart6fb120a2009-05-22 14:52:59 -04002048 }
James Smartecfd03c2010-02-12 14:41:27 -05002049 /*
2050 * Update on failover FCF record only if it's in FCF fast-failover
2051 * period; otherwise, update on current FCF record.
2052 */
James Smartfc2b9892010-02-26 14:15:29 -05002053 if (phba->fcf.fcf_flag & FCF_REDISC_FOV)
2054 fcf_rec = &phba->fcf.failover_rec;
2055 else
James Smartecfd03c2010-02-12 14:41:27 -05002056 fcf_rec = &phba->fcf.current_rec;
2057
James Smart6fb120a2009-05-22 14:52:59 -04002058 if (phba->fcf.fcf_flag & FCF_AVAILABLE) {
2059 /*
James Smartecfd03c2010-02-12 14:41:27 -05002060 * If the driver FCF record does not have boot flag
2061 * set and new hba fcf record has boot flag set, use
2062 * the new hba fcf record.
James Smart6fb120a2009-05-22 14:52:59 -04002063 */
James Smartecfd03c2010-02-12 14:41:27 -05002064 if (boot_flag && !(fcf_rec->flag & BOOT_ENABLE)) {
2065 /* Choose this FCF record */
James Smartdbb6b3a2010-06-08 18:31:37 -04002066 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2067 "2837 Update current FCF record "
2068 "(x%x) with new FCF record (x%x)\n",
2069 fcf_rec->fcf_indx,
2070 bf_get(lpfc_fcf_record_fcf_index,
2071 new_fcf_record));
James Smartecfd03c2010-02-12 14:41:27 -05002072 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
2073 addr_mode, vlan_id, BOOT_ENABLE);
James Smart0c9ab6f2010-02-26 14:15:57 -05002074 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04002075 goto read_next_fcf;
2076 }
2077 /*
James Smartecfd03c2010-02-12 14:41:27 -05002078 * If the driver FCF record has boot flag set and the
2079 * new hba FCF record does not have boot flag, read
2080 * the next FCF record.
James Smart6fb120a2009-05-22 14:52:59 -04002081 */
James Smartecfd03c2010-02-12 14:41:27 -05002082 if (!boot_flag && (fcf_rec->flag & BOOT_ENABLE)) {
James Smart0c9ab6f2010-02-26 14:15:57 -05002083 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04002084 goto read_next_fcf;
2085 }
2086 /*
James Smartecfd03c2010-02-12 14:41:27 -05002087 * If the new hba FCF record has lower priority value
2088 * than the driver FCF record, use the new record.
James Smart6fb120a2009-05-22 14:52:59 -04002089 */
James Smartfc2b9892010-02-26 14:15:29 -05002090 if (new_fcf_record->fip_priority < fcf_rec->priority) {
James Smart999d8132010-03-15 11:24:56 -04002091 /* Choose the new FCF record with lower priority */
James Smartdbb6b3a2010-06-08 18:31:37 -04002092 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2093 "2838 Update current FCF record "
2094 "(x%x) with new FCF record (x%x)\n",
2095 fcf_rec->fcf_indx,
2096 bf_get(lpfc_fcf_record_fcf_index,
2097 new_fcf_record));
James Smartecfd03c2010-02-12 14:41:27 -05002098 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
2099 addr_mode, vlan_id, 0);
James Smart999d8132010-03-15 11:24:56 -04002100 /* Reset running random FCF selection count */
2101 phba->fcf.eligible_fcf_cnt = 1;
2102 } else if (new_fcf_record->fip_priority == fcf_rec->priority) {
2103 /* Update running random FCF selection count */
2104 phba->fcf.eligible_fcf_cnt++;
2105 select_new_fcf = lpfc_sli4_new_fcf_random_select(phba,
2106 phba->fcf.eligible_fcf_cnt);
James Smartdbb6b3a2010-06-08 18:31:37 -04002107 if (select_new_fcf) {
2108 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2109 "2839 Update current FCF record "
2110 "(x%x) with new FCF record (x%x)\n",
2111 fcf_rec->fcf_indx,
2112 bf_get(lpfc_fcf_record_fcf_index,
2113 new_fcf_record));
James Smart999d8132010-03-15 11:24:56 -04002114 /* Choose the new FCF by random selection */
2115 __lpfc_update_fcf_record(phba, fcf_rec,
2116 new_fcf_record,
2117 addr_mode, vlan_id, 0);
James Smartdbb6b3a2010-06-08 18:31:37 -04002118 }
James Smart6fb120a2009-05-22 14:52:59 -04002119 }
James Smart0c9ab6f2010-02-26 14:15:57 -05002120 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04002121 goto read_next_fcf;
2122 }
2123 /*
James Smartecfd03c2010-02-12 14:41:27 -05002124 * This is the first suitable FCF record, choose this record for
2125 * initial best-fit FCF.
James Smart6fb120a2009-05-22 14:52:59 -04002126 */
James Smartecfd03c2010-02-12 14:41:27 -05002127 if (fcf_rec) {
James Smartdbb6b3a2010-06-08 18:31:37 -04002128 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04002129 "2840 Update initial FCF candidate "
2130 "with FCF (x%x)\n",
James Smartdbb6b3a2010-06-08 18:31:37 -04002131 bf_get(lpfc_fcf_record_fcf_index,
2132 new_fcf_record));
James Smartecfd03c2010-02-12 14:41:27 -05002133 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
2134 addr_mode, vlan_id, (boot_flag ?
2135 BOOT_ENABLE : 0));
2136 phba->fcf.fcf_flag |= FCF_AVAILABLE;
James Smart999d8132010-03-15 11:24:56 -04002137 /* Setup initial running random FCF selection count */
2138 phba->fcf.eligible_fcf_cnt = 1;
2139 /* Seeding the random number generator for random selection */
2140 seed = (uint32_t)(0xFFFFFFFF & jiffies);
2141 srandom32(seed);
James Smart6fb120a2009-05-22 14:52:59 -04002142 }
James Smart0c9ab6f2010-02-26 14:15:57 -05002143 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04002144 goto read_next_fcf;
2145
2146read_next_fcf:
2147 lpfc_sli4_mbox_cmd_free(phba, mboxq);
James Smartecfd03c2010-02-12 14:41:27 -05002148 if (next_fcf_index == LPFC_FCOE_FCF_NEXT_NONE || next_fcf_index == 0) {
2149 if (phba->fcf.fcf_flag & FCF_REDISC_FOV) {
2150 /*
2151 * Case of FCF fast failover scan
2152 */
2153
2154 /*
2155 * It has not found any suitable FCF record, cancel
2156 * FCF scan inprogress, and do nothing
2157 */
2158 if (!(phba->fcf.failover_rec.flag & RECORD_VALID)) {
James Smart0c9ab6f2010-02-26 14:15:57 -05002159 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04002160 "2782 No suitable FCF found: "
2161 "(x%x/x%x)\n",
James Smart0c9ab6f2010-02-26 14:15:57 -05002162 phba->fcoe_eventtag_at_fcf_scan,
2163 bf_get(lpfc_fcf_record_fcf_index,
2164 new_fcf_record));
James Smart0c9ab6f2010-02-26 14:15:57 -05002165 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04002166 if (phba->hba_flag & HBA_DEVLOSS_TMO) {
2167 phba->hba_flag &= ~FCF_TS_INPROG;
2168 spin_unlock_irq(&phba->hbalock);
2169 /* Unregister in-use FCF and rescan */
2170 lpfc_printf_log(phba, KERN_INFO,
2171 LOG_FIP,
2172 "2864 On devloss tmo "
2173 "unreg in-use FCF and "
2174 "rescan FCF table\n");
2175 lpfc_unregister_fcf_rescan(phba);
2176 return;
2177 }
2178 /*
2179 * Let next new FCF event trigger fast failover
2180 */
2181 phba->hba_flag &= ~FCF_TS_INPROG;
James Smart0c9ab6f2010-02-26 14:15:57 -05002182 spin_unlock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -05002183 return;
2184 }
2185 /*
2186 * It has found a suitable FCF record that is not
2187 * the same as in-use FCF record, unregister the
2188 * in-use FCF record, replace the in-use FCF record
2189 * with the new FCF record, mark FCF fast failover
2190 * completed, and then start register the new FCF
2191 * record.
2192 */
2193
James Smart0c9ab6f2010-02-26 14:15:57 -05002194 /* Unregister the current in-use FCF record */
James Smartecfd03c2010-02-12 14:41:27 -05002195 lpfc_unregister_fcf(phba);
James Smart0c9ab6f2010-02-26 14:15:57 -05002196
2197 /* Replace in-use record with the new record */
James Smartdbb6b3a2010-06-08 18:31:37 -04002198 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04002199 "2842 Replace in-use FCF (x%x) "
2200 "with failover FCF (x%x)\n",
James Smartdbb6b3a2010-06-08 18:31:37 -04002201 phba->fcf.current_rec.fcf_indx,
2202 phba->fcf.failover_rec.fcf_indx);
James Smartecfd03c2010-02-12 14:41:27 -05002203 memcpy(&phba->fcf.current_rec,
2204 &phba->fcf.failover_rec,
2205 sizeof(struct lpfc_fcf_rec));
James Smart3804dc82010-07-14 15:31:37 -04002206 /*
2207 * Mark the fast FCF failover rediscovery completed
2208 * and the start of the first round of the roundrobin
2209 * FCF failover.
2210 */
James Smart0c9ab6f2010-02-26 14:15:57 -05002211 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04002212 phba->fcf.fcf_flag &= ~FCF_REDISC_FOV;
James Smart0c9ab6f2010-02-26 14:15:57 -05002213 spin_unlock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -05002214 /* Register to the new FCF record */
2215 lpfc_register_fcf(phba);
2216 } else {
2217 /*
2218 * In case of transaction period to fast FCF failover,
2219 * do nothing when search to the end of the FCF table.
2220 */
2221 if ((phba->fcf.fcf_flag & FCF_REDISC_EVT) ||
2222 (phba->fcf.fcf_flag & FCF_REDISC_PEND))
2223 return;
James Smartdbb6b3a2010-06-08 18:31:37 -04002224
2225 if (phba->fcf.fcf_flag & FCF_IN_USE) {
2226 /*
2227 * In case the current in-use FCF record no
2228 * longer existed during FCF discovery that
2229 * was not triggered by fast FCF failover
2230 * process, treat it as fast FCF failover.
2231 */
2232 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2233 "2841 In-use FCF record (x%x) "
2234 "not reported, entering fast "
2235 "FCF failover mode scanning.\n",
2236 phba->fcf.current_rec.fcf_indx);
2237 spin_lock_irq(&phba->hbalock);
2238 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
2239 spin_unlock_irq(&phba->hbalock);
2240 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2241 lpfc_sli4_fcf_scan_read_fcf_rec(phba,
2242 LPFC_FCOE_FCF_GET_FIRST);
2243 return;
2244 }
James Smart0c9ab6f2010-02-26 14:15:57 -05002245 /* Register to the new FCF record */
James Smartecfd03c2010-02-12 14:41:27 -05002246 lpfc_register_fcf(phba);
2247 }
2248 } else
James Smart0c9ab6f2010-02-26 14:15:57 -05002249 lpfc_sli4_fcf_scan_read_fcf_rec(phba, next_fcf_index);
James Smart6fb120a2009-05-22 14:52:59 -04002250 return;
2251
2252out:
2253 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2254 lpfc_register_fcf(phba);
2255
2256 return;
2257}
2258
2259/**
James Smarta93ff372010-10-22 11:06:08 -04002260 * lpfc_mbx_cmpl_fcf_rr_read_fcf_rec - fcf roundrobin read_fcf mbox cmpl hdler
James Smart0c9ab6f2010-02-26 14:15:57 -05002261 * @phba: pointer to lpfc hba data structure.
2262 * @mboxq: pointer to mailbox object.
2263 *
James Smarta93ff372010-10-22 11:06:08 -04002264 * This is the callback function for FLOGI failure roundrobin FCF failover
James Smart0c9ab6f2010-02-26 14:15:57 -05002265 * read FCF record mailbox command from the eligible FCF record bmask for
2266 * performing the failover. If the FCF read back is not valid/available, it
2267 * fails through to retrying FLOGI to the currently registered FCF again.
2268 * Otherwise, if the FCF read back is valid and available, it will set the
2269 * newly read FCF record to the failover FCF record, unregister currently
2270 * registered FCF record, copy the failover FCF record to the current
2271 * FCF record, and then register the current FCF record before proceeding
2272 * to trying FLOGI on the new failover FCF.
2273 */
2274void
2275lpfc_mbx_cmpl_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2276{
2277 struct fcf_record *new_fcf_record;
2278 uint32_t boot_flag, addr_mode;
James Smarta93ff372010-10-22 11:06:08 -04002279 uint16_t next_fcf_index, fcf_index;
James Smart0c9ab6f2010-02-26 14:15:57 -05002280 uint16_t current_fcf_index;
2281 uint16_t vlan_id;
James Smarta93ff372010-10-22 11:06:08 -04002282 int rc;
James Smart0c9ab6f2010-02-26 14:15:57 -05002283
James Smarta93ff372010-10-22 11:06:08 -04002284 /* If link state is not up, stop the roundrobin failover process */
James Smart0c9ab6f2010-02-26 14:15:57 -05002285 if (phba->link_state < LPFC_LINK_UP) {
2286 spin_lock_irq(&phba->hbalock);
2287 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
James Smarta93ff372010-10-22 11:06:08 -04002288 phba->hba_flag &= ~FCF_RR_INPROG;
James Smart0c9ab6f2010-02-26 14:15:57 -05002289 spin_unlock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04002290 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -05002291 }
2292
2293 /* Parse the FCF record from the non-embedded mailbox command */
2294 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
2295 &next_fcf_index);
2296 if (!new_fcf_record) {
2297 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2298 "2766 Mailbox command READ_FCF_RECORD "
2299 "failed to retrieve a FCF record.\n");
James Smarta93ff372010-10-22 11:06:08 -04002300 goto error_out;
James Smart0c9ab6f2010-02-26 14:15:57 -05002301 }
2302
2303 /* Get the needed parameters from FCF record */
James Smarta93ff372010-10-22 11:06:08 -04002304 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
2305 &addr_mode, &vlan_id);
James Smart0c9ab6f2010-02-26 14:15:57 -05002306
2307 /* Log the FCF record information if turned on */
2308 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
2309 next_fcf_index);
2310
James Smarta93ff372010-10-22 11:06:08 -04002311 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
2312 if (!rc) {
2313 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2314 "2848 Remove ineligible FCF (x%x) from "
2315 "from roundrobin bmask\n", fcf_index);
2316 /* Clear roundrobin bmask bit for ineligible FCF */
2317 lpfc_sli4_fcf_rr_index_clear(phba, fcf_index);
2318 /* Perform next round of roundrobin FCF failover */
2319 fcf_index = lpfc_sli4_fcf_rr_next_index_get(phba);
2320 rc = lpfc_sli4_fcf_rr_next_proc(phba->pport, fcf_index);
2321 if (rc)
2322 goto out;
2323 goto error_out;
2324 }
2325
2326 if (fcf_index == phba->fcf.current_rec.fcf_indx) {
2327 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2328 "2760 Perform FLOGI roundrobin FCF failover: "
2329 "FCF (x%x) back to FCF (x%x)\n",
2330 phba->fcf.current_rec.fcf_indx, fcf_index);
2331 /* Wait 500 ms before retrying FLOGI to current FCF */
2332 msleep(500);
James Smart76a95d72010-11-20 23:11:48 -05002333 lpfc_issue_init_vfi(phba->pport);
James Smarta93ff372010-10-22 11:06:08 -04002334 goto out;
2335 }
2336
James Smart0c9ab6f2010-02-26 14:15:57 -05002337 /* Upload new FCF record to the failover FCF record */
James Smartdbb6b3a2010-06-08 18:31:37 -04002338 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04002339 "2834 Update current FCF (x%x) with new FCF (x%x)\n",
2340 phba->fcf.failover_rec.fcf_indx, fcf_index);
James Smart0c9ab6f2010-02-26 14:15:57 -05002341 spin_lock_irq(&phba->hbalock);
2342 __lpfc_update_fcf_record(phba, &phba->fcf.failover_rec,
2343 new_fcf_record, addr_mode, vlan_id,
2344 (boot_flag ? BOOT_ENABLE : 0));
2345 spin_unlock_irq(&phba->hbalock);
2346
2347 current_fcf_index = phba->fcf.current_rec.fcf_indx;
2348
2349 /* Unregister the current in-use FCF record */
2350 lpfc_unregister_fcf(phba);
2351
2352 /* Replace in-use record with the new record */
2353 memcpy(&phba->fcf.current_rec, &phba->fcf.failover_rec,
2354 sizeof(struct lpfc_fcf_rec));
2355
2356 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
James Smarta93ff372010-10-22 11:06:08 -04002357 "2783 Perform FLOGI roundrobin FCF failover: FCF "
2358 "(x%x) to FCF (x%x)\n", current_fcf_index, fcf_index);
James Smart0c9ab6f2010-02-26 14:15:57 -05002359
James Smarta93ff372010-10-22 11:06:08 -04002360error_out:
2361 lpfc_register_fcf(phba);
James Smart0c9ab6f2010-02-26 14:15:57 -05002362out:
2363 lpfc_sli4_mbox_cmd_free(phba, mboxq);
James Smart0c9ab6f2010-02-26 14:15:57 -05002364}
2365
2366/**
2367 * lpfc_mbx_cmpl_read_fcf_rec - read fcf completion handler.
2368 * @phba: pointer to lpfc hba data structure.
2369 * @mboxq: pointer to mailbox object.
2370 *
2371 * This is the callback function of read FCF record mailbox command for
James Smarta93ff372010-10-22 11:06:08 -04002372 * updating the eligible FCF bmask for FLOGI failure roundrobin FCF
James Smart0c9ab6f2010-02-26 14:15:57 -05002373 * failover when a new FCF event happened. If the FCF read back is
2374 * valid/available and it passes the connection list check, it updates
James Smarta93ff372010-10-22 11:06:08 -04002375 * the bmask for the eligible FCF record for roundrobin failover.
James Smart0c9ab6f2010-02-26 14:15:57 -05002376 */
2377void
2378lpfc_mbx_cmpl_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2379{
2380 struct fcf_record *new_fcf_record;
2381 uint32_t boot_flag, addr_mode;
2382 uint16_t fcf_index, next_fcf_index;
2383 uint16_t vlan_id;
2384 int rc;
2385
2386 /* If link state is not up, no need to proceed */
2387 if (phba->link_state < LPFC_LINK_UP)
2388 goto out;
2389
2390 /* If FCF discovery period is over, no need to proceed */
James Smart3804dc82010-07-14 15:31:37 -04002391 if (!(phba->fcf.fcf_flag & FCF_DISCOVERY))
James Smart0c9ab6f2010-02-26 14:15:57 -05002392 goto out;
2393
2394 /* Parse the FCF record from the non-embedded mailbox command */
2395 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
2396 &next_fcf_index);
2397 if (!new_fcf_record) {
2398 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2399 "2767 Mailbox command READ_FCF_RECORD "
2400 "failed to retrieve a FCF record.\n");
2401 goto out;
2402 }
2403
2404 /* Check the connection list for eligibility */
2405 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
2406 &addr_mode, &vlan_id);
2407
2408 /* Log the FCF record information if turned on */
2409 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
2410 next_fcf_index);
2411
2412 if (!rc)
2413 goto out;
2414
2415 /* Update the eligible FCF record index bmask */
2416 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
2417 rc = lpfc_sli4_fcf_rr_index_set(phba, fcf_index);
2418
2419out:
2420 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2421}
2422
2423/**
James Smart76a95d72010-11-20 23:11:48 -05002424 * lpfc_init_vfi_cmpl - Completion handler for init_vfi mbox command.
2425 * @phba: pointer to lpfc hba data structure.
2426 * @mboxq: pointer to mailbox data structure.
2427 *
2428 * This function handles completion of init vfi mailbox command.
2429 */
2430void
2431lpfc_init_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2432{
2433 struct lpfc_vport *vport = mboxq->vport;
2434
2435 if (mboxq->u.mb.mbxStatus && (mboxq->u.mb.mbxStatus != 0x4002)) {
2436 lpfc_printf_vlog(vport, KERN_ERR,
2437 LOG_MBOX,
2438 "2891 Init VFI mailbox failed 0x%x\n",
2439 mboxq->u.mb.mbxStatus);
2440 mempool_free(mboxq, phba->mbox_mem_pool);
2441 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
2442 return;
2443 }
2444 lpfc_initial_flogi(vport);
2445 mempool_free(mboxq, phba->mbox_mem_pool);
2446 return;
2447}
2448
2449/**
2450 * lpfc_issue_init_vfi - Issue init_vfi mailbox command.
2451 * @vport: pointer to lpfc_vport data structure.
2452 *
2453 * This function issue a init_vfi mailbox command to initialize the VFI and
2454 * VPI for the physical port.
2455 */
2456void
2457lpfc_issue_init_vfi(struct lpfc_vport *vport)
2458{
2459 LPFC_MBOXQ_t *mboxq;
2460 int rc;
2461 struct lpfc_hba *phba = vport->phba;
2462
2463 mboxq = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2464 if (!mboxq) {
2465 lpfc_printf_vlog(vport, KERN_ERR,
2466 LOG_MBOX, "2892 Failed to allocate "
2467 "init_vfi mailbox\n");
2468 return;
2469 }
2470 lpfc_init_vfi(mboxq, vport);
2471 mboxq->mbox_cmpl = lpfc_init_vfi_cmpl;
2472 rc = lpfc_sli_issue_mbox(phba, mboxq, MBX_NOWAIT);
2473 if (rc == MBX_NOT_FINISHED) {
2474 lpfc_printf_vlog(vport, KERN_ERR,
2475 LOG_MBOX, "2893 Failed to issue init_vfi mailbox\n");
2476 mempool_free(mboxq, vport->phba->mbox_mem_pool);
2477 }
2478}
2479
2480/**
James Smart1c6834a2009-07-19 10:01:26 -04002481 * lpfc_init_vpi_cmpl - Completion handler for init_vpi mbox command.
2482 * @phba: pointer to lpfc hba data structure.
2483 * @mboxq: pointer to mailbox data structure.
2484 *
2485 * This function handles completion of init vpi mailbox command.
2486 */
James Smart695a8142010-01-26 23:08:03 -05002487void
James Smart1c6834a2009-07-19 10:01:26 -04002488lpfc_init_vpi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2489{
2490 struct lpfc_vport *vport = mboxq->vport;
James Smart695a8142010-01-26 23:08:03 -05002491 struct lpfc_nodelist *ndlp;
James Smart72100cc2010-02-12 14:43:01 -05002492 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2493
James Smart1c6834a2009-07-19 10:01:26 -04002494 if (mboxq->u.mb.mbxStatus) {
2495 lpfc_printf_vlog(vport, KERN_ERR,
2496 LOG_MBOX,
2497 "2609 Init VPI mailbox failed 0x%x\n",
2498 mboxq->u.mb.mbxStatus);
2499 mempool_free(mboxq, phba->mbox_mem_pool);
2500 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
2501 return;
2502 }
James Smart72100cc2010-02-12 14:43:01 -05002503 spin_lock_irq(shost->host_lock);
James Smart1c6834a2009-07-19 10:01:26 -04002504 vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI;
James Smart72100cc2010-02-12 14:43:01 -05002505 spin_unlock_irq(shost->host_lock);
James Smart1c6834a2009-07-19 10:01:26 -04002506
James Smart695a8142010-01-26 23:08:03 -05002507 /* If this port is physical port or FDISC is done, do reg_vpi */
2508 if ((phba->pport == vport) || (vport->port_state == LPFC_FDISC)) {
2509 ndlp = lpfc_findnode_did(vport, Fabric_DID);
2510 if (!ndlp)
2511 lpfc_printf_vlog(vport, KERN_ERR,
2512 LOG_DISCOVERY,
2513 "2731 Cannot find fabric "
2514 "controller node\n");
2515 else
2516 lpfc_register_new_vport(phba, vport, ndlp);
2517 mempool_free(mboxq, phba->mbox_mem_pool);
2518 return;
2519 }
2520
James Smart1c6834a2009-07-19 10:01:26 -04002521 if (phba->link_flag & LS_NPIV_FAB_SUPPORTED)
2522 lpfc_initial_fdisc(vport);
2523 else {
2524 lpfc_vport_set_state(vport, FC_VPORT_NO_FABRIC_SUPP);
James Smart6a9c52c2009-10-02 15:16:51 -04002525 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2526 "2606 No NPIV Fabric support\n");
James Smart1c6834a2009-07-19 10:01:26 -04002527 }
James Smart695a8142010-01-26 23:08:03 -05002528 mempool_free(mboxq, phba->mbox_mem_pool);
James Smart1c6834a2009-07-19 10:01:26 -04002529 return;
2530}
2531
2532/**
James Smartecfd03c2010-02-12 14:41:27 -05002533 * lpfc_issue_init_vpi - Issue init_vpi mailbox command.
2534 * @vport: pointer to lpfc_vport data structure.
2535 *
2536 * This function issue a init_vpi mailbox command to initialize
2537 * VPI for the vport.
2538 */
2539void
2540lpfc_issue_init_vpi(struct lpfc_vport *vport)
2541{
2542 LPFC_MBOXQ_t *mboxq;
2543 int rc;
2544
2545 mboxq = mempool_alloc(vport->phba->mbox_mem_pool, GFP_KERNEL);
2546 if (!mboxq) {
2547 lpfc_printf_vlog(vport, KERN_ERR,
2548 LOG_MBOX, "2607 Failed to allocate "
2549 "init_vpi mailbox\n");
2550 return;
2551 }
2552 lpfc_init_vpi(vport->phba, mboxq, vport->vpi);
2553 mboxq->vport = vport;
2554 mboxq->mbox_cmpl = lpfc_init_vpi_cmpl;
2555 rc = lpfc_sli_issue_mbox(vport->phba, mboxq, MBX_NOWAIT);
2556 if (rc == MBX_NOT_FINISHED) {
2557 lpfc_printf_vlog(vport, KERN_ERR,
2558 LOG_MBOX, "2608 Failed to issue init_vpi mailbox\n");
2559 mempool_free(mboxq, vport->phba->mbox_mem_pool);
2560 }
2561}
2562
2563/**
James Smart6fb120a2009-05-22 14:52:59 -04002564 * lpfc_start_fdiscs - send fdiscs for each vports on this port.
2565 * @phba: pointer to lpfc hba data structure.
2566 *
2567 * This function loops through the list of vports on the @phba and issues an
2568 * FDISC if possible.
2569 */
2570void
2571lpfc_start_fdiscs(struct lpfc_hba *phba)
2572{
2573 struct lpfc_vport **vports;
2574 int i;
2575
2576 vports = lpfc_create_vport_work_array(phba);
2577 if (vports != NULL) {
2578 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2579 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
2580 continue;
2581 /* There are no vpi for this vport */
2582 if (vports[i]->vpi > phba->max_vpi) {
2583 lpfc_vport_set_state(vports[i],
2584 FC_VPORT_FAILED);
2585 continue;
2586 }
James Smart76a95d72010-11-20 23:11:48 -05002587 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart6fb120a2009-05-22 14:52:59 -04002588 lpfc_vport_set_state(vports[i],
2589 FC_VPORT_LINKDOWN);
2590 continue;
2591 }
James Smart1c6834a2009-07-19 10:01:26 -04002592 if (vports[i]->fc_flag & FC_VPORT_NEEDS_INIT_VPI) {
James Smartecfd03c2010-02-12 14:41:27 -05002593 lpfc_issue_init_vpi(vports[i]);
James Smart1c6834a2009-07-19 10:01:26 -04002594 continue;
2595 }
James Smart6fb120a2009-05-22 14:52:59 -04002596 if (phba->link_flag & LS_NPIV_FAB_SUPPORTED)
2597 lpfc_initial_fdisc(vports[i]);
2598 else {
2599 lpfc_vport_set_state(vports[i],
2600 FC_VPORT_NO_FABRIC_SUPP);
2601 lpfc_printf_vlog(vports[i], KERN_ERR,
2602 LOG_ELS,
2603 "0259 No NPIV "
2604 "Fabric support\n");
2605 }
2606 }
2607 }
2608 lpfc_destroy_vport_work_array(phba, vports);
2609}
2610
2611void
2612lpfc_mbx_cmpl_reg_vfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2613{
2614 struct lpfc_dmabuf *dmabuf = mboxq->context1;
2615 struct lpfc_vport *vport = mboxq->vport;
James Smart72100cc2010-02-12 14:43:01 -05002616 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart6fb120a2009-05-22 14:52:59 -04002617
2618 if (mboxq->u.mb.mbxStatus) {
2619 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
2620 "2018 REG_VFI mbxStatus error x%x "
2621 "HBA state x%x\n",
2622 mboxq->u.mb.mbxStatus, vport->port_state);
James Smart76a95d72010-11-20 23:11:48 -05002623 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart6fb120a2009-05-22 14:52:59 -04002624 /* FLOGI failed, use loop map to make discovery list */
2625 lpfc_disc_list_loopmap(vport);
2626 /* Start discovery */
2627 lpfc_disc_start(vport);
2628 goto fail_free_mem;
2629 }
2630 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
2631 goto fail_free_mem;
2632 }
James Smartc8685952009-11-18 15:39:16 -05002633 /* The VPI is implicitly registered when the VFI is registered */
James Smart72100cc2010-02-12 14:43:01 -05002634 spin_lock_irq(shost->host_lock);
James Smartc8685952009-11-18 15:39:16 -05002635 vport->vpi_state |= LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05002636 vport->fc_flag |= FC_VFI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05002637 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
James Smart72100cc2010-02-12 14:43:01 -05002638 spin_unlock_irq(shost->host_lock);
James Smart6fb120a2009-05-22 14:52:59 -04002639
2640 if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
James Smart76a95d72010-11-20 23:11:48 -05002641 /* For private loop just start discovery and we are done. */
2642 if ((phba->fc_topology == LPFC_TOPOLOGY_LOOP) &&
2643 (phba->alpa_map[0] == 0) &&
2644 !(vport->fc_flag & FC_PUBLIC_LOOP)) {
2645 /* Use loop map to make discovery list */
2646 lpfc_disc_list_loopmap(vport);
2647 /* Start discovery */
2648 lpfc_disc_start(vport);
2649 } else {
2650 lpfc_start_fdiscs(phba);
2651 lpfc_do_scr_ns_plogi(phba, vport);
2652 }
James Smart6fb120a2009-05-22 14:52:59 -04002653 }
2654
2655fail_free_mem:
2656 mempool_free(mboxq, phba->mbox_mem_pool);
2657 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
2658 kfree(dmabuf);
2659 return;
2660}
2661
2662static void
James Smart2e0fef82007-06-17 19:56:36 -05002663lpfc_mbx_cmpl_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05002664{
James Smart6fb120a2009-05-22 14:52:59 -04002665 MAILBOX_t *mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -05002666 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) pmb->context1;
James Smart2e0fef82007-06-17 19:56:36 -05002667 struct lpfc_vport *vport = pmb->vport;
dea31012005-04-17 16:05:31 -05002668
2669
2670 /* Check for error */
2671 if (mb->mbxStatus) {
2672 /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */
James Smarte8b62012007-08-02 11:10:09 -04002673 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
2674 "0319 READ_SPARAM mbxStatus error x%x "
2675 "hba state x%x>\n",
2676 mb->mbxStatus, vport->port_state);
dea31012005-04-17 16:05:31 -05002677 lpfc_linkdown(phba);
dea31012005-04-17 16:05:31 -05002678 goto out;
2679 }
2680
James Smart2e0fef82007-06-17 19:56:36 -05002681 memcpy((uint8_t *) &vport->fc_sparam, (uint8_t *) mp->virt,
dea31012005-04-17 16:05:31 -05002682 sizeof (struct serv_parm));
James Smarta12e07b2006-12-02 13:35:30 -05002683 if (phba->cfg_soft_wwnn)
James Smart2e0fef82007-06-17 19:56:36 -05002684 u64_to_wwn(phba->cfg_soft_wwnn,
2685 vport->fc_sparam.nodeName.u.wwn);
James Smartc3f28af2006-08-18 17:47:18 -04002686 if (phba->cfg_soft_wwpn)
James Smart2e0fef82007-06-17 19:56:36 -05002687 u64_to_wwn(phba->cfg_soft_wwpn,
2688 vport->fc_sparam.portName.u.wwn);
James Smart92d7f7b2007-06-17 19:56:38 -05002689 memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
2690 sizeof(vport->fc_nodename));
2691 memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
2692 sizeof(vport->fc_portname));
2693 if (vport->port_type == LPFC_PHYSICAL_PORT) {
2694 memcpy(&phba->wwnn, &vport->fc_nodename, sizeof(phba->wwnn));
2695 memcpy(&phba->wwpn, &vport->fc_portname, sizeof(phba->wwnn));
2696 }
2697
dea31012005-04-17 16:05:31 -05002698 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2699 kfree(mp);
James Smart2e0fef82007-06-17 19:56:36 -05002700 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05002701 return;
2702
2703out:
2704 pmb->context1 = NULL;
2705 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2706 kfree(mp);
James Smart92d7f7b2007-06-17 19:56:38 -05002707 lpfc_issue_clear_la(phba, vport);
2708 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05002709 return;
2710}
2711
2712static void
James Smart76a95d72010-11-20 23:11:48 -05002713lpfc_mbx_process_link_up(struct lpfc_hba *phba, struct lpfc_mbx_read_top *la)
dea31012005-04-17 16:05:31 -05002714{
James Smart92d7f7b2007-06-17 19:56:38 -05002715 struct lpfc_vport *vport = phba->pport;
James Smart6fb120a2009-05-22 14:52:59 -04002716 LPFC_MBOXQ_t *sparam_mbox, *cfglink_mbox = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05002717 int i;
James Smart14691152006-12-02 13:34:28 -05002718 struct lpfc_dmabuf *mp;
2719 int rc;
James Smart6fb120a2009-05-22 14:52:59 -04002720 struct fcf_record *fcf_record;
James Smart14691152006-12-02 13:34:28 -05002721
James Smart92d7f7b2007-06-17 19:56:38 -05002722 spin_lock_irq(&phba->hbalock);
James Smart76a95d72010-11-20 23:11:48 -05002723 switch (bf_get(lpfc_mbx_read_top_link_spd, la)) {
2724 case LPFC_LINK_SPEED_1GHZ:
2725 case LPFC_LINK_SPEED_2GHZ:
2726 case LPFC_LINK_SPEED_4GHZ:
2727 case LPFC_LINK_SPEED_8GHZ:
2728 case LPFC_LINK_SPEED_10GHZ:
2729 case LPFC_LINK_SPEED_16GHZ:
2730 phba->fc_linkspeed = bf_get(lpfc_mbx_read_top_link_spd, la);
James Smartf4b4c682009-05-22 14:53:12 -04002731 break;
James Smart92d7f7b2007-06-17 19:56:38 -05002732 default:
James Smart76a95d72010-11-20 23:11:48 -05002733 phba->fc_linkspeed = LPFC_LINK_SPEED_UNKNOWN;
James Smart92d7f7b2007-06-17 19:56:38 -05002734 break;
dea31012005-04-17 16:05:31 -05002735 }
2736
James Smart76a95d72010-11-20 23:11:48 -05002737 phba->fc_topology = bf_get(lpfc_mbx_read_top_topology, la);
James Smart92d7f7b2007-06-17 19:56:38 -05002738 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
dea31012005-04-17 16:05:31 -05002739
James Smart76a95d72010-11-20 23:11:48 -05002740 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart92d7f7b2007-06-17 19:56:38 -05002741 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
dea31012005-04-17 16:05:31 -05002742
James Smart6a9c52c2009-10-02 15:16:51 -04002743 /* if npiv is enabled and this adapter supports npiv log
2744 * a message that npiv is not supported in this topology
2745 */
2746 if (phba->cfg_enable_npiv && phba->max_vpi)
James Smart495a7142008-06-14 22:52:59 -04002747 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
2748 "1309 Link Up Event npiv not supported in loop "
2749 "topology\n");
James Smart92d7f7b2007-06-17 19:56:38 -05002750 /* Get Loop Map information */
James Smart76a95d72010-11-20 23:11:48 -05002751 if (bf_get(lpfc_mbx_read_top_il, la))
James Smart2e0fef82007-06-17 19:56:36 -05002752 vport->fc_flag |= FC_LBIT;
dea31012005-04-17 16:05:31 -05002753
James Smart76a95d72010-11-20 23:11:48 -05002754 vport->fc_myDID = bf_get(lpfc_mbx_read_top_alpa_granted, la);
2755 i = la->lilpBde64.tus.f.bdeSize;
dea31012005-04-17 16:05:31 -05002756
2757 if (i == 0) {
2758 phba->alpa_map[0] = 0;
2759 } else {
James Smarte8b62012007-08-02 11:10:09 -04002760 if (vport->cfg_log_verbose & LOG_LINK_EVENT) {
dea31012005-04-17 16:05:31 -05002761 int numalpa, j, k;
2762 union {
2763 uint8_t pamap[16];
2764 struct {
2765 uint32_t wd1;
2766 uint32_t wd2;
2767 uint32_t wd3;
2768 uint32_t wd4;
2769 } pa;
2770 } un;
2771 numalpa = phba->alpa_map[0];
2772 j = 0;
2773 while (j < numalpa) {
2774 memset(un.pamap, 0, 16);
2775 for (k = 1; j < numalpa; k++) {
2776 un.pamap[k - 1] =
2777 phba->alpa_map[j + 1];
2778 j++;
2779 if (k == 16)
2780 break;
2781 }
2782 /* Link Up Event ALPA map */
2783 lpfc_printf_log(phba,
James Smart92d7f7b2007-06-17 19:56:38 -05002784 KERN_WARNING,
2785 LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04002786 "1304 Link Up Event "
James Smart92d7f7b2007-06-17 19:56:38 -05002787 "ALPA map Data: x%x "
2788 "x%x x%x x%x\n",
James Smart92d7f7b2007-06-17 19:56:38 -05002789 un.pa.wd1, un.pa.wd2,
2790 un.pa.wd3, un.pa.wd4);
dea31012005-04-17 16:05:31 -05002791 }
2792 }
2793 }
2794 } else {
James Smart92d7f7b2007-06-17 19:56:38 -05002795 if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)) {
James Smart78b2d852007-08-02 11:10:21 -04002796 if (phba->max_vpi && phba->cfg_enable_npiv &&
James Smart92d7f7b2007-06-17 19:56:38 -05002797 (phba->sli_rev == 3))
2798 phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
2799 }
James Smart2e0fef82007-06-17 19:56:36 -05002800 vport->fc_myDID = phba->fc_pref_DID;
2801 vport->fc_flag |= FC_LBIT;
dea31012005-04-17 16:05:31 -05002802 }
James Smart92d7f7b2007-06-17 19:56:38 -05002803 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002804
2805 lpfc_linkup(phba);
James Smart9f1177a2010-02-26 14:12:57 -05002806 sparam_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2807 if (!sparam_mbox)
2808 goto out;
2809
2810 rc = lpfc_read_sparam(phba, sparam_mbox, 0);
2811 if (rc) {
2812 mempool_free(sparam_mbox, phba->mbox_mem_pool);
2813 goto out;
2814 }
2815 sparam_mbox->vport = vport;
2816 sparam_mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam;
2817 rc = lpfc_sli_issue_mbox(phba, sparam_mbox, MBX_NOWAIT);
2818 if (rc == MBX_NOT_FINISHED) {
2819 mp = (struct lpfc_dmabuf *) sparam_mbox->context1;
2820 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2821 kfree(mp);
2822 mempool_free(sparam_mbox, phba->mbox_mem_pool);
2823 goto out;
dea31012005-04-17 16:05:31 -05002824 }
2825
James Smart76a95d72010-11-20 23:11:48 -05002826 if (!(phba->hba_flag & HBA_FCOE_MODE)) {
James Smart6fb120a2009-05-22 14:52:59 -04002827 cfglink_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2828 if (!cfglink_mbox)
2829 goto out;
James Smart2e0fef82007-06-17 19:56:36 -05002830 vport->port_state = LPFC_LOCAL_CFG_LINK;
dea31012005-04-17 16:05:31 -05002831 lpfc_config_link(phba, cfglink_mbox);
James Smart2e0fef82007-06-17 19:56:36 -05002832 cfglink_mbox->vport = vport;
Jamie Wellnitz25594c62006-02-28 19:25:34 -05002833 cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
James Smart0b727fe2007-10-27 13:37:25 -04002834 rc = lpfc_sli_issue_mbox(phba, cfglink_mbox, MBX_NOWAIT);
James Smart6fb120a2009-05-22 14:52:59 -04002835 if (rc == MBX_NOT_FINISHED) {
2836 mempool_free(cfglink_mbox, phba->mbox_mem_pool);
2837 goto out;
2838 }
2839 } else {
James Smart32b97932009-07-19 10:01:21 -04002840 vport->port_state = LPFC_VPORT_UNKNOWN;
James Smart6fb120a2009-05-22 14:52:59 -04002841 /*
2842 * Add the driver's default FCF record at FCF index 0 now. This
2843 * is phase 1 implementation that support FCF index 0 and driver
2844 * defaults.
2845 */
James Smart45ed1192009-10-02 15:17:02 -04002846 if (!(phba->hba_flag & HBA_FIP_SUPPORT)) {
James Smart6fb120a2009-05-22 14:52:59 -04002847 fcf_record = kzalloc(sizeof(struct fcf_record),
2848 GFP_KERNEL);
2849 if (unlikely(!fcf_record)) {
2850 lpfc_printf_log(phba, KERN_ERR,
2851 LOG_MBOX | LOG_SLI,
2852 "2554 Could not allocate memmory for "
2853 "fcf record\n");
2854 rc = -ENODEV;
2855 goto out;
2856 }
2857
2858 lpfc_sli4_build_dflt_fcf_record(phba, fcf_record,
2859 LPFC_FCOE_FCF_DEF_INDEX);
2860 rc = lpfc_sli4_add_fcf_record(phba, fcf_record);
2861 if (unlikely(rc)) {
2862 lpfc_printf_log(phba, KERN_ERR,
2863 LOG_MBOX | LOG_SLI,
2864 "2013 Could not manually add FCF "
2865 "record 0, status %d\n", rc);
2866 rc = -ENODEV;
2867 kfree(fcf_record);
2868 goto out;
2869 }
2870 kfree(fcf_record);
2871 }
2872 /*
2873 * The driver is expected to do FIP/FCF. Call the port
2874 * and get the FCF Table.
2875 */
James Smart32b97932009-07-19 10:01:21 -04002876 spin_lock_irq(&phba->hbalock);
James Smarta93ff372010-10-22 11:06:08 -04002877 if (phba->hba_flag & FCF_TS_INPROG) {
James Smart32b97932009-07-19 10:01:21 -04002878 spin_unlock_irq(&phba->hbalock);
2879 return;
2880 }
James Smart0c9ab6f2010-02-26 14:15:57 -05002881 /* This is the initial FCF discovery scan */
2882 phba->fcf.fcf_flag |= FCF_INIT_DISC;
James Smart32b97932009-07-19 10:01:21 -04002883 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05002884 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
2885 "2778 Start FCF table scan at linkup\n");
James Smart0c9ab6f2010-02-26 14:15:57 -05002886 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba,
2887 LPFC_FCOE_FCF_GET_FIRST);
2888 if (rc) {
2889 spin_lock_irq(&phba->hbalock);
2890 phba->fcf.fcf_flag &= ~FCF_INIT_DISC;
2891 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04002892 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -05002893 }
James Smart38b92ef2010-08-04 16:11:39 -04002894 /* Reset FCF roundrobin bmask for new discovery */
2895 memset(phba->fcf.fcf_rr_bmask, 0,
2896 sizeof(*phba->fcf.fcf_rr_bmask));
dea31012005-04-17 16:05:31 -05002897 }
James Smart6fb120a2009-05-22 14:52:59 -04002898
2899 return;
James Smart92d7f7b2007-06-17 19:56:38 -05002900out:
2901 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04002902 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
2903 "0263 Discovery Mailbox error: state: 0x%x : %p %p\n",
2904 vport->port_state, sparam_mbox, cfglink_mbox);
James Smart92d7f7b2007-06-17 19:56:38 -05002905 lpfc_issue_clear_la(phba, vport);
2906 return;
dea31012005-04-17 16:05:31 -05002907}
2908
2909static void
James Smart84774a42008-08-24 21:50:06 -04002910lpfc_enable_la(struct lpfc_hba *phba)
James Smart2e0fef82007-06-17 19:56:36 -05002911{
dea31012005-04-17 16:05:31 -05002912 uint32_t control;
2913 struct lpfc_sli *psli = &phba->sli;
James Smart2e0fef82007-06-17 19:56:36 -05002914 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002915 psli->sli_flag |= LPFC_PROCESS_LA;
James Smart3772a992009-05-22 14:50:54 -04002916 if (phba->sli_rev <= LPFC_SLI_REV3) {
2917 control = readl(phba->HCregaddr);
2918 control |= HC_LAINT_ENA;
2919 writel(control, phba->HCregaddr);
2920 readl(phba->HCregaddr); /* flush */
2921 }
James Smart2e0fef82007-06-17 19:56:36 -05002922 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002923}
2924
James Smart84774a42008-08-24 21:50:06 -04002925static void
2926lpfc_mbx_issue_link_down(struct lpfc_hba *phba)
2927{
2928 lpfc_linkdown(phba);
2929 lpfc_enable_la(phba);
James Smart6fb120a2009-05-22 14:52:59 -04002930 lpfc_unregister_unused_fcf(phba);
James Smart84774a42008-08-24 21:50:06 -04002931 /* turn on Link Attention interrupts - no CLEAR_LA needed */
2932}
2933
2934
dea31012005-04-17 16:05:31 -05002935/*
James Smart76a95d72010-11-20 23:11:48 -05002936 * This routine handles processing a READ_TOPOLOGY mailbox
dea31012005-04-17 16:05:31 -05002937 * command upon completion. It is setup in the LPFC_MBOXQ
2938 * as the completion routine when the command is
2939 * handed off to the SLI layer.
2940 */
2941void
James Smart76a95d72010-11-20 23:11:48 -05002942lpfc_mbx_cmpl_read_topology(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05002943{
James Smart2e0fef82007-06-17 19:56:36 -05002944 struct lpfc_vport *vport = pmb->vport;
2945 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart76a95d72010-11-20 23:11:48 -05002946 struct lpfc_mbx_read_top *la;
James Smart04c68492009-05-22 14:52:52 -04002947 MAILBOX_t *mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -05002948 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
2949
James Smart0d2b6b82008-06-14 22:52:47 -04002950 /* Unblock ELS traffic */
2951 phba->sli.ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
dea31012005-04-17 16:05:31 -05002952 /* Check for error */
2953 if (mb->mbxStatus) {
James Smarted957682007-06-17 19:56:37 -05002954 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04002955 "1307 READ_LA mbox error x%x state x%x\n",
2956 mb->mbxStatus, vport->port_state);
dea31012005-04-17 16:05:31 -05002957 lpfc_mbx_issue_link_down(phba);
James Smart2e0fef82007-06-17 19:56:36 -05002958 phba->link_state = LPFC_HBA_ERROR;
James Smart76a95d72010-11-20 23:11:48 -05002959 goto lpfc_mbx_cmpl_read_topology_free_mbuf;
dea31012005-04-17 16:05:31 -05002960 }
2961
James Smart76a95d72010-11-20 23:11:48 -05002962 la = (struct lpfc_mbx_read_top *) &pmb->u.mb.un.varReadTop;
dea31012005-04-17 16:05:31 -05002963
2964 memcpy(&phba->alpa_map[0], mp->virt, 128);
2965
James Smart2e0fef82007-06-17 19:56:36 -05002966 spin_lock_irq(shost->host_lock);
James Smart76a95d72010-11-20 23:11:48 -05002967 if (bf_get(lpfc_mbx_read_top_pb, la))
James Smart2e0fef82007-06-17 19:56:36 -05002968 vport->fc_flag |= FC_BYPASSED_MODE;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002969 else
James Smart2e0fef82007-06-17 19:56:36 -05002970 vport->fc_flag &= ~FC_BYPASSED_MODE;
2971 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002972
James Smart0c287582009-06-10 17:22:56 -04002973 if ((phba->fc_eventTag < la->eventTag) ||
James Smart92d7f7b2007-06-17 19:56:38 -05002974 (phba->fc_eventTag == la->eventTag)) {
dea31012005-04-17 16:05:31 -05002975 phba->fc_stat.LinkMultiEvent++;
James Smart76a95d72010-11-20 23:11:48 -05002976 if (bf_get(lpfc_mbx_read_top_att_type, la) == LPFC_ATT_LINK_UP)
dea31012005-04-17 16:05:31 -05002977 if (phba->fc_eventTag != 0)
2978 lpfc_linkdown(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05002979 }
dea31012005-04-17 16:05:31 -05002980
2981 phba->fc_eventTag = la->eventTag;
James Smart72100cc2010-02-12 14:43:01 -05002982 spin_lock_irq(&phba->hbalock);
James Smart76a95d72010-11-20 23:11:48 -05002983 if (bf_get(lpfc_mbx_read_top_mm, la))
James Smart84774a42008-08-24 21:50:06 -04002984 phba->sli.sli_flag |= LPFC_MENLO_MAINT;
2985 else
2986 phba->sli.sli_flag &= ~LPFC_MENLO_MAINT;
James Smart72100cc2010-02-12 14:43:01 -05002987 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002988
James Smart4d9ab992009-10-02 15:16:39 -04002989 phba->link_events++;
James Smart76a95d72010-11-20 23:11:48 -05002990 if ((bf_get(lpfc_mbx_read_top_att_type, la) == LPFC_ATT_LINK_UP) &&
2991 (!bf_get(lpfc_mbx_read_top_mm, la))) {
dea31012005-04-17 16:05:31 -05002992 phba->fc_stat.LinkUp++;
James Smart2e0fef82007-06-17 19:56:36 -05002993 if (phba->link_flag & LS_LOOPBACK_MODE) {
James Smart3163f722008-02-08 18:50:25 -05002994 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04002995 "1306 Link Up Event in loop back mode "
2996 "x%x received Data: x%x x%x x%x x%x\n",
2997 la->eventTag, phba->fc_eventTag,
James Smart76a95d72010-11-20 23:11:48 -05002998 bf_get(lpfc_mbx_read_top_alpa_granted,
2999 la),
3000 bf_get(lpfc_mbx_read_top_link_spd, la),
James Smarte8b62012007-08-02 11:10:09 -04003001 phba->alpa_map[0]);
James Smart5b8bd0c2007-04-25 09:52:49 -04003002 } else {
3003 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04003004 "1303 Link Up Event x%x received "
James Smart84774a42008-08-24 21:50:06 -04003005 "Data: x%x x%x x%x x%x x%x x%x %d\n",
James Smarte8b62012007-08-02 11:10:09 -04003006 la->eventTag, phba->fc_eventTag,
James Smart76a95d72010-11-20 23:11:48 -05003007 bf_get(lpfc_mbx_read_top_alpa_granted,
3008 la),
3009 bf_get(lpfc_mbx_read_top_link_spd, la),
James Smart84774a42008-08-24 21:50:06 -04003010 phba->alpa_map[0],
James Smart76a95d72010-11-20 23:11:48 -05003011 bf_get(lpfc_mbx_read_top_mm, la),
3012 bf_get(lpfc_mbx_read_top_fa, la),
James Smart84774a42008-08-24 21:50:06 -04003013 phba->wait_4_mlo_maint_flg);
James Smart5b8bd0c2007-04-25 09:52:49 -04003014 }
James Smart92d7f7b2007-06-17 19:56:38 -05003015 lpfc_mbx_process_link_up(phba, la);
James Smart76a95d72010-11-20 23:11:48 -05003016 } else if (bf_get(lpfc_mbx_read_top_att_type, la) ==
3017 LPFC_ATT_LINK_DOWN) {
dea31012005-04-17 16:05:31 -05003018 phba->fc_stat.LinkDown++;
James Smart3163f722008-02-08 18:50:25 -05003019 if (phba->link_flag & LS_LOOPBACK_MODE) {
3020 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3021 "1308 Link Down Event in loop back mode "
3022 "x%x received "
3023 "Data: x%x x%x x%x\n",
3024 la->eventTag, phba->fc_eventTag,
3025 phba->pport->port_state, vport->fc_flag);
3026 }
3027 else {
3028 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04003029 "1305 Link Down Event x%x received "
James Smart84774a42008-08-24 21:50:06 -04003030 "Data: x%x x%x x%x x%x x%x\n",
3031 la->eventTag, phba->fc_eventTag,
3032 phba->pport->port_state, vport->fc_flag,
James Smart76a95d72010-11-20 23:11:48 -05003033 bf_get(lpfc_mbx_read_top_mm, la),
3034 bf_get(lpfc_mbx_read_top_fa, la));
James Smart84774a42008-08-24 21:50:06 -04003035 }
3036 lpfc_mbx_issue_link_down(phba);
3037 }
James Smart76a95d72010-11-20 23:11:48 -05003038 if ((bf_get(lpfc_mbx_read_top_mm, la)) &&
3039 (bf_get(lpfc_mbx_read_top_att_type, la) == LPFC_ATT_LINK_UP)) {
James Smart84774a42008-08-24 21:50:06 -04003040 if (phba->link_state != LPFC_LINK_DOWN) {
3041 phba->fc_stat.LinkDown++;
3042 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3043 "1312 Link Down Event x%x received "
dea31012005-04-17 16:05:31 -05003044 "Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04003045 la->eventTag, phba->fc_eventTag,
James Smart2e0fef82007-06-17 19:56:36 -05003046 phba->pport->port_state, vport->fc_flag);
James Smart84774a42008-08-24 21:50:06 -04003047 lpfc_mbx_issue_link_down(phba);
3048 } else
3049 lpfc_enable_la(phba);
3050
3051 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
3052 "1310 Menlo Maint Mode Link up Event x%x rcvd "
3053 "Data: x%x x%x x%x\n",
3054 la->eventTag, phba->fc_eventTag,
3055 phba->pport->port_state, vport->fc_flag);
3056 /*
3057 * The cmnd that triggered this will be waiting for this
3058 * signal.
3059 */
3060 /* WAKEUP for MENLO_SET_MODE or MENLO_RESET command. */
3061 if (phba->wait_4_mlo_maint_flg) {
3062 phba->wait_4_mlo_maint_flg = 0;
3063 wake_up_interruptible(&phba->wait_4_mlo_m_q);
James Smart3163f722008-02-08 18:50:25 -05003064 }
James Smart84774a42008-08-24 21:50:06 -04003065 }
3066
James Smart76a95d72010-11-20 23:11:48 -05003067 if (bf_get(lpfc_mbx_read_top_fa, la)) {
3068 if (bf_get(lpfc_mbx_read_top_mm, la))
James Smart84774a42008-08-24 21:50:06 -04003069 lpfc_issue_clear_la(phba, vport);
3070 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
James Smart76a95d72010-11-20 23:11:48 -05003071 "1311 fa %d\n",
3072 bf_get(lpfc_mbx_read_top_fa, la));
dea31012005-04-17 16:05:31 -05003073 }
3074
James Smart76a95d72010-11-20 23:11:48 -05003075lpfc_mbx_cmpl_read_topology_free_mbuf:
dea31012005-04-17 16:05:31 -05003076 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3077 kfree(mp);
3078 mempool_free(pmb, phba->mbox_mem_pool);
3079 return;
3080}
3081
3082/*
3083 * This routine handles processing a REG_LOGIN mailbox
3084 * command upon completion. It is setup in the LPFC_MBOXQ
3085 * as the completion routine when the command is
3086 * handed off to the SLI layer.
3087 */
3088void
James Smart2e0fef82007-06-17 19:56:36 -05003089lpfc_mbx_cmpl_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05003090{
James Smart2e0fef82007-06-17 19:56:36 -05003091 struct lpfc_vport *vport = pmb->vport;
James Smart92d7f7b2007-06-17 19:56:38 -05003092 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
James Smart2e0fef82007-06-17 19:56:36 -05003093 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smartffc95492010-06-07 15:23:17 -04003094 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05003095
dea31012005-04-17 16:05:31 -05003096 pmb->context1 = NULL;
James Smartd439d282010-09-29 11:18:45 -04003097 pmb->context2 = NULL;
dea31012005-04-17 16:05:31 -05003098
James Smartffc95492010-06-07 15:23:17 -04003099 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
3100 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
3101
3102 if (ndlp->nlp_flag & NLP_IGNR_REG_CMPL ||
3103 ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE) {
3104 /* We rcvd a rscn after issuing this
3105 * mbox reg login, we may have cycled
3106 * back through the state and be
3107 * back at reg login state so this
3108 * mbox needs to be ignored becase
3109 * there is another reg login in
3110 * proccess.
3111 */
3112 spin_lock_irq(shost->host_lock);
3113 ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
3114 spin_unlock_irq(shost->host_lock);
3115 if (phba->sli_rev == LPFC_SLI_REV4)
3116 lpfc_sli4_free_rpi(phba,
3117 pmb->u.mb.un.varRegLogin.rpi);
3118
3119 } else
3120 /* Good status, call state machine */
3121 lpfc_disc_state_machine(vport, ndlp, pmb,
3122 NLP_EVT_CMPL_REG_LOGIN);
3123
dea31012005-04-17 16:05:31 -05003124 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3125 kfree(mp);
James Smart2e0fef82007-06-17 19:56:36 -05003126 mempool_free(pmb, phba->mbox_mem_pool);
James Smartfa4066b2008-01-11 01:53:27 -05003127 /* decrement the node reference count held for this callback
3128 * function.
3129 */
James Smart329f9bc2007-04-25 09:53:01 -04003130 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05003131
3132 return;
3133}
3134
James Smart92d7f7b2007-06-17 19:56:38 -05003135static void
3136lpfc_mbx_cmpl_unreg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3137{
James Smart04c68492009-05-22 14:52:52 -04003138 MAILBOX_t *mb = &pmb->u.mb;
James Smart92d7f7b2007-06-17 19:56:38 -05003139 struct lpfc_vport *vport = pmb->vport;
3140 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3141
3142 switch (mb->mbxStatus) {
3143 case 0x0011:
3144 case 0x0020:
James Smarte8b62012007-08-02 11:10:09 -04003145 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
3146 "0911 cmpl_unreg_vpi, mb status = 0x%x\n",
3147 mb->mbxStatus);
James Smart92d7f7b2007-06-17 19:56:38 -05003148 break;
James Smart78730cf2010-04-06 15:06:30 -04003149 /* If VPI is busy, reset the HBA */
3150 case 0x9700:
3151 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE,
3152 "2798 Unreg_vpi failed vpi 0x%x, mb status = 0x%x\n",
3153 vport->vpi, mb->mbxStatus);
3154 if (!(phba->pport->load_flag & FC_UNLOADING))
3155 lpfc_workq_post_event(phba, NULL, NULL,
3156 LPFC_EVT_RESET_HBA);
James Smart92d7f7b2007-06-17 19:56:38 -05003157 }
James Smart72100cc2010-02-12 14:43:01 -05003158 spin_lock_irq(shost->host_lock);
James Smartc8685952009-11-18 15:39:16 -05003159 vport->vpi_state &= ~LPFC_VPI_REGISTERED;
James Smart19878072009-12-21 17:02:00 -05003160 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart72100cc2010-02-12 14:43:01 -05003161 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05003162 vport->unreg_vpi_cmpl = VPORT_OK;
3163 mempool_free(pmb, phba->mbox_mem_pool);
3164 /*
3165 * This shost reference might have been taken at the beginning of
3166 * lpfc_vport_delete()
3167 */
James Smart1c6f4ef52009-11-18 15:40:49 -05003168 if ((vport->load_flag & FC_UNLOADING) && (vport != phba->pport))
James Smart92d7f7b2007-06-17 19:56:38 -05003169 scsi_host_put(shost);
3170}
3171
James Smartd7c255b2008-08-24 21:50:00 -04003172int
James Smart92d7f7b2007-06-17 19:56:38 -05003173lpfc_mbx_unreg_vpi(struct lpfc_vport *vport)
3174{
3175 struct lpfc_hba *phba = vport->phba;
3176 LPFC_MBOXQ_t *mbox;
3177 int rc;
3178
3179 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3180 if (!mbox)
James Smartd7c255b2008-08-24 21:50:00 -04003181 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -05003182
3183 lpfc_unreg_vpi(phba, vport->vpi, mbox);
3184 mbox->vport = vport;
3185 mbox->mbox_cmpl = lpfc_mbx_cmpl_unreg_vpi;
James Smart0b727fe2007-10-27 13:37:25 -04003186 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart92d7f7b2007-06-17 19:56:38 -05003187 if (rc == MBX_NOT_FINISHED) {
James Smarte8b62012007-08-02 11:10:09 -04003188 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT,
3189 "1800 Could not issue unreg_vpi\n");
James Smart92d7f7b2007-06-17 19:56:38 -05003190 mempool_free(mbox, phba->mbox_mem_pool);
3191 vport->unreg_vpi_cmpl = VPORT_ERROR;
James Smartd7c255b2008-08-24 21:50:00 -04003192 return rc;
James Smart92d7f7b2007-06-17 19:56:38 -05003193 }
James Smartd7c255b2008-08-24 21:50:00 -04003194 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05003195}
3196
3197static void
3198lpfc_mbx_cmpl_reg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
3199{
3200 struct lpfc_vport *vport = pmb->vport;
3201 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart04c68492009-05-22 14:52:52 -04003202 MAILBOX_t *mb = &pmb->u.mb;
James Smart92d7f7b2007-06-17 19:56:38 -05003203
3204 switch (mb->mbxStatus) {
3205 case 0x0011:
3206 case 0x9601:
3207 case 0x9602:
James Smarte8b62012007-08-02 11:10:09 -04003208 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
3209 "0912 cmpl_reg_vpi, mb status = 0x%x\n",
3210 mb->mbxStatus);
James Smart92d7f7b2007-06-17 19:56:38 -05003211 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
3212 spin_lock_irq(shost->host_lock);
3213 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
3214 spin_unlock_irq(shost->host_lock);
3215 vport->fc_myDID = 0;
3216 goto out;
3217 }
James Smart92d7f7b2007-06-17 19:56:38 -05003218
James Smart72100cc2010-02-12 14:43:01 -05003219 spin_lock_irq(shost->host_lock);
James Smartc8685952009-11-18 15:39:16 -05003220 vport->vpi_state |= LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05003221 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
James Smart72100cc2010-02-12 14:43:01 -05003222 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05003223 vport->num_disc_nodes = 0;
3224 /* go thru NPR list and issue ELS PLOGIs */
3225 if (vport->fc_npr_cnt)
3226 lpfc_els_disc_plogi(vport);
3227
3228 if (!vport->num_disc_nodes) {
3229 spin_lock_irq(shost->host_lock);
3230 vport->fc_flag &= ~FC_NDISC_ACTIVE;
3231 spin_unlock_irq(shost->host_lock);
3232 lpfc_can_disctmo(vport);
3233 }
3234 vport->port_state = LPFC_VPORT_READY;
3235
3236out:
3237 mempool_free(pmb, phba->mbox_mem_pool);
3238 return;
3239}
3240
James Smart21e9a0a2009-05-22 14:53:21 -04003241/**
3242 * lpfc_create_static_vport - Read HBA config region to create static vports.
3243 * @phba: pointer to lpfc hba data structure.
3244 *
3245 * This routine issue a DUMP mailbox command for config region 22 to get
3246 * the list of static vports to be created. The function create vports
3247 * based on the information returned from the HBA.
3248 **/
3249void
3250lpfc_create_static_vport(struct lpfc_hba *phba)
3251{
3252 LPFC_MBOXQ_t *pmb = NULL;
3253 MAILBOX_t *mb;
3254 struct static_vport_info *vport_info;
James Smart1c6834a2009-07-19 10:01:26 -04003255 int rc = 0, i;
James Smart21e9a0a2009-05-22 14:53:21 -04003256 struct fc_vport_identifiers vport_id;
3257 struct fc_vport *new_fc_vport;
3258 struct Scsi_Host *shost;
3259 struct lpfc_vport *vport;
3260 uint16_t offset = 0;
3261 uint8_t *vport_buff;
James Smart1c6834a2009-07-19 10:01:26 -04003262 struct lpfc_dmabuf *mp;
3263 uint32_t byte_count = 0;
James Smart21e9a0a2009-05-22 14:53:21 -04003264
3265 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3266 if (!pmb) {
3267 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3268 "0542 lpfc_create_static_vport failed to"
3269 " allocate mailbox memory\n");
3270 return;
3271 }
3272
3273 mb = &pmb->u.mb;
3274
3275 vport_info = kzalloc(sizeof(struct static_vport_info), GFP_KERNEL);
3276 if (!vport_info) {
3277 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3278 "0543 lpfc_create_static_vport failed to"
3279 " allocate vport_info\n");
3280 mempool_free(pmb, phba->mbox_mem_pool);
3281 return;
3282 }
3283
3284 vport_buff = (uint8_t *) vport_info;
3285 do {
James Smart1c6834a2009-07-19 10:01:26 -04003286 if (lpfc_dump_static_vport(phba, pmb, offset))
3287 goto out;
3288
James Smart21e9a0a2009-05-22 14:53:21 -04003289 pmb->vport = phba->pport;
3290 rc = lpfc_sli_issue_mbox_wait(phba, pmb, LPFC_MBOX_TMO);
3291
3292 if ((rc != MBX_SUCCESS) || mb->mbxStatus) {
3293 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
3294 "0544 lpfc_create_static_vport failed to"
3295 " issue dump mailbox command ret 0x%x "
3296 "status 0x%x\n",
3297 rc, mb->mbxStatus);
3298 goto out;
3299 }
3300
James Smart1c6834a2009-07-19 10:01:26 -04003301 if (phba->sli_rev == LPFC_SLI_REV4) {
3302 byte_count = pmb->u.mqe.un.mb_words[5];
3303 mp = (struct lpfc_dmabuf *) pmb->context2;
3304 if (byte_count > sizeof(struct static_vport_info) -
3305 offset)
3306 byte_count = sizeof(struct static_vport_info)
3307 - offset;
3308 memcpy(vport_buff + offset, mp->virt, byte_count);
3309 offset += byte_count;
3310 } else {
3311 if (mb->un.varDmp.word_cnt >
3312 sizeof(struct static_vport_info) - offset)
3313 mb->un.varDmp.word_cnt =
3314 sizeof(struct static_vport_info)
3315 - offset;
3316 byte_count = mb->un.varDmp.word_cnt;
3317 lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
3318 vport_buff + offset,
3319 byte_count);
James Smart21e9a0a2009-05-22 14:53:21 -04003320
James Smart1c6834a2009-07-19 10:01:26 -04003321 offset += byte_count;
3322 }
James Smart21e9a0a2009-05-22 14:53:21 -04003323
James Smart1c6834a2009-07-19 10:01:26 -04003324 } while (byte_count &&
James Smart21e9a0a2009-05-22 14:53:21 -04003325 offset < sizeof(struct static_vport_info));
3326
3327
3328 if ((le32_to_cpu(vport_info->signature) != VPORT_INFO_SIG) ||
3329 ((le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK)
3330 != VPORT_INFO_REV)) {
3331 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3332 "0545 lpfc_create_static_vport bad"
3333 " information header 0x%x 0x%x\n",
3334 le32_to_cpu(vport_info->signature),
3335 le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK);
3336
3337 goto out;
3338 }
3339
3340 shost = lpfc_shost_from_vport(phba->pport);
3341
3342 for (i = 0; i < MAX_STATIC_VPORT_COUNT; i++) {
3343 memset(&vport_id, 0, sizeof(vport_id));
3344 vport_id.port_name = wwn_to_u64(vport_info->vport_list[i].wwpn);
3345 vport_id.node_name = wwn_to_u64(vport_info->vport_list[i].wwnn);
3346 if (!vport_id.port_name || !vport_id.node_name)
3347 continue;
3348
3349 vport_id.roles = FC_PORT_ROLE_FCP_INITIATOR;
3350 vport_id.vport_type = FC_PORTTYPE_NPIV;
3351 vport_id.disable = false;
3352 new_fc_vport = fc_vport_create(shost, 0, &vport_id);
3353
3354 if (!new_fc_vport) {
3355 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
3356 "0546 lpfc_create_static_vport failed to"
James Smarte4e74272009-07-19 10:01:38 -04003357 " create vport\n");
James Smart21e9a0a2009-05-22 14:53:21 -04003358 continue;
3359 }
3360
3361 vport = *(struct lpfc_vport **)new_fc_vport->dd_data;
3362 vport->vport_flag |= STATIC_VPORT;
3363 }
3364
3365out:
James Smart21e9a0a2009-05-22 14:53:21 -04003366 kfree(vport_info);
James Smart1c6834a2009-07-19 10:01:26 -04003367 if (rc != MBX_TIMEOUT) {
3368 if (pmb->context2) {
3369 mp = (struct lpfc_dmabuf *) pmb->context2;
3370 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3371 kfree(mp);
3372 }
James Smart21e9a0a2009-05-22 14:53:21 -04003373 mempool_free(pmb, phba->mbox_mem_pool);
James Smart1c6834a2009-07-19 10:01:26 -04003374 }
James Smart21e9a0a2009-05-22 14:53:21 -04003375
3376 return;
3377}
3378
dea31012005-04-17 16:05:31 -05003379/*
3380 * This routine handles processing a Fabric REG_LOGIN mailbox
3381 * command upon completion. It is setup in the LPFC_MBOXQ
3382 * as the completion routine when the command is
3383 * handed off to the SLI layer.
3384 */
3385void
James Smart2e0fef82007-06-17 19:56:36 -05003386lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05003387{
James Smart92d7f7b2007-06-17 19:56:38 -05003388 struct lpfc_vport *vport = pmb->vport;
James Smart21e9a0a2009-05-22 14:53:21 -04003389 MAILBOX_t *mb = &pmb->u.mb;
James Smart2e0fef82007-06-17 19:56:36 -05003390 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
James Smart92d7f7b2007-06-17 19:56:38 -05003391 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05003392
James Smart549e55c2007-08-02 11:09:51 -04003393 ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart329f9bc2007-04-25 09:53:01 -04003394 pmb->context1 = NULL;
3395 pmb->context2 = NULL;
James Smartd439d282010-09-29 11:18:45 -04003396
dea31012005-04-17 16:05:31 -05003397 if (mb->mbxStatus) {
James Smart21e9a0a2009-05-22 14:53:21 -04003398 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
3399 "0258 Register Fabric login error: 0x%x\n",
3400 mb->mbxStatus);
dea31012005-04-17 16:05:31 -05003401 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3402 kfree(mp);
James Smart329f9bc2007-04-25 09:53:01 -04003403 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003404
James Smart76a95d72010-11-20 23:11:48 -05003405 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart92d7f7b2007-06-17 19:56:38 -05003406 /* FLOGI failed, use loop map to make discovery list */
3407 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -05003408
James Smart92d7f7b2007-06-17 19:56:38 -05003409 /* Start discovery */
3410 lpfc_disc_start(vport);
James Smarte47c9092008-02-08 18:49:26 -05003411 /* Decrement the reference count to ndlp after the
3412 * reference to the ndlp are done.
3413 */
3414 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05003415 return;
3416 }
3417
3418 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte47c9092008-02-08 18:49:26 -05003419 /* Decrement the reference count to ndlp after the reference
3420 * to the ndlp are done.
3421 */
3422 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05003423 return;
3424 }
3425
dea31012005-04-17 16:05:31 -05003426 ndlp->nlp_rpi = mb->un.varWords[0];
James Smart21e9a0a2009-05-22 14:53:21 -04003427 ndlp->nlp_flag |= NLP_RPI_VALID;
dea31012005-04-17 16:05:31 -05003428 ndlp->nlp_type |= NLP_FABRIC;
James Smart2e0fef82007-06-17 19:56:36 -05003429 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
dea31012005-04-17 16:05:31 -05003430
James Smart2e0fef82007-06-17 19:56:36 -05003431 if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
James Smart4b40c592010-03-15 11:25:44 -04003432 /* when physical port receive logo donot start
3433 * vport discovery */
3434 if (!(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG))
3435 lpfc_start_fdiscs(phba);
3436 else
3437 vport->fc_flag &= ~FC_LOGO_RCVD_DID_CHNG ;
James Smart92d7f7b2007-06-17 19:56:38 -05003438 lpfc_do_scr_ns_plogi(phba, vport);
dea31012005-04-17 16:05:31 -05003439 }
3440
3441 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3442 kfree(mp);
James Smart329f9bc2007-04-25 09:53:01 -04003443 mempool_free(pmb, phba->mbox_mem_pool);
James Smarte47c9092008-02-08 18:49:26 -05003444
3445 /* Drop the reference count from the mbox at the end after
3446 * all the current reference to the ndlp have been done.
3447 */
3448 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05003449 return;
3450}
3451
3452/*
3453 * This routine handles processing a NameServer REG_LOGIN mailbox
3454 * command upon completion. It is setup in the LPFC_MBOXQ
3455 * as the completion routine when the command is
3456 * handed off to the SLI layer.
3457 */
3458void
James Smart2e0fef82007-06-17 19:56:36 -05003459lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05003460{
James Smart21e9a0a2009-05-22 14:53:21 -04003461 MAILBOX_t *mb = &pmb->u.mb;
James Smart2e0fef82007-06-17 19:56:36 -05003462 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3463 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
3464 struct lpfc_vport *vport = pmb->vport;
dea31012005-04-17 16:05:31 -05003465
James Smartd439d282010-09-29 11:18:45 -04003466 pmb->context1 = NULL;
3467 pmb->context2 = NULL;
3468
dea31012005-04-17 16:05:31 -05003469 if (mb->mbxStatus) {
James Smart92d7f7b2007-06-17 19:56:38 -05003470out:
James Smart21e9a0a2009-05-22 14:53:21 -04003471 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3472 "0260 Register NameServer error: 0x%x\n",
3473 mb->mbxStatus);
James Smartfa4066b2008-01-11 01:53:27 -05003474 /* decrement the node reference count held for this
3475 * callback function.
3476 */
James Smart329f9bc2007-04-25 09:53:01 -04003477 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05003478 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3479 kfree(mp);
James Smartde0c5b32007-04-25 09:52:27 -04003480 mempool_free(pmb, phba->mbox_mem_pool);
James Smart87af33f2007-10-27 13:37:43 -04003481
3482 /* If no other thread is using the ndlp, free it */
3483 lpfc_nlp_not_used(ndlp);
dea31012005-04-17 16:05:31 -05003484
James Smart76a95d72010-11-20 23:11:48 -05003485 if (phba->fc_topology == LPFC_TOPOLOGY_LOOP) {
James Smart92d7f7b2007-06-17 19:56:38 -05003486 /*
3487 * RegLogin failed, use loop map to make discovery
3488 * list
3489 */
3490 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -05003491
James Smart92d7f7b2007-06-17 19:56:38 -05003492 /* Start discovery */
3493 lpfc_disc_start(vport);
3494 return;
3495 }
3496 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
dea31012005-04-17 16:05:31 -05003497 return;
3498 }
3499
dea31012005-04-17 16:05:31 -05003500 ndlp->nlp_rpi = mb->un.varWords[0];
James Smart21e9a0a2009-05-22 14:53:21 -04003501 ndlp->nlp_flag |= NLP_RPI_VALID;
dea31012005-04-17 16:05:31 -05003502 ndlp->nlp_type |= NLP_FABRIC;
James Smart2e0fef82007-06-17 19:56:36 -05003503 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
dea31012005-04-17 16:05:31 -05003504
James Smart2e0fef82007-06-17 19:56:36 -05003505 if (vport->port_state < LPFC_VPORT_READY) {
3506 /* Link up discovery requires Fabric registration. */
James Smart92d7f7b2007-06-17 19:56:38 -05003507 lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0, 0); /* Do this first! */
3508 lpfc_ns_cmd(vport, SLI_CTNS_RNN_ID, 0, 0);
3509 lpfc_ns_cmd(vport, SLI_CTNS_RSNN_NN, 0, 0);
3510 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
3511 lpfc_ns_cmd(vport, SLI_CTNS_RFT_ID, 0, 0);
3512
3513 /* Issue SCR just before NameServer GID_FT Query */
3514 lpfc_issue_els_scr(vport, SCR_DID, 0);
dea31012005-04-17 16:05:31 -05003515 }
3516
James Smart2e0fef82007-06-17 19:56:36 -05003517 vport->fc_ns_retry = 0;
dea31012005-04-17 16:05:31 -05003518 /* Good status, issue CT Request to NameServer */
James Smart92d7f7b2007-06-17 19:56:38 -05003519 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0)) {
dea31012005-04-17 16:05:31 -05003520 /* Cannot issue NameServer Query, so finish up discovery */
James Smart92d7f7b2007-06-17 19:56:38 -05003521 goto out;
dea31012005-04-17 16:05:31 -05003522 }
3523
James Smartfa4066b2008-01-11 01:53:27 -05003524 /* decrement the node reference count held for this
3525 * callback function.
3526 */
James Smart329f9bc2007-04-25 09:53:01 -04003527 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05003528 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3529 kfree(mp);
James Smart2e0fef82007-06-17 19:56:36 -05003530 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003531
3532 return;
3533}
3534
3535static void
James Smart2e0fef82007-06-17 19:56:36 -05003536lpfc_register_remote_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003537{
James Smart2e0fef82007-06-17 19:56:36 -05003538 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3539 struct fc_rport *rport;
dea31012005-04-17 16:05:31 -05003540 struct lpfc_rport_data *rdata;
3541 struct fc_rport_identifiers rport_ids;
James Smart2e0fef82007-06-17 19:56:36 -05003542 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003543
3544 /* Remote port has reappeared. Re-register w/ FC transport */
Andrew Morton68ce1eb2005-09-21 09:46:54 -07003545 rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
3546 rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
dea31012005-04-17 16:05:31 -05003547 rport_ids.port_id = ndlp->nlp_DID;
3548 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
dea31012005-04-17 16:05:31 -05003549
James Smart329f9bc2007-04-25 09:53:01 -04003550 /*
3551 * We leave our node pointer in rport->dd_data when we unregister a
3552 * FCP target port. But fc_remote_port_add zeros the space to which
3553 * rport->dd_data points. So, if we're reusing a previously
3554 * registered port, drop the reference that we took the last time we
3555 * registered the port.
3556 */
3557 if (ndlp->rport && ndlp->rport->dd_data &&
James Smarte47c9092008-02-08 18:49:26 -05003558 ((struct lpfc_rport_data *) ndlp->rport->dd_data)->pnode == ndlp)
James Smart329f9bc2007-04-25 09:53:01 -04003559 lpfc_nlp_put(ndlp);
James Smart858c9f62007-06-17 19:56:39 -05003560
3561 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
3562 "rport add: did:x%x flg:x%x type x%x",
3563 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
3564
James Smart2e0fef82007-06-17 19:56:36 -05003565 ndlp->rport = rport = fc_remote_port_add(shost, 0, &rport_ids);
James Smart329f9bc2007-04-25 09:53:01 -04003566 if (!rport || !get_device(&rport->dev)) {
dea31012005-04-17 16:05:31 -05003567 dev_printk(KERN_WARNING, &phba->pcidev->dev,
3568 "Warning: fc_remote_port_add failed\n");
3569 return;
3570 }
3571
3572 /* initialize static port data */
3573 rport->maxframe_size = ndlp->nlp_maxframe;
3574 rport->supported_classes = ndlp->nlp_class_sup;
dea31012005-04-17 16:05:31 -05003575 rdata = rport->dd_data;
James Smart329f9bc2007-04-25 09:53:01 -04003576 rdata->pnode = lpfc_nlp_get(ndlp);
James.Smart@Emulex.Com23dc04f2005-11-28 11:41:44 -05003577
3578 if (ndlp->nlp_type & NLP_FCP_TARGET)
3579 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
3580 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
3581 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
3582
3583
3584 if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN)
3585 fc_remote_port_rolechg(rport, rport_ids.roles);
3586
James Smart071fbd3d2006-04-15 11:53:20 -04003587 if ((rport->scsi_target_id != -1) &&
James Smart92d7f7b2007-06-17 19:56:38 -05003588 (rport->scsi_target_id < LPFC_MAX_TARGET)) {
James Smart071fbd3d2006-04-15 11:53:20 -04003589 ndlp->nlp_sid = rport->scsi_target_id;
3590 }
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04003591 return;
3592}
3593
3594static void
James Smart2e0fef82007-06-17 19:56:36 -05003595lpfc_unregister_remote_port(struct lpfc_nodelist *ndlp)
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04003596{
3597 struct fc_rport *rport = ndlp->rport;
James Smartc01f3202006-08-18 17:47:08 -04003598
James Smart858c9f62007-06-17 19:56:39 -05003599 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_RPORT,
3600 "rport delete: did:x%x flg:x%x type x%x",
3601 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
3602
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04003603 fc_remote_port_delete(rport);
dea31012005-04-17 16:05:31 -05003604
3605 return;
3606}
3607
James Smartde0c5b32007-04-25 09:52:27 -04003608static void
James Smart2e0fef82007-06-17 19:56:36 -05003609lpfc_nlp_counters(struct lpfc_vport *vport, int state, int count)
James Smartde0c5b32007-04-25 09:52:27 -04003610{
James Smart2e0fef82007-06-17 19:56:36 -05003611 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3612
3613 spin_lock_irq(shost->host_lock);
James Smartde0c5b32007-04-25 09:52:27 -04003614 switch (state) {
3615 case NLP_STE_UNUSED_NODE:
James Smart2e0fef82007-06-17 19:56:36 -05003616 vport->fc_unused_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04003617 break;
3618 case NLP_STE_PLOGI_ISSUE:
James Smart2e0fef82007-06-17 19:56:36 -05003619 vport->fc_plogi_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04003620 break;
3621 case NLP_STE_ADISC_ISSUE:
James Smart2e0fef82007-06-17 19:56:36 -05003622 vport->fc_adisc_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04003623 break;
3624 case NLP_STE_REG_LOGIN_ISSUE:
James Smart2e0fef82007-06-17 19:56:36 -05003625 vport->fc_reglogin_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04003626 break;
3627 case NLP_STE_PRLI_ISSUE:
James Smart2e0fef82007-06-17 19:56:36 -05003628 vport->fc_prli_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04003629 break;
3630 case NLP_STE_UNMAPPED_NODE:
James Smart2e0fef82007-06-17 19:56:36 -05003631 vport->fc_unmap_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04003632 break;
3633 case NLP_STE_MAPPED_NODE:
James Smart2e0fef82007-06-17 19:56:36 -05003634 vport->fc_map_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04003635 break;
3636 case NLP_STE_NPR_NODE:
James Smart2e0fef82007-06-17 19:56:36 -05003637 vport->fc_npr_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04003638 break;
3639 }
James Smart2e0fef82007-06-17 19:56:36 -05003640 spin_unlock_irq(shost->host_lock);
James Smartde0c5b32007-04-25 09:52:27 -04003641}
Jamie Wellnitz66a9ed62006-02-28 22:33:10 -05003642
James Smartde0c5b32007-04-25 09:52:27 -04003643static void
James Smart2e0fef82007-06-17 19:56:36 -05003644lpfc_nlp_state_cleanup(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04003645 int old_state, int new_state)
3646{
James Smart2e0fef82007-06-17 19:56:36 -05003647 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3648
James Smartde0c5b32007-04-25 09:52:27 -04003649 if (new_state == NLP_STE_UNMAPPED_NODE) {
James Smartde0c5b32007-04-25 09:52:27 -04003650 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
3651 ndlp->nlp_type |= NLP_FC_NODE;
3652 }
3653 if (new_state == NLP_STE_MAPPED_NODE)
3654 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
3655 if (new_state == NLP_STE_NPR_NODE)
3656 ndlp->nlp_flag &= ~NLP_RCV_PLOGI;
dea31012005-04-17 16:05:31 -05003657
James Smartde0c5b32007-04-25 09:52:27 -04003658 /* Transport interface */
3659 if (ndlp->rport && (old_state == NLP_STE_MAPPED_NODE ||
3660 old_state == NLP_STE_UNMAPPED_NODE)) {
James Smart2e0fef82007-06-17 19:56:36 -05003661 vport->phba->nport_event_cnt++;
3662 lpfc_unregister_remote_port(ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04003663 }
dea31012005-04-17 16:05:31 -05003664
James Smartde0c5b32007-04-25 09:52:27 -04003665 if (new_state == NLP_STE_MAPPED_NODE ||
3666 new_state == NLP_STE_UNMAPPED_NODE) {
James Smart2e0fef82007-06-17 19:56:36 -05003667 vport->phba->nport_event_cnt++;
James Smart858c9f62007-06-17 19:56:39 -05003668 /*
3669 * Tell the fc transport about the port, if we haven't
3670 * already. If we have, and it's a scsi entity, be
3671 * sure to unblock any attached scsi devices
3672 */
3673 lpfc_register_remote_port(vport, ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04003674 }
James Smartea2151b2008-09-07 11:52:10 -04003675 if ((new_state == NLP_STE_MAPPED_NODE) &&
3676 (vport->stat_data_enabled)) {
3677 /*
3678 * A new target is discovered, if there is no buffer for
3679 * statistical data collection allocate buffer.
3680 */
3681 ndlp->lat_data = kcalloc(LPFC_MAX_BUCKET_COUNT,
3682 sizeof(struct lpfc_scsicmd_bkt),
3683 GFP_KERNEL);
3684
3685 if (!ndlp->lat_data)
3686 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE,
3687 "0286 lpfc_nlp_state_cleanup failed to "
3688 "allocate statistical data buffer DID "
3689 "0x%x\n", ndlp->nlp_DID);
3690 }
James Smart858c9f62007-06-17 19:56:39 -05003691 /*
3692 * if we added to Mapped list, but the remote port
3693 * registration failed or assigned a target id outside
3694 * our presentable range - move the node to the
3695 * Unmapped List
3696 */
James Smartde0c5b32007-04-25 09:52:27 -04003697 if (new_state == NLP_STE_MAPPED_NODE &&
3698 (!ndlp->rport ||
3699 ndlp->rport->scsi_target_id == -1 ||
3700 ndlp->rport->scsi_target_id >= LPFC_MAX_TARGET)) {
James Smart2e0fef82007-06-17 19:56:36 -05003701 spin_lock_irq(shost->host_lock);
James Smartde0c5b32007-04-25 09:52:27 -04003702 ndlp->nlp_flag |= NLP_TGT_NO_SCSIID;
James Smart2e0fef82007-06-17 19:56:36 -05003703 spin_unlock_irq(shost->host_lock);
3704 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
dea31012005-04-17 16:05:31 -05003705 }
James Smartde0c5b32007-04-25 09:52:27 -04003706}
3707
James Smart685f0bf2007-04-25 09:53:08 -04003708static char *
3709lpfc_nlp_state_name(char *buffer, size_t size, int state)
3710{
3711 static char *states[] = {
3712 [NLP_STE_UNUSED_NODE] = "UNUSED",
3713 [NLP_STE_PLOGI_ISSUE] = "PLOGI",
3714 [NLP_STE_ADISC_ISSUE] = "ADISC",
3715 [NLP_STE_REG_LOGIN_ISSUE] = "REGLOGIN",
3716 [NLP_STE_PRLI_ISSUE] = "PRLI",
3717 [NLP_STE_UNMAPPED_NODE] = "UNMAPPED",
3718 [NLP_STE_MAPPED_NODE] = "MAPPED",
3719 [NLP_STE_NPR_NODE] = "NPR",
3720 };
3721
James Smart311464e2007-08-02 11:10:37 -04003722 if (state < NLP_STE_MAX_STATE && states[state])
James Smart685f0bf2007-04-25 09:53:08 -04003723 strlcpy(buffer, states[state], size);
3724 else
3725 snprintf(buffer, size, "unknown (%d)", state);
3726 return buffer;
3727}
3728
James Smartde0c5b32007-04-25 09:52:27 -04003729void
James Smart2e0fef82007-06-17 19:56:36 -05003730lpfc_nlp_set_state(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
3731 int state)
James Smartde0c5b32007-04-25 09:52:27 -04003732{
James Smart2e0fef82007-06-17 19:56:36 -05003733 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smartde0c5b32007-04-25 09:52:27 -04003734 int old_state = ndlp->nlp_state;
James Smart685f0bf2007-04-25 09:53:08 -04003735 char name1[16], name2[16];
James Smartde0c5b32007-04-25 09:52:27 -04003736
James Smarte8b62012007-08-02 11:10:09 -04003737 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
3738 "0904 NPort state transition x%06x, %s -> %s\n",
3739 ndlp->nlp_DID,
3740 lpfc_nlp_state_name(name1, sizeof(name1), old_state),
3741 lpfc_nlp_state_name(name2, sizeof(name2), state));
James Smart858c9f62007-06-17 19:56:39 -05003742
3743 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
3744 "node statechg did:x%x old:%d ste:%d",
3745 ndlp->nlp_DID, old_state, state);
3746
James Smartde0c5b32007-04-25 09:52:27 -04003747 if (old_state == NLP_STE_NPR_NODE &&
James Smartde0c5b32007-04-25 09:52:27 -04003748 state != NLP_STE_NPR_NODE)
James Smart2e0fef82007-06-17 19:56:36 -05003749 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04003750 if (old_state == NLP_STE_UNMAPPED_NODE) {
3751 ndlp->nlp_flag &= ~NLP_TGT_NO_SCSIID;
3752 ndlp->nlp_type &= ~NLP_FC_NODE;
3753 }
3754
James Smart685f0bf2007-04-25 09:53:08 -04003755 if (list_empty(&ndlp->nlp_listp)) {
James Smart2e0fef82007-06-17 19:56:36 -05003756 spin_lock_irq(shost->host_lock);
3757 list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
3758 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003759 } else if (old_state)
James Smart2e0fef82007-06-17 19:56:36 -05003760 lpfc_nlp_counters(vport, old_state, -1);
James Smartde0c5b32007-04-25 09:52:27 -04003761
3762 ndlp->nlp_state = state;
James Smart2e0fef82007-06-17 19:56:36 -05003763 lpfc_nlp_counters(vport, state, 1);
3764 lpfc_nlp_state_cleanup(vport, ndlp, old_state, state);
James Smartde0c5b32007-04-25 09:52:27 -04003765}
3766
3767void
James Smarte47c9092008-02-08 18:49:26 -05003768lpfc_enqueue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
3769{
3770 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3771
3772 if (list_empty(&ndlp->nlp_listp)) {
3773 spin_lock_irq(shost->host_lock);
3774 list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
3775 spin_unlock_irq(shost->host_lock);
3776 }
3777}
3778
3779void
James Smart2e0fef82007-06-17 19:56:36 -05003780lpfc_dequeue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
James Smartde0c5b32007-04-25 09:52:27 -04003781{
James Smart2e0fef82007-06-17 19:56:36 -05003782 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3783
James Smart0d2b6b82008-06-14 22:52:47 -04003784 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04003785 if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
James Smart2e0fef82007-06-17 19:56:36 -05003786 lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
3787 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003788 list_del_init(&ndlp->nlp_listp);
James Smart2e0fef82007-06-17 19:56:36 -05003789 spin_unlock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05003790 lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state,
James Smarte47c9092008-02-08 18:49:26 -05003791 NLP_STE_UNUSED_NODE);
3792}
3793
Adrian Bunk4d9db012008-02-14 23:24:02 +02003794static void
James Smarte47c9092008-02-08 18:49:26 -05003795lpfc_disable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
3796{
James Smart0d2b6b82008-06-14 22:52:47 -04003797 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smarte47c9092008-02-08 18:49:26 -05003798 if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
3799 lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
3800 lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state,
3801 NLP_STE_UNUSED_NODE);
3802}
James Smart109f6ed2008-12-04 22:39:08 -05003803/**
James Smart3621a712009-04-06 18:47:14 -04003804 * lpfc_initialize_node - Initialize all fields of node object
James Smart109f6ed2008-12-04 22:39:08 -05003805 * @vport: Pointer to Virtual Port object.
3806 * @ndlp: Pointer to FC node object.
3807 * @did: FC_ID of the node.
James Smarta257bf92009-04-06 18:48:10 -04003808 *
3809 * This function is always called when node object need to be initialized.
3810 * It initializes all the fields of the node object. Although the reference
3811 * to phba from @ndlp can be obtained indirectly through it's reference to
3812 * @vport, a direct reference to phba is taken here by @ndlp. This is due
3813 * to the life-span of the @ndlp might go beyond the existence of @vport as
3814 * the final release of ndlp is determined by its reference count. And, the
3815 * operation on @ndlp needs the reference to phba.
James Smart109f6ed2008-12-04 22:39:08 -05003816 **/
3817static inline void
3818lpfc_initialize_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
3819 uint32_t did)
3820{
3821 INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp);
3822 INIT_LIST_HEAD(&ndlp->dev_loss_evt.evt_listp);
3823 init_timer(&ndlp->nlp_delayfunc);
3824 ndlp->nlp_delayfunc.function = lpfc_els_retry_delay;
3825 ndlp->nlp_delayfunc.data = (unsigned long)ndlp;
3826 ndlp->nlp_DID = did;
3827 ndlp->vport = vport;
James Smarta257bf92009-04-06 18:48:10 -04003828 ndlp->phba = vport->phba;
James Smart109f6ed2008-12-04 22:39:08 -05003829 ndlp->nlp_sid = NLP_NO_SID;
3830 kref_init(&ndlp->kref);
3831 NLP_INT_NODE_ACT(ndlp);
3832 atomic_set(&ndlp->cmd_pending, 0);
James Smart7dc517d2010-07-14 15:32:10 -04003833 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
James Smart109f6ed2008-12-04 22:39:08 -05003834}
James Smarte47c9092008-02-08 18:49:26 -05003835
3836struct lpfc_nodelist *
3837lpfc_enable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
3838 int state)
3839{
3840 struct lpfc_hba *phba = vport->phba;
3841 uint32_t did;
3842 unsigned long flags;
3843
3844 if (!ndlp)
3845 return NULL;
3846
3847 spin_lock_irqsave(&phba->ndlp_lock, flags);
3848 /* The ndlp should not be in memory free mode */
3849 if (NLP_CHK_FREE_REQ(ndlp)) {
3850 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
3851 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
3852 "0277 lpfc_enable_node: ndlp:x%p "
3853 "usgmap:x%x refcnt:%d\n",
3854 (void *)ndlp, ndlp->nlp_usg_map,
3855 atomic_read(&ndlp->kref.refcount));
3856 return NULL;
3857 }
3858 /* The ndlp should not already be in active mode */
3859 if (NLP_CHK_NODE_ACT(ndlp)) {
3860 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
3861 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
3862 "0278 lpfc_enable_node: ndlp:x%p "
3863 "usgmap:x%x refcnt:%d\n",
3864 (void *)ndlp, ndlp->nlp_usg_map,
3865 atomic_read(&ndlp->kref.refcount));
3866 return NULL;
3867 }
3868
3869 /* Keep the original DID */
3870 did = ndlp->nlp_DID;
3871
3872 /* re-initialize ndlp except of ndlp linked list pointer */
3873 memset((((char *)ndlp) + sizeof (struct list_head)), 0,
3874 sizeof (struct lpfc_nodelist) - sizeof (struct list_head));
James Smart109f6ed2008-12-04 22:39:08 -05003875 lpfc_initialize_node(vport, ndlp, did);
James Smarte47c9092008-02-08 18:49:26 -05003876
3877 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
3878
3879 if (state != NLP_STE_UNUSED_NODE)
3880 lpfc_nlp_set_state(vport, ndlp, state);
3881
3882 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
3883 "node enable: did:x%x",
3884 ndlp->nlp_DID, 0, 0);
3885 return ndlp;
James Smartde0c5b32007-04-25 09:52:27 -04003886}
3887
3888void
James Smart2e0fef82007-06-17 19:56:36 -05003889lpfc_drop_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
James Smartde0c5b32007-04-25 09:52:27 -04003890{
James Smart87af33f2007-10-27 13:37:43 -04003891 /*
James Smartfa4066b2008-01-11 01:53:27 -05003892 * Use of lpfc_drop_node and UNUSED list: lpfc_drop_node should
James Smart87af33f2007-10-27 13:37:43 -04003893 * be used if we wish to issue the "last" lpfc_nlp_put() to remove
James Smartfa4066b2008-01-11 01:53:27 -05003894 * the ndlp from the vport. The ndlp marked as UNUSED on the list
3895 * until ALL other outstanding threads have completed. We check
3896 * that the ndlp not already in the UNUSED state before we proceed.
James Smart87af33f2007-10-27 13:37:43 -04003897 */
James Smartfa4066b2008-01-11 01:53:27 -05003898 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
3899 return;
James Smart51ef4c22007-08-02 11:10:31 -04003900 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE);
James Smart87af33f2007-10-27 13:37:43 -04003901 lpfc_nlp_put(ndlp);
James Smart98c9ea52007-10-27 13:37:33 -04003902 return;
dea31012005-04-17 16:05:31 -05003903}
3904
3905/*
3906 * Start / ReStart rescue timer for Discovery / RSCN handling
3907 */
3908void
James Smart2e0fef82007-06-17 19:56:36 -05003909lpfc_set_disctmo(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003910{
James Smart2e0fef82007-06-17 19:56:36 -05003911 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3912 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003913 uint32_t tmo;
3914
James Smart2e0fef82007-06-17 19:56:36 -05003915 if (vport->port_state == LPFC_LOCAL_CFG_LINK) {
Frederik Schwarzer025dfda2008-10-16 19:02:37 +02003916 /* For FAN, timeout should be greater than edtov */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003917 tmo = (((phba->fc_edtov + 999) / 1000) + 1);
3918 } else {
Frederik Schwarzer025dfda2008-10-16 19:02:37 +02003919 /* Normal discovery timeout should be > than ELS/CT timeout
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003920 * FC spec states we need 3 * ratov for CT requests
3921 */
3922 tmo = ((phba->fc_ratov * 3) + 3);
3923 }
dea31012005-04-17 16:05:31 -05003924
James Smart858c9f62007-06-17 19:56:39 -05003925
3926 if (!timer_pending(&vport->fc_disctmo)) {
3927 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3928 "set disc timer: tmo:x%x state:x%x flg:x%x",
3929 tmo, vport->port_state, vport->fc_flag);
3930 }
3931
James Smart2e0fef82007-06-17 19:56:36 -05003932 mod_timer(&vport->fc_disctmo, jiffies + HZ * tmo);
3933 spin_lock_irq(shost->host_lock);
3934 vport->fc_flag |= FC_DISC_TMO;
3935 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003936
3937 /* Start Discovery Timer state <hba_state> */
James Smarte8b62012007-08-02 11:10:09 -04003938 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3939 "0247 Start Discovery Timer state x%x "
3940 "Data: x%x x%lx x%x x%x\n",
3941 vport->port_state, tmo,
3942 (unsigned long)&vport->fc_disctmo, vport->fc_plogi_cnt,
3943 vport->fc_adisc_cnt);
dea31012005-04-17 16:05:31 -05003944
3945 return;
3946}
3947
3948/*
3949 * Cancel rescue timer for Discovery / RSCN handling
3950 */
3951int
James Smart2e0fef82007-06-17 19:56:36 -05003952lpfc_can_disctmo(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003953{
James Smart2e0fef82007-06-17 19:56:36 -05003954 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05003955 unsigned long iflags;
3956
James Smart858c9f62007-06-17 19:56:39 -05003957 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3958 "can disc timer: state:x%x rtry:x%x flg:x%x",
3959 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
3960
dea31012005-04-17 16:05:31 -05003961 /* Turn off discovery timer if its running */
James Smart2e0fef82007-06-17 19:56:36 -05003962 if (vport->fc_flag & FC_DISC_TMO) {
3963 spin_lock_irqsave(shost->host_lock, iflags);
3964 vport->fc_flag &= ~FC_DISC_TMO;
3965 spin_unlock_irqrestore(shost->host_lock, iflags);
3966 del_timer_sync(&vport->fc_disctmo);
3967 spin_lock_irqsave(&vport->work_port_lock, iflags);
3968 vport->work_port_events &= ~WORKER_DISC_TMO;
3969 spin_unlock_irqrestore(&vport->work_port_lock, iflags);
dea31012005-04-17 16:05:31 -05003970 }
3971
3972 /* Cancel Discovery Timer state <hba_state> */
James Smarte8b62012007-08-02 11:10:09 -04003973 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3974 "0248 Cancel Discovery Timer state x%x "
3975 "Data: x%x x%x x%x\n",
3976 vport->port_state, vport->fc_flag,
3977 vport->fc_plogi_cnt, vport->fc_adisc_cnt);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003978 return 0;
dea31012005-04-17 16:05:31 -05003979}
3980
3981/*
3982 * Check specified ring for outstanding IOCB on the SLI queue
3983 * Return true if iocb matches the specified nport
3984 */
3985int
James Smart2e0fef82007-06-17 19:56:36 -05003986lpfc_check_sli_ndlp(struct lpfc_hba *phba,
3987 struct lpfc_sli_ring *pring,
3988 struct lpfc_iocbq *iocb,
3989 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003990{
James Smart2e0fef82007-06-17 19:56:36 -05003991 struct lpfc_sli *psli = &phba->sli;
3992 IOCB_t *icmd = &iocb->iocb;
James Smart92d7f7b2007-06-17 19:56:38 -05003993 struct lpfc_vport *vport = ndlp->vport;
3994
3995 if (iocb->vport != vport)
3996 return 0;
3997
dea31012005-04-17 16:05:31 -05003998 if (pring->ringno == LPFC_ELS_RING) {
3999 switch (icmd->ulpCommand) {
4000 case CMD_GEN_REQUEST64_CR:
James Smart21e9a0a2009-05-22 14:53:21 -04004001 if (iocb->context_un.ndlp == ndlp)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004002 return 1;
dea31012005-04-17 16:05:31 -05004003 case CMD_ELS_REQUEST64_CR:
James Smart10d4e952006-04-15 11:53:15 -04004004 if (icmd->un.elsreq64.remoteID == ndlp->nlp_DID)
4005 return 1;
dea31012005-04-17 16:05:31 -05004006 case CMD_XMIT_ELS_RSP64_CX:
4007 if (iocb->context1 == (uint8_t *) ndlp)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004008 return 1;
dea31012005-04-17 16:05:31 -05004009 }
James Smarta4bc3372006-12-02 13:34:16 -05004010 } else if (pring->ringno == psli->extra_ring) {
dea31012005-04-17 16:05:31 -05004011
4012 } else if (pring->ringno == psli->fcp_ring) {
4013 /* Skip match check if waiting to relogin to FCP target */
4014 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
James Smart92d7f7b2007-06-17 19:56:38 -05004015 (ndlp->nlp_flag & NLP_DELAY_TMO)) {
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004016 return 0;
dea31012005-04-17 16:05:31 -05004017 }
4018 if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) {
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004019 return 1;
dea31012005-04-17 16:05:31 -05004020 }
4021 } else if (pring->ringno == psli->next_ring) {
4022
4023 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004024 return 0;
dea31012005-04-17 16:05:31 -05004025}
4026
4027/*
4028 * Free resources / clean up outstanding I/Os
4029 * associated with nlp_rpi in the LPFC_NODELIST entry.
4030 */
4031static int
James Smart2e0fef82007-06-17 19:56:36 -05004032lpfc_no_rpi(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004033{
James Smart2534ba72007-04-25 09:52:20 -04004034 LIST_HEAD(completions);
dea31012005-04-17 16:05:31 -05004035 struct lpfc_sli *psli;
4036 struct lpfc_sli_ring *pring;
4037 struct lpfc_iocbq *iocb, *next_iocb;
James Smart6a9c52c2009-10-02 15:16:51 -04004038 uint32_t i;
dea31012005-04-17 16:05:31 -05004039
James Smart92d7f7b2007-06-17 19:56:38 -05004040 lpfc_fabric_abort_nport(ndlp);
4041
dea31012005-04-17 16:05:31 -05004042 /*
4043 * Everything that matches on txcmplq will be returned
4044 * by firmware with a no rpi error.
4045 */
4046 psli = &phba->sli;
James Smart21e9a0a2009-05-22 14:53:21 -04004047 if (ndlp->nlp_flag & NLP_RPI_VALID) {
dea31012005-04-17 16:05:31 -05004048 /* Now process each ring */
4049 for (i = 0; i < psli->num_rings; i++) {
4050 pring = &psli->ring[i];
4051
James Smart2e0fef82007-06-17 19:56:36 -05004052 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004053 list_for_each_entry_safe(iocb, next_iocb, &pring->txq,
James Smart2e0fef82007-06-17 19:56:36 -05004054 list) {
dea31012005-04-17 16:05:31 -05004055 /*
4056 * Check to see if iocb matches the nport we are
4057 * looking for
4058 */
James Smart92d7f7b2007-06-17 19:56:38 -05004059 if ((lpfc_check_sli_ndlp(phba, pring, iocb,
4060 ndlp))) {
dea31012005-04-17 16:05:31 -05004061 /* It matches, so deque and call compl
4062 with an error */
James Smart2534ba72007-04-25 09:52:20 -04004063 list_move_tail(&iocb->list,
4064 &completions);
dea31012005-04-17 16:05:31 -05004065 pring->txq_cnt--;
dea31012005-04-17 16:05:31 -05004066 }
4067 }
James Smart2e0fef82007-06-17 19:56:36 -05004068 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004069 }
4070 }
James Smart2534ba72007-04-25 09:52:20 -04004071
James Smarta257bf92009-04-06 18:48:10 -04004072 /* Cancel all the IOCBs from the completions list */
4073 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
4074 IOERR_SLI_ABORTED);
James Smart2534ba72007-04-25 09:52:20 -04004075
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004076 return 0;
dea31012005-04-17 16:05:31 -05004077}
4078
4079/*
4080 * Free rpi associated with LPFC_NODELIST entry.
4081 * This routine is called from lpfc_freenode(), when we are removing
4082 * a LPFC_NODELIST entry. It is also called if the driver initiates a
4083 * LOGO that completes successfully, and we are waiting to PLOGI back
4084 * to the remote NPort. In addition, it is called after we receive
4085 * and unsolicated ELS cmd, send back a rsp, the rsp completes and
4086 * we are waiting to PLOGI back to the remote NPort.
4087 */
4088int
James Smart2e0fef82007-06-17 19:56:36 -05004089lpfc_unreg_rpi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004090{
James Smart2e0fef82007-06-17 19:56:36 -05004091 struct lpfc_hba *phba = vport->phba;
4092 LPFC_MBOXQ_t *mbox;
dea31012005-04-17 16:05:31 -05004093 int rc;
4094
James Smart21e9a0a2009-05-22 14:53:21 -04004095 if (ndlp->nlp_flag & NLP_RPI_VALID) {
James Smart2e0fef82007-06-17 19:56:36 -05004096 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4097 if (mbox) {
James Smart92d7f7b2007-06-17 19:56:38 -05004098 lpfc_unreg_login(phba, vport->vpi, ndlp->nlp_rpi, mbox);
James Smarted957682007-06-17 19:56:37 -05004099 mbox->vport = vport;
James Smart92d7f7b2007-06-17 19:56:38 -05004100 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart0b727fe2007-10-27 13:37:25 -04004101 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -05004102 if (rc == MBX_NOT_FINISHED)
James Smart2e0fef82007-06-17 19:56:36 -05004103 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004104 }
dea31012005-04-17 16:05:31 -05004105 lpfc_no_rpi(phba, ndlp);
James Smartd7c47992010-06-08 18:31:54 -04004106
dea31012005-04-17 16:05:31 -05004107 ndlp->nlp_rpi = 0;
James Smart21e9a0a2009-05-22 14:53:21 -04004108 ndlp->nlp_flag &= ~NLP_RPI_VALID;
James Smart0c287582009-06-10 17:22:56 -04004109 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
dea31012005-04-17 16:05:31 -05004110 return 1;
4111 }
4112 return 0;
4113}
4114
James Smartecfd03c2010-02-12 14:41:27 -05004115/**
4116 * lpfc_unreg_hba_rpis - Unregister rpis registered to the hba.
4117 * @phba: pointer to lpfc hba data structure.
4118 *
4119 * This routine is invoked to unregister all the currently registered RPIs
4120 * to the HBA.
4121 **/
4122void
4123lpfc_unreg_hba_rpis(struct lpfc_hba *phba)
4124{
4125 struct lpfc_vport **vports;
4126 struct lpfc_nodelist *ndlp;
4127 struct Scsi_Host *shost;
4128 int i;
4129
4130 vports = lpfc_create_vport_work_array(phba);
James Smart63e801c2010-11-20 23:14:19 -05004131 if (!vports) {
4132 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
4133 "2884 Vport array allocation failed \n");
4134 return;
4135 }
James Smartecfd03c2010-02-12 14:41:27 -05004136 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
4137 shost = lpfc_shost_from_vport(vports[i]);
4138 spin_lock_irq(shost->host_lock);
4139 list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) {
James Smart0c9ab6f2010-02-26 14:15:57 -05004140 if (ndlp->nlp_flag & NLP_RPI_VALID) {
4141 /* The mempool_alloc might sleep */
4142 spin_unlock_irq(shost->host_lock);
James Smartecfd03c2010-02-12 14:41:27 -05004143 lpfc_unreg_rpi(vports[i], ndlp);
James Smart0c9ab6f2010-02-26 14:15:57 -05004144 spin_lock_irq(shost->host_lock);
4145 }
James Smartecfd03c2010-02-12 14:41:27 -05004146 }
4147 spin_unlock_irq(shost->host_lock);
4148 }
4149 lpfc_destroy_vport_work_array(phba, vports);
4150}
4151
James Smart92d7f7b2007-06-17 19:56:38 -05004152void
4153lpfc_unreg_all_rpis(struct lpfc_vport *vport)
4154{
4155 struct lpfc_hba *phba = vport->phba;
4156 LPFC_MBOXQ_t *mbox;
4157 int rc;
4158
James Smart5af5eee2010-10-22 11:06:38 -04004159 if (phba->sli_rev == LPFC_SLI_REV4) {
4160 lpfc_sli4_unreg_all_rpis(vport);
4161 return;
4162 }
4163
James Smart92d7f7b2007-06-17 19:56:38 -05004164 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4165 if (mbox) {
4166 lpfc_unreg_login(phba, vport->vpi, 0xffff, mbox);
4167 mbox->vport = vport;
4168 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart09372822008-01-11 01:52:54 -05004169 mbox->context1 = NULL;
4170 rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
James Smarta257bf92009-04-06 18:48:10 -04004171 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05004172 mempool_free(mbox, phba->mbox_mem_pool);
James Smarta257bf92009-04-06 18:48:10 -04004173
4174 if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED))
4175 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT,
4176 "1836 Could not issue "
4177 "unreg_login(all_rpis) status %d\n", rc);
James Smart92d7f7b2007-06-17 19:56:38 -05004178 }
4179}
4180
4181void
4182lpfc_unreg_default_rpis(struct lpfc_vport *vport)
4183{
4184 struct lpfc_hba *phba = vport->phba;
4185 LPFC_MBOXQ_t *mbox;
4186 int rc;
4187
4188 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4189 if (mbox) {
4190 lpfc_unreg_did(phba, vport->vpi, 0xffffffff, mbox);
4191 mbox->vport = vport;
4192 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart09372822008-01-11 01:52:54 -05004193 mbox->context1 = NULL;
4194 rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
James Smarta257bf92009-04-06 18:48:10 -04004195 if (rc != MBX_TIMEOUT)
4196 mempool_free(mbox, phba->mbox_mem_pool);
4197
4198 if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED))
James Smarte8b62012007-08-02 11:10:09 -04004199 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT,
4200 "1815 Could not issue "
James Smarta257bf92009-04-06 18:48:10 -04004201 "unreg_did (default rpis) status %d\n",
4202 rc);
James Smart92d7f7b2007-06-17 19:56:38 -05004203 }
4204}
4205
dea31012005-04-17 16:05:31 -05004206/*
4207 * Free resources associated with LPFC_NODELIST entry
4208 * so it can be freed.
4209 */
4210static int
James Smart2e0fef82007-06-17 19:56:36 -05004211lpfc_cleanup_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004212{
James Smart2e0fef82007-06-17 19:56:36 -05004213 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4214 struct lpfc_hba *phba = vport->phba;
4215 LPFC_MBOXQ_t *mb, *nextmb;
dea31012005-04-17 16:05:31 -05004216 struct lpfc_dmabuf *mp;
dea31012005-04-17 16:05:31 -05004217
4218 /* Cleanup node for NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04004219 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4220 "0900 Cleanup node for NPort x%x "
4221 "Data: x%x x%x x%x\n",
4222 ndlp->nlp_DID, ndlp->nlp_flag,
4223 ndlp->nlp_state, ndlp->nlp_rpi);
James Smarte47c9092008-02-08 18:49:26 -05004224 if (NLP_CHK_FREE_REQ(ndlp)) {
4225 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
4226 "0280 lpfc_cleanup_node: ndlp:x%p "
4227 "usgmap:x%x refcnt:%d\n",
4228 (void *)ndlp, ndlp->nlp_usg_map,
4229 atomic_read(&ndlp->kref.refcount));
4230 lpfc_dequeue_node(vport, ndlp);
4231 } else {
4232 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
4233 "0281 lpfc_cleanup_node: ndlp:x%p "
4234 "usgmap:x%x refcnt:%d\n",
4235 (void *)ndlp, ndlp->nlp_usg_map,
4236 atomic_read(&ndlp->kref.refcount));
4237 lpfc_disable_node(vport, ndlp);
4238 }
dea31012005-04-17 16:05:31 -05004239
dea31012005-04-17 16:05:31 -05004240 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
4241 if ((mb = phba->sli.mbox_active)) {
James Smart04c68492009-05-22 14:52:52 -04004242 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
dea31012005-04-17 16:05:31 -05004243 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
4244 mb->context2 = NULL;
4245 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
4246 }
4247 }
James Smart33ccf8d2006-08-17 11:57:58 -04004248
James Smart2e0fef82007-06-17 19:56:36 -05004249 spin_lock_irq(&phba->hbalock);
James Smart5ac6b302010-10-22 11:05:36 -04004250 /* Cleanup REG_LOGIN completions which are not yet processed */
4251 list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) {
4252 if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) ||
4253 (ndlp != (struct lpfc_nodelist *) mb->context2))
4254 continue;
4255
4256 mb->context2 = NULL;
4257 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
4258 }
4259
dea31012005-04-17 16:05:31 -05004260 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
James Smart04c68492009-05-22 14:52:52 -04004261 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
James Smart92d7f7b2007-06-17 19:56:38 -05004262 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
dea31012005-04-17 16:05:31 -05004263 mp = (struct lpfc_dmabuf *) (mb->context1);
4264 if (mp) {
James Smart2e0fef82007-06-17 19:56:36 -05004265 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
dea31012005-04-17 16:05:31 -05004266 kfree(mp);
4267 }
4268 list_del(&mb->list);
James Smartffc95492010-06-07 15:23:17 -04004269 if (phba->sli_rev == LPFC_SLI_REV4)
4270 lpfc_sli4_free_rpi(phba,
4271 mb->u.mb.un.varRegLogin.rpi);
dea31012005-04-17 16:05:31 -05004272 mempool_free(mb, phba->mbox_mem_pool);
James Smarte47c9092008-02-08 18:49:26 -05004273 /* We shall not invoke the lpfc_nlp_put to decrement
4274 * the ndlp reference count as we are in the process
4275 * of lpfc_nlp_release.
4276 */
dea31012005-04-17 16:05:31 -05004277 }
4278 }
James Smart2e0fef82007-06-17 19:56:36 -05004279 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004280
James Smarte47c9092008-02-08 18:49:26 -05004281 lpfc_els_abort(phba, ndlp);
4282
James Smart2e0fef82007-06-17 19:56:36 -05004283 spin_lock_irq(shost->host_lock);
James Smartc01f3202006-08-18 17:47:08 -04004284 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05004285 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004286
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004287 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05004288 del_timer_sync(&ndlp->nlp_delayfunc);
4289
James Smart0d2b6b82008-06-14 22:52:47 -04004290 list_del_init(&ndlp->els_retry_evt.evt_listp);
4291 list_del_init(&ndlp->dev_loss_evt.evt_listp);
dea31012005-04-17 16:05:31 -05004292
James Smart2e0fef82007-06-17 19:56:36 -05004293 lpfc_unreg_rpi(vport, ndlp);
dea31012005-04-17 16:05:31 -05004294
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004295 return 0;
dea31012005-04-17 16:05:31 -05004296}
4297
4298/*
4299 * Check to see if we can free the nlp back to the freelist.
4300 * If we are in the middle of using the nlp in the discovery state
4301 * machine, defer the free till we reach the end of the state machine.
4302 */
James Smart329f9bc2007-04-25 09:53:01 -04004303static void
James Smart2e0fef82007-06-17 19:56:36 -05004304lpfc_nlp_remove(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004305{
James Smarta8adb832007-10-27 13:37:53 -04004306 struct lpfc_hba *phba = vport->phba;
James Smart1dcb58e2007-04-25 09:51:30 -04004307 struct lpfc_rport_data *rdata;
James Smarta8adb832007-10-27 13:37:53 -04004308 LPFC_MBOXQ_t *mbox;
4309 int rc;
dea31012005-04-17 16:05:31 -05004310
James Smart0d2b6b82008-06-14 22:52:47 -04004311 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smart21e9a0a2009-05-22 14:53:21 -04004312 if ((ndlp->nlp_flag & NLP_DEFER_RM) &&
James Smartffc95492010-06-07 15:23:17 -04004313 !(ndlp->nlp_flag & NLP_REG_LOGIN_SEND) &&
James Smart21e9a0a2009-05-22 14:53:21 -04004314 !(ndlp->nlp_flag & NLP_RPI_VALID)) {
James Smarta8adb832007-10-27 13:37:53 -04004315 /* For this case we need to cleanup the default rpi
4316 * allocated by the firmware.
4317 */
4318 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))
4319 != NULL) {
James Smart21e9a0a2009-05-22 14:53:21 -04004320 rc = lpfc_reg_rpi(phba, vport->vpi, ndlp->nlp_DID,
James Smarta8adb832007-10-27 13:37:53 -04004321 (uint8_t *) &vport->fc_sparam, mbox, 0);
4322 if (rc) {
4323 mempool_free(mbox, phba->mbox_mem_pool);
4324 }
4325 else {
4326 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
4327 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
4328 mbox->vport = vport;
James Smart09372822008-01-11 01:52:54 -05004329 mbox->context2 = NULL;
James Smarta8adb832007-10-27 13:37:53 -04004330 rc =lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
4331 if (rc == MBX_NOT_FINISHED) {
4332 mempool_free(mbox, phba->mbox_mem_pool);
4333 }
4334 }
4335 }
4336 }
James Smart2e0fef82007-06-17 19:56:36 -05004337 lpfc_cleanup_node(vport, ndlp);
James Smart1dcb58e2007-04-25 09:51:30 -04004338
James Smart2e0fef82007-06-17 19:56:36 -05004339 /*
James Smart92d7f7b2007-06-17 19:56:38 -05004340 * We can get here with a non-NULL ndlp->rport because when we
4341 * unregister a rport we don't break the rport/node linkage. So if we
4342 * do, make sure we don't leaving any dangling pointers behind.
James Smart2e0fef82007-06-17 19:56:36 -05004343 */
James Smart92d7f7b2007-06-17 19:56:38 -05004344 if (ndlp->rport) {
James Smart329f9bc2007-04-25 09:53:01 -04004345 rdata = ndlp->rport->dd_data;
4346 rdata->pnode = NULL;
4347 ndlp->rport = NULL;
dea31012005-04-17 16:05:31 -05004348 }
dea31012005-04-17 16:05:31 -05004349}
4350
4351static int
James Smart2e0fef82007-06-17 19:56:36 -05004352lpfc_matchdid(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4353 uint32_t did)
dea31012005-04-17 16:05:31 -05004354{
James Smart2e0fef82007-06-17 19:56:36 -05004355 D_ID mydid, ndlpdid, matchdid;
dea31012005-04-17 16:05:31 -05004356
4357 if (did == Bcast_DID)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004358 return 0;
dea31012005-04-17 16:05:31 -05004359
dea31012005-04-17 16:05:31 -05004360 /* First check for Direct match */
4361 if (ndlp->nlp_DID == did)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004362 return 1;
dea31012005-04-17 16:05:31 -05004363
4364 /* Next check for area/domain identically equals 0 match */
James Smart2e0fef82007-06-17 19:56:36 -05004365 mydid.un.word = vport->fc_myDID;
dea31012005-04-17 16:05:31 -05004366 if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) {
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004367 return 0;
dea31012005-04-17 16:05:31 -05004368 }
4369
4370 matchdid.un.word = did;
4371 ndlpdid.un.word = ndlp->nlp_DID;
4372 if (matchdid.un.b.id == ndlpdid.un.b.id) {
4373 if ((mydid.un.b.domain == matchdid.un.b.domain) &&
4374 (mydid.un.b.area == matchdid.un.b.area)) {
4375 if ((ndlpdid.un.b.domain == 0) &&
4376 (ndlpdid.un.b.area == 0)) {
4377 if (ndlpdid.un.b.id)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004378 return 1;
dea31012005-04-17 16:05:31 -05004379 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004380 return 0;
dea31012005-04-17 16:05:31 -05004381 }
4382
4383 matchdid.un.word = ndlp->nlp_DID;
4384 if ((mydid.un.b.domain == ndlpdid.un.b.domain) &&
4385 (mydid.un.b.area == ndlpdid.un.b.area)) {
4386 if ((matchdid.un.b.domain == 0) &&
4387 (matchdid.un.b.area == 0)) {
4388 if (matchdid.un.b.id)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004389 return 1;
dea31012005-04-17 16:05:31 -05004390 }
4391 }
4392 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004393 return 0;
dea31012005-04-17 16:05:31 -05004394}
4395
James Smart685f0bf2007-04-25 09:53:08 -04004396/* Search for a nodelist entry */
James Smart2e0fef82007-06-17 19:56:36 -05004397static struct lpfc_nodelist *
4398__lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05004399{
James Smart2fb9bd82006-12-02 13:33:57 -05004400 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05004401 uint32_t data1;
4402
James Smart2e0fef82007-06-17 19:56:36 -05004403 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
4404 if (lpfc_matchdid(vport, ndlp, did)) {
James Smart685f0bf2007-04-25 09:53:08 -04004405 data1 = (((uint32_t) ndlp->nlp_state << 24) |
4406 ((uint32_t) ndlp->nlp_xri << 16) |
4407 ((uint32_t) ndlp->nlp_type << 8) |
4408 ((uint32_t) ndlp->nlp_rpi & 0xff));
James Smarte8b62012007-08-02 11:10:09 -04004409 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4410 "0929 FIND node DID "
4411 "Data: x%p x%x x%x x%x\n",
4412 ndlp, ndlp->nlp_DID,
4413 ndlp->nlp_flag, data1);
James Smart685f0bf2007-04-25 09:53:08 -04004414 return ndlp;
dea31012005-04-17 16:05:31 -05004415 }
4416 }
Jamie Wellnitz66a9ed62006-02-28 22:33:10 -05004417
dea31012005-04-17 16:05:31 -05004418 /* FIND node did <did> NOT FOUND */
James Smarte8b62012007-08-02 11:10:09 -04004419 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4420 "0932 FIND node did x%x NOT FOUND.\n", did);
dea31012005-04-17 16:05:31 -05004421 return NULL;
4422}
4423
4424struct lpfc_nodelist *
James Smart2e0fef82007-06-17 19:56:36 -05004425lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05004426{
James Smart2e0fef82007-06-17 19:56:36 -05004427 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004428 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05004429
James Smart2e0fef82007-06-17 19:56:36 -05004430 spin_lock_irq(shost->host_lock);
4431 ndlp = __lpfc_findnode_did(vport, did);
4432 spin_unlock_irq(shost->host_lock);
4433 return ndlp;
4434}
4435
4436struct lpfc_nodelist *
4437lpfc_setup_disc_node(struct lpfc_vport *vport, uint32_t did)
4438{
4439 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4440 struct lpfc_nodelist *ndlp;
4441
4442 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004443 if (!ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05004444 if ((vport->fc_flag & FC_RSCN_MODE) != 0 &&
4445 lpfc_rscn_payload_check(vport, did) == 0)
dea31012005-04-17 16:05:31 -05004446 return NULL;
4447 ndlp = (struct lpfc_nodelist *)
James Smart2e0fef82007-06-17 19:56:36 -05004448 mempool_alloc(vport->phba->nlp_mem_pool, GFP_KERNEL);
dea31012005-04-17 16:05:31 -05004449 if (!ndlp)
4450 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05004451 lpfc_nlp_init(vport, ndlp, did);
4452 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
4453 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004454 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05004455 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004456 return ndlp;
James Smarte47c9092008-02-08 18:49:26 -05004457 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
4458 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_NPR_NODE);
4459 if (!ndlp)
4460 return NULL;
4461 spin_lock_irq(shost->host_lock);
4462 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
4463 spin_unlock_irq(shost->host_lock);
4464 return ndlp;
dea31012005-04-17 16:05:31 -05004465 }
James Smarte47c9092008-02-08 18:49:26 -05004466
James Smart58da1ff2008-04-07 10:15:56 -04004467 if ((vport->fc_flag & FC_RSCN_MODE) &&
4468 !(vport->fc_flag & FC_NDISC_ACTIVE)) {
James Smart2e0fef82007-06-17 19:56:36 -05004469 if (lpfc_rscn_payload_check(vport, did)) {
James Smart87af33f2007-10-27 13:37:43 -04004470 /* If we've already recieved a PLOGI from this NPort
4471 * we don't need to try to discover it again.
4472 */
4473 if (ndlp->nlp_flag & NLP_RCV_PLOGI)
4474 return NULL;
4475
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004476 /* Since this node is marked for discovery,
4477 * delay timeout is not needed.
4478 */
James Smart0d2b6b82008-06-14 22:52:47 -04004479 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smarta257bf92009-04-06 18:48:10 -04004480 spin_lock_irq(shost->host_lock);
4481 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
4482 spin_unlock_irq(shost->host_lock);
James Smart071fbd3d2006-04-15 11:53:20 -04004483 } else
dea31012005-04-17 16:05:31 -05004484 ndlp = NULL;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004485 } else {
James Smart87af33f2007-10-27 13:37:43 -04004486 /* If we've already recieved a PLOGI from this NPort,
4487 * or we are already in the process of discovery on it,
4488 * we don't need to try to discover it again.
4489 */
James Smart685f0bf2007-04-25 09:53:08 -04004490 if (ndlp->nlp_state == NLP_STE_ADISC_ISSUE ||
James Smart87af33f2007-10-27 13:37:43 -04004491 ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
4492 ndlp->nlp_flag & NLP_RCV_PLOGI)
dea31012005-04-17 16:05:31 -05004493 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05004494 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
4495 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004496 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05004497 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004498 }
4499 return ndlp;
4500}
4501
4502/* Build a list of nodes to discover based on the loopmap */
4503void
James Smart2e0fef82007-06-17 19:56:36 -05004504lpfc_disc_list_loopmap(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004505{
James Smart2e0fef82007-06-17 19:56:36 -05004506 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004507 int j;
4508 uint32_t alpa, index;
4509
James Smart2e0fef82007-06-17 19:56:36 -05004510 if (!lpfc_is_link_up(phba))
dea31012005-04-17 16:05:31 -05004511 return;
James Smart2e0fef82007-06-17 19:56:36 -05004512
James Smart76a95d72010-11-20 23:11:48 -05004513 if (phba->fc_topology != LPFC_TOPOLOGY_LOOP)
dea31012005-04-17 16:05:31 -05004514 return;
dea31012005-04-17 16:05:31 -05004515
4516 /* Check for loop map present or not */
4517 if (phba->alpa_map[0]) {
4518 for (j = 1; j <= phba->alpa_map[0]; j++) {
4519 alpa = phba->alpa_map[j];
James Smart2e0fef82007-06-17 19:56:36 -05004520 if (((vport->fc_myDID & 0xff) == alpa) || (alpa == 0))
dea31012005-04-17 16:05:31 -05004521 continue;
James Smart2e0fef82007-06-17 19:56:36 -05004522 lpfc_setup_disc_node(vport, alpa);
dea31012005-04-17 16:05:31 -05004523 }
4524 } else {
4525 /* No alpamap, so try all alpa's */
4526 for (j = 0; j < FC_MAXLOOP; j++) {
4527 /* If cfg_scan_down is set, start from highest
4528 * ALPA (0xef) to lowest (0x1).
4529 */
James Smart3de2a652007-08-02 11:09:59 -04004530 if (vport->cfg_scan_down)
dea31012005-04-17 16:05:31 -05004531 index = j;
4532 else
4533 index = FC_MAXLOOP - j - 1;
4534 alpa = lpfcAlpaArray[index];
James Smart2e0fef82007-06-17 19:56:36 -05004535 if ((vport->fc_myDID & 0xff) == alpa)
dea31012005-04-17 16:05:31 -05004536 continue;
James Smart2e0fef82007-06-17 19:56:36 -05004537 lpfc_setup_disc_node(vport, alpa);
dea31012005-04-17 16:05:31 -05004538 }
4539 }
4540 return;
4541}
4542
dea31012005-04-17 16:05:31 -05004543void
James Smart2e0fef82007-06-17 19:56:36 -05004544lpfc_issue_clear_la(struct lpfc_hba *phba, struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004545{
dea31012005-04-17 16:05:31 -05004546 LPFC_MBOXQ_t *mbox;
James Smart2e0fef82007-06-17 19:56:36 -05004547 struct lpfc_sli *psli = &phba->sli;
4548 struct lpfc_sli_ring *extra_ring = &psli->ring[psli->extra_ring];
4549 struct lpfc_sli_ring *fcp_ring = &psli->ring[psli->fcp_ring];
4550 struct lpfc_sli_ring *next_ring = &psli->ring[psli->next_ring];
4551 int rc;
4552
James Smart92d7f7b2007-06-17 19:56:38 -05004553 /*
4554 * if it's not a physical port or if we already send
4555 * clear_la then don't send it.
4556 */
4557 if ((phba->link_state >= LPFC_CLEAR_LA) ||
James Smartda0436e2009-05-22 14:51:39 -04004558 (vport->port_type != LPFC_PHYSICAL_PORT) ||
4559 (phba->sli_rev == LPFC_SLI_REV4))
James Smart92d7f7b2007-06-17 19:56:38 -05004560 return;
4561
James Smart2e0fef82007-06-17 19:56:36 -05004562 /* Link up discovery */
4563 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL)) != NULL) {
4564 phba->link_state = LPFC_CLEAR_LA;
4565 lpfc_clear_la(phba, mbox);
4566 mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
4567 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -04004568 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart2e0fef82007-06-17 19:56:36 -05004569 if (rc == MBX_NOT_FINISHED) {
4570 mempool_free(mbox, phba->mbox_mem_pool);
4571 lpfc_disc_flush_list(vport);
4572 extra_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
4573 fcp_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
4574 next_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
James Smart92d7f7b2007-06-17 19:56:38 -05004575 phba->link_state = LPFC_HBA_ERROR;
4576 }
4577 }
4578}
4579
4580/* Reg_vpi to tell firmware to resume normal operations */
4581void
4582lpfc_issue_reg_vpi(struct lpfc_hba *phba, struct lpfc_vport *vport)
4583{
4584 LPFC_MBOXQ_t *regvpimbox;
4585
4586 regvpimbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4587 if (regvpimbox) {
James Smartda0436e2009-05-22 14:51:39 -04004588 lpfc_reg_vpi(vport, regvpimbox);
James Smart92d7f7b2007-06-17 19:56:38 -05004589 regvpimbox->mbox_cmpl = lpfc_mbx_cmpl_reg_vpi;
4590 regvpimbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -04004591 if (lpfc_sli_issue_mbox(phba, regvpimbox, MBX_NOWAIT)
James Smart92d7f7b2007-06-17 19:56:38 -05004592 == MBX_NOT_FINISHED) {
4593 mempool_free(regvpimbox, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05004594 }
4595 }
4596}
4597
4598/* Start Link up / RSCN discovery on NPR nodes */
4599void
4600lpfc_disc_start(struct lpfc_vport *vport)
4601{
4602 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4603 struct lpfc_hba *phba = vport->phba;
James Smart685f0bf2007-04-25 09:53:08 -04004604 uint32_t num_sent;
dea31012005-04-17 16:05:31 -05004605 uint32_t clear_la_pending;
James Smart685f0bf2007-04-25 09:53:08 -04004606 int did_changed;
dea31012005-04-17 16:05:31 -05004607
James Smart2e0fef82007-06-17 19:56:36 -05004608 if (!lpfc_is_link_up(phba))
dea31012005-04-17 16:05:31 -05004609 return;
James Smart2e0fef82007-06-17 19:56:36 -05004610
4611 if (phba->link_state == LPFC_CLEAR_LA)
dea31012005-04-17 16:05:31 -05004612 clear_la_pending = 1;
4613 else
4614 clear_la_pending = 0;
4615
James Smart2e0fef82007-06-17 19:56:36 -05004616 if (vport->port_state < LPFC_VPORT_READY)
4617 vport->port_state = LPFC_DISC_AUTH;
dea31012005-04-17 16:05:31 -05004618
James Smart2e0fef82007-06-17 19:56:36 -05004619 lpfc_set_disctmo(vport);
4620
4621 if (vport->fc_prevDID == vport->fc_myDID)
dea31012005-04-17 16:05:31 -05004622 did_changed = 0;
James Smart2e0fef82007-06-17 19:56:36 -05004623 else
dea31012005-04-17 16:05:31 -05004624 did_changed = 1;
James Smart2e0fef82007-06-17 19:56:36 -05004625
4626 vport->fc_prevDID = vport->fc_myDID;
4627 vport->num_disc_nodes = 0;
dea31012005-04-17 16:05:31 -05004628
4629 /* Start Discovery state <hba_state> */
James Smarte8b62012007-08-02 11:10:09 -04004630 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4631 "0202 Start Discovery hba state x%x "
4632 "Data: x%x x%x x%x\n",
4633 vport->port_state, vport->fc_flag, vport->fc_plogi_cnt,
4634 vport->fc_adisc_cnt);
dea31012005-04-17 16:05:31 -05004635
4636 /* First do ADISCs - if any */
James Smart2e0fef82007-06-17 19:56:36 -05004637 num_sent = lpfc_els_disc_adisc(vport);
dea31012005-04-17 16:05:31 -05004638
4639 if (num_sent)
4640 return;
4641
James Smart92d7f7b2007-06-17 19:56:38 -05004642 /*
4643 * For SLI3, cmpl_reg_vpi will set port_state to READY, and
4644 * continue discovery.
4645 */
4646 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart1b32f6a2008-02-08 18:49:39 -05004647 !(vport->fc_flag & FC_PT2PT) &&
James Smartda0436e2009-05-22 14:51:39 -04004648 !(vport->fc_flag & FC_RSCN_MODE) &&
4649 (phba->sli_rev < LPFC_SLI_REV4)) {
James Smart92d7f7b2007-06-17 19:56:38 -05004650 lpfc_issue_reg_vpi(phba, vport);
4651 return;
4652 }
James Smart2e0fef82007-06-17 19:56:36 -05004653
James Smart92d7f7b2007-06-17 19:56:38 -05004654 /*
4655 * For SLI2, we need to set port_state to READY and continue
4656 * discovery.
4657 */
4658 if (vport->port_state < LPFC_VPORT_READY && !clear_la_pending) {
4659 /* If we get here, there is nothing to ADISC */
4660 if (vport->port_type == LPFC_PHYSICAL_PORT)
4661 lpfc_issue_clear_la(phba, vport);
4662
4663 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
James Smart2e0fef82007-06-17 19:56:36 -05004664 vport->num_disc_nodes = 0;
4665 /* go thru NPR nodes and issue ELS PLOGIs */
4666 if (vport->fc_npr_cnt)
4667 lpfc_els_disc_plogi(vport);
4668
4669 if (!vport->num_disc_nodes) {
4670 spin_lock_irq(shost->host_lock);
4671 vport->fc_flag &= ~FC_NDISC_ACTIVE;
4672 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004673 lpfc_can_disctmo(vport);
dea31012005-04-17 16:05:31 -05004674 }
4675 }
James Smart92d7f7b2007-06-17 19:56:38 -05004676 vport->port_state = LPFC_VPORT_READY;
dea31012005-04-17 16:05:31 -05004677 } else {
4678 /* Next do PLOGIs - if any */
James Smart2e0fef82007-06-17 19:56:36 -05004679 num_sent = lpfc_els_disc_plogi(vport);
dea31012005-04-17 16:05:31 -05004680
4681 if (num_sent)
4682 return;
4683
James Smart2e0fef82007-06-17 19:56:36 -05004684 if (vport->fc_flag & FC_RSCN_MODE) {
dea31012005-04-17 16:05:31 -05004685 /* Check to see if more RSCNs came in while we
4686 * were processing this one.
4687 */
James Smart2e0fef82007-06-17 19:56:36 -05004688 if ((vport->fc_rscn_id_cnt == 0) &&
4689 (!(vport->fc_flag & FC_RSCN_DISCOVERY))) {
4690 spin_lock_irq(shost->host_lock);
4691 vport->fc_flag &= ~FC_RSCN_MODE;
4692 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004693 lpfc_can_disctmo(vport);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004694 } else
James Smart2e0fef82007-06-17 19:56:36 -05004695 lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05004696 }
4697 }
4698 return;
4699}
4700
4701/*
4702 * Ignore completion for all IOCBs on tx and txcmpl queue for ELS
4703 * ring the match the sppecified nodelist.
4704 */
4705static void
James Smart2e0fef82007-06-17 19:56:36 -05004706lpfc_free_tx(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004707{
James Smart2534ba72007-04-25 09:52:20 -04004708 LIST_HEAD(completions);
dea31012005-04-17 16:05:31 -05004709 struct lpfc_sli *psli;
4710 IOCB_t *icmd;
4711 struct lpfc_iocbq *iocb, *next_iocb;
4712 struct lpfc_sli_ring *pring;
dea31012005-04-17 16:05:31 -05004713
4714 psli = &phba->sli;
4715 pring = &psli->ring[LPFC_ELS_RING];
4716
4717 /* Error matching iocb on txq or txcmplq
4718 * First check the txq.
4719 */
James Smart2e0fef82007-06-17 19:56:36 -05004720 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004721 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
4722 if (iocb->context1 != ndlp) {
4723 continue;
4724 }
4725 icmd = &iocb->iocb;
4726 if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
4727 (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
4728
James Smart2534ba72007-04-25 09:52:20 -04004729 list_move_tail(&iocb->list, &completions);
dea31012005-04-17 16:05:31 -05004730 pring->txq_cnt--;
dea31012005-04-17 16:05:31 -05004731 }
4732 }
4733
4734 /* Next check the txcmplq */
4735 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
4736 if (iocb->context1 != ndlp) {
4737 continue;
4738 }
4739 icmd = &iocb->iocb;
James Smart2e0fef82007-06-17 19:56:36 -05004740 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR ||
4741 icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX) {
James Smart2534ba72007-04-25 09:52:20 -04004742 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
dea31012005-04-17 16:05:31 -05004743 }
4744 }
James Smart2e0fef82007-06-17 19:56:36 -05004745 spin_unlock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04004746
James Smarta257bf92009-04-06 18:48:10 -04004747 /* Cancel all the IOCBs from the completions list */
4748 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
4749 IOERR_SLI_ABORTED);
dea31012005-04-17 16:05:31 -05004750}
4751
Adrian Bunka6ababd2007-11-05 18:07:33 +01004752static void
James Smart2e0fef82007-06-17 19:56:36 -05004753lpfc_disc_flush_list(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004754{
4755 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004756 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004757
James Smart2e0fef82007-06-17 19:56:36 -05004758 if (vport->fc_plogi_cnt || vport->fc_adisc_cnt) {
4759 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
James Smart685f0bf2007-04-25 09:53:08 -04004760 nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004761 if (!NLP_CHK_NODE_ACT(ndlp))
4762 continue;
James Smart685f0bf2007-04-25 09:53:08 -04004763 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
4764 ndlp->nlp_state == NLP_STE_ADISC_ISSUE) {
4765 lpfc_free_tx(phba, ndlp);
James Smart685f0bf2007-04-25 09:53:08 -04004766 }
dea31012005-04-17 16:05:31 -05004767 }
4768 }
dea31012005-04-17 16:05:31 -05004769}
4770
James Smart92d7f7b2007-06-17 19:56:38 -05004771void
4772lpfc_cleanup_discovery_resources(struct lpfc_vport *vport)
4773{
4774 lpfc_els_flush_rscn(vport);
4775 lpfc_els_flush_cmd(vport);
4776 lpfc_disc_flush_list(vport);
4777}
4778
dea31012005-04-17 16:05:31 -05004779/*****************************************************************************/
4780/*
4781 * NAME: lpfc_disc_timeout
4782 *
4783 * FUNCTION: Fibre Channel driver discovery timeout routine.
4784 *
4785 * EXECUTION ENVIRONMENT: interrupt only
4786 *
4787 * CALLED FROM:
4788 * Timer function
4789 *
4790 * RETURNS:
4791 * none
4792 */
4793/*****************************************************************************/
4794void
4795lpfc_disc_timeout(unsigned long ptr)
4796{
James Smart2e0fef82007-06-17 19:56:36 -05004797 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
4798 struct lpfc_hba *phba = vport->phba;
James Smart5e9d9b82008-06-14 22:52:53 -04004799 uint32_t tmo_posted;
dea31012005-04-17 16:05:31 -05004800 unsigned long flags = 0;
4801
4802 if (unlikely(!phba))
4803 return;
4804
James Smart5e9d9b82008-06-14 22:52:53 -04004805 spin_lock_irqsave(&vport->work_port_lock, flags);
4806 tmo_posted = vport->work_port_events & WORKER_DISC_TMO;
4807 if (!tmo_posted)
James Smart2e0fef82007-06-17 19:56:36 -05004808 vport->work_port_events |= WORKER_DISC_TMO;
James Smart5e9d9b82008-06-14 22:52:53 -04004809 spin_unlock_irqrestore(&vport->work_port_lock, flags);
James Smart2e0fef82007-06-17 19:56:36 -05004810
James Smart5e9d9b82008-06-14 22:52:53 -04004811 if (!tmo_posted)
4812 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05004813 return;
4814}
4815
4816static void
James Smart2e0fef82007-06-17 19:56:36 -05004817lpfc_disc_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004818{
James Smart2e0fef82007-06-17 19:56:36 -05004819 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4820 struct lpfc_hba *phba = vport->phba;
4821 struct lpfc_sli *psli = &phba->sli;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004822 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart92d7f7b2007-06-17 19:56:38 -05004823 LPFC_MBOXQ_t *initlinkmbox;
dea31012005-04-17 16:05:31 -05004824 int rc, clrlaerr = 0;
4825
James Smart2e0fef82007-06-17 19:56:36 -05004826 if (!(vport->fc_flag & FC_DISC_TMO))
dea31012005-04-17 16:05:31 -05004827 return;
4828
James Smart2e0fef82007-06-17 19:56:36 -05004829 spin_lock_irq(shost->host_lock);
4830 vport->fc_flag &= ~FC_DISC_TMO;
4831 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004832
James Smart858c9f62007-06-17 19:56:39 -05004833 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4834 "disc timeout: state:x%x rtry:x%x flg:x%x",
4835 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
4836
James Smart2e0fef82007-06-17 19:56:36 -05004837 switch (vport->port_state) {
dea31012005-04-17 16:05:31 -05004838
4839 case LPFC_LOCAL_CFG_LINK:
James Smart2e0fef82007-06-17 19:56:36 -05004840 /* port_state is identically LPFC_LOCAL_CFG_LINK while waiting for
4841 * FAN
4842 */
4843 /* FAN timeout */
James Smarte8b62012007-08-02 11:10:09 -04004844 lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY,
4845 "0221 FAN timeout\n");
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004846 /* Start discovery by sending FLOGI, clean up old rpis */
James Smart2e0fef82007-06-17 19:56:36 -05004847 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
James Smart685f0bf2007-04-25 09:53:08 -04004848 nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004849 if (!NLP_CHK_NODE_ACT(ndlp))
4850 continue;
James Smart685f0bf2007-04-25 09:53:08 -04004851 if (ndlp->nlp_state != NLP_STE_NPR_NODE)
4852 continue;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004853 if (ndlp->nlp_type & NLP_FABRIC) {
4854 /* Clean up the ndlp on Fabric connections */
James Smart2e0fef82007-06-17 19:56:36 -05004855 lpfc_drop_node(vport, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04004856
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004857 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004858 /* Fail outstanding IO now since device
4859 * is marked for PLOGI.
4860 */
James Smart2e0fef82007-06-17 19:56:36 -05004861 lpfc_unreg_rpi(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004862 }
4863 }
James Smart92d7f7b2007-06-17 19:56:38 -05004864 if (vport->port_state != LPFC_FLOGI) {
James Smart76a95d72010-11-20 23:11:48 -05004865 if (phba->sli_rev <= LPFC_SLI_REV3)
4866 lpfc_initial_flogi(vport);
4867 else
4868 lpfc_issue_init_vfi(vport);
James Smart0ff10d42008-01-11 01:52:36 -05004869 return;
James Smart92d7f7b2007-06-17 19:56:38 -05004870 }
dea31012005-04-17 16:05:31 -05004871 break;
4872
James Smart92d7f7b2007-06-17 19:56:38 -05004873 case LPFC_FDISC:
dea31012005-04-17 16:05:31 -05004874 case LPFC_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05004875 /* port_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */
dea31012005-04-17 16:05:31 -05004876 /* Initial FLOGI timeout */
James Smarte8b62012007-08-02 11:10:09 -04004877 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
4878 "0222 Initial %s timeout\n",
James Smart87af33f2007-10-27 13:37:43 -04004879 vport->vpi ? "FDISC" : "FLOGI");
dea31012005-04-17 16:05:31 -05004880
4881 /* Assume no Fabric and go on with discovery.
4882 * Check for outstanding ELS FLOGI to abort.
4883 */
4884
4885 /* FLOGI failed, so just use loop map to make discovery list */
James Smart2e0fef82007-06-17 19:56:36 -05004886 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -05004887
4888 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -05004889 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -05004890 break;
4891
4892 case LPFC_FABRIC_CFG_LINK:
4893 /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for
4894 NameServer login */
James Smarte8b62012007-08-02 11:10:09 -04004895 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
4896 "0223 Timeout while waiting for "
4897 "NameServer login\n");
dea31012005-04-17 16:05:31 -05004898 /* Next look for NameServer ndlp */
James Smart2e0fef82007-06-17 19:56:36 -05004899 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004900 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart87af33f2007-10-27 13:37:43 -04004901 lpfc_els_abort(phba, ndlp);
4902
4903 /* ReStart discovery */
4904 goto restart_disc;
dea31012005-04-17 16:05:31 -05004905
4906 case LPFC_NS_QRY:
4907 /* Check for wait for NameServer Rsp timeout */
James Smarte8b62012007-08-02 11:10:09 -04004908 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
4909 "0224 NameServer Query timeout "
4910 "Data: x%x x%x\n",
4911 vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
dea31012005-04-17 16:05:31 -05004912
James Smart92d7f7b2007-06-17 19:56:38 -05004913 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
4914 /* Try it one more time */
4915 vport->fc_ns_retry++;
4916 rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT,
4917 vport->fc_ns_retry, 0);
4918 if (rc == 0)
4919 break;
dea31012005-04-17 16:05:31 -05004920 }
James Smart92d7f7b2007-06-17 19:56:38 -05004921 vport->fc_ns_retry = 0;
dea31012005-04-17 16:05:31 -05004922
James Smart87af33f2007-10-27 13:37:43 -04004923restart_disc:
James Smart92d7f7b2007-06-17 19:56:38 -05004924 /*
4925 * Discovery is over.
4926 * set port_state to PORT_READY if SLI2.
4927 * cmpl_reg_vpi will set port_state to READY for SLI3.
4928 */
James Smart3772a992009-05-22 14:50:54 -04004929 if (phba->sli_rev < LPFC_SLI_REV4) {
4930 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
4931 lpfc_issue_reg_vpi(phba, vport);
4932 else { /* NPIV Not enabled */
4933 lpfc_issue_clear_la(phba, vport);
4934 vport->port_state = LPFC_VPORT_READY;
4935 }
dea31012005-04-17 16:05:31 -05004936 }
4937
4938 /* Setup and issue mailbox INITIALIZE LINK command */
4939 initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4940 if (!initlinkmbox) {
James Smarte8b62012007-08-02 11:10:09 -04004941 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
4942 "0206 Device Discovery "
4943 "completion error\n");
James Smart2e0fef82007-06-17 19:56:36 -05004944 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05004945 break;
4946 }
4947
4948 lpfc_linkdown(phba);
4949 lpfc_init_link(phba, initlinkmbox, phba->cfg_topology,
4950 phba->cfg_link_speed);
James Smart04c68492009-05-22 14:52:52 -04004951 initlinkmbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
James Smarted957682007-06-17 19:56:37 -05004952 initlinkmbox->vport = vport;
James Smart92d7f7b2007-06-17 19:56:38 -05004953 initlinkmbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart0b727fe2007-10-27 13:37:25 -04004954 rc = lpfc_sli_issue_mbox(phba, initlinkmbox, MBX_NOWAIT);
James Smart5b8bd0c2007-04-25 09:52:49 -04004955 lpfc_set_loopback_flag(phba);
dea31012005-04-17 16:05:31 -05004956 if (rc == MBX_NOT_FINISHED)
4957 mempool_free(initlinkmbox, phba->mbox_mem_pool);
4958
4959 break;
4960
4961 case LPFC_DISC_AUTH:
4962 /* Node Authentication timeout */
James Smarte8b62012007-08-02 11:10:09 -04004963 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
4964 "0227 Node Authentication timeout\n");
James Smart2e0fef82007-06-17 19:56:36 -05004965 lpfc_disc_flush_list(vport);
4966
James Smart92d7f7b2007-06-17 19:56:38 -05004967 /*
4968 * set port_state to PORT_READY if SLI2.
4969 * cmpl_reg_vpi will set port_state to READY for SLI3.
4970 */
James Smart3772a992009-05-22 14:50:54 -04004971 if (phba->sli_rev < LPFC_SLI_REV4) {
4972 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
4973 lpfc_issue_reg_vpi(phba, vport);
4974 else { /* NPIV Not enabled */
4975 lpfc_issue_clear_la(phba, vport);
4976 vport->port_state = LPFC_VPORT_READY;
4977 }
dea31012005-04-17 16:05:31 -05004978 }
4979 break;
4980
James Smart2e0fef82007-06-17 19:56:36 -05004981 case LPFC_VPORT_READY:
4982 if (vport->fc_flag & FC_RSCN_MODE) {
James Smarte8b62012007-08-02 11:10:09 -04004983 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
4984 "0231 RSCN timeout Data: x%x "
4985 "x%x\n",
4986 vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
dea31012005-04-17 16:05:31 -05004987
4988 /* Cleanup any outstanding ELS commands */
James Smart2e0fef82007-06-17 19:56:36 -05004989 lpfc_els_flush_cmd(vport);
dea31012005-04-17 16:05:31 -05004990
James Smart2e0fef82007-06-17 19:56:36 -05004991 lpfc_els_flush_rscn(vport);
4992 lpfc_disc_flush_list(vport);
dea31012005-04-17 16:05:31 -05004993 }
4994 break;
James Smart2e0fef82007-06-17 19:56:36 -05004995
James Smart92d7f7b2007-06-17 19:56:38 -05004996 default:
James Smarte8b62012007-08-02 11:10:09 -04004997 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -04004998 "0273 Unexpected discovery timeout, "
James Smarte8b62012007-08-02 11:10:09 -04004999 "vport State x%x\n", vport->port_state);
James Smart2e0fef82007-06-17 19:56:36 -05005000 break;
5001 }
5002
5003 switch (phba->link_state) {
5004 case LPFC_CLEAR_LA:
James Smart92d7f7b2007-06-17 19:56:38 -05005005 /* CLEAR LA timeout */
James Smarte8b62012007-08-02 11:10:09 -04005006 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5007 "0228 CLEAR LA timeout\n");
James Smart2e0fef82007-06-17 19:56:36 -05005008 clrlaerr = 1;
5009 break;
5010
James Smart09372822008-01-11 01:52:54 -05005011 case LPFC_LINK_UP:
5012 lpfc_issue_clear_la(phba, vport);
5013 /* Drop thru */
James Smart2e0fef82007-06-17 19:56:36 -05005014 case LPFC_LINK_UNKNOWN:
5015 case LPFC_WARM_START:
5016 case LPFC_INIT_START:
5017 case LPFC_INIT_MBX_CMDS:
5018 case LPFC_LINK_DOWN:
James Smart2e0fef82007-06-17 19:56:36 -05005019 case LPFC_HBA_ERROR:
James Smarte8b62012007-08-02 11:10:09 -04005020 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
5021 "0230 Unexpected timeout, hba link "
5022 "state x%x\n", phba->link_state);
James Smart2e0fef82007-06-17 19:56:36 -05005023 clrlaerr = 1;
5024 break;
James Smart92d7f7b2007-06-17 19:56:38 -05005025
5026 case LPFC_HBA_READY:
5027 break;
dea31012005-04-17 16:05:31 -05005028 }
5029
5030 if (clrlaerr) {
James Smart2e0fef82007-06-17 19:56:36 -05005031 lpfc_disc_flush_list(vport);
James Smarta4bc3372006-12-02 13:34:16 -05005032 psli->ring[(psli->extra_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
dea31012005-04-17 16:05:31 -05005033 psli->ring[(psli->fcp_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
5034 psli->ring[(psli->next_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
James Smart2e0fef82007-06-17 19:56:36 -05005035 vport->port_state = LPFC_VPORT_READY;
dea31012005-04-17 16:05:31 -05005036 }
5037
5038 return;
5039}
5040
dea31012005-04-17 16:05:31 -05005041/*
5042 * This routine handles processing a NameServer REG_LOGIN mailbox
5043 * command upon completion. It is setup in the LPFC_MBOXQ
5044 * as the completion routine when the command is
5045 * handed off to the SLI layer.
5046 */
5047void
James Smart2e0fef82007-06-17 19:56:36 -05005048lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05005049{
James Smart04c68492009-05-22 14:52:52 -04005050 MAILBOX_t *mb = &pmb->u.mb;
James Smart2e0fef82007-06-17 19:56:36 -05005051 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
5052 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
5053 struct lpfc_vport *vport = pmb->vport;
dea31012005-04-17 16:05:31 -05005054
5055 pmb->context1 = NULL;
James Smartd439d282010-09-29 11:18:45 -04005056 pmb->context2 = NULL;
dea31012005-04-17 16:05:31 -05005057
dea31012005-04-17 16:05:31 -05005058 ndlp->nlp_rpi = mb->un.varWords[0];
James Smart21e9a0a2009-05-22 14:53:21 -04005059 ndlp->nlp_flag |= NLP_RPI_VALID;
dea31012005-04-17 16:05:31 -05005060 ndlp->nlp_type |= NLP_FABRIC;
James Smart2e0fef82007-06-17 19:56:36 -05005061 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
dea31012005-04-17 16:05:31 -05005062
James Smart2e0fef82007-06-17 19:56:36 -05005063 /*
5064 * Start issuing Fabric-Device Management Interface (FDMI) command to
5065 * 0xfffffa (FDMI well known port) or Delay issuing FDMI command if
5066 * fdmi-on=2 (supporting RPA/hostnmae)
dea31012005-04-17 16:05:31 -05005067 */
James Smart2e0fef82007-06-17 19:56:36 -05005068
James Smart3de2a652007-08-02 11:09:59 -04005069 if (vport->cfg_fdmi_on == 1)
James Smart2e0fef82007-06-17 19:56:36 -05005070 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA);
5071 else
5072 mod_timer(&vport->fc_fdmitmo, jiffies + HZ * 60);
dea31012005-04-17 16:05:31 -05005073
James Smartfa4066b2008-01-11 01:53:27 -05005074 /* decrement the node reference count held for this callback
5075 * function.
5076 */
James Smart329f9bc2007-04-25 09:53:01 -04005077 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05005078 lpfc_mbuf_free(phba, mp->virt, mp->phys);
5079 kfree(mp);
James Smart329f9bc2007-04-25 09:53:01 -04005080 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05005081
5082 return;
5083}
5084
James Smart685f0bf2007-04-25 09:53:08 -04005085static int
5086lpfc_filter_by_rpi(struct lpfc_nodelist *ndlp, void *param)
5087{
5088 uint16_t *rpi = param;
5089
5090 return ndlp->nlp_rpi == *rpi;
5091}
5092
5093static int
5094lpfc_filter_by_wwpn(struct lpfc_nodelist *ndlp, void *param)
5095{
5096 return memcmp(&ndlp->nlp_portname, param,
5097 sizeof(ndlp->nlp_portname)) == 0;
5098}
5099
Adrian Bunka6ababd2007-11-05 18:07:33 +01005100static struct lpfc_nodelist *
James Smart2e0fef82007-06-17 19:56:36 -05005101__lpfc_find_node(struct lpfc_vport *vport, node_filter filter, void *param)
dea31012005-04-17 16:05:31 -05005102{
James.Smart@Emulex.Com21568f52005-10-28 20:29:36 -04005103 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05005104
James Smart2e0fef82007-06-17 19:56:36 -05005105 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smart87af33f2007-10-27 13:37:43 -04005106 if (filter(ndlp, param))
James Smart685f0bf2007-04-25 09:53:08 -04005107 return ndlp;
5108 }
James.Smart@Emulex.Com21568f52005-10-28 20:29:36 -04005109 return NULL;
dea31012005-04-17 16:05:31 -05005110}
5111
James Smart685f0bf2007-04-25 09:53:08 -04005112/*
5113 * This routine looks up the ndlp lists for the given RPI. If rpi found it
James Smart2e0fef82007-06-17 19:56:36 -05005114 * returns the node list element pointer else return NULL.
James Smart685f0bf2007-04-25 09:53:08 -04005115 */
5116struct lpfc_nodelist *
James Smart2e0fef82007-06-17 19:56:36 -05005117__lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi)
James Smart685f0bf2007-04-25 09:53:08 -04005118{
James Smart2e0fef82007-06-17 19:56:36 -05005119 return __lpfc_find_node(vport, lpfc_filter_by_rpi, &rpi);
James Smart685f0bf2007-04-25 09:53:08 -04005120}
5121
James Smart488d1462006-03-07 15:02:37 -05005122/*
James Smart685f0bf2007-04-25 09:53:08 -04005123 * This routine looks up the ndlp lists for the given WWPN. If WWPN found it
James Smart2e0fef82007-06-17 19:56:36 -05005124 * returns the node element list pointer else return NULL.
James Smart488d1462006-03-07 15:02:37 -05005125 */
5126struct lpfc_nodelist *
James Smart2e0fef82007-06-17 19:56:36 -05005127lpfc_findnode_wwpn(struct lpfc_vport *vport, struct lpfc_name *wwpn)
James Smart488d1462006-03-07 15:02:37 -05005128{
James Smart2e0fef82007-06-17 19:56:36 -05005129 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart488d1462006-03-07 15:02:37 -05005130 struct lpfc_nodelist *ndlp;
James Smart488d1462006-03-07 15:02:37 -05005131
James Smart2e0fef82007-06-17 19:56:36 -05005132 spin_lock_irq(shost->host_lock);
5133 ndlp = __lpfc_find_node(vport, lpfc_filter_by_wwpn, wwpn);
5134 spin_unlock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05005135 return ndlp;
James Smart488d1462006-03-07 15:02:37 -05005136}
5137
dea31012005-04-17 16:05:31 -05005138void
James Smart2e0fef82007-06-17 19:56:36 -05005139lpfc_nlp_init(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
5140 uint32_t did)
dea31012005-04-17 16:05:31 -05005141{
5142 memset(ndlp, 0, sizeof (struct lpfc_nodelist));
James Smart109f6ed2008-12-04 22:39:08 -05005143
5144 lpfc_initialize_node(vport, ndlp, did);
James Smart685f0bf2007-04-25 09:53:08 -04005145 INIT_LIST_HEAD(&ndlp->nlp_listp);
James Smart858c9f62007-06-17 19:56:39 -05005146
5147 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
5148 "node init: did:x%x",
5149 ndlp->nlp_DID, 0, 0);
5150
dea31012005-04-17 16:05:31 -05005151 return;
5152}
James Smart329f9bc2007-04-25 09:53:01 -04005153
James Smart98c9ea52007-10-27 13:37:33 -04005154/* This routine releases all resources associated with a specifc NPort's ndlp
5155 * and mempool_free's the nodelist.
5156 */
James Smart311464e2007-08-02 11:10:37 -04005157static void
James Smart329f9bc2007-04-25 09:53:01 -04005158lpfc_nlp_release(struct kref *kref)
5159{
James Smarte47c9092008-02-08 18:49:26 -05005160 struct lpfc_hba *phba;
5161 unsigned long flags;
James Smart329f9bc2007-04-25 09:53:01 -04005162 struct lpfc_nodelist *ndlp = container_of(kref, struct lpfc_nodelist,
5163 kref);
James Smart858c9f62007-06-17 19:56:39 -05005164
5165 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
5166 "node release: did:x%x flg:x%x type:x%x",
5167 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
5168
James Smarte47c9092008-02-08 18:49:26 -05005169 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
5170 "0279 lpfc_nlp_release: ndlp:x%p "
5171 "usgmap:x%x refcnt:%d\n",
5172 (void *)ndlp, ndlp->nlp_usg_map,
5173 atomic_read(&ndlp->kref.refcount));
5174
5175 /* remove ndlp from action. */
James Smart2e0fef82007-06-17 19:56:36 -05005176 lpfc_nlp_remove(ndlp->vport, ndlp);
James Smarte47c9092008-02-08 18:49:26 -05005177
5178 /* clear the ndlp active flag for all release cases */
James Smarta257bf92009-04-06 18:48:10 -04005179 phba = ndlp->phba;
James Smarte47c9092008-02-08 18:49:26 -05005180 spin_lock_irqsave(&phba->ndlp_lock, flags);
5181 NLP_CLR_NODE_ACT(ndlp);
5182 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
5183
5184 /* free ndlp memory for final ndlp release */
James Smartea2151b2008-09-07 11:52:10 -04005185 if (NLP_CHK_FREE_REQ(ndlp)) {
5186 kfree(ndlp->lat_data);
James Smarta257bf92009-04-06 18:48:10 -04005187 mempool_free(ndlp, ndlp->phba->nlp_mem_pool);
James Smartea2151b2008-09-07 11:52:10 -04005188 }
James Smart329f9bc2007-04-25 09:53:01 -04005189}
5190
James Smart98c9ea52007-10-27 13:37:33 -04005191/* This routine bumps the reference count for a ndlp structure to ensure
5192 * that one discovery thread won't free a ndlp while another discovery thread
5193 * is using it.
5194 */
James Smart329f9bc2007-04-25 09:53:01 -04005195struct lpfc_nodelist *
5196lpfc_nlp_get(struct lpfc_nodelist *ndlp)
5197{
James Smarte47c9092008-02-08 18:49:26 -05005198 struct lpfc_hba *phba;
5199 unsigned long flags;
5200
James Smart98c9ea52007-10-27 13:37:33 -04005201 if (ndlp) {
5202 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
5203 "node get: did:x%x flg:x%x refcnt:x%x",
5204 ndlp->nlp_DID, ndlp->nlp_flag,
5205 atomic_read(&ndlp->kref.refcount));
James Smarte47c9092008-02-08 18:49:26 -05005206 /* The check of ndlp usage to prevent incrementing the
5207 * ndlp reference count that is in the process of being
5208 * released.
5209 */
James Smarta257bf92009-04-06 18:48:10 -04005210 phba = ndlp->phba;
James Smarte47c9092008-02-08 18:49:26 -05005211 spin_lock_irqsave(&phba->ndlp_lock, flags);
5212 if (!NLP_CHK_NODE_ACT(ndlp) || NLP_CHK_FREE_ACK(ndlp)) {
5213 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
5214 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
5215 "0276 lpfc_nlp_get: ndlp:x%p "
5216 "usgmap:x%x refcnt:%d\n",
5217 (void *)ndlp, ndlp->nlp_usg_map,
5218 atomic_read(&ndlp->kref.refcount));
5219 return NULL;
5220 } else
5221 kref_get(&ndlp->kref);
5222 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
James Smart98c9ea52007-10-27 13:37:33 -04005223 }
James Smart329f9bc2007-04-25 09:53:01 -04005224 return ndlp;
5225}
5226
James Smart98c9ea52007-10-27 13:37:33 -04005227/* This routine decrements the reference count for a ndlp structure. If the
James Smarte47c9092008-02-08 18:49:26 -05005228 * count goes to 0, this indicates the the associated nodelist should be
5229 * freed. Returning 1 indicates the ndlp resource has been released; on the
5230 * other hand, returning 0 indicates the ndlp resource has not been released
5231 * yet.
James Smart98c9ea52007-10-27 13:37:33 -04005232 */
James Smart329f9bc2007-04-25 09:53:01 -04005233int
5234lpfc_nlp_put(struct lpfc_nodelist *ndlp)
5235{
James Smarte47c9092008-02-08 18:49:26 -05005236 struct lpfc_hba *phba;
5237 unsigned long flags;
5238
5239 if (!ndlp)
5240 return 1;
5241
5242 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
5243 "node put: did:x%x flg:x%x refcnt:x%x",
5244 ndlp->nlp_DID, ndlp->nlp_flag,
5245 atomic_read(&ndlp->kref.refcount));
James Smarta257bf92009-04-06 18:48:10 -04005246 phba = ndlp->phba;
James Smarte47c9092008-02-08 18:49:26 -05005247 spin_lock_irqsave(&phba->ndlp_lock, flags);
5248 /* Check the ndlp memory free acknowledge flag to avoid the
5249 * possible race condition that kref_put got invoked again
5250 * after previous one has done ndlp memory free.
5251 */
5252 if (NLP_CHK_FREE_ACK(ndlp)) {
5253 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
5254 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
5255 "0274 lpfc_nlp_put: ndlp:x%p "
5256 "usgmap:x%x refcnt:%d\n",
5257 (void *)ndlp, ndlp->nlp_usg_map,
5258 atomic_read(&ndlp->kref.refcount));
5259 return 1;
James Smart98c9ea52007-10-27 13:37:33 -04005260 }
James Smarte47c9092008-02-08 18:49:26 -05005261 /* Check the ndlp inactivate log flag to avoid the possible
5262 * race condition that kref_put got invoked again after ndlp
5263 * is already in inactivating state.
5264 */
5265 if (NLP_CHK_IACT_REQ(ndlp)) {
5266 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
5267 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
5268 "0275 lpfc_nlp_put: ndlp:x%p "
5269 "usgmap:x%x refcnt:%d\n",
5270 (void *)ndlp, ndlp->nlp_usg_map,
5271 atomic_read(&ndlp->kref.refcount));
5272 return 1;
5273 }
5274 /* For last put, mark the ndlp usage flags to make sure no
5275 * other kref_get and kref_put on the same ndlp shall get
5276 * in between the process when the final kref_put has been
5277 * invoked on this ndlp.
5278 */
5279 if (atomic_read(&ndlp->kref.refcount) == 1) {
5280 /* Indicate ndlp is put to inactive state. */
5281 NLP_SET_IACT_REQ(ndlp);
5282 /* Acknowledge ndlp memory free has been seen. */
5283 if (NLP_CHK_FREE_REQ(ndlp))
5284 NLP_SET_FREE_ACK(ndlp);
5285 }
5286 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
5287 /* Note, the kref_put returns 1 when decrementing a reference
5288 * count that was 1, it invokes the release callback function,
5289 * but it still left the reference count as 1 (not actually
5290 * performs the last decrementation). Otherwise, it actually
5291 * decrements the reference count and returns 0.
5292 */
5293 return kref_put(&ndlp->kref, lpfc_nlp_release);
James Smart329f9bc2007-04-25 09:53:01 -04005294}
James Smart98c9ea52007-10-27 13:37:33 -04005295
5296/* This routine free's the specified nodelist if it is not in use
James Smarte47c9092008-02-08 18:49:26 -05005297 * by any other discovery thread. This routine returns 1 if the
5298 * ndlp has been freed. A return value of 0 indicates the ndlp is
5299 * not yet been released.
James Smart98c9ea52007-10-27 13:37:33 -04005300 */
5301int
5302lpfc_nlp_not_used(struct lpfc_nodelist *ndlp)
5303{
5304 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
5305 "node not used: did:x%x flg:x%x refcnt:x%x",
5306 ndlp->nlp_DID, ndlp->nlp_flag,
5307 atomic_read(&ndlp->kref.refcount));
James Smarte47c9092008-02-08 18:49:26 -05005308 if (atomic_read(&ndlp->kref.refcount) == 1)
5309 if (lpfc_nlp_put(ndlp))
5310 return 1;
James Smart98c9ea52007-10-27 13:37:33 -04005311 return 0;
5312}
James Smart6fb120a2009-05-22 14:52:59 -04005313
5314/**
5315 * lpfc_fcf_inuse - Check if FCF can be unregistered.
5316 * @phba: Pointer to hba context object.
5317 *
5318 * This function iterate through all FC nodes associated
5319 * will all vports to check if there is any node with
5320 * fc_rports associated with it. If there is an fc_rport
5321 * associated with the node, then the node is either in
5322 * discovered state or its devloss_timer is pending.
5323 */
5324static int
5325lpfc_fcf_inuse(struct lpfc_hba *phba)
5326{
5327 struct lpfc_vport **vports;
5328 int i, ret = 0;
5329 struct lpfc_nodelist *ndlp;
5330 struct Scsi_Host *shost;
5331
5332 vports = lpfc_create_vport_work_array(phba);
5333
James Smart63e801c2010-11-20 23:14:19 -05005334 /* If driver cannot allocate memory, indicate fcf is in use */
5335 if (!vports)
5336 return 1;
5337
James Smart6fb120a2009-05-22 14:52:59 -04005338 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
5339 shost = lpfc_shost_from_vport(vports[i]);
5340 spin_lock_irq(shost->host_lock);
5341 list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) {
5342 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport &&
5343 (ndlp->rport->roles & FC_RPORT_ROLE_FCP_TARGET)) {
5344 ret = 1;
5345 spin_unlock_irq(shost->host_lock);
5346 goto out;
James Smart891478a2009-11-18 15:40:23 -05005347 } else {
5348 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
5349 "2624 RPI %x DID %x flg %x still "
5350 "logged in\n",
5351 ndlp->nlp_rpi, ndlp->nlp_DID,
5352 ndlp->nlp_flag);
5353 if (ndlp->nlp_flag & NLP_RPI_VALID)
5354 ret = 1;
James Smart6fb120a2009-05-22 14:52:59 -04005355 }
5356 }
5357 spin_unlock_irq(shost->host_lock);
5358 }
5359out:
5360 lpfc_destroy_vport_work_array(phba, vports);
5361 return ret;
5362}
5363
5364/**
5365 * lpfc_unregister_vfi_cmpl - Completion handler for unreg vfi.
5366 * @phba: Pointer to hba context object.
5367 * @mboxq: Pointer to mailbox object.
5368 *
5369 * This function frees memory associated with the mailbox command.
5370 */
5371static void
5372lpfc_unregister_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
5373{
5374 struct lpfc_vport *vport = mboxq->vport;
James Smart38b92ef2010-08-04 16:11:39 -04005375 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart6fb120a2009-05-22 14:52:59 -04005376
5377 if (mboxq->u.mb.mbxStatus) {
5378 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
5379 "2555 UNREG_VFI mbxStatus error x%x "
5380 "HBA state x%x\n",
5381 mboxq->u.mb.mbxStatus, vport->port_state);
5382 }
James Smart38b92ef2010-08-04 16:11:39 -04005383 spin_lock_irq(shost->host_lock);
5384 phba->pport->fc_flag &= ~FC_VFI_REGISTERED;
5385 spin_unlock_irq(shost->host_lock);
James Smart6fb120a2009-05-22 14:52:59 -04005386 mempool_free(mboxq, phba->mbox_mem_pool);
5387 return;
5388}
5389
5390/**
5391 * lpfc_unregister_fcfi_cmpl - Completion handler for unreg fcfi.
5392 * @phba: Pointer to hba context object.
5393 * @mboxq: Pointer to mailbox object.
5394 *
5395 * This function frees memory associated with the mailbox command.
5396 */
5397static void
5398lpfc_unregister_fcfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
5399{
5400 struct lpfc_vport *vport = mboxq->vport;
5401
5402 if (mboxq->u.mb.mbxStatus) {
5403 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
5404 "2550 UNREG_FCFI mbxStatus error x%x "
5405 "HBA state x%x\n",
5406 mboxq->u.mb.mbxStatus, vport->port_state);
5407 }
5408 mempool_free(mboxq, phba->mbox_mem_pool);
5409 return;
5410}
5411
5412/**
James Smartecfd03c2010-02-12 14:41:27 -05005413 * lpfc_unregister_fcf_prep - Unregister fcf record preparation
James Smart6fb120a2009-05-22 14:52:59 -04005414 * @phba: Pointer to hba context object.
5415 *
James Smartecfd03c2010-02-12 14:41:27 -05005416 * This function prepare the HBA for unregistering the currently registered
5417 * FCF from the HBA. It performs unregistering, in order, RPIs, VPIs, and
5418 * VFIs.
James Smart6fb120a2009-05-22 14:52:59 -04005419 */
James Smartecfd03c2010-02-12 14:41:27 -05005420int
5421lpfc_unregister_fcf_prep(struct lpfc_hba *phba)
James Smart6fb120a2009-05-22 14:52:59 -04005422{
5423 LPFC_MBOXQ_t *mbox;
James Smart6fb120a2009-05-22 14:52:59 -04005424 struct lpfc_vport **vports;
James Smart695a8142010-01-26 23:08:03 -05005425 struct lpfc_nodelist *ndlp;
James Smart72100cc2010-02-12 14:43:01 -05005426 struct Scsi_Host *shost;
James Smartecfd03c2010-02-12 14:41:27 -05005427 int i, rc;
James Smart6fb120a2009-05-22 14:52:59 -04005428
James Smartecfd03c2010-02-12 14:41:27 -05005429 /* Unregister RPIs */
James Smart6fb120a2009-05-22 14:52:59 -04005430 if (lpfc_fcf_inuse(phba))
James Smartecfd03c2010-02-12 14:41:27 -05005431 lpfc_unreg_hba_rpis(phba);
James Smart6fb120a2009-05-22 14:52:59 -04005432
James Smart4d9ab992009-10-02 15:16:39 -04005433 /* At this point, all discovery is aborted */
5434 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
James Smart6fb120a2009-05-22 14:52:59 -04005435
5436 /* Unregister VPIs */
5437 vports = lpfc_create_vport_work_array(phba);
James Smartecfd03c2010-02-12 14:41:27 -05005438 if (vports && (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED))
James Smart6fb120a2009-05-22 14:52:59 -04005439 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart695a8142010-01-26 23:08:03 -05005440 /* Stop FLOGI/FDISC retries */
5441 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
5442 if (ndlp)
5443 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
James Smart78730cf2010-04-06 15:06:30 -04005444 lpfc_cleanup_pending_mbox(vports[i]);
James Smart5af5eee2010-10-22 11:06:38 -04005445 if (phba->sli_rev == LPFC_SLI_REV4)
5446 lpfc_sli4_unreg_all_rpis(vports[i]);
James Smart6fb120a2009-05-22 14:52:59 -04005447 lpfc_mbx_unreg_vpi(vports[i]);
James Smart72100cc2010-02-12 14:43:01 -05005448 shost = lpfc_shost_from_vport(vports[i]);
5449 spin_lock_irq(shost->host_lock);
James Smart891478a2009-11-18 15:40:23 -05005450 vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smartc8685952009-11-18 15:39:16 -05005451 vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED;
James Smart72100cc2010-02-12 14:43:01 -05005452 spin_unlock_irq(shost->host_lock);
James Smart6fb120a2009-05-22 14:52:59 -04005453 }
5454 lpfc_destroy_vport_work_array(phba, vports);
5455
James Smart695a8142010-01-26 23:08:03 -05005456 /* Cleanup any outstanding ELS commands */
5457 lpfc_els_flush_all_cmd(phba);
5458
James Smart6fb120a2009-05-22 14:52:59 -04005459 /* Unregister VFI */
5460 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5461 if (!mbox) {
5462 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
James Smartecfd03c2010-02-12 14:41:27 -05005463 "2556 UNREG_VFI mbox allocation failed"
5464 "HBA state x%x\n", phba->pport->port_state);
5465 return -ENOMEM;
James Smart6fb120a2009-05-22 14:52:59 -04005466 }
5467
James Smart6669f9b2009-10-02 15:16:45 -04005468 lpfc_unreg_vfi(mbox, phba->pport);
James Smart6fb120a2009-05-22 14:52:59 -04005469 mbox->vport = phba->pport;
5470 mbox->mbox_cmpl = lpfc_unregister_vfi_cmpl;
5471
5472 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5473 if (rc == MBX_NOT_FINISHED) {
5474 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
James Smartecfd03c2010-02-12 14:41:27 -05005475 "2557 UNREG_VFI issue mbox failed rc x%x "
5476 "HBA state x%x\n",
5477 rc, phba->pport->port_state);
James Smart6fb120a2009-05-22 14:52:59 -04005478 mempool_free(mbox, phba->mbox_mem_pool);
James Smartecfd03c2010-02-12 14:41:27 -05005479 return -EIO;
James Smart6fb120a2009-05-22 14:52:59 -04005480 }
5481
James Smart72100cc2010-02-12 14:43:01 -05005482 shost = lpfc_shost_from_vport(phba->pport);
5483 spin_lock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05005484 phba->pport->fc_flag &= ~FC_VFI_REGISTERED;
James Smart72100cc2010-02-12 14:43:01 -05005485 spin_unlock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05005486
James Smartecfd03c2010-02-12 14:41:27 -05005487 return 0;
5488}
5489
5490/**
5491 * lpfc_sli4_unregister_fcf - Unregister currently registered FCF record
5492 * @phba: Pointer to hba context object.
5493 *
5494 * This function issues synchronous unregister FCF mailbox command to HBA to
5495 * unregister the currently registered FCF record. The driver does not reset
5496 * the driver FCF usage state flags.
5497 *
5498 * Return 0 if successfully issued, none-zero otherwise.
5499 */
5500int
5501lpfc_sli4_unregister_fcf(struct lpfc_hba *phba)
5502{
5503 LPFC_MBOXQ_t *mbox;
5504 int rc;
5505
James Smart6fb120a2009-05-22 14:52:59 -04005506 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5507 if (!mbox) {
5508 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
James Smartecfd03c2010-02-12 14:41:27 -05005509 "2551 UNREG_FCFI mbox allocation failed"
5510 "HBA state x%x\n", phba->pport->port_state);
5511 return -ENOMEM;
James Smart6fb120a2009-05-22 14:52:59 -04005512 }
James Smart6fb120a2009-05-22 14:52:59 -04005513 lpfc_unreg_fcfi(mbox, phba->fcf.fcfi);
5514 mbox->vport = phba->pport;
5515 mbox->mbox_cmpl = lpfc_unregister_fcfi_cmpl;
5516 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5517
5518 if (rc == MBX_NOT_FINISHED) {
James Smartecfd03c2010-02-12 14:41:27 -05005519 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5520 "2552 Unregister FCFI command failed rc x%x "
5521 "HBA state x%x\n",
5522 rc, phba->pport->port_state);
5523 return -EINVAL;
5524 }
5525 return 0;
5526}
5527
5528/**
5529 * lpfc_unregister_fcf_rescan - Unregister currently registered fcf and rescan
5530 * @phba: Pointer to hba context object.
5531 *
5532 * This function unregisters the currently reigstered FCF. This function
5533 * also tries to find another FCF for discovery by rescan the HBA FCF table.
5534 */
5535void
5536lpfc_unregister_fcf_rescan(struct lpfc_hba *phba)
5537{
5538 int rc;
5539
5540 /* Preparation for unregistering fcf */
5541 rc = lpfc_unregister_fcf_prep(phba);
5542 if (rc) {
5543 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
5544 "2748 Failed to prepare for unregistering "
5545 "HBA's FCF record: rc=%d\n", rc);
James Smart6fb120a2009-05-22 14:52:59 -04005546 return;
5547 }
5548
James Smartecfd03c2010-02-12 14:41:27 -05005549 /* Now, unregister FCF record and reset HBA FCF state */
5550 rc = lpfc_sli4_unregister_fcf(phba);
5551 if (rc)
5552 return;
5553 /* Reset HBA FCF states after successful unregister FCF */
5554 phba->fcf.fcf_flag = 0;
James Smartfc2b9892010-02-26 14:15:29 -05005555 phba->fcf.current_rec.flag = 0;
James Smart6fb120a2009-05-22 14:52:59 -04005556
5557 /*
5558 * If driver is not unloading, check if there is any other
5559 * FCF record that can be used for discovery.
5560 */
5561 if ((phba->pport->load_flag & FC_UNLOADING) ||
James Smartecfd03c2010-02-12 14:41:27 -05005562 (phba->link_state < LPFC_LINK_UP))
James Smart6fb120a2009-05-22 14:52:59 -04005563 return;
5564
James Smart0c9ab6f2010-02-26 14:15:57 -05005565 /* This is considered as the initial FCF discovery scan */
5566 spin_lock_irq(&phba->hbalock);
5567 phba->fcf.fcf_flag |= FCF_INIT_DISC;
5568 spin_unlock_irq(&phba->hbalock);
James Smart38b92ef2010-08-04 16:11:39 -04005569
5570 /* Reset FCF roundrobin bmask for new discovery */
5571 memset(phba->fcf.fcf_rr_bmask, 0, sizeof(*phba->fcf.fcf_rr_bmask));
5572
James Smart0c9ab6f2010-02-26 14:15:57 -05005573 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
James Smart6fb120a2009-05-22 14:52:59 -04005574
James Smart0c9ab6f2010-02-26 14:15:57 -05005575 if (rc) {
5576 spin_lock_irq(&phba->hbalock);
5577 phba->fcf.fcf_flag &= ~FCF_INIT_DISC;
5578 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04005579 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
James Smartecfd03c2010-02-12 14:41:27 -05005580 "2553 lpfc_unregister_unused_fcf failed "
5581 "to read FCF record HBA state x%x\n",
5582 phba->pport->port_state);
James Smart0c9ab6f2010-02-26 14:15:57 -05005583 }
James Smartecfd03c2010-02-12 14:41:27 -05005584}
5585
5586/**
5587 * lpfc_unregister_fcf - Unregister the currently registered fcf record
5588 * @phba: Pointer to hba context object.
5589 *
5590 * This function just unregisters the currently reigstered FCF. It does not
5591 * try to find another FCF for discovery.
5592 */
5593void
5594lpfc_unregister_fcf(struct lpfc_hba *phba)
5595{
5596 int rc;
5597
5598 /* Preparation for unregistering fcf */
5599 rc = lpfc_unregister_fcf_prep(phba);
5600 if (rc) {
5601 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
5602 "2749 Failed to prepare for unregistering "
5603 "HBA's FCF record: rc=%d\n", rc);
5604 return;
5605 }
5606
5607 /* Now, unregister FCF record and reset HBA FCF state */
5608 rc = lpfc_sli4_unregister_fcf(phba);
5609 if (rc)
5610 return;
5611 /* Set proper HBA FCF states after successful unregister FCF */
5612 spin_lock_irq(&phba->hbalock);
5613 phba->fcf.fcf_flag &= ~FCF_REGISTERED;
5614 spin_unlock_irq(&phba->hbalock);
5615}
5616
5617/**
5618 * lpfc_unregister_unused_fcf - Unregister FCF if all devices are disconnected.
5619 * @phba: Pointer to hba context object.
5620 *
5621 * This function check if there are any connected remote port for the FCF and
5622 * if all the devices are disconnected, this function unregister FCFI.
5623 * This function also tries to use another FCF for discovery.
5624 */
5625void
5626lpfc_unregister_unused_fcf(struct lpfc_hba *phba)
5627{
5628 /*
James Smart3804dc82010-07-14 15:31:37 -04005629 * If HBA is not running in FIP mode, if HBA does not support
5630 * FCoE, if FCF discovery is ongoing, or if FCF has not been
5631 * registered, do nothing.
James Smartecfd03c2010-02-12 14:41:27 -05005632 */
5633 spin_lock_irq(&phba->hbalock);
James Smart76a95d72010-11-20 23:11:48 -05005634 if (!(phba->hba_flag & HBA_FCOE_MODE) ||
James Smartecfd03c2010-02-12 14:41:27 -05005635 !(phba->fcf.fcf_flag & FCF_REGISTERED) ||
James Smartdbb6b3a2010-06-08 18:31:37 -04005636 !(phba->hba_flag & HBA_FIP_SUPPORT) ||
James Smart3804dc82010-07-14 15:31:37 -04005637 (phba->fcf.fcf_flag & FCF_DISCOVERY) ||
James Smartdbb6b3a2010-06-08 18:31:37 -04005638 (phba->pport->port_state == LPFC_FLOGI)) {
James Smartecfd03c2010-02-12 14:41:27 -05005639 spin_unlock_irq(&phba->hbalock);
5640 return;
5641 }
5642 spin_unlock_irq(&phba->hbalock);
5643
5644 if (lpfc_fcf_inuse(phba))
5645 return;
5646
5647 lpfc_unregister_fcf_rescan(phba);
James Smart6fb120a2009-05-22 14:52:59 -04005648}
5649
5650/**
5651 * lpfc_read_fcf_conn_tbl - Create driver FCF connection table.
5652 * @phba: Pointer to hba context object.
5653 * @buff: Buffer containing the FCF connection table as in the config
5654 * region.
5655 * This function create driver data structure for the FCF connection
5656 * record table read from config region 23.
5657 */
5658static void
5659lpfc_read_fcf_conn_tbl(struct lpfc_hba *phba,
5660 uint8_t *buff)
5661{
5662 struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
5663 struct lpfc_fcf_conn_hdr *conn_hdr;
5664 struct lpfc_fcf_conn_rec *conn_rec;
5665 uint32_t record_count;
5666 int i;
5667
5668 /* Free the current connect table */
5669 list_for_each_entry_safe(conn_entry, next_conn_entry,
James Smart4d9ab992009-10-02 15:16:39 -04005670 &phba->fcf_conn_rec_list, list) {
5671 list_del_init(&conn_entry->list);
James Smart6fb120a2009-05-22 14:52:59 -04005672 kfree(conn_entry);
James Smart4d9ab992009-10-02 15:16:39 -04005673 }
James Smart6fb120a2009-05-22 14:52:59 -04005674
5675 conn_hdr = (struct lpfc_fcf_conn_hdr *) buff;
5676 record_count = conn_hdr->length * sizeof(uint32_t)/
5677 sizeof(struct lpfc_fcf_conn_rec);
5678
5679 conn_rec = (struct lpfc_fcf_conn_rec *)
5680 (buff + sizeof(struct lpfc_fcf_conn_hdr));
5681
5682 for (i = 0; i < record_count; i++) {
5683 if (!(conn_rec[i].flags & FCFCNCT_VALID))
5684 continue;
5685 conn_entry = kzalloc(sizeof(struct lpfc_fcf_conn_entry),
5686 GFP_KERNEL);
5687 if (!conn_entry) {
5688 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5689 "2566 Failed to allocate connection"
5690 " table entry\n");
5691 return;
5692 }
5693
5694 memcpy(&conn_entry->conn_rec, &conn_rec[i],
5695 sizeof(struct lpfc_fcf_conn_rec));
5696 conn_entry->conn_rec.vlan_tag =
5697 le16_to_cpu(conn_entry->conn_rec.vlan_tag) & 0xFFF;
5698 conn_entry->conn_rec.flags =
5699 le16_to_cpu(conn_entry->conn_rec.flags);
5700 list_add_tail(&conn_entry->list,
5701 &phba->fcf_conn_rec_list);
5702 }
5703}
5704
5705/**
5706 * lpfc_read_fcoe_param - Read FCoe parameters from conf region..
5707 * @phba: Pointer to hba context object.
5708 * @buff: Buffer containing the FCoE parameter data structure.
5709 *
5710 * This function update driver data structure with config
5711 * parameters read from config region 23.
5712 */
5713static void
5714lpfc_read_fcoe_param(struct lpfc_hba *phba,
5715 uint8_t *buff)
5716{
5717 struct lpfc_fip_param_hdr *fcoe_param_hdr;
5718 struct lpfc_fcoe_params *fcoe_param;
5719
5720 fcoe_param_hdr = (struct lpfc_fip_param_hdr *)
5721 buff;
5722 fcoe_param = (struct lpfc_fcoe_params *)
James Smart32b97932009-07-19 10:01:21 -04005723 (buff + sizeof(struct lpfc_fip_param_hdr));
James Smart6fb120a2009-05-22 14:52:59 -04005724
5725 if ((fcoe_param_hdr->parm_version != FIPP_VERSION) ||
5726 (fcoe_param_hdr->length != FCOE_PARAM_LENGTH))
5727 return;
5728
James Smart6fb120a2009-05-22 14:52:59 -04005729 if (fcoe_param_hdr->parm_flags & FIPP_VLAN_VALID) {
5730 phba->valid_vlan = 1;
5731 phba->vlan_id = le16_to_cpu(fcoe_param->vlan_tag) &
5732 0xFFF;
5733 }
5734
5735 phba->fc_map[0] = fcoe_param->fc_map[0];
5736 phba->fc_map[1] = fcoe_param->fc_map[1];
5737 phba->fc_map[2] = fcoe_param->fc_map[2];
5738 return;
5739}
5740
5741/**
5742 * lpfc_get_rec_conf23 - Get a record type in config region data.
5743 * @buff: Buffer containing config region 23 data.
5744 * @size: Size of the data buffer.
5745 * @rec_type: Record type to be searched.
5746 *
5747 * This function searches config region data to find the begining
5748 * of the record specified by record_type. If record found, this
5749 * function return pointer to the record else return NULL.
5750 */
5751static uint8_t *
5752lpfc_get_rec_conf23(uint8_t *buff, uint32_t size, uint8_t rec_type)
5753{
5754 uint32_t offset = 0, rec_length;
5755
5756 if ((buff[0] == LPFC_REGION23_LAST_REC) ||
5757 (size < sizeof(uint32_t)))
5758 return NULL;
5759
5760 rec_length = buff[offset + 1];
5761
5762 /*
5763 * One TLV record has one word header and number of data words
5764 * specified in the rec_length field of the record header.
5765 */
5766 while ((offset + rec_length * sizeof(uint32_t) + sizeof(uint32_t))
5767 <= size) {
5768 if (buff[offset] == rec_type)
5769 return &buff[offset];
5770
5771 if (buff[offset] == LPFC_REGION23_LAST_REC)
5772 return NULL;
5773
5774 offset += rec_length * sizeof(uint32_t) + sizeof(uint32_t);
5775 rec_length = buff[offset + 1];
5776 }
5777 return NULL;
5778}
5779
5780/**
5781 * lpfc_parse_fcoe_conf - Parse FCoE config data read from config region 23.
5782 * @phba: Pointer to lpfc_hba data structure.
5783 * @buff: Buffer containing config region 23 data.
5784 * @size: Size of the data buffer.
5785 *
Stefan Weileef35c22010-08-06 21:11:15 +02005786 * This function parses the FCoE config parameters in config region 23 and
James Smart6fb120a2009-05-22 14:52:59 -04005787 * populate driver data structure with the parameters.
5788 */
5789void
5790lpfc_parse_fcoe_conf(struct lpfc_hba *phba,
5791 uint8_t *buff,
5792 uint32_t size)
5793{
5794 uint32_t offset = 0, rec_length;
5795 uint8_t *rec_ptr;
5796
5797 /*
5798 * If data size is less than 2 words signature and version cannot be
5799 * verified.
5800 */
5801 if (size < 2*sizeof(uint32_t))
5802 return;
5803
5804 /* Check the region signature first */
5805 if (memcmp(buff, LPFC_REGION23_SIGNATURE, 4)) {
5806 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5807 "2567 Config region 23 has bad signature\n");
5808 return;
5809 }
5810
5811 offset += 4;
5812
5813 /* Check the data structure version */
5814 if (buff[offset] != LPFC_REGION23_VERSION) {
5815 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5816 "2568 Config region 23 has bad version\n");
5817 return;
5818 }
5819 offset += 4;
5820
5821 rec_length = buff[offset + 1];
5822
5823 /* Read FCoE param record */
5824 rec_ptr = lpfc_get_rec_conf23(&buff[offset],
5825 size - offset, FCOE_PARAM_TYPE);
5826 if (rec_ptr)
5827 lpfc_read_fcoe_param(phba, rec_ptr);
5828
5829 /* Read FCF connection table */
5830 rec_ptr = lpfc_get_rec_conf23(&buff[offset],
5831 size - offset, FCOE_CONN_TBL_TYPE);
5832 if (rec_ptr)
5833 lpfc_read_fcf_conn_tbl(phba, rec_ptr);
5834
5835}