blob: 0788bf670addf83641f5033979fa10c69f558a46 [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>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090023#include <linux/slab.h>
dea31012005-04-17 16:05:31 -050024#include <linux/pci.h>
25#include <linux/kthread.h>
26#include <linux/interrupt.h>
27
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040028#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050029#include <scsi/scsi_device.h>
30#include <scsi/scsi_host.h>
31#include <scsi/scsi_transport_fc.h>
32
James Smartda0436e2009-05-22 14:51:39 -040033#include "lpfc_hw4.h"
dea31012005-04-17 16:05:31 -050034#include "lpfc_hw.h"
James Smartea2151b2008-09-07 11:52:10 -040035#include "lpfc_nl.h"
dea31012005-04-17 16:05:31 -050036#include "lpfc_disc.h"
37#include "lpfc_sli.h"
James Smartda0436e2009-05-22 14:51:39 -040038#include "lpfc_sli4.h"
dea31012005-04-17 16:05:31 -050039#include "lpfc_scsi.h"
40#include "lpfc.h"
41#include "lpfc_logmsg.h"
42#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050043#include "lpfc_vport.h"
James Smart858c9f62007-06-17 19:56:39 -050044#include "lpfc_debugfs.h"
dea31012005-04-17 16:05:31 -050045
46/* AlpaArray for assignment of scsid for scan-down and bind_method */
47static uint8_t lpfcAlpaArray[] = {
48 0xEF, 0xE8, 0xE4, 0xE2, 0xE1, 0xE0, 0xDC, 0xDA, 0xD9, 0xD6,
49 0xD5, 0xD4, 0xD3, 0xD2, 0xD1, 0xCE, 0xCD, 0xCC, 0xCB, 0xCA,
50 0xC9, 0xC7, 0xC6, 0xC5, 0xC3, 0xBC, 0xBA, 0xB9, 0xB6, 0xB5,
51 0xB4, 0xB3, 0xB2, 0xB1, 0xAE, 0xAD, 0xAC, 0xAB, 0xAA, 0xA9,
52 0xA7, 0xA6, 0xA5, 0xA3, 0x9F, 0x9E, 0x9D, 0x9B, 0x98, 0x97,
53 0x90, 0x8F, 0x88, 0x84, 0x82, 0x81, 0x80, 0x7C, 0x7A, 0x79,
54 0x76, 0x75, 0x74, 0x73, 0x72, 0x71, 0x6E, 0x6D, 0x6C, 0x6B,
55 0x6A, 0x69, 0x67, 0x66, 0x65, 0x63, 0x5C, 0x5A, 0x59, 0x56,
56 0x55, 0x54, 0x53, 0x52, 0x51, 0x4E, 0x4D, 0x4C, 0x4B, 0x4A,
57 0x49, 0x47, 0x46, 0x45, 0x43, 0x3C, 0x3A, 0x39, 0x36, 0x35,
58 0x34, 0x33, 0x32, 0x31, 0x2E, 0x2D, 0x2C, 0x2B, 0x2A, 0x29,
59 0x27, 0x26, 0x25, 0x23, 0x1F, 0x1E, 0x1D, 0x1B, 0x18, 0x17,
60 0x10, 0x0F, 0x08, 0x04, 0x02, 0x01
61};
62
James Smart2e0fef82007-06-17 19:56:36 -050063static void lpfc_disc_timeout_handler(struct lpfc_vport *);
Adrian Bunka6ababd2007-11-05 18:07:33 +010064static void lpfc_disc_flush_list(struct lpfc_vport *vport);
James Smart32b97932009-07-19 10:01:21 -040065static void lpfc_unregister_fcfi_cmpl(struct lpfc_hba *, LPFC_MBOXQ_t *);
dea31012005-04-17 16:05:31 -050066
James Smartc01f3202006-08-18 17:47:08 -040067void
68lpfc_terminate_rport_io(struct fc_rport *rport)
dea31012005-04-17 16:05:31 -050069{
James Smartc01f3202006-08-18 17:47:08 -040070 struct lpfc_rport_data *rdata;
71 struct lpfc_nodelist * ndlp;
72 struct lpfc_hba *phba;
dea31012005-04-17 16:05:31 -050073
James Smartc01f3202006-08-18 17:47:08 -040074 rdata = rport->dd_data;
75 ndlp = rdata->pnode;
76
James Smart58da1ff2008-04-07 10:15:56 -040077 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smartc01f3202006-08-18 17:47:08 -040078 if (rport->roles & FC_RPORT_ROLE_FCP_TARGET)
79 printk(KERN_ERR "Cannot find remote node"
80 " to terminate I/O Data x%x\n",
81 rport->port_id);
dea31012005-04-17 16:05:31 -050082 return;
83 }
84
James Smarta257bf92009-04-06 18:48:10 -040085 phba = ndlp->phba;
James Smart1a169682006-03-07 15:04:06 -050086
James Smart858c9f62007-06-17 19:56:39 -050087 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_RPORT,
88 "rport terminate: sid:x%x did:x%x flg:x%x",
89 ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag);
90
James Smartc01f3202006-08-18 17:47:08 -040091 if (ndlp->nlp_sid != NLP_NO_SID) {
James Smart51ef4c22007-08-02 11:10:31 -040092 lpfc_sli_abort_iocb(ndlp->vport,
93 &phba->sli.ring[phba->sli.fcp_ring],
94 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
James Smartc01f3202006-08-18 17:47:08 -040095 }
James Smartc01f3202006-08-18 17:47:08 -040096}
97
98/*
99 * This function will be called when dev_loss_tmo fire.
100 */
101void
102lpfc_dev_loss_tmo_callbk(struct fc_rport *rport)
103{
104 struct lpfc_rport_data *rdata;
105 struct lpfc_nodelist * ndlp;
James Smart2e0fef82007-06-17 19:56:36 -0500106 struct lpfc_vport *vport;
James Smart858c9f62007-06-17 19:56:39 -0500107 struct lpfc_hba *phba;
James Smart858c9f62007-06-17 19:56:39 -0500108 struct lpfc_work_evt *evtp;
James Smarta8adb832007-10-27 13:37:53 -0400109 int put_node;
110 int put_rport;
James Smartc01f3202006-08-18 17:47:08 -0400111
112 rdata = rport->dd_data;
113 ndlp = rdata->pnode;
James Smart58da1ff2008-04-07 10:15:56 -0400114 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
James Smartc01f3202006-08-18 17:47:08 -0400115 return;
James Smartc01f3202006-08-18 17:47:08 -0400116
James Smart858c9f62007-06-17 19:56:39 -0500117 vport = ndlp->vport;
118 phba = vport->phba;
119
120 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
121 "rport devlosscb: sid:x%x did:x%x flg:x%x",
122 ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag);
123
James Smarta8adb832007-10-27 13:37:53 -0400124 /* Don't defer this if we are in the process of deleting the vport
125 * or unloading the driver. The unload will cleanup the node
126 * appropriately we just need to cleanup the ndlp rport info here.
127 */
128 if (vport->load_flag & FC_UNLOADING) {
129 put_node = rdata->pnode != NULL;
130 put_rport = ndlp->rport != NULL;
131 rdata->pnode = NULL;
132 ndlp->rport = NULL;
133 if (put_node)
134 lpfc_nlp_put(ndlp);
135 if (put_rport)
136 put_device(&rport->dev);
137 return;
138 }
139
140 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE)
141 return;
142
James Smart858c9f62007-06-17 19:56:39 -0500143 evtp = &ndlp->dev_loss_evt;
144
145 if (!list_empty(&evtp->evt_listp))
146 return;
147
148 spin_lock_irq(&phba->hbalock);
James Smartfa4066b2008-01-11 01:53:27 -0500149 /* We need to hold the node by incrementing the reference
150 * count until this queued work is done
151 */
152 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
James Smart5e9d9b82008-06-14 22:52:53 -0400153 if (evtp->evt_arg1) {
154 evtp->evt = LPFC_EVT_DEV_LOSS;
155 list_add_tail(&evtp->evt_listp, &phba->work_list);
156 lpfc_worker_wake_up(phba);
157 }
James Smart858c9f62007-06-17 19:56:39 -0500158 spin_unlock_irq(&phba->hbalock);
159
James Smart858c9f62007-06-17 19:56:39 -0500160 return;
161}
162
163/*
164 * This function is called from the worker thread when dev_loss_tmo
165 * expire.
166 */
Adrian Bunka6ababd2007-11-05 18:07:33 +0100167static void
James Smart858c9f62007-06-17 19:56:39 -0500168lpfc_dev_loss_tmo_handler(struct lpfc_nodelist *ndlp)
169{
170 struct lpfc_rport_data *rdata;
171 struct fc_rport *rport;
172 struct lpfc_vport *vport;
173 struct lpfc_hba *phba;
174 uint8_t *name;
James Smart87af33f2007-10-27 13:37:43 -0400175 int put_node;
176 int put_rport;
James Smart858c9f62007-06-17 19:56:39 -0500177 int warn_on = 0;
178
179 rport = ndlp->rport;
180
181 if (!rport)
182 return;
183
184 rdata = rport->dd_data;
185 name = (uint8_t *) &ndlp->nlp_portname;
186 vport = ndlp->vport;
187 phba = vport->phba;
188
189 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
190 "rport devlosstmo:did:x%x type:x%x id:x%x",
191 ndlp->nlp_DID, ndlp->nlp_type, rport->scsi_target_id);
192
James Smarta8adb832007-10-27 13:37:53 -0400193 /* Don't defer this if we are in the process of deleting the vport
194 * or unloading the driver. The unload will cleanup the node
195 * appropriately we just need to cleanup the ndlp rport info here.
196 */
197 if (vport->load_flag & FC_UNLOADING) {
James Smart09372822008-01-11 01:52:54 -0500198 if (ndlp->nlp_sid != NLP_NO_SID) {
199 /* flush the target */
200 lpfc_sli_abort_iocb(vport,
201 &phba->sli.ring[phba->sli.fcp_ring],
202 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
203 }
James Smarta8adb832007-10-27 13:37:53 -0400204 put_node = rdata->pnode != NULL;
205 put_rport = ndlp->rport != NULL;
206 rdata->pnode = NULL;
207 ndlp->rport = NULL;
208 if (put_node)
209 lpfc_nlp_put(ndlp);
210 if (put_rport)
211 put_device(&rport->dev);
212 return;
213 }
214
James Smartd7c255b2008-08-24 21:50:00 -0400215 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE) {
216 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
217 "0284 Devloss timeout Ignored on "
218 "WWPN %x:%x:%x:%x:%x:%x:%x:%x "
219 "NPort x%x\n",
220 *name, *(name+1), *(name+2), *(name+3),
221 *(name+4), *(name+5), *(name+6), *(name+7),
222 ndlp->nlp_DID);
James Smart858c9f62007-06-17 19:56:39 -0500223 return;
James Smartd7c255b2008-08-24 21:50:00 -0400224 }
James Smart858c9f62007-06-17 19:56:39 -0500225
James Smart92d7f7b2007-06-17 19:56:38 -0500226 if (ndlp->nlp_type & NLP_FABRIC) {
227 /* We will clean up these Nodes in linkup */
228 put_node = rdata->pnode != NULL;
229 put_rport = ndlp->rport != NULL;
230 rdata->pnode = NULL;
231 ndlp->rport = NULL;
232 if (put_node)
233 lpfc_nlp_put(ndlp);
234 if (put_rport)
235 put_device(&rport->dev);
James Smart82085712007-04-25 09:52:41 -0400236 return;
James Smart92d7f7b2007-06-17 19:56:38 -0500237 }
James Smart82085712007-04-25 09:52:41 -0400238
dea31012005-04-17 16:05:31 -0500239 if (ndlp->nlp_sid != NLP_NO_SID) {
James.Smart@Emulex.Com6e8215e2005-06-25 10:34:04 -0400240 warn_on = 1;
dea31012005-04-17 16:05:31 -0500241 /* flush the target */
James Smart51ef4c22007-08-02 11:10:31 -0400242 lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring],
243 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
dea31012005-04-17 16:05:31 -0500244 }
James Smartc01f3202006-08-18 17:47:08 -0400245
James.Smart@Emulex.Com6e8215e2005-06-25 10:34:04 -0400246 if (warn_on) {
James Smarte8b62012007-08-02 11:10:09 -0400247 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
248 "0203 Devloss timeout on "
James Smart58da1ff2008-04-07 10:15:56 -0400249 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x "
250 "NPort x%06x Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400251 *name, *(name+1), *(name+2), *(name+3),
252 *(name+4), *(name+5), *(name+6), *(name+7),
253 ndlp->nlp_DID, ndlp->nlp_flag,
254 ndlp->nlp_state, ndlp->nlp_rpi);
James.Smart@Emulex.Com6e8215e2005-06-25 10:34:04 -0400255 } else {
James Smarte8b62012007-08-02 11:10:09 -0400256 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
257 "0204 Devloss timeout on "
James Smart58da1ff2008-04-07 10:15:56 -0400258 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x "
259 "NPort x%06x Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400260 *name, *(name+1), *(name+2), *(name+3),
261 *(name+4), *(name+5), *(name+6), *(name+7),
262 ndlp->nlp_DID, ndlp->nlp_flag,
263 ndlp->nlp_state, ndlp->nlp_rpi);
James.Smart@Emulex.Com6e8215e2005-06-25 10:34:04 -0400264 }
265
James Smart87af33f2007-10-27 13:37:43 -0400266 put_node = rdata->pnode != NULL;
267 put_rport = ndlp->rport != NULL;
268 rdata->pnode = NULL;
269 ndlp->rport = NULL;
270 if (put_node)
271 lpfc_nlp_put(ndlp);
272 if (put_rport)
273 put_device(&rport->dev);
274
James Smart2e0fef82007-06-17 19:56:36 -0500275 if (!(vport->load_flag & FC_UNLOADING) &&
James Smart1dcb58e2007-04-25 09:51:30 -0400276 !(ndlp->nlp_flag & NLP_DELAY_TMO) &&
James Smart82085712007-04-25 09:52:41 -0400277 !(ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
James Smartffc95492010-06-07 15:23:17 -0400278 (ndlp->nlp_state != NLP_STE_UNMAPPED_NODE) &&
James Smart589a52d2010-07-14 15:30:54 -0400279 (ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE) &&
280 (ndlp->nlp_state != NLP_STE_PRLI_ISSUE))
James Smart2e0fef82007-06-17 19:56:36 -0500281 lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
James Smart6fb120a2009-05-22 14:52:59 -0400282
283 lpfc_unregister_unused_fcf(phba);
James Smart92d7f7b2007-06-17 19:56:38 -0500284}
James Smartc01f3202006-08-18 17:47:08 -0400285
James Smartea2151b2008-09-07 11:52:10 -0400286/**
James Smart3621a712009-04-06 18:47:14 -0400287 * lpfc_alloc_fast_evt - Allocates data structure for posting event
James Smartea2151b2008-09-07 11:52:10 -0400288 * @phba: Pointer to hba context object.
289 *
290 * This function is called from the functions which need to post
291 * events from interrupt context. This function allocates data
292 * structure required for posting event. It also keeps track of
293 * number of events pending and prevent event storm when there are
294 * too many events.
295 **/
296struct lpfc_fast_path_event *
297lpfc_alloc_fast_evt(struct lpfc_hba *phba) {
298 struct lpfc_fast_path_event *ret;
299
300 /* If there are lot of fast event do not exhaust memory due to this */
301 if (atomic_read(&phba->fast_event_count) > LPFC_MAX_EVT_COUNT)
302 return NULL;
303
304 ret = kzalloc(sizeof(struct lpfc_fast_path_event),
305 GFP_ATOMIC);
James Smart6fb120a2009-05-22 14:52:59 -0400306 if (ret) {
James Smartea2151b2008-09-07 11:52:10 -0400307 atomic_inc(&phba->fast_event_count);
James Smart6fb120a2009-05-22 14:52:59 -0400308 INIT_LIST_HEAD(&ret->work_evt.evt_listp);
309 ret->work_evt.evt = LPFC_EVT_FASTPATH_MGMT_EVT;
310 }
James Smartea2151b2008-09-07 11:52:10 -0400311 return ret;
312}
313
314/**
James Smart3621a712009-04-06 18:47:14 -0400315 * lpfc_free_fast_evt - Frees event data structure
James Smartea2151b2008-09-07 11:52:10 -0400316 * @phba: Pointer to hba context object.
317 * @evt: Event object which need to be freed.
318 *
319 * This function frees the data structure required for posting
320 * events.
321 **/
322void
323lpfc_free_fast_evt(struct lpfc_hba *phba,
324 struct lpfc_fast_path_event *evt) {
325
326 atomic_dec(&phba->fast_event_count);
327 kfree(evt);
328}
329
330/**
James Smart3621a712009-04-06 18:47:14 -0400331 * lpfc_send_fastpath_evt - Posts events generated from fast path
James Smartea2151b2008-09-07 11:52:10 -0400332 * @phba: Pointer to hba context object.
333 * @evtp: Event data structure.
334 *
335 * This function is called from worker thread, when the interrupt
336 * context need to post an event. This function posts the event
337 * to fc transport netlink interface.
338 **/
339static void
340lpfc_send_fastpath_evt(struct lpfc_hba *phba,
341 struct lpfc_work_evt *evtp)
342{
343 unsigned long evt_category, evt_sub_category;
344 struct lpfc_fast_path_event *fast_evt_data;
345 char *evt_data;
346 uint32_t evt_data_size;
347 struct Scsi_Host *shost;
348
349 fast_evt_data = container_of(evtp, struct lpfc_fast_path_event,
350 work_evt);
351
352 evt_category = (unsigned long) fast_evt_data->un.fabric_evt.event_type;
353 evt_sub_category = (unsigned long) fast_evt_data->un.
354 fabric_evt.subcategory;
355 shost = lpfc_shost_from_vport(fast_evt_data->vport);
356 if (evt_category == FC_REG_FABRIC_EVENT) {
357 if (evt_sub_category == LPFC_EVENT_FCPRDCHKERR) {
358 evt_data = (char *) &fast_evt_data->un.read_check_error;
359 evt_data_size = sizeof(fast_evt_data->un.
360 read_check_error);
361 } else if ((evt_sub_category == LPFC_EVENT_FABRIC_BUSY) ||
James Smarteaf15d52008-12-04 22:39:29 -0500362 (evt_sub_category == LPFC_EVENT_PORT_BUSY)) {
James Smartea2151b2008-09-07 11:52:10 -0400363 evt_data = (char *) &fast_evt_data->un.fabric_evt;
364 evt_data_size = sizeof(fast_evt_data->un.fabric_evt);
365 } else {
366 lpfc_free_fast_evt(phba, fast_evt_data);
367 return;
368 }
369 } else if (evt_category == FC_REG_SCSI_EVENT) {
370 switch (evt_sub_category) {
371 case LPFC_EVENT_QFULL:
372 case LPFC_EVENT_DEVBSY:
373 evt_data = (char *) &fast_evt_data->un.scsi_evt;
374 evt_data_size = sizeof(fast_evt_data->un.scsi_evt);
375 break;
376 case LPFC_EVENT_CHECK_COND:
377 evt_data = (char *) &fast_evt_data->un.check_cond_evt;
378 evt_data_size = sizeof(fast_evt_data->un.
379 check_cond_evt);
380 break;
381 case LPFC_EVENT_VARQUEDEPTH:
382 evt_data = (char *) &fast_evt_data->un.queue_depth_evt;
383 evt_data_size = sizeof(fast_evt_data->un.
384 queue_depth_evt);
385 break;
386 default:
387 lpfc_free_fast_evt(phba, fast_evt_data);
388 return;
389 }
390 } else {
391 lpfc_free_fast_evt(phba, fast_evt_data);
392 return;
393 }
394
395 fc_host_post_vendor_event(shost,
396 fc_get_event_number(),
397 evt_data_size,
398 evt_data,
James Smartddcc50f2008-12-04 22:38:46 -0500399 LPFC_NL_VENDOR_ID);
James Smartea2151b2008-09-07 11:52:10 -0400400
401 lpfc_free_fast_evt(phba, fast_evt_data);
402 return;
403}
404
dea31012005-04-17 16:05:31 -0500405static void
James Smart2e0fef82007-06-17 19:56:36 -0500406lpfc_work_list_done(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500407{
408 struct lpfc_work_evt *evtp = NULL;
409 struct lpfc_nodelist *ndlp;
410 int free_evt;
411
James Smart2e0fef82007-06-17 19:56:36 -0500412 spin_lock_irq(&phba->hbalock);
413 while (!list_empty(&phba->work_list)) {
dea31012005-04-17 16:05:31 -0500414 list_remove_head((&phba->work_list), evtp, typeof(*evtp),
415 evt_listp);
James Smart2e0fef82007-06-17 19:56:36 -0500416 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500417 free_evt = 1;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500418 switch (evtp->evt) {
dea31012005-04-17 16:05:31 -0500419 case LPFC_EVT_ELS_RETRY:
James Smart2e0fef82007-06-17 19:56:36 -0500420 ndlp = (struct lpfc_nodelist *) (evtp->evt_arg1);
dea31012005-04-17 16:05:31 -0500421 lpfc_els_retry_delay_handler(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -0500422 free_evt = 0; /* evt is part of ndlp */
James Smartfa4066b2008-01-11 01:53:27 -0500423 /* decrement the node reference count held
424 * for this queued work
425 */
426 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500427 break;
James Smart858c9f62007-06-17 19:56:39 -0500428 case LPFC_EVT_DEV_LOSS:
429 ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1);
James Smart858c9f62007-06-17 19:56:39 -0500430 lpfc_dev_loss_tmo_handler(ndlp);
431 free_evt = 0;
James Smartfa4066b2008-01-11 01:53:27 -0500432 /* decrement the node reference count held for
433 * this queued work
434 */
James Smart858c9f62007-06-17 19:56:39 -0500435 lpfc_nlp_put(ndlp);
436 break;
dea31012005-04-17 16:05:31 -0500437 case LPFC_EVT_ONLINE:
James Smart2e0fef82007-06-17 19:56:36 -0500438 if (phba->link_state < LPFC_LINK_DOWN)
439 *(int *) (evtp->evt_arg1) = lpfc_online(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500440 else
James Smart2e0fef82007-06-17 19:56:36 -0500441 *(int *) (evtp->evt_arg1) = 0;
dea31012005-04-17 16:05:31 -0500442 complete((struct completion *)(evtp->evt_arg2));
443 break;
James Smart46fa3112007-04-25 09:51:45 -0400444 case LPFC_EVT_OFFLINE_PREP:
James Smart2e0fef82007-06-17 19:56:36 -0500445 if (phba->link_state >= LPFC_LINK_DOWN)
James Smart46fa3112007-04-25 09:51:45 -0400446 lpfc_offline_prep(phba);
447 *(int *)(evtp->evt_arg1) = 0;
448 complete((struct completion *)(evtp->evt_arg2));
449 break;
450 case LPFC_EVT_OFFLINE:
451 lpfc_offline(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500452 lpfc_sli_brdrestart(phba);
453 *(int *)(evtp->evt_arg1) =
James Smart46fa3112007-04-25 09:51:45 -0400454 lpfc_sli_brdready(phba, HS_FFRDY | HS_MBRDY);
455 lpfc_unblock_mgmt_io(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500456 complete((struct completion *)(evtp->evt_arg2));
457 break;
458 case LPFC_EVT_WARM_START:
James Smart46fa3112007-04-25 09:51:45 -0400459 lpfc_offline(phba);
James Smart92908312006-03-07 15:04:13 -0500460 lpfc_reset_barrier(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500461 lpfc_sli_brdreset(phba);
462 lpfc_hba_down_post(phba);
463 *(int *)(evtp->evt_arg1) =
464 lpfc_sli_brdready(phba, HS_MBRDY);
James Smart46fa3112007-04-25 09:51:45 -0400465 lpfc_unblock_mgmt_io(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500466 complete((struct completion *)(evtp->evt_arg2));
467 break;
468 case LPFC_EVT_KILL:
James Smart46fa3112007-04-25 09:51:45 -0400469 lpfc_offline(phba);
James Smart92908312006-03-07 15:04:13 -0500470 *(int *)(evtp->evt_arg1)
James Smart2e0fef82007-06-17 19:56:36 -0500471 = (phba->pport->stopped)
472 ? 0 : lpfc_sli_brdkill(phba);
James Smart46fa3112007-04-25 09:51:45 -0400473 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -0500474 complete((struct completion *)(evtp->evt_arg2));
475 break;
James Smartea2151b2008-09-07 11:52:10 -0400476 case LPFC_EVT_FASTPATH_MGMT_EVT:
477 lpfc_send_fastpath_evt(phba, evtp);
478 free_evt = 0;
479 break;
James Smart78730cf2010-04-06 15:06:30 -0400480 case LPFC_EVT_RESET_HBA:
481 if (!(phba->pport->load_flag & FC_UNLOADING))
482 lpfc_reset_hba(phba);
483 break;
dea31012005-04-17 16:05:31 -0500484 }
485 if (free_evt)
486 kfree(evtp);
James Smart2e0fef82007-06-17 19:56:36 -0500487 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500488 }
James Smart2e0fef82007-06-17 19:56:36 -0500489 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500490
491}
492
James Smart311464e2007-08-02 11:10:37 -0400493static void
James Smart2e0fef82007-06-17 19:56:36 -0500494lpfc_work_done(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500495{
496 struct lpfc_sli_ring *pring;
James Smart858c9f62007-06-17 19:56:39 -0500497 uint32_t ha_copy, status, control, work_port_events;
James Smart549e55c2007-08-02 11:09:51 -0400498 struct lpfc_vport **vports;
James Smart51ef4c22007-08-02 11:10:31 -0400499 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -0400500 int i;
dea31012005-04-17 16:05:31 -0500501
James Smart2e0fef82007-06-17 19:56:36 -0500502 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500503 ha_copy = phba->work_ha;
504 phba->work_ha = 0;
James Smart2e0fef82007-06-17 19:56:36 -0500505 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500506
James Smartda0436e2009-05-22 14:51:39 -0400507 /* First, try to post the next mailbox command to SLI4 device */
508 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC)
509 lpfc_sli4_post_async_mbox(phba);
510
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500511 if (ha_copy & HA_ERATT)
James Smart93996272008-08-24 21:50:30 -0400512 /* Handle the error attention event */
dea31012005-04-17 16:05:31 -0500513 lpfc_handle_eratt(phba);
514
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500515 if (ha_copy & HA_MBATT)
dea31012005-04-17 16:05:31 -0500516 lpfc_sli_handle_mb_event(phba);
517
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500518 if (ha_copy & HA_LATT)
dea31012005-04-17 16:05:31 -0500519 lpfc_handle_latt(phba);
James Smart93996272008-08-24 21:50:30 -0400520
James Smartda0436e2009-05-22 14:51:39 -0400521 /* Process SLI4 events */
522 if (phba->pci_dev_grp == LPFC_PCI_DEV_OC) {
523 if (phba->hba_flag & FCP_XRI_ABORT_EVENT)
524 lpfc_sli4_fcp_xri_abort_event_proc(phba);
525 if (phba->hba_flag & ELS_XRI_ABORT_EVENT)
526 lpfc_sli4_els_xri_abort_event_proc(phba);
527 if (phba->hba_flag & ASYNC_EVENT)
528 lpfc_sli4_async_event_proc(phba);
529 if (phba->hba_flag & HBA_POST_RECEIVE_BUFFER) {
530 spin_lock_irq(&phba->hbalock);
531 phba->hba_flag &= ~HBA_POST_RECEIVE_BUFFER;
532 spin_unlock_irq(&phba->hbalock);
533 lpfc_sli_hbqbuf_add_hbqs(phba, LPFC_ELS_HBQ);
534 }
James Smartecfd03c2010-02-12 14:41:27 -0500535 if (phba->fcf.fcf_flag & FCF_REDISC_EVT)
536 lpfc_sli4_fcf_redisc_event_proc(phba);
James Smartda0436e2009-05-22 14:51:39 -0400537 }
538
James Smart549e55c2007-08-02 11:09:51 -0400539 vports = lpfc_create_vport_work_array(phba);
540 if (vports != NULL)
James Smartda0436e2009-05-22 14:51:39 -0400541 for (i = 0; i <= phba->max_vports; i++) {
James Smart51ef4c22007-08-02 11:10:31 -0400542 /*
543 * We could have no vports in array if unloading, so if
544 * this happens then just use the pport
545 */
546 if (vports[i] == NULL && i == 0)
547 vport = phba->pport;
548 else
549 vport = vports[i];
550 if (vport == NULL)
551 break;
James Smart58da1ff2008-04-07 10:15:56 -0400552 spin_lock_irq(&vport->work_port_lock);
James Smart51ef4c22007-08-02 11:10:31 -0400553 work_port_events = vport->work_port_events;
James Smart58da1ff2008-04-07 10:15:56 -0400554 vport->work_port_events &= ~work_port_events;
555 spin_unlock_irq(&vport->work_port_lock);
James Smart549e55c2007-08-02 11:09:51 -0400556 if (work_port_events & WORKER_DISC_TMO)
James Smart51ef4c22007-08-02 11:10:31 -0400557 lpfc_disc_timeout_handler(vport);
James Smart549e55c2007-08-02 11:09:51 -0400558 if (work_port_events & WORKER_ELS_TMO)
James Smart51ef4c22007-08-02 11:10:31 -0400559 lpfc_els_timeout_handler(vport);
James Smart549e55c2007-08-02 11:09:51 -0400560 if (work_port_events & WORKER_HB_TMO)
561 lpfc_hb_timeout_handler(phba);
562 if (work_port_events & WORKER_MBOX_TMO)
563 lpfc_mbox_timeout_handler(phba);
564 if (work_port_events & WORKER_FABRIC_BLOCK_TMO)
565 lpfc_unblock_fabric_iocbs(phba);
566 if (work_port_events & WORKER_FDMI_TMO)
James Smart51ef4c22007-08-02 11:10:31 -0400567 lpfc_fdmi_timeout_handler(vport);
James Smart549e55c2007-08-02 11:09:51 -0400568 if (work_port_events & WORKER_RAMP_DOWN_QUEUE)
569 lpfc_ramp_down_queue_handler(phba);
570 if (work_port_events & WORKER_RAMP_UP_QUEUE)
571 lpfc_ramp_up_queue_handler(phba);
James Smart92d7f7b2007-06-17 19:56:38 -0500572 }
James Smart09372822008-01-11 01:52:54 -0500573 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -0500574
James Smart858c9f62007-06-17 19:56:39 -0500575 pring = &phba->sli.ring[LPFC_ELS_RING];
576 status = (ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
577 status >>= (4*LPFC_ELS_RING);
James Smart4d9ab992009-10-02 15:16:39 -0400578 if ((status & HA_RXMASK) ||
579 (pring->flag & LPFC_DEFERRED_RING_EVENT) ||
James Smart45ed1192009-10-02 15:17:02 -0400580 (phba->hba_flag & HBA_SP_QUEUE_EVT)) {
James Smart0b727fe2007-10-27 13:37:25 -0400581 if (pring->flag & LPFC_STOP_IOCB_EVENT) {
James Smart858c9f62007-06-17 19:56:39 -0500582 pring->flag |= LPFC_DEFERRED_RING_EVENT;
James Smart5e9d9b82008-06-14 22:52:53 -0400583 /* Set the lpfc data pending flag */
584 set_bit(LPFC_DATA_READY, &phba->data_flags);
James Smart858c9f62007-06-17 19:56:39 -0500585 } else {
James Smart58da1ff2008-04-07 10:15:56 -0400586 pring->flag &= ~LPFC_DEFERRED_RING_EVENT;
James Smart858c9f62007-06-17 19:56:39 -0500587 lpfc_sli_handle_slow_ring_event(phba, pring,
588 (status &
589 HA_RXMASK));
James Smart858c9f62007-06-17 19:56:39 -0500590 }
James Smartbc739052010-08-04 16:11:18 -0400591 if ((phba->sli_rev == LPFC_SLI_REV4) && pring->txq_cnt)
James Smart2a9bf3d2010-06-07 15:24:45 -0400592 lpfc_drain_txq(phba);
James Smart858c9f62007-06-17 19:56:39 -0500593 /*
594 * Turn on Ring interrupts
595 */
James Smart3772a992009-05-22 14:50:54 -0400596 if (phba->sli_rev <= LPFC_SLI_REV3) {
597 spin_lock_irq(&phba->hbalock);
598 control = readl(phba->HCregaddr);
599 if (!(control & (HC_R0INT_ENA << LPFC_ELS_RING))) {
600 lpfc_debugfs_slow_ring_trc(phba,
601 "WRK Enable ring: cntl:x%x hacopy:x%x",
602 control, ha_copy, 0);
James Smarta58cbd52007-08-02 11:09:43 -0400603
James Smart3772a992009-05-22 14:50:54 -0400604 control |= (HC_R0INT_ENA << LPFC_ELS_RING);
605 writel(control, phba->HCregaddr);
606 readl(phba->HCregaddr); /* flush */
607 } else {
608 lpfc_debugfs_slow_ring_trc(phba,
609 "WRK Ring ok: cntl:x%x hacopy:x%x",
610 control, ha_copy, 0);
611 }
612 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500613 }
614 }
James Smart2e0fef82007-06-17 19:56:36 -0500615 lpfc_work_list_done(phba);
dea31012005-04-17 16:05:31 -0500616}
617
dea31012005-04-17 16:05:31 -0500618int
619lpfc_do_work(void *p)
620{
621 struct lpfc_hba *phba = p;
622 int rc;
dea31012005-04-17 16:05:31 -0500623
624 set_user_nice(current, -20);
James Smart5e9d9b82008-06-14 22:52:53 -0400625 phba->data_flags = 0;
dea31012005-04-17 16:05:31 -0500626
James Smart3a55b532008-12-04 22:38:54 -0500627 while (!kthread_should_stop()) {
James Smart5e9d9b82008-06-14 22:52:53 -0400628 /* wait and check worker queue activities */
629 rc = wait_event_interruptible(phba->work_waitq,
630 (test_and_clear_bit(LPFC_DATA_READY,
631 &phba->data_flags)
632 || kthread_should_stop()));
James Smart3a55b532008-12-04 22:38:54 -0500633 /* Signal wakeup shall terminate the worker thread */
634 if (rc) {
635 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
636 "0433 Wakeup on signal: rc=x%x\n", rc);
dea31012005-04-17 16:05:31 -0500637 break;
James Smart3a55b532008-12-04 22:38:54 -0500638 }
dea31012005-04-17 16:05:31 -0500639
James Smart5e9d9b82008-06-14 22:52:53 -0400640 /* Attend pending lpfc data processing */
dea31012005-04-17 16:05:31 -0500641 lpfc_work_done(phba);
dea31012005-04-17 16:05:31 -0500642 }
James Smart3a55b532008-12-04 22:38:54 -0500643 phba->worker_thread = NULL;
644 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
645 "0432 Worker thread stopped.\n");
dea31012005-04-17 16:05:31 -0500646 return 0;
647}
648
649/*
650 * This is only called to handle FC worker events. Since this a rare
651 * occurance, we allocate a struct lpfc_work_evt structure here instead of
652 * embedding it in the IOCB.
653 */
654int
James Smart2e0fef82007-06-17 19:56:36 -0500655lpfc_workq_post_event(struct lpfc_hba *phba, void *arg1, void *arg2,
dea31012005-04-17 16:05:31 -0500656 uint32_t evt)
657{
658 struct lpfc_work_evt *evtp;
James Smarted957682007-06-17 19:56:37 -0500659 unsigned long flags;
dea31012005-04-17 16:05:31 -0500660
661 /*
662 * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will
663 * be queued to worker thread for processing
664 */
James Smart92d7f7b2007-06-17 19:56:38 -0500665 evtp = kmalloc(sizeof(struct lpfc_work_evt), GFP_ATOMIC);
dea31012005-04-17 16:05:31 -0500666 if (!evtp)
667 return 0;
668
669 evtp->evt_arg1 = arg1;
670 evtp->evt_arg2 = arg2;
671 evtp->evt = evt;
672
James Smarted957682007-06-17 19:56:37 -0500673 spin_lock_irqsave(&phba->hbalock, flags);
James Smart071fbd3d2006-04-15 11:53:20 -0400674 list_add_tail(&evtp->evt_listp, &phba->work_list);
James Smarted957682007-06-17 19:56:37 -0500675 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -0500676
James Smart5e9d9b82008-06-14 22:52:53 -0400677 lpfc_worker_wake_up(phba);
678
dea31012005-04-17 16:05:31 -0500679 return 1;
680}
681
James Smart92d7f7b2007-06-17 19:56:38 -0500682void
683lpfc_cleanup_rpis(struct lpfc_vport *vport, int remove)
684{
James Smart09372822008-01-11 01:52:54 -0500685 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500686 struct lpfc_hba *phba = vport->phba;
687 struct lpfc_nodelist *ndlp, *next_ndlp;
688 int rc;
689
690 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -0500691 if (!NLP_CHK_NODE_ACT(ndlp))
692 continue;
James Smart92d7f7b2007-06-17 19:56:38 -0500693 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
694 continue;
James Smart98c9ea52007-10-27 13:37:33 -0400695 if ((phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) ||
696 ((vport->port_type == LPFC_NPIV_PORT) &&
697 (ndlp->nlp_DID == NameServer_DID)))
James Smart92d7f7b2007-06-17 19:56:38 -0500698 lpfc_unreg_rpi(vport, ndlp);
699
700 /* Leave Fabric nodes alone on link down */
James Smart4d9ab992009-10-02 15:16:39 -0400701 if ((phba->sli_rev < LPFC_SLI_REV4) &&
702 (!remove && ndlp->nlp_type & NLP_FABRIC))
James Smart92d7f7b2007-06-17 19:56:38 -0500703 continue;
704 rc = lpfc_disc_state_machine(vport, ndlp, NULL,
705 remove
706 ? NLP_EVT_DEVICE_RM
707 : NLP_EVT_DEVICE_RECOVERY);
708 }
709 if (phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) {
710 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -0500711 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500712 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -0500713 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500714 }
715}
716
James Smart87af33f2007-10-27 13:37:43 -0400717void
James Smart98c9ea52007-10-27 13:37:33 -0400718lpfc_port_link_failure(struct lpfc_vport *vport)
James Smart92d7f7b2007-06-17 19:56:38 -0500719{
James Smart695a8142010-01-26 23:08:03 -0500720 lpfc_vport_set_state(vport, FC_VPORT_LINKDOWN);
721
James Smart45ed1192009-10-02 15:17:02 -0400722 /* Cleanup any outstanding received buffers */
723 lpfc_cleanup_rcv_buffers(vport);
724
James Smart92d7f7b2007-06-17 19:56:38 -0500725 /* Cleanup any outstanding RSCN activity */
726 lpfc_els_flush_rscn(vport);
727
728 /* Cleanup any outstanding ELS commands */
729 lpfc_els_flush_cmd(vport);
730
731 lpfc_cleanup_rpis(vport, 0);
732
James Smart92d7f7b2007-06-17 19:56:38 -0500733 /* Turn off discovery timer if its running */
734 lpfc_can_disctmo(vport);
735}
736
James Smart3772a992009-05-22 14:50:54 -0400737void
James Smart98c9ea52007-10-27 13:37:33 -0400738lpfc_linkdown_port(struct lpfc_vport *vport)
739{
740 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
741
742 fc_host_post_event(shost, fc_get_event_number(), FCH_EVT_LINKDOWN, 0);
743
744 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
745 "Link Down: state:x%x rtry:x%x flg:x%x",
746 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
747
748 lpfc_port_link_failure(vport);
749
750}
751
dea31012005-04-17 16:05:31 -0500752int
James Smart685f0bf2007-04-25 09:53:08 -0400753lpfc_linkdown(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500754{
James Smart2e0fef82007-06-17 19:56:36 -0500755 struct lpfc_vport *vport = phba->pport;
756 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart549e55c2007-08-02 11:09:51 -0400757 struct lpfc_vport **vports;
James Smart685f0bf2007-04-25 09:53:08 -0400758 LPFC_MBOXQ_t *mb;
James Smart549e55c2007-08-02 11:09:51 -0400759 int i;
dea31012005-04-17 16:05:31 -0500760
James Smart3163f722008-02-08 18:50:25 -0500761 if (phba->link_state == LPFC_LINK_DOWN)
James Smart2e0fef82007-06-17 19:56:36 -0500762 return 0;
James Smartaacc20e2009-12-21 17:02:51 -0500763
764 /* Block all SCSI stack I/Os */
765 lpfc_scsi_dev_block(phba);
766
James Smart2e0fef82007-06-17 19:56:36 -0500767 spin_lock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -0500768 phba->fcf.fcf_flag &= ~(FCF_AVAILABLE | FCF_SCAN_DONE);
James Smart72100cc2010-02-12 14:43:01 -0500769 spin_unlock_irq(&phba->hbalock);
James Smart92d7f7b2007-06-17 19:56:38 -0500770 if (phba->link_state > LPFC_LINK_DOWN) {
James Smart2e0fef82007-06-17 19:56:36 -0500771 phba->link_state = LPFC_LINK_DOWN;
James Smart72100cc2010-02-12 14:43:01 -0500772 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500773 phba->pport->fc_flag &= ~FC_LBIT;
James Smart72100cc2010-02-12 14:43:01 -0500774 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500775 }
James Smart549e55c2007-08-02 11:09:51 -0400776 vports = lpfc_create_vport_work_array(phba);
777 if (vports != NULL)
James Smart6fb120a2009-05-22 14:52:59 -0400778 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -0400779 /* Issue a LINK DOWN event to all nodes */
780 lpfc_linkdown_port(vports[i]);
781 }
James Smart09372822008-01-11 01:52:54 -0500782 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -0500783 /* Clean up any firmware default rpi's */
James Smart2e0fef82007-06-17 19:56:36 -0500784 mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
785 if (mb) {
James Smart92d7f7b2007-06-17 19:56:38 -0500786 lpfc_unreg_did(phba, 0xffff, 0xffffffff, mb);
James Smarted957682007-06-17 19:56:37 -0500787 mb->vport = vport;
James Smart2e0fef82007-06-17 19:56:36 -0500788 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart0b727fe2007-10-27 13:37:25 -0400789 if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT)
dea31012005-04-17 16:05:31 -0500790 == MBX_NOT_FINISHED) {
James Smart2e0fef82007-06-17 19:56:36 -0500791 mempool_free(mb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500792 }
793 }
794
dea31012005-04-17 16:05:31 -0500795 /* Setup myDID for link up if we are in pt2pt mode */
James Smart92d7f7b2007-06-17 19:56:38 -0500796 if (phba->pport->fc_flag & FC_PT2PT) {
797 phba->pport->fc_myDID = 0;
James Smart2e0fef82007-06-17 19:56:36 -0500798 mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
799 if (mb) {
dea31012005-04-17 16:05:31 -0500800 lpfc_config_link(phba, mb);
James Smart92d7f7b2007-06-17 19:56:38 -0500801 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -0500802 mb->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -0400803 if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT)
dea31012005-04-17 16:05:31 -0500804 == MBX_NOT_FINISHED) {
James Smart2e0fef82007-06-17 19:56:36 -0500805 mempool_free(mb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500806 }
807 }
James Smart2e0fef82007-06-17 19:56:36 -0500808 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500809 phba->pport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI);
James Smart2e0fef82007-06-17 19:56:36 -0500810 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500811 }
James Smart2e0fef82007-06-17 19:56:36 -0500812
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500813 return 0;
dea31012005-04-17 16:05:31 -0500814}
815
James Smart92d7f7b2007-06-17 19:56:38 -0500816static void
817lpfc_linkup_cleanup_nodes(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -0500818{
James Smart92d7f7b2007-06-17 19:56:38 -0500819 struct lpfc_nodelist *ndlp;
820
821 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -0500822 if (!NLP_CHK_NODE_ACT(ndlp))
823 continue;
James Smart92d7f7b2007-06-17 19:56:38 -0500824 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
825 continue;
James Smart92d7f7b2007-06-17 19:56:38 -0500826 if (ndlp->nlp_type & NLP_FABRIC) {
James Smarte47c9092008-02-08 18:49:26 -0500827 /* On Linkup its safe to clean up the ndlp
828 * from Fabric connections.
829 */
James Smart92d7f7b2007-06-17 19:56:38 -0500830 if (ndlp->nlp_DID != Fabric_DID)
831 lpfc_unreg_rpi(vport, ndlp);
832 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
833 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
James Smarte47c9092008-02-08 18:49:26 -0500834 /* Fail outstanding IO now since device is
835 * marked for PLOGI.
836 */
James Smart92d7f7b2007-06-17 19:56:38 -0500837 lpfc_unreg_rpi(vport, ndlp);
838 }
839 }
840}
841
842static void
843lpfc_linkup_port(struct lpfc_vport *vport)
844{
845 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500846 struct lpfc_hba *phba = vport->phba;
847
848 if ((vport->load_flag & FC_UNLOADING) != 0)
849 return;
850
James Smart858c9f62007-06-17 19:56:39 -0500851 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
852 "Link Up: top:x%x speed:x%x flg:x%x",
853 phba->fc_topology, phba->fc_linkspeed, phba->link_flag);
854
James Smart92d7f7b2007-06-17 19:56:38 -0500855 /* If NPIV is not enabled, only bring the physical port up */
856 if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
857 (vport != phba->pport))
858 return;
dea31012005-04-17 16:05:31 -0500859
James Smart2e0fef82007-06-17 19:56:36 -0500860 fc_host_post_event(shost, fc_get_event_number(), FCH_EVT_LINKUP, 0);
James Smartd2873e42006-08-18 17:46:43 -0400861
James Smart2e0fef82007-06-17 19:56:36 -0500862 spin_lock_irq(shost->host_lock);
James Smart2e0fef82007-06-17 19:56:36 -0500863 vport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI | FC_ABORT_DISCOVERY |
864 FC_RSCN_MODE | FC_NLP_MORE | FC_RSCN_DISCOVERY);
865 vport->fc_flag |= FC_NDISC_ACTIVE;
866 vport->fc_ns_retry = 0;
867 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500868
James Smart92d7f7b2007-06-17 19:56:38 -0500869 if (vport->fc_flag & FC_LBIT)
870 lpfc_linkup_cleanup_nodes(vport);
dea31012005-04-17 16:05:31 -0500871
James Smart92d7f7b2007-06-17 19:56:38 -0500872}
873
874static int
875lpfc_linkup(struct lpfc_hba *phba)
876{
James Smart549e55c2007-08-02 11:09:51 -0400877 struct lpfc_vport **vports;
878 int i;
James Smart92d7f7b2007-06-17 19:56:38 -0500879
880 phba->link_state = LPFC_LINK_UP;
881
882 /* Unblock fabric iocbs if they are blocked */
883 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
884 del_timer_sync(&phba->fabric_block_timer);
885
James Smart549e55c2007-08-02 11:09:51 -0400886 vports = lpfc_create_vport_work_array(phba);
887 if (vports != NULL)
James Smart6fb120a2009-05-22 14:52:59 -0400888 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++)
James Smart549e55c2007-08-02 11:09:51 -0400889 lpfc_linkup_port(vports[i]);
James Smart09372822008-01-11 01:52:54 -0500890 lpfc_destroy_vport_work_array(phba, vports);
James Smart6fb120a2009-05-22 14:52:59 -0400891 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
892 (phba->sli_rev < LPFC_SLI_REV4))
James Smart92d7f7b2007-06-17 19:56:38 -0500893 lpfc_issue_clear_la(phba, phba->pport);
dea31012005-04-17 16:05:31 -0500894
895 return 0;
896}
897
898/*
899 * This routine handles processing a CLEAR_LA mailbox
900 * command upon completion. It is setup in the LPFC_MBOXQ
901 * as the completion routine when the command is
902 * handed off to the SLI layer.
903 */
Adrian Bunka6ababd2007-11-05 18:07:33 +0100904static void
James Smart2e0fef82007-06-17 19:56:36 -0500905lpfc_mbx_cmpl_clear_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -0500906{
James Smart2e0fef82007-06-17 19:56:36 -0500907 struct lpfc_vport *vport = pmb->vport;
908 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
909 struct lpfc_sli *psli = &phba->sli;
James Smart04c68492009-05-22 14:52:52 -0400910 MAILBOX_t *mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -0500911 uint32_t control;
912
dea31012005-04-17 16:05:31 -0500913 /* Since we don't do discovery right now, turn these off here */
James Smarta4bc3372006-12-02 13:34:16 -0500914 psli->ring[psli->extra_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
dea31012005-04-17 16:05:31 -0500915 psli->ring[psli->fcp_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
916 psli->ring[psli->next_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
917
918 /* Check for error */
919 if ((mb->mbxStatus) && (mb->mbxStatus != 0x1601)) {
James Smart92d7f7b2007-06-17 19:56:38 -0500920 /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */
James Smarte8b62012007-08-02 11:10:09 -0400921 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
922 "0320 CLEAR_LA mbxStatus error x%x hba "
923 "state x%x\n",
924 mb->mbxStatus, vport->port_state);
James Smart2e0fef82007-06-17 19:56:36 -0500925 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500926 goto out;
927 }
928
James Smart92d7f7b2007-06-17 19:56:38 -0500929 if (vport->port_type == LPFC_PHYSICAL_PORT)
930 phba->link_state = LPFC_HBA_READY;
931
932 spin_lock_irq(&phba->hbalock);
933 psli->sli_flag |= LPFC_PROCESS_LA;
934 control = readl(phba->HCregaddr);
935 control |= HC_LAINT_ENA;
936 writel(control, phba->HCregaddr);
937 readl(phba->HCregaddr); /* flush */
938 spin_unlock_irq(&phba->hbalock);
James Smart1b32f6a2008-02-08 18:49:39 -0500939 mempool_free(pmb, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -0500940 return;
dea31012005-04-17 16:05:31 -0500941
dea31012005-04-17 16:05:31 -0500942out:
943 /* Device Discovery completes */
James Smarte8b62012007-08-02 11:10:09 -0400944 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
945 "0225 Device Discovery completes\n");
James Smart2e0fef82007-06-17 19:56:36 -0500946 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500947
James Smart2e0fef82007-06-17 19:56:36 -0500948 spin_lock_irq(shost->host_lock);
James Smart58da1ff2008-04-07 10:15:56 -0400949 vport->fc_flag &= ~FC_ABORT_DISCOVERY;
James Smart2e0fef82007-06-17 19:56:36 -0500950 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500951
James Smart2e0fef82007-06-17 19:56:36 -0500952 lpfc_can_disctmo(vport);
dea31012005-04-17 16:05:31 -0500953
954 /* turn on Link Attention interrupts */
James Smart2e0fef82007-06-17 19:56:36 -0500955
956 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500957 psli->sli_flag |= LPFC_PROCESS_LA;
958 control = readl(phba->HCregaddr);
959 control |= HC_LAINT_ENA;
960 writel(control, phba->HCregaddr);
961 readl(phba->HCregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -0500962 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500963
964 return;
965}
966
James Smart2e0fef82007-06-17 19:56:36 -0500967
dea31012005-04-17 16:05:31 -0500968static void
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500969lpfc_mbx_cmpl_local_config_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -0500970{
James Smart2e0fef82007-06-17 19:56:36 -0500971 struct lpfc_vport *vport = pmb->vport;
dea31012005-04-17 16:05:31 -0500972
James Smart04c68492009-05-22 14:52:52 -0400973 if (pmb->u.mb.mbxStatus)
dea31012005-04-17 16:05:31 -0500974 goto out;
dea31012005-04-17 16:05:31 -0500975
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500976 mempool_free(pmb, phba->mbox_mem_pool);
977
978 if (phba->fc_topology == TOPOLOGY_LOOP &&
James Smart2e0fef82007-06-17 19:56:36 -0500979 vport->fc_flag & FC_PUBLIC_LOOP &&
980 !(vport->fc_flag & FC_LBIT)) {
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500981 /* Need to wait for FAN - use discovery timer
James Smart2e0fef82007-06-17 19:56:36 -0500982 * for timeout. port_state is identically
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500983 * LPFC_LOCAL_CFG_LINK while waiting for FAN
984 */
James Smart2e0fef82007-06-17 19:56:36 -0500985 lpfc_set_disctmo(vport);
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500986 return;
James Smart92d7f7b2007-06-17 19:56:38 -0500987 }
dea31012005-04-17 16:05:31 -0500988
James Smart2e0fef82007-06-17 19:56:36 -0500989 /* Start discovery by sending a FLOGI. port_state is identically
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500990 * LPFC_FLOGI while waiting for FLOGI cmpl
991 */
James Smart92d7f7b2007-06-17 19:56:38 -0500992 if (vport->port_state != LPFC_FLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -0500993 lpfc_initial_flogi(vport);
994 }
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500995 return;
dea31012005-04-17 16:05:31 -0500996
997out:
James Smarte8b62012007-08-02 11:10:09 -0400998 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
999 "0306 CONFIG_LINK mbxStatus error x%x "
1000 "HBA state x%x\n",
James Smart04c68492009-05-22 14:52:52 -04001001 pmb->u.mb.mbxStatus, vport->port_state);
James Smart92d7f7b2007-06-17 19:56:38 -05001002 mempool_free(pmb, phba->mbox_mem_pool);
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001003
1004 lpfc_linkdown(phba);
1005
James Smarte8b62012007-08-02 11:10:09 -04001006 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
1007 "0200 CONFIG_LINK bad hba state x%x\n",
1008 vport->port_state);
dea31012005-04-17 16:05:31 -05001009
James Smart92d7f7b2007-06-17 19:56:38 -05001010 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -05001011 return;
1012}
1013
1014static void
James Smart6fb120a2009-05-22 14:52:59 -04001015lpfc_mbx_cmpl_reg_fcfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
1016{
1017 struct lpfc_vport *vport = mboxq->vport;
James Smart6fb120a2009-05-22 14:52:59 -04001018
1019 if (mboxq->u.mb.mbxStatus) {
1020 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
1021 "2017 REG_FCFI mbxStatus error x%x "
1022 "HBA state x%x\n",
1023 mboxq->u.mb.mbxStatus, vport->port_state);
1024 mempool_free(mboxq, phba->mbox_mem_pool);
1025 return;
1026 }
1027
1028 /* Start FCoE discovery by sending a FLOGI. */
1029 phba->fcf.fcfi = bf_get(lpfc_reg_fcfi_fcfi, &mboxq->u.mqe.un.reg_fcfi);
1030 /* Set the FCFI registered flag */
James Smartd439d282010-09-29 11:18:45 -04001031 spin_lock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04001032 phba->fcf.fcf_flag |= FCF_REGISTERED;
James Smartd439d282010-09-29 11:18:45 -04001033 spin_unlock_irq(&phba->hbalock);
James Smart32b97932009-07-19 10:01:21 -04001034 /* If there is a pending FCoE event, restart FCF table scan. */
1035 if (lpfc_check_pending_fcoe_event(phba, 1)) {
1036 mempool_free(mboxq, phba->mbox_mem_pool);
1037 return;
1038 }
James Smartd439d282010-09-29 11:18:45 -04001039 spin_lock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -05001040 phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE);
James Smart4d9ab992009-10-02 15:16:39 -04001041 phba->hba_flag &= ~FCF_DISC_INPROGRESS;
James Smartd439d282010-09-29 11:18:45 -04001042 spin_unlock_irq(&phba->hbalock);
James Smart1c6f4ef52009-11-18 15:40:49 -05001043 if (vport->port_state != LPFC_FLOGI)
James Smart6fb120a2009-05-22 14:52:59 -04001044 lpfc_initial_flogi(vport);
James Smart6fb120a2009-05-22 14:52:59 -04001045
1046 mempool_free(mboxq, phba->mbox_mem_pool);
1047 return;
1048}
1049
1050/**
1051 * lpfc_fab_name_match - Check if the fcf fabric name match.
1052 * @fab_name: pointer to fabric name.
1053 * @new_fcf_record: pointer to fcf record.
1054 *
1055 * This routine compare the fcf record's fabric name with provided
1056 * fabric name. If the fabric name are identical this function
1057 * returns 1 else return 0.
1058 **/
1059static uint32_t
1060lpfc_fab_name_match(uint8_t *fab_name, struct fcf_record *new_fcf_record)
1061{
James Smartecfd03c2010-02-12 14:41:27 -05001062 if (fab_name[0] != bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record))
James Smart6fb120a2009-05-22 14:52:59 -04001063 return 0;
James Smartecfd03c2010-02-12 14:41:27 -05001064 if (fab_name[1] != bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record))
1065 return 0;
1066 if (fab_name[2] != bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record))
1067 return 0;
1068 if (fab_name[3] != bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record))
1069 return 0;
1070 if (fab_name[4] != bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record))
1071 return 0;
1072 if (fab_name[5] != bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record))
1073 return 0;
1074 if (fab_name[6] != bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record))
1075 return 0;
1076 if (fab_name[7] != bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record))
1077 return 0;
1078 return 1;
James Smart6fb120a2009-05-22 14:52:59 -04001079}
1080
1081/**
James Smart8fa38512009-07-19 10:01:03 -04001082 * lpfc_sw_name_match - Check if the fcf switch name match.
1083 * @fab_name: pointer to fabric name.
1084 * @new_fcf_record: pointer to fcf record.
1085 *
1086 * This routine compare the fcf record's switch name with provided
1087 * switch name. If the switch name are identical this function
1088 * returns 1 else return 0.
1089 **/
1090static uint32_t
1091lpfc_sw_name_match(uint8_t *sw_name, struct fcf_record *new_fcf_record)
1092{
James Smartecfd03c2010-02-12 14:41:27 -05001093 if (sw_name[0] != bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record))
James Smart8fa38512009-07-19 10:01:03 -04001094 return 0;
James Smartecfd03c2010-02-12 14:41:27 -05001095 if (sw_name[1] != bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record))
1096 return 0;
1097 if (sw_name[2] != bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record))
1098 return 0;
1099 if (sw_name[3] != bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record))
1100 return 0;
1101 if (sw_name[4] != bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record))
1102 return 0;
1103 if (sw_name[5] != bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record))
1104 return 0;
1105 if (sw_name[6] != bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record))
1106 return 0;
1107 if (sw_name[7] != bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record))
1108 return 0;
1109 return 1;
James Smart8fa38512009-07-19 10:01:03 -04001110}
1111
1112/**
James Smart6fb120a2009-05-22 14:52:59 -04001113 * lpfc_mac_addr_match - Check if the fcf mac address match.
James Smartecfd03c2010-02-12 14:41:27 -05001114 * @mac_addr: pointer to mac address.
James Smart6fb120a2009-05-22 14:52:59 -04001115 * @new_fcf_record: pointer to fcf record.
1116 *
1117 * This routine compare the fcf record's mac address with HBA's
1118 * FCF mac address. If the mac addresses are identical this function
1119 * returns 1 else return 0.
1120 **/
1121static uint32_t
James Smartecfd03c2010-02-12 14:41:27 -05001122lpfc_mac_addr_match(uint8_t *mac_addr, struct fcf_record *new_fcf_record)
James Smart6fb120a2009-05-22 14:52:59 -04001123{
James Smartecfd03c2010-02-12 14:41:27 -05001124 if (mac_addr[0] != bf_get(lpfc_fcf_record_mac_0, new_fcf_record))
James Smart6fb120a2009-05-22 14:52:59 -04001125 return 0;
James Smartecfd03c2010-02-12 14:41:27 -05001126 if (mac_addr[1] != bf_get(lpfc_fcf_record_mac_1, new_fcf_record))
1127 return 0;
1128 if (mac_addr[2] != bf_get(lpfc_fcf_record_mac_2, new_fcf_record))
1129 return 0;
1130 if (mac_addr[3] != bf_get(lpfc_fcf_record_mac_3, new_fcf_record))
1131 return 0;
1132 if (mac_addr[4] != bf_get(lpfc_fcf_record_mac_4, new_fcf_record))
1133 return 0;
1134 if (mac_addr[5] != bf_get(lpfc_fcf_record_mac_5, new_fcf_record))
1135 return 0;
1136 return 1;
1137}
1138
1139static bool
1140lpfc_vlan_id_match(uint16_t curr_vlan_id, uint16_t new_vlan_id)
1141{
1142 return (curr_vlan_id == new_vlan_id);
James Smart6fb120a2009-05-22 14:52:59 -04001143}
1144
1145/**
1146 * lpfc_copy_fcf_record - Copy fcf information to lpfc_hba.
James Smartecfd03c2010-02-12 14:41:27 -05001147 * @fcf: pointer to driver fcf record.
James Smart6fb120a2009-05-22 14:52:59 -04001148 * @new_fcf_record: pointer to fcf record.
1149 *
1150 * This routine copies the FCF information from the FCF
1151 * record to lpfc_hba data structure.
1152 **/
1153static void
James Smartecfd03c2010-02-12 14:41:27 -05001154lpfc_copy_fcf_record(struct lpfc_fcf_rec *fcf_rec,
1155 struct fcf_record *new_fcf_record)
James Smart6fb120a2009-05-22 14:52:59 -04001156{
James Smartecfd03c2010-02-12 14:41:27 -05001157 /* Fabric name */
1158 fcf_rec->fabric_name[0] =
James Smart6fb120a2009-05-22 14:52:59 -04001159 bf_get(lpfc_fcf_record_fab_name_0, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001160 fcf_rec->fabric_name[1] =
James Smart6fb120a2009-05-22 14:52:59 -04001161 bf_get(lpfc_fcf_record_fab_name_1, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001162 fcf_rec->fabric_name[2] =
James Smart6fb120a2009-05-22 14:52:59 -04001163 bf_get(lpfc_fcf_record_fab_name_2, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001164 fcf_rec->fabric_name[3] =
James Smart6fb120a2009-05-22 14:52:59 -04001165 bf_get(lpfc_fcf_record_fab_name_3, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001166 fcf_rec->fabric_name[4] =
James Smart6fb120a2009-05-22 14:52:59 -04001167 bf_get(lpfc_fcf_record_fab_name_4, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001168 fcf_rec->fabric_name[5] =
James Smart6fb120a2009-05-22 14:52:59 -04001169 bf_get(lpfc_fcf_record_fab_name_5, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001170 fcf_rec->fabric_name[6] =
James Smart6fb120a2009-05-22 14:52:59 -04001171 bf_get(lpfc_fcf_record_fab_name_6, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001172 fcf_rec->fabric_name[7] =
James Smart6fb120a2009-05-22 14:52:59 -04001173 bf_get(lpfc_fcf_record_fab_name_7, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001174 /* Mac address */
1175 fcf_rec->mac_addr[0] = bf_get(lpfc_fcf_record_mac_0, new_fcf_record);
1176 fcf_rec->mac_addr[1] = bf_get(lpfc_fcf_record_mac_1, new_fcf_record);
1177 fcf_rec->mac_addr[2] = bf_get(lpfc_fcf_record_mac_2, new_fcf_record);
1178 fcf_rec->mac_addr[3] = bf_get(lpfc_fcf_record_mac_3, new_fcf_record);
1179 fcf_rec->mac_addr[4] = bf_get(lpfc_fcf_record_mac_4, new_fcf_record);
1180 fcf_rec->mac_addr[5] = bf_get(lpfc_fcf_record_mac_5, new_fcf_record);
1181 /* FCF record index */
1182 fcf_rec->fcf_indx = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
1183 /* FCF record priority */
1184 fcf_rec->priority = new_fcf_record->fip_priority;
1185 /* Switch name */
1186 fcf_rec->switch_name[0] =
James Smart8fa38512009-07-19 10:01:03 -04001187 bf_get(lpfc_fcf_record_switch_name_0, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001188 fcf_rec->switch_name[1] =
James Smart8fa38512009-07-19 10:01:03 -04001189 bf_get(lpfc_fcf_record_switch_name_1, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001190 fcf_rec->switch_name[2] =
James Smart8fa38512009-07-19 10:01:03 -04001191 bf_get(lpfc_fcf_record_switch_name_2, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001192 fcf_rec->switch_name[3] =
James Smart8fa38512009-07-19 10:01:03 -04001193 bf_get(lpfc_fcf_record_switch_name_3, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001194 fcf_rec->switch_name[4] =
James Smart8fa38512009-07-19 10:01:03 -04001195 bf_get(lpfc_fcf_record_switch_name_4, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001196 fcf_rec->switch_name[5] =
James Smart8fa38512009-07-19 10:01:03 -04001197 bf_get(lpfc_fcf_record_switch_name_5, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001198 fcf_rec->switch_name[6] =
James Smart8fa38512009-07-19 10:01:03 -04001199 bf_get(lpfc_fcf_record_switch_name_6, new_fcf_record);
James Smartecfd03c2010-02-12 14:41:27 -05001200 fcf_rec->switch_name[7] =
James Smart8fa38512009-07-19 10:01:03 -04001201 bf_get(lpfc_fcf_record_switch_name_7, new_fcf_record);
James Smart6fb120a2009-05-22 14:52:59 -04001202}
1203
1204/**
James Smartecfd03c2010-02-12 14:41:27 -05001205 * lpfc_update_fcf_record - Update driver fcf record
1206 * @phba: pointer to lpfc hba data structure.
1207 * @fcf_rec: pointer to driver fcf record.
1208 * @new_fcf_record: pointer to hba fcf record.
1209 * @addr_mode: address mode to be set to the driver fcf record.
1210 * @vlan_id: vlan tag to be set to the driver fcf record.
1211 * @flag: flag bits to be set to the driver fcf record.
1212 *
1213 * This routine updates the driver FCF record from the new HBA FCF record
1214 * together with the address mode, vlan_id, and other informations. This
1215 * routine is called with the host lock held.
1216 **/
1217static void
1218__lpfc_update_fcf_record(struct lpfc_hba *phba, struct lpfc_fcf_rec *fcf_rec,
1219 struct fcf_record *new_fcf_record, uint32_t addr_mode,
1220 uint16_t vlan_id, uint32_t flag)
1221{
1222 /* Copy the fields from the HBA's FCF record */
1223 lpfc_copy_fcf_record(fcf_rec, new_fcf_record);
1224 /* Update other fields of driver FCF record */
1225 fcf_rec->addr_mode = addr_mode;
1226 fcf_rec->vlan_id = vlan_id;
1227 fcf_rec->flag |= (flag | RECORD_VALID);
1228}
1229
1230/**
James Smart6fb120a2009-05-22 14:52:59 -04001231 * lpfc_register_fcf - Register the FCF with hba.
1232 * @phba: pointer to lpfc hba data structure.
1233 *
1234 * This routine issues a register fcfi mailbox command to register
1235 * the fcf with HBA.
1236 **/
1237static void
1238lpfc_register_fcf(struct lpfc_hba *phba)
1239{
1240 LPFC_MBOXQ_t *fcf_mbxq;
1241 int rc;
James Smart6fb120a2009-05-22 14:52:59 -04001242
James Smartd439d282010-09-29 11:18:45 -04001243 spin_lock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04001244
1245 /* If the FCF is not availabe do nothing. */
1246 if (!(phba->fcf.fcf_flag & FCF_AVAILABLE)) {
James Smart4d9ab992009-10-02 15:16:39 -04001247 phba->hba_flag &= ~FCF_DISC_INPROGRESS;
James Smartd439d282010-09-29 11:18:45 -04001248 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04001249 return;
1250 }
1251
1252 /* The FCF is already registered, start discovery */
1253 if (phba->fcf.fcf_flag & FCF_REGISTERED) {
James Smartecfd03c2010-02-12 14:41:27 -05001254 phba->fcf.fcf_flag |= (FCF_SCAN_DONE | FCF_IN_USE);
James Smart32b97932009-07-19 10:01:21 -04001255 phba->hba_flag &= ~FCF_DISC_INPROGRESS;
James Smartd439d282010-09-29 11:18:45 -04001256 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04001257 if (phba->pport->port_state != LPFC_FLOGI)
1258 lpfc_initial_flogi(phba->pport);
1259 return;
1260 }
James Smartd439d282010-09-29 11:18:45 -04001261 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04001262
1263 fcf_mbxq = mempool_alloc(phba->mbox_mem_pool,
1264 GFP_KERNEL);
James Smart4d9ab992009-10-02 15:16:39 -04001265 if (!fcf_mbxq) {
James Smartd439d282010-09-29 11:18:45 -04001266 spin_lock_irq(&phba->hbalock);
James Smart4d9ab992009-10-02 15:16:39 -04001267 phba->hba_flag &= ~FCF_DISC_INPROGRESS;
James Smartd439d282010-09-29 11:18:45 -04001268 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04001269 return;
James Smart4d9ab992009-10-02 15:16:39 -04001270 }
James Smart6fb120a2009-05-22 14:52:59 -04001271
1272 lpfc_reg_fcfi(phba, fcf_mbxq);
1273 fcf_mbxq->vport = phba->pport;
1274 fcf_mbxq->mbox_cmpl = lpfc_mbx_cmpl_reg_fcfi;
1275 rc = lpfc_sli_issue_mbox(phba, fcf_mbxq, MBX_NOWAIT);
James Smart4d9ab992009-10-02 15:16:39 -04001276 if (rc == MBX_NOT_FINISHED) {
James Smartd439d282010-09-29 11:18:45 -04001277 spin_lock_irq(&phba->hbalock);
James Smart4d9ab992009-10-02 15:16:39 -04001278 phba->hba_flag &= ~FCF_DISC_INPROGRESS;
James Smartd439d282010-09-29 11:18:45 -04001279 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04001280 mempool_free(fcf_mbxq, phba->mbox_mem_pool);
James Smart4d9ab992009-10-02 15:16:39 -04001281 }
James Smart6fb120a2009-05-22 14:52:59 -04001282
1283 return;
1284}
1285
1286/**
1287 * lpfc_match_fcf_conn_list - Check if the FCF record can be used for discovery.
1288 * @phba: pointer to lpfc hba data structure.
1289 * @new_fcf_record: pointer to fcf record.
1290 * @boot_flag: Indicates if this record used by boot bios.
1291 * @addr_mode: The address mode to be used by this FCF
James Smartecfd03c2010-02-12 14:41:27 -05001292 * @vlan_id: The vlan id to be used as vlan tagging by this FCF.
James Smart6fb120a2009-05-22 14:52:59 -04001293 *
1294 * This routine compare the fcf record with connect list obtained from the
1295 * config region to decide if this FCF can be used for SAN discovery. It returns
1296 * 1 if this record can be used for SAN discovery else return zero. If this FCF
1297 * record can be used for SAN discovery, the boot_flag will indicate if this FCF
1298 * is used by boot bios and addr_mode will indicate the addressing mode to be
1299 * used for this FCF when the function returns.
1300 * If the FCF record need to be used with a particular vlan id, the vlan is
1301 * set in the vlan_id on return of the function. If not VLAN tagging need to
James Smartdbb6b3a2010-06-08 18:31:37 -04001302 * be used with the FCF vlan_id will be set to LPFC_FCOE_NULL_VID;
James Smart6fb120a2009-05-22 14:52:59 -04001303 **/
1304static int
1305lpfc_match_fcf_conn_list(struct lpfc_hba *phba,
1306 struct fcf_record *new_fcf_record,
1307 uint32_t *boot_flag, uint32_t *addr_mode,
1308 uint16_t *vlan_id)
1309{
1310 struct lpfc_fcf_conn_entry *conn_entry;
James Smart4d9ab992009-10-02 15:16:39 -04001311 int i, j, fcf_vlan_id = 0;
1312
1313 /* Find the lowest VLAN id in the FCF record */
1314 for (i = 0; i < 512; i++) {
1315 if (new_fcf_record->vlan_bitmap[i]) {
1316 fcf_vlan_id = i * 8;
1317 j = 0;
1318 while (!((new_fcf_record->vlan_bitmap[i] >> j) & 1)) {
1319 j++;
1320 fcf_vlan_id++;
1321 }
1322 break;
1323 }
1324 }
James Smart6fb120a2009-05-22 14:52:59 -04001325
James Smart0c287582009-06-10 17:22:56 -04001326 /* If FCF not available return 0 */
1327 if (!bf_get(lpfc_fcf_record_fcf_avail, new_fcf_record) ||
1328 !bf_get(lpfc_fcf_record_fcf_valid, new_fcf_record))
1329 return 0;
1330
James Smart45ed1192009-10-02 15:17:02 -04001331 if (!(phba->hba_flag & HBA_FIP_SUPPORT)) {
James Smart6fb120a2009-05-22 14:52:59 -04001332 *boot_flag = 0;
1333 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1334 new_fcf_record);
1335 if (phba->valid_vlan)
1336 *vlan_id = phba->vlan_id;
1337 else
James Smartdbb6b3a2010-06-08 18:31:37 -04001338 *vlan_id = LPFC_FCOE_NULL_VID;
James Smart6fb120a2009-05-22 14:52:59 -04001339 return 1;
1340 }
1341
1342 /*
1343 * If there are no FCF connection table entry, driver connect to all
1344 * FCFs.
1345 */
1346 if (list_empty(&phba->fcf_conn_rec_list)) {
1347 *boot_flag = 0;
1348 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1349 new_fcf_record);
James Smart0c287582009-06-10 17:22:56 -04001350
1351 /*
1352 * When there are no FCF connect entries, use driver's default
1353 * addressing mode - FPMA.
1354 */
1355 if (*addr_mode & LPFC_FCF_FPMA)
1356 *addr_mode = LPFC_FCF_FPMA;
1357
James Smart4d9ab992009-10-02 15:16:39 -04001358 /* If FCF record report a vlan id use that vlan id */
1359 if (fcf_vlan_id)
1360 *vlan_id = fcf_vlan_id;
1361 else
James Smartdbb6b3a2010-06-08 18:31:37 -04001362 *vlan_id = LPFC_FCOE_NULL_VID;
James Smart6fb120a2009-05-22 14:52:59 -04001363 return 1;
1364 }
1365
James Smartecfd03c2010-02-12 14:41:27 -05001366 list_for_each_entry(conn_entry,
1367 &phba->fcf_conn_rec_list, list) {
James Smart6fb120a2009-05-22 14:52:59 -04001368 if (!(conn_entry->conn_rec.flags & FCFCNCT_VALID))
1369 continue;
1370
1371 if ((conn_entry->conn_rec.flags & FCFCNCT_FBNM_VALID) &&
1372 !lpfc_fab_name_match(conn_entry->conn_rec.fabric_name,
James Smart8fa38512009-07-19 10:01:03 -04001373 new_fcf_record))
James Smart6fb120a2009-05-22 14:52:59 -04001374 continue;
James Smart8fa38512009-07-19 10:01:03 -04001375 if ((conn_entry->conn_rec.flags & FCFCNCT_SWNM_VALID) &&
1376 !lpfc_sw_name_match(conn_entry->conn_rec.switch_name,
1377 new_fcf_record))
1378 continue;
James Smart6fb120a2009-05-22 14:52:59 -04001379 if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID) {
1380 /*
1381 * If the vlan bit map does not have the bit set for the
1382 * vlan id to be used, then it is not a match.
1383 */
1384 if (!(new_fcf_record->vlan_bitmap
1385 [conn_entry->conn_rec.vlan_tag / 8] &
1386 (1 << (conn_entry->conn_rec.vlan_tag % 8))))
1387 continue;
1388 }
1389
1390 /*
James Smart0c287582009-06-10 17:22:56 -04001391 * If connection record does not support any addressing mode,
1392 * skip the FCF record.
1393 */
1394 if (!(bf_get(lpfc_fcf_record_mac_addr_prov, new_fcf_record)
1395 & (LPFC_FCF_FPMA | LPFC_FCF_SPMA)))
1396 continue;
1397
1398 /*
James Smart6fb120a2009-05-22 14:52:59 -04001399 * Check if the connection record specifies a required
1400 * addressing mode.
1401 */
1402 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1403 !(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)) {
1404
1405 /*
1406 * If SPMA required but FCF not support this continue.
1407 */
1408 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1409 !(bf_get(lpfc_fcf_record_mac_addr_prov,
1410 new_fcf_record) & LPFC_FCF_SPMA))
1411 continue;
1412
1413 /*
1414 * If FPMA required but FCF not support this continue.
1415 */
1416 if (!(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1417 !(bf_get(lpfc_fcf_record_mac_addr_prov,
1418 new_fcf_record) & LPFC_FCF_FPMA))
1419 continue;
1420 }
1421
1422 /*
1423 * This fcf record matches filtering criteria.
1424 */
1425 if (conn_entry->conn_rec.flags & FCFCNCT_BOOT)
1426 *boot_flag = 1;
1427 else
1428 *boot_flag = 0;
1429
James Smart0c287582009-06-10 17:22:56 -04001430 /*
1431 * If user did not specify any addressing mode, or if the
1432 * prefered addressing mode specified by user is not supported
1433 * by FCF, allow fabric to pick the addressing mode.
1434 */
James Smart6fb120a2009-05-22 14:52:59 -04001435 *addr_mode = bf_get(lpfc_fcf_record_mac_addr_prov,
1436 new_fcf_record);
1437 /*
1438 * If the user specified a required address mode, assign that
1439 * address mode
1440 */
1441 if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1442 (!(conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED)))
1443 *addr_mode = (conn_entry->conn_rec.flags &
1444 FCFCNCT_AM_SPMA) ?
1445 LPFC_FCF_SPMA : LPFC_FCF_FPMA;
1446 /*
1447 * If the user specified a prefered address mode, use the
1448 * addr mode only if FCF support the addr_mode.
1449 */
1450 else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1451 (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) &&
1452 (conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1453 (*addr_mode & LPFC_FCF_SPMA))
1454 *addr_mode = LPFC_FCF_SPMA;
1455 else if ((conn_entry->conn_rec.flags & FCFCNCT_AM_VALID) &&
1456 (conn_entry->conn_rec.flags & FCFCNCT_AM_PREFERRED) &&
1457 !(conn_entry->conn_rec.flags & FCFCNCT_AM_SPMA) &&
1458 (*addr_mode & LPFC_FCF_FPMA))
1459 *addr_mode = LPFC_FCF_FPMA;
James Smart6fb120a2009-05-22 14:52:59 -04001460
James Smart4d9ab992009-10-02 15:16:39 -04001461 /* If matching connect list has a vlan id, use it */
James Smart6fb120a2009-05-22 14:52:59 -04001462 if (conn_entry->conn_rec.flags & FCFCNCT_VLAN_VALID)
1463 *vlan_id = conn_entry->conn_rec.vlan_tag;
James Smart4d9ab992009-10-02 15:16:39 -04001464 /*
1465 * If no vlan id is specified in connect list, use the vlan id
1466 * in the FCF record
1467 */
1468 else if (fcf_vlan_id)
1469 *vlan_id = fcf_vlan_id;
James Smart6fb120a2009-05-22 14:52:59 -04001470 else
James Smartdbb6b3a2010-06-08 18:31:37 -04001471 *vlan_id = LPFC_FCOE_NULL_VID;
James Smart6fb120a2009-05-22 14:52:59 -04001472
1473 return 1;
1474 }
1475
1476 return 0;
1477}
1478
1479/**
James Smart32b97932009-07-19 10:01:21 -04001480 * lpfc_check_pending_fcoe_event - Check if there is pending fcoe event.
1481 * @phba: pointer to lpfc hba data structure.
1482 * @unreg_fcf: Unregister FCF if FCF table need to be re-scaned.
1483 *
1484 * This function check if there is any fcoe event pending while driver
1485 * scan FCF entries. If there is any pending event, it will restart the
1486 * FCF saning and return 1 else return 0.
1487 */
1488int
1489lpfc_check_pending_fcoe_event(struct lpfc_hba *phba, uint8_t unreg_fcf)
1490{
James Smart32b97932009-07-19 10:01:21 -04001491 /*
1492 * If the Link is up and no FCoE events while in the
1493 * FCF discovery, no need to restart FCF discovery.
1494 */
1495 if ((phba->link_state >= LPFC_LINK_UP) &&
1496 (phba->fcoe_eventtag == phba->fcoe_eventtag_at_fcf_scan))
1497 return 0;
1498
James Smart0c9ab6f2010-02-26 14:15:57 -05001499 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
1500 "2768 Pending link or FCF event during current "
1501 "handling of the previous event: link_state:x%x, "
1502 "evt_tag_at_scan:x%x, evt_tag_current:x%x\n",
1503 phba->link_state, phba->fcoe_eventtag_at_fcf_scan,
1504 phba->fcoe_eventtag);
1505
James Smart32b97932009-07-19 10:01:21 -04001506 spin_lock_irq(&phba->hbalock);
1507 phba->fcf.fcf_flag &= ~FCF_AVAILABLE;
1508 spin_unlock_irq(&phba->hbalock);
1509
James Smart0c9ab6f2010-02-26 14:15:57 -05001510 if (phba->link_state >= LPFC_LINK_UP) {
1511 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
1512 "2780 Restart FCF table scan due to "
1513 "pending FCF event:evt_tag_at_scan:x%x, "
1514 "evt_tag_current:x%x\n",
1515 phba->fcoe_eventtag_at_fcf_scan,
1516 phba->fcoe_eventtag);
1517 lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
1518 } else {
James Smart4d9ab992009-10-02 15:16:39 -04001519 /*
1520 * Do not continue FCF discovery and clear FCF_DISC_INPROGRESS
1521 * flag
1522 */
James Smartdbb6b3a2010-06-08 18:31:37 -04001523 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
1524 "2833 Stop FCF discovery process due to link "
1525 "state change (x%x)\n", phba->link_state);
James Smart1c6f4ef52009-11-18 15:40:49 -05001526 spin_lock_irq(&phba->hbalock);
James Smart4d9ab992009-10-02 15:16:39 -04001527 phba->hba_flag &= ~FCF_DISC_INPROGRESS;
James Smart0c9ab6f2010-02-26 14:15:57 -05001528 phba->fcf.fcf_flag &= ~(FCF_REDISC_FOV | FCF_DISCOVERY);
James Smart1c6f4ef52009-11-18 15:40:49 -05001529 spin_unlock_irq(&phba->hbalock);
1530 }
James Smart32b97932009-07-19 10:01:21 -04001531
James Smart0c9ab6f2010-02-26 14:15:57 -05001532 /* Unregister the currently registered FCF if required */
James Smart32b97932009-07-19 10:01:21 -04001533 if (unreg_fcf) {
1534 spin_lock_irq(&phba->hbalock);
1535 phba->fcf.fcf_flag &= ~FCF_REGISTERED;
1536 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05001537 lpfc_sli4_unregister_fcf(phba);
James Smart32b97932009-07-19 10:01:21 -04001538 }
James Smart32b97932009-07-19 10:01:21 -04001539 return 1;
1540}
1541
1542/**
James Smart999d8132010-03-15 11:24:56 -04001543 * lpfc_sli4_new_fcf_random_select - Randomly select an eligible new fcf record
1544 * @phba: pointer to lpfc hba data structure.
1545 * @fcf_cnt: number of eligible fcf record seen so far.
1546 *
1547 * This function makes an running random selection decision on FCF record to
1548 * use through a sequence of @fcf_cnt eligible FCF records with equal
1549 * probability. To perform integer manunipulation of random numbers with
1550 * size unit32_t, the lower 16 bits of the 32-bit random number returned
1551 * from random32() are taken as the random random number generated.
1552 *
1553 * Returns true when outcome is for the newly read FCF record should be
1554 * chosen; otherwise, return false when outcome is for keeping the previously
1555 * chosen FCF record.
1556 **/
1557static bool
1558lpfc_sli4_new_fcf_random_select(struct lpfc_hba *phba, uint32_t fcf_cnt)
1559{
1560 uint32_t rand_num;
1561
1562 /* Get 16-bit uniform random number */
1563 rand_num = (0xFFFF & random32());
1564
1565 /* Decision with probability 1/fcf_cnt */
1566 if ((fcf_cnt * rand_num) < 0xFFFF)
1567 return true;
1568 else
1569 return false;
1570}
1571
1572/**
James Smart3804dc82010-07-14 15:31:37 -04001573 * lpfc_sli4_fcf_rec_mbox_parse - Parse read_fcf mbox command.
James Smart6fb120a2009-05-22 14:52:59 -04001574 * @phba: pointer to lpfc hba data structure.
1575 * @mboxq: pointer to mailbox object.
James Smart0c9ab6f2010-02-26 14:15:57 -05001576 * @next_fcf_index: pointer to holder of next fcf index.
James Smart6fb120a2009-05-22 14:52:59 -04001577 *
James Smart0c9ab6f2010-02-26 14:15:57 -05001578 * This routine parses the non-embedded fcf mailbox command by performing the
1579 * necessarily error checking, non-embedded read FCF record mailbox command
1580 * SGE parsing, and endianness swapping.
1581 *
1582 * Returns the pointer to the new FCF record in the non-embedded mailbox
1583 * command DMA memory if successfully, other NULL.
James Smart6fb120a2009-05-22 14:52:59 -04001584 */
James Smart0c9ab6f2010-02-26 14:15:57 -05001585static struct fcf_record *
1586lpfc_sli4_fcf_rec_mbox_parse(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq,
1587 uint16_t *next_fcf_index)
James Smart6fb120a2009-05-22 14:52:59 -04001588{
1589 void *virt_addr;
1590 dma_addr_t phys_addr;
James Smart6fb120a2009-05-22 14:52:59 -04001591 struct lpfc_mbx_sge sge;
1592 struct lpfc_mbx_read_fcf_tbl *read_fcf;
1593 uint32_t shdr_status, shdr_add_status;
1594 union lpfc_sli4_cfg_shdr *shdr;
1595 struct fcf_record *new_fcf_record;
James Smart32b97932009-07-19 10:01:21 -04001596
James Smart6fb120a2009-05-22 14:52:59 -04001597 /* Get the first SGE entry from the non-embedded DMA memory. This
1598 * routine only uses a single SGE.
1599 */
1600 lpfc_sli4_mbx_sge_get(mboxq, 0, &sge);
1601 phys_addr = getPaddr(sge.pa_hi, sge.pa_lo);
1602 if (unlikely(!mboxq->sge_array)) {
1603 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1604 "2524 Failed to get the non-embedded SGE "
1605 "virtual address\n");
James Smart0c9ab6f2010-02-26 14:15:57 -05001606 return NULL;
James Smart6fb120a2009-05-22 14:52:59 -04001607 }
1608 virt_addr = mboxq->sge_array->addr[0];
1609
1610 shdr = (union lpfc_sli4_cfg_shdr *)virt_addr;
1611 shdr_status = bf_get(lpfc_mbox_hdr_status, &shdr->response);
James Smart0c9ab6f2010-02-26 14:15:57 -05001612 shdr_add_status = bf_get(lpfc_mbox_hdr_add_status, &shdr->response);
James Smart6fb120a2009-05-22 14:52:59 -04001613 if (shdr_status || shdr_add_status) {
James Smart0c9ab6f2010-02-26 14:15:57 -05001614 if (shdr_status == STATUS_FCF_TABLE_EMPTY)
1615 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
James Smartdef9c7a2009-12-21 17:02:28 -05001616 "2726 READ_FCF_RECORD Indicates empty "
1617 "FCF table.\n");
James Smart0c9ab6f2010-02-26 14:15:57 -05001618 else
1619 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
James Smartdef9c7a2009-12-21 17:02:28 -05001620 "2521 READ_FCF_RECORD mailbox failed "
James Smart0c9ab6f2010-02-26 14:15:57 -05001621 "with status x%x add_status x%x, "
1622 "mbx\n", shdr_status, shdr_add_status);
1623 return NULL;
James Smart6fb120a2009-05-22 14:52:59 -04001624 }
James Smart0c9ab6f2010-02-26 14:15:57 -05001625
1626 /* Interpreting the returned information of the FCF record */
James Smart6fb120a2009-05-22 14:52:59 -04001627 read_fcf = (struct lpfc_mbx_read_fcf_tbl *)virt_addr;
1628 lpfc_sli_pcimem_bcopy(read_fcf, read_fcf,
1629 sizeof(struct lpfc_mbx_read_fcf_tbl));
James Smart0c9ab6f2010-02-26 14:15:57 -05001630 *next_fcf_index = bf_get(lpfc_mbx_read_fcf_tbl_nxt_vindx, read_fcf);
James Smart6fb120a2009-05-22 14:52:59 -04001631 new_fcf_record = (struct fcf_record *)(virt_addr +
1632 sizeof(struct lpfc_mbx_read_fcf_tbl));
1633 lpfc_sli_pcimem_bcopy(new_fcf_record, new_fcf_record,
James Smartcb5172e2010-03-15 11:25:07 -04001634 offsetof(struct fcf_record, vlan_bitmap));
1635 new_fcf_record->word137 = le32_to_cpu(new_fcf_record->word137);
1636 new_fcf_record->word138 = le32_to_cpu(new_fcf_record->word138);
James Smart6fb120a2009-05-22 14:52:59 -04001637
James Smart0c9ab6f2010-02-26 14:15:57 -05001638 return new_fcf_record;
1639}
1640
1641/**
1642 * lpfc_sli4_log_fcf_record_info - Log the information of a fcf record
1643 * @phba: pointer to lpfc hba data structure.
1644 * @fcf_record: pointer to the fcf record.
1645 * @vlan_id: the lowest vlan identifier associated to this fcf record.
1646 * @next_fcf_index: the index to the next fcf record in hba's fcf table.
1647 *
1648 * This routine logs the detailed FCF record if the LOG_FIP loggin is
1649 * enabled.
1650 **/
1651static void
1652lpfc_sli4_log_fcf_record_info(struct lpfc_hba *phba,
1653 struct fcf_record *fcf_record,
1654 uint16_t vlan_id,
1655 uint16_t next_fcf_index)
1656{
1657 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
1658 "2764 READ_FCF_RECORD:\n"
1659 "\tFCF_Index : x%x\n"
1660 "\tFCF_Avail : x%x\n"
1661 "\tFCF_Valid : x%x\n"
1662 "\tFIP_Priority : x%x\n"
1663 "\tMAC_Provider : x%x\n"
1664 "\tLowest VLANID : x%x\n"
1665 "\tFCF_MAC Addr : x%x:%x:%x:%x:%x:%x\n"
1666 "\tFabric_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n"
1667 "\tSwitch_Name : x%x:%x:%x:%x:%x:%x:%x:%x\n"
1668 "\tNext_FCF_Index: x%x\n",
1669 bf_get(lpfc_fcf_record_fcf_index, fcf_record),
1670 bf_get(lpfc_fcf_record_fcf_avail, fcf_record),
1671 bf_get(lpfc_fcf_record_fcf_valid, fcf_record),
1672 fcf_record->fip_priority,
1673 bf_get(lpfc_fcf_record_mac_addr_prov, fcf_record),
1674 vlan_id,
1675 bf_get(lpfc_fcf_record_mac_0, fcf_record),
1676 bf_get(lpfc_fcf_record_mac_1, fcf_record),
1677 bf_get(lpfc_fcf_record_mac_2, fcf_record),
1678 bf_get(lpfc_fcf_record_mac_3, fcf_record),
1679 bf_get(lpfc_fcf_record_mac_4, fcf_record),
1680 bf_get(lpfc_fcf_record_mac_5, fcf_record),
1681 bf_get(lpfc_fcf_record_fab_name_0, fcf_record),
1682 bf_get(lpfc_fcf_record_fab_name_1, fcf_record),
1683 bf_get(lpfc_fcf_record_fab_name_2, fcf_record),
1684 bf_get(lpfc_fcf_record_fab_name_3, fcf_record),
1685 bf_get(lpfc_fcf_record_fab_name_4, fcf_record),
1686 bf_get(lpfc_fcf_record_fab_name_5, fcf_record),
1687 bf_get(lpfc_fcf_record_fab_name_6, fcf_record),
1688 bf_get(lpfc_fcf_record_fab_name_7, fcf_record),
1689 bf_get(lpfc_fcf_record_switch_name_0, fcf_record),
1690 bf_get(lpfc_fcf_record_switch_name_1, fcf_record),
1691 bf_get(lpfc_fcf_record_switch_name_2, fcf_record),
1692 bf_get(lpfc_fcf_record_switch_name_3, fcf_record),
1693 bf_get(lpfc_fcf_record_switch_name_4, fcf_record),
1694 bf_get(lpfc_fcf_record_switch_name_5, fcf_record),
1695 bf_get(lpfc_fcf_record_switch_name_6, fcf_record),
1696 bf_get(lpfc_fcf_record_switch_name_7, fcf_record),
1697 next_fcf_index);
1698}
1699
1700/**
James Smartdbb6b3a2010-06-08 18:31:37 -04001701 lpfc_sli4_fcf_record_match - testing new FCF record for matching existing FCF
1702 * @phba: pointer to lpfc hba data structure.
1703 * @fcf_rec: pointer to an existing FCF record.
1704 * @new_fcf_record: pointer to a new FCF record.
1705 * @new_vlan_id: vlan id from the new FCF record.
1706 *
1707 * This function performs matching test of a new FCF record against an existing
1708 * FCF record. If the new_vlan_id passed in is LPFC_FCOE_IGNORE_VID, vlan id
1709 * will not be used as part of the FCF record matching criteria.
1710 *
1711 * Returns true if all the fields matching, otherwise returns false.
1712 */
1713static bool
1714lpfc_sli4_fcf_record_match(struct lpfc_hba *phba,
1715 struct lpfc_fcf_rec *fcf_rec,
1716 struct fcf_record *new_fcf_record,
1717 uint16_t new_vlan_id)
1718{
1719 if (new_vlan_id != LPFC_FCOE_IGNORE_VID)
1720 if (!lpfc_vlan_id_match(fcf_rec->vlan_id, new_vlan_id))
1721 return false;
1722 if (!lpfc_mac_addr_match(fcf_rec->mac_addr, new_fcf_record))
1723 return false;
1724 if (!lpfc_sw_name_match(fcf_rec->switch_name, new_fcf_record))
1725 return false;
1726 if (!lpfc_fab_name_match(fcf_rec->fabric_name, new_fcf_record))
1727 return false;
1728 return true;
1729}
1730
1731/**
James Smart0c9ab6f2010-02-26 14:15:57 -05001732 * lpfc_mbx_cmpl_fcf_scan_read_fcf_rec - fcf scan read_fcf mbox cmpl handler.
1733 * @phba: pointer to lpfc hba data structure.
1734 * @mboxq: pointer to mailbox object.
1735 *
1736 * This function iterates through all the fcf records available in
1737 * HBA and chooses the optimal FCF record for discovery. After finding
1738 * the FCF for discovery it registers the FCF record and kicks start
1739 * discovery.
1740 * If FCF_IN_USE flag is set in currently used FCF, the routine tries to
1741 * use an FCF record which matches fabric name and mac address of the
1742 * currently used FCF record.
1743 * If the driver supports only one FCF, it will try to use the FCF record
1744 * used by BOOT_BIOS.
1745 */
1746void
1747lpfc_mbx_cmpl_fcf_scan_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
1748{
1749 struct fcf_record *new_fcf_record;
1750 uint32_t boot_flag, addr_mode;
1751 uint16_t fcf_index, next_fcf_index;
1752 struct lpfc_fcf_rec *fcf_rec = NULL;
1753 uint16_t vlan_id;
James Smart999d8132010-03-15 11:24:56 -04001754 uint32_t seed;
1755 bool select_new_fcf;
James Smart0c9ab6f2010-02-26 14:15:57 -05001756 int rc;
1757
1758 /* If there is pending FCoE event restart FCF table scan */
1759 if (lpfc_check_pending_fcoe_event(phba, 0)) {
1760 lpfc_sli4_mbox_cmd_free(phba, mboxq);
1761 return;
1762 }
1763
1764 /* Parse the FCF record from the non-embedded mailbox command */
1765 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
1766 &next_fcf_index);
1767 if (!new_fcf_record) {
1768 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
1769 "2765 Mailbox command READ_FCF_RECORD "
1770 "failed to retrieve a FCF record.\n");
1771 /* Let next new FCF event trigger fast failover */
1772 spin_lock_irq(&phba->hbalock);
1773 phba->hba_flag &= ~FCF_DISC_INPROGRESS;
1774 spin_unlock_irq(&phba->hbalock);
1775 lpfc_sli4_mbox_cmd_free(phba, mboxq);
1776 return;
1777 }
1778
1779 /* Check the FCF record against the connection list */
James Smartecfd03c2010-02-12 14:41:27 -05001780 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
1781 &addr_mode, &vlan_id);
James Smart0c9ab6f2010-02-26 14:15:57 -05001782
1783 /* Log the FCF record information if turned on */
1784 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
1785 next_fcf_index);
1786
James Smart6fb120a2009-05-22 14:52:59 -04001787 /*
1788 * If the fcf record does not match with connect list entries
James Smart0c9ab6f2010-02-26 14:15:57 -05001789 * read the next entry; otherwise, this is an eligible FCF
1790 * record for round robin FCF failover.
James Smart6fb120a2009-05-22 14:52:59 -04001791 */
James Smart0c9ab6f2010-02-26 14:15:57 -05001792 if (!rc) {
1793 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
James Smartdbb6b3a2010-06-08 18:31:37 -04001794 "2781 FCF record (x%x) failed FCF "
James Smart0c9ab6f2010-02-26 14:15:57 -05001795 "connection list check, fcf_avail:x%x, "
1796 "fcf_valid:x%x\n",
1797 bf_get(lpfc_fcf_record_fcf_index,
1798 new_fcf_record),
1799 bf_get(lpfc_fcf_record_fcf_avail,
1800 new_fcf_record),
1801 bf_get(lpfc_fcf_record_fcf_valid,
1802 new_fcf_record));
James Smartdbb6b3a2010-06-08 18:31:37 -04001803 if ((phba->fcf.fcf_flag & FCF_IN_USE) &&
1804 lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec,
1805 new_fcf_record, LPFC_FCOE_IGNORE_VID)) {
James Smart5ac6b302010-10-22 11:05:36 -04001806 if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) !=
1807 phba->fcf.current_rec.fcf_indx) {
1808 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
1809 "2862 FCF (x%x) matches property "
1810 "of in-use FCF (x%x)\n",
1811 bf_get(lpfc_fcf_record_fcf_index,
1812 new_fcf_record),
1813 phba->fcf.current_rec.fcf_indx);
1814 goto read_next_fcf;
1815 }
James Smartdbb6b3a2010-06-08 18:31:37 -04001816 /*
1817 * In case the current in-use FCF record becomes
1818 * invalid/unavailable during FCF discovery that
1819 * was not triggered by fast FCF failover process,
1820 * treat it as fast FCF failover.
1821 */
1822 if (!(phba->fcf.fcf_flag & FCF_REDISC_PEND) &&
1823 !(phba->fcf.fcf_flag & FCF_REDISC_FOV)) {
1824 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
1825 "2835 Invalid in-use FCF "
1826 "record (x%x) reported, "
1827 "entering fast FCF failover "
1828 "mode scanning.\n",
1829 phba->fcf.current_rec.fcf_indx);
1830 spin_lock_irq(&phba->hbalock);
1831 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
1832 spin_unlock_irq(&phba->hbalock);
1833 lpfc_sli4_mbox_cmd_free(phba, mboxq);
1834 lpfc_sli4_fcf_scan_read_fcf_rec(phba,
1835 LPFC_FCOE_FCF_GET_FIRST);
1836 return;
1837 }
1838 }
James Smart6fb120a2009-05-22 14:52:59 -04001839 goto read_next_fcf;
James Smart0c9ab6f2010-02-26 14:15:57 -05001840 } else {
1841 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
1842 rc = lpfc_sli4_fcf_rr_index_set(phba, fcf_index);
1843 if (rc)
1844 goto read_next_fcf;
1845 }
1846
James Smart6fb120a2009-05-22 14:52:59 -04001847 /*
1848 * If this is not the first FCF discovery of the HBA, use last
James Smartecfd03c2010-02-12 14:41:27 -05001849 * FCF record for the discovery. The condition that a rescan
1850 * matches the in-use FCF record: fabric name, switch name, mac
1851 * address, and vlan_id.
James Smart6fb120a2009-05-22 14:52:59 -04001852 */
James Smart0c9ab6f2010-02-26 14:15:57 -05001853 spin_lock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04001854 if (phba->fcf.fcf_flag & FCF_IN_USE) {
James Smartdbb6b3a2010-06-08 18:31:37 -04001855 if (lpfc_sli4_fcf_record_match(phba, &phba->fcf.current_rec,
1856 new_fcf_record, vlan_id)) {
James Smart5ac6b302010-10-22 11:05:36 -04001857 if (bf_get(lpfc_fcf_record_fcf_index, new_fcf_record) ==
1858 phba->fcf.current_rec.fcf_indx) {
1859 phba->fcf.fcf_flag |= FCF_AVAILABLE;
1860 if (phba->fcf.fcf_flag & FCF_REDISC_PEND)
1861 /* Stop FCF redisc wait timer */
1862 __lpfc_sli4_stop_fcf_redisc_wait_timer(
1863 phba);
1864 else if (phba->fcf.fcf_flag & FCF_REDISC_FOV)
1865 /* Fast failover, mark completed */
1866 phba->fcf.fcf_flag &= ~FCF_REDISC_FOV;
1867 spin_unlock_irq(&phba->hbalock);
1868 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
1869 "2836 New FCF matches in-use "
1870 "FCF (x%x)\n",
1871 phba->fcf.current_rec.fcf_indx);
1872 goto out;
1873 } else
1874 lpfc_printf_log(phba, KERN_ERR, LOG_FIP,
1875 "2863 New FCF (x%x) matches "
1876 "property of in-use FCF (x%x)\n",
James Smartdbb6b3a2010-06-08 18:31:37 -04001877 bf_get(lpfc_fcf_record_fcf_index,
James Smart5ac6b302010-10-22 11:05:36 -04001878 new_fcf_record),
1879 phba->fcf.current_rec.fcf_indx);
James Smart6fb120a2009-05-22 14:52:59 -04001880 }
James Smartecfd03c2010-02-12 14:41:27 -05001881 /*
1882 * Read next FCF record from HBA searching for the matching
1883 * with in-use record only if not during the fast failover
1884 * period. In case of fast failover period, it shall try to
1885 * determine whether the FCF record just read should be the
1886 * next candidate.
1887 */
1888 if (!(phba->fcf.fcf_flag & FCF_REDISC_FOV)) {
James Smart0c9ab6f2010-02-26 14:15:57 -05001889 spin_unlock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -05001890 goto read_next_fcf;
1891 }
James Smart6fb120a2009-05-22 14:52:59 -04001892 }
James Smartecfd03c2010-02-12 14:41:27 -05001893 /*
1894 * Update on failover FCF record only if it's in FCF fast-failover
1895 * period; otherwise, update on current FCF record.
1896 */
James Smartfc2b9892010-02-26 14:15:29 -05001897 if (phba->fcf.fcf_flag & FCF_REDISC_FOV)
1898 fcf_rec = &phba->fcf.failover_rec;
1899 else
James Smartecfd03c2010-02-12 14:41:27 -05001900 fcf_rec = &phba->fcf.current_rec;
1901
James Smart6fb120a2009-05-22 14:52:59 -04001902 if (phba->fcf.fcf_flag & FCF_AVAILABLE) {
1903 /*
James Smartecfd03c2010-02-12 14:41:27 -05001904 * If the driver FCF record does not have boot flag
1905 * set and new hba fcf record has boot flag set, use
1906 * the new hba fcf record.
James Smart6fb120a2009-05-22 14:52:59 -04001907 */
James Smartecfd03c2010-02-12 14:41:27 -05001908 if (boot_flag && !(fcf_rec->flag & BOOT_ENABLE)) {
1909 /* Choose this FCF record */
James Smartdbb6b3a2010-06-08 18:31:37 -04001910 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
1911 "2837 Update current FCF record "
1912 "(x%x) with new FCF record (x%x)\n",
1913 fcf_rec->fcf_indx,
1914 bf_get(lpfc_fcf_record_fcf_index,
1915 new_fcf_record));
James Smartecfd03c2010-02-12 14:41:27 -05001916 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
1917 addr_mode, vlan_id, BOOT_ENABLE);
James Smart0c9ab6f2010-02-26 14:15:57 -05001918 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04001919 goto read_next_fcf;
1920 }
1921 /*
James Smartecfd03c2010-02-12 14:41:27 -05001922 * If the driver FCF record has boot flag set and the
1923 * new hba FCF record does not have boot flag, read
1924 * the next FCF record.
James Smart6fb120a2009-05-22 14:52:59 -04001925 */
James Smartecfd03c2010-02-12 14:41:27 -05001926 if (!boot_flag && (fcf_rec->flag & BOOT_ENABLE)) {
James Smart0c9ab6f2010-02-26 14:15:57 -05001927 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04001928 goto read_next_fcf;
1929 }
1930 /*
James Smartecfd03c2010-02-12 14:41:27 -05001931 * If the new hba FCF record has lower priority value
1932 * than the driver FCF record, use the new record.
James Smart6fb120a2009-05-22 14:52:59 -04001933 */
James Smartfc2b9892010-02-26 14:15:29 -05001934 if (new_fcf_record->fip_priority < fcf_rec->priority) {
James Smart999d8132010-03-15 11:24:56 -04001935 /* Choose the new FCF record with lower priority */
James Smartdbb6b3a2010-06-08 18:31:37 -04001936 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
1937 "2838 Update current FCF record "
1938 "(x%x) with new FCF record (x%x)\n",
1939 fcf_rec->fcf_indx,
1940 bf_get(lpfc_fcf_record_fcf_index,
1941 new_fcf_record));
James Smartecfd03c2010-02-12 14:41:27 -05001942 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
1943 addr_mode, vlan_id, 0);
James Smart999d8132010-03-15 11:24:56 -04001944 /* Reset running random FCF selection count */
1945 phba->fcf.eligible_fcf_cnt = 1;
1946 } else if (new_fcf_record->fip_priority == fcf_rec->priority) {
1947 /* Update running random FCF selection count */
1948 phba->fcf.eligible_fcf_cnt++;
1949 select_new_fcf = lpfc_sli4_new_fcf_random_select(phba,
1950 phba->fcf.eligible_fcf_cnt);
James Smartdbb6b3a2010-06-08 18:31:37 -04001951 if (select_new_fcf) {
1952 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
1953 "2839 Update current FCF record "
1954 "(x%x) with new FCF record (x%x)\n",
1955 fcf_rec->fcf_indx,
1956 bf_get(lpfc_fcf_record_fcf_index,
1957 new_fcf_record));
James Smart999d8132010-03-15 11:24:56 -04001958 /* Choose the new FCF by random selection */
1959 __lpfc_update_fcf_record(phba, fcf_rec,
1960 new_fcf_record,
1961 addr_mode, vlan_id, 0);
James Smartdbb6b3a2010-06-08 18:31:37 -04001962 }
James Smart6fb120a2009-05-22 14:52:59 -04001963 }
James Smart0c9ab6f2010-02-26 14:15:57 -05001964 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04001965 goto read_next_fcf;
1966 }
1967 /*
James Smartecfd03c2010-02-12 14:41:27 -05001968 * This is the first suitable FCF record, choose this record for
1969 * initial best-fit FCF.
James Smart6fb120a2009-05-22 14:52:59 -04001970 */
James Smartecfd03c2010-02-12 14:41:27 -05001971 if (fcf_rec) {
James Smartdbb6b3a2010-06-08 18:31:37 -04001972 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
1973 "2840 Update current FCF record "
1974 "with initial FCF record (x%x)\n",
1975 bf_get(lpfc_fcf_record_fcf_index,
1976 new_fcf_record));
James Smartecfd03c2010-02-12 14:41:27 -05001977 __lpfc_update_fcf_record(phba, fcf_rec, new_fcf_record,
1978 addr_mode, vlan_id, (boot_flag ?
1979 BOOT_ENABLE : 0));
1980 phba->fcf.fcf_flag |= FCF_AVAILABLE;
James Smart999d8132010-03-15 11:24:56 -04001981 /* Setup initial running random FCF selection count */
1982 phba->fcf.eligible_fcf_cnt = 1;
1983 /* Seeding the random number generator for random selection */
1984 seed = (uint32_t)(0xFFFFFFFF & jiffies);
1985 srandom32(seed);
James Smart6fb120a2009-05-22 14:52:59 -04001986 }
James Smart0c9ab6f2010-02-26 14:15:57 -05001987 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04001988 goto read_next_fcf;
1989
1990read_next_fcf:
1991 lpfc_sli4_mbox_cmd_free(phba, mboxq);
James Smartecfd03c2010-02-12 14:41:27 -05001992 if (next_fcf_index == LPFC_FCOE_FCF_NEXT_NONE || next_fcf_index == 0) {
1993 if (phba->fcf.fcf_flag & FCF_REDISC_FOV) {
1994 /*
1995 * Case of FCF fast failover scan
1996 */
1997
1998 /*
1999 * It has not found any suitable FCF record, cancel
2000 * FCF scan inprogress, and do nothing
2001 */
2002 if (!(phba->fcf.failover_rec.flag & RECORD_VALID)) {
James Smart0c9ab6f2010-02-26 14:15:57 -05002003 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2004 "2782 No suitable FCF record "
2005 "found during this round of "
2006 "post FCF rediscovery scan: "
2007 "fcf_evt_tag:x%x, fcf_index: "
2008 "x%x\n",
2009 phba->fcoe_eventtag_at_fcf_scan,
2010 bf_get(lpfc_fcf_record_fcf_index,
2011 new_fcf_record));
2012 /*
2013 * Let next new FCF event trigger fast
2014 * failover
2015 */
2016 spin_lock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -05002017 phba->hba_flag &= ~FCF_DISC_INPROGRESS;
James Smart0c9ab6f2010-02-26 14:15:57 -05002018 spin_unlock_irq(&phba->hbalock);
James Smartecfd03c2010-02-12 14:41:27 -05002019 return;
2020 }
2021 /*
2022 * It has found a suitable FCF record that is not
2023 * the same as in-use FCF record, unregister the
2024 * in-use FCF record, replace the in-use FCF record
2025 * with the new FCF record, mark FCF fast failover
2026 * completed, and then start register the new FCF
2027 * record.
2028 */
2029
James Smart0c9ab6f2010-02-26 14:15:57 -05002030 /* Unregister the current in-use FCF record */
James Smartecfd03c2010-02-12 14:41:27 -05002031 lpfc_unregister_fcf(phba);
James Smart0c9ab6f2010-02-26 14:15:57 -05002032
2033 /* Replace in-use record with the new record */
James Smartdbb6b3a2010-06-08 18:31:37 -04002034 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2035 "2842 Replace the current in-use "
2036 "FCF record (x%x) with failover FCF "
2037 "record (x%x)\n",
2038 phba->fcf.current_rec.fcf_indx,
2039 phba->fcf.failover_rec.fcf_indx);
James Smartecfd03c2010-02-12 14:41:27 -05002040 memcpy(&phba->fcf.current_rec,
2041 &phba->fcf.failover_rec,
2042 sizeof(struct lpfc_fcf_rec));
James Smart3804dc82010-07-14 15:31:37 -04002043 /*
2044 * Mark the fast FCF failover rediscovery completed
2045 * and the start of the first round of the roundrobin
2046 * FCF failover.
2047 */
James Smart0c9ab6f2010-02-26 14:15:57 -05002048 spin_lock_irq(&phba->hbalock);
James Smart3804dc82010-07-14 15:31:37 -04002049 phba->fcf.fcf_flag &=
2050 ~(FCF_REDISC_FOV | FCF_REDISC_RRU);
James Smart0c9ab6f2010-02-26 14:15:57 -05002051 spin_unlock_irq(&phba->hbalock);
2052 /*
2053 * Set up the initial registered FCF index for FLOGI
2054 * round robin FCF failover.
2055 */
2056 phba->fcf.fcf_rr_init_indx =
2057 phba->fcf.failover_rec.fcf_indx;
James Smartecfd03c2010-02-12 14:41:27 -05002058 /* Register to the new FCF record */
2059 lpfc_register_fcf(phba);
2060 } else {
2061 /*
2062 * In case of transaction period to fast FCF failover,
2063 * do nothing when search to the end of the FCF table.
2064 */
2065 if ((phba->fcf.fcf_flag & FCF_REDISC_EVT) ||
2066 (phba->fcf.fcf_flag & FCF_REDISC_PEND))
2067 return;
James Smartdbb6b3a2010-06-08 18:31:37 -04002068
2069 if (phba->fcf.fcf_flag & FCF_IN_USE) {
2070 /*
2071 * In case the current in-use FCF record no
2072 * longer existed during FCF discovery that
2073 * was not triggered by fast FCF failover
2074 * process, treat it as fast FCF failover.
2075 */
2076 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2077 "2841 In-use FCF record (x%x) "
2078 "not reported, entering fast "
2079 "FCF failover mode scanning.\n",
2080 phba->fcf.current_rec.fcf_indx);
2081 spin_lock_irq(&phba->hbalock);
2082 phba->fcf.fcf_flag |= FCF_REDISC_FOV;
2083 spin_unlock_irq(&phba->hbalock);
2084 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2085 lpfc_sli4_fcf_scan_read_fcf_rec(phba,
2086 LPFC_FCOE_FCF_GET_FIRST);
2087 return;
2088 }
James Smart0c9ab6f2010-02-26 14:15:57 -05002089 /* Register to the new FCF record */
James Smartecfd03c2010-02-12 14:41:27 -05002090 lpfc_register_fcf(phba);
2091 }
2092 } else
James Smart0c9ab6f2010-02-26 14:15:57 -05002093 lpfc_sli4_fcf_scan_read_fcf_rec(phba, next_fcf_index);
James Smart6fb120a2009-05-22 14:52:59 -04002094 return;
2095
2096out:
2097 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2098 lpfc_register_fcf(phba);
2099
2100 return;
2101}
2102
2103/**
James Smart0c9ab6f2010-02-26 14:15:57 -05002104 * lpfc_mbx_cmpl_fcf_rr_read_fcf_rec - fcf round robin read_fcf mbox cmpl hdler
2105 * @phba: pointer to lpfc hba data structure.
2106 * @mboxq: pointer to mailbox object.
2107 *
2108 * This is the callback function for FLOGI failure round robin FCF failover
2109 * read FCF record mailbox command from the eligible FCF record bmask for
2110 * performing the failover. If the FCF read back is not valid/available, it
2111 * fails through to retrying FLOGI to the currently registered FCF again.
2112 * Otherwise, if the FCF read back is valid and available, it will set the
2113 * newly read FCF record to the failover FCF record, unregister currently
2114 * registered FCF record, copy the failover FCF record to the current
2115 * FCF record, and then register the current FCF record before proceeding
2116 * to trying FLOGI on the new failover FCF.
2117 */
2118void
2119lpfc_mbx_cmpl_fcf_rr_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2120{
2121 struct fcf_record *new_fcf_record;
2122 uint32_t boot_flag, addr_mode;
2123 uint16_t next_fcf_index;
2124 uint16_t current_fcf_index;
2125 uint16_t vlan_id;
2126
2127 /* If link state is not up, stop the round robin failover process */
2128 if (phba->link_state < LPFC_LINK_UP) {
2129 spin_lock_irq(&phba->hbalock);
2130 phba->fcf.fcf_flag &= ~FCF_DISCOVERY;
2131 spin_unlock_irq(&phba->hbalock);
2132 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2133 return;
2134 }
2135
2136 /* Parse the FCF record from the non-embedded mailbox command */
2137 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
2138 &next_fcf_index);
2139 if (!new_fcf_record) {
2140 lpfc_printf_log(phba, KERN_WARNING, LOG_FIP,
2141 "2766 Mailbox command READ_FCF_RECORD "
2142 "failed to retrieve a FCF record.\n");
2143 goto out;
2144 }
2145
2146 /* Get the needed parameters from FCF record */
2147 lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
2148 &addr_mode, &vlan_id);
2149
2150 /* Log the FCF record information if turned on */
2151 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
2152 next_fcf_index);
2153
2154 /* Upload new FCF record to the failover FCF record */
James Smartdbb6b3a2010-06-08 18:31:37 -04002155 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2156 "2834 Update the current FCF record (x%x) "
2157 "with the next FCF record (x%x)\n",
2158 phba->fcf.failover_rec.fcf_indx,
2159 bf_get(lpfc_fcf_record_fcf_index, new_fcf_record));
James Smart0c9ab6f2010-02-26 14:15:57 -05002160 spin_lock_irq(&phba->hbalock);
2161 __lpfc_update_fcf_record(phba, &phba->fcf.failover_rec,
2162 new_fcf_record, addr_mode, vlan_id,
2163 (boot_flag ? BOOT_ENABLE : 0));
2164 spin_unlock_irq(&phba->hbalock);
2165
2166 current_fcf_index = phba->fcf.current_rec.fcf_indx;
2167
2168 /* Unregister the current in-use FCF record */
2169 lpfc_unregister_fcf(phba);
2170
2171 /* Replace in-use record with the new record */
2172 memcpy(&phba->fcf.current_rec, &phba->fcf.failover_rec,
2173 sizeof(struct lpfc_fcf_rec));
2174
2175 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2176 "2783 FLOGI round robin FCF failover from FCF "
James Smartdbb6b3a2010-06-08 18:31:37 -04002177 "(x%x) to FCF (x%x).\n",
James Smart0c9ab6f2010-02-26 14:15:57 -05002178 current_fcf_index,
2179 bf_get(lpfc_fcf_record_fcf_index, new_fcf_record));
2180
2181out:
2182 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2183 lpfc_register_fcf(phba);
2184}
2185
2186/**
2187 * lpfc_mbx_cmpl_read_fcf_rec - read fcf completion handler.
2188 * @phba: pointer to lpfc hba data structure.
2189 * @mboxq: pointer to mailbox object.
2190 *
2191 * This is the callback function of read FCF record mailbox command for
2192 * updating the eligible FCF bmask for FLOGI failure round robin FCF
2193 * failover when a new FCF event happened. If the FCF read back is
2194 * valid/available and it passes the connection list check, it updates
2195 * the bmask for the eligible FCF record for round robin failover.
2196 */
2197void
2198lpfc_mbx_cmpl_read_fcf_rec(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2199{
2200 struct fcf_record *new_fcf_record;
2201 uint32_t boot_flag, addr_mode;
2202 uint16_t fcf_index, next_fcf_index;
2203 uint16_t vlan_id;
2204 int rc;
2205
2206 /* If link state is not up, no need to proceed */
2207 if (phba->link_state < LPFC_LINK_UP)
2208 goto out;
2209
2210 /* If FCF discovery period is over, no need to proceed */
James Smart3804dc82010-07-14 15:31:37 -04002211 if (!(phba->fcf.fcf_flag & FCF_DISCOVERY))
James Smart0c9ab6f2010-02-26 14:15:57 -05002212 goto out;
2213
2214 /* Parse the FCF record from the non-embedded mailbox command */
2215 new_fcf_record = lpfc_sli4_fcf_rec_mbox_parse(phba, mboxq,
2216 &next_fcf_index);
2217 if (!new_fcf_record) {
2218 lpfc_printf_log(phba, KERN_INFO, LOG_FIP,
2219 "2767 Mailbox command READ_FCF_RECORD "
2220 "failed to retrieve a FCF record.\n");
2221 goto out;
2222 }
2223
2224 /* Check the connection list for eligibility */
2225 rc = lpfc_match_fcf_conn_list(phba, new_fcf_record, &boot_flag,
2226 &addr_mode, &vlan_id);
2227
2228 /* Log the FCF record information if turned on */
2229 lpfc_sli4_log_fcf_record_info(phba, new_fcf_record, vlan_id,
2230 next_fcf_index);
2231
2232 if (!rc)
2233 goto out;
2234
2235 /* Update the eligible FCF record index bmask */
2236 fcf_index = bf_get(lpfc_fcf_record_fcf_index, new_fcf_record);
2237 rc = lpfc_sli4_fcf_rr_index_set(phba, fcf_index);
2238
2239out:
2240 lpfc_sli4_mbox_cmd_free(phba, mboxq);
2241}
2242
2243/**
James Smart1c6834a2009-07-19 10:01:26 -04002244 * lpfc_init_vpi_cmpl - Completion handler for init_vpi mbox command.
2245 * @phba: pointer to lpfc hba data structure.
2246 * @mboxq: pointer to mailbox data structure.
2247 *
2248 * This function handles completion of init vpi mailbox command.
2249 */
James Smart695a8142010-01-26 23:08:03 -05002250void
James Smart1c6834a2009-07-19 10:01:26 -04002251lpfc_init_vpi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2252{
2253 struct lpfc_vport *vport = mboxq->vport;
James Smart695a8142010-01-26 23:08:03 -05002254 struct lpfc_nodelist *ndlp;
James Smart72100cc2010-02-12 14:43:01 -05002255 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2256
James Smart1c6834a2009-07-19 10:01:26 -04002257 if (mboxq->u.mb.mbxStatus) {
2258 lpfc_printf_vlog(vport, KERN_ERR,
2259 LOG_MBOX,
2260 "2609 Init VPI mailbox failed 0x%x\n",
2261 mboxq->u.mb.mbxStatus);
2262 mempool_free(mboxq, phba->mbox_mem_pool);
2263 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
2264 return;
2265 }
James Smart72100cc2010-02-12 14:43:01 -05002266 spin_lock_irq(shost->host_lock);
James Smart1c6834a2009-07-19 10:01:26 -04002267 vport->fc_flag &= ~FC_VPORT_NEEDS_INIT_VPI;
James Smart72100cc2010-02-12 14:43:01 -05002268 spin_unlock_irq(shost->host_lock);
James Smart1c6834a2009-07-19 10:01:26 -04002269
James Smart695a8142010-01-26 23:08:03 -05002270 /* If this port is physical port or FDISC is done, do reg_vpi */
2271 if ((phba->pport == vport) || (vport->port_state == LPFC_FDISC)) {
2272 ndlp = lpfc_findnode_did(vport, Fabric_DID);
2273 if (!ndlp)
2274 lpfc_printf_vlog(vport, KERN_ERR,
2275 LOG_DISCOVERY,
2276 "2731 Cannot find fabric "
2277 "controller node\n");
2278 else
2279 lpfc_register_new_vport(phba, vport, ndlp);
2280 mempool_free(mboxq, phba->mbox_mem_pool);
2281 return;
2282 }
2283
James Smart1c6834a2009-07-19 10:01:26 -04002284 if (phba->link_flag & LS_NPIV_FAB_SUPPORTED)
2285 lpfc_initial_fdisc(vport);
2286 else {
2287 lpfc_vport_set_state(vport, FC_VPORT_NO_FABRIC_SUPP);
James Smart6a9c52c2009-10-02 15:16:51 -04002288 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
2289 "2606 No NPIV Fabric support\n");
James Smart1c6834a2009-07-19 10:01:26 -04002290 }
James Smart695a8142010-01-26 23:08:03 -05002291 mempool_free(mboxq, phba->mbox_mem_pool);
James Smart1c6834a2009-07-19 10:01:26 -04002292 return;
2293}
2294
2295/**
James Smartecfd03c2010-02-12 14:41:27 -05002296 * lpfc_issue_init_vpi - Issue init_vpi mailbox command.
2297 * @vport: pointer to lpfc_vport data structure.
2298 *
2299 * This function issue a init_vpi mailbox command to initialize
2300 * VPI for the vport.
2301 */
2302void
2303lpfc_issue_init_vpi(struct lpfc_vport *vport)
2304{
2305 LPFC_MBOXQ_t *mboxq;
2306 int rc;
2307
2308 mboxq = mempool_alloc(vport->phba->mbox_mem_pool, GFP_KERNEL);
2309 if (!mboxq) {
2310 lpfc_printf_vlog(vport, KERN_ERR,
2311 LOG_MBOX, "2607 Failed to allocate "
2312 "init_vpi mailbox\n");
2313 return;
2314 }
2315 lpfc_init_vpi(vport->phba, mboxq, vport->vpi);
2316 mboxq->vport = vport;
2317 mboxq->mbox_cmpl = lpfc_init_vpi_cmpl;
2318 rc = lpfc_sli_issue_mbox(vport->phba, mboxq, MBX_NOWAIT);
2319 if (rc == MBX_NOT_FINISHED) {
2320 lpfc_printf_vlog(vport, KERN_ERR,
2321 LOG_MBOX, "2608 Failed to issue init_vpi mailbox\n");
2322 mempool_free(mboxq, vport->phba->mbox_mem_pool);
2323 }
2324}
2325
2326/**
James Smart6fb120a2009-05-22 14:52:59 -04002327 * lpfc_start_fdiscs - send fdiscs for each vports on this port.
2328 * @phba: pointer to lpfc hba data structure.
2329 *
2330 * This function loops through the list of vports on the @phba and issues an
2331 * FDISC if possible.
2332 */
2333void
2334lpfc_start_fdiscs(struct lpfc_hba *phba)
2335{
2336 struct lpfc_vport **vports;
2337 int i;
2338
2339 vports = lpfc_create_vport_work_array(phba);
2340 if (vports != NULL) {
2341 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
2342 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
2343 continue;
2344 /* There are no vpi for this vport */
2345 if (vports[i]->vpi > phba->max_vpi) {
2346 lpfc_vport_set_state(vports[i],
2347 FC_VPORT_FAILED);
2348 continue;
2349 }
2350 if (phba->fc_topology == TOPOLOGY_LOOP) {
2351 lpfc_vport_set_state(vports[i],
2352 FC_VPORT_LINKDOWN);
2353 continue;
2354 }
James Smart1c6834a2009-07-19 10:01:26 -04002355 if (vports[i]->fc_flag & FC_VPORT_NEEDS_INIT_VPI) {
James Smartecfd03c2010-02-12 14:41:27 -05002356 lpfc_issue_init_vpi(vports[i]);
James Smart1c6834a2009-07-19 10:01:26 -04002357 continue;
2358 }
James Smart6fb120a2009-05-22 14:52:59 -04002359 if (phba->link_flag & LS_NPIV_FAB_SUPPORTED)
2360 lpfc_initial_fdisc(vports[i]);
2361 else {
2362 lpfc_vport_set_state(vports[i],
2363 FC_VPORT_NO_FABRIC_SUPP);
2364 lpfc_printf_vlog(vports[i], KERN_ERR,
2365 LOG_ELS,
2366 "0259 No NPIV "
2367 "Fabric support\n");
2368 }
2369 }
2370 }
2371 lpfc_destroy_vport_work_array(phba, vports);
2372}
2373
2374void
2375lpfc_mbx_cmpl_reg_vfi(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
2376{
2377 struct lpfc_dmabuf *dmabuf = mboxq->context1;
2378 struct lpfc_vport *vport = mboxq->vport;
James Smart72100cc2010-02-12 14:43:01 -05002379 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart6fb120a2009-05-22 14:52:59 -04002380
2381 if (mboxq->u.mb.mbxStatus) {
2382 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
2383 "2018 REG_VFI mbxStatus error x%x "
2384 "HBA state x%x\n",
2385 mboxq->u.mb.mbxStatus, vport->port_state);
2386 if (phba->fc_topology == TOPOLOGY_LOOP) {
2387 /* FLOGI failed, use loop map to make discovery list */
2388 lpfc_disc_list_loopmap(vport);
2389 /* Start discovery */
2390 lpfc_disc_start(vport);
2391 goto fail_free_mem;
2392 }
2393 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
2394 goto fail_free_mem;
2395 }
James Smartc8685952009-11-18 15:39:16 -05002396 /* The VPI is implicitly registered when the VFI is registered */
James Smart72100cc2010-02-12 14:43:01 -05002397 spin_lock_irq(shost->host_lock);
James Smartc8685952009-11-18 15:39:16 -05002398 vport->vpi_state |= LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05002399 vport->fc_flag |= FC_VFI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05002400 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
James Smart72100cc2010-02-12 14:43:01 -05002401 spin_unlock_irq(shost->host_lock);
James Smart6fb120a2009-05-22 14:52:59 -04002402
2403 if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
2404 lpfc_start_fdiscs(phba);
2405 lpfc_do_scr_ns_plogi(phba, vport);
2406 }
2407
2408fail_free_mem:
2409 mempool_free(mboxq, phba->mbox_mem_pool);
2410 lpfc_mbuf_free(phba, dmabuf->virt, dmabuf->phys);
2411 kfree(dmabuf);
2412 return;
2413}
2414
2415static void
James Smart2e0fef82007-06-17 19:56:36 -05002416lpfc_mbx_cmpl_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05002417{
James Smart6fb120a2009-05-22 14:52:59 -04002418 MAILBOX_t *mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -05002419 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) pmb->context1;
James Smart2e0fef82007-06-17 19:56:36 -05002420 struct lpfc_vport *vport = pmb->vport;
dea31012005-04-17 16:05:31 -05002421
2422
2423 /* Check for error */
2424 if (mb->mbxStatus) {
2425 /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */
James Smarte8b62012007-08-02 11:10:09 -04002426 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
2427 "0319 READ_SPARAM mbxStatus error x%x "
2428 "hba state x%x>\n",
2429 mb->mbxStatus, vport->port_state);
dea31012005-04-17 16:05:31 -05002430 lpfc_linkdown(phba);
dea31012005-04-17 16:05:31 -05002431 goto out;
2432 }
2433
James Smart2e0fef82007-06-17 19:56:36 -05002434 memcpy((uint8_t *) &vport->fc_sparam, (uint8_t *) mp->virt,
dea31012005-04-17 16:05:31 -05002435 sizeof (struct serv_parm));
James Smarta12e07b2006-12-02 13:35:30 -05002436 if (phba->cfg_soft_wwnn)
James Smart2e0fef82007-06-17 19:56:36 -05002437 u64_to_wwn(phba->cfg_soft_wwnn,
2438 vport->fc_sparam.nodeName.u.wwn);
James Smartc3f28af2006-08-18 17:47:18 -04002439 if (phba->cfg_soft_wwpn)
James Smart2e0fef82007-06-17 19:56:36 -05002440 u64_to_wwn(phba->cfg_soft_wwpn,
2441 vport->fc_sparam.portName.u.wwn);
James Smart92d7f7b2007-06-17 19:56:38 -05002442 memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
2443 sizeof(vport->fc_nodename));
2444 memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
2445 sizeof(vport->fc_portname));
2446 if (vport->port_type == LPFC_PHYSICAL_PORT) {
2447 memcpy(&phba->wwnn, &vport->fc_nodename, sizeof(phba->wwnn));
2448 memcpy(&phba->wwpn, &vport->fc_portname, sizeof(phba->wwnn));
2449 }
2450
dea31012005-04-17 16:05:31 -05002451 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2452 kfree(mp);
James Smart2e0fef82007-06-17 19:56:36 -05002453 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05002454 return;
2455
2456out:
2457 pmb->context1 = NULL;
2458 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2459 kfree(mp);
James Smart92d7f7b2007-06-17 19:56:38 -05002460 lpfc_issue_clear_la(phba, vport);
2461 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05002462 return;
2463}
2464
2465static void
James Smart92d7f7b2007-06-17 19:56:38 -05002466lpfc_mbx_process_link_up(struct lpfc_hba *phba, READ_LA_VAR *la)
dea31012005-04-17 16:05:31 -05002467{
James Smart92d7f7b2007-06-17 19:56:38 -05002468 struct lpfc_vport *vport = phba->pport;
James Smart6fb120a2009-05-22 14:52:59 -04002469 LPFC_MBOXQ_t *sparam_mbox, *cfglink_mbox = NULL;
James Smart2e0fef82007-06-17 19:56:36 -05002470 int i;
James Smart14691152006-12-02 13:34:28 -05002471 struct lpfc_dmabuf *mp;
2472 int rc;
James Smart6fb120a2009-05-22 14:52:59 -04002473 struct fcf_record *fcf_record;
James Smart14691152006-12-02 13:34:28 -05002474
James Smart92d7f7b2007-06-17 19:56:38 -05002475 spin_lock_irq(&phba->hbalock);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002476 switch (la->UlnkSpeed) {
James Smart92d7f7b2007-06-17 19:56:38 -05002477 case LA_1GHZ_LINK:
2478 phba->fc_linkspeed = LA_1GHZ_LINK;
2479 break;
2480 case LA_2GHZ_LINK:
2481 phba->fc_linkspeed = LA_2GHZ_LINK;
2482 break;
2483 case LA_4GHZ_LINK:
2484 phba->fc_linkspeed = LA_4GHZ_LINK;
2485 break;
2486 case LA_8GHZ_LINK:
2487 phba->fc_linkspeed = LA_8GHZ_LINK;
2488 break;
James Smartf4b4c682009-05-22 14:53:12 -04002489 case LA_10GHZ_LINK:
2490 phba->fc_linkspeed = LA_10GHZ_LINK;
2491 break;
James Smart92d7f7b2007-06-17 19:56:38 -05002492 default:
2493 phba->fc_linkspeed = LA_UNKNW_LINK;
2494 break;
dea31012005-04-17 16:05:31 -05002495 }
2496
2497 phba->fc_topology = la->topology;
James Smart92d7f7b2007-06-17 19:56:38 -05002498 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
dea31012005-04-17 16:05:31 -05002499
2500 if (phba->fc_topology == TOPOLOGY_LOOP) {
James Smart92d7f7b2007-06-17 19:56:38 -05002501 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
dea31012005-04-17 16:05:31 -05002502
James Smart6a9c52c2009-10-02 15:16:51 -04002503 /* if npiv is enabled and this adapter supports npiv log
2504 * a message that npiv is not supported in this topology
2505 */
2506 if (phba->cfg_enable_npiv && phba->max_vpi)
James Smart495a7142008-06-14 22:52:59 -04002507 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
2508 "1309 Link Up Event npiv not supported in loop "
2509 "topology\n");
James Smart92d7f7b2007-06-17 19:56:38 -05002510 /* Get Loop Map information */
dea31012005-04-17 16:05:31 -05002511 if (la->il)
James Smart2e0fef82007-06-17 19:56:36 -05002512 vport->fc_flag |= FC_LBIT;
dea31012005-04-17 16:05:31 -05002513
James Smart2e0fef82007-06-17 19:56:36 -05002514 vport->fc_myDID = la->granted_AL_PA;
dea31012005-04-17 16:05:31 -05002515 i = la->un.lilpBde64.tus.f.bdeSize;
2516
2517 if (i == 0) {
2518 phba->alpa_map[0] = 0;
2519 } else {
James Smarte8b62012007-08-02 11:10:09 -04002520 if (vport->cfg_log_verbose & LOG_LINK_EVENT) {
dea31012005-04-17 16:05:31 -05002521 int numalpa, j, k;
2522 union {
2523 uint8_t pamap[16];
2524 struct {
2525 uint32_t wd1;
2526 uint32_t wd2;
2527 uint32_t wd3;
2528 uint32_t wd4;
2529 } pa;
2530 } un;
2531 numalpa = phba->alpa_map[0];
2532 j = 0;
2533 while (j < numalpa) {
2534 memset(un.pamap, 0, 16);
2535 for (k = 1; j < numalpa; k++) {
2536 un.pamap[k - 1] =
2537 phba->alpa_map[j + 1];
2538 j++;
2539 if (k == 16)
2540 break;
2541 }
2542 /* Link Up Event ALPA map */
2543 lpfc_printf_log(phba,
James Smart92d7f7b2007-06-17 19:56:38 -05002544 KERN_WARNING,
2545 LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04002546 "1304 Link Up Event "
James Smart92d7f7b2007-06-17 19:56:38 -05002547 "ALPA map Data: x%x "
2548 "x%x x%x x%x\n",
James Smart92d7f7b2007-06-17 19:56:38 -05002549 un.pa.wd1, un.pa.wd2,
2550 un.pa.wd3, un.pa.wd4);
dea31012005-04-17 16:05:31 -05002551 }
2552 }
2553 }
2554 } else {
James Smart92d7f7b2007-06-17 19:56:38 -05002555 if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)) {
James Smart78b2d852007-08-02 11:10:21 -04002556 if (phba->max_vpi && phba->cfg_enable_npiv &&
James Smart92d7f7b2007-06-17 19:56:38 -05002557 (phba->sli_rev == 3))
2558 phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
2559 }
James Smart2e0fef82007-06-17 19:56:36 -05002560 vport->fc_myDID = phba->fc_pref_DID;
2561 vport->fc_flag |= FC_LBIT;
dea31012005-04-17 16:05:31 -05002562 }
James Smart92d7f7b2007-06-17 19:56:38 -05002563 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002564
2565 lpfc_linkup(phba);
James Smart9f1177a2010-02-26 14:12:57 -05002566 sparam_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2567 if (!sparam_mbox)
2568 goto out;
2569
2570 rc = lpfc_read_sparam(phba, sparam_mbox, 0);
2571 if (rc) {
2572 mempool_free(sparam_mbox, phba->mbox_mem_pool);
2573 goto out;
2574 }
2575 sparam_mbox->vport = vport;
2576 sparam_mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam;
2577 rc = lpfc_sli_issue_mbox(phba, sparam_mbox, MBX_NOWAIT);
2578 if (rc == MBX_NOT_FINISHED) {
2579 mp = (struct lpfc_dmabuf *) sparam_mbox->context1;
2580 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2581 kfree(mp);
2582 mempool_free(sparam_mbox, phba->mbox_mem_pool);
2583 goto out;
dea31012005-04-17 16:05:31 -05002584 }
2585
James Smart6fb120a2009-05-22 14:52:59 -04002586 if (!(phba->hba_flag & HBA_FCOE_SUPPORT)) {
2587 cfglink_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2588 if (!cfglink_mbox)
2589 goto out;
James Smart2e0fef82007-06-17 19:56:36 -05002590 vport->port_state = LPFC_LOCAL_CFG_LINK;
dea31012005-04-17 16:05:31 -05002591 lpfc_config_link(phba, cfglink_mbox);
James Smart2e0fef82007-06-17 19:56:36 -05002592 cfglink_mbox->vport = vport;
Jamie Wellnitz25594c62006-02-28 19:25:34 -05002593 cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
James Smart0b727fe2007-10-27 13:37:25 -04002594 rc = lpfc_sli_issue_mbox(phba, cfglink_mbox, MBX_NOWAIT);
James Smart6fb120a2009-05-22 14:52:59 -04002595 if (rc == MBX_NOT_FINISHED) {
2596 mempool_free(cfglink_mbox, phba->mbox_mem_pool);
2597 goto out;
2598 }
2599 } else {
James Smart32b97932009-07-19 10:01:21 -04002600 vport->port_state = LPFC_VPORT_UNKNOWN;
James Smart6fb120a2009-05-22 14:52:59 -04002601 /*
2602 * Add the driver's default FCF record at FCF index 0 now. This
2603 * is phase 1 implementation that support FCF index 0 and driver
2604 * defaults.
2605 */
James Smart45ed1192009-10-02 15:17:02 -04002606 if (!(phba->hba_flag & HBA_FIP_SUPPORT)) {
James Smart6fb120a2009-05-22 14:52:59 -04002607 fcf_record = kzalloc(sizeof(struct fcf_record),
2608 GFP_KERNEL);
2609 if (unlikely(!fcf_record)) {
2610 lpfc_printf_log(phba, KERN_ERR,
2611 LOG_MBOX | LOG_SLI,
2612 "2554 Could not allocate memmory for "
2613 "fcf record\n");
2614 rc = -ENODEV;
2615 goto out;
2616 }
2617
2618 lpfc_sli4_build_dflt_fcf_record(phba, fcf_record,
2619 LPFC_FCOE_FCF_DEF_INDEX);
2620 rc = lpfc_sli4_add_fcf_record(phba, fcf_record);
2621 if (unlikely(rc)) {
2622 lpfc_printf_log(phba, KERN_ERR,
2623 LOG_MBOX | LOG_SLI,
2624 "2013 Could not manually add FCF "
2625 "record 0, status %d\n", rc);
2626 rc = -ENODEV;
2627 kfree(fcf_record);
2628 goto out;
2629 }
2630 kfree(fcf_record);
2631 }
2632 /*
2633 * The driver is expected to do FIP/FCF. Call the port
2634 * and get the FCF Table.
2635 */
James Smart32b97932009-07-19 10:01:21 -04002636 spin_lock_irq(&phba->hbalock);
2637 if (phba->hba_flag & FCF_DISC_INPROGRESS) {
2638 spin_unlock_irq(&phba->hbalock);
2639 return;
2640 }
James Smart0c9ab6f2010-02-26 14:15:57 -05002641 /* This is the initial FCF discovery scan */
2642 phba->fcf.fcf_flag |= FCF_INIT_DISC;
James Smart32b97932009-07-19 10:01:21 -04002643 spin_unlock_irq(&phba->hbalock);
James Smart0c9ab6f2010-02-26 14:15:57 -05002644 lpfc_printf_log(phba, KERN_INFO, LOG_FIP | LOG_DISCOVERY,
2645 "2778 Start FCF table scan at linkup\n");
James Smart0c9ab6f2010-02-26 14:15:57 -05002646 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba,
2647 LPFC_FCOE_FCF_GET_FIRST);
2648 if (rc) {
2649 spin_lock_irq(&phba->hbalock);
2650 phba->fcf.fcf_flag &= ~FCF_INIT_DISC;
2651 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04002652 goto out;
James Smart0c9ab6f2010-02-26 14:15:57 -05002653 }
James Smart38b92ef2010-08-04 16:11:39 -04002654 /* Reset FCF roundrobin bmask for new discovery */
2655 memset(phba->fcf.fcf_rr_bmask, 0,
2656 sizeof(*phba->fcf.fcf_rr_bmask));
dea31012005-04-17 16:05:31 -05002657 }
James Smart6fb120a2009-05-22 14:52:59 -04002658
2659 return;
James Smart92d7f7b2007-06-17 19:56:38 -05002660out:
2661 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04002662 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
2663 "0263 Discovery Mailbox error: state: 0x%x : %p %p\n",
2664 vport->port_state, sparam_mbox, cfglink_mbox);
James Smart92d7f7b2007-06-17 19:56:38 -05002665 lpfc_issue_clear_la(phba, vport);
2666 return;
dea31012005-04-17 16:05:31 -05002667}
2668
2669static void
James Smart84774a42008-08-24 21:50:06 -04002670lpfc_enable_la(struct lpfc_hba *phba)
James Smart2e0fef82007-06-17 19:56:36 -05002671{
dea31012005-04-17 16:05:31 -05002672 uint32_t control;
2673 struct lpfc_sli *psli = &phba->sli;
James Smart2e0fef82007-06-17 19:56:36 -05002674 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002675 psli->sli_flag |= LPFC_PROCESS_LA;
James Smart3772a992009-05-22 14:50:54 -04002676 if (phba->sli_rev <= LPFC_SLI_REV3) {
2677 control = readl(phba->HCregaddr);
2678 control |= HC_LAINT_ENA;
2679 writel(control, phba->HCregaddr);
2680 readl(phba->HCregaddr); /* flush */
2681 }
James Smart2e0fef82007-06-17 19:56:36 -05002682 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002683}
2684
James Smart84774a42008-08-24 21:50:06 -04002685static void
2686lpfc_mbx_issue_link_down(struct lpfc_hba *phba)
2687{
2688 lpfc_linkdown(phba);
2689 lpfc_enable_la(phba);
James Smart6fb120a2009-05-22 14:52:59 -04002690 lpfc_unregister_unused_fcf(phba);
James Smart84774a42008-08-24 21:50:06 -04002691 /* turn on Link Attention interrupts - no CLEAR_LA needed */
2692}
2693
2694
dea31012005-04-17 16:05:31 -05002695/*
2696 * This routine handles processing a READ_LA mailbox
2697 * command upon completion. It is setup in the LPFC_MBOXQ
2698 * as the completion routine when the command is
2699 * handed off to the SLI layer.
2700 */
2701void
James Smart2e0fef82007-06-17 19:56:36 -05002702lpfc_mbx_cmpl_read_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05002703{
James Smart2e0fef82007-06-17 19:56:36 -05002704 struct lpfc_vport *vport = pmb->vport;
2705 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002706 READ_LA_VAR *la;
James Smart04c68492009-05-22 14:52:52 -04002707 MAILBOX_t *mb = &pmb->u.mb;
dea31012005-04-17 16:05:31 -05002708 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
2709
James Smart0d2b6b82008-06-14 22:52:47 -04002710 /* Unblock ELS traffic */
2711 phba->sli.ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
dea31012005-04-17 16:05:31 -05002712 /* Check for error */
2713 if (mb->mbxStatus) {
James Smarted957682007-06-17 19:56:37 -05002714 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04002715 "1307 READ_LA mbox error x%x state x%x\n",
2716 mb->mbxStatus, vport->port_state);
dea31012005-04-17 16:05:31 -05002717 lpfc_mbx_issue_link_down(phba);
James Smart2e0fef82007-06-17 19:56:36 -05002718 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05002719 goto lpfc_mbx_cmpl_read_la_free_mbuf;
2720 }
2721
James Smart04c68492009-05-22 14:52:52 -04002722 la = (READ_LA_VAR *) &pmb->u.mb.un.varReadLA;
dea31012005-04-17 16:05:31 -05002723
2724 memcpy(&phba->alpa_map[0], mp->virt, 128);
2725
James Smart2e0fef82007-06-17 19:56:36 -05002726 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002727 if (la->pb)
James Smart2e0fef82007-06-17 19:56:36 -05002728 vport->fc_flag |= FC_BYPASSED_MODE;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002729 else
James Smart2e0fef82007-06-17 19:56:36 -05002730 vport->fc_flag &= ~FC_BYPASSED_MODE;
2731 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002732
James Smart0c287582009-06-10 17:22:56 -04002733 if ((phba->fc_eventTag < la->eventTag) ||
James Smart92d7f7b2007-06-17 19:56:38 -05002734 (phba->fc_eventTag == la->eventTag)) {
dea31012005-04-17 16:05:31 -05002735 phba->fc_stat.LinkMultiEvent++;
James Smart2e0fef82007-06-17 19:56:36 -05002736 if (la->attType == AT_LINK_UP)
dea31012005-04-17 16:05:31 -05002737 if (phba->fc_eventTag != 0)
2738 lpfc_linkdown(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05002739 }
dea31012005-04-17 16:05:31 -05002740
2741 phba->fc_eventTag = la->eventTag;
James Smart72100cc2010-02-12 14:43:01 -05002742 spin_lock_irq(&phba->hbalock);
James Smart84774a42008-08-24 21:50:06 -04002743 if (la->mm)
2744 phba->sli.sli_flag |= LPFC_MENLO_MAINT;
2745 else
2746 phba->sli.sli_flag &= ~LPFC_MENLO_MAINT;
James Smart72100cc2010-02-12 14:43:01 -05002747 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002748
James Smart4d9ab992009-10-02 15:16:39 -04002749 phba->link_events++;
James Smart84774a42008-08-24 21:50:06 -04002750 if (la->attType == AT_LINK_UP && (!la->mm)) {
dea31012005-04-17 16:05:31 -05002751 phba->fc_stat.LinkUp++;
James Smart2e0fef82007-06-17 19:56:36 -05002752 if (phba->link_flag & LS_LOOPBACK_MODE) {
James Smart3163f722008-02-08 18:50:25 -05002753 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04002754 "1306 Link Up Event in loop back mode "
2755 "x%x received Data: x%x x%x x%x x%x\n",
2756 la->eventTag, phba->fc_eventTag,
2757 la->granted_AL_PA, la->UlnkSpeed,
2758 phba->alpa_map[0]);
James Smart5b8bd0c2007-04-25 09:52:49 -04002759 } else {
2760 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04002761 "1303 Link Up Event x%x received "
James Smart84774a42008-08-24 21:50:06 -04002762 "Data: x%x x%x x%x x%x x%x x%x %d\n",
James Smarte8b62012007-08-02 11:10:09 -04002763 la->eventTag, phba->fc_eventTag,
2764 la->granted_AL_PA, la->UlnkSpeed,
James Smart84774a42008-08-24 21:50:06 -04002765 phba->alpa_map[0],
2766 la->mm, la->fa,
2767 phba->wait_4_mlo_maint_flg);
James Smart5b8bd0c2007-04-25 09:52:49 -04002768 }
James Smart92d7f7b2007-06-17 19:56:38 -05002769 lpfc_mbx_process_link_up(phba, la);
James Smart84774a42008-08-24 21:50:06 -04002770 } else if (la->attType == AT_LINK_DOWN) {
dea31012005-04-17 16:05:31 -05002771 phba->fc_stat.LinkDown++;
James Smart3163f722008-02-08 18:50:25 -05002772 if (phba->link_flag & LS_LOOPBACK_MODE) {
2773 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
2774 "1308 Link Down Event in loop back mode "
2775 "x%x received "
2776 "Data: x%x x%x x%x\n",
2777 la->eventTag, phba->fc_eventTag,
2778 phba->pport->port_state, vport->fc_flag);
2779 }
2780 else {
2781 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04002782 "1305 Link Down Event x%x received "
James Smart84774a42008-08-24 21:50:06 -04002783 "Data: x%x x%x x%x x%x x%x\n",
2784 la->eventTag, phba->fc_eventTag,
2785 phba->pport->port_state, vport->fc_flag,
2786 la->mm, la->fa);
2787 }
2788 lpfc_mbx_issue_link_down(phba);
2789 }
2790 if (la->mm && la->attType == AT_LINK_UP) {
2791 if (phba->link_state != LPFC_LINK_DOWN) {
2792 phba->fc_stat.LinkDown++;
2793 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
2794 "1312 Link Down Event x%x received "
dea31012005-04-17 16:05:31 -05002795 "Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04002796 la->eventTag, phba->fc_eventTag,
James Smart2e0fef82007-06-17 19:56:36 -05002797 phba->pport->port_state, vport->fc_flag);
James Smart84774a42008-08-24 21:50:06 -04002798 lpfc_mbx_issue_link_down(phba);
2799 } else
2800 lpfc_enable_la(phba);
2801
2802 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
2803 "1310 Menlo Maint Mode Link up Event x%x rcvd "
2804 "Data: x%x x%x x%x\n",
2805 la->eventTag, phba->fc_eventTag,
2806 phba->pport->port_state, vport->fc_flag);
2807 /*
2808 * The cmnd that triggered this will be waiting for this
2809 * signal.
2810 */
2811 /* WAKEUP for MENLO_SET_MODE or MENLO_RESET command. */
2812 if (phba->wait_4_mlo_maint_flg) {
2813 phba->wait_4_mlo_maint_flg = 0;
2814 wake_up_interruptible(&phba->wait_4_mlo_m_q);
James Smart3163f722008-02-08 18:50:25 -05002815 }
James Smart84774a42008-08-24 21:50:06 -04002816 }
2817
2818 if (la->fa) {
2819 if (la->mm)
2820 lpfc_issue_clear_la(phba, vport);
2821 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
2822 "1311 fa %d\n", la->fa);
dea31012005-04-17 16:05:31 -05002823 }
2824
2825lpfc_mbx_cmpl_read_la_free_mbuf:
2826 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2827 kfree(mp);
2828 mempool_free(pmb, phba->mbox_mem_pool);
2829 return;
2830}
2831
2832/*
2833 * This routine handles processing a REG_LOGIN mailbox
2834 * command upon completion. It is setup in the LPFC_MBOXQ
2835 * as the completion routine when the command is
2836 * handed off to the SLI layer.
2837 */
2838void
James Smart2e0fef82007-06-17 19:56:36 -05002839lpfc_mbx_cmpl_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05002840{
James Smart2e0fef82007-06-17 19:56:36 -05002841 struct lpfc_vport *vport = pmb->vport;
James Smart92d7f7b2007-06-17 19:56:38 -05002842 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
James Smart2e0fef82007-06-17 19:56:36 -05002843 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smartffc95492010-06-07 15:23:17 -04002844 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002845
dea31012005-04-17 16:05:31 -05002846 pmb->context1 = NULL;
James Smartd439d282010-09-29 11:18:45 -04002847 pmb->context2 = NULL;
dea31012005-04-17 16:05:31 -05002848
James Smartffc95492010-06-07 15:23:17 -04002849 if (ndlp->nlp_flag & NLP_REG_LOGIN_SEND)
2850 ndlp->nlp_flag &= ~NLP_REG_LOGIN_SEND;
2851
2852 if (ndlp->nlp_flag & NLP_IGNR_REG_CMPL ||
2853 ndlp->nlp_state != NLP_STE_REG_LOGIN_ISSUE) {
2854 /* We rcvd a rscn after issuing this
2855 * mbox reg login, we may have cycled
2856 * back through the state and be
2857 * back at reg login state so this
2858 * mbox needs to be ignored becase
2859 * there is another reg login in
2860 * proccess.
2861 */
2862 spin_lock_irq(shost->host_lock);
2863 ndlp->nlp_flag &= ~NLP_IGNR_REG_CMPL;
2864 spin_unlock_irq(shost->host_lock);
2865 if (phba->sli_rev == LPFC_SLI_REV4)
2866 lpfc_sli4_free_rpi(phba,
2867 pmb->u.mb.un.varRegLogin.rpi);
2868
2869 } else
2870 /* Good status, call state machine */
2871 lpfc_disc_state_machine(vport, ndlp, pmb,
2872 NLP_EVT_CMPL_REG_LOGIN);
2873
dea31012005-04-17 16:05:31 -05002874 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2875 kfree(mp);
James Smart2e0fef82007-06-17 19:56:36 -05002876 mempool_free(pmb, phba->mbox_mem_pool);
James Smartfa4066b2008-01-11 01:53:27 -05002877 /* decrement the node reference count held for this callback
2878 * function.
2879 */
James Smart329f9bc2007-04-25 09:53:01 -04002880 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002881
2882 return;
2883}
2884
James Smart92d7f7b2007-06-17 19:56:38 -05002885static void
2886lpfc_mbx_cmpl_unreg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
2887{
James Smart04c68492009-05-22 14:52:52 -04002888 MAILBOX_t *mb = &pmb->u.mb;
James Smart92d7f7b2007-06-17 19:56:38 -05002889 struct lpfc_vport *vport = pmb->vport;
2890 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2891
2892 switch (mb->mbxStatus) {
2893 case 0x0011:
2894 case 0x0020:
James Smarte8b62012007-08-02 11:10:09 -04002895 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
2896 "0911 cmpl_unreg_vpi, mb status = 0x%x\n",
2897 mb->mbxStatus);
James Smart92d7f7b2007-06-17 19:56:38 -05002898 break;
James Smart78730cf2010-04-06 15:06:30 -04002899 /* If VPI is busy, reset the HBA */
2900 case 0x9700:
2901 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE,
2902 "2798 Unreg_vpi failed vpi 0x%x, mb status = 0x%x\n",
2903 vport->vpi, mb->mbxStatus);
2904 if (!(phba->pport->load_flag & FC_UNLOADING))
2905 lpfc_workq_post_event(phba, NULL, NULL,
2906 LPFC_EVT_RESET_HBA);
James Smart92d7f7b2007-06-17 19:56:38 -05002907 }
James Smart72100cc2010-02-12 14:43:01 -05002908 spin_lock_irq(shost->host_lock);
James Smartc8685952009-11-18 15:39:16 -05002909 vport->vpi_state &= ~LPFC_VPI_REGISTERED;
James Smart19878072009-12-21 17:02:00 -05002910 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart72100cc2010-02-12 14:43:01 -05002911 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05002912 vport->unreg_vpi_cmpl = VPORT_OK;
2913 mempool_free(pmb, phba->mbox_mem_pool);
2914 /*
2915 * This shost reference might have been taken at the beginning of
2916 * lpfc_vport_delete()
2917 */
James Smart1c6f4ef52009-11-18 15:40:49 -05002918 if ((vport->load_flag & FC_UNLOADING) && (vport != phba->pport))
James Smart92d7f7b2007-06-17 19:56:38 -05002919 scsi_host_put(shost);
2920}
2921
James Smartd7c255b2008-08-24 21:50:00 -04002922int
James Smart92d7f7b2007-06-17 19:56:38 -05002923lpfc_mbx_unreg_vpi(struct lpfc_vport *vport)
2924{
2925 struct lpfc_hba *phba = vport->phba;
2926 LPFC_MBOXQ_t *mbox;
2927 int rc;
2928
2929 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2930 if (!mbox)
James Smartd7c255b2008-08-24 21:50:00 -04002931 return 1;
James Smart92d7f7b2007-06-17 19:56:38 -05002932
2933 lpfc_unreg_vpi(phba, vport->vpi, mbox);
2934 mbox->vport = vport;
2935 mbox->mbox_cmpl = lpfc_mbx_cmpl_unreg_vpi;
James Smart0b727fe2007-10-27 13:37:25 -04002936 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart92d7f7b2007-06-17 19:56:38 -05002937 if (rc == MBX_NOT_FINISHED) {
James Smarte8b62012007-08-02 11:10:09 -04002938 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT,
2939 "1800 Could not issue unreg_vpi\n");
James Smart92d7f7b2007-06-17 19:56:38 -05002940 mempool_free(mbox, phba->mbox_mem_pool);
2941 vport->unreg_vpi_cmpl = VPORT_ERROR;
James Smartd7c255b2008-08-24 21:50:00 -04002942 return rc;
James Smart92d7f7b2007-06-17 19:56:38 -05002943 }
James Smartd7c255b2008-08-24 21:50:00 -04002944 return 0;
James Smart92d7f7b2007-06-17 19:56:38 -05002945}
2946
2947static void
2948lpfc_mbx_cmpl_reg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
2949{
2950 struct lpfc_vport *vport = pmb->vport;
2951 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart04c68492009-05-22 14:52:52 -04002952 MAILBOX_t *mb = &pmb->u.mb;
James Smart92d7f7b2007-06-17 19:56:38 -05002953
2954 switch (mb->mbxStatus) {
2955 case 0x0011:
2956 case 0x9601:
2957 case 0x9602:
James Smarte8b62012007-08-02 11:10:09 -04002958 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
2959 "0912 cmpl_reg_vpi, mb status = 0x%x\n",
2960 mb->mbxStatus);
James Smart92d7f7b2007-06-17 19:56:38 -05002961 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
2962 spin_lock_irq(shost->host_lock);
2963 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
2964 spin_unlock_irq(shost->host_lock);
2965 vport->fc_myDID = 0;
2966 goto out;
2967 }
James Smart92d7f7b2007-06-17 19:56:38 -05002968
James Smart72100cc2010-02-12 14:43:01 -05002969 spin_lock_irq(shost->host_lock);
James Smartc8685952009-11-18 15:39:16 -05002970 vport->vpi_state |= LPFC_VPI_REGISTERED;
James Smart695a8142010-01-26 23:08:03 -05002971 vport->fc_flag &= ~FC_VPORT_NEEDS_REG_VPI;
James Smart72100cc2010-02-12 14:43:01 -05002972 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05002973 vport->num_disc_nodes = 0;
2974 /* go thru NPR list and issue ELS PLOGIs */
2975 if (vport->fc_npr_cnt)
2976 lpfc_els_disc_plogi(vport);
2977
2978 if (!vport->num_disc_nodes) {
2979 spin_lock_irq(shost->host_lock);
2980 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2981 spin_unlock_irq(shost->host_lock);
2982 lpfc_can_disctmo(vport);
2983 }
2984 vport->port_state = LPFC_VPORT_READY;
2985
2986out:
2987 mempool_free(pmb, phba->mbox_mem_pool);
2988 return;
2989}
2990
James Smart21e9a0a2009-05-22 14:53:21 -04002991/**
2992 * lpfc_create_static_vport - Read HBA config region to create static vports.
2993 * @phba: pointer to lpfc hba data structure.
2994 *
2995 * This routine issue a DUMP mailbox command for config region 22 to get
2996 * the list of static vports to be created. The function create vports
2997 * based on the information returned from the HBA.
2998 **/
2999void
3000lpfc_create_static_vport(struct lpfc_hba *phba)
3001{
3002 LPFC_MBOXQ_t *pmb = NULL;
3003 MAILBOX_t *mb;
3004 struct static_vport_info *vport_info;
James Smart1c6834a2009-07-19 10:01:26 -04003005 int rc = 0, i;
James Smart21e9a0a2009-05-22 14:53:21 -04003006 struct fc_vport_identifiers vport_id;
3007 struct fc_vport *new_fc_vport;
3008 struct Scsi_Host *shost;
3009 struct lpfc_vport *vport;
3010 uint16_t offset = 0;
3011 uint8_t *vport_buff;
James Smart1c6834a2009-07-19 10:01:26 -04003012 struct lpfc_dmabuf *mp;
3013 uint32_t byte_count = 0;
James Smart21e9a0a2009-05-22 14:53:21 -04003014
3015 pmb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3016 if (!pmb) {
3017 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3018 "0542 lpfc_create_static_vport failed to"
3019 " allocate mailbox memory\n");
3020 return;
3021 }
3022
3023 mb = &pmb->u.mb;
3024
3025 vport_info = kzalloc(sizeof(struct static_vport_info), GFP_KERNEL);
3026 if (!vport_info) {
3027 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3028 "0543 lpfc_create_static_vport failed to"
3029 " allocate vport_info\n");
3030 mempool_free(pmb, phba->mbox_mem_pool);
3031 return;
3032 }
3033
3034 vport_buff = (uint8_t *) vport_info;
3035 do {
James Smart1c6834a2009-07-19 10:01:26 -04003036 if (lpfc_dump_static_vport(phba, pmb, offset))
3037 goto out;
3038
James Smart21e9a0a2009-05-22 14:53:21 -04003039 pmb->vport = phba->pport;
3040 rc = lpfc_sli_issue_mbox_wait(phba, pmb, LPFC_MBOX_TMO);
3041
3042 if ((rc != MBX_SUCCESS) || mb->mbxStatus) {
3043 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
3044 "0544 lpfc_create_static_vport failed to"
3045 " issue dump mailbox command ret 0x%x "
3046 "status 0x%x\n",
3047 rc, mb->mbxStatus);
3048 goto out;
3049 }
3050
James Smart1c6834a2009-07-19 10:01:26 -04003051 if (phba->sli_rev == LPFC_SLI_REV4) {
3052 byte_count = pmb->u.mqe.un.mb_words[5];
3053 mp = (struct lpfc_dmabuf *) pmb->context2;
3054 if (byte_count > sizeof(struct static_vport_info) -
3055 offset)
3056 byte_count = sizeof(struct static_vport_info)
3057 - offset;
3058 memcpy(vport_buff + offset, mp->virt, byte_count);
3059 offset += byte_count;
3060 } else {
3061 if (mb->un.varDmp.word_cnt >
3062 sizeof(struct static_vport_info) - offset)
3063 mb->un.varDmp.word_cnt =
3064 sizeof(struct static_vport_info)
3065 - offset;
3066 byte_count = mb->un.varDmp.word_cnt;
3067 lpfc_sli_pcimem_bcopy(((uint8_t *)mb) + DMP_RSP_OFFSET,
3068 vport_buff + offset,
3069 byte_count);
James Smart21e9a0a2009-05-22 14:53:21 -04003070
James Smart1c6834a2009-07-19 10:01:26 -04003071 offset += byte_count;
3072 }
James Smart21e9a0a2009-05-22 14:53:21 -04003073
James Smart1c6834a2009-07-19 10:01:26 -04003074 } while (byte_count &&
James Smart21e9a0a2009-05-22 14:53:21 -04003075 offset < sizeof(struct static_vport_info));
3076
3077
3078 if ((le32_to_cpu(vport_info->signature) != VPORT_INFO_SIG) ||
3079 ((le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK)
3080 != VPORT_INFO_REV)) {
3081 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
3082 "0545 lpfc_create_static_vport bad"
3083 " information header 0x%x 0x%x\n",
3084 le32_to_cpu(vport_info->signature),
3085 le32_to_cpu(vport_info->rev) & VPORT_INFO_REV_MASK);
3086
3087 goto out;
3088 }
3089
3090 shost = lpfc_shost_from_vport(phba->pport);
3091
3092 for (i = 0; i < MAX_STATIC_VPORT_COUNT; i++) {
3093 memset(&vport_id, 0, sizeof(vport_id));
3094 vport_id.port_name = wwn_to_u64(vport_info->vport_list[i].wwpn);
3095 vport_id.node_name = wwn_to_u64(vport_info->vport_list[i].wwnn);
3096 if (!vport_id.port_name || !vport_id.node_name)
3097 continue;
3098
3099 vport_id.roles = FC_PORT_ROLE_FCP_INITIATOR;
3100 vport_id.vport_type = FC_PORTTYPE_NPIV;
3101 vport_id.disable = false;
3102 new_fc_vport = fc_vport_create(shost, 0, &vport_id);
3103
3104 if (!new_fc_vport) {
3105 lpfc_printf_log(phba, KERN_WARNING, LOG_INIT,
3106 "0546 lpfc_create_static_vport failed to"
James Smarte4e74272009-07-19 10:01:38 -04003107 " create vport\n");
James Smart21e9a0a2009-05-22 14:53:21 -04003108 continue;
3109 }
3110
3111 vport = *(struct lpfc_vport **)new_fc_vport->dd_data;
3112 vport->vport_flag |= STATIC_VPORT;
3113 }
3114
3115out:
James Smart21e9a0a2009-05-22 14:53:21 -04003116 kfree(vport_info);
James Smart1c6834a2009-07-19 10:01:26 -04003117 if (rc != MBX_TIMEOUT) {
3118 if (pmb->context2) {
3119 mp = (struct lpfc_dmabuf *) pmb->context2;
3120 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3121 kfree(mp);
3122 }
James Smart21e9a0a2009-05-22 14:53:21 -04003123 mempool_free(pmb, phba->mbox_mem_pool);
James Smart1c6834a2009-07-19 10:01:26 -04003124 }
James Smart21e9a0a2009-05-22 14:53:21 -04003125
3126 return;
3127}
3128
dea31012005-04-17 16:05:31 -05003129/*
3130 * This routine handles processing a Fabric REG_LOGIN mailbox
3131 * command upon completion. It is setup in the LPFC_MBOXQ
3132 * as the completion routine when the command is
3133 * handed off to the SLI layer.
3134 */
3135void
James Smart2e0fef82007-06-17 19:56:36 -05003136lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05003137{
James Smart92d7f7b2007-06-17 19:56:38 -05003138 struct lpfc_vport *vport = pmb->vport;
James Smart21e9a0a2009-05-22 14:53:21 -04003139 MAILBOX_t *mb = &pmb->u.mb;
James Smart2e0fef82007-06-17 19:56:36 -05003140 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
James Smart92d7f7b2007-06-17 19:56:38 -05003141 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05003142
James Smart549e55c2007-08-02 11:09:51 -04003143 ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart329f9bc2007-04-25 09:53:01 -04003144 pmb->context1 = NULL;
3145 pmb->context2 = NULL;
James Smartd439d282010-09-29 11:18:45 -04003146
dea31012005-04-17 16:05:31 -05003147 if (mb->mbxStatus) {
James Smart21e9a0a2009-05-22 14:53:21 -04003148 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
3149 "0258 Register Fabric login error: 0x%x\n",
3150 mb->mbxStatus);
dea31012005-04-17 16:05:31 -05003151 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3152 kfree(mp);
James Smart329f9bc2007-04-25 09:53:01 -04003153 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003154
James Smart92d7f7b2007-06-17 19:56:38 -05003155 if (phba->fc_topology == TOPOLOGY_LOOP) {
3156 /* FLOGI failed, use loop map to make discovery list */
3157 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -05003158
James Smart92d7f7b2007-06-17 19:56:38 -05003159 /* Start discovery */
3160 lpfc_disc_start(vport);
James Smarte47c9092008-02-08 18:49:26 -05003161 /* Decrement the reference count to ndlp after the
3162 * reference to the ndlp are done.
3163 */
3164 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05003165 return;
3166 }
3167
3168 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte47c9092008-02-08 18:49:26 -05003169 /* Decrement the reference count to ndlp after the reference
3170 * to the ndlp are done.
3171 */
3172 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05003173 return;
3174 }
3175
dea31012005-04-17 16:05:31 -05003176 ndlp->nlp_rpi = mb->un.varWords[0];
James Smart21e9a0a2009-05-22 14:53:21 -04003177 ndlp->nlp_flag |= NLP_RPI_VALID;
dea31012005-04-17 16:05:31 -05003178 ndlp->nlp_type |= NLP_FABRIC;
James Smart2e0fef82007-06-17 19:56:36 -05003179 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
dea31012005-04-17 16:05:31 -05003180
James Smart2e0fef82007-06-17 19:56:36 -05003181 if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
James Smart4b40c592010-03-15 11:25:44 -04003182 /* when physical port receive logo donot start
3183 * vport discovery */
3184 if (!(vport->fc_flag & FC_LOGO_RCVD_DID_CHNG))
3185 lpfc_start_fdiscs(phba);
3186 else
3187 vport->fc_flag &= ~FC_LOGO_RCVD_DID_CHNG ;
James Smart92d7f7b2007-06-17 19:56:38 -05003188 lpfc_do_scr_ns_plogi(phba, vport);
dea31012005-04-17 16:05:31 -05003189 }
3190
3191 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3192 kfree(mp);
James Smart329f9bc2007-04-25 09:53:01 -04003193 mempool_free(pmb, phba->mbox_mem_pool);
James Smarte47c9092008-02-08 18:49:26 -05003194
3195 /* Drop the reference count from the mbox at the end after
3196 * all the current reference to the ndlp have been done.
3197 */
3198 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05003199 return;
3200}
3201
3202/*
3203 * This routine handles processing a NameServer REG_LOGIN mailbox
3204 * command upon completion. It is setup in the LPFC_MBOXQ
3205 * as the completion routine when the command is
3206 * handed off to the SLI layer.
3207 */
3208void
James Smart2e0fef82007-06-17 19:56:36 -05003209lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05003210{
James Smart21e9a0a2009-05-22 14:53:21 -04003211 MAILBOX_t *mb = &pmb->u.mb;
James Smart2e0fef82007-06-17 19:56:36 -05003212 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
3213 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
3214 struct lpfc_vport *vport = pmb->vport;
dea31012005-04-17 16:05:31 -05003215
James Smartd439d282010-09-29 11:18:45 -04003216 pmb->context1 = NULL;
3217 pmb->context2 = NULL;
3218
dea31012005-04-17 16:05:31 -05003219 if (mb->mbxStatus) {
James Smart92d7f7b2007-06-17 19:56:38 -05003220out:
James Smart21e9a0a2009-05-22 14:53:21 -04003221 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
3222 "0260 Register NameServer error: 0x%x\n",
3223 mb->mbxStatus);
James Smartfa4066b2008-01-11 01:53:27 -05003224 /* decrement the node reference count held for this
3225 * callback function.
3226 */
James Smart329f9bc2007-04-25 09:53:01 -04003227 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05003228 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3229 kfree(mp);
James Smartde0c5b32007-04-25 09:52:27 -04003230 mempool_free(pmb, phba->mbox_mem_pool);
James Smart87af33f2007-10-27 13:37:43 -04003231
3232 /* If no other thread is using the ndlp, free it */
3233 lpfc_nlp_not_used(ndlp);
dea31012005-04-17 16:05:31 -05003234
James Smart92d7f7b2007-06-17 19:56:38 -05003235 if (phba->fc_topology == TOPOLOGY_LOOP) {
3236 /*
3237 * RegLogin failed, use loop map to make discovery
3238 * list
3239 */
3240 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -05003241
James Smart92d7f7b2007-06-17 19:56:38 -05003242 /* Start discovery */
3243 lpfc_disc_start(vport);
3244 return;
3245 }
3246 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
dea31012005-04-17 16:05:31 -05003247 return;
3248 }
3249
dea31012005-04-17 16:05:31 -05003250 ndlp->nlp_rpi = mb->un.varWords[0];
James Smart21e9a0a2009-05-22 14:53:21 -04003251 ndlp->nlp_flag |= NLP_RPI_VALID;
dea31012005-04-17 16:05:31 -05003252 ndlp->nlp_type |= NLP_FABRIC;
James Smart2e0fef82007-06-17 19:56:36 -05003253 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
dea31012005-04-17 16:05:31 -05003254
James Smart2e0fef82007-06-17 19:56:36 -05003255 if (vport->port_state < LPFC_VPORT_READY) {
3256 /* Link up discovery requires Fabric registration. */
James Smart92d7f7b2007-06-17 19:56:38 -05003257 lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0, 0); /* Do this first! */
3258 lpfc_ns_cmd(vport, SLI_CTNS_RNN_ID, 0, 0);
3259 lpfc_ns_cmd(vport, SLI_CTNS_RSNN_NN, 0, 0);
3260 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
3261 lpfc_ns_cmd(vport, SLI_CTNS_RFT_ID, 0, 0);
3262
3263 /* Issue SCR just before NameServer GID_FT Query */
3264 lpfc_issue_els_scr(vport, SCR_DID, 0);
dea31012005-04-17 16:05:31 -05003265 }
3266
James Smart2e0fef82007-06-17 19:56:36 -05003267 vport->fc_ns_retry = 0;
dea31012005-04-17 16:05:31 -05003268 /* Good status, issue CT Request to NameServer */
James Smart92d7f7b2007-06-17 19:56:38 -05003269 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0)) {
dea31012005-04-17 16:05:31 -05003270 /* Cannot issue NameServer Query, so finish up discovery */
James Smart92d7f7b2007-06-17 19:56:38 -05003271 goto out;
dea31012005-04-17 16:05:31 -05003272 }
3273
James Smartfa4066b2008-01-11 01:53:27 -05003274 /* decrement the node reference count held for this
3275 * callback function.
3276 */
James Smart329f9bc2007-04-25 09:53:01 -04003277 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05003278 lpfc_mbuf_free(phba, mp->virt, mp->phys);
3279 kfree(mp);
James Smart2e0fef82007-06-17 19:56:36 -05003280 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003281
3282 return;
3283}
3284
3285static void
James Smart2e0fef82007-06-17 19:56:36 -05003286lpfc_register_remote_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003287{
James Smart2e0fef82007-06-17 19:56:36 -05003288 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3289 struct fc_rport *rport;
dea31012005-04-17 16:05:31 -05003290 struct lpfc_rport_data *rdata;
3291 struct fc_rport_identifiers rport_ids;
James Smart2e0fef82007-06-17 19:56:36 -05003292 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003293
3294 /* Remote port has reappeared. Re-register w/ FC transport */
Andrew Morton68ce1eb2005-09-21 09:46:54 -07003295 rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
3296 rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
dea31012005-04-17 16:05:31 -05003297 rport_ids.port_id = ndlp->nlp_DID;
3298 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
dea31012005-04-17 16:05:31 -05003299
James Smart329f9bc2007-04-25 09:53:01 -04003300 /*
3301 * We leave our node pointer in rport->dd_data when we unregister a
3302 * FCP target port. But fc_remote_port_add zeros the space to which
3303 * rport->dd_data points. So, if we're reusing a previously
3304 * registered port, drop the reference that we took the last time we
3305 * registered the port.
3306 */
3307 if (ndlp->rport && ndlp->rport->dd_data &&
James Smarte47c9092008-02-08 18:49:26 -05003308 ((struct lpfc_rport_data *) ndlp->rport->dd_data)->pnode == ndlp)
James Smart329f9bc2007-04-25 09:53:01 -04003309 lpfc_nlp_put(ndlp);
James Smart858c9f62007-06-17 19:56:39 -05003310
3311 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
3312 "rport add: did:x%x flg:x%x type x%x",
3313 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
3314
James Smart2e0fef82007-06-17 19:56:36 -05003315 ndlp->rport = rport = fc_remote_port_add(shost, 0, &rport_ids);
James Smart329f9bc2007-04-25 09:53:01 -04003316 if (!rport || !get_device(&rport->dev)) {
dea31012005-04-17 16:05:31 -05003317 dev_printk(KERN_WARNING, &phba->pcidev->dev,
3318 "Warning: fc_remote_port_add failed\n");
3319 return;
3320 }
3321
3322 /* initialize static port data */
3323 rport->maxframe_size = ndlp->nlp_maxframe;
3324 rport->supported_classes = ndlp->nlp_class_sup;
dea31012005-04-17 16:05:31 -05003325 rdata = rport->dd_data;
James Smart329f9bc2007-04-25 09:53:01 -04003326 rdata->pnode = lpfc_nlp_get(ndlp);
James.Smart@Emulex.Com23dc04f2005-11-28 11:41:44 -05003327
3328 if (ndlp->nlp_type & NLP_FCP_TARGET)
3329 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
3330 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
3331 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
3332
3333
3334 if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN)
3335 fc_remote_port_rolechg(rport, rport_ids.roles);
3336
James Smart071fbd3d2006-04-15 11:53:20 -04003337 if ((rport->scsi_target_id != -1) &&
James Smart92d7f7b2007-06-17 19:56:38 -05003338 (rport->scsi_target_id < LPFC_MAX_TARGET)) {
James Smart071fbd3d2006-04-15 11:53:20 -04003339 ndlp->nlp_sid = rport->scsi_target_id;
3340 }
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04003341 return;
3342}
3343
3344static void
James Smart2e0fef82007-06-17 19:56:36 -05003345lpfc_unregister_remote_port(struct lpfc_nodelist *ndlp)
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04003346{
3347 struct fc_rport *rport = ndlp->rport;
James Smartc01f3202006-08-18 17:47:08 -04003348
James Smart858c9f62007-06-17 19:56:39 -05003349 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_RPORT,
3350 "rport delete: did:x%x flg:x%x type x%x",
3351 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
3352
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04003353 fc_remote_port_delete(rport);
dea31012005-04-17 16:05:31 -05003354
3355 return;
3356}
3357
James Smartde0c5b32007-04-25 09:52:27 -04003358static void
James Smart2e0fef82007-06-17 19:56:36 -05003359lpfc_nlp_counters(struct lpfc_vport *vport, int state, int count)
James Smartde0c5b32007-04-25 09:52:27 -04003360{
James Smart2e0fef82007-06-17 19:56:36 -05003361 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3362
3363 spin_lock_irq(shost->host_lock);
James Smartde0c5b32007-04-25 09:52:27 -04003364 switch (state) {
3365 case NLP_STE_UNUSED_NODE:
James Smart2e0fef82007-06-17 19:56:36 -05003366 vport->fc_unused_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04003367 break;
3368 case NLP_STE_PLOGI_ISSUE:
James Smart2e0fef82007-06-17 19:56:36 -05003369 vport->fc_plogi_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04003370 break;
3371 case NLP_STE_ADISC_ISSUE:
James Smart2e0fef82007-06-17 19:56:36 -05003372 vport->fc_adisc_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04003373 break;
3374 case NLP_STE_REG_LOGIN_ISSUE:
James Smart2e0fef82007-06-17 19:56:36 -05003375 vport->fc_reglogin_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04003376 break;
3377 case NLP_STE_PRLI_ISSUE:
James Smart2e0fef82007-06-17 19:56:36 -05003378 vport->fc_prli_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04003379 break;
3380 case NLP_STE_UNMAPPED_NODE:
James Smart2e0fef82007-06-17 19:56:36 -05003381 vport->fc_unmap_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04003382 break;
3383 case NLP_STE_MAPPED_NODE:
James Smart2e0fef82007-06-17 19:56:36 -05003384 vport->fc_map_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04003385 break;
3386 case NLP_STE_NPR_NODE:
James Smart2e0fef82007-06-17 19:56:36 -05003387 vport->fc_npr_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04003388 break;
3389 }
James Smart2e0fef82007-06-17 19:56:36 -05003390 spin_unlock_irq(shost->host_lock);
James Smartde0c5b32007-04-25 09:52:27 -04003391}
Jamie Wellnitz66a9ed62006-02-28 22:33:10 -05003392
James Smartde0c5b32007-04-25 09:52:27 -04003393static void
James Smart2e0fef82007-06-17 19:56:36 -05003394lpfc_nlp_state_cleanup(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04003395 int old_state, int new_state)
3396{
James Smart2e0fef82007-06-17 19:56:36 -05003397 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3398
James Smartde0c5b32007-04-25 09:52:27 -04003399 if (new_state == NLP_STE_UNMAPPED_NODE) {
James Smartde0c5b32007-04-25 09:52:27 -04003400 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
3401 ndlp->nlp_type |= NLP_FC_NODE;
3402 }
3403 if (new_state == NLP_STE_MAPPED_NODE)
3404 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
3405 if (new_state == NLP_STE_NPR_NODE)
3406 ndlp->nlp_flag &= ~NLP_RCV_PLOGI;
dea31012005-04-17 16:05:31 -05003407
James Smartde0c5b32007-04-25 09:52:27 -04003408 /* Transport interface */
3409 if (ndlp->rport && (old_state == NLP_STE_MAPPED_NODE ||
3410 old_state == NLP_STE_UNMAPPED_NODE)) {
James Smart2e0fef82007-06-17 19:56:36 -05003411 vport->phba->nport_event_cnt++;
3412 lpfc_unregister_remote_port(ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04003413 }
dea31012005-04-17 16:05:31 -05003414
James Smartde0c5b32007-04-25 09:52:27 -04003415 if (new_state == NLP_STE_MAPPED_NODE ||
3416 new_state == NLP_STE_UNMAPPED_NODE) {
James Smart2e0fef82007-06-17 19:56:36 -05003417 vport->phba->nport_event_cnt++;
James Smart858c9f62007-06-17 19:56:39 -05003418 /*
3419 * Tell the fc transport about the port, if we haven't
3420 * already. If we have, and it's a scsi entity, be
3421 * sure to unblock any attached scsi devices
3422 */
3423 lpfc_register_remote_port(vport, ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04003424 }
James Smartea2151b2008-09-07 11:52:10 -04003425 if ((new_state == NLP_STE_MAPPED_NODE) &&
3426 (vport->stat_data_enabled)) {
3427 /*
3428 * A new target is discovered, if there is no buffer for
3429 * statistical data collection allocate buffer.
3430 */
3431 ndlp->lat_data = kcalloc(LPFC_MAX_BUCKET_COUNT,
3432 sizeof(struct lpfc_scsicmd_bkt),
3433 GFP_KERNEL);
3434
3435 if (!ndlp->lat_data)
3436 lpfc_printf_vlog(vport, KERN_ERR, LOG_NODE,
3437 "0286 lpfc_nlp_state_cleanup failed to "
3438 "allocate statistical data buffer DID "
3439 "0x%x\n", ndlp->nlp_DID);
3440 }
James Smart858c9f62007-06-17 19:56:39 -05003441 /*
3442 * if we added to Mapped list, but the remote port
3443 * registration failed or assigned a target id outside
3444 * our presentable range - move the node to the
3445 * Unmapped List
3446 */
James Smartde0c5b32007-04-25 09:52:27 -04003447 if (new_state == NLP_STE_MAPPED_NODE &&
3448 (!ndlp->rport ||
3449 ndlp->rport->scsi_target_id == -1 ||
3450 ndlp->rport->scsi_target_id >= LPFC_MAX_TARGET)) {
James Smart2e0fef82007-06-17 19:56:36 -05003451 spin_lock_irq(shost->host_lock);
James Smartde0c5b32007-04-25 09:52:27 -04003452 ndlp->nlp_flag |= NLP_TGT_NO_SCSIID;
James Smart2e0fef82007-06-17 19:56:36 -05003453 spin_unlock_irq(shost->host_lock);
3454 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
dea31012005-04-17 16:05:31 -05003455 }
James Smartde0c5b32007-04-25 09:52:27 -04003456}
3457
James Smart685f0bf2007-04-25 09:53:08 -04003458static char *
3459lpfc_nlp_state_name(char *buffer, size_t size, int state)
3460{
3461 static char *states[] = {
3462 [NLP_STE_UNUSED_NODE] = "UNUSED",
3463 [NLP_STE_PLOGI_ISSUE] = "PLOGI",
3464 [NLP_STE_ADISC_ISSUE] = "ADISC",
3465 [NLP_STE_REG_LOGIN_ISSUE] = "REGLOGIN",
3466 [NLP_STE_PRLI_ISSUE] = "PRLI",
3467 [NLP_STE_UNMAPPED_NODE] = "UNMAPPED",
3468 [NLP_STE_MAPPED_NODE] = "MAPPED",
3469 [NLP_STE_NPR_NODE] = "NPR",
3470 };
3471
James Smart311464e2007-08-02 11:10:37 -04003472 if (state < NLP_STE_MAX_STATE && states[state])
James Smart685f0bf2007-04-25 09:53:08 -04003473 strlcpy(buffer, states[state], size);
3474 else
3475 snprintf(buffer, size, "unknown (%d)", state);
3476 return buffer;
3477}
3478
James Smartde0c5b32007-04-25 09:52:27 -04003479void
James Smart2e0fef82007-06-17 19:56:36 -05003480lpfc_nlp_set_state(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
3481 int state)
James Smartde0c5b32007-04-25 09:52:27 -04003482{
James Smart2e0fef82007-06-17 19:56:36 -05003483 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smartde0c5b32007-04-25 09:52:27 -04003484 int old_state = ndlp->nlp_state;
James Smart685f0bf2007-04-25 09:53:08 -04003485 char name1[16], name2[16];
James Smartde0c5b32007-04-25 09:52:27 -04003486
James Smarte8b62012007-08-02 11:10:09 -04003487 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
3488 "0904 NPort state transition x%06x, %s -> %s\n",
3489 ndlp->nlp_DID,
3490 lpfc_nlp_state_name(name1, sizeof(name1), old_state),
3491 lpfc_nlp_state_name(name2, sizeof(name2), state));
James Smart858c9f62007-06-17 19:56:39 -05003492
3493 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
3494 "node statechg did:x%x old:%d ste:%d",
3495 ndlp->nlp_DID, old_state, state);
3496
James Smartde0c5b32007-04-25 09:52:27 -04003497 if (old_state == NLP_STE_NPR_NODE &&
James Smartde0c5b32007-04-25 09:52:27 -04003498 state != NLP_STE_NPR_NODE)
James Smart2e0fef82007-06-17 19:56:36 -05003499 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04003500 if (old_state == NLP_STE_UNMAPPED_NODE) {
3501 ndlp->nlp_flag &= ~NLP_TGT_NO_SCSIID;
3502 ndlp->nlp_type &= ~NLP_FC_NODE;
3503 }
3504
James Smart685f0bf2007-04-25 09:53:08 -04003505 if (list_empty(&ndlp->nlp_listp)) {
James Smart2e0fef82007-06-17 19:56:36 -05003506 spin_lock_irq(shost->host_lock);
3507 list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
3508 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003509 } else if (old_state)
James Smart2e0fef82007-06-17 19:56:36 -05003510 lpfc_nlp_counters(vport, old_state, -1);
James Smartde0c5b32007-04-25 09:52:27 -04003511
3512 ndlp->nlp_state = state;
James Smart2e0fef82007-06-17 19:56:36 -05003513 lpfc_nlp_counters(vport, state, 1);
3514 lpfc_nlp_state_cleanup(vport, ndlp, old_state, state);
James Smartde0c5b32007-04-25 09:52:27 -04003515}
3516
3517void
James Smarte47c9092008-02-08 18:49:26 -05003518lpfc_enqueue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
3519{
3520 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3521
3522 if (list_empty(&ndlp->nlp_listp)) {
3523 spin_lock_irq(shost->host_lock);
3524 list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
3525 spin_unlock_irq(shost->host_lock);
3526 }
3527}
3528
3529void
James Smart2e0fef82007-06-17 19:56:36 -05003530lpfc_dequeue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
James Smartde0c5b32007-04-25 09:52:27 -04003531{
James Smart2e0fef82007-06-17 19:56:36 -05003532 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3533
James Smart0d2b6b82008-06-14 22:52:47 -04003534 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04003535 if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
James Smart2e0fef82007-06-17 19:56:36 -05003536 lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
3537 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04003538 list_del_init(&ndlp->nlp_listp);
James Smart2e0fef82007-06-17 19:56:36 -05003539 spin_unlock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05003540 lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state,
James Smarte47c9092008-02-08 18:49:26 -05003541 NLP_STE_UNUSED_NODE);
3542}
3543
Adrian Bunk4d9db012008-02-14 23:24:02 +02003544static void
James Smarte47c9092008-02-08 18:49:26 -05003545lpfc_disable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
3546{
James Smart0d2b6b82008-06-14 22:52:47 -04003547 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smarte47c9092008-02-08 18:49:26 -05003548 if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
3549 lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
3550 lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state,
3551 NLP_STE_UNUSED_NODE);
3552}
James Smart109f6ed2008-12-04 22:39:08 -05003553/**
James Smart3621a712009-04-06 18:47:14 -04003554 * lpfc_initialize_node - Initialize all fields of node object
James Smart109f6ed2008-12-04 22:39:08 -05003555 * @vport: Pointer to Virtual Port object.
3556 * @ndlp: Pointer to FC node object.
3557 * @did: FC_ID of the node.
James Smarta257bf92009-04-06 18:48:10 -04003558 *
3559 * This function is always called when node object need to be initialized.
3560 * It initializes all the fields of the node object. Although the reference
3561 * to phba from @ndlp can be obtained indirectly through it's reference to
3562 * @vport, a direct reference to phba is taken here by @ndlp. This is due
3563 * to the life-span of the @ndlp might go beyond the existence of @vport as
3564 * the final release of ndlp is determined by its reference count. And, the
3565 * operation on @ndlp needs the reference to phba.
James Smart109f6ed2008-12-04 22:39:08 -05003566 **/
3567static inline void
3568lpfc_initialize_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
3569 uint32_t did)
3570{
3571 INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp);
3572 INIT_LIST_HEAD(&ndlp->dev_loss_evt.evt_listp);
3573 init_timer(&ndlp->nlp_delayfunc);
3574 ndlp->nlp_delayfunc.function = lpfc_els_retry_delay;
3575 ndlp->nlp_delayfunc.data = (unsigned long)ndlp;
3576 ndlp->nlp_DID = did;
3577 ndlp->vport = vport;
James Smarta257bf92009-04-06 18:48:10 -04003578 ndlp->phba = vport->phba;
James Smart109f6ed2008-12-04 22:39:08 -05003579 ndlp->nlp_sid = NLP_NO_SID;
3580 kref_init(&ndlp->kref);
3581 NLP_INT_NODE_ACT(ndlp);
3582 atomic_set(&ndlp->cmd_pending, 0);
James Smart7dc517d2010-07-14 15:32:10 -04003583 ndlp->cmd_qdepth = vport->cfg_tgt_queue_depth;
James Smart109f6ed2008-12-04 22:39:08 -05003584}
James Smarte47c9092008-02-08 18:49:26 -05003585
3586struct lpfc_nodelist *
3587lpfc_enable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
3588 int state)
3589{
3590 struct lpfc_hba *phba = vport->phba;
3591 uint32_t did;
3592 unsigned long flags;
3593
3594 if (!ndlp)
3595 return NULL;
3596
3597 spin_lock_irqsave(&phba->ndlp_lock, flags);
3598 /* The ndlp should not be in memory free mode */
3599 if (NLP_CHK_FREE_REQ(ndlp)) {
3600 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
3601 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
3602 "0277 lpfc_enable_node: ndlp:x%p "
3603 "usgmap:x%x refcnt:%d\n",
3604 (void *)ndlp, ndlp->nlp_usg_map,
3605 atomic_read(&ndlp->kref.refcount));
3606 return NULL;
3607 }
3608 /* The ndlp should not already be in active mode */
3609 if (NLP_CHK_NODE_ACT(ndlp)) {
3610 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
3611 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
3612 "0278 lpfc_enable_node: ndlp:x%p "
3613 "usgmap:x%x refcnt:%d\n",
3614 (void *)ndlp, ndlp->nlp_usg_map,
3615 atomic_read(&ndlp->kref.refcount));
3616 return NULL;
3617 }
3618
3619 /* Keep the original DID */
3620 did = ndlp->nlp_DID;
3621
3622 /* re-initialize ndlp except of ndlp linked list pointer */
3623 memset((((char *)ndlp) + sizeof (struct list_head)), 0,
3624 sizeof (struct lpfc_nodelist) - sizeof (struct list_head));
James Smart109f6ed2008-12-04 22:39:08 -05003625 lpfc_initialize_node(vport, ndlp, did);
James Smarte47c9092008-02-08 18:49:26 -05003626
3627 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
3628
3629 if (state != NLP_STE_UNUSED_NODE)
3630 lpfc_nlp_set_state(vport, ndlp, state);
3631
3632 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
3633 "node enable: did:x%x",
3634 ndlp->nlp_DID, 0, 0);
3635 return ndlp;
James Smartde0c5b32007-04-25 09:52:27 -04003636}
3637
3638void
James Smart2e0fef82007-06-17 19:56:36 -05003639lpfc_drop_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
James Smartde0c5b32007-04-25 09:52:27 -04003640{
James Smart87af33f2007-10-27 13:37:43 -04003641 /*
James Smartfa4066b2008-01-11 01:53:27 -05003642 * Use of lpfc_drop_node and UNUSED list: lpfc_drop_node should
James Smart87af33f2007-10-27 13:37:43 -04003643 * be used if we wish to issue the "last" lpfc_nlp_put() to remove
James Smartfa4066b2008-01-11 01:53:27 -05003644 * the ndlp from the vport. The ndlp marked as UNUSED on the list
3645 * until ALL other outstanding threads have completed. We check
3646 * that the ndlp not already in the UNUSED state before we proceed.
James Smart87af33f2007-10-27 13:37:43 -04003647 */
James Smartfa4066b2008-01-11 01:53:27 -05003648 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
3649 return;
James Smart51ef4c22007-08-02 11:10:31 -04003650 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE);
James Smart87af33f2007-10-27 13:37:43 -04003651 lpfc_nlp_put(ndlp);
James Smart98c9ea52007-10-27 13:37:33 -04003652 return;
dea31012005-04-17 16:05:31 -05003653}
3654
3655/*
3656 * Start / ReStart rescue timer for Discovery / RSCN handling
3657 */
3658void
James Smart2e0fef82007-06-17 19:56:36 -05003659lpfc_set_disctmo(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003660{
James Smart2e0fef82007-06-17 19:56:36 -05003661 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3662 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05003663 uint32_t tmo;
3664
James Smart2e0fef82007-06-17 19:56:36 -05003665 if (vport->port_state == LPFC_LOCAL_CFG_LINK) {
Frederik Schwarzer025dfda2008-10-16 19:02:37 +02003666 /* For FAN, timeout should be greater than edtov */
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003667 tmo = (((phba->fc_edtov + 999) / 1000) + 1);
3668 } else {
Frederik Schwarzer025dfda2008-10-16 19:02:37 +02003669 /* Normal discovery timeout should be > than ELS/CT timeout
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05003670 * FC spec states we need 3 * ratov for CT requests
3671 */
3672 tmo = ((phba->fc_ratov * 3) + 3);
3673 }
dea31012005-04-17 16:05:31 -05003674
James Smart858c9f62007-06-17 19:56:39 -05003675
3676 if (!timer_pending(&vport->fc_disctmo)) {
3677 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3678 "set disc timer: tmo:x%x state:x%x flg:x%x",
3679 tmo, vport->port_state, vport->fc_flag);
3680 }
3681
James Smart2e0fef82007-06-17 19:56:36 -05003682 mod_timer(&vport->fc_disctmo, jiffies + HZ * tmo);
3683 spin_lock_irq(shost->host_lock);
3684 vport->fc_flag |= FC_DISC_TMO;
3685 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05003686
3687 /* Start Discovery Timer state <hba_state> */
James Smarte8b62012007-08-02 11:10:09 -04003688 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3689 "0247 Start Discovery Timer state x%x "
3690 "Data: x%x x%lx x%x x%x\n",
3691 vport->port_state, tmo,
3692 (unsigned long)&vport->fc_disctmo, vport->fc_plogi_cnt,
3693 vport->fc_adisc_cnt);
dea31012005-04-17 16:05:31 -05003694
3695 return;
3696}
3697
3698/*
3699 * Cancel rescue timer for Discovery / RSCN handling
3700 */
3701int
James Smart2e0fef82007-06-17 19:56:36 -05003702lpfc_can_disctmo(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05003703{
James Smart2e0fef82007-06-17 19:56:36 -05003704 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05003705 unsigned long iflags;
3706
James Smart858c9f62007-06-17 19:56:39 -05003707 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
3708 "can disc timer: state:x%x rtry:x%x flg:x%x",
3709 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
3710
dea31012005-04-17 16:05:31 -05003711 /* Turn off discovery timer if its running */
James Smart2e0fef82007-06-17 19:56:36 -05003712 if (vport->fc_flag & FC_DISC_TMO) {
3713 spin_lock_irqsave(shost->host_lock, iflags);
3714 vport->fc_flag &= ~FC_DISC_TMO;
3715 spin_unlock_irqrestore(shost->host_lock, iflags);
3716 del_timer_sync(&vport->fc_disctmo);
3717 spin_lock_irqsave(&vport->work_port_lock, iflags);
3718 vport->work_port_events &= ~WORKER_DISC_TMO;
3719 spin_unlock_irqrestore(&vport->work_port_lock, iflags);
dea31012005-04-17 16:05:31 -05003720 }
3721
3722 /* Cancel Discovery Timer state <hba_state> */
James Smarte8b62012007-08-02 11:10:09 -04003723 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
3724 "0248 Cancel Discovery Timer state x%x "
3725 "Data: x%x x%x x%x\n",
3726 vport->port_state, vport->fc_flag,
3727 vport->fc_plogi_cnt, vport->fc_adisc_cnt);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003728 return 0;
dea31012005-04-17 16:05:31 -05003729}
3730
3731/*
3732 * Check specified ring for outstanding IOCB on the SLI queue
3733 * Return true if iocb matches the specified nport
3734 */
3735int
James Smart2e0fef82007-06-17 19:56:36 -05003736lpfc_check_sli_ndlp(struct lpfc_hba *phba,
3737 struct lpfc_sli_ring *pring,
3738 struct lpfc_iocbq *iocb,
3739 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003740{
James Smart2e0fef82007-06-17 19:56:36 -05003741 struct lpfc_sli *psli = &phba->sli;
3742 IOCB_t *icmd = &iocb->iocb;
James Smart92d7f7b2007-06-17 19:56:38 -05003743 struct lpfc_vport *vport = ndlp->vport;
3744
3745 if (iocb->vport != vport)
3746 return 0;
3747
dea31012005-04-17 16:05:31 -05003748 if (pring->ringno == LPFC_ELS_RING) {
3749 switch (icmd->ulpCommand) {
3750 case CMD_GEN_REQUEST64_CR:
James Smart21e9a0a2009-05-22 14:53:21 -04003751 if (iocb->context_un.ndlp == ndlp)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003752 return 1;
dea31012005-04-17 16:05:31 -05003753 case CMD_ELS_REQUEST64_CR:
James Smart10d4e952006-04-15 11:53:15 -04003754 if (icmd->un.elsreq64.remoteID == ndlp->nlp_DID)
3755 return 1;
dea31012005-04-17 16:05:31 -05003756 case CMD_XMIT_ELS_RSP64_CX:
3757 if (iocb->context1 == (uint8_t *) ndlp)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003758 return 1;
dea31012005-04-17 16:05:31 -05003759 }
James Smarta4bc3372006-12-02 13:34:16 -05003760 } else if (pring->ringno == psli->extra_ring) {
dea31012005-04-17 16:05:31 -05003761
3762 } else if (pring->ringno == psli->fcp_ring) {
3763 /* Skip match check if waiting to relogin to FCP target */
3764 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
James Smart92d7f7b2007-06-17 19:56:38 -05003765 (ndlp->nlp_flag & NLP_DELAY_TMO)) {
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003766 return 0;
dea31012005-04-17 16:05:31 -05003767 }
3768 if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) {
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003769 return 1;
dea31012005-04-17 16:05:31 -05003770 }
3771 } else if (pring->ringno == psli->next_ring) {
3772
3773 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003774 return 0;
dea31012005-04-17 16:05:31 -05003775}
3776
3777/*
3778 * Free resources / clean up outstanding I/Os
3779 * associated with nlp_rpi in the LPFC_NODELIST entry.
3780 */
3781static int
James Smart2e0fef82007-06-17 19:56:36 -05003782lpfc_no_rpi(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003783{
James Smart2534ba72007-04-25 09:52:20 -04003784 LIST_HEAD(completions);
dea31012005-04-17 16:05:31 -05003785 struct lpfc_sli *psli;
3786 struct lpfc_sli_ring *pring;
3787 struct lpfc_iocbq *iocb, *next_iocb;
James Smart6a9c52c2009-10-02 15:16:51 -04003788 uint32_t i;
dea31012005-04-17 16:05:31 -05003789
James Smart92d7f7b2007-06-17 19:56:38 -05003790 lpfc_fabric_abort_nport(ndlp);
3791
dea31012005-04-17 16:05:31 -05003792 /*
3793 * Everything that matches on txcmplq will be returned
3794 * by firmware with a no rpi error.
3795 */
3796 psli = &phba->sli;
James Smart21e9a0a2009-05-22 14:53:21 -04003797 if (ndlp->nlp_flag & NLP_RPI_VALID) {
dea31012005-04-17 16:05:31 -05003798 /* Now process each ring */
3799 for (i = 0; i < psli->num_rings; i++) {
3800 pring = &psli->ring[i];
3801
James Smart2e0fef82007-06-17 19:56:36 -05003802 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003803 list_for_each_entry_safe(iocb, next_iocb, &pring->txq,
James Smart2e0fef82007-06-17 19:56:36 -05003804 list) {
dea31012005-04-17 16:05:31 -05003805 /*
3806 * Check to see if iocb matches the nport we are
3807 * looking for
3808 */
James Smart92d7f7b2007-06-17 19:56:38 -05003809 if ((lpfc_check_sli_ndlp(phba, pring, iocb,
3810 ndlp))) {
dea31012005-04-17 16:05:31 -05003811 /* It matches, so deque and call compl
3812 with an error */
James Smart2534ba72007-04-25 09:52:20 -04003813 list_move_tail(&iocb->list,
3814 &completions);
dea31012005-04-17 16:05:31 -05003815 pring->txq_cnt--;
dea31012005-04-17 16:05:31 -05003816 }
3817 }
James Smart2e0fef82007-06-17 19:56:36 -05003818 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05003819 }
3820 }
James Smart2534ba72007-04-25 09:52:20 -04003821
James Smarta257bf92009-04-06 18:48:10 -04003822 /* Cancel all the IOCBs from the completions list */
3823 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
3824 IOERR_SLI_ABORTED);
James Smart2534ba72007-04-25 09:52:20 -04003825
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05003826 return 0;
dea31012005-04-17 16:05:31 -05003827}
3828
3829/*
3830 * Free rpi associated with LPFC_NODELIST entry.
3831 * This routine is called from lpfc_freenode(), when we are removing
3832 * a LPFC_NODELIST entry. It is also called if the driver initiates a
3833 * LOGO that completes successfully, and we are waiting to PLOGI back
3834 * to the remote NPort. In addition, it is called after we receive
3835 * and unsolicated ELS cmd, send back a rsp, the rsp completes and
3836 * we are waiting to PLOGI back to the remote NPort.
3837 */
3838int
James Smart2e0fef82007-06-17 19:56:36 -05003839lpfc_unreg_rpi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003840{
James Smart2e0fef82007-06-17 19:56:36 -05003841 struct lpfc_hba *phba = vport->phba;
3842 LPFC_MBOXQ_t *mbox;
dea31012005-04-17 16:05:31 -05003843 int rc;
3844
James Smart21e9a0a2009-05-22 14:53:21 -04003845 if (ndlp->nlp_flag & NLP_RPI_VALID) {
James Smart2e0fef82007-06-17 19:56:36 -05003846 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3847 if (mbox) {
James Smart92d7f7b2007-06-17 19:56:38 -05003848 lpfc_unreg_login(phba, vport->vpi, ndlp->nlp_rpi, mbox);
James Smarted957682007-06-17 19:56:37 -05003849 mbox->vport = vport;
James Smart92d7f7b2007-06-17 19:56:38 -05003850 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart0b727fe2007-10-27 13:37:25 -04003851 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -05003852 if (rc == MBX_NOT_FINISHED)
James Smart2e0fef82007-06-17 19:56:36 -05003853 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05003854 }
dea31012005-04-17 16:05:31 -05003855 lpfc_no_rpi(phba, ndlp);
James Smartd7c47992010-06-08 18:31:54 -04003856
dea31012005-04-17 16:05:31 -05003857 ndlp->nlp_rpi = 0;
James Smart21e9a0a2009-05-22 14:53:21 -04003858 ndlp->nlp_flag &= ~NLP_RPI_VALID;
James Smart0c287582009-06-10 17:22:56 -04003859 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
dea31012005-04-17 16:05:31 -05003860 return 1;
3861 }
3862 return 0;
3863}
3864
James Smartecfd03c2010-02-12 14:41:27 -05003865/**
3866 * lpfc_unreg_hba_rpis - Unregister rpis registered to the hba.
3867 * @phba: pointer to lpfc hba data structure.
3868 *
3869 * This routine is invoked to unregister all the currently registered RPIs
3870 * to the HBA.
3871 **/
3872void
3873lpfc_unreg_hba_rpis(struct lpfc_hba *phba)
3874{
3875 struct lpfc_vport **vports;
3876 struct lpfc_nodelist *ndlp;
3877 struct Scsi_Host *shost;
3878 int i;
3879
3880 vports = lpfc_create_vport_work_array(phba);
3881 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
3882 shost = lpfc_shost_from_vport(vports[i]);
3883 spin_lock_irq(shost->host_lock);
3884 list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) {
James Smart0c9ab6f2010-02-26 14:15:57 -05003885 if (ndlp->nlp_flag & NLP_RPI_VALID) {
3886 /* The mempool_alloc might sleep */
3887 spin_unlock_irq(shost->host_lock);
James Smartecfd03c2010-02-12 14:41:27 -05003888 lpfc_unreg_rpi(vports[i], ndlp);
James Smart0c9ab6f2010-02-26 14:15:57 -05003889 spin_lock_irq(shost->host_lock);
3890 }
James Smartecfd03c2010-02-12 14:41:27 -05003891 }
3892 spin_unlock_irq(shost->host_lock);
3893 }
3894 lpfc_destroy_vport_work_array(phba, vports);
3895}
3896
James Smart92d7f7b2007-06-17 19:56:38 -05003897void
3898lpfc_unreg_all_rpis(struct lpfc_vport *vport)
3899{
3900 struct lpfc_hba *phba = vport->phba;
3901 LPFC_MBOXQ_t *mbox;
3902 int rc;
3903
3904 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3905 if (mbox) {
3906 lpfc_unreg_login(phba, vport->vpi, 0xffff, mbox);
3907 mbox->vport = vport;
3908 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart09372822008-01-11 01:52:54 -05003909 mbox->context1 = NULL;
3910 rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
James Smarta257bf92009-04-06 18:48:10 -04003911 if (rc != MBX_TIMEOUT)
James Smart92d7f7b2007-06-17 19:56:38 -05003912 mempool_free(mbox, phba->mbox_mem_pool);
James Smarta257bf92009-04-06 18:48:10 -04003913
3914 if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED))
3915 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT,
3916 "1836 Could not issue "
3917 "unreg_login(all_rpis) status %d\n", rc);
James Smart92d7f7b2007-06-17 19:56:38 -05003918 }
3919}
3920
3921void
3922lpfc_unreg_default_rpis(struct lpfc_vport *vport)
3923{
3924 struct lpfc_hba *phba = vport->phba;
3925 LPFC_MBOXQ_t *mbox;
3926 int rc;
3927
3928 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
3929 if (mbox) {
3930 lpfc_unreg_did(phba, vport->vpi, 0xffffffff, mbox);
3931 mbox->vport = vport;
3932 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart09372822008-01-11 01:52:54 -05003933 mbox->context1 = NULL;
3934 rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
James Smarta257bf92009-04-06 18:48:10 -04003935 if (rc != MBX_TIMEOUT)
3936 mempool_free(mbox, phba->mbox_mem_pool);
3937
3938 if ((rc == MBX_TIMEOUT) || (rc == MBX_NOT_FINISHED))
James Smarte8b62012007-08-02 11:10:09 -04003939 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT,
3940 "1815 Could not issue "
James Smarta257bf92009-04-06 18:48:10 -04003941 "unreg_did (default rpis) status %d\n",
3942 rc);
James Smart92d7f7b2007-06-17 19:56:38 -05003943 }
3944}
3945
dea31012005-04-17 16:05:31 -05003946/*
3947 * Free resources associated with LPFC_NODELIST entry
3948 * so it can be freed.
3949 */
3950static int
James Smart2e0fef82007-06-17 19:56:36 -05003951lpfc_cleanup_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05003952{
James Smart2e0fef82007-06-17 19:56:36 -05003953 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
3954 struct lpfc_hba *phba = vport->phba;
3955 LPFC_MBOXQ_t *mb, *nextmb;
dea31012005-04-17 16:05:31 -05003956 struct lpfc_dmabuf *mp;
dea31012005-04-17 16:05:31 -05003957
3958 /* Cleanup node for NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04003959 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
3960 "0900 Cleanup node for NPort x%x "
3961 "Data: x%x x%x x%x\n",
3962 ndlp->nlp_DID, ndlp->nlp_flag,
3963 ndlp->nlp_state, ndlp->nlp_rpi);
James Smarte47c9092008-02-08 18:49:26 -05003964 if (NLP_CHK_FREE_REQ(ndlp)) {
3965 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
3966 "0280 lpfc_cleanup_node: ndlp:x%p "
3967 "usgmap:x%x refcnt:%d\n",
3968 (void *)ndlp, ndlp->nlp_usg_map,
3969 atomic_read(&ndlp->kref.refcount));
3970 lpfc_dequeue_node(vport, ndlp);
3971 } else {
3972 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
3973 "0281 lpfc_cleanup_node: ndlp:x%p "
3974 "usgmap:x%x refcnt:%d\n",
3975 (void *)ndlp, ndlp->nlp_usg_map,
3976 atomic_read(&ndlp->kref.refcount));
3977 lpfc_disable_node(vport, ndlp);
3978 }
dea31012005-04-17 16:05:31 -05003979
dea31012005-04-17 16:05:31 -05003980 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
3981 if ((mb = phba->sli.mbox_active)) {
James Smart04c68492009-05-22 14:52:52 -04003982 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
dea31012005-04-17 16:05:31 -05003983 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
3984 mb->context2 = NULL;
3985 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
3986 }
3987 }
James Smart33ccf8d2006-08-17 11:57:58 -04003988
James Smart2e0fef82007-06-17 19:56:36 -05003989 spin_lock_irq(&phba->hbalock);
James Smart5ac6b302010-10-22 11:05:36 -04003990 /* Cleanup REG_LOGIN completions which are not yet processed */
3991 list_for_each_entry(mb, &phba->sli.mboxq_cmpl, list) {
3992 if ((mb->u.mb.mbxCommand != MBX_REG_LOGIN64) ||
3993 (ndlp != (struct lpfc_nodelist *) mb->context2))
3994 continue;
3995
3996 mb->context2 = NULL;
3997 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
3998 }
3999
dea31012005-04-17 16:05:31 -05004000 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
James Smart04c68492009-05-22 14:52:52 -04004001 if ((mb->u.mb.mbxCommand == MBX_REG_LOGIN64) &&
James Smart92d7f7b2007-06-17 19:56:38 -05004002 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
dea31012005-04-17 16:05:31 -05004003 mp = (struct lpfc_dmabuf *) (mb->context1);
4004 if (mp) {
James Smart2e0fef82007-06-17 19:56:36 -05004005 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
dea31012005-04-17 16:05:31 -05004006 kfree(mp);
4007 }
4008 list_del(&mb->list);
James Smartffc95492010-06-07 15:23:17 -04004009 if (phba->sli_rev == LPFC_SLI_REV4)
4010 lpfc_sli4_free_rpi(phba,
4011 mb->u.mb.un.varRegLogin.rpi);
dea31012005-04-17 16:05:31 -05004012 mempool_free(mb, phba->mbox_mem_pool);
James Smarte47c9092008-02-08 18:49:26 -05004013 /* We shall not invoke the lpfc_nlp_put to decrement
4014 * the ndlp reference count as we are in the process
4015 * of lpfc_nlp_release.
4016 */
dea31012005-04-17 16:05:31 -05004017 }
4018 }
James Smart2e0fef82007-06-17 19:56:36 -05004019 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004020
James Smarte47c9092008-02-08 18:49:26 -05004021 lpfc_els_abort(phba, ndlp);
4022
James Smart2e0fef82007-06-17 19:56:36 -05004023 spin_lock_irq(shost->host_lock);
James Smartc01f3202006-08-18 17:47:08 -04004024 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05004025 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004026
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05004027 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05004028 del_timer_sync(&ndlp->nlp_delayfunc);
4029
James Smart0d2b6b82008-06-14 22:52:47 -04004030 list_del_init(&ndlp->els_retry_evt.evt_listp);
4031 list_del_init(&ndlp->dev_loss_evt.evt_listp);
dea31012005-04-17 16:05:31 -05004032
James Smart2e0fef82007-06-17 19:56:36 -05004033 lpfc_unreg_rpi(vport, ndlp);
dea31012005-04-17 16:05:31 -05004034
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004035 return 0;
dea31012005-04-17 16:05:31 -05004036}
4037
4038/*
4039 * Check to see if we can free the nlp back to the freelist.
4040 * If we are in the middle of using the nlp in the discovery state
4041 * machine, defer the free till we reach the end of the state machine.
4042 */
James Smart329f9bc2007-04-25 09:53:01 -04004043static void
James Smart2e0fef82007-06-17 19:56:36 -05004044lpfc_nlp_remove(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004045{
James Smarta8adb832007-10-27 13:37:53 -04004046 struct lpfc_hba *phba = vport->phba;
James Smart1dcb58e2007-04-25 09:51:30 -04004047 struct lpfc_rport_data *rdata;
James Smarta8adb832007-10-27 13:37:53 -04004048 LPFC_MBOXQ_t *mbox;
4049 int rc;
dea31012005-04-17 16:05:31 -05004050
James Smart0d2b6b82008-06-14 22:52:47 -04004051 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smart21e9a0a2009-05-22 14:53:21 -04004052 if ((ndlp->nlp_flag & NLP_DEFER_RM) &&
James Smartffc95492010-06-07 15:23:17 -04004053 !(ndlp->nlp_flag & NLP_REG_LOGIN_SEND) &&
James Smart21e9a0a2009-05-22 14:53:21 -04004054 !(ndlp->nlp_flag & NLP_RPI_VALID)) {
James Smarta8adb832007-10-27 13:37:53 -04004055 /* For this case we need to cleanup the default rpi
4056 * allocated by the firmware.
4057 */
4058 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))
4059 != NULL) {
James Smart21e9a0a2009-05-22 14:53:21 -04004060 rc = lpfc_reg_rpi(phba, vport->vpi, ndlp->nlp_DID,
James Smarta8adb832007-10-27 13:37:53 -04004061 (uint8_t *) &vport->fc_sparam, mbox, 0);
4062 if (rc) {
4063 mempool_free(mbox, phba->mbox_mem_pool);
4064 }
4065 else {
4066 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
4067 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
4068 mbox->vport = vport;
James Smart09372822008-01-11 01:52:54 -05004069 mbox->context2 = NULL;
James Smarta8adb832007-10-27 13:37:53 -04004070 rc =lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
4071 if (rc == MBX_NOT_FINISHED) {
4072 mempool_free(mbox, phba->mbox_mem_pool);
4073 }
4074 }
4075 }
4076 }
James Smart2e0fef82007-06-17 19:56:36 -05004077 lpfc_cleanup_node(vport, ndlp);
James Smart1dcb58e2007-04-25 09:51:30 -04004078
James Smart2e0fef82007-06-17 19:56:36 -05004079 /*
James Smart92d7f7b2007-06-17 19:56:38 -05004080 * We can get here with a non-NULL ndlp->rport because when we
4081 * unregister a rport we don't break the rport/node linkage. So if we
4082 * do, make sure we don't leaving any dangling pointers behind.
James Smart2e0fef82007-06-17 19:56:36 -05004083 */
James Smart92d7f7b2007-06-17 19:56:38 -05004084 if (ndlp->rport) {
James Smart329f9bc2007-04-25 09:53:01 -04004085 rdata = ndlp->rport->dd_data;
4086 rdata->pnode = NULL;
4087 ndlp->rport = NULL;
dea31012005-04-17 16:05:31 -05004088 }
dea31012005-04-17 16:05:31 -05004089}
4090
4091static int
James Smart2e0fef82007-06-17 19:56:36 -05004092lpfc_matchdid(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4093 uint32_t did)
dea31012005-04-17 16:05:31 -05004094{
James Smart2e0fef82007-06-17 19:56:36 -05004095 D_ID mydid, ndlpdid, matchdid;
dea31012005-04-17 16:05:31 -05004096
4097 if (did == Bcast_DID)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004098 return 0;
dea31012005-04-17 16:05:31 -05004099
dea31012005-04-17 16:05:31 -05004100 /* First check for Direct match */
4101 if (ndlp->nlp_DID == did)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004102 return 1;
dea31012005-04-17 16:05:31 -05004103
4104 /* Next check for area/domain identically equals 0 match */
James Smart2e0fef82007-06-17 19:56:36 -05004105 mydid.un.word = vport->fc_myDID;
dea31012005-04-17 16:05:31 -05004106 if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) {
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004107 return 0;
dea31012005-04-17 16:05:31 -05004108 }
4109
4110 matchdid.un.word = did;
4111 ndlpdid.un.word = ndlp->nlp_DID;
4112 if (matchdid.un.b.id == ndlpdid.un.b.id) {
4113 if ((mydid.un.b.domain == matchdid.un.b.domain) &&
4114 (mydid.un.b.area == matchdid.un.b.area)) {
4115 if ((ndlpdid.un.b.domain == 0) &&
4116 (ndlpdid.un.b.area == 0)) {
4117 if (ndlpdid.un.b.id)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004118 return 1;
dea31012005-04-17 16:05:31 -05004119 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004120 return 0;
dea31012005-04-17 16:05:31 -05004121 }
4122
4123 matchdid.un.word = ndlp->nlp_DID;
4124 if ((mydid.un.b.domain == ndlpdid.un.b.domain) &&
4125 (mydid.un.b.area == ndlpdid.un.b.area)) {
4126 if ((matchdid.un.b.domain == 0) &&
4127 (matchdid.un.b.area == 0)) {
4128 if (matchdid.un.b.id)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004129 return 1;
dea31012005-04-17 16:05:31 -05004130 }
4131 }
4132 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004133 return 0;
dea31012005-04-17 16:05:31 -05004134}
4135
James Smart685f0bf2007-04-25 09:53:08 -04004136/* Search for a nodelist entry */
James Smart2e0fef82007-06-17 19:56:36 -05004137static struct lpfc_nodelist *
4138__lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05004139{
James Smart2fb9bd82006-12-02 13:33:57 -05004140 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05004141 uint32_t data1;
4142
James Smart2e0fef82007-06-17 19:56:36 -05004143 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
4144 if (lpfc_matchdid(vport, ndlp, did)) {
James Smart685f0bf2007-04-25 09:53:08 -04004145 data1 = (((uint32_t) ndlp->nlp_state << 24) |
4146 ((uint32_t) ndlp->nlp_xri << 16) |
4147 ((uint32_t) ndlp->nlp_type << 8) |
4148 ((uint32_t) ndlp->nlp_rpi & 0xff));
James Smarte8b62012007-08-02 11:10:09 -04004149 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4150 "0929 FIND node DID "
4151 "Data: x%p x%x x%x x%x\n",
4152 ndlp, ndlp->nlp_DID,
4153 ndlp->nlp_flag, data1);
James Smart685f0bf2007-04-25 09:53:08 -04004154 return ndlp;
dea31012005-04-17 16:05:31 -05004155 }
4156 }
Jamie Wellnitz66a9ed62006-02-28 22:33:10 -05004157
dea31012005-04-17 16:05:31 -05004158 /* FIND node did <did> NOT FOUND */
James Smarte8b62012007-08-02 11:10:09 -04004159 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
4160 "0932 FIND node did x%x NOT FOUND.\n", did);
dea31012005-04-17 16:05:31 -05004161 return NULL;
4162}
4163
4164struct lpfc_nodelist *
James Smart2e0fef82007-06-17 19:56:36 -05004165lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05004166{
James Smart2e0fef82007-06-17 19:56:36 -05004167 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05004168 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05004169
James Smart2e0fef82007-06-17 19:56:36 -05004170 spin_lock_irq(shost->host_lock);
4171 ndlp = __lpfc_findnode_did(vport, did);
4172 spin_unlock_irq(shost->host_lock);
4173 return ndlp;
4174}
4175
4176struct lpfc_nodelist *
4177lpfc_setup_disc_node(struct lpfc_vport *vport, uint32_t did)
4178{
4179 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4180 struct lpfc_nodelist *ndlp;
4181
4182 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004183 if (!ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05004184 if ((vport->fc_flag & FC_RSCN_MODE) != 0 &&
4185 lpfc_rscn_payload_check(vport, did) == 0)
dea31012005-04-17 16:05:31 -05004186 return NULL;
4187 ndlp = (struct lpfc_nodelist *)
James Smart2e0fef82007-06-17 19:56:36 -05004188 mempool_alloc(vport->phba->nlp_mem_pool, GFP_KERNEL);
dea31012005-04-17 16:05:31 -05004189 if (!ndlp)
4190 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05004191 lpfc_nlp_init(vport, ndlp, did);
4192 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
4193 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004194 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05004195 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004196 return ndlp;
James Smarte47c9092008-02-08 18:49:26 -05004197 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
4198 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_NPR_NODE);
4199 if (!ndlp)
4200 return NULL;
4201 spin_lock_irq(shost->host_lock);
4202 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
4203 spin_unlock_irq(shost->host_lock);
4204 return ndlp;
dea31012005-04-17 16:05:31 -05004205 }
James Smarte47c9092008-02-08 18:49:26 -05004206
James Smart58da1ff2008-04-07 10:15:56 -04004207 if ((vport->fc_flag & FC_RSCN_MODE) &&
4208 !(vport->fc_flag & FC_NDISC_ACTIVE)) {
James Smart2e0fef82007-06-17 19:56:36 -05004209 if (lpfc_rscn_payload_check(vport, did)) {
James Smart87af33f2007-10-27 13:37:43 -04004210 /* If we've already recieved a PLOGI from this NPort
4211 * we don't need to try to discover it again.
4212 */
4213 if (ndlp->nlp_flag & NLP_RCV_PLOGI)
4214 return NULL;
4215
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004216 /* Since this node is marked for discovery,
4217 * delay timeout is not needed.
4218 */
James Smart0d2b6b82008-06-14 22:52:47 -04004219 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smarta257bf92009-04-06 18:48:10 -04004220 spin_lock_irq(shost->host_lock);
4221 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
4222 spin_unlock_irq(shost->host_lock);
James Smart071fbd3d2006-04-15 11:53:20 -04004223 } else
dea31012005-04-17 16:05:31 -05004224 ndlp = NULL;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004225 } else {
James Smart87af33f2007-10-27 13:37:43 -04004226 /* If we've already recieved a PLOGI from this NPort,
4227 * or we are already in the process of discovery on it,
4228 * we don't need to try to discover it again.
4229 */
James Smart685f0bf2007-04-25 09:53:08 -04004230 if (ndlp->nlp_state == NLP_STE_ADISC_ISSUE ||
James Smart87af33f2007-10-27 13:37:43 -04004231 ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
4232 ndlp->nlp_flag & NLP_RCV_PLOGI)
dea31012005-04-17 16:05:31 -05004233 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05004234 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
4235 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004236 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05004237 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004238 }
4239 return ndlp;
4240}
4241
4242/* Build a list of nodes to discover based on the loopmap */
4243void
James Smart2e0fef82007-06-17 19:56:36 -05004244lpfc_disc_list_loopmap(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004245{
James Smart2e0fef82007-06-17 19:56:36 -05004246 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004247 int j;
4248 uint32_t alpa, index;
4249
James Smart2e0fef82007-06-17 19:56:36 -05004250 if (!lpfc_is_link_up(phba))
dea31012005-04-17 16:05:31 -05004251 return;
James Smart2e0fef82007-06-17 19:56:36 -05004252
4253 if (phba->fc_topology != TOPOLOGY_LOOP)
dea31012005-04-17 16:05:31 -05004254 return;
dea31012005-04-17 16:05:31 -05004255
4256 /* Check for loop map present or not */
4257 if (phba->alpa_map[0]) {
4258 for (j = 1; j <= phba->alpa_map[0]; j++) {
4259 alpa = phba->alpa_map[j];
James Smart2e0fef82007-06-17 19:56:36 -05004260 if (((vport->fc_myDID & 0xff) == alpa) || (alpa == 0))
dea31012005-04-17 16:05:31 -05004261 continue;
James Smart2e0fef82007-06-17 19:56:36 -05004262 lpfc_setup_disc_node(vport, alpa);
dea31012005-04-17 16:05:31 -05004263 }
4264 } else {
4265 /* No alpamap, so try all alpa's */
4266 for (j = 0; j < FC_MAXLOOP; j++) {
4267 /* If cfg_scan_down is set, start from highest
4268 * ALPA (0xef) to lowest (0x1).
4269 */
James Smart3de2a652007-08-02 11:09:59 -04004270 if (vport->cfg_scan_down)
dea31012005-04-17 16:05:31 -05004271 index = j;
4272 else
4273 index = FC_MAXLOOP - j - 1;
4274 alpa = lpfcAlpaArray[index];
James Smart2e0fef82007-06-17 19:56:36 -05004275 if ((vport->fc_myDID & 0xff) == alpa)
dea31012005-04-17 16:05:31 -05004276 continue;
James Smart2e0fef82007-06-17 19:56:36 -05004277 lpfc_setup_disc_node(vport, alpa);
dea31012005-04-17 16:05:31 -05004278 }
4279 }
4280 return;
4281}
4282
dea31012005-04-17 16:05:31 -05004283void
James Smart2e0fef82007-06-17 19:56:36 -05004284lpfc_issue_clear_la(struct lpfc_hba *phba, struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004285{
dea31012005-04-17 16:05:31 -05004286 LPFC_MBOXQ_t *mbox;
James Smart2e0fef82007-06-17 19:56:36 -05004287 struct lpfc_sli *psli = &phba->sli;
4288 struct lpfc_sli_ring *extra_ring = &psli->ring[psli->extra_ring];
4289 struct lpfc_sli_ring *fcp_ring = &psli->ring[psli->fcp_ring];
4290 struct lpfc_sli_ring *next_ring = &psli->ring[psli->next_ring];
4291 int rc;
4292
James Smart92d7f7b2007-06-17 19:56:38 -05004293 /*
4294 * if it's not a physical port or if we already send
4295 * clear_la then don't send it.
4296 */
4297 if ((phba->link_state >= LPFC_CLEAR_LA) ||
James Smartda0436e2009-05-22 14:51:39 -04004298 (vport->port_type != LPFC_PHYSICAL_PORT) ||
4299 (phba->sli_rev == LPFC_SLI_REV4))
James Smart92d7f7b2007-06-17 19:56:38 -05004300 return;
4301
James Smart2e0fef82007-06-17 19:56:36 -05004302 /* Link up discovery */
4303 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL)) != NULL) {
4304 phba->link_state = LPFC_CLEAR_LA;
4305 lpfc_clear_la(phba, mbox);
4306 mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
4307 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -04004308 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart2e0fef82007-06-17 19:56:36 -05004309 if (rc == MBX_NOT_FINISHED) {
4310 mempool_free(mbox, phba->mbox_mem_pool);
4311 lpfc_disc_flush_list(vport);
4312 extra_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
4313 fcp_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
4314 next_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
James Smart92d7f7b2007-06-17 19:56:38 -05004315 phba->link_state = LPFC_HBA_ERROR;
4316 }
4317 }
4318}
4319
4320/* Reg_vpi to tell firmware to resume normal operations */
4321void
4322lpfc_issue_reg_vpi(struct lpfc_hba *phba, struct lpfc_vport *vport)
4323{
4324 LPFC_MBOXQ_t *regvpimbox;
4325
4326 regvpimbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4327 if (regvpimbox) {
James Smartda0436e2009-05-22 14:51:39 -04004328 lpfc_reg_vpi(vport, regvpimbox);
James Smart92d7f7b2007-06-17 19:56:38 -05004329 regvpimbox->mbox_cmpl = lpfc_mbx_cmpl_reg_vpi;
4330 regvpimbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -04004331 if (lpfc_sli_issue_mbox(phba, regvpimbox, MBX_NOWAIT)
James Smart92d7f7b2007-06-17 19:56:38 -05004332 == MBX_NOT_FINISHED) {
4333 mempool_free(regvpimbox, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05004334 }
4335 }
4336}
4337
4338/* Start Link up / RSCN discovery on NPR nodes */
4339void
4340lpfc_disc_start(struct lpfc_vport *vport)
4341{
4342 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4343 struct lpfc_hba *phba = vport->phba;
James Smart685f0bf2007-04-25 09:53:08 -04004344 uint32_t num_sent;
dea31012005-04-17 16:05:31 -05004345 uint32_t clear_la_pending;
James Smart685f0bf2007-04-25 09:53:08 -04004346 int did_changed;
dea31012005-04-17 16:05:31 -05004347
James Smart2e0fef82007-06-17 19:56:36 -05004348 if (!lpfc_is_link_up(phba))
dea31012005-04-17 16:05:31 -05004349 return;
James Smart2e0fef82007-06-17 19:56:36 -05004350
4351 if (phba->link_state == LPFC_CLEAR_LA)
dea31012005-04-17 16:05:31 -05004352 clear_la_pending = 1;
4353 else
4354 clear_la_pending = 0;
4355
James Smart2e0fef82007-06-17 19:56:36 -05004356 if (vport->port_state < LPFC_VPORT_READY)
4357 vport->port_state = LPFC_DISC_AUTH;
dea31012005-04-17 16:05:31 -05004358
James Smart2e0fef82007-06-17 19:56:36 -05004359 lpfc_set_disctmo(vport);
4360
4361 if (vport->fc_prevDID == vport->fc_myDID)
dea31012005-04-17 16:05:31 -05004362 did_changed = 0;
James Smart2e0fef82007-06-17 19:56:36 -05004363 else
dea31012005-04-17 16:05:31 -05004364 did_changed = 1;
James Smart2e0fef82007-06-17 19:56:36 -05004365
4366 vport->fc_prevDID = vport->fc_myDID;
4367 vport->num_disc_nodes = 0;
dea31012005-04-17 16:05:31 -05004368
4369 /* Start Discovery state <hba_state> */
James Smarte8b62012007-08-02 11:10:09 -04004370 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
4371 "0202 Start Discovery hba state x%x "
4372 "Data: x%x x%x x%x\n",
4373 vport->port_state, vport->fc_flag, vport->fc_plogi_cnt,
4374 vport->fc_adisc_cnt);
dea31012005-04-17 16:05:31 -05004375
4376 /* First do ADISCs - if any */
James Smart2e0fef82007-06-17 19:56:36 -05004377 num_sent = lpfc_els_disc_adisc(vport);
dea31012005-04-17 16:05:31 -05004378
4379 if (num_sent)
4380 return;
4381
James Smart92d7f7b2007-06-17 19:56:38 -05004382 /*
4383 * For SLI3, cmpl_reg_vpi will set port_state to READY, and
4384 * continue discovery.
4385 */
4386 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart1b32f6a2008-02-08 18:49:39 -05004387 !(vport->fc_flag & FC_PT2PT) &&
James Smartda0436e2009-05-22 14:51:39 -04004388 !(vport->fc_flag & FC_RSCN_MODE) &&
4389 (phba->sli_rev < LPFC_SLI_REV4)) {
James Smart92d7f7b2007-06-17 19:56:38 -05004390 lpfc_issue_reg_vpi(phba, vport);
4391 return;
4392 }
James Smart2e0fef82007-06-17 19:56:36 -05004393
James Smart92d7f7b2007-06-17 19:56:38 -05004394 /*
4395 * For SLI2, we need to set port_state to READY and continue
4396 * discovery.
4397 */
4398 if (vport->port_state < LPFC_VPORT_READY && !clear_la_pending) {
4399 /* If we get here, there is nothing to ADISC */
4400 if (vport->port_type == LPFC_PHYSICAL_PORT)
4401 lpfc_issue_clear_la(phba, vport);
4402
4403 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
James Smart2e0fef82007-06-17 19:56:36 -05004404 vport->num_disc_nodes = 0;
4405 /* go thru NPR nodes and issue ELS PLOGIs */
4406 if (vport->fc_npr_cnt)
4407 lpfc_els_disc_plogi(vport);
4408
4409 if (!vport->num_disc_nodes) {
4410 spin_lock_irq(shost->host_lock);
4411 vport->fc_flag &= ~FC_NDISC_ACTIVE;
4412 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004413 lpfc_can_disctmo(vport);
dea31012005-04-17 16:05:31 -05004414 }
4415 }
James Smart92d7f7b2007-06-17 19:56:38 -05004416 vport->port_state = LPFC_VPORT_READY;
dea31012005-04-17 16:05:31 -05004417 } else {
4418 /* Next do PLOGIs - if any */
James Smart2e0fef82007-06-17 19:56:36 -05004419 num_sent = lpfc_els_disc_plogi(vport);
dea31012005-04-17 16:05:31 -05004420
4421 if (num_sent)
4422 return;
4423
James Smart2e0fef82007-06-17 19:56:36 -05004424 if (vport->fc_flag & FC_RSCN_MODE) {
dea31012005-04-17 16:05:31 -05004425 /* Check to see if more RSCNs came in while we
4426 * were processing this one.
4427 */
James Smart2e0fef82007-06-17 19:56:36 -05004428 if ((vport->fc_rscn_id_cnt == 0) &&
4429 (!(vport->fc_flag & FC_RSCN_DISCOVERY))) {
4430 spin_lock_irq(shost->host_lock);
4431 vport->fc_flag &= ~FC_RSCN_MODE;
4432 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05004433 lpfc_can_disctmo(vport);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004434 } else
James Smart2e0fef82007-06-17 19:56:36 -05004435 lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05004436 }
4437 }
4438 return;
4439}
4440
4441/*
4442 * Ignore completion for all IOCBs on tx and txcmpl queue for ELS
4443 * ring the match the sppecified nodelist.
4444 */
4445static void
James Smart2e0fef82007-06-17 19:56:36 -05004446lpfc_free_tx(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05004447{
James Smart2534ba72007-04-25 09:52:20 -04004448 LIST_HEAD(completions);
dea31012005-04-17 16:05:31 -05004449 struct lpfc_sli *psli;
4450 IOCB_t *icmd;
4451 struct lpfc_iocbq *iocb, *next_iocb;
4452 struct lpfc_sli_ring *pring;
dea31012005-04-17 16:05:31 -05004453
4454 psli = &phba->sli;
4455 pring = &psli->ring[LPFC_ELS_RING];
4456
4457 /* Error matching iocb on txq or txcmplq
4458 * First check the txq.
4459 */
James Smart2e0fef82007-06-17 19:56:36 -05004460 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05004461 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
4462 if (iocb->context1 != ndlp) {
4463 continue;
4464 }
4465 icmd = &iocb->iocb;
4466 if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
4467 (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
4468
James Smart2534ba72007-04-25 09:52:20 -04004469 list_move_tail(&iocb->list, &completions);
dea31012005-04-17 16:05:31 -05004470 pring->txq_cnt--;
dea31012005-04-17 16:05:31 -05004471 }
4472 }
4473
4474 /* Next check the txcmplq */
4475 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
4476 if (iocb->context1 != ndlp) {
4477 continue;
4478 }
4479 icmd = &iocb->iocb;
James Smart2e0fef82007-06-17 19:56:36 -05004480 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR ||
4481 icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX) {
James Smart2534ba72007-04-25 09:52:20 -04004482 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
dea31012005-04-17 16:05:31 -05004483 }
4484 }
James Smart2e0fef82007-06-17 19:56:36 -05004485 spin_unlock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04004486
James Smarta257bf92009-04-06 18:48:10 -04004487 /* Cancel all the IOCBs from the completions list */
4488 lpfc_sli_cancel_iocbs(phba, &completions, IOSTAT_LOCAL_REJECT,
4489 IOERR_SLI_ABORTED);
dea31012005-04-17 16:05:31 -05004490}
4491
Adrian Bunka6ababd2007-11-05 18:07:33 +01004492static void
James Smart2e0fef82007-06-17 19:56:36 -05004493lpfc_disc_flush_list(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004494{
4495 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05004496 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05004497
James Smart2e0fef82007-06-17 19:56:36 -05004498 if (vport->fc_plogi_cnt || vport->fc_adisc_cnt) {
4499 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
James Smart685f0bf2007-04-25 09:53:08 -04004500 nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004501 if (!NLP_CHK_NODE_ACT(ndlp))
4502 continue;
James Smart685f0bf2007-04-25 09:53:08 -04004503 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
4504 ndlp->nlp_state == NLP_STE_ADISC_ISSUE) {
4505 lpfc_free_tx(phba, ndlp);
James Smart685f0bf2007-04-25 09:53:08 -04004506 }
dea31012005-04-17 16:05:31 -05004507 }
4508 }
dea31012005-04-17 16:05:31 -05004509}
4510
James Smart92d7f7b2007-06-17 19:56:38 -05004511void
4512lpfc_cleanup_discovery_resources(struct lpfc_vport *vport)
4513{
4514 lpfc_els_flush_rscn(vport);
4515 lpfc_els_flush_cmd(vport);
4516 lpfc_disc_flush_list(vport);
4517}
4518
dea31012005-04-17 16:05:31 -05004519/*****************************************************************************/
4520/*
4521 * NAME: lpfc_disc_timeout
4522 *
4523 * FUNCTION: Fibre Channel driver discovery timeout routine.
4524 *
4525 * EXECUTION ENVIRONMENT: interrupt only
4526 *
4527 * CALLED FROM:
4528 * Timer function
4529 *
4530 * RETURNS:
4531 * none
4532 */
4533/*****************************************************************************/
4534void
4535lpfc_disc_timeout(unsigned long ptr)
4536{
James Smart2e0fef82007-06-17 19:56:36 -05004537 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
4538 struct lpfc_hba *phba = vport->phba;
James Smart5e9d9b82008-06-14 22:52:53 -04004539 uint32_t tmo_posted;
dea31012005-04-17 16:05:31 -05004540 unsigned long flags = 0;
4541
4542 if (unlikely(!phba))
4543 return;
4544
James Smart5e9d9b82008-06-14 22:52:53 -04004545 spin_lock_irqsave(&vport->work_port_lock, flags);
4546 tmo_posted = vport->work_port_events & WORKER_DISC_TMO;
4547 if (!tmo_posted)
James Smart2e0fef82007-06-17 19:56:36 -05004548 vport->work_port_events |= WORKER_DISC_TMO;
James Smart5e9d9b82008-06-14 22:52:53 -04004549 spin_unlock_irqrestore(&vport->work_port_lock, flags);
James Smart2e0fef82007-06-17 19:56:36 -05004550
James Smart5e9d9b82008-06-14 22:52:53 -04004551 if (!tmo_posted)
4552 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05004553 return;
4554}
4555
4556static void
James Smart2e0fef82007-06-17 19:56:36 -05004557lpfc_disc_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05004558{
James Smart2e0fef82007-06-17 19:56:36 -05004559 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
4560 struct lpfc_hba *phba = vport->phba;
4561 struct lpfc_sli *psli = &phba->sli;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004562 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart92d7f7b2007-06-17 19:56:38 -05004563 LPFC_MBOXQ_t *initlinkmbox;
dea31012005-04-17 16:05:31 -05004564 int rc, clrlaerr = 0;
4565
James Smart2e0fef82007-06-17 19:56:36 -05004566 if (!(vport->fc_flag & FC_DISC_TMO))
dea31012005-04-17 16:05:31 -05004567 return;
4568
James Smart2e0fef82007-06-17 19:56:36 -05004569 spin_lock_irq(shost->host_lock);
4570 vport->fc_flag &= ~FC_DISC_TMO;
4571 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05004572
James Smart858c9f62007-06-17 19:56:39 -05004573 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
4574 "disc timeout: state:x%x rtry:x%x flg:x%x",
4575 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
4576
James Smart2e0fef82007-06-17 19:56:36 -05004577 switch (vport->port_state) {
dea31012005-04-17 16:05:31 -05004578
4579 case LPFC_LOCAL_CFG_LINK:
James Smart2e0fef82007-06-17 19:56:36 -05004580 /* port_state is identically LPFC_LOCAL_CFG_LINK while waiting for
4581 * FAN
4582 */
4583 /* FAN timeout */
James Smarte8b62012007-08-02 11:10:09 -04004584 lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY,
4585 "0221 FAN timeout\n");
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004586 /* Start discovery by sending FLOGI, clean up old rpis */
James Smart2e0fef82007-06-17 19:56:36 -05004587 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
James Smart685f0bf2007-04-25 09:53:08 -04004588 nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05004589 if (!NLP_CHK_NODE_ACT(ndlp))
4590 continue;
James Smart685f0bf2007-04-25 09:53:08 -04004591 if (ndlp->nlp_state != NLP_STE_NPR_NODE)
4592 continue;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004593 if (ndlp->nlp_type & NLP_FABRIC) {
4594 /* Clean up the ndlp on Fabric connections */
James Smart2e0fef82007-06-17 19:56:36 -05004595 lpfc_drop_node(vport, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04004596
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05004597 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004598 /* Fail outstanding IO now since device
4599 * is marked for PLOGI.
4600 */
James Smart2e0fef82007-06-17 19:56:36 -05004601 lpfc_unreg_rpi(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05004602 }
4603 }
James Smart92d7f7b2007-06-17 19:56:38 -05004604 if (vport->port_state != LPFC_FLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05004605 lpfc_initial_flogi(vport);
James Smart0ff10d42008-01-11 01:52:36 -05004606 return;
James Smart92d7f7b2007-06-17 19:56:38 -05004607 }
dea31012005-04-17 16:05:31 -05004608 break;
4609
James Smart92d7f7b2007-06-17 19:56:38 -05004610 case LPFC_FDISC:
dea31012005-04-17 16:05:31 -05004611 case LPFC_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05004612 /* port_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */
dea31012005-04-17 16:05:31 -05004613 /* Initial FLOGI timeout */
James Smarte8b62012007-08-02 11:10:09 -04004614 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
4615 "0222 Initial %s timeout\n",
James Smart87af33f2007-10-27 13:37:43 -04004616 vport->vpi ? "FDISC" : "FLOGI");
dea31012005-04-17 16:05:31 -05004617
4618 /* Assume no Fabric and go on with discovery.
4619 * Check for outstanding ELS FLOGI to abort.
4620 */
4621
4622 /* FLOGI failed, so just use loop map to make discovery list */
James Smart2e0fef82007-06-17 19:56:36 -05004623 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -05004624
4625 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -05004626 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -05004627 break;
4628
4629 case LPFC_FABRIC_CFG_LINK:
4630 /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for
4631 NameServer login */
James Smarte8b62012007-08-02 11:10:09 -04004632 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
4633 "0223 Timeout while waiting for "
4634 "NameServer login\n");
dea31012005-04-17 16:05:31 -05004635 /* Next look for NameServer ndlp */
James Smart2e0fef82007-06-17 19:56:36 -05004636 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05004637 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart87af33f2007-10-27 13:37:43 -04004638 lpfc_els_abort(phba, ndlp);
4639
4640 /* ReStart discovery */
4641 goto restart_disc;
dea31012005-04-17 16:05:31 -05004642
4643 case LPFC_NS_QRY:
4644 /* Check for wait for NameServer Rsp timeout */
James Smarte8b62012007-08-02 11:10:09 -04004645 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
4646 "0224 NameServer Query timeout "
4647 "Data: x%x x%x\n",
4648 vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
dea31012005-04-17 16:05:31 -05004649
James Smart92d7f7b2007-06-17 19:56:38 -05004650 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
4651 /* Try it one more time */
4652 vport->fc_ns_retry++;
4653 rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT,
4654 vport->fc_ns_retry, 0);
4655 if (rc == 0)
4656 break;
dea31012005-04-17 16:05:31 -05004657 }
James Smart92d7f7b2007-06-17 19:56:38 -05004658 vport->fc_ns_retry = 0;
dea31012005-04-17 16:05:31 -05004659
James Smart87af33f2007-10-27 13:37:43 -04004660restart_disc:
James Smart92d7f7b2007-06-17 19:56:38 -05004661 /*
4662 * Discovery is over.
4663 * set port_state to PORT_READY if SLI2.
4664 * cmpl_reg_vpi will set port_state to READY for SLI3.
4665 */
James Smart3772a992009-05-22 14:50:54 -04004666 if (phba->sli_rev < LPFC_SLI_REV4) {
4667 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
4668 lpfc_issue_reg_vpi(phba, vport);
4669 else { /* NPIV Not enabled */
4670 lpfc_issue_clear_la(phba, vport);
4671 vport->port_state = LPFC_VPORT_READY;
4672 }
dea31012005-04-17 16:05:31 -05004673 }
4674
4675 /* Setup and issue mailbox INITIALIZE LINK command */
4676 initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
4677 if (!initlinkmbox) {
James Smarte8b62012007-08-02 11:10:09 -04004678 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
4679 "0206 Device Discovery "
4680 "completion error\n");
James Smart2e0fef82007-06-17 19:56:36 -05004681 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05004682 break;
4683 }
4684
4685 lpfc_linkdown(phba);
4686 lpfc_init_link(phba, initlinkmbox, phba->cfg_topology,
4687 phba->cfg_link_speed);
James Smart04c68492009-05-22 14:52:52 -04004688 initlinkmbox->u.mb.un.varInitLnk.lipsr_AL_PA = 0;
James Smarted957682007-06-17 19:56:37 -05004689 initlinkmbox->vport = vport;
James Smart92d7f7b2007-06-17 19:56:38 -05004690 initlinkmbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart0b727fe2007-10-27 13:37:25 -04004691 rc = lpfc_sli_issue_mbox(phba, initlinkmbox, MBX_NOWAIT);
James Smart5b8bd0c2007-04-25 09:52:49 -04004692 lpfc_set_loopback_flag(phba);
dea31012005-04-17 16:05:31 -05004693 if (rc == MBX_NOT_FINISHED)
4694 mempool_free(initlinkmbox, phba->mbox_mem_pool);
4695
4696 break;
4697
4698 case LPFC_DISC_AUTH:
4699 /* Node Authentication timeout */
James Smarte8b62012007-08-02 11:10:09 -04004700 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
4701 "0227 Node Authentication timeout\n");
James Smart2e0fef82007-06-17 19:56:36 -05004702 lpfc_disc_flush_list(vport);
4703
James Smart92d7f7b2007-06-17 19:56:38 -05004704 /*
4705 * set port_state to PORT_READY if SLI2.
4706 * cmpl_reg_vpi will set port_state to READY for SLI3.
4707 */
James Smart3772a992009-05-22 14:50:54 -04004708 if (phba->sli_rev < LPFC_SLI_REV4) {
4709 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
4710 lpfc_issue_reg_vpi(phba, vport);
4711 else { /* NPIV Not enabled */
4712 lpfc_issue_clear_la(phba, vport);
4713 vport->port_state = LPFC_VPORT_READY;
4714 }
dea31012005-04-17 16:05:31 -05004715 }
4716 break;
4717
James Smart2e0fef82007-06-17 19:56:36 -05004718 case LPFC_VPORT_READY:
4719 if (vport->fc_flag & FC_RSCN_MODE) {
James Smarte8b62012007-08-02 11:10:09 -04004720 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
4721 "0231 RSCN timeout Data: x%x "
4722 "x%x\n",
4723 vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
dea31012005-04-17 16:05:31 -05004724
4725 /* Cleanup any outstanding ELS commands */
James Smart2e0fef82007-06-17 19:56:36 -05004726 lpfc_els_flush_cmd(vport);
dea31012005-04-17 16:05:31 -05004727
James Smart2e0fef82007-06-17 19:56:36 -05004728 lpfc_els_flush_rscn(vport);
4729 lpfc_disc_flush_list(vport);
dea31012005-04-17 16:05:31 -05004730 }
4731 break;
James Smart2e0fef82007-06-17 19:56:36 -05004732
James Smart92d7f7b2007-06-17 19:56:38 -05004733 default:
James Smarte8b62012007-08-02 11:10:09 -04004734 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
James Smartd7c255b2008-08-24 21:50:00 -04004735 "0273 Unexpected discovery timeout, "
James Smarte8b62012007-08-02 11:10:09 -04004736 "vport State x%x\n", vport->port_state);
James Smart2e0fef82007-06-17 19:56:36 -05004737 break;
4738 }
4739
4740 switch (phba->link_state) {
4741 case LPFC_CLEAR_LA:
James Smart92d7f7b2007-06-17 19:56:38 -05004742 /* CLEAR LA timeout */
James Smarte8b62012007-08-02 11:10:09 -04004743 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
4744 "0228 CLEAR LA timeout\n");
James Smart2e0fef82007-06-17 19:56:36 -05004745 clrlaerr = 1;
4746 break;
4747
James Smart09372822008-01-11 01:52:54 -05004748 case LPFC_LINK_UP:
4749 lpfc_issue_clear_la(phba, vport);
4750 /* Drop thru */
James Smart2e0fef82007-06-17 19:56:36 -05004751 case LPFC_LINK_UNKNOWN:
4752 case LPFC_WARM_START:
4753 case LPFC_INIT_START:
4754 case LPFC_INIT_MBX_CMDS:
4755 case LPFC_LINK_DOWN:
James Smart2e0fef82007-06-17 19:56:36 -05004756 case LPFC_HBA_ERROR:
James Smarte8b62012007-08-02 11:10:09 -04004757 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
4758 "0230 Unexpected timeout, hba link "
4759 "state x%x\n", phba->link_state);
James Smart2e0fef82007-06-17 19:56:36 -05004760 clrlaerr = 1;
4761 break;
James Smart92d7f7b2007-06-17 19:56:38 -05004762
4763 case LPFC_HBA_READY:
4764 break;
dea31012005-04-17 16:05:31 -05004765 }
4766
4767 if (clrlaerr) {
James Smart2e0fef82007-06-17 19:56:36 -05004768 lpfc_disc_flush_list(vport);
James Smarta4bc3372006-12-02 13:34:16 -05004769 psli->ring[(psli->extra_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
dea31012005-04-17 16:05:31 -05004770 psli->ring[(psli->fcp_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
4771 psli->ring[(psli->next_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
James Smart2e0fef82007-06-17 19:56:36 -05004772 vport->port_state = LPFC_VPORT_READY;
dea31012005-04-17 16:05:31 -05004773 }
4774
4775 return;
4776}
4777
dea31012005-04-17 16:05:31 -05004778/*
4779 * This routine handles processing a NameServer REG_LOGIN mailbox
4780 * command upon completion. It is setup in the LPFC_MBOXQ
4781 * as the completion routine when the command is
4782 * handed off to the SLI layer.
4783 */
4784void
James Smart2e0fef82007-06-17 19:56:36 -05004785lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05004786{
James Smart04c68492009-05-22 14:52:52 -04004787 MAILBOX_t *mb = &pmb->u.mb;
James Smart2e0fef82007-06-17 19:56:36 -05004788 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
4789 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
4790 struct lpfc_vport *vport = pmb->vport;
dea31012005-04-17 16:05:31 -05004791
4792 pmb->context1 = NULL;
James Smartd439d282010-09-29 11:18:45 -04004793 pmb->context2 = NULL;
dea31012005-04-17 16:05:31 -05004794
dea31012005-04-17 16:05:31 -05004795 ndlp->nlp_rpi = mb->un.varWords[0];
James Smart21e9a0a2009-05-22 14:53:21 -04004796 ndlp->nlp_flag |= NLP_RPI_VALID;
dea31012005-04-17 16:05:31 -05004797 ndlp->nlp_type |= NLP_FABRIC;
James Smart2e0fef82007-06-17 19:56:36 -05004798 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
dea31012005-04-17 16:05:31 -05004799
James Smart2e0fef82007-06-17 19:56:36 -05004800 /*
4801 * Start issuing Fabric-Device Management Interface (FDMI) command to
4802 * 0xfffffa (FDMI well known port) or Delay issuing FDMI command if
4803 * fdmi-on=2 (supporting RPA/hostnmae)
dea31012005-04-17 16:05:31 -05004804 */
James Smart2e0fef82007-06-17 19:56:36 -05004805
James Smart3de2a652007-08-02 11:09:59 -04004806 if (vport->cfg_fdmi_on == 1)
James Smart2e0fef82007-06-17 19:56:36 -05004807 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA);
4808 else
4809 mod_timer(&vport->fc_fdmitmo, jiffies + HZ * 60);
dea31012005-04-17 16:05:31 -05004810
James Smartfa4066b2008-01-11 01:53:27 -05004811 /* decrement the node reference count held for this callback
4812 * function.
4813 */
James Smart329f9bc2007-04-25 09:53:01 -04004814 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05004815 lpfc_mbuf_free(phba, mp->virt, mp->phys);
4816 kfree(mp);
James Smart329f9bc2007-04-25 09:53:01 -04004817 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05004818
4819 return;
4820}
4821
James Smart685f0bf2007-04-25 09:53:08 -04004822static int
4823lpfc_filter_by_rpi(struct lpfc_nodelist *ndlp, void *param)
4824{
4825 uint16_t *rpi = param;
4826
4827 return ndlp->nlp_rpi == *rpi;
4828}
4829
4830static int
4831lpfc_filter_by_wwpn(struct lpfc_nodelist *ndlp, void *param)
4832{
4833 return memcmp(&ndlp->nlp_portname, param,
4834 sizeof(ndlp->nlp_portname)) == 0;
4835}
4836
Adrian Bunka6ababd2007-11-05 18:07:33 +01004837static struct lpfc_nodelist *
James Smart2e0fef82007-06-17 19:56:36 -05004838__lpfc_find_node(struct lpfc_vport *vport, node_filter filter, void *param)
dea31012005-04-17 16:05:31 -05004839{
James.Smart@Emulex.Com21568f52005-10-28 20:29:36 -04004840 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05004841
James Smart2e0fef82007-06-17 19:56:36 -05004842 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smart87af33f2007-10-27 13:37:43 -04004843 if (filter(ndlp, param))
James Smart685f0bf2007-04-25 09:53:08 -04004844 return ndlp;
4845 }
James.Smart@Emulex.Com21568f52005-10-28 20:29:36 -04004846 return NULL;
dea31012005-04-17 16:05:31 -05004847}
4848
James Smart685f0bf2007-04-25 09:53:08 -04004849/*
4850 * This routine looks up the ndlp lists for the given RPI. If rpi found it
James Smart2e0fef82007-06-17 19:56:36 -05004851 * returns the node list element pointer else return NULL.
James Smart685f0bf2007-04-25 09:53:08 -04004852 */
4853struct lpfc_nodelist *
James Smart2e0fef82007-06-17 19:56:36 -05004854__lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi)
James Smart685f0bf2007-04-25 09:53:08 -04004855{
James Smart2e0fef82007-06-17 19:56:36 -05004856 return __lpfc_find_node(vport, lpfc_filter_by_rpi, &rpi);
James Smart685f0bf2007-04-25 09:53:08 -04004857}
4858
James Smart488d1462006-03-07 15:02:37 -05004859/*
James Smart685f0bf2007-04-25 09:53:08 -04004860 * This routine looks up the ndlp lists for the given WWPN. If WWPN found it
James Smart2e0fef82007-06-17 19:56:36 -05004861 * returns the node element list pointer else return NULL.
James Smart488d1462006-03-07 15:02:37 -05004862 */
4863struct lpfc_nodelist *
James Smart2e0fef82007-06-17 19:56:36 -05004864lpfc_findnode_wwpn(struct lpfc_vport *vport, struct lpfc_name *wwpn)
James Smart488d1462006-03-07 15:02:37 -05004865{
James Smart2e0fef82007-06-17 19:56:36 -05004866 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart488d1462006-03-07 15:02:37 -05004867 struct lpfc_nodelist *ndlp;
James Smart488d1462006-03-07 15:02:37 -05004868
James Smart2e0fef82007-06-17 19:56:36 -05004869 spin_lock_irq(shost->host_lock);
4870 ndlp = __lpfc_find_node(vport, lpfc_filter_by_wwpn, wwpn);
4871 spin_unlock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05004872 return ndlp;
James Smart488d1462006-03-07 15:02:37 -05004873}
4874
dea31012005-04-17 16:05:31 -05004875void
James Smart2e0fef82007-06-17 19:56:36 -05004876lpfc_nlp_init(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
4877 uint32_t did)
dea31012005-04-17 16:05:31 -05004878{
4879 memset(ndlp, 0, sizeof (struct lpfc_nodelist));
James Smart109f6ed2008-12-04 22:39:08 -05004880
4881 lpfc_initialize_node(vport, ndlp, did);
James Smart685f0bf2007-04-25 09:53:08 -04004882 INIT_LIST_HEAD(&ndlp->nlp_listp);
James Smart858c9f62007-06-17 19:56:39 -05004883
4884 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
4885 "node init: did:x%x",
4886 ndlp->nlp_DID, 0, 0);
4887
dea31012005-04-17 16:05:31 -05004888 return;
4889}
James Smart329f9bc2007-04-25 09:53:01 -04004890
James Smart98c9ea52007-10-27 13:37:33 -04004891/* This routine releases all resources associated with a specifc NPort's ndlp
4892 * and mempool_free's the nodelist.
4893 */
James Smart311464e2007-08-02 11:10:37 -04004894static void
James Smart329f9bc2007-04-25 09:53:01 -04004895lpfc_nlp_release(struct kref *kref)
4896{
James Smarte47c9092008-02-08 18:49:26 -05004897 struct lpfc_hba *phba;
4898 unsigned long flags;
James Smart329f9bc2007-04-25 09:53:01 -04004899 struct lpfc_nodelist *ndlp = container_of(kref, struct lpfc_nodelist,
4900 kref);
James Smart858c9f62007-06-17 19:56:39 -05004901
4902 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
4903 "node release: did:x%x flg:x%x type:x%x",
4904 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
4905
James Smarte47c9092008-02-08 18:49:26 -05004906 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
4907 "0279 lpfc_nlp_release: ndlp:x%p "
4908 "usgmap:x%x refcnt:%d\n",
4909 (void *)ndlp, ndlp->nlp_usg_map,
4910 atomic_read(&ndlp->kref.refcount));
4911
4912 /* remove ndlp from action. */
James Smart2e0fef82007-06-17 19:56:36 -05004913 lpfc_nlp_remove(ndlp->vport, ndlp);
James Smarte47c9092008-02-08 18:49:26 -05004914
4915 /* clear the ndlp active flag for all release cases */
James Smarta257bf92009-04-06 18:48:10 -04004916 phba = ndlp->phba;
James Smarte47c9092008-02-08 18:49:26 -05004917 spin_lock_irqsave(&phba->ndlp_lock, flags);
4918 NLP_CLR_NODE_ACT(ndlp);
4919 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
4920
4921 /* free ndlp memory for final ndlp release */
James Smartea2151b2008-09-07 11:52:10 -04004922 if (NLP_CHK_FREE_REQ(ndlp)) {
4923 kfree(ndlp->lat_data);
James Smarta257bf92009-04-06 18:48:10 -04004924 mempool_free(ndlp, ndlp->phba->nlp_mem_pool);
James Smartea2151b2008-09-07 11:52:10 -04004925 }
James Smart329f9bc2007-04-25 09:53:01 -04004926}
4927
James Smart98c9ea52007-10-27 13:37:33 -04004928/* This routine bumps the reference count for a ndlp structure to ensure
4929 * that one discovery thread won't free a ndlp while another discovery thread
4930 * is using it.
4931 */
James Smart329f9bc2007-04-25 09:53:01 -04004932struct lpfc_nodelist *
4933lpfc_nlp_get(struct lpfc_nodelist *ndlp)
4934{
James Smarte47c9092008-02-08 18:49:26 -05004935 struct lpfc_hba *phba;
4936 unsigned long flags;
4937
James Smart98c9ea52007-10-27 13:37:33 -04004938 if (ndlp) {
4939 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
4940 "node get: did:x%x flg:x%x refcnt:x%x",
4941 ndlp->nlp_DID, ndlp->nlp_flag,
4942 atomic_read(&ndlp->kref.refcount));
James Smarte47c9092008-02-08 18:49:26 -05004943 /* The check of ndlp usage to prevent incrementing the
4944 * ndlp reference count that is in the process of being
4945 * released.
4946 */
James Smarta257bf92009-04-06 18:48:10 -04004947 phba = ndlp->phba;
James Smarte47c9092008-02-08 18:49:26 -05004948 spin_lock_irqsave(&phba->ndlp_lock, flags);
4949 if (!NLP_CHK_NODE_ACT(ndlp) || NLP_CHK_FREE_ACK(ndlp)) {
4950 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
4951 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
4952 "0276 lpfc_nlp_get: ndlp:x%p "
4953 "usgmap:x%x refcnt:%d\n",
4954 (void *)ndlp, ndlp->nlp_usg_map,
4955 atomic_read(&ndlp->kref.refcount));
4956 return NULL;
4957 } else
4958 kref_get(&ndlp->kref);
4959 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
James Smart98c9ea52007-10-27 13:37:33 -04004960 }
James Smart329f9bc2007-04-25 09:53:01 -04004961 return ndlp;
4962}
4963
James Smart98c9ea52007-10-27 13:37:33 -04004964/* This routine decrements the reference count for a ndlp structure. If the
James Smarte47c9092008-02-08 18:49:26 -05004965 * count goes to 0, this indicates the the associated nodelist should be
4966 * freed. Returning 1 indicates the ndlp resource has been released; on the
4967 * other hand, returning 0 indicates the ndlp resource has not been released
4968 * yet.
James Smart98c9ea52007-10-27 13:37:33 -04004969 */
James Smart329f9bc2007-04-25 09:53:01 -04004970int
4971lpfc_nlp_put(struct lpfc_nodelist *ndlp)
4972{
James Smarte47c9092008-02-08 18:49:26 -05004973 struct lpfc_hba *phba;
4974 unsigned long flags;
4975
4976 if (!ndlp)
4977 return 1;
4978
4979 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
4980 "node put: did:x%x flg:x%x refcnt:x%x",
4981 ndlp->nlp_DID, ndlp->nlp_flag,
4982 atomic_read(&ndlp->kref.refcount));
James Smarta257bf92009-04-06 18:48:10 -04004983 phba = ndlp->phba;
James Smarte47c9092008-02-08 18:49:26 -05004984 spin_lock_irqsave(&phba->ndlp_lock, flags);
4985 /* Check the ndlp memory free acknowledge flag to avoid the
4986 * possible race condition that kref_put got invoked again
4987 * after previous one has done ndlp memory free.
4988 */
4989 if (NLP_CHK_FREE_ACK(ndlp)) {
4990 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
4991 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
4992 "0274 lpfc_nlp_put: ndlp:x%p "
4993 "usgmap:x%x refcnt:%d\n",
4994 (void *)ndlp, ndlp->nlp_usg_map,
4995 atomic_read(&ndlp->kref.refcount));
4996 return 1;
James Smart98c9ea52007-10-27 13:37:33 -04004997 }
James Smarte47c9092008-02-08 18:49:26 -05004998 /* Check the ndlp inactivate log flag to avoid the possible
4999 * race condition that kref_put got invoked again after ndlp
5000 * is already in inactivating state.
5001 */
5002 if (NLP_CHK_IACT_REQ(ndlp)) {
5003 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
5004 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
5005 "0275 lpfc_nlp_put: ndlp:x%p "
5006 "usgmap:x%x refcnt:%d\n",
5007 (void *)ndlp, ndlp->nlp_usg_map,
5008 atomic_read(&ndlp->kref.refcount));
5009 return 1;
5010 }
5011 /* For last put, mark the ndlp usage flags to make sure no
5012 * other kref_get and kref_put on the same ndlp shall get
5013 * in between the process when the final kref_put has been
5014 * invoked on this ndlp.
5015 */
5016 if (atomic_read(&ndlp->kref.refcount) == 1) {
5017 /* Indicate ndlp is put to inactive state. */
5018 NLP_SET_IACT_REQ(ndlp);
5019 /* Acknowledge ndlp memory free has been seen. */
5020 if (NLP_CHK_FREE_REQ(ndlp))
5021 NLP_SET_FREE_ACK(ndlp);
5022 }
5023 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
5024 /* Note, the kref_put returns 1 when decrementing a reference
5025 * count that was 1, it invokes the release callback function,
5026 * but it still left the reference count as 1 (not actually
5027 * performs the last decrementation). Otherwise, it actually
5028 * decrements the reference count and returns 0.
5029 */
5030 return kref_put(&ndlp->kref, lpfc_nlp_release);
James Smart329f9bc2007-04-25 09:53:01 -04005031}
James Smart98c9ea52007-10-27 13:37:33 -04005032
5033/* This routine free's the specified nodelist if it is not in use
James Smarte47c9092008-02-08 18:49:26 -05005034 * by any other discovery thread. This routine returns 1 if the
5035 * ndlp has been freed. A return value of 0 indicates the ndlp is
5036 * not yet been released.
James Smart98c9ea52007-10-27 13:37:33 -04005037 */
5038int
5039lpfc_nlp_not_used(struct lpfc_nodelist *ndlp)
5040{
5041 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
5042 "node not used: did:x%x flg:x%x refcnt:x%x",
5043 ndlp->nlp_DID, ndlp->nlp_flag,
5044 atomic_read(&ndlp->kref.refcount));
James Smarte47c9092008-02-08 18:49:26 -05005045 if (atomic_read(&ndlp->kref.refcount) == 1)
5046 if (lpfc_nlp_put(ndlp))
5047 return 1;
James Smart98c9ea52007-10-27 13:37:33 -04005048 return 0;
5049}
James Smart6fb120a2009-05-22 14:52:59 -04005050
5051/**
5052 * lpfc_fcf_inuse - Check if FCF can be unregistered.
5053 * @phba: Pointer to hba context object.
5054 *
5055 * This function iterate through all FC nodes associated
5056 * will all vports to check if there is any node with
5057 * fc_rports associated with it. If there is an fc_rport
5058 * associated with the node, then the node is either in
5059 * discovered state or its devloss_timer is pending.
5060 */
5061static int
5062lpfc_fcf_inuse(struct lpfc_hba *phba)
5063{
5064 struct lpfc_vport **vports;
5065 int i, ret = 0;
5066 struct lpfc_nodelist *ndlp;
5067 struct Scsi_Host *shost;
5068
5069 vports = lpfc_create_vport_work_array(phba);
5070
5071 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
5072 shost = lpfc_shost_from_vport(vports[i]);
5073 spin_lock_irq(shost->host_lock);
5074 list_for_each_entry(ndlp, &vports[i]->fc_nodes, nlp_listp) {
5075 if (NLP_CHK_NODE_ACT(ndlp) && ndlp->rport &&
5076 (ndlp->rport->roles & FC_RPORT_ROLE_FCP_TARGET)) {
5077 ret = 1;
5078 spin_unlock_irq(shost->host_lock);
5079 goto out;
James Smart891478a2009-11-18 15:40:23 -05005080 } else {
5081 lpfc_printf_log(phba, KERN_INFO, LOG_ELS,
5082 "2624 RPI %x DID %x flg %x still "
5083 "logged in\n",
5084 ndlp->nlp_rpi, ndlp->nlp_DID,
5085 ndlp->nlp_flag);
5086 if (ndlp->nlp_flag & NLP_RPI_VALID)
5087 ret = 1;
James Smart6fb120a2009-05-22 14:52:59 -04005088 }
5089 }
5090 spin_unlock_irq(shost->host_lock);
5091 }
5092out:
5093 lpfc_destroy_vport_work_array(phba, vports);
5094 return ret;
5095}
5096
5097/**
5098 * lpfc_unregister_vfi_cmpl - Completion handler for unreg vfi.
5099 * @phba: Pointer to hba context object.
5100 * @mboxq: Pointer to mailbox object.
5101 *
5102 * This function frees memory associated with the mailbox command.
5103 */
5104static void
5105lpfc_unregister_vfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
5106{
5107 struct lpfc_vport *vport = mboxq->vport;
James Smart38b92ef2010-08-04 16:11:39 -04005108 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart6fb120a2009-05-22 14:52:59 -04005109
5110 if (mboxq->u.mb.mbxStatus) {
5111 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
5112 "2555 UNREG_VFI mbxStatus error x%x "
5113 "HBA state x%x\n",
5114 mboxq->u.mb.mbxStatus, vport->port_state);
5115 }
James Smart38b92ef2010-08-04 16:11:39 -04005116 spin_lock_irq(shost->host_lock);
5117 phba->pport->fc_flag &= ~FC_VFI_REGISTERED;
5118 spin_unlock_irq(shost->host_lock);
James Smart6fb120a2009-05-22 14:52:59 -04005119 mempool_free(mboxq, phba->mbox_mem_pool);
5120 return;
5121}
5122
5123/**
5124 * lpfc_unregister_fcfi_cmpl - Completion handler for unreg fcfi.
5125 * @phba: Pointer to hba context object.
5126 * @mboxq: Pointer to mailbox object.
5127 *
5128 * This function frees memory associated with the mailbox command.
5129 */
5130static void
5131lpfc_unregister_fcfi_cmpl(struct lpfc_hba *phba, LPFC_MBOXQ_t *mboxq)
5132{
5133 struct lpfc_vport *vport = mboxq->vport;
5134
5135 if (mboxq->u.mb.mbxStatus) {
5136 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
5137 "2550 UNREG_FCFI mbxStatus error x%x "
5138 "HBA state x%x\n",
5139 mboxq->u.mb.mbxStatus, vport->port_state);
5140 }
5141 mempool_free(mboxq, phba->mbox_mem_pool);
5142 return;
5143}
5144
5145/**
James Smartecfd03c2010-02-12 14:41:27 -05005146 * lpfc_unregister_fcf_prep - Unregister fcf record preparation
James Smart6fb120a2009-05-22 14:52:59 -04005147 * @phba: Pointer to hba context object.
5148 *
James Smartecfd03c2010-02-12 14:41:27 -05005149 * This function prepare the HBA for unregistering the currently registered
5150 * FCF from the HBA. It performs unregistering, in order, RPIs, VPIs, and
5151 * VFIs.
James Smart6fb120a2009-05-22 14:52:59 -04005152 */
James Smartecfd03c2010-02-12 14:41:27 -05005153int
5154lpfc_unregister_fcf_prep(struct lpfc_hba *phba)
James Smart6fb120a2009-05-22 14:52:59 -04005155{
5156 LPFC_MBOXQ_t *mbox;
James Smart6fb120a2009-05-22 14:52:59 -04005157 struct lpfc_vport **vports;
James Smart695a8142010-01-26 23:08:03 -05005158 struct lpfc_nodelist *ndlp;
James Smart72100cc2010-02-12 14:43:01 -05005159 struct Scsi_Host *shost;
James Smartecfd03c2010-02-12 14:41:27 -05005160 int i, rc;
James Smart6fb120a2009-05-22 14:52:59 -04005161
James Smartecfd03c2010-02-12 14:41:27 -05005162 /* Unregister RPIs */
James Smart6fb120a2009-05-22 14:52:59 -04005163 if (lpfc_fcf_inuse(phba))
James Smartecfd03c2010-02-12 14:41:27 -05005164 lpfc_unreg_hba_rpis(phba);
James Smart6fb120a2009-05-22 14:52:59 -04005165
James Smart4d9ab992009-10-02 15:16:39 -04005166 /* At this point, all discovery is aborted */
5167 phba->pport->port_state = LPFC_VPORT_UNKNOWN;
James Smart6fb120a2009-05-22 14:52:59 -04005168
5169 /* Unregister VPIs */
5170 vports = lpfc_create_vport_work_array(phba);
James Smartecfd03c2010-02-12 14:41:27 -05005171 if (vports && (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED))
James Smart6fb120a2009-05-22 14:52:59 -04005172 for (i = 0; i <= phba->max_vports && vports[i] != NULL; i++) {
James Smart695a8142010-01-26 23:08:03 -05005173 /* Stop FLOGI/FDISC retries */
5174 ndlp = lpfc_findnode_did(vports[i], Fabric_DID);
5175 if (ndlp)
5176 lpfc_cancel_retry_delay_tmo(vports[i], ndlp);
James Smart78730cf2010-04-06 15:06:30 -04005177 lpfc_cleanup_pending_mbox(vports[i]);
James Smart6fb120a2009-05-22 14:52:59 -04005178 lpfc_mbx_unreg_vpi(vports[i]);
James Smart72100cc2010-02-12 14:43:01 -05005179 shost = lpfc_shost_from_vport(vports[i]);
5180 spin_lock_irq(shost->host_lock);
James Smart891478a2009-11-18 15:40:23 -05005181 vports[i]->fc_flag |= FC_VPORT_NEEDS_INIT_VPI;
James Smartc8685952009-11-18 15:39:16 -05005182 vports[i]->vpi_state &= ~LPFC_VPI_REGISTERED;
James Smart72100cc2010-02-12 14:43:01 -05005183 spin_unlock_irq(shost->host_lock);
James Smart6fb120a2009-05-22 14:52:59 -04005184 }
5185 lpfc_destroy_vport_work_array(phba, vports);
5186
James Smart695a8142010-01-26 23:08:03 -05005187 /* Cleanup any outstanding ELS commands */
5188 lpfc_els_flush_all_cmd(phba);
5189
James Smart6fb120a2009-05-22 14:52:59 -04005190 /* Unregister VFI */
5191 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5192 if (!mbox) {
5193 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
James Smartecfd03c2010-02-12 14:41:27 -05005194 "2556 UNREG_VFI mbox allocation failed"
5195 "HBA state x%x\n", phba->pport->port_state);
5196 return -ENOMEM;
James Smart6fb120a2009-05-22 14:52:59 -04005197 }
5198
James Smart6669f9b2009-10-02 15:16:45 -04005199 lpfc_unreg_vfi(mbox, phba->pport);
James Smart6fb120a2009-05-22 14:52:59 -04005200 mbox->vport = phba->pport;
5201 mbox->mbox_cmpl = lpfc_unregister_vfi_cmpl;
5202
5203 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5204 if (rc == MBX_NOT_FINISHED) {
5205 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
James Smartecfd03c2010-02-12 14:41:27 -05005206 "2557 UNREG_VFI issue mbox failed rc x%x "
5207 "HBA state x%x\n",
5208 rc, phba->pport->port_state);
James Smart6fb120a2009-05-22 14:52:59 -04005209 mempool_free(mbox, phba->mbox_mem_pool);
James Smartecfd03c2010-02-12 14:41:27 -05005210 return -EIO;
James Smart6fb120a2009-05-22 14:52:59 -04005211 }
5212
James Smart72100cc2010-02-12 14:43:01 -05005213 shost = lpfc_shost_from_vport(phba->pport);
5214 spin_lock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05005215 phba->pport->fc_flag &= ~FC_VFI_REGISTERED;
James Smart72100cc2010-02-12 14:43:01 -05005216 spin_unlock_irq(shost->host_lock);
James Smart695a8142010-01-26 23:08:03 -05005217
James Smartecfd03c2010-02-12 14:41:27 -05005218 return 0;
5219}
5220
5221/**
5222 * lpfc_sli4_unregister_fcf - Unregister currently registered FCF record
5223 * @phba: Pointer to hba context object.
5224 *
5225 * This function issues synchronous unregister FCF mailbox command to HBA to
5226 * unregister the currently registered FCF record. The driver does not reset
5227 * the driver FCF usage state flags.
5228 *
5229 * Return 0 if successfully issued, none-zero otherwise.
5230 */
5231int
5232lpfc_sli4_unregister_fcf(struct lpfc_hba *phba)
5233{
5234 LPFC_MBOXQ_t *mbox;
5235 int rc;
5236
James Smart6fb120a2009-05-22 14:52:59 -04005237 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
5238 if (!mbox) {
5239 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
James Smartecfd03c2010-02-12 14:41:27 -05005240 "2551 UNREG_FCFI mbox allocation failed"
5241 "HBA state x%x\n", phba->pport->port_state);
5242 return -ENOMEM;
James Smart6fb120a2009-05-22 14:52:59 -04005243 }
James Smart6fb120a2009-05-22 14:52:59 -04005244 lpfc_unreg_fcfi(mbox, phba->fcf.fcfi);
5245 mbox->vport = phba->pport;
5246 mbox->mbox_cmpl = lpfc_unregister_fcfi_cmpl;
5247 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
5248
5249 if (rc == MBX_NOT_FINISHED) {
James Smartecfd03c2010-02-12 14:41:27 -05005250 lpfc_printf_log(phba, KERN_ERR, LOG_SLI,
5251 "2552 Unregister FCFI command failed rc x%x "
5252 "HBA state x%x\n",
5253 rc, phba->pport->port_state);
5254 return -EINVAL;
5255 }
5256 return 0;
5257}
5258
5259/**
5260 * lpfc_unregister_fcf_rescan - Unregister currently registered fcf and rescan
5261 * @phba: Pointer to hba context object.
5262 *
5263 * This function unregisters the currently reigstered FCF. This function
5264 * also tries to find another FCF for discovery by rescan the HBA FCF table.
5265 */
5266void
5267lpfc_unregister_fcf_rescan(struct lpfc_hba *phba)
5268{
5269 int rc;
5270
5271 /* Preparation for unregistering fcf */
5272 rc = lpfc_unregister_fcf_prep(phba);
5273 if (rc) {
5274 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
5275 "2748 Failed to prepare for unregistering "
5276 "HBA's FCF record: rc=%d\n", rc);
James Smart6fb120a2009-05-22 14:52:59 -04005277 return;
5278 }
5279
James Smartecfd03c2010-02-12 14:41:27 -05005280 /* Now, unregister FCF record and reset HBA FCF state */
5281 rc = lpfc_sli4_unregister_fcf(phba);
5282 if (rc)
5283 return;
5284 /* Reset HBA FCF states after successful unregister FCF */
5285 phba->fcf.fcf_flag = 0;
James Smartfc2b9892010-02-26 14:15:29 -05005286 phba->fcf.current_rec.flag = 0;
James Smart6fb120a2009-05-22 14:52:59 -04005287
5288 /*
5289 * If driver is not unloading, check if there is any other
5290 * FCF record that can be used for discovery.
5291 */
5292 if ((phba->pport->load_flag & FC_UNLOADING) ||
James Smartecfd03c2010-02-12 14:41:27 -05005293 (phba->link_state < LPFC_LINK_UP))
James Smart6fb120a2009-05-22 14:52:59 -04005294 return;
5295
James Smart0c9ab6f2010-02-26 14:15:57 -05005296 /* This is considered as the initial FCF discovery scan */
5297 spin_lock_irq(&phba->hbalock);
5298 phba->fcf.fcf_flag |= FCF_INIT_DISC;
5299 spin_unlock_irq(&phba->hbalock);
James Smart38b92ef2010-08-04 16:11:39 -04005300
5301 /* Reset FCF roundrobin bmask for new discovery */
5302 memset(phba->fcf.fcf_rr_bmask, 0, sizeof(*phba->fcf.fcf_rr_bmask));
5303
James Smart0c9ab6f2010-02-26 14:15:57 -05005304 rc = lpfc_sli4_fcf_scan_read_fcf_rec(phba, LPFC_FCOE_FCF_GET_FIRST);
James Smart6fb120a2009-05-22 14:52:59 -04005305
James Smart0c9ab6f2010-02-26 14:15:57 -05005306 if (rc) {
5307 spin_lock_irq(&phba->hbalock);
5308 phba->fcf.fcf_flag &= ~FCF_INIT_DISC;
5309 spin_unlock_irq(&phba->hbalock);
James Smart6fb120a2009-05-22 14:52:59 -04005310 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY|LOG_MBOX,
James Smartecfd03c2010-02-12 14:41:27 -05005311 "2553 lpfc_unregister_unused_fcf failed "
5312 "to read FCF record HBA state x%x\n",
5313 phba->pport->port_state);
James Smart0c9ab6f2010-02-26 14:15:57 -05005314 }
James Smartecfd03c2010-02-12 14:41:27 -05005315}
5316
5317/**
5318 * lpfc_unregister_fcf - Unregister the currently registered fcf record
5319 * @phba: Pointer to hba context object.
5320 *
5321 * This function just unregisters the currently reigstered FCF. It does not
5322 * try to find another FCF for discovery.
5323 */
5324void
5325lpfc_unregister_fcf(struct lpfc_hba *phba)
5326{
5327 int rc;
5328
5329 /* Preparation for unregistering fcf */
5330 rc = lpfc_unregister_fcf_prep(phba);
5331 if (rc) {
5332 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
5333 "2749 Failed to prepare for unregistering "
5334 "HBA's FCF record: rc=%d\n", rc);
5335 return;
5336 }
5337
5338 /* Now, unregister FCF record and reset HBA FCF state */
5339 rc = lpfc_sli4_unregister_fcf(phba);
5340 if (rc)
5341 return;
5342 /* Set proper HBA FCF states after successful unregister FCF */
5343 spin_lock_irq(&phba->hbalock);
5344 phba->fcf.fcf_flag &= ~FCF_REGISTERED;
5345 spin_unlock_irq(&phba->hbalock);
5346}
5347
5348/**
5349 * lpfc_unregister_unused_fcf - Unregister FCF if all devices are disconnected.
5350 * @phba: Pointer to hba context object.
5351 *
5352 * This function check if there are any connected remote port for the FCF and
5353 * if all the devices are disconnected, this function unregister FCFI.
5354 * This function also tries to use another FCF for discovery.
5355 */
5356void
5357lpfc_unregister_unused_fcf(struct lpfc_hba *phba)
5358{
5359 /*
James Smart3804dc82010-07-14 15:31:37 -04005360 * If HBA is not running in FIP mode, if HBA does not support
5361 * FCoE, if FCF discovery is ongoing, or if FCF has not been
5362 * registered, do nothing.
James Smartecfd03c2010-02-12 14:41:27 -05005363 */
5364 spin_lock_irq(&phba->hbalock);
5365 if (!(phba->hba_flag & HBA_FCOE_SUPPORT) ||
5366 !(phba->fcf.fcf_flag & FCF_REGISTERED) ||
James Smartdbb6b3a2010-06-08 18:31:37 -04005367 !(phba->hba_flag & HBA_FIP_SUPPORT) ||
James Smart3804dc82010-07-14 15:31:37 -04005368 (phba->fcf.fcf_flag & FCF_DISCOVERY) ||
James Smartdbb6b3a2010-06-08 18:31:37 -04005369 (phba->pport->port_state == LPFC_FLOGI)) {
James Smartecfd03c2010-02-12 14:41:27 -05005370 spin_unlock_irq(&phba->hbalock);
5371 return;
5372 }
5373 spin_unlock_irq(&phba->hbalock);
5374
5375 if (lpfc_fcf_inuse(phba))
5376 return;
5377
5378 lpfc_unregister_fcf_rescan(phba);
James Smart6fb120a2009-05-22 14:52:59 -04005379}
5380
5381/**
5382 * lpfc_read_fcf_conn_tbl - Create driver FCF connection table.
5383 * @phba: Pointer to hba context object.
5384 * @buff: Buffer containing the FCF connection table as in the config
5385 * region.
5386 * This function create driver data structure for the FCF connection
5387 * record table read from config region 23.
5388 */
5389static void
5390lpfc_read_fcf_conn_tbl(struct lpfc_hba *phba,
5391 uint8_t *buff)
5392{
5393 struct lpfc_fcf_conn_entry *conn_entry, *next_conn_entry;
5394 struct lpfc_fcf_conn_hdr *conn_hdr;
5395 struct lpfc_fcf_conn_rec *conn_rec;
5396 uint32_t record_count;
5397 int i;
5398
5399 /* Free the current connect table */
5400 list_for_each_entry_safe(conn_entry, next_conn_entry,
James Smart4d9ab992009-10-02 15:16:39 -04005401 &phba->fcf_conn_rec_list, list) {
5402 list_del_init(&conn_entry->list);
James Smart6fb120a2009-05-22 14:52:59 -04005403 kfree(conn_entry);
James Smart4d9ab992009-10-02 15:16:39 -04005404 }
James Smart6fb120a2009-05-22 14:52:59 -04005405
5406 conn_hdr = (struct lpfc_fcf_conn_hdr *) buff;
5407 record_count = conn_hdr->length * sizeof(uint32_t)/
5408 sizeof(struct lpfc_fcf_conn_rec);
5409
5410 conn_rec = (struct lpfc_fcf_conn_rec *)
5411 (buff + sizeof(struct lpfc_fcf_conn_hdr));
5412
5413 for (i = 0; i < record_count; i++) {
5414 if (!(conn_rec[i].flags & FCFCNCT_VALID))
5415 continue;
5416 conn_entry = kzalloc(sizeof(struct lpfc_fcf_conn_entry),
5417 GFP_KERNEL);
5418 if (!conn_entry) {
5419 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5420 "2566 Failed to allocate connection"
5421 " table entry\n");
5422 return;
5423 }
5424
5425 memcpy(&conn_entry->conn_rec, &conn_rec[i],
5426 sizeof(struct lpfc_fcf_conn_rec));
5427 conn_entry->conn_rec.vlan_tag =
5428 le16_to_cpu(conn_entry->conn_rec.vlan_tag) & 0xFFF;
5429 conn_entry->conn_rec.flags =
5430 le16_to_cpu(conn_entry->conn_rec.flags);
5431 list_add_tail(&conn_entry->list,
5432 &phba->fcf_conn_rec_list);
5433 }
5434}
5435
5436/**
5437 * lpfc_read_fcoe_param - Read FCoe parameters from conf region..
5438 * @phba: Pointer to hba context object.
5439 * @buff: Buffer containing the FCoE parameter data structure.
5440 *
5441 * This function update driver data structure with config
5442 * parameters read from config region 23.
5443 */
5444static void
5445lpfc_read_fcoe_param(struct lpfc_hba *phba,
5446 uint8_t *buff)
5447{
5448 struct lpfc_fip_param_hdr *fcoe_param_hdr;
5449 struct lpfc_fcoe_params *fcoe_param;
5450
5451 fcoe_param_hdr = (struct lpfc_fip_param_hdr *)
5452 buff;
5453 fcoe_param = (struct lpfc_fcoe_params *)
James Smart32b97932009-07-19 10:01:21 -04005454 (buff + sizeof(struct lpfc_fip_param_hdr));
James Smart6fb120a2009-05-22 14:52:59 -04005455
5456 if ((fcoe_param_hdr->parm_version != FIPP_VERSION) ||
5457 (fcoe_param_hdr->length != FCOE_PARAM_LENGTH))
5458 return;
5459
James Smart6fb120a2009-05-22 14:52:59 -04005460 if (fcoe_param_hdr->parm_flags & FIPP_VLAN_VALID) {
5461 phba->valid_vlan = 1;
5462 phba->vlan_id = le16_to_cpu(fcoe_param->vlan_tag) &
5463 0xFFF;
5464 }
5465
5466 phba->fc_map[0] = fcoe_param->fc_map[0];
5467 phba->fc_map[1] = fcoe_param->fc_map[1];
5468 phba->fc_map[2] = fcoe_param->fc_map[2];
5469 return;
5470}
5471
5472/**
5473 * lpfc_get_rec_conf23 - Get a record type in config region data.
5474 * @buff: Buffer containing config region 23 data.
5475 * @size: Size of the data buffer.
5476 * @rec_type: Record type to be searched.
5477 *
5478 * This function searches config region data to find the begining
5479 * of the record specified by record_type. If record found, this
5480 * function return pointer to the record else return NULL.
5481 */
5482static uint8_t *
5483lpfc_get_rec_conf23(uint8_t *buff, uint32_t size, uint8_t rec_type)
5484{
5485 uint32_t offset = 0, rec_length;
5486
5487 if ((buff[0] == LPFC_REGION23_LAST_REC) ||
5488 (size < sizeof(uint32_t)))
5489 return NULL;
5490
5491 rec_length = buff[offset + 1];
5492
5493 /*
5494 * One TLV record has one word header and number of data words
5495 * specified in the rec_length field of the record header.
5496 */
5497 while ((offset + rec_length * sizeof(uint32_t) + sizeof(uint32_t))
5498 <= size) {
5499 if (buff[offset] == rec_type)
5500 return &buff[offset];
5501
5502 if (buff[offset] == LPFC_REGION23_LAST_REC)
5503 return NULL;
5504
5505 offset += rec_length * sizeof(uint32_t) + sizeof(uint32_t);
5506 rec_length = buff[offset + 1];
5507 }
5508 return NULL;
5509}
5510
5511/**
5512 * lpfc_parse_fcoe_conf - Parse FCoE config data read from config region 23.
5513 * @phba: Pointer to lpfc_hba data structure.
5514 * @buff: Buffer containing config region 23 data.
5515 * @size: Size of the data buffer.
5516 *
Stefan Weileef35c22010-08-06 21:11:15 +02005517 * This function parses the FCoE config parameters in config region 23 and
James Smart6fb120a2009-05-22 14:52:59 -04005518 * populate driver data structure with the parameters.
5519 */
5520void
5521lpfc_parse_fcoe_conf(struct lpfc_hba *phba,
5522 uint8_t *buff,
5523 uint32_t size)
5524{
5525 uint32_t offset = 0, rec_length;
5526 uint8_t *rec_ptr;
5527
5528 /*
5529 * If data size is less than 2 words signature and version cannot be
5530 * verified.
5531 */
5532 if (size < 2*sizeof(uint32_t))
5533 return;
5534
5535 /* Check the region signature first */
5536 if (memcmp(buff, LPFC_REGION23_SIGNATURE, 4)) {
5537 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5538 "2567 Config region 23 has bad signature\n");
5539 return;
5540 }
5541
5542 offset += 4;
5543
5544 /* Check the data structure version */
5545 if (buff[offset] != LPFC_REGION23_VERSION) {
5546 lpfc_printf_log(phba, KERN_ERR, LOG_INIT,
5547 "2568 Config region 23 has bad version\n");
5548 return;
5549 }
5550 offset += 4;
5551
5552 rec_length = buff[offset + 1];
5553
5554 /* Read FCoE param record */
5555 rec_ptr = lpfc_get_rec_conf23(&buff[offset],
5556 size - offset, FCOE_PARAM_TYPE);
5557 if (rec_ptr)
5558 lpfc_read_fcoe_param(phba, rec_ptr);
5559
5560 /* Read FCF connection table */
5561 rec_ptr = lpfc_get_rec_conf23(&buff[offset],
5562 size - offset, FCOE_CONN_TBL_TYPE);
5563 if (rec_ptr)
5564 lpfc_read_fcf_conn_tbl(phba, rec_ptr);
5565
5566}