blob: 20b2a4905daaad73f9fd64ea290f13d057cefa80 [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;
James Smart2e0fef82007-06-17 19:56:36 -0500235 uint32_t ha_copy, control, work_port_events;
236 struct lpfc_vport *vport;
James Smarted957682007-06-17 19:56:37 -0500237 int i;
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 if (!vport)
dea31012005-04-17 16:05:31 -0500307 return 0;
James Smarted957682007-06-17 19:56:37 -0500308
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;
James Smarted957682007-06-17 19:56:37 -0500357 unsigned long flags;
dea31012005-04-17 16:05:31 -0500358
359 /*
360 * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will
361 * be queued to worker thread for processing
362 */
363 evtp = kmalloc(sizeof(struct lpfc_work_evt), GFP_KERNEL);
364 if (!evtp)
365 return 0;
366
367 evtp->evt_arg1 = arg1;
368 evtp->evt_arg2 = arg2;
369 evtp->evt = evt;
370
James Smarted957682007-06-17 19:56:37 -0500371 spin_lock_irqsave(&phba->hbalock, flags);
James Smart071fbd3d2006-04-15 11:53:20 -0400372 list_add_tail(&evtp->evt_listp, &phba->work_list);
dea31012005-04-17 16:05:31 -0500373 if (phba->work_wait)
374 wake_up(phba->work_wait);
James Smarted957682007-06-17 19:56:37 -0500375 spin_unlock_irqrestore(&phba->hbalock, flags);
dea31012005-04-17 16:05:31 -0500376
377 return 1;
378}
379
380int
James Smart685f0bf2007-04-25 09:53:08 -0400381lpfc_linkdown(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500382{
James Smart2e0fef82007-06-17 19:56:36 -0500383 struct lpfc_vport *vport = phba->pport;
384 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
385 struct lpfc_sli *psli;
dea31012005-04-17 16:05:31 -0500386 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart685f0bf2007-04-25 09:53:08 -0400387 LPFC_MBOXQ_t *mb;
388 int rc;
dea31012005-04-17 16:05:31 -0500389
390 psli = &phba->sli;
James Smart2e0fef82007-06-17 19:56:36 -0500391 if (phba->link_state == LPFC_LINK_DOWN) {
392 return 0;
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500393 }
James Smart2e0fef82007-06-17 19:56:36 -0500394 spin_lock_irq(&phba->hbalock);
395 if (phba->link_state > LPFC_LINK_DOWN)
396 phba->link_state = LPFC_LINK_DOWN;
397 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500398
James Smart2e0fef82007-06-17 19:56:36 -0500399 fc_host_post_event(shost, fc_get_event_number(), FCH_EVT_LINKDOWN, 0);
James Smartd2873e42006-08-18 17:46:43 -0400400
dea31012005-04-17 16:05:31 -0500401 /* Clean up any firmware default rpi's */
James Smart2e0fef82007-06-17 19:56:36 -0500402 mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
403 if (mb) {
dea31012005-04-17 16:05:31 -0500404 lpfc_unreg_did(phba, 0xffffffff, mb);
James Smarted957682007-06-17 19:56:37 -0500405 mb->vport = vport;
James Smart2e0fef82007-06-17 19:56:36 -0500406 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
dea31012005-04-17 16:05:31 -0500407 if (lpfc_sli_issue_mbox(phba, mb, (MBX_NOWAIT | MBX_STOP_IOCB))
408 == MBX_NOT_FINISHED) {
James Smart2e0fef82007-06-17 19:56:36 -0500409 mempool_free(mb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500410 }
411 }
412
413 /* Cleanup any outstanding RSCN activity */
James Smart2e0fef82007-06-17 19:56:36 -0500414 lpfc_els_flush_rscn(vport);
dea31012005-04-17 16:05:31 -0500415
416 /* Cleanup any outstanding ELS commands */
James Smart2e0fef82007-06-17 19:56:36 -0500417 lpfc_els_flush_cmd(vport);
dea31012005-04-17 16:05:31 -0500418
James Smart685f0bf2007-04-25 09:53:08 -0400419 /*
420 * Issue a LINK DOWN event to all nodes.
421 */
James Smart2e0fef82007-06-17 19:56:36 -0500422 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
423 /* free any ndlp's on unused state */
James Smart685f0bf2007-04-25 09:53:08 -0400424 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
James Smart2e0fef82007-06-17 19:56:36 -0500425 lpfc_drop_node(vport, ndlp);
James Smart685f0bf2007-04-25 09:53:08 -0400426 else /* otherwise, force node recovery. */
James Smart2e0fef82007-06-17 19:56:36 -0500427 rc = lpfc_disc_state_machine(vport, ndlp, NULL,
James Smart685f0bf2007-04-25 09:53:08 -0400428 NLP_EVT_DEVICE_RECOVERY);
dea31012005-04-17 16:05:31 -0500429 }
430
dea31012005-04-17 16:05:31 -0500431 /* Setup myDID for link up if we are in pt2pt mode */
James Smart2e0fef82007-06-17 19:56:36 -0500432 if (vport->fc_flag & FC_PT2PT) {
433 vport->fc_myDID = 0;
434 mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
435 if (mb) {
dea31012005-04-17 16:05:31 -0500436 lpfc_config_link(phba, mb);
437 mb->mbox_cmpl=lpfc_sli_def_mbox_cmpl;
James Smarted957682007-06-17 19:56:37 -0500438 mb->vport = vport;
James Smart2e0fef82007-06-17 19:56:36 -0500439 if (lpfc_sli_issue_mbox(phba, mb,
440 (MBX_NOWAIT | MBX_STOP_IOCB))
dea31012005-04-17 16:05:31 -0500441 == MBX_NOT_FINISHED) {
James Smart2e0fef82007-06-17 19:56:36 -0500442 mempool_free(mb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500443 }
444 }
James Smart2e0fef82007-06-17 19:56:36 -0500445 spin_lock_irq(shost->host_lock);
446 vport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI);
447 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500448 }
James Smart2e0fef82007-06-17 19:56:36 -0500449
450 spin_lock_irq(shost->host_lock);
451 vport->fc_flag &= ~FC_LBIT;
452 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500453
454 /* Turn off discovery timer if its running */
James Smart2e0fef82007-06-17 19:56:36 -0500455 lpfc_can_disctmo(vport);
dea31012005-04-17 16:05:31 -0500456
457 /* Must process IOCBs on all rings to handle ABORTed I/Os */
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500458 return 0;
dea31012005-04-17 16:05:31 -0500459}
460
461static int
James Smart685f0bf2007-04-25 09:53:08 -0400462lpfc_linkup(struct lpfc_hba *phba)
dea31012005-04-17 16:05:31 -0500463{
James Smart2e0fef82007-06-17 19:56:36 -0500464 struct lpfc_vport *vport = phba->pport;
465 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500466 struct lpfc_nodelist *ndlp, *next_ndlp;
467
James Smart2e0fef82007-06-17 19:56:36 -0500468 fc_host_post_event(shost, fc_get_event_number(), FCH_EVT_LINKUP, 0);
James Smartd2873e42006-08-18 17:46:43 -0400469
James Smart2e0fef82007-06-17 19:56:36 -0500470 spin_lock_irq(shost->host_lock);
471 phba->link_state = LPFC_LINK_UP;
472 vport->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI | FC_ABORT_DISCOVERY |
473 FC_RSCN_MODE | FC_NLP_MORE | FC_RSCN_DISCOVERY);
474 vport->fc_flag |= FC_NDISC_ACTIVE;
475 vport->fc_ns_retry = 0;
476 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500477
478
James Smart2e0fef82007-06-17 19:56:36 -0500479 if (vport->fc_flag & FC_LBIT) {
480 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smart685f0bf2007-04-25 09:53:08 -0400481 if (ndlp->nlp_state != NLP_STE_UNUSED_NODE) {
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500482 if (ndlp->nlp_type & NLP_FABRIC) {
James Smart685f0bf2007-04-25 09:53:08 -0400483 /*
484 * On Linkup its safe to clean up the
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500485 * ndlp from Fabric connections.
486 */
James Smart2e0fef82007-06-17 19:56:36 -0500487 lpfc_nlp_set_state(vport, ndlp,
James Smart685f0bf2007-04-25 09:53:08 -0400488 NLP_STE_UNUSED_NODE);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500489 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
James Smart685f0bf2007-04-25 09:53:08 -0400490 /*
491 * Fail outstanding IO now since
492 * device is marked for PLOGI.
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500493 */
James Smart2e0fef82007-06-17 19:56:36 -0500494 lpfc_unreg_rpi(vport, ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500495 }
496 }
dea31012005-04-17 16:05:31 -0500497 }
498 }
499
James Smart2e0fef82007-06-17 19:56:36 -0500500 /* free any ndlp's in unused state */
501 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
James Smart685f0bf2007-04-25 09:53:08 -0400502 nlp_listp) {
503 if (ndlp->nlp_state == NLP_STE_UNUSED_NODE)
James Smart2e0fef82007-06-17 19:56:36 -0500504 lpfc_drop_node(vport, ndlp);
James Smart685f0bf2007-04-25 09:53:08 -0400505 }
dea31012005-04-17 16:05:31 -0500506
507 return 0;
508}
509
510/*
511 * This routine handles processing a CLEAR_LA mailbox
512 * command upon completion. It is setup in the LPFC_MBOXQ
513 * as the completion routine when the command is
514 * handed off to the SLI layer.
515 */
516void
James Smart2e0fef82007-06-17 19:56:36 -0500517lpfc_mbx_cmpl_clear_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -0500518{
James Smart2e0fef82007-06-17 19:56:36 -0500519 struct lpfc_vport *vport = pmb->vport;
520 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
521 struct lpfc_sli *psli = &phba->sli;
522 MAILBOX_t *mb = &pmb->mb;
dea31012005-04-17 16:05:31 -0500523 uint32_t control;
524
dea31012005-04-17 16:05:31 -0500525 /* Since we don't do discovery right now, turn these off here */
James Smarta4bc3372006-12-02 13:34:16 -0500526 psli->ring[psli->extra_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
dea31012005-04-17 16:05:31 -0500527 psli->ring[psli->fcp_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
528 psli->ring[psli->next_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
529
530 /* Check for error */
531 if ((mb->mbxStatus) && (mb->mbxStatus != 0x1601)) {
James Smart2e0fef82007-06-17 19:56:36 -0500532 /* CLEAR_LA mbox error <mbxStatus> state <port_state> */
dea31012005-04-17 16:05:31 -0500533 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
534 "%d:0320 CLEAR_LA mbxStatus error x%x hba "
535 "state x%x\n",
James Smart2e0fef82007-06-17 19:56:36 -0500536 phba->brd_no, mb->mbxStatus, vport->port_state);
dea31012005-04-17 16:05:31 -0500537
James Smart2e0fef82007-06-17 19:56:36 -0500538 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500539 goto out;
540 }
541
James Smart2e0fef82007-06-17 19:56:36 -0500542 if (vport->fc_flag & FC_ABORT_DISCOVERY)
dea31012005-04-17 16:05:31 -0500543 goto out;
544
James Smart2e0fef82007-06-17 19:56:36 -0500545 vport->num_disc_nodes = 0;
546 /* go thru NPR nodes and issue ELS PLOGIs */
547 if (vport->fc_npr_cnt)
548 lpfc_els_disc_plogi(vport);
549
550 if (!vport->num_disc_nodes) {
551 spin_lock_irq(shost->host_lock);
552 vport->fc_flag &= ~FC_NDISC_ACTIVE;
553 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500554 }
555
James Smart2e0fef82007-06-17 19:56:36 -0500556 vport->port_state = LPFC_VPORT_READY;
dea31012005-04-17 16:05:31 -0500557
558out:
559 /* Device Discovery completes */
James Smarted957682007-06-17 19:56:37 -0500560 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
dea31012005-04-17 16:05:31 -0500561 "%d:0225 Device Discovery completes\n",
562 phba->brd_no);
563
James Smart2e0fef82007-06-17 19:56:36 -0500564 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500565
James Smart2e0fef82007-06-17 19:56:36 -0500566 spin_lock_irq(shost->host_lock);
567 vport->fc_flag &= ~(FC_ABORT_DISCOVERY | FC_ESTABLISH_LINK);
568 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500569
570 del_timer_sync(&phba->fc_estabtmo);
571
James Smart2e0fef82007-06-17 19:56:36 -0500572 lpfc_can_disctmo(vport);
dea31012005-04-17 16:05:31 -0500573
574 /* turn on Link Attention interrupts */
James Smart2e0fef82007-06-17 19:56:36 -0500575
576 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500577 psli->sli_flag |= LPFC_PROCESS_LA;
578 control = readl(phba->HCregaddr);
579 control |= HC_LAINT_ENA;
580 writel(control, phba->HCregaddr);
581 readl(phba->HCregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -0500582 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500583
584 return;
585}
586
James Smart2e0fef82007-06-17 19:56:36 -0500587
dea31012005-04-17 16:05:31 -0500588static void
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500589lpfc_mbx_cmpl_local_config_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -0500590{
James Smart2e0fef82007-06-17 19:56:36 -0500591 struct lpfc_vport *vport = pmb->vport;
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500592 struct lpfc_sli *psli = &phba->sli;
593 int rc;
dea31012005-04-17 16:05:31 -0500594
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500595 if (pmb->mb.mbxStatus)
dea31012005-04-17 16:05:31 -0500596 goto out;
dea31012005-04-17 16:05:31 -0500597
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500598 mempool_free(pmb, phba->mbox_mem_pool);
599
600 if (phba->fc_topology == TOPOLOGY_LOOP &&
James Smart2e0fef82007-06-17 19:56:36 -0500601 vport->fc_flag & FC_PUBLIC_LOOP &&
602 !(vport->fc_flag & FC_LBIT)) {
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500603 /* Need to wait for FAN - use discovery timer
James Smart2e0fef82007-06-17 19:56:36 -0500604 * for timeout. port_state is identically
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500605 * LPFC_LOCAL_CFG_LINK while waiting for FAN
606 */
James Smart2e0fef82007-06-17 19:56:36 -0500607 lpfc_set_disctmo(vport);
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500608 return;
dea31012005-04-17 16:05:31 -0500609 }
610
James Smart2e0fef82007-06-17 19:56:36 -0500611 /* Start discovery by sending a FLOGI. port_state is identically
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500612 * LPFC_FLOGI while waiting for FLOGI cmpl
613 */
James Smart2e0fef82007-06-17 19:56:36 -0500614 vport->port_state = LPFC_FLOGI;
615 lpfc_set_disctmo(vport);
616 lpfc_initial_flogi(vport);
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500617 return;
dea31012005-04-17 16:05:31 -0500618
619out:
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500620 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
621 "%d:0306 CONFIG_LINK mbxStatus error x%x "
622 "HBA state x%x\n",
James Smart2e0fef82007-06-17 19:56:36 -0500623 phba->brd_no, pmb->mb.mbxStatus, vport->port_state);
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500624
625 lpfc_linkdown(phba);
626
James Smart2e0fef82007-06-17 19:56:36 -0500627 phba->link_state = LPFC_HBA_ERROR;
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500628
629 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
dea31012005-04-17 16:05:31 -0500630 "%d:0200 CONFIG_LINK bad hba state x%x\n",
James Smart2e0fef82007-06-17 19:56:36 -0500631 phba->brd_no, vport->port_state);
dea31012005-04-17 16:05:31 -0500632
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500633 lpfc_clear_la(phba, pmb);
634 pmb->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
James Smart2e0fef82007-06-17 19:56:36 -0500635 pmb->vport = vport;
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500636 rc = lpfc_sli_issue_mbox(phba, pmb, (MBX_NOWAIT | MBX_STOP_IOCB));
637 if (rc == MBX_NOT_FINISHED) {
638 mempool_free(pmb, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -0500639 lpfc_disc_flush_list(vport);
James Smarta4bc3372006-12-02 13:34:16 -0500640 psli->ring[(psli->extra_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500641 psli->ring[(psli->fcp_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
642 psli->ring[(psli->next_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
James Smart2e0fef82007-06-17 19:56:36 -0500643 vport->port_state = LPFC_VPORT_READY;
dea31012005-04-17 16:05:31 -0500644 }
645 return;
646}
647
648static void
James Smart2e0fef82007-06-17 19:56:36 -0500649lpfc_mbx_cmpl_read_sparam(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -0500650{
651 struct lpfc_sli *psli = &phba->sli;
652 MAILBOX_t *mb = &pmb->mb;
653 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) pmb->context1;
James Smart2e0fef82007-06-17 19:56:36 -0500654 struct lpfc_vport *vport = pmb->vport;
dea31012005-04-17 16:05:31 -0500655
656
657 /* Check for error */
658 if (mb->mbxStatus) {
659 /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */
660 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
661 "%d:0319 READ_SPARAM mbxStatus error x%x "
662 "hba state x%x>\n",
James Smart2e0fef82007-06-17 19:56:36 -0500663 phba->brd_no, mb->mbxStatus, vport->port_state);
dea31012005-04-17 16:05:31 -0500664
665 lpfc_linkdown(phba);
James Smart2e0fef82007-06-17 19:56:36 -0500666 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500667 goto out;
668 }
669
James Smart2e0fef82007-06-17 19:56:36 -0500670 memcpy((uint8_t *) &vport->fc_sparam, (uint8_t *) mp->virt,
dea31012005-04-17 16:05:31 -0500671 sizeof (struct serv_parm));
James Smarta12e07b2006-12-02 13:35:30 -0500672 if (phba->cfg_soft_wwnn)
James Smart2e0fef82007-06-17 19:56:36 -0500673 u64_to_wwn(phba->cfg_soft_wwnn,
674 vport->fc_sparam.nodeName.u.wwn);
James Smartc3f28af2006-08-18 17:47:18 -0400675 if (phba->cfg_soft_wwpn)
James Smart2e0fef82007-06-17 19:56:36 -0500676 u64_to_wwn(phba->cfg_soft_wwpn,
677 vport->fc_sparam.portName.u.wwn);
678 memcpy((uint8_t *) &vport->fc_nodename,
679 (uint8_t *) &vport->fc_sparam.nodeName,
dea31012005-04-17 16:05:31 -0500680 sizeof (struct lpfc_name));
James Smart2e0fef82007-06-17 19:56:36 -0500681 memcpy((uint8_t *) &vport->fc_portname,
682 (uint8_t *) &vport->fc_sparam.portName,
dea31012005-04-17 16:05:31 -0500683 sizeof (struct lpfc_name));
684 lpfc_mbuf_free(phba, mp->virt, mp->phys);
685 kfree(mp);
James Smart2e0fef82007-06-17 19:56:36 -0500686 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500687 return;
688
689out:
690 pmb->context1 = NULL;
691 lpfc_mbuf_free(phba, mp->virt, mp->phys);
692 kfree(mp);
James Smart2e0fef82007-06-17 19:56:36 -0500693 if (phba->link_state != LPFC_CLEAR_LA) {
694 struct lpfc_sli_ring *extra_ring =
695 &psli->ring[psli->extra_ring];
696 struct lpfc_sli_ring *fcp_ring = &psli->ring[psli->fcp_ring];
697 struct lpfc_sli_ring *next_ring = &psli->ring[psli->next_ring];
698
dea31012005-04-17 16:05:31 -0500699 lpfc_clear_la(phba, pmb);
700 pmb->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
James Smart2e0fef82007-06-17 19:56:36 -0500701 pmb->vport = vport;
dea31012005-04-17 16:05:31 -0500702 if (lpfc_sli_issue_mbox(phba, pmb, (MBX_NOWAIT | MBX_STOP_IOCB))
703 == MBX_NOT_FINISHED) {
James Smart2e0fef82007-06-17 19:56:36 -0500704 mempool_free(pmb, phba->mbox_mem_pool);
705 lpfc_disc_flush_list(vport);
706 extra_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
707 fcp_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
708 next_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
James Smart2e0fef82007-06-17 19:56:36 -0500709 vport->port_state = LPFC_VPORT_READY;
dea31012005-04-17 16:05:31 -0500710 }
711 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500712 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500713 }
714 return;
715}
716
717static void
James Smart2e0fef82007-06-17 19:56:36 -0500718lpfc_mbx_process_link_up(struct lpfc_vport *vport, READ_LA_VAR *la)
dea31012005-04-17 16:05:31 -0500719{
James Smart2e0fef82007-06-17 19:56:36 -0500720 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
721 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -0500722 LPFC_MBOXQ_t *sparam_mbox, *cfglink_mbox;
James Smart2e0fef82007-06-17 19:56:36 -0500723 int i;
James Smart14691152006-12-02 13:34:28 -0500724 struct lpfc_dmabuf *mp;
725 int rc;
726
dea31012005-04-17 16:05:31 -0500727 sparam_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
728 cfglink_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
729
James Smart2e0fef82007-06-17 19:56:36 -0500730 spin_lock_irq(shost->host_lock);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -0500731 switch (la->UlnkSpeed) {
dea31012005-04-17 16:05:31 -0500732 case LA_1GHZ_LINK:
733 phba->fc_linkspeed = LA_1GHZ_LINK;
734 break;
735 case LA_2GHZ_LINK:
736 phba->fc_linkspeed = LA_2GHZ_LINK;
737 break;
738 case LA_4GHZ_LINK:
739 phba->fc_linkspeed = LA_4GHZ_LINK;
740 break;
James Smartb87eab32007-04-25 09:53:28 -0400741 case LA_8GHZ_LINK:
742 phba->fc_linkspeed = LA_8GHZ_LINK;
743 break;
dea31012005-04-17 16:05:31 -0500744 default:
745 phba->fc_linkspeed = LA_UNKNW_LINK;
746 break;
747 }
748
749 phba->fc_topology = la->topology;
750
751 if (phba->fc_topology == TOPOLOGY_LOOP) {
752 /* Get Loop Map information */
753
754 if (la->il)
James Smart2e0fef82007-06-17 19:56:36 -0500755 vport->fc_flag |= FC_LBIT;
dea31012005-04-17 16:05:31 -0500756
James Smart2e0fef82007-06-17 19:56:36 -0500757 vport->fc_myDID = la->granted_AL_PA;
dea31012005-04-17 16:05:31 -0500758 i = la->un.lilpBde64.tus.f.bdeSize;
759
760 if (i == 0) {
761 phba->alpa_map[0] = 0;
762 } else {
763 if (phba->cfg_log_verbose & LOG_LINK_EVENT) {
764 int numalpa, j, k;
765 union {
766 uint8_t pamap[16];
767 struct {
768 uint32_t wd1;
769 uint32_t wd2;
770 uint32_t wd3;
771 uint32_t wd4;
772 } pa;
773 } un;
774 numalpa = phba->alpa_map[0];
775 j = 0;
776 while (j < numalpa) {
777 memset(un.pamap, 0, 16);
778 for (k = 1; j < numalpa; k++) {
779 un.pamap[k - 1] =
780 phba->alpa_map[j + 1];
781 j++;
782 if (k == 16)
783 break;
784 }
785 /* Link Up Event ALPA map */
786 lpfc_printf_log(phba,
787 KERN_WARNING,
788 LOG_LINK_EVENT,
789 "%d:1304 Link Up Event "
790 "ALPA map Data: x%x "
791 "x%x x%x x%x\n",
792 phba->brd_no,
793 un.pa.wd1, un.pa.wd2,
794 un.pa.wd3, un.pa.wd4);
795 }
796 }
797 }
798 } else {
James Smart2e0fef82007-06-17 19:56:36 -0500799 vport->fc_myDID = phba->fc_pref_DID;
800 vport->fc_flag |= FC_LBIT;
dea31012005-04-17 16:05:31 -0500801 }
James Smart2e0fef82007-06-17 19:56:36 -0500802 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -0500803
804 lpfc_linkup(phba);
805 if (sparam_mbox) {
806 lpfc_read_sparam(phba, sparam_mbox);
James Smart2e0fef82007-06-17 19:56:36 -0500807 sparam_mbox->vport = vport;
dea31012005-04-17 16:05:31 -0500808 sparam_mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam;
James Smart14691152006-12-02 13:34:28 -0500809 rc = lpfc_sli_issue_mbox(phba, sparam_mbox,
dea31012005-04-17 16:05:31 -0500810 (MBX_NOWAIT | MBX_STOP_IOCB));
James Smart14691152006-12-02 13:34:28 -0500811 if (rc == MBX_NOT_FINISHED) {
812 mp = (struct lpfc_dmabuf *) sparam_mbox->context1;
813 lpfc_mbuf_free(phba, mp->virt, mp->phys);
814 kfree(mp);
815 mempool_free(sparam_mbox, phba->mbox_mem_pool);
816 if (cfglink_mbox)
817 mempool_free(cfglink_mbox, phba->mbox_mem_pool);
818 return;
819 }
dea31012005-04-17 16:05:31 -0500820 }
821
822 if (cfglink_mbox) {
James Smart2e0fef82007-06-17 19:56:36 -0500823 vport->port_state = LPFC_LOCAL_CFG_LINK;
dea31012005-04-17 16:05:31 -0500824 lpfc_config_link(phba, cfglink_mbox);
James Smart2e0fef82007-06-17 19:56:36 -0500825 cfglink_mbox->vport = vport;
Jamie Wellnitz25594c62006-02-28 19:25:34 -0500826 cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
James Smart14691152006-12-02 13:34:28 -0500827 rc = lpfc_sli_issue_mbox(phba, cfglink_mbox,
dea31012005-04-17 16:05:31 -0500828 (MBX_NOWAIT | MBX_STOP_IOCB));
James Smart14691152006-12-02 13:34:28 -0500829 if (rc == MBX_NOT_FINISHED)
830 mempool_free(cfglink_mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -0500831 }
832}
833
834static void
James Smart2e0fef82007-06-17 19:56:36 -0500835lpfc_mbx_issue_link_down(struct lpfc_hba *phba)
836{
dea31012005-04-17 16:05:31 -0500837 uint32_t control;
838 struct lpfc_sli *psli = &phba->sli;
839
840 lpfc_linkdown(phba);
841
842 /* turn on Link Attention interrupts - no CLEAR_LA needed */
James Smart2e0fef82007-06-17 19:56:36 -0500843 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500844 psli->sli_flag |= LPFC_PROCESS_LA;
845 control = readl(phba->HCregaddr);
846 control |= HC_LAINT_ENA;
847 writel(control, phba->HCregaddr);
848 readl(phba->HCregaddr); /* flush */
James Smart2e0fef82007-06-17 19:56:36 -0500849 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -0500850}
851
852/*
853 * This routine handles processing a READ_LA mailbox
854 * command upon completion. It is setup in the LPFC_MBOXQ
855 * as the completion routine when the command is
856 * handed off to the SLI layer.
857 */
858void
James Smart2e0fef82007-06-17 19:56:36 -0500859lpfc_mbx_cmpl_read_la(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -0500860{
James Smart2e0fef82007-06-17 19:56:36 -0500861 struct lpfc_vport *vport = pmb->vport;
862 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -0500863 READ_LA_VAR *la;
864 MAILBOX_t *mb = &pmb->mb;
865 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
866
867 /* Check for error */
868 if (mb->mbxStatus) {
James Smarted957682007-06-17 19:56:37 -0500869 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
dea31012005-04-17 16:05:31 -0500870 "%d:1307 READ_LA mbox error x%x state x%x\n",
James Smarted957682007-06-17 19:56:37 -0500871 phba->brd_no, mb->mbxStatus, vport->port_state);
dea31012005-04-17 16:05:31 -0500872 lpfc_mbx_issue_link_down(phba);
James Smart2e0fef82007-06-17 19:56:36 -0500873 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -0500874 goto lpfc_mbx_cmpl_read_la_free_mbuf;
875 }
876
877 la = (READ_LA_VAR *) & pmb->mb.un.varReadLA;
878
879 memcpy(&phba->alpa_map[0], mp->virt, 128);
880
James Smart2e0fef82007-06-17 19:56:36 -0500881 spin_lock_irq(shost->host_lock);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500882 if (la->pb)
James Smart2e0fef82007-06-17 19:56:36 -0500883 vport->fc_flag |= FC_BYPASSED_MODE;
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500884 else
James Smart2e0fef82007-06-17 19:56:36 -0500885 vport->fc_flag &= ~FC_BYPASSED_MODE;
886 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -0500887
dea31012005-04-17 16:05:31 -0500888 if (((phba->fc_eventTag + 1) < la->eventTag) ||
889 (phba->fc_eventTag == la->eventTag)) {
890 phba->fc_stat.LinkMultiEvent++;
James Smart2e0fef82007-06-17 19:56:36 -0500891 if (la->attType == AT_LINK_UP)
dea31012005-04-17 16:05:31 -0500892 if (phba->fc_eventTag != 0)
893 lpfc_linkdown(phba);
894 }
dea31012005-04-17 16:05:31 -0500895
896 phba->fc_eventTag = la->eventTag;
897
898 if (la->attType == AT_LINK_UP) {
899 phba->fc_stat.LinkUp++;
James Smart2e0fef82007-06-17 19:56:36 -0500900 if (phba->link_flag & LS_LOOPBACK_MODE) {
James Smart5b8bd0c2007-04-25 09:52:49 -0400901 lpfc_printf_log(phba, KERN_INFO, LOG_LINK_EVENT,
902 "%d:1306 Link Up Event in loop back mode "
903 "x%x received Data: x%x x%x x%x x%x\n",
904 phba->brd_no, la->eventTag, phba->fc_eventTag,
905 la->granted_AL_PA, la->UlnkSpeed,
906 phba->alpa_map[0]);
907 } else {
908 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
dea31012005-04-17 16:05:31 -0500909 "%d:1303 Link Up Event x%x received "
910 "Data: x%x x%x x%x x%x\n",
911 phba->brd_no, la->eventTag, phba->fc_eventTag,
912 la->granted_AL_PA, la->UlnkSpeed,
913 phba->alpa_map[0]);
James Smart5b8bd0c2007-04-25 09:52:49 -0400914 }
James Smart2e0fef82007-06-17 19:56:36 -0500915 lpfc_mbx_process_link_up(vport, la);
dea31012005-04-17 16:05:31 -0500916 } else {
917 phba->fc_stat.LinkDown++;
918 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
919 "%d:1305 Link Down Event x%x received "
920 "Data: x%x x%x x%x\n",
921 phba->brd_no, la->eventTag, phba->fc_eventTag,
James Smart2e0fef82007-06-17 19:56:36 -0500922 phba->pport->port_state, vport->fc_flag);
dea31012005-04-17 16:05:31 -0500923 lpfc_mbx_issue_link_down(phba);
924 }
925
926lpfc_mbx_cmpl_read_la_free_mbuf:
927 lpfc_mbuf_free(phba, mp->virt, mp->phys);
928 kfree(mp);
929 mempool_free(pmb, phba->mbox_mem_pool);
930 return;
931}
932
933/*
934 * This routine handles processing a REG_LOGIN mailbox
935 * command upon completion. It is setup in the LPFC_MBOXQ
936 * as the completion routine when the command is
937 * handed off to the SLI layer.
938 */
939void
James Smart2e0fef82007-06-17 19:56:36 -0500940lpfc_mbx_cmpl_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -0500941{
James Smart2e0fef82007-06-17 19:56:36 -0500942 struct lpfc_vport *vport = pmb->vport;
943 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) pmb->context1;
944 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
dea31012005-04-17 16:05:31 -0500945
dea31012005-04-17 16:05:31 -0500946 pmb->context1 = NULL;
947
948 /* Good status, call state machine */
James Smart2e0fef82007-06-17 19:56:36 -0500949 lpfc_disc_state_machine(vport, ndlp, pmb, NLP_EVT_CMPL_REG_LOGIN);
dea31012005-04-17 16:05:31 -0500950 lpfc_mbuf_free(phba, mp->virt, mp->phys);
951 kfree(mp);
James Smart2e0fef82007-06-17 19:56:36 -0500952 mempool_free(pmb, phba->mbox_mem_pool);
James Smart329f9bc2007-04-25 09:53:01 -0400953 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500954
955 return;
956}
957
958/*
959 * This routine handles processing a Fabric REG_LOGIN mailbox
960 * command upon completion. It is setup in the LPFC_MBOXQ
961 * as the completion routine when the command is
962 * handed off to the SLI layer.
963 */
964void
James Smart2e0fef82007-06-17 19:56:36 -0500965lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -0500966{
James Smart2e0fef82007-06-17 19:56:36 -0500967 struct lpfc_vport *vport = pmb->vport;
968 MAILBOX_t *mb = &pmb->mb;
969 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
970 struct lpfc_nodelist *ndlp, *ndlp_fdmi;
dea31012005-04-17 16:05:31 -0500971 ndlp = (struct lpfc_nodelist *) pmb->context2;
dea31012005-04-17 16:05:31 -0500972
James Smart329f9bc2007-04-25 09:53:01 -0400973 pmb->context1 = NULL;
974 pmb->context2 = NULL;
975
dea31012005-04-17 16:05:31 -0500976 if (mb->mbxStatus) {
977 lpfc_mbuf_free(phba, mp->virt, mp->phys);
978 kfree(mp);
James Smart329f9bc2007-04-25 09:53:01 -0400979 mempool_free(pmb, phba->mbox_mem_pool);
980 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -0500981
982 /* FLOGI failed, so just use loop map to make discovery list */
James Smart2e0fef82007-06-17 19:56:36 -0500983 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -0500984
985 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -0500986 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -0500987 return;
988 }
989
dea31012005-04-17 16:05:31 -0500990 ndlp->nlp_rpi = mb->un.varWords[0];
dea31012005-04-17 16:05:31 -0500991 ndlp->nlp_type |= NLP_FABRIC;
James Smart2e0fef82007-06-17 19:56:36 -0500992 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
dea31012005-04-17 16:05:31 -0500993
James Smart329f9bc2007-04-25 09:53:01 -0400994 lpfc_nlp_put(ndlp); /* Drop the reference from the mbox */
995
James Smart2e0fef82007-06-17 19:56:36 -0500996 if (vport->port_state == LPFC_FABRIC_CFG_LINK) {
dea31012005-04-17 16:05:31 -0500997 /* This NPort has been assigned an NPort_ID by the fabric as a
998 * result of the completed fabric login. Issue a State Change
999 * Registration (SCR) ELS request to the fabric controller
1000 * (SCR_DID) so that this NPort gets RSCN events from the
1001 * fabric.
1002 */
James Smart2e0fef82007-06-17 19:56:36 -05001003 lpfc_issue_els_scr(vport, SCR_DID, 0);
dea31012005-04-17 16:05:31 -05001004
James Smart2e0fef82007-06-17 19:56:36 -05001005 ndlp = lpfc_findnode_did(vport, NameServer_DID);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001006 if (!ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05001007 /* Allocate a new node instance. If the pool is empty,
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001008 * start the discovery process and skip the Nameserver
1009 * login process. This is attempted again later on.
James Smart2e0fef82007-06-17 19:56:36 -05001010 * Otherwise, issue a Port Login (PLOGI) to
1011 * the NameServer
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001012 */
James Smart2e0fef82007-06-17 19:56:36 -05001013 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001014 if (!ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05001015 lpfc_disc_start(vport);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001016 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1017 kfree(mp);
James Smart329f9bc2007-04-25 09:53:01 -04001018 mempool_free(pmb, phba->mbox_mem_pool);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001019 return;
1020 } else {
James Smart2e0fef82007-06-17 19:56:36 -05001021 lpfc_nlp_init(vport, ndlp, NameServer_DID);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001022 ndlp->nlp_type |= NLP_FABRIC;
1023 }
1024 }
James Smart2e0fef82007-06-17 19:56:36 -05001025
1026 lpfc_nlp_set_state(vport, ndlp, NLP_STE_PLOGI_ISSUE);
1027 lpfc_issue_els_plogi(vport, NameServer_DID, 0);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001028 if (phba->cfg_fdmi_on) {
1029 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
James Smart2e0fef82007-06-17 19:56:36 -05001030 GFP_KERNEL);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001031 if (ndlp_fdmi) {
James Smart2e0fef82007-06-17 19:56:36 -05001032 lpfc_nlp_init(vport, ndlp_fdmi, FDMI_DID);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001033 ndlp_fdmi->nlp_type |= NLP_FABRIC;
1034 ndlp_fdmi->nlp_state = NLP_STE_PLOGI_ISSUE;
James Smart2e0fef82007-06-17 19:56:36 -05001035 lpfc_issue_els_plogi(vport, FDMI_DID, 0);
dea31012005-04-17 16:05:31 -05001036 }
1037 }
1038 }
1039
1040 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1041 kfree(mp);
James Smart329f9bc2007-04-25 09:53:01 -04001042 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05001043 return;
1044}
1045
1046/*
1047 * This routine handles processing a NameServer REG_LOGIN mailbox
1048 * command upon completion. It is setup in the LPFC_MBOXQ
1049 * as the completion routine when the command is
1050 * handed off to the SLI layer.
1051 */
1052void
James Smart2e0fef82007-06-17 19:56:36 -05001053lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05001054{
James Smart2e0fef82007-06-17 19:56:36 -05001055 MAILBOX_t *mb = &pmb->mb;
1056 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
1057 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
1058 struct lpfc_vport *vport = pmb->vport;
dea31012005-04-17 16:05:31 -05001059
1060 if (mb->mbxStatus) {
James Smart329f9bc2007-04-25 09:53:01 -04001061 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001062 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1063 kfree(mp);
James Smartde0c5b32007-04-25 09:52:27 -04001064 mempool_free(pmb, phba->mbox_mem_pool);
James Smart2e0fef82007-06-17 19:56:36 -05001065 lpfc_drop_node(vport, ndlp);
dea31012005-04-17 16:05:31 -05001066
James Smart2e0fef82007-06-17 19:56:36 -05001067 /*
1068 * RegLogin failed, so just use loop map to make discovery
1069 * list
1070 */
1071 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -05001072
1073 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001074 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -05001075 return;
1076 }
1077
1078 pmb->context1 = NULL;
1079
dea31012005-04-17 16:05:31 -05001080 ndlp->nlp_rpi = mb->un.varWords[0];
dea31012005-04-17 16:05:31 -05001081 ndlp->nlp_type |= NLP_FABRIC;
James Smart2e0fef82007-06-17 19:56:36 -05001082 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
dea31012005-04-17 16:05:31 -05001083
James Smart2e0fef82007-06-17 19:56:36 -05001084 if (vport->port_state < LPFC_VPORT_READY) {
1085 /* Link up discovery requires Fabric registration. */
1086 lpfc_ns_cmd(vport, ndlp, SLI_CTNS_RNN_ID);
1087 lpfc_ns_cmd(vport, ndlp, SLI_CTNS_RSNN_NN);
1088 lpfc_ns_cmd(vport, ndlp, SLI_CTNS_RFT_ID);
1089 lpfc_ns_cmd(vport, ndlp, SLI_CTNS_RFF_ID);
dea31012005-04-17 16:05:31 -05001090 }
1091
James Smart2e0fef82007-06-17 19:56:36 -05001092 vport->fc_ns_retry = 0;
dea31012005-04-17 16:05:31 -05001093 /* Good status, issue CT Request to NameServer */
James Smart2e0fef82007-06-17 19:56:36 -05001094 if (lpfc_ns_cmd(vport, ndlp, SLI_CTNS_GID_FT)) {
dea31012005-04-17 16:05:31 -05001095 /* Cannot issue NameServer Query, so finish up discovery */
James Smart2e0fef82007-06-17 19:56:36 -05001096 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -05001097 }
1098
James Smart329f9bc2007-04-25 09:53:01 -04001099 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001100 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1101 kfree(mp);
James Smart2e0fef82007-06-17 19:56:36 -05001102 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05001103
1104 return;
1105}
1106
1107static void
James Smart2e0fef82007-06-17 19:56:36 -05001108lpfc_register_remote_port(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05001109{
James Smart2e0fef82007-06-17 19:56:36 -05001110 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1111 struct fc_rport *rport;
dea31012005-04-17 16:05:31 -05001112 struct lpfc_rport_data *rdata;
1113 struct fc_rport_identifiers rport_ids;
James Smart2e0fef82007-06-17 19:56:36 -05001114 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001115
1116 /* Remote port has reappeared. Re-register w/ FC transport */
Andrew Morton68ce1eb2005-09-21 09:46:54 -07001117 rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
1118 rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
dea31012005-04-17 16:05:31 -05001119 rport_ids.port_id = ndlp->nlp_DID;
1120 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
dea31012005-04-17 16:05:31 -05001121
James Smart329f9bc2007-04-25 09:53:01 -04001122 /*
1123 * We leave our node pointer in rport->dd_data when we unregister a
1124 * FCP target port. But fc_remote_port_add zeros the space to which
1125 * rport->dd_data points. So, if we're reusing a previously
1126 * registered port, drop the reference that we took the last time we
1127 * registered the port.
1128 */
1129 if (ndlp->rport && ndlp->rport->dd_data &&
1130 *(struct lpfc_rport_data **) ndlp->rport->dd_data) {
1131 lpfc_nlp_put(ndlp);
1132 }
James Smart2e0fef82007-06-17 19:56:36 -05001133 ndlp->rport = rport = fc_remote_port_add(shost, 0, &rport_ids);
James Smart329f9bc2007-04-25 09:53:01 -04001134 if (!rport || !get_device(&rport->dev)) {
dea31012005-04-17 16:05:31 -05001135 dev_printk(KERN_WARNING, &phba->pcidev->dev,
1136 "Warning: fc_remote_port_add failed\n");
1137 return;
1138 }
1139
1140 /* initialize static port data */
1141 rport->maxframe_size = ndlp->nlp_maxframe;
1142 rport->supported_classes = ndlp->nlp_class_sup;
dea31012005-04-17 16:05:31 -05001143 rdata = rport->dd_data;
James Smart329f9bc2007-04-25 09:53:01 -04001144 rdata->pnode = lpfc_nlp_get(ndlp);
James.Smart@Emulex.Com23dc04f2005-11-28 11:41:44 -05001145
1146 if (ndlp->nlp_type & NLP_FCP_TARGET)
1147 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
1148 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
1149 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
1150
1151
1152 if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN)
1153 fc_remote_port_rolechg(rport, rport_ids.roles);
1154
James Smart071fbd3d2006-04-15 11:53:20 -04001155 if ((rport->scsi_target_id != -1) &&
James Smarte17da182006-07-06 15:49:25 -04001156 (rport->scsi_target_id < LPFC_MAX_TARGET)) {
James Smart071fbd3d2006-04-15 11:53:20 -04001157 ndlp->nlp_sid = rport->scsi_target_id;
1158 }
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001159
1160 return;
1161}
1162
1163static void
James Smart2e0fef82007-06-17 19:56:36 -05001164lpfc_unregister_remote_port(struct lpfc_nodelist *ndlp)
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001165{
1166 struct fc_rport *rport = ndlp->rport;
1167 struct lpfc_rport_data *rdata = rport->dd_data;
1168
James Smartc01f3202006-08-18 17:47:08 -04001169 if (rport->scsi_target_id == -1) {
1170 ndlp->rport = NULL;
1171 rdata->pnode = NULL;
James Smart329f9bc2007-04-25 09:53:01 -04001172 lpfc_nlp_put(ndlp);
1173 put_device(&rport->dev);
James Smartc01f3202006-08-18 17:47:08 -04001174 }
1175
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001176 fc_remote_port_delete(rport);
dea31012005-04-17 16:05:31 -05001177
1178 return;
1179}
1180
James Smartde0c5b32007-04-25 09:52:27 -04001181static void
James Smart2e0fef82007-06-17 19:56:36 -05001182lpfc_nlp_counters(struct lpfc_vport *vport, int state, int count)
James Smartde0c5b32007-04-25 09:52:27 -04001183{
James Smart2e0fef82007-06-17 19:56:36 -05001184 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1185
1186 spin_lock_irq(shost->host_lock);
James Smartde0c5b32007-04-25 09:52:27 -04001187 switch (state) {
1188 case NLP_STE_UNUSED_NODE:
James Smart2e0fef82007-06-17 19:56:36 -05001189 vport->fc_unused_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04001190 break;
1191 case NLP_STE_PLOGI_ISSUE:
James Smart2e0fef82007-06-17 19:56:36 -05001192 vport->fc_plogi_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04001193 break;
1194 case NLP_STE_ADISC_ISSUE:
James Smart2e0fef82007-06-17 19:56:36 -05001195 vport->fc_adisc_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04001196 break;
1197 case NLP_STE_REG_LOGIN_ISSUE:
James Smart2e0fef82007-06-17 19:56:36 -05001198 vport->fc_reglogin_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04001199 break;
1200 case NLP_STE_PRLI_ISSUE:
James Smart2e0fef82007-06-17 19:56:36 -05001201 vport->fc_prli_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04001202 break;
1203 case NLP_STE_UNMAPPED_NODE:
James Smart2e0fef82007-06-17 19:56:36 -05001204 vport->fc_unmap_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04001205 break;
1206 case NLP_STE_MAPPED_NODE:
James Smart2e0fef82007-06-17 19:56:36 -05001207 vport->fc_map_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04001208 break;
1209 case NLP_STE_NPR_NODE:
James Smart2e0fef82007-06-17 19:56:36 -05001210 vport->fc_npr_cnt += count;
James Smartde0c5b32007-04-25 09:52:27 -04001211 break;
1212 }
James Smart2e0fef82007-06-17 19:56:36 -05001213 spin_unlock_irq(shost->host_lock);
James Smartde0c5b32007-04-25 09:52:27 -04001214}
Jamie Wellnitz66a9ed62006-02-28 22:33:10 -05001215
James Smartde0c5b32007-04-25 09:52:27 -04001216static void
James Smart2e0fef82007-06-17 19:56:36 -05001217lpfc_nlp_state_cleanup(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
James Smartde0c5b32007-04-25 09:52:27 -04001218 int old_state, int new_state)
1219{
James Smart2e0fef82007-06-17 19:56:36 -05001220 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1221
James Smartde0c5b32007-04-25 09:52:27 -04001222 if (new_state == NLP_STE_UNMAPPED_NODE) {
1223 ndlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
1224 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
1225 ndlp->nlp_type |= NLP_FC_NODE;
1226 }
1227 if (new_state == NLP_STE_MAPPED_NODE)
1228 ndlp->nlp_flag &= ~NLP_NODEV_REMOVE;
1229 if (new_state == NLP_STE_NPR_NODE)
1230 ndlp->nlp_flag &= ~NLP_RCV_PLOGI;
dea31012005-04-17 16:05:31 -05001231
James Smartde0c5b32007-04-25 09:52:27 -04001232 /* Transport interface */
1233 if (ndlp->rport && (old_state == NLP_STE_MAPPED_NODE ||
1234 old_state == NLP_STE_UNMAPPED_NODE)) {
James Smart2e0fef82007-06-17 19:56:36 -05001235 vport->phba->nport_event_cnt++;
1236 lpfc_unregister_remote_port(ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04001237 }
dea31012005-04-17 16:05:31 -05001238
James Smartde0c5b32007-04-25 09:52:27 -04001239 if (new_state == NLP_STE_MAPPED_NODE ||
1240 new_state == NLP_STE_UNMAPPED_NODE) {
James Smart2e0fef82007-06-17 19:56:36 -05001241 vport->phba->nport_event_cnt++;
dea31012005-04-17 16:05:31 -05001242 /*
1243 * Tell the fc transport about the port, if we haven't
1244 * already. If we have, and it's a scsi entity, be
1245 * sure to unblock any attached scsi devices
1246 */
James Smart2e0fef82007-06-17 19:56:36 -05001247 lpfc_register_remote_port(vport, ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04001248 }
dea31012005-04-17 16:05:31 -05001249
1250 /*
1251 * if we added to Mapped list, but the remote port
1252 * registration failed or assigned a target id outside
1253 * our presentable range - move the node to the
1254 * Unmapped List
1255 */
James Smartde0c5b32007-04-25 09:52:27 -04001256 if (new_state == NLP_STE_MAPPED_NODE &&
1257 (!ndlp->rport ||
1258 ndlp->rport->scsi_target_id == -1 ||
1259 ndlp->rport->scsi_target_id >= LPFC_MAX_TARGET)) {
James Smart2e0fef82007-06-17 19:56:36 -05001260 spin_lock_irq(shost->host_lock);
James Smartde0c5b32007-04-25 09:52:27 -04001261 ndlp->nlp_flag |= NLP_TGT_NO_SCSIID;
James Smart2e0fef82007-06-17 19:56:36 -05001262 spin_unlock_irq(shost->host_lock);
1263 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
dea31012005-04-17 16:05:31 -05001264 }
James Smartde0c5b32007-04-25 09:52:27 -04001265}
1266
James Smart685f0bf2007-04-25 09:53:08 -04001267static char *
1268lpfc_nlp_state_name(char *buffer, size_t size, int state)
1269{
1270 static char *states[] = {
1271 [NLP_STE_UNUSED_NODE] = "UNUSED",
1272 [NLP_STE_PLOGI_ISSUE] = "PLOGI",
1273 [NLP_STE_ADISC_ISSUE] = "ADISC",
1274 [NLP_STE_REG_LOGIN_ISSUE] = "REGLOGIN",
1275 [NLP_STE_PRLI_ISSUE] = "PRLI",
1276 [NLP_STE_UNMAPPED_NODE] = "UNMAPPED",
1277 [NLP_STE_MAPPED_NODE] = "MAPPED",
1278 [NLP_STE_NPR_NODE] = "NPR",
1279 };
1280
1281 if (state < ARRAY_SIZE(states) && states[state])
1282 strlcpy(buffer, states[state], size);
1283 else
1284 snprintf(buffer, size, "unknown (%d)", state);
1285 return buffer;
1286}
1287
James Smartde0c5b32007-04-25 09:52:27 -04001288void
James Smart2e0fef82007-06-17 19:56:36 -05001289lpfc_nlp_set_state(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1290 int state)
James Smartde0c5b32007-04-25 09:52:27 -04001291{
James Smart2e0fef82007-06-17 19:56:36 -05001292 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smartde0c5b32007-04-25 09:52:27 -04001293 int old_state = ndlp->nlp_state;
James Smart685f0bf2007-04-25 09:53:08 -04001294 char name1[16], name2[16];
James Smartde0c5b32007-04-25 09:52:27 -04001295
James Smart2e0fef82007-06-17 19:56:36 -05001296 lpfc_printf_log(vport->phba, KERN_INFO, LOG_NODE,
James Smart685f0bf2007-04-25 09:53:08 -04001297 "%d:0904 NPort state transition x%06x, %s -> %s\n",
James Smart2e0fef82007-06-17 19:56:36 -05001298 vport->phba->brd_no,
James Smart685f0bf2007-04-25 09:53:08 -04001299 ndlp->nlp_DID,
1300 lpfc_nlp_state_name(name1, sizeof(name1), old_state),
1301 lpfc_nlp_state_name(name2, sizeof(name2), state));
James Smartde0c5b32007-04-25 09:52:27 -04001302 if (old_state == NLP_STE_NPR_NODE &&
1303 (ndlp->nlp_flag & NLP_DELAY_TMO) != 0 &&
1304 state != NLP_STE_NPR_NODE)
James Smart2e0fef82007-06-17 19:56:36 -05001305 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04001306 if (old_state == NLP_STE_UNMAPPED_NODE) {
1307 ndlp->nlp_flag &= ~NLP_TGT_NO_SCSIID;
1308 ndlp->nlp_type &= ~NLP_FC_NODE;
1309 }
1310
James Smart685f0bf2007-04-25 09:53:08 -04001311 if (list_empty(&ndlp->nlp_listp)) {
James Smart2e0fef82007-06-17 19:56:36 -05001312 spin_lock_irq(shost->host_lock);
1313 list_add_tail(&ndlp->nlp_listp, &vport->fc_nodes);
1314 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04001315 } else if (old_state)
James Smart2e0fef82007-06-17 19:56:36 -05001316 lpfc_nlp_counters(vport, old_state, -1);
James Smartde0c5b32007-04-25 09:52:27 -04001317
1318 ndlp->nlp_state = state;
James Smart2e0fef82007-06-17 19:56:36 -05001319 lpfc_nlp_counters(vport, state, 1);
1320 lpfc_nlp_state_cleanup(vport, ndlp, old_state, state);
James Smartde0c5b32007-04-25 09:52:27 -04001321}
1322
1323void
James Smart2e0fef82007-06-17 19:56:36 -05001324lpfc_dequeue_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
James Smartde0c5b32007-04-25 09:52:27 -04001325{
James Smart2e0fef82007-06-17 19:56:36 -05001326 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1327
James Smartde0c5b32007-04-25 09:52:27 -04001328 if ((ndlp->nlp_flag & NLP_DELAY_TMO) != 0)
James Smart2e0fef82007-06-17 19:56:36 -05001329 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04001330 if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
James Smart2e0fef82007-06-17 19:56:36 -05001331 lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
1332 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04001333 list_del_init(&ndlp->nlp_listp);
James Smart2e0fef82007-06-17 19:56:36 -05001334 spin_unlock_irq(shost->host_lock);
1335 lpfc_nlp_state_cleanup(vport, ndlp, ndlp->nlp_state, 0);
James Smartde0c5b32007-04-25 09:52:27 -04001336}
1337
1338void
James Smart2e0fef82007-06-17 19:56:36 -05001339lpfc_drop_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
James Smartde0c5b32007-04-25 09:52:27 -04001340{
James Smart2e0fef82007-06-17 19:56:36 -05001341 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1342
James Smartde0c5b32007-04-25 09:52:27 -04001343 if ((ndlp->nlp_flag & NLP_DELAY_TMO) != 0)
James Smart2e0fef82007-06-17 19:56:36 -05001344 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smartde0c5b32007-04-25 09:52:27 -04001345 if (ndlp->nlp_state && !list_empty(&ndlp->nlp_listp))
James Smart2e0fef82007-06-17 19:56:36 -05001346 lpfc_nlp_counters(vport, ndlp->nlp_state, -1);
1347 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04001348 list_del_init(&ndlp->nlp_listp);
James Smart2e0fef82007-06-17 19:56:36 -05001349 spin_unlock_irq(shost->host_lock);
James Smart329f9bc2007-04-25 09:53:01 -04001350 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001351}
1352
1353/*
1354 * Start / ReStart rescue timer for Discovery / RSCN handling
1355 */
1356void
James Smart2e0fef82007-06-17 19:56:36 -05001357lpfc_set_disctmo(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001358{
James Smart2e0fef82007-06-17 19:56:36 -05001359 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1360 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001361 uint32_t tmo;
1362
James Smart2e0fef82007-06-17 19:56:36 -05001363 if (vport->port_state == LPFC_LOCAL_CFG_LINK) {
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001364 /* For FAN, timeout should be greater then edtov */
1365 tmo = (((phba->fc_edtov + 999) / 1000) + 1);
1366 } else {
1367 /* Normal discovery timeout should be > then ELS/CT timeout
1368 * FC spec states we need 3 * ratov for CT requests
1369 */
1370 tmo = ((phba->fc_ratov * 3) + 3);
1371 }
dea31012005-04-17 16:05:31 -05001372
James Smart2e0fef82007-06-17 19:56:36 -05001373 mod_timer(&vport->fc_disctmo, jiffies + HZ * tmo);
1374 spin_lock_irq(shost->host_lock);
1375 vport->fc_flag |= FC_DISC_TMO;
1376 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001377
1378 /* Start Discovery Timer state <hba_state> */
1379 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1380 "%d:0247 Start Discovery Timer state x%x "
1381 "Data: x%x x%lx x%x x%x\n",
James Smart2e0fef82007-06-17 19:56:36 -05001382 phba->brd_no, vport->port_state, tmo,
1383 (unsigned long)&vport->fc_disctmo, vport->fc_plogi_cnt,
1384 vport->fc_adisc_cnt);
dea31012005-04-17 16:05:31 -05001385
1386 return;
1387}
1388
1389/*
1390 * Cancel rescue timer for Discovery / RSCN handling
1391 */
1392int
James Smart2e0fef82007-06-17 19:56:36 -05001393lpfc_can_disctmo(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001394{
James Smart2e0fef82007-06-17 19:56:36 -05001395 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1396 struct lpfc_hba *phba = vport->phba;
1397 unsigned long iflags;
1398
dea31012005-04-17 16:05:31 -05001399 /* Turn off discovery timer if its running */
James Smart2e0fef82007-06-17 19:56:36 -05001400 if (vport->fc_flag & FC_DISC_TMO) {
1401 spin_lock_irqsave(shost->host_lock, iflags);
1402 vport->fc_flag &= ~FC_DISC_TMO;
1403 spin_unlock_irqrestore(shost->host_lock, iflags);
1404 del_timer_sync(&vport->fc_disctmo);
1405 spin_lock_irqsave(&vport->work_port_lock, iflags);
1406 vport->work_port_events &= ~WORKER_DISC_TMO;
1407 spin_unlock_irqrestore(&vport->work_port_lock, iflags);
dea31012005-04-17 16:05:31 -05001408 }
1409
1410 /* Cancel Discovery Timer state <hba_state> */
1411 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1412 "%d:0248 Cancel Discovery Timer state x%x "
1413 "Data: x%x x%x x%x\n",
James Smart2e0fef82007-06-17 19:56:36 -05001414 phba->brd_no, vport->port_state, vport->fc_flag,
1415 vport->fc_plogi_cnt, vport->fc_adisc_cnt);
dea31012005-04-17 16:05:31 -05001416
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001417 return 0;
dea31012005-04-17 16:05:31 -05001418}
1419
1420/*
1421 * Check specified ring for outstanding IOCB on the SLI queue
1422 * Return true if iocb matches the specified nport
1423 */
1424int
James Smart2e0fef82007-06-17 19:56:36 -05001425lpfc_check_sli_ndlp(struct lpfc_hba *phba,
1426 struct lpfc_sli_ring *pring,
1427 struct lpfc_iocbq *iocb,
1428 struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05001429{
James Smart2e0fef82007-06-17 19:56:36 -05001430 struct lpfc_sli *psli = &phba->sli;
1431 IOCB_t *icmd = &iocb->iocb;
dea31012005-04-17 16:05:31 -05001432 if (pring->ringno == LPFC_ELS_RING) {
1433 switch (icmd->ulpCommand) {
1434 case CMD_GEN_REQUEST64_CR:
1435 if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001436 return 1;
dea31012005-04-17 16:05:31 -05001437 case CMD_ELS_REQUEST64_CR:
James Smart10d4e952006-04-15 11:53:15 -04001438 if (icmd->un.elsreq64.remoteID == ndlp->nlp_DID)
1439 return 1;
dea31012005-04-17 16:05:31 -05001440 case CMD_XMIT_ELS_RSP64_CX:
1441 if (iocb->context1 == (uint8_t *) ndlp)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001442 return 1;
dea31012005-04-17 16:05:31 -05001443 }
James Smarta4bc3372006-12-02 13:34:16 -05001444 } else if (pring->ringno == psli->extra_ring) {
dea31012005-04-17 16:05:31 -05001445
1446 } else if (pring->ringno == psli->fcp_ring) {
1447 /* Skip match check if waiting to relogin to FCP target */
1448 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
1449 (ndlp->nlp_flag & NLP_DELAY_TMO)) {
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001450 return 0;
dea31012005-04-17 16:05:31 -05001451 }
1452 if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) {
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001453 return 1;
dea31012005-04-17 16:05:31 -05001454 }
1455 } else if (pring->ringno == psli->next_ring) {
1456
1457 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001458 return 0;
dea31012005-04-17 16:05:31 -05001459}
1460
1461/*
1462 * Free resources / clean up outstanding I/Os
1463 * associated with nlp_rpi in the LPFC_NODELIST entry.
1464 */
1465static int
James Smart2e0fef82007-06-17 19:56:36 -05001466lpfc_no_rpi(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05001467{
James Smart2534ba72007-04-25 09:52:20 -04001468 LIST_HEAD(completions);
dea31012005-04-17 16:05:31 -05001469 struct lpfc_sli *psli;
1470 struct lpfc_sli_ring *pring;
1471 struct lpfc_iocbq *iocb, *next_iocb;
1472 IOCB_t *icmd;
1473 uint32_t rpi, i;
1474
1475 /*
1476 * Everything that matches on txcmplq will be returned
1477 * by firmware with a no rpi error.
1478 */
1479 psli = &phba->sli;
1480 rpi = ndlp->nlp_rpi;
1481 if (rpi) {
1482 /* Now process each ring */
1483 for (i = 0; i < psli->num_rings; i++) {
1484 pring = &psli->ring[i];
1485
James Smart2e0fef82007-06-17 19:56:36 -05001486 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001487 list_for_each_entry_safe(iocb, next_iocb, &pring->txq,
James Smart2e0fef82007-06-17 19:56:36 -05001488 list) {
dea31012005-04-17 16:05:31 -05001489 /*
1490 * Check to see if iocb matches the nport we are
1491 * looking for
1492 */
1493 if ((lpfc_check_sli_ndlp
1494 (phba, pring, iocb, ndlp))) {
1495 /* It matches, so deque and call compl
1496 with an error */
James Smart2534ba72007-04-25 09:52:20 -04001497 list_move_tail(&iocb->list,
1498 &completions);
dea31012005-04-17 16:05:31 -05001499 pring->txq_cnt--;
dea31012005-04-17 16:05:31 -05001500 }
1501 }
James Smart2e0fef82007-06-17 19:56:36 -05001502 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001503 }
1504 }
James Smart2534ba72007-04-25 09:52:20 -04001505
1506 while (!list_empty(&completions)) {
1507 iocb = list_get_first(&completions, struct lpfc_iocbq, list);
1508 list_del(&iocb->list);
1509
James Smart2e0fef82007-06-17 19:56:36 -05001510 if (!iocb->iocb_cmpl)
1511 lpfc_sli_release_iocbq(phba, iocb);
1512 else {
James Smart2534ba72007-04-25 09:52:20 -04001513 icmd = &iocb->iocb;
1514 icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
1515 icmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
James Smart2e0fef82007-06-17 19:56:36 -05001516 (iocb->iocb_cmpl)(phba, iocb, iocb);
1517 }
James Smart2534ba72007-04-25 09:52:20 -04001518 }
1519
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001520 return 0;
dea31012005-04-17 16:05:31 -05001521}
1522
1523/*
1524 * Free rpi associated with LPFC_NODELIST entry.
1525 * This routine is called from lpfc_freenode(), when we are removing
1526 * a LPFC_NODELIST entry. It is also called if the driver initiates a
1527 * LOGO that completes successfully, and we are waiting to PLOGI back
1528 * to the remote NPort. In addition, it is called after we receive
1529 * and unsolicated ELS cmd, send back a rsp, the rsp completes and
1530 * we are waiting to PLOGI back to the remote NPort.
1531 */
1532int
James Smart2e0fef82007-06-17 19:56:36 -05001533lpfc_unreg_rpi(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05001534{
James Smart2e0fef82007-06-17 19:56:36 -05001535 struct lpfc_hba *phba = vport->phba;
1536 LPFC_MBOXQ_t *mbox;
dea31012005-04-17 16:05:31 -05001537 int rc;
1538
1539 if (ndlp->nlp_rpi) {
James Smart2e0fef82007-06-17 19:56:36 -05001540 mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
1541 if (mbox) {
dea31012005-04-17 16:05:31 -05001542 lpfc_unreg_login(phba, ndlp->nlp_rpi, mbox);
James Smarted957682007-06-17 19:56:37 -05001543 mbox->vport = vport;
dea31012005-04-17 16:05:31 -05001544 mbox->mbox_cmpl=lpfc_sli_def_mbox_cmpl;
1545 rc = lpfc_sli_issue_mbox
1546 (phba, mbox, (MBX_NOWAIT | MBX_STOP_IOCB));
1547 if (rc == MBX_NOT_FINISHED)
James Smart2e0fef82007-06-17 19:56:36 -05001548 mempool_free(mbox, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05001549 }
dea31012005-04-17 16:05:31 -05001550 lpfc_no_rpi(phba, ndlp);
1551 ndlp->nlp_rpi = 0;
1552 return 1;
1553 }
1554 return 0;
1555}
1556
1557/*
1558 * Free resources associated with LPFC_NODELIST entry
1559 * so it can be freed.
1560 */
1561static int
James Smart2e0fef82007-06-17 19:56:36 -05001562lpfc_cleanup_node(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05001563{
James Smart2e0fef82007-06-17 19:56:36 -05001564 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1565 struct lpfc_hba *phba = vport->phba;
1566 LPFC_MBOXQ_t *mb, *nextmb;
dea31012005-04-17 16:05:31 -05001567 struct lpfc_dmabuf *mp;
dea31012005-04-17 16:05:31 -05001568
1569 /* Cleanup node for NPort <nlp_DID> */
1570 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1571 "%d:0900 Cleanup node for NPort x%x "
1572 "Data: x%x x%x x%x\n",
1573 phba->brd_no, ndlp->nlp_DID, ndlp->nlp_flag,
1574 ndlp->nlp_state, ndlp->nlp_rpi);
1575
James Smart2e0fef82007-06-17 19:56:36 -05001576 lpfc_dequeue_node(vport, ndlp);
dea31012005-04-17 16:05:31 -05001577
dea31012005-04-17 16:05:31 -05001578 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
1579 if ((mb = phba->sli.mbox_active)) {
1580 if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
1581 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1582 mb->context2 = NULL;
1583 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1584 }
1585 }
James Smart33ccf8d2006-08-17 11:57:58 -04001586
James Smart2e0fef82007-06-17 19:56:36 -05001587 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001588 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
1589 if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
1590 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1591 mp = (struct lpfc_dmabuf *) (mb->context1);
1592 if (mp) {
James Smart2e0fef82007-06-17 19:56:36 -05001593 __lpfc_mbuf_free(phba, mp->virt, mp->phys);
dea31012005-04-17 16:05:31 -05001594 kfree(mp);
1595 }
1596 list_del(&mb->list);
1597 mempool_free(mb, phba->mbox_mem_pool);
James Smart329f9bc2007-04-25 09:53:01 -04001598 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05001599 }
1600 }
James Smart2e0fef82007-06-17 19:56:36 -05001601 spin_unlock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001602
James Smart07951072007-04-25 09:51:38 -04001603 lpfc_els_abort(phba,ndlp);
James Smart2e0fef82007-06-17 19:56:36 -05001604 spin_lock_irq(shost->host_lock);
James Smartc01f3202006-08-18 17:47:08 -04001605 ndlp->nlp_flag &= ~NLP_DELAY_TMO;
James Smart2e0fef82007-06-17 19:56:36 -05001606 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001607
Jamie Wellnitz5024ab12006-02-28 19:25:28 -05001608 ndlp->nlp_last_elscmd = 0;
dea31012005-04-17 16:05:31 -05001609 del_timer_sync(&ndlp->nlp_delayfunc);
1610
dea31012005-04-17 16:05:31 -05001611 if (!list_empty(&ndlp->els_retry_evt.evt_listp))
1612 list_del_init(&ndlp->els_retry_evt.evt_listp);
1613
James Smart2e0fef82007-06-17 19:56:36 -05001614 lpfc_unreg_rpi(vport, ndlp);
dea31012005-04-17 16:05:31 -05001615
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001616 return 0;
dea31012005-04-17 16:05:31 -05001617}
1618
1619/*
1620 * Check to see if we can free the nlp back to the freelist.
1621 * If we are in the middle of using the nlp in the discovery state
1622 * machine, defer the free till we reach the end of the state machine.
1623 */
James Smart329f9bc2007-04-25 09:53:01 -04001624static void
James Smart2e0fef82007-06-17 19:56:36 -05001625lpfc_nlp_remove(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05001626{
James Smart1dcb58e2007-04-25 09:51:30 -04001627 struct lpfc_rport_data *rdata;
dea31012005-04-17 16:05:31 -05001628
1629 if (ndlp->nlp_flag & NLP_DELAY_TMO) {
James Smart2e0fef82007-06-17 19:56:36 -05001630 lpfc_cancel_retry_delay_tmo(vport, ndlp);
dea31012005-04-17 16:05:31 -05001631 }
1632
James Smart2e0fef82007-06-17 19:56:36 -05001633 lpfc_cleanup_node(vport, ndlp);
James Smart1dcb58e2007-04-25 09:51:30 -04001634
James Smart2e0fef82007-06-17 19:56:36 -05001635 /*
1636 * We should never get here with a non-NULL ndlp->rport. But
1637 * if we do, drop the reference to the rport. That seems the
1638 * intelligent thing to do.
1639 */
1640 if (ndlp->rport && !(vport->load_flag & FC_UNLOADING)) {
James Smart329f9bc2007-04-25 09:53:01 -04001641 put_device(&ndlp->rport->dev);
1642 rdata = ndlp->rport->dd_data;
1643 rdata->pnode = NULL;
1644 ndlp->rport = NULL;
dea31012005-04-17 16:05:31 -05001645 }
dea31012005-04-17 16:05:31 -05001646}
1647
1648static int
James Smart2e0fef82007-06-17 19:56:36 -05001649lpfc_matchdid(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
1650 uint32_t did)
dea31012005-04-17 16:05:31 -05001651{
James Smart2e0fef82007-06-17 19:56:36 -05001652 D_ID mydid, ndlpdid, matchdid;
dea31012005-04-17 16:05:31 -05001653
1654 if (did == Bcast_DID)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001655 return 0;
dea31012005-04-17 16:05:31 -05001656
1657 if (ndlp->nlp_DID == 0) {
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001658 return 0;
dea31012005-04-17 16:05:31 -05001659 }
1660
1661 /* First check for Direct match */
1662 if (ndlp->nlp_DID == did)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001663 return 1;
dea31012005-04-17 16:05:31 -05001664
1665 /* Next check for area/domain identically equals 0 match */
James Smart2e0fef82007-06-17 19:56:36 -05001666 mydid.un.word = vport->fc_myDID;
dea31012005-04-17 16:05:31 -05001667 if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) {
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001668 return 0;
dea31012005-04-17 16:05:31 -05001669 }
1670
1671 matchdid.un.word = did;
1672 ndlpdid.un.word = ndlp->nlp_DID;
1673 if (matchdid.un.b.id == ndlpdid.un.b.id) {
1674 if ((mydid.un.b.domain == matchdid.un.b.domain) &&
1675 (mydid.un.b.area == matchdid.un.b.area)) {
1676 if ((ndlpdid.un.b.domain == 0) &&
1677 (ndlpdid.un.b.area == 0)) {
1678 if (ndlpdid.un.b.id)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001679 return 1;
dea31012005-04-17 16:05:31 -05001680 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001681 return 0;
dea31012005-04-17 16:05:31 -05001682 }
1683
1684 matchdid.un.word = ndlp->nlp_DID;
1685 if ((mydid.un.b.domain == ndlpdid.un.b.domain) &&
1686 (mydid.un.b.area == ndlpdid.un.b.area)) {
1687 if ((matchdid.un.b.domain == 0) &&
1688 (matchdid.un.b.area == 0)) {
1689 if (matchdid.un.b.id)
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001690 return 1;
dea31012005-04-17 16:05:31 -05001691 }
1692 }
1693 }
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001694 return 0;
dea31012005-04-17 16:05:31 -05001695}
1696
James Smart685f0bf2007-04-25 09:53:08 -04001697/* Search for a nodelist entry */
James Smart2e0fef82007-06-17 19:56:36 -05001698static struct lpfc_nodelist *
1699__lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05001700{
James Smart2e0fef82007-06-17 19:56:36 -05001701 struct lpfc_hba *phba = vport->phba;
James Smart2fb9bd82006-12-02 13:33:57 -05001702 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05001703 uint32_t data1;
1704
James Smart2e0fef82007-06-17 19:56:36 -05001705 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
1706 if (lpfc_matchdid(vport, ndlp, did)) {
James Smart685f0bf2007-04-25 09:53:08 -04001707 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1708 ((uint32_t) ndlp->nlp_xri << 16) |
1709 ((uint32_t) ndlp->nlp_type << 8) |
1710 ((uint32_t) ndlp->nlp_rpi & 0xff));
1711 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1712 "%d:0929 FIND node DID "
1713 " Data: x%p x%x x%x x%x\n",
1714 phba->brd_no,
1715 ndlp, ndlp->nlp_DID,
1716 ndlp->nlp_flag, data1);
James Smart685f0bf2007-04-25 09:53:08 -04001717 return ndlp;
dea31012005-04-17 16:05:31 -05001718 }
1719 }
Jamie Wellnitz66a9ed62006-02-28 22:33:10 -05001720
dea31012005-04-17 16:05:31 -05001721 /* FIND node did <did> NOT FOUND */
James Smart2fb9bd82006-12-02 13:33:57 -05001722 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
James Smart685f0bf2007-04-25 09:53:08 -04001723 "%d:0932 FIND node did x%x NOT FOUND.\n",
1724 phba->brd_no, did);
dea31012005-04-17 16:05:31 -05001725 return NULL;
1726}
1727
1728struct lpfc_nodelist *
James Smart2e0fef82007-06-17 19:56:36 -05001729lpfc_findnode_did(struct lpfc_vport *vport, uint32_t did)
dea31012005-04-17 16:05:31 -05001730{
James Smart2e0fef82007-06-17 19:56:36 -05001731 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
dea31012005-04-17 16:05:31 -05001732 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05001733
James Smart2e0fef82007-06-17 19:56:36 -05001734 spin_lock_irq(shost->host_lock);
1735 ndlp = __lpfc_findnode_did(vport, did);
1736 spin_unlock_irq(shost->host_lock);
1737 return ndlp;
1738}
1739
1740struct lpfc_nodelist *
1741lpfc_setup_disc_node(struct lpfc_vport *vport, uint32_t did)
1742{
1743 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1744 struct lpfc_nodelist *ndlp;
1745
1746 ndlp = lpfc_findnode_did(vport, did);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001747 if (!ndlp) {
James Smart2e0fef82007-06-17 19:56:36 -05001748 if ((vport->fc_flag & FC_RSCN_MODE) != 0 &&
1749 lpfc_rscn_payload_check(vport, did) == 0)
dea31012005-04-17 16:05:31 -05001750 return NULL;
1751 ndlp = (struct lpfc_nodelist *)
James Smart2e0fef82007-06-17 19:56:36 -05001752 mempool_alloc(vport->phba->nlp_mem_pool, GFP_KERNEL);
dea31012005-04-17 16:05:31 -05001753 if (!ndlp)
1754 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05001755 lpfc_nlp_init(vport, ndlp, did);
1756 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1757 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001758 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001759 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001760 return ndlp;
1761 }
James Smart2e0fef82007-06-17 19:56:36 -05001762 if (vport->fc_flag & FC_RSCN_MODE) {
1763 if (lpfc_rscn_payload_check(vport, did)) {
1764 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001765 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001766 spin_unlock_irq(shost->host_lock);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05001767
1768 /* Since this node is marked for discovery,
1769 * delay timeout is not needed.
1770 */
James Smartfdcebe22006-03-07 15:04:01 -05001771 if (ndlp->nlp_flag & NLP_DELAY_TMO)
James Smart2e0fef82007-06-17 19:56:36 -05001772 lpfc_cancel_retry_delay_tmo(vport, ndlp);
James Smart071fbd3d2006-04-15 11:53:20 -04001773 } else
dea31012005-04-17 16:05:31 -05001774 ndlp = NULL;
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001775 } else {
James Smart685f0bf2007-04-25 09:53:08 -04001776 if (ndlp->nlp_state == NLP_STE_ADISC_ISSUE ||
1777 ndlp->nlp_state == NLP_STE_PLOGI_ISSUE)
dea31012005-04-17 16:05:31 -05001778 return NULL;
James Smart2e0fef82007-06-17 19:56:36 -05001779 lpfc_nlp_set_state(vport, ndlp, NLP_STE_NPR_NODE);
1780 spin_lock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001781 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
James Smart2e0fef82007-06-17 19:56:36 -05001782 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001783 }
1784 return ndlp;
1785}
1786
1787/* Build a list of nodes to discover based on the loopmap */
1788void
James Smart2e0fef82007-06-17 19:56:36 -05001789lpfc_disc_list_loopmap(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001790{
James Smart2e0fef82007-06-17 19:56:36 -05001791 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001792 int j;
1793 uint32_t alpa, index;
1794
James Smart2e0fef82007-06-17 19:56:36 -05001795 if (!lpfc_is_link_up(phba))
dea31012005-04-17 16:05:31 -05001796 return;
James Smart2e0fef82007-06-17 19:56:36 -05001797
1798 if (phba->fc_topology != TOPOLOGY_LOOP)
dea31012005-04-17 16:05:31 -05001799 return;
dea31012005-04-17 16:05:31 -05001800
1801 /* Check for loop map present or not */
1802 if (phba->alpa_map[0]) {
1803 for (j = 1; j <= phba->alpa_map[0]; j++) {
1804 alpa = phba->alpa_map[j];
James Smart2e0fef82007-06-17 19:56:36 -05001805 if (((vport->fc_myDID & 0xff) == alpa) || (alpa == 0))
dea31012005-04-17 16:05:31 -05001806 continue;
James Smart2e0fef82007-06-17 19:56:36 -05001807 lpfc_setup_disc_node(vport, alpa);
dea31012005-04-17 16:05:31 -05001808 }
1809 } else {
1810 /* No alpamap, so try all alpa's */
1811 for (j = 0; j < FC_MAXLOOP; j++) {
1812 /* If cfg_scan_down is set, start from highest
1813 * ALPA (0xef) to lowest (0x1).
1814 */
1815 if (phba->cfg_scan_down)
1816 index = j;
1817 else
1818 index = FC_MAXLOOP - j - 1;
1819 alpa = lpfcAlpaArray[index];
James Smart2e0fef82007-06-17 19:56:36 -05001820 if ((vport->fc_myDID & 0xff) == alpa)
dea31012005-04-17 16:05:31 -05001821 continue;
James Smart2e0fef82007-06-17 19:56:36 -05001822 lpfc_setup_disc_node(vport, alpa);
dea31012005-04-17 16:05:31 -05001823 }
1824 }
1825 return;
1826}
1827
dea31012005-04-17 16:05:31 -05001828void
James Smart2e0fef82007-06-17 19:56:36 -05001829lpfc_issue_clear_la(struct lpfc_hba *phba, struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05001830{
dea31012005-04-17 16:05:31 -05001831 LPFC_MBOXQ_t *mbox;
James Smart2e0fef82007-06-17 19:56:36 -05001832 struct lpfc_sli *psli = &phba->sli;
1833 struct lpfc_sli_ring *extra_ring = &psli->ring[psli->extra_ring];
1834 struct lpfc_sli_ring *fcp_ring = &psli->ring[psli->fcp_ring];
1835 struct lpfc_sli_ring *next_ring = &psli->ring[psli->next_ring];
1836 int rc;
1837
1838 /* Link up discovery */
1839 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL)) != NULL) {
1840 phba->link_state = LPFC_CLEAR_LA;
1841 lpfc_clear_la(phba, mbox);
1842 mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
1843 mbox->vport = vport;
1844 rc = lpfc_sli_issue_mbox(phba, mbox, (MBX_NOWAIT |
1845 MBX_STOP_IOCB));
1846 if (rc == MBX_NOT_FINISHED) {
1847 mempool_free(mbox, phba->mbox_mem_pool);
1848 lpfc_disc_flush_list(vport);
1849 extra_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
1850 fcp_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
1851 next_ring->flag &= ~LPFC_STOP_IOCB_EVENT;
1852 vport->port_state = LPFC_VPORT_READY;
1853 }
1854 }
1855}
1856
1857/* Start Link up / RSCN discovery on NPR nodes */
1858void
1859lpfc_disc_start(struct lpfc_vport *vport)
1860{
1861 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
1862 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05001863 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart685f0bf2007-04-25 09:53:08 -04001864 uint32_t num_sent;
dea31012005-04-17 16:05:31 -05001865 uint32_t clear_la_pending;
James Smart685f0bf2007-04-25 09:53:08 -04001866 int did_changed;
dea31012005-04-17 16:05:31 -05001867
James Smart2e0fef82007-06-17 19:56:36 -05001868 if (!lpfc_is_link_up(phba))
dea31012005-04-17 16:05:31 -05001869 return;
James Smart2e0fef82007-06-17 19:56:36 -05001870
1871 if (phba->link_state == LPFC_CLEAR_LA)
dea31012005-04-17 16:05:31 -05001872 clear_la_pending = 1;
1873 else
1874 clear_la_pending = 0;
1875
James Smart2e0fef82007-06-17 19:56:36 -05001876 if (vport->port_state < LPFC_VPORT_READY)
1877 vport->port_state = LPFC_DISC_AUTH;
dea31012005-04-17 16:05:31 -05001878
James Smart2e0fef82007-06-17 19:56:36 -05001879 lpfc_set_disctmo(vport);
1880
1881 if (vport->fc_prevDID == vport->fc_myDID)
dea31012005-04-17 16:05:31 -05001882 did_changed = 0;
James Smart2e0fef82007-06-17 19:56:36 -05001883 else
dea31012005-04-17 16:05:31 -05001884 did_changed = 1;
James Smart2e0fef82007-06-17 19:56:36 -05001885
1886 vport->fc_prevDID = vport->fc_myDID;
1887 vport->num_disc_nodes = 0;
dea31012005-04-17 16:05:31 -05001888
1889 /* Start Discovery state <hba_state> */
1890 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1891 "%d:0202 Start Discovery hba state x%x "
1892 "Data: x%x x%x x%x\n",
James Smart2e0fef82007-06-17 19:56:36 -05001893 phba->brd_no, vport->port_state, vport->fc_flag,
1894 vport->fc_plogi_cnt, vport->fc_adisc_cnt);
dea31012005-04-17 16:05:31 -05001895
1896 /* If our did changed, we MUST do PLOGI */
James Smart2e0fef82007-06-17 19:56:36 -05001897 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes, nlp_listp) {
James Smart685f0bf2007-04-25 09:53:08 -04001898 if (ndlp->nlp_state == NLP_STE_NPR_NODE &&
1899 (ndlp->nlp_flag & NLP_NPR_2B_DISC) != 0 &&
1900 did_changed) {
James Smart2e0fef82007-06-17 19:56:36 -05001901 spin_lock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04001902 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
James Smart2e0fef82007-06-17 19:56:36 -05001903 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001904 }
1905 }
1906
1907 /* First do ADISCs - if any */
James Smart2e0fef82007-06-17 19:56:36 -05001908 num_sent = lpfc_els_disc_adisc(vport);
dea31012005-04-17 16:05:31 -05001909
1910 if (num_sent)
1911 return;
1912
James Smart2e0fef82007-06-17 19:56:36 -05001913 if (vport->port_state < LPFC_VPORT_READY && !clear_la_pending) {
1914 if (vport->port_type == LPFC_PHYSICAL_PORT) {
dea31012005-04-17 16:05:31 -05001915 /* If we get here, there is nothing to ADISC */
James Smart2e0fef82007-06-17 19:56:36 -05001916 lpfc_issue_clear_la(phba, vport);
1917 } else if (!(vport->fc_flag & FC_ABORT_DISCOVERY)) {
1918
1919 vport->num_disc_nodes = 0;
1920 /* go thru NPR nodes and issue ELS PLOGIs */
1921 if (vport->fc_npr_cnt)
1922 lpfc_els_disc_plogi(vport);
1923
1924 if (!vport->num_disc_nodes) {
1925 spin_lock_irq(shost->host_lock);
1926 vport->fc_flag &= ~FC_NDISC_ACTIVE;
1927 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05001928 }
James Smart2e0fef82007-06-17 19:56:36 -05001929 vport->port_state = LPFC_VPORT_READY;
dea31012005-04-17 16:05:31 -05001930 }
1931 } else {
1932 /* Next do PLOGIs - if any */
James Smart2e0fef82007-06-17 19:56:36 -05001933 num_sent = lpfc_els_disc_plogi(vport);
dea31012005-04-17 16:05:31 -05001934
1935 if (num_sent)
1936 return;
1937
James Smart2e0fef82007-06-17 19:56:36 -05001938 if (vport->fc_flag & FC_RSCN_MODE) {
dea31012005-04-17 16:05:31 -05001939 /* Check to see if more RSCNs came in while we
1940 * were processing this one.
1941 */
James Smart2e0fef82007-06-17 19:56:36 -05001942 if ((vport->fc_rscn_id_cnt == 0) &&
1943 (!(vport->fc_flag & FC_RSCN_DISCOVERY))) {
1944 spin_lock_irq(shost->host_lock);
1945 vport->fc_flag &= ~FC_RSCN_MODE;
1946 spin_unlock_irq(shost->host_lock);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05001947 } else
James Smart2e0fef82007-06-17 19:56:36 -05001948 lpfc_els_handle_rscn(vport);
dea31012005-04-17 16:05:31 -05001949 }
1950 }
1951 return;
1952}
1953
1954/*
1955 * Ignore completion for all IOCBs on tx and txcmpl queue for ELS
1956 * ring the match the sppecified nodelist.
1957 */
1958static void
James Smart2e0fef82007-06-17 19:56:36 -05001959lpfc_free_tx(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
dea31012005-04-17 16:05:31 -05001960{
James Smart2534ba72007-04-25 09:52:20 -04001961 LIST_HEAD(completions);
dea31012005-04-17 16:05:31 -05001962 struct lpfc_sli *psli;
1963 IOCB_t *icmd;
1964 struct lpfc_iocbq *iocb, *next_iocb;
1965 struct lpfc_sli_ring *pring;
dea31012005-04-17 16:05:31 -05001966
1967 psli = &phba->sli;
1968 pring = &psli->ring[LPFC_ELS_RING];
1969
1970 /* Error matching iocb on txq or txcmplq
1971 * First check the txq.
1972 */
James Smart2e0fef82007-06-17 19:56:36 -05001973 spin_lock_irq(&phba->hbalock);
dea31012005-04-17 16:05:31 -05001974 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
1975 if (iocb->context1 != ndlp) {
1976 continue;
1977 }
1978 icmd = &iocb->iocb;
1979 if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
1980 (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
1981
James Smart2534ba72007-04-25 09:52:20 -04001982 list_move_tail(&iocb->list, &completions);
dea31012005-04-17 16:05:31 -05001983 pring->txq_cnt--;
dea31012005-04-17 16:05:31 -05001984 }
1985 }
1986
1987 /* Next check the txcmplq */
1988 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
1989 if (iocb->context1 != ndlp) {
1990 continue;
1991 }
1992 icmd = &iocb->iocb;
James Smart2e0fef82007-06-17 19:56:36 -05001993 if (icmd->ulpCommand == CMD_ELS_REQUEST64_CR ||
1994 icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX) {
James Smart2534ba72007-04-25 09:52:20 -04001995 lpfc_sli_issue_abort_iotag(phba, pring, iocb);
dea31012005-04-17 16:05:31 -05001996 }
1997 }
James Smart2e0fef82007-06-17 19:56:36 -05001998 spin_unlock_irq(&phba->hbalock);
James Smart2534ba72007-04-25 09:52:20 -04001999
2000 while (!list_empty(&completions)) {
2001 iocb = list_get_first(&completions, struct lpfc_iocbq, list);
2002 list_del(&iocb->list);
2003
James Smart2e0fef82007-06-17 19:56:36 -05002004 if (!iocb->iocb_cmpl)
2005 lpfc_sli_release_iocbq(phba, iocb);
2006 else {
James Smart2534ba72007-04-25 09:52:20 -04002007 icmd = &iocb->iocb;
2008 icmd->ulpStatus = IOSTAT_LOCAL_REJECT;
2009 icmd->un.ulpWord[4] = IOERR_SLI_ABORTED;
2010 (iocb->iocb_cmpl) (phba, iocb, iocb);
James Smart2e0fef82007-06-17 19:56:36 -05002011 }
James Smart2534ba72007-04-25 09:52:20 -04002012 }
dea31012005-04-17 16:05:31 -05002013}
2014
2015void
James Smart2e0fef82007-06-17 19:56:36 -05002016lpfc_disc_flush_list(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002017{
2018 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05002019 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002020
James Smart2e0fef82007-06-17 19:56:36 -05002021 if (vport->fc_plogi_cnt || vport->fc_adisc_cnt) {
2022 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
James Smart685f0bf2007-04-25 09:53:08 -04002023 nlp_listp) {
2024 if (ndlp->nlp_state == NLP_STE_PLOGI_ISSUE ||
2025 ndlp->nlp_state == NLP_STE_ADISC_ISSUE) {
2026 lpfc_free_tx(phba, ndlp);
2027 lpfc_nlp_put(ndlp);
2028 }
dea31012005-04-17 16:05:31 -05002029 }
2030 }
dea31012005-04-17 16:05:31 -05002031}
2032
2033/*****************************************************************************/
2034/*
2035 * NAME: lpfc_disc_timeout
2036 *
2037 * FUNCTION: Fibre Channel driver discovery timeout routine.
2038 *
2039 * EXECUTION ENVIRONMENT: interrupt only
2040 *
2041 * CALLED FROM:
2042 * Timer function
2043 *
2044 * RETURNS:
2045 * none
2046 */
2047/*****************************************************************************/
2048void
2049lpfc_disc_timeout(unsigned long ptr)
2050{
James Smart2e0fef82007-06-17 19:56:36 -05002051 struct lpfc_vport *vport = (struct lpfc_vport *) ptr;
2052 struct lpfc_hba *phba = vport->phba;
dea31012005-04-17 16:05:31 -05002053 unsigned long flags = 0;
2054
2055 if (unlikely(!phba))
2056 return;
2057
James Smart2e0fef82007-06-17 19:56:36 -05002058 if ((vport->work_port_events & WORKER_DISC_TMO) == 0) {
2059 spin_lock_irqsave(&vport->work_port_lock, flags);
2060 vport->work_port_events |= WORKER_DISC_TMO;
2061 spin_unlock_irqrestore(&vport->work_port_lock, flags);
2062
dea31012005-04-17 16:05:31 -05002063 if (phba->work_wait)
2064 wake_up(phba->work_wait);
2065 }
dea31012005-04-17 16:05:31 -05002066 return;
2067}
2068
2069static void
James Smart2e0fef82007-06-17 19:56:36 -05002070lpfc_disc_timeout_handler(struct lpfc_vport *vport)
dea31012005-04-17 16:05:31 -05002071{
James Smart2e0fef82007-06-17 19:56:36 -05002072 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
2073 struct lpfc_hba *phba = vport->phba;
2074 struct lpfc_sli *psli = &phba->sli;
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002075 struct lpfc_nodelist *ndlp, *next_ndlp;
James Smart2e0fef82007-06-17 19:56:36 -05002076 LPFC_MBOXQ_t *clearlambox, *initlinkmbox;
dea31012005-04-17 16:05:31 -05002077 int rc, clrlaerr = 0;
2078
James Smart2e0fef82007-06-17 19:56:36 -05002079 if (!(vport->fc_flag & FC_DISC_TMO))
dea31012005-04-17 16:05:31 -05002080 return;
2081
James Smart2e0fef82007-06-17 19:56:36 -05002082 spin_lock_irq(shost->host_lock);
2083 vport->fc_flag &= ~FC_DISC_TMO;
2084 spin_unlock_irq(shost->host_lock);
dea31012005-04-17 16:05:31 -05002085
James Smart2e0fef82007-06-17 19:56:36 -05002086 switch (vport->port_state) {
dea31012005-04-17 16:05:31 -05002087
2088 case LPFC_LOCAL_CFG_LINK:
James Smart2e0fef82007-06-17 19:56:36 -05002089 /* port_state is identically LPFC_LOCAL_CFG_LINK while waiting for
2090 * FAN
2091 */
2092 /* FAN timeout */
James Smarted957682007-06-17 19:56:37 -05002093 lpfc_printf_log(phba, KERN_WARNING, LOG_DISCOVERY,
dea31012005-04-17 16:05:31 -05002094 "%d:0221 FAN timeout\n",
2095 phba->brd_no);
2096
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002097 /* Start discovery by sending FLOGI, clean up old rpis */
James Smart2e0fef82007-06-17 19:56:36 -05002098 list_for_each_entry_safe(ndlp, next_ndlp, &vport->fc_nodes,
James Smart685f0bf2007-04-25 09:53:08 -04002099 nlp_listp) {
2100 if (ndlp->nlp_state != NLP_STE_NPR_NODE)
2101 continue;
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002102 if (ndlp->nlp_type & NLP_FABRIC) {
2103 /* Clean up the ndlp on Fabric connections */
James Smart2e0fef82007-06-17 19:56:36 -05002104 lpfc_drop_node(vport, ndlp);
Jamie Wellnitz2fe165b2006-02-28 19:25:31 -05002105 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002106 /* Fail outstanding IO now since device
2107 * is marked for PLOGI.
2108 */
James Smart2e0fef82007-06-17 19:56:36 -05002109 lpfc_unreg_rpi(vport, ndlp);
Jamie Wellnitzc9f8735b2006-02-28 19:25:23 -05002110 }
2111 }
James Smart2e0fef82007-06-17 19:56:36 -05002112 vport->port_state = LPFC_FLOGI;
2113 lpfc_set_disctmo(vport);
2114 lpfc_initial_flogi(vport);
dea31012005-04-17 16:05:31 -05002115 break;
2116
2117 case LPFC_FLOGI:
James Smart2e0fef82007-06-17 19:56:36 -05002118 /* port_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */
dea31012005-04-17 16:05:31 -05002119 /* Initial FLOGI timeout */
James Smarted957682007-06-17 19:56:37 -05002120 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
dea31012005-04-17 16:05:31 -05002121 "%d:0222 Initial FLOGI timeout\n",
2122 phba->brd_no);
2123
2124 /* Assume no Fabric and go on with discovery.
2125 * Check for outstanding ELS FLOGI to abort.
2126 */
2127
2128 /* FLOGI failed, so just use loop map to make discovery list */
James Smart2e0fef82007-06-17 19:56:36 -05002129 lpfc_disc_list_loopmap(vport);
dea31012005-04-17 16:05:31 -05002130
2131 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002132 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -05002133 break;
2134
2135 case LPFC_FABRIC_CFG_LINK:
2136 /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for
2137 NameServer login */
2138 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2139 "%d:0223 Timeout while waiting for NameServer "
2140 "login\n", phba->brd_no);
2141
2142 /* Next look for NameServer ndlp */
James Smart2e0fef82007-06-17 19:56:36 -05002143 ndlp = lpfc_findnode_did(vport, NameServer_DID);
dea31012005-04-17 16:05:31 -05002144 if (ndlp)
James Smart329f9bc2007-04-25 09:53:01 -04002145 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002146 /* Start discovery */
James Smart2e0fef82007-06-17 19:56:36 -05002147 lpfc_disc_start(vport);
dea31012005-04-17 16:05:31 -05002148 break;
2149
2150 case LPFC_NS_QRY:
2151 /* Check for wait for NameServer Rsp timeout */
2152 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2153 "%d:0224 NameServer Query timeout "
2154 "Data: x%x x%x\n",
2155 phba->brd_no,
James Smart2e0fef82007-06-17 19:56:36 -05002156 vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
dea31012005-04-17 16:05:31 -05002157
James Smart2e0fef82007-06-17 19:56:36 -05002158 ndlp = lpfc_findnode_did(vport, NameServer_DID);
James Smart685f0bf2007-04-25 09:53:08 -04002159 if (ndlp && ndlp->nlp_state == NLP_STE_UNMAPPED_NODE) {
James Smart2e0fef82007-06-17 19:56:36 -05002160 if (vport->fc_ns_retry < LPFC_MAX_NS_RETRY) {
dea31012005-04-17 16:05:31 -05002161 /* Try it one more time */
James Smart2e0fef82007-06-17 19:56:36 -05002162 rc = lpfc_ns_cmd(vport, ndlp, SLI_CTNS_GID_FT);
dea31012005-04-17 16:05:31 -05002163 if (rc == 0)
2164 break;
2165 }
James Smart2e0fef82007-06-17 19:56:36 -05002166 vport->fc_ns_retry = 0;
dea31012005-04-17 16:05:31 -05002167 }
2168
2169 /* Nothing to authenticate, so CLEAR_LA right now */
2170 clearlambox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2171 if (!clearlambox) {
2172 clrlaerr = 1;
2173 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2174 "%d:0226 Device Discovery "
2175 "completion error\n",
2176 phba->brd_no);
James Smart2e0fef82007-06-17 19:56:36 -05002177 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05002178 break;
2179 }
2180
James Smart2e0fef82007-06-17 19:56:36 -05002181 phba->link_state = LPFC_CLEAR_LA;
dea31012005-04-17 16:05:31 -05002182 lpfc_clear_la(phba, clearlambox);
2183 clearlambox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
James Smart2e0fef82007-06-17 19:56:36 -05002184 clearlambox->vport = vport;
dea31012005-04-17 16:05:31 -05002185 rc = lpfc_sli_issue_mbox(phba, clearlambox,
2186 (MBX_NOWAIT | MBX_STOP_IOCB));
2187 if (rc == MBX_NOT_FINISHED) {
2188 mempool_free(clearlambox, phba->mbox_mem_pool);
2189 clrlaerr = 1;
2190 break;
2191 }
2192
2193 /* Setup and issue mailbox INITIALIZE LINK command */
2194 initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2195 if (!initlinkmbox) {
2196 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
James Smartdca94792006-08-01 07:34:08 -04002197 "%d:0206 Device Discovery "
dea31012005-04-17 16:05:31 -05002198 "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
2204 lpfc_linkdown(phba);
2205 lpfc_init_link(phba, initlinkmbox, phba->cfg_topology,
2206 phba->cfg_link_speed);
2207 initlinkmbox->mb.un.varInitLnk.lipsr_AL_PA = 0;
James Smarted957682007-06-17 19:56:37 -05002208 initlinkmbox->vport = vport;
dea31012005-04-17 16:05:31 -05002209 rc = lpfc_sli_issue_mbox(phba, initlinkmbox,
2210 (MBX_NOWAIT | MBX_STOP_IOCB));
James Smart5b8bd0c2007-04-25 09:52:49 -04002211 lpfc_set_loopback_flag(phba);
dea31012005-04-17 16:05:31 -05002212 if (rc == MBX_NOT_FINISHED)
2213 mempool_free(initlinkmbox, phba->mbox_mem_pool);
2214
2215 break;
2216
2217 case LPFC_DISC_AUTH:
2218 /* Node Authentication timeout */
James Smarted957682007-06-17 19:56:37 -05002219 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
dea31012005-04-17 16:05:31 -05002220 "%d:0227 Node Authentication timeout\n",
2221 phba->brd_no);
James Smart2e0fef82007-06-17 19:56:36 -05002222 lpfc_disc_flush_list(vport);
2223
dea31012005-04-17 16:05:31 -05002224 clearlambox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2225 if (!clearlambox) {
2226 clrlaerr = 1;
2227 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
James Smartdca94792006-08-01 07:34:08 -04002228 "%d:0207 Device Discovery "
dea31012005-04-17 16:05:31 -05002229 "completion error\n",
2230 phba->brd_no);
James Smart2e0fef82007-06-17 19:56:36 -05002231 phba->link_state = LPFC_HBA_ERROR;
dea31012005-04-17 16:05:31 -05002232 break;
2233 }
James Smart2e0fef82007-06-17 19:56:36 -05002234 phba->link_state = LPFC_CLEAR_LA;
dea31012005-04-17 16:05:31 -05002235 lpfc_clear_la(phba, clearlambox);
2236 clearlambox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
James Smart2e0fef82007-06-17 19:56:36 -05002237 clearlambox->vport = vport;
dea31012005-04-17 16:05:31 -05002238 rc = lpfc_sli_issue_mbox(phba, clearlambox,
2239 (MBX_NOWAIT | MBX_STOP_IOCB));
2240 if (rc == MBX_NOT_FINISHED) {
2241 mempool_free(clearlambox, phba->mbox_mem_pool);
2242 clrlaerr = 1;
2243 }
2244 break;
2245
James Smart2e0fef82007-06-17 19:56:36 -05002246 case LPFC_VPORT_READY:
2247 if (vport->fc_flag & FC_RSCN_MODE) {
James Smarted957682007-06-17 19:56:37 -05002248 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
dea31012005-04-17 16:05:31 -05002249 "%d:0231 RSCN timeout Data: x%x x%x\n",
2250 phba->brd_no,
James Smart2e0fef82007-06-17 19:56:36 -05002251 vport->fc_ns_retry, LPFC_MAX_NS_RETRY);
dea31012005-04-17 16:05:31 -05002252
2253 /* Cleanup any outstanding ELS commands */
James Smart2e0fef82007-06-17 19:56:36 -05002254 lpfc_els_flush_cmd(vport);
dea31012005-04-17 16:05:31 -05002255
James Smart2e0fef82007-06-17 19:56:36 -05002256 lpfc_els_flush_rscn(vport);
2257 lpfc_disc_flush_list(vport);
dea31012005-04-17 16:05:31 -05002258 }
2259 break;
James Smart2e0fef82007-06-17 19:56:36 -05002260
2261 case LPFC_STATE_UNKNOWN:
2262 case LPFC_NS_REG:
2263 case LPFC_BUILD_DISC_LIST:
James Smarted957682007-06-17 19:56:37 -05002264 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
James Smart2e0fef82007-06-17 19:56:36 -05002265 "%d:0229 Unexpected discovery timeout, vport "
2266 "State x%x\n",
James Smarted957682007-06-17 19:56:37 -05002267 vport->port_state, phba->brd_no);
James Smart2e0fef82007-06-17 19:56:36 -05002268
2269 break;
2270 }
2271
2272 switch (phba->link_state) {
2273 case LPFC_CLEAR_LA:
2274 /* CLEAR LA timeout */
James Smarted957682007-06-17 19:56:37 -05002275 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
James Smart2e0fef82007-06-17 19:56:36 -05002276 "%d:0228 CLEAR LA timeout\n",
2277 phba->brd_no);
2278 clrlaerr = 1;
2279 break;
2280
2281 case LPFC_LINK_UNKNOWN:
2282 case LPFC_WARM_START:
2283 case LPFC_INIT_START:
2284 case LPFC_INIT_MBX_CMDS:
2285 case LPFC_LINK_DOWN:
2286 case LPFC_LINK_UP:
2287 case LPFC_HBA_ERROR:
James Smarted957682007-06-17 19:56:37 -05002288 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
James Smart2e0fef82007-06-17 19:56:36 -05002289 "%d:0230 Unexpected timeout, hba link "
2290 "state x%x\n",
2291 phba->brd_no, phba->link_state);
2292 clrlaerr = 1;
2293 break;
dea31012005-04-17 16:05:31 -05002294 }
2295
2296 if (clrlaerr) {
James Smart2e0fef82007-06-17 19:56:36 -05002297 lpfc_disc_flush_list(vport);
James Smarta4bc3372006-12-02 13:34:16 -05002298 psli->ring[(psli->extra_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
dea31012005-04-17 16:05:31 -05002299 psli->ring[(psli->fcp_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
2300 psli->ring[(psli->next_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
James Smart2e0fef82007-06-17 19:56:36 -05002301 vport->port_state = LPFC_VPORT_READY;
dea31012005-04-17 16:05:31 -05002302 }
2303
2304 return;
2305}
2306
dea31012005-04-17 16:05:31 -05002307/*
2308 * This routine handles processing a NameServer REG_LOGIN mailbox
2309 * command upon completion. It is setup in the LPFC_MBOXQ
2310 * as the completion routine when the command is
2311 * handed off to the SLI layer.
2312 */
2313void
James Smart2e0fef82007-06-17 19:56:36 -05002314lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea31012005-04-17 16:05:31 -05002315{
James Smart2e0fef82007-06-17 19:56:36 -05002316 MAILBOX_t *mb = &pmb->mb;
2317 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
2318 struct lpfc_nodelist *ndlp = (struct lpfc_nodelist *) pmb->context2;
2319 struct lpfc_vport *vport = pmb->vport;
dea31012005-04-17 16:05:31 -05002320
2321 pmb->context1 = NULL;
2322
dea31012005-04-17 16:05:31 -05002323 ndlp->nlp_rpi = mb->un.varWords[0];
dea31012005-04-17 16:05:31 -05002324 ndlp->nlp_type |= NLP_FABRIC;
James Smart2e0fef82007-06-17 19:56:36 -05002325 lpfc_nlp_set_state(vport, ndlp, NLP_STE_UNMAPPED_NODE);
dea31012005-04-17 16:05:31 -05002326
James Smart2e0fef82007-06-17 19:56:36 -05002327 /*
2328 * Start issuing Fabric-Device Management Interface (FDMI) command to
2329 * 0xfffffa (FDMI well known port) or Delay issuing FDMI command if
2330 * fdmi-on=2 (supporting RPA/hostnmae)
dea31012005-04-17 16:05:31 -05002331 */
James Smart2e0fef82007-06-17 19:56:36 -05002332
2333 if (phba->cfg_fdmi_on == 1)
2334 lpfc_fdmi_cmd(vport, ndlp, SLI_MGMT_DHBA);
2335 else
2336 mod_timer(&vport->fc_fdmitmo, jiffies + HZ * 60);
dea31012005-04-17 16:05:31 -05002337
James Smart329f9bc2007-04-25 09:53:01 -04002338 /* Mailbox took a reference to the node */
2339 lpfc_nlp_put(ndlp);
dea31012005-04-17 16:05:31 -05002340 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2341 kfree(mp);
James Smart329f9bc2007-04-25 09:53:01 -04002342 mempool_free(pmb, phba->mbox_mem_pool);
dea31012005-04-17 16:05:31 -05002343
2344 return;
2345}
2346
James Smart685f0bf2007-04-25 09:53:08 -04002347static int
2348lpfc_filter_by_rpi(struct lpfc_nodelist *ndlp, void *param)
2349{
2350 uint16_t *rpi = param;
2351
2352 return ndlp->nlp_rpi == *rpi;
2353}
2354
2355static int
2356lpfc_filter_by_wwpn(struct lpfc_nodelist *ndlp, void *param)
2357{
2358 return memcmp(&ndlp->nlp_portname, param,
2359 sizeof(ndlp->nlp_portname)) == 0;
2360}
2361
dea31012005-04-17 16:05:31 -05002362struct lpfc_nodelist *
James Smart2e0fef82007-06-17 19:56:36 -05002363__lpfc_find_node(struct lpfc_vport *vport, node_filter filter, void *param)
dea31012005-04-17 16:05:31 -05002364{
James.Smart@Emulex.Com21568f52005-10-28 20:29:36 -04002365 struct lpfc_nodelist *ndlp;
dea31012005-04-17 16:05:31 -05002366
James Smart2e0fef82007-06-17 19:56:36 -05002367 list_for_each_entry(ndlp, &vport->fc_nodes, nlp_listp) {
James Smart685f0bf2007-04-25 09:53:08 -04002368 if (ndlp->nlp_state != NLP_STE_UNUSED_NODE &&
2369 filter(ndlp, param))
2370 return ndlp;
2371 }
James.Smart@Emulex.Com21568f52005-10-28 20:29:36 -04002372 return NULL;
dea31012005-04-17 16:05:31 -05002373}
2374
James Smart685f0bf2007-04-25 09:53:08 -04002375/*
2376 * Search node lists for a remote port matching filter criteria
2377 * This routine is used when the caller does NOT have host_lock.
2378 */
2379struct lpfc_nodelist *
James Smart2e0fef82007-06-17 19:56:36 -05002380lpfc_find_node(struct lpfc_vport *vport, node_filter filter, void *param)
James Smart685f0bf2007-04-25 09:53:08 -04002381{
James Smart2e0fef82007-06-17 19:56:36 -05002382 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart685f0bf2007-04-25 09:53:08 -04002383 struct lpfc_nodelist *ndlp;
2384
James Smart2e0fef82007-06-17 19:56:36 -05002385 spin_lock_irq(shost->host_lock);
2386 ndlp = __lpfc_find_node(vport, filter, param);
2387 spin_unlock_irq(shost->host_lock);
James Smart685f0bf2007-04-25 09:53:08 -04002388 return ndlp;
2389}
2390
2391/*
2392 * This routine looks up the ndlp lists for the given RPI. If rpi found it
James Smart2e0fef82007-06-17 19:56:36 -05002393 * returns the node list element pointer else return NULL.
James Smart685f0bf2007-04-25 09:53:08 -04002394 */
2395struct lpfc_nodelist *
James Smart2e0fef82007-06-17 19:56:36 -05002396__lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi)
James Smart685f0bf2007-04-25 09:53:08 -04002397{
James Smart2e0fef82007-06-17 19:56:36 -05002398 return __lpfc_find_node(vport, lpfc_filter_by_rpi, &rpi);
James Smart685f0bf2007-04-25 09:53:08 -04002399}
2400
James Smart2534ba72007-04-25 09:52:20 -04002401struct lpfc_nodelist *
James Smart2e0fef82007-06-17 19:56:36 -05002402lpfc_findnode_rpi(struct lpfc_vport *vport, uint16_t rpi)
James Smart2534ba72007-04-25 09:52:20 -04002403{
James Smart2e0fef82007-06-17 19:56:36 -05002404 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart2534ba72007-04-25 09:52:20 -04002405 struct lpfc_nodelist *ndlp;
2406
James Smart2e0fef82007-06-17 19:56:36 -05002407 spin_lock_irq(shost->host_lock);
2408 ndlp = __lpfc_findnode_rpi(vport, rpi);
2409 spin_unlock_irq(shost->host_lock);
James Smart2534ba72007-04-25 09:52:20 -04002410 return ndlp;
2411}
2412
James Smart488d1462006-03-07 15:02:37 -05002413/*
James Smart685f0bf2007-04-25 09:53:08 -04002414 * This routine looks up the ndlp lists for the given WWPN. If WWPN found it
James Smart2e0fef82007-06-17 19:56:36 -05002415 * returns the node element list pointer else return NULL.
James Smart488d1462006-03-07 15:02:37 -05002416 */
2417struct lpfc_nodelist *
James Smart2e0fef82007-06-17 19:56:36 -05002418lpfc_findnode_wwpn(struct lpfc_vport *vport, struct lpfc_name *wwpn)
James Smart488d1462006-03-07 15:02:37 -05002419{
James Smart2e0fef82007-06-17 19:56:36 -05002420 struct Scsi_Host *shost = lpfc_shost_from_vport(vport);
James Smart488d1462006-03-07 15:02:37 -05002421 struct lpfc_nodelist *ndlp;
James Smart488d1462006-03-07 15:02:37 -05002422
James Smart2e0fef82007-06-17 19:56:36 -05002423 spin_lock_irq(shost->host_lock);
2424 ndlp = __lpfc_find_node(vport, lpfc_filter_by_wwpn, wwpn);
2425 spin_unlock_irq(shost->host_lock);
James Smart488d1462006-03-07 15:02:37 -05002426 return NULL;
2427}
2428
dea31012005-04-17 16:05:31 -05002429void
James Smart2e0fef82007-06-17 19:56:36 -05002430lpfc_nlp_init(struct lpfc_vport *vport, struct lpfc_nodelist *ndlp,
2431 uint32_t did)
dea31012005-04-17 16:05:31 -05002432{
2433 memset(ndlp, 0, sizeof (struct lpfc_nodelist));
dea31012005-04-17 16:05:31 -05002434 INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp);
dea31012005-04-17 16:05:31 -05002435 init_timer(&ndlp->nlp_delayfunc);
2436 ndlp->nlp_delayfunc.function = lpfc_els_retry_delay;
2437 ndlp->nlp_delayfunc.data = (unsigned long)ndlp;
2438 ndlp->nlp_DID = did;
James Smart2e0fef82007-06-17 19:56:36 -05002439 ndlp->vport = vport;
dea31012005-04-17 16:05:31 -05002440 ndlp->nlp_sid = NLP_NO_SID;
James Smart685f0bf2007-04-25 09:53:08 -04002441 INIT_LIST_HEAD(&ndlp->nlp_listp);
James Smart329f9bc2007-04-25 09:53:01 -04002442 kref_init(&ndlp->kref);
dea31012005-04-17 16:05:31 -05002443 return;
2444}
James Smart329f9bc2007-04-25 09:53:01 -04002445
2446void
2447lpfc_nlp_release(struct kref *kref)
2448{
2449 struct lpfc_nodelist *ndlp = container_of(kref, struct lpfc_nodelist,
2450 kref);
James Smart2e0fef82007-06-17 19:56:36 -05002451 lpfc_nlp_remove(ndlp->vport, ndlp);
2452 mempool_free(ndlp, ndlp->vport->phba->nlp_mem_pool);
James Smart329f9bc2007-04-25 09:53:01 -04002453}
2454
2455struct lpfc_nodelist *
2456lpfc_nlp_get(struct lpfc_nodelist *ndlp)
2457{
2458 if (ndlp)
2459 kref_get(&ndlp->kref);
2460 return ndlp;
2461}
2462
2463int
2464lpfc_nlp_put(struct lpfc_nodelist *ndlp)
2465{
2466 return ndlp ? kref_put(&ndlp->kref, lpfc_nlp_release) : 0;
2467}