blob: ba4873c9e2c36f71085140c5b9938f1876af02f2 [file] [log] [blame]
dea31012005-04-17 16:05:31 -05001/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04003 * Fibre Channel Host Bus Adapters. *
James Smarte47c9092008-02-08 18:49:26 -05004 * Copyright (C) 2004-2008 Emulex. All rights reserved. *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04005 * EMULEX and SLI are trademarks of Emulex. *
dea31012005-04-17 16:05:31 -05006 * www.emulex.com *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -04007 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea31012005-04-17 16:05:31 -05008 * *
9 * This program is free software; you can redistribute it and/or *
James.Smart@Emulex.Comc44ce172005-06-25 10:34:39 -040010 * modify it under the terms of version 2 of the GNU General *
11 * Public License as published by the Free Software Foundation. *
12 * This program is distributed in the hope that it will be useful. *
13 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND *
14 * WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, *
15 * FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT, ARE *
16 * DISCLAIMED, EXCEPT TO THE EXTENT THAT SUCH DISCLAIMERS ARE HELD *
17 * TO BE LEGALLY INVALID. See the GNU General Public License for *
18 * more details, a copy of which can be found in the file COPYING *
19 * included with this package. *
dea31012005-04-17 16:05:31 -050020 *******************************************************************/
21
dea31012005-04-17 16:05:31 -050022#include <linux/blkdev.h>
23#include <linux/pci.h>
24#include <linux/kthread.h>
25#include <linux/interrupt.h>
26
James.Smart@Emulex.Com91886522005-08-10 15:03:09 -040027#include <scsi/scsi.h>
dea31012005-04-17 16:05:31 -050028#include <scsi/scsi_device.h>
29#include <scsi/scsi_host.h>
30#include <scsi/scsi_transport_fc.h>
31
32#include "lpfc_hw.h"
33#include "lpfc_disc.h"
34#include "lpfc_sli.h"
35#include "lpfc_scsi.h"
36#include "lpfc.h"
37#include "lpfc_logmsg.h"
38#include "lpfc_crtn.h"
James Smart92d7f7b2007-06-17 19:56:38 -050039#include "lpfc_vport.h"
James Smart858c9f62007-06-17 19:56:39 -050040#include "lpfc_debugfs.h"
dea31012005-04-17 16:05:31 -050041
42/* AlpaArray for assignment of scsid for scan-down and bind_method */
43static uint8_t lpfcAlpaArray[] = {
44 0xEF, 0xE8, 0xE4, 0xE2, 0xE1, 0xE0, 0xDC, 0xDA, 0xD9, 0xD6,
45 0xD5, 0xD4, 0xD3, 0xD2, 0xD1, 0xCE, 0xCD, 0xCC, 0xCB, 0xCA,
46 0xC9, 0xC7, 0xC6, 0xC5, 0xC3, 0xBC, 0xBA, 0xB9, 0xB6, 0xB5,
47 0xB4, 0xB3, 0xB2, 0xB1, 0xAE, 0xAD, 0xAC, 0xAB, 0xAA, 0xA9,
48 0xA7, 0xA6, 0xA5, 0xA3, 0x9F, 0x9E, 0x9D, 0x9B, 0x98, 0x97,
49 0x90, 0x8F, 0x88, 0x84, 0x82, 0x81, 0x80, 0x7C, 0x7A, 0x79,
50 0x76, 0x75, 0x74, 0x73, 0x72, 0x71, 0x6E, 0x6D, 0x6C, 0x6B,
51 0x6A, 0x69, 0x67, 0x66, 0x65, 0x63, 0x5C, 0x5A, 0x59, 0x56,
52 0x55, 0x54, 0x53, 0x52, 0x51, 0x4E, 0x4D, 0x4C, 0x4B, 0x4A,
53 0x49, 0x47, 0x46, 0x45, 0x43, 0x3C, 0x3A, 0x39, 0x36, 0x35,
54 0x34, 0x33, 0x32, 0x31, 0x2E, 0x2D, 0x2C, 0x2B, 0x2A, 0x29,
55 0x27, 0x26, 0x25, 0x23, 0x1F, 0x1E, 0x1D, 0x1B, 0x18, 0x17,
56 0x10, 0x0F, 0x08, 0x04, 0x02, 0x01
57};
58
James Smart2e0fef82007-06-17 19:56:36 -050059static void lpfc_disc_timeout_handler(struct lpfc_vport *);
Adrian Bunka6ababd2007-11-05 18:07:33 +010060static void lpfc_disc_flush_list(struct lpfc_vport *vport);
dea31012005-04-17 16:05:31 -050061
James Smartc01f3202006-08-18 17:47:08 -040062void
63lpfc_terminate_rport_io(struct fc_rport *rport)
dea31012005-04-17 16:05:31 -050064{
James Smartc01f3202006-08-18 17:47:08 -040065 struct lpfc_rport_data *rdata;
66 struct lpfc_nodelist * ndlp;
67 struct lpfc_hba *phba;
dea31012005-04-17 16:05:31 -050068
James Smartc01f3202006-08-18 17:47:08 -040069 rdata = rport->dd_data;
70 ndlp = rdata->pnode;
71
James Smart58da1ff2008-04-07 10:15:56 -040072 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp)) {
James Smartc01f3202006-08-18 17:47:08 -040073 if (rport->roles & FC_RPORT_ROLE_FCP_TARGET)
74 printk(KERN_ERR "Cannot find remote node"
75 " to terminate I/O Data x%x\n",
76 rport->port_id);
dea31012005-04-17 16:05:31 -050077 return;
78 }
79
James Smart2e0fef82007-06-17 19:56:36 -050080 phba = ndlp->vport->phba;
James Smart1a169682006-03-07 15:04:06 -050081
James Smart858c9f62007-06-17 19:56:39 -050082 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_RPORT,
83 "rport terminate: sid:x%x did:x%x flg:x%x",
84 ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag);
85
James Smartc01f3202006-08-18 17:47:08 -040086 if (ndlp->nlp_sid != NLP_NO_SID) {
James Smart51ef4c22007-08-02 11:10:31 -040087 lpfc_sli_abort_iocb(ndlp->vport,
88 &phba->sli.ring[phba->sli.fcp_ring],
89 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
James Smartc01f3202006-08-18 17:47:08 -040090 }
James Smartc01f3202006-08-18 17:47:08 -040091
James Smart51ef4c22007-08-02 11:10:31 -040092 /*
93 * A device is normally blocked for rediscovery and unblocked when
94 * devloss timeout happens. In case a vport is removed or driver
95 * unloaded before devloss timeout happens, we need to unblock here.
96 */
97 scsi_target_unblock(&rport->dev);
James Smartc01f3202006-08-18 17:47:08 -040098 return;
99}
100
101/*
102 * This function will be called when dev_loss_tmo fire.
103 */
104void
105lpfc_dev_loss_tmo_callbk(struct fc_rport *rport)
106{
107 struct lpfc_rport_data *rdata;
108 struct lpfc_nodelist * ndlp;
James Smart2e0fef82007-06-17 19:56:36 -0500109 struct lpfc_vport *vport;
James Smart858c9f62007-06-17 19:56:39 -0500110 struct lpfc_hba *phba;
James Smart858c9f62007-06-17 19:56:39 -0500111 struct lpfc_work_evt *evtp;
James Smarta8adb832007-10-27 13:37:53 -0400112 int put_node;
113 int put_rport;
James Smartc01f3202006-08-18 17:47:08 -0400114
115 rdata = rport->dd_data;
116 ndlp = rdata->pnode;
James Smart58da1ff2008-04-07 10:15:56 -0400117 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
James Smartc01f3202006-08-18 17:47:08 -0400118 return;
James Smartc01f3202006-08-18 17:47:08 -0400119
James Smart858c9f62007-06-17 19:56:39 -0500120 vport = ndlp->vport;
121 phba = vport->phba;
122
123 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
124 "rport devlosscb: sid:x%x did:x%x flg:x%x",
125 ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag);
126
James Smarta8adb832007-10-27 13:37:53 -0400127 /* Don't defer this if we are in the process of deleting the vport
128 * or unloading the driver. The unload will cleanup the node
129 * appropriately we just need to cleanup the ndlp rport info here.
130 */
131 if (vport->load_flag & FC_UNLOADING) {
132 put_node = rdata->pnode != NULL;
133 put_rport = ndlp->rport != NULL;
134 rdata->pnode = NULL;
135 ndlp->rport = NULL;
136 if (put_node)
137 lpfc_nlp_put(ndlp);
138 if (put_rport)
139 put_device(&rport->dev);
140 return;
141 }
142
143 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE)
144 return;
145
James Smart858c9f62007-06-17 19:56:39 -0500146 evtp = &ndlp->dev_loss_evt;
147
148 if (!list_empty(&evtp->evt_listp))
149 return;
150
151 spin_lock_irq(&phba->hbalock);
James Smartfa4066b2008-01-11 01:53:27 -0500152 /* We need to hold the node by incrementing the reference
153 * count until this queued work is done
154 */
155 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
James Smart5e9d9b82008-06-14 22:52:53 -0400156 if (evtp->evt_arg1) {
157 evtp->evt = LPFC_EVT_DEV_LOSS;
158 list_add_tail(&evtp->evt_listp, &phba->work_list);
159 lpfc_worker_wake_up(phba);
160 }
James Smart858c9f62007-06-17 19:56:39 -0500161 spin_unlock_irq(&phba->hbalock);
162
James Smart858c9f62007-06-17 19:56:39 -0500163 return;
164}
165
166/*
167 * This function is called from the worker thread when dev_loss_tmo
168 * expire.
169 */
Adrian Bunka6ababd2007-11-05 18:07:33 +0100170static void
James Smart858c9f62007-06-17 19:56:39 -0500171lpfc_dev_loss_tmo_handler(struct lpfc_nodelist *ndlp)
172{
173 struct lpfc_rport_data *rdata;
174 struct fc_rport *rport;
175 struct lpfc_vport *vport;
176 struct lpfc_hba *phba;
177 uint8_t *name;
James Smart87af33f2007-10-27 13:37:43 -0400178 int put_node;
179 int put_rport;
James Smart858c9f62007-06-17 19:56:39 -0500180 int warn_on = 0;
181
182 rport = ndlp->rport;
183
184 if (!rport)
185 return;
186
187 rdata = rport->dd_data;
188 name = (uint8_t *) &ndlp->nlp_portname;
189 vport = ndlp->vport;
190 phba = vport->phba;
191
192 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
193 "rport devlosstmo:did:x%x type:x%x id:x%x",
194 ndlp->nlp_DID, ndlp->nlp_type, rport->scsi_target_id);
195
James Smarta8adb832007-10-27 13:37:53 -0400196 /* Don't defer this if we are in the process of deleting the vport
197 * or unloading the driver. The unload will cleanup the node
198 * appropriately we just need to cleanup the ndlp rport info here.
199 */
200 if (vport->load_flag & FC_UNLOADING) {
James Smart09372822008-01-11 01:52:54 -0500201 if (ndlp->nlp_sid != NLP_NO_SID) {
202 /* flush the target */
203 lpfc_sli_abort_iocb(vport,
204 &phba->sli.ring[phba->sli.fcp_ring],
205 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
206 }
James Smarta8adb832007-10-27 13:37:53 -0400207 put_node = rdata->pnode != NULL;
208 put_rport = ndlp->rport != NULL;
209 rdata->pnode = NULL;
210 ndlp->rport = NULL;
211 if (put_node)
212 lpfc_nlp_put(ndlp);
213 if (put_rport)
214 put_device(&rport->dev);
215 return;
216 }
217
218 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE)
James Smart858c9f62007-06-17 19:56:39 -0500219 return;
220
James Smart92d7f7b2007-06-17 19:56:38 -0500221 if (ndlp->nlp_type & NLP_FABRIC) {
222 /* We will clean up these Nodes in linkup */
223 put_node = rdata->pnode != NULL;
224 put_rport = ndlp->rport != NULL;
225 rdata->pnode = NULL;
226 ndlp->rport = NULL;
227 if (put_node)
228 lpfc_nlp_put(ndlp);
229 if (put_rport)
230 put_device(&rport->dev);
James Smart82085712007-04-25 09:52:41 -0400231 return;
James Smart92d7f7b2007-06-17 19:56:38 -0500232 }
James Smart82085712007-04-25 09:52:41 -0400233
dea31012005-04-17 16:05:31 -0500234 if (ndlp->nlp_sid != NLP_NO_SID) {
James.Smart@Emulex.Com6e8215e2005-06-25 10:34:04 -0400235 warn_on = 1;
dea31012005-04-17 16:05:31 -0500236 /* flush the target */
James Smart51ef4c22007-08-02 11:10:31 -0400237 lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring],
238 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
dea31012005-04-17 16:05:31 -0500239 }
James Smart2e0fef82007-06-17 19:56:36 -0500240 if (vport->load_flag & FC_UNLOADING)
James Smartc01f3202006-08-18 17:47:08 -0400241 warn_on = 0;
242
James.Smart@Emulex.Com6e8215e2005-06-25 10:34:04 -0400243 if (warn_on) {
James Smarte8b62012007-08-02 11:10:09 -0400244 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
245 "0203 Devloss timeout on "
James Smart58da1ff2008-04-07 10:15:56 -0400246 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x "
247 "NPort x%06x Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400248 *name, *(name+1), *(name+2), *(name+3),
249 *(name+4), *(name+5), *(name+6), *(name+7),
250 ndlp->nlp_DID, ndlp->nlp_flag,
251 ndlp->nlp_state, ndlp->nlp_rpi);
James.Smart@Emulex.Com6e8215e2005-06-25 10:34:04 -0400252 } else {
James Smarte8b62012007-08-02 11:10:09 -0400253 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
254 "0204 Devloss timeout on "
James Smart58da1ff2008-04-07 10:15:56 -0400255 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x "
256 "NPort x%06x Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400257 *name, *(name+1), *(name+2), *(name+3),
258 *(name+4), *(name+5), *(name+6), *(name+7),
259 ndlp->nlp_DID, ndlp->nlp_flag,
260 ndlp->nlp_state, ndlp->nlp_rpi);
James.Smart@Emulex.Com6e8215e2005-06-25 10:34:04 -0400261 }
262
James Smart87af33f2007-10-27 13:37:43 -0400263 put_node = rdata->pnode != NULL;
264 put_rport = ndlp->rport != NULL;
265 rdata->pnode = NULL;
266 ndlp->rport = NULL;
267 if (put_node)
268 lpfc_nlp_put(ndlp);
269 if (put_rport)
270 put_device(&rport->dev);
271
James Smart2e0fef82007-06-17 19:56:36 -0500272 if (!(vport->load_flag & FC_UNLOADING) &&
James Smart1dcb58e2007-04-25 09:51:30 -0400273 !(ndlp->nlp_flag & NLP_DELAY_TMO) &&
James Smart82085712007-04-25 09:52:41 -0400274 !(ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
James Smarte47c9092008-02-08 18:49:26 -0500275 (ndlp->nlp_state != NLP_STE_UNMAPPED_NODE))
James Smart2e0fef82007-06-17 19:56:36 -0500276 lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
James Smart92d7f7b2007-06-17 19:56:38 -0500277}
James Smartc01f3202006-08-18 17:47:08 -0400278
dea31012005-04-17 16:05:31 -0500279static void
James Smart2e0fef82007-06-17 19:56:36 -0500280lpfc_work_list_done(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500281{
282 struct lpfc_work_evt *evtp = NULL;
283 struct lpfc_nodelist *ndlp;
284 int free_evt;
285
James Smart2e0fef82007-06-17 19:56:36 -0500286 spin_lock_irq(&phba->hbalock);
287 while (!list_empty(&phba->work_list)) {
dea31012005-04-17 16:05:31 -0500288 list_remove_head((&phba->work_list), evtp, typeof(*evtp),
289 evt_listp);
James Smart2e0fef82007-06-17 19:56:36 -0500290 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500291 free_evt = 1;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500292 switch (evtp->evt) {
dea31012005-04-17 16:05:31 -0500293 case LPFC_EVT_ELS_RETRY:
James Smart2e0fef82007-06-17 19:56:36 -0500294 ndlp = (struct lpfc_nodelist *) (evtp->evt_arg1);
dea31012005-04-17 16:05:31 -0500295 lpfc_els_retry_delay_handler(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -0500296 free_evt = 0; /* evt is part of ndlp */
James Smartfa4066b2008-01-11 01:53:27 -0500297 /* decrement the node reference count held
298 * for this queued work
299 */
300 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500301 break;
James Smart858c9f62007-06-17 19:56:39 -0500302 case LPFC_EVT_DEV_LOSS:
303 ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1);
James Smart858c9f62007-06-17 19:56:39 -0500304 lpfc_dev_loss_tmo_handler(ndlp);
305 free_evt = 0;
James Smartfa4066b2008-01-11 01:53:27 -0500306 /* decrement the node reference count held for
307 * this queued work
308 */
James Smart858c9f62007-06-17 19:56:39 -0500309 lpfc_nlp_put(ndlp);
310 break;
dea31012005-04-17 16:05:31 -0500311 case LPFC_EVT_ONLINE:
James Smart2e0fef82007-06-17 19:56:36 -0500312 if (phba->link_state < LPFC_LINK_DOWN)
313 *(int *) (evtp->evt_arg1) = lpfc_online(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500314 else
James Smart2e0fef82007-06-17 19:56:36 -0500315 *(int *) (evtp->evt_arg1) = 0;
dea31012005-04-17 16:05:31 -0500316 complete((struct completion *)(evtp->evt_arg2));
317 break;
James Smart46fa3112007-04-25 09:51:45 -0400318 case LPFC_EVT_OFFLINE_PREP:
James Smart2e0fef82007-06-17 19:56:36 -0500319 if (phba->link_state >= LPFC_LINK_DOWN)
James Smart46fa3112007-04-25 09:51:45 -0400320 lpfc_offline_prep(phba);
321 *(int *)(evtp->evt_arg1) = 0;
322 complete((struct completion *)(evtp->evt_arg2));
323 break;
324 case LPFC_EVT_OFFLINE:
325 lpfc_offline(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500326 lpfc_sli_brdrestart(phba);
327 *(int *)(evtp->evt_arg1) =
James Smart46fa3112007-04-25 09:51:45 -0400328 lpfc_sli_brdready(phba, HS_FFRDY | HS_MBRDY);
329 lpfc_unblock_mgmt_io(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500330 complete((struct completion *)(evtp->evt_arg2));
331 break;
332 case LPFC_EVT_WARM_START:
James Smart46fa3112007-04-25 09:51:45 -0400333 lpfc_offline(phba);
James Smart92908312006-03-07 15:04:13 -0500334 lpfc_reset_barrier(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500335 lpfc_sli_brdreset(phba);
336 lpfc_hba_down_post(phba);
337 *(int *)(evtp->evt_arg1) =
338 lpfc_sli_brdready(phba, HS_MBRDY);
James Smart46fa3112007-04-25 09:51:45 -0400339 lpfc_unblock_mgmt_io(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500340 complete((struct completion *)(evtp->evt_arg2));
341 break;
342 case LPFC_EVT_KILL:
James Smart46fa3112007-04-25 09:51:45 -0400343 lpfc_offline(phba);
James Smart92908312006-03-07 15:04:13 -0500344 *(int *)(evtp->evt_arg1)
James Smart2e0fef82007-06-17 19:56:36 -0500345 = (phba->pport->stopped)
346 ? 0 : lpfc_sli_brdkill(phba);
James Smart46fa3112007-04-25 09:51:45 -0400347 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -0500348 complete((struct completion *)(evtp->evt_arg2));
349 break;
350 }
351 if (free_evt)
352 kfree(evtp);
James Smart2e0fef82007-06-17 19:56:36 -0500353 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500354 }
James Smart2e0fef82007-06-17 19:56:36 -0500355 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500356
357}
358
James Smart311464e2007-08-02 11:10:37 -0400359static void
James Smart2e0fef82007-06-17 19:56:36 -0500360lpfc_work_done(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500361{
362 struct lpfc_sli_ring *pring;
James Smart858c9f62007-06-17 19:56:39 -0500363 uint32_t ha_copy, status, control, work_port_events;
James Smart549e55c2007-08-02 11:09:51 -0400364 struct lpfc_vport **vports;
James Smart51ef4c22007-08-02 11:10:31 -0400365 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -0400366 int i;
dea31012005-04-17 16:05:31 -0500367
James Smart2e0fef82007-06-17 19:56:36 -0500368 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500369 ha_copy = phba->work_ha;
370 phba->work_ha = 0;
James Smart2e0fef82007-06-17 19:56:36 -0500371 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500372
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500373 if (ha_copy & HA_ERATT)
dea31012005-04-17 16:05:31 -0500374 lpfc_handle_eratt(phba);
375
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500376 if (ha_copy & HA_MBATT)
dea31012005-04-17 16:05:31 -0500377 lpfc_sli_handle_mb_event(phba);
378
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500379 if (ha_copy & HA_LATT)
dea31012005-04-17 16:05:31 -0500380 lpfc_handle_latt(phba);
James Smart549e55c2007-08-02 11:09:51 -0400381 vports = lpfc_create_vport_work_array(phba);
382 if (vports != NULL)
James Smart09372822008-01-11 01:52:54 -0500383 for(i = 0; i <= phba->max_vpi; i++) {
James Smart51ef4c22007-08-02 11:10:31 -0400384 /*
385 * We could have no vports in array if unloading, so if
386 * this happens then just use the pport
387 */
388 if (vports[i] == NULL && i == 0)
389 vport = phba->pport;
390 else
391 vport = vports[i];
392 if (vport == NULL)
393 break;
James Smart58da1ff2008-04-07 10:15:56 -0400394 spin_lock_irq(&vport->work_port_lock);
James Smart51ef4c22007-08-02 11:10:31 -0400395 work_port_events = vport->work_port_events;
James Smart58da1ff2008-04-07 10:15:56 -0400396 vport->work_port_events &= ~work_port_events;
397 spin_unlock_irq(&vport->work_port_lock);
James Smart549e55c2007-08-02 11:09:51 -0400398 if (work_port_events & WORKER_DISC_TMO)
James Smart51ef4c22007-08-02 11:10:31 -0400399 lpfc_disc_timeout_handler(vport);
James Smart549e55c2007-08-02 11:09:51 -0400400 if (work_port_events & WORKER_ELS_TMO)
James Smart51ef4c22007-08-02 11:10:31 -0400401 lpfc_els_timeout_handler(vport);
James Smart549e55c2007-08-02 11:09:51 -0400402 if (work_port_events & WORKER_HB_TMO)
403 lpfc_hb_timeout_handler(phba);
404 if (work_port_events & WORKER_MBOX_TMO)
405 lpfc_mbox_timeout_handler(phba);
406 if (work_port_events & WORKER_FABRIC_BLOCK_TMO)
407 lpfc_unblock_fabric_iocbs(phba);
408 if (work_port_events & WORKER_FDMI_TMO)
James Smart51ef4c22007-08-02 11:10:31 -0400409 lpfc_fdmi_timeout_handler(vport);
James Smart549e55c2007-08-02 11:09:51 -0400410 if (work_port_events & WORKER_RAMP_DOWN_QUEUE)
411 lpfc_ramp_down_queue_handler(phba);
412 if (work_port_events & WORKER_RAMP_UP_QUEUE)
413 lpfc_ramp_up_queue_handler(phba);
James Smart92d7f7b2007-06-17 19:56:38 -0500414 }
James Smart09372822008-01-11 01:52:54 -0500415 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -0500416
James Smart858c9f62007-06-17 19:56:39 -0500417 pring = &phba->sli.ring[LPFC_ELS_RING];
418 status = (ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
419 status >>= (4*LPFC_ELS_RING);
420 if ((status & HA_RXMASK)
421 || (pring->flag & LPFC_DEFERRED_RING_EVENT)) {
James Smart0b727fe2007-10-27 13:37:25 -0400422 if (pring->flag & LPFC_STOP_IOCB_EVENT) {
James Smart858c9f62007-06-17 19:56:39 -0500423 pring->flag |= LPFC_DEFERRED_RING_EVENT;
James Smart5e9d9b82008-06-14 22:52:53 -0400424 /* Set the lpfc data pending flag */
425 set_bit(LPFC_DATA_READY, &phba->data_flags);
James Smart858c9f62007-06-17 19:56:39 -0500426 } else {
James Smart58da1ff2008-04-07 10:15:56 -0400427 pring->flag &= ~LPFC_DEFERRED_RING_EVENT;
James Smart858c9f62007-06-17 19:56:39 -0500428 lpfc_sli_handle_slow_ring_event(phba, pring,
429 (status &
430 HA_RXMASK));
James Smart858c9f62007-06-17 19:56:39 -0500431 }
432 /*
433 * Turn on Ring interrupts
434 */
435 spin_lock_irq(&phba->hbalock);
436 control = readl(phba->HCregaddr);
437 if (!(control & (HC_R0INT_ENA << LPFC_ELS_RING))) {
James Smarta58cbd52007-08-02 11:09:43 -0400438 lpfc_debugfs_slow_ring_trc(phba,
439 "WRK Enable ring: cntl:x%x hacopy:x%x",
440 control, ha_copy, 0);
441
James Smart858c9f62007-06-17 19:56:39 -0500442 control |= (HC_R0INT_ENA << LPFC_ELS_RING);
dea31012005-04-17 16:05:31 -0500443 writel(control, phba->HCregaddr);
444 readl(phba->HCregaddr); /* flush */
dea31012005-04-17 16:05:31 -0500445 }
James Smarta58cbd52007-08-02 11:09:43 -0400446 else {
447 lpfc_debugfs_slow_ring_trc(phba,
448 "WRK Ring ok: cntl:x%x hacopy:x%x",
449 control, ha_copy, 0);
450 }
James Smart858c9f62007-06-17 19:56:39 -0500451 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500452 }
James Smart2e0fef82007-06-17 19:56:36 -0500453 lpfc_work_list_done(phba);
dea31012005-04-17 16:05:31 -0500454}
455
dea31012005-04-17 16:05:31 -0500456int
457lpfc_do_work(void *p)
458{
459 struct lpfc_hba *phba = p;
460 int rc;
dea31012005-04-17 16:05:31 -0500461
462 set_user_nice(current, -20);
James Smart5e9d9b82008-06-14 22:52:53 -0400463 phba->data_flags = 0;
dea31012005-04-17 16:05:31 -0500464
465 while (1) {
James Smart5e9d9b82008-06-14 22:52:53 -0400466 /* wait and check worker queue activities */
467 rc = wait_event_interruptible(phba->work_waitq,
468 (test_and_clear_bit(LPFC_DATA_READY,
469 &phba->data_flags)
470 || kthread_should_stop()));
dea31012005-04-17 16:05:31 -0500471 BUG_ON(rc);
472
473 if (kthread_should_stop())
474 break;
475
James Smart5e9d9b82008-06-14 22:52:53 -0400476 /* Attend pending lpfc data processing */
dea31012005-04-17 16:05:31 -0500477 lpfc_work_done(phba);
dea31012005-04-17 16:05:31 -0500478 }
dea31012005-04-17 16:05:31 -0500479 return 0;
480}
481
482/*
483 * This is only called to handle FC worker events. Since this a rare
484 * occurance, we allocate a struct lpfc_work_evt structure here instead of
485 * embedding it in the IOCB.
486 */
487int
James Smart2e0fef82007-06-17 19:56:36 -0500488lpfc_workq_post_event(struct lpfc_hba *phba, void *arg1, void *arg2,
dea31012005-04-17 16:05:31 -0500489 uint32_t evt)
490{
491 struct lpfc_work_evt *evtp;
James Smarted957682007-06-17 19:56:37 -0500492 unsigned long flags;
dea31012005-04-17 16:05:31 -0500493
494 /*
495 * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will
496 * be queued to worker thread for processing
497 */
James Smart92d7f7b2007-06-17 19:56:38 -0500498 evtp = kmalloc(sizeof(struct lpfc_work_evt), GFP_ATOMIC);
dea31012005-04-17 16:05:31 -0500499 if (!evtp)
500 return 0;
501
502 evtp->evt_arg1 = arg1;
503 evtp->evt_arg2 = arg2;
504 evtp->evt = evt;
505
James Smarted957682007-06-17 19:56:37 -0500506 spin_lock_irqsave(&phba->hbalock, flags);
James Smart071fbd3d2006-04-15 11:53:20 -0400507 list_add_tail(&evtp->evt_listp, &phba->work_list);
James Smarted957682007-06-17 19:56:37 -0500508 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -0500509
James Smart5e9d9b82008-06-14 22:52:53 -0400510 lpfc_worker_wake_up(phba);
511
dea31012005-04-17 16:05:31 -0500512 return 1;
513}
514
James Smart92d7f7b2007-06-17 19:56:38 -0500515void
516lpfc_cleanup_rpis(struct lpfc_vport *vport, int remove)
517{
James Smart09372822008-01-11 01:52:54 -0500518 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500519 struct lpfc_hba *phba = vport->phba;
520 struct lpfc_nodelist *ndlp, *next_ndlp;
521 int rc;
522
523 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -0500524 if (!NLP_CHK_NODE_ACT(ndlp))
525 continue;
James Smart92d7f7b2007-06-17 19:56:38 -0500526 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
527 continue;
James Smart98c9ea52007-10-27 13:37:33 -0400528 if ((phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) ||
529 ((vport->port_type == LPFC_NPIV_PORT) &&
530 (ndlp->nlp_DID == NameServer_DID)))
James Smart92d7f7b2007-06-17 19:56:38 -0500531 lpfc_unreg_rpi(vport, ndlp);
532
533 /* Leave Fabric nodes alone on link down */
534 if (!remove && ndlp->nlp_type & NLP_FABRIC)
535 continue;
536 rc = lpfc_disc_state_machine(vport, ndlp, NULL,
537 remove
538 ? NLP_EVT_DEVICE_RM
539 : NLP_EVT_DEVICE_RECOVERY);
540 }
541 if (phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) {
542 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -0500543 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500544 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -0500545 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500546 }
547}
548
James Smart87af33f2007-10-27 13:37:43 -0400549void
James Smart98c9ea52007-10-27 13:37:33 -0400550lpfc_port_link_failure(struct lpfc_vport *vport)
James Smart92d7f7b2007-06-17 19:56:38 -0500551{
James Smart92d7f7b2007-06-17 19:56:38 -0500552 /* Cleanup any outstanding RSCN activity */
553 lpfc_els_flush_rscn(vport);
554
555 /* Cleanup any outstanding ELS commands */
556 lpfc_els_flush_cmd(vport);
557
558 lpfc_cleanup_rpis(vport, 0);
559
James Smart92d7f7b2007-06-17 19:56:38 -0500560 /* Turn off discovery timer if its running */
561 lpfc_can_disctmo(vport);
562}
563
James Smart98c9ea52007-10-27 13:37:33 -0400564static void
565lpfc_linkdown_port(struct lpfc_vport *vport)
566{
567 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
568
569 fc_host_post_event(shost, fc_get_event_number(), FCH_EVT_LINKDOWN, 0);
570
571 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
572 "Link Down: state:x%x rtry:x%x flg:x%x",
573 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
574
575 lpfc_port_link_failure(vport);
576
577}
578
dea31012005-04-17 16:05:31 -0500579int
James Smart685f0bf2007-04-25 09:53:08 -0400580lpfc_linkdown(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500581{
James Smart2e0fef82007-06-17 19:56:36 -0500582 struct lpfc_vport *vport = phba->pport;
583 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart549e55c2007-08-02 11:09:51 -0400584 struct lpfc_vport **vports;
James Smart685f0bf2007-04-25 09:53:08 -0400585 LPFC_MBOXQ_t *mb;
James Smart549e55c2007-08-02 11:09:51 -0400586 int i;
dea31012005-04-17 16:05:31 -0500587
James Smart3163f722008-02-08 18:50:25 -0500588 if (phba->link_state == LPFC_LINK_DOWN)
James Smart2e0fef82007-06-17 19:56:36 -0500589 return 0;
James Smart2e0fef82007-06-17 19:56:36 -0500590 spin_lock_irq(&phba->hbalock);
James Smart92d7f7b2007-06-17 19:56:38 -0500591 if (phba->link_state > LPFC_LINK_DOWN) {
James Smart2e0fef82007-06-17 19:56:36 -0500592 phba->link_state = LPFC_LINK_DOWN;
James Smart92d7f7b2007-06-17 19:56:38 -0500593 phba->pport->fc_flag &= ~FC_LBIT;
594 }
James Smart2e0fef82007-06-17 19:56:36 -0500595 spin_unlock_irq(&phba->hbalock);
James Smart549e55c2007-08-02 11:09:51 -0400596 vports = lpfc_create_vport_work_array(phba);
597 if (vports != NULL)
James Smart09372822008-01-11 01:52:54 -0500598 for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -0400599 /* Issue a LINK DOWN event to all nodes */
600 lpfc_linkdown_port(vports[i]);
601 }
James Smart09372822008-01-11 01:52:54 -0500602 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -0500603 /* Clean up any firmware default rpi's */
James Smart2e0fef82007-06-17 19:56:36 -0500604 mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
605 if (mb) {
James Smart92d7f7b2007-06-17 19:56:38 -0500606 lpfc_unreg_did(phba, 0xffff, 0xffffffff, mb);
James Smarted957682007-06-17 19:56:37 -0500607 mb->vport = vport;
James Smart2e0fef82007-06-17 19:56:36 -0500608 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart0b727fe2007-10-27 13:37:25 -0400609 if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT)
dea31012005-04-17 16:05:31 -0500610 == MBX_NOT_FINISHED) {
James Smart2e0fef82007-06-17 19:56:36 -0500611 mempool_free(mb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500612 }
613 }
614
dea31012005-04-17 16:05:31 -0500615 /* Setup myDID for link up if we are in pt2pt mode */
James Smart92d7f7b2007-06-17 19:56:38 -0500616 if (phba->pport->fc_flag & FC_PT2PT) {
617 phba->pport->fc_myDID = 0;
James Smart2e0fef82007-06-17 19:56:36 -0500618 mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
619 if (mb) {
dea31012005-04-17 16:05:31 -0500620 lpfc_config_link(phba, mb);
James Smart92d7f7b2007-06-17 19:56:38 -0500621 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -0500622 mb->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -0400623 if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT)
dea31012005-04-17 16:05:31 -0500624 == MBX_NOT_FINISHED) {
James Smart2e0fef82007-06-17 19:56:36 -0500625 mempool_free(mb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500626 }
627 }
James Smart2e0fef82007-06-17 19:56:36 -0500628 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500629 phba->pport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI);
James Smart2e0fef82007-06-17 19:56:36 -0500630 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500631 }
James Smart2e0fef82007-06-17 19:56:36 -0500632
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500633 return 0;
dea31012005-04-17 16:05:31 -0500634}
635
James Smart92d7f7b2007-06-17 19:56:38 -0500636static void
637lpfc_linkup_cleanup_nodes(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -0500638{
James Smart92d7f7b2007-06-17 19:56:38 -0500639 struct lpfc_nodelist *ndlp;
640
641 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -0500642 if (!NLP_CHK_NODE_ACT(ndlp))
643 continue;
James Smart92d7f7b2007-06-17 19:56:38 -0500644 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
645 continue;
James Smart92d7f7b2007-06-17 19:56:38 -0500646 if (ndlp->nlp_type & NLP_FABRIC) {
James Smarte47c9092008-02-08 18:49:26 -0500647 /* On Linkup its safe to clean up the ndlp
648 * from Fabric connections.
649 */
James Smart92d7f7b2007-06-17 19:56:38 -0500650 if (ndlp->nlp_DID != Fabric_DID)
651 lpfc_unreg_rpi(vport, ndlp);
652 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
653 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
James Smarte47c9092008-02-08 18:49:26 -0500654 /* Fail outstanding IO now since device is
655 * marked for PLOGI.
656 */
James Smart92d7f7b2007-06-17 19:56:38 -0500657 lpfc_unreg_rpi(vport, ndlp);
658 }
659 }
660}
661
662static void
663lpfc_linkup_port(struct lpfc_vport *vport)
664{
665 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500666 struct lpfc_hba *phba = vport->phba;
667
668 if ((vport->load_flag & FC_UNLOADING) != 0)
669 return;
670
James Smart858c9f62007-06-17 19:56:39 -0500671 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
672 "Link Up: top:x%x speed:x%x flg:x%x",
673 phba->fc_topology, phba->fc_linkspeed, phba->link_flag);
674
James Smart92d7f7b2007-06-17 19:56:38 -0500675 /* If NPIV is not enabled, only bring the physical port up */
676 if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
677 (vport != phba->pport))
678 return;
dea31012005-04-17 16:05:31 -0500679
James Smart2e0fef82007-06-17 19:56:36 -0500680 fc_host_post_event(shost, fc_get_event_number(), FCH_EVT_LINKUP, 0);
James Smartd2873e42006-08-18 17:46:43 -0400681
James Smart2e0fef82007-06-17 19:56:36 -0500682 spin_lock_irq(shost->host_lock);
James Smart2e0fef82007-06-17 19:56:36 -0500683 vport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI | FC_ABORT_DISCOVERY |
684 FC_RSCN_MODE | FC_NLP_MORE | FC_RSCN_DISCOVERY);
685 vport->fc_flag |= FC_NDISC_ACTIVE;
686 vport->fc_ns_retry = 0;
687 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500688
James Smart92d7f7b2007-06-17 19:56:38 -0500689 if (vport->fc_flag & FC_LBIT)
690 lpfc_linkup_cleanup_nodes(vport);
dea31012005-04-17 16:05:31 -0500691
James Smart92d7f7b2007-06-17 19:56:38 -0500692}
693
694static int
695lpfc_linkup(struct lpfc_hba *phba)
696{
James Smart549e55c2007-08-02 11:09:51 -0400697 struct lpfc_vport **vports;
698 int i;
James Smart92d7f7b2007-06-17 19:56:38 -0500699
700 phba->link_state = LPFC_LINK_UP;
701
702 /* Unblock fabric iocbs if they are blocked */
703 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
704 del_timer_sync(&phba->fabric_block_timer);
705
James Smart549e55c2007-08-02 11:09:51 -0400706 vports = lpfc_create_vport_work_array(phba);
707 if (vports != NULL)
James Smart09372822008-01-11 01:52:54 -0500708 for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++)
James Smart549e55c2007-08-02 11:09:51 -0400709 lpfc_linkup_port(vports[i]);
James Smart09372822008-01-11 01:52:54 -0500710 lpfc_destroy_vport_work_array(phba, vports);
James Smart92d7f7b2007-06-17 19:56:38 -0500711 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
712 lpfc_issue_clear_la(phba, phba->pport);
dea31012005-04-17 16:05:31 -0500713
714 return 0;
715}
716
717/*
718 * This routine handles processing a CLEAR_LA mailbox
719 * command upon completion. It is setup in the LPFC_MBOXQ
720 * as the completion routine when the command is
721 * handed off to the SLI layer.
722 */
Adrian Bunka6ababd2007-11-05 18:07:33 +0100723static void
James Smart2e0fef82007-06-17 19:56:36 -0500724lpfc_mbx_cmpl_clear_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -0500725{
James Smart2e0fef82007-06-17 19:56:36 -0500726 struct lpfc_vport *vport = pmb->vport;
727 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
728 struct lpfc_sli *psli = &phba->sli;
729 MAILBOX_t *mb = &pmb->mb;
dea31012005-04-17 16:05:31 -0500730 uint32_t control;
731
dea31012005-04-17 16:05:31 -0500732 /* Since we don't do discovery right now, turn these off here */
James Smarta4bc3372006-12-02 13:34:16 -0500733 psli->ring[psli->extra_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
dea31012005-04-17 16:05:31 -0500734 psli->ring[psli->fcp_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
735 psli->ring[psli->next_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
736
737 /* Check for error */
738 if ((mb->mbxStatus) && (mb->mbxStatus != 0x1601)) {
James Smart92d7f7b2007-06-17 19:56:38 -0500739 /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */
James Smarte8b62012007-08-02 11:10:09 -0400740 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
741 "0320 CLEAR_LA mbxStatus error x%x hba "
742 "state x%x\n",
743 mb->mbxStatus, vport->port_state);
James Smart2e0fef82007-06-17 19:56:36 -0500744 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500745 goto out;
746 }
747
James Smart92d7f7b2007-06-17 19:56:38 -0500748 if (vport->port_type == LPFC_PHYSICAL_PORT)
749 phba->link_state = LPFC_HBA_READY;
750
751 spin_lock_irq(&phba->hbalock);
752 psli->sli_flag |= LPFC_PROCESS_LA;
753 control = readl(phba->HCregaddr);
754 control |= HC_LAINT_ENA;
755 writel(control, phba->HCregaddr);
756 readl(phba->HCregaddr); /* flush */
757 spin_unlock_irq(&phba->hbalock);
James Smart1b32f6a2008-02-08 18:49:39 -0500758 mempool_free(pmb, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -0500759 return;
dea31012005-04-17 16:05:31 -0500760
dea31012005-04-17 16:05:31 -0500761out:
762 /* Device Discovery completes */
James Smarte8b62012007-08-02 11:10:09 -0400763 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
764 "0225 Device Discovery completes\n");
James Smart2e0fef82007-06-17 19:56:36 -0500765 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500766
James Smart2e0fef82007-06-17 19:56:36 -0500767 spin_lock_irq(shost->host_lock);
James Smart58da1ff2008-04-07 10:15:56 -0400768 vport->fc_flag &= ~FC_ABORT_DISCOVERY;
James Smart2e0fef82007-06-17 19:56:36 -0500769 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500770
James Smart2e0fef82007-06-17 19:56:36 -0500771 lpfc_can_disctmo(vport);
dea31012005-04-17 16:05:31 -0500772
773 /* turn on Link Attention interrupts */
James Smart2e0fef82007-06-17 19:56:36 -0500774
775 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500776 psli->sli_flag |= LPFC_PROCESS_LA;
777 control = readl(phba->HCregaddr);
778 control |= HC_LAINT_ENA;
779 writel(control, phba->HCregaddr);
780 readl(phba->HCregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -0500781 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500782
783 return;
784}
785
James Smart2e0fef82007-06-17 19:56:36 -0500786
dea31012005-04-17 16:05:31 -0500787static void
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500788lpfc_mbx_cmpl_local_config_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -0500789{
James Smart2e0fef82007-06-17 19:56:36 -0500790 struct lpfc_vport *vport = pmb->vport;
dea31012005-04-17 16:05:31 -0500791
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500792 if (pmb->mb.mbxStatus)
dea31012005-04-17 16:05:31 -0500793 goto out;
dea31012005-04-17 16:05:31 -0500794
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500795 mempool_free(pmb, phba->mbox_mem_pool);
796
797 if (phba->fc_topology == TOPOLOGY_LOOP &&
James Smart2e0fef82007-06-17 19:56:36 -0500798 vport->fc_flag & FC_PUBLIC_LOOP &&
799 !(vport->fc_flag & FC_LBIT)) {
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500800 /* Need to wait for FAN - use discovery timer
James Smart2e0fef82007-06-17 19:56:36 -0500801 * for timeout. port_state is identically
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500802 * LPFC_LOCAL_CFG_LINK while waiting for FAN
803 */
James Smart2e0fef82007-06-17 19:56:36 -0500804 lpfc_set_disctmo(vport);
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500805 return;
James Smart92d7f7b2007-06-17 19:56:38 -0500806 }
dea31012005-04-17 16:05:31 -0500807
James Smart2e0fef82007-06-17 19:56:36 -0500808 /* Start discovery by sending a FLOGI. port_state is identically
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500809 * LPFC_FLOGI while waiting for FLOGI cmpl
810 */
James Smart92d7f7b2007-06-17 19:56:38 -0500811 if (vport->port_state != LPFC_FLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -0500812 lpfc_initial_flogi(vport);
813 }
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500814 return;
dea31012005-04-17 16:05:31 -0500815
816out:
James Smarte8b62012007-08-02 11:10:09 -0400817 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
818 "0306 CONFIG_LINK mbxStatus error x%x "
819 "HBA state x%x\n",
820 pmb->mb.mbxStatus, vport->port_state);
James Smart92d7f7b2007-06-17 19:56:38 -0500821 mempool_free(pmb, phba->mbox_mem_pool);
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500822
823 lpfc_linkdown(phba);
824
James Smarte8b62012007-08-02 11:10:09 -0400825 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
826 "0200 CONFIG_LINK bad hba state x%x\n",
827 vport->port_state);
dea31012005-04-17 16:05:31 -0500828
James Smart92d7f7b2007-06-17 19:56:38 -0500829 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -0500830 return;
831}
832
833static void
James Smart2e0fef82007-06-17 19:56:36 -0500834lpfc_mbx_cmpl_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -0500835{
dea31012005-04-17 16:05:31 -0500836 MAILBOX_t *mb = &pmb->mb;
837 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) pmb->context1;
James Smart2e0fef82007-06-17 19:56:36 -0500838 struct lpfc_vport *vport = pmb->vport;
dea31012005-04-17 16:05:31 -0500839
840
841 /* Check for error */
842 if (mb->mbxStatus) {
843 /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */
James Smarte8b62012007-08-02 11:10:09 -0400844 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
845 "0319 READ_SPARAM mbxStatus error x%x "
846 "hba state x%x>\n",
847 mb->mbxStatus, vport->port_state);
dea31012005-04-17 16:05:31 -0500848 lpfc_linkdown(phba);
dea31012005-04-17 16:05:31 -0500849 goto out;
850 }
851
James Smart2e0fef82007-06-17 19:56:36 -0500852 memcpy((uint8_t *) &vport->fc_sparam, (uint8_t *) mp->virt,
dea31012005-04-17 16:05:31 -0500853 sizeof (struct serv_parm));
James Smarta12e07b2006-12-02 13:35:30 -0500854 if (phba->cfg_soft_wwnn)
James Smart2e0fef82007-06-17 19:56:36 -0500855 u64_to_wwn(phba->cfg_soft_wwnn,
856 vport->fc_sparam.nodeName.u.wwn);
James Smartc3f28af2006-08-18 17:47:18 -0400857 if (phba->cfg_soft_wwpn)
James Smart2e0fef82007-06-17 19:56:36 -0500858 u64_to_wwn(phba->cfg_soft_wwpn,
859 vport->fc_sparam.portName.u.wwn);
James Smart92d7f7b2007-06-17 19:56:38 -0500860 memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
861 sizeof(vport->fc_nodename));
862 memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
863 sizeof(vport->fc_portname));
864 if (vport->port_type == LPFC_PHYSICAL_PORT) {
865 memcpy(&phba->wwnn, &vport->fc_nodename, sizeof(phba->wwnn));
866 memcpy(&phba->wwpn, &vport->fc_portname, sizeof(phba->wwnn));
867 }
868
dea31012005-04-17 16:05:31 -0500869 lpfc_mbuf_free(phba, mp->virt, mp->phys);
870 kfree(mp);
James Smart2e0fef82007-06-17 19:56:36 -0500871 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500872 return;
873
874out:
875 pmb->context1 = NULL;
876 lpfc_mbuf_free(phba, mp->virt, mp->phys);
877 kfree(mp);
James Smart92d7f7b2007-06-17 19:56:38 -0500878 lpfc_issue_clear_la(phba, vport);
879 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500880 return;
881}
882
883static void
James Smart92d7f7b2007-06-17 19:56:38 -0500884lpfc_mbx_process_link_up(struct lpfc_hba *phba, READ_LA_VAR *la)
dea31012005-04-17 16:05:31 -0500885{
James Smart92d7f7b2007-06-17 19:56:38 -0500886 struct lpfc_vport *vport = phba->pport;
dea31012005-04-17 16:05:31 -0500887 LPFC_MBOXQ_t *sparam_mbox, *cfglink_mbox;
James Smart2e0fef82007-06-17 19:56:36 -0500888 int i;
James Smart14691152006-12-02 13:34:28 -0500889 struct lpfc_dmabuf *mp;
890 int rc;
891
dea31012005-04-17 16:05:31 -0500892 sparam_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
893 cfglink_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
894
James Smart92d7f7b2007-06-17 19:56:38 -0500895 spin_lock_irq(&phba->hbalock);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500896 switch (la->UlnkSpeed) {
James Smart92d7f7b2007-06-17 19:56:38 -0500897 case LA_1GHZ_LINK:
898 phba->fc_linkspeed = LA_1GHZ_LINK;
899 break;
900 case LA_2GHZ_LINK:
901 phba->fc_linkspeed = LA_2GHZ_LINK;
902 break;
903 case LA_4GHZ_LINK:
904 phba->fc_linkspeed = LA_4GHZ_LINK;
905 break;
906 case LA_8GHZ_LINK:
907 phba->fc_linkspeed = LA_8GHZ_LINK;
908 break;
909 default:
910 phba->fc_linkspeed = LA_UNKNW_LINK;
911 break;
dea31012005-04-17 16:05:31 -0500912 }
913
914 phba->fc_topology = la->topology;
James Smart92d7f7b2007-06-17 19:56:38 -0500915 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
dea31012005-04-17 16:05:31 -0500916
917 if (phba->fc_topology == TOPOLOGY_LOOP) {
James Smart92d7f7b2007-06-17 19:56:38 -0500918 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
dea31012005-04-17 16:05:31 -0500919
James Smart92d7f7b2007-06-17 19:56:38 -0500920 /* Get Loop Map information */
dea31012005-04-17 16:05:31 -0500921 if (la->il)
James Smart2e0fef82007-06-17 19:56:36 -0500922 vport->fc_flag |= FC_LBIT;
dea31012005-04-17 16:05:31 -0500923
James Smart2e0fef82007-06-17 19:56:36 -0500924 vport->fc_myDID = la->granted_AL_PA;
dea31012005-04-17 16:05:31 -0500925 i = la->un.lilpBde64.tus.f.bdeSize;
926
927 if (i == 0) {
928 phba->alpa_map[0] = 0;
929 } else {
James Smarte8b62012007-08-02 11:10:09 -0400930 if (vport->cfg_log_verbose & LOG_LINK_EVENT) {
dea31012005-04-17 16:05:31 -0500931 int numalpa, j, k;
932 union {
933 uint8_t pamap[16];
934 struct {
935 uint32_t wd1;
936 uint32_t wd2;
937 uint32_t wd3;
938 uint32_t wd4;
939 } pa;
940 } un;
941 numalpa = phba->alpa_map[0];
942 j = 0;
943 while (j < numalpa) {
944 memset(un.pamap, 0, 16);
945 for (k = 1; j < numalpa; k++) {
946 un.pamap[k - 1] =
947 phba->alpa_map[j + 1];
948 j++;
949 if (k == 16)
950 break;
951 }
952 /* Link Up Event ALPA map */
953 lpfc_printf_log(phba,
James Smart92d7f7b2007-06-17 19:56:38 -0500954 KERN_WARNING,
955 LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -0400956 "1304 Link Up Event "
James Smart92d7f7b2007-06-17 19:56:38 -0500957 "ALPA map Data: x%x "
958 "x%x x%x x%x\n",
James Smart92d7f7b2007-06-17 19:56:38 -0500959 un.pa.wd1, un.pa.wd2,
960 un.pa.wd3, un.pa.wd4);
dea31012005-04-17 16:05:31 -0500961 }
962 }
963 }
964 } else {
James Smart92d7f7b2007-06-17 19:56:38 -0500965 if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)) {
James Smart78b2d852007-08-02 11:10:21 -0400966 if (phba->max_vpi && phba->cfg_enable_npiv &&
James Smart92d7f7b2007-06-17 19:56:38 -0500967 (phba->sli_rev == 3))
968 phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
969 }
James Smart2e0fef82007-06-17 19:56:36 -0500970 vport->fc_myDID = phba->fc_pref_DID;
971 vport->fc_flag |= FC_LBIT;
dea31012005-04-17 16:05:31 -0500972 }
James Smart92d7f7b2007-06-17 19:56:38 -0500973 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500974
975 lpfc_linkup(phba);
976 if (sparam_mbox) {
James Smart92d7f7b2007-06-17 19:56:38 -0500977 lpfc_read_sparam(phba, sparam_mbox, 0);
James Smart2e0fef82007-06-17 19:56:36 -0500978 sparam_mbox->vport = vport;
dea31012005-04-17 16:05:31 -0500979 sparam_mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam;
James Smart0b727fe2007-10-27 13:37:25 -0400980 rc = lpfc_sli_issue_mbox(phba, sparam_mbox, MBX_NOWAIT);
James Smart14691152006-12-02 13:34:28 -0500981 if (rc == MBX_NOT_FINISHED) {
982 mp = (struct lpfc_dmabuf *) sparam_mbox->context1;
983 lpfc_mbuf_free(phba, mp->virt, mp->phys);
984 kfree(mp);
985 mempool_free(sparam_mbox, phba->mbox_mem_pool);
986 if (cfglink_mbox)
987 mempool_free(cfglink_mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -0500988 goto out;
James Smart14691152006-12-02 13:34:28 -0500989 }
dea31012005-04-17 16:05:31 -0500990 }
991
992 if (cfglink_mbox) {
James Smart2e0fef82007-06-17 19:56:36 -0500993 vport->port_state = LPFC_LOCAL_CFG_LINK;
dea31012005-04-17 16:05:31 -0500994 lpfc_config_link(phba, cfglink_mbox);
James Smart2e0fef82007-06-17 19:56:36 -0500995 cfglink_mbox->vport = vport;
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500996 cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
James Smart0b727fe2007-10-27 13:37:25 -0400997 rc = lpfc_sli_issue_mbox(phba, cfglink_mbox, MBX_NOWAIT);
James Smart92d7f7b2007-06-17 19:56:38 -0500998 if (rc != MBX_NOT_FINISHED)
999 return;
1000 mempool_free(cfglink_mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05001001 }
James Smart92d7f7b2007-06-17 19:56:38 -05001002out:
1003 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04001004 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
1005 "0263 Discovery Mailbox error: state: 0x%x : %p %p\n",
1006 vport->port_state, sparam_mbox, cfglink_mbox);
James Smart92d7f7b2007-06-17 19:56:38 -05001007 lpfc_issue_clear_la(phba, vport);
1008 return;
dea31012005-04-17 16:05:31 -05001009}
1010
1011static void
James Smart2e0fef82007-06-17 19:56:36 -05001012lpfc_mbx_issue_link_down(struct lpfc_hba *phba)
1013{
dea31012005-04-17 16:05:31 -05001014 uint32_t control;
1015 struct lpfc_sli *psli = &phba->sli;
1016
1017 lpfc_linkdown(phba);
1018
1019 /* turn on Link Attention interrupts - no CLEAR_LA needed */
James Smart2e0fef82007-06-17 19:56:36 -05001020 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001021 psli->sli_flag |= LPFC_PROCESS_LA;
1022 control = readl(phba->HCregaddr);
1023 control |= HC_LAINT_ENA;
1024 writel(control, phba->HCregaddr);
1025 readl(phba->HCregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05001026 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001027}
1028
1029/*
1030 * This routine handles processing a READ_LA mailbox
1031 * command upon completion. It is setup in the LPFC_MBOXQ
1032 * as the completion routine when the command is
1033 * handed off to the SLI layer.
1034 */
1035void
James Smart2e0fef82007-06-17 19:56:36 -05001036lpfc_mbx_cmpl_read_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05001037{
James Smart2e0fef82007-06-17 19:56:36 -05001038 struct lpfc_vport *vport = pmb->vport;
1039 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001040 READ_LA_VAR *la;
1041 MAILBOX_t *mb = &pmb->mb;
1042 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
1043
James Smart0d2b6b82008-06-14 22:52:47 -04001044 /* Unblock ELS traffic */
1045 phba->sli.ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
dea31012005-04-17 16:05:31 -05001046 /* Check for error */
1047 if (mb->mbxStatus) {
James Smarted957682007-06-17 19:56:37 -05001048 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04001049 "1307 READ_LA mbox error x%x state x%x\n",
1050 mb->mbxStatus, vport->port_state);
dea31012005-04-17 16:05:31 -05001051 lpfc_mbx_issue_link_down(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001052 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05001053 goto lpfc_mbx_cmpl_read_la_free_mbuf;
1054 }
1055
1056 la = (READ_LA_VAR *) & pmb->mb.un.varReadLA;
1057
1058 memcpy(&phba->alpa_map[0], mp->virt, 128);
1059
James Smart2e0fef82007-06-17 19:56:36 -05001060 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001061 if (la->pb)
James Smart2e0fef82007-06-17 19:56:36 -05001062 vport->fc_flag |= FC_BYPASSED_MODE;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001063 else
James Smart2e0fef82007-06-17 19:56:36 -05001064 vport->fc_flag &= ~FC_BYPASSED_MODE;
1065 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001066
dea31012005-04-17 16:05:31 -05001067 if (((phba->fc_eventTag + 1) < la->eventTag) ||
James Smart92d7f7b2007-06-17 19:56:38 -05001068 (phba->fc_eventTag == la->eventTag)) {
dea31012005-04-17 16:05:31 -05001069 phba->fc_stat.LinkMultiEvent++;
James Smart2e0fef82007-06-17 19:56:36 -05001070 if (la->attType == AT_LINK_UP)
dea31012005-04-17 16:05:31 -05001071 if (phba->fc_eventTag != 0)
1072 lpfc_linkdown(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05001073 }
dea31012005-04-17 16:05:31 -05001074
1075 phba->fc_eventTag = la->eventTag;
1076
1077 if (la->attType == AT_LINK_UP) {
1078 phba->fc_stat.LinkUp++;
James Smart2e0fef82007-06-17 19:56:36 -05001079 if (phba->link_flag & LS_LOOPBACK_MODE) {
James Smart3163f722008-02-08 18:50:25 -05001080 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04001081 "1306 Link Up Event in loop back mode "
1082 "x%x received Data: x%x x%x x%x x%x\n",
1083 la->eventTag, phba->fc_eventTag,
1084 la->granted_AL_PA, la->UlnkSpeed,
1085 phba->alpa_map[0]);
James Smart5b8bd0c2007-04-25 09:52:49 -04001086 } else {
1087 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04001088 "1303 Link Up Event x%x received "
1089 "Data: x%x x%x x%x x%x\n",
1090 la->eventTag, phba->fc_eventTag,
1091 la->granted_AL_PA, la->UlnkSpeed,
1092 phba->alpa_map[0]);
James Smart5b8bd0c2007-04-25 09:52:49 -04001093 }
James Smart92d7f7b2007-06-17 19:56:38 -05001094 lpfc_mbx_process_link_up(phba, la);
dea31012005-04-17 16:05:31 -05001095 } else {
1096 phba->fc_stat.LinkDown++;
James Smart3163f722008-02-08 18:50:25 -05001097 if (phba->link_flag & LS_LOOPBACK_MODE) {
1098 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
1099 "1308 Link Down Event in loop back mode "
1100 "x%x received "
1101 "Data: x%x x%x x%x\n",
1102 la->eventTag, phba->fc_eventTag,
1103 phba->pport->port_state, vport->fc_flag);
1104 }
1105 else {
1106 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04001107 "1305 Link Down Event x%x received "
dea31012005-04-17 16:05:31 -05001108 "Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04001109 la->eventTag, phba->fc_eventTag,
James Smart2e0fef82007-06-17 19:56:36 -05001110 phba->pport->port_state, vport->fc_flag);
James Smart3163f722008-02-08 18:50:25 -05001111 }
dea31012005-04-17 16:05:31 -05001112 lpfc_mbx_issue_link_down(phba);
1113 }
1114
1115lpfc_mbx_cmpl_read_la_free_mbuf:
1116 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1117 kfree(mp);
1118 mempool_free(pmb, phba->mbox_mem_pool);
1119 return;
1120}
1121
1122/*
1123 * This routine handles processing a REG_LOGIN mailbox
1124 * command upon completion. It is setup in the LPFC_MBOXQ
1125 * as the completion routine when the command is
1126 * handed off to the SLI layer.
1127 */
1128void
James Smart2e0fef82007-06-17 19:56:36 -05001129lpfc_mbx_cmpl_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05001130{
James Smart2e0fef82007-06-17 19:56:36 -05001131 struct lpfc_vport *vport = pmb->vport;
James Smart92d7f7b2007-06-17 19:56:38 -05001132 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
James Smart2e0fef82007-06-17 19:56:36 -05001133 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
dea31012005-04-17 16:05:31 -05001134
dea31012005-04-17 16:05:31 -05001135 pmb->context1 = NULL;
1136
1137 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05001138 lpfc_disc_state_machine(vport, ndlp, pmb, NLP_EVT_CMPL_REG_LOGIN);
dea31012005-04-17 16:05:31 -05001139 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1140 kfree(mp);
James Smart2e0fef82007-06-17 19:56:36 -05001141 mempool_free(pmb, phba->mbox_mem_pool);
James Smartfa4066b2008-01-11 01:53:27 -05001142 /* decrement the node reference count held for this callback
1143 * function.
1144 */
James Smart329f9bc2007-04-25 09:53:01 -04001145 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001146
1147 return;
1148}
1149
James Smart92d7f7b2007-06-17 19:56:38 -05001150static void
1151lpfc_mbx_cmpl_unreg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
1152{
1153 MAILBOX_t *mb = &pmb->mb;
1154 struct lpfc_vport *vport = pmb->vport;
1155 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1156
1157 switch (mb->mbxStatus) {
1158 case 0x0011:
1159 case 0x0020:
1160 case 0x9700:
James Smarte8b62012007-08-02 11:10:09 -04001161 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
1162 "0911 cmpl_unreg_vpi, mb status = 0x%x\n",
1163 mb->mbxStatus);
James Smart92d7f7b2007-06-17 19:56:38 -05001164 break;
James Smart92d7f7b2007-06-17 19:56:38 -05001165 }
1166 vport->unreg_vpi_cmpl = VPORT_OK;
1167 mempool_free(pmb, phba->mbox_mem_pool);
1168 /*
1169 * This shost reference might have been taken at the beginning of
1170 * lpfc_vport_delete()
1171 */
1172 if (vport->load_flag & FC_UNLOADING)
1173 scsi_host_put(shost);
1174}
1175
1176void
1177lpfc_mbx_unreg_vpi(struct lpfc_vport *vport)
1178{
1179 struct lpfc_hba *phba = vport->phba;
1180 LPFC_MBOXQ_t *mbox;
1181 int rc;
1182
1183 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1184 if (!mbox)
1185 return;
1186
1187 lpfc_unreg_vpi(phba, vport->vpi, mbox);
1188 mbox->vport = vport;
1189 mbox->mbox_cmpl = lpfc_mbx_cmpl_unreg_vpi;
James Smart0b727fe2007-10-27 13:37:25 -04001190 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart92d7f7b2007-06-17 19:56:38 -05001191 if (rc == MBX_NOT_FINISHED) {
James Smarte8b62012007-08-02 11:10:09 -04001192 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT,
1193 "1800 Could not issue unreg_vpi\n");
James Smart92d7f7b2007-06-17 19:56:38 -05001194 mempool_free(mbox, phba->mbox_mem_pool);
1195 vport->unreg_vpi_cmpl = VPORT_ERROR;
1196 }
1197}
1198
1199static void
1200lpfc_mbx_cmpl_reg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
1201{
1202 struct lpfc_vport *vport = pmb->vport;
1203 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1204 MAILBOX_t *mb = &pmb->mb;
1205
1206 switch (mb->mbxStatus) {
1207 case 0x0011:
1208 case 0x9601:
1209 case 0x9602:
James Smarte8b62012007-08-02 11:10:09 -04001210 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
1211 "0912 cmpl_reg_vpi, mb status = 0x%x\n",
1212 mb->mbxStatus);
James Smart92d7f7b2007-06-17 19:56:38 -05001213 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
1214 spin_lock_irq(shost->host_lock);
1215 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
1216 spin_unlock_irq(shost->host_lock);
1217 vport->fc_myDID = 0;
1218 goto out;
1219 }
James Smart92d7f7b2007-06-17 19:56:38 -05001220
1221 vport->num_disc_nodes = 0;
1222 /* go thru NPR list and issue ELS PLOGIs */
1223 if (vport->fc_npr_cnt)
1224 lpfc_els_disc_plogi(vport);
1225
1226 if (!vport->num_disc_nodes) {
1227 spin_lock_irq(shost->host_lock);
1228 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1229 spin_unlock_irq(shost->host_lock);
1230 lpfc_can_disctmo(vport);
1231 }
1232 vport->port_state = LPFC_VPORT_READY;
1233
1234out:
1235 mempool_free(pmb, phba->mbox_mem_pool);
1236 return;
1237}
1238
dea31012005-04-17 16:05:31 -05001239/*
1240 * This routine handles processing a Fabric REG_LOGIN mailbox
1241 * command upon completion. It is setup in the LPFC_MBOXQ
1242 * as the completion routine when the command is
1243 * handed off to the SLI layer.
1244 */
1245void
James Smart2e0fef82007-06-17 19:56:36 -05001246lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05001247{
James Smart92d7f7b2007-06-17 19:56:38 -05001248 struct lpfc_vport *vport = pmb->vport;
James Smart2e0fef82007-06-17 19:56:36 -05001249 MAILBOX_t *mb = &pmb->mb;
1250 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
James Smart92d7f7b2007-06-17 19:56:38 -05001251 struct lpfc_nodelist *ndlp;
James Smart549e55c2007-08-02 11:09:51 -04001252 struct lpfc_vport **vports;
1253 int i;
dea31012005-04-17 16:05:31 -05001254
James Smart549e55c2007-08-02 11:09:51 -04001255 ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart329f9bc2007-04-25 09:53:01 -04001256 pmb->context1 = NULL;
1257 pmb->context2 = NULL;
dea31012005-04-17 16:05:31 -05001258 if (mb->mbxStatus) {
1259 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1260 kfree(mp);
James Smart329f9bc2007-04-25 09:53:01 -04001261 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05001262
James Smart92d7f7b2007-06-17 19:56:38 -05001263 if (phba->fc_topology == TOPOLOGY_LOOP) {
1264 /* FLOGI failed, use loop map to make discovery list */
1265 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -05001266
James Smart92d7f7b2007-06-17 19:56:38 -05001267 /* Start discovery */
1268 lpfc_disc_start(vport);
James Smarte47c9092008-02-08 18:49:26 -05001269 /* Decrement the reference count to ndlp after the
1270 * reference to the ndlp are done.
1271 */
1272 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05001273 return;
1274 }
1275
1276 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04001277 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
1278 "0258 Register Fabric login error: 0x%x\n",
1279 mb->mbxStatus);
James Smarte47c9092008-02-08 18:49:26 -05001280 /* Decrement the reference count to ndlp after the reference
1281 * to the ndlp are done.
1282 */
1283 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001284 return;
1285 }
1286
dea31012005-04-17 16:05:31 -05001287 ndlp->nlp_rpi = mb->un.varWords[0];
dea31012005-04-17 16:05:31 -05001288 ndlp->nlp_type |= NLP_FABRIC;
James Smart2e0fef82007-06-17 19:56:36 -05001289 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
dea31012005-04-17 16:05:31 -05001290
James Smart2e0fef82007-06-17 19:56:36 -05001291 if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
James Smart549e55c2007-08-02 11:09:51 -04001292 vports = lpfc_create_vport_work_array(phba);
1293 if (vports != NULL)
1294 for(i = 0;
James Smart09372822008-01-11 01:52:54 -05001295 i <= phba->max_vpi && vports[i] != NULL;
James Smart549e55c2007-08-02 11:09:51 -04001296 i++) {
1297 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
1298 continue;
James Smart58da1ff2008-04-07 10:15:56 -04001299 if (phba->fc_topology == TOPOLOGY_LOOP) {
1300 lpfc_vport_set_state(vports[i],
1301 FC_VPORT_LINKDOWN);
1302 continue;
1303 }
James Smart549e55c2007-08-02 11:09:51 -04001304 if (phba->link_flag & LS_NPIV_FAB_SUPPORTED)
1305 lpfc_initial_fdisc(vports[i]);
James Smart58da1ff2008-04-07 10:15:56 -04001306 else {
James Smart549e55c2007-08-02 11:09:51 -04001307 lpfc_vport_set_state(vports[i],
1308 FC_VPORT_NO_FABRIC_SUPP);
James Smarte8b62012007-08-02 11:10:09 -04001309 lpfc_printf_vlog(vport, KERN_ERR,
1310 LOG_ELS,
1311 "0259 No NPIV "
1312 "Fabric support\n");
James Smart549e55c2007-08-02 11:09:51 -04001313 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001314 }
James Smart09372822008-01-11 01:52:54 -05001315 lpfc_destroy_vport_work_array(phba, vports);
James Smart92d7f7b2007-06-17 19:56:38 -05001316 lpfc_do_scr_ns_plogi(phba, vport);
dea31012005-04-17 16:05:31 -05001317 }
1318
1319 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1320 kfree(mp);
James Smart329f9bc2007-04-25 09:53:01 -04001321 mempool_free(pmb, phba->mbox_mem_pool);
James Smarte47c9092008-02-08 18:49:26 -05001322
1323 /* Drop the reference count from the mbox at the end after
1324 * all the current reference to the ndlp have been done.
1325 */
1326 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001327 return;
1328}
1329
1330/*
1331 * This routine handles processing a NameServer REG_LOGIN mailbox
1332 * command upon completion. It is setup in the LPFC_MBOXQ
1333 * as the completion routine when the command is
1334 * handed off to the SLI layer.
1335 */
1336void
James Smart2e0fef82007-06-17 19:56:36 -05001337lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05001338{
James Smart2e0fef82007-06-17 19:56:36 -05001339 MAILBOX_t *mb = &pmb->mb;
1340 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
1341 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
1342 struct lpfc_vport *vport = pmb->vport;
dea31012005-04-17 16:05:31 -05001343
1344 if (mb->mbxStatus) {
James Smart92d7f7b2007-06-17 19:56:38 -05001345out:
James Smartfa4066b2008-01-11 01:53:27 -05001346 /* decrement the node reference count held for this
1347 * callback function.
1348 */
James Smart329f9bc2007-04-25 09:53:01 -04001349 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001350 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1351 kfree(mp);
James Smartde0c5b32007-04-25 09:52:27 -04001352 mempool_free(pmb, phba->mbox_mem_pool);
James Smart87af33f2007-10-27 13:37:43 -04001353
1354 /* If no other thread is using the ndlp, free it */
1355 lpfc_nlp_not_used(ndlp);
dea31012005-04-17 16:05:31 -05001356
James Smart92d7f7b2007-06-17 19:56:38 -05001357 if (phba->fc_topology == TOPOLOGY_LOOP) {
1358 /*
1359 * RegLogin failed, use loop map to make discovery
1360 * list
1361 */
1362 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -05001363
James Smart92d7f7b2007-06-17 19:56:38 -05001364 /* Start discovery */
1365 lpfc_disc_start(vport);
1366 return;
1367 }
1368 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04001369 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1370 "0260 Register NameServer error: 0x%x\n",
1371 mb->mbxStatus);
dea31012005-04-17 16:05:31 -05001372 return;
1373 }
1374
1375 pmb->context1 = NULL;
1376
dea31012005-04-17 16:05:31 -05001377 ndlp->nlp_rpi = mb->un.varWords[0];
dea31012005-04-17 16:05:31 -05001378 ndlp->nlp_type |= NLP_FABRIC;
James Smart2e0fef82007-06-17 19:56:36 -05001379 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
dea31012005-04-17 16:05:31 -05001380
James Smart2e0fef82007-06-17 19:56:36 -05001381 if (vport->port_state < LPFC_VPORT_READY) {
1382 /* Link up discovery requires Fabric registration. */
James Smart92d7f7b2007-06-17 19:56:38 -05001383 lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0, 0); /* Do this first! */
1384 lpfc_ns_cmd(vport, SLI_CTNS_RNN_ID, 0, 0);
1385 lpfc_ns_cmd(vport, SLI_CTNS_RSNN_NN, 0, 0);
1386 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
1387 lpfc_ns_cmd(vport, SLI_CTNS_RFT_ID, 0, 0);
1388
1389 /* Issue SCR just before NameServer GID_FT Query */
1390 lpfc_issue_els_scr(vport, SCR_DID, 0);
dea31012005-04-17 16:05:31 -05001391 }
1392
James Smart2e0fef82007-06-17 19:56:36 -05001393 vport->fc_ns_retry = 0;
dea31012005-04-17 16:05:31 -05001394 /* Good status, issue CT Request to NameServer */
James Smart92d7f7b2007-06-17 19:56:38 -05001395 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0)) {
dea31012005-04-17 16:05:31 -05001396 /* Cannot issue NameServer Query, so finish up discovery */
James Smart92d7f7b2007-06-17 19:56:38 -05001397 goto out;
dea31012005-04-17 16:05:31 -05001398 }
1399
James Smartfa4066b2008-01-11 01:53:27 -05001400 /* decrement the node reference count held for this
1401 * callback function.
1402 */
James Smart329f9bc2007-04-25 09:53:01 -04001403 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001404 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1405 kfree(mp);
James Smart2e0fef82007-06-17 19:56:36 -05001406 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05001407
1408 return;
1409}
1410
1411static void
James Smart2e0fef82007-06-17 19:56:36 -05001412lpfc_register_remote_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05001413{
James Smart2e0fef82007-06-17 19:56:36 -05001414 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1415 struct fc_rport *rport;
dea31012005-04-17 16:05:31 -05001416 struct lpfc_rport_data *rdata;
1417 struct fc_rport_identifiers rport_ids;
James Smart2e0fef82007-06-17 19:56:36 -05001418 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001419
1420 /* Remote port has reappeared. Re-register w/ FC transport */
Andrew Morton68ce1eb2005-09-21 09:46:54 -07001421 rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
1422 rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
dea31012005-04-17 16:05:31 -05001423 rport_ids.port_id = ndlp->nlp_DID;
1424 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
dea31012005-04-17 16:05:31 -05001425
James Smart329f9bc2007-04-25 09:53:01 -04001426 /*
1427 * We leave our node pointer in rport->dd_data when we unregister a
1428 * FCP target port. But fc_remote_port_add zeros the space to which
1429 * rport->dd_data points. So, if we're reusing a previously
1430 * registered port, drop the reference that we took the last time we
1431 * registered the port.
1432 */
1433 if (ndlp->rport && ndlp->rport->dd_data &&
James Smarte47c9092008-02-08 18:49:26 -05001434 ((struct lpfc_rport_data *) ndlp->rport->dd_data)->pnode == ndlp)
James Smart329f9bc2007-04-25 09:53:01 -04001435 lpfc_nlp_put(ndlp);
James Smart858c9f62007-06-17 19:56:39 -05001436
1437 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
1438 "rport add: did:x%x flg:x%x type x%x",
1439 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
1440
James Smart2e0fef82007-06-17 19:56:36 -05001441 ndlp->rport = rport = fc_remote_port_add(shost, 0, &rport_ids);
James Smart329f9bc2007-04-25 09:53:01 -04001442 if (!rport || !get_device(&rport->dev)) {
dea31012005-04-17 16:05:31 -05001443 dev_printk(KERN_WARNING, &phba->pcidev->dev,
1444 "Warning: fc_remote_port_add failed\n");
1445 return;
1446 }
1447
1448 /* initialize static port data */
1449 rport->maxframe_size = ndlp->nlp_maxframe;
1450 rport->supported_classes = ndlp->nlp_class_sup;
dea31012005-04-17 16:05:31 -05001451 rdata = rport->dd_data;
James Smart329f9bc2007-04-25 09:53:01 -04001452 rdata->pnode = lpfc_nlp_get(ndlp);
James.Smart@Emulex.Com23dc04f2005-11-28 11:41:44 -05001453
1454 if (ndlp->nlp_type & NLP_FCP_TARGET)
1455 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
1456 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
1457 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
1458
1459
1460 if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN)
1461 fc_remote_port_rolechg(rport, rport_ids.roles);
1462
James Smart071fbd3d2006-04-15 11:53:20 -04001463 if ((rport->scsi_target_id != -1) &&
James Smart92d7f7b2007-06-17 19:56:38 -05001464 (rport->scsi_target_id < LPFC_MAX_TARGET)) {
James Smart071fbd3d2006-04-15 11:53:20 -04001465 ndlp->nlp_sid = rport->scsi_target_id;
1466 }
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001467 return;
1468}
1469
1470static void
James Smart2e0fef82007-06-17 19:56:36 -05001471lpfc_unregister_remote_port(struct lpfc_nodelist *ndlp)
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001472{
1473 struct fc_rport *rport = ndlp->rport;
James Smartc01f3202006-08-18 17:47:08 -04001474
James Smart858c9f62007-06-17 19:56:39 -05001475 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_RPORT,
1476 "rport delete: did:x%x flg:x%x type x%x",
1477 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
1478
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001479 fc_remote_port_delete(rport);
dea31012005-04-17 16:05:31 -05001480
1481 return;
1482}
1483
James Smartde0c5b32007-04-25 09:52:27 -04001484static void
James Smart2e0fef82007-06-17 19:56:36 -05001485lpfc_nlp_counters(struct lpfc_vport *vport, int state, int count)
James Smartde0c5b32007-04-25 09:52:27 -04001486{
James Smart2e0fef82007-06-17 19:56:36 -05001487 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1488
1489 spin_lock_irq(shost->host_lock);
James Smartde0c5b32007-04-25 09:52:27 -04001490 switch (state) {
1491 case NLP_STE_UNUSED_NODE:
James Smart2e0fef82007-06-17 19:56:36 -05001492 vport->fc_unused_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04001493 break;
1494 case NLP_STE_PLOGI_ISSUE:
James Smart2e0fef82007-06-17 19:56:36 -05001495 vport->fc_plogi_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04001496 break;
1497 case NLP_STE_ADISC_ISSUE:
James Smart2e0fef82007-06-17 19:56:36 -05001498 vport->fc_adisc_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04001499 break;
1500 case NLP_STE_REG_LOGIN_ISSUE:
James Smart2e0fef82007-06-17 19:56:36 -05001501 vport->fc_reglogin_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04001502 break;
1503 case NLP_STE_PRLI_ISSUE:
James Smart2e0fef82007-06-17 19:56:36 -05001504 vport->fc_prli_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04001505 break;
1506 case NLP_STE_UNMAPPED_NODE:
James Smart2e0fef82007-06-17 19:56:36 -05001507 vport->fc_unmap_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04001508 break;
1509 case NLP_STE_MAPPED_NODE:
James Smart2e0fef82007-06-17 19:56:36 -05001510 vport->fc_map_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04001511 break;
1512 case NLP_STE_NPR_NODE:
James Smart2e0fef82007-06-17 19:56:36 -05001513 vport->fc_npr_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04001514 break;
1515 }
James Smart2e0fef82007-06-17 19:56:36 -05001516 spin_unlock_irq(shost->host_lock);
James Smartde0c5b32007-04-25 09:52:27 -04001517}
Jamie Wellnitz66a9ed62006-02-28 22:33:10 -05001518
James Smartde0c5b32007-04-25 09:52:27 -04001519static void
James Smart2e0fef82007-06-17 19:56:36 -05001520lpfc_nlp_state_cleanup(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04001521 int old_state, int new_state)
1522{
James Smart2e0fef82007-06-17 19:56:36 -05001523 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1524
James Smartde0c5b32007-04-25 09:52:27 -04001525 if (new_state == NLP_STE_UNMAPPED_NODE) {
1526 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
1527 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
1528 ndlp->nlp_type |= NLP_FC_NODE;
1529 }
1530 if (new_state == NLP_STE_MAPPED_NODE)
1531 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
1532 if (new_state == NLP_STE_NPR_NODE)
1533 ndlp->nlp_flag &= ~NLP_RCV_PLOGI;
dea31012005-04-17 16:05:31 -05001534
James Smartde0c5b32007-04-25 09:52:27 -04001535 /* Transport interface */
1536 if (ndlp->rport && (old_state == NLP_STE_MAPPED_NODE ||
1537 old_state == NLP_STE_UNMAPPED_NODE)) {
James Smart2e0fef82007-06-17 19:56:36 -05001538 vport->phba->nport_event_cnt++;
1539 lpfc_unregister_remote_port(ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04001540 }
dea31012005-04-17 16:05:31 -05001541
James Smartde0c5b32007-04-25 09:52:27 -04001542 if (new_state == NLP_STE_MAPPED_NODE ||
1543 new_state == NLP_STE_UNMAPPED_NODE) {
James Smart2e0fef82007-06-17 19:56:36 -05001544 vport->phba->nport_event_cnt++;
James Smart858c9f62007-06-17 19:56:39 -05001545 /*
1546 * Tell the fc transport about the port, if we haven't
1547 * already. If we have, and it's a scsi entity, be
1548 * sure to unblock any attached scsi devices
1549 */
1550 lpfc_register_remote_port(vport, ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04001551 }
James Smart858c9f62007-06-17 19:56:39 -05001552 /*
1553 * if we added to Mapped list, but the remote port
1554 * registration failed or assigned a target id outside
1555 * our presentable range - move the node to the
1556 * Unmapped List
1557 */
James Smartde0c5b32007-04-25 09:52:27 -04001558 if (new_state == NLP_STE_MAPPED_NODE &&
1559 (!ndlp->rport ||
1560 ndlp->rport->scsi_target_id == -1 ||
1561 ndlp->rport->scsi_target_id >= LPFC_MAX_TARGET)) {
James Smart2e0fef82007-06-17 19:56:36 -05001562 spin_lock_irq(shost->host_lock);
James Smartde0c5b32007-04-25 09:52:27 -04001563 ndlp->nlp_flag |= NLP_TGT_NO_SCSIID;
James Smart2e0fef82007-06-17 19:56:36 -05001564 spin_unlock_irq(shost->host_lock);
1565 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
dea31012005-04-17 16:05:31 -05001566 }
James Smartde0c5b32007-04-25 09:52:27 -04001567}
1568
James Smart685f0bf2007-04-25 09:53:08 -04001569static char *
1570lpfc_nlp_state_name(char *buffer, size_t size, int state)
1571{
1572 static char *states[] = {
1573 [NLP_STE_UNUSED_NODE] = "UNUSED",
1574 [NLP_STE_PLOGI_ISSUE] = "PLOGI",
1575 [NLP_STE_ADISC_ISSUE] = "ADISC",
1576 [NLP_STE_REG_LOGIN_ISSUE] = "REGLOGIN",
1577 [NLP_STE_PRLI_ISSUE] = "PRLI",
1578 [NLP_STE_UNMAPPED_NODE] = "UNMAPPED",
1579 [NLP_STE_MAPPED_NODE] = "MAPPED",
1580 [NLP_STE_NPR_NODE] = "NPR",
1581 };
1582
James Smart311464e2007-08-02 11:10:37 -04001583 if (state < NLP_STE_MAX_STATE && states[state])
James Smart685f0bf2007-04-25 09:53:08 -04001584 strlcpy(buffer, states[state], size);
1585 else
1586 snprintf(buffer, size, "unknown (%d)", state);
1587 return buffer;
1588}
1589
James Smartde0c5b32007-04-25 09:52:27 -04001590void
James Smart2e0fef82007-06-17 19:56:36 -05001591lpfc_nlp_set_state(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1592 int state)
James Smartde0c5b32007-04-25 09:52:27 -04001593{
James Smart2e0fef82007-06-17 19:56:36 -05001594 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smartde0c5b32007-04-25 09:52:27 -04001595 int old_state = ndlp->nlp_state;
James Smart685f0bf2007-04-25 09:53:08 -04001596 char name1[16], name2[16];
James Smartde0c5b32007-04-25 09:52:27 -04001597
James Smarte8b62012007-08-02 11:10:09 -04001598 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
1599 "0904 NPort state transition x%06x, %s -> %s\n",
1600 ndlp->nlp_DID,
1601 lpfc_nlp_state_name(name1, sizeof(name1), old_state),
1602 lpfc_nlp_state_name(name2, sizeof(name2), state));
James Smart858c9f62007-06-17 19:56:39 -05001603
1604 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
1605 "node statechg did:x%x old:%d ste:%d",
1606 ndlp->nlp_DID, old_state, state);
1607
James Smartde0c5b32007-04-25 09:52:27 -04001608 if (old_state == NLP_STE_NPR_NODE &&
James Smartde0c5b32007-04-25 09:52:27 -04001609 state != NLP_STE_NPR_NODE)
James Smart2e0fef82007-06-17 19:56:36 -05001610 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04001611 if (old_state == NLP_STE_UNMAPPED_NODE) {
1612 ndlp->nlp_flag &= ~NLP_TGT_NO_SCSIID;
1613 ndlp->nlp_type &= ~NLP_FC_NODE;
1614 }
1615
James Smart685f0bf2007-04-25 09:53:08 -04001616 if (list_empty(&ndlp->nlp_listp)) {
James Smart2e0fef82007-06-17 19:56:36 -05001617 spin_lock_irq(shost->host_lock);
1618 list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
1619 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04001620 } else if (old_state)
James Smart2e0fef82007-06-17 19:56:36 -05001621 lpfc_nlp_counters(vport, old_state, -1);
James Smartde0c5b32007-04-25 09:52:27 -04001622
1623 ndlp->nlp_state = state;
James Smart2e0fef82007-06-17 19:56:36 -05001624 lpfc_nlp_counters(vport, state, 1);
1625 lpfc_nlp_state_cleanup(vport, ndlp, old_state, state);
James Smartde0c5b32007-04-25 09:52:27 -04001626}
1627
1628void
James Smarte47c9092008-02-08 18:49:26 -05001629lpfc_enqueue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
1630{
1631 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1632
1633 if (list_empty(&ndlp->nlp_listp)) {
1634 spin_lock_irq(shost->host_lock);
1635 list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
1636 spin_unlock_irq(shost->host_lock);
1637 }
1638}
1639
1640void
James Smart2e0fef82007-06-17 19:56:36 -05001641lpfc_dequeue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
James Smartde0c5b32007-04-25 09:52:27 -04001642{
James Smart2e0fef82007-06-17 19:56:36 -05001643 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1644
James Smart0d2b6b82008-06-14 22:52:47 -04001645 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04001646 if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
James Smart2e0fef82007-06-17 19:56:36 -05001647 lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
1648 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04001649 list_del_init(&ndlp->nlp_listp);
James Smart2e0fef82007-06-17 19:56:36 -05001650 spin_unlock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05001651 lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state,
James Smarte47c9092008-02-08 18:49:26 -05001652 NLP_STE_UNUSED_NODE);
1653}
1654
Adrian Bunk4d9db012008-02-14 23:24:02 +02001655static void
James Smarte47c9092008-02-08 18:49:26 -05001656lpfc_disable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
1657{
James Smart0d2b6b82008-06-14 22:52:47 -04001658 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smarte47c9092008-02-08 18:49:26 -05001659 if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
1660 lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
1661 lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state,
1662 NLP_STE_UNUSED_NODE);
1663}
1664
1665struct lpfc_nodelist *
1666lpfc_enable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1667 int state)
1668{
1669 struct lpfc_hba *phba = vport->phba;
1670 uint32_t did;
1671 unsigned long flags;
1672
1673 if (!ndlp)
1674 return NULL;
1675
1676 spin_lock_irqsave(&phba->ndlp_lock, flags);
1677 /* The ndlp should not be in memory free mode */
1678 if (NLP_CHK_FREE_REQ(ndlp)) {
1679 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
1680 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
1681 "0277 lpfc_enable_node: ndlp:x%p "
1682 "usgmap:x%x refcnt:%d\n",
1683 (void *)ndlp, ndlp->nlp_usg_map,
1684 atomic_read(&ndlp->kref.refcount));
1685 return NULL;
1686 }
1687 /* The ndlp should not already be in active mode */
1688 if (NLP_CHK_NODE_ACT(ndlp)) {
1689 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
1690 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
1691 "0278 lpfc_enable_node: ndlp:x%p "
1692 "usgmap:x%x refcnt:%d\n",
1693 (void *)ndlp, ndlp->nlp_usg_map,
1694 atomic_read(&ndlp->kref.refcount));
1695 return NULL;
1696 }
1697
1698 /* Keep the original DID */
1699 did = ndlp->nlp_DID;
1700
1701 /* re-initialize ndlp except of ndlp linked list pointer */
1702 memset((((char *)ndlp) + sizeof (struct list_head)), 0,
1703 sizeof (struct lpfc_nodelist) - sizeof (struct list_head));
1704 INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp);
1705 INIT_LIST_HEAD(&ndlp->dev_loss_evt.evt_listp);
1706 init_timer(&ndlp->nlp_delayfunc);
1707 ndlp->nlp_delayfunc.function = lpfc_els_retry_delay;
1708 ndlp->nlp_delayfunc.data = (unsigned long)ndlp;
1709 ndlp->nlp_DID = did;
1710 ndlp->vport = vport;
1711 ndlp->nlp_sid = NLP_NO_SID;
1712 /* ndlp management re-initialize */
1713 kref_init(&ndlp->kref);
1714 NLP_INT_NODE_ACT(ndlp);
1715
1716 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
1717
1718 if (state != NLP_STE_UNUSED_NODE)
1719 lpfc_nlp_set_state(vport, ndlp, state);
1720
1721 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
1722 "node enable: did:x%x",
1723 ndlp->nlp_DID, 0, 0);
1724 return ndlp;
James Smartde0c5b32007-04-25 09:52:27 -04001725}
1726
1727void
James Smart2e0fef82007-06-17 19:56:36 -05001728lpfc_drop_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
James Smartde0c5b32007-04-25 09:52:27 -04001729{
James Smart87af33f2007-10-27 13:37:43 -04001730 /*
James Smartfa4066b2008-01-11 01:53:27 -05001731 * Use of lpfc_drop_node and UNUSED list: lpfc_drop_node should
James Smart87af33f2007-10-27 13:37:43 -04001732 * be used if we wish to issue the "last" lpfc_nlp_put() to remove
James Smartfa4066b2008-01-11 01:53:27 -05001733 * the ndlp from the vport. The ndlp marked as UNUSED on the list
1734 * until ALL other outstanding threads have completed. We check
1735 * that the ndlp not already in the UNUSED state before we proceed.
James Smart87af33f2007-10-27 13:37:43 -04001736 */
James Smartfa4066b2008-01-11 01:53:27 -05001737 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
1738 return;
James Smart51ef4c22007-08-02 11:10:31 -04001739 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE);
James Smart87af33f2007-10-27 13:37:43 -04001740 lpfc_nlp_put(ndlp);
James Smart98c9ea52007-10-27 13:37:33 -04001741 return;
dea31012005-04-17 16:05:31 -05001742}
1743
1744/*
1745 * Start / ReStart rescue timer for Discovery / RSCN handling
1746 */
1747void
James Smart2e0fef82007-06-17 19:56:36 -05001748lpfc_set_disctmo(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001749{
James Smart2e0fef82007-06-17 19:56:36 -05001750 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1751 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001752 uint32_t tmo;
1753
James Smart2e0fef82007-06-17 19:56:36 -05001754 if (vport->port_state == LPFC_LOCAL_CFG_LINK) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001755 /* For FAN, timeout should be greater then edtov */
1756 tmo = (((phba->fc_edtov + 999) / 1000) + 1);
1757 } else {
1758 /* Normal discovery timeout should be > then ELS/CT timeout
1759 * FC spec states we need 3 * ratov for CT requests
1760 */
1761 tmo = ((phba->fc_ratov * 3) + 3);
1762 }
dea31012005-04-17 16:05:31 -05001763
James Smart858c9f62007-06-17 19:56:39 -05001764
1765 if (!timer_pending(&vport->fc_disctmo)) {
1766 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1767 "set disc timer: tmo:x%x state:x%x flg:x%x",
1768 tmo, vport->port_state, vport->fc_flag);
1769 }
1770
James Smart2e0fef82007-06-17 19:56:36 -05001771 mod_timer(&vport->fc_disctmo, jiffies + HZ * tmo);
1772 spin_lock_irq(shost->host_lock);
1773 vport->fc_flag |= FC_DISC_TMO;
1774 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001775
1776 /* Start Discovery Timer state <hba_state> */
James Smarte8b62012007-08-02 11:10:09 -04001777 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1778 "0247 Start Discovery Timer state x%x "
1779 "Data: x%x x%lx x%x x%x\n",
1780 vport->port_state, tmo,
1781 (unsigned long)&vport->fc_disctmo, vport->fc_plogi_cnt,
1782 vport->fc_adisc_cnt);
dea31012005-04-17 16:05:31 -05001783
1784 return;
1785}
1786
1787/*
1788 * Cancel rescue timer for Discovery / RSCN handling
1789 */
1790int
James Smart2e0fef82007-06-17 19:56:36 -05001791lpfc_can_disctmo(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001792{
James Smart2e0fef82007-06-17 19:56:36 -05001793 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05001794 unsigned long iflags;
1795
James Smart858c9f62007-06-17 19:56:39 -05001796 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1797 "can disc timer: state:x%x rtry:x%x flg:x%x",
1798 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
1799
dea31012005-04-17 16:05:31 -05001800 /* Turn off discovery timer if its running */
James Smart2e0fef82007-06-17 19:56:36 -05001801 if (vport->fc_flag & FC_DISC_TMO) {
1802 spin_lock_irqsave(shost->host_lock, iflags);
1803 vport->fc_flag &= ~FC_DISC_TMO;
1804 spin_unlock_irqrestore(shost->host_lock, iflags);
1805 del_timer_sync(&vport->fc_disctmo);
1806 spin_lock_irqsave(&vport->work_port_lock, iflags);
1807 vport->work_port_events &= ~WORKER_DISC_TMO;
1808 spin_unlock_irqrestore(&vport->work_port_lock, iflags);
dea31012005-04-17 16:05:31 -05001809 }
1810
1811 /* Cancel Discovery Timer state <hba_state> */
James Smarte8b62012007-08-02 11:10:09 -04001812 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1813 "0248 Cancel Discovery Timer state x%x "
1814 "Data: x%x x%x x%x\n",
1815 vport->port_state, vport->fc_flag,
1816 vport->fc_plogi_cnt, vport->fc_adisc_cnt);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001817 return 0;
dea31012005-04-17 16:05:31 -05001818}
1819
1820/*
1821 * Check specified ring for outstanding IOCB on the SLI queue
1822 * Return true if iocb matches the specified nport
1823 */
1824int
James Smart2e0fef82007-06-17 19:56:36 -05001825lpfc_check_sli_ndlp(struct lpfc_hba *phba,
1826 struct lpfc_sli_ring *pring,
1827 struct lpfc_iocbq *iocb,
1828 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05001829{
James Smart2e0fef82007-06-17 19:56:36 -05001830 struct lpfc_sli *psli = &phba->sli;
1831 IOCB_t *icmd = &iocb->iocb;
James Smart92d7f7b2007-06-17 19:56:38 -05001832 struct lpfc_vport *vport = ndlp->vport;
1833
1834 if (iocb->vport != vport)
1835 return 0;
1836
dea31012005-04-17 16:05:31 -05001837 if (pring->ringno == LPFC_ELS_RING) {
1838 switch (icmd->ulpCommand) {
1839 case CMD_GEN_REQUEST64_CR:
1840 if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001841 return 1;
dea31012005-04-17 16:05:31 -05001842 case CMD_ELS_REQUEST64_CR:
James Smart10d4e952006-04-15 11:53:15 -04001843 if (icmd->un.elsreq64.remoteID == ndlp->nlp_DID)
1844 return 1;
dea31012005-04-17 16:05:31 -05001845 case CMD_XMIT_ELS_RSP64_CX:
1846 if (iocb->context1 == (uint8_t *) ndlp)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001847 return 1;
dea31012005-04-17 16:05:31 -05001848 }
James Smarta4bc3372006-12-02 13:34:16 -05001849 } else if (pring->ringno == psli->extra_ring) {
dea31012005-04-17 16:05:31 -05001850
1851 } else if (pring->ringno == psli->fcp_ring) {
1852 /* Skip match check if waiting to relogin to FCP target */
1853 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
James Smart92d7f7b2007-06-17 19:56:38 -05001854 (ndlp->nlp_flag & NLP_DELAY_TMO)) {
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001855 return 0;
dea31012005-04-17 16:05:31 -05001856 }
1857 if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) {
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001858 return 1;
dea31012005-04-17 16:05:31 -05001859 }
1860 } else if (pring->ringno == psli->next_ring) {
1861
1862 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001863 return 0;
dea31012005-04-17 16:05:31 -05001864}
1865
1866/*
1867 * Free resources / clean up outstanding I/Os
1868 * associated with nlp_rpi in the LPFC_NODELIST entry.
1869 */
1870static int
James Smart2e0fef82007-06-17 19:56:36 -05001871lpfc_no_rpi(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05001872{
James Smart2534ba72007-04-25 09:52:20 -04001873 LIST_HEAD(completions);
dea31012005-04-17 16:05:31 -05001874 struct lpfc_sli *psli;
1875 struct lpfc_sli_ring *pring;
1876 struct lpfc_iocbq *iocb, *next_iocb;
1877 IOCB_t *icmd;
1878 uint32_t rpi, i;
1879
James Smart92d7f7b2007-06-17 19:56:38 -05001880 lpfc_fabric_abort_nport(ndlp);
1881
dea31012005-04-17 16:05:31 -05001882 /*
1883 * Everything that matches on txcmplq will be returned
1884 * by firmware with a no rpi error.
1885 */
1886 psli = &phba->sli;
1887 rpi = ndlp->nlp_rpi;
1888 if (rpi) {
1889 /* Now process each ring */
1890 for (i = 0; i < psli->num_rings; i++) {
1891 pring = &psli->ring[i];
1892
James Smart2e0fef82007-06-17 19:56:36 -05001893 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001894 list_for_each_entry_safe(iocb, next_iocb, &pring->txq,
James Smart2e0fef82007-06-17 19:56:36 -05001895 list) {
dea31012005-04-17 16:05:31 -05001896 /*
1897 * Check to see if iocb matches the nport we are
1898 * looking for
1899 */
James Smart92d7f7b2007-06-17 19:56:38 -05001900 if ((lpfc_check_sli_ndlp(phba, pring, iocb,
1901 ndlp))) {
dea31012005-04-17 16:05:31 -05001902 /* It matches, so deque and call compl
1903 with an error */
James Smart2534ba72007-04-25 09:52:20 -04001904 list_move_tail(&iocb->list,
1905 &completions);
dea31012005-04-17 16:05:31 -05001906 pring->txq_cnt--;
dea31012005-04-17 16:05:31 -05001907 }
1908 }
James Smart2e0fef82007-06-17 19:56:36 -05001909 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001910 }
1911 }
James Smart2534ba72007-04-25 09:52:20 -04001912
1913 while (!list_empty(&completions)) {
1914 iocb = list_get_first(&completions, struct lpfc_iocbq, list);
James Smart92d7f7b2007-06-17 19:56:38 -05001915 list_del_init(&iocb->list);
James Smart2534ba72007-04-25 09:52:20 -04001916
James Smart2e0fef82007-06-17 19:56:36 -05001917 if (!iocb->iocb_cmpl)
1918 lpfc_sli_release_iocbq(phba, iocb);
1919 else {
James Smart2534ba72007-04-25 09:52:20 -04001920 icmd = &iocb->iocb;
1921 icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
1922 icmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
James Smart2e0fef82007-06-17 19:56:36 -05001923 (iocb->iocb_cmpl)(phba, iocb, iocb);
1924 }
James Smart2534ba72007-04-25 09:52:20 -04001925 }
1926
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001927 return 0;
dea31012005-04-17 16:05:31 -05001928}
1929
1930/*
1931 * Free rpi associated with LPFC_NODELIST entry.
1932 * This routine is called from lpfc_freenode(), when we are removing
1933 * a LPFC_NODELIST entry. It is also called if the driver initiates a
1934 * LOGO that completes successfully, and we are waiting to PLOGI back
1935 * to the remote NPort. In addition, it is called after we receive
1936 * and unsolicated ELS cmd, send back a rsp, the rsp completes and
1937 * we are waiting to PLOGI back to the remote NPort.
1938 */
1939int
James Smart2e0fef82007-06-17 19:56:36 -05001940lpfc_unreg_rpi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05001941{
James Smart2e0fef82007-06-17 19:56:36 -05001942 struct lpfc_hba *phba = vport->phba;
1943 LPFC_MBOXQ_t *mbox;
dea31012005-04-17 16:05:31 -05001944 int rc;
1945
1946 if (ndlp->nlp_rpi) {
James Smart2e0fef82007-06-17 19:56:36 -05001947 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1948 if (mbox) {
James Smart92d7f7b2007-06-17 19:56:38 -05001949 lpfc_unreg_login(phba, vport->vpi, ndlp->nlp_rpi, mbox);
James Smarted957682007-06-17 19:56:37 -05001950 mbox->vport = vport;
James Smart92d7f7b2007-06-17 19:56:38 -05001951 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart0b727fe2007-10-27 13:37:25 -04001952 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -05001953 if (rc == MBX_NOT_FINISHED)
James Smart2e0fef82007-06-17 19:56:36 -05001954 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05001955 }
dea31012005-04-17 16:05:31 -05001956 lpfc_no_rpi(phba, ndlp);
1957 ndlp->nlp_rpi = 0;
1958 return 1;
1959 }
1960 return 0;
1961}
1962
James Smart92d7f7b2007-06-17 19:56:38 -05001963void
1964lpfc_unreg_all_rpis(struct lpfc_vport *vport)
1965{
1966 struct lpfc_hba *phba = vport->phba;
1967 LPFC_MBOXQ_t *mbox;
1968 int rc;
1969
1970 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1971 if (mbox) {
1972 lpfc_unreg_login(phba, vport->vpi, 0xffff, mbox);
1973 mbox->vport = vport;
1974 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart09372822008-01-11 01:52:54 -05001975 mbox->context1 = NULL;
1976 rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
James Smart92d7f7b2007-06-17 19:56:38 -05001977 if (rc == MBX_NOT_FINISHED) {
1978 mempool_free(mbox, phba->mbox_mem_pool);
1979 }
1980 }
1981}
1982
1983void
1984lpfc_unreg_default_rpis(struct lpfc_vport *vport)
1985{
1986 struct lpfc_hba *phba = vport->phba;
1987 LPFC_MBOXQ_t *mbox;
1988 int rc;
1989
1990 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1991 if (mbox) {
1992 lpfc_unreg_did(phba, vport->vpi, 0xffffffff, mbox);
1993 mbox->vport = vport;
1994 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart09372822008-01-11 01:52:54 -05001995 mbox->context1 = NULL;
1996 rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
James Smart92d7f7b2007-06-17 19:56:38 -05001997 if (rc == MBX_NOT_FINISHED) {
James Smarte8b62012007-08-02 11:10:09 -04001998 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT,
1999 "1815 Could not issue "
2000 "unreg_did (default rpis)\n");
James Smart92d7f7b2007-06-17 19:56:38 -05002001 mempool_free(mbox, phba->mbox_mem_pool);
2002 }
2003 }
2004}
2005
dea31012005-04-17 16:05:31 -05002006/*
2007 * Free resources associated with LPFC_NODELIST entry
2008 * so it can be freed.
2009 */
2010static int
James Smart2e0fef82007-06-17 19:56:36 -05002011lpfc_cleanup_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05002012{
James Smart2e0fef82007-06-17 19:56:36 -05002013 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2014 struct lpfc_hba *phba = vport->phba;
2015 LPFC_MBOXQ_t *mb, *nextmb;
dea31012005-04-17 16:05:31 -05002016 struct lpfc_dmabuf *mp;
dea31012005-04-17 16:05:31 -05002017
2018 /* Cleanup node for NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002019 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
2020 "0900 Cleanup node for NPort x%x "
2021 "Data: x%x x%x x%x\n",
2022 ndlp->nlp_DID, ndlp->nlp_flag,
2023 ndlp->nlp_state, ndlp->nlp_rpi);
James Smarte47c9092008-02-08 18:49:26 -05002024 if (NLP_CHK_FREE_REQ(ndlp)) {
2025 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
2026 "0280 lpfc_cleanup_node: ndlp:x%p "
2027 "usgmap:x%x refcnt:%d\n",
2028 (void *)ndlp, ndlp->nlp_usg_map,
2029 atomic_read(&ndlp->kref.refcount));
2030 lpfc_dequeue_node(vport, ndlp);
2031 } else {
2032 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
2033 "0281 lpfc_cleanup_node: ndlp:x%p "
2034 "usgmap:x%x refcnt:%d\n",
2035 (void *)ndlp, ndlp->nlp_usg_map,
2036 atomic_read(&ndlp->kref.refcount));
2037 lpfc_disable_node(vport, ndlp);
2038 }
dea31012005-04-17 16:05:31 -05002039
dea31012005-04-17 16:05:31 -05002040 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
2041 if ((mb = phba->sli.mbox_active)) {
2042 if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
2043 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
2044 mb->context2 = NULL;
2045 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
2046 }
2047 }
James Smart33ccf8d2006-08-17 11:57:58 -04002048
James Smart2e0fef82007-06-17 19:56:36 -05002049 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002050 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
2051 if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
James Smart92d7f7b2007-06-17 19:56:38 -05002052 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
dea31012005-04-17 16:05:31 -05002053 mp = (struct lpfc_dmabuf *) (mb->context1);
2054 if (mp) {
James Smart2e0fef82007-06-17 19:56:36 -05002055 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
dea31012005-04-17 16:05:31 -05002056 kfree(mp);
2057 }
2058 list_del(&mb->list);
2059 mempool_free(mb, phba->mbox_mem_pool);
James Smarte47c9092008-02-08 18:49:26 -05002060 /* We shall not invoke the lpfc_nlp_put to decrement
2061 * the ndlp reference count as we are in the process
2062 * of lpfc_nlp_release.
2063 */
dea31012005-04-17 16:05:31 -05002064 }
2065 }
James Smart2e0fef82007-06-17 19:56:36 -05002066 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002067
James Smarte47c9092008-02-08 18:49:26 -05002068 lpfc_els_abort(phba, ndlp);
2069
James Smart2e0fef82007-06-17 19:56:36 -05002070 spin_lock_irq(shost->host_lock);
James Smartc01f3202006-08-18 17:47:08 -04002071 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002072 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002073
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002074 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05002075 del_timer_sync(&ndlp->nlp_delayfunc);
2076
James Smart0d2b6b82008-06-14 22:52:47 -04002077 list_del_init(&ndlp->els_retry_evt.evt_listp);
2078 list_del_init(&ndlp->dev_loss_evt.evt_listp);
dea31012005-04-17 16:05:31 -05002079
James Smart2e0fef82007-06-17 19:56:36 -05002080 lpfc_unreg_rpi(vport, ndlp);
dea31012005-04-17 16:05:31 -05002081
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002082 return 0;
dea31012005-04-17 16:05:31 -05002083}
2084
2085/*
2086 * Check to see if we can free the nlp back to the freelist.
2087 * If we are in the middle of using the nlp in the discovery state
2088 * machine, defer the free till we reach the end of the state machine.
2089 */
James Smart329f9bc2007-04-25 09:53:01 -04002090static void
James Smart2e0fef82007-06-17 19:56:36 -05002091lpfc_nlp_remove(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05002092{
James Smarta8adb832007-10-27 13:37:53 -04002093 struct lpfc_hba *phba = vport->phba;
James Smart1dcb58e2007-04-25 09:51:30 -04002094 struct lpfc_rport_data *rdata;
James Smarta8adb832007-10-27 13:37:53 -04002095 LPFC_MBOXQ_t *mbox;
2096 int rc;
dea31012005-04-17 16:05:31 -05002097
James Smart0d2b6b82008-06-14 22:52:47 -04002098 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smarta8adb832007-10-27 13:37:53 -04002099 if (ndlp->nlp_flag & NLP_DEFER_RM && !ndlp->nlp_rpi) {
2100 /* For this case we need to cleanup the default rpi
2101 * allocated by the firmware.
2102 */
2103 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))
2104 != NULL) {
2105 rc = lpfc_reg_login(phba, vport->vpi, ndlp->nlp_DID,
2106 (uint8_t *) &vport->fc_sparam, mbox, 0);
2107 if (rc) {
2108 mempool_free(mbox, phba->mbox_mem_pool);
2109 }
2110 else {
2111 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
2112 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
2113 mbox->vport = vport;
James Smart09372822008-01-11 01:52:54 -05002114 mbox->context2 = NULL;
James Smarta8adb832007-10-27 13:37:53 -04002115 rc =lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
2116 if (rc == MBX_NOT_FINISHED) {
2117 mempool_free(mbox, phba->mbox_mem_pool);
2118 }
2119 }
2120 }
2121 }
James Smart2e0fef82007-06-17 19:56:36 -05002122 lpfc_cleanup_node(vport, ndlp);
James Smart1dcb58e2007-04-25 09:51:30 -04002123
James Smart2e0fef82007-06-17 19:56:36 -05002124 /*
James Smart92d7f7b2007-06-17 19:56:38 -05002125 * We can get here with a non-NULL ndlp->rport because when we
2126 * unregister a rport we don't break the rport/node linkage. So if we
2127 * do, make sure we don't leaving any dangling pointers behind.
James Smart2e0fef82007-06-17 19:56:36 -05002128 */
James Smart92d7f7b2007-06-17 19:56:38 -05002129 if (ndlp->rport) {
James Smart329f9bc2007-04-25 09:53:01 -04002130 rdata = ndlp->rport->dd_data;
2131 rdata->pnode = NULL;
2132 ndlp->rport = NULL;
dea31012005-04-17 16:05:31 -05002133 }
dea31012005-04-17 16:05:31 -05002134}
2135
2136static int
James Smart2e0fef82007-06-17 19:56:36 -05002137lpfc_matchdid(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2138 uint32_t did)
dea31012005-04-17 16:05:31 -05002139{
James Smart2e0fef82007-06-17 19:56:36 -05002140 D_ID mydid, ndlpdid, matchdid;
dea31012005-04-17 16:05:31 -05002141
2142 if (did == Bcast_DID)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002143 return 0;
dea31012005-04-17 16:05:31 -05002144
dea31012005-04-17 16:05:31 -05002145 /* First check for Direct match */
2146 if (ndlp->nlp_DID == did)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002147 return 1;
dea31012005-04-17 16:05:31 -05002148
2149 /* Next check for area/domain identically equals 0 match */
James Smart2e0fef82007-06-17 19:56:36 -05002150 mydid.un.word = vport->fc_myDID;
dea31012005-04-17 16:05:31 -05002151 if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) {
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002152 return 0;
dea31012005-04-17 16:05:31 -05002153 }
2154
2155 matchdid.un.word = did;
2156 ndlpdid.un.word = ndlp->nlp_DID;
2157 if (matchdid.un.b.id == ndlpdid.un.b.id) {
2158 if ((mydid.un.b.domain == matchdid.un.b.domain) &&
2159 (mydid.un.b.area == matchdid.un.b.area)) {
2160 if ((ndlpdid.un.b.domain == 0) &&
2161 (ndlpdid.un.b.area == 0)) {
2162 if (ndlpdid.un.b.id)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002163 return 1;
dea31012005-04-17 16:05:31 -05002164 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002165 return 0;
dea31012005-04-17 16:05:31 -05002166 }
2167
2168 matchdid.un.word = ndlp->nlp_DID;
2169 if ((mydid.un.b.domain == ndlpdid.un.b.domain) &&
2170 (mydid.un.b.area == ndlpdid.un.b.area)) {
2171 if ((matchdid.un.b.domain == 0) &&
2172 (matchdid.un.b.area == 0)) {
2173 if (matchdid.un.b.id)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002174 return 1;
dea31012005-04-17 16:05:31 -05002175 }
2176 }
2177 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002178 return 0;
dea31012005-04-17 16:05:31 -05002179}
2180
James Smart685f0bf2007-04-25 09:53:08 -04002181/* Search for a nodelist entry */
James Smart2e0fef82007-06-17 19:56:36 -05002182static struct lpfc_nodelist *
2183__lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05002184{
James Smart2fb9bd82006-12-02 13:33:57 -05002185 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05002186 uint32_t data1;
2187
James Smart2e0fef82007-06-17 19:56:36 -05002188 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
2189 if (lpfc_matchdid(vport, ndlp, did)) {
James Smart685f0bf2007-04-25 09:53:08 -04002190 data1 = (((uint32_t) ndlp->nlp_state << 24) |
2191 ((uint32_t) ndlp->nlp_xri << 16) |
2192 ((uint32_t) ndlp->nlp_type << 8) |
2193 ((uint32_t) ndlp->nlp_rpi & 0xff));
James Smarte8b62012007-08-02 11:10:09 -04002194 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
2195 "0929 FIND node DID "
2196 "Data: x%p x%x x%x x%x\n",
2197 ndlp, ndlp->nlp_DID,
2198 ndlp->nlp_flag, data1);
James Smart685f0bf2007-04-25 09:53:08 -04002199 return ndlp;
dea31012005-04-17 16:05:31 -05002200 }
2201 }
Jamie Wellnitz66a9ed62006-02-28 22:33:10 -05002202
dea31012005-04-17 16:05:31 -05002203 /* FIND node did <did> NOT FOUND */
James Smarte8b62012007-08-02 11:10:09 -04002204 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
2205 "0932 FIND node did x%x NOT FOUND.\n", did);
dea31012005-04-17 16:05:31 -05002206 return NULL;
2207}
2208
2209struct lpfc_nodelist *
James Smart2e0fef82007-06-17 19:56:36 -05002210lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05002211{
James Smart2e0fef82007-06-17 19:56:36 -05002212 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002213 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05002214
James Smart2e0fef82007-06-17 19:56:36 -05002215 spin_lock_irq(shost->host_lock);
2216 ndlp = __lpfc_findnode_did(vport, did);
2217 spin_unlock_irq(shost->host_lock);
2218 return ndlp;
2219}
2220
2221struct lpfc_nodelist *
2222lpfc_setup_disc_node(struct lpfc_vport *vport, uint32_t did)
2223{
2224 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2225 struct lpfc_nodelist *ndlp;
2226
2227 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002228 if (!ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05002229 if ((vport->fc_flag & FC_RSCN_MODE) != 0 &&
2230 lpfc_rscn_payload_check(vport, did) == 0)
dea31012005-04-17 16:05:31 -05002231 return NULL;
2232 ndlp = (struct lpfc_nodelist *)
James Smart2e0fef82007-06-17 19:56:36 -05002233 mempool_alloc(vport->phba->nlp_mem_pool, GFP_KERNEL);
dea31012005-04-17 16:05:31 -05002234 if (!ndlp)
2235 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05002236 lpfc_nlp_init(vport, ndlp, did);
2237 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2238 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002239 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002240 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002241 return ndlp;
James Smarte47c9092008-02-08 18:49:26 -05002242 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2243 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_NPR_NODE);
2244 if (!ndlp)
2245 return NULL;
2246 spin_lock_irq(shost->host_lock);
2247 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2248 spin_unlock_irq(shost->host_lock);
2249 return ndlp;
dea31012005-04-17 16:05:31 -05002250 }
James Smarte47c9092008-02-08 18:49:26 -05002251
James Smart58da1ff2008-04-07 10:15:56 -04002252 if ((vport->fc_flag & FC_RSCN_MODE) &&
2253 !(vport->fc_flag & FC_NDISC_ACTIVE)) {
James Smart2e0fef82007-06-17 19:56:36 -05002254 if (lpfc_rscn_payload_check(vport, did)) {
James Smart87af33f2007-10-27 13:37:43 -04002255 /* If we've already recieved a PLOGI from this NPort
2256 * we don't need to try to discover it again.
2257 */
2258 if (ndlp->nlp_flag & NLP_RCV_PLOGI)
2259 return NULL;
2260
James Smart2e0fef82007-06-17 19:56:36 -05002261 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002262 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002263 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002264
2265 /* Since this node is marked for discovery,
2266 * delay timeout is not needed.
2267 */
James Smart0d2b6b82008-06-14 22:52:47 -04002268 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smart071fbd3d2006-04-15 11:53:20 -04002269 } else
dea31012005-04-17 16:05:31 -05002270 ndlp = NULL;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002271 } else {
James Smart87af33f2007-10-27 13:37:43 -04002272 /* If we've already recieved a PLOGI from this NPort,
2273 * or we are already in the process of discovery on it,
2274 * we don't need to try to discover it again.
2275 */
James Smart685f0bf2007-04-25 09:53:08 -04002276 if (ndlp->nlp_state == NLP_STE_ADISC_ISSUE ||
James Smart87af33f2007-10-27 13:37:43 -04002277 ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
2278 ndlp->nlp_flag & NLP_RCV_PLOGI)
dea31012005-04-17 16:05:31 -05002279 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05002280 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2281 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002282 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002283 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002284 }
2285 return ndlp;
2286}
2287
2288/* Build a list of nodes to discover based on the loopmap */
2289void
James Smart2e0fef82007-06-17 19:56:36 -05002290lpfc_disc_list_loopmap(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002291{
James Smart2e0fef82007-06-17 19:56:36 -05002292 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002293 int j;
2294 uint32_t alpa, index;
2295
James Smart2e0fef82007-06-17 19:56:36 -05002296 if (!lpfc_is_link_up(phba))
dea31012005-04-17 16:05:31 -05002297 return;
James Smart2e0fef82007-06-17 19:56:36 -05002298
2299 if (phba->fc_topology != TOPOLOGY_LOOP)
dea31012005-04-17 16:05:31 -05002300 return;
dea31012005-04-17 16:05:31 -05002301
2302 /* Check for loop map present or not */
2303 if (phba->alpa_map[0]) {
2304 for (j = 1; j <= phba->alpa_map[0]; j++) {
2305 alpa = phba->alpa_map[j];
James Smart2e0fef82007-06-17 19:56:36 -05002306 if (((vport->fc_myDID & 0xff) == alpa) || (alpa == 0))
dea31012005-04-17 16:05:31 -05002307 continue;
James Smart2e0fef82007-06-17 19:56:36 -05002308 lpfc_setup_disc_node(vport, alpa);
dea31012005-04-17 16:05:31 -05002309 }
2310 } else {
2311 /* No alpamap, so try all alpa's */
2312 for (j = 0; j < FC_MAXLOOP; j++) {
2313 /* If cfg_scan_down is set, start from highest
2314 * ALPA (0xef) to lowest (0x1).
2315 */
James Smart3de2a652007-08-02 11:09:59 -04002316 if (vport->cfg_scan_down)
dea31012005-04-17 16:05:31 -05002317 index = j;
2318 else
2319 index = FC_MAXLOOP - j - 1;
2320 alpa = lpfcAlpaArray[index];
James Smart2e0fef82007-06-17 19:56:36 -05002321 if ((vport->fc_myDID & 0xff) == alpa)
dea31012005-04-17 16:05:31 -05002322 continue;
James Smart2e0fef82007-06-17 19:56:36 -05002323 lpfc_setup_disc_node(vport, alpa);
dea31012005-04-17 16:05:31 -05002324 }
2325 }
2326 return;
2327}
2328
dea31012005-04-17 16:05:31 -05002329void
James Smart2e0fef82007-06-17 19:56:36 -05002330lpfc_issue_clear_la(struct lpfc_hba *phba, struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002331{
dea31012005-04-17 16:05:31 -05002332 LPFC_MBOXQ_t *mbox;
James Smart2e0fef82007-06-17 19:56:36 -05002333 struct lpfc_sli *psli = &phba->sli;
2334 struct lpfc_sli_ring *extra_ring = &psli->ring[psli->extra_ring];
2335 struct lpfc_sli_ring *fcp_ring = &psli->ring[psli->fcp_ring];
2336 struct lpfc_sli_ring *next_ring = &psli->ring[psli->next_ring];
2337 int rc;
2338
James Smart92d7f7b2007-06-17 19:56:38 -05002339 /*
2340 * if it's not a physical port or if we already send
2341 * clear_la then don't send it.
2342 */
2343 if ((phba->link_state >= LPFC_CLEAR_LA) ||
2344 (vport->port_type != LPFC_PHYSICAL_PORT))
2345 return;
2346
James Smart2e0fef82007-06-17 19:56:36 -05002347 /* Link up discovery */
2348 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL)) != NULL) {
2349 phba->link_state = LPFC_CLEAR_LA;
2350 lpfc_clear_la(phba, mbox);
2351 mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
2352 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -04002353 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart2e0fef82007-06-17 19:56:36 -05002354 if (rc == MBX_NOT_FINISHED) {
2355 mempool_free(mbox, phba->mbox_mem_pool);
2356 lpfc_disc_flush_list(vport);
2357 extra_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
2358 fcp_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
2359 next_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
James Smart92d7f7b2007-06-17 19:56:38 -05002360 phba->link_state = LPFC_HBA_ERROR;
2361 }
2362 }
2363}
2364
2365/* Reg_vpi to tell firmware to resume normal operations */
2366void
2367lpfc_issue_reg_vpi(struct lpfc_hba *phba, struct lpfc_vport *vport)
2368{
2369 LPFC_MBOXQ_t *regvpimbox;
2370
2371 regvpimbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2372 if (regvpimbox) {
2373 lpfc_reg_vpi(phba, vport->vpi, vport->fc_myDID, regvpimbox);
2374 regvpimbox->mbox_cmpl = lpfc_mbx_cmpl_reg_vpi;
2375 regvpimbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -04002376 if (lpfc_sli_issue_mbox(phba, regvpimbox, MBX_NOWAIT)
James Smart92d7f7b2007-06-17 19:56:38 -05002377 == MBX_NOT_FINISHED) {
2378 mempool_free(regvpimbox, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05002379 }
2380 }
2381}
2382
2383/* Start Link up / RSCN discovery on NPR nodes */
2384void
2385lpfc_disc_start(struct lpfc_vport *vport)
2386{
2387 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2388 struct lpfc_hba *phba = vport->phba;
James Smart685f0bf2007-04-25 09:53:08 -04002389 uint32_t num_sent;
dea31012005-04-17 16:05:31 -05002390 uint32_t clear_la_pending;
James Smart685f0bf2007-04-25 09:53:08 -04002391 int did_changed;
dea31012005-04-17 16:05:31 -05002392
James Smart2e0fef82007-06-17 19:56:36 -05002393 if (!lpfc_is_link_up(phba))
dea31012005-04-17 16:05:31 -05002394 return;
James Smart2e0fef82007-06-17 19:56:36 -05002395
2396 if (phba->link_state == LPFC_CLEAR_LA)
dea31012005-04-17 16:05:31 -05002397 clear_la_pending = 1;
2398 else
2399 clear_la_pending = 0;
2400
James Smart2e0fef82007-06-17 19:56:36 -05002401 if (vport->port_state < LPFC_VPORT_READY)
2402 vport->port_state = LPFC_DISC_AUTH;
dea31012005-04-17 16:05:31 -05002403
James Smart2e0fef82007-06-17 19:56:36 -05002404 lpfc_set_disctmo(vport);
2405
2406 if (vport->fc_prevDID == vport->fc_myDID)
dea31012005-04-17 16:05:31 -05002407 did_changed = 0;
James Smart2e0fef82007-06-17 19:56:36 -05002408 else
dea31012005-04-17 16:05:31 -05002409 did_changed = 1;
James Smart2e0fef82007-06-17 19:56:36 -05002410
2411 vport->fc_prevDID = vport->fc_myDID;
2412 vport->num_disc_nodes = 0;
dea31012005-04-17 16:05:31 -05002413
2414 /* Start Discovery state <hba_state> */
James Smarte8b62012007-08-02 11:10:09 -04002415 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2416 "0202 Start Discovery hba state x%x "
2417 "Data: x%x x%x x%x\n",
2418 vport->port_state, vport->fc_flag, vport->fc_plogi_cnt,
2419 vport->fc_adisc_cnt);
dea31012005-04-17 16:05:31 -05002420
2421 /* First do ADISCs - if any */
James Smart2e0fef82007-06-17 19:56:36 -05002422 num_sent = lpfc_els_disc_adisc(vport);
dea31012005-04-17 16:05:31 -05002423
2424 if (num_sent)
2425 return;
2426
James Smart92d7f7b2007-06-17 19:56:38 -05002427 /*
2428 * For SLI3, cmpl_reg_vpi will set port_state to READY, and
2429 * continue discovery.
2430 */
2431 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart1b32f6a2008-02-08 18:49:39 -05002432 !(vport->fc_flag & FC_PT2PT) &&
James Smart92d7f7b2007-06-17 19:56:38 -05002433 !(vport->fc_flag & FC_RSCN_MODE)) {
2434 lpfc_issue_reg_vpi(phba, vport);
2435 return;
2436 }
James Smart2e0fef82007-06-17 19:56:36 -05002437
James Smart92d7f7b2007-06-17 19:56:38 -05002438 /*
2439 * For SLI2, we need to set port_state to READY and continue
2440 * discovery.
2441 */
2442 if (vport->port_state < LPFC_VPORT_READY && !clear_la_pending) {
2443 /* If we get here, there is nothing to ADISC */
2444 if (vport->port_type == LPFC_PHYSICAL_PORT)
2445 lpfc_issue_clear_la(phba, vport);
2446
2447 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
James Smart2e0fef82007-06-17 19:56:36 -05002448 vport->num_disc_nodes = 0;
2449 /* go thru NPR nodes and issue ELS PLOGIs */
2450 if (vport->fc_npr_cnt)
2451 lpfc_els_disc_plogi(vport);
2452
2453 if (!vport->num_disc_nodes) {
2454 spin_lock_irq(shost->host_lock);
2455 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2456 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05002457 lpfc_can_disctmo(vport);
dea31012005-04-17 16:05:31 -05002458 }
2459 }
James Smart92d7f7b2007-06-17 19:56:38 -05002460 vport->port_state = LPFC_VPORT_READY;
dea31012005-04-17 16:05:31 -05002461 } else {
2462 /* Next do PLOGIs - if any */
James Smart2e0fef82007-06-17 19:56:36 -05002463 num_sent = lpfc_els_disc_plogi(vport);
dea31012005-04-17 16:05:31 -05002464
2465 if (num_sent)
2466 return;
2467
James Smart2e0fef82007-06-17 19:56:36 -05002468 if (vport->fc_flag & FC_RSCN_MODE) {
dea31012005-04-17 16:05:31 -05002469 /* Check to see if more RSCNs came in while we
2470 * were processing this one.
2471 */
James Smart2e0fef82007-06-17 19:56:36 -05002472 if ((vport->fc_rscn_id_cnt == 0) &&
2473 (!(vport->fc_flag & FC_RSCN_DISCOVERY))) {
2474 spin_lock_irq(shost->host_lock);
2475 vport->fc_flag &= ~FC_RSCN_MODE;
2476 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05002477 lpfc_can_disctmo(vport);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002478 } else
James Smart2e0fef82007-06-17 19:56:36 -05002479 lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05002480 }
2481 }
2482 return;
2483}
2484
2485/*
2486 * Ignore completion for all IOCBs on tx and txcmpl queue for ELS
2487 * ring the match the sppecified nodelist.
2488 */
2489static void
James Smart2e0fef82007-06-17 19:56:36 -05002490lpfc_free_tx(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05002491{
James Smart2534ba72007-04-25 09:52:20 -04002492 LIST_HEAD(completions);
dea31012005-04-17 16:05:31 -05002493 struct lpfc_sli *psli;
2494 IOCB_t *icmd;
2495 struct lpfc_iocbq *iocb, *next_iocb;
2496 struct lpfc_sli_ring *pring;
dea31012005-04-17 16:05:31 -05002497
2498 psli = &phba->sli;
2499 pring = &psli->ring[LPFC_ELS_RING];
2500
2501 /* Error matching iocb on txq or txcmplq
2502 * First check the txq.
2503 */
James Smart2e0fef82007-06-17 19:56:36 -05002504 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002505 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
2506 if (iocb->context1 != ndlp) {
2507 continue;
2508 }
2509 icmd = &iocb->iocb;
2510 if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
2511 (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
2512
James Smart2534ba72007-04-25 09:52:20 -04002513 list_move_tail(&iocb->list, &completions);
dea31012005-04-17 16:05:31 -05002514 pring->txq_cnt--;
dea31012005-04-17 16:05:31 -05002515 }
2516 }
2517
2518 /* Next check the txcmplq */
2519 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
2520 if (iocb->context1 != ndlp) {
2521 continue;
2522 }
2523 icmd = &iocb->iocb;
James Smart2e0fef82007-06-17 19:56:36 -05002524 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR ||
2525 icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX) {
James Smart2534ba72007-04-25 09:52:20 -04002526 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
dea31012005-04-17 16:05:31 -05002527 }
2528 }
James Smart2e0fef82007-06-17 19:56:36 -05002529 spin_unlock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04002530
2531 while (!list_empty(&completions)) {
2532 iocb = list_get_first(&completions, struct lpfc_iocbq, list);
James Smart92d7f7b2007-06-17 19:56:38 -05002533 list_del_init(&iocb->list);
James Smart2534ba72007-04-25 09:52:20 -04002534
James Smart2e0fef82007-06-17 19:56:36 -05002535 if (!iocb->iocb_cmpl)
2536 lpfc_sli_release_iocbq(phba, iocb);
2537 else {
James Smart2534ba72007-04-25 09:52:20 -04002538 icmd = &iocb->iocb;
2539 icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
2540 icmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
2541 (iocb->iocb_cmpl) (phba, iocb, iocb);
James Smart2e0fef82007-06-17 19:56:36 -05002542 }
James Smart2534ba72007-04-25 09:52:20 -04002543 }
dea31012005-04-17 16:05:31 -05002544}
2545
Adrian Bunka6ababd2007-11-05 18:07:33 +01002546static void
James Smart2e0fef82007-06-17 19:56:36 -05002547lpfc_disc_flush_list(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002548{
2549 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05002550 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002551
James Smart2e0fef82007-06-17 19:56:36 -05002552 if (vport->fc_plogi_cnt || vport->fc_adisc_cnt) {
2553 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
James Smart685f0bf2007-04-25 09:53:08 -04002554 nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05002555 if (!NLP_CHK_NODE_ACT(ndlp))
2556 continue;
James Smart685f0bf2007-04-25 09:53:08 -04002557 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
2558 ndlp->nlp_state == NLP_STE_ADISC_ISSUE) {
2559 lpfc_free_tx(phba, ndlp);
James Smart685f0bf2007-04-25 09:53:08 -04002560 }
dea31012005-04-17 16:05:31 -05002561 }
2562 }
dea31012005-04-17 16:05:31 -05002563}
2564
James Smart92d7f7b2007-06-17 19:56:38 -05002565void
2566lpfc_cleanup_discovery_resources(struct lpfc_vport *vport)
2567{
2568 lpfc_els_flush_rscn(vport);
2569 lpfc_els_flush_cmd(vport);
2570 lpfc_disc_flush_list(vport);
2571}
2572
dea31012005-04-17 16:05:31 -05002573/*****************************************************************************/
2574/*
2575 * NAME: lpfc_disc_timeout
2576 *
2577 * FUNCTION: Fibre Channel driver discovery timeout routine.
2578 *
2579 * EXECUTION ENVIRONMENT: interrupt only
2580 *
2581 * CALLED FROM:
2582 * Timer function
2583 *
2584 * RETURNS:
2585 * none
2586 */
2587/*****************************************************************************/
2588void
2589lpfc_disc_timeout(unsigned long ptr)
2590{
James Smart2e0fef82007-06-17 19:56:36 -05002591 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
2592 struct lpfc_hba *phba = vport->phba;
James Smart5e9d9b82008-06-14 22:52:53 -04002593 uint32_t tmo_posted;
dea31012005-04-17 16:05:31 -05002594 unsigned long flags = 0;
2595
2596 if (unlikely(!phba))
2597 return;
2598
James Smart5e9d9b82008-06-14 22:52:53 -04002599 spin_lock_irqsave(&vport->work_port_lock, flags);
2600 tmo_posted = vport->work_port_events & WORKER_DISC_TMO;
2601 if (!tmo_posted)
James Smart2e0fef82007-06-17 19:56:36 -05002602 vport->work_port_events |= WORKER_DISC_TMO;
James Smart5e9d9b82008-06-14 22:52:53 -04002603 spin_unlock_irqrestore(&vport->work_port_lock, flags);
James Smart2e0fef82007-06-17 19:56:36 -05002604
James Smart5e9d9b82008-06-14 22:52:53 -04002605 if (!tmo_posted)
2606 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05002607 return;
2608}
2609
2610static void
James Smart2e0fef82007-06-17 19:56:36 -05002611lpfc_disc_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002612{
James Smart2e0fef82007-06-17 19:56:36 -05002613 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2614 struct lpfc_hba *phba = vport->phba;
2615 struct lpfc_sli *psli = &phba->sli;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002616 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart92d7f7b2007-06-17 19:56:38 -05002617 LPFC_MBOXQ_t *initlinkmbox;
dea31012005-04-17 16:05:31 -05002618 int rc, clrlaerr = 0;
2619
James Smart2e0fef82007-06-17 19:56:36 -05002620 if (!(vport->fc_flag & FC_DISC_TMO))
dea31012005-04-17 16:05:31 -05002621 return;
2622
James Smart2e0fef82007-06-17 19:56:36 -05002623 spin_lock_irq(shost->host_lock);
2624 vport->fc_flag &= ~FC_DISC_TMO;
2625 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002626
James Smart858c9f62007-06-17 19:56:39 -05002627 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2628 "disc timeout: state:x%x rtry:x%x flg:x%x",
2629 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
2630
James Smart2e0fef82007-06-17 19:56:36 -05002631 switch (vport->port_state) {
dea31012005-04-17 16:05:31 -05002632
2633 case LPFC_LOCAL_CFG_LINK:
James Smart2e0fef82007-06-17 19:56:36 -05002634 /* port_state is identically LPFC_LOCAL_CFG_LINK while waiting for
2635 * FAN
2636 */
2637 /* FAN timeout */
James Smarte8b62012007-08-02 11:10:09 -04002638 lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY,
2639 "0221 FAN timeout\n");
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002640 /* Start discovery by sending FLOGI, clean up old rpis */
James Smart2e0fef82007-06-17 19:56:36 -05002641 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
James Smart685f0bf2007-04-25 09:53:08 -04002642 nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05002643 if (!NLP_CHK_NODE_ACT(ndlp))
2644 continue;
James Smart685f0bf2007-04-25 09:53:08 -04002645 if (ndlp->nlp_state != NLP_STE_NPR_NODE)
2646 continue;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002647 if (ndlp->nlp_type & NLP_FABRIC) {
2648 /* Clean up the ndlp on Fabric connections */
James Smart2e0fef82007-06-17 19:56:36 -05002649 lpfc_drop_node(vport, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04002650
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002651 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002652 /* Fail outstanding IO now since device
2653 * is marked for PLOGI.
2654 */
James Smart2e0fef82007-06-17 19:56:36 -05002655 lpfc_unreg_rpi(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002656 }
2657 }
James Smart92d7f7b2007-06-17 19:56:38 -05002658 if (vport->port_state != LPFC_FLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05002659 lpfc_initial_flogi(vport);
James Smart0ff10d42008-01-11 01:52:36 -05002660 return;
James Smart92d7f7b2007-06-17 19:56:38 -05002661 }
dea31012005-04-17 16:05:31 -05002662 break;
2663
James Smart92d7f7b2007-06-17 19:56:38 -05002664 case LPFC_FDISC:
dea31012005-04-17 16:05:31 -05002665 case LPFC_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002666 /* port_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */
dea31012005-04-17 16:05:31 -05002667 /* Initial FLOGI timeout */
James Smarte8b62012007-08-02 11:10:09 -04002668 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
2669 "0222 Initial %s timeout\n",
James Smart87af33f2007-10-27 13:37:43 -04002670 vport->vpi ? "FDISC" : "FLOGI");
dea31012005-04-17 16:05:31 -05002671
2672 /* Assume no Fabric and go on with discovery.
2673 * Check for outstanding ELS FLOGI to abort.
2674 */
2675
2676 /* FLOGI failed, so just use loop map to make discovery list */
James Smart2e0fef82007-06-17 19:56:36 -05002677 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -05002678
2679 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002680 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -05002681 break;
2682
2683 case LPFC_FABRIC_CFG_LINK:
2684 /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for
2685 NameServer login */
James Smarte8b62012007-08-02 11:10:09 -04002686 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
2687 "0223 Timeout while waiting for "
2688 "NameServer login\n");
dea31012005-04-17 16:05:31 -05002689 /* Next look for NameServer ndlp */
James Smart2e0fef82007-06-17 19:56:36 -05002690 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05002691 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart87af33f2007-10-27 13:37:43 -04002692 lpfc_els_abort(phba, ndlp);
2693
2694 /* ReStart discovery */
2695 goto restart_disc;
dea31012005-04-17 16:05:31 -05002696
2697 case LPFC_NS_QRY:
2698 /* Check for wait for NameServer Rsp timeout */
James Smarte8b62012007-08-02 11:10:09 -04002699 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
2700 "0224 NameServer Query timeout "
2701 "Data: x%x x%x\n",
2702 vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
dea31012005-04-17 16:05:31 -05002703
James Smart92d7f7b2007-06-17 19:56:38 -05002704 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
2705 /* Try it one more time */
2706 vport->fc_ns_retry++;
2707 rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT,
2708 vport->fc_ns_retry, 0);
2709 if (rc == 0)
2710 break;
dea31012005-04-17 16:05:31 -05002711 }
James Smart92d7f7b2007-06-17 19:56:38 -05002712 vport->fc_ns_retry = 0;
dea31012005-04-17 16:05:31 -05002713
James Smart87af33f2007-10-27 13:37:43 -04002714restart_disc:
James Smart92d7f7b2007-06-17 19:56:38 -05002715 /*
2716 * Discovery is over.
2717 * set port_state to PORT_READY if SLI2.
2718 * cmpl_reg_vpi will set port_state to READY for SLI3.
2719 */
2720 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
2721 lpfc_issue_reg_vpi(phba, vport);
2722 else { /* NPIV Not enabled */
2723 lpfc_issue_clear_la(phba, vport);
2724 vport->port_state = LPFC_VPORT_READY;
dea31012005-04-17 16:05:31 -05002725 }
2726
2727 /* Setup and issue mailbox INITIALIZE LINK command */
2728 initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2729 if (!initlinkmbox) {
James Smarte8b62012007-08-02 11:10:09 -04002730 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
2731 "0206 Device Discovery "
2732 "completion error\n");
James Smart2e0fef82007-06-17 19:56:36 -05002733 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05002734 break;
2735 }
2736
2737 lpfc_linkdown(phba);
2738 lpfc_init_link(phba, initlinkmbox, phba->cfg_topology,
2739 phba->cfg_link_speed);
2740 initlinkmbox->mb.un.varInitLnk.lipsr_AL_PA = 0;
James Smarted957682007-06-17 19:56:37 -05002741 initlinkmbox->vport = vport;
James Smart92d7f7b2007-06-17 19:56:38 -05002742 initlinkmbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart0b727fe2007-10-27 13:37:25 -04002743 rc = lpfc_sli_issue_mbox(phba, initlinkmbox, MBX_NOWAIT);
James Smart5b8bd0c2007-04-25 09:52:49 -04002744 lpfc_set_loopback_flag(phba);
dea31012005-04-17 16:05:31 -05002745 if (rc == MBX_NOT_FINISHED)
2746 mempool_free(initlinkmbox, phba->mbox_mem_pool);
2747
2748 break;
2749
2750 case LPFC_DISC_AUTH:
2751 /* Node Authentication timeout */
James Smarte8b62012007-08-02 11:10:09 -04002752 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
2753 "0227 Node Authentication timeout\n");
James Smart2e0fef82007-06-17 19:56:36 -05002754 lpfc_disc_flush_list(vport);
2755
James Smart92d7f7b2007-06-17 19:56:38 -05002756 /*
2757 * set port_state to PORT_READY if SLI2.
2758 * cmpl_reg_vpi will set port_state to READY for SLI3.
2759 */
2760 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
2761 lpfc_issue_reg_vpi(phba, vport);
2762 else { /* NPIV Not enabled */
2763 lpfc_issue_clear_la(phba, vport);
2764 vport->port_state = LPFC_VPORT_READY;
dea31012005-04-17 16:05:31 -05002765 }
2766 break;
2767
James Smart2e0fef82007-06-17 19:56:36 -05002768 case LPFC_VPORT_READY:
2769 if (vport->fc_flag & FC_RSCN_MODE) {
James Smarte8b62012007-08-02 11:10:09 -04002770 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
2771 "0231 RSCN timeout Data: x%x "
2772 "x%x\n",
2773 vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
dea31012005-04-17 16:05:31 -05002774
2775 /* Cleanup any outstanding ELS commands */
James Smart2e0fef82007-06-17 19:56:36 -05002776 lpfc_els_flush_cmd(vport);
dea31012005-04-17 16:05:31 -05002777
James Smart2e0fef82007-06-17 19:56:36 -05002778 lpfc_els_flush_rscn(vport);
2779 lpfc_disc_flush_list(vport);
dea31012005-04-17 16:05:31 -05002780 }
2781 break;
James Smart2e0fef82007-06-17 19:56:36 -05002782
James Smart92d7f7b2007-06-17 19:56:38 -05002783 default:
James Smarte8b62012007-08-02 11:10:09 -04002784 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
2785 "0229 Unexpected discovery timeout, "
2786 "vport State x%x\n", vport->port_state);
James Smart2e0fef82007-06-17 19:56:36 -05002787 break;
2788 }
2789
2790 switch (phba->link_state) {
2791 case LPFC_CLEAR_LA:
James Smart92d7f7b2007-06-17 19:56:38 -05002792 /* CLEAR LA timeout */
James Smarte8b62012007-08-02 11:10:09 -04002793 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
2794 "0228 CLEAR LA timeout\n");
James Smart2e0fef82007-06-17 19:56:36 -05002795 clrlaerr = 1;
2796 break;
2797
James Smart09372822008-01-11 01:52:54 -05002798 case LPFC_LINK_UP:
2799 lpfc_issue_clear_la(phba, vport);
2800 /* Drop thru */
James Smart2e0fef82007-06-17 19:56:36 -05002801 case LPFC_LINK_UNKNOWN:
2802 case LPFC_WARM_START:
2803 case LPFC_INIT_START:
2804 case LPFC_INIT_MBX_CMDS:
2805 case LPFC_LINK_DOWN:
James Smart2e0fef82007-06-17 19:56:36 -05002806 case LPFC_HBA_ERROR:
James Smarte8b62012007-08-02 11:10:09 -04002807 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
2808 "0230 Unexpected timeout, hba link "
2809 "state x%x\n", phba->link_state);
James Smart2e0fef82007-06-17 19:56:36 -05002810 clrlaerr = 1;
2811 break;
James Smart92d7f7b2007-06-17 19:56:38 -05002812
2813 case LPFC_HBA_READY:
2814 break;
dea31012005-04-17 16:05:31 -05002815 }
2816
2817 if (clrlaerr) {
James Smart2e0fef82007-06-17 19:56:36 -05002818 lpfc_disc_flush_list(vport);
James Smarta4bc3372006-12-02 13:34:16 -05002819 psli->ring[(psli->extra_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
dea31012005-04-17 16:05:31 -05002820 psli->ring[(psli->fcp_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
2821 psli->ring[(psli->next_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
James Smart2e0fef82007-06-17 19:56:36 -05002822 vport->port_state = LPFC_VPORT_READY;
dea31012005-04-17 16:05:31 -05002823 }
2824
2825 return;
2826}
2827
dea31012005-04-17 16:05:31 -05002828/*
2829 * This routine handles processing a NameServer REG_LOGIN mailbox
2830 * command upon completion. It is setup in the LPFC_MBOXQ
2831 * as the completion routine when the command is
2832 * handed off to the SLI layer.
2833 */
2834void
James Smart2e0fef82007-06-17 19:56:36 -05002835lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05002836{
James Smart2e0fef82007-06-17 19:56:36 -05002837 MAILBOX_t *mb = &pmb->mb;
2838 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
2839 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
2840 struct lpfc_vport *vport = pmb->vport;
dea31012005-04-17 16:05:31 -05002841
2842 pmb->context1 = NULL;
2843
dea31012005-04-17 16:05:31 -05002844 ndlp->nlp_rpi = mb->un.varWords[0];
dea31012005-04-17 16:05:31 -05002845 ndlp->nlp_type |= NLP_FABRIC;
James Smart2e0fef82007-06-17 19:56:36 -05002846 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
dea31012005-04-17 16:05:31 -05002847
James Smart2e0fef82007-06-17 19:56:36 -05002848 /*
2849 * Start issuing Fabric-Device Management Interface (FDMI) command to
2850 * 0xfffffa (FDMI well known port) or Delay issuing FDMI command if
2851 * fdmi-on=2 (supporting RPA/hostnmae)
dea31012005-04-17 16:05:31 -05002852 */
James Smart2e0fef82007-06-17 19:56:36 -05002853
James Smart3de2a652007-08-02 11:09:59 -04002854 if (vport->cfg_fdmi_on == 1)
James Smart2e0fef82007-06-17 19:56:36 -05002855 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA);
2856 else
2857 mod_timer(&vport->fc_fdmitmo, jiffies + HZ * 60);
dea31012005-04-17 16:05:31 -05002858
James Smartfa4066b2008-01-11 01:53:27 -05002859 /* decrement the node reference count held for this callback
2860 * function.
2861 */
James Smart329f9bc2007-04-25 09:53:01 -04002862 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002863 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2864 kfree(mp);
James Smart329f9bc2007-04-25 09:53:01 -04002865 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05002866
2867 return;
2868}
2869
James Smart685f0bf2007-04-25 09:53:08 -04002870static int
2871lpfc_filter_by_rpi(struct lpfc_nodelist *ndlp, void *param)
2872{
2873 uint16_t *rpi = param;
2874
2875 return ndlp->nlp_rpi == *rpi;
2876}
2877
2878static int
2879lpfc_filter_by_wwpn(struct lpfc_nodelist *ndlp, void *param)
2880{
2881 return memcmp(&ndlp->nlp_portname, param,
2882 sizeof(ndlp->nlp_portname)) == 0;
2883}
2884
Adrian Bunka6ababd2007-11-05 18:07:33 +01002885static struct lpfc_nodelist *
James Smart2e0fef82007-06-17 19:56:36 -05002886__lpfc_find_node(struct lpfc_vport *vport, node_filter filter, void *param)
dea31012005-04-17 16:05:31 -05002887{
James.Smart@Emulex.Com21568f52005-10-28 20:29:36 -04002888 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05002889
James Smart2e0fef82007-06-17 19:56:36 -05002890 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smart87af33f2007-10-27 13:37:43 -04002891 if (filter(ndlp, param))
James Smart685f0bf2007-04-25 09:53:08 -04002892 return ndlp;
2893 }
James.Smart@Emulex.Com21568f52005-10-28 20:29:36 -04002894 return NULL;
dea31012005-04-17 16:05:31 -05002895}
2896
James Smart685f0bf2007-04-25 09:53:08 -04002897/*
2898 * This routine looks up the ndlp lists for the given RPI. If rpi found it
James Smart2e0fef82007-06-17 19:56:36 -05002899 * returns the node list element pointer else return NULL.
James Smart685f0bf2007-04-25 09:53:08 -04002900 */
2901struct lpfc_nodelist *
James Smart2e0fef82007-06-17 19:56:36 -05002902__lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi)
James Smart685f0bf2007-04-25 09:53:08 -04002903{
James Smart2e0fef82007-06-17 19:56:36 -05002904 return __lpfc_find_node(vport, lpfc_filter_by_rpi, &rpi);
James Smart685f0bf2007-04-25 09:53:08 -04002905}
2906
James Smart488d1462006-03-07 15:02:37 -05002907/*
James Smart685f0bf2007-04-25 09:53:08 -04002908 * This routine looks up the ndlp lists for the given WWPN. If WWPN found it
James Smart2e0fef82007-06-17 19:56:36 -05002909 * returns the node element list pointer else return NULL.
James Smart488d1462006-03-07 15:02:37 -05002910 */
2911struct lpfc_nodelist *
James Smart2e0fef82007-06-17 19:56:36 -05002912lpfc_findnode_wwpn(struct lpfc_vport *vport, struct lpfc_name *wwpn)
James Smart488d1462006-03-07 15:02:37 -05002913{
James Smart2e0fef82007-06-17 19:56:36 -05002914 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart488d1462006-03-07 15:02:37 -05002915 struct lpfc_nodelist *ndlp;
James Smart488d1462006-03-07 15:02:37 -05002916
James Smart2e0fef82007-06-17 19:56:36 -05002917 spin_lock_irq(shost->host_lock);
2918 ndlp = __lpfc_find_node(vport, lpfc_filter_by_wwpn, wwpn);
2919 spin_unlock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05002920 return ndlp;
James Smart488d1462006-03-07 15:02:37 -05002921}
2922
dea31012005-04-17 16:05:31 -05002923void
James Smart2e0fef82007-06-17 19:56:36 -05002924lpfc_nlp_init(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2925 uint32_t did)
dea31012005-04-17 16:05:31 -05002926{
2927 memset(ndlp, 0, sizeof (struct lpfc_nodelist));
dea31012005-04-17 16:05:31 -05002928 INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp);
James Smart92d7f7b2007-06-17 19:56:38 -05002929 INIT_LIST_HEAD(&ndlp->dev_loss_evt.evt_listp);
dea31012005-04-17 16:05:31 -05002930 init_timer(&ndlp->nlp_delayfunc);
2931 ndlp->nlp_delayfunc.function = lpfc_els_retry_delay;
2932 ndlp->nlp_delayfunc.data = (unsigned long)ndlp;
2933 ndlp->nlp_DID = did;
James Smart2e0fef82007-06-17 19:56:36 -05002934 ndlp->vport = vport;
dea31012005-04-17 16:05:31 -05002935 ndlp->nlp_sid = NLP_NO_SID;
James Smart685f0bf2007-04-25 09:53:08 -04002936 INIT_LIST_HEAD(&ndlp->nlp_listp);
James Smart329f9bc2007-04-25 09:53:01 -04002937 kref_init(&ndlp->kref);
James Smarte47c9092008-02-08 18:49:26 -05002938 NLP_INT_NODE_ACT(ndlp);
James Smart858c9f62007-06-17 19:56:39 -05002939
2940 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
2941 "node init: did:x%x",
2942 ndlp->nlp_DID, 0, 0);
2943
dea31012005-04-17 16:05:31 -05002944 return;
2945}
James Smart329f9bc2007-04-25 09:53:01 -04002946
James Smart98c9ea52007-10-27 13:37:33 -04002947/* This routine releases all resources associated with a specifc NPort's ndlp
2948 * and mempool_free's the nodelist.
2949 */
James Smart311464e2007-08-02 11:10:37 -04002950static void
James Smart329f9bc2007-04-25 09:53:01 -04002951lpfc_nlp_release(struct kref *kref)
2952{
James Smarte47c9092008-02-08 18:49:26 -05002953 struct lpfc_hba *phba;
2954 unsigned long flags;
James Smart329f9bc2007-04-25 09:53:01 -04002955 struct lpfc_nodelist *ndlp = container_of(kref, struct lpfc_nodelist,
2956 kref);
James Smart858c9f62007-06-17 19:56:39 -05002957
2958 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
2959 "node release: did:x%x flg:x%x type:x%x",
2960 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
2961
James Smarte47c9092008-02-08 18:49:26 -05002962 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
2963 "0279 lpfc_nlp_release: ndlp:x%p "
2964 "usgmap:x%x refcnt:%d\n",
2965 (void *)ndlp, ndlp->nlp_usg_map,
2966 atomic_read(&ndlp->kref.refcount));
2967
2968 /* remove ndlp from action. */
James Smart2e0fef82007-06-17 19:56:36 -05002969 lpfc_nlp_remove(ndlp->vport, ndlp);
James Smarte47c9092008-02-08 18:49:26 -05002970
2971 /* clear the ndlp active flag for all release cases */
2972 phba = ndlp->vport->phba;
2973 spin_lock_irqsave(&phba->ndlp_lock, flags);
2974 NLP_CLR_NODE_ACT(ndlp);
2975 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
2976
2977 /* free ndlp memory for final ndlp release */
2978 if (NLP_CHK_FREE_REQ(ndlp))
2979 mempool_free(ndlp, ndlp->vport->phba->nlp_mem_pool);
James Smart329f9bc2007-04-25 09:53:01 -04002980}
2981
James Smart98c9ea52007-10-27 13:37:33 -04002982/* This routine bumps the reference count for a ndlp structure to ensure
2983 * that one discovery thread won't free a ndlp while another discovery thread
2984 * is using it.
2985 */
James Smart329f9bc2007-04-25 09:53:01 -04002986struct lpfc_nodelist *
2987lpfc_nlp_get(struct lpfc_nodelist *ndlp)
2988{
James Smarte47c9092008-02-08 18:49:26 -05002989 struct lpfc_hba *phba;
2990 unsigned long flags;
2991
James Smart98c9ea52007-10-27 13:37:33 -04002992 if (ndlp) {
2993 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
2994 "node get: did:x%x flg:x%x refcnt:x%x",
2995 ndlp->nlp_DID, ndlp->nlp_flag,
2996 atomic_read(&ndlp->kref.refcount));
James Smarte47c9092008-02-08 18:49:26 -05002997 /* The check of ndlp usage to prevent incrementing the
2998 * ndlp reference count that is in the process of being
2999 * released.
3000 */
3001 phba = ndlp->vport->phba;
3002 spin_lock_irqsave(&phba->ndlp_lock, flags);
3003 if (!NLP_CHK_NODE_ACT(ndlp) || NLP_CHK_FREE_ACK(ndlp)) {
3004 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
3005 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
3006 "0276 lpfc_nlp_get: ndlp:x%p "
3007 "usgmap:x%x refcnt:%d\n",
3008 (void *)ndlp, ndlp->nlp_usg_map,
3009 atomic_read(&ndlp->kref.refcount));
3010 return NULL;
3011 } else
3012 kref_get(&ndlp->kref);
3013 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
James Smart98c9ea52007-10-27 13:37:33 -04003014 }
James Smart329f9bc2007-04-25 09:53:01 -04003015 return ndlp;
3016}
3017
James Smart98c9ea52007-10-27 13:37:33 -04003018/* This routine decrements the reference count for a ndlp structure. If the
James Smarte47c9092008-02-08 18:49:26 -05003019 * count goes to 0, this indicates the the associated nodelist should be
3020 * freed. Returning 1 indicates the ndlp resource has been released; on the
3021 * other hand, returning 0 indicates the ndlp resource has not been released
3022 * yet.
James Smart98c9ea52007-10-27 13:37:33 -04003023 */
James Smart329f9bc2007-04-25 09:53:01 -04003024int
3025lpfc_nlp_put(struct lpfc_nodelist *ndlp)
3026{
James Smarte47c9092008-02-08 18:49:26 -05003027 struct lpfc_hba *phba;
3028 unsigned long flags;
3029
3030 if (!ndlp)
3031 return 1;
3032
3033 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
3034 "node put: did:x%x flg:x%x refcnt:x%x",
3035 ndlp->nlp_DID, ndlp->nlp_flag,
3036 atomic_read(&ndlp->kref.refcount));
3037 phba = ndlp->vport->phba;
3038 spin_lock_irqsave(&phba->ndlp_lock, flags);
3039 /* Check the ndlp memory free acknowledge flag to avoid the
3040 * possible race condition that kref_put got invoked again
3041 * after previous one has done ndlp memory free.
3042 */
3043 if (NLP_CHK_FREE_ACK(ndlp)) {
3044 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
3045 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
3046 "0274 lpfc_nlp_put: ndlp:x%p "
3047 "usgmap:x%x refcnt:%d\n",
3048 (void *)ndlp, ndlp->nlp_usg_map,
3049 atomic_read(&ndlp->kref.refcount));
3050 return 1;
James Smart98c9ea52007-10-27 13:37:33 -04003051 }
James Smarte47c9092008-02-08 18:49:26 -05003052 /* Check the ndlp inactivate log flag to avoid the possible
3053 * race condition that kref_put got invoked again after ndlp
3054 * is already in inactivating state.
3055 */
3056 if (NLP_CHK_IACT_REQ(ndlp)) {
3057 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
3058 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
3059 "0275 lpfc_nlp_put: ndlp:x%p "
3060 "usgmap:x%x refcnt:%d\n",
3061 (void *)ndlp, ndlp->nlp_usg_map,
3062 atomic_read(&ndlp->kref.refcount));
3063 return 1;
3064 }
3065 /* For last put, mark the ndlp usage flags to make sure no
3066 * other kref_get and kref_put on the same ndlp shall get
3067 * in between the process when the final kref_put has been
3068 * invoked on this ndlp.
3069 */
3070 if (atomic_read(&ndlp->kref.refcount) == 1) {
3071 /* Indicate ndlp is put to inactive state. */
3072 NLP_SET_IACT_REQ(ndlp);
3073 /* Acknowledge ndlp memory free has been seen. */
3074 if (NLP_CHK_FREE_REQ(ndlp))
3075 NLP_SET_FREE_ACK(ndlp);
3076 }
3077 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
3078 /* Note, the kref_put returns 1 when decrementing a reference
3079 * count that was 1, it invokes the release callback function,
3080 * but it still left the reference count as 1 (not actually
3081 * performs the last decrementation). Otherwise, it actually
3082 * decrements the reference count and returns 0.
3083 */
3084 return kref_put(&ndlp->kref, lpfc_nlp_release);
James Smart329f9bc2007-04-25 09:53:01 -04003085}
James Smart98c9ea52007-10-27 13:37:33 -04003086
3087/* This routine free's the specified nodelist if it is not in use
James Smarte47c9092008-02-08 18:49:26 -05003088 * by any other discovery thread. This routine returns 1 if the
3089 * ndlp has been freed. A return value of 0 indicates the ndlp is
3090 * not yet been released.
James Smart98c9ea52007-10-27 13:37:33 -04003091 */
3092int
3093lpfc_nlp_not_used(struct lpfc_nodelist *ndlp)
3094{
3095 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
3096 "node not used: did:x%x flg:x%x refcnt:x%x",
3097 ndlp->nlp_DID, ndlp->nlp_flag,
3098 atomic_read(&ndlp->kref.refcount));
James Smarte47c9092008-02-08 18:49:26 -05003099 if (atomic_read(&ndlp->kref.refcount) == 1)
3100 if (lpfc_nlp_put(ndlp))
3101 return 1;
James Smart98c9ea52007-10-27 13:37:33 -04003102 return 0;
3103}