1 /*******************************************************************
2 * This file is part of the Emulex Linux Device Driver for *
3 * Fibre Channel Host Bus Adapters. *
4 * Copyright (C) 2004-2007 Emulex. All rights reserved. *
5 * EMULEX and SLI are trademarks of Emulex. *
7 * Portions Copyright (C) 2004-2005 Christoph Hellwig *
9 * This program is free software; you can redistribute it and/or *
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. *
20 *******************************************************************/
22 #include <linux/blkdev.h>
23 #include <linux/pci.h>
24 #include <linux/kthread.h>
25 #include <linux/interrupt.h>
27 #include <scsi/scsi.h>
28 #include <scsi/scsi_device.h>
29 #include <scsi/scsi_host.h>
30 #include <scsi/scsi_transport_fc.h>
33 #include "lpfc_disc.h"
35 #include "lpfc_scsi.h"
37 #include "lpfc_logmsg.h"
38 #include "lpfc_crtn.h"
39 #include "lpfc_vport.h"
40 #include "lpfc_debugfs.h"
42 /* AlpaArray for assignment of scsid for scan-down and bind_method */
43 static uint8_t lpfcAlpaArray
[] = {
44 0xEF, 0xE8, 0xE4, 0xE2, 0xE1, 0xE0, 0xDC, 0xDA, 0xD9, 0xD6,
45 0xD5, 0xD4, 0xD3, 0xD2, 0xD1, 0xCE, 0xCD, 0xCC, 0xCB, 0xCA,
46 0xC9, 0xC7, 0xC6, 0xC5, 0xC3, 0xBC, 0xBA, 0xB9, 0xB6, 0xB5,
47 0xB4, 0xB3, 0xB2, 0xB1, 0xAE, 0xAD, 0xAC, 0xAB, 0xAA, 0xA9,
48 0xA7, 0xA6, 0xA5, 0xA3, 0x9F, 0x9E, 0x9D, 0x9B, 0x98, 0x97,
49 0x90, 0x8F, 0x88, 0x84, 0x82, 0x81, 0x80, 0x7C, 0x7A, 0x79,
50 0x76, 0x75, 0x74, 0x73, 0x72, 0x71, 0x6E, 0x6D, 0x6C, 0x6B,
51 0x6A, 0x69, 0x67, 0x66, 0x65, 0x63, 0x5C, 0x5A, 0x59, 0x56,
52 0x55, 0x54, 0x53, 0x52, 0x51, 0x4E, 0x4D, 0x4C, 0x4B, 0x4A,
53 0x49, 0x47, 0x46, 0x45, 0x43, 0x3C, 0x3A, 0x39, 0x36, 0x35,
54 0x34, 0x33, 0x32, 0x31, 0x2E, 0x2D, 0x2C, 0x2B, 0x2A, 0x29,
55 0x27, 0x26, 0x25, 0x23, 0x1F, 0x1E, 0x1D, 0x1B, 0x18, 0x17,
56 0x10, 0x0F, 0x08, 0x04, 0x02, 0x01
59 static void lpfc_disc_timeout_handler(struct lpfc_vport
*);
62 lpfc_terminate_rport_io(struct fc_rport
*rport
)
64 struct lpfc_rport_data
*rdata
;
65 struct lpfc_nodelist
* ndlp
;
66 struct lpfc_hba
*phba
;
68 rdata
= rport
->dd_data
;
72 if (rport
->roles
& FC_RPORT_ROLE_FCP_TARGET
)
73 printk(KERN_ERR
"Cannot find remote node"
74 " to terminate I/O Data x%x\n",
79 phba
= ndlp
->vport
->phba
;
81 lpfc_debugfs_disc_trc(ndlp
->vport
, LPFC_DISC_TRC_RPORT
,
82 "rport terminate: sid:x%x did:x%x flg:x%x",
83 ndlp
->nlp_sid
, ndlp
->nlp_DID
, ndlp
->nlp_flag
);
85 if (ndlp
->nlp_sid
!= NLP_NO_SID
) {
86 lpfc_sli_abort_iocb(phba
, &phba
->sli
.ring
[phba
->sli
.fcp_ring
],
87 ndlp
->nlp_sid
, 0, 0, LPFC_CTX_TGT
);
94 * This function will be called when dev_loss_tmo fire.
97 lpfc_dev_loss_tmo_callbk(struct fc_rport
*rport
)
99 struct lpfc_rport_data
*rdata
;
100 struct lpfc_nodelist
* ndlp
;
101 struct lpfc_vport
*vport
;
102 struct lpfc_hba
*phba
;
103 struct completion devloss_compl
;
104 struct lpfc_work_evt
*evtp
;
106 rdata
= rport
->dd_data
;
110 if (rport
->scsi_target_id
!= -1) {
111 printk(KERN_ERR
"Cannot find remote node"
112 " for rport in dev_loss_tmo_callbk x%x\n",
121 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_RPORT
,
122 "rport devlosscb: sid:x%x did:x%x flg:x%x",
123 ndlp
->nlp_sid
, ndlp
->nlp_DID
, ndlp
->nlp_flag
);
125 init_completion(&devloss_compl
);
126 evtp
= &ndlp
->dev_loss_evt
;
128 if (!list_empty(&evtp
->evt_listp
))
131 spin_lock_irq(&phba
->hbalock
);
132 evtp
->evt_arg1
= ndlp
;
133 evtp
->evt_arg2
= &devloss_compl
;
134 evtp
->evt
= LPFC_EVT_DEV_LOSS
;
135 list_add_tail(&evtp
->evt_listp
, &phba
->work_list
);
137 wake_up(phba
->work_wait
);
139 spin_unlock_irq(&phba
->hbalock
);
141 wait_for_completion(&devloss_compl
);
147 * This function is called from the worker thread when dev_loss_tmo
151 lpfc_dev_loss_tmo_handler(struct lpfc_nodelist
*ndlp
)
153 struct lpfc_rport_data
*rdata
;
154 struct fc_rport
*rport
;
155 struct lpfc_vport
*vport
;
156 struct lpfc_hba
*phba
;
165 rdata
= rport
->dd_data
;
166 name
= (uint8_t *) &ndlp
->nlp_portname
;
170 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_RPORT
,
171 "rport devlosstmo:did:x%x type:x%x id:x%x",
172 ndlp
->nlp_DID
, ndlp
->nlp_type
, rport
->scsi_target_id
);
174 if (!(vport
->load_flag
& FC_UNLOADING
) &&
175 ndlp
->nlp_state
== NLP_STE_MAPPED_NODE
)
178 if (ndlp
->nlp_type
& NLP_FABRIC
) {
182 /* We will clean up these Nodes in linkup */
183 put_node
= rdata
->pnode
!= NULL
;
184 put_rport
= ndlp
->rport
!= NULL
;
190 put_device(&rport
->dev
);
194 if (ndlp
->nlp_sid
!= NLP_NO_SID
) {
196 /* flush the target */
197 lpfc_sli_abort_iocb(phba
, &phba
->sli
.ring
[phba
->sli
.fcp_ring
],
198 ndlp
->nlp_sid
, 0, 0, LPFC_CTX_TGT
);
200 if (vport
->load_flag
& FC_UNLOADING
)
204 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
205 "0203 Devloss timeout on "
206 "WWPN %x:%x:%x:%x:%x:%x:%x:%x "
207 "NPort x%x Data: x%x x%x x%x\n",
208 *name
, *(name
+1), *(name
+2), *(name
+3),
209 *(name
+4), *(name
+5), *(name
+6), *(name
+7),
210 ndlp
->nlp_DID
, ndlp
->nlp_flag
,
211 ndlp
->nlp_state
, ndlp
->nlp_rpi
);
213 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
214 "0204 Devloss timeout on "
215 "WWPN %x:%x:%x:%x:%x:%x:%x:%x "
216 "NPort x%x Data: x%x x%x x%x\n",
217 *name
, *(name
+1), *(name
+2), *(name
+3),
218 *(name
+4), *(name
+5), *(name
+6), *(name
+7),
219 ndlp
->nlp_DID
, ndlp
->nlp_flag
,
220 ndlp
->nlp_state
, ndlp
->nlp_rpi
);
223 if (!(vport
->load_flag
& FC_UNLOADING
) &&
224 !(ndlp
->nlp_flag
& NLP_DELAY_TMO
) &&
225 !(ndlp
->nlp_flag
& NLP_NPR_2B_DISC
) &&
226 (ndlp
->nlp_state
!= NLP_STE_UNMAPPED_NODE
))
227 lpfc_disc_state_machine(vport
, ndlp
, NULL
, NLP_EVT_DEVICE_RM
);
232 put_node
= rdata
->pnode
!= NULL
;
233 put_rport
= ndlp
->rport
!= NULL
;
239 put_device(&rport
->dev
);
245 lpfc_worker_wake_up(struct lpfc_hba
*phba
)
247 wake_up(phba
->work_wait
);
252 lpfc_work_list_done(struct lpfc_hba
*phba
)
254 struct lpfc_work_evt
*evtp
= NULL
;
255 struct lpfc_nodelist
*ndlp
;
256 struct lpfc_vport
*vport
;
259 spin_lock_irq(&phba
->hbalock
);
260 while (!list_empty(&phba
->work_list
)) {
261 list_remove_head((&phba
->work_list
), evtp
, typeof(*evtp
),
263 spin_unlock_irq(&phba
->hbalock
);
266 case LPFC_EVT_DEV_LOSS_DELAY
:
267 free_evt
= 0; /* evt is part of ndlp */
268 ndlp
= (struct lpfc_nodelist
*) (evtp
->evt_arg1
);
273 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_RPORT
,
274 "rport devlossdly:did:x%x flg:x%x",
275 ndlp
->nlp_DID
, ndlp
->nlp_flag
, 0);
277 if (!(vport
->load_flag
& FC_UNLOADING
) &&
278 !(ndlp
->nlp_flag
& NLP_DELAY_TMO
) &&
279 !(ndlp
->nlp_flag
& NLP_NPR_2B_DISC
)) {
280 lpfc_disc_state_machine(vport
, ndlp
, NULL
,
284 case LPFC_EVT_ELS_RETRY
:
285 ndlp
= (struct lpfc_nodelist
*) (evtp
->evt_arg1
);
286 lpfc_els_retry_delay_handler(ndlp
);
287 free_evt
= 0; /* evt is part of ndlp */
289 case LPFC_EVT_DEV_LOSS
:
290 ndlp
= (struct lpfc_nodelist
*)(evtp
->evt_arg1
);
292 lpfc_dev_loss_tmo_handler(ndlp
);
294 complete((struct completion
*)(evtp
->evt_arg2
));
297 case LPFC_EVT_ONLINE
:
298 if (phba
->link_state
< LPFC_LINK_DOWN
)
299 *(int *) (evtp
->evt_arg1
) = lpfc_online(phba
);
301 *(int *) (evtp
->evt_arg1
) = 0;
302 complete((struct completion
*)(evtp
->evt_arg2
));
304 case LPFC_EVT_OFFLINE_PREP
:
305 if (phba
->link_state
>= LPFC_LINK_DOWN
)
306 lpfc_offline_prep(phba
);
307 *(int *)(evtp
->evt_arg1
) = 0;
308 complete((struct completion
*)(evtp
->evt_arg2
));
310 case LPFC_EVT_OFFLINE
:
312 lpfc_sli_brdrestart(phba
);
313 *(int *)(evtp
->evt_arg1
) =
314 lpfc_sli_brdready(phba
, HS_FFRDY
| HS_MBRDY
);
315 lpfc_unblock_mgmt_io(phba
);
316 complete((struct completion
*)(evtp
->evt_arg2
));
318 case LPFC_EVT_WARM_START
:
320 lpfc_reset_barrier(phba
);
321 lpfc_sli_brdreset(phba
);
322 lpfc_hba_down_post(phba
);
323 *(int *)(evtp
->evt_arg1
) =
324 lpfc_sli_brdready(phba
, HS_MBRDY
);
325 lpfc_unblock_mgmt_io(phba
);
326 complete((struct completion
*)(evtp
->evt_arg2
));
330 *(int *)(evtp
->evt_arg1
)
331 = (phba
->pport
->stopped
)
332 ? 0 : lpfc_sli_brdkill(phba
);
333 lpfc_unblock_mgmt_io(phba
);
334 complete((struct completion
*)(evtp
->evt_arg2
));
339 spin_lock_irq(&phba
->hbalock
);
341 spin_unlock_irq(&phba
->hbalock
);
346 lpfc_work_done(struct lpfc_hba
*phba
)
348 struct lpfc_sli_ring
*pring
;
349 uint32_t ha_copy
, status
, control
, work_port_events
;
350 struct lpfc_vport
**vports
;
353 spin_lock_irq(&phba
->hbalock
);
354 ha_copy
= phba
->work_ha
;
356 spin_unlock_irq(&phba
->hbalock
);
358 if (ha_copy
& HA_ERATT
)
359 lpfc_handle_eratt(phba
);
361 if (ha_copy
& HA_MBATT
)
362 lpfc_sli_handle_mb_event(phba
);
364 if (ha_copy
& HA_LATT
)
365 lpfc_handle_latt(phba
);
366 vports
= lpfc_create_vport_work_array(phba
);
368 for(i
= 0; i
< LPFC_MAX_VPORTS
&& vports
[i
] != NULL
; i
++) {
369 work_port_events
= vports
[i
]->work_port_events
;
370 if (work_port_events
& WORKER_DISC_TMO
)
371 lpfc_disc_timeout_handler(vports
[i
]);
372 if (work_port_events
& WORKER_ELS_TMO
)
373 lpfc_els_timeout_handler(vports
[i
]);
374 if (work_port_events
& WORKER_HB_TMO
)
375 lpfc_hb_timeout_handler(phba
);
376 if (work_port_events
& WORKER_MBOX_TMO
)
377 lpfc_mbox_timeout_handler(phba
);
378 if (work_port_events
& WORKER_FABRIC_BLOCK_TMO
)
379 lpfc_unblock_fabric_iocbs(phba
);
380 if (work_port_events
& WORKER_FDMI_TMO
)
381 lpfc_fdmi_timeout_handler(vports
[i
]);
382 if (work_port_events
& WORKER_RAMP_DOWN_QUEUE
)
383 lpfc_ramp_down_queue_handler(phba
);
384 if (work_port_events
& WORKER_RAMP_UP_QUEUE
)
385 lpfc_ramp_up_queue_handler(phba
);
386 spin_lock_irq(&vports
[i
]->work_port_lock
);
387 vports
[i
]->work_port_events
&= ~work_port_events
;
388 spin_unlock_irq(&vports
[i
]->work_port_lock
);
390 lpfc_destroy_vport_work_array(vports
);
392 pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
393 status
= (ha_copy
& (HA_RXMASK
<< (4*LPFC_ELS_RING
)));
394 status
>>= (4*LPFC_ELS_RING
);
395 if ((status
& HA_RXMASK
)
396 || (pring
->flag
& LPFC_DEFERRED_RING_EVENT
)) {
397 if (pring
->flag
& LPFC_STOP_IOCB_MASK
) {
398 pring
->flag
|= LPFC_DEFERRED_RING_EVENT
;
400 lpfc_sli_handle_slow_ring_event(phba
, pring
,
403 pring
->flag
&= ~LPFC_DEFERRED_RING_EVENT
;
406 * Turn on Ring interrupts
408 spin_lock_irq(&phba
->hbalock
);
409 control
= readl(phba
->HCregaddr
);
410 if (!(control
& (HC_R0INT_ENA
<< LPFC_ELS_RING
))) {
411 lpfc_debugfs_slow_ring_trc(phba
,
412 "WRK Enable ring: cntl:x%x hacopy:x%x",
413 control
, ha_copy
, 0);
415 control
|= (HC_R0INT_ENA
<< LPFC_ELS_RING
);
416 writel(control
, phba
->HCregaddr
);
417 readl(phba
->HCregaddr
); /* flush */
420 lpfc_debugfs_slow_ring_trc(phba
,
421 "WRK Ring ok: cntl:x%x hacopy:x%x",
422 control
, ha_copy
, 0);
424 spin_unlock_irq(&phba
->hbalock
);
426 lpfc_work_list_done(phba
);
430 check_work_wait_done(struct lpfc_hba
*phba
)
432 struct lpfc_vport
*vport
;
433 struct lpfc_sli_ring
*pring
= &phba
->sli
.ring
[LPFC_ELS_RING
];
436 spin_lock_irq(&phba
->hbalock
);
437 list_for_each_entry(vport
, &phba
->port_list
, listentry
) {
438 if (vport
->work_port_events
) {
443 if (rc
|| phba
->work_ha
|| (!list_empty(&phba
->work_list
)) ||
444 kthread_should_stop() || pring
->flag
& LPFC_DEFERRED_RING_EVENT
) {
448 phba
->work_found
= 0;
449 spin_unlock_irq(&phba
->hbalock
);
455 lpfc_do_work(void *p
)
457 struct lpfc_hba
*phba
= p
;
459 DECLARE_WAIT_QUEUE_HEAD_ONSTACK(work_waitq
);
461 set_user_nice(current
, -20);
462 phba
->work_wait
= &work_waitq
;
463 phba
->work_found
= 0;
467 rc
= wait_event_interruptible(work_waitq
,
468 check_work_wait_done(phba
));
472 if (kthread_should_stop())
475 lpfc_work_done(phba
);
477 /* If there is alot of slow ring work, like during link up
478 * check_work_wait_done() may cause this thread to not give
479 * up the CPU for very long periods of time. This may cause
480 * soft lockups or other problems. To avoid these situations
481 * give up the CPU here after LPFC_MAX_WORKER_ITERATION
482 * consecutive iterations.
484 if (phba
->work_found
>= LPFC_MAX_WORKER_ITERATION
) {
485 phba
->work_found
= 0;
489 phba
->work_wait
= NULL
;
494 * This is only called to handle FC worker events. Since this a rare
495 * occurance, we allocate a struct lpfc_work_evt structure here instead of
496 * embedding it in the IOCB.
499 lpfc_workq_post_event(struct lpfc_hba
*phba
, void *arg1
, void *arg2
,
502 struct lpfc_work_evt
*evtp
;
506 * All Mailbox completions and LPFC_ELS_RING rcv ring IOCB events will
507 * be queued to worker thread for processing
509 evtp
= kmalloc(sizeof(struct lpfc_work_evt
), GFP_ATOMIC
);
513 evtp
->evt_arg1
= arg1
;
514 evtp
->evt_arg2
= arg2
;
517 spin_lock_irqsave(&phba
->hbalock
, flags
);
518 list_add_tail(&evtp
->evt_listp
, &phba
->work_list
);
520 lpfc_worker_wake_up(phba
);
521 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
527 lpfc_cleanup_rpis(struct lpfc_vport
*vport
, int remove
)
529 struct lpfc_hba
*phba
= vport
->phba
;
530 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
533 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
, nlp_listp
) {
534 if (ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
)
537 if (phba
->sli3_options
& LPFC_SLI3_VPORT_TEARDOWN
)
538 lpfc_unreg_rpi(vport
, ndlp
);
540 /* Leave Fabric nodes alone on link down */
541 if (!remove
&& ndlp
->nlp_type
& NLP_FABRIC
)
543 rc
= lpfc_disc_state_machine(vport
, ndlp
, NULL
,
546 : NLP_EVT_DEVICE_RECOVERY
);
548 if (phba
->sli3_options
& LPFC_SLI3_VPORT_TEARDOWN
) {
549 lpfc_mbx_unreg_vpi(vport
);
550 vport
->fc_flag
|= FC_VPORT_NEEDS_REG_VPI
;
555 lpfc_linkdown_port(struct lpfc_vport
*vport
)
557 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
558 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
560 fc_host_post_event(shost
, fc_get_event_number(), FCH_EVT_LINKDOWN
, 0);
562 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
563 "Link Down: state:x%x rtry:x%x flg:x%x",
564 vport
->port_state
, vport
->fc_ns_retry
, vport
->fc_flag
);
566 /* Cleanup any outstanding RSCN activity */
567 lpfc_els_flush_rscn(vport
);
569 /* Cleanup any outstanding ELS commands */
570 lpfc_els_flush_cmd(vport
);
572 lpfc_cleanup_rpis(vport
, 0);
574 /* free any ndlp's on unused list */
575 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
, nlp_listp
)
576 if (ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
)
577 lpfc_drop_node(vport
, ndlp
);
579 /* Turn off discovery timer if its running */
580 lpfc_can_disctmo(vport
);
584 lpfc_linkdown(struct lpfc_hba
*phba
)
586 struct lpfc_vport
*vport
= phba
->pport
;
587 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
588 struct lpfc_vport
**vports
;
592 if (phba
->link_state
== LPFC_LINK_DOWN
) {
595 spin_lock_irq(&phba
->hbalock
);
596 if (phba
->link_state
> LPFC_LINK_DOWN
) {
597 phba
->link_state
= LPFC_LINK_DOWN
;
598 phba
->pport
->fc_flag
&= ~FC_LBIT
;
600 spin_unlock_irq(&phba
->hbalock
);
601 vports
= lpfc_create_vport_work_array(phba
);
603 for(i
= 0; i
< LPFC_MAX_VPORTS
&& vports
[i
] != NULL
; i
++) {
604 /* Issue a LINK DOWN event to all nodes */
605 lpfc_linkdown_port(vports
[i
]);
607 lpfc_destroy_vport_work_array(vports
);
608 /* Clean up any firmware default rpi's */
609 mb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
611 lpfc_unreg_did(phba
, 0xffff, 0xffffffff, mb
);
613 mb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
614 if (lpfc_sli_issue_mbox(phba
, mb
, (MBX_NOWAIT
| MBX_STOP_IOCB
))
615 == MBX_NOT_FINISHED
) {
616 mempool_free(mb
, phba
->mbox_mem_pool
);
620 /* Setup myDID for link up if we are in pt2pt mode */
621 if (phba
->pport
->fc_flag
& FC_PT2PT
) {
622 phba
->pport
->fc_myDID
= 0;
623 mb
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
625 lpfc_config_link(phba
, mb
);
626 mb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
628 if (lpfc_sli_issue_mbox(phba
, mb
,
629 (MBX_NOWAIT
| MBX_STOP_IOCB
))
630 == MBX_NOT_FINISHED
) {
631 mempool_free(mb
, phba
->mbox_mem_pool
);
634 spin_lock_irq(shost
->host_lock
);
635 phba
->pport
->fc_flag
&= ~(FC_PT2PT
| FC_PT2PT_PLOGI
);
636 spin_unlock_irq(shost
->host_lock
);
643 lpfc_linkup_cleanup_nodes(struct lpfc_vport
*vport
)
645 struct lpfc_nodelist
*ndlp
;
647 list_for_each_entry(ndlp
, &vport
->fc_nodes
, nlp_listp
) {
648 if (ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
)
651 if (ndlp
->nlp_type
& NLP_FABRIC
) {
652 /* On Linkup its safe to clean up the ndlp
653 * from Fabric connections.
655 if (ndlp
->nlp_DID
!= Fabric_DID
)
656 lpfc_unreg_rpi(vport
, ndlp
);
657 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
658 } else if (!(ndlp
->nlp_flag
& NLP_NPR_ADISC
)) {
659 /* Fail outstanding IO now since device is
662 lpfc_unreg_rpi(vport
, ndlp
);
668 lpfc_linkup_port(struct lpfc_vport
*vport
)
670 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
671 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
672 struct lpfc_hba
*phba
= vport
->phba
;
674 if ((vport
->load_flag
& FC_UNLOADING
) != 0)
677 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
678 "Link Up: top:x%x speed:x%x flg:x%x",
679 phba
->fc_topology
, phba
->fc_linkspeed
, phba
->link_flag
);
681 /* If NPIV is not enabled, only bring the physical port up */
682 if (!(phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
683 (vport
!= phba
->pport
))
686 fc_host_post_event(shost
, fc_get_event_number(), FCH_EVT_LINKUP
, 0);
688 spin_lock_irq(shost
->host_lock
);
689 vport
->fc_flag
&= ~(FC_PT2PT
| FC_PT2PT_PLOGI
| FC_ABORT_DISCOVERY
|
690 FC_RSCN_MODE
| FC_NLP_MORE
| FC_RSCN_DISCOVERY
);
691 vport
->fc_flag
|= FC_NDISC_ACTIVE
;
692 vport
->fc_ns_retry
= 0;
693 spin_unlock_irq(shost
->host_lock
);
695 if (vport
->fc_flag
& FC_LBIT
)
696 lpfc_linkup_cleanup_nodes(vport
);
698 /* free any ndlp's in unused state */
699 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
,
701 if (ndlp
->nlp_state
== NLP_STE_UNUSED_NODE
)
702 lpfc_drop_node(vport
, ndlp
);
706 lpfc_linkup(struct lpfc_hba
*phba
)
708 struct lpfc_vport
**vports
;
711 phba
->link_state
= LPFC_LINK_UP
;
713 /* Unblock fabric iocbs if they are blocked */
714 clear_bit(FABRIC_COMANDS_BLOCKED
, &phba
->bit_flags
);
715 del_timer_sync(&phba
->fabric_block_timer
);
717 vports
= lpfc_create_vport_work_array(phba
);
719 for(i
= 0; i
< LPFC_MAX_VPORTS
&& vports
[i
] != NULL
; i
++)
720 lpfc_linkup_port(vports
[i
]);
721 lpfc_destroy_vport_work_array(vports
);
722 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
)
723 lpfc_issue_clear_la(phba
, phba
->pport
);
729 * This routine handles processing a CLEAR_LA mailbox
730 * command upon completion. It is setup in the LPFC_MBOXQ
731 * as the completion routine when the command is
732 * handed off to the SLI layer.
735 lpfc_mbx_cmpl_clear_la(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
737 struct lpfc_vport
*vport
= pmb
->vport
;
738 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
739 struct lpfc_sli
*psli
= &phba
->sli
;
740 MAILBOX_t
*mb
= &pmb
->mb
;
743 /* Since we don't do discovery right now, turn these off here */
744 psli
->ring
[psli
->extra_ring
].flag
&= ~LPFC_STOP_IOCB_EVENT
;
745 psli
->ring
[psli
->fcp_ring
].flag
&= ~LPFC_STOP_IOCB_EVENT
;
746 psli
->ring
[psli
->next_ring
].flag
&= ~LPFC_STOP_IOCB_EVENT
;
748 /* Check for error */
749 if ((mb
->mbxStatus
) && (mb
->mbxStatus
!= 0x1601)) {
750 /* CLEAR_LA mbox error <mbxStatus> state <hba_state> */
751 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
752 "0320 CLEAR_LA mbxStatus error x%x hba "
754 mb
->mbxStatus
, vport
->port_state
);
755 phba
->link_state
= LPFC_HBA_ERROR
;
759 if (vport
->port_type
== LPFC_PHYSICAL_PORT
)
760 phba
->link_state
= LPFC_HBA_READY
;
762 spin_lock_irq(&phba
->hbalock
);
763 psli
->sli_flag
|= LPFC_PROCESS_LA
;
764 control
= readl(phba
->HCregaddr
);
765 control
|= HC_LAINT_ENA
;
766 writel(control
, phba
->HCregaddr
);
767 readl(phba
->HCregaddr
); /* flush */
768 spin_unlock_irq(&phba
->hbalock
);
771 vport
->num_disc_nodes
= 0;
772 /* go thru NPR nodes and issue ELS PLOGIs */
773 if (vport
->fc_npr_cnt
)
774 lpfc_els_disc_plogi(vport
);
776 if (!vport
->num_disc_nodes
) {
777 spin_lock_irq(shost
->host_lock
);
778 vport
->fc_flag
&= ~FC_NDISC_ACTIVE
;
779 spin_unlock_irq(shost
->host_lock
);
782 vport
->port_state
= LPFC_VPORT_READY
;
785 /* Device Discovery completes */
786 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
787 "0225 Device Discovery completes\n");
788 mempool_free(pmb
, phba
->mbox_mem_pool
);
790 spin_lock_irq(shost
->host_lock
);
791 vport
->fc_flag
&= ~(FC_ABORT_DISCOVERY
| FC_ESTABLISH_LINK
);
792 spin_unlock_irq(shost
->host_lock
);
794 del_timer_sync(&phba
->fc_estabtmo
);
796 lpfc_can_disctmo(vport
);
798 /* turn on Link Attention interrupts */
800 spin_lock_irq(&phba
->hbalock
);
801 psli
->sli_flag
|= LPFC_PROCESS_LA
;
802 control
= readl(phba
->HCregaddr
);
803 control
|= HC_LAINT_ENA
;
804 writel(control
, phba
->HCregaddr
);
805 readl(phba
->HCregaddr
); /* flush */
806 spin_unlock_irq(&phba
->hbalock
);
813 lpfc_mbx_cmpl_local_config_link(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
815 struct lpfc_vport
*vport
= pmb
->vport
;
817 if (pmb
->mb
.mbxStatus
)
820 mempool_free(pmb
, phba
->mbox_mem_pool
);
822 if (phba
->fc_topology
== TOPOLOGY_LOOP
&&
823 vport
->fc_flag
& FC_PUBLIC_LOOP
&&
824 !(vport
->fc_flag
& FC_LBIT
)) {
825 /* Need to wait for FAN - use discovery timer
826 * for timeout. port_state is identically
827 * LPFC_LOCAL_CFG_LINK while waiting for FAN
829 lpfc_set_disctmo(vport
);
833 /* Start discovery by sending a FLOGI. port_state is identically
834 * LPFC_FLOGI while waiting for FLOGI cmpl
836 if (vport
->port_state
!= LPFC_FLOGI
) {
837 vport
->port_state
= LPFC_FLOGI
;
838 lpfc_set_disctmo(vport
);
839 lpfc_initial_flogi(vport
);
844 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
845 "0306 CONFIG_LINK mbxStatus error x%x "
847 pmb
->mb
.mbxStatus
, vport
->port_state
);
848 mempool_free(pmb
, phba
->mbox_mem_pool
);
852 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
853 "0200 CONFIG_LINK bad hba state x%x\n",
856 lpfc_issue_clear_la(phba
, vport
);
861 lpfc_mbx_cmpl_read_sparam(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
863 MAILBOX_t
*mb
= &pmb
->mb
;
864 struct lpfc_dmabuf
*mp
= (struct lpfc_dmabuf
*) pmb
->context1
;
865 struct lpfc_vport
*vport
= pmb
->vport
;
868 /* Check for error */
870 /* READ_SPARAM mbox error <mbxStatus> state <hba_state> */
871 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
872 "0319 READ_SPARAM mbxStatus error x%x "
874 mb
->mbxStatus
, vport
->port_state
);
879 memcpy((uint8_t *) &vport
->fc_sparam
, (uint8_t *) mp
->virt
,
880 sizeof (struct serv_parm
));
881 if (phba
->cfg_soft_wwnn
)
882 u64_to_wwn(phba
->cfg_soft_wwnn
,
883 vport
->fc_sparam
.nodeName
.u
.wwn
);
884 if (phba
->cfg_soft_wwpn
)
885 u64_to_wwn(phba
->cfg_soft_wwpn
,
886 vport
->fc_sparam
.portName
.u
.wwn
);
887 memcpy(&vport
->fc_nodename
, &vport
->fc_sparam
.nodeName
,
888 sizeof(vport
->fc_nodename
));
889 memcpy(&vport
->fc_portname
, &vport
->fc_sparam
.portName
,
890 sizeof(vport
->fc_portname
));
891 if (vport
->port_type
== LPFC_PHYSICAL_PORT
) {
892 memcpy(&phba
->wwnn
, &vport
->fc_nodename
, sizeof(phba
->wwnn
));
893 memcpy(&phba
->wwpn
, &vport
->fc_portname
, sizeof(phba
->wwnn
));
896 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
898 mempool_free(pmb
, phba
->mbox_mem_pool
);
902 pmb
->context1
= NULL
;
903 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
905 lpfc_issue_clear_la(phba
, vport
);
906 mempool_free(pmb
, phba
->mbox_mem_pool
);
911 lpfc_mbx_process_link_up(struct lpfc_hba
*phba
, READ_LA_VAR
*la
)
913 struct lpfc_vport
*vport
= phba
->pport
;
914 LPFC_MBOXQ_t
*sparam_mbox
, *cfglink_mbox
;
916 struct lpfc_dmabuf
*mp
;
919 sparam_mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
920 cfglink_mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
922 spin_lock_irq(&phba
->hbalock
);
923 switch (la
->UlnkSpeed
) {
925 phba
->fc_linkspeed
= LA_1GHZ_LINK
;
928 phba
->fc_linkspeed
= LA_2GHZ_LINK
;
931 phba
->fc_linkspeed
= LA_4GHZ_LINK
;
934 phba
->fc_linkspeed
= LA_8GHZ_LINK
;
937 phba
->fc_linkspeed
= LA_UNKNW_LINK
;
941 phba
->fc_topology
= la
->topology
;
942 phba
->link_flag
&= ~LS_NPIV_FAB_SUPPORTED
;
944 if (phba
->fc_topology
== TOPOLOGY_LOOP
) {
945 phba
->sli3_options
&= ~LPFC_SLI3_NPIV_ENABLED
;
947 /* Get Loop Map information */
949 vport
->fc_flag
|= FC_LBIT
;
951 vport
->fc_myDID
= la
->granted_AL_PA
;
952 i
= la
->un
.lilpBde64
.tus
.f
.bdeSize
;
955 phba
->alpa_map
[0] = 0;
957 if (vport
->cfg_log_verbose
& LOG_LINK_EVENT
) {
968 numalpa
= phba
->alpa_map
[0];
970 while (j
< numalpa
) {
971 memset(un
.pamap
, 0, 16);
972 for (k
= 1; j
< numalpa
; k
++) {
974 phba
->alpa_map
[j
+ 1];
979 /* Link Up Event ALPA map */
980 lpfc_printf_log(phba
,
983 "1304 Link Up Event "
984 "ALPA map Data: x%x "
986 un
.pa
.wd1
, un
.pa
.wd2
,
987 un
.pa
.wd3
, un
.pa
.wd4
);
992 if (!(phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
)) {
993 if (phba
->max_vpi
&& phba
->cfg_npiv_enable
&&
994 (phba
->sli_rev
== 3))
995 phba
->sli3_options
|= LPFC_SLI3_NPIV_ENABLED
;
997 vport
->fc_myDID
= phba
->fc_pref_DID
;
998 vport
->fc_flag
|= FC_LBIT
;
1000 spin_unlock_irq(&phba
->hbalock
);
1004 lpfc_read_sparam(phba
, sparam_mbox
, 0);
1005 sparam_mbox
->vport
= vport
;
1006 sparam_mbox
->mbox_cmpl
= lpfc_mbx_cmpl_read_sparam
;
1007 rc
= lpfc_sli_issue_mbox(phba
, sparam_mbox
,
1008 (MBX_NOWAIT
| MBX_STOP_IOCB
));
1009 if (rc
== MBX_NOT_FINISHED
) {
1010 mp
= (struct lpfc_dmabuf
*) sparam_mbox
->context1
;
1011 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
1013 mempool_free(sparam_mbox
, phba
->mbox_mem_pool
);
1015 mempool_free(cfglink_mbox
, phba
->mbox_mem_pool
);
1021 vport
->port_state
= LPFC_LOCAL_CFG_LINK
;
1022 lpfc_config_link(phba
, cfglink_mbox
);
1023 cfglink_mbox
->vport
= vport
;
1024 cfglink_mbox
->mbox_cmpl
= lpfc_mbx_cmpl_local_config_link
;
1025 rc
= lpfc_sli_issue_mbox(phba
, cfglink_mbox
,
1026 (MBX_NOWAIT
| MBX_STOP_IOCB
));
1027 if (rc
!= MBX_NOT_FINISHED
)
1029 mempool_free(cfglink_mbox
, phba
->mbox_mem_pool
);
1032 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
1033 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
1034 "0263 Discovery Mailbox error: state: 0x%x : %p %p\n",
1035 vport
->port_state
, sparam_mbox
, cfglink_mbox
);
1036 lpfc_issue_clear_la(phba
, vport
);
1041 lpfc_mbx_issue_link_down(struct lpfc_hba
*phba
)
1044 struct lpfc_sli
*psli
= &phba
->sli
;
1046 lpfc_linkdown(phba
);
1048 /* turn on Link Attention interrupts - no CLEAR_LA needed */
1049 spin_lock_irq(&phba
->hbalock
);
1050 psli
->sli_flag
|= LPFC_PROCESS_LA
;
1051 control
= readl(phba
->HCregaddr
);
1052 control
|= HC_LAINT_ENA
;
1053 writel(control
, phba
->HCregaddr
);
1054 readl(phba
->HCregaddr
); /* flush */
1055 spin_unlock_irq(&phba
->hbalock
);
1059 * This routine handles processing a READ_LA mailbox
1060 * command upon completion. It is setup in the LPFC_MBOXQ
1061 * as the completion routine when the command is
1062 * handed off to the SLI layer.
1065 lpfc_mbx_cmpl_read_la(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
1067 struct lpfc_vport
*vport
= pmb
->vport
;
1068 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1070 MAILBOX_t
*mb
= &pmb
->mb
;
1071 struct lpfc_dmabuf
*mp
= (struct lpfc_dmabuf
*) (pmb
->context1
);
1073 /* Check for error */
1074 if (mb
->mbxStatus
) {
1075 lpfc_printf_log(phba
, KERN_INFO
, LOG_LINK_EVENT
,
1076 "1307 READ_LA mbox error x%x state x%x\n",
1077 mb
->mbxStatus
, vport
->port_state
);
1078 lpfc_mbx_issue_link_down(phba
);
1079 phba
->link_state
= LPFC_HBA_ERROR
;
1080 goto lpfc_mbx_cmpl_read_la_free_mbuf
;
1083 la
= (READ_LA_VAR
*) & pmb
->mb
.un
.varReadLA
;
1085 memcpy(&phba
->alpa_map
[0], mp
->virt
, 128);
1087 spin_lock_irq(shost
->host_lock
);
1089 vport
->fc_flag
|= FC_BYPASSED_MODE
;
1091 vport
->fc_flag
&= ~FC_BYPASSED_MODE
;
1092 spin_unlock_irq(shost
->host_lock
);
1094 if (((phba
->fc_eventTag
+ 1) < la
->eventTag
) ||
1095 (phba
->fc_eventTag
== la
->eventTag
)) {
1096 phba
->fc_stat
.LinkMultiEvent
++;
1097 if (la
->attType
== AT_LINK_UP
)
1098 if (phba
->fc_eventTag
!= 0)
1099 lpfc_linkdown(phba
);
1102 phba
->fc_eventTag
= la
->eventTag
;
1104 if (la
->attType
== AT_LINK_UP
) {
1105 phba
->fc_stat
.LinkUp
++;
1106 if (phba
->link_flag
& LS_LOOPBACK_MODE
) {
1107 lpfc_printf_log(phba
, KERN_INFO
, LOG_LINK_EVENT
,
1108 "1306 Link Up Event in loop back mode "
1109 "x%x received Data: x%x x%x x%x x%x\n",
1110 la
->eventTag
, phba
->fc_eventTag
,
1111 la
->granted_AL_PA
, la
->UlnkSpeed
,
1114 lpfc_printf_log(phba
, KERN_ERR
, LOG_LINK_EVENT
,
1115 "1303 Link Up Event x%x received "
1116 "Data: x%x x%x x%x x%x\n",
1117 la
->eventTag
, phba
->fc_eventTag
,
1118 la
->granted_AL_PA
, la
->UlnkSpeed
,
1121 lpfc_mbx_process_link_up(phba
, la
);
1123 phba
->fc_stat
.LinkDown
++;
1124 lpfc_printf_log(phba
, KERN_ERR
, LOG_LINK_EVENT
,
1125 "1305 Link Down Event x%x received "
1126 "Data: x%x x%x x%x\n",
1127 la
->eventTag
, phba
->fc_eventTag
,
1128 phba
->pport
->port_state
, vport
->fc_flag
);
1129 lpfc_mbx_issue_link_down(phba
);
1132 lpfc_mbx_cmpl_read_la_free_mbuf
:
1133 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
1135 mempool_free(pmb
, phba
->mbox_mem_pool
);
1140 * This routine handles processing a REG_LOGIN mailbox
1141 * command upon completion. It is setup in the LPFC_MBOXQ
1142 * as the completion routine when the command is
1143 * handed off to the SLI layer.
1146 lpfc_mbx_cmpl_reg_login(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
1148 struct lpfc_vport
*vport
= pmb
->vport
;
1149 struct lpfc_dmabuf
*mp
= (struct lpfc_dmabuf
*) (pmb
->context1
);
1150 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
1152 pmb
->context1
= NULL
;
1154 /* Good status, call state machine */
1155 lpfc_disc_state_machine(vport
, ndlp
, pmb
, NLP_EVT_CMPL_REG_LOGIN
);
1156 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
1158 mempool_free(pmb
, phba
->mbox_mem_pool
);
1165 lpfc_mbx_cmpl_unreg_vpi(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
1167 MAILBOX_t
*mb
= &pmb
->mb
;
1168 struct lpfc_vport
*vport
= pmb
->vport
;
1169 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1171 switch (mb
->mbxStatus
) {
1175 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
1176 "0911 cmpl_unreg_vpi, mb status = 0x%x\n",
1180 vport
->unreg_vpi_cmpl
= VPORT_OK
;
1181 mempool_free(pmb
, phba
->mbox_mem_pool
);
1183 * This shost reference might have been taken at the beginning of
1184 * lpfc_vport_delete()
1186 if (vport
->load_flag
& FC_UNLOADING
)
1187 scsi_host_put(shost
);
1191 lpfc_mbx_unreg_vpi(struct lpfc_vport
*vport
)
1193 struct lpfc_hba
*phba
= vport
->phba
;
1197 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1201 lpfc_unreg_vpi(phba
, vport
->vpi
, mbox
);
1202 mbox
->vport
= vport
;
1203 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_unreg_vpi
;
1204 rc
= lpfc_sli_issue_mbox(phba
, mbox
, (MBX_NOWAIT
| MBX_STOP_IOCB
));
1205 if (rc
== MBX_NOT_FINISHED
) {
1206 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
| LOG_VPORT
,
1207 "1800 Could not issue unreg_vpi\n");
1208 mempool_free(mbox
, phba
->mbox_mem_pool
);
1209 vport
->unreg_vpi_cmpl
= VPORT_ERROR
;
1214 lpfc_mbx_cmpl_reg_vpi(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
1216 struct lpfc_vport
*vport
= pmb
->vport
;
1217 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1218 MAILBOX_t
*mb
= &pmb
->mb
;
1220 switch (mb
->mbxStatus
) {
1224 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
1225 "0912 cmpl_reg_vpi, mb status = 0x%x\n",
1227 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
1228 spin_lock_irq(shost
->host_lock
);
1229 vport
->fc_flag
&= ~(FC_FABRIC
| FC_PUBLIC_LOOP
);
1230 spin_unlock_irq(shost
->host_lock
);
1231 vport
->fc_myDID
= 0;
1235 vport
->num_disc_nodes
= 0;
1236 /* go thru NPR list and issue ELS PLOGIs */
1237 if (vport
->fc_npr_cnt
)
1238 lpfc_els_disc_plogi(vport
);
1240 if (!vport
->num_disc_nodes
) {
1241 spin_lock_irq(shost
->host_lock
);
1242 vport
->fc_flag
&= ~FC_NDISC_ACTIVE
;
1243 spin_unlock_irq(shost
->host_lock
);
1244 lpfc_can_disctmo(vport
);
1246 vport
->port_state
= LPFC_VPORT_READY
;
1249 mempool_free(pmb
, phba
->mbox_mem_pool
);
1254 * This routine handles processing a Fabric REG_LOGIN mailbox
1255 * command upon completion. It is setup in the LPFC_MBOXQ
1256 * as the completion routine when the command is
1257 * handed off to the SLI layer.
1260 lpfc_mbx_cmpl_fabric_reg_login(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
1262 struct lpfc_vport
*vport
= pmb
->vport
;
1263 MAILBOX_t
*mb
= &pmb
->mb
;
1264 struct lpfc_dmabuf
*mp
= (struct lpfc_dmabuf
*) (pmb
->context1
);
1265 struct lpfc_nodelist
*ndlp
;
1266 struct lpfc_vport
**vports
;
1269 ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
1270 pmb
->context1
= NULL
;
1271 pmb
->context2
= NULL
;
1272 if (mb
->mbxStatus
) {
1273 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
1275 mempool_free(pmb
, phba
->mbox_mem_pool
);
1278 if (phba
->fc_topology
== TOPOLOGY_LOOP
) {
1279 /* FLOGI failed, use loop map to make discovery list */
1280 lpfc_disc_list_loopmap(vport
);
1282 /* Start discovery */
1283 lpfc_disc_start(vport
);
1287 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
1288 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
,
1289 "0258 Register Fabric login error: 0x%x\n",
1294 ndlp
->nlp_rpi
= mb
->un
.varWords
[0];
1295 ndlp
->nlp_type
|= NLP_FABRIC
;
1296 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
1298 lpfc_nlp_put(ndlp
); /* Drop the reference from the mbox */
1300 if (vport
->port_state
== LPFC_FABRIC_CFG_LINK
) {
1301 vports
= lpfc_create_vport_work_array(phba
);
1304 i
< LPFC_MAX_VPORTS
&& vports
[i
] != NULL
;
1306 if (vports
[i
]->port_type
== LPFC_PHYSICAL_PORT
)
1308 if (phba
->link_flag
& LS_NPIV_FAB_SUPPORTED
)
1309 lpfc_initial_fdisc(vports
[i
]);
1310 else if (phba
->sli3_options
&
1311 LPFC_SLI3_NPIV_ENABLED
) {
1312 lpfc_vport_set_state(vports
[i
],
1313 FC_VPORT_NO_FABRIC_SUPP
);
1314 lpfc_printf_vlog(vport
, KERN_ERR
,
1317 "Fabric support\n");
1320 lpfc_destroy_vport_work_array(vports
);
1321 lpfc_do_scr_ns_plogi(phba
, vport
);
1324 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
1326 mempool_free(pmb
, phba
->mbox_mem_pool
);
1331 * This routine handles processing a NameServer REG_LOGIN mailbox
1332 * command upon completion. It is setup in the LPFC_MBOXQ
1333 * as the completion routine when the command is
1334 * handed off to the SLI layer.
1337 lpfc_mbx_cmpl_ns_reg_login(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
1339 MAILBOX_t
*mb
= &pmb
->mb
;
1340 struct lpfc_dmabuf
*mp
= (struct lpfc_dmabuf
*) (pmb
->context1
);
1341 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
1342 struct lpfc_vport
*vport
= pmb
->vport
;
1344 if (mb
->mbxStatus
) {
1347 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
1349 mempool_free(pmb
, phba
->mbox_mem_pool
);
1350 lpfc_drop_node(vport
, ndlp
);
1352 if (phba
->fc_topology
== TOPOLOGY_LOOP
) {
1354 * RegLogin failed, use loop map to make discovery
1357 lpfc_disc_list_loopmap(vport
);
1359 /* Start discovery */
1360 lpfc_disc_start(vport
);
1363 lpfc_vport_set_state(vport
, FC_VPORT_FAILED
);
1364 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_ELS
,
1365 "0260 Register NameServer error: 0x%x\n",
1370 pmb
->context1
= NULL
;
1372 ndlp
->nlp_rpi
= mb
->un
.varWords
[0];
1373 ndlp
->nlp_type
|= NLP_FABRIC
;
1374 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
1376 if (vport
->port_state
< LPFC_VPORT_READY
) {
1377 /* Link up discovery requires Fabric registration. */
1378 lpfc_ns_cmd(vport
, SLI_CTNS_RFF_ID
, 0, 0); /* Do this first! */
1379 lpfc_ns_cmd(vport
, SLI_CTNS_RNN_ID
, 0, 0);
1380 lpfc_ns_cmd(vport
, SLI_CTNS_RSNN_NN
, 0, 0);
1381 lpfc_ns_cmd(vport
, SLI_CTNS_RSPN_ID
, 0, 0);
1382 lpfc_ns_cmd(vport
, SLI_CTNS_RFT_ID
, 0, 0);
1384 /* Issue SCR just before NameServer GID_FT Query */
1385 lpfc_issue_els_scr(vport
, SCR_DID
, 0);
1388 vport
->fc_ns_retry
= 0;
1389 /* Good status, issue CT Request to NameServer */
1390 if (lpfc_ns_cmd(vport
, SLI_CTNS_GID_FT
, 0, 0)) {
1391 /* Cannot issue NameServer Query, so finish up discovery */
1396 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
1398 mempool_free(pmb
, phba
->mbox_mem_pool
);
1404 lpfc_register_remote_port(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
1406 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1407 struct fc_rport
*rport
;
1408 struct lpfc_rport_data
*rdata
;
1409 struct fc_rport_identifiers rport_ids
;
1410 struct lpfc_hba
*phba
= vport
->phba
;
1412 /* Remote port has reappeared. Re-register w/ FC transport */
1413 rport_ids
.node_name
= wwn_to_u64(ndlp
->nlp_nodename
.u
.wwn
);
1414 rport_ids
.port_name
= wwn_to_u64(ndlp
->nlp_portname
.u
.wwn
);
1415 rport_ids
.port_id
= ndlp
->nlp_DID
;
1416 rport_ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
1419 * We leave our node pointer in rport->dd_data when we unregister a
1420 * FCP target port. But fc_remote_port_add zeros the space to which
1421 * rport->dd_data points. So, if we're reusing a previously
1422 * registered port, drop the reference that we took the last time we
1423 * registered the port.
1425 if (ndlp
->rport
&& ndlp
->rport
->dd_data
&&
1426 ((struct lpfc_rport_data
*) ndlp
->rport
->dd_data
)->pnode
== ndlp
) {
1430 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_RPORT
,
1431 "rport add: did:x%x flg:x%x type x%x",
1432 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_type
);
1434 ndlp
->rport
= rport
= fc_remote_port_add(shost
, 0, &rport_ids
);
1435 if (!rport
|| !get_device(&rport
->dev
)) {
1436 dev_printk(KERN_WARNING
, &phba
->pcidev
->dev
,
1437 "Warning: fc_remote_port_add failed\n");
1441 /* initialize static port data */
1442 rport
->maxframe_size
= ndlp
->nlp_maxframe
;
1443 rport
->supported_classes
= ndlp
->nlp_class_sup
;
1444 rdata
= rport
->dd_data
;
1445 rdata
->pnode
= lpfc_nlp_get(ndlp
);
1447 if (ndlp
->nlp_type
& NLP_FCP_TARGET
)
1448 rport_ids
.roles
|= FC_RPORT_ROLE_FCP_TARGET
;
1449 if (ndlp
->nlp_type
& NLP_FCP_INITIATOR
)
1450 rport_ids
.roles
|= FC_RPORT_ROLE_FCP_INITIATOR
;
1453 if (rport_ids
.roles
!= FC_RPORT_ROLE_UNKNOWN
)
1454 fc_remote_port_rolechg(rport
, rport_ids
.roles
);
1456 if ((rport
->scsi_target_id
!= -1) &&
1457 (rport
->scsi_target_id
< LPFC_MAX_TARGET
)) {
1458 ndlp
->nlp_sid
= rport
->scsi_target_id
;
1464 lpfc_unregister_remote_port(struct lpfc_nodelist
*ndlp
)
1466 struct fc_rport
*rport
= ndlp
->rport
;
1468 lpfc_debugfs_disc_trc(ndlp
->vport
, LPFC_DISC_TRC_RPORT
,
1469 "rport delete: did:x%x flg:x%x type x%x",
1470 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_type
);
1472 fc_remote_port_delete(rport
);
1478 lpfc_nlp_counters(struct lpfc_vport
*vport
, int state
, int count
)
1480 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1482 spin_lock_irq(shost
->host_lock
);
1484 case NLP_STE_UNUSED_NODE
:
1485 vport
->fc_unused_cnt
+= count
;
1487 case NLP_STE_PLOGI_ISSUE
:
1488 vport
->fc_plogi_cnt
+= count
;
1490 case NLP_STE_ADISC_ISSUE
:
1491 vport
->fc_adisc_cnt
+= count
;
1493 case NLP_STE_REG_LOGIN_ISSUE
:
1494 vport
->fc_reglogin_cnt
+= count
;
1496 case NLP_STE_PRLI_ISSUE
:
1497 vport
->fc_prli_cnt
+= count
;
1499 case NLP_STE_UNMAPPED_NODE
:
1500 vport
->fc_unmap_cnt
+= count
;
1502 case NLP_STE_MAPPED_NODE
:
1503 vport
->fc_map_cnt
+= count
;
1505 case NLP_STE_NPR_NODE
:
1506 vport
->fc_npr_cnt
+= count
;
1509 spin_unlock_irq(shost
->host_lock
);
1513 lpfc_nlp_state_cleanup(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1514 int old_state
, int new_state
)
1516 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1518 if (new_state
== NLP_STE_UNMAPPED_NODE
) {
1519 ndlp
->nlp_type
&= ~(NLP_FCP_TARGET
| NLP_FCP_INITIATOR
);
1520 ndlp
->nlp_flag
&= ~NLP_NODEV_REMOVE
;
1521 ndlp
->nlp_type
|= NLP_FC_NODE
;
1523 if (new_state
== NLP_STE_MAPPED_NODE
)
1524 ndlp
->nlp_flag
&= ~NLP_NODEV_REMOVE
;
1525 if (new_state
== NLP_STE_NPR_NODE
)
1526 ndlp
->nlp_flag
&= ~NLP_RCV_PLOGI
;
1528 /* Transport interface */
1529 if (ndlp
->rport
&& (old_state
== NLP_STE_MAPPED_NODE
||
1530 old_state
== NLP_STE_UNMAPPED_NODE
)) {
1531 vport
->phba
->nport_event_cnt
++;
1532 lpfc_unregister_remote_port(ndlp
);
1535 if (new_state
== NLP_STE_MAPPED_NODE
||
1536 new_state
== NLP_STE_UNMAPPED_NODE
) {
1537 vport
->phba
->nport_event_cnt
++;
1539 * Tell the fc transport about the port, if we haven't
1540 * already. If we have, and it's a scsi entity, be
1541 * sure to unblock any attached scsi devices
1543 lpfc_register_remote_port(vport
, ndlp
);
1546 * if we added to Mapped list, but the remote port
1547 * registration failed or assigned a target id outside
1548 * our presentable range - move the node to the
1551 if (new_state
== NLP_STE_MAPPED_NODE
&&
1553 ndlp
->rport
->scsi_target_id
== -1 ||
1554 ndlp
->rport
->scsi_target_id
>= LPFC_MAX_TARGET
)) {
1555 spin_lock_irq(shost
->host_lock
);
1556 ndlp
->nlp_flag
|= NLP_TGT_NO_SCSIID
;
1557 spin_unlock_irq(shost
->host_lock
);
1558 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
1563 lpfc_nlp_state_name(char *buffer
, size_t size
, int state
)
1565 static char *states
[] = {
1566 [NLP_STE_UNUSED_NODE
] = "UNUSED",
1567 [NLP_STE_PLOGI_ISSUE
] = "PLOGI",
1568 [NLP_STE_ADISC_ISSUE
] = "ADISC",
1569 [NLP_STE_REG_LOGIN_ISSUE
] = "REGLOGIN",
1570 [NLP_STE_PRLI_ISSUE
] = "PRLI",
1571 [NLP_STE_UNMAPPED_NODE
] = "UNMAPPED",
1572 [NLP_STE_MAPPED_NODE
] = "MAPPED",
1573 [NLP_STE_NPR_NODE
] = "NPR",
1576 if (state
< ARRAY_SIZE(states
) && states
[state
])
1577 strlcpy(buffer
, states
[state
], size
);
1579 snprintf(buffer
, size
, "unknown (%d)", state
);
1584 lpfc_nlp_set_state(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
1587 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1588 int old_state
= ndlp
->nlp_state
;
1589 char name1
[16], name2
[16];
1591 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
1592 "0904 NPort state transition x%06x, %s -> %s\n",
1594 lpfc_nlp_state_name(name1
, sizeof(name1
), old_state
),
1595 lpfc_nlp_state_name(name2
, sizeof(name2
), state
));
1597 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_NODE
,
1598 "node statechg did:x%x old:%d ste:%d",
1599 ndlp
->nlp_DID
, old_state
, state
);
1601 if (old_state
== NLP_STE_NPR_NODE
&&
1602 (ndlp
->nlp_flag
& NLP_DELAY_TMO
) != 0 &&
1603 state
!= NLP_STE_NPR_NODE
)
1604 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
1605 if (old_state
== NLP_STE_UNMAPPED_NODE
) {
1606 ndlp
->nlp_flag
&= ~NLP_TGT_NO_SCSIID
;
1607 ndlp
->nlp_type
&= ~NLP_FC_NODE
;
1610 if (list_empty(&ndlp
->nlp_listp
)) {
1611 spin_lock_irq(shost
->host_lock
);
1612 list_add_tail(&ndlp
->nlp_listp
, &vport
->fc_nodes
);
1613 spin_unlock_irq(shost
->host_lock
);
1614 } else if (old_state
)
1615 lpfc_nlp_counters(vport
, old_state
, -1);
1617 ndlp
->nlp_state
= state
;
1618 lpfc_nlp_counters(vport
, state
, 1);
1619 lpfc_nlp_state_cleanup(vport
, ndlp
, old_state
, state
);
1623 lpfc_dequeue_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
1625 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1627 if ((ndlp
->nlp_flag
& NLP_DELAY_TMO
) != 0)
1628 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
1629 if (ndlp
->nlp_state
&& !list_empty(&ndlp
->nlp_listp
))
1630 lpfc_nlp_counters(vport
, ndlp
->nlp_state
, -1);
1631 spin_lock_irq(shost
->host_lock
);
1632 list_del_init(&ndlp
->nlp_listp
);
1633 spin_unlock_irq(shost
->host_lock
);
1634 lpfc_nlp_state_cleanup(vport
, ndlp
, ndlp
->nlp_state
,
1635 NLP_STE_UNUSED_NODE
);
1639 lpfc_drop_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
1641 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1643 if ((ndlp
->nlp_flag
& NLP_DELAY_TMO
) != 0)
1644 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
1645 if (ndlp
->nlp_state
&& !list_empty(&ndlp
->nlp_listp
))
1646 lpfc_nlp_counters(vport
, ndlp
->nlp_state
, -1);
1647 spin_lock_irq(shost
->host_lock
);
1648 list_del_init(&ndlp
->nlp_listp
);
1649 ndlp
->nlp_flag
&= ~NLP_TARGET_REMOVE
;
1650 spin_unlock_irq(shost
->host_lock
);
1655 * Start / ReStart rescue timer for Discovery / RSCN handling
1658 lpfc_set_disctmo(struct lpfc_vport
*vport
)
1660 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1661 struct lpfc_hba
*phba
= vport
->phba
;
1664 if (vport
->port_state
== LPFC_LOCAL_CFG_LINK
) {
1665 /* For FAN, timeout should be greater then edtov */
1666 tmo
= (((phba
->fc_edtov
+ 999) / 1000) + 1);
1668 /* Normal discovery timeout should be > then ELS/CT timeout
1669 * FC spec states we need 3 * ratov for CT requests
1671 tmo
= ((phba
->fc_ratov
* 3) + 3);
1675 if (!timer_pending(&vport
->fc_disctmo
)) {
1676 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1677 "set disc timer: tmo:x%x state:x%x flg:x%x",
1678 tmo
, vport
->port_state
, vport
->fc_flag
);
1681 mod_timer(&vport
->fc_disctmo
, jiffies
+ HZ
* tmo
);
1682 spin_lock_irq(shost
->host_lock
);
1683 vport
->fc_flag
|= FC_DISC_TMO
;
1684 spin_unlock_irq(shost
->host_lock
);
1686 /* Start Discovery Timer state <hba_state> */
1687 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
1688 "0247 Start Discovery Timer state x%x "
1689 "Data: x%x x%lx x%x x%x\n",
1690 vport
->port_state
, tmo
,
1691 (unsigned long)&vport
->fc_disctmo
, vport
->fc_plogi_cnt
,
1692 vport
->fc_adisc_cnt
);
1698 * Cancel rescue timer for Discovery / RSCN handling
1701 lpfc_can_disctmo(struct lpfc_vport
*vport
)
1703 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1704 unsigned long iflags
;
1706 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
1707 "can disc timer: state:x%x rtry:x%x flg:x%x",
1708 vport
->port_state
, vport
->fc_ns_retry
, vport
->fc_flag
);
1710 /* Turn off discovery timer if its running */
1711 if (vport
->fc_flag
& FC_DISC_TMO
) {
1712 spin_lock_irqsave(shost
->host_lock
, iflags
);
1713 vport
->fc_flag
&= ~FC_DISC_TMO
;
1714 spin_unlock_irqrestore(shost
->host_lock
, iflags
);
1715 del_timer_sync(&vport
->fc_disctmo
);
1716 spin_lock_irqsave(&vport
->work_port_lock
, iflags
);
1717 vport
->work_port_events
&= ~WORKER_DISC_TMO
;
1718 spin_unlock_irqrestore(&vport
->work_port_lock
, iflags
);
1721 /* Cancel Discovery Timer state <hba_state> */
1722 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
1723 "0248 Cancel Discovery Timer state x%x "
1724 "Data: x%x x%x x%x\n",
1725 vport
->port_state
, vport
->fc_flag
,
1726 vport
->fc_plogi_cnt
, vport
->fc_adisc_cnt
);
1731 * Check specified ring for outstanding IOCB on the SLI queue
1732 * Return true if iocb matches the specified nport
1735 lpfc_check_sli_ndlp(struct lpfc_hba
*phba
,
1736 struct lpfc_sli_ring
*pring
,
1737 struct lpfc_iocbq
*iocb
,
1738 struct lpfc_nodelist
*ndlp
)
1740 struct lpfc_sli
*psli
= &phba
->sli
;
1741 IOCB_t
*icmd
= &iocb
->iocb
;
1742 struct lpfc_vport
*vport
= ndlp
->vport
;
1744 if (iocb
->vport
!= vport
)
1747 if (pring
->ringno
== LPFC_ELS_RING
) {
1748 switch (icmd
->ulpCommand
) {
1749 case CMD_GEN_REQUEST64_CR
:
1750 if (icmd
->ulpContext
== (volatile ushort
)ndlp
->nlp_rpi
)
1752 case CMD_ELS_REQUEST64_CR
:
1753 if (icmd
->un
.elsreq64
.remoteID
== ndlp
->nlp_DID
)
1755 case CMD_XMIT_ELS_RSP64_CX
:
1756 if (iocb
->context1
== (uint8_t *) ndlp
)
1759 } else if (pring
->ringno
== psli
->extra_ring
) {
1761 } else if (pring
->ringno
== psli
->fcp_ring
) {
1762 /* Skip match check if waiting to relogin to FCP target */
1763 if ((ndlp
->nlp_type
& NLP_FCP_TARGET
) &&
1764 (ndlp
->nlp_flag
& NLP_DELAY_TMO
)) {
1767 if (icmd
->ulpContext
== (volatile ushort
)ndlp
->nlp_rpi
) {
1770 } else if (pring
->ringno
== psli
->next_ring
) {
1777 * Free resources / clean up outstanding I/Os
1778 * associated with nlp_rpi in the LPFC_NODELIST entry.
1781 lpfc_no_rpi(struct lpfc_hba
*phba
, struct lpfc_nodelist
*ndlp
)
1783 LIST_HEAD(completions
);
1784 struct lpfc_sli
*psli
;
1785 struct lpfc_sli_ring
*pring
;
1786 struct lpfc_iocbq
*iocb
, *next_iocb
;
1790 lpfc_fabric_abort_nport(ndlp
);
1793 * Everything that matches on txcmplq will be returned
1794 * by firmware with a no rpi error.
1797 rpi
= ndlp
->nlp_rpi
;
1799 /* Now process each ring */
1800 for (i
= 0; i
< psli
->num_rings
; i
++) {
1801 pring
= &psli
->ring
[i
];
1803 spin_lock_irq(&phba
->hbalock
);
1804 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txq
,
1807 * Check to see if iocb matches the nport we are
1810 if ((lpfc_check_sli_ndlp(phba
, pring
, iocb
,
1812 /* It matches, so deque and call compl
1814 list_move_tail(&iocb
->list
,
1819 spin_unlock_irq(&phba
->hbalock
);
1823 while (!list_empty(&completions
)) {
1824 iocb
= list_get_first(&completions
, struct lpfc_iocbq
, list
);
1825 list_del_init(&iocb
->list
);
1827 if (!iocb
->iocb_cmpl
)
1828 lpfc_sli_release_iocbq(phba
, iocb
);
1831 icmd
->ulpStatus
= IOSTAT_LOCAL_REJECT
;
1832 icmd
->un
.ulpWord
[4] = IOERR_SLI_ABORTED
;
1833 (iocb
->iocb_cmpl
)(phba
, iocb
, iocb
);
1841 * Free rpi associated with LPFC_NODELIST entry.
1842 * This routine is called from lpfc_freenode(), when we are removing
1843 * a LPFC_NODELIST entry. It is also called if the driver initiates a
1844 * LOGO that completes successfully, and we are waiting to PLOGI back
1845 * to the remote NPort. In addition, it is called after we receive
1846 * and unsolicated ELS cmd, send back a rsp, the rsp completes and
1847 * we are waiting to PLOGI back to the remote NPort.
1850 lpfc_unreg_rpi(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
1852 struct lpfc_hba
*phba
= vport
->phba
;
1856 if (ndlp
->nlp_rpi
) {
1857 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1859 lpfc_unreg_login(phba
, vport
->vpi
, ndlp
->nlp_rpi
, mbox
);
1860 mbox
->vport
= vport
;
1861 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
1862 rc
= lpfc_sli_issue_mbox(phba
, mbox
,
1863 (MBX_NOWAIT
| MBX_STOP_IOCB
));
1864 if (rc
== MBX_NOT_FINISHED
)
1865 mempool_free(mbox
, phba
->mbox_mem_pool
);
1867 lpfc_no_rpi(phba
, ndlp
);
1875 lpfc_unreg_all_rpis(struct lpfc_vport
*vport
)
1877 struct lpfc_hba
*phba
= vport
->phba
;
1881 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1883 lpfc_unreg_login(phba
, vport
->vpi
, 0xffff, mbox
);
1884 mbox
->vport
= vport
;
1885 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
1886 rc
= lpfc_sli_issue_mbox(phba
, mbox
,
1887 (MBX_NOWAIT
| MBX_STOP_IOCB
));
1888 if (rc
== MBX_NOT_FINISHED
) {
1889 mempool_free(mbox
, phba
->mbox_mem_pool
);
1895 lpfc_unreg_default_rpis(struct lpfc_vport
*vport
)
1897 struct lpfc_hba
*phba
= vport
->phba
;
1901 mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
1903 lpfc_unreg_did(phba
, vport
->vpi
, 0xffffffff, mbox
);
1904 mbox
->vport
= vport
;
1905 mbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
1906 rc
= lpfc_sli_issue_mbox(phba
, mbox
,
1907 (MBX_NOWAIT
| MBX_STOP_IOCB
));
1908 if (rc
== MBX_NOT_FINISHED
) {
1909 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_MBOX
| LOG_VPORT
,
1910 "1815 Could not issue "
1911 "unreg_did (default rpis)\n");
1912 mempool_free(mbox
, phba
->mbox_mem_pool
);
1918 * Free resources associated with LPFC_NODELIST entry
1919 * so it can be freed.
1922 lpfc_cleanup_node(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
1924 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
1925 struct lpfc_hba
*phba
= vport
->phba
;
1926 LPFC_MBOXQ_t
*mb
, *nextmb
;
1927 struct lpfc_dmabuf
*mp
;
1929 /* Cleanup node for NPort <nlp_DID> */
1930 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
1931 "0900 Cleanup node for NPort x%x "
1932 "Data: x%x x%x x%x\n",
1933 ndlp
->nlp_DID
, ndlp
->nlp_flag
,
1934 ndlp
->nlp_state
, ndlp
->nlp_rpi
);
1935 lpfc_dequeue_node(vport
, ndlp
);
1937 /* cleanup any ndlp on mbox q waiting for reglogin cmpl */
1938 if ((mb
= phba
->sli
.mbox_active
)) {
1939 if ((mb
->mb
.mbxCommand
== MBX_REG_LOGIN64
) &&
1940 (ndlp
== (struct lpfc_nodelist
*) mb
->context2
)) {
1941 mb
->context2
= NULL
;
1942 mb
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
1946 spin_lock_irq(&phba
->hbalock
);
1947 list_for_each_entry_safe(mb
, nextmb
, &phba
->sli
.mboxq
, list
) {
1948 if ((mb
->mb
.mbxCommand
== MBX_REG_LOGIN64
) &&
1949 (ndlp
== (struct lpfc_nodelist
*) mb
->context2
)) {
1950 mp
= (struct lpfc_dmabuf
*) (mb
->context1
);
1952 __lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
1955 list_del(&mb
->list
);
1956 mempool_free(mb
, phba
->mbox_mem_pool
);
1960 spin_unlock_irq(&phba
->hbalock
);
1962 lpfc_els_abort(phba
,ndlp
);
1963 spin_lock_irq(shost
->host_lock
);
1964 ndlp
->nlp_flag
&= ~NLP_DELAY_TMO
;
1965 spin_unlock_irq(shost
->host_lock
);
1967 ndlp
->nlp_last_elscmd
= 0;
1968 del_timer_sync(&ndlp
->nlp_delayfunc
);
1970 if (!list_empty(&ndlp
->els_retry_evt
.evt_listp
))
1971 list_del_init(&ndlp
->els_retry_evt
.evt_listp
);
1972 if (!list_empty(&ndlp
->dev_loss_evt
.evt_listp
))
1973 list_del_init(&ndlp
->dev_loss_evt
.evt_listp
);
1975 if (!list_empty(&ndlp
->dev_loss_evt
.evt_listp
)) {
1976 list_del_init(&ndlp
->dev_loss_evt
.evt_listp
);
1977 complete((struct completion
*)(ndlp
->dev_loss_evt
.evt_arg2
));
1980 lpfc_unreg_rpi(vport
, ndlp
);
1986 * Check to see if we can free the nlp back to the freelist.
1987 * If we are in the middle of using the nlp in the discovery state
1988 * machine, defer the free till we reach the end of the state machine.
1991 lpfc_nlp_remove(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
)
1993 struct lpfc_rport_data
*rdata
;
1995 if (ndlp
->nlp_flag
& NLP_DELAY_TMO
) {
1996 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
1999 lpfc_cleanup_node(vport
, ndlp
);
2002 * We can get here with a non-NULL ndlp->rport because when we
2003 * unregister a rport we don't break the rport/node linkage. So if we
2004 * do, make sure we don't leaving any dangling pointers behind.
2007 rdata
= ndlp
->rport
->dd_data
;
2008 rdata
->pnode
= NULL
;
2014 lpfc_matchdid(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2017 D_ID mydid
, ndlpdid
, matchdid
;
2019 if (did
== Bcast_DID
)
2022 if (ndlp
->nlp_DID
== 0) {
2026 /* First check for Direct match */
2027 if (ndlp
->nlp_DID
== did
)
2030 /* Next check for area/domain identically equals 0 match */
2031 mydid
.un
.word
= vport
->fc_myDID
;
2032 if ((mydid
.un
.b
.domain
== 0) && (mydid
.un
.b
.area
== 0)) {
2036 matchdid
.un
.word
= did
;
2037 ndlpdid
.un
.word
= ndlp
->nlp_DID
;
2038 if (matchdid
.un
.b
.id
== ndlpdid
.un
.b
.id
) {
2039 if ((mydid
.un
.b
.domain
== matchdid
.un
.b
.domain
) &&
2040 (mydid
.un
.b
.area
== matchdid
.un
.b
.area
)) {
2041 if ((ndlpdid
.un
.b
.domain
== 0) &&
2042 (ndlpdid
.un
.b
.area
== 0)) {
2043 if (ndlpdid
.un
.b
.id
)
2049 matchdid
.un
.word
= ndlp
->nlp_DID
;
2050 if ((mydid
.un
.b
.domain
== ndlpdid
.un
.b
.domain
) &&
2051 (mydid
.un
.b
.area
== ndlpdid
.un
.b
.area
)) {
2052 if ((matchdid
.un
.b
.domain
== 0) &&
2053 (matchdid
.un
.b
.area
== 0)) {
2054 if (matchdid
.un
.b
.id
)
2062 /* Search for a nodelist entry */
2063 static struct lpfc_nodelist
*
2064 __lpfc_findnode_did(struct lpfc_vport
*vport
, uint32_t did
)
2066 struct lpfc_nodelist
*ndlp
;
2069 list_for_each_entry(ndlp
, &vport
->fc_nodes
, nlp_listp
) {
2070 if (lpfc_matchdid(vport
, ndlp
, did
)) {
2071 data1
= (((uint32_t) ndlp
->nlp_state
<< 24) |
2072 ((uint32_t) ndlp
->nlp_xri
<< 16) |
2073 ((uint32_t) ndlp
->nlp_type
<< 8) |
2074 ((uint32_t) ndlp
->nlp_rpi
& 0xff));
2075 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
2076 "0929 FIND node DID "
2077 "Data: x%p x%x x%x x%x\n",
2078 ndlp
, ndlp
->nlp_DID
,
2079 ndlp
->nlp_flag
, data1
);
2084 /* FIND node did <did> NOT FOUND */
2085 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_NODE
,
2086 "0932 FIND node did x%x NOT FOUND.\n", did
);
2090 struct lpfc_nodelist
*
2091 lpfc_findnode_did(struct lpfc_vport
*vport
, uint32_t did
)
2093 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2094 struct lpfc_nodelist
*ndlp
;
2096 spin_lock_irq(shost
->host_lock
);
2097 ndlp
= __lpfc_findnode_did(vport
, did
);
2098 spin_unlock_irq(shost
->host_lock
);
2102 struct lpfc_nodelist
*
2103 lpfc_setup_disc_node(struct lpfc_vport
*vport
, uint32_t did
)
2105 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2106 struct lpfc_nodelist
*ndlp
;
2108 ndlp
= lpfc_findnode_did(vport
, did
);
2110 if ((vport
->fc_flag
& FC_RSCN_MODE
) != 0 &&
2111 lpfc_rscn_payload_check(vport
, did
) == 0)
2113 ndlp
= (struct lpfc_nodelist
*)
2114 mempool_alloc(vport
->phba
->nlp_mem_pool
, GFP_KERNEL
);
2117 lpfc_nlp_init(vport
, ndlp
, did
);
2118 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
2119 spin_lock_irq(shost
->host_lock
);
2120 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
2121 spin_unlock_irq(shost
->host_lock
);
2124 if (vport
->fc_flag
& FC_RSCN_MODE
) {
2125 if (lpfc_rscn_payload_check(vport
, did
)) {
2126 spin_lock_irq(shost
->host_lock
);
2127 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
2128 spin_unlock_irq(shost
->host_lock
);
2130 /* Since this node is marked for discovery,
2131 * delay timeout is not needed.
2133 if (ndlp
->nlp_flag
& NLP_DELAY_TMO
)
2134 lpfc_cancel_retry_delay_tmo(vport
, ndlp
);
2138 if (ndlp
->nlp_state
== NLP_STE_ADISC_ISSUE
||
2139 ndlp
->nlp_state
== NLP_STE_PLOGI_ISSUE
)
2141 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_NPR_NODE
);
2142 spin_lock_irq(shost
->host_lock
);
2143 ndlp
->nlp_flag
|= NLP_NPR_2B_DISC
;
2144 spin_unlock_irq(shost
->host_lock
);
2149 /* Build a list of nodes to discover based on the loopmap */
2151 lpfc_disc_list_loopmap(struct lpfc_vport
*vport
)
2153 struct lpfc_hba
*phba
= vport
->phba
;
2155 uint32_t alpa
, index
;
2157 if (!lpfc_is_link_up(phba
))
2160 if (phba
->fc_topology
!= TOPOLOGY_LOOP
)
2163 /* Check for loop map present or not */
2164 if (phba
->alpa_map
[0]) {
2165 for (j
= 1; j
<= phba
->alpa_map
[0]; j
++) {
2166 alpa
= phba
->alpa_map
[j
];
2167 if (((vport
->fc_myDID
& 0xff) == alpa
) || (alpa
== 0))
2169 lpfc_setup_disc_node(vport
, alpa
);
2172 /* No alpamap, so try all alpa's */
2173 for (j
= 0; j
< FC_MAXLOOP
; j
++) {
2174 /* If cfg_scan_down is set, start from highest
2175 * ALPA (0xef) to lowest (0x1).
2177 if (vport
->cfg_scan_down
)
2180 index
= FC_MAXLOOP
- j
- 1;
2181 alpa
= lpfcAlpaArray
[index
];
2182 if ((vport
->fc_myDID
& 0xff) == alpa
)
2184 lpfc_setup_disc_node(vport
, alpa
);
2191 lpfc_issue_clear_la(struct lpfc_hba
*phba
, struct lpfc_vport
*vport
)
2194 struct lpfc_sli
*psli
= &phba
->sli
;
2195 struct lpfc_sli_ring
*extra_ring
= &psli
->ring
[psli
->extra_ring
];
2196 struct lpfc_sli_ring
*fcp_ring
= &psli
->ring
[psli
->fcp_ring
];
2197 struct lpfc_sli_ring
*next_ring
= &psli
->ring
[psli
->next_ring
];
2201 * if it's not a physical port or if we already send
2202 * clear_la then don't send it.
2204 if ((phba
->link_state
>= LPFC_CLEAR_LA
) ||
2205 (vport
->port_type
!= LPFC_PHYSICAL_PORT
))
2208 /* Link up discovery */
2209 if ((mbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
)) != NULL
) {
2210 phba
->link_state
= LPFC_CLEAR_LA
;
2211 lpfc_clear_la(phba
, mbox
);
2212 mbox
->mbox_cmpl
= lpfc_mbx_cmpl_clear_la
;
2213 mbox
->vport
= vport
;
2214 rc
= lpfc_sli_issue_mbox(phba
, mbox
, (MBX_NOWAIT
|
2216 if (rc
== MBX_NOT_FINISHED
) {
2217 mempool_free(mbox
, phba
->mbox_mem_pool
);
2218 lpfc_disc_flush_list(vport
);
2219 extra_ring
->flag
&= ~LPFC_STOP_IOCB_EVENT
;
2220 fcp_ring
->flag
&= ~LPFC_STOP_IOCB_EVENT
;
2221 next_ring
->flag
&= ~LPFC_STOP_IOCB_EVENT
;
2222 phba
->link_state
= LPFC_HBA_ERROR
;
2227 /* Reg_vpi to tell firmware to resume normal operations */
2229 lpfc_issue_reg_vpi(struct lpfc_hba
*phba
, struct lpfc_vport
*vport
)
2231 LPFC_MBOXQ_t
*regvpimbox
;
2233 regvpimbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
2235 lpfc_reg_vpi(phba
, vport
->vpi
, vport
->fc_myDID
, regvpimbox
);
2236 regvpimbox
->mbox_cmpl
= lpfc_mbx_cmpl_reg_vpi
;
2237 regvpimbox
->vport
= vport
;
2238 if (lpfc_sli_issue_mbox(phba
, regvpimbox
,
2239 (MBX_NOWAIT
| MBX_STOP_IOCB
))
2240 == MBX_NOT_FINISHED
) {
2241 mempool_free(regvpimbox
, phba
->mbox_mem_pool
);
2246 /* Start Link up / RSCN discovery on NPR nodes */
2248 lpfc_disc_start(struct lpfc_vport
*vport
)
2250 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2251 struct lpfc_hba
*phba
= vport
->phba
;
2253 uint32_t clear_la_pending
;
2256 if (!lpfc_is_link_up(phba
))
2259 if (phba
->link_state
== LPFC_CLEAR_LA
)
2260 clear_la_pending
= 1;
2262 clear_la_pending
= 0;
2264 if (vport
->port_state
< LPFC_VPORT_READY
)
2265 vport
->port_state
= LPFC_DISC_AUTH
;
2267 lpfc_set_disctmo(vport
);
2269 if (vport
->fc_prevDID
== vport
->fc_myDID
)
2274 vport
->fc_prevDID
= vport
->fc_myDID
;
2275 vport
->num_disc_nodes
= 0;
2277 /* Start Discovery state <hba_state> */
2278 lpfc_printf_vlog(vport
, KERN_INFO
, LOG_DISCOVERY
,
2279 "0202 Start Discovery hba state x%x "
2280 "Data: x%x x%x x%x\n",
2281 vport
->port_state
, vport
->fc_flag
, vport
->fc_plogi_cnt
,
2282 vport
->fc_adisc_cnt
);
2284 /* First do ADISCs - if any */
2285 num_sent
= lpfc_els_disc_adisc(vport
);
2291 * For SLI3, cmpl_reg_vpi will set port_state to READY, and
2292 * continue discovery.
2294 if ((phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
) &&
2295 !(vport
->fc_flag
& FC_RSCN_MODE
)) {
2296 lpfc_issue_reg_vpi(phba
, vport
);
2301 * For SLI2, we need to set port_state to READY and continue
2304 if (vport
->port_state
< LPFC_VPORT_READY
&& !clear_la_pending
) {
2305 /* If we get here, there is nothing to ADISC */
2306 if (vport
->port_type
== LPFC_PHYSICAL_PORT
)
2307 lpfc_issue_clear_la(phba
, vport
);
2309 if (!(vport
->fc_flag
& FC_ABORT_DISCOVERY
)) {
2310 vport
->num_disc_nodes
= 0;
2311 /* go thru NPR nodes and issue ELS PLOGIs */
2312 if (vport
->fc_npr_cnt
)
2313 lpfc_els_disc_plogi(vport
);
2315 if (!vport
->num_disc_nodes
) {
2316 spin_lock_irq(shost
->host_lock
);
2317 vport
->fc_flag
&= ~FC_NDISC_ACTIVE
;
2318 spin_unlock_irq(shost
->host_lock
);
2319 lpfc_can_disctmo(vport
);
2322 vport
->port_state
= LPFC_VPORT_READY
;
2324 /* Next do PLOGIs - if any */
2325 num_sent
= lpfc_els_disc_plogi(vport
);
2330 if (vport
->fc_flag
& FC_RSCN_MODE
) {
2331 /* Check to see if more RSCNs came in while we
2332 * were processing this one.
2334 if ((vport
->fc_rscn_id_cnt
== 0) &&
2335 (!(vport
->fc_flag
& FC_RSCN_DISCOVERY
))) {
2336 spin_lock_irq(shost
->host_lock
);
2337 vport
->fc_flag
&= ~FC_RSCN_MODE
;
2338 spin_unlock_irq(shost
->host_lock
);
2339 lpfc_can_disctmo(vport
);
2341 lpfc_els_handle_rscn(vport
);
2348 * Ignore completion for all IOCBs on tx and txcmpl queue for ELS
2349 * ring the match the sppecified nodelist.
2352 lpfc_free_tx(struct lpfc_hba
*phba
, struct lpfc_nodelist
*ndlp
)
2354 LIST_HEAD(completions
);
2355 struct lpfc_sli
*psli
;
2357 struct lpfc_iocbq
*iocb
, *next_iocb
;
2358 struct lpfc_sli_ring
*pring
;
2361 pring
= &psli
->ring
[LPFC_ELS_RING
];
2363 /* Error matching iocb on txq or txcmplq
2364 * First check the txq.
2366 spin_lock_irq(&phba
->hbalock
);
2367 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txq
, list
) {
2368 if (iocb
->context1
!= ndlp
) {
2372 if ((icmd
->ulpCommand
== CMD_ELS_REQUEST64_CR
) ||
2373 (icmd
->ulpCommand
== CMD_XMIT_ELS_RSP64_CX
)) {
2375 list_move_tail(&iocb
->list
, &completions
);
2380 /* Next check the txcmplq */
2381 list_for_each_entry_safe(iocb
, next_iocb
, &pring
->txcmplq
, list
) {
2382 if (iocb
->context1
!= ndlp
) {
2386 if (icmd
->ulpCommand
== CMD_ELS_REQUEST64_CR
||
2387 icmd
->ulpCommand
== CMD_XMIT_ELS_RSP64_CX
) {
2388 lpfc_sli_issue_abort_iotag(phba
, pring
, iocb
);
2391 spin_unlock_irq(&phba
->hbalock
);
2393 while (!list_empty(&completions
)) {
2394 iocb
= list_get_first(&completions
, struct lpfc_iocbq
, list
);
2395 list_del_init(&iocb
->list
);
2397 if (!iocb
->iocb_cmpl
)
2398 lpfc_sli_release_iocbq(phba
, iocb
);
2401 icmd
->ulpStatus
= IOSTAT_LOCAL_REJECT
;
2402 icmd
->un
.ulpWord
[4] = IOERR_SLI_ABORTED
;
2403 (iocb
->iocb_cmpl
) (phba
, iocb
, iocb
);
2409 lpfc_disc_flush_list(struct lpfc_vport
*vport
)
2411 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
2412 struct lpfc_hba
*phba
= vport
->phba
;
2414 if (vport
->fc_plogi_cnt
|| vport
->fc_adisc_cnt
) {
2415 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
,
2417 if (ndlp
->nlp_state
== NLP_STE_PLOGI_ISSUE
||
2418 ndlp
->nlp_state
== NLP_STE_ADISC_ISSUE
) {
2419 lpfc_free_tx(phba
, ndlp
);
2427 lpfc_cleanup_discovery_resources(struct lpfc_vport
*vport
)
2429 lpfc_els_flush_rscn(vport
);
2430 lpfc_els_flush_cmd(vport
);
2431 lpfc_disc_flush_list(vport
);
2434 /*****************************************************************************/
2436 * NAME: lpfc_disc_timeout
2438 * FUNCTION: Fibre Channel driver discovery timeout routine.
2440 * EXECUTION ENVIRONMENT: interrupt only
2448 /*****************************************************************************/
2450 lpfc_disc_timeout(unsigned long ptr
)
2452 struct lpfc_vport
*vport
= (struct lpfc_vport
*) ptr
;
2453 struct lpfc_hba
*phba
= vport
->phba
;
2454 unsigned long flags
= 0;
2456 if (unlikely(!phba
))
2459 if ((vport
->work_port_events
& WORKER_DISC_TMO
) == 0) {
2460 spin_lock_irqsave(&vport
->work_port_lock
, flags
);
2461 vport
->work_port_events
|= WORKER_DISC_TMO
;
2462 spin_unlock_irqrestore(&vport
->work_port_lock
, flags
);
2464 spin_lock_irqsave(&phba
->hbalock
, flags
);
2465 if (phba
->work_wait
)
2466 lpfc_worker_wake_up(phba
);
2467 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
2473 lpfc_disc_timeout_handler(struct lpfc_vport
*vport
)
2475 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2476 struct lpfc_hba
*phba
= vport
->phba
;
2477 struct lpfc_sli
*psli
= &phba
->sli
;
2478 struct lpfc_nodelist
*ndlp
, *next_ndlp
;
2479 LPFC_MBOXQ_t
*initlinkmbox
;
2480 int rc
, clrlaerr
= 0;
2482 if (!(vport
->fc_flag
& FC_DISC_TMO
))
2485 spin_lock_irq(shost
->host_lock
);
2486 vport
->fc_flag
&= ~FC_DISC_TMO
;
2487 spin_unlock_irq(shost
->host_lock
);
2489 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_ELS_CMD
,
2490 "disc timeout: state:x%x rtry:x%x flg:x%x",
2491 vport
->port_state
, vport
->fc_ns_retry
, vport
->fc_flag
);
2493 switch (vport
->port_state
) {
2495 case LPFC_LOCAL_CFG_LINK
:
2496 /* port_state is identically LPFC_LOCAL_CFG_LINK while waiting for
2500 lpfc_printf_vlog(vport
, KERN_WARNING
, LOG_DISCOVERY
,
2501 "0221 FAN timeout\n");
2502 /* Start discovery by sending FLOGI, clean up old rpis */
2503 list_for_each_entry_safe(ndlp
, next_ndlp
, &vport
->fc_nodes
,
2505 if (ndlp
->nlp_state
!= NLP_STE_NPR_NODE
)
2507 if (ndlp
->nlp_type
& NLP_FABRIC
) {
2508 /* Clean up the ndlp on Fabric connections */
2509 lpfc_drop_node(vport
, ndlp
);
2510 } else if (!(ndlp
->nlp_flag
& NLP_NPR_ADISC
)) {
2511 /* Fail outstanding IO now since device
2512 * is marked for PLOGI.
2514 lpfc_unreg_rpi(vport
, ndlp
);
2517 if (vport
->port_state
!= LPFC_FLOGI
) {
2518 vport
->port_state
= LPFC_FLOGI
;
2519 lpfc_set_disctmo(vport
);
2520 lpfc_initial_flogi(vport
);
2526 /* port_state is identically LPFC_FLOGI while waiting for FLOGI cmpl */
2527 /* Initial FLOGI timeout */
2528 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
2529 "0222 Initial %s timeout\n",
2530 vport
->vpi
? "FLOGI" : "FDISC");
2532 /* Assume no Fabric and go on with discovery.
2533 * Check for outstanding ELS FLOGI to abort.
2536 /* FLOGI failed, so just use loop map to make discovery list */
2537 lpfc_disc_list_loopmap(vport
);
2539 /* Start discovery */
2540 lpfc_disc_start(vport
);
2543 case LPFC_FABRIC_CFG_LINK
:
2544 /* hba_state is identically LPFC_FABRIC_CFG_LINK while waiting for
2546 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
2547 "0223 Timeout while waiting for "
2548 "NameServer login\n");
2549 /* Next look for NameServer ndlp */
2550 ndlp
= lpfc_findnode_did(vport
, NameServer_DID
);
2553 /* Start discovery */
2554 lpfc_disc_start(vport
);
2558 /* Check for wait for NameServer Rsp timeout */
2559 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
2560 "0224 NameServer Query timeout "
2562 vport
->fc_ns_retry
, LPFC_MAX_NS_RETRY
);
2564 if (vport
->fc_ns_retry
< LPFC_MAX_NS_RETRY
) {
2565 /* Try it one more time */
2566 vport
->fc_ns_retry
++;
2567 rc
= lpfc_ns_cmd(vport
, SLI_CTNS_GID_FT
,
2568 vport
->fc_ns_retry
, 0);
2572 vport
->fc_ns_retry
= 0;
2575 * Discovery is over.
2576 * set port_state to PORT_READY if SLI2.
2577 * cmpl_reg_vpi will set port_state to READY for SLI3.
2579 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
)
2580 lpfc_issue_reg_vpi(phba
, vport
);
2581 else { /* NPIV Not enabled */
2582 lpfc_issue_clear_la(phba
, vport
);
2583 vport
->port_state
= LPFC_VPORT_READY
;
2586 /* Setup and issue mailbox INITIALIZE LINK command */
2587 initlinkmbox
= mempool_alloc(phba
->mbox_mem_pool
, GFP_KERNEL
);
2588 if (!initlinkmbox
) {
2589 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
2590 "0206 Device Discovery "
2591 "completion error\n");
2592 phba
->link_state
= LPFC_HBA_ERROR
;
2596 lpfc_linkdown(phba
);
2597 lpfc_init_link(phba
, initlinkmbox
, phba
->cfg_topology
,
2598 phba
->cfg_link_speed
);
2599 initlinkmbox
->mb
.un
.varInitLnk
.lipsr_AL_PA
= 0;
2600 initlinkmbox
->vport
= vport
;
2601 initlinkmbox
->mbox_cmpl
= lpfc_sli_def_mbox_cmpl
;
2602 rc
= lpfc_sli_issue_mbox(phba
, initlinkmbox
,
2603 (MBX_NOWAIT
| MBX_STOP_IOCB
));
2604 lpfc_set_loopback_flag(phba
);
2605 if (rc
== MBX_NOT_FINISHED
)
2606 mempool_free(initlinkmbox
, phba
->mbox_mem_pool
);
2610 case LPFC_DISC_AUTH
:
2611 /* Node Authentication timeout */
2612 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
2613 "0227 Node Authentication timeout\n");
2614 lpfc_disc_flush_list(vport
);
2617 * set port_state to PORT_READY if SLI2.
2618 * cmpl_reg_vpi will set port_state to READY for SLI3.
2620 if (phba
->sli3_options
& LPFC_SLI3_NPIV_ENABLED
)
2621 lpfc_issue_reg_vpi(phba
, vport
);
2622 else { /* NPIV Not enabled */
2623 lpfc_issue_clear_la(phba
, vport
);
2624 vport
->port_state
= LPFC_VPORT_READY
;
2628 case LPFC_VPORT_READY
:
2629 if (vport
->fc_flag
& FC_RSCN_MODE
) {
2630 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
2631 "0231 RSCN timeout Data: x%x "
2633 vport
->fc_ns_retry
, LPFC_MAX_NS_RETRY
);
2635 /* Cleanup any outstanding ELS commands */
2636 lpfc_els_flush_cmd(vport
);
2638 lpfc_els_flush_rscn(vport
);
2639 lpfc_disc_flush_list(vport
);
2644 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
2645 "0229 Unexpected discovery timeout, "
2646 "vport State x%x\n", vport
->port_state
);
2650 switch (phba
->link_state
) {
2652 /* CLEAR LA timeout */
2653 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
2654 "0228 CLEAR LA timeout\n");
2658 case LPFC_LINK_UNKNOWN
:
2659 case LPFC_WARM_START
:
2660 case LPFC_INIT_START
:
2661 case LPFC_INIT_MBX_CMDS
:
2662 case LPFC_LINK_DOWN
:
2664 case LPFC_HBA_ERROR
:
2665 lpfc_printf_vlog(vport
, KERN_ERR
, LOG_DISCOVERY
,
2666 "0230 Unexpected timeout, hba link "
2667 "state x%x\n", phba
->link_state
);
2671 case LPFC_HBA_READY
:
2676 lpfc_disc_flush_list(vport
);
2677 psli
->ring
[(psli
->extra_ring
)].flag
&= ~LPFC_STOP_IOCB_EVENT
;
2678 psli
->ring
[(psli
->fcp_ring
)].flag
&= ~LPFC_STOP_IOCB_EVENT
;
2679 psli
->ring
[(psli
->next_ring
)].flag
&= ~LPFC_STOP_IOCB_EVENT
;
2680 vport
->port_state
= LPFC_VPORT_READY
;
2687 * This routine handles processing a NameServer REG_LOGIN mailbox
2688 * command upon completion. It is setup in the LPFC_MBOXQ
2689 * as the completion routine when the command is
2690 * handed off to the SLI layer.
2693 lpfc_mbx_cmpl_fdmi_reg_login(struct lpfc_hba
*phba
, LPFC_MBOXQ_t
*pmb
)
2695 MAILBOX_t
*mb
= &pmb
->mb
;
2696 struct lpfc_dmabuf
*mp
= (struct lpfc_dmabuf
*) (pmb
->context1
);
2697 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) pmb
->context2
;
2698 struct lpfc_vport
*vport
= pmb
->vport
;
2700 pmb
->context1
= NULL
;
2702 ndlp
->nlp_rpi
= mb
->un
.varWords
[0];
2703 ndlp
->nlp_type
|= NLP_FABRIC
;
2704 lpfc_nlp_set_state(vport
, ndlp
, NLP_STE_UNMAPPED_NODE
);
2707 * Start issuing Fabric-Device Management Interface (FDMI) command to
2708 * 0xfffffa (FDMI well known port) or Delay issuing FDMI command if
2709 * fdmi-on=2 (supporting RPA/hostnmae)
2712 if (vport
->cfg_fdmi_on
== 1)
2713 lpfc_fdmi_cmd(vport
, ndlp
, SLI_MGMT_DHBA
);
2715 mod_timer(&vport
->fc_fdmitmo
, jiffies
+ HZ
* 60);
2717 /* Mailbox took a reference to the node */
2719 lpfc_mbuf_free(phba
, mp
->virt
, mp
->phys
);
2721 mempool_free(pmb
, phba
->mbox_mem_pool
);
2727 lpfc_filter_by_rpi(struct lpfc_nodelist
*ndlp
, void *param
)
2729 uint16_t *rpi
= param
;
2731 return ndlp
->nlp_rpi
== *rpi
;
2735 lpfc_filter_by_wwpn(struct lpfc_nodelist
*ndlp
, void *param
)
2737 return memcmp(&ndlp
->nlp_portname
, param
,
2738 sizeof(ndlp
->nlp_portname
)) == 0;
2741 struct lpfc_nodelist
*
2742 __lpfc_find_node(struct lpfc_vport
*vport
, node_filter filter
, void *param
)
2744 struct lpfc_nodelist
*ndlp
;
2746 list_for_each_entry(ndlp
, &vport
->fc_nodes
, nlp_listp
) {
2747 if (ndlp
->nlp_state
!= NLP_STE_UNUSED_NODE
&&
2748 filter(ndlp
, param
))
2755 * Search node lists for a remote port matching filter criteria
2756 * Caller needs to hold host_lock before calling this routine.
2758 struct lpfc_nodelist
*
2759 lpfc_find_node(struct lpfc_vport
*vport
, node_filter filter
, void *param
)
2761 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2762 struct lpfc_nodelist
*ndlp
;
2764 spin_lock_irq(shost
->host_lock
);
2765 ndlp
= __lpfc_find_node(vport
, filter
, param
);
2766 spin_unlock_irq(shost
->host_lock
);
2771 * This routine looks up the ndlp lists for the given RPI. If rpi found it
2772 * returns the node list element pointer else return NULL.
2774 struct lpfc_nodelist
*
2775 __lpfc_findnode_rpi(struct lpfc_vport
*vport
, uint16_t rpi
)
2777 return __lpfc_find_node(vport
, lpfc_filter_by_rpi
, &rpi
);
2780 struct lpfc_nodelist
*
2781 lpfc_findnode_rpi(struct lpfc_vport
*vport
, uint16_t rpi
)
2783 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2784 struct lpfc_nodelist
*ndlp
;
2786 spin_lock_irq(shost
->host_lock
);
2787 ndlp
= __lpfc_findnode_rpi(vport
, rpi
);
2788 spin_unlock_irq(shost
->host_lock
);
2793 * This routine looks up the ndlp lists for the given WWPN. If WWPN found it
2794 * returns the node element list pointer else return NULL.
2796 struct lpfc_nodelist
*
2797 lpfc_findnode_wwpn(struct lpfc_vport
*vport
, struct lpfc_name
*wwpn
)
2799 struct Scsi_Host
*shost
= lpfc_shost_from_vport(vport
);
2800 struct lpfc_nodelist
*ndlp
;
2802 spin_lock_irq(shost
->host_lock
);
2803 ndlp
= __lpfc_find_node(vport
, lpfc_filter_by_wwpn
, wwpn
);
2804 spin_unlock_irq(shost
->host_lock
);
2809 lpfc_dev_loss_delay(unsigned long ptr
)
2811 struct lpfc_nodelist
*ndlp
= (struct lpfc_nodelist
*) ptr
;
2812 struct lpfc_vport
*vport
= ndlp
->vport
;
2813 struct lpfc_hba
*phba
= vport
->phba
;
2814 struct lpfc_work_evt
*evtp
= &ndlp
->dev_loss_evt
;
2815 unsigned long flags
;
2817 evtp
= &ndlp
->dev_loss_evt
;
2819 spin_lock_irqsave(&phba
->hbalock
, flags
);
2820 if (!list_empty(&evtp
->evt_listp
)) {
2821 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
2825 evtp
->evt_arg1
= ndlp
;
2826 evtp
->evt
= LPFC_EVT_DEV_LOSS_DELAY
;
2827 list_add_tail(&evtp
->evt_listp
, &phba
->work_list
);
2828 if (phba
->work_wait
)
2829 lpfc_worker_wake_up(phba
);
2830 spin_unlock_irqrestore(&phba
->hbalock
, flags
);
2835 lpfc_nlp_init(struct lpfc_vport
*vport
, struct lpfc_nodelist
*ndlp
,
2838 memset(ndlp
, 0, sizeof (struct lpfc_nodelist
));
2839 INIT_LIST_HEAD(&ndlp
->els_retry_evt
.evt_listp
);
2840 INIT_LIST_HEAD(&ndlp
->dev_loss_evt
.evt_listp
);
2841 init_timer(&ndlp
->nlp_delayfunc
);
2842 ndlp
->nlp_delayfunc
.function
= lpfc_els_retry_delay
;
2843 ndlp
->nlp_delayfunc
.data
= (unsigned long)ndlp
;
2844 ndlp
->nlp_DID
= did
;
2845 ndlp
->vport
= vport
;
2846 ndlp
->nlp_sid
= NLP_NO_SID
;
2847 INIT_LIST_HEAD(&ndlp
->nlp_listp
);
2848 kref_init(&ndlp
->kref
);
2850 lpfc_debugfs_disc_trc(vport
, LPFC_DISC_TRC_NODE
,
2851 "node init: did:x%x",
2852 ndlp
->nlp_DID
, 0, 0);
2858 lpfc_nlp_release(struct kref
*kref
)
2860 struct lpfc_nodelist
*ndlp
= container_of(kref
, struct lpfc_nodelist
,
2863 lpfc_debugfs_disc_trc(ndlp
->vport
, LPFC_DISC_TRC_NODE
,
2864 "node release: did:x%x flg:x%x type:x%x",
2865 ndlp
->nlp_DID
, ndlp
->nlp_flag
, ndlp
->nlp_type
);
2867 lpfc_nlp_remove(ndlp
->vport
, ndlp
);
2868 mempool_free(ndlp
, ndlp
->vport
->phba
->nlp_mem_pool
);
2871 struct lpfc_nodelist
*
2872 lpfc_nlp_get(struct lpfc_nodelist
*ndlp
)
2875 kref_get(&ndlp
->kref
);
2880 lpfc_nlp_put(struct lpfc_nodelist
*ndlp
)
2882 return ndlp
? kref_put(&ndlp
->kref
, lpfc_nlp_release
) : 0;