[SCSI] lpfc 8.1.4 : Introduce lpfc_reset_barrier() function for resets on dual channe...
[deliverable/linux.git] / drivers / scsi / lpfc / lpfc_hbadisc.c
CommitLineData
dea3101e 1/*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
c44ce173 3 * Fibre Channel Host Bus Adapters. *
41415862 4 * Copyright (C) 2004-2006 Emulex. All rights reserved. *
c44ce173 5 * EMULEX and SLI are trademarks of Emulex. *
dea3101e 6 * www.emulex.com *
c44ce173 7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
dea3101e 8 * *
9 * This program is free software; you can redistribute it and/or *
c44ce173
JSEC
10 * 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. *
dea3101e 20 *******************************************************************/
21
dea3101e 22#include <linux/blkdev.h>
23#include <linux/pci.h>
24#include <linux/kthread.h>
25#include <linux/interrupt.h>
26
91886523 27#include <scsi/scsi.h>
dea3101e 28#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
57static void lpfc_disc_timeout_handler(struct lpfc_hba *);
58
59static void
60lpfc_process_nodev_timeout(struct lpfc_hba *phba, struct lpfc_nodelist *ndlp)
61{
488d1469 62 uint8_t *name = (uint8_t *)&ndlp->nlp_portname;
6e8215e4 63 int warn_on = 0;
dea3101e 64
65 spin_lock_irq(phba->host->host_lock);
66 if (!(ndlp->nlp_flag & NLP_NODEV_TMO)) {
67 spin_unlock_irq(phba->host->host_lock);
68 return;
69 }
70
1a169689
JS
71 /*
72 * If a discovery event readded nodev_timer after timer
73 * firing and before processing the timer, cancel the
74 * nlp_tmofunc.
75 */
76 spin_unlock_irq(phba->host->host_lock);
77 del_timer_sync(&ndlp->nlp_tmofunc);
78 spin_lock_irq(phba->host->host_lock);
79
dea3101e 80 ndlp->nlp_flag &= ~NLP_NODEV_TMO;
81
82 if (ndlp->nlp_sid != NLP_NO_SID) {
6e8215e4 83 warn_on = 1;
dea3101e 84 /* flush the target */
85 lpfc_sli_abort_iocb(phba, &phba->sli.ring[phba->sli.fcp_ring],
86 ndlp->nlp_sid, 0, 0, LPFC_CTX_TGT);
87 }
88 spin_unlock_irq(phba->host->host_lock);
89
6e8215e4
JSEC
90 if (warn_on) {
91 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
488d1469
JS
92 "%d:0203 Nodev timeout on "
93 "WWPN %x:%x:%x:%x:%x:%x:%x:%x "
94 "NPort x%x Data: x%x x%x x%x\n",
95 phba->brd_no,
96 *name, *(name+1), *(name+2), *(name+3),
97 *(name+4), *(name+5), *(name+6), *(name+7),
98 ndlp->nlp_DID, ndlp->nlp_flag,
6e8215e4
JSEC
99 ndlp->nlp_state, ndlp->nlp_rpi);
100 } else {
101 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
488d1469
JS
102 "%d:0204 Nodev timeout on "
103 "WWPN %x:%x:%x:%x:%x:%x:%x:%x "
104 "NPort x%x Data: x%x x%x x%x\n",
105 phba->brd_no,
106 *name, *(name+1), *(name+2), *(name+3),
107 *(name+4), *(name+5), *(name+6), *(name+7),
108 ndlp->nlp_DID, ndlp->nlp_flag,
6e8215e4
JSEC
109 ndlp->nlp_state, ndlp->nlp_rpi);
110 }
111
dea3101e 112 lpfc_disc_state_machine(phba, ndlp, NULL, NLP_EVT_DEVICE_RM);
113 return;
114}
115
116static void
117lpfc_work_list_done(struct lpfc_hba * phba)
118{
119 struct lpfc_work_evt *evtp = NULL;
120 struct lpfc_nodelist *ndlp;
121 int free_evt;
122
123 spin_lock_irq(phba->host->host_lock);
124 while(!list_empty(&phba->work_list)) {
125 list_remove_head((&phba->work_list), evtp, typeof(*evtp),
126 evt_listp);
127 spin_unlock_irq(phba->host->host_lock);
128 free_evt = 1;
2fe165b6 129 switch (evtp->evt) {
dea3101e 130 case LPFC_EVT_NODEV_TMO:
131 ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1);
132 lpfc_process_nodev_timeout(phba, ndlp);
133 free_evt = 0;
134 break;
135 case LPFC_EVT_ELS_RETRY:
136 ndlp = (struct lpfc_nodelist *)(evtp->evt_arg1);
137 lpfc_els_retry_delay_handler(ndlp);
138 free_evt = 0;
139 break;
140 case LPFC_EVT_ONLINE:
41415862
JW
141 if (phba->hba_state < LPFC_LINK_DOWN)
142 *(int *)(evtp->evt_arg1) = lpfc_online(phba);
143 else
144 *(int *)(evtp->evt_arg1) = 0;
dea3101e 145 complete((struct completion *)(evtp->evt_arg2));
146 break;
147 case LPFC_EVT_OFFLINE:
41415862
JW
148 if (phba->hba_state >= LPFC_LINK_DOWN)
149 lpfc_offline(phba);
150 lpfc_sli_brdrestart(phba);
151 *(int *)(evtp->evt_arg1) =
152 lpfc_sli_brdready(phba,HS_FFRDY | HS_MBRDY);
153 complete((struct completion *)(evtp->evt_arg2));
154 break;
155 case LPFC_EVT_WARM_START:
156 if (phba->hba_state >= LPFC_LINK_DOWN)
157 lpfc_offline(phba);
9290831f 158 lpfc_reset_barrier(phba);
41415862
JW
159 lpfc_sli_brdreset(phba);
160 lpfc_hba_down_post(phba);
161 *(int *)(evtp->evt_arg1) =
162 lpfc_sli_brdready(phba, HS_MBRDY);
163 complete((struct completion *)(evtp->evt_arg2));
164 break;
165 case LPFC_EVT_KILL:
166 if (phba->hba_state >= LPFC_LINK_DOWN)
167 lpfc_offline(phba);
9290831f
JS
168 *(int *)(evtp->evt_arg1)
169 = (phba->stopped) ? 0 : lpfc_sli_brdkill(phba);
dea3101e 170 complete((struct completion *)(evtp->evt_arg2));
171 break;
172 }
173 if (free_evt)
174 kfree(evtp);
175 spin_lock_irq(phba->host->host_lock);
176 }
177 spin_unlock_irq(phba->host->host_lock);
178
179}
180
181static void
182lpfc_work_done(struct lpfc_hba * phba)
183{
184 struct lpfc_sli_ring *pring;
185 int i;
186 uint32_t ha_copy;
187 uint32_t control;
188 uint32_t work_hba_events;
189
190 spin_lock_irq(phba->host->host_lock);
191 ha_copy = phba->work_ha;
192 phba->work_ha = 0;
193 work_hba_events=phba->work_hba_events;
194 spin_unlock_irq(phba->host->host_lock);
195
2fe165b6 196 if (ha_copy & HA_ERATT)
dea3101e 197 lpfc_handle_eratt(phba);
198
2fe165b6 199 if (ha_copy & HA_MBATT)
dea3101e 200 lpfc_sli_handle_mb_event(phba);
201
2fe165b6 202 if (ha_copy & HA_LATT)
dea3101e 203 lpfc_handle_latt(phba);
204
205 if (work_hba_events & WORKER_DISC_TMO)
206 lpfc_disc_timeout_handler(phba);
207
208 if (work_hba_events & WORKER_ELS_TMO)
209 lpfc_els_timeout_handler(phba);
210
211 if (work_hba_events & WORKER_MBOX_TMO)
212 lpfc_mbox_timeout_handler(phba);
213
214 if (work_hba_events & WORKER_FDMI_TMO)
215 lpfc_fdmi_tmo_handler(phba);
216
217 spin_lock_irq(phba->host->host_lock);
218 phba->work_hba_events &= ~work_hba_events;
219 spin_unlock_irq(phba->host->host_lock);
220
221 for (i = 0; i < phba->sli.num_rings; i++, ha_copy >>= 4) {
222 pring = &phba->sli.ring[i];
223 if ((ha_copy & HA_RXATT)
224 || (pring->flag & LPFC_DEFERRED_RING_EVENT)) {
225 if (pring->flag & LPFC_STOP_IOCB_MASK) {
226 pring->flag |= LPFC_DEFERRED_RING_EVENT;
227 } else {
228 lpfc_sli_handle_slow_ring_event(phba, pring,
229 (ha_copy &
230 HA_RXMASK));
231 pring->flag &= ~LPFC_DEFERRED_RING_EVENT;
232 }
233 /*
234 * Turn on Ring interrupts
235 */
236 spin_lock_irq(phba->host->host_lock);
237 control = readl(phba->HCregaddr);
238 control |= (HC_R0INT_ENA << i);
239 writel(control, phba->HCregaddr);
240 readl(phba->HCregaddr); /* flush */
241 spin_unlock_irq(phba->host->host_lock);
242 }
243 }
244
245 lpfc_work_list_done (phba);
246
247}
248
249static int
250check_work_wait_done(struct lpfc_hba *phba) {
251
252 spin_lock_irq(phba->host->host_lock);
253 if (phba->work_ha ||
254 phba->work_hba_events ||
255 (!list_empty(&phba->work_list)) ||
256 kthread_should_stop()) {
257 spin_unlock_irq(phba->host->host_lock);
258 return 1;
259 } else {
260 spin_unlock_irq(phba->host->host_lock);
261 return 0;
262 }
263}
264
265int
266lpfc_do_work(void *p)
267{
268 struct lpfc_hba *phba = p;
269 int rc;
270 DECLARE_WAIT_QUEUE_HEAD(work_waitq);
271
272 set_user_nice(current, -20);
273 phba->work_wait = &work_waitq;
274
275 while (1) {
276
277 rc = wait_event_interruptible(work_waitq,
278 check_work_wait_done(phba));
279 BUG_ON(rc);
280
281 if (kthread_should_stop())
282 break;
283
284 lpfc_work_done(phba);
285
286 }
287 phba->work_wait = NULL;
288 return 0;
289}
290
291/*
292 * This is only called to handle FC worker events. Since this a rare
293 * occurance, we allocate a struct lpfc_work_evt structure here instead of
294 * embedding it in the IOCB.
295 */
296int
297lpfc_workq_post_event(struct lpfc_hba * phba, void *arg1, void *arg2,
298 uint32_t evt)
299{
300 struct lpfc_work_evt *evtp;
301
302 /*
303 * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will
304 * be queued to worker thread for processing
305 */
306 evtp = kmalloc(sizeof(struct lpfc_work_evt), GFP_KERNEL);
307 if (!evtp)
308 return 0;
309
310 evtp->evt_arg1 = arg1;
311 evtp->evt_arg2 = arg2;
312 evtp->evt = evt;
313
314 list_add_tail(&evtp->evt_listp, &phba->work_list);
315 spin_lock_irq(phba->host->host_lock);
316 if (phba->work_wait)
317 wake_up(phba->work_wait);
318 spin_unlock_irq(phba->host->host_lock);
319
320 return 1;
321}
322
323int
324lpfc_linkdown(struct lpfc_hba * phba)
325{
326 struct lpfc_sli *psli;
327 struct lpfc_nodelist *ndlp, *next_ndlp;
c9f8735b 328 struct list_head *listp, *node_list[7];
dea3101e 329 LPFC_MBOXQ_t *mb;
330 int rc, i;
331
332 psli = &phba->sli;
c9f8735b 333 /* sysfs or selective reset may call this routine to clean up */
5024ab17
JW
334 if (phba->hba_state >= LPFC_LINK_DOWN) {
335 if (phba->hba_state == LPFC_LINK_DOWN)
336 return 0;
337
c9f8735b
JW
338 spin_lock_irq(phba->host->host_lock);
339 phba->hba_state = LPFC_LINK_DOWN;
340 spin_unlock_irq(phba->host->host_lock);
341 }
dea3101e 342
343 /* Clean up any firmware default rpi's */
344 if ((mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) {
345 lpfc_unreg_did(phba, 0xffffffff, mb);
346 mb->mbox_cmpl=lpfc_sli_def_mbox_cmpl;
347 if (lpfc_sli_issue_mbox(phba, mb, (MBX_NOWAIT | MBX_STOP_IOCB))
348 == MBX_NOT_FINISHED) {
349 mempool_free( mb, phba->mbox_mem_pool);
350 }
351 }
352
353 /* Cleanup any outstanding RSCN activity */
354 lpfc_els_flush_rscn(phba);
355
356 /* Cleanup any outstanding ELS commands */
357 lpfc_els_flush_cmd(phba);
358
359 /* Issue a LINK DOWN event to all nodes */
360 node_list[0] = &phba->fc_npr_list; /* MUST do this list first */
361 node_list[1] = &phba->fc_nlpmap_list;
362 node_list[2] = &phba->fc_nlpunmap_list;
363 node_list[3] = &phba->fc_prli_list;
364 node_list[4] = &phba->fc_reglogin_list;
365 node_list[5] = &phba->fc_adisc_list;
366 node_list[6] = &phba->fc_plogi_list;
367 for (i = 0; i < 7; i++) {
368 listp = node_list[i];
369 if (list_empty(listp))
370 continue;
371
372 list_for_each_entry_safe(ndlp, next_ndlp, listp, nlp_listp) {
c9f8735b
JW
373
374 rc = lpfc_disc_state_machine(phba, ndlp, NULL,
375 NLP_EVT_DEVICE_RECOVERY);
376
377 /* Check config parameter use-adisc or FCP-2 */
378 if ((rc != NLP_STE_FREED_NODE) &&
379 (phba->cfg_use_adisc == 0) &&
2fe165b6 380 !(ndlp->nlp_fcp_info & NLP_FCP_2_DEVICE)) {
c9f8735b
JW
381 /* We know we will have to relogin, so
382 * unreglogin the rpi right now to fail
383 * any outstanding I/Os quickly.
384 */
385 lpfc_unreg_rpi(phba, ndlp);
dea3101e 386 }
387 }
388 }
389
390 /* free any ndlp's on unused list */
391 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_unused_list,
392 nlp_listp) {
393 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
394 }
395
396 /* Setup myDID for link up if we are in pt2pt mode */
397 if (phba->fc_flag & FC_PT2PT) {
398 phba->fc_myDID = 0;
399 if ((mb = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) {
400 lpfc_config_link(phba, mb);
401 mb->mbox_cmpl=lpfc_sli_def_mbox_cmpl;
402 if (lpfc_sli_issue_mbox
403 (phba, mb, (MBX_NOWAIT | MBX_STOP_IOCB))
404 == MBX_NOT_FINISHED) {
405 mempool_free( mb, phba->mbox_mem_pool);
406 }
407 }
408 spin_lock_irq(phba->host->host_lock);
409 phba->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI);
410 spin_unlock_irq(phba->host->host_lock);
411 }
412 spin_lock_irq(phba->host->host_lock);
413 phba->fc_flag &= ~FC_LBIT;
414 spin_unlock_irq(phba->host->host_lock);
415
416 /* Turn off discovery timer if its running */
417 lpfc_can_disctmo(phba);
418
419 /* Must process IOCBs on all rings to handle ABORTed I/Os */
2fe165b6 420 return 0;
dea3101e 421}
422
423static int
424lpfc_linkup(struct lpfc_hba * phba)
425{
426 struct lpfc_nodelist *ndlp, *next_ndlp;
c9f8735b
JW
427 struct list_head *listp, *node_list[7];
428 int i;
dea3101e 429
430 spin_lock_irq(phba->host->host_lock);
431 phba->hba_state = LPFC_LINK_UP;
432 phba->fc_flag &= ~(FC_PT2PT | FC_PT2PT_PLOGI | FC_ABORT_DISCOVERY |
433 FC_RSCN_MODE | FC_NLP_MORE | FC_RSCN_DISCOVERY);
434 phba->fc_flag |= FC_NDISC_ACTIVE;
435 phba->fc_ns_retry = 0;
436 spin_unlock_irq(phba->host->host_lock);
437
438
c9f8735b
JW
439 node_list[0] = &phba->fc_plogi_list;
440 node_list[1] = &phba->fc_adisc_list;
441 node_list[2] = &phba->fc_reglogin_list;
442 node_list[3] = &phba->fc_prli_list;
443 node_list[4] = &phba->fc_nlpunmap_list;
444 node_list[5] = &phba->fc_nlpmap_list;
445 node_list[6] = &phba->fc_npr_list;
446 for (i = 0; i < 7; i++) {
447 listp = node_list[i];
448 if (list_empty(listp))
449 continue;
450
451 list_for_each_entry_safe(ndlp, next_ndlp, listp, nlp_listp) {
452 if (phba->fc_flag & FC_LBIT) {
453 if (ndlp->nlp_type & NLP_FABRIC) {
454 /* On Linkup its safe to clean up the
455 * ndlp from Fabric connections.
456 */
457 lpfc_nlp_list(phba, ndlp,
458 NLP_UNUSED_LIST);
459 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
460 /* Fail outstanding IO now since device
461 * is marked for PLOGI.
462 */
463 lpfc_unreg_rpi(phba, ndlp);
464 }
465 }
dea3101e 466 }
467 }
468
469 /* free any ndlp's on unused list */
470 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_unused_list,
471 nlp_listp) {
472 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
473 }
474
475 return 0;
476}
477
478/*
479 * This routine handles processing a CLEAR_LA mailbox
480 * command upon completion. It is setup in the LPFC_MBOXQ
481 * as the completion routine when the command is
482 * handed off to the SLI layer.
483 */
484void
485lpfc_mbx_cmpl_clear_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
486{
487 struct lpfc_sli *psli;
488 MAILBOX_t *mb;
489 uint32_t control;
490
491 psli = &phba->sli;
492 mb = &pmb->mb;
493 /* Since we don't do discovery right now, turn these off here */
494 psli->ring[psli->ip_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
495 psli->ring[psli->fcp_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
496 psli->ring[psli->next_ring].flag &= ~LPFC_STOP_IOCB_EVENT;
497
498 /* Check for error */
499 if ((mb->mbxStatus) && (mb->mbxStatus != 0x1601)) {
500 /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */
501 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
502 "%d:0320 CLEAR_LA mbxStatus error x%x hba "
503 "state x%x\n",
504 phba->brd_no, mb->mbxStatus, phba->hba_state);
505
506 phba->hba_state = LPFC_HBA_ERROR;
507 goto out;
508 }
509
510 if (phba->fc_flag & FC_ABORT_DISCOVERY)
511 goto out;
512
513 phba->num_disc_nodes = 0;
514 /* go thru NPR list and issue ELS PLOGIs */
515 if (phba->fc_npr_cnt) {
516 lpfc_els_disc_plogi(phba);
517 }
518
2fe165b6 519 if (!phba->num_disc_nodes) {
dea3101e 520 spin_lock_irq(phba->host->host_lock);
521 phba->fc_flag &= ~FC_NDISC_ACTIVE;
522 spin_unlock_irq(phba->host->host_lock);
523 }
524
525 phba->hba_state = LPFC_HBA_READY;
526
527out:
528 /* Device Discovery completes */
529 lpfc_printf_log(phba,
530 KERN_INFO,
531 LOG_DISCOVERY,
532 "%d:0225 Device Discovery completes\n",
533 phba->brd_no);
534
535 mempool_free( pmb, phba->mbox_mem_pool);
536
537 spin_lock_irq(phba->host->host_lock);
538 phba->fc_flag &= ~FC_ABORT_DISCOVERY;
539 if (phba->fc_flag & FC_ESTABLISH_LINK) {
540 phba->fc_flag &= ~FC_ESTABLISH_LINK;
541 }
542 spin_unlock_irq(phba->host->host_lock);
543
544 del_timer_sync(&phba->fc_estabtmo);
545
546 lpfc_can_disctmo(phba);
547
548 /* turn on Link Attention interrupts */
549 spin_lock_irq(phba->host->host_lock);
550 psli->sli_flag |= LPFC_PROCESS_LA;
551 control = readl(phba->HCregaddr);
552 control |= HC_LAINT_ENA;
553 writel(control, phba->HCregaddr);
554 readl(phba->HCregaddr); /* flush */
555 spin_unlock_irq(phba->host->host_lock);
556
557 return;
558}
559
560static void
25594c6b 561lpfc_mbx_cmpl_local_config_link(struct lpfc_hba *phba, LPFC_MBOXQ_t *pmb)
dea3101e 562{
25594c6b
JW
563 struct lpfc_sli *psli = &phba->sli;
564 int rc;
dea3101e 565
25594c6b 566 if (pmb->mb.mbxStatus)
dea3101e 567 goto out;
dea3101e 568
25594c6b
JW
569 mempool_free(pmb, phba->mbox_mem_pool);
570
571 if (phba->fc_topology == TOPOLOGY_LOOP &&
572 phba->fc_flag & FC_PUBLIC_LOOP &&
573 !(phba->fc_flag & FC_LBIT)) {
574 /* Need to wait for FAN - use discovery timer
575 * for timeout. hba_state is identically
576 * LPFC_LOCAL_CFG_LINK while waiting for FAN
577 */
578 lpfc_set_disctmo(phba);
579 return;
dea3101e 580 }
581
25594c6b
JW
582 /* Start discovery by sending a FLOGI. hba_state is identically
583 * LPFC_FLOGI while waiting for FLOGI cmpl
584 */
585 phba->hba_state = LPFC_FLOGI;
586 lpfc_set_disctmo(phba);
587 lpfc_initial_flogi(phba);
588 return;
dea3101e 589
590out:
25594c6b
JW
591 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
592 "%d:0306 CONFIG_LINK mbxStatus error x%x "
593 "HBA state x%x\n",
594 phba->brd_no, pmb->mb.mbxStatus, phba->hba_state);
595
596 lpfc_linkdown(phba);
597
598 phba->hba_state = LPFC_HBA_ERROR;
599
600 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
dea3101e 601 "%d:0200 CONFIG_LINK bad hba state x%x\n",
602 phba->brd_no, phba->hba_state);
603
25594c6b
JW
604 lpfc_clear_la(phba, pmb);
605 pmb->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
606 rc = lpfc_sli_issue_mbox(phba, pmb, (MBX_NOWAIT | MBX_STOP_IOCB));
607 if (rc == MBX_NOT_FINISHED) {
608 mempool_free(pmb, phba->mbox_mem_pool);
609 lpfc_disc_flush_list(phba);
610 psli->ring[(psli->ip_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
611 psli->ring[(psli->fcp_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
612 psli->ring[(psli->next_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
613 phba->hba_state = LPFC_HBA_READY;
dea3101e 614 }
615 return;
616}
617
618static void
619lpfc_mbx_cmpl_read_sparam(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
620{
621 struct lpfc_sli *psli = &phba->sli;
622 MAILBOX_t *mb = &pmb->mb;
623 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) pmb->context1;
624
625
626 /* Check for error */
627 if (mb->mbxStatus) {
628 /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */
629 lpfc_printf_log(phba, KERN_ERR, LOG_MBOX,
630 "%d:0319 READ_SPARAM mbxStatus error x%x "
631 "hba state x%x>\n",
632 phba->brd_no, mb->mbxStatus, phba->hba_state);
633
634 lpfc_linkdown(phba);
635 phba->hba_state = LPFC_HBA_ERROR;
636 goto out;
637 }
638
639 memcpy((uint8_t *) & phba->fc_sparam, (uint8_t *) mp->virt,
640 sizeof (struct serv_parm));
641 memcpy((uint8_t *) & phba->fc_nodename,
642 (uint8_t *) & phba->fc_sparam.nodeName,
643 sizeof (struct lpfc_name));
644 memcpy((uint8_t *) & phba->fc_portname,
645 (uint8_t *) & phba->fc_sparam.portName,
646 sizeof (struct lpfc_name));
647 lpfc_mbuf_free(phba, mp->virt, mp->phys);
648 kfree(mp);
649 mempool_free( pmb, phba->mbox_mem_pool);
650 return;
651
652out:
653 pmb->context1 = NULL;
654 lpfc_mbuf_free(phba, mp->virt, mp->phys);
655 kfree(mp);
656 if (phba->hba_state != LPFC_CLEAR_LA) {
657 lpfc_clear_la(phba, pmb);
658 pmb->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
659 if (lpfc_sli_issue_mbox(phba, pmb, (MBX_NOWAIT | MBX_STOP_IOCB))
660 == MBX_NOT_FINISHED) {
661 mempool_free( pmb, phba->mbox_mem_pool);
662 lpfc_disc_flush_list(phba);
663 psli->ring[(psli->ip_ring)].flag &=
664 ~LPFC_STOP_IOCB_EVENT;
665 psli->ring[(psli->fcp_ring)].flag &=
666 ~LPFC_STOP_IOCB_EVENT;
667 psli->ring[(psli->next_ring)].flag &=
668 ~LPFC_STOP_IOCB_EVENT;
669 phba->hba_state = LPFC_HBA_READY;
670 }
671 } else {
672 mempool_free( pmb, phba->mbox_mem_pool);
673 }
674 return;
675}
676
677static void
678lpfc_mbx_process_link_up(struct lpfc_hba *phba, READ_LA_VAR *la)
679{
680 int i;
681 LPFC_MBOXQ_t *sparam_mbox, *cfglink_mbox;
682 sparam_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
683 cfglink_mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
684
685 spin_lock_irq(phba->host->host_lock);
2fe165b6 686 switch (la->UlnkSpeed) {
dea3101e 687 case LA_1GHZ_LINK:
688 phba->fc_linkspeed = LA_1GHZ_LINK;
689 break;
690 case LA_2GHZ_LINK:
691 phba->fc_linkspeed = LA_2GHZ_LINK;
692 break;
693 case LA_4GHZ_LINK:
694 phba->fc_linkspeed = LA_4GHZ_LINK;
695 break;
696 default:
697 phba->fc_linkspeed = LA_UNKNW_LINK;
698 break;
699 }
700
701 phba->fc_topology = la->topology;
702
703 if (phba->fc_topology == TOPOLOGY_LOOP) {
704 /* Get Loop Map information */
705
706 if (la->il)
707 phba->fc_flag |= FC_LBIT;
708
709 phba->fc_myDID = la->granted_AL_PA;
710 i = la->un.lilpBde64.tus.f.bdeSize;
711
712 if (i == 0) {
713 phba->alpa_map[0] = 0;
714 } else {
715 if (phba->cfg_log_verbose & LOG_LINK_EVENT) {
716 int numalpa, j, k;
717 union {
718 uint8_t pamap[16];
719 struct {
720 uint32_t wd1;
721 uint32_t wd2;
722 uint32_t wd3;
723 uint32_t wd4;
724 } pa;
725 } un;
726 numalpa = phba->alpa_map[0];
727 j = 0;
728 while (j < numalpa) {
729 memset(un.pamap, 0, 16);
730 for (k = 1; j < numalpa; k++) {
731 un.pamap[k - 1] =
732 phba->alpa_map[j + 1];
733 j++;
734 if (k == 16)
735 break;
736 }
737 /* Link Up Event ALPA map */
738 lpfc_printf_log(phba,
739 KERN_WARNING,
740 LOG_LINK_EVENT,
741 "%d:1304 Link Up Event "
742 "ALPA map Data: x%x "
743 "x%x x%x x%x\n",
744 phba->brd_no,
745 un.pa.wd1, un.pa.wd2,
746 un.pa.wd3, un.pa.wd4);
747 }
748 }
749 }
750 } else {
751 phba->fc_myDID = phba->fc_pref_DID;
752 phba->fc_flag |= FC_LBIT;
753 }
754 spin_unlock_irq(phba->host->host_lock);
755
756 lpfc_linkup(phba);
757 if (sparam_mbox) {
758 lpfc_read_sparam(phba, sparam_mbox);
759 sparam_mbox->mbox_cmpl = lpfc_mbx_cmpl_read_sparam;
760 lpfc_sli_issue_mbox(phba, sparam_mbox,
761 (MBX_NOWAIT | MBX_STOP_IOCB));
762 }
763
764 if (cfglink_mbox) {
765 phba->hba_state = LPFC_LOCAL_CFG_LINK;
766 lpfc_config_link(phba, cfglink_mbox);
25594c6b 767 cfglink_mbox->mbox_cmpl = lpfc_mbx_cmpl_local_config_link;
dea3101e 768 lpfc_sli_issue_mbox(phba, cfglink_mbox,
769 (MBX_NOWAIT | MBX_STOP_IOCB));
770 }
771}
772
773static void
774lpfc_mbx_issue_link_down(struct lpfc_hba *phba) {
775 uint32_t control;
776 struct lpfc_sli *psli = &phba->sli;
777
778 lpfc_linkdown(phba);
779
780 /* turn on Link Attention interrupts - no CLEAR_LA needed */
781 spin_lock_irq(phba->host->host_lock);
782 psli->sli_flag |= LPFC_PROCESS_LA;
783 control = readl(phba->HCregaddr);
784 control |= HC_LAINT_ENA;
785 writel(control, phba->HCregaddr);
786 readl(phba->HCregaddr); /* flush */
787 spin_unlock_irq(phba->host->host_lock);
788}
789
790/*
791 * This routine handles processing a READ_LA mailbox
792 * command upon completion. It is setup in the LPFC_MBOXQ
793 * as the completion routine when the command is
794 * handed off to the SLI layer.
795 */
796void
797lpfc_mbx_cmpl_read_la(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
798{
799 READ_LA_VAR *la;
800 MAILBOX_t *mb = &pmb->mb;
801 struct lpfc_dmabuf *mp = (struct lpfc_dmabuf *) (pmb->context1);
802
803 /* Check for error */
804 if (mb->mbxStatus) {
805 lpfc_printf_log(phba,
806 KERN_INFO,
807 LOG_LINK_EVENT,
808 "%d:1307 READ_LA mbox error x%x state x%x\n",
809 phba->brd_no,
810 mb->mbxStatus, phba->hba_state);
811 lpfc_mbx_issue_link_down(phba);
812 phba->hba_state = LPFC_HBA_ERROR;
813 goto lpfc_mbx_cmpl_read_la_free_mbuf;
814 }
815
816 la = (READ_LA_VAR *) & pmb->mb.un.varReadLA;
817
818 memcpy(&phba->alpa_map[0], mp->virt, 128);
819
c9f8735b
JW
820 spin_lock_irq(phba->host->host_lock);
821 if (la->pb)
822 phba->fc_flag |= FC_BYPASSED_MODE;
823 else
824 phba->fc_flag &= ~FC_BYPASSED_MODE;
825 spin_unlock_irq(phba->host->host_lock);
826
dea3101e 827 if (((phba->fc_eventTag + 1) < la->eventTag) ||
828 (phba->fc_eventTag == la->eventTag)) {
829 phba->fc_stat.LinkMultiEvent++;
830 if (la->attType == AT_LINK_UP) {
831 if (phba->fc_eventTag != 0)
832 lpfc_linkdown(phba);
833 }
834 }
835
836 phba->fc_eventTag = la->eventTag;
837
838 if (la->attType == AT_LINK_UP) {
839 phba->fc_stat.LinkUp++;
840 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
841 "%d:1303 Link Up Event x%x received "
842 "Data: x%x x%x x%x x%x\n",
843 phba->brd_no, la->eventTag, phba->fc_eventTag,
844 la->granted_AL_PA, la->UlnkSpeed,
845 phba->alpa_map[0]);
846 lpfc_mbx_process_link_up(phba, la);
847 } else {
848 phba->fc_stat.LinkDown++;
849 lpfc_printf_log(phba, KERN_ERR, LOG_LINK_EVENT,
850 "%d:1305 Link Down Event x%x received "
851 "Data: x%x x%x x%x\n",
852 phba->brd_no, la->eventTag, phba->fc_eventTag,
853 phba->hba_state, phba->fc_flag);
854 lpfc_mbx_issue_link_down(phba);
855 }
856
857lpfc_mbx_cmpl_read_la_free_mbuf:
858 lpfc_mbuf_free(phba, mp->virt, mp->phys);
859 kfree(mp);
860 mempool_free(pmb, phba->mbox_mem_pool);
861 return;
862}
863
864/*
865 * This routine handles processing a REG_LOGIN mailbox
866 * command upon completion. It is setup in the LPFC_MBOXQ
867 * as the completion routine when the command is
868 * handed off to the SLI layer.
869 */
870void
871lpfc_mbx_cmpl_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
872{
873 struct lpfc_sli *psli;
874 MAILBOX_t *mb;
875 struct lpfc_dmabuf *mp;
876 struct lpfc_nodelist *ndlp;
877
878 psli = &phba->sli;
879 mb = &pmb->mb;
880
881 ndlp = (struct lpfc_nodelist *) pmb->context2;
882 mp = (struct lpfc_dmabuf *) (pmb->context1);
883
884 pmb->context1 = NULL;
885
886 /* Good status, call state machine */
887 lpfc_disc_state_machine(phba, ndlp, pmb, NLP_EVT_CMPL_REG_LOGIN);
888 lpfc_mbuf_free(phba, mp->virt, mp->phys);
889 kfree(mp);
890 mempool_free( pmb, phba->mbox_mem_pool);
891
892 return;
893}
894
895/*
896 * This routine handles processing a Fabric REG_LOGIN mailbox
897 * command upon completion. It is setup in the LPFC_MBOXQ
898 * as the completion routine when the command is
899 * handed off to the SLI layer.
900 */
901void
902lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
903{
904 struct lpfc_sli *psli;
905 MAILBOX_t *mb;
906 struct lpfc_dmabuf *mp;
907 struct lpfc_nodelist *ndlp;
908 struct lpfc_nodelist *ndlp_fdmi;
909
910
911 psli = &phba->sli;
912 mb = &pmb->mb;
913
914 ndlp = (struct lpfc_nodelist *) pmb->context2;
915 mp = (struct lpfc_dmabuf *) (pmb->context1);
916
917 if (mb->mbxStatus) {
918 lpfc_mbuf_free(phba, mp->virt, mp->phys);
919 kfree(mp);
920 mempool_free( pmb, phba->mbox_mem_pool);
921 mempool_free( ndlp, phba->nlp_mem_pool);
922
923 /* FLOGI failed, so just use loop map to make discovery list */
924 lpfc_disc_list_loopmap(phba);
925
926 /* Start discovery */
927 lpfc_disc_start(phba);
928 return;
929 }
930
931 pmb->context1 = NULL;
932
dea3101e 933 ndlp->nlp_rpi = mb->un.varWords[0];
dea3101e 934 ndlp->nlp_type |= NLP_FABRIC;
935 ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
936 lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
937
938 if (phba->hba_state == LPFC_FABRIC_CFG_LINK) {
939 /* This NPort has been assigned an NPort_ID by the fabric as a
940 * result of the completed fabric login. Issue a State Change
941 * Registration (SCR) ELS request to the fabric controller
942 * (SCR_DID) so that this NPort gets RSCN events from the
943 * fabric.
944 */
945 lpfc_issue_els_scr(phba, SCR_DID, 0);
946
c9f8735b
JW
947 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, NameServer_DID);
948 if (!ndlp) {
949 /* Allocate a new node instance. If the pool is empty,
950 * start the discovery process and skip the Nameserver
951 * login process. This is attempted again later on.
952 * Otherwise, issue a Port Login (PLOGI) to NameServer.
953 */
954 ndlp = mempool_alloc(phba->nlp_mem_pool, GFP_ATOMIC);
955 if (!ndlp) {
956 lpfc_disc_start(phba);
957 lpfc_mbuf_free(phba, mp->virt, mp->phys);
958 kfree(mp);
959 mempool_free( pmb, phba->mbox_mem_pool);
960 return;
961 } else {
962 lpfc_nlp_init(phba, ndlp, NameServer_DID);
963 ndlp->nlp_type |= NLP_FABRIC;
964 }
965 }
966 ndlp->nlp_state = NLP_STE_PLOGI_ISSUE;
967 lpfc_nlp_list(phba, ndlp, NLP_PLOGI_LIST);
488d1469 968 lpfc_issue_els_plogi(phba, NameServer_DID, 0);
c9f8735b
JW
969 if (phba->cfg_fdmi_on) {
970 ndlp_fdmi = mempool_alloc(phba->nlp_mem_pool,
971 GFP_KERNEL);
972 if (ndlp_fdmi) {
973 lpfc_nlp_init(phba, ndlp_fdmi, FDMI_DID);
974 ndlp_fdmi->nlp_type |= NLP_FABRIC;
975 ndlp_fdmi->nlp_state = NLP_STE_PLOGI_ISSUE;
488d1469 976 lpfc_issue_els_plogi(phba, FDMI_DID, 0);
dea3101e 977 }
978 }
979 }
980
981 lpfc_mbuf_free(phba, mp->virt, mp->phys);
982 kfree(mp);
983 mempool_free( pmb, phba->mbox_mem_pool);
dea3101e 984 return;
985}
986
987/*
988 * This routine handles processing a NameServer REG_LOGIN mailbox
989 * command upon completion. It is setup in the LPFC_MBOXQ
990 * as the completion routine when the command is
991 * handed off to the SLI layer.
992 */
993void
994lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
995{
996 struct lpfc_sli *psli;
997 MAILBOX_t *mb;
998 struct lpfc_dmabuf *mp;
999 struct lpfc_nodelist *ndlp;
1000
1001 psli = &phba->sli;
1002 mb = &pmb->mb;
1003
1004 ndlp = (struct lpfc_nodelist *) pmb->context2;
1005 mp = (struct lpfc_dmabuf *) (pmb->context1);
1006
1007 if (mb->mbxStatus) {
1008 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1009 kfree(mp);
1010 mempool_free( pmb, phba->mbox_mem_pool);
1011 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
1012
1013 /* RegLogin failed, so just use loop map to make discovery
1014 list */
1015 lpfc_disc_list_loopmap(phba);
1016
1017 /* Start discovery */
1018 lpfc_disc_start(phba);
1019 return;
1020 }
1021
1022 pmb->context1 = NULL;
1023
dea3101e 1024 ndlp->nlp_rpi = mb->un.varWords[0];
dea3101e 1025 ndlp->nlp_type |= NLP_FABRIC;
1026 ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
1027 lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
1028
1029 if (phba->hba_state < LPFC_HBA_READY) {
1030 /* Link up discovery requires Fabrib registration. */
1031 lpfc_ns_cmd(phba, ndlp, SLI_CTNS_RNN_ID);
1032 lpfc_ns_cmd(phba, ndlp, SLI_CTNS_RSNN_NN);
1033 lpfc_ns_cmd(phba, ndlp, SLI_CTNS_RFT_ID);
1034 }
1035
1036 phba->fc_ns_retry = 0;
1037 /* Good status, issue CT Request to NameServer */
1038 if (lpfc_ns_cmd(phba, ndlp, SLI_CTNS_GID_FT)) {
1039 /* Cannot issue NameServer Query, so finish up discovery */
1040 lpfc_disc_start(phba);
1041 }
1042
1043 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1044 kfree(mp);
1045 mempool_free( pmb, phba->mbox_mem_pool);
1046
1047 return;
1048}
1049
1050static void
1051lpfc_register_remote_port(struct lpfc_hba * phba,
1052 struct lpfc_nodelist * ndlp)
1053{
1054 struct fc_rport *rport;
1055 struct lpfc_rport_data *rdata;
1056 struct fc_rport_identifiers rport_ids;
dea3101e 1057
1058 /* Remote port has reappeared. Re-register w/ FC transport */
68ce1eb5
AM
1059 rport_ids.node_name = wwn_to_u64(ndlp->nlp_nodename.u.wwn);
1060 rport_ids.port_name = wwn_to_u64(ndlp->nlp_portname.u.wwn);
dea3101e 1061 rport_ids.port_id = ndlp->nlp_DID;
1062 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
dea3101e 1063
1064 ndlp->rport = rport = fc_remote_port_add(phba->host, 0, &rport_ids);
1065 if (!rport) {
1066 dev_printk(KERN_WARNING, &phba->pcidev->dev,
1067 "Warning: fc_remote_port_add failed\n");
1068 return;
1069 }
1070
1071 /* initialize static port data */
1072 rport->maxframe_size = ndlp->nlp_maxframe;
1073 rport->supported_classes = ndlp->nlp_class_sup;
1074 if ((rport->scsi_target_id != -1) &&
1075 (rport->scsi_target_id < MAX_FCP_TARGET)) {
1076 ndlp->nlp_sid = rport->scsi_target_id;
1077 }
1078 rdata = rport->dd_data;
1079 rdata->pnode = ndlp;
23dc04f1
JSEC
1080
1081 if (ndlp->nlp_type & NLP_FCP_TARGET)
1082 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
1083 if (ndlp->nlp_type & NLP_FCP_INITIATOR)
1084 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
1085
1086
1087 if (rport_ids.roles != FC_RPORT_ROLE_UNKNOWN)
1088 fc_remote_port_rolechg(rport, rport_ids.roles);
1089
19a7b4ae
JSEC
1090
1091 return;
1092}
1093
1094static void
1095lpfc_unregister_remote_port(struct lpfc_hba * phba,
1096 struct lpfc_nodelist * ndlp)
1097{
1098 struct fc_rport *rport = ndlp->rport;
1099 struct lpfc_rport_data *rdata = rport->dd_data;
1100
1101 ndlp->rport = NULL;
1102 rdata->pnode = NULL;
19a7b4ae 1103 fc_remote_port_delete(rport);
dea3101e 1104
1105 return;
1106}
1107
1108int
1109lpfc_nlp_list(struct lpfc_hba * phba, struct lpfc_nodelist * nlp, int list)
1110{
1111 enum { none, unmapped, mapped } rport_add = none, rport_del = none;
1112 struct lpfc_sli *psli;
1113
1114 psli = &phba->sli;
1115 /* Sanity check to ensure we are not moving to / from the same list */
2fe165b6 1116 if ((nlp->nlp_flag & NLP_LIST_MASK) == list)
dea3101e 1117 if (list != NLP_NO_LIST)
2fe165b6 1118 return 0;
dea3101e 1119
66a9ed66 1120 spin_lock_irq(phba->host->host_lock);
2fe165b6 1121 switch (nlp->nlp_flag & NLP_LIST_MASK) {
dea3101e 1122 case NLP_NO_LIST: /* Not on any list */
1123 break;
1124 case NLP_UNUSED_LIST:
1125 phba->fc_unused_cnt--;
1126 list_del(&nlp->nlp_listp);
1127 break;
1128 case NLP_PLOGI_LIST:
1129 phba->fc_plogi_cnt--;
1130 list_del(&nlp->nlp_listp);
1131 break;
1132 case NLP_ADISC_LIST:
1133 phba->fc_adisc_cnt--;
1134 list_del(&nlp->nlp_listp);
1135 break;
1136 case NLP_REGLOGIN_LIST:
1137 phba->fc_reglogin_cnt--;
1138 list_del(&nlp->nlp_listp);
1139 break;
1140 case NLP_PRLI_LIST:
1141 phba->fc_prli_cnt--;
1142 list_del(&nlp->nlp_listp);
1143 break;
1144 case NLP_UNMAPPED_LIST:
1145 phba->fc_unmap_cnt--;
1146 list_del(&nlp->nlp_listp);
dea3101e 1147 nlp->nlp_flag &= ~NLP_TGT_NO_SCSIID;
1148 nlp->nlp_type &= ~NLP_FC_NODE;
dea3101e 1149 phba->nport_event_cnt++;
1150 if (nlp->rport)
1151 rport_del = unmapped;
1152 break;
1153 case NLP_MAPPED_LIST:
1154 phba->fc_map_cnt--;
1155 list_del(&nlp->nlp_listp);
1156 phba->nport_event_cnt++;
1157 if (nlp->rport)
1158 rport_del = mapped;
1159 break;
1160 case NLP_NPR_LIST:
1161 phba->fc_npr_cnt--;
1162 list_del(&nlp->nlp_listp);
1163 /* Stop delay tmo if taking node off NPR list */
1164 if ((nlp->nlp_flag & NLP_DELAY_TMO) &&
1165 (list != NLP_NPR_LIST)) {
66a9ed66 1166 spin_unlock_irq(phba->host->host_lock);
fdcebe28 1167 lpfc_cancel_retry_delay_tmo(phba, nlp);
66a9ed66 1168 spin_lock_irq(phba->host->host_lock);
dea3101e 1169 }
1170 break;
1171 }
1172
dea3101e 1173 nlp->nlp_flag &= ~NLP_LIST_MASK;
dea3101e 1174
1175 /* Add NPort <did> to <num> list */
1176 lpfc_printf_log(phba,
1177 KERN_INFO,
1178 LOG_NODE,
1179 "%d:0904 Add NPort x%x to %d list Data: x%x\n",
1180 phba->brd_no,
1181 nlp->nlp_DID, list, nlp->nlp_flag);
1182
2fe165b6 1183 switch (list) {
dea3101e 1184 case NLP_NO_LIST: /* No list, just remove it */
66a9ed66 1185 spin_unlock_irq(phba->host->host_lock);
dea3101e 1186 lpfc_nlp_remove(phba, nlp);
66a9ed66 1187 spin_lock_irq(phba->host->host_lock);
8cbdc5ff
JSEC
1188 /* as node removed - stop further transport calls */
1189 rport_del = none;
dea3101e 1190 break;
1191 case NLP_UNUSED_LIST:
dea3101e 1192 nlp->nlp_flag |= list;
dea3101e 1193 /* Put it at the end of the unused list */
1194 list_add_tail(&nlp->nlp_listp, &phba->fc_unused_list);
1195 phba->fc_unused_cnt++;
1196 break;
1197 case NLP_PLOGI_LIST:
dea3101e 1198 nlp->nlp_flag |= list;
dea3101e 1199 /* Put it at the end of the plogi list */
1200 list_add_tail(&nlp->nlp_listp, &phba->fc_plogi_list);
1201 phba->fc_plogi_cnt++;
1202 break;
1203 case NLP_ADISC_LIST:
dea3101e 1204 nlp->nlp_flag |= list;
dea3101e 1205 /* Put it at the end of the adisc list */
1206 list_add_tail(&nlp->nlp_listp, &phba->fc_adisc_list);
1207 phba->fc_adisc_cnt++;
1208 break;
1209 case NLP_REGLOGIN_LIST:
dea3101e 1210 nlp->nlp_flag |= list;
dea3101e 1211 /* Put it at the end of the reglogin list */
1212 list_add_tail(&nlp->nlp_listp, &phba->fc_reglogin_list);
1213 phba->fc_reglogin_cnt++;
1214 break;
1215 case NLP_PRLI_LIST:
dea3101e 1216 nlp->nlp_flag |= list;
dea3101e 1217 /* Put it at the end of the prli list */
1218 list_add_tail(&nlp->nlp_listp, &phba->fc_prli_list);
1219 phba->fc_prli_cnt++;
1220 break;
1221 case NLP_UNMAPPED_LIST:
1222 rport_add = unmapped;
1223 /* ensure all vestiges of "mapped" significance are gone */
1224 nlp->nlp_type &= ~(NLP_FCP_TARGET | NLP_FCP_INITIATOR);
dea3101e 1225 nlp->nlp_flag |= list;
dea3101e 1226 /* Put it at the end of the unmap list */
1227 list_add_tail(&nlp->nlp_listp, &phba->fc_nlpunmap_list);
1228 phba->fc_unmap_cnt++;
1229 phba->nport_event_cnt++;
1230 /* stop nodev tmo if running */
1231 if (nlp->nlp_flag & NLP_NODEV_TMO) {
dea3101e 1232 nlp->nlp_flag &= ~NLP_NODEV_TMO;
1233 spin_unlock_irq(phba->host->host_lock);
1234 del_timer_sync(&nlp->nlp_tmofunc);
66a9ed66 1235 spin_lock_irq(phba->host->host_lock);
dea3101e 1236 if (!list_empty(&nlp->nodev_timeout_evt.evt_listp))
1237 list_del_init(&nlp->nodev_timeout_evt.
1238 evt_listp);
1239
1240 }
1241 nlp->nlp_type |= NLP_FC_NODE;
1242 break;
1243 case NLP_MAPPED_LIST:
1244 rport_add = mapped;
dea3101e 1245 nlp->nlp_flag |= list;
dea3101e 1246 /* Put it at the end of the map list */
1247 list_add_tail(&nlp->nlp_listp, &phba->fc_nlpmap_list);
1248 phba->fc_map_cnt++;
1249 phba->nport_event_cnt++;
1250 /* stop nodev tmo if running */
1251 if (nlp->nlp_flag & NLP_NODEV_TMO) {
1252 nlp->nlp_flag &= ~NLP_NODEV_TMO;
66a9ed66 1253 spin_unlock_irq(phba->host->host_lock);
dea3101e 1254 del_timer_sync(&nlp->nlp_tmofunc);
66a9ed66 1255 spin_lock_irq(phba->host->host_lock);
dea3101e 1256 if (!list_empty(&nlp->nodev_timeout_evt.evt_listp))
1257 list_del_init(&nlp->nodev_timeout_evt.
1258 evt_listp);
1259
1260 }
1261 break;
1262 case NLP_NPR_LIST:
dea3101e 1263 nlp->nlp_flag |= list;
dea3101e 1264 /* Put it at the end of the npr list */
1265 list_add_tail(&nlp->nlp_listp, &phba->fc_npr_list);
1266 phba->fc_npr_cnt++;
1267
2fe165b6 1268 if (!(nlp->nlp_flag & NLP_NODEV_TMO))
dea3101e 1269 mod_timer(&nlp->nlp_tmofunc,
c9f8735b 1270 jiffies + HZ * phba->cfg_nodev_tmo);
2fe165b6 1271
dea3101e 1272 nlp->nlp_flag |= NLP_NODEV_TMO;
1273 nlp->nlp_flag &= ~NLP_RCV_PLOGI;
dea3101e 1274 break;
1275 case NLP_JUST_DQ:
1276 break;
1277 }
1278
66a9ed66
JW
1279 spin_unlock_irq(phba->host->host_lock);
1280
dea3101e 1281 /*
1282 * We make all the calls into the transport after we have
1283 * moved the node between lists. This so that we don't
1284 * release the lock while in-between lists.
1285 */
1286
1287 /* Don't upcall midlayer if we're unloading */
1288 if (!(phba->fc_flag & FC_UNLOADING)) {
1289 /*
1290 * We revalidate the rport pointer as the "add" function
1291 * may have removed the remote port.
1292 */
1293 if ((rport_del != none) && nlp->rport)
19a7b4ae 1294 lpfc_unregister_remote_port(phba, nlp);
dea3101e 1295
1296 if (rport_add != none) {
1297 /*
1298 * Tell the fc transport about the port, if we haven't
1299 * already. If we have, and it's a scsi entity, be
1300 * sure to unblock any attached scsi devices
1301 */
1302 if (!nlp->rport)
1303 lpfc_register_remote_port(phba, nlp);
dea3101e 1304
1305 /*
1306 * if we added to Mapped list, but the remote port
1307 * registration failed or assigned a target id outside
1308 * our presentable range - move the node to the
1309 * Unmapped List
1310 */
1311 if ((rport_add == mapped) &&
1312 ((!nlp->rport) ||
1313 (nlp->rport->scsi_target_id == -1) ||
1314 (nlp->rport->scsi_target_id >= MAX_FCP_TARGET))) {
1315 nlp->nlp_state = NLP_STE_UNMAPPED_NODE;
1316 spin_lock_irq(phba->host->host_lock);
1317 nlp->nlp_flag |= NLP_TGT_NO_SCSIID;
1318 spin_unlock_irq(phba->host->host_lock);
1319 lpfc_nlp_list(phba, nlp, NLP_UNMAPPED_LIST);
1320 }
1321 }
1322 }
2fe165b6 1323 return 0;
dea3101e 1324}
1325
1326/*
1327 * Start / ReStart rescue timer for Discovery / RSCN handling
1328 */
1329void
1330lpfc_set_disctmo(struct lpfc_hba * phba)
1331{
1332 uint32_t tmo;
1333
c9f8735b
JW
1334 if (phba->hba_state == LPFC_LOCAL_CFG_LINK) {
1335 /* For FAN, timeout should be greater then edtov */
1336 tmo = (((phba->fc_edtov + 999) / 1000) + 1);
1337 } else {
1338 /* Normal discovery timeout should be > then ELS/CT timeout
1339 * FC spec states we need 3 * ratov for CT requests
1340 */
1341 tmo = ((phba->fc_ratov * 3) + 3);
1342 }
dea3101e 1343
1344 mod_timer(&phba->fc_disctmo, jiffies + HZ * tmo);
1345 spin_lock_irq(phba->host->host_lock);
1346 phba->fc_flag |= FC_DISC_TMO;
1347 spin_unlock_irq(phba->host->host_lock);
1348
1349 /* Start Discovery Timer state <hba_state> */
1350 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1351 "%d:0247 Start Discovery Timer state x%x "
1352 "Data: x%x x%lx x%x x%x\n",
1353 phba->brd_no,
1354 phba->hba_state, tmo, (unsigned long)&phba->fc_disctmo,
1355 phba->fc_plogi_cnt, phba->fc_adisc_cnt);
1356
1357 return;
1358}
1359
1360/*
1361 * Cancel rescue timer for Discovery / RSCN handling
1362 */
1363int
1364lpfc_can_disctmo(struct lpfc_hba * phba)
1365{
1366 /* Turn off discovery timer if its running */
1367 if (phba->fc_flag & FC_DISC_TMO) {
1368 spin_lock_irq(phba->host->host_lock);
1369 phba->fc_flag &= ~FC_DISC_TMO;
1370 spin_unlock_irq(phba->host->host_lock);
1371 del_timer_sync(&phba->fc_disctmo);
1372 phba->work_hba_events &= ~WORKER_DISC_TMO;
1373 }
1374
1375 /* Cancel Discovery Timer state <hba_state> */
1376 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1377 "%d:0248 Cancel Discovery Timer state x%x "
1378 "Data: x%x x%x x%x\n",
1379 phba->brd_no, phba->hba_state, phba->fc_flag,
1380 phba->fc_plogi_cnt, phba->fc_adisc_cnt);
1381
2fe165b6 1382 return 0;
dea3101e 1383}
1384
1385/*
1386 * Check specified ring for outstanding IOCB on the SLI queue
1387 * Return true if iocb matches the specified nport
1388 */
1389int
1390lpfc_check_sli_ndlp(struct lpfc_hba * phba,
1391 struct lpfc_sli_ring * pring,
1392 struct lpfc_iocbq * iocb, struct lpfc_nodelist * ndlp)
1393{
1394 struct lpfc_sli *psli;
1395 IOCB_t *icmd;
1396
1397 psli = &phba->sli;
1398 icmd = &iocb->iocb;
1399 if (pring->ringno == LPFC_ELS_RING) {
1400 switch (icmd->ulpCommand) {
1401 case CMD_GEN_REQUEST64_CR:
1402 if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi)
2fe165b6 1403 return 1;
dea3101e 1404 case CMD_ELS_REQUEST64_CR:
1405 case CMD_XMIT_ELS_RSP64_CX:
1406 if (iocb->context1 == (uint8_t *) ndlp)
2fe165b6 1407 return 1;
dea3101e 1408 }
1409 } else if (pring->ringno == psli->ip_ring) {
1410
1411 } else if (pring->ringno == psli->fcp_ring) {
1412 /* Skip match check if waiting to relogin to FCP target */
1413 if ((ndlp->nlp_type & NLP_FCP_TARGET) &&
1414 (ndlp->nlp_flag & NLP_DELAY_TMO)) {
2fe165b6 1415 return 0;
dea3101e 1416 }
1417 if (icmd->ulpContext == (volatile ushort)ndlp->nlp_rpi) {
2fe165b6 1418 return 1;
dea3101e 1419 }
1420 } else if (pring->ringno == psli->next_ring) {
1421
1422 }
2fe165b6 1423 return 0;
dea3101e 1424}
1425
1426/*
1427 * Free resources / clean up outstanding I/Os
1428 * associated with nlp_rpi in the LPFC_NODELIST entry.
1429 */
1430static int
1431lpfc_no_rpi(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
1432{
1433 struct lpfc_sli *psli;
1434 struct lpfc_sli_ring *pring;
1435 struct lpfc_iocbq *iocb, *next_iocb;
1436 IOCB_t *icmd;
1437 uint32_t rpi, i;
1438
1439 /*
1440 * Everything that matches on txcmplq will be returned
1441 * by firmware with a no rpi error.
1442 */
1443 psli = &phba->sli;
1444 rpi = ndlp->nlp_rpi;
1445 if (rpi) {
1446 /* Now process each ring */
1447 for (i = 0; i < psli->num_rings; i++) {
1448 pring = &psli->ring[i];
1449
1450 spin_lock_irq(phba->host->host_lock);
1451 list_for_each_entry_safe(iocb, next_iocb, &pring->txq,
1452 list) {
1453 /*
1454 * Check to see if iocb matches the nport we are
1455 * looking for
1456 */
1457 if ((lpfc_check_sli_ndlp
1458 (phba, pring, iocb, ndlp))) {
1459 /* It matches, so deque and call compl
1460 with an error */
1461 list_del(&iocb->list);
1462 pring->txq_cnt--;
1463 if (iocb->iocb_cmpl) {
1464 icmd = &iocb->iocb;
1465 icmd->ulpStatus =
1466 IOSTAT_LOCAL_REJECT;
1467 icmd->un.ulpWord[4] =
1468 IOERR_SLI_ABORTED;
1469 spin_unlock_irq(phba->host->
1470 host_lock);
1471 (iocb->iocb_cmpl) (phba,
1472 iocb, iocb);
1473 spin_lock_irq(phba->host->
1474 host_lock);
604a3e30
JB
1475 } else
1476 lpfc_sli_release_iocbq(phba,
1477 iocb);
dea3101e 1478 }
1479 }
1480 spin_unlock_irq(phba->host->host_lock);
1481
1482 }
1483 }
2fe165b6 1484 return 0;
dea3101e 1485}
1486
1487/*
1488 * Free rpi associated with LPFC_NODELIST entry.
1489 * This routine is called from lpfc_freenode(), when we are removing
1490 * a LPFC_NODELIST entry. It is also called if the driver initiates a
1491 * LOGO that completes successfully, and we are waiting to PLOGI back
1492 * to the remote NPort. In addition, it is called after we receive
1493 * and unsolicated ELS cmd, send back a rsp, the rsp completes and
1494 * we are waiting to PLOGI back to the remote NPort.
1495 */
1496int
1497lpfc_unreg_rpi(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
1498{
1499 LPFC_MBOXQ_t *mbox;
1500 int rc;
1501
1502 if (ndlp->nlp_rpi) {
1503 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) {
1504 lpfc_unreg_login(phba, ndlp->nlp_rpi, mbox);
1505 mbox->mbox_cmpl=lpfc_sli_def_mbox_cmpl;
1506 rc = lpfc_sli_issue_mbox
1507 (phba, mbox, (MBX_NOWAIT | MBX_STOP_IOCB));
1508 if (rc == MBX_NOT_FINISHED)
1509 mempool_free( mbox, phba->mbox_mem_pool);
1510 }
dea3101e 1511 lpfc_no_rpi(phba, ndlp);
1512 ndlp->nlp_rpi = 0;
1513 return 1;
1514 }
1515 return 0;
1516}
1517
1518/*
1519 * Free resources associated with LPFC_NODELIST entry
1520 * so it can be freed.
1521 */
1522static int
1523lpfc_freenode(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
1524{
1525 LPFC_MBOXQ_t *mb;
1526 LPFC_MBOXQ_t *nextmb;
1527 struct lpfc_dmabuf *mp;
dea3101e 1528
1529 /* Cleanup node for NPort <nlp_DID> */
1530 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1531 "%d:0900 Cleanup node for NPort x%x "
1532 "Data: x%x x%x x%x\n",
1533 phba->brd_no, ndlp->nlp_DID, ndlp->nlp_flag,
1534 ndlp->nlp_state, ndlp->nlp_rpi);
1535
1536 lpfc_nlp_list(phba, ndlp, NLP_JUST_DQ);
1537
1538 /*
1539 * if unloading the driver - just leave the remote port in place.
1540 * The driver unload will force the attached devices to detach
1541 * and flush cache's w/o generating flush errors.
1542 */
1543 if ((ndlp->rport) && !(phba->fc_flag & FC_UNLOADING)) {
19a7b4ae 1544 lpfc_unregister_remote_port(phba, ndlp);
dea3101e 1545 ndlp->nlp_sid = NLP_NO_SID;
1546 }
1547
1548 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
1549 if ((mb = phba->sli.mbox_active)) {
1550 if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
1551 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1552 mb->context2 = NULL;
1553 mb->mbox_cmpl = lpfc_sli_def_mbox_cmpl;
1554 }
1555 }
1556 list_for_each_entry_safe(mb, nextmb, &phba->sli.mboxq, list) {
1557 if ((mb->mb.mbxCommand == MBX_REG_LOGIN64) &&
1558 (ndlp == (struct lpfc_nodelist *) mb->context2)) {
1559 mp = (struct lpfc_dmabuf *) (mb->context1);
1560 if (mp) {
1561 lpfc_mbuf_free(phba, mp->virt, mp->phys);
1562 kfree(mp);
1563 }
1564 list_del(&mb->list);
1565 mempool_free(mb, phba->mbox_mem_pool);
1566 }
1567 }
1568
1569 lpfc_els_abort(phba,ndlp,0);
1570 spin_lock_irq(phba->host->host_lock);
1571 ndlp->nlp_flag &= ~(NLP_NODEV_TMO|NLP_DELAY_TMO);
1572 spin_unlock_irq(phba->host->host_lock);
1573 del_timer_sync(&ndlp->nlp_tmofunc);
1574
5024ab17 1575 ndlp->nlp_last_elscmd = 0;
dea3101e 1576 del_timer_sync(&ndlp->nlp_delayfunc);
1577
1578 if (!list_empty(&ndlp->nodev_timeout_evt.evt_listp))
1579 list_del_init(&ndlp->nodev_timeout_evt.evt_listp);
1580 if (!list_empty(&ndlp->els_retry_evt.evt_listp))
1581 list_del_init(&ndlp->els_retry_evt.evt_listp);
1582
1583 lpfc_unreg_rpi(phba, ndlp);
1584
2fe165b6 1585 return 0;
dea3101e 1586}
1587
1588/*
1589 * Check to see if we can free the nlp back to the freelist.
1590 * If we are in the middle of using the nlp in the discovery state
1591 * machine, defer the free till we reach the end of the state machine.
1592 */
1593int
1594lpfc_nlp_remove(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
1595{
1596 if (ndlp->nlp_flag & NLP_NODEV_TMO) {
1597 spin_lock_irq(phba->host->host_lock);
1598 ndlp->nlp_flag &= ~NLP_NODEV_TMO;
1599 spin_unlock_irq(phba->host->host_lock);
1600 del_timer_sync(&ndlp->nlp_tmofunc);
1601 if (!list_empty(&ndlp->nodev_timeout_evt.evt_listp))
1602 list_del_init(&ndlp->nodev_timeout_evt.evt_listp);
1603
1604 }
1605
1606
1607 if (ndlp->nlp_flag & NLP_DELAY_TMO) {
fdcebe28 1608 lpfc_cancel_retry_delay_tmo(phba, ndlp);
dea3101e 1609 }
1610
1611 if (ndlp->nlp_disc_refcnt) {
1612 spin_lock_irq(phba->host->host_lock);
1613 ndlp->nlp_flag |= NLP_DELAY_REMOVE;
1614 spin_unlock_irq(phba->host->host_lock);
2fe165b6 1615 } else {
dea3101e 1616 lpfc_freenode(phba, ndlp);
1617 mempool_free( ndlp, phba->nlp_mem_pool);
1618 }
2fe165b6 1619 return 0;
dea3101e 1620}
1621
1622static int
1623lpfc_matchdid(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp, uint32_t did)
1624{
1625 D_ID mydid;
1626 D_ID ndlpdid;
1627 D_ID matchdid;
1628
1629 if (did == Bcast_DID)
2fe165b6 1630 return 0;
dea3101e 1631
1632 if (ndlp->nlp_DID == 0) {
2fe165b6 1633 return 0;
dea3101e 1634 }
1635
1636 /* First check for Direct match */
1637 if (ndlp->nlp_DID == did)
2fe165b6 1638 return 1;
dea3101e 1639
1640 /* Next check for area/domain identically equals 0 match */
1641 mydid.un.word = phba->fc_myDID;
1642 if ((mydid.un.b.domain == 0) && (mydid.un.b.area == 0)) {
2fe165b6 1643 return 0;
dea3101e 1644 }
1645
1646 matchdid.un.word = did;
1647 ndlpdid.un.word = ndlp->nlp_DID;
1648 if (matchdid.un.b.id == ndlpdid.un.b.id) {
1649 if ((mydid.un.b.domain == matchdid.un.b.domain) &&
1650 (mydid.un.b.area == matchdid.un.b.area)) {
1651 if ((ndlpdid.un.b.domain == 0) &&
1652 (ndlpdid.un.b.area == 0)) {
1653 if (ndlpdid.un.b.id)
2fe165b6 1654 return 1;
dea3101e 1655 }
2fe165b6 1656 return 0;
dea3101e 1657 }
1658
1659 matchdid.un.word = ndlp->nlp_DID;
1660 if ((mydid.un.b.domain == ndlpdid.un.b.domain) &&
1661 (mydid.un.b.area == ndlpdid.un.b.area)) {
1662 if ((matchdid.un.b.domain == 0) &&
1663 (matchdid.un.b.area == 0)) {
1664 if (matchdid.un.b.id)
2fe165b6 1665 return 1;
dea3101e 1666 }
1667 }
1668 }
2fe165b6 1669 return 0;
dea3101e 1670}
1671
1672/* Search for a nodelist entry on a specific list */
1673struct lpfc_nodelist *
1674lpfc_findnode_did(struct lpfc_hba * phba, uint32_t order, uint32_t did)
1675{
1676 struct lpfc_nodelist *ndlp, *next_ndlp;
1677 uint32_t data1;
1678
66a9ed66 1679 spin_lock_irq(phba->host->host_lock);
dea3101e 1680 if (order & NLP_SEARCH_UNMAPPED) {
1681 list_for_each_entry_safe(ndlp, next_ndlp,
1682 &phba->fc_nlpunmap_list, nlp_listp) {
1683 if (lpfc_matchdid(phba, ndlp, did)) {
1684 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1685 ((uint32_t) ndlp->nlp_xri << 16) |
1686 ((uint32_t) ndlp->nlp_type << 8) |
1687 ((uint32_t) ndlp->nlp_rpi & 0xff));
1688 /* FIND node DID unmapped */
1689 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1690 "%d:0929 FIND node DID unmapped"
1691 " Data: x%p x%x x%x x%x\n",
1692 phba->brd_no,
1693 ndlp, ndlp->nlp_DID,
1694 ndlp->nlp_flag, data1);
66a9ed66 1695 spin_unlock_irq(phba->host->host_lock);
2fe165b6 1696 return ndlp;
dea3101e 1697 }
1698 }
1699 }
1700
1701 if (order & NLP_SEARCH_MAPPED) {
1702 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_nlpmap_list,
1703 nlp_listp) {
1704 if (lpfc_matchdid(phba, ndlp, did)) {
1705
1706 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1707 ((uint32_t) ndlp->nlp_xri << 16) |
1708 ((uint32_t) ndlp->nlp_type << 8) |
1709 ((uint32_t) ndlp->nlp_rpi & 0xff));
1710 /* FIND node DID mapped */
1711 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1712 "%d:0930 FIND node DID mapped "
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);
66a9ed66 1717 spin_unlock_irq(phba->host->host_lock);
2fe165b6 1718 return ndlp;
dea3101e 1719 }
1720 }
1721 }
1722
1723 if (order & NLP_SEARCH_PLOGI) {
1724 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_plogi_list,
1725 nlp_listp) {
1726 if (lpfc_matchdid(phba, ndlp, did)) {
1727
1728 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1729 ((uint32_t) ndlp->nlp_xri << 16) |
1730 ((uint32_t) ndlp->nlp_type << 8) |
1731 ((uint32_t) ndlp->nlp_rpi & 0xff));
1732 /* LOG change to PLOGI */
1733 /* FIND node DID plogi */
1734 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1735 "%d:0908 FIND node DID plogi "
1736 "Data: x%p x%x x%x x%x\n",
1737 phba->brd_no,
1738 ndlp, ndlp->nlp_DID,
1739 ndlp->nlp_flag, data1);
66a9ed66 1740 spin_unlock_irq(phba->host->host_lock);
2fe165b6 1741 return ndlp;
dea3101e 1742 }
1743 }
1744 }
1745
1746 if (order & NLP_SEARCH_ADISC) {
1747 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_adisc_list,
1748 nlp_listp) {
1749 if (lpfc_matchdid(phba, ndlp, did)) {
1750
1751 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1752 ((uint32_t) ndlp->nlp_xri << 16) |
1753 ((uint32_t) ndlp->nlp_type << 8) |
1754 ((uint32_t) ndlp->nlp_rpi & 0xff));
1755 /* LOG change to ADISC */
1756 /* FIND node DID adisc */
1757 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1758 "%d:0931 FIND node DID adisc "
1759 "Data: x%p x%x x%x x%x\n",
1760 phba->brd_no,
1761 ndlp, ndlp->nlp_DID,
1762 ndlp->nlp_flag, data1);
2fe165b6 1763 return ndlp;
dea3101e 1764 }
1765 }
1766 }
1767
1768 if (order & NLP_SEARCH_REGLOGIN) {
1769 list_for_each_entry_safe(ndlp, next_ndlp,
1770 &phba->fc_reglogin_list, nlp_listp) {
1771 if (lpfc_matchdid(phba, ndlp, did)) {
1772
1773 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1774 ((uint32_t) ndlp->nlp_xri << 16) |
1775 ((uint32_t) ndlp->nlp_type << 8) |
1776 ((uint32_t) ndlp->nlp_rpi & 0xff));
1777 /* LOG change to REGLOGIN */
1778 /* FIND node DID reglogin */
1779 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1780 "%d:0931 FIND node DID reglogin"
1781 " Data: x%p x%x x%x x%x\n",
1782 phba->brd_no,
1783 ndlp, ndlp->nlp_DID,
1784 ndlp->nlp_flag, data1);
66a9ed66 1785 spin_unlock_irq(phba->host->host_lock);
2fe165b6 1786 return ndlp;
dea3101e 1787 }
1788 }
1789 }
1790
1791 if (order & NLP_SEARCH_PRLI) {
1792 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_prli_list,
1793 nlp_listp) {
1794 if (lpfc_matchdid(phba, ndlp, did)) {
1795
1796 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1797 ((uint32_t) ndlp->nlp_xri << 16) |
1798 ((uint32_t) ndlp->nlp_type << 8) |
1799 ((uint32_t) ndlp->nlp_rpi & 0xff));
1800 /* LOG change to PRLI */
1801 /* FIND node DID prli */
1802 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1803 "%d:0931 FIND node DID prli "
1804 "Data: x%p x%x x%x x%x\n",
1805 phba->brd_no,
1806 ndlp, ndlp->nlp_DID,
1807 ndlp->nlp_flag, data1);
2fe165b6 1808 return ndlp;
dea3101e 1809 }
1810 }
1811 }
1812
1813 if (order & NLP_SEARCH_NPR) {
1814 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
1815 nlp_listp) {
1816 if (lpfc_matchdid(phba, ndlp, did)) {
1817
1818 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1819 ((uint32_t) ndlp->nlp_xri << 16) |
1820 ((uint32_t) ndlp->nlp_type << 8) |
1821 ((uint32_t) ndlp->nlp_rpi & 0xff));
1822 /* LOG change to NPR */
1823 /* FIND node DID npr */
1824 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1825 "%d:0931 FIND node DID npr "
1826 "Data: x%p x%x x%x x%x\n",
1827 phba->brd_no,
1828 ndlp, ndlp->nlp_DID,
1829 ndlp->nlp_flag, data1);
66a9ed66 1830 spin_unlock_irq(phba->host->host_lock);
2fe165b6 1831 return ndlp;
dea3101e 1832 }
1833 }
1834 }
1835
1836 if (order & NLP_SEARCH_UNUSED) {
1837 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_adisc_list,
1838 nlp_listp) {
1839 if (lpfc_matchdid(phba, ndlp, did)) {
1840
1841 data1 = (((uint32_t) ndlp->nlp_state << 24) |
1842 ((uint32_t) ndlp->nlp_xri << 16) |
1843 ((uint32_t) ndlp->nlp_type << 8) |
1844 ((uint32_t) ndlp->nlp_rpi & 0xff));
1845 /* LOG change to UNUSED */
1846 /* FIND node DID unused */
1847 lpfc_printf_log(phba, KERN_INFO, LOG_NODE,
1848 "%d:0931 FIND node DID unused "
1849 "Data: x%p x%x x%x x%x\n",
1850 phba->brd_no,
1851 ndlp, ndlp->nlp_DID,
1852 ndlp->nlp_flag, data1);
66a9ed66 1853 spin_unlock_irq(phba->host->host_lock);
2fe165b6 1854 return ndlp;
dea3101e 1855 }
1856 }
1857 }
1858
66a9ed66
JW
1859 spin_unlock_irq(phba->host->host_lock);
1860
dea3101e 1861 /* FIND node did <did> NOT FOUND */
1862 lpfc_printf_log(phba,
1863 KERN_INFO,
1864 LOG_NODE,
1865 "%d:0932 FIND node did x%x NOT FOUND Data: x%x\n",
1866 phba->brd_no, did, order);
1867
1868 /* no match found */
1869 return NULL;
1870}
1871
1872struct lpfc_nodelist *
1873lpfc_setup_disc_node(struct lpfc_hba * phba, uint32_t did)
1874{
1875 struct lpfc_nodelist *ndlp;
1876 uint32_t flg;
1877
c9f8735b
JW
1878 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, did);
1879 if (!ndlp) {
1880 if ((phba->fc_flag & FC_RSCN_MODE) &&
dea3101e 1881 ((lpfc_rscn_payload_check(phba, did) == 0)))
1882 return NULL;
1883 ndlp = (struct lpfc_nodelist *)
1884 mempool_alloc(phba->nlp_mem_pool, GFP_KERNEL);
1885 if (!ndlp)
1886 return NULL;
1887 lpfc_nlp_init(phba, ndlp, did);
1888 ndlp->nlp_state = NLP_STE_NPR_NODE;
1889 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1890 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1891 return ndlp;
1892 }
c9f8735b 1893 if (phba->fc_flag & FC_RSCN_MODE) {
dea3101e 1894 if (lpfc_rscn_payload_check(phba, did)) {
1895 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
c9f8735b
JW
1896
1897 /* Since this node is marked for discovery,
1898 * delay timeout is not needed.
1899 */
fdcebe28
JS
1900 if (ndlp->nlp_flag & NLP_DELAY_TMO)
1901 lpfc_cancel_retry_delay_tmo(phba, ndlp);
2fe165b6 1902 } else {
dea3101e 1903 ndlp->nlp_flag &= ~NLP_NPR_2B_DISC;
1904 ndlp = NULL;
1905 }
2fe165b6 1906 } else {
dea3101e 1907 flg = ndlp->nlp_flag & NLP_LIST_MASK;
c9f8735b 1908 if ((flg == NLP_ADISC_LIST) || (flg == NLP_PLOGI_LIST))
dea3101e 1909 return NULL;
dea3101e 1910 ndlp->nlp_state = NLP_STE_NPR_NODE;
1911 lpfc_nlp_list(phba, ndlp, NLP_NPR_LIST);
1912 ndlp->nlp_flag |= NLP_NPR_2B_DISC;
1913 }
1914 return ndlp;
1915}
1916
1917/* Build a list of nodes to discover based on the loopmap */
1918void
1919lpfc_disc_list_loopmap(struct lpfc_hba * phba)
1920{
1921 int j;
1922 uint32_t alpa, index;
1923
1924 if (phba->hba_state <= LPFC_LINK_DOWN) {
1925 return;
1926 }
1927 if (phba->fc_topology != TOPOLOGY_LOOP) {
1928 return;
1929 }
1930
1931 /* Check for loop map present or not */
1932 if (phba->alpa_map[0]) {
1933 for (j = 1; j <= phba->alpa_map[0]; j++) {
1934 alpa = phba->alpa_map[j];
1935
1936 if (((phba->fc_myDID & 0xff) == alpa) || (alpa == 0)) {
1937 continue;
1938 }
1939 lpfc_setup_disc_node(phba, alpa);
1940 }
1941 } else {
1942 /* No alpamap, so try all alpa's */
1943 for (j = 0; j < FC_MAXLOOP; j++) {
1944 /* If cfg_scan_down is set, start from highest
1945 * ALPA (0xef) to lowest (0x1).
1946 */
1947 if (phba->cfg_scan_down)
1948 index = j;
1949 else
1950 index = FC_MAXLOOP - j - 1;
1951 alpa = lpfcAlpaArray[index];
1952 if ((phba->fc_myDID & 0xff) == alpa) {
1953 continue;
1954 }
1955
1956 lpfc_setup_disc_node(phba, alpa);
1957 }
1958 }
1959 return;
1960}
1961
1962/* Start Link up / RSCN discovery on NPR list */
1963void
1964lpfc_disc_start(struct lpfc_hba * phba)
1965{
1966 struct lpfc_sli *psli;
1967 LPFC_MBOXQ_t *mbox;
1968 struct lpfc_nodelist *ndlp, *next_ndlp;
1969 uint32_t did_changed, num_sent;
1970 uint32_t clear_la_pending;
1971 int rc;
1972
1973 psli = &phba->sli;
1974
1975 if (phba->hba_state <= LPFC_LINK_DOWN) {
1976 return;
1977 }
1978 if (phba->hba_state == LPFC_CLEAR_LA)
1979 clear_la_pending = 1;
1980 else
1981 clear_la_pending = 0;
1982
1983 if (phba->hba_state < LPFC_HBA_READY) {
1984 phba->hba_state = LPFC_DISC_AUTH;
1985 }
1986 lpfc_set_disctmo(phba);
1987
1988 if (phba->fc_prevDID == phba->fc_myDID) {
1989 did_changed = 0;
1990 } else {
1991 did_changed = 1;
1992 }
1993 phba->fc_prevDID = phba->fc_myDID;
1994 phba->num_disc_nodes = 0;
1995
1996 /* Start Discovery state <hba_state> */
1997 lpfc_printf_log(phba, KERN_INFO, LOG_DISCOVERY,
1998 "%d:0202 Start Discovery hba state x%x "
1999 "Data: x%x x%x x%x\n",
2000 phba->brd_no, phba->hba_state, phba->fc_flag,
2001 phba->fc_plogi_cnt, phba->fc_adisc_cnt);
2002
2003 /* If our did changed, we MUST do PLOGI */
2004 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
2005 nlp_listp) {
2006 if (ndlp->nlp_flag & NLP_NPR_2B_DISC) {
2007 if (did_changed) {
2008 spin_lock_irq(phba->host->host_lock);
2009 ndlp->nlp_flag &= ~NLP_NPR_ADISC;
2010 spin_unlock_irq(phba->host->host_lock);
2011 }
2012 }
2013 }
2014
2015 /* First do ADISCs - if any */
2016 num_sent = lpfc_els_disc_adisc(phba);
2017
2018 if (num_sent)
2019 return;
2020
2021 if ((phba->hba_state < LPFC_HBA_READY) && (!clear_la_pending)) {
2022 /* If we get here, there is nothing to ADISC */
2023 if ((mbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL))) {
2024 phba->hba_state = LPFC_CLEAR_LA;
2025 lpfc_clear_la(phba, mbox);
2026 mbox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
2027 rc = lpfc_sli_issue_mbox(phba, mbox,
2028 (MBX_NOWAIT | MBX_STOP_IOCB));
2029 if (rc == MBX_NOT_FINISHED) {
2030 mempool_free( mbox, phba->mbox_mem_pool);
2031 lpfc_disc_flush_list(phba);
2032 psli->ring[(psli->ip_ring)].flag &=
2033 ~LPFC_STOP_IOCB_EVENT;
2034 psli->ring[(psli->fcp_ring)].flag &=
2035 ~LPFC_STOP_IOCB_EVENT;
2036 psli->ring[(psli->next_ring)].flag &=
2037 ~LPFC_STOP_IOCB_EVENT;
2038 phba->hba_state = LPFC_HBA_READY;
2039 }
2040 }
2041 } else {
2042 /* Next do PLOGIs - if any */
2043 num_sent = lpfc_els_disc_plogi(phba);
2044
2045 if (num_sent)
2046 return;
2047
2048 if (phba->fc_flag & FC_RSCN_MODE) {
2049 /* Check to see if more RSCNs came in while we
2050 * were processing this one.
2051 */
2052 if ((phba->fc_rscn_id_cnt == 0) &&
2053 (!(phba->fc_flag & FC_RSCN_DISCOVERY))) {
2054 spin_lock_irq(phba->host->host_lock);
2055 phba->fc_flag &= ~FC_RSCN_MODE;
2056 spin_unlock_irq(phba->host->host_lock);
2fe165b6 2057 } else
dea3101e 2058 lpfc_els_handle_rscn(phba);
2059 }
2060 }
2061 return;
2062}
2063
2064/*
2065 * Ignore completion for all IOCBs on tx and txcmpl queue for ELS
2066 * ring the match the sppecified nodelist.
2067 */
2068static void
2069lpfc_free_tx(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp)
2070{
2071 struct lpfc_sli *psli;
2072 IOCB_t *icmd;
2073 struct lpfc_iocbq *iocb, *next_iocb;
2074 struct lpfc_sli_ring *pring;
2075 struct lpfc_dmabuf *mp;
2076
2077 psli = &phba->sli;
2078 pring = &psli->ring[LPFC_ELS_RING];
2079
2080 /* Error matching iocb on txq or txcmplq
2081 * First check the txq.
2082 */
2083 list_for_each_entry_safe(iocb, next_iocb, &pring->txq, list) {
2084 if (iocb->context1 != ndlp) {
2085 continue;
2086 }
2087 icmd = &iocb->iocb;
2088 if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
2089 (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
2090
2091 list_del(&iocb->list);
2092 pring->txq_cnt--;
2093 lpfc_els_free_iocb(phba, iocb);
2094 }
2095 }
2096
2097 /* Next check the txcmplq */
2098 list_for_each_entry_safe(iocb, next_iocb, &pring->txcmplq, list) {
2099 if (iocb->context1 != ndlp) {
2100 continue;
2101 }
2102 icmd = &iocb->iocb;
2103 if ((icmd->ulpCommand == CMD_ELS_REQUEST64_CR) ||
2104 (icmd->ulpCommand == CMD_XMIT_ELS_RSP64_CX)) {
2105
2106 iocb->iocb_cmpl = NULL;
2107 /* context2 = cmd, context2->next = rsp, context3 =
2108 bpl */
2109 if (iocb->context2) {
2110 /* Free the response IOCB before handling the
2111 command. */
2112
2113 mp = (struct lpfc_dmabuf *) (iocb->context2);
2114 mp = list_get_first(&mp->list,
2115 struct lpfc_dmabuf,
2116 list);
2117 if (mp) {
2118 /* Delay before releasing rsp buffer to
2119 * give UNREG mbox a chance to take
2120 * effect.
2121 */
2122 list_add(&mp->list,
2123 &phba->freebufList);
2124 }
2125 lpfc_mbuf_free(phba,
2126 ((struct lpfc_dmabuf *)
2127 iocb->context2)->virt,
2128 ((struct lpfc_dmabuf *)
2129 iocb->context2)->phys);
2130 kfree(iocb->context2);
2131 }
2132
2133 if (iocb->context3) {
2134 lpfc_mbuf_free(phba,
2135 ((struct lpfc_dmabuf *)
2136 iocb->context3)->virt,
2137 ((struct lpfc_dmabuf *)
2138 iocb->context3)->phys);
2139 kfree(iocb->context3);
2140 }
2141 }
2142 }
2143
2144 return;
2145}
2146
2147void
2148lpfc_disc_flush_list(struct lpfc_hba * phba)
2149{
2150 struct lpfc_nodelist *ndlp, *next_ndlp;
2151
2152 if (phba->fc_plogi_cnt) {
2153 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_plogi_list,
2154 nlp_listp) {
2155 lpfc_free_tx(phba, ndlp);
2156 lpfc_nlp_remove(phba, ndlp);
2157 }
2158 }
2159 if (phba->fc_adisc_cnt) {
2160 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_adisc_list,
2161 nlp_listp) {
2162 lpfc_free_tx(phba, ndlp);
2163 lpfc_nlp_remove(phba, ndlp);
2164 }
2165 }
2166 return;
2167}
2168
2169/*****************************************************************************/
2170/*
2171 * NAME: lpfc_disc_timeout
2172 *
2173 * FUNCTION: Fibre Channel driver discovery timeout routine.
2174 *
2175 * EXECUTION ENVIRONMENT: interrupt only
2176 *
2177 * CALLED FROM:
2178 * Timer function
2179 *
2180 * RETURNS:
2181 * none
2182 */
2183/*****************************************************************************/
2184void
2185lpfc_disc_timeout(unsigned long ptr)
2186{
2187 struct lpfc_hba *phba = (struct lpfc_hba *)ptr;
2188 unsigned long flags = 0;
2189
2190 if (unlikely(!phba))
2191 return;
2192
2193 spin_lock_irqsave(phba->host->host_lock, flags);
2194 if (!(phba->work_hba_events & WORKER_DISC_TMO)) {
2195 phba->work_hba_events |= WORKER_DISC_TMO;
2196 if (phba->work_wait)
2197 wake_up(phba->work_wait);
2198 }
2199 spin_unlock_irqrestore(phba->host->host_lock, flags);
2200 return;
2201}
2202
2203static void
2204lpfc_disc_timeout_handler(struct lpfc_hba *phba)
2205{
2206 struct lpfc_sli *psli;
c9f8735b 2207 struct lpfc_nodelist *ndlp, *next_ndlp;
dea3101e 2208 LPFC_MBOXQ_t *clearlambox, *initlinkmbox;
2209 int rc, clrlaerr = 0;
2210
2211 if (unlikely(!phba))
2212 return;
2213
2214 if (!(phba->fc_flag & FC_DISC_TMO))
2215 return;
2216
2217 psli = &phba->sli;
2218
2219 spin_lock_irq(phba->host->host_lock);
2220 phba->fc_flag &= ~FC_DISC_TMO;
2221 spin_unlock_irq(phba->host->host_lock);
2222
2223 switch (phba->hba_state) {
2224
2225 case LPFC_LOCAL_CFG_LINK:
2226 /* hba_state is identically LPFC_LOCAL_CFG_LINK while waiting for FAN */
2227 /* FAN timeout */
2228 lpfc_printf_log(phba,
2229 KERN_WARNING,
2230 LOG_DISCOVERY,
2231 "%d:0221 FAN timeout\n",
2232 phba->brd_no);
2233
c9f8735b
JW
2234 /* Start discovery by sending FLOGI, clean up old rpis */
2235 list_for_each_entry_safe(ndlp, next_ndlp, &phba->fc_npr_list,
2236 nlp_listp) {
2237 if (ndlp->nlp_type & NLP_FABRIC) {
2238 /* Clean up the ndlp on Fabric connections */
2239 lpfc_nlp_list(phba, ndlp, NLP_NO_LIST);
2fe165b6 2240 } else if (!(ndlp->nlp_flag & NLP_NPR_ADISC)) {
c9f8735b
JW
2241 /* Fail outstanding IO now since device
2242 * is marked for PLOGI.
2243 */
2244 lpfc_unreg_rpi(phba, ndlp);
2245 }
2246 }
dea3101e 2247 phba->hba_state = LPFC_FLOGI;
2248 lpfc_set_disctmo(phba);
2249 lpfc_initial_flogi(phba);
2250 break;
2251
2252 case LPFC_FLOGI:
2253 /* hba_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */
2254 /* Initial FLOGI timeout */
2255 lpfc_printf_log(phba,
2256 KERN_ERR,
2257 LOG_DISCOVERY,
2258 "%d:0222 Initial FLOGI timeout\n",
2259 phba->brd_no);
2260
2261 /* Assume no Fabric and go on with discovery.
2262 * Check for outstanding ELS FLOGI to abort.
2263 */
2264
2265 /* FLOGI failed, so just use loop map to make discovery list */
2266 lpfc_disc_list_loopmap(phba);
2267
2268 /* Start discovery */
2269 lpfc_disc_start(phba);
2270 break;
2271
2272 case LPFC_FABRIC_CFG_LINK:
2273 /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for
2274 NameServer login */
2275 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2276 "%d:0223 Timeout while waiting for NameServer "
2277 "login\n", phba->brd_no);
2278
2279 /* Next look for NameServer ndlp */
2280 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_ALL, NameServer_DID);
2281 if (ndlp)
2282 lpfc_nlp_remove(phba, ndlp);
2283 /* Start discovery */
2284 lpfc_disc_start(phba);
2285 break;
2286
2287 case LPFC_NS_QRY:
2288 /* Check for wait for NameServer Rsp timeout */
2289 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2290 "%d:0224 NameServer Query timeout "
2291 "Data: x%x x%x\n",
2292 phba->brd_no,
2293 phba->fc_ns_retry, LPFC_MAX_NS_RETRY);
2294
2295 ndlp = lpfc_findnode_did(phba, NLP_SEARCH_UNMAPPED,
2296 NameServer_DID);
2297 if (ndlp) {
2298 if (phba->fc_ns_retry < LPFC_MAX_NS_RETRY) {
2299 /* Try it one more time */
2300 rc = lpfc_ns_cmd(phba, ndlp, SLI_CTNS_GID_FT);
2301 if (rc == 0)
2302 break;
2303 }
2304 phba->fc_ns_retry = 0;
2305 }
2306
2307 /* Nothing to authenticate, so CLEAR_LA right now */
2308 clearlambox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2309 if (!clearlambox) {
2310 clrlaerr = 1;
2311 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2312 "%d:0226 Device Discovery "
2313 "completion error\n",
2314 phba->brd_no);
2315 phba->hba_state = LPFC_HBA_ERROR;
2316 break;
2317 }
2318
2319 phba->hba_state = LPFC_CLEAR_LA;
2320 lpfc_clear_la(phba, clearlambox);
2321 clearlambox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
2322 rc = lpfc_sli_issue_mbox(phba, clearlambox,
2323 (MBX_NOWAIT | MBX_STOP_IOCB));
2324 if (rc == MBX_NOT_FINISHED) {
2325 mempool_free(clearlambox, phba->mbox_mem_pool);
2326 clrlaerr = 1;
2327 break;
2328 }
2329
2330 /* Setup and issue mailbox INITIALIZE LINK command */
2331 initlinkmbox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2332 if (!initlinkmbox) {
2333 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2334 "%d:0226 Device Discovery "
2335 "completion error\n",
2336 phba->brd_no);
2337 phba->hba_state = LPFC_HBA_ERROR;
2338 break;
2339 }
2340
2341 lpfc_linkdown(phba);
2342 lpfc_init_link(phba, initlinkmbox, phba->cfg_topology,
2343 phba->cfg_link_speed);
2344 initlinkmbox->mb.un.varInitLnk.lipsr_AL_PA = 0;
2345 rc = lpfc_sli_issue_mbox(phba, initlinkmbox,
2346 (MBX_NOWAIT | MBX_STOP_IOCB));
2347 if (rc == MBX_NOT_FINISHED)
2348 mempool_free(initlinkmbox, phba->mbox_mem_pool);
2349
2350 break;
2351
2352 case LPFC_DISC_AUTH:
2353 /* Node Authentication timeout */
2354 lpfc_printf_log(phba,
2355 KERN_ERR,
2356 LOG_DISCOVERY,
2357 "%d:0227 Node Authentication timeout\n",
2358 phba->brd_no);
2359 lpfc_disc_flush_list(phba);
2360 clearlambox = mempool_alloc(phba->mbox_mem_pool, GFP_KERNEL);
2361 if (!clearlambox) {
2362 clrlaerr = 1;
2363 lpfc_printf_log(phba, KERN_ERR, LOG_DISCOVERY,
2364 "%d:0226 Device Discovery "
2365 "completion error\n",
2366 phba->brd_no);
2367 phba->hba_state = LPFC_HBA_ERROR;
2368 break;
2369 }
2370 phba->hba_state = LPFC_CLEAR_LA;
2371 lpfc_clear_la(phba, clearlambox);
2372 clearlambox->mbox_cmpl = lpfc_mbx_cmpl_clear_la;
2373 rc = lpfc_sli_issue_mbox(phba, clearlambox,
2374 (MBX_NOWAIT | MBX_STOP_IOCB));
2375 if (rc == MBX_NOT_FINISHED) {
2376 mempool_free(clearlambox, phba->mbox_mem_pool);
2377 clrlaerr = 1;
2378 }
2379 break;
2380
2381 case LPFC_CLEAR_LA:
2382 /* CLEAR LA timeout */
2383 lpfc_printf_log(phba,
2384 KERN_ERR,
2385 LOG_DISCOVERY,
2386 "%d:0228 CLEAR LA timeout\n",
2387 phba->brd_no);
2388 clrlaerr = 1;
2389 break;
2390
2391 case LPFC_HBA_READY:
2392 if (phba->fc_flag & FC_RSCN_MODE) {
2393 lpfc_printf_log(phba,
2394 KERN_ERR,
2395 LOG_DISCOVERY,
2396 "%d:0231 RSCN timeout Data: x%x x%x\n",
2397 phba->brd_no,
2398 phba->fc_ns_retry, LPFC_MAX_NS_RETRY);
2399
2400 /* Cleanup any outstanding ELS commands */
2401 lpfc_els_flush_cmd(phba);
2402
2403 lpfc_els_flush_rscn(phba);
2404 lpfc_disc_flush_list(phba);
2405 }
2406 break;
2407 }
2408
2409 if (clrlaerr) {
2410 lpfc_disc_flush_list(phba);
2411 psli->ring[(psli->ip_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
2412 psli->ring[(psli->fcp_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
2413 psli->ring[(psli->next_ring)].flag &= ~LPFC_STOP_IOCB_EVENT;
2414 phba->hba_state = LPFC_HBA_READY;
2415 }
2416
2417 return;
2418}
2419
2420static void
2421lpfc_nodev_timeout(unsigned long ptr)
2422{
2423 struct lpfc_hba *phba;
2424 struct lpfc_nodelist *ndlp;
2425 unsigned long iflag;
2426 struct lpfc_work_evt *evtp;
2427
2428 ndlp = (struct lpfc_nodelist *)ptr;
2429 phba = ndlp->nlp_phba;
2430 evtp = &ndlp->nodev_timeout_evt;
2431 spin_lock_irqsave(phba->host->host_lock, iflag);
2432
2433 if (!list_empty(&evtp->evt_listp)) {
2434 spin_unlock_irqrestore(phba->host->host_lock, iflag);
2435 return;
2436 }
2437 evtp->evt_arg1 = ndlp;
2438 evtp->evt = LPFC_EVT_NODEV_TMO;
2439 list_add_tail(&evtp->evt_listp, &phba->work_list);
2440 if (phba->work_wait)
2441 wake_up(phba->work_wait);
2442
2443 spin_unlock_irqrestore(phba->host->host_lock, iflag);
2444 return;
2445}
2446
2447
2448/*
2449 * This routine handles processing a NameServer REG_LOGIN mailbox
2450 * command upon completion. It is setup in the LPFC_MBOXQ
2451 * as the completion routine when the command is
2452 * handed off to the SLI layer.
2453 */
2454void
2455lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba * phba, LPFC_MBOXQ_t * pmb)
2456{
2457 struct lpfc_sli *psli;
2458 MAILBOX_t *mb;
2459 struct lpfc_dmabuf *mp;
2460 struct lpfc_nodelist *ndlp;
2461
2462 psli = &phba->sli;
2463 mb = &pmb->mb;
2464
2465 ndlp = (struct lpfc_nodelist *) pmb->context2;
2466 mp = (struct lpfc_dmabuf *) (pmb->context1);
2467
2468 pmb->context1 = NULL;
2469
dea3101e 2470 ndlp->nlp_rpi = mb->un.varWords[0];
dea3101e 2471 ndlp->nlp_type |= NLP_FABRIC;
2472 ndlp->nlp_state = NLP_STE_UNMAPPED_NODE;
2473 lpfc_nlp_list(phba, ndlp, NLP_UNMAPPED_LIST);
2474
2475 /* Start issuing Fabric-Device Management Interface (FDMI)
2476 * command to 0xfffffa (FDMI well known port)
2477 */
2478 if (phba->cfg_fdmi_on == 1) {
2479 lpfc_fdmi_cmd(phba, ndlp, SLI_MGMT_DHBA);
2480 } else {
2481 /*
2482 * Delay issuing FDMI command if fdmi-on=2
2483 * (supporting RPA/hostnmae)
2484 */
2485 mod_timer(&phba->fc_fdmitmo, jiffies + HZ * 60);
2486 }
2487
2488 lpfc_mbuf_free(phba, mp->virt, mp->phys);
2489 kfree(mp);
2490 mempool_free( pmb, phba->mbox_mem_pool);
2491
2492 return;
2493}
2494
2495/*
21568f53
JSEC
2496 * This routine looks up the ndlp lists
2497 * for the given RPI. If rpi found
dea3101e 2498 * it return the node list pointer
21568f53 2499 * else return NULL.
dea3101e 2500 */
2501struct lpfc_nodelist *
2502lpfc_findnode_rpi(struct lpfc_hba * phba, uint16_t rpi)
2503{
21568f53
JSEC
2504 struct lpfc_nodelist *ndlp;
2505 struct list_head * lists[]={&phba->fc_nlpunmap_list,
2506 &phba->fc_nlpmap_list,
2507 &phba->fc_plogi_list,
2508 &phba->fc_adisc_list,
2509 &phba->fc_reglogin_list};
2510 int i;
dea3101e 2511
66a9ed66 2512 spin_lock_irq(phba->host->host_lock);
21568f53
JSEC
2513 for (i = 0; i < ARRAY_SIZE(lists); i++ )
2514 list_for_each_entry(ndlp, lists[i], nlp_listp)
66a9ed66
JW
2515 if (ndlp->nlp_rpi == rpi) {
2516 spin_unlock_irq(phba->host->host_lock);
2fe165b6 2517 return ndlp;
66a9ed66
JW
2518 }
2519 spin_unlock_irq(phba->host->host_lock);
21568f53 2520 return NULL;
dea3101e 2521}
2522
488d1469
JS
2523/*
2524 * This routine looks up the ndlp lists
2525 * for the given WWPN. If WWPN found
2526 * it return the node list pointer
2527 * else return NULL.
2528 */
2529struct lpfc_nodelist *
2530lpfc_findnode_wwpn(struct lpfc_hba * phba, uint32_t order,
2531 struct lpfc_name * wwpn)
2532{
2533 struct lpfc_nodelist *ndlp;
2534 struct list_head * lists[]={&phba->fc_nlpunmap_list,
2535 &phba->fc_nlpmap_list,
2536 &phba->fc_npr_list,
2537 &phba->fc_plogi_list,
2538 &phba->fc_adisc_list,
2539 &phba->fc_reglogin_list,
2540 &phba->fc_prli_list};
2541 uint32_t search[]={NLP_SEARCH_UNMAPPED,
2542 NLP_SEARCH_MAPPED,
2543 NLP_SEARCH_NPR,
2544 NLP_SEARCH_PLOGI,
2545 NLP_SEARCH_ADISC,
2546 NLP_SEARCH_REGLOGIN,
2547 NLP_SEARCH_PRLI};
2548 int i;
2549
2550 spin_lock_irq(phba->host->host_lock);
2551 for (i = 0; i < ARRAY_SIZE(lists); i++ ) {
2552 if (!(order & search[i]))
2553 continue;
2554 list_for_each_entry(ndlp, lists[i], nlp_listp) {
2555 if (memcmp(&ndlp->nlp_portname, wwpn,
2556 sizeof(struct lpfc_name)) == 0) {
2557 spin_unlock_irq(phba->host->host_lock);
2558 return ndlp;
2559 }
2560 }
2561 }
2562 spin_unlock_irq(phba->host->host_lock);
2563 return NULL;
2564}
2565
dea3101e 2566void
2567lpfc_nlp_init(struct lpfc_hba * phba, struct lpfc_nodelist * ndlp,
2568 uint32_t did)
2569{
2570 memset(ndlp, 0, sizeof (struct lpfc_nodelist));
2571 INIT_LIST_HEAD(&ndlp->nodev_timeout_evt.evt_listp);
2572 INIT_LIST_HEAD(&ndlp->els_retry_evt.evt_listp);
2573 init_timer(&ndlp->nlp_tmofunc);
2574 ndlp->nlp_tmofunc.function = lpfc_nodev_timeout;
2575 ndlp->nlp_tmofunc.data = (unsigned long)ndlp;
2576 init_timer(&ndlp->nlp_delayfunc);
2577 ndlp->nlp_delayfunc.function = lpfc_els_retry_delay;
2578 ndlp->nlp_delayfunc.data = (unsigned long)ndlp;
2579 ndlp->nlp_DID = did;
2580 ndlp->nlp_phba = phba;
2581 ndlp->nlp_sid = NLP_NO_SID;
2582 return;
2583}
This page took 0.213135 seconds and 5 git commands to generate.