blob: dee875ee61657538611008ea09c0eaa45ee1675a [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"
39
40/* AlpaArray for assignment of scsid for scan-down and bind_method */
41static uint8_t lpfcAlpaArray[] = {
42 0xEF, 0xE8, 0xE4, 0xE2, 0xE1, 0xE0, 0xDC, 0xDA, 0xD9, 0xD6,
43 0xD5, 0xD4, 0xD3, 0xD2, 0xD1, 0xCE, 0xCD, 0xCC, 0xCB, 0xCA,
44 0xC9, 0xC7, 0xC6, 0xC5, 0xC3, 0xBC, 0xBA, 0xB9, 0xB6, 0xB5,
45 0xB4, 0xB3, 0xB2, 0xB1, 0xAE, 0xAD, 0xAC, 0xAB, 0xAA, 0xA9,
46 0xA7, 0xA6, 0xA5, 0xA3, 0x9F, 0x9E, 0x9D, 0x9B, 0x98, 0x97,
47 0x90, 0x8F, 0x88, 0x84, 0x82, 0x81, 0x80, 0x7C, 0x7A, 0x79,
48 0x76, 0x75, 0x74, 0x73, 0x72, 0x71, 0x6E, 0x6D, 0x6C, 0x6B,
49 0x6A, 0x69, 0x67, 0x66, 0x65, 0x63, 0x5C, 0x5A, 0x59, 0x56,
50 0x55, 0x54, 0x53, 0x52, 0x51, 0x4E, 0x4D, 0x4C, 0x4B, 0x4A,
51 0x49, 0x47, 0x46, 0x45, 0x43, 0x3C, 0x3A, 0x39, 0x36, 0x35,
52 0x34, 0x33, 0x32, 0x31, 0x2E, 0x2D, 0x2C, 0x2B, 0x2A, 0x29,
53 0x27, 0x26, 0x25, 0x23, 0x1F, 0x1E, 0x1D, 0x1B, 0x18, 0x17,
54 0x10, 0x0F, 0x08, 0x04, 0x02, 0x01
55};
56
James Smart2e0fef82007-06-17 19:56:36 -050057static void lpfc_disc_timeout_handler(struct lpfc_vport *);
dea31012005-04-17 16:05:31 -050058
James Smartc01f3202006-08-18 17:47:08 -040059void
60lpfc_terminate_rport_io(struct fc_rport *rport)
dea31012005-04-17 16:05:31 -050061{
James Smartc01f3202006-08-18 17:47:08 -040062 struct lpfc_rport_data *rdata;
63 struct lpfc_nodelist * ndlp;
64 struct lpfc_hba *phba;
dea31012005-04-17 16:05:31 -050065
James Smartc01f3202006-08-18 17:47:08 -040066 rdata = rport->dd_data;
67 ndlp = rdata->pnode;
68
69 if (!ndlp) {
70 if (rport->roles & FC_RPORT_ROLE_FCP_TARGET)
71 printk(KERN_ERR "Cannot find remote node"
72 " to terminate I/O Data x%x\n",
73 rport->port_id);
dea31012005-04-17 16:05:31 -050074 return;
75 }
76
James Smart2e0fef82007-06-17 19:56:36 -050077 phba = ndlp->vport->phba;
James Smart1a169682006-03-07 15:04:06 -050078
James Smartc01f3202006-08-18 17:47:08 -040079 if (ndlp->nlp_sid != NLP_NO_SID) {
80 lpfc_sli_abort_iocb(phba, &phba->sli.ring[phba->sli.fcp_ring],
81 ndlp->nlp_sid, 0, 0, LPFC_CTX_TGT);
82 }
James Smartc01f3202006-08-18 17:47:08 -040083
84 return;
85}
86
87/*
88 * This function will be called when dev_loss_tmo fire.
89 */
90void
91lpfc_dev_loss_tmo_callbk(struct fc_rport *rport)
92{
93 struct lpfc_rport_data *rdata;
94 struct lpfc_nodelist * ndlp;
95 uint8_t *name;
96 int warn_on = 0;
97 struct lpfc_hba *phba;
James Smart2e0fef82007-06-17 19:56:36 -050098 struct lpfc_vport *vport;
James Smartc01f3202006-08-18 17:47:08 -040099
100 rdata = rport->dd_data;
101 ndlp = rdata->pnode;
102
103 if (!ndlp) {
104 if (rport->roles & FC_RPORT_ROLE_FCP_TARGET)
105 printk(KERN_ERR "Cannot find remote node"
106 " for rport in dev_loss_tmo_callbk x%x\n",
107 rport->port_id);
108 return;
109 }
110
James Smart82085712007-04-25 09:52:41 -0400111 if (ndlp->nlp_state == NLP_STE_MAPPED_NODE)
112 return;
113
James Smartc01f3202006-08-18 17:47:08 -0400114 name = (uint8_t *)&ndlp->nlp_portname;
James Smart2e0fef82007-06-17 19:56:36 -0500115 vport = ndlp->vport;
116 phba = vport->phba;
dea31012005-04-17 16:05:31 -0500117
118 if (ndlp->nlp_sid != NLP_NO_SID) {
James.Smart@Emulex.Com6e8215e2005-06-25 10:34:04 -0400119 warn_on = 1;
dea31012005-04-17 16:05:31 -0500120 /* flush the target */
121 lpfc_sli_abort_iocb(phba, &phba->sli.ring[phba->sli.fcp_ring],
122 ndlp->nlp_sid, 0, 0, LPFC_CTX_TGT);
123 }
James Smart2e0fef82007-06-17 19:56:36 -0500124 if (vport->load_flag & FC_UNLOADING)
James Smartc01f3202006-08-18 17:47:08 -0400125 warn_on = 0;
126
James.Smart@Emulex.Com6e8215e2005-06-25 10:34:04 -0400127 if (warn_on) {
128 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
James Smartc01f3202006-08-18 17:47:08 -0400129 "%d:0203 Devloss timeout on "
James Smart488d1462006-03-07 15:02:37 -0500130 "WWPN %x:%x:%x:%x:%x:%x:%x:%x "
131 "NPort x%x Data: x%x x%x x%x\n",
132 phba->brd_no,
133 *name, *(name+1), *(name+2), *(name+3),
134 *(name+4), *(name+5), *(name+6), *(name+7),
135 ndlp->nlp_DID, ndlp->nlp_flag,
James.Smart@Emulex.Com6e8215e2005-06-25 10:34:04 -0400136 ndlp->nlp_state, ndlp->nlp_rpi);
137 } else {
138 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
James Smartc01f3202006-08-18 17:47:08 -0400139 "%d:0204 Devloss timeout on "
James Smart488d1462006-03-07 15:02:37 -0500140 "WWPN %x:%x:%x:%x:%x:%x:%x:%x "
141 "NPort x%x Data: x%x x%x x%x\n",
142 phba->brd_no,
143 *name, *(name+1), *(name+2), *(name+3),
144 *(name+4), *(name+5), *(name+6), *(name+7),
145 ndlp->nlp_DID, ndlp->nlp_flag,
James.Smart@Emulex.Com6e8215e2005-06-25 10:34:04 -0400146 ndlp->nlp_state, ndlp->nlp_rpi);
147 }
148
James Smart2e0fef82007-06-17 19:56:36 -0500149 if (!(vport->load_flag & FC_UNLOADING) &&
James Smart1dcb58e2007-04-25 09:51:30 -0400150 !(ndlp->nlp_flag & NLP_DELAY_TMO) &&
James Smart82085712007-04-25 09:52:41 -0400151 !(ndlp->nlp_flag & NLP_NPR_2B_DISC) &&
152 (ndlp->nlp_state != NLP_STE_UNMAPPED_NODE))
James Smart2e0fef82007-06-17 19:56:36 -0500153 lpfc_disc_state_machine(vport, ndlp, NULL, NLP_EVT_DEVICE_RM);
James Smart1dcb58e2007-04-25 09:51:30 -0400154 else {
155 rdata->pnode = NULL;
156 ndlp->rport = NULL;
James Smart329f9bc2007-04-25 09:53:01 -0400157 lpfc_nlp_put(ndlp);
158 put_device(&rport->dev);
James Smart1dcb58e2007-04-25 09:51:30 -0400159 }
James Smartc01f3202006-08-18 17:47:08 -0400160
dea31012005-04-17 16:05:31 -0500161 return;
162}
163
164static void
James Smart2e0fef82007-06-17 19:56:36 -0500165lpfc_work_list_done(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500166{
167 struct lpfc_work_evt *evtp = NULL;
168 struct lpfc_nodelist *ndlp;
169 int free_evt;
170
James Smart2e0fef82007-06-17 19:56:36 -0500171 spin_lock_irq(&phba->hbalock);
172 while (!list_empty(&phba->work_list)) {
dea31012005-04-17 16:05:31 -0500173 list_remove_head((&phba->work_list), evtp, typeof(*evtp),
174 evt_listp);
James Smart2e0fef82007-06-17 19:56:36 -0500175 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500176 free_evt = 1;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500177 switch (evtp->evt) {
dea31012005-04-17 16:05:31 -0500178 case LPFC_EVT_ELS_RETRY:
James Smart2e0fef82007-06-17 19:56:36 -0500179 ndlp = (struct lpfc_nodelist *) (evtp->evt_arg1);
dea31012005-04-17 16:05:31 -0500180 lpfc_els_retry_delay_handler(ndlp);
181 free_evt = 0;
182 break;
183 case LPFC_EVT_ONLINE:
James Smart2e0fef82007-06-17 19:56:36 -0500184 if (phba->link_state < LPFC_LINK_DOWN)
185 *(int *) (evtp->evt_arg1) = lpfc_online(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500186 else
James Smart2e0fef82007-06-17 19:56:36 -0500187 *(int *) (evtp->evt_arg1) = 0;
dea31012005-04-17 16:05:31 -0500188 complete((struct completion *)(evtp->evt_arg2));
189 break;
James Smart46fa3112007-04-25 09:51:45 -0400190 case LPFC_EVT_OFFLINE_PREP:
James Smart2e0fef82007-06-17 19:56:36 -0500191 if (phba->link_state >= LPFC_LINK_DOWN)
James Smart46fa3112007-04-25 09:51:45 -0400192 lpfc_offline_prep(phba);
193 *(int *)(evtp->evt_arg1) = 0;
194 complete((struct completion *)(evtp->evt_arg2));
195 break;
196 case LPFC_EVT_OFFLINE:
197 lpfc_offline(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500198 lpfc_sli_brdrestart(phba);
199 *(int *)(evtp->evt_arg1) =
James Smart46fa3112007-04-25 09:51:45 -0400200 lpfc_sli_brdready(phba, HS_FFRDY | HS_MBRDY);
201 lpfc_unblock_mgmt_io(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500202 complete((struct completion *)(evtp->evt_arg2));
203 break;
204 case LPFC_EVT_WARM_START:
James Smart46fa3112007-04-25 09:51:45 -0400205 lpfc_offline(phba);
James Smart92908312006-03-07 15:04:13 -0500206 lpfc_reset_barrier(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500207 lpfc_sli_brdreset(phba);
208 lpfc_hba_down_post(phba);
209 *(int *)(evtp->evt_arg1) =
210 lpfc_sli_brdready(phba, HS_MBRDY);
James Smart46fa3112007-04-25 09:51:45 -0400211 lpfc_unblock_mgmt_io(phba);
Jamie Wellnitz41415862006-02-28 19:25:27 -0500212 complete((struct completion *)(evtp->evt_arg2));
213 break;
214 case LPFC_EVT_KILL:
James Smart46fa3112007-04-25 09:51:45 -0400215 lpfc_offline(phba);
James Smart92908312006-03-07 15:04:13 -0500216 *(int *)(evtp->evt_arg1)
James Smart2e0fef82007-06-17 19:56:36 -0500217 = (phba->pport->stopped)
218 ? 0 : lpfc_sli_brdkill(phba);
James Smart46fa3112007-04-25 09:51:45 -0400219 lpfc_unblock_mgmt_io(phba);
dea31012005-04-17 16:05:31 -0500220 complete((struct completion *)(evtp->evt_arg2));
221 break;
222 }
223 if (free_evt)
224 kfree(evtp);
James Smart2e0fef82007-06-17 19:56:36 -0500225 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500226 }
James Smart2e0fef82007-06-17 19:56:36 -0500227 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500228
229}
230
231static void
James Smart2e0fef82007-06-17 19:56:36 -0500232lpfc_work_done(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500233{
234 struct lpfc_sli_ring *pring;
235 int i;
James Smart2e0fef82007-06-17 19:56:36 -0500236 uint32_t ha_copy, control, work_port_events;
237 struct lpfc_vport *vport;
dea31012005-04-17 16:05:31 -0500238
James Smart2e0fef82007-06-17 19:56:36 -0500239 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500240 ha_copy = phba->work_ha;
241 phba->work_ha = 0;
James Smart2e0fef82007-06-17 19:56:36 -0500242 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500243
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500244 if (ha_copy & HA_ERATT)
dea31012005-04-17 16:05:31 -0500245 lpfc_handle_eratt(phba);
246
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500247 if (ha_copy & HA_MBATT)
dea31012005-04-17 16:05:31 -0500248 lpfc_sli_handle_mb_event(phba);
249
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500250 if (ha_copy & HA_LATT)
dea31012005-04-17 16:05:31 -0500251 lpfc_handle_latt(phba);
252
James Smart2e0fef82007-06-17 19:56:36 -0500253 vport = phba->pport;
dea31012005-04-17 16:05:31 -0500254
James Smart2e0fef82007-06-17 19:56:36 -0500255 work_port_events = vport->work_port_events;
dea31012005-04-17 16:05:31 -0500256
James Smart2e0fef82007-06-17 19:56:36 -0500257 if (work_port_events & WORKER_DISC_TMO)
258 lpfc_disc_timeout_handler(vport);
259
260 if (work_port_events & WORKER_ELS_TMO)
261 lpfc_els_timeout_handler(vport);
262
263 if (work_port_events & WORKER_MBOX_TMO)
dea31012005-04-17 16:05:31 -0500264 lpfc_mbox_timeout_handler(phba);
265
James Smart2e0fef82007-06-17 19:56:36 -0500266 if (work_port_events & WORKER_FDMI_TMO)
267 lpfc_fdmi_timeout_handler(vport);
dea31012005-04-17 16:05:31 -0500268
James Smart2e0fef82007-06-17 19:56:36 -0500269 spin_lock_irq(&phba->hbalock);
270 vport->work_port_events &= ~work_port_events;
271 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500272
273 for (i = 0; i < phba->sli.num_rings; i++, ha_copy >>= 4) {
274 pring = &phba->sli.ring[i];
275 if ((ha_copy & HA_RXATT)
276 || (pring->flag & LPFC_DEFERRED_RING_EVENT)) {
277 if (pring->flag & LPFC_STOP_IOCB_MASK) {
278 pring->flag |= LPFC_DEFERRED_RING_EVENT;
279 } else {
280 lpfc_sli_handle_slow_ring_event(phba, pring,
281 (ha_copy &
282 HA_RXMASK));
283 pring->flag &= ~LPFC_DEFERRED_RING_EVENT;
284 }
285 /*
286 * Turn on Ring interrupts
287 */
James Smart2e0fef82007-06-17 19:56:36 -0500288 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500289 control = readl(phba->HCregaddr);
290 control |= (HC_R0INT_ENA << i);
291 writel(control, phba->HCregaddr);
292 readl(phba->HCregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -0500293 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500294 }
295 }
296
James Smart2e0fef82007-06-17 19:56:36 -0500297 lpfc_work_list_done(phba);
dea31012005-04-17 16:05:31 -0500298}
299
300static int
James Smart2e0fef82007-06-17 19:56:36 -0500301check_work_wait_done(struct lpfc_hba *phba)
302{
303 struct lpfc_vport *vport = phba->pport;
304 int rc = 0;
dea31012005-04-17 16:05:31 -0500305
James Smart2e0fef82007-06-17 19:56:36 -0500306
307 if (!vport)
dea31012005-04-17 16:05:31 -0500308 return 0;
James Smart2e0fef82007-06-17 19:56:36 -0500309 spin_lock_irq(&phba->hbalock);
310
311 if (phba->work_ha ||
312 vport->work_port_events ||
313 (!list_empty(&phba->work_list)) ||
314 kthread_should_stop())
315 rc = 1;
316
317 spin_unlock_irq(&phba->hbalock);
318 return rc;
dea31012005-04-17 16:05:31 -0500319}
320
321int
322lpfc_do_work(void *p)
323{
324 struct lpfc_hba *phba = p;
325 int rc;
Peter Zijlstra7259f0d2006-10-29 22:46:36 -0800326 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(work_waitq);
dea31012005-04-17 16:05:31 -0500327
328 set_user_nice(current, -20);
329 phba->work_wait = &work_waitq;
330
331 while (1) {
332
333 rc = wait_event_interruptible(work_waitq,
334 check_work_wait_done(phba));
335 BUG_ON(rc);
336
337 if (kthread_should_stop())
338 break;
339
340 lpfc_work_done(phba);
341
342 }
343 phba->work_wait = NULL;
344 return 0;
345}
346
347/*
348 * This is only called to handle FC worker events. Since this a rare
349 * occurance, we allocate a struct lpfc_work_evt structure here instead of
350 * embedding it in the IOCB.
351 */
352int
James Smart2e0fef82007-06-17 19:56:36 -0500353lpfc_workq_post_event(struct lpfc_hba *phba, void *arg1, void *arg2,
dea31012005-04-17 16:05:31 -0500354 uint32_t evt)
355{
356 struct lpfc_work_evt *evtp;
357
358 /*
359 * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will
360 * be queued to worker thread for processing
361 */
362 evtp = kmalloc(sizeof(struct lpfc_work_evt), GFP_KERNEL);
363 if (!evtp)
364 return 0;
365
366 evtp->evt_arg1 = arg1;
367 evtp->evt_arg2 = arg2;
368 evtp->evt = evt;
369
James Smart2e0fef82007-06-17 19:56:36 -0500370 spin_lock_irq(&phba->hbalock);
James Smart071fbd3d2006-04-15 11:53:20 -0400371 list_add_tail(&evtp->evt_listp, &phba->work_list);
dea31012005-04-17 16:05:31 -0500372 if (phba->work_wait)
373 wake_up(phba->work_wait);
James Smart2e0fef82007-06-17 19:56:36 -0500374 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500375
376 return 1;
377}
378
379int
James Smart685f0bf2007-04-25 09:53:08 -0400380lpfc_linkdown(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500381{
James Smart2e0fef82007-06-17 19:56:36 -0500382 struct lpfc_vport *vport = phba->pport;
383 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
384 struct lpfc_sli *psli;
dea31012005-04-17 16:05:31 -0500385 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart685f0bf2007-04-25 09:53:08 -0400386 LPFC_MBOXQ_t *mb;
387 int rc;
dea31012005-04-17 16:05:31 -0500388
389 psli = &phba->sli;
James Smart2e0fef82007-06-17 19:56:36 -0500390 if (phba->link_state == LPFC_LINK_DOWN) {
391 return 0;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500392 }
James Smart2e0fef82007-06-17 19:56:36 -0500393 spin_lock_irq(&phba->hbalock);
394 if (phba->link_state > LPFC_LINK_DOWN)
395 phba->link_state = LPFC_LINK_DOWN;
396 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500397
James Smart2e0fef82007-06-17 19:56:36 -0500398 fc_host_post_event(shost, fc_get_event_number(), FCH_EVT_LINKDOWN, 0);
James Smartd2873e42006-08-18 17:46:43 -0400399
dea31012005-04-17 16:05:31 -0500400 /* Clean up any firmware default rpi's */
James Smart2e0fef82007-06-17 19:56:36 -0500401 mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
402 if (mb) {
dea31012005-04-17 16:05:31 -0500403 lpfc_unreg_did(phba, 0xffffffff, mb);
James Smart2e0fef82007-06-17 19:56:36 -0500404 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
dea31012005-04-17 16:05:31 -0500405 if (lpfc_sli_issue_mbox(phba, mb, (MBX_NOWAIT | MBX_STOP_IOCB))
406 == MBX_NOT_FINISHED) {
James Smart2e0fef82007-06-17 19:56:36 -0500407 mempool_free(mb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500408 }
409 }
410
411 /* Cleanup any outstanding RSCN activity */
James Smart2e0fef82007-06-17 19:56:36 -0500412 lpfc_els_flush_rscn(vport);
dea31012005-04-17 16:05:31 -0500413
414 /* Cleanup any outstanding ELS commands */
James Smart2e0fef82007-06-17 19:56:36 -0500415 lpfc_els_flush_cmd(vport);
dea31012005-04-17 16:05:31 -0500416
James Smart685f0bf2007-04-25 09:53:08 -0400417 /*
418 * Issue a LINK DOWN event to all nodes.
419 */
James Smart2e0fef82007-06-17 19:56:36 -0500420 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
421 /* free any ndlp's on unused state */
James Smart685f0bf2007-04-25 09:53:08 -0400422 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
James Smart2e0fef82007-06-17 19:56:36 -0500423 lpfc_drop_node(vport, ndlp);
James Smart685f0bf2007-04-25 09:53:08 -0400424 else /* otherwise, force node recovery. */
James Smart2e0fef82007-06-17 19:56:36 -0500425 rc = lpfc_disc_state_machine(vport, ndlp, NULL,
James Smart685f0bf2007-04-25 09:53:08 -0400426 NLP_EVT_DEVICE_RECOVERY);
dea31012005-04-17 16:05:31 -0500427 }
428
dea31012005-04-17 16:05:31 -0500429 /* Setup myDID for link up if we are in pt2pt mode */
James Smart2e0fef82007-06-17 19:56:36 -0500430 if (vport->fc_flag & FC_PT2PT) {
431 vport->fc_myDID = 0;
432 mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
433 if (mb) {
dea31012005-04-17 16:05:31 -0500434 lpfc_config_link(phba, mb);
435 mb->mbox_cmpl=lpfc_sli_def_mbox_cmpl;
James Smart2e0fef82007-06-17 19:56:36 -0500436 if (lpfc_sli_issue_mbox(phba, mb,
437 (MBX_NOWAIT | MBX_STOP_IOCB))
dea31012005-04-17 16:05:31 -0500438 == MBX_NOT_FINISHED) {
James Smart2e0fef82007-06-17 19:56:36 -0500439 mempool_free(mb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500440 }
441 }
James Smart2e0fef82007-06-17 19:56:36 -0500442 spin_lock_irq(shost->host_lock);
443 vport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI);
444 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500445 }
James Smart2e0fef82007-06-17 19:56:36 -0500446
447 spin_lock_irq(shost->host_lock);
448 vport->fc_flag &= ~FC_LBIT;
449 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500450
451 /* Turn off discovery timer if its running */
James Smart2e0fef82007-06-17 19:56:36 -0500452 lpfc_can_disctmo(vport);
dea31012005-04-17 16:05:31 -0500453
454 /* Must process IOCBs on all rings to handle ABORTed I/Os */
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500455 return 0;
dea31012005-04-17 16:05:31 -0500456}
457
458static int
James Smart685f0bf2007-04-25 09:53:08 -0400459lpfc_linkup(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500460{
James Smart2e0fef82007-06-17 19:56:36 -0500461 struct lpfc_vport *vport = phba->pport;
462 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500463 struct lpfc_nodelist *ndlp, *next_ndlp;
464
James Smart2e0fef82007-06-17 19:56:36 -0500465 fc_host_post_event(shost, fc_get_event_number(), FCH_EVT_LINKUP, 0);
James Smartd2873e42006-08-18 17:46:43 -0400466
James Smart2e0fef82007-06-17 19:56:36 -0500467 spin_lock_irq(shost->host_lock);
468 phba->link_state = LPFC_LINK_UP;
469 vport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI | FC_ABORT_DISCOVERY |
470 FC_RSCN_MODE | FC_NLP_MORE | FC_RSCN_DISCOVERY);
471 vport->fc_flag |= FC_NDISC_ACTIVE;
472 vport->fc_ns_retry = 0;
473 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500474
475
James Smart2e0fef82007-06-17 19:56:36 -0500476 if (vport->fc_flag & FC_LBIT) {
477 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smart685f0bf2007-04-25 09:53:08 -0400478 if (ndlp->nlp_state != NLP_STE_UNUSED_NODE) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500479 if (ndlp->nlp_type & NLP_FABRIC) {
James Smart685f0bf2007-04-25 09:53:08 -0400480 /*
481 * On Linkup its safe to clean up the
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500482 * ndlp from Fabric connections.
483 */
James Smart2e0fef82007-06-17 19:56:36 -0500484 lpfc_nlp_set_state(vport, ndlp,
James Smart685f0bf2007-04-25 09:53:08 -0400485 NLP_STE_UNUSED_NODE);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500486 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
James Smart685f0bf2007-04-25 09:53:08 -0400487 /*
488 * Fail outstanding IO now since
489 * device is marked for PLOGI.
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500490 */
James Smart2e0fef82007-06-17 19:56:36 -0500491 lpfc_unreg_rpi(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500492 }
493 }
dea31012005-04-17 16:05:31 -0500494 }
495 }
496
James Smart2e0fef82007-06-17 19:56:36 -0500497 /* free any ndlp's in unused state */
498 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
James Smart685f0bf2007-04-25 09:53:08 -0400499 nlp_listp) {
500 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
James Smart2e0fef82007-06-17 19:56:36 -0500501 lpfc_drop_node(vport, ndlp);
James Smart685f0bf2007-04-25 09:53:08 -0400502 }
dea31012005-04-17 16:05:31 -0500503
504 return 0;
505}
506
507/*
508 * This routine handles processing a CLEAR_LA mailbox
509 * command upon completion. It is setup in the LPFC_MBOXQ
510 * as the completion routine when the command is
511 * handed off to the SLI layer.
512 */
513void
James Smart2e0fef82007-06-17 19:56:36 -0500514lpfc_mbx_cmpl_clear_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -0500515{
James Smart2e0fef82007-06-17 19:56:36 -0500516 struct lpfc_vport *vport = pmb->vport;
517 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
518 struct lpfc_sli *psli = &phba->sli;
519 MAILBOX_t *mb = &pmb->mb;
dea31012005-04-17 16:05:31 -0500520 uint32_t control;
521
dea31012005-04-17 16:05:31 -0500522 /* Since we don't do discovery right now, turn these off here */
James Smarta4bc3372006-12-02 13:34:16 -0500523 psli->ring[psli->extra_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
dea31012005-04-17 16:05:31 -0500524 psli->ring[psli->fcp_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
525 psli->ring[psli->next_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
526
527 /* Check for error */
528 if ((mb->mbxStatus) && (mb->mbxStatus != 0x1601)) {
James Smart2e0fef82007-06-17 19:56:36 -0500529 /* CLEAR_LA mbox error <mbxStatus> state <port_state> */
dea31012005-04-17 16:05:31 -0500530 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
531 "%d:0320 CLEAR_LA mbxStatus error x%x hba "
532 "state x%x\n",
James Smart2e0fef82007-06-17 19:56:36 -0500533 phba->brd_no, mb->mbxStatus, vport->port_state);
dea31012005-04-17 16:05:31 -0500534
James Smart2e0fef82007-06-17 19:56:36 -0500535 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500536 goto out;
537 }
538
James Smart2e0fef82007-06-17 19:56:36 -0500539 if (vport->fc_flag & FC_ABORT_DISCOVERY)
dea31012005-04-17 16:05:31 -0500540 goto out;
541
James Smart2e0fef82007-06-17 19:56:36 -0500542 vport->num_disc_nodes = 0;
543 /* go thru NPR nodes and issue ELS PLOGIs */
544 if (vport->fc_npr_cnt)
545 lpfc_els_disc_plogi(vport);
546
547 if (!vport->num_disc_nodes) {
548 spin_lock_irq(shost->host_lock);
549 vport->fc_flag &= ~FC_NDISC_ACTIVE;
550 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500551 }
552
James Smart2e0fef82007-06-17 19:56:36 -0500553 printk(KERN_ERR "%s (%d): vport ready\n",
554 __FUNCTION__, __LINE__);
555 vport->port_state = LPFC_VPORT_READY;
dea31012005-04-17 16:05:31 -0500556
557out:
558 /* Device Discovery completes */
559 lpfc_printf_log(phba,
560 KERN_INFO,
561 LOG_DISCOVERY,
562 "%d:0225 Device Discovery completes\n",
563 phba->brd_no);
564
James Smart2e0fef82007-06-17 19:56:36 -0500565 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500566
James Smart2e0fef82007-06-17 19:56:36 -0500567 spin_lock_irq(shost->host_lock);
568 vport->fc_flag &= ~(FC_ABORT_DISCOVERY | FC_ESTABLISH_LINK);
569 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500570
571 del_timer_sync(&phba->fc_estabtmo);
572
James Smart2e0fef82007-06-17 19:56:36 -0500573 lpfc_can_disctmo(vport);
dea31012005-04-17 16:05:31 -0500574
575 /* turn on Link Attention interrupts */
James Smart2e0fef82007-06-17 19:56:36 -0500576
577 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500578 psli->sli_flag |= LPFC_PROCESS_LA;
579 control = readl(phba->HCregaddr);
580 control |= HC_LAINT_ENA;
581 writel(control, phba->HCregaddr);
582 readl(phba->HCregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -0500583 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500584
585 return;
586}
587
James Smart2e0fef82007-06-17 19:56:36 -0500588
dea31012005-04-17 16:05:31 -0500589static void
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500590lpfc_mbx_cmpl_local_config_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -0500591{
James Smart2e0fef82007-06-17 19:56:36 -0500592 struct lpfc_vport *vport = pmb->vport;
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500593 struct lpfc_sli *psli = &phba->sli;
594 int rc;
dea31012005-04-17 16:05:31 -0500595
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500596 if (pmb->mb.mbxStatus)
dea31012005-04-17 16:05:31 -0500597 goto out;
dea31012005-04-17 16:05:31 -0500598
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500599 mempool_free(pmb, phba->mbox_mem_pool);
600
601 if (phba->fc_topology == TOPOLOGY_LOOP &&
James Smart2e0fef82007-06-17 19:56:36 -0500602 vport->fc_flag & FC_PUBLIC_LOOP &&
603 !(vport->fc_flag & FC_LBIT)) {
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500604 /* Need to wait for FAN - use discovery timer
James Smart2e0fef82007-06-17 19:56:36 -0500605 * for timeout. port_state is identically
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500606 * LPFC_LOCAL_CFG_LINK while waiting for FAN
607 */
James Smart2e0fef82007-06-17 19:56:36 -0500608 lpfc_set_disctmo(vport);
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500609 return;
dea31012005-04-17 16:05:31 -0500610 }
611
James Smart2e0fef82007-06-17 19:56:36 -0500612 /* Start discovery by sending a FLOGI. port_state is identically
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500613 * LPFC_FLOGI while waiting for FLOGI cmpl
614 */
James Smart2e0fef82007-06-17 19:56:36 -0500615 vport->port_state = LPFC_FLOGI;
616 lpfc_set_disctmo(vport);
617 lpfc_initial_flogi(vport);
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500618 return;
dea31012005-04-17 16:05:31 -0500619
620out:
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500621 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
622 "%d:0306 CONFIG_LINK mbxStatus error x%x "
623 "HBA state x%x\n",
James Smart2e0fef82007-06-17 19:56:36 -0500624 phba->brd_no, pmb->mb.mbxStatus, vport->port_state);
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500625
626 lpfc_linkdown(phba);
627
James Smart2e0fef82007-06-17 19:56:36 -0500628 phba->link_state = LPFC_HBA_ERROR;
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500629
630 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
dea31012005-04-17 16:05:31 -0500631 "%d:0200 CONFIG_LINK bad hba state x%x\n",
James Smart2e0fef82007-06-17 19:56:36 -0500632 phba->brd_no, vport->port_state);
dea31012005-04-17 16:05:31 -0500633
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500634 lpfc_clear_la(phba, pmb);
James Smart2e0fef82007-06-17 19:56:36 -0500635 printk(KERN_ERR "%s (%d): do clear_la\n",
636 __FUNCTION__, __LINE__);
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500637 pmb->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
James Smart2e0fef82007-06-17 19:56:36 -0500638 pmb->vport = vport;
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500639 rc = lpfc_sli_issue_mbox(phba, pmb, (MBX_NOWAIT | MBX_STOP_IOCB));
640 if (rc == MBX_NOT_FINISHED) {
641 mempool_free(pmb, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -0500642 lpfc_disc_flush_list(vport);
James Smarta4bc3372006-12-02 13:34:16 -0500643 psli->ring[(psli->extra_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500644 psli->ring[(psli->fcp_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
645 psli->ring[(psli->next_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
James Smart2e0fef82007-06-17 19:56:36 -0500646 printk(KERN_ERR "%s (%d): vport ready\n",
647 __FUNCTION__, __LINE__);
648 vport->port_state = LPFC_VPORT_READY;
dea31012005-04-17 16:05:31 -0500649 }
650 return;
651}
652
653static void
James Smart2e0fef82007-06-17 19:56:36 -0500654lpfc_mbx_cmpl_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -0500655{
656 struct lpfc_sli *psli = &phba->sli;
657 MAILBOX_t *mb = &pmb->mb;
658 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) pmb->context1;
James Smart2e0fef82007-06-17 19:56:36 -0500659 struct lpfc_vport *vport = pmb->vport;
dea31012005-04-17 16:05:31 -0500660
661
662 /* Check for error */
663 if (mb->mbxStatus) {
664 /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */
665 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
666 "%d:0319 READ_SPARAM mbxStatus error x%x "
667 "hba state x%x>\n",
James Smart2e0fef82007-06-17 19:56:36 -0500668 phba->brd_no, mb->mbxStatus, vport->port_state);
dea31012005-04-17 16:05:31 -0500669
670 lpfc_linkdown(phba);
James Smart2e0fef82007-06-17 19:56:36 -0500671 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500672 goto out;
673 }
674
James Smart2e0fef82007-06-17 19:56:36 -0500675 memcpy((uint8_t *) &vport->fc_sparam, (uint8_t *) mp->virt,
dea31012005-04-17 16:05:31 -0500676 sizeof (struct serv_parm));
James Smarta12e07b2006-12-02 13:35:30 -0500677 if (phba->cfg_soft_wwnn)
James Smart2e0fef82007-06-17 19:56:36 -0500678 u64_to_wwn(phba->cfg_soft_wwnn,
679 vport->fc_sparam.nodeName.u.wwn);
James Smartc3f28af2006-08-18 17:47:18 -0400680 if (phba->cfg_soft_wwpn)
James Smart2e0fef82007-06-17 19:56:36 -0500681 u64_to_wwn(phba->cfg_soft_wwpn,
682 vport->fc_sparam.portName.u.wwn);
683 memcpy((uint8_t *) &vport->fc_nodename,
684 (uint8_t *) &vport->fc_sparam.nodeName,
dea31012005-04-17 16:05:31 -0500685 sizeof (struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -0500686 memcpy((uint8_t *) &vport->fc_portname,
687 (uint8_t *) &vport->fc_sparam.portName,
dea31012005-04-17 16:05:31 -0500688 sizeof (struct lpfc_name));
689 lpfc_mbuf_free(phba, mp->virt, mp->phys);
690 kfree(mp);
James Smart2e0fef82007-06-17 19:56:36 -0500691 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500692 return;
693
694out:
695 pmb->context1 = NULL;
696 lpfc_mbuf_free(phba, mp->virt, mp->phys);
697 kfree(mp);
James Smart2e0fef82007-06-17 19:56:36 -0500698 if (phba->link_state != LPFC_CLEAR_LA) {
699 struct lpfc_sli_ring *extra_ring =
700 &psli->ring[psli->extra_ring];
701 struct lpfc_sli_ring *fcp_ring = &psli->ring[psli->fcp_ring];
702 struct lpfc_sli_ring *next_ring = &psli->ring[psli->next_ring];
703
dea31012005-04-17 16:05:31 -0500704 lpfc_clear_la(phba, pmb);
James Smart2e0fef82007-06-17 19:56:36 -0500705 printk(KERN_ERR "%s (%d): do clear_la\n",
706 __FUNCTION__, __LINE__);
dea31012005-04-17 16:05:31 -0500707 pmb->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
James Smart2e0fef82007-06-17 19:56:36 -0500708 pmb->vport = vport;
dea31012005-04-17 16:05:31 -0500709 if (lpfc_sli_issue_mbox(phba, pmb, (MBX_NOWAIT | MBX_STOP_IOCB))
710 == MBX_NOT_FINISHED) {
James Smart2e0fef82007-06-17 19:56:36 -0500711 mempool_free(pmb, phba->mbox_mem_pool);
712 lpfc_disc_flush_list(vport);
713 extra_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
714 fcp_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
715 next_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
716 printk(KERN_ERR "%s (%d): vport ready\n",
717 __FUNCTION__, __LINE__);
718 vport->port_state = LPFC_VPORT_READY;
dea31012005-04-17 16:05:31 -0500719 }
720 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500721 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500722 }
723 return;
724}
725
726static void
James Smart2e0fef82007-06-17 19:56:36 -0500727lpfc_mbx_process_link_up(struct lpfc_vport *vport, READ_LA_VAR *la)
dea31012005-04-17 16:05:31 -0500728{
James Smart2e0fef82007-06-17 19:56:36 -0500729 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
730 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500731 LPFC_MBOXQ_t *sparam_mbox, *cfglink_mbox;
James Smart2e0fef82007-06-17 19:56:36 -0500732 int i;
James Smart14691152006-12-02 13:34:28 -0500733 struct lpfc_dmabuf *mp;
734 int rc;
735
dea31012005-04-17 16:05:31 -0500736 sparam_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
737 cfglink_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
738
James Smart2e0fef82007-06-17 19:56:36 -0500739 spin_lock_irq(shost->host_lock);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500740 switch (la->UlnkSpeed) {
dea31012005-04-17 16:05:31 -0500741 case LA_1GHZ_LINK:
742 phba->fc_linkspeed = LA_1GHZ_LINK;
743 break;
744 case LA_2GHZ_LINK:
745 phba->fc_linkspeed = LA_2GHZ_LINK;
746 break;
747 case LA_4GHZ_LINK:
748 phba->fc_linkspeed = LA_4GHZ_LINK;
749 break;
James Smartb87eab32007-04-25 09:53:28 -0400750 case LA_8GHZ_LINK:
751 phba->fc_linkspeed = LA_8GHZ_LINK;
752 break;
dea31012005-04-17 16:05:31 -0500753 default:
754 phba->fc_linkspeed = LA_UNKNW_LINK;
755 break;
756 }
757
758 phba->fc_topology = la->topology;
759
760 if (phba->fc_topology == TOPOLOGY_LOOP) {
761 /* Get Loop Map information */
762
763 if (la->il)
James Smart2e0fef82007-06-17 19:56:36 -0500764 vport->fc_flag |= FC_LBIT;
dea31012005-04-17 16:05:31 -0500765
James Smart2e0fef82007-06-17 19:56:36 -0500766 vport->fc_myDID = la->granted_AL_PA;
dea31012005-04-17 16:05:31 -0500767 i = la->un.lilpBde64.tus.f.bdeSize;
768
769 if (i == 0) {
770 phba->alpa_map[0] = 0;
771 } else {
772 if (phba->cfg_log_verbose & LOG_LINK_EVENT) {
773 int numalpa, j, k;
774 union {
775 uint8_t pamap[16];
776 struct {
777 uint32_t wd1;
778 uint32_t wd2;
779 uint32_t wd3;
780 uint32_t wd4;
781 } pa;
782 } un;
783 numalpa = phba->alpa_map[0];
784 j = 0;
785 while (j < numalpa) {
786 memset(un.pamap, 0, 16);
787 for (k = 1; j < numalpa; k++) {
788 un.pamap[k - 1] =
789 phba->alpa_map[j + 1];
790 j++;
791 if (k == 16)
792 break;
793 }
794 /* Link Up Event ALPA map */
795 lpfc_printf_log(phba,
796 KERN_WARNING,
797 LOG_LINK_EVENT,
798 "%d:1304 Link Up Event "
799 "ALPA map Data: x%x "
800 "x%x x%x x%x\n",
801 phba->brd_no,
802 un.pa.wd1, un.pa.wd2,
803 un.pa.wd3, un.pa.wd4);
804 }
805 }
806 }
807 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500808 vport->fc_myDID = phba->fc_pref_DID;
809 vport->fc_flag |= FC_LBIT;
dea31012005-04-17 16:05:31 -0500810 }
James Smart2e0fef82007-06-17 19:56:36 -0500811 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500812
813 lpfc_linkup(phba);
814 if (sparam_mbox) {
815 lpfc_read_sparam(phba, sparam_mbox);
James Smart2e0fef82007-06-17 19:56:36 -0500816 sparam_mbox->vport = vport;
dea31012005-04-17 16:05:31 -0500817 sparam_mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam;
James Smart14691152006-12-02 13:34:28 -0500818 rc = lpfc_sli_issue_mbox(phba, sparam_mbox,
dea31012005-04-17 16:05:31 -0500819 (MBX_NOWAIT | MBX_STOP_IOCB));
James Smart14691152006-12-02 13:34:28 -0500820 if (rc == MBX_NOT_FINISHED) {
821 mp = (struct lpfc_dmabuf *) sparam_mbox->context1;
822 lpfc_mbuf_free(phba, mp->virt, mp->phys);
823 kfree(mp);
824 mempool_free(sparam_mbox, phba->mbox_mem_pool);
825 if (cfglink_mbox)
826 mempool_free(cfglink_mbox, phba->mbox_mem_pool);
827 return;
828 }
dea31012005-04-17 16:05:31 -0500829 }
830
831 if (cfglink_mbox) {
James Smart2e0fef82007-06-17 19:56:36 -0500832 vport->port_state = LPFC_LOCAL_CFG_LINK;
dea31012005-04-17 16:05:31 -0500833 lpfc_config_link(phba, cfglink_mbox);
James Smart2e0fef82007-06-17 19:56:36 -0500834 cfglink_mbox->vport = vport;
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500835 cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
James Smart14691152006-12-02 13:34:28 -0500836 rc = lpfc_sli_issue_mbox(phba, cfglink_mbox,
dea31012005-04-17 16:05:31 -0500837 (MBX_NOWAIT | MBX_STOP_IOCB));
James Smart14691152006-12-02 13:34:28 -0500838 if (rc == MBX_NOT_FINISHED)
839 mempool_free(cfglink_mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500840 }
841}
842
843static void
James Smart2e0fef82007-06-17 19:56:36 -0500844lpfc_mbx_issue_link_down(struct lpfc_hba *phba)
845{
dea31012005-04-17 16:05:31 -0500846 uint32_t control;
847 struct lpfc_sli *psli = &phba->sli;
848
849 lpfc_linkdown(phba);
850
851 /* turn on Link Attention interrupts - no CLEAR_LA needed */
James Smart2e0fef82007-06-17 19:56:36 -0500852 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500853 psli->sli_flag |= LPFC_PROCESS_LA;
854 control = readl(phba->HCregaddr);
855 control |= HC_LAINT_ENA;
856 writel(control, phba->HCregaddr);
857 readl(phba->HCregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -0500858 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500859}
860
861/*
862 * This routine handles processing a READ_LA mailbox
863 * command upon completion. It is setup in the LPFC_MBOXQ
864 * as the completion routine when the command is
865 * handed off to the SLI layer.
866 */
867void
James Smart2e0fef82007-06-17 19:56:36 -0500868lpfc_mbx_cmpl_read_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -0500869{
James Smart2e0fef82007-06-17 19:56:36 -0500870 struct lpfc_vport *vport = pmb->vport;
871 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500872 READ_LA_VAR *la;
873 MAILBOX_t *mb = &pmb->mb;
874 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
875
876 /* Check for error */
877 if (mb->mbxStatus) {
878 lpfc_printf_log(phba,
879 KERN_INFO,
880 LOG_LINK_EVENT,
881 "%d:1307 READ_LA mbox error x%x state x%x\n",
882 phba->brd_no,
James Smart2e0fef82007-06-17 19:56:36 -0500883 mb->mbxStatus, vport->port_state);
dea31012005-04-17 16:05:31 -0500884 lpfc_mbx_issue_link_down(phba);
James Smart2e0fef82007-06-17 19:56:36 -0500885 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500886 goto lpfc_mbx_cmpl_read_la_free_mbuf;
887 }
888
889 la = (READ_LA_VAR *) & pmb->mb.un.varReadLA;
890
891 memcpy(&phba->alpa_map[0], mp->virt, 128);
892
James Smart2e0fef82007-06-17 19:56:36 -0500893 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500894 if (la->pb)
James Smart2e0fef82007-06-17 19:56:36 -0500895 vport->fc_flag |= FC_BYPASSED_MODE;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500896 else
James Smart2e0fef82007-06-17 19:56:36 -0500897 vport->fc_flag &= ~FC_BYPASSED_MODE;
898 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -0500899
dea31012005-04-17 16:05:31 -0500900 if (((phba->fc_eventTag + 1) < la->eventTag) ||
901 (phba->fc_eventTag == la->eventTag)) {
902 phba->fc_stat.LinkMultiEvent++;
James Smart2e0fef82007-06-17 19:56:36 -0500903 if (la->attType == AT_LINK_UP)
dea31012005-04-17 16:05:31 -0500904 if (phba->fc_eventTag != 0)
905 lpfc_linkdown(phba);
906 }
dea31012005-04-17 16:05:31 -0500907
908 phba->fc_eventTag = la->eventTag;
909
910 if (la->attType == AT_LINK_UP) {
911 phba->fc_stat.LinkUp++;
James Smart2e0fef82007-06-17 19:56:36 -0500912 if (phba->link_flag & LS_LOOPBACK_MODE) {
James Smart5b8bd0c2007-04-25 09:52:49 -0400913 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
914 "%d:1306 Link Up Event in loop back mode "
915 "x%x received Data: x%x x%x x%x x%x\n",
916 phba->brd_no, la->eventTag, phba->fc_eventTag,
917 la->granted_AL_PA, la->UlnkSpeed,
918 phba->alpa_map[0]);
919 } else {
920 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
dea31012005-04-17 16:05:31 -0500921 "%d:1303 Link Up Event x%x received "
922 "Data: x%x x%x x%x x%x\n",
923 phba->brd_no, la->eventTag, phba->fc_eventTag,
924 la->granted_AL_PA, la->UlnkSpeed,
925 phba->alpa_map[0]);
James Smart5b8bd0c2007-04-25 09:52:49 -0400926 }
James Smart2e0fef82007-06-17 19:56:36 -0500927 lpfc_mbx_process_link_up(vport, la);
dea31012005-04-17 16:05:31 -0500928 } else {
929 phba->fc_stat.LinkDown++;
930 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
931 "%d:1305 Link Down Event x%x received "
932 "Data: x%x x%x x%x\n",
933 phba->brd_no, la->eventTag, phba->fc_eventTag,
James Smart2e0fef82007-06-17 19:56:36 -0500934 phba->pport->port_state, vport->fc_flag);
dea31012005-04-17 16:05:31 -0500935 lpfc_mbx_issue_link_down(phba);
936 }
937
938lpfc_mbx_cmpl_read_la_free_mbuf:
939 lpfc_mbuf_free(phba, mp->virt, mp->phys);
940 kfree(mp);
941 mempool_free(pmb, phba->mbox_mem_pool);
942 return;
943}
944
945/*
946 * This routine handles processing a REG_LOGIN mailbox
947 * command upon completion. It is setup in the LPFC_MBOXQ
948 * as the completion routine when the command is
949 * handed off to the SLI layer.
950 */
951void
James Smart2e0fef82007-06-17 19:56:36 -0500952lpfc_mbx_cmpl_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -0500953{
James Smart2e0fef82007-06-17 19:56:36 -0500954 struct lpfc_vport *vport = pmb->vport;
955 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) pmb->context1;
956 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
dea31012005-04-17 16:05:31 -0500957
dea31012005-04-17 16:05:31 -0500958
959 pmb->context1 = NULL;
960
961 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -0500962 lpfc_disc_state_machine(vport, ndlp, pmb, NLP_EVT_CMPL_REG_LOGIN);
dea31012005-04-17 16:05:31 -0500963 lpfc_mbuf_free(phba, mp->virt, mp->phys);
964 kfree(mp);
James Smart2e0fef82007-06-17 19:56:36 -0500965 mempool_free(pmb, phba->mbox_mem_pool);
James Smart329f9bc2007-04-25 09:53:01 -0400966 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500967
968 return;
969}
970
971/*
972 * This routine handles processing a Fabric REG_LOGIN mailbox
973 * command upon completion. It is setup in the LPFC_MBOXQ
974 * as the completion routine when the command is
975 * handed off to the SLI layer.
976 */
977void
James Smart2e0fef82007-06-17 19:56:36 -0500978lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -0500979{
James Smart2e0fef82007-06-17 19:56:36 -0500980 struct lpfc_vport *vport = pmb->vport;
981 MAILBOX_t *mb = &pmb->mb;
982 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
983 struct lpfc_nodelist *ndlp, *ndlp_fdmi;
dea31012005-04-17 16:05:31 -0500984 ndlp = (struct lpfc_nodelist *) pmb->context2;
dea31012005-04-17 16:05:31 -0500985
James Smart329f9bc2007-04-25 09:53:01 -0400986 pmb->context1 = NULL;
987 pmb->context2 = NULL;
988
dea31012005-04-17 16:05:31 -0500989 if (mb->mbxStatus) {
990 lpfc_mbuf_free(phba, mp->virt, mp->phys);
991 kfree(mp);
James Smart329f9bc2007-04-25 09:53:01 -0400992 mempool_free(pmb, phba->mbox_mem_pool);
993 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500994
995 /* FLOGI failed, so just use loop map to make discovery list */
James Smart2e0fef82007-06-17 19:56:36 -0500996 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -0500997
998 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500999 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -05001000 return;
1001 }
1002
dea31012005-04-17 16:05:31 -05001003 ndlp->nlp_rpi = mb->un.varWords[0];
dea31012005-04-17 16:05:31 -05001004 ndlp->nlp_type |= NLP_FABRIC;
James Smart2e0fef82007-06-17 19:56:36 -05001005 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
dea31012005-04-17 16:05:31 -05001006
James Smart329f9bc2007-04-25 09:53:01 -04001007 lpfc_nlp_put(ndlp); /* Drop the reference from the mbox */
1008
James Smart2e0fef82007-06-17 19:56:36 -05001009 if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
dea31012005-04-17 16:05:31 -05001010 /* This NPort has been assigned an NPort_ID by the fabric as a
1011 * result of the completed fabric login. Issue a State Change
1012 * Registration (SCR) ELS request to the fabric controller
1013 * (SCR_DID) so that this NPort gets RSCN events from the
1014 * fabric.
1015 */
James Smart2e0fef82007-06-17 19:56:36 -05001016 lpfc_issue_els_scr(vport, SCR_DID, 0);
dea31012005-04-17 16:05:31 -05001017
James Smart2e0fef82007-06-17 19:56:36 -05001018 ndlp = lpfc_findnode_did(vport, NameServer_DID);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001019 if (!ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05001020 /* Allocate a new node instance. If the pool is empty,
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001021 * start the discovery process and skip the Nameserver
1022 * login process. This is attempted again later on.
James Smart2e0fef82007-06-17 19:56:36 -05001023 * Otherwise, issue a Port Login (PLOGI) to
1024 * the NameServer
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001025 */
James Smart2e0fef82007-06-17 19:56:36 -05001026 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001027 if (!ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05001028 lpfc_disc_start(vport);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001029 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1030 kfree(mp);
James Smart329f9bc2007-04-25 09:53:01 -04001031 mempool_free(pmb, phba->mbox_mem_pool);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001032 return;
1033 } else {
James Smart2e0fef82007-06-17 19:56:36 -05001034 lpfc_nlp_init(vport, ndlp, NameServer_DID);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001035 ndlp->nlp_type |= NLP_FABRIC;
1036 }
1037 }
James Smart2e0fef82007-06-17 19:56:36 -05001038
1039 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1040 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001041 if (phba->cfg_fdmi_on) {
1042 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
James Smart2e0fef82007-06-17 19:56:36 -05001043 GFP_KERNEL);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001044 if (ndlp_fdmi) {
James Smart2e0fef82007-06-17 19:56:36 -05001045 lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001046 ndlp_fdmi->nlp_type |= NLP_FABRIC;
1047 ndlp_fdmi->nlp_state = NLP_STE_PLOGI_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001048 lpfc_issue_els_plogi(vport, FDMI_DID, 0);
dea31012005-04-17 16:05:31 -05001049 }
1050 }
1051 }
1052
1053 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1054 kfree(mp);
James Smart329f9bc2007-04-25 09:53:01 -04001055 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05001056 return;
1057}
1058
1059/*
1060 * This routine handles processing a NameServer REG_LOGIN mailbox
1061 * command upon completion. It is setup in the LPFC_MBOXQ
1062 * as the completion routine when the command is
1063 * handed off to the SLI layer.
1064 */
1065void
James Smart2e0fef82007-06-17 19:56:36 -05001066lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05001067{
James Smart2e0fef82007-06-17 19:56:36 -05001068 MAILBOX_t *mb = &pmb->mb;
1069 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
1070 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
1071 struct lpfc_vport *vport = pmb->vport;
dea31012005-04-17 16:05:31 -05001072
1073 if (mb->mbxStatus) {
James Smart329f9bc2007-04-25 09:53:01 -04001074 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001075 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1076 kfree(mp);
James Smartde0c5b32007-04-25 09:52:27 -04001077 mempool_free(pmb, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05001078 lpfc_drop_node(vport, ndlp);
dea31012005-04-17 16:05:31 -05001079
James Smart2e0fef82007-06-17 19:56:36 -05001080 /*
1081 * RegLogin failed, so just use loop map to make discovery
1082 * list
1083 */
1084 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -05001085
1086 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001087 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -05001088 return;
1089 }
1090
1091 pmb->context1 = NULL;
1092
dea31012005-04-17 16:05:31 -05001093 ndlp->nlp_rpi = mb->un.varWords[0];
dea31012005-04-17 16:05:31 -05001094 ndlp->nlp_type |= NLP_FABRIC;
James Smart2e0fef82007-06-17 19:56:36 -05001095 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
dea31012005-04-17 16:05:31 -05001096
James Smart2e0fef82007-06-17 19:56:36 -05001097 if (vport->port_state < LPFC_VPORT_READY) {
1098 /* Link up discovery requires Fabric registration. */
1099 lpfc_ns_cmd(vport, ndlp, SLI_CTNS_RNN_ID);
1100 lpfc_ns_cmd(vport, ndlp, SLI_CTNS_RSNN_NN);
1101 lpfc_ns_cmd(vport, ndlp, SLI_CTNS_RFT_ID);
1102 lpfc_ns_cmd(vport, ndlp, SLI_CTNS_RFF_ID);
dea31012005-04-17 16:05:31 -05001103 }
1104
James Smart2e0fef82007-06-17 19:56:36 -05001105 vport->fc_ns_retry = 0;
dea31012005-04-17 16:05:31 -05001106 /* Good status, issue CT Request to NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05001107 if (lpfc_ns_cmd(vport, ndlp, SLI_CTNS_GID_FT)) {
dea31012005-04-17 16:05:31 -05001108 /* Cannot issue NameServer Query, so finish up discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001109 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -05001110 }
1111
James Smart329f9bc2007-04-25 09:53:01 -04001112 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001113 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1114 kfree(mp);
James Smart2e0fef82007-06-17 19:56:36 -05001115 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05001116
1117 return;
1118}
1119
1120static void
James Smart2e0fef82007-06-17 19:56:36 -05001121lpfc_register_remote_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05001122{
James Smart2e0fef82007-06-17 19:56:36 -05001123 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1124 struct fc_rport *rport;
dea31012005-04-17 16:05:31 -05001125 struct lpfc_rport_data *rdata;
1126 struct fc_rport_identifiers rport_ids;
James Smart2e0fef82007-06-17 19:56:36 -05001127 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001128
1129 /* Remote port has reappeared. Re-register w/ FC transport */
Andrew Morton68ce1eb2005-09-21 09:46:54 -07001130 rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
1131 rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
dea31012005-04-17 16:05:31 -05001132 rport_ids.port_id = ndlp->nlp_DID;
1133 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
dea31012005-04-17 16:05:31 -05001134
James Smart329f9bc2007-04-25 09:53:01 -04001135 /*
1136 * We leave our node pointer in rport->dd_data when we unregister a
1137 * FCP target port. But fc_remote_port_add zeros the space to which
1138 * rport->dd_data points. So, if we're reusing a previously
1139 * registered port, drop the reference that we took the last time we
1140 * registered the port.
1141 */
1142 if (ndlp->rport && ndlp->rport->dd_data &&
1143 *(struct lpfc_rport_data **) ndlp->rport->dd_data) {
1144 lpfc_nlp_put(ndlp);
1145 }
James Smart2e0fef82007-06-17 19:56:36 -05001146 ndlp->rport = rport = fc_remote_port_add(shost, 0, &rport_ids);
James Smart329f9bc2007-04-25 09:53:01 -04001147 if (!rport || !get_device(&rport->dev)) {
dea31012005-04-17 16:05:31 -05001148 dev_printk(KERN_WARNING, &phba->pcidev->dev,
1149 "Warning: fc_remote_port_add failed\n");
1150 return;
1151 }
1152
1153 /* initialize static port data */
1154 rport->maxframe_size = ndlp->nlp_maxframe;
1155 rport->supported_classes = ndlp->nlp_class_sup;
dea31012005-04-17 16:05:31 -05001156 rdata = rport->dd_data;
James Smart329f9bc2007-04-25 09:53:01 -04001157 rdata->pnode = lpfc_nlp_get(ndlp);
James.Smart@Emulex.Com23dc04f2005-11-28 11:41:44 -05001158
1159 if (ndlp->nlp_type & NLP_FCP_TARGET)
1160 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
1161 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
1162 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
1163
1164
1165 if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN)
1166 fc_remote_port_rolechg(rport, rport_ids.roles);
1167
James Smart071fbd3d2006-04-15 11:53:20 -04001168 if ((rport->scsi_target_id != -1) &&
James Smarte17da182006-07-06 15:49:25 -04001169 (rport->scsi_target_id < LPFC_MAX_TARGET)) {
James Smart071fbd3d2006-04-15 11:53:20 -04001170 ndlp->nlp_sid = rport->scsi_target_id;
1171 }
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001172
1173 return;
1174}
1175
1176static void
James Smart2e0fef82007-06-17 19:56:36 -05001177lpfc_unregister_remote_port(struct lpfc_nodelist *ndlp)
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001178{
1179 struct fc_rport *rport = ndlp->rport;
1180 struct lpfc_rport_data *rdata = rport->dd_data;
1181
James Smartc01f3202006-08-18 17:47:08 -04001182 if (rport->scsi_target_id == -1) {
1183 ndlp->rport = NULL;
1184 rdata->pnode = NULL;
James Smart329f9bc2007-04-25 09:53:01 -04001185 lpfc_nlp_put(ndlp);
1186 put_device(&rport->dev);
James Smartc01f3202006-08-18 17:47:08 -04001187 }
1188
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001189 fc_remote_port_delete(rport);
dea31012005-04-17 16:05:31 -05001190
1191 return;
1192}
1193
James Smartde0c5b32007-04-25 09:52:27 -04001194static void
James Smart2e0fef82007-06-17 19:56:36 -05001195lpfc_nlp_counters(struct lpfc_vport *vport, int state, int count)
James Smartde0c5b32007-04-25 09:52:27 -04001196{
James Smart2e0fef82007-06-17 19:56:36 -05001197 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1198
1199 spin_lock_irq(shost->host_lock);
James Smartde0c5b32007-04-25 09:52:27 -04001200 switch (state) {
1201 case NLP_STE_UNUSED_NODE:
James Smart2e0fef82007-06-17 19:56:36 -05001202 vport->fc_unused_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04001203 break;
1204 case NLP_STE_PLOGI_ISSUE:
James Smart2e0fef82007-06-17 19:56:36 -05001205 vport->fc_plogi_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04001206 break;
1207 case NLP_STE_ADISC_ISSUE:
James Smart2e0fef82007-06-17 19:56:36 -05001208 vport->fc_adisc_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04001209 break;
1210 case NLP_STE_REG_LOGIN_ISSUE:
James Smart2e0fef82007-06-17 19:56:36 -05001211 vport->fc_reglogin_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04001212 break;
1213 case NLP_STE_PRLI_ISSUE:
James Smart2e0fef82007-06-17 19:56:36 -05001214 vport->fc_prli_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04001215 break;
1216 case NLP_STE_UNMAPPED_NODE:
James Smart2e0fef82007-06-17 19:56:36 -05001217 vport->fc_unmap_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04001218 break;
1219 case NLP_STE_MAPPED_NODE:
James Smart2e0fef82007-06-17 19:56:36 -05001220 vport->fc_map_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04001221 break;
1222 case NLP_STE_NPR_NODE:
James Smart2e0fef82007-06-17 19:56:36 -05001223 vport->fc_npr_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04001224 break;
1225 }
James Smart2e0fef82007-06-17 19:56:36 -05001226 spin_unlock_irq(shost->host_lock);
James Smartde0c5b32007-04-25 09:52:27 -04001227}
Jamie Wellnitz66a9ed62006-02-28 22:33:10 -05001228
James Smartde0c5b32007-04-25 09:52:27 -04001229static void
James Smart2e0fef82007-06-17 19:56:36 -05001230lpfc_nlp_state_cleanup(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04001231 int old_state, int new_state)
1232{
James Smart2e0fef82007-06-17 19:56:36 -05001233 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1234
James Smartde0c5b32007-04-25 09:52:27 -04001235 if (new_state == NLP_STE_UNMAPPED_NODE) {
1236 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
1237 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
1238 ndlp->nlp_type |= NLP_FC_NODE;
1239 }
1240 if (new_state == NLP_STE_MAPPED_NODE)
1241 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
1242 if (new_state == NLP_STE_NPR_NODE)
1243 ndlp->nlp_flag &= ~NLP_RCV_PLOGI;
dea31012005-04-17 16:05:31 -05001244
James Smartde0c5b32007-04-25 09:52:27 -04001245 /* Transport interface */
1246 if (ndlp->rport && (old_state == NLP_STE_MAPPED_NODE ||
1247 old_state == NLP_STE_UNMAPPED_NODE)) {
James Smart2e0fef82007-06-17 19:56:36 -05001248 vport->phba->nport_event_cnt++;
1249 lpfc_unregister_remote_port(ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04001250 }
dea31012005-04-17 16:05:31 -05001251
James Smartde0c5b32007-04-25 09:52:27 -04001252 if (new_state == NLP_STE_MAPPED_NODE ||
1253 new_state == NLP_STE_UNMAPPED_NODE) {
James Smart2e0fef82007-06-17 19:56:36 -05001254 vport->phba->nport_event_cnt++;
dea31012005-04-17 16:05:31 -05001255 /*
1256 * Tell the fc transport about the port, if we haven't
1257 * already. If we have, and it's a scsi entity, be
1258 * sure to unblock any attached scsi devices
1259 */
James Smart2e0fef82007-06-17 19:56:36 -05001260 lpfc_register_remote_port(vport, ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04001261 }
dea31012005-04-17 16:05:31 -05001262
1263 /*
1264 * if we added to Mapped list, but the remote port
1265 * registration failed or assigned a target id outside
1266 * our presentable range - move the node to the
1267 * Unmapped List
1268 */
James Smartde0c5b32007-04-25 09:52:27 -04001269 if (new_state == NLP_STE_MAPPED_NODE &&
1270 (!ndlp->rport ||
1271 ndlp->rport->scsi_target_id == -1 ||
1272 ndlp->rport->scsi_target_id >= LPFC_MAX_TARGET)) {
James Smart2e0fef82007-06-17 19:56:36 -05001273 spin_lock_irq(shost->host_lock);
James Smartde0c5b32007-04-25 09:52:27 -04001274 ndlp->nlp_flag |= NLP_TGT_NO_SCSIID;
James Smart2e0fef82007-06-17 19:56:36 -05001275 spin_unlock_irq(shost->host_lock);
1276 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
dea31012005-04-17 16:05:31 -05001277 }
James Smartde0c5b32007-04-25 09:52:27 -04001278}
1279
James Smart685f0bf2007-04-25 09:53:08 -04001280static char *
1281lpfc_nlp_state_name(char *buffer, size_t size, int state)
1282{
1283 static char *states[] = {
1284 [NLP_STE_UNUSED_NODE] = "UNUSED",
1285 [NLP_STE_PLOGI_ISSUE] = "PLOGI",
1286 [NLP_STE_ADISC_ISSUE] = "ADISC",
1287 [NLP_STE_REG_LOGIN_ISSUE] = "REGLOGIN",
1288 [NLP_STE_PRLI_ISSUE] = "PRLI",
1289 [NLP_STE_UNMAPPED_NODE] = "UNMAPPED",
1290 [NLP_STE_MAPPED_NODE] = "MAPPED",
1291 [NLP_STE_NPR_NODE] = "NPR",
1292 };
1293
1294 if (state < ARRAY_SIZE(states) && states[state])
1295 strlcpy(buffer, states[state], size);
1296 else
1297 snprintf(buffer, size, "unknown (%d)", state);
1298 return buffer;
1299}
1300
James Smartde0c5b32007-04-25 09:52:27 -04001301void
James Smart2e0fef82007-06-17 19:56:36 -05001302lpfc_nlp_set_state(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1303 int state)
James Smartde0c5b32007-04-25 09:52:27 -04001304{
James Smart2e0fef82007-06-17 19:56:36 -05001305 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smartde0c5b32007-04-25 09:52:27 -04001306 int old_state = ndlp->nlp_state;
James Smart685f0bf2007-04-25 09:53:08 -04001307 char name1[16], name2[16];
James Smartde0c5b32007-04-25 09:52:27 -04001308
James Smart2e0fef82007-06-17 19:56:36 -05001309 lpfc_printf_log(vport->phba, KERN_INFO, LOG_NODE,
James Smart685f0bf2007-04-25 09:53:08 -04001310 "%d:0904 NPort state transition x%06x, %s -> %s\n",
James Smart2e0fef82007-06-17 19:56:36 -05001311 vport->phba->brd_no,
James Smart685f0bf2007-04-25 09:53:08 -04001312 ndlp->nlp_DID,
1313 lpfc_nlp_state_name(name1, sizeof(name1), old_state),
1314 lpfc_nlp_state_name(name2, sizeof(name2), state));
James Smartde0c5b32007-04-25 09:52:27 -04001315 if (old_state == NLP_STE_NPR_NODE &&
1316 (ndlp->nlp_flag & NLP_DELAY_TMO) != 0 &&
1317 state != NLP_STE_NPR_NODE)
James Smart2e0fef82007-06-17 19:56:36 -05001318 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04001319 if (old_state == NLP_STE_UNMAPPED_NODE) {
1320 ndlp->nlp_flag &= ~NLP_TGT_NO_SCSIID;
1321 ndlp->nlp_type &= ~NLP_FC_NODE;
1322 }
1323
James Smart685f0bf2007-04-25 09:53:08 -04001324 if (list_empty(&ndlp->nlp_listp)) {
James Smart2e0fef82007-06-17 19:56:36 -05001325 spin_lock_irq(shost->host_lock);
1326 list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
1327 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04001328 } else if (old_state)
James Smart2e0fef82007-06-17 19:56:36 -05001329 lpfc_nlp_counters(vport, old_state, -1);
James Smartde0c5b32007-04-25 09:52:27 -04001330
1331 ndlp->nlp_state = state;
James Smart2e0fef82007-06-17 19:56:36 -05001332 lpfc_nlp_counters(vport, state, 1);
1333 lpfc_nlp_state_cleanup(vport, ndlp, old_state, state);
James Smartde0c5b32007-04-25 09:52:27 -04001334}
1335
1336void
James Smart2e0fef82007-06-17 19:56:36 -05001337lpfc_dequeue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
James Smartde0c5b32007-04-25 09:52:27 -04001338{
James Smart2e0fef82007-06-17 19:56:36 -05001339 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1340
James Smartde0c5b32007-04-25 09:52:27 -04001341 if ((ndlp->nlp_flag & NLP_DELAY_TMO) != 0)
James Smart2e0fef82007-06-17 19:56:36 -05001342 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04001343 if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
James Smart2e0fef82007-06-17 19:56:36 -05001344 lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
1345 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04001346 list_del_init(&ndlp->nlp_listp);
James Smart2e0fef82007-06-17 19:56:36 -05001347 spin_unlock_irq(shost->host_lock);
1348 lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state, 0);
James Smartde0c5b32007-04-25 09:52:27 -04001349}
1350
1351void
James Smart2e0fef82007-06-17 19:56:36 -05001352lpfc_drop_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
James Smartde0c5b32007-04-25 09:52:27 -04001353{
James Smart2e0fef82007-06-17 19:56:36 -05001354 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1355
James Smartde0c5b32007-04-25 09:52:27 -04001356 if ((ndlp->nlp_flag & NLP_DELAY_TMO) != 0)
James Smart2e0fef82007-06-17 19:56:36 -05001357 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04001358 if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
James Smart2e0fef82007-06-17 19:56:36 -05001359 lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
1360 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04001361 list_del_init(&ndlp->nlp_listp);
James Smart2e0fef82007-06-17 19:56:36 -05001362 spin_unlock_irq(shost->host_lock);
James Smart329f9bc2007-04-25 09:53:01 -04001363 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001364}
1365
1366/*
1367 * Start / ReStart rescue timer for Discovery / RSCN handling
1368 */
1369void
James Smart2e0fef82007-06-17 19:56:36 -05001370lpfc_set_disctmo(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001371{
James Smart2e0fef82007-06-17 19:56:36 -05001372 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1373 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001374 uint32_t tmo;
1375
James Smart2e0fef82007-06-17 19:56:36 -05001376 if (vport->port_state == LPFC_LOCAL_CFG_LINK) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001377 /* For FAN, timeout should be greater then edtov */
1378 tmo = (((phba->fc_edtov + 999) / 1000) + 1);
1379 } else {
1380 /* Normal discovery timeout should be > then ELS/CT timeout
1381 * FC spec states we need 3 * ratov for CT requests
1382 */
1383 tmo = ((phba->fc_ratov * 3) + 3);
1384 }
dea31012005-04-17 16:05:31 -05001385
James Smart2e0fef82007-06-17 19:56:36 -05001386 mod_timer(&vport->fc_disctmo, jiffies + HZ * tmo);
1387 spin_lock_irq(shost->host_lock);
1388 vport->fc_flag |= FC_DISC_TMO;
1389 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001390
1391 /* Start Discovery Timer state <hba_state> */
1392 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1393 "%d:0247 Start Discovery Timer state x%x "
1394 "Data: x%x x%lx x%x x%x\n",
James Smart2e0fef82007-06-17 19:56:36 -05001395 phba->brd_no, vport->port_state, tmo,
1396 (unsigned long)&vport->fc_disctmo, vport->fc_plogi_cnt,
1397 vport->fc_adisc_cnt);
dea31012005-04-17 16:05:31 -05001398
1399 return;
1400}
1401
1402/*
1403 * Cancel rescue timer for Discovery / RSCN handling
1404 */
1405int
James Smart2e0fef82007-06-17 19:56:36 -05001406lpfc_can_disctmo(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001407{
James Smart2e0fef82007-06-17 19:56:36 -05001408 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1409 struct lpfc_hba *phba = vport->phba;
1410 unsigned long iflags;
1411
dea31012005-04-17 16:05:31 -05001412 /* Turn off discovery timer if its running */
James Smart2e0fef82007-06-17 19:56:36 -05001413 if (vport->fc_flag & FC_DISC_TMO) {
1414 spin_lock_irqsave(shost->host_lock, iflags);
1415 vport->fc_flag &= ~FC_DISC_TMO;
1416 spin_unlock_irqrestore(shost->host_lock, iflags);
1417 del_timer_sync(&vport->fc_disctmo);
1418 spin_lock_irqsave(&vport->work_port_lock, iflags);
1419 vport->work_port_events &= ~WORKER_DISC_TMO;
1420 spin_unlock_irqrestore(&vport->work_port_lock, iflags);
dea31012005-04-17 16:05:31 -05001421 }
1422
1423 /* Cancel Discovery Timer state <hba_state> */
1424 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1425 "%d:0248 Cancel Discovery Timer state x%x "
1426 "Data: x%x x%x x%x\n",
James Smart2e0fef82007-06-17 19:56:36 -05001427 phba->brd_no, vport->port_state, vport->fc_flag,
1428 vport->fc_plogi_cnt, vport->fc_adisc_cnt);
dea31012005-04-17 16:05:31 -05001429
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001430 return 0;
dea31012005-04-17 16:05:31 -05001431}
1432
1433/*
1434 * Check specified ring for outstanding IOCB on the SLI queue
1435 * Return true if iocb matches the specified nport
1436 */
1437int
James Smart2e0fef82007-06-17 19:56:36 -05001438lpfc_check_sli_ndlp(struct lpfc_hba *phba,
1439 struct lpfc_sli_ring *pring,
1440 struct lpfc_iocbq *iocb,
1441 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05001442{
James Smart2e0fef82007-06-17 19:56:36 -05001443 struct lpfc_sli *psli = &phba->sli;
1444 IOCB_t *icmd = &iocb->iocb;
dea31012005-04-17 16:05:31 -05001445 if (pring->ringno == LPFC_ELS_RING) {
1446 switch (icmd->ulpCommand) {
1447 case CMD_GEN_REQUEST64_CR:
1448 if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001449 return 1;
dea31012005-04-17 16:05:31 -05001450 case CMD_ELS_REQUEST64_CR:
James Smart10d4e952006-04-15 11:53:15 -04001451 if (icmd->un.elsreq64.remoteID == ndlp->nlp_DID)
1452 return 1;
dea31012005-04-17 16:05:31 -05001453 case CMD_XMIT_ELS_RSP64_CX:
1454 if (iocb->context1 == (uint8_t *) ndlp)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001455 return 1;
dea31012005-04-17 16:05:31 -05001456 }
James Smarta4bc3372006-12-02 13:34:16 -05001457 } else if (pring->ringno == psli->extra_ring) {
dea31012005-04-17 16:05:31 -05001458
1459 } else if (pring->ringno == psli->fcp_ring) {
1460 /* Skip match check if waiting to relogin to FCP target */
1461 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
1462 (ndlp->nlp_flag & NLP_DELAY_TMO)) {
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001463 return 0;
dea31012005-04-17 16:05:31 -05001464 }
1465 if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) {
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001466 return 1;
dea31012005-04-17 16:05:31 -05001467 }
1468 } else if (pring->ringno == psli->next_ring) {
1469
1470 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001471 return 0;
dea31012005-04-17 16:05:31 -05001472}
1473
1474/*
1475 * Free resources / clean up outstanding I/Os
1476 * associated with nlp_rpi in the LPFC_NODELIST entry.
1477 */
1478static int
James Smart2e0fef82007-06-17 19:56:36 -05001479lpfc_no_rpi(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05001480{
James Smart2534ba72007-04-25 09:52:20 -04001481 LIST_HEAD(completions);
dea31012005-04-17 16:05:31 -05001482 struct lpfc_sli *psli;
1483 struct lpfc_sli_ring *pring;
1484 struct lpfc_iocbq *iocb, *next_iocb;
1485 IOCB_t *icmd;
1486 uint32_t rpi, i;
1487
1488 /*
1489 * Everything that matches on txcmplq will be returned
1490 * by firmware with a no rpi error.
1491 */
1492 psli = &phba->sli;
1493 rpi = ndlp->nlp_rpi;
1494 if (rpi) {
1495 /* Now process each ring */
1496 for (i = 0; i < psli->num_rings; i++) {
1497 pring = &psli->ring[i];
1498
James Smart2e0fef82007-06-17 19:56:36 -05001499 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001500 list_for_each_entry_safe(iocb, next_iocb, &pring->txq,
James Smart2e0fef82007-06-17 19:56:36 -05001501 list) {
dea31012005-04-17 16:05:31 -05001502 /*
1503 * Check to see if iocb matches the nport we are
1504 * looking for
1505 */
1506 if ((lpfc_check_sli_ndlp
1507 (phba, pring, iocb, ndlp))) {
1508 /* It matches, so deque and call compl
1509 with an error */
James Smart2534ba72007-04-25 09:52:20 -04001510 list_move_tail(&iocb->list,
1511 &completions);
dea31012005-04-17 16:05:31 -05001512 pring->txq_cnt--;
dea31012005-04-17 16:05:31 -05001513 }
1514 }
James Smart2e0fef82007-06-17 19:56:36 -05001515 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001516 }
1517 }
James Smart2534ba72007-04-25 09:52:20 -04001518
1519 while (!list_empty(&completions)) {
1520 iocb = list_get_first(&completions, struct lpfc_iocbq, list);
1521 list_del(&iocb->list);
1522
James Smart2e0fef82007-06-17 19:56:36 -05001523 if (!iocb->iocb_cmpl)
1524 lpfc_sli_release_iocbq(phba, iocb);
1525 else {
James Smart2534ba72007-04-25 09:52:20 -04001526 icmd = &iocb->iocb;
1527 icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
1528 icmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
James Smart2e0fef82007-06-17 19:56:36 -05001529 (iocb->iocb_cmpl)(phba, iocb, iocb);
1530 }
James Smart2534ba72007-04-25 09:52:20 -04001531 }
1532
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001533 return 0;
dea31012005-04-17 16:05:31 -05001534}
1535
1536/*
1537 * Free rpi associated with LPFC_NODELIST entry.
1538 * This routine is called from lpfc_freenode(), when we are removing
1539 * a LPFC_NODELIST entry. It is also called if the driver initiates a
1540 * LOGO that completes successfully, and we are waiting to PLOGI back
1541 * to the remote NPort. In addition, it is called after we receive
1542 * and unsolicated ELS cmd, send back a rsp, the rsp completes and
1543 * we are waiting to PLOGI back to the remote NPort.
1544 */
1545int
James Smart2e0fef82007-06-17 19:56:36 -05001546lpfc_unreg_rpi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05001547{
James Smart2e0fef82007-06-17 19:56:36 -05001548 struct lpfc_hba *phba = vport->phba;
1549 LPFC_MBOXQ_t *mbox;
dea31012005-04-17 16:05:31 -05001550 int rc;
1551
1552 if (ndlp->nlp_rpi) {
James Smart2e0fef82007-06-17 19:56:36 -05001553 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1554 if (mbox) {
dea31012005-04-17 16:05:31 -05001555 lpfc_unreg_login(phba, ndlp->nlp_rpi, mbox);
1556 mbox->mbox_cmpl=lpfc_sli_def_mbox_cmpl;
1557 rc = lpfc_sli_issue_mbox
1558 (phba, mbox, (MBX_NOWAIT | MBX_STOP_IOCB));
1559 if (rc == MBX_NOT_FINISHED)
James Smart2e0fef82007-06-17 19:56:36 -05001560 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05001561 }
dea31012005-04-17 16:05:31 -05001562 lpfc_no_rpi(phba, ndlp);
1563 ndlp->nlp_rpi = 0;
1564 return 1;
1565 }
1566 return 0;
1567}
1568
1569/*
1570 * Free resources associated with LPFC_NODELIST entry
1571 * so it can be freed.
1572 */
1573static int
James Smart2e0fef82007-06-17 19:56:36 -05001574lpfc_cleanup_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05001575{
James Smart2e0fef82007-06-17 19:56:36 -05001576 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1577 struct lpfc_hba *phba = vport->phba;
1578 LPFC_MBOXQ_t *mb, *nextmb;
dea31012005-04-17 16:05:31 -05001579 struct lpfc_dmabuf *mp;
dea31012005-04-17 16:05:31 -05001580
1581 /* Cleanup node for NPort <nlp_DID> */
1582 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1583 "%d:0900 Cleanup node for NPort x%x "
1584 "Data: x%x x%x x%x\n",
1585 phba->brd_no, ndlp->nlp_DID, ndlp->nlp_flag,
1586 ndlp->nlp_state, ndlp->nlp_rpi);
1587
James Smart2e0fef82007-06-17 19:56:36 -05001588 lpfc_dequeue_node(vport, ndlp);
dea31012005-04-17 16:05:31 -05001589
dea31012005-04-17 16:05:31 -05001590 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
1591 if ((mb = phba->sli.mbox_active)) {
1592 if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
1593 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1594 mb->context2 = NULL;
1595 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1596 }
1597 }
James Smart33ccf8d2006-08-17 11:57:58 -04001598
James Smart2e0fef82007-06-17 19:56:36 -05001599 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001600 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
1601 if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
1602 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1603 mp = (struct lpfc_dmabuf *) (mb->context1);
1604 if (mp) {
James Smart2e0fef82007-06-17 19:56:36 -05001605 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
dea31012005-04-17 16:05:31 -05001606 kfree(mp);
1607 }
1608 list_del(&mb->list);
1609 mempool_free(mb, phba->mbox_mem_pool);
James Smart329f9bc2007-04-25 09:53:01 -04001610 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001611 }
1612 }
James Smart2e0fef82007-06-17 19:56:36 -05001613 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001614
James Smart07951072007-04-25 09:51:38 -04001615 lpfc_els_abort(phba,ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05001616 spin_lock_irq(shost->host_lock);
James Smartc01f3202006-08-18 17:47:08 -04001617 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001618 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001619
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001620 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05001621 del_timer_sync(&ndlp->nlp_delayfunc);
1622
dea31012005-04-17 16:05:31 -05001623 if (!list_empty(&ndlp->els_retry_evt.evt_listp))
1624 list_del_init(&ndlp->els_retry_evt.evt_listp);
1625
James Smart2e0fef82007-06-17 19:56:36 -05001626 lpfc_unreg_rpi(vport, ndlp);
dea31012005-04-17 16:05:31 -05001627
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001628 return 0;
dea31012005-04-17 16:05:31 -05001629}
1630
1631/*
1632 * Check to see if we can free the nlp back to the freelist.
1633 * If we are in the middle of using the nlp in the discovery state
1634 * machine, defer the free till we reach the end of the state machine.
1635 */
James Smart329f9bc2007-04-25 09:53:01 -04001636static void
James Smart2e0fef82007-06-17 19:56:36 -05001637lpfc_nlp_remove(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05001638{
James Smart1dcb58e2007-04-25 09:51:30 -04001639 struct lpfc_rport_data *rdata;
dea31012005-04-17 16:05:31 -05001640
1641 if (ndlp->nlp_flag & NLP_DELAY_TMO) {
James Smart2e0fef82007-06-17 19:56:36 -05001642 lpfc_cancel_retry_delay_tmo(vport, ndlp);
dea31012005-04-17 16:05:31 -05001643 }
1644
James Smart2e0fef82007-06-17 19:56:36 -05001645 lpfc_cleanup_node(vport, ndlp);
James Smart1dcb58e2007-04-25 09:51:30 -04001646
James Smart2e0fef82007-06-17 19:56:36 -05001647 /*
1648 * We should never get here with a non-NULL ndlp->rport. But
1649 * if we do, drop the reference to the rport. That seems the
1650 * intelligent thing to do.
1651 */
1652 if (ndlp->rport && !(vport->load_flag & FC_UNLOADING)) {
James Smart329f9bc2007-04-25 09:53:01 -04001653 put_device(&ndlp->rport->dev);
1654 rdata = ndlp->rport->dd_data;
1655 rdata->pnode = NULL;
1656 ndlp->rport = NULL;
dea31012005-04-17 16:05:31 -05001657 }
dea31012005-04-17 16:05:31 -05001658}
1659
1660static int
James Smart2e0fef82007-06-17 19:56:36 -05001661lpfc_matchdid(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1662 uint32_t did)
dea31012005-04-17 16:05:31 -05001663{
James Smart2e0fef82007-06-17 19:56:36 -05001664 D_ID mydid, ndlpdid, matchdid;
dea31012005-04-17 16:05:31 -05001665
1666 if (did == Bcast_DID)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001667 return 0;
dea31012005-04-17 16:05:31 -05001668
1669 if (ndlp->nlp_DID == 0) {
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001670 return 0;
dea31012005-04-17 16:05:31 -05001671 }
1672
1673 /* First check for Direct match */
1674 if (ndlp->nlp_DID == did)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001675 return 1;
dea31012005-04-17 16:05:31 -05001676
1677 /* Next check for area/domain identically equals 0 match */
James Smart2e0fef82007-06-17 19:56:36 -05001678 mydid.un.word = vport->fc_myDID;
dea31012005-04-17 16:05:31 -05001679 if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) {
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001680 return 0;
dea31012005-04-17 16:05:31 -05001681 }
1682
1683 matchdid.un.word = did;
1684 ndlpdid.un.word = ndlp->nlp_DID;
1685 if (matchdid.un.b.id == ndlpdid.un.b.id) {
1686 if ((mydid.un.b.domain == matchdid.un.b.domain) &&
1687 (mydid.un.b.area == matchdid.un.b.area)) {
1688 if ((ndlpdid.un.b.domain == 0) &&
1689 (ndlpdid.un.b.area == 0)) {
1690 if (ndlpdid.un.b.id)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001691 return 1;
dea31012005-04-17 16:05:31 -05001692 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001693 return 0;
dea31012005-04-17 16:05:31 -05001694 }
1695
1696 matchdid.un.word = ndlp->nlp_DID;
1697 if ((mydid.un.b.domain == ndlpdid.un.b.domain) &&
1698 (mydid.un.b.area == ndlpdid.un.b.area)) {
1699 if ((matchdid.un.b.domain == 0) &&
1700 (matchdid.un.b.area == 0)) {
1701 if (matchdid.un.b.id)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001702 return 1;
dea31012005-04-17 16:05:31 -05001703 }
1704 }
1705 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001706 return 0;
dea31012005-04-17 16:05:31 -05001707}
1708
James Smart685f0bf2007-04-25 09:53:08 -04001709/* Search for a nodelist entry */
James Smart2e0fef82007-06-17 19:56:36 -05001710static struct lpfc_nodelist *
1711__lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05001712{
James Smart2e0fef82007-06-17 19:56:36 -05001713 struct lpfc_hba *phba = vport->phba;
James Smart2fb9bd82006-12-02 13:33:57 -05001714 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05001715 uint32_t data1;
1716
James Smart2e0fef82007-06-17 19:56:36 -05001717 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
1718 if (lpfc_matchdid(vport, ndlp, did)) {
James Smart685f0bf2007-04-25 09:53:08 -04001719 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1720 ((uint32_t) ndlp->nlp_xri << 16) |
1721 ((uint32_t) ndlp->nlp_type << 8) |
1722 ((uint32_t) ndlp->nlp_rpi & 0xff));
1723 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1724 "%d:0929 FIND node DID "
1725 " Data: x%p x%x x%x x%x\n",
1726 phba->brd_no,
1727 ndlp, ndlp->nlp_DID,
1728 ndlp->nlp_flag, data1);
James Smart685f0bf2007-04-25 09:53:08 -04001729 return ndlp;
dea31012005-04-17 16:05:31 -05001730 }
1731 }
Jamie Wellnitz66a9ed62006-02-28 22:33:10 -05001732
dea31012005-04-17 16:05:31 -05001733 /* FIND node did <did> NOT FOUND */
James Smart2fb9bd82006-12-02 13:33:57 -05001734 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
James Smart685f0bf2007-04-25 09:53:08 -04001735 "%d:0932 FIND node did x%x NOT FOUND.\n",
1736 phba->brd_no, did);
dea31012005-04-17 16:05:31 -05001737 return NULL;
1738}
1739
1740struct lpfc_nodelist *
James Smart2e0fef82007-06-17 19:56:36 -05001741lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05001742{
James Smart2e0fef82007-06-17 19:56:36 -05001743 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001744 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05001745
James Smart2e0fef82007-06-17 19:56:36 -05001746 spin_lock_irq(shost->host_lock);
1747 ndlp = __lpfc_findnode_did(vport, did);
1748 spin_unlock_irq(shost->host_lock);
1749 return ndlp;
1750}
1751
1752struct lpfc_nodelist *
1753lpfc_setup_disc_node(struct lpfc_vport *vport, uint32_t did)
1754{
1755 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1756 struct lpfc_nodelist *ndlp;
1757
1758 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001759 if (!ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05001760 if ((vport->fc_flag & FC_RSCN_MODE) != 0 &&
1761 lpfc_rscn_payload_check(vport, did) == 0)
dea31012005-04-17 16:05:31 -05001762 return NULL;
1763 ndlp = (struct lpfc_nodelist *)
James Smart2e0fef82007-06-17 19:56:36 -05001764 mempool_alloc(vport->phba->nlp_mem_pool, GFP_KERNEL);
dea31012005-04-17 16:05:31 -05001765 if (!ndlp)
1766 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05001767 lpfc_nlp_init(vport, ndlp, did);
1768 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1769 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001770 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001771 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001772 return ndlp;
1773 }
James Smart2e0fef82007-06-17 19:56:36 -05001774 if (vport->fc_flag & FC_RSCN_MODE) {
1775 if (lpfc_rscn_payload_check(vport, did)) {
1776 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001777 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001778 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05001779
1780 /* Since this node is marked for discovery,
1781 * delay timeout is not needed.
1782 */
James Smartfdcebe22006-03-07 15:04:01 -05001783 if (ndlp->nlp_flag & NLP_DELAY_TMO)
James Smart2e0fef82007-06-17 19:56:36 -05001784 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smart071fbd3d2006-04-15 11:53:20 -04001785 } else
dea31012005-04-17 16:05:31 -05001786 ndlp = NULL;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001787 } else {
James Smart685f0bf2007-04-25 09:53:08 -04001788 if (ndlp->nlp_state == NLP_STE_ADISC_ISSUE ||
1789 ndlp->nlp_state == NLP_STE_PLOGI_ISSUE)
dea31012005-04-17 16:05:31 -05001790 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05001791 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1792 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001793 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001794 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001795 }
1796 return ndlp;
1797}
1798
1799/* Build a list of nodes to discover based on the loopmap */
1800void
James Smart2e0fef82007-06-17 19:56:36 -05001801lpfc_disc_list_loopmap(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001802{
James Smart2e0fef82007-06-17 19:56:36 -05001803 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001804 int j;
1805 uint32_t alpa, index;
1806
James Smart2e0fef82007-06-17 19:56:36 -05001807 if (!lpfc_is_link_up(phba))
dea31012005-04-17 16:05:31 -05001808 return;
James Smart2e0fef82007-06-17 19:56:36 -05001809
1810 if (phba->fc_topology != TOPOLOGY_LOOP)
dea31012005-04-17 16:05:31 -05001811 return;
dea31012005-04-17 16:05:31 -05001812
1813 /* Check for loop map present or not */
1814 if (phba->alpa_map[0]) {
1815 for (j = 1; j <= phba->alpa_map[0]; j++) {
1816 alpa = phba->alpa_map[j];
James Smart2e0fef82007-06-17 19:56:36 -05001817 if (((vport->fc_myDID & 0xff) == alpa) || (alpa == 0))
dea31012005-04-17 16:05:31 -05001818 continue;
James Smart2e0fef82007-06-17 19:56:36 -05001819 lpfc_setup_disc_node(vport, alpa);
dea31012005-04-17 16:05:31 -05001820 }
1821 } else {
1822 /* No alpamap, so try all alpa's */
1823 for (j = 0; j < FC_MAXLOOP; j++) {
1824 /* If cfg_scan_down is set, start from highest
1825 * ALPA (0xef) to lowest (0x1).
1826 */
1827 if (phba->cfg_scan_down)
1828 index = j;
1829 else
1830 index = FC_MAXLOOP - j - 1;
1831 alpa = lpfcAlpaArray[index];
James Smart2e0fef82007-06-17 19:56:36 -05001832 if ((vport->fc_myDID & 0xff) == alpa)
dea31012005-04-17 16:05:31 -05001833 continue;
James Smart2e0fef82007-06-17 19:56:36 -05001834 lpfc_setup_disc_node(vport, alpa);
dea31012005-04-17 16:05:31 -05001835 }
1836 }
1837 return;
1838}
1839
dea31012005-04-17 16:05:31 -05001840void
James Smart2e0fef82007-06-17 19:56:36 -05001841lpfc_issue_clear_la(struct lpfc_hba *phba, struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001842{
dea31012005-04-17 16:05:31 -05001843 LPFC_MBOXQ_t *mbox;
James Smart2e0fef82007-06-17 19:56:36 -05001844 struct lpfc_sli *psli = &phba->sli;
1845 struct lpfc_sli_ring *extra_ring = &psli->ring[psli->extra_ring];
1846 struct lpfc_sli_ring *fcp_ring = &psli->ring[psli->fcp_ring];
1847 struct lpfc_sli_ring *next_ring = &psli->ring[psli->next_ring];
1848 int rc;
1849
1850 /* Link up discovery */
1851 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL)) != NULL) {
1852 phba->link_state = LPFC_CLEAR_LA;
1853 lpfc_clear_la(phba, mbox);
1854 mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
1855 mbox->vport = vport;
1856 rc = lpfc_sli_issue_mbox(phba, mbox, (MBX_NOWAIT |
1857 MBX_STOP_IOCB));
1858 if (rc == MBX_NOT_FINISHED) {
1859 mempool_free(mbox, phba->mbox_mem_pool);
1860 lpfc_disc_flush_list(vport);
1861 extra_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
1862 fcp_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
1863 next_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
1864 vport->port_state = LPFC_VPORT_READY;
1865 }
1866 }
1867}
1868
1869/* Start Link up / RSCN discovery on NPR nodes */
1870void
1871lpfc_disc_start(struct lpfc_vport *vport)
1872{
1873 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1874 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001875 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart685f0bf2007-04-25 09:53:08 -04001876 uint32_t num_sent;
dea31012005-04-17 16:05:31 -05001877 uint32_t clear_la_pending;
James Smart685f0bf2007-04-25 09:53:08 -04001878 int did_changed;
dea31012005-04-17 16:05:31 -05001879
James Smart2e0fef82007-06-17 19:56:36 -05001880 if (!lpfc_is_link_up(phba))
dea31012005-04-17 16:05:31 -05001881 return;
James Smart2e0fef82007-06-17 19:56:36 -05001882
1883 if (phba->link_state == LPFC_CLEAR_LA)
dea31012005-04-17 16:05:31 -05001884 clear_la_pending = 1;
1885 else
1886 clear_la_pending = 0;
1887
James Smart2e0fef82007-06-17 19:56:36 -05001888 if (vport->port_state < LPFC_VPORT_READY)
1889 vport->port_state = LPFC_DISC_AUTH;
dea31012005-04-17 16:05:31 -05001890
James Smart2e0fef82007-06-17 19:56:36 -05001891 lpfc_set_disctmo(vport);
1892
1893 if (vport->fc_prevDID == vport->fc_myDID)
dea31012005-04-17 16:05:31 -05001894 did_changed = 0;
James Smart2e0fef82007-06-17 19:56:36 -05001895 else
dea31012005-04-17 16:05:31 -05001896 did_changed = 1;
James Smart2e0fef82007-06-17 19:56:36 -05001897
1898 vport->fc_prevDID = vport->fc_myDID;
1899 vport->num_disc_nodes = 0;
dea31012005-04-17 16:05:31 -05001900
1901 /* Start Discovery state <hba_state> */
1902 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1903 "%d:0202 Start Discovery hba state x%x "
1904 "Data: x%x x%x x%x\n",
James Smart2e0fef82007-06-17 19:56:36 -05001905 phba->brd_no, vport->port_state, vport->fc_flag,
1906 vport->fc_plogi_cnt, vport->fc_adisc_cnt);
dea31012005-04-17 16:05:31 -05001907
1908 /* If our did changed, we MUST do PLOGI */
James Smart2e0fef82007-06-17 19:56:36 -05001909 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smart685f0bf2007-04-25 09:53:08 -04001910 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
1911 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
1912 did_changed) {
James Smart2e0fef82007-06-17 19:56:36 -05001913 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04001914 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05001915 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001916 }
1917 }
1918
1919 /* First do ADISCs - if any */
James Smart2e0fef82007-06-17 19:56:36 -05001920 num_sent = lpfc_els_disc_adisc(vport);
dea31012005-04-17 16:05:31 -05001921
1922 if (num_sent)
1923 return;
1924
James Smart2e0fef82007-06-17 19:56:36 -05001925 if (vport->port_state < LPFC_VPORT_READY && !clear_la_pending) {
1926 if (vport->port_type == LPFC_PHYSICAL_PORT) {
dea31012005-04-17 16:05:31 -05001927 /* If we get here, there is nothing to ADISC */
James Smart2e0fef82007-06-17 19:56:36 -05001928 printk(KERN_ERR "%s (%d): do clear_la\n",
1929 __FUNCTION__, __LINE__);
1930 lpfc_issue_clear_la(phba, vport);
1931 } else if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
1932
1933 vport->num_disc_nodes = 0;
1934 /* go thru NPR nodes and issue ELS PLOGIs */
1935 if (vport->fc_npr_cnt)
1936 lpfc_els_disc_plogi(vport);
1937
1938 if (!vport->num_disc_nodes) {
1939 spin_lock_irq(shost->host_lock);
1940 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1941 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001942 }
James Smart2e0fef82007-06-17 19:56:36 -05001943 printk(KERN_ERR "%s (%d): vport ready\n",
1944 __FUNCTION__, __LINE__);
1945 vport->port_state = LPFC_VPORT_READY;
dea31012005-04-17 16:05:31 -05001946 }
1947 } else {
1948 /* Next do PLOGIs - if any */
James Smart2e0fef82007-06-17 19:56:36 -05001949 num_sent = lpfc_els_disc_plogi(vport);
dea31012005-04-17 16:05:31 -05001950
1951 if (num_sent)
1952 return;
1953
James Smart2e0fef82007-06-17 19:56:36 -05001954 if (vport->fc_flag & FC_RSCN_MODE) {
dea31012005-04-17 16:05:31 -05001955 /* Check to see if more RSCNs came in while we
1956 * were processing this one.
1957 */
James Smart2e0fef82007-06-17 19:56:36 -05001958 if ((vport->fc_rscn_id_cnt == 0) &&
1959 (!(vport->fc_flag & FC_RSCN_DISCOVERY))) {
1960 spin_lock_irq(shost->host_lock);
1961 vport->fc_flag &= ~FC_RSCN_MODE;
1962 spin_unlock_irq(shost->host_lock);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001963 } else
James Smart2e0fef82007-06-17 19:56:36 -05001964 lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05001965 }
1966 }
1967 return;
1968}
1969
1970/*
1971 * Ignore completion for all IOCBs on tx and txcmpl queue for ELS
1972 * ring the match the sppecified nodelist.
1973 */
1974static void
James Smart2e0fef82007-06-17 19:56:36 -05001975lpfc_free_tx(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05001976{
James Smart2534ba72007-04-25 09:52:20 -04001977 LIST_HEAD(completions);
dea31012005-04-17 16:05:31 -05001978 struct lpfc_sli *psli;
1979 IOCB_t *icmd;
1980 struct lpfc_iocbq *iocb, *next_iocb;
1981 struct lpfc_sli_ring *pring;
dea31012005-04-17 16:05:31 -05001982
1983 psli = &phba->sli;
1984 pring = &psli->ring[LPFC_ELS_RING];
1985
1986 /* Error matching iocb on txq or txcmplq
1987 * First check the txq.
1988 */
James Smart2e0fef82007-06-17 19:56:36 -05001989 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001990 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
1991 if (iocb->context1 != ndlp) {
1992 continue;
1993 }
1994 icmd = &iocb->iocb;
1995 if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
1996 (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
1997
James Smart2534ba72007-04-25 09:52:20 -04001998 list_move_tail(&iocb->list, &completions);
dea31012005-04-17 16:05:31 -05001999 pring->txq_cnt--;
dea31012005-04-17 16:05:31 -05002000 }
2001 }
2002
2003 /* Next check the txcmplq */
2004 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
2005 if (iocb->context1 != ndlp) {
2006 continue;
2007 }
2008 icmd = &iocb->iocb;
James Smart2e0fef82007-06-17 19:56:36 -05002009 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR ||
2010 icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX) {
James Smart2534ba72007-04-25 09:52:20 -04002011 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
dea31012005-04-17 16:05:31 -05002012 }
2013 }
James Smart2e0fef82007-06-17 19:56:36 -05002014 spin_unlock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04002015
2016 while (!list_empty(&completions)) {
2017 iocb = list_get_first(&completions, struct lpfc_iocbq, list);
2018 list_del(&iocb->list);
2019
James Smart2e0fef82007-06-17 19:56:36 -05002020 if (!iocb->iocb_cmpl)
2021 lpfc_sli_release_iocbq(phba, iocb);
2022 else {
James Smart2534ba72007-04-25 09:52:20 -04002023 icmd = &iocb->iocb;
2024 icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
2025 icmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
2026 (iocb->iocb_cmpl) (phba, iocb, iocb);
James Smart2e0fef82007-06-17 19:56:36 -05002027 }
James Smart2534ba72007-04-25 09:52:20 -04002028 }
dea31012005-04-17 16:05:31 -05002029}
2030
2031void
James Smart2e0fef82007-06-17 19:56:36 -05002032lpfc_disc_flush_list(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002033{
2034 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05002035 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002036
James Smart2e0fef82007-06-17 19:56:36 -05002037 if (vport->fc_plogi_cnt || vport->fc_adisc_cnt) {
2038 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
James Smart685f0bf2007-04-25 09:53:08 -04002039 nlp_listp) {
2040 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
2041 ndlp->nlp_state == NLP_STE_ADISC_ISSUE) {
2042 lpfc_free_tx(phba, ndlp);
2043 lpfc_nlp_put(ndlp);
2044 }
dea31012005-04-17 16:05:31 -05002045 }
2046 }
dea31012005-04-17 16:05:31 -05002047}
2048
2049/*****************************************************************************/
2050/*
2051 * NAME: lpfc_disc_timeout
2052 *
2053 * FUNCTION: Fibre Channel driver discovery timeout routine.
2054 *
2055 * EXECUTION ENVIRONMENT: interrupt only
2056 *
2057 * CALLED FROM:
2058 * Timer function
2059 *
2060 * RETURNS:
2061 * none
2062 */
2063/*****************************************************************************/
2064void
2065lpfc_disc_timeout(unsigned long ptr)
2066{
James Smart2e0fef82007-06-17 19:56:36 -05002067 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
2068 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002069 unsigned long flags = 0;
2070
2071 if (unlikely(!phba))
2072 return;
2073
James Smart2e0fef82007-06-17 19:56:36 -05002074 if ((vport->work_port_events & WORKER_DISC_TMO) == 0) {
2075 spin_lock_irqsave(&vport->work_port_lock, flags);
2076 vport->work_port_events |= WORKER_DISC_TMO;
2077 spin_unlock_irqrestore(&vport->work_port_lock, flags);
2078
dea31012005-04-17 16:05:31 -05002079 if (phba->work_wait)
2080 wake_up(phba->work_wait);
2081 }
dea31012005-04-17 16:05:31 -05002082 return;
2083}
2084
2085static void
James Smart2e0fef82007-06-17 19:56:36 -05002086lpfc_disc_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002087{
James Smart2e0fef82007-06-17 19:56:36 -05002088 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2089 struct lpfc_hba *phba = vport->phba;
2090 struct lpfc_sli *psli = &phba->sli;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002091 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05002092 LPFC_MBOXQ_t *clearlambox, *initlinkmbox;
dea31012005-04-17 16:05:31 -05002093 int rc, clrlaerr = 0;
2094
James Smart2e0fef82007-06-17 19:56:36 -05002095 if (!(vport->fc_flag & FC_DISC_TMO))
dea31012005-04-17 16:05:31 -05002096 return;
2097
dea31012005-04-17 16:05:31 -05002098
James Smart2e0fef82007-06-17 19:56:36 -05002099 spin_lock_irq(shost->host_lock);
2100 vport->fc_flag &= ~FC_DISC_TMO;
2101 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002102
James Smart2e0fef82007-06-17 19:56:36 -05002103 printk(KERN_ERR "%s (%d): link_state = %d, port_state = %d\n",
2104 __FUNCTION__, __LINE__, phba->link_state, vport->port_state);
2105 switch (vport->port_state) {
dea31012005-04-17 16:05:31 -05002106
2107 case LPFC_LOCAL_CFG_LINK:
James Smart2e0fef82007-06-17 19:56:36 -05002108 /* port_state is identically LPFC_LOCAL_CFG_LINK while waiting for
2109 * FAN
2110 */
2111 /* FAN timeout */
dea31012005-04-17 16:05:31 -05002112 lpfc_printf_log(phba,
2113 KERN_WARNING,
2114 LOG_DISCOVERY,
2115 "%d:0221 FAN timeout\n",
2116 phba->brd_no);
2117
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002118 /* Start discovery by sending FLOGI, clean up old rpis */
James Smart2e0fef82007-06-17 19:56:36 -05002119 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
James Smart685f0bf2007-04-25 09:53:08 -04002120 nlp_listp) {
2121 if (ndlp->nlp_state != NLP_STE_NPR_NODE)
2122 continue;
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002123 if (ndlp->nlp_type & NLP_FABRIC) {
2124 /* Clean up the ndlp on Fabric connections */
James Smart2e0fef82007-06-17 19:56:36 -05002125 lpfc_drop_node(vport, ndlp);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002126 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002127 /* Fail outstanding IO now since device
2128 * is marked for PLOGI.
2129 */
James Smart2e0fef82007-06-17 19:56:36 -05002130 lpfc_unreg_rpi(vport, ndlp);
Jamie Wellnitzc9f87352006-02-28 19:25:23 -05002131 }
2132 }
James Smart2e0fef82007-06-17 19:56:36 -05002133 vport->port_state = LPFC_FLOGI;
2134 lpfc_set_disctmo(vport);
2135 lpfc_initial_flogi(vport);
dea31012005-04-17 16:05:31 -05002136 break;
2137
2138 case LPFC_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002139 /* port_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */
dea31012005-04-17 16:05:31 -05002140 /* Initial FLOGI timeout */
2141 lpfc_printf_log(phba,
2142 KERN_ERR,
2143 LOG_DISCOVERY,
2144 "%d:0222 Initial FLOGI timeout\n",
2145 phba->brd_no);
2146
2147 /* Assume no Fabric and go on with discovery.
2148 * Check for outstanding ELS FLOGI to abort.
2149 */
2150
2151 /* FLOGI failed, so just use loop map to make discovery list */
James Smart2e0fef82007-06-17 19:56:36 -05002152 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -05002153
2154 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002155 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -05002156 break;
2157
2158 case LPFC_FABRIC_CFG_LINK:
2159 /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for
2160 NameServer login */
2161 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2162 "%d:0223 Timeout while waiting for NameServer "
2163 "login\n", phba->brd_no);
2164
2165 /* Next look for NameServer ndlp */
James Smart2e0fef82007-06-17 19:56:36 -05002166 ndlp = lpfc_findnode_did(vport, NameServer_DID);
dea31012005-04-17 16:05:31 -05002167 if (ndlp)
James Smart329f9bc2007-04-25 09:53:01 -04002168 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002169 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002170 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -05002171 break;
2172
2173 case LPFC_NS_QRY:
2174 /* Check for wait for NameServer Rsp timeout */
2175 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2176 "%d:0224 NameServer Query timeout "
2177 "Data: x%x x%x\n",
2178 phba->brd_no,
James Smart2e0fef82007-06-17 19:56:36 -05002179 vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
dea31012005-04-17 16:05:31 -05002180
James Smart2e0fef82007-06-17 19:56:36 -05002181 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smart685f0bf2007-04-25 09:53:08 -04002182 if (ndlp && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
James Smart2e0fef82007-06-17 19:56:36 -05002183 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
dea31012005-04-17 16:05:31 -05002184 /* Try it one more time */
James Smart2e0fef82007-06-17 19:56:36 -05002185 rc = lpfc_ns_cmd(vport, ndlp, SLI_CTNS_GID_FT);
dea31012005-04-17 16:05:31 -05002186 if (rc == 0)
2187 break;
2188 }
James Smart2e0fef82007-06-17 19:56:36 -05002189 vport->fc_ns_retry = 0;
dea31012005-04-17 16:05:31 -05002190 }
2191
2192 /* Nothing to authenticate, so CLEAR_LA right now */
2193 clearlambox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2194 if (!clearlambox) {
2195 clrlaerr = 1;
2196 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2197 "%d:0226 Device Discovery "
2198 "completion error\n",
2199 phba->brd_no);
James Smart2e0fef82007-06-17 19:56:36 -05002200 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05002201 break;
2202 }
2203
James Smart2e0fef82007-06-17 19:56:36 -05002204 phba->link_state = LPFC_CLEAR_LA;
dea31012005-04-17 16:05:31 -05002205 lpfc_clear_la(phba, clearlambox);
James Smart2e0fef82007-06-17 19:56:36 -05002206 printk(KERN_ERR "%s (%d): do clear_la\n",
2207 __FUNCTION__, __LINE__);
dea31012005-04-17 16:05:31 -05002208 clearlambox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
James Smart2e0fef82007-06-17 19:56:36 -05002209 clearlambox->vport = vport;
dea31012005-04-17 16:05:31 -05002210 rc = lpfc_sli_issue_mbox(phba, clearlambox,
2211 (MBX_NOWAIT | MBX_STOP_IOCB));
2212 if (rc == MBX_NOT_FINISHED) {
2213 mempool_free(clearlambox, phba->mbox_mem_pool);
2214 clrlaerr = 1;
2215 break;
2216 }
2217
2218 /* Setup and issue mailbox INITIALIZE LINK command */
2219 initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2220 if (!initlinkmbox) {
2221 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
James Smartdca94792006-08-01 07:34:08 -04002222 "%d:0206 Device Discovery "
dea31012005-04-17 16:05:31 -05002223 "completion error\n",
2224 phba->brd_no);
James Smart2e0fef82007-06-17 19:56:36 -05002225 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05002226 break;
2227 }
2228
2229 lpfc_linkdown(phba);
2230 lpfc_init_link(phba, initlinkmbox, phba->cfg_topology,
2231 phba->cfg_link_speed);
2232 initlinkmbox->mb.un.varInitLnk.lipsr_AL_PA = 0;
2233 rc = lpfc_sli_issue_mbox(phba, initlinkmbox,
2234 (MBX_NOWAIT | MBX_STOP_IOCB));
James Smart5b8bd0c2007-04-25 09:52:49 -04002235 lpfc_set_loopback_flag(phba);
dea31012005-04-17 16:05:31 -05002236 if (rc == MBX_NOT_FINISHED)
2237 mempool_free(initlinkmbox, phba->mbox_mem_pool);
2238
2239 break;
2240
2241 case LPFC_DISC_AUTH:
2242 /* Node Authentication timeout */
2243 lpfc_printf_log(phba,
2244 KERN_ERR,
2245 LOG_DISCOVERY,
2246 "%d:0227 Node Authentication timeout\n",
2247 phba->brd_no);
James Smart2e0fef82007-06-17 19:56:36 -05002248 lpfc_disc_flush_list(vport);
2249
dea31012005-04-17 16:05:31 -05002250 clearlambox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2251 if (!clearlambox) {
2252 clrlaerr = 1;
2253 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
James Smartdca94792006-08-01 07:34:08 -04002254 "%d:0207 Device Discovery "
dea31012005-04-17 16:05:31 -05002255 "completion error\n",
2256 phba->brd_no);
James Smart2e0fef82007-06-17 19:56:36 -05002257 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05002258 break;
2259 }
James Smart2e0fef82007-06-17 19:56:36 -05002260 phba->link_state = LPFC_CLEAR_LA;
dea31012005-04-17 16:05:31 -05002261 lpfc_clear_la(phba, clearlambox);
James Smart2e0fef82007-06-17 19:56:36 -05002262 printk(KERN_ERR "%s (%d): do clear_la\n",
2263 __FUNCTION__, __LINE__);
dea31012005-04-17 16:05:31 -05002264 clearlambox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
James Smart2e0fef82007-06-17 19:56:36 -05002265 clearlambox->vport = vport;
dea31012005-04-17 16:05:31 -05002266 rc = lpfc_sli_issue_mbox(phba, clearlambox,
2267 (MBX_NOWAIT | MBX_STOP_IOCB));
2268 if (rc == MBX_NOT_FINISHED) {
2269 mempool_free(clearlambox, phba->mbox_mem_pool);
2270 clrlaerr = 1;
2271 }
2272 break;
2273
James Smart2e0fef82007-06-17 19:56:36 -05002274 case LPFC_VPORT_READY:
2275 if (vport->fc_flag & FC_RSCN_MODE) {
dea31012005-04-17 16:05:31 -05002276 lpfc_printf_log(phba,
2277 KERN_ERR,
2278 LOG_DISCOVERY,
2279 "%d:0231 RSCN timeout Data: x%x x%x\n",
2280 phba->brd_no,
James Smart2e0fef82007-06-17 19:56:36 -05002281 vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
dea31012005-04-17 16:05:31 -05002282
2283 /* Cleanup any outstanding ELS commands */
James Smart2e0fef82007-06-17 19:56:36 -05002284 lpfc_els_flush_cmd(vport);
dea31012005-04-17 16:05:31 -05002285
James Smart2e0fef82007-06-17 19:56:36 -05002286 lpfc_els_flush_rscn(vport);
2287 lpfc_disc_flush_list(vport);
dea31012005-04-17 16:05:31 -05002288 }
2289 break;
James Smart2e0fef82007-06-17 19:56:36 -05002290
2291 case LPFC_STATE_UNKNOWN:
2292 case LPFC_NS_REG:
2293 case LPFC_BUILD_DISC_LIST:
2294 lpfc_printf_log(phba,
2295 KERN_ERR,
2296 LOG_DISCOVERY,
2297 "%d:0229 Unexpected discovery timeout, vport "
2298 "State x%x\n",
2299 vport->port_state,
2300 phba->brd_no);
2301
2302 break;
2303 }
2304
2305 switch (phba->link_state) {
2306 case LPFC_CLEAR_LA:
2307 /* CLEAR LA timeout */
2308 lpfc_printf_log(phba,
2309 KERN_ERR,
2310 LOG_DISCOVERY,
2311 "%d:0228 CLEAR LA timeout\n",
2312 phba->brd_no);
2313 clrlaerr = 1;
2314 break;
2315
2316 case LPFC_LINK_UNKNOWN:
2317 case LPFC_WARM_START:
2318 case LPFC_INIT_START:
2319 case LPFC_INIT_MBX_CMDS:
2320 case LPFC_LINK_DOWN:
2321 case LPFC_LINK_UP:
2322 case LPFC_HBA_ERROR:
2323 lpfc_printf_log(phba,
2324 KERN_ERR,
2325 LOG_DISCOVERY,
2326 "%d:0230 Unexpected timeout, hba link "
2327 "state x%x\n",
2328 phba->brd_no, phba->link_state);
2329 clrlaerr = 1;
2330 break;
dea31012005-04-17 16:05:31 -05002331 }
2332
2333 if (clrlaerr) {
James Smart2e0fef82007-06-17 19:56:36 -05002334 lpfc_disc_flush_list(vport);
James Smarta4bc3372006-12-02 13:34:16 -05002335 psli->ring[(psli->extra_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
dea31012005-04-17 16:05:31 -05002336 psli->ring[(psli->fcp_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
2337 psli->ring[(psli->next_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
James Smart2e0fef82007-06-17 19:56:36 -05002338 printk(KERN_ERR "%s (%d): vport ready\n",
2339 __FUNCTION__, __LINE__);
2340 vport->port_state = LPFC_VPORT_READY;
dea31012005-04-17 16:05:31 -05002341 }
2342
2343 return;
2344}
2345
dea31012005-04-17 16:05:31 -05002346/*
2347 * This routine handles processing a NameServer REG_LOGIN mailbox
2348 * command upon completion. It is setup in the LPFC_MBOXQ
2349 * as the completion routine when the command is
2350 * handed off to the SLI layer.
2351 */
2352void
James Smart2e0fef82007-06-17 19:56:36 -05002353lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05002354{
James Smart2e0fef82007-06-17 19:56:36 -05002355 MAILBOX_t *mb = &pmb->mb;
2356 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
2357 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
2358 struct lpfc_vport *vport = pmb->vport;
dea31012005-04-17 16:05:31 -05002359
2360 pmb->context1 = NULL;
2361
dea31012005-04-17 16:05:31 -05002362 ndlp->nlp_rpi = mb->un.varWords[0];
dea31012005-04-17 16:05:31 -05002363 ndlp->nlp_type |= NLP_FABRIC;
James Smart2e0fef82007-06-17 19:56:36 -05002364 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
dea31012005-04-17 16:05:31 -05002365
James Smart2e0fef82007-06-17 19:56:36 -05002366 /*
2367 * Start issuing Fabric-Device Management Interface (FDMI) command to
2368 * 0xfffffa (FDMI well known port) or Delay issuing FDMI command if
2369 * fdmi-on=2 (supporting RPA/hostnmae)
dea31012005-04-17 16:05:31 -05002370 */
James Smart2e0fef82007-06-17 19:56:36 -05002371
2372 if (phba->cfg_fdmi_on == 1)
2373 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA);
2374 else
2375 mod_timer(&vport->fc_fdmitmo, jiffies + HZ * 60);
dea31012005-04-17 16:05:31 -05002376
James Smart329f9bc2007-04-25 09:53:01 -04002377 /* Mailbox took a reference to the node */
2378 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002379 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2380 kfree(mp);
James Smart329f9bc2007-04-25 09:53:01 -04002381 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05002382
2383 return;
2384}
2385
James Smart685f0bf2007-04-25 09:53:08 -04002386static int
2387lpfc_filter_by_rpi(struct lpfc_nodelist *ndlp, void *param)
2388{
2389 uint16_t *rpi = param;
2390
2391 return ndlp->nlp_rpi == *rpi;
2392}
2393
2394static int
2395lpfc_filter_by_wwpn(struct lpfc_nodelist *ndlp, void *param)
2396{
2397 return memcmp(&ndlp->nlp_portname, param,
2398 sizeof(ndlp->nlp_portname)) == 0;
2399}
2400
dea31012005-04-17 16:05:31 -05002401struct lpfc_nodelist *
James Smart2e0fef82007-06-17 19:56:36 -05002402__lpfc_find_node(struct lpfc_vport *vport, node_filter filter, void *param)
dea31012005-04-17 16:05:31 -05002403{
James.Smart@Emulex.Com21568f52005-10-28 20:29:36 -04002404 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05002405
James Smart2e0fef82007-06-17 19:56:36 -05002406 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smart685f0bf2007-04-25 09:53:08 -04002407 if (ndlp->nlp_state != NLP_STE_UNUSED_NODE &&
2408 filter(ndlp, param))
2409 return ndlp;
2410 }
James.Smart@Emulex.Com21568f52005-10-28 20:29:36 -04002411 return NULL;
dea31012005-04-17 16:05:31 -05002412}
2413
James Smart685f0bf2007-04-25 09:53:08 -04002414/*
2415 * Search node lists for a remote port matching filter criteria
2416 * This routine is used when the caller does NOT have host_lock.
2417 */
2418struct lpfc_nodelist *
James Smart2e0fef82007-06-17 19:56:36 -05002419lpfc_find_node(struct lpfc_vport *vport, node_filter filter, void *param)
James Smart685f0bf2007-04-25 09:53:08 -04002420{
James Smart2e0fef82007-06-17 19:56:36 -05002421 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart685f0bf2007-04-25 09:53:08 -04002422 struct lpfc_nodelist *ndlp;
2423
James Smart2e0fef82007-06-17 19:56:36 -05002424 spin_lock_irq(shost->host_lock);
2425 ndlp = __lpfc_find_node(vport, filter, param);
2426 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04002427 return ndlp;
2428}
2429
2430/*
2431 * This routine looks up the ndlp lists for the given RPI. If rpi found it
James Smart2e0fef82007-06-17 19:56:36 -05002432 * returns the node list element pointer else return NULL.
James Smart685f0bf2007-04-25 09:53:08 -04002433 */
2434struct lpfc_nodelist *
James Smart2e0fef82007-06-17 19:56:36 -05002435__lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi)
James Smart685f0bf2007-04-25 09:53:08 -04002436{
James Smart2e0fef82007-06-17 19:56:36 -05002437 return __lpfc_find_node(vport, lpfc_filter_by_rpi, &rpi);
James Smart685f0bf2007-04-25 09:53:08 -04002438}
2439
James Smart2534ba72007-04-25 09:52:20 -04002440struct lpfc_nodelist *
James Smart2e0fef82007-06-17 19:56:36 -05002441lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi)
James Smart2534ba72007-04-25 09:52:20 -04002442{
James Smart2e0fef82007-06-17 19:56:36 -05002443 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart2534ba72007-04-25 09:52:20 -04002444 struct lpfc_nodelist *ndlp;
2445
James Smart2e0fef82007-06-17 19:56:36 -05002446 spin_lock_irq(shost->host_lock);
2447 ndlp = __lpfc_findnode_rpi(vport, rpi);
2448 spin_unlock_irq(shost->host_lock);
James Smart2534ba72007-04-25 09:52:20 -04002449 return ndlp;
2450}
2451
James Smart488d1462006-03-07 15:02:37 -05002452/*
James Smart685f0bf2007-04-25 09:53:08 -04002453 * This routine looks up the ndlp lists for the given WWPN. If WWPN found it
James Smart2e0fef82007-06-17 19:56:36 -05002454 * returns the node element list pointer else return NULL.
James Smart488d1462006-03-07 15:02:37 -05002455 */
2456struct lpfc_nodelist *
James Smart2e0fef82007-06-17 19:56:36 -05002457lpfc_findnode_wwpn(struct lpfc_vport *vport, struct lpfc_name *wwpn)
James Smart488d1462006-03-07 15:02:37 -05002458{
James Smart2e0fef82007-06-17 19:56:36 -05002459 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart488d1462006-03-07 15:02:37 -05002460 struct lpfc_nodelist *ndlp;
James Smart488d1462006-03-07 15:02:37 -05002461
James Smart2e0fef82007-06-17 19:56:36 -05002462 spin_lock_irq(shost->host_lock);
2463 ndlp = __lpfc_find_node(vport, lpfc_filter_by_wwpn, wwpn);
2464 spin_unlock_irq(shost->host_lock);
James Smart488d1462006-03-07 15:02:37 -05002465 return NULL;
2466}
2467
dea31012005-04-17 16:05:31 -05002468void
James Smart2e0fef82007-06-17 19:56:36 -05002469lpfc_nlp_init(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2470 uint32_t did)
dea31012005-04-17 16:05:31 -05002471{
2472 memset(ndlp, 0, sizeof (struct lpfc_nodelist));
dea31012005-04-17 16:05:31 -05002473 INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp);
dea31012005-04-17 16:05:31 -05002474 init_timer(&ndlp->nlp_delayfunc);
2475 ndlp->nlp_delayfunc.function = lpfc_els_retry_delay;
2476 ndlp->nlp_delayfunc.data = (unsigned long)ndlp;
2477 ndlp->nlp_DID = did;
James Smart2e0fef82007-06-17 19:56:36 -05002478 ndlp->vport = vport;
dea31012005-04-17 16:05:31 -05002479 ndlp->nlp_sid = NLP_NO_SID;
James Smart685f0bf2007-04-25 09:53:08 -04002480 INIT_LIST_HEAD(&ndlp->nlp_listp);
James Smart329f9bc2007-04-25 09:53:01 -04002481 kref_init(&ndlp->kref);
dea31012005-04-17 16:05:31 -05002482 return;
2483}
James Smart329f9bc2007-04-25 09:53:01 -04002484
2485void
2486lpfc_nlp_release(struct kref *kref)
2487{
2488 struct lpfc_nodelist *ndlp = container_of(kref, struct lpfc_nodelist,
2489 kref);
James Smart2e0fef82007-06-17 19:56:36 -05002490 lpfc_nlp_remove(ndlp->vport, ndlp);
2491 mempool_free(ndlp, ndlp->vport->phba->nlp_mem_pool);
James Smart329f9bc2007-04-25 09:53:01 -04002492}
2493
2494struct lpfc_nodelist *
2495lpfc_nlp_get(struct lpfc_nodelist *ndlp)
2496{
2497 if (ndlp)
2498 kref_get(&ndlp->kref);
2499 return ndlp;
2500}
2501
2502int
2503lpfc_nlp_put(struct lpfc_nodelist *ndlp)
2504{
2505 return ndlp ? kref_put(&ndlp->kref, lpfc_nlp_release) : 0;
2506}