blob: 914e74ac11e5c2a893e4a1daaeb47e163168005d [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 Smart9413aff2007-04-25 09:53:35 -04004 * Copyright (C) 2004-2007 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 *);
dea31012005-04-17 16:05:31 -050060
James Smartc01f3202006-08-18 17:47:08 -040061void
62lpfc_terminate_rport_io(struct fc_rport *rport)
dea31012005-04-17 16:05:31 -050063{
James Smartc01f3202006-08-18 17:47:08 -040064 struct lpfc_rport_data *rdata;
65 struct lpfc_nodelist * ndlp;
66 struct lpfc_hba *phba;
dea31012005-04-17 16:05:31 -050067
James Smartc01f3202006-08-18 17:47:08 -040068 rdata = rport->dd_data;
69 ndlp = rdata->pnode;
70
71 if (!ndlp) {
72 if (rport->roles & FC_RPORT_ROLE_FCP_TARGET)
73 printk(KERN_ERR "Cannot find remote node"
74 " to terminate I/O Data x%x\n",
75 rport->port_id);
dea31012005-04-17 16:05:31 -050076 return;
77 }
78
James Smart2e0fef82007-06-17 19:56:36 -050079 phba = ndlp->vport->phba;
James Smart1a169682006-03-07 15:04:06 -050080
James Smart858c9f62007-06-17 19:56:39 -050081 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_RPORT,
82 "rport terminate: sid:x%x did:x%x flg:x%x",
83 ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag);
84
James Smartc01f3202006-08-18 17:47:08 -040085 if (ndlp->nlp_sid != NLP_NO_SID) {
86 lpfc_sli_abort_iocb(phba, &phba->sli.ring[phba->sli.fcp_ring],
87 ndlp->nlp_sid, 0, 0, LPFC_CTX_TGT);
88 }
James Smartc01f3202006-08-18 17:47:08 -040089
90 return;
91}
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;
103 struct completion devloss_compl;
104 struct lpfc_work_evt *evtp;
James Smartc01f3202006-08-18 17:47:08 -0400105
106 rdata = rport->dd_data;
107 ndlp = rdata->pnode;
108
109 if (!ndlp) {
James Smart92d7f7b2007-06-17 19:56:38 -0500110 if (rport->scsi_target_id != -1) {
James Smartc01f3202006-08-18 17:47:08 -0400111 printk(KERN_ERR "Cannot find remote node"
James Smart92d7f7b2007-06-17 19:56:38 -0500112 " for rport in dev_loss_tmo_callbk x%x\n",
113 rport->port_id);
114 }
James Smartc01f3202006-08-18 17:47:08 -0400115 return;
116 }
117
James Smart858c9f62007-06-17 19:56:39 -0500118 vport = ndlp->vport;
119 phba = vport->phba;
120
121 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
122 "rport devlosscb: sid:x%x did:x%x flg:x%x",
123 ndlp->nlp_sid, ndlp->nlp_DID, ndlp->nlp_flag);
124
125 init_completion(&devloss_compl);
126 evtp = &ndlp->dev_loss_evt;
127
128 if (!list_empty(&evtp->evt_listp))
129 return;
130
131 spin_lock_irq(&phba->hbalock);
132 evtp->evt_arg1 = ndlp;
133 evtp->evt_arg2 = &devloss_compl;
134 evtp->evt = LPFC_EVT_DEV_LOSS;
135 list_add_tail(&evtp->evt_listp, &phba->work_list);
136 if (phba->work_wait)
137 wake_up(phba->work_wait);
138
139 spin_unlock_irq(&phba->hbalock);
140
141 wait_for_completion(&devloss_compl);
142
143 return;
144}
145
146/*
147 * This function is called from the worker thread when dev_loss_tmo
148 * expire.
149 */
150void
151lpfc_dev_loss_tmo_handler(struct lpfc_nodelist *ndlp)
152{
153 struct lpfc_rport_data *rdata;
154 struct fc_rport *rport;
155 struct lpfc_vport *vport;
156 struct lpfc_hba *phba;
157 uint8_t *name;
158 int warn_on = 0;
159
160 rport = ndlp->rport;
161
162 if (!rport)
163 return;
164
165 rdata = rport->dd_data;
166 name = (uint8_t *) &ndlp->nlp_portname;
167 vport = ndlp->vport;
168 phba = vport->phba;
169
170 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
171 "rport devlosstmo:did:x%x type:x%x id:x%x",
172 ndlp->nlp_DID, ndlp->nlp_type, rport->scsi_target_id);
173
174 if (!(vport->load_flag & FC_UNLOADING) &&
175 ndlp->nlp_state == NLP_STE_MAPPED_NODE)
176 return;
177
James Smart92d7f7b2007-06-17 19:56:38 -0500178 if (ndlp->nlp_type & NLP_FABRIC) {
James Smart858c9f62007-06-17 19:56:39 -0500179 int put_node;
180 int put_rport;
181
James Smart92d7f7b2007-06-17 19:56:38 -0500182 /* We will clean up these Nodes in linkup */
183 put_node = rdata->pnode != NULL;
184 put_rport = ndlp->rport != NULL;
185 rdata->pnode = NULL;
186 ndlp->rport = NULL;
187 if (put_node)
188 lpfc_nlp_put(ndlp);
189 if (put_rport)
190 put_device(&rport->dev);
James Smart82085712007-04-25 09:52:41 -0400191 return;
James Smart92d7f7b2007-06-17 19:56:38 -0500192 }
James Smart82085712007-04-25 09:52:41 -0400193
dea31012005-04-17 16:05:31 -0500194 if (ndlp->nlp_sid != NLP_NO_SID) {
James.Smart@Emulex.Com6e8215e2005-06-25 10:34:04 -0400195 warn_on = 1;
dea31012005-04-17 16:05:31 -0500196 /* flush the target */
197 lpfc_sli_abort_iocb(phba, &phba->sli.ring[phba->sli.fcp_ring],
James Smart92d7f7b2007-06-17 19:56:38 -0500198 ndlp->nlp_sid, 0, 0, LPFC_CTX_TGT);
dea31012005-04-17 16:05:31 -0500199 }
James Smart2e0fef82007-06-17 19:56:36 -0500200 if (vport->load_flag & FC_UNLOADING)
James Smartc01f3202006-08-18 17:47:08 -0400201 warn_on = 0;
202
James.Smart@Emulex.Com6e8215e2005-06-25 10:34:04 -0400203 if (warn_on) {
204 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
James Smart92d7f7b2007-06-17 19:56:38 -0500205 "%d (%d):0203 Devloss timeout on "
James Smart488d1462006-03-07 15:02:37 -0500206 "WWPN %x:%x:%x:%x:%x:%x:%x:%x "
207 "NPort x%x Data: x%x x%x x%x\n",
James Smart92d7f7b2007-06-17 19:56:38 -0500208 phba->brd_no, vport->vpi,
James Smart488d1462006-03-07 15:02:37 -0500209 *name, *(name+1), *(name+2), *(name+3),
210 *(name+4), *(name+5), *(name+6), *(name+7),
211 ndlp->nlp_DID, ndlp->nlp_flag,
James.Smart@Emulex.Com6e8215e2005-06-25 10:34:04 -0400212 ndlp->nlp_state, ndlp->nlp_rpi);
213 } else {
214 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smart92d7f7b2007-06-17 19:56:38 -0500215 "%d (%d):0204 Devloss timeout on "
James Smart488d1462006-03-07 15:02:37 -0500216 "WWPN %x:%x:%x:%x:%x:%x:%x:%x "
217 "NPort x%x Data: x%x x%x x%x\n",
James Smart92d7f7b2007-06-17 19:56:38 -0500218 phba->brd_no, vport->vpi,
James Smart488d1462006-03-07 15:02:37 -0500219 *name, *(name+1), *(name+2), *(name+3),
220 *(name+4), *(name+5), *(name+6), *(name+7),
221 ndlp->nlp_DID, ndlp->nlp_flag,
James.Smart@Emulex.Com6e8215e2005-06-25 10:34:04 -0400222 ndlp->nlp_state, ndlp->nlp_rpi);
223 }
224
James Smart2e0fef82007-06-17 19:56:36 -0500225 if (!(vport->load_flag & FC_UNLOADING) &&
James Smart1dcb58e2007-04-25 09:51:30 -0400226 !(ndlp->nlp_flag & NLP_DELAY_TMO) &&
James Smart82085712007-04-25 09:52:41 -0400227 !(ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
228 (ndlp->nlp_state != NLP_STE_UNMAPPED_NODE))
James Smart2e0fef82007-06-17 19:56:36 -0500229 lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
James Smart1dcb58e2007-04-25 09:51:30 -0400230 else {
James Smart858c9f62007-06-17 19:56:39 -0500231 int put_node;
232 int put_rport;
233
James Smart92d7f7b2007-06-17 19:56:38 -0500234 put_node = rdata->pnode != NULL;
235 put_rport = ndlp->rport != NULL;
James Smart1dcb58e2007-04-25 09:51:30 -0400236 rdata->pnode = NULL;
237 ndlp->rport = NULL;
James Smart92d7f7b2007-06-17 19:56:38 -0500238 if (put_node)
239 lpfc_nlp_put(ndlp);
240 if (put_rport)
241 put_device(&rport->dev);
James Smart1dcb58e2007-04-25 09:51:30 -0400242 }
James Smart92d7f7b2007-06-17 19:56:38 -0500243}
James Smartc01f3202006-08-18 17:47:08 -0400244
James Smart92d7f7b2007-06-17 19:56:38 -0500245
246void
247lpfc_worker_wake_up(struct lpfc_hba *phba)
248{
249 wake_up(phba->work_wait);
dea31012005-04-17 16:05:31 -0500250 return;
251}
252
253static void
James Smart2e0fef82007-06-17 19:56:36 -0500254lpfc_work_list_done(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500255{
256 struct lpfc_work_evt *evtp = NULL;
257 struct lpfc_nodelist *ndlp;
James Smart92d7f7b2007-06-17 19:56:38 -0500258 struct lpfc_vport *vport;
dea31012005-04-17 16:05:31 -0500259 int free_evt;
260
James Smart2e0fef82007-06-17 19:56:36 -0500261 spin_lock_irq(&phba->hbalock);
262 while (!list_empty(&phba->work_list)) {
dea31012005-04-17 16:05:31 -0500263 list_remove_head((&phba->work_list), evtp, typeof(*evtp),
264 evt_listp);
James Smart2e0fef82007-06-17 19:56:36 -0500265 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500266 free_evt = 1;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500267 switch (evtp->evt) {
James Smart858c9f62007-06-17 19:56:39 -0500268 case LPFC_EVT_DEV_LOSS_DELAY:
James Smart92d7f7b2007-06-17 19:56:38 -0500269 free_evt = 0; /* evt is part of ndlp */
270 ndlp = (struct lpfc_nodelist *) (evtp->evt_arg1);
271 vport = ndlp->vport;
272 if (!vport)
273 break;
James Smart858c9f62007-06-17 19:56:39 -0500274
275 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
276 "rport devlossdly:did:x%x flg:x%x",
277 ndlp->nlp_DID, ndlp->nlp_flag, 0);
278
James Smart92d7f7b2007-06-17 19:56:38 -0500279 if (!(vport->load_flag & FC_UNLOADING) &&
280 !(ndlp->nlp_flag & NLP_DELAY_TMO) &&
281 !(ndlp->nlp_flag & NLP_NPR_2B_DISC)) {
282 lpfc_disc_state_machine(vport, ndlp, NULL,
283 NLP_EVT_DEVICE_RM);
284 }
285 break;
dea31012005-04-17 16:05:31 -0500286 case LPFC_EVT_ELS_RETRY:
James Smart2e0fef82007-06-17 19:56:36 -0500287 ndlp = (struct lpfc_nodelist *) (evtp->evt_arg1);
dea31012005-04-17 16:05:31 -0500288 lpfc_els_retry_delay_handler(ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -0500289 free_evt = 0; /* evt is part of ndlp */
dea31012005-04-17 16:05:31 -0500290 break;
James Smart858c9f62007-06-17 19:56:39 -0500291 case LPFC_EVT_DEV_LOSS:
292 ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1);
293 lpfc_nlp_get(ndlp);
294 lpfc_dev_loss_tmo_handler(ndlp);
295 free_evt = 0;
296 complete((struct completion *)(evtp->evt_arg2));
297 lpfc_nlp_put(ndlp);
298 break;
dea31012005-04-17 16:05:31 -0500299 case LPFC_EVT_ONLINE:
James Smart2e0fef82007-06-17 19:56:36 -0500300 if (phba->link_state < LPFC_LINK_DOWN)
301 *(int *) (evtp->evt_arg1) = lpfc_online(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500302 else
James Smart2e0fef82007-06-17 19:56:36 -0500303 *(int *) (evtp->evt_arg1) = 0;
dea31012005-04-17 16:05:31 -0500304 complete((struct completion *)(evtp->evt_arg2));
305 break;
James Smart46fa3112007-04-25 09:51:45 -0400306 case LPFC_EVT_OFFLINE_PREP:
James Smart2e0fef82007-06-17 19:56:36 -0500307 if (phba->link_state >= LPFC_LINK_DOWN)
James Smart46fa3112007-04-25 09:51:45 -0400308 lpfc_offline_prep(phba);
309 *(int *)(evtp->evt_arg1) = 0;
310 complete((struct completion *)(evtp->evt_arg2));
311 break;
312 case LPFC_EVT_OFFLINE:
313 lpfc_offline(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500314 lpfc_sli_brdrestart(phba);
315 *(int *)(evtp->evt_arg1) =
James Smart46fa3112007-04-25 09:51:45 -0400316 lpfc_sli_brdready(phba, HS_FFRDY | HS_MBRDY);
317 lpfc_unblock_mgmt_io(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500318 complete((struct completion *)(evtp->evt_arg2));
319 break;
320 case LPFC_EVT_WARM_START:
James Smart46fa3112007-04-25 09:51:45 -0400321 lpfc_offline(phba);
James Smart92908312006-03-07 15:04:13 -0500322 lpfc_reset_barrier(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500323 lpfc_sli_brdreset(phba);
324 lpfc_hba_down_post(phba);
325 *(int *)(evtp->evt_arg1) =
326 lpfc_sli_brdready(phba, HS_MBRDY);
James Smart46fa3112007-04-25 09:51:45 -0400327 lpfc_unblock_mgmt_io(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500328 complete((struct completion *)(evtp->evt_arg2));
329 break;
330 case LPFC_EVT_KILL:
James Smart46fa3112007-04-25 09:51:45 -0400331 lpfc_offline(phba);
James Smart92908312006-03-07 15:04:13 -0500332 *(int *)(evtp->evt_arg1)
James Smart2e0fef82007-06-17 19:56:36 -0500333 = (phba->pport->stopped)
334 ? 0 : lpfc_sli_brdkill(phba);
James Smart46fa3112007-04-25 09:51:45 -0400335 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -0500336 complete((struct completion *)(evtp->evt_arg2));
337 break;
338 }
339 if (free_evt)
340 kfree(evtp);
James Smart2e0fef82007-06-17 19:56:36 -0500341 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500342 }
James Smart2e0fef82007-06-17 19:56:36 -0500343 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500344
345}
346
James Smart858c9f62007-06-17 19:56:39 -0500347void
James Smart2e0fef82007-06-17 19:56:36 -0500348lpfc_work_done(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500349{
350 struct lpfc_sli_ring *pring;
James Smart858c9f62007-06-17 19:56:39 -0500351 uint32_t ha_copy, status, control, work_port_events;
James Smart549e55c2007-08-02 11:09:51 -0400352 struct lpfc_vport **vports;
353 int i;
dea31012005-04-17 16:05:31 -0500354
James Smart2e0fef82007-06-17 19:56:36 -0500355 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500356 ha_copy = phba->work_ha;
357 phba->work_ha = 0;
James Smart2e0fef82007-06-17 19:56:36 -0500358 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500359
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500360 if (ha_copy & HA_ERATT)
dea31012005-04-17 16:05:31 -0500361 lpfc_handle_eratt(phba);
362
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500363 if (ha_copy & HA_MBATT)
dea31012005-04-17 16:05:31 -0500364 lpfc_sli_handle_mb_event(phba);
365
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500366 if (ha_copy & HA_LATT)
dea31012005-04-17 16:05:31 -0500367 lpfc_handle_latt(phba);
James Smart549e55c2007-08-02 11:09:51 -0400368 vports = lpfc_create_vport_work_array(phba);
369 if (vports != NULL)
370 for(i = 0; i < LPFC_MAX_VPORTS && vports[i] != NULL; i++) {
371 work_port_events = vports[i]->work_port_events;
372 if (work_port_events & WORKER_DISC_TMO)
373 lpfc_disc_timeout_handler(vports[i]);
374 if (work_port_events & WORKER_ELS_TMO)
375 lpfc_els_timeout_handler(vports[i]);
376 if (work_port_events & WORKER_HB_TMO)
377 lpfc_hb_timeout_handler(phba);
378 if (work_port_events & WORKER_MBOX_TMO)
379 lpfc_mbox_timeout_handler(phba);
380 if (work_port_events & WORKER_FABRIC_BLOCK_TMO)
381 lpfc_unblock_fabric_iocbs(phba);
382 if (work_port_events & WORKER_FDMI_TMO)
383 lpfc_fdmi_timeout_handler(vports[i]);
384 if (work_port_events & WORKER_RAMP_DOWN_QUEUE)
385 lpfc_ramp_down_queue_handler(phba);
386 if (work_port_events & WORKER_RAMP_UP_QUEUE)
387 lpfc_ramp_up_queue_handler(phba);
388 spin_lock_irq(&vports[i]->work_port_lock);
389 vports[i]->work_port_events &= ~work_port_events;
390 spin_unlock_irq(&vports[i]->work_port_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500391 }
James Smart549e55c2007-08-02 11:09:51 -0400392 lpfc_destroy_vport_work_array(vports);
dea31012005-04-17 16:05:31 -0500393
James Smart858c9f62007-06-17 19:56:39 -0500394 pring = &phba->sli.ring[LPFC_ELS_RING];
395 status = (ha_copy & (HA_RXMASK << (4*LPFC_ELS_RING)));
396 status >>= (4*LPFC_ELS_RING);
397 if ((status & HA_RXMASK)
398 || (pring->flag & LPFC_DEFERRED_RING_EVENT)) {
399 if (pring->flag & LPFC_STOP_IOCB_MASK) {
400 pring->flag |= LPFC_DEFERRED_RING_EVENT;
401 } else {
402 lpfc_sli_handle_slow_ring_event(phba, pring,
403 (status &
404 HA_RXMASK));
405 pring->flag &= ~LPFC_DEFERRED_RING_EVENT;
406 }
407 /*
408 * Turn on Ring interrupts
409 */
410 spin_lock_irq(&phba->hbalock);
411 control = readl(phba->HCregaddr);
412 if (!(control & (HC_R0INT_ENA << LPFC_ELS_RING))) {
James Smarta58cbd52007-08-02 11:09:43 -0400413 lpfc_debugfs_slow_ring_trc(phba,
414 "WRK Enable ring: cntl:x%x hacopy:x%x",
415 control, ha_copy, 0);
416
James Smart858c9f62007-06-17 19:56:39 -0500417 control |= (HC_R0INT_ENA << LPFC_ELS_RING);
dea31012005-04-17 16:05:31 -0500418 writel(control, phba->HCregaddr);
419 readl(phba->HCregaddr); /* flush */
dea31012005-04-17 16:05:31 -0500420 }
James Smarta58cbd52007-08-02 11:09:43 -0400421 else {
422 lpfc_debugfs_slow_ring_trc(phba,
423 "WRK Ring ok: cntl:x%x hacopy:x%x",
424 control, ha_copy, 0);
425 }
James Smart858c9f62007-06-17 19:56:39 -0500426 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500427 }
James Smart2e0fef82007-06-17 19:56:36 -0500428 lpfc_work_list_done(phba);
dea31012005-04-17 16:05:31 -0500429}
430
431static int
James Smart2e0fef82007-06-17 19:56:36 -0500432check_work_wait_done(struct lpfc_hba *phba)
433{
James Smart92d7f7b2007-06-17 19:56:38 -0500434 struct lpfc_vport *vport;
James Smart549e55c2007-08-02 11:09:51 -0400435 struct lpfc_sli_ring *pring = &phba->sli.ring[LPFC_ELS_RING];
James Smart858c9f62007-06-17 19:56:39 -0500436 int rc = 0;
James Smarted957682007-06-17 19:56:37 -0500437
James Smart2e0fef82007-06-17 19:56:36 -0500438 spin_lock_irq(&phba->hbalock);
James Smart92d7f7b2007-06-17 19:56:38 -0500439 list_for_each_entry(vport, &phba->port_list, listentry) {
440 if (vport->work_port_events) {
441 rc = 1;
James Smart549e55c2007-08-02 11:09:51 -0400442 break;
James Smart92d7f7b2007-06-17 19:56:38 -0500443 }
444 }
James Smart549e55c2007-08-02 11:09:51 -0400445 if (rc || phba->work_ha || (!list_empty(&phba->work_list)) ||
446 kthread_should_stop() || pring->flag & LPFC_DEFERRED_RING_EVENT) {
James Smart2e0fef82007-06-17 19:56:36 -0500447 rc = 1;
James Smart92d7f7b2007-06-17 19:56:38 -0500448 phba->work_found++;
James Smart549e55c2007-08-02 11:09:51 -0400449 } else
James Smart92d7f7b2007-06-17 19:56:38 -0500450 phba->work_found = 0;
James Smart2e0fef82007-06-17 19:56:36 -0500451 spin_unlock_irq(&phba->hbalock);
452 return rc;
dea31012005-04-17 16:05:31 -0500453}
454
James Smart92d7f7b2007-06-17 19:56:38 -0500455
dea31012005-04-17 16:05:31 -0500456int
457lpfc_do_work(void *p)
458{
459 struct lpfc_hba *phba = p;
460 int rc;
Peter Zijlstra7259f0d2006-10-29 22:46:36 -0800461 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(work_waitq);
dea31012005-04-17 16:05:31 -0500462
463 set_user_nice(current, -20);
464 phba->work_wait = &work_waitq;
James Smart92d7f7b2007-06-17 19:56:38 -0500465 phba->work_found = 0;
dea31012005-04-17 16:05:31 -0500466
467 while (1) {
468
469 rc = wait_event_interruptible(work_waitq,
James Smart92d7f7b2007-06-17 19:56:38 -0500470 check_work_wait_done(phba));
471
dea31012005-04-17 16:05:31 -0500472 BUG_ON(rc);
473
474 if (kthread_should_stop())
475 break;
476
477 lpfc_work_done(phba);
478
James Smart92d7f7b2007-06-17 19:56:38 -0500479 /* If there is alot of slow ring work, like during link up
480 * check_work_wait_done() may cause this thread to not give
481 * up the CPU for very long periods of time. This may cause
482 * soft lockups or other problems. To avoid these situations
483 * give up the CPU here after LPFC_MAX_WORKER_ITERATION
484 * consecutive iterations.
485 */
486 if (phba->work_found >= LPFC_MAX_WORKER_ITERATION) {
487 phba->work_found = 0;
488 schedule();
489 }
dea31012005-04-17 16:05:31 -0500490 }
491 phba->work_wait = NULL;
492 return 0;
493}
494
495/*
496 * This is only called to handle FC worker events. Since this a rare
497 * occurance, we allocate a struct lpfc_work_evt structure here instead of
498 * embedding it in the IOCB.
499 */
500int
James Smart2e0fef82007-06-17 19:56:36 -0500501lpfc_workq_post_event(struct lpfc_hba *phba, void *arg1, void *arg2,
dea31012005-04-17 16:05:31 -0500502 uint32_t evt)
503{
504 struct lpfc_work_evt *evtp;
James Smarted957682007-06-17 19:56:37 -0500505 unsigned long flags;
dea31012005-04-17 16:05:31 -0500506
507 /*
508 * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will
509 * be queued to worker thread for processing
510 */
James Smart92d7f7b2007-06-17 19:56:38 -0500511 evtp = kmalloc(sizeof(struct lpfc_work_evt), GFP_ATOMIC);
dea31012005-04-17 16:05:31 -0500512 if (!evtp)
513 return 0;
514
515 evtp->evt_arg1 = arg1;
516 evtp->evt_arg2 = arg2;
517 evtp->evt = evt;
518
James Smarted957682007-06-17 19:56:37 -0500519 spin_lock_irqsave(&phba->hbalock, flags);
James Smart071fbd3d2006-04-15 11:53:20 -0400520 list_add_tail(&evtp->evt_listp, &phba->work_list);
dea31012005-04-17 16:05:31 -0500521 if (phba->work_wait)
James Smart92d7f7b2007-06-17 19:56:38 -0500522 lpfc_worker_wake_up(phba);
James Smarted957682007-06-17 19:56:37 -0500523 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -0500524
525 return 1;
526}
527
James Smart92d7f7b2007-06-17 19:56:38 -0500528void
529lpfc_cleanup_rpis(struct lpfc_vport *vport, int remove)
530{
531 struct lpfc_hba *phba = vport->phba;
532 struct lpfc_nodelist *ndlp, *next_ndlp;
533 int rc;
534
535 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
536 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
537 continue;
538
539 if (phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN)
540 lpfc_unreg_rpi(vport, ndlp);
541
542 /* Leave Fabric nodes alone on link down */
543 if (!remove && ndlp->nlp_type & NLP_FABRIC)
544 continue;
545 rc = lpfc_disc_state_machine(vport, ndlp, NULL,
546 remove
547 ? NLP_EVT_DEVICE_RM
548 : NLP_EVT_DEVICE_RECOVERY);
549 }
550 if (phba->sli3_options & LPFC_SLI3_VPORT_TEARDOWN) {
551 lpfc_mbx_unreg_vpi(vport);
552 vport->fc_flag |= FC_VPORT_NEEDS_REG_VPI;
553 }
554}
555
556static void
557lpfc_linkdown_port(struct lpfc_vport *vport)
558{
559 struct lpfc_nodelist *ndlp, *next_ndlp;
560 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
561
562 fc_host_post_event(shost, fc_get_event_number(), FCH_EVT_LINKDOWN, 0);
563
James Smart858c9f62007-06-17 19:56:39 -0500564 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
565 "Link Down: state:x%x rtry:x%x flg:x%x",
566 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
567
James Smart92d7f7b2007-06-17 19:56:38 -0500568 /* Cleanup any outstanding RSCN activity */
569 lpfc_els_flush_rscn(vport);
570
571 /* Cleanup any outstanding ELS commands */
572 lpfc_els_flush_cmd(vport);
573
574 lpfc_cleanup_rpis(vport, 0);
575
576 /* free any ndlp's on unused list */
577 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp)
James Smart92d7f7b2007-06-17 19:56:38 -0500578 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
579 lpfc_drop_node(vport, ndlp);
580
581 /* Turn off discovery timer if its running */
582 lpfc_can_disctmo(vport);
583}
584
dea31012005-04-17 16:05:31 -0500585int
James Smart685f0bf2007-04-25 09:53:08 -0400586lpfc_linkdown(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500587{
James Smart2e0fef82007-06-17 19:56:36 -0500588 struct lpfc_vport *vport = phba->pport;
589 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart549e55c2007-08-02 11:09:51 -0400590 struct lpfc_vport **vports;
James Smart685f0bf2007-04-25 09:53:08 -0400591 LPFC_MBOXQ_t *mb;
James Smart549e55c2007-08-02 11:09:51 -0400592 int i;
dea31012005-04-17 16:05:31 -0500593
James Smart2e0fef82007-06-17 19:56:36 -0500594 if (phba->link_state == LPFC_LINK_DOWN) {
595 return 0;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500596 }
James Smart2e0fef82007-06-17 19:56:36 -0500597 spin_lock_irq(&phba->hbalock);
James Smart92d7f7b2007-06-17 19:56:38 -0500598 if (phba->link_state > LPFC_LINK_DOWN) {
James Smart2e0fef82007-06-17 19:56:36 -0500599 phba->link_state = LPFC_LINK_DOWN;
James Smart92d7f7b2007-06-17 19:56:38 -0500600 phba->pport->fc_flag &= ~FC_LBIT;
601 }
James Smart2e0fef82007-06-17 19:56:36 -0500602 spin_unlock_irq(&phba->hbalock);
James Smart549e55c2007-08-02 11:09:51 -0400603 vports = lpfc_create_vport_work_array(phba);
604 if (vports != NULL)
605 for(i = 0; i < LPFC_MAX_VPORTS && vports[i] != NULL; i++) {
606 /* Issue a LINK DOWN event to all nodes */
607 lpfc_linkdown_port(vports[i]);
608 }
609 lpfc_destroy_vport_work_array(vports);
dea31012005-04-17 16:05:31 -0500610 /* Clean up any firmware default rpi's */
James Smart2e0fef82007-06-17 19:56:36 -0500611 mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
612 if (mb) {
James Smart92d7f7b2007-06-17 19:56:38 -0500613 lpfc_unreg_did(phba, 0xffff, 0xffffffff, mb);
James Smarted957682007-06-17 19:56:37 -0500614 mb->vport = vport;
James Smart2e0fef82007-06-17 19:56:36 -0500615 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
dea31012005-04-17 16:05:31 -0500616 if (lpfc_sli_issue_mbox(phba, mb, (MBX_NOWAIT | MBX_STOP_IOCB))
617 == MBX_NOT_FINISHED) {
James Smart2e0fef82007-06-17 19:56:36 -0500618 mempool_free(mb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500619 }
620 }
621
dea31012005-04-17 16:05:31 -0500622 /* Setup myDID for link up if we are in pt2pt mode */
James Smart92d7f7b2007-06-17 19:56:38 -0500623 if (phba->pport->fc_flag & FC_PT2PT) {
624 phba->pport->fc_myDID = 0;
James Smart2e0fef82007-06-17 19:56:36 -0500625 mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
626 if (mb) {
dea31012005-04-17 16:05:31 -0500627 lpfc_config_link(phba, mb);
James Smart92d7f7b2007-06-17 19:56:38 -0500628 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -0500629 mb->vport = vport;
James Smart2e0fef82007-06-17 19:56:36 -0500630 if (lpfc_sli_issue_mbox(phba, mb,
631 (MBX_NOWAIT | MBX_STOP_IOCB))
dea31012005-04-17 16:05:31 -0500632 == MBX_NOT_FINISHED) {
James Smart2e0fef82007-06-17 19:56:36 -0500633 mempool_free(mb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500634 }
635 }
James Smart2e0fef82007-06-17 19:56:36 -0500636 spin_lock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -0500637 phba->pport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI);
James Smart2e0fef82007-06-17 19:56:36 -0500638 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500639 }
James Smart2e0fef82007-06-17 19:56:36 -0500640
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500641 return 0;
dea31012005-04-17 16:05:31 -0500642}
643
James Smart92d7f7b2007-06-17 19:56:38 -0500644static void
645lpfc_linkup_cleanup_nodes(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -0500646{
James Smart92d7f7b2007-06-17 19:56:38 -0500647 struct lpfc_nodelist *ndlp;
648
649 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
650 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
651 continue;
652
653 if (ndlp->nlp_type & NLP_FABRIC) {
654 /* On Linkup its safe to clean up the ndlp
655 * from Fabric connections.
656 */
657 if (ndlp->nlp_DID != Fabric_DID)
658 lpfc_unreg_rpi(vport, ndlp);
659 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
660 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
661 /* Fail outstanding IO now since device is
662 * marked for PLOGI.
663 */
664 lpfc_unreg_rpi(vport, ndlp);
665 }
666 }
667}
668
669static void
670lpfc_linkup_port(struct lpfc_vport *vport)
671{
672 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500673 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart92d7f7b2007-06-17 19:56:38 -0500674 struct lpfc_hba *phba = vport->phba;
675
676 if ((vport->load_flag & FC_UNLOADING) != 0)
677 return;
678
James Smart858c9f62007-06-17 19:56:39 -0500679 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
680 "Link Up: top:x%x speed:x%x flg:x%x",
681 phba->fc_topology, phba->fc_linkspeed, phba->link_flag);
682
James Smart92d7f7b2007-06-17 19:56:38 -0500683 /* If NPIV is not enabled, only bring the physical port up */
684 if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
685 (vport != phba->pport))
686 return;
dea31012005-04-17 16:05:31 -0500687
James Smart2e0fef82007-06-17 19:56:36 -0500688 fc_host_post_event(shost, fc_get_event_number(), FCH_EVT_LINKUP, 0);
James Smartd2873e42006-08-18 17:46:43 -0400689
James Smart2e0fef82007-06-17 19:56:36 -0500690 spin_lock_irq(shost->host_lock);
James Smart2e0fef82007-06-17 19:56:36 -0500691 vport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI | FC_ABORT_DISCOVERY |
692 FC_RSCN_MODE | FC_NLP_MORE | FC_RSCN_DISCOVERY);
693 vport->fc_flag |= FC_NDISC_ACTIVE;
694 vport->fc_ns_retry = 0;
695 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500696
James Smart92d7f7b2007-06-17 19:56:38 -0500697 if (vport->fc_flag & FC_LBIT)
698 lpfc_linkup_cleanup_nodes(vport);
dea31012005-04-17 16:05:31 -0500699
James Smart92d7f7b2007-06-17 19:56:38 -0500700 /* free any ndlp's in unused state */
James Smart2e0fef82007-06-17 19:56:36 -0500701 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
James Smart92d7f7b2007-06-17 19:56:38 -0500702 nlp_listp)
James Smart685f0bf2007-04-25 09:53:08 -0400703 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
James Smart2e0fef82007-06-17 19:56:36 -0500704 lpfc_drop_node(vport, ndlp);
James Smart92d7f7b2007-06-17 19:56:38 -0500705}
706
707static int
708lpfc_linkup(struct lpfc_hba *phba)
709{
James Smart549e55c2007-08-02 11:09:51 -0400710 struct lpfc_vport **vports;
711 int i;
James Smart92d7f7b2007-06-17 19:56:38 -0500712
713 phba->link_state = LPFC_LINK_UP;
714
715 /* Unblock fabric iocbs if they are blocked */
716 clear_bit(FABRIC_COMANDS_BLOCKED, &phba->bit_flags);
717 del_timer_sync(&phba->fabric_block_timer);
718
James Smart549e55c2007-08-02 11:09:51 -0400719 vports = lpfc_create_vport_work_array(phba);
720 if (vports != NULL)
721 for(i = 0; i < LPFC_MAX_VPORTS && vports[i] != NULL; i++)
722 lpfc_linkup_port(vports[i]);
723 lpfc_destroy_vport_work_array(vports);
James Smart92d7f7b2007-06-17 19:56:38 -0500724 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
725 lpfc_issue_clear_la(phba, phba->pport);
dea31012005-04-17 16:05:31 -0500726
727 return 0;
728}
729
730/*
731 * This routine handles processing a CLEAR_LA mailbox
732 * command upon completion. It is setup in the LPFC_MBOXQ
733 * as the completion routine when the command is
734 * handed off to the SLI layer.
735 */
736void
James Smart2e0fef82007-06-17 19:56:36 -0500737lpfc_mbx_cmpl_clear_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -0500738{
James Smart2e0fef82007-06-17 19:56:36 -0500739 struct lpfc_vport *vport = pmb->vport;
740 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
741 struct lpfc_sli *psli = &phba->sli;
742 MAILBOX_t *mb = &pmb->mb;
dea31012005-04-17 16:05:31 -0500743 uint32_t control;
744
dea31012005-04-17 16:05:31 -0500745 /* Since we don't do discovery right now, turn these off here */
James Smarta4bc3372006-12-02 13:34:16 -0500746 psli->ring[psli->extra_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
dea31012005-04-17 16:05:31 -0500747 psli->ring[psli->fcp_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
748 psli->ring[psli->next_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
749
750 /* Check for error */
751 if ((mb->mbxStatus) && (mb->mbxStatus != 0x1601)) {
James Smart92d7f7b2007-06-17 19:56:38 -0500752 /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */
dea31012005-04-17 16:05:31 -0500753 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
James Smart92d7f7b2007-06-17 19:56:38 -0500754 "%d (%d):0320 CLEAR_LA mbxStatus error x%x hba "
dea31012005-04-17 16:05:31 -0500755 "state x%x\n",
James Smart92d7f7b2007-06-17 19:56:38 -0500756 phba->brd_no, vport->vpi, mb->mbxStatus,
757 vport->port_state);
dea31012005-04-17 16:05:31 -0500758
James Smart2e0fef82007-06-17 19:56:36 -0500759 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500760 goto out;
761 }
762
James Smart92d7f7b2007-06-17 19:56:38 -0500763 if (vport->port_type == LPFC_PHYSICAL_PORT)
764 phba->link_state = LPFC_HBA_READY;
765
766 spin_lock_irq(&phba->hbalock);
767 psli->sli_flag |= LPFC_PROCESS_LA;
768 control = readl(phba->HCregaddr);
769 control |= HC_LAINT_ENA;
770 writel(control, phba->HCregaddr);
771 readl(phba->HCregaddr); /* flush */
772 spin_unlock_irq(&phba->hbalock);
773 return;
dea31012005-04-17 16:05:31 -0500774
James Smart2e0fef82007-06-17 19:56:36 -0500775 vport->num_disc_nodes = 0;
776 /* go thru NPR nodes and issue ELS PLOGIs */
777 if (vport->fc_npr_cnt)
778 lpfc_els_disc_plogi(vport);
779
780 if (!vport->num_disc_nodes) {
781 spin_lock_irq(shost->host_lock);
782 vport->fc_flag &= ~FC_NDISC_ACTIVE;
783 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500784 }
785
James Smart2e0fef82007-06-17 19:56:36 -0500786 vport->port_state = LPFC_VPORT_READY;
dea31012005-04-17 16:05:31 -0500787
788out:
789 /* Device Discovery completes */
James Smarted957682007-06-17 19:56:37 -0500790 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smart92d7f7b2007-06-17 19:56:38 -0500791 "%d (%d):0225 Device Discovery completes\n",
792 phba->brd_no, vport->vpi);
dea31012005-04-17 16:05:31 -0500793
James Smart2e0fef82007-06-17 19:56:36 -0500794 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500795
James Smart2e0fef82007-06-17 19:56:36 -0500796 spin_lock_irq(shost->host_lock);
797 vport->fc_flag &= ~(FC_ABORT_DISCOVERY | FC_ESTABLISH_LINK);
798 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500799
800 del_timer_sync(&phba->fc_estabtmo);
801
James Smart2e0fef82007-06-17 19:56:36 -0500802 lpfc_can_disctmo(vport);
dea31012005-04-17 16:05:31 -0500803
804 /* turn on Link Attention interrupts */
James Smart2e0fef82007-06-17 19:56:36 -0500805
806 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500807 psli->sli_flag |= LPFC_PROCESS_LA;
808 control = readl(phba->HCregaddr);
809 control |= HC_LAINT_ENA;
810 writel(control, phba->HCregaddr);
811 readl(phba->HCregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -0500812 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500813
814 return;
815}
816
James Smart2e0fef82007-06-17 19:56:36 -0500817
dea31012005-04-17 16:05:31 -0500818static void
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500819lpfc_mbx_cmpl_local_config_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -0500820{
James Smart2e0fef82007-06-17 19:56:36 -0500821 struct lpfc_vport *vport = pmb->vport;
dea31012005-04-17 16:05:31 -0500822
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500823 if (pmb->mb.mbxStatus)
dea31012005-04-17 16:05:31 -0500824 goto out;
dea31012005-04-17 16:05:31 -0500825
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500826 mempool_free(pmb, phba->mbox_mem_pool);
827
828 if (phba->fc_topology == TOPOLOGY_LOOP &&
James Smart2e0fef82007-06-17 19:56:36 -0500829 vport->fc_flag & FC_PUBLIC_LOOP &&
830 !(vport->fc_flag & FC_LBIT)) {
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500831 /* Need to wait for FAN - use discovery timer
James Smart2e0fef82007-06-17 19:56:36 -0500832 * for timeout. port_state is identically
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500833 * LPFC_LOCAL_CFG_LINK while waiting for FAN
834 */
James Smart2e0fef82007-06-17 19:56:36 -0500835 lpfc_set_disctmo(vport);
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500836 return;
James Smart92d7f7b2007-06-17 19:56:38 -0500837 }
dea31012005-04-17 16:05:31 -0500838
James Smart2e0fef82007-06-17 19:56:36 -0500839 /* Start discovery by sending a FLOGI. port_state is identically
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500840 * LPFC_FLOGI while waiting for FLOGI cmpl
841 */
James Smart92d7f7b2007-06-17 19:56:38 -0500842 if (vport->port_state != LPFC_FLOGI) {
843 vport->port_state = LPFC_FLOGI;
844 lpfc_set_disctmo(vport);
845 lpfc_initial_flogi(vport);
846 }
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500847 return;
dea31012005-04-17 16:05:31 -0500848
849out:
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500850 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
James Smart92d7f7b2007-06-17 19:56:38 -0500851 "%d (%d):0306 CONFIG_LINK mbxStatus error x%x "
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500852 "HBA state x%x\n",
James Smart92d7f7b2007-06-17 19:56:38 -0500853 phba->brd_no, vport->vpi, pmb->mb.mbxStatus,
854 vport->port_state);
855
856 mempool_free(pmb, phba->mbox_mem_pool);
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500857
858 lpfc_linkdown(phba);
859
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500860 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
James Smart92d7f7b2007-06-17 19:56:38 -0500861 "%d (%d):0200 CONFIG_LINK bad hba state x%x\n",
862 phba->brd_no, vport->vpi, vport->port_state);
dea31012005-04-17 16:05:31 -0500863
James Smart92d7f7b2007-06-17 19:56:38 -0500864 lpfc_issue_clear_la(phba, vport);
dea31012005-04-17 16:05:31 -0500865 return;
866}
867
868static void
James Smart2e0fef82007-06-17 19:56:36 -0500869lpfc_mbx_cmpl_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -0500870{
dea31012005-04-17 16:05:31 -0500871 MAILBOX_t *mb = &pmb->mb;
872 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) pmb->context1;
James Smart2e0fef82007-06-17 19:56:36 -0500873 struct lpfc_vport *vport = pmb->vport;
dea31012005-04-17 16:05:31 -0500874
875
876 /* Check for error */
877 if (mb->mbxStatus) {
878 /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */
879 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
James Smart92d7f7b2007-06-17 19:56:38 -0500880 "%d (%d):0319 READ_SPARAM mbxStatus error x%x "
dea31012005-04-17 16:05:31 -0500881 "hba state x%x>\n",
James Smart92d7f7b2007-06-17 19:56:38 -0500882 phba->brd_no, vport->vpi, mb->mbxStatus,
883 vport->port_state);
dea31012005-04-17 16:05:31 -0500884
885 lpfc_linkdown(phba);
dea31012005-04-17 16:05:31 -0500886 goto out;
887 }
888
James Smart2e0fef82007-06-17 19:56:36 -0500889 memcpy((uint8_t *) &vport->fc_sparam, (uint8_t *) mp->virt,
dea31012005-04-17 16:05:31 -0500890 sizeof (struct serv_parm));
James Smarta12e07b2006-12-02 13:35:30 -0500891 if (phba->cfg_soft_wwnn)
James Smart2e0fef82007-06-17 19:56:36 -0500892 u64_to_wwn(phba->cfg_soft_wwnn,
893 vport->fc_sparam.nodeName.u.wwn);
James Smartc3f28af2006-08-18 17:47:18 -0400894 if (phba->cfg_soft_wwpn)
James Smart2e0fef82007-06-17 19:56:36 -0500895 u64_to_wwn(phba->cfg_soft_wwpn,
896 vport->fc_sparam.portName.u.wwn);
James Smart92d7f7b2007-06-17 19:56:38 -0500897 memcpy(&vport->fc_nodename, &vport->fc_sparam.nodeName,
898 sizeof(vport->fc_nodename));
899 memcpy(&vport->fc_portname, &vport->fc_sparam.portName,
900 sizeof(vport->fc_portname));
901 if (vport->port_type == LPFC_PHYSICAL_PORT) {
902 memcpy(&phba->wwnn, &vport->fc_nodename, sizeof(phba->wwnn));
903 memcpy(&phba->wwpn, &vport->fc_portname, sizeof(phba->wwnn));
904 }
905
dea31012005-04-17 16:05:31 -0500906 lpfc_mbuf_free(phba, mp->virt, mp->phys);
907 kfree(mp);
James Smart2e0fef82007-06-17 19:56:36 -0500908 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500909 return;
910
911out:
912 pmb->context1 = NULL;
913 lpfc_mbuf_free(phba, mp->virt, mp->phys);
914 kfree(mp);
James Smart92d7f7b2007-06-17 19:56:38 -0500915 lpfc_issue_clear_la(phba, vport);
916 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500917 return;
918}
919
920static void
James Smart92d7f7b2007-06-17 19:56:38 -0500921lpfc_mbx_process_link_up(struct lpfc_hba *phba, READ_LA_VAR *la)
dea31012005-04-17 16:05:31 -0500922{
James Smart92d7f7b2007-06-17 19:56:38 -0500923 struct lpfc_vport *vport = phba->pport;
dea31012005-04-17 16:05:31 -0500924 LPFC_MBOXQ_t *sparam_mbox, *cfglink_mbox;
James Smart2e0fef82007-06-17 19:56:36 -0500925 int i;
James Smart14691152006-12-02 13:34:28 -0500926 struct lpfc_dmabuf *mp;
927 int rc;
928
dea31012005-04-17 16:05:31 -0500929 sparam_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
930 cfglink_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
931
James Smart92d7f7b2007-06-17 19:56:38 -0500932 spin_lock_irq(&phba->hbalock);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500933 switch (la->UlnkSpeed) {
James Smart92d7f7b2007-06-17 19:56:38 -0500934 case LA_1GHZ_LINK:
935 phba->fc_linkspeed = LA_1GHZ_LINK;
936 break;
937 case LA_2GHZ_LINK:
938 phba->fc_linkspeed = LA_2GHZ_LINK;
939 break;
940 case LA_4GHZ_LINK:
941 phba->fc_linkspeed = LA_4GHZ_LINK;
942 break;
943 case LA_8GHZ_LINK:
944 phba->fc_linkspeed = LA_8GHZ_LINK;
945 break;
946 default:
947 phba->fc_linkspeed = LA_UNKNW_LINK;
948 break;
dea31012005-04-17 16:05:31 -0500949 }
950
951 phba->fc_topology = la->topology;
James Smart92d7f7b2007-06-17 19:56:38 -0500952 phba->link_flag &= ~LS_NPIV_FAB_SUPPORTED;
dea31012005-04-17 16:05:31 -0500953
954 if (phba->fc_topology == TOPOLOGY_LOOP) {
James Smart92d7f7b2007-06-17 19:56:38 -0500955 phba->sli3_options &= ~LPFC_SLI3_NPIV_ENABLED;
dea31012005-04-17 16:05:31 -0500956
James Smart92d7f7b2007-06-17 19:56:38 -0500957 /* Get Loop Map information */
dea31012005-04-17 16:05:31 -0500958 if (la->il)
James Smart2e0fef82007-06-17 19:56:36 -0500959 vport->fc_flag |= FC_LBIT;
dea31012005-04-17 16:05:31 -0500960
James Smart2e0fef82007-06-17 19:56:36 -0500961 vport->fc_myDID = la->granted_AL_PA;
dea31012005-04-17 16:05:31 -0500962 i = la->un.lilpBde64.tus.f.bdeSize;
963
964 if (i == 0) {
965 phba->alpa_map[0] = 0;
966 } else {
967 if (phba->cfg_log_verbose & LOG_LINK_EVENT) {
968 int numalpa, j, k;
969 union {
970 uint8_t pamap[16];
971 struct {
972 uint32_t wd1;
973 uint32_t wd2;
974 uint32_t wd3;
975 uint32_t wd4;
976 } pa;
977 } un;
978 numalpa = phba->alpa_map[0];
979 j = 0;
980 while (j < numalpa) {
981 memset(un.pamap, 0, 16);
982 for (k = 1; j < numalpa; k++) {
983 un.pamap[k - 1] =
984 phba->alpa_map[j + 1];
985 j++;
986 if (k == 16)
987 break;
988 }
989 /* Link Up Event ALPA map */
990 lpfc_printf_log(phba,
James Smart92d7f7b2007-06-17 19:56:38 -0500991 KERN_WARNING,
992 LOG_LINK_EVENT,
993 "%d:1304 Link Up Event "
994 "ALPA map Data: x%x "
995 "x%x x%x x%x\n",
996 phba->brd_no,
997 un.pa.wd1, un.pa.wd2,
998 un.pa.wd3, un.pa.wd4);
dea31012005-04-17 16:05:31 -0500999 }
1000 }
1001 }
1002 } else {
James Smart92d7f7b2007-06-17 19:56:38 -05001003 if (!(phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)) {
James Smart858c9f62007-06-17 19:56:39 -05001004 if (phba->max_vpi && phba->cfg_npiv_enable &&
James Smart92d7f7b2007-06-17 19:56:38 -05001005 (phba->sli_rev == 3))
1006 phba->sli3_options |= LPFC_SLI3_NPIV_ENABLED;
1007 }
James Smart2e0fef82007-06-17 19:56:36 -05001008 vport->fc_myDID = phba->fc_pref_DID;
1009 vport->fc_flag |= FC_LBIT;
dea31012005-04-17 16:05:31 -05001010 }
James Smart92d7f7b2007-06-17 19:56:38 -05001011 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001012
1013 lpfc_linkup(phba);
1014 if (sparam_mbox) {
James Smart92d7f7b2007-06-17 19:56:38 -05001015 lpfc_read_sparam(phba, sparam_mbox, 0);
James Smart2e0fef82007-06-17 19:56:36 -05001016 sparam_mbox->vport = vport;
dea31012005-04-17 16:05:31 -05001017 sparam_mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam;
James Smart14691152006-12-02 13:34:28 -05001018 rc = lpfc_sli_issue_mbox(phba, sparam_mbox,
James Smart92d7f7b2007-06-17 19:56:38 -05001019 (MBX_NOWAIT | MBX_STOP_IOCB));
James Smart14691152006-12-02 13:34:28 -05001020 if (rc == MBX_NOT_FINISHED) {
1021 mp = (struct lpfc_dmabuf *) sparam_mbox->context1;
1022 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1023 kfree(mp);
1024 mempool_free(sparam_mbox, phba->mbox_mem_pool);
1025 if (cfglink_mbox)
1026 mempool_free(cfglink_mbox, phba->mbox_mem_pool);
James Smart92d7f7b2007-06-17 19:56:38 -05001027 goto out;
James Smart14691152006-12-02 13:34:28 -05001028 }
dea31012005-04-17 16:05:31 -05001029 }
1030
1031 if (cfglink_mbox) {
James Smart2e0fef82007-06-17 19:56:36 -05001032 vport->port_state = LPFC_LOCAL_CFG_LINK;
dea31012005-04-17 16:05:31 -05001033 lpfc_config_link(phba, cfglink_mbox);
James Smart2e0fef82007-06-17 19:56:36 -05001034 cfglink_mbox->vport = vport;
Jamie Wellnitz25594c62006-02-28 19:25:34 -05001035 cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
James Smart14691152006-12-02 13:34:28 -05001036 rc = lpfc_sli_issue_mbox(phba, cfglink_mbox,
James Smart92d7f7b2007-06-17 19:56:38 -05001037 (MBX_NOWAIT | MBX_STOP_IOCB));
1038 if (rc != MBX_NOT_FINISHED)
1039 return;
1040 mempool_free(cfglink_mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05001041 }
James Smart92d7f7b2007-06-17 19:56:38 -05001042out:
1043 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
1044 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1045 "%d (%d):0263 Discovery Mailbox error: state: 0x%x : %p %p\n",
1046 phba->brd_no, vport->vpi,
1047 vport->port_state, sparam_mbox, cfglink_mbox);
1048
1049 lpfc_issue_clear_la(phba, vport);
1050 return;
dea31012005-04-17 16:05:31 -05001051}
1052
1053static void
James Smart2e0fef82007-06-17 19:56:36 -05001054lpfc_mbx_issue_link_down(struct lpfc_hba *phba)
1055{
dea31012005-04-17 16:05:31 -05001056 uint32_t control;
1057 struct lpfc_sli *psli = &phba->sli;
1058
1059 lpfc_linkdown(phba);
1060
1061 /* turn on Link Attention interrupts - no CLEAR_LA needed */
James Smart2e0fef82007-06-17 19:56:36 -05001062 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001063 psli->sli_flag |= LPFC_PROCESS_LA;
1064 control = readl(phba->HCregaddr);
1065 control |= HC_LAINT_ENA;
1066 writel(control, phba->HCregaddr);
1067 readl(phba->HCregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -05001068 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001069}
1070
1071/*
1072 * This routine handles processing a READ_LA mailbox
1073 * command upon completion. It is setup in the LPFC_MBOXQ
1074 * as the completion routine when the command is
1075 * handed off to the SLI layer.
1076 */
1077void
James Smart2e0fef82007-06-17 19:56:36 -05001078lpfc_mbx_cmpl_read_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05001079{
James Smart2e0fef82007-06-17 19:56:36 -05001080 struct lpfc_vport *vport = pmb->vport;
1081 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001082 READ_LA_VAR *la;
1083 MAILBOX_t *mb = &pmb->mb;
1084 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
1085
1086 /* Check for error */
1087 if (mb->mbxStatus) {
James Smarted957682007-06-17 19:56:37 -05001088 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
dea31012005-04-17 16:05:31 -05001089 "%d:1307 READ_LA mbox error x%x state x%x\n",
James Smarted957682007-06-17 19:56:37 -05001090 phba->brd_no, mb->mbxStatus, vport->port_state);
dea31012005-04-17 16:05:31 -05001091 lpfc_mbx_issue_link_down(phba);
James Smart2e0fef82007-06-17 19:56:36 -05001092 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05001093 goto lpfc_mbx_cmpl_read_la_free_mbuf;
1094 }
1095
1096 la = (READ_LA_VAR *) & pmb->mb.un.varReadLA;
1097
1098 memcpy(&phba->alpa_map[0], mp->virt, 128);
1099
James Smart2e0fef82007-06-17 19:56:36 -05001100 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001101 if (la->pb)
James Smart2e0fef82007-06-17 19:56:36 -05001102 vport->fc_flag |= FC_BYPASSED_MODE;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001103 else
James Smart2e0fef82007-06-17 19:56:36 -05001104 vport->fc_flag &= ~FC_BYPASSED_MODE;
1105 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001106
dea31012005-04-17 16:05:31 -05001107 if (((phba->fc_eventTag + 1) < la->eventTag) ||
James Smart92d7f7b2007-06-17 19:56:38 -05001108 (phba->fc_eventTag == la->eventTag)) {
dea31012005-04-17 16:05:31 -05001109 phba->fc_stat.LinkMultiEvent++;
James Smart2e0fef82007-06-17 19:56:36 -05001110 if (la->attType == AT_LINK_UP)
dea31012005-04-17 16:05:31 -05001111 if (phba->fc_eventTag != 0)
1112 lpfc_linkdown(phba);
James Smart92d7f7b2007-06-17 19:56:38 -05001113 }
dea31012005-04-17 16:05:31 -05001114
1115 phba->fc_eventTag = la->eventTag;
1116
1117 if (la->attType == AT_LINK_UP) {
1118 phba->fc_stat.LinkUp++;
James Smart2e0fef82007-06-17 19:56:36 -05001119 if (phba->link_flag & LS_LOOPBACK_MODE) {
James Smart5b8bd0c2007-04-25 09:52:49 -04001120 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
1121 "%d:1306 Link Up Event in loop back mode "
1122 "x%x received Data: x%x x%x x%x x%x\n",
1123 phba->brd_no, la->eventTag, phba->fc_eventTag,
1124 la->granted_AL_PA, la->UlnkSpeed,
1125 phba->alpa_map[0]);
1126 } else {
1127 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
dea31012005-04-17 16:05:31 -05001128 "%d:1303 Link Up Event x%x received "
1129 "Data: x%x x%x x%x x%x\n",
1130 phba->brd_no, la->eventTag, phba->fc_eventTag,
1131 la->granted_AL_PA, la->UlnkSpeed,
1132 phba->alpa_map[0]);
James Smart5b8bd0c2007-04-25 09:52:49 -04001133 }
James Smart92d7f7b2007-06-17 19:56:38 -05001134 lpfc_mbx_process_link_up(phba, la);
dea31012005-04-17 16:05:31 -05001135 } else {
1136 phba->fc_stat.LinkDown++;
1137 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
1138 "%d:1305 Link Down Event x%x received "
1139 "Data: x%x x%x x%x\n",
1140 phba->brd_no, la->eventTag, phba->fc_eventTag,
James Smart2e0fef82007-06-17 19:56:36 -05001141 phba->pport->port_state, vport->fc_flag);
dea31012005-04-17 16:05:31 -05001142 lpfc_mbx_issue_link_down(phba);
1143 }
1144
1145lpfc_mbx_cmpl_read_la_free_mbuf:
1146 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1147 kfree(mp);
1148 mempool_free(pmb, phba->mbox_mem_pool);
1149 return;
1150}
1151
1152/*
1153 * This routine handles processing a REG_LOGIN mailbox
1154 * command upon completion. It is setup in the LPFC_MBOXQ
1155 * as the completion routine when the command is
1156 * handed off to the SLI layer.
1157 */
1158void
James Smart2e0fef82007-06-17 19:56:36 -05001159lpfc_mbx_cmpl_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05001160{
James Smart2e0fef82007-06-17 19:56:36 -05001161 struct lpfc_vport *vport = pmb->vport;
James Smart92d7f7b2007-06-17 19:56:38 -05001162 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
James Smart2e0fef82007-06-17 19:56:36 -05001163 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
dea31012005-04-17 16:05:31 -05001164
dea31012005-04-17 16:05:31 -05001165 pmb->context1 = NULL;
1166
1167 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -05001168 lpfc_disc_state_machine(vport, ndlp, pmb, NLP_EVT_CMPL_REG_LOGIN);
dea31012005-04-17 16:05:31 -05001169 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1170 kfree(mp);
James Smart2e0fef82007-06-17 19:56:36 -05001171 mempool_free(pmb, phba->mbox_mem_pool);
James Smart329f9bc2007-04-25 09:53:01 -04001172 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001173
1174 return;
1175}
1176
James Smart92d7f7b2007-06-17 19:56:38 -05001177static void
1178lpfc_mbx_cmpl_unreg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
1179{
1180 MAILBOX_t *mb = &pmb->mb;
1181 struct lpfc_vport *vport = pmb->vport;
1182 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1183
1184 switch (mb->mbxStatus) {
1185 case 0x0011:
1186 case 0x0020:
1187 case 0x9700:
1188 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1189 "%d (%d):0911 cmpl_unreg_vpi, "
1190 "mb status = 0x%x\n",
1191 phba->brd_no, vport->vpi, mb->mbxStatus);
1192 break;
James Smart92d7f7b2007-06-17 19:56:38 -05001193 }
1194 vport->unreg_vpi_cmpl = VPORT_OK;
1195 mempool_free(pmb, phba->mbox_mem_pool);
1196 /*
1197 * This shost reference might have been taken at the beginning of
1198 * lpfc_vport_delete()
1199 */
1200 if (vport->load_flag & FC_UNLOADING)
1201 scsi_host_put(shost);
1202}
1203
1204void
1205lpfc_mbx_unreg_vpi(struct lpfc_vport *vport)
1206{
1207 struct lpfc_hba *phba = vport->phba;
1208 LPFC_MBOXQ_t *mbox;
1209 int rc;
1210
1211 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1212 if (!mbox)
1213 return;
1214
1215 lpfc_unreg_vpi(phba, vport->vpi, mbox);
1216 mbox->vport = vport;
1217 mbox->mbox_cmpl = lpfc_mbx_cmpl_unreg_vpi;
1218 rc = lpfc_sli_issue_mbox(phba, mbox, (MBX_NOWAIT | MBX_STOP_IOCB));
1219 if (rc == MBX_NOT_FINISHED) {
1220 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_VPORT,
1221 "%d (%d):1800 Could not issue unreg_vpi\n",
1222 phba->brd_no, vport->vpi);
1223 mempool_free(mbox, phba->mbox_mem_pool);
1224 vport->unreg_vpi_cmpl = VPORT_ERROR;
1225 }
1226}
1227
1228static void
1229lpfc_mbx_cmpl_reg_vpi(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
1230{
1231 struct lpfc_vport *vport = pmb->vport;
1232 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1233 MAILBOX_t *mb = &pmb->mb;
1234
1235 switch (mb->mbxStatus) {
1236 case 0x0011:
1237 case 0x9601:
1238 case 0x9602:
1239 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1240 "%d (%d):0912 cmpl_reg_vpi, mb status = 0x%x\n",
1241 phba->brd_no, vport->vpi, mb->mbxStatus);
1242 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
1243 spin_lock_irq(shost->host_lock);
1244 vport->fc_flag &= ~(FC_FABRIC | FC_PUBLIC_LOOP);
1245 spin_unlock_irq(shost->host_lock);
1246 vport->fc_myDID = 0;
1247 goto out;
1248 }
James Smart92d7f7b2007-06-17 19:56:38 -05001249
1250 vport->num_disc_nodes = 0;
1251 /* go thru NPR list and issue ELS PLOGIs */
1252 if (vport->fc_npr_cnt)
1253 lpfc_els_disc_plogi(vport);
1254
1255 if (!vport->num_disc_nodes) {
1256 spin_lock_irq(shost->host_lock);
1257 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1258 spin_unlock_irq(shost->host_lock);
1259 lpfc_can_disctmo(vport);
1260 }
1261 vport->port_state = LPFC_VPORT_READY;
1262
1263out:
1264 mempool_free(pmb, phba->mbox_mem_pool);
1265 return;
1266}
1267
dea31012005-04-17 16:05:31 -05001268/*
1269 * This routine handles processing a Fabric REG_LOGIN mailbox
1270 * command upon completion. It is setup in the LPFC_MBOXQ
1271 * as the completion routine when the command is
1272 * handed off to the SLI layer.
1273 */
1274void
James Smart2e0fef82007-06-17 19:56:36 -05001275lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05001276{
James Smart92d7f7b2007-06-17 19:56:38 -05001277 struct lpfc_vport *vport = pmb->vport;
James Smart2e0fef82007-06-17 19:56:36 -05001278 MAILBOX_t *mb = &pmb->mb;
1279 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
James Smart92d7f7b2007-06-17 19:56:38 -05001280 struct lpfc_nodelist *ndlp;
James Smart549e55c2007-08-02 11:09:51 -04001281 struct lpfc_vport **vports;
1282 int i;
dea31012005-04-17 16:05:31 -05001283
James Smart549e55c2007-08-02 11:09:51 -04001284 ndlp = (struct lpfc_nodelist *) pmb->context2;
James Smart329f9bc2007-04-25 09:53:01 -04001285 pmb->context1 = NULL;
1286 pmb->context2 = NULL;
dea31012005-04-17 16:05:31 -05001287 if (mb->mbxStatus) {
1288 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1289 kfree(mp);
James Smart329f9bc2007-04-25 09:53:01 -04001290 mempool_free(pmb, phba->mbox_mem_pool);
1291 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001292
James Smart92d7f7b2007-06-17 19:56:38 -05001293 if (phba->fc_topology == TOPOLOGY_LOOP) {
1294 /* FLOGI failed, use loop map to make discovery list */
1295 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -05001296
James Smart92d7f7b2007-06-17 19:56:38 -05001297 /* Start discovery */
1298 lpfc_disc_start(vport);
1299 return;
1300 }
1301
1302 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
1303 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
1304 "%d (%d):0258 Register Fabric login error: 0x%x\n",
1305 phba->brd_no, vport->vpi, mb->mbxStatus);
1306
dea31012005-04-17 16:05:31 -05001307 return;
1308 }
1309
dea31012005-04-17 16:05:31 -05001310 ndlp->nlp_rpi = mb->un.varWords[0];
dea31012005-04-17 16:05:31 -05001311 ndlp->nlp_type |= NLP_FABRIC;
James Smart2e0fef82007-06-17 19:56:36 -05001312 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
dea31012005-04-17 16:05:31 -05001313
James Smart329f9bc2007-04-25 09:53:01 -04001314 lpfc_nlp_put(ndlp); /* Drop the reference from the mbox */
1315
James Smart2e0fef82007-06-17 19:56:36 -05001316 if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
James Smart549e55c2007-08-02 11:09:51 -04001317 vports = lpfc_create_vport_work_array(phba);
1318 if (vports != NULL)
1319 for(i = 0;
1320 i < LPFC_MAX_VPORTS && vports[i] != NULL;
1321 i++) {
1322 if (vports[i]->port_type == LPFC_PHYSICAL_PORT)
1323 continue;
1324 if (phba->link_flag & LS_NPIV_FAB_SUPPORTED)
1325 lpfc_initial_fdisc(vports[i]);
1326 else if (phba->sli3_options &
1327 LPFC_SLI3_NPIV_ENABLED) {
1328 lpfc_vport_set_state(vports[i],
1329 FC_VPORT_NO_FABRIC_SUPP);
1330 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
1331 "%d (%d):0259 No NPIV "
1332 "Fabric support\n",
1333 phba->brd_no,
1334 vports[i]->vpi);
1335 }
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001336 }
James Smart549e55c2007-08-02 11:09:51 -04001337 lpfc_destroy_vport_work_array(vports);
James Smart92d7f7b2007-06-17 19:56:38 -05001338 lpfc_do_scr_ns_plogi(phba, vport);
dea31012005-04-17 16:05:31 -05001339 }
1340
1341 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1342 kfree(mp);
James Smart329f9bc2007-04-25 09:53:01 -04001343 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05001344 return;
1345}
1346
1347/*
1348 * This routine handles processing a NameServer REG_LOGIN mailbox
1349 * command upon completion. It is setup in the LPFC_MBOXQ
1350 * as the completion routine when the command is
1351 * handed off to the SLI layer.
1352 */
1353void
James Smart2e0fef82007-06-17 19:56:36 -05001354lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05001355{
James Smart2e0fef82007-06-17 19:56:36 -05001356 MAILBOX_t *mb = &pmb->mb;
1357 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
1358 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
1359 struct lpfc_vport *vport = pmb->vport;
dea31012005-04-17 16:05:31 -05001360
1361 if (mb->mbxStatus) {
James Smart92d7f7b2007-06-17 19:56:38 -05001362out:
James Smart329f9bc2007-04-25 09:53:01 -04001363 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001364 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1365 kfree(mp);
James Smartde0c5b32007-04-25 09:52:27 -04001366 mempool_free(pmb, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05001367 lpfc_drop_node(vport, ndlp);
dea31012005-04-17 16:05:31 -05001368
James Smart92d7f7b2007-06-17 19:56:38 -05001369 if (phba->fc_topology == TOPOLOGY_LOOP) {
1370 /*
1371 * RegLogin failed, use loop map to make discovery
1372 * list
1373 */
1374 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -05001375
James Smart92d7f7b2007-06-17 19:56:38 -05001376 /* Start discovery */
1377 lpfc_disc_start(vport);
1378 return;
1379 }
1380 lpfc_vport_set_state(vport, FC_VPORT_FAILED);
1381 lpfc_printf_log(phba, KERN_ERR, LOG_ELS,
1382 "%d (%d):0260 Register NameServer error: 0x%x\n",
1383 phba->brd_no, vport->vpi, mb->mbxStatus);
dea31012005-04-17 16:05:31 -05001384 return;
1385 }
1386
1387 pmb->context1 = NULL;
1388
dea31012005-04-17 16:05:31 -05001389 ndlp->nlp_rpi = mb->un.varWords[0];
dea31012005-04-17 16:05:31 -05001390 ndlp->nlp_type |= NLP_FABRIC;
James Smart2e0fef82007-06-17 19:56:36 -05001391 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
dea31012005-04-17 16:05:31 -05001392
James Smart2e0fef82007-06-17 19:56:36 -05001393 if (vport->port_state < LPFC_VPORT_READY) {
1394 /* Link up discovery requires Fabric registration. */
James Smart92d7f7b2007-06-17 19:56:38 -05001395 lpfc_ns_cmd(vport, SLI_CTNS_RFF_ID, 0, 0); /* Do this first! */
1396 lpfc_ns_cmd(vport, SLI_CTNS_RNN_ID, 0, 0);
1397 lpfc_ns_cmd(vport, SLI_CTNS_RSNN_NN, 0, 0);
1398 lpfc_ns_cmd(vport, SLI_CTNS_RSPN_ID, 0, 0);
1399 lpfc_ns_cmd(vport, SLI_CTNS_RFT_ID, 0, 0);
1400
1401 /* Issue SCR just before NameServer GID_FT Query */
1402 lpfc_issue_els_scr(vport, SCR_DID, 0);
dea31012005-04-17 16:05:31 -05001403 }
1404
James Smart2e0fef82007-06-17 19:56:36 -05001405 vport->fc_ns_retry = 0;
dea31012005-04-17 16:05:31 -05001406 /* Good status, issue CT Request to NameServer */
James Smart92d7f7b2007-06-17 19:56:38 -05001407 if (lpfc_ns_cmd(vport, SLI_CTNS_GID_FT, 0, 0)) {
dea31012005-04-17 16:05:31 -05001408 /* Cannot issue NameServer Query, so finish up discovery */
James Smart92d7f7b2007-06-17 19:56:38 -05001409 goto out;
dea31012005-04-17 16:05:31 -05001410 }
1411
James Smart329f9bc2007-04-25 09:53:01 -04001412 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001413 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1414 kfree(mp);
James Smart2e0fef82007-06-17 19:56:36 -05001415 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05001416
1417 return;
1418}
1419
1420static void
James Smart2e0fef82007-06-17 19:56:36 -05001421lpfc_register_remote_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05001422{
James Smart2e0fef82007-06-17 19:56:36 -05001423 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1424 struct fc_rport *rport;
dea31012005-04-17 16:05:31 -05001425 struct lpfc_rport_data *rdata;
1426 struct fc_rport_identifiers rport_ids;
James Smart2e0fef82007-06-17 19:56:36 -05001427 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001428
1429 /* Remote port has reappeared. Re-register w/ FC transport */
Andrew Morton68ce1eb2005-09-21 09:46:54 -07001430 rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
1431 rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
dea31012005-04-17 16:05:31 -05001432 rport_ids.port_id = ndlp->nlp_DID;
1433 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
dea31012005-04-17 16:05:31 -05001434
James Smart329f9bc2007-04-25 09:53:01 -04001435 /*
1436 * We leave our node pointer in rport->dd_data when we unregister a
1437 * FCP target port. But fc_remote_port_add zeros the space to which
1438 * rport->dd_data points. So, if we're reusing a previously
1439 * registered port, drop the reference that we took the last time we
1440 * registered the port.
1441 */
1442 if (ndlp->rport && ndlp->rport->dd_data &&
James Smart92d7f7b2007-06-17 19:56:38 -05001443 ((struct lpfc_rport_data *) ndlp->rport->dd_data)->pnode == ndlp) {
James Smart329f9bc2007-04-25 09:53:01 -04001444 lpfc_nlp_put(ndlp);
1445 }
James Smart858c9f62007-06-17 19:56:39 -05001446
1447 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_RPORT,
1448 "rport add: did:x%x flg:x%x type x%x",
1449 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
1450
James Smart2e0fef82007-06-17 19:56:36 -05001451 ndlp->rport = rport = fc_remote_port_add(shost, 0, &rport_ids);
James Smart329f9bc2007-04-25 09:53:01 -04001452 if (!rport || !get_device(&rport->dev)) {
dea31012005-04-17 16:05:31 -05001453 dev_printk(KERN_WARNING, &phba->pcidev->dev,
1454 "Warning: fc_remote_port_add failed\n");
1455 return;
1456 }
1457
1458 /* initialize static port data */
1459 rport->maxframe_size = ndlp->nlp_maxframe;
1460 rport->supported_classes = ndlp->nlp_class_sup;
dea31012005-04-17 16:05:31 -05001461 rdata = rport->dd_data;
James Smart329f9bc2007-04-25 09:53:01 -04001462 rdata->pnode = lpfc_nlp_get(ndlp);
James.Smart@Emulex.Com23dc04f2005-11-28 11:41:44 -05001463
1464 if (ndlp->nlp_type & NLP_FCP_TARGET)
1465 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
1466 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
1467 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
1468
1469
1470 if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN)
1471 fc_remote_port_rolechg(rport, rport_ids.roles);
1472
James Smart071fbd3d2006-04-15 11:53:20 -04001473 if ((rport->scsi_target_id != -1) &&
James Smart92d7f7b2007-06-17 19:56:38 -05001474 (rport->scsi_target_id < LPFC_MAX_TARGET)) {
James Smart071fbd3d2006-04-15 11:53:20 -04001475 ndlp->nlp_sid = rport->scsi_target_id;
1476 }
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001477 return;
1478}
1479
1480static void
James Smart2e0fef82007-06-17 19:56:36 -05001481lpfc_unregister_remote_port(struct lpfc_nodelist *ndlp)
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001482{
1483 struct fc_rport *rport = ndlp->rport;
James Smartc01f3202006-08-18 17:47:08 -04001484
James Smart858c9f62007-06-17 19:56:39 -05001485 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_RPORT,
1486 "rport delete: did:x%x flg:x%x type x%x",
1487 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
1488
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001489 fc_remote_port_delete(rport);
dea31012005-04-17 16:05:31 -05001490
1491 return;
1492}
1493
James Smartde0c5b32007-04-25 09:52:27 -04001494static void
James Smart2e0fef82007-06-17 19:56:36 -05001495lpfc_nlp_counters(struct lpfc_vport *vport, int state, int count)
James Smartde0c5b32007-04-25 09:52:27 -04001496{
James Smart2e0fef82007-06-17 19:56:36 -05001497 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1498
1499 spin_lock_irq(shost->host_lock);
James Smartde0c5b32007-04-25 09:52:27 -04001500 switch (state) {
1501 case NLP_STE_UNUSED_NODE:
James Smart2e0fef82007-06-17 19:56:36 -05001502 vport->fc_unused_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04001503 break;
1504 case NLP_STE_PLOGI_ISSUE:
James Smart2e0fef82007-06-17 19:56:36 -05001505 vport->fc_plogi_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04001506 break;
1507 case NLP_STE_ADISC_ISSUE:
James Smart2e0fef82007-06-17 19:56:36 -05001508 vport->fc_adisc_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04001509 break;
1510 case NLP_STE_REG_LOGIN_ISSUE:
James Smart2e0fef82007-06-17 19:56:36 -05001511 vport->fc_reglogin_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04001512 break;
1513 case NLP_STE_PRLI_ISSUE:
James Smart2e0fef82007-06-17 19:56:36 -05001514 vport->fc_prli_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04001515 break;
1516 case NLP_STE_UNMAPPED_NODE:
James Smart2e0fef82007-06-17 19:56:36 -05001517 vport->fc_unmap_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04001518 break;
1519 case NLP_STE_MAPPED_NODE:
James Smart2e0fef82007-06-17 19:56:36 -05001520 vport->fc_map_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04001521 break;
1522 case NLP_STE_NPR_NODE:
James Smart2e0fef82007-06-17 19:56:36 -05001523 vport->fc_npr_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04001524 break;
1525 }
James Smart2e0fef82007-06-17 19:56:36 -05001526 spin_unlock_irq(shost->host_lock);
James Smartde0c5b32007-04-25 09:52:27 -04001527}
Jamie Wellnitz66a9ed62006-02-28 22:33:10 -05001528
James Smartde0c5b32007-04-25 09:52:27 -04001529static void
James Smart2e0fef82007-06-17 19:56:36 -05001530lpfc_nlp_state_cleanup(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04001531 int old_state, int new_state)
1532{
James Smart2e0fef82007-06-17 19:56:36 -05001533 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1534
James Smartde0c5b32007-04-25 09:52:27 -04001535 if (new_state == NLP_STE_UNMAPPED_NODE) {
1536 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
1537 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
1538 ndlp->nlp_type |= NLP_FC_NODE;
1539 }
1540 if (new_state == NLP_STE_MAPPED_NODE)
1541 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
1542 if (new_state == NLP_STE_NPR_NODE)
1543 ndlp->nlp_flag &= ~NLP_RCV_PLOGI;
dea31012005-04-17 16:05:31 -05001544
James Smartde0c5b32007-04-25 09:52:27 -04001545 /* Transport interface */
1546 if (ndlp->rport && (old_state == NLP_STE_MAPPED_NODE ||
1547 old_state == NLP_STE_UNMAPPED_NODE)) {
James Smart2e0fef82007-06-17 19:56:36 -05001548 vport->phba->nport_event_cnt++;
1549 lpfc_unregister_remote_port(ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04001550 }
dea31012005-04-17 16:05:31 -05001551
James Smartde0c5b32007-04-25 09:52:27 -04001552 if (new_state == NLP_STE_MAPPED_NODE ||
1553 new_state == NLP_STE_UNMAPPED_NODE) {
James Smart2e0fef82007-06-17 19:56:36 -05001554 vport->phba->nport_event_cnt++;
James Smart858c9f62007-06-17 19:56:39 -05001555 /*
1556 * Tell the fc transport about the port, if we haven't
1557 * already. If we have, and it's a scsi entity, be
1558 * sure to unblock any attached scsi devices
1559 */
1560 lpfc_register_remote_port(vport, ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04001561 }
James Smart858c9f62007-06-17 19:56:39 -05001562 /*
1563 * if we added to Mapped list, but the remote port
1564 * registration failed or assigned a target id outside
1565 * our presentable range - move the node to the
1566 * Unmapped List
1567 */
James Smartde0c5b32007-04-25 09:52:27 -04001568 if (new_state == NLP_STE_MAPPED_NODE &&
1569 (!ndlp->rport ||
1570 ndlp->rport->scsi_target_id == -1 ||
1571 ndlp->rport->scsi_target_id >= LPFC_MAX_TARGET)) {
James Smart2e0fef82007-06-17 19:56:36 -05001572 spin_lock_irq(shost->host_lock);
James Smartde0c5b32007-04-25 09:52:27 -04001573 ndlp->nlp_flag |= NLP_TGT_NO_SCSIID;
James Smart2e0fef82007-06-17 19:56:36 -05001574 spin_unlock_irq(shost->host_lock);
1575 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
dea31012005-04-17 16:05:31 -05001576 }
James Smartde0c5b32007-04-25 09:52:27 -04001577}
1578
James Smart685f0bf2007-04-25 09:53:08 -04001579static char *
1580lpfc_nlp_state_name(char *buffer, size_t size, int state)
1581{
1582 static char *states[] = {
1583 [NLP_STE_UNUSED_NODE] = "UNUSED",
1584 [NLP_STE_PLOGI_ISSUE] = "PLOGI",
1585 [NLP_STE_ADISC_ISSUE] = "ADISC",
1586 [NLP_STE_REG_LOGIN_ISSUE] = "REGLOGIN",
1587 [NLP_STE_PRLI_ISSUE] = "PRLI",
1588 [NLP_STE_UNMAPPED_NODE] = "UNMAPPED",
1589 [NLP_STE_MAPPED_NODE] = "MAPPED",
1590 [NLP_STE_NPR_NODE] = "NPR",
1591 };
1592
1593 if (state < ARRAY_SIZE(states) && states[state])
1594 strlcpy(buffer, states[state], size);
1595 else
1596 snprintf(buffer, size, "unknown (%d)", state);
1597 return buffer;
1598}
1599
James Smartde0c5b32007-04-25 09:52:27 -04001600void
James Smart2e0fef82007-06-17 19:56:36 -05001601lpfc_nlp_set_state(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1602 int state)
James Smartde0c5b32007-04-25 09:52:27 -04001603{
James Smart2e0fef82007-06-17 19:56:36 -05001604 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smartde0c5b32007-04-25 09:52:27 -04001605 int old_state = ndlp->nlp_state;
James Smart685f0bf2007-04-25 09:53:08 -04001606 char name1[16], name2[16];
James Smartde0c5b32007-04-25 09:52:27 -04001607
James Smart2e0fef82007-06-17 19:56:36 -05001608 lpfc_printf_log(vport->phba, KERN_INFO, LOG_NODE,
James Smart858c9f62007-06-17 19:56:39 -05001609 "%d (%d):0904 NPort state transition x%06x, %s -> %s\n",
1610 vport->phba->brd_no, vport->vpi,
James Smart685f0bf2007-04-25 09:53:08 -04001611 ndlp->nlp_DID,
1612 lpfc_nlp_state_name(name1, sizeof(name1), old_state),
1613 lpfc_nlp_state_name(name2, sizeof(name2), state));
James Smart858c9f62007-06-17 19:56:39 -05001614
1615 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
1616 "node statechg did:x%x old:%d ste:%d",
1617 ndlp->nlp_DID, old_state, state);
1618
James Smartde0c5b32007-04-25 09:52:27 -04001619 if (old_state == NLP_STE_NPR_NODE &&
1620 (ndlp->nlp_flag & NLP_DELAY_TMO) != 0 &&
1621 state != NLP_STE_NPR_NODE)
James Smart2e0fef82007-06-17 19:56:36 -05001622 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04001623 if (old_state == NLP_STE_UNMAPPED_NODE) {
1624 ndlp->nlp_flag &= ~NLP_TGT_NO_SCSIID;
1625 ndlp->nlp_type &= ~NLP_FC_NODE;
1626 }
1627
James Smart685f0bf2007-04-25 09:53:08 -04001628 if (list_empty(&ndlp->nlp_listp)) {
James Smart2e0fef82007-06-17 19:56:36 -05001629 spin_lock_irq(shost->host_lock);
1630 list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
1631 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04001632 } else if (old_state)
James Smart2e0fef82007-06-17 19:56:36 -05001633 lpfc_nlp_counters(vport, old_state, -1);
James Smartde0c5b32007-04-25 09:52:27 -04001634
1635 ndlp->nlp_state = state;
James Smart2e0fef82007-06-17 19:56:36 -05001636 lpfc_nlp_counters(vport, state, 1);
1637 lpfc_nlp_state_cleanup(vport, ndlp, old_state, state);
James Smartde0c5b32007-04-25 09:52:27 -04001638}
1639
1640void
James Smart2e0fef82007-06-17 19:56:36 -05001641lpfc_dequeue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
James Smartde0c5b32007-04-25 09:52:27 -04001642{
James Smart2e0fef82007-06-17 19:56:36 -05001643 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1644
James Smartde0c5b32007-04-25 09:52:27 -04001645 if ((ndlp->nlp_flag & NLP_DELAY_TMO) != 0)
James Smart2e0fef82007-06-17 19:56:36 -05001646 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04001647 if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
James Smart2e0fef82007-06-17 19:56:36 -05001648 lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
1649 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04001650 list_del_init(&ndlp->nlp_listp);
James Smart2e0fef82007-06-17 19:56:36 -05001651 spin_unlock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05001652 lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state,
1653 NLP_STE_UNUSED_NODE);
James Smartde0c5b32007-04-25 09:52:27 -04001654}
1655
1656void
James Smart2e0fef82007-06-17 19:56:36 -05001657lpfc_drop_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
James Smartde0c5b32007-04-25 09:52:27 -04001658{
James Smart2e0fef82007-06-17 19:56:36 -05001659 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1660
James Smartde0c5b32007-04-25 09:52:27 -04001661 if ((ndlp->nlp_flag & NLP_DELAY_TMO) != 0)
James Smart2e0fef82007-06-17 19:56:36 -05001662 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04001663 if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
James Smart2e0fef82007-06-17 19:56:36 -05001664 lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
1665 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04001666 list_del_init(&ndlp->nlp_listp);
James Smart858c9f62007-06-17 19:56:39 -05001667 ndlp->nlp_flag &= ~NLP_TARGET_REMOVE;
James Smart2e0fef82007-06-17 19:56:36 -05001668 spin_unlock_irq(shost->host_lock);
James Smart329f9bc2007-04-25 09:53:01 -04001669 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001670}
1671
1672/*
1673 * Start / ReStart rescue timer for Discovery / RSCN handling
1674 */
1675void
James Smart2e0fef82007-06-17 19:56:36 -05001676lpfc_set_disctmo(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001677{
James Smart2e0fef82007-06-17 19:56:36 -05001678 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1679 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001680 uint32_t tmo;
1681
James Smart2e0fef82007-06-17 19:56:36 -05001682 if (vport->port_state == LPFC_LOCAL_CFG_LINK) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001683 /* For FAN, timeout should be greater then edtov */
1684 tmo = (((phba->fc_edtov + 999) / 1000) + 1);
1685 } else {
1686 /* Normal discovery timeout should be > then ELS/CT timeout
1687 * FC spec states we need 3 * ratov for CT requests
1688 */
1689 tmo = ((phba->fc_ratov * 3) + 3);
1690 }
dea31012005-04-17 16:05:31 -05001691
James Smart858c9f62007-06-17 19:56:39 -05001692
1693 if (!timer_pending(&vport->fc_disctmo)) {
1694 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1695 "set disc timer: tmo:x%x state:x%x flg:x%x",
1696 tmo, vport->port_state, vport->fc_flag);
1697 }
1698
James Smart2e0fef82007-06-17 19:56:36 -05001699 mod_timer(&vport->fc_disctmo, jiffies + HZ * tmo);
1700 spin_lock_irq(shost->host_lock);
1701 vport->fc_flag |= FC_DISC_TMO;
1702 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001703
1704 /* Start Discovery Timer state <hba_state> */
1705 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smart92d7f7b2007-06-17 19:56:38 -05001706 "%d (%d):0247 Start Discovery Timer state x%x "
dea31012005-04-17 16:05:31 -05001707 "Data: x%x x%lx x%x x%x\n",
James Smart92d7f7b2007-06-17 19:56:38 -05001708 phba->brd_no, vport->vpi, vport->port_state, tmo,
James Smart2e0fef82007-06-17 19:56:36 -05001709 (unsigned long)&vport->fc_disctmo, vport->fc_plogi_cnt,
1710 vport->fc_adisc_cnt);
dea31012005-04-17 16:05:31 -05001711
1712 return;
1713}
1714
1715/*
1716 * Cancel rescue timer for Discovery / RSCN handling
1717 */
1718int
James Smart2e0fef82007-06-17 19:56:36 -05001719lpfc_can_disctmo(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001720{
James Smart2e0fef82007-06-17 19:56:36 -05001721 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1722 struct lpfc_hba *phba = vport->phba;
1723 unsigned long iflags;
1724
James Smart858c9f62007-06-17 19:56:39 -05001725 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
1726 "can disc timer: state:x%x rtry:x%x flg:x%x",
1727 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
1728
dea31012005-04-17 16:05:31 -05001729 /* Turn off discovery timer if its running */
James Smart2e0fef82007-06-17 19:56:36 -05001730 if (vport->fc_flag & FC_DISC_TMO) {
1731 spin_lock_irqsave(shost->host_lock, iflags);
1732 vport->fc_flag &= ~FC_DISC_TMO;
1733 spin_unlock_irqrestore(shost->host_lock, iflags);
1734 del_timer_sync(&vport->fc_disctmo);
1735 spin_lock_irqsave(&vport->work_port_lock, iflags);
1736 vport->work_port_events &= ~WORKER_DISC_TMO;
1737 spin_unlock_irqrestore(&vport->work_port_lock, iflags);
dea31012005-04-17 16:05:31 -05001738 }
1739
1740 /* Cancel Discovery Timer state <hba_state> */
1741 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smart92d7f7b2007-06-17 19:56:38 -05001742 "%d (%d):0248 Cancel Discovery Timer state x%x "
dea31012005-04-17 16:05:31 -05001743 "Data: x%x x%x x%x\n",
James Smart92d7f7b2007-06-17 19:56:38 -05001744 phba->brd_no, vport->vpi, vport->port_state,
1745 vport->fc_flag, vport->fc_plogi_cnt,
1746 vport->fc_adisc_cnt);
dea31012005-04-17 16:05:31 -05001747
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001748 return 0;
dea31012005-04-17 16:05:31 -05001749}
1750
1751/*
1752 * Check specified ring for outstanding IOCB on the SLI queue
1753 * Return true if iocb matches the specified nport
1754 */
1755int
James Smart2e0fef82007-06-17 19:56:36 -05001756lpfc_check_sli_ndlp(struct lpfc_hba *phba,
1757 struct lpfc_sli_ring *pring,
1758 struct lpfc_iocbq *iocb,
1759 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05001760{
James Smart2e0fef82007-06-17 19:56:36 -05001761 struct lpfc_sli *psli = &phba->sli;
1762 IOCB_t *icmd = &iocb->iocb;
James Smart92d7f7b2007-06-17 19:56:38 -05001763 struct lpfc_vport *vport = ndlp->vport;
1764
1765 if (iocb->vport != vport)
1766 return 0;
1767
dea31012005-04-17 16:05:31 -05001768 if (pring->ringno == LPFC_ELS_RING) {
1769 switch (icmd->ulpCommand) {
1770 case CMD_GEN_REQUEST64_CR:
1771 if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001772 return 1;
dea31012005-04-17 16:05:31 -05001773 case CMD_ELS_REQUEST64_CR:
James Smart10d4e952006-04-15 11:53:15 -04001774 if (icmd->un.elsreq64.remoteID == ndlp->nlp_DID)
1775 return 1;
dea31012005-04-17 16:05:31 -05001776 case CMD_XMIT_ELS_RSP64_CX:
1777 if (iocb->context1 == (uint8_t *) ndlp)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001778 return 1;
dea31012005-04-17 16:05:31 -05001779 }
James Smarta4bc3372006-12-02 13:34:16 -05001780 } else if (pring->ringno == psli->extra_ring) {
dea31012005-04-17 16:05:31 -05001781
1782 } else if (pring->ringno == psli->fcp_ring) {
1783 /* Skip match check if waiting to relogin to FCP target */
1784 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
James Smart92d7f7b2007-06-17 19:56:38 -05001785 (ndlp->nlp_flag & NLP_DELAY_TMO)) {
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001786 return 0;
dea31012005-04-17 16:05:31 -05001787 }
1788 if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) {
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001789 return 1;
dea31012005-04-17 16:05:31 -05001790 }
1791 } else if (pring->ringno == psli->next_ring) {
1792
1793 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001794 return 0;
dea31012005-04-17 16:05:31 -05001795}
1796
1797/*
1798 * Free resources / clean up outstanding I/Os
1799 * associated with nlp_rpi in the LPFC_NODELIST entry.
1800 */
1801static int
James Smart2e0fef82007-06-17 19:56:36 -05001802lpfc_no_rpi(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05001803{
James Smart2534ba72007-04-25 09:52:20 -04001804 LIST_HEAD(completions);
dea31012005-04-17 16:05:31 -05001805 struct lpfc_sli *psli;
1806 struct lpfc_sli_ring *pring;
1807 struct lpfc_iocbq *iocb, *next_iocb;
1808 IOCB_t *icmd;
1809 uint32_t rpi, i;
1810
James Smart92d7f7b2007-06-17 19:56:38 -05001811 lpfc_fabric_abort_nport(ndlp);
1812
dea31012005-04-17 16:05:31 -05001813 /*
1814 * Everything that matches on txcmplq will be returned
1815 * by firmware with a no rpi error.
1816 */
1817 psli = &phba->sli;
1818 rpi = ndlp->nlp_rpi;
1819 if (rpi) {
1820 /* Now process each ring */
1821 for (i = 0; i < psli->num_rings; i++) {
1822 pring = &psli->ring[i];
1823
James Smart2e0fef82007-06-17 19:56:36 -05001824 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001825 list_for_each_entry_safe(iocb, next_iocb, &pring->txq,
James Smart2e0fef82007-06-17 19:56:36 -05001826 list) {
dea31012005-04-17 16:05:31 -05001827 /*
1828 * Check to see if iocb matches the nport we are
1829 * looking for
1830 */
James Smart92d7f7b2007-06-17 19:56:38 -05001831 if ((lpfc_check_sli_ndlp(phba, pring, iocb,
1832 ndlp))) {
dea31012005-04-17 16:05:31 -05001833 /* It matches, so deque and call compl
1834 with an error */
James Smart2534ba72007-04-25 09:52:20 -04001835 list_move_tail(&iocb->list,
1836 &completions);
dea31012005-04-17 16:05:31 -05001837 pring->txq_cnt--;
dea31012005-04-17 16:05:31 -05001838 }
1839 }
James Smart2e0fef82007-06-17 19:56:36 -05001840 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001841 }
1842 }
James Smart2534ba72007-04-25 09:52:20 -04001843
1844 while (!list_empty(&completions)) {
1845 iocb = list_get_first(&completions, struct lpfc_iocbq, list);
James Smart92d7f7b2007-06-17 19:56:38 -05001846 list_del_init(&iocb->list);
James Smart2534ba72007-04-25 09:52:20 -04001847
James Smart2e0fef82007-06-17 19:56:36 -05001848 if (!iocb->iocb_cmpl)
1849 lpfc_sli_release_iocbq(phba, iocb);
1850 else {
James Smart2534ba72007-04-25 09:52:20 -04001851 icmd = &iocb->iocb;
1852 icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
1853 icmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
James Smart2e0fef82007-06-17 19:56:36 -05001854 (iocb->iocb_cmpl)(phba, iocb, iocb);
1855 }
James Smart2534ba72007-04-25 09:52:20 -04001856 }
1857
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001858 return 0;
dea31012005-04-17 16:05:31 -05001859}
1860
1861/*
1862 * Free rpi associated with LPFC_NODELIST entry.
1863 * This routine is called from lpfc_freenode(), when we are removing
1864 * a LPFC_NODELIST entry. It is also called if the driver initiates a
1865 * LOGO that completes successfully, and we are waiting to PLOGI back
1866 * to the remote NPort. In addition, it is called after we receive
1867 * and unsolicated ELS cmd, send back a rsp, the rsp completes and
1868 * we are waiting to PLOGI back to the remote NPort.
1869 */
1870int
James Smart2e0fef82007-06-17 19:56:36 -05001871lpfc_unreg_rpi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05001872{
James Smart2e0fef82007-06-17 19:56:36 -05001873 struct lpfc_hba *phba = vport->phba;
1874 LPFC_MBOXQ_t *mbox;
dea31012005-04-17 16:05:31 -05001875 int rc;
1876
1877 if (ndlp->nlp_rpi) {
James Smart2e0fef82007-06-17 19:56:36 -05001878 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1879 if (mbox) {
James Smart92d7f7b2007-06-17 19:56:38 -05001880 lpfc_unreg_login(phba, vport->vpi, ndlp->nlp_rpi, mbox);
James Smarted957682007-06-17 19:56:37 -05001881 mbox->vport = vport;
James Smart92d7f7b2007-06-17 19:56:38 -05001882 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1883 rc = lpfc_sli_issue_mbox(phba, mbox,
1884 (MBX_NOWAIT | MBX_STOP_IOCB));
dea31012005-04-17 16:05:31 -05001885 if (rc == MBX_NOT_FINISHED)
James Smart2e0fef82007-06-17 19:56:36 -05001886 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05001887 }
dea31012005-04-17 16:05:31 -05001888 lpfc_no_rpi(phba, ndlp);
1889 ndlp->nlp_rpi = 0;
1890 return 1;
1891 }
1892 return 0;
1893}
1894
James Smart92d7f7b2007-06-17 19:56:38 -05001895void
1896lpfc_unreg_all_rpis(struct lpfc_vport *vport)
1897{
1898 struct lpfc_hba *phba = vport->phba;
1899 LPFC_MBOXQ_t *mbox;
1900 int rc;
1901
1902 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1903 if (mbox) {
1904 lpfc_unreg_login(phba, vport->vpi, 0xffff, mbox);
1905 mbox->vport = vport;
1906 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1907 rc = lpfc_sli_issue_mbox(phba, mbox,
1908 (MBX_NOWAIT | MBX_STOP_IOCB));
1909 if (rc == MBX_NOT_FINISHED) {
1910 mempool_free(mbox, phba->mbox_mem_pool);
1911 }
1912 }
1913}
1914
1915void
1916lpfc_unreg_default_rpis(struct lpfc_vport *vport)
1917{
1918 struct lpfc_hba *phba = vport->phba;
1919 LPFC_MBOXQ_t *mbox;
1920 int rc;
1921
1922 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1923 if (mbox) {
1924 lpfc_unreg_did(phba, vport->vpi, 0xffffffff, mbox);
1925 mbox->vport = vport;
1926 mbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1927 rc = lpfc_sli_issue_mbox(phba, mbox,
1928 (MBX_NOWAIT | MBX_STOP_IOCB));
1929 if (rc == MBX_NOT_FINISHED) {
1930 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX | LOG_VPORT,
1931 "%d (%d):1815 Could not issue "
1932 "unreg_did (default rpis)\n",
1933 phba->brd_no, vport->vpi);
1934 mempool_free(mbox, phba->mbox_mem_pool);
1935 }
1936 }
1937}
1938
dea31012005-04-17 16:05:31 -05001939/*
1940 * Free resources associated with LPFC_NODELIST entry
1941 * so it can be freed.
1942 */
1943static int
James Smart2e0fef82007-06-17 19:56:36 -05001944lpfc_cleanup_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05001945{
James Smart2e0fef82007-06-17 19:56:36 -05001946 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1947 struct lpfc_hba *phba = vport->phba;
1948 LPFC_MBOXQ_t *mb, *nextmb;
dea31012005-04-17 16:05:31 -05001949 struct lpfc_dmabuf *mp;
dea31012005-04-17 16:05:31 -05001950
1951 /* Cleanup node for NPort <nlp_DID> */
1952 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
James Smart92d7f7b2007-06-17 19:56:38 -05001953 "%d (%d):0900 Cleanup node for NPort x%x "
dea31012005-04-17 16:05:31 -05001954 "Data: x%x x%x x%x\n",
James Smart92d7f7b2007-06-17 19:56:38 -05001955 phba->brd_no, vport->vpi, ndlp->nlp_DID, ndlp->nlp_flag,
dea31012005-04-17 16:05:31 -05001956 ndlp->nlp_state, ndlp->nlp_rpi);
1957
James Smart2e0fef82007-06-17 19:56:36 -05001958 lpfc_dequeue_node(vport, ndlp);
dea31012005-04-17 16:05:31 -05001959
dea31012005-04-17 16:05:31 -05001960 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
1961 if ((mb = phba->sli.mbox_active)) {
1962 if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
1963 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1964 mb->context2 = NULL;
1965 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1966 }
1967 }
James Smart33ccf8d2006-08-17 11:57:58 -04001968
James Smart2e0fef82007-06-17 19:56:36 -05001969 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001970 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
1971 if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
James Smart92d7f7b2007-06-17 19:56:38 -05001972 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
dea31012005-04-17 16:05:31 -05001973 mp = (struct lpfc_dmabuf *) (mb->context1);
1974 if (mp) {
James Smart2e0fef82007-06-17 19:56:36 -05001975 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
dea31012005-04-17 16:05:31 -05001976 kfree(mp);
1977 }
1978 list_del(&mb->list);
1979 mempool_free(mb, phba->mbox_mem_pool);
James Smart329f9bc2007-04-25 09:53:01 -04001980 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001981 }
1982 }
James Smart2e0fef82007-06-17 19:56:36 -05001983 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001984
James Smart07951072007-04-25 09:51:38 -04001985 lpfc_els_abort(phba,ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05001986 spin_lock_irq(shost->host_lock);
James Smartc01f3202006-08-18 17:47:08 -04001987 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001988 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001989
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001990 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05001991 del_timer_sync(&ndlp->nlp_delayfunc);
1992
dea31012005-04-17 16:05:31 -05001993 if (!list_empty(&ndlp->els_retry_evt.evt_listp))
1994 list_del_init(&ndlp->els_retry_evt.evt_listp);
James Smart92d7f7b2007-06-17 19:56:38 -05001995 if (!list_empty(&ndlp->dev_loss_evt.evt_listp))
1996 list_del_init(&ndlp->dev_loss_evt.evt_listp);
dea31012005-04-17 16:05:31 -05001997
James Smart858c9f62007-06-17 19:56:39 -05001998 if (!list_empty(&ndlp->dev_loss_evt.evt_listp)) {
1999 list_del_init(&ndlp->dev_loss_evt.evt_listp);
2000 complete((struct completion *)(ndlp->dev_loss_evt.evt_arg2));
2001 }
2002
James Smart2e0fef82007-06-17 19:56:36 -05002003 lpfc_unreg_rpi(vport, ndlp);
dea31012005-04-17 16:05:31 -05002004
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002005 return 0;
dea31012005-04-17 16:05:31 -05002006}
2007
2008/*
2009 * Check to see if we can free the nlp back to the freelist.
2010 * If we are in the middle of using the nlp in the discovery state
2011 * machine, defer the free till we reach the end of the state machine.
2012 */
James Smart329f9bc2007-04-25 09:53:01 -04002013static void
James Smart2e0fef82007-06-17 19:56:36 -05002014lpfc_nlp_remove(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05002015{
James Smart1dcb58e2007-04-25 09:51:30 -04002016 struct lpfc_rport_data *rdata;
dea31012005-04-17 16:05:31 -05002017
2018 if (ndlp->nlp_flag & NLP_DELAY_TMO) {
James Smart2e0fef82007-06-17 19:56:36 -05002019 lpfc_cancel_retry_delay_tmo(vport, ndlp);
dea31012005-04-17 16:05:31 -05002020 }
2021
James Smart2e0fef82007-06-17 19:56:36 -05002022 lpfc_cleanup_node(vport, ndlp);
James Smart1dcb58e2007-04-25 09:51:30 -04002023
James Smart2e0fef82007-06-17 19:56:36 -05002024 /*
James Smart92d7f7b2007-06-17 19:56:38 -05002025 * We can get here with a non-NULL ndlp->rport because when we
2026 * unregister a rport we don't break the rport/node linkage. So if we
2027 * do, make sure we don't leaving any dangling pointers behind.
James Smart2e0fef82007-06-17 19:56:36 -05002028 */
James Smart92d7f7b2007-06-17 19:56:38 -05002029 if (ndlp->rport) {
James Smart329f9bc2007-04-25 09:53:01 -04002030 rdata = ndlp->rport->dd_data;
2031 rdata->pnode = NULL;
2032 ndlp->rport = NULL;
dea31012005-04-17 16:05:31 -05002033 }
dea31012005-04-17 16:05:31 -05002034}
2035
2036static int
James Smart2e0fef82007-06-17 19:56:36 -05002037lpfc_matchdid(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2038 uint32_t did)
dea31012005-04-17 16:05:31 -05002039{
James Smart2e0fef82007-06-17 19:56:36 -05002040 D_ID mydid, ndlpdid, matchdid;
dea31012005-04-17 16:05:31 -05002041
2042 if (did == Bcast_DID)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002043 return 0;
dea31012005-04-17 16:05:31 -05002044
2045 if (ndlp->nlp_DID == 0) {
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002046 return 0;
dea31012005-04-17 16:05:31 -05002047 }
2048
2049 /* First check for Direct match */
2050 if (ndlp->nlp_DID == did)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002051 return 1;
dea31012005-04-17 16:05:31 -05002052
2053 /* Next check for area/domain identically equals 0 match */
James Smart2e0fef82007-06-17 19:56:36 -05002054 mydid.un.word = vport->fc_myDID;
dea31012005-04-17 16:05:31 -05002055 if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) {
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002056 return 0;
dea31012005-04-17 16:05:31 -05002057 }
2058
2059 matchdid.un.word = did;
2060 ndlpdid.un.word = ndlp->nlp_DID;
2061 if (matchdid.un.b.id == ndlpdid.un.b.id) {
2062 if ((mydid.un.b.domain == matchdid.un.b.domain) &&
2063 (mydid.un.b.area == matchdid.un.b.area)) {
2064 if ((ndlpdid.un.b.domain == 0) &&
2065 (ndlpdid.un.b.area == 0)) {
2066 if (ndlpdid.un.b.id)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002067 return 1;
dea31012005-04-17 16:05:31 -05002068 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002069 return 0;
dea31012005-04-17 16:05:31 -05002070 }
2071
2072 matchdid.un.word = ndlp->nlp_DID;
2073 if ((mydid.un.b.domain == ndlpdid.un.b.domain) &&
2074 (mydid.un.b.area == ndlpdid.un.b.area)) {
2075 if ((matchdid.un.b.domain == 0) &&
2076 (matchdid.un.b.area == 0)) {
2077 if (matchdid.un.b.id)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002078 return 1;
dea31012005-04-17 16:05:31 -05002079 }
2080 }
2081 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002082 return 0;
dea31012005-04-17 16:05:31 -05002083}
2084
James Smart685f0bf2007-04-25 09:53:08 -04002085/* Search for a nodelist entry */
James Smart2e0fef82007-06-17 19:56:36 -05002086static struct lpfc_nodelist *
2087__lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05002088{
James Smart2e0fef82007-06-17 19:56:36 -05002089 struct lpfc_hba *phba = vport->phba;
James Smart2fb9bd82006-12-02 13:33:57 -05002090 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05002091 uint32_t data1;
2092
James Smart2e0fef82007-06-17 19:56:36 -05002093 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
2094 if (lpfc_matchdid(vport, ndlp, did)) {
James Smart685f0bf2007-04-25 09:53:08 -04002095 data1 = (((uint32_t) ndlp->nlp_state << 24) |
2096 ((uint32_t) ndlp->nlp_xri << 16) |
2097 ((uint32_t) ndlp->nlp_type << 8) |
2098 ((uint32_t) ndlp->nlp_rpi & 0xff));
2099 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
James Smart92d7f7b2007-06-17 19:56:38 -05002100 "%d (%d):0929 FIND node DID "
James Smart685f0bf2007-04-25 09:53:08 -04002101 " Data: x%p x%x x%x x%x\n",
James Smart92d7f7b2007-06-17 19:56:38 -05002102 phba->brd_no, vport->vpi,
James Smart685f0bf2007-04-25 09:53:08 -04002103 ndlp, ndlp->nlp_DID,
2104 ndlp->nlp_flag, data1);
James Smart685f0bf2007-04-25 09:53:08 -04002105 return ndlp;
dea31012005-04-17 16:05:31 -05002106 }
2107 }
Jamie Wellnitz66a9ed62006-02-28 22:33:10 -05002108
dea31012005-04-17 16:05:31 -05002109 /* FIND node did <did> NOT FOUND */
James Smart2fb9bd82006-12-02 13:33:57 -05002110 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
James Smart92d7f7b2007-06-17 19:56:38 -05002111 "%d (%d):0932 FIND node did x%x NOT FOUND.\n",
2112 phba->brd_no, vport->vpi, did);
dea31012005-04-17 16:05:31 -05002113 return NULL;
2114}
2115
2116struct lpfc_nodelist *
James Smart2e0fef82007-06-17 19:56:36 -05002117lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05002118{
James Smart2e0fef82007-06-17 19:56:36 -05002119 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05002120 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05002121
James Smart2e0fef82007-06-17 19:56:36 -05002122 spin_lock_irq(shost->host_lock);
2123 ndlp = __lpfc_findnode_did(vport, did);
2124 spin_unlock_irq(shost->host_lock);
2125 return ndlp;
2126}
2127
2128struct lpfc_nodelist *
2129lpfc_setup_disc_node(struct lpfc_vport *vport, uint32_t did)
2130{
2131 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2132 struct lpfc_nodelist *ndlp;
2133
2134 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002135 if (!ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05002136 if ((vport->fc_flag & FC_RSCN_MODE) != 0 &&
2137 lpfc_rscn_payload_check(vport, did) == 0)
dea31012005-04-17 16:05:31 -05002138 return NULL;
2139 ndlp = (struct lpfc_nodelist *)
James Smart2e0fef82007-06-17 19:56:36 -05002140 mempool_alloc(vport->phba->nlp_mem_pool, GFP_KERNEL);
dea31012005-04-17 16:05:31 -05002141 if (!ndlp)
2142 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05002143 lpfc_nlp_init(vport, ndlp, did);
2144 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2145 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002146 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002147 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002148 return ndlp;
2149 }
James Smart2e0fef82007-06-17 19:56:36 -05002150 if (vport->fc_flag & FC_RSCN_MODE) {
2151 if (lpfc_rscn_payload_check(vport, did)) {
2152 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002153 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002154 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002155
2156 /* Since this node is marked for discovery,
2157 * delay timeout is not needed.
2158 */
James Smartfdcebe22006-03-07 15:04:01 -05002159 if (ndlp->nlp_flag & NLP_DELAY_TMO)
James Smart2e0fef82007-06-17 19:56:36 -05002160 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smart071fbd3d2006-04-15 11:53:20 -04002161 } else
dea31012005-04-17 16:05:31 -05002162 ndlp = NULL;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002163 } else {
James Smart685f0bf2007-04-25 09:53:08 -04002164 if (ndlp->nlp_state == NLP_STE_ADISC_ISSUE ||
2165 ndlp->nlp_state == NLP_STE_PLOGI_ISSUE)
dea31012005-04-17 16:05:31 -05002166 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05002167 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
2168 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002169 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05002170 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002171 }
2172 return ndlp;
2173}
2174
2175/* Build a list of nodes to discover based on the loopmap */
2176void
James Smart2e0fef82007-06-17 19:56:36 -05002177lpfc_disc_list_loopmap(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002178{
James Smart2e0fef82007-06-17 19:56:36 -05002179 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002180 int j;
2181 uint32_t alpa, index;
2182
James Smart2e0fef82007-06-17 19:56:36 -05002183 if (!lpfc_is_link_up(phba))
dea31012005-04-17 16:05:31 -05002184 return;
James Smart2e0fef82007-06-17 19:56:36 -05002185
2186 if (phba->fc_topology != TOPOLOGY_LOOP)
dea31012005-04-17 16:05:31 -05002187 return;
dea31012005-04-17 16:05:31 -05002188
2189 /* Check for loop map present or not */
2190 if (phba->alpa_map[0]) {
2191 for (j = 1; j <= phba->alpa_map[0]; j++) {
2192 alpa = phba->alpa_map[j];
James Smart2e0fef82007-06-17 19:56:36 -05002193 if (((vport->fc_myDID & 0xff) == alpa) || (alpa == 0))
dea31012005-04-17 16:05:31 -05002194 continue;
James Smart2e0fef82007-06-17 19:56:36 -05002195 lpfc_setup_disc_node(vport, alpa);
dea31012005-04-17 16:05:31 -05002196 }
2197 } else {
2198 /* No alpamap, so try all alpa's */
2199 for (j = 0; j < FC_MAXLOOP; j++) {
2200 /* If cfg_scan_down is set, start from highest
2201 * ALPA (0xef) to lowest (0x1).
2202 */
James Smart3de2a652007-08-02 11:09:59 -04002203 if (vport->cfg_scan_down)
dea31012005-04-17 16:05:31 -05002204 index = j;
2205 else
2206 index = FC_MAXLOOP - j - 1;
2207 alpa = lpfcAlpaArray[index];
James Smart2e0fef82007-06-17 19:56:36 -05002208 if ((vport->fc_myDID & 0xff) == alpa)
dea31012005-04-17 16:05:31 -05002209 continue;
James Smart2e0fef82007-06-17 19:56:36 -05002210 lpfc_setup_disc_node(vport, alpa);
dea31012005-04-17 16:05:31 -05002211 }
2212 }
2213 return;
2214}
2215
dea31012005-04-17 16:05:31 -05002216void
James Smart2e0fef82007-06-17 19:56:36 -05002217lpfc_issue_clear_la(struct lpfc_hba *phba, struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002218{
dea31012005-04-17 16:05:31 -05002219 LPFC_MBOXQ_t *mbox;
James Smart2e0fef82007-06-17 19:56:36 -05002220 struct lpfc_sli *psli = &phba->sli;
2221 struct lpfc_sli_ring *extra_ring = &psli->ring[psli->extra_ring];
2222 struct lpfc_sli_ring *fcp_ring = &psli->ring[psli->fcp_ring];
2223 struct lpfc_sli_ring *next_ring = &psli->ring[psli->next_ring];
2224 int rc;
2225
James Smart92d7f7b2007-06-17 19:56:38 -05002226 /*
2227 * if it's not a physical port or if we already send
2228 * clear_la then don't send it.
2229 */
2230 if ((phba->link_state >= LPFC_CLEAR_LA) ||
2231 (vport->port_type != LPFC_PHYSICAL_PORT))
2232 return;
2233
James Smart2e0fef82007-06-17 19:56:36 -05002234 /* Link up discovery */
2235 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL)) != NULL) {
2236 phba->link_state = LPFC_CLEAR_LA;
2237 lpfc_clear_la(phba, mbox);
2238 mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
2239 mbox->vport = vport;
2240 rc = lpfc_sli_issue_mbox(phba, mbox, (MBX_NOWAIT |
2241 MBX_STOP_IOCB));
2242 if (rc == MBX_NOT_FINISHED) {
2243 mempool_free(mbox, phba->mbox_mem_pool);
2244 lpfc_disc_flush_list(vport);
2245 extra_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
2246 fcp_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
2247 next_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
James Smart92d7f7b2007-06-17 19:56:38 -05002248 phba->link_state = LPFC_HBA_ERROR;
2249 }
2250 }
2251}
2252
2253/* Reg_vpi to tell firmware to resume normal operations */
2254void
2255lpfc_issue_reg_vpi(struct lpfc_hba *phba, struct lpfc_vport *vport)
2256{
2257 LPFC_MBOXQ_t *regvpimbox;
2258
2259 regvpimbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2260 if (regvpimbox) {
2261 lpfc_reg_vpi(phba, vport->vpi, vport->fc_myDID, regvpimbox);
2262 regvpimbox->mbox_cmpl = lpfc_mbx_cmpl_reg_vpi;
2263 regvpimbox->vport = vport;
2264 if (lpfc_sli_issue_mbox(phba, regvpimbox,
2265 (MBX_NOWAIT | MBX_STOP_IOCB))
2266 == MBX_NOT_FINISHED) {
2267 mempool_free(regvpimbox, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05002268 }
2269 }
2270}
2271
2272/* Start Link up / RSCN discovery on NPR nodes */
2273void
2274lpfc_disc_start(struct lpfc_vport *vport)
2275{
2276 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2277 struct lpfc_hba *phba = vport->phba;
James Smart685f0bf2007-04-25 09:53:08 -04002278 uint32_t num_sent;
dea31012005-04-17 16:05:31 -05002279 uint32_t clear_la_pending;
James Smart685f0bf2007-04-25 09:53:08 -04002280 int did_changed;
dea31012005-04-17 16:05:31 -05002281
James Smart2e0fef82007-06-17 19:56:36 -05002282 if (!lpfc_is_link_up(phba))
dea31012005-04-17 16:05:31 -05002283 return;
James Smart2e0fef82007-06-17 19:56:36 -05002284
2285 if (phba->link_state == LPFC_CLEAR_LA)
dea31012005-04-17 16:05:31 -05002286 clear_la_pending = 1;
2287 else
2288 clear_la_pending = 0;
2289
James Smart2e0fef82007-06-17 19:56:36 -05002290 if (vport->port_state < LPFC_VPORT_READY)
2291 vport->port_state = LPFC_DISC_AUTH;
dea31012005-04-17 16:05:31 -05002292
James Smart2e0fef82007-06-17 19:56:36 -05002293 lpfc_set_disctmo(vport);
2294
2295 if (vport->fc_prevDID == vport->fc_myDID)
dea31012005-04-17 16:05:31 -05002296 did_changed = 0;
James Smart2e0fef82007-06-17 19:56:36 -05002297 else
dea31012005-04-17 16:05:31 -05002298 did_changed = 1;
James Smart2e0fef82007-06-17 19:56:36 -05002299
2300 vport->fc_prevDID = vport->fc_myDID;
2301 vport->num_disc_nodes = 0;
dea31012005-04-17 16:05:31 -05002302
2303 /* Start Discovery state <hba_state> */
2304 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smart92d7f7b2007-06-17 19:56:38 -05002305 "%d (%d):0202 Start Discovery hba state x%x "
dea31012005-04-17 16:05:31 -05002306 "Data: x%x x%x x%x\n",
James Smart92d7f7b2007-06-17 19:56:38 -05002307 phba->brd_no, vport->vpi, vport->port_state,
2308 vport->fc_flag, vport->fc_plogi_cnt,
2309 vport->fc_adisc_cnt);
dea31012005-04-17 16:05:31 -05002310
2311 /* First do ADISCs - if any */
James Smart2e0fef82007-06-17 19:56:36 -05002312 num_sent = lpfc_els_disc_adisc(vport);
dea31012005-04-17 16:05:31 -05002313
2314 if (num_sent)
2315 return;
2316
James Smart92d7f7b2007-06-17 19:56:38 -05002317 /*
2318 * For SLI3, cmpl_reg_vpi will set port_state to READY, and
2319 * continue discovery.
2320 */
2321 if ((phba->sli3_options & LPFC_SLI3_NPIV_ENABLED) &&
2322 !(vport->fc_flag & FC_RSCN_MODE)) {
2323 lpfc_issue_reg_vpi(phba, vport);
2324 return;
2325 }
James Smart2e0fef82007-06-17 19:56:36 -05002326
James Smart92d7f7b2007-06-17 19:56:38 -05002327 /*
2328 * For SLI2, we need to set port_state to READY and continue
2329 * discovery.
2330 */
2331 if (vport->port_state < LPFC_VPORT_READY && !clear_la_pending) {
2332 /* If we get here, there is nothing to ADISC */
2333 if (vport->port_type == LPFC_PHYSICAL_PORT)
2334 lpfc_issue_clear_la(phba, vport);
2335
2336 if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
James Smart2e0fef82007-06-17 19:56:36 -05002337 vport->num_disc_nodes = 0;
2338 /* go thru NPR nodes and issue ELS PLOGIs */
2339 if (vport->fc_npr_cnt)
2340 lpfc_els_disc_plogi(vport);
2341
2342 if (!vport->num_disc_nodes) {
2343 spin_lock_irq(shost->host_lock);
2344 vport->fc_flag &= ~FC_NDISC_ACTIVE;
2345 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05002346 lpfc_can_disctmo(vport);
dea31012005-04-17 16:05:31 -05002347 }
2348 }
James Smart92d7f7b2007-06-17 19:56:38 -05002349 vport->port_state = LPFC_VPORT_READY;
dea31012005-04-17 16:05:31 -05002350 } else {
2351 /* Next do PLOGIs - if any */
James Smart2e0fef82007-06-17 19:56:36 -05002352 num_sent = lpfc_els_disc_plogi(vport);
dea31012005-04-17 16:05:31 -05002353
2354 if (num_sent)
2355 return;
2356
James Smart2e0fef82007-06-17 19:56:36 -05002357 if (vport->fc_flag & FC_RSCN_MODE) {
dea31012005-04-17 16:05:31 -05002358 /* Check to see if more RSCNs came in while we
2359 * were processing this one.
2360 */
James Smart2e0fef82007-06-17 19:56:36 -05002361 if ((vport->fc_rscn_id_cnt == 0) &&
2362 (!(vport->fc_flag & FC_RSCN_DISCOVERY))) {
2363 spin_lock_irq(shost->host_lock);
2364 vport->fc_flag &= ~FC_RSCN_MODE;
2365 spin_unlock_irq(shost->host_lock);
James Smart92d7f7b2007-06-17 19:56:38 -05002366 lpfc_can_disctmo(vport);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002367 } else
James Smart2e0fef82007-06-17 19:56:36 -05002368 lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05002369 }
2370 }
2371 return;
2372}
2373
2374/*
2375 * Ignore completion for all IOCBs on tx and txcmpl queue for ELS
2376 * ring the match the sppecified nodelist.
2377 */
2378static void
James Smart2e0fef82007-06-17 19:56:36 -05002379lpfc_free_tx(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05002380{
James Smart2534ba72007-04-25 09:52:20 -04002381 LIST_HEAD(completions);
dea31012005-04-17 16:05:31 -05002382 struct lpfc_sli *psli;
2383 IOCB_t *icmd;
2384 struct lpfc_iocbq *iocb, *next_iocb;
2385 struct lpfc_sli_ring *pring;
dea31012005-04-17 16:05:31 -05002386
2387 psli = &phba->sli;
2388 pring = &psli->ring[LPFC_ELS_RING];
2389
2390 /* Error matching iocb on txq or txcmplq
2391 * First check the txq.
2392 */
James Smart2e0fef82007-06-17 19:56:36 -05002393 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05002394 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
2395 if (iocb->context1 != ndlp) {
2396 continue;
2397 }
2398 icmd = &iocb->iocb;
2399 if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
2400 (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
2401
James Smart2534ba72007-04-25 09:52:20 -04002402 list_move_tail(&iocb->list, &completions);
dea31012005-04-17 16:05:31 -05002403 pring->txq_cnt--;
dea31012005-04-17 16:05:31 -05002404 }
2405 }
2406
2407 /* Next check the txcmplq */
2408 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
2409 if (iocb->context1 != ndlp) {
2410 continue;
2411 }
2412 icmd = &iocb->iocb;
James Smart2e0fef82007-06-17 19:56:36 -05002413 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR ||
2414 icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX) {
James Smart2534ba72007-04-25 09:52:20 -04002415 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
dea31012005-04-17 16:05:31 -05002416 }
2417 }
James Smart2e0fef82007-06-17 19:56:36 -05002418 spin_unlock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04002419
2420 while (!list_empty(&completions)) {
2421 iocb = list_get_first(&completions, struct lpfc_iocbq, list);
James Smart92d7f7b2007-06-17 19:56:38 -05002422 list_del_init(&iocb->list);
James Smart2534ba72007-04-25 09:52:20 -04002423
James Smart2e0fef82007-06-17 19:56:36 -05002424 if (!iocb->iocb_cmpl)
2425 lpfc_sli_release_iocbq(phba, iocb);
2426 else {
James Smart2534ba72007-04-25 09:52:20 -04002427 icmd = &iocb->iocb;
2428 icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
2429 icmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
2430 (iocb->iocb_cmpl) (phba, iocb, iocb);
James Smart2e0fef82007-06-17 19:56:36 -05002431 }
James Smart2534ba72007-04-25 09:52:20 -04002432 }
dea31012005-04-17 16:05:31 -05002433}
2434
2435void
James Smart2e0fef82007-06-17 19:56:36 -05002436lpfc_disc_flush_list(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002437{
2438 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05002439 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002440
James Smart2e0fef82007-06-17 19:56:36 -05002441 if (vport->fc_plogi_cnt || vport->fc_adisc_cnt) {
2442 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
James Smart685f0bf2007-04-25 09:53:08 -04002443 nlp_listp) {
2444 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
2445 ndlp->nlp_state == NLP_STE_ADISC_ISSUE) {
2446 lpfc_free_tx(phba, ndlp);
2447 lpfc_nlp_put(ndlp);
2448 }
dea31012005-04-17 16:05:31 -05002449 }
2450 }
dea31012005-04-17 16:05:31 -05002451}
2452
James Smart92d7f7b2007-06-17 19:56:38 -05002453void
2454lpfc_cleanup_discovery_resources(struct lpfc_vport *vport)
2455{
2456 lpfc_els_flush_rscn(vport);
2457 lpfc_els_flush_cmd(vport);
2458 lpfc_disc_flush_list(vport);
2459}
2460
dea31012005-04-17 16:05:31 -05002461/*****************************************************************************/
2462/*
2463 * NAME: lpfc_disc_timeout
2464 *
2465 * FUNCTION: Fibre Channel driver discovery timeout routine.
2466 *
2467 * EXECUTION ENVIRONMENT: interrupt only
2468 *
2469 * CALLED FROM:
2470 * Timer function
2471 *
2472 * RETURNS:
2473 * none
2474 */
2475/*****************************************************************************/
2476void
2477lpfc_disc_timeout(unsigned long ptr)
2478{
James Smart2e0fef82007-06-17 19:56:36 -05002479 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
2480 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002481 unsigned long flags = 0;
2482
2483 if (unlikely(!phba))
2484 return;
2485
James Smart2e0fef82007-06-17 19:56:36 -05002486 if ((vport->work_port_events & WORKER_DISC_TMO) == 0) {
2487 spin_lock_irqsave(&vport->work_port_lock, flags);
2488 vport->work_port_events |= WORKER_DISC_TMO;
2489 spin_unlock_irqrestore(&vport->work_port_lock, flags);
2490
James Smart92d7f7b2007-06-17 19:56:38 -05002491 spin_lock_irqsave(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002492 if (phba->work_wait)
James Smart92d7f7b2007-06-17 19:56:38 -05002493 lpfc_worker_wake_up(phba);
2494 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -05002495 }
dea31012005-04-17 16:05:31 -05002496 return;
2497}
2498
2499static void
James Smart2e0fef82007-06-17 19:56:36 -05002500lpfc_disc_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002501{
James Smart2e0fef82007-06-17 19:56:36 -05002502 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2503 struct lpfc_hba *phba = vport->phba;
2504 struct lpfc_sli *psli = &phba->sli;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002505 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart92d7f7b2007-06-17 19:56:38 -05002506 LPFC_MBOXQ_t *initlinkmbox;
dea31012005-04-17 16:05:31 -05002507 int rc, clrlaerr = 0;
2508
James Smart2e0fef82007-06-17 19:56:36 -05002509 if (!(vport->fc_flag & FC_DISC_TMO))
dea31012005-04-17 16:05:31 -05002510 return;
2511
James Smart2e0fef82007-06-17 19:56:36 -05002512 spin_lock_irq(shost->host_lock);
2513 vport->fc_flag &= ~FC_DISC_TMO;
2514 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002515
James Smart858c9f62007-06-17 19:56:39 -05002516 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_ELS_CMD,
2517 "disc timeout: state:x%x rtry:x%x flg:x%x",
2518 vport->port_state, vport->fc_ns_retry, vport->fc_flag);
2519
James Smart2e0fef82007-06-17 19:56:36 -05002520 switch (vport->port_state) {
dea31012005-04-17 16:05:31 -05002521
2522 case LPFC_LOCAL_CFG_LINK:
James Smart2e0fef82007-06-17 19:56:36 -05002523 /* port_state is identically LPFC_LOCAL_CFG_LINK while waiting for
2524 * FAN
2525 */
2526 /* FAN timeout */
James Smarted957682007-06-17 19:56:37 -05002527 lpfc_printf_log(phba, KERN_WARNING, LOG_DISCOVERY,
James Smart92d7f7b2007-06-17 19:56:38 -05002528 "%d (%d):0221 FAN timeout\n",
2529 phba->brd_no, vport->vpi);
dea31012005-04-17 16:05:31 -05002530
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002531 /* Start discovery by sending FLOGI, clean up old rpis */
James Smart2e0fef82007-06-17 19:56:36 -05002532 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
James Smart685f0bf2007-04-25 09:53:08 -04002533 nlp_listp) {
2534 if (ndlp->nlp_state != NLP_STE_NPR_NODE)
2535 continue;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002536 if (ndlp->nlp_type & NLP_FABRIC) {
2537 /* Clean up the ndlp on Fabric connections */
James Smart2e0fef82007-06-17 19:56:36 -05002538 lpfc_drop_node(vport, ndlp);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002539 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002540 /* Fail outstanding IO now since device
2541 * is marked for PLOGI.
2542 */
James Smart2e0fef82007-06-17 19:56:36 -05002543 lpfc_unreg_rpi(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002544 }
2545 }
James Smart92d7f7b2007-06-17 19:56:38 -05002546 if (vport->port_state != LPFC_FLOGI) {
2547 vport->port_state = LPFC_FLOGI;
2548 lpfc_set_disctmo(vport);
2549 lpfc_initial_flogi(vport);
2550 }
dea31012005-04-17 16:05:31 -05002551 break;
2552
James Smart92d7f7b2007-06-17 19:56:38 -05002553 case LPFC_FDISC:
dea31012005-04-17 16:05:31 -05002554 case LPFC_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002555 /* port_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */
dea31012005-04-17 16:05:31 -05002556 /* Initial FLOGI timeout */
James Smarted957682007-06-17 19:56:37 -05002557 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
James Smart92d7f7b2007-06-17 19:56:38 -05002558 "%d (%d):0222 Initial %s timeout\n",
2559 phba->brd_no, vport->vpi,
2560 vport->vpi ? "FLOGI" : "FDISC");
dea31012005-04-17 16:05:31 -05002561
2562 /* Assume no Fabric and go on with discovery.
2563 * Check for outstanding ELS FLOGI to abort.
2564 */
2565
2566 /* FLOGI failed, so just use loop map to make discovery list */
James Smart2e0fef82007-06-17 19:56:36 -05002567 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -05002568
2569 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002570 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -05002571 break;
2572
2573 case LPFC_FABRIC_CFG_LINK:
2574 /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for
2575 NameServer login */
2576 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
James Smart92d7f7b2007-06-17 19:56:38 -05002577 "%d (%d):0223 Timeout while waiting for "
2578 "NameServer login\n",
2579 phba->brd_no, vport->vpi);
dea31012005-04-17 16:05:31 -05002580
2581 /* Next look for NameServer ndlp */
James Smart2e0fef82007-06-17 19:56:36 -05002582 ndlp = lpfc_findnode_did(vport, NameServer_DID);
dea31012005-04-17 16:05:31 -05002583 if (ndlp)
James Smart329f9bc2007-04-25 09:53:01 -04002584 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002585 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002586 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -05002587 break;
2588
2589 case LPFC_NS_QRY:
2590 /* Check for wait for NameServer Rsp timeout */
2591 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
James Smart92d7f7b2007-06-17 19:56:38 -05002592 "%d (%d):0224 NameServer Query timeout "
dea31012005-04-17 16:05:31 -05002593 "Data: x%x x%x\n",
James Smart92d7f7b2007-06-17 19:56:38 -05002594 phba->brd_no, vport->vpi,
James Smart2e0fef82007-06-17 19:56:36 -05002595 vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
dea31012005-04-17 16:05:31 -05002596
James Smart92d7f7b2007-06-17 19:56:38 -05002597 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
2598 /* Try it one more time */
2599 vport->fc_ns_retry++;
2600 rc = lpfc_ns_cmd(vport, SLI_CTNS_GID_FT,
2601 vport->fc_ns_retry, 0);
2602 if (rc == 0)
2603 break;
dea31012005-04-17 16:05:31 -05002604 }
James Smart92d7f7b2007-06-17 19:56:38 -05002605 vport->fc_ns_retry = 0;
dea31012005-04-17 16:05:31 -05002606
James Smart92d7f7b2007-06-17 19:56:38 -05002607 /*
2608 * Discovery is over.
2609 * set port_state to PORT_READY if SLI2.
2610 * cmpl_reg_vpi will set port_state to READY for SLI3.
2611 */
2612 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
2613 lpfc_issue_reg_vpi(phba, vport);
2614 else { /* NPIV Not enabled */
2615 lpfc_issue_clear_la(phba, vport);
2616 vport->port_state = LPFC_VPORT_READY;
dea31012005-04-17 16:05:31 -05002617 }
2618
2619 /* Setup and issue mailbox INITIALIZE LINK command */
2620 initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2621 if (!initlinkmbox) {
2622 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
James Smart92d7f7b2007-06-17 19:56:38 -05002623 "%d (%d):0206 Device Discovery "
dea31012005-04-17 16:05:31 -05002624 "completion error\n",
James Smart92d7f7b2007-06-17 19:56:38 -05002625 phba->brd_no, vport->vpi);
James Smart2e0fef82007-06-17 19:56:36 -05002626 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05002627 break;
2628 }
2629
2630 lpfc_linkdown(phba);
2631 lpfc_init_link(phba, initlinkmbox, phba->cfg_topology,
2632 phba->cfg_link_speed);
2633 initlinkmbox->mb.un.varInitLnk.lipsr_AL_PA = 0;
James Smarted957682007-06-17 19:56:37 -05002634 initlinkmbox->vport = vport;
James Smart92d7f7b2007-06-17 19:56:38 -05002635 initlinkmbox->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
dea31012005-04-17 16:05:31 -05002636 rc = lpfc_sli_issue_mbox(phba, initlinkmbox,
2637 (MBX_NOWAIT | MBX_STOP_IOCB));
James Smart5b8bd0c2007-04-25 09:52:49 -04002638 lpfc_set_loopback_flag(phba);
dea31012005-04-17 16:05:31 -05002639 if (rc == MBX_NOT_FINISHED)
2640 mempool_free(initlinkmbox, phba->mbox_mem_pool);
2641
2642 break;
2643
2644 case LPFC_DISC_AUTH:
2645 /* Node Authentication timeout */
James Smarted957682007-06-17 19:56:37 -05002646 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
James Smart92d7f7b2007-06-17 19:56:38 -05002647 "%d (%d):0227 Node Authentication timeout\n",
2648 phba->brd_no, vport->vpi);
James Smart2e0fef82007-06-17 19:56:36 -05002649 lpfc_disc_flush_list(vport);
2650
James Smart92d7f7b2007-06-17 19:56:38 -05002651 /*
2652 * set port_state to PORT_READY if SLI2.
2653 * cmpl_reg_vpi will set port_state to READY for SLI3.
2654 */
2655 if (phba->sli3_options & LPFC_SLI3_NPIV_ENABLED)
2656 lpfc_issue_reg_vpi(phba, vport);
2657 else { /* NPIV Not enabled */
2658 lpfc_issue_clear_la(phba, vport);
2659 vport->port_state = LPFC_VPORT_READY;
dea31012005-04-17 16:05:31 -05002660 }
2661 break;
2662
James Smart2e0fef82007-06-17 19:56:36 -05002663 case LPFC_VPORT_READY:
2664 if (vport->fc_flag & FC_RSCN_MODE) {
James Smarted957682007-06-17 19:56:37 -05002665 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
James Smart92d7f7b2007-06-17 19:56:38 -05002666 "%d (%d):0231 RSCN timeout Data: x%x "
2667 "x%x\n",
2668 phba->brd_no, vport->vpi,
James Smart2e0fef82007-06-17 19:56:36 -05002669 vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
dea31012005-04-17 16:05:31 -05002670
2671 /* Cleanup any outstanding ELS commands */
James Smart2e0fef82007-06-17 19:56:36 -05002672 lpfc_els_flush_cmd(vport);
dea31012005-04-17 16:05:31 -05002673
James Smart2e0fef82007-06-17 19:56:36 -05002674 lpfc_els_flush_rscn(vport);
2675 lpfc_disc_flush_list(vport);
dea31012005-04-17 16:05:31 -05002676 }
2677 break;
James Smart2e0fef82007-06-17 19:56:36 -05002678
James Smart92d7f7b2007-06-17 19:56:38 -05002679 default:
James Smarted957682007-06-17 19:56:37 -05002680 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
James Smart92d7f7b2007-06-17 19:56:38 -05002681 "%d (%d):0229 Unexpected discovery timeout, "
2682 "vport State x%x\n",
2683 phba->brd_no, vport->vpi, vport->port_state);
James Smart2e0fef82007-06-17 19:56:36 -05002684
2685 break;
2686 }
2687
2688 switch (phba->link_state) {
2689 case LPFC_CLEAR_LA:
James Smart92d7f7b2007-06-17 19:56:38 -05002690 /* CLEAR LA timeout */
James Smarted957682007-06-17 19:56:37 -05002691 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
James Smart92d7f7b2007-06-17 19:56:38 -05002692 "%d (%d):0228 CLEAR LA timeout\n",
2693 phba->brd_no, vport->vpi);
James Smart2e0fef82007-06-17 19:56:36 -05002694 clrlaerr = 1;
2695 break;
2696
2697 case LPFC_LINK_UNKNOWN:
2698 case LPFC_WARM_START:
2699 case LPFC_INIT_START:
2700 case LPFC_INIT_MBX_CMDS:
2701 case LPFC_LINK_DOWN:
2702 case LPFC_LINK_UP:
2703 case LPFC_HBA_ERROR:
James Smarted957682007-06-17 19:56:37 -05002704 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
James Smart92d7f7b2007-06-17 19:56:38 -05002705 "%d (%d):0230 Unexpected timeout, hba link "
James Smart2e0fef82007-06-17 19:56:36 -05002706 "state x%x\n",
James Smart92d7f7b2007-06-17 19:56:38 -05002707 phba->brd_no, vport->vpi, phba->link_state);
James Smart2e0fef82007-06-17 19:56:36 -05002708 clrlaerr = 1;
2709 break;
James Smart92d7f7b2007-06-17 19:56:38 -05002710
2711 case LPFC_HBA_READY:
2712 break;
dea31012005-04-17 16:05:31 -05002713 }
2714
2715 if (clrlaerr) {
James Smart2e0fef82007-06-17 19:56:36 -05002716 lpfc_disc_flush_list(vport);
James Smarta4bc3372006-12-02 13:34:16 -05002717 psli->ring[(psli->extra_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
dea31012005-04-17 16:05:31 -05002718 psli->ring[(psli->fcp_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
2719 psli->ring[(psli->next_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
James Smart2e0fef82007-06-17 19:56:36 -05002720 vport->port_state = LPFC_VPORT_READY;
dea31012005-04-17 16:05:31 -05002721 }
2722
2723 return;
2724}
2725
dea31012005-04-17 16:05:31 -05002726/*
2727 * This routine handles processing a NameServer REG_LOGIN mailbox
2728 * command upon completion. It is setup in the LPFC_MBOXQ
2729 * as the completion routine when the command is
2730 * handed off to the SLI layer.
2731 */
2732void
James Smart2e0fef82007-06-17 19:56:36 -05002733lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05002734{
James Smart2e0fef82007-06-17 19:56:36 -05002735 MAILBOX_t *mb = &pmb->mb;
2736 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
2737 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
2738 struct lpfc_vport *vport = pmb->vport;
dea31012005-04-17 16:05:31 -05002739
2740 pmb->context1 = NULL;
2741
dea31012005-04-17 16:05:31 -05002742 ndlp->nlp_rpi = mb->un.varWords[0];
dea31012005-04-17 16:05:31 -05002743 ndlp->nlp_type |= NLP_FABRIC;
James Smart2e0fef82007-06-17 19:56:36 -05002744 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
dea31012005-04-17 16:05:31 -05002745
James Smart2e0fef82007-06-17 19:56:36 -05002746 /*
2747 * Start issuing Fabric-Device Management Interface (FDMI) command to
2748 * 0xfffffa (FDMI well known port) or Delay issuing FDMI command if
2749 * fdmi-on=2 (supporting RPA/hostnmae)
dea31012005-04-17 16:05:31 -05002750 */
James Smart2e0fef82007-06-17 19:56:36 -05002751
James Smart3de2a652007-08-02 11:09:59 -04002752 if (vport->cfg_fdmi_on == 1)
James Smart2e0fef82007-06-17 19:56:36 -05002753 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA);
2754 else
2755 mod_timer(&vport->fc_fdmitmo, jiffies + HZ * 60);
dea31012005-04-17 16:05:31 -05002756
James Smart329f9bc2007-04-25 09:53:01 -04002757 /* Mailbox took a reference to the node */
2758 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002759 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2760 kfree(mp);
James Smart329f9bc2007-04-25 09:53:01 -04002761 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05002762
2763 return;
2764}
2765
James Smart685f0bf2007-04-25 09:53:08 -04002766static int
2767lpfc_filter_by_rpi(struct lpfc_nodelist *ndlp, void *param)
2768{
2769 uint16_t *rpi = param;
2770
2771 return ndlp->nlp_rpi == *rpi;
2772}
2773
2774static int
2775lpfc_filter_by_wwpn(struct lpfc_nodelist *ndlp, void *param)
2776{
2777 return memcmp(&ndlp->nlp_portname, param,
2778 sizeof(ndlp->nlp_portname)) == 0;
2779}
2780
dea31012005-04-17 16:05:31 -05002781struct lpfc_nodelist *
James Smart2e0fef82007-06-17 19:56:36 -05002782__lpfc_find_node(struct lpfc_vport *vport, node_filter filter, void *param)
dea31012005-04-17 16:05:31 -05002783{
James.Smart@Emulex.Com21568f52005-10-28 20:29:36 -04002784 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05002785
James Smart2e0fef82007-06-17 19:56:36 -05002786 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smart685f0bf2007-04-25 09:53:08 -04002787 if (ndlp->nlp_state != NLP_STE_UNUSED_NODE &&
2788 filter(ndlp, param))
2789 return ndlp;
2790 }
James.Smart@Emulex.Com21568f52005-10-28 20:29:36 -04002791 return NULL;
dea31012005-04-17 16:05:31 -05002792}
2793
James Smart685f0bf2007-04-25 09:53:08 -04002794/*
2795 * Search node lists for a remote port matching filter criteria
James Smart92d7f7b2007-06-17 19:56:38 -05002796 * Caller needs to hold host_lock before calling this routine.
James Smart685f0bf2007-04-25 09:53:08 -04002797 */
2798struct lpfc_nodelist *
James Smart2e0fef82007-06-17 19:56:36 -05002799lpfc_find_node(struct lpfc_vport *vport, node_filter filter, void *param)
James Smart685f0bf2007-04-25 09:53:08 -04002800{
James Smart2e0fef82007-06-17 19:56:36 -05002801 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart685f0bf2007-04-25 09:53:08 -04002802 struct lpfc_nodelist *ndlp;
2803
James Smart2e0fef82007-06-17 19:56:36 -05002804 spin_lock_irq(shost->host_lock);
2805 ndlp = __lpfc_find_node(vport, filter, param);
2806 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04002807 return ndlp;
2808}
2809
2810/*
2811 * This routine looks up the ndlp lists for the given RPI. If rpi found it
James Smart2e0fef82007-06-17 19:56:36 -05002812 * returns the node list element pointer else return NULL.
James Smart685f0bf2007-04-25 09:53:08 -04002813 */
2814struct lpfc_nodelist *
James Smart2e0fef82007-06-17 19:56:36 -05002815__lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi)
James Smart685f0bf2007-04-25 09:53:08 -04002816{
James Smart2e0fef82007-06-17 19:56:36 -05002817 return __lpfc_find_node(vport, lpfc_filter_by_rpi, &rpi);
James Smart685f0bf2007-04-25 09:53:08 -04002818}
2819
James Smart2534ba72007-04-25 09:52:20 -04002820struct lpfc_nodelist *
James Smart2e0fef82007-06-17 19:56:36 -05002821lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi)
James Smart2534ba72007-04-25 09:52:20 -04002822{
James Smart2e0fef82007-06-17 19:56:36 -05002823 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart2534ba72007-04-25 09:52:20 -04002824 struct lpfc_nodelist *ndlp;
2825
James Smart2e0fef82007-06-17 19:56:36 -05002826 spin_lock_irq(shost->host_lock);
2827 ndlp = __lpfc_findnode_rpi(vport, rpi);
2828 spin_unlock_irq(shost->host_lock);
James Smart2534ba72007-04-25 09:52:20 -04002829 return ndlp;
2830}
2831
James Smart488d1462006-03-07 15:02:37 -05002832/*
James Smart685f0bf2007-04-25 09:53:08 -04002833 * This routine looks up the ndlp lists for the given WWPN. If WWPN found it
James Smart2e0fef82007-06-17 19:56:36 -05002834 * returns the node element list pointer else return NULL.
James Smart488d1462006-03-07 15:02:37 -05002835 */
2836struct lpfc_nodelist *
James Smart2e0fef82007-06-17 19:56:36 -05002837lpfc_findnode_wwpn(struct lpfc_vport *vport, struct lpfc_name *wwpn)
James Smart488d1462006-03-07 15:02:37 -05002838{
James Smart2e0fef82007-06-17 19:56:36 -05002839 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart488d1462006-03-07 15:02:37 -05002840 struct lpfc_nodelist *ndlp;
James Smart488d1462006-03-07 15:02:37 -05002841
James Smart2e0fef82007-06-17 19:56:36 -05002842 spin_lock_irq(shost->host_lock);
2843 ndlp = __lpfc_find_node(vport, lpfc_filter_by_wwpn, wwpn);
2844 spin_unlock_irq(shost->host_lock);
James Smart858c9f62007-06-17 19:56:39 -05002845 return ndlp;
James Smart488d1462006-03-07 15:02:37 -05002846}
2847
dea31012005-04-17 16:05:31 -05002848void
James Smart92d7f7b2007-06-17 19:56:38 -05002849lpfc_dev_loss_delay(unsigned long ptr)
2850{
2851 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) ptr;
2852 struct lpfc_vport *vport = ndlp->vport;
2853 struct lpfc_hba *phba = vport->phba;
2854 struct lpfc_work_evt *evtp = &ndlp->dev_loss_evt;
2855 unsigned long flags;
2856
2857 evtp = &ndlp->dev_loss_evt;
2858
2859 spin_lock_irqsave(&phba->hbalock, flags);
2860 if (!list_empty(&evtp->evt_listp)) {
2861 spin_unlock_irqrestore(&phba->hbalock, flags);
2862 return;
2863 }
2864
2865 evtp->evt_arg1 = ndlp;
James Smart858c9f62007-06-17 19:56:39 -05002866 evtp->evt = LPFC_EVT_DEV_LOSS_DELAY;
James Smart92d7f7b2007-06-17 19:56:38 -05002867 list_add_tail(&evtp->evt_listp, &phba->work_list);
2868 if (phba->work_wait)
2869 lpfc_worker_wake_up(phba);
2870 spin_unlock_irqrestore(&phba->hbalock, flags);
2871 return;
2872}
2873
2874void
James Smart2e0fef82007-06-17 19:56:36 -05002875lpfc_nlp_init(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2876 uint32_t did)
dea31012005-04-17 16:05:31 -05002877{
2878 memset(ndlp, 0, sizeof (struct lpfc_nodelist));
dea31012005-04-17 16:05:31 -05002879 INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp);
James Smart92d7f7b2007-06-17 19:56:38 -05002880 INIT_LIST_HEAD(&ndlp->dev_loss_evt.evt_listp);
dea31012005-04-17 16:05:31 -05002881 init_timer(&ndlp->nlp_delayfunc);
2882 ndlp->nlp_delayfunc.function = lpfc_els_retry_delay;
2883 ndlp->nlp_delayfunc.data = (unsigned long)ndlp;
2884 ndlp->nlp_DID = did;
James Smart2e0fef82007-06-17 19:56:36 -05002885 ndlp->vport = vport;
dea31012005-04-17 16:05:31 -05002886 ndlp->nlp_sid = NLP_NO_SID;
James Smart685f0bf2007-04-25 09:53:08 -04002887 INIT_LIST_HEAD(&ndlp->nlp_listp);
James Smart329f9bc2007-04-25 09:53:01 -04002888 kref_init(&ndlp->kref);
James Smart858c9f62007-06-17 19:56:39 -05002889
2890 lpfc_debugfs_disc_trc(vport, LPFC_DISC_TRC_NODE,
2891 "node init: did:x%x",
2892 ndlp->nlp_DID, 0, 0);
2893
dea31012005-04-17 16:05:31 -05002894 return;
2895}
James Smart329f9bc2007-04-25 09:53:01 -04002896
2897void
2898lpfc_nlp_release(struct kref *kref)
2899{
2900 struct lpfc_nodelist *ndlp = container_of(kref, struct lpfc_nodelist,
2901 kref);
James Smart858c9f62007-06-17 19:56:39 -05002902
2903 lpfc_debugfs_disc_trc(ndlp->vport, LPFC_DISC_TRC_NODE,
2904 "node release: did:x%x flg:x%x type:x%x",
2905 ndlp->nlp_DID, ndlp->nlp_flag, ndlp->nlp_type);
2906
James Smart2e0fef82007-06-17 19:56:36 -05002907 lpfc_nlp_remove(ndlp->vport, ndlp);
2908 mempool_free(ndlp, ndlp->vport->phba->nlp_mem_pool);
James Smart329f9bc2007-04-25 09:53:01 -04002909}
2910
2911struct lpfc_nodelist *
2912lpfc_nlp_get(struct lpfc_nodelist *ndlp)
2913{
2914 if (ndlp)
2915 kref_get(&ndlp->kref);
2916 return ndlp;
2917}
2918
2919int
2920lpfc_nlp_put(struct lpfc_nodelist *ndlp)
2921{
2922 return ndlp ? kref_put(&ndlp->kref, lpfc_nlp_release) : 0;
2923}