blob: aaf398e5c93f9317ee62ea569bee0bc7b0853240 [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}
92
93/*
94 * This function will be called when dev_loss_tmo fire.
95 */
96void
97lpfc_dev_loss_tmo_callbk(struct fc_rport *rport)
98{
99 struct lpfc_rport_data *rdata;
100 struct lpfc_nodelist * ndlp;
James Smart2e0fef82007-06-17 19:56:36 -0500101 struct lpfc_vport *vport;
James Smart858c9f62007-06-17 19:56:39 -0500102 struct lpfc_hba *phba;
James Smart858c9f62007-06-17 19:56:39 -0500103 struct lpfc_work_evt *evtp;
James Smarta8adb832007-10-27 13:37:53 -0400104 int put_node;
105 int put_rport;
James Smartc01f3202006-08-18 17:47:08 -0400106
107 rdata = rport->dd_data;
108 ndlp = rdata->pnode;
James Smart58da1ff2008-04-07 10:15:56 -0400109 if (!ndlp || !NLP_CHK_NODE_ACT(ndlp))
James Smartc01f3202006-08-18 17:47:08 -0400110 return;
James Smartc01f3202006-08-18 17:47:08 -0400111
James Smart858c9f62007-06-17 19:56:39 -0500112 vport = ndlp->vport;
113 phba = vport->phba;
114
115 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
116 "rport devlosscb: sid:x%x did:x%x flg:x%x",
117 ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag);
118
James Smarta8adb832007-10-27 13:37:53 -0400119 /* Don't defer this if we are in the process of deleting the vport
120 * or unloading the driver. The unload will cleanup the node
121 * appropriately we just need to cleanup the ndlp rport info here.
122 */
123 if (vport->load_flag & FC_UNLOADING) {
124 put_node = rdata->pnode != NULL;
125 put_rport = ndlp->rport != NULL;
126 rdata->pnode = NULL;
127 ndlp->rport = NULL;
128 if (put_node)
129 lpfc_nlp_put(ndlp);
130 if (put_rport)
131 put_device(&rport->dev);
132 return;
133 }
134
135 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE)
136 return;
137
James Smart858c9f62007-06-17 19:56:39 -0500138 evtp = &ndlp->dev_loss_evt;
139
140 if (!list_empty(&evtp->evt_listp))
141 return;
142
143 spin_lock_irq(&phba->hbalock);
James Smartfa4066b2008-01-11 01:53:27 -0500144 /* We need to hold the node by incrementing the reference
145 * count until this queued work is done
146 */
147 evtp->evt_arg1 = lpfc_nlp_get(ndlp);
James Smart5e9d9b82008-06-14 22:52:53 -0400148 if (evtp->evt_arg1) {
149 evtp->evt = LPFC_EVT_DEV_LOSS;
150 list_add_tail(&evtp->evt_listp, &phba->work_list);
151 lpfc_worker_wake_up(phba);
152 }
James Smart858c9f62007-06-17 19:56:39 -0500153 spin_unlock_irq(&phba->hbalock);
154
James Smart858c9f62007-06-17 19:56:39 -0500155 return;
156}
157
158/*
159 * This function is called from the worker thread when dev_loss_tmo
160 * expire.
161 */
Adrian Bunka6ababd2007-11-05 18:07:33 +0100162static void
James Smart858c9f62007-06-17 19:56:39 -0500163lpfc_dev_loss_tmo_handler(struct lpfc_nodelist *ndlp)
164{
165 struct lpfc_rport_data *rdata;
166 struct fc_rport *rport;
167 struct lpfc_vport *vport;
168 struct lpfc_hba *phba;
169 uint8_t *name;
James Smart87af33f2007-10-27 13:37:43 -0400170 int put_node;
171 int put_rport;
James Smart858c9f62007-06-17 19:56:39 -0500172 int warn_on = 0;
173
174 rport = ndlp->rport;
175
176 if (!rport)
177 return;
178
179 rdata = rport->dd_data;
180 name = (uint8_t *) &ndlp->nlp_portname;
181 vport = ndlp->vport;
182 phba = vport->phba;
183
184 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
185 "rport devlosstmo:did:x%x type:x%x id:x%x",
186 ndlp->nlp_DID, ndlp->nlp_type, rport->scsi_target_id);
187
James Smarta8adb832007-10-27 13:37:53 -0400188 /* Don't defer this if we are in the process of deleting the vport
189 * or unloading the driver. The unload will cleanup the node
190 * appropriately we just need to cleanup the ndlp rport info here.
191 */
192 if (vport->load_flag & FC_UNLOADING) {
James Smart09372822008-01-11 01:52:54 -0500193 if (ndlp->nlp_sid != NLP_NO_SID) {
194 /* flush the target */
195 lpfc_sli_abort_iocb(vport,
196 &phba->sli.ring[phba->sli.fcp_ring],
197 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
198 }
James Smarta8adb832007-10-27 13:37:53 -0400199 put_node = rdata->pnode != NULL;
200 put_rport = ndlp->rport != NULL;
201 rdata->pnode = NULL;
202 ndlp->rport = NULL;
203 if (put_node)
204 lpfc_nlp_put(ndlp);
205 if (put_rport)
206 put_device(&rport->dev);
207 return;
208 }
209
210 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE)
James Smart858c9f62007-06-17 19:56:39 -0500211 return;
212
James Smart92d7f7b2007-06-17 19:56:38 -0500213 if (ndlp->nlp_type & NLP_FABRIC) {
214 /* We will clean up these Nodes in linkup */
215 put_node = rdata->pnode != NULL;
216 put_rport = ndlp->rport != NULL;
217 rdata->pnode = NULL;
218 ndlp->rport = NULL;
219 if (put_node)
220 lpfc_nlp_put(ndlp);
221 if (put_rport)
222 put_device(&rport->dev);
James Smart82085712007-04-25 09:52:41 -0400223 return;
James Smart92d7f7b2007-06-17 19:56:38 -0500224 }
James Smart82085712007-04-25 09:52:41 -0400225
dea31012005-04-17 16:05:31 -0500226 if (ndlp->nlp_sid != NLP_NO_SID) {
James.Smart@Emulex.Com6e8215e2005-06-25 10:34:04 -0400227 warn_on = 1;
dea31012005-04-17 16:05:31 -0500228 /* flush the target */
James Smart51ef4c22007-08-02 11:10:31 -0400229 lpfc_sli_abort_iocb(vport, &phba->sli.ring[phba->sli.fcp_ring],
230 ndlp->nlp_sid, 0, LPFC_CTX_TGT);
dea31012005-04-17 16:05:31 -0500231 }
James Smart2e0fef82007-06-17 19:56:36 -0500232 if (vport->load_flag & FC_UNLOADING)
James Smartc01f3202006-08-18 17:47:08 -0400233 warn_on = 0;
234
James.Smart@Emulex.Com6e8215e2005-06-25 10:34:04 -0400235 if (warn_on) {
James Smarte8b62012007-08-02 11:10:09 -0400236 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
237 "0203 Devloss timeout on "
James Smart58da1ff2008-04-07 10:15:56 -0400238 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x "
239 "NPort x%06x Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400240 *name, *(name+1), *(name+2), *(name+3),
241 *(name+4), *(name+5), *(name+6), *(name+7),
242 ndlp->nlp_DID, ndlp->nlp_flag,
243 ndlp->nlp_state, ndlp->nlp_rpi);
James.Smart@Emulex.Com6e8215e2005-06-25 10:34:04 -0400244 } else {
James Smarte8b62012007-08-02 11:10:09 -0400245 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
246 "0204 Devloss timeout on "
James Smart58da1ff2008-04-07 10:15:56 -0400247 "WWPN %02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x "
248 "NPort x%06x Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -0400249 *name, *(name+1), *(name+2), *(name+3),
250 *(name+4), *(name+5), *(name+6), *(name+7),
251 ndlp->nlp_DID, ndlp->nlp_flag,
252 ndlp->nlp_state, ndlp->nlp_rpi);
James.Smart@Emulex.Com6e8215e2005-06-25 10:34:04 -0400253 }
254
James Smart87af33f2007-10-27 13:37:43 -0400255 put_node = rdata->pnode != NULL;
256 put_rport = ndlp->rport != NULL;
257 rdata->pnode = NULL;
258 ndlp->rport = NULL;
259 if (put_node)
260 lpfc_nlp_put(ndlp);
261 if (put_rport)
262 put_device(&rport->dev);
263
James Smart2e0fef82007-06-17 19:56:36 -0500264 if (!(vport->load_flag & FC_UNLOADING) &&
James Smart1dcb58e2007-04-25 09:51:30 -0400265 !(ndlp->nlp_flag & NLP_DELAY_TMO) &&
James Smart82085712007-04-25 09:52:41 -0400266 !(ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
James Smarte47c9092008-02-08 18:49:26 -0500267 (ndlp->nlp_state != NLP_STE_UNMAPPED_NODE))
James Smart2e0fef82007-06-17 19:56:36 -0500268 lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
James Smart92d7f7b2007-06-17 19:56:38 -0500269}
James Smartc01f3202006-08-18 17:47:08 -0400270
dea31012005-04-17 16:05:31 -0500271static void
James Smart2e0fef82007-06-17 19:56:36 -0500272lpfc_work_list_done(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500273{
274 struct lpfc_work_evt *evtp = NULL;
275 struct lpfc_nodelist *ndlp;
276 int free_evt;
277
James Smart2e0fef82007-06-17 19:56:36 -0500278 spin_lock_irq(&phba->hbalock);
279 while (!list_empty(&phba->work_list)) {
dea31012005-04-17 16:05:31 -0500280 list_remove_head((&phba->work_list), evtp, typeof(*evtp),
281 evt_listp);
James Smart2e0fef82007-06-17 19:56:36 -0500282 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500283 free_evt = 1;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500284 switch (evtp->evt) {
dea31012005-04-17 16:05:31 -0500285 case LPFC_EVT_ELS_RETRY:
James Smart2e0fef82007-06-17 19:56:36 -0500286 ndlp = (struct lpfc_nodelist *) (evtp->evt_arg1);
dea31012005-04-17 16:05:31 -0500287 lpfc_els_retry_delay_handler(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -0500288 free_evt = 0; /* evt is part of ndlp */
James Smartfa4066b2008-01-11 01:53:27 -0500289 /* decrement the node reference count held
290 * for this queued work
291 */
292 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500293 break;
James Smart858c9f62007-06-17 19:56:39 -0500294 case LPFC_EVT_DEV_LOSS:
295 ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1);
James Smart858c9f62007-06-17 19:56:39 -0500296 lpfc_dev_loss_tmo_handler(ndlp);
297 free_evt = 0;
James Smartfa4066b2008-01-11 01:53:27 -0500298 /* decrement the node reference count held for
299 * this queued work
300 */
James Smart858c9f62007-06-17 19:56:39 -0500301 lpfc_nlp_put(ndlp);
302 break;
dea31012005-04-17 16:05:31 -0500303 case LPFC_EVT_ONLINE:
James Smart2e0fef82007-06-17 19:56:36 -0500304 if (phba->link_state < LPFC_LINK_DOWN)
305 *(int *) (evtp->evt_arg1) = lpfc_online(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500306 else
James Smart2e0fef82007-06-17 19:56:36 -0500307 *(int *) (evtp->evt_arg1) = 0;
dea31012005-04-17 16:05:31 -0500308 complete((struct completion *)(evtp->evt_arg2));
309 break;
James Smart46fa3112007-04-25 09:51:45 -0400310 case LPFC_EVT_OFFLINE_PREP:
James Smart2e0fef82007-06-17 19:56:36 -0500311 if (phba->link_state >= LPFC_LINK_DOWN)
James Smart46fa3112007-04-25 09:51:45 -0400312 lpfc_offline_prep(phba);
313 *(int *)(evtp->evt_arg1) = 0;
314 complete((struct completion *)(evtp->evt_arg2));
315 break;
316 case LPFC_EVT_OFFLINE:
317 lpfc_offline(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500318 lpfc_sli_brdrestart(phba);
319 *(int *)(evtp->evt_arg1) =
James Smart46fa3112007-04-25 09:51:45 -0400320 lpfc_sli_brdready(phba, HS_FFRDY | HS_MBRDY);
321 lpfc_unblock_mgmt_io(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500322 complete((struct completion *)(evtp->evt_arg2));
323 break;
324 case LPFC_EVT_WARM_START:
James Smart46fa3112007-04-25 09:51:45 -0400325 lpfc_offline(phba);
James Smart92908312006-03-07 15:04:13 -0500326 lpfc_reset_barrier(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500327 lpfc_sli_brdreset(phba);
328 lpfc_hba_down_post(phba);
329 *(int *)(evtp->evt_arg1) =
330 lpfc_sli_brdready(phba, HS_MBRDY);
James Smart46fa3112007-04-25 09:51:45 -0400331 lpfc_unblock_mgmt_io(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500332 complete((struct completion *)(evtp->evt_arg2));
333 break;
334 case LPFC_EVT_KILL:
James Smart46fa3112007-04-25 09:51:45 -0400335 lpfc_offline(phba);
James Smart92908312006-03-07 15:04:13 -0500336 *(int *)(evtp->evt_arg1)
James Smart2e0fef82007-06-17 19:56:36 -0500337 = (phba->pport->stopped)
338 ? 0 : lpfc_sli_brdkill(phba);
James Smart46fa3112007-04-25 09:51:45 -0400339 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -0500340 complete((struct completion *)(evtp->evt_arg2));
341 break;
342 }
343 if (free_evt)
344 kfree(evtp);
James Smart2e0fef82007-06-17 19:56:36 -0500345 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500346 }
James Smart2e0fef82007-06-17 19:56:36 -0500347 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500348
349}
350
James Smart311464e2007-08-02 11:10:37 -0400351static void
James Smart2e0fef82007-06-17 19:56:36 -0500352lpfc_work_done(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500353{
354 struct lpfc_sli_ring *pring;
James Smart858c9f62007-06-17 19:56:39 -0500355 uint32_t ha_copy, status, control, work_port_events;
James Smart549e55c2007-08-02 11:09:51 -0400356 struct lpfc_vport **vports;
James Smart51ef4c22007-08-02 11:10:31 -0400357 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -0400358 int i;
dea31012005-04-17 16:05:31 -0500359
James Smart2e0fef82007-06-17 19:56:36 -0500360 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500361 ha_copy = phba->work_ha;
362 phba->work_ha = 0;
James Smart2e0fef82007-06-17 19:56:36 -0500363 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500364
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500365 if (ha_copy & HA_ERATT)
dea31012005-04-17 16:05:31 -0500366 lpfc_handle_eratt(phba);
367
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500368 if (ha_copy & HA_MBATT)
dea31012005-04-17 16:05:31 -0500369 lpfc_sli_handle_mb_event(phba);
370
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500371 if (ha_copy & HA_LATT)
dea31012005-04-17 16:05:31 -0500372 lpfc_handle_latt(phba);
James Smart549e55c2007-08-02 11:09:51 -0400373 vports = lpfc_create_vport_work_array(phba);
374 if (vports != NULL)
James Smart09372822008-01-11 01:52:54 -0500375 for(i = 0; i <= phba->max_vpi; i++) {
James Smart51ef4c22007-08-02 11:10:31 -0400376 /*
377 * We could have no vports in array if unloading, so if
378 * this happens then just use the pport
379 */
380 if (vports[i] == NULL && i == 0)
381 vport = phba->pport;
382 else
383 vport = vports[i];
384 if (vport == NULL)
385 break;
James Smart58da1ff2008-04-07 10:15:56 -0400386 spin_lock_irq(&vport->work_port_lock);
James Smart51ef4c22007-08-02 11:10:31 -0400387 work_port_events = vport->work_port_events;
James Smart58da1ff2008-04-07 10:15:56 -0400388 vport->work_port_events &= ~work_port_events;
389 spin_unlock_irq(&vport->work_port_lock);
James Smart549e55c2007-08-02 11:09:51 -0400390 if (work_port_events & WORKER_DISC_TMO)
James Smart51ef4c22007-08-02 11:10:31 -0400391 lpfc_disc_timeout_handler(vport);
James Smart549e55c2007-08-02 11:09:51 -0400392 if (work_port_events & WORKER_ELS_TMO)
James Smart51ef4c22007-08-02 11:10:31 -0400393 lpfc_els_timeout_handler(vport);
James Smart549e55c2007-08-02 11:09:51 -0400394 if (work_port_events & WORKER_HB_TMO)
395 lpfc_hb_timeout_handler(phba);
396 if (work_port_events & WORKER_MBOX_TMO)
397 lpfc_mbox_timeout_handler(phba);
398 if (work_port_events & WORKER_FABRIC_BLOCK_TMO)
399 lpfc_unblock_fabric_iocbs(phba);
400 if (work_port_events & WORKER_FDMI_TMO)
James Smart51ef4c22007-08-02 11:10:31 -0400401 lpfc_fdmi_timeout_handler(vport);
James Smart549e55c2007-08-02 11:09:51 -0400402 if (work_port_events & WORKER_RAMP_DOWN_QUEUE)
403 lpfc_ramp_down_queue_handler(phba);
404 if (work_port_events & WORKER_RAMP_UP_QUEUE)
405 lpfc_ramp_up_queue_handler(phba);
James Smart92d7f7b2007-06-17 19:56:38 -0500406 }
James Smart09372822008-01-11 01:52:54 -0500407 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -0500408
James Smart858c9f62007-06-17 19:56:39 -0500409 pring = &phba->sli.ring[LPFC_ELS_RING];
410 status = (ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
411 status >>= (4*LPFC_ELS_RING);
412 if ((status & HA_RXMASK)
413 || (pring->flag & LPFC_DEFERRED_RING_EVENT)) {
James Smart0b727fe2007-10-27 13:37:25 -0400414 if (pring->flag & LPFC_STOP_IOCB_EVENT) {
James Smart858c9f62007-06-17 19:56:39 -0500415 pring->flag |= LPFC_DEFERRED_RING_EVENT;
James Smart5e9d9b82008-06-14 22:52:53 -0400416 /* Set the lpfc data pending flag */
417 set_bit(LPFC_DATA_READY, &phba->data_flags);
James Smart858c9f62007-06-17 19:56:39 -0500418 } else {
James Smart58da1ff2008-04-07 10:15:56 -0400419 pring->flag &= ~LPFC_DEFERRED_RING_EVENT;
James Smart858c9f62007-06-17 19:56:39 -0500420 lpfc_sli_handle_slow_ring_event(phba, pring,
421 (status &
422 HA_RXMASK));
James Smart858c9f62007-06-17 19:56:39 -0500423 }
424 /*
425 * Turn on Ring interrupts
426 */
427 spin_lock_irq(&phba->hbalock);
428 control = readl(phba->HCregaddr);
429 if (!(control & (HC_R0INT_ENA << LPFC_ELS_RING))) {
James Smarta58cbd52007-08-02 11:09:43 -0400430 lpfc_debugfs_slow_ring_trc(phba,
431 "WRK Enable ring: cntl:x%x hacopy:x%x",
432 control, ha_copy, 0);
433
James Smart858c9f62007-06-17 19:56:39 -0500434 control |= (HC_R0INT_ENA << LPFC_ELS_RING);
dea31012005-04-17 16:05:31 -0500435 writel(control, phba->HCregaddr);
436 readl(phba->HCregaddr); /* flush */
dea31012005-04-17 16:05:31 -0500437 }
James Smarta58cbd52007-08-02 11:09:43 -0400438 else {
439 lpfc_debugfs_slow_ring_trc(phba,
440 "WRK Ring ok: cntl:x%x hacopy:x%x",
441 control, ha_copy, 0);
442 }
James Smart858c9f62007-06-17 19:56:39 -0500443 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500444 }
James Smart2e0fef82007-06-17 19:56:36 -0500445 lpfc_work_list_done(phba);
dea31012005-04-17 16:05:31 -0500446}
447
dea31012005-04-17 16:05:31 -0500448int
449lpfc_do_work(void *p)
450{
451 struct lpfc_hba *phba = p;
452 int rc;
dea31012005-04-17 16:05:31 -0500453
454 set_user_nice(current, -20);
James Smart5e9d9b82008-06-14 22:52:53 -0400455 phba->data_flags = 0;
dea31012005-04-17 16:05:31 -0500456
457 while (1) {
James Smart5e9d9b82008-06-14 22:52:53 -0400458 /* wait and check worker queue activities */
459 rc = wait_event_interruptible(phba->work_waitq,
460 (test_and_clear_bit(LPFC_DATA_READY,
461 &phba->data_flags)
462 || kthread_should_stop()));
dea31012005-04-17 16:05:31 -0500463 BUG_ON(rc);
464
465 if (kthread_should_stop())
466 break;
467
James Smart5e9d9b82008-06-14 22:52:53 -0400468 /* Attend pending lpfc data processing */
dea31012005-04-17 16:05:31 -0500469 lpfc_work_done(phba);
dea31012005-04-17 16:05:31 -0500470 }
dea31012005-04-17 16:05:31 -0500471 return 0;
472}
473
474/*
475 * This is only called to handle FC worker events. Since this a rare
476 * occurance, we allocate a struct lpfc_work_evt structure here instead of
477 * embedding it in the IOCB.
478 */
479int
James Smart2e0fef82007-06-17 19:56:36 -0500480lpfc_workq_post_event(struct lpfc_hba *phba, void *arg1, void *arg2,
dea31012005-04-17 16:05:31 -0500481 uint32_t evt)
482{
483 struct lpfc_work_evt *evtp;
James Smarted957682007-06-17 19:56:37 -0500484 unsigned long flags;
dea31012005-04-17 16:05:31 -0500485
486 /*
487 * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will
488 * be queued to worker thread for processing
489 */
James Smart92d7f7b2007-06-17 19:56:38 -0500490 evtp = kmalloc(sizeof(struct lpfc_work_evt), GFP_ATOMIC);
dea31012005-04-17 16:05:31 -0500491 if (!evtp)
492 return 0;
493
494 evtp->evt_arg1 = arg1;
495 evtp->evt_arg2 = arg2;
496 evtp->evt = evt;
497
James Smarted957682007-06-17 19:56:37 -0500498 spin_lock_irqsave(&phba->hbalock, flags);
James Smart071fbd3d2006-04-15 11:53:20 -0400499 list_add_tail(&evtp->evt_listp, &phba->work_list);
James Smarted957682007-06-17 19:56:37 -0500500 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -0500501
James Smart5e9d9b82008-06-14 22:52:53 -0400502 lpfc_worker_wake_up(phba);
503
dea31012005-04-17 16:05:31 -0500504 return 1;
505}
506
James Smart92d7f7b2007-06-17 19:56:38 -0500507void
508lpfc_cleanup_rpis(struct lpfc_vport *vport, int remove)
509{
James Smart09372822008-01-11 01:52:54 -0500510 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500511 struct lpfc_hba *phba = vport->phba;
512 struct lpfc_nodelist *ndlp, *next_ndlp;
513 int rc;
514
515 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -0500516 if (!NLP_CHK_NODE_ACT(ndlp))
517 continue;
James Smart92d7f7b2007-06-17 19:56:38 -0500518 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
519 continue;
James Smart98c9ea52007-10-27 13:37:33 -0400520 if ((phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) ||
521 ((vport->port_type == LPFC_NPIV_PORT) &&
522 (ndlp->nlp_DID == NameServer_DID)))
James Smart92d7f7b2007-06-17 19:56:38 -0500523 lpfc_unreg_rpi(vport, ndlp);
524
525 /* Leave Fabric nodes alone on link down */
526 if (!remove && ndlp->nlp_type & NLP_FABRIC)
527 continue;
528 rc = lpfc_disc_state_machine(vport, ndlp, NULL,
529 remove
530 ? NLP_EVT_DEVICE_RM
531 : NLP_EVT_DEVICE_RECOVERY);
532 }
533 if (phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) {
534 lpfc_mbx_unreg_vpi(vport);
James Smart09372822008-01-11 01:52:54 -0500535 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500536 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
James Smart09372822008-01-11 01:52:54 -0500537 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500538 }
539}
540
James Smart87af33f2007-10-27 13:37:43 -0400541void
James Smart98c9ea52007-10-27 13:37:33 -0400542lpfc_port_link_failure(struct lpfc_vport *vport)
James Smart92d7f7b2007-06-17 19:56:38 -0500543{
James Smart92d7f7b2007-06-17 19:56:38 -0500544 /* Cleanup any outstanding RSCN activity */
545 lpfc_els_flush_rscn(vport);
546
547 /* Cleanup any outstanding ELS commands */
548 lpfc_els_flush_cmd(vport);
549
550 lpfc_cleanup_rpis(vport, 0);
551
James Smart92d7f7b2007-06-17 19:56:38 -0500552 /* Turn off discovery timer if its running */
553 lpfc_can_disctmo(vport);
554}
555
James Smart98c9ea52007-10-27 13:37:33 -0400556static void
557lpfc_linkdown_port(struct lpfc_vport *vport)
558{
559 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
560
561 fc_host_post_event(shost, fc_get_event_number(), FCH_EVT_LINKDOWN, 0);
562
563 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
564 "Link Down: state:x%x rtry:x%x flg:x%x",
565 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
566
567 lpfc_port_link_failure(vport);
568
569}
570
dea31012005-04-17 16:05:31 -0500571int
James Smart685f0bf2007-04-25 09:53:08 -0400572lpfc_linkdown(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500573{
James Smart2e0fef82007-06-17 19:56:36 -0500574 struct lpfc_vport *vport = phba->pport;
575 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart549e55c2007-08-02 11:09:51 -0400576 struct lpfc_vport **vports;
James Smart685f0bf2007-04-25 09:53:08 -0400577 LPFC_MBOXQ_t *mb;
James Smart549e55c2007-08-02 11:09:51 -0400578 int i;
dea31012005-04-17 16:05:31 -0500579
James Smart3163f722008-02-08 18:50:25 -0500580 if (phba->link_state == LPFC_LINK_DOWN)
James Smart2e0fef82007-06-17 19:56:36 -0500581 return 0;
James Smart2e0fef82007-06-17 19:56:36 -0500582 spin_lock_irq(&phba->hbalock);
James Smart92d7f7b2007-06-17 19:56:38 -0500583 if (phba->link_state > LPFC_LINK_DOWN) {
James Smart2e0fef82007-06-17 19:56:36 -0500584 phba->link_state = LPFC_LINK_DOWN;
James Smart92d7f7b2007-06-17 19:56:38 -0500585 phba->pport->fc_flag &= ~FC_LBIT;
586 }
James Smart2e0fef82007-06-17 19:56:36 -0500587 spin_unlock_irq(&phba->hbalock);
James Smart549e55c2007-08-02 11:09:51 -0400588 vports = lpfc_create_vport_work_array(phba);
589 if (vports != NULL)
James Smart09372822008-01-11 01:52:54 -0500590 for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++) {
James Smart549e55c2007-08-02 11:09:51 -0400591 /* Issue a LINK DOWN event to all nodes */
592 lpfc_linkdown_port(vports[i]);
593 }
James Smart09372822008-01-11 01:52:54 -0500594 lpfc_destroy_vport_work_array(phba, vports);
dea31012005-04-17 16:05:31 -0500595 /* Clean up any firmware default rpi's */
James Smart2e0fef82007-06-17 19:56:36 -0500596 mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
597 if (mb) {
James Smart92d7f7b2007-06-17 19:56:38 -0500598 lpfc_unreg_did(phba, 0xffff, 0xffffffff, mb);
James Smarted957682007-06-17 19:56:37 -0500599 mb->vport = vport;
James Smart2e0fef82007-06-17 19:56:36 -0500600 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart0b727fe2007-10-27 13:37:25 -0400601 if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT)
dea31012005-04-17 16:05:31 -0500602 == MBX_NOT_FINISHED) {
James Smart2e0fef82007-06-17 19:56:36 -0500603 mempool_free(mb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500604 }
605 }
606
dea31012005-04-17 16:05:31 -0500607 /* Setup myDID for link up if we are in pt2pt mode */
James Smart92d7f7b2007-06-17 19:56:38 -0500608 if (phba->pport->fc_flag & FC_PT2PT) {
609 phba->pport->fc_myDID = 0;
James Smart2e0fef82007-06-17 19:56:36 -0500610 mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
611 if (mb) {
dea31012005-04-17 16:05:31 -0500612 lpfc_config_link(phba, mb);
James Smart92d7f7b2007-06-17 19:56:38 -0500613 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -0500614 mb->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -0400615 if (lpfc_sli_issue_mbox(phba, mb, MBX_NOWAIT)
dea31012005-04-17 16:05:31 -0500616 == MBX_NOT_FINISHED) {
James Smart2e0fef82007-06-17 19:56:36 -0500617 mempool_free(mb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500618 }
619 }
James Smart2e0fef82007-06-17 19:56:36 -0500620 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500621 phba->pport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI);
James Smart2e0fef82007-06-17 19:56:36 -0500622 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500623 }
James Smart2e0fef82007-06-17 19:56:36 -0500624
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500625 return 0;
dea31012005-04-17 16:05:31 -0500626}
627
James Smart92d7f7b2007-06-17 19:56:38 -0500628static void
629lpfc_linkup_cleanup_nodes(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -0500630{
James Smart92d7f7b2007-06-17 19:56:38 -0500631 struct lpfc_nodelist *ndlp;
632
633 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -0500634 if (!NLP_CHK_NODE_ACT(ndlp))
635 continue;
James Smart92d7f7b2007-06-17 19:56:38 -0500636 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
637 continue;
James Smart92d7f7b2007-06-17 19:56:38 -0500638 if (ndlp->nlp_type & NLP_FABRIC) {
James Smarte47c9092008-02-08 18:49:26 -0500639 /* On Linkup its safe to clean up the ndlp
640 * from Fabric connections.
641 */
James Smart92d7f7b2007-06-17 19:56:38 -0500642 if (ndlp->nlp_DID != Fabric_DID)
643 lpfc_unreg_rpi(vport, ndlp);
644 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
645 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
James Smarte47c9092008-02-08 18:49:26 -0500646 /* Fail outstanding IO now since device is
647 * marked for PLOGI.
648 */
James Smart92d7f7b2007-06-17 19:56:38 -0500649 lpfc_unreg_rpi(vport, ndlp);
650 }
651 }
652}
653
654static void
655lpfc_linkup_port(struct lpfc_vport *vport)
656{
657 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart92d7f7b2007-06-17 19:56:38 -0500658 struct lpfc_hba *phba = vport->phba;
659
660 if ((vport->load_flag & FC_UNLOADING) != 0)
661 return;
662
James Smart858c9f62007-06-17 19:56:39 -0500663 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
664 "Link Up: top:x%x speed:x%x flg:x%x",
665 phba->fc_topology, phba->fc_linkspeed, phba->link_flag);
666
James Smart92d7f7b2007-06-17 19:56:38 -0500667 /* If NPIV is not enabled, only bring the physical port up */
668 if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
669 (vport != phba->pport))
670 return;
dea31012005-04-17 16:05:31 -0500671
James Smart2e0fef82007-06-17 19:56:36 -0500672 fc_host_post_event(shost, fc_get_event_number(), FCH_EVT_LINKUP, 0);
James Smartd2873e42006-08-18 17:46:43 -0400673
James Smart2e0fef82007-06-17 19:56:36 -0500674 spin_lock_irq(shost->host_lock);
James Smart2e0fef82007-06-17 19:56:36 -0500675 vport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI | FC_ABORT_DISCOVERY |
676 FC_RSCN_MODE | FC_NLP_MORE | FC_RSCN_DISCOVERY);
677 vport->fc_flag |= FC_NDISC_ACTIVE;
678 vport->fc_ns_retry = 0;
679 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500680
James Smart92d7f7b2007-06-17 19:56:38 -0500681 if (vport->fc_flag & FC_LBIT)
682 lpfc_linkup_cleanup_nodes(vport);
dea31012005-04-17 16:05:31 -0500683
James Smart92d7f7b2007-06-17 19:56:38 -0500684}
685
686static int
687lpfc_linkup(struct lpfc_hba *phba)
688{
James Smart549e55c2007-08-02 11:09:51 -0400689 struct lpfc_vport **vports;
690 int i;
James Smart92d7f7b2007-06-17 19:56:38 -0500691
692 phba->link_state = LPFC_LINK_UP;
693
694 /* Unblock fabric iocbs if they are blocked */
695 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
696 del_timer_sync(&phba->fabric_block_timer);
697
James Smart549e55c2007-08-02 11:09:51 -0400698 vports = lpfc_create_vport_work_array(phba);
699 if (vports != NULL)
James Smart09372822008-01-11 01:52:54 -0500700 for(i = 0; i <= phba->max_vpi && vports[i] != NULL; i++)
James Smart549e55c2007-08-02 11:09:51 -0400701 lpfc_linkup_port(vports[i]);
James Smart09372822008-01-11 01:52:54 -0500702 lpfc_destroy_vport_work_array(phba, vports);
James Smart92d7f7b2007-06-17 19:56:38 -0500703 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
704 lpfc_issue_clear_la(phba, phba->pport);
dea31012005-04-17 16:05:31 -0500705
706 return 0;
707}
708
709/*
710 * This routine handles processing a CLEAR_LA mailbox
711 * command upon completion. It is setup in the LPFC_MBOXQ
712 * as the completion routine when the command is
713 * handed off to the SLI layer.
714 */
Adrian Bunka6ababd2007-11-05 18:07:33 +0100715static void
James Smart2e0fef82007-06-17 19:56:36 -0500716lpfc_mbx_cmpl_clear_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -0500717{
James Smart2e0fef82007-06-17 19:56:36 -0500718 struct lpfc_vport *vport = pmb->vport;
719 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
720 struct lpfc_sli *psli = &phba->sli;
721 MAILBOX_t *mb = &pmb->mb;
dea31012005-04-17 16:05:31 -0500722 uint32_t control;
723
dea31012005-04-17 16:05:31 -0500724 /* Since we don't do discovery right now, turn these off here */
James Smarta4bc3372006-12-02 13:34:16 -0500725 psli->ring[psli->extra_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
dea31012005-04-17 16:05:31 -0500726 psli->ring[psli->fcp_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
727 psli->ring[psli->next_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
728
729 /* Check for error */
730 if ((mb->mbxStatus) && (mb->mbxStatus != 0x1601)) {
James Smart92d7f7b2007-06-17 19:56:38 -0500731 /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */
James Smarte8b62012007-08-02 11:10:09 -0400732 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
733 "0320 CLEAR_LA mbxStatus error x%x hba "
734 "state x%x\n",
735 mb->mbxStatus, vport->port_state);
James Smart2e0fef82007-06-17 19:56:36 -0500736 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500737 goto out;
738 }
739
James Smart92d7f7b2007-06-17 19:56:38 -0500740 if (vport->port_type == LPFC_PHYSICAL_PORT)
741 phba->link_state = LPFC_HBA_READY;
742
743 spin_lock_irq(&phba->hbalock);
744 psli->sli_flag |= LPFC_PROCESS_LA;
745 control = readl(phba->HCregaddr);
746 control |= HC_LAINT_ENA;
747 writel(control, phba->HCregaddr);
748 readl(phba->HCregaddr); /* flush */
749 spin_unlock_irq(&phba->hbalock);
James Smart1b32f6a2008-02-08 18:49:39 -0500750 mempool_free(pmb, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -0500751 return;
dea31012005-04-17 16:05:31 -0500752
dea31012005-04-17 16:05:31 -0500753out:
754 /* Device Discovery completes */
James Smarte8b62012007-08-02 11:10:09 -0400755 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
756 "0225 Device Discovery completes\n");
James Smart2e0fef82007-06-17 19:56:36 -0500757 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500758
James Smart2e0fef82007-06-17 19:56:36 -0500759 spin_lock_irq(shost->host_lock);
James Smart58da1ff2008-04-07 10:15:56 -0400760 vport->fc_flag &= ~FC_ABORT_DISCOVERY;
James Smart2e0fef82007-06-17 19:56:36 -0500761 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500762
James Smart2e0fef82007-06-17 19:56:36 -0500763 lpfc_can_disctmo(vport);
dea31012005-04-17 16:05:31 -0500764
765 /* turn on Link Attention interrupts */
James Smart2e0fef82007-06-17 19:56:36 -0500766
767 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500768 psli->sli_flag |= LPFC_PROCESS_LA;
769 control = readl(phba->HCregaddr);
770 control |= HC_LAINT_ENA;
771 writel(control, phba->HCregaddr);
772 readl(phba->HCregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -0500773 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500774
775 return;
776}
777
James Smart2e0fef82007-06-17 19:56:36 -0500778
dea31012005-04-17 16:05:31 -0500779static void
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500780lpfc_mbx_cmpl_local_config_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -0500781{
James Smart2e0fef82007-06-17 19:56:36 -0500782 struct lpfc_vport *vport = pmb->vport;
dea31012005-04-17 16:05:31 -0500783
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500784 if (pmb->mb.mbxStatus)
dea31012005-04-17 16:05:31 -0500785 goto out;
dea31012005-04-17 16:05:31 -0500786
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500787 mempool_free(pmb, phba->mbox_mem_pool);
788
789 if (phba->fc_topology == TOPOLOGY_LOOP &&
James Smart2e0fef82007-06-17 19:56:36 -0500790 vport->fc_flag & FC_PUBLIC_LOOP &&
791 !(vport->fc_flag & FC_LBIT)) {
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500792 /* Need to wait for FAN - use discovery timer
James Smart2e0fef82007-06-17 19:56:36 -0500793 * for timeout. port_state is identically
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500794 * LPFC_LOCAL_CFG_LINK while waiting for FAN
795 */
James Smart2e0fef82007-06-17 19:56:36 -0500796 lpfc_set_disctmo(vport);
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500797 return;
James Smart92d7f7b2007-06-17 19:56:38 -0500798 }
dea31012005-04-17 16:05:31 -0500799
James Smart2e0fef82007-06-17 19:56:36 -0500800 /* Start discovery by sending a FLOGI. port_state is identically
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500801 * LPFC_FLOGI while waiting for FLOGI cmpl
802 */
James Smart92d7f7b2007-06-17 19:56:38 -0500803 if (vport->port_state != LPFC_FLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -0500804 lpfc_initial_flogi(vport);
805 }
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500806 return;
dea31012005-04-17 16:05:31 -0500807
808out:
James Smarte8b62012007-08-02 11:10:09 -0400809 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
810 "0306 CONFIG_LINK mbxStatus error x%x "
811 "HBA state x%x\n",
812 pmb->mb.mbxStatus, vport->port_state);
James Smart92d7f7b2007-06-17 19:56:38 -0500813 mempool_free(pmb, phba->mbox_mem_pool);
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500814
815 lpfc_linkdown(phba);
816
James Smarte8b62012007-08-02 11:10:09 -0400817 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
818 "0200 CONFIG_LINK bad hba state x%x\n",
819 vport->port_state);
dea31012005-04-17 16:05:31 -0500820
James Smart92d7f7b2007-06-17 19:56:38 -0500821 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -0500822 return;
823}
824
825static void
James Smart2e0fef82007-06-17 19:56:36 -0500826lpfc_mbx_cmpl_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -0500827{
dea31012005-04-17 16:05:31 -0500828 MAILBOX_t *mb = &pmb->mb;
829 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) pmb->context1;
James Smart2e0fef82007-06-17 19:56:36 -0500830 struct lpfc_vport *vport = pmb->vport;
dea31012005-04-17 16:05:31 -0500831
832
833 /* Check for error */
834 if (mb->mbxStatus) {
835 /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */
James Smarte8b62012007-08-02 11:10:09 -0400836 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
837 "0319 READ_SPARAM mbxStatus error x%x "
838 "hba state x%x>\n",
839 mb->mbxStatus, vport->port_state);
dea31012005-04-17 16:05:31 -0500840 lpfc_linkdown(phba);
dea31012005-04-17 16:05:31 -0500841 goto out;
842 }
843
James Smart2e0fef82007-06-17 19:56:36 -0500844 memcpy((uint8_t *) &vport->fc_sparam, (uint8_t *) mp->virt,
dea31012005-04-17 16:05:31 -0500845 sizeof (struct serv_parm));
James Smarta12e07b2006-12-02 13:35:30 -0500846 if (phba->cfg_soft_wwnn)
James Smart2e0fef82007-06-17 19:56:36 -0500847 u64_to_wwn(phba->cfg_soft_wwnn,
848 vport->fc_sparam.nodeName.u.wwn);
James Smartc3f28af2006-08-18 17:47:18 -0400849 if (phba->cfg_soft_wwpn)
James Smart2e0fef82007-06-17 19:56:36 -0500850 u64_to_wwn(phba->cfg_soft_wwpn,
851 vport->fc_sparam.portName.u.wwn);
James Smart92d7f7b2007-06-17 19:56:38 -0500852 memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
853 sizeof(vport->fc_nodename));
854 memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
855 sizeof(vport->fc_portname));
856 if (vport->port_type == LPFC_PHYSICAL_PORT) {
857 memcpy(&phba->wwnn, &vport->fc_nodename, sizeof(phba->wwnn));
858 memcpy(&phba->wwpn, &vport->fc_portname, sizeof(phba->wwnn));
859 }
860
dea31012005-04-17 16:05:31 -0500861 lpfc_mbuf_free(phba, mp->virt, mp->phys);
862 kfree(mp);
James Smart2e0fef82007-06-17 19:56:36 -0500863 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500864 return;
865
866out:
867 pmb->context1 = NULL;
868 lpfc_mbuf_free(phba, mp->virt, mp->phys);
869 kfree(mp);
James Smart92d7f7b2007-06-17 19:56:38 -0500870 lpfc_issue_clear_la(phba, vport);
871 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500872 return;
873}
874
875static void
James Smart92d7f7b2007-06-17 19:56:38 -0500876lpfc_mbx_process_link_up(struct lpfc_hba *phba, READ_LA_VAR *la)
dea31012005-04-17 16:05:31 -0500877{
James Smart92d7f7b2007-06-17 19:56:38 -0500878 struct lpfc_vport *vport = phba->pport;
dea31012005-04-17 16:05:31 -0500879 LPFC_MBOXQ_t *sparam_mbox, *cfglink_mbox;
James Smart2e0fef82007-06-17 19:56:36 -0500880 int i;
James Smart14691152006-12-02 13:34:28 -0500881 struct lpfc_dmabuf *mp;
882 int rc;
883
dea31012005-04-17 16:05:31 -0500884 sparam_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
885 cfglink_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
886
James Smart92d7f7b2007-06-17 19:56:38 -0500887 spin_lock_irq(&phba->hbalock);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500888 switch (la->UlnkSpeed) {
James Smart92d7f7b2007-06-17 19:56:38 -0500889 case LA_1GHZ_LINK:
890 phba->fc_linkspeed = LA_1GHZ_LINK;
891 break;
892 case LA_2GHZ_LINK:
893 phba->fc_linkspeed = LA_2GHZ_LINK;
894 break;
895 case LA_4GHZ_LINK:
896 phba->fc_linkspeed = LA_4GHZ_LINK;
897 break;
898 case LA_8GHZ_LINK:
899 phba->fc_linkspeed = LA_8GHZ_LINK;
900 break;
901 default:
902 phba->fc_linkspeed = LA_UNKNW_LINK;
903 break;
dea31012005-04-17 16:05:31 -0500904 }
905
906 phba->fc_topology = la->topology;
James Smart92d7f7b2007-06-17 19:56:38 -0500907 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
dea31012005-04-17 16:05:31 -0500908
909 if (phba->fc_topology == TOPOLOGY_LOOP) {
James Smart92d7f7b2007-06-17 19:56:38 -0500910 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
dea31012005-04-17 16:05:31 -0500911
James Smart495a7142008-06-14 22:52:59 -0400912 if (phba->cfg_enable_npiv)
913 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
914 "1309 Link Up Event npiv not supported in loop "
915 "topology\n");
James Smart92d7f7b2007-06-17 19:56:38 -0500916 /* Get Loop Map information */
dea31012005-04-17 16:05:31 -0500917 if (la->il)
James Smart2e0fef82007-06-17 19:56:36 -0500918 vport->fc_flag |= FC_LBIT;
dea31012005-04-17 16:05:31 -0500919
James Smart2e0fef82007-06-17 19:56:36 -0500920 vport->fc_myDID = la->granted_AL_PA;
dea31012005-04-17 16:05:31 -0500921 i = la->un.lilpBde64.tus.f.bdeSize;
922
923 if (i == 0) {
924 phba->alpa_map[0] = 0;
925 } else {
James Smarte8b62012007-08-02 11:10:09 -0400926 if (vport->cfg_log_verbose & LOG_LINK_EVENT) {
dea31012005-04-17 16:05:31 -0500927 int numalpa, j, k;
928 union {
929 uint8_t pamap[16];
930 struct {
931 uint32_t wd1;
932 uint32_t wd2;
933 uint32_t wd3;
934 uint32_t wd4;
935 } pa;
936 } un;
937 numalpa = phba->alpa_map[0];
938 j = 0;
939 while (j < numalpa) {
940 memset(un.pamap, 0, 16);
941 for (k = 1; j < numalpa; k++) {
942 un.pamap[k - 1] =
943 phba->alpa_map[j + 1];
944 j++;
945 if (k == 16)
946 break;
947 }
948 /* Link Up Event ALPA map */
949 lpfc_printf_log(phba,
James Smart92d7f7b2007-06-17 19:56:38 -0500950 KERN_WARNING,
951 LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -0400952 "1304 Link Up Event "
James Smart92d7f7b2007-06-17 19:56:38 -0500953 "ALPA map Data: x%x "
954 "x%x x%x x%x\n",
James Smart92d7f7b2007-06-17 19:56:38 -0500955 un.pa.wd1, un.pa.wd2,
956 un.pa.wd3, un.pa.wd4);
dea31012005-04-17 16:05:31 -0500957 }
958 }
959 }
960 } else {
James Smart92d7f7b2007-06-17 19:56:38 -0500961 if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)) {
James Smart78b2d852007-08-02 11:10:21 -0400962 if (phba->max_vpi && phba->cfg_enable_npiv &&
James Smart92d7f7b2007-06-17 19:56:38 -0500963 (phba->sli_rev == 3))
964 phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
965 }
James Smart2e0fef82007-06-17 19:56:36 -0500966 vport->fc_myDID = phba->fc_pref_DID;
967 vport->fc_flag |= FC_LBIT;
dea31012005-04-17 16:05:31 -0500968 }
James Smart92d7f7b2007-06-17 19:56:38 -0500969 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500970
971 lpfc_linkup(phba);
972 if (sparam_mbox) {
James Smart92d7f7b2007-06-17 19:56:38 -0500973 lpfc_read_sparam(phba, sparam_mbox, 0);
James Smart2e0fef82007-06-17 19:56:36 -0500974 sparam_mbox->vport = vport;
dea31012005-04-17 16:05:31 -0500975 sparam_mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam;
James Smart0b727fe2007-10-27 13:37:25 -0400976 rc = lpfc_sli_issue_mbox(phba, sparam_mbox, MBX_NOWAIT);
James Smart14691152006-12-02 13:34:28 -0500977 if (rc == MBX_NOT_FINISHED) {
978 mp = (struct lpfc_dmabuf *) sparam_mbox->context1;
979 lpfc_mbuf_free(phba, mp->virt, mp->phys);
980 kfree(mp);
981 mempool_free(sparam_mbox, phba->mbox_mem_pool);
982 if (cfglink_mbox)
983 mempool_free(cfglink_mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -0500984 goto out;
James Smart14691152006-12-02 13:34:28 -0500985 }
dea31012005-04-17 16:05:31 -0500986 }
987
988 if (cfglink_mbox) {
James Smart2e0fef82007-06-17 19:56:36 -0500989 vport->port_state = LPFC_LOCAL_CFG_LINK;
dea31012005-04-17 16:05:31 -0500990 lpfc_config_link(phba, cfglink_mbox);
James Smart2e0fef82007-06-17 19:56:36 -0500991 cfglink_mbox->vport = vport;
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500992 cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
James Smart0b727fe2007-10-27 13:37:25 -0400993 rc = lpfc_sli_issue_mbox(phba, cfglink_mbox, MBX_NOWAIT);
James Smart92d7f7b2007-06-17 19:56:38 -0500994 if (rc != MBX_NOT_FINISHED)
995 return;
996 mempool_free(cfglink_mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500997 }
James Smart92d7f7b2007-06-17 19:56:38 -0500998out:
999 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04001000 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
1001 "0263 Discovery Mailbox error: state: 0x%x : %p %p\n",
1002 vport->port_state, sparam_mbox, cfglink_mbox);
James Smart92d7f7b2007-06-17 19:56:38 -05001003 lpfc_issue_clear_la(phba, vport);
1004 return;
dea31012005-04-17 16:05:31 -05001005}
1006
1007static void
James Smart2e0fef82007-06-17 19:56:36 -05001008lpfc_mbx_issue_link_down(struct lpfc_hba *phba)
1009{
dea31012005-04-17 16:05:31 -05001010 uint32_t control;
1011 struct lpfc_sli *psli = &phba->sli;
1012
1013 lpfc_linkdown(phba);
1014
1015 /* turn on Link Attention interrupts - no CLEAR_LA needed */
James Smart2e0fef82007-06-17 19:56:36 -05001016 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001017 psli->sli_flag |= LPFC_PROCESS_LA;
1018 control = readl(phba->HCregaddr);
1019 control |= HC_LAINT_ENA;
1020 writel(control, phba->HCregaddr);
1021 readl(phba->HCregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05001022 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001023}
1024
1025/*
1026 * This routine handles processing a READ_LA mailbox
1027 * command upon completion. It is setup in the LPFC_MBOXQ
1028 * as the completion routine when the command is
1029 * handed off to the SLI layer.
1030 */
1031void
James Smart2e0fef82007-06-17 19:56:36 -05001032lpfc_mbx_cmpl_read_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05001033{
James Smart2e0fef82007-06-17 19:56:36 -05001034 struct lpfc_vport *vport = pmb->vport;
1035 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001036 READ_LA_VAR *la;
1037 MAILBOX_t *mb = &pmb->mb;
1038 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
1039
James Smart0d2b6b82008-06-14 22:52:47 -04001040 /* Unblock ELS traffic */
1041 phba->sli.ring[LPFC_ELS_RING].flag &= ~LPFC_STOP_IOCB_EVENT;
dea31012005-04-17 16:05:31 -05001042 /* Check for error */
1043 if (mb->mbxStatus) {
James Smarted957682007-06-17 19:56:37 -05001044 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04001045 "1307 READ_LA mbox error x%x state x%x\n",
1046 mb->mbxStatus, vport->port_state);
dea31012005-04-17 16:05:31 -05001047 lpfc_mbx_issue_link_down(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001048 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05001049 goto lpfc_mbx_cmpl_read_la_free_mbuf;
1050 }
1051
1052 la = (READ_LA_VAR *) & pmb->mb.un.varReadLA;
1053
1054 memcpy(&phba->alpa_map[0], mp->virt, 128);
1055
James Smart2e0fef82007-06-17 19:56:36 -05001056 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001057 if (la->pb)
James Smart2e0fef82007-06-17 19:56:36 -05001058 vport->fc_flag |= FC_BYPASSED_MODE;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001059 else
James Smart2e0fef82007-06-17 19:56:36 -05001060 vport->fc_flag &= ~FC_BYPASSED_MODE;
1061 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001062
dea31012005-04-17 16:05:31 -05001063 if (((phba->fc_eventTag + 1) < la->eventTag) ||
James Smart92d7f7b2007-06-17 19:56:38 -05001064 (phba->fc_eventTag == la->eventTag)) {
dea31012005-04-17 16:05:31 -05001065 phba->fc_stat.LinkMultiEvent++;
James Smart2e0fef82007-06-17 19:56:36 -05001066 if (la->attType == AT_LINK_UP)
dea31012005-04-17 16:05:31 -05001067 if (phba->fc_eventTag != 0)
1068 lpfc_linkdown(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05001069 }
dea31012005-04-17 16:05:31 -05001070
1071 phba->fc_eventTag = la->eventTag;
1072
1073 if (la->attType == AT_LINK_UP) {
1074 phba->fc_stat.LinkUp++;
James Smart2e0fef82007-06-17 19:56:36 -05001075 if (phba->link_flag & LS_LOOPBACK_MODE) {
James Smart3163f722008-02-08 18:50:25 -05001076 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04001077 "1306 Link Up Event in loop back mode "
1078 "x%x received Data: x%x x%x x%x x%x\n",
1079 la->eventTag, phba->fc_eventTag,
1080 la->granted_AL_PA, la->UlnkSpeed,
1081 phba->alpa_map[0]);
James Smart5b8bd0c2007-04-25 09:52:49 -04001082 } else {
1083 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04001084 "1303 Link Up Event x%x received "
1085 "Data: x%x x%x x%x x%x\n",
1086 la->eventTag, phba->fc_eventTag,
1087 la->granted_AL_PA, la->UlnkSpeed,
1088 phba->alpa_map[0]);
James Smart5b8bd0c2007-04-25 09:52:49 -04001089 }
James Smart92d7f7b2007-06-17 19:56:38 -05001090 lpfc_mbx_process_link_up(phba, la);
dea31012005-04-17 16:05:31 -05001091 } else {
1092 phba->fc_stat.LinkDown++;
James Smart3163f722008-02-08 18:50:25 -05001093 if (phba->link_flag & LS_LOOPBACK_MODE) {
1094 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
1095 "1308 Link Down Event in loop back mode "
1096 "x%x received "
1097 "Data: x%x x%x x%x\n",
1098 la->eventTag, phba->fc_eventTag,
1099 phba->pport->port_state, vport->fc_flag);
1100 }
1101 else {
1102 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
James Smarte8b62012007-08-02 11:10:09 -04001103 "1305 Link Down Event x%x received "
dea31012005-04-17 16:05:31 -05001104 "Data: x%x x%x x%x\n",
James Smarte8b62012007-08-02 11:10:09 -04001105 la->eventTag, phba->fc_eventTag,
James Smart2e0fef82007-06-17 19:56:36 -05001106 phba->pport->port_state, vport->fc_flag);
James Smart3163f722008-02-08 18:50:25 -05001107 }
dea31012005-04-17 16:05:31 -05001108 lpfc_mbx_issue_link_down(phba);
1109 }
1110
1111lpfc_mbx_cmpl_read_la_free_mbuf:
1112 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1113 kfree(mp);
1114 mempool_free(pmb, phba->mbox_mem_pool);
1115 return;
1116}
1117
1118/*
1119 * This routine handles processing a REG_LOGIN mailbox
1120 * command upon completion. It is setup in the LPFC_MBOXQ
1121 * as the completion routine when the command is
1122 * handed off to the SLI layer.
1123 */
1124void
James Smart2e0fef82007-06-17 19:56:36 -05001125lpfc_mbx_cmpl_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05001126{
James Smart2e0fef82007-06-17 19:56:36 -05001127 struct lpfc_vport *vport = pmb->vport;
James Smart92d7f7b2007-06-17 19:56:38 -05001128 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
James Smart2e0fef82007-06-17 19:56:36 -05001129 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
dea31012005-04-17 16:05:31 -05001130
dea31012005-04-17 16:05:31 -05001131 pmb->context1 = NULL;
1132
1133 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05001134 lpfc_disc_state_machine(vport, ndlp, pmb, NLP_EVT_CMPL_REG_LOGIN);
dea31012005-04-17 16:05:31 -05001135 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1136 kfree(mp);
James Smart2e0fef82007-06-17 19:56:36 -05001137 mempool_free(pmb, phba->mbox_mem_pool);
James Smartfa4066b2008-01-11 01:53:27 -05001138 /* decrement the node reference count held for this callback
1139 * function.
1140 */
James Smart329f9bc2007-04-25 09:53:01 -04001141 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001142
1143 return;
1144}
1145
James Smart92d7f7b2007-06-17 19:56:38 -05001146static void
1147lpfc_mbx_cmpl_unreg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
1148{
1149 MAILBOX_t *mb = &pmb->mb;
1150 struct lpfc_vport *vport = pmb->vport;
1151 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1152
1153 switch (mb->mbxStatus) {
1154 case 0x0011:
1155 case 0x0020:
1156 case 0x9700:
James Smarte8b62012007-08-02 11:10:09 -04001157 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
1158 "0911 cmpl_unreg_vpi, mb status = 0x%x\n",
1159 mb->mbxStatus);
James Smart92d7f7b2007-06-17 19:56:38 -05001160 break;
James Smart92d7f7b2007-06-17 19:56:38 -05001161 }
1162 vport->unreg_vpi_cmpl = VPORT_OK;
1163 mempool_free(pmb, phba->mbox_mem_pool);
1164 /*
1165 * This shost reference might have been taken at the beginning of
1166 * lpfc_vport_delete()
1167 */
1168 if (vport->load_flag & FC_UNLOADING)
1169 scsi_host_put(shost);
1170}
1171
1172void
1173lpfc_mbx_unreg_vpi(struct lpfc_vport *vport)
1174{
1175 struct lpfc_hba *phba = vport->phba;
1176 LPFC_MBOXQ_t *mbox;
1177 int rc;
1178
1179 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1180 if (!mbox)
1181 return;
1182
1183 lpfc_unreg_vpi(phba, vport->vpi, mbox);
1184 mbox->vport = vport;
1185 mbox->mbox_cmpl = lpfc_mbx_cmpl_unreg_vpi;
James Smart0b727fe2007-10-27 13:37:25 -04001186 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart92d7f7b2007-06-17 19:56:38 -05001187 if (rc == MBX_NOT_FINISHED) {
James Smarte8b62012007-08-02 11:10:09 -04001188 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT,
1189 "1800 Could not issue unreg_vpi\n");
James Smart92d7f7b2007-06-17 19:56:38 -05001190 mempool_free(mbox, phba->mbox_mem_pool);
1191 vport->unreg_vpi_cmpl = VPORT_ERROR;
1192 }
1193}
1194
1195static void
1196lpfc_mbx_cmpl_reg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
1197{
1198 struct lpfc_vport *vport = pmb->vport;
1199 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1200 MAILBOX_t *mb = &pmb->mb;
1201
1202 switch (mb->mbxStatus) {
1203 case 0x0011:
1204 case 0x9601:
1205 case 0x9602:
James Smarte8b62012007-08-02 11:10:09 -04001206 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
1207 "0912 cmpl_reg_vpi, mb status = 0x%x\n",
1208 mb->mbxStatus);
James Smart92d7f7b2007-06-17 19:56:38 -05001209 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
1210 spin_lock_irq(shost->host_lock);
1211 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
1212 spin_unlock_irq(shost->host_lock);
1213 vport->fc_myDID = 0;
1214 goto out;
1215 }
James Smart92d7f7b2007-06-17 19:56:38 -05001216
1217 vport->num_disc_nodes = 0;
1218 /* go thru NPR list and issue ELS PLOGIs */
1219 if (vport->fc_npr_cnt)
1220 lpfc_els_disc_plogi(vport);
1221
1222 if (!vport->num_disc_nodes) {
1223 spin_lock_irq(shost->host_lock);
1224 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1225 spin_unlock_irq(shost->host_lock);
1226 lpfc_can_disctmo(vport);
1227 }
1228 vport->port_state = LPFC_VPORT_READY;
1229
1230out:
1231 mempool_free(pmb, phba->mbox_mem_pool);
1232 return;
1233}
1234
dea31012005-04-17 16:05:31 -05001235/*
1236 * This routine handles processing a Fabric REG_LOGIN mailbox
1237 * command upon completion. It is setup in the LPFC_MBOXQ
1238 * as the completion routine when the command is
1239 * handed off to the SLI layer.
1240 */
1241void
James Smart2e0fef82007-06-17 19:56:36 -05001242lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05001243{
James Smart92d7f7b2007-06-17 19:56:38 -05001244 struct lpfc_vport *vport = pmb->vport;
James Smart2e0fef82007-06-17 19:56:36 -05001245 MAILBOX_t *mb = &pmb->mb;
1246 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
James Smart92d7f7b2007-06-17 19:56:38 -05001247 struct lpfc_nodelist *ndlp;
James Smart549e55c2007-08-02 11:09:51 -04001248 struct lpfc_vport **vports;
1249 int i;
dea31012005-04-17 16:05:31 -05001250
James Smart549e55c2007-08-02 11:09:51 -04001251 ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart329f9bc2007-04-25 09:53:01 -04001252 pmb->context1 = NULL;
1253 pmb->context2 = NULL;
dea31012005-04-17 16:05:31 -05001254 if (mb->mbxStatus) {
1255 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1256 kfree(mp);
James Smart329f9bc2007-04-25 09:53:01 -04001257 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05001258
James Smart92d7f7b2007-06-17 19:56:38 -05001259 if (phba->fc_topology == TOPOLOGY_LOOP) {
1260 /* FLOGI failed, use loop map to make discovery list */
1261 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -05001262
James Smart92d7f7b2007-06-17 19:56:38 -05001263 /* Start discovery */
1264 lpfc_disc_start(vport);
James Smarte47c9092008-02-08 18:49:26 -05001265 /* Decrement the reference count to ndlp after the
1266 * reference to the ndlp are done.
1267 */
1268 lpfc_nlp_put(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -05001269 return;
1270 }
1271
1272 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04001273 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX,
1274 "0258 Register Fabric login error: 0x%x\n",
1275 mb->mbxStatus);
James Smarte47c9092008-02-08 18:49:26 -05001276 /* Decrement the reference count to ndlp after the reference
1277 * to the ndlp are done.
1278 */
1279 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001280 return;
1281 }
1282
dea31012005-04-17 16:05:31 -05001283 ndlp->nlp_rpi = mb->un.varWords[0];
dea31012005-04-17 16:05:31 -05001284 ndlp->nlp_type |= NLP_FABRIC;
James Smart2e0fef82007-06-17 19:56:36 -05001285 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
dea31012005-04-17 16:05:31 -05001286
James Smart2e0fef82007-06-17 19:56:36 -05001287 if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
James Smart549e55c2007-08-02 11:09:51 -04001288 vports = lpfc_create_vport_work_array(phba);
1289 if (vports != NULL)
1290 for(i = 0;
James Smart09372822008-01-11 01:52:54 -05001291 i <= phba->max_vpi && vports[i] != NULL;
James Smart549e55c2007-08-02 11:09:51 -04001292 i++) {
1293 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
1294 continue;
James Smart58da1ff2008-04-07 10:15:56 -04001295 if (phba->fc_topology == TOPOLOGY_LOOP) {
1296 lpfc_vport_set_state(vports[i],
1297 FC_VPORT_LINKDOWN);
1298 continue;
1299 }
James Smart549e55c2007-08-02 11:09:51 -04001300 if (phba->link_flag & LS_NPIV_FAB_SUPPORTED)
1301 lpfc_initial_fdisc(vports[i]);
James Smart58da1ff2008-04-07 10:15:56 -04001302 else {
James Smart549e55c2007-08-02 11:09:51 -04001303 lpfc_vport_set_state(vports[i],
1304 FC_VPORT_NO_FABRIC_SUPP);
James Smarte8b62012007-08-02 11:10:09 -04001305 lpfc_printf_vlog(vport, KERN_ERR,
1306 LOG_ELS,
1307 "0259 No NPIV "
1308 "Fabric support\n");
James Smart549e55c2007-08-02 11:09:51 -04001309 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001310 }
James Smart09372822008-01-11 01:52:54 -05001311 lpfc_destroy_vport_work_array(phba, vports);
James Smart92d7f7b2007-06-17 19:56:38 -05001312 lpfc_do_scr_ns_plogi(phba, vport);
dea31012005-04-17 16:05:31 -05001313 }
1314
1315 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1316 kfree(mp);
James Smart329f9bc2007-04-25 09:53:01 -04001317 mempool_free(pmb, phba->mbox_mem_pool);
James Smarte47c9092008-02-08 18:49:26 -05001318
1319 /* Drop the reference count from the mbox at the end after
1320 * all the current reference to the ndlp have been done.
1321 */
1322 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001323 return;
1324}
1325
1326/*
1327 * This routine handles processing a NameServer REG_LOGIN mailbox
1328 * command upon completion. It is setup in the LPFC_MBOXQ
1329 * as the completion routine when the command is
1330 * handed off to the SLI layer.
1331 */
1332void
James Smart2e0fef82007-06-17 19:56:36 -05001333lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05001334{
James Smart2e0fef82007-06-17 19:56:36 -05001335 MAILBOX_t *mb = &pmb->mb;
1336 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
1337 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
1338 struct lpfc_vport *vport = pmb->vport;
dea31012005-04-17 16:05:31 -05001339
1340 if (mb->mbxStatus) {
James Smart92d7f7b2007-06-17 19:56:38 -05001341out:
James Smartfa4066b2008-01-11 01:53:27 -05001342 /* decrement the node reference count held for this
1343 * callback function.
1344 */
James Smart329f9bc2007-04-25 09:53:01 -04001345 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001346 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1347 kfree(mp);
James Smartde0c5b32007-04-25 09:52:27 -04001348 mempool_free(pmb, phba->mbox_mem_pool);
James Smart87af33f2007-10-27 13:37:43 -04001349
1350 /* If no other thread is using the ndlp, free it */
1351 lpfc_nlp_not_used(ndlp);
dea31012005-04-17 16:05:31 -05001352
James Smart92d7f7b2007-06-17 19:56:38 -05001353 if (phba->fc_topology == TOPOLOGY_LOOP) {
1354 /*
1355 * RegLogin failed, use loop map to make discovery
1356 * list
1357 */
1358 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -05001359
James Smart92d7f7b2007-06-17 19:56:38 -05001360 /* Start discovery */
1361 lpfc_disc_start(vport);
1362 return;
1363 }
1364 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
James Smarte8b62012007-08-02 11:10:09 -04001365 lpfc_printf_vlog(vport, KERN_ERR, LOG_ELS,
1366 "0260 Register NameServer error: 0x%x\n",
1367 mb->mbxStatus);
dea31012005-04-17 16:05:31 -05001368 return;
1369 }
1370
1371 pmb->context1 = NULL;
1372
dea31012005-04-17 16:05:31 -05001373 ndlp->nlp_rpi = mb->un.varWords[0];
dea31012005-04-17 16:05:31 -05001374 ndlp->nlp_type |= NLP_FABRIC;
James Smart2e0fef82007-06-17 19:56:36 -05001375 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
dea31012005-04-17 16:05:31 -05001376
James Smart2e0fef82007-06-17 19:56:36 -05001377 if (vport->port_state < LPFC_VPORT_READY) {
1378 /* Link up discovery requires Fabric registration. */
James Smart92d7f7b2007-06-17 19:56:38 -05001379 lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0, 0); /* Do this first! */
1380 lpfc_ns_cmd(vport, SLI_CTNS_RNN_ID, 0, 0);
1381 lpfc_ns_cmd(vport, SLI_CTNS_RSNN_NN, 0, 0);
1382 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
1383 lpfc_ns_cmd(vport, SLI_CTNS_RFT_ID, 0, 0);
1384
1385 /* Issue SCR just before NameServer GID_FT Query */
1386 lpfc_issue_els_scr(vport, SCR_DID, 0);
dea31012005-04-17 16:05:31 -05001387 }
1388
James Smart2e0fef82007-06-17 19:56:36 -05001389 vport->fc_ns_retry = 0;
dea31012005-04-17 16:05:31 -05001390 /* Good status, issue CT Request to NameServer */
James Smart92d7f7b2007-06-17 19:56:38 -05001391 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0)) {
dea31012005-04-17 16:05:31 -05001392 /* Cannot issue NameServer Query, so finish up discovery */
James Smart92d7f7b2007-06-17 19:56:38 -05001393 goto out;
dea31012005-04-17 16:05:31 -05001394 }
1395
James Smartfa4066b2008-01-11 01:53:27 -05001396 /* decrement the node reference count held for this
1397 * callback function.
1398 */
James Smart329f9bc2007-04-25 09:53:01 -04001399 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001400 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1401 kfree(mp);
James Smart2e0fef82007-06-17 19:56:36 -05001402 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05001403
1404 return;
1405}
1406
1407static void
James Smart2e0fef82007-06-17 19:56:36 -05001408lpfc_register_remote_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05001409{
James Smart2e0fef82007-06-17 19:56:36 -05001410 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1411 struct fc_rport *rport;
dea31012005-04-17 16:05:31 -05001412 struct lpfc_rport_data *rdata;
1413 struct fc_rport_identifiers rport_ids;
James Smart2e0fef82007-06-17 19:56:36 -05001414 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001415
1416 /* Remote port has reappeared. Re-register w/ FC transport */
Andrew Morton68ce1eb2005-09-21 09:46:54 -07001417 rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
1418 rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
dea31012005-04-17 16:05:31 -05001419 rport_ids.port_id = ndlp->nlp_DID;
1420 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
dea31012005-04-17 16:05:31 -05001421
James Smart329f9bc2007-04-25 09:53:01 -04001422 /*
1423 * We leave our node pointer in rport->dd_data when we unregister a
1424 * FCP target port. But fc_remote_port_add zeros the space to which
1425 * rport->dd_data points. So, if we're reusing a previously
1426 * registered port, drop the reference that we took the last time we
1427 * registered the port.
1428 */
1429 if (ndlp->rport && ndlp->rport->dd_data &&
James Smarte47c9092008-02-08 18:49:26 -05001430 ((struct lpfc_rport_data *) ndlp->rport->dd_data)->pnode == ndlp)
James Smart329f9bc2007-04-25 09:53:01 -04001431 lpfc_nlp_put(ndlp);
James Smart858c9f62007-06-17 19:56:39 -05001432
1433 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
1434 "rport add: did:x%x flg:x%x type x%x",
1435 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
1436
James Smart2e0fef82007-06-17 19:56:36 -05001437 ndlp->rport = rport = fc_remote_port_add(shost, 0, &rport_ids);
James Smart329f9bc2007-04-25 09:53:01 -04001438 if (!rport || !get_device(&rport->dev)) {
dea31012005-04-17 16:05:31 -05001439 dev_printk(KERN_WARNING, &phba->pcidev->dev,
1440 "Warning: fc_remote_port_add failed\n");
1441 return;
1442 }
1443
1444 /* initialize static port data */
1445 rport->maxframe_size = ndlp->nlp_maxframe;
1446 rport->supported_classes = ndlp->nlp_class_sup;
dea31012005-04-17 16:05:31 -05001447 rdata = rport->dd_data;
James Smart329f9bc2007-04-25 09:53:01 -04001448 rdata->pnode = lpfc_nlp_get(ndlp);
James.Smart@Emulex.Com23dc04f2005-11-28 11:41:44 -05001449
1450 if (ndlp->nlp_type & NLP_FCP_TARGET)
1451 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
1452 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
1453 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
1454
1455
1456 if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN)
1457 fc_remote_port_rolechg(rport, rport_ids.roles);
1458
James Smart071fbd3d2006-04-15 11:53:20 -04001459 if ((rport->scsi_target_id != -1) &&
James Smart92d7f7b2007-06-17 19:56:38 -05001460 (rport->scsi_target_id < LPFC_MAX_TARGET)) {
James Smart071fbd3d2006-04-15 11:53:20 -04001461 ndlp->nlp_sid = rport->scsi_target_id;
1462 }
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001463 return;
1464}
1465
1466static void
James Smart2e0fef82007-06-17 19:56:36 -05001467lpfc_unregister_remote_port(struct lpfc_nodelist *ndlp)
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001468{
1469 struct fc_rport *rport = ndlp->rport;
James Smartc01f3202006-08-18 17:47:08 -04001470
James Smart858c9f62007-06-17 19:56:39 -05001471 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_RPORT,
1472 "rport delete: did:x%x flg:x%x type x%x",
1473 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
1474
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001475 fc_remote_port_delete(rport);
dea31012005-04-17 16:05:31 -05001476
1477 return;
1478}
1479
James Smartde0c5b32007-04-25 09:52:27 -04001480static void
James Smart2e0fef82007-06-17 19:56:36 -05001481lpfc_nlp_counters(struct lpfc_vport *vport, int state, int count)
James Smartde0c5b32007-04-25 09:52:27 -04001482{
James Smart2e0fef82007-06-17 19:56:36 -05001483 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1484
1485 spin_lock_irq(shost->host_lock);
James Smartde0c5b32007-04-25 09:52:27 -04001486 switch (state) {
1487 case NLP_STE_UNUSED_NODE:
James Smart2e0fef82007-06-17 19:56:36 -05001488 vport->fc_unused_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04001489 break;
1490 case NLP_STE_PLOGI_ISSUE:
James Smart2e0fef82007-06-17 19:56:36 -05001491 vport->fc_plogi_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04001492 break;
1493 case NLP_STE_ADISC_ISSUE:
James Smart2e0fef82007-06-17 19:56:36 -05001494 vport->fc_adisc_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04001495 break;
1496 case NLP_STE_REG_LOGIN_ISSUE:
James Smart2e0fef82007-06-17 19:56:36 -05001497 vport->fc_reglogin_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04001498 break;
1499 case NLP_STE_PRLI_ISSUE:
James Smart2e0fef82007-06-17 19:56:36 -05001500 vport->fc_prli_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04001501 break;
1502 case NLP_STE_UNMAPPED_NODE:
James Smart2e0fef82007-06-17 19:56:36 -05001503 vport->fc_unmap_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04001504 break;
1505 case NLP_STE_MAPPED_NODE:
James Smart2e0fef82007-06-17 19:56:36 -05001506 vport->fc_map_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04001507 break;
1508 case NLP_STE_NPR_NODE:
James Smart2e0fef82007-06-17 19:56:36 -05001509 vport->fc_npr_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04001510 break;
1511 }
James Smart2e0fef82007-06-17 19:56:36 -05001512 spin_unlock_irq(shost->host_lock);
James Smartde0c5b32007-04-25 09:52:27 -04001513}
Jamie Wellnitz66a9ed62006-02-28 22:33:10 -05001514
James Smartde0c5b32007-04-25 09:52:27 -04001515static void
James Smart2e0fef82007-06-17 19:56:36 -05001516lpfc_nlp_state_cleanup(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04001517 int old_state, int new_state)
1518{
James Smart2e0fef82007-06-17 19:56:36 -05001519 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1520
James Smartde0c5b32007-04-25 09:52:27 -04001521 if (new_state == NLP_STE_UNMAPPED_NODE) {
1522 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
1523 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
1524 ndlp->nlp_type |= NLP_FC_NODE;
1525 }
1526 if (new_state == NLP_STE_MAPPED_NODE)
1527 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
1528 if (new_state == NLP_STE_NPR_NODE)
1529 ndlp->nlp_flag &= ~NLP_RCV_PLOGI;
dea31012005-04-17 16:05:31 -05001530
James Smartde0c5b32007-04-25 09:52:27 -04001531 /* Transport interface */
1532 if (ndlp->rport && (old_state == NLP_STE_MAPPED_NODE ||
1533 old_state == NLP_STE_UNMAPPED_NODE)) {
James Smart2e0fef82007-06-17 19:56:36 -05001534 vport->phba->nport_event_cnt++;
1535 lpfc_unregister_remote_port(ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04001536 }
dea31012005-04-17 16:05:31 -05001537
James Smartde0c5b32007-04-25 09:52:27 -04001538 if (new_state == NLP_STE_MAPPED_NODE ||
1539 new_state == NLP_STE_UNMAPPED_NODE) {
James Smart2e0fef82007-06-17 19:56:36 -05001540 vport->phba->nport_event_cnt++;
James Smart858c9f62007-06-17 19:56:39 -05001541 /*
1542 * Tell the fc transport about the port, if we haven't
1543 * already. If we have, and it's a scsi entity, be
1544 * sure to unblock any attached scsi devices
1545 */
1546 lpfc_register_remote_port(vport, ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04001547 }
James Smart858c9f62007-06-17 19:56:39 -05001548 /*
1549 * if we added to Mapped list, but the remote port
1550 * registration failed or assigned a target id outside
1551 * our presentable range - move the node to the
1552 * Unmapped List
1553 */
James Smartde0c5b32007-04-25 09:52:27 -04001554 if (new_state == NLP_STE_MAPPED_NODE &&
1555 (!ndlp->rport ||
1556 ndlp->rport->scsi_target_id == -1 ||
1557 ndlp->rport->scsi_target_id >= LPFC_MAX_TARGET)) {
James Smart2e0fef82007-06-17 19:56:36 -05001558 spin_lock_irq(shost->host_lock);
James Smartde0c5b32007-04-25 09:52:27 -04001559 ndlp->nlp_flag |= NLP_TGT_NO_SCSIID;
James Smart2e0fef82007-06-17 19:56:36 -05001560 spin_unlock_irq(shost->host_lock);
1561 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
dea31012005-04-17 16:05:31 -05001562 }
James Smartde0c5b32007-04-25 09:52:27 -04001563}
1564
James Smart685f0bf2007-04-25 09:53:08 -04001565static char *
1566lpfc_nlp_state_name(char *buffer, size_t size, int state)
1567{
1568 static char *states[] = {
1569 [NLP_STE_UNUSED_NODE] = "UNUSED",
1570 [NLP_STE_PLOGI_ISSUE] = "PLOGI",
1571 [NLP_STE_ADISC_ISSUE] = "ADISC",
1572 [NLP_STE_REG_LOGIN_ISSUE] = "REGLOGIN",
1573 [NLP_STE_PRLI_ISSUE] = "PRLI",
1574 [NLP_STE_UNMAPPED_NODE] = "UNMAPPED",
1575 [NLP_STE_MAPPED_NODE] = "MAPPED",
1576 [NLP_STE_NPR_NODE] = "NPR",
1577 };
1578
James Smart311464e2007-08-02 11:10:37 -04001579 if (state < NLP_STE_MAX_STATE && states[state])
James Smart685f0bf2007-04-25 09:53:08 -04001580 strlcpy(buffer, states[state], size);
1581 else
1582 snprintf(buffer, size, "unknown (%d)", state);
1583 return buffer;
1584}
1585
James Smartde0c5b32007-04-25 09:52:27 -04001586void
James Smart2e0fef82007-06-17 19:56:36 -05001587lpfc_nlp_set_state(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1588 int state)
James Smartde0c5b32007-04-25 09:52:27 -04001589{
James Smart2e0fef82007-06-17 19:56:36 -05001590 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smartde0c5b32007-04-25 09:52:27 -04001591 int old_state = ndlp->nlp_state;
James Smart685f0bf2007-04-25 09:53:08 -04001592 char name1[16], name2[16];
James Smartde0c5b32007-04-25 09:52:27 -04001593
James Smarte8b62012007-08-02 11:10:09 -04001594 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
1595 "0904 NPort state transition x%06x, %s -> %s\n",
1596 ndlp->nlp_DID,
1597 lpfc_nlp_state_name(name1, sizeof(name1), old_state),
1598 lpfc_nlp_state_name(name2, sizeof(name2), state));
James Smart858c9f62007-06-17 19:56:39 -05001599
1600 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
1601 "node statechg did:x%x old:%d ste:%d",
1602 ndlp->nlp_DID, old_state, state);
1603
James Smartde0c5b32007-04-25 09:52:27 -04001604 if (old_state == NLP_STE_NPR_NODE &&
James Smartde0c5b32007-04-25 09:52:27 -04001605 state != NLP_STE_NPR_NODE)
James Smart2e0fef82007-06-17 19:56:36 -05001606 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04001607 if (old_state == NLP_STE_UNMAPPED_NODE) {
1608 ndlp->nlp_flag &= ~NLP_TGT_NO_SCSIID;
1609 ndlp->nlp_type &= ~NLP_FC_NODE;
1610 }
1611
James Smart685f0bf2007-04-25 09:53:08 -04001612 if (list_empty(&ndlp->nlp_listp)) {
James Smart2e0fef82007-06-17 19:56:36 -05001613 spin_lock_irq(shost->host_lock);
1614 list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
1615 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04001616 } else if (old_state)
James Smart2e0fef82007-06-17 19:56:36 -05001617 lpfc_nlp_counters(vport, old_state, -1);
James Smartde0c5b32007-04-25 09:52:27 -04001618
1619 ndlp->nlp_state = state;
James Smart2e0fef82007-06-17 19:56:36 -05001620 lpfc_nlp_counters(vport, state, 1);
1621 lpfc_nlp_state_cleanup(vport, ndlp, old_state, state);
James Smartde0c5b32007-04-25 09:52:27 -04001622}
1623
1624void
James Smarte47c9092008-02-08 18:49:26 -05001625lpfc_enqueue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
1626{
1627 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1628
1629 if (list_empty(&ndlp->nlp_listp)) {
1630 spin_lock_irq(shost->host_lock);
1631 list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
1632 spin_unlock_irq(shost->host_lock);
1633 }
1634}
1635
1636void
James Smart2e0fef82007-06-17 19:56:36 -05001637lpfc_dequeue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
James Smartde0c5b32007-04-25 09:52:27 -04001638{
James Smart2e0fef82007-06-17 19:56:36 -05001639 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1640
James Smart0d2b6b82008-06-14 22:52:47 -04001641 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04001642 if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
James Smart2e0fef82007-06-17 19:56:36 -05001643 lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
1644 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04001645 list_del_init(&ndlp->nlp_listp);
James Smart2e0fef82007-06-17 19:56:36 -05001646 spin_unlock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05001647 lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state,
James Smarte47c9092008-02-08 18:49:26 -05001648 NLP_STE_UNUSED_NODE);
1649}
1650
Adrian Bunk4d9db012008-02-14 23:24:02 +02001651static void
James Smarte47c9092008-02-08 18:49:26 -05001652lpfc_disable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
1653{
James Smart0d2b6b82008-06-14 22:52:47 -04001654 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smarte47c9092008-02-08 18:49:26 -05001655 if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
1656 lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
1657 lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state,
1658 NLP_STE_UNUSED_NODE);
1659}
1660
1661struct lpfc_nodelist *
1662lpfc_enable_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1663 int state)
1664{
1665 struct lpfc_hba *phba = vport->phba;
1666 uint32_t did;
1667 unsigned long flags;
1668
1669 if (!ndlp)
1670 return NULL;
1671
1672 spin_lock_irqsave(&phba->ndlp_lock, flags);
1673 /* The ndlp should not be in memory free mode */
1674 if (NLP_CHK_FREE_REQ(ndlp)) {
1675 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
1676 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
1677 "0277 lpfc_enable_node: ndlp:x%p "
1678 "usgmap:x%x refcnt:%d\n",
1679 (void *)ndlp, ndlp->nlp_usg_map,
1680 atomic_read(&ndlp->kref.refcount));
1681 return NULL;
1682 }
1683 /* The ndlp should not already be in active mode */
1684 if (NLP_CHK_NODE_ACT(ndlp)) {
1685 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
1686 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
1687 "0278 lpfc_enable_node: ndlp:x%p "
1688 "usgmap:x%x refcnt:%d\n",
1689 (void *)ndlp, ndlp->nlp_usg_map,
1690 atomic_read(&ndlp->kref.refcount));
1691 return NULL;
1692 }
1693
1694 /* Keep the original DID */
1695 did = ndlp->nlp_DID;
1696
1697 /* re-initialize ndlp except of ndlp linked list pointer */
1698 memset((((char *)ndlp) + sizeof (struct list_head)), 0,
1699 sizeof (struct lpfc_nodelist) - sizeof (struct list_head));
1700 INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp);
1701 INIT_LIST_HEAD(&ndlp->dev_loss_evt.evt_listp);
1702 init_timer(&ndlp->nlp_delayfunc);
1703 ndlp->nlp_delayfunc.function = lpfc_els_retry_delay;
1704 ndlp->nlp_delayfunc.data = (unsigned long)ndlp;
1705 ndlp->nlp_DID = did;
1706 ndlp->vport = vport;
1707 ndlp->nlp_sid = NLP_NO_SID;
1708 /* ndlp management re-initialize */
1709 kref_init(&ndlp->kref);
1710 NLP_INT_NODE_ACT(ndlp);
1711
1712 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
1713
1714 if (state != NLP_STE_UNUSED_NODE)
1715 lpfc_nlp_set_state(vport, ndlp, state);
1716
1717 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
1718 "node enable: did:x%x",
1719 ndlp->nlp_DID, 0, 0);
1720 return ndlp;
James Smartde0c5b32007-04-25 09:52:27 -04001721}
1722
1723void
James Smart2e0fef82007-06-17 19:56:36 -05001724lpfc_drop_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
James Smartde0c5b32007-04-25 09:52:27 -04001725{
James Smart87af33f2007-10-27 13:37:43 -04001726 /*
James Smartfa4066b2008-01-11 01:53:27 -05001727 * Use of lpfc_drop_node and UNUSED list: lpfc_drop_node should
James Smart87af33f2007-10-27 13:37:43 -04001728 * be used if we wish to issue the "last" lpfc_nlp_put() to remove
James Smartfa4066b2008-01-11 01:53:27 -05001729 * the ndlp from the vport. The ndlp marked as UNUSED on the list
1730 * until ALL other outstanding threads have completed. We check
1731 * that the ndlp not already in the UNUSED state before we proceed.
James Smart87af33f2007-10-27 13:37:43 -04001732 */
James Smartfa4066b2008-01-11 01:53:27 -05001733 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
1734 return;
James Smart51ef4c22007-08-02 11:10:31 -04001735 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNUSED_NODE);
James Smart87af33f2007-10-27 13:37:43 -04001736 lpfc_nlp_put(ndlp);
James Smart98c9ea52007-10-27 13:37:33 -04001737 return;
dea31012005-04-17 16:05:31 -05001738}
1739
1740/*
1741 * Start / ReStart rescue timer for Discovery / RSCN handling
1742 */
1743void
James Smart2e0fef82007-06-17 19:56:36 -05001744lpfc_set_disctmo(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001745{
James Smart2e0fef82007-06-17 19:56:36 -05001746 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1747 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001748 uint32_t tmo;
1749
James Smart2e0fef82007-06-17 19:56:36 -05001750 if (vport->port_state == LPFC_LOCAL_CFG_LINK) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001751 /* For FAN, timeout should be greater then edtov */
1752 tmo = (((phba->fc_edtov + 999) / 1000) + 1);
1753 } else {
1754 /* Normal discovery timeout should be > then ELS/CT timeout
1755 * FC spec states we need 3 * ratov for CT requests
1756 */
1757 tmo = ((phba->fc_ratov * 3) + 3);
1758 }
dea31012005-04-17 16:05:31 -05001759
James Smart858c9f62007-06-17 19:56:39 -05001760
1761 if (!timer_pending(&vport->fc_disctmo)) {
1762 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1763 "set disc timer: tmo:x%x state:x%x flg:x%x",
1764 tmo, vport->port_state, vport->fc_flag);
1765 }
1766
James Smart2e0fef82007-06-17 19:56:36 -05001767 mod_timer(&vport->fc_disctmo, jiffies + HZ * tmo);
1768 spin_lock_irq(shost->host_lock);
1769 vport->fc_flag |= FC_DISC_TMO;
1770 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001771
1772 /* Start Discovery Timer state <hba_state> */
James Smarte8b62012007-08-02 11:10:09 -04001773 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1774 "0247 Start Discovery Timer state x%x "
1775 "Data: x%x x%lx x%x x%x\n",
1776 vport->port_state, tmo,
1777 (unsigned long)&vport->fc_disctmo, vport->fc_plogi_cnt,
1778 vport->fc_adisc_cnt);
dea31012005-04-17 16:05:31 -05001779
1780 return;
1781}
1782
1783/*
1784 * Cancel rescue timer for Discovery / RSCN handling
1785 */
1786int
James Smart2e0fef82007-06-17 19:56:36 -05001787lpfc_can_disctmo(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001788{
James Smart2e0fef82007-06-17 19:56:36 -05001789 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart2e0fef82007-06-17 19:56:36 -05001790 unsigned long iflags;
1791
James Smart858c9f62007-06-17 19:56:39 -05001792 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1793 "can disc timer: state:x%x rtry:x%x flg:x%x",
1794 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
1795
dea31012005-04-17 16:05:31 -05001796 /* Turn off discovery timer if its running */
James Smart2e0fef82007-06-17 19:56:36 -05001797 if (vport->fc_flag & FC_DISC_TMO) {
1798 spin_lock_irqsave(shost->host_lock, iflags);
1799 vport->fc_flag &= ~FC_DISC_TMO;
1800 spin_unlock_irqrestore(shost->host_lock, iflags);
1801 del_timer_sync(&vport->fc_disctmo);
1802 spin_lock_irqsave(&vport->work_port_lock, iflags);
1803 vport->work_port_events &= ~WORKER_DISC_TMO;
1804 spin_unlock_irqrestore(&vport->work_port_lock, iflags);
dea31012005-04-17 16:05:31 -05001805 }
1806
1807 /* Cancel Discovery Timer state <hba_state> */
James Smarte8b62012007-08-02 11:10:09 -04001808 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
1809 "0248 Cancel Discovery Timer state x%x "
1810 "Data: x%x x%x x%x\n",
1811 vport->port_state, vport->fc_flag,
1812 vport->fc_plogi_cnt, vport->fc_adisc_cnt);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001813 return 0;
dea31012005-04-17 16:05:31 -05001814}
1815
1816/*
1817 * Check specified ring for outstanding IOCB on the SLI queue
1818 * Return true if iocb matches the specified nport
1819 */
1820int
James Smart2e0fef82007-06-17 19:56:36 -05001821lpfc_check_sli_ndlp(struct lpfc_hba *phba,
1822 struct lpfc_sli_ring *pring,
1823 struct lpfc_iocbq *iocb,
1824 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05001825{
James Smart2e0fef82007-06-17 19:56:36 -05001826 struct lpfc_sli *psli = &phba->sli;
1827 IOCB_t *icmd = &iocb->iocb;
James Smart92d7f7b2007-06-17 19:56:38 -05001828 struct lpfc_vport *vport = ndlp->vport;
1829
1830 if (iocb->vport != vport)
1831 return 0;
1832
dea31012005-04-17 16:05:31 -05001833 if (pring->ringno == LPFC_ELS_RING) {
1834 switch (icmd->ulpCommand) {
1835 case CMD_GEN_REQUEST64_CR:
1836 if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001837 return 1;
dea31012005-04-17 16:05:31 -05001838 case CMD_ELS_REQUEST64_CR:
James Smart10d4e952006-04-15 11:53:15 -04001839 if (icmd->un.elsreq64.remoteID == ndlp->nlp_DID)
1840 return 1;
dea31012005-04-17 16:05:31 -05001841 case CMD_XMIT_ELS_RSP64_CX:
1842 if (iocb->context1 == (uint8_t *) ndlp)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001843 return 1;
dea31012005-04-17 16:05:31 -05001844 }
James Smarta4bc3372006-12-02 13:34:16 -05001845 } else if (pring->ringno == psli->extra_ring) {
dea31012005-04-17 16:05:31 -05001846
1847 } else if (pring->ringno == psli->fcp_ring) {
1848 /* Skip match check if waiting to relogin to FCP target */
1849 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
James Smart92d7f7b2007-06-17 19:56:38 -05001850 (ndlp->nlp_flag & NLP_DELAY_TMO)) {
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001851 return 0;
dea31012005-04-17 16:05:31 -05001852 }
1853 if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) {
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001854 return 1;
dea31012005-04-17 16:05:31 -05001855 }
1856 } else if (pring->ringno == psli->next_ring) {
1857
1858 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001859 return 0;
dea31012005-04-17 16:05:31 -05001860}
1861
1862/*
1863 * Free resources / clean up outstanding I/Os
1864 * associated with nlp_rpi in the LPFC_NODELIST entry.
1865 */
1866static int
James Smart2e0fef82007-06-17 19:56:36 -05001867lpfc_no_rpi(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05001868{
James Smart2534ba72007-04-25 09:52:20 -04001869 LIST_HEAD(completions);
dea31012005-04-17 16:05:31 -05001870 struct lpfc_sli *psli;
1871 struct lpfc_sli_ring *pring;
1872 struct lpfc_iocbq *iocb, *next_iocb;
1873 IOCB_t *icmd;
1874 uint32_t rpi, i;
1875
James Smart92d7f7b2007-06-17 19:56:38 -05001876 lpfc_fabric_abort_nport(ndlp);
1877
dea31012005-04-17 16:05:31 -05001878 /*
1879 * Everything that matches on txcmplq will be returned
1880 * by firmware with a no rpi error.
1881 */
1882 psli = &phba->sli;
1883 rpi = ndlp->nlp_rpi;
1884 if (rpi) {
1885 /* Now process each ring */
1886 for (i = 0; i < psli->num_rings; i++) {
1887 pring = &psli->ring[i];
1888
James Smart2e0fef82007-06-17 19:56:36 -05001889 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001890 list_for_each_entry_safe(iocb, next_iocb, &pring->txq,
James Smart2e0fef82007-06-17 19:56:36 -05001891 list) {
dea31012005-04-17 16:05:31 -05001892 /*
1893 * Check to see if iocb matches the nport we are
1894 * looking for
1895 */
James Smart92d7f7b2007-06-17 19:56:38 -05001896 if ((lpfc_check_sli_ndlp(phba, pring, iocb,
1897 ndlp))) {
dea31012005-04-17 16:05:31 -05001898 /* It matches, so deque and call compl
1899 with an error */
James Smart2534ba72007-04-25 09:52:20 -04001900 list_move_tail(&iocb->list,
1901 &completions);
dea31012005-04-17 16:05:31 -05001902 pring->txq_cnt--;
dea31012005-04-17 16:05:31 -05001903 }
1904 }
James Smart2e0fef82007-06-17 19:56:36 -05001905 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001906 }
1907 }
James Smart2534ba72007-04-25 09:52:20 -04001908
1909 while (!list_empty(&completions)) {
1910 iocb = list_get_first(&completions, struct lpfc_iocbq, list);
James Smart92d7f7b2007-06-17 19:56:38 -05001911 list_del_init(&iocb->list);
James Smart2534ba72007-04-25 09:52:20 -04001912
James Smart2e0fef82007-06-17 19:56:36 -05001913 if (!iocb->iocb_cmpl)
1914 lpfc_sli_release_iocbq(phba, iocb);
1915 else {
James Smart2534ba72007-04-25 09:52:20 -04001916 icmd = &iocb->iocb;
1917 icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
1918 icmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
James Smart2e0fef82007-06-17 19:56:36 -05001919 (iocb->iocb_cmpl)(phba, iocb, iocb);
1920 }
James Smart2534ba72007-04-25 09:52:20 -04001921 }
1922
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001923 return 0;
dea31012005-04-17 16:05:31 -05001924}
1925
1926/*
1927 * Free rpi associated with LPFC_NODELIST entry.
1928 * This routine is called from lpfc_freenode(), when we are removing
1929 * a LPFC_NODELIST entry. It is also called if the driver initiates a
1930 * LOGO that completes successfully, and we are waiting to PLOGI back
1931 * to the remote NPort. In addition, it is called after we receive
1932 * and unsolicated ELS cmd, send back a rsp, the rsp completes and
1933 * we are waiting to PLOGI back to the remote NPort.
1934 */
1935int
James Smart2e0fef82007-06-17 19:56:36 -05001936lpfc_unreg_rpi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05001937{
James Smart2e0fef82007-06-17 19:56:36 -05001938 struct lpfc_hba *phba = vport->phba;
1939 LPFC_MBOXQ_t *mbox;
dea31012005-04-17 16:05:31 -05001940 int rc;
1941
1942 if (ndlp->nlp_rpi) {
James Smart2e0fef82007-06-17 19:56:36 -05001943 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1944 if (mbox) {
James Smart92d7f7b2007-06-17 19:56:38 -05001945 lpfc_unreg_login(phba, vport->vpi, ndlp->nlp_rpi, mbox);
James Smarted957682007-06-17 19:56:37 -05001946 mbox->vport = vport;
James Smart92d7f7b2007-06-17 19:56:38 -05001947 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart0b727fe2007-10-27 13:37:25 -04001948 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
dea31012005-04-17 16:05:31 -05001949 if (rc == MBX_NOT_FINISHED)
James Smart2e0fef82007-06-17 19:56:36 -05001950 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05001951 }
dea31012005-04-17 16:05:31 -05001952 lpfc_no_rpi(phba, ndlp);
1953 ndlp->nlp_rpi = 0;
1954 return 1;
1955 }
1956 return 0;
1957}
1958
James Smart92d7f7b2007-06-17 19:56:38 -05001959void
1960lpfc_unreg_all_rpis(struct lpfc_vport *vport)
1961{
1962 struct lpfc_hba *phba = vport->phba;
1963 LPFC_MBOXQ_t *mbox;
1964 int rc;
1965
1966 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1967 if (mbox) {
1968 lpfc_unreg_login(phba, vport->vpi, 0xffff, mbox);
1969 mbox->vport = vport;
1970 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart09372822008-01-11 01:52:54 -05001971 mbox->context1 = NULL;
1972 rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
James Smart92d7f7b2007-06-17 19:56:38 -05001973 if (rc == MBX_NOT_FINISHED) {
1974 mempool_free(mbox, phba->mbox_mem_pool);
1975 }
1976 }
1977}
1978
1979void
1980lpfc_unreg_default_rpis(struct lpfc_vport *vport)
1981{
1982 struct lpfc_hba *phba = vport->phba;
1983 LPFC_MBOXQ_t *mbox;
1984 int rc;
1985
1986 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1987 if (mbox) {
1988 lpfc_unreg_did(phba, vport->vpi, 0xffffffff, mbox);
1989 mbox->vport = vport;
1990 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart09372822008-01-11 01:52:54 -05001991 mbox->context1 = NULL;
1992 rc = lpfc_sli_issue_mbox_wait(phba, mbox, LPFC_MBOX_TMO);
James Smart92d7f7b2007-06-17 19:56:38 -05001993 if (rc == MBX_NOT_FINISHED) {
James Smarte8b62012007-08-02 11:10:09 -04001994 lpfc_printf_vlog(vport, KERN_ERR, LOG_MBOX | LOG_VPORT,
1995 "1815 Could not issue "
1996 "unreg_did (default rpis)\n");
James Smart92d7f7b2007-06-17 19:56:38 -05001997 mempool_free(mbox, phba->mbox_mem_pool);
1998 }
1999 }
2000}
2001
dea31012005-04-17 16:05:31 -05002002/*
2003 * Free resources associated with LPFC_NODELIST entry
2004 * so it can be freed.
2005 */
2006static int
James Smart2e0fef82007-06-17 19:56:36 -05002007lpfc_cleanup_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05002008{
James Smart2e0fef82007-06-17 19:56:36 -05002009 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2010 struct lpfc_hba *phba = vport->phba;
2011 LPFC_MBOXQ_t *mb, *nextmb;
dea31012005-04-17 16:05:31 -05002012 struct lpfc_dmabuf *mp;
dea31012005-04-17 16:05:31 -05002013
2014 /* Cleanup node for NPort <nlp_DID> */
James Smarte8b62012007-08-02 11:10:09 -04002015 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
2016 "0900 Cleanup node for NPort x%x "
2017 "Data: x%x x%x x%x\n",
2018 ndlp->nlp_DID, ndlp->nlp_flag,
2019 ndlp->nlp_state, ndlp->nlp_rpi);
James Smarte47c9092008-02-08 18:49:26 -05002020 if (NLP_CHK_FREE_REQ(ndlp)) {
2021 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
2022 "0280 lpfc_cleanup_node: ndlp:x%p "
2023 "usgmap:x%x refcnt:%d\n",
2024 (void *)ndlp, ndlp->nlp_usg_map,
2025 atomic_read(&ndlp->kref.refcount));
2026 lpfc_dequeue_node(vport, ndlp);
2027 } else {
2028 lpfc_printf_vlog(vport, KERN_WARNING, LOG_NODE,
2029 "0281 lpfc_cleanup_node: ndlp:x%p "
2030 "usgmap:x%x refcnt:%d\n",
2031 (void *)ndlp, ndlp->nlp_usg_map,
2032 atomic_read(&ndlp->kref.refcount));
2033 lpfc_disable_node(vport, ndlp);
2034 }
dea31012005-04-17 16:05:31 -05002035
dea31012005-04-17 16:05:31 -05002036 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
2037 if ((mb = phba->sli.mbox_active)) {
2038 if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
2039 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
2040 mb->context2 = NULL;
2041 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
2042 }
2043 }
James Smart33ccf8d2006-08-17 11:57:58 -04002044
James Smart2e0fef82007-06-17 19:56:36 -05002045 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002046 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
2047 if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
James Smart92d7f7b2007-06-17 19:56:38 -05002048 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
dea31012005-04-17 16:05:31 -05002049 mp = (struct lpfc_dmabuf *) (mb->context1);
2050 if (mp) {
James Smart2e0fef82007-06-17 19:56:36 -05002051 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
dea31012005-04-17 16:05:31 -05002052 kfree(mp);
2053 }
2054 list_del(&mb->list);
2055 mempool_free(mb, phba->mbox_mem_pool);
James Smarte47c9092008-02-08 18:49:26 -05002056 /* We shall not invoke the lpfc_nlp_put to decrement
2057 * the ndlp reference count as we are in the process
2058 * of lpfc_nlp_release.
2059 */
dea31012005-04-17 16:05:31 -05002060 }
2061 }
James Smart2e0fef82007-06-17 19:56:36 -05002062 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002063
James Smarte47c9092008-02-08 18:49:26 -05002064 lpfc_els_abort(phba, ndlp);
2065
James Smart2e0fef82007-06-17 19:56:36 -05002066 spin_lock_irq(shost->host_lock);
James Smartc01f3202006-08-18 17:47:08 -04002067 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05002068 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002069
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05002070 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05002071 del_timer_sync(&ndlp->nlp_delayfunc);
2072
James Smart0d2b6b82008-06-14 22:52:47 -04002073 list_del_init(&ndlp->els_retry_evt.evt_listp);
2074 list_del_init(&ndlp->dev_loss_evt.evt_listp);
dea31012005-04-17 16:05:31 -05002075
James Smart2e0fef82007-06-17 19:56:36 -05002076 lpfc_unreg_rpi(vport, ndlp);
dea31012005-04-17 16:05:31 -05002077
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002078 return 0;
dea31012005-04-17 16:05:31 -05002079}
2080
2081/*
2082 * Check to see if we can free the nlp back to the freelist.
2083 * If we are in the middle of using the nlp in the discovery state
2084 * machine, defer the free till we reach the end of the state machine.
2085 */
James Smart329f9bc2007-04-25 09:53:01 -04002086static void
James Smart2e0fef82007-06-17 19:56:36 -05002087lpfc_nlp_remove(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05002088{
James Smarta8adb832007-10-27 13:37:53 -04002089 struct lpfc_hba *phba = vport->phba;
James Smart1dcb58e2007-04-25 09:51:30 -04002090 struct lpfc_rport_data *rdata;
James Smarta8adb832007-10-27 13:37:53 -04002091 LPFC_MBOXQ_t *mbox;
2092 int rc;
dea31012005-04-17 16:05:31 -05002093
James Smart0d2b6b82008-06-14 22:52:47 -04002094 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smarta8adb832007-10-27 13:37:53 -04002095 if (ndlp->nlp_flag & NLP_DEFER_RM && !ndlp->nlp_rpi) {
2096 /* For this case we need to cleanup the default rpi
2097 * allocated by the firmware.
2098 */
2099 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))
2100 != NULL) {
2101 rc = lpfc_reg_login(phba, vport->vpi, ndlp->nlp_DID,
2102 (uint8_t *) &vport->fc_sparam, mbox, 0);
2103 if (rc) {
2104 mempool_free(mbox, phba->mbox_mem_pool);
2105 }
2106 else {
2107 mbox->mbox_flag |= LPFC_MBX_IMED_UNREG;
2108 mbox->mbox_cmpl = lpfc_mbx_cmpl_dflt_rpi;
2109 mbox->vport = vport;
James Smart09372822008-01-11 01:52:54 -05002110 mbox->context2 = NULL;
James Smarta8adb832007-10-27 13:37:53 -04002111 rc =lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
2112 if (rc == MBX_NOT_FINISHED) {
2113 mempool_free(mbox, phba->mbox_mem_pool);
2114 }
2115 }
2116 }
2117 }
James Smart2e0fef82007-06-17 19:56:36 -05002118 lpfc_cleanup_node(vport, ndlp);
James Smart1dcb58e2007-04-25 09:51:30 -04002119
James Smart2e0fef82007-06-17 19:56:36 -05002120 /*
James Smart92d7f7b2007-06-17 19:56:38 -05002121 * We can get here with a non-NULL ndlp->rport because when we
2122 * unregister a rport we don't break the rport/node linkage. So if we
2123 * do, make sure we don't leaving any dangling pointers behind.
James Smart2e0fef82007-06-17 19:56:36 -05002124 */
James Smart92d7f7b2007-06-17 19:56:38 -05002125 if (ndlp->rport) {
James Smart329f9bc2007-04-25 09:53:01 -04002126 rdata = ndlp->rport->dd_data;
2127 rdata->pnode = NULL;
2128 ndlp->rport = NULL;
dea31012005-04-17 16:05:31 -05002129 }
dea31012005-04-17 16:05:31 -05002130}
2131
2132static int
James Smart2e0fef82007-06-17 19:56:36 -05002133lpfc_matchdid(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2134 uint32_t did)
dea31012005-04-17 16:05:31 -05002135{
James Smart2e0fef82007-06-17 19:56:36 -05002136 D_ID mydid, ndlpdid, matchdid;
dea31012005-04-17 16:05:31 -05002137
2138 if (did == Bcast_DID)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002139 return 0;
dea31012005-04-17 16:05:31 -05002140
dea31012005-04-17 16:05:31 -05002141 /* First check for Direct match */
2142 if (ndlp->nlp_DID == did)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002143 return 1;
dea31012005-04-17 16:05:31 -05002144
2145 /* Next check for area/domain identically equals 0 match */
James Smart2e0fef82007-06-17 19:56:36 -05002146 mydid.un.word = vport->fc_myDID;
dea31012005-04-17 16:05:31 -05002147 if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) {
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002148 return 0;
dea31012005-04-17 16:05:31 -05002149 }
2150
2151 matchdid.un.word = did;
2152 ndlpdid.un.word = ndlp->nlp_DID;
2153 if (matchdid.un.b.id == ndlpdid.un.b.id) {
2154 if ((mydid.un.b.domain == matchdid.un.b.domain) &&
2155 (mydid.un.b.area == matchdid.un.b.area)) {
2156 if ((ndlpdid.un.b.domain == 0) &&
2157 (ndlpdid.un.b.area == 0)) {
2158 if (ndlpdid.un.b.id)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002159 return 1;
dea31012005-04-17 16:05:31 -05002160 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002161 return 0;
dea31012005-04-17 16:05:31 -05002162 }
2163
2164 matchdid.un.word = ndlp->nlp_DID;
2165 if ((mydid.un.b.domain == ndlpdid.un.b.domain) &&
2166 (mydid.un.b.area == ndlpdid.un.b.area)) {
2167 if ((matchdid.un.b.domain == 0) &&
2168 (matchdid.un.b.area == 0)) {
2169 if (matchdid.un.b.id)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002170 return 1;
dea31012005-04-17 16:05:31 -05002171 }
2172 }
2173 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002174 return 0;
dea31012005-04-17 16:05:31 -05002175}
2176
James Smart685f0bf2007-04-25 09:53:08 -04002177/* Search for a nodelist entry */
James Smart2e0fef82007-06-17 19:56:36 -05002178static struct lpfc_nodelist *
2179__lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05002180{
James Smart2fb9bd82006-12-02 13:33:57 -05002181 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05002182 uint32_t data1;
2183
James Smart2e0fef82007-06-17 19:56:36 -05002184 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
2185 if (lpfc_matchdid(vport, ndlp, did)) {
James Smart685f0bf2007-04-25 09:53:08 -04002186 data1 = (((uint32_t) ndlp->nlp_state << 24) |
2187 ((uint32_t) ndlp->nlp_xri << 16) |
2188 ((uint32_t) ndlp->nlp_type << 8) |
2189 ((uint32_t) ndlp->nlp_rpi & 0xff));
James Smarte8b62012007-08-02 11:10:09 -04002190 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
2191 "0929 FIND node DID "
2192 "Data: x%p x%x x%x x%x\n",
2193 ndlp, ndlp->nlp_DID,
2194 ndlp->nlp_flag, data1);
James Smart685f0bf2007-04-25 09:53:08 -04002195 return ndlp;
dea31012005-04-17 16:05:31 -05002196 }
2197 }
Jamie Wellnitz66a9ed62006-02-28 22:33:10 -05002198
dea31012005-04-17 16:05:31 -05002199 /* FIND node did <did> NOT FOUND */
James Smarte8b62012007-08-02 11:10:09 -04002200 lpfc_printf_vlog(vport, KERN_INFO, LOG_NODE,
2201 "0932 FIND node did x%x NOT FOUND.\n", did);
dea31012005-04-17 16:05:31 -05002202 return NULL;
2203}
2204
2205struct lpfc_nodelist *
James Smart2e0fef82007-06-17 19:56:36 -05002206lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05002207{
James Smart2e0fef82007-06-17 19:56:36 -05002208 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002209 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05002210
James Smart2e0fef82007-06-17 19:56:36 -05002211 spin_lock_irq(shost->host_lock);
2212 ndlp = __lpfc_findnode_did(vport, did);
2213 spin_unlock_irq(shost->host_lock);
2214 return ndlp;
2215}
2216
2217struct lpfc_nodelist *
2218lpfc_setup_disc_node(struct lpfc_vport *vport, uint32_t did)
2219{
2220 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2221 struct lpfc_nodelist *ndlp;
2222
2223 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002224 if (!ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05002225 if ((vport->fc_flag & FC_RSCN_MODE) != 0 &&
2226 lpfc_rscn_payload_check(vport, did) == 0)
dea31012005-04-17 16:05:31 -05002227 return NULL;
2228 ndlp = (struct lpfc_nodelist *)
James Smart2e0fef82007-06-17 19:56:36 -05002229 mempool_alloc(vport->phba->nlp_mem_pool, GFP_KERNEL);
dea31012005-04-17 16:05:31 -05002230 if (!ndlp)
2231 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05002232 lpfc_nlp_init(vport, ndlp, did);
2233 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2234 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002235 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002236 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002237 return ndlp;
James Smarte47c9092008-02-08 18:49:26 -05002238 } else if (!NLP_CHK_NODE_ACT(ndlp)) {
2239 ndlp = lpfc_enable_node(vport, ndlp, NLP_STE_NPR_NODE);
2240 if (!ndlp)
2241 return NULL;
2242 spin_lock_irq(shost->host_lock);
2243 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
2244 spin_unlock_irq(shost->host_lock);
2245 return ndlp;
dea31012005-04-17 16:05:31 -05002246 }
James Smarte47c9092008-02-08 18:49:26 -05002247
James Smart58da1ff2008-04-07 10:15:56 -04002248 if ((vport->fc_flag & FC_RSCN_MODE) &&
2249 !(vport->fc_flag & FC_NDISC_ACTIVE)) {
James Smart2e0fef82007-06-17 19:56:36 -05002250 if (lpfc_rscn_payload_check(vport, did)) {
James Smart87af33f2007-10-27 13:37:43 -04002251 /* If we've already recieved a PLOGI from this NPort
2252 * we don't need to try to discover it again.
2253 */
2254 if (ndlp->nlp_flag & NLP_RCV_PLOGI)
2255 return NULL;
2256
James Smart2e0fef82007-06-17 19:56:36 -05002257 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002258 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002259 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002260
2261 /* Since this node is marked for discovery,
2262 * delay timeout is not needed.
2263 */
James Smart0d2b6b82008-06-14 22:52:47 -04002264 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smart071fbd3d2006-04-15 11:53:20 -04002265 } else
dea31012005-04-17 16:05:31 -05002266 ndlp = NULL;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002267 } else {
James Smart87af33f2007-10-27 13:37:43 -04002268 /* If we've already recieved a PLOGI from this NPort,
2269 * or we are already in the process of discovery on it,
2270 * we don't need to try to discover it again.
2271 */
James Smart685f0bf2007-04-25 09:53:08 -04002272 if (ndlp->nlp_state == NLP_STE_ADISC_ISSUE ||
James Smart87af33f2007-10-27 13:37:43 -04002273 ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
2274 ndlp->nlp_flag & NLP_RCV_PLOGI)
dea31012005-04-17 16:05:31 -05002275 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05002276 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2277 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002278 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002279 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002280 }
2281 return ndlp;
2282}
2283
2284/* Build a list of nodes to discover based on the loopmap */
2285void
James Smart2e0fef82007-06-17 19:56:36 -05002286lpfc_disc_list_loopmap(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002287{
James Smart2e0fef82007-06-17 19:56:36 -05002288 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002289 int j;
2290 uint32_t alpa, index;
2291
James Smart2e0fef82007-06-17 19:56:36 -05002292 if (!lpfc_is_link_up(phba))
dea31012005-04-17 16:05:31 -05002293 return;
James Smart2e0fef82007-06-17 19:56:36 -05002294
2295 if (phba->fc_topology != TOPOLOGY_LOOP)
dea31012005-04-17 16:05:31 -05002296 return;
dea31012005-04-17 16:05:31 -05002297
2298 /* Check for loop map present or not */
2299 if (phba->alpa_map[0]) {
2300 for (j = 1; j <= phba->alpa_map[0]; j++) {
2301 alpa = phba->alpa_map[j];
James Smart2e0fef82007-06-17 19:56:36 -05002302 if (((vport->fc_myDID & 0xff) == alpa) || (alpa == 0))
dea31012005-04-17 16:05:31 -05002303 continue;
James Smart2e0fef82007-06-17 19:56:36 -05002304 lpfc_setup_disc_node(vport, alpa);
dea31012005-04-17 16:05:31 -05002305 }
2306 } else {
2307 /* No alpamap, so try all alpa's */
2308 for (j = 0; j < FC_MAXLOOP; j++) {
2309 /* If cfg_scan_down is set, start from highest
2310 * ALPA (0xef) to lowest (0x1).
2311 */
James Smart3de2a652007-08-02 11:09:59 -04002312 if (vport->cfg_scan_down)
dea31012005-04-17 16:05:31 -05002313 index = j;
2314 else
2315 index = FC_MAXLOOP - j - 1;
2316 alpa = lpfcAlpaArray[index];
James Smart2e0fef82007-06-17 19:56:36 -05002317 if ((vport->fc_myDID & 0xff) == alpa)
dea31012005-04-17 16:05:31 -05002318 continue;
James Smart2e0fef82007-06-17 19:56:36 -05002319 lpfc_setup_disc_node(vport, alpa);
dea31012005-04-17 16:05:31 -05002320 }
2321 }
2322 return;
2323}
2324
dea31012005-04-17 16:05:31 -05002325void
James Smart2e0fef82007-06-17 19:56:36 -05002326lpfc_issue_clear_la(struct lpfc_hba *phba, struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002327{
dea31012005-04-17 16:05:31 -05002328 LPFC_MBOXQ_t *mbox;
James Smart2e0fef82007-06-17 19:56:36 -05002329 struct lpfc_sli *psli = &phba->sli;
2330 struct lpfc_sli_ring *extra_ring = &psli->ring[psli->extra_ring];
2331 struct lpfc_sli_ring *fcp_ring = &psli->ring[psli->fcp_ring];
2332 struct lpfc_sli_ring *next_ring = &psli->ring[psli->next_ring];
2333 int rc;
2334
James Smart92d7f7b2007-06-17 19:56:38 -05002335 /*
2336 * if it's not a physical port or if we already send
2337 * clear_la then don't send it.
2338 */
2339 if ((phba->link_state >= LPFC_CLEAR_LA) ||
2340 (vport->port_type != LPFC_PHYSICAL_PORT))
2341 return;
2342
James Smart2e0fef82007-06-17 19:56:36 -05002343 /* Link up discovery */
2344 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL)) != NULL) {
2345 phba->link_state = LPFC_CLEAR_LA;
2346 lpfc_clear_la(phba, mbox);
2347 mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
2348 mbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -04002349 rc = lpfc_sli_issue_mbox(phba, mbox, MBX_NOWAIT);
James Smart2e0fef82007-06-17 19:56:36 -05002350 if (rc == MBX_NOT_FINISHED) {
2351 mempool_free(mbox, phba->mbox_mem_pool);
2352 lpfc_disc_flush_list(vport);
2353 extra_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
2354 fcp_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
2355 next_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
James Smart92d7f7b2007-06-17 19:56:38 -05002356 phba->link_state = LPFC_HBA_ERROR;
2357 }
2358 }
2359}
2360
2361/* Reg_vpi to tell firmware to resume normal operations */
2362void
2363lpfc_issue_reg_vpi(struct lpfc_hba *phba, struct lpfc_vport *vport)
2364{
2365 LPFC_MBOXQ_t *regvpimbox;
2366
2367 regvpimbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2368 if (regvpimbox) {
2369 lpfc_reg_vpi(phba, vport->vpi, vport->fc_myDID, regvpimbox);
2370 regvpimbox->mbox_cmpl = lpfc_mbx_cmpl_reg_vpi;
2371 regvpimbox->vport = vport;
James Smart0b727fe2007-10-27 13:37:25 -04002372 if (lpfc_sli_issue_mbox(phba, regvpimbox, MBX_NOWAIT)
James Smart92d7f7b2007-06-17 19:56:38 -05002373 == MBX_NOT_FINISHED) {
2374 mempool_free(regvpimbox, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05002375 }
2376 }
2377}
2378
2379/* Start Link up / RSCN discovery on NPR nodes */
2380void
2381lpfc_disc_start(struct lpfc_vport *vport)
2382{
2383 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2384 struct lpfc_hba *phba = vport->phba;
James Smart685f0bf2007-04-25 09:53:08 -04002385 uint32_t num_sent;
dea31012005-04-17 16:05:31 -05002386 uint32_t clear_la_pending;
James Smart685f0bf2007-04-25 09:53:08 -04002387 int did_changed;
dea31012005-04-17 16:05:31 -05002388
James Smart2e0fef82007-06-17 19:56:36 -05002389 if (!lpfc_is_link_up(phba))
dea31012005-04-17 16:05:31 -05002390 return;
James Smart2e0fef82007-06-17 19:56:36 -05002391
2392 if (phba->link_state == LPFC_CLEAR_LA)
dea31012005-04-17 16:05:31 -05002393 clear_la_pending = 1;
2394 else
2395 clear_la_pending = 0;
2396
James Smart2e0fef82007-06-17 19:56:36 -05002397 if (vport->port_state < LPFC_VPORT_READY)
2398 vport->port_state = LPFC_DISC_AUTH;
dea31012005-04-17 16:05:31 -05002399
James Smart2e0fef82007-06-17 19:56:36 -05002400 lpfc_set_disctmo(vport);
2401
2402 if (vport->fc_prevDID == vport->fc_myDID)
dea31012005-04-17 16:05:31 -05002403 did_changed = 0;
James Smart2e0fef82007-06-17 19:56:36 -05002404 else
dea31012005-04-17 16:05:31 -05002405 did_changed = 1;
James Smart2e0fef82007-06-17 19:56:36 -05002406
2407 vport->fc_prevDID = vport->fc_myDID;
2408 vport->num_disc_nodes = 0;
dea31012005-04-17 16:05:31 -05002409
2410 /* Start Discovery state <hba_state> */
James Smarte8b62012007-08-02 11:10:09 -04002411 lpfc_printf_vlog(vport, KERN_INFO, LOG_DISCOVERY,
2412 "0202 Start Discovery hba state x%x "
2413 "Data: x%x x%x x%x\n",
2414 vport->port_state, vport->fc_flag, vport->fc_plogi_cnt,
2415 vport->fc_adisc_cnt);
dea31012005-04-17 16:05:31 -05002416
2417 /* First do ADISCs - if any */
James Smart2e0fef82007-06-17 19:56:36 -05002418 num_sent = lpfc_els_disc_adisc(vport);
dea31012005-04-17 16:05:31 -05002419
2420 if (num_sent)
2421 return;
2422
James Smart92d7f7b2007-06-17 19:56:38 -05002423 /*
2424 * For SLI3, cmpl_reg_vpi will set port_state to READY, and
2425 * continue discovery.
2426 */
2427 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
James Smart1b32f6a2008-02-08 18:49:39 -05002428 !(vport->fc_flag & FC_PT2PT) &&
James Smart92d7f7b2007-06-17 19:56:38 -05002429 !(vport->fc_flag & FC_RSCN_MODE)) {
2430 lpfc_issue_reg_vpi(phba, vport);
2431 return;
2432 }
James Smart2e0fef82007-06-17 19:56:36 -05002433
James Smart92d7f7b2007-06-17 19:56:38 -05002434 /*
2435 * For SLI2, we need to set port_state to READY and continue
2436 * discovery.
2437 */
2438 if (vport->port_state < LPFC_VPORT_READY && !clear_la_pending) {
2439 /* If we get here, there is nothing to ADISC */
2440 if (vport->port_type == LPFC_PHYSICAL_PORT)
2441 lpfc_issue_clear_la(phba, vport);
2442
2443 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
James Smart2e0fef82007-06-17 19:56:36 -05002444 vport->num_disc_nodes = 0;
2445 /* go thru NPR nodes and issue ELS PLOGIs */
2446 if (vport->fc_npr_cnt)
2447 lpfc_els_disc_plogi(vport);
2448
2449 if (!vport->num_disc_nodes) {
2450 spin_lock_irq(shost->host_lock);
2451 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2452 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05002453 lpfc_can_disctmo(vport);
dea31012005-04-17 16:05:31 -05002454 }
2455 }
James Smart92d7f7b2007-06-17 19:56:38 -05002456 vport->port_state = LPFC_VPORT_READY;
dea31012005-04-17 16:05:31 -05002457 } else {
2458 /* Next do PLOGIs - if any */
James Smart2e0fef82007-06-17 19:56:36 -05002459 num_sent = lpfc_els_disc_plogi(vport);
dea31012005-04-17 16:05:31 -05002460
2461 if (num_sent)
2462 return;
2463
James Smart2e0fef82007-06-17 19:56:36 -05002464 if (vport->fc_flag & FC_RSCN_MODE) {
dea31012005-04-17 16:05:31 -05002465 /* Check to see if more RSCNs came in while we
2466 * were processing this one.
2467 */
James Smart2e0fef82007-06-17 19:56:36 -05002468 if ((vport->fc_rscn_id_cnt == 0) &&
2469 (!(vport->fc_flag & FC_RSCN_DISCOVERY))) {
2470 spin_lock_irq(shost->host_lock);
2471 vport->fc_flag &= ~FC_RSCN_MODE;
2472 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05002473 lpfc_can_disctmo(vport);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002474 } else
James Smart2e0fef82007-06-17 19:56:36 -05002475 lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05002476 }
2477 }
2478 return;
2479}
2480
2481/*
2482 * Ignore completion for all IOCBs on tx and txcmpl queue for ELS
2483 * ring the match the sppecified nodelist.
2484 */
2485static void
James Smart2e0fef82007-06-17 19:56:36 -05002486lpfc_free_tx(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05002487{
James Smart2534ba72007-04-25 09:52:20 -04002488 LIST_HEAD(completions);
dea31012005-04-17 16:05:31 -05002489 struct lpfc_sli *psli;
2490 IOCB_t *icmd;
2491 struct lpfc_iocbq *iocb, *next_iocb;
2492 struct lpfc_sli_ring *pring;
dea31012005-04-17 16:05:31 -05002493
2494 psli = &phba->sli;
2495 pring = &psli->ring[LPFC_ELS_RING];
2496
2497 /* Error matching iocb on txq or txcmplq
2498 * First check the txq.
2499 */
James Smart2e0fef82007-06-17 19:56:36 -05002500 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002501 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
2502 if (iocb->context1 != ndlp) {
2503 continue;
2504 }
2505 icmd = &iocb->iocb;
2506 if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
2507 (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
2508
James Smart2534ba72007-04-25 09:52:20 -04002509 list_move_tail(&iocb->list, &completions);
dea31012005-04-17 16:05:31 -05002510 pring->txq_cnt--;
dea31012005-04-17 16:05:31 -05002511 }
2512 }
2513
2514 /* Next check the txcmplq */
2515 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
2516 if (iocb->context1 != ndlp) {
2517 continue;
2518 }
2519 icmd = &iocb->iocb;
James Smart2e0fef82007-06-17 19:56:36 -05002520 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR ||
2521 icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX) {
James Smart2534ba72007-04-25 09:52:20 -04002522 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
dea31012005-04-17 16:05:31 -05002523 }
2524 }
James Smart2e0fef82007-06-17 19:56:36 -05002525 spin_unlock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04002526
2527 while (!list_empty(&completions)) {
2528 iocb = list_get_first(&completions, struct lpfc_iocbq, list);
James Smart92d7f7b2007-06-17 19:56:38 -05002529 list_del_init(&iocb->list);
James Smart2534ba72007-04-25 09:52:20 -04002530
James Smart2e0fef82007-06-17 19:56:36 -05002531 if (!iocb->iocb_cmpl)
2532 lpfc_sli_release_iocbq(phba, iocb);
2533 else {
James Smart2534ba72007-04-25 09:52:20 -04002534 icmd = &iocb->iocb;
2535 icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
2536 icmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
2537 (iocb->iocb_cmpl) (phba, iocb, iocb);
James Smart2e0fef82007-06-17 19:56:36 -05002538 }
James Smart2534ba72007-04-25 09:52:20 -04002539 }
dea31012005-04-17 16:05:31 -05002540}
2541
Adrian Bunka6ababd2007-11-05 18:07:33 +01002542static void
James Smart2e0fef82007-06-17 19:56:36 -05002543lpfc_disc_flush_list(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002544{
2545 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05002546 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002547
James Smart2e0fef82007-06-17 19:56:36 -05002548 if (vport->fc_plogi_cnt || vport->fc_adisc_cnt) {
2549 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
James Smart685f0bf2007-04-25 09:53:08 -04002550 nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05002551 if (!NLP_CHK_NODE_ACT(ndlp))
2552 continue;
James Smart685f0bf2007-04-25 09:53:08 -04002553 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
2554 ndlp->nlp_state == NLP_STE_ADISC_ISSUE) {
2555 lpfc_free_tx(phba, ndlp);
James Smart685f0bf2007-04-25 09:53:08 -04002556 }
dea31012005-04-17 16:05:31 -05002557 }
2558 }
dea31012005-04-17 16:05:31 -05002559}
2560
James Smart92d7f7b2007-06-17 19:56:38 -05002561void
2562lpfc_cleanup_discovery_resources(struct lpfc_vport *vport)
2563{
2564 lpfc_els_flush_rscn(vport);
2565 lpfc_els_flush_cmd(vport);
2566 lpfc_disc_flush_list(vport);
2567}
2568
dea31012005-04-17 16:05:31 -05002569/*****************************************************************************/
2570/*
2571 * NAME: lpfc_disc_timeout
2572 *
2573 * FUNCTION: Fibre Channel driver discovery timeout routine.
2574 *
2575 * EXECUTION ENVIRONMENT: interrupt only
2576 *
2577 * CALLED FROM:
2578 * Timer function
2579 *
2580 * RETURNS:
2581 * none
2582 */
2583/*****************************************************************************/
2584void
2585lpfc_disc_timeout(unsigned long ptr)
2586{
James Smart2e0fef82007-06-17 19:56:36 -05002587 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
2588 struct lpfc_hba *phba = vport->phba;
James Smart5e9d9b82008-06-14 22:52:53 -04002589 uint32_t tmo_posted;
dea31012005-04-17 16:05:31 -05002590 unsigned long flags = 0;
2591
2592 if (unlikely(!phba))
2593 return;
2594
James Smart5e9d9b82008-06-14 22:52:53 -04002595 spin_lock_irqsave(&vport->work_port_lock, flags);
2596 tmo_posted = vport->work_port_events & WORKER_DISC_TMO;
2597 if (!tmo_posted)
James Smart2e0fef82007-06-17 19:56:36 -05002598 vport->work_port_events |= WORKER_DISC_TMO;
James Smart5e9d9b82008-06-14 22:52:53 -04002599 spin_unlock_irqrestore(&vport->work_port_lock, flags);
James Smart2e0fef82007-06-17 19:56:36 -05002600
James Smart5e9d9b82008-06-14 22:52:53 -04002601 if (!tmo_posted)
2602 lpfc_worker_wake_up(phba);
dea31012005-04-17 16:05:31 -05002603 return;
2604}
2605
2606static void
James Smart2e0fef82007-06-17 19:56:36 -05002607lpfc_disc_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002608{
James Smart2e0fef82007-06-17 19:56:36 -05002609 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2610 struct lpfc_hba *phba = vport->phba;
2611 struct lpfc_sli *psli = &phba->sli;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002612 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart92d7f7b2007-06-17 19:56:38 -05002613 LPFC_MBOXQ_t *initlinkmbox;
dea31012005-04-17 16:05:31 -05002614 int rc, clrlaerr = 0;
2615
James Smart2e0fef82007-06-17 19:56:36 -05002616 if (!(vport->fc_flag & FC_DISC_TMO))
dea31012005-04-17 16:05:31 -05002617 return;
2618
James Smart2e0fef82007-06-17 19:56:36 -05002619 spin_lock_irq(shost->host_lock);
2620 vport->fc_flag &= ~FC_DISC_TMO;
2621 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002622
James Smart858c9f62007-06-17 19:56:39 -05002623 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2624 "disc timeout: state:x%x rtry:x%x flg:x%x",
2625 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
2626
James Smart2e0fef82007-06-17 19:56:36 -05002627 switch (vport->port_state) {
dea31012005-04-17 16:05:31 -05002628
2629 case LPFC_LOCAL_CFG_LINK:
James Smart2e0fef82007-06-17 19:56:36 -05002630 /* port_state is identically LPFC_LOCAL_CFG_LINK while waiting for
2631 * FAN
2632 */
2633 /* FAN timeout */
James Smarte8b62012007-08-02 11:10:09 -04002634 lpfc_printf_vlog(vport, KERN_WARNING, LOG_DISCOVERY,
2635 "0221 FAN timeout\n");
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002636 /* Start discovery by sending FLOGI, clean up old rpis */
James Smart2e0fef82007-06-17 19:56:36 -05002637 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
James Smart685f0bf2007-04-25 09:53:08 -04002638 nlp_listp) {
James Smarte47c9092008-02-08 18:49:26 -05002639 if (!NLP_CHK_NODE_ACT(ndlp))
2640 continue;
James Smart685f0bf2007-04-25 09:53:08 -04002641 if (ndlp->nlp_state != NLP_STE_NPR_NODE)
2642 continue;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002643 if (ndlp->nlp_type & NLP_FABRIC) {
2644 /* Clean up the ndlp on Fabric connections */
James Smart2e0fef82007-06-17 19:56:36 -05002645 lpfc_drop_node(vport, ndlp);
James Smart87af33f2007-10-27 13:37:43 -04002646
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002647 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002648 /* Fail outstanding IO now since device
2649 * is marked for PLOGI.
2650 */
James Smart2e0fef82007-06-17 19:56:36 -05002651 lpfc_unreg_rpi(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002652 }
2653 }
James Smart92d7f7b2007-06-17 19:56:38 -05002654 if (vport->port_state != LPFC_FLOGI) {
James Smart92d7f7b2007-06-17 19:56:38 -05002655 lpfc_initial_flogi(vport);
James Smart0ff10d42008-01-11 01:52:36 -05002656 return;
James Smart92d7f7b2007-06-17 19:56:38 -05002657 }
dea31012005-04-17 16:05:31 -05002658 break;
2659
James Smart92d7f7b2007-06-17 19:56:38 -05002660 case LPFC_FDISC:
dea31012005-04-17 16:05:31 -05002661 case LPFC_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002662 /* port_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */
dea31012005-04-17 16:05:31 -05002663 /* Initial FLOGI timeout */
James Smarte8b62012007-08-02 11:10:09 -04002664 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
2665 "0222 Initial %s timeout\n",
James Smart87af33f2007-10-27 13:37:43 -04002666 vport->vpi ? "FDISC" : "FLOGI");
dea31012005-04-17 16:05:31 -05002667
2668 /* Assume no Fabric and go on with discovery.
2669 * Check for outstanding ELS FLOGI to abort.
2670 */
2671
2672 /* FLOGI failed, so just use loop map to make discovery list */
James Smart2e0fef82007-06-17 19:56:36 -05002673 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -05002674
2675 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002676 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -05002677 break;
2678
2679 case LPFC_FABRIC_CFG_LINK:
2680 /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for
2681 NameServer login */
James Smarte8b62012007-08-02 11:10:09 -04002682 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
2683 "0223 Timeout while waiting for "
2684 "NameServer login\n");
dea31012005-04-17 16:05:31 -05002685 /* Next look for NameServer ndlp */
James Smart2e0fef82007-06-17 19:56:36 -05002686 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smarte47c9092008-02-08 18:49:26 -05002687 if (ndlp && NLP_CHK_NODE_ACT(ndlp))
James Smart87af33f2007-10-27 13:37:43 -04002688 lpfc_els_abort(phba, ndlp);
2689
2690 /* ReStart discovery */
2691 goto restart_disc;
dea31012005-04-17 16:05:31 -05002692
2693 case LPFC_NS_QRY:
2694 /* Check for wait for NameServer Rsp timeout */
James Smarte8b62012007-08-02 11:10:09 -04002695 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
2696 "0224 NameServer Query timeout "
2697 "Data: x%x x%x\n",
2698 vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
dea31012005-04-17 16:05:31 -05002699
James Smart92d7f7b2007-06-17 19:56:38 -05002700 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
2701 /* Try it one more time */
2702 vport->fc_ns_retry++;
2703 rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT,
2704 vport->fc_ns_retry, 0);
2705 if (rc == 0)
2706 break;
dea31012005-04-17 16:05:31 -05002707 }
James Smart92d7f7b2007-06-17 19:56:38 -05002708 vport->fc_ns_retry = 0;
dea31012005-04-17 16:05:31 -05002709
James Smart87af33f2007-10-27 13:37:43 -04002710restart_disc:
James Smart92d7f7b2007-06-17 19:56:38 -05002711 /*
2712 * Discovery is over.
2713 * set port_state to PORT_READY if SLI2.
2714 * cmpl_reg_vpi will set port_state to READY for SLI3.
2715 */
2716 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
2717 lpfc_issue_reg_vpi(phba, vport);
2718 else { /* NPIV Not enabled */
2719 lpfc_issue_clear_la(phba, vport);
2720 vport->port_state = LPFC_VPORT_READY;
dea31012005-04-17 16:05:31 -05002721 }
2722
2723 /* Setup and issue mailbox INITIALIZE LINK command */
2724 initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2725 if (!initlinkmbox) {
James Smarte8b62012007-08-02 11:10:09 -04002726 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
2727 "0206 Device Discovery "
2728 "completion error\n");
James Smart2e0fef82007-06-17 19:56:36 -05002729 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05002730 break;
2731 }
2732
2733 lpfc_linkdown(phba);
2734 lpfc_init_link(phba, initlinkmbox, phba->cfg_topology,
2735 phba->cfg_link_speed);
2736 initlinkmbox->mb.un.varInitLnk.lipsr_AL_PA = 0;
James Smarted957682007-06-17 19:56:37 -05002737 initlinkmbox->vport = vport;
James Smart92d7f7b2007-06-17 19:56:38 -05002738 initlinkmbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smart0b727fe2007-10-27 13:37:25 -04002739 rc = lpfc_sli_issue_mbox(phba, initlinkmbox, MBX_NOWAIT);
James Smart5b8bd0c2007-04-25 09:52:49 -04002740 lpfc_set_loopback_flag(phba);
dea31012005-04-17 16:05:31 -05002741 if (rc == MBX_NOT_FINISHED)
2742 mempool_free(initlinkmbox, phba->mbox_mem_pool);
2743
2744 break;
2745
2746 case LPFC_DISC_AUTH:
2747 /* Node Authentication timeout */
James Smarte8b62012007-08-02 11:10:09 -04002748 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
2749 "0227 Node Authentication timeout\n");
James Smart2e0fef82007-06-17 19:56:36 -05002750 lpfc_disc_flush_list(vport);
2751
James Smart92d7f7b2007-06-17 19:56:38 -05002752 /*
2753 * set port_state to PORT_READY if SLI2.
2754 * cmpl_reg_vpi will set port_state to READY for SLI3.
2755 */
2756 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
2757 lpfc_issue_reg_vpi(phba, vport);
2758 else { /* NPIV Not enabled */
2759 lpfc_issue_clear_la(phba, vport);
2760 vport->port_state = LPFC_VPORT_READY;
dea31012005-04-17 16:05:31 -05002761 }
2762 break;
2763
James Smart2e0fef82007-06-17 19:56:36 -05002764 case LPFC_VPORT_READY:
2765 if (vport->fc_flag & FC_RSCN_MODE) {
James Smarte8b62012007-08-02 11:10:09 -04002766 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
2767 "0231 RSCN timeout Data: x%x "
2768 "x%x\n",
2769 vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
dea31012005-04-17 16:05:31 -05002770
2771 /* Cleanup any outstanding ELS commands */
James Smart2e0fef82007-06-17 19:56:36 -05002772 lpfc_els_flush_cmd(vport);
dea31012005-04-17 16:05:31 -05002773
James Smart2e0fef82007-06-17 19:56:36 -05002774 lpfc_els_flush_rscn(vport);
2775 lpfc_disc_flush_list(vport);
dea31012005-04-17 16:05:31 -05002776 }
2777 break;
James Smart2e0fef82007-06-17 19:56:36 -05002778
James Smart92d7f7b2007-06-17 19:56:38 -05002779 default:
James Smarte8b62012007-08-02 11:10:09 -04002780 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
2781 "0229 Unexpected discovery timeout, "
2782 "vport State x%x\n", vport->port_state);
James Smart2e0fef82007-06-17 19:56:36 -05002783 break;
2784 }
2785
2786 switch (phba->link_state) {
2787 case LPFC_CLEAR_LA:
James Smart92d7f7b2007-06-17 19:56:38 -05002788 /* CLEAR LA timeout */
James Smarte8b62012007-08-02 11:10:09 -04002789 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
2790 "0228 CLEAR LA timeout\n");
James Smart2e0fef82007-06-17 19:56:36 -05002791 clrlaerr = 1;
2792 break;
2793
James Smart09372822008-01-11 01:52:54 -05002794 case LPFC_LINK_UP:
2795 lpfc_issue_clear_la(phba, vport);
2796 /* Drop thru */
James Smart2e0fef82007-06-17 19:56:36 -05002797 case LPFC_LINK_UNKNOWN:
2798 case LPFC_WARM_START:
2799 case LPFC_INIT_START:
2800 case LPFC_INIT_MBX_CMDS:
2801 case LPFC_LINK_DOWN:
James Smart2e0fef82007-06-17 19:56:36 -05002802 case LPFC_HBA_ERROR:
James Smarte8b62012007-08-02 11:10:09 -04002803 lpfc_printf_vlog(vport, KERN_ERR, LOG_DISCOVERY,
2804 "0230 Unexpected timeout, hba link "
2805 "state x%x\n", phba->link_state);
James Smart2e0fef82007-06-17 19:56:36 -05002806 clrlaerr = 1;
2807 break;
James Smart92d7f7b2007-06-17 19:56:38 -05002808
2809 case LPFC_HBA_READY:
2810 break;
dea31012005-04-17 16:05:31 -05002811 }
2812
2813 if (clrlaerr) {
James Smart2e0fef82007-06-17 19:56:36 -05002814 lpfc_disc_flush_list(vport);
James Smarta4bc3372006-12-02 13:34:16 -05002815 psli->ring[(psli->extra_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
dea31012005-04-17 16:05:31 -05002816 psli->ring[(psli->fcp_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
2817 psli->ring[(psli->next_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
James Smart2e0fef82007-06-17 19:56:36 -05002818 vport->port_state = LPFC_VPORT_READY;
dea31012005-04-17 16:05:31 -05002819 }
2820
2821 return;
2822}
2823
dea31012005-04-17 16:05:31 -05002824/*
2825 * This routine handles processing a NameServer REG_LOGIN mailbox
2826 * command upon completion. It is setup in the LPFC_MBOXQ
2827 * as the completion routine when the command is
2828 * handed off to the SLI layer.
2829 */
2830void
James Smart2e0fef82007-06-17 19:56:36 -05002831lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05002832{
James Smart2e0fef82007-06-17 19:56:36 -05002833 MAILBOX_t *mb = &pmb->mb;
2834 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
2835 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
2836 struct lpfc_vport *vport = pmb->vport;
dea31012005-04-17 16:05:31 -05002837
2838 pmb->context1 = NULL;
2839
dea31012005-04-17 16:05:31 -05002840 ndlp->nlp_rpi = mb->un.varWords[0];
dea31012005-04-17 16:05:31 -05002841 ndlp->nlp_type |= NLP_FABRIC;
James Smart2e0fef82007-06-17 19:56:36 -05002842 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
dea31012005-04-17 16:05:31 -05002843
James Smart2e0fef82007-06-17 19:56:36 -05002844 /*
2845 * Start issuing Fabric-Device Management Interface (FDMI) command to
2846 * 0xfffffa (FDMI well known port) or Delay issuing FDMI command if
2847 * fdmi-on=2 (supporting RPA/hostnmae)
dea31012005-04-17 16:05:31 -05002848 */
James Smart2e0fef82007-06-17 19:56:36 -05002849
James Smart3de2a652007-08-02 11:09:59 -04002850 if (vport->cfg_fdmi_on == 1)
James Smart2e0fef82007-06-17 19:56:36 -05002851 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA);
2852 else
2853 mod_timer(&vport->fc_fdmitmo, jiffies + HZ * 60);
dea31012005-04-17 16:05:31 -05002854
James Smartfa4066b2008-01-11 01:53:27 -05002855 /* decrement the node reference count held for this callback
2856 * function.
2857 */
James Smart329f9bc2007-04-25 09:53:01 -04002858 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002859 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2860 kfree(mp);
James Smart329f9bc2007-04-25 09:53:01 -04002861 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05002862
2863 return;
2864}
2865
James Smart685f0bf2007-04-25 09:53:08 -04002866static int
2867lpfc_filter_by_rpi(struct lpfc_nodelist *ndlp, void *param)
2868{
2869 uint16_t *rpi = param;
2870
2871 return ndlp->nlp_rpi == *rpi;
2872}
2873
2874static int
2875lpfc_filter_by_wwpn(struct lpfc_nodelist *ndlp, void *param)
2876{
2877 return memcmp(&ndlp->nlp_portname, param,
2878 sizeof(ndlp->nlp_portname)) == 0;
2879}
2880
Adrian Bunka6ababd2007-11-05 18:07:33 +01002881static struct lpfc_nodelist *
James Smart2e0fef82007-06-17 19:56:36 -05002882__lpfc_find_node(struct lpfc_vport *vport, node_filter filter, void *param)
dea31012005-04-17 16:05:31 -05002883{
James.Smart@Emulex.Com21568f52005-10-28 20:29:36 -04002884 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05002885
James Smart2e0fef82007-06-17 19:56:36 -05002886 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smart87af33f2007-10-27 13:37:43 -04002887 if (filter(ndlp, param))
James Smart685f0bf2007-04-25 09:53:08 -04002888 return ndlp;
2889 }
James.Smart@Emulex.Com21568f52005-10-28 20:29:36 -04002890 return NULL;
dea31012005-04-17 16:05:31 -05002891}
2892
James Smart685f0bf2007-04-25 09:53:08 -04002893/*
2894 * This routine looks up the ndlp lists for the given RPI. If rpi found it
James Smart2e0fef82007-06-17 19:56:36 -05002895 * returns the node list element pointer else return NULL.
James Smart685f0bf2007-04-25 09:53:08 -04002896 */
2897struct lpfc_nodelist *
James Smart2e0fef82007-06-17 19:56:36 -05002898__lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi)
James Smart685f0bf2007-04-25 09:53:08 -04002899{
James Smart2e0fef82007-06-17 19:56:36 -05002900 return __lpfc_find_node(vport, lpfc_filter_by_rpi, &rpi);
James Smart685f0bf2007-04-25 09:53:08 -04002901}
2902
James Smart488d1462006-03-07 15:02:37 -05002903/*
James Smart685f0bf2007-04-25 09:53:08 -04002904 * This routine looks up the ndlp lists for the given WWPN. If WWPN found it
James Smart2e0fef82007-06-17 19:56:36 -05002905 * returns the node element list pointer else return NULL.
James Smart488d1462006-03-07 15:02:37 -05002906 */
2907struct lpfc_nodelist *
James Smart2e0fef82007-06-17 19:56:36 -05002908lpfc_findnode_wwpn(struct lpfc_vport *vport, struct lpfc_name *wwpn)
James Smart488d1462006-03-07 15:02:37 -05002909{
James Smart2e0fef82007-06-17 19:56:36 -05002910 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart488d1462006-03-07 15:02:37 -05002911 struct lpfc_nodelist *ndlp;
James Smart488d1462006-03-07 15:02:37 -05002912
James Smart2e0fef82007-06-17 19:56:36 -05002913 spin_lock_irq(shost->host_lock);
2914 ndlp = __lpfc_find_node(vport, lpfc_filter_by_wwpn, wwpn);
2915 spin_unlock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05002916 return ndlp;
James Smart488d1462006-03-07 15:02:37 -05002917}
2918
dea31012005-04-17 16:05:31 -05002919void
James Smart2e0fef82007-06-17 19:56:36 -05002920lpfc_nlp_init(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2921 uint32_t did)
dea31012005-04-17 16:05:31 -05002922{
2923 memset(ndlp, 0, sizeof (struct lpfc_nodelist));
dea31012005-04-17 16:05:31 -05002924 INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp);
James Smart92d7f7b2007-06-17 19:56:38 -05002925 INIT_LIST_HEAD(&ndlp->dev_loss_evt.evt_listp);
dea31012005-04-17 16:05:31 -05002926 init_timer(&ndlp->nlp_delayfunc);
2927 ndlp->nlp_delayfunc.function = lpfc_els_retry_delay;
2928 ndlp->nlp_delayfunc.data = (unsigned long)ndlp;
2929 ndlp->nlp_DID = did;
James Smart2e0fef82007-06-17 19:56:36 -05002930 ndlp->vport = vport;
dea31012005-04-17 16:05:31 -05002931 ndlp->nlp_sid = NLP_NO_SID;
James Smart685f0bf2007-04-25 09:53:08 -04002932 INIT_LIST_HEAD(&ndlp->nlp_listp);
James Smart329f9bc2007-04-25 09:53:01 -04002933 kref_init(&ndlp->kref);
James Smarte47c9092008-02-08 18:49:26 -05002934 NLP_INT_NODE_ACT(ndlp);
James Smart858c9f62007-06-17 19:56:39 -05002935
2936 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
2937 "node init: did:x%x",
2938 ndlp->nlp_DID, 0, 0);
2939
dea31012005-04-17 16:05:31 -05002940 return;
2941}
James Smart329f9bc2007-04-25 09:53:01 -04002942
James Smart98c9ea52007-10-27 13:37:33 -04002943/* This routine releases all resources associated with a specifc NPort's ndlp
2944 * and mempool_free's the nodelist.
2945 */
James Smart311464e2007-08-02 11:10:37 -04002946static void
James Smart329f9bc2007-04-25 09:53:01 -04002947lpfc_nlp_release(struct kref *kref)
2948{
James Smarte47c9092008-02-08 18:49:26 -05002949 struct lpfc_hba *phba;
2950 unsigned long flags;
James Smart329f9bc2007-04-25 09:53:01 -04002951 struct lpfc_nodelist *ndlp = container_of(kref, struct lpfc_nodelist,
2952 kref);
James Smart858c9f62007-06-17 19:56:39 -05002953
2954 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
2955 "node release: did:x%x flg:x%x type:x%x",
2956 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
2957
James Smarte47c9092008-02-08 18:49:26 -05002958 lpfc_printf_vlog(ndlp->vport, KERN_INFO, LOG_NODE,
2959 "0279 lpfc_nlp_release: ndlp:x%p "
2960 "usgmap:x%x refcnt:%d\n",
2961 (void *)ndlp, ndlp->nlp_usg_map,
2962 atomic_read(&ndlp->kref.refcount));
2963
2964 /* remove ndlp from action. */
James Smart2e0fef82007-06-17 19:56:36 -05002965 lpfc_nlp_remove(ndlp->vport, ndlp);
James Smarte47c9092008-02-08 18:49:26 -05002966
2967 /* clear the ndlp active flag for all release cases */
2968 phba = ndlp->vport->phba;
2969 spin_lock_irqsave(&phba->ndlp_lock, flags);
2970 NLP_CLR_NODE_ACT(ndlp);
2971 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
2972
2973 /* free ndlp memory for final ndlp release */
2974 if (NLP_CHK_FREE_REQ(ndlp))
2975 mempool_free(ndlp, ndlp->vport->phba->nlp_mem_pool);
James Smart329f9bc2007-04-25 09:53:01 -04002976}
2977
James Smart98c9ea52007-10-27 13:37:33 -04002978/* This routine bumps the reference count for a ndlp structure to ensure
2979 * that one discovery thread won't free a ndlp while another discovery thread
2980 * is using it.
2981 */
James Smart329f9bc2007-04-25 09:53:01 -04002982struct lpfc_nodelist *
2983lpfc_nlp_get(struct lpfc_nodelist *ndlp)
2984{
James Smarte47c9092008-02-08 18:49:26 -05002985 struct lpfc_hba *phba;
2986 unsigned long flags;
2987
James Smart98c9ea52007-10-27 13:37:33 -04002988 if (ndlp) {
2989 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
2990 "node get: did:x%x flg:x%x refcnt:x%x",
2991 ndlp->nlp_DID, ndlp->nlp_flag,
2992 atomic_read(&ndlp->kref.refcount));
James Smarte47c9092008-02-08 18:49:26 -05002993 /* The check of ndlp usage to prevent incrementing the
2994 * ndlp reference count that is in the process of being
2995 * released.
2996 */
2997 phba = ndlp->vport->phba;
2998 spin_lock_irqsave(&phba->ndlp_lock, flags);
2999 if (!NLP_CHK_NODE_ACT(ndlp) || NLP_CHK_FREE_ACK(ndlp)) {
3000 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
3001 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
3002 "0276 lpfc_nlp_get: ndlp:x%p "
3003 "usgmap:x%x refcnt:%d\n",
3004 (void *)ndlp, ndlp->nlp_usg_map,
3005 atomic_read(&ndlp->kref.refcount));
3006 return NULL;
3007 } else
3008 kref_get(&ndlp->kref);
3009 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
James Smart98c9ea52007-10-27 13:37:33 -04003010 }
James Smart329f9bc2007-04-25 09:53:01 -04003011 return ndlp;
3012}
3013
James Smart98c9ea52007-10-27 13:37:33 -04003014/* This routine decrements the reference count for a ndlp structure. If the
James Smarte47c9092008-02-08 18:49:26 -05003015 * count goes to 0, this indicates the the associated nodelist should be
3016 * freed. Returning 1 indicates the ndlp resource has been released; on the
3017 * other hand, returning 0 indicates the ndlp resource has not been released
3018 * yet.
James Smart98c9ea52007-10-27 13:37:33 -04003019 */
James Smart329f9bc2007-04-25 09:53:01 -04003020int
3021lpfc_nlp_put(struct lpfc_nodelist *ndlp)
3022{
James Smarte47c9092008-02-08 18:49:26 -05003023 struct lpfc_hba *phba;
3024 unsigned long flags;
3025
3026 if (!ndlp)
3027 return 1;
3028
3029 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
3030 "node put: did:x%x flg:x%x refcnt:x%x",
3031 ndlp->nlp_DID, ndlp->nlp_flag,
3032 atomic_read(&ndlp->kref.refcount));
3033 phba = ndlp->vport->phba;
3034 spin_lock_irqsave(&phba->ndlp_lock, flags);
3035 /* Check the ndlp memory free acknowledge flag to avoid the
3036 * possible race condition that kref_put got invoked again
3037 * after previous one has done ndlp memory free.
3038 */
3039 if (NLP_CHK_FREE_ACK(ndlp)) {
3040 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
3041 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
3042 "0274 lpfc_nlp_put: ndlp:x%p "
3043 "usgmap:x%x refcnt:%d\n",
3044 (void *)ndlp, ndlp->nlp_usg_map,
3045 atomic_read(&ndlp->kref.refcount));
3046 return 1;
James Smart98c9ea52007-10-27 13:37:33 -04003047 }
James Smarte47c9092008-02-08 18:49:26 -05003048 /* Check the ndlp inactivate log flag to avoid the possible
3049 * race condition that kref_put got invoked again after ndlp
3050 * is already in inactivating state.
3051 */
3052 if (NLP_CHK_IACT_REQ(ndlp)) {
3053 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
3054 lpfc_printf_vlog(ndlp->vport, KERN_WARNING, LOG_NODE,
3055 "0275 lpfc_nlp_put: ndlp:x%p "
3056 "usgmap:x%x refcnt:%d\n",
3057 (void *)ndlp, ndlp->nlp_usg_map,
3058 atomic_read(&ndlp->kref.refcount));
3059 return 1;
3060 }
3061 /* For last put, mark the ndlp usage flags to make sure no
3062 * other kref_get and kref_put on the same ndlp shall get
3063 * in between the process when the final kref_put has been
3064 * invoked on this ndlp.
3065 */
3066 if (atomic_read(&ndlp->kref.refcount) == 1) {
3067 /* Indicate ndlp is put to inactive state. */
3068 NLP_SET_IACT_REQ(ndlp);
3069 /* Acknowledge ndlp memory free has been seen. */
3070 if (NLP_CHK_FREE_REQ(ndlp))
3071 NLP_SET_FREE_ACK(ndlp);
3072 }
3073 spin_unlock_irqrestore(&phba->ndlp_lock, flags);
3074 /* Note, the kref_put returns 1 when decrementing a reference
3075 * count that was 1, it invokes the release callback function,
3076 * but it still left the reference count as 1 (not actually
3077 * performs the last decrementation). Otherwise, it actually
3078 * decrements the reference count and returns 0.
3079 */
3080 return kref_put(&ndlp->kref, lpfc_nlp_release);
James Smart329f9bc2007-04-25 09:53:01 -04003081}
James Smart98c9ea52007-10-27 13:37:33 -04003082
3083/* This routine free's the specified nodelist if it is not in use
James Smarte47c9092008-02-08 18:49:26 -05003084 * by any other discovery thread. This routine returns 1 if the
3085 * ndlp has been freed. A return value of 0 indicates the ndlp is
3086 * not yet been released.
James Smart98c9ea52007-10-27 13:37:33 -04003087 */
3088int
3089lpfc_nlp_not_used(struct lpfc_nodelist *ndlp)
3090{
3091 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
3092 "node not used: did:x%x flg:x%x refcnt:x%x",
3093 ndlp->nlp_DID, ndlp->nlp_flag,
3094 atomic_read(&ndlp->kref.refcount));
James Smarte47c9092008-02-08 18:49:26 -05003095 if (atomic_read(&ndlp->kref.refcount) == 1)
3096 if (lpfc_nlp_put(ndlp))
3097 return 1;
James Smart98c9ea52007-10-27 13:37:33 -04003098 return 0;
3099}